Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement auto-start for pre- and post-game launch #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/XIVLauncher.Core/Components/MainPage/MainPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,30 @@ public async Task<Process> 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<string, string>(), 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<string, string>(), true);
if (Program.Config.WaitForBeforeScriptWine ?? false)
{
App.StartLoading("Running pre-game Wine script...", "Please wait");
await (scriptProcess?.WaitForExitAsync()!).ConfigureAwait(false);
}
}

if (!Program.IsSteamDeckHardware)
{
Expand Down Expand Up @@ -816,6 +840,20 @@ public async Task<Process> 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<string, string>(), 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<string, string>(), true);
}

Log.Debug("Waiting for game to exit");

await Task.Run(() => launchedProcess!.WaitForExit()).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<string>("Pre-game script",
"Set a script that should be executed before the game launches",
() => Program.Config.BeforeScript, s => Program.Config.BeforeScript = s),
new SettingsEntry<bool>("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<string>("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<bool>("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<string>("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<string>("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();
}
}
16 changes: 16 additions & 0 deletions src/XIVLauncher.Core/Configuration/ILauncherConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
7 changes: 7 additions & 0 deletions src/XIVLauncher.Core/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down