diff options
| author | 2020-12-04 01:41:21 -0500 | |
|---|---|---|
| committer | 2020-12-08 08:19:05 -0500 | |
| commit | 0eb6c6cd836028a94260321e460871c228deee50 (patch) | |
| tree | 1f32afb694eae681c5d5936efe751f0f0d3cb972 | |
| parent | Merge pull request #5165 from lioncash/copy-controller (diff) | |
| download | yuzu-0eb6c6cd836028a94260321e460871c228deee50.tar.gz yuzu-0eb6c6cd836028a94260321e460871c228deee50.tar.xz yuzu-0eb6c6cd836028a94260321e460871c228deee50.zip | |
file_sys: Consolidate common Title ID operations
| -rw-r--r-- | src/core/CMakeLists.txt | 1 | ||||
| -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/hle/service/aoc/aoc_u.cpp | 12 | ||||
| -rw-r--r-- | src/yuzu/main.cpp | 7 |
5 files changed, 67 insertions, 13 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 66de33799..949748178 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -41,6 +41,7 @@ add_library(core STATIC | |||
| 41 | file_sys/bis_factory.h | 41 | file_sys/bis_factory.h |
| 42 | file_sys/card_image.cpp | 42 | file_sys/card_image.cpp |
| 43 | file_sys/card_image.h | 43 | file_sys/card_image.h |
| 44 | file_sys/common_funcs.h | ||
| 44 | file_sys/content_archive.cpp | 45 | file_sys/content_archive.cpp |
| 45 | file_sys/content_archive.h | 46 | file_sys/content_archive.h |
| 46 | file_sys/control_metadata.cpp | 47 | file_sys/control_metadata.cpp |
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/hle/service/aoc/aoc_u.cpp b/src/core/hle/service/aoc/aoc_u.cpp index 6abac3f78..17ba21496 100644 --- a/src/core/hle/service/aoc/aoc_u.cpp +++ b/src/core/hle/service/aoc/aoc_u.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <vector> | 7 | #include <vector> |
| 8 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 9 | #include "core/core.h" | 9 | #include "core/core.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/control_metadata.h" | 12 | #include "core/file_sys/control_metadata.h" |
| 12 | #include "core/file_sys/nca_metadata.h" | 13 | #include "core/file_sys/nca_metadata.h" |
| @@ -23,11 +24,8 @@ | |||
| 23 | 24 | ||
| 24 | namespace Service::AOC { | 25 | namespace Service::AOC { |
| 25 | 26 | ||
| 26 | constexpr u64 DLC_BASE_TITLE_ID_MASK = 0xFFFFFFFFFFFFE000; | ||
| 27 | constexpr u64 DLC_BASE_TO_AOC_ID = 0x1000; | ||
| 28 | |||
| 29 | static bool CheckAOCTitleIDMatchesBase(u64 title_id, u64 base) { | 27 | static bool CheckAOCTitleIDMatchesBase(u64 title_id, u64 base) { |
| 30 | return (title_id & DLC_BASE_TITLE_ID_MASK) == base; | 28 | return FileSys::GetBaseTitleID(title_id) == base; |
| 31 | } | 29 | } |
| 32 | 30 | ||
| 33 | static std::vector<u64> AccumulateAOCTitleIDs(Core::System& system) { | 31 | static std::vector<u64> AccumulateAOCTitleIDs(Core::System& system) { |
| @@ -123,11 +121,11 @@ void AOC_U::ListAddOnContent(Kernel::HLERequestContext& ctx) { | |||
| 123 | const auto& disabled = Settings::values.disabled_addons[current]; | 121 | const auto& disabled = Settings::values.disabled_addons[current]; |
| 124 | if (std::find(disabled.begin(), disabled.end(), "DLC") == disabled.end()) { | 122 | if (std::find(disabled.begin(), disabled.end(), "DLC") == disabled.end()) { |
| 125 | for (u64 content_id : add_on_content) { | 123 | for (u64 content_id : add_on_content) { |
| 126 | if ((content_id & DLC_BASE_TITLE_ID_MASK) != current) { | 124 | if (FileSys::GetBaseTitleID(content_id) != current) { |
| 127 | continue; | 125 | continue; |
| 128 | } | 126 | } |
| 129 | 127 | ||
| 130 | out.push_back(static_cast<u32>(content_id & 0x7FF)); | 128 | out.push_back(static_cast<u32>(FileSys::GetAOCID(content_id))); |
| 131 | } | 129 | } |
| 132 | } | 130 | } |
| 133 | 131 | ||
| @@ -169,7 +167,7 @@ void AOC_U::GetAddOnContentBaseId(Kernel::HLERequestContext& ctx) { | |||
| 169 | 167 | ||
| 170 | const auto res = pm.GetControlMetadata(); | 168 | const auto res = pm.GetControlMetadata(); |
| 171 | if (res.first == nullptr) { | 169 | if (res.first == nullptr) { |
| 172 | rb.Push(title_id + DLC_BASE_TO_AOC_ID); | 170 | rb.Push(FileSys::GetAOCBaseTitleID(title_id)); |
| 173 | return; | 171 | return; |
| 174 | } | 172 | } |
| 175 | 173 | ||
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 26f5e42ed..3461fa675 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -83,6 +83,7 @@ static FileSys::VirtualFile VfsDirectoryCreateFileWrapper(const FileSys::Virtual | |||
| 83 | #include "core/core.h" | 83 | #include "core/core.h" |
| 84 | #include "core/crypto/key_manager.h" | 84 | #include "core/crypto/key_manager.h" |
| 85 | #include "core/file_sys/card_image.h" | 85 | #include "core/file_sys/card_image.h" |
| 86 | #include "core/file_sys/common_funcs.h" | ||
| 86 | #include "core/file_sys/content_archive.h" | 87 | #include "core/file_sys/content_archive.h" |
| 87 | #include "core/file_sys/control_metadata.h" | 88 | #include "core/file_sys/control_metadata.h" |
| 88 | #include "core/file_sys/patch_manager.h" | 89 | #include "core/file_sys/patch_manager.h" |
| @@ -148,8 +149,6 @@ __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; | |||
| 148 | 149 | ||
| 149 | constexpr int default_mouse_timeout = 2500; | 150 | constexpr int default_mouse_timeout = 2500; |
| 150 | 151 | ||
| 151 | constexpr u64 DLC_BASE_TITLE_ID_MASK = 0xFFFFFFFFFFFFE000; | ||
| 152 | |||
| 153 | /** | 152 | /** |
| 154 | * "Callouts" are one-time instructional messages shown to the user. In the config settings, there | 153 | * "Callouts" are one-time instructional messages shown to the user. In the config settings, there |
| 155 | * is a bitfield "callout_flags" options, used to track if a message has already been shown to the | 154 | * is a bitfield "callout_flags" options, used to track if a message has already been shown to the |
| @@ -1529,7 +1528,7 @@ void GMainWindow::RemoveAddOnContent(u64 program_id, const QString& entry_type) | |||
| 1529 | FileSys::TitleType::AOC, FileSys::ContentRecordType::Data); | 1528 | FileSys::TitleType::AOC, FileSys::ContentRecordType::Data); |
| 1530 | 1529 | ||
| 1531 | for (const auto& entry : dlc_entries) { | 1530 | for (const auto& entry : dlc_entries) { |
| 1532 | if ((entry.title_id & DLC_BASE_TITLE_ID_MASK) == program_id) { | 1531 | if (FileSys::GetBaseTitleID(entry.title_id) == program_id) { |
| 1533 | const auto res = | 1532 | const auto res = |
| 1534 | fs_controller.GetUserNANDContents()->RemoveExistingEntry(entry.title_id) || | 1533 | fs_controller.GetUserNANDContents()->RemoveExistingEntry(entry.title_id) || |
| 1535 | fs_controller.GetSDMCContents()->RemoveExistingEntry(entry.title_id); | 1534 | fs_controller.GetSDMCContents()->RemoveExistingEntry(entry.title_id); |
| @@ -2709,7 +2708,7 @@ std::optional<u64> GMainWindow::SelectRomFSDumpTarget(const FileSys::ContentProv | |||
| 2709 | dlc_match.reserve(dlc_entries.size()); | 2708 | dlc_match.reserve(dlc_entries.size()); |
| 2710 | std::copy_if(dlc_entries.begin(), dlc_entries.end(), std::back_inserter(dlc_match), | 2709 | std::copy_if(dlc_entries.begin(), dlc_entries.end(), std::back_inserter(dlc_match), |
| 2711 | [&program_id, &installed](const FileSys::ContentProviderEntry& entry) { | 2710 | [&program_id, &installed](const FileSys::ContentProviderEntry& entry) { |
| 2712 | return (entry.title_id & DLC_BASE_TITLE_ID_MASK) == program_id && | 2711 | return FileSys::GetBaseTitleID(entry.title_id) == program_id && |
| 2713 | installed.GetEntry(entry)->GetStatus() == Loader::ResultStatus::Success; | 2712 | installed.GetEntry(entry)->GetStatus() == Loader::ResultStatus::Success; |
| 2714 | }); | 2713 | }); |
| 2715 | 2714 | ||