From 0e8d876c5d52bb00251bbe01db4e6e7edbd91770 Mon Sep 17 00:00:00 2001 From: Karol Szuster Date: Thu, 21 Jan 2016 23:50:07 +0100 Subject: [PATCH] Move Cvar_DirectSet to gamedata --- amxmodx/CvarManager.cpp | 39 ++++------------------ amxmodx/CvarManager.h | 1 + amxmodx/meta_api.cpp | 4 +-- gamedata/common.games/functions.engine.txt | 7 ++++ 4 files changed, 17 insertions(+), 34 deletions(-) diff --git a/amxmodx/CvarManager.cpp b/amxmodx/CvarManager.cpp index 3d352e62..daf5f3e1 100644 --- a/amxmodx/CvarManager.cpp +++ b/amxmodx/CvarManager.cpp @@ -116,41 +116,16 @@ void CvarManager::CreateCvarHook(void) // Cvar_DirectSet(var, value); // <- We want to hook this. // } - byte *baseAddress = (byte *)g_engfuncs.pfnCvar_DirectSet; - uintptr_t *functionAddress = nullptr; + void *functionAddress = nullptr; -#if defined(WIN32) - // 55 push ebp - // 8B EC mov ebp, esp - // 8B 45 0C mov eax, [ebp+arg_4] - // 8B 4D 08 mov ecx, [ebp+arg_0] - // 50 push eax - // 51 push ecx - // E8 XX XX XX XX call Cvar_DirectSet - const byte opcodeJump = 0xE8; -#else - // E9 XX XX XX XX jmp Cvar_DirectSet - const byte opcodeJump = 0xE9; -#endif - - const byte opcodeJumpSize = 5; - const byte opcodeJumpByteSize = 1; - - const int maxBytesLimit = 20; - - for (size_t i = 0; i < maxBytesLimit; ++i, ++baseAddress) - { - if (*baseAddress == opcodeJump) - { - functionAddress = (uintptr_t *)(&baseAddress[opcodeJumpSize] + *(uintptr_t *)&baseAddress[opcodeJumpByteSize]); - break; - } - } - - if (functionAddress) + if (CommonConfig && CommonConfig->GetMemSig("Cvar_DirectSet", &functionAddress) && functionAddress) { // Disabled by default. - m_HookDetour = DETOUR_CREATE_STATIC_FIXED(Cvar_DirectSet, (void *)functionAddress); + m_HookDetour = DETOUR_CREATE_STATIC_FIXED(Cvar_DirectSet, functionAddress); + } + else + { + AMXXLOG_Log("Binding/Hooking cvars have been disabled - check your gamedata files."); } } diff --git a/amxmodx/CvarManager.h b/amxmodx/CvarManager.h index 043caa7f..88f23825 100644 --- a/amxmodx/CvarManager.h +++ b/amxmodx/CvarManager.h @@ -14,6 +14,7 @@ #include #include #include +#include "CGameConfigs.h" class CDetour; diff --git a/amxmodx/meta_api.cpp b/amxmodx/meta_api.cpp index 108da745..737049e7 100755 --- a/amxmodx/meta_api.cpp +++ b/amxmodx/meta_api.cpp @@ -1572,10 +1572,10 @@ C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, m FlagMan.SetFile("cmdaccess.ini"); - g_CvarManager.CreateCvarHook(); - ConfigManager.OnAmxxStartup(); + g_CvarManager.CreateCvarHook(); + void *address = nullptr; if (CommonConfig && CommonConfig->GetMemSig("SV_DropClient", &address) && address) diff --git a/gamedata/common.games/functions.engine.txt b/gamedata/common.games/functions.engine.txt index f219d70e..1600f8de 100644 --- a/gamedata/common.games/functions.engine.txt +++ b/gamedata/common.games/functions.engine.txt @@ -22,6 +22,13 @@ "linux" "@SV_DropClient" "mac" "@SV_DropClient" } + "Cvar_DirectSet" // void Cvar_DirectSet(struct cvar_s *var, char *value); + { + "library" "engine" + "windows" "\x55\x8B\x2A\x81\x2A\x2A\x2A\x2A\x2A\x56\x8B\x2A\x2A\x57\x8B\x2A\x2A\x85" + "linux" "@Cvar_DirectSet" + "mac" "@Cvar_DirectSet" + } } } }