optionally patch/unpatch

This commit is contained in:
SpikeHD
2023-04-21 18:06:53 -07:00
parent 3141bcea41
commit e6492825dc
2 changed files with 74 additions and 0 deletions

View File

@@ -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<String>) -> Result<Args, ArgsError> {
);
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<String>) -> Result<Args, ArgsError> {
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(())
}

59
src-tauri/src/patch.rs Normal file
View File

@@ -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<String> {
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("\\", "/"))
}