feat: added experimental compact_launch wine feature

This commit is contained in:
Observer KRypt0n_ 2023-03-09 15:00:36 +02:00
parent ba11109082
commit e47af52646
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
3 changed files with 38 additions and 17 deletions

View file

@ -37,6 +37,11 @@ pub struct Features {
/// Whether this wine group needs DXVK /// Whether this wine group needs DXVK
pub need_dxvk: bool, pub need_dxvk: bool,
/// Create temp bat file with `launcher.bat` call and its flags
///
/// Extremely helpful when your custom `command` feature can't handle multiline arguments (e.g. in GE-Proton)
pub compact_launch: bool,
/// Command used to launch the game /// Command used to launch the game
/// ///
/// Available keywords: /// Available keywords:
@ -62,6 +67,7 @@ impl Default for Features {
fn default() -> Self { fn default() -> Self {
Self { Self {
need_dxvk: true, need_dxvk: true,
compact_launch: false,
command: None, command: None,
env: HashMap::new() env: HashMap::new()
} }
@ -78,6 +84,11 @@ impl From<&JsonValue> for Features {
None => default.need_dxvk None => default.need_dxvk
}, },
compact_launch: match value.get("compact_launch") {
Some(value) => value.as_bool().unwrap_or(default.compact_launch),
None => default.compact_launch
},
command: match value.get("command") { command: match value.get("command") {
Some(value) => value.as_str().map(|value| value.to_string()), Some(value) => value.as_str().map(|value| value.to_string()),
None => default.command None => default.command

View file

@ -48,6 +48,7 @@ impl VirtualDesktop {
Resolution::from_pair(self.width, self.height) Resolution::from_pair(self.width, self.height)
} }
/// `explorer /desktop=animegame,[width]x[height]`
pub fn get_command(&self) -> Option<String> { pub fn get_command(&self) -> Option<String> {
if self.enabled { if self.enabled {
Some(format!("explorer /desktop=animegame,{}x{}", self.width, self.height)) Some(format!("explorer /desktop=animegame,{}x{}", self.width, self.height))

View file

@ -89,7 +89,7 @@ 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 = config.game.path.join("fpsunlocker.bat"); let bat_path = config.game.path.join("fps_unlocker.bat");
let original_bat_path = config.game.path.join("launcher.bat"); let original_bat_path = config.game.path.join("launcher.bat");
// Generate fpsunlocker.bat from launcher.bat // Generate fpsunlocker.bat from launcher.bat
@ -100,10 +100,11 @@ pub fn run() -> anyhow::Result<()> {
// Prepare bash -c '<command>' // Prepare bash -c '<command>'
let mut bash_chain = String::new(); let mut bash_command = String::new();
let mut windows_command = String::new();
if config.game.enhancements.gamemode { if config.game.enhancements.gamemode {
bash_chain += "gamemoderun "; bash_command += "gamemoderun ";
} }
let wine_build = config.game.wine.builds.join(&wine.name); let wine_build = config.game.wine.builds.join(&wine.name);
@ -112,42 +113,50 @@ pub fn run() -> anyhow::Result<()> {
.map(|command| replace_keywords(command, &config)) .map(|command| replace_keywords(command, &config))
.unwrap_or(format!("'{}'", wine_build.join(wine.files.wine64.unwrap_or(wine.files.wine)).to_string_lossy())); .unwrap_or(format!("'{}'", wine_build.join(wine.files.wine64.unwrap_or(wine.files.wine)).to_string_lossy()));
bash_chain += &run_command; bash_command += &run_command;
bash_chain += " "; bash_command += " ";
if let Some(virtual_desktop) = config.game.wine.virtual_desktop.get_command() { if let Some(virtual_desktop) = config.game.wine.virtual_desktop.get_command() {
bash_chain += &format!("{virtual_desktop} "); windows_command += &virtual_desktop;
windows_command += " ";
} }
bash_chain += if config.game.enhancements.fps_unlocker.enabled && cfg!(feature = "fps-unlocker") { windows_command += if config.game.enhancements.fps_unlocker.enabled && cfg!(feature = "fps-unlocker") {
"fpsunlocker.bat " "fps_unlocker.bat "
} else { } else {
"launcher.bat " "launcher.bat "
}; };
if config.game.wine.borderless { if config.game.wine.borderless {
bash_chain += "-screen-fullscreen 0 -popupwindow "; windows_command += "-screen-fullscreen 0 -popupwindow ";
} }
// https://notabug.org/Krock/dawn/src/master/TWEAKS.md // https://notabug.org/Krock/dawn/src/master/TWEAKS.md
if config.game.enhancements.fsr.enabled { if config.game.enhancements.fsr.enabled {
bash_chain += "-window-mode exclusive "; windows_command += "-window-mode exclusive ";
} }
// gamescope <params> -- <command to run> // gamescope <params> -- <command to run>
if let Some(gamescope) = config.game.enhancements.gamescope.get_command() { if let Some(gamescope) = config.game.enhancements.gamescope.get_command() {
bash_chain = format!("{gamescope} -- {bash_chain}"); bash_command = format!("{gamescope} -- {bash_command}");
} }
let bash_chain = match &config.game.command { // Bundle all windows arguments used to run the game into a single file
Some(command) => replace_keywords(command, &config).replace("%command%", &bash_chain), if features.compact_launch {
None => bash_chain std::fs::write(config.game.path.join("compact_launch.bat"), format!("start {}\nexit", windows_command))?;
};
windows_command = String::from("compact_launch.bat");
}
let bash_command = match &config.game.command {
Some(command) => replace_keywords(command, &config).replace("%command%", &bash_command),
None => bash_command
} + &windows_command;
let mut command = Command::new("bash"); let mut command = Command::new("bash");
command.arg("-c"); command.arg("-c");
command.arg(&bash_chain); command.arg(&bash_command);
// Setup environment // Setup environment
@ -188,7 +197,7 @@ pub fn run() -> anyhow::Result<()> {
.map(|(key, value)| format!("{}=\"{}\"", key.to_string_lossy(), value.unwrap_or_default().to_string_lossy())) .map(|(key, value)| format!("{}=\"{}\"", key.to_string_lossy(), value.unwrap_or_default().to_string_lossy()))
.fold(String::new(), |acc, env| acc + " " + &env); .fold(String::new(), |acc, env| acc + " " + &env);
tracing::info!("Running the game with command: {variables} bash -c \"{bash_chain}\""); tracing::info!("Running the game with command: {variables} bash -c \"{bash_command}\"");
command.current_dir(config.game.path).spawn()?.wait_with_output()?; command.current_dir(config.game.path).spawn()?.wait_with_output()?;