Decompiled source of LevelTheUI v1.0.2

plugins\LevelTheUI.dll

Decompiled 18 hours ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LevelTheUI")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LevelTheUI")]
[assembly: AssemblyTitle("LevelTheUI")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LevelTheUI
{
	[BepInPlugin("com.leveltheui", "LevelTheUI", "1.0.2")]
	public class LevelTheUIPlugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> DeAngle;

		internal static ConfigEntry<bool> RemoveTabCtrl;

		private float lastTriggerTime = -100f;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			DeAngle = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DeAngleUI", true, "Remove the angled tilt from UI clusters");
			RemoveTabCtrl = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "RemoveTabCtrlIcons", true, "Disable Tab/Ctrl and Sprint/Chest prompts in the bottom-right HUD");
			Log.LogInfo((object)"LevelTheUI loaded");
			TriggerEventScan();
			SceneManager.sceneLoaded += delegate
			{
				TriggerEventScan();
			};
		}

		private void TriggerEventScan()
		{
			if (!(Time.time - lastTriggerTime < 2f))
			{
				lastTriggerTime = Time.time;
				((MonoBehaviour)this).StartCoroutine(EventScan());
			}
		}

		private IEnumerator EventScan()
		{
			float[] delays = new float[4] { 0f, 1f, 3f, 7f };
			float[] array = delays;
			foreach (float d in array)
			{
				if (d > 0f)
				{
					yield return (object)new WaitForSeconds(d);
				}
				else
				{
					yield return null;
				}
				ApplyFixes("event");
			}
		}

		private static void ApplyFixes(string reason)
		{
			int n = 0;
			try
			{
				Canvas[] array = Resources.FindObjectsOfTypeAll<Canvas>();
				Canvas[] array2 = array;
				foreach (Canvas val in array2)
				{
					if (!((Object)(object)val == (Object)null) && IsInGameCanvas(val))
					{
						if (DeAngle.Value)
						{
							WalkDeAngle(((Component)val).transform, ref n);
						}
						if (RemoveTabCtrl.Value)
						{
							WalkBottomRight(((Component)val).transform);
						}
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogError((object)ex);
			}
			if (n > 0)
			{
				Log.LogInfo((object)$"[{reason}] de-angled {n} transforms");
			}
		}

		private static void WalkDeAngle(Transform t, ref int n)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)t == (Object)null)
			{
				return;
			}
			if (ShouldDeAngle(((Object)t).name))
			{
				Vector3 localEulerAngles = t.localEulerAngles;
				float num = Norm(localEulerAngles.x);
				float num2 = Norm(localEulerAngles.y);
				float num3 = Norm(localEulerAngles.z);
				if ((Mathf.Abs(num) > 0.01f && Mathf.Abs(num) <= 15f) || (Mathf.Abs(num2) > 0.01f && Mathf.Abs(num2) <= 15f) || (Mathf.Abs(num3) > 0.01f && Mathf.Abs(num3) <= 15f))
				{
					t.localRotation = Quaternion.identity;
					n++;
				}
			}
			for (int i = 0; i < t.childCount; i++)
			{
				WalkDeAngle(t.GetChild(i), ref n);
			}
		}

		private static bool ShouldDeAngle(string name)
		{
			if (string.IsNullOrEmpty(name))
			{
				return false;
			}
			return name.EndsWith("Cluster", StringComparison.OrdinalIgnoreCase) || string.Equals(name, "SharedSufferingRoot", StringComparison.OrdinalIgnoreCase) || string.Equals(name, "FillRoot", StringComparison.OrdinalIgnoreCase);
		}

		private static void WalkBottomRight(Transform t)
		{
			if ((Object)(object)t == (Object)null)
			{
				return;
			}
			string text = ((Object)t).name.ToLowerInvariant();
			if (text.Contains("bottomrightcluster"))
			{
				DisableTabCtrlTree(t);
				return;
			}
			for (int i = 0; i < t.childCount; i++)
			{
				WalkBottomRight(t.GetChild(i));
			}
		}

		private static void DisableTabCtrlTree(Transform root)
		{
			if ((Object)(object)root == (Object)null)
			{
				return;
			}
			try
			{
				TMP_Text[] componentsInChildren = ((Component)root).GetComponentsInChildren<TMP_Text>(true);
				TMP_Text[] array = componentsInChildren;
				foreach (TMP_Text val in array)
				{
					if (!((Object)(object)val == (Object)null))
					{
						string text = val.text;
						if (!string.IsNullOrEmpty(text) && (text.IndexOf("tab", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("ctrl", StringComparison.OrdinalIgnoreCase) >= 0))
						{
							ForceDisable(((Component)val).gameObject);
						}
					}
				}
				Text[] componentsInChildren2 = ((Component)root).GetComponentsInChildren<Text>(true);
				Text[] array2 = componentsInChildren2;
				foreach (Text val2 in array2)
				{
					if (!((Object)(object)val2 == (Object)null))
					{
						string text2 = val2.text;
						if (!string.IsNullOrEmpty(text2) && (text2.IndexOf("tab", StringComparison.OrdinalIgnoreCase) >= 0 || text2.IndexOf("ctrl", StringComparison.OrdinalIgnoreCase) >= 0))
						{
							ForceDisable(((Component)val2).gameObject);
						}
					}
				}
			}
			catch
			{
			}
			WalkDisableByName(root);
		}

		private static void WalkDisableByName(Transform t)
		{
			if ((Object)(object)t == (Object)null)
			{
				return;
			}
			string text = ((Object)t).name.ToLowerInvariant();
			if (text == "sprintcluster" || text == "inventorycluster" || text.Contains("tab") || text.Contains("ctrl"))
			{
				ForceDisable(((Component)t).gameObject);
				return;
			}
			for (int i = 0; i < t.childCount; i++)
			{
				WalkDisableByName(t.GetChild(i));
			}
		}

		private static void ForceDisable(GameObject go)
		{
			if (!((Object)(object)go == (Object)null))
			{
				go.SetActive(false);
			}
		}

		private static bool IsInGameCanvas(Canvas c)
		{
			if ((Object)(object)c == (Object)null)
			{
				return false;
			}
			return ((Object)c).name.IndexOf("HUDSimple", StringComparison.OrdinalIgnoreCase) >= 0;
		}

		private static float Norm(float a)
		{
			while (a > 180f)
			{
				a -= 360f;
			}
			while (a < -180f)
			{
				a += 360f;
			}
			return a;
		}
	}
}