From 2c087406d6d9ecce167bdfb44a60214c1a1a41cb Mon Sep 17 00:00:00 2001 From: Adrian <78108584+AdrianCassar@users.noreply.github.com> Date: Fri, 22 Sep 2023 19:23:32 +0100 Subject: [PATCH] [Kernel] Runtime Module Patching Fixes source games TUs --- src/xenia/kernel/kernel_state.cc | 14 +++++++++++++- src/xenia/kernel/xboxkrnl/xboxkrnl_modules.cc | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/xenia/kernel/kernel_state.cc b/src/xenia/kernel/kernel_state.cc index 524c075b1..a9239a8d6 100644 --- a/src/xenia/kernel/kernel_state.cc +++ b/src/xenia/kernel/kernel_state.cc @@ -553,7 +553,19 @@ X_RESULT KernelState::ApplyTitleUpdate(const object_ref module) { content_manager()->OpenContent("UPDATE", title_update, disc_number); // Use the corresponding patch for the launch module - std::filesystem::path patch_xexp = fmt::format("{0}.xexp", module->name()); + std::filesystem::path patch_xexp; + + std::string mount_path = ""; + file_system()->FindSymbolicLink("game:", mount_path); + + auto is_relative = std::filesystem::relative(module->path(), mount_path); + + if (is_relative.empty()) { + return X_STATUS_UNSUCCESSFUL; + } + + patch_xexp = + is_relative.replace_extension(is_relative.extension().string() + "p"); std::string resolved_path = ""; file_system()->FindSymbolicLink("UPDATE:", resolved_path); diff --git a/src/xenia/kernel/xboxkrnl/xboxkrnl_modules.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_modules.cc index 9703a9260..4dea471ca 100644 --- a/src/xenia/kernel/xboxkrnl/xboxkrnl_modules.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_modules.cc @@ -118,6 +118,7 @@ dword_result_t xeXexLoadImage( // Not found; attempt to load as a user module. auto user_module = load_callback(); if (user_module) { + kernel_state()->ApplyTitleUpdate(user_module); kernel_state()->FinishLoadingUserModule(user_module); // Give up object ownership, this reference will be released by the last // XexUnloadImage call