From 8fde529e2b3f86a92d5f1c86fd506ad07f7195a6 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Mon, 8 Aug 2022 17:49:46 +0200 Subject: [PATCH] Print script errors to the console at all times This change prints script errors and their callstack to the console even when sq_showvmoutput < 2 (this avoids confusion when running a dedicated server and the server 'appears' to shutdown the game on its own. You could also check the script log files which are written to at all times, but having some indication is nice). --- r5dev/squirrel/sqstdaux.cpp | 4 ++++ r5dev/squirrel/sqstdaux.h | 3 +++ r5dev/squirrel/sqvm.cpp | 10 ++++++++-- r5dev/squirrel/sqvm.h | 13 +++++++++++-- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/r5dev/squirrel/sqstdaux.cpp b/r5dev/squirrel/sqstdaux.cpp index 705963b9..d4a85267 100644 --- a/r5dev/squirrel/sqstdaux.cpp +++ b/r5dev/squirrel/sqstdaux.cpp @@ -11,6 +11,8 @@ bool g_bSQAuxError = false; bool g_bSQAuxBadLogic = false; +HSQUIRRELVM g_pErrorVM = nullptr; + SQInteger sqstd_aux_printerror(HSQUIRRELVM v) { g_bSQAuxError = true; @@ -21,6 +23,8 @@ SQInteger sqstd_aux_printerror(HSQUIRRELVM v) SQInteger sqstd_aux_badlogic(HSQUIRRELVM v, __m128i* a2, __m128i* a3) { + g_pErrorVM = v; + SQInteger results = v_sqstd_aux_badlogic(v, a2, a3); return results; } diff --git a/r5dev/squirrel/sqstdaux.h b/r5dev/squirrel/sqstdaux.h index 8a702ad6..ec480b7c 100644 --- a/r5dev/squirrel/sqstdaux.h +++ b/r5dev/squirrel/sqstdaux.h @@ -1,6 +1,9 @@ #pragma once +#include "sqtype.h" + extern bool g_bSQAuxError; extern bool g_bSQAuxBadLogic; +extern HSQUIRRELVM g_pErrorVM; inline CMemory p_sqstd_aux_printerror; inline auto v_sqstd_aux_printerror = p_sqstd_aux_printerror.RCast(); diff --git a/r5dev/squirrel/sqvm.cpp b/r5dev/squirrel/sqvm.cpp index 6cb515ba..fd994073 100644 --- a/r5dev/squirrel/sqvm.cpp +++ b/r5dev/squirrel/sqvm.cpp @@ -105,7 +105,8 @@ SQRESULT SQVM_PrintFunc(HSQUIRRELVM v, SQChar* fmt, ...) if (sq_showvmoutput->GetInt() > 0) { sqlogger->debug(vmStr); } - if (sq_showvmoutput->GetInt() > 1) + if (sq_showvmoutput->GetInt() > 1 || + (g_bSQAuxError || g_bSQAuxBadLogic && v == g_pErrorVM)) { bool bError = false; bool bColorOverride = false; @@ -334,10 +335,15 @@ void SQVM_CompileError(HSQUIRRELVM v, const SQChar* pszError, const SQChar* pszF //--------------------------------------------------------------------------------- void SQVM_LogicError(SQBool bPrompt) { - if (*g_flErrorTimeStamp > 0.0 && (bPrompt || Plat_FloatTime() > *g_flErrorTimeStamp + 0.0)) + if ((*g_flErrorTimeStamp) > 0.0 && (bPrompt || Plat_FloatTime() > (*g_flErrorTimeStamp) + 0.0)) { g_bSQAuxBadLogic = true; } + else + { + g_bSQAuxBadLogic = false; + g_pErrorVM = nullptr; + } v_SQVM_LogicError(bPrompt); } diff --git a/r5dev/squirrel/sqvm.h b/r5dev/squirrel/sqvm.h index 00044adc..32e50016 100644 --- a/r5dev/squirrel/sqvm.h +++ b/r5dev/squirrel/sqvm.h @@ -11,12 +11,21 @@ struct SQVM { return _vftable; } -#if !defined (GAMEDLL_S0) && !defined (GAMEDLL_S1) && !defined (GAMEDLL_S2) SQCONTEXT GetContext() const { +#if !defined (GAMEDLL_S0) && !defined (GAMEDLL_S1) && !defined (GAMEDLL_S2) return _contextidx; +#else // This is the only way to obtain the context directly in anything _contextname, "SERVER") == 0) + return SQCONTEXT::SERVER; + if (strcmp(_sharedstate->_contextname, "CLIENT") == 0) + return SQCONTEXT::CLIENT; + if (strcmp(_sharedstate->_contextname, "UI") == 0) + return SQCONTEXT::UI; + + return SQCONTEXT::NONE; +#endif // !GAMEDLL_S0 && !GAMEDLL_S1 && !GAMEDLL_S2 } -#endif SQVM* _vftable; _BYTE gap000[16];