From 1e636e3395d8fcabadb02d194c40ddc9eeef3623 Mon Sep 17 00:00:00 2001
From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com>
Date: Fri, 17 Feb 2023 06:10:49 -0600
Subject: [PATCH] backport
---
DesktopVRSwitch/DesktopVRSwitch.cs | 125 +++++++++++++
DesktopVRSwitch/DesktopVRSwitch.csproj | 4 +
DesktopVRSwitch/DesktopVRSwitch.sln | 14 +-
DesktopVRSwitch/HarmonyPatches.cs | 92 ++++++++++
DesktopVRSwitch/Main.cs | 37 ++++
.../Patches/CVRPickupObjectTracker.cs | 32 ++++
.../Patches/CameraFacingObjectTracker.cs | 24 +++
DesktopVRSwitch/Patches/IKSystemTracker.cs | 57 ++++++
.../Patches/MovementSystemTracker.cs | 39 ++++
.../Patches/ReferenceCameraPatch.cs | 91 ++++++++++
.../Patches/VRModeSwitchTracker.cs | 33 ++++
DesktopVRSwitch/Properties/AssemblyInfo.cs | 22 +++
DesktopVRSwitch/TryCatchHell.cs | 167 ++++++++++++++++++
13 files changed, 732 insertions(+), 5 deletions(-)
create mode 100644 DesktopVRSwitch/DesktopVRSwitch.cs
create mode 100644 DesktopVRSwitch/HarmonyPatches.cs
create mode 100644 DesktopVRSwitch/Patches/CameraFacingObjectTracker.cs
create mode 100644 DesktopVRSwitch/Patches/IKSystemTracker.cs
create mode 100644 DesktopVRSwitch/Patches/MovementSystemTracker.cs
create mode 100644 DesktopVRSwitch/Patches/ReferenceCameraPatch.cs
create mode 100644 DesktopVRSwitch/Patches/VRModeSwitchTracker.cs
create mode 100644 DesktopVRSwitch/TryCatchHell.cs
diff --git a/DesktopVRSwitch/DesktopVRSwitch.cs b/DesktopVRSwitch/DesktopVRSwitch.cs
new file mode 100644
index 0000000..593d475
--- /dev/null
+++ b/DesktopVRSwitch/DesktopVRSwitch.cs
@@ -0,0 +1,125 @@
+using NAK.Melons.DesktopVRSwitch.Patches;
+using System.Collections;
+using UnityEngine;
+using UnityEngine.XR;
+using Valve.VR;
+
+namespace NAK.Melons.DesktopVRSwitch;
+
+public class DesktopVRSwitch : MonoBehaviour
+{
+ //Settings
+ public bool _reloadLocalAvatar = true;
+
+ //Internal Stuff
+ private bool _switchInProgress = false;
+
+ void Start()
+ {
+ //do not pause game, this breaks dynbones & trackers
+ SteamVR_Settings.instance.pauseGameWhenDashboardVisible = false;
+ }
+
+ void Update()
+ {
+ if (Input.GetKeyDown(KeyCode.F6) && Input.GetKey(KeyCode.LeftControl))
+ {
+ SwitchXRMode();
+ }
+ }
+
+ public void SwitchXRMode()
+ {
+ if (_switchInProgress) return;
+ if (!IsInXR())
+ {
+ StartCoroutine(StartXRSystem());
+ }
+ else
+ {
+ StartCoroutine(StopXR());
+ }
+ }
+
+ public bool IsInXR() => XRSettings.enabled;
+
+ private IEnumerator StartXRSystem()
+ {
+ BeforeXRModeSwitch(true);
+ XRSettings.LoadDeviceByName("OpenVR");
+ yield return null;
+ if (string.IsNullOrEmpty(XRSettings.loadedDeviceName))
+ {
+ DesktopVRSwitchMod.Logger.Error("Initializing VR Failed. Is there no VR device connected?");
+ }
+ else
+ {
+ DesktopVRSwitchMod.Logger.Msg("Starting SteamVR...");
+ XRSettings.enabled = true;
+ //force steamvr to reinitialize input
+ //this does SteamVR_Input.actionSets[0].Activate() for us (we deactivate in StopVR())
+ //but only if SteamVR_Settings.instance.activateFirstActionSetOnStart is enabled
+ //which in ChilloutVR, it is, because all those settings are default
+ SteamVR_Input.Initialize(true);
+ yield return null;
+ AfterXRModeSwitch(true);
+ }
+ yield break;
+ }
+
+ private IEnumerator StopXR()
+ {
+ BeforeXRModeSwitch(false);
+ yield return null;
+ if (!string.IsNullOrEmpty(XRSettings.loadedDeviceName))
+ {
+ //deactivate the action set so SteamVR_Input.Initialize can reactivate
+ SteamVR_Input.actionSets[0].Deactivate(SteamVR_Input_Sources.Any);
+ SteamVR.SafeDispose(); //idk
+ XRSettings.LoadDeviceByName("");
+ XRSettings.enabled = false;
+ yield return null;
+ AfterXRModeSwitch(false);
+ }
+ yield break;
+ }
+
+ //one frame before switch attempt
+ public void BeforeXRModeSwitch(bool enterXR)
+ {
+ //let tracked objects know we are attempting to switch
+ VRModeSwitchTracker.PreVRModeSwitch(enterXR);
+ }
+
+ //one frame after switch attempt
+ public void AfterXRModeSwitch(bool enterXR)
+ {
+ //reset physics time to Desktop default
+ Time.fixedDeltaTime = 0.02f;
+
+ //these two must come first
+ TryCatchHell.SetCheckVR(enterXR);
+ TryCatchHell.SetMetaPort(enterXR);
+
+ //the bulk of funni changes
+ TryCatchHell.RepositionCohtmlHud(enterXR);
+ TryCatchHell.UpdateHudOperations(enterXR);
+ TryCatchHell.DisableMirrorCanvas();
+ TryCatchHell.SwitchActiveCameraRigs(enterXR);
+ TryCatchHell.ResetCVRInputManager();
+ TryCatchHell.UpdateRichPresence();
+ TryCatchHell.UpdateGestureReconizerCam();
+
+ //let tracked objects know we switched
+ VRModeSwitchTracker.PostVRModeSwitch(enterXR);
+
+ //reload avatar by default, optional for debugging
+ if (_reloadLocalAvatar)
+ {
+ TryCatchHell.ReloadLocalAvatar();
+ }
+
+ _switchInProgress = false;
+ }
+}
+
diff --git a/DesktopVRSwitch/DesktopVRSwitch.csproj b/DesktopVRSwitch/DesktopVRSwitch.csproj
index adb74e4..57841c7 100644
--- a/DesktopVRSwitch/DesktopVRSwitch.csproj
+++ b/DesktopVRSwitch/DesktopVRSwitch.csproj
@@ -43,7 +43,11 @@
..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Unity.Postprocessing.Runtime.dll
+<<<<<<< Updated upstream
..\..\..\DakyModsCVR\ManagedLibs\Unity.TextMeshPro.dll
+=======
+ C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Unity.TextMeshPro.dll
+>>>>>>> Stashed changes
..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.AnimationModule.dll
diff --git a/DesktopVRSwitch/DesktopVRSwitch.sln b/DesktopVRSwitch/DesktopVRSwitch.sln
index 758488c..8d77157 100644
--- a/DesktopVRSwitch/DesktopVRSwitch.sln
+++ b/DesktopVRSwitch/DesktopVRSwitch.sln
@@ -3,7 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32630.192
MinimumVisualStudioVersion = 10.0.40219.1
+<<<<<<< Updated upstream
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesktopVRSwitch", "DesktopVRSwitch.csproj", "{4008E6D1-32F9-449B-8820-80ACF0ED8233}"
+=======
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesktopVRSwitch", "DesktopVRSwitch.csproj", "{D8B326EF-AC8E-4D71-AFC9-0658831B059B}"
+>>>>>>> Stashed changes
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -11,15 +15,15 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {4008E6D1-32F9-449B-8820-80ACF0ED8233}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {4008E6D1-32F9-449B-8820-80ACF0ED8233}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {4008E6D1-32F9-449B-8820-80ACF0ED8233}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {4008E6D1-32F9-449B-8820-80ACF0ED8233}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D8B326EF-AC8E-4D71-AFC9-0658831B059B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D8B326EF-AC8E-4D71-AFC9-0658831B059B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D8B326EF-AC8E-4D71-AFC9-0658831B059B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D8B326EF-AC8E-4D71-AFC9-0658831B059B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
- SolutionGuid = {3C86465A-87F5-49EF-915C-5B5F568A8815}
+ SolutionGuid = {9F6A1F88-B3D1-46F3-9370-9DDAE1F707C3}
EndGlobalSection
EndGlobal
diff --git a/DesktopVRSwitch/HarmonyPatches.cs b/DesktopVRSwitch/HarmonyPatches.cs
new file mode 100644
index 0000000..6790699
--- /dev/null
+++ b/DesktopVRSwitch/HarmonyPatches.cs
@@ -0,0 +1,92 @@
+using ABI.CCK.Components;
+using ABI_RC.Core.Player;
+using ABI_RC.Core.Savior;
+using ABI_RC.Core.Util.Object_Behaviour;
+using ABI_RC.Systems.IK;
+using ABI_RC.Systems.MovementSystem;
+using HarmonyLib;
+using NAK.Melons.DesktopVRSwitch.Patches;
+using UnityEngine;
+
+namespace NAK.Melons.DesktopVRSwitch.HarmonyPatches;
+
+internal class PlayerSetupPatches
+{
+ [HarmonyPostfix]
+ [HarmonyPatch(typeof(PlayerSetup), "Start")]
+ private static void Postfix_PlayerSetup_Start(ref PlayerSetup __instance)
+ {
+ if (CheckVR.Instance != null)
+ {
+ CheckVR.Instance.gameObject.AddComponent();
+ return;
+ }
+ __instance.gameObject.AddComponent();
+ DesktopVRSwitchMod.Logger.Error("CheckVR not found. Reverting to fallback method. This should never happen!");
+ }
+}
+
+internal class MovementSystemPatches
+{
+ [HarmonyPostfix]
+ [HarmonyPatch(typeof(MovementSystem), "Start")]
+ private static void Postfix_MovementSystem_Start(ref MovementSystem __instance)
+ {
+ __instance.gameObject.AddComponent();
+ }
+}
+
+internal class CVRPickupObjectPatches
+{
+ [HarmonyPrefix]
+ [HarmonyPatch(typeof(CVRPickupObject), "Start")]
+ private 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);
+ }
+ }
+}
+
+internal class CVRWorldPatches
+{
+ [HarmonyPostfix]
+ [HarmonyPatch(typeof(CVRWorld), "SetDefaultCamValues")]
+ private static void CVRWorld_SetDefaultCamValues_Postfix()
+ {
+ ReferenceCameraPatch.OnWorldLoad();
+ }
+
+ [HarmonyPostfix]
+ [HarmonyPatch(typeof(CVRWorld), "CopyRefCamValues")]
+ private static void CVRWorld_CopyRefCamValues_Postfix()
+ {
+ ReferenceCameraPatch.OnWorldLoad();
+ }
+}
+
+internal class CameraFacingObjectPatches
+{
+ [HarmonyPostfix]
+ [HarmonyPatch(typeof(CameraFacingObject), "Start")]
+ private static void Postfix_CameraFacingObject_Start(ref CameraFacingObject __instance)
+ {
+ __instance.gameObject.AddComponent();
+ }
+}
+
+internal class IKSystemPatches
+{
+ [HarmonyPostfix]
+ [HarmonyPatch(typeof(IKSystem), "Start")]
+ private static void Postfix_IKSystem_Start(ref IKSystem __instance)
+ {
+ __instance.gameObject.AddComponent();
+ }
+}
\ No newline at end of file
diff --git a/DesktopVRSwitch/Main.cs b/DesktopVRSwitch/Main.cs
index a6ca2f9..092c575 100644
--- a/DesktopVRSwitch/Main.cs
+++ b/DesktopVRSwitch/Main.cs
@@ -1,3 +1,4 @@
+<<<<<<< Updated upstream
using ABI_RC.Core.Player;
using MelonLoader;
@@ -55,5 +56,41 @@ public class DesktopVRSwitch : MelonMod
if (!DesktopVRSwitchHelper.Instance) return;
DesktopVRSwitchHelper.Instance.SettingTimedErrorCatch = m_entryTimedErrorCatch.Value;
DesktopVRSwitchHelper.Instance.SettingTimedErrorTimer = m_entryTimedErrorTimer.Value;
+=======
+using MelonLoader;
+
+namespace NAK.Melons.DesktopVRSwitch;
+
+public class DesktopVRSwitchMod : MelonMod
+{
+ internal const string SettingsCategory = "DesktopVRSwitch";
+ internal static MelonPreferences_Category m_categoryDesktopVRSwitch;
+ internal static MelonLogger.Instance Logger;
+
+ public override void OnInitializeMelon()
+ {
+ Logger = LoggerInstance;
+ m_categoryDesktopVRSwitch = MelonPreferences.CreateCategory(SettingsCategory);
+
+ ApplyPatches(typeof(HarmonyPatches.PlayerSetupPatches));
+ ApplyPatches(typeof(HarmonyPatches.CVRPickupObjectPatches));
+ ApplyPatches(typeof(HarmonyPatches.CVRWorldPatches));
+ ApplyPatches(typeof(HarmonyPatches.CameraFacingObjectPatches));
+ ApplyPatches(typeof(HarmonyPatches.IKSystemPatches));
+ ApplyPatches(typeof(HarmonyPatches.MovementSystemPatches));
+ }
+
+ private void ApplyPatches(Type type)
+ {
+ try
+ {
+ HarmonyInstance.PatchAll(type);
+ }
+ catch (Exception e)
+ {
+ Logger.Msg($"Failed while patching {type.Name}!");
+ Logger.Error(e);
+ }
+>>>>>>> Stashed changes
}
}
\ No newline at end of file
diff --git a/DesktopVRSwitch/Patches/CVRPickupObjectTracker.cs b/DesktopVRSwitch/Patches/CVRPickupObjectTracker.cs
index 5bb7943..71615cf 100644
--- a/DesktopVRSwitch/Patches/CVRPickupObjectTracker.cs
+++ b/DesktopVRSwitch/Patches/CVRPickupObjectTracker.cs
@@ -1,11 +1,15 @@
using ABI.CCK.Components;
+<<<<<<< Updated upstream
using ABI_RC.Core.Savior;
using HarmonyLib;
using MelonLoader;
+=======
+>>>>>>> Stashed changes
using UnityEngine;
//Thanks Ben! I was scared of transpiler so I reworked a bit...
+<<<<<<< Updated upstream
namespace DesktopVRSwitch.Patches;
[HarmonyPatch]
@@ -59,3 +63,31 @@ public class CVRPickupObjectTracker : MonoBehaviour
previousGripOrigin.Remove(pickupObject);
}
}
+=======
+namespace NAK.Melons.DesktopVRSwitch.Patches;
+
+public class CVRPickupObjectTracker : MonoBehaviour
+{
+ public CVRPickupObject pickupObject;
+ public Transform storedGripOrigin;
+
+ void Start()
+ {
+ VRModeSwitchTracker.OnPostVRModeSwitch += PostVRModeSwitch;
+ }
+
+ void OnDestroy()
+ {
+ VRModeSwitchTracker.OnPostVRModeSwitch -= PostVRModeSwitch;
+ }
+
+ public void PostVRModeSwitch(bool enterXR, Camera activeCamera)
+ {
+ if (pickupObject != null)
+ {
+ if (pickupObject._controllerRay != null) pickupObject._controllerRay.DropObject(true);
+ (storedGripOrigin, pickupObject.gripOrigin) = (pickupObject.gripOrigin, storedGripOrigin);
+ }
+ }
+}
+>>>>>>> Stashed changes
diff --git a/DesktopVRSwitch/Patches/CameraFacingObjectTracker.cs b/DesktopVRSwitch/Patches/CameraFacingObjectTracker.cs
new file mode 100644
index 0000000..b99dd7f
--- /dev/null
+++ b/DesktopVRSwitch/Patches/CameraFacingObjectTracker.cs
@@ -0,0 +1,24 @@
+using ABI_RC.Core.Util.Object_Behaviour;
+using UnityEngine;
+
+namespace NAK.Melons.DesktopVRSwitch.Patches;
+
+public class CameraFacingObjectTracker : MonoBehaviour
+{
+ public CameraFacingObject cameraFacingObject;
+ void Start()
+ {
+ cameraFacingObject = GetComponent();
+ VRModeSwitchTracker.OnPostVRModeSwitch += PostVRModeSwitch;
+ }
+
+ void OnDestroy()
+ {
+ VRModeSwitchTracker.OnPostVRModeSwitch -= PostVRModeSwitch;
+ }
+
+ public void PostVRModeSwitch(bool enterXR, Camera activeCamera)
+ {
+ cameraFacingObject.m_Camera = activeCamera;
+ }
+}
\ No newline at end of file
diff --git a/DesktopVRSwitch/Patches/IKSystemTracker.cs b/DesktopVRSwitch/Patches/IKSystemTracker.cs
new file mode 100644
index 0000000..2bd535d
--- /dev/null
+++ b/DesktopVRSwitch/Patches/IKSystemTracker.cs
@@ -0,0 +1,57 @@
+using ABI_RC.Systems.IK;
+using ABI_RC.Systems.IK.SubSystems;
+using ABI_RC.Systems.IK.TrackingModules;
+using HarmonyLib;
+using UnityEngine;
+using System.Reflection;
+
+namespace NAK.Melons.DesktopVRSwitch.Patches;
+
+public class IKSystemTracker : MonoBehaviour
+{
+ public IKSystem ikSystem;
+ public Traverse _traverseModules;
+
+ void Start()
+ {
+ ikSystem = GetComponent();
+ _traverseModules = Traverse.Create(ikSystem).Field("_trackingModules");
+ VRModeSwitchTracker.OnPostVRModeSwitch += PostVRModeSwitch;
+ }
+ void OnDestroy()
+ {
+ VRModeSwitchTracker.OnPostVRModeSwitch -= PostVRModeSwitch;
+ }
+
+ public void PostVRModeSwitch(bool enterXR, Camera activeCamera)
+ {
+ var _trackingModules = _traverseModules.GetValue>();
+ SteamVRTrackingModule openXRTrackingModule = _trackingModules.FirstOrDefault(m => m is SteamVRTrackingModule) as SteamVRTrackingModule;
+ if (openXRTrackingModule != null)
+ {
+ if (enterXR)
+ {
+ openXRTrackingModule.ModuleStart();
+ }
+ else
+ {
+ //why named destroy when it doesnt ?
+ openXRTrackingModule.ModuleDestroy();
+ }
+ }
+ else
+ {
+ var steamVRTrackingModule = CreateSteamVRTrackingModule();
+ ikSystem.AddTrackingModule(steamVRTrackingModule);
+ }
+ }
+
+ //thanks for marking the constructor as internal
+ private SteamVRTrackingModule CreateSteamVRTrackingModule()
+ {
+ var steamVRTrackingModuleType = typeof(SteamVRTrackingModule);
+ var constructor = steamVRTrackingModuleType.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null);
+ var instance = constructor.Invoke(null);
+ return (SteamVRTrackingModule)instance;
+ }
+}
\ No newline at end of file
diff --git a/DesktopVRSwitch/Patches/MovementSystemTracker.cs b/DesktopVRSwitch/Patches/MovementSystemTracker.cs
new file mode 100644
index 0000000..54bfaf6
--- /dev/null
+++ b/DesktopVRSwitch/Patches/MovementSystemTracker.cs
@@ -0,0 +1,39 @@
+using ABI_RC.Systems.MovementSystem;
+using UnityEngine;
+
+namespace NAK.Melons.DesktopVRSwitch.Patches;
+
+public class MovementSystemTracker : MonoBehaviour
+{
+ public MovementSystem movementSystem;
+
+ public Vector3 preSwitchWorldPosition;
+ public Quaternion preSwitchWorldRotation;
+
+ void Start()
+ {
+ movementSystem = GetComponent();
+ VRModeSwitchTracker.OnPostVRModeSwitch += PreVRModeSwitch;
+ VRModeSwitchTracker.OnPostVRModeSwitch += PostVRModeSwitch;
+ }
+
+ void OnDestroy()
+ {
+ VRModeSwitchTracker.OnPostVRModeSwitch -= PreVRModeSwitch;
+ VRModeSwitchTracker.OnPostVRModeSwitch -= PostVRModeSwitch;
+ }
+
+ public void PreVRModeSwitch(bool enterXR, Camera activeCamera)
+ {
+ preSwitchWorldPosition = movementSystem.rotationPivot.transform.position;
+ preSwitchWorldRotation = movementSystem.rotationPivot.transform.rotation;
+ }
+
+ public void PostVRModeSwitch(bool enterXR, Camera activeCamera)
+ {
+ //lazy way of correcting Desktop & VR offset issue (game does the maths)
+ movementSystem.TeleportToPosRot(preSwitchWorldPosition, preSwitchWorldRotation, false);
+ //recenter desktop collision to player object
+ if (!enterXR) movementSystem.UpdateColliderCenter(movementSystem.transform.position);
+ }
+}
\ No newline at end of file
diff --git a/DesktopVRSwitch/Patches/ReferenceCameraPatch.cs b/DesktopVRSwitch/Patches/ReferenceCameraPatch.cs
new file mode 100644
index 0000000..9681873
--- /dev/null
+++ b/DesktopVRSwitch/Patches/ReferenceCameraPatch.cs
@@ -0,0 +1,91 @@
+using ABI_RC.Core.Base;
+using ABI_RC.Core.Player;
+using ABI_RC.Core.Savior;
+using Aura2API;
+using BeautifyEffect;
+using UnityEngine;
+using UnityEngine.AzureSky;
+using UnityEngine.Rendering.PostProcessing;
+using Object = UnityEngine.Object;
+
+namespace NAK.Melons.DesktopVRSwitch.Patches;
+
+internal class ReferenceCameraPatch
+{
+ internal static void OnWorldLoad()
+ {
+ Camera activeCamera = (MetaPort.Instance.isUsingVr ? PlayerSetup.Instance.vrCamera : PlayerSetup.Instance.desktopCamera).GetComponent();
+ Camera inactiveCamera = (MetaPort.Instance.isUsingVr ? PlayerSetup.Instance.desktopCamera : PlayerSetup.Instance.vrCamera).GetComponent();
+ CopyToInactiveCam(activeCamera, inactiveCamera);
+ }
+
+ internal static void CopyToInactiveCam(Camera activeCam, Camera inactiveCam)
+ {
+ DesktopVRSwitchMod.Logger.Msg("Copying active camera settings & components to inactive camera.");
+
+ //steal basic settings
+ inactiveCam.farClipPlane = activeCam.farClipPlane;
+ inactiveCam.nearClipPlane = activeCam.nearClipPlane;
+ inactiveCam.cullingMask = activeCam.cullingMask;
+ inactiveCam.depthTextureMode = activeCam.depthTextureMode;
+
+ //steal post processing if added
+ PostProcessLayer ppLayerActiveCam = activeCam.GetComponent();
+ PostProcessLayer ppLayerInactiveCam = inactiveCam.AddComponentIfMissing();
+ if (ppLayerActiveCam != null && ppLayerInactiveCam != null)
+ {
+ ppLayerInactiveCam.enabled = ppLayerActiveCam.enabled;
+ ppLayerInactiveCam.volumeLayer = ppLayerActiveCam.volumeLayer;
+ }
+
+ //what even is this aura camera stuff
+ AuraCamera auraActiveCam = activeCam.GetComponent();
+ AuraCamera auraInactiveCam = inactiveCam.AddComponentIfMissing();
+ if (auraActiveCam != null && auraInactiveCam != null)
+ {
+ auraInactiveCam.enabled = auraActiveCam.enabled;
+ auraInactiveCam.frustumSettings = auraActiveCam.frustumSettings;
+ }
+ else
+ {
+ auraInactiveCam.enabled = false;
+ }
+
+ //flare layer thing? the sun :_:_:_:_:_:
+ FlareLayer flareActiveCam = activeCam.GetComponent();
+ FlareLayer flareInactiveCam = inactiveCam.AddComponentIfMissing();
+ if (flareActiveCam != null && flareInactiveCam != null)
+ {
+ flareInactiveCam.enabled = flareActiveCam.enabled;
+ }
+ else
+ {
+ flareInactiveCam.enabled = false;
+ }
+
+ //and now what the fuck is fog scattering
+ AzureFogScattering azureFogActiveCam = activeCam.GetComponent();
+ AzureFogScattering azureFogInactiveCam = inactiveCam.AddComponentIfMissing();
+ if (azureFogActiveCam != null && azureFogInactiveCam != null)
+ {
+ azureFogInactiveCam.fogScatteringMaterial = azureFogActiveCam.fogScatteringMaterial;
+ }
+ else
+ {
+ Object.Destroy(inactiveCam.GetComponent());
+ }
+
+ //why is there so many thingsssssssss
+ Beautify beautifyActiveCam = activeCam.GetComponent();
+ Beautify beautifyInactiveCam = inactiveCam.AddComponentIfMissing();
+ if (beautifyActiveCam != null && beautifyInactiveCam != null)
+ {
+ beautifyInactiveCam.quality = beautifyActiveCam.quality;
+ beautifyInactiveCam.profile = beautifyActiveCam.profile;
+ }
+ else
+ {
+ Object.Destroy(inactiveCam.gameObject.GetComponent());
+ }
+ }
+}
\ No newline at end of file
diff --git a/DesktopVRSwitch/Patches/VRModeSwitchTracker.cs b/DesktopVRSwitch/Patches/VRModeSwitchTracker.cs
new file mode 100644
index 0000000..e6cb2c9
--- /dev/null
+++ b/DesktopVRSwitch/Patches/VRModeSwitchTracker.cs
@@ -0,0 +1,33 @@
+using ABI_RC.Core.Player;
+using UnityEngine;
+using UnityEngine.Events;
+
+namespace NAK.Melons.DesktopVRSwitch.Patches;
+
+public class VRModeSwitchTracker
+{
+ public static event UnityAction OnPreVRModeSwitch;
+ public static event UnityAction OnPostVRModeSwitch;
+
+ public static void PreVRModeSwitch(bool enterXR)
+ {
+ TryCatchHell.TryCatchWrapper(() =>
+ {
+ DesktopVRSwitchMod.Logger.Msg("Invoking VRModeSwitchTracker.OnPreVRModeSwitch.");
+ Camera activeCamera = PlayerSetup.Instance.GetActiveCamera().GetComponent();
+ VRModeSwitchTracker.OnPreVRModeSwitch?.Invoke(enterXR, activeCamera);
+ },
+ "Error while invoking VRModeSwitchTracker.OnPreVRModeSwitch. Did someone do a fucky?");
+ }
+
+ public static void PostVRModeSwitch(bool enterXR)
+ {
+ TryCatchHell.TryCatchWrapper(() =>
+ {
+ DesktopVRSwitchMod.Logger.Msg("Invoking VRModeSwitchTracker.OnPostVRModeSwitch.");
+ Camera activeCamera = PlayerSetup.Instance.GetActiveCamera().GetComponent();
+ VRModeSwitchTracker.OnPostVRModeSwitch?.Invoke(enterXR, activeCamera);
+ },
+ "Error while invoking VRModeSwitchTracker.OnPostVRModeSwitch. Did someone do a fucky?");
+ }
+}
\ No newline at end of file
diff --git a/DesktopVRSwitch/Properties/AssemblyInfo.cs b/DesktopVRSwitch/Properties/AssemblyInfo.cs
index 743b703..2ff0727 100644
--- a/DesktopVRSwitch/Properties/AssemblyInfo.cs
+++ b/DesktopVRSwitch/Properties/AssemblyInfo.cs
@@ -1,11 +1,17 @@
+<<<<<<< Updated upstream
using DesktopVRSwitch.Properties;
using MelonLoader;
+=======
+using MelonLoader;
+using NAK.Melons.DesktopVRSwitch.Properties;
+>>>>>>> Stashed changes
using System.Reflection;
[assembly: AssemblyVersion(AssemblyInfoParams.Version)]
[assembly: AssemblyFileVersion(AssemblyInfoParams.Version)]
[assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)]
+<<<<<<< Updated upstream
[assembly: AssemblyTitle(nameof(DesktopVRSwitch))]
[assembly: AssemblyCompany(AssemblyInfoParams.Author)]
[assembly: AssemblyProduct(nameof(DesktopVRSwitch))]
@@ -13,6 +19,15 @@ using System.Reflection;
[assembly: MelonInfo(
typeof(DesktopVRSwitch.DesktopVRSwitch),
nameof(DesktopVRSwitch),
+=======
+[assembly: AssemblyTitle(nameof(NAK.Melons.DesktopVRSwitch))]
+[assembly: AssemblyCompany(AssemblyInfoParams.Author)]
+[assembly: AssemblyProduct(nameof(NAK.Melons.DesktopVRSwitch))]
+
+[assembly: MelonInfo(
+ typeof(NAK.Melons.DesktopVRSwitch.DesktopVRSwitchMod),
+ nameof(NAK.Melons.DesktopVRSwitch),
+>>>>>>> Stashed changes
AssemblyInfoParams.Version,
AssemblyInfoParams.Author,
downloadLink: "https://github.com/NotAKidOnSteam/DesktopVRSwitch"
@@ -22,9 +37,16 @@ using System.Reflection;
[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
+<<<<<<< Updated upstream
namespace DesktopVRSwitch.Properties;
internal static class AssemblyInfoParams
{
public const string Version = "3.0.5";
+=======
+namespace NAK.Melons.DesktopVRSwitch.Properties;
+internal static class AssemblyInfoParams
+{
+ public const string Version = "4.2.4";
+>>>>>>> Stashed changes
public const string Author = "NotAKidoS";
}
\ No newline at end of file
diff --git a/DesktopVRSwitch/TryCatchHell.cs b/DesktopVRSwitch/TryCatchHell.cs
new file mode 100644
index 0000000..ad3313b
--- /dev/null
+++ b/DesktopVRSwitch/TryCatchHell.cs
@@ -0,0 +1,167 @@
+using ABI_RC.Core;
+using ABI_RC.Core.EventSystem;
+using ABI_RC.Core.InteractionSystem;
+using ABI_RC.Core.Player;
+using ABI_RC.Core.Savior;
+using ABI_RC.Core.UI;
+using ABI_RC.Systems.Camera;
+using HarmonyLib;
+using UnityEngine;
+
+namespace NAK.Melons.DesktopVRSwitch;
+
+internal class TryCatchHell
+{
+ internal static void TryCatchWrapper(Action action, string errorMsg, params object[] msgArgs)
+ {
+ try
+ {
+ action();
+ }
+ catch (Exception ex)
+ {
+ DesktopVRSwitchMod.Logger.Error(string.Format(errorMsg, msgArgs));
+ DesktopVRSwitchMod.Logger.Msg(ex.Message);
+ }
+ }
+
+ internal static void SetCheckVR(bool isVR)
+ {
+ TryCatchWrapper(() =>
+ {
+ DesktopVRSwitchMod.Logger.Msg($"Setting CheckVR hasVrDeviceLoaded to {isVR}.");
+ CheckVR.Instance.hasVrDeviceLoaded = isVR;
+ },
+ "Setting CheckVR hasVrDeviceLoaded failed.");
+ }
+
+ internal static void SetMetaPort(bool isVR)
+ {
+ TryCatchWrapper(() =>
+ {
+ DesktopVRSwitchMod.Logger.Msg($"Setting MetaPort isUsingVr to {isVR}.");
+ MetaPort.Instance.isUsingVr = isVR;
+ },
+ "Setting MetaPort isUsingVr failed.");
+ }
+
+ internal static void RepositionCohtmlHud(bool isVR)
+ {
+ TryCatchWrapper(() =>
+ {
+ DesktopVRSwitchMod.Logger.Msg("Configuring new hud affinity for CohtmlHud.");
+ CohtmlHud.Instance.gameObject.transform.parent = isVR ? PlayerSetup.Instance.vrCamera.transform : PlayerSetup.Instance.desktopCamera.transform;
+ CVRTools.ConfigureHudAffinity();
+ CohtmlHud.Instance.gameObject.transform.localScale = new Vector3(1.2f, 1f, 1.2f);
+ },
+ "Error parenting CohtmlHud to active camera.");
+ }
+
+ internal static void UpdateHudOperations(bool isVR)
+ {
+ TryCatchWrapper(() =>
+ {
+ DesktopVRSwitchMod.Logger.Msg("Switching HudOperations worldLoadingItem & worldLoadStatus.");
+ HudOperations.Instance.worldLoadingItem = isVR ? HudOperations.Instance.worldLoadingItemVr : HudOperations.Instance.worldLoadingItemDesktop;
+ HudOperations.Instance.worldLoadStatus = isVR ? HudOperations.Instance.worldLoadStatusVr : HudOperations.Instance.worldLoadStatusDesktop;
+ },
+ "Failed switching HudOperations objects.");
+ }
+
+ internal static void DisableMirrorCanvas()
+ {
+ TryCatchWrapper(() =>
+ {
+ DesktopVRSwitchMod.Logger.Msg("Forcing PortableCamera canvas mirroring off.");
+ //tell the game we are in mirror mode so itll disable it (if enabled)
+ PortableCamera.Instance.mode = MirroringMode.Mirror;
+ PortableCamera.Instance.ChangeMirroring();
+ },
+ "Failed to disable PortableCamera canvas mirroring.");
+ }
+
+ internal static void SwitchActiveCameraRigs(bool isVR)
+ {
+ TryCatchWrapper(() =>
+ {
+ DesktopVRSwitchMod.Logger.Msg("Switching active PlayerSetup camera rigs. Updating Desktop camera FOV.");
+ PlayerSetup.Instance.desktopCameraRig.SetActive(!isVR);
+ PlayerSetup.Instance.vrCameraRig.SetActive(isVR);
+ CVR_DesktopCameraController.UpdateFov();
+ //uicamera has script that copies fov from desktop cam
+ //toggling the cameras on/off resets aspect ratio
+ //so when rigs switch, that is already handled
+ },
+ "Failed to switch active camera rigs or update Desktop camera FOV.");
+ }
+
+ internal static void PauseInputInteractions(bool toggle)
+ {
+ TryCatchWrapper(() =>
+ {
+ DesktopVRSwitchMod.Logger.Msg($"Setting CVRInputManager inputEnabled & CVR_InteractableManager enableInteractions to {!toggle}");
+ CVRInputManager.Instance.inputEnabled = !toggle;
+ CVR_InteractableManager.enableInteractions = !toggle;
+ },
+ "Failed to toggle CVRInputManager inputEnabled & CVR_InteractableManager enableInteractions.");
+ }
+
+ internal static void ResetCVRInputManager()
+ {
+ TryCatchWrapper(() =>
+ {
+ DesktopVRSwitchMod.Logger.Msg("Resetting CVRInputManager inputs.");
+ //just in case
+ CVRInputManager.Instance.blockedByUi = false;
+ //sometimes head can get stuck, so just in case
+ CVRInputManager.Instance.independentHeadToggle = false;
+ //just nice to load into desktop with idle gesture
+ CVRInputManager.Instance.gestureLeft = 0f;
+ CVRInputManager.Instance.gestureLeftRaw = 0f;
+ CVRInputManager.Instance.gestureRight = 0f;
+ CVRInputManager.Instance.gestureRightRaw = 0f;
+ },
+ "Failed to reset CVRInputManager inputs.");
+ }
+
+ internal static void ReloadLocalAvatar()
+ {
+ TryCatchWrapper(() =>
+ {
+ DesktopVRSwitchMod.Logger.Msg("Attempting to reload current local avatar from GUID.");
+ AssetManagement.Instance.LoadLocalAvatar(MetaPort.Instance.currentAvatarGuid);
+ },
+ "Failed to reload local avatar.");
+ }
+
+ internal static void UpdateRichPresence()
+ {
+ TryCatchWrapper(() =>
+ {
+ if (MetaPort.Instance.settings.GetSettingsBool("ImplementationRichPresenceDiscordEnabled", true))
+ {
+ DesktopVRSwitchMod.Logger.Msg("Forcing Discord Rich Presence update.");
+ MetaPort.Instance.settings.SetSettingsBool("ImplementationRichPresenceDiscordEnabled", false);
+ MetaPort.Instance.settings.SetSettingsBool("ImplementationRichPresenceDiscordEnabled", true);
+ }
+ if (MetaPort.Instance.settings.GetSettingsBool("ImplementationRichPresenceSteamEnabled", true))
+ {
+ DesktopVRSwitchMod.Logger.Msg("Forcing Steam Rich Presence update.");
+ MetaPort.Instance.settings.SetSettingsBool("ImplementationRichPresenceSteamEnabled", false);
+ MetaPort.Instance.settings.SetSettingsBool("ImplementationRichPresenceSteamEnabled", true);
+ }
+ },
+ "Failed to update Discord & Steam Rich Presence.");
+ }
+
+ internal static void UpdateGestureReconizerCam()
+ {
+ TryCatchWrapper(() =>
+ {
+ DesktopVRSwitchMod.Logger.Msg("Updating CVRGestureRecognizer _camera to active camera.");
+ Traverse.Create(CVRGestureRecognizer.Instance).Field("_camera").SetValue(PlayerSetup.Instance.GetActiveCamera().GetComponent());
+ },
+ "Failed to update CVRGestureRecognizer camera.");
+ }
+}
+