Try to relocate r3 exe

This commit is contained in:
Guus Waals 2025-05-30 03:23:12 +08:00
parent 2c104648cd
commit 556f8339c0
2 changed files with 13 additions and 3 deletions

View File

@ -82,6 +82,7 @@ function(setup_target TARGET DBG_MODE)
target_link_options(${TARGET} PRIVATE
-Wl,/BASE:0x20000000
-Wl,/DYNAMICBASE:NO
-Wl,/SECTION:.reserved,RW,0x400000
)
target_link_libraries(${TARGET} PRIVATE
DbgHelp

View File

@ -15,9 +15,18 @@ struct R3Bin {
auto &config = getDefaultConfig();
std::string path = config.gameRootDir + "/Rayman3.exe";
module = LoadLibraryA(path.c_str());
if (!module)
throw std::runtime_error("Failed to load original binary");
// Reserve 4MB at the original base address
module = (HINSTANCE)VirtualAlloc((LPVOID)GH_BASE_ADDR, 4 * 1024 * 1024, MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if (!module) {
// Get the error code
DWORD error = GetLastError();
throw std::runtime_error("Failed to allocate memory at original base address: " + std::to_string(error));
}
// module = LoadLibraryA(path.c_str());
// if (!module)
// throw std::runtime_error("Failed to load original binary");
fixupImports(module);