~quf/tocs

ba77f7df17b770c648c919171c1e0ee616d5e0b4 — Lukas Himbert 5 months ago 9ca9dd1
ActionTable parsing
2 files changed, 49 insertions(+), 12 deletions(-)

M tocs/src/script/deser.rs
M tocs/src/script/ser.rs
M tocs/src/script/deser.rs => tocs/src/script/deser.rs +2 -8
@@ 126,10 126,8 @@ pub fn parse(data: &[u8]) -> Option<Script> {
        //println!("foo {i}");

        let table = match name.to_str() {
            /*
            "ActionTable" => ScriptEntry::ActionTable(read_action_table_entries(table_data)?),
            "AlgoTable" => ScriptEntry::ActionTable(read_action_table_entries(table_data)?),
            */
            //"AlgoTable" => ScriptEntry::ActionTable(read_action_table_entries(table_data)?),
            _ => ScriptEntry::Generic {
                name: name.to_owned(),
                data: table_data.to_owned(),


@@ 165,12 163,8 @@ pub fn read_action_table_entries(data: &[u8]) -> Option<std::vec::Vec<ActionTabl
    let mut reader = MemReader::new(data);
    let mut entries = std::vec::Vec::with_capacity(data.len() / 212);

    loop {
    while !reader.at_end() {
        let id = reader.read_i16_le()?;
        if id == 1 {
            ensure!(reader.rest() == &[0, 0]);
            break;
        }

        let unk1 = reader.read_u16_le()?;
        let unk2 = reader.read_chunk::<4>()?;

M tocs/src/script/ser.rs => tocs/src/script/ser.rs +47 -4
@@ 143,8 143,51 @@ impl ScriptEntry {
}

impl ActionTableEntry {
    fn serialize_data(&self, vec: &mut MemWriter) -> Option<()> {
        todo!()
    fn serialize_data(&self, writer: &mut MemWriter) -> Option<()> {
        let Self {
            id,
            unk1,
            unk2,
            unk3,
            unk4,
            unk5,
            unk10,
            unk11,
            unk12,
            unk13,
            unk14,
            unk15,
            unk16,
            unk17,
            unk18,
            unk19,
            flags,
            animation,
            name,
        } = self;
        writer.write_i16_le(*id);
        writer.write_u16_le(*unk1);
        writer.write_data(unk2.as_slice());
        writer.write_f32_le(*unk3);
        writer.write_f32_le(*unk4);
        writer.write_f32_le(*unk5);
        writer.write_data(unk10.as_slice());
        writer.write_u16_le(*unk11);
        writer.write_u16_le(*unk12);
        writer.write_u16_le(*unk13);
        writer.write_u16_le(*unk14);
        writer.write_u16_le(*unk15);
        writer.write_u16_le(*unk16);
        for x in unk17 {
            writer.write_i32_le(*x);
        }
        writer.write_u16_le(*unk18);
        writer.write_u16_le(*unk19);
        writer.write_padded_ascii_str(flags.as_padded_ascii_str());
        writer.write_padded_utf8_str(animation.as_padded_utf8_str());
        writer.write_padded_utf8_str(name.as_padded_utf8_str());

        Some(())
    }
}



@@ 157,8 200,8 @@ impl AlgoTableEntry {
impl ScriptEntry {
    fn data_len(&self) -> usize {
        match self {
            ScriptEntry::ActionTable { .. } => 212,
            ScriptEntry::AlgoTable { .. } => 32,
            ScriptEntry::ActionTable(entries) => 212 * entries.len(),
            ScriptEntry::AlgoTable(entries) => 32 * entries.len(),
            ScriptEntry::Generic { name: _, data } => data.len(),
        }
    }