Begin loading ROM data for randomization.

Use the fact that the default path for the asar symbols file is just the
ROM's file with a ".sym" extension. When enemize runs, it checks if this
file exists, and if it doesn't, runs asar on the ROM to create the
symbols file.
This commit is contained in:
Lyle Mantooth 2022-05-31 22:48:45 -04:00
parent f6eb37b6fe
commit 568360206d
Signed by: IslandUsurper
GPG key ID: 6DB52EAE123A5789
4 changed files with 112 additions and 10 deletions

View file

@ -8,6 +8,7 @@ edition = "2021"
[dependencies]
anyhow = "1"
clap = { version = "3.1.18", features = ["derive"] }
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1"

View file

@ -1,7 +1,13 @@
use std::path::PathBuf;
use std::fs::File;
use std::io::prelude::*;
use std::path::{Path, PathBuf};
use std::time::Instant;
use anyhow::ensure;
use clap::Parser;
use enemize::{asar, rom::RomData};
/// Randomizes enemy placements in The Legend of Zelda: A Link to the Past for the Super Nintendo
/// Entertainment System
#[derive(Debug, Parser)]
@ -12,12 +18,6 @@ struct Args {
/// seed number
#[clap(short, long)]
seed: Option<u32>,
/// path to the base2patched.json (not used in binary mode)
#[clap(short, long, required_unless_present = "binary")]
base: Option<PathBuf>,
/// path to the randomizerPatch.json (not used in binary mode)
#[clap(short, long, required_unless_present = "binary")]
randomizer: Option<PathBuf>,
/// path to the enemizerOptions.json
#[clap(short, long)]
enemizer: PathBuf,
@ -28,6 +28,53 @@ struct Args {
binary: bool,
}
fn main() {
fn main() -> anyhow::Result<()> {
let args = Args::parse();
let stopwatch = Instant::now();
let options = serde_json::from_reader(File::open(args.enemizer)?)?;
let symbols = load_symbols(&args.rom)?;
let mut raw_data = vec![];
let mut rom_file = File::open(args.rom)?;
rom_file.read_to_end(&mut raw_data)?;
raw_data.resize(2 * 1024 * 1024, 0);
let mut rom_data = RomData::new(symbols, raw_data);
ensure!(!rom_data.is_enemizer(), "It appears that the provided base ROM is already enemized. Please ensure you are using an original game ROM.");
let seed = args.seed.unwrap_or_else(|| rand::random());
//let randomized_rom = randomize_rom(seed, raw_data, options);
if args.binary {
} else {
}
println!("Seed generated in: {}ms", stopwatch.elapsed().as_millis());
Ok(())
}
fn load_symbols(rom: &Path) -> anyhow::Result<asar::Symbols> {
let sym_path = rom.with_extension("sym");
if let Err(_) = std::fs::metadata(&sym_path) {
let status = std::process::Command::new("asar")
.arg("--no-title-check")
.arg("--fix-checksum=off")
.arg("--symbols=wla")
.arg("-Iassembly/src")
.arg("assembly/src/main.asm")
.arg(rom)
.status()?;
ensure!(status.success(), "could not generate symbols");
}
asar::load_symbols(sym_path.as_path())
}