From b2d4a5bb1c75aa65ce59fb0309ddbdda14a063f8 Mon Sep 17 00:00:00 2001 From: Rankyn Bass Date: Thu, 24 Oct 2024 20:36:35 -0700 Subject: [PATCH] Improve launcher and game launch logic * Don't hide the window/show deck prompt until ffxiv actually starts launching This saves several seconds of launcher disappearing and nothing happening * Don't show the deck prompt in XLM mode (no manual swap is needed) * Improve steam initialization: use SteamAppId, which is provided by whatever entry you use XLM on This allows for use on non-ffxiv entries for Steam regions without FFXIV --- .../Components/MainPage/MainPage.cs | 20 ++++---- .../CoreEnvironmentSettings.cs | 5 +- src/XIVLauncher.Core/Program.cs | 48 +++++++++---------- 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/XIVLauncher.Core/Components/MainPage/MainPage.cs b/src/XIVLauncher.Core/Components/MainPage/MainPage.cs index 69806061..73500b0d 100644 --- a/src/XIVLauncher.Core/Components/MainPage/MainPage.cs +++ b/src/XIVLauncher.Core/Components/MainPage/MainPage.cs @@ -821,15 +821,6 @@ public async Task StartGameAndAddon(Launcher.LoginResult loginResult, b throw new NotImplementedException(); } - if (!Program.IsSteamDeckHardware) - { - Hide(); - } - else - { - App.State = LauncherApp.LauncherState.SteamDeckPrompt; - } - // We won't do any sanity checks here anymore, since that should be handled in StartLogin var launchedProcess = App.Launcher.LaunchGame(runner, loginResult.UniqueId, @@ -842,6 +833,17 @@ public async Task StartGameAndAddon(Launcher.LoginResult loginResult, b App.Settings.IsEncryptArgs.GetValueOrDefault(true), App.Settings.DpiAwareness.GetValueOrDefault(DpiAwareness.Unaware)); + // Hide the launcher if not Steam Deck or if using as a compatibility tool (XLM) + // Show the Steam Deck prompt if on steam deck and not using as a compatibility tool + if (!Program.IsSteamDeckHardware || CoreEnvironmentSettings.IsSteamCompatTool) + { + Hide(); + } + else + { + App.State = LauncherApp.LauncherState.SteamDeckPrompt; + } + if (launchedProcess == null) { Log.Information("GameProcess was null..."); diff --git a/src/XIVLauncher.Core/CoreEnvironmentSettings.cs b/src/XIVLauncher.Core/CoreEnvironmentSettings.cs index b5975868..51c89987 100644 --- a/src/XIVLauncher.Core/CoreEnvironmentSettings.cs +++ b/src/XIVLauncher.Core/CoreEnvironmentSettings.cs @@ -16,7 +16,8 @@ public static class CoreEnvironmentSettings public static bool ClearAll => CheckEnvBool("XL_CLEAR_ALL"); public static bool? UseSteam => CheckEnvBoolOrNull("XL_USE_STEAM"); // Fix for Steam Deck users who lock themselves out public static bool IsSteamCompatTool => CheckEnvBool("XL_SCT"); - public static uint AltAppID => GetAltAppId(System.Environment.GetEnvironmentVariable("XL_APPID")); + public static uint SteamAppId => GetAppId(System.Environment.GetEnvironmentVariable("SteamAppId")); + public static uint AltAppID => GetAppId(System.Environment.GetEnvironmentVariable("XL_APPID")); private static bool CheckEnvBool(string key) { @@ -40,7 +41,7 @@ public static string GetCleanEnvironmentVariable(string envvar, string badstring return string.Join(separator, Array.FindAll(dirty.Split(separator, StringSplitOptions.RemoveEmptyEntries), s => !s.Contains(badstring))); } - public static uint GetAltAppId(string? appid) + public static uint GetAppId(string? appid) { uint.TryParse(appid, out var result); diff --git a/src/XIVLauncher.Core/Program.cs b/src/XIVLauncher.Core/Program.cs index 0961e656..e8d4c01e 100644 --- a/src/XIVLauncher.Core/Program.cs +++ b/src/XIVLauncher.Core/Program.cs @@ -198,29 +198,25 @@ private static void Main(string[] args) Loc.SetupWithFallbacks(); - uint appId, altId; - string appName, altName; - // AppId of 0 is invalid (though still a valid uint) - if (CoreEnvironmentSettings.AltAppID > 0) + Dictionary apps = new Dictionary(); + uint[] ignoredIds = { 0, STEAM_APP_ID, STEAM_APP_ID_FT}; + if (!ignoredIds.Contains(CoreEnvironmentSettings.SteamAppId)) { - appId = CoreEnvironmentSettings.AltAppID; - altId = STEAM_APP_ID_FT; - appName = $"Override AppId={appId.ToString()}"; - altName = "FFXIV Free Trial"; + apps.Add(CoreEnvironmentSettings.SteamAppId, "XLM"); } - else if (Config.IsFt == true) + if (!ignoredIds.Contains(CoreEnvironmentSettings.AltAppID)) { - appId = STEAM_APP_ID_FT; - altId = STEAM_APP_ID; - appName = "FFXIV Free Trial"; - altName = "FFXIV Retail"; + apps.Add(CoreEnvironmentSettings.AltAppID, "XL_APPID"); + } + if (Config.IsFt == true) + { + apps.Add(STEAM_APP_ID_FT, "FFXIV Free Trial"); + apps.Add(STEAM_APP_ID, "FFXIV Retail"); } else { - appId = STEAM_APP_ID; - altId = STEAM_APP_ID_FT; - appName = "FFXIV Retail"; - altName = "FFXIV Free Trial"; + apps.Add(STEAM_APP_ID, "FFXIV Retail"); + apps.Add(STEAM_APP_ID_FT, "FFXIV Free Trial"); } try { @@ -239,14 +235,18 @@ private static void Main(string[] args) } if (Config.IsIgnoringSteam != true || CoreEnvironmentSettings.IsSteamCompatTool) { - try - { - Steam.Initialize(appId); - } - catch (Exception ex) + foreach (var app in apps) { - Log.Error(ex, $"Couldn't init Steam with AppId={appId} ({appName}), trying AppId={altId} ({altName})"); - Steam.Initialize(altId); + try + { + Steam.Initialize(app.Key); + Log.Information($"Successfully initialized Steam entry {app.Key} - {app.Value}"); + break; + } + catch (Exception ex) + { + Log.Error(ex, $"Failed to initialize Steam Steam entry {app.Key} - {app.Value}"); + } } } }