~quf/tocs

e59ef9c83cc85f38ced2fffc0a11f75e6c07e67c — Lukas Himbert 5 months ago 3155ce6
reverie script reading update
4 files changed, 7 insertions(+), 9 deletions(-)

M sqlite_conv/src/main.rs
M tocs/src/script/deser.rs
M tocs/src/script/mod.rs
M tocs/src/script/ser.rs
M sqlite_conv/src/main.rs => sqlite_conv/src/main.rs +1 -3
@@ 201,7 201,6 @@ fn scripts_to_new_db<P: AsRef<std::path::Path>>(base_path: P, dbpath: P) {
    tx.execute(
        "create table scripts (
    file_name text primary key not null,
    unk2 blob not null,
    script_name text not null,
    name_padding int not null
) strict;",


@@ 244,10 243,9 @@ fn scripts_to_new_db<P: AsRef<std::path::Path>>(base_path: P, dbpath: P) {
            let aldat = tocs::script::parse(data.as_slice()).unwrap();
            assert!(tocs::script::serialize(&aldat).unwrap() == data);
            tx.execute(
                "insert into scripts (file_name, unk2, script_name, name_padding) values (?, ?, ?, ?)",
                "insert into scripts (file_name, script_name, name_padding) values (?, ?, ?)",
                [
                    &path_for_db as &dyn rusqlite::types::ToSql,
                    &aldat.unk2.as_slice() as &dyn rusqlite::types::ToSql,
                    &aldat.name.as_str() as _,
                    match aldat.name_padding {
                        tocs::script::ScriptNamePadding::None => &0,

M tocs/src/script/deser.rs => tocs/src/script/deser.rs +4 -3
@@ 44,8 44,10 @@ pub fn parse(data: &[u8]) -> Option<Script> {
    ensure!(n1 == 4 * n_tables_u32);
    ensure!(n2 == table_list_offset + n1);

    // read more
    let unk2 = reader.read_chunk::<4>()?;
    // read another magic value
    let n3 = reader.read_u32_le()?;
    ensure!(n3 == 0xabcdef00);

    let script_name = reader.read_c_ascii_str().ok()?;

    // check padding between end of script name and start of table name offsets


@@ 128,7 130,6 @@ pub fn parse(data: &[u8]) -> Option<Script> {
    }

    Some(Script {
        unk2,
        alignment,
        name: script_name.to_owned(),
        name_padding,

M tocs/src/script/mod.rs => tocs/src/script/mod.rs +0 -1
@@ 11,7 11,6 @@ use crate::io::{PaddedAsciiStr, PaddedAsciiString, PaddedUtf8String};

#[derive(Debug)]
pub struct Script {
    pub unk2: [u8; 4],
    pub name: PaddedAsciiString<1>,
    pub name_padding: ScriptNamePadding,
    pub alignment: std::collections::BTreeMap<PaddedAsciiString<1>, usize>, // TODO: builtin known alignments

M tocs/src/script/ser.rs => tocs/src/script/ser.rs +2 -2
@@ 42,8 42,8 @@ pub fn serialize(script: &Script) -> Option<std::vec::Vec<u8>> {
    let table_data_offset = table_names_end_offset + table_data_padding;
    writer.write_u32_le(table_names_end_offset.try_into().unwrap());

    // unknown
    writer.write_data(script.unk2.as_slice());
    // magic value
    writer.write_u32_le(0xabcdef00);

    // script name
    writer.write_padded_ascii_str(script.name.as_padded_ascii_str());