Skip to content

Commit

Permalink
Merge pull request #109 from maximegmd/master
Browse files Browse the repository at this point in the history
Fix for 2.12
  • Loading branch information
wopss authored Feb 29, 2024
2 parents 45b44c7 + e113fd1 commit 49c38b8
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 40 deletions.
1 change: 1 addition & 0 deletions include/RED4ext/Api/Runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion include/RED4ext/Api/v0/Runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
2 changes: 1 addition & 1 deletion include/RED4ext/Detail/AddressHashes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 26 additions & 26 deletions include/RED4ext/Relocation-inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<functionType>(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<functionType>(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;
Expand Down
16 changes: 5 additions & 11 deletions include/RED4ext/Relocation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

/**
Expand All @@ -102,7 +96,7 @@ class UniversalRelocFunc : private UniversalRelocBase
{
public:
UniversalRelocFunc(uint32_t aHash)
: m_address(reinterpret_cast<T>(Resolve(UniversalRelocSegment::Text, aHash)))
: m_address(reinterpret_cast<T>(Resolve(aHash)))
{
}

Expand All @@ -123,8 +117,8 @@ template<typename T>
class UniversalRelocPtr : private UniversalRelocBase
{
public:
UniversalRelocPtr(uint32_t aHash, UniversalRelocSegment aSegment = UniversalRelocSegment::Data)
: m_address(reinterpret_cast<T*>(Resolve(aSegment, aHash)))
UniversalRelocPtr(uint32_t aHash)
: m_address(reinterpret_cast<T*>(Resolve(aHash)))
{
}

Expand All @@ -150,7 +144,7 @@ class UniversalRelocVtbl : private UniversalRelocBase
{
public:
UniversalRelocVtbl(uint32_t aHash)
: m_address(reinterpret_cast<uintptr_t*>(Resolve(UniversalRelocSegment::Rdata, aHash)))
: m_address(reinterpret_cast<uintptr_t*>(Resolve(aHash)))
{
}

Expand Down
2 changes: 1 addition & 1 deletion include/RED4ext/Scripting/Functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ struct CClassStaticFunction : CClassFunction

using func_t =
CClassStaticFunction* (*)(CClassStaticFunction*, CClass*, CName, CName, ScriptingFunction_t<T>, Flags);
UniversalRelocFunc<func_t> func(Detail::AddressHashes::CClassStaticFunction_ctor);
static UniversalRelocFunc<func_t> func(Detail::AddressHashes::CClassStaticFunction_ctor);
func(memory, aParent, fullName, shortName, aFunc, aFlags);
}

Expand Down

0 comments on commit 49c38b8

Please sign in to comment.