Skip to content

Commit

Permalink
Merge pull request #948 from psiberx/master
Browse files Browse the repository at this point in the history
Support latest SDK
  • Loading branch information
maximegmd authored May 29, 2024
2 parents 67eee66 + 1701016 commit f8bc6bd
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 4 deletions.
68 changes: 68 additions & 0 deletions src/reverse/Relocation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#pragma once

#include <filesystem>
#include <mutex>
#include <sstream>

#include <Windows.h>

#include <RED4ext/Common.hpp>
#include <RED4ext/Detail/Memory.hpp>

template<>
struct RED4ext::Detail::AddressResolverOverride<uint32_t> : std::true_type
{
inline static uintptr_t Resolve(uint32_t aHash)
{
using functionType = void* (*)(uint32_t);
static functionType resolveFunc = nullptr;

static std::once_flag flag;
std::call_once(flag,
[]()
{
char exePath[4096];
GetModuleFileNameA(GetModuleHandle(nullptr), exePath, 4096);

std::filesystem::path exe = exePath;

auto dllName = exe.parent_path() / "version.dll";
constexpr auto functionName = "ResolveAddress";

auto handle = LoadLibraryA(dllName.string().c_str());
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(), "Cyber Engine Tweaks", MB_ICONERROR | MB_OK);
TerminateProcess(GetCurrentProcess(), 1);
return; // Disable stupid warning
}

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(), "Cyber Engine Tweaks", MB_ICONERROR | MB_OK);
TerminateProcess(GetCurrentProcess(), 1);
}
});

auto address = resolveFunc(aHash);
if (address == nullptr)
{
std::stringstream stream;
stream << "Failed to resolve address for hash " << std::hex << std::showbase << aHash << ".\nProcess will now close.";

MessageBoxA(nullptr, stream.str().c_str(), "Cyber Engine Tweaks", MB_ICONERROR | MB_OK);
TerminateProcess(GetCurrentProcess(), 1);
}

return reinterpret_cast<uintptr_t>(address);
}
};
3 changes: 2 additions & 1 deletion src/scripting/FunctionOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,10 +700,11 @@ void FunctionOverride::CopyFunctionDescription(RED4ext::CBaseFunction* aFunc, RE
}

aFunc->unk20 = aRealFunc->unk20;
aFunc->bytecode = aRealFunc->bytecode;
aFunc->unk48 = aRealFunc->unk48;
aFunc->unkAC = aRealFunc->unkAC;

aFunc->flags = aRealFunc->flags;
aFunc->flags.isNative = aForceNative;

std::memcpy(&aFunc->bytecode, &aRealFunc->bytecode, sizeof(aRealFunc->bytecode));
}
2 changes: 2 additions & 0 deletions src/stdafx.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "reverse/Relocation.h"

#include <sol/sol.hpp>
#include <spdlog/spdlog.h>
#include <imgui.h>
Expand Down
5 changes: 2 additions & 3 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ add_rules("mode.debug","mode.releasedbg", "mode.release")
add_rules("c.unity_build")

add_cxflags("/bigobj", "/MP", "/EHsc")
add_defines("RED4EXT_STATIC_LIB", "UNICODE", "_UNICODE", "_CRT_SECURE_NO_WARNINGS")
add_defines("UNICODE", "_UNICODE", "_CRT_SECURE_NO_WARNINGS")

local vsRuntime = "MD"

Expand Down Expand Up @@ -53,13 +53,12 @@ add_requires("stb")
add_requires("sol2", { configs = { includes_lua = false } })
add_requires("openrestry-luajit", { configs = { gc64 = true } })

local imguiUserConfig = path.absolute("src/imgui_impl/imgui_user_config.h")
local imguiUserConfig = string.gsub(path.absolute("src/imgui_impl/imgui_user_config.h"), "\\", "/")
add_requires("imgui v1.88-docking", { configs = { wchar32 = true, freetype = true, user_config = imguiUserConfig } })

target("RED4ext.SDK")
set_kind("static")
set_group("vendor")
add_files("vendor/RED4ext.SDK/src/**.cpp")
add_headerfiles("vendor/RED4ext.SDK/include/**.hpp")
add_includedirs("vendor/RED4ext.SDK/include/", { public = true })
on_install(function() end)
Expand Down

0 comments on commit f8bc6bd

Please sign in to comment.