Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-Implement -vrmode from OpenVR for use within OpenXR #105

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 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 Down Expand Up @@ -84,6 +85,8 @@ internal static void Main(string[] args)
GameVersionEarly.Load();
SelfConfig.Instance.CheckVersionBoundary();

SetOpenXRRuntime(arguments);

// updates backup
InstallBootstrapPatch();

Expand All @@ -102,6 +105,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
Loading