mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 14:29:25 +00:00
[SmoothRay] Fixes for 2023r171
This commit is contained in:
parent
a44354502f
commit
d67c45023f
5 changed files with 110 additions and 77 deletions
|
@ -3,11 +3,11 @@ using HarmonyLib;
|
|||
|
||||
namespace NAK.SmoothRay.HarmonyPatches;
|
||||
|
||||
class PlayerSetupPatches
|
||||
internal class PlayerSetupPatches
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.Start))]
|
||||
static void Post_PlayerSetup_Start(ref PlayerSetup __instance)
|
||||
private static void Post_PlayerSetup_Start(ref PlayerSetup __instance)
|
||||
{
|
||||
__instance.vrLeftHandTracker.gameObject.AddComponent<SmoothRayer>().ray = __instance.leftRay;
|
||||
__instance.vrRightHandTracker.gameObject.AddComponent<SmoothRayer>().ray = __instance.rightRay;
|
||||
|
|
|
@ -36,7 +36,7 @@ public class SmoothRay : MelonMod
|
|||
ApplyPatches(typeof(HarmonyPatches.PlayerSetupPatches));
|
||||
}
|
||||
|
||||
void ApplyPatches(Type type)
|
||||
private void ApplyPatches(Type type)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
@ -20,11 +20,14 @@ using System.Reflection;
|
|||
[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")]
|
||||
[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
|
||||
[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
|
||||
[assembly: MelonColor(255, 220, 130, 5)]
|
||||
[assembly: MelonAuthorColor(255, 158, 21, 32)]
|
||||
[assembly: HarmonyDontPatchAll]
|
||||
|
||||
namespace NAK.SmoothRay.Properties;
|
||||
|
||||
internal static class AssemblyInfoParams
|
||||
{
|
||||
public const string Version = "1.0.1";
|
||||
public const string Version = "1.0.2";
|
||||
public const string Author = "NotAKidoS";
|
||||
}
|
|
@ -23,6 +23,8 @@
|
|||
**/
|
||||
|
||||
using ABI_RC.Core.InteractionSystem;
|
||||
using ABI_RC.Core.Savior;
|
||||
using MelonLoader;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using Valve.VR;
|
||||
|
@ -31,118 +33,146 @@ namespace NAK.SmoothRay;
|
|||
|
||||
public class SmoothRayer : MonoBehaviour
|
||||
{
|
||||
#region Variables
|
||||
|
||||
public ControllerRay ray;
|
||||
|
||||
//settings
|
||||
bool isEnabled;
|
||||
bool menuOnly;
|
||||
float positionSmoothingValue;
|
||||
float rotationSmoothingValue;
|
||||
float smallMovementThresholdAngle;
|
||||
private bool _isEnabled;
|
||||
private bool _menuOnly;
|
||||
private float _positionSmoothingValue;
|
||||
private float _rotationSmoothingValue;
|
||||
private float _smallMovementThresholdAngle;
|
||||
|
||||
//internal
|
||||
Vector3 smoothedPosition = Vector3.zero;
|
||||
Quaternion smoothedRotation = Quaternion.identity;
|
||||
float angleVelocitySnap = 1f;
|
||||
private Vector3 _smoothedPosition = Vector3.zero;
|
||||
private Quaternion _smoothedRotation = Quaternion.identity;
|
||||
private float _angleVelocitySnap = 1f;
|
||||
|
||||
//native & trackedcontrollerfix stuff
|
||||
SteamVR_Behaviour_Pose pose;
|
||||
SteamVR_TrackedObject tracked;
|
||||
SteamVR_Events.Action newPosesAction = null;
|
||||
|
||||
void Start()
|
||||
private SteamVR_Behaviour_Pose _behaviourPose;
|
||||
private SteamVR_TrackedObject _trackedObject;
|
||||
private SteamVR_Events.Action _newPosesAction;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Unity Methods
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// native CVR
|
||||
pose = GetComponent<SteamVR_Behaviour_Pose>();
|
||||
if (pose != null)
|
||||
pose.onTransformUpdatedEvent += OnTransformUpdated;
|
||||
// Native ChilloutVR - OpenVR
|
||||
if (TryGetComponent(out _behaviourPose))
|
||||
UpdateTransformUpdatedEvent(true);
|
||||
|
||||
// trackedcontrollerfix support
|
||||
tracked = GetComponent<SteamVR_TrackedObject>();
|
||||
if (tracked != null)
|
||||
// TrackedControllerFix support - OpenVR
|
||||
if (TryGetComponent(out _trackedObject))
|
||||
{
|
||||
newPosesAction = SteamVR_Events.NewPosesAppliedAction(new UnityAction(OnAppliedPoses));
|
||||
newPosesAction.enabled = true;
|
||||
_newPosesAction = SteamVR_Events.NewPosesAppliedAction(new UnityAction(OnAppliedPoses));
|
||||
UpdatePosesAction(true);
|
||||
}
|
||||
|
||||
foreach (var setting in SmoothRay.Category.Entries)
|
||||
{
|
||||
foreach (MelonPreferences_Entry setting in SmoothRay.Category.Entries)
|
||||
setting.OnEntryValueChangedUntyped.Subscribe(OnUpdateSettings);
|
||||
}
|
||||
|
||||
OnUpdateSettings(null, null);
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
smoothedPosition = transform.localPosition;
|
||||
smoothedRotation = transform.localRotation;
|
||||
_smoothedPosition = transform.localPosition;
|
||||
_smoothedRotation = transform.localRotation;
|
||||
|
||||
// desktopvrswitch support, start handles this for normal use
|
||||
if (pose != null)
|
||||
pose.onTransformUpdatedEvent += OnTransformUpdated;
|
||||
if (tracked != null && newPosesAction != null)
|
||||
newPosesAction.enabled = true;
|
||||
UpdateTransformUpdatedEvent(true);
|
||||
UpdatePosesAction(true);
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
private void OnDisable()
|
||||
{
|
||||
smoothedPosition = transform.localPosition;
|
||||
smoothedRotation = transform.localRotation;
|
||||
|
||||
_smoothedPosition = transform.localPosition;
|
||||
_smoothedRotation = transform.localRotation;
|
||||
|
||||
// desktopvrswitch support, normal use wont run this
|
||||
if (pose != null)
|
||||
pose.onTransformUpdatedEvent -= OnTransformUpdated;
|
||||
if (tracked != null && newPosesAction != null)
|
||||
newPosesAction.enabled = false;
|
||||
UpdateTransformUpdatedEvent(false);
|
||||
UpdatePosesAction(false);
|
||||
}
|
||||
|
||||
void OnUpdateSettings(object arg1, object arg2)
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private void UpdatePosesAction(bool enable)
|
||||
{
|
||||
isEnabled = SmoothRay.EntryEnabled.Value;
|
||||
menuOnly = SmoothRay.EntryMenuOnly.Value;
|
||||
smallMovementThresholdAngle = SmoothRay.EntrySmallMovementThresholdAngle.Value;
|
||||
if (enable && CheckVR.Instance.forceOpenXr)
|
||||
return;
|
||||
|
||||
if (_trackedObject != null && _newPosesAction != null)
|
||||
_newPosesAction.enabled = enable;
|
||||
}
|
||||
|
||||
private void UpdateTransformUpdatedEvent(bool enable)
|
||||
{
|
||||
if (enable && CheckVR.Instance.forceOpenXr)
|
||||
return;
|
||||
|
||||
if (_behaviourPose == null)
|
||||
return;
|
||||
|
||||
if (enable)
|
||||
_behaviourPose.onTransformUpdatedEvent += OnTransformUpdated;
|
||||
else
|
||||
_behaviourPose.onTransformUpdatedEvent -= OnTransformUpdated;
|
||||
}
|
||||
|
||||
private void OnUpdateSettings(object arg1, object arg2)
|
||||
{
|
||||
_isEnabled = SmoothRay.EntryEnabled.Value;
|
||||
_menuOnly = SmoothRay.EntryMenuOnly.Value;
|
||||
_smallMovementThresholdAngle = SmoothRay.EntrySmallMovementThresholdAngle.Value;
|
||||
// dont let value hit 0, itll freeze controllers
|
||||
positionSmoothingValue = Math.Max(20f - Mathf.Clamp(SmoothRay.EntryPositionSmoothing.Value, 0f, 20f), 0.1f);
|
||||
rotationSmoothingValue = Math.Max(20f - Mathf.Clamp(SmoothRay.EntryRotationSmoothing.Value, 0f, 20f), 0.1f);
|
||||
_positionSmoothingValue = Math.Max(20f - Mathf.Clamp(SmoothRay.EntryPositionSmoothing.Value, 0f, 20f), 0.1f);
|
||||
_rotationSmoothingValue = Math.Max(20f - Mathf.Clamp(SmoothRay.EntryRotationSmoothing.Value, 0f, 20f), 0.1f);
|
||||
}
|
||||
|
||||
void OnAppliedPoses() => SmoothTransform();
|
||||
void OnTransformUpdated(SteamVR_Behaviour_Pose pose, SteamVR_Input_Sources inputSource) => SmoothTransform();
|
||||
|
||||
void SmoothTransform()
|
||||
private void OnAppliedPoses() => SmoothTransform();
|
||||
|
||||
private void OnTransformUpdated(SteamVR_Behaviour_Pose pose, SteamVR_Input_Sources inputSource) => SmoothTransform();
|
||||
|
||||
private void SmoothTransform()
|
||||
{
|
||||
if (isEnabled && ray.lineRenderer != null && ray.lineRenderer.enabled)
|
||||
if (_isEnabled && ray.lineRenderer != null && ray.lineRenderer.enabled)
|
||||
{
|
||||
if (menuOnly && (!ray.uiActive || (ray.hitTransform != ViewManager.Instance.transform && ray.hitTransform != CVR_MenuManager.Instance.quickMenu.transform)))
|
||||
if (_menuOnly && (!ray.uiActive || (ray.hitTransform != ViewManager.Instance.transform && ray.hitTransform != CVR_MenuManager.Instance.quickMenu.transform)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var angDiff = Quaternion.Angle(smoothedRotation, transform.localRotation);
|
||||
angleVelocitySnap = Mathf.Min(angleVelocitySnap + angDiff, 90f);
|
||||
var angDiff = Quaternion.Angle(_smoothedRotation, transform.localRotation);
|
||||
_angleVelocitySnap = Mathf.Min(_angleVelocitySnap + angDiff, 90f);
|
||||
|
||||
var snapMulti = Mathf.Clamp(angleVelocitySnap / smallMovementThresholdAngle, 0.1f, 2.5f);
|
||||
var snapMulti = Mathf.Clamp(_angleVelocitySnap / _smallMovementThresholdAngle, 0.1f, 2.5f);
|
||||
|
||||
if (angleVelocitySnap > 0.1f)
|
||||
angleVelocitySnap -= Mathf.Max(0.4f, angleVelocitySnap / 1.7f);
|
||||
if (_angleVelocitySnap > 0.1f)
|
||||
_angleVelocitySnap -= Mathf.Max(0.4f, _angleVelocitySnap / 1.7f);
|
||||
|
||||
if (positionSmoothingValue < 20f)
|
||||
if (_positionSmoothingValue < 20f)
|
||||
{
|
||||
smoothedPosition = Vector3.Lerp(smoothedPosition, transform.localPosition, positionSmoothingValue * Time.deltaTime * snapMulti);
|
||||
transform.localPosition = smoothedPosition;
|
||||
_smoothedPosition = Vector3.Lerp(_smoothedPosition, transform.localPosition, _positionSmoothingValue * Time.deltaTime * snapMulti);
|
||||
transform.localPosition = _smoothedPosition;
|
||||
}
|
||||
|
||||
if (rotationSmoothingValue < 20f)
|
||||
if (_rotationSmoothingValue < 20f)
|
||||
{
|
||||
smoothedRotation = Quaternion.Lerp(smoothedRotation, transform.localRotation, rotationSmoothingValue * Time.deltaTime * snapMulti);
|
||||
transform.localRotation = smoothedRotation;
|
||||
_smoothedRotation = Quaternion.Lerp(_smoothedRotation, transform.localRotation, _rotationSmoothingValue * Time.deltaTime * snapMulti);
|
||||
transform.localRotation = _smoothedRotation;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
smoothedPosition = transform.localPosition;
|
||||
smoothedRotation = transform.localRotation;
|
||||
_smoothedPosition = transform.localPosition;
|
||||
_smoothedRotation = transform.localRotation;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"_id": -1,
|
||||
"_id": 162,
|
||||
"name": "SmoothRay",
|
||||
"modversion": "1.0.1",
|
||||
"gameversion": "2022r170p1",
|
||||
"modversion": "1.0.2",
|
||||
"gameversion": "2023r171",
|
||||
"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\nSupport for TrackedControllerFix & DesktopVRSwitch.",
|
||||
"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\nSupport for TrackedControllerFix & DesktopVRSwitch.\n**Only supports OpenVR, not OpenXR.**",
|
||||
"searchtags": [
|
||||
"vr",
|
||||
"ray",
|
||||
|
@ -16,8 +16,8 @@
|
|||
"requirements": [
|
||||
"None"
|
||||
],
|
||||
"downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r9/SmoothRay.dll",
|
||||
"downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r16/SmoothRay.dll",
|
||||
"sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/SmoothRay/",
|
||||
"changelog": "Initial CVRMG Release",
|
||||
"embedcolor": "dc8105"
|
||||
"changelog": "- Fixes for 2023r171.\n- Prevented from initializing when launching with OpenXR.",
|
||||
"embedcolor": "#dc8105"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue