diff --git a/src/fot/entity.rs b/src/fot/entity.rs index 0884a3c..ae87ba9 100644 --- a/src/fot/entity.rs +++ b/src/fot/entity.rs @@ -49,6 +49,26 @@ impl Entity { Ok(()) } + + pub fn get_modifiers(&self) -> Result { + let value = match self.get_esh()?.get("Modifiers") { + Some(value) => value, + None => return Err(FE::EntityNoModifiers), + }; + + if let ESHValue::Binary(bin) = value { + Ok(Attributes::from_binary(&bin)?) + } else { + Err(FE::AttributesNonBinary) + } + } + + pub fn set_modifiers(&mut self, attrs: Attributes) -> Result<(), FE> { + self.get_esh_mut()? + .set("Modifiers", ESHValue::Binary(attrs.into_binary()?)); + + Ok(()) + } } impl DecoderCtx<&mut EntityList, &EntityList> for Entity { diff --git a/src/fot/ferror.rs b/src/fot/ferror.rs index 5053703..853dafb 100644 --- a/src/fot/ferror.rs +++ b/src/fot/ferror.rs @@ -10,6 +10,7 @@ pub enum FError { NoZeroTerminator, EntityNoESH, EntityNoAttributes, + EntityNoModifiers, AttributesNonBinary, AttributesNoESBIN, } @@ -32,6 +33,7 @@ impl std::fmt::Display for FError { FE::NoZeroTerminator => write!(f, "No zero-terminator when String::decode"), FE::EntityNoESH => write!(f, "Entity has no ESH"), FE::EntityNoAttributes => write!(f, "Entity has no Attributes"), + FE::EntityNoModifiers => write!(f, "Entity has no Modifiers"), FE::AttributesNonBinary => write!(f, "Attributes Binary != true"), FE::AttributesNoESBIN => write!(f, "Attributes has no esbin"), } diff --git a/src/fot/world.rs b/src/fot/world.rs index 1f14158..d17bcf6 100644 --- a/src/fot/world.rs +++ b/src/fot/world.rs @@ -40,8 +40,8 @@ impl World { //self.entlist.dump_to_entfile(ent, Path::new("D:\\actor.ent"))?; println!(""); - let mut attributes = ent.get_attributes()?; - if let ESHValue::Binary(bin) = &esh.get("Attributes").unwrap() { + let mut attributes = ent.get_modifiers()?; + if let ESHValue::Binary(bin) = &esh.get("Modifiers").unwrap() { dbg!(bin.len()); } attributes.stats["strength"] = 10; @@ -54,10 +54,10 @@ impl World { for (_, value) in attributes.skills.iter_mut() { *value = 300; } - ent.set_attributes(attributes)?; + ent.set_modifiers(attributes)?; let esh = ent.get_esh()?; - if let ESHValue::Binary(bin) = &esh.get("Attributes").unwrap() { + if let ESHValue::Binary(bin) = &esh.get("Modifiers").unwrap() { dbg!(bin.len()); } diff --git a/src/main.rs b/src/main.rs index e5ae789..a40d270 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,12 +8,12 @@ use fot::save::Save; fn main() { let args: Vec<_> = env::args().collect(); let save_path = args.get(1).unwrap(); - /*let out_path = match args.get(2) { + let out_path = match args.get(2) { Some(path) => path, - None => "out.bin" - };*/ + None => "out.sav" + }; 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"); + save.save(Path::new(out_path)).expect("failed to save"); }