From 6b32a6475d6ba1e9ed0654a192fcdeae713e4bb1 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Sat, 23 Sep 2023 19:35:46 -0500 Subject: [PATCH] [DesktopVRSwitch] Fixes for 2023r172. --- DesktopVRSwitch/HarmonyPatches.cs | 26 ----------------- DesktopVRSwitch/Main.cs | 3 -- .../DestroySteamVRInstancesImmediate.cs | 29 +++++++++++++++++++ .../VRModeTrackers/CVRInputManagerTracker.cs | 18 +++++++----- DesktopVRSwitch/XRHandler.cs | 1 + DesktopVRSwitch/format.json | 4 +-- 6 files changed, 43 insertions(+), 38 deletions(-) create mode 100644 DesktopVRSwitch/Patches/DestroySteamVRInstancesImmediate.cs diff --git a/DesktopVRSwitch/HarmonyPatches.cs b/DesktopVRSwitch/HarmonyPatches.cs index f17d1f3..e32f5ca 100644 --- a/DesktopVRSwitch/HarmonyPatches.cs +++ b/DesktopVRSwitch/HarmonyPatches.cs @@ -118,32 +118,6 @@ internal class CVRPickupObjectPatches } } -internal class CohtmlUISystemPatches -{ - [HarmonyPrefix] - [HarmonyPatch(typeof(UISystem), nameof(UISystem.RegisterGamepad), typeof(uint), typeof(string), typeof(uint), typeof(uint), typeof(IntPtr))] - [HarmonyPatch(typeof(UISystem), nameof(UISystem.RegisterGamepad), typeof(uint), typeof(string), typeof(uint), typeof(uint))] - [HarmonyPatch(typeof(UISystem), nameof(UISystem.UpdateGamepadState), typeof(cohtml.GamepadState))] - [HarmonyPatch(typeof(UISystem), nameof(UISystem.UpdateGamepadState), typeof(uint), typeof(float[]), typeof(float[]))] - [HarmonyPatch(typeof(UISystem), nameof(UISystem.UnregisterGamepad))] - [HarmonyPatch(typeof(UISystem), nameof(UISystem.UpdateGamepadStateExtended))] - private static bool Prefix_UISystem_FuckOff() - { - /** - GameFace Version 1.34.0.4 – released 10 Nov 2022 - Fixed a crash when registering and unregistering gamepads - Fix Fixed setting a gamepad object when creating GamepadEvent from JavaScript - Fix Fixed a crash when unregistering a gamepad twice - Fix Fixed a GamepadEvent related crash during garbage collector tracing - - it is not fixed you fucking piece of shit - **/ - - // dont - return false; - } -} - internal class SteamVRBehaviourPatches { [HarmonyPrefix] diff --git a/DesktopVRSwitch/Main.cs b/DesktopVRSwitch/Main.cs index 47671f8..572acb0 100644 --- a/DesktopVRSwitch/Main.cs +++ b/DesktopVRSwitch/Main.cs @@ -26,9 +26,6 @@ public class DesktopVRSwitch : MelonMod // post processing fixes ApplyPatches(typeof(HarmonyPatches.CVRWorldPatches)); - // fuck you - ApplyPatches(typeof(HarmonyPatches.CohtmlUISystemPatches)); - // prevent steamvr behaviour from closing game ApplyPatches(typeof(HarmonyPatches.SteamVRBehaviourPatches)); diff --git a/DesktopVRSwitch/Patches/DestroySteamVRInstancesImmediate.cs b/DesktopVRSwitch/Patches/DestroySteamVRInstancesImmediate.cs new file mode 100644 index 0000000..bb6e9e5 --- /dev/null +++ b/DesktopVRSwitch/Patches/DestroySteamVRInstancesImmediate.cs @@ -0,0 +1,29 @@ +using ABI_RC.Systems.IK; +using ABI_RC.Systems.IK.TrackingModules; +using ABI_RC.Systems.InputManagement; +using ABI_RC.Systems.InputManagement.XR.Modules; + +namespace NAK.DesktopVRSwitch.Patches; + +internal static class SteamVRNullReferencePatch +{ + public static void DestroySteamVRInstancesImmediate() + { + // set to null so input manager doesnt attempt to access it + if (CVRInputManager._moduleXR != null) + { + if (CVRInputManager._moduleXR._leftModule != null) + if (CVRInputManager._moduleXR._leftModule is CVRXRModule_SteamVR leftModule) leftModule._steamVr = null; + if (CVRInputManager._moduleXR._rightModule != null) + if (CVRInputManager._moduleXR._rightModule is CVRXRModule_SteamVR rightModule) rightModule._steamVr = null; + } + + if (IKSystem.Instance == null) + return; + + // set to null so tracking module doesnt attempt to access it + foreach (TrackingModule module in IKSystem.Instance._trackingModules) + if (module is SteamVRTrackingModule steamVRModule) + steamVRModule._steamVr = null; + } +} \ No newline at end of file diff --git a/DesktopVRSwitch/VRModeTrackers/CVRInputManagerTracker.cs b/DesktopVRSwitch/VRModeTrackers/CVRInputManagerTracker.cs index b5caf88..eb504e0 100644 --- a/DesktopVRSwitch/VRModeTrackers/CVRInputManagerTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/CVRInputManagerTracker.cs @@ -25,13 +25,6 @@ public class CVRInputManagerTracker : VRModeTracker // IM CRYING //CVRInputManager.Instance.reload = true; - - // set to null so input manager doesnt attempt to access it - if (CVRInputManager._moduleXR._leftModule != null) - if (CVRInputManager._moduleXR._leftModule is CVRXRModule_SteamVR leftModule) leftModule._steamVr = null; - - if (CVRInputManager._moduleXR._rightModule != null) - if (CVRInputManager._moduleXR._rightModule is CVRXRModule_SteamVR rightModule) rightModule._steamVr = null; // TODO: MOVE THIS TO DIFFERENT TRACKER RootLogic.Instance.ToggleMouse(args.IsUsingVr); @@ -50,7 +43,18 @@ public class CVRInputManagerTracker : VRModeTracker //add input module if you started in desktop if (CVRInputManager._moduleXR == null) + { CVRInputManager.Instance.AddInputModule(CVRInputManager._moduleXR = new CVRInputModule_XR()); + } + else + { + // set to null so input manager doesnt attempt to access it + + if (CVRInputManager._moduleXR._leftModule != null) + if (CVRInputManager._moduleXR._leftModule is CVRXRModule_SteamVR leftModule) leftModule._steamVr = null; + if (CVRInputManager._moduleXR._rightModule != null) + if (CVRInputManager._moduleXR._rightModule is CVRXRModule_SteamVR rightModule) rightModule._steamVr = null; + } //enable xr input or whatnot CVRInputManager._moduleXR.InputEnabled = args.IsUsingVr; diff --git a/DesktopVRSwitch/XRHandler.cs b/DesktopVRSwitch/XRHandler.cs index 149cd9f..d1219bf 100644 --- a/DesktopVRSwitch/XRHandler.cs +++ b/DesktopVRSwitch/XRHandler.cs @@ -35,6 +35,7 @@ internal static class XRHandler // Remove SteamVR behaviour & render UnityEngine.Object.DestroyImmediate(SteamVR_Behaviour.instance.gameObject); SteamVR.enabled = false; // disposes SteamVR + Patches.SteamVRNullReferencePatch.DestroySteamVRInstancesImmediate(); // Disable UnityXR XRGeneralSettings.Instance.Manager.StopSubsystems(); diff --git a/DesktopVRSwitch/format.json b/DesktopVRSwitch/format.json index fb3b9d0..e478ce8 100644 --- a/DesktopVRSwitch/format.json +++ b/DesktopVRSwitch/format.json @@ -2,7 +2,7 @@ "_id": 103, "name": "DesktopVRSwitch", "modversion": "4.4.1", - "gameversion": "2023r171", + "gameversion": "2023r172", "loaderversion": "0.6.1", "modtype": "Mod", "author": "NotAKidoS", @@ -18,6 +18,6 @@ ], "downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r20/DesktopVRSwitch.dll", "sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/DesktopVRSwitch/", - "changelog": "- Fixes for 2023r171.", + "changelog": "- Fixes for 2023r172.\n- Mouse is now force unlocked once entering VR mode as QOL.", "embedcolor": "3498db" } \ No newline at end of file