From 4273b967b5a0b07df18ebcc0131eb11dda497bc8 Mon Sep 17 00:00:00 2001 From: zhupengfei Date: Tue, 11 Feb 2020 14:03:07 +0800 Subject: [PATCH] core/file_sys: Do not apply the same mods to DLCs Now you can apply separate mods to DLCs and mods for the original title won't be applied. --- src/core/file_sys/ncch_container.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/core/file_sys/ncch_container.cpp b/src/core/file_sys/ncch_container.cpp index 2e549a894..81525786f 100644 --- a/src/core/file_sys/ncch_container.cpp +++ b/src/core/file_sys/ncch_container.cpp @@ -26,6 +26,14 @@ namespace FileSys { static const int kMaxSections = 8; ///< Maximum number of sections (files) in an ExeFs static const int kBlockSize = 0x200; ///< Size of ExeFS blocks (in bytes) +u64 GetModId(u64 program_id) { + constexpr u64 UPDATE_MASK = 0x0000000e'00000000; + if ((program_id & 0x000000ff'00000000) == UPDATE_MASK) { // Apply the mods to updates + return program_id & ~UPDATE_MASK; + } + return program_id; +} + /** * Get the decompressed size of an LZSS compressed ExeFS file * @param buffer Buffer of compressed file @@ -306,7 +314,7 @@ Loader::ResultStatus NCCHContainer::Load() { const auto mods_path = fmt::format("{}mods/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::LoadDir), - ncch_header.program_id & 0x00040000'FFFFFFFF); + GetModId(ncch_header.program_id)); std::array exheader_override_paths{{ mods_path + "exheader.bin", filepath + ".exheader", @@ -530,7 +538,7 @@ Loader::ResultStatus NCCHContainer::ApplyCodePatch(std::vector& code) const const auto mods_path = fmt::format("{}mods/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::LoadDir), - ncch_header.program_id & 0x00040000'FFFFFFFF); + GetModId(ncch_header.program_id)); const std::array patch_paths{{ {mods_path + "exefs/code.ips", Patch::ApplyIpsPatch}, {mods_path + "exefs/code.bps", Patch::ApplyBpsPatch}, @@ -574,7 +582,7 @@ Loader::ResultStatus NCCHContainer::LoadOverrideExeFSSection(const char* name, const auto mods_path = fmt::format("{}mods/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::LoadDir), - ncch_header.program_id & 0x00040000'FFFFFFFF); + GetModId(ncch_header.program_id)); std::array override_paths{{ mods_path + "exefs/" + override_name, filepath + ".exefsdir/" + override_name, @@ -640,7 +648,7 @@ Loader::ResultStatus NCCHContainer::ReadRomFS(std::shared_ptr& romf const auto path = fmt::format("{}mods/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::LoadDir), - ncch_header.program_id & 0x00040000'FFFFFFFF); + GetModId(ncch_header.program_id)); if (use_layered_fs && (FileUtil::Exists(path + "romfs/") || FileUtil::Exists(path + "romfs_ext/"))) {