diff --git a/.gitignore b/.gitignore index e604ba8..409c74d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target *.bin -*.sav \ No newline at end of file +*.sav +*.ent \ No newline at end of file diff --git a/src/fot/entitylist.rs b/src/fot/entitylist.rs index 8f00b10..46e5178 100644 --- a/src/fot/entitylist.rs +++ b/src/fot/entitylist.rs @@ -18,6 +18,10 @@ const DEFAULT_ENTITY_TAG: CTag<'static> = CTag { name: "", version: "2", }; +const DEFAULT_ENTITYFILE_TAG: CTag<'static> = CTag { + name: "", + version: "3", +}; pub struct EntityList { encoding: EntityEncoding, @@ -27,7 +31,7 @@ pub struct EntityList { enc_size: usize, pub types: Vec, - pub entities: Vec, + pub ents: Vec, } impl EntityList { @@ -59,6 +63,8 @@ impl EntityList { use EntityEncoding as EE; if self.encoding == EE::World && new == EE::File { self.entity_tag = Some(DEFAULT_ENTITY_TAG.to_tag()); + } else if self.encoding == EE::File && new == EE::World { + self.entity_file_tag = Some(DEFAULT_ENTITYFILE_TAG.to_tag()); } } } @@ -73,7 +79,7 @@ impl DecoderCtx for EntityList { unk1: 0, enc_size: 0, types: Vec::new(), - entities: Vec::new(), + ents: Vec::new(), }; Ok(match ctx { @@ -87,7 +93,7 @@ impl DecoderCtx for EntityList { } let ent: Entity = rd.read_opt(0, &mut ent_list)?; - ent_list.entities.push(ent); + ent_list.ents.push(ent); } ent_list.enc_size = rd.offset() - offset; @@ -105,7 +111,7 @@ impl DecoderCtx for EntityList { ent_list.unk1 = rd.read_u32()?; for _ in 1..ent_count { let ent: Entity = rd.read_opt(0, &mut ent_list)?; - ent_list.entities.push(ent); + ent_list.ents.push(ent); } ent_list.enc_size = rd.offset() - offset; @@ -118,7 +124,7 @@ impl DecoderCtx for EntityList { let mut wd = WriteStream::new(self.get_enc_size()); match ctx { EntityEncoding::File => { - for ent in self.entities.iter() { + for ent in self.ents.iter() { wd.write(self.get_entity_tag())?; wd.write_opt(ent, &self)?; } @@ -130,9 +136,9 @@ impl DecoderCtx for EntityList { wd.write(type_name)?; } - wd.write_u16((self.entities.len() + 1) as u16)?; + wd.write_u16((self.ents.len() + 1) as u16)?; wd.write_u32(self.unk1)?; - for ent in self.entities.iter() { + for ent in self.ents.iter() { wd.write_opt(ent, &self)?; } } diff --git a/src/fot/world.rs b/src/fot/world.rs index 1552d97..4725ca5 100644 --- a/src/fot/world.rs +++ b/src/fot/world.rs @@ -25,24 +25,18 @@ pub struct World { pub sgd: SGD, pub ssg: SSG, - pub ents: EntityList, + pub entlist: EntityList, } impl World { const WORLD_TAG_LEN: usize = 11; const WORLD_HDR_LEN: usize = 0x13; - pub fn test(&self) -> Result<()> { - 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(), - }; - raw1.dump(Path::new("entfile1.bin"))?; - - let raw2 = self.ents.encode(EntityEncoding::World)?; - raw2.dump(Path::new("entfile2.bin"))?; + pub fn test(&mut self) -> Result<()> { + self.entlist.convert(EntityEncoding::File); + self.entlist + .encode(EntityEncoding::File)? + .dump(Path::new("entlist.ent"))?; Ok(()) } @@ -70,7 +64,7 @@ impl Decoder for World { let sgd: SGD = rd.read(0)?; let ssg: SSG = rd.read(0)?; - let ents: EntityList = rd.read_opt(0, EntityEncoding::World)?; + let entlist: EntityList = rd.read_opt(0, EntityEncoding::World)?; Ok(World { tag, @@ -79,7 +73,7 @@ impl Decoder for World { mission, sgd, ssg, - ents, + entlist, }) } diff --git a/src/main.rs b/src/main.rs index 277f0e8..667ccf7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,7 @@ fn main() { None => "out.bin" };*/ - let save = Save::load(Path::new(save_path)).expect("load save"); + let mut save = Save::load(Path::new(save_path)).expect("load save"); save.world.test().expect("test"); //save.save(Path::new("out.sav")).expect("failed to save"); }