mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 14:29:25 +00:00
[EzGrab] Fixes for 2023r172. Add Curve & Tuned Curve options.
This commit is contained in:
parent
25ccf7c61c
commit
553da7edb3
6 changed files with 191 additions and 9 deletions
|
@ -1,5 +1,5 @@
|
||||||
using ABI_RC.Core.Savior;
|
using ABI_RC.Systems.InputManagement;
|
||||||
using ABI_RC.Systems.IK.SubSystems;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace NAK.EzCurls;
|
namespace NAK.EzCurls;
|
||||||
|
|
||||||
|
@ -20,15 +20,27 @@ internal class InputModuleCurlAdjuster : CVRInputModule
|
||||||
public float CurlSimilarityThreshold = 0.5f;
|
public float CurlSimilarityThreshold = 0.5f;
|
||||||
public float CurlSmoothingFactor = 0.4f;
|
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;
|
Instance = this;
|
||||||
base.Start();
|
base.ModuleAdded();
|
||||||
EzCurls.OnSettingsChanged();
|
EzCurls.OnSettingsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void UpdateInput() => DoCurlAdjustments();
|
public override void UpdateInput() => DoCurlAdjustments();
|
||||||
public override void UpdateImportantInput() => DoCurlAdjustments();
|
|
||||||
|
|
||||||
private void DoCurlAdjustments()
|
private void DoCurlAdjustments()
|
||||||
{
|
{
|
||||||
|
@ -83,6 +95,20 @@ internal class InputModuleCurlAdjuster : CVRInputModule
|
||||||
SnapCurls(ref _inputManager.fingerCurlRightRing);
|
SnapCurls(ref _inputManager.fingerCurlRightRing);
|
||||||
SnapCurls(ref _inputManager.fingerCurlRightPinky);
|
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)
|
private void SnapCurls(ref float fingerCurl)
|
||||||
|
@ -158,4 +184,15 @@ internal class InputModuleCurlAdjuster : CVRInputModule
|
||||||
float dist = curlValue - 0.5f;
|
float dist = curlValue - 0.5f;
|
||||||
return 1.0f - 4 * dist * dist;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,9 @@
|
||||||
using ABI_RC.Core.Savior;
|
using ABI_RC.Core.Savior;
|
||||||
using MelonLoader;
|
using MelonLoader;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using ABI_RC.Systems.InputManagement;
|
||||||
|
using ABI_RC.Systems.InputManagement.InputModules;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace NAK.EzCurls;
|
namespace NAK.EzCurls;
|
||||||
|
|
||||||
|
@ -47,12 +50,33 @@ public class EzCurls : MelonMod
|
||||||
public static readonly MelonPreferences_Entry<float> EntryCurlSmoothingFactor =
|
public static readonly MelonPreferences_Entry<float> EntryCurlSmoothingFactor =
|
||||||
Category.CreateEntry("CurlSmoothingFactor", 0.5f,
|
Category.CreateEntry("CurlSmoothingFactor", 0.5f,
|
||||||
description: "The multiplier for curl smoothing.");
|
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()
|
public override void OnInitializeMelon()
|
||||||
{
|
{
|
||||||
HarmonyInstance.Patch(
|
HarmonyInstance.Patch(
|
||||||
typeof(InputModuleSteamVR).GetMethod(nameof(InputModuleSteamVR.Start)),
|
typeof(CVRInputModule_XR).GetMethod(nameof(CVRInputModule_XR.ModuleAdded)),
|
||||||
prefix: new HarmonyLib.HarmonyMethod(typeof(EzCurls).GetMethod(nameof(OnInputModuleSteamVRStart_Prefix), BindingFlags.NonPublic | BindingFlags.Static))
|
postfix: new HarmonyLib.HarmonyMethod(typeof(EzCurls).GetMethod(nameof(OnCVRInputModule_XRModuleAdded_Postfix), BindingFlags.NonPublic | BindingFlags.Static))
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach (MelonPreferences_Entry setting in Category.Entries)
|
foreach (MelonPreferences_Entry setting in Category.Entries)
|
||||||
|
@ -76,10 +100,19 @@ public class EzCurls : MelonMod
|
||||||
InputModuleCurlAdjuster.Instance.DontSmoothExtremes = EntryDontSmoothExtremes.Value;
|
InputModuleCurlAdjuster.Instance.DontSmoothExtremes = EntryDontSmoothExtremes.Value;
|
||||||
InputModuleCurlAdjuster.Instance.CurlSimilarityThreshold = EntryCurlSimilarityThreshold.Value;
|
InputModuleCurlAdjuster.Instance.CurlSimilarityThreshold = EntryCurlSimilarityThreshold.Value;
|
||||||
InputModuleCurlAdjuster.Instance.CurlSmoothingFactor = EntryCurlSmoothingFactor.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());
|
||||||
}
|
}
|
||||||
}
|
}
|
2
EzGrab/EzGrab.csproj
Normal file
2
EzGrab/EzGrab.csproj
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk"/>
|
58
EzGrab/Main.cs
Normal file
58
EzGrab/Main.cs
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
using MelonLoader;
|
||||||
|
using System.Reflection;
|
||||||
|
using ABI_RC.Systems.InputManagement.InputModules;
|
||||||
|
using ABI_RC.Systems.InputManagement.XR;
|
||||||
|
|
||||||
|
namespace NAK.EzGrab;
|
||||||
|
|
||||||
|
public class EzGrab : MelonMod
|
||||||
|
{
|
||||||
|
private const string SettingsCategory = nameof(EzGrab);
|
||||||
|
|
||||||
|
private static readonly MelonPreferences_Category Category =
|
||||||
|
MelonPreferences.CreateCategory(SettingsCategory);
|
||||||
|
|
||||||
|
private static readonly MelonPreferences_Entry<bool> EntryEnabled =
|
||||||
|
Category.CreateEntry("Enabled", true,
|
||||||
|
description: "Should EzGrab be enabled?");
|
||||||
|
|
||||||
|
private static readonly MelonPreferences_Entry<float> EntryReleaseWeight =
|
||||||
|
Category.CreateEntry("Release Weight", 0.1f,
|
||||||
|
description: "The release weight for grip up to fire.");
|
||||||
|
|
||||||
|
public override void OnInitializeMelon()
|
||||||
|
{
|
||||||
|
HarmonyInstance.Patch(
|
||||||
|
typeof(CVRInputModule_XR).GetMethod(nameof(CVRInputModule_XR.Update_Grip)),
|
||||||
|
prefix: new HarmonyLib.HarmonyMethod(typeof(EzGrab).GetMethod(nameof(OnCVRInputModule_XR_Prefix), BindingFlags.NonPublic))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void OnCVRInputModule_XR_Prefix(CVRXRModule module, ref CVRInputModule_XR __instance)
|
||||||
|
{
|
||||||
|
if (module.Type != EXRControllerType.Index || !EntryEnabled.Value) return;
|
||||||
|
|
||||||
|
float gripValue = module.Grip;
|
||||||
|
float gripThreshold = __instance._indexGripThreshold;
|
||||||
|
float releaseThreshold = EntryReleaseWeight.Value;
|
||||||
|
|
||||||
|
if (module.IsLeftHand)
|
||||||
|
{
|
||||||
|
float lastGripLeft = __instance._lastGripLeft;
|
||||||
|
if ((gripValue < gripThreshold && lastGripLeft >= gripThreshold) &&
|
||||||
|
!(gripValue < releaseThreshold && lastGripLeft >= releaseThreshold))
|
||||||
|
{
|
||||||
|
__instance._lastGripLeft = 0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float lastGripRight = __instance._lastGripRight;
|
||||||
|
if ((gripValue < gripThreshold && lastGripRight >= gripThreshold) &&
|
||||||
|
!(gripValue < releaseThreshold && lastGripRight >= releaseThreshold))
|
||||||
|
{
|
||||||
|
__instance._lastGripRight = 0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
29
EzGrab/Properties/AssemblyInfo.cs
Normal file
29
EzGrab/Properties/AssemblyInfo.cs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
using MelonLoader;
|
||||||
|
using NAK.EzGrab.Properties;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
[assembly: AssemblyVersion(AssemblyInfoParams.Version)]
|
||||||
|
[assembly: AssemblyFileVersion(AssemblyInfoParams.Version)]
|
||||||
|
[assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)]
|
||||||
|
[assembly: AssemblyTitle(nameof(NAK.EzGrab))]
|
||||||
|
[assembly: AssemblyCompany(AssemblyInfoParams.Author)]
|
||||||
|
[assembly: AssemblyProduct(nameof(NAK.EzGrab))]
|
||||||
|
|
||||||
|
[assembly: MelonInfo(
|
||||||
|
typeof(NAK.EzGrab.EzGrab),
|
||||||
|
nameof(NAK.EzGrab),
|
||||||
|
AssemblyInfoParams.Version,
|
||||||
|
AssemblyInfoParams.Author,
|
||||||
|
downloadLink: "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/EzGrab"
|
||||||
|
)]
|
||||||
|
|
||||||
|
[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")]
|
||||||
|
[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
|
||||||
|
[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
|
||||||
|
|
||||||
|
namespace NAK.EzGrab.Properties;
|
||||||
|
internal static class AssemblyInfoParams
|
||||||
|
{
|
||||||
|
public const string Version = "1.0.0";
|
||||||
|
public const string Author = "NotAKidoS";
|
||||||
|
}
|
23
EzGrab/format.json
Normal file
23
EzGrab/format.json
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
{
|
||||||
|
"_id": -1,
|
||||||
|
"name": "EzCurls",
|
||||||
|
"modversion": "1.0.0",
|
||||||
|
"gameversion": "2022r170p1",
|
||||||
|
"loaderversion": "0.6.1",
|
||||||
|
"modtype": "Mod",
|
||||||
|
"author": "NotAKidoS",
|
||||||
|
"description": "A mod that should hopefully make finger curls more predictable.",
|
||||||
|
"searchtags": [
|
||||||
|
"aas",
|
||||||
|
"sync",
|
||||||
|
"naked",
|
||||||
|
"buffer"
|
||||||
|
],
|
||||||
|
"requirements": [
|
||||||
|
"UIExpansionKit"
|
||||||
|
],
|
||||||
|
"downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r13/EzCurls.dll",
|
||||||
|
"sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/EzCurls/",
|
||||||
|
"changelog": "- Initial CVRMG release",
|
||||||
|
"embedcolor": "7d7d7d"
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue