Add base_patch_generator.
This commit is contained in:
parent
7cd01df7d6
commit
4112573d85
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -8,6 +8,16 @@ version = "1.0.57"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc"
|
checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base_patch_generator"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"enemize",
|
||||||
|
"md5",
|
||||||
|
"serde_json",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bin_comp"
|
name = "bin_comp"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
|
@ -3,4 +3,5 @@
|
||||||
members = [
|
members = [
|
||||||
"enemize",
|
"enemize",
|
||||||
"bin_comp",
|
"bin_comp",
|
||||||
|
"base_patch_generator",
|
||||||
]
|
]
|
||||||
|
|
12
base_patch_generator/Cargo.toml
Normal file
12
base_patch_generator/Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
[package]
|
||||||
|
name = "base_patch_generator"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
anyhow = "1.0"
|
||||||
|
enemize = { path = "../enemize" }
|
||||||
|
md5 = "0.7.0"
|
||||||
|
serde_json = "1.0"
|
56
base_patch_generator/src/main.rs
Normal file
56
base_patch_generator/src/main.rs
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::Read;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use enemize::PatchSet;
|
||||||
|
use enemize::asar;
|
||||||
|
use enemize::rom::RomData;
|
||||||
|
|
||||||
|
fn main() -> Result<(), anyhow::Error> {
|
||||||
|
let mut args = env::args();
|
||||||
|
|
||||||
|
let output_path = args.next_back().expect("No output file");
|
||||||
|
let symbols_path = args.next_back().expect("No symbols file");
|
||||||
|
let patch_path = args.next_back().expect("No patch file");
|
||||||
|
let rom_path = args.next_back().expect("No ROM file");
|
||||||
|
|
||||||
|
let mut rom_bytes = vec![];
|
||||||
|
let mut rom_file = File::open(&rom_path)?;
|
||||||
|
rom_file.read_to_end(&mut rom_bytes)?;
|
||||||
|
|
||||||
|
rom_bytes = if rom_bytes.len() % 1024 == 512 {
|
||||||
|
rom_bytes.into_iter().skip(512).collect()
|
||||||
|
} else {
|
||||||
|
rom_bytes
|
||||||
|
};
|
||||||
|
|
||||||
|
let expected = [
|
||||||
|
0x03, 0xa6, 0x39, 0x45, 0x39, 0x81, 0x91, 0x33, 0x7e, 0x89, 0x6e, 0x57, 0x71, 0xf7, 0x71,
|
||||||
|
0x73,
|
||||||
|
];
|
||||||
|
let actual: [u8; 16] = md5::compute(&rom_bytes).into();
|
||||||
|
assert_eq!(expected, actual, "Invalid rom file");
|
||||||
|
|
||||||
|
println!("Applying Patch to rom");
|
||||||
|
|
||||||
|
rom_bytes.resize(4 * 1024 * 1024, 0);
|
||||||
|
|
||||||
|
let symbols = asar::load_symbols(Path::new(&symbols_path))?;
|
||||||
|
|
||||||
|
let mut rom = RomData::new(symbols, rom_bytes);
|
||||||
|
|
||||||
|
let mut patches = PatchSet::load(Path::new(&patch_path))?;
|
||||||
|
patches.patch_rom(&mut rom);
|
||||||
|
|
||||||
|
rom.move_room_headers();
|
||||||
|
|
||||||
|
let rom_patches = rom.generate_patch();
|
||||||
|
patches.add_patches(rom_patches);
|
||||||
|
|
||||||
|
println!("Writing output file {}", output_path);
|
||||||
|
let out_file = File::create(&output_path)?;
|
||||||
|
serde_json::to_writer(out_file, &patches)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
Reference in a new issue