Decompiled source of UIOverflowPatches v0.3.1

UIOverflowPatches.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyVersion("0.0.0.0")]
[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 UIOverflowPatches
{
	internal static class BackgroundFitter
	{
		private const float Tolerance = 0.002f;

		internal static void Inset(SpriteRenderer frame, SpriteRenderer background, float margin)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Abs(((Component)frame).transform.lossyScale.x);
			if (Mathf.Approximately(num, 0f))
			{
				return;
			}
			float num2 = margin * num;
			Bounds bounds = ((Renderer)frame).bounds;
			Bounds bounds2 = ((Renderer)background).bounds;
			float num3 = ((Bounds)(ref bounds2)).min.x - ((Bounds)(ref bounds)).min.x;
			float num4 = ((Bounds)(ref bounds)).max.x - ((Bounds)(ref bounds2)).max.x;
			if (num3 >= num2 - 0.002f && num4 >= num2 - 0.002f)
			{
				return;
			}
			float num5 = Mathf.Min(((Bounds)(ref bounds2)).size.x, ((Bounds)(ref bounds)).size.x - 2f * num2);
			if (num5 <= 0f || ((Bounds)(ref bounds2)).size.x <= 0f)
			{
				return;
			}
			if (num5 < ((Bounds)(ref bounds2)).size.x)
			{
				if ((int)background.drawMode == 0)
				{
					Vector3 localScale = ((Component)background).transform.localScale;
					localScale.x *= num5 / ((Bounds)(ref bounds2)).size.x;
					((Component)background).transform.localScale = localScale;
				}
				else
				{
					float x = ((Component)background).transform.lossyScale.x;
					if (Mathf.Approximately(x, 0f))
					{
						return;
					}
					Vector2 size = background.size;
					size.x = num5 / x;
					background.size = size;
				}
			}
			float x2 = ((Bounds)(ref bounds)).center.x;
			Bounds bounds3 = ((Renderer)background).bounds;
			float num6 = x2 - ((Bounds)(ref bounds3)).center.x;
			Transform transform = ((Component)background).transform;
			transform.position += new Vector3(num6, 0f, 0f);
		}

		internal static void ExtendRight(SpriteRenderer frame, SpriteRenderer background, float margin)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//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_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Abs(((Component)frame).transform.lossyScale.x);
			if (Mathf.Approximately(num, 0f))
			{
				return;
			}
			Bounds bounds = ((Renderer)frame).bounds;
			Bounds bounds2 = ((Renderer)background).bounds;
			float num2 = ((Bounds)(ref bounds)).max.x - margin * num;
			if (((Bounds)(ref bounds2)).max.x >= num2 - 0.002f)
			{
				return;
			}
			float x = ((Bounds)(ref bounds2)).min.x;
			float num3 = num2 - x;
			if (num3 <= 0f || ((Bounds)(ref bounds2)).size.x <= 0f)
			{
				return;
			}
			if ((int)background.drawMode == 0)
			{
				Vector3 localScale = ((Component)background).transform.localScale;
				localScale.x *= num3 / ((Bounds)(ref bounds2)).size.x;
				((Component)background).transform.localScale = localScale;
			}
			else
			{
				float x2 = ((Component)background).transform.lossyScale.x;
				if (Mathf.Approximately(x2, 0f))
				{
					return;
				}
				Vector2 size = background.size;
				size.x = num3 / x2;
				background.size = size;
			}
			Bounds bounds3 = ((Renderer)background).bounds;
			float num4 = x - ((Bounds)(ref bounds3)).min.x;
			Transform transform = ((Component)background).transform;
			transform.position += new Vector3(num4, 0f, 0f);
		}
	}
	[HarmonyPatch(typeof(BonusManager), "Start")]
	internal static class BonusDisplayStartPatch
	{
		private static void Postfix(BonusManager __instance)
		{
			BonusDisplayFix.Apply(__instance);
		}
	}
	[HarmonyPatch(typeof(BonusManager), "OnEnable")]
	internal static class BonusDisplayEnablePatch
	{
		private static void Postfix(BonusManager __instance)
		{
			BonusDisplayFix.Apply(__instance);
		}
	}
	internal static class BonusDisplayFix
	{
		private const float Margin = 0.08f;

		private static bool warned;

		internal static void Apply(BonusManager instance)
		{
			try
			{
				Run(instance);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Bonus display patch failed: " + ex));
			}
		}

		private static void Run(BonusManager instance)
		{
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			object? value = AccessTools.Field(typeof(BonusManager), "displayBackground").GetValue(instance);
			SpriteRenderer val = (SpriteRenderer)((value is SpriteRenderer) ? value : null);
			object? value2 = AccessTools.Field(typeof(BonusManager), "bonusDisplayParent").GetValue(instance);
			Transform val2 = (Transform)((value2 is Transform) ? value2 : null);
			HashSet<SpriteRenderer> hashSet = new HashSet<SpriteRenderer>();
			if ((Object)(object)val != (Object)null)
			{
				hashSet.Add(val);
			}
			string[] array = new string[3] { "physicalIcon", "magicalIcon", "coinIcon" };
			foreach (string text in array)
			{
				object? value3 = AccessTools.Field(typeof(BonusManager), text).GetValue(instance);
				SpriteRenderer val3 = (SpriteRenderer)((value3 is SpriteRenderer) ? value3 : null);
				if (val3 != null)
				{
					hashSet.Add(val3);
				}
			}
			Transform obj = (((Object)(object)val2 != (Object)null) ? val2 : ((Component)instance).transform);
			SpriteRenderer val4 = null;
			SpriteRenderer[] componentsInChildren = ((Component)obj).GetComponentsInChildren<SpriteRenderer>(true);
			foreach (SpriteRenderer val5 in componentsInChildren)
			{
				if (hashSet.Contains(val5) || (Object)(object)val5.sprite == (Object)null || ((Object)val5.sprite).name.IndexOf("Frame", StringComparison.OrdinalIgnoreCase) < 0)
				{
					continue;
				}
				if (!((Object)(object)val4 == (Object)null))
				{
					Bounds bounds = ((Renderer)val5).bounds;
					float x = ((Bounds)(ref bounds)).size.x;
					bounds = ((Renderer)val4).bounds;
					if (!(x > ((Bounds)(ref bounds)).size.x))
					{
						continue;
					}
				}
				val4 = val5;
			}
			if ((Object)(object)val == (Object)null || (Object)(object)val4 == (Object)null)
			{
				if (!warned)
				{
					warned = true;
					Plugin.Log.LogWarning((object)"Bonus display sprites not found, skipping");
				}
			}
			else
			{
				BackgroundFitter.ExtendRight(val4, val, 0.08f);
			}
		}
	}
	[HarmonyPatch(typeof(EncounterManager), "OnEnable")]
	internal static class HealthBarPatch
	{
		private const string FrameName = "Frame (1)";

		private const string BackgroundName = "Surface";

		private const float Margin = 0.11f;

		private static bool warned;

		private static void Postfix(EncounterManager __instance)
		{
			RectTransform bossHealthBarParent = __instance.bossHealthBarParent;
			if ((Object)(object)bossHealthBarParent == (Object)null)
			{
				return;
			}
			Transform val = ((Transform)bossHealthBarParent).Find("Frame (1)");
			Transform val2 = ((Transform)bossHealthBarParent).Find("Surface");
			SpriteRenderer val3 = (((Object)(object)val == (Object)null) ? null : ((Component)val).GetComponent<SpriteRenderer>());
			SpriteRenderer val4 = (((Object)(object)val2 == (Object)null) ? null : ((Component)val2).GetComponent<SpriteRenderer>());
			if ((Object)(object)val3 == (Object)null || (Object)(object)val4 == (Object)null)
			{
				if (!warned)
				{
					warned = true;
					Plugin.Log.LogWarning((object)"Health bar sprites not found, skipping");
				}
			}
			else
			{
				BackgroundFitter.Inset(val3, val4, 0.11f);
			}
		}
	}
	[BepInPlugin("com.king_tajin.uioverflowpatches", "UI Overflow Patches", "0.3.1")]
	[BepInProcess("Slots and Daggers.exe")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Harmony val = new Harmony("com.king_tajin.uioverflowpatches");
			try
			{
				val.PatchAll(typeof(Plugin).Assembly);
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)ex);
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"UI Overflow Patches loaded");
		}
	}
	[HarmonyPatch(typeof(SkillCheckManager), "Start")]
	internal static class SkillCheckButtonPatch
	{
		private static readonly (string Frame, string[] Backgrounds, float Margin)[] Groups = new(string, string[], float)[2]
		{
			("Frame B", new string[1] { "Surface C" }, 0.11f),
			("Frame A", new string[2] { "Square WhiteA", "Ornament E" }, 0.05f)
		};

		private static void Postfix(SkillCheckManager __instance)
		{
			object? value = AccessTools.Field(typeof(SkillCheckManager), "skillCheckButtonParent").GetValue(__instance);
			Transform val = (Transform)((value is Transform) ? value : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Dictionary<string, SpriteRenderer> dictionary = new Dictionary<string, SpriteRenderer>();
			SpriteRenderer[] componentsInChildren = ((Component)val).GetComponentsInChildren<SpriteRenderer>(true);
			foreach (SpriteRenderer val2 in componentsInChildren)
			{
				if ((Object)(object)val2.sprite != (Object)null && !dictionary.ContainsKey(((Object)val2.sprite).name))
				{
					dictionary.Add(((Object)val2.sprite).name, val2);
				}
			}
			(string, string[], float)[] groups = Groups;
			for (int i = 0; i < groups.Length; i++)
			{
				var (text, array, margin) = groups[i];
				if (!dictionary.TryGetValue(text, out var value2))
				{
					Plugin.Log.LogWarning((object)("Sprite " + text + " not found, skipping"));
					continue;
				}
				string[] array2 = array;
				foreach (string text2 in array2)
				{
					if (dictionary.TryGetValue(text2, out var value3))
					{
						BackgroundFitter.Inset(value2, value3, margin);
					}
					else
					{
						Plugin.Log.LogWarning((object)("Sprite " + text2 + " not found, skipping"));
					}
				}
			}
		}
	}
}