Skip to content

Commit

Permalink
Quick OpenXR hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
DaXcess committed Jun 2, 2024
1 parent 2425346 commit aa47a23
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 1.2.5

**Bug Fixes**:
- Fixed corrupt/unreadable OpenXR default runtimes preventing VR to launch properly

# 1.2.4

**Bug Fixes**:
Expand Down
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.4</Version>
<Version>1.2.5</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>12.0</LangVersion>
<Title>LethalCompanyVR</Title>
Expand Down
Binary file modified Resources/lethalcompanyvr
Binary file not shown.
2 changes: 1 addition & 1 deletion Source/Assets/AssetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static bool LoadAssets()
kofiImage = assetBundle.LoadAsset<Sprite>("Ko-Fi");
discordImage = assetBundle.LoadAsset<Sprite>("Discord");
warningImage = assetBundle.LoadAsset<Sprite>("Warning");
settingsImage = assetBundle.LoadAsset<Sprite>("lcsettings-icon");
settingsImage = assetBundle.LoadAsset<Sprite>("lcsettings-icon-2");

localVrMetarig = assetBundle.LoadAsset<RuntimeAnimatorController>("metarig");
remoteVrMetarig = assetBundle.LoadAsset<RuntimeAnimatorController>("metarigOtherPlayers");
Expand Down
15 changes: 9 additions & 6 deletions Source/OpenXR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -88,9 +89,9 @@ public static bool GetRuntimes(out Runtimes runtimes)
Default = file == defaultRuntimePath
});
}
catch
catch (Exception ex)
{
// ignore errors
Logger.LogWarning($"Failed to parse {file}: {ex.Message}. Runtime will not be used.");
}
}

Expand Down Expand Up @@ -141,7 +142,7 @@ public static bool GetActiveRuntimeVersion(out ushort major, out ushort minor, o

public class Runtimes(Runtime[] runtimes) : IReadOnlyCollection<Runtime>
{
public Runtime Default => runtimes.First(rt => rt.Default);
public Runtime? Default => runtimes.Select(rt => (Runtime?)rt).FirstOrDefault(rt => rt.Value.Default);
public int Count => runtimes.Length;

public bool TryGetRuntime(string name, out Runtime runtime)
Expand Down Expand Up @@ -218,8 +219,10 @@ public static bool InitializeXR()
return InitializeXR(null);
}

if (!GetRuntimes(out var runtimes))
if (!GetRuntimes(out var runtimes) || runtimes.Count == 0)
{
Logger.LogWarning("Failed to query runtimes, or no runtimes were found. Falling back to old behavior.");

// On failure, revert back to pre 1.2.4 behavior (Default runtime or the one specified by the config)
return InitializeXR(string.IsNullOrEmpty(Plugin.Config.OpenXRRuntimeFile.Value)
? null
Expand Down Expand Up @@ -247,9 +250,9 @@ public static bool InitializeXR()
}

// Make sure the default runtime is first (unless it's the override which already failed at this point)
if (runtimes.Default.Path != Plugin.Config.OpenXRRuntimeFile.Value)
if (runtimes.Default is {} @default && @default.Path != Plugin.Config.OpenXRRuntimeFile.Value)
{
if (InitializeXR(runtimes.Default))
if (InitializeXR(@default))
return true;
}

Expand Down
3 changes: 1 addition & 2 deletions Source/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.SceneManagement;
using UnityEngine.XR.Interaction.Toolkit.UI;

using DependencyFlags = BepInEx.BepInDependency.DependencyFlags;

Expand All @@ -29,7 +28,7 @@ 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.4";
public const string PLUGIN_VERSION = "1.2.5";

private readonly string[] GAME_ASSEMBLY_HASHES =
[
Expand Down

0 comments on commit aa47a23

Please sign in to comment.