From 97fe838b8c665c7147dea1e2db229558ec21319c Mon Sep 17 00:00:00 2001 From: NinjaCheetah <58050615+NinjaCheetah@users.noreply.github.com> Date: Tue, 1 Apr 2025 21:09:54 -0400 Subject: [PATCH] Fix for possible crash when getting info for some TMDs --- src/bin/rustii/info.rs | 11 +++++------ src/bin/rustii/main.rs | 3 +++ src/bin/rustii/title/wad.rs | 24 +++++++++++++++++++++++- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/bin/rustii/info.rs b/src/bin/rustii/info.rs index 247687e..a863258 100644 --- a/src/bin/rustii/info.rs +++ b/src/bin/rustii/info.rs @@ -26,12 +26,11 @@ fn print_tmd_info(tmd: tmd::TMD, cert: Option) { } else { println!(" Title ID: {}", hex::encode(tmd.title_id).to_uppercase()); } - if hex::encode(tmd.title_id)[..8].eq("00000001") { - if hex::encode(tmd.title_id).eq("0000000100000001") { - println!(" Title Version: {} (boot2v{})", tmd.title_version, tmd.title_version); - } else { - println!(" Title Version: {} ({})", tmd.title_version, versions::dec_to_standard(tmd.title_version, &hex::encode(tmd.title_id), Some(tmd.is_vwii != 0)).unwrap()); - } + let converted_ver = versions::dec_to_standard(tmd.title_version, &hex::encode(tmd.title_id), Some(tmd.is_vwii != 0)); + if hex::encode(tmd.title_id).eq("0000000100000001") { + println!(" Title Version: {} (boot2v{})", tmd.title_version, tmd.title_version); + } else if hex::encode(tmd.title_id)[..8].eq("00000001") && converted_ver.is_some() { + println!(" Title Version: {} ({})", tmd.title_version, converted_ver.unwrap()); } else { println!(" Title Version: {}", tmd.title_version); } diff --git a/src/bin/rustii/main.rs b/src/bin/rustii/main.rs index eb7a025..638447b 100644 --- a/src/bin/rustii/main.rs +++ b/src/bin/rustii/main.rs @@ -46,6 +46,9 @@ fn main() { match &cli.command { Some(Commands::Wad { command }) => { match command { + Some(wad::Commands::Convert { input, output }) => { + wad::convert_wad(input, output) + }, Some(wad::Commands::Pack { input, output}) => { wad::pack_wad(input, output) }, diff --git a/src/bin/rustii/title/wad.rs b/src/bin/rustii/title/wad.rs index bd72819..6675d75 100644 --- a/src/bin/rustii/title/wad.rs +++ b/src/bin/rustii/title/wad.rs @@ -5,7 +5,7 @@ use std::{str, fs}; use std::path::{Path, PathBuf}; -use clap::Subcommand; +use clap::{Subcommand, Args}; use glob::glob; use rustii::title::{cert, tmd, ticket, content, wad}; use rustii::title; @@ -13,18 +13,40 @@ use rustii::title; #[derive(Subcommand)] #[command(arg_required_else_help = true)] pub enum Commands { + /// Re-encrypt a WAD file with a different key + Convert { + /// The path to the WAD to convert + input: String, + /// An (optional) WAD name; defaults to _.wad + #[arg(short, long)] + output: Option, + }, /// Pack a directory into a WAD file Pack { + /// The directory to pack into a WAD input: String, + /// The name of the packed WAD file output: String }, /// Unpack a WAD file into a directory Unpack { + /// The path to the WAD to unpack input: String, + /// The directory to extract the WAD to output: String } } +#[derive(Args)] +#[group(multiple = false, required = true)] +struct ConvertTargets { + +} + +pub fn convert_wad(input: &str, output: &Option) { + todo!(); +} + pub fn pack_wad(input: &str, output: &str) { let in_path = Path::new(input); if !in_path.exists() {