add convert ability for EntityList to convert from world entity_file to separate ent file. Needs to be fixed

This commit is contained in:
mykola2312 2023-09-04 10:19:40 +03:00
parent 41c513f5e9
commit b01a11f9b9
4 changed files with 24 additions and 23 deletions

3
.gitignore vendored
View file

@ -1,3 +1,4 @@
/target
*.bin
*.sav
*.sav
*.ent

View file

@ -18,6 +18,10 @@ const DEFAULT_ENTITY_TAG: CTag<'static> = CTag {
name: "<entity>",
version: "2",
};
const DEFAULT_ENTITYFILE_TAG: CTag<'static> = CTag {
name: "<entity_file>",
version: "3",
};
pub struct EntityList {
encoding: EntityEncoding,
@ -27,7 +31,7 @@ pub struct EntityList {
enc_size: usize,
pub types: Vec<FString>,
pub entities: Vec<Entity>,
pub ents: Vec<Entity>,
}
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<EntityEncoding, EntityEncoding> 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<EntityEncoding, EntityEncoding> 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<EntityEncoding, EntityEncoding> 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<EntityEncoding, EntityEncoding> 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<EntityEncoding, EntityEncoding> 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)?;
}
}

View file

@ -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,
})
}

View file

@ -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");
}