From 900c6646af424f9cf0a3f88c2726f3cb08ce404c Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Tue, 20 Jun 2023 18:23:23 -0500 Subject: [PATCH] [DesktopVRSwitch] Handle CVRWorld- Post Processing & FOV settings. --- DesktopVRSwitch/HarmonyPatches.cs | 10 +--- DesktopVRSwitch/Main.cs | 16 ++---- .../CVRGestureRecognizerTracker.cs | 1 - .../VRModeTrackers/CVRWorldTracker.cs | 51 +++++++++++++++++++ .../CVR_InteractableManagerTracker.cs | 1 - .../VRModeTrackers/CVR_MenuManagerTracker.cs | 1 - .../CameraFacingObjectTracker.cs | 4 +- .../VRModeTrackers/CheckVRTracker.cs | 1 - .../VRModeTrackers/CohtmlHudTracker.cs | 1 - .../VRModeTrackers/HudOperationsTracker.cs | 1 - .../VRModeTrackers/IKSystemTracker.cs | 1 - .../VRModeTrackers/MetaPortTracker.cs | 6 +-- .../VRModeTrackers/MovementSystemTracker.cs | 1 + .../VRModeTrackers/PlayerSetupTracker.cs | 12 ----- .../VRModeTrackers/PortableCameraTracker.cs | 1 - .../VRModeTrackers/VRTrackerManagerTracker.cs | 1 - .../VRModeTrackers/ViewManagerTracker.cs | 1 - 17 files changed, 62 insertions(+), 48 deletions(-) create mode 100644 DesktopVRSwitch/VRModeTrackers/CVRWorldTracker.cs diff --git a/DesktopVRSwitch/HarmonyPatches.cs b/DesktopVRSwitch/HarmonyPatches.cs index 0e341ff..b1b840f 100644 --- a/DesktopVRSwitch/HarmonyPatches.cs +++ b/DesktopVRSwitch/HarmonyPatches.cs @@ -47,14 +47,8 @@ class CVRWorldPatches { [HarmonyPostfix] [HarmonyPatch(typeof(CVRWorld), nameof(CVRWorld.SetDefaultCamValues))] - static void Postfix_CVRWorld_SetDefaultCamValues() - { - ReferenceCameraPatch.OnWorldLoad(); - } - - [HarmonyPostfix] [HarmonyPatch(typeof(CVRWorld), nameof(CVRWorld.CopyRefCamValues))] - static void Postfix_CVRWorld_CopyRefCamValues() + static void Postfix_CVRWorld_HandleCamValues() { ReferenceCameraPatch.OnWorldLoad(); } @@ -66,7 +60,7 @@ class CameraFacingObjectPatches [HarmonyPatch(typeof(CameraFacingObject), nameof(CameraFacingObject.Start))] static void Postfix_CameraFacingObject_Start(ref CameraFacingObject __instance) { - __instance.gameObject.AddComponent()._cameraFacingObject = __instance; + __instance.gameObject.AddComponent(); } } diff --git a/DesktopVRSwitch/Main.cs b/DesktopVRSwitch/Main.cs index 7faab89..77aab9d 100644 --- a/DesktopVRSwitch/Main.cs +++ b/DesktopVRSwitch/Main.cs @@ -3,19 +3,6 @@ using MelonLoader; using NAK.DesktopVRSwitch.VRModeTrackers; using UnityEngine; -/** - I know the TryCatchHell thing might be a bit exessive, but it is - built so if a user that happens to have access to a build I do not, - I will have a good idea of what broke and where, and what to look out - for when updates/experimentals release. (which has happened a few times) - - 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 - components that may or may not change between builds without breaking the rest of the mod. -**/ - namespace NAK.DesktopVRSwitch; public class DesktopVRSwitch : MelonMod @@ -94,6 +81,9 @@ public class DesktopVRSwitch : MelonMod // Portable camera tracker VRModeSwitchManager.RegisterVRModeTracker(new PortableCameraTracker()); + + // CVRWorld tracker - Must come after PlayerSetupTracker + VRModeSwitchManager.RegisterVRModeTracker(new CVRWorldTracker()); } void ApplyPatches(Type type) diff --git a/DesktopVRSwitch/VRModeTrackers/CVRGestureRecognizerTracker.cs b/DesktopVRSwitch/VRModeTrackers/CVRGestureRecognizerTracker.cs index 92490ae..b87a7d7 100644 --- a/DesktopVRSwitch/VRModeTrackers/CVRGestureRecognizerTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/CVRGestureRecognizerTracker.cs @@ -1,5 +1,4 @@ using ABI_RC.Core.Savior; - using UnityEngine; namespace NAK.DesktopVRSwitch.VRModeTrackers; diff --git a/DesktopVRSwitch/VRModeTrackers/CVRWorldTracker.cs b/DesktopVRSwitch/VRModeTrackers/CVRWorldTracker.cs new file mode 100644 index 0000000..394ebab --- /dev/null +++ b/DesktopVRSwitch/VRModeTrackers/CVRWorldTracker.cs @@ -0,0 +1,51 @@ +using ABI.CCK.Components; +using ABI_RC.Core.InteractionSystem; +using ABI_RC.Core.Player; +using UnityEngine; + +namespace NAK.DesktopVRSwitch.VRModeTrackers; + +public class CVRWorldTracker : VRModeTracker +{ + public override void TrackerInit() + { + VRModeSwitchManager.OnPostVRModeSwitch += OnPostSwitch; + } + + public override void TrackerDestroy() + { + VRModeSwitchManager.OnPostVRModeSwitch -= OnPostSwitch; + } + + 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); + } + + private void UpdateCVRDesktopCameraController(CVRWorld _cvrWorld) + { + // 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.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; + + // 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. + } +} \ No newline at end of file diff --git a/DesktopVRSwitch/VRModeTrackers/CVR_InteractableManagerTracker.cs b/DesktopVRSwitch/VRModeTrackers/CVR_InteractableManagerTracker.cs index 6e84653..824d72a 100644 --- a/DesktopVRSwitch/VRModeTrackers/CVR_InteractableManagerTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/CVR_InteractableManagerTracker.cs @@ -1,6 +1,5 @@ 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 3a8bf55..dcf18c6 100644 --- a/DesktopVRSwitch/VRModeTrackers/CVR_MenuManagerTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/CVR_MenuManagerTracker.cs @@ -1,6 +1,5 @@ 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 29730b3..f43289a 100644 --- a/DesktopVRSwitch/VRModeTrackers/CameraFacingObjectTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/CameraFacingObjectTracker.cs @@ -5,10 +5,11 @@ namespace NAK.DesktopVRSwitch.VRModeTrackers; public class CameraFacingObjectTracker : MonoBehaviour { - internal CameraFacingObject _cameraFacingObject; + CameraFacingObject _cameraFacingObject; void Start() { + _cameraFacingObject = GetComponent(); VRModeSwitchManager.OnPostVRModeSwitch += OnPostSwitch; } @@ -19,6 +20,7 @@ public class CameraFacingObjectTracker : MonoBehaviour public void OnPostSwitch(bool intoVR) { + // TODO: cache camera _cameraFacingObject.m_Camera = Utils.GetPlayerCameraObject(intoVR).GetComponent(); } } \ No newline at end of file diff --git a/DesktopVRSwitch/VRModeTrackers/CheckVRTracker.cs b/DesktopVRSwitch/VRModeTrackers/CheckVRTracker.cs index d494308..7dfa7e4 100644 --- a/DesktopVRSwitch/VRModeTrackers/CheckVRTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/CheckVRTracker.cs @@ -1,6 +1,5 @@ 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 12a084c..e6583ae 100644 --- a/DesktopVRSwitch/VRModeTrackers/CohtmlHudTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/CohtmlHudTracker.cs @@ -1,6 +1,5 @@ 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 745934f..f25a03a 100644 --- a/DesktopVRSwitch/VRModeTrackers/HudOperationsTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/HudOperationsTracker.cs @@ -1,6 +1,5 @@ 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 ab9ef3d..9e3a300 100644 --- a/DesktopVRSwitch/VRModeTrackers/IKSystemTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/IKSystemTracker.cs @@ -2,7 +2,6 @@ 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 26dd910..3d73c7a 100644 --- a/DesktopVRSwitch/VRModeTrackers/MetaPortTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/MetaPortTracker.cs @@ -57,14 +57,12 @@ public class MetaPortTracker : VRModeTracker if (intoVR) { // Testing - XRSettings.eyeTextureResolutionScale = 1; - XRSettings.gameViewRenderMode = DesktopVRSwitch.EntryRenderVRGameView.Value ? GameViewRenderMode.LeftEye : GameViewRenderMode.None; + //XRSettings.gameViewRenderMode = DesktopVRSwitch.EntryRenderVRGameView.Value ? GameViewRenderMode.LeftEye : GameViewRenderMode.None; + XRSettings.eyeTextureResolutionScale = 1; // unsure if will cause issues with FSR? SteamVR_Settings.instance.pauseGameWhenDashboardVisible = false; if (MetaPort.Instance.settings.GetSettingsBool("InteractionTobiiEyeTracking", false)) - { MetaPort.Instance.TobiiXrInitializer.Initialize(); - } return; } diff --git a/DesktopVRSwitch/VRModeTrackers/MovementSystemTracker.cs b/DesktopVRSwitch/VRModeTrackers/MovementSystemTracker.cs index 534f7a8..22de1ed 100644 --- a/DesktopVRSwitch/VRModeTrackers/MovementSystemTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/MovementSystemTracker.cs @@ -23,6 +23,7 @@ public class MovementSystemTracker : VRModeTracker VRModeSwitchManager.OnPostVRModeSwitch -= OnPostSwitch; } + // why do i do this private MovementSystem GetMovementSystemInstance() { MovementSystem _movementSystem = MovementSystem.Instance; diff --git a/DesktopVRSwitch/VRModeTrackers/PlayerSetupTracker.cs b/DesktopVRSwitch/VRModeTrackers/PlayerSetupTracker.cs index 825cd57..4a5fbfe 100644 --- a/DesktopVRSwitch/VRModeTrackers/PlayerSetupTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/PlayerSetupTracker.cs @@ -1,6 +1,5 @@ using ABI_RC.Core.Player; - namespace NAK.DesktopVRSwitch.VRModeTrackers; public class PlayerSetupTracker : VRModeTracker @@ -27,16 +26,5 @@ public class PlayerSetupTracker : VRModeTracker _playerSetup.desktopCameraRig.SetActive(!intoVR); _playerSetup.vrCameraRig.SetActive(intoVR); - - // This might error if we started in VR. - // '_cam' is not set until Start(). - 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. } } \ No newline at end of file diff --git a/DesktopVRSwitch/VRModeTrackers/PortableCameraTracker.cs b/DesktopVRSwitch/VRModeTrackers/PortableCameraTracker.cs index 654964b..f2a616e 100644 --- a/DesktopVRSwitch/VRModeTrackers/PortableCameraTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/PortableCameraTracker.cs @@ -1,6 +1,5 @@ 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 d1d8044..a24d85c 100644 --- a/DesktopVRSwitch/VRModeTrackers/VRTrackerManagerTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/VRTrackerManagerTracker.cs @@ -1,6 +1,5 @@ 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 e3500f7..1014b4d 100644 --- a/DesktopVRSwitch/VRModeTrackers/ViewManagerTracker.cs +++ b/DesktopVRSwitch/VRModeTrackers/ViewManagerTracker.cs @@ -1,6 +1,5 @@ using ABI_RC.Core.InteractionSystem; - namespace NAK.DesktopVRSwitch.VRModeTrackers; public class ViewManagerTracker : VRModeTracker