Decompiled source of EquipWheel v1.5.2

EquipWheel.dll

Decompiled 10 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
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("EquipWheel")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EquipWheel")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9299ddd5-a76a-423e-b5ce-c053e68f6abf")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.5", FrameworkDisplayName = "")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace EquipWheel;

public class EpicLootWrapper
{
	private Assembly EpicLootAssembly;

	private Type ItemBackgroundHelper;

	private Type EpicLoot;

	private Type ItemDataExtensions;

	private MethodInfo CreateAndGetMagicItemBackgroundImage;

	private MethodInfo GetMagicItemBgSprite;

	private MethodInfo UseMagicBackground;

	private MethodInfo GetRarityColor;

	private MethodInfo GetDecoratedName;

	public static EpicLootWrapper instance;

	private EpicLootWrapper()
	{
	}

	public static EpicLootWrapper CreateInstance()
	{
		PluginInfo val;
		try
		{
			val = Chainloader.PluginInfos["randyknapp.mods.epicloot"];
		}
		catch (KeyNotFoundException)
		{
			return null;
		}
		EpicLootWrapper epicLootWrapper = new EpicLootWrapper();
		Assembly assembly = ((object)val.Instance).GetType().Assembly;
		if (assembly == null)
		{
			throw new Exception("Assembly for EpicLoot cannot be resolved");
		}
		epicLootWrapper.EpicLootAssembly = assembly;
		Type[] exportedTypes = epicLootWrapper.EpicLootAssembly.GetExportedTypes();
		foreach (Type type in exportedTypes)
		{
			if (type.FullName == "EpicLoot.ItemBackgroundHelper")
			{
				epicLootWrapper.ItemBackgroundHelper = type;
			}
			if (type.FullName == "EpicLoot.EpicLoot")
			{
				epicLootWrapper.EpicLoot = type;
			}
			if (type.FullName == "EpicLoot.ItemDataExtensions")
			{
				epicLootWrapper.ItemDataExtensions = type;
			}
		}
		if (epicLootWrapper.ItemBackgroundHelper == null)
		{
			throw new Exception("Type EpicLoot.ItemBackgroundHelper cannot be resolved");
		}
		if (epicLootWrapper.EpicLoot == null)
		{
			throw new Exception("Type EpicLoot.EpicLoot cannot be resolved");
		}
		if (epicLootWrapper.ItemDataExtensions == null)
		{
			throw new Exception("Type EpicLoot.ItemDataExtensions cannot be resolved");
		}
		epicLootWrapper.CreateAndGetMagicItemBackgroundImage = epicLootWrapper.ItemBackgroundHelper.GetMethod("CreateAndGetMagicItemBackgroundImage", new Type[3]
		{
			typeof(GameObject),
			typeof(GameObject),
			typeof(bool)
		});
		if (epicLootWrapper.CreateAndGetMagicItemBackgroundImage == null)
		{
			throw new Exception("Method CreateAndGetMagicItemBackgroundImage cannot be resolved");
		}
		epicLootWrapper.GetMagicItemBgSprite = epicLootWrapper.EpicLoot.GetMethod("GetMagicItemBgSprite", new Type[0]);
		if (epicLootWrapper.GetMagicItemBgSprite == null)
		{
			throw new Exception("Method GetMagicItemBgSprite cannot be resolved");
		}
		epicLootWrapper.UseMagicBackground = epicLootWrapper.ItemDataExtensions.GetMethod("UseMagicBackground", new Type[1] { typeof(ItemData) });
		if (epicLootWrapper.UseMagicBackground == null)
		{
			throw new Exception("Method UseMagicBackground cannot be resolved");
		}
		epicLootWrapper.GetRarityColor = epicLootWrapper.ItemDataExtensions.GetMethod("GetRarityColor", new Type[1] { typeof(ItemData) });
		if (epicLootWrapper.GetRarityColor == null)
		{
			throw new Exception("Method GetRarityColor cannot be resolved");
		}
		epicLootWrapper.GetDecoratedName = epicLootWrapper.ItemDataExtensions.GetMethod("GetDecoratedName", new Type[2]
		{
			typeof(ItemData),
			typeof(string)
		});
		if (epicLootWrapper.GetDecoratedName == null)
		{
			throw new Exception("Method GetDecoratedName cannot be resolved");
		}
		instance = epicLootWrapper;
		return epicLootWrapper;
	}

	public string GetItemName(ItemData item, Color color)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		return (string)GetDecoratedName.Invoke(null, new object[2]
		{
			item,
			"#" + ColorUtility.ToHtmlStringRGB(color)
		});
	}

	public string GetItemName(ItemData item)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		return GetItemName(item, EquipWheel.GetHighlightColor);
	}

	public Color GetItemColor(ItemData item)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		return (Color)GetRarityColor.Invoke(null, new object[1] { item });
	}

	public void ModifyElement(EquipWheelUI.ElementData element, ItemData item)
	{
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Expected O, but got Unknown
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Expected O, but got Unknown
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		if (element == null || item == null)
		{
			return;
		}
		Transform val = element.m_go.transform.Find("magicItem");
		if ((Object)(object)val != (Object)null)
		{
			Image component = ((Component)val).GetComponent<Image>();
			if ((Object)(object)component != (Object)null)
			{
				((Behaviour)component).enabled = false;
			}
		}
		Transform val2 = element.m_go.transform.Find("setItem");
		if ((Object)(object)val2 != (Object)null)
		{
			Image component2 = ((Component)val2).GetComponent<Image>();
			if ((Object)(object)component2 != (Object)null)
			{
				((Behaviour)component2).enabled = false;
			}
		}
		Image val3 = (Image)CreateAndGetMagicItemBackgroundImage.Invoke(null, new object[3]
		{
			element.m_go,
			element.m_equiped.gameObject,
			true
		});
		if ((bool)UseMagicBackground.Invoke(null, new object[1] { item }))
		{
			((Behaviour)val3).enabled = true;
			val3.sprite = (Sprite)GetMagicItemBgSprite.Invoke(null, new object[0]);
			((Graphic)val3).color = (Color)GetRarityColor.Invoke(null, new object[1] { item });
		}
		Transform val4 = element.m_go.transform.Find("setItem");
		if ((Object)(object)val4 != (Object)null && !string.IsNullOrEmpty(item.m_shared.m_setName))
		{
			((Behaviour)((Component)val4).GetComponent<Image>()).enabled = true;
		}
	}
}
[BepInPlugin("virtuacode.valheim.equipwheel", "Equip Wheel Mod", "1.5.2")]
public class EquipWheel : BaseUnityPlugin, WheelManager.IWheel
{
	private static Harmony harmony;

	public static ManualLogSource MyLogger = Logger.CreateLogSource(Assembly.GetExecutingAssembly().GetName().Name);

	public static ConfigEntry<KeyboardShortcut> Hotkey;

	public static ConfigEntry<WheelManager.DPadButton> HotkeyDPad;

	public static ConfigEntry<bool> UseSitButton;

	public static ConfigEntry<bool> EquipWhileRunning;

	public static ConfigEntry<bool> AutoEquipShield;

	public static ConfigEntry<bool> HideHotkeyBar;

	public static ConfigEntry<int> IgnoreJoyStickDuration;

	public static ConfigEntry<bool> UseRarityColoring;

	public static ConfigEntry<bool> TriggerOnRelease;

	public static ConfigEntry<bool> TriggerOnClick;

	public static ConfigEntry<bool> ToggleMenu;

	public static ConfigEntry<bool> ModEnabled;

	public static ConfigEntry<Color> HighlightColor;

	public static ConfigEntry<float> GuiScale;

	public static ConfigEntry<int> InventoryRow;

	public static ConfigEntry<bool> ItemFiltering;

	public static ConfigEntry<ItemType> ItemType1;

	public static ConfigEntry<ItemType> ItemType2;

	public static ConfigEntry<ItemType> ItemType3;

	public static ConfigEntry<ItemType> ItemType4;

	public static ConfigEntry<ItemType> ItemType5;

	public static ConfigEntry<ItemType> ItemType6;

	public static ConfigEntry<string> ItemRegex;

	public static ConfigEntry<string> ItemRegexIgnore;

	public static ConfigEntry<bool> ItemRegexCaseSensitive;

	private static EquipWheel instance;

	public static KeyCode replacedKey = (KeyCode)0;

	public static List<string> replacedButtons = new List<string>();

	public static float JoyStickIgnoreTime = 0f;

	public static EquipGui Gui;

	public static Color GetHighlightColor => HighlightColor.Value;

	public static EquipWheel Instance => instance;

	public static bool CanOpenMenu
	{
		get
		{
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null) && !((Character)localPlayer).IsDead() && !((Character)localPlayer).InCutscene() && !((Character)localPlayer).IsTeleporting() && TakeInput(look: true) && !InInventoryEtc() && !WheelManager.inventoryVisible)
			{
				if (IsUsingUseButton())
				{
					return !WheelManager.pressedOnHovering;
				}
				return true;
			}
			return false;
		}
	}

	public static bool BestMatchPressed
	{
		get
		{
			if ((Object)(object)Instance == (Object)null)
			{
				return false;
			}
			return WheelManager.BestMatchPressed(Instance);
		}
	}

	public static bool BestMatchDown
	{
		get
		{
			if ((Object)(object)Instance == (Object)null)
			{
				return false;
			}
			return WheelManager.BestMatchDown(Instance);
		}
	}

	public static bool IsShortcutDown
	{
		get
		{
			//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_00a4: Unknown result type (might be due to invalid IL or missing references)
			if (ZInput.IsGamepadActive())
			{
				switch (HotkeyDPad.Value)
				{
				case WheelManager.DPadButton.None:
					if (UseSitButton.Value)
					{
						return ZInput.GetButtonDown("JoySit");
					}
					return ZInput.GetButtonDown("JoyUse");
				case WheelManager.DPadButton.Left:
					return ZInput.GetButtonDown("JoyHotbarLeft");
				case WheelManager.DPadButton.Right:
					return ZInput.GetButtonDown("JoyHotbarRight");
				case WheelManager.DPadButton.LeftOrRight:
					if (!ZInput.GetButtonDown("JoyHotbarRight"))
					{
						return ZInput.GetButtonDown("JoyHotbarLeft");
					}
					return true;
				default:
					if (!ZInput.GetButtonDown("JoyHotbarRight"))
					{
						return ZInput.GetButtonDown("JoyHotbarLeft");
					}
					return true;
				}
			}
			KeyboardShortcut value = Hotkey.Value;
			KeyCode mainKey = ((KeyboardShortcut)(ref value)).MainKey;
			KeyCode[] source = ((KeyboardShortcut)(ref value)).Modifiers.ToArray();
			if (!Input.GetKeyDown(mainKey))
			{
				return ((IEnumerable<KeyCode>)source).Any((Func<KeyCode, bool>)Input.GetKeyDown);
			}
			return true;
		}
	}

	public static bool IsShortcutUp
	{
		get
		{
			//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_00a4: Unknown result type (might be due to invalid IL or missing references)
			if (ZInput.IsGamepadActive())
			{
				switch (HotkeyDPad.Value)
				{
				case WheelManager.DPadButton.None:
					if (UseSitButton.Value)
					{
						return ZInput.GetButtonUp("JoySit");
					}
					return ZInput.GetButtonUp("JoyUse");
				case WheelManager.DPadButton.Left:
					return ZInput.GetButtonUp("JoyHotbarLeft");
				case WheelManager.DPadButton.Right:
					return ZInput.GetButtonUp("JoyHotbarRight");
				case WheelManager.DPadButton.LeftOrRight:
					if (!ZInput.GetButtonUp("JoyHotbarRight"))
					{
						return ZInput.GetButtonUp("JoyHotbarLeft");
					}
					return true;
				default:
					if (!ZInput.GetButtonUp("JoyHotbarRight"))
					{
						return ZInput.GetButtonUp("JoyHotbarLeft");
					}
					return true;
				}
			}
			KeyboardShortcut value = Hotkey.Value;
			KeyCode mainKey = ((KeyboardShortcut)(ref value)).MainKey;
			KeyCode[] source = ((KeyboardShortcut)(ref value)).Modifiers.ToArray();
			if (!Input.GetKeyUp(mainKey))
			{
				return ((IEnumerable<KeyCode>)source).Any((Func<KeyCode, bool>)Input.GetKeyUp);
			}
			return true;
		}
	}

	public static bool IsShortcutPressed
	{
		get
		{
			//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_00a4: Unknown result type (might be due to invalid IL or missing references)
			if (ZInput.IsGamepadActive())
			{
				switch (HotkeyDPad.Value)
				{
				case WheelManager.DPadButton.None:
					if (UseSitButton.Value)
					{
						return ZInput.GetButton("JoySit");
					}
					return ZInput.GetButton("JoyUse");
				case WheelManager.DPadButton.Left:
					return ZInput.GetButton("JoyHotbarLeft");
				case WheelManager.DPadButton.Right:
					return ZInput.GetButton("JoyHotbarRight");
				case WheelManager.DPadButton.LeftOrRight:
					if (!ZInput.GetButton("JoyHotbarRight"))
					{
						return ZInput.GetButton("JoyHotbarLeft");
					}
					return true;
				default:
					if (!ZInput.GetButton("JoyHotbarRight"))
					{
						return ZInput.GetButton("JoyHotbarLeft");
					}
					return true;
				}
			}
			KeyboardShortcut value = Hotkey.Value;
			KeyCode mainKey = ((KeyboardShortcut)(ref value)).MainKey;
			KeyCode[] source = ((KeyboardShortcut)(ref value)).Modifiers.ToArray();
			if (!Input.GetKey(mainKey))
			{
				return ((IEnumerable<KeyCode>)source).Any((Func<KeyCode, bool>)Input.GetKey);
			}
			return true;
		}
	}

	public static void Log(string msg)
	{
		ManualLogSource myLogger = MyLogger;
		if (myLogger != null)
		{
			myLogger.LogInfo((object)msg);
		}
	}

	public static void LogErr(string msg)
	{
		ManualLogSource myLogger = MyLogger;
		if (myLogger != null)
		{
			myLogger.LogError((object)msg);
		}
	}

	public static void LogWarn(string msg)
	{
		ManualLogSource myLogger = MyLogger;
		if (myLogger != null)
		{
			myLogger.LogWarning((object)msg);
		}
	}

	private static bool TakeInput(bool look = false)
	{
		if (!GameCamera.InFreeFly() && (!Object.op_Implicit((Object)(object)Chat.instance) || !Chat.instance.HasFocus()) && !Menu.IsVisible() && !Console.IsVisible() && !TextInput.IsVisible() && !Minimap.InTextInput() && (!ZInput.IsGamepadActive() || !Minimap.IsOpen()) && (!ZInput.IsGamepadActive() || !StoreGui.IsVisible()) && (!ZInput.IsGamepadActive() || !Hud.IsPieceSelectionVisible()) && (!PlayerCustomizaton.IsBarberGuiVisible() || look))
		{
			if (PlayerCustomizaton.BarberBlocksLook())
			{
				return !look;
			}
			return true;
		}
		return false;
	}

	private static bool InInventoryEtc()
	{
		if (!Minimap.IsOpen() && !StoreGui.IsVisible())
		{
			return Hud.IsPieceSelectionVisible();
		}
		return true;
	}

	public static bool IsDedicated()
	{
		MethodInfo method = typeof(ZNet).GetMethod("IsDedicated", BindingFlags.Instance | BindingFlags.Public);
		return ((Func<ZNet, bool>)Delegate.CreateDelegate(typeof(Func<ZNet, bool>), method))(null);
	}

	public static bool IsUsingUseButton()
	{
		if (ZInput.IsGamepadActive() && HotkeyDPad.Value == WheelManager.DPadButton.None)
		{
			return !UseSitButton.Value;
		}
		return false;
	}

	public void Awake()
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0204: Expected O, but got Unknown
		//IL_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0236: Expected O, but got Unknown
		instance = this;
		ModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ModEnabled", true, "Enable mod when value is true");
		Hotkey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Input", "Hotkey", KeyboardShortcut.Deserialize("G"), "Hotkey for opening equip wheel menu");
		HotkeyDPad = ((BaseUnityPlugin)this).Config.Bind<WheelManager.DPadButton>("Input", "HotkeyDPad", WheelManager.DPadButton.None, "Hotkey on the D-Pad (None, Left, Right or LeftOrRight)");
		UseSitButton = ((BaseUnityPlugin)this).Config.Bind<bool>("Input", "UseSitButton", false, "When enabled use the sit button as hotkey (HotkeyDPad has to be set to None)");
		TriggerOnRelease = ((BaseUnityPlugin)this).Config.Bind<bool>("Input", "TriggerOnRelease", true, "Releasing the Hotkey will equip/use the selected item");
		TriggerOnClick = ((BaseUnityPlugin)this).Config.Bind<bool>("Input", "TriggerOnClick", false, "Click with left mouse button will equip/use the selected item");
		ToggleMenu = ((BaseUnityPlugin)this).Config.Bind<bool>("Input", "ToggleMenu", false, "When enabled the equip wheel will toggle between hidden/visible when the hotkey was pressed");
		HighlightColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Appereance", "HighlightColor", new Color(0.414f, 0.734f, 1f), "Color of the highlighted selection");
		GuiScale = ((BaseUnityPlugin)this).Config.Bind<float>("Appereance", "GuiScale", 0.5f, "Scale factor of the user interface");
		HideHotkeyBar = ((BaseUnityPlugin)this).Config.Bind<bool>("Appereance", "HideHotkeyBar", false, "Hides the top-left Hotkey Bar");
		EquipWhileRunning = ((BaseUnityPlugin)this).Config.Bind<bool>("Misc", "EquipWhileRunning", true, "Allow to equip weapons while running");
		AutoEquipShield = ((BaseUnityPlugin)this).Config.Bind<bool>("Misc", "AutoEquipShield", true, "Enable auto equip of shield when one-handed weapon was equipped");
		HideHotkeyBar.SettingChanged += delegate
		{
			if (!((Object)(object)Hud.instance == (Object)null))
			{
				HotkeyBar component = ((Component)((Component)Hud.instance).transform.Find("hudroot/HotKeyBar")).GetComponent<HotkeyBar>();
				if (!((Object)(object)component == (Object)null))
				{
					((Component)component).gameObject.SetActive(!HideHotkeyBar.Value);
				}
			}
		};
		IgnoreJoyStickDuration = ((BaseUnityPlugin)this).Config.Bind<int>("Input", "IgnoreJoyStickDuration", 500, new ConfigDescription("Duration in milliseconds for ignoring left joystick input after button release", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 2000), new object[0]));
		InventoryRow = ((BaseUnityPlugin)this).Config.Bind<int>("Misc", "InventoryRow", 1, new ConfigDescription("Row of the inventory that should be used for the equip wheel", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 4), new object[0]));
		ItemFiltering = ((BaseUnityPlugin)this).Config.Bind<bool>("Misc", "ItemFiltering", false, "Will scan the whole inventory for items of the specified item types and Regex and show them in the equip wheel");
		ItemType1 = ((BaseUnityPlugin)this).Config.Bind<ItemType>("Misc", "ItemType1", (ItemType)0, "Item type used for filtering items");
		ItemType2 = ((BaseUnityPlugin)this).Config.Bind<ItemType>("Misc", "ItemType2", (ItemType)0, "Item type used for filtering items");
		ItemType3 = ((BaseUnityPlugin)this).Config.Bind<ItemType>("Misc", "ItemType3", (ItemType)0, "Item type used for filtering items");
		ItemType4 = ((BaseUnityPlugin)this).Config.Bind<ItemType>("Misc", "ItemType4", (ItemType)0, "Item type used for filtering items");
		ItemType5 = ((BaseUnityPlugin)this).Config.Bind<ItemType>("Misc", "ItemType5", (ItemType)0, "Item type used for filtering items");
		ItemType6 = ((BaseUnityPlugin)this).Config.Bind<ItemType>("Misc", "ItemType6", (ItemType)0, "Item type used for filtering items");
		ItemRegex = ((BaseUnityPlugin)this).Config.Bind<string>("Misc", "ItemRegex", "", "Regex used for filtering items");
		ItemRegexIgnore = ((BaseUnityPlugin)this).Config.Bind<string>("Misc", "ItemRegexIgnore", "", "Regex used for ignoring items");
		ItemRegexCaseSensitive = ((BaseUnityPlugin)this).Config.Bind<bool>("Misc", "ItemRegexCaseSensitive", false, "When enabled the Regex will be case-sensitive");
		if (!ModEnabled.Value)
		{
			LogWarn("Mod not loaded because it was disabled via config.");
			return;
		}
		if (IsDedicated())
		{
			LogWarn("Mod not loaded because game instance is a dedicated server.");
			return;
		}
		harmony = Harmony.CreateAndPatchAll(typeof(Patcher), (string)null);
		WheelManager.AddWheel(this);
		try
		{
			EpicLootWrapper.CreateInstance();
			UseRarityColoring = ((BaseUnityPlugin)this).Config.Bind<bool>("Appereance", "UseRarityColoring", true, "When enabled, the highlight color will be set to the rarity color of the selected item.");
			Log("Epicloot Mod installed. Applied compatibility patch.");
		}
		catch (Exception ex)
		{
			LogErr(ex.Message);
			LogErr("Failed to initialize EpicLootWrapper. Probably a compatibility issue. Please inform the mod creator of EquipWheel about this issue! (https://www.nexusmods.com/valheim/mods/536)");
		}
		Log(((object)this).GetType().Namespace + " Loaded!");
	}

	private void OnDestroy()
	{
		WheelManager.RemoveWheel(this);
		Harmony obj = harmony;
		if (obj != null)
		{
			obj.UnpatchAll((string)null);
		}
	}

	public static void TryHideHotkeyBar()
	{
		HotkeyBar component = ((Component)((Component)Hud.instance).transform.Find("hudroot/HotKeyBar")).GetComponent<HotkeyBar>();
		if (!((Object)(object)component == (Object)null))
		{
			((Component)component).gameObject.SetActive(!HideHotkeyBar.Value);
		}
	}

	public static void ParseNames(string value, ref string[] arr)
	{
		if ((Object)(object)ObjectDB.instance == (Object)null)
		{
			return;
		}
		string[] array = ParseTokens(value);
		List<string> list = new List<string>();
		string[] array2 = array;
		foreach (string text in array2)
		{
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(text);
			if ((Object)(object)itemPrefab != (Object)null)
			{
				ItemDrop component = itemPrefab.GetComponent<ItemDrop>();
				list.Add(component.m_itemData.m_shared.m_name);
			}
		}
		arr = list.Distinct().ToArray();
	}

	public static string[] ParseTokens(string value)
	{
		char[] separator = new char[5] { ' ', ',', '.', ':', '\t' };
		return value.Split(separator, StringSplitOptions.RemoveEmptyEntries);
	}

	public int GetKeyCount(bool pressed = false)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0022: 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_002a: Unknown result type (might be due to invalid IL or missing references)
		int num = 0;
		KeyboardShortcut value = Hotkey.Value;
		KeyCode mainKey = ((KeyboardShortcut)(ref value)).MainKey;
		KeyCode[] source = ((KeyboardShortcut)(ref value)).Modifiers.ToArray();
		if ((int)mainKey == 0)
		{
			return num;
		}
		if (pressed ? Input.GetKey(mainKey) : Input.GetKeyDown(mainKey))
		{
			num++;
		}
		return num + ((IEnumerable<KeyCode>)source).Count((Func<KeyCode, bool>)Input.GetKey);
	}

	public int GetKeyCountDown()
	{
		return GetKeyCount();
	}

	public int GetKeyCountPressed()
	{
		return GetKeyCount(pressed: true);
	}

	public bool IsVisible()
	{
		return EquipGui.visible;
	}

	public void Hide()
	{
		if (!((Object)(object)Gui == (Object)null))
		{
			Gui.Hide();
		}
	}

	public string GetName()
	{
		return Assembly.GetExecutingAssembly().GetName().Name;
	}

	float WheelManager.IWheel.JoyStickIgnoreTime()
	{
		return JoyStickIgnoreTime;
	}
}
public class EquipGui : MonoBehaviour
{
	private EquipWheelUI ui;

	public AssetBundle assets;

	public static bool visible;

	public int toggleVisible;

	private void Awake()
	{
		//IL_0031: 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)
		LoadAssets();
		GameObject obj = assets.LoadAsset<GameObject>("assets/selectionwheel/selectionwheel.prefab");
		RectTransform val = ((Component)this).gameObject.AddComponent<RectTransform>();
		GameObject val2 = Object.Instantiate<GameObject>(obj, new Vector3(0f, 0f, 0f), ((Component)this).transform.rotation, (Transform)(object)val);
		ui = val2.AddComponent<EquipWheelUI>();
		val2.SetActive(false);
		visible = false;
		assets.Unload(false);
	}

	private void Start()
	{
		//IL_000c: 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_002c: 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_0055: Unknown result type (might be due to invalid IL or missing references)
		RectTransform component = ((Component)this).gameObject.GetComponent<RectTransform>();
		component.offsetMin = Vector2.zero;
		component.offsetMax = Vector2.zero;
		component.anchorMax = new Vector2(1f, 1f);
		component.anchorMin = new Vector2(0f, 0f);
		component.anchoredPosition = new Vector2(0f, 0f);
		if (!((Object)(object)Hud.instance == (Object)null))
		{
			EquipWheel.TryHideHotkeyBar();
		}
	}

	private void LoadAssets()
	{
		Stream manifestResourceStream = Assembly.GetAssembly(typeof(EquipWheel)).GetManifestResourceStream("EquipWheel.res.selectionwheel");
		using MemoryStream memoryStream = new MemoryStream();
		manifestResourceStream.CopyTo(memoryStream);
		assets = AssetBundle.LoadFromMemory(memoryStream.ToArray());
	}

	public void Hide()
	{
		((Component)ui).gameObject.SetActive(false);
		visible = false;
		toggleVisible = 0;
	}

	private void Update()
	{
		if (EquipWheel.JoyStickIgnoreTime > 0f)
		{
			EquipWheel.JoyStickIgnoreTime -= Time.deltaTime;
		}
		Player localPlayer = Player.m_localPlayer;
		if (WheelManager.pressedOnHovering && ZInput.GetButtonUp("JoyUse"))
		{
			WheelManager.pressedOnHovering = false;
			WheelManager.hoverTextVisible = false;
			return;
		}
		if (EquipWheel.IsShortcutDown && EquipWheel.IsUsingUseButton())
		{
			WheelManager.pressedOnHovering = WheelManager.pressedOnHovering || WheelManager.hoverTextVisible;
		}
		if (!EquipWheel.CanOpenMenu)
		{
			Hide();
			return;
		}
		if (EquipWheel.IsShortcutDown && EquipWheel.ToggleMenu.Value && toggleVisible < 2 && EquipWheel.BestMatchDown)
		{
			toggleVisible++;
		}
		bool flag = EquipWheel.IsShortcutDown && EquipWheel.ToggleMenu.Value && toggleVisible == 2 && EquipWheel.BestMatchDown;
		bool flag2 = EquipWheel.IsShortcutUp && !EquipWheel.ToggleMenu.Value;
		if ((EquipWheel.ToggleMenu.Value && toggleVisible > 0 && !flag) || (EquipWheel.IsShortcutPressed && ZInput.IsGamepadActive()) || (EquipWheel.IsShortcutPressed && (EquipWheel.BestMatchPressed || EquipWheel.BestMatchDown) && !EquipWheel.ToggleMenu.Value))
		{
			((Component)ui).gameObject.SetActive(true);
			visible = true;
			WheelManager.Activate(EquipWheel.Instance);
			if (EquipWheel.TriggerOnClick.Value && (Input.GetMouseButtonDown(0) || Input.GetKeyDown((KeyCode)330)) && ui.CurrentItem != null)
			{
				ui.Flash();
				((Humanoid)localPlayer).UseItem((Inventory)null, ui.CurrentItem, false);
			}
			if (!flag)
			{
				return;
			}
		}
		if (EquipWheel.TriggerOnRelease.Value && (flag || flag2) && WheelManager.IsActive(EquipWheel.Instance))
		{
			if (ui.CurrentItem != null)
			{
				((Humanoid)localPlayer).UseItem((Inventory)null, ui.CurrentItem, false);
			}
			EquipWheel.JoyStickIgnoreTime = (float)EquipWheel.IgnoreJoyStickDuration.Value / 1000f;
		}
		Hide();
	}
}
public class EquipWheelUI : MonoBehaviour
{
	public class ElementData
	{
		public bool m_used;

		public GameObject m_go;

		public Image m_icon;

		public GuiBar m_durability;

		public TextMeshProUGUI m_amount;

		public GameObject m_equiped;

		public GameObject m_queued;

		public GameObject m_selection;
	}

	public readonly float ANGLE_STEP = 45f;

	public readonly float ITEM_DISTANCE = 295f;

	public readonly float ITEM_SCALE = 2f;

	public readonly float INNER_DIAMETER = 340f;

	private GameObject cursor;

	private Text text;

	private GameObject highlight;

	private readonly ItemData[] items = (ItemData[])(object)new ItemData[8];

	private HotkeyBar hotKeyBar;

	private Transform itemsRoot;

	private bool addedListener;

	private readonly List<ElementData> m_elements = new List<ElementData>();

	private GameObject m_elementPrefab;

	private int previous = -1;

	public int Current
	{
		get
		{
			if ((!ZInput.IsGamepadActive() && MouseInCenter) || JoyStickInCenter)
			{
				return -1;
			}
			int num = Mod((int)Mathf.Round((0f - Angle) / ANGLE_STEP), 8);
			if (num >= items.Length)
			{
				return -1;
			}
			return num;
		}
	}

	public bool JoyStickInCenter
	{
		get
		{
			if (EquipWheel.HotkeyDPad.Value == WheelManager.DPadButton.None)
			{
				float joyLeftStickX = ZInput.GetJoyLeftStickX(false);
				float joyLeftStickY = ZInput.GetJoyLeftStickY(true);
				if (ZInput.IsGamepadActive() && joyLeftStickX == 0f)
				{
					return joyLeftStickY == 0f;
				}
				return false;
			}
			float joyRightStickX = ZInput.GetJoyRightStickX();
			float joyRightStickY = ZInput.GetJoyRightStickY();
			if (ZInput.IsGamepadActive() && joyRightStickX == 0f)
			{
				return joyRightStickY == 0f;
			}
			return false;
		}
	}

	public ItemData CurrentItem
	{
		get
		{
			if (Current < 0)
			{
				return null;
			}
			return items[Current];
		}
	}

	public bool MouseInCenter
	{
		get
		{
			//IL_0017: 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_0033: 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)
			float num = INNER_DIAMETER / 2f * ((Component)this).gameObject.transform.lossyScale.x;
			Vector3 val = Input.mousePosition - cursor.transform.position;
			return ((Vector3)(ref val)).magnitude <= num;
		}
	}

	public float Angle
	{
		get
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: 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)
			if (ZInput.IsGamepadActive())
			{
				if (EquipWheel.HotkeyDPad.Value == WheelManager.DPadButton.None)
				{
					float joyLeftStickX = ZInput.GetJoyLeftStickX(false);
					float num = 0f - ZInput.GetJoyLeftStickY(true);
					if (joyLeftStickX != 0f || num != 0f)
					{
						return Mathf.Atan2(num, joyLeftStickX) * 57.29578f - 90f;
					}
				}
				else
				{
					float joyRightStickX = ZInput.GetJoyRightStickX();
					float num2 = 0f - ZInput.GetJoyRightStickY();
					if (joyRightStickX != 0f || num2 != 0f)
					{
						return Mathf.Atan2(num2, joyRightStickX) * 57.29578f - 90f;
					}
				}
			}
			Vector3 val = Input.mousePosition - cursor.transform.position;
			return Mathf.Atan2(val.y, val.x) * 57.29578f - 90f;
		}
	}

	public IEnumerator FlashCoroutine(float aTime)
	{
		Color color = EquipWheel.GetHighlightColor;
		for (float t = 0f; t < 1f; t += Time.deltaTime / aTime)
		{
			((Graphic)highlight.GetComponent<Image>()).color = Color.Lerp(Color.white, color, t);
			yield return null;
		}
	}

	private int Mod(int a, int b)
	{
		return (a % b + b) % b;
	}

	public void Flash()
	{
		((MonoBehaviour)this).StartCoroutine(FlashCoroutine(0.4f));
	}

	private void Awake()
	{
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Expected O, but got Unknown
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: 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_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		cursor = ((Component)((Component)this).transform.Find("Cursor")).gameObject;
		highlight = ((Component)((Component)this).transform.Find("Highlight")).gameObject;
		hotKeyBar = ((Component)((Component)Hud.instance).transform.Find("hudroot/HotKeyBar")).gameObject.GetComponent<HotkeyBar>();
		m_elementPrefab = hotKeyBar.m_elementPrefab;
		itemsRoot = ((Component)this).transform.Find("Items");
		((Graphic)highlight.GetComponent<Image>()).material.SetFloat("_Degree", ANGLE_STEP);
		GameObject val = new GameObject("Text");
		RectTransform obj = val.AddComponent<RectTransform>();
		((Transform)obj).SetParent(((Component)this).transform);
		obj.sizeDelta = new Vector2(1000f, 100f);
		obj.anchoredPosition = new Vector2(0f, 450f);
		text = val.AddComponent<Text>();
		((Graphic)text).color = EquipWheel.GetHighlightColor;
		EquipWheel.HighlightColor.SettingChanged += delegate
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			((Graphic)text).color = EquipWheel.GetHighlightColor;
		};
		text.alignment = (TextAnchor)1;
		text.fontSize = 60;
		text.supportRichText = true;
		Font[] array = Resources.FindObjectsOfTypeAll<Font>();
		foreach (Font val2 in array)
		{
			if (((Object)val2).name == "AveriaSerifLibre-Bold")
			{
				text.font = val2;
				break;
			}
		}
		Outline obj2 = val.AddComponent<Outline>();
		((Shadow)obj2).effectDistance = new Vector2(1f, -1f);
		((Shadow)obj2).effectColor = Color.black;
		val.SetActive(false);
	}

	private void Start()
	{
		if (!addedListener)
		{
			Inventory inventory = ((Humanoid)Player.m_localPlayer).GetInventory();
			inventory.m_onChanged = (Action)Delegate.Combine(inventory.m_onChanged, new Action(OnInventoryChanged));
			addedListener = true;
		}
	}

	public void OnInventoryChanged()
	{
		if (EquipGui.visible)
		{
			UpdateItems();
			UpdateIcons(Player.m_localPlayer, forceUpdate: true);
		}
	}

	private void UpdateItems()
	{
		//IL_0200: Unknown result type (might be due to invalid IL or missing references)
		//IL_0206: Expected I4, but got Unknown
		//IL_020d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0213: Expected I4, but got Unknown
		//IL_021a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0220: Expected I4, but got Unknown
		//IL_0227: Unknown result type (might be due to invalid IL or missing references)
		//IL_022d: Expected I4, but got Unknown
		//IL_0234: Unknown result type (might be due to invalid IL or missing references)
		//IL_023a: Expected I4, but got Unknown
		//IL_0241: Unknown result type (might be due to invalid IL or missing references)
		//IL_0247: Expected I4, but got Unknown
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: 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_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: 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_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)Player.m_localPlayer == (Object)null)
		{
			return;
		}
		Inventory inventory = ((Humanoid)Player.m_localPlayer).GetInventory();
		if (inventory == null)
		{
			return;
		}
		if (EquipWheel.ItemFiltering.Value)
		{
			List<ItemData> list = new List<ItemData>();
			List<ItemData> list2 = new List<ItemData>();
			foreach (ItemData allItem in inventory.GetAllItems())
			{
				if (EquipWheel.ItemRegexIgnore.Value.Length > 0)
				{
					Regex regex = new Regex(EquipWheel.ItemRegexIgnore.Value, (!EquipWheel.ItemRegexCaseSensitive.Value) ? RegexOptions.IgnoreCase : RegexOptions.None);
					string input;
					if (EpicLootWrapper.instance != null)
					{
						Color itemColor = EpicLootWrapper.instance.GetItemColor(allItem);
						input = Localization.instance.Localize(EpicLootWrapper.instance.GetItemName(allItem, itemColor));
					}
					else
					{
						input = Localization.instance.Localize(allItem.m_shared.m_name);
					}
					if (regex.IsMatch(input))
					{
						continue;
					}
				}
				if (EquipWheel.ItemRegex.Value.Length > 0)
				{
					Regex regex2 = new Regex(EquipWheel.ItemRegex.Value, (!EquipWheel.ItemRegexCaseSensitive.Value) ? RegexOptions.IgnoreCase : RegexOptions.None);
					string input2;
					if (EpicLootWrapper.instance != null)
					{
						Color itemColor2 = EpicLootWrapper.instance.GetItemColor(allItem);
						input2 = Localization.instance.Localize(EpicLootWrapper.instance.GetItemName(allItem, itemColor2));
					}
					else
					{
						input2 = Localization.instance.Localize(allItem.m_shared.m_name);
					}
					if (regex2.IsMatch(input2))
					{
						list.Add(allItem);
						continue;
					}
				}
				ItemType itemType = allItem.m_shared.m_itemType;
				if (itemType == EquipWheel.ItemType1.Value || itemType == EquipWheel.ItemType2.Value || itemType == EquipWheel.ItemType3.Value || itemType == EquipWheel.ItemType4.Value || itemType == EquipWheel.ItemType5.Value || itemType == EquipWheel.ItemType6.Value)
				{
					list2.Add(allItem);
				}
			}
			ItemType[] types = (ItemType[])(object)new ItemType[6]
			{
				(ItemType)(int)EquipWheel.ItemType1.Value,
				(ItemType)(int)EquipWheel.ItemType2.Value,
				(ItemType)(int)EquipWheel.ItemType3.Value,
				(ItemType)(int)EquipWheel.ItemType4.Value,
				(ItemType)(int)EquipWheel.ItemType5.Value,
				(ItemType)(int)EquipWheel.ItemType6.Value
			};
			list2.Sort((ItemData a, ItemData b) => Array.IndexOf(types, a.m_shared.m_itemType).CompareTo(Array.IndexOf(types, b.m_shared.m_itemType)));
			for (int i = 0; i < 8; i++)
			{
				items[i] = null;
				if (list.Count > i)
				{
					items[i] = list[i];
				}
				else if (list2.Count > i - list.Count)
				{
					items[i] = list2[i - list.Count];
				}
			}
			return;
		}
		for (int j = 0; j < 8; j++)
		{
			items[j] = null;
			ItemData itemAt = inventory.GetItemAt(j, EquipWheel.InventoryRow.Value - 1);
			if (itemAt != null)
			{
				items[j] = itemAt;
			}
		}
	}

	private void OnEnable()
	{
		//IL_000b: 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)
		((Graphic)highlight.GetComponent<Image>()).color = EquipWheel.GetHighlightColor;
		float value = EquipWheel.GuiScale.Value;
		((Transform)((Component)this).GetComponent<RectTransform>()).localScale = new Vector3(value, value, value);
		EquipWheel.JoyStickIgnoreTime = 0f;
		UpdateItems();
		UpdateIcons(Player.m_localPlayer, forceUpdate: true);
		Update();
	}

	private void OnDisable()
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		highlight.SetActive(false);
		Image[] componentsInChildren = cursor.GetComponentsInChildren<Image>(true);
		foreach (Image val in componentsInChildren)
		{
			((Graphic)val).color = new Color(0f, 0f, 0f, 0.5f);
			if (((Object)((Component)val).gameObject).name == "Image")
			{
				((Component)val).gameObject.SetActive(false);
			}
		}
	}

	private void Update()
	{
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: 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_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: 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_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0207: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0232: Unknown result type (might be due to invalid IL or missing references)
		//IL_0237: 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_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		if (Current != previous)
		{
			if (CurrentItem != null)
			{
				InventoryGui.instance.m_moveItemEffects.Create(((Component)this).transform.position, Quaternion.identity, (Transform)null, 1f, -1);
				((Component)text).gameObject.SetActive(true);
				if (EpicLootWrapper.instance != null)
				{
					Color color = EpicLootWrapper.instance.GetItemColor(CurrentItem);
					if (((Color)(ref color)).Equals(Color.white) || !EquipWheel.UseRarityColoring.Value)
					{
						color = EquipWheel.GetHighlightColor;
					}
					text.text = Localization.instance.Localize(EpicLootWrapper.instance.GetItemName(CurrentItem, color));
				}
				else
				{
					text.text = Localization.instance.Localize(CurrentItem.m_shared.m_name);
				}
			}
			else
			{
				((Component)text).gameObject.SetActive(false);
			}
			previous = Current;
		}
		highlight.SetActive(CurrentItem != null);
		Color color2 = (Color)((CurrentItem == null) ? new Color(0f, 0f, 0f, 0.5f) : EquipWheel.GetHighlightColor);
		if (CurrentItem != null && EpicLootWrapper.instance != null)
		{
			Color itemColor = EpicLootWrapper.instance.GetItemColor(CurrentItem);
			if (!((Color)(ref itemColor)).Equals(Color.white) && EquipWheel.UseRarityColoring.Value)
			{
				color2 = itemColor;
				((Graphic)highlight.GetComponent<Image>()).color = color2;
			}
			else
			{
				((Graphic)highlight.GetComponent<Image>()).color = EquipWheel.GetHighlightColor;
			}
		}
		Image[] componentsInChildren = cursor.GetComponentsInChildren<Image>(true);
		foreach (Image val in componentsInChildren)
		{
			((Graphic)val).color = color2;
			if (((Object)((Component)val).gameObject).name == "Image")
			{
				((Component)val).gameObject.SetActive(CurrentItem != null);
			}
		}
		cursor.transform.rotation = Quaternion.AngleAxis(Angle, Vector3.forward);
		float num = (float)Current * ANGLE_STEP;
		highlight.transform.rotation = Quaternion.AngleAxis(0f - num, Vector3.forward);
		UpdateIcons(Player.m_localPlayer);
	}

	private int CountItems(ItemData[] items)
	{
		int num = 0;
		for (int i = 0; i < items.Length; i++)
		{
			if (items[i] != null)
			{
				num++;
			}
		}
		return num;
	}

	private void UpdateIcons(Player player, bool forceUpdate = false)
	{
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)player) || ((Character)player).IsDead())
		{
			foreach (ElementData element in m_elements)
			{
				Object.Destroy((Object)(object)element.m_go);
			}
			m_elements.Clear();
			return;
		}
		if (m_elements.Count != CountItems(items) || forceUpdate)
		{
			foreach (ElementData element2 in m_elements)
			{
				Object.Destroy((Object)(object)element2.m_go);
			}
			m_elements.Clear();
			for (int i = 0; i < items.Length; i++)
			{
				if (items[i] != null)
				{
					ElementData elementData = new ElementData();
					elementData.m_go = Object.Instantiate<GameObject>(m_elementPrefab, itemsRoot);
					elementData.m_go.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 0.5f);
					float num = Mathf.Sin((float)i * ANGLE_STEP * ((float)Math.PI / 180f)) * ITEM_DISTANCE;
					float num2 = Mathf.Cos((float)i * ANGLE_STEP * ((float)Math.PI / 180f)) * ITEM_DISTANCE;
					elementData.m_go.transform.localScale = new Vector3(ITEM_SCALE, ITEM_SCALE, ITEM_SCALE);
					elementData.m_go.transform.localPosition = new Vector3(num, num2, 0f);
					((TMP_Text)((Component)elementData.m_go.transform.Find("binding")).GetComponent<TextMeshProUGUI>()).text = (i + 1).ToString();
					elementData.m_icon = ((Component)((Component)elementData.m_go.transform).transform.Find("icon")).GetComponent<Image>();
					elementData.m_durability = ((Component)elementData.m_go.transform.Find("durability")).GetComponent<GuiBar>();
					elementData.m_amount = ((Component)elementData.m_go.transform.Find("amount")).GetComponent<TextMeshProUGUI>();
					elementData.m_equiped = ((Component)elementData.m_go.transform.Find("equiped")).gameObject;
					elementData.m_queued = ((Component)elementData.m_go.transform.Find("queued")).gameObject;
					elementData.m_selection = ((Component)elementData.m_go.transform.Find("selected")).gameObject;
					elementData.m_selection.SetActive(false);
					if (EquipWheel.InventoryRow.Value > 1 || EquipWheel.ItemFiltering.Value)
					{
						((Behaviour)((Component)elementData.m_go.transform.Find("binding")).GetComponent<TextMeshProUGUI>()).enabled = false;
					}
					m_elements.Add(elementData);
				}
			}
		}
		foreach (ElementData element3 in m_elements)
		{
			element3.m_used = false;
		}
		int num3 = 0;
		for (int j = 0; j < items.Length; j++)
		{
			if (items[j] == null)
			{
				continue;
			}
			ItemData val = items[j];
			ElementData elementData2 = m_elements[num3];
			elementData2.m_used = true;
			((Component)elementData2.m_icon).gameObject.SetActive(true);
			elementData2.m_icon.sprite = val.GetIcon();
			((Component)elementData2.m_durability).gameObject.SetActive(val.m_shared.m_useDurability);
			if (val.m_shared.m_useDurability)
			{
				if (val.m_durability <= 0f)
				{
					elementData2.m_durability.SetValue(1f);
					elementData2.m_durability.SetColor((Color)((Mathf.Sin(Time.time * 10f) > 0f) ? Color.red : new Color(0f, 0f, 0f, 0f)));
				}
				else
				{
					elementData2.m_durability.SetValue(val.GetDurabilityPercentage());
					elementData2.m_durability.ResetColor();
				}
			}
			elementData2.m_equiped.SetActive(val.m_equipped);
			elementData2.m_queued.SetActive(player.IsEquipActionQueued(val));
			if (val.m_shared.m_maxStackSize > 1)
			{
				((Component)elementData2.m_amount).gameObject.SetActive(true);
				((TMP_Text)elementData2.m_amount).text = val.m_stack + "/" + val.m_shared.m_maxStackSize;
			}
			else
			{
				((Component)elementData2.m_amount).gameObject.SetActive(false);
			}
			if (EpicLootWrapper.instance != null)
			{
				EpicLootWrapper.instance.ModifyElement(elementData2, val);
			}
			num3++;
		}
		for (int k = 0; k < m_elements.Count; k++)
		{
			ElementData elementData3 = m_elements[k];
			if (!elementData3.m_used)
			{
				((Component)elementData3.m_icon).gameObject.SetActive(false);
				((Component)elementData3.m_durability).gameObject.SetActive(false);
				elementData3.m_equiped.SetActive(false);
				elementData3.m_queued.SetActive(false);
				((Component)elementData3.m_amount).gameObject.SetActive(false);
			}
		}
	}
}
public class Patcher
{
	public static readonly KeyCode[] NUMBERS;

	[HarmonyPatch(typeof(InventoryGui), "IsVisible")]
	[HarmonyPostfix]
	public static void IsVisible_Postfix(ref bool __result)
	{
		WheelManager.inventoryVisible = __result;
		__result = __result || WheelManager.AnyVisible;
	}

	[HarmonyPatch(typeof(Hud), "UpdateCrosshair")]
	[HarmonyPostfix]
	public static void IsVisible_Postfix(Hud __instance, Player player, float bowDrawPercentage)
	{
		GameObject hoverObject = ((Humanoid)player).GetHoverObject();
		if ((Object.op_Implicit((Object)(object)hoverObject) ? hoverObject.GetComponentInParent<Interactable>() : null) != null && !TextViewer.instance.IsVisible())
		{
			WheelManager.hoverTextVisible = true;
		}
		else
		{
			WheelManager.hoverTextVisible = false;
		}
	}

	[HarmonyPatch(typeof(Humanoid), "UseItem")]
	[HarmonyPostfix]
	public static void UseItem_Postfix(Humanoid __instance, Inventory inventory, ItemData item, bool fromInventoryGui)
	{
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Expected O, but got Unknown
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Invalid comparison between Unknown and I4
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Invalid comparison between Unknown and I4
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Invalid comparison between Unknown and I4
		if (!EquipWheel.AutoEquipShield.Value || ((object)__instance).GetType() != typeof(Player) || fromInventoryGui)
		{
			return;
		}
		ItemData val = (ItemData)typeof(Humanoid).GetMethod("GetLeftItem", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, new object[0]);
		if ((val != null && (int)val.m_shared.m_itemType == 5) || !((Player)__instance).IsEquipActionQueued(item) || item.m_equipped || (int)item.m_shared.m_itemType != 3)
		{
			return;
		}
		List<ItemData> allItems = __instance.GetInventory().GetAllItems();
		int num = -1;
		int num2 = -1;
		ItemData val2 = null;
		foreach (ItemData item2 in allItems)
		{
			if (item2 != null && (int)item2.m_shared.m_itemType == 5 && (val2 == null || item2.m_gridPos.y < num2 || (item2.m_gridPos.y == num2 && item2.m_gridPos.x < num)))
			{
				val2 = item2;
				num = val2.m_gridPos.x;
				num2 = val2.m_gridPos.y;
			}
		}
		if (val2 != null)
		{
			__instance.UseItem((Inventory)null, val2, false);
		}
	}

	[HarmonyPatch(typeof(ZInput), "GetJoyRightStickX")]
	[HarmonyPostfix]
	public static void GetJoyRightStickX_Postfix(ref float __result)
	{
		if (WheelManager.GetJoyStickIgnoreTime() > 0f)
		{
			__result = 0f;
		}
	}

	[HarmonyPatch(typeof(ZInput), "GetJoyRightStickY")]
	[HarmonyPostfix]
	public static void GetJoyRightStickY_Postfix(ref float __result)
	{
		if (WheelManager.GetJoyStickIgnoreTime() > 0f)
		{
			__result = 0f;
		}
	}

	[HarmonyPatch(typeof(ZInput), "GetJoyLeftStickX")]
	[HarmonyPostfix]
	public static void GetJoyLeftStickX_Postfix(ref float __result)
	{
		if (WheelManager.GetJoyStickIgnoreTime() > 0f)
		{
			__result = 0f;
		}
	}

	[HarmonyPatch(typeof(ZInput), "GetJoyLeftStickY")]
	[HarmonyPostfix]
	public static void GetJoyLeftStickY_Postfix(ref float __result)
	{
		if (WheelManager.GetJoyStickIgnoreTime() > 0f)
		{
			__result = 0f;
		}
	}

	[HarmonyPatch(typeof(HotkeyBar), "Update")]
	[HarmonyPostfix]
	public static void Update_Postfix(HotkeyBar __instance)
	{
		if (EquipWheel.HideHotkeyBar.Value)
		{
			((Component)__instance).gameObject.SetActive(false);
		}
	}

	[HarmonyPatch(typeof(Player), "ClearActionQueue")]
	[HarmonyPrefix]
	public static bool Prefix(Player __instance)
	{
		if ((bool)typeof(Player).GetField("m_run", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance))
		{
			return !EquipWheel.EquipWhileRunning.Value;
		}
		return true;
	}

	[HarmonyPatch(typeof(Player), "Awake")]
	[HarmonyPostfix]
	public static void Awake_Postfix()
	{
		//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)
		string text = "EquipGui (" + Assembly.GetExecutingAssembly().GetName().Name + ")";
		if (!((Object)(object)Menu.instance == (Object)null) && !Object.op_Implicit((Object)(object)GameObject.Find(text)))
		{
			GameObject val = new GameObject(text);
			EquipWheel.Gui = val.AddComponent<EquipGui>();
			val.transform.SetParent(((Component)Menu.instance).transform.parent, false);
			EquipWheel.Log("Spawned EquipGui!");
		}
	}

	[HarmonyPatch(typeof(HotkeyBar), "Update")]
	[HarmonyPrefix]
	public static bool Prefix(HotkeyBar __instance)
	{
		if ((Object)(object)EquipWheel.Instance == (Object)null)
		{
			return true;
		}
		if (EquipWheel.HotkeyDPad != null && EquipWheel.HotkeyDPad.Value == WheelManager.DPadButton.None)
		{
			return true;
		}
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer != (Object)null)
		{
			typeof(HotkeyBar).GetMethod("UpdateIcons", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, new object[1] { localPlayer });
		}
		return false;
	}

	[HarmonyPatch(typeof(Player), "UseHotbarItem")]
	[HarmonyPrefix]
	public static bool UseHotbarItem(int index)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		KeyCode[] nUMBERS = NUMBERS;
		KeyboardShortcut value = EquipWheel.Hotkey.Value;
		bool num = Array.IndexOf(nUMBERS, ((KeyboardShortcut)(ref value)).MainKey) != index - 1;
		bool flag = !EquipWheel.IsShortcutDown;
		if (!(num || flag) && EquipWheel.CanOpenMenu)
		{
			return ZInput.IsGamepadActive();
		}
		return true;
	}

	[HarmonyPatch(typeof(Player), "Update")]
	[HarmonyPostfix]
	public static void Update()
	{
		Player localPlayer = Player.m_localPlayer;
		if (!((Object)(object)localPlayer == (Object)null) && EquipWheel.UseSitButton.Value && EquipWheel.HotkeyDPad.Value == WheelManager.DPadButton.None && (ZInput.GetButtonDown("JoySit") || ZInput.GetButtonUp("JoySit")))
		{
			typeof(Player).GetMethod("StopEmote", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(localPlayer, new object[0]);
		}
	}

	static Patcher()
	{
		KeyCode[] array = new KeyCode[8];
		RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
		NUMBERS = (KeyCode[])(object)array;
	}
}
public sealed class WheelManager
{
	public enum DPadButton
	{
		None,
		Left,
		Right,
		LeftOrRight
	}

	public interface IWheel
	{
		int GetKeyCountDown();

		int GetKeyCountPressed();

		bool IsVisible();

		void Hide();

		string GetName();

		float JoyStickIgnoreTime();
	}

	private static readonly HashSet<IWheel> wheels = new HashSet<IWheel>();

	private static IWheel activeWheel;

	public static bool inventoryVisible = false;

	public static bool hoverTextVisible = false;

	public static bool pressedOnHovering = false;

	public static bool AnyVisible => wheels.Any((IWheel w) => w.IsVisible());

	public static void Activate(IWheel wheel)
	{
		if (!wheel.IsVisible())
		{
			return;
		}
		foreach (IWheel wheel2 in wheels)
		{
			if (!wheel.Equals(wheel2))
			{
				wheel2.Hide();
			}
		}
		activeWheel = wheel;
	}

	public static bool IsActive(IWheel wheel)
	{
		return wheel.Equals(activeWheel);
	}

	public static bool AddWheel(IWheel wheel)
	{
		return wheels.Add(wheel);
	}

	public static bool RemoveWheel(IWheel wheel)
	{
		return wheels.Remove(wheel);
	}

	public static bool BestMatchDown(IWheel wheel)
	{
		if (!wheels.Contains(wheel))
		{
			return false;
		}
		IWheel obj = wheels.OrderByDescending((IWheel w) => w.GetKeyCountDown()).FirstOrDefault();
		return wheel.Equals(obj);
	}

	public static bool BestMatchPressed(IWheel wheel)
	{
		if (!wheels.Contains(wheel))
		{
			return false;
		}
		IWheel obj = wheels.OrderByDescending((IWheel w) => w.GetKeyCountPressed()).FirstOrDefault();
		return wheel.Equals(obj);
	}

	public static float GetJoyStickIgnoreTime()
	{
		float num = 0f;
		foreach (IWheel wheel in wheels)
		{
			num += wheel.JoyStickIgnoreTime();
		}
		return num;
	}
}