NCodeHook<ArchT>::~NCodeHook() { if (cleanOnDestruct_) { // Restore all hooks and free memory. for (size_t i = hookedFunctions_.size(); i > 0; --i) removeHook(hookedFunctions_[i - 1]); VirtualFree(trampolineBuffer_, 0, MEM_RELEASE); } }
bool NCodeHook<ArchT>::removeHook(U address) { // Remove hooked function again, address points to the HOOK function! std::map<uintptr_t, NCodeHookItem>::const_iterator result = hookedFunctions_.find((uintptr_t)address); if (result != hookedFunctions_.end()) return removeHook(result->second); return true; }
void WINAPI mainFunction() { bool turnOn; #ifdef _DEBUG turnOn = true; #endif Log::Init(turnOn); workWithFiles(); MODULEINFO baseAddress; GetModuleInformation(GetCurrentProcess(), GetModuleHandle(NULL), &baseAddress, sizeof(MODULEINFO)); Log::Write(Log::Type::Debug, "Base address: %p", baseAddress); #ifdef GTAV removeHook(baseAddress); removeDebuggerCheck(); g_VelocityLimit = Pattern::Scan(baseAddress, "C7 83 ? ? ? ? ? ? ? ? C7 83 ? ? ? ? ? ? ? ? 0F 29 9B ? ? ? ?"); Log::Write(Log::Type::Debug,"Velocity address: %p", g_VelocityLimit); DWORD defaultValue = *(DWORD*)(g_VelocityLimit + 6); Log::Write(Log::Type::Debug,"Velocity default limit: in Hex: %X in float:%f ", defaultValue, convertHextoFloat(defaultValue)); float limit = g_FileManager.ReadFloat("Values", "Limit", 3306.0f); *(DWORD*)(g_VelocityLimit + 6) = convertFloatToHex(limit); g_VelocityPatch1 = Pattern::Scan(baseAddress, "F3 0F 11 80 ? ? ? ? 48 8B 8F ? ? ? ? 48 8B 41 78 48 8B 90 ? ? ? ? 48 85 D2 74 24"); Log::Write(Log::Type::Debug, "First velocity patch address: %p", g_VelocityPatch1); memset((void*)g_VelocityPatch1, 0x90, 8); g_VelocityPatch2 = Pattern::Scan(baseAddress,"F3 0F 11 83 ? ? ? ? 48 8B 07 FF 90 ? ? ? ? F3 0F 11 83 ? ? ? ? 8B 47 10 85 C0 74 14 83 F8 01 74 08 83 C0 FE 83 F8 01 77 07 F3 0F 10 47 ? EB 08 F3 0F 10 05 ? ? ? ? F3 0F 11 83 ? ? ? ?"); Log::Write(Log::Type::Debug, "Second velocity patch address: %p", g_VelocityPatch2); memset((void*)g_VelocityPatch2, 0x90, 8); g_VelocityPatch3 = Pattern::Scan(baseAddress, "F3 0F 11 83 ? ? ? ? 48 8B 07 FF 90 ? ? ? ? F3 0F 11 83 ? ? ? ? 8B 47 10 85 C0 74 14 83 F8 01 74 08 83 C0 FE 83 F8 01 77 07 F3 0F 10 47 ? EB 08 F3 0F 10 05 ? ? ? ? 83 7B 08 00"); Log::Write(Log::Type::Debug,"Third velocity patch address: %p", g_VelocityPatch3); memset((void*)g_VelocityPatch3, 0x90, 8); #else g_VelocityLimitIV = (DWORD*)(((DWORD)GetModuleHandleA(NULL) - 0x400000) + 0xE86A6C); Log::Write(Log::Type::Debug,"Velocity address: %p", g_VelocityLimitIV); DWORD defaultValue = *g_VelocityLimitIV; Log::Write(Log::Type::Debug,"Velocity default limit: in Hex: %X in float:%f ", defaultValue, convertHextoFloat(defaultValue)); float limit = g_FileManager.ReadFloat("Values", "Limit", 3306.0f); *g_VelocityLimitIV = convertFloatToHex(limit); g_VelocityPatchIV = (DWORD*)Pattern::Scan(baseAddress, "D9 9E C8 00 00 00 8B 17"); memset(g_VelocityPatchIV, 0x90, 6); #endif }
void ScriptManager::removeHookFromScript(const std::string& hook, const std::string& func) { auto* ctx = asGetActiveContext(); if (mRegisteredHooks.count(hook) == 0) { ctx->SetException("No such hook"); return; } asIScriptObject* obj = (asIScriptObject*)ctx->GetThisPointer(); asIScriptFunction* funcptr = nullptr; if (func.empty()) { if (mScriptHooks.count(hook) > 0) { auto& hooks = mScriptHooks.at(hook); std::find_if(hooks.begin(), hooks.end(), [&funcptr, obj](const ScriptHook& sh) { if (sh.Object == obj) { funcptr = sh.Function; return true; } return false; }); } if (!funcptr) { ctx->SetException("No such hook registered"); return; } } else funcptr = obj->GetObjectType()->GetMethodByName(func.c_str()); removeHook(hook, funcptr, obj); }