physis 0.6.0

Library for reading and writing FFXIV data.
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
// SPDX-FileCopyrightText: 2024 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later

#![allow(unused_variables)] // just binrw things with br(temp)

use std::io::{Read, Seek, SeekFrom};

use crate::common_file_operations::{read_bool_from, write_bool_as};
use crate::string_heap::{HeapPointer, HeapString, StringHeap};
use binrw::{BinRead, BinReaderExt};
use binrw::{Endian, binrw};

mod aetheryte;
pub use aetheryte::AetheryteInstanceObject;

mod bg;
pub use bg::{BGInstanceObject, ModelCollisionType};

mod collision;
pub use collision::{CollisionBoxInstanceObject, TriggerBoxInstanceObject, TriggerBoxShape};

mod common;
pub use common::{Color, ColorHDRI, GameInstanceObject};

mod env;
pub use env::{EnvLocationObject, EnvSetInstanceObject, EnvSetShape};

mod event;
pub use event::EventInstanceObject;

mod gathering;
pub use gathering::GatheringInstanceObject;

mod light;
pub use light::{LightInstanceObject, LightType, PointLightType};

mod marker;
pub use marker::{
    ChairMarkerInstanceObject, ChairType, PositionMarkerInstanceObject, PositionMarkerType,
    QuestMarkerInstanceObject, TargetMarkerInstanceObject, TargetMarkerType,
};

mod npc;
pub use npc::{BNPCInstanceObject, ENPCInstanceObject, NPCInstanceObject};

mod path;
pub use path::{
    ClientPathInstanceObject, PathControlPoint, PathInstanceObject, ServerPathInstanceObject,
};

mod range;
pub use range::{
    ClickableRangeInstanceObject, DoorRangeInstanceObject, EventRangeInstanceObject,
    ExitRangeInstanceObject, ExitType, FateRangeInstanceObject, GimmickRangeInstanceObject,
    MapRangeInstanceObject, PopRangeInstanceObject, PopType, PrefetchRangeInstanceObject,
};

mod shared_group;
pub use shared_group::{
    ColourState, DoorState, RotationState, SharedGroupInstance, TransformState,
};

mod sound;
pub use sound::SoundInstanceObject;

mod transformation;
pub use transformation::Transformation;

mod treasure;
pub use treasure::TreasureInstanceObject;

mod vfx;
pub use vfx::{LineStyle, LineVFXInstanceObject, VFXInstanceObject};

// From https://github.com/NotAdam/Lumina/tree/40dab50183eb7ddc28344378baccc2d63ae71d35/src/Lumina/Data/Parsing/Layer
// Also see https://github.com/aers/FFXIVClientStructs/blob/6b62122cae38bfbc016bf697bef75f80f37abac1/FFXIVClientStructs/FFXIV/Client/LayoutEngine/ILayoutInstance.cs

// TODO: convert these all to magic
#[binrw]
#[brw(repr = i32)]
#[repr(i32)]
#[derive(Debug, PartialEq)]
pub enum LayerEntryType {
    None = 0x0,
    BG = 0x1,
    Attribute = 0x2,
    LayLight = 0x3,
    Vfx = 0x4,
    PositionMarker = 0x5,
    SharedGroup = 0x6,
    Sound = 0x7,
    EventNPC = 0x8,
    BattleNPC = 0x9,
    RoutePath = 0xA,
    Character = 0xB,
    Aetheryte = 0xC,
    EnvSet = 0xD,
    Gathering = 0xE,
    HelperObject = 0xF,
    Treasure = 0x10,
    Clip = 0x11,
    ClipCtrlPoint = 0x12,
    ClipCamera = 0x13,
    ClipLight = 0x14,
    ClipReserve00 = 0x15,
    ClipReserve01 = 0x16,
    ClipReserve02 = 0x17,
    ClipReserve03 = 0x18,
    ClipReserve04 = 0x19,
    ClipReserve05 = 0x1A,
    ClipReserve06 = 0x1B,
    ClipReserve07 = 0x1C,
    ClipReserve08 = 0x1D,
    ClipReserve09 = 0x1E,
    ClipReserve10 = 0x1F,
    ClipReserve11 = 0x20,
    ClipReserve12 = 0x21,
    ClipReserve13 = 0x22,
    ClipReserve14 = 0x23,
    CutAssetOnlySelectable = 0x24,
    Player = 0x25,
    Monster = 0x26,
    Weapon = 0x27,
    PopRange = 0x28,
    /// Zone Transitions (the visible part is probably LineVFX?)
    ExitRange = 0x29,
    Lvb = 0x2A,
    MapRange = 0x2B,
    NaviMeshRange = 0x2C,
    EventObject = 0x2D,
    DemiHuman = 0x2E,
    EnvLocation = 0x2F,
    ControlPoint = 0x30,
    EventRange = 0x31,
    RestBonusRange = 0x32,
    QuestMarker = 0x33,
    Timeline = 0x34,
    ObjectBehaviorSet = 0x35,
    Movie = 0x36,
    ScenarioExd = 0x37,
    ScenarioText = 0x38,
    CollisionBox = 0x39,
    DoorRange = 0x3A,
    LineVFX = 0x3B,
    SoundEnvSet = 0x3C,
    CutActionTimeline = 0x3D,
    CharaScene = 0x3E,
    CutAction = 0x3F,
    EquipPreset = 0x40,
    ClientPath = 0x41,
    ServerPath = 0x42,
    GimmickRange = 0x43,
    TargetMarker = 0x44,
    ChairMarker = 0x45,
    ClickableRange = 0x46,
    PrefetchRange = 0x47,
    FateRange = 0x48,
    PartyMember = 0x49,
    KeepRange = 0x4A,
    SphereCastRange = 0x4B,
    IndoorObject = 0x4C,
    OutdoorObject = 0x4D,
    EditGroup = 0x4E,
    StableChocobo = 0x4F,
    Unk4 = 0x53, // seen in bg/ex5/01_xkt_x6/twn/x6t1/level/bg.lgb
    Unk2 = 0x56, // seen in bg/ex5/02_ykt_y6/fld/y6f1/level/bg.lgb
    Unk5 = 0x57, // seen in bg/ex2/05_zon_z3/rad/z3r3/level/planmap.lgb
    Unk3 = 0x59, // seen in bg/ffxiv/sea_s1/fld/s1f3/level/planevent.lgb
    Unk1 = 0x5A, // Culling related?
}

#[binrw]
#[derive(Debug, PartialEq)]
#[br(import(magic: &LayerEntryType, string_heap: &StringHeap, heap_pointer: HeapPointer))]
#[bw(import(string_heap: &mut StringHeap))]
pub enum LayerEntryData {
    /// Representing nothing.
    #[br(pre_assert(*magic == LayerEntryType::None))]
    None,
    /// Background model.
    #[br(pre_assert(*magic == LayerEntryType::BG))]
    BG(
        #[br(args(string_heap, heap_pointer))]
        #[bw(args(string_heap))]
        BGInstanceObject,
    ),
    /// Light source.
    #[br(pre_assert(*magic == LayerEntryType::LayLight))]
    LayLight(LightInstanceObject),
    /// Visual effect.
    #[br(pre_assert(*magic == LayerEntryType::Vfx))]
    Vfx(
        #[br(args(string_heap, heap_pointer))]
        #[bw(args(string_heap))]
        VFXInstanceObject,
    ),
    /// Unknown purpose.
    #[br(pre_assert(*magic == LayerEntryType::PositionMarker))]
    PositionMarker(PositionMarkerInstanceObject),
    /// Instance of a prefab.
    #[br(pre_assert(*magic == LayerEntryType::SharedGroup))]
    SharedGroup(
        #[br(args(string_heap, heap_pointer))]
        #[bw(args(string_heap))]
        SharedGroupInstance,
    ),
    /// Unknown purpose.
    #[br(pre_assert(*magic == LayerEntryType::Sound))]
    Sound(
        #[br(args(string_heap, heap_pointer))]
        #[bw(args(string_heap))]
        SoundInstanceObject,
    ),
    /// Event NPC.
    #[br(pre_assert(*magic == LayerEntryType::EventNPC))]
    EventNPC(ENPCInstanceObject),
    /// Battle NPC.
    #[br(pre_assert(*magic == LayerEntryType::BattleNPC))]
    BattleNPC(BNPCInstanceObject),
    /// Aetheryte.
    #[br(pre_assert(*magic == LayerEntryType::Aetheryte))]
    Aetheryte(AetheryteInstanceObject),
    /// Unknown purpose.
    #[br(pre_assert(*magic == LayerEntryType::EnvSet))]
    EnvSet(
        #[br(args(string_heap, heap_pointer))]
        #[bw(args(string_heap))]
        EnvSetInstanceObject,
    ),
    /// Unknown purpose.
    #[br(pre_assert(*magic == LayerEntryType::Gathering))]
    Gathering(GatheringInstanceObject),
    /// Unknown purpose.
    #[br(pre_assert(*magic == LayerEntryType::Treasure))]
    Treasure(TreasureInstanceObject),
    /// Used for a variety of things, including teleport locations.
    #[br(pre_assert(*magic == LayerEntryType::PopRange))]
    PopRange(PopRangeInstanceObject),
    /// Walkable transitions between zones.
    #[br(pre_assert(*magic == LayerEntryType::ExitRange))]
    ExitRange(ExitRangeInstanceObject),
    /// Locations on the map, such as sanctuaries.
    #[br(pre_assert(*magic == LayerEntryType::MapRange))]
    MapRange(MapRangeInstanceObject),
    /// Event object.
    #[br(pre_assert(*magic == LayerEntryType::EventObject))]
    EventObject(EventInstanceObject),
    /// Unknown purpose.
    #[br(pre_assert(*magic == LayerEntryType::EnvLocation))]
    EnvLocation(
        #[br(args(string_heap, heap_pointer))]
        #[bw(args(string_heap))]
        EnvLocationObject,
    ),
    /// Unknown purpose.
    #[br(pre_assert(*magic == LayerEntryType::EventRange))]
    EventRange(EventRangeInstanceObject),
    /// Unknown purpose.
    #[br(pre_assert(*magic == LayerEntryType::QuestMarker))]
    QuestMarker(QuestMarkerInstanceObject),
    /// Unknown purpose.
    #[br(pre_assert(*magic == LayerEntryType::CollisionBox))]
    CollisionBox(
        #[br(args(string_heap, heap_pointer))]
        #[bw(args(string_heap))]
        CollisionBoxInstanceObject,
    ),
    /// Unknown purpose.
    #[br(pre_assert(*magic == LayerEntryType::LineVFX))]
    LineVFX(LineVFXInstanceObject),
    /// Unknown purpose.
    #[br(pre_assert(*magic == LayerEntryType::ClientPath))]
    ClientPath(ClientPathInstanceObject),
    /// Unknown purpose.
    #[br(pre_assert(*magic == LayerEntryType::ServerPath))]
    ServerPath(ServerPathInstanceObject),
    /// Unknown purpose.
    #[br(pre_assert(*magic == LayerEntryType::GimmickRange))]
    GimmickRange(GimmickRangeInstanceObject),
    /// Unknown purpose.
    #[br(pre_assert(*magic == LayerEntryType::TargetMarker))]
    TargetMarker(TargetMarkerInstanceObject),
    /// Unknown purpose.
    #[br(pre_assert(*magic == LayerEntryType::ChairMarker))]
    ChairMarker(ChairMarkerInstanceObject),
    /// Unknown purpose.
    #[br(pre_assert(*magic == LayerEntryType::ClickableRange))]
    ClickableRange(ClickableRangeInstanceObject),
    /// Unknown purpose.
    #[br(pre_assert(*magic == LayerEntryType::PrefetchRange))]
    PrefetchRange(PrefetchRangeInstanceObject),
    /// Unknown purpose.
    #[br(pre_assert(*magic == LayerEntryType::FateRange))]
    FateRange(FateRangeInstanceObject),
    /// Unknown purpose.
    #[br(pre_assert(*magic == LayerEntryType::Unk1))]
    Unk1(),
    /// Unknown purpose.
    #[br(pre_assert(*magic == LayerEntryType::Unk2))]
    Unk2(),
    /// Unknown purpose.
    #[br(pre_assert(*magic == LayerEntryType::Unk3))]
    Unk3(),
    /// Unknown purpose.
    #[br(pre_assert(*magic == LayerEntryType::Unk4))]
    Unk4(),
    /// Unknown purpose.
    #[br(pre_assert(*magic == LayerEntryType::DoorRange))]
    DoorRange(DoorRangeInstanceObject),
    /// Unhandled or unknown type.
    Unknown(),
}

#[binrw]
#[brw(repr = i32)]
#[derive(Debug, PartialEq)]
pub enum LayerSetReferencedType {
    All = 0x0,
    Include = 0x1,
    Exclude = 0x2,
    Undetermined = 0x3,
}

/// Metadata information for a [Layer].
#[binrw]
#[derive(Debug, PartialEq)]
#[br(import(endianness: Endian, data_heap: &StringHeap, string_heap: &StringHeap), stream = r)]
#[bw(import(data_heap: &mut StringHeap, string_heap: &mut StringHeap))]
#[allow(dead_code)] // most of the fields are unused at the moment
pub struct LayerHeader {
    #[br(temp)]
    #[bw(ignore)]
    heap_pointer: HeapPointer,

    /// ID of this layer.
    pub layer_id: u32,

    /// The name of this layer.
    #[br(args(heap_pointer, string_heap))]
    #[bw(args(string_heap))]
    pub name: HeapString,

    pub(crate) instance_object_offset: i32,
    pub(crate) instance_object_count: i32,

    /// Whether this layer is only visible in tool mode.
    #[br(map = read_bool_from::<u8>)]
    #[bw(map = write_bool_as::<u8>)]
    pub tool_mode_visible: bool,
    /// Whether this layer is supposed to be read-only in tool mode.
    #[br(map = read_bool_from::<u8>)]
    #[bw(map = write_bool_as::<u8>)]
    pub tool_mode_read_only: bool,

    /// Whether this is a bush layer.
    #[br(map = read_bool_from::<u8>)]
    #[bw(map = write_bool_as::<u8>)]
    pub is_bush_layer: bool,

    /// If this layer should be visible on the Playstation 3.
    #[br(map = read_bool_from::<u8>)]
    #[bw(map = write_bool_as::<u8>)]
    pub ps3_visible: bool,

    #[br(temp)]
    #[bw(calc = data_heap.get_free_offset_args(&layer_set_referenced_list))]
    pub(crate) layer_set_referenced_list_offset: i32,

    /// The layer set referenced list.
    #[br(calc = data_heap.read_args(r, endianness, heap_pointer, layer_set_referenced_list_offset))]
    #[bw(ignore)]
    pub layer_set_referenced_list: LayerSetReferencedList,

    /// Only show this layer if this festival ID is active.
    pub festival_id: u16,
    /// Only show this layer if this festival phase ID is active..
    pub festival_phase_id: u16,

    /// Whether this layer is temporary.
    #[br(map = read_bool_from::<u8>)]
    #[bw(map = write_bool_as::<u8>)]
    pub is_temporary: bool,

    /// Whether this is a housing-related layer.
    #[br(map = read_bool_from::<u8>)]
    #[bw(map = write_bool_as::<u8>)]
    pub is_housing: bool,

    /// Unknown purpose, but probably version related.
    pub version_mask: u16,

    #[brw(pad_before = 4)]
    pub(crate) ob_set_referenced_list_offset: i32,
    pub(crate) ob_set_referenced_list_count: i32,

    /// The object set referenced.
    #[br(calc = data_heap.read_vec_args(r, endianness, string_heap, heap_pointer, ob_set_referenced_list_count as usize, ob_set_referenced_list_offset))]
    #[bw(ignore)]
    pub object_set_referenced: Vec<ObjectSetReferenced>,

    pub(crate) ob_set_enable_referenced_list_offset: i32,
    pub(crate) ob_set_enable_referenced_list_count: i32,

    /// The object set enable referenced.
    #[br(calc = data_heap.read_vec_args(r, endianness, string_heap, heap_pointer, ob_set_enable_referenced_list_count as usize, ob_set_enable_referenced_list_offset))]
    #[bw(ignore)]
    pub object_set_enable_referenced: Vec<ObjectSetEnableReferenced>,
}

impl LayerHeader {
    /// Whether this layer set ID is included or excluded.
    pub fn has_layer_set(&self, id: u32) -> bool {
        match self.layer_set_referenced_list.referenced_type {
            LayerSetReferencedType::Include => self
                .layer_set_referenced_list
                .layer_sets
                .iter()
                .any(|x| x.layer_set_id == id),
            LayerSetReferencedType::Exclude => !self
                .layer_set_referenced_list
                .layer_sets
                .iter()
                .any(|x| x.layer_set_id == id),
            LayerSetReferencedType::All => true, // NOTE: This is based on the assumption seen in The Lavender Beds (340)'s pop range in LVD_Zone_01.
            _ => false,                          // Unsure how the other ones should be handled yet
        }
    }
}

#[binrw]
#[derive(Debug, PartialEq)]
#[allow(dead_code)] // most of the fields are unused at the moment
pub struct LayerSetReferenced {
    /// Corresponds to an ID of a [ScnLayerSet](crate::scn::ScnLayerSet).
    pub layer_set_id: u32,
}

#[binrw]
#[br(import(data_heap: &StringHeap), stream = r)]
#[bw(import(data_heap: &mut StringHeap))]
#[derive(Debug, PartialEq)]
pub struct LayerSetReferencedList {
    /// The type of reference.
    pub referenced_type: LayerSetReferencedType,
    #[br(temp)]
    #[bw(calc = data_heap.get_free_offset(&layer_sets))]
    layer_set_offset: i32,
    #[bw(calc = layer_sets.len() as i32)]
    pub layer_set_count: i32,

    #[br(count = layer_set_count)]
    #[bw(ignore)]
    pub layer_sets: Vec<LayerSetReferenced>,
}

#[binrw]
#[br(import(string_heap: &StringHeap), stream = r)]
#[bw(import(string_heap: &mut StringHeap))]
#[derive(Debug, PartialEq)]
pub struct ObjectSetReferenced {
    #[br(temp)]
    #[bw(ignore)]
    heap_pointer: HeapPointer,

    /// The type of InstanceObject of `instance_id`.
    pub asset_type: LayerEntryType,

    /// Instance ID referring to an object within this LGB.
    pub instance_id: u32,

    /// Path to an `.obsb` file.
    #[br(args(heap_pointer, string_heap))]
    #[bw(args(string_heap))]
    pub obsb_path: HeapString,
}

#[binrw]
#[br(import(string_heap: &StringHeap), stream = r)]
#[bw(import(string_heap: &mut StringHeap))]
#[derive(Debug, PartialEq)]
pub struct ObjectSetEnableReferenced {
    pub asset_type: LayerEntryType,
    pub instance_id: u32,
    #[br(map = read_bool_from::<u8>)]
    #[bw(map = write_bool_as::<u8>)]
    pub ob_set_enable: bool,
    #[br(map = read_bool_from::<u8>)]
    #[bw(map = write_bool_as::<u8>)]
    pub ob_set_emissive_enable: bool,
    padding: [u8; 2],
}

/// Represents a single object in a [Layer], which could be anything from a light to an aetheryte.
#[binrw]
#[derive(Debug, PartialEq)]
#[br(import(string_heap: &StringHeap))]
#[bw(import(string_heap: &mut StringHeap))]
#[allow(dead_code)] // most of the fields are unused at the moment
pub struct InstanceObject {
    #[br(temp)]
    #[bw(ignore)]
    heap_pointer: HeapPointer,

    asset_type: LayerEntryType,
    /// The unique ID of this object.
    pub instance_id: u32,
    /// The name of this object.
    #[br(args(heap_pointer, string_heap))]
    #[bw(args(string_heap))]
    pub name: HeapString,
    /// The object's transformation in the world space.
    pub transform: Transformation,
    /// The data associated with this object.
    #[br(args(&asset_type, string_heap, heap_pointer))]
    #[bw(args(string_heap))]
    pub data: LayerEntryData,
}

/// Represents a layer of [InstanceObject].
#[derive(Debug, PartialEq)]
pub struct Layer {
    /// The header for this layer.
    pub header: LayerHeader,
    /// The list of objects contained within this layer.
    pub objects: Vec<InstanceObject>,
}

impl Layer {
    /// Read from `cursor` with `endianness`.
    pub(crate) fn read<T: Read + Seek>(
        endianness: Endian,
        cursor: &mut T,
        data_heap: &StringHeap,
        string_heap: &StringHeap,
    ) -> Option<Layer> {
        let old_pos = cursor.stream_position().unwrap();

        let header =
            LayerHeader::read_options(cursor, endianness, (endianness, data_heap, string_heap))
                .unwrap();

        let mut objects = Vec::new();
        // read instance objects
        {
            let mut instance_offsets = vec![0i32; header.instance_object_count as usize];
            for i in 0..header.instance_object_count {
                instance_offsets[i as usize] =
                    cursor.read_type_args::<i32>(endianness, ()).unwrap();
            }

            for i in 0..header.instance_object_count {
                cursor
                    .seek(SeekFrom::Start(
                        old_pos
                            + header.instance_object_offset as u64
                            + instance_offsets[i as usize] as u64,
                    ))
                    .unwrap();

                let start = cursor.stream_position().unwrap();

                objects
                    .push(InstanceObject::read_options(cursor, endianness, (string_heap,)).ok()?);

                let after_immediate_read = cursor.stream_position().unwrap();

                let next_offset = if i + 1 < header.instance_object_count {
                    old_pos
                        + header.instance_object_offset as u64
                        + instance_offsets[i as usize + 1] as u64
                } else {
                    old_pos + header.ob_set_referenced_list_offset as u64
                };

                let expected_size = next_offset as u64 - start;
                let actual_size = after_immediate_read - start;

                // TODO: remove this once all the objects are fixed!
                // TODO: check if we hit unknown/unhandled data types too
                /*if cfg!(debug_assertions) && expected_size != actual_size {
                    println!(
                        "{:#?} doesn't match the expected size! it's supposed to be {} bytes, but we read {} instead",
                        objects.last(),
                        expected_size,
                        actual_size
                    );
                }*/
            }
        }

        Some(Layer { header, objects })
    }
}