From 9cb0e0b2bf4dc50ae805ebf513ffac01610c9a22 Mon Sep 17 00:00:00 2001 From: Lyle Mantooth Date: Thu, 2 Jun 2022 11:55:41 -0400 Subject: [PATCH] WIP --- enemize/Cargo.toml | 2 +- enemize/src/constants.rs | 102 +++++++++++++++++++++++++++++++++++++++ enemize/src/lib.rs | 1 + enemize/src/main.rs | 6 ++- enemize/src/randomize.rs | 30 ++++++++++++ enemize/src/rom.rs | 38 ++++++++++++++- 6 files changed, 174 insertions(+), 5 deletions(-) create mode 100644 enemize/src/randomize.rs diff --git a/enemize/Cargo.toml b/enemize/Cargo.toml index a763a91..f377aae 100644 --- a/enemize/Cargo.toml +++ b/enemize/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" [dependencies] anyhow = "1" clap = { version = "3.1.18", features = ["derive"] } -rand = "0.8" +rand_chacha = "0.3" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1" diff --git a/enemize/src/constants.rs b/enemize/src/constants.rs index 630ff5b..4cd503c 100644 --- a/enemize/src/constants.rs +++ b/enemize/src/constants.rs @@ -10,3 +10,105 @@ pub const NEW_BOSS_GRAPHICS: usize = 0x1B0000; pub const RANDOM_SPRITE_GRAPHICS: usize = 0x300000; pub const ENEMIZER_FILE_LENGTH: usize = 0x200000; pub const HIDDEN_ENEMY_CHANCE_POOL: usize = 0xD7BBB; + +pub(crate) const ORIGINAL_ROOM_POINTERS: [u8; 640] = [ 0x62, 0xF4, 0x6C, 0xF4, 0x7A, 0xF4, 0xDD, 0xF5, 0x85, + 0xF4, 0x90, 0xF4, 0x90, 0xF4, 0x97, 0xF4, 0xA2, 0xF4, 0xA9, 0xF4, 0xB5, 0xF4, 0xC0, 0xF4, + 0xCB, 0xF4, 0xD8, 0xF4, 0xDF, 0xF4, 0xEA, 0xF4, 0xEA, 0xF4, 0xF1, 0xF4, 0xFC, 0xF4, 0x03, + 0xF5, 0x11, 0xF5, 0x18, 0xF5, 0x23, 0xF5, 0x2E, 0xF5, 0x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 0xAC, 0xFC, 0xB3, 0xFC, 0xBA, 0xFC, 0x5E, + 0xFC, 0x5E, 0xFC, 0xC1, 0xFC, 0xC8, 0xFC, 0xC8, 0xFC, 0xC8, 0xFC, 0xAC, 0xFC, 0xCF, 0xFC, + 0xCF, 0xFC, 0xCF, 0xFC, 0xCF, 0xFC, 0xCF, 0xFC, 0xCF, 0xFC, 0xCF, 0xFC, 0xCF, 0xFC, 0xCF, + 0xFC, 0xCF, 0xFC, 0xCF, 0xFC, 0xCF, 0xFC, 0xCF, 0xFC, 0xCF, 0xFC, 0xCF, 0xFC, 0xCF, 0xFC, + 0xCF, 0xFC, 0xCF, 0xFC, 0xCF, 0xFC, 0xCF, 0xFC, 0xCF, 0xFC, 0xCF, 0xFC, 0xCF, 0xFC, 0xCF, + 0xFC]; + +pub(crate) const ORIGINAL_ROOM_BLOCKS: [u8; 576] = [ 0x00, 0x49, 0x00, 0x00, 0x46, 0x49, 0x0C, 0x1D, +0x48, 0x49, 0x13, 0x1D, 0x46, 0x49, 0x13, 0x0E, 0x48, 0x49, 0x0C, 0x11, 0x48, 0x49, 0x0C, 0x10, +0x4F, 0x49, 0x4A, 0x50, 0x0E, 0x49, 0x4A, 0x11, 0x46, 0x49, 0x12, 0x00, 0x00, 0x49, 0x00, 0x50, +0x00, 0x49, 0x00, 0x11, 0x48, 0x49, 0x0C, 0x00, 0x00, 0x00, 0x37, 0x36, 0x48, 0x49, 0x4C, 0x11, +0x5D, 0x2C, 0x0C, 0x44, 0x00, 0x00, 0x4E, 0x00, 0x0F, 0x00, 0x12, 0x10, 0x00, 0x00, 0x00, 0x4C, +0x00, 0x0D, 0x17, 0x00, 0x16, 0x0D, 0x17, 0x1B, 0x16, 0x0D, 0x17, 0x14, 0x15, 0x0D, 0x17, 0x15, +0x16, 0x0D, 0x18, 0x19, 0x16, 0x0D, 0x17, 0x19, 0x16, 0x0D, 0x00, 0x00, 0x16, 0x0D, 0x18, 0x1B, +0x0F, 0x49, 0x4A, 0x11, 0x4B, 0x2A, 0x5C, 0x15, 0x16, 0x49, 0x17, 0x1D, 0x00, 0x00, 0x00, 0x15, +0x16, 0x0D, 0x17, 0x10, 0x16, 0x49, 0x12, 0x00, 0x16, 0x49, 0x0C, 0x11, 0x00, 0x00, 0x12, 0x10, +0x16, 0x0D, 0x00, 0x11, 0x16, 0x49, 0x0C, 0x00, 0x16, 0x0D, 0x4C, 0x11, 0x0E, 0x0D, 0x4A, 0x11, +0x16, 0x1A, 0x17, 0x1B, 0x4F, 0x34, 0x4A, 0x50, 0x35, 0x4D, 0x65, 0x36, 0x4A, 0x34, 0x4E, 0x00, +0x0E, 0x34, 0x4A, 0x11, 0x51, 0x34, 0x5D, 0x59, 0x4B, 0x49, 0x4C, 0x11, 0x2D, 0x00, 0x00, 0x00, +0x5D, 0x00, 0x12, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x49, 0x2B, 0x2D, 0x46, 0x49, 0x1C, 0x52, +0x00, 0x49, 0x1C, 0x52, 0x5D, 0x49, 0x00, 0x52, 0x46, 0x49, 0x13, 0x52, 0x4B, 0x4D, 0x4A, 0x5A, +0x47, 0x49, 0x1C, 0x52, 0x4B, 0x4D, 0x39, 0x36, 0x1F, 0x2C, 0x2E, 0x52, 0x1F, 0x2C, 0x2E, 0x1D, +0x2F, 0x2C, 0x2E, 0x52, 0x2F, 0x2C, 0x2E, 0x31, 0x1F, 0x1E, 0x30, 0x52, 0x51, 0x49, 0x13, 0x00, +0x4F, 0x49, 0x13, 0x50, 0x4F, 0x4D, 0x4A, 0x50, 0x4B, 0x49, 0x4C, 0x2B, 0x1F, 0x20, 0x22, 0x53, +0x55, 0x3D, 0x42, 0x43, 0x1F, 0x1E, 0x23, 0x52, 0x1F, 0x1E, 0x39, 0x3A, 0x1F, 0x1E, 0x3A, 0x3E, +0x1F, 0x1E, 0x3C, 0x3D, 0x40, 0x1E, 0x27, 0x3F, 0x55, 0x1A, 0x42, 0x43, 0x1F, 0x1E, 0x2A, 0x52, +0x1F, 0x1E, 0x38, 0x52, 0x1F, 0x20, 0x28, 0x52, 0x1F, 0x20, 0x26, 0x52, 0x1F, 0x2C, 0x25, 0x52, +0x1F, 0x20, 0x27, 0x52, 0x1F, 0x1E, 0x29, 0x52, 0x1F, 0x2C, 0x3B, 0x52, 0x46, 0x49, 0x24, 0x52, +0x21, 0x41, 0x45, 0x33, 0x1F, 0x2C, 0x28, 0x31, 0x1F, 0x0D, 0x29, 0x52, 0x1F, 0x1E, 0x27, 0x52, +0x1F, 0x20, 0x27, 0x53, 0x48, 0x49, 0x13, 0x52, 0x0E, 0x1E, 0x4A, 0x50, 0x1F, 0x20, 0x26, 0x53, +0x15, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x2A, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, +0x5D, 0x49, 0x00, 0x52, 0x55, 0x49, 0x42, 0x43, 0x61, 0x62, 0x63, 0x50, 0x61, 0x62, 0x63, 0x50, +0x61, 0x62, 0x63, 0x50, 0x61, 0x62, 0x63, 0x50, 0x61, 0x62, 0x63, 0x50, 0x61, 0x62, 0x63, 0x50, +0x61, 0x56, 0x57, 0x50, 0x61, 0x62, 0x63, 0x50, 0x61, 0x62, 0x63, 0x50, 0x61, 0x56, 0x57, 0x50, +0x61, 0x56, 0x63, 0x50, 0x61, 0x56, 0x57, 0x50, 0x61, 0x56, 0x33, 0x50, 0x61, 0x56, 0x57, 0x50, +0x61, 0x62, 0x63, 0x50, 0x61, 0x62, 0x63, 0x50 ]; + +pub(crate) const ORIGINAL_OVERWORLD_BLOCKS: [u8; 272] = [ 0x07, 0x07, 0x07, 0x10, 0x10, 0x10, 0x10, +0x10, 0x07, 0x07, 0x07, 0x10, 0x10, 0x10, 0x10, 0x04, 0x06, 0x06, 0x00, 0x03, 0x03, 0x00, 0x0D, +0x0A, 0x06, 0x06, 0x01, 0x01, 0x01, 0x04, 0x05, 0x05, 0x06, 0x06, 0x06, 0x01, 0x01, 0x04, 0x05, +0x05, 0x06, 0x09, 0x0F, 0x00, 0x00, 0x0B, 0x0B, 0x05, 0x08, 0x08, 0x0A, 0x04, 0x04, 0x04, 0x04, +0x04, 0x08, 0x08, 0x0A, 0x04, 0x04, 0x04, 0x04, 0x04, 0x07, 0x07, 0x1A, 0x10, 0x10, 0x10, 0x10, +0x10, 0x07, 0x07, 0x1A, 0x10, 0x10, 0x10, 0x10, 0x04, 0x06, 0x06, 0x00, 0x03, 0x03, 0x00, 0x0D, +0x0A, 0x06, 0x06, 0x1C, 0x1C, 0x1C, 0x02, 0x05, 0x05, 0x06, 0x06, 0x06, 0x1C, 0x1C, 0x00, 0x05, +0x05, 0x06, 0x00, 0x0F, 0x00, 0x00, 0x23, 0x23, 0x05, 0x1F, 0x1F, 0x0A, 0x20, 0x20, 0x20, 0x20, +0x20, 0x1F, 0x1F, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x13, 0x13, 0x17, 0x14, 0x14, 0x14, 0x14, +0x14, 0x13, 0x13, 0x17, 0x14, 0x14, 0x14, 0x14, 0x16, 0x15, 0x15, 0x12, 0x13, 0x13, 0x18, 0x16, +0x16, 0x15, 0x15, 0x13, 0x26, 0x26, 0x13, 0x17, 0x17, 0x15, 0x15, 0x15, 0x26, 0x26, 0x13, 0x17, +0x17, 0x1B, 0x1D, 0x11, 0x13, 0x13, 0x18, 0x18, 0x17, 0x16, 0x16, 0x13, 0x13, 0x13, 0x19, 0x19, +0x19, 0x16, 0x16, 0x18, 0x13, 0x18, 0x19, 0x19, 0x19, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x05, 0x05, 0x06, 0x09, 0x09, 0x09, 0x09, +0x09, 0x05, 0x05, 0x06, 0x09, 0x09, 0x09, 0x09, 0x03 ]; diff --git a/enemize/src/lib.rs b/enemize/src/lib.rs index e5c016e..aae5429 100644 --- a/enemize/src/lib.rs +++ b/enemize/src/lib.rs @@ -11,6 +11,7 @@ pub mod asar; pub mod bosses; pub mod constants; pub mod option_flags; +pub mod randomize; pub mod rom; #[derive(Debug, Error)] diff --git a/enemize/src/main.rs b/enemize/src/main.rs index ea0f310..8dc8e4a 100644 --- a/enemize/src/main.rs +++ b/enemize/src/main.rs @@ -17,7 +17,7 @@ struct Args { rom: PathBuf, /// seed number #[clap(short, long)] - seed: Option, + seed: Option, /// path to the enemizerOptions.json #[clap(short, long)] enemizer: PathBuf, @@ -45,7 +45,9 @@ fn main() -> anyhow::Result<()> { 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()); + // Oh noes! The max seed number is twice as likely to show up as any other! + // (That is, 2 out of 2billion instead of 1.) + let seed = args.seed.unwrap_or_else(|| rand::random()).saturating_abs(); //let randomized_rom = randomize_rom(seed, raw_data, options); diff --git a/enemize/src/randomize.rs b/enemize/src/randomize.rs new file mode 100644 index 0000000..b0dc494 --- /dev/null +++ b/enemize/src/randomize.rs @@ -0,0 +1,30 @@ +use std::collections::HashMap; + +use anyhow::{ensure, Result}; + +use crate::option_flags::OptionFlags; +use crate::rom::RomData; + +pub struct Randomization { + rom: RomData, + option_flags: OptionFlags, + bosses_gfx_index: HashMap, +} + +impl RomData { + pub fn randomize(&mut self, option_flags: OptionFlags, seed: i32) -> anyhow::Result<()> { + ensure!(self.is_randomizer(), "Enemizer only supports randomizer ROMs for input."); + ensure!(!self.is_race(), "Enemizer does not support race roms."); + + if self.is_enemizer() { + // Reuse seed in ROM, not the one given. + self.reset_enemizer(); + } else { + self.set_enemizer_seed(seed); + } + + self.set_info_flags(option_flags)?; + + Ok(()) + } +} diff --git a/enemize/src/rom.rs b/enemize/src/rom.rs index 95b1fb6..64a400c 100644 --- a/enemize/src/rom.rs +++ b/enemize/src/rom.rs @@ -31,9 +31,9 @@ pub const RANDOMIZER_MODE_FLAG: usize = 0x180032; pub struct RomData { asar_symbols: Symbols, spoiler: String, - rom_data: Vec, + pub(crate) rom_data: Vec, patch_data: BTreeMap, - seed: i32, + pub(crate) seed: i32, } impl RomData { @@ -41,6 +41,25 @@ impl RomData { self.spoiler.as_str() } + pub fn reset_enemizer(&mut self) -> i32 { + use crate::constants::*; + + let seed = self.get_enemizer_seed(); + + self.rom_data[ROOM_HEADER_BANK_LOCATION] = 0x04; + + let dungeon_header_range = DUNGEON_HEADER_POINTER_TABLE..(DUNGEON_HEADER_POINTER_TABLE + 640); + self.rom_data[dungeon_header_range].copy_from_slice(&ORIGINAL_ROOM_POINTERS); + + let room_range = 0x5B97..(0x5B97 + 576); + self.rom_data[room_range].copy_from_slice(&ORIGINAL_ROOM_BLOCKS); + + let ow_gfx_range = OVERWORLD_AREA_GRAPHICS_BLOCK..(OVERWORLD_AREA_GRAPHICS_BLOCK + 272); + self.rom_data[ow_gfx_range].copy_from_slice(&ORIGINAL_OVERWORLD_BLOCKS); + + seed + } + pub fn generate_patch(&self) -> Vec { let mut patches = vec![]; @@ -92,6 +111,12 @@ impl RomData { &self.rom_data[0x7FC0..0x7FCE] == b"ZELDANODENSETSU") } + pub fn is_race(&self) -> bool { + self.is_randomizer() && + (&self.rom_data[0x180213..0x180214] == &[1, 0] || + &self.rom_data[0x7FC0..0x7FC9] == b"VT TOURNEY") + } + fn assert_rom_length(&self) { assert!(self.rom_data.len() >= ENEMIZER_FILE_LENGTH, "You need to expand the rom before you can use Enemizer features."); } @@ -127,6 +152,15 @@ impl RomData { self.set_patch_bytes(seed_start..seed_end); } + pub fn expand_rom(&mut self) { + self.rom_data.resize(0x40_0000, 0); + // Update header length. + self.rom_data[0x7FD7] = 0x0C; + self.set_patch_bytes(0x7FD7..0x7FD8); + + self.set_enemizer_version("6.0.32".to_owned()); + } + pub fn get_enemizer_version(&self) -> anyhow::Result<&str> { if self.is_enemizer() { let version_start = self.asar_symbols["enemizer_info_table"] + ENEMIZER_INFO_VERSION_OFFSET;