feat(genshin): allowed to launch the game without launcher.bat file

This commit is contained in:
Observer KRypt0n_ 2023-07-15 14:49:15 +02:00
parent cedb6f05b5
commit 1e75e23692
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2

View file

@ -50,6 +50,13 @@ pub fn run() -> anyhow::Result<()> {
let config = Config::get()?; 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); let game_path = config.game.path.for_edition(config.launcher.edition);
if !game_path.exists() { if !game_path.exists() {
@ -110,13 +117,21 @@ pub fn run() -> anyhow::Result<()> {
return Err(anyhow::anyhow!("Failed to update FPS unlocker config: {err}")); return Err(anyhow::anyhow!("Failed to update FPS unlocker config: {err}"));
} }
let bat_path = game_path.join("fps_unlocker.bat"); let launcher_bat = game_path.join("launcher.bat");
let original_bat_path = game_path.join("launcher.bat"); let fps_unlocker_bat = game_path.join("fps_unlocker.bat");
// Generate fpsunlocker.bat from launcher.bat // Generate fps_unlocker.bat
std::fs::write(bat_path, std::fs::read_to_string(original_bat_path)? if config.patch.apply {
.replace("start GenshinImpact.exe %*", &format!("start GenshinImpact.exe %*\n\nZ:\ncd \"{}\"\nstart unlocker.exe", unlocker.dir().to_string_lossy())) std::fs::write(fps_unlocker_bat, std::fs::read_to_string(launcher_bat)?
.replace("start YuanShen.exe %*", &format!("start YuanShen.exe %*\n\nZ:\ncd \"{}\"\nstart unlocker.exe", unlocker.dir().to_string_lossy())))?; .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 // 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") { windows_command += if config.game.enhancements.fps_unlocker.enabled && cfg!(feature = "fps-unlocker") {
"fps_unlocker.bat " "fps_unlocker.bat"
} else { } else {
"launcher.bat " game_executable
}; };
windows_command += " ";
if config.game.wine.borderless { if config.game.wine.borderless {
windows_command += "-screen-fullscreen 0 -popupwindow "; windows_command += "-screen-fullscreen 0 -popupwindow ";
} }