Skip to content

Commit

Permalink
Use Ubisoft64 for MQFEL BFs
Browse files Browse the repository at this point in the history
  • Loading branch information
widberg committed Nov 29, 2023
1 parent f11a1c5 commit 99854ac
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 33 deletions.
6 changes: 4 additions & 2 deletions bff/src/bigfile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod v1_2000_77_18_pc;
mod v1_2002_45_19_pc;
mod v1_22_pc;
mod v2_07_pc;
mod v2_0_pc;
mod v2_128_52_19_pc;
mod v2_128_92_19_pc;
mod v2_256_38_19_pc;
Expand All @@ -26,7 +27,8 @@ use crate::bigfile::v1_22_pc::{
BigFileV1_22PCNoVersionTriple,
BigFileV1_22PCNoVersionTripleBlackSheep,
};
use crate::bigfile::v2_07_pc::{BigFileV2_07PCMQFEL, BigFileV2_07PCPROTO, BigFileV2_07PCSHAUN};
use crate::bigfile::v2_07_pc::{BigFileV2_07PCPROTO, BigFileV2_07PCSHAUN};
use crate::bigfile::v2_0_pc::BigFileV2_0PC;
use crate::bigfile::v2_128_52_19_pc::BigFileV2_128_52_19PC;
use crate::bigfile::v2_128_92_19_pc::BigFileV2_128_92_19PC;
use crate::bigfile::v2_256_38_19_pc::BigFileV2_256_38_19PC;
Expand All @@ -47,7 +49,7 @@ bigfiles! {
(Kalisto(1, _), _) => BigFileV1_22PCNoVersionTriple,
(BlackSheep(2, ..=7) | BlackSheep(2, 158..), _) => BigFileV2_07PCPROTO,
(BlackSheep(2, _), _) => BigFileV2_07PCSHAUN,
(Ubisoft { .. }, _) => BigFileV2_07PCMQFEL,
(Ubisoft { .. }, _) => BigFileV2_0PC,
(AsoboLegacy(1, ..=80), _) => BigFileV1_22PC,
(AsoboLegacy(1, _) | Asobo(1, 1..=5 | 8, _, _), _) => BigFileV1_08_40_02PC,
(Asobo(1, 1..=1999, _, _), _) => BigFileV1_06_63_02PC,
Expand Down
14 changes: 7 additions & 7 deletions bff/src/bigfile/v1_22_pc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ use crate::BffResult;

#[binrw]
#[derive(Debug)]
pub struct Resource {
pub struct Resource<const S: u32 = 12> {
#[br(temp)]
#[bw(calc = data.len() as u32 + 12)]
#[bw(calc = data.len() as u32 + S)]
data_size: u32,
class_name: Name,
pub name: Name,
#[br(count = data_size - 12)]
#[br(count = data_size - S)]
data: Vec<u8>,
}

impl Resource {
impl<const S: u32> Resource<S> {
pub fn dump_resource<W: Write + Seek>(
resource: &crate::bigfile::resource::Resource,
writer: &mut W,
Expand Down Expand Up @@ -61,8 +61,8 @@ impl Resource {
}
}

impl From<Resource> for crate::bigfile::resource::Resource {
fn from(resource: Resource) -> crate::bigfile::resource::Resource {
impl<const S: u32> From<Resource<S>> for crate::bigfile::resource::Resource {
fn from(resource: Resource<S>) -> crate::bigfile::resource::Resource {
crate::bigfile::resource::Resource {
class_name: resource.class_name,
name: resource.name,
Expand Down Expand Up @@ -216,7 +216,7 @@ impl<const HAS_VERSION_TRIPLE: bool, const KALISTO: bool> BigFileIo

for resource in block.objects.iter() {
let resource = bigfile.objects.get(&resource.name).unwrap();
Resource::dump_resource(resource, writer, endian)?;
Resource::<12>::dump_resource(resource, writer, endian)?;
}

write_align_to(writer, 0x20000, 0xCD)?;
Expand Down
29 changes: 6 additions & 23 deletions bff/src/bigfile/v2_07_pc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::bigfile::BigFile;
use crate::helpers::{calculated_padded, read_align_to, write_align_to, DynArray};
use crate::lz::{lzo_compress, lzo_decompress};
use crate::names::NameType;
use crate::names::NameType::{BlackSheep32, Ubisoft64};
use crate::names::NameType::BlackSheep32;
use crate::platforms::Platform;
use crate::traits::BigFileIo;
use crate::versions::Version;
Expand Down Expand Up @@ -39,7 +39,6 @@ impl BinWrite for Block {

const SHAUN_PROTO: usize = 0;
const SHAUN: usize = 1;
const MQFEL: usize = 2;

#[parser(reader, endian)]
fn parse_blocks<const GAME: usize>(
Expand All @@ -51,11 +50,6 @@ fn parse_blocks<const GAME: usize>(
for block_size in block_sizes {
let block_start = reader.stream_position()?;

let checksum = if GAME == MQFEL {
Some(u32::read_options(reader, endian, ())?)
} else {
None
};
let resource_count = u32::read_options(reader, endian, ())?;

if *block_size != decompressed_block_size {
Expand All @@ -65,7 +59,6 @@ fn parse_blocks<const GAME: usize>(
- match GAME {
SHAUN_PROTO => 0,
SHAUN => 4,
MQFEL => 8,
_ => unreachable!(),
}) as usize
];
Expand All @@ -75,7 +68,7 @@ fn parse_blocks<const GAME: usize>(
let mut decompressed = Cursor::new(decompressed);
blocks.push(Block {
compressed: true,
checksum,
checksum: None,
resources: Vec::<Resource>::read_options(
&mut decompressed,
endian,
Expand All @@ -86,7 +79,7 @@ fn parse_blocks<const GAME: usize>(
} else {
blocks.push(Block {
compressed: false,
checksum,
checksum: None,
resources: Vec::<Resource>::read_options(
reader,
endian,
Expand Down Expand Up @@ -128,7 +121,6 @@ pub struct BigFileV2_07PC<const GAME: usize> {
blocks: Vec<Block>,
}

pub type BigFileV2_07PCMQFEL = BigFileV2_07PC<MQFEL>;
pub type BigFileV2_07PCSHAUN = BigFileV2_07PC<SHAUN>;
pub type BigFileV2_07PCPROTO = BigFileV2_07PC<SHAUN_PROTO>;

Expand Down Expand Up @@ -203,7 +195,7 @@ impl<const GAME: usize> BigFileIo for BigFileV2_07PC<GAME> {

for resource in block.objects.iter() {
let resource = bigfile.objects.get(&resource.name).unwrap();
Resource::dump_resource(resource, &mut block_writer, endian)?;
Resource::<12>::dump_resource(resource, &mut block_writer, endian)?;
}

let block_data = block_writer.into_inner();
Expand All @@ -222,13 +214,9 @@ impl<const GAME: usize> BigFileIo for BigFileV2_07PC<GAME> {
let mut block_sizes = Vec::new();
let mut compression_type = CompressionType::None;

for (resource_count, checksum, compressed, mut block_data) in blocks {
for (resource_count, _, compressed, mut block_data) in blocks {
let block_begin = writer.stream_position()?;

if GAME == MQFEL {
checksum.write_options(writer, endian, ())?;
}

resource_count.write_options(writer, endian, ())?;

block_data.resize(decompressed_block_size as usize, 0);
Expand All @@ -251,7 +239,6 @@ impl<const GAME: usize> BigFileIo for BigFileV2_07PC<GAME> {
match GAME {
SHAUN_PROTO => 0,
SHAUN => 4,
MQFEL => 8,
_ => unreachable!(),
}
} else {
Expand Down Expand Up @@ -281,11 +268,7 @@ impl<const GAME: usize> BigFileIo for BigFileV2_07PC<GAME> {
Ok(())
}

const NAME_TYPE: NameType = if GAME == MQFEL {
Ubisoft64
} else {
BlackSheep32
};
const NAME_TYPE: NameType = BlackSheep32;

type ResourceType = Resource;
}
Loading

0 comments on commit 99854ac

Please sign in to comment.