1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-22 20:57: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]]
name = "binrw"
version = "0.9.2"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4abb4fd60add897b9e8827e0d5fa6c2ca129ece2432d9aa13454b21ac2ecc18f"
checksum = "f846d8732b2a55b569b885852ecc925a2b1f24568f4707f8b1ccd5dc6805ea9b"
dependencies = [
"array-init",
"binrw_derive",
"bytemuck",
]
[[package]]
name = "binrw_derive"
version = "0.9.0"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a36ff195a3a1a82d5eeb98e0069bdf3ea076042d28591396d9020fac763bf66f"
checksum = "5c2aa66a5e35daf7f91ed44c945886597ef4c327f34f68b6bbf22951a250ceeb"
dependencies = [
"either",
"owo-colors",
"proc-macro2",
"quote",
@ -76,6 +78,12 @@ version = "3.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d"
[[package]]
name = "bytemuck"
version = "1.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f5715e491b5a1598fc2bef5a606847b5dc1d48ea625bd3c02c00de8285591da"
[[package]]
name = "cast"
version = "0.3.0"

View file

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

View file

@ -1,7 +1,7 @@
use crate::gamedata::MemoryBuffer;
use crate::model::ModelFileHeader;
use crate::sqpack::read_data_block;
use binrw::binrw;
use binrw::{binrw, Endian, ReadOptions};
use binrw::BinRead;
use binrw::BinWrite;
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
/// model data depending on the file type.
#[derive(BinRead)]
#[br(little)]
struct FileInfo {
size: u32,
file_type: FileType,
@ -132,6 +133,7 @@ struct FileInfo {
}
#[binrw]
#[br(little)]
pub struct Block {
#[br(pad_after = 4)]
offset: i32,
@ -154,6 +156,7 @@ pub enum CompressionMode {
#[binrw::binread]
#[derive(Debug)]
#[br(little)]
pub struct BlockHeader {
#[br(pad_after = 4)]
pub size: u32,
@ -380,7 +383,7 @@ impl DatFile {
buffer.seek(SeekFrom::Start(0)).ok()?;
header.write_to(&mut buffer).ok()?;
header.write(&mut buffer).ok()?;
Some(buffer.into_inner())
}
@ -421,7 +424,8 @@ impl DatFile {
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]
#[brw(magic = b"FileInfo")]
#[derive(Debug)]
#[br(little)]
pub struct FileInfo {
#[brw(pad_before = 16)]
#[br(ignore)]

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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