From 4a88adafb6bbadfe59593143eb86619808349bf2 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Sat, 4 Jul 2020 21:22:35 +0100 Subject: [PATCH] Implement the set service together with GetAvailableLanguageCodes The 'set' service is used to obtain user settings such as language. This is used by Puyo Puyo Tetris. --- app/CMakeLists.txt | 1 + .../main/cpp/skyline/services/base_service.h | 2 ++ .../main/cpp/skyline/services/serviceman.cpp | 4 +++ .../services/settings/ISettingsServer.cpp | 35 +++++++++++++++++++ .../services/settings/ISettingsServer.h | 22 ++++++++++++ 5 files changed, 64 insertions(+) create mode 100644 app/src/main/cpp/skyline/services/settings/ISettingsServer.cpp create mode 100644 app/src/main/cpp/skyline/services/settings/ISettingsServer.h diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 4ba47ee3..44a9c575 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -63,6 +63,7 @@ add_library(skyline SHARED ${source_DIR}/skyline/services/audio/IAudioRenderer/IAudioRenderer.cpp ${source_DIR}/skyline/services/audio/IAudioRenderer/voice.cpp ${source_DIR}/skyline/services/audio/IAudioRenderer/memory_pool.cpp + ${source_DIR}/skyline/services/settings/ISettingsServer.cpp ${source_DIR}/skyline/services/settings/ISystemSettingsServer.cpp ${source_DIR}/skyline/services/apm/IManager.cpp ${source_DIR}/skyline/services/apm/ISession.cpp diff --git a/app/src/main/cpp/skyline/services/base_service.h b/app/src/main/cpp/skyline/services/base_service.h index 282a530d..2d63f610 100644 --- a/app/src/main/cpp/skyline/services/base_service.h +++ b/app/src/main/cpp/skyline/services/base_service.h @@ -23,6 +23,7 @@ namespace skyline::service { enum class Service { sm_IUserInterface, fatalsrv_IService, + settings_ISettingsServer, settings_ISystemSettingsServer, apm_IManager, apm_ISession, @@ -67,6 +68,7 @@ namespace skyline::service { */ const static std::unordered_map ServiceString{ {"fatal:u", Service::fatalsrv_IService}, + {"set", Service::settings_ISettingsServer}, {"set:sys", Service::settings_ISystemSettingsServer}, {"apm", Service::apm_IManager}, {"appletOE", Service::am_IApplicationProxyService}, diff --git a/app/src/main/cpp/skyline/services/serviceman.cpp b/app/src/main/cpp/skyline/services/serviceman.cpp index 606756fb..ef942007 100644 --- a/app/src/main/cpp/skyline/services/serviceman.cpp +++ b/app/src/main/cpp/skyline/services/serviceman.cpp @@ -3,6 +3,7 @@ #include #include "sm/IUserInterface.h" +#include "settings/ISettingsServer.h" #include "settings/ISystemSettingsServer.h" #include "apm/IManager.h" #include "am/IApplicationProxyService.h" @@ -34,6 +35,9 @@ namespace skyline::service { case Service::fatalsrv_IService: serviceObj = std::make_shared(state, *this); break; + case Service::settings_ISettingsServer: + serviceObj = std::make_shared(state, *this); + break; case Service::settings_ISystemSettingsServer: serviceObj = std::make_shared(state, *this); break; diff --git a/app/src/main/cpp/skyline/services/settings/ISettingsServer.cpp b/app/src/main/cpp/skyline/services/settings/ISettingsServer.cpp new file mode 100644 index 00000000..7683245b --- /dev/null +++ b/app/src/main/cpp/skyline/services/settings/ISettingsServer.cpp @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: MPL-2.0 +// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) + +#include +#include "ISettingsServer.h" + +namespace skyline::service::settings { + ISettingsServer::ISettingsServer(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::settings_ISettingsServer, "settings:ISettingsServer", { + {0x1, SFUNC(ISettingsServer::GetAvailableLanguageCodes)} + }) {} + + constexpr std::array LanguageCodeList = { + util::MakeMagic("ja"), + util::MakeMagic("en-US"), + util::MakeMagic("fr"), + util::MakeMagic("de"), + util::MakeMagic("it"), + util::MakeMagic("es"), + util::MakeMagic("zh-CN"), + util::MakeMagic("ko"), + util::MakeMagic("nl"), + util::MakeMagic("pt"), + util::MakeMagic("ru"), + util::MakeMagic("zh-TW"), + util::MakeMagic("en-GB"), + util::MakeMagic("fr-CA"), + util::MakeMagic("es-419") + }; + + void ISettingsServer::GetAvailableLanguageCodes(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { + state.process->WriteMemory(LanguageCodeList.data(), request.outputBuf.at(0).address, LanguageCodeList.size() * sizeof(u64)); + + response.Push(LanguageCodeList.size()); + } +} diff --git a/app/src/main/cpp/skyline/services/settings/ISettingsServer.h b/app/src/main/cpp/skyline/services/settings/ISettingsServer.h new file mode 100644 index 00000000..568f72b4 --- /dev/null +++ b/app/src/main/cpp/skyline/services/settings/ISettingsServer.h @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: MPL-2.0 +// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) + +#pragma once + +#include +#include + +namespace skyline::service::settings { + /** + * @brief ISettingsServer or 'set' provides access to user settings (https://switchbrew.org/wiki/Settings_services#set) + */ + class ISettingsServer : public BaseService { + public: + ISettingsServer(const DeviceState &state, ServiceManager &manager); + + /** + * @brief This reads the available language codes that an application can use + */ + void GetAvailableLanguageCodes(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); + }; +}