diff --git a/CommunityBugFixCollection/CommunityBugFixCollection.csproj b/CommunityBugFixCollection/CommunityBugFixCollection.csproj index d152007..8659121 100644 --- a/CommunityBugFixCollection/CommunityBugFixCollection.csproj +++ b/CommunityBugFixCollection/CommunityBugFixCollection.csproj @@ -10,7 +10,7 @@ True CommunityBugFixCollection Community Bug-Fix Collection - Banane9; Nytra; art0007i; LeCloutPanda + Banane9; Nytra; art0007i; LeCloutPanda; goat; __Choco__ 0.3.0-beta This MonkeyLoader mod for Resonite that fixes various small Resonite-issues that are still open. README.md diff --git a/CommunityBugFixCollection/Locale/de.json b/CommunityBugFixCollection/Locale/de.json index 52f3093..d24244b 100644 --- a/CommunityBugFixCollection/Locale/de.json +++ b/CommunityBugFixCollection/Locale/de.json @@ -32,6 +32,7 @@ "CommunityBugFixCollection.NonHDRColorClamping.Description": "Korrigiert, dass die nicht-HDR Varianten der Color(X) Kanal-Additionen die Werte nicht limitieren.", "CommunityBugFixCollection.PauseAnimatorUpdates.Description": "Verhindert, dass Animatoren jeden Frame in alle assoziierten Felder schreiben, obwohl sie nicht am animieren sind.", "CommunityBugFixCollection.SmoothDraggables.Description": "Umgeht, dass Slider und Joints in Headless-Sessions verrutschen.", + "CommunityBugFixCollection.TiltedUIAlignment.Description": "Kippt die UI-fokussierte Kamera, um UIX-Renderprobleme zum umgehen.", "CommunityBugFixCollection.StationaryGrabWorldActivation.Description": "Verhindert, dass die Welt-Greifen Fortbewegung den Spieler bei jeder Aktivierung bewegt.", "CommunityBugFixCollection.UserInspectorAsNonHost.Description": "Sorgt dafür, dass Benutzer-Inspektoren bereits präsente Benutzer auch in Sessions anzeigen, in denen man nicht der Host ist." } diff --git a/CommunityBugFixCollection/Locale/en.json b/CommunityBugFixCollection/Locale/en.json index 499718e..b71f869 100644 --- a/CommunityBugFixCollection/Locale/en.json +++ b/CommunityBugFixCollection/Locale/en.json @@ -33,7 +33,8 @@ "CommunityBugFixCollection.PauseAnimatorUpdates.Description": "Fixes animators updating all associated fields every frame while enabled but not playing.", "CommunityBugFixCollection.SmoothDraggables.Description": "Workaround for Sliders and Joints snapping in sessions hosted by a headless.", "CommunityBugFixCollection.StationaryGrabWorldActivation.Description": "Stops the Grab World Locomotion from moving the player with each activiation.", + "CommunityBugFixCollection.TiltedUIAlignment.Description": "Tilts the UI-Focus camera to work around UIX rendering issues.", "CommunityBugFixCollection.UserInspectorAsNonHost.Description": "Fixes UserInspectors not listing existing users in the session for non-host users.", "CommunityBugFixCollection.ValueModDecimal.Description": "Adds a zero check to the Decimal ValueMod ProtoFlux node to prevent DIV/0 crashes" } -} +} \ No newline at end of file diff --git a/CommunityBugFixCollection/TiltedUIAlignment.cs b/CommunityBugFixCollection/TiltedUIAlignment.cs new file mode 100644 index 0000000..3d34bfe --- /dev/null +++ b/CommunityBugFixCollection/TiltedUIAlignment.cs @@ -0,0 +1,93 @@ +using Elements.Core; +using FrooxEngine; +using HarmonyLib; +using MonkeyLoader; +using MonkeyLoader.Components; +using MonkeyLoader.Configuration; +using MonkeyLoader.Resonite; +using MonoMod.Utils; +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Text; + +namespace CommunityBugFixCollection +{ + [HarmonyPatchCategory(nameof(TiltedUIAlignment))] + [HarmonyPatch(typeof(UI_TargettingController), nameof(UI_TargettingController.OnBeforeHeadUpdate))] + internal sealed class TiltedUIAlignment : ResoniteMonkey + { + public override IEnumerable Authors => Contributors.Banane9; + + public override bool CanBeDisabled => true; + + protected override bool OnEngineReady() + { + var wasSetFromDefault = false; + + void SetFromDefaultHandler(object sender, ConfigKeyChangedEventArgs eventArgs) + => wasSetFromDefault = eventArgs.Label == ConfigKey.SetFromDefaultEventLabel; + + EnabledToggle!.Changed += SetFromDefaultHandler; + EnabledToggle.GetValue(); + EnabledToggle.Changed -= SetFromDefaultHandler; + + if (wasSetFromDefault) + { + Logger.Info(() => "Enabled was set from default, applying GPU detection!"); + + var unitySystemInfoType = AccessTools.TypeByName("UnityEngine.SystemInfo, UnityEngine.CoreModule"); + Logger.Info(() => $"Unity SystemInfo type is: {(unitySystemInfoType is null ? "null" : unitySystemInfoType.CompactDescription())}"); + + var getGraphicsDeviceName = unitySystemInfoType is null ? null : AccessTools.DeclaredPropertyGetter(unitySystemInfoType, "graphicsDeviceName"); + + if (getGraphicsDeviceName is null) + { + Logger.Warn(() => "Did not find UnityEngine.SystemInfo to check GPU name - disabling tilt!"); + + EnabledToggle!.SetValue(false, "GPU-Detection.Fail"); + } + else + { + Logger.Debug(() => "Using UnityEngine.SystemInfo to check GPU name!"); + + var gpu = (string?)getGraphicsDeviceName?.Invoke(null, null); + var isAmd = gpu?.Contains("AMD", StringComparison.OrdinalIgnoreCase) ?? false; + var isIntel = gpu?.Contains("Intel", StringComparison.OrdinalIgnoreCase) ?? false; + var enableTilt = isAmd || isIntel; + + Logger.Info(() => $"Detected GPU [{gpu}] - {(enableTilt ? "enabled" : "disabled")} tilt!"); + + EnabledToggle!.SetValue(enableTilt, "GPU-Detection.Success"); + } + } + else + { + Logger.Info(() => "Enabled wasn't set from default, not applying GPU detection!"); + } + + return base.OnEngineReady(); + } + + private static void Postfix(UI_TargettingController __instance) + { + if (!Enabled) + return; + + var space = __instance.ViewSpace ?? __instance.Slot; + var spacePosition = space.GlobalPosition; + var rootDistance = MathX.Max(1, MathX.MaxComponent(MathX.Abs(spacePosition))); + + var rotationAxis = float3.Right; + var angle = MathX.Clamp(0.1f, 5, 0.01f * MathX.Sqrt(rootDistance)); + + // Add angle to camera to prevent flickering + var rotation = floatQ.AxisAngle(rotationAxis, angle); + __instance.ViewRotation *= rotation; + + // Adjust position based on angle to frame UI properly still + var antiRotation = floatQ.AxisAngle(rotationAxis, angle + 2); + __instance.ViewPosition = __instance._currentCenter + (antiRotation * __instance._currentPlane * __instance._currentDistance); + } + } +} \ No newline at end of file diff --git a/README.md b/README.md index 6444295..8b02105 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ just disable them in the settings in the meantime. * Sliders and Joints snapping in sessions hosted by a headless (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/399) * Missing Cloud Home template for Groups (fallback to User Cloud Home) (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/1144) +* UIX Rendering issues in UI-Focus mode (https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/1292) ## Features