From 39cbdf8ed54d681bd6dce475368b5fdf0c5efb49 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Sat, 23 Sep 2023 18:59:17 -0500 Subject: [PATCH] [SmoothRay] Fixes for 2023r172. --- SmoothRay/Properties/AssemblyInfo.cs | 2 +- SmoothRay/SmoothRay.cs | 47 +++++++++++++++++----------- SmoothRay/format.json | 8 ++--- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/SmoothRay/Properties/AssemblyInfo.cs b/SmoothRay/Properties/AssemblyInfo.cs index a4f4227..5716c3e 100644 --- a/SmoothRay/Properties/AssemblyInfo.cs +++ b/SmoothRay/Properties/AssemblyInfo.cs @@ -28,6 +28,6 @@ namespace NAK.SmoothRay.Properties; internal static class AssemblyInfoParams { - public const string Version = "1.0.2"; + public const string Version = "1.0.3"; public const string Author = "NotAKidoS"; } \ No newline at end of file diff --git a/SmoothRay/SmoothRay.cs b/SmoothRay/SmoothRay.cs index 4bd2b4d..5d7eb56 100644 --- a/SmoothRay/SmoothRay.cs +++ b/SmoothRay/SmoothRay.cs @@ -26,7 +26,6 @@ using ABI_RC.Core.InteractionSystem; using ABI_RC.Core.Savior; using MelonLoader; using UnityEngine; -using UnityEngine.Events; using Valve.VR; namespace NAK.SmoothRay; @@ -67,7 +66,7 @@ public class SmoothRayer : MonoBehaviour // TrackedControllerFix support - OpenVR if (TryGetComponent(out _trackedObject)) { - _newPosesAction = SteamVR_Events.NewPosesAppliedAction(new UnityAction(OnAppliedPoses)); + _newPosesAction = SteamVR_Events.NewPosesAppliedAction(OnAppliedPoses); UpdatePosesAction(true); } @@ -79,8 +78,9 @@ public class SmoothRayer : MonoBehaviour private void OnEnable() { - _smoothedPosition = transform.localPosition; - _smoothedRotation = transform.localRotation; + Transform controller = transform; + _smoothedPosition = controller.localPosition; + _smoothedRotation = controller.localRotation; // desktopvrswitch support, start handles this for normal use UpdateTransformUpdatedEvent(true); @@ -89,8 +89,9 @@ public class SmoothRayer : MonoBehaviour private void OnDisable() { - _smoothedPosition = transform.localPosition; - _smoothedRotation = transform.localRotation; + Transform controller = transform; + _smoothedPosition = controller.localPosition; + _smoothedRotation = controller.localRotation; // desktopvrswitch support, normal use wont run this UpdateTransformUpdatedEvent(false); @@ -115,7 +116,7 @@ public class SmoothRayer : MonoBehaviour if (enable && CheckVR.Instance.forceOpenXr) return; - if (_behaviourPose == null) + if (_behaviourPose == null) return; if (enable) @@ -134,20 +135,26 @@ public class SmoothRayer : MonoBehaviour _rotationSmoothingValue = Math.Max(20f - Mathf.Clamp(SmoothRay.EntryRotationSmoothing.Value, 0f, 20f), 0.1f); } - private void OnAppliedPoses() => SmoothTransform(); + private void OnAppliedPoses() + { + SmoothTransform(); + } - private void OnTransformUpdated(SteamVR_Behaviour_Pose pose, SteamVR_Input_Sources inputSource) => SmoothTransform(); + private void OnTransformUpdated(SteamVR_Behaviour_Pose pose, SteamVR_Input_Sources inputSource) + { + SmoothTransform(); + } private void SmoothTransform() { + Transform controller = transform; 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); + var angDiff = Quaternion.Angle(_smoothedRotation, controller.localRotation); _angleVelocitySnap = Mathf.Min(_angleVelocitySnap + angDiff, 90f); var snapMulti = Mathf.Clamp(_angleVelocitySnap / _smallMovementThresholdAngle, 0.1f, 2.5f); @@ -157,20 +164,22 @@ public class SmoothRayer : MonoBehaviour if (_positionSmoothingValue < 20f) { - _smoothedPosition = Vector3.Lerp(_smoothedPosition, transform.localPosition, _positionSmoothingValue * Time.deltaTime * snapMulti); - transform.localPosition = _smoothedPosition; + _smoothedPosition = Vector3.Lerp(_smoothedPosition, controller.localPosition, + _positionSmoothingValue * Time.deltaTime * snapMulti); + controller.localPosition = _smoothedPosition; } if (_rotationSmoothingValue < 20f) { - _smoothedRotation = Quaternion.Lerp(_smoothedRotation, transform.localRotation, _rotationSmoothingValue * Time.deltaTime * snapMulti); - transform.localRotation = _smoothedRotation; + _smoothedRotation = Quaternion.Lerp(_smoothedRotation, controller.localRotation, + _rotationSmoothingValue * Time.deltaTime * snapMulti); + controller.localRotation = _smoothedRotation; } } else { - _smoothedPosition = transform.localPosition; - _smoothedRotation = transform.localRotation; + _smoothedPosition = controller.localPosition; + _smoothedRotation = controller.localRotation; } } diff --git a/SmoothRay/format.json b/SmoothRay/format.json index 1168caf..8a70277 100644 --- a/SmoothRay/format.json +++ b/SmoothRay/format.json @@ -1,8 +1,8 @@ { "_id": 162, "name": "SmoothRay", - "modversion": "1.0.2", - "gameversion": "2023r171", + "modversion": "1.0.3", + "gameversion": "2023r172", "loaderversion": "0.6.1", "modtype": "Mod", "author": "NotAKidoS", @@ -16,8 +16,8 @@ "requirements": [ "None" ], - "downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r16/SmoothRay.dll", + "downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r21/SmoothRay.dll", "sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/SmoothRay/", - "changelog": "- Fixes for 2023r171.\n- Prevented from initializing when launching with OpenXR.", + "changelog": "- Fixes for 2023r172. Literally just recompiled.", "embedcolor": "#dc8105" } \ No newline at end of file