Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions crates/lovely-core/src/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub fn write_dump(
dir_name: &str,
name: &str,
buffer: &str,
debug: &PatchDebug,
debug: Option<&PatchDebug>,
) {
if name.chars().count() > 100 {
return;
Expand Down Expand Up @@ -149,14 +149,19 @@ pub fn write_dump(
return;
}

match serde_json::to_string_pretty(debug) {
Ok(json) => {
if let Err(e) = fs::write(&json_path, json) {
log::error!("Failed to write debug JSON to {json_path:?}: {e:?}");
match debug {
Some(debug) => {
match serde_json::to_string_pretty(debug) {
Ok(json) => {
if let Err(e) = fs::write(&json_path, json) {
log::error!("Failed to write debug JSON to {json_path:?}: {e:?}");
}
}
Err(e) => {
log::error!("Failed to serialize debug info: {e:?}");
}
}
}
Err(e) => {
log::error!("Failed to serialize debug info: {e:?}");
}
None => return,
}
}
6 changes: 3 additions & 3 deletions crates/lovely-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use regex_lite::Regex;
use sys::{check_lua_string, LuaFunc, LuaLib, LuaState, LuaStateTrait, LUA};

use crate::patch::Target;
use crate::dump::{PatchDebug, write_dump};
use crate::dump::write_dump;

pub mod chunk_vec_cursor;
pub mod dump;
Expand Down Expand Up @@ -310,6 +310,7 @@ impl Lovely {
};

// Apply patches onto this buffer.
write_dump(&self.mod_dir, "game-dump", &pretty_name, &buf_str, None);
let res = patch_table.apply_patches(name, buf_str, state);
if res.is_err() {
state.push(res.unwrap_err());
Expand All @@ -318,8 +319,7 @@ impl Lovely {
}
let (patched, debug) = res.unwrap();

write_dump(&self.mod_dir, "game-dump", &pretty_name, &patched, &PatchDebug::new(name));
write_dump(&self.mod_dir, "dump", &pretty_name, &patched, &debug);
write_dump(&self.mod_dir, "dump", &pretty_name, &patched, Some(&debug));

(self.loadbuffer)(state, patched.as_ptr(), patched.len(), name_ptr, mode_ptr)
}
Expand Down
Loading