diff options
| author | 2020-12-15 11:07:03 -0800 | |
|---|---|---|
| committer | 2020-12-15 11:07:03 -0800 | |
| commit | 2e1b998d5ed676f7d637916a40118450cf0599a1 (patch) | |
| tree | 77e254b90270dcf28052d79bd6fdddfa9c77783c /src/core/file_sys | |
| parent | Merge pull request #5157 from lioncash/array-dirty (diff) | |
| parent | fsp_srv: Implement OpenDataStorageWithProgramIndex (diff) | |
| download | yuzu-2e1b998d5ed676f7d637916a40118450cf0599a1.tar.gz yuzu-2e1b998d5ed676f7d637916a40118450cf0599a1.tar.xz yuzu-2e1b998d5ed676f7d637916a40118450cf0599a1.zip | |
Merge pull request #5119 from Morph1984/fs-opendatastoragewithprogramindex
fsp_srv: Implement OpenDataStorageWithProgramIndex
Diffstat (limited to 'src/core/file_sys')
| -rw-r--r-- | src/core/file_sys/common_funcs.h | 56 | ||||
| -rw-r--r-- | src/core/file_sys/patch_manager.cpp | 4 | ||||
| -rw-r--r-- | src/core/file_sys/romfs_factory.cpp | 22 | ||||
| -rw-r--r-- | src/core/file_sys/romfs_factory.h | 4 |
4 files changed, 84 insertions, 2 deletions
diff --git a/src/core/file_sys/common_funcs.h b/src/core/file_sys/common_funcs.h new file mode 100644 index 000000000..7ed97aa50 --- /dev/null +++ b/src/core/file_sys/common_funcs.h | |||
| @@ -0,0 +1,56 @@ | |||
| 1 | // Copyright 2020 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "common/common_types.h" | ||
| 8 | |||
| 9 | namespace FileSys { | ||
| 10 | |||
| 11 | constexpr u64 AOC_TITLE_ID_MASK = 0x7FF; | ||
| 12 | constexpr u64 AOC_TITLE_ID_OFFSET = 0x1000; | ||
| 13 | constexpr u64 BASE_TITLE_ID_MASK = 0xFFFFFFFFFFFFE000; | ||
| 14 | |||
| 15 | /** | ||
| 16 | * Gets the base title ID from a given title ID. | ||
| 17 | * | ||
| 18 | * @param title_id The title ID. | ||
| 19 | * @returns The base title ID. | ||
| 20 | */ | ||
| 21 | [[nodiscard]] constexpr u64 GetBaseTitleID(u64 title_id) { | ||
| 22 | return title_id & BASE_TITLE_ID_MASK; | ||
| 23 | } | ||
| 24 | |||
| 25 | /** | ||
| 26 | * Gets the base title ID with a program index offset from a given title ID. | ||
| 27 | * | ||
| 28 | * @param title_id The title ID. | ||
| 29 | * @param program_index The program index. | ||
| 30 | * @returns The base title ID with a program index offset. | ||
| 31 | */ | ||
| 32 | [[nodiscard]] constexpr u64 GetBaseTitleIDWithProgramIndex(u64 title_id, u64 program_index) { | ||
| 33 | return GetBaseTitleID(title_id) + program_index; | ||
| 34 | } | ||
| 35 | |||
| 36 | /** | ||
| 37 | * Gets the AOC (Add-On Content) base title ID from a given title ID. | ||
| 38 | * | ||
| 39 | * @param title_id The title ID. | ||
| 40 | * @returns The AOC base title ID. | ||
| 41 | */ | ||
| 42 | [[nodiscard]] constexpr u64 GetAOCBaseTitleID(u64 title_id) { | ||
| 43 | return GetBaseTitleID(title_id) + AOC_TITLE_ID_OFFSET; | ||
| 44 | } | ||
| 45 | |||
| 46 | /** | ||
| 47 | * Gets the AOC (Add-On Content) ID from a given AOC title ID. | ||
| 48 | * | ||
| 49 | * @param aoc_title_id The AOC title ID. | ||
| 50 | * @returns The AOC ID. | ||
| 51 | */ | ||
| 52 | [[nodiscard]] constexpr u64 GetAOCID(u64 aoc_title_id) { | ||
| 53 | return aoc_title_id & AOC_TITLE_ID_MASK; | ||
| 54 | } | ||
| 55 | |||
| 56 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index e9d1607d0..7c3284df8 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp | |||
| @@ -12,6 +12,7 @@ | |||
| 12 | #include "common/logging/log.h" | 12 | #include "common/logging/log.h" |
| 13 | #include "common/string_util.h" | 13 | #include "common/string_util.h" |
| 14 | #include "core/core.h" | 14 | #include "core/core.h" |
| 15 | #include "core/file_sys/common_funcs.h" | ||
| 15 | #include "core/file_sys/content_archive.h" | 16 | #include "core/file_sys/content_archive.h" |
| 16 | #include "core/file_sys/control_metadata.h" | 17 | #include "core/file_sys/control_metadata.h" |
| 17 | #include "core/file_sys/ips_layer.h" | 18 | #include "core/file_sys/ips_layer.h" |
| @@ -30,7 +31,6 @@ namespace FileSys { | |||
| 30 | namespace { | 31 | namespace { |
| 31 | 32 | ||
| 32 | constexpr u32 SINGLE_BYTE_MODULUS = 0x100; | 33 | constexpr u32 SINGLE_BYTE_MODULUS = 0x100; |
| 33 | constexpr u64 DLC_BASE_TITLE_ID_MASK = 0xFFFFFFFFFFFFE000; | ||
| 34 | 34 | ||
| 35 | constexpr std::array<const char*, 14> EXEFS_FILE_NAMES{ | 35 | constexpr std::array<const char*, 14> EXEFS_FILE_NAMES{ |
| 36 | "main", "main.npdm", "rtld", "sdk", "subsdk0", "subsdk1", "subsdk2", | 36 | "main", "main.npdm", "rtld", "sdk", "subsdk0", "subsdk1", "subsdk2", |
| @@ -532,7 +532,7 @@ PatchManager::PatchVersionNames PatchManager::GetPatchVersionNames(VirtualFile u | |||
| 532 | dlc_match.reserve(dlc_entries.size()); | 532 | dlc_match.reserve(dlc_entries.size()); |
| 533 | std::copy_if(dlc_entries.begin(), dlc_entries.end(), std::back_inserter(dlc_match), | 533 | std::copy_if(dlc_entries.begin(), dlc_entries.end(), std::back_inserter(dlc_match), |
| 534 | [this](const ContentProviderEntry& entry) { | 534 | [this](const ContentProviderEntry& entry) { |
| 535 | return (entry.title_id & DLC_BASE_TITLE_ID_MASK) == title_id && | 535 | return GetBaseTitleID(entry.title_id) == title_id && |
| 536 | content_provider.GetEntry(entry)->GetStatus() == | 536 | content_provider.GetEntry(entry)->GetStatus() == |
| 537 | Loader::ResultStatus::Success; | 537 | Loader::ResultStatus::Success; |
| 538 | }); | 538 | }); |
diff --git a/src/core/file_sys/romfs_factory.cpp b/src/core/file_sys/romfs_factory.cpp index 987199747..f4e16e4be 100644 --- a/src/core/file_sys/romfs_factory.cpp +++ b/src/core/file_sys/romfs_factory.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 8 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 9 | #include "core/file_sys/card_image.h" | 9 | #include "core/file_sys/card_image.h" |
| 10 | #include "core/file_sys/common_funcs.h" | ||
| 10 | #include "core/file_sys/content_archive.h" | 11 | #include "core/file_sys/content_archive.h" |
| 11 | #include "core/file_sys/nca_metadata.h" | 12 | #include "core/file_sys/nca_metadata.h" |
| 12 | #include "core/file_sys/patch_manager.h" | 13 | #include "core/file_sys/patch_manager.h" |
| @@ -47,6 +48,27 @@ ResultVal<VirtualFile> RomFSFactory::OpenCurrentProcess(u64 current_process_titl | |||
| 47 | patch_manager.PatchRomFS(file, ivfc_offset, ContentRecordType::Program, update_raw)); | 48 | patch_manager.PatchRomFS(file, ivfc_offset, ContentRecordType::Program, update_raw)); |
| 48 | } | 49 | } |
| 49 | 50 | ||
| 51 | ResultVal<VirtualFile> RomFSFactory::OpenPatchedRomFS(u64 title_id, ContentRecordType type) const { | ||
| 52 | auto nca = content_provider.GetEntry(title_id, type); | ||
| 53 | |||
| 54 | if (nca == nullptr) { | ||
| 55 | // TODO: Find the right error code to use here | ||
| 56 | return RESULT_UNKNOWN; | ||
| 57 | } | ||
| 58 | |||
| 59 | const PatchManager patch_manager{title_id, filesystem_controller, content_provider}; | ||
| 60 | |||
| 61 | return MakeResult<VirtualFile>( | ||
| 62 | patch_manager.PatchRomFS(nca->GetRomFS(), nca->GetBaseIVFCOffset(), type)); | ||
| 63 | } | ||
| 64 | |||
| 65 | ResultVal<VirtualFile> RomFSFactory::OpenPatchedRomFSWithProgramIndex( | ||
| 66 | u64 title_id, u8 program_index, ContentRecordType type) const { | ||
| 67 | const auto res_title_id = GetBaseTitleIDWithProgramIndex(title_id, program_index); | ||
| 68 | |||
| 69 | return OpenPatchedRomFS(res_title_id, type); | ||
| 70 | } | ||
| 71 | |||
| 50 | ResultVal<VirtualFile> RomFSFactory::Open(u64 title_id, StorageId storage, | 72 | ResultVal<VirtualFile> RomFSFactory::Open(u64 title_id, StorageId storage, |
| 51 | ContentRecordType type) const { | 73 | ContentRecordType type) const { |
| 52 | const std::shared_ptr<NCA> res = GetEntry(title_id, storage, type); | 74 | const std::shared_ptr<NCA> res = GetEntry(title_id, storage, type); |
diff --git a/src/core/file_sys/romfs_factory.h b/src/core/file_sys/romfs_factory.h index ec704dfa8..96dd0d578 100644 --- a/src/core/file_sys/romfs_factory.h +++ b/src/core/file_sys/romfs_factory.h | |||
| @@ -42,6 +42,10 @@ public: | |||
| 42 | 42 | ||
| 43 | void SetPackedUpdate(VirtualFile update_raw); | 43 | void SetPackedUpdate(VirtualFile update_raw); |
| 44 | [[nodiscard]] ResultVal<VirtualFile> OpenCurrentProcess(u64 current_process_title_id) const; | 44 | [[nodiscard]] ResultVal<VirtualFile> OpenCurrentProcess(u64 current_process_title_id) const; |
| 45 | [[nodiscard]] ResultVal<VirtualFile> OpenPatchedRomFS(u64 title_id, | ||
| 46 | ContentRecordType type) const; | ||
| 47 | [[nodiscard]] ResultVal<VirtualFile> OpenPatchedRomFSWithProgramIndex( | ||
| 48 | u64 title_id, u8 program_index, ContentRecordType type) const; | ||
| 45 | [[nodiscard]] ResultVal<VirtualFile> Open(u64 title_id, StorageId storage, | 49 | [[nodiscard]] ResultVal<VirtualFile> Open(u64 title_id, StorageId storage, |
| 46 | ContentRecordType type) const; | 50 | ContentRecordType type) const; |
| 47 | 51 | ||