Skip to content

Commit 22e6509

Browse files
author
N3xoX1
committed
os: Add code back in for AccumulateAOCTitleIDs
1 parent 89b2ae3 commit 22e6509

6 files changed

Lines changed: 124 additions & 32 deletions

File tree

src/nxemu-loader/core/file_sys/registered_cache.cpp

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,23 @@
1818
#include "core/file_sys/vfs/vfs_concat.h"
1919
#include "core/loader/loader.h"
2020

21-
namespace FileSys {
22-
23-
// The size of blocks to use when vfs raw copying into nand.
24-
constexpr size_t VFS_RC_LARGE_COPY_BLOCK = 0x400000;
25-
26-
std::string ContentProviderEntry::DebugInfo() const {
27-
return fmt::format("title_id={:016X}, content_type={:02X}", title_id, static_cast<u8>(type));
28-
}
29-
3021
bool operator<(const ContentProviderEntry& lhs, const ContentProviderEntry& rhs) {
31-
return (lhs.title_id < rhs.title_id) || (lhs.title_id == rhs.title_id && lhs.type < rhs.type);
22+
return (lhs.titleID < rhs.titleID) || (lhs.titleID == rhs.titleID && lhs.type < rhs.type);
3223
}
3324

3425
bool operator==(const ContentProviderEntry& lhs, const ContentProviderEntry& rhs) {
35-
return std::tie(lhs.title_id, lhs.type) == std::tie(rhs.title_id, rhs.type);
26+
return std::tie(lhs.titleID, lhs.type) == std::tie(rhs.titleID, rhs.type);
3627
}
3728

3829
bool operator!=(const ContentProviderEntry& lhs, const ContentProviderEntry& rhs) {
3930
return !operator==(lhs, rhs);
4031
}
4132

33+
namespace FileSys {
34+
35+
// The size of blocks to use when vfs raw copying into nand.
36+
constexpr size_t VFS_RC_LARGE_COPY_BLOCK = 0x400000;
37+
4238
static bool FollowsTwoDigitDirFormat(std::string_view name) {
4339
static const std::regex two_digit_regex("000000[0-9A-F]{2}", std::regex_constants::ECMAScript |
4440
std::regex_constants::icase);
@@ -115,15 +111,19 @@ LoaderContentRecordType GetCRTypeFromNCAType(NCAContentType type) {
115111
ContentProvider::~ContentProvider() = default;
116112

117113
bool ContentProvider::HasEntry(ContentProviderEntry entry) const {
118-
return HasEntry(entry.title_id, entry.type);
114+
return HasEntry(entry.titleID, entry.type);
119115
}
120116

121117
VirtualFile ContentProvider::GetEntryUnparsed(ContentProviderEntry entry) const {
122-
return GetEntryUnparsed(entry.title_id, entry.type);
118+
return GetEntryUnparsed(entry.titleID, entry.type);
123119
}
124120

125121
VirtualFile ContentProvider::GetEntryRaw(ContentProviderEntry entry) const {
126-
return GetEntryRaw(entry.title_id, entry.type);
122+
return GetEntryRaw(entry.titleID, entry.type);
123+
}
124+
125+
std::unique_ptr<NCA> ContentProvider::GetEntryNCA(ContentProviderEntry entry) const {
126+
return GetEntryNCA(entry.titleID, entry.type);
127127
}
128128

129129
std::vector<ContentProviderEntry> ContentProvider::ListEntries() const {
@@ -491,10 +491,14 @@ VirtualFile RegisteredCache::GetEntryRaw(u64 title_id, LoaderContentRecordType t
491491
}
492492

493493
IFileSysNCA * RegisteredCache::GetEntry(u64 title_id, LoaderContentRecordType type) const {
494+
return GetEntryNCA(title_id, type).release();
495+
}
496+
497+
std::unique_ptr<NCA> RegisteredCache::GetEntryNCA(u64 title_id, LoaderContentRecordType type) const {
494498
const auto raw = GetEntryRaw(title_id, type);
495499
if (raw == nullptr)
496500
return nullptr;
497-
return std::make_unique<NCA>(raw).release();
501+
return std::make_unique<NCA>(raw);
498502
}
499503

500504
template <typename T>
@@ -812,6 +816,19 @@ VirtualFile ContentProviderUnion::GetEntryRaw(u64 title_id, LoaderContentRecordT
812816
return nullptr;
813817
}
814818

819+
std::unique_ptr<NCA> ContentProviderUnion::GetEntryNCA(u64 title_id, LoaderContentRecordType type) const {
820+
for (const auto& provider : providers) {
821+
if (provider.second == nullptr)
822+
continue;
823+
824+
auto res = provider.second->GetEntryNCA(title_id, type);
825+
if (res != nullptr)
826+
return res;
827+
}
828+
829+
return nullptr;
830+
}
831+
815832
std::vector<ContentProviderEntry> ContentProviderUnion::ListEntriesFilter(
816833
std::optional<LoaderTitleType> title_type, std::optional<LoaderContentRecordType> record_type,
817834
std::optional<u64> title_id) const {
@@ -907,6 +924,13 @@ VirtualFile ManualContentProvider::GetEntryRaw(u64 title_id, LoaderContentRecord
907924
return iter->second;
908925
}
909926

927+
std::unique_ptr<NCA> ManualContentProvider::GetEntryNCA(u64 title_id, LoaderContentRecordType type) const {
928+
const auto res = GetEntryRaw(title_id, type);
929+
if (res == nullptr)
930+
return nullptr;
931+
return std::make_unique<NCA>(res);
932+
}
933+
910934
std::vector<ContentProviderEntry> ManualContentProvider::ListEntriesFilter(
911935
std::optional<LoaderTitleType> title_type, std::optional<LoaderContentRecordType> record_type,
912936
std::optional<u64> title_id) const {

src/nxemu-loader/core/file_sys/registered_cache.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ enum class InstallResult {
4242
ErrorBaseInstall,
4343
};
4444

45-
struct ContentProviderEntry {
46-
u64 title_id;
47-
LoaderContentRecordType type;
48-
49-
std::string DebugInfo() const;
50-
};
51-
5245
constexpr u64 GetUpdateTitleID(u64 base_title_id) {
5346
return base_title_id | 0x800;
5447
}
@@ -79,6 +72,9 @@ class ContentProvider {
7972
virtual VirtualFile GetEntryRaw(u64 title_id, LoaderContentRecordType type) const = 0;
8073
VirtualFile GetEntryRaw(ContentProviderEntry entry) const;
8174

75+
virtual std::unique_ptr<NCA> GetEntryNCA(u64 title_id, LoaderContentRecordType type) const = 0;
76+
std::unique_ptr<NCA> GetEntryNCA(ContentProviderEntry entry) const;
77+
8278
virtual std::vector<ContentProviderEntry> ListEntries() const;
8379

8480
// If a parameter is not std::nullopt, it will be filtered for from all entries.
@@ -149,6 +145,7 @@ class RegisteredCache :
149145

150146
VirtualFile GetEntryRaw(u64 title_id, LoaderContentRecordType type) const override;
151147

148+
std::unique_ptr<NCA> GetEntryNCA(u64 title_id, LoaderContentRecordType type) const override;
152149

153150
// If a parameter is not std::nullopt, it will be filtered for from all entries.
154151
std::vector<ContentProviderEntry> ListEntriesFilter(
@@ -222,6 +219,7 @@ class ContentProviderUnion : public ContentProvider {
222219
std::optional<u32> GetEntryVersion(u64 title_id) const override;
223220
VirtualFile GetEntryUnparsed(u64 title_id, LoaderContentRecordType type) const override;
224221
VirtualFile GetEntryRaw(u64 title_id, LoaderContentRecordType type) const override;
222+
std::unique_ptr<NCA> GetEntryNCA(u64 title_id, LoaderContentRecordType type) const override;
225223
std::vector<ContentProviderEntry> ListEntriesFilter(
226224
std::optional<LoaderTitleType> title_type, std::optional<LoaderContentRecordType> record_type,
227225
std::optional<u64> title_id) const override;
@@ -251,6 +249,7 @@ class ManualContentProvider : public ContentProvider {
251249
std::optional<u32> GetEntryVersion(u64 title_id) const override;
252250
VirtualFile GetEntryUnparsed(u64 title_id, LoaderContentRecordType type) const override;
253251
VirtualFile GetEntryRaw(u64 title_id, LoaderContentRecordType type) const override;
252+
std::unique_ptr<NCA> GetEntryNCA(u64 title_id, LoaderContentRecordType type) const override;
254253
std::vector<ContentProviderEntry> ListEntriesFilter(
255254
std::optional<LoaderTitleType> title_type, std::optional<LoaderContentRecordType> record_type,
256255
std::optional<u64> title_id) const override;

src/nxemu-loader/system_loader.cpp

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ struct Systemloader::Impl {
1818
m_loader(loader),
1919
m_system(system),
2020
m_fsController(loader),
21-
m_TitleID(0)
21+
m_provider(std::make_unique<FileSys::ManualContentProvider>()),
22+
m_processID(0),
23+
m_titleID(0)
2224
{
2325
}
2426

@@ -31,8 +33,10 @@ struct Systemloader::Impl {
3133
/// ContentProviderUnion instance
3234
std::unique_ptr<FileSys::ContentProviderUnion> m_contentProvider;
3335
FileSys::FileSystemController m_fsController;
36+
std::unique_ptr<FileSys::ManualContentProvider> m_provider;
3437
std::unique_ptr<Nro> m_nro;
35-
uint64_t m_TitleID;
38+
uint64_t m_processID;
39+
uint64_t m_titleID;
3640
};
3741

3842
Systemloader::Systemloader(ISwitchSystem & system) :
@@ -52,6 +56,7 @@ bool Systemloader::Initialize(void)
5256
if (impl->m_contentProvider == nullptr) {
5357
impl->m_contentProvider = std::make_unique<FileSys::ContentProviderUnion>();
5458
}
59+
impl->m_contentProvider->SetSlot(FileSys::ContentProviderUnionSlot::FrontendManual, impl->m_provider.get());
5560
GetFileSystemController().CreateFactories(*GetFilesystem(), false);
5661
return true;
5762
}
@@ -94,6 +99,10 @@ ISwitchSystem & Systemloader::GetSystem() {
9499
return impl->m_system;
95100
}
96101

102+
FileSys::ContentProvider & Systemloader::GetContentProvider() {
103+
return *impl->m_contentProvider;
104+
}
105+
97106
FileSys::VirtualFilesystem Systemloader::GetFilesystem() {
98107
return impl->m_virtualFilesystem;
99108
}
@@ -107,6 +116,16 @@ void Systemloader::RegisterContentProvider(FileSys::ContentProviderUnionSlot slo
107116
impl->m_contentProvider->SetSlot(slot, provider);
108117
}
109118

119+
void Systemloader::SetProcessID(uint64_t processID)
120+
{
121+
impl->m_processID = processID;
122+
}
123+
124+
void Systemloader::SetTitleID(uint64_t titleID)
125+
{
126+
impl->m_titleID = titleID;
127+
}
128+
110129
bool Systemloader::Impl::LoadNRO(const char* nroFile)
111130
{
112131
Path filePath(nroFile);
@@ -135,8 +154,8 @@ bool Systemloader::Impl::LoadNRO(const char* nroFile)
135154
return false;
136155
}
137156

138-
m_TitleID = Nacp->GetTitleId();
139-
m_fsController.RegisterProcess(processID, m_TitleID, std::make_unique<FileSys::RomFSFactory>(nullptr, false, *m_contentProvider, m_fsController));
157+
m_titleID = Nacp->GetTitleId();
158+
m_fsController.RegisterProcess(processID, m_titleID, std::make_unique<FileSys::RomFSFactory>(nullptr, false, *m_contentProvider, m_fsController));
140159
g_settings->SetString(NXCoreSetting::GameName, Nacp->GetApplicationName().c_str());
141160
operatingSystem.StartApplicationProcess(metaData.GetMainThreadPriority(), metaData.GetMainThreadStackSize(), 0, StorageId::None, StorageId::None, nullptr, 0);
142161
return true;
@@ -159,6 +178,28 @@ uint32_t Systemloader::GetContentProviderEntriesCount(bool useTitleType, LoaderT
159178
std::optional<LoaderTitleType> title = useTitleType ? std::optional<LoaderTitleType>((LoaderTitleType)titleType) : std::nullopt;
160179
std::optional<LoaderContentRecordType> record = useContentRecordType ? std::optional<LoaderContentRecordType>((LoaderContentRecordType)contentRecordType) : std::nullopt;
161180
std::optional<u64> id = useTitleId ? std::optional<u64>(titleId) : std::nullopt;
162-
const std::vector<FileSys::ContentProviderEntry> list = rcu.ListEntriesFilter(title, record, id);
181+
const std::vector<ContentProviderEntry> list = rcu.ListEntriesFilter(title, record, id);
163182
return (uint32_t)list.size();
164183
}
184+
185+
uint32_t Systemloader::GetContentProviderEntries(bool useTitleType, LoaderTitleType titleType, bool useContentRecordType, LoaderContentRecordType contentRecordType, bool useTitleId, unsigned long long titleId, ContentProviderEntry * entries, uint32_t entryCount)
186+
{
187+
if (entries == nullptr || entryCount == 0)
188+
{
189+
return 0;
190+
}
191+
const FileSys::ContentProviderUnion& rcu = *impl->m_contentProvider;
192+
std::optional<LoaderTitleType> title = useTitleType ? std::optional<LoaderTitleType>((LoaderTitleType)titleType) : std::nullopt;
193+
std::optional<LoaderContentRecordType> record = useContentRecordType ? std::optional<LoaderContentRecordType>((LoaderContentRecordType)contentRecordType) : std::nullopt;
194+
std::optional<u64> id = useTitleId ? std::optional<u64>(titleId) : std::nullopt;
195+
const std::vector<ContentProviderEntry> list = rcu.ListEntriesFilter(title, record, id);
196+
entryCount = std::min((uint32_t)list.size(), entryCount);
197+
memcpy(entries, list.data(), entryCount * sizeof(ContentProviderEntry));
198+
return entryCount;
199+
}
200+
201+
IFileSysNCA * Systemloader::GetContentProviderEntry(uint64_t title_id, LoaderContentRecordType type)
202+
{
203+
UNIMPLEMENTED();
204+
return nullptr;
205+
}

src/nxemu-loader/system_loader.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ class Systemloader :
2020
~Systemloader();
2121

2222
ISwitchSystem & GetSystem();
23+
FileSys::ContentProvider & GetContentProvider();
2324
FileSys::VirtualFilesystem GetFilesystem();
2425
FileSys::FileSystemController & GetFileSystemController();
2526
void RegisterContentProvider(FileSys::ContentProviderUnionSlot slot, FileSys::ContentProvider* provider);
2627

28+
void SetProcessID(uint64_t processID);
29+
void SetTitleID(uint64_t titleID);
30+
2731
//ISystemloader
2832
bool Initialize() override;
2933
bool SelectAndLoad(void * parentWindow) override;
@@ -32,6 +36,8 @@ class Systemloader :
3236
IFileSystemController & FileSystemController() override;
3337
IVirtualFile * SynthesizeSystemArchive(const uint64_t title_id) override;
3438
uint32_t GetContentProviderEntriesCount(bool useTitleType, LoaderTitleType titleType, bool useContentRecordType, LoaderContentRecordType contentRecordType, bool useTitleId, unsigned long long titleId) override;
39+
uint32_t GetContentProviderEntries(bool useTitleType, LoaderTitleType titleType, bool useContentRecordType, LoaderContentRecordType contentRecordType, bool useTitleId, unsigned long long titleId, ContentProviderEntry * entries, uint32_t entryCount) override;
40+
IFileSysNCA * GetContentProviderEntry(uint64_t title_id, LoaderContentRecordType type) override;
3541

3642
private:
3743
Systemloader() = delete;

src/nxemu-module-spec/system_loader.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ enum class LoaderResultStatus : uint16_t {
9494
ErrorIntegrityVerificationFailed,
9595
};
9696

97+
struct ContentProviderEntry
98+
{
99+
uint64_t titleID;
100+
LoaderContentRecordType type;
101+
};
102+
97103
__interface IVirtualFile;
98104

99105
__interface IVirtualDirectory
@@ -114,20 +120,20 @@ __interface IVirtualFile
114120

115121
__interface ISaveDataFactory
116122
{
117-
void Release();
123+
void Release() = 0;
118124
};
119125

120126
__interface IRomFsController
121127
{
122128
IVirtualFile * OpenCurrentProcess(uint64_t currentProcessTitleId) const = 0;
123-
void Release();
129+
void Release() = 0;
124130
};
125131

126132
__interface IFileSysNCA
127133
{
128134
LoaderResultStatus GetStatus() const = 0;
129135
IVirtualFile * GetRomFS() = 0;
130-
void Release();
136+
void Release() = 0;
131137
};
132138

133139
__interface IFileSysRegisteredCache
@@ -151,6 +157,8 @@ __interface ISystemloader
151157
IFileSystemController & FileSystemController() = 0;
152158
IVirtualFile * SynthesizeSystemArchive(const uint64_t title_id) = 0;
153159
uint32_t GetContentProviderEntriesCount(bool useTitleType, LoaderTitleType titleType, bool useContentRecordType, LoaderContentRecordType contentRecordType, bool useTitleId, unsigned long long titleId) = 0;
160+
uint32_t GetContentProviderEntries(bool useTitleType, LoaderTitleType titleType, bool useContentRecordType, LoaderContentRecordType contentRecordType, bool useTitleId, unsigned long long titleId, ContentProviderEntry* entries, uint32_t entryCount) = 0;
161+
IFileSysNCA * GetContentProviderEntry(uint64_t title_id, LoaderContentRecordType type) = 0;
154162
};
155163

156164
EXPORT ISystemloader * CALL CreateSystemLoader(ISwitchSystem & system);

src/nxemu-os/core/hle/service/aoc/addon_content_manager.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "yuzu_common/logging/log.h"
99
#include "yuzu_common/settings.h"
1010
#include "core/core.h"
11+
#include "core/file_sys/filesystem_interfaces.h"
1112
#include "core/hle/kernel/k_event.h"
1213
#include "core/hle/service/aoc/addon_content_manager.h"
1314
#include "core/hle/service/aoc/purchase_event_manager.h"
@@ -24,14 +25,27 @@ static bool CheckAOCTitleIDMatchesBase(u64 title_id, u64 base) {
2425
return false;
2526
}
2627

27-
static std::vector<u64> AccumulateAOCTitleIDs(Core::System& system) {
28+
static std::vector<u64> AccumulateAOCTitleIDs(Core::System & system) {
2829
std::vector<u64> add_on_content;
2930
ISystemloader & loader = system.GetSystemloader();
3031
uint32_t entriesCount = loader.GetContentProviderEntriesCount(true, LoaderTitleType::AOC, true, LoaderContentRecordType::Data, false, 0);
3132

3233
if (entriesCount > 0)
3334
{
34-
UNIMPLEMENTED();
35+
std::vector<ContentProviderEntry> entries(entriesCount);
36+
entriesCount = loader.GetContentProviderEntries(true, LoaderTitleType::AOC, true, LoaderContentRecordType::Data, false, 0, entries.data(), entriesCount);
37+
entries.resize(entriesCount);
38+
std::vector<u64> add_on_content;
39+
std::transform(entries.begin(), entries.end(), std::back_inserter(add_on_content),
40+
[](const ContentProviderEntry& rce) { return rce.titleID; });
41+
42+
add_on_content.erase(
43+
std::remove_if(
44+
add_on_content.begin(), add_on_content.end(),
45+
[&loader](u64 tid) {
46+
return FileSysNCAPtr(loader.GetContentProviderEntry(tid, LoaderContentRecordType::Data))->GetStatus() != LoaderResultStatus::Success;
47+
}),
48+
add_on_content.end());
3549
}
3650
return add_on_content;
3751
}

0 commit comments

Comments
 (0)