diff --git a/BG3Extender/GameHooks/OsirisWrappers.cpp b/BG3Extender/GameHooks/OsirisWrappers.cpp index 0f0a8003..5cbebd18 100644 --- a/BG3Extender/GameHooks/OsirisWrappers.cpp +++ b/BG3Extender/GameHooks/OsirisWrappers.cpp @@ -221,34 +221,6 @@ void * OsirisWrappers::FindRuleActionCallProc() return nullptr; } -void const* ResolveRealFunctionAddress(void const * ptr) -{ - auto p = (uint8_t const*)ptr; - - // Unconditional jump - if (p[0] == 0xE9) { - int32_t relOffset = *reinterpret_cast(p + 1); - return p + relOffset + 5; - } - - // Resolve function pointer through relocations - auto end = p + 64; - for (; p < end; p++) - { - // Look for the instruction "cmp qword ptr [rip+xxxxxx], 0" - if (p[0] == 0x48 && p[1] == 0x83 && p[2] == 0x3d && p[6] == 0x00 && - // Look for the instruction "jmp xxxx" - p[13] == 0xe9) - { - int32_t relOffset = *reinterpret_cast(p + 14); - return p + relOffset + 18; - } - } - - // Could not find any relocations - return ptr; -} - void OsirisWrappers::FindOsirisGlobals(FARPROC CtorProc) { #if 0 diff --git a/CoreLib/Utils.cpp b/CoreLib/Utils.cpp index b6217128..25e14264 100644 --- a/CoreLib/Utils.cpp +++ b/CoreLib/Utils.cpp @@ -143,4 +143,32 @@ bool LoadFile(std::wstring const& path, std::string& body) return false; } +void const* ResolveRealFunctionAddress(void const * ptr) +{ + auto p = (uint8_t const*)ptr; + + // Unconditional jump + if (p[0] == 0xE9) { + int32_t relOffset = *reinterpret_cast(p + 1); + return p + relOffset + 5; + } + + // Resolve function pointer through relocations + auto end = p + 64; + for (; p < end; p++) + { + // Look for the instruction "cmp qword ptr [rip+xxxxxx], 0" + if (p[0] == 0x48 && p[1] == 0x83 && p[2] == 0x3d && p[6] == 0x00 && + // Look for the instruction "jmp xxxx" + p[13] == 0xe9) + { + int32_t relOffset = *reinterpret_cast(p + 14); + return p + relOffset + 18; + } + } + + // Could not find any relocations + return ptr; +} + END_SE() diff --git a/CoreLib/Wrappers.h b/CoreLib/Wrappers.h index 97915cb6..e1aebef2 100644 --- a/CoreLib/Wrappers.h +++ b/CoreLib/Wrappers.h @@ -32,7 +32,7 @@ namespace bg3se { bool IsWrapped() const { - return TrampolineFunc != nullptr; + return FuncTrampoline != nullptr; } void Wrap(HMODULE Module, char const * ProcName, FuncType NewFunction)