Clean up code, imports, and other misc tasks
This commit is contained in:
parent
9dd335f80e
commit
e92686e179
6 changed files with 13 additions and 24 deletions
|
@ -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<Vec<SetEntry>> {
|
||||
fn custom_parser(size_in_bytes: u32) -> BinResult<Vec<SetEntry>> {
|
||||
let mut result = Vec::<SetEntry>::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<SetEntry>,
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::io::{Cursor, Read};
|
|||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let args: Vec<String> = 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<dyn std::error::Error>> {
|
|||
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)?;
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ use crate::str_property::StrProperty;
|
|||
use crate::struct_property::StructProperty;
|
||||
use binrw::binrw;
|
||||
|
||||
pub(crate) fn read_bool_from<T: std::convert::From<u8> + std::cmp::PartialEq>(x: T) -> bool {
|
||||
pub(crate) fn read_bool_from<T: From<u8> + PartialEq>(x: T) -> bool {
|
||||
x == T::from(1u8)
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<SetEntry>,
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue