From 30cadef34b18a86f5d9d9e8693073bf1f4983ea7 Mon Sep 17 00:00:00 2001 From: Kaz Wolfe Date: Mon, 24 Mar 2025 09:12:13 -0700 Subject: [PATCH] fix: support XL_PLATFORM as well (hopefully) --- Dalamud.Common/Util/EnvironmentUtils.cs | 18 ++++++++++++++++++ Dalamud.Injector/EntryPoint.cs | 6 ++++++ 2 files changed, 24 insertions(+) create mode 100644 Dalamud.Common/Util/EnvironmentUtils.cs diff --git a/Dalamud.Common/Util/EnvironmentUtils.cs b/Dalamud.Common/Util/EnvironmentUtils.cs new file mode 100644 index 000000000..d6cf65e3d --- /dev/null +++ b/Dalamud.Common/Util/EnvironmentUtils.cs @@ -0,0 +1,18 @@ +using System.Diagnostics.CodeAnalysis; + +namespace Dalamud.Common.Util; + +public static class EnvironmentUtils +{ + /// + /// Attempts to get an environment variable using the Try pattern. + /// + /// The env var to get. + /// An output containing the env var, if present. + /// A boolean indicating whether the var was present. + public static bool TryGetEnvironmentVariable(string variableName, [NotNullWhen(true)] out string? value) + { + value = Environment.GetEnvironmentVariable(variableName); + return value != null; + } +} diff --git a/Dalamud.Injector/EntryPoint.cs b/Dalamud.Injector/EntryPoint.cs index 0ee2e5507..4d26313a9 100644 --- a/Dalamud.Injector/EntryPoint.cs +++ b/Dalamud.Injector/EntryPoint.cs @@ -11,6 +11,8 @@ using System.Text.RegularExpressions; using Dalamud.Common; using Dalamud.Common.Game; +using Dalamud.Common.Util; + using Newtonsoft.Json; using Reloaded.Memory.Buffers; using Serilog; @@ -311,6 +313,10 @@ namespace Dalamud.Injector var unhandledExceptionStr = startInfo.UnhandledException.ToString().ToLowerInvariant(); var troubleshootingData = "{\"empty\": true, \"description\": \"No troubleshooting data supplied.\"}"; + // env vars are brought in prior to launch args, since args can override them. + if (EnvironmentUtils.TryGetEnvironmentVariable("XL_PLATFORM", out var xlPlatformEnv)) + platformStr = xlPlatformEnv.ToLowerInvariant(); + for (var i = 2; i < args.Count; i++) { if (args[i].StartsWith(key = "--dalamud-working-directory="))