From 183193e6ed36e926fd7ff5f6840a2c1bb5022fa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sat, 15 Apr 2017 00:39:34 +0200 Subject: [PATCH] IOS/ES: Implement ES_DIGetTMD and ES_DIGetTMDSize Used by Metroid Prime. --- Source/Core/Core/IOS/ES/ES.cpp | 6 ++++-- Source/Core/Core/IOS/ES/ES.h | 6 ++++-- Source/Core/Core/IOS/ES/Views.cpp | 33 +++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/Source/Core/Core/IOS/ES/ES.cpp b/Source/Core/Core/IOS/ES/ES.cpp index 0a76a77040..00207aff17 100644 --- a/Source/Core/Core/IOS/ES/ES.cpp +++ b/Source/Core/Core/IOS/ES/ES.cpp @@ -372,6 +372,10 @@ IPCCommandResult ES::IOCtlV(const IOCtlVRequest& request) return DIGetTMDViewSize(request); case IOCTL_ES_DIGETTMDVIEW: return DIGetTMDView(request); + case IOCTL_ES_DIGETTMDSIZE: + return DIGetTMDSize(request); + case IOCTL_ES_DIGETTMD: + return DIGetTMD(request); case IOCTL_ES_GETCONSUMPTION: return GetConsumption(request); @@ -414,8 +418,6 @@ IPCCommandResult ES::IOCtlV(const IOCtlVRequest& request) case IOCTL_ES_VERIFYSIGN: case IOCTL_ES_DELETESHAREDCONTENT: - case IOCTL_ES_UNKNOWN_39: - case IOCTL_ES_UNKNOWN_3A: case IOCTL_ES_UNKNOWN_3B: case IOCTL_ES_UNKNOWN_3C: case IOCTL_ES_UNKNOWN_3D: diff --git a/Source/Core/Core/IOS/ES/ES.h b/Source/Core/Core/IOS/ES/ES.h index f80d920f89..b0f7f25b8f 100644 --- a/Source/Core/Core/IOS/ES/ES.h +++ b/Source/Core/Core/IOS/ES/ES.h @@ -120,8 +120,8 @@ private: IOCTL_ES_GETSHAREDCONTENTCNT = 0x36, IOCTL_ES_GETSHAREDCONTENTS = 0x37, IOCTL_ES_DELETESHAREDCONTENT = 0x38, - IOCTL_ES_UNKNOWN_39 = 0x39, - IOCTL_ES_UNKNOWN_3A = 0x3A, + IOCTL_ES_DIGETTMDSIZE = 0x39, + IOCTL_ES_DIGETTMD = 0x3A, IOCTL_ES_UNKNOWN_3B = 0x3B, IOCTL_ES_UNKNOWN_3C = 0x3C, IOCTL_ES_UNKNOWN_3D = 0x3D, @@ -223,6 +223,8 @@ private: IPCCommandResult DIGetTicketView(const IOCtlVRequest& request); IPCCommandResult DIGetTMDViewSize(const IOCtlVRequest& request); IPCCommandResult DIGetTMDView(const IOCtlVRequest& request); + IPCCommandResult DIGetTMDSize(const IOCtlVRequest& request); + IPCCommandResult DIGetTMD(const IOCtlVRequest& request); static bool LaunchIOS(u64 ios_title_id); static bool LaunchPPCTitle(u64 title_id, bool skip_reload); diff --git a/Source/Core/Core/IOS/ES/Views.cpp b/Source/Core/Core/IOS/ES/Views.cpp index 822485abd3..8f06bc8973 100644 --- a/Source/Core/Core/IOS/ES/Views.cpp +++ b/Source/Core/Core/IOS/ES/Views.cpp @@ -260,6 +260,39 @@ IPCCommandResult ES::DIGetTicketView(const IOCtlVRequest& request) return GetDefaultReply(IPC_SUCCESS); } +IPCCommandResult ES::DIGetTMDSize(const IOCtlVRequest& request) +{ + if (!request.HasNumberOfValidVectors(0, 1) || request.io_vectors[0].size != sizeof(u32)) + return GetDefaultReply(ES_EINVAL); + + if (!GetTitleContext().active) + return GetDefaultReply(ES_EINVAL); + + Memory::Write_U32(static_cast(GetTitleContext().tmd.GetRawTMD().size()), + request.io_vectors[0].address); + return GetDefaultReply(IPC_SUCCESS); +} + +IPCCommandResult ES::DIGetTMD(const IOCtlVRequest& request) +{ + if (!request.HasNumberOfValidVectors(1, 1) || request.in_vectors[0].size != sizeof(u32)) + return GetDefaultReply(ES_EINVAL); + + const u32 tmd_size = Memory::Read_U32(request.in_vectors[0].address); + if (tmd_size != request.io_vectors[0].size) + return GetDefaultReply(ES_EINVAL); + + if (!GetTitleContext().active) + return GetDefaultReply(ES_EINVAL); + + const std::vector& tmd_bytes = GetTitleContext().tmd.GetRawTMD(); + + if (static_cast(tmd_bytes.size()) > tmd_size) + return GetDefaultReply(ES_EINVAL); + + Memory::CopyToEmu(request.io_vectors[0].address, tmd_bytes.data(), tmd_bytes.size()); + return GetDefaultReply(IPC_SUCCESS); +} } // namespace Device } // namespace HLE } // namespace IOS