From 8833331c1e7f1eb6bc0d81cc3456d2494ebef4f5 Mon Sep 17 00:00:00 2001 From: maximegmd <672982+maximegmd@users.noreply.github.com> Date: Thu, 29 Feb 2024 15:02:30 +0100 Subject: [PATCH 1/2] Update for new format --- include/RED4ext/Api/Runtime.hpp | 1 + include/RED4ext/Api/v0/Runtime.hpp | 3 +- include/RED4ext/Relocation-inl.hpp | 52 +++++++++++++++--------------- include/RED4ext/Relocation.hpp | 16 +++------ 4 files changed, 34 insertions(+), 38 deletions(-) diff --git a/include/RED4ext/Api/Runtime.hpp b/include/RED4ext/Api/Runtime.hpp index 57cb03627..53707e6c6 100644 --- a/include/RED4ext/Api/Runtime.hpp +++ b/include/RED4ext/Api/Runtime.hpp @@ -19,6 +19,7 @@ #define RED4EXT_RUNTIME_2_02 RED4EXT_V0_RUNTIME_2_02 #define RED4EXT_RUNTIME_2_10 RED4EXT_V0_RUNTIME_2_10 #define RED4EXT_RUNTIME_2_11 RED4EXT_V0_RUNTIME_2_11 +#define RED4EXT_RUNTIME_2_12 RED4EXT_V0_RUNTIME_2_12 /** * @brief Supports all game versions. diff --git a/include/RED4ext/Api/v0/Runtime.hpp b/include/RED4ext/Api/v0/Runtime.hpp index 4cd4529a2..552a6d647 100644 --- a/include/RED4ext/Api/v0/Runtime.hpp +++ b/include/RED4ext/Api/v0/Runtime.hpp @@ -29,6 +29,7 @@ #define RED4EXT_V0_RUNTIME_2_02 RED4EXT_V0_FILEVER(3, 0, 75, 25522) #define RED4EXT_V0_RUNTIME_2_10 RED4EXT_V0_FILEVER(3, 0, 76, 4238) #define RED4EXT_V0_RUNTIME_2_11 RED4EXT_V0_FILEVER(3, 0, 76, 41558) +#define RED4EXT_V0_RUNTIME_2_12 RED4EXT_V0_FILEVER(3, 0, 76, 55031) /** * @brief Supports all game versions. @@ -39,4 +40,4 @@ /* * @brief The latest game version. */ -#define RED4EXT_V0_RUNTIME_LATEST RED4EXT_V0_RUNTIME_2_11 +#define RED4EXT_V0_RUNTIME_LATEST RED4EXT_V0_RUNTIME_2_12 diff --git a/include/RED4ext/Relocation-inl.hpp b/include/RED4ext/Relocation-inl.hpp index 806d36bd3..e57296c6d 100644 --- a/include/RED4ext/Relocation-inl.hpp +++ b/include/RED4ext/Relocation-inl.hpp @@ -18,42 +18,42 @@ RED4EXT_INLINE uintptr_t RED4ext::RelocBase::GetImageBase() } RED4EXT_INLINE -uintptr_t RED4ext::UniversalRelocBase::Resolve(UniversalRelocSegment aSegment, uint32_t aHash) +uintptr_t RED4ext::UniversalRelocBase::Resolve(uint32_t aHash) { - using functionType = uintptr_t (*)(UniversalRelocSegment, uint32_t); + using functionType = uintptr_t (*)(uint32_t); static functionType resolveFunc = nullptr; static std::once_flag flag; std::call_once(flag, - []() - { - constexpr auto dllName = "RED4ext.dll"; - constexpr auto functionName = "RED4ext_ResolveAddress"; + []() + { + constexpr auto dllName = "RED4ext.dll"; + constexpr auto functionName = "RED4ext_ResolveAddress"; - auto handle = LoadLibraryA(dllName); - if (!handle) - { - std::stringstream stream; - stream << "Failed to get '" << dllName - << "' handle.\nProcess will now close.\n\nLast error: " << GetLastError(); + auto handle = GetModuleHandleA(dllName); + if (!handle) + { + std::stringstream stream; + stream << "Failed to get '" << dllName + << "' handle.\nProcess will now close.\n\nLast error: " << GetLastError(); - MessageBoxA(nullptr, stream.str().c_str(), "RED4ext.SDK", MB_ICONERROR | MB_OK); - TerminateProcess(GetCurrentProcess(), 1); - } + MessageBoxA(nullptr, stream.str().c_str(), "RED4ext.SDK", MB_ICONERROR | MB_OK); + TerminateProcess(GetCurrentProcess(), 1); + } - resolveFunc = reinterpret_cast(GetProcAddress(handle, functionName)); - if (resolveFunc == nullptr) - { - std::stringstream stream; - stream << "Failed to get '" << functionName - << "' address.\nProcess will now close.\n\nLast error: " << GetLastError(); + resolveFunc = reinterpret_cast(GetProcAddress(handle, functionName)); + if (resolveFunc == nullptr) + { + std::stringstream stream; + stream << "Failed to get '" << functionName + << "' address.\nProcess will now close.\n\nLast error: " << GetLastError(); - MessageBoxA(nullptr, stream.str().c_str(), "RED4ext.SDK", MB_ICONERROR | MB_OK); - TerminateProcess(GetCurrentProcess(), 1); - } - }); + MessageBoxA(nullptr, stream.str().c_str(), "RED4ext.SDK", MB_ICONERROR | MB_OK); + TerminateProcess(GetCurrentProcess(), 1); + } + }); - auto address = resolveFunc(aSegment, aHash); + auto address = resolveFunc(aHash); if (address == 0) { std::stringstream stream; diff --git a/include/RED4ext/Relocation.hpp b/include/RED4ext/Relocation.hpp index 896889973..8bc54b4fb 100644 --- a/include/RED4ext/Relocation.hpp +++ b/include/RED4ext/Relocation.hpp @@ -80,17 +80,11 @@ class RelocVtbl : private RelocBase uintptr_t* m_address; }; -enum class UniversalRelocSegment : uint32_t -{ - Text = 0, - Data, - Rdata -}; class UniversalRelocBase { public: - static uintptr_t Resolve(UniversalRelocSegment aSegment, uint32_t aHash); + static uintptr_t Resolve(uint32_t aHash); }; /** @@ -102,7 +96,7 @@ class UniversalRelocFunc : private UniversalRelocBase { public: UniversalRelocFunc(uint32_t aHash) - : m_address(reinterpret_cast(Resolve(UniversalRelocSegment::Text, aHash))) + : m_address(reinterpret_cast(Resolve(aHash))) { } @@ -123,8 +117,8 @@ template class UniversalRelocPtr : private UniversalRelocBase { public: - UniversalRelocPtr(uint32_t aHash, UniversalRelocSegment aSegment = UniversalRelocSegment::Data) - : m_address(reinterpret_cast(Resolve(aSegment, aHash))) + UniversalRelocPtr(uint32_t aHash) + : m_address(reinterpret_cast(Resolve(aHash))) { } @@ -150,7 +144,7 @@ class UniversalRelocVtbl : private UniversalRelocBase { public: UniversalRelocVtbl(uint32_t aHash) - : m_address(reinterpret_cast(Resolve(UniversalRelocSegment::Rdata, aHash))) + : m_address(reinterpret_cast(Resolve(aHash))) { } From e113fd169fbac9a0e19a13f115516370ad36ac09 Mon Sep 17 00:00:00 2001 From: maximegmd <672982+maximegmd@users.noreply.github.com> Date: Thu, 29 Feb 2024 16:34:30 +0100 Subject: [PATCH 2/2] Fix hash --- include/RED4ext/Detail/AddressHashes.hpp | 2 +- include/RED4ext/Scripting/Functions.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/RED4ext/Detail/AddressHashes.hpp b/include/RED4ext/Detail/AddressHashes.hpp index f89b67442..b97de4ac0 100644 --- a/include/RED4ext/Detail/AddressHashes.hpp +++ b/include/RED4ext/Detail/AddressHashes.hpp @@ -53,7 +53,7 @@ constexpr std::uint32_t CClassFunction_ctor = 0x602D29F3; #pragma endregion #pragma region CClassStaticFunction -constexpr std::uint32_t CClassStaticFunction_ctor = 0x235013BB; +constexpr std::uint32_t CClassStaticFunction_ctor = 2920426135UL; #pragma endregion #pragma region CEnum diff --git a/include/RED4ext/Scripting/Functions.hpp b/include/RED4ext/Scripting/Functions.hpp index 19d39ad3b..6953baab0 100644 --- a/include/RED4ext/Scripting/Functions.hpp +++ b/include/RED4ext/Scripting/Functions.hpp @@ -167,7 +167,7 @@ struct CClassStaticFunction : CClassFunction using func_t = CClassStaticFunction* (*)(CClassStaticFunction*, CClass*, CName, CName, ScriptingFunction_t, Flags); - UniversalRelocFunc func(Detail::AddressHashes::CClassStaticFunction_ctor); + static UniversalRelocFunc func(Detail::AddressHashes::CClassStaticFunction_ctor); func(memory, aParent, fullName, shortName, aFunc, aFlags); }