From 0eb6c6cd836028a94260321e460871c228deee50 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Fri, 4 Dec 2020 01:41:21 -0500 Subject: file_sys: Consolidate common Title ID operations --- src/core/hle/service/aoc/aoc_u.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/core/hle/service') 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 @@ #include #include "common/logging/log.h" #include "core/core.h" +#include "core/file_sys/common_funcs.h" #include "core/file_sys/content_archive.h" #include "core/file_sys/control_metadata.h" #include "core/file_sys/nca_metadata.h" @@ -23,11 +24,8 @@ namespace Service::AOC { -constexpr u64 DLC_BASE_TITLE_ID_MASK = 0xFFFFFFFFFFFFE000; -constexpr u64 DLC_BASE_TO_AOC_ID = 0x1000; - static bool CheckAOCTitleIDMatchesBase(u64 title_id, u64 base) { - return (title_id & DLC_BASE_TITLE_ID_MASK) == base; + return FileSys::GetBaseTitleID(title_id) == base; } static std::vector AccumulateAOCTitleIDs(Core::System& system) { @@ -123,11 +121,11 @@ void AOC_U::ListAddOnContent(Kernel::HLERequestContext& ctx) { const auto& disabled = Settings::values.disabled_addons[current]; if (std::find(disabled.begin(), disabled.end(), "DLC") == disabled.end()) { for (u64 content_id : add_on_content) { - if ((content_id & DLC_BASE_TITLE_ID_MASK) != current) { + if (FileSys::GetBaseTitleID(content_id) != current) { continue; } - out.push_back(static_cast(content_id & 0x7FF)); + out.push_back(static_cast(FileSys::GetAOCID(content_id))); } } @@ -169,7 +167,7 @@ void AOC_U::GetAddOnContentBaseId(Kernel::HLERequestContext& ctx) { const auto res = pm.GetControlMetadata(); if (res.first == nullptr) { - rb.Push(title_id + DLC_BASE_TO_AOC_ID); + rb.Push(FileSys::GetAOCBaseTitleID(title_id)); return; } -- cgit v1.2.3 From e15039372ea63efb37cdaa70833b2d080931ee3c Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 3 Dec 2020 22:57:28 -0500 Subject: fsp_srv: Implement OpenDataStorageWithProgramIndex - Used by RollerCoaster Tycoon 3: Complete Edition --- src/core/hle/service/filesystem/filesystem.cpp | 25 +++++++++++++++++++++++ src/core/hle/service/filesystem/filesystem.h | 4 ++++ src/core/hle/service/filesystem/fsp_srv.cpp | 28 +++++++++++++++++++++++++- src/core/hle/service/filesystem/fsp_srv.h | 1 + 4 files changed, 57 insertions(+), 1 deletion(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index ca93062cf..0e9e06267 100644 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp @@ -298,6 +298,31 @@ ResultVal FileSystemController::OpenRomFSCurrentProcess() return romfs_factory->OpenCurrentProcess(system.CurrentProcess()->GetTitleID()); } +ResultVal FileSystemController::OpenPatchedRomFS( + u64 title_id, FileSys::ContentRecordType type) const { + LOG_TRACE(Service_FS, "Opening patched RomFS for title_id={:016X}", title_id); + + if (romfs_factory == nullptr) { + // TODO: Find a better error code for this + return RESULT_UNKNOWN; + } + + return romfs_factory->OpenPatchedRomFS(title_id, type); +} + +ResultVal FileSystemController::OpenPatchedRomFSWithProgramIndex( + u64 title_id, u8 program_index, FileSys::ContentRecordType type) const { + LOG_TRACE(Service_FS, "Opening patched RomFS for title_id={:016X}, program_index={}", title_id, + program_index); + + if (romfs_factory == nullptr) { + // TODO: Find a better error code for this + return RESULT_UNKNOWN; + } + + return romfs_factory->OpenPatchedRomFSWithProgramIndex(title_id, program_index, type); +} + ResultVal FileSystemController::OpenRomFS( u64 title_id, FileSys::StorageId storage_id, FileSys::ContentRecordType type) const { LOG_TRACE(Service_FS, "Opening RomFS for title_id={:016X}, storage_id={:02X}, type={:02X}", diff --git a/src/core/hle/service/filesystem/filesystem.h b/src/core/hle/service/filesystem/filesystem.h index 6dbbf0b2b..7102d3f9a 100644 --- a/src/core/hle/service/filesystem/filesystem.h +++ b/src/core/hle/service/filesystem/filesystem.h @@ -66,6 +66,10 @@ public: void SetPackedUpdate(FileSys::VirtualFile update_raw); ResultVal OpenRomFSCurrentProcess() const; + ResultVal OpenPatchedRomFS(u64 title_id, + FileSys::ContentRecordType type) const; + ResultVal OpenPatchedRomFSWithProgramIndex( + u64 title_id, u8 program_index, FileSys::ContentRecordType type) const; ResultVal OpenRomFS(u64 title_id, FileSys::StorageId storage_id, FileSys::ContentRecordType type) const; ResultVal CreateSaveData( diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index b3480494c..a3623e0be 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp @@ -718,7 +718,7 @@ FSP_SRV::FSP_SRV(Core::System& system_) {202, &FSP_SRV::OpenDataStorageByDataId, "OpenDataStorageByDataId"}, {203, &FSP_SRV::OpenPatchDataStorageByCurrentProcess, "OpenPatchDataStorageByCurrentProcess"}, {204, nullptr, "OpenDataFileSystemByProgramIndex"}, - {205, nullptr, "OpenDataStorageByProgramIndex"}, + {205, &FSP_SRV::OpenDataStorageWithProgramIndex, "OpenDataStorageWithProgramIndex"}, {400, nullptr, "OpenDeviceOperator"}, {500, nullptr, "OpenSdCardDetectionEventNotifier"}, {501, nullptr, "OpenGameCardDetectionEventNotifier"}, @@ -997,6 +997,32 @@ void FSP_SRV::OpenPatchDataStorageByCurrentProcess(Kernel::HLERequestContext& ct rb.Push(FileSys::ERROR_ENTITY_NOT_FOUND); } +void FSP_SRV::OpenDataStorageWithProgramIndex(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + + const auto program_index = rp.PopRaw(); + + LOG_DEBUG(Service_FS, "called, program_index={}", program_index); + + auto romfs = fsc.OpenPatchedRomFSWithProgramIndex( + system.CurrentProcess()->GetTitleID(), program_index, FileSys::ContentRecordType::Program); + + if (romfs.Failed()) { + // TODO: Find the right error code to use here + LOG_ERROR(Service_FS, "could not open storage with program_index={}", program_index); + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(RESULT_UNKNOWN); + return; + } + + auto storage = std::make_shared(system, std::move(romfs.Unwrap())); + + IPC::ResponseBuilder rb{ctx, 2, 0, 1}; + rb.Push(RESULT_SUCCESS); + rb.PushIpcInterface(std::move(storage)); +} + void FSP_SRV::SetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; log_mode = rp.PopEnum(); diff --git a/src/core/hle/service/filesystem/fsp_srv.h b/src/core/hle/service/filesystem/fsp_srv.h index 472286d6e..8ed933279 100644 --- a/src/core/hle/service/filesystem/fsp_srv.h +++ b/src/core/hle/service/filesystem/fsp_srv.h @@ -49,6 +49,7 @@ private: void OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx); void OpenDataStorageByDataId(Kernel::HLERequestContext& ctx); void OpenPatchDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx); + void OpenDataStorageWithProgramIndex(Kernel::HLERequestContext& ctx); void SetGlobalAccessLogMode(Kernel::HLERequestContext& ctx); void GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx); void OutputAccessLogToSdCard(Kernel::HLERequestContext& ctx); -- cgit v1.2.3