mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 06:19:22 +00:00
SmoothRay: cleanup
This commit is contained in:
parent
35943bd709
commit
59cec7e7d3
4 changed files with 93 additions and 31 deletions
|
@ -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
|
||||
}
|
|
@ -10,7 +10,7 @@ using System.Reflection;
|
|||
[assembly: AssemblyProduct(nameof(NAK.SmoothRay))]
|
||||
|
||||
[assembly: MelonInfo(
|
||||
typeof(NAK.SmoothRay.SmoothRay),
|
||||
typeof(NAK.SmoothRay.SmoothRayMod),
|
||||
nameof(NAK.SmoothRay),
|
||||
AssemblyInfoParams.Version,
|
||||
AssemblyInfoParams.Author,
|
||||
|
@ -28,6 +28,6 @@ namespace NAK.SmoothRay.Properties;
|
|||
|
||||
internal static class AssemblyInfoParams
|
||||
{
|
||||
public const string Version = "1.0.4";
|
||||
public const string Version = "1.0.5";
|
||||
public const string Author = "NotAKidoS";
|
||||
}
|
|
@ -22,8 +22,10 @@
|
|||
SOFTWARE.
|
||||
**/
|
||||
|
||||
using ABI_RC.Core;
|
||||
using ABI_RC.Core.InteractionSystem;
|
||||
using ABI_RC.Core.Savior;
|
||||
using ABI_RC.Systems.InputManagement;
|
||||
using MelonLoader;
|
||||
using UnityEngine;
|
||||
using Valve.VR;
|
||||
|
@ -70,8 +72,10 @@ public class SmoothRayer : MonoBehaviour
|
|||
UpdatePosesAction(true);
|
||||
}
|
||||
|
||||
foreach (MelonPreferences_Entry setting in SmoothRay.Category.Entries)
|
||||
foreach (MelonPreferences_Entry setting in SmoothRayMod.Category.Entries)
|
||||
setting.OnEntryValueChangedUntyped.Subscribe(OnUpdateSettings);
|
||||
|
||||
MetaPort.Instance.settings.settingBoolChanged.AddListener(OnSettingsBoolChanged);
|
||||
|
||||
OnUpdateSettings(null, null);
|
||||
}
|
||||
|
@ -127,12 +131,41 @@ public class SmoothRayer : MonoBehaviour
|
|||
|
||||
private void OnUpdateSettings(object arg1, object arg2)
|
||||
{
|
||||
_isEnabled = SmoothRay.EntryEnabled.Value;
|
||||
_menuOnly = SmoothRay.EntryMenuOnly.Value;
|
||||
_smallMovementThresholdAngle = SmoothRay.EntrySmallMovementThresholdAngle.Value;
|
||||
_isEnabled = SmoothRayMod.EntryEnabled.Value;
|
||||
_menuOnly = SmoothRayMod.EntryMenuOnly.Value;
|
||||
_smallMovementThresholdAngle = SmoothRayMod.EntrySmallMovementThresholdAngle.Value;
|
||||
|
||||
// dont let value hit 0, itll freeze controllers
|
||||
_positionSmoothingValue = Mathf.Max(20f - Mathf.Clamp(SmoothRay.EntryPositionSmoothing.Value, 0f, 20f), 0.1f);
|
||||
_rotationSmoothingValue = Mathf.Max(20f - Mathf.Clamp(SmoothRay.EntryRotationSmoothing.Value, 0f, 20f), 0.1f);
|
||||
_positionSmoothingValue = Mathf.Max(20f - Mathf.Clamp(SmoothRayMod.EntryPositionSmoothing.Value, 0f, 20f), 0.1f);
|
||||
_rotationSmoothingValue = Mathf.Max(20f - Mathf.Clamp(SmoothRayMod.EntryRotationSmoothing.Value, 0f, 20f), 0.1f);
|
||||
|
||||
if (!_isEnabled)
|
||||
return; // only care about setting being enabled
|
||||
|
||||
ray._enableSmoothRay = false; // ensure built-in smoothing is disabled
|
||||
|
||||
if (MetaPort.Instance.settings.GetSettingsBool("ControlSmoothRaycast"))
|
||||
return; // disable saved setting once
|
||||
|
||||
SmoothRayMod.Logger.Msg("Built-in SmoothRay setting found to be enabled. Disabling built-in SmoothRay implementation in favor of modded implementation.");
|
||||
MetaPort.Instance.settings.SetSettingsBool("ControlSmoothRaycast", false);
|
||||
ViewManager.SetGameSettingBool("ControlSmoothRaycast", false);
|
||||
// ^ did you know the game doesn't even use this method native...
|
||||
}
|
||||
|
||||
private void OnSettingsBoolChanged(string key, bool value)
|
||||
{
|
||||
if (key != "ControlSmoothRaycast")
|
||||
return; // only care about SmoothRaycast setting
|
||||
|
||||
if (!value)
|
||||
return; // only care about setting being enabled
|
||||
|
||||
_isEnabled = false; // ensure modded SmoothRay is disabled
|
||||
|
||||
if (!SmoothRayMod.EntryEnabled.Value) return; // disable saved setting once
|
||||
SmoothRayMod.Logger.Msg("Modded SmoothRay found to be enabled. Disabling modded SmoothRay implementation in favor of built-in implementation.");
|
||||
SmoothRayMod.EntryEnabled.Value = false;
|
||||
}
|
||||
|
||||
private void OnAppliedPoses()
|
||||
|
@ -148,12 +181,13 @@ public class SmoothRayer : MonoBehaviour
|
|||
private void SmoothTransform()
|
||||
{
|
||||
Transform controller = transform;
|
||||
if (_isEnabled && ray.lineRenderer != null && ray.lineRenderer.enabled)
|
||||
if (!CanSmoothRay())
|
||||
{
|
||||
_smoothedPosition = controller.localPosition;
|
||||
_smoothedRotation = controller.localRotation;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_menuOnly && (!ray.uiActive || (ray.hitTransform != ViewManager.Instance.transform &&
|
||||
ray.hitTransform != CVR_MenuManager.Instance.quickMenu.transform)))
|
||||
return;
|
||||
|
||||
var angDiff = Quaternion.Angle(_smoothedRotation, controller.localRotation);
|
||||
_angleVelocitySnap = Mathf.Min(_angleVelocitySnap + angDiff, 90f);
|
||||
|
||||
|
@ -176,12 +210,25 @@ public class SmoothRayer : MonoBehaviour
|
|||
controller.localRotation = _smoothedRotation;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_smoothedPosition = controller.localPosition;
|
||||
_smoothedRotation = controller.localRotation;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
private bool CanSmoothRay()
|
||||
{
|
||||
bool canSmoothRay = _isEnabled && ray.lineRenderer != null && ray.lineRenderer.enabled;
|
||||
|
||||
if (_menuOnly)
|
||||
{
|
||||
switch (ray.hand)
|
||||
{
|
||||
case CVRHand.Left when !CVRInputManager.Instance.leftControllerPointingMenu:
|
||||
case CVRHand.Right when !CVRInputManager.Instance.rightControllerPointingMenu:
|
||||
canSmoothRay = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return canSmoothRay;
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"_id": 162,
|
||||
"name": "SmoothRay",
|
||||
"modversion": "1.0.4",
|
||||
"modversion": "1.0.5",
|
||||
"gameversion": "2024r176",
|
||||
"loaderversion": "0.6.1",
|
||||
"modtype": "Mod",
|
||||
"author": "NotAKidoS",
|
||||
"description": "Smoothes your controller while using the Quick and Main menus to make it easier to navigate.\nThis is a CVR adaptation of a Beat Saber mod: [BeatSaber_SmoothedController](https://github.com/kinsi55/BeatSaber_SmoothedController)\n\n**Only supports OpenVR, not OpenXR.**",
|
||||
"description": "Smoothes your controller while using the Quick and Main menus to make it easier to navigate.\nThis is a CVR adaptation of a Beat Saber mod: [BeatSaber_SmoothedController](https://github.com/kinsi55/BeatSaber_SmoothedController)\n\n**Only supports OpenVR, not OpenXR.\n\n **NOTE:** This disables the built-in Smooth Ray setting when the mod is enabled. Compare both & you'll see why.",
|
||||
"searchtags": [
|
||||
"vr",
|
||||
"ray",
|
||||
|
@ -16,7 +16,7 @@
|
|||
"requirements": [
|
||||
"None"
|
||||
],
|
||||
"downloadlink": "https://github.com/NotAKidoS/NAK_CVR_Mods/releases/download/r21/SmoothRay.dll",
|
||||
"downloadlink": "https://github.com/NotAKidoS/NAK_CVR_Mods/releases/download/r40/SmoothRay.dll",
|
||||
"sourcelink": "https://github.com/NotAKidoS/NAK_CVR_Mods/tree/main/SmoothRay/",
|
||||
"changelog": "- Fixed for 2024r176.",
|
||||
"embedcolor": "#f61963"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue