From 93da9f28267a0ec60d9a1c7177b62253c2599157 Mon Sep 17 00:00:00 2001 From: Willi Ye Date: Mon, 20 Jul 2020 22:16:11 +0200 Subject: [PATCH] Align code style with project * Return correct error code for invalid user * Always return first icon color --- app/src/main/cpp/skyline/common.h | 1 - .../account/IAccountServiceForApplication.cpp | 4 +-- .../account/IAccountServiceForApplication.h | 6 ++-- .../cpp/skyline/services/account/IProfile.cpp | 29 ++++++++++++++----- .../cpp/skyline/services/account/IProfile.h | 22 +++----------- .../preference/CustomEditTextPreference.kt | 3 +- 6 files changed, 30 insertions(+), 35 deletions(-) diff --git a/app/src/main/cpp/skyline/common.h b/app/src/main/cpp/skyline/common.h index 705e2873..c2414c41 100644 --- a/app/src/main/cpp/skyline/common.h +++ b/app/src/main/cpp/skyline/common.h @@ -54,7 +54,6 @@ namespace skyline { constexpr u32 MaxHandles = 0xEE01; //!< "Too many handles" constexpr u32 NotFound = 0xF201; //!< "Not found" constexpr u32 Unimpl = 0x177202; //!< "Unimplemented behaviour" - constexpr u32 InvArg = 0x2c7c; //!< "Argument is invalid" } }; diff --git a/app/src/main/cpp/skyline/services/account/IAccountServiceForApplication.cpp b/app/src/main/cpp/skyline/services/account/IAccountServiceForApplication.cpp index b745ab95..f09d0843 100644 --- a/app/src/main/cpp/skyline/services/account/IAccountServiceForApplication.cpp +++ b/app/src/main/cpp/skyline/services/account/IAccountServiceForApplication.cpp @@ -2,8 +2,8 @@ // Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) #include "IManagerForApplication.h" -#include "IAccountServiceForApplication.h" #include "IProfile.h" +#include "IAccountServiceForApplication.h" namespace skyline::service::account { IAccountServiceForApplication::IAccountServiceForApplication(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::account_IAccountServiceForApplication, "account:IAccountServiceForApplication", { @@ -29,7 +29,7 @@ namespace skyline::service::account { void IAccountServiceForApplication::GetProfile(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { auto id = request.Pop(); if (id != constant::DefaultUserId) { - response.errorCode = constant::status::InvArg; + response.errorCode = constant::InvUser; return; } diff --git a/app/src/main/cpp/skyline/services/account/IAccountServiceForApplication.h b/app/src/main/cpp/skyline/services/account/IAccountServiceForApplication.h index 05104940..b7bf0bfd 100644 --- a/app/src/main/cpp/skyline/services/account/IAccountServiceForApplication.h +++ b/app/src/main/cpp/skyline/services/account/IAccountServiceForApplication.h @@ -15,10 +15,6 @@ namespace skyline { 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; } @@ -63,5 +59,7 @@ namespace skyline { namespace constant { constexpr service::account::UserId DefaultUserId = {0x0000000000000001, 0x0000000000000000}; //!< The default user ID + + constexpr u32 InvUser = 0xC87C; //!< Invalid user } } \ No newline at end of file diff --git a/app/src/main/cpp/skyline/services/account/IProfile.cpp b/app/src/main/cpp/skyline/services/account/IProfile.cpp index 8b366de8..7078e862 100644 --- a/app/src/main/cpp/skyline/services/account/IProfile.cpp +++ b/app/src/main/cpp/skyline/services/account/IProfile.cpp @@ -5,20 +5,33 @@ #include "IProfile.h" namespace skyline::service::account { - IProfile::IProfile(const DeviceState &state, ServiceManager &manager, const UserId &userId) : BaseService(state, manager, Service::account_IProfile, "account:IProfile", { + IProfile::IProfile(const DeviceState &state, ServiceManager &manager, const UserId &userId) : userId(userId), BaseService(state, manager, Service::account_IProfile, "account:IProfile", { {0x0, SFUNC(IProfile::Get)} }) {} void IProfile::Get(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { - AccountUserData userData{}; - AccountProfileBase profileBase{}; + struct AccountUserData { + u32 _unk0_; //!< Unknown. + u32 iconID; //!< Icon ID (0 = Mii, the rest are character icon IDs). + u8 iconBackgroundColorID; //!< Profile icon background color ID + std::array _unk1_; //!< Unknown. + std::array miiID; //!< Some ID related to the Mii? All zeros when a character icon is used. + std::array _unk2_; //!< Unknown. + }; + + struct { + UserId uid; //!< The UID of the corresponding account + u64 lastEditTimestamp; //!< A POSIX UTC timestamp denoting the last account edit. + std::array nickname; //!< UTF-8 Nickname. + } accountProfileBase = {.uid = userId}; std::string username = state.settings->GetString("username_value"); - size_t usernameSize = std::min(sizeof(profileBase), username.size()); - std::memcpy(profileBase.nickname, username.c_str(), usernameSize); - profileBase.nickname[usernameSize] = '\0'; + size_t usernameSize = std::min(accountProfileBase.nickname.size(), username.size()); + std::memcpy(accountProfileBase.nickname.data(), username.c_str(), usernameSize); - state.process->WriteMemory(userData, request.outputBuf.at(0).address); - response.Push(profileBase); + AccountUserData *userData = state.process->GetPointer(request.outputBuf.at(0).address); + userData->iconBackgroundColorID = 0x1; // Color indexing starts at 0x1 + + response.Push(accountProfileBase); } } diff --git a/app/src/main/cpp/skyline/services/account/IProfile.h b/app/src/main/cpp/skyline/services/account/IProfile.h index b8f16252..73d95abf 100644 --- a/app/src/main/cpp/skyline/services/account/IProfile.h +++ b/app/src/main/cpp/skyline/services/account/IProfile.h @@ -8,23 +8,6 @@ namespace skyline::service::account { - /// UserData - typedef struct { - u32 unk_x0; ///< Unknown. - u32 iconID; ///< Icon ID. 0 = Mii, the rest are character icon IDs. - u8 iconBackgroundColorID; ///< Profile icon background color ID - u8 unk_x9[0x7]; ///< Unknown. - u8 miiID[0x10]; ///< Some ID related to the Mii? All zeros when a character icon is used. - u8 unk_x20[0x60]; ///< Usually zeros? - } AccountUserData; - - /// ProfileBase - typedef struct { - UserId uid; ///< \ref AccountUid - u64 lastEditTimestamp; ///< POSIX UTC timestamp, for the last account edit. - char nickname[0x20]; ///< UTF-8 Nickname. - } AccountProfileBase; - /** * @brief IProfile provides functions for reading user profile (https://switchbrew.org/wiki/Account_services#IProfile) */ @@ -33,8 +16,11 @@ namespace skyline::service::account { IProfile(const DeviceState &state, ServiceManager &manager, const UserId &userId); private: + + UserId userId; + /** - * @brief This returns AccountUserData (optional) and AccountProfileBase + * @brief This returns AccountUserData and AccountProfileBase objects that describe the user's information */ void Get(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); }; diff --git a/app/src/main/java/emu/skyline/preference/CustomEditTextPreference.kt b/app/src/main/java/emu/skyline/preference/CustomEditTextPreference.kt index c20efe41..0db6c548 100644 --- a/app/src/main/java/emu/skyline/preference/CustomEditTextPreference.kt +++ b/app/src/main/java/emu/skyline/preference/CustomEditTextPreference.kt @@ -13,8 +13,7 @@ import androidx.preference.EditTextPreference import emu.skyline.R /** - * [EditTextPreference] lacks the feature to set the automatically value as summary. - * This class adds this missing thing. Also added useful attributes. + * This class adapts [EditTextPreference] so that it supports setting the value as the summary automatically. Also added useful attributes. */ class CustomEditTextPreference : EditTextPreference {