A native webfishing installer for macos

1.4.0 - Webfishing 1.11

- Fixed wrong version of godot steam
- Fixed Typo in SteamManager.gd

Changed files
+114 -60
src
+113 -59
src/main.rs
··· 1 - mod utils; 1 + mod mods; 2 2 mod patches; 3 - mod mods; 3 + mod utils; 4 4 5 + use asky::Text; 6 + use async_std::fs::create_dir; 7 + use godot_pck::structs::PCK; 5 8 use std::env::{current_exe, set_current_dir}; 6 9 use std::fs::File; 7 10 use std::io::{Read, Write}; 8 11 use std::path::Path; 9 12 use std::process::Command; 10 13 use std::time::Duration; 11 - use asky::Text; 12 - use async_std::fs::create_dir; 13 14 use steamlocate::SteamDir; 14 15 use sudo::RunningAs; 15 16 use sysinfo::ProcessesToUpdate; 16 - use godot_pck::structs::PCK; 17 17 18 18 static WEBFISHING_APPID: u32 = 3146520; 19 19 20 20 async fn install_webfishing(location: &SteamDir) { 21 21 let steam_location = location.path(); 22 - let acf_path = steam_location.join("steamapps").join(format!("appmanifest_{}.acf", WEBFISHING_APPID)); 22 + let acf_path = steam_location 23 + .join("steamapps") 24 + .join(format!("appmanifest_{}.acf", WEBFISHING_APPID)); 23 25 24 26 println!("Creating Webfishing ACF"); 25 - File::create(acf_path).unwrap().write(include_str!("../res/webfishing.acf").as_bytes()).expect("could not write acf"); 27 + File::create(acf_path) 28 + .unwrap() 29 + .write(include_str!("../res/webfishing.acf").as_bytes()) 30 + .expect("could not write acf"); 26 31 27 32 println!("Waiting for steam to close"); 28 33 let mut system = sysinfo::System::new_all(); ··· 40 45 } 41 46 42 47 println!("Steam launched, downloading webfishing"); 43 - let download_path = steam_location.join("steamapps").join("downloading").join(format!("{}", WEBFISHING_APPID)); 48 + let download_path = steam_location 49 + .join("steamapps") 50 + .join("downloading") 51 + .join(format!("{}", WEBFISHING_APPID)); 44 52 45 53 while Path::exists(download_path.as_path()) { 46 54 println!("Downloading webfishing..."); ··· 50 58 51 59 async fn download_godot_steam_template() { 52 60 println!("Downloading GodotSteam template..."); 53 - 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"); 61 + let res = reqwest::get( 62 + "https://github.com/GodotSteam/GodotSteam/releases/download/v3.24/macos-g353-s159-gs324.zip", 63 + ) 64 + .await 65 + .expect("Could not download godotsteam template"); 54 66 let body = res.bytes().await.expect("Could not read body"); 55 67 56 - let mut file = File::create("build/godot_steam_template.zip").expect("Could not create godotsteam template"); 57 - file.write_all(&body).expect("Could not write godotsteam template"); 68 + let mut file = File::create("build/godot_steam_template_324.zip") 69 + .expect("Could not create godotsteam template"); 70 + file.write_all(&body) 71 + .expect("Could not write godotsteam template"); 58 72 } 59 73 60 74 async fn download_gd_decomp() { ··· 69 83 Command::new("unzip") 70 84 .arg("decompiler.zip") 71 85 .current_dir("build") 72 - .output().expect("Could not unzip godotsteam template"); 86 + .output() 87 + .expect("Could not unzip godotsteam template"); 73 88 } 74 89 75 90 fn build_webfishing_macos(webfishing_path: &Path) { 76 91 let template_path = Path::new("build/osx_template.app"); 77 92 Command::new("rm") 78 93 .current_dir(template_path) 79 - .arg("Contents/MacOS/godot_osx_debug.64") 80 - .output().expect("Could not remove delete godot_osx_debug.64"); 94 + .arg("Contents/MacOS/godot_osx_debug.universal") 95 + .output() 96 + .expect("Could not remove delete godot_osx_debug.universal"); 81 97 82 98 Command::new("mv") 83 99 .current_dir(template_path) 84 - .arg("Contents/MacOS/godot_osx_release.64") 100 + .arg("Contents/MacOS/godot_osx_release.universal") 85 101 .arg("Contents/MacOS/webfishing") 86 - .output().expect("Could not rename godot_osc_release.64"); 102 + .output() 103 + .expect("Could not rename godot_osc_release.universal"); 87 104 88 - let mut steamappid = File::create(template_path.join("Contents").join("MacOS").join("steam_appid.txt")).expect("could not create steam_appid.txt file"); 89 - steamappid.write(include_str!("../res/steam_appid.txt").as_bytes()).expect("could not write steam_appid.txt"); 105 + let mut steamappid = File::create( 106 + template_path 107 + .join("Contents") 108 + .join("MacOS") 109 + .join("steam_appid.txt"), 110 + ) 111 + .expect("could not create steam_appid.txt file"); 112 + steamappid 113 + .write(include_str!("../res/steam_appid.txt").as_bytes()) 114 + .expect("could not write steam_appid.txt"); 90 115 91 116 Command::new("cp") 92 117 .arg(webfishing_path.join("webfishing.exe")) 93 - .arg(template_path.join("Contents").join("Resources").join("webfishing.pck")) 94 - .output().expect("Could not copy webfishing.exe"); 118 + .arg( 119 + template_path 120 + .join("Contents") 121 + .join("Resources") 122 + .join("webfishing.pck"), 123 + ) 124 + .output() 125 + .expect("Could not copy webfishing.exe"); 95 126 96 - let mut info_plist = File::create(template_path.join("Contents").join("Info.plist")).expect("Could not open Info.plist"); 97 - info_plist.write_all(include_str!("../res/Info.plist").as_bytes()).expect("could not write Info.plist"); 127 + let mut info_plist = File::create(template_path.join("Contents").join("Info.plist")) 128 + .expect("Could not open Info.plist"); 129 + info_plist 130 + .write_all(include_str!("../res/Info.plist").as_bytes()) 131 + .expect("could not write Info.plist"); 98 132 99 133 Command::new("mv") 100 134 .arg(template_path) 101 135 .arg(Path::new("build/webfishing.app")) 102 - .output().expect("Could not copy webfishing.app"); 136 + .output() 137 + .expect("Could not copy webfishing.app"); 103 138 } 104 139 105 140 #[tokio::main] 106 141 async fn main() { 107 - set_current_dir(current_exe().unwrap().parent().expect("Could not get current dir")).expect("Could not set current dir"); 142 + if sudo::check() != RunningAs::Root { 143 + println!("You need to be root to run this program"); 144 + } 145 + sudo::escalate_if_needed().expect("Could not escalate"); 146 + 147 + set_current_dir( 148 + current_exe() 149 + .unwrap() 150 + .parent() 151 + .expect("Could not get current dir"), 152 + ) 153 + .expect("Could not set current dir"); 108 154 if !Path::exists("build".as_ref()) { 109 155 println!("Creating build folder"); 110 - create_dir("build").await.expect("could not create build folder"); 156 + create_dir("build") 157 + .await 158 + .expect("could not create build folder"); 111 159 } 112 160 113 161 let location = SteamDir::locate().expect("could not locate steam directory"); ··· 118 166 install_webfishing(&location).await; 119 167 } 120 168 121 - let (app, library) = location.find_app(WEBFISHING_APPID).unwrap().unwrap(); 169 + let (app, library) = location.find_app(WEBFISHING_APPID).unwrap().unwrap(); 122 170 123 171 if !Path::exists("build/decompiler.zip".as_ref()) { 124 172 download_gd_decomp().await; 125 173 } 126 174 127 - if !Path::exists("build/godot_steam_template.zip".as_ref()) { 175 + if !Path::exists("build/godot_steam_template_324.zip".as_ref()) { 128 176 download_godot_steam_template().await; 129 177 } 130 178 131 - if !Path::exists("build/macos.zip".as_ref()) { 132 - println!("Unzipping template"); 133 - Command::new("unzip") 134 - .arg("-o") 135 - .arg("godot_steam_template.zip") 136 - .current_dir("./build") 137 - .output().expect("Could not unzip godot_steam_template.zip"); 138 - } 179 + println!("Unzipping template 1/2"); 180 + Command::new("unzip") 181 + .arg("-o") 182 + .arg("godot_steam_template_324.zip") 183 + .current_dir("./build") 184 + .output() 185 + .expect("Could not unzip godot_steam_template_324.zip"); 139 186 140 - if !Path::exists("build/osx_template.app".as_ref()) && !Path::exists("build/webfishing.app".as_ref()) { 141 - println!("Unzipping template"); 142 - Command::new("unzip") 143 - .arg("-o") 144 - .arg("macos.zip") 145 - .current_dir("./build") 146 - .output() 147 - .expect("Could not unzip macos.zip"); 148 - } 187 + Command::new("mv") 188 + .arg("build/godot_steam_template_324/macos.zip") 189 + .arg("build/macos.zip") 190 + .current_dir("./build") 191 + .output() 192 + .expect("Could not copy godot_steam_template_324/macos.zip"); 149 193 194 + println!("Unzipping template 2/2"); 195 + Command::new("unzip") 196 + .arg("-o") 197 + .arg("macos.zip") 198 + .current_dir("./build") 199 + .output() 200 + .expect("Could not unzip macos.zip"); 150 201 151 202 let binding = library.resolve_app_dir(&app); 152 203 let webfishing_path = binding.as_path(); ··· 154 205 build_webfishing_macos(webfishing_path); 155 206 } 156 207 157 - if sudo::check()!= RunningAs::Root { 158 - let _ = create_dir("build/webfishing-export").await; 159 - let mut bytes = vec![]; 160 - File::open(webfishing_path.join("webfishing.exe")).unwrap().read_to_end(&mut bytes).unwrap(); 161 - let mut pck = PCK::from_bytes(&*bytes).unwrap(); 208 + let _ = create_dir("build/webfishing-export").await; 209 + let mut bytes = vec![]; 210 + File::open(webfishing_path.join("webfishing.exe")) 211 + .unwrap() 212 + .read_to_end(&mut bytes) 213 + .unwrap(); 214 + let mut pck = PCK::from_bytes(&*bytes).unwrap(); 162 215 163 - patches::steam_network_patch::patch(&mut pck).await; 164 - patches::options_menu_patch::patch(&mut pck).await; 165 - mods::mods::process_mods(&mut pck); 166 - println!("Root permissions needed to sign webfishing"); 216 + patches::steam_network_patch::patch(&mut pck).await; 217 + patches::options_menu_patch::patch(&mut pck).await; 218 + mods::mods::process_mods(&mut pck); 167 219 168 - let bytes = &pck.to_bytes(); 169 - File::create("build/webfishing.app/Contents/Resources/webfishing.pck").unwrap().write(bytes).expect("Could not write to webfishing.pck"); 170 - } 171 - 172 - sudo::escalate_if_needed().expect("Could not escalate to sign the app"); 220 + let bytes = &pck.to_bytes(); 221 + File::create("build/webfishing.app/Contents/Resources/webfishing.pck") 222 + .unwrap() 223 + .write(bytes) 224 + .expect("Could not write to webfishing.pck"); 173 225 174 226 Command::new("xattr") 175 227 .arg("-cr") ··· 179 231 180 232 println!("Webfishing is in the build folder !"); 181 233 182 - Text::new("Press Enter to quit").prompt().expect("Could not confirm to quit"); 234 + Text::new("Press Enter to quit") 235 + .prompt() 236 + .expect("Could not confirm to quit"); 183 237 }
+1 -1
src/patches/steam_network_patch.rs
··· 24 24 script.read_to_string(&mut script_txt).await.expect("Cannot read script"); 25 25 drop(script); 26 26 27 - let patched_script = script_txt.replace("steam_id_remote", "remote_steam_id"); 27 + let patched_script = script_txt.replace(".LOBBY_COMPARISON_EQUAL_TO_GREATER_THAN", ".OBBY_COMPARISON_EQUAL_TO_GREATER_THAN"); 28 28 let mut script = File::create(SCRIPT_PATH).await.expect("Cannot open script"); 29 29 script.write_all(patched_script.as_bytes()).await.expect("Cannot write"); 30 30 drop(script);