summaryrefslogtreecommitdiff
path: root/src/core/hle/service/mii
diff options
context:
space:
mode:
authorGravatar Morph2022-02-05 00:40:48 -0500
committerGravatar Morph2022-02-05 13:18:46 -0500
commitee0547e4c4d38d681d9cd3b9f7071c4dade9110d (patch)
tree9833fb69b1bd34105ea7d43dc74977c0c88e9fb3 /src/core/hle/service/mii
parentinput/hid: Migrate to the new UUID implementation (diff)
downloadyuzu-ee0547e4c4d38d681d9cd3b9f7071c4dade9110d.tar.gz
yuzu-ee0547e4c4d38d681d9cd3b9f7071c4dade9110d.tar.xz
yuzu-ee0547e4c4d38d681d9cd3b9f7071c4dade9110d.zip
service: Migrate to the new UUID implementation
Diffstat (limited to 'src/core/hle/service/mii')
-rw-r--r--src/core/hle/service/mii/mii_manager.cpp21
-rw-r--r--src/core/hle/service/mii/mii_manager.h10
2 files changed, 11 insertions, 20 deletions
diff --git a/src/core/hle/service/mii/mii_manager.cpp b/src/core/hle/service/mii/mii_manager.cpp
index ca4ed35bb..aa1a9a6c7 100644
--- a/src/core/hle/service/mii/mii_manager.cpp
+++ b/src/core/hle/service/mii/mii_manager.cpp
@@ -118,16 +118,6 @@ u16 GenerateCrc16(const void* data, std::size_t size) {
118 return Common::swap16(static_cast<u16>(crc)); 118 return Common::swap16(static_cast<u16>(crc));
119} 119}
120 120
121Common::UUID GenerateValidUUID() {
122 auto uuid{Common::UUID::Generate()};
123
124 // Bit 7 must be set, and bit 6 unset for the UUID to be valid
125 uuid.uuid[1] &= 0xFFFFFFFFFFFFFF3FULL;
126 uuid.uuid[1] |= 0x0000000000000080ULL;
127
128 return uuid;
129}
130
131template <typename T> 121template <typename T>
132T GetRandomValue(T min, T max) { 122T GetRandomValue(T min, T max) {
133 std::random_device device; 123 std::random_device device;
@@ -141,7 +131,8 @@ T GetRandomValue(T max) {
141 return GetRandomValue<T>({}, max); 131 return GetRandomValue<T>({}, max);
142} 132}
143 133
144MiiStoreData BuildRandomStoreData(Age age, Gender gender, Race race, const Common::UUID& user_id) { 134MiiStoreData BuildRandomStoreData(Age age, Gender gender, Race race,
135 const Common::NewUUID& user_id) {
145 MiiStoreBitFields bf{}; 136 MiiStoreBitFields bf{};
146 137
147 if (gender == Gender::All) { 138 if (gender == Gender::All) {
@@ -320,7 +311,7 @@ MiiStoreData BuildRandomStoreData(Age age, Gender gender, Race race, const Commo
320 return {DefaultMiiName, bf, user_id}; 311 return {DefaultMiiName, bf, user_id};
321} 312}
322 313
323MiiStoreData BuildDefaultStoreData(const DefaultMii& info, const Common::UUID& user_id) { 314MiiStoreData BuildDefaultStoreData(const DefaultMii& info, const Common::NewUUID& user_id) {
324 MiiStoreBitFields bf{}; 315 MiiStoreBitFields bf{};
325 316
326 bf.font_region.Assign(info.font_region); 317 bf.font_region.Assign(info.font_region);
@@ -381,13 +372,13 @@ MiiStoreData BuildDefaultStoreData(const DefaultMii& info, const Common::UUID& u
381MiiStoreData::MiiStoreData() = default; 372MiiStoreData::MiiStoreData() = default;
382 373
383MiiStoreData::MiiStoreData(const MiiStoreData::Name& name, const MiiStoreBitFields& bit_fields, 374MiiStoreData::MiiStoreData(const MiiStoreData::Name& name, const MiiStoreBitFields& bit_fields,
384 const Common::UUID& user_id) { 375 const Common::NewUUID& user_id) {
385 data.name = name; 376 data.name = name;
386 data.uuid = GenerateValidUUID(); 377 data.uuid = Common::NewUUID::MakeRandomRFC4122V4();
387 378
388 std::memcpy(data.data.data(), &bit_fields, sizeof(MiiStoreBitFields)); 379 std::memcpy(data.data.data(), &bit_fields, sizeof(MiiStoreBitFields));
389 data_crc = GenerateCrc16(data.data.data(), sizeof(data)); 380 data_crc = GenerateCrc16(data.data.data(), sizeof(data));
390 device_crc = GenerateCrc16(&user_id, sizeof(Common::UUID)); 381 device_crc = GenerateCrc16(&user_id, sizeof(Common::NewUUID));
391} 382}
392 383
393MiiManager::MiiManager() : user_id{Service::Account::ProfileManager().GetLastOpenedUser()} {} 384MiiManager::MiiManager() : user_id{Service::Account::ProfileManager().GetLastOpenedUser()} {}
diff --git a/src/core/hle/service/mii/mii_manager.h b/src/core/hle/service/mii/mii_manager.h
index 8e048fc56..580a64fc9 100644
--- a/src/core/hle/service/mii/mii_manager.h
+++ b/src/core/hle/service/mii/mii_manager.h
@@ -8,7 +8,7 @@
8#include <vector> 8#include <vector>
9#include "common/bit_field.h" 9#include "common/bit_field.h"
10#include "common/common_funcs.h" 10#include "common/common_funcs.h"
11#include "common/uuid.h" 11#include "common/new_uuid.h"
12#include "core/hle/result.h" 12#include "core/hle/result.h"
13#include "core/hle/service/mii/types.h" 13#include "core/hle/service/mii/types.h"
14 14
@@ -29,7 +29,7 @@ enum class SourceFlag : u32 {
29DECLARE_ENUM_FLAG_OPERATORS(SourceFlag); 29DECLARE_ENUM_FLAG_OPERATORS(SourceFlag);
30 30
31struct MiiInfo { 31struct MiiInfo {
32 Common::UUID uuid; 32 Common::NewUUID uuid;
33 std::array<char16_t, 11> name; 33 std::array<char16_t, 11> name;
34 u8 font_region; 34 u8 font_region;
35 u8 favorite_color; 35 u8 favorite_color;
@@ -192,7 +192,7 @@ struct MiiStoreData {
192 192
193 MiiStoreData(); 193 MiiStoreData();
194 MiiStoreData(const Name& name, const MiiStoreBitFields& bit_fields, 194 MiiStoreData(const Name& name, const MiiStoreBitFields& bit_fields,
195 const Common::UUID& user_id); 195 const Common::NewUUID& user_id);
196 196
197 // This corresponds to the above structure MiiStoreBitFields. I did it like this because the 197 // This corresponds to the above structure MiiStoreBitFields. I did it like this because the
198 // BitField<> type makes this (and any thing that contains it) not trivially copyable, which is 198 // BitField<> type makes this (and any thing that contains it) not trivially copyable, which is
@@ -202,7 +202,7 @@ struct MiiStoreData {
202 static_assert(sizeof(MiiStoreBitFields) == sizeof(data), "data field has incorrect size."); 202 static_assert(sizeof(MiiStoreBitFields) == sizeof(data), "data field has incorrect size.");
203 203
204 Name name{}; 204 Name name{};
205 Common::UUID uuid{Common::INVALID_UUID}; 205 Common::NewUUID uuid{};
206 } data; 206 } data;
207 207
208 u16 data_crc{}; 208 u16 data_crc{};
@@ -326,7 +326,7 @@ public:
326 ResultCode GetIndex(const MiiInfo& info, u32& index); 326 ResultCode GetIndex(const MiiInfo& info, u32& index);
327 327
328private: 328private:
329 const Common::UUID user_id{Common::INVALID_UUID}; 329 const Common::NewUUID user_id{};
330 u64 update_counter{}; 330 u64 update_counter{};
331}; 331};
332 332