From b02a312e7dcc6de6814c4d44c35424c2a2952ba7 Mon Sep 17 00:00:00 2001 From: Arne Kiesewetter Date: Wed, 22 Jan 2025 22:57:53 +0100 Subject: [PATCH] Add fix for jumpy sliders and joints on headlesses by @LeCloutPanda Add fix for https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/399 Co-authored-by: LeCloutPanda <53411604+LeCloutPanda@users.noreply.github.com> --- .../CommunityBugFixCollection.csproj | 2 +- CommunityBugFixCollection/Contributors.cs | 2 + .../SmoothSlidersAndJoints.cs | 58 +++++++++++++++++++ README.md | 1 + 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 CommunityBugFixCollection/SmoothSlidersAndJoints.cs diff --git a/CommunityBugFixCollection/CommunityBugFixCollection.csproj b/CommunityBugFixCollection/CommunityBugFixCollection.csproj index 2ce7bc0..ada1f95 100644 --- a/CommunityBugFixCollection/CommunityBugFixCollection.csproj +++ b/CommunityBugFixCollection/CommunityBugFixCollection.csproj @@ -10,7 +10,7 @@ True CommunityBugFixCollection Component Selector Additions - Banane9; Nytra; art0007i + Banane9; Nytra; art0007i; LeCloutPanda 0.7.0-beta This MonkeyLoader mod for Resonite overhauls the Component Selector / Protoflux Node Selector to have a search, as well as favorites and recents categories. README.md diff --git a/CommunityBugFixCollection/Contributors.cs b/CommunityBugFixCollection/Contributors.cs index f4fad1f..97cc215 100644 --- a/CommunityBugFixCollection/Contributors.cs +++ b/CommunityBugFixCollection/Contributors.cs @@ -11,6 +11,8 @@ internal static class Contributors public static string[] Banane9 { get; } = ["Banane9"]; + public static string[] LeCloutPanda { get; } = ["LeCloutPanda"]; + public static string[] Nytra { get; } = ["Nytra"]; } } \ No newline at end of file diff --git a/CommunityBugFixCollection/SmoothSlidersAndJoints.cs b/CommunityBugFixCollection/SmoothSlidersAndJoints.cs new file mode 100644 index 0000000..c30a0f8 --- /dev/null +++ b/CommunityBugFixCollection/SmoothSlidersAndJoints.cs @@ -0,0 +1,58 @@ +using FrooxEngine; +using HarmonyLib; +using MonkeyLoader.Resonite; +using System; +using System.Collections.Generic; +using System.Text; + +// Originally released under MIT by LeCloutPanda here: +// https://github.com/LeCloutPanda/SoNoHeadCrash + +namespace CommunityBugFixCollection +{ + [HarmonyPatch("OnAwake")] + [HarmonyPatchCategory(nameof(SmoothSlidersAndJoints))] + internal sealed class SmoothSlidersAndJoints : ResoniteMonkey + { + public override IEnumerable Authors => base.Authors; + public override bool CanBeDisabled => true; + + [HarmonyPostfix] + [HarmonyPatch(typeof(Joint))] + public static void JointOnAwakePostfix(Joint __instance) + { + if (!Enabled || __instance.LocalUser.HeadDevice != HeadOutputDevice.Headless || !__instance.LocalUser.IsHost) + return; + + __instance.RunInUpdates(3, () => + { + if (__instance.FilterWorldElement() is null) + return; + + __instance.DontDrive.Value = true; + + Logger.Info(() => $"Set DontDrive to true for Joint:"); + Logger.Info(() => __instance.ParentHierarchyToString()); + }); + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(Slider))] + public static void SliderOnAwakePostfix(Slider __instance) + { + if (!Enabled || __instance.LocalUser.HeadDevice != HeadOutputDevice.Headless || !__instance.LocalUser.IsHost) + return; + + __instance.RunInUpdates(3, () => + { + if (__instance.FilterWorldElement() is null) + return; + + __instance.DontDrive.Value = true; + + Logger.Info(() => $"Set DontDrive to true for Slider:"); + Logger.Info(() => __instance.ParentHierarchyToString()); + }); + } + } +} \ No newline at end of file diff --git a/README.md b/README.md index 866642a..b704d13 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ just disable them in the settings in the meantime. * ColorX Luminance calculations being incorrect for non-linear color profiles (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/281) * Non-HDR variants of Color(X) channel addition not clamping (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/316) * Color Profile not being preserved on all operations (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/318) +* Sliders and Joints snapping in sessions hosted by a headless (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/399) * ProtoFlux Node names containing `ColorX` being spaced wrong (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/496) * The selected Home World in the Inventory not being highlighted as a favorite (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/503) * The MaterialGizmo being scaled twice when using Edit on the Material Tool (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/528)