diff --git a/src/dat.rs b/src/dat.rs index cb9aa88..2f3efc3 100755 --- a/src/dat.rs +++ b/src/dat.rs @@ -1,7 +1,7 @@ use crate::gamedata::MemoryBuffer; use crate::model::ModelFileHeader; use crate::sqpack::read_data_block; -use binrw::{binrw, Endian, ReadOptions}; +use binrw::{BinReaderExt, binrw}; use binrw::BinRead; use binrw::BinWrite; use std::io::Write; @@ -424,8 +424,7 @@ impl DatFile { self.file.seek(SeekFrom::Start(original_pos)).ok()?; - let options = ReadOptions::new(Endian::Little); - running_block_total += i16::read_options(&mut self.file, &options, ()).ok()? as u64; + running_block_total += self.file.read_le::().ok()? as u64; } } diff --git a/src/gamedata.rs b/src/gamedata.rs index 708ebd0..7197d13 100755 --- a/src/gamedata.rs +++ b/src/gamedata.rs @@ -165,7 +165,7 @@ impl GameData { let slice = index_file.entries.iter().find(|s| s.hash == hash); match slice { Some(entry) => { - let mut dat_file = self.get_dat_file(path, entry.bitfield.data_file_id())?; + let mut dat_file = self.get_dat_file(path, entry.bitfield.data_file_id().into())?; dat_file.read_from_offset(entry.bitfield.offset()) } diff --git a/src/model.rs b/src/model.rs index 8a35dbc..3f89aa7 100755 --- a/src/model.rs +++ b/src/model.rs @@ -1,5 +1,5 @@ use crate::gamedata::MemoryBuffer; -use binrw::{Endian, ReadOptions}; +use binrw::BinReaderExt; use binrw::binrw; use binrw::BinRead; use half::f16; @@ -409,40 +409,26 @@ impl MDL { )) .ok()?; - let options = ReadOptions::new(Endian::Little); - match element.vertex_usage { VertexUsage::Position => { - vertices[k as usize].position = - <[f32; 3]>::read_options(&mut cursor, &options, ()).unwrap(); + vertices[k as usize].position = cursor.read_le::<[f32; 3]>().ok()?; } VertexUsage::BlendWeights => { - vertices[k as usize].bone_weight = - <[f32; 4]>::read_options(&mut cursor, &options, ()).unwrap(); + vertices[k as usize].bone_weight = cursor.read_le::<[f32; 4]>().ok()?; } VertexUsage::BlendIndices => { - vertices[k as usize].bone_id = - <[u8; 4]>::read(&mut cursor).unwrap(); + vertices[k as usize].bone_id = cursor.read_le::<[u8; 4]>().ok()?; } VertexUsage::Normal => { // TODO: normals are assumed to be half4 - vertices[k as usize].normal[0] = - f16::from_bits(::read_options(&mut cursor, &options, ()).unwrap()) - .to_f32(); - vertices[k as usize].normal[1] = - f16::from_bits(::read_options(&mut cursor, &options, ()).unwrap()) - .to_f32(); - vertices[k as usize].normal[2] = - f16::from_bits(::read_options(&mut cursor, &options, ()).unwrap()) - .to_f32(); + for i in 0..3 { + vertices[k as usize].normal[i] = f16::from_bits(cursor.read_le::().ok()?).to_f32(); + } } VertexUsage::UV => { - vertices[k as usize].uv[0] = - f16::from_bits(::read_options(&mut cursor, &options, ()).unwrap()) - .to_f32(); - vertices[k as usize].uv[1] = - f16::from_bits(::read_options(&mut cursor, &options, ()).unwrap()) - .to_f32(); + for i in 0..2 { + vertices[k as usize].uv[i] = f16::from_bits(cursor.read_le::().ok()?).to_f32(); + } } VertexUsage::Tangent2 => {} VertexUsage::Tangent1 => {} @@ -463,8 +449,7 @@ impl MDL { let mut indices: Vec = Vec::with_capacity(model.meshes[j as usize].index_count as usize); for _ in 0..model.meshes[j as usize].index_count { - let options = ReadOptions::new(Endian::Little); - indices.push(::read_options(&mut cursor, &options, ()).unwrap()); + indices.push(cursor.read_le::().ok()?); } parts.push(Part { vertices, indices }); diff --git a/tests/integration_test.rs b/tests/integration_test.rs index 24e7f20..a2a8aa5 100755 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -1,7 +1,6 @@ use std::collections::HashMap; use physis::index; use std::env; -use std::path::Path; use std::process::Command; use hmac_sha512::Hash; use physis::installer::install_game; @@ -58,7 +57,7 @@ fn fill_dir_hash(game_dir: &str) -> HashMap { .for_each(|x| { let file = std::fs::read(x.path()).unwrap(); - let mut hash = hmac_sha512::Hash::new(); + let mut hash = Hash::new(); hash.update(&file); let sha = hash.finalize();