From 473fd552c8e59d378d9d8cb72d4b76a3984640d1 Mon Sep 17 00:00:00 2001 From: Valentin Vanelslande Date: Sat, 5 May 2018 08:43:31 -0500 Subject: [PATCH] Service/AM: Implement GetProductCode (#3549) * [skip ci] * [skip ci] * [skip ci] * [skip ci] * Service/AM: Implement GetProductCode * fix? * remove close * Use PushRaw * Use NCCHContainer * 2 if found * struct * fix build? * fix * remove return * fix? * 6 words --- src/core/hle/service/am/am.cpp | 26 ++++++++++++++++++++++++++ src/core/hle/service/am/am.h | 12 ++++++++++++ src/core/hle/service/am/am_net.cpp | 2 +- src/core/hle/service/am/am_sys.cpp | 2 +- src/core/hle/service/am/am_u.cpp | 2 +- 5 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index e4fd704cc4..5b80c493f9 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -712,6 +712,32 @@ void Module::Interface::DeleteUserProgram(Kernel::HLERequestContext& ctx) { LOG_ERROR(Service_AM, "FileUtil::DeleteDirRecursively unexpectedly failed"); } +void Module::Interface::GetProductCode(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp(ctx, 0x0005, 3, 0); + FS::MediaType media_type = rp.PopEnum(); + u64 title_id = rp.Pop(); + std::string path = GetTitleContentPath(media_type, title_id); + + if (!FileUtil::Exists(path)) { + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + rb.Push(ResultCode(ErrorDescription::NotFound, ErrorModule::AM, ErrorSummary::InvalidState, + ErrorLevel::Permanent)); + } else { + struct ProductCode { + u8 code[0x10]; + }; + + ProductCode product_code; + + IPC::RequestBuilder rb = rp.MakeBuilder(6, 0); + FileSys::NCCHContainer ncch(path); + ncch.Load(); + std::memcpy(&product_code.code, &ncch.ncch_header.product_code, 0x10); + rb.Push(RESULT_SUCCESS); + rb.PushRaw(product_code); + } +} + void Module::Interface::GetDLCTitleInfos(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp(ctx, 0x1005, 2, 4); // 0x10050084 diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h index cc322375a3..40414b6d67 100644 --- a/src/core/hle/service/am/am.h +++ b/src/core/hle/service/am/am.h @@ -242,6 +242,18 @@ public: */ void DeleteUserProgram(Kernel::HLERequestContext& ctx); + /** + * AM::GetProductCode service function + * Gets the product code of a title + * Inputs: + * 1 : Media Type + * 2-3 : Title ID + * Outputs: + * 1 : Result, 0 on success, otherwise error code + * 2-5 : Product Code + */ + void GetProductCode(Kernel::HLERequestContext& ctx); + /** * AM::GetDLCTitleInfos service function * Wrapper for AM::GetProgramInfos, explicitly checks that TID high value is 0004008C. diff --git a/src/core/hle/service/am/am_net.cpp b/src/core/hle/service/am/am_net.cpp index ca844b5b59..c96df1761e 100644 --- a/src/core/hle/service/am/am_net.cpp +++ b/src/core/hle/service/am/am_net.cpp @@ -13,7 +13,7 @@ AM_NET::AM_NET(std::shared_ptr am) : Module::Interface(std::move(am), "a {0x00020082, &AM_NET::GetProgramList, "GetProgramList"}, {0x00030084, &AM_NET::GetProgramInfos, "GetProgramInfos"}, {0x000400C0, &AM_NET::DeleteUserProgram, "DeleteUserProgram"}, - {0x000500C0, nullptr, "GetProductCode"}, + {0x000500C0, &AM_NET::GetProductCode, "GetProductCode"}, {0x000600C0, nullptr, "GetStorageId"}, {0x00070080, &AM_NET::DeleteTicket, "DeleteTicket"}, {0x00080000, &AM_NET::GetNumTickets, "GetNumTickets"}, diff --git a/src/core/hle/service/am/am_sys.cpp b/src/core/hle/service/am/am_sys.cpp index 61a2bcc7c3..22dab73c7f 100644 --- a/src/core/hle/service/am/am_sys.cpp +++ b/src/core/hle/service/am/am_sys.cpp @@ -13,7 +13,7 @@ AM_SYS::AM_SYS(std::shared_ptr am) : Module::Interface(std::move(am), "a {0x00020082, &AM_SYS::GetProgramList, "GetProgramList"}, {0x00030084, &AM_SYS::GetProgramInfos, "GetProgramInfos"}, {0x000400C0, &AM_SYS::DeleteUserProgram, "DeleteUserProgram"}, - {0x000500C0, nullptr, "GetProductCode"}, + {0x000500C0, &AM_SYS::GetProductCode, "GetProductCode"}, {0x000600C0, nullptr, "GetStorageId"}, {0x00070080, &AM_SYS::DeleteTicket, "DeleteTicket"}, {0x00080000, &AM_SYS::GetNumTickets, "GetNumTickets"}, diff --git a/src/core/hle/service/am/am_u.cpp b/src/core/hle/service/am/am_u.cpp index 9d3d268724..c39a938636 100644 --- a/src/core/hle/service/am/am_u.cpp +++ b/src/core/hle/service/am/am_u.cpp @@ -13,7 +13,7 @@ AM_U::AM_U(std::shared_ptr am) : Module::Interface(std::move(am), "am:u" {0x00020082, &AM_U::GetProgramList, "GetProgramList"}, {0x00030084, &AM_U::GetProgramInfos, "GetProgramInfos"}, {0x000400C0, &AM_U::DeleteUserProgram, "DeleteUserProgram"}, - {0x000500C0, nullptr, "GetProductCode"}, + {0x000500C0, &AM_U::GetProductCode, "GetProductCode"}, {0x000600C0, nullptr, "GetStorageId"}, {0x00070080, &AM_U::DeleteTicket, "DeleteTicket"}, {0x00080000, &AM_U::GetNumTickets, "GetNumTickets"},