use std::io::Read; use std::path::{Path, PathBuf}; use serde::Serialize; pub mod rom; #[derive(Serialize)] pub struct Patch { pub address: usize, pub patch_data: Vec, } #[derive(Serialize)] pub struct PatchSet { filename: PathBuf, patches: Vec } impl PatchSet { pub fn load(filename: Path) -> Result { let patches = { let mut file = File::open(filename)?; let mut buffer = std::io::BufReader::new(file); serde_json::from_reader(buffer)? }; PatchSet { filename: filename.into(), patches: patches } } pub fn filename(&self) -> Path { self.filename.as_path() } pub fn patchRom(&self, &mut rom: RomData) { for patch in self.patches { rom.patch_data(patch); } } }