From 5399c79d9723fe9bd7f249b12513511a2c20e1ac Mon Sep 17 00:00:00 2001 From: Peace-Maker Date: Thu, 3 Mar 2016 11:49:14 +0100 Subject: [PATCH] Dynamically get CHLTVServer::m_DemoRecorder offset Instead of hardcoding a hugh member variable offset, get it dynamically from functions using the variable. --- extension.cpp | 21 ++++++++++++--- sourcetvmanager.games.txt | 55 ++++++++++++++++++++++++++++++--------- 2 files changed, 61 insertions(+), 15 deletions(-) diff --git a/extension.cpp b/extension.cpp index 7426fae..f8b1ba3 100644 --- a/extension.cpp +++ b/extension.cpp @@ -291,16 +291,31 @@ void SourceTVManager::SelectSourceTVServer(IHLTVServer *hltv) IDemoRecorder *SourceTVManager::GetDemoRecorderPtr(IHLTVServer *hltv) { static int offset = -1; - if (offset == -1 && !g_pGameConf->GetOffset("CHLTVServer::m_DemoRecorder", &offset)) + if (offset == -1) { - smutils->LogError(myself, "Failed to get CHLTVServer::m_DemoRecorder offset."); - return nullptr; + void *addr; + if (!g_pGameConf->GetAddress("CHLTVServer::m_DemoRecorder", &addr)) + { + smutils->LogError(myself, "Failed to get CHLTVServer::m_DemoRecorder offset."); + return nullptr; + } + + *(int **)&offset = (int *)addr; } if (hltv) + { +#if SOURCE_ENGINE == SE_CSGO return (IDemoRecorder *)((intptr_t)hltv + offset); +#else + IServer *baseServer = hltv->GetBaseServer(); + return (IDemoRecorder *)((intptr_t)baseServer + offset); +#endif + } else + { return nullptr; + } } #if SOURCE_ENGINE == SE_CSGO diff --git a/sourcetvmanager.games.txt b/sourcetvmanager.games.txt index 6573d1e..8c4d37d 100644 --- a/sourcetvmanager.games.txt +++ b/sourcetvmanager.games.txt @@ -16,6 +16,20 @@ "signature" "host_client" } } + + "CHLTVServer::m_DemoRecorder" + { + "windows" + { + "signature" "CHLTVServer::GetRecordingDemoFilename" + "read" "2" + } + "linux" + { + "signature" "CHLTVServer::GetRecordingDemoFilename" + "read" "10" + } + } } "Offsets" { @@ -49,12 +63,6 @@ "linux" "65" } - "CHLTVServer::m_DemoRecorder" - { - "windows" "19600" - "linux" "20496" - } - "CHLTVDirector::m_iPVSEntity" { "windows" "32" @@ -90,6 +98,13 @@ // "SourceTV broadcast local event: %s\n" "windows" "\x55\x8B\xEC\x83\xEC\x4C\x53\x8B\xD9\xC7\x45\xB4\x2A\x2A\x2A\x2A\x56\x8D" } + + "CHLTVServer::GetRecordingDemoFilename" + { + "library" "engine" + "linux" "@_ZN11CHLTVServer24GetRecordingDemoFilenameEv" + "windows" "\x81\xC1\x2A\x2A\x2A\x2A\x8B\x01\xFF\x20" + } } } "cstrike" @@ -108,6 +123,20 @@ "signature" "host_client" } } + + "CHLTVServer::m_DemoRecorder" + { + "windows" + { + "signature" "CHLTVServer::Shutdown" + "read" "5" + } + "linux" + { + "signature" "CHLTVServer::Shutdown" + "read" "12" + } + } } "Offsets" { @@ -153,12 +182,6 @@ "linux" "56" } - "CHLTVServer::m_DemoRecorder" - { - "windows" "19192" - "linux" "19424" // -416 - } - "CHLTVDirector::m_iPVSEntity" { "windows" "16" @@ -194,6 +217,14 @@ // "SourceTV broadcast local event: %s\n" "windows" "\x55\x8B\xEC\x81\xEC\x44\x04\x00\x00\x53" } + + "CHLTVServer::Shutdown" + { + "library" "engine" + "linux" "@_ZN11CHLTVServer8ShutdownEv" + // "HLTV server shutting down" + "windows" "\x56\x8B\xF1\x8B\x86\x2A\x2A\x2A\x2A\x8D\x8E\x2A\x2A\x2A\x2A\xFF\x50\x2A\x8B\x86\x2A\x2A\x2A\x2A\x8D\x8E" + } } } } \ No newline at end of file