Skip to content

Commit

Permalink
use a built-in database for game titles
Browse files Browse the repository at this point in the history
  • Loading branch information
iliazeus committed Jul 15, 2024
1 parent 149bcf6 commit 94269b8
Show file tree
Hide file tree
Showing 9 changed files with 2,884 additions and 79 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "iso2god"
version = "1.4.8"
version = "1.5.0"
description = "A tool to convert between Xbox 360 ISO and Games On Demand file formats"
repository = "https://github.com/iliazeus/iso2god-rs"
edition = "2021"
Expand All @@ -15,11 +15,13 @@ clap = { version = "4.5.9", features = ["derive"] }
hex = "0.4.3"
num = "0.4.3"
num_enum = "0.7.2"
sha1 = "0.10.6"

[dev-dependencies]
reqwest = { version = "0.12.5", features = ["blocking", "json"] }
serde = { version = "1.0.204", features = ["derive"] }
serde-aux = "4.5.0"
serde_json = "1.0.120"
sha1 = "0.10.6"

[profile.release]
strip = true
Expand Down
63 changes: 63 additions & 0 deletions examples/game_title/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use anyhow::{Context, Error};
use clap::{command, Parser};
use hex;

use iso2god::game_list;

mod unity;

#[derive(Clone, clap::ValueEnum)]
enum Source {
BuiltIn,
Unity,
}

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
#[command(color = clap::ColorChoice::Never)]
struct Cli {
#[arg(value_enum)]
source: Source,

title_id: String,
}

fn main() -> Result<(), Error> {
let args = Cli::parse();

let title_id: [u8; 4] = hex::decode(&args.title_id)?
.try_into()
.map_err(|_| Error::msg("invalid title ID"))?;

match args.source {
Source::BuiltIn => {
println!("querying the built-in DB for title ID {}", args.title_id);

if let Some(name) = game_list::find_title_by_id(title_id) {
let title_id = hex::encode_upper(title_id);
println!("Title ID: {title_id}");
println!(" Name: {name}");
} else {
println!("title not found in built-in database");
}
}

Source::Unity => {
println!("querying XboxUnity for title ID {}", args.title_id);

let client = unity::Client::new().context("error creating XboxUnity client")?;

let unity_title_info = client
.find_xbox_360_title_id(&title_id)
.context("error querying XboxUnity")?;

if let Some(unity_title_info) = &unity_title_info {
println!("{unity_title_info}");
} else {
println!("no XboxUnity title info available");
}
}
}

Ok(())
}
5 changes: 4 additions & 1 deletion src/unity.rs → examples/game_title/unity.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(dead_code)]

use reqwest::blocking as http;
use serde::Deserialize;
use serde_aux::prelude::*;
Expand Down Expand Up @@ -71,6 +73,7 @@ pub enum TitleType {
Xbla,

Xbox1,
HomeBrew,
}

impl fmt::Display for TitleType {
Expand All @@ -80,6 +83,7 @@ impl fmt::Display for TitleType {
Self::Xbox360 => write!(f, "Xbox 360 title"),
Self::Xbla => write!(f, "Xbox Live Arcade title"),
Self::Xbox1 => write!(f, "Xbox One title"),
Self::HomeBrew => write!(f, "Homebrew title"),
}
}
}
Expand Down Expand Up @@ -136,7 +140,6 @@ impl Client {
.items
.into_iter()
.filter(|t| t.title_id == title_id)
.filter(|t| t.title_type == TitleType::Xbox360 || t.title_type == TitleType::Xbla)
.min_by_key(|t| match t.title_type {
TitleType::Xbox360 => 0,
TitleType::Xbla => 1,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/debug_list_files.rs → examples/list_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use iso2god::iso;
#[command(author, version, about, long_about = None)]
#[command(color = clap::ColorChoice::Never)]
struct Cli {
/// Xbox 360 ISO file to convert
/// Xbox 360 ISO file
source_iso: PathBuf,
}

Expand Down
38 changes: 0 additions & 38 deletions src/bin/debug_unity.rs

This file was deleted.

55 changes: 20 additions & 35 deletions src/bin/iso2god.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ use std::path::{Path, PathBuf};

use num::integer::div_ceil;

use anyhow::{bail, Context, Error};
use anyhow::{Context, Error};

use clap::{arg, command, Parser};

use hex;

use iso2god::{god, iso, unity, xex};
use iso2god::{game_list, god, iso, xex};

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
Expand All @@ -24,11 +22,11 @@ struct Cli {
/// A folder to write resulting GOD files to
dest_dir: PathBuf,

/// Do not query XboxUnity for title info
#[arg(long)]
#[arg(long, hide = true)]
#[deprecated(since = "1.5.0", note = "now uses a built-in database")]
offline: bool,

/// Do not convert anything, just query the title info
/// Do not convert anything, just print the title info
#[arg(long)]
dry_run: bool,

Expand All @@ -40,6 +38,11 @@ struct Cli {
fn main() -> Result<(), Error> {
let args = Cli::parse();

#[allow(deprecated)]
if args.offline {
eprintln!("the --offline flag is deprecated: the tool now has a built-in title database, so it is always offline");
}

println!("extracting ISO metadata");

let source_iso_file = open_file_for_buffered_reading(&args.source_iso)
Expand All @@ -64,33 +67,14 @@ fn main() -> Result<(), Error> {
.execution_info
.context("no execution info in default.xex header")?;

let unity_title_info = if args.offline {
None
} else {
println!(
"querying XboxUnity for title ID {}",
hex::encode_upper(exe_info.title_id)
);

let client = unity::Client::new().context("error creating XboxUnity client")?;
if args.dry_run {
let title_id = hex::encode_upper(exe_info.title_id);
let name = game_list::find_title_by_id(exe_info.title_id).unwrap_or("(unknown)".to_owned());

client
.find_xbox_360_title_id(&exe_info.title_id)
.context("error querying XboxUnity; try --offline flag")?
};
println!("Title ID: {title_id}");
println!(" Name: {name}");

if let Some(unity_title_info) = &unity_title_info {
println!("\n{}\n", unity_title_info);

if args.dry_run {
return Ok(());
}
} else {
if args.dry_run {
bail!("no XboxUnity title info available");
} else {
println!("no XboxUnity title info available");
}
return Ok(());
}

// TODO: cropping
Expand Down Expand Up @@ -158,9 +142,10 @@ fn main() -> Result<(), Error> {
.with_content_type(god::ContentType::GamesOnDemand)
.with_mht_hash(&mht.digest());

if let Some(unity_title_info) = &unity_title_info {
con_header = con_header.with_game_title(&unity_title_info.name);
} else if let Some(game_title) = args.game_title {
let game_title = args
.game_title
.or(game_list::find_title_by_id(exe_info.title_id));
if let Some(game_title) = game_title {
con_header = con_header.with_game_title(&game_title);
}

Expand Down
Loading

0 comments on commit 94269b8

Please sign in to comment.