mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
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.
This commit is contained in:
parent
0634261c18
commit
1d41b23abb
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -1,4 +1,7 @@
|
||||
#pragma once
|
||||
#include "localize/ilocalize.h"
|
||||
|
||||
bool Localize_IsLanguageSupported(const char* pLocaleName);
|
||||
|
||||
class CLocalize
|
||||
{
|
||||
|
@ -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<NetGameServer_t> 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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user