1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-23 05:07:46 +00:00

Update binrw to 0.10.0

This introduces a new breaking change, namely that all endianness must
be known. I've done the best I can, but I'll be checking soon.
This commit is contained in:
Joshua Goins 2022-10-13 16:03:46 -04:00
parent eed1b5fe83
commit e86d910594
10 changed files with 43 additions and 17 deletions

16
Cargo.lock generated
View file

@ -33,20 +33,22 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]] [[package]]
name = "binrw" name = "binrw"
version = "0.9.2" version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4abb4fd60add897b9e8827e0d5fa6c2ca129ece2432d9aa13454b21ac2ecc18f" checksum = "f846d8732b2a55b569b885852ecc925a2b1f24568f4707f8b1ccd5dc6805ea9b"
dependencies = [ dependencies = [
"array-init", "array-init",
"binrw_derive", "binrw_derive",
"bytemuck",
] ]
[[package]] [[package]]
name = "binrw_derive" name = "binrw_derive"
version = "0.9.0" version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a36ff195a3a1a82d5eeb98e0069bdf3ea076042d28591396d9020fac763bf66f" checksum = "5c2aa66a5e35daf7f91ed44c945886597ef4c327f34f68b6bbf22951a250ceeb"
dependencies = [ dependencies = [
"either",
"owo-colors", "owo-colors",
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -76,6 +78,12 @@ version = "3.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d"
[[package]]
name = "bytemuck"
version = "1.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f5715e491b5a1598fc2bef5a606847b5dc1d48ea625bd3c02c00de8285591da"
[[package]] [[package]]
name = "cast" name = "cast"
version = "0.3.0" version = "0.3.0"

View file

@ -29,7 +29,7 @@ patch_testing = []
crc = "3.0.0" crc = "3.0.0"
# amazing binary parsing/writing library # amazing binary parsing/writing library
binrw = "0.9.2" binrw = "0.10.0"
# used for zlib compression in sqpack files # used for zlib compression in sqpack files
libz-sys = { version = "1.1.8", default-features = false } libz-sys = { version = "1.1.8", default-features = false }

View file

@ -1,7 +1,7 @@
use crate::gamedata::MemoryBuffer; use crate::gamedata::MemoryBuffer;
use crate::model::ModelFileHeader; use crate::model::ModelFileHeader;
use crate::sqpack::read_data_block; use crate::sqpack::read_data_block;
use binrw::binrw; use binrw::{binrw, Endian, ReadOptions};
use binrw::BinRead; use binrw::BinRead;
use binrw::BinWrite; use binrw::BinWrite;
use std::io::Write; use std::io::Write;
@ -116,6 +116,7 @@ struct TextureBlock {
/// A SqPack file info header. It can optionally contain extra information, such as texture or /// A SqPack file info header. It can optionally contain extra information, such as texture or
/// model data depending on the file type. /// model data depending on the file type.
#[derive(BinRead)] #[derive(BinRead)]
#[br(little)]
struct FileInfo { struct FileInfo {
size: u32, size: u32,
file_type: FileType, file_type: FileType,
@ -132,6 +133,7 @@ struct FileInfo {
} }
#[binrw] #[binrw]
#[br(little)]
pub struct Block { pub struct Block {
#[br(pad_after = 4)] #[br(pad_after = 4)]
offset: i32, offset: i32,
@ -154,6 +156,7 @@ pub enum CompressionMode {
#[binrw::binread] #[binrw::binread]
#[derive(Debug)] #[derive(Debug)]
#[br(little)]
pub struct BlockHeader { pub struct BlockHeader {
#[br(pad_after = 4)] #[br(pad_after = 4)]
pub size: u32, pub size: u32,
@ -380,7 +383,7 @@ impl DatFile {
buffer.seek(SeekFrom::Start(0)).ok()?; buffer.seek(SeekFrom::Start(0)).ok()?;
header.write_to(&mut buffer).ok()?; header.write(&mut buffer).ok()?;
Some(buffer.into_inner()) Some(buffer.into_inner())
} }
@ -421,7 +424,8 @@ impl DatFile {
self.file.seek(SeekFrom::Start(original_pos)).ok()?; self.file.seek(SeekFrom::Start(original_pos)).ok()?;
running_block_total += i16::read(&mut self.file).ok()? as u64; let mut options = ReadOptions::new(Endian::Little);
running_block_total += i16::read_options(&mut self.file, &options, ()).ok()? as u64;
} }
} }

View file

@ -7,6 +7,7 @@ use std::io::Cursor;
#[binrw] #[binrw]
#[brw(magic = b"FileInfo")] #[brw(magic = b"FileInfo")]
#[derive(Debug)] #[derive(Debug)]
#[br(little)]
pub struct FileInfo { pub struct FileInfo {
#[brw(pad_before = 16)] #[brw(pad_before = 16)]
#[br(ignore)] #[br(ignore)]

View file

@ -60,6 +60,7 @@ pub struct IndexEntry {
} }
#[binrw] #[binrw]
#[br(little)]
pub struct IndexFile { pub struct IndexFile {
sqpack_header: SqPackHeader, sqpack_header: SqPackHeader,

View file

@ -5,6 +5,7 @@ use std::io::{Cursor, Seek, SeekFrom};
#[binread] #[binread]
#[allow(dead_code)] #[allow(dead_code)]
#[br(little)]
pub struct ChatLogHeader { pub struct ChatLogHeader {
content_size: u32, content_size: u32,
file_size: u32, file_size: u32,
@ -46,6 +47,7 @@ enum EventChannel {
#[binread] #[binread]
#[derive(Debug)] #[derive(Debug)]
#[allow(dead_code)] #[allow(dead_code)]
#[br(little)]
pub struct ChatLogEntry { pub struct ChatLogEntry {
timestamp: u32, timestamp: u32,
filter: EventFilter, filter: EventFilter,

View file

@ -1,5 +1,5 @@
use crate::gamedata::MemoryBuffer; use crate::gamedata::MemoryBuffer;
use binrw::binread; use binrw::{binread, Endian, ReadOptions};
use binrw::binrw; use binrw::binrw;
use binrw::BinRead; use binrw::BinRead;
use half::f16; use half::f16;
@ -7,6 +7,7 @@ use std::io::{Cursor, Seek, SeekFrom};
#[binrw] #[binrw]
#[derive(Debug)] #[derive(Debug)]
#[brw(little)]
pub struct ModelFileHeader { pub struct ModelFileHeader {
pub(crate) version: u32, pub(crate) version: u32,
@ -196,6 +197,7 @@ struct BoundingBox {
#[binread] #[binread]
#[derive(Debug)] #[derive(Debug)]
#[allow(dead_code)] #[allow(dead_code)]
#[br(little)]
struct ModelData { struct ModelData {
header: ModelHeader, header: ModelHeader,
@ -285,6 +287,7 @@ enum VertexUsage {
#[binread] #[binread]
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
#[allow(dead_code)] #[allow(dead_code)]
#[br(little)]
struct VertexElement { struct VertexElement {
stream: u8, stream: u8,
offset: u8, offset: u8,
@ -404,14 +407,16 @@ impl MDL {
)) ))
.ok()?; .ok()?;
let mut options = ReadOptions::new(Endian::Little);
match element.vertex_usage { match element.vertex_usage {
VertexUsage::Position => { VertexUsage::Position => {
vertices[k as usize].position = vertices[k as usize].position =
<[f32; 3]>::read(&mut cursor).unwrap(); <[f32; 3]>::read_options(&mut cursor, &options, ()).unwrap();
} }
VertexUsage::BlendWeights => { VertexUsage::BlendWeights => {
vertices[k as usize].bone_weight = vertices[k as usize].bone_weight =
<[f32; 4]>::read(&mut cursor).unwrap(); <[f32; 4]>::read_options(&mut cursor, &options, ()).unwrap();
} }
VertexUsage::BlendIndices => { VertexUsage::BlendIndices => {
vertices[k as usize].bone_id = vertices[k as usize].bone_id =
@ -420,21 +425,21 @@ impl MDL {
VertexUsage::Normal => { VertexUsage::Normal => {
// TODO: normals are assumed to be half4 // TODO: normals are assumed to be half4
vertices[k as usize].normal[0] = vertices[k as usize].normal[0] =
f16::from_bits(<u16 as BinRead>::read(&mut cursor).unwrap()) f16::from_bits(<u16 as BinRead>::read_options(&mut cursor, &options, ()).unwrap())
.to_f32(); .to_f32();
vertices[k as usize].normal[1] = vertices[k as usize].normal[1] =
f16::from_bits(<u16 as BinRead>::read(&mut cursor).unwrap()) f16::from_bits(<u16 as BinRead>::read_options(&mut cursor, &options, ()).unwrap())
.to_f32(); .to_f32();
vertices[k as usize].normal[2] = vertices[k as usize].normal[2] =
f16::from_bits(<u16 as BinRead>::read(&mut cursor).unwrap()) f16::from_bits(<u16 as BinRead>::read_options(&mut cursor, &options, ()).unwrap())
.to_f32(); .to_f32();
} }
VertexUsage::UV => { VertexUsage::UV => {
vertices[k as usize].uv[0] = vertices[k as usize].uv[0] =
f16::from_bits(<u16 as BinRead>::read(&mut cursor).unwrap()) f16::from_bits(<u16 as BinRead>::read_options(&mut cursor, &options, ()).unwrap())
.to_f32(); .to_f32();
vertices[k as usize].uv[1] = vertices[k as usize].uv[1] =
f16::from_bits(<u16 as BinRead>::read(&mut cursor).unwrap()) f16::from_bits(<u16 as BinRead>::read_options(&mut cursor, &options, ()).unwrap())
.to_f32(); .to_f32();
} }
VertexUsage::Tangent2 => {} VertexUsage::Tangent2 => {}
@ -456,7 +461,8 @@ impl MDL {
let mut indices: Vec<u16> = let mut indices: Vec<u16> =
Vec::with_capacity(model.meshes[j as usize].index_count as usize); Vec::with_capacity(model.meshes[j as usize].index_count as usize);
for _ in 0..model.meshes[j as usize].index_count { for _ in 0..model.meshes[j as usize].index_count {
indices.push(<u16 as BinRead>::read(&mut cursor).unwrap()); let mut options = ReadOptions::new(Endian::Little);
indices.push(<u16 as BinRead>::read_options(&mut cursor, &options, ()).unwrap());
} }
parts.push(Part { vertices, indices }); parts.push(Part { vertices, indices });

View file

@ -82,6 +82,7 @@ struct Sampler {
#[binread] #[binread]
#[derive(Debug)] #[derive(Debug)]
#[allow(dead_code)] #[allow(dead_code)]
#[br(little)]
struct MaterialData { struct MaterialData {
file_header: MaterialFileHeader, file_header: MaterialFileHeader,

View file

@ -11,6 +11,7 @@ use std::path::PathBuf;
#[binread] #[binread]
#[derive(Debug)] #[derive(Debug)]
#[br(little)]
struct PatchHeader { struct PatchHeader {
#[br(temp)] #[br(temp)]
#[br(count = 7)] #[br(count = 7)]
@ -22,6 +23,7 @@ struct PatchHeader {
#[derive(BinRead, Debug)] #[derive(BinRead, Debug)]
#[allow(dead_code)] #[allow(dead_code)]
#[br(little)]
struct PatchChunk { struct PatchChunk {
#[br(big)] #[br(big)]
size: u32, size: u32,

View file

@ -49,6 +49,7 @@ enum TextureFormat {
#[binread] #[binread]
#[derive(Debug)] #[derive(Debug)]
#[allow(dead_code)] #[allow(dead_code)]
#[br(little)]
struct TexHeader { struct TexHeader {
attribute: TextureAttribute, attribute: TextureAttribute,
format: TextureFormat, format: TextureFormat,