use std::fs::File; use std::marker::PhantomData; use std::path::{Path, PathBuf}; use serde::{Deserialize, Serialize}; use thiserror::Error; use crate::rom::RomData; pub mod bosses; pub mod constants; pub mod option_flags; pub mod rom; #[derive(Debug, Error)] #[error("Not a valid value for {0:?}")] pub struct InvalidEnumError(PhantomData); #[derive(Deserialize, Serialize)] pub struct Patch { pub address: usize, pub patch_data: Vec, } #[derive(Deserialize, Serialize)] pub struct PatchSet { filename: PathBuf, patches: Vec, } impl PatchSet { pub fn load(filename: &Path) -> Result { let patches = { let file = File::open(filename)?; let buffer = std::io::BufReader::new(file); serde_json::from_reader(buffer)? }; Ok(PatchSet { filename: filename.into(), patches: patches, }) } pub fn filename(&self) -> &Path { self.filename.as_path() } pub fn patch_rom(self, rom: &mut RomData) { for patch in self.patches { rom.patch_data(patch); } } }