aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/shared/exploit_fixes
diff options
context:
space:
mode:
Diffstat (limited to 'NorthstarDLL/shared/exploit_fixes')
-rw-r--r--NorthstarDLL/shared/exploit_fixes/ns_limits.cpp44
1 files changed, 24 insertions, 20 deletions
diff --git a/NorthstarDLL/shared/exploit_fixes/ns_limits.cpp b/NorthstarDLL/shared/exploit_fixes/ns_limits.cpp
index 49f80bab..135cfb83 100644
--- a/NorthstarDLL/shared/exploit_fixes/ns_limits.cpp
+++ b/NorthstarDLL/shared/exploit_fixes/ns_limits.cpp
@@ -4,7 +4,6 @@
#include "client/r2client.h"
#include "engine/r2engine.h"
#include "server/r2server.h"
-#include "shared/maxplayers.h"
#include "core/tier0.h"
#include "core/math/vector.h"
#include "server/auth/serverauthentication.h"
@@ -13,22 +12,26 @@ AUTOHOOK_INIT()
ServerLimitsManager* g_pServerLimits;
+float (*CEngineServer__GetTimescale)();
+
// todo: make this work on higher timescales, also possibly disable when sv_cheats is set
void ServerLimitsManager::RunFrame(double flCurrentTime, float flFrameTime)
{
if (Cvar_sv_antispeedhack_enable->GetBool())
{
// for each player, set their usercmd processing budget for the frame to the last frametime for the server
- for (int i = 0; i < R2::GetMaxPlayers(); i++)
+ for (int i = 0; i < R2::g_pGlobals->m_nMaxClients; i++)
{
R2::CBaseClient* player = &R2::g_pClientArray[i];
if (m_PlayerLimitData.find(player) != m_PlayerLimitData.end())
{
PlayerLimitData* pLimitData = &g_pServerLimits->m_PlayerLimitData[player];
- if (pLimitData->flFrameUserCmdBudget < 0.016666667 * Cvar_sv_antispeedhack_maxtickbudget->GetFloat())
- pLimitData->flFrameUserCmdBudget +=
- fmax(flFrameTime, 0.016666667) * g_pServerLimits->Cvar_sv_antispeedhack_budgetincreasemultiplier->GetFloat();
+ if (pLimitData->flFrameUserCmdBudget < R2::g_pGlobals->m_flTickInterval * Cvar_sv_antispeedhack_maxtickbudget->GetFloat())
+ {
+ pLimitData->flFrameUserCmdBudget += g_pServerLimits->Cvar_sv_antispeedhack_budgetincreasemultiplier->GetFloat() *
+ fmax(flFrameTime, R2::g_pGlobals->m_flFrameTime * CEngineServer__GetTimescale());
+ }
}
}
}
@@ -37,7 +40,8 @@ void ServerLimitsManager::RunFrame(double flCurrentTime, float flFrameTime)
void ServerLimitsManager::AddPlayer(R2::CBaseClient* player)
{
PlayerLimitData limitData;
- limitData.flFrameUserCmdBudget = 0.016666667 * Cvar_sv_antispeedhack_maxtickbudget->GetFloat();
+ limitData.flFrameUserCmdBudget =
+ R2::g_pGlobals->m_flTickInterval * CEngineServer__GetTimescale() * Cvar_sv_antispeedhack_maxtickbudget->GetFloat();
m_PlayerLimitData.insert(std::make_pair(player, limitData));
}
@@ -53,10 +57,10 @@ bool ServerLimitsManager::CheckStringCommandLimits(R2::CBaseClient* player)
if (CVar_sv_quota_stringcmdspersecond->GetInt() != -1)
{
// note: this isn't super perfect, legit clients can trigger it in lobby if they try, mostly good enough tho imo
- if (Tier0::Plat_FloatTime() - m_PlayerLimitData[player].lastClientCommandQuotaStart >= 1.0)
+ if (R2::g_pGlobals->m_flCurTime - m_PlayerLimitData[player].lastClientCommandQuotaStart >= 1.0)
{
// reset quota
- m_PlayerLimitData[player].lastClientCommandQuotaStart = Tier0::Plat_FloatTime();
+ m_PlayerLimitData[player].lastClientCommandQuotaStart = R2::g_pGlobals->m_flCurTime;
m_PlayerLimitData[player].numClientCommandsInQuota = 0;
}
@@ -73,9 +77,9 @@ bool ServerLimitsManager::CheckStringCommandLimits(R2::CBaseClient* player)
bool ServerLimitsManager::CheckChatLimits(R2::CBaseClient* player)
{
- if (Tier0::Plat_FloatTime() - m_PlayerLimitData[player].lastSayTextLimitStart >= 1.0)
+ if (R2::g_pGlobals->m_flCurTime - m_PlayerLimitData[player].lastSayTextLimitStart >= 1.0)
{
- m_PlayerLimitData[player].lastSayTextLimitStart = Tier0::Plat_FloatTime();
+ m_PlayerLimitData[player].lastSayTextLimitStart = R2::g_pGlobals->m_flCurTime;
m_PlayerLimitData[player].sayTextLimitCount = 0;
}
@@ -97,7 +101,7 @@ char, __fastcall, (void* self, void* buf))
NETCHANLIMIT_KICK
};
- double startTime = Tier0::Plat_FloatTime();
+ double startTime = R2::g_pGlobals->m_flCurTime;
char ret = CNetChan__ProcessMessages(self, buf);
// check processing limits, unless we're in a level transition
@@ -118,7 +122,7 @@ char, __fastcall, (void* self, void* buf))
g_pServerLimits->m_PlayerLimitData[sender].lastNetChanProcessingLimitStart = startTime;
g_pServerLimits->m_PlayerLimitData[sender].netChanProcessingLimitTime = 0.0;
}
- g_pServerLimits->m_PlayerLimitData[sender].netChanProcessingLimitTime += (Tier0::Plat_FloatTime() * 1000) - (startTime * 1000);
+ g_pServerLimits->m_PlayerLimitData[sender].netChanProcessingLimitTime += (R2::g_pGlobals->m_flCurTime * 1000) - (startTime * 1000);
if (g_pServerLimits->m_PlayerLimitData[sender].netChanProcessingLimitTime >=
g_pServerLimits->Cvar_net_chan_limit_msec_per_sec->GetInt())
@@ -169,12 +173,12 @@ bool, , (void* a1, R2::netpacket_t* packet))
memcpy(sendData->ip, packet->adr.ip, 16);
}
- if (Tier0::Plat_FloatTime() < sendData->timeoutEnd)
+ if (R2::g_pGlobals->m_flCurTime < sendData->timeoutEnd)
return false;
- if (Tier0::Plat_FloatTime() - sendData->lastQuotaStart >= 1.0)
+ if (R2::g_pGlobals->m_flCurTime - sendData->lastQuotaStart >= 1.0)
{
- sendData->lastQuotaStart = Tier0::Plat_FloatTime();
+ sendData->lastQuotaStart = R2::g_pGlobals->m_flCurTime;
sendData->packetCount = 0;
}
@@ -188,7 +192,7 @@ bool, , (void* a1, R2::netpacket_t* packet))
packet->data[4]);
// timeout for a minute
- sendData->timeoutEnd = Tier0::Plat_FloatTime() + 60.0;
+ sendData->timeoutEnd = R2::g_pGlobals->m_flCurTime + 60.0;
return false;
}
}
@@ -250,8 +254,6 @@ void, __fastcall, (void* self, R2::CBasePlayer* player, SV_CUserCmd* pUserCmd, u
spdlog::warn("player {} went over usercmd budget ({})", pClient->m_Name, pLimitData->flFrameUserCmdBudget);
return;
}
- // else
- // spdlog::info("{}: {}", pClient->m_Name, pLimitData->flFrameUserCmdBudget);
}
}
@@ -284,12 +286,14 @@ ON_DLL_LOAD_RELIESON("engine.dll", ServerLimits, ConVar, (CModule module))
"sv_antispeedhack_maxtickbudget",
"64",
FCVAR_GAMEDLL,
- "Maximum number of client-issued usercmd ticks that can be replayed in packet loss conditions, 0 to allow no restrictions");
+ "Maximum number of client-issued usercmd ticks that can be replayed in packet loss conditions");
g_pServerLimits->Cvar_sv_antispeedhack_budgetincreasemultiplier = new ConVar(
"sv_antispeedhack_budgetincreasemultiplier",
- "1.2",
+ "1",
FCVAR_GAMEDLL,
"Increase usercmd processing budget by tickinterval * value per tick");
+
+ CEngineServer__GetTimescale = module.Offset(0x240840).As<float (*)()>();
}
ON_DLL_LOAD("server.dll", ServerLimitsServer, (CModule module))