From b20a04c907b141563c8b4320b8c40cd2b487a906 Mon Sep 17 00:00:00 2001 From: spuds <71292624+bananaturtlesandwich@users.noreply.github.com> Date: Sat, 14 Jan 2023 14:41:57 +0000 Subject: [PATCH] fixed offsets so example now has output (with errors)! --- examples/unpack.rs | 5 +++++ src/entry.rs | 9 +++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/unpack.rs b/examples/unpack.rs index 42c2d87..2a7d87b 100644 --- a/examples/unpack.rs +++ b/examples/unpack.rs @@ -5,6 +5,11 @@ fn main() -> Result<(), un_pak::Error> { None, )?; for file in pak.files() { + std::fs::create_dir_all( + std::path::Path::new(&file) + .parent() + .expect("will be a file"), + )?; match pak.get(&file).expect("file should be in pak") { Ok(data) => std::fs::write(&file, data)?, Err(e) => eprintln!("{e}"), diff --git a/src/entry.rs b/src/entry.rs index f53cbaa..623004a 100644 --- a/src/entry.rs +++ b/src/entry.rs @@ -73,6 +73,7 @@ impl Entry { let mut buf = io::BufWriter::new(Vec::with_capacity(self.uncompressed as usize)); reader.seek(io::SeekFrom::Start(self.offset))?; Entry::new(reader, version)?; + let data_offset = reader.stream_position()?; let mut data = reader.read_len(match self.encrypted { // add alignment (aes block size: 16) then zero out alignment bits true => (self.compressed + 15) & !17, @@ -98,11 +99,11 @@ impl Entry { for block in blocks { decoder.write( &data[match version >= Version::RelativeChunkOffsets { - true => { - (block.start - self.offset) as usize - ..(block.end - self.offset) as usize + true => block.start as usize..block.end as usize, + false => { + (block.start - data_offset) as usize + ..(block.end - data_offset) as usize } - false => block.start as usize..block.end as usize, }], )?; }