From 119238e4a1db599fb04c94a87b56da86c14e154a Mon Sep 17 00:00:00 2001 From: widberg Date: Thu, 26 Oct 2023 16:11:08 -0400 Subject: [PATCH] Some BigFile cleanup --- bff-derive/src/bigfiles.rs | 6 ++--- bff/src/bigfile/v1_06_63_02_pc/mod.rs | 4 +--- bff/src/bigfile/v1_08_40_02_pc/mod.rs | 4 +--- bff/src/bigfile/v1_22_pc/mod.rs | 12 ++++------ bff/src/bigfile/v2_07_pc/mod.rs | 33 +++++++++++---------------- bff/src/traits/big_file_io.rs | 2 +- 6 files changed, 24 insertions(+), 37 deletions(-) diff --git a/bff-derive/src/bigfiles.rs b/bff-derive/src/bigfiles.rs index a29b420..afd4960 100644 --- a/bff-derive/src/bigfiles.rs +++ b/bff-derive/src/bigfiles.rs @@ -46,7 +46,7 @@ fn impl_read_bigfile(input: &BffBigFileMacroInput) -> proc_macro2::TokenStream { quote! { #(#attrs)* #pat #guard => { - crate::names::names().lock().unwrap().name_type = <#body as BigFileIo>::name_type(version.clone(), platform); + crate::names::names().lock().unwrap().name_type = <#body as BigFileIo>::NAME_TYPE; <#body as BigFileIo>::read(reader, version, platform) } } @@ -84,7 +84,7 @@ fn impl_write_bigfile(input: &BffBigFileMacroInput) -> proc_macro2::TokenStream quote! { #(#attrs)* #pat #guard => { - crate::names::names().lock().unwrap().name_type = <#body as BigFileIo>::name_type(version.clone(), platform); + crate::names::names().lock().unwrap().name_type = <#body as BigFileIo>::NAME_TYPE; <#body as BigFileIo>::write(self, writer, tag) } } @@ -125,7 +125,7 @@ fn impl_dump_resource(input: &BffBigFileMacroInput) -> proc_macro2::TokenStream quote! { #(#attrs)* #pat #guard => { - crate::names::names().lock().unwrap().name_type = <#body as BigFileIo>::name_type(version.clone(), platform); + crate::names::names().lock().unwrap().name_type = <#body as BigFileIo>::NAME_TYPE; Ok(<#body as BigFileIo>::ResourceType::dump_resource(resource, writer, endian)?) } } diff --git a/bff/src/bigfile/v1_06_63_02_pc/mod.rs b/bff/src/bigfile/v1_06_63_02_pc/mod.rs index 2d1602e..c835091 100644 --- a/bff/src/bigfile/v1_06_63_02_pc/mod.rs +++ b/bff/src/bigfile/v1_06_63_02_pc/mod.rs @@ -479,9 +479,7 @@ impl BigFileIo for BigFileV1_06_63_02PC { Ok(()) } - fn name_type(_version: Version, _platform: Platform) -> NameType { - Asobo32 - } + const NAME_TYPE: NameType = Asobo32; type ResourceType = Object; } diff --git a/bff/src/bigfile/v1_08_40_02_pc/mod.rs b/bff/src/bigfile/v1_08_40_02_pc/mod.rs index 1bd1243..d40de70 100644 --- a/bff/src/bigfile/v1_08_40_02_pc/mod.rs +++ b/bff/src/bigfile/v1_08_40_02_pc/mod.rs @@ -248,9 +248,7 @@ impl BigFileIo for BigFileV1_08_40_02PC { Ok(()) } - fn name_type(_version: Version, _platform: Platform) -> NameType { - Asobo32 - } + const NAME_TYPE: NameType = Asobo32; type ResourceType = Object; } diff --git a/bff/src/bigfile/v1_22_pc/mod.rs b/bff/src/bigfile/v1_22_pc/mod.rs index c1cbd48..c076849 100644 --- a/bff/src/bigfile/v1_22_pc/mod.rs +++ b/bff/src/bigfile/v1_22_pc/mod.rs @@ -239,13 +239,11 @@ impl BigFileIo Ok(()) } - fn name_type(_version: Version, _platform: Platform) -> NameType { - if KALISTO { - Kalisto32 - } else { - BlackSheep32 - } - } + const NAME_TYPE: NameType = if KALISTO { + Kalisto32 + } else { + BlackSheep32 + }; type ResourceType = Resource; } diff --git a/bff/src/bigfile/v2_07_pc/mod.rs b/bff/src/bigfile/v2_07_pc/mod.rs index 2420e5e..b3e2586 100644 --- a/bff/src/bigfile/v2_07_pc/mod.rs +++ b/bff/src/bigfile/v2_07_pc/mod.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use std::io::{Cursor, Read, Seek, Write}; -use binrw::{binread, parser, BinRead, BinResult, BinWrite, Endian}; +use binrw::{binread, parser, BinRead, BinResult, BinWrite, Endian, args}; use super::v1_22_pc::Resource; use crate::bigfile::manifest::Manifest; @@ -15,14 +15,10 @@ use crate::traits::BigFileIo; use crate::versions::Version; use crate::BffResult; -#[derive(Debug, BinRead)] -#[br(import(compressed: bool, checksum: Option, resource_count: u32))] +#[derive(Debug)] pub struct Block { - #[br(calc = compressed)] pub compressed: bool, - #[br(calc = checksum)] pub checksum: Option, - #[br(count = resource_count)] pub resources: Vec, } @@ -55,11 +51,6 @@ fn parse_blocks( }; let resource_count = u32::read_options(reader, endian, ())?; - println!( - "block_size: {}, resource_count: {}, checksum: {:?}", - block_size, resource_count, checksum - ); - if block_size != decompressed_block_size { let block_size = if MQFEL { block_size - 8 } else { block_size }; @@ -68,12 +59,17 @@ fn parse_blocks( let decompressed = lzo_decompress(&compressed, decompressed_block_size as usize).unwrap(); let mut decompressed = Cursor::new(decompressed); - let block = - Block::read_options(&mut decompressed, endian, (true, checksum, resource_count))?; - blocks.push(block); + blocks.push(Block { + compressed: true, + checksum, + resources: Vec::::read_options(&mut decompressed, endian, args! { count: resource_count as usize })? + }); } else { - let block = Block::read_options(reader, endian, (false, checksum, resource_count))?; - blocks.push(block); + blocks.push(Block { + compressed: false, + checksum, + resources: Vec::::read_options(reader, endian, args! { count: resource_count as usize })? + }); } read_align_to(reader, 2048)?; } @@ -86,7 +82,6 @@ fn parse_blocks( enum CompressionType { None, Lzo, - Zlib, // Unused } #[binread] @@ -169,9 +164,7 @@ impl BigFileIo for BigFileV2_07PC { todo!() } - fn name_type(_version: Version, _platform: Platform) -> NameType { - BlackSheep32 - } + const NAME_TYPE: NameType = BlackSheep32; type ResourceType = Resource; } diff --git a/bff/src/traits/big_file_io.rs b/bff/src/traits/big_file_io.rs index 23b442c..b64f867 100644 --- a/bff/src/traits/big_file_io.rs +++ b/bff/src/traits/big_file_io.rs @@ -19,7 +19,7 @@ pub trait BigFileIo { tag: Option<&str>, ) -> BffResult<()>; - fn name_type(version: Version, platform: Platform) -> NameType; + const NAME_TYPE: NameType; type ResourceType; }