frostbite-formats 0.3.0

Read and write the Frostbite containers and resources of skate. (2025): TOCs, bundles, CAS, EBX documents, shaders, meshes, physics, .fbmod mods
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
//! The field-level readings of EBX documents, shader block depots and bundle manifests, checked over every TOC of the
//! skate. install (`installs.skate/Data`, `tools.oodle9`; about half a minute in release, the TOCs read in parallel):
//!
//! - every distinct EBX payload reads, is written again without a refusal (the 213 stock documents holding a NaN or an
//!   infinity included) and reads back to the same values, floats compared by bits;
//! - the two 64-bit integer codes: a field whose name in the game's own reflection says `Int64` is code 0x11 and one
//!   that says `Uint64` or `U64` is code 0x12, and each reads as the matching `Value` variant;
//! - type references name a slot of the EFIX type list (always inside it), and a slot whose GUID some document of the
//!   install reflects resolves to a type whose name fits the field (`TraitDataTypeRef` names `...TraitData` types);
//! - every enumeration value is named by `Document::enum_member` but one (the census counted 3,368,510 values over 605
//!   enumeration types, one of them naming no member), and no enumeration type is memberless;
//! - the file GUID -> name table (`GuidNames`, built bundle by bundle) names every document of the install, no GUID gets
//!   two names, and it agrees with the file GUIDs read out of the fully decoded documents;
//! - every shader block of every depot parses to its last byte, the blocks with parameter type `0x566e2dd0` included;
//! - a manifest chunk row's size is its stored range's `lsize`, `loff` is a multiple of 65,536, and `loff + lsize` is
//!   the decoded size of the whole chunk in the TOC's chunk table.

#![allow(clippy::unwrap_used)]

mod inputs;

use std::collections::{BTreeMap, BTreeSet, HashSet};
use std::sync::Mutex;
use std::sync::atomic::{AtomicUsize, Ordering};

use frostbite_formats::bundle::Kind;
use frostbite_formats::depot;
use frostbite_formats::ebx::{self, Document, FieldType, Object, TypeRef, Value};
use frostbite_formats::folder::{Folder, Source};
use frostbite_formats::names::GuidNames;
use frostbite_formats::paramdb::{self, KeyUse, ParamNames};
use inputs::{Game, Tool, install_file, tool};
use primase_foundations::compress::oodle::{Oodle, Version};

#[derive(Default)]
struct Tally {
    counts: BTreeMap<&'static str, u64>,
    problems: Vec<String>,
    int64_fields: BTreeSet<String>,
    uint64_fields: BTreeSet<String>,
    /// (field, EFIX GUID) of every type reference to a type of the document, with how many
    refs: BTreeMap<(String, [u8; 16]), u64>,
    /// every reflected type's GUID -> names, over the install
    guid_names: BTreeMap<[u8; 16], BTreeSet<String>>,
    /// the enumeration types (by name) used by a field, and those of them with no member
    enum_types: BTreeSet<String>,
    /// the members (name, value) of every enumeration type used by a field, by type name
    enum_members: BTreeMap<String, Vec<(String, i64)>>,
    memberless_enums: BTreeSet<String>,
    /// every document's file GUID -> its manifest names, as the decoded documents say it
    file_names: BTreeMap<[u8; 16], BTreeSet<String>>,
    /// every import's file GUID, with how many imports name it
    imports: BTreeMap<[u8; 16], u64>,
    /// every non-zero parameter key the documents carry (`ParamDbKeySerialized`), with what stands beside it
    key_uses: Vec<KeyUse>,
    /// every depot parameter's key hash -> the (type, identity) pairs its records carry
    depot_prefix: BTreeMap<u64, BTreeSet<(u32, u16)>>,
}

impl Tally {
    fn n(&mut self, k: &'static str) {
        *self.counts.entry(k).or_default() += 1;
    }
    fn problem(&mut self, s: String) {
        if self.problems.len() < 20 {
            self.problems.push(s);
        }
    }
    fn merge(&mut self, o: Tally) {
        for (k, v) in o.counts {
            *self.counts.entry(k).or_default() += v;
        }
        self.problems.extend(o.problems);
        self.int64_fields.extend(o.int64_fields);
        self.uint64_fields.extend(o.uint64_fields);
        for (k, v) in o.refs {
            *self.refs.entry(k).or_default() += v;
        }
        for (k, v) in o.guid_names {
            self.guid_names.entry(k).or_default().extend(v);
        }
        self.enum_types.extend(o.enum_types);
        self.enum_members.extend(o.enum_members);
        self.memberless_enums.extend(o.memberless_enums);
        for (k, v) in o.file_names {
            self.file_names.entry(k).or_default().extend(v);
        }
        for (k, v) in o.imports {
            *self.imports.entry(k).or_default() += v;
        }
        self.key_uses.extend(o.key_uses);
        for (k, v) in o.depot_prefix {
            self.depot_prefix.entry(k).or_default().extend(v);
        }
    }
}

struct Walk<'a> {
    doc: &'a Document,
    tally: &'a mut Tally,
    name: &'a str,
}

impl Walk<'_> {
    fn object(&mut self, o: &Object) {
        let ty = self.doc.types.get(o.descriptor).map_or("?", |t| t.name.as_str());
        for fv in &o.fields {
            let key = format!("{ty}.{}", fv.name);
            self.value(&key, fv.descriptor, &fv.value);
        }
    }

    fn value(&mut self, key: &str, field: usize, v: &Value) {
        let field_type = self.doc.fields.get(field).map(|f| f.ty());
        match v {
            Value::Object(o) => self.object(o),
            Value::Array(items, _) => items.iter().for_each(|x| self.value(key, field, x)),
            Value::Int(n) if field_type == Some(FieldType::Enumeration) => self.enumeration(field, *n),
            Value::Int(_) | Value::UInt(_) => match (field_type, v) {
                (Some(FieldType::Int64), Value::Int(_)) => self.integer64(key, true),
                (Some(FieldType::UInt64), Value::UInt(_)) => self.integer64(key, false),
                (Some(FieldType::Int64 | FieldType::UInt64), _) => {
                    self.tally.n("64-bit value of the other variant");
                    self.tally.problem(format!("{}: {key} reads as {v:?}", self.name));
                }
                _ => {}
            },
            Value::TypeRef(t) => self.type_ref(key, t),
            _ => {}
        }
    }

    fn enumeration(&mut self, field: usize, value: i64) {
        let doc = self.doc;
        let ty = doc
            .fields
            .get(field)
            .and_then(|f| doc.types.get(usize::from(f.class_ref)));
        let name = ty.map_or("?".to_string(), |t| t.name.clone());
        self.tally.enum_types.insert(name.clone());
        if !self.tally.enum_members.contains_key(&name) {
            let members = doc.enum_members(field).map(|(n, v)| (n.to_string(), v)).collect();
            self.tally.enum_members.insert(name.clone(), members);
        }
        if ty.is_some_and(|t| t.field_count == 0) {
            self.tally.memberless_enums.insert(name.clone());
        }
        self.tally.n("enumeration values");
        match doc.enum_member(field, value) {
            Some(member) => {
                self.tally.n("enumeration values naming a member");
                // the member reads back to the value, and the first member of that value is the one named
                if !doc.enum_members(field).any(|(m, v)| m == member && v == value) {
                    self.tally.n("enumeration members that do not read back");
                }
            }
            None => {
                self.tally.n("enumeration values naming no member");
                self.tally.problem(format!(
                    "{}: enumeration {name} = {value} names no member",
                    self.name
                ));
            }
        }
    }

    fn integer64(&mut self, key: &str, signed: bool) {
        let field = key.rsplit('.').next().unwrap_or(key).to_ascii_lowercase();
        let named_unsigned = field.contains("uint64") || field.contains("u64");
        let named_signed = !named_unsigned && field.contains("int64");
        if (named_unsigned && signed) || (named_signed && !signed) {
            self.tally.n("64-bit field named for the other signedness");
            self.tally.problem(format!(
                "{key} is read as {}",
                if signed { "Int64" } else { "UInt64" }
            ));
        }
        if named_unsigned || named_signed {
            self.tally.n("64-bit fields named for their signedness");
        }
        if signed {
            self.tally.int64_fields.insert(key.to_string());
        } else {
            self.tally.uint64_fields.insert(key.to_string());
        }
    }

    fn type_ref(&mut self, key: &str, t: &TypeRef) {
        if t.encoded == 0 || t.primitive {
            return;
        }
        let doc = self.doc;
        let Some(slot) = t.fixup_type.filter(|&s| s < doc.fixup_type_guids.len()) else {
            self.tally.n("type reference past the EFIX list");
            self.tally
                .problem(format!("{}: {key} names slot {:?}", self.name, t.fixup_type));
            return;
        };
        self.tally.n("type references");
        if t.with_fixup_type(slot) != Some(*t) {
            self.tally
                .n("type reference that with_fixup_type does not give back");
        }
        if let Some(i) = doc.type_ref_target(t) {
            let ty = &doc.types[i];
            if ty.guid != doc.fixup_type_guids[slot] {
                self.tally.n("type reference resolved to another GUID");
            }
            self.tally
                .n("type references resolved by this document's reflection");
        }
        *self
            .tally
            .refs
            .entry((key.to_string(), doc.fixup_type_guids[slot]))
            .or_default() += 1;
        // the slot read as an index into the reflection table instead (what was done before): a different type
        if key.ends_with(".TraitDataTypeRef") {
            self.tally.n("TraitDataTypeRef references");
            if doc
                .types
                .get(slot)
                .is_some_and(|ty| ty.name.ends_with("TraitData"))
            {
                self.tally.n(
                    "TraitDataTypeRef references whose reflection-table entry at the slot is a trait type",
                );
            }
        }
    }
}

/// Values equal, floats by bits; boxed values by their type (the writer lays them out elsewhere).
fn same(a: &Value, b: &Value) -> bool {
    match (a, b) {
        (Value::Float(x), Value::Float(y)) => x.to_bits() == y.to_bits(),
        (Value::Array(x, _), Value::Array(y, _)) => {
            x.len() == y.len() && x.iter().zip(y).all(|(p, q)| same(p, q))
        }
        (Value::Object(x), Value::Object(y)) => same_object(x, y),
        (Value::Boxed(x), Value::Boxed(y)) => x.encoded_type == y.encoded_type,
        _ => a == b,
    }
}

fn same_object(a: &Object, b: &Object) -> bool {
    a.fields.len() == b.fields.len()
        && a.fields
            .iter()
            .zip(&b.fields)
            .all(|(p, q)| p.name == q.name && same(&p.value, &q.value))
}

fn has_non_finite(v: &Value) -> bool {
    match v {
        Value::Float(f) => !f.is_finite(),
        Value::Array(items, _) => items.iter().any(has_non_finite),
        Value::Object(o) => o.fields.iter().any(|f| has_non_finite(&f.value)),
        _ => false,
    }
}

fn document(t: &mut Tally, bytes: &[u8], name: &str) {
    let doc = match ebx::read(bytes) {
        Ok(d) => d,
        Err(e) => {
            t.n("EBX payloads refused by the reader");
            t.problem(format!("{name}: {e}"));
            return;
        }
    };
    t.n("EBX payloads read");
    t.file_names
        .entry(doc.file_guid)
        .or_default()
        .insert(name.to_string());
    for i in &doc.imports {
        *t.imports.entry(i.file_guid).or_default() += 1;
    }
    for ty in &doc.types {
        t.guid_names.entry(ty.guid).or_default().insert(ty.name.clone());
    }
    t.key_uses.extend(paramdb::key_uses(&doc));
    let mut walk = Walk {
        doc: &doc,
        tally: t,
        name,
    };
    for o in doc.instances.iter().filter_map(|i| i.object.as_ref()) {
        walk.object(o);
    }
    let non_finite = doc
        .instances
        .iter()
        .filter_map(|i| i.object.as_ref())
        .any(|o| o.fields.iter().any(|f| has_non_finite(&f.value)));
    if non_finite {
        t.n("documents holding a NaN or an infinity");
    }
    let written = match ebx::write(&doc) {
        Ok(w) => w,
        Err(e) => {
            t.n("EBX payloads refused by the writer");
            t.problem(format!("{name}: {e}"));
            return;
        }
    };
    let Ok(again) = ebx::read(&written) else {
        t.n("rewritten EBX payloads that do not read");
        t.problem(format!("{name}: the rewrite does not read"));
        return;
    };
    let objects = |d: &Document| d.instances.iter().map(|i| i.object.clone()).collect::<Vec<_>>();
    let (a, b) = (objects(&doc), objects(&again));
    let ok = a.len() == b.len()
        && again.file_guid == doc.file_guid
        && a.iter().zip(&b).all(|(x, y)| match (x, y) {
            (Some(x), Some(y)) => same_object(x, y),
            (None, None) => true,
            _ => false,
        });
    if !ok {
        t.n("rewritten EBX payloads that read back to other values");
        t.problem(format!("{name}: the rewrite reads back differently"));
    } else if non_finite {
        t.n("documents with a NaN or an infinity that read back to the same bits");
    }
}

#[test]
fn field_readings_hold_over_the_install() -> Result<(), Box<dyn std::error::Error>> {
    let (Some(data), Some(dll)) = (install_file(Game::Skate, "Data"), tool(Tool::Oodle9)) else {
        return Ok(());
    };
    let folder = Folder::open(data)?;
    // SAFETY: the configuration names the game's own Oodle DLL as tools.oodle9.
    #[allow(unsafe_code)]
    let oodle = unsafe { Oodle::load(dll, Version::V9) }?;
    let src = Source {
        folder: &folder,
        base: Some(&folder),
        oodle: Some(&oodle),
    };
    let tocs = folder.tocs.clone();
    let seen = Mutex::new(HashSet::new());
    let next = AtomicUsize::new(0);
    let total = Mutex::new(Tally::default());
    let names = Mutex::new((GuidNames::new(), 0usize));
    let threads = std::thread::available_parallelism().map_or(4, usize::from).min(8);
    std::thread::scope(|scope| {
        for _ in 0..threads {
            scope.spawn(|| {
                while let Some(toc) = tocs.get(next.fetch_add(1, Ordering::SeqCst)) {
                    let mut t = Tally::default();
                    let listing = match src.listing(toc) {
                        Ok(l) => l,
                        Err(e) => {
                            t.n("TOCs that do not list");
                            t.problem(format!("{toc}: {e}"));
                            total.lock().unwrap().merge(t);
                            continue;
                        }
                    };
                    t.counts.insert("bundles that did not read", listing.unread.len() as u64);
                    let mut local = GuidNames::new();
                    let mut done = std::collections::BTreeSet::new();
                    let mut unreadable = 0;
                    for bundle in &listing.bundles {
                        unreadable += local.add_bundle(&src, bundle, &mut done).unreadable;
                    }
                    {
                        let mut n = names.lock().unwrap();
                        n.0.extend(local);
                        n.1 += unreadable;
                    }
                    for bundle in &listing.bundles {
                        for row in &bundle.manifest.chunks {
                            t.n("manifest chunk rows");
                            if row.size != row.lsize {
                                t.n("chunk rows whose size is not lsize");
                            }
                            if row.loff % 65536 != 0 {
                                t.n("chunk rows whose loff is not a multiple of 65,536");
                            }
                            if row.loff != 0 {
                                match bundle.toc_chunk(&src, &row.guid) {
                                    Ok(Some((_, whole))) if row.chunk_size() == whole as u64 => {
                                        t.n("chunk rows with loff != 0 whose loff + lsize is the whole chunk");
                                    }
                                    other => {
                                        t.n("chunk rows with loff != 0 whose loff + lsize is not the whole chunk");
                                        t.problem(format!("{}: {other:?}", bundle.name));
                                    }
                                }
                            }
                        }
                        for e in bundle.entries() {
                            let key = (e.file.0.encode(), e.file.1, e.file.2);
                            let is_depot = e.kind == Kind::Res && e.resource_type == Some(depot::RTYPE);
                            if !(e.kind == Kind::Ebx || is_depot) || !seen.lock().unwrap().insert(key) {
                                continue;
                            }
                            let Ok(bytes) = src.payload(e.file, e.size as usize) else {
                                t.n("payloads that did not read");
                                continue;
                            };
                            if !is_depot {
                                document(&mut t, &bytes, &e.name);
                                continue;
                            }
                            let meta = bundle.manifest.res[e.index].rmeta;
                            let d = match depot::read(&bytes, &meta) {
                                Ok(d) => d,
                                Err(err) => {
                                    t.n("depots refused");
                                    t.problem(format!("{}: {err}", e.name));
                                    continue;
                                }
                            };
                            t.n("depots read");
                            for block in &d.blocks {
                                match depot::params(&block.data) {
                                    Ok(ps) => {
                                        for p in &ps {
                                            t.depot_prefix.entry(p.name).or_default().insert((p.ty, p.extra));
                                        }
                                        t.n("shader blocks parsed to their last byte");
                                        if ps.iter().any(|p| p.ty == 0x566e_2dd0) {
                                            t.n("shader blocks holding parameter type 0x566e2dd0");
                                        }
                                    }
                                    Err(err) => {
                                        t.n("shader blocks refused");
                                        t.problem(format!("{}: {err}", e.name));
                                    }
                                }
                            }
                        }
                    }
                    total.lock().unwrap().merge(t);
                }
            });
        }
    });
    let t = total.into_inner().unwrap();
    let (names, names_unreadable) = names.into_inner().unwrap();
    println!("{:#?}", t.counts);
    let count = |k: &str| t.counts.get(k).copied().unwrap_or(0);

    // nothing refused, nothing changed
    for refused in [
        "TOCs that do not list",
        "bundles that did not read",
        "payloads that did not read",
        "EBX payloads refused by the reader",
        "EBX payloads refused by the writer",
        "rewritten EBX payloads that do not read",
        "rewritten EBX payloads that read back to other values",
        "depots refused",
        "shader blocks refused",
    ] {
        assert_eq!(count(refused), 0, "{refused}: {:?}", t.problems);
    }
    assert!(
        count("EBX payloads read") > 300_000,
        "{}",
        count("EBX payloads read")
    );
    // the documents with a NaN or an infinity: all of them rewritten with their bits
    assert!(count("documents holding a NaN or an infinity") > 0);
    assert_eq!(
        count("documents holding a NaN or an infinity"),
        count("documents with a NaN or an infinity that read back to the same bits")
    );
    // the 64-bit codes: the game's field names agree with the reading, over the fields it has
    for k in [
        "64-bit field named for the other signedness",
        "64-bit value of the other variant",
        "type reference past the EFIX list",
        "type reference that with_fixup_type does not give back",
        "type reference resolved to another GUID",
    ] {
        assert_eq!(count(k), 0, "{k}: {:?}", t.problems);
    }
    assert!(count("64-bit fields named for their signedness") > 0);
    assert!(t.int64_fields.contains("CompareInt64EntityData.A"));
    assert!(t.int64_fields.contains("PropertyCastEntityData.Int64Value"));
    assert!(t.uint64_fields.contains("CompareUint64EntityData.A"));
    assert!(t.uint64_fields.contains("ExpressionPortData.PortKey"));
    assert!(
        t.uint64_fields
            .contains("EnvironmentDecalVolumeData.ShaderInstanceKey")
    );
    // type references: a slot of the EFIX list names the type the field is about
    let mut trait_refs = 0u64;
    for ((key, guid), n) in &t.refs {
        if key.ends_with(".TraitDataTypeRef")
            && let Some(names) = t.guid_names.get(guid)
        {
            assert!(
                names.iter().all(|name| name.ends_with("TraitData")),
                "{key} names {names:?}"
            );
            trait_refs += n;
        }
    }
    assert!(trait_refs > 1000, "{trait_refs} trait type references resolved");
    // read as an index into the reflection table, these references would mostly name other types
    let all = count("TraitDataTypeRef references");
    let by_table_index =
        count("TraitDataTypeRef references whose reflection-table entry at the slot is a trait type");
    assert!(
        all > 1000 && by_table_index * 2 < all,
        "{by_table_index} of {all}"
    );
    // enumerations: every value but one names a member of its type, and no type is memberless
    println!(
        "{} enumeration types used, {} memberless; {} documents named by GuidNames ({} conflicts, {names_unreadable} unreadable); {} import file GUIDs",
        t.enum_types.len(),
        t.memberless_enums.len(),
        names.len(),
        names.conflicts().len(),
        t.imports.len()
    );
    for (name, members) in &t.enum_members {
        if [
            "Mesh",
            "Primitive",
            "Instancing",
            "IndexBuffer",
            "SubsetCategory",
            "VertexElement",
        ]
        .iter()
        .any(|k| name.contains(k))
        {
            println!("ENUM {name}: {members:?}");
        }
    }
    assert_eq!(count("enumeration values"), 3_368_510, "{:?}", t.problems);
    assert_eq!(count("enumeration values naming a member"), 3_368_509);
    assert_eq!(count("enumeration values naming no member"), 1);
    assert_eq!(count("enumeration members that do not read back"), 0);
    assert!(t.memberless_enums.is_empty(), "{:?}", t.memberless_enums);
    // the file GUID table: it names the documents the decoded files say it does, with no GUID given two names
    let (mut import_refs, mut resolved_refs) = (0u64, 0u64);
    let (mut resolved_guids, mut unresolved) = (0u64, Vec::new());
    for (guid, n) in &t.imports {
        import_refs += n;
        if names.get(guid).is_some() {
            resolved_refs += n;
            resolved_guids += 1;
        } else if unresolved.len() < 3 {
            unresolved.push(frostbite_formats::hex(guid));
        }
    }
    println!(
        "imports: {import_refs} references to {} file GUIDs; {resolved_refs} references and {resolved_guids} GUIDs named by the table (unnamed e.g. {unresolved:?})",
        t.imports.len()
    );
    // the census of build 20260929: 865,673 references to 147,320 file GUIDs; two GUIDs, one reference each, name a
    // document no bundle of the install holds
    assert_eq!(import_refs, 865_673);
    assert_eq!(resolved_refs, 865_671, "{unresolved:?}");
    assert_eq!(resolved_guids, 147_318);
    assert_eq!(names_unreadable, 0);
    assert!(names.conflicts().is_empty(), "{:?}", names.conflicts());
    assert_eq!(names.len(), t.file_names.len());
    for (guid, expected) in &t.file_names {
        let got = names.get(guid).unwrap_or("");
        assert!(expected.contains(got), "{got} not among {expected:?}");
    }
    // the parameter keys: the census of build 20260929 (an independent EBX reader over the 328,015 payloads) found 207
    // distinct keys that 40,262 `AppearanceExpressionParamInfo` values tie to a `ShaderExpressionParameter` asset, each
    // key to one asset, and every asset name hashes (lower-cased djb2-XOR from `NAME_HASH_SEED`) to its key's name hash
    let mut param_names = ParamNames::new();
    let added = param_names.add(&t.key_uses, &names);
    println!(
        "parameter keys: {} uses, {added:?}; {} depot key hashes",
        t.key_uses.len(),
        t.depot_prefix.len()
    );
    assert_eq!((added.unnamed, added.refused), (0, 0), "{added:?}");
    assert_eq!(added.added, 207);
    assert_eq!(added.added + added.repeated, 40_262);
    assert_eq!(param_names.len(), 207);
    // the keys of the documents are the depots' parameter prefixes: 195 of the 207 occur in a depot, with the same type
    // and identity as the one record every depot parameter hash carries (1,636 distinct hashes)
    assert_eq!(t.depot_prefix.len(), 1636);
    assert!(
        t.depot_prefix.values().all(|s| s.len() == 1),
        "a key hash with two prefixes"
    );
    let (mut in_depots, mut differing) = (0, 0);
    for (key, _) in param_names.iter() {
        if let Some(seen) = t.depot_prefix.get(&key.hash) {
            in_depots += 1;
            if !seen.contains(&(key.type_key, key.identity)) {
                differing += 1;
            }
        }
    }
    assert_eq!((in_depots, differing), (195, 0));
    // the depots: every block parses, the one-byte parameter type among them
    assert!(count("shader blocks parsed to their last byte") > 60_000);
    assert!(count("shader blocks holding parameter type 0x566e2dd0") > 0);
    // the manifests
    assert!(count("manifest chunk rows") > 200_000);
    assert_eq!(count("chunk rows whose size is not lsize"), 0, "{:?}", t.problems);
    assert_eq!(count("chunk rows whose loff is not a multiple of 65,536"), 0);
    assert_eq!(
        count("chunk rows with loff != 0 whose loff + lsize is not the whole chunk"),
        0,
        "{:?}",
        t.problems
    );
    assert!(count("chunk rows with loff != 0 whose loff + lsize is the whole chunk") > 0);
    Ok(())
}