From 1d41b23abb8f30fa91d27a44b6f31e9a3f28e81f Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sat, 16 Sep 2023 00:45:11 +0200 Subject: [PATCH] Make sure language is never NULL * Initialize CPylon::m_Language to "english". * Make sure cvar change callback is always setting values instead of returning out early. --- r5dev/common/callback.cpp | 31 +++++++++---------------------- r5dev/localize/localize.cpp | 11 +++++++++++ r5dev/localize/localize.h | 3 +++ r5dev/networksystem/pylon.h | 3 +++ 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/r5dev/common/callback.cpp b/r5dev/common/callback.cpp index b9cb18d1..9baa3340 100644 --- a/r5dev/common/callback.cpp +++ b/r5dev/common/callback.cpp @@ -30,6 +30,7 @@ #include "filesystem/filesystem.h" #include "vpklib/packedstore.h" #include "vscript/vscript.h" +#include "localize/localize.h" #include "ebisusdk/EbisuSDK.h" #ifndef DEDICATED #include "geforce/reflex.h" @@ -1023,37 +1024,23 @@ void GFX_NVN_Changed_f(IConVar* pConVar, const char* pOldString, float flOldValu } #endif // !DEDICATED -static bool IsValidTextLanguage(const char* pLocaleName) -{ - for (int i = 0; i < SDK_ARRAYSIZE(g_LanguageNames); ++i) - { - if (strcmp(pLocaleName, g_LanguageNames[i]) == NULL) - return true; - } - - return false; -} - void LanguageChanged_f(IConVar* pConVar, const char* pOldString, float flOldValue) { if (ConVar* pConVarRef = g_pCVar->FindVar(pConVar->GetCommandName())) { const char* pNewString = pConVarRef->GetString(); - if (IsValidTextLanguage(pNewString)) - return; - - // if new text isn't valid but the old value is, reset the value - if (IsValidTextLanguage(pOldString)) + if (!Localize_IsLanguageSupported(pNewString)) { - pConVarRef->SetValue(pOldString); - return; + // if new text isn't valid but the old value is, reset the value + if (Localize_IsLanguageSupported(pOldString)) + pNewString = pOldString; + else // this shouldn't really happen, but if neither the old nor new values are valid, set to english + pNewString = g_LanguageNames[0]; } - else // this shouldn't really happen, but if neither the old nor new values are valid, set to english - pConVarRef->SetValue("english"); - - g_pMasterServer->SetLanguage(pConVarRef->GetString()); + pConVarRef->SetValue(pNewString); + g_pMasterServer->SetLanguage(pNewString); } } diff --git a/r5dev/localize/localize.cpp b/r5dev/localize/localize.cpp index f1823b12..d770831b 100644 --- a/r5dev/localize/localize.cpp +++ b/r5dev/localize/localize.cpp @@ -30,6 +30,17 @@ bool Localize_LoadLocalizationFileLists(CLocalize* thisptr) return true; } +bool Localize_IsLanguageSupported(const char* pLocaleName) +{ + for (int i = 0; i < SDK_ARRAYSIZE(g_LanguageNames); ++i) + { + if (strcmp(pLocaleName, g_LanguageNames[i]) == NULL) + return true; + } + + return false; +} + void VLocalize::Attach() const { DetourAttach((LPVOID*)&v_CLocalize__LoadLocalizationFileLists, &Localize_LoadLocalizationFileLists); diff --git a/r5dev/localize/localize.h b/r5dev/localize/localize.h index be9ca839..08c06401 100644 --- a/r5dev/localize/localize.h +++ b/r5dev/localize/localize.h @@ -1,4 +1,7 @@ #pragma once +#include "localize/ilocalize.h" + +bool Localize_IsLanguageSupported(const char* pLocaleName); class CLocalize { diff --git a/r5dev/networksystem/pylon.h b/r5dev/networksystem/pylon.h index e8ed3e22..ec6b40f7 100644 --- a/r5dev/networksystem/pylon.h +++ b/r5dev/networksystem/pylon.h @@ -2,10 +2,13 @@ #include "thirdparty/curl/include/curl/curl.h" #include "bansystem.h" #include "serverlisting.h" +#include "localize/ilocalize.h" class CPylon { public: + CPylon() { m_Language = g_LanguageNames[0]; } + vector GetServerList(string& outMessage) const; bool GetServerByToken(NetGameServer_t& slOutServer, string& outMessage, const string& svToken) const; bool PostServerHost(string& outMessage, string& svOutToken, const NetGameServer_t& netGameServer) const;