mirror of
https://github.com/redstrate/Physis.git
synced 2025-04-25 13:57:45 +00:00
Make a semantic difference between owned and non-owned byte data
This commit is contained in:
parent
07582775cd
commit
7a75c170cc
17 changed files with 60 additions and 64 deletions
11
src/cfg.rs
11
src/cfg.rs
|
@ -3,8 +3,7 @@
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io::{BufRead, BufReader, BufWriter, Cursor, Write};
|
use std::io::{BufRead, BufReader, BufWriter, Cursor, Write};
|
||||||
|
use crate::{ByteBuffer, ByteSpan};
|
||||||
use crate::gamedata::MemoryBuffer;
|
|
||||||
|
|
||||||
/// Represents a collection of keys, mapped to their values.
|
/// Represents a collection of keys, mapped to their values.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -24,7 +23,7 @@ pub struct ConfigFile {
|
||||||
|
|
||||||
impl ConfigFile {
|
impl ConfigFile {
|
||||||
/// Parses an existing config file.
|
/// Parses an existing config file.
|
||||||
pub fn from_existing(buffer: &MemoryBuffer) -> Option<ConfigFile> {
|
pub fn from_existing(buffer: ByteSpan) -> Option<ConfigFile> {
|
||||||
let mut cfg = ConfigFile {
|
let mut cfg = ConfigFile {
|
||||||
categories: Vec::new(),
|
categories: Vec::new(),
|
||||||
settings: HashMap::new()
|
settings: HashMap::new()
|
||||||
|
@ -55,8 +54,8 @@ impl ConfigFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Writes an existing config file to a buffer.
|
/// Writes an existing config file to a buffer.
|
||||||
pub fn write_to_buffer(&self) -> Option<MemoryBuffer> {
|
pub fn write_to_buffer(&self) -> Option<ByteBuffer> {
|
||||||
let mut buffer = MemoryBuffer::new();
|
let mut buffer = ByteBuffer::new();
|
||||||
|
|
||||||
{
|
{
|
||||||
let cursor = Cursor::new(&mut buffer);
|
let cursor = Cursor::new(&mut buffer);
|
||||||
|
@ -128,7 +127,7 @@ mod tests {
|
||||||
ConfigFile::from_existing(&read(d).unwrap()).unwrap()
|
ConfigFile::from_existing(&read(d).unwrap()).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn common_setup_modified() -> MemoryBuffer {
|
fn common_setup_modified() -> ByteBuffer {
|
||||||
let mut d = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
let mut d = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||||
d.push("resources/tests");
|
d.push("resources/tests");
|
||||||
d.push("FFXIV.modified.cfg");
|
d.push("FFXIV.modified.cfg");
|
||||||
|
|
|
@ -5,8 +5,8 @@ use std::io::{BufWriter, Cursor};
|
||||||
|
|
||||||
use binrw::{BinRead, BinWrite};
|
use binrw::{BinRead, BinWrite};
|
||||||
use binrw::binrw;
|
use binrw::binrw;
|
||||||
|
use crate::{ByteBuffer, ByteSpan};
|
||||||
|
|
||||||
use crate::gamedata::MemoryBuffer;
|
|
||||||
use crate::race::{Gender, Race, Subrace};
|
use crate::race::{Gender, Race, Subrace};
|
||||||
|
|
||||||
fn convert_dat_race(x: u8) -> Race {
|
fn convert_dat_race(x: u8) -> Race {
|
||||||
|
@ -201,15 +201,15 @@ pub struct CharacterData { // version 4
|
||||||
|
|
||||||
impl CharacterData {
|
impl CharacterData {
|
||||||
/// Parses existing character data.
|
/// Parses existing character data.
|
||||||
pub fn from_existing(buffer: &MemoryBuffer) -> Option<CharacterData> {
|
pub fn from_existing(buffer: ByteSpan) -> Option<CharacterData> {
|
||||||
let mut cursor = Cursor::new(buffer);
|
let mut cursor = Cursor::new(buffer);
|
||||||
|
|
||||||
CharacterData::read(&mut cursor).ok()
|
CharacterData::read(&mut cursor).ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Write existing character data to a buffer.
|
/// Write existing character data to a buffer.
|
||||||
pub fn write_to_buffer(&self) -> Option<MemoryBuffer> {
|
pub fn write_to_buffer(&self) -> Option<ByteBuffer> {
|
||||||
let mut buffer = MemoryBuffer::new();
|
let mut buffer = ByteBuffer::new();
|
||||||
|
|
||||||
{
|
{
|
||||||
let cursor = Cursor::new(&mut buffer);
|
let cursor = Cursor::new(&mut buffer);
|
||||||
|
|
|
@ -5,8 +5,7 @@ use std::io::{Cursor, Seek, SeekFrom};
|
||||||
|
|
||||||
use binrw::BinRead;
|
use binrw::BinRead;
|
||||||
use binrw::binrw;
|
use binrw::binrw;
|
||||||
|
use crate::ByteSpan;
|
||||||
use crate::gamedata::MemoryBuffer;
|
|
||||||
|
|
||||||
#[binrw]
|
#[binrw]
|
||||||
#[br(little)]
|
#[br(little)]
|
||||||
|
@ -41,7 +40,7 @@ pub struct CMP {
|
||||||
|
|
||||||
impl CMP {
|
impl CMP {
|
||||||
/// Parses an existing FIIN file.
|
/// Parses an existing FIIN file.
|
||||||
pub fn from_existing(buffer: &MemoryBuffer) -> Option<CMP> {
|
pub fn from_existing(buffer: ByteSpan) -> Option<CMP> {
|
||||||
let mut cursor = Cursor::new(buffer);
|
let mut cursor = Cursor::new(buffer);
|
||||||
|
|
||||||
cursor.seek(SeekFrom::Start(0x2a800)).unwrap();
|
cursor.seek(SeekFrom::Start(0x2a800)).unwrap();
|
||||||
|
|
10
src/dat.rs
10
src/dat.rs
|
@ -7,8 +7,8 @@ use std::io::Write;
|
||||||
use binrw::{BinReaderExt, binrw};
|
use binrw::{BinReaderExt, binrw};
|
||||||
use binrw::BinRead;
|
use binrw::BinRead;
|
||||||
use binrw::BinWrite;
|
use binrw::BinWrite;
|
||||||
|
use crate::ByteBuffer;
|
||||||
|
|
||||||
use crate::gamedata::MemoryBuffer;
|
|
||||||
#[cfg(feature = "visual_data")]
|
#[cfg(feature = "visual_data")]
|
||||||
use crate::model::ModelFileHeader;
|
use crate::model::ModelFileHeader;
|
||||||
use crate::sqpack::read_data_block;
|
use crate::sqpack::read_data_block;
|
||||||
|
@ -191,7 +191,7 @@ impl DatFile {
|
||||||
/// by the function.
|
/// by the function.
|
||||||
///
|
///
|
||||||
/// If the block of data is successfully parsed, it returns the file data - otherwise is None.
|
/// If the block of data is successfully parsed, it returns the file data - otherwise is None.
|
||||||
pub fn read_from_offset(&mut self, offset: u32) -> Option<MemoryBuffer> {
|
pub fn read_from_offset(&mut self, offset: u32) -> Option<ByteBuffer> {
|
||||||
let offset = (offset * 0x80) as u64;
|
let offset = (offset * 0x80) as u64;
|
||||||
|
|
||||||
self.file
|
self.file
|
||||||
|
@ -219,7 +219,7 @@ impl DatFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reads a standard file block.
|
/// Reads a standard file block.
|
||||||
fn read_standard_file(&mut self, offset: u64, file_info: &FileInfo) -> Option<MemoryBuffer> {
|
fn read_standard_file(&mut self, offset: u64, file_info: &FileInfo) -> Option<ByteBuffer> {
|
||||||
let standard_file_info = file_info.standard_info.as_ref().unwrap();
|
let standard_file_info = file_info.standard_info.as_ref().unwrap();
|
||||||
|
|
||||||
let mut blocks: Vec<Block> = Vec::with_capacity(standard_file_info.num_blocks as usize);
|
let mut blocks: Vec<Block> = Vec::with_capacity(standard_file_info.num_blocks as usize);
|
||||||
|
@ -247,7 +247,7 @@ impl DatFile {
|
||||||
|
|
||||||
/// Reads a model file block.
|
/// Reads a model file block.
|
||||||
#[cfg(feature = "visual_data")]
|
#[cfg(feature = "visual_data")]
|
||||||
fn read_model_file(&mut self, offset: u64, file_info: &FileInfo) -> Option<MemoryBuffer> {
|
fn read_model_file(&mut self, offset: u64, file_info: &FileInfo) -> Option<ByteBuffer> {
|
||||||
let mut buffer = Cursor::new(Vec::new());
|
let mut buffer = Cursor::new(Vec::new());
|
||||||
|
|
||||||
let model_file_info = file_info.model_info.as_ref().unwrap();
|
let model_file_info = file_info.model_info.as_ref().unwrap();
|
||||||
|
@ -397,7 +397,7 @@ impl DatFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reads a texture file block.
|
/// Reads a texture file block.
|
||||||
fn read_texture_file(&mut self, offset: u64, file_info: &FileInfo) -> Option<MemoryBuffer> {
|
fn read_texture_file(&mut self, offset: u64, file_info: &FileInfo) -> Option<ByteBuffer> {
|
||||||
let mut data: Vec<u8> = Vec::with_capacity(file_info.file_size as usize);
|
let mut data: Vec<u8> = Vec::with_capacity(file_info.file_size as usize);
|
||||||
|
|
||||||
let texture_file_info = file_info.texture_info.as_ref().unwrap();
|
let texture_file_info = file_info.texture_info.as_ref().unwrap();
|
||||||
|
|
|
@ -8,7 +8,7 @@ use binrw::binrw;
|
||||||
|
|
||||||
use crate::common::Language;
|
use crate::common::Language;
|
||||||
use crate::exh::{ColumnDataType, ExcelColumnDefinition, ExcelDataPagination, EXH};
|
use crate::exh::{ColumnDataType, ExcelColumnDefinition, ExcelDataPagination, EXH};
|
||||||
use crate::gamedata::MemoryBuffer;
|
use crate::ByteSpan;
|
||||||
|
|
||||||
#[binrw]
|
#[binrw]
|
||||||
#[brw(magic = b"EXDF")]
|
#[brw(magic = b"EXDF")]
|
||||||
|
@ -70,7 +70,7 @@ pub struct ExcelRow {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EXD {
|
impl EXD {
|
||||||
fn read_data_raw<Z: BinRead<Args<'static> = ()>>(cursor: &mut Cursor<&MemoryBuffer>) -> Option<Z>
|
fn read_data_raw<Z: BinRead<Args<'static> = ()>>(cursor: &mut Cursor<ByteSpan>) -> Option<Z>
|
||||||
{
|
{
|
||||||
Some(
|
Some(
|
||||||
Z::read_options(
|
Z::read_options(
|
||||||
|
@ -83,7 +83,7 @@ impl EXD {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_column(
|
fn read_column(
|
||||||
cursor: &mut Cursor<&MemoryBuffer>,
|
cursor: &mut Cursor<ByteSpan>,
|
||||||
exh: &EXH,
|
exh: &EXH,
|
||||||
offset: u32,
|
offset: u32,
|
||||||
column: &ExcelColumnDefinition,
|
column: &ExcelColumnDefinition,
|
||||||
|
@ -149,7 +149,7 @@ impl EXD {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_existing(exh: &EXH, buffer: &MemoryBuffer) -> Option<EXD> {
|
pub fn from_existing(exh: &EXH, buffer: ByteSpan) -> Option<EXD> {
|
||||||
let mut cursor = Cursor::new(buffer);
|
let mut cursor = Cursor::new(buffer);
|
||||||
let mut exd = EXD::read(&mut cursor).ok()?;
|
let mut exd = EXD::read(&mut cursor).ok()?;
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ use binrw::BinRead;
|
||||||
use binrw::binrw;
|
use binrw::binrw;
|
||||||
|
|
||||||
use crate::common::Language;
|
use crate::common::Language;
|
||||||
use crate::gamedata::MemoryBuffer;
|
use crate::ByteSpan;
|
||||||
|
|
||||||
#[binrw]
|
#[binrw]
|
||||||
#[brw(magic = b"EXHF")]
|
#[brw(magic = b"EXHF")]
|
||||||
|
@ -83,7 +83,7 @@ pub struct EXH {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EXH {
|
impl EXH {
|
||||||
pub fn from_existing(buffer: &MemoryBuffer) -> Option<EXH> {
|
pub fn from_existing(buffer: ByteSpan) -> Option<EXH> {
|
||||||
EXH::read(&mut Cursor::new(&buffer)).ok()
|
EXH::read(&mut Cursor::new(&buffer)).ok()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
use std::io::{BufRead, BufReader, BufWriter, Cursor, Write};
|
use std::io::{BufRead, BufReader, BufWriter, Cursor, Write};
|
||||||
|
use crate::{ByteBuffer, ByteSpan};
|
||||||
use crate::gamedata::MemoryBuffer;
|
|
||||||
|
|
||||||
/// Represents an Excel List.
|
/// Represents an Excel List.
|
||||||
pub struct EXL {
|
pub struct EXL {
|
||||||
|
@ -16,7 +15,7 @@ pub struct EXL {
|
||||||
|
|
||||||
impl EXL {
|
impl EXL {
|
||||||
/// Initializes `EXL` from an existing list.
|
/// Initializes `EXL` from an existing list.
|
||||||
pub fn from_existing(buffer: &MemoryBuffer) -> Option<EXL> {
|
pub fn from_existing(buffer: ByteSpan) -> Option<EXL> {
|
||||||
let mut exl = Self {
|
let mut exl = Self {
|
||||||
version: 0,
|
version: 0,
|
||||||
entries: Vec::new(),
|
entries: Vec::new(),
|
||||||
|
@ -43,8 +42,8 @@ impl EXL {
|
||||||
Some(exl)
|
Some(exl)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_to_buffer(&self) -> Option<MemoryBuffer> {
|
pub fn write_to_buffer(&self) -> Option<ByteBuffer> {
|
||||||
let mut buffer = MemoryBuffer::new();
|
let mut buffer = ByteBuffer::new();
|
||||||
|
|
||||||
{
|
{
|
||||||
let cursor = Cursor::new(&mut buffer);
|
let cursor = Cursor::new(&mut buffer);
|
||||||
|
|
|
@ -6,8 +6,8 @@ use std::io::Cursor;
|
||||||
|
|
||||||
use binrw::{BinRead, BinWrite};
|
use binrw::{BinRead, BinWrite};
|
||||||
use binrw::binrw;
|
use binrw::binrw;
|
||||||
|
use crate::{ByteBuffer, ByteSpan};
|
||||||
|
|
||||||
use crate::gamedata::MemoryBuffer;
|
|
||||||
use crate::sha1::Sha1;
|
use crate::sha1::Sha1;
|
||||||
|
|
||||||
#[binrw]
|
#[binrw]
|
||||||
|
@ -47,13 +47,13 @@ pub struct FIINEntry {
|
||||||
|
|
||||||
impl FileInfo {
|
impl FileInfo {
|
||||||
/// Parses an existing FIIN file.
|
/// Parses an existing FIIN file.
|
||||||
pub fn from_existing(buffer: &MemoryBuffer) -> Option<FileInfo> {
|
pub fn from_existing(buffer: ByteSpan) -> Option<FileInfo> {
|
||||||
let mut cursor = Cursor::new(buffer);
|
let mut cursor = Cursor::new(buffer);
|
||||||
FileInfo::read(&mut cursor).ok()
|
FileInfo::read(&mut cursor).ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_to_buffer(&self) -> Option<MemoryBuffer> {
|
pub fn write_to_buffer(&self) -> Option<ByteBuffer> {
|
||||||
let mut buffer = MemoryBuffer::new();
|
let mut buffer = ByteBuffer::new();
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut cursor = Cursor::new(&mut buffer);
|
let mut cursor = Cursor::new(&mut buffer);
|
||||||
|
|
|
@ -13,6 +13,7 @@ use crate::exd::EXD;
|
||||||
use crate::exh::EXH;
|
use crate::exh::EXH;
|
||||||
use crate::exl::EXL;
|
use crate::exl::EXL;
|
||||||
use crate::index::IndexFile;
|
use crate::index::IndexFile;
|
||||||
|
use crate::ByteBuffer;
|
||||||
use crate::patch::{apply_patch, PatchError};
|
use crate::patch::{apply_patch, PatchError};
|
||||||
use crate::repository::{Category, Repository, string_to_category};
|
use crate::repository::{Category, Repository, string_to_category};
|
||||||
use crate::sqpack::calculate_hash;
|
use crate::sqpack::calculate_hash;
|
||||||
|
@ -48,8 +49,6 @@ pub enum RepairError<'a> {
|
||||||
FailedRepair(&'a Repository),
|
FailedRepair(&'a Repository),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type MemoryBuffer = Vec<u8>;
|
|
||||||
|
|
||||||
impl GameData {
|
impl GameData {
|
||||||
/// Read game data from an existing game installation.
|
/// Read game data from an existing game installation.
|
||||||
///
|
///
|
||||||
|
@ -187,7 +186,7 @@ impl GameData {
|
||||||
/// let mut file = std::fs::File::create("root.exl").unwrap();
|
/// let mut file = std::fs::File::create("root.exl").unwrap();
|
||||||
/// file.write(data.as_slice()).unwrap();
|
/// file.write(data.as_slice()).unwrap();
|
||||||
/// ```
|
/// ```
|
||||||
pub fn extract(&self, path: &str) -> Option<MemoryBuffer> {
|
pub fn extract(&self, path: &str) -> Option<ByteBuffer> {
|
||||||
debug!(file=path, "Extracting file");
|
debug!(file=path, "Extracting file");
|
||||||
|
|
||||||
let hash = calculate_hash(path);
|
let hash = calculate_hash(path);
|
||||||
|
|
|
@ -5,6 +5,12 @@
|
||||||
|
|
||||||
extern crate core;
|
extern crate core;
|
||||||
|
|
||||||
|
/// Represents a continuous block of memory which is not owned, and comes either from an in-memory location or from a file.
|
||||||
|
pub type ByteSpan<'a> = &'a[u8];
|
||||||
|
|
||||||
|
/// Represents a continuous block of memory which is owned.
|
||||||
|
pub type ByteBuffer = Vec<u8>;
|
||||||
|
|
||||||
/// Reading and writing game data repositories, such as "ffxiv" and "ex1", and so on.
|
/// Reading and writing game data repositories, such as "ffxiv" and "ex1", and so on.
|
||||||
pub mod gamedata;
|
pub mod gamedata;
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,7 @@ use std::io::{Cursor, Seek, SeekFrom};
|
||||||
|
|
||||||
use binrw::BinRead;
|
use binrw::BinRead;
|
||||||
use binrw::binrw;
|
use binrw::binrw;
|
||||||
|
use crate::ByteSpan;
|
||||||
use crate::gamedata::MemoryBuffer;
|
|
||||||
|
|
||||||
#[binrw]
|
#[binrw]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
@ -73,7 +72,7 @@ pub struct ChatLog {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChatLog {
|
impl ChatLog {
|
||||||
pub fn from_existing(buffer: &MemoryBuffer) -> Option<ChatLog> {
|
pub fn from_existing(buffer: ByteSpan) -> Option<ChatLog> {
|
||||||
let mut cursor = Cursor::new(buffer);
|
let mut cursor = Cursor::new(buffer);
|
||||||
|
|
||||||
let header = ChatLogHeader::read(&mut cursor).expect("Cannot parse header.");
|
let header = ChatLogHeader::read(&mut cursor).expect("Cannot parse header.");
|
||||||
|
|
19
src/model.rs
19
src/model.rs
|
@ -7,8 +7,7 @@ use binrw::{BinResult, binrw, BinWrite, BinWriterExt};
|
||||||
use binrw::BinRead;
|
use binrw::BinRead;
|
||||||
use binrw::BinReaderExt;
|
use binrw::BinReaderExt;
|
||||||
use half::f16;
|
use half::f16;
|
||||||
|
use crate::{ByteBuffer, ByteSpan};
|
||||||
use crate::gamedata::MemoryBuffer;
|
|
||||||
|
|
||||||
#[binrw]
|
#[binrw]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -342,7 +341,7 @@ pub struct MDL {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MDL {
|
impl MDL {
|
||||||
pub fn from_existing(buffer: &MemoryBuffer) -> Option<MDL> {
|
pub fn from_existing(buffer: ByteSpan) -> Option<MDL> {
|
||||||
let mut cursor = Cursor::new(buffer);
|
let mut cursor = Cursor::new(buffer);
|
||||||
let model_file_header = ModelFileHeader::read(&mut cursor).unwrap();
|
let model_file_header = ModelFileHeader::read(&mut cursor).unwrap();
|
||||||
|
|
||||||
|
@ -537,8 +536,8 @@ impl MDL {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_to_buffer(&self) -> Option<MemoryBuffer> {
|
pub fn write_to_buffer(&self) -> Option<ByteBuffer> {
|
||||||
let mut buffer = MemoryBuffer::new();
|
let mut buffer = ByteBuffer::new();
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut cursor = Cursor::new(&mut buffer);
|
let mut cursor = Cursor::new(&mut buffer);
|
||||||
|
@ -665,7 +664,7 @@ impl MDL {
|
||||||
Some(buffer)
|
Some(buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_byte_float4(cursor: &mut Cursor<&MemoryBuffer>) -> Option<[f32; 4]> {
|
fn read_byte_float4(cursor: &mut Cursor<ByteSpan>) -> Option<[f32; 4]> {
|
||||||
Some([
|
Some([
|
||||||
f32::from(cursor.read_le::<u8>().ok()?) / 255.0,
|
f32::from(cursor.read_le::<u8>().ok()?) / 255.0,
|
||||||
f32::from(cursor.read_le::<u8>().ok()?) / 255.0,
|
f32::from(cursor.read_le::<u8>().ok()?) / 255.0,
|
||||||
|
@ -674,7 +673,7 @@ impl MDL {
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_half4(cursor: &mut Cursor<&MemoryBuffer>) -> Option<[f32; 4]> {
|
fn read_half4(cursor: &mut Cursor<ByteSpan>) -> Option<[f32; 4]> {
|
||||||
Some([
|
Some([
|
||||||
f16::from_bits(cursor.read_le::<u16>().ok()?).to_f32(),
|
f16::from_bits(cursor.read_le::<u16>().ok()?).to_f32(),
|
||||||
f16::from_bits(cursor.read_le::<u16>().ok()?).to_f32(),
|
f16::from_bits(cursor.read_le::<u16>().ok()?).to_f32(),
|
||||||
|
@ -683,7 +682,7 @@ impl MDL {
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_uint(cursor: &mut Cursor<&MemoryBuffer>) -> BinResult<[u8; 4]> {
|
fn read_uint(cursor: &mut Cursor<ByteSpan>) -> BinResult<[u8; 4]> {
|
||||||
cursor.read_le::<[u8; 4]>()
|
cursor.read_le::<[u8; 4]>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -691,7 +690,7 @@ impl MDL {
|
||||||
cursor.write_le(vec)
|
cursor.write_le(vec)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_single3(cursor: &mut Cursor<&MemoryBuffer>) -> BinResult<[f32; 3]> {
|
fn read_single3(cursor: &mut Cursor<ByteSpan>) -> BinResult<[f32; 3]> {
|
||||||
cursor.read_le::<[f32; 3]>()
|
cursor.read_le::<[f32; 3]>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -699,7 +698,7 @@ impl MDL {
|
||||||
cursor.write_le(vec)
|
cursor.write_le(vec)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_single4(cursor: &mut Cursor<&MemoryBuffer>) -> BinResult<[f32; 4]> {
|
fn read_single4(cursor: &mut Cursor<ByteSpan>) -> BinResult<[f32; 4]> {
|
||||||
cursor.read_le::<[f32; 4]>()
|
cursor.read_le::<[f32; 4]>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
|
||||||
use binrw::{BinRead, binrw};
|
use binrw::{BinRead, binrw};
|
||||||
|
use crate::ByteSpan;
|
||||||
use crate::gamedata::MemoryBuffer;
|
|
||||||
|
|
||||||
#[binrw]
|
#[binrw]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -128,7 +127,7 @@ pub struct Material {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Material {
|
impl Material {
|
||||||
pub fn from_existing(buffer: &MemoryBuffer) -> Option<Material> {
|
pub fn from_existing(buffer: ByteSpan) -> Option<Material> {
|
||||||
let mut cursor = Cursor::new(buffer);
|
let mut cursor = Cursor::new(buffer);
|
||||||
let mat_data = MaterialData::read(&mut cursor).ok()?;
|
let mat_data = MaterialData::read(&mut cursor).ok()?;
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,7 @@ use std::io::{Cursor, Seek, SeekFrom};
|
||||||
|
|
||||||
use binrw::{BinRead, BinReaderExt, BinWrite};
|
use binrw::{BinRead, BinReaderExt, BinWrite};
|
||||||
use binrw::binrw;
|
use binrw::binrw;
|
||||||
|
use crate::ByteSpan;
|
||||||
use crate::gamedata::MemoryBuffer;
|
|
||||||
|
|
||||||
#[binrw]
|
#[binrw]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -59,11 +58,11 @@ pub struct PreBoneDeformMatrices {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PreBoneDeformer {
|
impl PreBoneDeformer {
|
||||||
pub fn from_existing(buffer: &MemoryBuffer) -> Option<PreBoneDeformer> {
|
pub fn from_existing(buffer: ByteSpan) -> Option<PreBoneDeformer> {
|
||||||
let mut cursor = Cursor::new(buffer);
|
let mut cursor = Cursor::new(buffer);
|
||||||
let mut header = PreBoneDeformerHeader::read(&mut cursor).ok()?;
|
let mut header = PreBoneDeformerHeader::read(&mut cursor).ok()?;
|
||||||
|
|
||||||
header.raw_data = buffer.clone();
|
header.raw_data = buffer.to_vec();
|
||||||
|
|
||||||
Some(PreBoneDeformer {
|
Some(PreBoneDeformer {
|
||||||
header
|
header
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
use std::io::{Cursor, Read, Seek, SeekFrom};
|
use std::io::{Cursor, Read, Seek, SeekFrom};
|
||||||
|
|
||||||
use binrw::{BinRead, binread};
|
use binrw::{BinRead, binread};
|
||||||
|
use crate::ByteSpan;
|
||||||
use crate::gamedata::MemoryBuffer;
|
|
||||||
|
|
||||||
#[binread]
|
#[binread]
|
||||||
#[br(little)]
|
#[br(little)]
|
||||||
|
@ -88,7 +87,7 @@ pub struct ShaderPackage {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ShaderPackage {
|
impl ShaderPackage {
|
||||||
pub fn from_existing(buffer: &MemoryBuffer) -> Option<ShaderPackage> {
|
pub fn from_existing(buffer: ByteSpan) -> Option<ShaderPackage> {
|
||||||
let mut cursor = Cursor::new(buffer);
|
let mut cursor = Cursor::new(buffer);
|
||||||
let shpk_header = SHPKHeader::read(&mut cursor).unwrap();
|
let shpk_header = SHPKHeader::read(&mut cursor).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,8 @@ use binrw::{binread, BinRead};
|
||||||
use binrw::helpers::until_eof;
|
use binrw::helpers::until_eof;
|
||||||
use glam::Mat4;
|
use glam::Mat4;
|
||||||
|
|
||||||
use crate::gamedata::MemoryBuffer;
|
|
||||||
use crate::havok::{HavokAnimationContainer, HavokBinaryTagFileReader};
|
use crate::havok::{HavokAnimationContainer, HavokBinaryTagFileReader};
|
||||||
|
use crate::ByteSpan;
|
||||||
|
|
||||||
#[binread]
|
#[binread]
|
||||||
#[br(little)]
|
#[br(little)]
|
||||||
|
@ -69,7 +69,7 @@ pub struct Skeleton {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Skeleton {
|
impl Skeleton {
|
||||||
pub fn from_existing(buffer: &MemoryBuffer) -> Option<Skeleton> {
|
pub fn from_existing(buffer: ByteSpan) -> Option<Skeleton> {
|
||||||
let mut cursor = Cursor::new(buffer);
|
let mut cursor = Cursor::new(buffer);
|
||||||
|
|
||||||
let sklb = SKLB::read(&mut cursor).unwrap();
|
let sklb = SKLB::read(&mut cursor).unwrap();
|
||||||
|
|
|
@ -10,8 +10,7 @@ use binrw::BinRead;
|
||||||
use binrw::binrw;
|
use binrw::binrw;
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
use texpresso::Format;
|
use texpresso::Format;
|
||||||
|
use crate::ByteSpan;
|
||||||
use crate::gamedata::MemoryBuffer;
|
|
||||||
|
|
||||||
// Attributes and Format are adapted from Lumina (https://github.com/NotAdam/Lumina/blob/master/src/Lumina/Data/Files/TexFile.cs)
|
// Attributes and Format are adapted from Lumina (https://github.com/NotAdam/Lumina/blob/master/src/Lumina/Data/Files/TexFile.cs)
|
||||||
bitflags! {
|
bitflags! {
|
||||||
|
@ -77,7 +76,7 @@ pub struct Texture {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Texture {
|
impl Texture {
|
||||||
pub fn from_existing(buffer: &MemoryBuffer) -> Option<Texture> {
|
pub fn from_existing(buffer: ByteSpan) -> Option<Texture> {
|
||||||
let mut cursor = Cursor::new(buffer);
|
let mut cursor = Cursor::new(buffer);
|
||||||
let header = TexHeader::read(&mut cursor).unwrap();
|
let header = TexHeader::read(&mut cursor).unwrap();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue