summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar bunnei2019-05-30 13:26:40 -0400
committerGravatar GitHub2019-05-30 13:26:40 -0400
commited74a3cb8b69841bd34344b1387320c0d8912979 (patch)
treef914218f6a5965ad6c47bd9acab096ab22356d5d
parentMerge pull request #2431 from DarkLordZach/game-list-cache (diff)
parentmii_manager: Fix incorrect loop condition in mii UUID generation code (diff)
downloadyuzu-ed74a3cb8b69841bd34344b1387320c0d8912979.tar.gz
yuzu-ed74a3cb8b69841bd34344b1387320c0d8912979.tar.xz
yuzu-ed74a3cb8b69841bd34344b1387320c0d8912979.zip
Merge pull request #1931 from DarkLordZach/mii-database-1
mii: Implement MiiManager backend and several mii service commands
Diffstat (limited to '')
-rw-r--r--src/common/CMakeLists.txt2
-rw-r--r--src/common/uuid.cpp33
-rw-r--r--src/common/uuid.h48
-rw-r--r--src/core/CMakeLists.txt2
-rw-r--r--src/core/frontend/applets/profile_select.cpp5
-rw-r--r--src/core/frontend/applets/profile_select.h8
-rw-r--r--src/core/hle/service/acc/acc.cpp18
-rw-r--r--src/core/hle/service/acc/profile_manager.cpp28
-rw-r--r--src/core/hle/service/acc/profile_manager.h66
-rw-r--r--src/core/hle/service/am/applets/profile_select.cpp8
-rw-r--r--src/core/hle/service/am/applets/profile_select.h5
-rw-r--r--src/core/hle/service/mii/mii.cpp341
-rw-r--r--src/core/hle/service/mii/mii_manager.cpp416
-rw-r--r--src/core/hle/service/mii/mii_manager.h273
-rw-r--r--src/yuzu/applets/profile_select.cpp10
-rw-r--r--src/yuzu/applets/profile_select.h8
-rw-r--r--src/yuzu/configuration/configure_profile_manager.cpp11
-rw-r--r--src/yuzu/main.h2
18 files changed, 1157 insertions, 127 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 1e8e1b215..cb514a0d2 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -123,6 +123,8 @@ add_library(common STATIC
123 timer.h 123 timer.h
124 uint128.cpp 124 uint128.cpp
125 uint128.h 125 uint128.h
126 uuid.cpp
127 uuid.h
126 vector_math.h 128 vector_math.h
127 web_result.h 129 web_result.h
128 zstd_compression.cpp 130 zstd_compression.cpp
diff --git a/src/common/uuid.cpp b/src/common/uuid.cpp
new file mode 100644
index 000000000..26db03fba
--- /dev/null
+++ b/src/common/uuid.cpp
@@ -0,0 +1,33 @@
1// Copyright 2018 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <random>
6
7#include <fmt/format.h>
8
9#include "common/uuid.h"
10
11namespace Common {
12
13UUID UUID::Generate() {
14 std::random_device device;
15 std::mt19937 gen(device());
16 std::uniform_int_distribution<u64> distribution(1, std::numeric_limits<u64>::max());
17 return UUID{distribution(gen), distribution(gen)};
18}
19
20std::string UUID::Format() const {
21 return fmt::format("0x{:016X}{:016X}", uuid[1], uuid[0]);
22}
23
24std::string UUID::FormatSwitch() const {
25 std::array<u8, 16> s{};
26 std::memcpy(s.data(), uuid.data(), sizeof(u128));
27 return fmt::format("{:02x}{:02x}{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{"
28 ":02x}{:02x}{:02x}{:02x}{:02x}",
29 s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11],
30 s[12], s[13], s[14], s[15]);
31}
32
33} // namespace Common
diff --git a/src/common/uuid.h b/src/common/uuid.h
new file mode 100644
index 000000000..f6ad064fb
--- /dev/null
+++ b/src/common/uuid.h
@@ -0,0 +1,48 @@
1// Copyright 2018 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <string>
8
9#include "common/common_types.h"
10
11namespace Common {
12
13constexpr u128 INVALID_UUID{{0, 0}};
14
15struct UUID {
16 // UUIDs which are 0 are considered invalid!
17 u128 uuid = INVALID_UUID;
18 constexpr UUID() = default;
19 constexpr explicit UUID(const u128& id) : uuid{id} {}
20 constexpr explicit UUID(const u64 lo, const u64 hi) : uuid{{lo, hi}} {}
21
22 constexpr explicit operator bool() const {
23 return uuid[0] != INVALID_UUID[0] && uuid[1] != INVALID_UUID[1];
24 }
25
26 constexpr bool operator==(const UUID& rhs) const {
27 // TODO(DarkLordZach): Replace with uuid == rhs.uuid with C++20
28 return uuid[0] == rhs.uuid[0] && uuid[1] == rhs.uuid[1];
29 }
30
31 constexpr bool operator!=(const UUID& rhs) const {
32 return !operator==(rhs);
33 }
34
35 // TODO(ogniK): Properly generate uuids based on RFC-4122
36 static UUID Generate();
37
38 // Set the UUID to {0,0} to be considered an invalid user
39 constexpr void Invalidate() {
40 uuid = INVALID_UUID;
41 }
42
43 std::string Format() const;
44 std::string FormatSwitch() const;
45};
46static_assert(sizeof(UUID) == 16, "UUID is an invalid size!");
47
48} // namespace Common
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 2ace866ee..a56e526a6 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -310,6 +310,8 @@ add_library(core STATIC
310 hle/service/mig/mig.h 310 hle/service/mig/mig.h
311 hle/service/mii/mii.cpp 311 hle/service/mii/mii.cpp
312 hle/service/mii/mii.h 312 hle/service/mii/mii.h
313 hle/service/mii/mii_manager.cpp
314 hle/service/mii/mii_manager.h
313 hle/service/mm/mm_u.cpp 315 hle/service/mm/mm_u.cpp
314 hle/service/mm/mm_u.h 316 hle/service/mm/mm_u.h
315 hle/service/ncm/ncm.cpp 317 hle/service/ncm/ncm.cpp
diff --git a/src/core/frontend/applets/profile_select.cpp b/src/core/frontend/applets/profile_select.cpp
index fbf5f2a9e..4df3574d2 100644
--- a/src/core/frontend/applets/profile_select.cpp
+++ b/src/core/frontend/applets/profile_select.cpp
@@ -3,6 +3,7 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include "core/frontend/applets/profile_select.h" 5#include "core/frontend/applets/profile_select.h"
6#include "core/hle/service/acc/profile_manager.h"
6#include "core/settings.h" 7#include "core/settings.h"
7 8
8namespace Core::Frontend { 9namespace Core::Frontend {
@@ -10,9 +11,9 @@ namespace Core::Frontend {
10ProfileSelectApplet::~ProfileSelectApplet() = default; 11ProfileSelectApplet::~ProfileSelectApplet() = default;
11 12
12void DefaultProfileSelectApplet::SelectProfile( 13void DefaultProfileSelectApplet::SelectProfile(
13 std::function<void(std::optional<Service::Account::UUID>)> callback) const { 14 std::function<void(std::optional<Common::UUID>)> callback) const {
14 Service::Account::ProfileManager manager; 15 Service::Account::ProfileManager manager;
15 callback(manager.GetUser(Settings::values.current_user).value_or(Service::Account::UUID{})); 16 callback(manager.GetUser(Settings::values.current_user).value_or(Common::UUID{}));
16 LOG_INFO(Service_ACC, "called, selecting current user instead of prompting..."); 17 LOG_INFO(Service_ACC, "called, selecting current user instead of prompting...");
17} 18}
18 19
diff --git a/src/core/frontend/applets/profile_select.h b/src/core/frontend/applets/profile_select.h
index fc8f7ae94..3506b9885 100644
--- a/src/core/frontend/applets/profile_select.h
+++ b/src/core/frontend/applets/profile_select.h
@@ -6,7 +6,7 @@
6 6
7#include <functional> 7#include <functional>
8#include <optional> 8#include <optional>
9#include "core/hle/service/acc/profile_manager.h" 9#include "common/uuid.h"
10 10
11namespace Core::Frontend { 11namespace Core::Frontend {
12 12
@@ -14,14 +14,12 @@ class ProfileSelectApplet {
14public: 14public:
15 virtual ~ProfileSelectApplet(); 15 virtual ~ProfileSelectApplet();
16 16
17 virtual void SelectProfile( 17 virtual void SelectProfile(std::function<void(std::optional<Common::UUID>)> callback) const = 0;
18 std::function<void(std::optional<Service::Account::UUID>)> callback) const = 0;
19}; 18};
20 19
21class DefaultProfileSelectApplet final : public ProfileSelectApplet { 20class DefaultProfileSelectApplet final : public ProfileSelectApplet {
22public: 21public:
23 void SelectProfile( 22 void SelectProfile(std::function<void(std::optional<Common::UUID>)> callback) const override;
24 std::function<void(std::optional<Service::Account::UUID>)> callback) const override;
25}; 23};
26 24
27} // namespace Core::Frontend 25} // namespace Core::Frontend
diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp
index ba7d7acbd..86bf53d08 100644
--- a/src/core/hle/service/acc/acc.cpp
+++ b/src/core/hle/service/acc/acc.cpp
@@ -34,7 +34,7 @@ constexpr std::array<u8, backup_jpeg_size> backup_jpeg{{
34 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, 34 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9,
35}}; 35}};
36 36
37static std::string GetImagePath(UUID uuid) { 37static std::string GetImagePath(Common::UUID uuid) {
38 return FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + 38 return FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
39 "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg"; 39 "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg";
40} 40}
@@ -46,7 +46,7 @@ static constexpr u32 SanitizeJPEGSize(std::size_t size) {
46 46
47class IProfile final : public ServiceFramework<IProfile> { 47class IProfile final : public ServiceFramework<IProfile> {
48public: 48public:
49 explicit IProfile(UUID user_id, ProfileManager& profile_manager) 49 explicit IProfile(Common::UUID user_id, ProfileManager& profile_manager)
50 : ServiceFramework("IProfile"), profile_manager(profile_manager), user_id(user_id) { 50 : ServiceFramework("IProfile"), profile_manager(profile_manager), user_id(user_id) {
51 static const FunctionInfo functions[] = { 51 static const FunctionInfo functions[] = {
52 {0, &IProfile::Get, "Get"}, 52 {0, &IProfile::Get, "Get"},
@@ -131,7 +131,7 @@ private:
131 } 131 }
132 132
133 const ProfileManager& profile_manager; 133 const ProfileManager& profile_manager;
134 UUID user_id; ///< The user id this profile refers to. 134 Common::UUID user_id; ///< The user id this profile refers to.
135}; 135};
136 136
137class IManagerForApplication final : public ServiceFramework<IManagerForApplication> { 137class IManagerForApplication final : public ServiceFramework<IManagerForApplication> {
@@ -179,7 +179,7 @@ void Module::Interface::GetUserCount(Kernel::HLERequestContext& ctx) {
179 179
180void Module::Interface::GetUserExistence(Kernel::HLERequestContext& ctx) { 180void Module::Interface::GetUserExistence(Kernel::HLERequestContext& ctx) {
181 IPC::RequestParser rp{ctx}; 181 IPC::RequestParser rp{ctx};
182 UUID user_id = rp.PopRaw<UUID>(); 182 Common::UUID user_id = rp.PopRaw<Common::UUID>();
183 LOG_INFO(Service_ACC, "called user_id={}", user_id.Format()); 183 LOG_INFO(Service_ACC, "called user_id={}", user_id.Format());
184 184
185 IPC::ResponseBuilder rb{ctx, 3}; 185 IPC::ResponseBuilder rb{ctx, 3};
@@ -205,12 +205,12 @@ void Module::Interface::GetLastOpenedUser(Kernel::HLERequestContext& ctx) {
205 LOG_INFO(Service_ACC, "called"); 205 LOG_INFO(Service_ACC, "called");
206 IPC::ResponseBuilder rb{ctx, 6}; 206 IPC::ResponseBuilder rb{ctx, 6};
207 rb.Push(RESULT_SUCCESS); 207 rb.Push(RESULT_SUCCESS);
208 rb.PushRaw<UUID>(profile_manager->GetLastOpenedUser()); 208 rb.PushRaw<Common::UUID>(profile_manager->GetLastOpenedUser());
209} 209}
210 210
211void Module::Interface::GetProfile(Kernel::HLERequestContext& ctx) { 211void Module::Interface::GetProfile(Kernel::HLERequestContext& ctx) {
212 IPC::RequestParser rp{ctx}; 212 IPC::RequestParser rp{ctx};
213 UUID user_id = rp.PopRaw<UUID>(); 213 Common::UUID user_id = rp.PopRaw<Common::UUID>();
214 LOG_DEBUG(Service_ACC, "called user_id={}", user_id.Format()); 214 LOG_DEBUG(Service_ACC, "called user_id={}", user_id.Format());
215 215
216 IPC::ResponseBuilder rb{ctx, 2, 0, 1}; 216 IPC::ResponseBuilder rb{ctx, 2, 0, 1};
@@ -245,15 +245,15 @@ void Module::Interface::TrySelectUserWithoutInteraction(Kernel::HLERequestContex
245 IPC::ResponseBuilder rb{ctx, 6}; 245 IPC::ResponseBuilder rb{ctx, 6};
246 if (profile_manager->GetUserCount() != 1) { 246 if (profile_manager->GetUserCount() != 1) {
247 rb.Push(RESULT_SUCCESS); 247 rb.Push(RESULT_SUCCESS);
248 rb.PushRaw<u128>(INVALID_UUID); 248 rb.PushRaw<u128>(Common::INVALID_UUID);
249 return; 249 return;
250 } 250 }
251 251
252 const auto user_list = profile_manager->GetAllUsers(); 252 const auto user_list = profile_manager->GetAllUsers();
253 if (std::all_of(user_list.begin(), user_list.end(), 253 if (std::all_of(user_list.begin(), user_list.end(),
254 [](const auto& user) { return user.uuid == INVALID_UUID; })) { 254 [](const auto& user) { return user.uuid == Common::INVALID_UUID; })) {
255 rb.Push(ResultCode(-1)); // TODO(ogniK): Find the correct error code 255 rb.Push(ResultCode(-1)); // TODO(ogniK): Find the correct error code
256 rb.PushRaw<u128>(INVALID_UUID); 256 rb.PushRaw<u128>(Common::INVALID_UUID);
257 return; 257 return;
258 } 258 }
259 259
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp
index 1316d0b07..49aa5908b 100644
--- a/src/core/hle/service/acc/profile_manager.cpp
+++ b/src/core/hle/service/acc/profile_manager.cpp
@@ -13,6 +13,8 @@
13 13
14namespace Service::Account { 14namespace Service::Account {
15 15
16using Common::UUID;
17
16struct UserRaw { 18struct UserRaw {
17 UUID uuid; 19 UUID uuid;
18 UUID uuid2; 20 UUID uuid2;
@@ -35,26 +37,6 @@ constexpr ResultCode ERROR_ARGUMENT_IS_NULL(ErrorModule::Account, 20);
35 37
36constexpr char ACC_SAVE_AVATORS_BASE_PATH[] = "/system/save/8000000000000010/su/avators/"; 38constexpr char ACC_SAVE_AVATORS_BASE_PATH[] = "/system/save/8000000000000010/su/avators/";
37 39
38UUID UUID::Generate() {
39 std::random_device device;
40 std::mt19937 gen(device());
41 std::uniform_int_distribution<u64> distribution(1, std::numeric_limits<u64>::max());
42 return UUID{distribution(gen), distribution(gen)};
43}
44
45std::string UUID::Format() const {
46 return fmt::format("0x{:016X}{:016X}", uuid[1], uuid[0]);
47}
48
49std::string UUID::FormatSwitch() const {
50 std::array<u8, 16> s{};
51 std::memcpy(s.data(), uuid.data(), sizeof(u128));
52 return fmt::format("{:02x}{:02x}{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{"
53 ":02x}{:02x}{:02x}{:02x}{:02x}",
54 s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11],
55 s[12], s[13], s[14], s[15]);
56}
57
58ProfileManager::ProfileManager() { 40ProfileManager::ProfileManager() {
59 ParseUserSaveFile(); 41 ParseUserSaveFile();
60 42
@@ -217,7 +199,7 @@ bool ProfileManager::UserExists(UUID uuid) const {
217bool ProfileManager::UserExistsIndex(std::size_t index) const { 199bool ProfileManager::UserExistsIndex(std::size_t index) const {
218 if (index >= MAX_USERS) 200 if (index >= MAX_USERS)
219 return false; 201 return false;
220 return profiles[index].user_uuid.uuid != INVALID_UUID; 202 return profiles[index].user_uuid.uuid != Common::INVALID_UUID;
221} 203}
222 204
223/// Opens a specific user 205/// Opens a specific user
@@ -311,7 +293,7 @@ bool ProfileManager::RemoveUser(UUID uuid) {
311 293
312bool ProfileManager::SetProfileBase(UUID uuid, const ProfileBase& profile_new) { 294bool ProfileManager::SetProfileBase(UUID uuid, const ProfileBase& profile_new) {
313 const auto index = GetUserIndex(uuid); 295 const auto index = GetUserIndex(uuid);
314 if (!index || profile_new.user_uuid == UUID(INVALID_UUID)) { 296 if (!index || profile_new.user_uuid == UUID(Common::INVALID_UUID)) {
315 return false; 297 return false;
316 } 298 }
317 299
@@ -342,7 +324,7 @@ void ProfileManager::ParseUserSaveFile() {
342 } 324 }
343 325
344 for (const auto& user : data.users) { 326 for (const auto& user : data.users) {
345 if (user.uuid == UUID(INVALID_UUID)) { 327 if (user.uuid == UUID(Common::INVALID_UUID)) {
346 continue; 328 continue;
347 } 329 }
348 330
diff --git a/src/core/hle/service/acc/profile_manager.h b/src/core/hle/service/acc/profile_manager.h
index c4ce2e0b3..fd7abb541 100644
--- a/src/core/hle/service/acc/profile_manager.h
+++ b/src/core/hle/service/acc/profile_manager.h
@@ -9,47 +9,15 @@
9 9
10#include "common/common_types.h" 10#include "common/common_types.h"
11#include "common/swap.h" 11#include "common/swap.h"
12#include "common/uuid.h"
12#include "core/hle/result.h" 13#include "core/hle/result.h"
13 14
14namespace Service::Account { 15namespace Service::Account {
15constexpr std::size_t MAX_USERS = 8; 16constexpr std::size_t MAX_USERS = 8;
16constexpr u128 INVALID_UUID{{0, 0}};
17
18struct UUID {
19 // UUIDs which are 0 are considered invalid!
20 u128 uuid = INVALID_UUID;
21 UUID() = default;
22 explicit UUID(const u128& id) : uuid{id} {}
23 explicit UUID(const u64 lo, const u64 hi) : uuid{{lo, hi}} {}
24
25 explicit operator bool() const {
26 return uuid != INVALID_UUID;
27 }
28
29 bool operator==(const UUID& rhs) const {
30 return uuid == rhs.uuid;
31 }
32
33 bool operator!=(const UUID& rhs) const {
34 return !operator==(rhs);
35 }
36
37 // TODO(ogniK): Properly generate uuids based on RFC-4122
38 static UUID Generate();
39
40 // Set the UUID to {0,0} to be considered an invalid user
41 void Invalidate() {
42 uuid = INVALID_UUID;
43 }
44
45 std::string Format() const;
46 std::string FormatSwitch() const;
47};
48static_assert(sizeof(UUID) == 16, "UUID is an invalid size!");
49 17
50constexpr std::size_t profile_username_size = 32; 18constexpr std::size_t profile_username_size = 32;
51using ProfileUsername = std::array<u8, profile_username_size>; 19using ProfileUsername = std::array<u8, profile_username_size>;
52using UserIDArray = std::array<UUID, MAX_USERS>; 20using UserIDArray = std::array<Common::UUID, MAX_USERS>;
53 21
54/// Contains extra data related to a user. 22/// Contains extra data related to a user.
55/// TODO: RE this structure 23/// TODO: RE this structure
@@ -66,7 +34,7 @@ static_assert(sizeof(ProfileData) == 0x80, "ProfileData structure has incorrect
66/// This holds general information about a users profile. This is where we store all the information 34/// This holds general information about a users profile. This is where we store all the information
67/// based on a specific user 35/// based on a specific user
68struct ProfileInfo { 36struct ProfileInfo {
69 UUID user_uuid; 37 Common::UUID user_uuid;
70 ProfileUsername username; 38 ProfileUsername username;
71 u64 creation_time; 39 u64 creation_time;
72 ProfileData data; // TODO(ognik): Work out what this is 40 ProfileData data; // TODO(ognik): Work out what this is
@@ -74,7 +42,7 @@ struct ProfileInfo {
74}; 42};
75 43
76struct ProfileBase { 44struct ProfileBase {
77 UUID user_uuid; 45 Common::UUID user_uuid;
78 u64_le timestamp; 46 u64_le timestamp;
79 ProfileUsername username; 47 ProfileUsername username;
80 48
@@ -96,33 +64,33 @@ public:
96 ~ProfileManager(); 64 ~ProfileManager();
97 65
98 ResultCode AddUser(const ProfileInfo& user); 66 ResultCode AddUser(const ProfileInfo& user);
99 ResultCode CreateNewUser(UUID uuid, const ProfileUsername& username); 67 ResultCode CreateNewUser(Common::UUID uuid, const ProfileUsername& username);
100 ResultCode CreateNewUser(UUID uuid, const std::string& username); 68 ResultCode CreateNewUser(Common::UUID uuid, const std::string& username);
101 std::optional<UUID> GetUser(std::size_t index) const; 69 std::optional<Common::UUID> GetUser(std::size_t index) const;
102 std::optional<std::size_t> GetUserIndex(const UUID& uuid) const; 70 std::optional<std::size_t> GetUserIndex(const Common::UUID& uuid) const;
103 std::optional<std::size_t> GetUserIndex(const ProfileInfo& user) const; 71 std::optional<std::size_t> GetUserIndex(const ProfileInfo& user) const;
104 bool GetProfileBase(std::optional<std::size_t> index, ProfileBase& profile) const; 72 bool GetProfileBase(std::optional<std::size_t> index, ProfileBase& profile) const;
105 bool GetProfileBase(UUID uuid, ProfileBase& profile) const; 73 bool GetProfileBase(Common::UUID uuid, ProfileBase& profile) const;
106 bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const; 74 bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const;
107 bool GetProfileBaseAndData(std::optional<std::size_t> index, ProfileBase& profile, 75 bool GetProfileBaseAndData(std::optional<std::size_t> index, ProfileBase& profile,
108 ProfileData& data) const; 76 ProfileData& data) const;
109 bool GetProfileBaseAndData(UUID uuid, ProfileBase& profile, ProfileData& data) const; 77 bool GetProfileBaseAndData(Common::UUID uuid, ProfileBase& profile, ProfileData& data) const;
110 bool GetProfileBaseAndData(const ProfileInfo& user, ProfileBase& profile, 78 bool GetProfileBaseAndData(const ProfileInfo& user, ProfileBase& profile,
111 ProfileData& data) const; 79 ProfileData& data) const;
112 std::size_t GetUserCount() const; 80 std::size_t GetUserCount() const;
113 std::size_t GetOpenUserCount() const; 81 std::size_t GetOpenUserCount() const;
114 bool UserExists(UUID uuid) const; 82 bool UserExists(Common::UUID uuid) const;
115 bool UserExistsIndex(std::size_t index) const; 83 bool UserExistsIndex(std::size_t index) const;
116 void OpenUser(UUID uuid); 84 void OpenUser(Common::UUID uuid);
117 void CloseUser(UUID uuid); 85 void CloseUser(Common::UUID uuid);
118 UserIDArray GetOpenUsers() const; 86 UserIDArray GetOpenUsers() const;
119 UserIDArray GetAllUsers() const; 87 UserIDArray GetAllUsers() const;
120 UUID GetLastOpenedUser() const; 88 Common::UUID GetLastOpenedUser() const;
121 89
122 bool CanSystemRegisterUser() const; 90 bool CanSystemRegisterUser() const;
123 91
124 bool RemoveUser(UUID uuid); 92 bool RemoveUser(Common::UUID uuid);
125 bool SetProfileBase(UUID uuid, const ProfileBase& profile_new); 93 bool SetProfileBase(Common::UUID uuid, const ProfileBase& profile_new);
126 94
127private: 95private:
128 void ParseUserSaveFile(); 96 void ParseUserSaveFile();
@@ -132,7 +100,7 @@ private:
132 100
133 std::array<ProfileInfo, MAX_USERS> profiles{}; 101 std::array<ProfileInfo, MAX_USERS> profiles{};
134 std::size_t user_count = 0; 102 std::size_t user_count = 0;
135 UUID last_opened_user{INVALID_UUID}; 103 Common::UUID last_opened_user{Common::INVALID_UUID};
136}; 104};
137 105
138}; // namespace Service::Account 106}; // namespace Service::Account
diff --git a/src/core/hle/service/am/applets/profile_select.cpp b/src/core/hle/service/am/applets/profile_select.cpp
index d113bd2eb..57b5419e8 100644
--- a/src/core/hle/service/am/applets/profile_select.cpp
+++ b/src/core/hle/service/am/applets/profile_select.cpp
@@ -53,19 +53,19 @@ void ProfileSelect::Execute() {
53 return; 53 return;
54 } 54 }
55 55
56 frontend.SelectProfile([this](std::optional<Account::UUID> uuid) { SelectionComplete(uuid); }); 56 frontend.SelectProfile([this](std::optional<Common::UUID> uuid) { SelectionComplete(uuid); });
57} 57}
58 58
59void ProfileSelect::SelectionComplete(std::optional<Account::UUID> uuid) { 59void ProfileSelect::SelectionComplete(std::optional<Common::UUID> uuid) {
60 UserSelectionOutput output{}; 60 UserSelectionOutput output{};
61 61
62 if (uuid.has_value() && uuid->uuid != Account::INVALID_UUID) { 62 if (uuid.has_value() && uuid->uuid != Common::INVALID_UUID) {
63 output.result = 0; 63 output.result = 0;
64 output.uuid_selected = uuid->uuid; 64 output.uuid_selected = uuid->uuid;
65 } else { 65 } else {
66 status = ERR_USER_CANCELLED_SELECTION; 66 status = ERR_USER_CANCELLED_SELECTION;
67 output.result = ERR_USER_CANCELLED_SELECTION.raw; 67 output.result = ERR_USER_CANCELLED_SELECTION.raw;
68 output.uuid_selected = Account::INVALID_UUID; 68 output.uuid_selected = Common::INVALID_UUID;
69 } 69 }
70 70
71 final_data = std::vector<u8>(sizeof(UserSelectionOutput)); 71 final_data = std::vector<u8>(sizeof(UserSelectionOutput));
diff --git a/src/core/hle/service/am/applets/profile_select.h b/src/core/hle/service/am/applets/profile_select.h
index a2ac6cf50..563cd744a 100644
--- a/src/core/hle/service/am/applets/profile_select.h
+++ b/src/core/hle/service/am/applets/profile_select.h
@@ -7,7 +7,8 @@
7#include <vector> 7#include <vector>
8 8
9#include "common/common_funcs.h" 9#include "common/common_funcs.h"
10#include "core/hle/service/acc/profile_manager.h" 10#include "common/uuid.h"
11#include "core/hle/result.h"
11#include "core/hle/service/am/applets/applets.h" 12#include "core/hle/service/am/applets/applets.h"
12 13
13namespace Service::AM::Applets { 14namespace Service::AM::Applets {
@@ -38,7 +39,7 @@ public:
38 void ExecuteInteractive() override; 39 void ExecuteInteractive() override;
39 void Execute() override; 40 void Execute() override;
40 41
41 void SelectionComplete(std::optional<Account::UUID> uuid); 42 void SelectionComplete(std::optional<Common::UUID> uuid);
42 43
43private: 44private:
44 const Core::Frontend::ProfileSelectApplet& frontend; 45 const Core::Frontend::ProfileSelectApplet& frontend;
diff --git a/src/core/hle/service/mii/mii.cpp b/src/core/hle/service/mii/mii.cpp
index a6197124a..ce84e25ed 100644
--- a/src/core/hle/service/mii/mii.cpp
+++ b/src/core/hle/service/mii/mii.cpp
@@ -4,42 +4,50 @@
4 4
5#include <memory> 5#include <memory>
6 6
7#include <fmt/ostream.h>
8
7#include "common/logging/log.h" 9#include "common/logging/log.h"
10#include "common/string_util.h"
8#include "core/hle/ipc_helpers.h" 11#include "core/hle/ipc_helpers.h"
9#include "core/hle/kernel/hle_ipc.h" 12#include "core/hle/kernel/hle_ipc.h"
10#include "core/hle/service/mii/mii.h" 13#include "core/hle/service/mii/mii.h"
14#include "core/hle/service/mii/mii_manager.h"
11#include "core/hle/service/service.h" 15#include "core/hle/service/service.h"
12#include "core/hle/service/sm/sm.h" 16#include "core/hle/service/sm/sm.h"
13 17
14namespace Service::Mii { 18namespace Service::Mii {
15 19
20constexpr ResultCode ERROR_INVALID_ARGUMENT{ErrorModule::Mii, 1};
21constexpr ResultCode ERROR_CANNOT_FIND_ENTRY{ErrorModule::Mii, 4};
22constexpr ResultCode ERROR_NOT_IN_TEST_MODE{ErrorModule::Mii, 99};
23
16class IDatabaseService final : public ServiceFramework<IDatabaseService> { 24class IDatabaseService final : public ServiceFramework<IDatabaseService> {
17public: 25public:
18 explicit IDatabaseService() : ServiceFramework{"IDatabaseService"} { 26 explicit IDatabaseService() : ServiceFramework{"IDatabaseService"} {
19 // clang-format off 27 // clang-format off
20 static const FunctionInfo functions[] = { 28 static const FunctionInfo functions[] = {
21 {0, nullptr, "IsUpdated"}, 29 {0, &IDatabaseService::IsUpdated, "IsUpdated"},
22 {1, nullptr, "IsFullDatabase"}, 30 {1, &IDatabaseService::IsFullDatabase, "IsFullDatabase"},
23 {2, nullptr, "GetCount"}, 31 {2, &IDatabaseService::GetCount, "GetCount"},
24 {3, nullptr, "Get"}, 32 {3, &IDatabaseService::Get, "Get"},
25 {4, nullptr, "Get1"}, 33 {4, &IDatabaseService::Get1, "Get1"},
26 {5, nullptr, "UpdateLatest"}, 34 {5, nullptr, "UpdateLatest"},
27 {6, nullptr, "BuildRandom"}, 35 {6, &IDatabaseService::BuildRandom, "BuildRandom"},
28 {7, nullptr, "BuildDefault"}, 36 {7, &IDatabaseService::BuildDefault, "BuildDefault"},
29 {8, nullptr, "Get2"}, 37 {8, &IDatabaseService::Get2, "Get2"},
30 {9, nullptr, "Get3"}, 38 {9, &IDatabaseService::Get3, "Get3"},
31 {10, nullptr, "UpdateLatest1"}, 39 {10, nullptr, "UpdateLatest1"},
32 {11, nullptr, "FindIndex"}, 40 {11, &IDatabaseService::FindIndex, "FindIndex"},
33 {12, nullptr, "Move"}, 41 {12, &IDatabaseService::Move, "Move"},
34 {13, nullptr, "AddOrReplace"}, 42 {13, &IDatabaseService::AddOrReplace, "AddOrReplace"},
35 {14, nullptr, "Delete"}, 43 {14, &IDatabaseService::Delete, "Delete"},
36 {15, nullptr, "DestroyFile"}, 44 {15, &IDatabaseService::DestroyFile, "DestroyFile"},
37 {16, nullptr, "DeleteFile"}, 45 {16, &IDatabaseService::DeleteFile, "DeleteFile"},
38 {17, nullptr, "Format"}, 46 {17, &IDatabaseService::Format, "Format"},
39 {18, nullptr, "Import"}, 47 {18, nullptr, "Import"},
40 {19, nullptr, "Export"}, 48 {19, nullptr, "Export"},
41 {20, nullptr, "IsBrokenDatabaseWithClearFlag"}, 49 {20, nullptr, "IsBrokenDatabaseWithClearFlag"},
42 {21, nullptr, "GetIndex"}, 50 {21, &IDatabaseService::GetIndex, "GetIndex"},
43 {22, nullptr, "SetInterfaceVersion"}, 51 {22, nullptr, "SetInterfaceVersion"},
44 {23, nullptr, "Convert"}, 52 {23, nullptr, "Convert"},
45 }; 53 };
@@ -47,6 +55,305 @@ public:
47 55
48 RegisterHandlers(functions); 56 RegisterHandlers(functions);
49 } 57 }
58
59private:
60 template <typename OutType>
61 std::vector<u8> SerializeArray(OutType (MiiManager::*getter)(u32) const, u32 offset,
62 u32 requested_size, u32& read_size) {
63 read_size = std::min(requested_size, db.Size() - offset);
64
65 std::vector<u8> out(read_size * sizeof(OutType));
66
67 for (u32 i = 0; i < read_size; ++i) {
68 const auto obj = (db.*getter)(offset + i);
69 std::memcpy(out.data() + i * sizeof(OutType), &obj, sizeof(OutType));
70 }
71
72 return out;
73 }
74
75 void IsUpdated(Kernel::HLERequestContext& ctx) {
76 IPC::RequestParser rp{ctx};
77 const auto source{rp.PopRaw<Source>()};
78
79 LOG_DEBUG(Service_Mii, "called with source={}", source);
80
81 IPC::ResponseBuilder rb{ctx, 3};
82 rb.Push(RESULT_SUCCESS);
83 rb.Push(db.CheckUpdatedFlag());
84 db.ResetUpdatedFlag();
85 }
86
87 void IsFullDatabase(Kernel::HLERequestContext& ctx) {
88 LOG_DEBUG(Service_Mii, "called");
89
90 IPC::ResponseBuilder rb{ctx, 3};
91 rb.Push(RESULT_SUCCESS);
92 rb.Push(db.Full());
93 }
94
95 void GetCount(Kernel::HLERequestContext& ctx) {
96 IPC::RequestParser rp{ctx};
97 const auto source{rp.PopRaw<Source>()};
98
99 LOG_DEBUG(Service_Mii, "called with source={}", source);
100
101 IPC::ResponseBuilder rb{ctx, 3};
102 rb.Push(RESULT_SUCCESS);
103 rb.Push<u32>(db.Size());
104 }
105
106 // Gets Miis from database at offset and index in format MiiInfoElement
107 void Get(Kernel::HLERequestContext& ctx) {
108 IPC::RequestParser rp{ctx};
109 const auto size{rp.PopRaw<u32>()};
110 const auto source{rp.PopRaw<Source>()};
111
112 LOG_DEBUG(Service_Mii, "called with size={:08X}, offset={:08X}, source={}", size,
113 offsets[0], source);
114
115 u32 read_size{};
116 ctx.WriteBuffer(SerializeArray(&MiiManager::GetInfoElement, offsets[0], size, read_size));
117 offsets[0] += read_size;
118
119 IPC::ResponseBuilder rb{ctx, 3};
120 rb.Push(RESULT_SUCCESS);
121 rb.Push<u32>(read_size);
122 }
123
124 // Gets Miis from database at offset and index in format MiiInfo
125 void Get1(Kernel::HLERequestContext& ctx) {
126 IPC::RequestParser rp{ctx};
127 const auto size{rp.PopRaw<u32>()};
128 const auto source{rp.PopRaw<Source>()};
129
130 LOG_DEBUG(Service_Mii, "called with size={:08X}, offset={:08X}, source={}", size,
131 offsets[1], source);
132
133 u32 read_size{};
134 ctx.WriteBuffer(SerializeArray(&MiiManager::GetInfo, offsets[1], size, read_size));
135 offsets[1] += read_size;
136
137 IPC::ResponseBuilder rb{ctx, 3};
138 rb.Push(RESULT_SUCCESS);
139 rb.Push<u32>(read_size);
140 }
141
142 void BuildRandom(Kernel::HLERequestContext& ctx) {
143 IPC::RequestParser rp{ctx};
144 const auto [unknown1, unknown2, unknown3] = rp.PopRaw<RandomParameters>();
145
146 if (unknown1 > 3) {
147 IPC::ResponseBuilder rb{ctx, 2};
148 rb.Push(ERROR_INVALID_ARGUMENT);
149 LOG_ERROR(Service_Mii, "Invalid unknown1 value: {}", unknown1);
150 return;
151 }
152
153 if (unknown2 > 2) {
154 IPC::ResponseBuilder rb{ctx, 2};
155 rb.Push(ERROR_INVALID_ARGUMENT);
156 LOG_ERROR(Service_Mii, "Invalid unknown2 value: {}", unknown2);
157 return;
158 }
159
160 if (unknown3 > 3) {
161 IPC::ResponseBuilder rb{ctx, 2};
162 rb.Push(ERROR_INVALID_ARGUMENT);
163 LOG_ERROR(Service_Mii, "Invalid unknown3 value: {}", unknown3);
164 return;
165 }
166
167 LOG_DEBUG(Service_Mii, "called with param_1={:08X}, param_2={:08X}, param_3={:08X}",
168 unknown1, unknown2, unknown3);
169
170 const auto info = db.CreateRandom({unknown1, unknown2, unknown3});
171 IPC::ResponseBuilder rb{ctx, 2 + sizeof(MiiInfo) / sizeof(u32)};
172 rb.Push(RESULT_SUCCESS);
173 rb.PushRaw<MiiInfo>(info);
174 }
175
176 void BuildDefault(Kernel::HLERequestContext& ctx) {
177 IPC::RequestParser rp{ctx};
178 const auto index{rp.PopRaw<u32>()};
179
180 if (index > 5) {
181 LOG_ERROR(Service_Mii, "invalid argument, index cannot be greater than 5 but is {:08X}",
182 index);
183 IPC::ResponseBuilder rb{ctx, 2};
184 rb.Push(ERROR_INVALID_ARGUMENT);
185 return;
186 }
187
188 LOG_DEBUG(Service_Mii, "called with index={:08X}", index);
189
190 const auto info = db.CreateDefault(index);
191 IPC::ResponseBuilder rb{ctx, 2 + sizeof(MiiInfo) / sizeof(u32)};
192 rb.Push(RESULT_SUCCESS);
193 rb.PushRaw<MiiInfo>(info);
194 }
195
196 // Gets Miis from database at offset and index in format MiiStoreDataElement
197 void Get2(Kernel::HLERequestContext& ctx) {
198 IPC::RequestParser rp{ctx};
199 const auto size{rp.PopRaw<u32>()};
200 const auto source{rp.PopRaw<Source>()};
201
202 LOG_DEBUG(Service_Mii, "called with size={:08X}, offset={:08X}, source={}", size,
203 offsets[2], source);
204
205 u32 read_size{};
206 ctx.WriteBuffer(
207 SerializeArray(&MiiManager::GetStoreDataElement, offsets[2], size, read_size));
208 offsets[2] += read_size;
209
210 IPC::ResponseBuilder rb{ctx, 3};
211 rb.Push(RESULT_SUCCESS);
212 rb.Push<u32>(read_size);
213 }
214
215 // Gets Miis from database at offset and index in format MiiStoreData
216 void Get3(Kernel::HLERequestContext& ctx) {
217 IPC::RequestParser rp{ctx};
218 const auto size{rp.PopRaw<u32>()};
219 const auto source{rp.PopRaw<Source>()};
220
221 LOG_DEBUG(Service_Mii, "called with size={:08X}, offset={:08X}, source={}", size,
222 offsets[3], source);
223
224 u32 read_size{};
225 ctx.WriteBuffer(SerializeArray(&MiiManager::GetStoreData, offsets[3], size, read_size));
226 offsets[3] += read_size;
227
228 IPC::ResponseBuilder rb{ctx, 3};
229 rb.Push(RESULT_SUCCESS);
230 rb.Push<u32>(read_size);
231 }
232
233 void FindIndex(Kernel::HLERequestContext& ctx) {
234 IPC::RequestParser rp{ctx};
235 const auto uuid{rp.PopRaw<Common::UUID>()};
236 const auto unknown{rp.PopRaw<bool>()};
237
238 LOG_DEBUG(Service_Mii, "called with uuid={}, unknown={}", uuid.FormatSwitch(), unknown);
239
240 IPC::ResponseBuilder rb{ctx, 3};
241
242 const auto index = db.IndexOf(uuid);
243 if (index > MAX_MIIS) {
244 // TODO(DarkLordZach): Find a better error code
245 rb.Push(ResultCode(-1));
246 rb.Push(index);
247 } else {
248 rb.Push(RESULT_SUCCESS);
249 rb.Push(index);
250 }
251 }
252
253 void Move(Kernel::HLERequestContext& ctx) {
254 IPC::RequestParser rp{ctx};
255 const auto uuid{rp.PopRaw<Common::UUID>()};
256 const auto index{rp.PopRaw<s32>()};
257
258 if (index < 0) {
259 LOG_ERROR(Service_Mii, "Index cannot be negative but is {:08X}!", index);
260 IPC::ResponseBuilder rb{ctx, 2};
261 rb.Push(ERROR_INVALID_ARGUMENT);
262 return;
263 }
264
265 LOG_DEBUG(Service_Mii, "called with uuid={}, index={:08X}", uuid.FormatSwitch(), index);
266
267 const auto success = db.Move(uuid, index);
268
269 IPC::ResponseBuilder rb{ctx, 2};
270 // TODO(DarkLordZach): Find a better error code
271 rb.Push(success ? RESULT_SUCCESS : ResultCode(-1));
272 }
273
274 void AddOrReplace(Kernel::HLERequestContext& ctx) {
275 IPC::RequestParser rp{ctx};
276 const auto data{rp.PopRaw<MiiStoreData>()};
277
278 LOG_DEBUG(Service_Mii, "called with Mii data uuid={}, name={}", data.uuid.FormatSwitch(),
279 Common::UTF16ToUTF8(data.Name()));
280
281 const auto success = db.AddOrReplace(data);
282
283 IPC::ResponseBuilder rb{ctx, 2};
284 // TODO(DarkLordZach): Find a better error code
285 rb.Push(success ? RESULT_SUCCESS : ResultCode(-1));
286 }
287
288 void Delete(Kernel::HLERequestContext& ctx) {
289 IPC::RequestParser rp{ctx};
290 const auto uuid{rp.PopRaw<Common::UUID>()};
291
292 LOG_DEBUG(Service_Mii, "called with uuid={}", uuid.FormatSwitch());
293
294 const auto success = db.Remove(uuid);
295
296 IPC::ResponseBuilder rb{ctx, 2};
297 rb.Push(success ? RESULT_SUCCESS : ERROR_CANNOT_FIND_ENTRY);
298 }
299
300 void DestroyFile(Kernel::HLERequestContext& ctx) {
301 LOG_DEBUG(Service_Mii, "called");
302
303 if (!db.IsTestModeEnabled()) {
304 LOG_ERROR(Service_Mii, "Database is not in test mode -- cannot destory database file.");
305 IPC::ResponseBuilder rb{ctx, 2};
306 rb.Push(ERROR_NOT_IN_TEST_MODE);
307 return;
308 }
309
310 IPC::ResponseBuilder rb{ctx, 3};
311 rb.Push(RESULT_SUCCESS);
312 rb.Push(db.DestroyFile());
313 }
314
315 void DeleteFile(Kernel::HLERequestContext& ctx) {
316 LOG_DEBUG(Service_Mii, "called");
317
318 if (!db.IsTestModeEnabled()) {
319 LOG_ERROR(Service_Mii, "Database is not in test mode -- cannot delete database file.");
320 IPC::ResponseBuilder rb{ctx, 2};
321 rb.Push(ERROR_NOT_IN_TEST_MODE);
322 return;
323 }
324
325 IPC::ResponseBuilder rb{ctx, 3};
326 rb.Push(RESULT_SUCCESS);
327 rb.Push(db.DeleteFile());
328 }
329
330 void Format(Kernel::HLERequestContext& ctx) {
331 LOG_DEBUG(Service_Mii, "called");
332
333 db.Clear();
334
335 IPC::ResponseBuilder rb{ctx, 2};
336 rb.Push(RESULT_SUCCESS);
337 }
338
339 void GetIndex(Kernel::HLERequestContext& ctx) {
340 IPC::RequestParser rp{ctx};
341 const auto info{rp.PopRaw<MiiInfo>()};
342
343 LOG_DEBUG(Service_Mii, "called with Mii info uuid={}, name={}", info.uuid.FormatSwitch(),
344 Common::UTF16ToUTF8(info.Name()));
345
346 const auto index = db.IndexOf(info);
347
348 IPC::ResponseBuilder rb{ctx, 2};
349 rb.Push(RESULT_SUCCESS);
350 rb.Push(index);
351 }
352
353 MiiManager db;
354
355 // Last read offsets of Get functions
356 std::array<u32, 4> offsets{};
50}; 357};
51 358
52class MiiDBModule final : public ServiceFramework<MiiDBModule> { 359class MiiDBModule final : public ServiceFramework<MiiDBModule> {
diff --git a/src/core/hle/service/mii/mii_manager.cpp b/src/core/hle/service/mii/mii_manager.cpp
new file mode 100644
index 000000000..131b01d62
--- /dev/null
+++ b/src/core/hle/service/mii/mii_manager.cpp
@@ -0,0 +1,416 @@
1// Copyright 2018 yuzu emulator team
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <algorithm>
6#include <cstring>
7#include "common/assert.h"
8#include "common/file_util.h"
9#include "common/logging/log.h"
10#include "common/string_util.h"
11#include "core/hle/service/mii/mii_manager.h"
12
13namespace Service::Mii {
14
15namespace {
16
17constexpr char MII_SAVE_DATABASE_PATH[] = "/system/save/8000000000000030/MiiDatabase.dat";
18constexpr std::array<char16_t, 11> DEFAULT_MII_NAME = {u'y', u'u', u'z', u'u', u'\0'};
19
20// This value was retrieved from HW test
21constexpr MiiStoreData DEFAULT_MII = {
22 {
23 0x21, 0x40, 0x40, 0x01, 0x08, 0x01, 0x13, 0x08, 0x08, 0x02, 0x17, 0x8C, 0x06, 0x01,
24 0x69, 0x6D, 0x8A, 0x6A, 0x82, 0x14, 0x00, 0x00, 0x00, 0x20, 0x64, 0x72, 0x44, 0x44,
25 },
26 {'y', 'u', 'z', 'u', '\0'},
27 Common::UUID{1, 0},
28 0,
29 0,
30};
31
32// Default values taken from multiple real databases
33const MiiDatabase DEFAULT_MII_DATABASE{Common::MakeMagic('N', 'F', 'D', 'B'), {}, {1}, 0, 0};
34
35constexpr std::array<const char*, 4> SOURCE_NAMES{
36 "Database",
37 "Default",
38 "Account",
39 "Friend",
40};
41
42template <typename T, std::size_t SourceArraySize, std::size_t DestArraySize>
43std::array<T, DestArraySize> ResizeArray(const std::array<T, SourceArraySize>& in) {
44 std::array<T, DestArraySize> out{};
45 std::memcpy(out.data(), in.data(), sizeof(T) * std::min(SourceArraySize, DestArraySize));
46 return out;
47}
48
49MiiInfo ConvertStoreDataToInfo(const MiiStoreData& data) {
50 MiiStoreBitFields bf{};
51 std::memcpy(&bf, data.data.data(), sizeof(MiiStoreBitFields));
52 return {
53 data.uuid,
54 ResizeArray<char16_t, 10, 11>(data.name),
55 static_cast<u8>(bf.font_region.Value()),
56 static_cast<u8>(bf.favorite_color.Value()),
57 static_cast<u8>(bf.gender.Value()),
58 static_cast<u8>(bf.height.Value()),
59 static_cast<u8>(bf.weight.Value()),
60 static_cast<u8>(bf.mii_type.Value()),
61 static_cast<u8>(bf.mii_region.Value()),
62 static_cast<u8>(bf.face_type.Value()),
63 static_cast<u8>(bf.face_color.Value()),
64 static_cast<u8>(bf.face_wrinkle.Value()),
65 static_cast<u8>(bf.face_makeup.Value()),
66 static_cast<u8>(bf.hair_type.Value()),
67 static_cast<u8>(bf.hair_color.Value()),
68 static_cast<bool>(bf.hair_flip.Value()),
69 static_cast<u8>(bf.eye_type.Value()),
70 static_cast<u8>(bf.eye_color.Value()),
71 static_cast<u8>(bf.eye_scale.Value()),
72 static_cast<u8>(bf.eye_aspect.Value()),
73 static_cast<u8>(bf.eye_rotate.Value()),
74 static_cast<u8>(bf.eye_x.Value()),
75 static_cast<u8>(bf.eye_y.Value()),
76 static_cast<u8>(bf.eyebrow_type.Value()),
77 static_cast<u8>(bf.eyebrow_color.Value()),
78 static_cast<u8>(bf.eyebrow_scale.Value()),
79 static_cast<u8>(bf.eyebrow_aspect.Value()),
80 static_cast<u8>(bf.eyebrow_rotate.Value()),
81 static_cast<u8>(bf.eyebrow_x.Value()),
82 static_cast<u8>(bf.eyebrow_y.Value()),
83 static_cast<u8>(bf.nose_type.Value()),
84 static_cast<u8>(bf.nose_scale.Value()),
85 static_cast<u8>(bf.nose_y.Value()),
86 static_cast<u8>(bf.mouth_type.Value()),
87 static_cast<u8>(bf.mouth_color.Value()),
88 static_cast<u8>(bf.mouth_scale.Value()),
89 static_cast<u8>(bf.mouth_aspect.Value()),
90 static_cast<u8>(bf.mouth_y.Value()),
91 static_cast<u8>(bf.facial_hair_color.Value()),
92 static_cast<u8>(bf.beard_type.Value()),
93 static_cast<u8>(bf.mustache_type.Value()),
94 static_cast<u8>(bf.mustache_scale.Value()),
95 static_cast<u8>(bf.mustache_y.Value()),
96 static_cast<u8>(bf.glasses_type.Value()),
97 static_cast<u8>(bf.glasses_color.Value()),
98 static_cast<u8>(bf.glasses_scale.Value()),
99 static_cast<u8>(bf.glasses_y.Value()),
100 static_cast<u8>(bf.mole_type.Value()),
101 static_cast<u8>(bf.mole_scale.Value()),
102 static_cast<u8>(bf.mole_x.Value()),
103 static_cast<u8>(bf.mole_y.Value()),
104 0x00,
105 };
106}
107MiiStoreData ConvertInfoToStoreData(const MiiInfo& info) {
108 MiiStoreData out{};
109 out.name = ResizeArray<char16_t, 11, 10>(info.name);
110 out.uuid = info.uuid;
111
112 MiiStoreBitFields bf{};
113
114 bf.hair_type.Assign(info.hair_type);
115 bf.mole_type.Assign(info.mole_type);
116 bf.height.Assign(info.height);
117 bf.hair_flip.Assign(info.hair_flip);
118 bf.weight.Assign(info.weight);
119 bf.hair_color.Assign(info.hair_color);
120
121 bf.gender.Assign(info.gender);
122 bf.eye_color.Assign(info.eye_color);
123 bf.eyebrow_color.Assign(info.eyebrow_color);
124 bf.mouth_color.Assign(info.mouth_color);
125 bf.facial_hair_color.Assign(info.facial_hair_color);
126
127 bf.mii_type.Assign(info.mii_type);
128 bf.glasses_color.Assign(info.glasses_color);
129 bf.font_region.Assign(info.font_region);
130 bf.eye_type.Assign(info.eye_type);
131 bf.mii_region.Assign(info.mii_region);
132 bf.mouth_type.Assign(info.mouth_type);
133 bf.glasses_scale.Assign(info.glasses_scale);
134 bf.eye_y.Assign(info.eye_y);
135
136 bf.mustache_type.Assign(info.mustache_type);
137 bf.eyebrow_type.Assign(info.eyebrow_type);
138 bf.beard_type.Assign(info.beard_type);
139 bf.nose_type.Assign(info.nose_type);
140 bf.mouth_aspect.Assign(info.mouth_aspect_ratio);
141 bf.nose_y.Assign(info.nose_y);
142 bf.eyebrow_aspect.Assign(info.eyebrow_aspect_ratio);
143 bf.mouth_y.Assign(info.mouth_y);
144
145 bf.eye_rotate.Assign(info.eye_rotate);
146 bf.mustache_y.Assign(info.mustache_y);
147 bf.eye_aspect.Assign(info.eye_aspect_ratio);
148 bf.glasses_y.Assign(info.glasses_y);
149 bf.eye_scale.Assign(info.eye_scale);
150 bf.mole_x.Assign(info.mole_x);
151 bf.mole_y.Assign(info.mole_y);
152
153 bf.glasses_type.Assign(info.glasses_type);
154 bf.face_type.Assign(info.face_type);
155 bf.favorite_color.Assign(info.favorite_color);
156 bf.face_wrinkle.Assign(info.face_wrinkle);
157 bf.face_color.Assign(info.face_color);
158 bf.eye_x.Assign(info.eye_x);
159 bf.face_makeup.Assign(info.face_makeup);
160
161 bf.eyebrow_rotate.Assign(info.eyebrow_rotate);
162 bf.eyebrow_scale.Assign(info.eyebrow_scale);
163 bf.eyebrow_y.Assign(info.eyebrow_y);
164 bf.eyebrow_x.Assign(info.eyebrow_x);
165 bf.mouth_scale.Assign(info.mouth_scale);
166 bf.nose_scale.Assign(info.nose_scale);
167 bf.mole_scale.Assign(info.mole_scale);
168 bf.mustache_scale.Assign(info.mustache_scale);
169
170 std::memcpy(out.data.data(), &bf, sizeof(MiiStoreBitFields));
171
172 return out;
173}
174
175} // namespace
176
177std::ostream& operator<<(std::ostream& os, Source source) {
178 os << SOURCE_NAMES.at(static_cast<std::size_t>(source));
179 return os;
180}
181
182std::u16string MiiInfo::Name() const {
183 return Common::UTF16StringFromFixedZeroTerminatedBuffer(name.data(), name.size());
184}
185
186bool operator==(const MiiInfo& lhs, const MiiInfo& rhs) {
187 return std::memcmp(&lhs, &rhs, sizeof(MiiInfo)) == 0;
188}
189
190bool operator!=(const MiiInfo& lhs, const MiiInfo& rhs) {
191 return !operator==(lhs, rhs);
192}
193
194std::u16string MiiStoreData::Name() const {
195 return Common::UTF16StringFromFixedZeroTerminatedBuffer(name.data(), name.size());
196}
197
198MiiManager::MiiManager() = default;
199
200MiiManager::~MiiManager() = default;
201
202MiiInfo MiiManager::CreateRandom(RandomParameters params) {
203 LOG_WARNING(Service_Mii,
204 "(STUBBED) called with params={:08X}{:08X}{:08X}, returning default Mii",
205 params.unknown_1, params.unknown_2, params.unknown_3);
206
207 return ConvertStoreDataToInfo(CreateMiiWithUniqueUUID());
208}
209
210MiiInfo MiiManager::CreateDefault(u32 index) {
211 const auto new_mii = CreateMiiWithUniqueUUID();
212
213 database.miis.at(index) = new_mii;
214
215 EnsureDatabasePartition();
216 return ConvertStoreDataToInfo(new_mii);
217}
218
219bool MiiManager::CheckUpdatedFlag() const {
220 return updated_flag;
221}
222
223void MiiManager::ResetUpdatedFlag() {
224 updated_flag = false;
225}
226
227bool MiiManager::IsTestModeEnabled() const {
228 return is_test_mode_enabled;
229}
230
231bool MiiManager::Empty() const {
232 return Size() == 0;
233}
234
235bool MiiManager::Full() const {
236 return Size() == MAX_MIIS;
237}
238
239void MiiManager::Clear() {
240 updated_flag = true;
241 std::fill(database.miis.begin(), database.miis.end(), MiiStoreData{});
242}
243
244u32 MiiManager::Size() const {
245 return static_cast<u32>(std::count_if(database.miis.begin(), database.miis.end(),
246 [](const MiiStoreData& elem) { return elem.uuid; }));
247}
248
249MiiInfo MiiManager::GetInfo(u32 index) const {
250 return ConvertStoreDataToInfo(GetStoreData(index));
251}
252
253MiiInfoElement MiiManager::GetInfoElement(u32 index) const {
254 return {GetInfo(index), Source::Database};
255}
256
257MiiStoreData MiiManager::GetStoreData(u32 index) const {
258 return database.miis.at(index);
259}
260
261MiiStoreDataElement MiiManager::GetStoreDataElement(u32 index) const {
262 return {GetStoreData(index), Source::Database};
263}
264
265bool MiiManager::Remove(Common::UUID uuid) {
266 const auto iter = std::find_if(database.miis.begin(), database.miis.end(),
267 [uuid](const MiiStoreData& elem) { return elem.uuid == uuid; });
268
269 if (iter == database.miis.end())
270 return false;
271
272 updated_flag = true;
273 *iter = MiiStoreData{};
274 EnsureDatabasePartition();
275 return true;
276}
277
278u32 MiiManager::IndexOf(Common::UUID uuid) const {
279 const auto iter = std::find_if(database.miis.begin(), database.miis.end(),
280 [uuid](const MiiStoreData& elem) { return elem.uuid == uuid; });
281
282 if (iter == database.miis.end())
283 return INVALID_INDEX;
284
285 return static_cast<u32>(std::distance(database.miis.begin(), iter));
286}
287
288u32 MiiManager::IndexOf(const MiiInfo& info) const {
289 const auto iter =
290 std::find_if(database.miis.begin(), database.miis.end(), [&info](const MiiStoreData& elem) {
291 return ConvertStoreDataToInfo(elem) == info;
292 });
293
294 if (iter == database.miis.end())
295 return INVALID_INDEX;
296
297 return static_cast<u32>(std::distance(database.miis.begin(), iter));
298}
299
300bool MiiManager::Move(Common::UUID uuid, u32 new_index) {
301 const auto index = IndexOf(uuid);
302
303 if (index == INVALID_INDEX || new_index >= MAX_MIIS)
304 return false;
305
306 updated_flag = true;
307 const auto moving = database.miis[index];
308 const auto replacing = database.miis[new_index];
309 if (replacing.uuid) {
310 database.miis[index] = replacing;
311 database.miis[new_index] = moving;
312 } else {
313 database.miis[index] = MiiStoreData{};
314 database.miis[new_index] = moving;
315 }
316
317 EnsureDatabasePartition();
318 return true;
319}
320
321bool MiiManager::AddOrReplace(const MiiStoreData& data) {
322 const auto index = IndexOf(data.uuid);
323
324 updated_flag = true;
325 if (index == INVALID_INDEX) {
326 const auto size = Size();
327 if (size == MAX_MIIS)
328 return false;
329 database.miis[size] = data;
330 } else {
331 database.miis[index] = data;
332 }
333
334 return true;
335}
336
337bool MiiManager::DestroyFile() {
338 database = DEFAULT_MII_DATABASE;
339 updated_flag = false;
340 return DeleteFile();
341}
342
343bool MiiManager::DeleteFile() {
344 const auto path = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + MII_SAVE_DATABASE_PATH;
345 return FileUtil::Exists(path) && FileUtil::Delete(path);
346}
347
348void MiiManager::WriteToFile() {
349 const auto raw_path =
350 FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + "/system/save/8000000000000030";
351 if (FileUtil::Exists(raw_path) && !FileUtil::IsDirectory(raw_path))
352 FileUtil::Delete(raw_path);
353
354 const auto path = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + MII_SAVE_DATABASE_PATH;
355
356 if (!FileUtil::CreateFullPath(path)) {
357 LOG_WARNING(Service_Mii,
358 "Failed to create full path of MiiDatabase.dat. Create the directory "
359 "nand/system/save/8000000000000030 to mitigate this "
360 "issue.");
361 return;
362 }
363
364 FileUtil::IOFile save(path, "wb");
365
366 if (!save.IsOpen()) {
367 LOG_WARNING(Service_Mii, "Failed to write save data to file... No changes to user data "
368 "made in current session will be saved.");
369 return;
370 }
371
372 save.Resize(sizeof(MiiDatabase));
373 if (save.WriteBytes(&database, sizeof(MiiDatabase)) != sizeof(MiiDatabase)) {
374 LOG_WARNING(Service_Mii, "Failed to write all data to save file... Data may be malformed "
375 "and/or regenerated on next run.");
376 save.Resize(0);
377 }
378}
379
380void MiiManager::ReadFromFile() {
381 FileUtil::IOFile save(
382 FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + MII_SAVE_DATABASE_PATH, "rb");
383
384 if (!save.IsOpen()) {
385 LOG_WARNING(Service_ACC, "Failed to load profile data from save data... Generating new "
386 "blank Mii database with no Miis.");
387 std::memcpy(&database, &DEFAULT_MII_DATABASE, sizeof(MiiDatabase));
388 return;
389 }
390
391 if (save.ReadBytes(&database, sizeof(MiiDatabase)) != sizeof(MiiDatabase)) {
392 LOG_WARNING(Service_ACC, "MiiDatabase.dat is smaller than expected... Generating new blank "
393 "Mii database with no Miis.");
394 std::memcpy(&database, &DEFAULT_MII_DATABASE, sizeof(MiiDatabase));
395 return;
396 }
397
398 EnsureDatabasePartition();
399}
400
401MiiStoreData MiiManager::CreateMiiWithUniqueUUID() const {
402 auto new_mii = DEFAULT_MII;
403
404 do {
405 new_mii.uuid = Common::UUID::Generate();
406 } while (IndexOf(new_mii.uuid) != INVALID_INDEX);
407
408 return new_mii;
409}
410
411void MiiManager::EnsureDatabasePartition() {
412 std::stable_partition(database.miis.begin(), database.miis.end(),
413 [](const MiiStoreData& elem) { return elem.uuid; });
414}
415
416} // namespace Service::Mii
diff --git a/src/core/hle/service/mii/mii_manager.h b/src/core/hle/service/mii/mii_manager.h
new file mode 100644
index 000000000..38ad78a0d
--- /dev/null
+++ b/src/core/hle/service/mii/mii_manager.h
@@ -0,0 +1,273 @@
1// Copyright 2018 yuzu emulator team
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "common/bit_field.h"
8#include "common/common_funcs.h"
9#include "common/uuid.h"
10
11namespace Service::Mii {
12
13constexpr std::size_t MAX_MIIS = 100;
14constexpr u32 INVALID_INDEX = 0xFFFFFFFF;
15
16struct RandomParameters {
17 u32 unknown_1;
18 u32 unknown_2;
19 u32 unknown_3;
20};
21static_assert(sizeof(RandomParameters) == 0xC, "RandomParameters has incorrect size.");
22
23enum class Source : u32 {
24 Database = 0,
25 Default = 1,
26 Account = 2,
27 Friend = 3,
28};
29
30std::ostream& operator<<(std::ostream& os, Source source);
31
32struct MiiInfo {
33 Common::UUID uuid;
34 std::array<char16_t, 11> name;
35 u8 font_region;
36 u8 favorite_color;
37 u8 gender;
38 u8 height;
39 u8 weight;
40 u8 mii_type;
41 u8 mii_region;
42 u8 face_type;
43 u8 face_color;
44 u8 face_wrinkle;
45 u8 face_makeup;
46 u8 hair_type;
47 u8 hair_color;
48 bool hair_flip;
49 u8 eye_type;
50 u8 eye_color;
51 u8 eye_scale;
52 u8 eye_aspect_ratio;
53 u8 eye_rotate;
54 u8 eye_x;
55 u8 eye_y;
56 u8 eyebrow_type;
57 u8 eyebrow_color;
58 u8 eyebrow_scale;
59 u8 eyebrow_aspect_ratio;
60 u8 eyebrow_rotate;
61 u8 eyebrow_x;
62 u8 eyebrow_y;
63 u8 nose_type;
64 u8 nose_scale;
65 u8 nose_y;
66 u8 mouth_type;
67 u8 mouth_color;
68 u8 mouth_scale;
69 u8 mouth_aspect_ratio;
70 u8 mouth_y;
71 u8 facial_hair_color;
72 u8 beard_type;
73 u8 mustache_type;
74 u8 mustache_scale;
75 u8 mustache_y;
76 u8 glasses_type;
77 u8 glasses_color;
78 u8 glasses_scale;
79 u8 glasses_y;
80 u8 mole_type;
81 u8 mole_scale;
82 u8 mole_x;
83 u8 mole_y;
84 INSERT_PADDING_BYTES(1);
85
86 std::u16string Name() const;
87};
88static_assert(sizeof(MiiInfo) == 0x58, "MiiInfo has incorrect size.");
89static_assert(std::has_unique_object_representations_v<MiiInfo>,
90 "All bits of MiiInfo must contribute to its value.");
91
92bool operator==(const MiiInfo& lhs, const MiiInfo& rhs);
93bool operator!=(const MiiInfo& lhs, const MiiInfo& rhs);
94
95#pragma pack(push, 4)
96struct MiiInfoElement {
97 MiiInfo info;
98 Source source;
99};
100static_assert(sizeof(MiiInfoElement) == 0x5C, "MiiInfoElement has incorrect size.");
101
102struct MiiStoreBitFields {
103 union {
104 u32 word_0;
105
106 BitField<24, 8, u32> hair_type;
107 BitField<23, 1, u32> mole_type;
108 BitField<16, 7, u32> height;
109 BitField<15, 1, u32> hair_flip;
110 BitField<8, 7, u32> weight;
111 BitField<0, 7, u32> hair_color;
112 };
113
114 union {
115 u32 word_1;
116
117 BitField<31, 1, u32> gender;
118 BitField<24, 7, u32> eye_color;
119 BitField<16, 7, u32> eyebrow_color;
120 BitField<8, 7, u32> mouth_color;
121 BitField<0, 7, u32> facial_hair_color;
122 };
123
124 union {
125 u32 word_2;
126
127 BitField<31, 1, u32> mii_type;
128 BitField<24, 7, u32> glasses_color;
129 BitField<22, 2, u32> font_region;
130 BitField<16, 6, u32> eye_type;
131 BitField<14, 2, u32> mii_region;
132 BitField<8, 6, u32> mouth_type;
133 BitField<5, 3, u32> glasses_scale;
134 BitField<0, 5, u32> eye_y;
135 };
136
137 union {
138 u32 word_3;
139
140 BitField<29, 3, u32> mustache_type;
141 BitField<24, 5, u32> eyebrow_type;
142 BitField<21, 3, u32> beard_type;
143 BitField<16, 5, u32> nose_type;
144 BitField<13, 3, u32> mouth_aspect;
145 BitField<8, 5, u32> nose_y;
146 BitField<5, 3, u32> eyebrow_aspect;
147 BitField<0, 5, u32> mouth_y;
148 };
149
150 union {
151 u32 word_4;
152
153 BitField<29, 3, u32> eye_rotate;
154 BitField<24, 5, u32> mustache_y;
155 BitField<21, 3, u32> eye_aspect;
156 BitField<16, 5, u32> glasses_y;
157 BitField<13, 3, u32> eye_scale;
158 BitField<8, 5, u32> mole_x;
159 BitField<0, 5, u32> mole_y;
160 };
161
162 union {
163 u32 word_5;
164
165 BitField<24, 5, u32> glasses_type;
166 BitField<20, 4, u32> face_type;
167 BitField<16, 4, u32> favorite_color;
168 BitField<12, 4, u32> face_wrinkle;
169 BitField<8, 4, u32> face_color;
170 BitField<4, 4, u32> eye_x;
171 BitField<0, 4, u32> face_makeup;
172 };
173
174 union {
175 u32 word_6;
176
177 BitField<28, 4, u32> eyebrow_rotate;
178 BitField<24, 4, u32> eyebrow_scale;
179 BitField<20, 4, u32> eyebrow_y;
180 BitField<16, 4, u32> eyebrow_x;
181 BitField<12, 4, u32> mouth_scale;
182 BitField<8, 4, u32> nose_scale;
183 BitField<4, 4, u32> mole_scale;
184 BitField<0, 4, u32> mustache_scale;
185 };
186};
187static_assert(sizeof(MiiStoreBitFields) == 0x1C, "MiiStoreBitFields has incorrect size.");
188static_assert(std::is_trivially_copyable_v<MiiStoreBitFields>,
189 "MiiStoreBitFields is not trivially copyable.");
190
191struct MiiStoreData {
192 // This corresponds to the above structure MiiStoreBitFields. I did it like this because the
193 // BitField<> type makes this (and any thing that contains it) not trivially copyable, which is
194 // not suitable for our uses.
195 std::array<u8, 0x1C> data;
196 static_assert(sizeof(MiiStoreBitFields) == sizeof(data), "data field has incorrect size.");
197
198 std::array<char16_t, 10> name;
199 Common::UUID uuid;
200 u16 crc_1;
201 u16 crc_2;
202
203 std::u16string Name() const;
204};
205static_assert(sizeof(MiiStoreData) == 0x44, "MiiStoreData has incorrect size.");
206
207struct MiiStoreDataElement {
208 MiiStoreData data;
209 Source source;
210};
211static_assert(sizeof(MiiStoreDataElement) == 0x48, "MiiStoreDataElement has incorrect size.");
212
213struct MiiDatabase {
214 u32 magic; // 'NFDB'
215 std::array<MiiStoreData, MAX_MIIS> miis;
216 INSERT_PADDING_BYTES(1);
217 u8 count;
218 u16 crc;
219};
220static_assert(sizeof(MiiDatabase) == 0x1A98, "MiiDatabase has incorrect size.");
221#pragma pack(pop)
222
223// The Mii manager is responsible for loading and storing the Miis to the database in NAND along
224// with providing an easy interface for HLE emulation of the mii service.
225class MiiManager {
226public:
227 MiiManager();
228 ~MiiManager();
229
230 MiiInfo CreateRandom(RandomParameters params);
231 MiiInfo CreateDefault(u32 index);
232
233 bool CheckUpdatedFlag() const;
234 void ResetUpdatedFlag();
235
236 bool IsTestModeEnabled() const;
237
238 bool Empty() const;
239 bool Full() const;
240
241 void Clear();
242
243 u32 Size() const;
244
245 MiiInfo GetInfo(u32 index) const;
246 MiiInfoElement GetInfoElement(u32 index) const;
247 MiiStoreData GetStoreData(u32 index) const;
248 MiiStoreDataElement GetStoreDataElement(u32 index) const;
249
250 bool Remove(Common::UUID uuid);
251 u32 IndexOf(Common::UUID uuid) const;
252 u32 IndexOf(const MiiInfo& info) const;
253
254 bool Move(Common::UUID uuid, u32 new_index);
255 bool AddOrReplace(const MiiStoreData& data);
256
257 bool DestroyFile();
258 bool DeleteFile();
259
260private:
261 void WriteToFile();
262 void ReadFromFile();
263
264 MiiStoreData CreateMiiWithUniqueUUID() const;
265
266 void EnsureDatabasePartition();
267
268 MiiDatabase database;
269 bool updated_flag = false;
270 bool is_test_mode_enabled = false;
271};
272
273}; // namespace Service::Mii
diff --git a/src/yuzu/applets/profile_select.cpp b/src/yuzu/applets/profile_select.cpp
index 7fbc9deeb..42e26b978 100644
--- a/src/yuzu/applets/profile_select.cpp
+++ b/src/yuzu/applets/profile_select.cpp
@@ -27,20 +27,20 @@ constexpr std::array<u8, 107> backup_jpeg{
27 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, 27 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9,
28}; 28};
29 29
30QString FormatUserEntryText(const QString& username, Service::Account::UUID uuid) { 30QString FormatUserEntryText(const QString& username, Common::UUID uuid) {
31 return QtProfileSelectionDialog::tr( 31 return QtProfileSelectionDialog::tr(
32 "%1\n%2", "%1 is the profile username, %2 is the formatted UUID (e.g. " 32 "%1\n%2", "%1 is the profile username, %2 is the formatted UUID (e.g. "
33 "00112233-4455-6677-8899-AABBCCDDEEFF))") 33 "00112233-4455-6677-8899-AABBCCDDEEFF))")
34 .arg(username, QString::fromStdString(uuid.FormatSwitch())); 34 .arg(username, QString::fromStdString(uuid.FormatSwitch()));
35} 35}
36 36
37QString GetImagePath(Service::Account::UUID uuid) { 37QString GetImagePath(Common::UUID uuid) {
38 const auto path = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + 38 const auto path = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
39 "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg"; 39 "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg";
40 return QString::fromStdString(path); 40 return QString::fromStdString(path);
41} 41}
42 42
43QPixmap GetIcon(Service::Account::UUID uuid) { 43QPixmap GetIcon(Common::UUID uuid) {
44 QPixmap icon{GetImagePath(uuid)}; 44 QPixmap icon{GetImagePath(uuid)};
45 45
46 if (!icon) { 46 if (!icon) {
@@ -154,12 +154,12 @@ QtProfileSelector::QtProfileSelector(GMainWindow& parent) {
154QtProfileSelector::~QtProfileSelector() = default; 154QtProfileSelector::~QtProfileSelector() = default;
155 155
156void QtProfileSelector::SelectProfile( 156void QtProfileSelector::SelectProfile(
157 std::function<void(std::optional<Service::Account::UUID>)> callback) const { 157 std::function<void(std::optional<Common::UUID>)> callback) const {
158 this->callback = std::move(callback); 158 this->callback = std::move(callback);
159 emit MainWindowSelectProfile(); 159 emit MainWindowSelectProfile();
160} 160}
161 161
162void QtProfileSelector::MainWindowFinishedSelection(std::optional<Service::Account::UUID> uuid) { 162void QtProfileSelector::MainWindowFinishedSelection(std::optional<Common::UUID> uuid) {
163 // Acquire the HLE mutex 163 // Acquire the HLE mutex
164 std::lock_guard lock{HLE::g_hle_lock}; 164 std::lock_guard lock{HLE::g_hle_lock};
165 callback(uuid); 165 callback(uuid);
diff --git a/src/yuzu/applets/profile_select.h b/src/yuzu/applets/profile_select.h
index 1c2922e54..c5b90a78e 100644
--- a/src/yuzu/applets/profile_select.h
+++ b/src/yuzu/applets/profile_select.h
@@ -9,6 +9,7 @@
9#include <QList> 9#include <QList>
10#include <QTreeView> 10#include <QTreeView>
11#include "core/frontend/applets/profile_select.h" 11#include "core/frontend/applets/profile_select.h"
12#include "core/hle/service/acc/profile_manager.h"
12 13
13class GMainWindow; 14class GMainWindow;
14class QDialogButtonBox; 15class QDialogButtonBox;
@@ -60,14 +61,13 @@ public:
60 explicit QtProfileSelector(GMainWindow& parent); 61 explicit QtProfileSelector(GMainWindow& parent);
61 ~QtProfileSelector() override; 62 ~QtProfileSelector() override;
62 63
63 void SelectProfile( 64 void SelectProfile(std::function<void(std::optional<Common::UUID>)> callback) const override;
64 std::function<void(std::optional<Service::Account::UUID>)> callback) const override;
65 65
66signals: 66signals:
67 void MainWindowSelectProfile() const; 67 void MainWindowSelectProfile() const;
68 68
69private: 69private:
70 void MainWindowFinishedSelection(std::optional<Service::Account::UUID> uuid); 70 void MainWindowFinishedSelection(std::optional<Common::UUID> uuid);
71 71
72 mutable std::function<void(std::optional<Service::Account::UUID>)> callback; 72 mutable std::function<void(std::optional<Common::UUID>)> callback;
73}; 73};
diff --git a/src/yuzu/configuration/configure_profile_manager.cpp b/src/yuzu/configuration/configure_profile_manager.cpp
index 002a51780..6d7d04c98 100644
--- a/src/yuzu/configuration/configure_profile_manager.cpp
+++ b/src/yuzu/configuration/configure_profile_manager.cpp
@@ -33,14 +33,13 @@ constexpr std::array<u8, 107> backup_jpeg{
33 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, 33 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9,
34}; 34};
35 35
36QString GetImagePath(Service::Account::UUID uuid) { 36QString GetImagePath(Common::UUID uuid) {
37 const auto path = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + 37 const auto path = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
38 "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg"; 38 "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg";
39 return QString::fromStdString(path); 39 return QString::fromStdString(path);
40} 40}
41 41
42QString GetAccountUsername(const Service::Account::ProfileManager& manager, 42QString GetAccountUsername(const Service::Account::ProfileManager& manager, Common::UUID uuid) {
43 Service::Account::UUID uuid) {
44 Service::Account::ProfileBase profile; 43 Service::Account::ProfileBase profile;
45 if (!manager.GetProfileBase(uuid, profile)) { 44 if (!manager.GetProfileBase(uuid, profile)) {
46 return {}; 45 return {};
@@ -51,14 +50,14 @@ QString GetAccountUsername(const Service::Account::ProfileManager& manager,
51 return QString::fromStdString(text); 50 return QString::fromStdString(text);
52} 51}
53 52
54QString FormatUserEntryText(const QString& username, Service::Account::UUID uuid) { 53QString FormatUserEntryText(const QString& username, Common::UUID uuid) {
55 return ConfigureProfileManager::tr("%1\n%2", 54 return ConfigureProfileManager::tr("%1\n%2",
56 "%1 is the profile username, %2 is the formatted UUID (e.g. " 55 "%1 is the profile username, %2 is the formatted UUID (e.g. "
57 "00112233-4455-6677-8899-AABBCCDDEEFF))") 56 "00112233-4455-6677-8899-AABBCCDDEEFF))")
58 .arg(username, QString::fromStdString(uuid.FormatSwitch())); 57 .arg(username, QString::fromStdString(uuid.FormatSwitch()));
59} 58}
60 59
61QPixmap GetIcon(Service::Account::UUID uuid) { 60QPixmap GetIcon(Common::UUID uuid) {
62 QPixmap icon{GetImagePath(uuid)}; 61 QPixmap icon{GetImagePath(uuid)};
63 62
64 if (!icon) { 63 if (!icon) {
@@ -190,7 +189,7 @@ void ConfigureProfileManager::AddUser() {
190 return; 189 return;
191 } 190 }
192 191
193 const auto uuid = Service::Account::UUID::Generate(); 192 const auto uuid = Common::UUID::Generate();
194 profile_manager->CreateNewUser(uuid, username.toStdString()); 193 profile_manager->CreateNewUser(uuid, username.toStdString());
195 194
196 item_model->appendRow(new QStandardItem{GetIcon(uuid), FormatUserEntryText(username, uuid)}); 195 item_model->appendRow(new QStandardItem{GetIcon(uuid), FormatUserEntryText(username, uuid)});
diff --git a/src/yuzu/main.h b/src/yuzu/main.h
index 7bf82e665..1137bbc7a 100644
--- a/src/yuzu/main.h
+++ b/src/yuzu/main.h
@@ -104,7 +104,7 @@ signals:
104 104
105 void ErrorDisplayFinished(); 105 void ErrorDisplayFinished();
106 106
107 void ProfileSelectorFinishedSelection(std::optional<Service::Account::UUID> uuid); 107 void ProfileSelectorFinishedSelection(std::optional<Common::UUID> uuid);
108 void SoftwareKeyboardFinishedText(std::optional<std::u16string> text); 108 void SoftwareKeyboardFinishedText(std::optional<std::u16string> text);
109 void SoftwareKeyboardFinishedCheckDialog(); 109 void SoftwareKeyboardFinishedCheckDialog();
110 110