mirror of
https://github.com/xavo95/repak.git
synced 2025-01-18 19:04:07 +00:00
Fix Oodle decompression of entries with more than one block
This commit is contained in:
parent
8dcf7f504c
commit
45780637c2
1 changed files with 40 additions and 28 deletions
|
@ -404,7 +404,8 @@ impl Entry {
|
||||||
set_printf(printf);
|
set_printf(printf);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
let func: libloading::Symbol<
|
#[allow(non_snake_case)]
|
||||||
|
let OodleLZ_Decompress: libloading::Symbol<
|
||||||
extern "C" fn(
|
extern "C" fn(
|
||||||
compBuf: *mut u8,
|
compBuf: *mut u8,
|
||||||
compBufSize: usize,
|
compBufSize: usize,
|
||||||
|
@ -417,7 +418,7 @@ impl Entry {
|
||||||
decBufSize: usize,
|
decBufSize: usize,
|
||||||
fpCallback: u64,
|
fpCallback: u64,
|
||||||
callbackUserData: u64,
|
callbackUserData: u64,
|
||||||
decoderMemory: u64,
|
decoderMemory: *mut u8,
|
||||||
decoderMemorySize: usize,
|
decoderMemorySize: usize,
|
||||||
threadPhase: u32,
|
threadPhase: u32,
|
||||||
) -> i32,
|
) -> i32,
|
||||||
|
@ -425,34 +426,45 @@ impl Entry {
|
||||||
|
|
||||||
let mut decompressed = vec![0; self.uncompressed as usize];
|
let mut decompressed = vec![0; self.uncompressed as usize];
|
||||||
|
|
||||||
// merge all blocks into one (assuming no odd bytes) in between
|
let mut compress_offset = 0;
|
||||||
// oodle does not like decompressing blocks individually
|
let mut decompress_offset = 0;
|
||||||
let buffer = &mut data[ranges[0].start..ranges[ranges.len() - 1].end];
|
let block_count = ranges.len();
|
||||||
let out = func(
|
for range in ranges {
|
||||||
buffer.as_mut_ptr(),
|
let decomp = if block_count == 1 {
|
||||||
buffer.len(),
|
self.uncompressed as usize
|
||||||
decompressed.as_mut_ptr(),
|
} else {
|
||||||
decompressed.len(),
|
(self.compression_block_size as usize)
|
||||||
0,
|
.min(self.uncompressed as usize - compress_offset)
|
||||||
0,
|
};
|
||||||
0, //verbose 3
|
let buffer = &mut data[range];
|
||||||
0,
|
let out = OodleLZ_Decompress(
|
||||||
0,
|
buffer.as_mut_ptr(),
|
||||||
0,
|
buffer.len(),
|
||||||
0,
|
decompressed.as_mut_ptr().offset(decompress_offset),
|
||||||
0,
|
decomp,
|
||||||
0,
|
1,
|
||||||
3,
|
1,
|
||||||
);
|
0, //verbose 3
|
||||||
if out == 0 {
|
0,
|
||||||
return Err(super::Error::DecompressionFailed(Compression::Oodle));
|
0,
|
||||||
} else {
|
0,
|
||||||
assert_eq!(
|
0,
|
||||||
out as u64, self.uncompressed,
|
std::ptr::null_mut(),
|
||||||
"Unexpected decompressed bytes"
|
0,
|
||||||
|
3,
|
||||||
);
|
);
|
||||||
buf.write_all(&decompressed)?;
|
if out == 0 {
|
||||||
|
return Err(super::Error::DecompressionFailed(Compression::Oodle));
|
||||||
|
}
|
||||||
|
compress_offset += self.compression_block_size as usize;
|
||||||
|
decompress_offset += out as isize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
decompress_offset, self.uncompressed as isize,
|
||||||
|
"Oodle decompression length mismatch"
|
||||||
|
);
|
||||||
|
buf.write_all(&decompressed)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
|
|
Loading…
Reference in a new issue