Skip to content

Commit

Permalink
Fix SteamVR not behaving properly when recentering is allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoco007 committed Nov 16, 2024
1 parent cdac839 commit 199896a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions SiraUtil/SiraUtil.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>$(BeatSaberDir)\Libs\0Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="BeatSaber.Init">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\BeatSaber.Init.dll</HintPath>
Expand Down Expand Up @@ -131,6 +132,10 @@
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Unity.XR.Management.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Unity.XR.OpenXR">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Unity.XR.OpenXR.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.dll</HintPath>
<Private>False</Private>
Expand Down
26 changes: 26 additions & 0 deletions SiraUtil/Tweaks/DisableOpenXRRecentering.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using HarmonyLib;
using UnityEngine.XR.OpenXR;

namespace SiraUtil.Tweaks
{
/// <summary>
/// This patch fixes an issue with SteamVR where Unity will decide to not use SteamVR's room center
/// and instead try to invent its own origin, often resulting in the headset being under the floor.
/// This tends to happen when using FPFCToggle.
/// </summary>
/// <remarks>
/// This post explains the various possible OpenXR tracking spaces: <see href="https://discussions.unity.com/t/how-to-recenter-in-openxr/935209/9"/>
/// </remarks>
[HarmonyPatch(typeof(OpenXRLoaderBase), nameof(OpenXRLoaderBase.Initialize))]
internal static class DisableOpenXRRecentering
{
private static void Postfix(ref bool __result)
{
if (__result && OpenXRRuntime.name == "SteamVR/OpenXR")
{
Plugin.Log.Info("Disabling recentering");
OpenXRSettings.SetAllowRecentering(false, 0);
}
}
}
}

0 comments on commit 199896a

Please sign in to comment.