From 2d87e082f1d75072e8fb60a3cca167d8d7b61c5f Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 2 Apr 2023 17:11:14 +0200 Subject: [PATCH] /W4: Fix unreferenced symbol bugs Fixed bugs that was caused by symbols that were defined, but never used. * 'UnsignedIntConvertToFltSIMD' never used its input parameter. * The results from the call to 'sq_call' were never checked, so if a failure took place, it was never logged. * 'CheckForWarnings' never used the 'context' parameter, but this was required as context types of 'eDLL_T::SYSTEM_WARNING' or 'context == eDLL_T::SYSTEM_ERROR', should be returning the warning/error color as well. * Renamed 'GetHiddenServerConnectStatus' to 'GetHiddenServerName' and added more dedicated error handling within its logic, as the results from the call 'g_pMasterServer->GetServerByToken' was never checked. --- r5dev/mathlib/ssemath.h | 12 ++++++------ r5dev/squirrel/sqinit.cpp | 33 ++++++++++++++++++++++++++++----- r5dev/squirrel/sqinit.h | 2 +- r5dev/squirrel/sqscript.cpp | 11 ++++++++--- r5dev/squirrel/sqvm.cpp | 1 + r5dev/tier0/dbg.cpp | 4 ++-- 6 files changed, 46 insertions(+), 17 deletions(-) diff --git a/r5dev/mathlib/ssemath.h b/r5dev/mathlib/ssemath.h index b8ed98d1..b47adab2 100644 --- a/r5dev/mathlib/ssemath.h +++ b/r5dev/mathlib/ssemath.h @@ -4302,10 +4302,10 @@ FORCEINLINE fltx4 LoadGatherSIMD(const float& x, const float& y, const float& z, FORCEINLINE fltx4 UnsignedIntConvertToFltSIMD(const u32x4& vSrcA) { fltx4 retval; - SubFloat(retval, 0) = ((float)SubInt(retval, 0)); - SubFloat(retval, 1) = ((float)SubInt(retval, 1)); - SubFloat(retval, 2) = ((float)SubInt(retval, 2)); - SubFloat(retval, 3) = ((float)SubInt(retval, 3)); + SubFloat(retval, 0) = ((float)SubInt(vSrcA, 0)); + SubFloat(retval, 1) = ((float)SubInt(vSrcA, 1)); + SubFloat(retval, 2) = ((float)SubInt(vSrcA, 2)); + SubFloat(retval, 3) = ((float)SubInt(vSrcA, 3)); return retval; } @@ -5573,7 +5573,7 @@ inline fltx4 SimpleSpline(const fltx4& value) // remaps a value in [startInterval, startInterval+rangeInterval] from linear to // spline using SimpleSpline inline fltx4 SimpleSplineRemapValWithDeltas(const fltx4& val, - const fltx4& A, const fltx4& BMinusA, + const fltx4& A, /*const fltx4& BMinusA,*/ const fltx4& OneOverBMinusA, const fltx4& C, const fltx4& DMinusC) { @@ -5584,7 +5584,7 @@ inline fltx4 SimpleSplineRemapValWithDeltas(const fltx4& val, } inline fltx4 SimpleSplineRemapValWithDeltasClamped(const fltx4& val, - const fltx4& A, const fltx4& BMinusA, + const fltx4& A, /*const fltx4& BMinusA,*/ const fltx4& OneOverBMinusA, const fltx4& C, const fltx4& DMinusC) { diff --git a/r5dev/squirrel/sqinit.cpp b/r5dev/squirrel/sqinit.cpp index 2c0e9327..055c0eaf 100644 --- a/r5dev/squirrel/sqinit.cpp +++ b/r5dev/squirrel/sqinit.cpp @@ -525,7 +525,7 @@ namespace VSquirrel } else { - DevMsg(eDLL_T::UI, "Failed to connect to private server: %s\n", hiddenServerRequestMessage.c_str()); + Warning(eDLL_T::UI, "Failed to connect to private server: %s\n", hiddenServerRequestMessage.c_str()); } return SQ_OK; @@ -534,7 +534,7 @@ namespace VSquirrel //----------------------------------------------------------------------------- // Purpose: get response from private server request //----------------------------------------------------------------------------- - SQRESULT GetHiddenServerConnectStatus(HSQUIRRELVM v) + SQRESULT GetHiddenServerName(HSQUIRRELVM v) { SQChar* privateToken = sq_getstring(v, 1); @@ -545,14 +545,37 @@ namespace VSquirrel NetGameServer_t serverListing; bool result = g_pMasterServer->GetServerByToken(serverListing, hiddenServerRequestMessage, privateToken); // Send token connect request. - if (!serverListing.m_svHostName.empty()) + if (!result) { - hiddenServerRequestMessage = Format("Found server: %s", serverListing.m_svHostName.c_str()); + if (hiddenServerRequestMessage.empty()) + { + sq_pushstring(v, "Request failed", -1); + } + else + { + hiddenServerRequestMessage = Format("Request failed: %s", hiddenServerRequestMessage.c_str()); + sq_pushstring(v, hiddenServerRequestMessage.c_str(), -1); + } + + return SQ_OK; + } + + if (serverListing.m_svHostName.empty()) + { + if (hiddenServerRequestMessage.empty()) + { + hiddenServerRequestMessage = Format("Server listing empty"); + } + else + { + hiddenServerRequestMessage = Format("Server listing empty: %s", hiddenServerRequestMessage.c_str()); + } + sq_pushstring(v, hiddenServerRequestMessage.c_str(), -1); } else { - hiddenServerRequestMessage = Format("Server not found: %s", hiddenServerRequestMessage.c_str()); + hiddenServerRequestMessage = Format("Found server: %s", serverListing.m_svHostName.c_str()); sq_pushstring(v, hiddenServerRequestMessage.c_str(), -1); } diff --git a/r5dev/squirrel/sqinit.h b/r5dev/squirrel/sqinit.h index 4e2cff07..fcb11c36 100644 --- a/r5dev/squirrel/sqinit.h +++ b/r5dev/squirrel/sqinit.h @@ -60,7 +60,7 @@ namespace VSquirrel SQRESULT ConnectToListedServer(HSQUIRRELVM v); SQRESULT CreateServer(HSQUIRRELVM v); SQRESULT ConnectToHiddenServer(HSQUIRRELVM v); - SQRESULT GetHiddenServerConnectStatus(HSQUIRRELVM v); + SQRESULT GetHiddenServerName(HSQUIRRELVM v); SQRESULT ConnectToServer(HSQUIRRELVM v); } #endif // !DEDICATED diff --git a/r5dev/squirrel/sqscript.cpp b/r5dev/squirrel/sqscript.cpp index e453aa68..9386dc77 100644 --- a/r5dev/squirrel/sqscript.cpp +++ b/r5dev/squirrel/sqscript.cpp @@ -121,12 +121,12 @@ void Script_RegisterUIFunctions(CSquirrelVM* s) Script_RegisterFunction(s, "GetPromoData", "Script_GetPromoData", "Gets promo data for specified slot type", "string", "int", &VSquirrel::UI::GetPromoData); // Functions for connecting to servers - Script_RegisterFunction(s, "CreateServer", "Script_CreateServer", "Start server with the specified settings", "void", "string, string, string, string, int", &VSquirrel::UI::CreateServer); + Script_RegisterFunction(s, "CreateServer", "Script_CreateServer", "Starts server with the specified settings", "void", "string, string, string, string, int", &VSquirrel::UI::CreateServer); Script_RegisterFunction(s, "ConnectToServer", "Script_ConnectToServer", "Joins server by ip address and encryption key", "void", "string, string", &VSquirrel::UI::ConnectToServer); Script_RegisterFunction(s, "ConnectToListedServer", "Script_ConnectToListedServer", "Joins listed server by index", "void", "int", &VSquirrel::UI::ConnectToListedServer); Script_RegisterFunction(s, "ConnectToHiddenServer", "Script_ConnectToHiddenServer", "Joins hidden server by token", "void", "string", &VSquirrel::UI::ConnectToHiddenServer); - Script_RegisterFunction(s, "GetHiddenServerConnectStatus", "Script_GetHiddenServerConnectStatus", "Gets hidden server join status message", "string", "string", &VSquirrel::UI::GetHiddenServerConnectStatus); + Script_RegisterFunction(s, "GetHiddenServerName", "Script_GetHiddenServerName", "Gets hidden server name by token", "string", "string", &VSquirrel::UI::GetHiddenServerName); Script_RegisterFunction(s, "GetAvailableMaps", "Script_GetAvailableMaps", "Gets an array of all available maps", "array< string >", "", &VSquirrel::SHARED::GetAvailableMaps); Script_RegisterFunction(s, "GetAvailablePlaylists", "Script_GetAvailablePlaylists", "Gets an array of all available playlists", "array< string >", "", &VSquirrel::SHARED::GetAvailablePlaylists); #ifndef CLIENT_DLL @@ -312,10 +312,15 @@ void Script_Execute(const SQChar* code, const SQCONTEXT context) SQBufState bufState = SQBufState(code); SQRESULT compileResult = sq_compilebuffer(v, &bufState, "console", -1); - if (compileResult >= NULL) + if (SQ_SUCCEEDED(compileResult)) { sq_pushroottable(v); SQRESULT callResult = sq_call(v, 1, false, false); + + if (!SQ_SUCCEEDED(callResult)) + { + Error(eDLL_T::ENGINE, NO_ERROR, "Failed to execute %s script \"%s\"\n", SQVM_GetContextName(context), code); + } } } diff --git a/r5dev/squirrel/sqvm.cpp b/r5dev/squirrel/sqvm.cpp index 7420d8d0..2fc20d1b 100644 --- a/r5dev/squirrel/sqvm.cpp +++ b/r5dev/squirrel/sqvm.cpp @@ -33,6 +33,7 @@ SQRESULT SQVM_PrintFunc(HSQUIRRELVM v, SQChar* fmt, ...) { eDLL_T remoteContext; // We use the sqvm pointer as index for SDK usage as the function prototype has to match assembly. + // The compiler 'pointer truncation' warning couldn't be avoided, but it's safe to ignore it. switch (static_cast(reinterpret_cast(v))) { case SQCONTEXT::SERVER: diff --git a/r5dev/tier0/dbg.cpp b/r5dev/tier0/dbg.cpp index 5102b573..7f7ac3ca 100644 --- a/r5dev/tier0/dbg.cpp +++ b/r5dev/tier0/dbg.cpp @@ -117,11 +117,11 @@ bool HushAsserts() ImVec4 CheckForWarnings(LogType_t type, eDLL_T context, const ImVec4& defaultCol) { ImVec4 color = defaultCol; - if (type == LogType_t::LOG_WARNING) + if (type == LogType_t::LOG_WARNING || context == eDLL_T::SYSTEM_WARNING) { color = ImVec4(1.00f, 1.00f, 0.00f, 0.80f); } - else if (type == LogType_t::LOG_ERROR) + else if (type == LogType_t::LOG_ERROR || context == eDLL_T::SYSTEM_ERROR) { color = ImVec4(1.00f, 0.00f, 0.00f, 0.80f); }