From 7fd33da180167880acf9b65a058b5b3359878edc Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Thu, 5 Dec 2024 13:25:49 +0100 Subject: [PATCH] Common: only rerun 'language->SetValue()' when provided language is unsuppported The function was always ran, but it should only be run if the language provided isn't supported. --- src/common/callback.cpp | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/common/callback.cpp b/src/common/callback.cpp index 58b6c99e..e08abdb4 100644 --- a/src/common/callback.cpp +++ b/src/common/callback.cpp @@ -231,28 +231,24 @@ void VPK_Unmount_f(const CCommand& args) void LanguageChanged_f(IConVar* pConVar, const char* pOldString, float flOldValue, ChangeUserData_t pUserData) { - if (ConVar* pConVarRef = g_pCVar->FindVar(pConVar->GetName())) + const char* pNewString = language_cvar->GetString(); + + if (strcmp(pOldString, pNewString) == NULL) + return; // Same language. + + if (!Localize_IsLanguageSupported(pNewString)) { - const char* pNewString = pConVarRef->GetString(); - - if (strcmp(pOldString, pConVarRef->GetString()) == NULL) - return; // Same language. - - if (!Localize_IsLanguageSupported(pNewString)) + // if new text isn't valid but the old value is, reset the value + if (Localize_IsLanguageSupported(pOldString)) + pNewString = pOldString; + else { - // 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 - Assert(0); - pNewString = g_LanguageNames[0]; - } + // this shouldn't really happen, but if neither the old nor new values are valid, set to english + Assert(0); + pNewString = g_LanguageNames[0]; } - pConVarRef->SetValue(pNewString); - g_MasterServer.SetLanguage(pNewString); + language_cvar->SetValue(pNewString); } }