diff --git a/game_re/CMakeLists.txt b/game_re/CMakeLists.txt index a891f6df..caf8f3a2 100644 --- a/game_re/CMakeLists.txt +++ b/game_re/CMakeLists.txt @@ -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 diff --git a/game_re/r3/binders/dbg_mem.cxx b/game_re/r3/binders/dbg_mem.cxx index 4fd6046e..008b3138 100644 --- a/game_re/r3/binders/dbg_mem.cxx +++ b/game_re/r3/binders/dbg_mem.cxx @@ -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);