diff --git a/src/xenia/emulator.cc b/src/xenia/emulator.cc index 4142f6a3e..69c088bbb 100644 --- a/src/xenia/emulator.cc +++ b/src/xenia/emulator.cc @@ -91,6 +91,9 @@ DEFINE_CVar(launch_data, "", "Used internally for title-to-title launches.", "General", true, std::string); +DEFINE_bool(dump_xex, false, "Dump the main XEX to current directory on launch", + "General"); + DEFINE_bool(allow_game_relative_writes, false, "Not useful to non-developers. Allows code to write to paths " "relative to game://. Used for " diff --git a/src/xenia/kernel/user_module.cc b/src/xenia/kernel/user_module.cc index 2020e987c..193f5d69f 100644 --- a/src/xenia/kernel/user_module.cc +++ b/src/xenia/kernel/user_module.cc @@ -10,11 +10,14 @@ #include "xenia/kernel/user_module.h" #include "xenia/base/byte_stream.h" +#include "xenia/base/filesystem.h" #include "xenia/base/logging.h" #include "xenia/base/xxhash.h" #include "xenia/cpu/elf_module.h" #include "xenia/emulator.h" +DECLARE_bool(dump_xex); + namespace xe { namespace kernel { @@ -156,6 +159,16 @@ X_STATUS UserModule::LoadFromMemory(const void* addr, const size_t length) { // Runtime takes ownership. auto xex_module = std::make_unique(processor, kernel_state()); + if (cvars::dump_xex) { + auto dump_name = name_ + ".xex"; + auto dump_file = xe::filesystem::OpenFile(dump_name, "wb"); + if (dump_file) { + fwrite(addr, 1, length, dump_file); + fclose(dump_file); + XELOGI("Dumped XEX '{}' ({} bytes)", dump_name, length); + } + } + if (!xex_module->Load(name_, path_, addr, length)) { return X_STATUS_UNSUCCESSFUL; }