Skip to content

Commit

Permalink
Re-Implement -vrmode within OpenXR
Browse files Browse the repository at this point in the history
  • Loading branch information
ModdingPink committed Dec 16, 2024
1 parent a81bad9 commit ebe3ec9
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions IPA.Injector/Injector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using IPA.Loader;
using IPA.Logging;
using IPA.Utilities;
using Microsoft.Win32;
using Mono.Cecil;
using Mono.Cecil.Cil;
using System;
Expand All @@ -15,6 +16,7 @@
using System.Threading.Tasks;
using UnityEngine;
using static IPA.Logging.Logger;
using static UnityEngine.Scripting.GarbageCollector;
using MethodAttributes = Mono.Cecil.MethodAttributes;
#if NET3
using Net3_Proxy;
Expand Down Expand Up @@ -84,6 +86,8 @@ internal static void Main(string[] args)
GameVersionEarly.Load();
SelfConfig.Instance.CheckVersionBoundary();

SetOpenXRRuntime(arguments);

// updates backup
InstallBootstrapPatch();

Expand All @@ -102,6 +106,59 @@ internal static void Main(string[] args)
}
}

public static void SetOpenXRRuntime(string[] arguments)
{
if (arguments == null)
return;

string targetRuntime = string.Empty;

for (int i = 0; i < arguments.Length; i++)
{
if (arguments[i] == "-vrmode" && i + 1 < arguments.Length)
{
targetRuntime = arguments[i + 1];
break;
}
}

if (string.IsNullOrEmpty(targetRuntime))
return;

targetRuntime = targetRuntime.ToLower(System.Globalization.CultureInfo.CurrentCulture);

//This forces the OpenXRLoader to error as there is no OpenXR Runtime found, which is intentional as a mod can then select it
switch (targetRuntime)
{
case "none":
case "fpfc":
case "controllable":
Environment.SetEnvironmentVariable("XR_RUNTIME_JSON", targetRuntime); //By checking the env variable you can see what caused the override while still causing the fail
return;
}

string registryPath = @"SOFTWARE\Khronos\OpenXR\1\AvailableRuntimes";
RegistryKey baseKey = Registry.LocalMachine.OpenSubKey(registryPath);
string foundRuntime = string.Empty;
if (baseKey != null)
{
foreach (string valueName in baseKey.GetValueNames())
{
if (Path.GetFileNameWithoutExtension(valueName).ToLower().Contains(targetRuntime))
{
foundRuntime = valueName;
break;
}
}
baseKey.Close();
}

if(!string.IsNullOrEmpty(foundRuntime))
Environment.SetEnvironmentVariable("XR_RUNTIME_JSON", foundRuntime);

//This is not stored within CommandLineValues.Debug as you can check the environment variable
}

private static void MaybeInitializeConsole(string[] arguments)
{
var i = 0;
Expand Down

0 comments on commit ebe3ec9

Please sign in to comment.