From 46134434a98300e80fdf4f5d4ac87518af0946bd Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Mon, 9 May 2022 21:21:05 +0200 Subject: [PATCH] Show script error callstacks and context in colors in the external console Show colors on console and use color constant to determine color instead of comparing strings in the console render loop. removed 5 string compares which should once again bump the performance quite a bit. The last string compares will be removed soon --- r5dev/core/init.cpp | 3 ++ r5dev/gameui/IConsole.cpp | 7 ---- r5dev/squirrel/sqstdaux.cpp | 29 +++++++++++++ r5dev/squirrel/sqstdaux.h | 37 +++++++++++++++++ r5dev/squirrel/sqtype.h | 24 +++++++---- r5dev/squirrel/sqvm.cpp | 59 +++++++++++++++++++-------- r5dev/vproj/clientsdk.vcxproj | 2 + r5dev/vproj/clientsdk.vcxproj.filters | 6 +++ r5dev/vproj/dedicated.vcxproj | 2 + r5dev/vproj/dedicated.vcxproj.filters | 6 +++ r5dev/vproj/gamesdk.vcxproj | 2 + r5dev/vproj/gamesdk.vcxproj.filters | 6 +++ 12 files changed, 152 insertions(+), 31 deletions(-) create mode 100644 r5dev/squirrel/sqstdaux.cpp create mode 100644 r5dev/squirrel/sqstdaux.h diff --git a/r5dev/core/init.cpp b/r5dev/core/init.cpp index 8e164034..1bff7dfd 100644 --- a/r5dev/core/init.cpp +++ b/r5dev/core/init.cpp @@ -53,6 +53,7 @@ #include "squirrel/sqinit.h" #include "squirrel/sqapi.h" #include "squirrel/sqvm.h" +#include "squirrel/sqstdaux.h" #include "studiorender/studiorendercontext.h" #include "rtech/rtech_game.h" #include "rtech/rtech_utils.h" @@ -188,6 +189,7 @@ void Systems_Init() SQAPI_Attach(); SQVM_Attach(); + SQAUX_Attach(); RTech_Game_Attach(); #ifndef DEDICATED @@ -301,6 +303,7 @@ void Systems_Shutdown() #endif // !CLIENT_DLL SQAPI_Detach(); SQVM_Detach(); + SQAUX_Detach(); RTech_Game_Detach(); #ifndef DEDICATED diff --git a/r5dev/gameui/IConsole.cpp b/r5dev/gameui/IConsole.cpp index 2f142827..80be8444 100644 --- a/r5dev/gameui/IConsole.cpp +++ b/r5dev/gameui/IConsole.cpp @@ -799,13 +799,6 @@ void CConsole::ColorLog(void) const if (strstr(m_ivConLog[i].m_svConLog.c_str(), "[WARNING]")) { imColor = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); true; } if (strncmp(m_ivConLog[i].m_svConLog.c_str(), "# ", 2) == 0) { imColor = ImVec4(1.00f, 0.80f, 0.60f, 1.00f); true; } - //// Squirrel VM script debug - if (strstr(m_ivConLog[i].m_svConLog.c_str(), "CALLSTACK")) { imColor = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); true; } - if (strstr(m_ivConLog[i].m_svConLog.c_str(), "LOCALS")) { imColor = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); true; } - if (strstr(m_ivConLog[i].m_svConLog.c_str(), "DIAGPRINTS")) { imColor = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); true; } - if (strstr(m_ivConLog[i].m_svConLog.c_str(), "SCRIPT ERROR")) { imColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); true; } - if (strstr(m_ivConLog[i].m_svConLog.c_str(), "<><>GRX<><>")) { imColor = ImVec4(0.00f, 0.30f, 1.00f, 1.00f); true; } - ImGui::PushStyleColor(ImGuiCol_Text, imColor); ImGui::TextWrapped(m_ivConLog[i].m_svConLog.c_str()); ImGui::PopStyleColor(); diff --git a/r5dev/squirrel/sqstdaux.cpp b/r5dev/squirrel/sqstdaux.cpp new file mode 100644 index 00000000..4434cf31 --- /dev/null +++ b/r5dev/squirrel/sqstdaux.cpp @@ -0,0 +1,29 @@ +//=============================================================================// +// +// Purpose: +// +//=============================================================================// + +#include "core/stdafx.h" +#include "tier0/tslist.h" +#include "squirrel/sqvm.h" +#include "squirrel/sqstdaux.h" + +bool g_bSQAuxError = false; +SQInteger sqstd_aux_printerror(HSQUIRRELVM v) +{ + g_bSQAuxError = true; + SQInteger results = v_sqstd_aux_printerror(v); + g_bSQAuxError = false; + return results; +} + +void SQAUX_Attach() +{ + DetourAttach((LPVOID*)&v_sqstd_aux_printerror, &sqstd_aux_printerror); +} + +void SQAUX_Detach() +{ + DetourDetach((LPVOID*)&v_sqstd_aux_printerror, &sqstd_aux_printerror); +} \ No newline at end of file diff --git a/r5dev/squirrel/sqstdaux.h b/r5dev/squirrel/sqstdaux.h new file mode 100644 index 00000000..46e9a093 --- /dev/null +++ b/r5dev/squirrel/sqstdaux.h @@ -0,0 +1,37 @@ +#pragma once + + +extern bool g_bSQAuxError; + +inline CMemory p_sqstd_aux_printerror; +inline auto v_sqstd_aux_printerror = p_sqstd_aux_printerror.RCast(); + + +void SQAUX_Attach(); +void SQAUX_Detach(); +/////////////////////////////////////////////////////////////////////////////// +class HSqStdAux : public IDetour +{ + virtual void GetAdr(void) const + { + std::cout << "| FUN: sqstd_aux_printerror : 0x" << std::hex << std::uppercase << p_sqstd_aux_printerror.GetPtr() << std::setw(nPad) << " |" << std::endl; + std::cout << "+----------------------------------------------------------------+" << std::endl; + } + virtual void GetFun(void) const + { +#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) + p_sqstd_aux_printerror = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x40\x53\x55\x56\x57\x41\x54\x41\x55\x41\x57\x48\x81\xEC\x00\x00\x00\x00"), "xxxxxxxxxxxxxx????"); + v_sqstd_aux_printerror = p_sqstd_aux_printerror.RCast(); /*40 53 55 56 57 41 54 41 55 41 57 48 81 EC ?? ?? ?? ??*/ +#elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3) + p_sqstd_aux_printerror = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x40\x53\x56\x57\x41\x54\x41\x55\x41\x56\x41\x57\x48\x81\xEC\x00\x00\x00\x00\xFF\x05\x00\x00\x00\x00"), "xxxxxxxxxxxxxxx????xx????"); + v_sqstd_aux_printerror = p_sqstd_aux_printerror.RCast(); /*40 53 56 57 41 54 41 55 41 56 41 57 48 81 EC ?? ?? ?? ?? FF 05 ?? ?? ?? ??*/ +#endif + } + virtual void GetVar(void) const { } + virtual void GetCon(void) const { } + virtual void Attach(void) const { } + virtual void Detach(void) const { } +}; +/////////////////////////////////////////////////////////////////////////////// + +REGISTER(HSqStdAux); diff --git a/r5dev/squirrel/sqtype.h b/r5dev/squirrel/sqtype.h index 2681ce9e..45ad0e60 100644 --- a/r5dev/squirrel/sqtype.h +++ b/r5dev/squirrel/sqtype.h @@ -94,10 +94,10 @@ const static std::string SQVM_LOG_T[4] = const static std::string SQVM_WARNING_LOG_T[4] = { - "Script(S):Warning:", - "Script(C):Warning:", - "Script(U):Warning:", - "Script(X):Warning:" + "Script(S):", + "Script(C):", + "Script(U):", + "Script(X):" }; const static std::string SQVM_ANSI_LOG_T[4] = @@ -110,9 +110,17 @@ const static std::string SQVM_ANSI_LOG_T[4] = const static std::string SQVM_WARNING_ANSI_LOG_T[4] = { - "\033[38;2;151;149;187mScript(S):\033[38;2;255;255;000mWarning:", - "\033[38;2;151;149;163mScript(C):\033[38;2;255;255;000mWarning:", - "\033[38;2;151;123;136mScript(U):\033[38;2;255;255;000mWarning:", - "\033[38;2;151;149;163mScript(X):\033[38;2;255;255;000mWarning:" + "\033[38;2;151;149;187mScript(S):\033[38;2;255;255;000m", + "\033[38;2;151;149;163mScript(C):\033[38;2;255;255;000m", + "\033[38;2;151;123;136mScript(U):\033[38;2;255;255;000m", + "\033[38;2;151;149;163mScript(X):\033[38;2;255;255;000m" +}; + +const static std::string SQVM_ERROR_ANSI_LOG_T[4] = +{ + "\033[38;2;151;149;187mScript(S):\033[38;2;255;000;000m", + "\033[38;2;151;149;163mScript(C):\033[38;2;255;000;000m", + "\033[38;2;151;123;136mScript(U):\033[38;2;255;000;000m", + "\033[38;2;151;149;163mScript(X):\033[38;2;255;000;000m" }; #endif // SQTYPE_H diff --git a/r5dev/squirrel/sqvm.cpp b/r5dev/squirrel/sqvm.cpp index 52bf9f6d..c540c792 100644 --- a/r5dev/squirrel/sqvm.cpp +++ b/r5dev/squirrel/sqvm.cpp @@ -20,6 +20,7 @@ #include "squirrel/sqtype.h" #include "squirrel/sqvm.h" #include "squirrel/sqinit.h" +#include "squirrel/sqstdaux.h" //--------------------------------------------------------------------------------- // Purpose: prints the output of each VM to the console @@ -74,12 +75,12 @@ SQRESULT HSQVM_PrintFunc(HSQUIRRELVM v, SQChar* fmt, ...) std::string vmStr = SQVM_LOG_T[static_cast(context)].c_str(); vmStr.append(buf); - if (sq_showvmoutput->GetInt() > 0) - { + if (sq_showvmoutput->GetInt() > 0) { sqlogger->debug(vmStr); } if (sq_showvmoutput->GetInt() > 1) { + bool bError = false; if (!g_bSpdLog_UseAnsiClr) { wconsole->debug(vmStr); @@ -89,7 +90,21 @@ SQRESULT HSQVM_PrintFunc(HSQUIRRELVM v, SQChar* fmt, ...) } else { - std::string vmStrAnsi = SQVM_ANSI_LOG_T[static_cast(context)].c_str(); + std::string vmStrAnsi; + if (g_bSQAuxError) + { + if (strstr(buf, "SCRIPT ERROR:") || strstr(buf, " -> ")) + { + bError = true; + vmStrAnsi = SQVM_ERROR_ANSI_LOG_T[static_cast(context)].c_str(); + } + else { + vmStrAnsi = SQVM_WARNING_ANSI_LOG_T[static_cast(context)].c_str(); + } + } + else { + vmStrAnsi = SQVM_ANSI_LOG_T[static_cast(context)].c_str(); + } vmStrAnsi.append(buf); wconsole->debug(vmStrAnsi); #ifdef DEDICATED @@ -104,20 +119,32 @@ SQRESULT HSQVM_PrintFunc(HSQUIRRELVM v, SQChar* fmt, ...) if (sq_showvmoutput->GetInt() > 2) { ImVec4 color; - switch (context) + if (g_bSQAuxError) { - case SQCONTEXT::SERVER: - color = ImVec4(0.59f, 0.58f, 0.73f, 1.00f); - break; - case SQCONTEXT::CLIENT: - color = ImVec4(0.59f, 0.58f, 0.63f, 1.00f); - break; - case SQCONTEXT::UI: - color = ImVec4(0.59f, 0.48f, 0.53f, 1.00f); - break; - default: - color = ImVec4(0.59f, 0.58f, 0.63f, 1.00f); - break; + if (bError) { + color = ImVec4(1.00f, 0.00f, 0.00f, 0.80f); + } + else { + color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); + } + } + else + { + switch (context) + { + case SQCONTEXT::SERVER: + color = ImVec4(0.59f, 0.58f, 0.73f, 1.00f); + break; + case SQCONTEXT::CLIENT: + color = ImVec4(0.59f, 0.58f, 0.63f, 1.00f); + break; + case SQCONTEXT::UI: + color = ImVec4(0.59f, 0.48f, 0.53f, 1.00f); + break; + default: + color = ImVec4(0.59f, 0.58f, 0.63f, 1.00f); + break; + } } g_pIConsole->m_ivConLog.push_back(CConLog(g_spd_sys_w_oss.str(), color)); diff --git a/r5dev/vproj/clientsdk.vcxproj b/r5dev/vproj/clientsdk.vcxproj index dcee2d26..dfaa9157 100644 --- a/r5dev/vproj/clientsdk.vcxproj +++ b/r5dev/vproj/clientsdk.vcxproj @@ -80,6 +80,7 @@ + @@ -212,6 +213,7 @@ + diff --git a/r5dev/vproj/clientsdk.vcxproj.filters b/r5dev/vproj/clientsdk.vcxproj.filters index 284b54c4..755fbfb2 100644 --- a/r5dev/vproj/clientsdk.vcxproj.filters +++ b/r5dev/vproj/clientsdk.vcxproj.filters @@ -480,6 +480,9 @@ sdk\game\shared + + sdk\squirrel + @@ -1433,6 +1436,9 @@ thirdparty\nlohmann\detail\output + + sdk\squirrel + diff --git a/r5dev/vproj/dedicated.vcxproj b/r5dev/vproj/dedicated.vcxproj index 608d0b2e..3b7148ee 100644 --- a/r5dev/vproj/dedicated.vcxproj +++ b/r5dev/vproj/dedicated.vcxproj @@ -214,6 +214,7 @@ + @@ -480,6 +481,7 @@ + diff --git a/r5dev/vproj/dedicated.vcxproj.filters b/r5dev/vproj/dedicated.vcxproj.filters index 8e407ac3..543fb17a 100644 --- a/r5dev/vproj/dedicated.vcxproj.filters +++ b/r5dev/vproj/dedicated.vcxproj.filters @@ -1062,6 +1062,9 @@ thirdparty\nlohmann\detail + + sdk\squirrel + @@ -1298,6 +1301,9 @@ sdk\game\shared + + sdk\squirrel + diff --git a/r5dev/vproj/gamesdk.vcxproj b/r5dev/vproj/gamesdk.vcxproj index cc1a9867..c9c43052 100644 --- a/r5dev/vproj/gamesdk.vcxproj +++ b/r5dev/vproj/gamesdk.vcxproj @@ -88,6 +88,7 @@ + @@ -232,6 +233,7 @@ + diff --git a/r5dev/vproj/gamesdk.vcxproj.filters b/r5dev/vproj/gamesdk.vcxproj.filters index 9c060ad0..08d536e1 100644 --- a/r5dev/vproj/gamesdk.vcxproj.filters +++ b/r5dev/vproj/gamesdk.vcxproj.filters @@ -510,6 +510,9 @@ sdk\game\shared + + sdk\squirrel + @@ -1496,6 +1499,9 @@ thirdparty\nlohmann\detail\output + + sdk\squirrel +