diff --git a/lib/FFXIVQuickLauncher b/lib/FFXIVQuickLauncher index 77115d3f..8d992d08 160000 --- a/lib/FFXIVQuickLauncher +++ b/lib/FFXIVQuickLauncher @@ -1 +1 @@ -Subproject commit 77115d3f7d920179ce83f0708ec97ba2450ce795 +Subproject commit 8d992d08de5c807b76f0aed37a60910498369ece diff --git a/src/XIVLauncher.Core/Components/MainPage/MainPage.cs b/src/XIVLauncher.Core/Components/MainPage/MainPage.cs index cbb3fb42..76278ef7 100644 --- a/src/XIVLauncher.Core/Components/MainPage/MainPage.cs +++ b/src/XIVLauncher.Core/Components/MainPage/MainPage.cs @@ -758,6 +758,30 @@ public async Task StartGameAndAddon(Launcher.LoginResult loginResult, b { throw new NotImplementedException(); } + + if (!string.IsNullOrEmpty(Program.Config.BeforeScript)) + { + Log.Information($"Running pre-game script {Program.Config.BeforeScript}"); + var scriptProcess = runner.Run(Program.Config.BeforeScript, new FileInfo(Program.Config.BeforeScript).Directory?.FullName, "", + new Dictionary(), false); + if (Program.Config.WaitForBeforeScript ?? false) + { + App.StartLoading("Running pre-game script...", "Please wait"); + await (scriptProcess?.WaitForExitAsync()!).ConfigureAwait(false); + } + } + + if (Environment.OSVersion.Platform == PlatformID.Unix && !string.IsNullOrEmpty(Program.Config.BeforeScriptWine)) + { + Log.Information($"Running pre-game Wine script {Program.Config.BeforeScriptWine}"); + var scriptProcess = runner.Run(Program.Config.BeforeScriptWine, new FileInfo(Program.Config.BeforeScriptWine).Directory?.FullName, "", + new Dictionary(), true); + if (Program.Config.WaitForBeforeScriptWine ?? false) + { + App.StartLoading("Running pre-game Wine script...", "Please wait"); + await (scriptProcess?.WaitForExitAsync()!).ConfigureAwait(false); + } + } if (!Program.IsSteamDeckHardware) { @@ -816,6 +840,20 @@ public async Task StartGameAndAddon(Launcher.LoginResult loginResult, b throw; } + if (!string.IsNullOrEmpty(Program.Config.AfterScript)) + { + Log.Information($"Running post-game script {Program.Config.AfterScript}"); + runner.Run(Program.Config.AfterScript, new FileInfo(Program.Config.AfterScript).Directory?.FullName, "", + new Dictionary(), false); + } + + if (Environment.OSVersion.Platform == PlatformID.Unix && !string.IsNullOrEmpty(Program.Config.AfterScriptWine)) + { + Log.Information($"Running post-game script {Program.Config.AfterScriptWine}"); + runner.Run(Program.Config.AfterScriptWine, new FileInfo(Program.Config.AfterScriptWine).Directory?.FullName, "", + new Dictionary(), true); + } + Log.Debug("Waiting for game to exit"); await Task.Run(() => launchedProcess!.WaitForExit()).ConfigureAwait(false); diff --git a/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabAutoStart.cs b/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabAutoStart.cs index 0e57d99b..546fe89b 100644 --- a/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabAutoStart.cs +++ b/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabAutoStart.cs @@ -1,16 +1,42 @@ +using System.Runtime.InteropServices; using ImGuiNET; namespace XIVLauncher.Core.Components.SettingsPage.Tabs; public class SettingsTabAutoStart : SettingsTab { - public override SettingsEntry[] Entries { get; } = new SettingsEntry[] { }; + public override SettingsEntry[] Entries { get; } = new SettingsEntry[] + { + new SettingsEntry("Pre-game script", + "Set a script that should be executed before the game launches", + () => Program.Config.BeforeScript, s => Program.Config.BeforeScript = s), + new SettingsEntry("Wait for pre-game script", "Wait for the pre-game script before launching the game", + () => Program.Config.WaitForBeforeScript ?? false, s => Program.Config.WaitForBeforeScript = s), + new SettingsEntry("Pre-game Wine script", + "Set a script that should be executed in the Wine prefix before the game launches", + () => Program.Config.BeforeScriptWine, s => Program.Config.BeforeScriptWine = s) + { + CheckVisibility = () => RuntimeInformation.IsOSPlatform(OSPlatform.Linux) + }, + new SettingsEntry("Wait for pre-game Wine script", "Wait for the pre-game Wine script before launching the game", + () => Program.Config.WaitForBeforeScriptWine ?? false, s => Program.Config.WaitForBeforeScriptWine = s) + { + CheckVisibility = () => RuntimeInformation.IsOSPlatform(OSPlatform.Linux) + }, + new SettingsEntry("Post-game script", + "Set a script that should be executed after the game has launched", + () => Program.Config.AfterScript, s => Program.Config.AfterScript = s), + new SettingsEntry("Post-game Wine script", + "Set a script that should be executed in the Wine prefix after the game has launched", + () => Program.Config.AfterScriptWine, s => Program.Config.AfterScriptWine = s) + { + CheckVisibility = () => RuntimeInformation.IsOSPlatform(OSPlatform.Linux) + } + }; public override string Title => "Auto-Start"; public override void Draw() { - ImGui.Text("Please check back later."); - base.Draw(); } } \ No newline at end of file diff --git a/src/XIVLauncher.Core/Configuration/ILauncherConfig.cs b/src/XIVLauncher.Core/Configuration/ILauncherConfig.cs index 026666d8..3b39131f 100644 --- a/src/XIVLauncher.Core/Configuration/ILauncherConfig.cs +++ b/src/XIVLauncher.Core/Configuration/ILauncherConfig.cs @@ -89,4 +89,20 @@ public interface ILauncherConfig public int DalamudLoadDelay { get; set; } #endregion + + #region Auto-Start + + public string? BeforeScript { get; set; } + + public bool? WaitForBeforeScript { get; set; } + + public string? BeforeScriptWine { get; set; } + + public bool? WaitForBeforeScriptWine { get; set; } + + public string? AfterScript { get; set; } + + public string? AfterScriptWine { get; set; } + + #endregion } \ No newline at end of file diff --git a/src/XIVLauncher.Core/Program.cs b/src/XIVLauncher.Core/Program.cs index 0b5e842f..5170192d 100644 --- a/src/XIVLauncher.Core/Program.cs +++ b/src/XIVLauncher.Core/Program.cs @@ -115,6 +115,13 @@ private static void LoadConfig(Storage storage) Config.WineStartupType ??= WineStartupType.Managed; Config.WineBinaryPath ??= "/usr/bin"; Config.WineDebugVars ??= "-all"; + + Config.BeforeScript ??= ""; + Config.BeforeScriptWine ??= ""; + Config.WaitForBeforeScript ??= false; + Config.WaitForBeforeScriptWine ??= false; + Config.AfterScript ??= ""; + Config.AfterScriptWine ??= ""; } public const uint STEAM_APP_ID = 39210;