From c05213d97055d7d6cd25a81ecaf2934ade21d62a Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Sun, 21 May 2023 23:04:39 -0500 Subject: [PATCH] [SmoothRay] Initial Upload --- NAK_CVR_Mods.sln | 6 ++ SmoothRay/HarmonyPatches.cs | 17 ++++ SmoothRay/Main.cs | 50 +++++++++++ SmoothRay/Properties/AssemblyInfo.cs | 30 +++++++ SmoothRay/README.md | 19 ++++ SmoothRay/SmoothRay.cs | 126 +++++++++++++++++++++++++++ SmoothRay/SmoothRay.csproj | 2 + SmoothRay/format.json | 23 +++++ nstrip_copy_stuff.ps1 | 2 +- 9 files changed, 274 insertions(+), 1 deletion(-) create mode 100644 SmoothRay/HarmonyPatches.cs create mode 100644 SmoothRay/Main.cs create mode 100644 SmoothRay/Properties/AssemblyInfo.cs create mode 100644 SmoothRay/README.md create mode 100644 SmoothRay/SmoothRay.cs create mode 100644 SmoothRay/SmoothRay.csproj create mode 100644 SmoothRay/format.json diff --git a/NAK_CVR_Mods.sln b/NAK_CVR_Mods.sln index cc5c586..5f0a3e6 100644 --- a/NAK_CVR_Mods.sln +++ b/NAK_CVR_Mods.sln @@ -55,6 +55,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CameraFixes", "CameraFixes\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IKAdjustments", "IKAdjustments\IKAdjustments.csproj", "{CCD510BF-1A32-441F-B52B-8A937BF75CE3}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmoothRay", "SmoothRay\SmoothRay.csproj", "{1BBC97C5-CC9F-4DA2-B166-F507F825DFAA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -165,6 +167,10 @@ Global {CCD510BF-1A32-441F-B52B-8A937BF75CE3}.Debug|Any CPU.Build.0 = Debug|Any CPU {CCD510BF-1A32-441F-B52B-8A937BF75CE3}.Release|Any CPU.ActiveCfg = Release|Any CPU {CCD510BF-1A32-441F-B52B-8A937BF75CE3}.Release|Any CPU.Build.0 = Release|Any CPU + {1BBC97C5-CC9F-4DA2-B166-F507F825DFAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1BBC97C5-CC9F-4DA2-B166-F507F825DFAA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1BBC97C5-CC9F-4DA2-B166-F507F825DFAA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1BBC97C5-CC9F-4DA2-B166-F507F825DFAA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SmoothRay/HarmonyPatches.cs b/SmoothRay/HarmonyPatches.cs new file mode 100644 index 0000000..af5847b --- /dev/null +++ b/SmoothRay/HarmonyPatches.cs @@ -0,0 +1,17 @@ +using ABI_RC.Core.Player; +using HarmonyLib; + +namespace NAK.SmoothRay.HarmonyPatches; + +class PlayerSetupPatches +{ + [HarmonyPostfix] + [HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.Start))] + static void Post_PlayerSetup_Start(ref PlayerSetup __instance) + { + var leftSmoother = __instance.vrLeftHandTracker.gameObject.AddComponent(); + leftSmoother.ray = __instance.leftRay; + var rightSmoother = __instance.vrRightHandTracker.gameObject.AddComponent(); + rightSmoother.ray = __instance.rightRay; + } +} \ No newline at end of file diff --git a/SmoothRay/Main.cs b/SmoothRay/Main.cs new file mode 100644 index 0000000..1166bb0 --- /dev/null +++ b/SmoothRay/Main.cs @@ -0,0 +1,50 @@ +using MelonLoader; + +namespace NAK.SmoothRay; + +// ChilloutVR adaptation of: +// https://github.com/kinsi55/BeatSaber_SmoothedController + +public class SmoothRay : MelonMod +{ + public static readonly MelonPreferences_Category Category = + MelonPreferences.CreateCategory(nameof(SmoothRay)); + + public static readonly MelonPreferences_Entry EntryEnabled = + Category.CreateEntry("Enable Smoothing", true, + description: "Enable or disable smoothing."); + + public static readonly MelonPreferences_Entry 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."); + + public static readonly MelonPreferences_Entry EntryPositionSmoothing = + Category.CreateEntry("Position Smoothing", 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 EntryRotationSmoothing = + Category.CreateEntry("Rotation Smoothing", 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 EntrySmallMovementThresholdAngle = + Category.CreateEntry("Small Angle Threshold", 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."); + + public override void OnInitializeMelon() + { + ApplyPatches(typeof(HarmonyPatches.PlayerSetupPatches)); + } + + private void ApplyPatches(Type type) + { + try + { + HarmonyInstance.PatchAll(type); + } + catch (Exception e) + { + LoggerInstance.Msg($"Failed while patching {type.Name}!"); + LoggerInstance.Error(e); + } + } +} \ No newline at end of file diff --git a/SmoothRay/Properties/AssemblyInfo.cs b/SmoothRay/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..ca69d5a --- /dev/null +++ b/SmoothRay/Properties/AssemblyInfo.cs @@ -0,0 +1,30 @@ +using MelonLoader; +using NAK.SmoothRay.Properties; +using System.Reflection; + +[assembly: AssemblyVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyFileVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyTitle(nameof(NAK.SmoothRay))] +[assembly: AssemblyCompany(AssemblyInfoParams.Author)] +[assembly: AssemblyProduct(nameof(NAK.SmoothRay))] + +[assembly: MelonInfo( + typeof(NAK.SmoothRay.SmoothRay), + nameof(NAK.SmoothRay), + AssemblyInfoParams.Version, + AssemblyInfoParams.Author, + downloadLink: "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/SmoothRay" +)] + +[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")] +[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] +[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)] +[assembly: HarmonyDontPatchAll] + +namespace NAK.SmoothRay.Properties; +internal static class AssemblyInfoParams +{ + public const string Version = "1.0.0"; + public const string Author = "NotAKidoS"; +} \ No newline at end of file diff --git a/SmoothRay/README.md b/SmoothRay/README.md new file mode 100644 index 0000000..99dd8df --- /dev/null +++ b/SmoothRay/README.md @@ -0,0 +1,19 @@ +# SmoothRay (Depricated) +lazy af fix for a small issue + +Your Left/Right hand controllers will now track faster and while in the Steam overlay. + +This approach to fixing the issue is made lazy to support DesktopVRSwitch. + +(also because im lazy) + +--- + +Here is the block of text where I tell you this mod is not affiliated or endorsed by ABI. +https://documentation.abinteractive.net/official/legal/tos/#7-modding-our-games + +> This mod is an independent creation and is not affiliated with, supported by or approved by Alpha Blend Interactive. + +> Use of this mod is done so at the user's own risk and the creator cannot be held responsible for any issues arising from its use. + +> To the best of my knowledge, I have adhered to the Modding Guidelines established by Alpha Blend Interactive. diff --git a/SmoothRay/SmoothRay.cs b/SmoothRay/SmoothRay.cs new file mode 100644 index 0000000..f0273b6 --- /dev/null +++ b/SmoothRay/SmoothRay.cs @@ -0,0 +1,126 @@ +using ABI_RC.Core.InteractionSystem; +using UnityEngine; +using UnityEngine.Events; +using Valve.VR; + +namespace NAK.SmoothRay; + +public class SmoothRayer : MonoBehaviour +{ + internal ControllerRay ray; + + //settings + bool isEnabled; + bool menuOnly; + float positionSmoothingValue; + float rotationSmoothingValue; + float smallMovementThresholdAngle; + + //internal + Vector3 smoothedPosition = Vector3.zero; + Quaternion smoothedRotation = Quaternion.identity; + float angleVelocitySnap = 1f; + + //native & trackedcontrollerfix stuff + SteamVR_Behaviour_Pose pose; + SteamVR_TrackedObject tracked; + SteamVR_Events.Action newPosesAction = null; + + void Start() + { + // native CVR + pose = GetComponent(); + if (pose != null) + pose.onTransformUpdatedEvent += OnTransformUpdated; + + // trackedcontrollerfix support + tracked = GetComponent(); + if (tracked != null) + { + newPosesAction = SteamVR_Events.NewPosesAppliedAction(new UnityAction(OnAppliedPoses)); + newPosesAction.enabled = true; + } + + foreach (var setting in SmoothRay.Category.Entries) + { + setting.OnEntryValueChangedUntyped.Subscribe(OnUpdateSettings); + } + + OnUpdateSettings(null, null); + } + + void OnEnable() + { + 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; + } + } + + void OnDisable() + { + 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; + } + + 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); + } + + void OnAppliedPoses() => SmoothTransform(); + void OnTransformUpdated(SteamVR_Behaviour_Pose pose, SteamVR_Input_Sources inputSource) => SmoothTransform(); + + void SmoothTransform() + { + if (isEnabled && ray.lineRenderer != null && ray.lineRenderer.enabled) + { + 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 snapMulti = Mathf.Clamp(angleVelocitySnap / smallMovementThresholdAngle, 0.1f, 2.5f); + + if (angleVelocitySnap > 0.1f) + angleVelocitySnap -= Mathf.Max(0.4f, angleVelocitySnap / 1.7f); + + if (positionSmoothingValue < 20f) + { + smoothedPosition = Vector3.Lerp(smoothedPosition, transform.localPosition, positionSmoothingValue * Time.deltaTime * snapMulti); + transform.localPosition = smoothedPosition; + } + + if (rotationSmoothingValue < 20f) + { + smoothedRotation = Quaternion.Lerp(smoothedRotation, transform.localRotation, rotationSmoothingValue * Time.deltaTime * snapMulti); + transform.localRotation = smoothedRotation; + } + } + else + { + smoothedPosition = transform.localPosition; + smoothedRotation = transform.localRotation; + } + } +} \ No newline at end of file diff --git a/SmoothRay/SmoothRay.csproj b/SmoothRay/SmoothRay.csproj new file mode 100644 index 0000000..66a50a8 --- /dev/null +++ b/SmoothRay/SmoothRay.csproj @@ -0,0 +1,2 @@ + + diff --git a/SmoothRay/format.json b/SmoothRay/format.json new file mode 100644 index 0000000..4178936 --- /dev/null +++ b/SmoothRay/format.json @@ -0,0 +1,23 @@ +{ + "_id": -1, + "name": "SmoothRay", + "modversion": "1.0.0", + "gameversion": "2022r170", + "loaderversion": "0.5.7", + "modtype": "Mod", + "author": "NotAKidoS", + "description": "Allows your controllers to track while the SteamVR overlay is open. This also fixes Quest/Touch controllers feeling slow during fast movements.", + "searchtags": [ + "vr", + "quest", + "controller", + "tracking" + ], + "requirements": [ + "None" + ], + "downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r3/SmoothRay.dll", + "sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/SmoothRay/", + "changelog": "Initial Release", + "embedcolor": "3498db" +} \ No newline at end of file diff --git a/nstrip_copy_stuff.ps1 b/nstrip_copy_stuff.ps1 index 9d8420f..c518612 100644 --- a/nstrip_copy_stuff.ps1 +++ b/nstrip_copy_stuff.ps1 @@ -101,7 +101,7 @@ $HOST.UI.RawUI.Flushinputbuffer() Write-Host "NStrip Convert all private/protected stuff to public. Requires true>" # Create an array to hold the file names to strip -$dllsToStrip = @('Assembly-CSharp.dll','Assembly-CSharp-firstpass.dll','AVProVideo.Runtime.dll','cohtml.Net.dll','Cohtml.RenderingBackend.dll','Cohtml.Runtime.dll') +$dllsToStrip = @('Assembly-CSharp.dll','Assembly-CSharp-firstpass.dll','AVProVideo.Runtime.dll','cohtml.Net.dll','Cohtml.RenderingBackend.dll','Cohtml.Runtime.dll','SteamVR.dll','SteamVR_Actions.dll') # Check if NStrip.exe exists in the current directory if(Test-Path -Path ".\NStrip.exe") {