From 0fb7c3d401d5734bc99482e66b65b5aec8f68b55 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Mon, 19 Jun 2023 23:47:43 -0500 Subject: [PATCH] [DesktopVRSwitch] Nuke CohtmlUISystem Gamepad handling for now. --- DesktopVRSwitch/HarmonyPatches.cs | 46 +++++++++++++++- DesktopVRSwitch/Main.cs | 12 ++++- .../VRModeSwitchManager.cs | 3 +- .../CVRGestureRecognizerTracker.cs | 1 + .../VRModeTrackers/CVRInputManagerTracker.cs | 1 + .../VRModeTrackers/CVRPickupObjectTracker.cs | 13 +++-- .../CVR_InteractableManagerTracker.cs | 1 + .../VRModeTrackers/CVR_MenuManagerTracker.cs | 1 + .../CameraFacingObjectTracker.cs | 13 ++--- .../VRModeTrackers/CheckVRTracker.cs | 1 + .../VRModeTrackers/CohtmlHudTracker.cs | 1 + .../VRModeTrackers/HudOperationsTracker.cs | 1 + .../VRModeTrackers/IKSystemTracker.cs | 1 + .../VRModeTrackers/MetaPortTracker.cs | 53 ++++++++++++++++++- .../VRModeTrackers/MovementSystemTracker.cs | 10 ++++ .../VRModeTrackers/PlayerSetupTracker.cs | 6 ++- .../VRModeTrackers/PortableCameraTracker.cs | 1 + .../VRModeTrackers/VRTrackerManagerTracker.cs | 1 + .../VRModeTrackers/ViewManagerTracker.cs | 1 + 19 files changed, 146 insertions(+), 21 deletions(-) rename DesktopVRSwitch/{VRModeTrackers => }/VRModeSwitchManager.cs (98%) diff --git a/DesktopVRSwitch/HarmonyPatches.cs b/DesktopVRSwitch/HarmonyPatches.cs index 6cb7c27..462a3f3 100644 --- a/DesktopVRSwitch/HarmonyPatches.cs +++ b/DesktopVRSwitch/HarmonyPatches.cs @@ -7,6 +7,7 @@ using HarmonyLib; using NAK.DesktopVRSwitch.Patches; using NAK.DesktopVRSwitch.VRModeTrackers; using UnityEngine; +using cohtml; namespace NAK.DesktopVRSwitch.HarmonyPatches; @@ -64,6 +65,49 @@ class CameraFacingObjectPatches [HarmonyPatch(typeof(CameraFacingObject), nameof(CameraFacingObject.Start))] static void Postfix_CameraFacingObject_Start(ref CameraFacingObject __instance) { - __instance.gameObject.AddComponent(); + __instance.gameObject.AddComponent()._cameraFacingObject = __instance; + } +} + +class CVRPickupObjectPatches +{ + [HarmonyPrefix] + [HarmonyPatch(typeof(CVRPickupObject), nameof(CVRPickupObject.Start))] + static void Prefix_CVRPickupObject_Start(ref CVRPickupObject __instance) + { + if (__instance.gripType == CVRPickupObject.GripType.Free) + return; + + Transform vrOrigin = __instance.gripOrigin; + Transform desktopOrigin = __instance.gripOrigin.Find("[Desktop]"); + if (vrOrigin != null && desktopOrigin != null) + { + var tracker = __instance.gameObject.AddComponent(); + tracker._pickupObject = __instance; + tracker._storedGripOrigin = (!MetaPort.Instance.isUsingVr ? vrOrigin : desktopOrigin); + } + } +} + +class CohtmlUISystemPatches +{ + [HarmonyPrefix] + [HarmonyPatch(typeof(CohtmlUISystem), nameof(CohtmlUISystem.RegisterGamepad))] + [HarmonyPatch(typeof(CohtmlUISystem), nameof(CohtmlUISystem.UnregisterGamepad))] + [HarmonyPatch(typeof(CohtmlUISystem), nameof(CohtmlUISystem.UpdateGamepadState))] + static bool Prefix_CohtmlUISystem_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 + + we are using 1.17.0 (released 10/09/21) :):):) + **/ + + // dont + return false; } } \ No newline at end of file diff --git a/DesktopVRSwitch/Main.cs b/DesktopVRSwitch/Main.cs index 134bc8c..04bedbf 100644 --- a/DesktopVRSwitch/Main.cs +++ b/DesktopVRSwitch/Main.cs @@ -1,4 +1,5 @@ -using MelonLoader; + +using MelonLoader; using NAK.DesktopVRSwitch.VRModeTrackers; using UnityEngine; @@ -28,7 +29,10 @@ public class DesktopVRSwitch : MelonMod 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."); public static readonly MelonPreferences_Entry EntryUseTransitionOnSwitch = - Category.CreateEntry("Use Transition on Switch", true, description: "Should the world transition play on VRMode switch?"); + Category.CreateEntry("Use Transition on Switch", true, description: "Should the world transition play on VRMode switch?"); + + public static readonly MelonPreferences_Entry EntryRenderVRGameView = + Category.CreateEntry("Render VR Game View", true, description: "Should the VR view be displayed in the game window?"); public override void OnInitializeMelon() { @@ -40,10 +44,14 @@ public class DesktopVRSwitch : MelonMod ApplyPatches(typeof(HarmonyPatches.CheckVRPatches)); // nameplate fixes ApplyPatches(typeof(HarmonyPatches.CameraFacingObjectPatches)); + // pickup fixes + ApplyPatches(typeof(HarmonyPatches.CVRPickupObjectPatches)); // lazy fix to reset iksystem ApplyPatches(typeof(HarmonyPatches.IKSystemPatches)); // post processing fixes ApplyPatches(typeof(HarmonyPatches.CVRWorldPatches)); + // cohtml gamepad handling nuke + ApplyPatches(typeof(HarmonyPatches.CohtmlUISystemPatches)); } public override void OnUpdate() diff --git a/DesktopVRSwitch/VRModeTrackers/VRModeSwitchManager.cs b/DesktopVRSwitch/VRModeSwitchManager.cs similarity index 98% rename from DesktopVRSwitch/VRModeTrackers/VRModeSwitchManager.cs rename to DesktopVRSwitch/VRModeSwitchManager.cs index 96ae3b3..a82d147 100644 --- a/DesktopVRSwitch/VRModeTrackers/VRModeSwitchManager.cs +++ b/DesktopVRSwitch/VRModeSwitchManager.cs @@ -1,4 +1,5 @@ using ABI_RC.Systems.UI; +using NAK.DesktopVRSwitch.VRModeTrackers; using System.Collections; using UnityEngine; using UnityEngine.Events; @@ -16,7 +17,7 @@ using Valve.VR; **/ -namespace NAK.DesktopVRSwitch.VRModeTrackers; +namespace NAK.DesktopVRSwitch; public class VRModeSwitchManager : MonoBehaviour { diff --git a/DesktopVRSwitch/VRModeTrackers/CVRGestureRecognizerTracker.cs b/DesktopVRSwitch/VRModeTrackers/CVRGestureRecognizerTracker.cs index b87a7d7..92490ae 100644 --- a/DesktopVRSwitch/VRModeTrackers/CVRGestureRecognizerTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/CVRGestureRecognizerTracker.cs @@ -1,4 +1,5 @@ using ABI_RC.Core.Savior; + using UnityEngine; namespace NAK.DesktopVRSwitch.VRModeTrackers; diff --git a/DesktopVRSwitch/VRModeTrackers/CVRInputManagerTracker.cs b/DesktopVRSwitch/VRModeTrackers/CVRInputManagerTracker.cs index 7ff3ddc..3dc6d91 100644 --- a/DesktopVRSwitch/VRModeTrackers/CVRInputManagerTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/CVRInputManagerTracker.cs @@ -1,5 +1,6 @@ using ABI_RC.Core.Savior; + namespace NAK.DesktopVRSwitch.VRModeTrackers; public class CVRInputManagerTracker : VRModeTracker diff --git a/DesktopVRSwitch/VRModeTrackers/CVRPickupObjectTracker.cs b/DesktopVRSwitch/VRModeTrackers/CVRPickupObjectTracker.cs index 42f9fe4..78bfde8 100644 --- a/DesktopVRSwitch/VRModeTrackers/CVRPickupObjectTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/CVRPickupObjectTracker.cs @@ -5,18 +5,17 @@ namespace NAK.DesktopVRSwitch.VRModeTrackers; public class CVRPickupObjectTracker : MonoBehaviour { - private CVRPickupObject _pickupObject; - private Transform _storedGripOrigin; + internal CVRPickupObject _pickupObject; + internal Transform _storedGripOrigin; - public CVRPickupObjectTracker(CVRPickupObject pickupObject, Transform storedGripOrigin) + void Start() { - this._pickupObject = pickupObject; - this._storedGripOrigin = storedGripOrigin; + VRModeSwitchManager.OnPostVRModeSwitch += OnPostSwitch; } - private void OnDestroy() + void OnDestroy() { - + VRModeSwitchManager.OnPostVRModeSwitch -= OnPostSwitch; } public void OnPostSwitch(bool intoVR) diff --git a/DesktopVRSwitch/VRModeTrackers/CVR_InteractableManagerTracker.cs b/DesktopVRSwitch/VRModeTrackers/CVR_InteractableManagerTracker.cs index 824d72a..6e84653 100644 --- a/DesktopVRSwitch/VRModeTrackers/CVR_InteractableManagerTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/CVR_InteractableManagerTracker.cs @@ -1,5 +1,6 @@ using ABI_RC.Core.InteractionSystem; + namespace NAK.DesktopVRSwitch.VRModeTrackers; public class CVR_InteractableManagerTracker : VRModeTracker diff --git a/DesktopVRSwitch/VRModeTrackers/CVR_MenuManagerTracker.cs b/DesktopVRSwitch/VRModeTrackers/CVR_MenuManagerTracker.cs index dcf18c6..3a8bf55 100644 --- a/DesktopVRSwitch/VRModeTrackers/CVR_MenuManagerTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/CVR_MenuManagerTracker.cs @@ -1,5 +1,6 @@ using ABI_RC.Core.InteractionSystem; + namespace NAK.DesktopVRSwitch.VRModeTrackers; public class CVR_MenuManagerTracker : VRModeTracker diff --git a/DesktopVRSwitch/VRModeTrackers/CameraFacingObjectTracker.cs b/DesktopVRSwitch/VRModeTrackers/CameraFacingObjectTracker.cs index 504b76a..29730b3 100644 --- a/DesktopVRSwitch/VRModeTrackers/CameraFacingObjectTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/CameraFacingObjectTracker.cs @@ -5,21 +5,18 @@ namespace NAK.DesktopVRSwitch.VRModeTrackers; public class CameraFacingObjectTracker : MonoBehaviour { - private CameraFacingObject _cameraFacingObject; + internal CameraFacingObject _cameraFacingObject; - public CameraFacingObjectTracker(CameraFacingObject cameraFacingObject) + void Start() { - this._cameraFacingObject = cameraFacingObject; + VRModeSwitchManager.OnPostVRModeSwitch += OnPostSwitch; } - private void OnDestroy() + void OnDestroy() { + VRModeSwitchManager.OnPostVRModeSwitch -= OnPostSwitch; } - public void OnPreSwitch(bool intoVR) { } - - public void OnFailedSwitch(bool intoVR) { } - public void OnPostSwitch(bool intoVR) { _cameraFacingObject.m_Camera = Utils.GetPlayerCameraObject(intoVR).GetComponent(); diff --git a/DesktopVRSwitch/VRModeTrackers/CheckVRTracker.cs b/DesktopVRSwitch/VRModeTrackers/CheckVRTracker.cs index 7dfa7e4..d494308 100644 --- a/DesktopVRSwitch/VRModeTrackers/CheckVRTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/CheckVRTracker.cs @@ -1,5 +1,6 @@ using ABI_RC.Core.Savior; + namespace NAK.DesktopVRSwitch.VRModeTrackers; public class CheckVRTracker : VRModeTracker diff --git a/DesktopVRSwitch/VRModeTrackers/CohtmlHudTracker.cs b/DesktopVRSwitch/VRModeTrackers/CohtmlHudTracker.cs index e6583ae..12a084c 100644 --- a/DesktopVRSwitch/VRModeTrackers/CohtmlHudTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/CohtmlHudTracker.cs @@ -1,5 +1,6 @@ using ABI_RC.Core; using ABI_RC.Core.UI; + using UnityEngine; namespace NAK.DesktopVRSwitch.VRModeTrackers; diff --git a/DesktopVRSwitch/VRModeTrackers/HudOperationsTracker.cs b/DesktopVRSwitch/VRModeTrackers/HudOperationsTracker.cs index f25a03a..745934f 100644 --- a/DesktopVRSwitch/VRModeTrackers/HudOperationsTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/HudOperationsTracker.cs @@ -1,5 +1,6 @@ using ABI_RC.Core.Player; + namespace NAK.DesktopVRSwitch.VRModeTrackers; public class HudOperationsTracker : VRModeTracker diff --git a/DesktopVRSwitch/VRModeTrackers/IKSystemTracker.cs b/DesktopVRSwitch/VRModeTrackers/IKSystemTracker.cs index 9e3a300..ab9ef3d 100644 --- a/DesktopVRSwitch/VRModeTrackers/IKSystemTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/IKSystemTracker.cs @@ -2,6 +2,7 @@ using ABI_RC.Systems.IK.SubSystems; using ABI_RC.Systems.IK.TrackingModules; + namespace NAK.DesktopVRSwitch.VRModeTrackers; public class IKSystemTracker : VRModeTracker diff --git a/DesktopVRSwitch/VRModeTrackers/MetaPortTracker.cs b/DesktopVRSwitch/VRModeTrackers/MetaPortTracker.cs index d767221..c6a3b73 100644 --- a/DesktopVRSwitch/VRModeTrackers/MetaPortTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/MetaPortTracker.cs @@ -1,9 +1,14 @@ using ABI_RC.Core.Savior; +using UnityEngine; +using UnityEngine.XR; +using Valve.VR; namespace NAK.DesktopVRSwitch.VRModeTrackers; public class MetaPortTracker : VRModeTracker { + private MetaPort _metaPort; + public override void TrackerInit() { VRModeSwitchManager.OnPostVRModeSwitch += OnPostSwitch; @@ -16,7 +21,7 @@ public class MetaPortTracker : VRModeTracker private void OnPostSwitch(bool intoVR) { - MetaPort _metaPort = MetaPort.Instance; + _metaPort = MetaPort.Instance; if (_metaPort == null) { DesktopVRSwitch.Logger.Error("Error while getting MetaPort!"); @@ -27,6 +32,13 @@ public class MetaPortTracker : VRModeTracker // Main thing most of the game checks for if using VR _metaPort.isUsingVr = intoVR; + // replace + UpdateRichPresence(); + ResetSteamVROverrides(intoVR); + } + + private void UpdateRichPresence() + { // Hacky way of updating rich presence if (_metaPort.settings.GetSettingsBool("ImplementationRichPresenceDiscordEnabled", true)) { @@ -41,4 +53,43 @@ public class MetaPortTracker : VRModeTracker _metaPort.settings.SetSettingsBool("ImplementationRichPresenceSteamEnabled", true); } } + + private void ResetSteamVROverrides(bool intoVR) + { + if (intoVR) + { + // Testing + XRSettings.eyeTextureResolutionScale = 1; + XRSettings.gameViewRenderMode = DesktopVRSwitch.EntryRenderVRGameView.Value ? GameViewRenderMode.LeftEye : GameViewRenderMode.None; + SteamVR_Settings.instance.pauseGameWhenDashboardVisible = false; + + if (MetaPort.Instance.settings.GetSettingsBool("InteractionTobiiEyeTracking", false)) + { + MetaPort.Instance.TobiiXrInitializer.Initialize(); + } + + return; + } + + // Reset physics time to Desktop default + Time.fixedDeltaTime = 0.02f; + + // Reset queued frames + QualitySettings.maxQueuedFrames = 2; + + // Reset framerate target + int graphicsFramerateTarget = MetaPort.Instance.settings.GetSettingInt("GraphicsFramerateTarget", 0); + ABI_RC.Core.CVRTools.SetFramerateTarget(graphicsFramerateTarget); + + // Reset VSync setting + bool graphicsVSync = MetaPort.Instance.settings.GetSettingsBool("GraphicsVSync", false); + QualitySettings.vSyncCount = graphicsVSync ? 1 : 0; + + // Reset anti-aliasing + int graphicsMsaaLevel = MetaPort.Instance.settings.GetSettingInt("GraphicsMsaaLevel", 0); + QualitySettings.antiAliasing = graphicsMsaaLevel; + + // Won't do anything if not already running + MetaPort.Instance.TobiiXrInitializer.DeInitialize(); + } } \ No newline at end of file diff --git a/DesktopVRSwitch/VRModeTrackers/MovementSystemTracker.cs b/DesktopVRSwitch/VRModeTrackers/MovementSystemTracker.cs index b905fe4..ac1a90b 100644 --- a/DesktopVRSwitch/VRModeTrackers/MovementSystemTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/MovementSystemTracker.cs @@ -1,4 +1,5 @@ using ABI_RC.Systems.MovementSystem; + using UnityEngine; namespace NAK.DesktopVRSwitch.VRModeTrackers; @@ -12,12 +13,14 @@ public class MovementSystemTracker : VRModeTracker public override void TrackerInit() { VRModeSwitchManager.OnPreVRModeSwitch += OnPreSwitch; + VRModeSwitchManager.OnFailVRModeSwitch += OnFailedSwitch; VRModeSwitchManager.OnPostVRModeSwitch += OnPostSwitch; } public override void TrackerDestroy() { VRModeSwitchManager.OnPreVRModeSwitch -= OnPreSwitch; + VRModeSwitchManager.OnFailVRModeSwitch -= OnFailedSwitch; VRModeSwitchManager.OnPostVRModeSwitch -= OnPostSwitch; } @@ -28,10 +31,16 @@ public class MovementSystemTracker : VRModeTracker preSwitchWorldPosition = Utils.GetPlayerRootPosition(); preSwitchWorldRotation = _movementSystem.rotationPivot.transform.rotation; + _movementSystem.SetImmobilized(true); _movementSystem.ChangeCrouch(false); _movementSystem.ChangeProne(false); } + private void OnFailedSwitch(bool intoVR) + { + _movementSystem.SetImmobilized(false); + } + private void OnPostSwitch(bool intoVR) { _movementSystem.rotationPivot = Utils.GetPlayerCameraObject(intoVR).transform; @@ -40,6 +49,7 @@ public class MovementSystemTracker : VRModeTracker if (!intoVR) _movementSystem.UpdateColliderCenter(_movementSystem.transform.position); + _movementSystem.SetImmobilized(false); _movementSystem.ChangeCrouch(false); _movementSystem.ChangeProne(false); } diff --git a/DesktopVRSwitch/VRModeTrackers/PlayerSetupTracker.cs b/DesktopVRSwitch/VRModeTrackers/PlayerSetupTracker.cs index 675a41d..bac1c63 100644 --- a/DesktopVRSwitch/VRModeTrackers/PlayerSetupTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/PlayerSetupTracker.cs @@ -1,5 +1,6 @@ using ABI_RC.Core.Player; + namespace NAK.DesktopVRSwitch.VRModeTrackers; public class PlayerSetupTracker : VRModeTracker @@ -29,8 +30,11 @@ public class PlayerSetupTracker : VRModeTracker // This might error if we started in VR. // '_cam' is not set until Start(). - CVR_DesktopCameraController.UpdateFov(); + if (CVR_DesktopCameraController._cam == null) + CVR_DesktopCameraController._cam = _playerSetup.desktopCamera.GetComponent(); + CVR_DesktopCameraController.UpdateFov(); + // UICamera has a script that copies the FOV from the desktop cam. // Toggling the cameras on/off resets the aspect ratio, // so when rigs switch, that is already handled. diff --git a/DesktopVRSwitch/VRModeTrackers/PortableCameraTracker.cs b/DesktopVRSwitch/VRModeTrackers/PortableCameraTracker.cs index f2a616e..654964b 100644 --- a/DesktopVRSwitch/VRModeTrackers/PortableCameraTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/PortableCameraTracker.cs @@ -1,5 +1,6 @@ using ABI_RC.Systems.Camera; + namespace NAK.DesktopVRSwitch.VRModeTrackers; public class PortableCameraTracker : VRModeTracker diff --git a/DesktopVRSwitch/VRModeTrackers/VRTrackerManagerTracker.cs b/DesktopVRSwitch/VRModeTrackers/VRTrackerManagerTracker.cs index a24d85c..d1d8044 100644 --- a/DesktopVRSwitch/VRModeTrackers/VRTrackerManagerTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/VRTrackerManagerTracker.cs @@ -1,5 +1,6 @@ using ABI_RC.Core.Player; + namespace NAK.DesktopVRSwitch.VRModeTrackers; public class VRTrackerManagerTracker : VRModeTracker diff --git a/DesktopVRSwitch/VRModeTrackers/ViewManagerTracker.cs b/DesktopVRSwitch/VRModeTrackers/ViewManagerTracker.cs index 1014b4d..e3500f7 100644 --- a/DesktopVRSwitch/VRModeTrackers/ViewManagerTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/ViewManagerTracker.cs @@ -1,5 +1,6 @@ using ABI_RC.Core.InteractionSystem; + namespace NAK.DesktopVRSwitch.VRModeTrackers; public class ViewManagerTracker : VRModeTracker