Scaled locomotion steps

Funny C# properties
Minor fixes
This commit is contained in:
SDraw 2023-03-03 00:44:17 +03:00
parent fc60219a4e
commit 28aca1bb49
No known key found for this signature in database
GPG key ID: BB95B4DAB2BB8BB5
11 changed files with 343 additions and 410 deletions

View file

@ -98,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);
@ -260,13 +260,10 @@ namespace ml_amt
{ {
try try
{ {
if(Settings.OverrideFix) if(Settings.OverrideFix && (__instance.animator != null))
{ {
if(__instance.animator != null) __instance.animator.enabled = false;
{ __instance.animator.WriteDefaultValues();
__instance.animator.enabled = false;
__instance.animator.WriteDefaultValues();
}
} }
} }
catch(System.Exception l_exception) catch(System.Exception l_exception)
@ -278,13 +275,10 @@ namespace ml_amt
{ {
try try
{ {
if(Settings.OverrideFix) if(Settings.OverrideFix && (__instance.animator != null))
{ {
if(__instance.animator != null) __instance.animator.enabled = true;
{ __instance.animator.Update(0f);
__instance.animator.enabled = true;
__instance.animator.Update(0f);
}
} }
} }
catch(System.Exception l_exception) catch(System.Exception 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;
@ -65,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;
@ -74,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();
@ -88,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()
@ -103,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()
@ -163,6 +167,7 @@ namespace ml_amt
} }
} }
// Game events
internal void OnAvatarClear() internal void OnAvatarClear()
{ {
m_vrIk = null; m_vrIk = null;
@ -183,6 +188,7 @@ namespace ml_amt
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();
} }
@ -253,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);
} }
@ -276,12 +284,23 @@ namespace ml_amt
internal void OnPlayspaceScale() internal void OnPlayspaceScale()
{ {
if((m_vrIk != null) && Settings.MassCenter) if(m_vrIk != null)
{ {
m_vrIk.solver.locomotion.offset = m_massCenter * GetRelativeScale(); 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_locomotionOverride = false; bool l_locomotionOverride = false;
@ -342,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;
@ -370,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;
@ -380,33 +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 * GetRelativeScale()) : 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() float GetRelativeScale()
{ {
return ((m_avatarScale > 0f) ? (PlayerSetup.Instance._avatar.transform.localScale.y / m_avatarScale) : 0f); 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 = true; 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(), true) 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

@ -257,6 +257,13 @@ function inp_toggle_mod_amt(_obj, _callbackName) {
</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>
<div class ="option-input"> <div class ="option-input">

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

@ -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()
@ -168,6 +138,7 @@ namespace ml_lme
} }
} }
// 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 +198,7 @@ namespace ml_lme
} }
} }
// Game events
internal void OnAvatarClear() internal void OnAvatarClear()
{ {
m_vrIK = null; m_vrIK = null;
@ -348,6 +320,7 @@ namespace ml_lme
} }
} }
// IK updates
void OnIKPreUpdate() void OnIKPreUpdate()
{ {
m_armsWeights.Set( m_armsWeights.Set(
@ -376,6 +349,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,72 @@ namespace ml_lme
{ {
case ModSetting.DesktopX: case ModSetting.DesktopX:
{ {
ms_desktopOffset.x = int.Parse(p_value) * 0.01f; DesktopOffset.Set(int.Parse(p_value) * 0.01f, DesktopOffset.y, DesktopOffset.z);
DesktopOffsetChange?.Invoke(ms_desktopOffset); DesktopOffsetChange?.Invoke(DesktopOffset);
} }
break; break;
case ModSetting.DesktopY: case ModSetting.DesktopY:
{ {
ms_desktopOffset.y = int.Parse(p_value) * 0.01f; DesktopOffset.Set(DesktopOffset.x, int.Parse(p_value) * 0.01f, DesktopOffset.z);
DesktopOffsetChange?.Invoke(ms_desktopOffset); DesktopOffsetChange?.Invoke(DesktopOffset);
} }
break; break;
case ModSetting.DesktopZ: case ModSetting.DesktopZ:
{ {
ms_desktopOffset.z = int.Parse(p_value) * 0.01f; DesktopOffset.Set(DesktopOffset.x, DesktopOffset.y, int.Parse(p_value) * 0.01f);
DesktopOffsetChange?.Invoke(ms_desktopOffset); DesktopOffsetChange?.Invoke(DesktopOffset);
} }
break; break;
case ModSetting.AngleX: case ModSetting.AngleX:
{ {
ms_rootAngle.x = int.Parse(p_value); RootAngle.Set(int.Parse(p_value), RootAngle.y, RootAngle.z);
RootAngleChange?.Invoke(ms_rootAngle); RootAngleChange?.Invoke(RootAngle);
} }
break; break;
case ModSetting.AngleY: case ModSetting.AngleY:
{ {
ms_rootAngle.y = int.Parse(p_value); RootAngle.Set(RootAngle.x, int.Parse(p_value), RootAngle.z);
RootAngleChange?.Invoke(ms_rootAngle); RootAngleChange?.Invoke(RootAngle);
} }
break; break;
case ModSetting.AngleZ: case ModSetting.AngleZ:
{ {
ms_rootAngle.z = int.Parse(p_value); RootAngle.Set(RootAngle.x, RootAngle.y, int.Parse(p_value));
RootAngleChange?.Invoke(ms_rootAngle); RootAngleChange?.Invoke(RootAngle);
} }
break; break;
case ModSetting.HeadX: case ModSetting.HeadX:
{ {
ms_headOffset.x = int.Parse(p_value) * 0.01f; HeadOffset.Set(int.Parse(p_value) * 0.01f, HeadOffset.y, HeadOffset.z);
HeadOffsetChange?.Invoke(ms_headOffset); HeadOffsetChange?.Invoke(HeadOffset);
} }
break; break;
case ModSetting.HeadY: case ModSetting.HeadY:
{ {
ms_headOffset.y = int.Parse(p_value) * 0.01f; HeadOffset.Set(HeadOffset.x, int.Parse(p_value) * 0.01f, HeadOffset.z);
HeadOffsetChange?.Invoke(ms_headOffset); HeadOffsetChange?.Invoke(HeadOffset);
} }
break; break;
case ModSetting.HeadZ: case ModSetting.HeadZ:
{ {
ms_headOffset.z = int.Parse(p_value) * 0.01f; HeadOffset.Set(HeadOffset.x, HeadOffset.y, int.Parse(p_value) * 0.01f);
HeadOffsetChange?.Invoke(ms_headOffset); HeadOffsetChange?.Invoke(HeadOffset);
} }
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 +291,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 +300,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

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