From 05374459be7e3e042f638c944f007a2aebb07d67 Mon Sep 17 00:00:00 2001
From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com>
Date: Wed, 17 May 2023 12:06:48 -0500
Subject: [PATCH] [DesktopVRSwitch] - > DesktopXRSwitch
---
DesktopVRSwitch/DesktopVRSwitch.csproj | 2 -
DesktopVRSwitch/DesktopVRSwitcher.cs | 141 -----------------
.../Patches/VRModeSwitchTracker.cs | 45 ------
.../Patches/VRTrackerManagerTracker.cs | 31 ----
DesktopXRSwitch/DesktopXRSwitch.csproj | 8 +
DesktopXRSwitch/DesktopXRSwitcher.cs | 135 +++++++++++++++++
.../HarmonyPatches.cs | 39 +----
{DesktopVRSwitch => DesktopXRSwitch}/Main.cs | 11 +-
.../Patches/CVRPickupObjectTracker.cs | 10 +-
.../Patches/CameraFacingObjectTracker.cs | 9 +-
.../Patches/IKSystemTracker.cs | 38 ++---
.../Patches/MovementSystemTracker.cs | 16 +-
DesktopXRSwitch/Patches/PlayerSetupTracker.cs | 142 ++++++++++++++++++
.../Patches/ReferenceCameraPatch.cs | 4 +-
.../Patches/VRModeSwitchTracker.cs | 45 ++++++
.../Properties/AssemblyInfo.cs | 17 +--
.../TryCatchHell.cs | 84 ++++++-----
.../format.json | 8 +-
Directory.Build.props | 4 +
NAK_CVR_Mods.sln | 2 +-
nstrip_copy_stuff.ps1 | 2 +-
21 files changed, 441 insertions(+), 352 deletions(-)
delete mode 100644 DesktopVRSwitch/DesktopVRSwitch.csproj
delete mode 100644 DesktopVRSwitch/DesktopVRSwitcher.cs
delete mode 100644 DesktopVRSwitch/Patches/VRModeSwitchTracker.cs
delete mode 100644 DesktopVRSwitch/Patches/VRTrackerManagerTracker.cs
create mode 100644 DesktopXRSwitch/DesktopXRSwitch.csproj
create mode 100644 DesktopXRSwitch/DesktopXRSwitcher.cs
rename {DesktopVRSwitch => DesktopXRSwitch}/HarmonyPatches.cs (65%)
rename {DesktopVRSwitch => DesktopXRSwitch}/Main.cs (86%)
rename {DesktopVRSwitch => DesktopXRSwitch}/Patches/CVRPickupObjectTracker.cs (71%)
rename {DesktopVRSwitch => DesktopXRSwitch}/Patches/CameraFacingObjectTracker.cs (61%)
rename {DesktopVRSwitch => DesktopXRSwitch}/Patches/IKSystemTracker.cs (58%)
rename {DesktopVRSwitch => DesktopXRSwitch}/Patches/MovementSystemTracker.cs (75%)
create mode 100644 DesktopXRSwitch/Patches/PlayerSetupTracker.cs
rename {DesktopVRSwitch => DesktopXRSwitch}/Patches/ReferenceCameraPatch.cs (97%)
create mode 100644 DesktopXRSwitch/Patches/VRModeSwitchTracker.cs
rename {DesktopVRSwitch => DesktopXRSwitch}/Properties/AssemblyInfo.cs (61%)
rename {DesktopVRSwitch => DesktopXRSwitch}/TryCatchHell.cs (64%)
rename {DesktopVRSwitch => DesktopXRSwitch}/format.json (55%)
diff --git a/DesktopVRSwitch/DesktopVRSwitch.csproj b/DesktopVRSwitch/DesktopVRSwitch.csproj
deleted file mode 100644
index 66a50a8..0000000
--- a/DesktopVRSwitch/DesktopVRSwitch.csproj
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
diff --git a/DesktopVRSwitch/DesktopVRSwitcher.cs b/DesktopVRSwitch/DesktopVRSwitcher.cs
deleted file mode 100644
index b0f5397..0000000
--- a/DesktopVRSwitch/DesktopVRSwitcher.cs
+++ /dev/null
@@ -1,141 +0,0 @@
-using NAK.DesktopVRSwitch.Patches;
-using System.Collections;
-using UnityEngine;
-using UnityEngine.XR;
-using Valve.VR;
-
-namespace NAK.DesktopVRSwitch;
-
-public class DesktopVRSwitcher : MonoBehaviour
-{
- //Debug Settings
- public bool _reloadLocalAvatar = true;
- public bool _softVRSwitch = false;
-
- //Internal Stuff
- private bool _switchInProgress = false;
-
- void Start()
- {
- //do not pause game, this breaks dynbones & trackers
- SteamVR_Settings.instance.pauseGameWhenDashboardVisible = false;
- }
-
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.F6) && Input.GetKey(KeyCode.LeftControl))
- {
- SwitchVRMode();
- }
- }
-
- public void SwitchVRMode()
- {
- if (_switchInProgress) return;
- if (!IsInVR())
- {
- StartCoroutine(StartVRSystem());
- }
- else
- {
- StartCoroutine(StopVR());
- }
- }
-
- public bool IsInVR() => XRSettings.enabled;
-
- private IEnumerator StartVRSystem()
- {
-
- PreVRModeSwitch(true);
- XRSettings.LoadDeviceByName("OpenVR");
- yield return null; //wait a frame before checking
- if (!string.IsNullOrEmpty(XRSettings.loadedDeviceName))
- {
- DesktopVRSwitch.Logger.Msg("Starting SteamVR...");
- XRSettings.enabled = true;
- //force steamvr to reinitialize input
- //this does SteamVR_Input.actionSets[0].Activate() for us (we deactivate in StopVR())
- //but only if SteamVR_Settings.instance.activateFirstActionSetOnStart is enabled
- //which in ChilloutVR, it is, because all those settings are default
- SteamVR_Input.Initialize(true);
- yield return null;
- PostVRModeSwitch(true);
- yield break;
- }
- DesktopVRSwitch.Logger.Error("Initializing VR Failed. Is there no VR device connected?");
- FailedVRModeSwitch(true);
- yield break;
- }
-
- private IEnumerator StopVR()
- {
- PreVRModeSwitch(false);
- yield return null;
- if (!string.IsNullOrEmpty(XRSettings.loadedDeviceName))
- {
- //SteamVR.SafeDispose(); //might fuck with SteamVRTrackingModule
- //deactivate the action set so SteamVR_Input.Initialize can reactivate
- SteamVR_Input.actionSets[0].Deactivate(SteamVR_Input_Sources.Any);
- XRSettings.LoadDeviceByName("");
- XRSettings.enabled = false;
- yield return null;
- Time.fixedDeltaTime = 0.02f; //reset physics time to Desktop default
- PostVRModeSwitch(false);
- yield break;
- }
- DesktopVRSwitch.Logger.Error("Attempted to exit VR without a VR device loaded.");
- FailedVRModeSwitch(false);
- yield break;
- }
-
- //one frame before switch attempt
- public void PreVRModeSwitch(bool enableVR)
- {
- if (_softVRSwitch) return;
- //let tracked objects know we are attempting to switch
- VRModeSwitchTracker.PreVRModeSwitch(enableVR);
- }
-
- //one frame after switch attempt
- public void FailedVRModeSwitch(bool enableVR)
- {
- if (_softVRSwitch) return;
- //let tracked objects know a switch failed
- VRModeSwitchTracker.FailVRModeSwitch(enableVR);
- }
-
- //one frame after switch attempt
- public void PostVRModeSwitch(bool enableVR)
- {
- if (_softVRSwitch) return;
- //close the menus
- TryCatchHell.CloseCohtmlMenus();
-
- //the base of VR checks
- TryCatchHell.SetCheckVR(enableVR);
- TryCatchHell.SetMetaPort(enableVR);
-
- //game basics for functional gameplay post switch
- TryCatchHell.RepositionCohtmlHud(enableVR);
- TryCatchHell.UpdateHudOperations(enableVR);
- TryCatchHell.DisableMirrorCanvas();
- TryCatchHell.SwitchActiveCameraRigs(enableVR);
- TryCatchHell.ResetCVRInputManager();
- TryCatchHell.UpdateRichPresence();
- TryCatchHell.UpdateGestureReconizerCam();
- TryCatchHell.UpdateMenuCoreData(enableVR);
-
- //let tracked objects know we switched
- VRModeSwitchTracker.PostVRModeSwitch(enableVR);
-
- //reload avatar by default, optional for debugging
- if (_reloadLocalAvatar)
- {
- TryCatchHell.ReloadLocalAvatar();
- }
-
- _switchInProgress = false;
- }
-}
-
diff --git a/DesktopVRSwitch/Patches/VRModeSwitchTracker.cs b/DesktopVRSwitch/Patches/VRModeSwitchTracker.cs
deleted file mode 100644
index 74822a0..0000000
--- a/DesktopVRSwitch/Patches/VRModeSwitchTracker.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-using ABI_RC.Core.Player;
-using UnityEngine;
-using UnityEngine.Events;
-
-namespace NAK.DesktopVRSwitch.Patches;
-
-public class VRModeSwitchTracker
-{
- public static event UnityAction OnPreVRModeSwitch;
- public static event UnityAction OnPostVRModeSwitch;
- public static event UnityAction OnFailVRModeSwitch;
-
- public static void PreVRModeSwitch(bool enableVR)
- {
- TryCatchHell.TryCatchWrapper(() =>
- {
- DesktopVRSwitch.Logger.Msg("Invoking VRModeSwitchTracker.OnPreVRModeSwitch.");
- Camera activeCamera = PlayerSetup.Instance.GetActiveCamera().GetComponent();
- VRModeSwitchTracker.OnPreVRModeSwitch?.Invoke(enableVR, activeCamera);
- },
- "Error while invoking VRModeSwitchTracker.OnPreVRModeSwitch. Did someone do a fucky?");
- }
-
- public static void PostVRModeSwitch(bool enableVR)
- {
- TryCatchHell.TryCatchWrapper(() =>
- {
- DesktopVRSwitch.Logger.Msg("Invoking VRModeSwitchTracker.OnPostVRModeSwitch.");
- Camera activeCamera = PlayerSetup.Instance.GetActiveCamera().GetComponent();
- VRModeSwitchTracker.OnPostVRModeSwitch?.Invoke(enableVR, activeCamera);
- },
- "Error while invoking VRModeSwitchTracker.OnPostVRModeSwitch. Did someone do a fucky?");
- }
-
- public static void FailVRModeSwitch(bool enableVR)
- {
- TryCatchHell.TryCatchWrapper(() =>
- {
- DesktopVRSwitch.Logger.Msg("Invoking VRModeSwitchTracker.OnFailVRModeSwitch.");
- Camera activeCamera = PlayerSetup.Instance.GetActiveCamera().GetComponent();
- VRModeSwitchTracker.OnFailVRModeSwitch?.Invoke(enableVR, activeCamera);
- },
- "Error while invoking OnFailVRModeSwitch.OnPreVRModeSwitch. Did someone do a fucky?");
- }
-}
\ No newline at end of file
diff --git a/DesktopVRSwitch/Patches/VRTrackerManagerTracker.cs b/DesktopVRSwitch/Patches/VRTrackerManagerTracker.cs
deleted file mode 100644
index 3cbaa46..0000000
--- a/DesktopVRSwitch/Patches/VRTrackerManagerTracker.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-using ABI_RC.Core.Player;
-using HarmonyLib;
-using UnityEngine;
-
-namespace NAK.DesktopVRSwitch.Patches;
-
-public class VRTrackerManagerTracker : MonoBehaviour
-{
- public VRTrackerManager vrTrackerManager;
-
- void Start()
- {
- vrTrackerManager = GetComponent();
- VRModeSwitchTracker.OnPostVRModeSwitch += PostVRModeSwitch;
- }
- void OnDestroy()
- {
- VRModeSwitchTracker.OnPostVRModeSwitch -= PostVRModeSwitch;
- }
-
- public void PostVRModeSwitch(bool enableVR, Camera activeCamera)
- {
- //force the VRTrackerManager to reset anything its stored
- //this makes it get correct Left/Right hand if entering VR with different controllers
- //or if you restarted SteamVR and controllers are now in swapped index
- vrTrackerManager.poses = null;
- vrTrackerManager.leftHand = null;
- vrTrackerManager.rightHand = null;
- vrTrackerManager.hasCheckedForKnuckles = false;
- }
-}
\ No newline at end of file
diff --git a/DesktopXRSwitch/DesktopXRSwitch.csproj b/DesktopXRSwitch/DesktopXRSwitch.csproj
new file mode 100644
index 0000000..6c60f6d
--- /dev/null
+++ b/DesktopXRSwitch/DesktopXRSwitch.csproj
@@ -0,0 +1,8 @@
+
+
+
+
+ ..\_ManagedLibs\Unity.XR.Management.dll
+
+
+
diff --git a/DesktopXRSwitch/DesktopXRSwitcher.cs b/DesktopXRSwitch/DesktopXRSwitcher.cs
new file mode 100644
index 0000000..54d8024
--- /dev/null
+++ b/DesktopXRSwitch/DesktopXRSwitcher.cs
@@ -0,0 +1,135 @@
+using NAK.Melons.DesktopXRSwitch.Patches;
+using System.Collections;
+using UnityEngine;
+using UnityEngine.XR.Management;
+using Valve.VR;
+
+namespace NAK.Melons.DesktopXRSwitch;
+
+public class DesktopXRSwitcher : MonoBehaviour
+{
+ //Debug Settings
+ public bool _reloadLocalAvatar = true;
+ public bool _softVRSwitch = false;
+
+ //Internal Stuff
+ private bool _switchInProgress = false;
+
+ void Start()
+ {
+ //do not pause game, this breaks dynbones & trackers
+ SteamVR_Settings.instance.pauseGameWhenDashboardVisible = false;
+ }
+
+ void Update()
+ {
+ if (Input.GetKeyDown(KeyCode.F6) && Input.GetKey(KeyCode.LeftControl))
+ {
+ SwitchXRMode();
+ }
+ }
+
+ public void SwitchXRMode()
+ {
+ if (_switchInProgress) return;
+ if (!IsInXR())
+ {
+ StartCoroutine(StartXRSystem());
+ }
+ else
+ {
+ StartCoroutine(StopXR());
+ }
+ }
+
+ public bool IsInXR() => XRGeneralSettings.Instance.Manager.activeLoader != null;
+
+ private IEnumerator StartXRSystem()
+ {
+ PreXRModeSwitch(true);
+ yield return null;
+ yield return XRGeneralSettings.Instance.Manager.InitializeLoader();
+ if (XRGeneralSettings.Instance.Manager.activeLoader != null)
+ {
+ DesktopXRSwitch.Logger.Msg("Starting OpenXR...");
+ XRGeneralSettings.Instance.Manager.StartSubsystems();
+ yield return null;
+ PostXRModeSwitch(true);
+ yield break;
+ }
+ DesktopXRSwitch.Logger.Error("Initializing XR Failed. Is there no XR device connected?");
+ FailedVRModeSwitch(true);
+ yield break;
+ }
+
+ private IEnumerator StopXR()
+ {
+ PreXRModeSwitch(false);
+ yield return null;
+ if (XRGeneralSettings.Instance.Manager.isInitializationComplete)
+ {
+ XRGeneralSettings.Instance.Manager.StopSubsystems();
+ XRGeneralSettings.Instance.Manager.DeinitializeLoader();
+ yield return null;
+ PostXRModeSwitch(false);
+ yield break;
+ }
+ DesktopXRSwitch.Logger.Error("Attempted to exit VR without a VR device loaded.");
+ FailedVRModeSwitch(false);
+ yield break;
+ }
+
+ //one frame after switch attempt
+ public void FailedVRModeSwitch(bool isXR)
+ {
+ if (_softVRSwitch) return;
+ //let tracked objects know a switch failed
+ XRModeSwitchTracker.FailXRModeSwitch(isXR);
+ }
+
+ //one frame before switch attempt
+ public void PreXRModeSwitch(bool isXR)
+ {
+ if (_softVRSwitch) return;
+ //let tracked objects know we are attempting to switch
+ XRModeSwitchTracker.PreXRModeSwitch(isXR);
+ }
+
+ //one frame after switch attempt
+ public void PostXRModeSwitch(bool isXR)
+ {
+ if (_softVRSwitch) return;
+
+ //close the menus
+ TryCatchHell.CloseCohtmlMenus();
+
+ //the base of VR checks
+ TryCatchHell.SetCheckVR(isXR);
+ TryCatchHell.SetMetaPort(isXR);
+
+ //game basics for functional gameplay post switch
+ TryCatchHell.RepositionCohtmlHud(isXR);
+ TryCatchHell.UpdateHudOperations(isXR);
+ TryCatchHell.DisableMirrorCanvas();
+ TryCatchHell.SwitchActiveCameraRigs(isXR);
+ TryCatchHell.SwitchCVRInputManager(isXR);
+ TryCatchHell.UpdateRichPresence();
+ TryCatchHell.UpdateGestureReconizerCam();
+
+ //let tracked objects know we switched
+ XRModeSwitchTracker.PostXRModeSwitch(isXR);
+
+ //reload avatar by default, optional for debugging
+ if (_reloadLocalAvatar)
+ {
+ TryCatchHell.ReloadLocalAvatar();
+ }
+ else
+ {
+
+ }
+
+ _switchInProgress = false;
+ }
+}
+
diff --git a/DesktopVRSwitch/HarmonyPatches.cs b/DesktopXRSwitch/HarmonyPatches.cs
similarity index 65%
rename from DesktopVRSwitch/HarmonyPatches.cs
rename to DesktopXRSwitch/HarmonyPatches.cs
index 30c4f8d..0af879a 100644
--- a/DesktopVRSwitch/HarmonyPatches.cs
+++ b/DesktopXRSwitch/HarmonyPatches.cs
@@ -3,13 +3,12 @@ using ABI_RC.Core.Player;
using ABI_RC.Core.Savior;
using ABI_RC.Core.Util.Object_Behaviour;
using ABI_RC.Systems.IK;
-using ABI_RC.Systems.IK.TrackingModules;
using ABI_RC.Systems.MovementSystem;
using HarmonyLib;
-using NAK.DesktopVRSwitch.Patches;
+using NAK.Melons.DesktopXRSwitch.Patches;
using UnityEngine;
-namespace NAK.DesktopVRSwitch.HarmonyPatches;
+namespace NAK.Melons.DesktopXRSwitch.HarmonyPatches;
internal class PlayerSetupPatches
{
@@ -17,13 +16,14 @@ internal class PlayerSetupPatches
[HarmonyPatch(typeof(PlayerSetup), "Start")]
private static void Postfix_PlayerSetup_Start(ref PlayerSetup __instance)
{
+ __instance.gameObject.AddComponent();
if (CheckVR.Instance != null)
{
- CheckVR.Instance.gameObject.AddComponent();
+ CheckVR.Instance.gameObject.AddComponent();
return;
}
- __instance.gameObject.AddComponent();
- DesktopVRSwitch.Logger.Error("CheckVR not found. Reverting to fallback method. This should never happen!");
+ __instance.gameObject.AddComponent();
+ DesktopXRSwitch.Logger.Error("CheckVR not found. Reverting to fallback method. This should never happen!");
}
}
@@ -90,31 +90,4 @@ internal class IKSystemPatches
{
__instance.gameObject.AddComponent();
}
-
- [HarmonyPostfix] //lazy fix so i dont need to wait few frames
- [HarmonyPatch(typeof(TrackingPoint), "Initialize")]
- private static void Postfix_TrackingPoint_Initialize(ref TrackingPoint __instance)
- {
- __instance.referenceTransform.localScale = Vector3.one;
- }
- [HarmonyPostfix] //lazy fix so device indecies can change properly
- [HarmonyPatch(typeof(SteamVRTrackingModule), "ModuleDestroy")]
- private static void Postfix_SteamVRTrackingModule_ModuleDestroy(ref SteamVRTrackingModule __instance)
- {
- for (int i = 0; i < __instance.TrackingPoints.Count; i++)
- {
- UnityEngine.Object.Destroy(__instance.TrackingPoints[i].referenceGameObject);
- }
- __instance.TrackingPoints.Clear();
- }
-}
-
-internal class VRTrackerManagerPatches
-{
- [HarmonyPostfix]
- [HarmonyPatch(typeof(VRTrackerManager), "Start")]
- private static void Postfix_VRTrackerManager_Start(ref VRTrackerManager __instance)
- {
- __instance.gameObject.AddComponent();
- }
}
\ No newline at end of file
diff --git a/DesktopVRSwitch/Main.cs b/DesktopXRSwitch/Main.cs
similarity index 86%
rename from DesktopVRSwitch/Main.cs
rename to DesktopXRSwitch/Main.cs
index 64ec989..2673a53 100644
--- a/DesktopVRSwitch/Main.cs
+++ b/DesktopXRSwitch/Main.cs
@@ -9,18 +9,18 @@
It is also just in case other mods break or tweak functionality that
could fuck with switching. Or if they try to detect switching and break...
- The VRModeSwitchTracker system is also built so I can easily & quickly make adjustments to
+ The XRModeSwitchTracker system is also built so I can easily & quickly make adjustments to
components that may or may not change between builds without breaking the rest of the mod.
**/
-namespace NAK.DesktopVRSwitch;
+namespace NAK.Melons.DesktopXRSwitch;
-public class DesktopVRSwitch : MelonMod
+public class DesktopXRSwitch : MelonMod
{
internal static MelonLogger.Instance Logger;
-
+
public static readonly MelonPreferences_Category Category =
- MelonPreferences.CreateCategory(nameof(DesktopVRSwitch));
+ MelonPreferences.CreateCategory(nameof(DesktopXRSwitch));
public static readonly MelonPreferences_Entry EntryEnterCalibrationOnSwitch =
Category.CreateEntry("Enter Calibration on Switch", true, description: "Should you automatically be placed into calibration after switch if FBT is available? Overridden by Save Calibration IK setting.");
@@ -34,7 +34,6 @@ public class DesktopVRSwitch : MelonMod
ApplyPatches(typeof(HarmonyPatches.CameraFacingObjectPatches));
ApplyPatches(typeof(HarmonyPatches.IKSystemPatches));
ApplyPatches(typeof(HarmonyPatches.MovementSystemPatches));
- ApplyPatches(typeof(HarmonyPatches.VRTrackerManagerPatches));
}
private void ApplyPatches(Type type)
diff --git a/DesktopVRSwitch/Patches/CVRPickupObjectTracker.cs b/DesktopXRSwitch/Patches/CVRPickupObjectTracker.cs
similarity index 71%
rename from DesktopVRSwitch/Patches/CVRPickupObjectTracker.cs
rename to DesktopXRSwitch/Patches/CVRPickupObjectTracker.cs
index f37acd1..95a4d69 100644
--- a/DesktopVRSwitch/Patches/CVRPickupObjectTracker.cs
+++ b/DesktopXRSwitch/Patches/CVRPickupObjectTracker.cs
@@ -3,7 +3,7 @@ using UnityEngine;
//Thanks Ben! I was scared of transpiler so I reworked a bit...
-namespace NAK.DesktopVRSwitch.Patches;
+namespace NAK.Melons.DesktopXRSwitch.Patches;
public class CVRPickupObjectTracker : MonoBehaviour
{
@@ -12,15 +12,15 @@ public class CVRPickupObjectTracker : MonoBehaviour
void Start()
{
- VRModeSwitchTracker.OnPostVRModeSwitch += PostVRModeSwitch;
+ XRModeSwitchTracker.OnPostXRModeSwitch += PostXRModeSwitch;
}
void OnDestroy()
{
- VRModeSwitchTracker.OnPostVRModeSwitch -= PostVRModeSwitch;
+ XRModeSwitchTracker.OnPostXRModeSwitch -= PostXRModeSwitch;
}
- public void PostVRModeSwitch(bool enableVR, Camera activeCamera)
+ public void PostXRModeSwitch(bool isXR, Camera activeCamera)
{
if (pickupObject != null)
{
@@ -28,4 +28,4 @@ public class CVRPickupObjectTracker : MonoBehaviour
(storedGripOrigin, pickupObject.gripOrigin) = (pickupObject.gripOrigin, storedGripOrigin);
}
}
-}
+}
\ No newline at end of file
diff --git a/DesktopVRSwitch/Patches/CameraFacingObjectTracker.cs b/DesktopXRSwitch/Patches/CameraFacingObjectTracker.cs
similarity index 61%
rename from DesktopVRSwitch/Patches/CameraFacingObjectTracker.cs
rename to DesktopXRSwitch/Patches/CameraFacingObjectTracker.cs
index 89bb90e..32ebbd0 100644
--- a/DesktopVRSwitch/Patches/CameraFacingObjectTracker.cs
+++ b/DesktopXRSwitch/Patches/CameraFacingObjectTracker.cs
@@ -1,24 +1,23 @@
using ABI_RC.Core.Util.Object_Behaviour;
using UnityEngine;
-namespace NAK.DesktopVRSwitch.Patches;
+namespace NAK.Melons.DesktopXRSwitch.Patches;
public class CameraFacingObjectTracker : MonoBehaviour
{
public CameraFacingObject cameraFacingObject;
-
void Start()
{
cameraFacingObject = GetComponent();
- VRModeSwitchTracker.OnPostVRModeSwitch += PostVRModeSwitch;
+ XRModeSwitchTracker.OnPostXRModeSwitch += PostXRModeSwitch;
}
void OnDestroy()
{
- VRModeSwitchTracker.OnPostVRModeSwitch -= PostVRModeSwitch;
+ XRModeSwitchTracker.OnPostXRModeSwitch -= PostXRModeSwitch;
}
- public void PostVRModeSwitch(bool enableVR, Camera activeCamera)
+ public void PostXRModeSwitch(bool isXR, Camera activeCamera)
{
cameraFacingObject.m_Camera = activeCamera;
}
diff --git a/DesktopVRSwitch/Patches/IKSystemTracker.cs b/DesktopXRSwitch/Patches/IKSystemTracker.cs
similarity index 58%
rename from DesktopVRSwitch/Patches/IKSystemTracker.cs
rename to DesktopXRSwitch/Patches/IKSystemTracker.cs
index 36d8c0c..672cfbf 100644
--- a/DesktopVRSwitch/Patches/IKSystemTracker.cs
+++ b/DesktopXRSwitch/Patches/IKSystemTracker.cs
@@ -3,7 +3,7 @@ using ABI_RC.Systems.IK.SubSystems;
using ABI_RC.Systems.IK.TrackingModules;
using UnityEngine;
-namespace NAK.DesktopVRSwitch.Patches;
+namespace NAK.Melons.DesktopXRSwitch.Patches;
public class IKSystemTracker : MonoBehaviour
{
@@ -12,18 +12,18 @@ public class IKSystemTracker : MonoBehaviour
void Start()
{
ikSystem = GetComponent();
- VRModeSwitchTracker.OnPreVRModeSwitch += PreVRModeSwitch;
- VRModeSwitchTracker.OnFailVRModeSwitch += FailedVRModeSwitch;
- VRModeSwitchTracker.OnPostVRModeSwitch += PostVRModeSwitch;
+ XRModeSwitchTracker.OnPreXRModeSwitch += PreXRModeSwitch;
+ XRModeSwitchTracker.OnFailXRModeSwitch += FailedXRModeSwitch;
+ XRModeSwitchTracker.OnPostXRModeSwitch += PostXRModeSwitch;
}
void OnDestroy()
{
- VRModeSwitchTracker.OnPreVRModeSwitch -= PreVRModeSwitch;
- VRModeSwitchTracker.OnFailVRModeSwitch -= FailedVRModeSwitch;
- VRModeSwitchTracker.OnPostVRModeSwitch -= PostVRModeSwitch;
+ XRModeSwitchTracker.OnPreXRModeSwitch -= PreXRModeSwitch;
+ XRModeSwitchTracker.OnFailXRModeSwitch -= FailedXRModeSwitch;
+ XRModeSwitchTracker.OnPostXRModeSwitch -= PostXRModeSwitch;
}
- public void PreVRModeSwitch(bool enableVR, Camera activeCamera)
+ public void PreXRModeSwitch(bool inXR, Camera activeCamera)
{
BodySystem.TrackingEnabled = false;
BodySystem.TrackingPositionWeight = 0f;
@@ -32,7 +32,7 @@ public class IKSystemTracker : MonoBehaviour
IKSystem.vrik.enabled = false;
}
- public void FailedVRModeSwitch(bool enableVR, Camera activeCamera)
+ public void FailedXRModeSwitch(bool inXR, Camera activeCamera)
{
BodySystem.TrackingEnabled = true;
BodySystem.TrackingPositionWeight = 1f;
@@ -41,7 +41,7 @@ public class IKSystemTracker : MonoBehaviour
IKSystem.vrik.enabled = true;
}
- public void PostVRModeSwitch(bool enableVR, Camera activeCamera)
+ public void PostXRModeSwitch(bool inXR, Camera activeCamera)
{
if (IKSystem.vrik != null)
DestroyImmediate(IKSystem.vrik);
@@ -54,33 +54,35 @@ public class IKSystemTracker : MonoBehaviour
BodySystem.isCalibrating = false;
BodySystem.isRecalibration = false;
//make it so you dont instantly end up in FBT from Desktop
- IKSystem.firstAvatarLoaded = DesktopVRSwitch.EntryEnterCalibrationOnSwitch.Value;
+ IKSystem.firstAvatarLoaded = DesktopXRSwitch.EntryEnterCalibrationOnSwitch.Value;
//turn of finger tracking just in case user switched controllers
ikSystem.FingerSystem.controlActive = false;
//vrik should be deleted by avatar switch
- SetupSteamVRTrackingModule(enableVR);
+ SetupOpenXRTrackingModule(inXR);
}
- void SetupSteamVRTrackingModule(bool enableVR)
+ void SetupOpenXRTrackingModule(bool enableVR)
{
- var openVRModule = ikSystem._trackingModules.OfType().FirstOrDefault();
+ var openXRTrackingModule = ikSystem._trackingModules.OfType().FirstOrDefault();
- if (openVRModule != null)
+ if (openXRTrackingModule != null)
{
if (enableVR)
{
- openVRModule.ModuleStart();
+ openXRTrackingModule.ModuleStart();
}
else
{
- openVRModule.ModuleDestroy();
+ openXRTrackingModule.ModuleDestroy();
+ if (openXRTrackingModule != null)
+ ikSystem._trackingModules.Remove(openXRTrackingModule);
}
}
else if (enableVR)
{
- var newVRModule = new SteamVRTrackingModule();
+ var newVRModule = new OpenXRTrackingModule();
ikSystem.AddTrackingModule(newVRModule);
}
}
diff --git a/DesktopVRSwitch/Patches/MovementSystemTracker.cs b/DesktopXRSwitch/Patches/MovementSystemTracker.cs
similarity index 75%
rename from DesktopVRSwitch/Patches/MovementSystemTracker.cs
rename to DesktopXRSwitch/Patches/MovementSystemTracker.cs
index ddfed75..1ab61ad 100644
--- a/DesktopVRSwitch/Patches/MovementSystemTracker.cs
+++ b/DesktopXRSwitch/Patches/MovementSystemTracker.cs
@@ -1,7 +1,7 @@
using ABI_RC.Systems.MovementSystem;
using UnityEngine;
-namespace NAK.DesktopVRSwitch.Patches;
+namespace NAK.Melons.DesktopXRSwitch.Patches;
public class MovementSystemTracker : MonoBehaviour
{
@@ -12,17 +12,17 @@ public class MovementSystemTracker : MonoBehaviour
void Start()
{
movementSystem = GetComponent();
- VRModeSwitchTracker.OnPreVRModeSwitch += PreVRModeSwitch;
- VRModeSwitchTracker.OnPostVRModeSwitch += PostVRModeSwitch;
+ XRModeSwitchTracker.OnPreXRModeSwitch += PreXRModeSwitch;
+ XRModeSwitchTracker.OnPostXRModeSwitch += PostXRModeSwitch;
}
void OnDestroy()
{
- VRModeSwitchTracker.OnPreVRModeSwitch -= PreVRModeSwitch;
- VRModeSwitchTracker.OnPostVRModeSwitch -= PostVRModeSwitch;
+ XRModeSwitchTracker.OnPreXRModeSwitch -= PreXRModeSwitch;
+ XRModeSwitchTracker.OnPostXRModeSwitch -= PostXRModeSwitch;
}
- public void PreVRModeSwitch(bool enableVR, Camera activeCamera)
+ public void PreXRModeSwitch(bool isXR, Camera activeCamera)
{
//correct rotationPivot y position, so we dont teleport up/down
Vector3 position = movementSystem.rotationPivot.transform.position;
@@ -39,14 +39,14 @@ public class MovementSystemTracker : MonoBehaviour
movementSystem.ChangeProne(false);
}
- public void PostVRModeSwitch(bool enableVR, Camera activeCamera)
+ public void PostXRModeSwitch(bool isXR, Camera activeCamera)
{
//immediatly update camera to new camera transform
movementSystem.rotationPivot = activeCamera.transform;
//lazy way of correcting Desktop & VR offset issue (game does the maths)
movementSystem.TeleportToPosRot(preSwitchWorldPosition, preSwitchWorldRotation, false);
//recenter desktop collision to player object
- if (!enableVR) movementSystem.UpdateColliderCenter(movementSystem.transform.position);
+ if (!isXR) movementSystem.UpdateColliderCenter(movementSystem.transform.position);
movementSystem.ChangeCrouch(false);
movementSystem.ChangeProne(false);
diff --git a/DesktopXRSwitch/Patches/PlayerSetupTracker.cs b/DesktopXRSwitch/Patches/PlayerSetupTracker.cs
new file mode 100644
index 0000000..481b071
--- /dev/null
+++ b/DesktopXRSwitch/Patches/PlayerSetupTracker.cs
@@ -0,0 +1,142 @@
+using ABI.CCK.Components;
+using ABI_RC.Core.Base;
+using ABI_RC.Core.Player;
+using ABI_RC.Systems.IK;
+using HarmonyLib;
+using RootMotion.FinalIK;
+using System.Reflection;
+using UnityEngine;
+
+namespace NAK.Melons.DesktopXRSwitch.Patches;
+
+public class PlayerSetupTracker : MonoBehaviour
+{
+ public static PlayerSetupTracker Instance;
+ public PlayerSetup playerSetup;
+
+ public Traverse _initialCameraPosTraverse;
+ public Traverse _lookIKTraverse;
+ public Traverse _lastScaleTraverse;
+
+ public HumanPose avatarInitialHumanPose;
+ public HumanPoseHandler avatarHumanPoseHandler;
+
+ public GameObject avatarObject;
+ public CVRAvatar avatarDescriptor;
+ public Animator avatarAnimator;
+ public Vector3 initialPosition;
+ public Quaternion initialRotation;
+
+ void Start()
+ {
+ Instance = this;
+ playerSetup = GetComponent();
+ _initialCameraPosTraverse = Traverse.Create(playerSetup).Field("initialCameraPos");
+ _lookIKTraverse = Traverse.Create(playerSetup).Field("lookIK");
+ _lastScaleTraverse = Traverse.Create(playerSetup).Field("lastScale");
+ }
+
+ public void OnSetupAvatar(GameObject avatar)
+ {
+ avatarObject = avatar;
+ avatarDescriptor = avatarObject.GetComponent();
+ avatarAnimator = avatarObject.GetComponent();
+ initialPosition = avatarObject.transform.localPosition;
+ initialRotation = avatarObject.transform.localRotation;
+ if (avatarHumanPoseHandler == null)
+ {
+ avatarHumanPoseHandler = new HumanPoseHandler(avatarAnimator.avatar, avatarAnimator.transform);
+ }
+ avatarHumanPoseHandler.GetHumanPose(ref avatarInitialHumanPose);
+ }
+
+ public void OnClearAvatar()
+ {
+ avatarObject = null;
+ avatarDescriptor = null;
+ avatarAnimator = null;
+ initialPosition = Vector3.one;
+ initialRotation = Quaternion.identity;
+ avatarHumanPoseHandler = null;
+ }
+
+ public void ConfigureAvatarIK(bool isVR)
+ {
+ bool StateOnDisable = avatarAnimator.keepAnimatorStateOnDisable;
+ avatarAnimator.keepAnimatorStateOnDisable = true;
+ avatarAnimator.enabled = false;
+
+ //reset avatar offsets
+ avatarObject.transform.localPosition = initialPosition;
+ avatarObject.transform.localRotation = initialRotation;
+ avatarHumanPoseHandler.SetHumanPose(ref avatarInitialHumanPose);
+
+ if (isVR)
+ {
+ SwitchAvatarVr();
+ }
+ else
+ {
+ SwitchAvatarDesktop();
+ }
+
+ //lazy fix
+ _lastScaleTraverse.SetValue(Vector3.zero);
+ MethodInfo setPlaySpaceScaleMethod = playerSetup.GetType().GetMethod("CheckUpdateAvatarScaleToPlaySpaceRelation", BindingFlags.NonPublic | BindingFlags.Instance);
+ setPlaySpaceScaleMethod.Invoke(playerSetup, null);
+
+ avatarAnimator.keepAnimatorStateOnDisable = StateOnDisable;
+ avatarAnimator.enabled = true;
+ }
+
+ private void SwitchAvatarVr()
+ {
+ if (avatarDescriptor == null) return;
+
+ //remove LookAtIK if found
+ LookAtIK avatarLookAtIK = avatarObject.GetComponent();
+ if (avatarLookAtIK != null) DestroyImmediate(avatarLookAtIK);
+
+ //have IKSystem set up avatar for VR
+ //a good chunk of IKSystem initialization checks for existing
+ //stuff & if it is set up, so game is ready to handle it
+ if (avatarAnimator != null && avatarAnimator.isHuman)
+ {
+ IKSystem.Instance.InitializeAvatar(avatarDescriptor);
+ }
+ }
+
+ private void SwitchAvatarDesktop()
+ {
+ if (avatarDescriptor == null) return;
+
+ //remove VRIK & VRIKRootController if found
+ VRIK avatarVRIK = avatarObject.GetComponent();
+ VRIKRootController avatarVRIKRootController = avatarObject.GetComponent();
+ if (avatarVRIK != null) DestroyImmediate(avatarVRIK);
+ if (avatarVRIKRootController != null) DestroyImmediate(avatarVRIKRootController);
+
+ //remove all TwistRelaxer components
+ TwistRelaxer[] avatarTwistRelaxers = avatarObject.GetComponentsInChildren();
+ for (int i = 0; i < avatarTwistRelaxers.Length; i++)
+ {
+ DestroyImmediate(avatarTwistRelaxers[i]);
+ }
+
+ Transform headTransform = avatarAnimator.GetBoneTransform(HumanBodyBones.Head);
+ if (headTransform != null)
+ {
+ //set DesktopCameraRig to head bone pos
+ playerSetup.desktopCameraRig.transform.position = headTransform.position;
+ //add LookAtIK & Configure
+ LookAtIK lookAtIK = avatarObject.AddComponentIfMissing();
+ lookAtIK.solver.head = new IKSolverLookAt.LookAtBone(headTransform);
+ lookAtIK.solver.headWeight = 0.75f;
+ lookAtIK.solver.target = playerSetup.desktopCameraTarget.transform;
+ _lookIKTraverse.SetValue(lookAtIK);
+ }
+
+ //set camera position & initial position for headbob (both modes end up with same number)
+ playerSetup.desktopCamera.transform.localPosition = (Vector3)_initialCameraPosTraverse.GetValue();
+ }
+}
\ No newline at end of file
diff --git a/DesktopVRSwitch/Patches/ReferenceCameraPatch.cs b/DesktopXRSwitch/Patches/ReferenceCameraPatch.cs
similarity index 97%
rename from DesktopVRSwitch/Patches/ReferenceCameraPatch.cs
rename to DesktopXRSwitch/Patches/ReferenceCameraPatch.cs
index cb547e7..699f332 100644
--- a/DesktopVRSwitch/Patches/ReferenceCameraPatch.cs
+++ b/DesktopXRSwitch/Patches/ReferenceCameraPatch.cs
@@ -8,7 +8,7 @@ using UnityEngine.AzureSky;
using UnityEngine.Rendering.PostProcessing;
using Object = UnityEngine.Object;
-namespace NAK.DesktopVRSwitch.Patches;
+namespace NAK.Melons.DesktopXRSwitch.Patches;
internal class ReferenceCameraPatch
{
@@ -21,7 +21,7 @@ internal class ReferenceCameraPatch
internal static void CopyToInactiveCam(Camera activeCam, Camera inactiveCam)
{
- DesktopVRSwitch.Logger.Msg("Copying active camera settings & components to inactive camera.");
+ DesktopXRSwitch.Logger.Msg("Copying active camera settings & components to inactive camera.");
//steal basic settings
inactiveCam.farClipPlane = activeCam.farClipPlane;
diff --git a/DesktopXRSwitch/Patches/VRModeSwitchTracker.cs b/DesktopXRSwitch/Patches/VRModeSwitchTracker.cs
new file mode 100644
index 0000000..bbff203
--- /dev/null
+++ b/DesktopXRSwitch/Patches/VRModeSwitchTracker.cs
@@ -0,0 +1,45 @@
+using ABI_RC.Core.Player;
+using UnityEngine;
+using UnityEngine.Events;
+
+namespace NAK.Melons.DesktopXRSwitch.Patches;
+
+public class XRModeSwitchTracker
+{
+ public static event UnityAction OnPreXRModeSwitch;
+ public static event UnityAction OnPostXRModeSwitch;
+ public static event UnityAction OnFailXRModeSwitch;
+
+ public static void PreXRModeSwitch(bool isXR)
+ {
+ TryCatchHell.TryCatchWrapper(() =>
+ {
+ DesktopXRSwitch.Logger.Msg("Invoking XRModeSwitchTracker.OnPreXRModeSwitch.");
+ Camera activeCamera = PlayerSetup.Instance.GetActiveCamera().GetComponent();
+ XRModeSwitchTracker.OnPreXRModeSwitch?.Invoke(isXR, activeCamera);
+ },
+ "Error while invoking XRModeSwitchTracker.OnPreXRModeSwitch. Did someone do a fucky?");
+ }
+
+ public static void PostXRModeSwitch(bool isXR)
+ {
+ TryCatchHell.TryCatchWrapper(() =>
+ {
+ DesktopXRSwitch.Logger.Msg("Invoking XRModeSwitchTracker.OnPostXRModeSwitch.");
+ Camera activeCamera = PlayerSetup.Instance.GetActiveCamera().GetComponent();
+ XRModeSwitchTracker.OnPostXRModeSwitch?.Invoke(isXR, activeCamera);
+ },
+ "Error while invoking XRModeSwitchTracker.OnPostXRModeSwitch. Did someone do a fucky?");
+ }
+
+ public static void FailXRModeSwitch(bool isXR)
+ {
+ TryCatchHell.TryCatchWrapper(() =>
+ {
+ DesktopXRSwitch.Logger.Msg("Invoking XRModeSwitchTracker.OnFailXRModeSwitch.");
+ Camera activeCamera = PlayerSetup.Instance.GetActiveCamera().GetComponent();
+ XRModeSwitchTracker.OnFailXRModeSwitch?.Invoke(isXR, activeCamera);
+ },
+ "Error while invoking OnFailXRModeSwitch.OnPreXRModeSwitch. Did someone do a fucky?");
+ }
+}
\ No newline at end of file
diff --git a/DesktopVRSwitch/Properties/AssemblyInfo.cs b/DesktopXRSwitch/Properties/AssemblyInfo.cs
similarity index 61%
rename from DesktopVRSwitch/Properties/AssemblyInfo.cs
rename to DesktopXRSwitch/Properties/AssemblyInfo.cs
index fc680c0..3b57a43 100644
--- a/DesktopVRSwitch/Properties/AssemblyInfo.cs
+++ b/DesktopXRSwitch/Properties/AssemblyInfo.cs
@@ -1,31 +1,30 @@
using MelonLoader;
-using NAK.DesktopVRSwitch.Properties;
+using NAK.Melons.DesktopXRSwitch.Properties;
using System.Reflection;
[assembly: AssemblyVersion(AssemblyInfoParams.Version)]
[assembly: AssemblyFileVersion(AssemblyInfoParams.Version)]
[assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)]
-[assembly: AssemblyTitle(nameof(NAK.DesktopVRSwitch))]
+[assembly: AssemblyTitle(nameof(NAK.Melons.DesktopXRSwitch))]
[assembly: AssemblyCompany(AssemblyInfoParams.Author)]
-[assembly: AssemblyProduct(nameof(NAK.DesktopVRSwitch))]
+[assembly: AssemblyProduct(nameof(NAK.Melons.DesktopXRSwitch))]
[assembly: MelonInfo(
- typeof(NAK.DesktopVRSwitch.DesktopVRSwitch),
- nameof(NAK.DesktopVRSwitch),
+ typeof(NAK.Melons.DesktopXRSwitch.DesktopXRSwitch),
+ nameof(NAK.Melons.DesktopXRSwitch),
AssemblyInfoParams.Version,
AssemblyInfoParams.Author,
- downloadLink: "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/DesktopVRSwitch"
+ downloadLink: "https://github.com/NotAKidOnSteam/DesktopXRSwitch"
)]
[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")]
[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
-[assembly: MelonColor(ConsoleColor.DarkCyan)]
[assembly: HarmonyDontPatchAll]
-namespace NAK.DesktopVRSwitch.Properties;
+namespace NAK.Melons.DesktopXRSwitch.Properties;
internal static class AssemblyInfoParams
{
- public const string Version = "4.3.6";
+ public const string Version = "4.3.4";
public const string Author = "NotAKidoS";
}
\ No newline at end of file
diff --git a/DesktopVRSwitch/TryCatchHell.cs b/DesktopXRSwitch/TryCatchHell.cs
similarity index 64%
rename from DesktopVRSwitch/TryCatchHell.cs
rename to DesktopXRSwitch/TryCatchHell.cs
index 92ff333..bb94915 100644
--- a/DesktopVRSwitch/TryCatchHell.cs
+++ b/DesktopXRSwitch/TryCatchHell.cs
@@ -5,9 +5,12 @@ using ABI_RC.Core.Player;
using ABI_RC.Core.Savior;
using ABI_RC.Core.UI;
using ABI_RC.Systems.Camera;
+using ABI_RC.Systems.InputManagement;
+using ABI_RC.Systems.InputManagement.InputModules;
+using HarmonyLib;
using UnityEngine;
-namespace NAK.DesktopVRSwitch;
+namespace NAK.Melons.DesktopXRSwitch;
internal class TryCatchHell
{
@@ -19,8 +22,8 @@ internal class TryCatchHell
}
catch (Exception ex)
{
- DesktopVRSwitch.Logger.Error(string.Format(errorMsg, msgArgs));
- DesktopVRSwitch.Logger.Msg(ex.Message);
+ DesktopXRSwitch.Logger.Error(string.Format(errorMsg, msgArgs));
+ DesktopXRSwitch.Logger.Msg(ex.Message);
}
}
@@ -28,52 +31,52 @@ internal class TryCatchHell
{
TryCatchWrapper(() =>
{
- DesktopVRSwitch.Logger.Msg("Closing ViewManager & CVR_MenuManager menus.");
+ DesktopXRSwitch.Logger.Msg("Closing ViewManager & CVR_MenuManager menus.");
ViewManager.Instance.UiStateToggle(false);
CVR_MenuManager.Instance.ToggleQuickMenu(false);
},
"Setting CheckVR hasVrDeviceLoaded failed.");
}
- internal static void SetCheckVR(bool enableVR)
+ internal static void SetCheckVR(bool isXR)
{
TryCatchWrapper(() =>
{
- DesktopVRSwitch.Logger.Msg($"Setting CheckVR hasVrDeviceLoaded to {enableVR}.");
- CheckVR.Instance.hasVrDeviceLoaded = enableVR;
+ DesktopXRSwitch.Logger.Msg($"Setting CheckVR hasVrDeviceLoaded to {isXR}.");
+ CheckVR.Instance.hasVrDeviceLoaded = isXR;
},
"Setting CheckVR hasVrDeviceLoaded failed.");
}
- internal static void SetMetaPort(bool enableVR)
+ internal static void SetMetaPort(bool isXR)
{
TryCatchWrapper(() =>
{
- DesktopVRSwitch.Logger.Msg($"Setting MetaPort isUsingVr to {enableVR}.");
- MetaPort.Instance.isUsingVr = enableVR;
+ DesktopXRSwitch.Logger.Msg($"Setting MetaPort isUsingVr to {isXR}.");
+ MetaPort.Instance.isUsingVr = isXR;
},
"Setting MetaPort isUsingVr failed.");
}
- internal static void RepositionCohtmlHud(bool enableVR)
+ internal static void RepositionCohtmlHud(bool isXR)
{
TryCatchWrapper(() =>
{
- DesktopVRSwitch.Logger.Msg("Configuring new hud affinity for CohtmlHud.");
- CohtmlHud.Instance.gameObject.transform.parent = enableVR ? PlayerSetup.Instance.vrCamera.transform : PlayerSetup.Instance.desktopCamera.transform;
+ DesktopXRSwitch.Logger.Msg("Configuring new hud affinity for CohtmlHud.");
+ CohtmlHud.Instance.gameObject.transform.parent = isXR ? PlayerSetup.Instance.vrCamera.transform : PlayerSetup.Instance.desktopCamera.transform;
CVRTools.ConfigureHudAffinity();
CohtmlHud.Instance.gameObject.transform.localScale = new Vector3(1.2f, 1f, 1.2f);
},
"Error parenting CohtmlHud to active camera.");
}
- internal static void UpdateHudOperations(bool enableVR)
+ internal static void UpdateHudOperations(bool isXR)
{
TryCatchWrapper(() =>
{
- DesktopVRSwitch.Logger.Msg("Switching HudOperations worldLoadingItem & worldLoadStatus.");
- HudOperations.Instance.worldLoadingItem = enableVR ? HudOperations.Instance.worldLoadingItemVr : HudOperations.Instance.worldLoadingItemDesktop;
- HudOperations.Instance.worldLoadStatus = enableVR ? HudOperations.Instance.worldLoadStatusVr : HudOperations.Instance.worldLoadStatusDesktop;
+ DesktopXRSwitch.Logger.Msg("Switching HudOperations worldLoadingItem & worldLoadStatus.");
+ HudOperations.Instance.worldLoadingItem = isXR ? HudOperations.Instance.worldLoadingItemVr : HudOperations.Instance.worldLoadingItemDesktop;
+ HudOperations.Instance.worldLoadStatus = isXR ? HudOperations.Instance.worldLoadStatusVr : HudOperations.Instance.worldLoadStatusDesktop;
},
"Failed switching HudOperations objects.");
}
@@ -82,7 +85,7 @@ internal class TryCatchHell
{
TryCatchWrapper(() =>
{
- DesktopVRSwitch.Logger.Msg("Forcing PortableCamera canvas mirroring off.");
+ DesktopXRSwitch.Logger.Msg("Forcing PortableCamera canvas mirroring off.");
//tell the game we are in mirror mode so itll disable it (if enabled)
PortableCamera.Instance.mode = MirroringMode.Mirror;
PortableCamera.Instance.ChangeMirroring();
@@ -90,13 +93,13 @@ internal class TryCatchHell
"Failed to disable PortableCamera canvas mirroring.");
}
- internal static void SwitchActiveCameraRigs(bool enableVR)
+ internal static void SwitchActiveCameraRigs(bool isXR)
{
TryCatchWrapper(() =>
{
- DesktopVRSwitch.Logger.Msg("Switching active PlayerSetup camera rigs. Updating Desktop camera FOV.");
- PlayerSetup.Instance.desktopCameraRig.SetActive(!enableVR);
- PlayerSetup.Instance.vrCameraRig.SetActive(enableVR);
+ DesktopXRSwitch.Logger.Msg("Switching active PlayerSetup camera rigs. Updating Desktop camera FOV.");
+ PlayerSetup.Instance.desktopCameraRig.SetActive(!isXR);
+ PlayerSetup.Instance.vrCameraRig.SetActive(isXR);
CVR_DesktopCameraController.UpdateFov();
//uicamera has script that copies fov from desktop cam
//toggling the cameras on/off resets aspect ratio
@@ -109,18 +112,18 @@ internal class TryCatchHell
{
TryCatchWrapper(() =>
{
- DesktopVRSwitch.Logger.Msg($"Setting CVRInputManager inputEnabled & CVR_InteractableManager enableInteractions to {!toggle}");
+ DesktopXRSwitch.Logger.Msg($"Setting CVRInputManager inputEnabled & CVR_InteractableManager enableInteractions to {!toggle}");
CVRInputManager.Instance.inputEnabled = !toggle;
CVR_InteractableManager.enableInteractions = !toggle;
},
"Failed to toggle CVRInputManager inputEnabled & CVR_InteractableManager enableInteractions.");
}
- internal static void ResetCVRInputManager()
+ internal static void SwitchCVRInputManager(bool isXR)
{
TryCatchWrapper(() =>
{
- DesktopVRSwitch.Logger.Msg("Resetting CVRInputManager inputs.");
+ DesktopXRSwitch.Logger.Msg("Resetting CVRInputManager inputs.");
//just in case
CVRInputManager.Instance.blockedByUi = false;
//sometimes head can get stuck, so just in case
@@ -132,6 +135,15 @@ internal class TryCatchHell
CVRInputManager.Instance.gestureRightRaw = 0f;
//turn off finger tracking input
CVRInputManager.Instance.individualFingerTracking = false;
+
+ //add input module if you started in desktop
+ if (CVRInputManager._moduleOpenXR == null)
+ {
+ CVRInputManager.Instance.AddInputModule(CVRInputManager._moduleOpenXR = new CVRInputModule_OpenXR());
+ }
+
+ //enable xr input or whatnot
+ CVRInputManager._moduleOpenXR.InputEnabled = isXR;
},
"Failed to reset CVRInputManager inputs.");
}
@@ -140,7 +152,7 @@ internal class TryCatchHell
{
TryCatchWrapper(() =>
{
- DesktopVRSwitch.Logger.Msg("Attempting to reload current local avatar from GUID.");
+ DesktopXRSwitch.Logger.Msg("Attempting to reload current local avatar from GUID.");
AssetManagement.Instance.LoadLocalAvatar(MetaPort.Instance.currentAvatarGuid);
},
"Failed to reload local avatar.");
@@ -152,13 +164,13 @@ internal class TryCatchHell
{
if (MetaPort.Instance.settings.GetSettingsBool("ImplementationRichPresenceDiscordEnabled", true))
{
- DesktopVRSwitch.Logger.Msg("Forcing Discord Rich Presence update.");
+ DesktopXRSwitch.Logger.Msg("Forcing Discord Rich Presence update.");
MetaPort.Instance.settings.SetSettingsBool("ImplementationRichPresenceDiscordEnabled", false);
MetaPort.Instance.settings.SetSettingsBool("ImplementationRichPresenceDiscordEnabled", true);
}
if (MetaPort.Instance.settings.GetSettingsBool("ImplementationRichPresenceSteamEnabled", true))
{
- DesktopVRSwitch.Logger.Msg("Forcing Steam Rich Presence update.");
+ DesktopXRSwitch.Logger.Msg("Forcing Steam Rich Presence update.");
MetaPort.Instance.settings.SetSettingsBool("ImplementationRichPresenceSteamEnabled", false);
MetaPort.Instance.settings.SetSettingsBool("ImplementationRichPresenceSteamEnabled", true);
}
@@ -170,19 +182,9 @@ internal class TryCatchHell
{
TryCatchWrapper(() =>
{
- DesktopVRSwitch.Logger.Msg("Updating CVRGestureRecognizer _camera to active camera.");
- CVRGestureRecognizer.Instance._camera = PlayerSetup.Instance.GetActiveCamera().GetComponent();
+ DesktopXRSwitch.Logger.Msg("Updating CVRGestureRecognizer _camera to active camera.");
+ Traverse.Create(CVRGestureRecognizer.Instance).Field("_camera").SetValue(PlayerSetup.Instance.GetActiveCamera().GetComponent());
},
"Failed to update CVRGestureRecognizer camera.");
}
-
- internal static void UpdateMenuCoreData(bool enableVR)
- {
- TryCatchWrapper(() =>
- {
- DesktopVRSwitch.Logger.Msg("Updating CVR_Menu_Data core data.");
- CVR_MenuManager.Instance.coreData.core.inVr = enableVR;
- },
- "Failed to update CVR_Menu_Data core data.");
- }
-}
+}
\ No newline at end of file
diff --git a/DesktopVRSwitch/format.json b/DesktopXRSwitch/format.json
similarity index 55%
rename from DesktopVRSwitch/format.json
rename to DesktopXRSwitch/format.json
index 4920d1d..d9514e0 100644
--- a/DesktopVRSwitch/format.json
+++ b/DesktopXRSwitch/format.json
@@ -1,7 +1,7 @@
{
"_id": 103,
"name": "DesktopVRSwitch",
- "modversion": "4.3.5",
+ "modversion": "4.3.1",
"gameversion": "2022r170",
"loaderversion": "0.5.7",
"modtype": "Mod",
@@ -16,8 +16,8 @@
"requirements": [
"None"
],
- "downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r3/DesktopVRSwitch.dll",
- "sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/DesktopVRSwitch/",
- "changelog": "- Reinitialize SteamVR input on switch. Correct fixedDeltaTime when entering Desktop.\n- Tweak to initial switch position for correcting offsets.\n- Fixed FBT tracking point initial size.\n- Update core menu data so QM Recalibrate/SeatedPlay button works.",
+ "downloadlink": "https://github.com/NotAKidOnSteam/DesktopVRSwitch/releases/download/v4.3.1/DesktopVRSwitch.dll",
+ "sourcelink": "https://github.com/NotAKidOnSteam/DesktopVRSwitch/",
+ "changelog": "- Backported rewrite from Experimental & patched up to handle OpenVR.\n- Reinitialize SteamVR input on switch incase user restarted SteamVR or changed controllers. Correct fixedDeltaTime when entering Desktop.\n- Many tweaks to ensure everything in-game functions as expected.",
"embedcolor": "3498db"
}
\ No newline at end of file
diff --git a/Directory.Build.props b/Directory.Build.props
index 9c10455..543acd1 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -444,6 +444,10 @@
$(MsBuildThisFileDirectory)\_ManagedLibs\Unity.Entities.Hybrid.dll
False
+
+ $(MsBuildThisFileDirectory)\_ManagedLibs\Unity.InputSystem.dll
+ False
+
$(MsBuildThisFileDirectory)\_ManagedLibs\Unity.InternalAPIEngineBridge.003.dll
False
diff --git a/NAK_CVR_Mods.sln b/NAK_CVR_Mods.sln
index cc5c586..118dae9 100644
--- a/NAK_CVR_Mods.sln
+++ b/NAK_CVR_Mods.sln
@@ -19,7 +19,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CVRGizmos", "CVRGizmos\CVRG
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesktopVRIK", "DesktopVRIK\DesktopVRIK.csproj", "{CD33AB69-F9A4-4F32-B69A-473131F6393B}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesktopVRSwitch", "DesktopVRSwitch\DesktopVRSwitch.csproj", "{30F56FE1-1654-4213-A51C-4C0278FB43A6}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesktopXRSwitch", "DesktopXRSwitch\DesktopXRSwitch.csproj", "{30F56FE1-1654-4213-A51C-4C0278FB43A6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FuckMetrics", "FuckMetrics\FuckMetrics.csproj", "{55E805A5-404C-4BB9-9AF1-A432443B1424}"
EndProject
diff --git a/nstrip_copy_stuff.ps1 b/nstrip_copy_stuff.ps1
index 9d8420f..d42a4f6 100644
--- a/nstrip_copy_stuff.ps1
+++ b/nstrip_copy_stuff.ps1
@@ -121,7 +121,7 @@ else {
# Loop through each DLL file to strip and call NStrip.exe
foreach($dllFile in $dllsToStrip) {
$dllPath = Join-Path -Path $managedLibsFolder -ChildPath $dllFile
- & $nStripPath -p -n $dllPath $dllPath
+ & $nStripPath -p -cg -n $dllPath $dllPath
}
Write-Host ""