Skip to content

Commit

Permalink
Classify Pre-BL files
Browse files Browse the repository at this point in the history
  • Loading branch information
cohaereo committed Jul 20, 2023
1 parent 1b59e9a commit 90d6001
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ directory where you run destinypkgtool from.
| Version | Platform | Works? |
|---------------------------------|----------|--------|
| Destiny Legacy (The Taken King) | PS3/X360 ||
| Destiny Legacy (The Taken King) | PS4/XONE | |
| Destiny Legacy (The Taken King) | PS4/XONE | |
| Destiny (Rise of Iron) | PS4/XONE ||
| Destiny 2 (Pre-BL) | PC ||
| Destiny 2 (Beyond Light) | PC ||
Expand Down
9 changes: 8 additions & 1 deletion src/bin/unpack.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use clap::Parser;
use destiny_pkg::package::classify_file;
use destiny_pkg::{PackageVersion, TagHash};
use std::fs::File;
use std::io::Write;
Expand Down Expand Up @@ -69,8 +70,14 @@ fn main() -> anyhow::Result<()> {
}
};

let ext = if args.version == PackageVersion::Destiny2PreBeyondLight {
classify_file(e.file_type, e.file_subtype)
} else {
"bin".to_string()
};

let mut o = File::create(format!(
"{out_dir}/{i}_{:08x}_t{}_s{}.bin",
"{out_dir}/{i}_{:08x}_t{}_s{}.{ext}",
e.reference, e.file_type, e.file_subtype
))?;
o.write_all(&data)?;
Expand Down
9 changes: 8 additions & 1 deletion src/bin/unpack_refs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use clap::Parser;
use clap_num::maybe_hex;
use destiny_pkg::package::classify_file;
use destiny_pkg::{PackageManager, PackageVersion, TagHash};
use std::fs::File;
use std::io::Write;
Expand Down Expand Up @@ -71,8 +72,14 @@ fn main() -> anyhow::Result<()> {
}
};

let ext = if args.version == PackageVersion::Destiny2PreBeyondLight {
classify_file(e.file_type, e.file_subtype)
} else {
"bin".to_string()
};

let mut o = File::create(format!(
"{out_dir}/{i}_{:08x}_t{}_s{}.bin",
"{out_dir}/{i}_{:08x}_t{}_s{}.{ext}",
e.reference, e.file_type, e.file_subtype
))?;
o.write_all(&data)?;
Expand Down
37 changes: 36 additions & 1 deletion src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct UHashTableEntry {
pub reference: TagHash,
}

#[derive(clap::ValueEnum, PartialEq, Debug, Clone)]
#[derive(clap::ValueEnum, PartialEq, Debug, Clone, Copy)]
pub enum PackageVersion {
/// PS3/X360 version of Destiny (The Taken King)
#[value(name = "d1_legacy")]
Expand Down Expand Up @@ -150,3 +150,38 @@ pub trait Package {
.collect()
}
}

/// ! Currently only works for Pre-BL Destiny 2
pub fn classify_file(ftype: u8, fsubtype: u8) -> String {
match (ftype, fsubtype) {
// WWise audio bank
(26, 5) => "bnk".to_string(),
// WWise audio stream
(26, 6) => "wem".to_string(),
// Havok data
(26, 7) => "hkf".to_string(),
// CriWare USM video
(27, _) => "usm".to_string(),
(32, 1) => "texture.header".to_string(),
(32, 2) => "texture_cube.header".to_string(),
(32, 4) => "vertex.header".to_string(),
(32, 6) => "index.header".to_string(),
(40, 4) => "vertex.data".to_string(),
(40, 6) => "index.data".to_string(),
(48, 1) => "texture.data".to_string(),
(48, 2) => "texture_cube.data".to_string(),
// DXBC data
(41, shader_type) => {
let ty = match shader_type {
0 => "fragment".to_string(),
1 => "vertex".to_string(),
6 => "compute".to_string(),
u => format!("unk{u}"),
};

format!("cso.{ty}")
}
(8, _) => "8080".to_string(),
_ => "bin".to_string(),
}
}

0 comments on commit 90d6001

Please sign in to comment.