Decompiled source of ZenUI v0.2.4

plugins\ZenUI.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using JetBrains.Annotations;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.PostProcessing;
using UnityEngine.UI;
using Zen.Config;
using Zen.Lib;
using Zen.Logging;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ZenUI")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ZenUI")]
[assembly: AssemblyCopyright("Copyright \ufffd  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 ZenUI
{
	[HarmonyPatch]
	internal static class AmmoCountIcon
	{
		private class ElementExtraData
		{
			[CompilerGenerated]
			private TMP_Text <text>P;

			[CompilerGenerated]
			private Image <icon>P;

			[CompilerGenerated]
			private Image <bait>P;

			public ItemData? Item;

			public ElementExtraData(TMP_Text text, Image icon, Image bait)
			{
				<text>P = text;
				<icon>P = icon;
				<bait>P = bait;
				base..ctor();
			}

			public void UpdateState(ElementData elementData)
			{
				if (Item == null)
				{
					((Component)<text>P).gameObject.SetActive(false);
					((Component)<icon>P).gameObject.SetActive(false);
					((Component)<bait>P).gameObject.SetActive(false);
					return;
				}
				ItemData currentAmmo = GetCurrentAmmo();
				int num = ((currentAmmo != null) ? ((Humanoid)Player.m_localPlayer).GetInventory().CountItems(currentAmmo.m_shared.m_name, -1, true) : 0);
				((Component)<text>P).gameObject.SetActive(Configs.EnableAmmoCount.Value && num > 0);
				if (num > 0)
				{
					<text>P.SetText(num.ToString());
				}
				Sprite val = ((currentAmmo != null) ? currentAmmo.GetIcon() : null);
				((Component)<icon>P).gameObject.SetActive(Configs.EnableAmmoCount.Value && Object.op_Implicit((Object)(object)val));
				if (Object.op_Implicit((Object)(object)val))
				{
					<icon>P.overrideSprite = val;
				}
				ItemData currentBait = GetCurrentBait();
				Sprite val2 = ((currentBait != null) ? currentBait.GetIcon() : null);
				((Component)<bait>P).gameObject.SetActive(Object.op_Implicit((Object)(object)val2));
				if (Object.op_Implicit((Object)(object)val2))
				{
					<bait>P.overrideSprite = val2;
				}
				int num2 = ((currentBait != null) ? ((Humanoid)Player.m_localPlayer).GetInventory().CountItems(currentBait.m_shared.m_name, -1, true) : 0);
				if (num2 > 0 && !((Component)elementData.m_amount).gameObject.activeSelf)
				{
					((Component)elementData.m_amount).gameObject.SetActive(true);
					elementData.m_amount.SetText(num2.ToString());
				}
			}

			private ItemData? GetCurrentAmmo()
			{
				if (Item == null || Utility.IsNullOrWhiteSpace(Item.m_shared.m_ammoType) || IsBaitAmmo() || IsAmmo())
				{
					return null;
				}
				ItemData ammoItem = ((Humanoid)Player.m_localPlayer).GetAmmoItem();
				if (ammoItem == null || ammoItem.m_shared.m_ammoType != Item.m_shared.m_ammoType || !((Humanoid)Player.m_localPlayer).GetInventory().ContainsItem(ammoItem))
				{
					ammoItem = ((Humanoid)Player.m_localPlayer).GetInventory().GetAmmoItem(Item.m_shared.m_ammoType, (string)null);
				}
				return ammoItem;
			}

			private ItemData? GetCurrentBait()
			{
				if (Item == null || Utility.IsNullOrWhiteSpace(Item.m_shared.m_ammoType) || !IsBaitAmmo() || IsAmmo())
				{
					return null;
				}
				ItemData ammoItem = ((Humanoid)Player.m_localPlayer).GetAmmoItem();
				if (ammoItem == null || ammoItem.m_shared.m_ammoType != Item.m_shared.m_ammoType || !((Humanoid)Player.m_localPlayer).GetInventory().ContainsItem(ammoItem))
				{
					ammoItem = ((Humanoid)Player.m_localPlayer).GetInventory().GetAmmoItem(Item.m_shared.m_ammoType, (string)null);
				}
				return ammoItem;
			}

			private bool IsAmmo()
			{
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Invalid comparison between Unknown and I4
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Invalid comparison between Unknown and I4
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Invalid comparison between Unknown and I4
				ItemType? val = Item?.m_shared.m_itemType;
				if (val.HasValue)
				{
					ItemType valueOrDefault = val.GetValueOrDefault();
					if ((int)valueOrDefault == 2 || (int)valueOrDefault == 9 || (int)valueOrDefault == 23)
					{
						return true;
					}
				}
				return false;
			}

			private bool IsBaitAmmo()
			{
				return Item?.m_shared.m_ammoType == "$item_fishingbait";
			}
		}

		private static readonly Vector2 AmmoCountPosition = new Vector2(0f, 86f);

		private const int AmmoCountFontSize = 14;

		private const HorizontalAlignmentOptions AmmoCountAlignment = 2;

		private static readonly Vector2 AmmoIconPosition = new Vector2(0f, 40f);

		private static readonly Vector2 AmmoIconSize = new Vector2(-10f, -10f);

		private const string ObjectAmmoName = "ZenUI_AmmoAmount";

		private const string ObjectIconName = "ZenUI_AmmoIcon";

		private const string ObjectBaitName = "ZenUI_AmmoBait";

		private static readonly Dictionary<HotkeyBar, bool> IsDirty = new Dictionary<HotkeyBar, bool>();

		private static readonly Dictionary<HotkeyBar, Dictionary<ElementData, ElementExtraData>> ElementExtraDatas = new Dictionary<HotkeyBar, Dictionary<ElementData, ElementExtraData>>();

		private static void UpdateVisibility(GameObject ammoCount, GameObject ammoIcon, GameObject ammoBait)
		{
			//IL_0006: 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_0038: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			ammoCount.GetComponent<RectTransform>().anchoredPosition = AmmoCountPosition;
			TMP_Text component = ammoCount.GetComponent<TMP_Text>();
			component.fontSize = 14f;
			component.horizontalAlignment = (HorizontalAlignmentOptions)2;
			RectTransform component2 = ammoIcon.GetComponent<RectTransform>();
			component2.anchoredPosition = AmmoIconPosition;
			component2.sizeDelta = AmmoIconSize;
			RectTransform component3 = ammoBait.GetComponent<RectTransform>();
			component3.anchorMin = new Vector2(0.5f, 0f);
			component3.anchorMax = new Vector2(1f, 0.5f);
			foreach (HotkeyBar key in IsDirty.Keys)
			{
				IsDirty[key] = true;
			}
		}

		private static void AddCustomElementsToHotkeyPrefab(HotkeyBar bar)
		{
			if (Configs.EnableAmmoCount.Value)
			{
				Log.Info((object)"Adding Custom Elements", (ushort)0);
				GameObject elementPrefab = bar.m_elementPrefab;
				if (!Object.op_Implicit((Object)(object)elementPrefab))
				{
					throw new NullReferenceException("HotkeyBar.m_elementPrefab is null, this should never happen");
				}
				int num = elementPrefab.transform.Find("icon").GetSiblingIndex() + 1;
				Transform obj = elementPrefab.transform.Find("ZenUI_AmmoAmount");
				GameObject val = ((obj != null) ? ((Component)obj).gameObject : null);
				if ((Object)(object)val == (Object)null)
				{
					GameObject gameObject = ((Component)elementPrefab.transform.Find("amount")).gameObject;
					val = Object.Instantiate<GameObject>(gameObject);
					((Object)val).name = "ZenUI_AmmoAmount";
					val.transform.SetSiblingIndex(num);
					val.SetActive(false);
					val.transform.SetParent(elementPrefab.transform);
					num++;
					FillFields(gameObject.GetComponent<RectTransform>(), val.GetComponent<RectTransform>());
				}
				Transform obj2 = elementPrefab.transform.Find("ZenUI_AmmoIcon");
				GameObject val2 = ((obj2 != null) ? ((Component)obj2).gameObject : null);
				if ((Object)(object)val2 == (Object)null)
				{
					GameObject gameObject2 = ((Component)elementPrefab.transform.Find("icon")).gameObject;
					val2 = Object.Instantiate<GameObject>(gameObject2);
					((Object)val2).name = "ZenUI_AmmoIcon";
					val2.transform.SetSiblingIndex(num);
					val2.SetActive(false);
					val2.transform.SetParent(elementPrefab.transform);
					num++;
					FillFields(gameObject2.GetComponent<RectTransform>(), val2.GetComponent<RectTransform>());
				}
				Transform obj3 = elementPrefab.transform.Find("ZenUI_AmmoBait");
				GameObject val3 = ((obj3 != null) ? ((Component)obj3).gameObject : null);
				if ((Object)(object)val3 == (Object)null)
				{
					GameObject gameObject3 = ((Component)elementPrefab.transform.Find("icon")).gameObject;
					val3 = Object.Instantiate<GameObject>(gameObject3);
					((Object)val3).name = "ZenUI_AmmoBait";
					val3.transform.SetSiblingIndex(num);
					val3.SetActive(false);
					val3.transform.SetParent(elementPrefab.transform);
					FillFields(gameObject3.GetComponent<RectTransform>(), val3.GetComponent<RectTransform>());
				}
				UpdateVisibility(val, val2, val3);
				Log.Info((object)"Added custom elements to hotkey bar", (ushort)0);
			}
			static void FillFields(RectTransform rtSource, RectTransform rtDestination)
			{
				//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)
				rtDestination.anchoredPosition = rtSource.anchoredPosition;
				rtDestination.sizeDelta = rtSource.sizeDelta;
			}
		}

		private static void UpdateDirtyState(HotkeyBar hotkeyBar)
		{
			if (GeneralExtensions.GetValueSafe<HotkeyBar, bool>(IsDirty, hotkeyBar))
			{
				Log.Info((object)"HotkeyBar is dirty", (ushort)0);
				IsDirty[hotkeyBar] = false;
				if (hotkeyBar.m_elements.Count > 0)
				{
					hotkeyBar.UpdateIcons((Player)null);
				}
			}
		}

		private static void UpdateAmmoAndIcon(HotkeyBar hotkeyBar, Player player)
		{
			if (!ElementExtraDatas.ContainsKey(hotkeyBar))
			{
				ElementExtraDatas.Add(hotkeyBar, new Dictionary<ElementData, ElementExtraData>());
			}
			Dictionary<ElementData, ElementExtraData> dictionary = ElementExtraDatas[hotkeyBar];
			if (!Object.op_Implicit((Object)(object)player) || ((Character)player).IsDead())
			{
				dictionary.Clear();
				return;
			}
			if (dictionary.Count != hotkeyBar.m_elements.Count)
			{
				dictionary.Clear();
			}
			if (dictionary.Count > 0 && hotkeyBar.m_elements.Count > 0 && !dictionary.ContainsKey(hotkeyBar.m_elements[0]))
			{
				dictionary.Clear();
			}
			if (dictionary.Count == 0)
			{
				foreach (ElementData element in hotkeyBar.m_elements)
				{
					Log.Info((object)"Get element data from Hotbar objects", (ushort)0);
					ElementExtraData value = new ElementExtraData(((Component)element.m_go.transform.Find("ZenUI_AmmoAmount")).GetComponent<TMP_Text>(), ((Component)element.m_go.transform.Find("ZenUI_AmmoIcon")).GetComponent<Image>(), ((Component)element.m_go.transform.Find("ZenUI_AmmoBait")).GetComponent<Image>());
					dictionary.Add(element, value);
				}
			}
			int num = 0;
			foreach (ElementData element2 in hotkeyBar.m_elements)
			{
				ElementExtraData elementExtraData = dictionary[element2];
				if (elementExtraData == null)
				{
					continue;
				}
				if (!element2.m_used || num > hotkeyBar.m_items.Count)
				{
					elementExtraData.Item = null;
				}
				else
				{
					elementExtraData.Item = hotkeyBar.m_items[num];
					if ((Object)(object)elementExtraData.Item.GetIcon() != (Object)(object)element2.m_icon.sprite)
					{
						elementExtraData.Item = null;
					}
					num++;
				}
				elementExtraData.UpdateState(element2);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(HotkeyBar), "OnEnable")]
		private static void HotkeyBar_OnEnable(HotkeyBar __instance)
		{
			if (Configs.EnableAmmoCount.Value)
			{
				AddCustomElementsToHotkeyPrefab(__instance);
			}
		}

		[HarmonyPriority(0)]
		[HarmonyBefore(new string[] { "Azumatt.AzuExtendedPlayerInventory" })]
		[HarmonyPrefix]
		[HarmonyPatch(typeof(HotkeyBar), "Update")]
		private static void HotkeyBar_Update(HotkeyBar __instance)
		{
			if (Configs.EnableAmmoCount.Value)
			{
				UpdateDirtyState(__instance);
			}
		}

		[HarmonyPriority(0)]
		[HarmonyAfter(new string[] { "Azumatt.AzuExtendedPlayerInventory" })]
		[HarmonyPostfix]
		[HarmonyPatch(typeof(HotkeyBar), "UpdateIcons")]
		private static void HotkeyBar_UpdateIcons(HotkeyBar __instance, Player player)
		{
			if (Configs.EnableAmmoCount.Value)
			{
				UpdateAmmoAndIcon(__instance, player);
			}
		}
	}
	public static class Configs
	{
		internal static readonly ConfigEntry<bool> EnableAmmoCount;

		internal static readonly ConfigEntry<bool> RemoveLensDirt;

		internal static readonly ConfigEntry<bool> HideModdedText;

		internal static readonly ConfigEntry<StringList> RemoveRichText;

		static Configs()
		{
			//IL_005c: 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_006c: Expected O, but got Unknown
			//IL_0076: Expected O, but got Unknown
			HideModdedText = Config.Define<bool>(false, "General", "Hide Modded Text On Title Screen", false, "Hide the modded text on the title screen. (Restart required)");
			EnableAmmoCount = Config.Define<bool>(true, "General", "Enable Ammo Count", true, "When true an icon and count appears on the hotbar with ammo type and count. (Logout required)");
			RemoveLensDirt = Config.Define<bool>(true, "General", "Remove Lens Dirt", true, "Remove the lens dirt from the camera. (Logout required)");
			StringList val = new StringList();
			((List<string>)val).Add("_RtD$");
			RemoveRichText = Config.Define<StringList>(true, "General", "Remove Rich Text From Translations", val, "Comma separated list of regex patterns. Match against the translation keys. \r\nMatched keys have their translations stripped of rich text.\r\nSome mods add rich text tags like <color> to their translations.\r\nIn order to provide a consistant UI theme you can remove those tags from the translations of matched keys.\r\nIf you don't want to remove any tags then leave the list empty. (Default is to remove the rich text on RtD mods)\r\nIf you need help with regex patterns then check out https://regex101.com/ or ask an AI.");
		}
	}
	internal static class ItemIcon
	{
		private static class Configs
		{
			public static readonly ConfigEntry<Color> DurabilityGood;

			public static readonly ConfigEntry<Color> DurabilityWorn;

			public static readonly ConfigEntry<Color> DurabilityAtRisk;

			public static readonly ConfigEntry<Color> DurabilityBroken;

			public static readonly ConfigEntry<bool> ShowQualityAsSymbols;

			public static readonly ConfigEntry<bool> Rotate90Degrees;

			public static readonly ConfigEntry<Color> ItemQualitySymbolColor;

			public static readonly ConfigEntry<string> ExtraQualityLevelSym;

			static Configs()
			{
				//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_001d: 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_003d: 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_0065: 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_0077: 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_00ec: 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_00fe: Unknown result type (might be due to invalid IL or missing references)
				Color green = Color.green;
				green.a = 0.2f;
				DurabilityGood = Config.Define<Color>(true, "Item Durability Bars", "Durability Good", green, "Durability bar color when durability is good");
				green = Color.yellow;
				green.a = 0.5f;
				DurabilityWorn = Config.Define<Color>(true, "Item Durability Bars", "Durability Worn", green, "Durability bar color when durability is worn");
				green = Color.red;
				green.a = 0.7f;
				DurabilityAtRisk = Config.Define<Color>(true, "Item Durability Bars", "Durability At Risk", green, "Durability bar color when durability is at risk of breaking");
				DurabilityBroken = Config.Define<Color>(true, "Item Durability Bars", "Durability Broken", Color.gray, "Durability bar color when item is broken");
				ShowQualityAsSymbols = Config.Define<bool>(true, "Item Quality Symbols", "Show Quality As Symbols", true, "Item quality is shown as symbols instead of numbers on the inventory grid.");
				Rotate90Degrees = Config.Define<bool>(true, "Item Quality Symbols", "Rotate Symbols 90 Degrees", false, "The quality symbols are rotated 90 degrees to display them vertically instead of horizontally. This is only used if Show Quality As Symbols is enabled.");
				green = UIColor.LightYellow.Color;
				green.a = 0.6f;
				ItemQualitySymbolColor = Config.Define<Color>(true, "Item Quality Symbols", "Symbol Color", green, "Color of the item quality symbols");
				ExtraQualityLevelSym = Config.Define<string>(true, "Item Quality Symbols", "Extra Level Symbols", "★", "The sequence of symbols used to display the quality level. The first symbol is always the dots and can not be changed.\r\nEach symbol adds 4 levels. Preconfigured with 1 symobl so 8 levels supported: Vanilla 4 + 1 symbol x 4 more levels.\r\nSo if you wanted to add 8 more levels for a total of 12 levels (4 + 8), you would add 2 more symbols to the end of the sequence.\r\nHere are some extra symbols you can try.  Not all unicode works, These are known to work: ★✽◈⚡▲\r\nExample: ★▲ would be 4 vanilla levels + 4 more levels for ★ + 4 more levels for ▲\r\nNOTE: If your item level exceeds this value it will be displayed as a number instead of a symbol.");
			}
		}

		[HarmonyPatch(typeof(InventoryGrid), "UpdateGui")]
		private class InventoryGrid_UpdateGui_DurabilityAndScale
		{
			private static bool HideEquipmentSlotsQuality(InventoryGrid grid, ItemData item)
			{
				if (!(((Object)grid).name == "EquipmentSlotGrid"))
				{
					return item.m_quality < 2;
				}
				return true;
			}

			[UsedImplicitly]
			private static void Postfix(InventoryGrid __instance, Inventory ___m_inventory, List<Element> ___m_elements)
			{
				//IL_0065: Unknown result type (might be due to invalid IL or missing references)
				int width = ___m_inventory.GetWidth();
				foreach (ItemData allItem in ___m_inventory.GetAllItems())
				{
					int num = allItem.m_gridPos.y * width + allItem.m_gridPos.x;
					if (0 <= num && num < ___m_elements.Count)
					{
						Element val = ___m_elements[num];
						UpdateItemIcon(val.m_durability, val.m_icon, val.m_equiped, ItemEquippedInventoryColor);
						if (HideEquipmentSlotsQuality(__instance, allItem))
						{
							val.m_quality.SetText("");
						}
						else
						{
							UpdateItemQuality(val.m_quality, allItem.m_quality);
						}
					}
				}
			}
		}

		[HarmonyPatch(typeof(HotkeyBar), "UpdateIcons")]
		private class HotkeyBar_UpdateIcons_DurabilityAndScale
		{
			[HarmonyPriority(0)]
			private static void Postfix(HotkeyBar __instance, Player player)
			{
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)player) || ((Character)player).IsDead())
				{
					return;
				}
				foreach (ElementData element in __instance.m_elements)
				{
					Image component = element.m_equiped.GetComponent<Image>();
					UpdateItemIcon(element.m_durability, element.m_icon, component, ItemEquippedHotbarColor);
				}
			}
		}

		private static readonly Color ItemEquippedInventoryColor;

		private static readonly Color ItemEquippedHotbarColor;

		private const float ItemQualitySymbolSizeDots = 14f;

		private const float ItemQualitySymbolSizeEtc = 12f;

		private const float ItemQualityLineSpacing = -35f;

		private const float ItemQualityCharacterSpacing = 8f;

		private static Color _itemEquippedColorOriginal;

		private const int MaxDots = 4;

		private const char Dot = '*';

		private static char _maxQualitySymbol;

		private static string[] _itemQualitySymbols;

		static ItemIcon()
		{
			//IL_0011: 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_001b: 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_003b: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			ItemEquippedInventoryColor = Color32.op_Implicit(new Color32((byte)190, (byte)184, (byte)135, (byte)127));
			ItemEquippedHotbarColor = Color32.op_Implicit(new Color32((byte)190, (byte)184, (byte)135, (byte)127));
			_itemEquippedColorOriginal = Color.clear;
			_itemQualitySymbols = CreateQualityStars(out _maxQualitySymbol);
			Configs.ExtraQualityLevelSym.SettingChanged += OnQualitySymLevelChanged;
		}

		private static void OnQualitySymLevelChanged(object? sender, EventArgs e)
		{
			Log.Message((object)"Refreshing the item quality symbols", (ushort)0);
			_itemQualitySymbols = CreateQualityStars(out _maxQualitySymbol);
		}

		private static string[] CreateQualityStars(out char maxQualitySym)
		{
			string text = "*" + Configs.ExtraQualityLevelSym.Value;
			maxQualitySym = text[text.Length - 1];
			List<string> list = new List<string> { string.Empty };
			string text2 = text;
			for (int i = 0; i < text2.Length; i++)
			{
				char c = text2[i];
				for (int j = 0; j < 4; j++)
				{
					list.Add(c + new string('*', j));
				}
			}
			foreach (var item in IEnumerableExt.WithIndex<string>((IEnumerable<string>)list))
			{
				Log.Info((object)$"{item.Item2:D2}: {item.Item1}", (ushort)0);
			}
			Log.Message((object)$"Max item quality level: {list.Count - 1} (overflow is allowed)", (ushort)0);
			return list.ToArray();
		}

		private static void UpdateItemIcon(GuiBar durability, Image icon, Image equiped, Color equipColor)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_0025: 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_001f: 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_003f: 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_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_00eb: 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)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)equiped))
			{
				if (_itemEquippedColorOriginal == Color.clear)
				{
					_itemEquippedColorOriginal = ((Graphic)equiped).color;
				}
				if (equipColor != Color.clear)
				{
					((Graphic)equiped).color = equipColor;
				}
				else if (_itemEquippedColorOriginal != Color.clear)
				{
					((Graphic)equiped).color = _itemEquippedColorOriginal;
				}
			}
			if (!Object.op_Implicit((Object)(object)durability))
			{
				return;
			}
			if (!Object.op_Implicit((Object)(object)durability.m_barImage) && Object.op_Implicit((Object)(object)durability.m_bar))
			{
				durability.m_barImage = ((Component)durability.m_bar).GetComponent<Image>();
			}
			float smoothValue = durability.GetSmoothValue();
			if (smoothValue >= 1f)
			{
				if (durability.GetColor() == Color.red)
				{
					durability.SetColor(Configs.DurabilityBroken.Value);
				}
				else if (durability.GetColor() != Color.clear)
				{
					((Component)durability).gameObject.SetActive(false);
				}
			}
			else if (smoothValue >= 0.75f)
			{
				durability.SetColor(Configs.DurabilityGood.Value);
			}
			else if (smoothValue >= 0.5f)
			{
				durability.SetColor(Configs.DurabilityWorn.Value);
			}
			else if (smoothValue > 0f)
			{
				durability.SetColor(Configs.DurabilityAtRisk.Value);
			}
			else
			{
				durability.SetColor(Configs.DurabilityBroken.Value);
			}
		}

		private static void UpdateItemQuality(TMP_Text uiElement, int quality)
		{
			//IL_0078: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			if (!((Behaviour)uiElement).enabled)
			{
				return;
			}
			if (quality < 0)
			{
				uiElement.text = string.Empty;
				return;
			}
			string text = $"{quality}{_maxQualitySymbol}";
			string text2 = ((quality < _itemQualitySymbols.Length && Configs.ShowQualityAsSymbols.Value) ? _itemQualitySymbols[quality] : text);
			if (!(uiElement.text == text2))
			{
				uiElement.text = text2;
				uiElement.textWrappingMode = (TextWrappingModes)3;
				((Graphic)uiElement).color = Configs.ItemQualitySymbolColor.Value;
				uiElement.lineSpacing = -35f;
				uiElement.characterSpacing = 8f;
				uiElement.rectTransform.pivot = new Vector2(1f, 1f);
				uiElement.rectTransform.anchorMin = new Vector2(1f, 1f);
				uiElement.rectTransform.anchorMax = new Vector2(1f, 1f);
				if (!Configs.Rotate90Degrees.Value || !Configs.ShowQualityAsSymbols.Value || quality >= _itemQualitySymbols.Length)
				{
					uiElement.fontSize = 14f;
					uiElement.isRightToLeftText = quality < _itemQualitySymbols.Length;
					((Transform)uiElement.rectTransform).localRotation = Quaternion.Euler(0f, 0f, 0f);
					uiElement.rectTransform.anchoredPosition = new Vector2(-4f, 2f);
				}
				else
				{
					uiElement.isRightToLeftText = false;
					uiElement.fontSize = ((quality <= 4) ? 14f : 12f);
					((Transform)uiElement.rectTransform).localRotation = Quaternion.Euler(0f, 0f, -90f);
					uiElement.rectTransform.anchoredPosition = new Vector2(1f, 0f - uiElement.preferredWidth - 4f);
				}
			}
		}
	}
	public static class LensDirt
	{
		public static void RemoveDirt()
		{
			GameCamera instance = GameCamera.instance;
			if (Object.op_Implicit((Object)(object)instance))
			{
				PostProcessingBehaviour component = ((Component)instance).gameObject.GetComponent<PostProcessingBehaviour>();
				if (Object.op_Implicit((Object)(object)component))
				{
					component.profile.bloom.m_Settings.lensDirt.intensity = 0f;
				}
			}
		}
	}
	[HarmonyPatch]
	public static class Patches
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(FejdStartup), "Start")]
		private static void FejdStartup_Start(FejdStartup __instance)
		{
			__instance.m_moddedText.SetActive(!Configs.HideModdedText.Value);
		}
	}
	[BepInPlugin("ZenDragon.ZenUI", "ZenUI", "0.2.4")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	internal class Plugin : ZenMod<Plugin>
	{
		public const string PluginName = "ZenUI";

		public const string PluginVersion = "0.2.4";

		public const string PluginGUID = "ZenDragon.ZenUI";

		protected override void Setup()
		{
			((ZenMod)this).LanguageChanged += OnLanguageChanged;
		}

		protected override void TitleScene(bool isFirstBoot)
		{
		}

		protected override void WorldStart()
		{
			if (Configs.RemoveLensDirt.Value)
			{
				LensDirt.RemoveDirt();
			}
		}

		protected override void Shutdown()
		{
		}

		private void OnLanguageChanged(string language)
		{
			RemoveRichTextTags();
		}

		private static void RemoveRichTextTags()
		{
			if (((List<string>)(object)Configs.RemoveRichText.Value).Count == 0)
			{
				return;
			}
			Log.Info((object)"Applying configs to remove rich text tags from translations", (ushort)0);
			List<string> list = new List<string>();
			Dictionary<string, string> translations = Localization.instance.m_translations;
			foreach (var (text2, text3) in IEnumerableExt.AsTuple<string, string>(translations))
			{
				if (IsMatch(text2) && text3.Contains("<") && text3.Contains(">"))
				{
					list.Add(text2);
				}
			}
			foreach (string item in list)
			{
				Log.Info((object)("Tags removed from " + item), (ushort)0);
				translations[item] = StringExtensionMethods.RemoveRichTextTags(translations[item]);
			}
			static bool IsMatch(string text)
			{
				string text4 = text;
				return ((IEnumerable<string>)Configs.RemoveRichText.Value).Any((string pattern) => Regex.Match(text4, pattern).Success);
			}
		}
	}
}