From ff5dddbd5bf06c4dca9b5b26cf5432b93663d304 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Thu, 9 Jul 2020 14:16:51 +0100 Subject: [PATCH] Extend account services to support BAAS and some user operations These are needed by Super Mario Odyssey and several other games. --- app/CMakeLists.txt | 1 + .../account/IAccountServiceForApplication.cpp | 20 +++++++++++++++- .../account/IAccountServiceForApplication.h | 23 +++++++++++++++++++ .../account/IManagerForApplication.cpp | 9 ++++++++ .../services/account/IManagerForApplication.h | 17 ++++++++++++++ .../main/cpp/skyline/services/base_service.h | 1 + 6 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 app/src/main/cpp/skyline/services/account/IManagerForApplication.cpp create mode 100644 app/src/main/cpp/skyline/services/account/IManagerForApplication.h diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 1573ca78..1794fc7c 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -114,6 +114,7 @@ add_library(skyline SHARED ${source_DIR}/skyline/services/lm/ILogService.cpp ${source_DIR}/skyline/services/lm/ILogger.cpp ${source_DIR}/skyline/services/account/IAccountServiceForApplication.cpp + ${source_DIR}/skyline/services/account/IManagerForApplication.cpp ${source_DIR}/skyline/vfs/partition_filesystem.cpp ${source_DIR}/skyline/vfs/rom_filesystem.cpp ${source_DIR}/skyline/vfs/os_backing.cpp diff --git a/app/src/main/cpp/skyline/services/account/IAccountServiceForApplication.cpp b/app/src/main/cpp/skyline/services/account/IAccountServiceForApplication.cpp index 42d2944f..545de332 100644 --- a/app/src/main/cpp/skyline/services/account/IAccountServiceForApplication.cpp +++ b/app/src/main/cpp/skyline/services/account/IAccountServiceForApplication.cpp @@ -1,12 +1,30 @@ // SPDX-License-Identifier: MPL-2.0 // Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) +#include "IManagerForApplication.h" #include "IAccountServiceForApplication.h" namespace skyline::service::account { IAccountServiceForApplication::IAccountServiceForApplication(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::account_IAccountServiceForApplication, "account:IAccountServiceForApplication", { - {0x64, SFUNC(IAccountServiceForApplication::InitializeApplicationInfoV0)} + {0x1, SFUNC(IAccountServiceForApplication::GetUserExistence)}, + {0x4, SFUNC(IAccountServiceForApplication::GetLastOpenedUser)}, + {0x64, SFUNC(IAccountServiceForApplication::InitializeApplicationInfoV0)}, + {0x65, SFUNC(IAccountServiceForApplication::GetBaasAccountManagerForApplication)} }) {} + void IAccountServiceForApplication::GetUserExistence(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { + auto id = request.Pop(); + + response.Push(id == constant::DefaultUserId); + } + + void IAccountServiceForApplication::GetLastOpenedUser(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { + response.Push(constant::DefaultUserId); + } + void IAccountServiceForApplication::InitializeApplicationInfoV0(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {} + + void IAccountServiceForApplication::GetBaasAccountManagerForApplication(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { + manager.RegisterService(SRVREG(IManagerForApplication), session, response); + } } diff --git a/app/src/main/cpp/skyline/services/account/IAccountServiceForApplication.h b/app/src/main/cpp/skyline/services/account/IAccountServiceForApplication.h index 5d97e37c..31688b7c 100644 --- a/app/src/main/cpp/skyline/services/account/IAccountServiceForApplication.h +++ b/app/src/main/cpp/skyline/services/account/IAccountServiceForApplication.h @@ -14,6 +14,14 @@ namespace skyline { struct UserId { u64 upper; //!< The upper 64 bits of the user ID u64 lower; //!< The lower 64 bits of the user ID + + /** + * @param userId The user ID to compare with + * @return Whether this user ID matches the one given as a parameter + */ + inline constexpr bool operator==(const UserId& userId) { + return upper == userId.upper && lower == userId.lower; + } }; /** * @brief IAccountServiceForApplication or acc:u0 provides functions for reading user information (https://switchbrew.org/wiki/Account_services#acc:u0) @@ -22,10 +30,25 @@ namespace skyline { public: IAccountServiceForApplication(const DeviceState &state, ServiceManager &manager); + /** + * @brief This checks if the given user ID exists + */ + void GetUserExistence(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); + + /** + * @brief This returns the user ID of the last active user on the console + */ + void GetLastOpenedUser(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); + /** * @brief This provides information about the running application for account services to use (https://switchbrew.org/wiki/Account_services#InitializeApplicationInfoV0) */ void InitializeApplicationInfoV0(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); + + /** + * @brief This returns a handle to an IManagerForApplication which can be used for reading Nintendo Online info + */ + void GetBaasAccountManagerForApplication(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); }; } diff --git a/app/src/main/cpp/skyline/services/account/IManagerForApplication.cpp b/app/src/main/cpp/skyline/services/account/IManagerForApplication.cpp new file mode 100644 index 00000000..a13e09ea --- /dev/null +++ b/app/src/main/cpp/skyline/services/account/IManagerForApplication.cpp @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: MPL-2.0 +// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) + +#include "IManagerForApplication.h" + +namespace skyline::service::account { + IManagerForApplication::IManagerForApplication(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::account_IManagerForApplication, "account:IManagerForApplication", { + }) {} +} diff --git a/app/src/main/cpp/skyline/services/account/IManagerForApplication.h b/app/src/main/cpp/skyline/services/account/IManagerForApplication.h new file mode 100644 index 00000000..e7c13159 --- /dev/null +++ b/app/src/main/cpp/skyline/services/account/IManagerForApplication.h @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: MPL-2.0 +// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) + +#pragma once + +#include +#include + +namespace skyline::service::account { + /** + * @brief IManagerForApplication provides functions for reading Nintendo Online user information (https://switchbrew.org/wiki/Account_services#IManagerForApplication) + */ + class IManagerForApplication : public BaseService { + public: + IManagerForApplication(const DeviceState &state, ServiceManager &manager); + }; +} \ No newline at end of file diff --git a/app/src/main/cpp/skyline/services/base_service.h b/app/src/main/cpp/skyline/services/base_service.h index ee8196c4..a3ac90ae 100644 --- a/app/src/main/cpp/skyline/services/base_service.h +++ b/app/src/main/cpp/skyline/services/base_service.h @@ -70,6 +70,7 @@ namespace skyline::service { lm_ILogService, lm_ILogger, account_IAccountServiceForApplication, + account_IManagerForApplication, }; /**