From b1e5485058f2eb711afc9548c41ff19e0690e04f Mon Sep 17 00:00:00 2001 From: PabloMK7 Date: Mon, 22 Apr 2024 23:37:30 +0200 Subject: [PATCH] Allow loading IPS files from Luma3DS folders. (#87) --- src/core/file_sys/ncch_container.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/core/file_sys/ncch_container.cpp b/src/core/file_sys/ncch_container.cpp index ad8b32629..2ebd31f2e 100644 --- a/src/core/file_sys/ncch_container.cpp +++ b/src/core/file_sys/ncch_container.cpp @@ -577,11 +577,26 @@ Loader::ResultStatus NCCHContainer::ApplyCodePatch(std::vector& code) const const auto mods_path = fmt::format("{}mods/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::LoadDir), GetModId(ncch_header.program_id)); - const std::array patch_paths{{ + + constexpr u32 system_module_tid_high = 0x00040130; + + std::string luma_ips_location; + if ((static_cast(ncch_header.program_id >> 32) & system_module_tid_high) == + system_module_tid_high) { + luma_ips_location = + fmt::format("{}luma/sysmodules/{:016X}.ips", + FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir), ncch_header.program_id); + } else { + luma_ips_location = + fmt::format("{}luma/titles/{:016X}/code.ips", + FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir), ncch_header.program_id); + } + const std::array patch_paths{{ {mods_path + "exefs/code.ips", Patch::ApplyIpsPatch}, {mods_path + "exefs/code.bps", Patch::ApplyBpsPatch}, {mods_path + "code.ips", Patch::ApplyIpsPatch}, {mods_path + "code.bps", Patch::ApplyBpsPatch}, + {luma_ips_location, Patch::ApplyIpsPatch}, {filepath + ".exefsdir/code.ips", Patch::ApplyIpsPatch}, {filepath + ".exefsdir/code.bps", Patch::ApplyBpsPatch}, }};