From 540b56dbc2ef6eff4be3c80871fe58c2e0e26dc5 Mon Sep 17 00:00:00 2001 From: Vauff Date: Wed, 11 Mar 2026 11:38:58 -0400 Subject: [PATCH 1/3] Port to KHook --- extension.cpp | 24 ++++++++++++++---------- extension.h | 8 ++++---- premake/mm-linux.lua | 7 +------ premake/mm-windows.lua | 7 +------ 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/extension.cpp b/extension.cpp index f30b251..68ebbf1 100644 --- a/extension.cpp +++ b/extension.cpp @@ -60,8 +60,8 @@ CGameEntitySystem *GameEntitySystem() } class GameSessionConfiguration_t { }; -SH_DECL_HOOK3_void(IServerGameDLL, GameFrame, SH_NOATTRIB, 0, bool, bool, bool); -SH_DECL_HOOK3_void(INetworkServerService, StartupServer, SH_NOATTRIB, 0, const GameSessionConfiguration_t&, ISource2WorldSession*, const char*); +KHook::Virtual gameFrameHook(&IServerGameDLL::GameFrame, &g_AcceleratorCS2, nullptr, &AcceleratorCS2::GameFrame); +KHook::Virtual startupServerHook(&INetworkServerService::StartupServer, &g_AcceleratorCS2, nullptr, &AcceleratorCS2::StartupServer); google_breakpad::ExceptionHandler* exceptionHandler = nullptr; @@ -459,7 +459,7 @@ bool AcceleratorCS2::Load(PluginId id, ISmmAPI* ismm, char* error, size_t maxlen sigaction(SIGSEGV, NULL, &oact); SignalHandler = oact.sa_sigaction; - SH_ADD_HOOK(IServerGameDLL, GameFrame, g_pSource2Server, SH_MEMBER(this, &AcceleratorCS2::GameFrame), true); + gameFrameHook.Add(g_pSource2Server); #else wchar_t* buf = new wchar_t[sizeof(dumpStoragePath)]; size_t num_chars = mbstowcs(buf, dumpStoragePath, sizeof(dumpStoragePath)); @@ -473,12 +473,12 @@ bool AcceleratorCS2::Load(PluginId id, ISmmAPI* ismm, char* error, size_t maxlen delete buf; #endif - SH_ADD_HOOK(INetworkServerService, StartupServer, g_pNetworkServerService, SH_MEMBER(this, &AcceleratorCS2::StartupServer), true); + startupServerHook.Add(g_pNetworkServerService); strncpy(crashCommandLine, CommandLine()->GetCmdLine(), sizeof(crashCommandLine) - 1); if (late) - StartupServer({}, nullptr, nullptr); + StartupServer(nullptr, {}, nullptr, nullptr); LoadServerId(); LoadConfig(); @@ -492,9 +492,9 @@ bool AcceleratorCS2::Load(PluginId id, ISmmAPI* ismm, char* error, size_t maxlen bool AcceleratorCS2::Unload(char* error, size_t maxlen) { #if defined _LINUX - SH_REMOVE_HOOK(IServerGameDLL, GameFrame, g_pSource2Server, SH_MEMBER(this, &AcceleratorCS2::GameFrame), true); + gameFrameHook.Remove(g_pSource2Server); #endif - SH_REMOVE_HOOK(INetworkServerService, StartupServer, g_pNetworkServerService, SH_MEMBER(this, &AcceleratorCS2::StartupServer), true); + startupServerHook.Remove(g_pNetworkServerService); delete exceptionHandler; @@ -503,7 +503,7 @@ bool AcceleratorCS2::Unload(char* error, size_t maxlen) #if defined _LINUX -void AcceleratorCS2::GameFrame(bool simulating, bool bFirstTick, bool bLastTick) +KHook::Return AcceleratorCS2::GameFrame(IServerGameDLL* pThis, bool simulating, bool bFirstTick, bool bLastTick) { bool weHaveBeenFuckedOver = false; struct sigaction oact; @@ -520,7 +520,7 @@ void AcceleratorCS2::GameFrame(bool simulating, bool bFirstTick, bool bLastTick) } if (!weHaveBeenFuckedOver) - return; + return {KHook::Action::Ignore}; struct sigaction act; memset(&act, 0, sizeof(act)); @@ -534,13 +534,17 @@ void AcceleratorCS2::GameFrame(bool simulating, bool bFirstTick, bool bLastTick) for (int i = 0; i < kNumHandledSignals; ++i) sigaction(kExceptionSignals[i], &act, NULL); + + return {KHook::Action::Ignore}; } #endif -void AcceleratorCS2::StartupServer(const GameSessionConfiguration_t& config, ISource2WorldSession*, const char*) +KHook::Return AcceleratorCS2::StartupServer(INetworkServerService* pThis, const GameSessionConfiguration_t& config, ISource2WorldSession*, const char*) { strncpy(crashMap, g_pNetworkServerService->GetIGameServer()->GetMapName(), sizeof(crashMap) - 1); + + return {KHook::Action::Ignore}; } const char* AcceleratorCS2::GetLicense() diff --git a/extension.h b/extension.h index be81d00..8d6bbe3 100644 --- a/extension.h +++ b/extension.h @@ -1,7 +1,7 @@ #pragma once +#include "khook.hpp" #include #include -#include #include class AcceleratorCS2 : public ISmmPlugin, public IMetamodListener @@ -18,7 +18,7 @@ class AcceleratorCS2 : public ISmmPlugin, public IMetamodListener const char* GetVersion(); const char* GetDate(); const char* GetLogTag(); -private: // Hooks - void GameFrame(bool simulating, bool bFirstTick, bool bLastTick); - void StartupServer(const GameSessionConfiguration_t& config, ISource2WorldSession*, const char*); +public: // Hooks + KHook::Return GameFrame(IServerGameDLL* pThis, bool simulating, bool bFirstTick, bool bLastTick); + KHook::Return StartupServer(INetworkServerService* pThis, const GameSessionConfiguration_t& config, ISource2WorldSession*, const char*); }; \ No newline at end of file diff --git a/premake/mm-linux.lua b/premake/mm-linux.lua index 637b5f5..3c5fee7 100644 --- a/premake/mm-linux.lua +++ b/premake/mm-linux.lua @@ -4,11 +4,6 @@ files { path.join(SDK_PATH, "tier1", "generichash.cpp"), path.join(SDK_PATH, "entity2", "entityidentity.cpp"), path.join(SDK_PATH, "entity2", "entitysystem.cpp"), - path.join(MM_PATH, "core", "sourcehook", "sourcehook.cpp"), - path.join(MM_PATH, "core", "sourcehook", "sourcehook_impl_chookidman.cpp"), - path.join(MM_PATH, "core", "sourcehook", "sourcehook_impl_chookmaninfo.cpp"), - path.join(MM_PATH, "core", "sourcehook", "sourcehook_impl_cvfnptr.cpp"), - path.join(MM_PATH, "core", "sourcehook", "sourcehook_impl_cproto.cpp"), } libdirs { @@ -40,7 +35,7 @@ includedirs { path.join(SDK_PATH, "public", "public", "entity2"), -- metamod path.join(MM_PATH, "core"), - path.join(MM_PATH, "core", "sourcehook"), + path.join(MM_PATH, "third_party", "khook", "include"), } defines { diff --git a/premake/mm-windows.lua b/premake/mm-windows.lua index 5831123..b60e2c7 100644 --- a/premake/mm-windows.lua +++ b/premake/mm-windows.lua @@ -3,11 +3,6 @@ files { path.join(SDK_PATH, "tier1", "generichash.cpp"), path.join(SDK_PATH, "entity2", "entityidentity.cpp"), path.join(SDK_PATH, "entity2", "entitysystem.cpp"), - path.join(MM_PATH, "core", "sourcehook", "sourcehook.cpp"), - path.join(MM_PATH, "core", "sourcehook", "sourcehook_impl_chookidman.cpp"), - path.join(MM_PATH, "core", "sourcehook", "sourcehook_impl_chookmaninfo.cpp"), - path.join(MM_PATH, "core", "sourcehook", "sourcehook_impl_cvfnptr.cpp"), - path.join(MM_PATH, "core", "sourcehook", "sourcehook_impl_cproto.cpp"), } links { @@ -35,7 +30,7 @@ includedirs { path.join(SDK_PATH, "public", "public", "entity2"), -- metamod path.join(MM_PATH, "core"), - path.join(MM_PATH, "core", "sourcehook"), + path.join(MM_PATH, "third_party", "khook", "include"), } defines { From abdac22db870b9feb43776e87adaec2a1bde3517 Mon Sep 17 00:00:00 2001 From: Vauff Date: Tue, 8 Sep 2026 14:49:38 -0400 Subject: [PATCH 2/3] Fix template deduction for Windows compilation --- extension.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extension.cpp b/extension.cpp index bcc800a..d660915 100644 --- a/extension.cpp +++ b/extension.cpp @@ -60,8 +60,8 @@ CGameEntitySystem *GameEntitySystem() } class GameSessionConfiguration_t { }; -KHook::Virtual gameFrameHook(&IServerGameDLL::GameFrame, &g_AcceleratorCS2, nullptr, &AcceleratorCS2::GameFrame); -KHook::Virtual startupServerHook(&INetworkServerService::StartupServer, &g_AcceleratorCS2, nullptr, &AcceleratorCS2::StartupServer); +KHook::Virtual gameFrameHook(&IServerGameDLL::GameFrame, &g_AcceleratorCS2, nullptr, &AcceleratorCS2::GameFrame); +KHook::Virtual startupServerHook(&INetworkServerService::StartupServer, &g_AcceleratorCS2, nullptr, &AcceleratorCS2::StartupServer); google_breakpad::ExceptionHandler* exceptionHandler = nullptr; @@ -554,7 +554,7 @@ const char* AcceleratorCS2::GetLicense() const char* AcceleratorCS2::GetVersion() { - return "2.0.6"; + return "3.0"; } const char* AcceleratorCS2::GetDate() From e4130853c7ad09eec39bd96cbb68ebd8a6b136df Mon Sep 17 00:00:00 2001 From: Vauff Date: Tue, 8 Sep 2026 14:58:42 -0400 Subject: [PATCH 3/3] another windows compilation fix --- extension.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extension.cpp b/extension.cpp index d660915..c99c5b8 100644 --- a/extension.cpp +++ b/extension.cpp @@ -60,7 +60,9 @@ CGameEntitySystem *GameEntitySystem() } class GameSessionConfiguration_t { }; +#if defined _LINUX KHook::Virtual gameFrameHook(&IServerGameDLL::GameFrame, &g_AcceleratorCS2, nullptr, &AcceleratorCS2::GameFrame); +#endif KHook::Virtual startupServerHook(&INetworkServerService::StartupServer, &g_AcceleratorCS2, nullptr, &AcceleratorCS2::StartupServer); google_breakpad::ExceptionHandler* exceptionHandler = nullptr;