diff --git a/src/index.rs b/src/index.rs index 2fc1624..3d76b3f 100755 --- a/src/index.rs +++ b/src/index.rs @@ -9,9 +9,8 @@ use std::io::Seek; use std::io::SeekFrom; use std::io::Write; -use crate::common::Platform; -use crate::common::Region; use crate::crc::Jamcrc; +use crate::sqpack::SqPackHeader; use binrw::BinRead; use binrw::BinResult; use binrw::BinWrite; @@ -19,43 +18,6 @@ use binrw::Endian; use binrw::Error; use binrw::binrw; -/// The type of this SqPack file. -#[binrw] -#[brw(repr = u8)] -enum SqPackFileType { - /// FFXIV Explorer says "SQDB", whatever that is. - SQDB = 0x0, - /// Dat files. - Data = 0x1, - /// Index/Index2 files. - Index = 0x2, -} - -#[binrw] -#[brw(magic = b"SqPack\0\0")] -pub struct SqPackHeader { - #[brw(pad_size_to = 4)] - platform_id: Platform, - size: u32, - // Have only seen version 1 - version: u32, - #[brw(pad_size_to = 4)] - file_type: SqPackFileType, - - // some unknown value, zeroed out for index files - // XivAlexandar says date/time, where does that come from? - unk1: u32, - unk2: u32, - - #[br(pad_size_to = 4)] - region: Region, - - #[brw(pad_before = 924)] - #[brw(pad_after = 44)] - // The SHA1 of the bytes immediately before this - sha1_hash: [u8; 20], -} - #[binrw] #[derive(Debug)] pub struct SegementDescriptor { diff --git a/src/sqpack.rs b/src/sqpack.rs index 8c9d04c..f689e4d 100755 --- a/src/sqpack.rs +++ b/src/sqpack.rs @@ -3,11 +3,49 @@ use std::io::{Read, Seek, SeekFrom, Write}; -use binrw::{BinRead, BinWrite}; +use binrw::{binrw, BinRead, BinWrite}; +use crate::common::{Platform, Region}; use crate::compression::no_header_decompress; use crate::dat::{BlockHeader, CompressionMode}; +/// The type of this SqPack file. +#[binrw] +#[brw(repr = u8)] +enum SqPackFileType { + /// FFXIV Explorer says "SQDB", whatever that is. + SQDB = 0x0, + /// Dat files. + Data = 0x1, + /// Index/Index2 files. + Index = 0x2, +} + +#[binrw] +#[brw(magic = b"SqPack\0\0")] +pub struct SqPackHeader { + #[brw(pad_size_to = 4)] + platform_id: Platform, + pub size: u32, + // Have only seen version 1 + version: u32, + #[brw(pad_size_to = 4)] + file_type: SqPackFileType, + + // some unknown value, zeroed out for index files + // XivAlexandar says date/time, where does that come from? + unk1: u32, + unk2: u32, + + #[br(pad_size_to = 4)] + region: Region, + + #[brw(pad_before = 924)] + #[brw(pad_after = 44)] + // The SHA1 of the bytes immediately before this + sha1_hash: [u8; 20], +} + pub fn read_data_block(mut buf: T, starting_position: u64) -> Option> { buf.seek(SeekFrom::Start(starting_position)).ok()?;