SmoothRay: cleanup

This commit is contained in:
NotAKidoS 2024-09-18 19:45:08 -05:00
parent 35943bd709
commit 59cec7e7d3
4 changed files with 93 additions and 31 deletions

View file

@ -1,4 +1,6 @@
using ABI_RC.Core.Player;
using System;
using ABI_RC.Core.InteractionSystem;
using ABI_RC.Core.Player;
using HarmonyLib;
using MelonLoader;
@ -8,31 +10,33 @@ namespace NAK.SmoothRay;
// https://github.com/kinsi55/BeatSaber_SmoothedController
// https://github.com/kinsi55/BeatSaber_SmoothedController/blob/master/LICENSE
public class SmoothRay : MelonMod
public class SmoothRayMod : MelonMod
{
internal static MelonLogger.Instance Logger;
#region Melon Preferences
public static readonly MelonPreferences_Category Category =
MelonPreferences.CreateCategory(nameof(SmoothRay));
MelonPreferences.CreateCategory(nameof(SmoothRayMod));
public static readonly MelonPreferences_Entry<bool> EntryEnabled =
Category.CreateEntry("Enable Smoothing", true,
description: "Enable or disable smoothing.");
public static readonly MelonPreferences_Entry<bool> EntryMenuOnly =
Category.CreateEntry("Menu Only", true,
description: "Only use smoothing on Main Menu and Quick Menu. This will be fine for most users, but it may be desired on pickups & Unity UI elements too.");
Category.CreateEntry("Menu Only", false,
description: "Only use smoothing on Main Menu and Quick Menu. This will be fine for most users, but it may be desired on pickups & Unity UI elements too. When off it is best paired with WhereAmIPointing.");
public static readonly MelonPreferences_Entry<float> EntryPositionSmoothing =
Category.CreateEntry("Position Smoothing", 3f,
Category.CreateEntry("Position Smoothing (3f)", 3f,
description: "How much to smooth position changes by. Use the slider to adjust the position smoothing factor. Range: 0 to 20.");
public static readonly MelonPreferences_Entry<float> EntryRotationSmoothing =
Category.CreateEntry("Rotation Smoothing", 12f,
Category.CreateEntry("Rotation Smoothing (12f)", 12f,
description: "How much to smooth rotation changes by. Use the slider to adjust the rotation smoothing factor. Range: 0 to 20.");
public static readonly MelonPreferences_Entry<float> EntrySmallMovementThresholdAngle =
Category.CreateEntry("Small Angle Threshold", 6f,
Category.CreateEntry("Small Angle Threshold (6f)", 6f,
description: "Angle difference to consider a 'small' movement. The less shaky your hands are, the lower you probably want to set this. This is probably the primary value you want to tweak. Use the slider to adjust the threshold angle. Range: 4 to 15.");
#endregion Melon Preferences
@ -41,7 +45,9 @@ public class SmoothRay : MelonMod
public override void OnInitializeMelon()
{
Logger = LoggerInstance;
ApplyPatches(typeof(PlayerSetup_Patches));
ApplyPatches(typeof(ControllerRay_Patches));
}
private void ApplyPatches(Type type)
@ -71,6 +77,15 @@ public class SmoothRay : MelonMod
__instance.vrRightHandTracker.gameObject.AddComponent<SmoothRayer>().ray = __instance.vrRayRight;
}
}
internal static class ControllerRay_Patches
{
// SmoothRay
[HarmonyPrefix]
[HarmonyPatch(typeof(ControllerRay), nameof(ControllerRay.SmoothRay))]
private static bool Prefix_ControllerRay_SmoothRay(ref ControllerRay __instance)
=> !EntryEnabled.Value; // SmoothRay method enforces identity local pos when disabled, so we skip it
}
#endregion Harmony Patches
}