Decompiled source of CompactStatusSquares v0.1.4

plugins\cjayride-CompactStatusSquares\CompactStatusSquares.dll

Decompiled 2 days 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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.EventSystems;
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("0.1.4")]
[assembly: AssemblyInformationalVersion("0.1.4+eb107badc08bdad57f26034544188b2d8b14614b")]
[assembly: AssemblyVersion("0.1.4.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 CompactStatusSquares
{
	[BepInPlugin("cjayride.CompactStatusSquares", "Compact Status Squares", "0.1.4")]
	[BepInProcess("valheim.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "cjayride.CompactStatusSquares";

		public const string Name = "Compact Status Squares";

		public const string Version = "0.1.4";

		public static ManualLogSource Log;

		public static ConfigEntry<bool> EnabledIcons;

		public static ConfigEntry<ScreenCorner> Corner;

		public static ConfigEntry<float> OffsetX;

		public static ConfigEntry<float> OffsetY;

		public static ConfigEntry<float> IconSize;

		public static ConfigEntry<int> Columns;

		public static ConfigEntry<float> Spacing;

		public static ConfigEntry<bool> ShowTimer;

		public static ConfigEntry<float> TextScale;

		public static ConfigEntry<StatusNameSide> ShowName;

		public static ConfigEntry<bool> UseVanillaFont;

		public static ConfigEntry<bool> CrispPixels;

		public static ConfigEntry<Color> Background;

		private readonly Harmony _harmony = new Harmony("cjayride.CompactStatusSquares");

		public static Plugin Instance { get; private set; }

		public void Awake()
		{
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Expected O, but got Unknown
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Expected O, but got Unknown
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Expected O, but got Unknown
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Expected O, but got Unknown
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			EnabledIcons = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Draw the small status squares and keep SeneaL UI from drawing its status pills.");
			Corner = ((BaseUnityPlugin)this).Config.Bind<ScreenCorner>("Layout", "Corner", ScreenCorner.TopRight, "Screen corner the first icon sits in. Extra icons flow away from that corner.");
			OffsetX = ((BaseUnityPlugin)this).Config.Bind<float>("Layout", "OffsetX", -18f, "Horizontal distance from the chosen corner, in pixels. Negative moves left.");
			OffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("Layout", "OffsetY", -18f, "Vertical distance from the chosen corner, in pixels. Negative moves down.");
			IconSize = ((BaseUnityPlugin)this).Config.Bind<float>("Layout", "IconSize", 36.577f, new ConfigDescription("Width and height of each square.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(16f, 96f), Array.Empty<object>()));
			Columns = ((BaseUnityPlugin)this).Config.Bind<int>("Layout", "Columns", 1, new ConfigDescription("Icons per row before wrapping. 1 is a vertical stack.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 16), Array.Empty<object>()));
			Spacing = ((BaseUnityPlugin)this).Config.Bind<float>("Layout", "Spacing", 4f, new ConfigDescription("Gap between squares.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 32f), Array.Empty<object>()));
			ShowTimer = ((BaseUnityPlugin)this).Config.Bind<bool>("Layout", "ShowTimer", true, "Draw the remaining time or comfort number on the square.");
			TextScale = ((BaseUnityPlugin)this).Config.Bind<float>("Layout", "TextScale", 1f, new ConfigDescription("Size of timers, comfort numbers, and optional status names. 1 is the original size.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.4f, 3f), Array.Empty<object>()));
			ShowName = ((BaseUnityPlugin)this).Config.Bind<StatusNameSide>("Layout", "ShowName", StatusNameSide.Off, "Draw the localized status name beside the icon. Off keeps the square-only layout.");
			UseVanillaFont = ((BaseUnityPlugin)this).Config.Bind<bool>("Layout", "UseVanillaFont", false, "Use Valheim's Norse font for timers and names. Off uses the compact UI font.");
			CrispPixels = ((BaseUnityPlugin)this).Config.Bind<bool>("Layout", "CrispPixels", true, "Point-filter the vanilla icon art so the squares stay sharp instead of soft and blurry.");
			Background = ((BaseUnityPlugin)this).Config.Bind<Color>("Layout", "Background", new Color(2f / 51f, 3f / 85f, 0.03137255f, 0.81960785f), "Color of the square behind each icon.");
			_harmony.PatchAll(typeof(VanillaStatusListGuard).Assembly);
			SenealStatusGuard.Patch(_harmony);
			((Component)this).gameObject.AddComponent<StatusSquaresHud>();
			Log.LogInfo((object)"Compact Status Squares 0.1.4 loaded.");
		}

		public void OnDestroy()
		{
			_harmony.UnpatchAll("cjayride.CompactStatusSquares");
			StatusSquaresHud.RestoreFilteredTextures();
		}
	}
	public enum StatusNameSide
	{
		Off,
		Left,
		Right
	}
	public enum ScreenCorner
	{
		TopRight,
		TopLeft,
		BottomRight,
		BottomLeft
	}
	[HarmonyPatch(typeof(Hud), "UpdateStatusEffects")]
	internal static class VanillaStatusListGuard
	{
		private static bool Prefix()
		{
			return !Plugin.EnabledIcons.Value;
		}
	}
	internal static class SenealStatusGuard
	{
		private static FieldInfo _statusField;

		private static FieldInfo _boxField;

		public static void Patch(Harmony harmony)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			Type type = AccessTools.TypeByName("SeneaLUI.Hud.StatusEffectsView");
			MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, "Tick", (Type[])null, (Type[])null));
			if (methodInfo == null)
			{
				Plugin.Log.LogInfo((object)"SeneaL UI status panel was not found. Squares will still replace the vanilla list.");
				return;
			}
			harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(SenealStatusGuard), "BlockTick", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			_statusField = AccessTools.Field(AccessTools.TypeByName("SeneaLUI.Hud.HudRoot"), "_status");
			Plugin.Log.LogInfo((object)"SeneaL UI status pills blocked. Compact Status Squares owns that slot.");
		}

		private static bool BlockTick()
		{
			return !Plugin.EnabledIcons.Value;
		}

		public static void HideLeftoverPanel()
		{
			if (!Plugin.EnabledIcons.Value || _statusField == null || (Object)(object)Hud.instance == (Object)null)
			{
				return;
			}
			object value = _statusField.GetValue(null);
			if (value == null)
			{
				return;
			}
			Object val = (Object)((value is Object) ? value : null);
			if (val != null && !Object.op_Implicit(val))
			{
				return;
			}
			if (_boxField == null)
			{
				_boxField = AccessTools.Field(value.GetType(), "_box");
			}
			object? obj = _boxField?.GetValue(value);
			Component val2 = (Component)((obj is Component) ? obj : null);
			if (Object.op_Implicit((Object)(object)val2))
			{
				GameObject gameObject = val2.gameObject;
				if ((Object)(object)gameObject != (Object)null && gameObject.activeSelf)
				{
					gameObject.SetActive(false);
				}
			}
		}
	}
	public class StatusSquaresHud : MonoBehaviour
	{
		public class Slot : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
		{
			public StatusSquaresHud Hud;

			public RectTransform Root;

			public Image Back;

			public Image Icon;

			public Text Timer;

			public Text Name;

			public StatusEffect Effect;

			public void OnPointerEnter(PointerEventData eventData)
			{
				Hud.SetHover(this);
			}

			public void OnPointerExit(PointerEventData eventData)
			{
				if ((Object)(object)Hud != (Object)null)
				{
					Hud.ClearHover(this);
				}
			}
		}

		private static readonly Dictionary<Texture, FilterMode> Filtered = new Dictionary<Texture, FilterMode>();

		private static Font _font;

		private static Font _norse;

		private readonly List<StatusEffect> _effects = new List<StatusEffect>(16);

		private readonly List<Slot> _slots = new List<Slot>(16);

		private Canvas _canvas;

		private RectTransform _root;

		private RectTransform _tipRoot;

		private Text _tip;

		private Sprite _pixel;

		private bool _loggedDraw;

		private bool _hidVanilla;

		private bool _vanillaWasActive;

		private Slot _hover;

		private void Awake()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			_pixel = Pixel();
			_font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
			if ((Object)(object)_font == (Object)null)
			{
				_font = Resources.GetBuiltinResource<Font>("Arial.ttf");
			}
			GameObject val = new GameObject("CompactStatusSquares");
			val.transform.SetParent(((Component)this).transform, false);
			_canvas = val.AddComponent<Canvas>();
			_canvas.renderMode = (RenderMode)0;
			_canvas.sortingOrder = 450;
			CanvasScaler obj = val.AddComponent<CanvasScaler>();
			obj.uiScaleMode = (ScaleMode)1;
			obj.referenceResolution = new Vector2(1920f, 1080f);
			obj.matchWidthOrHeight = 0.5f;
			val.AddComponent<GraphicRaycaster>();
			_root = Stretch(val.transform, "icons");
			_tipRoot = MakeTip();
		}

		private void LateUpdate()
		{
			if (!((Object)(object)Hud.instance == (Object)null))
			{
				SenealStatusGuard.HideLeftoverPanel();
				ApplyVanillaRoot();
				Player localPlayer = Player.m_localPlayer;
				if (!Plugin.EnabledIcons.Value || !((Object)(object)localPlayer != (Object)null) || !((Object)(object)Hud.instance != (Object)null) || !Hud.instance.IsVisible() || MapOpen() || InventoryOpen() || MenuOpen() || ConsoleOpen() || ((Character)localPlayer).IsDead())
				{
					((Behaviour)_canvas).enabled = false;
					SetHover(null);
					return;
				}
				((Behaviour)_canvas).enabled = true;
				_effects.Clear();
				((Character)localPlayer).GetSEMan().GetHUDStatusEffects(_effects);
				Layout();
			}
		}

		private void Layout()
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			float num2 = Mathf.Clamp(Plugin.IconSize.Value, 16f, 96f);
			int num3 = Mathf.Clamp(Plugin.Columns.Value, 1, 16);
			float num4 = Mathf.Max(0f, Plugin.Spacing.Value);
			float num5 = num2 + num4;
			ScreenCorner value = Plugin.Corner.Value;
			bool flag = value == ScreenCorner.TopRight || value == ScreenCorner.BottomRight;
			bool flag2 = value == ScreenCorner.TopRight || value == ScreenCorner.TopLeft;
			bool flag3 = Mathf.Sin(Time.time * 10f) > 0f;
			Color value2 = Plugin.Background.Value;
			_tip.font = CurrentFont();
			_tip.fontSize = ScaledFont(16f);
			for (int i = 0; i < _effects.Count; i++)
			{
				StatusEffect val = _effects[i];
				if ((Object)(object)val == (Object)null || (Object)(object)val.m_icon == (Object)null)
				{
					continue;
				}
				Slot slot = SlotAt(num);
				((Component)slot.Root).gameObject.SetActive(true);
				slot.Effect = val;
				int num6 = num % num3;
				int num7 = num / num3;
				float x = Plugin.OffsetX.Value + (flag ? ((float)(-num6) * num5) : ((float)num6 * num5));
				float y = Plugin.OffsetY.Value + (flag2 ? ((float)(-num7) * num5) : ((float)num7 * num5));
				Place(slot.Root, value, x, y, num2);
				((Graphic)slot.Back).color = value2;
				if ((Object)(object)slot.Icon.sprite != (Object)(object)val.m_icon)
				{
					slot.Icon.sprite = val.m_icon;
					ApplyFilter(val.m_icon);
				}
				((Graphic)slot.Icon).color = (Color)((val.m_flashIcon && flag3) ? new Color(1f, 0.45f, 0.45f, 1f) : Color.white);
				string iconText = val.GetIconText();
				bool flag4 = Plugin.ShowTimer.Value && !string.IsNullOrEmpty(iconText);
				((Component)slot.Timer).gameObject.SetActive(flag4);
				if (flag4)
				{
					slot.Timer.text = iconText;
				}
				ApplyLabel(slot.Timer, timer: true);
				bool flag5 = Plugin.ShowName.Value != StatusNameSide.Off;
				((Component)slot.Name).gameObject.SetActive(flag5);
				if (flag5)
				{
					string text = val.m_name;
					if (Localization.instance != null)
					{
						text = Localization.instance.Localize(text);
					}
					slot.Name.text = text;
					PlaceName(((Graphic)slot.Name).rectTransform, Plugin.ShowName.Value);
					ApplyLabel(slot.Name, timer: false);
				}
				num++;
			}
			for (int j = num; j < _slots.Count; j++)
			{
				if (((Component)_slots[j].Root).gameObject.activeSelf)
				{
					((Component)_slots[j].Root).gameObject.SetActive(false);
				}
				if ((Object)(object)_hover == (Object)(object)_slots[j])
				{
					SetHover(null);
				}
			}
			if (num > 0 && !_loggedDraw)
			{
				_loggedDraw = true;
				Plugin.Log.LogInfo((object)("Drawing " + num + " status icon" + ((num == 1) ? "" : "s") + "."));
			}
			UpdateTip();
		}

		private void ApplyVanillaRoot()
		{
			Hud instance = Hud.instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.m_statusEffectListRoot == (Object)null)
			{
				return;
			}
			GameObject gameObject = ((Component)instance.m_statusEffectListRoot).gameObject;
			if (Plugin.EnabledIcons.Value)
			{
				if (!_hidVanilla)
				{
					_vanillaWasActive = gameObject.activeSelf;
					_hidVanilla = true;
				}
				if (gameObject.activeSelf)
				{
					gameObject.SetActive(false);
				}
			}
			else if (_hidVanilla)
			{
				gameObject.SetActive(_vanillaWasActive);
				_hidVanilla = false;
			}
		}

		private void UpdateTip()
		{
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: 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_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: 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)
			if ((Object)(object)_hover == (Object)null || !((Component)_hover.Root).gameObject.activeSelf || (Object)(object)_hover.Effect == (Object)null)
			{
				((Component)_tipRoot).gameObject.SetActive(false);
				return;
			}
			StatusEffect effect = _hover.Effect;
			string text = effect.m_name;
			if (Localization.instance != null)
			{
				text = Localization.instance.Localize(text);
			}
			string iconText = effect.GetIconText();
			_tip.text = (string.IsNullOrEmpty(iconText) ? text : (text + "   " + iconText));
			((Component)_tipRoot).gameObject.SetActive(true);
			ScreenCorner value = Plugin.Corner.Value;
			bool flag = value == ScreenCorner.TopRight || value == ScreenCorner.BottomRight;
			RectTransform root = _hover.Root;
			_tipRoot.anchorMin = root.anchorMin;
			_tipRoot.anchorMax = root.anchorMax;
			_tipRoot.pivot = new Vector2(flag ? 1f : 0f, root.pivot.y);
			float num = Mathf.Clamp(Plugin.IconSize.Value, 16f, 96f);
			_tipRoot.anchoredPosition = root.anchoredPosition + new Vector2(flag ? (0f - (num + 8f)) : (num + 8f), 0f);
			_tipRoot.sizeDelta = new Vector2(Mathf.Clamp((float)_tip.text.Length * 9f + 20f, 80f, 460f), 28f);
		}

		public void SetHover(Slot slot)
		{
			_hover = slot;
		}

		public void ClearHover(Slot slot)
		{
			if ((Object)(object)_hover == (Object)(object)slot)
			{
				_hover = null;
			}
		}

		private Slot SlotAt(int index)
		{
			while (_slots.Count <= index)
			{
				_slots.Add(CreateSlot());
			}
			return _slots[index];
		}

		private Slot CreateSlot()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0044: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("square");
			val.transform.SetParent((Transform)(object)_root, false);
			RectTransform root = val.AddComponent<RectTransform>();
			Image val2 = val.AddComponent<Image>();
			val2.sprite = _pixel;
			val2.type = (Type)0;
			((Graphic)val2).color = Plugin.Background.Value;
			GameObject val3 = new GameObject("icon");
			val3.transform.SetParent(val.transform, false);
			RectTransform obj = val3.AddComponent<RectTransform>();
			obj.anchorMin = Vector2.zero;
			obj.anchorMax = Vector2.one;
			obj.offsetMin = new Vector2(3f, 3f);
			obj.offsetMax = new Vector2(-3f, -3f);
			Image val4 = val3.AddComponent<Image>();
			val4.preserveAspect = true;
			((Graphic)val4).raycastTarget = false;
			GameObject val5 = new GameObject("time");
			val5.transform.SetParent(val.transform, false);
			RectTransform obj2 = val5.AddComponent<RectTransform>();
			obj2.anchorMin = new Vector2(0f, 0f);
			obj2.anchorMax = new Vector2(1f, 0f);
			obj2.pivot = new Vector2(0.5f, 0f);
			obj2.sizeDelta = new Vector2(-2f, 14f);
			obj2.anchoredPosition = new Vector2(0f, 1f);
			Text val6 = val5.AddComponent<Text>();
			val6.font = CurrentFont();
			val6.fontSize = 12;
			val6.alignment = (TextAnchor)7;
			((Graphic)val6).color = Color.white;
			val6.horizontalOverflow = (HorizontalWrapMode)1;
			val6.verticalOverflow = (VerticalWrapMode)1;
			((Graphic)val6).raycastTarget = false;
			val6.resizeTextForBestFit = false;
			Outline obj3 = val5.AddComponent<Outline>();
			((Shadow)obj3).effectColor = new Color(0f, 0f, 0f, 0.95f);
			((Shadow)obj3).effectDistance = new Vector2(1f, -1f);
			GameObject val7 = new GameObject("name");
			val7.transform.SetParent(val.transform, false);
			RectTransform obj4 = val7.AddComponent<RectTransform>();
			obj4.anchorMin = new Vector2(1f, 0.5f);
			obj4.anchorMax = new Vector2(1f, 0.5f);
			obj4.pivot = new Vector2(0f, 0.5f);
			obj4.sizeDelta = new Vector2(220f, 24f);
			obj4.anchoredPosition = new Vector2(6f, 0f);
			Text val8 = val7.AddComponent<Text>();
			val8.font = CurrentFont();
			val8.fontSize = 12;
			val8.alignment = (TextAnchor)3;
			((Graphic)val8).color = Color.white;
			val8.horizontalOverflow = (HorizontalWrapMode)1;
			val8.verticalOverflow = (VerticalWrapMode)1;
			((Graphic)val8).raycastTarget = false;
			val8.resizeTextForBestFit = false;
			Outline obj5 = val7.AddComponent<Outline>();
			((Shadow)obj5).effectColor = new Color(0f, 0f, 0f, 0.95f);
			((Shadow)obj5).effectDistance = new Vector2(1f, -1f);
			val7.SetActive(false);
			Slot slot = val.AddComponent<Slot>();
			slot.Hud = this;
			slot.Root = root;
			slot.Back = val2;
			slot.Icon = val4;
			slot.Timer = val6;
			slot.Name = val8;
			return slot;
		}

		private RectTransform MakeTip()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: 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_007a: Expected O, but got Unknown
			//IL_0093: 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)
			//IL_00b3: 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_0128: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("tip");
			val.transform.SetParent((Transform)(object)_root, false);
			RectTransform obj = val.AddComponent<RectTransform>();
			obj.sizeDelta = new Vector2(160f, 28f);
			Image obj2 = val.AddComponent<Image>();
			obj2.sprite = _pixel;
			((Graphic)obj2).color = new Color(0.05f, 0.04f, 0.035f, 0.92f);
			((Graphic)obj2).raycastTarget = false;
			GameObject val2 = new GameObject("label");
			val2.transform.SetParent(val.transform, false);
			RectTransform obj3 = val2.AddComponent<RectTransform>();
			obj3.anchorMin = Vector2.zero;
			obj3.anchorMax = Vector2.one;
			obj3.offsetMin = new Vector2(8f, 2f);
			obj3.offsetMax = new Vector2(-8f, -2f);
			_tip = val2.AddComponent<Text>();
			_tip.font = CurrentFont();
			_tip.fontSize = ScaledFont(16f);
			_tip.alignment = (TextAnchor)3;
			((Graphic)_tip).color = new Color(0.95f, 0.9f, 0.78f, 1f);
			((Graphic)_tip).raycastTarget = false;
			val.SetActive(false);
			return obj;
		}

		private void ApplyFilter(Sprite sprite)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.CrispPixels.Value && !((Object)(object)sprite == (Object)null) && !((Object)(object)sprite.texture == (Object)null))
			{
				Texture2D texture = sprite.texture;
				if (!Filtered.ContainsKey((Texture)(object)texture))
				{
					Filtered[(Texture)(object)texture] = ((Texture)texture).filterMode;
				}
				((Texture)texture).filterMode = (FilterMode)0;
			}
		}

		public static void RestoreFilteredTextures()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			foreach (KeyValuePair<Texture, FilterMode> item in Filtered)
			{
				if ((Object)(object)item.Key != (Object)null)
				{
					item.Key.filterMode = item.Value;
				}
			}
			Filtered.Clear();
		}

		private static void PlaceName(RectTransform rect, StatusNameSide side)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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_0059: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			bool flag = side == StatusNameSide.Left;
			rect.anchorMin = (flag ? new Vector2(0f, 0.5f) : new Vector2(1f, 0.5f));
			rect.anchorMax = rect.anchorMin;
			rect.pivot = (flag ? new Vector2(1f, 0.5f) : new Vector2(0f, 0.5f));
			rect.sizeDelta = new Vector2(260f, Mathf.Max(16f, 20f * Plugin.TextScale.Value));
			rect.anchoredPosition = new Vector2(flag ? (-6f) : 6f, 0f);
			Text component = ((Component)rect).GetComponent<Text>();
			if ((Object)(object)component != (Object)null)
			{
				component.alignment = (TextAnchor)(flag ? 5 : 3);
			}
		}

		private static void ApplyLabel(Text text, bool timer)
		{
			//IL_005d: 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)
			if (!((Object)(object)text == (Object)null))
			{
				text.font = CurrentFont();
				float baseSize = (timer ? 12f : 12f);
				text.fontSize = ScaledFont(baseSize);
				RectTransform rectTransform = ((Graphic)text).rectTransform;
				if (timer)
				{
					float num = Mathf.Max(10f, 14f * Plugin.TextScale.Value);
					rectTransform.sizeDelta = new Vector2(-2f, num);
				}
				Outline component = ((Component)text).GetComponent<Outline>();
				if ((Object)(object)component != (Object)null)
				{
					float num2 = Mathf.Clamp(Plugin.TextScale.Value, 0.75f, 2f);
					((Shadow)component).effectDistance = new Vector2(num2, 0f - num2);
				}
			}
		}

		private static int ScaledFont(float baseSize)
		{
			return Mathf.Clamp(Mathf.RoundToInt(baseSize * Plugin.TextScale.Value), 6, 72);
		}

		private static Font CurrentFont()
		{
			if (Plugin.UseVanillaFont.Value)
			{
				Font val = Norse();
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			return _font;
		}

		private static Font Norse()
		{
			if ((Object)(object)_norse != (Object)null)
			{
				return _norse;
			}
			Font[] array = Resources.FindObjectsOfTypeAll<Font>();
			foreach (Font val in array)
			{
				if (!((Object)(object)val == (Object)null) && (((Object)val).name.IndexOf("Norsebold", StringComparison.OrdinalIgnoreCase) >= 0 || ((Object)val).name.Equals("Norse", StringComparison.OrdinalIgnoreCase)))
				{
					_norse = val;
					return _norse;
				}
			}
			foreach (Font val2 in array)
			{
				if ((Object)(object)val2 != (Object)null && ((Object)val2).name.IndexOf("Norse", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					_norse = val2;
					break;
				}
			}
			return _norse;
		}

		private static void Place(RectTransform rect, ScreenCorner corner, float x, float y, float size)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			switch (corner)
			{
			case ScreenCorner.TopLeft:
				((Vector2)(ref val))..ctor(0f, 1f);
				break;
			case ScreenCorner.BottomLeft:
				((Vector2)(ref val))..ctor(0f, 0f);
				break;
			case ScreenCorner.BottomRight:
				((Vector2)(ref val))..ctor(1f, 0f);
				break;
			default:
				((Vector2)(ref val))..ctor(1f, 1f);
				break;
			}
			rect.anchorMin = val;
			rect.anchorMax = val;
			rect.pivot = val;
			rect.sizeDelta = new Vector2(size, size);
			rect.anchoredPosition = new Vector2(x, y);
		}

		private static RectTransform Stretch(Transform parent, string name)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			RectTransform obj = val.AddComponent<RectTransform>();
			obj.anchorMin = Vector2.zero;
			obj.anchorMax = Vector2.one;
			obj.offsetMin = Vector2.zero;
			obj.offsetMax = Vector2.zero;
			return obj;
		}

		private static Sprite Pixel()
		{
			//IL_0004: 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_000c: 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: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false);
			val.SetPixel(0, 0, Color.white);
			val.Apply();
			((Object)val).hideFlags = (HideFlags)61;
			Sprite obj = Sprite.Create(val, new Rect(0f, 0f, 1f, 1f), new Vector2(0.5f, 0.5f), 1f);
			((Object)obj).hideFlags = (HideFlags)61;
			return obj;
		}

		private static bool MapOpen()
		{
			return Minimap.IsOpen();
		}

		private static bool InventoryOpen()
		{
			return InventoryGui.IsVisible();
		}

		private static bool MenuOpen()
		{
			return Menu.IsVisible();
		}

		private static bool ConsoleOpen()
		{
			return Console.IsVisible();
		}
	}
}