(OnToggleUpdate));
+ };
+ ViewManager.Instance.gameMenuView.Listener.FinishLoad += (_) =>
+ {
+ ViewManager.Instance.gameMenuView.View.ExecuteScript(Scripts.GetEmbeddedScript("mods_extension.js"));
+ ViewManager.Instance.gameMenuView.View.ExecuteScript(Scripts.GetEmbeddedScript("mod_menu.js"));
+ foreach(var l_entry in ms_entries)
+ ViewManager.Instance.gameMenuView.View.TriggerEvent("updateModSetting", ms_category.Identifier, l_entry.DisplayName, l_entry.GetValueAsString());
+ };
+ }
+
+ static void OnSliderUpdate(string p_name, string p_value)
+ {
+ if(Enum.TryParse(p_name, out ModSetting l_setting))
+ {
+ switch(l_setting)
+ {
+ case ModSetting.CrouchLimit:
+ {
+ CrouchLimit = int.Parse(p_value) * 0.01f;
+ CrouchLimitChange?.Invoke(CrouchLimit);
+ }
+ break;
+
+ case ModSetting.ProneLimit:
+ {
+ ProneLimit = int.Parse(p_value) * 0.01f;
+ ProneLimitChange?.Invoke(ProneLimit);
+ }
+ break;
+ }
+
+ ms_entries[(int)l_setting].BoxedValue = int.Parse(p_value);
+ }
+ }
+
+ static void OnToggleUpdate(string p_name, string p_value)
+ {
+ if(Enum.TryParse(p_name, out ModSetting l_setting))
+ {
+ switch(l_setting)
+ {
+ case ModSetting.IKOverrideFly:
+ {
+ IKOverrideFly = bool.Parse(p_value);
+ IKOverrideFlyChange?.Invoke(IKOverrideFly);
+ }
+ break;
+
+ case ModSetting.IKOverrideJump:
+ {
+ IKOverrideJump = bool.Parse(p_value);
+ IKOverrideJumpChange?.Invoke(IKOverrideJump);
+ }
+ break;
+
+ case ModSetting.DetectEmotes:
+ {
+ DetectEmotes = bool.Parse(p_value);
+ DetectEmotesChange?.Invoke(DetectEmotes);
+ }
+ break;
+
+ case ModSetting.MassCenter:
+ {
+ MassCenter = bool.Parse(p_value);
+ MassCenterChange?.Invoke(MassCenter);
+ }
+ break;
+ }
+
+ ms_entries[(int)l_setting].BoxedValue = bool.Parse(p_value);
+ }
+ }
+ }
+}
diff --git a/ml_amt/ml_amt.csproj b/ml_amt/ml_amt.csproj
index 8ccfc4b..4a087bb 100644
--- a/ml_amt/ml_amt.csproj
+++ b/ml_amt/ml_amt.csproj
@@ -1,95 +1,87 @@
-
-
-
- netstandard2.1
- SDraw
- None
- AvatarMotionTweaker
- AvatarMotionTweaker
- 1.3.3
- x64
- ml_amt
-
-
-
- x64
- 4
- none
- false
- false
- TRACE
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- D:\Games\Steam\steamapps\common\ChilloutVR\MelonLoader\net35\0Harmony.dll
- false
-
-
- D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp.dll
- false
-
-
- D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp-firstpass.dll
- false
-
-
- D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\cohtml.Net.dll
- false
-
-
- D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Cohtml.Runtime.dll
- false
-
-
- D:\Games\Steam\steamapps\common\ChilloutVR\MelonLoader\net35\MelonLoader.dll
- false
-
-
- D:\games\Steam\steamapps\common\ChilloutVR\Mods\ml_pmc.dll
- false
-
-
- D:\games\Steam\steamapps\common\ChilloutVR\Mods\ml_prm.dll
- false
-
-
- D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.dll
- false
-
-
- D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.AnimationModule.dll
- false
-
-
- D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.CoreModule.dll
- false
-
-
- D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.PhysicsModule.dll
- false
-
-
-
-
-
-
-
-
+
+
+
+ netstandard2.1
+ SDraw
+ None
+ AvatarMotionTweaker
+ AvatarMotionTweaker
+ 1.3.4
+ x64
+ ml_amt
+
+
+
+ x64
+ 4
+ none
+ false
+ false
+ TRACE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ D:\Games\Steam\steamapps\common\ChilloutVR\MelonLoader\net35\0Harmony.dll
+ false
+
+
+ D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp.dll
+ false
+
+
+ D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp-firstpass.dll
+ false
+
+
+ D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\cohtml.Net.dll
+ false
+
+
+ D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Cohtml.Runtime.dll
+ false
+
+
+ D:\Games\Steam\steamapps\common\ChilloutVR\MelonLoader\net35\MelonLoader.dll
+ false
+
+
+ D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.dll
+ false
+
+
+ D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.AnimationModule.dll
+ false
+
+
+ D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.CoreModule.dll
+ false
+
+
+ D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.PhysicsModule.dll
+ false
+
+
+
+
+
+
+
+
diff --git a/ml_amt/resources/mod_menu.js b/ml_amt/resources/mod_menu.js
index f0aa5e1..aab2153 100644
--- a/ml_amt/resources/mod_menu.js
+++ b/ml_amt/resources/mod_menu.js
@@ -1,68 +1,61 @@
-// Add own menu
-{
- let l_block = document.createElement('div');
- l_block.innerHTML = `
-
-
Avatar Motion Tweaker
-
-
-
-
-
-
-
-
-
IK override while flying:
-
-
-
-
-
IK override while jumping:
-
-
-
-
-
Follow hips on IK override:
-
-
-
-
-
Detect animations emote tag:
-
-
-
-
-
Adjusted locomotion mass center:
-
-
- `;
- document.getElementById('settings-ik').appendChild(l_block);
-
- // Toggles
- for (let l_toggle of l_block.querySelectorAll('.inp_toggle'))
- modsExtension.addSetting('AMT', l_toggle.id, modsExtension.createToggle(l_toggle, 'OnToggleUpdate_AMT'));
-
- // Sliders
- for (let l_slider of l_block.querySelectorAll('.inp_slider'))
- modsExtension.addSetting('AMT', l_slider.id, modsExtension.createSlider(l_slider, 'OnSliderUpdate_AMT'));
-}
+// Add own menu
+{
+ let l_block = document.createElement('div');
+ l_block.innerHTML = `
+
+
Avatar Motion Tweaker
+
+
+
+
+
+
+
+
+
IK override while flying:
+
+
+
+
+
Follow hips on IK override:
+
+
+
+
+
Detect animations emote tag:
+
+
+
+
+
Adjusted locomotion mass center:
+
+
+ `;
+ document.getElementById('settings-ik').appendChild(l_block);
+
+ // Toggles
+ for (let l_toggle of l_block.querySelectorAll('.inp_toggle'))
+ modsExtension.addSetting('AMT', l_toggle.id, modsExtension.createToggle(l_toggle, 'OnToggleUpdate_AMT'));
+
+ // Sliders
+ for (let l_slider of l_block.querySelectorAll('.inp_slider'))
+ modsExtension.addSetting('AMT', l_slider.id, modsExtension.createSlider(l_slider, 'OnSliderUpdate_AMT'));
+}
diff --git a/ml_lme/LeapInput.cs b/ml_lme/LeapInput.cs
index e0a4a09..db15cf8 100644
--- a/ml_lme/LeapInput.cs
+++ b/ml_lme/LeapInput.cs
@@ -1,506 +1,506 @@
-using ABI_RC.Core.InteractionSystem;
-using ABI_RC.Core.Player;
-using ABI_RC.Core.Savior;
-using ABI_RC.Systems.IK;
-using ABI_RC.Systems.InputManagement;
-using System.Collections;
-using UnityEngine;
-
-namespace ml_lme
-{
- class LeapInput : CVRInputModule
- {
- bool m_inVR = false;
- bool m_gripToGrab = true;
-
- bool m_handVisibleLeft = false;
- bool m_handVisibleRight = false;
- ControllerRay m_handRayLeft = null;
- ControllerRay m_handRayRight = null;
- LineRenderer m_lineLeft = null;
- LineRenderer m_lineRight = null;
- bool m_interactLeft = false;
- bool m_interactRight = false;
- bool m_gripLeft = false;
- bool m_gripRight = false;
-
- ~LeapInput()
- {
- Settings.EnabledChange -= this.OnEnableChange;
- Settings.InteractionChange -= this.OnInteractionChange;
- Settings.GesturesChange -= this.OnGesturesChange;
- Settings.FingersOnlyChange -= this.OnFingersOnlyChange;
-
- MetaPort.Instance.settings.settingBoolChanged.RemoveListener(this.OnGameSettingBoolChange);
- }
-
- public override void ModuleAdded()
- {
- base.ModuleAdded();
- base.InputEnabled = Settings.Enabled;
- base.HapticFeedback = false;
-
- m_inVR = Utils.IsInVR();
-
- m_handRayLeft = LeapTracking.Instance.GetLeftHand().gameObject.AddComponent();
- m_handRayLeft.hand = true;
- m_handRayLeft.generalMask = -1485;
- m_handRayLeft.isInteractionRay = true;
- m_handRayLeft.triggerGazeEvents = false;
- m_handRayLeft.holderRoot = m_handRayLeft.gameObject;
- m_handRayLeft.attachmentDistance = 0f;
-
- m_lineLeft = m_handRayLeft.gameObject.AddComponent();
- m_lineLeft.endWidth = 1f;
- m_lineLeft.startWidth = 1f;
- m_lineLeft.textureMode = LineTextureMode.Tile;
- m_lineLeft.useWorldSpace = false;
- m_lineLeft.widthMultiplier = 1f;
- m_lineLeft.allowOcclusionWhenDynamic = false;
- m_lineLeft.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
- m_lineLeft.enabled = false;
- m_lineLeft.receiveShadows = false;
- m_handRayLeft.lineRenderer = m_lineLeft;
-
- m_handRayRight = LeapTracking.Instance.GetRightHand().gameObject.AddComponent();
- m_handRayRight.hand = false;
- m_handRayRight.generalMask = -1485;
- m_handRayRight.isInteractionRay = true;
- m_handRayRight.triggerGazeEvents = false;
- m_handRayRight.holderRoot = m_handRayRight.gameObject;
- m_handRayRight.attachmentDistance = 0f;
-
- m_lineRight = m_handRayRight.gameObject.AddComponent();
- m_lineRight.endWidth = 1f;
- m_lineRight.startWidth = 1f;
- m_lineRight.textureMode = LineTextureMode.Tile;
- m_lineRight.useWorldSpace = false;
- m_lineRight.widthMultiplier = 1f;
- m_lineRight.allowOcclusionWhenDynamic = false;
- m_lineRight.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
- m_lineRight.enabled = false;
- m_lineRight.receiveShadows = false;
- m_handRayRight.lineRenderer = m_lineRight;
-
- Settings.EnabledChange += this.OnEnableChange;
- Settings.InteractionChange += this.OnInteractionChange;
- Settings.GesturesChange += this.OnGesturesChange;
- Settings.FingersOnlyChange += this.OnFingersOnlyChange;
-
- OnEnableChange(Settings.Enabled);
- OnInteractionChange(Settings.Interaction);
- OnGesturesChange(Settings.Gestures);
- OnFingersOnlyChange(Settings.FingersOnly);
-
- MelonLoader.MelonCoroutines.Start(WaitForSettings());
- MelonLoader.MelonCoroutines.Start(WaitForMaterial());
- }
-
- IEnumerator WaitForSettings()
- {
- while(MetaPort.Instance == null)
- yield return null;
- while(MetaPort.Instance.settings == null)
- yield return null;
-
- m_gripToGrab = MetaPort.Instance.settings.GetSettingsBool("ControlUseGripToGrab", true);
- MetaPort.Instance.settings.settingBoolChanged.AddListener(this.OnGameSettingBoolChange);
- }
-
- IEnumerator WaitForMaterial()
- {
- while(PlayerSetup.Instance == null)
- yield return null;
- while(PlayerSetup.Instance.leftRay == null)
- yield return null;
- while(PlayerSetup.Instance.leftRay.lineRenderer == null)
- yield return null;
-
- m_lineLeft.material = PlayerSetup.Instance.leftRay.lineRenderer.material;
- m_lineLeft.gameObject.layer = PlayerSetup.Instance.leftRay.gameObject.layer;
- m_lineRight.material = PlayerSetup.Instance.leftRay.lineRenderer.material;
- m_lineRight.gameObject.layer = PlayerSetup.Instance.leftRay.gameObject.layer;
- }
-
- public override void UpdateInput()
- {
- if(base.InputEnabled)
- {
- LeapParser.LeapData l_data = LeapManager.Instance.GetLatestData();
-
- if(l_data.m_leftHand.m_present)
- {
- m_handVisibleLeft = true;
-
- SetFingersInput(l_data.m_leftHand, true);
-
- if(Settings.Gestures)
- {
- base._inputManager.gestureLeftRaw = 0f;
-
- // Finger Point & Finger Gun
- if((base._inputManager.fingerCurlLeftIndex < 0.2f) && (base._inputManager.fingerCurlLeftMiddle > 0.75f) &&
- (base._inputManager.fingerCurlLeftRing > 0.75f) && (base._inputManager.fingerCurlLeftPinky > 0.75f))
- {
- base._inputManager.gestureLeftRaw = (base._inputManager.fingerCurlLeftThumb >= 0.5f) ? 4f : 3f;
- }
-
- // Peace Sign
- if((base._inputManager.fingerCurlLeftIndex < 0.2f) && (base._inputManager.fingerCurlLeftMiddle < 0.2f) &&
- (base._inputManager.fingerCurlLeftRing > 0.75f) && (base._inputManager.fingerCurlLeftPinky > 0.75f))
- {
- base._inputManager.gestureLeftRaw = 5f;
- }
-
- // Rock and Roll
- if((base._inputManager.fingerCurlLeftIndex < 0.2f) && (base._inputManager.fingerCurlLeftMiddle > 0.75f) &&
- (base._inputManager.fingerCurlLeftRing > 0.75f) && (base._inputManager.fingerCurlLeftPinky < 0.5f))
- {
- base._inputManager.gestureLeftRaw = 6f;
- }
-
- // Fist & Thumbs Up
- if((base._inputManager.fingerCurlLeftIndex > 0.5f) && (base._inputManager.fingerCurlLeftMiddle > 0.5f) &&
- (base._inputManager.fingerCurlLeftRing > 0.5f) && (base._inputManager.fingerCurlLeftPinky > 0.5f))
- {
- base._inputManager.gestureLeftRaw = (base._inputManager.fingerCurlLeftThumb >= 0.5f) ? ((l_data.m_leftHand.m_grabStrength - 0.5f) * 2f) : 2f;
- }
-
- // Open Hand
- if((base._inputManager.fingerCurlLeftIndex < 0.2f) && (base._inputManager.fingerCurlLeftMiddle < 0.2f) &&
- (base._inputManager.fingerCurlLeftRing < 0.2f) && (base._inputManager.fingerCurlLeftPinky < 0.2f))
- {
- base._inputManager.gestureLeftRaw = -1f;
- }
-
- base._inputManager.gestureLeft = base._inputManager.gestureLeftRaw;
- }
- }
- else
- {
- if(m_handVisibleLeft)
- {
- ResetFingers(true);
- if(Settings.Gestures)
- ResetGestures(true);
- }
-
- m_handVisibleLeft = false;
- }
-
- if(l_data.m_rightHand.m_present)
- {
- m_handVisibleRight = true;
-
- SetFingersInput(l_data.m_rightHand, false);
-
- if(Settings.Gestures)
- {
- base._inputManager.gestureRightRaw = 0f;
-
- // Finger Point & Finger Gun
- if((base._inputManager.fingerCurlRightIndex < 0.2f) && (base._inputManager.fingerCurlRightMiddle > 0.75f) &&
- (base._inputManager.fingerCurlRightRing > 0.75f) && (base._inputManager.fingerCurlRightPinky > 0.75f))
- {
- base._inputManager.gestureRightRaw = (base._inputManager.fingerCurlRightThumb >= 0.5f) ? 4f : 3f;
- }
-
- // Peace Sign
- if((base._inputManager.fingerCurlRightIndex < 0.2f) && (base._inputManager.fingerCurlRightMiddle < 0.2f) &&
- (base._inputManager.fingerCurlRightRing > 0.75f) && (base._inputManager.fingerCurlRightPinky > 0.75f))
- {
- base._inputManager.gestureRightRaw = 5f;
- }
-
- // Rock and Roll
- if((base._inputManager.fingerCurlRightIndex < 0.2f) && (base._inputManager.fingerCurlRightMiddle > 0.75f) &&
- (base._inputManager.fingerCurlRightRing > 0.75f) && (base._inputManager.fingerCurlRightPinky < 0.5f))
- {
- base._inputManager.gestureRightRaw = 6f;
- }
-
- // Fist & Thumbs Up
- if((base._inputManager.fingerCurlRightIndex > 0.5f) && (base._inputManager.fingerCurlRightMiddle > 0.5f) &&
- (base._inputManager.fingerCurlRightRing > 0.5f) && (base._inputManager.fingerCurlRightPinky > 0.5f))
- {
- base._inputManager.gestureRightRaw = (base._inputManager.fingerCurlRightThumb >= 0.5f) ? ((l_data.m_rightHand.m_grabStrength - 0.5f) * 2f) : 2f;
- }
-
- // Open Hand
- if((base._inputManager.fingerCurlRightIndex < 0.2f) && (base._inputManager.fingerCurlRightMiddle < 0.2f) &&
- (base._inputManager.fingerCurlRightRing < 0.2f) && (base._inputManager.fingerCurlRightPinky < 0.2f))
- {
- base._inputManager.gestureRightRaw = -1f;
- }
-
- base._inputManager.gestureRight = base._inputManager.gestureRightRaw;
- }
- }
- else
- {
- if(m_handVisibleRight)
- {
- ResetFingers(false);
- if(Settings.Gestures)
- ResetGestures(false);
- }
-
- m_handVisibleRight = false;
- }
-
- if(!ModSupporter.SkipFingersOverride() && (!m_inVR || !Utils.AreKnucklesInUse()))
- SetGameFingersTracking(m_handVisibleRight || m_handVisibleLeft);
-
- base.UpdateInput();
- }
- }
-
- public override void Update_Interaction()
- {
- if(Settings.Interaction)
- {
- LeapParser.LeapData l_data = LeapManager.Instance.GetLatestData();
-
- if(m_handVisibleLeft && (!m_inVR || !Utils.IsLeftHandTracked()) && !Settings.FingersOnly)
- {
- float l_strength = l_data.m_leftHand.m_grabStrength;
-
- float l_interactValue = 0f;
- if(m_gripToGrab)
- l_interactValue = Mathf.Clamp01(Mathf.InverseLerp(Mathf.Min(Settings.GripThreadhold, Settings.InteractThreadhold), Mathf.Max(Settings.GripThreadhold, Settings.InteractThreadhold), l_strength));
- else
- l_interactValue = Mathf.Clamp01(Mathf.InverseLerp(0f, Settings.InteractThreadhold, l_strength));
- base._inputManager.interactLeftValue = Mathf.Max(l_interactValue, base._inputManager.interactLeftValue);
-
- if(m_interactLeft != (l_strength > Settings.InteractThreadhold))
- {
- m_interactLeft = (l_strength > Settings.InteractThreadhold);
- base._inputManager.interactLeftDown |= m_interactLeft;
- base._inputManager.interactLeftUp |= !m_interactLeft;
- }
-
- float l_gripValue = Mathf.Clamp01(Mathf.InverseLerp(0f, Settings.GripThreadhold, l_strength));
- base._inputManager.gripLeftValue = Mathf.Max(l_gripValue, base._inputManager.gripLeftValue);
- if(m_gripLeft != (l_strength > Settings.GripThreadhold))
- {
- m_gripLeft = (l_strength > Settings.GripThreadhold);
- base._inputManager.gripLeftDown |= m_gripLeft;
- base._inputManager.gripLeftUp |= !m_gripLeft;
- }
- }
-
- if(m_handVisibleRight && (!m_inVR || !Utils.IsRightHandTracked()) && !Settings.FingersOnly)
- {
- float l_strength = l_data.m_rightHand.m_grabStrength;
-
- float l_interactValue = 0f;
- if(m_gripToGrab)
- l_interactValue = Mathf.Clamp01(Mathf.InverseLerp(Mathf.Min(Settings.GripThreadhold, Settings.InteractThreadhold), Mathf.Max(Settings.GripThreadhold, Settings.InteractThreadhold), l_strength));
- else
- l_interactValue = Mathf.Clamp01(Mathf.InverseLerp(0f, Settings.InteractThreadhold, l_strength));
- base._inputManager.interactRightValue = Mathf.Max(l_interactValue, base._inputManager.interactRightValue);
-
- if(m_interactRight != (l_strength > Settings.InteractThreadhold))
- {
- m_interactRight = (l_strength > Settings.InteractThreadhold);
- base._inputManager.interactRightDown |= m_interactRight;
- base._inputManager.interactRightUp |= !m_interactRight;
- }
-
- float l_gripValue = Mathf.Clamp01(Mathf.InverseLerp(0f, Settings.GripThreadhold, l_strength));
- base._inputManager.gripRightValue = Mathf.Max(l_gripValue, base._inputManager.gripRightValue);
- if(m_gripRight != (l_strength > Settings.GripThreadhold))
- {
- m_gripRight = (l_strength > Settings.GripThreadhold);
- base._inputManager.gripRightDown |= m_gripRight;
- base._inputManager.gripRightUp |= !m_gripRight;
- }
- }
-
- ToggleHandRay(m_handVisibleLeft && (!m_inVR || !Utils.IsLeftHandTracked()) && !Settings.FingersOnly, true);
- ToggleHandRay(m_handVisibleRight && (!m_inVR || !Utils.IsRightHandTracked()) && !Settings.FingersOnly, false);
- }
- }
-
- // Settings changes
- void OnEnableChange(bool p_state)
- {
- base.InputEnabled = p_state;
-
- m_handVisibleLeft &= p_state;
- m_handVisibleRight &= p_state;
-
- if(!p_state)
- {
- ResetFingers(true);
- ResetFingers(false);
-
- if(Settings.Gestures)
- {
- ResetGestures(true);
- ResetGestures(false);
- }
-
- // Reset to default, FreedomFingers can go brrr, player should press funny controller button two times
- SetGameFingersTracking(m_inVR && Utils.AreKnucklesInUse() && !CVRInputManager._moduleXR.GestureToggleValue);
- }
-
- OnInteractionChange(Settings.Interaction);
- }
-
- void OnInteractionChange(bool p_state)
- {
- bool l_state = (p_state && Settings.Enabled && !Settings.FingersOnly);
-
- ToggleHandRay(l_state, true);
- ToggleHandRay(l_state, false);
-
- if(!l_state)
- {
- m_handRayLeft.DropObject(true);
- m_handRayLeft.ClearGrabbedObject();
-
- m_handRayRight.DropObject(true);
- m_handRayRight.ClearGrabbedObject();
-
- m_interactLeft = false;
- m_interactRight = false;
- m_gripLeft = false;
- m_gripRight = false;
- }
- }
-
- void OnGesturesChange(bool p_state)
- {
- base._inputManager.gestureLeft = 0f;
- base._inputManager.gestureLeftRaw = 0f;
- base._inputManager.gestureRight = 0f;
- base._inputManager.gestureRightRaw = 0f;
- }
-
- void OnFingersOnlyChange(bool p_state)
- {
- OnInteractionChange(Settings.Interaction);
- }
-
- // Game events
- internal void OnAvatarSetup()
- {
- m_inVR = Utils.IsInVR();
- }
-
- internal void OnRayScale(float p_scale)
- {
- m_handRayLeft.SetRayScale(p_scale);
- m_handRayRight.SetRayScale(p_scale);
- }
-
- // Arbitrary
- void SetFingersInput(LeapParser.HandData p_hand, bool p_left)
- {
- // Game has spreads in range of [0;1], but mod now operates in range of [-1;1]
- // So spreads will be normalized towards game's range
- if(p_left)
- {
- base._inputManager.fingerCurlLeftThumb = p_hand.m_bends[0];
- base._inputManager.fingerCurlLeftIndex = p_hand.m_bends[1];
- base._inputManager.fingerCurlLeftMiddle = p_hand.m_bends[2];
- base._inputManager.fingerCurlLeftRing = p_hand.m_bends[3];
- base._inputManager.fingerCurlLeftPinky = p_hand.m_bends[4];
- base._inputManager.fingerSpreadLeftThumb = 1f - (p_hand.m_spreads[0] * 0.5f + 0.5f);
- base._inputManager.fingerSpreadLeftIndex = 1f - (p_hand.m_spreads[1] * 0.5f + 0.5f);
- base._inputManager.fingerSpreadLeftMiddle = 1f - (p_hand.m_spreads[2] * 0.5f + 0.5f);
- base._inputManager.fingerSpreadLeftRing = 1f - (p_hand.m_spreads[3] * 0.5f + 0.5f);
- base._inputManager.fingerSpreadLeftPinky = 1f - (p_hand.m_spreads[4] * 0.5f + 0.5f);
- }
- else
- {
- base._inputManager.fingerCurlRightThumb = p_hand.m_bends[0];
- base._inputManager.fingerCurlRightIndex = p_hand.m_bends[1];
- base._inputManager.fingerCurlRightMiddle = p_hand.m_bends[2];
- base._inputManager.fingerCurlRightRing = p_hand.m_bends[3];
- base._inputManager.fingerCurlRightPinky = p_hand.m_bends[4];
- base._inputManager.fingerSpreadRightThumb = 1f - (p_hand.m_spreads[0] * 0.5f + 0.5f);
- base._inputManager.fingerSpreadRightIndex = 1f - (p_hand.m_spreads[1] * 0.5f + 0.5f);
- base._inputManager.fingerSpreadRightMiddle = 1f - (p_hand.m_spreads[2] * 0.5f + 0.5f);
- base._inputManager.fingerSpreadRightRing = 1f - (p_hand.m_spreads[3] * 0.5f + 0.5f);
- base._inputManager.fingerSpreadRightPinky = 1f - (p_hand.m_spreads[4] * 0.5f + 0.5f);
- }
- }
-
- void ResetFingers(bool p_left)
- {
- if(p_left)
- {
- base._inputManager.fingerCurlLeftThumb = 0f;
- base._inputManager.fingerCurlLeftIndex = 0f;
- base._inputManager.fingerCurlLeftMiddle = 0f;
- base._inputManager.fingerCurlLeftRing = 0f;
- base._inputManager.fingerCurlLeftPinky = 0f;
- base._inputManager.fingerSpreadLeftThumb = 0.5f;
- base._inputManager.fingerSpreadLeftIndex = 0.5f;
- base._inputManager.fingerSpreadLeftMiddle = 0.5f;
- base._inputManager.fingerSpreadLeftRing = 0.5f;
- base._inputManager.fingerSpreadLeftPinky = 0.5f;
- }
- else
- {
- base._inputManager.fingerCurlRightThumb = 0f;
- base._inputManager.fingerCurlRightIndex = 0f;
- base._inputManager.fingerCurlRightMiddle = 0f;
- base._inputManager.fingerCurlRightRing = 0f;
- base._inputManager.fingerCurlRightPinky = 0f;
- base._inputManager.fingerSpreadRightThumb = 0.5f;
- base._inputManager.fingerSpreadRightIndex = 0.5f;
- base._inputManager.fingerSpreadRightMiddle = 0.5f;
- base._inputManager.fingerSpreadRightRing = 0.5f;
- base._inputManager.fingerSpreadRightPinky = 0.5f;
- }
- }
-
- void ResetGestures(bool p_left)
- {
- if(p_left)
- {
- base._inputManager.gestureLeft = 0f;
- base._inputManager.gestureLeftRaw = 0f;
- }
- else
- {
- base._inputManager.gestureRight = 0f;
- base._inputManager.gestureRightRaw = 0f;
- }
- }
-
- void ToggleHandRay(bool p_state, bool p_left)
- {
- if(p_left)
- {
- m_handRayLeft.enabled = p_state;
- ((MonoBehaviour)m_handRayLeft).enabled = p_state;
- m_lineLeft.enabled = p_state;
- m_lineLeft.forceRenderingOff = !p_state;
- }
- else
- {
- m_handRayRight.enabled = p_state;
- ((MonoBehaviour)m_handRayRight).enabled = p_state;
- m_lineRight.enabled = p_state;
- m_lineRight.forceRenderingOff = !p_state;
- }
- }
-
- // Game settings
- void OnGameSettingBoolChange(string p_name, bool p_state)
- {
- if(p_name == "ControlUseGripToGrab")
- m_gripToGrab = p_state;
- }
-
- void SetGameFingersTracking(bool p_state)
- {
- base._inputManager.individualFingerTracking = p_state;
- IKSystem.Instance.FingerSystem.controlActive = base._inputManager.individualFingerTracking;
- }
- }
-}
+using ABI_RC.Core.InteractionSystem;
+using ABI_RC.Core.Player;
+using ABI_RC.Core.Savior;
+using ABI_RC.Systems.IK;
+using ABI_RC.Systems.InputManagement;
+using System.Collections;
+using UnityEngine;
+
+namespace ml_lme
+{
+ class LeapInput : CVRInputModule
+ {
+ bool m_inVR = false;
+ bool m_gripToGrab = true;
+
+ bool m_handVisibleLeft = false;
+ bool m_handVisibleRight = false;
+ ControllerRay m_handRayLeft = null;
+ ControllerRay m_handRayRight = null;
+ LineRenderer m_lineLeft = null;
+ LineRenderer m_lineRight = null;
+ bool m_interactLeft = false;
+ bool m_interactRight = false;
+ bool m_gripLeft = false;
+ bool m_gripRight = false;
+
+ ~LeapInput()
+ {
+ Settings.EnabledChange -= this.OnEnableChange;
+ Settings.InteractionChange -= this.OnInteractionChange;
+ Settings.GesturesChange -= this.OnGesturesChange;
+ Settings.FingersOnlyChange -= this.OnFingersOnlyChange;
+
+ MetaPort.Instance.settings.settingBoolChanged.RemoveListener(this.OnGameSettingBoolChange);
+ }
+
+ public override void ModuleAdded()
+ {
+ base.ModuleAdded();
+ base.InputEnabled = Settings.Enabled;
+ base.HapticFeedback = false;
+
+ m_inVR = Utils.IsInVR();
+
+ m_handRayLeft = LeapTracking.Instance.GetLeftHand().gameObject.AddComponent();
+ m_handRayLeft.hand = true;
+ m_handRayLeft.generalMask = -1485;
+ m_handRayLeft.isInteractionRay = true;
+ m_handRayLeft.triggerGazeEvents = false;
+ m_handRayLeft.holderRoot = m_handRayLeft.gameObject;
+ m_handRayLeft.attachmentDistance = 0f;
+
+ m_lineLeft = m_handRayLeft.gameObject.AddComponent();
+ m_lineLeft.endWidth = 1f;
+ m_lineLeft.startWidth = 1f;
+ m_lineLeft.textureMode = LineTextureMode.Tile;
+ m_lineLeft.useWorldSpace = false;
+ m_lineLeft.widthMultiplier = 1f;
+ m_lineLeft.allowOcclusionWhenDynamic = false;
+ m_lineLeft.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
+ m_lineLeft.enabled = false;
+ m_lineLeft.receiveShadows = false;
+ m_handRayLeft.lineRenderer = m_lineLeft;
+
+ m_handRayRight = LeapTracking.Instance.GetRightHand().gameObject.AddComponent();
+ m_handRayRight.hand = false;
+ m_handRayRight.generalMask = -1485;
+ m_handRayRight.isInteractionRay = true;
+ m_handRayRight.triggerGazeEvents = false;
+ m_handRayRight.holderRoot = m_handRayRight.gameObject;
+ m_handRayRight.attachmentDistance = 0f;
+
+ m_lineRight = m_handRayRight.gameObject.AddComponent();
+ m_lineRight.endWidth = 1f;
+ m_lineRight.startWidth = 1f;
+ m_lineRight.textureMode = LineTextureMode.Tile;
+ m_lineRight.useWorldSpace = false;
+ m_lineRight.widthMultiplier = 1f;
+ m_lineRight.allowOcclusionWhenDynamic = false;
+ m_lineRight.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
+ m_lineRight.enabled = false;
+ m_lineRight.receiveShadows = false;
+ m_handRayRight.lineRenderer = m_lineRight;
+
+ Settings.EnabledChange += this.OnEnableChange;
+ Settings.InteractionChange += this.OnInteractionChange;
+ Settings.GesturesChange += this.OnGesturesChange;
+ Settings.FingersOnlyChange += this.OnFingersOnlyChange;
+
+ OnEnableChange(Settings.Enabled);
+ OnInteractionChange(Settings.Interaction);
+ OnGesturesChange(Settings.Gestures);
+ OnFingersOnlyChange(Settings.FingersOnly);
+
+ MelonLoader.MelonCoroutines.Start(WaitForSettings());
+ MelonLoader.MelonCoroutines.Start(WaitForMaterial());
+ }
+
+ IEnumerator WaitForSettings()
+ {
+ while(MetaPort.Instance == null)
+ yield return null;
+ while(MetaPort.Instance.settings == null)
+ yield return null;
+
+ m_gripToGrab = MetaPort.Instance.settings.GetSettingsBool("ControlUseGripToGrab", true);
+ MetaPort.Instance.settings.settingBoolChanged.AddListener(this.OnGameSettingBoolChange);
+ }
+
+ IEnumerator WaitForMaterial()
+ {
+ while(PlayerSetup.Instance == null)
+ yield return null;
+ while(PlayerSetup.Instance.vrRayLeft == null)
+ yield return null;
+ while(PlayerSetup.Instance.vrRayLeft.lineRenderer == null)
+ yield return null;
+
+ m_lineLeft.material = PlayerSetup.Instance.vrRayLeft.lineRenderer.material;
+ m_lineLeft.gameObject.layer = PlayerSetup.Instance.vrRayLeft.gameObject.layer;
+ m_lineRight.material = PlayerSetup.Instance.vrRayLeft.lineRenderer.material;
+ m_lineRight.gameObject.layer = PlayerSetup.Instance.vrRayLeft.gameObject.layer;
+ }
+
+ public override void UpdateInput()
+ {
+ if(base.InputEnabled)
+ {
+ LeapParser.LeapData l_data = LeapManager.Instance.GetLatestData();
+
+ if(l_data.m_leftHand.m_present)
+ {
+ m_handVisibleLeft = true;
+
+ SetFingersInput(l_data.m_leftHand, true);
+
+ if(Settings.Gestures)
+ {
+ base._inputManager.gestureLeftRaw = 0f;
+
+ // Finger Point & Finger Gun
+ if((base._inputManager.fingerCurlLeftIndex < 0.2f) && (base._inputManager.fingerCurlLeftMiddle > 0.75f) &&
+ (base._inputManager.fingerCurlLeftRing > 0.75f) && (base._inputManager.fingerCurlLeftPinky > 0.75f))
+ {
+ base._inputManager.gestureLeftRaw = (base._inputManager.fingerCurlLeftThumb >= 0.5f) ? 4f : 3f;
+ }
+
+ // Peace Sign
+ if((base._inputManager.fingerCurlLeftIndex < 0.2f) && (base._inputManager.fingerCurlLeftMiddle < 0.2f) &&
+ (base._inputManager.fingerCurlLeftRing > 0.75f) && (base._inputManager.fingerCurlLeftPinky > 0.75f))
+ {
+ base._inputManager.gestureLeftRaw = 5f;
+ }
+
+ // Rock and Roll
+ if((base._inputManager.fingerCurlLeftIndex < 0.2f) && (base._inputManager.fingerCurlLeftMiddle > 0.75f) &&
+ (base._inputManager.fingerCurlLeftRing > 0.75f) && (base._inputManager.fingerCurlLeftPinky < 0.5f))
+ {
+ base._inputManager.gestureLeftRaw = 6f;
+ }
+
+ // Fist & Thumbs Up
+ if((base._inputManager.fingerCurlLeftIndex > 0.5f) && (base._inputManager.fingerCurlLeftMiddle > 0.5f) &&
+ (base._inputManager.fingerCurlLeftRing > 0.5f) && (base._inputManager.fingerCurlLeftPinky > 0.5f))
+ {
+ base._inputManager.gestureLeftRaw = (base._inputManager.fingerCurlLeftThumb >= 0.5f) ? ((l_data.m_leftHand.m_grabStrength - 0.5f) * 2f) : 2f;
+ }
+
+ // Open Hand
+ if((base._inputManager.fingerCurlLeftIndex < 0.2f) && (base._inputManager.fingerCurlLeftMiddle < 0.2f) &&
+ (base._inputManager.fingerCurlLeftRing < 0.2f) && (base._inputManager.fingerCurlLeftPinky < 0.2f))
+ {
+ base._inputManager.gestureLeftRaw = -1f;
+ }
+
+ base._inputManager.gestureLeft = base._inputManager.gestureLeftRaw;
+ }
+ }
+ else
+ {
+ if(m_handVisibleLeft)
+ {
+ ResetFingers(true);
+ if(Settings.Gestures)
+ ResetGestures(true);
+ }
+
+ m_handVisibleLeft = false;
+ }
+
+ if(l_data.m_rightHand.m_present)
+ {
+ m_handVisibleRight = true;
+
+ SetFingersInput(l_data.m_rightHand, false);
+
+ if(Settings.Gestures)
+ {
+ base._inputManager.gestureRightRaw = 0f;
+
+ // Finger Point & Finger Gun
+ if((base._inputManager.fingerCurlRightIndex < 0.2f) && (base._inputManager.fingerCurlRightMiddle > 0.75f) &&
+ (base._inputManager.fingerCurlRightRing > 0.75f) && (base._inputManager.fingerCurlRightPinky > 0.75f))
+ {
+ base._inputManager.gestureRightRaw = (base._inputManager.fingerCurlRightThumb >= 0.5f) ? 4f : 3f;
+ }
+
+ // Peace Sign
+ if((base._inputManager.fingerCurlRightIndex < 0.2f) && (base._inputManager.fingerCurlRightMiddle < 0.2f) &&
+ (base._inputManager.fingerCurlRightRing > 0.75f) && (base._inputManager.fingerCurlRightPinky > 0.75f))
+ {
+ base._inputManager.gestureRightRaw = 5f;
+ }
+
+ // Rock and Roll
+ if((base._inputManager.fingerCurlRightIndex < 0.2f) && (base._inputManager.fingerCurlRightMiddle > 0.75f) &&
+ (base._inputManager.fingerCurlRightRing > 0.75f) && (base._inputManager.fingerCurlRightPinky < 0.5f))
+ {
+ base._inputManager.gestureRightRaw = 6f;
+ }
+
+ // Fist & Thumbs Up
+ if((base._inputManager.fingerCurlRightIndex > 0.5f) && (base._inputManager.fingerCurlRightMiddle > 0.5f) &&
+ (base._inputManager.fingerCurlRightRing > 0.5f) && (base._inputManager.fingerCurlRightPinky > 0.5f))
+ {
+ base._inputManager.gestureRightRaw = (base._inputManager.fingerCurlRightThumb >= 0.5f) ? ((l_data.m_rightHand.m_grabStrength - 0.5f) * 2f) : 2f;
+ }
+
+ // Open Hand
+ if((base._inputManager.fingerCurlRightIndex < 0.2f) && (base._inputManager.fingerCurlRightMiddle < 0.2f) &&
+ (base._inputManager.fingerCurlRightRing < 0.2f) && (base._inputManager.fingerCurlRightPinky < 0.2f))
+ {
+ base._inputManager.gestureRightRaw = -1f;
+ }
+
+ base._inputManager.gestureRight = base._inputManager.gestureRightRaw;
+ }
+ }
+ else
+ {
+ if(m_handVisibleRight)
+ {
+ ResetFingers(false);
+ if(Settings.Gestures)
+ ResetGestures(false);
+ }
+
+ m_handVisibleRight = false;
+ }
+
+ if(!ModSupporter.SkipFingersOverride() && (!m_inVR || !Utils.AreKnucklesInUse()))
+ SetGameFingersTracking(m_handVisibleRight || m_handVisibleLeft);
+
+ base.UpdateInput();
+ }
+ }
+
+ public override void Update_Interaction()
+ {
+ if(Settings.Interaction)
+ {
+ LeapParser.LeapData l_data = LeapManager.Instance.GetLatestData();
+
+ if(m_handVisibleLeft && (!m_inVR || !Utils.IsLeftHandTracked()) && !Settings.FingersOnly)
+ {
+ float l_strength = l_data.m_leftHand.m_grabStrength;
+
+ float l_interactValue = 0f;
+ if(m_gripToGrab)
+ l_interactValue = Mathf.Clamp01(Mathf.InverseLerp(Mathf.Min(Settings.GripThreadhold, Settings.InteractThreadhold), Mathf.Max(Settings.GripThreadhold, Settings.InteractThreadhold), l_strength));
+ else
+ l_interactValue = Mathf.Clamp01(Mathf.InverseLerp(0f, Settings.InteractThreadhold, l_strength));
+ base._inputManager.interactLeftValue = Mathf.Max(l_interactValue, base._inputManager.interactLeftValue);
+
+ if(m_interactLeft != (l_strength > Settings.InteractThreadhold))
+ {
+ m_interactLeft = (l_strength > Settings.InteractThreadhold);
+ base._inputManager.interactLeftDown |= m_interactLeft;
+ base._inputManager.interactLeftUp |= !m_interactLeft;
+ }
+
+ float l_gripValue = Mathf.Clamp01(Mathf.InverseLerp(0f, Settings.GripThreadhold, l_strength));
+ base._inputManager.gripLeftValue = Mathf.Max(l_gripValue, base._inputManager.gripLeftValue);
+ if(m_gripLeft != (l_strength > Settings.GripThreadhold))
+ {
+ m_gripLeft = (l_strength > Settings.GripThreadhold);
+ base._inputManager.gripLeftDown |= m_gripLeft;
+ base._inputManager.gripLeftUp |= !m_gripLeft;
+ }
+ }
+
+ if(m_handVisibleRight && (!m_inVR || !Utils.IsRightHandTracked()) && !Settings.FingersOnly)
+ {
+ float l_strength = l_data.m_rightHand.m_grabStrength;
+
+ float l_interactValue = 0f;
+ if(m_gripToGrab)
+ l_interactValue = Mathf.Clamp01(Mathf.InverseLerp(Mathf.Min(Settings.GripThreadhold, Settings.InteractThreadhold), Mathf.Max(Settings.GripThreadhold, Settings.InteractThreadhold), l_strength));
+ else
+ l_interactValue = Mathf.Clamp01(Mathf.InverseLerp(0f, Settings.InteractThreadhold, l_strength));
+ base._inputManager.interactRightValue = Mathf.Max(l_interactValue, base._inputManager.interactRightValue);
+
+ if(m_interactRight != (l_strength > Settings.InteractThreadhold))
+ {
+ m_interactRight = (l_strength > Settings.InteractThreadhold);
+ base._inputManager.interactRightDown |= m_interactRight;
+ base._inputManager.interactRightUp |= !m_interactRight;
+ }
+
+ float l_gripValue = Mathf.Clamp01(Mathf.InverseLerp(0f, Settings.GripThreadhold, l_strength));
+ base._inputManager.gripRightValue = Mathf.Max(l_gripValue, base._inputManager.gripRightValue);
+ if(m_gripRight != (l_strength > Settings.GripThreadhold))
+ {
+ m_gripRight = (l_strength > Settings.GripThreadhold);
+ base._inputManager.gripRightDown |= m_gripRight;
+ base._inputManager.gripRightUp |= !m_gripRight;
+ }
+ }
+
+ ToggleHandRay(m_handVisibleLeft && (!m_inVR || !Utils.IsLeftHandTracked()) && !Settings.FingersOnly, true);
+ ToggleHandRay(m_handVisibleRight && (!m_inVR || !Utils.IsRightHandTracked()) && !Settings.FingersOnly, false);
+ }
+ }
+
+ // Settings changes
+ void OnEnableChange(bool p_state)
+ {
+ base.InputEnabled = p_state;
+
+ m_handVisibleLeft &= p_state;
+ m_handVisibleRight &= p_state;
+
+ if(!p_state)
+ {
+ ResetFingers(true);
+ ResetFingers(false);
+
+ if(Settings.Gestures)
+ {
+ ResetGestures(true);
+ ResetGestures(false);
+ }
+
+ // Reset to default, FreedomFingers can go brrr, player should press funny controller button two times
+ SetGameFingersTracking(m_inVR && Utils.AreKnucklesInUse() && !CVRInputManager._moduleXR.GestureToggleValue);
+ }
+
+ OnInteractionChange(Settings.Interaction);
+ }
+
+ void OnInteractionChange(bool p_state)
+ {
+ bool l_state = (p_state && Settings.Enabled && !Settings.FingersOnly);
+
+ ToggleHandRay(l_state, true);
+ ToggleHandRay(l_state, false);
+
+ if(!l_state)
+ {
+ m_handRayLeft.DropObject(true);
+ m_handRayLeft.ClearGrabbedObject();
+
+ m_handRayRight.DropObject(true);
+ m_handRayRight.ClearGrabbedObject();
+
+ m_interactLeft = false;
+ m_interactRight = false;
+ m_gripLeft = false;
+ m_gripRight = false;
+ }
+ }
+
+ void OnGesturesChange(bool p_state)
+ {
+ base._inputManager.gestureLeft = 0f;
+ base._inputManager.gestureLeftRaw = 0f;
+ base._inputManager.gestureRight = 0f;
+ base._inputManager.gestureRightRaw = 0f;
+ }
+
+ void OnFingersOnlyChange(bool p_state)
+ {
+ OnInteractionChange(Settings.Interaction);
+ }
+
+ // Game events
+ internal void OnAvatarSetup()
+ {
+ m_inVR = Utils.IsInVR();
+ }
+
+ internal void OnRayScale(float p_scale)
+ {
+ m_handRayLeft.SetRayScale(p_scale);
+ m_handRayRight.SetRayScale(p_scale);
+ }
+
+ // Arbitrary
+ void SetFingersInput(LeapParser.HandData p_hand, bool p_left)
+ {
+ // Game has spreads in range of [0;1], but mod now operates in range of [-1;1]
+ // So spreads will be normalized towards game's range
+ if(p_left)
+ {
+ base._inputManager.fingerCurlLeftThumb = p_hand.m_bends[0];
+ base._inputManager.fingerCurlLeftIndex = p_hand.m_bends[1];
+ base._inputManager.fingerCurlLeftMiddle = p_hand.m_bends[2];
+ base._inputManager.fingerCurlLeftRing = p_hand.m_bends[3];
+ base._inputManager.fingerCurlLeftPinky = p_hand.m_bends[4];
+ base._inputManager.fingerSpreadLeftThumb = 1f - (p_hand.m_spreads[0] * 0.5f + 0.5f);
+ base._inputManager.fingerSpreadLeftIndex = 1f - (p_hand.m_spreads[1] * 0.5f + 0.5f);
+ base._inputManager.fingerSpreadLeftMiddle = 1f - (p_hand.m_spreads[2] * 0.5f + 0.5f);
+ base._inputManager.fingerSpreadLeftRing = 1f - (p_hand.m_spreads[3] * 0.5f + 0.5f);
+ base._inputManager.fingerSpreadLeftPinky = 1f - (p_hand.m_spreads[4] * 0.5f + 0.5f);
+ }
+ else
+ {
+ base._inputManager.fingerCurlRightThumb = p_hand.m_bends[0];
+ base._inputManager.fingerCurlRightIndex = p_hand.m_bends[1];
+ base._inputManager.fingerCurlRightMiddle = p_hand.m_bends[2];
+ base._inputManager.fingerCurlRightRing = p_hand.m_bends[3];
+ base._inputManager.fingerCurlRightPinky = p_hand.m_bends[4];
+ base._inputManager.fingerSpreadRightThumb = 1f - (p_hand.m_spreads[0] * 0.5f + 0.5f);
+ base._inputManager.fingerSpreadRightIndex = 1f - (p_hand.m_spreads[1] * 0.5f + 0.5f);
+ base._inputManager.fingerSpreadRightMiddle = 1f - (p_hand.m_spreads[2] * 0.5f + 0.5f);
+ base._inputManager.fingerSpreadRightRing = 1f - (p_hand.m_spreads[3] * 0.5f + 0.5f);
+ base._inputManager.fingerSpreadRightPinky = 1f - (p_hand.m_spreads[4] * 0.5f + 0.5f);
+ }
+ }
+
+ void ResetFingers(bool p_left)
+ {
+ if(p_left)
+ {
+ base._inputManager.fingerCurlLeftThumb = 0f;
+ base._inputManager.fingerCurlLeftIndex = 0f;
+ base._inputManager.fingerCurlLeftMiddle = 0f;
+ base._inputManager.fingerCurlLeftRing = 0f;
+ base._inputManager.fingerCurlLeftPinky = 0f;
+ base._inputManager.fingerSpreadLeftThumb = 0.5f;
+ base._inputManager.fingerSpreadLeftIndex = 0.5f;
+ base._inputManager.fingerSpreadLeftMiddle = 0.5f;
+ base._inputManager.fingerSpreadLeftRing = 0.5f;
+ base._inputManager.fingerSpreadLeftPinky = 0.5f;
+ }
+ else
+ {
+ base._inputManager.fingerCurlRightThumb = 0f;
+ base._inputManager.fingerCurlRightIndex = 0f;
+ base._inputManager.fingerCurlRightMiddle = 0f;
+ base._inputManager.fingerCurlRightRing = 0f;
+ base._inputManager.fingerCurlRightPinky = 0f;
+ base._inputManager.fingerSpreadRightThumb = 0.5f;
+ base._inputManager.fingerSpreadRightIndex = 0.5f;
+ base._inputManager.fingerSpreadRightMiddle = 0.5f;
+ base._inputManager.fingerSpreadRightRing = 0.5f;
+ base._inputManager.fingerSpreadRightPinky = 0.5f;
+ }
+ }
+
+ void ResetGestures(bool p_left)
+ {
+ if(p_left)
+ {
+ base._inputManager.gestureLeft = 0f;
+ base._inputManager.gestureLeftRaw = 0f;
+ }
+ else
+ {
+ base._inputManager.gestureRight = 0f;
+ base._inputManager.gestureRightRaw = 0f;
+ }
+ }
+
+ void ToggleHandRay(bool p_state, bool p_left)
+ {
+ if(p_left)
+ {
+ m_handRayLeft.enabled = p_state;
+ ((MonoBehaviour)m_handRayLeft).enabled = p_state;
+ m_lineLeft.enabled = p_state;
+ m_lineLeft.forceRenderingOff = !p_state;
+ }
+ else
+ {
+ m_handRayRight.enabled = p_state;
+ ((MonoBehaviour)m_handRayRight).enabled = p_state;
+ m_lineRight.enabled = p_state;
+ m_lineRight.forceRenderingOff = !p_state;
+ }
+ }
+
+ // Game settings
+ void OnGameSettingBoolChange(string p_name, bool p_state)
+ {
+ if(p_name == "ControlUseGripToGrab")
+ m_gripToGrab = p_state;
+ }
+
+ void SetGameFingersTracking(bool p_state)
+ {
+ base._inputManager.individualFingerTracking = p_state;
+ IKSystem.Instance.FingerSystem.controlActive = base._inputManager.individualFingerTracking;
+ }
+ }
+}
diff --git a/ml_lme/Properties/AssemblyInfo.cs b/ml_lme/Properties/AssemblyInfo.cs
index b7c503d..24aa9cb 100644
--- a/ml_lme/Properties/AssemblyInfo.cs
+++ b/ml_lme/Properties/AssemblyInfo.cs
@@ -1,6 +1,6 @@
-[assembly: MelonLoader.MelonInfo(typeof(ml_lme.LeapMotionExtension), "LeapMotionExtension", "1.4.3", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
-[assembly: MelonLoader.MelonGame(null, "ChilloutVR")]
-[assembly: MelonLoader.MelonOptionalDependencies("ml_pmc")]
-[assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
-[assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
-[assembly: MelonLoader.MelonAdditionalCredits("NotAKidOnSteam")]
+[assembly: MelonLoader.MelonInfo(typeof(ml_lme.LeapMotionExtension), "LeapMotionExtension", "1.4.4", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
+[assembly: MelonLoader.MelonGame(null, "ChilloutVR")]
+[assembly: MelonLoader.MelonOptionalDependencies("ml_pmc")]
+[assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
+[assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
+[assembly: MelonLoader.MelonAdditionalCredits("NotAKidOnSteam")]
diff --git a/ml_lme/Utils.cs b/ml_lme/Utils.cs
index ed3b80d..a3888db 100644
--- a/ml_lme/Utils.cs
+++ b/ml_lme/Utils.cs
@@ -1,50 +1,50 @@
-using ABI_RC.Core.Savior;
-using ABI_RC.Core.UI;
-using ABI_RC.Systems.InputManagement;
-using System.Reflection;
-using UnityEngine;
-
-namespace ml_lme
-{
- static class Utils
- {
- static readonly FieldInfo ms_view = typeof(CohtmlControlledViewWrapper).GetField("_view", BindingFlags.NonPublic | BindingFlags.Instance);
-
- public static bool IsInVR() => ((CheckVR.Instance != null) && CheckVR.Instance.hasVrDeviceLoaded);
- public static bool AreKnucklesInUse() => ((CVRInputManager.Instance._leftController == ABI_RC.Systems.InputManagement.XR.EXRControllerType.Index) || (CVRInputManager.Instance._rightController == ABI_RC.Systems.InputManagement.XR.EXRControllerType.Index));
- public static bool IsLeftHandTracked() => (CVRInputManager.Instance._leftController != ABI_RC.Systems.InputManagement.XR.EXRControllerType.None);
- public static bool IsRightHandTracked() => (CVRInputManager.Instance._rightController != ABI_RC.Systems.InputManagement.XR.EXRControllerType.None);
-
- public static Matrix4x4 GetMatrix(this Transform p_transform, bool p_pos = true, bool p_rot = true, bool p_scl = false)
- {
- return Matrix4x4.TRS(p_pos ? p_transform.position : Vector3.zero, p_rot ? p_transform.rotation : Quaternion.identity, p_scl ? p_transform.lossyScale : Vector3.one);
- }
-
- public static void ShowHUDNotification(string p_title, string p_message, string p_small = "", bool p_immediate = false)
- {
- if(CohtmlHud.Instance != null)
- {
- if(p_immediate)
- CohtmlHud.Instance.ViewDropTextImmediate(p_title, p_message, p_small);
- else
- CohtmlHud.Instance.ViewDropText(p_title, p_message, p_small);
- }
- }
-
- static public void ExecuteScript(this CohtmlControlledViewWrapper p_instance, string p_script) => ((cohtml.Net.View)ms_view.GetValue(p_instance)).ExecuteScript(p_script);
-
- public static void Swap(ref T lhs, ref T rhs)
- {
- T temp = lhs;
- lhs = rhs;
- rhs = temp;
- }
-
- public static float InverseLerpUnclamped(float a, float b, float value)
- {
- if(a != b)
- return (value - a) / (b - a);
- return 0f;
- }
- }
-}
+using ABI_RC.Core.Savior;
+using ABI_RC.Core.UI;
+using ABI_RC.Systems.InputManagement;
+using System.Reflection;
+using UnityEngine;
+
+namespace ml_lme
+{
+ static class Utils
+ {
+ static readonly FieldInfo ms_view = typeof(CohtmlControlledViewWrapper).GetField("_view", BindingFlags.NonPublic | BindingFlags.Instance);
+
+ public static bool IsInVR() => ((CheckVR.Instance != null) && CheckVR.Instance.hasVrDeviceLoaded);
+ public static bool AreKnucklesInUse() => ((CVRInputManager.Instance._leftController == ABI_RC.Systems.InputManagement.XR.eXRControllerType.Index) || (CVRInputManager.Instance._rightController == ABI_RC.Systems.InputManagement.XR.eXRControllerType.Index));
+ public static bool IsLeftHandTracked() => (CVRInputManager.Instance._leftController != ABI_RC.Systems.InputManagement.XR.eXRControllerType.None);
+ public static bool IsRightHandTracked() => (CVRInputManager.Instance._rightController != ABI_RC.Systems.InputManagement.XR.eXRControllerType.None);
+
+ public static Matrix4x4 GetMatrix(this Transform p_transform, bool p_pos = true, bool p_rot = true, bool p_scl = false)
+ {
+ return Matrix4x4.TRS(p_pos ? p_transform.position : Vector3.zero, p_rot ? p_transform.rotation : Quaternion.identity, p_scl ? p_transform.lossyScale : Vector3.one);
+ }
+
+ public static void ShowHUDNotification(string p_title, string p_message, string p_small = "", bool p_immediate = false)
+ {
+ if(CohtmlHud.Instance != null)
+ {
+ if(p_immediate)
+ CohtmlHud.Instance.ViewDropTextImmediate(p_title, p_message, p_small);
+ else
+ CohtmlHud.Instance.ViewDropText(p_title, p_message, p_small);
+ }
+ }
+
+ static public void ExecuteScript(this CohtmlControlledViewWrapper p_instance, string p_script) => ((cohtml.Net.View)ms_view.GetValue(p_instance)).ExecuteScript(p_script);
+
+ public static void Swap(ref T lhs, ref T rhs)
+ {
+ T temp = lhs;
+ lhs = rhs;
+ rhs = temp;
+ }
+
+ public static float InverseLerpUnclamped(float a, float b, float value)
+ {
+ if(a != b)
+ return (value - a) / (b - a);
+ return 0f;
+ }
+ }
+}
diff --git a/ml_lme/ml_lme.csproj b/ml_lme/ml_lme.csproj
index ca3804c..3360e4c 100644
--- a/ml_lme/ml_lme.csproj
+++ b/ml_lme/ml_lme.csproj
@@ -1,103 +1,103 @@
-
-
-
- netstandard2.1
- x64
- LeapMotionExtension
- 1.4.3
- SDraw
- None
- LeapMotionExtension
-
-
-
- none
- false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- resources/LeapC.dll
-
-
-
-
-
- D:\Games\Steam\steamapps\common\ChilloutVR\MelonLoader\net35\0Harmony.dll
- false
-
-
- D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp.dll
- false
-
-
- D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp-firstpass.dll
- false
-
-
- D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\cohtml.Net.dll
- false
-
-
- D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Cohtml.Runtime.dll
- false
-
-
- D:\Games\Steam\steamapps\common\ChilloutVR\MelonLoader\net35\MelonLoader.dll
- false
-
-
- D:\games\Steam\steamapps\common\ChilloutVR\Mods\ml_pmc.dll
- false
-
-
- D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.dll
- false
-
-
- D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.AnimationModule.dll
- false
-
-
- D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.AssetBundleModule.dll
- false
-
-
- D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.CoreModule.dll
- false
-
-
- D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.XRModule.dll
- false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+ netstandard2.1
+ x64
+ LeapMotionExtension
+ 1.4.4
+ SDraw
+ None
+ LeapMotionExtension
+
+
+
+ none
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ resources/LeapC.dll
+
+
+
+
+
+ D:\Games\Steam\steamapps\common\ChilloutVR\MelonLoader\net35\0Harmony.dll
+ false
+
+
+ D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp.dll
+ false
+
+
+ D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp-firstpass.dll
+ false
+
+
+ D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\cohtml.Net.dll
+ false
+
+
+ D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Cohtml.Runtime.dll
+ false
+
+
+ D:\Games\Steam\steamapps\common\ChilloutVR\MelonLoader\net35\MelonLoader.dll
+ false
+
+
+ D:\games\Steam\steamapps\common\ChilloutVR\Mods\ml_pmc.dll
+ false
+
+
+ D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.dll
+ false
+
+
+ D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.AnimationModule.dll
+ false
+
+
+ D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.AssetBundleModule.dll
+ false
+
+
+ D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.CoreModule.dll
+ false
+
+
+ D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.XRModule.dll
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ml_pam/ArmMover.cs b/ml_pam/ArmMover.cs
index 6091e3b..de0c12e 100644
--- a/ml_pam/ArmMover.cs
+++ b/ml_pam/ArmMover.cs
@@ -1,299 +1,299 @@
-using ABI.CCK.Components;
-using ABI_RC.Core.InteractionSystem;
-using ABI_RC.Core.Player;
-using RootMotion.FinalIK;
-using System.Reflection;
-using UnityEngine;
-
-namespace ml_pam
-{
- [DisallowMultipleComponent]
- class ArmMover : MonoBehaviour
- {
- const float c_offsetLimit = 0.5f;
-
- static readonly float[] ms_tposeMuscles = typeof(ABI_RC.Systems.IK.SubSystems.BodySystem).GetField("TPoseMuscles", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) as float[];
- static readonly Vector4 ms_pointVector = new Vector4(0f, 0f, 0f, 1f);
- static readonly Quaternion ms_offsetRight = Quaternion.Euler(0f, 0f, 90f);
- static readonly Quaternion ms_offsetRightDesktop = Quaternion.Euler(0f, 270f, 0f);
- static readonly Quaternion ms_palmToLeft = Quaternion.Euler(0f, 0f, -90f);
-
- bool m_inVR = false;
- VRIK m_vrIK = null;
- Vector2 m_armWeight = Vector2.zero;
- Transform m_origRightHand = null;
- float m_playspaceScale = 1f;
-
- bool m_enabled = true;
- ArmIK m_armIK = null;
- Transform m_target = null;
- Transform m_rotationTarget = null;
- CVRPickupObject m_pickup = null;
- Matrix4x4 m_offset = Matrix4x4.identity;
- bool m_targetActive = false;
-
- // Unity events
- void Start()
- {
- m_inVR = Utils.IsInVR();
-
- m_target = new GameObject("ArmPickupTarget").transform;
- m_target.parent = PlayerSetup.Instance.GetActiveCamera().transform;
- m_target.localPosition = Vector3.zero;
- m_target.localRotation = Quaternion.identity;
-
- m_rotationTarget = new GameObject("RotationTarget").transform;
- m_rotationTarget.parent = m_target;
- m_rotationTarget.localPosition = new Vector3(c_offsetLimit * Settings.GrabOffset, 0f, 0f);
- m_rotationTarget.localRotation = Quaternion.identity;
-
- m_enabled = Settings.Enabled;
-
- Settings.EnabledChange += this.SetEnabled;
- Settings.GrabOffsetChange += this.SetGrabOffset;
- }
-
- void OnDestroy()
- {
- Settings.EnabledChange -= this.SetEnabled;
- Settings.GrabOffsetChange -= this.SetGrabOffset;
- }
-
- void Update()
- {
- if(m_enabled && !ReferenceEquals(m_pickup, null))
- {
- if(m_pickup != null)
- {
- Matrix4x4 l_result = m_pickup.transform.GetMatrix() * m_offset;
- m_target.position = l_result * ms_pointVector;
- }
- else
- this.OnPickupDrop(m_pickup);
- }
- }
-
- // IK updates
- void OnIKPreUpdate()
- {
- m_armWeight.Set(m_vrIK.solver.rightArm.positionWeight, m_vrIK.solver.rightArm.rotationWeight);
-
- if(m_targetActive && (Mathf.Approximately(m_armWeight.x, 0f) || Mathf.Approximately(m_armWeight.y, 0f)))
- {
- m_vrIK.solver.rightArm.positionWeight = 1f;
- m_vrIK.solver.rightArm.rotationWeight = 1f;
- }
- }
- void OnIKPostUpdate()
- {
- m_vrIK.solver.rightArm.positionWeight = m_armWeight.x;
- m_vrIK.solver.rightArm.rotationWeight = m_armWeight.y;
- }
-
- // Settings
- void SetEnabled(bool p_state)
- {
- m_enabled = p_state;
-
- RefreshArmIK();
- if(m_enabled)
- RestorePickup();
- else
- RestoreVRIK();
- }
-
- void SetGrabOffset(float p_value)
- {
- if(m_rotationTarget != null)
- m_rotationTarget.localPosition = new Vector3(c_offsetLimit * m_playspaceScale * p_value, 0f, 0f);
- }
-
- // Game events
- internal void OnAvatarClear()
- {
- m_vrIK = null;
- m_origRightHand = null;
- m_armIK = null;
- m_targetActive = false;
- }
-
- internal void OnAvatarSetup()
- {
- // Recheck if user could switch to VR
- if(m_inVR != Utils.IsInVR())
- {
- m_target.parent = PlayerSetup.Instance.GetActiveCamera().transform;
- m_target.localPosition = Vector3.zero;
- m_target.localRotation = Quaternion.identity;
- }
-
- m_inVR = Utils.IsInVR();
- m_vrIK = PlayerSetup.Instance._animator.GetComponent();
-
- if(PlayerSetup.Instance._animator.isHuman)
- {
- Vector3 l_hipsPos = Vector3.zero;
- Transform l_hips = PlayerSetup.Instance._animator.GetBoneTransform(HumanBodyBones.Hips);
- if(l_hips != null)
- l_hipsPos = l_hips.localPosition;
-
- HumanPose l_currentPose = new HumanPose();
- HumanPoseHandler l_poseHandler = null;
-
- if(!m_inVR)
- {
- l_poseHandler = new HumanPoseHandler(PlayerSetup.Instance._animator.avatar, PlayerSetup.Instance._avatar.transform);
- l_poseHandler.GetHumanPose(ref l_currentPose);
-
- HumanPose l_tPose = new HumanPose
- {
- bodyPosition = l_currentPose.bodyPosition,
- bodyRotation = l_currentPose.bodyRotation,
- muscles = new float[l_currentPose.muscles.Length]
- };
- for(int i = 0; i < l_tPose.muscles.Length; i++)
- l_tPose.muscles[i] = ms_tposeMuscles[i];
-
- l_poseHandler.SetHumanPose(ref l_tPose);
- }
-
- Transform l_hand = PlayerSetup.Instance._animator.GetBoneTransform(HumanBodyBones.RightHand);
- if(l_hand != null)
- m_rotationTarget.localRotation = (ms_palmToLeft * (m_inVR ? ms_offsetRight : ms_offsetRightDesktop)) * (PlayerSetup.Instance._avatar.transform.GetMatrix().inverse * l_hand.GetMatrix()).rotation;
-
- if(m_vrIK == null)
- {
- Transform l_chest = PlayerSetup.Instance._animator.GetBoneTransform(HumanBodyBones.UpperChest);
- if(l_chest == null)
- l_chest = PlayerSetup.Instance._animator.GetBoneTransform(HumanBodyBones.Chest);
- if(l_chest == null)
- l_chest = PlayerSetup.Instance._animator.GetBoneTransform(HumanBodyBones.Spine);
-
- m_armIK = PlayerSetup.Instance._avatar.AddComponent();
- m_armIK.solver.isLeft = false;
- m_armIK.solver.SetChain(
- l_chest,
- PlayerSetup.Instance._animator.GetBoneTransform(HumanBodyBones.RightShoulder),
- PlayerSetup.Instance._animator.GetBoneTransform(HumanBodyBones.RightUpperArm),
- PlayerSetup.Instance._animator.GetBoneTransform(HumanBodyBones.RightLowerArm),
- l_hand,
- PlayerSetup.Instance._animator.transform
- );
- m_armIK.solver.arm.target = m_rotationTarget;
- m_armIK.solver.arm.positionWeight = 1f;
- m_armIK.solver.arm.rotationWeight = 1f;
- m_armIK.solver.IKPositionWeight = 0f;
- m_armIK.solver.IKRotationWeight = 0f;
- m_armIK.enabled = m_enabled;
- }
- else
- {
- m_origRightHand = m_vrIK.solver.rightArm.target;
- m_vrIK.solver.OnPreUpdate += this.OnIKPreUpdate;
- m_vrIK.solver.OnPostUpdate += this.OnIKPostUpdate;
- }
-
- l_poseHandler?.SetHumanPose(ref l_currentPose);
- l_poseHandler?.Dispose();
-
- if(l_hips != null)
- l_hips.localPosition = l_hipsPos;
- }
-
- if(m_enabled)
- RestorePickup();
- }
-
- internal void OnPickupGrab(CVRPickupObject p_pickup, ControllerRay p_ray, Vector3 p_hit)
- {
- if(p_ray == ViewManager.Instance.desktopControllerRay)
- {
- m_pickup = p_pickup;
-
- // Set offsets
- if(m_pickup.gripType == CVRPickupObject.GripType.Origin)
- {
- if(m_pickup.ikReference != null)
- m_offset = (m_pickup.transform.GetMatrix().inverse * m_pickup.ikReference.GetMatrix());
- else
- {
- if(m_pickup.gripOrigin != null)
- m_offset = m_pickup.transform.GetMatrix().inverse * m_pickup.gripOrigin.GetMatrix();
- }
- }
- else
- m_offset = m_pickup.transform.GetMatrix().inverse * Matrix4x4.Translate(p_hit);
-
- if(m_enabled)
- {
- if((m_vrIK != null) && !m_targetActive)
- {
- m_vrIK.solver.rightArm.target = m_rotationTarget;
- m_targetActive = true;
- }
-
- if(m_armIK != null)
- {
- m_armIK.solver.IKPositionWeight = 1f;
- m_armIK.solver.IKRotationWeight = 1f;
- }
- }
- }
- }
-
- internal void OnPickupDrop(CVRPickupObject p_pickup)
- {
- if(m_pickup == p_pickup)
- {
- m_pickup = null;
-
- if(m_enabled)
- {
- RestoreVRIK();
-
- if(m_armIK != null)
- {
- m_armIK.solver.IKPositionWeight = 0f;
- m_armIK.solver.IKRotationWeight = 0f;
- }
- }
- }
- }
-
- internal void OnPlayspaceScale(float p_relation)
- {
- m_playspaceScale = p_relation;
- SetGrabOffset(Settings.GrabOffset);
- }
-
- // Arbitrary
- void RestorePickup()
- {
- if((m_vrIK != null) && (m_pickup != null))
- {
- m_vrIK.solver.rightArm.target = m_rotationTarget;
- m_targetActive = true;
- }
- if((m_armIK != null) && (m_pickup != null))
- {
- m_armIK.solver.IKPositionWeight = 1f;
- m_armIK.solver.IKRotationWeight = 1f;
- }
- }
-
- void RestoreVRIK()
- {
- if((m_vrIK != null) && m_targetActive)
- {
- m_vrIK.solver.rightArm.target = m_origRightHand;
- m_targetActive = false;
- }
- }
-
- void RefreshArmIK()
- {
- if(m_armIK != null)
- m_armIK.enabled = m_enabled;
- }
- }
-}
+using ABI.CCK.Components;
+using ABI_RC.Core.InteractionSystem;
+using ABI_RC.Core.Player;
+using RootMotion.FinalIK;
+using System.Reflection;
+using UnityEngine;
+
+namespace ml_pam
+{
+ [DisallowMultipleComponent]
+ class ArmMover : MonoBehaviour
+ {
+ const float c_offsetLimit = 0.5f;
+
+ static readonly float[] ms_tposeMuscles = typeof(ABI_RC.Systems.IK.SubSystems.BodySystem).GetField("TPoseMuscles", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) as float[];
+ static readonly Vector4 ms_pointVector = new Vector4(0f, 0f, 0f, 1f);
+ static readonly Quaternion ms_offsetRight = Quaternion.Euler(0f, 0f, 90f);
+ static readonly Quaternion ms_offsetRightDesktop = Quaternion.Euler(0f, 270f, 0f);
+ static readonly Quaternion ms_palmToLeft = Quaternion.Euler(0f, 0f, -90f);
+
+ bool m_inVR = false;
+ VRIK m_vrIK = null;
+ Vector2 m_armWeight = Vector2.zero;
+ Transform m_origRightHand = null;
+ float m_playspaceScale = 1f;
+
+ bool m_enabled = true;
+ ArmIK m_armIK = null;
+ Transform m_target = null;
+ Transform m_rotationTarget = null;
+ CVRPickupObject m_pickup = null;
+ Matrix4x4 m_offset = Matrix4x4.identity;
+ bool m_targetActive = false;
+
+ // Unity events
+ void Start()
+ {
+ m_inVR = Utils.IsInVR();
+
+ m_target = new GameObject("ArmPickupTarget").transform;
+ m_target.parent = PlayerSetup.Instance.GetActiveCamera().transform;
+ m_target.localPosition = Vector3.zero;
+ m_target.localRotation = Quaternion.identity;
+
+ m_rotationTarget = new GameObject("RotationTarget").transform;
+ m_rotationTarget.parent = m_target;
+ m_rotationTarget.localPosition = new Vector3(c_offsetLimit * Settings.GrabOffset, 0f, 0f);
+ m_rotationTarget.localRotation = Quaternion.identity;
+
+ m_enabled = Settings.Enabled;
+
+ Settings.EnabledChange += this.SetEnabled;
+ Settings.GrabOffsetChange += this.SetGrabOffset;
+ }
+
+ void OnDestroy()
+ {
+ Settings.EnabledChange -= this.SetEnabled;
+ Settings.GrabOffsetChange -= this.SetGrabOffset;
+ }
+
+ void Update()
+ {
+ if(m_enabled && !ReferenceEquals(m_pickup, null))
+ {
+ if(m_pickup != null)
+ {
+ Matrix4x4 l_result = m_pickup.transform.GetMatrix() * m_offset;
+ m_target.position = l_result * ms_pointVector;
+ }
+ else
+ this.OnPickupDrop(m_pickup);
+ }
+ }
+
+ // IK updates
+ void OnIKPreUpdate()
+ {
+ m_armWeight.Set(m_vrIK.solver.rightArm.positionWeight, m_vrIK.solver.rightArm.rotationWeight);
+
+ if(m_targetActive && (Mathf.Approximately(m_armWeight.x, 0f) || Mathf.Approximately(m_armWeight.y, 0f)))
+ {
+ m_vrIK.solver.rightArm.positionWeight = 1f;
+ m_vrIK.solver.rightArm.rotationWeight = 1f;
+ }
+ }
+ void OnIKPostUpdate()
+ {
+ m_vrIK.solver.rightArm.positionWeight = m_armWeight.x;
+ m_vrIK.solver.rightArm.rotationWeight = m_armWeight.y;
+ }
+
+ // Settings
+ void SetEnabled(bool p_state)
+ {
+ m_enabled = p_state;
+
+ RefreshArmIK();
+ if(m_enabled)
+ RestorePickup();
+ else
+ RestoreVRIK();
+ }
+
+ void SetGrabOffset(float p_value)
+ {
+ if(m_rotationTarget != null)
+ m_rotationTarget.localPosition = new Vector3(c_offsetLimit * m_playspaceScale * p_value, 0f, 0f);
+ }
+
+ // Game events
+ internal void OnAvatarClear()
+ {
+ m_vrIK = null;
+ m_origRightHand = null;
+ m_armIK = null;
+ m_targetActive = false;
+ }
+
+ internal void OnAvatarSetup()
+ {
+ // Recheck if user could switch to VR
+ if(m_inVR != Utils.IsInVR())
+ {
+ m_target.parent = PlayerSetup.Instance.GetActiveCamera().transform;
+ m_target.localPosition = Vector3.zero;
+ m_target.localRotation = Quaternion.identity;
+ }
+
+ m_inVR = Utils.IsInVR();
+ m_vrIK = PlayerSetup.Instance._animator.GetComponent();
+
+ if(PlayerSetup.Instance._animator.isHuman)
+ {
+ Vector3 l_hipsPos = Vector3.zero;
+ Transform l_hips = PlayerSetup.Instance._animator.GetBoneTransform(HumanBodyBones.Hips);
+ if(l_hips != null)
+ l_hipsPos = l_hips.localPosition;
+
+ HumanPose l_currentPose = new HumanPose();
+ HumanPoseHandler l_poseHandler = null;
+
+ if(!m_inVR)
+ {
+ l_poseHandler = new HumanPoseHandler(PlayerSetup.Instance._animator.avatar, PlayerSetup.Instance._avatar.transform);
+ l_poseHandler.GetHumanPose(ref l_currentPose);
+
+ HumanPose l_tPose = new HumanPose
+ {
+ bodyPosition = l_currentPose.bodyPosition,
+ bodyRotation = l_currentPose.bodyRotation,
+ muscles = new float[l_currentPose.muscles.Length]
+ };
+ for(int i = 0; i < l_tPose.muscles.Length; i++)
+ l_tPose.muscles[i] = ms_tposeMuscles[i];
+
+ l_poseHandler.SetHumanPose(ref l_tPose);
+ }
+
+ Transform l_hand = PlayerSetup.Instance._animator.GetBoneTransform(HumanBodyBones.RightHand);
+ if(l_hand != null)
+ m_rotationTarget.localRotation = (ms_palmToLeft * (m_inVR ? ms_offsetRight : ms_offsetRightDesktop)) * (PlayerSetup.Instance._avatar.transform.GetMatrix().inverse * l_hand.GetMatrix()).rotation;
+
+ if(m_vrIK == null)
+ {
+ Transform l_chest = PlayerSetup.Instance._animator.GetBoneTransform(HumanBodyBones.UpperChest);
+ if(l_chest == null)
+ l_chest = PlayerSetup.Instance._animator.GetBoneTransform(HumanBodyBones.Chest);
+ if(l_chest == null)
+ l_chest = PlayerSetup.Instance._animator.GetBoneTransform(HumanBodyBones.Spine);
+
+ m_armIK = PlayerSetup.Instance._avatar.AddComponent();
+ m_armIK.solver.isLeft = false;
+ m_armIK.solver.SetChain(
+ l_chest,
+ PlayerSetup.Instance._animator.GetBoneTransform(HumanBodyBones.RightShoulder),
+ PlayerSetup.Instance._animator.GetBoneTransform(HumanBodyBones.RightUpperArm),
+ PlayerSetup.Instance._animator.GetBoneTransform(HumanBodyBones.RightLowerArm),
+ l_hand,
+ PlayerSetup.Instance._animator.transform
+ );
+ m_armIK.solver.arm.target = m_rotationTarget;
+ m_armIK.solver.arm.positionWeight = 1f;
+ m_armIK.solver.arm.rotationWeight = 1f;
+ m_armIK.solver.IKPositionWeight = 0f;
+ m_armIK.solver.IKRotationWeight = 0f;
+ m_armIK.enabled = m_enabled;
+ }
+ else
+ {
+ m_origRightHand = m_vrIK.solver.rightArm.target;
+ m_vrIK.solver.OnPreUpdate += this.OnIKPreUpdate;
+ m_vrIK.solver.OnPostUpdate += this.OnIKPostUpdate;
+ }
+
+ l_poseHandler?.SetHumanPose(ref l_currentPose);
+ l_poseHandler?.Dispose();
+
+ if(l_hips != null)
+ l_hips.localPosition = l_hipsPos;
+ }
+
+ if(m_enabled)
+ RestorePickup();
+ }
+
+ internal void OnPickupGrab(CVRPickupObject p_pickup, ControllerRay p_ray, Vector3 p_hit)
+ {
+ if(p_ray == ViewManager.Instance.desktopControllerRay)
+ {
+ m_pickup = p_pickup;
+
+ // Set offsets
+ if(m_pickup.gripType == CVRPickupObject.GripType.Origin)
+ {
+ if(m_pickup.ikReference != null)
+ m_offset = (m_pickup.transform.GetMatrix().inverse * m_pickup.ikReference.GetMatrix());
+ else
+ {
+ if(m_pickup.gripOrigin != null)
+ m_offset = m_pickup.transform.GetMatrix().inverse * m_pickup.gripOrigin.GetMatrix();
+ }
+ }
+ else
+ m_offset = m_pickup.transform.GetMatrix().inverse * Matrix4x4.Translate(p_hit);
+
+ if(m_enabled)
+ {
+ if((m_vrIK != null) && !m_targetActive)
+ {
+ m_vrIK.solver.rightArm.target = m_rotationTarget;
+ m_targetActive = true;
+ }
+
+ if(m_armIK != null)
+ {
+ m_armIK.solver.IKPositionWeight = 1f;
+ m_armIK.solver.IKRotationWeight = 1f;
+ }
+ }
+ }
+ }
+
+ internal void OnPickupDrop(CVRPickupObject p_pickup)
+ {
+ if(m_pickup == p_pickup)
+ {
+ m_pickup = null;
+
+ if(m_enabled)
+ {
+ RestoreVRIK();
+
+ if(m_armIK != null)
+ {
+ m_armIK.solver.IKPositionWeight = 0f;
+ m_armIK.solver.IKRotationWeight = 0f;
+ }
+ }
+ }
+ }
+
+ internal void OnPlayspaceScale(float p_relation)
+ {
+ m_playspaceScale = p_relation;
+ SetGrabOffset(Settings.GrabOffset);
+ }
+
+ // Arbitrary
+ void RestorePickup()
+ {
+ if((m_vrIK != null) && (m_pickup != null))
+ {
+ m_vrIK.solver.rightArm.target = m_rotationTarget;
+ m_targetActive = true;
+ }
+ if((m_armIK != null) && (m_pickup != null))
+ {
+ m_armIK.solver.IKPositionWeight = 1f;
+ m_armIK.solver.IKRotationWeight = 1f;
+ }
+ }
+
+ void RestoreVRIK()
+ {
+ if((m_vrIK != null) && m_targetActive)
+ {
+ m_vrIK.solver.rightArm.target = m_origRightHand;
+ m_targetActive = false;
+ }
+ }
+
+ void RefreshArmIK()
+ {
+ if(m_armIK != null)
+ m_armIK.enabled = m_enabled;
+ }
+ }
+}
diff --git a/ml_pmc/Utils.cs b/ml_pmc/Utils.cs
index 0b93404..19fc92c 100644
--- a/ml_pmc/Utils.cs
+++ b/ml_pmc/Utils.cs
@@ -1,79 +1,79 @@
-using ABI.CCK.Components;
-using ABI_RC.Core.Player;
-using ABI_RC.Core.Savior;
-using ABI_RC.Systems.InputManagement;
-using System.Linq;
-using System.Reflection;
-using UnityEngine;
-
-namespace ml_pmc
-{
- static class Utils
- {
- static readonly (int, int)[] ms_sideMuscles = new (int, int)[]
- {
- (29,21), (30,22), (31,23), (32,24), (33,25), (34,26), (35,27), (36,28),
- (46,37), (47,38), (48,39), (49,40), (50,41), (51,42), (52,43), (53,44), (54,45),
- (75,55), (76,56), (77,57), (78,58), (79,59), (80,60), (81,61), (82,62), (83,63), (84,64),
- (85,65), (86,66), (87,67), (88,68), (89, 69), (90,70), (91,71), (92,72), (93,73), (94,74)
- };
- static readonly int[] ms_centralMuscles = new int[] { 1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 18, 20 };
-
- public static bool IsInVR() => ((CheckVR.Instance != null) && CheckVR.Instance.hasVrDeviceLoaded);
- public static bool AreKnucklesInUse() => ((CVRInputManager.Instance._leftController == ABI_RC.Systems.InputManagement.XR.EXRControllerType.Index) || (CVRInputManager.Instance._rightController == ABI_RC.Systems.InputManagement.XR.EXRControllerType.Index));
-
- public static bool IsWorldSafe() => ((CVRWorld.Instance != null) && CVRWorld.Instance.allowFlying);
- public static bool IsCombatSafe() => ((CombatSystem.Instance == null) || !CombatSystem.Instance.isDown);
-
- public static float GetWorldMovementLimit()
- {
- float l_result = 1f;
- if(CVRWorld.Instance != null)
- {
- l_result = CVRWorld.Instance.baseMovementSpeed;
- l_result *= CVRWorld.Instance.sprintMultiplier;
- l_result *= CVRWorld.Instance.inAirMovementMultiplier;
- l_result *= CVRWorld.Instance.flyMultiplier;
- }
- return l_result;
- }
-
- public static Matrix4x4 GetMatrix(this Transform p_transform, bool p_pos = true, bool p_rot = true, bool p_scl = false)
- {
- return Matrix4x4.TRS(p_pos ? p_transform.position : Vector3.zero, p_rot ? p_transform.rotation : Quaternion.identity, p_scl ? p_transform.lossyScale : Vector3.one);
- }
-
- public static void CopyTo(this HumanPose p_source, ref HumanPose p_target)
- {
- p_target.bodyPosition = p_source.bodyPosition;
- p_target.bodyRotation = p_source.bodyRotation;
-
- int l_count = Mathf.Min(p_source.muscles.Length, p_target.muscles.Length);
- for(int i = 0; i < l_count; i++)
- p_target.muscles[i] = p_source.muscles[i];
- }
-
- public static void MirrorPose(ref HumanPose p_pose)
- {
- int l_count = p_pose.muscles.Length;
- foreach(var l_pair in ms_sideMuscles)
- {
- if((l_count > l_pair.Item1) && (l_count > l_pair.Item2))
- {
- float l_temp = p_pose.muscles[l_pair.Item1];
- p_pose.muscles[l_pair.Item1] = p_pose.muscles[l_pair.Item2];
- p_pose.muscles[l_pair.Item2] = l_temp;
- }
- }
- foreach(int l_index in ms_centralMuscles)
- {
- if(l_count > l_index)
- p_pose.muscles[l_index] *= -1f;
- }
-
- p_pose.bodyRotation.x *= -1f;
- p_pose.bodyRotation.w *= -1f;
- p_pose.bodyPosition.x *= -1f;
- }
- }
-}
+using ABI.CCK.Components;
+using ABI_RC.Core.Player;
+using ABI_RC.Core.Savior;
+using ABI_RC.Systems.InputManagement;
+using System.Linq;
+using System.Reflection;
+using UnityEngine;
+
+namespace ml_pmc
+{
+ static class Utils
+ {
+ static readonly (int, int)[] ms_sideMuscles = new (int, int)[]
+ {
+ (29,21), (30,22), (31,23), (32,24), (33,25), (34,26), (35,27), (36,28),
+ (46,37), (47,38), (48,39), (49,40), (50,41), (51,42), (52,43), (53,44), (54,45),
+ (75,55), (76,56), (77,57), (78,58), (79,59), (80,60), (81,61), (82,62), (83,63), (84,64),
+ (85,65), (86,66), (87,67), (88,68), (89, 69), (90,70), (91,71), (92,72), (93,73), (94,74)
+ };
+ static readonly int[] ms_centralMuscles = new int[] { 1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 18, 20 };
+
+ public static bool IsInVR() => ((CheckVR.Instance != null) && CheckVR.Instance.hasVrDeviceLoaded);
+ public static bool AreKnucklesInUse() => ((CVRInputManager.Instance._leftController == ABI_RC.Systems.InputManagement.XR.eXRControllerType.Index) || (CVRInputManager.Instance._rightController == ABI_RC.Systems.InputManagement.XR.eXRControllerType.Index));
+
+ public static bool IsWorldSafe() => ((CVRWorld.Instance != null) && CVRWorld.Instance.allowFlying);
+ public static bool IsCombatSafe() => ((CombatSystem.Instance == null) || !CombatSystem.Instance.isDown);
+
+ public static float GetWorldMovementLimit()
+ {
+ float l_result = 1f;
+ if(CVRWorld.Instance != null)
+ {
+ l_result = CVRWorld.Instance.baseMovementSpeed;
+ l_result *= CVRWorld.Instance.sprintMultiplier;
+ l_result *= CVRWorld.Instance.inAirMovementMultiplier;
+ l_result *= CVRWorld.Instance.flyMultiplier;
+ }
+ return l_result;
+ }
+
+ public static Matrix4x4 GetMatrix(this Transform p_transform, bool p_pos = true, bool p_rot = true, bool p_scl = false)
+ {
+ return Matrix4x4.TRS(p_pos ? p_transform.position : Vector3.zero, p_rot ? p_transform.rotation : Quaternion.identity, p_scl ? p_transform.lossyScale : Vector3.one);
+ }
+
+ public static void CopyTo(this HumanPose p_source, ref HumanPose p_target)
+ {
+ p_target.bodyPosition = p_source.bodyPosition;
+ p_target.bodyRotation = p_source.bodyRotation;
+
+ int l_count = Mathf.Min(p_source.muscles.Length, p_target.muscles.Length);
+ for(int i = 0; i < l_count; i++)
+ p_target.muscles[i] = p_source.muscles[i];
+ }
+
+ public static void MirrorPose(ref HumanPose p_pose)
+ {
+ int l_count = p_pose.muscles.Length;
+ foreach(var l_pair in ms_sideMuscles)
+ {
+ if((l_count > l_pair.Item1) && (l_count > l_pair.Item2))
+ {
+ float l_temp = p_pose.muscles[l_pair.Item1];
+ p_pose.muscles[l_pair.Item1] = p_pose.muscles[l_pair.Item2];
+ p_pose.muscles[l_pair.Item2] = l_temp;
+ }
+ }
+ foreach(int l_index in ms_centralMuscles)
+ {
+ if(l_count > l_index)
+ p_pose.muscles[l_index] *= -1f;
+ }
+
+ p_pose.bodyRotation.x *= -1f;
+ p_pose.bodyRotation.w *= -1f;
+ p_pose.bodyPosition.x *= -1f;
+ }
+ }
+}
diff --git a/ml_vei/Main.cs b/ml_vei/Main.cs
index 7379cbe..dcf0cb3 100644
--- a/ml_vei/Main.cs
+++ b/ml_vei/Main.cs
@@ -1,56 +1,56 @@
-using ABI_RC.Systems.InputManagement;
-using ABI_RC.Systems.InputManagement.XR;
-using System;
-using System.Reflection;
-
-namespace ml_vei
-{
- public class ViveExtendedInput : MelonLoader.MelonMod
- {
- public override void OnInitializeMelon()
- {
- Settings.Init();
-
- HarmonyInstance.Patch(
- typeof(CVRXRModule).GetMethod("Update_Gestures_Vive", BindingFlags.NonPublic | BindingFlags.Instance),
- null,
- new HarmonyLib.HarmonyMethod(typeof(ViveExtendedInput).GetMethod(nameof(OnViveGesturesUpdate_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
- );
- }
-
- static void OnViveGesturesUpdate_Postfix(ref CVRXRModule __instance)
- {
- try
- {
- if(Settings.Gestures)
- {
- float l_mag = ((!__instance.HasEmoteOverride) ? __instance.Primary2DAxis : __instance.EmoteOverride).magnitude;
- if(__instance.ViveDirectionPressed && (l_mag >= CVRInputManager.VrViveGestureDeadZone))
- {
- if(Settings.GripTrigger)
- {
- switch(Settings.AxisPriority)
- {
- case Settings.PriorityAxis.Grip:
- __instance.GestureRaw = ((__instance.Grip > 0.5f) ? -1f : __instance.Trigger);
- break;
-
- case Settings.PriorityAxis.Trigger:
- __instance.GestureRaw = (!UnityEngine.Mathf.Approximately(__instance.Trigger, 0f) ? __instance.Trigger : ((__instance.Grip > 0.5f) ? -1f : 0f));
- break;
- }
- }
- else
- __instance.GestureRaw = 0f;
-
- __instance.Gesture = __instance.GestureRaw;
- }
- }
- }
- catch(Exception e)
- {
- MelonLoader.MelonLogger.Error(e);
- }
- }
- }
-}
+using ABI_RC.Systems.InputManagement;
+using ABI_RC.Systems.InputManagement.XR;
+using System;
+using System.Reflection;
+
+namespace ml_vei
+{
+ public class ViveExtendedInput : MelonLoader.MelonMod
+ {
+ public override void OnInitializeMelon()
+ {
+ Settings.Init();
+
+ HarmonyInstance.Patch(
+ typeof(CVRXRModule).GetMethod("Update_Gestures_Vive", BindingFlags.NonPublic | BindingFlags.Instance),
+ null,
+ new HarmonyLib.HarmonyMethod(typeof(ViveExtendedInput).GetMethod(nameof(OnViveGesturesUpdate_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
+ );
+ }
+
+ static void OnViveGesturesUpdate_Postfix(ref CVRXRModule __instance)
+ {
+ try
+ {
+ if(Settings.Gestures)
+ {
+ float l_mag = ((!__instance.HasEmoteOverride) ? __instance.Primary2DAxis : __instance.EmoteOverride).magnitude;
+ if(__instance.ViveDirectionPressed && (l_mag >= CVRInputManager.VrViveGestureDeadZone))
+ {
+ if(Settings.GripTrigger)
+ {
+ switch(Settings.AxisPriority)
+ {
+ case Settings.PriorityAxis.Grip:
+ __instance.GestureRaw = ((__instance.Grip > 0.5f) ? -1f : __instance.Trigger);
+ break;
+
+ case Settings.PriorityAxis.Trigger:
+ __instance.GestureRaw = (!UnityEngine.Mathf.Approximately(__instance.Trigger, 0f) ? __instance.Trigger : ((__instance.Grip > 0.5f) ? -1f : 0f));
+ break;
+ }
+ }
+ else
+ __instance.GestureRaw = 0f;
+
+ __instance.Gesture = __instance.GestureRaw;
+ }
+ }
+ }
+ catch(Exception e)
+ {
+ MelonLoader.MelonLogger.Error(e);
+ }
+ }
+ }
+}