From 426ae0c4cd58956aef782b27ca7d47cc365b182b Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Wed, 22 Jun 2022 12:12:08 +0200 Subject: [PATCH] Bad logic logging improvements Log bad logic in colors for every game logic error. Added 'g_flErrorTimeStamp' and a hook to 'SQVM_LogicError'. --- r5dev/squirrel/sqstdaux.cpp | 1 - r5dev/squirrel/sqvm.cpp | 16 ++++++++++++++++ r5dev/squirrel/sqvm.h | 7 +++++++ r5dev/tier0/platform_internal.h | 7 ++++++- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/r5dev/squirrel/sqstdaux.cpp b/r5dev/squirrel/sqstdaux.cpp index af16e2df..705963b9 100644 --- a/r5dev/squirrel/sqstdaux.cpp +++ b/r5dev/squirrel/sqstdaux.cpp @@ -21,7 +21,6 @@ SQInteger sqstd_aux_printerror(HSQUIRRELVM v) SQInteger sqstd_aux_badlogic(HSQUIRRELVM v, __m128i* a2, __m128i* a3) { - g_bSQAuxBadLogic = true; SQInteger results = v_sqstd_aux_badlogic(v, a2, a3); return results; } diff --git a/r5dev/squirrel/sqvm.cpp b/r5dev/squirrel/sqvm.cpp index 762285de..2c0977ae 100644 --- a/r5dev/squirrel/sqvm.cpp +++ b/r5dev/squirrel/sqvm.cpp @@ -6,6 +6,7 @@ #include "core/stdafx.h" #include "core/logdef.h" +#include "tier0/platform_internal.h" #include "tier0/commandline.h" #include "tier1/cvar.h" #include "tier1/IConVar.h" @@ -283,6 +284,19 @@ void SQVM_CompileError(HSQUIRRELVM v, const SQChar* pszError, const SQChar* pszF Error(static_cast(context), "%s line [%d] column [%d]\n", pszFile, nLine, nColumn); } +//--------------------------------------------------------------------------------- +// Purpose: prints the logic error and context to the console +// Input : bPrompt - +//--------------------------------------------------------------------------------- +void SQVM_LogicError(SQBool bPrompt) +{ + if (*g_flErrorTimeStamp > 0.0 && (bPrompt || Plat_FloatTime() > *g_flErrorTimeStamp + 0.0)) + { + g_bSQAuxBadLogic = true; + } + v_SQVM_LogicError(bPrompt); +} + //--------------------------------------------------------------------------------- // Purpose: Returns the VM name by context // Input : context - @@ -326,6 +340,7 @@ void SQVM_Attach() DetourAttach((LPVOID*)&v_SQVM_PrintFunc, &SQVM_PrintFunc); DetourAttach((LPVOID*)&v_SQVM_WarningFunc, &SQVM_WarningFunc); DetourAttach((LPVOID*)&v_SQVM_CompileError, &SQVM_CompileError); + DetourAttach((LPVOID*)&v_SQVM_LogicError, &SQVM_LogicError); } //--------------------------------------------------------------------------------- void SQVM_Detach() @@ -333,4 +348,5 @@ void SQVM_Detach() DetourDetach((LPVOID*)&v_SQVM_PrintFunc, &SQVM_PrintFunc); DetourDetach((LPVOID*)&v_SQVM_WarningFunc, &SQVM_WarningFunc); DetourDetach((LPVOID*)&v_SQVM_CompileError, &SQVM_CompileError); + DetourDetach((LPVOID*)&v_SQVM_LogicError, &SQVM_LogicError); } diff --git a/r5dev/squirrel/sqvm.h b/r5dev/squirrel/sqvm.h index 4ed2e59c..3737b459 100644 --- a/r5dev/squirrel/sqvm.h +++ b/r5dev/squirrel/sqvm.h @@ -54,6 +54,9 @@ inline auto v_SQVM_WarningCmd = p_SQVM_WarningCmd.RCast(); +inline CMemory p_SQVM_LogicError; +inline auto v_SQVM_LogicError = p_SQVM_LogicError.RCast(); + SQRESULT SQVM_PrintFunc(HSQUIRRELVM v, SQChar* fmt, ...); SQRESULT SQVM_WarningFunc(HSQUIRRELVM v, SQInteger a2, SQInteger a3, SQInteger* nStringSize, SQChar** ppString); void SQVM_CompileError(HSQUIRRELVM v, const SQChar* pszError, const SQChar* pszFile, SQUnsignedInteger nLine, SQInteger nColumn); @@ -74,6 +77,7 @@ class HSQVM : public IDetour spdlog::debug("| FUN: SQVM_GetErrorLine : {:#18x} |\n", p_SQVM_GetErrorLine.GetPtr()); spdlog::debug("| FUN: SQVM_WarningCmd : {:#18x} |\n", p_SQVM_WarningCmd.GetPtr()); spdlog::debug("| FUN: SQVM_CompileError : {:#18x} |\n", p_SQVM_CompileError.GetPtr()); + spdlog::debug("| FUN: SQVM_LogicError : {:#18x} |\n", p_SQVM_LogicError.GetPtr()); spdlog::debug("+----------------------------------------------------------------+\n"); } virtual void GetFun(void) const @@ -82,8 +86,10 @@ class HSQVM : public IDetour p_SQVM_WarningFunc = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x4C\x89\x4C\x24\x20\x44\x89\x44\x24\x18\x89\x54\x24\x10\x53\x55\x56\x57\x41\x54\x41\x55\x41\x56\x41\x57\x48\x83\xEC\x00\x48\x8B"), "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx?xx"); #if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) p_SQVM_GetErrorLine = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x89\x5C\x24\x00\x48\x89\x74\x24\x00\x48\x89\x7C\x24\x00\x55\x41\x54\x41\x55\x41\x56\x41\x57\x48\x8D\xAC\x24\x00\x00\x00\x00\x48\x81\xEC\x00\x00\x00\x00\x83\x65\x90\xFC"), "xxxx?xxxx?xxxx?xxxxxxxxxxxxx????xxx????xxxx"); + p_SQVM_LogicError = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x83\xEC\x48\xF2\x0F\x10\x05\x00\x00\x00\x00"), "xxxxxxxx????"); #elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3) p_SQVM_GetErrorLine = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x8B\xC4\x55\x56\x48\x8D\xA8\x00\x00\x00\x00\x48\x81\xEC\x00\x00\x00\x00\x83\x65\x90\xFC"), "xxxxxxxx????xxx????xxxx"); + p_SQVM_LogicError = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x83\xEC\x38\xF2\x0F\x10\x05\x00\x00\x00\x00"), "xxxxxxxx????"); #endif p_SQVM_WarningCmd = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x40\x53\x48\x83\xEC\x30\x33\xDB\x48\x8D\x44\x24\x00\x4C\x8D\x4C\x24\x00"), "xxxxxxxxxxxx?xxxx?"); p_SQVM_CompileError = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x89\x5C\x24\x00\x48\x89\x6C\x24\x00\x48\x89\x74\x24\x00\x48\x89\x7C\x24\x00\x41\x56\x48\x81\xEC\x00\x00\x00\x00\x48\x8B\xD9\x4C\x8B\xF2"), "xxxx?xxxx?xxxx?xxxx?xxxxx????xxxxxx"); @@ -93,6 +99,7 @@ class HSQVM : public IDetour v_SQVM_GetErrorLine = p_SQVM_GetErrorLine.RCast(); /*48 8B C4 55 56 48 8D A8 ?? ?? ?? ?? 48 81 EC ?? ?? ?? ?? 83 65 90 FC*/ v_SQVM_WarningCmd = p_SQVM_WarningCmd.RCast(); /*40 53 48 83 EC 30 33 DB 48 8D 44 24 ?? 4C 8D 4C 24 ??*/ v_SQVM_CompileError = p_SQVM_CompileError.RCast(); /*48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 48 89 7C 24 ? 41 56 48 81 EC ? ? ? ? 48 8B D9 4C 8B F2*/ + v_SQVM_LogicError = p_SQVM_LogicError.RCast(); /*48 83 EC 38 F2 0F 10 05 ? ? ? ?*/ } virtual void GetVar(void) const { } virtual void GetCon(void) const { } diff --git a/r5dev/tier0/platform_internal.h b/r5dev/tier0/platform_internal.h index 7939b8b1..fc2d402c 100644 --- a/r5dev/tier0/platform_internal.h +++ b/r5dev/tier0/platform_internal.h @@ -7,6 +7,7 @@ inline auto v_Plat_FloatTime = p_Plat_FloatTime.RCast(); inline CMemory p_Plat_MSTime; inline auto v_Plat_MSTime = p_Plat_MSTime.RCast(); +inline double* g_flErrorTimeStamp = nullptr; /////////////////////////////////////////////////////////////////////////////// class VPlatform : public IDetour { @@ -14,6 +15,7 @@ class VPlatform : public IDetour { spdlog::debug("| FUN: Plat_FloatTime : {:#18x} |\n", p_Plat_FloatTime.GetPtr()); spdlog::debug("| FUN: Plat_MSTime : {:#18x} |\n", p_Plat_MSTime.GetPtr()); + spdlog::debug("| VAR: g_flErrorTimeStamp : {:#18x} |\n", reinterpret_cast(g_flErrorTimeStamp)); spdlog::debug("+----------------------------------------------------------------+\n"); } virtual void GetFun(void) const @@ -24,7 +26,10 @@ class VPlatform : public IDetour v_Plat_FloatTime = p_Plat_FloatTime.RCast(); /*48 83 EC 28 80 3D ? ? ? ? ? 75 05 E8 ? ? ? ? 80 3D ? ? ? ? ? 74 1D*/ v_Plat_MSTime = p_Plat_MSTime.RCast(); /*48 83 EC 28 80 3D ? ? ? ? ? 75 05 E8 ? ? ? ? 80 3D ? ? ? ? ? 74 2A*/ } - virtual void GetVar(void) const { } + virtual void GetVar(void) const + { + g_flErrorTimeStamp = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x0F\x57\xC0\xF2\x0F\x11\x05\x00\x00\x00\x00\xC3"), "xxxxxxx????x").FindPatternSelf("F2 0F").ResolveRelativeAddressSelf(0x4, 0x8).RCast(); + } virtual void GetCon(void) const { } virtual void Attach(void) const { } virtual void Detach(void) const { }