diff --git a/hooking/Hooking.Patterns.h b/hooking/Hooking.Patterns.h index 856da04..6aff33a 100644 --- a/hooking/Hooking.Patterns.h +++ b/hooking/Hooking.Patterns.h @@ -9,6 +9,8 @@ #include "Hooking.h" +#include + namespace hook { class pattern_match @@ -71,7 +73,11 @@ namespace hook EnsureMatches(expected); } - assert(m_matches.size() == expected); + if (m_matches.size() != expected) { + std::stringstream message; + message << m_matches.size() << " != " << expected << " " << m_bytes; + MessageBoxA(NULL, message.str().c_str(), "MatchesCountError", MB_OK | MB_ICONEXCLAMATION); + }; return *this; } diff --git a/hooking/Hooking.cpp b/hooking/Hooking.cpp index 957dcda..50a33f8 100644 --- a/hooking/Hooking.cpp +++ b/hooking/Hooking.cpp @@ -9,6 +9,9 @@ namespace hook { + + uintptr_t baseAddress; + #ifndef _M_AMD64 void inject_hook::inject() { diff --git a/hooking/Hooking.h b/hooking/Hooking.h index e50b991..e793a53 100644 --- a/hooking/Hooking.h +++ b/hooking/Hooking.h @@ -16,19 +16,12 @@ namespace hook { // for link /DYNAMICBASE executables -static ptrdiff_t baseAddressDifference; +extern uintptr_t baseAddress; // sets the base address difference based on an obtained pointer inline void set_base(uintptr_t address) { -#ifdef _M_IX86 - uintptr_t addressDiff = (address - 0x400000); -#elif defined(_M_AMD64) - uintptr_t addressDiff = (address - 0x140000000); -#endif - - // pointer-style cast to ensure unsigned overflow ends up copied directly into a signed value - baseAddressDifference = *(ptrdiff_t*)&addressDiff; + baseAddress = address; } // sets the base to the process main base @@ -37,20 +30,6 @@ inline void set_base() set_base((uintptr_t)GetModuleHandle(NULL)); } -// adjusts the address passed to the base as set above -template -inline void adjust_base(T& address) -{ - *(uintptr_t*)&address += baseAddressDifference; -} - -// returns the adjusted address to the stated base -template -inline uintptr_t get_adjusted(T address) -{ - return (uintptr_t)address + baseAddressDifference; -} - struct pass { template pass(T...) {} @@ -134,9 +113,9 @@ template inline T* getRVA(uintptr_t rva) { #ifdef _M_IX86 - return (T*)(baseAddressDifference + 0x400000 + rva); + return (T*)(baseAddress + rva); #elif defined(_M_AMD64) - return (T*)(0x140000000 + rva); + return (T*)(baseAddress + rva); #endif } @@ -177,9 +156,9 @@ template void iat(const char* moduleName, T function, TOrdinal ordinal) { #ifdef _M_IX86 - IMAGE_DOS_HEADER* imageHeader = (IMAGE_DOS_HEADER*)(baseAddressDifference + 0x400000); + IMAGE_DOS_HEADER* imageHeader = (IMAGE_DOS_HEADER*)(baseAddress); #elif defined(_M_AMD64) - IMAGE_DOS_HEADER* imageHeader = (IMAGE_DOS_HEADER*)(baseAddressDifference + 0x140000000); + IMAGE_DOS_HEADER* imageHeader = (IMAGE_DOS_HEADER*)(baseAddress); #endif IMAGE_NT_HEADERS* ntHeader = getRVA(imageHeader->e_lfanew); diff --git a/main.cc b/main.cc index 9716fb7..c76c156 100644 --- a/main.cc +++ b/main.cc @@ -15,6 +15,8 @@ bool OnViewportInputDebugAlwaysHook(void* thisptr, void* viewport, int input_key } DWORD WINAPI InitializeHook(void* arguments) { + hook::set_base(); + char* location = hook::pattern("48 8B 05 ? ? ? ? 48 8D 4C 24 ? C6 44 24").count(1).get(0).get(3); void* global_game = *reinterpret_cast(location + *(int32_t*)location + 4);