[EzGrab] Fixes for 2023r172. Add Curve & Tuned Curve options.

This commit is contained in:
NotAKidoS 2023-09-24 06:14:55 -05:00
parent 25ccf7c61c
commit 553da7edb3
6 changed files with 191 additions and 9 deletions

View file

@ -1,5 +1,5 @@
using ABI_RC.Core.Savior;
using ABI_RC.Systems.IK.SubSystems;
using ABI_RC.Systems.InputManagement;
using UnityEngine;
namespace NAK.EzCurls;
@ -20,15 +20,27 @@ internal class InputModuleCurlAdjuster : CVRInputModule
public float CurlSimilarityThreshold = 0.5f;
public float CurlSmoothingFactor = 0.4f;
public new void Start()
// Curve control
public bool UseCurveControl = false;
public AnimationCurve DensityCurve = new AnimationCurve(new Keyframe(0, 0), new Keyframe(0.5f, 1), new Keyframe(1, 0));
// Tuned Curve control
public bool UseTunedCurveControl = false;
private readonly AnimationCurve TunedDensityCurve = new AnimationCurve(
new Keyframe(0, 0), // Start at (0, 0)
new Keyframe(0.5f, 0.5f), // Normal behavior up to (0.3, 0.3)
new Keyframe(0.85f, 0.6f), // Only 0.1f movement from 0.5 to 0.9
new Keyframe(1, 1) // Normal behavior from 0.9 to 1
);
public override void ModuleAdded()
{
Instance = this;
base.Start();
base.ModuleAdded();
EzCurls.OnSettingsChanged();
}
public override void UpdateInput() => DoCurlAdjustments();
public override void UpdateImportantInput() => DoCurlAdjustments();
private void DoCurlAdjustments()
{
@ -83,6 +95,20 @@ internal class InputModuleCurlAdjuster : CVRInputModule
SnapCurls(ref _inputManager.fingerCurlRightRing);
SnapCurls(ref _inputManager.fingerCurlRightPinky);
}
if (UseCurveControl)
{
AdjustCurlUsingCurve(ref _inputManager.fingerCurlLeftIndex);
AdjustCurlUsingCurve(ref _inputManager.fingerCurlLeftMiddle);
AdjustCurlUsingCurve(ref _inputManager.fingerCurlLeftRing);
AdjustCurlUsingCurve(ref _inputManager.fingerCurlLeftPinky);
AdjustCurlUsingCurve(ref _inputManager.fingerCurlRightIndex);
AdjustCurlUsingCurve(ref _inputManager.fingerCurlRightMiddle);
AdjustCurlUsingCurve(ref _inputManager.fingerCurlRightRing);
AdjustCurlUsingCurve(ref _inputManager.fingerCurlRightPinky);
}
}
private void SnapCurls(ref float fingerCurl)
@ -158,4 +184,15 @@ internal class InputModuleCurlAdjuster : CVRInputModule
float dist = curlValue - 0.5f;
return 1.0f - 4 * dist * dist;
}
// middle of curve is more "dense"
private void AdjustCurlUsingCurve(ref float fingerCurl)
{
if (UseTunedCurveControl)
{
fingerCurl = TunedDensityCurve.Evaluate(fingerCurl);
return;
}
fingerCurl = DensityCurve.Evaluate(fingerCurl);
}
}

View file

@ -1,6 +1,9 @@
using ABI_RC.Core.Savior;
using MelonLoader;
using System.Reflection;
using ABI_RC.Systems.InputManagement;
using ABI_RC.Systems.InputManagement.InputModules;
using UnityEngine;
namespace NAK.EzCurls;
@ -47,12 +50,33 @@ public class EzCurls : MelonMod
public static readonly MelonPreferences_Entry<float> EntryCurlSmoothingFactor =
Category.CreateEntry("CurlSmoothingFactor", 0.5f,
description: "The multiplier for curl smoothing.");
// Curve control settings
public static readonly MelonPreferences_Entry<bool> EntryUseCurveControl =
Category.CreateEntry("UseCurveControl", false,
description: "Enable curve control mode to make the midrange of the curl more dense.");
public static readonly MelonPreferences_Entry<bool> EntryUseTunedCurveControl =
Category.CreateEntry("UseTunedCurveControl", false,
description: "Enables a pre-tuned curve.");
public static readonly MelonPreferences_Entry<float> EntryCurveMin =
Category.CreateEntry("CurveMin", 0.0f,
description: "The minimum value of the density curve.");
public static readonly MelonPreferences_Entry<float> EntryCurveMiddle =
Category.CreateEntry("CurveMiddle", 0.5f,
description: "The middle value of the density curve.");
public static readonly MelonPreferences_Entry<float> EntryCurveMax =
Category.CreateEntry("CurveMax", 1.0f,
description: "The maximum value of the density curve.");
public override void OnInitializeMelon()
{
HarmonyInstance.Patch(
typeof(InputModuleSteamVR).GetMethod(nameof(InputModuleSteamVR.Start)),
prefix: new HarmonyLib.HarmonyMethod(typeof(EzCurls).GetMethod(nameof(OnInputModuleSteamVRStart_Prefix), BindingFlags.NonPublic | BindingFlags.Static))
typeof(CVRInputModule_XR).GetMethod(nameof(CVRInputModule_XR.ModuleAdded)),
postfix: new HarmonyLib.HarmonyMethod(typeof(EzCurls).GetMethod(nameof(OnCVRInputModule_XRModuleAdded_Postfix), BindingFlags.NonPublic | BindingFlags.Static))
);
foreach (MelonPreferences_Entry setting in Category.Entries)
@ -76,10 +100,19 @@ public class EzCurls : MelonMod
InputModuleCurlAdjuster.Instance.DontSmoothExtremes = EntryDontSmoothExtremes.Value;
InputModuleCurlAdjuster.Instance.CurlSimilarityThreshold = EntryCurlSimilarityThreshold.Value;
InputModuleCurlAdjuster.Instance.CurlSmoothingFactor = EntryCurlSmoothingFactor.Value;
// curve control
InputModuleCurlAdjuster.Instance.UseCurveControl = EntryUseCurveControl.Value;
InputModuleCurlAdjuster.Instance.UseTunedCurveControl = EntryUseTunedCurveControl.Value;
InputModuleCurlAdjuster.Instance.DensityCurve = new AnimationCurve(
new Keyframe(0, EntryCurveMin.Value),
new Keyframe(0.5f, EntryCurveMiddle.Value),
new Keyframe(1, EntryCurveMax.Value)
);
}
private static void OnInputModuleSteamVRStart_Prefix(ref InputModuleSteamVR __instance)
private static void OnCVRInputModule_XRModuleAdded_Postfix()
{
__instance.gameObject.AddComponent<InputModuleCurlAdjuster>();
CVRInputManager.Instance.AddInputModule(new InputModuleCurlAdjuster());
}
}