Skip to content

Commit 6824261

Browse files
committed
Add GPU check to UIX tilting to override default value
1 parent bb6b769 commit 6824261

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

CommunityBugFixCollection/TiltedUIAlignment.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
using Elements.Core;
22
using FrooxEngine;
33
using HarmonyLib;
4+
using MonkeyLoader;
5+
using MonkeyLoader.Components;
6+
using MonkeyLoader.Configuration;
47
using MonkeyLoader.Resonite;
8+
using MonoMod.Utils;
59
using System;
610
using System.Collections.Generic;
11+
using System.Reflection;
712
using System.Text;
813

914
namespace CommunityBugFixCollection
@@ -16,6 +21,54 @@ internal sealed class TiltedUIAlignment : ResoniteMonkey<TiltedUIAlignment>
1621

1722
public override bool CanBeDisabled => true;
1823

24+
protected override bool OnEngineReady()
25+
{
26+
var wasSetFromDefault = false;
27+
28+
void SetFromDefaultHandler(object sender, ConfigKeyChangedEventArgs<bool> eventArgs)
29+
=> wasSetFromDefault = eventArgs.Label == ConfigKey.SetFromDefaultEventLabel;
30+
31+
EnabledToggle!.Changed += SetFromDefaultHandler;
32+
EnabledToggle.GetValue();
33+
EnabledToggle.Changed -= SetFromDefaultHandler;
34+
35+
if (wasSetFromDefault)
36+
{
37+
Logger.Info(() => "Enabled was set from default, applying GPU detection!");
38+
39+
var unitySystemInfoType = AccessTools.TypeByName("UnityEngine.SystemInfo, UnityEngine.CoreModule");
40+
Logger.Info(() => $"Unity SystemInfo type is: {(unitySystemInfoType is null ? "null" : unitySystemInfoType.CompactDescription())}");
41+
42+
var getGraphicsDeviceName = unitySystemInfoType is null ? null : AccessTools.DeclaredPropertyGetter(unitySystemInfoType, "graphicsDeviceName");
43+
44+
if (getGraphicsDeviceName is null)
45+
{
46+
Logger.Warn(() => "Did not find UnityEngine.SystemInfo to check GPU name - disabling tilt!");
47+
48+
EnabledToggle!.SetValue(false, "GPU-Detection.Fail");
49+
}
50+
else
51+
{
52+
Logger.Debug(() => "Using UnityEngine.SystemInfo to check GPU name!");
53+
54+
var gpu = (string?)getGraphicsDeviceName?.Invoke(null, null);
55+
var isAmd = gpu?.Contains("AMD", StringComparison.OrdinalIgnoreCase) ?? false;
56+
var isIntel = gpu?.Contains("Intel", StringComparison.OrdinalIgnoreCase) ?? false;
57+
var enableTilt = isAmd || isIntel;
58+
59+
Logger.Info(() => $"Detected GPU [{gpu}] - {(enableTilt ? "enabled" : "disabled")} tilt!");
60+
61+
EnabledToggle!.SetValue(enableTilt, "GPU-Detection.Success");
62+
}
63+
}
64+
else
65+
{
66+
Logger.Info(() => "Enabled wasn't set from default, not applying GPU detection!");
67+
}
68+
69+
return base.OnEngineReady();
70+
}
71+
1972
private static void Postfix(UI_TargettingController __instance)
2073
{
2174
if (!Enabled)

0 commit comments

Comments
 (0)