diff --git a/r5dev/core/assert.h b/r5dev/core/assert.h new file mode 100644 index 00000000..dd44c5d2 --- /dev/null +++ b/r5dev/core/assert.h @@ -0,0 +1,13 @@ +#pragma once +#ifndef NDEBUG +# define Assert(condition, message) \ + do { \ + if (! (condition)) { \ + std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \ + << " line " << __LINE__ << ": " << message << std::endl; \ + std::terminate(); \ + } \ + } while (false) +#else +# define Assert(condition, message) do { } while (false) +#endif diff --git a/r5dev/core/dllmain.cpp b/r5dev/core/dllmain.cpp index c6627918..a8b7a027 100644 --- a/r5dev/core/dllmain.cpp +++ b/r5dev/core/dllmain.cpp @@ -1,6 +1,7 @@ #include "core/stdafx.h" #include "core/r5dev.h" #include "core/init.h" +#include "core/logdef.h" /*****************************************************************************/ #ifndef DEDICATED #include "windows/id3dx.h" @@ -15,7 +16,13 @@ void R5Dev_Init() { +#ifndef DEDICATED + if (strstr(GetCommandLineA(), "-wconsole")) { Console_Init(); } +#else Console_Init(); +#endif // !DEDICATED + + SpdLog_Init(); Systems_Init(); WinSys_Attach(); @@ -24,13 +31,17 @@ void R5Dev_Init() DirectX_Init(); #endif // !DEDICATED - spdlog::get("console")->set_pattern("%v"); + spdlog::info("\n"); spdlog::info("+-----------------------------------------------------------------------------+\n"); spdlog::info("| R5 DEVELOPER CONSOLE -- INITIALIZED ----------------------------------- |\n"); spdlog::info("+-----------------------------------------------------------------------------+\n"); - spdlog::get("console")->set_pattern("[%S.%e] %v"); + spdlog::info("\n"); } +//############################################################################# +// SHUTDOWN +//############################################################################# + void R5Dev_Shutdown() { Systems_Shutdown(); diff --git a/r5dev/core/logdef.cpp b/r5dev/core/logdef.cpp new file mode 100644 index 00000000..bfa3cc05 --- /dev/null +++ b/r5dev/core/logdef.cpp @@ -0,0 +1,60 @@ +#include "core/stdafx.h" +#include "core/logdef.h" + +//############################################################################# +// SPDLOG SETUP +//############################################################################# +void SpdLog_Init(void) +{ + static bool bInitialized = false; + + if (bInitialized) + { + Assert(bInitialized, "'SpdLog_Init()' has already been called."); + return; + } + + /************************ + * IMGUI LOGGER SETUP * + ************************/ + { + auto iconsole = std::make_shared("game_console", g_spd_sys_p_ostream_sink); + spdlog::register_logger(iconsole); // in-game console logger. + iconsole->set_pattern("[%S.%e] %v"); + iconsole->set_level(spdlog::level::trace); + } + + /************************ + * WINDOWS LOGGER SETUP * + ************************/ + { + auto wconsole = spdlog::stdout_logger_mt("win_console"); + + // Determine if user wants ansi-color logging in the terminal. + if (strstr(GetCommandLineA(), "-ansiclr")) + { + wconsole->set_pattern("[%S.%e] %v\u001b[0m"); + g_bSpdLog_UseAnsiClr = true; + } + else { wconsole->set_pattern("[%S.%e] %v"); } + wconsole->set_level(spdlog::level::trace); + spdlog::set_default_logger(wconsole); // Set as default. + } + + /************************ + * ROTATE LOGGER SETUP * + ************************/ + { + spdlog::rotating_logger_mt("sqvm_warn_logger", "platform\\logs\\sqvm_warn.log", SPDLOG_MAX_SIZE, SPDLOG_NUM_FILE)->set_pattern("[%Y-%m-%d %H:%M:%S.%e] %v"); + spdlog::rotating_logger_mt("sqvm_print_logger", "platform\\logs\\sqvm_print.log", SPDLOG_MAX_SIZE, SPDLOG_NUM_FILE)->set_pattern("[%Y-%m-%d %H:%M:%S.%e] %v"); + spdlog::rotating_logger_mt("dev_message_logger", "platform\\logs\\dev_message.log", SPDLOG_MAX_SIZE, SPDLOG_NUM_FILE)->set_pattern("[%Y-%m-%d %H:%M:%S.%e] %v"); + spdlog::rotating_logger_mt("netchan_pack_logger", "platform\\logs\\net_trace.log", SPDLOG_MAX_SIZE, SPDLOG_NUM_FILE)->set_pattern("[%Y-%m-%d %H:%M:%S.%e] %v"); + spdlog::rotating_logger_mt("qhull_debug_logger", "platform\\logs\\qhull_print.log", SPDLOG_MAX_SIZE, SPDLOG_NUM_FILE)->set_pattern("[%Y-%m-%d %H:%M:%S.%e] %v"); + spdlog::rotating_logger_mt("filesystem_warn_logger", "platform\\logs\\fs_warn.log", SPDLOG_MAX_SIZE, SPDLOG_NUM_FILE)->set_pattern("[%Y-%m-%d %H:%M:%S.%e] %v"); + } + + spdlog::set_level(spdlog::level::trace); + spdlog::flush_every(std::chrono::seconds(5)); // Flush buffers every 5 seconds for every logger. + + bInitialized = true; +} diff --git a/r5dev/core/logdef.h b/r5dev/core/logdef.h index 83d09dee..e4c41bf9 100644 --- a/r5dev/core/logdef.h +++ b/r5dev/core/logdef.h @@ -1,27 +1,13 @@ #pragma once +constexpr int SPDLOG_MAX_SIZE = 10 * 1024; // Sets number of bytes before rotating logger. +constexpr int SPDLOG_NUM_FILE = 0; // Sets number of files to rotate to. + +inline bool g_bSpdLog_UseAnsiClr = false; + //------------------------------------------------------------------------- -// NETCHAN | -inline auto g_spd_netchan_logger = spdlog::basic_logger_mt("netchan_logger", "platform\\logs\\net_trace.log"); -inline std::ostringstream g_spd_net_p_oss; -inline auto g_spd_net_p_ostream_sink = std::make_shared(g_spd_net_p_oss); -//------------------------------------------------------------------------- -// FILESYSTEM | -inline std::ostringstream fs_oss; -inline auto fs_ostream_sink = std::make_shared(fs_oss); -//------------------------------------------------------------------------- -// SQUIRREL PRINTF | -inline std::ostringstream g_spd_sqvm_p_oss; -inline auto g_spd_sqvm_p_ostream_sink = std::make_shared(g_spd_sqvm_p_oss); -//------------------------------------------------------------------------- -// SQUIRREL WARNF | -inline std::ostringstream g_spd_sqvm_w_oss; -inline auto g_spd_sqvm_w_ostream_sink = std::make_shared(g_spd_sqvm_w_oss); -//------------------------------------------------------------------------- -// SYSTEM PRINTF | +// IMGUI CONSOLE SINK | inline std::ostringstream g_spd_sys_w_oss; inline auto g_spd_sys_p_ostream_sink = std::make_shared(g_spd_sys_w_oss); -//------------------------------------------------------------------------- -// QHULL PRINTF | -inline std::ostringstream g_spd_qhull_p_w_oss; -inline auto g_spd_qhull_p_ostream_sink = std::make_shared(g_spd_qhull_p_w_oss); + +void SpdLog_Init(void); diff --git a/r5dev/dedicated.vcxproj b/r5dev/dedicated.vcxproj index 49eb0733..a16d295c 100644 --- a/r5dev/dedicated.vcxproj +++ b/r5dev/dedicated.vcxproj @@ -135,7 +135,7 @@ Console true - d3d11.lib;bcrypt.lib;%(AdditionalDependencies) + User32.lib;bcrypt.lib;%(AdditionalDependencies) del "..\..\..\$(ProjectName)" && copy /Y "$(TargetPath)" "..\..\..\ @@ -162,7 +162,7 @@ true true true - d3d11.lib;bcrypt.lib;%(AdditionalDependencies) + User32.lib;bcrypt.lib;%(AdditionalDependencies) del "..\..\..\$(ProjectName)" && copy /Y "$(TargetPath)" "..\..\..\ @@ -175,6 +175,7 @@ + diff --git a/r5dev/dedicated.vcxproj.filters b/r5dev/dedicated.vcxproj.filters index 8e9448d3..0fd1d77a 100644 --- a/r5dev/dedicated.vcxproj.filters +++ b/r5dev/dedicated.vcxproj.filters @@ -663,6 +663,9 @@ sdk\tier0 + + core + diff --git a/r5dev/engine/sys_utils.cpp b/r5dev/engine/sys_utils.cpp index 57a59e93..5ff66572 100644 --- a/r5dev/engine/sys_utils.cpp +++ b/r5dev/engine/sys_utils.cpp @@ -1,18 +1,23 @@ #include "core/stdafx.h" #include "core/logdef.h" +#include "tier0/commandline.h" #include "engine/sys_utils.h" +#ifndef DEDICATED #include "vgui/CEngineVGui.h" #include "gameui/IConsole.h" +#endif // !DEDICATED //----------------------------------------------------------------------------- -// Sys_Error -// +// Purpose: Exit engine with error +// Input : *error - +// ... - +// Output : void Sys_Error //----------------------------------------------------------------------------- void HSys_Error(char* fmt, ...) { - static char buf[1024]; + static char buf[1024] = {}; - va_list args; + va_list args{}; va_start(args, fmt); vsnprintf(buf, sizeof(buf), fmt, args); @@ -25,39 +30,16 @@ void HSys_Error(char* fmt, ...) } //----------------------------------------------------------------------------- -// Sys_Print -// +// Purpose: Show warning in the console, exit engine with error when level 5 +// Input : level - +// *error - ... - +// Output : void* Sys_Warning //----------------------------------------------------------------------------- -void DevMsg(eDLL_T idx, const char* fmt, ...) +void* HSys_Warning(int level, char* fmt, ...) { - int vmIdx = (int)idx; - static bool initialized = false; - static char buf[1024]; + static char buf[1024] = {}; - static std::string vmType[7] = { "Native(S):", "Native(C):", "Native(U):", "Native(E):", "Native(F):", "Native(R):", "Native(M):" }; - - static auto iconsole = spdlog::stdout_logger_mt("dev_message_iconsole"); // in-game console. - static auto wconsole = spdlog::stdout_logger_mt("dev_message_wconsole"); // windows console. - static auto sqlogger = spdlog::basic_logger_mt("dev_message_logger", "platform\\logs\\dev_message.log"); // file logger. - - std::string vmStr = vmType[vmIdx].c_str(); - - g_spd_sys_w_oss.str(""); - g_spd_sys_w_oss.clear(); - - if (!initialized) - { - iconsole = std::make_shared("sys_print_ostream", g_spd_sys_p_ostream_sink); - iconsole->set_pattern("[%S.%e] %v"); - iconsole->set_level(spdlog::level::debug); - wconsole->set_pattern("[%S.%e] %v"); - wconsole->set_level(spdlog::level::debug); - sqlogger->set_pattern("[%S.%e] %v"); - sqlogger->set_level(spdlog::level::debug); - initialized = true; - } - - va_list args; + va_list args{}; va_start(args, fmt); vsnprintf(buf, sizeof(buf), fmt, args); @@ -65,24 +47,65 @@ void DevMsg(eDLL_T idx, const char* fmt, ...) buf[sizeof(buf) - 1] = 0; va_end(args); + DevMsg(eDLL_T::NONE, "Warning(%d)%s\n", level, buf); // TODO: Color + return Sys_Warning(level, buf); +} + +//----------------------------------------------------------------------------- +// Purpose: Show logs to all console interfaces +// Input : idx - +// *fmt - ... - +// Output : void DevMsg +//----------------------------------------------------------------------------- +void DevMsg(eDLL_T idx, const char* fmt, ...) +{ + static char buf[1024] = {}; + + static std::shared_ptr iconsole = spdlog::get("game_console"); + static std::shared_ptr wconsole = spdlog::get("win_console"); + static std::shared_ptr sqlogger = spdlog::get("dev_message_logger"); + + {///////////////////////////// + va_list args{}; + va_start(args, fmt); + + vsnprintf(buf, sizeof(buf), fmt, args); + + buf[sizeof(buf) - 1] = 0; + va_end(args); + }///////////////////////////// + + std::string vmStr = sDLL_T[(int)idx].c_str(); vmStr.append(buf); - iconsole->debug(vmStr); - wconsole->debug(vmStr); sqlogger->debug(vmStr); + if (!g_bSpdLog_UseAnsiClr) { wconsole->debug(vmStr); } + else + { + std::string vmStrAnsi = sANSI_DLL_T[(int)idx].c_str(); + vmStrAnsi.append(buf); + wconsole->debug(vmStrAnsi); + } + #ifndef DEDICATED + g_spd_sys_w_oss.str(""); + g_spd_sys_w_oss.clear(); + + iconsole->info(vmStr); + std::string s = g_spd_sys_w_oss.str(); - const char* c = s.c_str(); g_pLogSystem.AddLog((LogType_t)eDLL_T::ENGINE, s); - g_pIConsole->m_ivConLog.push_back(Strdup((const char*)c)); + g_pIConsole->m_ivConLog.push_back(Strdup(s.c_str())); #endif // !DEDICATED } //----------------------------------------------------------------------------- -// Sys_LoadAssetHelper -// +// Purpose: Load assets from a custom directory if file exists +// Input : *lpFileName - +// a2 - *a3 - +// Output : void* Sys_LoadAssetHelper //----------------------------------------------------------------------------- void* HSys_LoadAssetHelper(const CHAR* lpFileName, std::int64_t a2, LARGE_INTEGER* a3) { @@ -113,11 +136,13 @@ void* HSys_LoadAssetHelper(const CHAR* lpFileName, std::int64_t a2, LARGE_INTEGE void SysUtils_Attach() { DetourAttach((LPVOID*)&Sys_Error, &HSys_Error); + DetourAttach((LPVOID*)&Sys_Warning, &HSys_Warning); DetourAttach((LPVOID*)&Sys_LoadAssetHelper, &HSys_LoadAssetHelper); } void SysUtils_Detach() { DetourDetach((LPVOID*)&Sys_Error, &HSys_Error); + DetourDetach((LPVOID*)&Sys_Warning, &HSys_Warning); DetourDetach((LPVOID*)&Sys_LoadAssetHelper, &HSys_LoadAssetHelper); } diff --git a/r5dev/engine/sys_utils.h b/r5dev/engine/sys_utils.h index 79807aac..5a1769ce 100644 --- a/r5dev/engine/sys_utils.h +++ b/r5dev/engine/sys_utils.h @@ -7,6 +7,9 @@ namespace ADDRESS p_Sys_Error = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x48\x89\x4C\x24\x08\x48\x89\x54\x24\x10\x4C\x89\x44\x24\x18\x4C\x89\x4C\x24\x20\x53\x55\x41\x54\x41\x56\xB8\x58\x10\x00\x00\xE8", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); void (*Sys_Error)(char* fmt, ...) = (void (*)(char* fmt, ...))p_Sys_Error.GetPtr(); /*48 89 4C 24 08 48 89 54 24 10 4C 89 44 24 18 4C 89 4C 24 20 53 55 41 54 41 56 B8 58 10 00 00 E8*/ + ADDRESS p_Warning = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x48\x89\x54\x24\x00\x4C\x89\x44\x24\x00\x4C\x89\x4C\x24\x00\x48\x83\xEC\x28\x4C\x8D\x44\x24\x00\xE8\x00\x00\x00\x00\x48\x83\xC4\x28\xC3\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\x48\x89\x5C\x24\x00\x48\x89\x74\x24\x00\x48\x89\x7C\x24\x00\x8B\x05\x00\x00\x00\x00", "xxxx?xxxx?xxxx?xxxxxxxx?x????xxxxxxxxxxxxxxxxxxxxxxx?xxxx?xxxx?xx????"); + void* (*Sys_Warning)(int level, char* fmt, ...) = (void* (*)(int, char* fmt, ...))p_Warning.GetPtr(); /*48 89 54 24 ? 4C 89 44 24 ? 4C 89 4C 24 ? 48 83 EC 28 4C 8D 44 24 ? E8 ? ? ? ? 48 83 C4 28 C3 CC CC CC CC CC CC CC CC CC CC CC CC CC CC 48 89 5C 24 ? 48 89 74 24 ? 48 89 7C 24 ? 8B 05 ? ? ? ?*/ + ADDRESS p_Sys_LoadAssetHelper = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x48\x89\x74\x24\x10\x48\x89\x7C\x24\x18\x41\x56\x48\x83\xEC\x40\x33", "xxxxxxxxxxxxxxxxx"); void*(*Sys_LoadAssetHelper)(const CHAR* lpFileName, std::int64_t a2, LARGE_INTEGER* a3) = (void*(*)(const CHAR*, std::int64_t, LARGE_INTEGER*))p_Sys_LoadAssetHelper.GetPtr();/*48 89 74 24 10 48 89 7C 24 18 41 56 48 83 EC 40 33*/ #if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) @@ -30,7 +33,32 @@ enum class eDLL_T : int ENGINE = 3, // Wrapper FS = 4, // File System RTECH = 5, // RTech API - MS = 6 // Material System + MS = 6, // Material System + NONE = 7 +}; + +const std::string sDLL_T[8] = +{ + "Native(S):", + "Native(C):", + "Native(U):", + "Native(E):", + "Native(F):", + "Native(R):", + "Native(M):", + "" +}; + +const static std::string sANSI_DLL_T[8] = +{ + "\u001b[94mNative(S):", + "\u001b[90mNative(C):", + "\u001b[33mNative(U):", + "\u001b[37mNative(E):", + "\u001b[96mNative(F):", + "\u001b[92mNative(R):", + "\u001b[91mNative(M):", + "" }; /////////////////////////////////////////////////////////////////////////////// @@ -46,6 +74,7 @@ class HSys_Utils : public IDetour virtual void debugp() { std::cout << "| FUN: Sys_Error : 0x" << std::hex << std::uppercase << p_Sys_Error.GetPtr() << std::setw(npad) << " |" << std::endl; + std::cout << "| FUN: Sys_Warning : 0x" << std::hex << std::uppercase << p_Warning.GetPtr() << std::setw(npad) << " |" << std::endl; std::cout << "| FUN: Sys_LoadAssetHelper : 0x" << std::hex << std::uppercase << p_Sys_LoadAssetHelper.GetPtr() << std::setw(npad) << " |" << std::endl; std::cout << "| FUN: MemAlloc_Wrapper : 0x" << std::hex << std::uppercase << p_MemAlloc_Wrapper.GetPtr() << std::setw(npad) << " |" << std::endl; std::cout << "+----------------------------------------------------------------+" << std::endl; diff --git a/r5dev/gameui/IConsole.cpp b/r5dev/gameui/IConsole.cpp index 470bee85..dd19f89b 100644 --- a/r5dev/gameui/IConsole.cpp +++ b/r5dev/gameui/IConsole.cpp @@ -31,12 +31,11 @@ CConsole::CConsole() m_nHistoryPos = -1; m_bAutoScroll = true; m_bScrollToBottom = false; - m_bInitialized = false; + m_bInitialized = false; m_ivCommands.push_back("CLEAR"); m_ivCommands.push_back("HELP"); m_ivCommands.push_back("HISTORY"); - AddLog("[DEBUG] THREAD ID: %ld\n", g_dThreadId); } //----------------------------------------------------------------------------- @@ -54,7 +53,7 @@ CConsole::~CConsole() //----------------------------------------------------------------------------- // Purpose: draws the console frontend //----------------------------------------------------------------------------- -void CConsole::Draw(const char* title, bool* bDraw) +void CConsole::Draw(const char* pszTitle, bool* bDraw) { if (!m_bInitialized) { @@ -79,7 +78,7 @@ void CConsole::Draw(const char* title, bool* bDraw) ImGui::SetNextWindowSize(ImVec2(1000, 600), ImGuiCond_FirstUseEver); ImGui::SetWindowPos(ImVec2(-1000, 50), ImGuiCond_FirstUseEver); - if (!ImGui::Begin(title, bDraw)) + if (!ImGui::Begin(pszTitle, bDraw)) { ImGui::End(); return; @@ -135,29 +134,21 @@ void CConsole::Draw(const char* title, bool* bDraw) ImGui::PushItemWidth(footer_width_to_reserve - 80); if (ImGui::IsWindowAppearing()) { ImGui::SetKeyboardFocusHere(); } + ImGuiInputTextFlags input_text_flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory; if (ImGui::InputText("##input", m_szInputBuf, IM_ARRAYSIZE(m_szInputBuf), input_text_flags, &TextEditCallbackStub, (void*)this)) { - char* s = m_szInputBuf; - - - const char* replace = ""; - - if (strstr(m_szInputBuf, "`")) { strcpy_s(s, sizeof(replace), replace); } - Strtrim(s); - if (s[0]) { ProcessCommand(s); } - strcpy_s(s, sizeof(replace), replace); + if (m_szInputBuf[0]) { ProcessCommand(m_szInputBuf); } + strcpy_s(m_szInputBuf, 1, ""); m_bReclaimFocus = true; } ImGui::SameLine(); if (ImGui::Button("Submit")) { - char* s = m_szInputBuf; - const char* replace = ""; - if (s[0]) { ProcessCommand(s); } - strcpy_s(s, sizeof(replace), replace); + if (m_szInputBuf[0]) { ProcessCommand(m_szInputBuf); } + strcpy_s(m_szInputBuf, 1, ""); m_bReclaimFocus = true; } @@ -226,11 +217,11 @@ void CConsole::Options() //----------------------------------------------------------------------------- // Purpose: executes submitted commands in a separate thread //----------------------------------------------------------------------------- -void CConsole::ProcessCommand(const char* command_line) +void CConsole::ProcessCommand(const char* pszCommand) { - AddLog("# %s\n", command_line); + AddLog("# %s\n", pszCommand); - std::thread t(IVEngineClient_CommandExecute, this, command_line); + std::thread t(IVEngineClient_CommandExecute, this, pszCommand); t.detach(); // Detach from render thread. // This is to avoid a race condition. @@ -239,7 +230,7 @@ void CConsole::ProcessCommand(const char* command_line) m_nHistoryPos = -1; for (int i = m_ivHistory.Size - 1; i >= 0; i--) { - if (Stricmp(m_ivHistory[i], command_line) == 0) + if (Stricmp(m_ivHistory[i], pszCommand) == 0) { delete m_ivHistory[i]; m_ivHistory.erase(m_ivHistory.begin() + i); @@ -247,12 +238,12 @@ void CConsole::ProcessCommand(const char* command_line) } } - m_ivHistory.push_back(Strdup(command_line)); - if (Stricmp(command_line, "CLEAR") == 0) + m_ivHistory.push_back(Strdup(pszCommand)); + if (Stricmp(pszCommand, "CLEAR") == 0) { ClearLog(); } - else if (Stricmp(command_line, "HELP") == 0) + else if (Stricmp(pszCommand, "HELP") == 0) { AddLog("Commands:"); for (int i = 0; i < m_ivCommands.Size; i++) @@ -274,7 +265,7 @@ void CConsole::ProcessCommand(const char* command_line) AddLog("Native(R): = RTech DLL (Code)"); AddLog("Native(M): = MatSys DLL (Code)"); } - else if (Stricmp(command_line, "HISTORY") == 0) + else if (Stricmp(pszCommand, "HISTORY") == 0) { int first = m_ivHistory.Size - 10; for (int i = first > 0 ? first : 0; i < m_ivHistory.Size; i++) @@ -296,22 +287,22 @@ int CConsole::TextEditCallback(ImGuiInputTextCallbackData* data) case ImGuiInputTextFlags_CallbackCompletion: { // Locate beginning of current word. - const char* word_end = data->Buf + data->CursorPos; - const char* word_start = word_end; - while (word_start > data->Buf) + const char* pszWordEnd = data->Buf + data->CursorPos; + const char* pszWordStart = pszWordEnd; + while (pszWordStart > data->Buf) { - const char c = word_start[-1]; + const char c = pszWordStart[-1]; if (c == ' ' || c == '\t' || c == ',' || c == ';') { break; } - word_start--; + pszWordStart--; } break; } case ImGuiInputTextFlags_CallbackHistory: { - const int prev_history_pos = m_nHistoryPos; + const int nPrevHistoryPos = m_nHistoryPos; if (data->EventKey == ImGuiKey_UpArrow) { if (m_nHistoryPos == -1) { m_nHistoryPos = m_ivHistory.Size - 1; } @@ -327,11 +318,11 @@ int CConsole::TextEditCallback(ImGuiInputTextCallbackData* data) } } } - if (prev_history_pos != m_nHistoryPos) + if (nPrevHistoryPos != m_nHistoryPos) { - const char* history_str = (m_nHistoryPos >= 0) ? m_ivHistory[m_nHistoryPos] : ""; + const char* pszHistory = (m_nHistoryPos >= 0) ? m_ivHistory[m_nHistoryPos] : ""; data->DeleteChars(0, data->BufTextLen); - data->InsertChars(0, history_str); + data->InsertChars(0, pszHistory); } } } @@ -343,8 +334,8 @@ int CConsole::TextEditCallback(ImGuiInputTextCallbackData* data) //----------------------------------------------------------------------------- int CConsole::TextEditCallbackStub(ImGuiInputTextCallbackData* data) { - CConsole* console = (CConsole*)data->UserData; - return console->TextEditCallback(data); + CConsole* pConsole = (CConsole*)data->UserData; + return pConsole->TextEditCallback(data); } //----------------------------------------------------------------------------- @@ -377,67 +368,67 @@ void CConsole::ColorLog() { for (int i = 0; i < m_ivConLog.Size; i++) { - const char* item = m_ivConLog[i]; - if (!m_itFilter.PassFilter(item)) + const char* pszConLog = m_ivConLog[i]; + if (!m_itFilter.PassFilter(pszConLog)) { continue; } /////////////////////////////////////////////////////////////////////// - ImVec4 color; - bool has_color = false; + ImVec4 imColor; // General - if (strstr(item, "[INFO]")) { color = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); has_color = true; } - if (strstr(item, "[ERROR]")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } - if (strstr(item, "[DEBUG]")) { color = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); has_color = true; } - if (strstr(item, "[WARNING]")) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); has_color = true; } - if (strncmp(item, "# ", 2) == 0) { color = ImVec4(1.00f, 0.80f, 0.60f, 1.00f); has_color = true; } + if (strstr(pszConLog, "[INFO]")) { imColor = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); true; } + if (strstr(pszConLog, "[ERROR]")) { imColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); true; } + if (strstr(pszConLog, "[DEBUG]")) { imColor = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); true; } + if (strstr(pszConLog, "[WARNING]")) { imColor = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); true; } + if (strncmp(pszConLog, "# ", 2) == 0) { imColor = ImVec4(1.00f, 0.80f, 0.60f, 1.00f); true; } // Script virtual machines per game dll - if (strstr(item, "Script(S):")) { color = ImVec4(0.59f, 0.58f, 0.73f, 1.00f); has_color = true; } - if (strstr(item, "Script(C):")) { color = ImVec4(0.59f, 0.58f, 0.63f, 1.00f); has_color = true; } - if (strstr(item, "Script(U):")) { color = ImVec4(0.59f, 0.48f, 0.53f, 1.00f); has_color = true; } + if (strstr(pszConLog, "Script(S):")) { imColor = ImVec4(0.59f, 0.58f, 0.73f, 1.00f); true; } + if (strstr(pszConLog, "Script(C):")) { imColor = ImVec4(0.59f, 0.58f, 0.63f, 1.00f); true; } + if (strstr(pszConLog, "Script(U):")) { imColor = ImVec4(0.59f, 0.48f, 0.53f, 1.00f); true; } + if (strstr(pszConLog, "Script(X):")) { imColor = ImVec4(0.59f, 0.58f, 0.63f, 1.00f); true; } // Native per game dll - if (strstr(item, "Native(S):")) { color = ImVec4(0.59f, 0.58f, 0.73f, 1.00f); has_color = true; } - if (strstr(item, "Native(C):")) { color = ImVec4(0.59f, 0.58f, 0.63f, 1.00f); has_color = true; } - if (strstr(item, "Native(U):")) { color = ImVec4(0.59f, 0.48f, 0.53f, 1.00f); has_color = true; } + if (strstr(pszConLog, "Native(S):")) { imColor = ImVec4(0.59f, 0.58f, 0.73f, 1.00f); true; } + if (strstr(pszConLog, "Native(C):")) { imColor = ImVec4(0.59f, 0.58f, 0.63f, 1.00f); true; } + if (strstr(pszConLog, "Native(U):")) { imColor = ImVec4(0.59f, 0.48f, 0.53f, 1.00f); true; } // Native per sys dll - if (strstr(item, "Native(E):")) { color = ImVec4(0.70f, 0.70f, 0.70f, 1.00f); has_color = true; } - if (strstr(item, "Native(F):")) { color = ImVec4(0.32f, 0.64f, 0.72f, 1.00f); has_color = true; } - if (strstr(item, "Native(R):")) { color = ImVec4(0.36f, 0.70f, 0.35f, 1.00f); has_color = true; } - if (strstr(item, "Native(M):")) { color = ImVec4(0.75f, 0.41f, 0.67f, 1.00f); has_color = true; } + if (strstr(pszConLog, "Native(E):")) { imColor = ImVec4(0.70f, 0.70f, 0.70f, 1.00f); true; } + if (strstr(pszConLog, "Native(F):")) { imColor = ImVec4(0.32f, 0.64f, 0.72f, 1.00f); true; } + if (strstr(pszConLog, "Native(R):")) { imColor = ImVec4(0.36f, 0.70f, 0.35f, 1.00f); true; } + if (strstr(pszConLog, "Native(M):")) { imColor = ImVec4(0.75f, 0.41f, 0.67f, 1.00f); true; } // Callbacks //if (strstr(item, "CodeCallback_")) { color = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); has_color = true; } // Squirrel VM script errors - if (strstr(item, ".gnut")) { color = ImVec4(1.00f, 1.00f, 1.00f, 0.60f); has_color = true; } - if (strstr(item, ".nut")) { color = ImVec4(1.00f, 1.00f, 1.00f, 0.60f); has_color = true; } - if (strstr(item, "[CLIENT]")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } - if (strstr(item, "[SERVER]")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } - if (strstr(item, "[UI]")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } - if (strstr(item, "SCRIPT ERROR")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } - if (strstr(item, "SCRIPT COMPILE")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } - if (strstr(item, ".gnut #")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } - if (strstr(item, ".nut #")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } - if (strstr(item, "): -> ")) { color = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); has_color = true; } + if (strstr(pszConLog, ".gnut")) { imColor = ImVec4(1.00f, 1.00f, 1.00f, 0.60f); true; } + if (strstr(pszConLog, ".nut")) { imColor = ImVec4(1.00f, 1.00f, 1.00f, 0.60f); true; } + if (strstr(pszConLog, "[CLIENT]")) { imColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); true; } + if (strstr(pszConLog, "[SERVER]")) { imColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); true; } + if (strstr(pszConLog, "[UI]")) { imColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); true; } + if (strstr(pszConLog, "SCRIPT ERROR")) { imColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); true; } + if (strstr(pszConLog, "SCRIPT COMPILE")) { imColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); true; } + if (strstr(pszConLog, ".gnut #")) { imColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); true; } + if (strstr(pszConLog, ".nut #")) { imColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); true; } + if (strstr(pszConLog, "): -> ")) { imColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); true; } // Squirrel VM script debug - if (strstr(item, "CALLSTACK")) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); has_color = true; } - if (strstr(item, "LOCALS")) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); has_color = true; } - if (strstr(item, "*FUNCTION")) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); has_color = true; } - if (strstr(item, "DIAGPRINTS")) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); has_color = true; } - if (strstr(item, " File : ")) { color = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); has_color = true; } - if (strstr(item, "<><>GRX<><>")) { color = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); has_color = true; } + if (strstr(pszConLog, "CALLSTACK")) { imColor = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); true; } + if (strstr(pszConLog, "LOCALS")) { imColor = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); true; } + if (strstr(pszConLog, "*FUNCTION")) { imColor = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); true; } + if (strstr(pszConLog, "DIAGPRINTS")) { imColor = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); true; } + if (strstr(pszConLog, " File : ")) { imColor = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); true; } + if (strstr(pszConLog, "<><>GRX<><>")) { imColor = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); true; } // Filters //if (strstr(item, ") -> ")) { color = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); has_color = true; } - if (has_color) { ImGui::PushStyleColor(ImGuiCol_Text, color); } - ImGui::TextWrapped(item); - if (has_color) { ImGui::PopStyleColor(); } + ImGui::PushStyleColor(ImGuiCol_Text, imColor); + ImGui::TextWrapped(pszConLog); + ImGui::PopStyleColor(); } } @@ -446,61 +437,61 @@ void CConsole::ColorLog() //----------------------------------------------------------------------------- void CConsole::SetStyleVar() { - ImGuiStyle& style = ImGui::GetStyle(); - ImVec4* colors = style.Colors; + ImGuiStyle& imStyle = ImGui::GetStyle(); + ImVec4* imColor = imStyle.Colors; - colors[ImGuiCol_Text] = ImVec4(0.81f, 0.81f, 0.81f, 1.00f); - colors[ImGuiCol_TextDisabled] = ImVec4(0.56f, 0.56f, 0.56f, 1.00f); - colors[ImGuiCol_WindowBg] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); - colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); - colors[ImGuiCol_PopupBg] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); - colors[ImGuiCol_Border] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); - colors[ImGuiCol_BorderShadow] = ImVec4(0.04f, 0.04f, 0.04f, 0.64f); - colors[ImGuiCol_FrameBg] = ImVec4(0.13f, 0.13f, 0.13f, 1.00f); - colors[ImGuiCol_FrameBgHovered] = ImVec4(0.19f, 0.19f, 0.19f, 1.00f); - colors[ImGuiCol_FrameBgActive] = ImVec4(0.24f, 0.24f, 0.24f, 1.00f); - colors[ImGuiCol_TitleBg] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f); - colors[ImGuiCol_TitleBgActive] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); - colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); - colors[ImGuiCol_MenuBarBg] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f); - colors[ImGuiCol_ScrollbarBg] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); - colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); - colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f); - colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f); - colors[ImGuiCol_CheckMark] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f); - colors[ImGuiCol_SliderGrab] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); - colors[ImGuiCol_SliderGrabActive] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f); - colors[ImGuiCol_Button] = ImVec4(0.35f, 0.35f, 0.35f, 1.00f); - colors[ImGuiCol_ButtonHovered] = ImVec4(0.45f, 0.45f, 0.45f, 1.00f); - colors[ImGuiCol_ButtonActive] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f); - colors[ImGuiCol_Header] = ImVec4(0.35f, 0.35f, 0.35f, 1.00f); - colors[ImGuiCol_HeaderHovered] = ImVec4(0.45f, 0.45f, 0.45f, 1.00f); - colors[ImGuiCol_HeaderActive] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f); - colors[ImGuiCol_Separator] = ImVec4(0.53f, 0.53f, 0.57f, 1.00f); - colors[ImGuiCol_SeparatorHovered] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f); - colors[ImGuiCol_SeparatorActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f); - colors[ImGuiCol_ResizeGrip] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); - colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f); - colors[ImGuiCol_ResizeGripActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f); - colors[ImGuiCol_Tab] = ImVec4(0.18f, 0.18f, 0.18f, 1.00f); - colors[ImGuiCol_TabHovered] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); - colors[ImGuiCol_TabActive] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); + imColor[ImGuiCol_Text] = ImVec4(0.81f, 0.81f, 0.81f, 1.00f); + imColor[ImGuiCol_TextDisabled] = ImVec4(0.56f, 0.56f, 0.56f, 1.00f); + imColor[ImGuiCol_WindowBg] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); + imColor[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); + imColor[ImGuiCol_PopupBg] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); + imColor[ImGuiCol_Border] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); + imColor[ImGuiCol_BorderShadow] = ImVec4(0.04f, 0.04f, 0.04f, 0.64f); + imColor[ImGuiCol_FrameBg] = ImVec4(0.13f, 0.13f, 0.13f, 1.00f); + imColor[ImGuiCol_FrameBgHovered] = ImVec4(0.19f, 0.19f, 0.19f, 1.00f); + imColor[ImGuiCol_FrameBgActive] = ImVec4(0.24f, 0.24f, 0.24f, 1.00f); + imColor[ImGuiCol_TitleBg] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f); + imColor[ImGuiCol_TitleBgActive] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); + imColor[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); + imColor[ImGuiCol_MenuBarBg] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f); + imColor[ImGuiCol_ScrollbarBg] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); + imColor[ImGuiCol_ScrollbarGrab] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); + imColor[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f); + imColor[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f); + imColor[ImGuiCol_CheckMark] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f); + imColor[ImGuiCol_SliderGrab] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); + imColor[ImGuiCol_SliderGrabActive] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f); + imColor[ImGuiCol_Button] = ImVec4(0.35f, 0.35f, 0.35f, 1.00f); + imColor[ImGuiCol_ButtonHovered] = ImVec4(0.45f, 0.45f, 0.45f, 1.00f); + imColor[ImGuiCol_ButtonActive] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f); + imColor[ImGuiCol_Header] = ImVec4(0.35f, 0.35f, 0.35f, 1.00f); + imColor[ImGuiCol_HeaderHovered] = ImVec4(0.45f, 0.45f, 0.45f, 1.00f); + imColor[ImGuiCol_HeaderActive] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f); + imColor[ImGuiCol_Separator] = ImVec4(0.53f, 0.53f, 0.57f, 1.00f); + imColor[ImGuiCol_SeparatorHovered] = ImVec4(0.53f, 0.53f, 0.53f, 1.00f); + imColor[ImGuiCol_SeparatorActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f); + imColor[ImGuiCol_ResizeGrip] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); + imColor[ImGuiCol_ResizeGripHovered] = ImVec4(0.52f, 0.52f, 0.52f, 1.00f); + imColor[ImGuiCol_ResizeGripActive] = ImVec4(0.63f, 0.63f, 0.63f, 1.00f); + imColor[ImGuiCol_Tab] = ImVec4(0.18f, 0.18f, 0.18f, 1.00f); + imColor[ImGuiCol_TabHovered] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); + imColor[ImGuiCol_TabActive] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); - style.WindowBorderSize = 0.0f; - style.FrameBorderSize = 1.0f; - style.ChildBorderSize = 1.0f; - style.PopupBorderSize = 1.0f; - style.TabBorderSize = 1.0f; + imStyle.WindowBorderSize = 0.0f; + imStyle.FrameBorderSize = 1.0f; + imStyle.ChildBorderSize = 1.0f; + imStyle.PopupBorderSize = 1.0f; + imStyle.TabBorderSize = 1.0f; - style.WindowRounding = 2.5f; - style.FrameRounding = 0.0f; - style.ChildRounding = 0.0f; - style.PopupRounding = 0.0f; - style.TabRounding = 1.0f; - style.ScrollbarRounding = 1.0f; + imStyle.WindowRounding = 2.5f; + imStyle.FrameRounding = 0.0f; + imStyle.ChildRounding = 0.0f; + imStyle.PopupRounding = 0.0f; + imStyle.TabRounding = 1.0f; + imStyle.ScrollbarRounding = 1.0f; - style.ItemSpacing = ImVec2(4, 4); - style.WindowPadding = ImVec2(5, 5); + imStyle.ItemSpacing = ImVec2(4, 4); + imStyle.WindowPadding = ImVec2(5, 5); } CConsole* g_pIConsole = new CConsole(); diff --git a/r5dev/public/utility.cpp b/r5dev/public/utility.cpp index c6886076..b2b64074 100644 --- a/r5dev/public/utility.cpp +++ b/r5dev/public/utility.cpp @@ -148,7 +148,7 @@ void HexDump(const char* szHeader, int nFunc, const void* pData, int nSize) szAscii[16] = '\0'; // Add new loggers here to replace the placeholder. - if (nFunc == 0) { logger = g_spd_netchan_logger; } + if (nFunc == 0) { logger = spdlog::get("netchan_pack_logger"); } // Add timestamp. logger->set_level(spdlog::level::trace); diff --git a/r5dev/r5dev.vcxproj b/r5dev/r5dev.vcxproj index 38f74ed2..c1cd4a2f 100644 --- a/r5dev/r5dev.vcxproj +++ b/r5dev/r5dev.vcxproj @@ -217,6 +217,7 @@ + diff --git a/r5dev/r5dev.vcxproj.filters b/r5dev/r5dev.vcxproj.filters index 3dcd9cbc..0cd6a3cc 100644 --- a/r5dev/r5dev.vcxproj.filters +++ b/r5dev/r5dev.vcxproj.filters @@ -1040,6 +1040,9 @@ sdk\tier0 + + core + diff --git a/r5dev/squirrel/sqvm.cpp b/r5dev/squirrel/sqvm.cpp index 0ecd5d9d..fe7567c6 100644 --- a/r5dev/squirrel/sqvm.cpp +++ b/r5dev/squirrel/sqvm.cpp @@ -9,10 +9,11 @@ #include "tier0/basetypes.h" #include "tier0/cvar.h" #include "tier0/IConVar.h" +#include "tier0/commandline.h" #include "engine/sys_utils.h" -#include "squirrel/sqvm.h" #include "vgui/CEngineVGui.h" #include "gameui/IConsole.h" +#include "squirrel/sqvm.h" //--------------------------------------------------------------------------------- // Purpose: prints the output of each VM to the console @@ -21,43 +22,26 @@ void* HSQVM_PrintFunc(void* sqvm, char* fmt, ...) { #ifdef GAMEDLL_S3 int vmIdx = *(int*)((std::uintptr_t)sqvm + 0x18); -#else // TODO [ AMOS ]: nothing equal to 'rdx + 18h' exist in the vm pointers for anything below S3. - int vmIdx = 3; +#else // TODO [ AMOS ]: nothing equal to 'rdx + 18h' exist in the vm structs for anything below S3. + static int vmIdx = 3; #endif - static bool initialized = false; + static char buf[1024] = {}; - static char buf[1024]; - static std::string vmType[4] = { "Script(S):", "Script(C):", "Script(U):", "Script(X):" }; + static std::shared_ptr iconsole = spdlog::get("game_console"); + static std::shared_ptr wconsole = spdlog::get("win_console"); + static std::shared_ptr sqlogger = spdlog::get("sqvm_print_logger"); - static auto iconsole = spdlog::stdout_logger_mt("sqvm_print_iconsole"); // in-game console. - static auto wconsole = spdlog::stdout_logger_mt("sqvm_print_wconsole"); // windows console. - static auto sqlogger = spdlog::basic_logger_mt("sqvm_print_logger", "platform\\logs\\sqvm_print.log"); // file logger. + {///////////////////////////// + va_list args{}; + va_start(args, fmt); - std::string vmStr = vmType[vmIdx].c_str(); + vsnprintf(buf, sizeof(buf), fmt, args); - g_spd_sqvm_p_oss.str(""); - g_spd_sqvm_p_oss.clear(); - - if (!initialized) - { - iconsole = std::make_shared("sqvm_print_ostream", g_spd_sqvm_p_ostream_sink); - iconsole->set_pattern("[%S.%e] %v"); - iconsole->set_level(spdlog::level::debug); - wconsole->set_pattern("[%S.%e] %v"); - wconsole->set_level(spdlog::level::debug); - sqlogger->set_pattern("[%S.%e] %v"); - sqlogger->set_level(spdlog::level::debug); - initialized = true; - } - - va_list args; - va_start(args, fmt); - - vsnprintf(buf, sizeof(buf), fmt, args); - - buf[sizeof(buf) - 1] = 0; - va_end(args); + buf[sizeof(buf) - 1] = 0; + va_end(args); + }///////////////////////////// + std::string vmStr = SQVM_LOG_T[vmIdx].c_str(); vmStr.append(buf); if (sq_showvmoutput->GetInt() > 0) @@ -66,21 +50,32 @@ void* HSQVM_PrintFunc(void* sqvm, char* fmt, ...) } if (sq_showvmoutput->GetInt() > 1) { + if (!g_bSpdLog_UseAnsiClr) + { + wconsole->debug(vmStr); + } + else + { + std::string vmStrAnsi = SQVM_ANSI_LOG_T[vmIdx].c_str(); + vmStrAnsi.append(buf); + wconsole->debug(vmStrAnsi); + } + +#ifndef DEDICATED + g_spd_sys_w_oss.str(""); + g_spd_sys_w_oss.clear(); + iconsole->debug(vmStr); - wconsole->debug(vmStr); -#ifndef DEDICATED - std::string s = g_spd_sqvm_p_oss.str(); - const char* c = s.c_str(); - g_pIConsole->m_ivConLog.push_back(Strdup((const char*)c)); + + std::string s = g_spd_sys_w_oss.str(); + g_pIConsole->m_ivConLog.push_back(Strdup(s.c_str())); + + if (sq_showvmoutput->GetInt() > 2) + { + g_pLogSystem.AddLog((LogType_t)vmIdx, s); + } #endif // !DEDICATED } -#ifndef DEDICATED - if (sq_showvmoutput->GetInt() > 2) - { - std::string s = g_spd_sqvm_p_oss.str(); - g_pLogSystem.AddLog((LogType_t)vmIdx, s); - } -#endif // !DEDICATED return NULL; } @@ -90,45 +85,26 @@ void* HSQVM_PrintFunc(void* sqvm, char* fmt, ...) void* HSQVM_WarningFunc(void* sqvm, int a2, int a3, int* nStringSize, void** ppString) { void* result = SQVM_WarningFunc(sqvm, a2, a3, nStringSize, ppString); - if (g_bSQVM_WarnFuncCalled) // Check if its SQVM_Warning calling. + void* retaddr = _ReturnAddress(); + + if (retaddr != SQVM_WarningFunc) // Check if its SQVM_Warning calling. { return result; // If not return. } - static bool initialized = false; - static std::string vmType[4] = { "Script(S): WARNING: ", "Script(C): WARNING: ", "Script(U): WARNING: ", "Script(X): WARNING: " }; - - static auto iconsole = spdlog::stdout_logger_mt("sqvm_warn_iconsole"); // in-game console. - static auto wconsole = spdlog::stdout_logger_mt("sqvm_warn_wconsole"); // windows console. - static auto sqlogger = spdlog::basic_logger_mt("sqvm_warn_logger", "platform\\logs\\sqvm_warn.log"); // file logger. - #ifdef GAMEDLL_S3 int vmIdx = *(int*)((std::uintptr_t)sqvm + 0x18); -#else // TODO [ AMOS ]: nothing equal to 'rdx + 18h' exist in the vm pointers for anything below S3. +#else // TODO [ AMOS ]: nothing equal to 'rdx + 18h' exist in the vm structs for anything below S3. int vmIdx = 3; #endif - std::string vmStr = vmType[vmIdx].c_str(); - g_spd_sqvm_w_oss.str(""); - g_spd_sqvm_w_oss.clear(); + static std::shared_ptr iconsole = spdlog::get("game_console"); + static std::shared_ptr wconsole = spdlog::get("win_console"); + static std::shared_ptr sqlogger = spdlog::get("sqvm_warn_logger"); - if (!initialized) - { - iconsole = std::make_shared("sqvm_warn_ostream", g_spd_sqvm_p_ostream_sink); - iconsole->set_pattern("[%S.%e] %v\n"); - iconsole->set_level(spdlog::level::debug); - wconsole->set_pattern("[%S.%e] %v\n"); - wconsole->set_level(spdlog::level::debug); - sqlogger->set_pattern("[%S.%e] %v\n"); - sqlogger->set_level(spdlog::level::debug); - initialized = true; - } - - std::string stringConstructor((char*)*ppString, *nStringSize); // Get string from memory via std::string constructor. - vmStr.append(stringConstructor); - - std::string s = g_spd_sqvm_w_oss.str(); - const char* c = s.c_str(); + std::string vmStr = SQVM_LOG_T[vmIdx].c_str(); + std::string svConstructor((char*)*ppString, *nStringSize); // Get string from memory via std::string constructor. + vmStr.append(svConstructor); if (sq_showvmwarning->GetInt() > 0) { @@ -136,36 +112,36 @@ void* HSQVM_WarningFunc(void* sqvm, int a2, int a3, int* nStringSize, void** ppS } if (sq_showvmwarning->GetInt() > 1) { + if (!g_bSpdLog_UseAnsiClr) + { + wconsole->debug(vmStr); + } + else + { + std::string vmStrAnsi = SQVM_ANSI_LOG_T[vmIdx].c_str(); + vmStrAnsi.append(svConstructor); + wconsole->debug(vmStrAnsi); + } + +#ifndef DEDICATED + g_spd_sys_w_oss.str(""); + g_spd_sys_w_oss.clear(); + iconsole->debug(vmStr); // Emit to in-game console. - wconsole->debug(vmStr); // Emit to windows console. -#ifndef DEDICATED - std::string s = g_spd_sqvm_w_oss.str(); - const char* c = s.c_str(); - g_pIConsole->m_ivConLog.push_back(Strdup(c)); -#endif // !DEDICATED - } -#ifndef DEDICATED - if (sq_showvmwarning->GetInt() > 2) - { - g_pLogSystem.AddLog((LogType_t)vmIdx, s); - const char* c = s.c_str(); - g_pIConsole->m_ivConLog.push_back(Strdup(c)); - } -#endif // !DEDICATED - g_bSQVM_WarnFuncCalled = false; + std::string s = g_spd_sys_w_oss.str(); + g_pIConsole->m_ivConLog.push_back(Strdup(s.c_str())); + + if (sq_showvmwarning->GetInt() > 2) + { + g_pLogSystem.AddLog((LogType_t)vmIdx, s); + g_pIConsole->m_ivConLog.push_back(Strdup(s.c_str())); + } +#endif // !DEDICATED + } return result; } -//--------------------------------------------------------------------------------- -// Purpose: -//--------------------------------------------------------------------------------- -void* HSQVM_WarningCmd(int a1, int a2) -{ - g_bSQVM_WarnFuncCalled = true; - return SQVM_WarningCmd(a1, a2); -} - //--------------------------------------------------------------------------------- // Purpose: loads the include file from the mods directory //--------------------------------------------------------------------------------- @@ -288,7 +264,6 @@ void SQVM_Attach() { DetourAttach((LPVOID*)&SQVM_PrintFunc, &HSQVM_PrintFunc); DetourAttach((LPVOID*)&SQVM_WarningFunc, &HSQVM_WarningFunc); - DetourAttach((LPVOID*)&SQVM_WarningCmd, &HSQVM_WarningCmd); DetourAttach((LPVOID*)&SQVM_LoadRson, &HSQVM_LoadRson); DetourAttach((LPVOID*)&SQVM_LoadScript, &HSQVM_LoadScript); } @@ -297,7 +272,6 @@ void SQVM_Detach() { DetourDetach((LPVOID*)&SQVM_PrintFunc, &HSQVM_PrintFunc); DetourDetach((LPVOID*)&SQVM_WarningFunc, &HSQVM_WarningFunc); - DetourDetach((LPVOID*)&SQVM_WarningCmd, &HSQVM_WarningCmd); DetourDetach((LPVOID*)&SQVM_LoadRson, &HSQVM_LoadRson); DetourDetach((LPVOID*)&SQVM_LoadScript, &HSQVM_LoadScript); } diff --git a/r5dev/squirrel/sqvm.h b/r5dev/squirrel/sqvm.h index 49067c79..d3d5e57a 100644 --- a/r5dev/squirrel/sqvm.h +++ b/r5dev/squirrel/sqvm.h @@ -27,6 +27,22 @@ struct SQFuncRegistration } }; +const static std::string SQVM_LOG_T[4] = +{ + "Script(S):", + "Script(C):", + "Script(U):", + "Script(X):" +}; + +const static std::string SQVM_ANSI_LOG_T[4] = +{ + "\u001b[94mScript(S):", + "\u001b[90mScript(C):", + "\u001b[33mScript(U):", + "\u001b[90mScript(X):" +}; + namespace { /* ==== SQUIRREL ======================================================================================================================================================== */ @@ -63,9 +79,6 @@ int HSQVM_NativeTest(void* sqvm); void SQVM_Attach(); void SQVM_Detach(); -/////////////////////////////////////////////////////////////////////////////// -extern bool g_bSQVM_WarnFuncCalled; - /////////////////////////////////////////////////////////////////////////////// class HSQVM : public IDetour { diff --git a/r5dev/tier0/IConVar.cpp b/r5dev/tier0/IConVar.cpp index 02051c26..fdf201f3 100644 --- a/r5dev/tier0/IConVar.cpp +++ b/r5dev/tier0/IConVar.cpp @@ -77,7 +77,8 @@ void ConVar::Init(void) cl_gpustats_offset_y = new ConVar("cl_gpustats_offset_y", "900", FCVAR_DEVELOPMENTONLY, "Y offset for texture streaming debug overlay.", false, 0.f, false, 0.f, nullptr, nullptr); //------------------------------------------------------------------------- // FILESYSTEM | - fs_warning_level_native = new ConVar("fs_warning_level_native", "0", FCVAR_DEVELOPMENTONLY, "Set the filesystem warning level ( !slower! ).", false, 0.f, false, 0.f, nullptr, nullptr); + fs_warning_level_native = new ConVar("fs_warning_level_native", "0", FCVAR_DEVELOPMENTONLY, "Set the filesystem warning level.", false, 0.f, false, 0.f, nullptr, nullptr); + fs_show_warning_output = new ConVar("fs_show_warning_output", "0", FCVAR_DEVELOPMENTONLY, "Logs the filesystem warnings to the console, filtered by 'fs_warning_level_native' ( !slower! ).", false, 0.f, false, 0.f, nullptr, nullptr); fs_packedstore_entryblock_stats = new ConVar("fs_packedstore_entryblock_stats", "0", FCVAR_DEVELOPMENTONLY, "If set to 1, prints the stats of each file entry in the VPK during decompression ( !slower! ).", false, 0.f, false, 0.f, nullptr, nullptr); //------------------------------------------------------------------------- // FILESYSTEM | diff --git a/r5dev/tier0/cvar.cpp b/r5dev/tier0/cvar.cpp index 374c6a2d..df4ce362 100644 --- a/r5dev/tier0/cvar.cpp +++ b/r5dev/tier0/cvar.cpp @@ -34,6 +34,7 @@ ConVar* cl_gpustats_offset_y = new ConVar(); //----------------------------------------------------------------------------- // FILESYSTEM | ConVar* fs_warning_level_native = new ConVar(); +ConVar* fs_show_warning_output = new ConVar(); ConVar* fs_packedstore_entryblock_stats = new ConVar(); //----------------------------------------------------------------------------- // MATERIALSYSTEM | diff --git a/r5dev/tier0/cvar.h b/r5dev/tier0/cvar.h index c0810fe6..f3411172 100644 --- a/r5dev/tier0/cvar.h +++ b/r5dev/tier0/cvar.h @@ -47,6 +47,7 @@ extern ConVar* cl_gpustats_offset_y; //------------------------------------------------------------------------- // FILESYSTEM | extern ConVar* fs_warning_level_native; +extern ConVar* fs_show_warning_output; extern ConVar* fs_packedstore_entryblock_stats; //------------------------------------------------------------------------- // MATERIALSYSTEM | diff --git a/r5dev/vpc/basefilesystem.cpp b/r5dev/vpc/basefilesystem.cpp index 1bff7e83..b28d9a72 100644 --- a/r5dev/vpc/basefilesystem.cpp +++ b/r5dev/vpc/basefilesystem.cpp @@ -14,42 +14,38 @@ void HCBaseFileSystem_Warning(void* thisptr, FileWarningLevel_t level, const cha return; } - static bool initialized = false; static char buf[1024] = {}; - static auto iconsole = spdlog::stdout_logger_mt("fs_warn_iconsole"); // in-game console. - static auto wconsole = spdlog::stdout_logger_mt("fs_warn_wconsole"); // windows console. + static std::shared_ptr iconsole = spdlog::get("game_console"); + static std::shared_ptr wconsole = spdlog::get("win_console"); + static std::shared_ptr fslogger = spdlog::get("filesystem_warn_logger"); - fs_oss.str(""); - fs_oss.clear(); + {///////////////////////////// + va_list args{}; + va_start(args, fmt); - if (!initialized) + vsnprintf(buf, sizeof(buf), fmt, args); + + buf[sizeof(buf) - 1] = 0; + va_end(args); + }///////////////////////////// + + fslogger->debug(buf); + + if (fs_show_warning_output->GetBool()) { - iconsole = std::make_shared("fs_warn_ostream", fs_ostream_sink); - iconsole->set_pattern("[%S.%e] %v"); - iconsole->set_level(spdlog::level::debug); - wconsole->set_pattern("[%S.%e] %v"); - wconsole->set_level(spdlog::level::debug); - initialized = true; - } - - va_list args{}; - va_start(args, fmt); - - vsnprintf(buf, sizeof(buf), fmt, args); - - buf[sizeof(buf) - 1] = 0; - va_end(args); - - iconsole->debug(buf); - wconsole->debug(buf); - + wconsole->debug(buf); #ifndef DEDICATED - std::string s = fs_oss.str(); - const char* c = s.c_str(); + g_spd_sys_w_oss.str(""); + g_spd_sys_w_oss.clear(); - g_pIConsole->m_ivConLog.push_back(Strdup((const char*)c)); + iconsole->debug(buf); + + std::string s = g_spd_sys_w_oss.str(); + + g_pIConsole->m_ivConLog.push_back(Strdup(s.c_str())); #endif // !DEDICATED + } } void CBaseFileSystem_Attach() diff --git a/r5dev/vphysics/QHull.cpp b/r5dev/vphysics/QHull.cpp index 8cd91fb7..fcc7ef61 100644 --- a/r5dev/vphysics/QHull.cpp +++ b/r5dev/vphysics/QHull.cpp @@ -1,46 +1,44 @@ #include "core/stdafx.h" #include "core/logdef.h" #include "vphysics/QHull.h" +#ifndef DEDICATED +#include "gameui/IConsole.h" +#endif // !DEDICATED //----------------------------------------------------------------------------- // Purpose: qhull error and debug prints //----------------------------------------------------------------------------- int HQHull_PrintFunc(const char* fmt, ...) { - static bool initialized = false; - static char buf[1024]; + static char buf[1024] = {}; - static auto iconsole = spdlog::stdout_logger_mt("qhull_print_iconsole"); // in-game console. - static auto wconsole = spdlog::stdout_logger_mt("qhull_print_wconsole"); // windows console. - static auto qhlogger = spdlog::basic_logger_mt("qhull_print_logger", "platform\\logs\\qhull_print.log"); // file logger. + static std::shared_ptr iconsole = spdlog::get("game_console"); + static std::shared_ptr wconsole = spdlog::get("win_console"); + static std::shared_ptr qhlogger = spdlog::get("qhull_debug_logger"); - g_spd_sqvm_p_oss.str(""); - g_spd_sqvm_p_oss.clear(); + {///////////////////////////// + va_list args{}; + va_start(args, fmt); - if (!initialized) - { - iconsole = std::make_shared("qhull_print_ostream", g_spd_sqvm_p_ostream_sink); - iconsole->set_pattern("[%S.%e] %v"); - iconsole->set_level(spdlog::level::debug); - wconsole->set_pattern("[%S.%e] %v"); - wconsole->set_level(spdlog::level::debug); - qhlogger->set_pattern("[%S.%e] %v"); - qhlogger->set_level(spdlog::level::debug); - initialized = true; - } + vsnprintf(buf, sizeof(buf), fmt, args); - va_list args; - va_start(args, fmt); - - vsnprintf(buf, sizeof(buf), fmt, args); - - buf[sizeof(buf) - 1] = 0; - va_end(args); + buf[sizeof(buf) - 1] = 0; + va_end(args); + }///////////////////////////// qhlogger->debug(buf); - iconsole->debug(buf); wconsole->debug(buf); +#ifndef DEDICATED + g_spd_sys_w_oss.str(""); + g_spd_sys_w_oss.clear(); + + iconsole->debug(buf); + + std::string s = g_spd_sys_w_oss.str(); + g_pIConsole->m_ivConLog.push_back(Strdup(s.c_str())); +#endif // !DEDICATED + return NULL; } diff --git a/r5dev/windows/console.cpp b/r5dev/windows/console.cpp index 5806a784..e950b94a 100644 --- a/r5dev/windows/console.cpp +++ b/r5dev/windows/console.cpp @@ -1,6 +1,6 @@ #include "core/stdafx.h" #include "core/init.h" -#include "rtech/rtech_utils.h" +#include "core/logdef.h" #ifndef DEDICATED #include "windows/id3dx.h" #endif // !DEDICATED @@ -47,23 +47,30 @@ void Console_Init() /////////////////////////////////////////////////////////////////////////// // Create a worker thread to process console commands - DWORD threadId; + DWORD dwMode = NULL; + DWORD dwThreadId = NULL; DWORD __stdcall ProcessConsoleWorker(LPVOID); - HANDLE hThread = CreateThread(NULL, 0, ProcessConsoleWorker, NULL, 0, &threadId); + HANDLE hThread = CreateThread(NULL, 0, ProcessConsoleWorker, NULL, 0, &dwThreadId); - // Initialize global spdlog. - auto console = spdlog::stdout_logger_mt("console"); - console->set_pattern("[%S.%e] %v"); // Set pattern. - - spdlog::set_level(spdlog::level::trace); - spdlog::set_default_logger(console); // Set as default. - spdlog::flush_every(std::chrono::seconds(5)); // Flush buffers every 5 seconds for every logger. + //HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE); + HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE); if (hThread) { - spdlog::debug("THREAD ID: {}\n\n", threadId); CloseHandle(hThread); } + + if (strstr(GetCommandLineA(), "-ansiclr")) + { + GetConsoleMode(hOutput, &dwMode); + dwMode |= ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING; + + if (!SetConsoleMode(hOutput, dwMode)) // Some editions of Windows have 'VirtualTerminalLevel' disabled by default. + { + // Warn the user if 'VirtualTerminalLevel' could not be set on users environment. + MessageBox(NULL, "Failed to set console mode 'VirtualTerminalLevel'.\nPlease omit the '-ansiclr' parameter and restart\nthe game if output logging appears distorted.", "SDK Warning", MB_ICONEXCLAMATION | MB_OK); + } + } } //#############################################################################