VRTrackerManager controller swap fix & IKSystem tweak.

This commit is contained in:
NotAKidoS 2023-02-18 06:25:51 -06:00
parent 4ca30fe5cd
commit 81e734ec8f
9 changed files with 95 additions and 13 deletions

View file

@ -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);

View file

@ -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

View file

@ -89,4 +89,14 @@ internal class IKSystemPatches
{
__instance.gameObject.AddComponent<IKSystemTracker>();
}
}
internal class VRTrackerManagerPatches
{
[HarmonyPostfix]
[HarmonyPatch(typeof(VRTrackerManager), "Start")]
private static void Postfix_VRTrackerManager_Start(ref VRTrackerManager __instance)
{
__instance.gameObject.AddComponent<VRTrackerManagerTracker>();
}
}

View file

@ -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)

View file

@ -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

View file

@ -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)

View file

@ -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<VRTrackerManager>();
_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);
}
}

View file

@ -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";
}

View file

@ -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.");
}