Skip to content

Commit

Permalink
Plague tale fixes and the death of is_rtc
Browse files Browse the repository at this point in the history
  • Loading branch information
widberg committed Nov 17, 2023
1 parent f514d70 commit 879a675
Show file tree
Hide file tree
Showing 17 changed files with 111 additions and 40 deletions.
10 changes: 9 additions & 1 deletion bff/src/bigfile/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,22 @@ pub struct ManifestBlock {
pub objects: Vec<ManifestObject>,
}

#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
pub enum BigFileType {
Rtc,
Normal,
Common,
Updated1,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Manifest {
pub version: Version,
pub platform: Platform,
#[serde(skip_serializing_if = "Option::is_none")]
pub version_xple: Option<VersionXple>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rtc: Option<bool>,
pub bigfile_type: Option<BigFileType>,
#[serde(skip_serializing_if = "Option::is_none")]
pub pool_manifest_unused: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
29 changes: 26 additions & 3 deletions bff/src/bigfile/v1_06_63_02_pc/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,35 @@ pub struct BlockDescription {
pub checksum: Option<i32>,
}

#[derive(Serialize, Debug, BinRead, BinWrite, Copy, Clone)]
#[brw(repr = u32)]
pub enum BigFileType {
Rtc = 0,
Normal = 1,
}

impl From<BigFileType> for crate::bigfile::manifest::BigFileType {
fn from(bigfile_type: BigFileType) -> Self {
match bigfile_type {
BigFileType::Rtc => Self::Rtc,
BigFileType::Normal => Self::Normal,
}
}
}

impl From<crate::bigfile::manifest::BigFileType> for BigFileType {
fn from(bigfile_type: crate::bigfile::manifest::BigFileType) -> Self {
match bigfile_type {
crate::bigfile::manifest::BigFileType::Rtc => Self::Rtc,
_ => Self::Normal,
}
}
}

#[binrw]
#[derive(Serialize, Debug)]
pub struct Header {
#[br(map = |is_not_rtc: u32| is_not_rtc == 0)]
#[bw(map = |is_rtc: &bool| if *is_rtc { 0u32 } else { 1u32 })]
pub is_rtc: bool,
pub bigfile_type: BigFileType,
#[br(temp)]
#[bw(calc = block_descriptions.len() as u32)]
block_count: u32,
Expand Down
10 changes: 7 additions & 3 deletions bff/src/bigfile/v1_06_63_02_pc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::io::{Read, Seek, SeekFrom, Write};

use binrw::{BinRead, BinResult, BinWrite, Endian};
use block::Block;
use header::*;
use header::{BlockDescription, Header};
use object::Object;
use pool::Pool;

Expand Down Expand Up @@ -137,7 +137,7 @@ impl BigFileIo for BigFileV1_06_63_02PC {
version,
version_xple: Some(header.version_triple.into()),
platform,
rtc: Some(header.is_rtc),
bigfile_type: Some(header.bigfile_type.into()),
pool_manifest_unused: header.pool_manifest_unused,
incredi_builder_string: header.incredi_builder_string,
blocks,
Expand Down Expand Up @@ -441,7 +441,11 @@ impl BigFileIo for BigFileV1_06_63_02PC {
writer.seek(SeekFrom::Start(begin))?;

let header = Header {
is_rtc: bigfile.manifest.rtc.unwrap_or(false),
bigfile_type: bigfile
.manifest
.bigfile_type
.unwrap_or(BigFileType::Normal)
.into(),
block_working_buffer_capacity_even,
block_working_buffer_capacity_odd,
padded_size: block_descriptions
Expand Down
2 changes: 1 addition & 1 deletion bff/src/bigfile/v1_08_40_02_pc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl BigFileIo for BigFileV1_08_40_02PC {
version,
version_xple: Some(header.version_triple.into()),
platform,
rtc: None,
bigfile_type: None,
pool_manifest_unused: None,
incredi_builder_string: None,
blocks,
Expand Down
6 changes: 2 additions & 4 deletions bff/src/bigfile/v1_2000_77_18_pc/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ use std::io::SeekFrom;
use binrw::*;
use serde::Serialize;

use crate::bigfile::v1_06_63_02_pc::header::BlockDescription;
use crate::bigfile::v1_06_63_02_pc::header::{BigFileType, BlockDescription};
use crate::versions::VersionOneple;

#[binrw]
#[derive(Serialize, Debug)]
pub struct Header {
pub version_oneple: VersionOneple,
#[br(map = |is_not_rtc: u32| is_not_rtc == 0)]
#[bw(map = |is_rtc: &bool| if *is_rtc { 0u32 } else { 1u32 })]
pub is_rtc: bool,
pub bigfile_type: BigFileType,
#[br(temp)]
#[bw(calc = block_descriptions.len() as u32)]
block_count: u32,
Expand Down
8 changes: 6 additions & 2 deletions bff/src/bigfile/v1_2000_77_18_pc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl BigFileIo for BigFileV1_2000_77_18PC {
version,
version_xple: Some(header.version_oneple.into()),
platform,
rtc: Some(header.is_rtc),
bigfile_type: Some(header.bigfile_type.into()),
pool_manifest_unused: None,
incredi_builder_string: None,
blocks,
Expand Down Expand Up @@ -181,7 +181,11 @@ impl BigFileIo for BigFileV1_2000_77_18PC {
version_oneple: match bigfile.manifest.version_xple.unwrap_or(0.into()) {
VersionXple::Oneple(x) | VersionXple::Triple((x, _, _)) => x,
},
is_rtc: bigfile.manifest.rtc.unwrap_or(false),
bigfile_type: bigfile
.manifest
.bigfile_type
.unwrap_or(BigFileType::Normal)
.into(),
block_working_buffer_capacity_even,
block_working_buffer_capacity_odd,
total_padded_block_size: block_descriptions
Expand Down
5 changes: 2 additions & 3 deletions bff/src/bigfile/v1_2002_45_19_pc/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::io::SeekFrom;
use binrw::*;
use serde::Serialize;

use crate::bigfile::v1_06_63_02_pc::header::BigFileType;
use crate::versions::VersionOneple;

#[derive(Serialize, Debug, BinRead, BinWrite)]
Expand All @@ -17,9 +18,7 @@ pub struct BlockDescription {
#[derive(Serialize, Debug)]
pub struct Header {
pub version_oneple: VersionOneple,
#[br(map = |is_not_rtc: u32| is_not_rtc == 0)]
#[bw(map = |is_rtc: &bool| if *is_rtc { 0u32 } else { 1u32 })]
pub is_rtc: bool,
pub bigfile_type: BigFileType,
#[br(temp)]
#[bw(calc = block_descriptions.len() as u32)]
block_count: u32,
Expand Down
8 changes: 6 additions & 2 deletions bff/src/bigfile/v1_2002_45_19_pc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl BigFileIo for BigFileV1_2002_45_19PC {
version,
version_xple: Some(header.version_oneple.into()),
platform,
rtc: Some(header.is_rtc),
bigfile_type: Some(header.bigfile_type.into()),
pool_manifest_unused: None,
incredi_builder_string: None,
blocks,
Expand Down Expand Up @@ -220,7 +220,11 @@ impl BigFileIo for BigFileV1_2002_45_19PC {
version_oneple: match bigfile.manifest.version_xple.unwrap_or(0.into()) {
VersionXple::Oneple(x) | VersionXple::Triple((x, _, _)) => x,
},
is_rtc: bigfile.manifest.rtc.unwrap_or(false),
bigfile_type: bigfile
.manifest
.bigfile_type
.unwrap_or(BigFileType::Normal)
.into(),
block_working_buffer_capacity_even,
block_working_buffer_capacity_odd,
total_padded_block_size: block_descriptions
Expand Down
2 changes: 1 addition & 1 deletion bff/src/bigfile/v1_22_pc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl<const HAS_VERSION_TRIPLE: bool, const KALISTO: bool>
version: bigfile.version,
version_xple: bigfile.version_triple.map(|x| x.into()),
platform: bigfile.platform,
rtc: None,
bigfile_type: None,
pool_manifest_unused: None,
incredi_builder_string: None,
blocks,
Expand Down
2 changes: 1 addition & 1 deletion bff/src/bigfile/v2_07_pc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl<const GAME: usize> From<BigFileV2_07PC<GAME>> for BigFile {
version: bigfile.version,
version_xple: None,
platform: bigfile.platform,
rtc: None,
bigfile_type: None,
pool_manifest_unused: None,
incredi_builder_string: None,
blocks,
Expand Down
2 changes: 1 addition & 1 deletion bff/src/bigfile/v2_128_52_19_pc/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ use super::object::Object;
#[derive(BinRead, Serialize, Debug)]
#[br(import(data_count: u32))]
pub struct Data {
#[br(count = data_count)]
#[br(count = data_count, align_after = 16)]
pub objects: Vec<Object>,
}
38 changes: 34 additions & 4 deletions bff/src/bigfile/v2_128_52_19_pc/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use serde::Serialize;

use crate::helpers::DynArray;
use crate::names::Name;
use crate::versions::VersionOneple;

#[derive(Serialize, Debug, BinRead, BinWrite)]
pub struct DataDescription {
Expand Down Expand Up @@ -67,13 +68,42 @@ pub struct BlockDescription {
pub data_resources_map_offset: u32,
}

#[derive(Serialize, Debug, BinRead, BinWrite)]
#[brw(repr = u8)]
pub enum BigFileType {
Rtc = 0,
Normal = 1,
Common = 2,
Updated1 = 4,
}

impl From<BigFileType> for crate::bigfile::manifest::BigFileType {
fn from(bigfile_type: BigFileType) -> Self {
match bigfile_type {
BigFileType::Rtc => Self::Rtc,
BigFileType::Normal => Self::Normal,
BigFileType::Common => Self::Common,
BigFileType::Updated1 => Self::Updated1,
}
}
}

impl From<crate::bigfile::manifest::BigFileType> for BigFileType {
fn from(bigfile_type: crate::bigfile::manifest::BigFileType) -> Self {
match bigfile_type {
crate::bigfile::manifest::BigFileType::Rtc => Self::Rtc,
crate::bigfile::manifest::BigFileType::Normal => Self::Normal,
crate::bigfile::manifest::BigFileType::Common => Self::Common,
crate::bigfile::manifest::BigFileType::Updated1 => Self::Updated1,
}
}
}

#[binrw]
#[derive(Serialize, Debug)]
pub struct Header {
pub version_oneple: u8,
#[br(map = |is_not_rtc: u32| is_not_rtc == 0)]
#[bw(map = |is_rtc: &bool| if *is_rtc { 0u32 } else { 1u32 })]
pub is_rtc: bool,
pub bigfile_type: BigFileType,
pub version_oneple: VersionOneple,
pub block_description_offset: u32,
pub resources_block_size: u32,
pub resources_block_offset: u32,
Expand Down
4 changes: 2 additions & 2 deletions bff/src/bigfile/v2_128_52_19_pc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ impl BigFileIo for BigFileV2_128_52_19PC {
Ok(BigFile {
manifest: Manifest {
version,
version_xple: Some((header.version_oneple as u32).into()),
version_xple: Some(header.version_oneple.into()),
platform,
rtc: Some(header.is_rtc),
bigfile_type: Some(header.bigfile_type.into()),
pool_manifest_unused: None,
incredi_builder_string: None,
blocks,
Expand Down
16 changes: 9 additions & 7 deletions bff/src/bigfile/v2_128_92_19_pc/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::io::SeekFrom;
use binrw::*;
use serde::Serialize;

use crate::bigfile::v1_06_63_02_pc::header::BigFileType;
use crate::helpers::DynArray;
use crate::names::Name;
use crate::versions::VersionOneple;
Expand Down Expand Up @@ -60,19 +61,20 @@ pub struct BlockDescription {
#[derive(Serialize, Debug)]
pub struct Header {
pub version_oneple: VersionOneple,
#[br(map = |is_not_rtc: u32| is_not_rtc == 0)]
#[bw(map = |is_rtc: &bool| if *is_rtc { 0u32 } else { 1u32 })]
pub is_rtc: bool,
pub block_description_offset: u64,
pub block_working_buffer_capacity_even: u64,
pub block_working_buffer_capacity_odd: u64,
pub bigfile_type: BigFileType,
pub block_description_offset: u32,
pub unk1: u32,
pub pool_offset: u32,
pub unk3: u32,
pub unk4: u32,
pub unk5: u32,
pub total_padded_block_size: u64,
pub block_sector_padding_size: u64,
pub file_size: u64,
pub total_decompressed_size: u64,
pub zero: u64,
#[brw(align_after = 4096)]
pub total_resource_count: u32,
#[br(seek_before = SeekFrom::Start(block_description_offset * 2048))]
#[br(seek_before = SeekFrom::Start(block_description_offset as u64 * 2048))]
pub block_descriptions: DynArray<BlockDescription>,
}
2 changes: 1 addition & 1 deletion bff/src/bigfile/v2_128_92_19_pc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl BigFileIo for BigFileV2_128_92_19PC {
version,
version_xple: Some(header.version_oneple.into()),
platform,
rtc: Some(header.is_rtc),
bigfile_type: Some(header.bigfile_type.into()),
pool_manifest_unused: None,
incredi_builder_string: None,
blocks,
Expand Down
5 changes: 2 additions & 3 deletions bff/src/bigfile/v2_256_38_19_pc/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::io::SeekFrom;
use binrw::*;
use serde::Serialize;

use crate::bigfile::v1_06_63_02_pc::header::BigFileType;
use crate::helpers::DynArray;
use crate::names::Name;
use crate::versions::VersionOneple;
Expand Down Expand Up @@ -64,9 +65,7 @@ pub struct BlockDescription {
#[derive(Serialize, Debug)]
pub struct Header {
pub version_oneple: VersionOneple,
#[br(map = |is_not_rtc: u32| is_not_rtc == 0)]
#[bw(map = |is_rtc: &bool| if *is_rtc { 0u32 } else { 1u32 })]
pub is_rtc: bool,
pub bigfile_type: BigFileType,
pub block_description_offset: u32,
pub unk1: u32,
pub unk2: u64,
Expand Down
2 changes: 1 addition & 1 deletion bff/src/bigfile/v2_256_38_19_pc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl BigFileIo for BigFileV2_256_38_19PC {
version,
version_xple: Some(header.version_oneple.into()),
platform,
rtc: Some(header.is_rtc),
bigfile_type: Some(header.bigfile_type.into()),
pool_manifest_unused: None,
incredi_builder_string: None,
blocks,
Expand Down

0 comments on commit 879a675

Please sign in to comment.