Decompiled source of HZ InventoryKeybinds v1.0.0

HZ_InventoryKeybinds.dll

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

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("HZ_InventoryKeybinds")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HZ_InventoryKeybinds")]
[assembly: AssemblyTitle("HZ_InventoryKeybinds")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ExtendedInventory
{
	internal sealed class ConfigurationManagerAttributes
	{
		public Action<ConfigEntryBase> CustomDrawer;

		public bool? Browsable;

		public int? Order;
	}
	internal class EquipmentPanel : MonoBehaviour
	{
		private class SlotElement
		{
			public GameObject Go;

			public Image Icon;

			public GuiBar Durability;

			public UITooltip Tooltip;
		}

		private static readonly ItemType[] SlotTypes;

		private const float SlotScale = 0.69f;

		private const float BaseVerticalSpacing = 70f;

		private const float VerticalSpacing = 48.3f;

		private readonly SlotElement[] _slots = new SlotElement[SlotTypes.Length];

		private bool _built;

		private Transform _content;

		private void Update()
		{
			//IL_0153: 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)
			bool flag = ModConfig.IsInitialized && ModConfig.ShowEquipmentPanel.Value;
			if (!_built)
			{
				Build();
			}
			if ((Object)(object)_content != (Object)null && ((Component)_content).gameObject.activeSelf != flag)
			{
				((Component)_content).gameObject.SetActive(flag);
			}
			if (!flag)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			for (int i = 0; i < _slots.Length; i++)
			{
				SlotElement slotElement = _slots[i];
				if (slotElement == null)
				{
					continue;
				}
				ItemData equippedItem = GetEquippedItem(localPlayer, SlotTypes[i]);
				if (equippedItem != null)
				{
					((Behaviour)slotElement.Icon).enabled = true;
					slotElement.Icon.sprite = equippedItem.GetIcon();
					if ((Object)(object)slotElement.Durability != (Object)null)
					{
						bool flag2 = equippedItem.m_shared.m_useDurability && equippedItem.m_durability < equippedItem.GetMaxDurability();
						((Component)slotElement.Durability).gameObject.SetActive(flag2);
						if (flag2)
						{
							if (equippedItem.m_durability <= 0f)
							{
								slotElement.Durability.SetValue(1f);
								slotElement.Durability.SetColor((Color)((Mathf.Sin(Time.time * 10f) > 0f) ? Color.red : new Color(0f, 0f, 0f, 0f)));
							}
							else
							{
								slotElement.Durability.SetValue(equippedItem.GetDurabilityPercentage());
								slotElement.Durability.ResetColor();
							}
						}
					}
					if ((Object)(object)slotElement.Tooltip != (Object)null)
					{
						slotElement.Tooltip.m_text = Localization.instance.Localize(equippedItem.m_shared.m_name);
					}
				}
				else
				{
					((Behaviour)slotElement.Icon).enabled = false;
					if ((Object)(object)slotElement.Durability != (Object)null)
					{
						((Component)slotElement.Durability).gameObject.SetActive(false);
					}
					if ((Object)(object)slotElement.Tooltip != (Object)null)
					{
						slotElement.Tooltip.m_text = "";
					}
				}
			}
		}

		private static ItemData GetEquippedItem(Player player, ItemType type)
		{
			//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)
			foreach (ItemData allItem in ((Humanoid)player).GetInventory().GetAllItems())
			{
				if (allItem.m_equipped && allItem.m_shared.m_itemType == type)
				{
					return allItem;
				}
			}
			return null;
		}

		private void Build()
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_006f: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			_built = true;
			HotkeyBar val = Object.FindFirstObjectByType<HotkeyBar>();
			if ((Object)(object)val == (Object)null || (Object)(object)val.m_elementPrefab == (Object)null)
			{
				Plugin.Log.LogWarning((object)"EquipmentPanel: HotkeyBar ou m_elementPrefab não encontrado.");
				return;
			}
			GameObject val2 = new GameObject("Content", new Type[1] { typeof(RectTransform) });
			val2.transform.SetParent(((Component)this).transform, false);
			Transform transform = val2.transform;
			((RectTransform)((transform is RectTransform) ? transform : null)).anchoredPosition = Vector2.zero;
			_content = val2.transform;
			for (int i = 0; i < SlotTypes.Length; i++)
			{
				GameObject val3 = Object.Instantiate<GameObject>(val.m_elementPrefab, _content);
				val3.SetActive(true);
				Transform transform2 = val3.transform;
				Transform obj = ((transform2 is RectTransform) ? transform2 : null);
				obj.localScale = new Vector3(0.69f, 0.69f, 1f);
				((RectTransform)obj).anchoredPosition = new Vector2(0f, (float)(-i) * 48.3f);
				SlotElement obj2 = new SlotElement
				{
					Go = val3
				};
				Transform obj3 = val3.transform.Find("icon");
				obj2.Icon = ((obj3 != null) ? ((Component)obj3).GetComponent<Image>() : null);
				Transform obj4 = val3.transform.Find("durability");
				obj2.Durability = ((obj4 != null) ? ((Component)obj4).GetComponent<GuiBar>() : null);
				obj2.Tooltip = val3.GetComponent<UITooltip>();
				SlotElement slotElement = obj2;
				Transform val4 = val3.transform.Find("amount");
				if ((Object)(object)val4 != (Object)null)
				{
					((Component)val4).gameObject.SetActive(false);
				}
				Transform val5 = val3.transform.Find("binding");
				if ((Object)(object)val5 != (Object)null)
				{
					((Component)val5).gameObject.SetActive(false);
				}
				Transform val6 = val3.transform.Find("queued");
				if ((Object)(object)val6 != (Object)null)
				{
					((Component)val6).gameObject.SetActive(false);
				}
				Transform val7 = val3.transform.Find("selected");
				if ((Object)(object)val7 != (Object)null)
				{
					((Component)val7).gameObject.SetActive(false);
				}
				Transform val8 = val3.transform.Find("equiped");
				if ((Object)(object)val8 != (Object)null)
				{
					((Component)val8).gameObject.SetActive(false);
				}
				_slots[i] = slotElement;
			}
		}

		static EquipmentPanel()
		{
			ItemType[] array = new ItemType[6];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			SlotTypes = (ItemType[])(object)array;
		}
	}
	[HarmonyPatch(typeof(Hud), "Awake")]
	internal class EquipmentPanelInstallPatch
	{
		internal static RectTransform PanelRect;

		[HarmonyPostfix]
		private static void Postfix(Hud __instance)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance.m_rootObject == (Object)null))
			{
				if ((Object)(object)Object.FindFirstObjectByType<HotkeyBar>() == (Object)null)
				{
					Plugin.Log.LogWarning((object)"EquipmentPanelInstallPatch: HotkeyBar não encontrado na cena.");
					return;
				}
				GameObject val = new GameObject("InventorySets_EquipmentPanel", new Type[1] { typeof(RectTransform) });
				val.transform.SetParent(__instance.m_rootObject.transform, false);
				PanelRect = val.GetComponent<RectTransform>();
				PanelRect.anchorMin = new Vector2(0f, 0.5f);
				PanelRect.anchorMax = new Vector2(0f, 0.5f);
				PanelRect.pivot = new Vector2(0f, 0.5f);
				PanelRect.anchoredPosition = new Vector2(50f, ModConfig.EquipmentPanelYOffset.Value);
				val.AddComponent<EquipmentPanel>();
			}
		}

		internal static void ApplyPosition()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)PanelRect != (Object)null)
			{
				PanelRect.anchoredPosition = new Vector2(50f, ModConfig.EquipmentPanelYOffset.Value);
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGrid), "UpdateGui")]
	internal class InventoryGridLabelPatch
	{
		private static readonly FieldRef<InventoryGrid, IList> ElementsField = AccessTools.FieldRefAccess<InventoryGrid, IList>("m_elements");

		[HarmonyPostfix]
		private static void Postfix(InventoryGrid __instance, Player player)
		{
			//IL_0060: 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_0067: 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_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player == (Object)null || !ModConfig.IsInitialized)
			{
				return;
			}
			int value = ModConfig.SecondRowSlotCount.Value;
			if (value <= 0)
			{
				return;
			}
			IList list = ElementsField.Invoke(__instance);
			if (list == null)
			{
				return;
			}
			foreach (object item in list)
			{
				Type type = item.GetType();
				Vector2i val = (Vector2i)AccessTools.Field(type, "m_pos").GetValue(item);
				if (val.y != 1 || val.x >= value)
				{
					continue;
				}
				GameObject val2 = (GameObject)AccessTools.Field(type, "m_go").GetValue(item);
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				Transform val3 = val2.transform.Find("binding");
				if (!((Object)(object)val3 == (Object)null))
				{
					TMP_Text component = ((Component)val3).GetComponent<TMP_Text>();
					if (!((Object)(object)component == (Object)null))
					{
						((Behaviour)component).enabled = true;
						component.text = ModConfig.GetRow2ShortcutDisplayName(val.x);
					}
				}
			}
		}
	}
	internal static class KeyCodePathMap
	{
		private static readonly Dictionary<KeyCode, string> Map = new Dictionary<KeyCode, string>
		{
			{
				(KeyCode)48,
				"<Keyboard>/0"
			},
			{
				(KeyCode)49,
				"<Keyboard>/1"
			},
			{
				(KeyCode)50,
				"<Keyboard>/2"
			},
			{
				(KeyCode)51,
				"<Keyboard>/3"
			},
			{
				(KeyCode)52,
				"<Keyboard>/4"
			},
			{
				(KeyCode)53,
				"<Keyboard>/5"
			},
			{
				(KeyCode)54,
				"<Keyboard>/6"
			},
			{
				(KeyCode)55,
				"<Keyboard>/7"
			},
			{
				(KeyCode)56,
				"<Keyboard>/8"
			},
			{
				(KeyCode)57,
				"<Keyboard>/9"
			},
			{
				(KeyCode)97,
				"<Keyboard>/a"
			},
			{
				(KeyCode)98,
				"<Keyboard>/b"
			},
			{
				(KeyCode)99,
				"<Keyboard>/c"
			},
			{
				(KeyCode)100,
				"<Keyboard>/d"
			},
			{
				(KeyCode)101,
				"<Keyboard>/e"
			},
			{
				(KeyCode)102,
				"<Keyboard>/f"
			},
			{
				(KeyCode)103,
				"<Keyboard>/g"
			},
			{
				(KeyCode)104,
				"<Keyboard>/h"
			},
			{
				(KeyCode)105,
				"<Keyboard>/i"
			},
			{
				(KeyCode)106,
				"<Keyboard>/j"
			},
			{
				(KeyCode)107,
				"<Keyboard>/k"
			},
			{
				(KeyCode)108,
				"<Keyboard>/l"
			},
			{
				(KeyCode)109,
				"<Keyboard>/m"
			},
			{
				(KeyCode)110,
				"<Keyboard>/n"
			},
			{
				(KeyCode)111,
				"<Keyboard>/o"
			},
			{
				(KeyCode)112,
				"<Keyboard>/p"
			},
			{
				(KeyCode)113,
				"<Keyboard>/q"
			},
			{
				(KeyCode)114,
				"<Keyboard>/r"
			},
			{
				(KeyCode)115,
				"<Keyboard>/s"
			},
			{
				(KeyCode)116,
				"<Keyboard>/t"
			},
			{
				(KeyCode)117,
				"<Keyboard>/u"
			},
			{
				(KeyCode)118,
				"<Keyboard>/v"
			},
			{
				(KeyCode)119,
				"<Keyboard>/w"
			},
			{
				(KeyCode)120,
				"<Keyboard>/x"
			},
			{
				(KeyCode)121,
				"<Keyboard>/y"
			},
			{
				(KeyCode)122,
				"<Keyboard>/z"
			},
			{
				(KeyCode)282,
				"<Keyboard>/f1"
			},
			{
				(KeyCode)283,
				"<Keyboard>/f2"
			},
			{
				(KeyCode)284,
				"<Keyboard>/f3"
			},
			{
				(KeyCode)285,
				"<Keyboard>/f4"
			},
			{
				(KeyCode)286,
				"<Keyboard>/f5"
			},
			{
				(KeyCode)287,
				"<Keyboard>/f6"
			},
			{
				(KeyCode)288,
				"<Keyboard>/f7"
			},
			{
				(KeyCode)289,
				"<Keyboard>/f8"
			},
			{
				(KeyCode)290,
				"<Keyboard>/f9"
			},
			{
				(KeyCode)291,
				"<Keyboard>/f10"
			},
			{
				(KeyCode)292,
				"<Keyboard>/f11"
			},
			{
				(KeyCode)293,
				"<Keyboard>/f12"
			},
			{
				(KeyCode)32,
				"<Keyboard>/space"
			},
			{
				(KeyCode)9,
				"<Keyboard>/tab"
			},
			{
				(KeyCode)301,
				"<Keyboard>/capsLock"
			},
			{
				(KeyCode)8,
				"<Keyboard>/backspace"
			},
			{
				(KeyCode)13,
				"<Keyboard>/enter"
			},
			{
				(KeyCode)27,
				"<Keyboard>/escape"
			},
			{
				(KeyCode)304,
				"<Keyboard>/leftShift"
			},
			{
				(KeyCode)303,
				"<Keyboard>/rightShift"
			},
			{
				(KeyCode)306,
				"<Keyboard>/leftCtrl"
			},
			{
				(KeyCode)305,
				"<Keyboard>/rightCtrl"
			},
			{
				(KeyCode)308,
				"<Keyboard>/leftAlt"
			},
			{
				(KeyCode)307,
				"<Keyboard>/rightAlt"
			},
			{
				(KeyCode)273,
				"<Keyboard>/upArrow"
			},
			{
				(KeyCode)274,
				"<Keyboard>/downArrow"
			},
			{
				(KeyCode)276,
				"<Keyboard>/leftArrow"
			},
			{
				(KeyCode)275,
				"<Keyboard>/rightArrow"
			},
			{
				(KeyCode)277,
				"<Keyboard>/insert"
			},
			{
				(KeyCode)127,
				"<Keyboard>/delete"
			},
			{
				(KeyCode)278,
				"<Keyboard>/home"
			},
			{
				(KeyCode)279,
				"<Keyboard>/end"
			},
			{
				(KeyCode)280,
				"<Keyboard>/pageUp"
			},
			{
				(KeyCode)281,
				"<Keyboard>/pageDown"
			},
			{
				(KeyCode)61,
				"<Keyboard>/equals"
			},
			{
				(KeyCode)45,
				"<Keyboard>/minus"
			},
			{
				(KeyCode)96,
				"<Keyboard>/backquote"
			},
			{
				(KeyCode)91,
				"<Keyboard>/leftBracket"
			},
			{
				(KeyCode)93,
				"<Keyboard>/rightBracket"
			},
			{
				(KeyCode)59,
				"<Keyboard>/semicolon"
			},
			{
				(KeyCode)39,
				"<Keyboard>/quote"
			},
			{
				(KeyCode)44,
				"<Keyboard>/comma"
			},
			{
				(KeyCode)46,
				"<Keyboard>/period"
			},
			{
				(KeyCode)47,
				"<Keyboard>/slash"
			},
			{
				(KeyCode)92,
				"<Keyboard>/backslash"
			},
			{
				(KeyCode)256,
				"<Keyboard>/numpad0"
			},
			{
				(KeyCode)257,
				"<Keyboard>/numpad1"
			},
			{
				(KeyCode)258,
				"<Keyboard>/numpad2"
			},
			{
				(KeyCode)259,
				"<Keyboard>/numpad3"
			},
			{
				(KeyCode)260,
				"<Keyboard>/numpad4"
			},
			{
				(KeyCode)261,
				"<Keyboard>/numpad5"
			},
			{
				(KeyCode)262,
				"<Keyboard>/numpad6"
			},
			{
				(KeyCode)263,
				"<Keyboard>/numpad7"
			},
			{
				(KeyCode)264,
				"<Keyboard>/numpad8"
			},
			{
				(KeyCode)265,
				"<Keyboard>/numpad9"
			},
			{
				(KeyCode)266,
				"<Keyboard>/numpadPeriod"
			},
			{
				(KeyCode)267,
				"<Keyboard>/numpadDivide"
			},
			{
				(KeyCode)268,
				"<Keyboard>/numpadMultiply"
			},
			{
				(KeyCode)269,
				"<Keyboard>/numpadMinus"
			},
			{
				(KeyCode)270,
				"<Keyboard>/numpadPlus"
			},
			{
				(KeyCode)271,
				"<Keyboard>/numpadEnter"
			},
			{
				(KeyCode)323,
				"<Mouse>/leftButton"
			},
			{
				(KeyCode)324,
				"<Mouse>/rightButton"
			},
			{
				(KeyCode)325,
				"<Mouse>/middleButton"
			},
			{
				(KeyCode)326,
				"<Mouse>/button3"
			},
			{
				(KeyCode)327,
				"<Mouse>/button4"
			},
			{
				(KeyCode)328,
				"<Mouse>/button5"
			},
			{
				(KeyCode)329,
				"<Mouse>/button6"
			}
		};

		public static string ToPath(KeyCode key)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			if (Map.TryGetValue(key, out var value))
			{
				return value;
			}
			return null;
		}
	}
	internal static class MessageHudOffsetPatch
	{
		private static Vector2? _originalTextPos;

		private static Vector2? _originalIconPos;

		[HarmonyPatch(typeof(MessageHud), "Awake")]
		[HarmonyPostfix]
		private static void Postfix(MessageHud __instance)
		{
			CacheOriginalPositions(__instance);
			((MonoBehaviour)__instance).StartCoroutine(DelayedApply(__instance));
		}

		private static IEnumerator DelayedApply(MessageHud hud)
		{
			ApplyOffset(hud);
			yield return (object)new WaitForSeconds(1.5f);
			ApplyOffset(hud);
			yield return (object)new WaitForSeconds(2f);
			ApplyOffset(hud);
			yield return (object)new WaitForSeconds(3f);
			ApplyOffset(hud);
		}

		private static void CacheOriginalPositions(MessageHud instance)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)instance == (Object)null))
			{
				TMP_Text messageText = instance.m_messageText;
				Transform obj = ((messageText != null) ? messageText.transform : null);
				RectTransform val = (RectTransform)(object)((obj is RectTransform) ? obj : null);
				Image messageIcon = instance.m_messageIcon;
				Transform obj2 = ((messageIcon != null) ? ((Component)messageIcon).transform : null);
				RectTransform val2 = (RectTransform)(object)((obj2 is RectTransform) ? obj2 : null);
				if ((Object)(object)val != (Object)null)
				{
					_originalTextPos = val.anchoredPosition;
				}
				if ((Object)(object)val2 != (Object)null)
				{
					_originalIconPos = val2.anchoredPosition;
				}
			}
		}

		public static void ApplyOffset(MessageHud instance = null)
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			if (instance == null)
			{
				instance = MessageHud.instance;
			}
			if (!((Object)(object)instance == (Object)null))
			{
				if (!_originalTextPos.HasValue || !_originalIconPos.HasValue)
				{
					CacheOriginalPositions(instance);
				}
				float num = ((ModConfig.IsInitialized && ModConfig.SecondRowSlotCount.Value >= 1) ? ModConfig.TopLeftMessageOffset.Value : 0f);
				TMP_Text messageText = instance.m_messageText;
				Transform obj = ((messageText != null) ? messageText.transform : null);
				RectTransform val = (RectTransform)(object)((obj is RectTransform) ? obj : null);
				Image messageIcon = instance.m_messageIcon;
				Transform obj2 = ((messageIcon != null) ? ((Component)messageIcon).transform : null);
				RectTransform val2 = (RectTransform)(object)((obj2 is RectTransform) ? obj2 : null);
				if ((Object)(object)val != (Object)null)
				{
					val.anchoredPosition = _originalTextPos.Value + new Vector2(0f, 0f - num);
				}
				if ((Object)(object)val2 != (Object)null)
				{
					val2.anchoredPosition = _originalIconPos.Value + new Vector2(0f, 0f - num);
				}
				Plugin.Log.LogInfo((object)$"ApplyOffset executado | Offset = {num}");
			}
		}
	}
	internal static class ModConfig
	{
		private const string GeneralSection = "General";

		private const string SecondRowSection = "SecondRow";

		public const int MaxRowSlots = 8;

		private static ConfigEntry<KeyboardShortcut>[] _row2Shortcuts;

		public static bool IsInitialized { get; private set; }

		public static ConfigEntry<bool> ShowEquipmentPanel { get; private set; }

		public static ConfigEntry<int> SecondRowSlotCount { get; private set; }

		public static ConfigEntry<float> EquipmentPanelYOffset { get; private set; }

		public static ConfigEntry<float> TopLeftMessageOffset { get; private set; }

		public static void Init(ConfigFile config)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			MessageHudOffsetPatch.ApplyOffset();
			ShowEquipmentPanel = config.Bind<bool>("General", "ShowEquipmentPanel", true, "Mostra o painel vertical com o set equipado (capacete, peito, pernas, capa), mesmo com o inventário fechado.");
			EquipmentPanelYOffset = config.Bind<float>("General", "EquipmentPanelYOffset", -50f, new ConfigDescription("Ajusta a posição vertical do painel de equipamentos.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-50f, 100f), Array.Empty<object>()));
			SecondRowSlotCount = config.Bind<int>("General", "SecondRowSlotCount", 0, new ConfigDescription("Quantos slots da 2ª linha do inventário recebem atalho de teclado, habilitados da esquerda pra direita. 0 desativa a 2ª linha.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 8), Array.Empty<object>()));
			_row2Shortcuts = new ConfigEntry<KeyboardShortcut>[8];
			TopLeftMessageOffset = config.Bind<float>("General", "Message-Offset", 75f, "Quantos pixels empurrar pra baixo as mensagens de status (cansado, molhado, abrigado etc.) quando a 2ª linha da hotbar estiver ativa (1+ slots), pra evitar sobreposição visual.");
			SecondRowSlotCount.SettingChanged += delegate
			{
				MessageHudOffsetPatch.ApplyOffset();
			};
			TopLeftMessageOffset.SettingChanged += delegate
			{
				MessageHudOffsetPatch.ApplyOffset();
			};
			EquipmentPanelYOffset.SettingChanged += delegate
			{
				EquipmentPanelInstallPatch.ApplyPosition();
			};
			for (int num = 0; num < 8; num++)
			{
				int slot = num;
				_row2Shortcuts[num] = config.Bind<KeyboardShortcut>("SecondRow", $"Row2Slot{num + 1}", new KeyboardShortcut((KeyCode)0, Array.Empty<KeyCode>()), $"Atalho para o slot {num + 1} da 2ª linha do inventário.");
				_row2Shortcuts[num].SettingChanged += delegate
				{
					ApplyToZInput(slot);
				};
			}
			IsInitialized = true;
			MessageHudOffsetPatch.ApplyOffset();
			EquipmentPanelInstallPatch.ApplyPosition();
			if (ZInput.instance != null)
			{
				ApplyAllToZInput(ZInput.instance);
				MessageHudOffsetPatch.ApplyOffset();
			}
		}

		public static string Row2ActionName(int slotIndex)
		{
			return $"HotbarRow2Slot{slotIndex + 1}";
		}

		public static KeyboardShortcut GetRow2Shortcut(int slotIndex)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			if (_row2Shortcuts == null || slotIndex < 0 || slotIndex >= _row2Shortcuts.Length)
			{
				return KeyboardShortcut.Empty;
			}
			return _row2Shortcuts[slotIndex].Value;
		}

		public static string GetRow2ShortcutDisplayName(int slotIndex)
		{
			//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_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			KeyboardShortcut row2Shortcut = GetRow2Shortcut(slotIndex);
			if ((int)((KeyboardShortcut)(ref row2Shortcut)).MainKey == 0)
			{
				return "";
			}
			return KeyCodeToShortLabel(((KeyboardShortcut)(ref row2Shortcut)).MainKey);
		}

		public static void ApplyToZInput(int slotIndex, ZInput zInput = null)
		{
			//IL_000f: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			if (zInput == null)
			{
				zInput = ZInput.instance;
			}
			if (zInput == null)
			{
				return;
			}
			KeyboardShortcut row2Shortcut = GetRow2Shortcut(slotIndex);
			string text = (((int)((KeyboardShortcut)(ref row2Shortcut)).MainKey == 0) ? "<Keyboard>/None" : KeyCodePathMap.ToPath(((KeyboardShortcut)(ref row2Shortcut)).MainKey));
			if (string.IsNullOrEmpty(text))
			{
				Plugin.Log.LogWarning((object)$"Não foi possível mapear {((KeyboardShortcut)(ref row2Shortcut)).MainKey} pro slot {slotIndex + 1} da 2ª linha.");
				return;
			}
			ButtonDef buttonDef = zInput.GetButtonDef(Row2ActionName(slotIndex));
			if (buttonDef != null)
			{
				buttonDef.Rebind(text);
			}
		}

		public static void ApplyAllToZInput(ZInput zInput = null)
		{
			for (int i = 0; i < 8; i++)
			{
				ApplyToZInput(i, zInput);
			}
		}

		private unsafe static string KeyCodeToShortLabel(KeyCode key)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Invalid comparison between Unknown and I4
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: 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_000f: Expected I4, but got Unknown
			if ((int)key >= 48 && (int)key <= 57)
			{
				return (key - 48).ToString();
			}
			if ((int)key >= 97)
			{
				_ = 122;
				return ((object)(*(KeyCode*)(&key))/*cast due to .constrained prefix*/).ToString();
			}
			return ((object)(*(KeyCode*)(&key))/*cast due to .constrained prefix*/).ToString();
		}
	}
	[BepInPlugin("hz.inventory_keybinds", "HZ_InventoryKeybinds", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string ModGuid = "hz.inventory_keybinds";

		public const string ModName = "HZ_InventoryKeybinds";

		public const string ModVersion = "1.0.0";

		internal static Plugin Instance { get; private set; }

		internal static Harmony Harmony { get; private set; }

		internal static ManualLogSource Log => ((BaseUnityPlugin)Instance).Logger;

		private void Awake()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			Instance = this;
			ModConfig.Init(((BaseUnityPlugin)this).Config);
			Harmony = new Harmony("hz.inventory_keybinds");
			Harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"HZ_InventoryKeybinds 1.0.0 loaded.");
		}

		private void OnDestroy()
		{
			Harmony harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	internal class SecondHotbarRow : MonoBehaviour
	{
		private class SlotElement
		{
			public GameObject Go;

			public Image Icon;

			public TMP_Text Amount;

			public TMP_Text Binding;

			public GameObject Equiped;

			public GameObject Queued;

			public GuiBar Durability;
		}

		private readonly List<SlotElement> _slots = new List<SlotElement>();

		private int _builtCount = -1;

		private void Update()
		{
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			int num = (ModConfig.IsInitialized ? ModConfig.SecondRowSlotCount.Value : 0);
			if (num != _builtCount)
			{
				Rebuild(num);
			}
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			for (int i = 0; i < _slots.Count; i++)
			{
				SlotElement slotElement = _slots[i];
				ItemData itemAt = ((Humanoid)localPlayer).GetInventory().GetItemAt(i, 1);
				bool flag = itemAt != null;
				if (slotElement.Go.activeSelf != flag)
				{
					slotElement.Go.SetActive(flag);
				}
				if (!flag)
				{
					continue;
				}
				((Behaviour)slotElement.Icon).enabled = true;
				slotElement.Icon.sprite = itemAt.GetIcon();
				if (itemAt.m_shared.m_maxStackSize > 1)
				{
					((Behaviour)slotElement.Amount).enabled = true;
					slotElement.Amount.text = $"{itemAt.m_stack}/{itemAt.m_shared.m_maxStackSize}";
				}
				else
				{
					((Behaviour)slotElement.Amount).enabled = false;
				}
				if ((Object)(object)slotElement.Equiped != (Object)null)
				{
					slotElement.Equiped.SetActive(itemAt.m_equipped);
				}
				if ((Object)(object)slotElement.Queued != (Object)null)
				{
					slotElement.Queued.SetActive(localPlayer.IsEquipActionQueued(itemAt));
				}
				if ((Object)(object)slotElement.Durability != (Object)null)
				{
					bool flag2 = itemAt.m_shared.m_useDurability && itemAt.m_durability < itemAt.GetMaxDurability();
					((Component)slotElement.Durability).gameObject.SetActive(flag2);
					if (flag2)
					{
						if (itemAt.m_durability <= 0f)
						{
							slotElement.Durability.SetValue(1f);
							slotElement.Durability.SetColor((Color)((Mathf.Sin(Time.time * 10f) > 0f) ? Color.red : new Color(0f, 0f, 0f, 0f)));
						}
						else
						{
							slotElement.Durability.SetValue(itemAt.GetDurabilityPercentage());
							slotElement.Durability.ResetColor();
						}
					}
				}
				slotElement.Binding.text = ModConfig.GetRow2ShortcutDisplayName(i);
			}
		}

		private void Rebuild(int count)
		{
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			foreach (SlotElement slot in _slots)
			{
				Object.Destroy((Object)(object)slot.Go);
			}
			_slots.Clear();
			HotkeyBar val = Object.FindFirstObjectByType<HotkeyBar>();
			if ((Object)(object)val == (Object)null || (Object)(object)val.m_elementPrefab == (Object)null)
			{
				Plugin.Log.LogWarning((object)"SecondHotbarRow: HotkeyBar ou m_elementPrefab não encontrado.");
				_builtCount = count;
				return;
			}
			for (int i = 0; i < count; i++)
			{
				GameObject val2 = Object.Instantiate<GameObject>(val.m_elementPrefab, ((Component)this).transform);
				val2.SetActive(true);
				Transform transform = val2.transform;
				((RectTransform)((transform is RectTransform) ? transform : null)).anchoredPosition = new Vector2((float)i * val.m_elementSpace, 0f);
				SlotElement obj = new SlotElement
				{
					Go = val2
				};
				Transform obj2 = val2.transform.Find("icon");
				obj.Icon = ((obj2 != null) ? ((Component)obj2).GetComponent<Image>() : null);
				Transform obj3 = val2.transform.Find("amount");
				obj.Amount = ((obj3 != null) ? ((Component)obj3).GetComponent<TMP_Text>() : null);
				Transform obj4 = val2.transform.Find("binding");
				obj.Binding = ((obj4 != null) ? ((Component)obj4).GetComponent<TMP_Text>() : null);
				Transform obj5 = val2.transform.Find("equiped");
				obj.Equiped = ((obj5 != null) ? ((Component)obj5).gameObject : null);
				Transform obj6 = val2.transform.Find("queued");
				obj.Queued = ((obj6 != null) ? ((Component)obj6).gameObject : null);
				Transform obj7 = val2.transform.Find("durability");
				obj.Durability = ((obj7 != null) ? ((Component)obj7).GetComponent<GuiBar>() : null);
				SlotElement item = obj;
				Transform val3 = val2.transform.Find("selected");
				if ((Object)(object)val3 != (Object)null)
				{
					((Component)val3).gameObject.SetActive(false);
				}
				_slots.Add(item);
			}
			_builtCount = count;
		}
	}
	[HarmonyPatch(typeof(Hud), "Awake")]
	internal class SecondHotbarRowInstallPatch
	{
		[HarmonyPostfix]
		private static void Postfix(Hud __instance)
		{
			//IL_0046: 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_006e: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance.m_rootObject == (Object)null))
			{
				HotkeyBar val = Object.FindFirstObjectByType<HotkeyBar>();
				if ((Object)(object)val == (Object)null)
				{
					Plugin.Log.LogWarning((object)"SecondHotbarRowInstallPatch: HotkeyBar não encontrado na cena.");
					return;
				}
				GameObject val2 = new GameObject("InventorySets_SecondHotbarRow", new Type[1] { typeof(RectTransform) });
				val2.transform.SetParent(__instance.m_rootObject.transform, false);
				Transform transform = ((Component)val).transform;
				RectTransform val3 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
				RectTransform component = val2.GetComponent<RectTransform>();
				component.anchorMin = val3.anchorMin;
				component.anchorMax = val3.anchorMax;
				component.pivot = val3.pivot;
				component.anchoredPosition = val3.anchoredPosition + new Vector2(0f, -80f);
				val2.AddComponent<SecondHotbarRow>();
				MessageHudOffsetPatch.ApplyOffset();
			}
		}
	}
	[HarmonyPatch(typeof(Player), "Update")]
	internal class SecondRowHotbarInputPatch
	{
		[HarmonyPostfix]
		private static void Postfix(Player __instance)
		{
			if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer || !ModConfig.IsInitialized)
			{
				return;
			}
			int value = ModConfig.SecondRowSlotCount.Value;
			for (int i = 0; i < value; i++)
			{
				if (ZInput.GetButtonDown(ModConfig.Row2ActionName(i)))
				{
					ItemData itemAt = ((Humanoid)__instance).GetInventory().GetItemAt(i, 1);
					if (itemAt != null)
					{
						((Humanoid)__instance).UseItem((Inventory)null, itemAt, false);
					}
				}
			}
		}
	}
	[HarmonyPatch(typeof(ZInput), "Reset")]
	internal class ZInputResetPatch
	{
		private static readonly MethodInfo AddButtonMethod = AccessTools.Method(typeof(ZInput), "AddButton", (Type[])null, (Type[])null);

		[HarmonyPostfix]
		private static void Postfix(ZInput __instance)
		{
			for (int i = 0; i < 8; i++)
			{
				string text = ModConfig.Row2ActionName(i);
				AddButtonMethod.Invoke(__instance, new object[7] { text, "<Keyboard>/None", false, true, false, 0f, 0f });
			}
			MessageHudOffsetPatch.ApplyOffset();
			ModConfig.ApplyAllToZInput(__instance);
		}
	}
}