EntityList decoding and encoding fully implemented, working and tested

This commit is contained in:
mykola2312 2023-09-04 09:26:16 +03:00
parent 35ce0e9076
commit 43c3bd11f6
3 changed files with 17 additions and 21 deletions

View file

@ -60,7 +60,10 @@ impl DecoderCtx<&mut EntityList, &EntityList> for Entity {
EntityEncoding::World => {
wd.write_u32(self.flags)?;
wd.write_u16(self.type_idx as u16)?;
wd.write(self.esh.as_ref().unwrap())?;
match self.esh.as_ref() {
Some(esh) => wd.write(esh)?,
None => ()
}
}
}
Ok(wd.into_raw(0, 0))

View file

@ -118,7 +118,7 @@ impl DecoderCtx<EntityEncoding,EntityEncoding> for EntityList {
wd.write(type_name)?;
}
wd.write_u16(self.entities.len() as u16)?;
wd.write_u16((self.entities.len() + 1) as u16)?;
wd.write_u32(self.unk1)?;
for ent in self.entities.iter() {
wd.write_opt(ent, &self)?;

View file

@ -1,4 +1,4 @@
use super::decoder::Decoder;
use super::decoder::{Decoder, DecoderCtx};
use super::fstring::FString;
use super::entitylist::{EntityList, EntityEncoding};
use super::raw::Raw;
@ -13,6 +13,8 @@ use deflate::deflate_bytes_zlib;
use inflate::inflate_bytes_zlib;
use std::io::Cursor;
use std::path::Path;
pub struct World {
pub tag: Tag,
pub uncompressed_size: u32,
@ -31,25 +33,16 @@ impl World {
const WORLD_HDR_LEN: usize = 0x13;
pub fn test(&self) -> Result<()> {
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 => "<NO ESH>",
_ => self.ents.get_type_name(ent.type_idx).str.as_str()
let entfile_start: usize = 0x1038;
let raw1 = Raw {
offset: 0,
size: self.ents.get_enc_size(),
mem: self.data.mem[entfile_start..entfile_start+self.ents.get_enc_size()].to_vec()
};
println!("idx {} type {}", idx, type_name);
raw1.dump(Path::new("entfile1.bin"))?;
match ent.esh.as_ref() {
Some(esh) => {
for (name, value) in esh.props.iter() {
println!("\t{} {}", &name, &value);
}
},
None => continue
}
}
let raw2 = self.ents.encode(EntityEncoding::World)?;
raw2.dump(Path::new("entfile2.bin"))?;
Ok(())
}