From 6774c3ff6d247edd22b9ce21ca7b5fb10ae356b4 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Wed, 21 Jun 2023 14:06:12 -0500 Subject: [PATCH] [DesktopVRSwitch] Stop being a baby. ??? --- ControllerFreeze/ControllerFreeze.csproj | 2 + ControllerFreeze/HarmonyPatches.cs | 20 ++++++ ControllerFreeze/Main.cs | 24 +++++++ ControllerFreeze/Properties/AssemblyInfo.cs | 30 +++++++++ ControllerFreeze/README.md | 16 +++++ ControllerFreeze/format.json | 23 +++++++ DesktopVRSwitch/VRModeSwitchManager.cs | 16 +++-- .../CVRGestureRecognizerTracker.cs | 8 +-- .../VRModeTrackers/CVRInputManagerTracker.cs | 22 +++---- .../VRModeTrackers/CVRWorldTracker.cs | 25 ++++--- .../CVR_InteractableManagerTracker.cs | 6 -- .../VRModeTrackers/CVR_MenuManagerTracker.cs | 16 +---- .../VRModeTrackers/CohtmlHudTracker.cs | 10 +-- .../VRModeTrackers/HudOperationsTracker.cs | 10 +-- .../VRModeTrackers/IKSystemTracker.cs | 5 +- .../VRModeTrackers/MetaPortTracker.cs | 24 +++---- .../VRModeTrackers/MovementSystemTracker.cs | 65 +++++++------------ .../VRModeTrackers/PlayerSetupTracker.cs | 10 +-- .../VRModeTrackers/PortableCameraTracker.cs | 10 +-- .../VRModeTrackers/VRTrackerManagerTracker.cs | 18 +++-- .../VRModeTrackers/ViewManagerTracker.cs | 8 +-- NAK_CVR_Mods.sln | 6 ++ 22 files changed, 205 insertions(+), 169 deletions(-) create mode 100644 ControllerFreeze/ControllerFreeze.csproj create mode 100644 ControllerFreeze/HarmonyPatches.cs create mode 100644 ControllerFreeze/Main.cs create mode 100644 ControllerFreeze/Properties/AssemblyInfo.cs create mode 100644 ControllerFreeze/README.md create mode 100644 ControllerFreeze/format.json diff --git a/ControllerFreeze/ControllerFreeze.csproj b/ControllerFreeze/ControllerFreeze.csproj new file mode 100644 index 0000000..66a50a8 --- /dev/null +++ b/ControllerFreeze/ControllerFreeze.csproj @@ -0,0 +1,2 @@ + + diff --git a/ControllerFreeze/HarmonyPatches.cs b/ControllerFreeze/HarmonyPatches.cs new file mode 100644 index 0000000..7a1e7bf --- /dev/null +++ b/ControllerFreeze/HarmonyPatches.cs @@ -0,0 +1,20 @@ +using ABI_RC.Core.Player; +using ABI_RC.Core.Savior; +using ABI_RC.Systems.IK.SubSystems; +using HarmonyLib; + +namespace NAK.ControllerFreeze.HarmonyPatches; + +class PlayerSetupPatches +{ + [HarmonyPostfix] + [HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.Update))] + static void Postfix_PlayerSetup_Update() + { + if (MetaPort.Instance.isUsingVr) + { + BodySystem.TrackingLeftArmEnabled = true; + BodySystem.TrackingRightArmEnabled = true; + } + } +} \ No newline at end of file diff --git a/ControllerFreeze/Main.cs b/ControllerFreeze/Main.cs new file mode 100644 index 0000000..a8101f0 --- /dev/null +++ b/ControllerFreeze/Main.cs @@ -0,0 +1,24 @@ +using MelonLoader; + +namespace NAK.ControllerFreeze; + +public class ControllerFreeze : MelonMod +{ + public override void OnInitializeMelon() + { + ApplyPatches(typeof(HarmonyPatches.PlayerSetupPatches)); + } + + void ApplyPatches(Type type) + { + try + { + HarmonyInstance.PatchAll(type); + } + catch (Exception e) + { + LoggerInstance.Msg($"Failed while patching {type.Name}!"); + LoggerInstance.Error(e); + } + } +} \ No newline at end of file diff --git a/ControllerFreeze/Properties/AssemblyInfo.cs b/ControllerFreeze/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..26229a1 --- /dev/null +++ b/ControllerFreeze/Properties/AssemblyInfo.cs @@ -0,0 +1,30 @@ +using MelonLoader; +using NAK.ControllerFreeze.Properties; +using System.Reflection; + +[assembly: AssemblyVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyFileVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyTitle(nameof(NAK.ControllerFreeze))] +[assembly: AssemblyCompany(AssemblyInfoParams.Author)] +[assembly: AssemblyProduct(nameof(NAK.ControllerFreeze))] + +[assembly: MelonInfo( + typeof(NAK.ControllerFreeze.ControllerFreeze), + nameof(NAK.ControllerFreeze), + AssemblyInfoParams.Version, + AssemblyInfoParams.Author, + downloadLink: "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/ControllerFreeze" +)] + +[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")] +[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] +[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)] +[assembly: HarmonyDontPatchAll] + +namespace NAK.ControllerFreeze.Properties; +internal static class AssemblyInfoParams +{ + public const string Version = "1.0.5"; + public const string Author = "NotAKidoS"; +} \ No newline at end of file diff --git a/ControllerFreeze/README.md b/ControllerFreeze/README.md new file mode 100644 index 0000000..8f36c62 --- /dev/null +++ b/ControllerFreeze/README.md @@ -0,0 +1,16 @@ +# ControllerFreeze + +This made no sense to dirty ControllerFreeze with, so it is now its own mod. + +Prevents game disabling arm tracking when a controller is inactive. + +--- + +Here is the block of text where I tell you this mod is not affiliated or endorsed by ABI. +https://documentation.abinteractive.net/official/legal/tos/#7-modding-our-games + +> This mod is an independent creation and is not affiliated with, supported by or approved by Alpha Blend Interactive. + +> Use of this mod is done so at the user's own risk and the creator cannot be held responsible for any issues arising from its use. + +> To the best of my knowledge, I have adhered to the Modding Guidelines established by Alpha Blend Interactive. diff --git a/ControllerFreeze/format.json b/ControllerFreeze/format.json new file mode 100644 index 0000000..71e890c --- /dev/null +++ b/ControllerFreeze/format.json @@ -0,0 +1,23 @@ +{ + "_id": -1, + "name": "ControllerFreeze", + "modversion": "1.0.5", + "gameversion": "2022r170p1", + "loaderversion": "0.6.1", + "modtype": "Mod", + "author": "NotAKidoS", + "description": "Allows your controllers to track while the SteamVR overlay is open. This also fixes Quest/Touch controllers feeling slow during fast movements.\n\nSupport for SmoothRay & DesktopVRSwitch.", + "searchtags": [ + "vr", + "quest", + "controller", + "tracking" + ], + "requirements": [ + "None" + ], + "downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r9/ControllerFreeze.dll", + "sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/ControllerFreeze/", + "changelog": "Initial CVRMG Release", + "embedcolor": "3498db" +} \ No newline at end of file diff --git a/DesktopVRSwitch/VRModeSwitchManager.cs b/DesktopVRSwitch/VRModeSwitchManager.cs index aa25ff1..7c3b985 100644 --- a/DesktopVRSwitch/VRModeSwitchManager.cs +++ b/DesktopVRSwitch/VRModeSwitchManager.cs @@ -75,9 +75,12 @@ public class VRModeSwitchManager : MonoBehaviour yield return null; - if (_useWorldTransition) // start visual transition and wait for it to complete - yield return WorldTransitionSystem.Instance.StartTransitionCoroutine(); - + if (_useWorldTransition) + { // start visual transition and wait for it to complete + WorldTransitionSystem.Instance.StartTransition(); + yield return new WaitForSeconds(WorldTransitionSystem.Instance.CurrentInLength); + } + // Check if OpenVR is running bool isUsingVr = IsInVR(); @@ -110,8 +113,11 @@ public class VRModeSwitchManager : MonoBehaviour InvokeOnFailedSwitch(!isUsingVr); } - if (_useWorldTransition) // finish the visual transition and wait - yield return WorldTransitionSystem.Instance.ContinueTransitionCoroutine(); + if (_useWorldTransition) + { // would be cool to have out length + WorldTransitionSystem.Instance.ContinueTransitionCoroutine(); + yield return new WaitForSeconds(WorldTransitionSystem.Instance.CurrentInLength); + } SwitchInProgress = false; yield break; diff --git a/DesktopVRSwitch/VRModeTrackers/CVRGestureRecognizerTracker.cs b/DesktopVRSwitch/VRModeTrackers/CVRGestureRecognizerTracker.cs index b87a7d7..fa4dc6a 100644 --- a/DesktopVRSwitch/VRModeTrackers/CVRGestureRecognizerTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/CVRGestureRecognizerTracker.cs @@ -17,14 +17,8 @@ public class CVRGestureRecognizerTracker : VRModeTracker private void OnPostSwitch(bool intoVR) { - CVRGestureRecognizer _cvrGestureRecognizer = CVRGestureRecognizer.Instance; - if (_cvrGestureRecognizer == null) - { - DesktopVRSwitch.Logger.Error("Error while getting CVRGestureRecognizer!"); - return; - } DesktopVRSwitch.Logger.Msg("Updating CVRGestureRecognizer _camera to active camera."); - _cvrGestureRecognizer._camera = Utils.GetPlayerCameraObject(intoVR).GetComponent(); + CVRGestureRecognizer.Instance._camera = Utils.GetPlayerCameraObject(intoVR).GetComponent(); } } \ No newline at end of file diff --git a/DesktopVRSwitch/VRModeTrackers/CVRInputManagerTracker.cs b/DesktopVRSwitch/VRModeTrackers/CVRInputManagerTracker.cs index 3dc6d91..1723cdf 100644 --- a/DesktopVRSwitch/VRModeTrackers/CVRInputManagerTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/CVRInputManagerTracker.cs @@ -17,26 +17,20 @@ public class CVRInputManagerTracker : VRModeTracker void OnPostSwitch(bool intoVR) { - CVRInputManager _cvrInputManager = CVRInputManager.Instance; - if (_cvrInputManager == null) - { - DesktopVRSwitch.Logger.Error("Error while getting CVRInputManager!"); - return; - } DesktopVRSwitch.Logger.Msg("Resetting CVRInputManager inputs."); - _cvrInputManager.inputEnabled = true; + CVRInputManager.Instance.inputEnabled = true; //just in case - _cvrInputManager.blockedByUi = false; + CVRInputManager.Instance.blockedByUi = false; //sometimes head can get stuck, so just in case - _cvrInputManager.independentHeadToggle = false; + CVRInputManager.Instance.independentHeadToggle = false; //just nice to load into desktop with idle gesture - _cvrInputManager.gestureLeft = 0f; - _cvrInputManager.gestureLeftRaw = 0f; - _cvrInputManager.gestureRight = 0f; - _cvrInputManager.gestureRightRaw = 0f; + CVRInputManager.Instance.gestureLeft = 0f; + CVRInputManager.Instance.gestureLeftRaw = 0f; + CVRInputManager.Instance.gestureRight = 0f; + CVRInputManager.Instance.gestureRightRaw = 0f; //turn off finger tracking input - _cvrInputManager.individualFingerTracking = false; + CVRInputManager.Instance.individualFingerTracking = false; } } \ No newline at end of file diff --git a/DesktopVRSwitch/VRModeTrackers/CVRWorldTracker.cs b/DesktopVRSwitch/VRModeTrackers/CVRWorldTracker.cs index 394ebab..51563e8 100644 --- a/DesktopVRSwitch/VRModeTrackers/CVRWorldTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/CVRWorldTracker.cs @@ -19,30 +19,27 @@ public class CVRWorldTracker : VRModeTracker private void OnPostSwitch(bool intoVR) { - CVRWorld _cvrWorld = CVRWorld.Instance; - if (_cvrWorld == null) - { - DesktopVRSwitch.Logger.Error("Error while getting CVRWorld!"); - return; - } DesktopVRSwitch.Logger.Msg("Configuring CVRWorld. Updating PostProcessing & DesktopCameraController FOV settings."); // some post processing settings aren't used in VR - _cvrWorld.UpdatePostProcessing(); - UpdateCVRDesktopCameraController(_cvrWorld); + CVRWorld.Instance.UpdatePostProcessing(); + UpdateCVRDesktopCameraController(); } - - private void UpdateCVRDesktopCameraController(CVRWorld _cvrWorld) + + private void UpdateCVRDesktopCameraController() { // Just making sure- Starting in VR will not call Start() as rig is disabled if (CVR_DesktopCameraController._cam == null) CVR_DesktopCameraController._cam = PlayerSetup.Instance.desktopCamera.GetComponent(); - CVR_DesktopCameraController.defaultFov = Mathf.Clamp(_cvrWorld.fov, 60f, 120f); + CVR_DesktopCameraController.defaultFov = Mathf.Clamp(CVRWorld.Instance.fov, 60f, 120f); CVR_DesktopCameraController.zoomFov = CVR_DesktopCameraController.defaultFov * 0.5f; - CVR_DesktopCameraController.enableZoom = _cvrWorld.enableZoom; - CVR_DesktopCameraController.UpdateFov(); // must happen after PlayerSetupTracker - CVR_MenuManager.Instance.coreData.instance.current_game_rule_no_zoom = !_cvrWorld.enableZoom; + CVR_DesktopCameraController.enableZoom = CVRWorld.Instance.enableZoom; + + // must happen after PlayerSetupTracker + CVR_DesktopCameraController.UpdateFov(); + + CVR_MenuManager.Instance.coreData.instance.current_game_rule_no_zoom = !CVRWorld.Instance.enableZoom; // UICamera has a script that copies the FOV from the desktop cam. // Toggling the cameras on/off resets the aspect ratio, diff --git a/DesktopVRSwitch/VRModeTrackers/CVR_InteractableManagerTracker.cs b/DesktopVRSwitch/VRModeTrackers/CVR_InteractableManagerTracker.cs index 824d72a..954862f 100644 --- a/DesktopVRSwitch/VRModeTrackers/CVR_InteractableManagerTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/CVR_InteractableManagerTracker.cs @@ -16,12 +16,6 @@ public class CVR_InteractableManagerTracker : VRModeTracker private void OnPostSwitch(bool intoVR) { - CVR_InteractableManager _cvrInteractableManager = CVR_InteractableManager.Instance; - if (_cvrInteractableManager == null) - { - DesktopVRSwitch.Logger.Error("Error while getting CVR_InteractableManager!"); - return; - } DesktopVRSwitch.Logger.Msg($"Setting CVRInputManager inputEnabled & CVR_InteractableManager enableInteractions to {!intoVR}"); CVR_InteractableManager.enableInteractions = !intoVR; diff --git a/DesktopVRSwitch/VRModeTrackers/CVR_MenuManagerTracker.cs b/DesktopVRSwitch/VRModeTrackers/CVR_MenuManagerTracker.cs index dcf18c6..f3bbea8 100644 --- a/DesktopVRSwitch/VRModeTrackers/CVR_MenuManagerTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/CVR_MenuManagerTracker.cs @@ -18,27 +18,15 @@ public class CVR_MenuManagerTracker : VRModeTracker private void OnPreSwitch(bool intoVR) { - CVR_MenuManager _cvrMenuManager = CVR_MenuManager.Instance; - if (_cvrMenuManager == null) - { - DesktopVRSwitch.Logger.Error("Error while getting CVR_MenuManager!"); - return; - } DesktopVRSwitch.Logger.Msg("Closing CVR_MenuManager - Quick Menu."); - _cvrMenuManager.ToggleQuickMenu(false); + CVR_MenuManager.Instance.ToggleQuickMenu(false); } private void OnPostSwitch(bool intoVR) { - CVR_MenuManager _cvrMenuManager = CVR_MenuManager.Instance; - if (_cvrMenuManager == null) - { - DesktopVRSwitch.Logger.Error("Error while getting CVR_MenuManager!"); - return; - } DesktopVRSwitch.Logger.Msg("Updating CVR_Menu_Data core data."); - _cvrMenuManager.coreData.core.inVr = intoVR; + CVR_MenuManager.Instance.coreData.core.inVr = intoVR; } } \ No newline at end of file diff --git a/DesktopVRSwitch/VRModeTrackers/CohtmlHudTracker.cs b/DesktopVRSwitch/VRModeTrackers/CohtmlHudTracker.cs index e6583ae..024ce93 100644 --- a/DesktopVRSwitch/VRModeTrackers/CohtmlHudTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/CohtmlHudTracker.cs @@ -18,17 +18,11 @@ public class CohtmlHudTracker : VRModeTracker private void OnPostSwitch(bool intoVR) { - CohtmlHud _cohtmlHud = CohtmlHud.Instance; - if (_cohtmlHud == null) - { - DesktopVRSwitch.Logger.Error("Error while getting CohtmlHud!"); - return; - } DesktopVRSwitch.Logger.Msg("Configuring new hud affinity for CohtmlHud."); - _cohtmlHud.gameObject.transform.parent = Utils.GetPlayerCameraObject(intoVR).transform; + CohtmlHud.Instance.gameObject.transform.parent = Utils.GetPlayerCameraObject(intoVR).transform; // This handles rotation and position CVRTools.ConfigureHudAffinity(); - _cohtmlHud.gameObject.transform.localScale = new Vector3(1.2f, 1f, 1.2f); + CohtmlHud.Instance.gameObject.transform.localScale = new Vector3(1.2f, 1f, 1.2f); } } \ No newline at end of file diff --git a/DesktopVRSwitch/VRModeTrackers/HudOperationsTracker.cs b/DesktopVRSwitch/VRModeTrackers/HudOperationsTracker.cs index f25a03a..d0a4574 100644 --- a/DesktopVRSwitch/VRModeTrackers/HudOperationsTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/HudOperationsTracker.cs @@ -16,15 +16,9 @@ public class HudOperationsTracker : VRModeTracker private void OnPostSwitch(bool intoVR) { - HudOperations _hudOperations = HudOperations.Instance; - if (_hudOperations == null) - { - DesktopVRSwitch.Logger.Error("Error while getting HudOperations!"); - return; - } DesktopVRSwitch.Logger.Msg("Switching HudOperations worldLoadingItem & worldLoadStatus."); - _hudOperations.worldLoadingItem = intoVR ? _hudOperations.worldLoadingItemVr : _hudOperations.worldLoadingItemDesktop; - _hudOperations.worldLoadStatus = intoVR ? _hudOperations.worldLoadStatusVr : _hudOperations.worldLoadStatusDesktop; + HudOperations.Instance.worldLoadingItem = intoVR ? HudOperations.Instance.worldLoadingItemVr : HudOperations.Instance.worldLoadingItemDesktop; + HudOperations.Instance.worldLoadStatus = intoVR ? HudOperations.Instance.worldLoadStatusVr : HudOperations.Instance.worldLoadStatusDesktop; } } \ No newline at end of file diff --git a/DesktopVRSwitch/VRModeTrackers/IKSystemTracker.cs b/DesktopVRSwitch/VRModeTrackers/IKSystemTracker.cs index 9e3a300..f70c081 100644 --- a/DesktopVRSwitch/VRModeTrackers/IKSystemTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/IKSystemTracker.cs @@ -52,13 +52,12 @@ public class IKSystemTracker : VRModeTracker BodySystem.isCalibratedAsFullBody = false; BodySystem.isCalibrating = false; BodySystem.isRecalibration = false; - + // Make it so you don't instantly end up in FBT from Desktop IKSystem.firstAvatarLoaded = DesktopVRSwitch.EntryEnterCalibrationOnSwitch.Value; // Turn off finger tracking just in case the user switched controllers - if (IKSystem.Instance != null) - IKSystem.Instance.FingerSystem.controlActive = false; + IKSystem.Instance.FingerSystem.controlActive = false; SetupSteamVRTrackingModule(intoVR); } diff --git a/DesktopVRSwitch/VRModeTrackers/MetaPortTracker.cs b/DesktopVRSwitch/VRModeTrackers/MetaPortTracker.cs index 3d73c7a..1f5e851 100644 --- a/DesktopVRSwitch/VRModeTrackers/MetaPortTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/MetaPortTracker.cs @@ -19,36 +19,30 @@ public class MetaPortTracker : VRModeTracker private void OnPostSwitch(bool intoVR) { - MetaPort _metaPort = MetaPort.Instance; - if (_metaPort == null) - { - DesktopVRSwitch.Logger.Error("Error while getting MetaPort!"); - return; - } DesktopVRSwitch.Logger.Msg($"Setting MetaPort isUsingVr to {intoVR}."); // Main thing most of the game checks for if using VR - _metaPort.isUsingVr = intoVR; + MetaPort.Instance.isUsingVr = intoVR; // replace - UpdateRichPresence(_metaPort); + UpdateRichPresence(); ResetSteamVROverrides(intoVR); } - private void UpdateRichPresence(MetaPort _metaPort) + private void UpdateRichPresence() { // Hacky way of updating rich presence - if (_metaPort.settings.GetSettingsBool("ImplementationRichPresenceDiscordEnabled", true)) + if (MetaPort.Instance.settings.GetSettingsBool("ImplementationRichPresenceDiscordEnabled", true)) { DesktopVRSwitch.Logger.Msg("Forcing Discord Rich Presence update."); - _metaPort.settings.SetSettingsBool("ImplementationRichPresenceDiscordEnabled", false); - _metaPort.settings.SetSettingsBool("ImplementationRichPresenceDiscordEnabled", true); + MetaPort.Instance.settings.SetSettingsBool("ImplementationRichPresenceDiscordEnabled", false); + MetaPort.Instance.settings.SetSettingsBool("ImplementationRichPresenceDiscordEnabled", true); } - if (_metaPort.settings.GetSettingsBool("ImplementationRichPresenceSteamEnabled", true)) + if (MetaPort.Instance.settings.GetSettingsBool("ImplementationRichPresenceSteamEnabled", true)) { DesktopVRSwitch.Logger.Msg("Forcing Steam Rich Presence update."); - _metaPort.settings.SetSettingsBool("ImplementationRichPresenceSteamEnabled", false); - _metaPort.settings.SetSettingsBool("ImplementationRichPresenceSteamEnabled", true); + MetaPort.Instance.settings.SetSettingsBool("ImplementationRichPresenceSteamEnabled", false); + MetaPort.Instance.settings.SetSettingsBool("ImplementationRichPresenceSteamEnabled", true); } } diff --git a/DesktopVRSwitch/VRModeTrackers/MovementSystemTracker.cs b/DesktopVRSwitch/VRModeTrackers/MovementSystemTracker.cs index 22de1ed..884cd0c 100644 --- a/DesktopVRSwitch/VRModeTrackers/MovementSystemTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/MovementSystemTracker.cs @@ -23,41 +23,26 @@ public class MovementSystemTracker : VRModeTracker VRModeSwitchManager.OnPostVRModeSwitch -= OnPostSwitch; } - // why do i do this - private MovementSystem GetMovementSystemInstance() - { - MovementSystem _movementSystem = MovementSystem.Instance; - if (_movementSystem == null) - { - DesktopVRSwitch.Logger.Error("Error while getting MovementSystem!"); - } - return _movementSystem; - } - private void OnPreSwitch(bool intoVR) { - MovementSystem _movementSystem = GetMovementSystemInstance(); - if (_movementSystem != null) - { - DesktopVRSwitch.Logger.Msg("Storing player world position and rotation."); - preSwitchWorldPosition = _movementSystem.rotationPivot.transform.position; - preSwitchWorldPosition.y = _movementSystem.transform.position.y; - preSwitchWorldRotation = _movementSystem.rotationPivot.transform.rotation; - _movementSystem.ChangeCrouch(false); - _movementSystem.ChangeProne(false); - _movementSystem.SetImmobilized(true); - } + DesktopVRSwitch.Logger.Msg("Storing player world position and rotation."); + + preSwitchWorldPosition = MovementSystem.Instance.rotationPivot.transform.position; + preSwitchWorldPosition.y = MovementSystem.Instance.transform.position.y; + preSwitchWorldRotation = MovementSystem.Instance.rotationPivot.transform.rotation; + + MovementSystem.Instance.ChangeCrouch(false); + MovementSystem.Instance.ChangeProne(false); + MovementSystem.Instance.SetImmobilized(true); + } private void OnFailedSwitch(bool intoVR) { - MovementSystem _movementSystem = GetMovementSystemInstance(); - if (_movementSystem != null) - { - DesktopVRSwitch.Logger.Msg("Resetting MovementSystem mobility."); - _movementSystem.SetImmobilized(false); - } + DesktopVRSwitch.Logger.Msg("Resetting MovementSystem mobility."); + + MovementSystem.Instance.SetImmobilized(false); } private void OnPostSwitch(bool intoVR) @@ -65,27 +50,23 @@ public class MovementSystemTracker : VRModeTracker // Lazy MelonLoader.MelonCoroutines.Start(TeleportFrameAfter(intoVR)); } - + private IEnumerator TeleportFrameAfter(bool intoVR) { yield return null; // need to wait a frame - MovementSystem _movementSystem = GetMovementSystemInstance(); - if (_movementSystem != null) - { - DesktopVRSwitch.Logger.Msg("Resetting MovementSystem mobility and applying stored position and rotation."); + DesktopVRSwitch.Logger.Msg("Resetting MovementSystem mobility and applying stored position and rotation."); - _movementSystem.rotationPivot = Utils.GetPlayerCameraObject(intoVR).transform; - _movementSystem.TeleportToPosRot(preSwitchWorldPosition, preSwitchWorldRotation, false); + MovementSystem.Instance.rotationPivot = Utils.GetPlayerCameraObject(intoVR).transform; + MovementSystem.Instance.TeleportToPosRot(preSwitchWorldPosition, preSwitchWorldRotation, false); - if (!intoVR) - _movementSystem.UpdateColliderCenter(_movementSystem.transform.position); - - _movementSystem.ChangeCrouch(false); - _movementSystem.ChangeProne(false); - _movementSystem.SetImmobilized(false); - } + if (!intoVR) + MovementSystem.Instance.UpdateColliderCenter(MovementSystem.Instance.transform.position); + MovementSystem.Instance.ChangeCrouch(false); + MovementSystem.Instance.ChangeProne(false); + MovementSystem.Instance.SetImmobilized(false); + yield break; } } \ No newline at end of file diff --git a/DesktopVRSwitch/VRModeTrackers/PlayerSetupTracker.cs b/DesktopVRSwitch/VRModeTrackers/PlayerSetupTracker.cs index 4a5fbfe..0568589 100644 --- a/DesktopVRSwitch/VRModeTrackers/PlayerSetupTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/PlayerSetupTracker.cs @@ -16,15 +16,9 @@ public class PlayerSetupTracker : VRModeTracker private void OnPostSwitch(bool intoVR) { - PlayerSetup _playerSetup = PlayerSetup.Instance; - if (_playerSetup == null) - { - DesktopVRSwitch.Logger.Error("Error while getting PlayerSetup!"); - return; - } DesktopVRSwitch.Logger.Msg("Switching active PlayerSetup camera rigs. Updating Desktop camera FOV."); - _playerSetup.desktopCameraRig.SetActive(!intoVR); - _playerSetup.vrCameraRig.SetActive(intoVR); + PlayerSetup.Instance.desktopCameraRig.SetActive(!intoVR); + PlayerSetup.Instance.vrCameraRig.SetActive(intoVR); } } \ No newline at end of file diff --git a/DesktopVRSwitch/VRModeTrackers/PortableCameraTracker.cs b/DesktopVRSwitch/VRModeTrackers/PortableCameraTracker.cs index f2a616e..4a4f145 100644 --- a/DesktopVRSwitch/VRModeTrackers/PortableCameraTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/PortableCameraTracker.cs @@ -16,16 +16,10 @@ public class PortableCameraTracker : VRModeTracker private void OnPostSwitch(bool intoVR) { - PortableCamera _portableCamera = PortableCamera.Instance; - if (_portableCamera == null) - { - DesktopVRSwitch.Logger.Error("Error while getting PortableCamera!"); - return; - } DesktopVRSwitch.Logger.Msg("Forcing PortableCamera canvas mirroring off."); // Tell the game we are in mirror mode so it'll disable it (if enabled) - _portableCamera.mode = MirroringMode.Mirror; - _portableCamera.ChangeMirroring(); + PortableCamera.Instance.mode = MirroringMode.Mirror; + PortableCamera.Instance.ChangeMirroring(); } } diff --git a/DesktopVRSwitch/VRModeTrackers/VRTrackerManagerTracker.cs b/DesktopVRSwitch/VRModeTrackers/VRTrackerManagerTracker.cs index a24d85c..d4ab6d2 100644 --- a/DesktopVRSwitch/VRModeTrackers/VRTrackerManagerTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/VRTrackerManagerTracker.cs @@ -16,17 +16,15 @@ public class VRTrackerManagerTracker : VRModeTracker private void OnPostSwitch(bool intoVR) { - VRTrackerManager _vrTrackerManager = VRTrackerManager.Instance; - if (_vrTrackerManager == null) - { - DesktopVRSwitch.Logger.Error("Error while getting VRTrackerManager!"); - return; - } DesktopVRSwitch.Logger.Msg("Resetting VRTrackerManager."); - _vrTrackerManager.poses = null; - _vrTrackerManager.leftHand = null; - _vrTrackerManager.rightHand = null; - _vrTrackerManager.hasCheckedForKnuckles = false; + // 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 1014b4d..b8aae58 100644 --- a/DesktopVRSwitch/VRModeTrackers/ViewManagerTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/ViewManagerTracker.cs @@ -16,14 +16,8 @@ public class ViewManagerTracker : VRModeTracker public void OnPreSwitch(bool intoVR) { - ViewManager _viewManager = ViewManager.Instance; - if (_viewManager == null) - { - DesktopVRSwitch.Logger.Error("Error while getting ViewManager!"); - return; - } DesktopVRSwitch.Logger.Msg("Closing ViewManager - Main Menu."); - _viewManager.UiStateToggle(false); + ViewManager.Instance.UiStateToggle(false); } } \ No newline at end of file diff --git a/NAK_CVR_Mods.sln b/NAK_CVR_Mods.sln index 9fd2e8b..06bab62 100644 --- a/NAK_CVR_Mods.sln +++ b/NAK_CVR_Mods.sln @@ -63,6 +63,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HeadBobbingFix", "HeadBobbi EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClickToMove", "ClickToMove\ClickToMove.csproj", "{8D392BEE-E959-4906-A2A7-5EB9E3AE4D00}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ControllerFreeze", "ControllerFreeze\ControllerFreeze.csproj", "{ADAAC4FB-D78B-4FD2-B23A-EA6AF6B0B4A5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -189,6 +191,10 @@ Global {8D392BEE-E959-4906-A2A7-5EB9E3AE4D00}.Debug|Any CPU.Build.0 = Debug|Any CPU {8D392BEE-E959-4906-A2A7-5EB9E3AE4D00}.Release|Any CPU.ActiveCfg = Release|Any CPU {8D392BEE-E959-4906-A2A7-5EB9E3AE4D00}.Release|Any CPU.Build.0 = Release|Any CPU + {ADAAC4FB-D78B-4FD2-B23A-EA6AF6B0B4A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ADAAC4FB-D78B-4FD2-B23A-EA6AF6B0B4A5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ADAAC4FB-D78B-4FD2-B23A-EA6AF6B0B4A5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ADAAC4FB-D78B-4FD2-B23A-EA6AF6B0B4A5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE