From 7c04fe22b4b954613b0fbabb7033675614955f12 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 28 Nov 2018 23:47:01 -0500 Subject: [PATCH 1/2] service/set: Implement MakeLanguageCode This function simply converts a given index into a language code. --- src/core/hle/service/set/set.cpp | 19 ++++++++++++++++++- src/core/hle/service/set/set.h | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/core/hle/service/set/set.cpp b/src/core/hle/service/set/set.cpp index 40a9144f9e..0c7f281c94 100644 --- a/src/core/hle/service/set/set.cpp +++ b/src/core/hle/service/set/set.cpp @@ -35,6 +35,8 @@ constexpr std::array available_language_codes = {{ constexpr std::size_t pre4_0_0_max_entries = 0xF; constexpr std::size_t post4_0_0_max_entries = 0x40; +constexpr ResultCode ERR_INVALID_LANGUAGE{ErrorModule::Settings, 625}; + LanguageCode GetLanguageCodeFromIndex(std::size_t index) { return available_language_codes.at(index); } @@ -67,6 +69,21 @@ void SET::GetAvailableLanguageCodes(Kernel::HLERequestContext& ctx) { PushResponseLanguageCode(ctx, pre4_0_0_max_entries); } +void SET::MakeLanguageCode(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + const auto index = rp.Pop(); + + if (index >= available_language_codes.size()) { + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ERR_INVALID_LANGUAGE); + return; + } + + IPC::ResponseBuilder rb{ctx, 4}; + rb.Push(RESULT_SUCCESS); + rb.PushEnum(available_language_codes[index]); +} + void SET::GetAvailableLanguageCodes2(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_SET, "called"); @@ -102,7 +119,7 @@ SET::SET() : ServiceFramework("set") { static const FunctionInfo functions[] = { {0, &SET::GetLanguageCode, "GetLanguageCode"}, {1, &SET::GetAvailableLanguageCodes, "GetAvailableLanguageCodes"}, - {2, nullptr, "MakeLanguageCode"}, + {2, &SET::MakeLanguageCode, "MakeLanguageCode"}, {3, &SET::GetAvailableLanguageCodeCount, "GetAvailableLanguageCodeCount"}, {4, nullptr, "GetRegionCode"}, {5, &SET::GetAvailableLanguageCodes2, "GetAvailableLanguageCodes2"}, diff --git a/src/core/hle/service/set/set.h b/src/core/hle/service/set/set.h index 266f13e46b..31f9cb296d 100644 --- a/src/core/hle/service/set/set.h +++ b/src/core/hle/service/set/set.h @@ -38,6 +38,7 @@ public: private: void GetLanguageCode(Kernel::HLERequestContext& ctx); void GetAvailableLanguageCodes(Kernel::HLERequestContext& ctx); + void MakeLanguageCode(Kernel::HLERequestContext& ctx); void GetAvailableLanguageCodes2(Kernel::HLERequestContext& ctx); void GetAvailableLanguageCodeCount(Kernel::HLERequestContext& ctx); void GetAvailableLanguageCodeCount2(Kernel::HLERequestContext& ctx); From 308bbba8b9d1dbdff196c161e180818a550216d2 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 30 Nov 2018 03:34:30 -0500 Subject: [PATCH 2/2] service/set: Convert GetLanguageCode over to using PushEnum() This code was around prior to the introduction of PushEnum, so convert it over so we don't need to cast here. --- src/core/hle/service/set/set.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/hle/service/set/set.cpp b/src/core/hle/service/set/set.cpp index 0c7f281c94..1afc43f759 100644 --- a/src/core/hle/service/set/set.cpp +++ b/src/core/hle/service/set/set.cpp @@ -112,7 +112,7 @@ void SET::GetLanguageCode(Kernel::HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 4}; rb.Push(RESULT_SUCCESS); - rb.Push(static_cast(available_language_codes[Settings::values.language_index])); + rb.PushEnum(available_language_codes[Settings::values.language_index]); } SET::SET() : ServiceFramework("set") {