Features merge from experimental:

Settings rework
Finger tracking networks sync only if hands are tracked
Working fix for animator override controller
Mass center offset calculations
Steps scaling
This commit is contained in:
SDraw 2023-03-16 09:20:45 +03:00
parent 8338fb758a
commit 971466da24
No known key found for this signature in database
GPG key ID: BB95B4DAB2BB8BB5
13 changed files with 474 additions and 451 deletions

View file

@ -47,6 +47,11 @@ namespace ml_amt
null, null,
new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnCalibrate_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnCalibrate_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
); );
HarmonyInstance.Patch(
typeof(PlayerSetup).GetMethod("SetPlaySpaceScale", BindingFlags.NonPublic | BindingFlags.Instance),
null,
new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnPlayspaceScale_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
);
// FBT detour // FBT detour
HarmonyInstance.Patch( HarmonyInstance.Patch(
@ -70,16 +75,16 @@ namespace ml_amt
null null
); );
// AAS overriding "fix" // AAS overriding fix
HarmonyInstance.Patch( HarmonyInstance.Patch(
typeof(CVRAnimatorManager).GetMethod(nameof(CVRAnimatorManager.SetOverrideAnimation), BindingFlags.Instance), typeof(CVRAnimatorManager).GetMethod(nameof(CVRAnimatorManager.SetOverrideAnimation)),
new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnAnimationOverride_Prefix), BindingFlags.Static | BindingFlags.NonPublic)), new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnOverride_Prefix), BindingFlags.Static | BindingFlags.NonPublic)),
null new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnOverride_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
); );
HarmonyInstance.Patch( HarmonyInstance.Patch(
typeof(CVRAnimatorManager).GetMethod(nameof(CVRAnimatorManager.RestoreOverrideAnimation)), typeof(CVRAnimatorManager).GetMethod(nameof(CVRAnimatorManager.RestoreOverrideAnimation)),
new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnAnimationOverrideRestore_Prefix), BindingFlags.Static | BindingFlags.NonPublic)), new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnOverride_Prefix), BindingFlags.Static | BindingFlags.NonPublic)),
null new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnOverride_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
); );
MelonLoader.MelonCoroutines.Start(WaitForLocalPlayer()); MelonLoader.MelonCoroutines.Start(WaitForLocalPlayer());
@ -93,7 +98,7 @@ namespace ml_amt
m_localTweaker = PlayerSetup.Instance.gameObject.AddComponent<MotionTweaker>(); m_localTweaker = PlayerSetup.Instance.gameObject.AddComponent<MotionTweaker>();
m_localTweaker.SetIKOverrideCrouch(Settings.IKOverrideCrouch); m_localTweaker.SetIKOverrideCrouch(Settings.IKOverrideCrouch);
m_localTweaker.SetCrouchLimit(Settings.CrouchLimit); m_localTweaker.SetCrouchLimit(Settings.CrouchLimit);
m_localTweaker.SetIKOverrideCrouch(Settings.IKOverrideProne); m_localTweaker.SetIKOverrideProne(Settings.IKOverrideProne);
m_localTweaker.SetProneLimit(Settings.ProneLimit); m_localTweaker.SetProneLimit(Settings.ProneLimit);
m_localTweaker.SetPoseTransitions(Settings.PoseTransitions); m_localTweaker.SetPoseTransitions(Settings.PoseTransitions);
m_localTweaker.SetAdjustedMovement(Settings.AdjustedMovement); m_localTweaker.SetAdjustedMovement(Settings.AdjustedMovement);
@ -153,6 +158,20 @@ namespace ml_amt
} }
} }
static void OnPlayspaceScale_Postfix() => ms_instance?.OnPlayspaceScale();
void OnPlayspaceScale()
{
try
{
if(m_localTweaker != null)
m_localTweaker.OnPlayspaceScale();
}
catch(System.Exception l_exception)
{
MelonLoader.MelonLogger.Error(l_exception);
}
}
// FBT detection override // FBT detection override
static void FBTDetour_Prefix() static void FBTDetour_Prefix()
{ {
@ -237,14 +256,38 @@ namespace ml_amt
return false; return false;
} }
static bool OnAnimationOverride_Prefix() static void OnOverride_Prefix(ref CVRAnimatorManager __instance, ref bool __state)
{ {
return !Settings.OverrideFix; try
{
if(Settings.OverrideFix && (__instance.animator != null))
{
__state = __instance.animator.enabled;
if(__state)
__instance.animator.enabled = false;
__instance.animator.WriteDefaultValues();
}
}
catch(System.Exception l_exception)
{
MelonLoader.MelonLogger.Error(l_exception);
}
} }
static void OnOverride_Postfix(ref CVRAnimatorManager __instance, bool __state)
static bool OnAnimationOverrideRestore_Prefix()
{ {
return !Settings.OverrideFix; try
{
if(Settings.OverrideFix && (__instance.animator != null))
{
__instance.animator.enabled = __state;
if(__state)
__instance.animator.Update(0f);
}
}
catch(System.Exception l_exception)
{
MelonLoader.MelonLogger.Error(l_exception);
}
} }
} }
} }

View file

@ -1,4 +1,5 @@
using ABI_RC.Core.Player; using ABI_RC.Core.Player;
using ABI_RC.Systems.IK;
using ABI_RC.Systems.IK.SubSystems; using ABI_RC.Systems.IK.SubSystems;
using ABI_RC.Systems.MovementSystem; using ABI_RC.Systems.MovementSystem;
using RootMotion.FinalIK; using RootMotion.FinalIK;
@ -44,6 +45,7 @@ namespace ml_amt
bool m_grounded = false; bool m_grounded = false;
bool m_groundedRaw = false; bool m_groundedRaw = false;
bool m_moving = false; bool m_moving = false;
bool m_locomotionOverride = false;
bool m_ikOverrideCrouch = true; bool m_ikOverrideCrouch = true;
float m_crouchLimit = 0.65f; float m_crouchLimit = 0.65f;
@ -64,6 +66,7 @@ namespace ml_amt
bool m_followHips = true; bool m_followHips = true;
Vector3 m_hipsToPlayer = Vector3.zero; Vector3 m_hipsToPlayer = Vector3.zero;
Vector2 m_stepDistance = Vector2.zero;
Vector3 m_massCenter = Vector3.zero; Vector3 m_massCenter = Vector3.zero;
readonly List<AvatarParameter> m_parameters = null; readonly List<AvatarParameter> m_parameters = null;
@ -73,6 +76,7 @@ namespace ml_amt
m_parameters = new List<AvatarParameter>(); m_parameters = new List<AvatarParameter>();
} }
// Unity events
void Start() void Start()
{ {
m_inVR = Utils.IsInVR(); m_inVR = Utils.IsInVR();
@ -87,7 +91,8 @@ namespace ml_amt
Settings.IKOverrideJumpChange += this.SetIKOverrideJump; Settings.IKOverrideJumpChange += this.SetIKOverrideJump;
Settings.DetectEmotesChange += this.SetDetectEmotes; Settings.DetectEmotesChange += this.SetDetectEmotes;
Settings.FollowHipsChange += this.SetFollowHips; Settings.FollowHipsChange += this.SetFollowHips;
Settings.MassCenterChange += this.SetMassCenter; Settings.MassCenterChange += this.OnMassCenterChange;
Settings.ScaledStepsChange += this.OnScaledStepsChange;
} }
void OnDestroy() void OnDestroy()
@ -102,7 +107,7 @@ namespace ml_amt
Settings.IKOverrideJumpChange -= this.SetIKOverrideJump; Settings.IKOverrideJumpChange -= this.SetIKOverrideJump;
Settings.DetectEmotesChange -= this.SetDetectEmotes; Settings.DetectEmotesChange -= this.SetDetectEmotes;
Settings.FollowHipsChange -= this.SetFollowHips; Settings.FollowHipsChange -= this.SetFollowHips;
Settings.MassCenterChange -= this.SetMassCenter; Settings.MassCenterChange -= this.OnMassCenterChange;
} }
void Update() void Update()
@ -116,8 +121,7 @@ namespace ml_amt
// Update upright // Update upright
Matrix4x4 l_hmdMatrix = PlayerSetup.Instance.transform.GetMatrix().inverse * (m_inVR ? PlayerSetup.Instance.vrHeadTracker.transform.GetMatrix() : PlayerSetup.Instance.desktopCameraRig.transform.GetMatrix()); Matrix4x4 l_hmdMatrix = PlayerSetup.Instance.transform.GetMatrix().inverse * (m_inVR ? PlayerSetup.Instance.vrHeadTracker.transform.GetMatrix() : PlayerSetup.Instance.desktopCameraRig.transform.GetMatrix());
float l_currentHeight = Mathf.Clamp((l_hmdMatrix * ms_pointVector).y, 0f, float.MaxValue); float l_currentHeight = Mathf.Clamp((l_hmdMatrix * ms_pointVector).y, 0f, float.MaxValue);
float l_avatarScale = (m_avatarScale > 0f) ? (PlayerSetup.Instance._avatar.transform.localScale.y / m_avatarScale) : 0f; float l_avatarViewHeight = Mathf.Clamp(m_viewPointHeight * GetRelativeScale(), 0f, float.MaxValue);
float l_avatarViewHeight = Mathf.Clamp(m_viewPointHeight * l_avatarScale, 0f, float.MaxValue);
m_upright = Mathf.Clamp01((l_avatarViewHeight > 0f) ? (l_currentHeight / l_avatarViewHeight) : 0f); m_upright = Mathf.Clamp01((l_avatarViewHeight > 0f) ? (l_currentHeight / l_avatarViewHeight) : 0f);
m_poseState = (m_upright <= Mathf.Min(m_proneLimit, m_crouchLimit)) ? PoseState.Proning : ((m_upright <= Mathf.Max(m_proneLimit, m_crouchLimit)) ? PoseState.Crouching : PoseState.Standing); m_poseState = (m_upright <= Mathf.Min(m_proneLimit, m_crouchLimit)) ? PoseState.Proning : ((m_upright <= Mathf.Max(m_proneLimit, m_crouchLimit)) ? PoseState.Crouching : PoseState.Standing);
@ -163,6 +167,7 @@ namespace ml_amt
} }
} }
// Game events
internal void OnAvatarClear() internal void OnAvatarClear()
{ {
m_vrIk = null; m_vrIk = null;
@ -178,10 +183,12 @@ namespace ml_amt
m_locomotionOffset = Vector3.zero; m_locomotionOffset = Vector3.zero;
m_emoteActive = false; m_emoteActive = false;
m_moving = false; m_moving = false;
m_locomotionOverride = false;
m_hipsToPlayer = Vector3.zero; m_hipsToPlayer = Vector3.zero;
m_avatarHips = null; m_avatarHips = null;
m_viewPointHeight = 1f; m_viewPointHeight = 1f;
m_massCenter = Vector3.zero; m_massCenter = Vector3.zero;
m_stepDistance = Vector2.zero;
m_parameters.Clear(); m_parameters.Clear();
} }
@ -252,6 +259,8 @@ namespace ml_amt
m_vrIk.solver.locomotion.offset = (Settings.MassCenter ? m_massCenter : m_locomotionOffset); m_vrIk.solver.locomotion.offset = (Settings.MassCenter ? m_massCenter : m_locomotionOffset);
m_stepDistance.Set(m_vrIk.solver.locomotion.stepThreshold, m_vrIk.solver.locomotion.footDistance);
m_vrIk.onPreSolverUpdate.AddListener(this.OnIKPreUpdate); m_vrIk.onPreSolverUpdate.AddListener(this.OnIKPreUpdate);
m_vrIk.onPostSolverUpdate.AddListener(this.OnIKPostUpdate); m_vrIk.onPostSolverUpdate.AddListener(this.OnIKPostUpdate);
} }
@ -273,9 +282,28 @@ namespace ml_amt
} }
} }
internal void OnPlayspaceScale()
{
if(m_vrIk != null)
{
if(Settings.MassCenter)
m_vrIk.solver.locomotion.offset = m_massCenter * GetRelativeScale();
if(Settings.ScaledSteps)
{
m_vrIk.solver.locomotion.stepThreshold = m_stepDistance.x * GetRelativeScale();
m_vrIk.solver.locomotion.footDistance = m_stepDistance.y * GetRelativeScale();
m_vrIk.solver.locomotion.stepHeight.keys = Utils.GetSineKeyframes(Mathf.Clamp01(PlayerSetup.Instance.GetAvatarHeight()) * 0.03f);
m_vrIk.solver.locomotion.heelHeight.keys = Utils.GetSineKeyframes(Mathf.Clamp01(PlayerSetup.Instance.GetAvatarHeight()) * 0.03f);
}
}
}
// IK events
void OnIKPreUpdate() void OnIKPreUpdate()
{ {
bool l_legsOverride = false; bool l_locomotionOverride = false;
m_ikWeight = m_vrIk.solver.IKPositionWeight; m_ikWeight = m_vrIk.solver.IKPositionWeight;
m_locomotionWeight = m_vrIk.solver.locomotion.weight; m_locomotionWeight = m_vrIk.solver.locomotion.weight;
@ -286,35 +314,42 @@ namespace ml_amt
if(m_detectEmotes && m_emoteActive) if(m_detectEmotes && m_emoteActive)
m_vrIk.solver.IKPositionWeight = 0f; m_vrIk.solver.IKPositionWeight = 0f;
if((m_ikOverrideCrouch && (m_poseState != PoseState.Standing)) || (m_ikOverrideProne && (m_poseState == PoseState.Proning))) if(!BodySystem.isCalibratedAsFullBody)
{ {
m_vrIk.solver.locomotion.weight = 0f; if((m_ikOverrideCrouch && (m_poseState != PoseState.Standing)) || (m_ikOverrideProne && (m_poseState == PoseState.Proning)))
l_legsOverride = true; {
} m_vrIk.solver.locomotion.weight = 0f;
if(m_ikOverrideFly && MovementSystem.Instance.flying) m_vrIk.solver.leftLeg.useAnimatedBendNormal = true;
{ m_vrIk.solver.rightLeg.useAnimatedBendNormal = true;
m_vrIk.solver.locomotion.weight = 0f; l_locomotionOverride = true;
m_vrIk.solver.leftLeg.useAnimatedBendNormal = true; }
m_vrIk.solver.rightLeg.useAnimatedBendNormal = true; if(m_ikOverrideFly && MovementSystem.Instance.flying)
l_legsOverride = true; {
} m_vrIk.solver.locomotion.weight = 0f;
m_vrIk.solver.leftLeg.useAnimatedBendNormal = true;
if(m_ikOverrideJump && !m_grounded && !MovementSystem.Instance.flying) m_vrIk.solver.rightLeg.useAnimatedBendNormal = true;
{ l_locomotionOverride = true;
m_vrIk.solver.locomotion.weight = 0f; }
m_vrIk.solver.leftLeg.useAnimatedBendNormal = true; if(m_ikOverrideJump && !m_grounded && !MovementSystem.Instance.flying)
m_vrIk.solver.rightLeg.useAnimatedBendNormal = true; {
l_legsOverride = true; m_vrIk.solver.locomotion.weight = 0f;
m_vrIk.solver.leftLeg.useAnimatedBendNormal = true;
m_vrIk.solver.rightLeg.useAnimatedBendNormal = true;
l_locomotionOverride = true;
}
} }
bool l_solverActive = !Mathf.Approximately(m_vrIk.solver.IKPositionWeight, 0f); bool l_solverActive = !Mathf.Approximately(m_vrIk.solver.IKPositionWeight, 0f);
if(l_locomotionOverride && l_solverActive && m_followHips && (!m_moving || (m_poseState == PoseState.Proning)) && m_inVR && !BodySystem.isCalibratedAsFullBody)
if(l_legsOverride && l_solverActive && m_followHips && (!m_moving || (m_poseState == PoseState.Proning)) && m_inVR && !BodySystem.isCalibratedAsFullBody)
{ {
m_vrIk.solver.plantFeet = false; m_vrIk.solver.plantFeet = false;
ABI_RC.Systems.IK.IKSystem.VrikRootController.enabled = false; IKSystem.VrikRootController.enabled = false;
PlayerSetup.Instance._avatar.transform.localPosition = m_hipsToPlayer; PlayerSetup.Instance._avatar.transform.localPosition = m_hipsToPlayer;
} }
if(m_locomotionOverride && !l_locomotionOverride)
m_vrIk.solver.Reset();
m_locomotionOverride = l_locomotionOverride;
} }
void OnIKPostUpdate() void OnIKPostUpdate()
@ -326,25 +361,26 @@ namespace ml_amt
m_vrIk.solver.rightLeg.useAnimatedBendNormal = m_bendNormalRight; m_vrIk.solver.rightLeg.useAnimatedBendNormal = m_bendNormalRight;
} }
public void SetIKOverrideCrouch(bool p_state) // Settings
internal void SetIKOverrideCrouch(bool p_state)
{ {
m_ikOverrideCrouch = p_state; m_ikOverrideCrouch = p_state;
} }
public void SetCrouchLimit(float p_value) internal void SetCrouchLimit(float p_value)
{ {
if(!m_customCrouchLimit) if(!m_customCrouchLimit)
m_crouchLimit = Mathf.Clamp01(p_value); m_crouchLimit = Mathf.Clamp01(p_value);
} }
public void SetIKOverrideProne(bool p_state) internal void SetIKOverrideProne(bool p_state)
{ {
m_ikOverrideProne = p_state; m_ikOverrideProne = p_state;
} }
public void SetProneLimit(float p_value) internal void SetProneLimit(float p_value)
{ {
if(!m_customProneLimit) if(!m_customProneLimit)
m_proneLimit = Mathf.Clamp01(p_value); m_proneLimit = Mathf.Clamp01(p_value);
} }
public void SetPoseTransitions(bool p_state) internal void SetPoseTransitions(bool p_state)
{ {
m_poseTransitions = p_state; m_poseTransitions = p_state;
@ -354,7 +390,7 @@ namespace ml_amt
PlayerSetup.Instance.animatorManager.SetAnimatorParameterBool("Prone", false); PlayerSetup.Instance.animatorManager.SetAnimatorParameterBool("Prone", false);
} }
} }
public void SetAdjustedMovement(bool p_state) internal void SetAdjustedMovement(bool p_state)
{ {
m_adjustedMovement = p_state; m_adjustedMovement = p_state;
@ -364,28 +400,54 @@ namespace ml_amt
MovementSystem.Instance.ChangeProne(false); MovementSystem.Instance.ChangeProne(false);
} }
} }
public void SetIKOverrideFly(bool p_state) internal void SetIKOverrideFly(bool p_state)
{ {
m_ikOverrideFly = p_state; m_ikOverrideFly = p_state;
} }
public void SetIKOverrideJump(bool p_state) internal void SetIKOverrideJump(bool p_state)
{ {
m_ikOverrideJump = p_state; m_ikOverrideJump = p_state;
} }
public void SetDetectEmotes(bool p_state) internal void SetDetectEmotes(bool p_state)
{ {
m_detectEmotes = p_state; m_detectEmotes = p_state;
} }
public void SetFollowHips(bool p_state) internal void SetFollowHips(bool p_state)
{ {
m_followHips = p_state; m_followHips = p_state;
} }
public void SetMassCenter(bool p_state) void OnMassCenterChange(bool p_state)
{ {
if(m_vrIk != null) if(m_vrIk != null)
m_vrIk.solver.locomotion.offset = (Settings.MassCenter ? m_massCenter : m_locomotionOffset); m_vrIk.solver.locomotion.offset = (Settings.MassCenter ? (m_massCenter * GetRelativeScale()) : m_locomotionOffset);
}
void OnScaledStepsChange(bool p_state)
{
if(m_vrIk != null)
{
if(p_state)
{
m_vrIk.solver.locomotion.stepThreshold = m_stepDistance.x * GetRelativeScale();
m_vrIk.solver.locomotion.footDistance = m_stepDistance.y * GetRelativeScale();
m_vrIk.solver.locomotion.stepHeight.keys = Utils.GetSineKeyframes(Mathf.Clamp01(PlayerSetup.Instance.GetAvatarHeight()) * 0.03f);
m_vrIk.solver.locomotion.heelHeight.keys = Utils.GetSineKeyframes(Mathf.Clamp01(PlayerSetup.Instance.GetAvatarHeight()) * 0.03f);
}
else
{
IKSystem.Instance.ApplyAvatarScaleToIk(PlayerSetup.Instance.GetAvatarHeight());
m_vrIk.solver.locomotion.stepHeight.keys = Utils.GetSineKeyframes(0.03f);
m_vrIk.solver.locomotion.heelHeight.keys = Utils.GetSineKeyframes(0.03f);
}
}
} }
// Arbitrary
float GetRelativeScale()
{
return ((m_avatarScale > 0f) ? (PlayerSetup.Instance._avatar.transform.localScale.y / m_avatarScale) : 0f);
}
// Parameters access
public float GetUpright() => m_upright; public float GetUpright() => m_upright;
public bool GetGroundedRaw() => m_groundedRaw; public bool GetGroundedRaw() => m_groundedRaw;
public bool GetMoving() => m_moving; public bool GetMoving() => m_moving;

View file

@ -20,23 +20,25 @@ namespace ml_amt
DetectEmotes, DetectEmotes,
FollowHips, FollowHips,
CollisionScale, CollisionScale,
ScaledSteps,
MassCenter, MassCenter,
OverrideFix OverrideFix
}; };
static bool ms_ikOverrideCrouch = true; public static bool IKOverrideCrouch { get; private set; } = true;
static float ms_crouchLimit = 0.65f; public static float CrouchLimit { get; private set; } = 0.65f;
static bool ms_ikOverrideProne = true; public static bool IKOverrideProne { get; private set; } = true;
static float ms_proneLimit = 0.3f; public static float ProneLimit { get; private set; } = 0.3f;
static bool ms_poseTransitions = true; public static bool PoseTransitions { get; private set; } = true;
static bool ms_adjustedMovement = true; public static bool AdjustedMovement { get; private set; } = true;
static bool ms_ikOverrideFly = true; public static bool IKOverrideFly { get; private set; } = true;
static bool ms_ikOverrideJump = true; public static bool IKOverrideJump { get; private set; } = true;
static bool ms_detectEmotes = true; public static bool DetectEmotes { get; private set; } = true;
static bool ms_followHips = true; public static bool FollowHips { get; private set; } = true;
static bool ms_collisionScale = true; public static bool MassCenter { get; private set; } = true;
static bool ms_massCenter = true; public static bool ScaledSteps { get; private set; } = true;
static bool ms_overrideFix = false; public static bool CollisionScale { get; private set; } = true;
public static bool OverrideFix { get; private set; } = true;
static MelonLoader.MelonPreferences_Category ms_category = null; static MelonLoader.MelonPreferences_Category ms_category = null;
static List<MelonLoader.MelonPreferences_Entry> ms_entries = null; static List<MelonLoader.MelonPreferences_Entry> ms_entries = null;
@ -51,8 +53,9 @@ namespace ml_amt
static public event Action<bool> IKOverrideJumpChange; static public event Action<bool> IKOverrideJumpChange;
static public event Action<bool> DetectEmotesChange; static public event Action<bool> DetectEmotesChange;
static public event Action<bool> FollowHipsChange; static public event Action<bool> FollowHipsChange;
static public event Action<bool> CollisionScaleChange;
static public event Action<bool> MassCenterChange; static public event Action<bool> MassCenterChange;
static public event Action<bool> ScaledStepsChange;
static public event Action<bool> CollisionScaleChange;
static public event Action<bool> OverrideFixChange; static public event Action<bool> OverrideFixChange;
internal static void Init() internal static void Init()
@ -61,19 +64,20 @@ namespace ml_amt
ms_entries = new List<MelonLoader.MelonPreferences_Entry>() ms_entries = new List<MelonLoader.MelonPreferences_Entry>()
{ {
ms_category.CreateEntry(ModSetting.IKOverrideCrouch.ToString(), true), ms_category.CreateEntry(ModSetting.IKOverrideCrouch.ToString(), IKOverrideCrouch),
ms_category.CreateEntry(ModSetting.CrouchLimit.ToString(), 65), ms_category.CreateEntry(ModSetting.CrouchLimit.ToString(), (int)(CrouchLimit * 100f)),
ms_category.CreateEntry(ModSetting.IKOverrideProne.ToString(), true), ms_category.CreateEntry(ModSetting.IKOverrideProne.ToString(), IKOverrideProne),
ms_category.CreateEntry(ModSetting.ProneLimit.ToString(), 30), ms_category.CreateEntry(ModSetting.ProneLimit.ToString(), (int)(ProneLimit * 100f)),
ms_category.CreateEntry(ModSetting.PoseTransitions.ToString(), true), ms_category.CreateEntry(ModSetting.PoseTransitions.ToString(), PoseTransitions),
ms_category.CreateEntry(ModSetting.AdjustedMovement.ToString(), true), ms_category.CreateEntry(ModSetting.AdjustedMovement.ToString(), AdjustedMovement),
ms_category.CreateEntry(ModSetting.IKOverrideFly.ToString(), true), ms_category.CreateEntry(ModSetting.IKOverrideFly.ToString(), IKOverrideFly),
ms_category.CreateEntry(ModSetting.IKOverrideJump.ToString(), true), ms_category.CreateEntry(ModSetting.IKOverrideJump.ToString(), IKOverrideJump),
ms_category.CreateEntry(ModSetting.DetectEmotes.ToString(), true), ms_category.CreateEntry(ModSetting.DetectEmotes.ToString(), DetectEmotes),
ms_category.CreateEntry(ModSetting.FollowHips.ToString(), true), ms_category.CreateEntry(ModSetting.FollowHips.ToString(), FollowHips),
ms_category.CreateEntry(ModSetting.CollisionScale.ToString(), true), ms_category.CreateEntry(ModSetting.MassCenter.ToString(), MassCenter),
ms_category.CreateEntry(ModSetting.MassCenter.ToString(), true), ms_category.CreateEntry(ModSetting.ScaledSteps.ToString(), ScaledSteps),
ms_category.CreateEntry(ModSetting.OverrideFix.ToString(), false) ms_category.CreateEntry(ModSetting.CollisionScale.ToString(), CollisionScale),
ms_category.CreateEntry(ModSetting.OverrideFix.ToString(), OverrideFix)
}; };
Load(); Load();
@ -105,19 +109,20 @@ namespace ml_amt
static void Load() static void Load()
{ {
ms_ikOverrideCrouch = (bool)ms_entries[(int)ModSetting.IKOverrideCrouch].BoxedValue; IKOverrideCrouch = (bool)ms_entries[(int)ModSetting.IKOverrideCrouch].BoxedValue;
ms_crouchLimit = ((int)ms_entries[(int)ModSetting.CrouchLimit].BoxedValue) * 0.01f; CrouchLimit = ((int)ms_entries[(int)ModSetting.CrouchLimit].BoxedValue) * 0.01f;
ms_ikOverrideProne = (bool)ms_entries[(int)ModSetting.IKOverrideProne].BoxedValue; IKOverrideProne = (bool)ms_entries[(int)ModSetting.IKOverrideProne].BoxedValue;
ms_proneLimit = ((int)ms_entries[(int)ModSetting.ProneLimit].BoxedValue) * 0.01f; ProneLimit = ((int)ms_entries[(int)ModSetting.ProneLimit].BoxedValue) * 0.01f;
ms_poseTransitions = (bool)ms_entries[(int)ModSetting.PoseTransitions].BoxedValue; PoseTransitions = (bool)ms_entries[(int)ModSetting.PoseTransitions].BoxedValue;
ms_adjustedMovement = (bool)ms_entries[(int)ModSetting.AdjustedMovement].BoxedValue; AdjustedMovement = (bool)ms_entries[(int)ModSetting.AdjustedMovement].BoxedValue;
ms_ikOverrideFly = (bool)ms_entries[(int)ModSetting.IKOverrideFly].BoxedValue; IKOverrideFly = (bool)ms_entries[(int)ModSetting.IKOverrideFly].BoxedValue;
ms_ikOverrideJump = (bool)ms_entries[(int)ModSetting.IKOverrideJump].BoxedValue; IKOverrideJump = (bool)ms_entries[(int)ModSetting.IKOverrideJump].BoxedValue;
ms_detectEmotes = (bool)ms_entries[(int)ModSetting.DetectEmotes].BoxedValue; DetectEmotes = (bool)ms_entries[(int)ModSetting.DetectEmotes].BoxedValue;
ms_followHips = (bool)ms_entries[(int)ModSetting.FollowHips].BoxedValue; FollowHips = (bool)ms_entries[(int)ModSetting.FollowHips].BoxedValue;
ms_collisionScale = (bool)ms_entries[(int)ModSetting.CollisionScale].BoxedValue; MassCenter = (bool)ms_entries[(int)ModSetting.MassCenter].BoxedValue;
ms_massCenter = (bool)ms_entries[(int)ModSetting.MassCenter].BoxedValue; ScaledSteps = (bool)ms_entries[(int)ModSetting.ScaledSteps].BoxedValue;
ms_overrideFix = (bool)ms_entries[(int)ModSetting.OverrideFix].BoxedValue; CollisionScale = (bool)ms_entries[(int)ModSetting.CollisionScale].BoxedValue;
OverrideFix = (bool)ms_entries[(int)ModSetting.OverrideFix].BoxedValue;
} }
static void OnSliderUpdate(string p_name, string p_value) static void OnSliderUpdate(string p_name, string p_value)
@ -128,15 +133,15 @@ namespace ml_amt
{ {
case ModSetting.CrouchLimit: case ModSetting.CrouchLimit:
{ {
ms_crouchLimit = int.Parse(p_value) * 0.01f; CrouchLimit = int.Parse(p_value) * 0.01f;
CrouchLimitChange?.Invoke(ms_crouchLimit); CrouchLimitChange?.Invoke(CrouchLimit);
} }
break; break;
case ModSetting.ProneLimit: case ModSetting.ProneLimit:
{ {
ms_proneLimit = int.Parse(p_value) * 0.01f; ProneLimit = int.Parse(p_value) * 0.01f;
ProneLimitChange?.Invoke(ms_proneLimit); ProneLimitChange?.Invoke(ProneLimit);
} }
break; break;
} }
@ -153,78 +158,85 @@ namespace ml_amt
{ {
case ModSetting.IKOverrideCrouch: case ModSetting.IKOverrideCrouch:
{ {
ms_ikOverrideCrouch = bool.Parse(p_value); IKOverrideCrouch = bool.Parse(p_value);
IKOverrideCrouchChange?.Invoke(ms_ikOverrideCrouch); IKOverrideCrouchChange?.Invoke(IKOverrideCrouch);
} }
break; break;
case ModSetting.IKOverrideProne: case ModSetting.IKOverrideProne:
{ {
ms_ikOverrideProne = bool.Parse(p_value); IKOverrideProne = bool.Parse(p_value);
IKOverrideProneChange?.Invoke(ms_ikOverrideProne); IKOverrideProneChange?.Invoke(IKOverrideProne);
} }
break; break;
case ModSetting.PoseTransitions: case ModSetting.PoseTransitions:
{ {
ms_poseTransitions = bool.Parse(p_value); PoseTransitions = bool.Parse(p_value);
PoseTransitionsChange?.Invoke(ms_poseTransitions); PoseTransitionsChange?.Invoke(PoseTransitions);
} }
break; break;
case ModSetting.AdjustedMovement: case ModSetting.AdjustedMovement:
{ {
ms_adjustedMovement = bool.Parse(p_value); AdjustedMovement = bool.Parse(p_value);
AdjustedMovementChange?.Invoke(ms_adjustedMovement); AdjustedMovementChange?.Invoke(AdjustedMovement);
} }
break; break;
case ModSetting.IKOverrideFly: case ModSetting.IKOverrideFly:
{ {
ms_ikOverrideFly = bool.Parse(p_value); IKOverrideFly = bool.Parse(p_value);
IKOverrideFlyChange?.Invoke(ms_ikOverrideFly); IKOverrideFlyChange?.Invoke(IKOverrideFly);
} }
break; break;
case ModSetting.IKOverrideJump: case ModSetting.IKOverrideJump:
{ {
ms_ikOverrideJump = bool.Parse(p_value); IKOverrideJump = bool.Parse(p_value);
IKOverrideJumpChange?.Invoke(ms_ikOverrideJump); IKOverrideJumpChange?.Invoke(IKOverrideJump);
} }
break; break;
case ModSetting.DetectEmotes: case ModSetting.DetectEmotes:
{ {
ms_detectEmotes = bool.Parse(p_value); DetectEmotes = bool.Parse(p_value);
DetectEmotesChange?.Invoke(ms_detectEmotes); DetectEmotesChange?.Invoke(DetectEmotes);
} }
break; break;
case ModSetting.FollowHips: case ModSetting.FollowHips:
{ {
ms_followHips = bool.Parse(p_value); FollowHips = bool.Parse(p_value);
FollowHipsChange?.Invoke(ms_followHips); FollowHipsChange?.Invoke(FollowHips);
}
break;
case ModSetting.CollisionScale:
{
ms_collisionScale = bool.Parse(p_value);
CollisionScaleChange?.Invoke(ms_collisionScale);
} }
break; break;
case ModSetting.MassCenter: case ModSetting.MassCenter:
{ {
ms_massCenter = bool.Parse(p_value); MassCenter = bool.Parse(p_value);
MassCenterChange?.Invoke(ms_massCenter); MassCenterChange?.Invoke(MassCenter);
}
break;
case ModSetting.ScaledSteps:
{
ScaledSteps = bool.Parse(p_value);
ScaledStepsChange?.Invoke(ScaledSteps);
}
break;
case ModSetting.CollisionScale:
{
CollisionScale = bool.Parse(p_value);
CollisionScaleChange?.Invoke(CollisionScale);
} }
break; break;
case ModSetting.OverrideFix: case ModSetting.OverrideFix:
{ {
ms_overrideFix = bool.Parse(p_value); OverrideFix = bool.Parse(p_value);
OverrideFixChange?.Invoke(ms_overrideFix); OverrideFixChange?.Invoke(OverrideFix);
} }
break; break;
} }
@ -232,58 +244,5 @@ namespace ml_amt
ms_entries[(int)l_setting].BoxedValue = bool.Parse(p_value); ms_entries[(int)l_setting].BoxedValue = bool.Parse(p_value);
} }
} }
public static bool IKOverrideCrouch
{
get => ms_ikOverrideCrouch;
}
public static float CrouchLimit
{
get => ms_crouchLimit;
}
public static bool IKOverrideProne
{
get => ms_ikOverrideProne;
}
public static float ProneLimit
{
get => ms_proneLimit;
}
public static bool PoseTransitions
{
get => ms_poseTransitions;
}
public static bool AdjustedMovement
{
get => ms_adjustedMovement;
}
public static bool IKOverrideFly
{
get => ms_ikOverrideFly;
}
public static bool IKOverrideJump
{
get => ms_ikOverrideJump;
}
public static bool DetectEmotes
{
get => ms_detectEmotes;
}
public static bool FollowHips
{
get => ms_followHips;
}
public static bool CollisionScale
{
get => ms_collisionScale;
}
public static bool MassCenter
{
get => ms_massCenter;
}
public static bool OverrideFix
{
get => ms_overrideFix;
}
} }
} }

View file

@ -1,10 +1,12 @@
using UnityEngine; using UnityEngine;
using ABI_RC.Systems.IK; using System.Reflection;
namespace ml_amt namespace ml_amt
{ {
static class Utils static class Utils
{ {
static MethodInfo ms_getSineKeyframes = typeof(RootMotion.FinalIK.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); public static bool IsInVR() => ((ABI_RC.Core.Savior.CheckVR.Instance != null) && ABI_RC.Core.Savior.CheckVR.Instance.hasVrDeviceLoaded);
// Extensions // Extensions
@ -12,5 +14,10 @@ namespace ml_amt
{ {
return Matrix4x4.TRS(p_pos ? p_transform.position : Vector3.zero, p_rot ? p_transform.rotation : Quaternion.identity, p_scl ? p_transform.localScale : Vector3.one); 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 Keyframe[] GetSineKeyframes(float p_mag)
{
return (Keyframe[])ms_getSineKeyframes.Invoke(null, new object[] { p_mag });
}
} }
} }

View file

@ -256,6 +256,13 @@ function inp_toggle_mod_amt(_obj, _callbackName) {
<div id="MassCenter" class ="inp_toggle no-scroll" data-current="true"></div> <div id="MassCenter" class ="inp_toggle no-scroll" data-current="true"></div>
</div> </div>
</div> </div>
<div class ="row-wrapper">
<div class ="option-caption">Scaled locomotion steps: </div>
<div class ="option-input">
<div id="ScaledSteps" class ="inp_toggle no-scroll" data-current="true"></div>
</div>
</div>
<div class ="row-wrapper"> <div class ="row-wrapper">
<div class ="option-caption">Alternative avatar collider scale: </div> <div class ="option-caption">Alternative avatar collider scale: </div>
@ -265,9 +272,9 @@ function inp_toggle_mod_amt(_obj, _callbackName) {
</div> </div>
<div class ="row-wrapper"> <div class ="row-wrapper">
<div class ="option-caption">Prevent Unity animation override (chairs, etc.): </div> <div class ="option-caption">Fix animation overrides (chairs, etc.): </div>
<div class ="option-input"> <div class ="option-input">
<div id="OverrideFix" class ="inp_toggle no-scroll" data-current="false"></div> <div id="OverrideFix" class ="inp_toggle no-scroll" data-current="true"></div>
</div> </div>
</div> </div>
`; `;

View file

@ -34,6 +34,7 @@ namespace ml_dht
Quaternion m_bindRotation; Quaternion m_bindRotation;
Quaternion m_lastHeadRotation; Quaternion m_lastHeadRotation;
// Unity events
void Start() void Start()
{ {
Settings.EnabledChange += this.SetEnabled; Settings.EnabledChange += this.SetEnabled;
@ -56,6 +57,7 @@ namespace ml_dht
Settings.FaceOverrideChange -= this.SetFaceOverride; Settings.FaceOverrideChange -= this.SetFaceOverride;
} }
// Tracking updates
public void UpdateTrackingData(ref TrackingData p_data) public void UpdateTrackingData(ref TrackingData p_data)
{ {
m_headPosition.Set(p_data.m_headPositionX * (m_mirrored ? -1f : 1f), p_data.m_headPositionY, p_data.m_headPositionZ); m_headPosition.Set(p_data.m_headPositionX * (m_mirrored ? -1f : 1f), p_data.m_headPositionY, p_data.m_headPositionZ);
@ -77,6 +79,7 @@ namespace ml_dht
} }
} }
// Game events
internal void OnEyeControllerUpdate(CVREyeController p_component) internal void OnEyeControllerUpdate(CVREyeController p_component)
{ {
if(m_enabled) if(m_enabled)
@ -139,7 +142,8 @@ namespace ml_dht
m_bindRotation = Quaternion.identity; m_bindRotation = Quaternion.identity;
} }
public void SetEnabled(bool p_state) // Settings
internal void SetEnabled(bool p_state)
{ {
if(m_enabled != p_state) if(m_enabled != p_state)
{ {
@ -148,7 +152,7 @@ namespace ml_dht
m_lastHeadRotation = ((m_headBone != null) ? m_headBone.rotation : m_bindRotation); m_lastHeadRotation = ((m_headBone != null) ? m_headBone.rotation : m_bindRotation);
} }
} }
public void SetHeadTracking(bool p_state) internal void SetHeadTracking(bool p_state)
{ {
if(m_headTracking != p_state) if(m_headTracking != p_state)
{ {
@ -157,23 +161,23 @@ namespace ml_dht
m_lastHeadRotation = ((m_headBone != null) ? m_headBone.rotation : m_bindRotation); m_lastHeadRotation = ((m_headBone != null) ? m_headBone.rotation : m_bindRotation);
} }
} }
public void SetEyeTracking(bool p_state) internal void SetEyeTracking(bool p_state)
{ {
m_eyeTracking = p_state; m_eyeTracking = p_state;
} }
public void SetBlinking(bool p_state) internal void SetBlinking(bool p_state)
{ {
m_blinking = p_state; m_blinking = p_state;
} }
public void SetSmoothing(float p_value) internal void SetSmoothing(float p_value)
{ {
m_smoothing = 1f - Mathf.Clamp(p_value, 0f, 0.99f); m_smoothing = 1f - Mathf.Clamp(p_value, 0f, 0.99f);
} }
public void SetMirrored(bool p_state) internal void SetMirrored(bool p_state)
{ {
m_mirrored = p_state; m_mirrored = p_state;
} }
public void SetFaceOverride(bool p_state) internal void SetFaceOverride(bool p_state)
{ {
m_faceOverride = p_state; m_faceOverride = p_state;
} }

View file

@ -18,13 +18,13 @@ namespace ml_dht
FaceOverride FaceOverride
} }
static bool ms_enabled = false; public static bool Enabled { get; private set; } = false;
static bool ms_headTracking = true; public static bool HeadTracking { get; private set; } = true;
static bool ms_eyeTracking = true; public static bool EyeTracking { get; private set; } = true;
static bool ms_blinking = true; public static bool Blinking { get; private set; } = true;
static bool ms_mirrored = false; public static bool Mirrored { get; private set; } = false;
static float ms_smoothing = 0.5f; public static float Smoothing { get; private set; } = 0.5f;
static bool ms_faceOverride = true; public static bool FaceOverride { get; private set; } = true;
static MelonLoader.MelonPreferences_Category ms_category = null; static MelonLoader.MelonPreferences_Category ms_category = null;
static List<MelonLoader.MelonPreferences_Entry> ms_entries = null; static List<MelonLoader.MelonPreferences_Entry> ms_entries = null;
@ -43,13 +43,13 @@ namespace ml_dht
ms_entries = new List<MelonLoader.MelonPreferences_Entry>() ms_entries = new List<MelonLoader.MelonPreferences_Entry>()
{ {
ms_category.CreateEntry(ModSetting.Enabled.ToString(), false), ms_category.CreateEntry(ModSetting.Enabled.ToString(), Enabled),
ms_category.CreateEntry(ModSetting.HeadTracking.ToString(), false), ms_category.CreateEntry(ModSetting.HeadTracking.ToString(), HeadTracking),
ms_category.CreateEntry(ModSetting.EyeTracking.ToString(), true), ms_category.CreateEntry(ModSetting.EyeTracking.ToString(), EyeTracking),
ms_category.CreateEntry(ModSetting.Blinking.ToString(), true), ms_category.CreateEntry(ModSetting.Blinking.ToString(), Blinking),
ms_category.CreateEntry(ModSetting.Mirrored.ToString(), false), ms_category.CreateEntry(ModSetting.Mirrored.ToString(), Mirrored),
ms_category.CreateEntry(ModSetting.Smoothing.ToString(), 50), ms_category.CreateEntry(ModSetting.Smoothing.ToString(), (int)(Smoothing * 50f)),
ms_category.CreateEntry(ModSetting.FaceOverride.ToString(), true) ms_category.CreateEntry(ModSetting.FaceOverride.ToString(), FaceOverride)
}; };
Load(); Load();
@ -81,13 +81,13 @@ namespace ml_dht
static void Load() static void Load()
{ {
ms_enabled = (bool)ms_entries[(int)ModSetting.Enabled].BoxedValue; Enabled = (bool)ms_entries[(int)ModSetting.Enabled].BoxedValue;
ms_headTracking = (bool)ms_entries[(int)ModSetting.HeadTracking].BoxedValue; HeadTracking = (bool)ms_entries[(int)ModSetting.HeadTracking].BoxedValue;
ms_eyeTracking = (bool)ms_entries[(int)ModSetting.EyeTracking].BoxedValue; EyeTracking = (bool)ms_entries[(int)ModSetting.EyeTracking].BoxedValue;
ms_blinking = (bool)ms_entries[(int)ModSetting.Blinking].BoxedValue; Blinking = (bool)ms_entries[(int)ModSetting.Blinking].BoxedValue;
ms_mirrored = (bool)ms_entries[(int)ModSetting.Mirrored].BoxedValue; Mirrored = (bool)ms_entries[(int)ModSetting.Mirrored].BoxedValue;
ms_smoothing = ((int)ms_entries[(int)ModSetting.Smoothing].BoxedValue) * 0.01f; Smoothing = ((int)ms_entries[(int)ModSetting.Smoothing].BoxedValue) * 0.01f;
ms_faceOverride = (bool)ms_entries[(int)ModSetting.FaceOverride].BoxedValue; FaceOverride = (bool)ms_entries[(int)ModSetting.FaceOverride].BoxedValue;
} }
static void OnSliderUpdate(string p_name, string p_value) static void OnSliderUpdate(string p_name, string p_value)
@ -98,8 +98,8 @@ namespace ml_dht
{ {
case ModSetting.Smoothing: case ModSetting.Smoothing:
{ {
ms_smoothing = int.Parse(p_value) * 0.01f; Smoothing = int.Parse(p_value) * 0.01f;
SmoothingChange?.Invoke(ms_smoothing); SmoothingChange?.Invoke(Smoothing);
} }
break; break;
} }
@ -116,43 +116,43 @@ namespace ml_dht
{ {
case ModSetting.Enabled: case ModSetting.Enabled:
{ {
ms_enabled = bool.Parse(p_value); Enabled = bool.Parse(p_value);
EnabledChange?.Invoke(ms_enabled); EnabledChange?.Invoke(Enabled);
} }
break; break;
case ModSetting.HeadTracking: case ModSetting.HeadTracking:
{ {
ms_headTracking = bool.Parse(p_value); HeadTracking = bool.Parse(p_value);
HeadTrackingChange?.Invoke(ms_headTracking); HeadTrackingChange?.Invoke(HeadTracking);
} }
break; break;
case ModSetting.EyeTracking: case ModSetting.EyeTracking:
{ {
ms_eyeTracking = bool.Parse(p_value); EyeTracking = bool.Parse(p_value);
EyeTrackingChange?.Invoke(ms_eyeTracking); EyeTrackingChange?.Invoke(EyeTracking);
} }
break; break;
case ModSetting.Blinking: case ModSetting.Blinking:
{ {
ms_blinking = bool.Parse(p_value); Blinking = bool.Parse(p_value);
BlinkingChange?.Invoke(ms_blinking); BlinkingChange?.Invoke(Blinking);
} }
break; break;
case ModSetting.Mirrored: case ModSetting.Mirrored:
{ {
ms_mirrored = bool.Parse(p_value); Mirrored = bool.Parse(p_value);
MirroredChange?.Invoke(ms_mirrored); MirroredChange?.Invoke(Mirrored);
} }
break; break;
case ModSetting.FaceOverride: case ModSetting.FaceOverride:
{ {
ms_faceOverride = bool.Parse(p_value); FaceOverride = bool.Parse(p_value);
FaceOverrideChange?.Invoke(ms_faceOverride); FaceOverrideChange?.Invoke(FaceOverride);
} }
break; break;
} }
@ -160,34 +160,5 @@ namespace ml_dht
ms_entries[(int)l_setting].BoxedValue = bool.Parse(p_value); ms_entries[(int)l_setting].BoxedValue = bool.Parse(p_value);
} }
} }
public static bool Enabled
{
get => ms_enabled;
}
public static bool HeadTracking
{
get => ms_headTracking;
}
public static bool EyeTracking
{
get => ms_eyeTracking;
}
public static bool Blinking
{
get => ms_blinking;
}
public static bool Mirrored
{
get => ms_mirrored;
}
public static float Smoothing
{
get => ms_smoothing;
}
public static bool FaceOverride
{
get => ms_faceOverride;
}
} }
} }

View file

@ -11,8 +11,6 @@ namespace ml_lme
[DisallowMultipleComponent] [DisallowMultipleComponent]
class LeapInput : CVRInputModule class LeapInput : CVRInputModule
{ {
static readonly FieldInfo ms_indexGestureToggle = typeof(InputModuleSteamVR).GetField("_steamVrIndexGestureToggleValue", BindingFlags.Instance | BindingFlags.NonPublic);
CVRInputManager m_inputManager = null; CVRInputManager m_inputManager = null;
InputModuleSteamVR m_steamVrModule = null; InputModuleSteamVR m_steamVrModule = null;
bool m_inVR = false; bool m_inVR = false;
@ -123,8 +121,18 @@ namespace ml_lme
{ {
if(l_data.m_leftHand.m_present) if(l_data.m_leftHand.m_present)
SetFingersInput(l_data.m_leftHand, true); SetFingersInput(l_data.m_leftHand, true);
if(l_data.m_rightHand.m_present) if(l_data.m_rightHand.m_present)
SetFingersInput(l_data.m_rightHand, false); SetFingersInput(l_data.m_rightHand, false);
if(m_inVR)
{
m_inputManager.individualFingerTracking = !m_steamVrModule.GetIndexGestureToggle();
m_inputManager.individualFingerTracking |= (l_data.m_leftHand.m_present || l_data.m_rightHand.m_present);
}
else
m_inputManager.individualFingerTracking = (l_data.m_leftHand.m_present || l_data.m_rightHand.m_present);
IKSystem.Instance.FingerSystem.controlActive = m_inputManager.individualFingerTracking;
} }
m_handRayLeft.enabled = (l_data.m_leftHand.m_present && (!m_inVR || !Utils.IsLeftHandTracked() || !Settings.FingersOnly)); m_handRayLeft.enabled = (l_data.m_leftHand.m_present && (!m_inVR || !Utils.IsLeftHandTracked() || !Settings.FingersOnly));
@ -240,15 +248,12 @@ namespace ml_lme
// Arbitrary // Arbitrary
void UpdateFingerTracking() void UpdateFingerTracking()
{ {
m_inputManager.individualFingerTracking = (Settings.Enabled || (m_inVR && Utils.AreKnucklesInUse() && !(bool)ms_indexGestureToggle.GetValue(m_steamVrModule))); m_inputManager.individualFingerTracking = (Settings.Enabled || (m_inVR && Utils.AreKnucklesInUse() && !m_steamVrModule.GetIndexGestureToggle()));
IKSystem.Instance.FingerSystem.controlActive = m_inputManager.individualFingerTracking; IKSystem.Instance.FingerSystem.controlActive = m_inputManager.individualFingerTracking;
} }
void SetFingersInput(GestureMatcher.HandData p_hand, bool p_left) void SetFingersInput(GestureMatcher.HandData p_hand, bool p_left)
{ {
m_inputManager.individualFingerTracking = true;
IKSystem.Instance.FingerSystem.controlActive = true;
if(p_left) if(p_left)
{ {
m_inputManager.fingerCurlLeftThumb = p_hand.m_bends[0]; m_inputManager.fingerCurlLeftThumb = p_hand.m_bends[0];
@ -256,11 +261,6 @@ namespace ml_lme
m_inputManager.fingerCurlLeftMiddle = p_hand.m_bends[2]; m_inputManager.fingerCurlLeftMiddle = p_hand.m_bends[2];
m_inputManager.fingerCurlLeftRing = p_hand.m_bends[3]; m_inputManager.fingerCurlLeftRing = p_hand.m_bends[3];
m_inputManager.fingerCurlLeftPinky = p_hand.m_bends[4]; m_inputManager.fingerCurlLeftPinky = p_hand.m_bends[4];
IKSystem.Instance.FingerSystem.leftThumbCurl = p_hand.m_bends[0];
IKSystem.Instance.FingerSystem.leftIndexCurl = p_hand.m_bends[1];
IKSystem.Instance.FingerSystem.leftMiddleCurl = p_hand.m_bends[2];
IKSystem.Instance.FingerSystem.leftRingCurl = p_hand.m_bends[3];
IKSystem.Instance.FingerSystem.leftPinkyCurl = p_hand.m_bends[4];
} }
else else
{ {
@ -269,14 +269,10 @@ namespace ml_lme
m_inputManager.fingerCurlRightMiddle = p_hand.m_bends[2]; m_inputManager.fingerCurlRightMiddle = p_hand.m_bends[2];
m_inputManager.fingerCurlRightRing = p_hand.m_bends[3]; m_inputManager.fingerCurlRightRing = p_hand.m_bends[3];
m_inputManager.fingerCurlRightPinky = p_hand.m_bends[4]; m_inputManager.fingerCurlRightPinky = p_hand.m_bends[4];
IKSystem.Instance.FingerSystem.rightThumbCurl = p_hand.m_bends[0];
IKSystem.Instance.FingerSystem.rightIndexCurl = p_hand.m_bends[1];
IKSystem.Instance.FingerSystem.rightMiddleCurl = p_hand.m_bends[2];
IKSystem.Instance.FingerSystem.rightRingCurl = p_hand.m_bends[3];
IKSystem.Instance.FingerSystem.rightPinkyCurl = p_hand.m_bends[4];
} }
} }
// Game settings
void OnGameSettingBoolChange(string p_name, bool p_state) void OnGameSettingBoolChange(string p_name, bool p_state)
{ {
if(p_name == "ControlUseGripToGrab") if(p_name == "ControlUseGripToGrab")

View file

@ -37,6 +37,7 @@ namespace ml_lme
bool m_leftTargetActive = false; bool m_leftTargetActive = false;
bool m_rightTargetActive = false; bool m_rightTargetActive = false;
// Unity events
void Start() void Start()
{ {
m_inVR = Utils.IsInVR(); m_inVR = Utils.IsInVR();
@ -51,51 +52,20 @@ namespace ml_lme
m_rightHandTarget.localPosition = Vector3.zero; m_rightHandTarget.localPosition = Vector3.zero;
m_rightHandTarget.localRotation = Quaternion.identity; m_rightHandTarget.localRotation = Quaternion.identity;
Settings.EnabledChange += this.SetEnabled; Settings.EnabledChange += this.OnEnabledChange;
Settings.FingersOnlyChange += this.SetFingersOnly; Settings.FingersOnlyChange += this.OnFingersOnlyChange;
Settings.TrackElbowsChange += this.SetTrackElbows; Settings.TrackElbowsChange += this.OnTrackElbowsChange;
SetEnabled(Settings.Enabled); OnEnabledChange(Settings.Enabled);
SetFingersOnly(Settings.FingersOnly); OnFingersOnlyChange(Settings.FingersOnly);
SetTrackElbows(Settings.TrackElbows); OnTrackElbowsChange(Settings.TrackElbows);
} }
void OnDestroy() void OnDestroy()
{ {
Settings.EnabledChange -= this.SetEnabled; Settings.EnabledChange -= this.OnEnabledChange;
Settings.FingersOnlyChange -= this.SetFingersOnly; Settings.FingersOnlyChange -= this.OnFingersOnlyChange;
Settings.TrackElbowsChange -= this.SetTrackElbows; Settings.TrackElbowsChange -= this.OnTrackElbowsChange;
}
void SetEnabled(bool p_state)
{
m_enabled = p_state;
RefreshArmIK();
if(!m_enabled || m_fingersOnly)
RestoreVRIK();
}
void SetFingersOnly(bool p_state)
{
m_fingersOnly = p_state;
RefreshArmIK();
if(!m_enabled || m_fingersOnly)
RestoreVRIK();
}
void SetTrackElbows(bool p_state)
{
m_trackElbows = p_state;
if((m_leftArmIK != null) && (m_rightArmIK != null))
{
m_leftArmIK.solver.arm.bendGoalWeight = (m_trackElbows ? 1f : 0f);
m_rightArmIK.solver.arm.bendGoalWeight = (m_trackElbows ? 1f : 0f);
}
RestoreVRIK();
} }
void Update() void Update()
@ -159,15 +129,18 @@ namespace ml_lme
GestureMatcher.LeapData l_data = LeapManager.GetInstance().GetLatestData(); GestureMatcher.LeapData l_data = LeapManager.GetInstance().GetLatestData();
Vector3 l_hipsLocalPos = m_hips.localPosition; Vector3 l_hipsLocalPos = m_hips.localPosition;
Quaternion l_hipsLocalRot = m_hips.localRotation;
m_poseHandler.GetHumanPose(ref m_pose); m_poseHandler.GetHumanPose(ref m_pose);
UpdateFingers(l_data); UpdateFingers(l_data);
m_poseHandler.SetHumanPose(ref m_pose); m_poseHandler.SetHumanPose(ref m_pose);
m_hips.localPosition = l_hipsLocalPos; m_hips.localPosition = l_hipsLocalPos;
m_hips.localRotation = l_hipsLocalRot;
} }
} }
// Tracking update
void UpdateFingers(GestureMatcher.LeapData p_data) void UpdateFingers(GestureMatcher.LeapData p_data)
{ {
if(p_data.m_leftHand.m_present) if(p_data.m_leftHand.m_present)
@ -227,6 +200,7 @@ namespace ml_lme
} }
} }
// Game events
internal void OnAvatarClear() internal void OnAvatarClear()
{ {
m_vrIK = null; m_vrIK = null;
@ -348,6 +322,7 @@ namespace ml_lme
} }
} }
// IK updates
void OnIKPreUpdate() void OnIKPreUpdate()
{ {
m_armsWeights.Set( m_armsWeights.Set(
@ -376,6 +351,39 @@ namespace ml_lme
m_vrIK.solver.rightArm.rotationWeight = m_armsWeights.w; m_vrIK.solver.rightArm.rotationWeight = m_armsWeights.w;
} }
// Settings
void OnEnabledChange(bool p_state)
{
m_enabled = p_state;
RefreshArmIK();
if(!m_enabled || m_fingersOnly)
RestoreVRIK();
}
void OnFingersOnlyChange(bool p_state)
{
m_fingersOnly = p_state;
RefreshArmIK();
if(!m_enabled || m_fingersOnly)
RestoreVRIK();
}
void OnTrackElbowsChange(bool p_state)
{
m_trackElbows = p_state;
if((m_leftArmIK != null) && (m_rightArmIK != null))
{
m_leftArmIK.solver.arm.bendGoalWeight = (m_trackElbows ? 1f : 0f);
m_rightArmIK.solver.arm.bendGoalWeight = (m_trackElbows ? 1f : 0f);
}
RestoreVRIK();
}
// Arbitrary
void RestoreVRIK() void RestoreVRIK()
{ {
if(m_vrIK != null) if(m_vrIK != null)

View file

@ -37,18 +37,18 @@ namespace ml_lme
GripThreadhold GripThreadhold
}; };
static bool ms_enabled = false; public static bool Enabled { get; private set; } = false;
static Vector3 ms_desktopOffset = new Vector3(0f, -0.45f, 0.3f); public static Vector3 DesktopOffset { get; private set; } = new Vector3(0f, -0.45f, 0.3f);
static bool ms_fingersOnly = false; public static bool FingersOnly { get; private set; } = false;
static bool ms_modelVisibility = false; public static bool ModelVisibility { get; private set; } = false;
static LeapTrackingMode ms_trackingMode = LeapTrackingMode.Desktop; public static LeapTrackingMode TrackingMode { get; private set; } = LeapTrackingMode.Desktop;
static Vector3 ms_rootAngle = Vector3.zero; public static Vector3 RootAngle { get; private set; } = Vector3.zero;
static bool ms_headAttach = false; public static bool HeadAttach { get; private set; } = false;
static Vector3 ms_headOffset = new Vector3(0f, -0.3f, 0.15f); public static Vector3 HeadOffset { get; private set; } = new Vector3(0f, -0.3f, 0.15f);
static bool ms_trackElbows = true; public static bool TrackElbows { get; private set; } = true;
static bool ms_input = true; public static bool Input { get; private set; } = true;
static float ms_interactThreadhold = 0.8f; public static float InteractThreadhold { get; private set; } = 0.8f;
static float ms_gripThreadhold = 0.4f; public static float GripThreadhold { get; private set; } = 0.4f;
static MelonLoader.MelonPreferences_Category ms_category = null; static MelonLoader.MelonPreferences_Category ms_category = null;
static List<MelonLoader.MelonPreferences_Entry> ms_entries = null; static List<MelonLoader.MelonPreferences_Entry> ms_entries = null;
@ -72,24 +72,24 @@ namespace ml_lme
ms_entries = new List<MelonLoader.MelonPreferences_Entry>() ms_entries = new List<MelonLoader.MelonPreferences_Entry>()
{ {
ms_category.CreateEntry(ModSetting.Enabled.ToString(), ms_enabled), ms_category.CreateEntry(ModSetting.Enabled.ToString(), Enabled),
ms_category.CreateEntry(ModSetting.DesktopX.ToString(), 0), ms_category.CreateEntry(ModSetting.DesktopX.ToString(), (int)(DesktopOffset.x * 100f)),
ms_category.CreateEntry(ModSetting.DesktopY.ToString(), -45), ms_category.CreateEntry(ModSetting.DesktopY.ToString(), (int)(DesktopOffset.y * 100f)),
ms_category.CreateEntry(ModSetting.DesktopZ.ToString(), 30), ms_category.CreateEntry(ModSetting.DesktopZ.ToString(), (int)(DesktopOffset.z * 100f)),
ms_category.CreateEntry(ModSetting.FingersOnly.ToString(), ms_modelVisibility), ms_category.CreateEntry(ModSetting.FingersOnly.ToString(), FingersOnly),
ms_category.CreateEntry(ModSetting.Model.ToString(), ms_modelVisibility), ms_category.CreateEntry(ModSetting.Model.ToString(), ModelVisibility),
ms_category.CreateEntry(ModSetting.Mode.ToString(), (int)ms_trackingMode), ms_category.CreateEntry(ModSetting.Mode.ToString(), (int)TrackingMode),
ms_category.CreateEntry(ModSetting.AngleX.ToString(), 0), ms_category.CreateEntry(ModSetting.AngleX.ToString(), (int)(RootAngle.x * 100f)),
ms_category.CreateEntry(ModSetting.AngleY.ToString(), 0), ms_category.CreateEntry(ModSetting.AngleY.ToString(), (int)(RootAngle.y * 100f)),
ms_category.CreateEntry(ModSetting.AngleZ.ToString(), 0), ms_category.CreateEntry(ModSetting.AngleZ.ToString(), (int)(RootAngle.z * 100f)),
ms_category.CreateEntry(ModSetting.Head.ToString(), ms_headAttach), ms_category.CreateEntry(ModSetting.Head.ToString(), HeadAttach),
ms_category.CreateEntry(ModSetting.HeadX.ToString(), 0), ms_category.CreateEntry(ModSetting.HeadX.ToString(), (int)(HeadOffset.x * 100f)),
ms_category.CreateEntry(ModSetting.HeadY.ToString(), -30), ms_category.CreateEntry(ModSetting.HeadY.ToString(), (int)(HeadOffset.y * 100f)),
ms_category.CreateEntry(ModSetting.HeadZ.ToString(), 15), ms_category.CreateEntry(ModSetting.HeadZ.ToString(), (int)(HeadOffset.z * 100f)),
ms_category.CreateEntry(ModSetting.TrackElbows.ToString(), true), ms_category.CreateEntry(ModSetting.TrackElbows.ToString(), TrackElbows),
ms_category.CreateEntry(ModSetting.Input.ToString(), true), ms_category.CreateEntry(ModSetting.Input.ToString(), Input),
ms_category.CreateEntry(ModSetting.InteractThreadhold.ToString(), 80), ms_category.CreateEntry(ModSetting.InteractThreadhold.ToString(), (int)(InteractThreadhold * 100f)),
ms_category.CreateEntry(ModSetting.GripThreadhold.ToString(), 40), ms_category.CreateEntry(ModSetting.GripThreadhold.ToString(), (int)(GripThreadhold * 100f)),
}; };
Load(); Load();
@ -122,30 +122,30 @@ namespace ml_lme
static void Load() static void Load()
{ {
ms_enabled = (bool)ms_entries[(int)ModSetting.Enabled].BoxedValue; Enabled = (bool)ms_entries[(int)ModSetting.Enabled].BoxedValue;
ms_desktopOffset = new Vector3( DesktopOffset = new Vector3(
(int)ms_entries[(int)ModSetting.DesktopX].BoxedValue, (int)ms_entries[(int)ModSetting.DesktopX].BoxedValue,
(int)ms_entries[(int)ModSetting.DesktopY].BoxedValue, (int)ms_entries[(int)ModSetting.DesktopY].BoxedValue,
(int)ms_entries[(int)ModSetting.DesktopZ].BoxedValue (int)ms_entries[(int)ModSetting.DesktopZ].BoxedValue
) * 0.01f; ) * 0.01f;
ms_fingersOnly = (bool)ms_entries[(int)ModSetting.FingersOnly].BoxedValue; FingersOnly = (bool)ms_entries[(int)ModSetting.FingersOnly].BoxedValue;
ms_modelVisibility = (bool)ms_entries[(int)ModSetting.Model].BoxedValue; ModelVisibility = (bool)ms_entries[(int)ModSetting.Model].BoxedValue;
ms_trackingMode = (LeapTrackingMode)(int)ms_entries[(int)ModSetting.Mode].BoxedValue; TrackingMode = (LeapTrackingMode)(int)ms_entries[(int)ModSetting.Mode].BoxedValue;
ms_rootAngle = new Vector3( RootAngle = new Vector3(
(int)ms_entries[(int)ModSetting.AngleX].BoxedValue, (int)ms_entries[(int)ModSetting.AngleX].BoxedValue,
(int)ms_entries[(int)ModSetting.AngleY].BoxedValue, (int)ms_entries[(int)ModSetting.AngleY].BoxedValue,
(int)ms_entries[(int)ModSetting.AngleZ].BoxedValue (int)ms_entries[(int)ModSetting.AngleZ].BoxedValue
); );
ms_headAttach = (bool)ms_entries[(int)ModSetting.Head].BoxedValue; HeadAttach = (bool)ms_entries[(int)ModSetting.Head].BoxedValue;
ms_headOffset = new Vector3( HeadOffset = new Vector3(
(int)ms_entries[(int)ModSetting.HeadX].BoxedValue, (int)ms_entries[(int)ModSetting.HeadX].BoxedValue,
(int)ms_entries[(int)ModSetting.HeadY].BoxedValue, (int)ms_entries[(int)ModSetting.HeadY].BoxedValue,
(int)ms_entries[(int)ModSetting.HeadZ].BoxedValue (int)ms_entries[(int)ModSetting.HeadZ].BoxedValue
) * 0.01f; ) * 0.01f;
ms_trackElbows = (bool)ms_entries[(int)ModSetting.TrackElbows].BoxedValue; TrackElbows = (bool)ms_entries[(int)ModSetting.TrackElbows].BoxedValue;
ms_input = (bool)ms_entries[(int)ModSetting.Input].BoxedValue; Input = (bool)ms_entries[(int)ModSetting.Input].BoxedValue;
ms_interactThreadhold = (int)ms_entries[(int)ModSetting.InteractThreadhold].BoxedValue * 0.01f; InteractThreadhold = (int)ms_entries[(int)ModSetting.InteractThreadhold].BoxedValue * 0.01f;
ms_gripThreadhold = (int)ms_entries[(int)ModSetting.GripThreadhold].BoxedValue * 0.01f; GripThreadhold = (int)ms_entries[(int)ModSetting.GripThreadhold].BoxedValue * 0.01f;
} }
static void OnToggleUpdate(string p_name, string p_value) static void OnToggleUpdate(string p_name, string p_value)
@ -156,43 +156,43 @@ namespace ml_lme
{ {
case ModSetting.Enabled: case ModSetting.Enabled:
{ {
ms_enabled = bool.Parse(p_value); Enabled = bool.Parse(p_value);
EnabledChange?.Invoke(ms_enabled); EnabledChange?.Invoke(Enabled);
} }
break; break;
case ModSetting.FingersOnly: case ModSetting.FingersOnly:
{ {
ms_fingersOnly = bool.Parse(p_value); FingersOnly = bool.Parse(p_value);
FingersOnlyChange?.Invoke(ms_fingersOnly); FingersOnlyChange?.Invoke(FingersOnly);
} }
break; break;
case ModSetting.Model: case ModSetting.Model:
{ {
ms_modelVisibility = bool.Parse(p_value); ModelVisibility = bool.Parse(p_value);
ModelVisibilityChange?.Invoke(ms_modelVisibility); ModelVisibilityChange?.Invoke(ModelVisibility);
} }
break; break;
case ModSetting.Head: case ModSetting.Head:
{ {
ms_headAttach = bool.Parse(p_value); HeadAttach = bool.Parse(p_value);
HeadAttachChange?.Invoke(ms_headAttach); HeadAttachChange?.Invoke(HeadAttach);
} }
break; break;
case ModSetting.TrackElbows: case ModSetting.TrackElbows:
{ {
ms_trackElbows = bool.Parse(p_value); TrackElbows = bool.Parse(p_value);
TrackElbowsChange?.Invoke(ms_trackElbows); TrackElbowsChange?.Invoke(TrackElbows);
} }
break; break;
case ModSetting.Input: case ModSetting.Input:
{ {
ms_input = bool.Parse(p_value); Input = bool.Parse(p_value);
InputChange?.Invoke(ms_input); InputChange?.Invoke(Input);
} }
break; break;
} }
@ -209,72 +209,90 @@ namespace ml_lme
{ {
case ModSetting.DesktopX: case ModSetting.DesktopX:
{ {
ms_desktopOffset.x = int.Parse(p_value) * 0.01f; Vector3 l_current = DesktopOffset;
DesktopOffsetChange?.Invoke(ms_desktopOffset); l_current.x = int.Parse(p_value) * 0.01f;
DesktopOffset = l_current;
DesktopOffsetChange?.Invoke(l_current);
} }
break; break;
case ModSetting.DesktopY: case ModSetting.DesktopY:
{ {
ms_desktopOffset.y = int.Parse(p_value) * 0.01f; Vector3 l_current = DesktopOffset;
DesktopOffsetChange?.Invoke(ms_desktopOffset); l_current.y = int.Parse(p_value) * 0.01f;
DesktopOffset = l_current;
DesktopOffsetChange?.Invoke(l_current);
} }
break; break;
case ModSetting.DesktopZ: case ModSetting.DesktopZ:
{ {
ms_desktopOffset.z = int.Parse(p_value) * 0.01f; Vector3 l_current = DesktopOffset;
DesktopOffsetChange?.Invoke(ms_desktopOffset); l_current.z = int.Parse(p_value) * 0.01f;
DesktopOffset = l_current;
DesktopOffsetChange?.Invoke(l_current);
} }
break; break;
case ModSetting.AngleX: case ModSetting.AngleX:
{ {
ms_rootAngle.x = int.Parse(p_value); Vector3 l_current = RootAngle;
RootAngleChange?.Invoke(ms_rootAngle); l_current.x = int.Parse(p_value);
RootAngle = l_current;
RootAngleChange?.Invoke(l_current);
} }
break; break;
case ModSetting.AngleY: case ModSetting.AngleY:
{ {
ms_rootAngle.y = int.Parse(p_value); Vector3 l_current = RootAngle;
RootAngleChange?.Invoke(ms_rootAngle); l_current.y = int.Parse(p_value);
RootAngle = l_current;
RootAngleChange?.Invoke(l_current);
} }
break; break;
case ModSetting.AngleZ: case ModSetting.AngleZ:
{ {
ms_rootAngle.z = int.Parse(p_value); Vector3 l_current = RootAngle;
RootAngleChange?.Invoke(ms_rootAngle); l_current.z = int.Parse(p_value);
RootAngle = l_current;
RootAngleChange?.Invoke(l_current);
} }
break; break;
case ModSetting.HeadX: case ModSetting.HeadX:
{ {
ms_headOffset.x = int.Parse(p_value) * 0.01f; Vector3 l_current = HeadOffset;
HeadOffsetChange?.Invoke(ms_headOffset); l_current.x = int.Parse(p_value) * 0.01f;
HeadOffset = l_current;
HeadOffsetChange?.Invoke(l_current);
} }
break; break;
case ModSetting.HeadY: case ModSetting.HeadY:
{ {
ms_headOffset.y = int.Parse(p_value) * 0.01f; Vector3 l_current = HeadOffset;
HeadOffsetChange?.Invoke(ms_headOffset); l_current.y = int.Parse(p_value) * 0.01f;
HeadOffset = l_current;
HeadOffsetChange?.Invoke(l_current);
} }
break; break;
case ModSetting.HeadZ: case ModSetting.HeadZ:
{ {
ms_headOffset.z = int.Parse(p_value) * 0.01f; Vector3 l_current = HeadOffset;
HeadOffsetChange?.Invoke(ms_headOffset); l_current.z = int.Parse(p_value) * 0.01f;
HeadOffset = l_current;
HeadOffsetChange?.Invoke(l_current);
} }
break; break;
case ModSetting.InteractThreadhold: case ModSetting.InteractThreadhold:
{ {
ms_interactThreadhold = int.Parse(p_value) * 0.01f; InteractThreadhold = int.Parse(p_value) * 0.01f;
InteractThreadholdChange?.Invoke(ms_interactThreadhold); InteractThreadholdChange?.Invoke(InteractThreadhold);
} }
break; break;
case ModSetting.GripThreadhold: case ModSetting.GripThreadhold:
{ {
ms_gripThreadhold = int.Parse(p_value) * 0.01f; GripThreadhold = int.Parse(p_value) * 0.01f;
GripThreadholdChange?.Invoke(ms_gripThreadhold); GripThreadholdChange?.Invoke(GripThreadhold);
} }
break; break;
} }
@ -291,8 +309,8 @@ namespace ml_lme
{ {
case ModSetting.Mode: case ModSetting.Mode:
{ {
ms_trackingMode = (LeapTrackingMode)int.Parse(p_value); TrackingMode = (LeapTrackingMode)int.Parse(p_value);
TrackingModeChange?.Invoke(ms_trackingMode); TrackingModeChange?.Invoke(TrackingMode);
} }
break; break;
} }
@ -300,54 +318,5 @@ namespace ml_lme
ms_entries[(int)l_setting].BoxedValue = int.Parse(p_value); ms_entries[(int)l_setting].BoxedValue = int.Parse(p_value);
} }
} }
public static bool Enabled
{
get => ms_enabled;
}
public static Vector3 DesktopOffset
{
get => ms_desktopOffset;
}
public static bool FingersOnly
{
get => ms_fingersOnly;
}
public static bool ModelVisibility
{
get => ms_modelVisibility;
}
public static LeapTrackingMode TrackingMode
{
get => ms_trackingMode;
}
public static Vector3 RootAngle
{
get => ms_rootAngle;
}
public static bool HeadAttach
{
get => ms_headAttach;
}
public static Vector3 HeadOffset
{
get => ms_headOffset;
}
public static bool TrackElbows
{
get => ms_trackElbows;
}
public static bool Input
{
get => ms_input;
}
public static float InteractThreadhold
{
get => ms_interactThreadhold;
}
public static float GripThreadhold
{
get => ms_gripThreadhold;
}
} }
} }

View file

@ -1,6 +1,8 @@
using ABI_RC.Core.Player; using ABI_RC.Core.Player;
using ABI_RC.Core.Savior;
using ABI_RC.Core.UI; using ABI_RC.Core.UI;
using System.Linq; using System.Linq;
using System.Reflection;
using UnityEngine; using UnityEngine;
namespace ml_lme namespace ml_lme
@ -9,9 +11,11 @@ namespace ml_lme
{ {
static readonly Quaternion ms_hmdRotationFix = new Quaternion(0f, 0.7071068f, 0.7071068f, 0f); static readonly Quaternion ms_hmdRotationFix = new Quaternion(0f, 0.7071068f, 0.7071068f, 0f);
static readonly Quaternion ms_screentopRotationFix = new Quaternion(0f, 0f, -1f, 0f); static readonly Quaternion ms_screentopRotationFix = new Quaternion(0f, 0f, -1f, 0f);
static readonly FieldInfo ms_indexGestureToggle = typeof(InputModuleSteamVR).GetField("_steamVrIndexGestureToggleValue", BindingFlags.Instance | BindingFlags.NonPublic);
public static bool IsInVR() => ((ABI_RC.Core.Savior.CheckVR.Instance != null) && ABI_RC.Core.Savior.CheckVR.Instance.hasVrDeviceLoaded); public static bool IsInVR() => ((CheckVR.Instance != null) && CheckVR.Instance.hasVrDeviceLoaded);
public static bool AreKnucklesInUse() => PlayerSetup.Instance._trackerManager.trackerNames.Contains("knuckles"); public static bool AreKnucklesInUse() => PlayerSetup.Instance._trackerManager.trackerNames.Contains("knuckles");
public static bool GetIndexGestureToggle(this InputModuleSteamVR p_module) => (bool)ms_indexGestureToggle.GetValue(p_module);
public static bool IsLeftHandTracked() => ((VRTrackerManager.Instance.leftHand != null) && VRTrackerManager.Instance.leftHand.active); public static bool IsLeftHandTracked() => ((VRTrackerManager.Instance.leftHand != null) && VRTrackerManager.Instance.leftHand.active);
public static bool IsRightHandTracked() => ((VRTrackerManager.Instance.rightHand != null) && VRTrackerManager.Instance.rightHand.active); public static bool IsRightHandTracked() => ((VRTrackerManager.Instance.rightHand != null) && VRTrackerManager.Instance.rightHand.active);

View file

@ -32,6 +32,7 @@ namespace ml_pam
Matrix4x4 m_offset = Matrix4x4.identity; Matrix4x4 m_offset = Matrix4x4.identity;
bool m_targetActive = false; bool m_targetActive = false;
// Unity events
void Start() void Start()
{ {
m_inVR = Utils.IsInVR(); m_inVR = Utils.IsInVR();
@ -67,6 +68,7 @@ namespace ml_pam
} }
} }
// IK updates
void OnIKPreUpdate() void OnIKPreUpdate()
{ {
m_armWeight.Set(m_vrIK.solver.rightArm.positionWeight, m_vrIK.solver.rightArm.rotationWeight); m_armWeight.Set(m_vrIK.solver.rightArm.positionWeight, m_vrIK.solver.rightArm.rotationWeight);

View file

@ -13,8 +13,8 @@ namespace ml_pam
GrabOffset GrabOffset
} }
static bool ms_enabled = true; public static bool Enabled { get; private set; } = true;
static float ms_grabOffset = 0.25f; public static float GrabOffset { get; private set; } = 0.25f;
static MelonLoader.MelonPreferences_Category ms_category = null; static MelonLoader.MelonPreferences_Category ms_category = null;
static List<MelonLoader.MelonPreferences_Entry> ms_entries = null; static List<MelonLoader.MelonPreferences_Entry> ms_entries = null;
@ -28,8 +28,8 @@ namespace ml_pam
ms_entries = new List<MelonLoader.MelonPreferences_Entry>() ms_entries = new List<MelonLoader.MelonPreferences_Entry>()
{ {
ms_category.CreateEntry(ModSetting.Enabled.ToString(), ms_enabled), ms_category.CreateEntry(ModSetting.Enabled.ToString(), Enabled),
ms_category.CreateEntry(ModSetting.GrabOffset.ToString(), 25), ms_category.CreateEntry(ModSetting.GrabOffset.ToString(), (int)(GrabOffset * 100f)),
}; };
Load(); Load();
@ -61,8 +61,8 @@ namespace ml_pam
static void Load() static void Load()
{ {
ms_enabled = (bool)ms_entries[(int)ModSetting.Enabled].BoxedValue; Enabled = (bool)ms_entries[(int)ModSetting.Enabled].BoxedValue;
ms_grabOffset = (int)ms_entries[(int)ModSetting.GrabOffset].BoxedValue * 0.01f; GrabOffset = (int)ms_entries[(int)ModSetting.GrabOffset].BoxedValue * 0.01f;
} }
static void OnToggleUpdate(string p_name, string p_value) static void OnToggleUpdate(string p_name, string p_value)
@ -73,8 +73,8 @@ namespace ml_pam
{ {
case ModSetting.Enabled: case ModSetting.Enabled:
{ {
ms_enabled = bool.Parse(p_value); Enabled = bool.Parse(p_value);
EnabledChange?.Invoke(ms_enabled); EnabledChange?.Invoke(Enabled);
} }
break; break;
} }
@ -91,8 +91,8 @@ namespace ml_pam
{ {
case ModSetting.GrabOffset: case ModSetting.GrabOffset:
{ {
ms_grabOffset = int.Parse(p_value) * 0.01f; GrabOffset = int.Parse(p_value) * 0.01f;
GrabOffsetChange?.Invoke(ms_grabOffset); GrabOffsetChange?.Invoke(GrabOffset);
} }
break; break;
} }
@ -100,14 +100,5 @@ namespace ml_pam
ms_entries[(int)l_setting].BoxedValue = int.Parse(p_value); ms_entries[(int)l_setting].BoxedValue = int.Parse(p_value);
} }
} }
public static bool Enabled
{
get => ms_enabled;
}
public static float GrabOffset
{
get => ms_grabOffset;
}
} }
} }