From 35ce0e90761b2b7f59f5f720b6ebf12d85076b9f Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Mon, 4 Sep 2023 07:38:59 +0300 Subject: [PATCH] EntityList decoding now fully works and tested --- src/fot/entity.rs | 15 ++++++++++----- src/fot/entitylist.rs | 5 ++--- src/fot/world.rs | 20 +++++++++++++++++++- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/fot/entity.rs b/src/fot/entity.rs index c0cfc54..b9f8599 100644 --- a/src/fot/entity.rs +++ b/src/fot/entity.rs @@ -10,7 +10,7 @@ const NO_FLAGS: u32 = 0; pub struct Entity { pub flags: u32, pub type_idx: usize, - pub esh: ESH, + pub esh: Option, enc_size: usize, } @@ -26,14 +26,19 @@ impl DecoderCtx<&mut EntityList, &EntityList> for Entity { Entity { flags, type_idx, - esh, + esh: Some(esh), enc_size, } } EntityEncoding::World => { let flags = rd.read_u32()?; let type_idx = rd.read_u16()? as usize; - let esh: ESH = rd.read(0)?; + let esh: Option = if type_idx != 0xFFFF { + Some(rd.read(0)?) + } else { + None + }; + let enc_size = rd.offset() - offset; Entity { flags, @@ -50,12 +55,12 @@ impl DecoderCtx<&mut EntityList, &EntityList> for Entity { match ctx.get_entity_encoding() { EntityEncoding::File => { wd.write(ctx.get_type_name(self.type_idx))?; - wd.write(&self.esh)?; + wd.write(self.esh.as_ref().unwrap())?; } EntityEncoding::World => { wd.write_u32(self.flags)?; wd.write_u16(self.type_idx as u16)?; - wd.write(&self.esh)?; + wd.write(self.esh.as_ref().unwrap())?; } } Ok(wd.into_raw(0, 0)) diff --git a/src/fot/entitylist.rs b/src/fot/entitylist.rs index 06017b8..e4d4573 100644 --- a/src/fot/entitylist.rs +++ b/src/fot/entitylist.rs @@ -91,9 +91,8 @@ impl DecoderCtx for EntityList { let ent_count = rd.read_u16()?; ent_list.unk1 = rd.read_u32()?; - for i in 1..ent_count { + for _ in 1..ent_count { let ent: Entity = rd.read_opt(0, &mut ent_list)?; - println!("ok read {}", i); ent_list.entities.push(ent); } @@ -131,6 +130,6 @@ impl DecoderCtx for EntityList { } fn get_enc_size(&self) -> usize { - todo!(); + self.enc_size } } diff --git a/src/fot/world.rs b/src/fot/world.rs index 4be5126..dba5dad 100644 --- a/src/fot/world.rs +++ b/src/fot/world.rs @@ -31,7 +31,25 @@ impl World { const WORLD_HDR_LEN: usize = 0x13; pub fn test(&self) -> Result<()> { - println!("read {} ents", self.ents.entities.len()); + for i in 0..self.ents.entities.len() { + let ent = &self.ents.entities[i]; + let idx = i+1; + + let type_name = match ent.type_idx { + 0xFFFF => "", + _ => self.ents.get_type_name(ent.type_idx).str.as_str() + }; + println!("idx {} type {}", idx, type_name); + + match ent.esh.as_ref() { + Some(esh) => { + for (name, value) in esh.props.iter() { + println!("\t{} {}", &name, &value); + } + }, + None => continue + } + } Ok(()) }