[SmoothRay] Initial Upload

This commit is contained in:
NotAKidoS 2023-05-21 23:04:39 -05:00
parent b5df421bec
commit c05213d970
9 changed files with 274 additions and 1 deletions

View file

@ -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

View file

@ -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<SmoothRayer>();
leftSmoother.ray = __instance.leftRay;
var rightSmoother = __instance.vrRightHandTracker.gameObject.AddComponent<SmoothRayer>();
rightSmoother.ray = __instance.rightRay;
}
}

50
SmoothRay/Main.cs Normal file
View file

@ -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<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.");
public static readonly MelonPreferences_Entry<float> 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<float> 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<float> 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);
}
}
}

View file

@ -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";
}

19
SmoothRay/README.md Normal file
View file

@ -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.

126
SmoothRay/SmoothRay.cs Normal file
View file

@ -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<SteamVR_Behaviour_Pose>();
if (pose != null)
pose.onTransformUpdatedEvent += OnTransformUpdated;
// trackedcontrollerfix support
tracked = GetComponent<SteamVR_TrackedObject>();
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;
}
}
}

View file

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk"/>

23
SmoothRay/format.json Normal file
View file

@ -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"
}

View file

@ -101,7 +101,7 @@ $HOST.UI.RawUI.Flushinputbuffer()
Write-Host "NStrip Convert all private/protected stuff to public. Requires <AllowUnsafeBlocks>true></AllowUnsafeBlocks>"
# 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") {