diff --git a/src/dat.rs b/src/dat.rs index 807db7e..4ae8372 100755 --- a/src/dat.rs +++ b/src/dat.rs @@ -310,18 +310,26 @@ impl DatFile { let texture_file_info = file_info.texture_info.unwrap(); + // write the header if it exists + if texture_file_info.lods[0].compressed_offset != 0 { + let original_pos = self.file.stream_position().unwrap(); + + self.file.seek(SeekFrom::Start(offset + file_info.size as u64)); + let mut header = vec![0u8; texture_file_info.lods[0].compressed_offset as usize]; + self.file.read(&mut header); + data.append(&mut header); + + self.file.seek(SeekFrom::Start(original_pos)); + } + for i in 0..texture_file_info.num_blocks { let mut running_block_total = (texture_file_info.lods[i as usize].compressed_offset as u64) + offset + (file_info.size as u64); - data.append(&mut read_data_block(&self.file, running_block_total).unwrap()); - - for _ in 1..texture_file_info.lods[i as usize].block_count { - running_block_total += i16::read(&mut self.file).unwrap() as u64; + for _ in 0..texture_file_info.lods[i as usize].block_count { data.append(&mut read_data_block(&self.file, running_block_total).unwrap()); + self.file.seek(SeekFrom::Start(running_block_total)); + running_block_total += i16::read(&mut self.file).unwrap() as u64; } - - // dummy? - i16::read(&mut self.file).unwrap(); } Some(data) diff --git a/src/lib.rs b/src/lib.rs index 7b5ddac..10523eb 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,5 +57,8 @@ pub mod skeleton; // Reading file into files (FIIN). pub mod fiin; -// Reading and writing chat logs (LOG) -pub mod log; \ No newline at end of file +// Reading and writing chat logs (LOG). +pub mod log; + +// Reading textures (TEX). +pub mod tex; \ No newline at end of file diff --git a/src/tex.rs b/src/tex.rs new file mode 100644 index 0000000..52d3da7 --- /dev/null +++ b/src/tex.rs @@ -0,0 +1,34 @@ +use std::io::Cursor; +use binrw::binread; +use crate::gamedata::MemoryBuffer; +use binrw::BinRead; + +#[binread] +#[derive(Debug)] +struct TexHeader { + attribute : u32, + format: u32, + + width : u16, + height : u16, + depth : u16, + mip_levels : u16, + + lod_offsets : [u32; 3], + offset_to_surface : [u32; 13] +} + +pub struct Texture { + +} + +impl Texture { + pub fn from_existing(buffer: &MemoryBuffer) -> Option { + let mut cursor = Cursor::new(buffer); + let header = TexHeader::read(&mut cursor).unwrap(); + + println!("{:#?}", header); + + None + } +} \ No newline at end of file