From 75169c75708d9f54297537b387182bee10ada9ab Mon Sep 17 00:00:00 2001 From: David Marcec Date: Thu, 9 Aug 2018 01:09:12 +1000 Subject: [PATCH] Inital pass of account backend implementation This commit verified working on puyo --- src/core/hle/service/acc/acc.cpp | 11 +++-------- src/core/hle/service/acc/profile_manager.cpp | 18 ++++++++++++++++-- src/core/hle/service/acc/profile_manager.h | 5 +++-- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index 92141f61c4..7c62d99f6c 100644 --- a/src/core/hle/service/acc/acc.cpp +++ b/src/core/hle/service/acc/acc.cpp @@ -48,13 +48,6 @@ private: LOG_INFO(Service_ACC, "called user_id={}", user_id.Format()); ProfileBase profile_base{}; std::array data{}; - /*if (Settings::values.username.size() > profile_base.username.size()) { - std::copy_n(Settings::values.username.begin(), profile_base.username.size(), - profile_base.username.begin()); - } else { - std::copy(Settings::values.username.begin(), Settings::values.username.end(), - profile_base.username.begin()); - }*/ if (profile_manager.GetProfileBaseAndData(user_id, profile_base, data)) { ctx.WriteBuffer(data); IPC::ResponseBuilder rb{ctx, 16}; @@ -177,7 +170,9 @@ void Module::Interface::GetBaasAccountManagerForApplication(Kernel::HLERequestCo } Module::Interface::Interface(std::shared_ptr module, const char* name) - : ServiceFramework(name), module(std::move(module)) {} + : ServiceFramework(name), module(std::move(module)) { + profile_manager = std::make_unique(); +} void InstallInterfaces(SM::ServiceManager& service_manager) { auto module = std::make_shared(); diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp index 9250220184..1633d5d484 100644 --- a/src/core/hle/service/acc/profile_manager.cpp +++ b/src/core/hle/service/acc/profile_manager.cpp @@ -1,3 +1,4 @@ +#include "core/settings.h" #include "profile_manager.h" namespace Service::Account { @@ -5,6 +6,10 @@ namespace Service::Account { constexpr ResultCode ERROR_TOO_MANY_USERS(ErrorModule::Account, -1); constexpr ResultCode ERROR_ARGUMENT_IS_NULL(ErrorModule::Account, 20); +ProfileManager::ProfileManager() { + CreateNewUser(UUID{1, 0}, Settings::values.username); +} + size_t ProfileManager::AddToProfiles(const ProfileInfo& user) { if (user_count >= MAX_USERS) { return -1; @@ -39,14 +44,23 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, std::array usernam if (username[0] == 0x0) return ERROR_ARGUMENT_IS_NULL; ProfileInfo prof_inf; - prof_inf.user_uuid = uuid; - prof_inf.username = username; + prof_inf.user_uuid = std::move(uuid); + prof_inf.username = std::move(username); prof_inf.data = std::array(); prof_inf.creation_time = 0x0; prof_inf.is_open = false; return AddUser(prof_inf); } +ResultCode ProfileManager::CreateNewUser(UUID uuid, std::string username) { + std::array username_output; + if (username.size() > username_output.size()) + std::copy_n(username.begin(), username_output.size(), username_output.begin()); + else + std::copy(username.begin(), username.end(), username_output.begin()); + return CreateNewUser(uuid, std::move(username_output)); +} + size_t ProfileManager::GetUserIndex(UUID uuid) { if (!uuid) return -1; diff --git a/src/core/hle/service/acc/profile_manager.h b/src/core/hle/service/acc/profile_manager.h index cb6239cc1e..1300419947 100644 --- a/src/core/hle/service/acc/profile_manager.h +++ b/src/core/hle/service/acc/profile_manager.h @@ -21,7 +21,7 @@ struct UUID { uuid[1] = hi; }; operator bool() const { - return uuid[0] != 0x0 && uuid[1] != 0x0; + return uuid[0] != 0x0 || uuid[1] != 0x0; } bool operator==(const UUID& rhs) { @@ -76,9 +76,10 @@ static_assert(sizeof(ProfileBase) == 0x38, "ProfileBase is an invalid size"); /// objects class ProfileManager { public: - ProfileManager() = default; // TODO(ogniK): Load from system save + ProfileManager(); // TODO(ogniK): Load from system save ResultCode AddUser(ProfileInfo user); ResultCode CreateNewUser(UUID uuid, std::array username); + ResultCode CreateNewUser(UUID uuid, std::string username); size_t GetUserIndex(UUID uuid); size_t GetUserIndex(ProfileInfo user); bool GetProfileBase(size_t index, ProfileBase& profile);