diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/core/file_sys/ips_layer.cpp | 88 | ||||
| -rw-r--r-- | src/core/file_sys/ips_layer.h | 15 | ||||
| -rw-r--r-- | src/core/file_sys/patch_manager.cpp | 141 | ||||
| -rw-r--r-- | src/core/file_sys/patch_manager.h | 20 | ||||
| -rw-r--r-- | src/core/loader/deconstructed_rom_directory.cpp | 3 | ||||
| -rw-r--r-- | src/core/loader/nso.cpp | 18 | ||||
| -rw-r--r-- | src/core/loader/nso.h | 4 | ||||
| -rw-r--r-- | src/yuzu/game_list_worker.cpp | 7 |
9 files changed, 258 insertions, 40 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 23fd6e920..a98dbb9ab 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -34,6 +34,8 @@ add_library(core STATIC | |||
| 34 | file_sys/errors.h | 34 | file_sys/errors.h |
| 35 | file_sys/fsmitm_romfsbuild.cpp | 35 | file_sys/fsmitm_romfsbuild.cpp |
| 36 | file_sys/fsmitm_romfsbuild.h | 36 | file_sys/fsmitm_romfsbuild.h |
| 37 | file_sys/ips_layer.cpp | ||
| 38 | file_sys/ips_layer.h | ||
| 37 | file_sys/mode.h | 39 | file_sys/mode.h |
| 38 | file_sys/nca_metadata.cpp | 40 | file_sys/nca_metadata.cpp |
| 39 | file_sys/nca_metadata.h | 41 | file_sys/nca_metadata.h |
diff --git a/src/core/file_sys/ips_layer.cpp b/src/core/file_sys/ips_layer.cpp new file mode 100644 index 000000000..df933ee36 --- /dev/null +++ b/src/core/file_sys/ips_layer.cpp | |||
| @@ -0,0 +1,88 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/assert.h" | ||
| 6 | #include "common/swap.h" | ||
| 7 | #include "core/file_sys/ips_layer.h" | ||
| 8 | #include "core/file_sys/vfs_vector.h" | ||
| 9 | |||
| 10 | namespace FileSys { | ||
| 11 | |||
| 12 | enum class IPSFileType { | ||
| 13 | IPS, | ||
| 14 | IPS32, | ||
| 15 | Error, | ||
| 16 | }; | ||
| 17 | |||
| 18 | static IPSFileType IdentifyMagic(const std::vector<u8>& magic) { | ||
| 19 | if (magic.size() != 5) | ||
| 20 | return IPSFileType::Error; | ||
| 21 | if (magic == std::vector<u8>{'P', 'A', 'T', 'C', 'H'}) | ||
| 22 | return IPSFileType::IPS; | ||
| 23 | if (magic == std::vector<u8>{'I', 'P', 'S', '3', '2'}) | ||
| 24 | return IPSFileType::IPS32; | ||
| 25 | return IPSFileType::Error; | ||
| 26 | } | ||
| 27 | |||
| 28 | VirtualFile PatchIPS(const VirtualFile& in, const VirtualFile& ips) { | ||
| 29 | if (in == nullptr || ips == nullptr) | ||
| 30 | return nullptr; | ||
| 31 | |||
| 32 | const auto type = IdentifyMagic(ips->ReadBytes(0x5)); | ||
| 33 | if (type == IPSFileType::Error) | ||
| 34 | return nullptr; | ||
| 35 | |||
| 36 | auto in_data = in->ReadAllBytes(); | ||
| 37 | |||
| 38 | std::vector<u8> temp(type == IPSFileType::IPS ? 3 : 4); | ||
| 39 | u64 offset = 5; // After header | ||
| 40 | while (ips->Read(temp.data(), temp.size(), offset) == temp.size()) { | ||
| 41 | offset += temp.size(); | ||
| 42 | if (type == IPSFileType::IPS32 && temp == std::vector<u8>{'E', 'E', 'O', 'F'} || | ||
| 43 | type == IPSFileType::IPS && temp == std::vector<u8>{'E', 'O', 'F'}) { | ||
| 44 | break; | ||
| 45 | } | ||
| 46 | |||
| 47 | u32 real_offset{}; | ||
| 48 | if (type == IPSFileType::IPS32) | ||
| 49 | real_offset = (temp[0] << 24) | (temp[1] << 16) | (temp[2] << 8) | temp[3]; | ||
| 50 | else | ||
| 51 | real_offset = (temp[0] << 16) | (temp[1] << 8) | temp[2]; | ||
| 52 | |||
| 53 | u16 data_size{}; | ||
| 54 | if (ips->ReadObject(&data_size, offset) != sizeof(u16)) | ||
| 55 | return nullptr; | ||
| 56 | data_size = Common::swap16(data_size); | ||
| 57 | offset += sizeof(u16); | ||
| 58 | |||
| 59 | if (data_size == 0) { // RLE | ||
| 60 | u16 rle_size{}; | ||
| 61 | if (ips->ReadObject(&rle_size, offset) != sizeof(u16)) | ||
| 62 | return nullptr; | ||
| 63 | rle_size = Common::swap16(data_size); | ||
| 64 | offset += sizeof(u16); | ||
| 65 | |||
| 66 | const auto data = ips->ReadByte(offset++); | ||
| 67 | if (data == boost::none) | ||
| 68 | return nullptr; | ||
| 69 | |||
| 70 | if (real_offset + rle_size > in_data.size()) | ||
| 71 | rle_size = in_data.size() - real_offset; | ||
| 72 | std::memset(in_data.data() + real_offset, data.get(), rle_size); | ||
| 73 | } else { // Standard Patch | ||
| 74 | auto read = data_size; | ||
| 75 | if (real_offset + read > in_data.size()) | ||
| 76 | read = in_data.size() - real_offset; | ||
| 77 | if (ips->Read(in_data.data() + real_offset, read, offset) != data_size) | ||
| 78 | return nullptr; | ||
| 79 | offset += data_size; | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | if (temp != std::vector<u8>{'E', 'E', 'O', 'F'} && temp != std::vector<u8>{'E', 'O', 'F'}) | ||
| 84 | return nullptr; | ||
| 85 | return std::make_shared<VectorVfsFile>(in_data, in->GetName(), in->GetContainingDirectory()); | ||
| 86 | } | ||
| 87 | |||
| 88 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/ips_layer.h b/src/core/file_sys/ips_layer.h new file mode 100644 index 000000000..81c163494 --- /dev/null +++ b/src/core/file_sys/ips_layer.h | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <memory> | ||
| 8 | |||
| 9 | #include "core/file_sys/vfs.h" | ||
| 10 | |||
| 11 | namespace FileSys { | ||
| 12 | |||
| 13 | VirtualFile PatchIPS(const VirtualFile& in, const VirtualFile& ips); | ||
| 14 | |||
| 15 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index 57b7741f8..539698f6e 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp | |||
| @@ -5,14 +5,18 @@ | |||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <array> | 6 | #include <array> |
| 7 | #include <cstddef> | 7 | #include <cstddef> |
| 8 | #include <cstring> | ||
| 8 | 9 | ||
| 10 | #include "common/hex_util.h" | ||
| 9 | #include "common/logging/log.h" | 11 | #include "common/logging/log.h" |
| 10 | #include "core/file_sys/content_archive.h" | 12 | #include "core/file_sys/content_archive.h" |
| 11 | #include "core/file_sys/control_metadata.h" | 13 | #include "core/file_sys/control_metadata.h" |
| 14 | #include "core/file_sys/ips_layer.h" | ||
| 12 | #include "core/file_sys/patch_manager.h" | 15 | #include "core/file_sys/patch_manager.h" |
| 13 | #include "core/file_sys/registered_cache.h" | 16 | #include "core/file_sys/registered_cache.h" |
| 14 | #include "core/file_sys/romfs.h" | 17 | #include "core/file_sys/romfs.h" |
| 15 | #include "core/file_sys/vfs_layered.h" | 18 | #include "core/file_sys/vfs_layered.h" |
| 19 | #include "core/file_sys/vfs_vector.h" | ||
| 16 | #include "core/hle/service/filesystem/filesystem.h" | 20 | #include "core/hle/service/filesystem/filesystem.h" |
| 17 | #include "core/loader/loader.h" | 21 | #include "core/loader/loader.h" |
| 18 | 22 | ||
| @@ -21,6 +25,14 @@ namespace FileSys { | |||
| 21 | constexpr u64 SINGLE_BYTE_MODULUS = 0x100; | 25 | constexpr u64 SINGLE_BYTE_MODULUS = 0x100; |
| 22 | constexpr u64 DLC_BASE_TITLE_ID_MASK = 0xFFFFFFFFFFFFE000; | 26 | constexpr u64 DLC_BASE_TITLE_ID_MASK = 0xFFFFFFFFFFFFE000; |
| 23 | 27 | ||
| 28 | struct NSOBuildHeader { | ||
| 29 | u32_le magic; | ||
| 30 | INSERT_PADDING_BYTES(0x3C); | ||
| 31 | std::array<u8, 0x20> build_id; | ||
| 32 | INSERT_PADDING_BYTES(0xA0); | ||
| 33 | }; | ||
| 34 | static_assert(sizeof(NSOBuildHeader) == 0x100, "NSOBuildHeader has incorrect size."); | ||
| 35 | |||
| 24 | std::string FormatTitleVersion(u32 version, TitleVersionFormat format) { | 36 | std::string FormatTitleVersion(u32 version, TitleVersionFormat format) { |
| 25 | std::array<u8, sizeof(u32)> bytes{}; | 37 | std::array<u8, sizeof(u32)> bytes{}; |
| 26 | bytes[0] = version % SINGLE_BYTE_MODULUS; | 38 | bytes[0] = version % SINGLE_BYTE_MODULUS; |
| @@ -34,16 +46,6 @@ std::string FormatTitleVersion(u32 version, TitleVersionFormat format) { | |||
| 34 | return fmt::format("v{}.{}.{}", bytes[3], bytes[2], bytes[1]); | 46 | return fmt::format("v{}.{}.{}", bytes[3], bytes[2], bytes[1]); |
| 35 | } | 47 | } |
| 36 | 48 | ||
| 37 | constexpr std::array<const char*, 3> PATCH_TYPE_NAMES{ | ||
| 38 | "Update", | ||
| 39 | "LayeredFS", | ||
| 40 | "DLC", | ||
| 41 | }; | ||
| 42 | |||
| 43 | std::string FormatPatchTypeName(PatchType type) { | ||
| 44 | return PATCH_TYPE_NAMES.at(static_cast<std::size_t>(type)); | ||
| 45 | } | ||
| 46 | |||
| 47 | PatchManager::PatchManager(u64 title_id) : title_id(title_id) {} | 49 | PatchManager::PatchManager(u64 title_id) : title_id(title_id) {} |
| 48 | 50 | ||
| 49 | PatchManager::~PatchManager() = default; | 51 | PatchManager::~PatchManager() = default; |
| @@ -71,6 +73,79 @@ VirtualDir PatchManager::PatchExeFS(VirtualDir exefs) const { | |||
| 71 | return exefs; | 73 | return exefs; |
| 72 | } | 74 | } |
| 73 | 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 | |||
| 99 | std::vector<u8> PatchManager::PatchNSO(const std::vector<u8>& nso) const { | ||
| 100 | if (nso.size() < 0x100) | ||
| 101 | return nso; | ||
| 102 | |||
| 103 | NSOBuildHeader header; | ||
| 104 | std::memcpy(&header, nso.data(), sizeof(NSOBuildHeader)); | ||
| 105 | |||
| 106 | if (header.magic != Common::MakeMagic('N', 'S', 'O', '0')) | ||
| 107 | return nso; | ||
| 108 | |||
| 109 | const auto build_id_raw = Common::HexArrayToString(header.build_id); | ||
| 110 | const auto build_id = build_id_raw.substr(0, build_id_raw.find_last_not_of('0') + 1); | ||
| 111 | |||
| 112 | LOG_INFO(Loader, "Patching NSO for build_id={}", build_id); | ||
| 113 | |||
| 114 | const auto load_dir = Service::FileSystem::GetModificationLoadRoot(title_id); | ||
| 115 | auto patch_dirs = load_dir->GetSubdirectories(); | ||
| 116 | std::sort(patch_dirs.begin(), patch_dirs.end(), | ||
| 117 | [](const VirtualDir& l, const VirtualDir& r) { return l->GetName() < r->GetName(); }); | ||
| 118 | const auto ips = CollectIPSPatches(patch_dirs, build_id); | ||
| 119 | |||
| 120 | auto out = nso; | ||
| 121 | for (const auto& ips_file : ips) { | ||
| 122 | LOG_INFO(Loader, " - Appling IPS patch from mod \"{}\"", | ||
| 123 | ips_file->GetContainingDirectory()->GetParentDirectory()->GetName()); | ||
| 124 | const auto patched = PatchIPS(std::make_shared<VectorVfsFile>(out), ips_file); | ||
| 125 | if (patched != nullptr) | ||
| 126 | out = patched->ReadAllBytes(); | ||
| 127 | } | ||
| 128 | |||
| 129 | if (out.size() < 0x100) | ||
| 130 | return nso; | ||
| 131 | std::memcpy(out.data(), &header, sizeof(NSOBuildHeader)); | ||
| 132 | return out; | ||
| 133 | } | ||
| 134 | |||
| 135 | bool PatchManager::HasNSOPatch(const std::array<u8, 32>& build_id_) const { | ||
| 136 | const auto build_id_raw = Common::HexArrayToString(build_id_); | ||
| 137 | const auto build_id = build_id_raw.substr(0, build_id_raw.find_last_not_of('0') + 1); | ||
| 138 | |||
| 139 | LOG_INFO(Loader, "Querying NSO patch existence for build_id={}", build_id); | ||
| 140 | |||
| 141 | const auto load_dir = Service::FileSystem::GetModificationLoadRoot(title_id); | ||
| 142 | auto patch_dirs = load_dir->GetSubdirectories(); | ||
| 143 | std::sort(patch_dirs.begin(), patch_dirs.end(), | ||
| 144 | [](const VirtualDir& l, const VirtualDir& r) { return l->GetName() < r->GetName(); }); | ||
| 145 | |||
| 146 | return !CollectIPSPatches(patch_dirs, build_id).empty(); | ||
| 147 | } | ||
| 148 | |||
| 74 | static void ApplyLayeredFS(VirtualFile& romfs, u64 title_id, ContentRecordType type) { | 149 | static void ApplyLayeredFS(VirtualFile& romfs, u64 title_id, ContentRecordType type) { |
| 75 | const auto load_dir = Service::FileSystem::GetModificationLoadRoot(title_id); | 150 | const auto load_dir = Service::FileSystem::GetModificationLoadRoot(title_id); |
| 76 | if (type != ContentRecordType::Program || load_dir == nullptr || load_dir->GetSize() <= 0) { | 151 | if (type != ContentRecordType::Program || load_dir == nullptr || load_dir->GetSize() <= 0) { |
| @@ -138,8 +213,19 @@ VirtualFile PatchManager::PatchRomFS(VirtualFile romfs, u64 ivfc_offset, | |||
| 138 | return romfs; | 213 | return romfs; |
| 139 | } | 214 | } |
| 140 | 215 | ||
| 141 | std::map<PatchType, std::string> PatchManager::GetPatchVersionNames() const { | 216 | static void AppendCommaIfNotEmpty(std::string& to, const std::string& with) { |
| 142 | std::map<PatchType, std::string> out; | 217 | if (to.empty()) |
| 218 | to += with; | ||
| 219 | else | ||
| 220 | to += ", " + with; | ||
| 221 | } | ||
| 222 | |||
| 223 | static bool IsDirValidAndNonEmpty(const VirtualDir& dir) { | ||
| 224 | return dir != nullptr && (!dir->GetFiles().empty() || !dir->GetSubdirectories().empty()); | ||
| 225 | } | ||
| 226 | |||
| 227 | std::map<std::string, std::string, std::less<>> PatchManager::GetPatchVersionNames() const { | ||
| 228 | std::map<std::string, std::string, std::less<>> out; | ||
| 143 | const auto installed = Service::FileSystem::GetUnionContents(); | 229 | const auto installed = Service::FileSystem::GetUnionContents(); |
| 144 | 230 | ||
| 145 | // Game Updates | 231 | // Game Updates |
| @@ -148,23 +234,36 @@ std::map<PatchType, std::string> PatchManager::GetPatchVersionNames() const { | |||
| 148 | auto [nacp, discard_icon_file] = update.GetControlMetadata(); | 234 | auto [nacp, discard_icon_file] = update.GetControlMetadata(); |
| 149 | 235 | ||
| 150 | if (nacp != nullptr) { | 236 | if (nacp != nullptr) { |
| 151 | out[PatchType::Update] = nacp->GetVersionString(); | 237 | out.insert_or_assign("Update", nacp->GetVersionString()); |
| 152 | } else { | 238 | } else { |
| 153 | if (installed->HasEntry(update_tid, ContentRecordType::Program)) { | 239 | if (installed->HasEntry(update_tid, ContentRecordType::Program)) { |
| 154 | const auto meta_ver = installed->GetEntryVersion(update_tid); | 240 | const auto meta_ver = installed->GetEntryVersion(update_tid); |
| 155 | if (meta_ver == boost::none || meta_ver.get() == 0) { | 241 | if (meta_ver == boost::none || meta_ver.get() == 0) { |
| 156 | out[PatchType::Update] = ""; | 242 | out.insert_or_assign("Update", ""); |
| 157 | } else { | 243 | } else { |
| 158 | out[PatchType::Update] = | 244 | out.insert_or_assign( |
| 159 | FormatTitleVersion(meta_ver.get(), TitleVersionFormat::ThreeElements); | 245 | "Update", |
| 246 | FormatTitleVersion(meta_ver.get(), TitleVersionFormat::ThreeElements)); | ||
| 160 | } | 247 | } |
| 161 | } | 248 | } |
| 162 | } | 249 | } |
| 163 | 250 | ||
| 164 | // LayeredFS | 251 | // General Mods (LayeredFS and IPS) |
| 165 | const auto lfs_dir = Service::FileSystem::GetModificationLoadRoot(title_id); | 252 | const auto mod_dir = Service::FileSystem::GetModificationLoadRoot(title_id); |
| 166 | if (lfs_dir != nullptr && lfs_dir->GetSize() > 0) | 253 | if (mod_dir != nullptr && mod_dir->GetSize() > 0) { |
| 167 | out.insert_or_assign(PatchType::LayeredFS, ""); | 254 | for (const auto& mod : mod_dir->GetSubdirectories()) { |
| 255 | std::string types; | ||
| 256 | if (IsDirValidAndNonEmpty(mod->GetSubdirectory("exefs"))) | ||
| 257 | AppendCommaIfNotEmpty(types, "IPS"); | ||
| 258 | if (IsDirValidAndNonEmpty(mod->GetSubdirectory("romfs"))) | ||
| 259 | AppendCommaIfNotEmpty(types, "LayeredFS"); | ||
| 260 | |||
| 261 | if (types.empty()) | ||
| 262 | continue; | ||
| 263 | |||
| 264 | out.insert_or_assign(mod->GetName(), types); | ||
| 265 | } | ||
| 266 | } | ||
| 168 | 267 | ||
| 169 | // DLC | 268 | // DLC |
| 170 | const auto dlc_entries = installed->ListEntriesFilter(TitleType::AOC, ContentRecordType::Data); | 269 | const auto dlc_entries = installed->ListEntriesFilter(TitleType::AOC, ContentRecordType::Data); |
| @@ -186,7 +285,7 @@ std::map<PatchType, std::string> PatchManager::GetPatchVersionNames() const { | |||
| 186 | 285 | ||
| 187 | list += fmt::format("{}", dlc_match.back().title_id & 0x7FF); | 286 | list += fmt::format("{}", dlc_match.back().title_id & 0x7FF); |
| 188 | 287 | ||
| 189 | out.insert_or_assign(PatchType::DLC, std::move(list)); | 288 | out.insert_or_assign("DLC", std::move(list)); |
| 190 | } | 289 | } |
| 191 | 290 | ||
| 192 | return out; | 291 | return out; |
diff --git a/src/core/file_sys/patch_manager.h b/src/core/file_sys/patch_manager.h index 3a2a9d212..6a864ec43 100644 --- a/src/core/file_sys/patch_manager.h +++ b/src/core/file_sys/patch_manager.h | |||
| @@ -24,14 +24,6 @@ enum class TitleVersionFormat : u8 { | |||
| 24 | std::string FormatTitleVersion(u32 version, | 24 | std::string FormatTitleVersion(u32 version, |
| 25 | TitleVersionFormat format = TitleVersionFormat::ThreeElements); | 25 | TitleVersionFormat format = TitleVersionFormat::ThreeElements); |
| 26 | 26 | ||
| 27 | enum class PatchType { | ||
| 28 | Update, | ||
| 29 | LayeredFS, | ||
| 30 | DLC, | ||
| 31 | }; | ||
| 32 | |||
| 33 | std::string FormatPatchTypeName(PatchType type); | ||
| 34 | |||
| 35 | // A centralized class to manage patches to games. | 27 | // A centralized class to manage patches to games. |
| 36 | class PatchManager { | 28 | class PatchManager { |
| 37 | public: | 29 | public: |
| @@ -42,6 +34,14 @@ public: | |||
| 42 | // - Game Updates | 34 | // - Game Updates |
| 43 | VirtualDir PatchExeFS(VirtualDir exefs) const; | 35 | VirtualDir PatchExeFS(VirtualDir exefs) const; |
| 44 | 36 | ||
| 37 | // Currently tracked NSO patches: | ||
| 38 | // - IPS | ||
| 39 | std::vector<u8> PatchNSO(const std::vector<u8>& nso) const; | ||
| 40 | |||
| 41 | // Checks to see if PatchNSO() will have any effect given the NSO's build ID. | ||
| 42 | // Used to prevent expensive copies in NSO loader. | ||
| 43 | bool HasNSOPatch(const std::array<u8, 0x20>& build_id) const; | ||
| 44 | |||
| 45 | // Currently tracked RomFS patches: | 45 | // Currently tracked RomFS patches: |
| 46 | // - Game Updates | 46 | // - Game Updates |
| 47 | // - LayeredFS | 47 | // - LayeredFS |
| @@ -49,8 +49,8 @@ public: | |||
| 49 | ContentRecordType type = ContentRecordType::Program) const; | 49 | ContentRecordType type = ContentRecordType::Program) const; |
| 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 v80 will return {Update, 80} | 52 | // i.e. Update 3.2.2 will return {"Update", "3.2.2"} |
| 53 | std::map<PatchType, 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 c1824b9c3..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,7 +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(module_file, load_addr); | 143 | next_load_addr = AppLoader_NSO::LoadModule(module_file, load_addr, pm); |
| 143 | LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", module, load_addr); | 144 | LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", module, load_addr); |
| 144 | // Register module with GDBStub | 145 | // Register module with GDBStub |
| 145 | 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 cbe2a3e53..2186b02af 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | #include "common/logging/log.h" | 10 | #include "common/logging/log.h" |
| 11 | #include "common/swap.h" | 11 | #include "common/swap.h" |
| 12 | #include "core/core.h" | 12 | #include "core/core.h" |
| 13 | #include "core/file_sys/patch_manager.h" | ||
| 13 | #include "core/gdbstub/gdbstub.h" | 14 | #include "core/gdbstub/gdbstub.h" |
| 14 | #include "core/hle/kernel/kernel.h" | 15 | #include "core/hle/kernel/kernel.h" |
| 15 | #include "core/hle/kernel/process.h" | 16 | #include "core/hle/kernel/process.h" |
| @@ -36,8 +37,7 @@ struct NsoHeader { | |||
| 36 | INSERT_PADDING_WORDS(1); | 37 | INSERT_PADDING_WORDS(1); |
| 37 | u8 flags; | 38 | u8 flags; |
| 38 | std::array<NsoSegmentHeader, 3> segments; // Text, RoData, Data (in that order) | 39 | std::array<NsoSegmentHeader, 3> segments; // Text, RoData, Data (in that order) |
| 39 | u32_le bss_size; | 40 | std::array<u8, 0x20> build_id; |
| 40 | INSERT_PADDING_BYTES(0x1c); | ||
| 41 | std::array<u32_le, 3> segments_compressed_size; | 41 | std::array<u32_le, 3> segments_compressed_size; |
| 42 | 42 | ||
| 43 | bool IsSegmentCompressed(size_t segment_num) const { | 43 | bool IsSegmentCompressed(size_t segment_num) const { |
| @@ -93,7 +93,8 @@ static constexpr u32 PageAlignSize(u32 size) { | |||
| 93 | return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; | 93 | return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; |
| 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 | boost::optional<FileSys::PatchManager> pm) { | ||
| 97 | if (file == nullptr) | 98 | if (file == nullptr) |
| 98 | return {}; | 99 | return {}; |
| 99 | 100 | ||
| @@ -142,6 +143,17 @@ VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base) { | |||
| 142 | const u32 image_size{PageAlignSize(static_cast<u32>(program_image.size()) + bss_size)}; | 143 | const u32 image_size{PageAlignSize(static_cast<u32>(program_image.size()) + bss_size)}; |
| 143 | program_image.resize(image_size); | 144 | program_image.resize(image_size); |
| 144 | 145 | ||
| 146 | // Apply patches if necessary | ||
| 147 | if (pm != boost::none && pm->HasNSOPatch(nso_header.build_id)) { | ||
| 148 | std::vector<u8> pi_header(program_image.size() + 0x100); | ||
| 149 | std::memcpy(pi_header.data(), &nso_header, sizeof(NsoHeader)); | ||
| 150 | std::memcpy(pi_header.data() + 0x100, program_image.data(), program_image.size()); | ||
| 151 | |||
| 152 | pi_header = pm->PatchNSO(pi_header); | ||
| 153 | |||
| 154 | std::memcpy(program_image.data(), pi_header.data() + 0x100, program_image.size()); | ||
| 155 | } | ||
| 156 | |||
| 145 | // Load codeset for current process | 157 | // Load codeset for current process |
| 146 | codeset->name = file->GetName(); | 158 | codeset->name = file->GetName(); |
| 147 | codeset->memory = std::make_shared<std::vector<u8>>(std::move(program_image)); | 159 | codeset->memory = std::make_shared<std::vector<u8>>(std::move(program_image)); |
diff --git a/src/core/loader/nso.h b/src/core/loader/nso.h index 7f142405b..05353d4d9 100644 --- a/src/core/loader/nso.h +++ b/src/core/loader/nso.h | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 8 | #include "core/file_sys/patch_manager.h" | ||
| 8 | #include "core/loader/linker.h" | 9 | #include "core/loader/linker.h" |
| 9 | #include "core/loader/loader.h" | 10 | #include "core/loader/loader.h" |
| 10 | 11 | ||
| @@ -26,7 +27,8 @@ public: | |||
| 26 | return IdentifyType(file); | 27 | return IdentifyType(file); |
| 27 | } | 28 | } |
| 28 | 29 | ||
| 29 | static VAddr LoadModule(FileSys::VirtualFile file, VAddr load_base); | 30 | static VAddr LoadModule(FileSys::VirtualFile file, VAddr load_base, |
| 31 | boost::optional<FileSys::PatchManager> pm = boost::none); | ||
| 30 | 32 | ||
| 31 | ResultStatus Load(Kernel::Process& process) override; | 33 | ResultStatus Load(Kernel::Process& process) override; |
| 32 | }; | 34 | }; |
diff --git a/src/yuzu/game_list_worker.cpp b/src/yuzu/game_list_worker.cpp index e228d61bd..1947bdb93 100644 --- a/src/yuzu/game_list_worker.cpp +++ b/src/yuzu/game_list_worker.cpp | |||
| @@ -60,14 +60,13 @@ QString FormatGameName(const std::string& physical_name) { | |||
| 60 | QString FormatPatchNameVersions(const FileSys::PatchManager& patch_manager, bool updatable = true) { | 60 | QString FormatPatchNameVersions(const FileSys::PatchManager& patch_manager, bool updatable = true) { |
| 61 | QString out; | 61 | QString out; |
| 62 | for (const auto& kv : patch_manager.GetPatchVersionNames()) { | 62 | for (const auto& kv : patch_manager.GetPatchVersionNames()) { |
| 63 | if (!updatable && kv.first == FileSys::PatchType::Update) | 63 | if (!updatable && kv.first == "Update") |
| 64 | continue; | 64 | continue; |
| 65 | 65 | ||
| 66 | if (kv.second.empty()) { | 66 | if (kv.second.empty()) { |
| 67 | out.append(fmt::format("{}\n", FileSys::FormatPatchTypeName(kv.first)).c_str()); | 67 | out.append(fmt::format("{}\n", kv.first).c_str()); |
| 68 | } else { | 68 | } else { |
| 69 | out.append(fmt::format("{} ({})\n", FileSys::FormatPatchTypeName(kv.first), kv.second) | 69 | out.append(fmt::format("{} ({})\n", kv.first, kv.second).c_str()); |
| 70 | .c_str()); | ||
| 71 | } | 70 | } |
| 72 | } | 71 | } |
| 73 | 72 | ||