Skip to content

Commit

Permalink
Small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
cohaereo committed Jul 13, 2023
1 parent a0a1499 commit 760b4fb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
14 changes: 10 additions & 4 deletions src/bin/unpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,27 @@ fn main() -> anyhow::Result<()> {
let package = Package::open(&std::env::args().nth(1).unwrap())?;
std::fs::create_dir("./files/").ok();

println!(
"PKG {:04x}_{}",
package.header.pkg_id, package.header.patch_id
);
for (i, e) in package.entries().enumerate() {
print!("{}/{} - ", e.file_type, e.file_subtype);
if e.reference != u32::MAX {
print!(
"{i} 0x{:x} - p={:x} f={} ",
"{i} 0x{:x} - p={:x} f={} / r=0x{:x} ",
e.file_size,
(e.reference >> 13) & 0x3ff,
e.reference & 0x1fff
(e.reference & !0x80800000) >> 13,
e.reference & 0x1fff,
e.reference
);
} else {
print!("{i} 0x{:x} - ", e.file_size);
}
let ext = match (e.file_type, e.file_subtype) {
(26, 6) => {
println!("WWise WAVE Audio");
"wav".to_string()
"wem".to_string()
}
(26, 7) => {
println!("Havok File");
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ mod crypto;
mod oodle;
pub mod package;
pub mod structs;

pub use package::Package;
4 changes: 2 additions & 2 deletions src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<R: Read + Seek> ReadSeek for R {}
pub struct Package {
gcm: RefCell<PkgGcmState>,

header: PackageHeader,
pub header: PackageHeader,
entries: Vec<EntryHeader>,
blocks: Vec<BlockHeader>,

Expand Down Expand Up @@ -147,7 +147,7 @@ impl Package {
let block_data = self.get_block(current_block as usize)?;

if current_block == entry.starting_block {
let block_start_offset = (entry.starting_block_offset * 16) as usize;
let block_start_offset = entry.starting_block_offset as usize;
let block_remaining = block_data.len() - block_start_offset;
let copy_size = if block_remaining < remaining_bytes {
block_remaining
Expand Down
2 changes: 1 addition & 1 deletion src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub struct EntryHeader {
#[br(calc = _block_info as u32 & 0x3fff)]
pub starting_block: u32,

#[br(calc = (_block_info >> 14) as u32 & 0x3FFF)]
#[br(calc = ((_block_info >> 14) as u32 & 0x3FFF) << 4)]
pub starting_block_offset: u32,

#[br(calc = (_block_info >> 28) as u32)]
Expand Down

0 comments on commit 760b4fb

Please sign in to comment.