From 1e75e23692161ab9afe14df1635919010d595d95 Mon Sep 17 00:00:00 2001 From: Observer KRypt0n_ Date: Sat, 15 Jul 2023 14:49:15 +0200 Subject: [PATCH] feat(genshin): allowed to launch the game without `launcher.bat` file --- src/games/genshin/game.rs | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/games/genshin/game.rs b/src/games/genshin/game.rs index 583de3f..bf051b2 100644 --- a/src/games/genshin/game.rs +++ b/src/games/genshin/game.rs @@ -50,6 +50,13 @@ pub fn run() -> anyhow::Result<()> { let config = Config::get()?; + let game_executable = config.patch.apply + .then_some("launcher.bat") + .unwrap_or_else(|| match config.launcher.edition { + genshin::GameEdition::Global => "GenshinImpact.exe", + genshin::GameEdition::China => "YuanShen.exe" + }); + let game_path = config.game.path.for_edition(config.launcher.edition); if !game_path.exists() { @@ -110,13 +117,21 @@ pub fn run() -> anyhow::Result<()> { return Err(anyhow::anyhow!("Failed to update FPS unlocker config: {err}")); } - let bat_path = game_path.join("fps_unlocker.bat"); - let original_bat_path = game_path.join("launcher.bat"); + let launcher_bat = game_path.join("launcher.bat"); + let fps_unlocker_bat = game_path.join("fps_unlocker.bat"); - // Generate fpsunlocker.bat from launcher.bat - std::fs::write(bat_path, std::fs::read_to_string(original_bat_path)? - .replace("start GenshinImpact.exe %*", &format!("start GenshinImpact.exe %*\n\nZ:\ncd \"{}\"\nstart unlocker.exe", unlocker.dir().to_string_lossy())) - .replace("start YuanShen.exe %*", &format!("start YuanShen.exe %*\n\nZ:\ncd \"{}\"\nstart unlocker.exe", unlocker.dir().to_string_lossy())))?; + // Generate fps_unlocker.bat + if config.patch.apply { + std::fs::write(fps_unlocker_bat, std::fs::read_to_string(launcher_bat)? + .replace("start GenshinImpact.exe %*", &format!("start GenshinImpact.exe %*\n\nZ:\ncd \"{}\"\nstart unlocker.exe", unlocker.dir().to_string_lossy())) + .replace("start YuanShen.exe %*", &format!("start YuanShen.exe %*\n\nZ:\ncd \"{}\"\nstart unlocker.exe", unlocker.dir().to_string_lossy())))?; + } + + else { + // If patch applying is disabled, then game_executable is either GenshinImpact.exe or YuanShen.exe + // so we don't need to check it here + std::fs::write(fps_unlocker_bat, format!("start {game_executable} %*\n\nZ:\ncd \"{}\"\nstart unlocker.exe", unlocker.dir().to_string_lossy()))?; + } } // Generate `config.ini` if environment emulation feature is presented @@ -152,11 +167,13 @@ pub fn run() -> anyhow::Result<()> { } windows_command += if config.game.enhancements.fps_unlocker.enabled && cfg!(feature = "fps-unlocker") { - "fps_unlocker.bat " + "fps_unlocker.bat" } else { - "launcher.bat " + game_executable }; + windows_command += " "; + if config.game.wine.borderless { windows_command += "-screen-fullscreen 0 -popupwindow "; }