Merge pull request #337 from Ni3znajomy/cvar_directset

Move Cvar_DirectSet to gamedata
This commit is contained in:
Vincent Herbet 2016-01-22 01:25:21 +01:00
commit 06290483da
4 changed files with 17 additions and 34 deletions

View File

@ -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.");
}
}

View File

@ -14,6 +14,7 @@
#include <amtl/am-vector.h>
#include <amtl/am-inlinelist.h>
#include <sm_namehashset.h>
#include "CGameConfigs.h"
class CDetour;

View File

@ -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)

View File

@ -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"
}
}
}
}