diff options
author | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2023-02-12 21:15:00 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-12 21:15:00 +0000 |
commit | 95b41b6f8cc612953eafd7f8b6b40124e1590bc7 (patch) | |
tree | 400746bace6855c210e020a5ca93b84c2fdd0dc9 /NorthstarDLL/shared | |
parent | b61ed18a86ddd2d7ab0e80992859750a49a9c4f6 (diff) | |
download | NorthstarLauncher-95b41b6f8cc612953eafd7f8b6b40124e1590bc7.tar.gz NorthstarLauncher-95b41b6f8cc612953eafd7f8b6b40124e1590bc7.zip |
Add `CGlobals` class and `g_pGlobals`, and update code to support (#411)
* add CGlobals class and g_pGlobals, and update scripts to support
* don't automatically enable antispeedhack (oops)
* add dedicated.cpp
* format
* bad push oops
* reformat again
Diffstat (limited to 'NorthstarDLL/shared')
-rw-r--r-- | NorthstarDLL/shared/exploit_fixes/ns_limits.cpp | 44 | ||||
-rw-r--r-- | NorthstarDLL/shared/keyvalues.cpp | 19 | ||||
-rw-r--r-- | NorthstarDLL/shared/playlist.cpp | 3 |
3 files changed, 39 insertions, 27 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)) diff --git a/NorthstarDLL/shared/keyvalues.cpp b/NorthstarDLL/shared/keyvalues.cpp index fe7d6299..25155dde 100644 --- a/NorthstarDLL/shared/keyvalues.cpp +++ b/NorthstarDLL/shared/keyvalues.cpp @@ -211,8 +211,15 @@ KeyValues* KeyValues::FindKey(const char* pszKeyName, bool bCreate) return this; const char* pSubStr = strchr(pszKeyName, '/'); + const char* pSearchStr = pszKeyName; + if (pSubStr && !*(pSubStr + 1)) + { + // if key name is just '/', then use it as a key directly + pSearchStr = pSubStr; + pSubStr = nullptr; + } - HKeySymbol iSearchStr = KeyValuesSystem()->m_pVtable->GetSymbolForString(KeyValuesSystem(), pszKeyName, bCreate); + HKeySymbol iSearchStr = KeyValuesSystem()->m_pVtable->GetSymbolForString(KeyValuesSystem(), pSearchStr, bCreate); if (iSearchStr == INVALID_KEY_SYMBOL) { // not found, couldn't possibly be in key value list @@ -222,7 +229,7 @@ KeyValues* KeyValues::FindKey(const char* pszKeyName, bool bCreate) KeyValues* pLastKVs = nullptr; KeyValues* pCurrentKVs; // find the searchStr in the current peer list - for (pCurrentKVs = m_pSub; pCurrentKVs != NULL; pCurrentKVs = pCurrentKVs->m_pPeer) + for (pCurrentKVs = m_pSub; pCurrentKVs != nullptr; pCurrentKVs = pCurrentKVs->m_pPeer) { pLastKVs = pCurrentKVs; // record the last item looked at (for if we need to append to the end of the list) @@ -232,7 +239,7 @@ KeyValues* KeyValues::FindKey(const char* pszKeyName, bool bCreate) } if (!pCurrentKVs && m_pChain) - pCurrentKVs = m_pChain->FindKey(pszKeyName, false); + pCurrentKVs = m_pChain->FindKey(pSearchStr, false); // make sure a key was found if (!pCurrentKVs) @@ -240,7 +247,7 @@ KeyValues* KeyValues::FindKey(const char* pszKeyName, bool bCreate) if (bCreate) { // we need to create a new key - pCurrentKVs = new KeyValues(pszKeyName); + pCurrentKVs = new KeyValues(pSearchStr); // Assert(dat != NULL); // insert new key at end of list @@ -249,7 +256,7 @@ KeyValues* KeyValues::FindKey(const char* pszKeyName, bool bCreate) else m_pSub = pCurrentKVs; - pCurrentKVs->m_pPeer = NULL; + pCurrentKVs->m_pPeer = nullptr; // a key graduates to be a submsg as soon as it's m_pSub is set // this should be the only place m_pSub is set @@ -257,7 +264,7 @@ KeyValues* KeyValues::FindKey(const char* pszKeyName, bool bCreate) } else { - return NULL; + return nullptr; } } diff --git a/NorthstarDLL/shared/playlist.cpp b/NorthstarDLL/shared/playlist.cpp index 2fb856b3..7c8f7312 100644 --- a/NorthstarDLL/shared/playlist.cpp +++ b/NorthstarDLL/shared/playlist.cpp @@ -4,6 +4,7 @@ #include "core/convar/convar.h" #include "squirrel/squirrel.h" #include "engine/hoststate.h" +#include "engine/r2engine.h" #include "server/serverpresence.h" AUTOHOOK_INIT() @@ -26,7 +27,7 @@ char, __fastcall, (void* a1, void* a2)) { // the private_match playlist on mp_lobby is the only situation where there should be any legitimate sending of this netmessage if (!Cvar_ns_use_clc_SetPlaylistVarOverride->GetBool() || strcmp(R2::GetCurrentPlaylistName(), "private_match") || - strcmp(R2::g_pHostState->m_levelName, "mp_lobby")) + strcmp(R2::g_pGlobals->m_pMapName, "mp_lobby")) return 1; return clc_SetPlaylistVarOverride__Process(a1, a2); |