diff --git a/src/main.rs b/src/main.rs index f495717..35413b9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,28 +1,33 @@ -mod utils; -mod patches; mod mods; +mod patches; +mod utils; +use asky::Text; +use async_std::fs::create_dir; +use godot_pck::structs::PCK; use std::env::{current_exe, set_current_dir}; use std::fs::File; use std::io::{Read, Write}; use std::path::Path; use std::process::Command; use std::time::Duration; -use asky::Text; -use async_std::fs::create_dir; use steamlocate::SteamDir; use sudo::RunningAs; use sysinfo::ProcessesToUpdate; -use godot_pck::structs::PCK; static WEBFISHING_APPID: u32 = 3146520; async fn install_webfishing(location: &SteamDir) { let steam_location = location.path(); - let acf_path = steam_location.join("steamapps").join(format!("appmanifest_{}.acf", WEBFISHING_APPID)); + let acf_path = steam_location + .join("steamapps") + .join(format!("appmanifest_{}.acf", WEBFISHING_APPID)); println!("Creating Webfishing ACF"); - File::create(acf_path).unwrap().write(include_str!("../res/webfishing.acf").as_bytes()).expect("could not write acf"); + File::create(acf_path) + .unwrap() + .write(include_str!("../res/webfishing.acf").as_bytes()) + .expect("could not write acf"); println!("Waiting for steam to close"); let mut system = sysinfo::System::new_all(); @@ -40,7 +45,10 @@ async fn install_webfishing(location: &SteamDir) { } println!("Steam launched, downloading webfishing"); - let download_path = steam_location.join("steamapps").join("downloading").join(format!("{}", WEBFISHING_APPID)); + let download_path = steam_location + .join("steamapps") + .join("downloading") + .join(format!("{}", WEBFISHING_APPID)); while Path::exists(download_path.as_path()) { println!("Downloading webfishing..."); @@ -50,11 +58,17 @@ async fn install_webfishing(location: &SteamDir) { async fn download_godot_steam_template() { println!("Downloading GodotSteam template..."); - let res = reqwest::get("https://github.com/GodotSteam/GodotSteam/releases/download/v3.27/macos-g36-s160-gs327.zip").await.expect("Could not download godotsteam template"); + let res = reqwest::get( + "https://github.com/GodotSteam/GodotSteam/releases/download/v3.24/macos-g353-s159-gs324.zip", + ) + .await + .expect("Could not download godotsteam template"); let body = res.bytes().await.expect("Could not read body"); - let mut file = File::create("build/godot_steam_template.zip").expect("Could not create godotsteam template"); - file.write_all(&body).expect("Could not write godotsteam template"); + let mut file = File::create("build/godot_steam_template_324.zip") + .expect("Could not create godotsteam template"); + file.write_all(&body) + .expect("Could not write godotsteam template"); } async fn download_gd_decomp() { @@ -69,45 +83,79 @@ async fn download_gd_decomp() { Command::new("unzip") .arg("decompiler.zip") .current_dir("build") - .output().expect("Could not unzip godotsteam template"); + .output() + .expect("Could not unzip godotsteam template"); } fn build_webfishing_macos(webfishing_path: &Path) { let template_path = Path::new("build/osx_template.app"); Command::new("rm") .current_dir(template_path) - .arg("Contents/MacOS/godot_osx_debug.64") - .output().expect("Could not remove delete godot_osx_debug.64"); + .arg("Contents/MacOS/godot_osx_debug.universal") + .output() + .expect("Could not remove delete godot_osx_debug.universal"); Command::new("mv") .current_dir(template_path) - .arg("Contents/MacOS/godot_osx_release.64") + .arg("Contents/MacOS/godot_osx_release.universal") .arg("Contents/MacOS/webfishing") - .output().expect("Could not rename godot_osc_release.64"); - - let mut steamappid = File::create(template_path.join("Contents").join("MacOS").join("steam_appid.txt")).expect("could not create steam_appid.txt file"); - steamappid.write(include_str!("../res/steam_appid.txt").as_bytes()).expect("could not write steam_appid.txt"); + .output() + .expect("Could not rename godot_osc_release.universal"); + + let mut steamappid = File::create( + template_path + .join("Contents") + .join("MacOS") + .join("steam_appid.txt"), + ) + .expect("could not create steam_appid.txt file"); + steamappid + .write(include_str!("../res/steam_appid.txt").as_bytes()) + .expect("could not write steam_appid.txt"); Command::new("cp") .arg(webfishing_path.join("webfishing.exe")) - .arg(template_path.join("Contents").join("Resources").join("webfishing.pck")) - .output().expect("Could not copy webfishing.exe"); + .arg( + template_path + .join("Contents") + .join("Resources") + .join("webfishing.pck"), + ) + .output() + .expect("Could not copy webfishing.exe"); - let mut info_plist = File::create(template_path.join("Contents").join("Info.plist")).expect("Could not open Info.plist"); - info_plist.write_all(include_str!("../res/Info.plist").as_bytes()).expect("could not write Info.plist"); + let mut info_plist = File::create(template_path.join("Contents").join("Info.plist")) + .expect("Could not open Info.plist"); + info_plist + .write_all(include_str!("../res/Info.plist").as_bytes()) + .expect("could not write Info.plist"); Command::new("mv") .arg(template_path) .arg(Path::new("build/webfishing.app")) - .output().expect("Could not copy webfishing.app"); + .output() + .expect("Could not copy webfishing.app"); } #[tokio::main] async fn main() { - set_current_dir(current_exe().unwrap().parent().expect("Could not get current dir")).expect("Could not set current dir"); + if sudo::check() != RunningAs::Root { + println!("You need to be root to run this program"); + } + sudo::escalate_if_needed().expect("Could not escalate"); + + set_current_dir( + current_exe() + .unwrap() + .parent() + .expect("Could not get current dir"), + ) + .expect("Could not set current dir"); if !Path::exists("build".as_ref()) { println!("Creating build folder"); - create_dir("build").await.expect("could not create build folder"); + create_dir("build") + .await + .expect("could not create build folder"); } let location = SteamDir::locate().expect("could not locate steam directory"); @@ -118,35 +166,38 @@ async fn main() { install_webfishing(&location).await; } - let (app, library) = location.find_app(WEBFISHING_APPID).unwrap().unwrap(); + let (app, library) = location.find_app(WEBFISHING_APPID).unwrap().unwrap(); if !Path::exists("build/decompiler.zip".as_ref()) { download_gd_decomp().await; } - if !Path::exists("build/godot_steam_template.zip".as_ref()) { + if !Path::exists("build/godot_steam_template_324.zip".as_ref()) { download_godot_steam_template().await; } - if !Path::exists("build/macos.zip".as_ref()) { - println!("Unzipping template"); - Command::new("unzip") - .arg("-o") - .arg("godot_steam_template.zip") - .current_dir("./build") - .output().expect("Could not unzip godot_steam_template.zip"); - } + println!("Unzipping template 1/2"); + Command::new("unzip") + .arg("-o") + .arg("godot_steam_template_324.zip") + .current_dir("./build") + .output() + .expect("Could not unzip godot_steam_template_324.zip"); - if !Path::exists("build/osx_template.app".as_ref()) && !Path::exists("build/webfishing.app".as_ref()) { - println!("Unzipping template"); - Command::new("unzip") - .arg("-o") - .arg("macos.zip") - .current_dir("./build") - .output() - .expect("Could not unzip macos.zip"); - } + Command::new("mv") + .arg("build/godot_steam_template_324/macos.zip") + .arg("build/macos.zip") + .current_dir("./build") + .output() + .expect("Could not copy godot_steam_template_324/macos.zip"); + println!("Unzipping template 2/2"); + Command::new("unzip") + .arg("-o") + .arg("macos.zip") + .current_dir("./build") + .output() + .expect("Could not unzip macos.zip"); let binding = library.resolve_app_dir(&app); let webfishing_path = binding.as_path(); @@ -154,22 +205,23 @@ async fn main() { build_webfishing_macos(webfishing_path); } - if sudo::check()!= RunningAs::Root { - let _ = create_dir("build/webfishing-export").await; - let mut bytes = vec![]; - File::open(webfishing_path.join("webfishing.exe")).unwrap().read_to_end(&mut bytes).unwrap(); - let mut pck = PCK::from_bytes(&*bytes).unwrap(); - - patches::steam_network_patch::patch(&mut pck).await; - patches::options_menu_patch::patch(&mut pck).await; - mods::mods::process_mods(&mut pck); - println!("Root permissions needed to sign webfishing"); + let _ = create_dir("build/webfishing-export").await; + let mut bytes = vec![]; + File::open(webfishing_path.join("webfishing.exe")) + .unwrap() + .read_to_end(&mut bytes) + .unwrap(); + let mut pck = PCK::from_bytes(&*bytes).unwrap(); - let bytes = &pck.to_bytes(); - File::create("build/webfishing.app/Contents/Resources/webfishing.pck").unwrap().write(bytes).expect("Could not write to webfishing.pck"); - } + patches::steam_network_patch::patch(&mut pck).await; + patches::options_menu_patch::patch(&mut pck).await; + mods::mods::process_mods(&mut pck); - sudo::escalate_if_needed().expect("Could not escalate to sign the app"); + let bytes = &pck.to_bytes(); + File::create("build/webfishing.app/Contents/Resources/webfishing.pck") + .unwrap() + .write(bytes) + .expect("Could not write to webfishing.pck"); Command::new("xattr") .arg("-cr") @@ -179,5 +231,7 @@ async fn main() { println!("Webfishing is in the build folder !"); - Text::new("Press Enter to quit").prompt().expect("Could not confirm to quit"); + Text::new("Press Enter to quit") + .prompt() + .expect("Could not confirm to quit"); } diff --git a/src/patches/steam_network_patch.rs b/src/patches/steam_network_patch.rs index cee75e4..1d5c8ed 100644 --- a/src/patches/steam_network_patch.rs +++ b/src/patches/steam_network_patch.rs @@ -24,7 +24,7 @@ pub(crate) async fn patch(pck: &mut PCK) { script.read_to_string(&mut script_txt).await.expect("Cannot read script"); drop(script); - let patched_script = script_txt.replace("steam_id_remote", "remote_steam_id"); + 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);