fixed offsets so example now has output (with errors)!

This commit is contained in:
spuds 2023-01-14 14:41:57 +00:00
parent 97469c58ae
commit b20a04c907
2 changed files with 10 additions and 4 deletions

View file

@ -5,6 +5,11 @@ fn main() -> Result<(), un_pak::Error> {
None, None,
)?; )?;
for file in pak.files() { 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") { match pak.get(&file).expect("file should be in pak") {
Ok(data) => std::fs::write(&file, data)?, Ok(data) => std::fs::write(&file, data)?,
Err(e) => eprintln!("{e}"), Err(e) => eprintln!("{e}"),

View file

@ -73,6 +73,7 @@ impl Entry {
let mut buf = io::BufWriter::new(Vec::with_capacity(self.uncompressed as usize)); let mut buf = io::BufWriter::new(Vec::with_capacity(self.uncompressed as usize));
reader.seek(io::SeekFrom::Start(self.offset))?; reader.seek(io::SeekFrom::Start(self.offset))?;
Entry::new(reader, version)?; Entry::new(reader, version)?;
let data_offset = reader.stream_position()?;
let mut data = reader.read_len(match self.encrypted { let mut data = reader.read_len(match self.encrypted {
// add alignment (aes block size: 16) then zero out alignment bits // add alignment (aes block size: 16) then zero out alignment bits
true => (self.compressed + 15) & !17, true => (self.compressed + 15) & !17,
@ -98,11 +99,11 @@ impl Entry {
for block in blocks { for block in blocks {
decoder.write( decoder.write(
&data[match version >= Version::RelativeChunkOffsets { &data[match version >= Version::RelativeChunkOffsets {
true => { true => block.start as usize..block.end as usize,
(block.start - self.offset) as usize false => {
..(block.end - self.offset) as usize (block.start - data_offset) as usize
..(block.end - data_offset) as usize
} }
false => block.start as usize..block.end as usize,
}], }],
)?; )?;
} }