Skip to content

Commit

Permalink
Fix --graphics arg on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Popax21 committed Aug 12, 2023
1 parent 706ff6c commit 8eb1b61
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions Celeste.Mod.mm/Patches/Celeste.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using System.Text.RegularExpressions;
using System.Text;
using System.Reflection;
using System.Runtime.Versioning;
using System.ComponentModel;

namespace Celeste {
class patch_Celeste : Celeste {
Expand Down Expand Up @@ -194,30 +196,31 @@ private static void MainInner(string[] args) {
Everest.Shutdown();
}

[MonoModIgnore]
private static extern void ParseFNAArgs(string[] args);
private static void ParseFNAArgs(string[] args) {
// FNA's main function already does this, but it doesn't work on Linux because the runtime doesn't call setenv :catassault:

[MonoModReplace]
[MonoModIfFlag("DontRelinkXNA")]
[MonoModPatch("ParseFNAArgs")]
private static void ParseFNAArgs_FNA(string[] args) {
// FNA's main function already does this
}
static void SetEnvVar(string name, string value) {
Environment.SetEnvironmentVariable(name, value);

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
if (setenv(name, value, 1) != 0)
throw new Win32Exception();
}

[MonoModReplace]
[MonoModIfFlag("RelinkXNA")]
[MonoModPatch("ParseFNAArgs")]
private static void ParseFNAArgs_XNA(string[] args) {
Environment.SetEnvironmentVariable("FNA_AUDIO_DISABLE_SOUND", "1");
SetEnvVar("FNA_AUDIO_DISABLE_SOUND", "1");
for (int i = 0; i < args.Length; i++) {
if (args[i] == "--graphics" && i < args.Length - 1) {
Environment.SetEnvironmentVariable("FNA3D_FORCE_DRIVER", args[i + 1]);
SetEnvVar("FNA3D_FORCE_DRIVER", args[i + 1]);
i++;
} else if (args[i] == "--disable-lateswaptear")
Environment.SetEnvironmentVariable("FNA3D_DISABLE_LATESWAPTEAR", "1");
}
// No --disable-lateswaptear as that is now explicitly opt-in
}
}

[SupportedOSPlatform("linux")]
[DllImport("libc", CallingConvention=CallingConvention.Cdecl, SetLastError=true)]
private extern static int setenv(string name, string val, int overwrite);

private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs e) {
if (e.IsTerminating) {
_CriticalFailureIsUnhandledException = true;
Expand Down

0 comments on commit 8eb1b61

Please sign in to comment.