diff --git a/Source/Core/Core/IOS/ES/TitleInformation.cpp b/Source/Core/Core/IOS/ES/TitleInformation.cpp index a608764e31..a70ac5b247 100644 --- a/Source/Core/Core/IOS/ES/TitleInformation.cpp +++ b/Source/Core/Core/IOS/ES/TitleInformation.cpp @@ -67,10 +67,10 @@ IPCCommandResult ES::GetStoredContentsCount(const IOCtlVRequest& request) return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT); const u64 title_id = Memory::Read_U64(request.in_vectors[0].address); - const DiscIO::CNANDContentLoader& content_loader = AccessContentDevice(title_id); - if (!content_loader.IsValid()) - return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT); - return GetStoredContentsCount(content_loader.GetTMD(), request); + const IOS::ES::TMDReader tmd = IOS::ES::FindInstalledTMD(title_id); + if (!tmd.IsValid()) + return GetDefaultReply(FS_ENOENT); + return GetStoredContentsCount(tmd, request); } IPCCommandResult ES::GetStoredContents(const IOCtlVRequest& request) @@ -79,10 +79,10 @@ IPCCommandResult ES::GetStoredContents(const IOCtlVRequest& request) return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT); const u64 title_id = Memory::Read_U64(request.in_vectors[0].address); - const DiscIO::CNANDContentLoader& content_loader = AccessContentDevice(title_id); - if (!content_loader.IsValid()) - return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT); - return GetStoredContents(content_loader.GetTMD(), request); + const IOS::ES::TMDReader tmd = IOS::ES::FindInstalledTMD(title_id); + if (!tmd.IsValid()) + return GetDefaultReply(FS_ENOENT); + return GetStoredContents(tmd, request); } IPCCommandResult ES::GetTMDStoredContentsCount(const IOCtlVRequest& request) @@ -146,17 +146,15 @@ IPCCommandResult ES::GetStoredTMDSize(const IOCtlVRequest& request) if (!request.HasNumberOfValidVectors(1, 1)) return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT); - u64 TitleID = Memory::Read_U64(request.in_vectors[0].address); - const DiscIO::CNANDContentLoader& Loader = AccessContentDevice(TitleID); - - if (!Loader.IsValid() || !Loader.GetTMD().IsValid()) + const u64 title_id = Memory::Read_U64(request.in_vectors[0].address); + const IOS::ES::TMDReader tmd = IOS::ES::FindInstalledTMD(title_id); + if (!tmd.IsValid()) return GetDefaultReply(FS_ENOENT); - const u32 tmd_size = static_cast(Loader.GetTMD().GetRawTMD().size()); + const u32 tmd_size = static_cast(tmd.GetRawTMD().size()); Memory::Write_U32(tmd_size, request.io_vectors[0].address); - INFO_LOG(IOS_ES, "IOCTL_ES_GETSTOREDTMDSIZE: title: %08x/%08x (view size %i)", - (u32)(TitleID >> 32), (u32)TitleID, tmd_size); + INFO_LOG(IOS_ES, "GetStoredTMDSize: %u bytes for %016" PRIx64, tmd_size, title_id); return GetDefaultReply(IPC_SUCCESS); } @@ -166,22 +164,21 @@ IPCCommandResult ES::GetStoredTMD(const IOCtlVRequest& request) if (!request.HasNumberOfValidVectors(2, 1)) return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT); - u64 TitleID = Memory::Read_U64(request.in_vectors[0].address); - // TODO: actually use this param in when writing to the outbuffer :/ - const u32 MaxCount = Memory::Read_U32(request.in_vectors[1].address); - const DiscIO::CNANDContentLoader& Loader = AccessContentDevice(TitleID); - - if (!Loader.IsValid() || !Loader.GetTMD().IsValid()) + const u64 title_id = Memory::Read_U64(request.in_vectors[0].address); + const IOS::ES::TMDReader tmd = IOS::ES::FindInstalledTMD(title_id); + if (!tmd.IsValid()) return GetDefaultReply(FS_ENOENT); - const std::vector raw_tmd = Loader.GetTMD().GetRawTMD(); + // TODO: actually use this param in when writing to the outbuffer :/ + const u32 MaxCount = Memory::Read_U32(request.in_vectors[1].address); + + const std::vector raw_tmd = tmd.GetRawTMD(); if (raw_tmd.size() != request.io_vectors[0].size) return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT); Memory::CopyToEmu(request.io_vectors[0].address, raw_tmd.data(), raw_tmd.size()); - INFO_LOG(IOS_ES, "IOCTL_ES_GETSTOREDTMD: title: %08x/%08x (buffer size: %i)", - (u32)(TitleID >> 32), (u32)TitleID, MaxCount); + INFO_LOG(IOS_ES, "GetStoredTMD: title %016" PRIx64 " (buffer size: %u)", title_id, MaxCount); return GetDefaultReply(IPC_SUCCESS); } diff --git a/Source/Core/Core/IOS/ES/TitleManagement.cpp b/Source/Core/Core/IOS/ES/TitleManagement.cpp index 5a275fa954..dd327ee1cb 100644 --- a/Source/Core/Core/IOS/ES/TitleManagement.cpp +++ b/Source/Core/Core/IOS/ES/TitleManagement.cpp @@ -19,6 +19,7 @@ #include "Common/StringUtil.h" #include "Core/HW/Memmap.h" #include "Core/IOS/ES/Formats.h" +#include "Core/IOS/ES/NandUtils.h" #include "Core/ec_wii.h" #include "DiscIO/NANDContentLoader.h" @@ -403,13 +404,11 @@ IPCCommandResult ES::ExportTitleInit(const IOCtlVRequest& request) if (m_export_title_context.valid) return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT); - const auto& content_loader = AccessContentDevice(Memory::Read_U64(request.in_vectors[0].address)); - if (!content_loader.IsValid()) + const auto tmd = IOS::ES::FindInstalledTMD(Memory::Read_U64(request.in_vectors[0].address)); + if (!tmd.IsValid()) return GetDefaultReply(FS_ENOENT); - if (!content_loader.GetTMD().IsValid()) - return GetDefaultReply(ES_INVALID_TMD); - m_export_title_context.tmd = content_loader.GetTMD(); + m_export_title_context.tmd = tmd; const auto ticket = DiscIO::FindSignedTicket(m_export_title_context.tmd.GetTitleId()); if (!ticket.IsValid()) diff --git a/Source/Core/Core/IOS/ES/Views.cpp b/Source/Core/Core/IOS/ES/Views.cpp index 3e18385078..e5b6bdb75a 100644 --- a/Source/Core/Core/IOS/ES/Views.cpp +++ b/Source/Core/Core/IOS/ES/Views.cpp @@ -14,6 +14,7 @@ #include "Core/ConfigManager.h" #include "Core/HW/Memmap.h" #include "Core/IOS/ES/Formats.h" +#include "Core/IOS/ES/NandUtils.h" #include "DiscIO/NANDContentLoader.h" namespace IOS @@ -96,16 +97,15 @@ IPCCommandResult ES::GetTMDViewSize(const IOCtlVRequest& request) u64 TitleID = Memory::Read_U64(request.in_vectors[0].address); - const DiscIO::CNANDContentLoader& Loader = AccessContentDevice(TitleID); + const IOS::ES::TMDReader tmd = IOS::ES::FindInstalledTMD(TitleID); - if (!Loader.IsValid()) + if (!tmd.IsValid()) return GetDefaultReply(FS_ENOENT); - const u32 view_size = static_cast(Loader.GetTMD().GetRawView().size()); + const u32 view_size = static_cast(tmd.GetRawView().size()); Memory::Write_U32(view_size, request.io_vectors[0].address); - INFO_LOG(IOS_ES, "IOCTL_ES_GETTMDVIEWCNT: title: %08x/%08x (view size %i)", (u32)(TitleID >> 32), - (u32)TitleID, view_size); + INFO_LOG(IOS_ES, "GetTMDViewSize: %u bytes for title %016" PRIx64, view_size, TitleID); return GetDefaultReply(IPC_SUCCESS); } @@ -117,22 +117,18 @@ IPCCommandResult ES::GetTMDViews(const IOCtlVRequest& request) u64 TitleID = Memory::Read_U64(request.in_vectors[0].address); u32 MaxCount = Memory::Read_U32(request.in_vectors[1].address); - const DiscIO::CNANDContentLoader& Loader = AccessContentDevice(TitleID); + const IOS::ES::TMDReader tmd = IOS::ES::FindInstalledTMD(TitleID); - INFO_LOG(IOS_ES, "IOCTL_ES_GETTMDVIEWCNT: title: %08x/%08x buffer size: %i", - (u32)(TitleID >> 32), (u32)TitleID, MaxCount); - - if (!Loader.IsValid()) + if (!tmd.IsValid()) return GetDefaultReply(FS_ENOENT); - const std::vector raw_view = Loader.GetTMD().GetRawView(); + const std::vector raw_view = tmd.GetRawView(); if (raw_view.size() != request.io_vectors[0].size) return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT); Memory::CopyToEmu(request.io_vectors[0].address, raw_view.data(), raw_view.size()); - INFO_LOG(IOS_ES, "IOCTL_ES_GETTMDVIEWS: title: %08x/%08x (buffer size: %i)", (u32)(TitleID >> 32), - (u32)TitleID, MaxCount); + INFO_LOG(IOS_ES, "GetTMDView: %u bytes for title %016" PRIx64, MaxCount, TitleID); return GetDefaultReply(IPC_SUCCESS); }