Set execution markers properly (#849)

Set execution markers properly if there's enough room or ignore command otherwise.
Stops servers from executing commands on the client if not in vanilla.

Co-authored-by: RoyalBlue1 <11448698+RoyalBlue1@users.noreply.github.com>
This commit is contained in:
AllusiveWheat 2025-04-26 17:06:33 -07:00 committed by GitHub
parent 1277b3711d
commit 8290f7b3c0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -14,6 +14,8 @@ ConVar* Cvar_ns_should_log_all_clientcommands;
ConVar* Cvar_sv_cheats;
int* g_ExecutionMarkerCount;
#define BLOCKED_INFO(s) \
( \
[=]() -> bool \
@ -294,6 +296,24 @@ bool, __fastcall, (const char* pModName)) // 48 83 EC 28 48 8B 0D ? ? ? ? 48 8D
return (!strcmp("r2", pModName) || !strcmp("r1", pModName)) && !CommandLine()->CheckParm("-norestrictservercommands");
}
// Checks if there's room left for execution markers
bool Cbuf_HasRoomForExecutionMarkers(const int marker)
{
return (*g_ExecutionMarkerCount + marker) < 2048;
}
// Set execution markers properly if there's space
// If not enough space, ignore command
// clang-format off
AUTOHOOK(CBaseClientState_ProcessStringCmd, engine.dll + 0x1A1C20,
bool, __fastcall, (CBaseClient* self, int64_t a2))
// clang-format on
{
if (!Cbuf_HasRoomForExecutionMarkers(2))
return true;
return CBaseClientState_ProcessStringCmd(self, a2);
}
// ratelimit stringcmds, and prevent remote clients from calling commands that they shouldn't
// clang-format off
AUTOHOOK(CGameClient__ExecuteStringCommand, engine.dll + 0x1022E0,
@ -428,7 +448,7 @@ bool, __fastcall, (void* a1))
ON_DLL_LOAD("engine.dll", EngineExploitFixes, (CModule module))
{
AUTOHOOK_DISPATCH_MODULE(engine.dll)
g_ExecutionMarkerCount = module.Offset(0x130DE8F0).RCast<int*>();
// allow client/ui to run clientcommands despite restricting servercommands
module.Offset(0x4FB65).Patch("EB 11");
module.Offset(0x4FBAC).Patch("EB 16");