Make mii classes trivial and add cast operator

This commit is contained in:
PabloMK7 2023-07-28 13:36:55 +02:00
parent 7143b0652a
commit bbd923d7a7
4 changed files with 37 additions and 46 deletions

View File

@ -27,8 +27,7 @@ QtMiiSelectorDialog::QtMiiSelectorDialog(QWidget* parent, QtMiiSelector* mii_sel
? tr("Mii Selector") ? tr("Mii Selector")
: QString::fromStdString(config.title)); : QString::fromStdString(config.title));
miis.push_back( miis.push_back(HLE::Applets::MiiSelector::GetStandardMiiResult().selected_mii_data);
HLE::Applets::MiiSelector::GetStandardMiiResult().selected_mii_data.GetMiiData());
combobox->addItem(tr("Standard Mii")); combobox->addItem(tr("Standard Mii"));
for (const auto& mii : Frontend::LoadMiis()) { for (const auto& mii : Frontend::LoadMiis()) {
miis.push_back(mii); miis.push_back(mii);

View File

@ -53,7 +53,7 @@ std::vector<Mii::MiiData> LoadMiis() {
void DefaultMiiSelector::Setup(const Frontend::MiiSelectorConfig& config) { void DefaultMiiSelector::Setup(const Frontend::MiiSelectorConfig& config) {
MiiSelector::Setup(config); MiiSelector::Setup(config);
Finalize(0, HLE::Applets::MiiSelector::GetStandardMiiResult().selected_mii_data.GetMiiData()); Finalize(0, HLE::Applets::MiiSelector::GetStandardMiiResult().selected_mii_data);
} }
} // namespace Frontend } // namespace Frontend

View File

@ -11,7 +11,7 @@ namespace Mii {
// Reference: https://github.com/devkitPro/libctru/blob/master/libctru/include/3ds/mii.h // Reference: https://github.com/devkitPro/libctru/blob/master/libctru/include/3ds/mii.h
class MiiData { class MiiData {
public: public:
u8 magic{}; ///< Always 3? u8 magic; ///< Always 3?
/// Mii options /// Mii options
union { union {
@ -21,7 +21,7 @@ public:
BitField<1, 1, u8> is_private_name; ///< Private name? BitField<1, 1, u8> is_private_name; ///< Private name?
BitField<2, 2, u8> region_lock; ///< Region lock (0=no lock, 1=JPN, 2=USA, 3=EUR) BitField<2, 2, u8> region_lock; ///< Region lock (0=no lock, 1=JPN, 2=USA, 3=EUR)
BitField<4, 2, u8> char_set; ///< Character set (0=JPN+USA+EUR, 1=CHN, 2=KOR, 3=TWN) BitField<4, 2, u8> char_set; ///< Character set (0=JPN+USA+EUR, 1=CHN, 2=KOR, 3=TWN)
} mii_options{}; } mii_options;
/// Mii position in Mii selector or Mii maker /// Mii position in Mii selector or Mii maker
union { union {
@ -29,7 +29,7 @@ public:
BitField<0, 4, u8> page_index; ///< Page index of Mii BitField<0, 4, u8> page_index; ///< Page index of Mii
BitField<4, 4, u8> slot_index; ///< Slot offset of Mii on its Page BitField<4, 4, u8> slot_index; ///< Slot offset of Mii on its Page
} mii_pos{}; } mii_pos;
/// Console Identity /// Console Identity
union { union {
@ -38,12 +38,12 @@ public:
BitField<0, 4, u8> unknown0; ///< Mabye padding (always seems to be 0)? BitField<0, 4, u8> unknown0; ///< Mabye padding (always seems to be 0)?
BitField<4, 3, u8> BitField<4, 3, u8>
origin_console; ///< Console that the Mii was created on (1=WII, 2=DSI, 3=3DS) origin_console; ///< Console that the Mii was created on (1=WII, 2=DSI, 3=3DS)
} console_identity{}; } console_identity;
u64_be system_id{}; ///< Identifies the system that the Mii was created on (Determines pants) u64_be system_id; ///< Identifies the system that the Mii was created on (Determines pants)
u32_be mii_id{}; ///< ID of Mii u32_be mii_id; ///< ID of Mii
std::array<u8, 6> mac{}; ///< Creator's system's full MAC address std::array<u8, 6> mac; ///< Creator's system's full MAC address
u16 pad{}; ///< Padding u16 pad; ///< Padding
/// Mii details /// Mii details
union { union {
@ -54,11 +54,11 @@ public:
BitField<5, 5, u16> bday_day; ///< Day of Mii's birthday BitField<5, 5, u16> bday_day; ///< Day of Mii's birthday
BitField<10, 4, u16> shirt_color; ///< Color of Mii's shirt BitField<10, 4, u16> shirt_color; ///< Color of Mii's shirt
BitField<14, 1, u16> favorite; ///< Whether the Mii is one of your 10 favorite Mii's BitField<14, 1, u16> favorite; ///< Whether the Mii is one of your 10 favorite Mii's
} mii_details{}; } mii_details;
std::array<u16_le, 10> mii_name{}; ///< Name of Mii (Encoded using UTF16) std::array<u16_le, 10> mii_name; ///< Name of Mii (Encoded using UTF16)
u8 height{}; ///< How tall the Mii is u8 height; ///< How tall the Mii is
u8 width{}; ///< How wide the Mii is u8 width; ///< How wide the Mii is
/// Face style /// Face style
union { union {
@ -67,7 +67,7 @@ public:
BitField<0, 1, u8> disable_sharing; ///< Whether or not Sharing of the Mii is allowed BitField<0, 1, u8> disable_sharing; ///< Whether or not Sharing of the Mii is allowed
BitField<1, 4, u8> shape; ///< Face shape BitField<1, 4, u8> shape; ///< Face shape
BitField<5, 3, u8> skin_color; ///< Color of skin BitField<5, 3, u8> skin_color; ///< Color of skin
} face_style{}; } face_style;
/// Face details /// Face details
union { union {
@ -75,9 +75,9 @@ public:
BitField<0, 4, u8> wrinkles; BitField<0, 4, u8> wrinkles;
BitField<4, 4, u8> makeup; BitField<4, 4, u8> makeup;
} face_details{}; } face_details;
u8 hair_style{}; u8 hair_style;
/// Hair details /// Hair details
union { union {
@ -85,7 +85,7 @@ public:
BitField<0, 3, u8> color; BitField<0, 3, u8> color;
BitField<3, 1, u8> flip; BitField<3, 1, u8> flip;
} hair_details{}; } hair_details;
/// Eye details /// Eye details
union { union {
@ -98,7 +98,7 @@ public:
BitField<16, 5, u32> rotation; BitField<16, 5, u32> rotation;
BitField<21, 4, u32> xspacing; BitField<21, 4, u32> xspacing;
BitField<25, 5, u32> yposition; BitField<25, 5, u32> yposition;
} eye_details{}; } eye_details;
/// Eyebrow details /// Eyebrow details
union { union {
@ -112,7 +112,7 @@ public:
BitField<16, 5, u32> rotation; BitField<16, 5, u32> rotation;
BitField<21, 4, u32> xspacing; BitField<21, 4, u32> xspacing;
BitField<25, 5, u32> yposition; BitField<25, 5, u32> yposition;
} eyebrow_details{}; } eyebrow_details;
/// Nose details /// Nose details
union { union {
@ -121,7 +121,7 @@ public:
BitField<0, 5, u16> style; BitField<0, 5, u16> style;
BitField<5, 4, u16> scale; BitField<5, 4, u16> scale;
BitField<9, 5, u16> yposition; BitField<9, 5, u16> yposition;
} nose_details{}; } nose_details;
/// Mouth details /// Mouth details
union { union {
@ -131,7 +131,7 @@ public:
BitField<6, 3, u16> color; BitField<6, 3, u16> color;
BitField<9, 4, u16> scale; BitField<9, 4, u16> scale;
BitField<13, 3, u16> yscale; BitField<13, 3, u16> yscale;
} mouth_details{}; } mouth_details;
/// Mustache details /// Mustache details
union { union {
@ -140,7 +140,7 @@ public:
BitField<0, 5, u16> mouth_yposition; BitField<0, 5, u16> mouth_yposition;
BitField<5, 3, u16> mustach_style; BitField<5, 3, u16> mustach_style;
BitField<8, 2, u16> pad; BitField<8, 2, u16> pad;
} mustache_details{}; } mustache_details;
/// Beard details /// Beard details
union { union {
@ -150,7 +150,7 @@ public:
BitField<3, 3, u16> color; BitField<3, 3, u16> color;
BitField<6, 4, u16> scale; BitField<6, 4, u16> scale;
BitField<10, 5, u16> ypos; BitField<10, 5, u16> ypos;
} beard_details{}; } beard_details;
/// Glasses details /// Glasses details
union { union {
@ -160,7 +160,7 @@ public:
BitField<4, 3, u16> color; BitField<4, 3, u16> color;
BitField<7, 4, u16> scale; BitField<7, 4, u16> scale;
BitField<11, 5, u16> ypos; BitField<11, 5, u16> ypos;
} glasses_details{}; } glasses_details;
/// Mole details /// Mole details
union { union {
@ -170,9 +170,9 @@ public:
BitField<1, 5, u16> scale; BitField<1, 5, u16> scale;
BitField<6, 5, u16> xpos; BitField<6, 5, u16> xpos;
BitField<11, 5, u16> ypos; BitField<11, 5, u16> ypos;
} mole_details{}; } mole_details;
std::array<u16_le, 10> author_name{}; ///< Name of Mii's author (Encoded using UTF16) std::array<u16_le, 10> author_name; ///< Name of Mii's author (Encoded using UTF16)
private: private:
template <class Archive> template <class Archive>
void serialize(Archive& ar, const unsigned int) { void serialize(Archive& ar, const unsigned int) {
@ -182,23 +182,11 @@ private:
}; };
static_assert(sizeof(MiiData) == 0x5C, "MiiData structure has incorrect size"); static_assert(sizeof(MiiData) == 0x5C, "MiiData structure has incorrect size");
static_assert(std::is_trivial_v<MiiData>, "MiiData must be trivial.");
static_assert(std::is_trivially_copyable_v<MiiData>, "MiiData must be trivially copyable.");
class ChecksummedMiiData { class ChecksummedMiiData {
public: public:
ChecksummedMiiData() = default;
ChecksummedMiiData(const ChecksummedMiiData& data) = default;
ChecksummedMiiData(ChecksummedMiiData&& data) = default;
ChecksummedMiiData& operator=(const ChecksummedMiiData&) = default;
ChecksummedMiiData& operator=(ChecksummedMiiData&&) = default;
ChecksummedMiiData(const MiiData& data) : mii_data(data) {
FixChecksum();
}
ChecksummedMiiData(MiiData&& data) : mii_data(data) {
FixChecksum();
}
ChecksummedMiiData& operator=(const MiiData& data) { ChecksummedMiiData& operator=(const MiiData& data) {
mii_data = data; mii_data = data;
FixChecksum(); FixChecksum();
@ -211,7 +199,7 @@ public:
return *this; return *this;
} }
MiiData& GetMiiData() { operator MiiData() const {
return mii_data; return mii_data;
} }
@ -226,9 +214,9 @@ public:
} }
private: private:
MiiData mii_data{}; MiiData mii_data;
[[maybe_unused]] INSERT_PADDING_BYTES(0x2){}; [[maybe_unused]] INSERT_PADDING_BYTES(0x2);
u16_be crc16{}; u16_be crc16;
template <class Archive> template <class Archive>
void serialize(Archive& ar, const unsigned int) { void serialize(Archive& ar, const unsigned int) {
@ -239,4 +227,7 @@ private:
#pragma pack(pop) #pragma pack(pop)
static_assert(sizeof(ChecksummedMiiData) == 0x60, static_assert(sizeof(ChecksummedMiiData) == 0x60,
"ChecksummedMiiData structure has incorrect size"); "ChecksummedMiiData structure has incorrect size");
static_assert(std::is_trivial_v<ChecksummedMiiData>, "ChecksummedMiiData must be trivial.");
static_assert(std::is_trivially_copyable_v<ChecksummedMiiData>,
"ChecksummedMiiData must be trivially copyable.");
} // namespace Mii } // namespace Mii

View File

@ -433,6 +433,7 @@ struct RegisterInfoPrivate {
INSERT_PADDING_BYTES(0x28); INSERT_PADDING_BYTES(0x28);
}; };
static_assert(sizeof(RegisterInfoPrivate) == 0xA4, "RegisterInfoPrivate is an invalid size"); static_assert(sizeof(RegisterInfoPrivate) == 0xA4, "RegisterInfoPrivate is an invalid size");
static_assert(std::is_trivial_v<RegisterInfoPrivate>, "RegisterInfoPrivate must be trivial.");
static_assert(std::is_trivially_copyable_v<RegisterInfoPrivate>, static_assert(std::is_trivially_copyable_v<RegisterInfoPrivate>,
"RegisterInfoPrivate must be trivially copyable."); "RegisterInfoPrivate must be trivially copyable.");