Decompiled source of SeneaLHudLayout v1.1.16

SeneaLHudLayout.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.16")]
[assembly: AssemblyInformationalVersion("1.1.16+92575c7041ce6dd64389a6313127f350441441b9")]
[assembly: AssemblyVersion("1.1.16.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 SeneaLHudLayout
{
	internal static class CompassPin
	{
		public static void Apply(Harmony harmony)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			MethodInfo methodInfo = AccessTools.Method(AccessTools.TypeByName("SeneaLUI.Hud.CompassView"), "Place", (Type[])null, (Type[])null);
			if (!(methodInfo == null))
			{
				harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(CompassPin), "IgnoreHotbar", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}

		public static void IgnoreHotbar([HarmonyArgument(1)] float sc, [HarmonyArgument(2)] ref float hotTop, [HarmonyArgument(3)] ref float hotRight, [HarmonyArgument(4)] ref float hotBottom)
		{
			hotRight = 0f;
			hotBottom = 0f;
			if (sc > 0.01f)
			{
				hotTop = SeneaLHudLayoutPlugin.CompassTop.Value * sc;
			}
		}
	}
	internal static class DrawerPreview
	{
		private static Type _hoverView;

		private static Type _drawer;

		private static FieldInfo _slots;

		private static FieldInfo _cols;

		private static FieldInfo _rows;

		private static FieldInfo _prev;

		private static FieldInfo _slotRoot;

		private static FieldInfo _slotCount;

		private static FieldInfo _slotMax;

		private static MethodInfo _slotSet;

		private static MethodInfo _slotClear;

		public static void Apply(Harmony harmony)
		{
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Expected O, but got Unknown
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Expected O, but got Unknown
			if (SeneaLHudLayoutPlugin.CollapseDrawerPreview == null || !SeneaLHudLayoutPlugin.CollapseDrawerPreview.Value)
			{
				return;
			}
			_drawer = AccessTools.TypeByName("ItemDrawers.Game.DrawerComponent");
			_hoverView = AccessTools.TypeByName("SeneaLUI.Hud.HoverView");
			if (!(_hoverView == null))
			{
				_slots = AccessTools.Field(_hoverView, "_slots");
				_cols = AccessTools.Field(_hoverView, "_cols");
				_rows = AccessTools.Field(_hoverView, "_rows");
				_prev = AccessTools.Field(_hoverView, "_prev");
				Type type = AccessTools.TypeByName("SeneaLUI.Components.Slot");
				if (type != null)
				{
					_slotRoot = AccessTools.Field(type, "Root");
					_slotCount = AccessTools.Field(type, "_count");
					_slotMax = AccessTools.Field(type, "_max");
					_slotSet = AccessTools.Method(type, "Set", new Type[1] { typeof(ItemData) }, (Type[])null);
					_slotClear = AccessTools.Method(type, "Clear", (Type[])null, (Type[])null);
				}
				MethodInfo methodInfo = AccessTools.Method(_hoverView, "FillPreview", (Type[])null, (Type[])null);
				MethodInfo methodInfo2 = AccessTools.Method(_hoverView, "Layout", (Type[])null, (Type[])null);
				if (methodInfo != null)
				{
					harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(DrawerPreview), "AfterPreview", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
				}
				if (methodInfo2 != null)
				{
					harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(DrawerPreview), "AfterPreview", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
				}
			}
		}

		private static bool IsDrawer(Container container)
		{
			if (_drawer != null && Object.op_Implicit((Object)(object)container))
			{
				return (Object)(object)((Component)container).GetComponent(_drawer) != (Object)null;
			}
			return false;
		}

		private static void AfterPreview(object __instance, Container c)
		{
			if (__instance == null || !IsDrawer(c))
			{
				return;
			}
			try
			{
				Collapse(__instance, c);
			}
			catch (Exception)
			{
			}
		}

		private static void Collapse(object hover, Container container)
		{
			IList list = _slots?.GetValue(hover) as IList;
			Inventory inventory = container.GetInventory();
			if (list == null || inventory == null)
			{
				return;
			}
			_cols?.SetValue(hover, 1);
			_rows?.SetValue(hover, 1);
			List<ItemData> allItems = inventory.GetAllItems();
			int num = 0;
			ItemData val = null;
			for (int i = 0; i < allItems.Count; i++)
			{
				ItemData val2 = allItems[i];
				if (val2 != null)
				{
					if (val == null)
					{
						val = val2;
					}
					num += val2.m_stack;
				}
			}
			for (int j = 0; j < list.Count; j++)
			{
				object obj = list[j];
				if (obj == null)
				{
					continue;
				}
				object? obj2 = _slotRoot?.GetValue(obj);
				RectTransform val3 = (RectTransform)((obj2 is RectTransform) ? obj2 : null);
				if (j == 0 && val != null)
				{
					if (Object.op_Implicit((Object)(object)val3))
					{
						((Component)val3).gameObject.SetActive(true);
					}
					_slotSet?.Invoke(obj, new object[1] { val });
					object? obj3 = _slotCount?.GetValue(obj);
					TMP_Text val4 = (TMP_Text)((obj3 is TMP_Text) ? obj3 : null);
					if (Object.op_Implicit((Object)(object)val4))
					{
						int num2 = Capacity(container);
						val4.text = ((num2 > 0) ? (num + "/" + num2) : num.ToString());
						((Component)val4).gameObject.SetActive(true);
					}
					object? obj4 = _slotMax?.GetValue(obj);
					TMP_Text val5 = (TMP_Text)((obj4 is TMP_Text) ? obj4 : null);
					if (Object.op_Implicit((Object)(object)val5))
					{
						((Component)val5).gameObject.SetActive(false);
					}
				}
				else
				{
					_slotClear?.Invoke(obj, null);
					if (Object.op_Implicit((Object)(object)val3))
					{
						((Component)val3).gameObject.SetActive(false);
					}
				}
			}
			object? obj5 = _prev?.GetValue(hover);
			RectTransform val6 = (RectTransform)((obj5 is RectTransform) ? obj5 : null);
			if (Object.op_Implicit((Object)(object)val6))
			{
				float num3 = 44f;
				val6.SetSizeWithCurrentAnchors((Axis)0, num3 + 16f);
				val6.SetSizeWithCurrentAnchors((Axis)1, num3 + 16f);
			}
		}

		private static int Capacity(Container container)
		{
			Component component = ((Component)container).GetComponent(_drawer);
			if ((Object)(object)component == (Object)null)
			{
				return 0;
			}
			PropertyInfo propertyInfo = AccessTools.Property(_drawer, "Capacity");
			if (propertyInfo == null)
			{
				return 0;
			}
			object value = propertyInfo.GetValue(component, null);
			if (value is int)
			{
				return (int)value;
			}
			return 0;
		}
	}
	internal static class HudLayout
	{
		private const string ShiftName = "SeneaLHudLayout_Shift";

		private static RectTransform _vitals;

		private static Vector2 _vitalsBase;

		private static bool _vitalsKnown;

		private static bool _loggedReady;

		private static bool _applied;

		private static int _prune;

		private static readonly Dictionary<int, Vector2> _bossBase = new Dictionary<int, Vector2>();

		private static readonly List<int> _staleBosses = new List<int>();

		private static RectTransform _banner;

		private static Vector2 _bannerBase;

		private static bool _bannerKnown;

		public static void Apply()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			Hud instance = Hud.instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.m_rootObject == (Object)null)
			{
				return;
			}
			Transform val = instance.m_rootObject.transform.Find("SeneaLUI_Hud");
			if (!((Object)(object)val == (Object)null))
			{
				RectTransform val2 = (RectTransform)val;
				RectTransform hotbarShift = PlaceHotbar(val2);
				PlaceHealthFood(val2, hotbarShift);
				PlaceMinimap(val2);
				PlaceBossBars();
				PinCompass(val2);
				PlaceCenterMessage(val2);
				PowersLayout.Apply(instance, val2);
				_applied = true;
				if (!_loggedReady)
				{
					_loggedReady = true;
					Debug.Log((object)"[SeneaL HUD Layout] Positioning hotbar, compass, messages, and boss powers.");
				}
			}
		}

		public static void Restore()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Expected O, but got Unknown
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			if (!_applied)
			{
				return;
			}
			Hud instance = Hud.instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.m_rootObject == (Object)null)
			{
				return;
			}
			Transform val = instance.m_rootObject.transform.Find("SeneaLUI_Hud");
			if (!((Object)(object)val == (Object)null))
			{
				RectTransform val2 = (RectTransform)val;
				Transform obj = ((Transform)val2).Find("menuFade/Hotbar/SeneaLHudLayout_Shift");
				RectTransform val3 = (RectTransform)(object)((obj is RectTransform) ? obj : null);
				if (val3 != null)
				{
					val3.anchoredPosition = Vector2.zero;
				}
				if (_vitalsKnown && (Object)(object)_vitals != (Object)null)
				{
					_vitals.anchoredPosition = _vitalsBase;
				}
				Transform obj2 = ((Transform)val2).Find("mapFade/Minimap");
				RectTransform val4 = (RectTransform)(object)((obj2 is RectTransform) ? obj2 : null);
				if (val4 != null)
				{
					val4.anchoredPosition = Vector2.zero;
				}
				RestoreBossBars();
				RestoreCenterMessage();
				PowersLayout.Restore(val2);
				_applied = false;
			}
		}

		private static RectTransform PlaceHotbar(RectTransform root)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ((Transform)root).Find("menuFade/Hotbar");
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			RectTransform val2 = EnsureShift((RectTransform)val);
			val2.anchoredPosition = Vector2.zero;
			if (!SeneaLHudLayoutPlugin.HotbarBottomLeft.Value && Mathf.Approximately(SeneaLHudLayoutPlugin.HotbarOffsetX.Value, 0f) && Mathf.Approximately(SeneaLHudLayoutPlugin.HotbarOffsetY.Value, 0f))
			{
				return val2;
			}
			if (SeneaLHudLayoutPlugin.HotbarBottomLeft.Value && TryChildrenVertical(val2, out var minY, out var _))
			{
				float num = EdgeY(root, bottom: true) + SeneaLHudLayoutPlugin.HotbarBottomMargin.Value;
				Move(val2, 0f, num - minY);
			}
			Move(val2, SeneaLHudLayoutPlugin.HotbarOffsetX.Value, SeneaLHudLayoutPlugin.HotbarOffsetY.Value);
			return val2;
		}

		private static void PlaceHealthFood(RectTransform root, RectTransform hotbarShift)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_0042: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ((Transform)root).Find("Health/vitals");
			if (!((Object)(object)val == (Object)null))
			{
				RectTransform val2 = (RectTransform)val;
				if ((Object)(object)_vitals != (Object)(object)val2)
				{
					_vitals = val2;
					_vitalsBase = val2.anchoredPosition;
					_vitalsKnown = true;
				}
				val2.anchoredPosition = _vitalsBase;
				float value = SeneaLHudLayoutPlugin.HealthFoodOffsetY.Value;
				float maxY = 0f;
				if (SeneaLHudLayoutPlugin.LiftHealthAboveHotbar.Value && SeneaLHudLayoutPlugin.HotbarBottomLeft.Value && (Object)(object)hotbarShift != (Object)null && TryChildrenVertical(hotbarShift, out var _, out maxY))
				{
					float num = EdgeY(val2, bottom: true);
					Move(val2, 0f, maxY + value - num);
				}
				else if (!Mathf.Approximately(value, 0f))
				{
					Move(val2, 0f, value);
				}
			}
		}

		private static void PlaceMinimap(RectTransform root)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			Transform val = ((Transform)root).Find("mapFade/Minimap");
			if (!((Object)(object)val == (Object)null))
			{
				RectTransform val2 = (RectTransform)val;
				val2.anchoredPosition = Vector2.zero;
				Move(val2, SeneaLHudLayoutPlugin.MinimapOffsetX.Value, SeneaLHudLayoutPlugin.MinimapOffsetY.Value);
			}
		}

		private static void PlaceBossBars()
		{
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			EnemyHud instance = EnemyHud.instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.m_hudRoot == (Object)null)
			{
				return;
			}
			float value = SeneaLHudLayoutPlugin.BossOffsetY.Value;
			Transform transform = instance.m_hudRoot.transform;
			HashSet<int> hashSet = new HashSet<int>();
			for (int i = 0; i < transform.childCount; i++)
			{
				Transform child = transform.GetChild(i);
				if (((Object)child).name.IndexOf("Boss", StringComparison.OrdinalIgnoreCase) < 0)
				{
					continue;
				}
				RectTransform val = (RectTransform)(object)((child is RectTransform) ? child : null);
				if (!((Object)(object)val == (Object)null))
				{
					int instanceID = ((Object)val).GetInstanceID();
					hashSet.Add(instanceID);
					if (!_bossBase.ContainsKey(instanceID))
					{
						_bossBase[instanceID] = val.anchoredPosition;
					}
					val.anchoredPosition = _bossBase[instanceID];
					if (!Mathf.Approximately(value, 0f))
					{
						Move(val, 0f, value);
					}
				}
			}
			if (++_prune < 120)
			{
				return;
			}
			_prune = 0;
			_staleBosses.Clear();
			foreach (int key in _bossBase.Keys)
			{
				if (!hashSet.Contains(key))
				{
					_staleBosses.Add(key);
				}
			}
			for (int j = 0; j < _staleBosses.Count; j++)
			{
				_bossBase.Remove(_staleBosses[j]);
			}
		}

		private static void RestoreBossBars()
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			EnemyHud instance = EnemyHud.instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.m_hudRoot == (Object)null)
			{
				_bossBase.Clear();
				return;
			}
			Transform transform = instance.m_hudRoot.transform;
			for (int i = 0; i < transform.childCount; i++)
			{
				Transform child = transform.GetChild(i);
				RectTransform val = (RectTransform)(object)((child is RectTransform) ? child : null);
				if (val != null && _bossBase.TryGetValue(((Object)val).GetInstanceID(), out var value))
				{
					val.anchoredPosition = value;
				}
			}
			_bossBase.Clear();
		}

		private static RectTransform EnsureShift(RectTransform layer)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			Transform val = ((Transform)layer).Find("SeneaLHudLayout_Shift");
			if ((Object)(object)val != (Object)null)
			{
				return (RectTransform)val;
			}
			RectTransform component = new GameObject("SeneaLHudLayout_Shift", new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
			((Transform)component).SetParent((Transform)(object)layer, false);
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.offsetMin = Vector2.zero;
			component.offsetMax = Vector2.zero;
			component.pivot = new Vector2(0.5f, 0.5f);
			List<Transform> list = new List<Transform>(((Transform)layer).childCount);
			for (int i = 0; i < ((Transform)layer).childCount; i++)
			{
				list.Add(((Transform)layer).GetChild(i));
			}
			for (int j = 0; j < list.Count; j++)
			{
				if ((Object)(object)list[j] != (Object)(object)component)
				{
					list[j].SetParent((Transform)(object)component, false);
				}
			}
			return component;
		}

		private static void PinCompass(RectTransform root)
		{
			Transform obj = ((Transform)root).Find("menuFade/Compass/compass");
			RectTransform val = (RectTransform)(object)((obj is RectTransform) ? obj : null);
			if (val != null)
			{
				Transform parent = ((Transform)val).parent;
				RectTransform val2 = (RectTransform)(object)((parent is RectTransform) ? parent : null);
				if (val2 != null)
				{
					float num = EdgeY(val2, bottom: false) - SeneaLHudLayoutPlugin.CompassTop.Value;
					Move(val, 0f, num - EdgeY(val, bottom: false));
				}
			}
		}

		private static void PlaceCenterMessage(RectTransform root)
		{
			//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)
			Transform obj = ((Transform)root).Find("menuFade/Notifications2/banner");
			RectTransform val = (RectTransform)(object)((obj is RectTransform) ? obj : null);
			if (val != null)
			{
				if ((Object)(object)_banner != (Object)(object)val)
				{
					_banner = val;
					_bannerBase = val.anchoredPosition;
					_bannerKnown = true;
				}
				float num = float.PositiveInfinity;
				Transform obj2 = ((Transform)root).Find("menuFade/Compass/compass");
				RectTransform val2 = (RectTransform)(object)((obj2 is RectTransform) ? obj2 : null);
				if (val2 != null && ((Component)val2).gameObject.activeInHierarchy)
				{
					num = EdgeY(val2, bottom: true);
				}
				if (TryBossBottom(out var bottom))
				{
					num = Mathf.Min(num, bottom);
				}
				if (!float.IsPositiveInfinity(num))
				{
					float num2 = num - SeneaLHudLayoutPlugin.CenterMessageGap.Value;
					Move(val, 0f, num2 - EdgeY(val, bottom: false));
				}
			}
		}

		private static void RestoreCenterMessage()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			if (_bannerKnown && (Object)(object)_banner != (Object)null)
			{
				_banner.anchoredPosition = _bannerBase;
			}
		}

		private static bool TryBossBottom(out float bottom)
		{
			bottom = float.PositiveInfinity;
			EnemyHud instance = EnemyHud.instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.m_hudRoot == (Object)null)
			{
				return false;
			}
			Transform transform = instance.m_hudRoot.transform;
			bool result = false;
			for (int i = 0; i < transform.childCount; i++)
			{
				Transform child = transform.GetChild(i);
				if (!((Component)child).gameObject.activeInHierarchy || ((Object)child).name.IndexOf("Boss", StringComparison.OrdinalIgnoreCase) < 0)
				{
					continue;
				}
				RectTransform val = (RectTransform)(object)((child is RectTransform) ? child : null);
				if (val != null)
				{
					float num = EdgeY(val, bottom: true);
					if (num < bottom)
					{
						bottom = num;
					}
					result = true;
				}
			}
			return result;
		}

		internal static void Move(RectTransform rt, float pixelsX, float pixelsY)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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_0048: 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)
			if (!((Object)(object)((Transform)rt).parent == (Object)null))
			{
				Vector3 val = ((Transform)rt).parent.InverseTransformVector(new Vector3(pixelsX, pixelsY, 0f));
				Vector2 anchoredPosition = rt.anchoredPosition;
				anchoredPosition.x += val.x;
				anchoredPosition.y += val.y;
				rt.anchoredPosition = anchoredPosition;
			}
		}

		internal static float EdgeX(RectTransform rt, bool left)
		{
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			rt.GetWorldCorners(array);
			float x = array[0].x;
			for (int i = 1; i < 4; i++)
			{
				if (left ? (array[i].x < x) : (array[i].x > x))
				{
					x = array[i].x;
				}
			}
			return x;
		}

		internal static float EdgeY(RectTransform rt, bool bottom)
		{
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			rt.GetWorldCorners(array);
			float y = array[0].y;
			for (int i = 1; i < 4; i++)
			{
				if (bottom ? (array[i].y < y) : (array[i].y > y))
				{
					y = array[i].y;
				}
			}
			return y;
		}

		private static bool TryChildrenVertical(RectTransform parent, out float minY, out float maxY)
		{
			minY = float.PositiveInfinity;
			maxY = float.NegativeInfinity;
			bool result = false;
			for (int i = 0; i < ((Transform)parent).childCount; i++)
			{
				Transform child = ((Transform)parent).GetChild(i);
				RectTransform val = (RectTransform)(object)((child is RectTransform) ? child : null);
				if (!((Object)(object)val == (Object)null) && ((Component)val).gameObject.activeInHierarchy)
				{
					float num = EdgeY(val, bottom: true);
					float num2 = EdgeY(val, bottom: false);
					if (num < minY)
					{
						minY = num;
					}
					if (num2 > maxY)
					{
						maxY = num2;
					}
					result = true;
				}
			}
			return result;
		}
	}
	internal static class PowersLayout
	{
		private const string PassiveGuid = "org.bepinex.plugins.passivepowers";

		private const string KeyName = "SeneaLHudLayout_Key";

		private const string BuffName = "SeneaLHudLayout_Buff";

		private const string DownName = "SeneaLHudLayout_Down";

		private const string ShortcutSection = "2 - Active Powers";

		private static readonly Color KeyReady = new Color(0.93f, 0.88f, 0.78f);

		private static readonly Color KeyLocked = new Color(0.45f, 0.45f, 0.45f);

		private static readonly Color BuffColor = new Color(0.45f, 0.95f, 0.4f);

		private static readonly Color DownColor = new Color(0.95f, 0.32f, 0.28f);

		private static readonly List<StatusEffect> Effects = new List<StatusEffect>();

		private static readonly FieldInfo GuardianPowerField = AccessTools.Field(typeof(Player), "m_guardianPower");

		private static readonly FieldInfo EffectTimeField = AccessTools.Field(typeof(StatusEffect), "m_time");

		private static bool _gpHidden;

		private static GameObject _gp;

		private static TMP_FontAsset _font;

		private static Material _fontMaterial;

		public static void Apply(Hud hud, RectTransform senealRoot)
		{
			if (Chainloader.PluginInfos.TryGetValue("org.bepinex.plugins.passivepowers", out var value))
			{
				if (SeneaLHudLayoutPlugin.HideSenealPower.Value)
				{
					HideSenealSlot(senealRoot);
				}
				else
				{
					ShowSenealSlot();
				}
				PlacePowers(hud, senealRoot, value.Instance.Config);
			}
		}

		public static void Restore(RectTransform senealRoot)
		{
			ShowSenealSlot();
			ResetScale();
		}

		private static void HideSenealSlot(RectTransform senealRoot)
		{
			Transform val = ((Transform)senealRoot).Find("Health/vitals/gp");
			if (!((Object)(object)val == (Object)null))
			{
				_gp = ((Component)val).gameObject;
				if (_gp.activeSelf)
				{
					_gp.SetActive(false);
				}
				_gpHidden = true;
			}
		}

		private static void ShowSenealSlot()
		{
			if (_gpHidden && (Object)(object)_gp != (Object)null)
			{
				_gp.SetActive(true);
			}
			_gpHidden = false;
		}

		private static void PlacePowers(Hud hud, RectTransform senealRoot, ConfigFile config)
		{
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)hud.m_gpRoot == (Object)null)
			{
				return;
			}
			Transform obj = ((Transform)senealRoot).Find("Health/vitals/food");
			RectTransform val = (RectTransform)(object)((obj is RectTransform) ? obj : null);
			if (val == null)
			{
				return;
			}
			RememberFont(hud);
			List<Transform> list = new List<Transform>();
			Transform transform = ((Component)hud.m_gpRoot).transform;
			for (int i = 0; i < transform.childCount; i++)
			{
				Transform child = transform.GetChild(i);
				if (((Object)child).name.StartsWith("powerContainer") && ((Component)child).gameObject.activeInHierarchy)
				{
					list.Add(child);
				}
			}
			float value = SeneaLHudLayoutPlugin.PowersGap.Value;
			float value2 = SeneaLHudLayoutPlugin.PowersScale.Value;
			float num = HudLayout.EdgeX(val, left: false) + value + SeneaLHudLayoutPlugin.PowersOffsetX.Value;
			float num2 = HudLayout.EdgeY(val, bottom: true) + SeneaLHudLayoutPlugin.PowersOffsetY.Value;
			float num3 = SharedCooldown();
			RefreshEffects();
			RectTransform icon = null;
			float num4 = float.NegativeInfinity;
			for (int j = 0; j < list.Count; j++)
			{
				int slot = SlotIndex(list[j]);
				list[j].localScale = new Vector3(value2, value2, 1f);
				if (!TryBounds(list[j], out var minX, out var minY, out var maxX, out var _))
				{
					continue;
				}
				Transform obj2 = list[j];
				obj2.position += new Vector3(num - minX, num2 - minY, 0f);
				SetKey(list[j], ShortcutText(config, slot), num3 > 0f);
				string text = PowerName(slot);
				SetTimer(list[j], "SeneaLHudLayout_Buff", (text == null) ? 0f : EffectTimeLeft("PassivePowers " + text), BuffColor, above: true);
				SetTimer(list[j], "SeneaLHudLayout_Down", (text == null) ? 0f : EffectTimeLeft("PassivePowers Depletion " + text), DownColor, above: false);
				Transform obj3 = list[j].Find("Icon");
				RectTransform val2 = (RectTransform)(object)((obj3 is RectTransform) ? obj3 : null);
				if (val2 != null)
				{
					float num5 = HudLayout.EdgeX(val2, left: false);
					if (num5 > num4)
					{
						num4 = num5;
						icon = val2;
					}
				}
				num += maxX - minX + value;
			}
			PlaceSharedCooldown(hud, icon, num3, value2);
		}

		private static void ResetScale()
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			Hud instance = Hud.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			if ((Object)(object)instance.m_gpRoot != (Object)null)
			{
				Transform transform = ((Component)instance.m_gpRoot).transform;
				for (int i = 0; i < transform.childCount; i++)
				{
					Transform child = transform.GetChild(i);
					if (((Object)child).name.StartsWith("powerContainer"))
					{
						child.localScale = Vector3.one;
					}
				}
			}
			if ((Object)(object)instance.m_gpCooldown != (Object)null)
			{
				instance.m_gpCooldown.transform.localScale = Vector3.one;
			}
		}

		private static float SharedCooldown()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return 0f;
			}
			return Mathf.Max(0f, localPlayer.m_guardianPowerCooldown);
		}

		private static void RefreshEffects()
		{
			Effects.Clear();
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null))
			{
				((Character)localPlayer).GetSEMan().GetHUDStatusEffects(Effects);
			}
		}

		private static float EffectTimeLeft(string effectName)
		{
			for (int i = 0; i < Effects.Count; i++)
			{
				StatusEffect val = Effects[i];
				if ((Object)(object)val != (Object)null && ((Object)val).name == effectName && val.m_ttl > 0f)
				{
					float num = ((EffectTimeField?.GetValue(val) is float num2) ? num2 : 0f);
					return Mathf.Max(0f, val.m_ttl - num);
				}
			}
			return 0f;
		}

		private static string PowerName(int slot)
		{
			Player localPlayer = Player.m_localPlayer;
			string text = GuardianPowerField?.GetValue(localPlayer) as string;
			if (string.IsNullOrEmpty(text))
			{
				return null;
			}
			string[] array = text.Split(new char[1] { ',' });
			int num = slot - 1;
			if (num < 0 || num >= array.Length)
			{
				return null;
			}
			string text2 = array[num].Trim();
			if (text2.Length != 0)
			{
				return text2;
			}
			return null;
		}

		private static void PlaceSharedCooldown(Hud hud, RectTransform icon, float seconds, float scale)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)hud.m_gpCooldown == (Object)null)
			{
				return;
			}
			if (!(seconds <= 0f) && !((Object)(object)icon == (Object)null))
			{
				Transform transform = hud.m_gpCooldown.transform;
				RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
				if (val != null)
				{
					((Component)hud.m_gpCooldown).gameObject.SetActive(true);
					((Transform)val).localScale = new Vector3(scale, scale, 1f);
					float num = (HudLayout.EdgeY(icon, bottom: true) + HudLayout.EdgeY(icon, bottom: false)) * 0.5f;
					float num2 = HudLayout.EdgeX(icon, left: false);
					float num3 = (HudLayout.EdgeY(val, bottom: true) + HudLayout.EdgeY(val, bottom: false)) * 0.5f;
					float num4 = HudLayout.EdgeX(val, left: true);
					((Transform)val).position = ((Transform)val).position + new Vector3(num2 + 8f - num4, num - num3, 0f);
					return;
				}
			}
			((Component)hud.m_gpCooldown).gameObject.SetActive(false);
		}

		private static int SlotIndex(Transform container)
		{
			string name = ((Object)container).name;
			int num = name.LastIndexOf(' ');
			if (num >= 0 && int.TryParse(name.Substring(num + 1), out var result))
			{
				return result;
			}
			return 1;
		}

		private static string ShortcutText(ConfigFile config, int slot)
		{
			//IL_0027: 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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			ConfigEntry<KeyboardShortcut> val = default(ConfigEntry<KeyboardShortcut>);
			if (!config.TryGetEntry<KeyboardShortcut>("2 - Active Powers", "Shortcut for boss power " + slot, ref val))
			{
				return "";
			}
			KeyboardShortcut value = val.Value;
			if ((int)((KeyboardShortcut)(ref value)).MainKey == 0)
			{
				return "";
			}
			List<string> list = new List<string>();
			foreach (KeyCode modifier in ((KeyboardShortcut)(ref value)).Modifiers)
			{
				list.Add(Pretty(modifier));
			}
			list.Add(Pretty(((KeyboardShortcut)(ref value)).MainKey));
			return string.Join("+", list);
		}

		private unsafe static string Pretty(KeyCode key)
		{
			string text = ((object)(*(KeyCode*)(&key))/*cast due to .constrained prefix*/).ToString();
			if (text.StartsWith("Alpha"))
			{
				return text.Substring(5);
			}
			switch (text)
			{
			case "LeftShift":
			case "RightShift":
				return "Shift";
			case "LeftControl":
			case "RightControl":
				return "Ctrl";
			case "LeftAlt":
			case "RightAlt":
				return "Alt";
			default:
				return text;
			}
		}

		private static void RememberFont(Hud hud)
		{
			if (!((Object)(object)_font != (Object)null) && !((Object)(object)hud.m_gpName == (Object)null))
			{
				_font = hud.m_gpName.font;
				_fontMaterial = hud.m_gpName.fontSharedMaterial;
			}
		}

		private static void SetKey(Transform container, string text, bool locked)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val = EnsureLabel(container, "SeneaLHudLayout_Key", locked ? KeyLocked : KeyReady);
			((TMP_Text)val).text = text;
			((Graphic)val).color = (locked ? KeyLocked : KeyReady);
			if (TryBounds(container, out var minX, out var minY, out var maxX, out var _))
			{
				((Transform)((TMP_Text)val).rectTransform).position = new Vector3((minX + maxX) * 0.5f, minY - 2f, ((Transform)((TMP_Text)val).rectTransform).position.z);
			}
		}

		private static void SetTimer(Transform container, string name, float seconds, Color color, bool above)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val = EnsureLabel(container, name, color);
			if (seconds <= 0.05f)
			{
				((Component)val).gameObject.SetActive(false);
				return;
			}
			((Component)val).gameObject.SetActive(true);
			((TMP_Text)val).text = StatusEffect.GetTimeString(seconds, false, false);
			((Graphic)val).color = color;
			RectTransform val2 = (RectTransform)(above ? ((object)TopAnchor(container)) : ((object)/*isinst with value type is only supported in some contexts*/));
			if ((Object)(object)val2 == (Object)null)
			{
				Transform obj = container.Find("Icon");
				val2 = (RectTransform)(object)((obj is RectTransform) ? obj : null);
			}
			if (!((Object)(object)val2 == (Object)null))
			{
				RectTransform rectTransform = ((TMP_Text)val).rectTransform;
				float num = (HudLayout.EdgeX(val2, left: true) + HudLayout.EdgeX(val2, left: false)) * 0.5f;
				float num2 = (HudLayout.EdgeX(rectTransform, left: true) + HudLayout.EdgeX(rectTransform, left: false)) * 0.5f;
				float num3 = ((!above) ? (HudLayout.EdgeY(val2, bottom: true) - 2f - HudLayout.EdgeY(rectTransform, bottom: false)) : (HudLayout.EdgeY(val2, bottom: false) + 2f - HudLayout.EdgeY(rectTransform, bottom: true)));
				((Transform)rectTransform).position = ((Transform)rectTransform).position + new Vector3(num - num2, num3, 0f);
			}
		}

		private static RectTransform TopAnchor(Transform container)
		{
			Transform obj = container.Find("Icon");
			RectTransform val = (RectTransform)(object)((obj is RectTransform) ? obj : null);
			Transform obj2 = container.Find("Name");
			RectTransform val2 = (RectTransform)(object)((obj2 is RectTransform) ? obj2 : null);
			if ((Object)(object)val == (Object)null)
			{
				return val2;
			}
			if ((Object)(object)val2 == (Object)null)
			{
				return val;
			}
			if (!(HudLayout.EdgeY(val2, bottom: false) > HudLayout.EdgeY(val, bottom: false)))
			{
				return val;
			}
			return val2;
		}

		private static TextMeshProUGUI EnsureLabel(Transform container, string name, Color color)
		{
			//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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			Transform val = container.Find(name);
			if ((Object)(object)val != (Object)null)
			{
				return ((Component)val).GetComponent<TextMeshProUGUI>();
			}
			GameObject val2 = new GameObject(name, new Type[1] { typeof(RectTransform) });
			val2.transform.SetParent(container, false);
			val2.GetComponent<RectTransform>().sizeDelta = new Vector2(96f, 18f);
			TextMeshProUGUI val3 = val2.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val3).fontSize = 13f;
			((TMP_Text)val3).alignment = (TextAlignmentOptions)514;
			((TMP_Text)val3).textWrappingMode = (TextWrappingModes)0;
			((TMP_Text)val3).overflowMode = (TextOverflowModes)0;
			((Graphic)val3).raycastTarget = false;
			((Graphic)val3).color = color;
			if ((Object)(object)_font != (Object)null)
			{
				((TMP_Text)val3).font = _font;
				((TMP_Text)val3).fontSharedMaterial = _fontMaterial;
			}
			return val3;
		}

		private static bool TryBounds(Transform root, out float minX, out float minY, out float maxX, out float maxY)
		{
			minX = float.PositiveInfinity;
			minY = float.PositiveInfinity;
			maxX = float.NegativeInfinity;
			maxY = float.NegativeInfinity;
			bool result = false;
			Stack<Transform> stack = new Stack<Transform>();
			stack.Push(root);
			while (stack.Count > 0)
			{
				Transform val = stack.Pop();
				for (int i = 0; i < val.childCount; i++)
				{
					Transform child = val.GetChild(i);
					if (((Object)child).name == "SeneaLHudLayout_Key" || ((Object)child).name == "SeneaLHudLayout_Buff" || ((Object)child).name == "SeneaLHudLayout_Down")
					{
						continue;
					}
					stack.Push(child);
					RectTransform val2 = (RectTransform)(object)((child is RectTransform) ? child : null);
					if (val2 != null && ((Component)val2).gameObject.activeInHierarchy)
					{
						float num = HudLayout.EdgeX(val2, left: true);
						float num2 = HudLayout.EdgeX(val2, left: false);
						float num3 = HudLayout.EdgeY(val2, bottom: true);
						float num4 = HudLayout.EdgeY(val2, bottom: false);
						if (num < minX)
						{
							minX = num;
						}
						if (num2 > maxX)
						{
							maxX = num2;
						}
						if (num3 < minY)
						{
							minY = num3;
						}
						if (num4 > maxY)
						{
							maxY = num4;
						}
						result = true;
					}
				}
			}
			return result;
		}
	}
	internal static class ResourceBars
	{
		private static Type _hudRoot;

		private static Type _staminaView;

		private static Type _row;

		private static FieldInfo _viewField;

		private static FieldInfo _staminaRow;

		private static FieldInfo _eitrRow;

		private static FieldInfo _adrenalineRow;

		private static FieldInfo _groupField;

		private static bool _ready;

		public static void Apply()
		{
			if (!Ready())
			{
				return;
			}
			object value = _viewField.GetValue(null);
			if (value != null)
			{
				if (On(SeneaLHudLayoutPlugin.AlwaysShowStamina))
				{
					Show(_staminaRow.GetValue(value));
				}
				if (On(SeneaLHudLayoutPlugin.AlwaysShowEitr))
				{
					Show(_eitrRow.GetValue(value));
				}
				if (On(SeneaLHudLayoutPlugin.AlwaysShowAdrenaline))
				{
					Show(_adrenalineRow.GetValue(value));
				}
			}
		}

		private static bool On(object entry)
		{
			if (entry is ConfigEntry<bool> val)
			{
				return val.Value;
			}
			return false;
		}

		private static void Show(object row)
		{
			if (row == null)
			{
				return;
			}
			object? value = _groupField.GetValue(row);
			CanvasGroup val = (CanvasGroup)((value is CanvasGroup) ? value : null);
			if (Object.op_Implicit((Object)(object)val))
			{
				if (!((Component)val).gameObject.activeSelf)
				{
					((Component)val).gameObject.SetActive(true);
				}
				if (val.alpha < 1f)
				{
					val.alpha = 1f;
				}
			}
		}

		private static bool Ready()
		{
			if (_ready)
			{
				return _viewField != null;
			}
			_ready = true;
			_hudRoot = AccessTools.TypeByName("SeneaLUI.Hud.HudRoot");
			_staminaView = AccessTools.TypeByName("SeneaLUI.Hud.StaminaView");
			_row = AccessTools.Inner(_staminaView, "Row");
			_viewField = AccessTools.Field(_hudRoot, "_stamina");
			_staminaRow = AccessTools.Field(_staminaView, "_stamina");
			_eitrRow = AccessTools.Field(_staminaView, "_eitr");
			_adrenalineRow = AccessTools.Field(_staminaView, "_adrenaline");
			_groupField = AccessTools.Field(_row, "Group");
			if (_viewField != null)
			{
				return _groupField != null;
			}
			return false;
		}
	}
	internal static class RulesNotice
	{
		public static void Apply(Harmony harmony)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			MethodInfo methodInfo = AccessTools.Method(AccessTools.TypeByName("SeneaLUI.Hud.NoticeModal"), "Show", (Type[])null, (Type[])null);
			if (!(methodInfo == null))
			{
				harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(RulesNotice), "SkipRulesWindow", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}

		private static bool SkipRulesWindow(string title)
		{
			if (SeneaLHudLayoutPlugin.HideServerRules == null || !SeneaLHudLayoutPlugin.HideServerRules.Value)
			{
				return true;
			}
			string text = AccessTools.Property(AccessTools.TypeByName("SeneaLUI.Core.Loc"), "SrvRulesTitle")?.GetValue(null, null) as string;
			if (!string.IsNullOrEmpty(text))
			{
				return title != text;
			}
			return true;
		}
	}
	[BepInPlugin("cjayride.SeneaLHudLayout", "SeneaL HUD Layout", "1.1.16")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("valheim.exe")]
	public class SeneaLHudLayoutPlugin : BaseUnityPlugin
	{
		public const string NAME = "SeneaL HUD Layout";

		public const string GUID = "cjayride.SeneaLHudLayout";

		public const string VERSION = "1.1.16";

		public static ConfigEntry<bool> Enabled;

		public static ConfigEntry<bool> HotbarBottomLeft;

		public static ConfigEntry<float> HotbarBottomMargin;

		public static ConfigEntry<float> HotbarOffsetX;

		public static ConfigEntry<float> HotbarOffsetY;

		public static ConfigEntry<bool> LiftHealthAboveHotbar;

		public static ConfigEntry<float> HealthFoodOffsetY;

		public static ConfigEntry<float> MinimapOffsetX;

		public static ConfigEntry<float> MinimapOffsetY;

		public static ConfigEntry<float> BossOffsetY;

		public static ConfigEntry<float> CompassTop;

		public static ConfigEntry<float> CenterMessageGap;

		public static ConfigEntry<bool> HideSenealPower;

		public static ConfigEntry<float> PowersGap;

		public static ConfigEntry<float> PowersScale;

		public static ConfigEntry<float> PowersOffsetX;

		public static ConfigEntry<float> PowersOffsetY;

		public static ConfigEntry<bool> CollapseDrawerPreview;

		public static ConfigEntry<bool> ShowWorldHealthNumbers;

		public static ConfigEntry<bool> AlwaysShowStamina;

		public static ConfigEntry<bool> AlwaysShowEitr;

		public static ConfigEntry<bool> AlwaysShowAdrenaline;

		public static ConfigEntry<float> SelectionGlow;

		public static ConfigEntry<bool> ShowEquipCue;

		public static ConfigEntry<bool> HideServerRules;

		private void Awake()
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Expected O, but got Unknown
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Expected O, but got Unknown
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Expected O, but got Unknown
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Expected O, but got Unknown
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Expected O, but got Unknown
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Expected O, but got Unknown
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Expected O, but got Unknown
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Expected O, but got Unknown
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Expected O, but got Unknown
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Expected O, but got Unknown
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Expected O, but got Unknown
			//IL_038a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: Expected O, but got Unknown
			//IL_0467: Unknown result type (might be due to invalid IL or missing references)
			//IL_0471: Expected O, but got Unknown
			//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c6: Expected O, but got Unknown
			//IL_04c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cc: Expected O, but got Unknown
			//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d2: Expected O, but got Unknown
			//IL_04d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d8: Expected O, but got Unknown
			//IL_04dd: Expected O, but got Unknown
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Apply the layout offsets below. Turn this off to restore SeneaL UI's own placement.");
			HotbarBottomLeft = ((BaseUnityPlugin)this).Config.Bind<bool>("Hotbar", "BottomLeft", true, "Move the hotbar, action slots, and food quick slots to the bottom left. They are drawn at the top left by SeneaL UI.");
			HotbarBottomMargin = ((BaseUnityPlugin)this).Config.Bind<float>("Hotbar", "BottomMargin", 16f, new ConfigDescription("Pixels to leave between the bottom of that cluster and the bottom of the screen.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 400f), Array.Empty<object>()));
			HotbarOffsetX = ((BaseUnityPlugin)this).Config.Bind<float>("Hotbar", "OffsetX", 0f, new ConfigDescription("Extra horizontal nudge in pixels. Positive moves right.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-2000f, 2000f), Array.Empty<object>()));
			HotbarOffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("Hotbar", "OffsetY", 0f, new ConfigDescription("Extra vertical nudge in pixels, after BottomLeft placement. Positive moves up.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-2000f, 2000f), Array.Empty<object>()));
			LiftHealthAboveHotbar = ((BaseUnityPlugin)this).Config.Bind<bool>("HealthFood", "LiftAboveHotbar", true, "Raise the health, food, and guardian-power cluster so it sits above the relocated hotbar.");
			HealthFoodOffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("HealthFood", "OffsetY", 28f, new ConfigDescription("Extra pixels to raise the health and food cluster. Positive moves up. Applied on top of LiftAboveHotbar.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-2000f, 2000f), Array.Empty<object>()));
			MinimapOffsetX = ((BaseUnityPlugin)this).Config.Bind<float>("Minimap", "OffsetX", -36f, new ConfigDescription("Pixels to move the minimap, wind pill, and time pill. Negative moves left.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-2000f, 2000f), Array.Empty<object>()));
			MinimapOffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("Minimap", "OffsetY", 0f, new ConfigDescription("Pixels to move the minimap cluster. Positive moves up.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-2000f, 2000f), Array.Empty<object>()));
			BossOffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("BossBar", "OffsetY", 40f, new ConfigDescription("Pixels to move boss health bars. Positive moves up. Regular enemy bars stay where SeneaL UI put them.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-2000f, 2000f), Array.Empty<object>()));
			CompassTop = ((BaseUnityPlugin)this).Config.Bind<float>("Compass", "Top", 8f, new ConfigDescription("Pixels between the top of the screen and the compass. The hotbar and action slots never move it.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 800f), Array.Empty<object>()));
			CenterMessageGap = ((BaseUnityPlugin)this).Config.Bind<float>("CenterMessage", "Gap", 18f, new ConfigDescription("Pixels between the slain / biome banner and whatever is above it: the compass, or the boss bar when one is showing.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 400f), Array.Empty<object>()));
			HideSenealPower = ((BaseUnityPlugin)this).Config.Bind<bool>("Powers", "HideSenealSlot", true, "Hide SeneaL UI's guardian-power circle and its F key. That key does not activate Passive Powers.");
			PowersGap = ((BaseUnityPlugin)this).Config.Bind<float>("Powers", "Gap", 12f, new ConfigDescription("Pixels between the food column and the first Passive Powers icon, and between the two icons.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 200f), Array.Empty<object>()));
			PowersScale = ((BaseUnityPlugin)this).Config.Bind<float>("Powers", "Scale", 1f, new ConfigDescription("Size of the Passive Powers icons, their key labels, and the shared cooldown. 1 is the current size. Smaller than 1 shrinks them.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 1.5f), Array.Empty<object>()));
			PowersOffsetX = ((BaseUnityPlugin)this).Config.Bind<float>("Powers", "OffsetX", 0f, new ConfigDescription("Extra nudge for the Passive Powers icons. Positive moves right.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-2000f, 2000f), Array.Empty<object>()));
			PowersOffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("Powers", "OffsetY", 0f, new ConfigDescription("Extra nudge for the Passive Powers icons. Positive moves up.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-2000f, 2000f), Array.Empty<object>()));
			CollapseDrawerPreview = ((BaseUnityPlugin)this).Config.Bind<bool>("Hover", "CollapseItemDrawerStacks", true, "When hovering a Grillspett Item Drawer, show one preview slot for the stored item instead of every stack.");
			ShowWorldHealthNumbers = ((BaseUnityPlugin)this).Config.Bind<bool>("WorldHud", "ShowHealthNumbers", true, "Show current/max health just above creature and player health bars.");
			AlwaysShowStamina = ((BaseUnityPlugin)this).Config.Bind<bool>("Vitals", "AlwaysShowStamina", false, "Keep the stamina bar visible when it is full. Off leaves SeneaL UI's normal fade.");
			AlwaysShowEitr = ((BaseUnityPlugin)this).Config.Bind<bool>("Vitals", "AlwaysShowEitr", false, "Keep the eitr bar visible when it is full. Off leaves SeneaL UI's normal fade.");
			AlwaysShowAdrenaline = ((BaseUnityPlugin)this).Config.Bind<bool>("Vitals", "AlwaysShowAdrenaline", false, "Keep the adrenaline bar visible when it is empty. Off leaves SeneaL UI's normal fade.");
			SelectionGlow = ((BaseUnityPlugin)this).Config.Bind<float>("Slots", "SelectionGlow", 1.4f, new ConfigDescription("Extra brightness on the frame around the selected hotbar item and equipped gear. 0 leaves SeneaL's soft glow.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f), Array.Empty<object>()));
			ShowEquipCue = ((BaseUnityPlugin)this).Config.Bind<bool>("Slots", "ShowEquipCue", true, "Show a white seconds countdown on the icon while an item is equipping, unequipping, or reloading.");
			HideServerRules = ((BaseUnityPlugin)this).Config.Bind<bool>("Notices", "HideServerRules", true, "Never show SeneaL UI's server-rules window when you enter a world.");
			Harmony val = new Harmony("cjayride.SeneaLHudLayout");
			CompassPin.Apply(val);
			DrawerPreview.Apply(val);
			WorldHealthText.Apply(val);
			SlotCue.Apply(val);
			RulesNotice.Apply(val);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"SeneaL HUD Layout loaded. Offsets apply once you are in a world with SeneaL UI.");
		}

		private void LateUpdate()
		{
			ResourceBars.Apply();
			SlotCue.Tick();
			if (Enabled == null || !Enabled.Value)
			{
				HudLayout.Restore();
			}
			else
			{
				HudLayout.Apply();
			}
		}
	}
	internal static class SlotCue
	{
		private class Tracked
		{
			public object Slot;

			public ItemData Item;
		}

		private const string GlowName = "SeneaLHudLayout_Glow";

		private const string WashName = "SeneaLHudLayout_Equip";

		private const string TimeName = "SeneaLHudLayout_EquipTime";

		private const int EquippedState = 2;

		private static readonly List<Tracked> Slots = new List<Tracked>();

		private static Type _slotType;

		private static FieldInfo _state;

		private static FieldInfo _bg;

		private static FieldInfo _icon;

		private static FieldInfo _actionType;

		private static FieldInfo _actionItem;

		private static FieldInfo _actionDuration;

		private static FieldInfo _actionTime;

		private static FieldInfo _queue;

		private static FieldInfo _root;

		private static FieldInfo _count;

		private static MethodInfo _progress;

		private static FieldInfo _playerGrid;

		private static FieldInfo _containerGrid;

		private static FieldInfo _elements;

		private static Sprite _white;

		private static TMP_FontAsset _font;

		private static Material _fontMat;

		private static readonly List<TextMeshProUGUI> Labels = new List<TextMeshProUGUI>();

		private static ItemData _trackedItem;

		private static float _trackedEnd;

		private static Canvas _overlay;

		private static TextMeshProUGUI _overlayText;

		private static bool _ready;

		private static bool _logged;

		public static void Apply(Harmony harmony)
		{
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Expected O, but got Unknown
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Expected O, but got Unknown
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Expected O, but got Unknown
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Expected O, but got Unknown
			_slotType = AccessTools.TypeByName("SeneaLUI.Components.Slot");
			if (!(_slotType == null))
			{
				_state = AccessTools.Field(_slotType, "_state");
				_bg = AccessTools.Field(_slotType, "_bg");
				_icon = AccessTools.Field(_slotType, "_icon");
				_root = AccessTools.Field(_slotType, "Root");
				_count = AccessTools.Field(_slotType, "_count");
				MethodInfo methodInfo = AccessTools.Method(_slotType, "Refresh", (Type[])null, (Type[])null);
				MethodInfo methodInfo2 = AccessTools.Method(_slotType, "Set", new Type[1] { typeof(ItemData) }, (Type[])null);
				if (methodInfo != null)
				{
					harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(SlotCue), "AfterRefresh", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
				}
				if (methodInfo2 != null)
				{
					harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(SlotCue), "AfterSet", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
				}
				MethodInfo methodInfo3 = AccessTools.Method(typeof(Player), "QueueEquipAction", (Type[])null, (Type[])null);
				MethodInfo methodInfo4 = AccessTools.Method(typeof(Player), "QueueUnequipAction", (Type[])null, (Type[])null);
				if (methodInfo3 != null)
				{
					harmony.Patch((MethodBase)methodInfo3, (HarmonyMethod)null, new HarmonyMethod(typeof(SlotCue), "AfterQueued", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
				}
				if (methodInfo4 != null)
				{
					harmony.Patch((MethodBase)methodInfo4, (HarmonyMethod)null, new HarmonyMethod(typeof(SlotCue), "AfterQueued", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
				}
				Type type = AccessTools.Inner(typeof(Player), "MinorActionData");
				_actionType = AccessTools.Field(type, "m_type");
				_actionItem = AccessTools.Field(type, "m_item");
				_actionDuration = AccessTools.Field(type, "m_duration");
				_actionTime = AccessTools.Field(type, "m_time");
				_queue = AccessTools.Field(typeof(Player), "m_actionQueue");
				_progress = AccessTools.Method(typeof(Player), "GetActionProgress", new Type[3]
				{
					typeof(string).MakeByRefType(),
					typeof(float).MakeByRefType(),
					type.MakeByRefType()
				}, (Type[])null);
				_playerGrid = AccessTools.Field(typeof(InventoryGui), "m_playerGrid");
				_containerGrid = AccessTools.Field(typeof(InventoryGui), "m_containerGrid");
				_elements = AccessTools.Field(typeof(InventoryGrid), "m_elements");
			}
		}

		public static void Tick()
		{
			if (Ready())
			{
				ItemData item = null;
				int kind = -1;
				float left = 0f;
				if (SeneaLHudLayoutPlugin.ShowEquipCue != null && SeneaLHudLayoutPlugin.ShowEquipCue.Value && (Object)(object)Player.m_localPlayer != (Object)null)
				{
					TryAction(Player.m_localPlayer, out item, out kind, out left);
				}
				if ((item == null || left <= 0.05f) && _trackedItem != null && Time.time < _trackedEnd)
				{
					item = _trackedItem;
					left = _trackedEnd - Time.time;
				}
				if (item == null || left <= 0.05f)
				{
					_trackedItem = null;
				}
				PlaceOverlay(item, left);
			}
		}

		private static void AfterQueued(ItemData item)
		{
			if (item != null && item.m_shared != null)
			{
				_trackedItem = item;
				_trackedEnd = Time.time + Mathf.Max(0.2f, item.m_shared.m_equipDuration);
			}
		}

		private static void AfterSet(object __instance, ItemData item)
		{
			if (__instance == null)
			{
				return;
			}
			for (int i = 0; i < Slots.Count; i++)
			{
				if (Slots[i].Slot == __instance)
				{
					Slots[i].Item = item;
					return;
				}
			}
			Slots.Add(new Tracked
			{
				Slot = __instance,
				Item = item
			});
		}

		private static void AfterRefresh(object __instance)
		{
			//IL_00ea: 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_0122: 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_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			if (__instance == null || _state == null || _bg == null)
			{
				return;
			}
			object? value = _bg.GetValue(__instance);
			Image val = (Image)((value is Image) ? value : null);
			if (Object.op_Implicit((Object)(object)val))
			{
				int num = ((_state.GetValue(__instance) is int num2) ? num2 : 0);
				float num3 = ((SeneaLHudLayoutPlugin.SelectionGlow == null) ? 0f : SeneaLHudLayoutPlugin.SelectionGlow.Value);
				bool flag = num == 2 && num3 > 0.01f;
				Image val2 = EnsureImage(((Component)val).transform.parent, "SeneaLHudLayout_Glow", ((Graphic)val).rectTransform);
				((Component)val2).gameObject.SetActive(flag);
				if (flag)
				{
					val2.sprite = val.sprite;
					val2.type = (Type)0;
					((Graphic)val2).color = new Color(0.28f, 0.62f, 1f, Mathf.Clamp01(0.4f + num3 * 0.35f));
					RectTransform rectTransform = ((Graphic)val2).rectTransform;
					float num4 = 1f + num3 * 1.5f;
					rectTransform.anchoredPosition = ((Graphic)val).rectTransform.anchoredPosition;
					rectTransform.sizeDelta = ((Graphic)val).rectTransform.sizeDelta + new Vector2(num4, num4) * 2f;
					((Transform)rectTransform).SetSiblingIndex(((Component)val).transform.GetSiblingIndex() + 1);
				}
			}
		}

		private static void PlaceOverlay(ItemData item, float left)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			int num = Mathf.CeilToInt(left);
			if (item == null || num < 1)
			{
				if (Object.op_Implicit((Object)(object)_overlayText))
				{
					((Component)_overlayText).gameObject.SetActive(false);
				}
				return;
			}
			RememberFont();
			EnsureOverlay();
			((Component)_overlayText).gameObject.SetActive(true);
			((TMP_Text)_overlayText).text = num.ToString();
			((Graphic)_overlayText).color = Color.white;
			if ((Object)(object)_font != (Object)null)
			{
				((TMP_Text)_overlayText).font = _font;
				if ((Object)(object)_fontMat != (Object)null)
				{
					((TMP_Text)_overlayText).fontSharedMaterial = _fontMat;
				}
			}
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor((float)Screen.width * 0.5f, (float)Screen.height * 0.5f);
			Image val2 = FindIcon(item.GetIcon());
			if (Object.op_Implicit((Object)(object)val2))
			{
				val = ScreenOf(((Graphic)val2).rectTransform);
			}
			RectTransform rectTransform = ((TMP_Text)_overlayText).rectTransform;
			rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
			rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
			rectTransform.pivot = new Vector2(0.5f, 0.5f);
			rectTransform.sizeDelta = new Vector2(64f, 40f);
			rectTransform.anchoredPosition = val - new Vector2((float)Screen.width * 0.5f, (float)Screen.height * 0.5f);
		}

		private static Image FindIcon(Sprite sprite)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)sprite))
			{
				return null;
			}
			Image result = null;
			float num = 0f;
			Image[] array = Object.FindObjectsOfType<Image>();
			foreach (Image val in array)
			{
				if (Object.op_Implicit((Object)(object)val) && ((Behaviour)val).isActiveAndEnabled && !((Object)(object)val.sprite != (Object)(object)sprite) && !((Component)val).transform.IsChildOf(((Component)_overlay).transform))
				{
					Rect rect = ((Graphic)val).rectTransform.rect;
					float num2 = ((Rect)(ref rect)).width * ((Rect)(ref rect)).height;
					if (!(num2 < 576f) && !(num2 <= num))
					{
						result = val;
						num = num2;
					}
				}
			}
			return result;
		}

		private static Vector2 ScreenOf(RectTransform rect)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			rect.GetWorldCorners(array);
			Vector3 val = (array[0] + array[2]) * 0.5f;
			Camera val2 = null;
			Canvas componentInParent = ((Component)rect).GetComponentInParent<Canvas>();
			if ((Object)(object)componentInParent != (Object)null && (int)componentInParent.renderMode != 0)
			{
				val2 = (((Object)(object)componentInParent.worldCamera != (Object)null) ? componentInParent.worldCamera : Camera.main);
			}
			return RectTransformUtility.WorldToScreenPoint(val2, val);
		}

		private static void EnsureOverlay()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)_overlayText))
			{
				GameObject val = new GameObject("SeneaLHudLayout_EquipCountdown");
				Object.DontDestroyOnLoad((Object)(object)val);
				_overlay = val.AddComponent<Canvas>();
				_overlay.renderMode = (RenderMode)0;
				_overlay.sortingOrder = 5000;
				val.AddComponent<CanvasScaler>().uiScaleMode = (ScaleMode)0;
				GameObject val2 = new GameObject("Time", new Type[1] { typeof(RectTransform) });
				val2.transform.SetParent(val.transform, false);
				_overlayText = val2.AddComponent<TextMeshProUGUI>();
				((TMP_Text)_overlayText).alignment = (TextAlignmentOptions)514;
				((TMP_Text)_overlayText).fontSize = 28f;
				((TMP_Text)_overlayText).fontStyle = (FontStyles)1;
				((Graphic)_overlayText).color = Color.white;
				((Graphic)_overlayText).raycastTarget = false;
				((TMP_Text)_overlayText).textWrappingMode = (TextWrappingModes)0;
				((TMP_Text)_overlayText).overflowMode = (TextOverflowModes)0;
			}
		}

		private static void ShowOnIcons(ItemData item, float left)
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			int num = Mathf.CeilToInt(left);
			Sprite val = ((item != null) ? item.GetIcon() : null);
			HashSet<Transform> hashSet = new HashSet<Transform>();
			if ((Object)(object)val != (Object)null && num >= 1)
			{
				RememberFont();
				Image[] array = Object.FindObjectsOfType<Image>();
				foreach (Image val2 in array)
				{
					if (Object.op_Implicit((Object)(object)val2) && ((Behaviour)val2).isActiveAndEnabled && !((Object)(object)val2.sprite != (Object)(object)val) && !(((Object)val2).name == "SeneaLHudLayout_Glow") && !(((Object)val2).name == "SeneaLHudLayout_Equip"))
					{
						Rect rect = ((Graphic)val2).rectTransform.rect;
						if (!(((Rect)(ref rect)).width < 24f) && !(((Rect)(ref rect)).height < 24f))
						{
							ShowSeconds(EnsureTime(((Component)val2).transform), num);
							hashSet.Add(((Component)val2).transform);
						}
					}
				}
			}
			for (int num2 = Labels.Count - 1; num2 >= 0; num2--)
			{
				TextMeshProUGUI val3 = Labels[num2];
				if (!Object.op_Implicit((Object)(object)val3))
				{
					Labels.RemoveAt(num2);
				}
				else if (!hashSet.Contains(((TMP_Text)val3).transform.parent))
				{
					((Component)val3).gameObject.SetActive(false);
				}
			}
		}

		private static void RememberFont()
		{
			if (!((Object)(object)_font != (Object)null))
			{
				TextMeshProUGUI val = Object.FindObjectOfType<TextMeshProUGUI>();
				if ((Object)(object)val != (Object)null && (Object)(object)((TMP_Text)val).font != (Object)null)
				{
					_font = ((TMP_Text)val).font;
					_fontMat = ((TMP_Text)val).fontSharedMaterial;
				}
			}
		}

		private static void PaintAction(object slot, bool on, int kind, float left)
		{
			RectTransform val = (RectTransform)((_root != null) ? /*isinst with value type is only supported in some contexts*/: null);
			if (Object.op_Implicit((Object)(object)val))
			{
				HideWash((Transform)(object)val);
				TextMeshProUGUI val2 = EnsureTime((Transform)(object)val);
				if (!on)
				{
					((Component)val2).gameObject.SetActive(false);
					return;
				}
				TMP_Text fontFrom = (TMP_Text)((_count != null) ? /*isinst with value type is only supported in some contexts*/: null);
				ShowSeconds(val2, left, fontFrom);
			}
		}

		private static void TryAction(Player player, out ItemData item, out int kind, out float left)
		{
			item = null;
			kind = -1;
			left = 0f;
			if (_progress == null)
			{
				return;
			}
			IList list = ((_queue != null) ? (_queue.GetValue(player) as IList) : null);
			if (list != null && list.Count != 0)
			{
				object obj = list[0];
				if (obj != null && !(_actionItem == null))
				{
					object? value = _actionItem.GetValue(obj);
					item = (ItemData)((value is ItemData) ? value : null);
					kind = ((_actionType != null && _actionType.GetValue(obj) != null) ? Convert.ToInt32(_actionType.GetValue(obj)) : 0);
					float num = ((_actionDuration != null && _actionDuration.GetValue(obj) is float num2) ? num2 : 0f);
					float num3 = ((_actionTime != null && _actionTime.GetValue(obj) is float num4) ? num4 : 0f);
					left = Mathf.Max(0f, num - num3);
				}
			}
		}

		private static void PaintGrids(ItemData busy, int kind, float left)
		{
			InventoryGui instance = InventoryGui.instance;
			if (Object.op_Implicit((Object)(object)instance))
			{
				PaintGrid((InventoryGrid)((_playerGrid != null) ? /*isinst with value type is only supported in some contexts*/: null), busy, kind, left);
				PaintGrid((InventoryGrid)((_containerGrid != null) ? /*isinst with value type is only supported in some contexts*/: null), busy, kind, left);
			}
		}

		private static void PaintGrid(InventoryGrid grid, ItemData busy, int kind, float left)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			IList list = ((_elements != null) ? (_elements.GetValue(grid) as IList) : null);
			if (!Object.op_Implicit((Object)(object)grid) || list == null)
			{
				return;
			}
			Inventory inventory = grid.GetInventory();
			for (int i = 0; i < list.Count; i++)
			{
				object? obj = list[i];
				InventoryElement val = (InventoryElement)((obj is InventoryElement) ? obj : null);
				if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val.m_icon))
				{
					continue;
				}
				ItemData val2 = ((inventory != null) ? inventory.GetItemAt(val.Position.x, val.Position.y) : null);
				bool flag = busy != null && val2 != null && val2 == busy;
				if (!flag && val2 != null && (Object)(object)Player.m_localPlayer != (Object)null && Player.m_localPlayer.IsEquipActionQueued(val2))
				{
					flag = true;
				}
				Transform transform = ((Component)val).transform;
				RectTransform val3 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
				HideWash((Transform)(object)val3);
				Transform val4 = (((Object)(object)val3 != (Object)null) ? ((Transform)val3).Find("SeneaLHudLayout_EquipTime") : null);
				if (!flag)
				{
					if (Object.op_Implicit((Object)(object)val4) && ((Component)val4).gameObject.activeSelf)
					{
						((Component)val4).gameObject.SetActive(false);
					}
				}
				else if (Object.op_Implicit((Object)(object)val3))
				{
					ShowSeconds(EnsureTime((Transform)(object)val3), left, val.m_amount);
				}
			}
		}

		private static void HideWash(Transform parent)
		{
			Transform val = (((Object)(object)parent != (Object)null) ? parent.Find("SeneaLHudLayout_Equip") : null);
			if (Object.op_Implicit((Object)(object)val) && ((Component)val).gameObject.activeSelf)
			{
				((Component)val).gameObject.SetActive(false);
			}
		}

		private static void ShowSeconds(TextMeshProUGUI time, int seconds)
		{
			ShowSeconds(time, seconds, null);
		}

		private static void ShowSeconds(TextMeshProUGUI time, float left, TMP_Text fontFrom)
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			int num = Mathf.CeilToInt(left);
			bool flag = num >= 1;
			((Component)time).gameObject.SetActive(flag);
			if (!flag)
			{
				return;
			}
			if ((Object)(object)fontFrom != (Object)null && (Object)(object)fontFrom.font != (Object)null)
			{
				((TMP_Text)time).font = fontFrom.font;
				if ((Object)(object)fontFrom.fontSharedMaterial != (Object)null)
				{
					((TMP_Text)time).fontSharedMaterial = fontFrom.fontSharedMaterial;
				}
			}
			else if ((Object)(object)_font != (Object)null)
			{
				((TMP_Text)time).font = _font;
				if ((Object)(object)_fontMat != (Object)null)
				{
					((TMP_Text)time).fontSharedMaterial = _fontMat;
				}
			}
			((TMP_Text)time).text = num.ToString();
			((Graphic)time).color = Color.white;
			((TMP_Text)time).fontSize = 22f;
			((TMP_Text)time).fontStyle = (FontStyles)1;
			((TMP_Text)time).alignment = (TextAlignmentOptions)514;
			RectTransform rectTransform = ((TMP_Text)time).rectTransform;
			rectTransform.anchorMin = Vector2.zero;
			rectTransform.anchorMax = Vector2.one;
			rectTransform.offsetMin = Vector2.zero;
			rectTransform.offsetMax = Vector2.zero;
			((Transform)rectTransform).localScale = Vector3.one;
			((Transform)rectTransform).SetAsLastSibling();
		}

		private static void CopyRect(RectTransform rt, RectTransform match)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			rt.anchorMin = match.anchorMin;
			rt.anchorMax = match.anchorMax;
			rt.pivot = match.pivot;
			rt.offsetMin = match.offsetMin;
			rt.offsetMax = match.offsetMax;
			((Transform)rt).localScale = Vector3.one;
			((Transform)rt).localRotation = Quaternion.identity;
		}

		private static TextMeshProUGUI EnsureTime(Transform parent)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			Transform val = parent.Find("SeneaLHudLayout_EquipTime");
			TextMeshProUGUI val2 = (Object.op_Implicit((Object)(object)val) ? ((Component)val).GetComponent<TextMeshProUGUI>() : null);
			if (!Object.op_Implicit((Object)(object)val2))
			{
				GameObject val3 = new GameObject("SeneaLHudLayout_EquipTime", new Type[1] { typeof(RectTransform) });
				val3.transform.SetParent(parent, false);
				val2 = val3.AddComponent<TextMeshProUGUI>();
				((TMP_Text)val2).alignment = (TextAlignmentOptions)514;
				((TMP_Text)val2).fontSize = 22f;
				((TMP_Text)val2).fontStyle = (FontStyles)1;
				((Graphic)val2).raycastTarget = false;
				((TMP_Text)val2).textWrappingMode = (TextWrappingModes)0;
				((TMP_Text)val2).overflowMode = (TextOverflowModes)0;
				((Graphic)val2).color = Color.white;
			}
			if (!Labels.Contains(val2))
			{
				Labels.Add(val2);
			}
			return val2;
		}

		private static Image EnsureImage(Transform parent, string name, RectTransform match)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			Transform val = parent.Find(name);
			Image val2 = (Object.op_Implicit((Object)(object)val) ? ((Component)val).GetComponent<Image>() : null);
			if (!Object.op_Implicit((Object)(object)val2))
			{
				GameObject val3 = new GameObject(name, new Type[1] { typeof(RectTransform) });
				val3.transform.SetParent(parent, false);
				val2 = val3.AddComponent<Image>();
				((Graphic)val2).raycastTarget = false;
				val2.sprite = White();
			}
			RectTransform rectTransform = ((Graphic)val2).rectTransform;
			rectTransform.anchorMin = match.anchorMin;
			rectTransform.anchorMax = match.anchorMax;
			rectTransform.pivot = match.pivot;
			((Transform)rectTransform).localScale = Vector3.one;
			((Transform)rectTransform).localRotation = Quaternion.identity;
			return val2;
		}

		private static Sprite White()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_white != (Object)null)
			{
				return _white;
			}
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			Color[] pixels = (Color[])(object)new Color[4]
			{
				Color.white,
				Color.white,
				Color.white,
				Color.white
			};
			val.SetPixels(pixels);
			val.Apply();
			_white = Sprite.Create(val, new Rect(0f, 0f, 2f, 2f), new Vector2(0.5f, 0.5f), 100f);
			return _white;
		}

		private static bool Ready()
		{
			if (_ready)
			{
				return _slotType != null;
			}
			_ready = true;
			if (_slotType == null && !_logged)
			{
				_logged = true;
				Debug.Log((object)"[SeneaL HUD Layout] Slot cues skipped. SeneaL UI slots were not found.");
			}
			return _slotType != null;
		}
	}
	internal static class WorldHealthText
	{
		private const string LabelName = "SeneaLHudLayout_Health";

		private static readonly FieldInfo HudsField = AccessTools.Field(typeof(EnemyHud), "m_huds");

		private static readonly FieldInfo CharacterField = AccessTools.Field(AccessTools.Inner(typeof(EnemyHud), "HudData"), "m_character");

		private static readonly FieldInfo GuiField = AccessTools.Field(AccessTools.Inner(typeof(EnemyHud), "HudData"), "m_gui");

		private static readonly FieldInfo HealthTextField = AccessTools.Field(AccessTools.Inner(typeof(EnemyHud), "HudData"), "m_healthText");

		private static readonly FieldInfo NameField = AccessTools.Field(AccessTools.Inner(typeof(EnemyHud), "HudData"), "m_name");

		public static void Apply(Harmony harmony)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			MethodInfo methodInfo = AccessTools.Method(typeof(EnemyHud), "UpdateHuds", (Type[])null, (Type[])null);
			if (methodInfo != null)
			{
				harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(WorldHealthText), "AfterUpdateHuds", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}

		private static void AfterUpdateHuds(EnemyHud __instance)
		{
			if ((Object)(object)__instance == (Object)null || HudsField == null)
			{
				return;
			}
			bool flag = SeneaLHudLayoutPlugin.ShowWorldHealthNumbers != null && SeneaLHudLayoutPlugin.ShowWorldHealthNumbers.Value;
			if (!(HudsField.GetValue(__instance) is IDictionary dictionary))
			{
				return;
			}
			foreach (DictionaryEntry item in dictionary)
			{
				object value = item.Value;
				if (value == null)
				{
					continue;
				}
				object? obj = CharacterField?.GetValue(value);
				Character val = (Character)((obj is Character) ? obj : null);
				object? obj2 = GuiField?.GetValue(value);
				GameObject val2 = (GameObject)((obj2 is GameObject) ? obj2 : null);
				if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2))
				{
					continue;
				}
				if (!flag)
				{
					Transform val3 = val2.transform.Find("SeneaLHudLayout_Health");
					if (!Object.op_Implicit((Object)(object)val3))
					{
						Transform val4 = val2.transform.Find("Health");
						val3 = (Object.op_Implicit((Object)(object)val4) ? val4.Find("SeneaLHudLayout_Health") : null);
					}
					if (Object.op_Implicit((Object)(object)val3) && ((Component)val3).gameObject.activeSelf)
					{
						((Component)val3).gameObject.SetActive(false);
					}
					Transform val5 = val2.transform.Find("Health/HealthText");
					if (Object.op_Implicit((Object)(object)val5) && !((Component)val5).gameObject.activeSelf)
					{
						((Component)val5).gameObject.SetActive(true);
					}
					continue;
				}
				object? obj3 = HealthTextField?.GetValue(value);
				TMP_Text val6 = (TMP_Text)((obj3 is TMP_Text) ? obj3 : null);
				if (!Object.op_Implicit((Object)(object)val6))
				{
					Transform transform = val2.transform;
					object? obj4 = NameField?.GetValue(value);
					val6 = EnsureLabel(transform, (TMP_Text)((obj4 is TMP_Text) ? obj4 : null));
					HealthTextField?.SetValue(value, val6);
				}
				Transform val7 = val2.transform.Find("Health/HealthText");
				if (Object.op_Implicit((Object)(object)val7) && (Object)(object)((Component)val7).gameObject != (Object)(object)((Component)val6).gameObject)
				{
					((Component)val7).gameObject.SetActive(false);
				}
				int num = Mathf.CeilToInt(val.GetHealth());
				int num2 = Mathf.Max(1, Mathf.CeilToInt(val.GetMaxHealth()));
				val6.text = num + "/" + num2;
				PlaceAbove(val6, val2.transform.Find("Health"));
				((Component)val6).gameObject.SetActive(true);
			}
		}

		private static TMP_Text EnsureLabel(Transform gui, TMP_Text name)
		{
			//IL_0056: 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_0103: Unknown result type (might be due to invalid IL or missing references)
			Transform val = gui.Find("Health");
			if (!Object.op_Implicit((Object)(object)val))
			{
				return null;
			}
			Transform val2 = gui.Find("SeneaLHudLayout_Health");
			if (!Object.op_Implicit((Object)(object)val2))
			{
				val2 = val.Find("SeneaLHudLayout_Health");
			}
			TextMeshProUGUI val3 = (Object.op_Implicit((Object)(object)val2) ? ((Component)val2).GetComponent<TextMeshProUGUI>() : null);
			if ((Object)(object)val3 == (Object)null)
			{
				GameObject val4 = new GameObject("SeneaLHudLayout_Health");
				val4.transform.SetParent(gui, false);
				val3 = val4.AddComponent<TextMeshProUGUI>();
				((Graphic)val3).raycastTarget = false;
				((TMP_Text)val3).alignment = (TextAlignmentOptions)514;
				((TMP_Text)val3).textWrappingMode = (TextWrappingModes)0;
				((TMP_Text)val3).overflowMode = (TextOverflowModes)0;
			}
			if ((Object)(object)name != (Object)null && (Object)(object)name.font != (Object)null)
			{
				((TMP_Text)val3).font = name.font;
				if ((Object)(object)name.fontSharedMaterial != (Object)null)
				{
					((TMP_Text)val3).fontSharedMaterial = name.fontSharedMaterial;
				}
			}
			else if ((Object)(object)((TMP_Text)val3).font == (Object)null && (Object)(object)TMP_Settings.defaultFontAsset != (Object)null)
			{
				((TMP_Text)val3).font = TMP_Settings.defaultFontAsset;
			}
			((Graphic)val3).color = new Color(0.96f, 0.93f, 0.86f);
			((TMP_Text)val3).fontSize = (((Object)(object)name != (Object)null) ? Mathf.Max(12f, name.fontSize * 0.8f) : 14f);
			return (TMP_Text)(object)val3;
		}

		private static void PlaceAbove(TMP_Text label, Transform health)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: 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_0098: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)health))
			{
				RectTransform val = (RectTransform)(object)((health is RectTransform) ? health : null);
				RectTransform rectTransform = label.rectTransform;
				Transform val2 = (((Object)(object)val != (Object)null) ? ((Transform)val).parent : health.parent);
				if (Object.op_Implicit((Object)(object)val2) && (Object)(object)((Transform)rectTransform).parent != (Object)(object)val2)
				{
					((Transform)rectTransform).SetParent(val2, false);
				}
				rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
				rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
				rectTransform.pivot = new Vector2(0.5f, 0f);
				((Transform)rectTransform).localScale = Vector3.one;
				((Transform)rectTransform).localRotation = Quaternion.identity;
				if ((Object)(object)val != (Object)null)
				{
					float y = val.anchoredPosition.y;
					Rect rect = val.rect;
					float num = y + ((Rect)(ref rect)).height * (1f - val.pivot.y);
					rectTransform.anchoredPosition = new Vector2(val.anchoredPosition.x, num + 1f);
					rect = val.rect;
					rectTransform.sizeDelta = new Vector2(Mathf.Max(64f, ((Rect)(ref rect)).width + 8f), 18f);
				}
				((Transform)rectTransform).SetAsLastSibling();
			}
		}
	}
}