-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.h
362 lines (309 loc) · 9.92 KB
/
main.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
#include <iostream>
#include <fstream>
#include <boost/crc.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include "bit_field.h"
#include <iomanip>
#include <sstream>
#include <string>
constexpr u32 FRIEND_SCREEN_NAME_SIZE = 0xB; ///< 11-short UTF-16 screen name
constexpr u32 FRIEND_COMMENT_SIZE = 0x10; ///< 16-short UTF-16 comment
constexpr u32 FRIEND_GAME_MODE_DESCRIPTION_SIZE = 0x80; ///< 128-short UTF-16 description
constexpr u32 FRIEND_LIST_SIZE = 0x64;
constexpr u32 MAGIC_NUMBER = 0x20101021;
#pragma pack(push, 1)
// Reference: https://github.com/devkitPro/libctru/blob/master/libctru/include/3ds/mii.h
class MiiData {
public:
u8 magic{}; ///< Always 3?
/// Mii options
union {
u8 raw;
BitField<0, 1, u8> allow_copying; ///< True if copying is allowed
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 position in Mii selector or Mii maker
union {
u8 raw;
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{};
/// Console Identity
union {
u8 raw;
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{};
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 {
u16_be raw;
BitField<0, 1, u16> sex; ///< Sex of Mii (False=Male, True=Female)
BitField<1, 4, u16> bday_month; ///< Month 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<14, 1, u16> favorite; ///< Whether the Mii is one of your 10 favorite Mii's
} 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
/// Face style
union {
u8 raw;
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 details
union {
u8 raw;
BitField<0, 4, u8> wrinkles;
BitField<4, 4, u8> makeup;
} face_details{};
u8 hair_style{};
/// Hair details
union {
u8 raw;
BitField<0, 3, u8> color;
BitField<3, 1, u8> flip;
} hair_details{};
/// Eye details
union {
u32_be raw;
BitField<0, 6, u32> style;
BitField<6, 3, u32> color;
BitField<9, 4, u32> scale;
BitField<13, 3, u32> yscale;
BitField<16, 5, u32> rotation;
BitField<21, 4, u32> xspacing;
BitField<25, 5, u32> yposition;
} eye_details{};
/// Eyebrow details
union {
u32_be raw;
BitField<0, 5, u32> style;
BitField<5, 3, u32> color;
BitField<8, 4, u32> scale;
BitField<12, 3, u32> yscale;
BitField<15, 1, u32> pad;
BitField<16, 5, u32> rotation;
BitField<21, 4, u32> xspacing;
BitField<25, 5, u32> yposition;
} eyebrow_details{};
/// Nose details
union {
u16_be raw;
BitField<0, 5, u16> style;
BitField<5, 4, u16> scale;
BitField<9, 5, u16> yposition;
} nose_details{};
/// Mouth details
union {
u16_be raw;
BitField<0, 6, u16> style;
BitField<6, 3, u16> color;
BitField<9, 4, u16> scale;
BitField<13, 3, u16> yscale;
} mouth_details{};
/// Mustache details
union {
u16_be raw;
BitField<0, 5, u16> mouth_yposition;
BitField<5, 3, u16> mustach_style;
BitField<8, 2, u16> pad;
} mustache_details{};
/// Beard details
union {
u16_be raw;
BitField<0, 3, u16> style;
BitField<3, 3, u16> color;
BitField<6, 4, u16> scale;
BitField<10, 5, u16> ypos;
} beard_details{};
/// Glasses details
union {
u16_be raw;
BitField<0, 4, u16> style;
BitField<4, 3, u16> color;
BitField<7, 4, u16> scale;
BitField<11, 5, u16> ypos;
} glasses_details{};
/// Mole details
union {
u16_be raw;
BitField<0, 1, u16> enable;
BitField<1, 5, u16> scale;
BitField<6, 5, u16> xpos;
BitField<11, 5, u16> ypos;
} mole_details{};
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) {
ar& magic;
ar& mii_options.raw;
ar& mii_pos.raw;
ar& console_identity.raw;
u64 system_id_ = system_id;
ar& system_id_;
system_id = system_id_;
u32 mii_id_ = mii_id;
ar& mii_id_;
mii_id = mii_id_;
ar& mac;
ar& pad;
u16 mii_details_ = mii_details.raw;
ar& mii_details_;
mii_details.raw = mii_details_;
ar& mii_name;
ar& height;
ar& width;
ar& face_style.raw;
ar& face_details.raw;
ar& hair_style;
ar& hair_details.raw;
u32 eye_details_ = eye_details.raw;
ar& eye_details_;
eye_details.raw = eye_details_;
u32 eyebrow_details_ = eyebrow_details.raw;
ar& eyebrow_details_;
eyebrow_details.raw = eyebrow_details_;
u16 nose_details_ = nose_details.raw;
ar& nose_details_;
nose_details.raw = nose_details_;
u16 mouth_details_ = mouth_details.raw;
ar& mouth_details_;
mouth_details.raw = mouth_details_;
u16 mustache_details_ = mustache_details.raw;
ar& mustache_details_;
mustache_details.raw = mustache_details_;
u16 beard_details_ = beard_details.raw;
ar& beard_details_;
beard_details.raw = beard_details_;
u16 glasses_details_ = glasses_details.raw;
ar& glasses_details_;
glasses_details.raw = glasses_details_;
u16 mole_details_ = mole_details.raw;
ar& mole_details_;
mole_details.raw = mole_details_;
ar& author_name;
}
friend class boost::serialization::access;
};
static_assert(sizeof(MiiData) == 0x5C, "MiiData structure has incorrect size");
class ChecksummedMiiData {
public:
ChecksummedMiiData() {
FixChecksum();
}
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();
return *this;
}
ChecksummedMiiData& operator=(MiiData&& data) {
mii_data = std::move(data);
FixChecksum();
return *this;
}
MiiData& GetMiiData() {
return mii_data;
}
bool IsChecksumValid() {
return crc16 == CalcChecksum();
}
u16 CalcChecksum();
MiiData mii_data{};
u16_be unknown{0};
u16_be crc16;
private:
void FixChecksum() {
crc16 = CalcChecksum();
}
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& mii_data;
u16 unknown_ = unknown;
ar& unknown_;
unknown = unknown_;
u16 crc16_ = crc16;
ar& crc16_;
crc16 = crc16_;
}
friend class boost::serialization::access;
};
#pragma pack(pop)
static_assert(sizeof(ChecksummedMiiData) == 0x60,
"ChecksummedMiiData structure has incorrect size");
struct FriendProfile {
u8 region{};
u8 country{};
u8 area{};
u8 language{};
u8 platform{};
std::array<u8, 3> padding{};
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& region;
ar& country;
ar& area;
ar& language;
ar& platform;
ar& padding;
}
friend class boost::serialization::access;
};
struct FRDMyData {
static constexpr u32 MAGIC_MY_DATA = 0x46504D44;
u32_le magic{MAGIC_MY_DATA};
u32_le magic_number{MAGIC_NUMBER};
u64_le padding1{};
std::array<u8, 0x20> unk10{};
std::array<u16_le, FRIEND_COMMENT_SIZE> comment{};
u64_le unk50{}; // likely padding
FriendProfile profile{};
u64_le local_friend_code_seed{};
std::array<u16_le, 0xD> unk68{}; // utf16 hex identifier?
std::array<u16_le, 0x10> serial_number{};
std::array<u16_le, FRIEND_SCREEN_NAME_SIZE> display_name{};
std::array<u8, 3> padding2{};
ChecksummedMiiData mii_data{};
std::array<u8, 5> padding3{};
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& magic;
ar& magic_number;
ar& padding1;
ar& unk10;
ar& comment;
ar& unk50;
ar& profile;
ar& local_friend_code_seed;
ar& unk68;
ar& serial_number;
ar& display_name;
ar& padding2;
ar& mii_data;
ar& padding3;
}
friend class boost::serialization::access;
};