Merge pull request #5774 from ogniK5377/mii-raw-random

mii: Fix BuildRandomStoreData & Cleanup raw_data
This commit is contained in:
bunnei 2021-01-25 16:41:20 -08:00 committed by GitHub
commit 64a5548454
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 1657 additions and 2274 deletions

View file

@ -21,7 +21,7 @@ namespace {
constexpr ResultCode ERROR_CANNOT_FIND_ENTRY{ErrorModule::Mii, 4}; constexpr ResultCode ERROR_CANNOT_FIND_ENTRY{ErrorModule::Mii, 4};
constexpr std::size_t DefaultMiiCount{sizeof(RawData::DefaultMii) / sizeof(DefaultMii)}; constexpr std::size_t DefaultMiiCount{RawData::DefaultMii.size()};
constexpr MiiStoreData::Name DefaultMiiName{u'y', u'u', u'z', u'u'}; constexpr MiiStoreData::Name DefaultMiiName{u'y', u'u', u'z', u'u'};
constexpr std::array<u8, 8> HairColorLookup{8, 1, 2, 3, 4, 5, 6, 7}; constexpr std::array<u8, 8> HairColorLookup{8, 1, 2, 3, 4, 5, 6, 7};
@ -141,13 +141,6 @@ T GetRandomValue(T max) {
return GetRandomValue<T>({}, max); return GetRandomValue<T>({}, max);
} }
template <typename T>
T GetArrayValue(const u8* data, std::size_t index) {
T result{};
std::memcpy(&result, &data[index * sizeof(T)], sizeof(T));
return result;
}
MiiStoreData BuildRandomStoreData(Age age, Gender gender, Race race, const Common::UUID& user_id) { MiiStoreData BuildRandomStoreData(Age age, Gender gender, Race race, const Common::UUID& user_id) {
MiiStoreBitFields bf{}; MiiStoreBitFields bf{};
@ -193,32 +186,20 @@ MiiStoreData BuildRandomStoreData(Age age, Gender gender, Race race, const Commo
const std::size_t index{3 * static_cast<std::size_t>(age) + const std::size_t index{3 * static_cast<std::size_t>(age) +
9 * static_cast<std::size_t>(gender) + static_cast<std::size_t>(race)}; 9 * static_cast<std::size_t>(gender) + static_cast<std::size_t>(race)};
const auto faceline_type_info{ const auto faceline_type_info{RawData::RandomMiiFaceline.at(index)};
GetArrayValue<RandomMiiData4>(&RawData::RandomMiiFaceline[0], index)}; const auto faceline_color_info{RawData::RandomMiiFacelineColor.at(
const auto faceline_color_info{GetArrayValue<RandomMiiData3>(
RawData::RandomMiiFacelineColor.data(),
3 * static_cast<std::size_t>(gender) + static_cast<std::size_t>(race))}; 3 * static_cast<std::size_t>(gender) + static_cast<std::size_t>(race))};
const auto faceline_wrinkle_info{ const auto faceline_wrinkle_info{RawData::RandomMiiFacelineWrinkle.at(index)};
GetArrayValue<RandomMiiData4>(RawData::RandomMiiFacelineWrinkle.data(), index)}; const auto faceline_makeup_info{RawData::RandomMiiFacelineMakeup.at(index)};
const auto faceline_makeup_info{ const auto hair_type_info{RawData::RandomMiiHairType.at(index)};
GetArrayValue<RandomMiiData4>(RawData::RandomMiiFacelineMakeup.data(), index)}; const auto hair_color_info{RawData::RandomMiiHairColor.at(3 * static_cast<std::size_t>(race) +
const auto hair_type_info{ static_cast<std::size_t>(age))};
GetArrayValue<RandomMiiData4>(RawData::RandomMiiHairType.data(), index)}; const auto eye_type_info{RawData::RandomMiiEyeType.at(index)};
const auto hair_color_info{GetArrayValue<RandomMiiData3>(RawData::RandomMiiHairColor.data(), const auto eye_color_info{RawData::RandomMiiEyeColor.at(static_cast<std::size_t>(race))};
3 * static_cast<std::size_t>(race) + const auto eyebrow_type_info{RawData::RandomMiiEyebrowType.at(index)};
static_cast<std::size_t>(age))}; const auto nose_type_info{RawData::RandomMiiNoseType.at(index)};
const auto eye_type_info{ const auto mouth_type_info{RawData::RandomMiiMouthType.at(index)};
GetArrayValue<RandomMiiData4>(RawData::RandomMiiEyeType.data(), index)}; const auto glasses_type_info{RawData::RandomMiiGlassType.at(static_cast<std::size_t>(age))};
const auto eye_color_info{GetArrayValue<RandomMiiData2>(RawData::RandomMiiEyeColor.data(),
static_cast<std::size_t>(race))};
const auto eyebrow_type_info{
GetArrayValue<RandomMiiData4>(RawData::RandomMiiEyebrowType.data(), index)};
const auto nose_type_info{
GetArrayValue<RandomMiiData4>(RawData::RandomMiiNoseType.data(), index)};
const auto mouth_type_info{
GetArrayValue<RandomMiiData4>(RawData::RandomMiiMouthType.data(), index)};
const auto glasses_type_info{GetArrayValue<RandomMiiData2>(RawData::RandomMiiGlassType.data(),
static_cast<std::size_t>(age))};
bf.faceline_type.Assign( bf.faceline_type.Assign(
faceline_type_info.values[GetRandomValue<std::size_t>(faceline_type_info.values_count)]); faceline_type_info.values[GetRandomValue<std::size_t>(faceline_type_info.values_count)]);
@ -455,8 +436,7 @@ MiiInfo MiiManager::BuildRandom(Age age, Gender gender, Race race) {
} }
MiiInfo MiiManager::BuildDefault(std::size_t index) { MiiInfo MiiManager::BuildDefault(std::size_t index) {
return ConvertStoreDataToInfo(BuildDefaultStoreData( return ConvertStoreDataToInfo(BuildDefaultStoreData(RawData::DefaultMii.at(index), user_id));
GetArrayValue<DefaultMii>(RawData::DefaultMii.data(), index), user_id));
} }
ResultVal<std::vector<MiiInfoElement>> MiiManager::GetDefault(SourceFlag source_flag) { ResultVal<std::vector<MiiInfoElement>> MiiManager::GetDefault(SourceFlag source_flag) {

View file

@ -233,7 +233,7 @@ struct RandomMiiData4 {
Age age{}; Age age{};
Race race{}; Race race{};
u32 values_count{}; u32 values_count{};
std::array<u8, 0xbc> values{}; std::array<u32, 47> values{};
}; };
static_assert(sizeof(RandomMiiData4) == 0xcc, "RandomMiiData4 has incorrect size."); static_assert(sizeof(RandomMiiData4) == 0xcc, "RandomMiiData4 has incorrect size.");
@ -241,14 +241,14 @@ struct RandomMiiData3 {
u32 arg_1; u32 arg_1;
u32 arg_2; u32 arg_2;
u32 values_count; u32 values_count;
std::array<u8, 0xbc> values{}; std::array<u32, 47> values{};
}; };
static_assert(sizeof(RandomMiiData3) == 0xc8, "RandomMiiData3 has incorrect size."); static_assert(sizeof(RandomMiiData3) == 0xc8, "RandomMiiData3 has incorrect size.");
struct RandomMiiData2 { struct RandomMiiData2 {
u32 arg_1; u32 arg_1;
u32 values_count; u32 values_count;
std::array<u8, 0xbc> values{}; std::array<u32, 47> values{};
}; };
static_assert(sizeof(RandomMiiData2) == 0xc4, "RandomMiiData2 has incorrect size."); static_assert(sizeof(RandomMiiData2) == 0xc4, "RandomMiiData2 has incorrect size.");

File diff suppressed because it is too large Load diff

View file

@ -7,21 +7,22 @@
#include <array> #include <array>
#include "common/common_types.h" #include "common/common_types.h"
#include "core/hle/service/mii/manager.h"
namespace Service::Mii::RawData { namespace Service::Mii::RawData {
extern const std::array<u8, 1728> DefaultMii; extern const std::array<Service::Mii::DefaultMii, 8> DefaultMii;
extern const std::array<u8, 3672> RandomMiiFaceline; extern const std::array<Service::Mii::RandomMiiData4, 18> RandomMiiFaceline;
extern const std::array<u8, 1200> RandomMiiFacelineColor; extern const std::array<Service::Mii::RandomMiiData3, 6> RandomMiiFacelineColor;
extern const std::array<u8, 3672> RandomMiiFacelineWrinkle; extern const std::array<Service::Mii::RandomMiiData4, 18> RandomMiiFacelineWrinkle;
extern const std::array<u8, 3672> RandomMiiFacelineMakeup; extern const std::array<Service::Mii::RandomMiiData4, 18> RandomMiiFacelineMakeup;
extern const std::array<u8, 3672> RandomMiiHairType; extern const std::array<Service::Mii::RandomMiiData4, 18> RandomMiiHairType;
extern const std::array<u8, 1800> RandomMiiHairColor; extern const std::array<Service::Mii::RandomMiiData3, 9> RandomMiiHairColor;
extern const std::array<u8, 3672> RandomMiiEyeType; extern const std::array<Service::Mii::RandomMiiData4, 18> RandomMiiEyeType;
extern const std::array<u8, 588> RandomMiiEyeColor; extern const std::array<Service::Mii::RandomMiiData2, 3> RandomMiiEyeColor;
extern const std::array<u8, 3672> RandomMiiEyebrowType; extern const std::array<Service::Mii::RandomMiiData4, 18> RandomMiiEyebrowType;
extern const std::array<u8, 3672> RandomMiiNoseType; extern const std::array<Service::Mii::RandomMiiData4, 18> RandomMiiNoseType;
extern const std::array<u8, 3672> RandomMiiMouthType; extern const std::array<Service::Mii::RandomMiiData4, 18> RandomMiiMouthType;
extern const std::array<u8, 588> RandomMiiGlassType; extern const std::array<Service::Mii::RandomMiiData2, 3> RandomMiiGlassType;
} // namespace Service::Mii::RawData } // namespace Service::Mii::RawData