From e92686e17900404fa546083221485df493975fe9 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sun, 23 Feb 2025 14:43:10 -0500 Subject: [PATCH] Clean up code, imports, and other misc tasks --- src/array_property.rs | 7 +++---- src/bin/ireko.rs | 4 ++-- src/lib.rs | 2 +- src/map_property.rs | 19 ++++++------------- src/set_property.rs | 3 +-- src/struct_property.rs | 2 -- 6 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/array_property.rs b/src/array_property.rs index f4a0d40..9bc2c5a 100644 --- a/src/array_property.rs +++ b/src/array_property.rs @@ -1,16 +1,15 @@ use crate::set_property::SetEntry; use binrw::{binrw, BinRead, BinResult}; -use crate::map_property::{KeyType, MapEntry}; #[binrw::parser(reader, endian)] -fn custom_parser(size_in_bytes: u32, key_name: &str) -> BinResult> { +fn custom_parser(size_in_bytes: u32) -> BinResult> { let mut result = Vec::::new(); let mut current = reader.stream_position().unwrap(); let end = current + size_in_bytes as u64 - 4; while current < end { - result.push(SetEntry::read_options(reader, endian, (key_name,)).unwrap()); + result.push(SetEntry::read_options(reader, endian, ()).unwrap()); current = reader.stream_position().unwrap(); } Ok(result) @@ -34,6 +33,6 @@ pub struct ArrayProperty { #[br(pad_before = 1)] pub unk: u32, - #[br(parse_with = custom_parser, args(size_in_bytes, &key_name))] + #[br(parse_with = custom_parser, args(size_in_bytes))] pub entries: Vec, } diff --git a/src/bin/ireko.rs b/src/bin/ireko.rs index 44deb7f..a4e3ac2 100644 --- a/src/bin/ireko.rs +++ b/src/bin/ireko.rs @@ -8,7 +8,7 @@ use std::io::{Cursor, Read}; fn main() -> Result<(), Box> { let args: Vec = env::args().collect(); - let mut data = std::io::Cursor::new(std::fs::read(&args[1])?); + let mut data = Cursor::new(std::fs::read(&args[1])?); let compressed = CompressedSaveFile::read_le(&mut data)?; @@ -19,7 +19,7 @@ fn main() -> Result<(), Box> { let decompress = Decompress::new(true); let mut d = ZlibDecoder::new_with_decompress(&*compressed.compressed_data, decompress); - let size = d.read(&mut *uncompressed)?; + let size = d.read(&mut uncompressed)?; output.extend_from_slice(&uncompressed[..size]); std::fs::write("output.bin", &output)?; diff --git a/src/lib.rs b/src/lib.rs index 44c2b86..579b93d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,7 +24,7 @@ use crate::str_property::StrProperty; use crate::struct_property::StructProperty; use binrw::binrw; -pub(crate) fn read_bool_from + std::cmp::PartialEq>(x: T) -> bool { +pub(crate) fn read_bool_from + PartialEq>(x: T) -> bool { x == T::from(1u8) } diff --git a/src/map_property.rs b/src/map_property.rs index ffefb8b..f210104 100644 --- a/src/map_property.rs +++ b/src/map_property.rs @@ -1,9 +1,8 @@ -use std::io::{Read, Seek, SeekFrom}; use crate::read_bool_from; use crate::struct_property::Struct; use crate::structs::PrimaryAssetNameProperty; -use binrw::{binrw, BinRead, BinResult}; use binrw::helpers::until_exclusive; +use binrw::{binrw, BinRead, BinResult}; // A struct without a name #[binrw] @@ -19,7 +18,6 @@ pub struct MapSubStructProperty { #[br(temp)] #[bw(ignore)] pub unk_name_length: u32, - #[br(args { is_map: true })] pub r#struct: Struct, } @@ -45,7 +43,6 @@ pub struct StructMaybeKey { #[br(dbg)] #[br(pad_before = 4)] // type length - #[br(args { is_map: true })] pub r#struct: Struct, } @@ -112,7 +109,7 @@ pub struct GuidStruct { // Used in MapProperty exclusively, seems to be a shortened version of some Properties #[binrw] #[derive(Debug)] -#[br(import { magic: &str, is_value: bool })] +#[br(import { magic: &str })] pub enum MabSubProperty { #[br(pre_assert("NameProperty" == magic))] Name(MapSubNameProperty), @@ -178,10 +175,6 @@ pub enum MapKeyProperty { SomeID2(SomeID2Struct), } -fn is_empty(key: &MapKeyProperty) -> bool { - false -} - #[binrw] #[derive(Debug)] #[br(import(key_type: &KeyType, value_type: &str))] @@ -190,7 +183,7 @@ pub struct MapEntry { #[br(dbg)] pub key: MapKeyProperty, - #[br(args {magic: value_type, is_value: true})] + #[br(args { magic: value_type })] #[br(dbg)] pub value: MabSubProperty, } @@ -215,9 +208,9 @@ fn custom_parser(size_in_bytes: u32, key_type: &KeyType, value_type: &str) -> Bi let mut current = reader.stream_position().unwrap(); let end = current + size_in_bytes as u64 - 5 - 3; - + while current < end { - result.push(MapEntry::read_options(reader, endian, (&key_type, &value_type)).unwrap()); + result.push(MapEntry::read_options(reader, endian, (key_type, value_type)).unwrap()); current = reader.stream_position().unwrap(); } Ok(result) @@ -258,7 +251,7 @@ pub struct MapProperty { #[cfg(test)] mod tests { use super::*; - use crate::map_property::MabSubProperty::{Int, Name, String}; + use crate::map_property::MabSubProperty::{Int, String}; use binrw::BinRead; use std::io::Cursor; diff --git a/src/set_property.rs b/src/set_property.rs index 1988016..55861e1 100644 --- a/src/set_property.rs +++ b/src/set_property.rs @@ -3,7 +3,6 @@ use binrw::binrw; #[binrw] #[derive(Debug)] -#[br(import(key_type: &str))] pub struct SetEntry { #[br(temp)] #[bw(ignore)] @@ -41,7 +40,7 @@ pub struct SetProperty { #[br(pad_before = 5)] pub num_set_entries: u32, - #[br(count = num_set_entries, args { inner: (&*key_name,) })] + #[br(count = num_set_entries)] pub entries: Vec, } diff --git a/src/struct_property.rs b/src/struct_property.rs index 9930f55..8a1b92e 100644 --- a/src/struct_property.rs +++ b/src/struct_property.rs @@ -3,7 +3,6 @@ use binrw::binrw; #[binrw] #[derive(Debug)] -#[br(import { is_map: bool })] pub enum Struct { #[br(magic = b"DateTime\0")] DateTime(DateTimeStruct), @@ -87,6 +86,5 @@ pub struct StructProperty { #[bw(ignore)] #[br(pad_before = 4)] pub name_length: u32, - #[br(args { is_map: false })] pub r#struct: Struct, }