diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/file_sys/patch_manager.cpp | 30 | ||||
| -rw-r--r-- | src/core/file_sys/patch_manager.h | 1 | ||||
| -rw-r--r-- | src/core/file_sys/romfs_factory.cpp | 51 | ||||
| -rw-r--r-- | src/core/hle/service/aoc/aoc_u.cpp | 93 | ||||
| -rw-r--r-- | src/core/hle/service/aoc/aoc_u.h | 4 |
5 files changed, 145 insertions, 34 deletions
diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index 4b3b5e665..57b7741f8 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 5 | #include <array> | 6 | #include <array> |
| 6 | #include <cstddef> | 7 | #include <cstddef> |
| 7 | 8 | ||
| @@ -18,6 +19,7 @@ | |||
| 18 | namespace FileSys { | 19 | namespace FileSys { |
| 19 | 20 | ||
| 20 | constexpr u64 SINGLE_BYTE_MODULUS = 0x100; | 21 | constexpr u64 SINGLE_BYTE_MODULUS = 0x100; |
| 22 | constexpr u64 DLC_BASE_TITLE_ID_MASK = 0xFFFFFFFFFFFFE000; | ||
| 21 | 23 | ||
| 22 | std::string FormatTitleVersion(u32 version, TitleVersionFormat format) { | 24 | std::string FormatTitleVersion(u32 version, TitleVersionFormat format) { |
| 23 | std::array<u8, sizeof(u32)> bytes{}; | 25 | std::array<u8, sizeof(u32)> bytes{}; |
| @@ -32,9 +34,10 @@ std::string FormatTitleVersion(u32 version, TitleVersionFormat format) { | |||
| 32 | return fmt::format("v{}.{}.{}", bytes[3], bytes[2], bytes[1]); | 34 | return fmt::format("v{}.{}.{}", bytes[3], bytes[2], bytes[1]); |
| 33 | } | 35 | } |
| 34 | 36 | ||
| 35 | constexpr std::array<const char*, 2> PATCH_TYPE_NAMES{ | 37 | constexpr std::array<const char*, 3> PATCH_TYPE_NAMES{ |
| 36 | "Update", | 38 | "Update", |
| 37 | "LayeredFS", | 39 | "LayeredFS", |
| 40 | "DLC", | ||
| 38 | }; | 41 | }; |
| 39 | 42 | ||
| 40 | std::string FormatPatchTypeName(PatchType type) { | 43 | std::string FormatPatchTypeName(PatchType type) { |
| @@ -139,6 +142,7 @@ std::map<PatchType, std::string> PatchManager::GetPatchVersionNames() const { | |||
| 139 | std::map<PatchType, std::string> out; | 142 | std::map<PatchType, std::string> out; |
| 140 | const auto installed = Service::FileSystem::GetUnionContents(); | 143 | const auto installed = Service::FileSystem::GetUnionContents(); |
| 141 | 144 | ||
| 145 | // Game Updates | ||
| 142 | const auto update_tid = GetUpdateTitleID(title_id); | 146 | const auto update_tid = GetUpdateTitleID(title_id); |
| 143 | PatchManager update{update_tid}; | 147 | PatchManager update{update_tid}; |
| 144 | auto [nacp, discard_icon_file] = update.GetControlMetadata(); | 148 | auto [nacp, discard_icon_file] = update.GetControlMetadata(); |
| @@ -157,10 +161,34 @@ std::map<PatchType, std::string> PatchManager::GetPatchVersionNames() const { | |||
| 157 | } | 161 | } |
| 158 | } | 162 | } |
| 159 | 163 | ||
| 164 | // LayeredFS | ||
| 160 | const auto lfs_dir = Service::FileSystem::GetModificationLoadRoot(title_id); | 165 | const auto lfs_dir = Service::FileSystem::GetModificationLoadRoot(title_id); |
| 161 | if (lfs_dir != nullptr && lfs_dir->GetSize() > 0) | 166 | if (lfs_dir != nullptr && lfs_dir->GetSize() > 0) |
| 162 | out.insert_or_assign(PatchType::LayeredFS, ""); | 167 | out.insert_or_assign(PatchType::LayeredFS, ""); |
| 163 | 168 | ||
| 169 | // DLC | ||
| 170 | const auto dlc_entries = installed->ListEntriesFilter(TitleType::AOC, ContentRecordType::Data); | ||
| 171 | std::vector<RegisteredCacheEntry> dlc_match; | ||
| 172 | dlc_match.reserve(dlc_entries.size()); | ||
| 173 | std::copy_if(dlc_entries.begin(), dlc_entries.end(), std::back_inserter(dlc_match), | ||
| 174 | [this, &installed](const RegisteredCacheEntry& entry) { | ||
| 175 | return (entry.title_id & DLC_BASE_TITLE_ID_MASK) == title_id && | ||
| 176 | installed->GetEntry(entry)->GetStatus() == | ||
| 177 | Loader::ResultStatus::Success; | ||
| 178 | }); | ||
| 179 | if (!dlc_match.empty()) { | ||
| 180 | // Ensure sorted so DLC IDs show in order. | ||
| 181 | std::sort(dlc_match.begin(), dlc_match.end()); | ||
| 182 | |||
| 183 | std::string list; | ||
| 184 | for (size_t i = 0; i < dlc_match.size() - 1; ++i) | ||
| 185 | list += fmt::format("{}, ", dlc_match[i].title_id & 0x7FF); | ||
| 186 | |||
| 187 | list += fmt::format("{}", dlc_match.back().title_id & 0x7FF); | ||
| 188 | |||
| 189 | out.insert_or_assign(PatchType::DLC, std::move(list)); | ||
| 190 | } | ||
| 191 | |||
| 164 | return out; | 192 | return out; |
| 165 | } | 193 | } |
| 166 | 194 | ||
diff --git a/src/core/file_sys/patch_manager.h b/src/core/file_sys/patch_manager.h index 464f17515..3a2a9d212 100644 --- a/src/core/file_sys/patch_manager.h +++ b/src/core/file_sys/patch_manager.h | |||
| @@ -27,6 +27,7 @@ std::string FormatTitleVersion(u32 version, | |||
| 27 | enum class PatchType { | 27 | enum class PatchType { |
| 28 | Update, | 28 | Update, |
| 29 | LayeredFS, | 29 | LayeredFS, |
| 30 | DLC, | ||
| 30 | }; | 31 | }; |
| 31 | 32 | ||
| 32 | std::string FormatPatchTypeName(PatchType type); | 33 | std::string FormatPatchTypeName(PatchType type); |
diff --git a/src/core/file_sys/romfs_factory.cpp b/src/core/file_sys/romfs_factory.cpp index d027a8d59..4994c2532 100644 --- a/src/core/file_sys/romfs_factory.cpp +++ b/src/core/file_sys/romfs_factory.cpp | |||
| @@ -39,36 +39,35 @@ ResultVal<VirtualFile> RomFSFactory::OpenCurrentProcess() { | |||
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | ResultVal<VirtualFile> RomFSFactory::Open(u64 title_id, StorageId storage, ContentRecordType type) { | 41 | ResultVal<VirtualFile> RomFSFactory::Open(u64 title_id, StorageId storage, ContentRecordType type) { |
| 42 | std::shared_ptr<NCA> res; | ||
| 43 | |||
| 42 | switch (storage) { | 44 | switch (storage) { |
| 43 | case StorageId::NandSystem: { | 45 | case StorageId::None: |
| 44 | const auto res = Service::FileSystem::GetSystemNANDContents()->GetEntry(title_id, type); | 46 | res = Service::FileSystem::GetUnionContents()->GetEntry(title_id, type); |
| 45 | if (res == nullptr) { | 47 | break; |
| 46 | // TODO(DarkLordZach): Find the right error code to use here | 48 | case StorageId::NandSystem: |
| 47 | return ResultCode(-1); | 49 | res = Service::FileSystem::GetSystemNANDContents()->GetEntry(title_id, type); |
| 48 | } | 50 | break; |
| 49 | const auto romfs = res->GetRomFS(); | 51 | case StorageId::NandUser: |
| 50 | if (romfs == nullptr) { | 52 | res = Service::FileSystem::GetUserNANDContents()->GetEntry(title_id, type); |
| 51 | // TODO(DarkLordZach): Find the right error code to use here | 53 | break; |
| 52 | return ResultCode(-1); | 54 | case StorageId::SdCard: |
| 53 | } | 55 | res = Service::FileSystem::GetSDMCContents()->GetEntry(title_id, type); |
| 54 | return MakeResult<VirtualFile>(romfs); | 56 | break; |
| 55 | } | ||
| 56 | case StorageId::NandUser: { | ||
| 57 | const auto res = Service::FileSystem::GetUserNANDContents()->GetEntry(title_id, type); | ||
| 58 | if (res == nullptr) { | ||
| 59 | // TODO(DarkLordZach): Find the right error code to use here | ||
| 60 | return ResultCode(-1); | ||
| 61 | } | ||
| 62 | const auto romfs = res->GetRomFS(); | ||
| 63 | if (romfs == nullptr) { | ||
| 64 | // TODO(DarkLordZach): Find the right error code to use here | ||
| 65 | return ResultCode(-1); | ||
| 66 | } | ||
| 67 | return MakeResult<VirtualFile>(romfs); | ||
| 68 | } | ||
| 69 | default: | 57 | default: |
| 70 | UNIMPLEMENTED_MSG("Unimplemented storage_id={:02X}", static_cast<u8>(storage)); | 58 | UNIMPLEMENTED_MSG("Unimplemented storage_id={:02X}", static_cast<u8>(storage)); |
| 71 | } | 59 | } |
| 60 | |||
| 61 | if (res == nullptr) { | ||
| 62 | // TODO(DarkLordZach): Find the right error code to use here | ||
| 63 | return ResultCode(-1); | ||
| 64 | } | ||
| 65 | const auto romfs = res->GetRomFS(); | ||
| 66 | if (romfs == nullptr) { | ||
| 67 | // TODO(DarkLordZach): Find the right error code to use here | ||
| 68 | return ResultCode(-1); | ||
| 69 | } | ||
| 70 | return MakeResult<VirtualFile>(romfs); | ||
| 72 | } | 71 | } |
| 73 | 72 | ||
| 74 | } // namespace FileSys | 73 | } // namespace FileSys |
diff --git a/src/core/hle/service/aoc/aoc_u.cpp b/src/core/hle/service/aoc/aoc_u.cpp index d9eeac9ec..cfc28fa0c 100644 --- a/src/core/hle/service/aoc/aoc_u.cpp +++ b/src/core/hle/service/aoc/aoc_u.cpp | |||
| @@ -2,22 +2,57 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 6 | #include <numeric> | ||
| 7 | #include <vector> | ||
| 5 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 9 | #include "core/file_sys/content_archive.h" | ||
| 10 | #include "core/file_sys/nca_metadata.h" | ||
| 11 | #include "core/file_sys/partition_filesystem.h" | ||
| 12 | #include "core/file_sys/registered_cache.h" | ||
| 6 | #include "core/hle/ipc_helpers.h" | 13 | #include "core/hle/ipc_helpers.h" |
| 14 | #include "core/hle/kernel/process.h" | ||
| 7 | #include "core/hle/service/aoc/aoc_u.h" | 15 | #include "core/hle/service/aoc/aoc_u.h" |
| 16 | #include "core/hle/service/filesystem/filesystem.h" | ||
| 17 | #include "core/loader/loader.h" | ||
| 8 | 18 | ||
| 9 | namespace Service::AOC { | 19 | namespace Service::AOC { |
| 10 | 20 | ||
| 11 | AOC_U::AOC_U() : ServiceFramework("aoc:u") { | 21 | constexpr u64 DLC_BASE_TITLE_ID_MASK = 0xFFFFFFFFFFFFE000; |
| 22 | constexpr u64 DLC_BASE_TO_AOC_ID_MASK = 0x1000; | ||
| 23 | |||
| 24 | static bool CheckAOCTitleIDMatchesBase(u64 base, u64 aoc) { | ||
| 25 | return (aoc & DLC_BASE_TITLE_ID_MASK) == base; | ||
| 26 | } | ||
| 27 | |||
| 28 | static std::vector<u64> AccumulateAOCTitleIDs() { | ||
| 29 | std::vector<u64> add_on_content; | ||
| 30 | const auto rcu = FileSystem::GetUnionContents(); | ||
| 31 | const auto list = | ||
| 32 | rcu->ListEntriesFilter(FileSys::TitleType::AOC, FileSys::ContentRecordType::Data); | ||
| 33 | std::transform(list.begin(), list.end(), std::back_inserter(add_on_content), | ||
| 34 | [](const FileSys::RegisteredCacheEntry& rce) { return rce.title_id; }); | ||
| 35 | add_on_content.erase( | ||
| 36 | std::remove_if( | ||
| 37 | add_on_content.begin(), add_on_content.end(), | ||
| 38 | [&rcu](u64 tid) { | ||
| 39 | return rcu->GetEntry(tid, FileSys::ContentRecordType::Data)->GetStatus() != | ||
| 40 | Loader::ResultStatus::Success; | ||
| 41 | }), | ||
| 42 | add_on_content.end()); | ||
| 43 | return add_on_content; | ||
| 44 | } | ||
| 45 | |||
| 46 | AOC_U::AOC_U() : ServiceFramework("aoc:u"), add_on_content(AccumulateAOCTitleIDs()) { | ||
| 12 | static const FunctionInfo functions[] = { | 47 | static const FunctionInfo functions[] = { |
| 13 | {0, nullptr, "CountAddOnContentByApplicationId"}, | 48 | {0, nullptr, "CountAddOnContentByApplicationId"}, |
| 14 | {1, nullptr, "ListAddOnContentByApplicationId"}, | 49 | {1, nullptr, "ListAddOnContentByApplicationId"}, |
| 15 | {2, &AOC_U::CountAddOnContent, "CountAddOnContent"}, | 50 | {2, &AOC_U::CountAddOnContent, "CountAddOnContent"}, |
| 16 | {3, &AOC_U::ListAddOnContent, "ListAddOnContent"}, | 51 | {3, &AOC_U::ListAddOnContent, "ListAddOnContent"}, |
| 17 | {4, nullptr, "GetAddOnContentBaseIdByApplicationId"}, | 52 | {4, nullptr, "GetAddOnContentBaseIdByApplicationId"}, |
| 18 | {5, nullptr, "GetAddOnContentBaseId"}, | 53 | {5, &AOC_U::GetAddOnContentBaseId, "GetAddOnContentBaseId"}, |
| 19 | {6, nullptr, "PrepareAddOnContentByApplicationId"}, | 54 | {6, nullptr, "PrepareAddOnContentByApplicationId"}, |
| 20 | {7, nullptr, "PrepareAddOnContent"}, | 55 | {7, &AOC_U::PrepareAddOnContent, "PrepareAddOnContent"}, |
| 21 | {8, nullptr, "GetAddOnContentListChangedEvent"}, | 56 | {8, nullptr, "GetAddOnContentListChangedEvent"}, |
| 22 | }; | 57 | }; |
| 23 | RegisterHandlers(functions); | 58 | RegisterHandlers(functions); |
| @@ -28,15 +63,59 @@ AOC_U::~AOC_U() = default; | |||
| 28 | void AOC_U::CountAddOnContent(Kernel::HLERequestContext& ctx) { | 63 | void AOC_U::CountAddOnContent(Kernel::HLERequestContext& ctx) { |
| 29 | IPC::ResponseBuilder rb{ctx, 4}; | 64 | IPC::ResponseBuilder rb{ctx, 4}; |
| 30 | rb.Push(RESULT_SUCCESS); | 65 | rb.Push(RESULT_SUCCESS); |
| 31 | rb.Push<u64>(0); | 66 | |
| 32 | LOG_WARNING(Service_AOC, "(STUBBED) called"); | 67 | const auto current = Core::System::GetInstance().CurrentProcess()->GetTitleID(); |
| 68 | rb.Push<u32>(std::count_if(add_on_content.begin(), add_on_content.end(), [¤t](u64 tid) { | ||
| 69 | return (tid & DLC_BASE_TITLE_ID_MASK) == current; | ||
| 70 | })); | ||
| 33 | } | 71 | } |
| 34 | 72 | ||
| 35 | void AOC_U::ListAddOnContent(Kernel::HLERequestContext& ctx) { | 73 | void AOC_U::ListAddOnContent(Kernel::HLERequestContext& ctx) { |
| 74 | IPC::RequestParser rp{ctx}; | ||
| 75 | |||
| 76 | const auto offset = rp.PopRaw<u32>(); | ||
| 77 | auto count = rp.PopRaw<u32>(); | ||
| 78 | |||
| 79 | const auto current = Core::System::GetInstance().CurrentProcess()->GetTitleID(); | ||
| 80 | |||
| 81 | std::vector<u32> out; | ||
| 82 | for (size_t i = 0; i < add_on_content.size(); ++i) { | ||
| 83 | if ((add_on_content[i] & DLC_BASE_TITLE_ID_MASK) == current) | ||
| 84 | out.push_back(static_cast<u32>(add_on_content[i] & 0x7FF)); | ||
| 85 | } | ||
| 86 | |||
| 87 | if (out.size() <= offset) { | ||
| 88 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 89 | // TODO(DarkLordZach): Find the correct error code. | ||
| 90 | rb.Push(ResultCode(-1)); | ||
| 91 | return; | ||
| 92 | } | ||
| 93 | |||
| 94 | count = std::min<size_t>(out.size() - offset, count); | ||
| 95 | std::rotate(out.begin(), out.begin() + offset, out.end()); | ||
| 96 | out.resize(count); | ||
| 97 | |||
| 98 | ctx.WriteBuffer(out); | ||
| 99 | |||
| 100 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 101 | rb.Push(RESULT_SUCCESS); | ||
| 102 | } | ||
| 103 | |||
| 104 | void AOC_U::GetAddOnContentBaseId(Kernel::HLERequestContext& ctx) { | ||
| 36 | IPC::ResponseBuilder rb{ctx, 4}; | 105 | IPC::ResponseBuilder rb{ctx, 4}; |
| 37 | rb.Push(RESULT_SUCCESS); | 106 | rb.Push(RESULT_SUCCESS); |
| 38 | rb.Push<u64>(0); | 107 | rb.Push(Core::System::GetInstance().CurrentProcess()->GetTitleID() | DLC_BASE_TO_AOC_ID_MASK); |
| 39 | LOG_WARNING(Service_AOC, "(STUBBED) called"); | 108 | } |
| 109 | |||
| 110 | void AOC_U::PrepareAddOnContent(Kernel::HLERequestContext& ctx) { | ||
| 111 | IPC::RequestParser rp{ctx}; | ||
| 112 | |||
| 113 | const auto aoc_id = rp.PopRaw<u32>(); | ||
| 114 | |||
| 115 | LOG_WARNING(Service_AOC, "(STUBBED) called with aoc_id={:08X}", aoc_id); | ||
| 116 | |||
| 117 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 118 | rb.Push(RESULT_SUCCESS); | ||
| 40 | } | 119 | } |
| 41 | 120 | ||
| 42 | void InstallInterfaces(SM::ServiceManager& service_manager) { | 121 | void InstallInterfaces(SM::ServiceManager& service_manager) { |
diff --git a/src/core/hle/service/aoc/aoc_u.h b/src/core/hle/service/aoc/aoc_u.h index 29ce8f488..b3c7cab7a 100644 --- a/src/core/hle/service/aoc/aoc_u.h +++ b/src/core/hle/service/aoc/aoc_u.h | |||
| @@ -16,6 +16,10 @@ public: | |||
| 16 | private: | 16 | private: |
| 17 | void CountAddOnContent(Kernel::HLERequestContext& ctx); | 17 | void CountAddOnContent(Kernel::HLERequestContext& ctx); |
| 18 | void ListAddOnContent(Kernel::HLERequestContext& ctx); | 18 | void ListAddOnContent(Kernel::HLERequestContext& ctx); |
| 19 | void GetAddOnContentBaseId(Kernel::HLERequestContext& ctx); | ||
| 20 | void PrepareAddOnContent(Kernel::HLERequestContext& ctx); | ||
| 21 | |||
| 22 | std::vector<u64> add_on_content; | ||
| 19 | }; | 23 | }; |
| 20 | 24 | ||
| 21 | /// Registers all AOC services with the specified service manager. | 25 | /// Registers all AOC services with the specified service manager. |