manager.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. // Copyright 2020 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <cstring>
  5. #include <random>
  6. #include "common/assert.h"
  7. #include "common/file_util.h"
  8. #include "common/logging/log.h"
  9. #include "common/string_util.h"
  10. #include "core/hle/service/acc/profile_manager.h"
  11. #include "core/hle/service/mii/manager.h"
  12. #include "core/hle/service/mii/raw_data.h"
  13. #include "core/hle/service/mii/types.h"
  14. namespace Service::Mii {
  15. namespace {
  16. constexpr ResultCode ERROR_CANNOT_FIND_ENTRY{ErrorModule::Mii, 4};
  17. constexpr std::size_t DefaultMiiCount{sizeof(RawData::DefaultMii) / sizeof(DefaultMii)};
  18. constexpr MiiStoreData::Name DefaultMiiName{u'y', u'u', u'z', u'u'};
  19. constexpr std::array<u8, 8> HairColorLookup{8, 1, 2, 3, 4, 5, 6, 7};
  20. constexpr std::array<u8, 6> EyeColorLookup{8, 9, 10, 11, 12, 13};
  21. constexpr std::array<u8, 5> MouthColorLookup{19, 20, 21, 22, 23};
  22. constexpr std::array<u8, 7> GlassesColorLookup{8, 14, 15, 16, 17, 18, 0};
  23. constexpr std::array<u8, 62> EyeRotateLookup{
  24. {0x03, 0x04, 0x04, 0x04, 0x03, 0x04, 0x04, 0x04, 0x03, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x04,
  25. 0x04, 0x04, 0x03, 0x03, 0x04, 0x03, 0x04, 0x03, 0x03, 0x04, 0x03, 0x04, 0x04, 0x03, 0x04, 0x04,
  26. 0x04, 0x03, 0x03, 0x03, 0x04, 0x04, 0x03, 0x03, 0x03, 0x04, 0x04, 0x03, 0x03, 0x03, 0x03, 0x03,
  27. 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04, 0x03, 0x04, 0x04, 0x03, 0x04, 0x04}};
  28. constexpr std::array<u8, 24> EyebrowRotateLookup{{0x06, 0x06, 0x05, 0x07, 0x06, 0x07, 0x06, 0x07,
  29. 0x04, 0x07, 0x06, 0x08, 0x05, 0x05, 0x06, 0x06,
  30. 0x07, 0x07, 0x06, 0x06, 0x05, 0x06, 0x07, 0x05}};
  31. template <typename T, std::size_t SourceArraySize, std::size_t DestArraySize>
  32. std::array<T, DestArraySize> ResizeArray(const std::array<T, SourceArraySize>& in) {
  33. std::array<T, DestArraySize> out{};
  34. std::memcpy(out.data(), in.data(), sizeof(T) * std::min(SourceArraySize, DestArraySize));
  35. return out;
  36. }
  37. MiiInfo ConvertStoreDataToInfo(const MiiStoreData& data) {
  38. MiiStoreBitFields bf;
  39. std::memcpy(&bf, data.data.data.data(), sizeof(MiiStoreBitFields));
  40. MiiInfo info{};
  41. info.name = ResizeArray<char16_t, 10, 11>(data.data.name);
  42. info.uuid = data.data.uuid;
  43. info.font_region = static_cast<u8>(bf.font_region.Value());
  44. info.favorite_color = static_cast<u8>(bf.favorite_color.Value());
  45. info.gender = static_cast<u8>(bf.gender.Value());
  46. info.height = static_cast<u8>(bf.height.Value());
  47. info.build = static_cast<u8>(bf.build.Value());
  48. info.type = static_cast<u8>(bf.type.Value());
  49. info.region_move = static_cast<u8>(bf.region_move.Value());
  50. info.faceline_type = static_cast<u8>(bf.faceline_type.Value());
  51. info.faceline_color = static_cast<u8>(bf.faceline_color.Value());
  52. info.faceline_wrinkle = static_cast<u8>(bf.faceline_wrinkle.Value());
  53. info.faceline_make = static_cast<u8>(bf.faceline_makeup.Value());
  54. info.hair_type = static_cast<u8>(bf.hair_type.Value());
  55. info.hair_color = static_cast<u8>(bf.hair_color.Value());
  56. info.hair_flip = static_cast<u8>(bf.hair_flip.Value());
  57. info.eye_type = static_cast<u8>(bf.eye_type.Value());
  58. info.eye_color = static_cast<u8>(bf.eye_color.Value());
  59. info.eye_scale = static_cast<u8>(bf.eye_scale.Value());
  60. info.eye_aspect = static_cast<u8>(bf.eye_aspect.Value());
  61. info.eye_rotate = static_cast<u8>(bf.eye_rotate.Value());
  62. info.eye_x = static_cast<u8>(bf.eye_x.Value());
  63. info.eye_y = static_cast<u8>(bf.eye_y.Value());
  64. info.eyebrow_type = static_cast<u8>(bf.eyebrow_type.Value());
  65. info.eyebrow_color = static_cast<u8>(bf.eyebrow_color.Value());
  66. info.eyebrow_scale = static_cast<u8>(bf.eyebrow_scale.Value());
  67. info.eyebrow_aspect = static_cast<u8>(bf.eyebrow_aspect.Value());
  68. info.eyebrow_rotate = static_cast<u8>(bf.eyebrow_rotate.Value());
  69. info.eyebrow_x = static_cast<u8>(bf.eyebrow_x.Value());
  70. info.eyebrow_y = static_cast<u8>(bf.eyebrow_y.Value() + 3);
  71. info.nose_type = static_cast<u8>(bf.nose_type.Value());
  72. info.nose_scale = static_cast<u8>(bf.nose_scale.Value());
  73. info.nose_y = static_cast<u8>(bf.nose_y.Value());
  74. info.mouth_type = static_cast<u8>(bf.mouth_type.Value());
  75. info.mouth_color = static_cast<u8>(bf.mouth_color.Value());
  76. info.mouth_scale = static_cast<u8>(bf.mouth_scale.Value());
  77. info.mouth_aspect = static_cast<u8>(bf.mouth_aspect.Value());
  78. info.mouth_y = static_cast<u8>(bf.mouth_y.Value());
  79. info.beard_color = static_cast<u8>(bf.beard_color.Value());
  80. info.beard_type = static_cast<u8>(bf.beard_type.Value());
  81. info.mustache_type = static_cast<u8>(bf.mustache_type.Value());
  82. info.mustache_scale = static_cast<u8>(bf.mustache_scale.Value());
  83. info.mustache_y = static_cast<u8>(bf.mustache_y.Value());
  84. info.glasses_type = static_cast<u8>(bf.glasses_type.Value());
  85. info.glasses_color = static_cast<u8>(bf.glasses_color.Value());
  86. info.glasses_scale = static_cast<u8>(bf.glasses_scale.Value());
  87. info.glasses_y = static_cast<u8>(bf.glasses_y.Value());
  88. info.mole_type = static_cast<u8>(bf.mole_type.Value());
  89. info.mole_scale = static_cast<u8>(bf.mole_scale.Value());
  90. info.mole_x = static_cast<u8>(bf.mole_x.Value());
  91. info.mole_y = static_cast<u8>(bf.mole_y.Value());
  92. return info;
  93. }
  94. u16 GenerateCrc16(const void* data, std::size_t size) {
  95. s32 crc{};
  96. for (int i = 0; i < size; i++) {
  97. crc ^= reinterpret_cast<const u8*>(data)[i] << 8;
  98. for (int j = 0; j < 8; j++) {
  99. crc <<= 1;
  100. if ((crc & 0x10000) != 0) {
  101. crc = (crc ^ 0x1021) & 0xFFFF;
  102. }
  103. }
  104. }
  105. return Common::swap16(static_cast<u16>(crc));
  106. }
  107. Common::UUID GenerateValidUUID() {
  108. auto uuid{Common::UUID::Generate()};
  109. // Bit 7 must be set, and bit 6 unset for the UUID to be valid
  110. uuid.uuid[1] &= 0xFFFFFFFFFFFFFF3FULL;
  111. uuid.uuid[1] |= 0x0000000000000080ULL;
  112. return uuid;
  113. }
  114. template <typename T>
  115. T GetRandomValue(T min, T max) {
  116. std::random_device device;
  117. std::mt19937 gen(device());
  118. std::uniform_int_distribution<u64> distribution(0, static_cast<u64>(max));
  119. return static_cast<T>(distribution(gen));
  120. }
  121. template <typename T>
  122. T GetRandomValue(T max) {
  123. return GetRandomValue<T>({}, max);
  124. }
  125. template <typename T>
  126. T GetArrayValue(const u8* data, std::size_t index) {
  127. T result{};
  128. std::memcpy(&result, &data[index * sizeof(T)], sizeof(T));
  129. return result;
  130. }
  131. MiiStoreData BuildRandomStoreData(Age age, Gender gender, Race race, const Common::UUID& user_id) {
  132. MiiStoreBitFields bf{};
  133. if (gender == Gender::All) {
  134. gender = GetRandomValue<Gender>(Gender::Maximum);
  135. }
  136. bf.gender.Assign(gender);
  137. bf.favorite_color.Assign(GetRandomValue<u8>(11));
  138. bf.region_move.Assign(0);
  139. bf.font_region.Assign(FontRegion::Standard);
  140. bf.type.Assign(0);
  141. bf.height.Assign(64);
  142. bf.build.Assign(64);
  143. if (age == Age::All) {
  144. const auto temp{GetRandomValue<int>(10)};
  145. if (temp >= 8) {
  146. age = Age::Old;
  147. } else if (temp >= 4) {
  148. age = Age::Normal;
  149. } else {
  150. age = Age::Young;
  151. }
  152. }
  153. if (race == Race::All) {
  154. const auto temp{GetRandomValue<int>(10)};
  155. if (temp >= 8) {
  156. race = Race::Black;
  157. } else if (temp >= 4) {
  158. race = Race::White;
  159. } else {
  160. race = Race::Asian;
  161. }
  162. }
  163. u32 axis_y{};
  164. if (gender == Gender::Female && age == Age::Young) {
  165. axis_y = GetRandomValue<u32>(3);
  166. }
  167. const std::size_t index{3 * static_cast<std::size_t>(age) +
  168. 9 * static_cast<std::size_t>(gender) + static_cast<std::size_t>(race)};
  169. const auto faceline_type_info{
  170. GetArrayValue<RandomMiiData4>(&RawData::RandomMiiFaceline[0], index)};
  171. const auto faceline_color_info{GetArrayValue<RandomMiiData3>(
  172. RawData::RandomMiiFacelineColor.data(),
  173. 3 * static_cast<std::size_t>(gender) + static_cast<std::size_t>(race))};
  174. const auto faceline_wrinkle_info{
  175. GetArrayValue<RandomMiiData4>(RawData::RandomMiiFacelineWrinkle.data(), index)};
  176. const auto faceline_makeup_info{
  177. GetArrayValue<RandomMiiData4>(RawData::RandomMiiFacelineMakeup.data(), index)};
  178. const auto hair_type_info{
  179. GetArrayValue<RandomMiiData4>(RawData::RandomMiiHairType.data(), index)};
  180. const auto hair_color_info{GetArrayValue<RandomMiiData3>(RawData::RandomMiiHairColor.data(),
  181. 3 * static_cast<std::size_t>(race) +
  182. static_cast<std::size_t>(age))};
  183. const auto eye_type_info{
  184. GetArrayValue<RandomMiiData4>(RawData::RandomMiiEyeType.data(), index)};
  185. const auto eye_color_info{GetArrayValue<RandomMiiData2>(RawData::RandomMiiEyeColor.data(),
  186. static_cast<std::size_t>(race))};
  187. const auto eyebrow_type_info{
  188. GetArrayValue<RandomMiiData4>(RawData::RandomMiiEyebrowType.data(), index)};
  189. const auto nose_type_info{
  190. GetArrayValue<RandomMiiData4>(RawData::RandomMiiNoseType.data(), index)};
  191. const auto mouth_type_info{
  192. GetArrayValue<RandomMiiData4>(RawData::RandomMiiMouthType.data(), index)};
  193. const auto glasses_type_info{GetArrayValue<RandomMiiData2>(RawData::RandomMiiGlassType.data(),
  194. static_cast<std::size_t>(age))};
  195. bf.faceline_type.Assign(
  196. faceline_type_info.values[GetRandomValue<std::size_t>(faceline_type_info.values_count)]);
  197. bf.faceline_color.Assign(
  198. faceline_color_info.values[GetRandomValue<std::size_t>(faceline_color_info.values_count)]);
  199. bf.faceline_wrinkle.Assign(
  200. faceline_wrinkle_info
  201. .values[GetRandomValue<std::size_t>(faceline_wrinkle_info.values_count)]);
  202. bf.faceline_makeup.Assign(
  203. faceline_makeup_info
  204. .values[GetRandomValue<std::size_t>(faceline_makeup_info.values_count)]);
  205. bf.hair_type.Assign(
  206. hair_type_info.values[GetRandomValue<std::size_t>(hair_type_info.values_count)]);
  207. bf.hair_color.Assign(
  208. HairColorLookup[hair_color_info
  209. .values[GetRandomValue<std::size_t>(hair_color_info.values_count)]]);
  210. bf.hair_flip.Assign(GetRandomValue<HairFlip>(HairFlip::Maximum));
  211. bf.eye_type.Assign(
  212. eye_type_info.values[GetRandomValue<std::size_t>(eye_type_info.values_count)]);
  213. const auto eye_rotate_1{gender != Gender::Male ? 4 : 2};
  214. const auto eye_rotate_2{gender != Gender::Male ? 3 : 4};
  215. const auto eye_rotate_offset{32 - EyeRotateLookup[eye_rotate_1] + eye_rotate_2};
  216. const auto eye_rotate{32 - EyeRotateLookup[bf.eye_type]};
  217. bf.eye_color.Assign(
  218. EyeColorLookup[eye_color_info
  219. .values[GetRandomValue<std::size_t>(eye_color_info.values_count)]]);
  220. bf.eye_scale.Assign(4);
  221. bf.eye_aspect.Assign(3);
  222. bf.eye_rotate.Assign(eye_rotate_offset - eye_rotate);
  223. bf.eye_x.Assign(2);
  224. bf.eye_y.Assign(axis_y + 12);
  225. bf.eyebrow_type.Assign(
  226. eyebrow_type_info.values[GetRandomValue<std::size_t>(eyebrow_type_info.values_count)]);
  227. const auto eyebrow_rotate_1{race == Race::Asian ? 6 : 0};
  228. const auto eyebrow_y{race == Race::Asian ? 9 : 10};
  229. const auto eyebrow_rotate_offset{32 - EyebrowRotateLookup[eyebrow_rotate_1] + 6};
  230. const auto eyebrow_rotate{
  231. 32 - EyebrowRotateLookup[static_cast<std::size_t>(bf.eyebrow_type.Value())]};
  232. bf.eyebrow_color.Assign(bf.hair_color);
  233. bf.eyebrow_scale.Assign(4);
  234. bf.eyebrow_aspect.Assign(3);
  235. bf.eyebrow_rotate.Assign(eyebrow_rotate_offset - eyebrow_rotate);
  236. bf.eyebrow_x.Assign(2);
  237. bf.eyebrow_y.Assign(axis_y + eyebrow_y);
  238. const auto nose_scale{gender == Gender::Female ? 3 : 4};
  239. bf.nose_type.Assign(
  240. nose_type_info.values[GetRandomValue<std::size_t>(nose_type_info.values_count)]);
  241. bf.nose_scale.Assign(nose_scale);
  242. bf.nose_y.Assign(axis_y + 9);
  243. const auto mouth_color{gender == Gender::Female ? GetRandomValue<int>(4) : 0};
  244. bf.mouth_type.Assign(
  245. mouth_type_info.values[GetRandomValue<std::size_t>(mouth_type_info.values_count)]);
  246. bf.mouth_color.Assign(MouthColorLookup[mouth_color]);
  247. bf.mouth_scale.Assign(4);
  248. bf.mouth_aspect.Assign(3);
  249. bf.mouth_y.Assign(axis_y + 13);
  250. bf.beard_color.Assign(bf.hair_color);
  251. bf.mustache_scale.Assign(4);
  252. if (gender == Gender::Male && age != Age::Young && GetRandomValue<int>(10) < 2) {
  253. const auto mustache_and_beard_flag{
  254. GetRandomValue<BeardAndMustacheFlag>(BeardAndMustacheFlag::All)};
  255. auto beard_type{BeardType::None};
  256. auto mustache_type{MustacheType::None};
  257. if ((mustache_and_beard_flag & BeardAndMustacheFlag::Beard) ==
  258. BeardAndMustacheFlag::Beard) {
  259. beard_type = GetRandomValue<BeardType>(BeardType::Beard1, BeardType::Beard5);
  260. }
  261. if ((mustache_and_beard_flag & BeardAndMustacheFlag::Mustache) ==
  262. BeardAndMustacheFlag::Mustache) {
  263. mustache_type =
  264. GetRandomValue<MustacheType>(MustacheType::Mustache1, MustacheType::Mustache5);
  265. }
  266. bf.mustache_type.Assign(mustache_type);
  267. bf.beard_type.Assign(beard_type);
  268. bf.mustache_y.Assign(10);
  269. } else {
  270. bf.mustache_type.Assign(MustacheType::None);
  271. bf.beard_type.Assign(BeardType::None);
  272. bf.mustache_y.Assign(axis_y + 10);
  273. }
  274. const auto glasses_type_start{GetRandomValue<std::size_t>(100)};
  275. u8 glasses_type{};
  276. while (glasses_type_start < glasses_type_info.values[glasses_type]) {
  277. if (++glasses_type >= glasses_type_info.values_count) {
  278. UNREACHABLE();
  279. break;
  280. }
  281. }
  282. bf.glasses_type.Assign(glasses_type);
  283. bf.glasses_color.Assign(GlassesColorLookup[0]);
  284. bf.glasses_scale.Assign(4);
  285. bf.glasses_y.Assign(axis_y + 10);
  286. bf.mole_type.Assign(0);
  287. bf.mole_scale.Assign(4);
  288. bf.mole_x.Assign(2);
  289. bf.mole_y.Assign(20);
  290. return {DefaultMiiName, bf, user_id};
  291. }
  292. MiiStoreData BuildDefaultStoreData(const DefaultMii& info, const Common::UUID& user_id) {
  293. MiiStoreBitFields bf{};
  294. bf.font_region.Assign(info.font_region);
  295. bf.favorite_color.Assign(info.favorite_color);
  296. bf.gender.Assign(info.gender);
  297. bf.height.Assign(info.height);
  298. bf.build.Assign(info.weight);
  299. bf.type.Assign(info.type);
  300. bf.region_move.Assign(info.region);
  301. bf.faceline_type.Assign(info.face_type);
  302. bf.faceline_color.Assign(info.face_color);
  303. bf.faceline_wrinkle.Assign(info.face_wrinkle);
  304. bf.faceline_makeup.Assign(info.face_makeup);
  305. bf.hair_type.Assign(info.hair_type);
  306. bf.hair_color.Assign(HairColorLookup[info.hair_color]);
  307. bf.hair_flip.Assign(static_cast<HairFlip>(info.hair_flip));
  308. bf.eye_type.Assign(info.eye_type);
  309. bf.eye_color.Assign(EyeColorLookup[info.eye_color]);
  310. bf.eye_scale.Assign(info.eye_scale);
  311. bf.eye_aspect.Assign(info.eye_aspect);
  312. bf.eye_rotate.Assign(info.eye_rotate);
  313. bf.eye_x.Assign(info.eye_x);
  314. bf.eye_y.Assign(info.eye_y);
  315. bf.eyebrow_type.Assign(info.eyebrow_type);
  316. bf.eyebrow_color.Assign(HairColorLookup[info.eyebrow_color]);
  317. bf.eyebrow_scale.Assign(info.eyebrow_scale);
  318. bf.eyebrow_aspect.Assign(info.eyebrow_aspect);
  319. bf.eyebrow_rotate.Assign(info.eyebrow_rotate);
  320. bf.eyebrow_x.Assign(info.eyebrow_x);
  321. bf.eyebrow_y.Assign(info.eyebrow_y - 3);
  322. bf.nose_type.Assign(info.nose_type);
  323. bf.nose_scale.Assign(info.nose_scale);
  324. bf.nose_y.Assign(info.nose_y);
  325. bf.mouth_type.Assign(info.mouth_type);
  326. bf.mouth_color.Assign(MouthColorLookup[info.mouth_color]);
  327. bf.mouth_scale.Assign(info.mouth_scale);
  328. bf.mouth_aspect.Assign(info.mouth_aspect);
  329. bf.mouth_y.Assign(info.mouth_y);
  330. bf.beard_color.Assign(HairColorLookup[info.beard_color]);
  331. bf.beard_type.Assign(static_cast<BeardType>(info.beard_type));
  332. bf.mustache_type.Assign(static_cast<MustacheType>(info.mustache_type));
  333. bf.mustache_scale.Assign(info.mustache_scale);
  334. bf.mustache_y.Assign(info.mustache_y);
  335. bf.glasses_type.Assign(info.glasses_type);
  336. bf.glasses_color.Assign(GlassesColorLookup[info.glasses_color]);
  337. bf.glasses_scale.Assign(info.glasses_scale);
  338. bf.glasses_y.Assign(info.glasses_y);
  339. bf.mole_type.Assign(info.mole_type);
  340. bf.mole_scale.Assign(info.mole_scale);
  341. bf.mole_x.Assign(info.mole_x);
  342. bf.mole_y.Assign(info.mole_y);
  343. return {DefaultMiiName, bf, user_id};
  344. }
  345. } // namespace
  346. MiiStoreData::MiiStoreData() = default;
  347. MiiStoreData::MiiStoreData(const MiiStoreData::Name& name, const MiiStoreBitFields& bit_fields,
  348. const Common::UUID& user_id) {
  349. data.name = name;
  350. data.uuid = GenerateValidUUID();
  351. std::memcpy(data.data.data(), &bit_fields, sizeof(MiiStoreBitFields));
  352. data_crc = GenerateCrc16(data.data.data(), sizeof(data));
  353. device_crc = GenerateCrc16(&user_id, sizeof(Common::UUID));
  354. }
  355. MiiManager::MiiManager() : user_id{Service::Account::ProfileManager().GetLastOpenedUser()} {}
  356. bool MiiManager::CheckAndResetUpdateCounter(SourceFlag source_flag, u64& current_update_counter) {
  357. if ((source_flag & SourceFlag::Database) == SourceFlag::None) {
  358. return false;
  359. }
  360. const bool result{current_update_counter != update_counter};
  361. current_update_counter = update_counter;
  362. return result;
  363. }
  364. bool MiiManager::IsFullDatabase() const {
  365. // TODO(bunnei): We don't implement the Mii database, so it cannot be full
  366. return false;
  367. }
  368. u32 MiiManager::GetCount(SourceFlag source_flag) const {
  369. u32 count{};
  370. if ((source_flag & SourceFlag::Database) != SourceFlag::None) {
  371. // TODO(bunnei): We don't implement the Mii database, but when we do, update this
  372. count += 0;
  373. }
  374. if ((source_flag & SourceFlag::Default) != SourceFlag::None) {
  375. count += DefaultMiiCount;
  376. }
  377. return count;
  378. }
  379. ResultVal<MiiInfo> MiiManager::UpdateLatest([[maybe_unused]] const MiiInfo& info,
  380. SourceFlag source_flag) {
  381. if ((source_flag & SourceFlag::Database) == SourceFlag::None) {
  382. return ERROR_CANNOT_FIND_ENTRY;
  383. }
  384. // TODO(bunnei): We don't implement the Mii database, so we can't have an entry
  385. return ERROR_CANNOT_FIND_ENTRY;
  386. }
  387. MiiInfo MiiManager::BuildRandom(Age age, Gender gender, Race race) {
  388. return ConvertStoreDataToInfo(BuildRandomStoreData(age, gender, race, user_id));
  389. }
  390. MiiInfo MiiManager::BuildDefault(std::size_t index) {
  391. return ConvertStoreDataToInfo(BuildDefaultStoreData(
  392. GetArrayValue<DefaultMii>(RawData::DefaultMii.data(), index), user_id));
  393. }
  394. ResultVal<std::vector<MiiInfoElement>> MiiManager::GetDefault(SourceFlag source_flag) {
  395. std::vector<MiiInfoElement> result;
  396. if ((source_flag & SourceFlag::Default) == SourceFlag::None) {
  397. return MakeResult(std::move(result));
  398. }
  399. for (std::size_t index = 0; index < DefaultMiiCount; index++) {
  400. result.emplace_back(BuildDefault(index), Source::Default);
  401. }
  402. return MakeResult(std::move(result));
  403. }
  404. ResultCode MiiManager::GetIndex([[maybe_unused]] const MiiInfo& info, u32& index) {
  405. constexpr u32 INVALID_INDEX{0xFFFFFFFF};
  406. index = INVALID_INDEX;
  407. // TODO(bunnei): We don't implement the Mii database, so we can't have an index
  408. return ERROR_CANNOT_FIND_ENTRY;
  409. }
  410. } // namespace Service::Mii