mirror of
https://github.com/xavo95/repak.git
synced 2025-01-18 19:04:07 +00:00
trying to figure out why it's not parsing
This commit is contained in:
parent
5104b41878
commit
38ed23a5bc
5 changed files with 29 additions and 22 deletions
|
@ -1,6 +1,9 @@
|
||||||
fn main() -> Result<(), un_pak::Error> {
|
fn main() -> Result<(), un_pak::Error> {
|
||||||
for version in un_pak::Version::iter().rev() {
|
for version in un_pak::Version::iter().rev() {
|
||||||
match un_pak::Pak::new(version, std::io::Cursor::new(include_bytes!("rando_p.pak"))) {
|
match un_pak::Pak::new(
|
||||||
|
version,
|
||||||
|
std::io::BufReader::new(std::io::Cursor::new(include_bytes!("rando_p.pak"))),
|
||||||
|
) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
println!("parsed successfully!");
|
println!("parsed successfully!");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|
12
src/error.rs
12
src/error.rs
|
@ -1,16 +1,18 @@
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("expected magic of {} but found {0}", super::MAGIC)]
|
#[error("expected magic of {} but got {0}", super::MAGIC)]
|
||||||
MagicMismatch(u32),
|
MagicMismatch(u32),
|
||||||
#[error("parsed with {0} but pak was {0}")]
|
#[error("parsed with {0} but pak was {0}")]
|
||||||
VersionMismatch(super::Version, super::Version),
|
VersionMismatch(super::Version, super::Version),
|
||||||
#[error("error reading file: {0}")]
|
#[error("expected 1 or 0 but got {0}")]
|
||||||
|
BoolConversion(u8),
|
||||||
|
#[error("reading file: {0}")]
|
||||||
IoError(#[from] std::io::Error),
|
IoError(#[from] std::io::Error),
|
||||||
#[error("error converting enum: {0}")]
|
#[error("converting to enum: {0}")]
|
||||||
StrumError(#[from] strum::ParseError),
|
StrumError(#[from] strum::ParseError),
|
||||||
#[error("error converting to utf8: {0}")]
|
#[error("converting to utf8: {0}")]
|
||||||
Utf8Error(#[from] std::string::FromUtf8Error),
|
Utf8Error(#[from] std::string::FromUtf8Error),
|
||||||
#[error("error converting to utf16: {0}")]
|
#[error("converting to utf16: {0}")]
|
||||||
Utf16Error(#[from] std::string::FromUtf16Error),
|
Utf16Error(#[from] std::string::FromUtf16Error),
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
Other(String),
|
Other(String),
|
||||||
|
|
|
@ -15,7 +15,11 @@ pub trait ReadExt {
|
||||||
|
|
||||||
impl<R: std::io::Read> ReadExt for R {
|
impl<R: std::io::Read> ReadExt for R {
|
||||||
fn read_bool(&mut self) -> Result<bool, super::Error> {
|
fn read_bool(&mut self) -> Result<bool, super::Error> {
|
||||||
Ok(self.read_u8()? != 0)
|
match self.read_u8()? {
|
||||||
|
1 => Ok(true),
|
||||||
|
0 => Ok(false),
|
||||||
|
err => Err(super::Error::BoolConversion(err)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_guid(&mut self) -> Result<[u8; 20], super::Error> {
|
fn read_guid(&mut self) -> Result<[u8; 20], super::Error> {
|
||||||
|
|
|
@ -30,10 +30,9 @@ impl Footer {
|
||||||
frozen: (version == &Version::FrozenIndex).then_some(reader.read_bool()?),
|
frozen: (version == &Version::FrozenIndex).then_some(reader.read_bool()?),
|
||||||
compression: (version >= &Version::FNameBasedCompression).then_some({
|
compression: (version >= &Version::FNameBasedCompression).then_some({
|
||||||
let mut compression =
|
let mut compression =
|
||||||
Vec::with_capacity(if version == &Version::FNameBasedCompression {
|
Vec::with_capacity(match version == &Version::FNameBasedCompression {
|
||||||
4
|
true => 4,
|
||||||
} else {
|
false => 5,
|
||||||
5
|
|
||||||
});
|
});
|
||||||
for _ in 0..compression.capacity() {
|
for _ in 0..compression.capacity() {
|
||||||
compression.push(
|
compression.push(
|
||||||
|
|
21
src/pak.rs
21
src/pak.rs
|
@ -13,8 +13,7 @@ impl Pak {
|
||||||
version: super::Version,
|
version: super::Version,
|
||||||
mut reader: R,
|
mut reader: R,
|
||||||
) -> Result<Self, super::Error> {
|
) -> Result<Self, super::Error> {
|
||||||
reader.seek(io::SeekFrom::End(-(footer_size(&version) as i64)))?;
|
reader.seek(io::SeekFrom::End(-footer_size(&version)))?;
|
||||||
// parse footer info to get index offset
|
|
||||||
let footer = super::Footer::new(&mut reader, &version)?;
|
let footer = super::Footer::new(&mut reader, &version)?;
|
||||||
reader.seek(io::SeekFrom::Start(footer.offset))?;
|
reader.seek(io::SeekFrom::Start(footer.offset))?;
|
||||||
let index = super::Index::new(&mut reader, &version)?;
|
let index = super::Index::new(&mut reader, &version)?;
|
||||||
|
@ -26,16 +25,20 @@ impl Pak {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn footer_size(version: &Version) -> u32 {
|
fn footer_size(version: &Version) -> i64 {
|
||||||
// (magic + version): u32 + (offset + size): u64 + hash: [u8; 20]
|
// (magic + version): u32 + (offset + size): u64 + hash: [u8; 20]
|
||||||
let mut size = 4 * 2 + 8 * 2 + 20;
|
let mut size = 4 + 4 + 8 + 8 + 20;
|
||||||
|
if version >= &Version::EncryptionKeyGuid {
|
||||||
|
// encryption guid: [u8; 20]
|
||||||
|
size += 20;
|
||||||
|
}
|
||||||
if version >= &Version::IndexEncryption {
|
if version >= &Version::IndexEncryption {
|
||||||
// encrypted: bool
|
// encrypted: bool
|
||||||
size += 1;
|
size += 1;
|
||||||
}
|
}
|
||||||
if version >= &Version::EncryptionKeyGuid {
|
if version == &Version::FrozenIndex {
|
||||||
// encryption guid: [u8; 20]
|
// frozen index: bool
|
||||||
size += 10;
|
size += 1;
|
||||||
}
|
}
|
||||||
if version >= &Version::FNameBasedCompression {
|
if version >= &Version::FNameBasedCompression {
|
||||||
// compression names: [[u8; 32]; 4]
|
// compression names: [[u8; 32]; 4]
|
||||||
|
@ -45,9 +48,5 @@ fn footer_size(version: &Version) -> u32 {
|
||||||
// extra compression name: [u8; 32]
|
// extra compression name: [u8; 32]
|
||||||
size += 32
|
size += 32
|
||||||
}
|
}
|
||||||
if version == &Version::FrozenIndex {
|
|
||||||
// frozen index: bool
|
|
||||||
size += 1;
|
|
||||||
}
|
|
||||||
size
|
size
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue