mirror of
https://github.com/redstrate/Physis.git
synced 2025-04-23 21:17:45 +00:00
Use read_le instead of manually passing ReadOptions
This commit is contained in:
parent
3615adac47
commit
a9fa6d714a
4 changed files with 15 additions and 32 deletions
|
@ -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::<i16>().ok()? as u64;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
|
37
src/model.rs
37
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(<u16 as BinRead>::read_options(&mut cursor, &options, ()).unwrap())
|
||||
.to_f32();
|
||||
vertices[k as usize].normal[1] =
|
||||
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_options(&mut cursor, &options, ()).unwrap())
|
||||
.to_f32();
|
||||
for i in 0..3 {
|
||||
vertices[k as usize].normal[i] = f16::from_bits(cursor.read_le::<u16>().ok()?).to_f32();
|
||||
}
|
||||
}
|
||||
VertexUsage::UV => {
|
||||
vertices[k as usize].uv[0] =
|
||||
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_options(&mut cursor, &options, ()).unwrap())
|
||||
.to_f32();
|
||||
for i in 0..2 {
|
||||
vertices[k as usize].uv[i] = f16::from_bits(cursor.read_le::<u16>().ok()?).to_f32();
|
||||
}
|
||||
}
|
||||
VertexUsage::Tangent2 => {}
|
||||
VertexUsage::Tangent1 => {}
|
||||
|
@ -463,8 +449,7 @@ 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 {
|
||||
let options = ReadOptions::new(Endian::Little);
|
||||
indices.push(<u16 as BinRead>::read_options(&mut cursor, &options, ()).unwrap());
|
||||
indices.push(cursor.read_le::<u16>().ok()?);
|
||||
}
|
||||
|
||||
parts.push(Part { vertices, indices });
|
||||
|
|
|
@ -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<String, [u8; 64]> {
|
|||
.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();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue