use godot_pck::structs::PckFile; use async_std::fs::File; use async_std::io::{ReadExt, WriteExt}; use godot_pck::structs::PCK; const RESOURCE_PATH: &str = "res://Scenes/Singletons/SteamNetwork.gdc"; const FILE_PATH: &str = "build/webfishing-export/SteamNetwork.gdc"; const SCRIPT_PATH: &str = "build/webfishing-decomp/SteamNetwork.gd"; const COMPILED_PATH: &str = "build/webfishing-recomp/SteamNetwork.gdc"; pub(crate) async fn patch(pck: &mut PCK) { println!("Patching {} files...", RESOURCE_PATH); let pck_file: &mut PckFile = pck.get_file_by_path_mut(RESOURCE_PATH).expect("Couldn't find options_menu.gdc file"); let content = pck_file.get_content(); let mut exported_file = File::create(FILE_PATH).await.expect("Couldn't create file"); exported_file.write_all(content).await.expect("Couldn't write file"); drop(exported_file); crate::utils::gd_utils::decomp_script(FILE_PATH); let mut script = File::open(SCRIPT_PATH).await.expect("Cannot open script"); let mut script_txt = String::new(); script.read_to_string(&mut script_txt).await.expect("Cannot read script"); drop(script); let patched_script = script_txt.replace(".LOBBY_COMPARISON_EQUAL_TO_GREATER_THAN", ".OBBY_COMPARISON_EQUAL_TO_GREATER_THAN"); let mut script = File::create(SCRIPT_PATH).await.expect("Cannot open script"); script.write_all(patched_script.as_bytes()).await.expect("Cannot write"); drop(script); crate::utils::gd_utils::recomp_file(SCRIPT_PATH); let mut file = File::open(COMPILED_PATH).await.expect("Cannot open compiled script"); let mut new_content = vec![]; file.read_to_end(&mut new_content).await.unwrap(); pck_file.set_content(new_content); }