From e6492825dce864363d2ef876ca9e254485e2174c Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Fri, 21 Apr 2023 18:06:53 -0700 Subject: [PATCH] optionally patch/unpatch --- src-tauri/src/main.rs | 15 +++++++++++ src-tauri/src/patch.rs | 59 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 src-tauri/src/patch.rs diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 96c0434..468fb3a 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -27,6 +27,7 @@ mod downloader; mod file_helpers; mod gamebanana; mod lang; +mod patch; mod proxy; mod release; mod system_helpers; @@ -56,6 +57,11 @@ async fn parse_args(inp: &Vec) -> Result { ); args.flag("g", "no-gui", "Run in CLI mode"); args.flag("s", "server", "Launch the configured GC server"); + args.flag( + "P", + "path", + "Patch your game before launching, with whatever your game version needs", + ); args.option( "H", "host", @@ -85,6 +91,12 @@ async fn parse_args(inp: &Vec) -> Result { if args.value_of("launch-game")? { let game_path = config.game_install_path; let game_args: String = args.value_of("game-args")?; + + // Patch if needed + if args.value_of("patch")? { + patch::patch_game().await; + } + system_helpers::run_program(game_path.to_string(), Some(game_args)) } @@ -211,6 +223,9 @@ fn main() -> Result<(), ArgsError> { // Always disconnect upon closing the program disconnect(); + // Always unpatch game upon closing the program + patch::unpatch_game(); + Ok(()) } diff --git a/src-tauri/src/patch.rs b/src-tauri/src/patch.rs new file mode 100644 index 0000000..5f8cc35 --- /dev/null +++ b/src-tauri/src/patch.rs @@ -0,0 +1,59 @@ +use crate::config; +use crate::file_helpers; +use crate::system_helpers; +use std::path::PathBuf; + +pub async fn patch_game() -> bool { + let patch_path = PathBuf::from(system_helpers::install_location()).join("patch/version.dll"); + + // Are we already patched with mhypbase? If so, that's fine, just continue as normal + let game_is_patched = file_helpers::are_files_identical( + patch_path.clone().to_str().unwrap(), + PathBuf::from(get_game_rsa_path().await.unwrap()) + .join("mhypbase.dll") + .to_str() + .unwrap(), + ); + + // Tell user they won't be unpatched with manual mhypbase patch + if game_is_patched { + println!( + "You are already patched using mhypbase, so you will not be auto patched and unpatched!" + ); + return true; + } + + // Copy the patch to game files + let replaced = file_helpers::copy_file_with_new_name( + patch_path.clone().to_str().unwrap().to_string(), + get_game_rsa_path().await.unwrap(), + String::from("version.dll"), + ); + + if !replaced { + return false; + } + + true +} + +pub async fn unpatch_game() -> bool { + // Just delete patch since it's not replacing any existing file + let deleted = file_helpers::delete_file( + PathBuf::from(get_game_rsa_path().await.unwrap()) + .join("version.dll") + .to_str() + .unwrap() + .to_string(), + ); + + deleted +} + +pub async fn get_game_rsa_path() -> Option { + let config = config::get_config(); + let mut game_folder = PathBuf::from(config.game_install_path); + game_folder.pop(); + + Some(format!("{}/", game_folder.to_str().unwrap()).replace("\\", "/")) +}