Decompiled source of CustomHotbarColors v0.1.0

plugins/CustomHotbarColors.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("CustomHotbarColors")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CustomHotbarColors")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
namespace CustomHotbarColors;

[BepInPlugin("orax.CustomHotbarColors", "CustomHotbarColors", "0.1.0")]
internal class CustomHotbarColors : BaseUnityPlugin
{
	public const string PluginGUID = "orax.CustomHotbarColors";

	public const string PluginName = "CustomHotbarColors";

	public const string PluginVersion = "0.1.0";

	internal static ManualLogSource Log;

	private Harmony _harmony;

	private void Awake()
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		Log.LogInfo((object)"CustomHotbarColors has landed");
		HotbarConfig.Bind(((BaseUnityPlugin)this).Config);
		_harmony = new Harmony("orax.CustomHotbarColors");
		_harmony.PatchAll();
		HotkeyBar[] array = Object.FindObjectsByType<HotkeyBar>((FindObjectsSortMode)0);
		for (int i = 0; i < array.Length; i++)
		{
			HotbarStyler.Ensure(array[i]);
		}
	}

	private void OnDestroy()
	{
		Harmony harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
		HotbarStyler[] array = Object.FindObjectsByType<HotbarStyler>((FindObjectsSortMode)0);
		for (int i = 0; i < array.Length; i++)
		{
			Object.Destroy((Object)(object)array[i]);
		}
	}
}
[HarmonyPatch(typeof(HotkeyBar), "OnEnable")]
internal static class HotkeyBarOnEnablePatch
{
	private static void Postfix(HotkeyBar __instance)
	{
		HotbarStyler.Ensure(__instance);
	}
}
internal sealed class HotbarBar : MonoBehaviour
{
	internal enum Side
	{
		Top,
		Bottom,
		Left,
		Right
	}

	internal const string ObjectName = "CustomHotbarColorsBar";

	private Image _image;

	private bool _visible;

	private Color _color;

	private float _thickness;

	private float _width;

	private float _offset;

	private float _along;

	private Side _side;

	internal bool Apply(bool visible, Color color, float thickness, float width, float offset, float along, Side side)
	{
		//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_005c: 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)
		bool result = false;
		if (_visible != visible)
		{
			_visible = visible;
			((Component)this).gameObject.SetActive(visible);
			result = true;
		}
		if (!visible)
		{
			return result;
		}
		if ((Object)(object)_image.sprite == (Object)null)
		{
			_image.sprite = HotbarStyler.WhiteSprite;
		}
		if (!HotbarStyler.SameColor(_color, color))
		{
			((Graphic)_image).color = color;
			_color = color;
			result = true;
		}
		if (!Mathf.Approximately(_thickness, thickness) || !Mathf.Approximately(_width, width) || !Mathf.Approximately(_offset, offset) || !Mathf.Approximately(_along, along) || _side != side)
		{
			SetGeometry(thickness, width, offset, along, side);
			_thickness = thickness;
			_width = width;
			_offset = offset;
			_along = along;
			_side = side;
			result = true;
		}
		return result;
	}

	internal static HotbarBar Create(Transform cell)
	{
		//IL_0018: 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_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Expected O, but got Unknown
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: 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_0063: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("CustomHotbarColorsBar", new Type[1] { typeof(RectTransform) });
		val.transform.SetParent(cell, false);
		val.transform.SetAsLastSibling();
		RectTransform val2 = (RectTransform)val.transform;
		val2.anchorMin = Vector2.zero;
		val2.anchorMax = Vector2.one;
		val2.offsetMin = Vector2.zero;
		val2.offsetMax = Vector2.zero;
		HotbarBar hotbarBar = val.AddComponent<HotbarBar>();
		hotbarBar._image = CreateImage((Transform)(object)val2);
		hotbarBar._visible = true;
		return hotbarBar;
	}

	private static Image CreateImage(Transform parent)
	{
		//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_0030: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("bar", new Type[2]
		{
			typeof(RectTransform),
			typeof(Image)
		});
		((Transform)(RectTransform)val.transform).SetParent(parent, false);
		Image component = val.GetComponent<Image>();
		component.sprite = HotbarStyler.WhiteSprite;
		component.type = (Type)0;
		((Graphic)component).raycastTarget = false;
		return component;
	}

	private void SetGeometry(float thickness, float width, float offset, float along, Side side)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: 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_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		Rect rect = ((RectTransform)((Component)this).transform).rect;
		Vector2 size = ((Rect)(ref rect)).size;
		Vector2 anchorMin = default(Vector2);
		Vector2 anchorMax = default(Vector2);
		Vector2 pivot = default(Vector2);
		Vector2 sizeDelta = default(Vector2);
		Vector2 anchoredPosition = default(Vector2);
		switch (side)
		{
		case Side.Bottom:
			((Vector2)(ref anchorMin))..ctor(0f, 0f);
			((Vector2)(ref anchorMax))..ctor(1f, 0f);
			((Vector2)(ref pivot))..ctor(0.5f, 0f);
			((Vector2)(ref sizeDelta))..ctor(Stretch(width, size.x), thickness);
			((Vector2)(ref anchoredPosition))..ctor(along, 0f - offset);
			break;
		case Side.Left:
			((Vector2)(ref anchorMin))..ctor(0f, 0f);
			((Vector2)(ref anchorMax))..ctor(0f, 1f);
			((Vector2)(ref pivot))..ctor(0f, 0.5f);
			((Vector2)(ref sizeDelta))..ctor(thickness, Stretch(width, size.y));
			((Vector2)(ref anchoredPosition))..ctor(0f - offset, along);
			break;
		case Side.Right:
			((Vector2)(ref anchorMin))..ctor(1f, 0f);
			((Vector2)(ref anchorMax))..ctor(1f, 1f);
			((Vector2)(ref pivot))..ctor(1f, 0.5f);
			((Vector2)(ref sizeDelta))..ctor(thickness, Stretch(width, size.y));
			((Vector2)(ref anchoredPosition))..ctor(offset, along);
			break;
		default:
			((Vector2)(ref anchorMin))..ctor(0f, 1f);
			((Vector2)(ref anchorMax))..ctor(1f, 1f);
			((Vector2)(ref pivot))..ctor(0.5f, 1f);
			((Vector2)(ref sizeDelta))..ctor(Stretch(width, size.x), thickness);
			((Vector2)(ref anchoredPosition))..ctor(along, offset);
			break;
		}
		RectTransform rectTransform = ((Graphic)_image).rectTransform;
		rectTransform.anchorMin = anchorMin;
		rectTransform.anchorMax = anchorMax;
		rectTransform.pivot = pivot;
		rectTransform.sizeDelta = sizeDelta;
		rectTransform.anchoredPosition = anchoredPosition;
	}

	private static float Stretch(float width, float sideLength)
	{
		if (!(width <= 0f))
		{
			return width - sideLength;
		}
		return 0f;
	}
}
internal sealed class HotbarBorder : MonoBehaviour
{
	internal const string ObjectName = "CustomHotbarColorsBorder";

	private Image[] _edges;

	private bool _visible;

	private Color _color;

	private float _thickness;

	private float _offset;

	private bool _grow;

	internal bool Apply(bool visible, Color color, float thickness, float offset, bool grow)
	{
		//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_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		bool result = false;
		if (_visible != visible)
		{
			_visible = visible;
			((Component)this).gameObject.SetActive(visible);
			result = true;
		}
		if (!visible)
		{
			return result;
		}
		if (!HotbarStyler.SameColor(_color, color))
		{
			for (int i = 0; i < _edges.Length; i++)
			{
				((Graphic)_edges[i]).color = color;
			}
			_color = color;
			result = true;
		}
		if (!Mathf.Approximately(_thickness, thickness) || !Mathf.Approximately(_offset, offset) || _grow != grow)
		{
			SetGeometry(thickness, offset, grow);
			_thickness = thickness;
			_offset = offset;
			_grow = grow;
			result = true;
		}
		return result;
	}

	internal static HotbarBorder Create(Transform cell)
	{
		//IL_0018: 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_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Expected O, but got Unknown
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: 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_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: 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_00d6: 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_0102: 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_0120: 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_014c: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("CustomHotbarColorsBorder", new Type[1] { typeof(RectTransform) });
		val.transform.SetParent(cell, false);
		val.transform.SetAsLastSibling();
		RectTransform val2 = (RectTransform)val.transform;
		val2.anchorMin = Vector2.zero;
		val2.anchorMax = Vector2.one;
		val2.offsetMin = Vector2.zero;
		val2.offsetMax = Vector2.zero;
		HotbarBorder hotbarBorder = val.AddComponent<HotbarBorder>();
		hotbarBorder._edges = (Image[])(object)new Image[4]
		{
			CreateEdge(val2, "top", new Vector2(0f, 1f), new Vector2(1f, 1f), new Vector2(0.5f, 1f)),
			CreateEdge(val2, "bottom", new Vector2(0f, 0f), new Vector2(1f, 0f), new Vector2(0.5f, 0f)),
			CreateEdge(val2, "left", new Vector2(0f, 0f), new Vector2(0f, 1f), new Vector2(0f, 0.5f)),
			CreateEdge(val2, "right", new Vector2(1f, 0f), new Vector2(1f, 1f), new Vector2(1f, 0.5f))
		};
		hotbarBorder._visible = true;
		return hotbarBorder;
	}

	private static Image CreateEdge(RectTransform parent, string name, Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot)
	{
		//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_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_0039: 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)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: 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_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject(name, new Type[2]
		{
			typeof(RectTransform),
			typeof(Image)
		});
		RectTransform val2 = (RectTransform)val.transform;
		((Transform)val2).SetParent((Transform)(object)parent, false);
		val2.anchorMin = anchorMin;
		val2.anchorMax = anchorMax;
		val2.pivot = pivot;
		val2.anchoredPosition = Vector2.zero;
		Image component = val.GetComponent<Image>();
		component.sprite = HotbarStyler.WhiteSprite;
		component.type = (Type)0;
		((Graphic)component).raycastTarget = false;
		return component;
	}

	private void SetGeometry(float thickness, float offset, bool grow)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: 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_003f: 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_006e: 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)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		float num = (grow ? (2f * offset) : 0f);
		Rect rect = ((RectTransform)((Component)_edges[0]).transform.parent).rect;
		Vector2 size = ((Rect)(ref rect)).size;
		Vector2 sizeDelta = default(Vector2);
		((Vector2)(ref sizeDelta))..ctor(Mathf.Max(0f, size.x + num) - size.x, thickness);
		Vector2 sizeDelta2 = default(Vector2);
		((Vector2)(ref sizeDelta2))..ctor(thickness, Mathf.Max(0f, size.y + num) - size.y);
		((Graphic)_edges[0]).rectTransform.sizeDelta = sizeDelta;
		((Graphic)_edges[1]).rectTransform.sizeDelta = sizeDelta;
		((Graphic)_edges[2]).rectTransform.sizeDelta = sizeDelta2;
		((Graphic)_edges[3]).rectTransform.sizeDelta = sizeDelta2;
		((Graphic)_edges[0]).rectTransform.anchoredPosition = new Vector2(0f, offset);
		((Graphic)_edges[1]).rectTransform.anchoredPosition = new Vector2(0f, 0f - offset);
		((Graphic)_edges[2]).rectTransform.anchoredPosition = new Vector2(0f - offset, 0f);
		((Graphic)_edges[3]).rectTransform.anchoredPosition = new Vector2(offset, 0f);
	}
}
internal static class HotbarConfig
{
	internal const string SectionGeneral = "1 - General";

	internal const string SectionBackgrounds = "2 - Backgrounds";

	internal const string SectionNumbers = "3 - Numbers";

	internal const string SectionBorder = "4 - Border";

	internal const string SectionBar = "5 - Bar";

	internal static readonly Color GameNumberColor = new Color(0.59607846f, 0.8156863f, 1f, 1f);

	internal static ConfigEntry<bool> Enabled;

	internal static ConfigEntry<int> RefreshFrames;

	internal static ConfigEntry<bool> EnableAllCellsBackground;

	internal static ConfigEntry<Color> AllCellsBackgroundColor;

	internal static ConfigEntry<bool> EnableEquippedBackground;

	internal static ConfigEntry<Color> EquippedBackgroundColor;

	internal static ConfigEntry<bool> EnableAllCellsNumberColor;

	internal static ConfigEntry<Color> AllCellsNumberColor;

	internal static ConfigEntry<bool> EnableEquippedNumberColor;

	internal static ConfigEntry<Color> EquippedNumberColor;

	internal static ConfigEntry<bool> EnableEquippedBorderColor;

	internal static ConfigEntry<Color> EquippedBorderColor;

	internal static ConfigEntry<float> EquippedBorderThickness;

	internal static ConfigEntry<float> EquippedBorderOffset;

	internal static ConfigEntry<bool> EquippedBorderGrowsWithOffset;

	internal static ConfigEntry<bool> EquippedBorderOutsideCell;

	internal static ConfigEntry<bool> EnableEquippedBar;

	internal static ConfigEntry<Color> EquippedBarColor;

	internal static ConfigEntry<float> EquippedBarThickness;

	internal static ConfigEntry<float> EquippedBarWidth;

	internal static ConfigEntry<HotbarBar.Side> EquippedBarSide;

	internal static ConfigEntry<float> EquippedBarOffset;

	internal static ConfigEntry<float> EquippedBarOffsetAlong;

	internal static void Bind(ConfigFile config)
	{
		//IL_0071: 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_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Expected O, but got Unknown
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0214: Expected O, but got Unknown
		//IL_0289: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d0: Expected O, but got Unknown
		//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0308: Expected O, but got Unknown
		//IL_0351: Unknown result type (might be due to invalid IL or missing references)
		//IL_035b: Expected O, but got Unknown
		//IL_0389: Unknown result type (might be due to invalid IL or missing references)
		//IL_0393: Expected O, but got Unknown
		Enabled = config.Bind<bool>("1 - General", "Enabled", true, "Master switch. While false the mod restores the hotbar to the colors the game draws on its own.");
		RefreshFrames = config.Bind<int>("1 - General", "RefreshFrames", 15, "How many frames to wait between two passes over the hotbar (15 frames is about 0.25 s at 60 FPS). Higher means less work, slower reaction to changes. Below 1 is treated as 1.");
		EnableAllCellsBackground = config.Bind<bool>("2 - Backgrounds", "EnableAllCellsBackground", false, "Whether a background is drawn under the content of every hotbar cell. While false the cells keep the background the game gives them.");
		AllCellsBackgroundColor = config.Bind<Color>("2 - Backgrounds", "AllCellsBackgroundColor", new Color(0f, 0f, 0f, 0.35f), "Background color of every hotbar cell. Pick a color with the swatch; the alpha channel sets the opacity. The default is a light black veil.");
		EnableEquippedBackground = config.Bind<bool>("2 - Backgrounds", "EnableEquippedBackground", false, "Whether the background of the cell holding the equipped item is recolored. While false that cell keeps the background the game gives it.");
		EquippedBackgroundColor = config.Bind<Color>("2 - Backgrounds", "EquippedBackgroundColor", new Color(1f, 0f, 0f, 0.35f), "Background color of the hotbar cell of the item you currently have equipped (weapon or shield). It wins over AllCellsBackgroundColor on that cell.");
		EnableAllCellsNumberColor = config.Bind<bool>("3 - Numbers", "EnableAllCellsNumberColor", false, "Whether AllCellsNumberColor is used. While false every slot number keeps the color the game gives it.");
		AllCellsNumberColor = config.Bind<Color>("3 - Numbers", "AllCellsNumberColor", GameNumberColor, "Color of the slot number of every hotbar cell. The default #98D0FF is the color the game uses on its own.");
		EnableEquippedNumberColor = config.Bind<bool>("3 - Numbers", "EnableEquippedNumberColor", true, "Whether EquippedNumberColor is used on the equipped cell. While false that number follows AllCellsNumberColor.");
		EquippedNumberColor = config.Bind<Color>("3 - Numbers", "EquippedNumberColor", new Color(1f, 43f / 51f, 0f, 1f), "Color of the slot number of the item you currently have equipped (weapon or shield). It wins over AllCellsNumberColor on that cell.");
		EnableEquippedBorderColor = config.Bind<bool>("4 - Border", "EnableEquippedBorderColor", true, "Whether a frame is drawn around the cell holding the equipped item.");
		EquippedBorderColor = config.Bind<Color>("4 - Border", "EquippedBorderColor", new Color(1f, 1f, 0f, 0.745f), "Color of the frame drawn around the hotbar cell of the item you currently have equipped (weapon or shield).");
		EquippedBorderThickness = config.Bind<float>("4 - Border", "EquippedBorderThickness", 3f, new ConfigDescription("Width of the frame drawn around the equipped cell, in UI units (about one screen pixel at 1080p).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 20f), Array.Empty<object>()));
		EquippedBorderOffset = config.Bind<float>("4 - Border", "EquippedBorderOffset", -1f, new ConfigDescription("Where the frame sits relative to the edge of the equipped cell, in UI units. 0 draws it just inside the cell, a positive value pushes it outside (at +thickness it sits flush against the outside), a negative value pulls it further inside.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-20f, 20f), Array.Empty<object>()));
		EquippedBorderGrowsWithOffset = config.Bind<bool>("4 - Border", "EquippedBorderGrowsWithOffset", true, "Whether the frame grows with EquippedBorderOffset, so it still surrounds the whole cell and its four edges keep meeting at the corners. While false the edges only slide, which opens the corners as soon as the offset gets bigger than EquippedBorderThickness.");
		EquippedBorderOutsideCell = config.Bind<bool>("4 - Border", "EquippedBorderOutsideCell", true, "Draws the frame just outside the equipped cell, one thickness beyond its edge instead of over the edge. EquippedBorderOffset still applies on top of that, and EquippedBorderGrowsWithOffset is ignored so the corners stay closed.");
		EnableEquippedBar = config.Bind<bool>("5 - Bar", "EnableEquippedBar", false, "Whether a single bar is drawn along one side of the cell holding the equipped item. It is independent of the frame drawn by EnableEquippedBorderColor, and both can be on at the same time.");
		EquippedBarColor = config.Bind<Color>("5 - Bar", "EquippedBarColor", new Color(1f, 1f, 0f, 1f), "Color of the bar drawn on the equipped cell. The alpha channel sets the opacity.");
		EquippedBarThickness = config.Bind<float>("5 - Bar", "EquippedBarThickness", 3f, new ConfigDescription("Thickness of the bar, its small dimension perpendicular to the side it sits on, in UI units (about one screen pixel at 1080p).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 20f), Array.Empty<object>()));
		EquippedBarWidth = config.Bind<float>("5 - Bar", "EquippedBarWidth", 0f, new ConfigDescription("Length of the bar along its side, in UI units. 0 draws it over the whole side; a shorter bar starts centered on that side, and EquippedBarOffsetAlong moves it along.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-100f, 100f), Array.Empty<object>()));
		EquippedBarSide = config.Bind<HotbarBar.Side>("5 - Bar", "EquippedBarSide", HotbarBar.Side.Bottom, "Which side of the equipped cell the bar sits on: Top, Bottom, Left or Right.");
		EquippedBarOffset = config.Bind<float>("5 - Bar", "EquippedBarOffset", 7f, new ConfigDescription("Where the bar sits relative to the cell edge it hangs on, in UI units. 0 puts it just inside the cell, a positive value pushes it outside (at +thickness it sits flush against the outside), a negative value pulls it further inside.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-20f, 20f), Array.Empty<object>()));
		EquippedBarOffsetAlong = config.Bind<float>("5 - Bar", "EquippedBarOffsetAlong", 0f, new ConfigDescription("How far the bar slides along its side, in UI units: positive means right for the top and bottom sides, upward for the left and right sides. 0 keeps it centered.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-20f, 20f), Array.Empty<object>()));
	}
}
internal sealed class HotbarStyler : MonoBehaviour
{
	private sealed class CellState
	{
		internal Transform Cell;

		internal TMP_Text Binding;

		internal Transform Marker;

		internal Image MarkerImage;

		internal Image Overlay;

		internal HotbarBorder Border;

		internal HotbarBar Bar;

		internal bool BindingStyled;

		internal bool MarkerStyled;
	}

	private const string BindingName = "binding";

	private const string EquipedName = "equiped";

	private const string VanillaBarName = "HotKeyBar";

	private const string OverlayName = "CustomHotbarColorsBackground";

	private static Sprite _whiteSprite;

	private readonly List<CellState> _cells = new List<CellState>();

	private HotkeyBar _bar;

	private Coroutine _refresh;

	private bool _styled;

	private bool _originalsRead;

	private Color _originalBindingColor = Color.white;

	private Color _originalEquipedColor = Color.white;

	internal static Sprite WhiteSprite
	{
		get
		{
			//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_0023: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_0068: Expected O, but got Unknown
			if ((Object)(object)_whiteSprite != (Object)null)
			{
				return _whiteSprite;
			}
			Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)0
			};
			val.SetPixel(0, 0, Color.white);
			val.Apply();
			_whiteSprite = Sprite.Create(val, new Rect(0f, 0f, 1f, 1f), new Vector2(0.5f, 0.5f), 100f);
			return _whiteSprite;
		}
	}

	internal static void Ensure(HotkeyBar bar)
	{
		if (Object.op_Implicit((Object)(object)bar) && !(((Object)bar).name != "HotKeyBar"))
		{
			HotbarStyler hotbarStyler = ((Component)bar).GetComponent<HotbarStyler>();
			if ((Object)(object)hotbarStyler == (Object)null)
			{
				hotbarStyler = ((Component)bar).gameObject.AddComponent<HotbarStyler>();
			}
			hotbarStyler.StartRefresh(bar);
		}
	}

	private void StartRefresh(HotkeyBar bar)
	{
		_bar = bar;
		if (_refresh != null)
		{
			((MonoBehaviour)this).StopCoroutine(_refresh);
		}
		_refresh = ((MonoBehaviour)this).StartCoroutine(RefreshLoop());
	}

	private IEnumerator RefreshLoop()
	{
		while (true)
		{
			Refresh();
			int frames = Mathf.Max(1, HotbarConfig.RefreshFrames.Value);
			for (int i = 0; i < frames; i++)
			{
				yield return null;
			}
		}
	}

	private void Refresh()
	{
		bool value = HotbarConfig.Enabled.Value;
		if (!value && !_styled)
		{
			return;
		}
		HotkeyBar bar = _bar;
		if (!Object.op_Implicit((Object)(object)bar))
		{
			_cells.Clear();
			_styled = false;
			return;
		}
		Transform transform = ((Component)bar).transform;
		if (!CacheMatches(transform))
		{
			RebuildCache(transform);
		}
		if (!_originalsRead)
		{
			ReadOriginals(bar);
		}
		bool flag = false;
		for (int i = 0; i < _cells.Count; i++)
		{
			flag |= Apply(_cells[i], value);
		}
		if (value)
		{
			_styled = true;
		}
		else if (!flag)
		{
			_styled = false;
		}
	}

	private bool CacheMatches(Transform root)
	{
		if (_cells.Count != root.childCount)
		{
			return false;
		}
		for (int i = 0; i < _cells.Count; i++)
		{
			if ((Object)(object)_cells[i].Cell != (Object)(object)root.GetChild(i))
			{
				return false;
			}
		}
		return true;
	}

	private void RebuildCache(Transform root)
	{
		_cells.Clear();
		for (int i = 0; i < root.childCount; i++)
		{
			Transform child = root.GetChild(i);
			CellState cellState = new CellState
			{
				Cell = child
			};
			Transform val = child.Find("binding");
			if ((Object)(object)val != (Object)null)
			{
				cellState.Binding = ((Component)val).GetComponent<TMP_Text>();
			}
			Transform val2 = child.Find("equiped");
			if ((Object)(object)val2 != (Object)null)
			{
				cellState.Marker = val2;
				cellState.MarkerImage = GetImage(val2);
			}
			Transform val3 = child.Find("CustomHotbarColorsBackground");
			if ((Object)(object)val3 != (Object)null)
			{
				cellState.Overlay = ((Component)val3).GetComponent<Image>();
			}
			Transform val4 = child.Find("CustomHotbarColorsBorder");
			if ((Object)(object)val4 != (Object)null)
			{
				cellState.Border = ((Component)val4).GetComponent<HotbarBorder>();
				if ((Object)(object)cellState.Border == (Object)null)
				{
					Object.Destroy((Object)(object)((Component)val4).gameObject);
				}
			}
			Transform val5 = child.Find("CustomHotbarColorsBar");
			if ((Object)(object)val5 != (Object)null)
			{
				cellState.Bar = ((Component)val5).GetComponent<HotbarBar>();
				if ((Object)(object)cellState.Bar == (Object)null)
				{
					Object.Destroy((Object)(object)((Component)val5).gameObject);
				}
			}
			_cells.Add(cellState);
		}
	}

	private void ReadOriginals(HotkeyBar bar)
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: 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)
		GameObject elementPrefab = bar.m_elementPrefab;
		if (Object.op_Implicit((Object)(object)elementPrefab))
		{
			Transform val = elementPrefab.transform.Find("binding");
			TMP_Text val2 = (((Object)(object)val == (Object)null) ? null : ((Component)val).GetComponent<TMP_Text>());
			if ((Object)(object)val2 != (Object)null)
			{
				_originalBindingColor = ((Graphic)val2).color;
			}
			Image image = GetImage(elementPrefab.transform.Find("equiped"));
			if ((Object)(object)image != (Object)null)
			{
				_originalEquipedColor = ((Graphic)image).color;
			}
			_originalsRead = true;
		}
	}

	private bool Apply(CellState cell, bool enabled)
	{
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: 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_00b7: 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_00f6: 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)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_027d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)cell.Binding == (Object)null)
		{
			return false;
		}
		bool flag = false;
		bool flag2 = (Object)(object)cell.Marker != (Object)null && ((Component)cell.Marker).gameObject.activeSelf;
		Color? val = null;
		if (enabled && flag2 && HotbarConfig.EnableEquippedNumberColor.Value)
		{
			val = HotbarConfig.EquippedNumberColor.Value;
		}
		else if (enabled && HotbarConfig.EnableAllCellsNumberColor.Value)
		{
			val = HotbarConfig.AllCellsNumberColor.Value;
		}
		if (val.HasValue)
		{
			flag |= Write((Graphic)(object)cell.Binding, val.Value);
			cell.BindingStyled = true;
		}
		else if (cell.BindingStyled)
		{
			flag |= Write((Graphic)(object)cell.Binding, _originalBindingColor);
			cell.BindingStyled = false;
		}
		bool num = (Object)(object)cell.MarkerImage != (Object)null;
		if (num)
		{
			if (enabled && flag2 && HotbarConfig.EnableEquippedBackground.Value)
			{
				flag |= Write((Graphic)(object)cell.MarkerImage, HotbarConfig.EquippedBackgroundColor.Value);
				cell.MarkerStyled = true;
			}
			else if (cell.MarkerStyled)
			{
				flag |= Write((Graphic)(object)cell.MarkerImage, _originalEquipedColor);
				cell.MarkerStyled = false;
			}
		}
		bool flag3 = !num && enabled && flag2 && HotbarConfig.EnableEquippedBackground.Value;
		bool flag4 = flag3 || (enabled && HotbarConfig.EnableAllCellsBackground.Value);
		if ((Object)(object)cell.Overlay == (Object)null && flag4)
		{
			cell.Overlay = CreateOverlay(cell.Cell);
		}
		if ((Object)(object)cell.Overlay != (Object)null)
		{
			if (((Component)cell.Overlay).gameObject.activeSelf != flag4)
			{
				((Component)cell.Overlay).gameObject.SetActive(flag4);
				flag = true;
			}
			if (flag4)
			{
				Color color = (flag3 ? HotbarConfig.EquippedBackgroundColor.Value : HotbarConfig.AllCellsBackgroundColor.Value);
				if ((Object)(object)cell.Overlay.sprite == (Object)null)
				{
					cell.Overlay.sprite = WhiteSprite;
				}
				flag |= Write((Graphic)(object)cell.Overlay, color);
			}
		}
		bool flag5 = enabled && flag2 && HotbarConfig.EnableEquippedBorderColor.Value;
		if ((Object)(object)cell.Border == (Object)null && flag5)
		{
			cell.Border = HotbarBorder.Create(cell.Cell);
		}
		if ((Object)(object)cell.Border != (Object)null)
		{
			bool value = HotbarConfig.EquippedBorderOutsideCell.Value;
			float value2 = HotbarConfig.EquippedBorderThickness.Value;
			float value3 = HotbarConfig.EquippedBorderOffset.Value;
			flag |= cell.Border.Apply(flag5, HotbarConfig.EquippedBorderColor.Value, value2, value ? (value2 + value3) : value3, value || HotbarConfig.EquippedBorderGrowsWithOffset.Value);
		}
		bool flag6 = enabled && flag2 && HotbarConfig.EnableEquippedBar.Value;
		if ((Object)(object)cell.Bar == (Object)null && flag6)
		{
			cell.Bar = HotbarBar.Create(cell.Cell);
		}
		if ((Object)(object)cell.Bar != (Object)null)
		{
			flag |= cell.Bar.Apply(flag6, HotbarConfig.EquippedBarColor.Value, HotbarConfig.EquippedBarThickness.Value, HotbarConfig.EquippedBarWidth.Value, HotbarConfig.EquippedBarOffset.Value, HotbarConfig.EquippedBarOffsetAlong.Value, HotbarConfig.EquippedBarSide.Value);
		}
		return flag;
	}

	private static bool Write(Graphic graphic, Color color)
	{
		//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_0011: Unknown result type (might be due to invalid IL or missing references)
		if (SameColor(graphic.color, color))
		{
			return false;
		}
		graphic.color = color;
		return true;
	}

	internal static bool SameColor(Color a, Color b)
	{
		//IL_0000: 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_001f: 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_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: 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 (Mathf.Abs(a.r - b.r) < 0.002f && Mathf.Abs(a.g - b.g) < 0.002f && Mathf.Abs(a.b - b.b) < 0.002f)
		{
			return Mathf.Abs(a.a - b.a) < 0.002f;
		}
		return false;
	}

	private static Image GetImage(Transform transform)
	{
		if ((Object)(object)transform == (Object)null)
		{
			return null;
		}
		Image component = ((Component)transform).GetComponent<Image>();
		if (!((Object)(object)component != (Object)null))
		{
			return ((Component)transform).GetComponentInChildren<Image>(true);
		}
		return component;
	}

	private static Image CreateOverlay(Transform cell)
	{
		//IL_0018: 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_002a: 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_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: 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_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: 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_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("CustomHotbarColorsBackground", new Type[1] { typeof(RectTransform) });
		val.transform.SetParent(cell, false);
		val.transform.SetSiblingIndex(0);
		RectTransform val2 = (RectTransform)val.transform;
		val2.anchorMin = Vector2.zero;
		val2.anchorMax = Vector2.one;
		val2.offsetMin = Vector2.zero;
		val2.offsetMax = Vector2.zero;
		Image obj = val.AddComponent<Image>();
		obj.sprite = WhiteSprite;
		obj.type = (Type)0;
		((Graphic)obj).raycastTarget = false;
		return obj;
	}
}