diff --git a/DesktopVRSwitch/DesktopVRSwitch.cs b/DesktopVRSwitch/DesktopVRSwitch.cs index 7da6495..8295c59 100644 --- a/DesktopVRSwitch/DesktopVRSwitch.cs +++ b/DesktopVRSwitch/DesktopVRSwitch.cs @@ -96,6 +96,9 @@ public class DesktopVRSwitch : MonoBehaviour //one frame after switch attempt public void AfterVRModeSwitch(bool enterVR) { + //close the menus + TryCatchHell.CloseCohtmlMenus(); + //these two must come first TryCatchHell.SetCheckVR(enterVR); TryCatchHell.SetMetaPort(enterVR); diff --git a/DesktopVRSwitch/DesktopVRSwitch.sln b/DesktopVRSwitch/DesktopVRSwitch.sln index 8d77157..0223868 100644 --- a/DesktopVRSwitch/DesktopVRSwitch.sln +++ b/DesktopVRSwitch/DesktopVRSwitch.sln @@ -3,11 +3,7 @@ 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 @@ -15,10 +11,10 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {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 + {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 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/DesktopVRSwitch/HarmonyPatches.cs b/DesktopVRSwitch/HarmonyPatches.cs index 6790699..93dad81 100644 --- a/DesktopVRSwitch/HarmonyPatches.cs +++ b/DesktopVRSwitch/HarmonyPatches.cs @@ -89,4 +89,14 @@ internal class IKSystemPatches { __instance.gameObject.AddComponent(); } +} + +internal class VRTrackerManagerPatches +{ + [HarmonyPostfix] + [HarmonyPatch(typeof(VRTrackerManager), "Start")] + private static void Postfix_VRTrackerManager_Start(ref VRTrackerManager __instance) + { + __instance.gameObject.AddComponent(); + } } \ No newline at end of file diff --git a/DesktopVRSwitch/Main.cs b/DesktopVRSwitch/Main.cs index 4e61e12..5bf1280 100644 --- a/DesktopVRSwitch/Main.cs +++ b/DesktopVRSwitch/Main.cs @@ -1,5 +1,18 @@ using MelonLoader; +/** + 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.Melons.DesktopVRSwitch; public class DesktopVRSwitchMod : MelonMod @@ -19,6 +32,7 @@ public class DesktopVRSwitchMod : MelonMod ApplyPatches(typeof(HarmonyPatches.CameraFacingObjectPatches)); ApplyPatches(typeof(HarmonyPatches.IKSystemPatches)); ApplyPatches(typeof(HarmonyPatches.MovementSystemPatches)); + ApplyPatches(typeof(HarmonyPatches.VRTrackerManagerPatches)); } private void ApplyPatches(Type type) diff --git a/DesktopVRSwitch/Patches/IKSystemTracker.cs b/DesktopVRSwitch/Patches/IKSystemTracker.cs index f64acea..7258a41 100644 --- a/DesktopVRSwitch/Patches/IKSystemTracker.cs +++ b/DesktopVRSwitch/Patches/IKSystemTracker.cs @@ -1,9 +1,8 @@ using ABI_RC.Systems.IK; -using ABI_RC.Systems.IK.SubSystems; using ABI_RC.Systems.IK.TrackingModules; using HarmonyLib; -using UnityEngine; using System.Reflection; +using UnityEngine; namespace NAK.Melons.DesktopVRSwitch.Patches; @@ -44,6 +43,11 @@ public class IKSystemTracker : MonoBehaviour var steamVRTrackingModule = CreateSteamVRTrackingModule(); ikSystem.AddTrackingModule(steamVRTrackingModule); } + + //make it so you dont instantly end up in FBT from Desktop + IKSystem.firstAvatarLoaded = false; + //turn of finger tracking just in case user switched controllers + ikSystem.FingerSystem.controlActive = false; } //thanks for marking the constructor as internal diff --git a/DesktopVRSwitch/Patches/MovementSystemTracker.cs b/DesktopVRSwitch/Patches/MovementSystemTracker.cs index 7aea4c9..a54c07d 100644 --- a/DesktopVRSwitch/Patches/MovementSystemTracker.cs +++ b/DesktopVRSwitch/Patches/MovementSystemTracker.cs @@ -6,7 +6,6 @@ namespace NAK.Melons.DesktopVRSwitch.Patches; public class MovementSystemTracker : MonoBehaviour { public MovementSystem movementSystem; - public Vector3 preSwitchWorldPosition; public Quaternion preSwitchWorldRotation; @@ -25,8 +24,16 @@ public class MovementSystemTracker : MonoBehaviour public void PreVRModeSwitch(bool enterVR, Camera activeCamera) { - preSwitchWorldPosition = movementSystem.rotationPivot.transform.position; + //correct rotationPivot y position, so we dont teleport up/down + Vector3 position = movementSystem.rotationPivot.transform.position; + position.y = movementSystem.transform.position.y; + preSwitchWorldPosition = position; preSwitchWorldRotation = movementSystem.rotationPivot.transform.rotation; + //ChilloutVR does not use VRIK root right, so avatar root is VR player root. + //This causes desync between VR and Desktop positions & collision on switch. + + //I correct for this in lazy way, but i use rotationPivot instead of avatar root, + //so the user can still switch even if avatar is null (if it failed to load for example). } public void PostVRModeSwitch(bool enterVR, Camera activeCamera) diff --git a/DesktopVRSwitch/Patches/VRTrackerManagerTracker.cs b/DesktopVRSwitch/Patches/VRTrackerManagerTracker.cs new file mode 100644 index 0000000..8ef5e50 --- /dev/null +++ b/DesktopVRSwitch/Patches/VRTrackerManagerTracker.cs @@ -0,0 +1,35 @@ +using ABI_RC.Core.Player; +using HarmonyLib; +using UnityEngine; + +namespace NAK.Melons.DesktopVRSwitch.Patches; + +public class VRTrackerManagerTracker : MonoBehaviour +{ + public VRTrackerManager vrTrackerManager; + public Traverse _hasCheckedForKnucklesTraverse; + public Traverse _posesTraverse; + + void Start() + { + vrTrackerManager = GetComponent(); + _posesTraverse = Traverse.Create(vrTrackerManager).Field("poses"); + _hasCheckedForKnucklesTraverse = Traverse.Create(vrTrackerManager).Field("hasCheckedForKnuckles"); + VRModeSwitchTracker.OnPostVRModeSwitch += PostVRModeSwitch; + } + void OnDestroy() + { + VRModeSwitchTracker.OnPostVRModeSwitch -= PostVRModeSwitch; + } + + public void PostVRModeSwitch(bool enterVR, Camera activeCamera) + { + //force the VRTrackerManager to reset anything its stored + //this makes it get correct Left/Right hand if entering VR with different controllers + //or if you restarted SteamVR and controllers are now in swapped index + vrTrackerManager.leftHand = null; + vrTrackerManager.rightHand = null; + _posesTraverse.SetValue(null); + _hasCheckedForKnucklesTraverse.SetValue(false); + } +} \ No newline at end of file diff --git a/DesktopVRSwitch/Properties/AssemblyInfo.cs b/DesktopVRSwitch/Properties/AssemblyInfo.cs index e8d2180..dd5b9f7 100644 --- a/DesktopVRSwitch/Properties/AssemblyInfo.cs +++ b/DesktopVRSwitch/Properties/AssemblyInfo.cs @@ -25,6 +25,6 @@ using System.Reflection; namespace NAK.Melons.DesktopVRSwitch.Properties; internal static class AssemblyInfoParams { - public const string Version = "4.3.0"; + public const string Version = "4.3.1"; public const string Author = "NotAKidoS"; } \ No newline at end of file diff --git a/DesktopVRSwitch/TryCatchHell.cs b/DesktopVRSwitch/TryCatchHell.cs index ad3313b..9a1a332 100644 --- a/DesktopVRSwitch/TryCatchHell.cs +++ b/DesktopVRSwitch/TryCatchHell.cs @@ -25,6 +25,17 @@ internal class TryCatchHell } } + internal static void CloseCohtmlMenus() + { + TryCatchWrapper(() => + { + DesktopVRSwitchMod.Logger.Msg("Closing ViewManager & CVR_MenuManager menus."); + ViewManager.Instance.UiStateToggle(false); + CVR_MenuManager.Instance.ToggleQuickMenu(false); + }, + "Setting CheckVR hasVrDeviceLoaded failed."); + } + internal static void SetCheckVR(bool isVR) { TryCatchWrapper(() => @@ -120,6 +131,8 @@ internal class TryCatchHell CVRInputManager.Instance.gestureLeftRaw = 0f; CVRInputManager.Instance.gestureRight = 0f; CVRInputManager.Instance.gestureRightRaw = 0f; + //turn off finger tracking input + CVRInputManager.Instance.individualFingerTracking = false; }, "Failed to reset CVRInputManager inputs."); }