xc3_lib 0.21.0

Xenoblade Chronicles file format library
Documentation
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
//! User interface [Mibl](crate::mibl::Mibl) images in `.wilay` files.
//!
//! # File Paths
//! Xenoblade 1 and some Xenoblade 3 `.wilay` [Lagp] are in [Xbc1](crate::xbc1::Xbc1) archives.
//!
//! | Game | Versions | File Patterns |
//! | --- | --- | --- |
//! | Xenoblade 1 DE | 10002, 10003 | `menu/image/*.wilay` |
//! | Xenoblade 2 |  | |
//! | Xenoblade 3 | 10003 | `menu/image/*.wilay` |
//! | Xenoblade X DE | 10003 | `ui/image/*.wilay` |
use crate::{
    dhal::{Textures, Unk1, Unk2, Unk3, Unk4, Unk5, Unk6},
    parse_count32_offset32, parse_offset32_count32, parse_opt_ptr32, parse_ptr32,
    parse_string_ptr32,
};
use binrw::{BinRead, NullString, args, binread};
use xc3_write::{
    Xc3Write, Xc3WriteOffsets,
    strings::{StringSectionUnique, WriteOptions},
};

// TODO: How much of this is shared with LAHD?
#[binread]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, Xc3Write, PartialEq, Clone)]
#[br(magic(b"LAGP"))]
#[xc3(magic(b"LAGP"))]
pub struct Lagp {
    // TODO: enum?
    pub version: u32,
    // TODO: Different values than dhal?
    pub unk0: u32, // 0, 64, 256, 320?

    #[br(temp, restore_position)]
    offsets: [u32; 13],

    #[br(parse_with = parse_ptr32)]
    #[xc3(offset(u32), align(16))]
    pub unk1: Unk1,

    #[br(parse_with = parse_ptr32)]
    #[xc3(offset(u32), align(1))]
    pub unk2: Unk2,

    #[br(parse_with = parse_opt_ptr32)]
    #[xc3(offset(u32), align(4))]
    pub unk3: Option<Unk3>,

    // TODO: this isn't correct for 10002 for XC1 DE.
    #[br(parse_with = parse_opt_ptr32)]
    #[br(args { inner: args! { offset: offsets[0], version } })]
    #[xc3(offset(u32), align(16))]
    pub unk4: Option<Unk4>,

    #[br(parse_with = parse_opt_ptr32)]
    #[xc3(offset(u32))]
    pub unk5: Option<Unk5>,

    #[br(parse_with = parse_opt_ptr32)]
    #[xc3(offset(u32))]
    pub unk6: Option<Unk6>,

    #[br(parse_with = parse_opt_ptr32)]
    #[xc3(offset(u32), align(1))]
    pub textures: Option<Textures>,

    pub unk8: u32,
    pub unk9: u32,
    pub unk10: u32,
    pub unk11: u32,

    pub unk12: u32,

    #[br(parse_with = parse_opt_ptr32)]
    #[br(args { inner: version })]
    #[xc3(offset(u32), align(1))]
    pub unk13: Option<Unk13Versioned>,

    // TODO: padding?
    pub unk: [u32; 11],
}

#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, BinRead, Xc3Write, Xc3WriteOffsets, PartialEq, Clone)]
#[br(import_raw(version: u32))]
pub enum Unk13Versioned {
    #[br(pre_assert(version > 10002))]
    Modern(Unk13),

    #[br(pre_assert(version == 10002))]
    Legacy(Unk13Legacy),
}

// TODO: fix writing.
#[binread]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, Xc3Write, PartialEq, Clone)]
#[br(stream = r)]
#[xc3(base_offset)]
pub struct Unk13 {
    #[br(temp, try_calc = r.stream_position())]
    base_offset: u64,

    #[br(parse_with = parse_offset32_count32)]
    #[br(args { offset: base_offset, inner: base_offset })]
    #[xc3(offset_count(u32, u32), align(1))]
    pub unk1: Vec<Unk13Unk1>,

    #[br(parse_with = parse_opt_ptr32, offset = base_offset)]
    #[xc3(offset(u32), align(1))]
    pub unk2: Option<Unk13Unk2>,

    #[br(parse_with = parse_opt_ptr32)]
    #[br(args { offset: base_offset, inner: args! { count: unk13_unk3_count(unk2.as_ref()) } })]
    #[xc3(offset(u32), align(1))]
    pub unk3: Option<Vec<u16>>,

    // TODO: padding?
    pub unk: [u32; 4],
}

#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, BinRead, Xc3Write, PartialEq, Clone)]
#[br(import_raw(base_offset: u64))]
pub struct Unk13Unk1 {
    pub unk1: u32,

    #[br(parse_with = parse_ptr32, offset = base_offset)]
    #[xc3(offset(u32), align(1))]
    pub unk2: Unk13Unk1Unk2,

    #[br(parse_with = parse_opt_ptr32, offset = base_offset)]
    #[xc3(offset(u32), align(1))]
    pub unk3: Option<Unk13Unk1Unk3>,

    #[br(parse_with = parse_ptr32, offset = base_offset)]
    #[xc3(offset(u32), align(1))]
    pub unk4: Unk13Unk1Unk4,

    #[br(parse_with = parse_opt_ptr32)]
    #[br(args { offset: base_offset, inner: base_offset })]
    #[xc3(offset(u32), align(1))]
    pub unk5: Option<Unk13Unk1Unk5>,

    #[br(parse_with = parse_opt_ptr32, offset = base_offset)]
    #[xc3(offset(u32), align(1))]
    pub unk6: Option<Unk13Unk1Unk6>,

    #[br(parse_with = parse_string_ptr32, offset = base_offset)]
    #[xc3(offset(u32), align(1))]
    pub unk7: String,
}

#[binread]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, Xc3Write, Xc3WriteOffsets, PartialEq, Clone)]
#[br(stream = r)]
#[xc3(base_offset)]
pub struct Unk13Unk1Unk2 {
    #[br(temp, try_calc = r.stream_position())]
    base_offset: u64,

    #[br(parse_with = parse_offset32_count32, offset = base_offset)]
    #[xc3(offset_count(u32, u32), align(1))]
    pub items: Vec<[u32; 2]>,
}

#[binread]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, Xc3Write, Xc3WriteOffsets, PartialEq, Clone)]
#[br(stream = r)]
#[xc3(base_offset)]
pub struct Unk13Unk1Unk3 {
    #[br(temp, try_calc = r.stream_position())]
    base_offset: u64,

    pub unk1: u32,

    #[br(parse_with = parse_offset32_count32)]
    #[br(args { offset: base_offset, inner: base_offset })]
    #[xc3(offset_count(u32, u32), align(1))]
    pub unk2: Vec<Unk13Unk1Unk3Unk2>,

    // TODO: padding?
    pub unk: [u32; 12],
}

// TODO: data is similar to Unk8ItemInner but with offsets?
#[binread]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, Xc3Write, PartialEq, Clone)]
#[br(import_raw(base_offset: u64))]
pub struct Unk13Unk1Unk3Unk2 {
    pub unk1: u32,
    pub unk2: u32,
    pub unk3: u32,

    #[br(temp, restore_position)]
    offsets: [u32; 3],

    // TODO: Does this have a count field?
    #[br(parse_with = parse_ptr32)]
    #[br(args { offset: base_offset, inner: args! { count: (offsets[2] / 2) as usize }})]
    #[xc3(offset(u32), align(1))]
    pub unk4: Vec<u16>,

    pub unk5: u32,

    // Relative to the start of unk4 data.
    #[br(parse_with = parse_ptr32, offset = base_offset + offsets[0] as u64)]
    #[xc3(offset(u32), align(1))]
    pub unk6: UnkString,

    pub unk7: f32,

    // TODO: padding?
    pub unk: [u32; 4],
}

#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, BinRead, PartialEq, Clone)]
pub struct UnkString(#[br(map(|x: NullString| x.to_string()))] pub String);

// TODO: padding after some of the arrays?
#[binread]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, Xc3Write, PartialEq, Clone)]
#[br(stream = r)]
#[xc3(base_offset)]
pub struct Unk13Unk1Unk4 {
    #[br(temp, try_calc = r.stream_position())]
    base_offset: u64,

    #[br(parse_with = parse_count32_offset32, offset = base_offset)]
    #[xc3(count_offset(u32, u32), align(1))]
    pub unk1: Vec<Unk13Unk1Unk4Unk1>,

    #[br(parse_with = parse_count32_offset32, offset = base_offset)]
    #[xc3(count_offset(u32, u32), align(1))]
    pub unk2: Vec<u16>,

    #[br(parse_with = parse_count32_offset32, offset = base_offset)]
    #[xc3(count_offset(u32, u32), align(1))]
    pub unk3: Vec<u16>,

    #[br(parse_with = parse_count32_offset32, offset = base_offset)]
    #[xc3(count_offset(u32, u32), align(1))]
    pub unk4: Vec<u16>,

    // TODO: padding?
    pub unk: [u32; 8],
}

#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, BinRead, Xc3Write, Xc3WriteOffsets, PartialEq, Clone)]
pub struct Unk13Unk1Unk4Unk1 {
    pub unk1: u32,
    pub unk2: u16, // TODO: index?
    pub unk3: u16, // TODO: index?
    pub unk4: u32, // TODO: index?
}

#[binread]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, Xc3Write, Xc3WriteOffsets, PartialEq, Clone)]
#[br(stream = r)]
#[br(import_raw(parent_base_offset: u64))]
#[xc3(base_offset)]
pub struct Unk13Unk1Unk5 {
    #[br(temp, try_calc = r.stream_position())]
    base_offset: u64,

    #[br(parse_with = parse_count32_offset32)]
    #[br(args { offset: base_offset, inner: parent_base_offset })]
    #[xc3(count_offset(u32, u32), align(1))]
    pub items: Vec<Unk13Unk1Unk5Item>,
}

#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, BinRead, Xc3Write, Xc3WriteOffsets, PartialEq, Clone)]
#[br(import_raw(base_offset: u64))]
pub struct Unk13Unk1Unk5Item {
    #[br(parse_with = parse_string_ptr32, offset = base_offset)]
    #[xc3(offset(u32))]
    pub unk1: String,
    pub unk2: u32, // index?
    pub unk3: f32,
    pub unk4: f32,
    pub unk5: f32,
    pub unk6: f32,
    pub unk7: u32,
    pub unk8: u32,
}

#[binread]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, Xc3Write, Xc3WriteOffsets, PartialEq, Clone)]
#[br(stream = r)]
#[xc3(base_offset)]
pub struct Unk13Unk1Unk6 {
    #[br(temp, try_calc = r.stream_position())]
    base_offset: u64,

    #[br(parse_with = parse_offset32_count32, offset = base_offset)]
    #[xc3(offset_count(u32, u32), align(1))]
    pub items: Vec<[i32; 5]>,

    // TODO: Padding?
    pub unk: [u32; 4],
}

#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, BinRead, Xc3Write, Xc3WriteOffsets, PartialEq, Clone)]
pub struct Unk13Unk2 {
    pub count1: u32,
    pub unk2: u32,
    pub total_count: u32,
    pub unk4: i32,
    pub unk5: [u32; 4],

    #[br(count = count1)]
    pub items1: Vec<[u32; 8]>,

    // TODO: is this the correct count?
    #[br(count = total_count - count1)]
    pub items2: Vec<[u32; 8]>,
}

fn unk13_unk3_count(unk2: Option<&Unk13Unk2>) -> usize {
    unk2.map(|u| u.total_count as usize + 1).unwrap_or_default()
}

#[binread]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, Xc3Write, PartialEq, Clone)]
#[br(stream = r)]
#[xc3(base_offset)]
pub struct Unk13Legacy {
    #[br(temp, try_calc = r.stream_position())]
    base_offset: u64,

    #[br(parse_with = parse_offset32_count32)]
    #[br(args { offset: base_offset, inner: base_offset })]
    #[xc3(offset_count(u32, u32), align(1))]
    pub unk1: Vec<Unk13Unk1Legacy>,

    // TODO: padding?
    pub unk: [u32; 4],
}

#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, BinRead, Xc3Write, Xc3WriteOffsets, PartialEq, Clone)]
#[br(import_raw(base_offset: u64))]
pub struct Unk13Unk1Legacy {
    pub unk1: u32,

    #[br(parse_with = parse_ptr32, offset = base_offset)]
    #[xc3(offset(u32), align(1))]
    pub unk2: Unk13Unk1Unk2,

    #[br(parse_with = parse_opt_ptr32, offset = base_offset)]
    #[xc3(offset(u32), align(1))]
    pub unk3: Option<Unk13Unk1Unk3>,

    #[br(parse_with = parse_ptr32, offset = base_offset)]
    #[xc3(offset(u32), align(1))]
    pub unk4: Unk13Unk1Unk4,

    #[br(parse_with = parse_opt_ptr32)]
    #[br(args { offset: base_offset, inner: base_offset })]
    #[xc3(offset(u32), align(1))]
    pub unk5: Option<Unk13Unk1Unk5Legacy>,

    #[br(parse_with = parse_opt_ptr32, offset = base_offset)]
    #[xc3(offset(u32), align(1))]
    pub unk6: Option<Unk13Unk1Unk6>,

    #[br(parse_with = parse_string_ptr32, offset = base_offset)]
    #[xc3(offset(u32), align(1))]
    pub unk7: String,
}

#[binread]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, Xc3Write, Xc3WriteOffsets, PartialEq, Clone)]
#[br(stream = r)]
#[br(import_raw(parent_base_offset: u64))]
#[xc3(base_offset)]
pub struct Unk13Unk1Unk5Legacy {
    #[br(temp, try_calc = r.stream_position())]
    base_offset: u64,

    #[br(parse_with = parse_count32_offset32)]
    #[br(args { offset: base_offset, inner: parent_base_offset })]
    #[xc3(count_offset(u32, u32), align(1))]
    pub items: Vec<Unk13Unk1Unk5ItemLegacy>,
}

#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, BinRead, Xc3Write, Xc3WriteOffsets, PartialEq, Clone)]
#[br(import_raw(base_offset: u64))]
pub struct Unk13Unk1Unk5ItemLegacy {
    #[br(parse_with = parse_string_ptr32, offset = base_offset)]
    #[xc3(offset(u32))]
    pub unk1: String,
    pub unk2: u32, // index?
    pub unk3: f32,
    pub unk4: f32,
    pub unk5: f32,
    pub unk6: f32,
    pub unk7: u32,
}

// TODO: identical to dhal?
impl Xc3WriteOffsets for LagpOffsets<'_> {
    type Args = ();

    fn write_offsets<W: std::io::prelude::Write + std::io::prelude::Seek>(
        &self,
        writer: &mut W,
        base_offset: u64,
        data_ptr: &mut u64,
        endian: xc3_write::Endian,
        _args: Self::Args,
    ) -> xc3_write::Xc3Result<()> {
        // Different order than field order.
        self.unk1
            .write_full(writer, base_offset, data_ptr, endian, ())?;
        self.unk3
            .write_full(writer, base_offset, data_ptr, endian, ())?;
        self.unk4
            .write_full(writer, base_offset, data_ptr, endian, ())?;
        self.unk13
            .write_full(writer, base_offset, data_ptr, endian, ())?;
        self.unk2
            .write_full(writer, base_offset, data_ptr, endian, ())?;
        self.unk5
            .write_full(writer, base_offset, data_ptr, endian, ())?;
        self.unk6
            .write_full(writer, base_offset, data_ptr, endian, ())?;
        self.textures
            .write_full(writer, base_offset, data_ptr, endian, ())?;
        Ok(())
    }
}

impl Xc3WriteOffsets for Unk13Offsets<'_> {
    type Args = ();

    fn write_offsets<W: std::io::prelude::Write + std::io::prelude::Seek>(
        &self,
        writer: &mut W,
        _base_offset: u64,
        data_ptr: &mut u64,
        endian: xc3_write::Endian,
        _args: Self::Args,
    ) -> xc3_write::Xc3Result<()> {
        let base_offset = self.base_offset;

        // Some strings are grouped at the end.
        // Strings should use insertion order instead of alphabetical.
        let mut string_section = StringSectionUnique::default();

        let unk1 = self.unk1.write(writer, base_offset, data_ptr, endian)?;
        for u in &unk1.0 {
            u.unk6
                .write_full(writer, base_offset, data_ptr, endian, ())?;
            u.unk2
                .write_full(writer, base_offset, data_ptr, endian, ())?;
            u.unk4
                .write_full(writer, base_offset, data_ptr, endian, ())?;
            string_section.insert_offset32(&u.unk7);
            if let Some(unk5) = u.unk5.write(writer, base_offset, data_ptr, endian)? {
                let base_offset = unk5.base_offset;
                let items = unk5.items.write(writer, base_offset, data_ptr, endian)?;
                for item in items.0 {
                    string_section.insert_offset32(&item.unk1);
                }
            }
            u.unk3
                .write_full(writer, base_offset, data_ptr, endian, ())?;
        }

        self.unk2
            .write_full(writer, base_offset, data_ptr, endian, ())?;
        self.unk3
            .write_full(writer, base_offset, data_ptr, endian, ())?;

        string_section.write(
            writer,
            base_offset,
            data_ptr,
            &WriteOptions::default(),
            endian,
        )?;

        // TODO: why is this padding necessary?
        *data_ptr += 3;

        Ok(())
    }
}

impl Xc3WriteOffsets for Unk13Unk1Unk3Unk2Offsets<'_> {
    type Args = ();

    fn write_offsets<W: std::io::prelude::Write + std::io::prelude::Seek>(
        &self,
        writer: &mut W,
        base_offset: u64,
        data_ptr: &mut u64,
        endian: xc3_write::Endian,
        _args: Self::Args,
    ) -> xc3_write::Xc3Result<()> {
        // The string offset is relative to the start of unk4 data.
        let string_start = *data_ptr;
        self.unk4
            .write_full(writer, base_offset, data_ptr, endian, ())?;
        self.unk6
            .write_full(writer, string_start, data_ptr, endian, ())?;
        Ok(())
    }
}

impl Xc3WriteOffsets for Unk13Unk1Unk4Offsets<'_> {
    type Args = ();

    fn write_offsets<W: std::io::prelude::Write + std::io::prelude::Seek>(
        &self,
        writer: &mut W,
        _base_offset: u64,
        data_ptr: &mut u64,
        endian: xc3_write::Endian,
        _args: Self::Args,
    ) -> xc3_write::Xc3Result<()> {
        let base_offset = self.base_offset;
        self.unk1
            .write_full(writer, base_offset, data_ptr, endian, ())?;
        if !self.unk2.data.is_empty() {
            self.unk2
                .write_full(writer, base_offset, data_ptr, endian, ())?;
        }
        if !self.unk3.data.is_empty() {
            self.unk3
                .write_full(writer, base_offset, data_ptr, endian, ())?;
            // TODO: why is this padding necessary?
            *data_ptr += 2;
        }
        if !self.unk4.data.is_empty() {
            self.unk4
                .write_full(writer, base_offset, data_ptr, endian, ())?;
        }
        Ok(())
    }
}

impl Xc3Write for UnkString {
    type Offsets<'a> = ();

    fn xc3_write<W: std::io::prelude::Write + std::io::prelude::Seek>(
        &self,
        writer: &mut W,
        endian: xc3_write::Endian,
    ) -> xc3_write::Xc3Result<Self::Offsets<'_>> {
        // TODO: Add align_size_to attribute to xc3_write_derive?
        // TODO: Just use binwrite for this?
        let start = writer.stream_position()?;
        self.0.xc3_write(writer, endian)?;
        let end = writer.stream_position()?;

        let size = end - start;
        let aligned_size = size.next_multiple_of(4);
        vec![0u8; (aligned_size - size) as usize].xc3_write(writer, endian)?;
        Ok(())
    }
}

impl Xc3WriteOffsets for Unk13LegacyOffsets<'_> {
    type Args = ();

    fn write_offsets<W: std::io::prelude::Write + std::io::prelude::Seek>(
        &self,
        writer: &mut W,
        _base_offset: u64,
        data_ptr: &mut u64,
        endian: xc3_write::Endian,
        _args: Self::Args,
    ) -> xc3_write::Xc3Result<()> {
        let base_offset = self.base_offset;

        // Some strings are grouped at the end.
        // Strings should use insertion order instead of alphabetical.
        let mut string_section = StringSectionUnique::default();

        let unk1 = self.unk1.write(writer, base_offset, data_ptr, endian)?;
        for u in &unk1.0 {
            u.unk6
                .write_full(writer, base_offset, data_ptr, endian, ())?;
            u.unk2
                .write_full(writer, base_offset, data_ptr, endian, ())?;
            u.unk4
                .write_full(writer, base_offset, data_ptr, endian, ())?;
            string_section.insert_offset32(&u.unk7);
            if let Some(unk5) = u.unk5.write(writer, base_offset, data_ptr, endian)? {
                let base_offset = unk5.base_offset;
                let items = unk5.items.write(writer, base_offset, data_ptr, endian)?;
                for item in items.0 {
                    string_section.insert_offset32(&item.unk1);
                }
            }
            u.unk3
                .write_full(writer, base_offset, data_ptr, endian, ())?;
        }

        string_section.write(
            writer,
            base_offset,
            data_ptr,
            &WriteOptions::default(),
            endian,
        )?;
        Ok(())
    }
}