43 lines
870 B
Rust
43 lines
870 B
Rust
|
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<u8>,
|
||
|
}
|
||
|
|
||
|
#[derive(Serialize)]
|
||
|
pub struct PatchSet {
|
||
|
filename: PathBuf,
|
||
|
patches: Vec<Patch>
|
||
|
}
|
||
|
|
||
|
impl PatchSet {
|
||
|
pub fn load(filename: Path) -> Result<PatchSet, anyhow::Error> {
|
||
|
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);
|
||
|
}
|
||
|
}
|
||
|
}
|