From e948fbf5d0211d9aed3d4cd9009e5f0224b75021 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Tue, 25 Sep 2018 09:17:14 -0400 Subject: [PATCH 1/6] loader: Add ReadRomFSIVFCOffset to NSP, XCI, and NAX loaders Fixes errors with certain updates --- src/core/loader/nax.cpp | 4 ++++ src/core/loader/nax.h | 1 + src/core/loader/nsp.cpp | 8 ++++++-- src/core/loader/nsp.h | 3 ++- src/core/loader/xci.cpp | 7 +++++-- src/core/loader/xci.h | 3 ++- 6 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/core/loader/nax.cpp b/src/core/loader/nax.cpp index 073fb9d2fe..42f4a777be 100644 --- a/src/core/loader/nax.cpp +++ b/src/core/loader/nax.cpp @@ -72,6 +72,10 @@ ResultStatus AppLoader_NAX::ReadRomFS(FileSys::VirtualFile& dir) { return nca_loader->ReadRomFS(dir); } +u64 AppLoader_NAX::ReadRomFSIVFCOffset() const { + return nca_loader->ReadRomFSIVFCOffset(); +} + ResultStatus AppLoader_NAX::ReadProgramId(u64& out_program_id) { return nca_loader->ReadProgramId(out_program_id); } diff --git a/src/core/loader/nax.h b/src/core/loader/nax.h index fc3c01876c..b4d93bd011 100644 --- a/src/core/loader/nax.h +++ b/src/core/loader/nax.h @@ -36,6 +36,7 @@ public: ResultStatus Load(Kernel::Process& process) override; ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; + u64 ReadRomFSIVFCOffset() const override; ResultStatus ReadProgramId(u64& out_program_id) override; private: diff --git a/src/core/loader/nsp.cpp b/src/core/loader/nsp.cpp index b7ba77ef46..ae1edf9ca4 100644 --- a/src/core/loader/nsp.cpp +++ b/src/core/loader/nsp.cpp @@ -96,8 +96,12 @@ ResultStatus AppLoader_NSP::Load(Kernel::Process& process) { return ResultStatus::Success; } -ResultStatus AppLoader_NSP::ReadRomFS(FileSys::VirtualFile& dir) { - return secondary_loader->ReadRomFS(dir); +ResultStatus AppLoader_NSP::ReadRomFS(FileSys::VirtualFile& file) { + return secondary_loader->ReadRomFS(file); +} + +u64 AppLoader_NSP::ReadRomFSIVFCOffset() const { + return secondary_loader->ReadRomFSIVFCOffset(); } ResultStatus AppLoader_NSP::ReadProgramId(u64& out_program_id) { diff --git a/src/core/loader/nsp.h b/src/core/loader/nsp.h index eac9b819ae..351bbf128d 100644 --- a/src/core/loader/nsp.h +++ b/src/core/loader/nsp.h @@ -37,7 +37,8 @@ public: ResultStatus Load(Kernel::Process& process) override; - ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; + ResultStatus ReadRomFS(FileSys::VirtualFile& file) override; + u64 ReadRomFSIVFCOffset() const override; ResultStatus ReadProgramId(u64& out_program_id) override; ResultStatus ReadIcon(std::vector& buffer) override; ResultStatus ReadTitle(std::string& title) override; diff --git a/src/core/loader/xci.cpp b/src/core/loader/xci.cpp index eda67a8c8c..12d589fab8 100644 --- a/src/core/loader/xci.cpp +++ b/src/core/loader/xci.cpp @@ -68,10 +68,13 @@ ResultStatus AppLoader_XCI::Load(Kernel::Process& process) { return ResultStatus::Success; } -ResultStatus AppLoader_XCI::ReadRomFS(FileSys::VirtualFile& dir) { - return nca_loader->ReadRomFS(dir); +ResultStatus AppLoader_XCI::ReadRomFS(FileSys::VirtualFile& file) { + return nca_loader->ReadRomFS(file); } +u64 AppLoader_XCI::ReadRomFSIVFCOffset() const { + return nca_loader->ReadRomFSIVFCOffset(); +} ResultStatus AppLoader_XCI::ReadProgramId(u64& out_program_id) { return nca_loader->ReadProgramId(out_program_id); } diff --git a/src/core/loader/xci.h b/src/core/loader/xci.h index 17e47b658d..4f9a9da489 100644 --- a/src/core/loader/xci.h +++ b/src/core/loader/xci.h @@ -37,7 +37,8 @@ public: ResultStatus Load(Kernel::Process& process) override; - ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; + ResultStatus ReadRomFS(FileSys::VirtualFile& file) override; + u64 ReadRomFSIVFCOffset() const override; ResultStatus ReadProgramId(u64& out_program_id) override; ResultStatus ReadIcon(std::vector& buffer) override; ResultStatus ReadTitle(std::string& title) override; From 504574882914902f0648e30078038472ae985570 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Tue, 25 Sep 2018 09:18:55 -0400 Subject: [PATCH 2/6] loader: Add getter for packed update Reads the update included with the game if it has one and adds the new ErrorNoPackedUpdate status. --- src/core/loader/loader.cpp | 3 ++- src/core/loader/loader.h | 14 ++++++++++++-- src/core/loader/nsp.cpp | 18 ++++++++++++++++++ src/core/loader/nsp.h | 1 + src/core/loader/xci.cpp | 24 ++++++++++++++++++++++++ src/core/loader/xci.h | 1 + 6 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index f2a183ba1c..91659ec176 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp @@ -93,7 +93,7 @@ std::string GetFileTypeString(FileType type) { return "unknown"; } -constexpr std::array RESULT_MESSAGES{ +constexpr std::array RESULT_MESSAGES{ "The operation completed successfully.", "The loader requested to load is already loaded.", "The operation is not implemented.", @@ -152,6 +152,7 @@ constexpr std::array RESULT_MESSAGES{ "The BKTR-type NCA has a bad Relocation bucket.", "The BKTR-type NCA has a bad Subsection bucket.", "The BKTR-type NCA is missing the base RomFS.", + "The NSP or XCI does not contain an update in addition to the base game.", }; std::ostream& operator<<(std::ostream& os, ResultStatus status) { diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 20e66109b1..0e0333db56 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -114,6 +114,7 @@ enum class ResultStatus : u16 { ErrorBadRelocationBuckets, ErrorBadSubsectionBuckets, ErrorMissingBKTRBaseRomFS, + ErrorNoPackedUpdate, }; std::ostream& operator<<(std::ostream& os, ResultStatus status); @@ -196,10 +197,19 @@ public: /** * Get the RomFS of the application * Since the RomFS can be huge, we return a file reference instead of copying to a buffer - * @param dir The directory containing the RomFS + * @param file The directory containing the RomFS * @return ResultStatus result of function */ - virtual ResultStatus ReadRomFS(FileSys::VirtualFile& dir) { + virtual ResultStatus ReadRomFS(FileSys::VirtualFile& file) { + return ResultStatus::ErrorNotImplemented; + } + + /** + * Get the raw update of the application, should it come packed with one + * @param file The raw update NCA file (Program-type + * @return ResultStatus result of function + */ + virtual ResultStatus ReadUpdateRaw(FileSys::VirtualFile& file) { return ResultStatus::ErrorNotImplemented; } diff --git a/src/core/loader/nsp.cpp b/src/core/loader/nsp.cpp index ae1edf9ca4..a630b618cc 100644 --- a/src/core/loader/nsp.cpp +++ b/src/core/loader/nsp.cpp @@ -104,6 +104,24 @@ u64 AppLoader_NSP::ReadRomFSIVFCOffset() const { return secondary_loader->ReadRomFSIVFCOffset(); } +ResultStatus AppLoader_NSP::ReadUpdateRaw(FileSys::VirtualFile& file) { + if (nsp->IsExtractedType()) + return ResultStatus::ErrorNoPackedUpdate; + + const auto read = + nsp->GetNCAFile(FileSys::GetUpdateTitleID(title_id), FileSys::ContentRecordType::Program); + + if (read == nullptr) + return ResultStatus::ErrorNoPackedUpdate; + const auto nca_test = std::make_shared(read); + + if (nca_test->GetStatus() != ResultStatus::ErrorMissingBKTRBaseRomFS) + return nca_test->GetStatus(); + + file = read; + return ResultStatus::Success; +} + ResultStatus AppLoader_NSP::ReadProgramId(u64& out_program_id) { if (title_id == 0) return ResultStatus::ErrorNotInitialized; diff --git a/src/core/loader/nsp.h b/src/core/loader/nsp.h index 351bbf128d..b006594a69 100644 --- a/src/core/loader/nsp.h +++ b/src/core/loader/nsp.h @@ -39,6 +39,7 @@ public: ResultStatus ReadRomFS(FileSys::VirtualFile& file) override; u64 ReadRomFSIVFCOffset() const override; + ResultStatus ReadUpdateRaw(FileSys::VirtualFile& file) override; ResultStatus ReadProgramId(u64& out_program_id) override; ResultStatus ReadIcon(std::vector& buffer) override; ResultStatus ReadTitle(std::string& title) override; diff --git a/src/core/loader/xci.cpp b/src/core/loader/xci.cpp index 12d589fab8..9d91ef03a7 100644 --- a/src/core/loader/xci.cpp +++ b/src/core/loader/xci.cpp @@ -9,6 +9,9 @@ #include "core/file_sys/content_archive.h" #include "core/file_sys/control_metadata.h" #include "core/file_sys/patch_manager.h" +#include "core/file_sys/registered_cache.h" +#include "core/file_sys/romfs.h" +#include "core/file_sys/submission_package.h" #include "core/hle/kernel/process.h" #include "core/loader/nca.h" #include "core/loader/xci.h" @@ -75,6 +78,27 @@ ResultStatus AppLoader_XCI::ReadRomFS(FileSys::VirtualFile& file) { u64 AppLoader_XCI::ReadRomFSIVFCOffset() const { return nca_loader->ReadRomFSIVFCOffset(); } + +ResultStatus AppLoader_XCI::ReadUpdateRaw(FileSys::VirtualFile& file) { + u64 program_id{}; + nca_loader->ReadProgramId(program_id); + if (program_id == 0) + return ResultStatus::ErrorXCIMissingProgramNCA; + + const auto read = xci->GetSecurePartitionNSP()->GetNCAFile( + FileSys::GetUpdateTitleID(program_id), FileSys::ContentRecordType::Program); + + if (read == nullptr) + return ResultStatus::ErrorNoPackedUpdate; + const auto nca_test = std::make_shared(read); + + if (nca_test->GetStatus() != ResultStatus::ErrorMissingBKTRBaseRomFS) + return nca_test->GetStatus(); + + file = read; + return ResultStatus::Success; +} + ResultStatus AppLoader_XCI::ReadProgramId(u64& out_program_id) { return nca_loader->ReadProgramId(out_program_id); } diff --git a/src/core/loader/xci.h b/src/core/loader/xci.h index 4f9a9da489..770ed14374 100644 --- a/src/core/loader/xci.h +++ b/src/core/loader/xci.h @@ -39,6 +39,7 @@ public: ResultStatus ReadRomFS(FileSys::VirtualFile& file) override; u64 ReadRomFSIVFCOffset() const override; + ResultStatus ReadUpdateRaw(FileSys::VirtualFile& file) override; ResultStatus ReadProgramId(u64& out_program_id) override; ResultStatus ReadIcon(std::vector& buffer) override; ResultStatus ReadTitle(std::string& title) override; From d79d4fd764c194e6c8c4d57ed0fd308e401c2f6e Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Tue, 25 Sep 2018 09:19:42 -0400 Subject: [PATCH 3/6] patch_manager: Add support for packed updates Will prefer any installed update over the packed version. --- src/core/file_sys/patch_manager.cpp | 15 ++++++++++++--- src/core/file_sys/patch_manager.h | 3 ++- src/core/file_sys/romfs_factory.cpp | 4 +++- src/core/file_sys/romfs_factory.h | 1 + 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index 539698f6e0..b43880e928 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp @@ -184,8 +184,8 @@ static void ApplyLayeredFS(VirtualFile& romfs, u64 title_id, ContentRecordType t romfs = std::move(packed); } -VirtualFile PatchManager::PatchRomFS(VirtualFile romfs, u64 ivfc_offset, - ContentRecordType type) const { +VirtualFile PatchManager::PatchRomFS(VirtualFile romfs, u64 ivfc_offset, ContentRecordType type, + VirtualFile update_raw) const { LOG_INFO(Loader, "Patching RomFS for title_id={:016X}, type={:02X}", title_id, static_cast(type)); @@ -205,6 +205,13 @@ VirtualFile PatchManager::PatchRomFS(VirtualFile romfs, u64 ivfc_offset, FormatTitleVersion(installed->GetEntryVersion(update_tid).get_value_or(0))); romfs = new_nca->GetRomFS(); } + } else if (update_raw != nullptr) { + const auto new_nca = std::make_shared(update, romfs, ivfc_offset); + if (new_nca->GetStatus() == Loader::ResultStatus::Success && + new_nca->GetRomFS() != nullptr) { + LOG_INFO(Loader, " RomFS: Update (XCI) applied successfully"); + romfs = new_nca->GetRomFS(); + } } // LayeredFS @@ -224,7 +231,7 @@ static bool IsDirValidAndNonEmpty(const VirtualDir& dir) { return dir != nullptr && (!dir->GetFiles().empty() || !dir->GetSubdirectories().empty()); } -std::map> PatchManager::GetPatchVersionNames() const { +std::map PatchManager::GetPatchVersionNames(VirtualFile update_raw) const { std::map> out; const auto installed = Service::FileSystem::GetUnionContents(); @@ -245,6 +252,8 @@ std::map> PatchManager::GetPatchVersionNam "Update", FormatTitleVersion(meta_ver.get(), TitleVersionFormat::ThreeElements)); } + } else if (update_raw != nullptr) { + out[PatchType::Update] = "XCI"; } } diff --git a/src/core/file_sys/patch_manager.h b/src/core/file_sys/patch_manager.h index 6a864ec43c..e87ce54e58 100644 --- a/src/core/file_sys/patch_manager.h +++ b/src/core/file_sys/patch_manager.h @@ -46,7 +46,8 @@ public: // - Game Updates // - LayeredFS VirtualFile PatchRomFS(VirtualFile base, u64 ivfc_offset, - ContentRecordType type = ContentRecordType::Program) const; + ContentRecordType type = ContentRecordType::Program, + VirtualFile update_raw = nullptr) const; // Returns a vector of pairs between patch names and patch versions. // i.e. Update 3.2.2 will return {"Update", "3.2.2"} diff --git a/src/core/file_sys/romfs_factory.cpp b/src/core/file_sys/romfs_factory.cpp index 4994c2532a..a0ee16895a 100644 --- a/src/core/file_sys/romfs_factory.cpp +++ b/src/core/file_sys/romfs_factory.cpp @@ -24,6 +24,7 @@ RomFSFactory::RomFSFactory(Loader::AppLoader& app_loader) { LOG_ERROR(Service_FS, "Unable to read RomFS!"); } + app_loader.ReadUpdateRaw(update_raw); updatable = app_loader.IsRomFSUpdatable(); ivfc_offset = app_loader.ReadRomFSIVFCOffset(); } @@ -35,7 +36,8 @@ ResultVal RomFSFactory::OpenCurrentProcess() { return MakeResult(file); const PatchManager patch_manager(Core::CurrentProcess()->GetTitleID()); - return MakeResult(patch_manager.PatchRomFS(file, ivfc_offset)); + return MakeResult( + patch_manager.PatchRomFS(file, ivfc_offset, ContentRecordType::Program, update_raw)); } ResultVal RomFSFactory::Open(u64 title_id, StorageId storage, ContentRecordType type) { diff --git a/src/core/file_sys/romfs_factory.h b/src/core/file_sys/romfs_factory.h index 2cace8180c..1cd4cedf11 100644 --- a/src/core/file_sys/romfs_factory.h +++ b/src/core/file_sys/romfs_factory.h @@ -37,6 +37,7 @@ public: private: VirtualFile file; + VirtualFile update_raw; bool updatable; u64 ivfc_offset; }; From cf7aba4817e4b00e9c6eaa5b81500b32e61f4655 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Tue, 25 Sep 2018 09:21:06 -0400 Subject: [PATCH 4/6] game_list: Add XCI update versioning to game list --- src/yuzu/game_list_worker.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/yuzu/game_list_worker.cpp b/src/yuzu/game_list_worker.cpp index 1947bdb93c..2bcc54b2fc 100644 --- a/src/yuzu/game_list_worker.cpp +++ b/src/yuzu/game_list_worker.cpp @@ -57,9 +57,12 @@ QString FormatGameName(const std::string& physical_name) { return physical_name_as_qstring; } -QString FormatPatchNameVersions(const FileSys::PatchManager& patch_manager, bool updatable = true) { +QString FormatPatchNameVersions(const FileSys::PatchManager& patch_manager, + Loader::AppLoader& loader, bool updatable = true) { QString out; - for (const auto& kv : patch_manager.GetPatchVersionNames()) { + FileSys::VirtualFile update_raw; + loader.ReadUpdateRaw(update_raw); + for (const auto& kv : patch_manager.GetPatchVersionNames(update_raw)) { if (!updatable && kv.first == "Update") continue; @@ -116,7 +119,7 @@ void GameListWorker::AddInstalledTitlesToGameList() { QString::fromStdString(Loader::GetFileTypeString(loader->GetFileType())), program_id), new GameListItemCompat(compatibility), - new GameListItem(FormatPatchNameVersions(patch)), + new GameListItem(FormatPatchNameVersions(patch, *loader)), new GameListItem( QString::fromStdString(Loader::GetFileTypeString(loader->GetFileType()))), new GameListItemSize(file->GetSize()), @@ -206,7 +209,8 @@ void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, unsign QString::fromStdString(Loader::GetFileTypeString(loader->GetFileType())), program_id), new GameListItemCompat(compatibility), - new GameListItem(FormatPatchNameVersions(patch, loader->IsRomFSUpdatable())), + new GameListItem( + FormatPatchNameVersions(patch, *loader, loader->IsRomFSUpdatable())), new GameListItem( QString::fromStdString(Loader::GetFileTypeString(loader->GetFileType()))), new GameListItemSize(FileUtil::GetSize(physical_name)), From 5acaeb04c4f4ebdffda37717347f6a0c82a71aa4 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Tue, 25 Sep 2018 14:07:13 -0400 Subject: [PATCH 5/6] patch_manager: Add support for NSP packed updates Reads as Update (NSP) in add-ons --- src/core/file_sys/patch_manager.cpp | 4 ++-- src/yuzu/game_list_worker.cpp | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index b43880e928..3fc44fb5c5 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp @@ -209,7 +209,7 @@ VirtualFile PatchManager::PatchRomFS(VirtualFile romfs, u64 ivfc_offset, Content const auto new_nca = std::make_shared(update, romfs, ivfc_offset); if (new_nca->GetStatus() == Loader::ResultStatus::Success && new_nca->GetRomFS() != nullptr) { - LOG_INFO(Loader, " RomFS: Update (XCI) applied successfully"); + LOG_INFO(Loader, " RomFS: Update (PACKED) applied successfully"); romfs = new_nca->GetRomFS(); } } @@ -253,7 +253,7 @@ std::map PatchManager::GetPatchVersionNames(VirtualFile FormatTitleVersion(meta_ver.get(), TitleVersionFormat::ThreeElements)); } } else if (update_raw != nullptr) { - out[PatchType::Update] = "XCI"; + out[PatchType::Update] = "PACKED"; } } diff --git a/src/yuzu/game_list_worker.cpp b/src/yuzu/game_list_worker.cpp index 2bcc54b2fc..af5b20b90d 100644 --- a/src/yuzu/game_list_worker.cpp +++ b/src/yuzu/game_list_worker.cpp @@ -69,7 +69,14 @@ QString FormatPatchNameVersions(const FileSys::PatchManager& patch_manager, if (kv.second.empty()) { out.append(fmt::format("{}\n", kv.first).c_str()); } else { - out.append(fmt::format("{} ({})\n", kv.first, kv.second).c_str()); + auto ver = kv.second; + + // Display container name for packed updates + if (ver == "PACKED" && kv.first == FileSys::PatchType::Update) + ver = Loader::GetFileTypeString(loader.GetFileType()); + + out.append( + fmt::format("{} ({})\n", FileSys::FormatPatchTypeName(kv.first), ver).c_str()); } } From 38c2ac95af814e21e65e2785b276c4f64bfead71 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Fri, 5 Oct 2018 08:53:45 -0400 Subject: [PATCH 6/6] romfs_factory: Extract packed update setter to new function --- src/core/file_sys/patch_manager.cpp | 7 ++++--- src/core/file_sys/patch_manager.h | 3 ++- src/core/file_sys/romfs_factory.cpp | 5 ++++- src/core/file_sys/romfs_factory.h | 1 + src/core/file_sys/submission_package.cpp | 5 ++++- src/core/hle/service/filesystem/filesystem.cpp | 9 +++++++++ src/core/hle/service/filesystem/filesystem.h | 1 + src/core/loader/nsp.cpp | 6 ++++++ src/core/loader/xci.cpp | 5 +++++ src/yuzu/game_list_worker.cpp | 5 ++--- 10 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index 3fc44fb5c5..1ac00ebb08 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp @@ -206,7 +206,7 @@ VirtualFile PatchManager::PatchRomFS(VirtualFile romfs, u64 ivfc_offset, Content romfs = new_nca->GetRomFS(); } } else if (update_raw != nullptr) { - const auto new_nca = std::make_shared(update, romfs, ivfc_offset); + const auto new_nca = std::make_shared(update_raw, romfs, ivfc_offset); if (new_nca->GetStatus() == Loader::ResultStatus::Success && new_nca->GetRomFS() != nullptr) { LOG_INFO(Loader, " RomFS: Update (PACKED) applied successfully"); @@ -231,7 +231,8 @@ static bool IsDirValidAndNonEmpty(const VirtualDir& dir) { return dir != nullptr && (!dir->GetFiles().empty() || !dir->GetSubdirectories().empty()); } -std::map PatchManager::GetPatchVersionNames(VirtualFile update_raw) const { +std::map> PatchManager::GetPatchVersionNames( + VirtualFile update_raw) const { std::map> out; const auto installed = Service::FileSystem::GetUnionContents(); @@ -253,7 +254,7 @@ std::map PatchManager::GetPatchVersionNames(VirtualFile FormatTitleVersion(meta_ver.get(), TitleVersionFormat::ThreeElements)); } } else if (update_raw != nullptr) { - out[PatchType::Update] = "PACKED"; + out.insert_or_assign("Update", "PACKED"); } } diff --git a/src/core/file_sys/patch_manager.h b/src/core/file_sys/patch_manager.h index e87ce54e58..2ae9322a1d 100644 --- a/src/core/file_sys/patch_manager.h +++ b/src/core/file_sys/patch_manager.h @@ -51,7 +51,8 @@ public: // Returns a vector of pairs between patch names and patch versions. // i.e. Update 3.2.2 will return {"Update", "3.2.2"} - std::map> GetPatchVersionNames() const; + std::map> GetPatchVersionNames( + VirtualFile update_raw = nullptr) const; // Given title_id of the program, attempts to get the control data of the update and parse it, // falling back to the base control data. diff --git a/src/core/file_sys/romfs_factory.cpp b/src/core/file_sys/romfs_factory.cpp index a0ee16895a..0b645b106b 100644 --- a/src/core/file_sys/romfs_factory.cpp +++ b/src/core/file_sys/romfs_factory.cpp @@ -24,13 +24,16 @@ RomFSFactory::RomFSFactory(Loader::AppLoader& app_loader) { LOG_ERROR(Service_FS, "Unable to read RomFS!"); } - app_loader.ReadUpdateRaw(update_raw); updatable = app_loader.IsRomFSUpdatable(); ivfc_offset = app_loader.ReadRomFSIVFCOffset(); } RomFSFactory::~RomFSFactory() = default; +void RomFSFactory::SetPackedUpdate(VirtualFile update_raw) { + this->update_raw = std::move(update_raw); +} + ResultVal RomFSFactory::OpenCurrentProcess() { if (!updatable) return MakeResult(file); diff --git a/src/core/file_sys/romfs_factory.h b/src/core/file_sys/romfs_factory.h index 1cd4cedf11..7724c0b234 100644 --- a/src/core/file_sys/romfs_factory.h +++ b/src/core/file_sys/romfs_factory.h @@ -32,6 +32,7 @@ public: explicit RomFSFactory(Loader::AppLoader& app_loader); ~RomFSFactory(); + void SetPackedUpdate(VirtualFile update_raw); ResultVal OpenCurrentProcess(); ResultVal Open(u64 title_id, StorageId storage, ContentRecordType type); diff --git a/src/core/file_sys/submission_package.cpp b/src/core/file_sys/submission_package.cpp index 09bf077cda..ab5dc900c7 100644 --- a/src/core/file_sys/submission_package.cpp +++ b/src/core/file_sys/submission_package.cpp @@ -259,8 +259,11 @@ void NSP::ReadNCAs(const std::vector& files) { auto next_nca = std::make_shared(next_file); if (next_nca->GetType() == NCAContentType::Program) program_status[cnmt.GetTitleID()] = next_nca->GetStatus(); - if (next_nca->GetStatus() == Loader::ResultStatus::Success) + if (next_nca->GetStatus() == Loader::ResultStatus::Success || + (next_nca->GetStatus() == Loader::ResultStatus::ErrorMissingBKTRBaseRomFS && + (cnmt.GetTitleID() & 0x800) != 0)) { ncas_title[rec.type] = std::move(next_nca); + } } break; diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index aed2abb717..439e62d27c 100644 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp @@ -264,6 +264,15 @@ ResultCode RegisterBIS(std::unique_ptr&& factory) { return RESULT_SUCCESS; } +void SetPackedUpdate(FileSys::VirtualFile update_raw) { + LOG_TRACE(Service_FS, "Setting packed update for romfs"); + + if (romfs_factory == nullptr) + return; + + romfs_factory->SetPackedUpdate(std::move(update_raw)); +} + ResultVal OpenRomFSCurrentProcess() { LOG_TRACE(Service_FS, "Opening RomFS for current process"); diff --git a/src/core/hle/service/filesystem/filesystem.h b/src/core/hle/service/filesystem/filesystem.h index 7039a22471..53b01bb01e 100644 --- a/src/core/hle/service/filesystem/filesystem.h +++ b/src/core/hle/service/filesystem/filesystem.h @@ -39,6 +39,7 @@ ResultCode RegisterSaveData(std::unique_ptr&& factory) ResultCode RegisterSDMC(std::unique_ptr&& factory); ResultCode RegisterBIS(std::unique_ptr&& factory); +void SetPackedUpdate(FileSys::VirtualFile update_raw); ResultVal OpenRomFSCurrentProcess(); ResultVal OpenRomFS(u64 title_id, FileSys::StorageId storage_id, FileSys::ContentRecordType type); diff --git a/src/core/loader/nsp.cpp b/src/core/loader/nsp.cpp index a630b618cc..5534ce01c4 100644 --- a/src/core/loader/nsp.cpp +++ b/src/core/loader/nsp.cpp @@ -10,8 +10,10 @@ #include "core/file_sys/control_metadata.h" #include "core/file_sys/nca_metadata.h" #include "core/file_sys/patch_manager.h" +#include "core/file_sys/registered_cache.h" #include "core/file_sys/submission_package.h" #include "core/hle/kernel/process.h" +#include "core/hle/service/filesystem/filesystem.h" #include "core/loader/deconstructed_rom_directory.h" #include "core/loader/nca.h" #include "core/loader/nsp.h" @@ -91,6 +93,10 @@ ResultStatus AppLoader_NSP::Load(Kernel::Process& process) { if (result != ResultStatus::Success) return result; + FileSys::VirtualFile update_raw; + if (ReadUpdateRaw(update_raw) == ResultStatus::Success && update_raw != nullptr) + Service::FileSystem::SetPackedUpdate(std::move(update_raw)); + is_loaded = true; return ResultStatus::Success; diff --git a/src/core/loader/xci.cpp b/src/core/loader/xci.cpp index 9d91ef03a7..ee5452eb97 100644 --- a/src/core/loader/xci.cpp +++ b/src/core/loader/xci.cpp @@ -13,6 +13,7 @@ #include "core/file_sys/romfs.h" #include "core/file_sys/submission_package.h" #include "core/hle/kernel/process.h" +#include "core/hle/service/filesystem/filesystem.h" #include "core/loader/nca.h" #include "core/loader/xci.h" @@ -66,6 +67,10 @@ ResultStatus AppLoader_XCI::Load(Kernel::Process& process) { if (result != ResultStatus::Success) return result; + FileSys::VirtualFile update_raw; + if (ReadUpdateRaw(update_raw) == ResultStatus::Success && update_raw != nullptr) + Service::FileSystem::SetPackedUpdate(std::move(update_raw)); + is_loaded = true; return ResultStatus::Success; diff --git a/src/yuzu/game_list_worker.cpp b/src/yuzu/game_list_worker.cpp index af5b20b90d..d2b3de6835 100644 --- a/src/yuzu/game_list_worker.cpp +++ b/src/yuzu/game_list_worker.cpp @@ -72,11 +72,10 @@ QString FormatPatchNameVersions(const FileSys::PatchManager& patch_manager, auto ver = kv.second; // Display container name for packed updates - if (ver == "PACKED" && kv.first == FileSys::PatchType::Update) + if (ver == "PACKED" && kv.first == "Update") ver = Loader::GetFileTypeString(loader.GetFileType()); - out.append( - fmt::format("{} ({})\n", FileSys::FormatPatchTypeName(kv.first), ver).c_str()); + out.append(fmt::format("{} ({})\n", kv.first, ver).c_str()); } }