Skip to content

Commit

Permalink
Fix invalid OpenXR config breaking settings
Browse files Browse the repository at this point in the history
  • Loading branch information
DaXcess committed Mar 25, 2024
1 parent 665910e commit 8c316df
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 26 deletions.
2 changes: 1 addition & 1 deletion LCVR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.1</TargetFramework>
<AssemblyName>LCVR</AssemblyName>
<Description>Collecting Scrap in VR</Description>
<Version>1.2.0</Version>
<Version>1.2.1</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>12.0</LangVersion>
<Title>LethalCompanyVR</Title>
Expand Down
26 changes: 19 additions & 7 deletions Source/OpenXR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,27 @@ public static bool GetDiagnosticReport(out OpenXRReport report)

try
{
if (Native.RegOpenKeyEx(Native.HKEY_LOCAL_MACHINE, "SOFTWARE\\Khronos\\OpenXR\\1", 0, 0x20019, out hKey) != 0)
return null;
if (Native.RegOpenKeyEx(Native.HKEY_LOCAL_MACHINE, "SOFTWARE\\Khronos\\OpenXR\\1", 0, 0x20019, out hKey) !=
0)
throw new Exception("Failed to open registry key HKLM\\SOFTWARE\\Khronos\\OpenXR\\1");

if (Native.RegQueryValueEx(hKey, "ActiveRuntime", 0, out var type, null, ref cbData) != 0)
return null;
throw new Exception("Failed to query ActiveRuntime value");

var data = new StringBuilder((int)cbData);

if (Native.RegQueryValueEx(hKey, "ActiveRuntime", 0, out type, data, ref cbData) != 0)
return null;
throw new Exception("Failed to query ActiveRuntime value");

var path = data.ToString();
@default = JsonConvert.DeserializeObject<OpenXRRuntime>(File.ReadAllText(path)).runtime.name;

if (Native.RegOpenKeyEx(hKey, "AvailableRuntimes", 0, 0x20019, out hKey) != 0)
return null;
throw new Exception("Failed to open AvailableRuntimes registry key");

if (Native.RegQueryInfoKey(hKey, null, IntPtr.Zero, IntPtr.Zero, out _, out _, out _, out var valueCount, out var maxValueNameLength, out _, IntPtr.Zero, IntPtr.Zero) != 0)
return null;
if (Native.RegQueryInfoKey(hKey, null, IntPtr.Zero, IntPtr.Zero, out _, out _, out _, out var valueCount,
out var maxValueNameLength, out _, IntPtr.Zero, IntPtr.Zero) != 0)
throw new Exception("Failed to query AvailableRuntimes registry key");

var values = new List<string>();

Expand All @@ -136,7 +138,17 @@ public static bool GetDiagnosticReport(out OpenXRReport report)

foreach (var file in values)
{
var i = 0;

var name = JsonConvert.DeserializeObject<OpenXRRuntime>(File.ReadAllText(file)).runtime.name;
var resultName = name;

while (list.ContainsKey(resultName))
{
i++;
resultName = $"{name} ({i})";
}


list.Add(name, file);
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public class Plugin : BaseUnityPlugin
{
public const string PLUGIN_GUID = "io.daxcess.lcvr";
public const string PLUGIN_NAME = "LCVR";
public const string PLUGIN_VERSION = "1.2.0";
public const string PLUGIN_VERSION = "1.2.1";

private readonly string[] GAME_ASSEMBLY_HASHES = [
"3EE687F8586F8597BA9E750E5C75141CA353C0076A3FC3C802AE9CE35D876580" // V49
];

public static new Config Config { get; private set; }
public new static Config Config { get; private set; }
public static Compat Compatibility { get; private set; }
public static Flags Flags { get; private set; } = 0;

Expand Down
35 changes: 19 additions & 16 deletions Source/UI/Settings/SettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public class SettingsManager : MonoBehaviour

private bool isInitializing = true;

void Awake()
private void Awake()
{
menuManager = FindObjectOfType<MenuManager>();
}

void Start()
private void Start()
{
isInitializing = true;

Expand All @@ -52,18 +52,23 @@ void Start()

// Set up OpenXR settings section
var runtimes = OpenXR.DetectOpenXRRuntimes(out _);
var selectedIndex = 0;

if (!string.IsNullOrEmpty(Plugin.Config.OpenXRRuntimeFile.Value))
for (var i = 0; i < runtimes.Count; i++)
if (runtimes.ElementAt(i).Value == Plugin.Config.OpenXRRuntimeFile.Value)
{
selectedIndex = i + 1;
break;
}
if (runtimes != null)
{
var selectedIndex = 0;

if (!string.IsNullOrEmpty(Plugin.Config.OpenXRRuntimeFile.Value))
for (var i = 0; i < runtimes.Count; i++)
if (runtimes.ElementAt(i).Value == Plugin.Config.OpenXRRuntimeFile.Value)
{
selectedIndex = i + 1;
break;
}

runtimesDropdown.AddOptions([$"System Default", .. runtimes.Keys]);
runtimesDropdown.value = selectedIndex;
runtimesDropdown.AddOptions(["System Default", .. runtimes.Keys]);
runtimesDropdown.value = selectedIndex;
} else
runtimesDropdown.AddOptions(["System Default"]);

// Dynamically add sections for other settings

Expand All @@ -84,7 +89,7 @@ void Start()
list.Add(entry);
}

foreach ((var category, var settings) in categories)
foreach (var (category, settings) in categories)
{
var categoryObject = Instantiate(categoryTemplate, content);
categoryObject.GetComponentInChildren<TextMeshProUGUI>().text = category;
Expand Down Expand Up @@ -115,7 +120,7 @@ void Start()
dropdown.AddOptions([.. names]);
dropdown.SetValueWithoutNotify(idx);
}
else if (config.SettingType == typeof(float) && config.Description.AcceptableValues is AcceptableValueRange<float>)
else if (config.SettingType == typeof(float) && config.Description.AcceptableValues is AcceptableValueRange<float> values)
{
var sliderOption = Instantiate(sliderTemplate, categoryObject.transform);
var title = sliderOption.GetComponentInChildren<TextMeshProUGUI>();
Expand All @@ -130,8 +135,6 @@ void Start()
entry.category = category;
entry.name = name;

var values = config.Description.AcceptableValues as AcceptableValueRange<float>;

slider.maxValue = values.MaxValue;
slider.minValue = values.MinValue;
slider.SetValueWithoutNotify((float)config.BoxedValue);
Expand Down

0 comments on commit 8c316df

Please sign in to comment.