From 98b4355b0e45f4d8fa81376da1021113653eaa31 Mon Sep 17 00:00:00 2001 From: Rankyn Bass Date: Sat, 27 Jul 2024 12:35:36 -0700 Subject: [PATCH 1/4] Add XL_APPID to allow alternate appid instead of Free Trial --- src/XIVLauncher.Core/CoreEnvironmentSettings.cs | 10 ++++++++++ src/XIVLauncher.Core/Program.cs | 9 ++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/XIVLauncher.Core/CoreEnvironmentSettings.cs b/src/XIVLauncher.Core/CoreEnvironmentSettings.cs index 0d067b25..c543c281 100644 --- a/src/XIVLauncher.Core/CoreEnvironmentSettings.cs +++ b/src/XIVLauncher.Core/CoreEnvironmentSettings.cs @@ -16,6 +16,7 @@ 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 int AltAppID => GetAltAppId(System.Environment.GetEnvironmentVariable("XL_APPID")); private static bool CheckEnvBool(string key) { @@ -39,6 +40,15 @@ 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 int GetAltAppId(string? appid) + { + int result; + if (int.TryParse(appid, out result)) + return result; + else + return -1; + } + public static string GetCType() { if (System.OperatingSystem.IsWindows()) diff --git a/src/XIVLauncher.Core/Program.cs b/src/XIVLauncher.Core/Program.cs index b37dabaa..b026c3ae 100644 --- a/src/XIVLauncher.Core/Program.cs +++ b/src/XIVLauncher.Core/Program.cs @@ -196,7 +196,14 @@ private static void Main(string[] args) uint appId, altId; string appName, altName; - if (Config.IsFt == true) + if (CoreEnvironmentSettings.AltAppID > 0) + { + appId = (uint)(int)CoreEnvironmentSettings.AltAppID; + altId = STEAM_APP_ID_FT; + appName = $"Override AppId={appId.ToString()}"; + altName = "FFXIV Free Trial"; + } + else if (Config.IsFt == true) { appId = STEAM_APP_ID_FT; altId = STEAM_APP_ID; From 221a5df13b0daa95731c1c8cad1107a7fcb478a9 Mon Sep 17 00:00:00 2001 From: Rankyn Bass Date: Sat, 27 Jul 2024 12:39:57 -0700 Subject: [PATCH 2/4] Get rid of redundant (int) cast --- src/XIVLauncher.Core/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/XIVLauncher.Core/Program.cs b/src/XIVLauncher.Core/Program.cs index b026c3ae..f32407e0 100644 --- a/src/XIVLauncher.Core/Program.cs +++ b/src/XIVLauncher.Core/Program.cs @@ -198,7 +198,7 @@ private static void Main(string[] args) string appName, altName; if (CoreEnvironmentSettings.AltAppID > 0) { - appId = (uint)(int)CoreEnvironmentSettings.AltAppID; + appId = (uint)CoreEnvironmentSettings.AltAppID; altId = STEAM_APP_ID_FT; appName = $"Override AppId={appId.ToString()}"; altName = "FFXIV Free Trial"; From c16b9d83c011e88e3c52cb644b831605056f18c7 Mon Sep 17 00:00:00 2001 From: Rankyn Bass Date: Sat, 27 Jul 2024 15:34:52 -0700 Subject: [PATCH 3/4] Simplify AppID logic --- src/XIVLauncher.Core/CoreEnvironmentSettings.cs | 14 +++++++------- src/XIVLauncher.Core/Program.cs | 3 ++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/XIVLauncher.Core/CoreEnvironmentSettings.cs b/src/XIVLauncher.Core/CoreEnvironmentSettings.cs index c543c281..3ecd7d54 100644 --- a/src/XIVLauncher.Core/CoreEnvironmentSettings.cs +++ b/src/XIVLauncher.Core/CoreEnvironmentSettings.cs @@ -16,7 +16,7 @@ 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 int AltAppID => GetAltAppId(System.Environment.GetEnvironmentVariable("XL_APPID")); + public static uint AltAppID => GetAltAppId(System.Environment.GetEnvironmentVariable("XL_APPID")); private static bool CheckEnvBool(string key) { @@ -40,13 +40,13 @@ 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 int GetAltAppId(string? appid) + public static uint GetAltAppId(string? appid) { - int result; - if (int.TryParse(appid, out result)) - return result; - else - return -1; + uint result; + uint.TryParse(appid, out result); + + // Will return 0 if appid is invalid (or zero). + return result; } public static string GetCType() diff --git a/src/XIVLauncher.Core/Program.cs b/src/XIVLauncher.Core/Program.cs index f32407e0..6a169c2a 100644 --- a/src/XIVLauncher.Core/Program.cs +++ b/src/XIVLauncher.Core/Program.cs @@ -196,9 +196,10 @@ private static void Main(string[] args) uint appId, altId; string appName, altName; + // AppId of 0 is invalid (though still a valid uint) if (CoreEnvironmentSettings.AltAppID > 0) { - appId = (uint)CoreEnvironmentSettings.AltAppID; + appId = CoreEnvironmentSettings.AltAppID; altId = STEAM_APP_ID_FT; appName = $"Override AppId={appId.ToString()}"; altName = "FFXIV Free Trial"; From 5cb374aff2c62afe2ed6c6c593e6196d27b833d2 Mon Sep 17 00:00:00 2001 From: Rankyn Bass Date: Sat, 27 Jul 2024 16:11:13 -0700 Subject: [PATCH 4/4] Some more cleanup --- src/XIVLauncher.Core/CoreEnvironmentSettings.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/XIVLauncher.Core/CoreEnvironmentSettings.cs b/src/XIVLauncher.Core/CoreEnvironmentSettings.cs index 3ecd7d54..b5975868 100644 --- a/src/XIVLauncher.Core/CoreEnvironmentSettings.cs +++ b/src/XIVLauncher.Core/CoreEnvironmentSettings.cs @@ -42,8 +42,7 @@ public static string GetCleanEnvironmentVariable(string envvar, string badstring public static uint GetAltAppId(string? appid) { - uint result; - uint.TryParse(appid, out result); + uint.TryParse(appid, out var result); // Will return 0 if appid is invalid (or zero). return result;