diff --git a/ml_amt/Main.cs b/ml_amt/Main.cs index 8717b1d..92136c0 100644 --- a/ml_amt/Main.cs +++ b/ml_amt/Main.cs @@ -20,11 +20,10 @@ namespace ml_amt null, new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnAvatarClear_Postfix), System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static)) ); - HarmonyInstance.Patch( - typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetupAvatar)), + typeof(PlayerSetup).GetMethod("SetupAvatarGeneral", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic), null, - new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnLocalAvatarSetup_Postfix), System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static)) + new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnSetupAvatarGeneral_Postfix), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)) ); MelonLoader.MelonCoroutines.Start(WaitForLocalPlayer()); @@ -44,18 +43,18 @@ namespace ml_amt m_localTweaker.SetCrouchLimit(p_value); } - static void OnLocalAvatarSetup_Postfix() => ms_instance?.OnLocalAvatarSetup(); - void OnLocalAvatarSetup() - { - if((m_localTweaker != null) && !PlayerSetup.Instance._inVr) - m_localTweaker.OnAvatarSetup(); - } - static void OnAvatarClear_Postfix() => ms_instance?.OnAvatarClear(); void OnAvatarClear() { if(m_localTweaker != null) m_localTweaker.OnAvatarClear(); } + + static void OnSetupAvatarGeneral_Postfix() => ms_instance?.OnSetupAvatarGeneral(); + void OnSetupAvatarGeneral() + { + if(m_localTweaker != null) + m_localTweaker.OnSetupAvatarGeneral(); + } } } diff --git a/ml_amt/MotionTweaker.cs b/ml_amt/MotionTweaker.cs index 680103b..922c4a3 100644 --- a/ml_amt/MotionTweaker.cs +++ b/ml_amt/MotionTweaker.cs @@ -46,12 +46,6 @@ namespace ml_amt m_parameters = new List(); } - void Start() - { - if(PlayerSetup.Instance._inVr) - PlayerSetup.Instance.avatarSetupCompleted.AddListener(this.OnAvatarSetup); - } - void Update() { if(m_ready) @@ -96,8 +90,8 @@ namespace ml_amt public void OnAvatarClear() { - m_vrIk = null; m_ready = false; + m_vrIk = null; m_standing = true; m_parameters.Clear(); m_locomotionWeight = 1f; @@ -107,7 +101,7 @@ namespace ml_amt m_locomotionOffset = Vector3.zero; } - public void OnAvatarSetup() + public void OnSetupAvatarGeneral() { m_vrIk = PlayerSetup.Instance._avatar.GetComponent(); @@ -142,7 +136,7 @@ namespace ml_amt l_customTransform = PlayerSetup.Instance._avatar.transform.Find("LocomotionOffset"); m_customLocomotionOffset = (l_customTransform != null); - m_locomotionOffset = m_customLocomotionOffset ? Vector3.zero : l_customTransform.localPosition; + m_locomotionOffset = m_customLocomotionOffset ? l_customTransform.localPosition : Vector3.zero; // Apply VRIK tweaks if(m_vrIk != null) diff --git a/ml_lme/LeapTracked.cs b/ml_lme/LeapTracked.cs index 11be868..138df39 100644 --- a/ml_lme/LeapTracked.cs +++ b/ml_lme/LeapTracked.cs @@ -1,7 +1,6 @@ using ABI_RC.Core.Player; using ABI_RC.Core.Savior; using RootMotion.FinalIK; -using System.Linq; using UnityEngine; namespace ml_lme @@ -19,15 +18,9 @@ namespace ml_lme Transform m_leftHand = null; Transform m_rightHand = null; - bool m_knucklesInUse = false; - void Start() { m_indexIK = this.GetComponent(); - m_knucklesInUse = PlayerSetup.Instance._trackerManager.trackerNames.Contains("knuckles"); - - if(PlayerSetup.Instance._inVr) - PlayerSetup.Instance.avatarSetupCompleted.AddListener(this.OnAvatarSetup); } public void SetEnabled(bool p_state) @@ -36,8 +29,8 @@ namespace ml_lme if(m_indexIK != null) { - m_indexIK.activeControl = (m_enabled || m_knucklesInUse); - CVRInputManager.Instance.individualFingerTracking = (m_enabled || m_knucklesInUse); + m_indexIK.activeControl = (m_enabled || Utils.AreKnucklesInUse()); + CVRInputManager.Instance.individualFingerTracking = (m_enabled || Utils.AreKnucklesInUse()); } if(m_leapIK != null) @@ -56,6 +49,9 @@ namespace ml_lme { m_leftHand = p_left; m_rightHand = p_right; + + if(m_leapIK != null) + m_leapIK.SetHands(m_leftHand, m_rightHand); } public void UpdateTracking(GestureMatcher.GesturesData p_gesturesData) @@ -145,13 +141,13 @@ namespace ml_lme m_vrIK = null; } - public void OnAvatarSetup() + public void OnSetupAvatarGeneral() { - m_knucklesInUse = PlayerSetup.Instance._trackerManager.trackerNames.Contains("knuckles"); - if(m_indexIK != null) - m_indexIK.activeControl = (m_enabled || m_knucklesInUse); - CVRInputManager.Instance.individualFingerTracking = (m_enabled || m_knucklesInUse); + m_indexIK.activeControl = (m_enabled || Utils.AreKnucklesInUse()); + CVRInputManager.Instance.individualFingerTracking = (m_enabled || Utils.AreKnucklesInUse()); + + m_vrIK = PlayerSetup.Instance._animator.GetComponent(); if(!PlayerSetup.Instance._inVr) { @@ -160,8 +156,6 @@ namespace ml_lme m_leapIK.SetFingersOnly(m_fingersOnly); m_leapIK.SetHands(m_leftHand, m_rightHand); } - else - m_vrIK = PlayerSetup.Instance._animator.GetComponent(); } } } diff --git a/ml_lme/Main.cs b/ml_lme/Main.cs index 28e4858..9a049c3 100644 --- a/ml_lme/Main.cs +++ b/ml_lme/Main.cs @@ -50,11 +50,6 @@ namespace ml_lme m_leapHands = new GameObject[GestureMatcher.GesturesData.ms_handsCount]; // Patches - HarmonyInstance.Patch( - typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetupAvatar)), - null, - new HarmonyLib.HarmonyMethod(typeof(LeapMotionExtension).GetMethod(nameof(OnAvatarSetup_Postfix), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)) - ); HarmonyInstance.Patch( typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.ClearAvatar)), null, @@ -66,6 +61,7 @@ namespace ml_lme new HarmonyLib.HarmonyMethod(typeof(LeapMotionExtension).GetMethod(nameof(OnSetupAvatarGeneral_Postfix), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)) ); + MelonLoader.MelonCoroutines.Start(CreateTrackingObjects()); } @@ -334,15 +330,6 @@ namespace ml_lme m_leapTracked.OnAvatarClear(); } - static void OnAvatarSetup_Postfix() => ms_instance?.OnAvatarSetup(); - void OnAvatarSetup() - { - if(!PlayerSetup.Instance._inVr && (m_leapTracked != null)) - m_leapTracked.OnAvatarSetup(); - - OnSettingsHeadAttachChange(Settings.HeadAttach); - } - // Sneaky forced IndexIK calibration static void OnSetupAvatarGeneral_Prefix(ref PlayerSetup __instance) { @@ -353,6 +340,15 @@ namespace ml_lme { if(__instance != null) __instance._inVr = ms_vrState; + + ms_instance?.OnSetupAvatarGeneral(); + } + void OnSetupAvatarGeneral() + { + if(m_leapTracked != null) + m_leapTracked.OnSetupAvatarGeneral(); + + OnSettingsHeadAttachChange(Settings.HeadAttach); } // Utilities diff --git a/ml_lme/Utils.cs b/ml_lme/Utils.cs index 2040962..0a6cd14 100644 --- a/ml_lme/Utils.cs +++ b/ml_lme/Utils.cs @@ -1,7 +1,12 @@ -namespace ml_lme +using ABI_RC.Core.Player; +using System.Linq; + +namespace ml_lme { static class Utils { + public static bool AreKnucklesInUse() => PlayerSetup.Instance._trackerManager.trackerNames.Contains("knuckles"); + public static void Swap(ref T lhs, ref T rhs) { T temp = lhs;