Skip to content

Commit f8bc6bd

Browse files
authored
Merge pull request #948 from psiberx/master
Support latest SDK
2 parents 67eee66 + 1701016 commit f8bc6bd

File tree

4 files changed

+74
-4
lines changed

4 files changed

+74
-4
lines changed

src/reverse/Relocation.h

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#pragma once
2+
3+
#include <filesystem>
4+
#include <mutex>
5+
#include <sstream>
6+
7+
#include <Windows.h>
8+
9+
#include <RED4ext/Common.hpp>
10+
#include <RED4ext/Detail/Memory.hpp>
11+
12+
template<>
13+
struct RED4ext::Detail::AddressResolverOverride<uint32_t> : std::true_type
14+
{
15+
inline static uintptr_t Resolve(uint32_t aHash)
16+
{
17+
using functionType = void* (*)(uint32_t);
18+
static functionType resolveFunc = nullptr;
19+
20+
static std::once_flag flag;
21+
std::call_once(flag,
22+
[]()
23+
{
24+
char exePath[4096];
25+
GetModuleFileNameA(GetModuleHandle(nullptr), exePath, 4096);
26+
27+
std::filesystem::path exe = exePath;
28+
29+
auto dllName = exe.parent_path() / "version.dll";
30+
constexpr auto functionName = "ResolveAddress";
31+
32+
auto handle = LoadLibraryA(dllName.string().c_str());
33+
if (!handle)
34+
{
35+
std::stringstream stream;
36+
stream << "Failed to get '" << dllName
37+
<< "' handle.\nProcess will now close.\n\nLast error: " << GetLastError();
38+
39+
MessageBoxA(nullptr, stream.str().c_str(), "Cyber Engine Tweaks", MB_ICONERROR | MB_OK);
40+
TerminateProcess(GetCurrentProcess(), 1);
41+
return; // Disable stupid warning
42+
}
43+
44+
resolveFunc = reinterpret_cast<functionType>(GetProcAddress(handle, functionName));
45+
if (resolveFunc == nullptr)
46+
{
47+
std::stringstream stream;
48+
stream << "Failed to get '" << functionName
49+
<< "' address.\nProcess will now close.\n\nLast error: " << GetLastError();
50+
51+
MessageBoxA(nullptr, stream.str().c_str(), "Cyber Engine Tweaks", MB_ICONERROR | MB_OK);
52+
TerminateProcess(GetCurrentProcess(), 1);
53+
}
54+
});
55+
56+
auto address = resolveFunc(aHash);
57+
if (address == nullptr)
58+
{
59+
std::stringstream stream;
60+
stream << "Failed to resolve address for hash " << std::hex << std::showbase << aHash << ".\nProcess will now close.";
61+
62+
MessageBoxA(nullptr, stream.str().c_str(), "Cyber Engine Tweaks", MB_ICONERROR | MB_OK);
63+
TerminateProcess(GetCurrentProcess(), 1);
64+
}
65+
66+
return reinterpret_cast<uintptr_t>(address);
67+
}
68+
};

src/scripting/FunctionOverride.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -700,10 +700,11 @@ void FunctionOverride::CopyFunctionDescription(RED4ext::CBaseFunction* aFunc, RE
700700
}
701701

702702
aFunc->unk20 = aRealFunc->unk20;
703-
aFunc->bytecode = aRealFunc->bytecode;
704703
aFunc->unk48 = aRealFunc->unk48;
705704
aFunc->unkAC = aRealFunc->unkAC;
706705

707706
aFunc->flags = aRealFunc->flags;
708707
aFunc->flags.isNative = aForceNative;
708+
709+
std::memcpy(&aFunc->bytecode, &aRealFunc->bytecode, sizeof(aRealFunc->bytecode));
709710
}

src/stdafx.h

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include "reverse/Relocation.h"
4+
35
#include <sol/sol.hpp>
46
#include <spdlog/spdlog.h>
57
#include <imgui.h>

xmake.lua

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ add_rules("mode.debug","mode.releasedbg", "mode.release")
77
add_rules("c.unity_build")
88

99
add_cxflags("/bigobj", "/MP", "/EHsc")
10-
add_defines("RED4EXT_STATIC_LIB", "UNICODE", "_UNICODE", "_CRT_SECURE_NO_WARNINGS")
10+
add_defines("UNICODE", "_UNICODE", "_CRT_SECURE_NO_WARNINGS")
1111

1212
local vsRuntime = "MD"
1313

@@ -53,13 +53,12 @@ add_requires("stb")
5353
add_requires("sol2", { configs = { includes_lua = false } })
5454
add_requires("openrestry-luajit", { configs = { gc64 = true } })
5555

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

5959
target("RED4ext.SDK")
6060
set_kind("static")
6161
set_group("vendor")
62-
add_files("vendor/RED4ext.SDK/src/**.cpp")
6362
add_headerfiles("vendor/RED4ext.SDK/include/**.hpp")
6463
add_includedirs("vendor/RED4ext.SDK/include/", { public = true })
6564
on_install(function() end)

0 commit comments

Comments
 (0)