initial commit -- v1 code

This commit is contained in:
2026-08-10 14:21:07 +02:00
commit 1ecb7f777e
25 changed files with 2472 additions and 0 deletions

69
src/detour.cpp Normal file
View File

@@ -0,0 +1,69 @@
#include "detour.h"
#include "common.h"
#include "gameconfig.h"
#include "overrides.h"
#include "playerslot.h"
extern CGameConfig* g_gameConfig;
extern bool g_enabled;
extern bool g_armed;
using SendSnapshotFn = void (*)(void*, void*);
static SendSnapshotFn g_sendSnapshot = nullptr;
static funchook_t* g_hook = nullptr;
static CPlayerSlot SlotFromClient(void* client)
{
int offset = g_gameConfig ? g_gameConfig->GetOffset("CServerSideClient_Slot") : -1;
if (offset < 0)
return CPlayerSlot(-1);
return *reinterpret_cast<CPlayerSlot*>(reinterpret_cast<uint8_t*>(client) + offset);
}
static void Detour_SendSnapshot(void* client, void* snapshot)
{
if (!g_enabled || !g_armed || !client || g_overrides.Empty())
{
g_sendSnapshot(client, snapshot);
return;
}
CPlayerSlot slot = SlotFromClient(client);
auto applied = g_overrides.ApplyForRecipient(slot);
g_sendSnapshot(client, snapshot);
g_overrides.Restore(applied);
}
bool InitSnapshotDetour(CGameConfig* config)
{
void* target = config->ResolveSignature("CServerSideClient_SendSnapshot");
if (!target)
{
SPWarning("CServerSideClient_SendSnapshot signature missing; snapshot hook disabled\n");
return true;
}
g_sendSnapshot = reinterpret_cast<SendSnapshotFn>(target);
g_hook = funchook_create();
if (!g_hook)
return false;
if (funchook_prepare(g_hook, reinterpret_cast<void**>(&g_sendSnapshot), reinterpret_cast<void*>(Detour_SendSnapshot)) != 0)
return false;
if (funchook_install(g_hook, 0) != 0)
return false;
SPMessage("detoured CServerSideClient_SendSnapshot at %p\n", target);
return true;
}
void ShutdownSnapshotDetour()
{
if (!g_hook)
return;
funchook_uninstall(g_hook, 0);
funchook_destroy(g_hook);
g_hook = nullptr;
g_sendSnapshot = nullptr;
}