diff --git a/ml_amt/MotionTweaker.cs b/ml_amt/MotionTweaker.cs index f205fd2..a02bf7c 100644 --- a/ml_amt/MotionTweaker.cs +++ b/ml_amt/MotionTweaker.cs @@ -5,7 +5,6 @@ using ABI_RC.Systems.IK.SubSystems; using ABI_RC.Systems.MovementSystem; using RootMotion.FinalIK; using System.Collections.Generic; -using System.Reflection; using UnityEngine; namespace ml_amt @@ -14,9 +13,6 @@ namespace ml_amt class MotionTweaker : MonoBehaviour { static readonly Vector4 ms_pointVector = new Vector4(0f, 0f, 0f, 1f); - static readonly FieldInfo ms_grounded = typeof(MovementSystem).GetField("_isGrounded", BindingFlags.NonPublic | BindingFlags.Instance); - static readonly FieldInfo ms_groundedRaw = typeof(MovementSystem).GetField("_isGroundedRaw", BindingFlags.NonPublic | BindingFlags.Instance); - static readonly FieldInfo ms_hasToes = typeof(IKSolverVR).GetField("hasToes", BindingFlags.NonPublic | BindingFlags.Instance); static readonly int ms_emoteHash = Animator.StringToHash("Emote"); enum PoseState @@ -121,8 +117,8 @@ namespace ml_amt { if(m_avatarReady) { - m_grounded = (bool)ms_grounded.GetValue(MovementSystem.Instance); - m_groundedRaw = (bool)ms_groundedRaw.GetValue(MovementSystem.Instance); + m_grounded = MovementSystem.Instance.IsGrounded(); + m_groundedRaw = MovementSystem.Instance.IsGroundedRaw(); m_moving = !Mathf.Approximately(MovementSystem.Instance.movementVector.magnitude, 0f); // Update upright @@ -230,7 +226,7 @@ namespace ml_amt m_locomotionOffset = m_vrIk.solver.locomotion.offset; m_massCenter = m_locomotionOffset; - if((bool)ms_hasToes.GetValue(m_vrIk.solver)) + if(m_vrIk.solver.HasToes()) { Transform l_foot = PlayerSetup.Instance._animator.GetBoneTransform(HumanBodyBones.LeftFoot); if(l_foot == null) diff --git a/ml_amt/Utils.cs b/ml_amt/Utils.cs index 02eaf7a..0024fe9 100644 --- a/ml_amt/Utils.cs +++ b/ml_amt/Utils.cs @@ -1,23 +1,32 @@ -using System.Reflection; +using ABI_RC.Systems.MovementSystem; +using RootMotion.FinalIK; +using System.Reflection; using UnityEngine; namespace ml_amt { static class Utils { - static MethodInfo ms_getSineKeyframes = typeof(RootMotion.FinalIK.IKSolverVR).GetMethod("GetSineKeyframes", BindingFlags.NonPublic | BindingFlags.Static); + static readonly FieldInfo ms_grounded = typeof(MovementSystem).GetField("_isGrounded", BindingFlags.NonPublic | BindingFlags.Instance); + static readonly FieldInfo ms_groundedRaw = typeof(MovementSystem).GetField("_isGroundedRaw", BindingFlags.NonPublic | BindingFlags.Instance); + static readonly FieldInfo ms_hasToes = typeof(IKSolverVR).GetField("hasToes", BindingFlags.NonPublic | BindingFlags.Instance); + static MethodInfo ms_getSineKeyframes = typeof(IKSolverVR).GetMethod("GetSineKeyframes", BindingFlags.NonPublic | BindingFlags.Static); public static bool IsInVR() => ((ABI_RC.Core.Savior.CheckVR.Instance != null) && ABI_RC.Core.Savior.CheckVR.Instance.hasVrDeviceLoaded); - // Extensions - public static Matrix4x4 GetMatrix(this Transform p_transform, bool p_pos = true, bool p_rot = true, bool p_scl = false) - { - return Matrix4x4.TRS(p_pos ? p_transform.position : Vector3.zero, p_rot ? p_transform.rotation : Quaternion.identity, p_scl ? p_transform.localScale : Vector3.one); - } + public static bool IsGrounded(this MovementSystem p_instance) => (bool)ms_grounded.GetValue(MovementSystem.Instance); + public static bool IsGroundedRaw(this MovementSystem p_instance) => (bool)ms_groundedRaw.GetValue(MovementSystem.Instance); + public static bool HasToes(this IKSolverVR p_instance) => (bool)ms_hasToes.GetValue(p_instance); public static Keyframe[] GetSineKeyframes(float p_mag) { return (Keyframe[])ms_getSineKeyframes.Invoke(null, new object[] { p_mag }); } + + // Engine extensions + public static Matrix4x4 GetMatrix(this Transform p_transform, bool p_pos = true, bool p_rot = true, bool p_scl = false) + { + return Matrix4x4.TRS(p_pos ? p_transform.position : Vector3.zero, p_rot ? p_transform.rotation : Quaternion.identity, p_scl ? p_transform.localScale : Vector3.one); + } } } diff --git a/ml_dht/HeadTracked.cs b/ml_dht/HeadTracked.cs index 00b116d..35c28a0 100644 --- a/ml_dht/HeadTracked.cs +++ b/ml_dht/HeadTracked.cs @@ -1,7 +1,6 @@ using ABI.CCK.Components; using ABI_RC.Core.Player; using RootMotion.FinalIK; -using System.Reflection; using UnityEngine; using ViveSR.anipal.Lip; @@ -10,8 +9,6 @@ namespace ml_dht [DisallowMultipleComponent] class HeadTracked : MonoBehaviour { - static FieldInfo ms_emotePlaying = typeof(PlayerSetup).GetField("_emotePlaying", BindingFlags.NonPublic | BindingFlags.Instance); - bool m_enabled = false; bool m_headTracking = true; bool m_blinking = true; @@ -74,7 +71,7 @@ namespace ml_dht { m_lastHeadRotation = Quaternion.Slerp(m_lastHeadRotation, m_avatarDescriptor.transform.rotation * (m_headRotation * m_bindRotation), m_smoothing); - if(!(bool)ms_emotePlaying.GetValue(PlayerSetup.Instance)) + if(!PlayerSetup.Instance.IsEmotePlaying()) m_headBone.rotation = m_lastHeadRotation; } } diff --git a/ml_dht/Utils.cs b/ml_dht/Utils.cs index 7d2651c..c830b43 100644 --- a/ml_dht/Utils.cs +++ b/ml_dht/Utils.cs @@ -1,9 +1,15 @@ -using UnityEngine; +using ABI_RC.Core.Player; +using System.Reflection; +using UnityEngine; namespace ml_dht { static class Utils { + static FieldInfo ms_emotePlaying = typeof(PlayerSetup).GetField("_emotePlaying", BindingFlags.NonPublic | BindingFlags.Instance); + + public static bool IsEmotePlaying(this PlayerSetup p_instance) => (bool)ms_emotePlaying.GetValue(p_instance); + public static Matrix4x4 GetMatrix(this Transform p_transform, bool p_pos = true, bool p_rot = true, bool p_scl = false) { return Matrix4x4.TRS(p_pos ? p_transform.position : Vector3.zero, p_rot ? p_transform.rotation : Quaternion.identity, p_scl ? p_transform.localScale : Vector3.one); diff --git a/ml_lme/LeapInput.cs b/ml_lme/LeapInput.cs index 585fbf1..9cf5545 100644 --- a/ml_lme/LeapInput.cs +++ b/ml_lme/LeapInput.cs @@ -3,7 +3,6 @@ using ABI_RC.Core.Player; using ABI_RC.Core.Savior; using ABI_RC.Systems.IK; using System.Collections; -using System.Reflection; using UnityEngine; namespace ml_lme diff --git a/ml_prm/Settings.cs b/ml_prm/Settings.cs index 502af1d..dcbed8b 100644 --- a/ml_prm/Settings.cs +++ b/ml_prm/Settings.cs @@ -100,7 +100,7 @@ namespace ml_prm Hotkey = (bool)ms_entries[(int)ModSetting.Hotkey].BoxedValue; VelocityMultiplier = Mathf.Clamp((float)ms_entries[(int)ModSetting.VelocityMultiplier].BoxedValue, 1f, 50f); MovementDrag = Mathf.Clamp((float)ms_entries[(int)ModSetting.MovementDrag].BoxedValue, 0f, 50f); - AngularDrag = Mathf.Clamp((float)ms_entries[(int)ModSetting.MovementDrag].BoxedValue, 0f, 50f); + AngularDrag = Mathf.Clamp((float)ms_entries[(int)ModSetting.AngularDrag].BoxedValue, 0f, 50f); Gravity = (bool)ms_entries[(int)ModSetting.Gravity].BoxedValue; PointersReaction = (bool)ms_entries[(int)ModSetting.PointersReaction].BoxedValue; IgnoreLocal = (bool)ms_entries[(int)ModSetting.IgnoreLocal].BoxedValue;