diff options
| -rw-r--r-- | src/core/hle/service/aoc/aoc_u.cpp | 78 | ||||
| -rw-r--r-- | src/core/hle/service/aoc/aoc_u.h | 3 |
2 files changed, 78 insertions, 3 deletions
diff --git a/src/core/hle/service/aoc/aoc_u.cpp b/src/core/hle/service/aoc/aoc_u.cpp index d9eeac9ec..f7597f9bb 100644 --- a/src/core/hle/service/aoc/aoc_u.cpp +++ b/src/core/hle/service/aoc/aoc_u.cpp | |||
| @@ -2,12 +2,27 @@ | |||
| 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 <numeric> | ||
| 5 | #include "common/logging/log.h" | 6 | #include "common/logging/log.h" |
| 7 | #include "core/file_sys/content_archive.h" | ||
| 8 | #include "core/file_sys/nca_metadata.h" | ||
| 9 | #include "core/file_sys/partition_filesystem.h" | ||
| 10 | #include "core/file_sys/registered_cache.h" | ||
| 6 | #include "core/hle/ipc_helpers.h" | 11 | #include "core/hle/ipc_helpers.h" |
| 12 | #include "core/hle/kernel/process.h" | ||
| 7 | #include "core/hle/service/aoc/aoc_u.h" | 13 | #include "core/hle/service/aoc/aoc_u.h" |
| 14 | #include "core/hle/service/filesystem/filesystem.h" | ||
| 15 | #include "core/loader/loader.h" | ||
| 8 | 16 | ||
| 9 | namespace Service::AOC { | 17 | namespace Service::AOC { |
| 10 | 18 | ||
| 19 | constexpr u64 DLC_BASE_TITLE_ID_MASK = 0xFFFFFFFFFFFFE000; | ||
| 20 | constexpr u64 DLC_BASE_TO_AOC_ID_MASK = 0x1000; | ||
| 21 | |||
| 22 | bool CheckAOCTitleIDMatchesBase(u64 base, u64 aoc) { | ||
| 23 | return (aoc & DLC_BASE_TITLE_ID_MASK) == base; | ||
| 24 | } | ||
| 25 | |||
| 11 | AOC_U::AOC_U() : ServiceFramework("aoc:u") { | 26 | AOC_U::AOC_U() : ServiceFramework("aoc:u") { |
| 12 | static const FunctionInfo functions[] = { | 27 | static const FunctionInfo functions[] = { |
| 13 | {0, nullptr, "CountAddOnContentByApplicationId"}, | 28 | {0, nullptr, "CountAddOnContentByApplicationId"}, |
| @@ -17,10 +32,25 @@ AOC_U::AOC_U() : ServiceFramework("aoc:u") { | |||
| 17 | {4, nullptr, "GetAddOnContentBaseIdByApplicationId"}, | 32 | {4, nullptr, "GetAddOnContentBaseIdByApplicationId"}, |
| 18 | {5, nullptr, "GetAddOnContentBaseId"}, | 33 | {5, nullptr, "GetAddOnContentBaseId"}, |
| 19 | {6, nullptr, "PrepareAddOnContentByApplicationId"}, | 34 | {6, nullptr, "PrepareAddOnContentByApplicationId"}, |
| 20 | {7, nullptr, "PrepareAddOnContent"}, | 35 | {7, &AOC_U::PrepareAddOnContent, "PrepareAddOnContent"}, |
| 21 | {8, nullptr, "GetAddOnContentListChangedEvent"}, | 36 | {8, nullptr, "GetAddOnContentListChangedEvent"}, |
| 22 | }; | 37 | }; |
| 23 | RegisterHandlers(functions); | 38 | RegisterHandlers(functions); |
| 39 | |||
| 40 | // Accumulate AOC title ids | ||
| 41 | const auto rcu = FileSystem::GetUnionContents(); | ||
| 42 | const auto list = | ||
| 43 | rcu->ListEntriesFilter(FileSys::TitleType::AOC, FileSys::ContentRecordType::Data); | ||
| 44 | std::transform(list.begin(), list.end(), std::back_inserter(add_on_content), | ||
| 45 | [](const FileSys::RegisteredCacheEntry& rce) { return rce.title_id; }); | ||
| 46 | add_on_content.erase( | ||
| 47 | std::remove_if( | ||
| 48 | add_on_content.begin(), add_on_content.end(), | ||
| 49 | [&rcu](u64 tid) { | ||
| 50 | return rcu->GetEntry(tid, FileSys::ContentRecordType::Data)->GetStatus() != | ||
| 51 | Loader::ResultStatus::Success; | ||
| 52 | }), | ||
| 53 | add_on_content.end()); | ||
| 24 | } | 54 | } |
| 25 | 55 | ||
| 26 | AOC_U::~AOC_U() = default; | 56 | AOC_U::~AOC_U() = default; |
| @@ -28,15 +58,57 @@ AOC_U::~AOC_U() = default; | |||
| 28 | void AOC_U::CountAddOnContent(Kernel::HLERequestContext& ctx) { | 58 | void AOC_U::CountAddOnContent(Kernel::HLERequestContext& ctx) { |
| 29 | IPC::ResponseBuilder rb{ctx, 4}; | 59 | IPC::ResponseBuilder rb{ctx, 4}; |
| 30 | rb.Push(RESULT_SUCCESS); | 60 | rb.Push(RESULT_SUCCESS); |
| 31 | rb.Push<u64>(0); | 61 | |
| 32 | LOG_WARNING(Service_AOC, "(STUBBED) called"); | 62 | const auto current = Core::System::GetInstance().CurrentProcess()->program_id; |
| 63 | rb.Push<u32>(std::count_if(add_on_content.begin(), add_on_content.end(), [¤t](u64 tid) { | ||
| 64 | return (tid & DLC_BASE_TITLE_ID_MASK) == current; | ||
| 65 | })); | ||
| 33 | } | 66 | } |
| 34 | 67 | ||
| 35 | void AOC_U::ListAddOnContent(Kernel::HLERequestContext& ctx) { | 68 | void AOC_U::ListAddOnContent(Kernel::HLERequestContext& ctx) { |
| 69 | IPC::RequestParser rp{ctx}; | ||
| 70 | |||
| 71 | const auto offset = rp.PopRaw<u32>(); | ||
| 72 | auto count = rp.PopRaw<u32>(); | ||
| 73 | |||
| 74 | const auto current = Core::System::GetInstance().CurrentProcess()->program_id; | ||
| 75 | |||
| 76 | std::vector<u32> out; | ||
| 77 | for (size_t i = 0; i < add_on_content.size(); ++i) { | ||
| 78 | if ((add_on_content[i] & DLC_BASE_TITLE_ID_MASK) == current) | ||
| 79 | out.push_back(static_cast<u32>(add_on_content[i] & 0x7FF)); | ||
| 80 | } | ||
| 81 | |||
| 82 | if (out.size() <= offset) { | ||
| 83 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 84 | // TODO(DarkLordZach): Find the correct error code. | ||
| 85 | rb.Push(ResultCode(-1)); | ||
| 86 | return; | ||
| 87 | } | ||
| 88 | |||
| 89 | count = std::min<size_t>(out.size() - offset, count); | ||
| 90 | out = std::vector<u32>(out.begin() + offset, out.begin() + offset + count); | ||
| 91 | |||
| 92 | ctx.WriteBuffer(out); | ||
| 93 | |||
| 94 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 95 | rb.Push(RESULT_SUCCESS); | ||
| 96 | } | ||
| 97 | |||
| 36 | IPC::ResponseBuilder rb{ctx, 4}; | 98 | IPC::ResponseBuilder rb{ctx, 4}; |
| 37 | rb.Push(RESULT_SUCCESS); | 99 | rb.Push(RESULT_SUCCESS); |
| 38 | rb.Push<u64>(0); | 100 | rb.Push<u64>(0); |
| 39 | LOG_WARNING(Service_AOC, "(STUBBED) called"); | 101 | LOG_WARNING(Service_AOC, "(STUBBED) called"); |
| 102 | |||
| 103 | void AOC_U::PrepareAddOnContent(Kernel::HLERequestContext& ctx) { | ||
| 104 | IPC::RequestParser rp{ctx}; | ||
| 105 | |||
| 106 | const auto aoc_id = rp.PopRaw<u32>(); | ||
| 107 | |||
| 108 | LOG_WARNING(Service_AOC, "(STUBBED) called with aoc_id={:08X}", aoc_id); | ||
| 109 | |||
| 110 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 111 | rb.Push(RESULT_SUCCESS); | ||
| 40 | } | 112 | } |
| 41 | 113 | ||
| 42 | void InstallInterfaces(SM::ServiceManager& service_manager) { | 114 | 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..61e2ec75d 100644 --- a/src/core/hle/service/aoc/aoc_u.h +++ b/src/core/hle/service/aoc/aoc_u.h | |||
| @@ -16,6 +16,9 @@ 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 PrepareAddOnContent(Kernel::HLERequestContext& ctx); | ||
| 20 | |||
| 21 | std::vector<u64> add_on_content; | ||
| 19 | }; | 22 | }; |
| 20 | 23 | ||
| 21 | /// Registers all AOC services with the specified service manager. | 24 | /// Registers all AOC services with the specified service manager. |