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::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, Endian, ReadOptions};
|
use binrw::{BinReaderExt, binrw};
|
||||||
use binrw::BinRead;
|
use binrw::BinRead;
|
||||||
use binrw::BinWrite;
|
use binrw::BinWrite;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
@ -424,8 +424,7 @@ impl DatFile {
|
||||||
|
|
||||||
self.file.seek(SeekFrom::Start(original_pos)).ok()?;
|
self.file.seek(SeekFrom::Start(original_pos)).ok()?;
|
||||||
|
|
||||||
let options = ReadOptions::new(Endian::Little);
|
running_block_total += self.file.read_le::<i16>().ok()? as u64;
|
||||||
running_block_total += i16::read_options(&mut self.file, &options, ()).ok()? as u64;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,7 @@ impl GameData {
|
||||||
let slice = index_file.entries.iter().find(|s| s.hash == hash);
|
let slice = index_file.entries.iter().find(|s| s.hash == hash);
|
||||||
match slice {
|
match slice {
|
||||||
Some(entry) => {
|
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())
|
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 crate::gamedata::MemoryBuffer;
|
||||||
use binrw::{Endian, ReadOptions};
|
use binrw::BinReaderExt;
|
||||||
use binrw::binrw;
|
use binrw::binrw;
|
||||||
use binrw::BinRead;
|
use binrw::BinRead;
|
||||||
use half::f16;
|
use half::f16;
|
||||||
|
@ -409,40 +409,26 @@ impl MDL {
|
||||||
))
|
))
|
||||||
.ok()?;
|
.ok()?;
|
||||||
|
|
||||||
let 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 = cursor.read_le::<[f32; 3]>().ok()?;
|
||||||
<[f32; 3]>::read_options(&mut cursor, &options, ()).unwrap();
|
|
||||||
}
|
}
|
||||||
VertexUsage::BlendWeights => {
|
VertexUsage::BlendWeights => {
|
||||||
vertices[k as usize].bone_weight =
|
vertices[k as usize].bone_weight = cursor.read_le::<[f32; 4]>().ok()?;
|
||||||
<[f32; 4]>::read_options(&mut cursor, &options, ()).unwrap();
|
|
||||||
}
|
}
|
||||||
VertexUsage::BlendIndices => {
|
VertexUsage::BlendIndices => {
|
||||||
vertices[k as usize].bone_id =
|
vertices[k as usize].bone_id = cursor.read_le::<[u8; 4]>().ok()?;
|
||||||
<[u8; 4]>::read(&mut cursor).unwrap();
|
|
||||||
}
|
}
|
||||||
VertexUsage::Normal => {
|
VertexUsage::Normal => {
|
||||||
// TODO: normals are assumed to be half4
|
// TODO: normals are assumed to be half4
|
||||||
vertices[k as usize].normal[0] =
|
for i in 0..3 {
|
||||||
f16::from_bits(<u16 as BinRead>::read_options(&mut cursor, &options, ()).unwrap())
|
vertices[k as usize].normal[i] = f16::from_bits(cursor.read_le::<u16>().ok()?).to_f32();
|
||||||
.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();
|
|
||||||
}
|
}
|
||||||
VertexUsage::UV => {
|
VertexUsage::UV => {
|
||||||
vertices[k as usize].uv[0] =
|
for i in 0..2 {
|
||||||
f16::from_bits(<u16 as BinRead>::read_options(&mut cursor, &options, ()).unwrap())
|
vertices[k as usize].uv[i] = f16::from_bits(cursor.read_le::<u16>().ok()?).to_f32();
|
||||||
.to_f32();
|
}
|
||||||
vertices[k as usize].uv[1] =
|
|
||||||
f16::from_bits(<u16 as BinRead>::read_options(&mut cursor, &options, ()).unwrap())
|
|
||||||
.to_f32();
|
|
||||||
}
|
}
|
||||||
VertexUsage::Tangent2 => {}
|
VertexUsage::Tangent2 => {}
|
||||||
VertexUsage::Tangent1 => {}
|
VertexUsage::Tangent1 => {}
|
||||||
|
@ -463,8 +449,7 @@ 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 {
|
||||||
let options = ReadOptions::new(Endian::Little);
|
indices.push(cursor.read_le::<u16>().ok()?);
|
||||||
indices.push(<u16 as BinRead>::read_options(&mut cursor, &options, ()).unwrap());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parts.push(Part { vertices, indices });
|
parts.push(Part { vertices, indices });
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use physis::index;
|
use physis::index;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::Path;
|
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use hmac_sha512::Hash;
|
use hmac_sha512::Hash;
|
||||||
use physis::installer::install_game;
|
use physis::installer::install_game;
|
||||||
|
@ -58,7 +57,7 @@ fn fill_dir_hash(game_dir: &str) -> HashMap<String, [u8; 64]> {
|
||||||
.for_each(|x| {
|
.for_each(|x| {
|
||||||
let file = std::fs::read(x.path()).unwrap();
|
let file = std::fs::read(x.path()).unwrap();
|
||||||
|
|
||||||
let mut hash = hmac_sha512::Hash::new();
|
let mut hash = Hash::new();
|
||||||
hash.update(&file);
|
hash.update(&file);
|
||||||
let sha = hash.finalize();
|
let sha = hash.finalize();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue