SteamWorksGSDetours::SteamWorksGSDetours() { const char *pLibSteamPath = g_SteamWorks.pSWGameServer->GetLibraryPath(); void *pSteamSafeInitAddress = NULL; void *pSteamShutdownAddress = NULL; const char *pInitSafeFuncName = "SteamGameServer_InitSafe"; const char *pShutdownFuncName = "SteamGameServer_Shutdown"; IGameConfig *pConfig = NULL; if (g_SteamWorks.pSWGameData) { pConfig = g_SteamWorks.pSWGameData->GetGameData(); if (pConfig != NULL) { pConfig->GetMemSig(pShutdownFuncName, &pSteamShutdownAddress); pConfig->GetMemSig(pInitSafeFuncName, &pSteamSafeInitAddress); } } ILibrary *pLibrary = libsys->OpenLibrary(pLibSteamPath, NULL, 0); if (pLibrary != NULL) { if (pSteamShutdownAddress == NULL) { pSteamShutdownAddress = pLibrary->GetSymbolAddress(pShutdownFuncName); } if (pSteamSafeInitAddress == NULL) { pSteamSafeInitAddress = pLibrary->GetSymbolAddress(pInitSafeFuncName); } pLibrary->CloseLibrary(); } CDetourManager::Init(g_pSM->GetScriptingEngine(), pConfig); if (pSteamShutdownAddress != NULL) { this->m_pShutdownDetour = DETOUR_CREATE_STATIC_FIXED(SteamAPIShutdown, pSteamShutdownAddress); this->m_pShutdownDetour->EnableDetour(); } else { this->m_pShutdownDetour = NULL; } if (pSteamSafeInitAddress != NULL) { this->m_pSafeInitDetour = DETOUR_CREATE_STATIC_FIXED(SteamGameServer_InitSafeDetour, pSteamSafeInitAddress); this->m_pSafeInitDetour->EnableDetour(); } else { this->m_pSafeInitDetour = NULL; } }
void CtrlDetours_ClientCommand(bool set) { if (set) { void *base = reinterpret_cast<void *>(MDLL_ClientCommand); #if defined(WIN32) int offset = 0; if (MainConfig->GetOffset("UseBotArgs", &offset)) { UseBotArgs = get_pdata<int*>(base, offset); } if (MainConfig->GetOffset("BotArgs", &offset)) { BotArgs = get_pdata<const char**>(base, offset); } #elif defined(__linux__) || defined(__APPLE__) void *address = nullptr; if (MainConfig->GetMemSig("UseBotArgs", &address)) { UseBotArgs = reinterpret_cast<int *>(address); } if (MainConfig->GetMemSig("BotArgs", &address)) { BotArgs = reinterpret_cast<const char **>(address); } #endif ClientCommandDetour = DETOUR_CREATE_STATIC_FIXED(C_ClientCommand, base); CommonConfig->GetOffsetByClass("CBasePlayer", "m_iTeam", &TeamOffset); CommonConfig->GetOffsetByClass("CBasePlayer", "m_iMenu", &MenuOffset); if (!ClientCommandDetour || !UseBotArgs || !BotArgs || !TeamOffset || !MenuOffset) { MF_Log("ClientCommand is not available - forward client_command has been disabled"); } } else { if (ClientCommandDetour) { ClientCommandDetour->Destroy(); } ItemAliasList.clear(); } }
void CvarManager::CreateCvarHook(void) { // void PF_Cvar_DirectSet(struct cvar_s *var, const char *value) // = pfnCvar_DirectSet // { // Cvar_DirectSet(var, value); // <- We want to hook this. // } byte *baseAddress = (byte *)g_engfuncs.pfnCvar_DirectSet; uintptr_t *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) { // Disabled by default. m_HookDetour = DETOUR_CREATE_STATIC_FIXED(Cvar_DirectSet, (void *)functionAddress); } }