From 90d600134bcade217f3085246e33ab870598bc1e Mon Sep 17 00:00:00 2001 From: cohaereo Date: Thu, 20 Jul 2023 22:12:34 +0200 Subject: [PATCH] Classify Pre-BL files --- README.md | 2 +- src/bin/unpack.rs | 9 ++++++++- src/bin/unpack_refs.rs | 9 ++++++++- src/package.rs | 37 ++++++++++++++++++++++++++++++++++++- 4 files changed, 53 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1a75d0b..a39b564 100644 --- a/README.md +++ b/README.md @@ -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 | ❌ | diff --git a/src/bin/unpack.rs b/src/bin/unpack.rs index c5552ad..9bd332e 100644 --- a/src/bin/unpack.rs +++ b/src/bin/unpack.rs @@ -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; @@ -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)?; diff --git a/src/bin/unpack_refs.rs b/src/bin/unpack_refs.rs index 52c062f..91294f1 100644 --- a/src/bin/unpack_refs.rs +++ b/src/bin/unpack_refs.rs @@ -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; @@ -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)?; diff --git a/src/package.rs b/src/package.rs index 6e7a6d7..effd97e 100644 --- a/src/package.rs +++ b/src/package.rs @@ -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")] @@ -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(), + } +}