rabex 0.1.1

Tools for parsing and writing unity files, bundles and typetrees
Documentation
//! Prints a regenerated `src/commonstring.rs` (from the embedded TPK common string table)
//! to stdout. Run via `just update-commonstring`.

use rabex::tpk::TpkTypeTreeBlob;

const HEADER: &str = r#"
//! @generated by `just update-commonstring` from the embedded TPK — do not edit by hand.

use std::collections::BTreeMap;
use std::sync::LazyLock;

pub static COMMONSTRING: LazyLock<BTreeMap<u32, &'static str>> = LazyLock::new(|| {
    [
"#;

const FOOTER: &str = r#"    ]
    .iter()
    .copied()
    .collect()
});
"#;

fn main() {
    let tpk = TpkTypeTreeBlob::embedded();
    let strings: Vec<&str> = tpk
        .common_string
        .string_buffer_indices
        .iter()
        .map(|&i| tpk.string_buffer[i as usize].as_str())
        .collect();

    print!("{HEADER}");
    let mut offset = 0u32;
    for s in &strings {
        println!("        ({offset}, {s:?}),");
        offset += s.len() as u32 + 1;
    }
    print!("{FOOTER}");
}