A2S_Rules fix: Only change host_rules_show if patching was successful (#1459)

If lookup of the patch location failed, don't turn on responding to A2S_Rules queries. Otherwise we'll see the log getting spammed with too large packet sizes again. #1447
This commit is contained in:
peace-maker 2021-04-19 09:33:36 +02:00 committed by GitHub
parent 2b1cc43355
commit 1fbe5e1daa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,21 +46,21 @@ RulesFix::RulesFix() :
{
}
void SetMTUMax(int iValue)
bool SetMTUMax(int iValue)
{
static int iOriginalValue = -1;
static int *m_pMaxMTU = nullptr;
//If we never changed skip resetting
if (iOriginalValue == -1 && iValue == -1)
return;
return true;
if (m_pMaxMTU == nullptr)
{
if (!g_pGameConf->GetAddress("MaxMTU", (void **)&m_pMaxMTU))
{
g_pSM->LogMessage(myself, "[CStrike] Failed to locate NET_SendPacket signature.");
return;
return false;
}
SourceHook::SetMemAccess(m_pMaxMTU, sizeof(int), SH_MEM_READ | SH_MEM_WRITE | SH_MEM_EXEC);
@ -72,6 +72,7 @@ void SetMTUMax(int iValue)
*m_pMaxMTU = iOriginalValue;
else
*m_pMaxMTU = iValue;
return true;
}
void RulesFix::OnLoad()
@ -79,11 +80,12 @@ void RulesFix::OnLoad()
host_rules_show = g_pCVar->FindVar("host_rules_show");
if (host_rules_show)
{
// Default to enabled. Explicit disable via cfg will still be obeyed.
host_rules_show->SetValue(true);
SetMTUMax(5000);
bPatched = true;
if (SetMTUMax(5000))
{
// Default to enabled. Explicit disable via cfg will still be obeyed.
host_rules_show->SetValue(true);
bPatched = true;
}
}
SH_ADD_HOOK(IServerGameDLL, GameServerSteamAPIActivated, gamedll, SH_MEMBER(this, &RulesFix::Hook_GameServerSteamAPIActivated), true);
@ -122,17 +124,19 @@ static void OnConVarChanged(IConVar *var, const char *pOldValue, float flOldValu
{
if (!bPatched)
{
SetMTUMax(5000);
bPatched = true;
NotifyAllCVars();
if (SetMTUMax(5000))
{
bPatched = true;
NotifyAllCVars();
}
}
}
else
{
if (bPatched)
{
SetMTUMax(-1);
bPatched = false;
if (SetMTUMax(-1))
bPatched = false;
}
}
}