From 162e709190df3e955167a890dd75fa174f3321ac Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 12 Jun 2022 17:41:26 +0200 Subject: [PATCH] General cleanup and improvements --- r5dev/squirrel/sqapi.h | 13 +++---------- r5dev/squirrel/sqtype.h | 10 +++++----- r5dev/tier0/dbg.cpp | 18 ++++++------------ r5dev/tier1/IConVar.cpp | 33 ++++++++++++++++++--------------- r5dev/tier1/IConVar.h | 2 +- r5dev/vgui/vgui_debugpanel.cpp | 2 +- r5dev/vgui/vgui_debugpanel.h | 6 +++--- 7 files changed, 37 insertions(+), 47 deletions(-) diff --git a/r5dev/squirrel/sqapi.h b/r5dev/squirrel/sqapi.h index 9e70d5e8..cbc3338a 100644 --- a/r5dev/squirrel/sqapi.h +++ b/r5dev/squirrel/sqapi.h @@ -29,13 +29,9 @@ inline auto v_sq_pushroottable = p_sq_pushroottable.RCast(); -#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) || defined (GAMEDLL_S2) inline CMemory p_sq_pushstring; inline auto v_sq_pushstring = p_sq_pushstring.RCast(); -#elif defined (GAMEDLL_S3) -inline CMemory p_sq_pushstring; -inline auto v_sq_pushstring = p_sq_pushstring.RCast(); -#endif + inline CMemory p_sq_pushinteger; inline auto v_sq_pushinteger = p_sq_pushinteger.RCast(); @@ -53,13 +49,10 @@ inline auto v_sq_newslot = p_sq_newslot.RCast(); -#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) || defined (GAMEDLL_S2) + inline CMemory p_sq_pushstructure; inline auto v_sq_pushstructure = p_sq_pushstructure.RCast(); -#elif defined (GAMEDLL_S3) -inline CMemory p_sq_pushstructure; -inline auto v_sq_pushstructure = p_sq_pushstructure.RCast(); -#endif + inline CMemory p_sq_compilebuffer; inline auto v_sq_compilebuffer = p_sq_compilebuffer.RCast(); diff --git a/r5dev/squirrel/sqtype.h b/r5dev/squirrel/sqtype.h index 5f767e4c..b52861a9 100644 --- a/r5dev/squirrel/sqtype.h +++ b/r5dev/squirrel/sqtype.h @@ -22,7 +22,7 @@ enum class SQCONTEXT : SQInteger NONE }; -const static std::string SQVM_TYPE_T[4] = +const static string SQVM_TYPE_T[4] = { "SERVER", "CLIENT", @@ -30,7 +30,7 @@ const static std::string SQVM_TYPE_T[4] = "NONE" }; -const static std::string SQVM_LOG_T[4] = +const static string SQVM_LOG_T[4] = { "Script(S):", "Script(C):", @@ -38,7 +38,7 @@ const static std::string SQVM_LOG_T[4] = "Script(X):" }; -const static std::string SQVM_ANSI_LOG_T[4] = +const static string SQVM_ANSI_LOG_T[4] = { "\033[38;2;151;149;187mScript(S):", "\033[38;2;151;149;163mScript(C):", @@ -46,7 +46,7 @@ const static std::string SQVM_ANSI_LOG_T[4] = "\033[38;2;151;149;163mScript(X):" }; -const static std::string SQVM_WARNING_ANSI_LOG_T[4] = +const static string SQVM_WARNING_ANSI_LOG_T[4] = { "\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", @@ -54,7 +54,7 @@ const static std::string SQVM_WARNING_ANSI_LOG_T[4] = "\033[38;2;151;149;163mScript(X):\033[38;2;255;255;000m" }; -const static std::string SQVM_ERROR_ANSI_LOG_T[4] = +const static 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", diff --git a/r5dev/tier0/dbg.cpp b/r5dev/tier0/dbg.cpp index c18e5dde..8dc47e21 100644 --- a/r5dev/tier0/dbg.cpp +++ b/r5dev/tier0/dbg.cpp @@ -108,8 +108,7 @@ void DevMsg(eDLL_T context, const char* fmt, ...) svOut.append(szBuf); svOut = std::regex_replace(svOut, rxAnsiExp, ""); - char szNewLine = svOut.back(); - if (szNewLine != '\n') + if (svOut.back() != '\n') { svOut.append("\n"); } @@ -126,8 +125,7 @@ void DevMsg(eDLL_T context, const char* fmt, ...) svAnsiOut = sANSI_DLL_T[static_cast(context)]; svAnsiOut.append(szBuf); - char szNewLine = svAnsiOut.back(); - if (szNewLine != '\n') + if (svAnsiOut.back() != '\n') { svAnsiOut.append("\n"); } @@ -216,8 +214,7 @@ void Warning(eDLL_T context, const char* fmt, ...) svOut.append(szBuf); svOut = std::regex_replace(svOut, rxAnsiExp, ""); - char szNewLine = svOut.back(); - if (szNewLine != '\n') + if (svOut.back() != '\n') { svOut.append("\n"); } @@ -235,8 +232,7 @@ void Warning(eDLL_T context, const char* fmt, ...) svAnsiOut.append(g_svYellowF); svAnsiOut.append(szBuf); - char szNewLine = svAnsiOut.back(); - if (szNewLine != '\n') + if (svAnsiOut.back() != '\n') { svAnsiOut.append("\n"); } @@ -293,8 +289,7 @@ void Error(eDLL_T context, const char* fmt, ...) svOut.append(szBuf); svOut = std::regex_replace(svOut, rxAnsiExp, ""); - char szNewLine = svOut.back(); - if (szNewLine != '\n') + if (svOut.back() != '\n') { svOut.append("\n"); } @@ -312,8 +307,7 @@ void Error(eDLL_T context, const char* fmt, ...) svAnsiOut.append(g_svRedF); svAnsiOut.append(szBuf); - char szNewLine = svAnsiOut.back(); - if (szNewLine != '\n') + if (svAnsiOut.back() != '\n') { svAnsiOut.append("\n"); } diff --git a/r5dev/tier1/IConVar.cpp b/r5dev/tier1/IConVar.cpp index e30dc07e..5ef64b5c 100644 --- a/r5dev/tier1/IConVar.cpp +++ b/r5dev/tier1/IConVar.cpp @@ -219,23 +219,22 @@ void ConVar::PurgeHostNames(void) const { const char* pszHostNames[] = { - "pin_telemetry_hostname", "assetdownloads_hostname", - "users_hostname", - "persistence_hostname", - "speechtotexttoken_hostname", "communities_hostname", - "persistenceDef_hostname", - "party_hostname", - "speechtotext_hostname", - "serverReports_hostname", - "subscription_hostname", - "steamlink_hostname", - "staticfile_hostname", "matchmaking_hostname", - "skill_hostname", + "party_hostname", + "persistence_hostname", + "persistenceDef_hostname", + "pin_telemetry_hostname", "publication_hostname", - "stats_hostname" + "serverReports_hostname", + "skill_hostname", + "speechtotext_hostname", + "staticfile_hostname", + "stats_hostname", + "steamlink_hostname", + "subscription_hostname", + "users_hostname" }; for (int i = 0; i < (&pszHostNames)[1] - pszHostNames; i++) @@ -720,7 +719,7 @@ void ConVar::ChangeStringValue(const char* pszTempVal, float flOldValue) if (pszTempVal) { - int len = strlen(pszTempVal) + 1; + size_t len = strlen(pszTempVal) + 1; if (len > m_Value.m_iStringLength) { @@ -732,7 +731,11 @@ void ConVar::ChangeStringValue(const char* pszTempVal, float flOldValue) m_Value.m_pszString = new char[len]; m_Value.m_iStringLength = len; } - + else if (!m_Value.m_pszString) + { + m_Value.m_pszString = new char[len]; + m_Value.m_iStringLength = len; + } memcpy(const_cast(m_Value.m_pszString), pszTempVal, len); } else diff --git a/r5dev/tier1/IConVar.h b/r5dev/tier1/IConVar.h index 43a29595..bfc25173 100644 --- a/r5dev/tier1/IConVar.h +++ b/r5dev/tier1/IConVar.h @@ -147,7 +147,7 @@ public: struct CVValue_t { const char* m_pszString; - int64_t m_iStringLength; + size_t m_iStringLength; float m_fValue; int m_nValue; }; diff --git a/r5dev/vgui/vgui_debugpanel.cpp b/r5dev/vgui/vgui_debugpanel.cpp index 2f16cfaf..4032924b 100644 --- a/r5dev/vgui/vgui_debugpanel.cpp +++ b/r5dev/vgui/vgui_debugpanel.cpp @@ -47,7 +47,7 @@ void CLogSystem::Update(void) //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- -void CLogSystem::AddLog(LogType_t type, std::string svMessage) +void CLogSystem::AddLog(LogType_t type, string svMessage) { if (svMessage.length() > 0) { diff --git a/r5dev/vgui/vgui_debugpanel.h b/r5dev/vgui/vgui_debugpanel.h index 51933994..69f1c75c 100644 --- a/r5dev/vgui/vgui_debugpanel.h +++ b/r5dev/vgui/vgui_debugpanel.h @@ -22,13 +22,13 @@ enum class LogType_t : int struct LogMsg_t { - LogMsg_t(const std::string svMessage, const int nTicks, const LogType_t type) + LogMsg_t(const string svMessage, const int nTicks, const LogType_t type) { this->m_svMessage = svMessage; this->m_nTicks = nTicks; this->m_type = type; } - std::string m_svMessage = ""; + string m_svMessage = ""; int m_nTicks = 1024; LogType_t m_type = LogType_t::NONE; }; @@ -37,7 +37,7 @@ class CLogSystem { public: void Update(void); - void AddLog(LogType_t type, std::string svText); + void AddLog(LogType_t type, string svText); void DrawLog(void); void DrawHostStats(void) const; void DrawSimStats(void) const;