diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/file_sys/patch_manager.cpp | 81 | ||||
| -rw-r--r-- | src/core/file_sys/patch_manager.h | 2 | ||||
| -rw-r--r-- | src/core/loader/deconstructed_rom_directory.cpp | 5 | ||||
| -rw-r--r-- | src/core/loader/nso.cpp | 4 | ||||
| -rw-r--r-- | src/core/loader/nso.h | 2 |
5 files changed, 43 insertions, 51 deletions
diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index 044e01ae9..539698f6e 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <array> | 6 | #include <array> |
| 7 | #include <cstddef> | 7 | #include <cstddef> |
| 8 | #include <cstring> | ||
| 8 | 9 | ||
| 9 | #include "common/hex_util.h" | 10 | #include "common/hex_util.h" |
| 10 | #include "common/logging/log.h" | 11 | #include "common/logging/log.h" |
| @@ -72,11 +73,34 @@ VirtualDir PatchManager::PatchExeFS(VirtualDir exefs) const { | |||
| 72 | return exefs; | 73 | return exefs; |
| 73 | } | 74 | } |
| 74 | 75 | ||
| 76 | static std::vector<VirtualFile> CollectIPSPatches(const std::vector<VirtualDir>& patch_dirs, | ||
| 77 | const std::string& build_id) { | ||
| 78 | std::vector<VirtualFile> ips; | ||
| 79 | ips.reserve(patch_dirs.size()); | ||
| 80 | for (const auto& subdir : patch_dirs) { | ||
| 81 | auto exefs_dir = subdir->GetSubdirectory("exefs"); | ||
| 82 | if (exefs_dir != nullptr) { | ||
| 83 | for (const auto& file : exefs_dir->GetFiles()) { | ||
| 84 | if (file->GetExtension() != "ips") | ||
| 85 | continue; | ||
| 86 | auto name = file->GetName(); | ||
| 87 | const auto p1 = name.substr(0, name.find('.')); | ||
| 88 | const auto this_build_id = p1.substr(0, p1.find_last_not_of('0') + 1); | ||
| 89 | |||
| 90 | if (build_id == this_build_id) | ||
| 91 | ips.push_back(file); | ||
| 92 | } | ||
| 93 | } | ||
| 94 | } | ||
| 95 | |||
| 96 | return ips; | ||
| 97 | } | ||
| 98 | |||
| 75 | std::vector<u8> PatchManager::PatchNSO(const std::vector<u8>& nso) const { | 99 | std::vector<u8> PatchManager::PatchNSO(const std::vector<u8>& nso) const { |
| 76 | if (nso.size() < 0x100) | 100 | if (nso.size() < 0x100) |
| 77 | return nso; | 101 | return nso; |
| 78 | 102 | ||
| 79 | NSOBuildHeader header{}; | 103 | NSOBuildHeader header; |
| 80 | std::memcpy(&header, nso.data(), sizeof(NSOBuildHeader)); | 104 | std::memcpy(&header, nso.data(), sizeof(NSOBuildHeader)); |
| 81 | 105 | ||
| 82 | if (header.magic != Common::MakeMagic('N', 'S', 'O', '0')) | 106 | if (header.magic != Common::MakeMagic('N', 'S', 'O', '0')) |
| @@ -91,24 +115,7 @@ std::vector<u8> PatchManager::PatchNSO(const std::vector<u8>& nso) const { | |||
| 91 | auto patch_dirs = load_dir->GetSubdirectories(); | 115 | auto patch_dirs = load_dir->GetSubdirectories(); |
| 92 | std::sort(patch_dirs.begin(), patch_dirs.end(), | 116 | std::sort(patch_dirs.begin(), patch_dirs.end(), |
| 93 | [](const VirtualDir& l, const VirtualDir& r) { return l->GetName() < r->GetName(); }); | 117 | [](const VirtualDir& l, const VirtualDir& r) { return l->GetName() < r->GetName(); }); |
| 94 | 118 | const auto ips = CollectIPSPatches(patch_dirs, build_id); | |
| 95 | std::vector<VirtualFile> ips; | ||
| 96 | ips.reserve(patch_dirs.size() - 1); | ||
| 97 | for (const auto& subdir : patch_dirs) { | ||
| 98 | auto exefs_dir = subdir->GetSubdirectory("exefs"); | ||
| 99 | if (exefs_dir != nullptr) { | ||
| 100 | for (const auto& file : exefs_dir->GetFiles()) { | ||
| 101 | if (file->GetExtension() != "ips") | ||
| 102 | continue; | ||
| 103 | auto name = file->GetName(); | ||
| 104 | const auto p1 = name.substr(0, name.find_first_of('.')); | ||
| 105 | const auto this_build_id = p1.substr(0, p1.find_last_not_of('0') + 1); | ||
| 106 | |||
| 107 | if (build_id == this_build_id) | ||
| 108 | ips.push_back(file); | ||
| 109 | } | ||
| 110 | } | ||
| 111 | } | ||
| 112 | 119 | ||
| 113 | auto out = nso; | 120 | auto out = nso; |
| 114 | for (const auto& ips_file : ips) { | 121 | for (const auto& ips_file : ips) { |
| @@ -136,23 +143,7 @@ bool PatchManager::HasNSOPatch(const std::array<u8, 32>& build_id_) const { | |||
| 136 | std::sort(patch_dirs.begin(), patch_dirs.end(), | 143 | std::sort(patch_dirs.begin(), patch_dirs.end(), |
| 137 | [](const VirtualDir& l, const VirtualDir& r) { return l->GetName() < r->GetName(); }); | 144 | [](const VirtualDir& l, const VirtualDir& r) { return l->GetName() < r->GetName(); }); |
| 138 | 145 | ||
| 139 | for (const auto& subdir : patch_dirs) { | 146 | return !CollectIPSPatches(patch_dirs, build_id).empty(); |
| 140 | auto exefs_dir = subdir->GetSubdirectory("exefs"); | ||
| 141 | if (exefs_dir != nullptr) { | ||
| 142 | for (const auto& file : exefs_dir->GetFiles()) { | ||
| 143 | if (file->GetExtension() != "ips") | ||
| 144 | continue; | ||
| 145 | auto name = file->GetName(); | ||
| 146 | const auto p1 = name.substr(0, name.find_first_of('.')); | ||
| 147 | const auto this_build_id = p1.substr(0, p1.find_last_not_of('0') + 1); | ||
| 148 | |||
| 149 | if (build_id == this_build_id) | ||
| 150 | return true; | ||
| 151 | } | ||
| 152 | } | ||
| 153 | } | ||
| 154 | |||
| 155 | return false; | ||
| 156 | } | 147 | } |
| 157 | 148 | ||
| 158 | static void ApplyLayeredFS(VirtualFile& romfs, u64 title_id, ContentRecordType type) { | 149 | static void ApplyLayeredFS(VirtualFile& romfs, u64 title_id, ContentRecordType type) { |
| @@ -222,7 +213,7 @@ VirtualFile PatchManager::PatchRomFS(VirtualFile romfs, u64 ivfc_offset, | |||
| 222 | return romfs; | 213 | return romfs; |
| 223 | } | 214 | } |
| 224 | 215 | ||
| 225 | void AppendCommaIfNotEmpty(std::string& to, const std::string& with) { | 216 | static void AppendCommaIfNotEmpty(std::string& to, const std::string& with) { |
| 226 | if (to.empty()) | 217 | if (to.empty()) |
| 227 | to += with; | 218 | to += with; |
| 228 | else | 219 | else |
| @@ -233,8 +224,8 @@ static bool IsDirValidAndNonEmpty(const VirtualDir& dir) { | |||
| 233 | return dir != nullptr && (!dir->GetFiles().empty() || !dir->GetSubdirectories().empty()); | 224 | return dir != nullptr && (!dir->GetFiles().empty() || !dir->GetSubdirectories().empty()); |
| 234 | } | 225 | } |
| 235 | 226 | ||
| 236 | std::map<std::string, std::string> PatchManager::GetPatchVersionNames() const { | 227 | std::map<std::string, std::string, std::less<>> PatchManager::GetPatchVersionNames() const { |
| 237 | std::map<std::string, std::string> out; | 228 | std::map<std::string, std::string, std::less<>> out; |
| 238 | const auto installed = Service::FileSystem::GetUnionContents(); | 229 | const auto installed = Service::FileSystem::GetUnionContents(); |
| 239 | 230 | ||
| 240 | // Game Updates | 231 | // Game Updates |
| @@ -243,19 +234,21 @@ std::map<std::string, std::string> PatchManager::GetPatchVersionNames() const { | |||
| 243 | auto [nacp, discard_icon_file] = update.GetControlMetadata(); | 234 | auto [nacp, discard_icon_file] = update.GetControlMetadata(); |
| 244 | 235 | ||
| 245 | if (nacp != nullptr) { | 236 | if (nacp != nullptr) { |
| 246 | out["Update"] = nacp->GetVersionString(); | 237 | out.insert_or_assign("Update", nacp->GetVersionString()); |
| 247 | } else { | 238 | } else { |
| 248 | if (installed->HasEntry(update_tid, ContentRecordType::Program)) { | 239 | if (installed->HasEntry(update_tid, ContentRecordType::Program)) { |
| 249 | const auto meta_ver = installed->GetEntryVersion(update_tid); | 240 | const auto meta_ver = installed->GetEntryVersion(update_tid); |
| 250 | if (meta_ver == boost::none || meta_ver.get() == 0) { | 241 | if (meta_ver == boost::none || meta_ver.get() == 0) { |
| 251 | out["Update"] = ""; | 242 | out.insert_or_assign("Update", ""); |
| 252 | } else { | 243 | } else { |
| 253 | out["Update"] = | 244 | out.insert_or_assign( |
| 254 | FormatTitleVersion(meta_ver.get(), TitleVersionFormat::ThreeElements); | 245 | "Update", |
| 246 | FormatTitleVersion(meta_ver.get(), TitleVersionFormat::ThreeElements)); | ||
| 255 | } | 247 | } |
| 256 | } | 248 | } |
| 257 | } | 249 | } |
| 258 | 250 | ||
| 251 | // General Mods (LayeredFS and IPS) | ||
| 259 | const auto mod_dir = Service::FileSystem::GetModificationLoadRoot(title_id); | 252 | const auto mod_dir = Service::FileSystem::GetModificationLoadRoot(title_id); |
| 260 | if (mod_dir != nullptr && mod_dir->GetSize() > 0) { | 253 | if (mod_dir != nullptr && mod_dir->GetSize() > 0) { |
| 261 | for (const auto& mod : mod_dir->GetSubdirectories()) { | 254 | for (const auto& mod : mod_dir->GetSubdirectories()) { |
| @@ -292,7 +285,7 @@ std::map<std::string, std::string> PatchManager::GetPatchVersionNames() const { | |||
| 292 | 285 | ||
| 293 | list += fmt::format("{}", dlc_match.back().title_id & 0x7FF); | 286 | list += fmt::format("{}", dlc_match.back().title_id & 0x7FF); |
| 294 | 287 | ||
| 295 | out.insert_or_assign(PatchType::DLC, std::move(list)); | 288 | out.insert_or_assign("DLC", std::move(list)); |
| 296 | } | 289 | } |
| 297 | 290 | ||
| 298 | return out; | 291 | return out; |
diff --git a/src/core/file_sys/patch_manager.h b/src/core/file_sys/patch_manager.h index 254f7bfc9..6a864ec43 100644 --- a/src/core/file_sys/patch_manager.h +++ b/src/core/file_sys/patch_manager.h | |||
| @@ -50,7 +50,7 @@ public: | |||
| 50 | 50 | ||
| 51 | // Returns a vector of pairs between patch names and patch versions. | 51 | // Returns a vector of pairs between patch names and patch versions. |
| 52 | // i.e. Update 3.2.2 will return {"Update", "3.2.2"} | 52 | // i.e. Update 3.2.2 will return {"Update", "3.2.2"} |
| 53 | std::map<std::string, std::string> GetPatchVersionNames() const; | 53 | std::map<std::string, std::string, std::less<>> GetPatchVersionNames() const; |
| 54 | 54 | ||
| 55 | // Given title_id of the program, attempts to get the control data of the update and parse it, | 55 | // Given title_id of the program, attempts to get the control data of the update and parse it, |
| 56 | // falling back to the base control data. | 56 | // falling back to the base control data. |
diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp index 338f6b01b..9a86e5824 100644 --- a/src/core/loader/deconstructed_rom_directory.cpp +++ b/src/core/loader/deconstructed_rom_directory.cpp | |||
| @@ -130,6 +130,7 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(Kernel::Process& process) | |||
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | process.LoadFromMetadata(metadata); | 132 | process.LoadFromMetadata(metadata); |
| 133 | const FileSys::PatchManager pm(metadata.GetTitleID()); | ||
| 133 | 134 | ||
| 134 | // Load NSO modules | 135 | // Load NSO modules |
| 135 | const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); | 136 | const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); |
| @@ -139,9 +140,7 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(Kernel::Process& process) | |||
| 139 | const FileSys::VirtualFile module_file = dir->GetFile(module); | 140 | const FileSys::VirtualFile module_file = dir->GetFile(module); |
| 140 | if (module_file != nullptr) { | 141 | if (module_file != nullptr) { |
| 141 | const VAddr load_addr = next_load_addr; | 142 | const VAddr load_addr = next_load_addr; |
| 142 | next_load_addr = AppLoader_NSO::LoadModule( | 143 | next_load_addr = AppLoader_NSO::LoadModule(module_file, load_addr, pm); |
| 143 | module_file, load_addr, | ||
| 144 | std::make_shared<FileSys::PatchManager>(metadata.GetTitleID())); | ||
| 145 | LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", module, load_addr); | 144 | LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", module, load_addr); |
| 146 | // Register module with GDBStub | 145 | // Register module with GDBStub |
| 147 | GDBStub::RegisterModule(module, load_addr, next_load_addr - 1, false); | 146 | GDBStub::RegisterModule(module, load_addr, next_load_addr - 1, false); |
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index d22a88af1..2186b02af 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp | |||
| @@ -94,7 +94,7 @@ static constexpr u32 PageAlignSize(u32 size) { | |||
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base, | 96 | VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base, |
| 97 | std::shared_ptr<FileSys::PatchManager> pm) { | 97 | boost::optional<FileSys::PatchManager> pm) { |
| 98 | if (file == nullptr) | 98 | if (file == nullptr) |
| 99 | return {}; | 99 | return {}; |
| 100 | 100 | ||
| @@ -144,7 +144,7 @@ VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base, | |||
| 144 | program_image.resize(image_size); | 144 | program_image.resize(image_size); |
| 145 | 145 | ||
| 146 | // Apply patches if necessary | 146 | // Apply patches if necessary |
| 147 | if (pm != nullptr && pm->HasNSOPatch(nso_header.build_id)) { | 147 | if (pm != boost::none && pm->HasNSOPatch(nso_header.build_id)) { |
| 148 | std::vector<u8> pi_header(program_image.size() + 0x100); | 148 | std::vector<u8> pi_header(program_image.size() + 0x100); |
| 149 | std::memcpy(pi_header.data(), &nso_header, sizeof(NsoHeader)); | 149 | std::memcpy(pi_header.data(), &nso_header, sizeof(NsoHeader)); |
| 150 | std::memcpy(pi_header.data() + 0x100, program_image.data(), program_image.size()); | 150 | std::memcpy(pi_header.data() + 0x100, program_image.data(), program_image.size()); |
diff --git a/src/core/loader/nso.h b/src/core/loader/nso.h index 7c26aa4ba..05353d4d9 100644 --- a/src/core/loader/nso.h +++ b/src/core/loader/nso.h | |||
| @@ -28,7 +28,7 @@ public: | |||
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | static VAddr LoadModule(FileSys::VirtualFile file, VAddr load_base, | 30 | static VAddr LoadModule(FileSys::VirtualFile file, VAddr load_base, |
| 31 | std::shared_ptr<FileSys::PatchManager> pm = nullptr); | 31 | boost::optional<FileSys::PatchManager> pm = boost::none); |
| 32 | 32 | ||
| 33 | ResultStatus Load(Kernel::Process& process) override; | 33 | ResultStatus Load(Kernel::Process& process) override; |
| 34 | }; | 34 | }; |