diff --git a/DesktopVRSwitch/HarmonyPatches.cs b/DesktopVRSwitch/HarmonyPatches.cs index 2dd6e0d..7dc00bb 100644 --- a/DesktopVRSwitch/HarmonyPatches.cs +++ b/DesktopVRSwitch/HarmonyPatches.cs @@ -3,7 +3,6 @@ using ABI_RC.Core.Savior; using ABI_RC.Core.Util.Object_Behaviour; using ABI_RC.Systems.IK; using ABI_RC.Systems.IK.TrackingModules; -using cohtml; using HarmonyLib; using NAK.DesktopVRSwitch.Patches; using NAK.DesktopVRSwitch.VRModeTrackers; @@ -12,11 +11,11 @@ using Valve.VR; namespace NAK.DesktopVRSwitch.HarmonyPatches; -class CheckVRPatches +internal class CheckVRPatches { [HarmonyPostfix] - [HarmonyPatch(typeof(CheckVR), nameof(CheckVR.Start))] - static void Postfix_CheckVR_Start(ref CheckVR __instance) + [HarmonyPatch(typeof(CheckVR), nameof(CheckVR.Awake))] + private static void Postfix_CheckVR_Start(ref CheckVR __instance) { try { @@ -30,33 +29,19 @@ class CheckVRPatches } } -class IKSystemPatches +internal class IKSystemPatches { - [HarmonyPostfix] //lazy fix so i dont need to wait few frames - [HarmonyPatch(typeof(TrackingPoint), nameof(TrackingPoint.Initialize))] - static void Postfix_TrackingPoint_Initialize(ref TrackingPoint __instance) - { - try - { - __instance.referenceTransform.localScale = Vector3.one; - } - catch (Exception e) - { - DesktopVRSwitch.Logger.Error($"Error during the patched method {nameof(Postfix_TrackingPoint_Initialize)}"); - DesktopVRSwitch.Logger.Error(e); - } - } - - [HarmonyPostfix] //lazy fix so device indecies can change properly + [HarmonyPostfix] //lazy fix so device indices can change properly [HarmonyPatch(typeof(SteamVRTrackingModule), nameof(SteamVRTrackingModule.ModuleDestroy))] - static void Postfix_SteamVRTrackingModule_ModuleDestroy(ref SteamVRTrackingModule __instance) + private static void Postfix_SteamVRTrackingModule_ModuleDestroy(ref SteamVRTrackingModule __instance) { try { - for (int i = 0; i < __instance.TrackingPoints.Count; i++) + foreach (TrackingPoint t in __instance.TrackingPoints) { - UnityEngine.Object.Destroy(__instance.TrackingPoints[i].referenceGameObject); + UnityEngine.Object.Destroy(t.referenceGameObject); } + __instance.TrackingPoints.Clear(); } catch (Exception e) @@ -67,12 +52,12 @@ class IKSystemPatches } } -class CVRWorldPatches +internal class CVRWorldPatches { [HarmonyPostfix] [HarmonyPatch(typeof(CVRWorld), nameof(CVRWorld.SetDefaultCamValues))] [HarmonyPatch(typeof(CVRWorld), nameof(CVRWorld.CopyRefCamValues))] - static void Postfix_CVRWorld_HandleCamValues() + private static void Postfix_CVRWorld_HandleCamValues() { try { @@ -86,11 +71,11 @@ class CVRWorldPatches } } -class CameraFacingObjectPatches +internal class CameraFacingObjectPatches { [HarmonyPostfix] [HarmonyPatch(typeof(CameraFacingObject), nameof(CameraFacingObject.Start))] - static void Postfix_CameraFacingObject_Start(ref CameraFacingObject __instance) + private static void Postfix_CameraFacingObject_Start(ref CameraFacingObject __instance) { try { @@ -104,11 +89,11 @@ class CameraFacingObjectPatches } } -class CVRPickupObjectPatches +internal class CVRPickupObjectPatches { [HarmonyPrefix] [HarmonyPatch(typeof(CVRPickupObject), nameof(CVRPickupObject.Start))] - static void Prefix_CVRPickupObject_Start(ref CVRPickupObject __instance) + private static void Prefix_CVRPickupObject_Start(ref CVRPickupObject __instance) { try { @@ -119,7 +104,7 @@ class CVRPickupObjectPatches Transform desktopOrigin = vrOrigin?.Find("[Desktop]"); if (vrOrigin != null && desktopOrigin != null) { - var tracker = __instance.gameObject.AddComponent(); + CVRPickupObjectTracker tracker = __instance.gameObject.AddComponent(); tracker._pickupObject = __instance; tracker._storedGripOrigin = (!MetaPort.Instance.isUsingVr ? vrOrigin : desktopOrigin); } @@ -132,42 +117,18 @@ class CVRPickupObjectPatches } } -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; - } -} - -class SteamVRBehaviourPatches +internal class SteamVRBehaviourPatches { [HarmonyPrefix] [HarmonyPatch(typeof(SteamVR_Behaviour), nameof(SteamVR_Behaviour.OnQuit))] - static bool Prefix_SteamVR_Behaviour_OnQuit() + private static bool Prefix_SteamVR_Behaviour_OnQuit() { - if (DesktopVRSwitch.EntrySwitchToDesktopOnExit.Value) - { - // If we don't switch fast enough, SteamVR will force close. - // World Transition might cause issues. Might need to override. - VRModeSwitchManager.Instance?.AttemptSwitch(); - return false; - } - return true; + if (!DesktopVRSwitch.EntrySwitchToDesktopOnExit.Value) + return true; + + // If we don't switch fast enough, SteamVR will force close. + // World Transition might cause issues. Might need to override. + VRModeSwitchManager.Instance?.AttemptSwitch(); + return false; } } \ No newline at end of file diff --git a/DesktopVRSwitch/Main.cs b/DesktopVRSwitch/Main.cs index 14ae4c0..f50922d 100644 --- a/DesktopVRSwitch/Main.cs +++ b/DesktopVRSwitch/Main.cs @@ -40,8 +40,6 @@ public class DesktopVRSwitch : MelonMod ApplyPatches(typeof(HarmonyPatches.IKSystemPatches)); // post processing fixes ApplyPatches(typeof(HarmonyPatches.CVRWorldPatches)); - // cohtml gamepad handling nuke - ApplyPatches(typeof(HarmonyPatches.CohtmlUISystemPatches)); // prevent steamvr behaviour from closing game ApplyPatches(typeof(HarmonyPatches.SteamVRBehaviourPatches)); @@ -55,7 +53,7 @@ public class DesktopVRSwitch : MelonMod } } - void RegisterVRModeTrackers() + private static void RegisterVRModeTrackers() { // Core trackers VRModeSwitchManager.RegisterVRModeTracker(new CheckVRTracker()); @@ -86,7 +84,7 @@ public class DesktopVRSwitch : MelonMod VRModeSwitchManager.RegisterVRModeTracker(new CVRWorldTracker()); } - void ApplyPatches(Type type) + private void ApplyPatches(Type type) { try { diff --git a/DesktopVRSwitch/Patches/ReferenceCameraPatch.cs b/DesktopVRSwitch/Patches/ReferenceCameraPatch.cs index fbd4baf..0b4d584 100644 --- a/DesktopVRSwitch/Patches/ReferenceCameraPatch.cs +++ b/DesktopVRSwitch/Patches/ReferenceCameraPatch.cs @@ -9,7 +9,7 @@ using UnityEngine.Rendering.PostProcessing; namespace NAK.DesktopVRSwitch.Patches; -class ReferenceCameraPatch +internal class ReferenceCameraPatch { public static void OnWorldLoad() { @@ -18,7 +18,7 @@ class ReferenceCameraPatch CopyToInactiveCam(activeCamera, inactiveCamera); } - static void CopyToInactiveCam(Camera activeCam, Camera inactiveCam) + private static void CopyToInactiveCam(Camera activeCam, Camera inactiveCam) { if (inactiveCam == null || activeCam == null) return; diff --git a/DesktopVRSwitch/Utils.cs b/DesktopVRSwitch/Utils.cs index 02c363c..44b63be 100644 --- a/DesktopVRSwitch/Utils.cs +++ b/DesktopVRSwitch/Utils.cs @@ -9,11 +9,7 @@ internal static class Utils { internal static GameObject GetPlayerCameraObject(bool intoVR) { - if (intoVR) - { - return PlayerSetup.Instance.vrCamera; - } - return PlayerSetup.Instance.desktopCamera; + return intoVR ? PlayerSetup.Instance.vrCamera : PlayerSetup.Instance.desktopCamera; } internal static void ClearLocalAvatar() @@ -27,10 +23,4 @@ internal static class Utils DesktopVRSwitch.Logger.Msg("Attempting to reload current local avatar from GUID."); AssetManagement.Instance.LoadLocalAvatar(MetaPort.Instance.currentAvatarGuid); } - - internal static bool IsLocalAvatarLoaded() - { - return PlayerSetup.Instance._avatar != null; - } - } diff --git a/DesktopVRSwitch/VRModeSwitchDebugger.cs b/DesktopVRSwitch/VRModeSwitchDebugger.cs index 5f2a7b8..aeb56d3 100644 --- a/DesktopVRSwitch/VRModeSwitchDebugger.cs +++ b/DesktopVRSwitch/VRModeSwitchDebugger.cs @@ -3,12 +3,12 @@ using UnityEngine; namespace NAK.DesktopVRSwitch; -class VRModeSwitchDebugger : MonoBehaviour +internal class VRModeSwitchDebugger : MonoBehaviour { - Coroutine _switchCoroutine; - WaitForSeconds _sleep; + private Coroutine _switchCoroutine; + private WaitForSeconds _sleep; - void OnEnable() + private void OnEnable() { if (_switchCoroutine == null) { @@ -17,7 +17,7 @@ class VRModeSwitchDebugger : MonoBehaviour } } - void OnDisable() + private void OnDisable() { if (_switchCoroutine != null) { @@ -27,7 +27,7 @@ class VRModeSwitchDebugger : MonoBehaviour } } - IEnumerator SwitchLoop() + private IEnumerator SwitchLoop() { while (true) { diff --git a/DesktopVRSwitch/VRModeSwitchManager.cs b/DesktopVRSwitch/VRModeSwitchManager.cs index cb6ebf7..5d20785 100644 --- a/DesktopVRSwitch/VRModeSwitchManager.cs +++ b/DesktopVRSwitch/VRModeSwitchManager.cs @@ -29,7 +29,7 @@ public class VRModeSwitchManager : MonoBehaviour public static event UnityAction OnPreVRModeSwitch; public static event UnityAction OnPostVRModeSwitch; public static event UnityAction OnFailVRModeSwitch; - const string XRSETTINGS_DEVICE = "OpenVR"; + private const string XRSETTINGS_DEVICE = "OpenVR"; public static void RegisterVRModeTracker(VRModeTracker observer) { @@ -49,7 +49,7 @@ public class VRModeSwitchManager : MonoBehaviour public bool SwitchInProgress { get; private set; } - void Awake() + private void Awake() { if (Instance != null) { diff --git a/DesktopVRSwitch/VRModeTrackers/CVRInputManagerTracker.cs b/DesktopVRSwitch/VRModeTrackers/CVRInputManagerTracker.cs index 22e3a77..1d70794 100644 --- a/DesktopVRSwitch/VRModeTrackers/CVRInputManagerTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/CVRInputManagerTracker.cs @@ -1,4 +1,6 @@ using ABI_RC.Core.Savior; +using ABI_RC.Systems.InputManagement; +using ABI_RC.Systems.InputManagement.InputModules; namespace NAK.DesktopVRSwitch.VRModeTrackers; @@ -14,14 +16,17 @@ public class CVRInputManagerTracker : VRModeTracker VRModeSwitchManager.OnPostVRModeSwitch -= OnPostSwitch; } - void OnPostSwitch(bool intoVR) + private void OnPostSwitch(bool intoVR) { DesktopVRSwitch.Logger.Msg("Resetting CVRInputManager inputs."); CVRInputManager.Instance.inputEnabled = true; + + // IM CRYING + CVRInputManager.Instance.reload = true; //just in case - CVRInputManager.Instance.blockedByUi = false; + CVRInputManager.Instance.textInputFocused = false; //sometimes head can get stuck, so just in case CVRInputManager.Instance.independentHeadToggle = false; //just nice to load into desktop with idle gesture @@ -31,5 +36,12 @@ public class CVRInputManagerTracker : VRModeTracker CVRInputManager.Instance.gestureRightRaw = 0f; //turn off finger tracking input CVRInputManager.Instance.individualFingerTracking = false; + + //add input module if you started in desktop + if (CVRInputManager._moduleXR == null) + CVRInputManager.Instance.AddInputModule(CVRInputManager._moduleXR = new CVRInputModule_XR()); + + //enable xr input or whatnot + CVRInputManager._moduleXR.InputEnabled = intoVR; } } \ No newline at end of file diff --git a/DesktopVRSwitch/VRModeTrackers/CVRPickupObjectTracker.cs b/DesktopVRSwitch/VRModeTrackers/CVRPickupObjectTracker.cs index 78bfde8..a5577c3 100644 --- a/DesktopVRSwitch/VRModeTrackers/CVRPickupObjectTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/CVRPickupObjectTracker.cs @@ -8,12 +8,12 @@ public class CVRPickupObjectTracker : MonoBehaviour internal CVRPickupObject _pickupObject; internal Transform _storedGripOrigin; - void Start() + private void Start() { VRModeSwitchManager.OnPostVRModeSwitch += OnPostSwitch; } - void OnDestroy() + private void OnDestroy() { VRModeSwitchManager.OnPostVRModeSwitch -= OnPostSwitch; } diff --git a/DesktopVRSwitch/VRModeTrackers/CameraFacingObjectTracker.cs b/DesktopVRSwitch/VRModeTrackers/CameraFacingObjectTracker.cs index f43289a..d05568d 100644 --- a/DesktopVRSwitch/VRModeTrackers/CameraFacingObjectTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/CameraFacingObjectTracker.cs @@ -5,15 +5,15 @@ namespace NAK.DesktopVRSwitch.VRModeTrackers; public class CameraFacingObjectTracker : MonoBehaviour { - CameraFacingObject _cameraFacingObject; + private CameraFacingObject _cameraFacingObject; - void Start() + private void Start() { _cameraFacingObject = GetComponent(); VRModeSwitchManager.OnPostVRModeSwitch += OnPostSwitch; } - void OnDestroy() + private void OnDestroy() { VRModeSwitchManager.OnPostVRModeSwitch -= OnPostSwitch; } diff --git a/DesktopVRSwitch/VRModeTrackers/MovementSystemTracker.cs b/DesktopVRSwitch/VRModeTrackers/MovementSystemTracker.cs index cd39ed9..0337bb7 100644 --- a/DesktopVRSwitch/VRModeTrackers/MovementSystemTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/MovementSystemTracker.cs @@ -28,9 +28,10 @@ public class MovementSystemTracker : VRModeTracker DesktopVRSwitch.Logger.Msg("Storing player world position and rotation."); - preSwitchWorldPosition = MovementSystem.Instance.rotationPivot.transform.position; + var pivotTransform = MovementSystem.Instance.rotationPivot.transform; + preSwitchWorldPosition = pivotTransform.position; preSwitchWorldPosition.y = MovementSystem.Instance.transform.position.y; - preSwitchWorldRotation = MovementSystem.Instance.rotationPivot.transform.rotation; + preSwitchWorldRotation = pivotTransform.rotation; MovementSystem.Instance.ChangeCrouch(false); MovementSystem.Instance.ChangeProne(false); diff --git a/DesktopVRSwitch/VRModeTrackers/VRTrackerManagerTracker.cs b/DesktopVRSwitch/VRModeTrackers/VRTrackerManagerTracker.cs deleted file mode 100644 index d4ab6d2..0000000 --- a/DesktopVRSwitch/VRModeTrackers/VRTrackerManagerTracker.cs +++ /dev/null @@ -1,30 +0,0 @@ -using ABI_RC.Core.Player; - -namespace NAK.DesktopVRSwitch.VRModeTrackers; - -public class VRTrackerManagerTracker : VRModeTracker -{ - public override void TrackerInit() - { - VRModeSwitchManager.OnPostVRModeSwitch += OnPostSwitch; - } - - public override void TrackerDestroy() - { - VRModeSwitchManager.OnPostVRModeSwitch -= OnPostSwitch; - } - - private void OnPostSwitch(bool intoVR) - { - DesktopVRSwitch.Logger.Msg("Resetting VRTrackerManager."); - - // VRTrackerManager will still get old Left/Right hand objects. - // This only breaks CVRGlobalParams1 reporting battry status - // MetaPort.Update - - VRTrackerManager.Instance.poses = null; - VRTrackerManager.Instance.leftHand = null; - VRTrackerManager.Instance.rightHand = null; - VRTrackerManager.Instance.hasCheckedForKnuckles = false; - } -} \ No newline at end of file diff --git a/DesktopVRSwitch/VRModeTrackers/ViewManagerTracker.cs b/DesktopVRSwitch/VRModeTrackers/ViewManagerTracker.cs index b8aae58..e7556a5 100644 --- a/DesktopVRSwitch/VRModeTrackers/ViewManagerTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/ViewManagerTracker.cs @@ -14,7 +14,7 @@ public class ViewManagerTracker : VRModeTracker VRModeSwitchManager.OnPreVRModeSwitch -= OnPreSwitch; } - public void OnPreSwitch(bool intoVR) + private void OnPreSwitch(bool intoVR) { DesktopVRSwitch.Logger.Msg("Closing ViewManager - Main Menu.");