mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 06:19:22 +00:00
backport
This commit is contained in:
parent
8a3523539b
commit
1e636e3395
13 changed files with 732 additions and 5 deletions
125
DesktopVRSwitch/DesktopVRSwitch.cs
Normal file
125
DesktopVRSwitch/DesktopVRSwitch.cs
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -43,7 +43,11 @@
|
|||
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Unity.Postprocessing.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Unity.TextMeshPro">
|
||||
<<<<<<< Updated upstream
|
||||
<HintPath>..\..\..\DakyModsCVR\ManagedLibs\Unity.TextMeshPro.dll</HintPath>
|
||||
=======
|
||||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Unity.TextMeshPro.dll</HintPath>
|
||||
>>>>>>> Stashed changes
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.AnimationModule">
|
||||
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.AnimationModule.dll</HintPath>
|
||||
|
|
|
@ -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
|
||||
|
|
92
DesktopVRSwitch/HarmonyPatches.cs
Normal file
92
DesktopVRSwitch/HarmonyPatches.cs
Normal file
|
@ -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<DesktopVRSwitch>();
|
||||
return;
|
||||
}
|
||||
__instance.gameObject.AddComponent<DesktopVRSwitch>();
|
||||
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<MovementSystemTracker>();
|
||||
}
|
||||
}
|
||||
|
||||
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<CVRPickupObjectTracker>();
|
||||
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<CameraFacingObjectTracker>();
|
||||
}
|
||||
}
|
||||
|
||||
internal class IKSystemPatches
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(IKSystem), "Start")]
|
||||
private static void Postfix_IKSystem_Start(ref IKSystem __instance)
|
||||
{
|
||||
__instance.gameObject.AddComponent<IKSystemTracker>();
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
24
DesktopVRSwitch/Patches/CameraFacingObjectTracker.cs
Normal file
24
DesktopVRSwitch/Patches/CameraFacingObjectTracker.cs
Normal file
|
@ -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<CameraFacingObject>();
|
||||
VRModeSwitchTracker.OnPostVRModeSwitch += PostVRModeSwitch;
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
VRModeSwitchTracker.OnPostVRModeSwitch -= PostVRModeSwitch;
|
||||
}
|
||||
|
||||
public void PostVRModeSwitch(bool enterXR, Camera activeCamera)
|
||||
{
|
||||
cameraFacingObject.m_Camera = activeCamera;
|
||||
}
|
||||
}
|
57
DesktopVRSwitch/Patches/IKSystemTracker.cs
Normal file
57
DesktopVRSwitch/Patches/IKSystemTracker.cs
Normal file
|
@ -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<IKSystem>();
|
||||
_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<List<TrackingModule>>();
|
||||
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;
|
||||
}
|
||||
}
|
39
DesktopVRSwitch/Patches/MovementSystemTracker.cs
Normal file
39
DesktopVRSwitch/Patches/MovementSystemTracker.cs
Normal file
|
@ -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<MovementSystem>();
|
||||
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);
|
||||
}
|
||||
}
|
91
DesktopVRSwitch/Patches/ReferenceCameraPatch.cs
Normal file
91
DesktopVRSwitch/Patches/ReferenceCameraPatch.cs
Normal file
|
@ -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>();
|
||||
Camera inactiveCamera = (MetaPort.Instance.isUsingVr ? PlayerSetup.Instance.desktopCamera : PlayerSetup.Instance.vrCamera).GetComponent<Camera>();
|
||||
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>();
|
||||
PostProcessLayer ppLayerInactiveCam = inactiveCam.AddComponentIfMissing<PostProcessLayer>();
|
||||
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>();
|
||||
AuraCamera auraInactiveCam = inactiveCam.AddComponentIfMissing<AuraCamera>();
|
||||
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>();
|
||||
FlareLayer flareInactiveCam = inactiveCam.AddComponentIfMissing<FlareLayer>();
|
||||
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>();
|
||||
AzureFogScattering azureFogInactiveCam = inactiveCam.AddComponentIfMissing<AzureFogScattering>();
|
||||
if (azureFogActiveCam != null && azureFogInactiveCam != null)
|
||||
{
|
||||
azureFogInactiveCam.fogScatteringMaterial = azureFogActiveCam.fogScatteringMaterial;
|
||||
}
|
||||
else
|
||||
{
|
||||
Object.Destroy(inactiveCam.GetComponent<AzureFogScattering>());
|
||||
}
|
||||
|
||||
//why is there so many thingsssssssss
|
||||
Beautify beautifyActiveCam = activeCam.GetComponent<Beautify>();
|
||||
Beautify beautifyInactiveCam = inactiveCam.AddComponentIfMissing<Beautify>();
|
||||
if (beautifyActiveCam != null && beautifyInactiveCam != null)
|
||||
{
|
||||
beautifyInactiveCam.quality = beautifyActiveCam.quality;
|
||||
beautifyInactiveCam.profile = beautifyActiveCam.profile;
|
||||
}
|
||||
else
|
||||
{
|
||||
Object.Destroy(inactiveCam.gameObject.GetComponent<Beautify>());
|
||||
}
|
||||
}
|
||||
}
|
33
DesktopVRSwitch/Patches/VRModeSwitchTracker.cs
Normal file
33
DesktopVRSwitch/Patches/VRModeSwitchTracker.cs
Normal file
|
@ -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<bool, Camera> OnPreVRModeSwitch;
|
||||
public static event UnityAction<bool, Camera> OnPostVRModeSwitch;
|
||||
|
||||
public static void PreVRModeSwitch(bool enterXR)
|
||||
{
|
||||
TryCatchHell.TryCatchWrapper(() =>
|
||||
{
|
||||
DesktopVRSwitchMod.Logger.Msg("Invoking VRModeSwitchTracker.OnPreVRModeSwitch.");
|
||||
Camera activeCamera = PlayerSetup.Instance.GetActiveCamera().GetComponent<Camera>();
|
||||
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<Camera>();
|
||||
VRModeSwitchTracker.OnPostVRModeSwitch?.Invoke(enterXR, activeCamera);
|
||||
},
|
||||
"Error while invoking VRModeSwitchTracker.OnPostVRModeSwitch. Did someone do a fucky?");
|
||||
}
|
||||
}
|
|
@ -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";
|
||||
}
|
167
DesktopVRSwitch/TryCatchHell.cs
Normal file
167
DesktopVRSwitch/TryCatchHell.cs
Normal file
|
@ -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<Camera>());
|
||||
},
|
||||
"Failed to update CVRGestureRecognizer camera.");
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue