push it
This commit is contained in:
parent
6b202eb725
commit
6f441eaf39
5 changed files with 43 additions and 3 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
|||
/target
|
||||
*.bin
|
||||
*.bin
|
||||
*.sav
|
||||
10
Cargo.lock
generated
10
Cargo.lock
generated
|
|
@ -14,11 +14,21 @@ version = "1.0.75"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
|
||||
|
||||
[[package]]
|
||||
name = "deflate"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c86f7e25f518f4b81808a2cf1c50996a61f5c2eb394b2393bd87f2a4780a432f"
|
||||
dependencies = [
|
||||
"adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fot-save-edit"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"deflate",
|
||||
"inflate",
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -7,4 +7,5 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
anyhow = "1.0.75"
|
||||
deflate = "1.0.0"
|
||||
inflate = "0.4.5"
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@ fn main() {
|
|||
};*/
|
||||
|
||||
let save = Save::load(Path::new(save_path)).expect("load save");
|
||||
for w in save.worlds {
|
||||
for w in save.worlds.iter() {
|
||||
println!("World {:x} size {}", w.offset, w.size);
|
||||
}
|
||||
|
||||
save.save(Path::new("out.sav")).expect("failed to save");
|
||||
}
|
||||
28
src/save.rs
28
src/save.rs
|
|
@ -1,9 +1,13 @@
|
|||
use std::fs;
|
||||
use std::io::Write;
|
||||
use std::str;
|
||||
use std::fs;
|
||||
use std::fs::File;
|
||||
use std::fs::OpenOptions;
|
||||
use std::path::Path;
|
||||
use anyhow::anyhow;
|
||||
use anyhow::Result;
|
||||
use inflate::inflate_bytes_zlib;
|
||||
use deflate::deflate_bytes_zlib;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct World {
|
||||
|
|
@ -24,6 +28,10 @@ impl World {
|
|||
Ok(Self { offset, size, data })
|
||||
}
|
||||
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
deflate_bytes_zlib(&self.data)
|
||||
}
|
||||
|
||||
pub fn dump(&self, path: &Path) -> Result<()> {
|
||||
Ok(fs::write(path, &self.data)?)
|
||||
}
|
||||
|
|
@ -69,4 +77,22 @@ impl Save {
|
|||
|
||||
Ok(Self { raw, worlds })
|
||||
}
|
||||
|
||||
pub fn save(&self, path: &Path) -> Result<()> {
|
||||
let mut file = OpenOptions::new()
|
||||
.create(true).write(true).open(path)?;
|
||||
|
||||
// write unknown block
|
||||
let unk_size = match self.worlds.first() {
|
||||
Some(w) => w.offset - 1,
|
||||
None => return Err(anyhow!("no offsets found"))
|
||||
};
|
||||
file.write(&self.raw[..unk_size])?;
|
||||
|
||||
for world in self.worlds.iter() {
|
||||
file.write(&world.encode())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue