diff --git a/src/common.rs b/src/common.rs index be5bea9..1adc743 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1,5 +1,5 @@ -use std::io::Seek; -use binrw::{BinRead, BinReaderExt, BinResult}; +use binrw::BinRead; +use binrw::BinResult; pub(crate) fn read_bool_from + PartialEq>(x: T) -> bool { x == T::from(1u8) @@ -9,7 +9,7 @@ pub(crate) fn read_bool_from + PartialEq>(x: T) -> bool { pub(crate) fn read_string_with_length() -> BinResult { let length = u32::read_le(reader)? as usize; if length == 0 { - return Ok(String::default());; + return Ok(String::default()); } // last byte is the null terminator which Rust ignores let length = length - 1; diff --git a/src/lib.rs b/src/lib.rs index 3eb2f77..19fbc09 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,6 +13,7 @@ use binrw::helpers::{until, until_eof}; use crate::array_property::ArrayProperty; use crate::bool_property::BoolProperty; +use crate::common::read_string_with_length; use crate::float_property::FloatProperty; use crate::int_property::IntProperty; use crate::map_property::MapProperty; @@ -20,36 +21,12 @@ use crate::set_property::SetProperty; use crate::str_property::StrProperty; use crate::struct_property::StructProperty; use binrw::binrw; -use crate::common::read_string_with_length; - -#[binrw] -#[derive(Debug)] -pub enum Property { - #[br(magic = b"IntProperty\0")] - Int(IntProperty), - #[br(magic = b"BoolProperty\0")] - Bool(BoolProperty), - #[br(magic = b"StructProperty\0")] - Struct(StructProperty), - #[br(magic = b"FloatProperty\0")] - Float(FloatProperty), - #[br(magic = b"StrProperty\0")] - String(StrProperty), - #[br(magic = b"NameProperty\0")] - Name(StrProperty), - #[br(magic = b"ArrayProperty\0")] - Array(ArrayProperty), - #[br(magic = b"MapProperty\0")] - Map(MapProperty), - #[br(magic = b"SetProperty\0")] - Set(SetProperty), -} // Used in ArrayProperty exclusively, but could be used instead of magic above #[binrw] #[derive(Debug)] #[br(import { magic: &str })] -pub enum StringBasedProperty { +pub enum Property { #[br(pre_assert("NameProperty" == magic))] Name(StrProperty), #[br(pre_assert("StructProperty" == magic))] @@ -83,7 +60,7 @@ pub struct Entry { pub type_name: String, #[br(if(name != "None"), args { magic: &type_name })] - pub r#type: Option, + pub r#type: Option, } #[binrw] diff --git a/src/map_property.rs b/src/map_property.rs index 693847a..a52269a 100644 --- a/src/map_property.rs +++ b/src/map_property.rs @@ -189,7 +189,11 @@ fn custom_parser( let end = current + size_in_bytes as u64 - 5 - 3; while current < end { - result.push(MapEntry::read_options(reader, endian, (key_type, value_type))?); + result.push(MapEntry::read_options( + reader, + endian, + (key_type, value_type), + )?); current = reader.stream_position()?; } Ok(result) diff --git a/src/set_property.rs b/src/set_property.rs index cbe3c4f..d21c3a0 100644 --- a/src/set_property.rs +++ b/src/set_property.rs @@ -1,4 +1,4 @@ -use crate::StringBasedProperty; +use crate::Property; use crate::common::read_string_with_length; use binrw::binrw; @@ -14,7 +14,7 @@ pub struct SetEntry { pub unk_type: String, #[br(args { magic: &unk_type })] - pub key: StringBasedProperty, + pub key: Property, } #[binrw] diff --git a/src/str_property.rs b/src/str_property.rs index fec676f..c198c6e 100644 --- a/src/str_property.rs +++ b/src/str_property.rs @@ -1,5 +1,5 @@ -use binrw::binrw; use crate::common::read_string_with_length; +use binrw::binrw; #[binrw] #[derive(Debug)] @@ -22,16 +22,8 @@ mod tests { fn empty_string() { // From Slot.sav let data = [ - 0x04, 0x00, 0x00, - 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, - 0x00, 0x0b, 0x00, - 0x00, 0x00, 0x4c, - 0x6f, 0x61, 0x64, - 0x4f, 0x70, 0x74, - 0x69, 0x6f, 0x6e, - 0x00, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, + 0x00, 0x00, 0x00, 0x4c, 0x6f, 0x61, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x00, ]; let mut cursor = Cursor::new(data); let decoded = StrProperty::read_le(&mut cursor).unwrap(); @@ -42,19 +34,9 @@ mod tests { fn regular_string() { // From Slot.sav let data = [ - 0x1e, 0x00, 0x00, - 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x00, - 0x00, 0x41, 0x52, - 0x30, 0x58, 0x4a, - 0x47, 0x46, 0x57, - 0x41, 0x36, 0x48, - 0x4e, 0x49, 0x51, - 0x31, 0x41, 0x41, - 0x55, 0x4a, 0x39, - 0x55, 0x52, 0x38, - 0x32, 0x38, 0x00, + 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x41, + 0x52, 0x30, 0x58, 0x4a, 0x47, 0x46, 0x57, 0x41, 0x36, 0x48, 0x4e, 0x49, 0x51, 0x31, + 0x41, 0x41, 0x55, 0x4a, 0x39, 0x55, 0x52, 0x38, 0x32, 0x38, 0x00, ]; let mut cursor = Cursor::new(data); let decoded = StrProperty::read_le(&mut cursor).unwrap(); diff --git a/src/struct_property.rs b/src/struct_property.rs index 22b1257..98510bd 100644 --- a/src/struct_property.rs +++ b/src/struct_property.rs @@ -1,8 +1,8 @@ use crate::structs::{ CarryCountProperty, DAAssembleIdDataStruct, DABuildDataStruct, DACharacterCommonStatusStruct, DALoadOptionStruct, DAMachineColoringDataStruct, DAModuleColorStruct, DAModuleItemDataStruct, - DateTimeStruct, GuidStruct, LinearColorStruct, ParamsStruct, PrimaryAssetIdStruct, - PrimaryAssetNameProperty, SaveSlotInfoStruct, + DateTimeStruct, GuidStruct, LinearColorStruct, PrimaryAssetIdStruct, PrimaryAssetNameProperty, + SaveSlotInfoStruct, }; use binrw::binrw; @@ -17,8 +17,6 @@ pub enum Struct { SaveSlotInfo(SaveSlotInfoStruct), #[br(magic = b"DACharacterCommonStatus\0")] DACharacterCommonStatus(DACharacterCommonStatusStruct), - #[br(magic = b"Params\0")] - Params(ParamsStruct), #[br(magic = b"PrimaryAssetType\0")] PrimaryAssetType { #[br(pad_before = 17)] diff --git a/src/structs.rs b/src/structs.rs index 5a1a891..6ba3657 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -1,4 +1,4 @@ -use crate::{Property, StringBasedProperty}; +use crate::Property; use binrw::binrw; #[binrw] @@ -25,14 +25,6 @@ pub struct DACharacterCommonStatusStruct { pub unk: [u8; 17], } -#[binrw] -#[derive(Debug)] -pub struct ParamsStruct { - pub params_value_type_length: u32, - - pub params_value: Box, -} - #[binrw] #[derive(Debug)] pub struct PrimaryAssetNameProperty { @@ -57,7 +49,7 @@ pub struct PrimaryAssetNameProperty { #[br(if(property_name != "None"))] #[br(args { magic: &type_name})] // - pub key: Option>, + pub key: Option>, } #[binrw] @@ -73,7 +65,7 @@ pub struct CarryCountProperty { #[br(args { magic: &property_name})] // - pub key: Option>, + pub key: Option>, } #[binrw]