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")
: QString::fromStdString(config.title));
miis.push_back(
HLE::Applets::MiiSelector::GetStandardMiiResult().selected_mii_data.GetMiiData());
miis.push_back(HLE::Applets::MiiSelector::GetStandardMiiResult().selected_mii_data);
combobox->addItem(tr("Standard Mii"));
for (const auto& mii : Frontend::LoadMiis()) {
miis.push_back(mii);

View File

@ -53,7 +53,7 @@ std::vector<Mii::MiiData> LoadMiis() {
void DefaultMiiSelector::Setup(const Frontend::MiiSelectorConfig& 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

View File

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

View File

@ -433,6 +433,7 @@ struct RegisterInfoPrivate {
INSERT_PADDING_BYTES(0x28);
};
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>,
"RegisterInfoPrivate must be trivially copyable.");