Decompiled source of UtilityWheel v0.2.2

BepInEx\plugins\UtilityWheel\InfernoProtocol.UtilityWheel.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Game.Data;
using Game.PlayerOperations;
using Game.UI;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("InfernoProtocol.UtilityWheel")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.2.0")]
[assembly: AssemblyInformationalVersion("0.2.2+477d00f8c6e6102e4d9ad948d3169f90685e9781")]
[assembly: AssemblyProduct("InfernoProtocol.UtilityWheel")]
[assembly: AssemblyTitle("InfernoProtocol.UtilityWheel")]
[assembly: AssemblyVersion("0.2.2.0")]
namespace InfernoProtocol.UtilityWheel;

internal static class PluginInfo
{
	internal const string Guid = "com.holden.infernoprotocol.utilitywheel";

	internal const string Name = "Utility Wheel";

	internal const string Version = "0.2.2";
}
public sealed class UtilityWheelController : MonoBehaviour
{
	private sealed class WeaponEntry
	{
		internal int Slot;

		internal string Name;

		internal Sprite Icon;
	}

	private sealed class SlotVisual
	{
		internal Image Sector;

		internal Image Panel;

		internal Image Icon;

		internal Image CurrentMarker;

		internal RectTransform Rect;
	}

	private readonly List<WeaponEntry> _weapons = new List<WeaponEntry>();

	private readonly List<SlotVisual> _slotVisuals = new List<SlotVisual>();

	private readonly List<InputActionMap> _disabledMaps = new List<InputActionMap>();

	private readonly Dictionary<int, Sprite[]> _sectorSprites = new Dictionary<int, Sprite[]>();

	private CanvasGroup _canvasGroup;

	private RectTransform _wheelRoot;

	private Image _scrim;

	private Image _wheelBackdrop;

	private Image _centerPanel;

	private TextMeshProUGUI _nameLabel;

	private TextMeshProUGUI _hintLabel;

	private TextMeshProUGUI _titleLabel;

	private Sprite _circleSprite;

	private WheelColors _colors;

	private int _selectedIndex = -1;

	private bool _open;

	private bool _suppressUntilRelease;

	private bool _built;

	private float _targetAlpha;

	internal static bool IsActivationHeld { get; private set; }

	internal static bool IsCommittingSelection { get; private set; }

	internal static bool ActivationControlIsPressed
	{
		get
		{
			Gamepad current = Gamepad.current;
			bool num = current != null && ((UtilityWheelPlugin.ControllerButton.Value == ControllerWheelButton.RightShoulder) ? current.rightShoulder.isPressed : current.leftShoulder.isPressed);
			Keyboard current2 = Keyboard.current;
			if (!num)
			{
				if (UtilityWheelPlugin.KeyboardFallback.Value && current2 != null)
				{
					return ((ButtonControl)current2.tabKey).isPressed;
				}
				return false;
			}
			return true;
		}
	}

	private static string ButtonHint
	{
		get
		{
			if (UtilityWheelPlugin.ControllerButton.Value != ControllerWheelButton.RightShoulder)
			{
				return "LB";
			}
			return "RB";
		}
	}

	public UtilityWheelController(IntPtr pointer)
		: base(pointer)
	{
	}

	private void Update()
	{
		ReadActivation(out var held, out var pressed);
		IsActivationHeld = held;
		if (_suppressUntilRelease)
		{
			if (!held)
			{
				_suppressUntilRelease = false;
			}
			FadeOverlay();
			return;
		}
		if (!UtilityWheelPlugin.Enabled.Value)
		{
			if (_open)
			{
				Close(equip: false);
			}
			FadeOverlay();
			return;
		}
		if (!_open && pressed && CanOpen())
		{
			Open();
		}
		if (_open)
		{
			Gamepad current = Gamepad.current;
			if (current != null && current.buttonEast.wasPressedThisFrame)
			{
				Close(equip: false);
				_suppressUntilRelease = held;
			}
			else if (!held)
			{
				Close(equip: true);
			}
			else if (!CanRemainOpen())
			{
				Close(equip: false);
				_suppressUntilRelease = true;
			}
			else
			{
				UpdateSelection();
			}
		}
		FadeOverlay();
	}

	private void OnDestroy()
	{
		if (_open)
		{
			RestoreInputMaps(restore: true);
		}
		foreach (Sprite[] value in _sectorSprites.Values)
		{
			for (int i = 0; i < value.Length; i++)
			{
				if ((Object)(object)value[i] != (Object)null)
				{
					Object.Destroy((Object)(object)value[i].texture);
					Object.Destroy((Object)(object)value[i]);
				}
			}
		}
		if ((Object)(object)_circleSprite != (Object)null)
		{
			Object.Destroy((Object)(object)_circleSprite.texture);
			Object.Destroy((Object)(object)_circleSprite);
		}
		IsActivationHeld = false;
		IsCommittingSelection = false;
	}

	private void Open()
	{
		if (!_built)
		{
			BuildOverlay();
		}
		_colors = UtilityWheelTheme.Load();
		CollectWeapons();
		ApplyPalette();
		BuildSlots();
		_open = true;
		_targetAlpha = 1f;
		((Component)_canvasGroup).gameObject.SetActive(true);
		DisableInputMaps();
		UpdateSelectionText();
	}

	private void Close(bool equip)
	{
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Expected O, but got Unknown
		if (!_open)
		{
			return;
		}
		_open = false;
		_targetAlpha = 0f;
		RestoreInputMaps(!Cursor.visible);
		if (!equip || _selectedIndex < 0 || _selectedIndex >= _weapons.Count)
		{
			return;
		}
		try
		{
			IsCommittingSelection = true;
			Player.OnInventorySlotSelected((byte)_weapons[_selectedIndex].Slot);
		}
		catch (Exception ex)
		{
			ManualLogSource modLog = UtilityWheelPlugin.ModLog;
			bool flag = default(bool);
			BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(33, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Could not equip wheel selection: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
			}
			modLog.LogWarning(val);
		}
		finally
		{
			IsCommittingSelection = false;
		}
	}

	private static bool CanOpen()
	{
		try
		{
			return Player.isLocalPlayerLoaded && (Object)(object)Player.localPlayer != (Object)null && !Cursor.visible && !PlayerInventoryUI.isOpen && !SkillWheelManager.isOpen && !IsArtisticStudioOpen();
		}
		catch
		{
			return false;
		}
	}

	private static bool CanRemainOpen()
	{
		try
		{
			return (Object)(object)Player.localPlayer != (Object)null && !Cursor.visible && !PlayerInventoryUI.isOpen && !IsArtisticStudioOpen();
		}
		catch
		{
			return false;
		}
	}

	private static bool IsArtisticStudioOpen()
	{
		return (Object)(object)GameObject.Find("Artistic_InputBlocker") != (Object)null;
	}

	private static void ReadActivation(out bool held, out bool pressed)
	{
		held = false;
		pressed = false;
		Gamepad current = Gamepad.current;
		if (current != null)
		{
			ButtonControl val = ((UtilityWheelPlugin.ControllerButton.Value == ControllerWheelButton.RightShoulder) ? current.rightShoulder : current.leftShoulder);
			held = val.isPressed;
			pressed = val.wasPressedThisFrame;
		}
		Keyboard current2 = Keyboard.current;
		if (UtilityWheelPlugin.KeyboardFallback.Value && current2 != null)
		{
			held |= ((ButtonControl)current2.tabKey).isPressed;
			pressed |= ((ButtonControl)current2.tabKey).wasPressedThisFrame;
		}
	}

	private unsafe void CollectWeapons()
	{
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: 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_0078: 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_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		_weapons.Clear();
		Player localPlayer = Player.localPlayer;
		if ((Object)(object)localPlayer == (Object)null || localPlayer.inventory == null)
		{
			return;
		}
		int num = localPlayer.inventory.Count;
		Il2CppReferenceArray<PlayerItemContainerUI> inventorySlotsUI = Player.inventorySlotsUI;
		if (inventorySlotsUI != null && ((Il2CppArrayBase<PlayerItemContainerUI>)(object)inventorySlotsUI).Length > 0)
		{
			num = Mathf.Min(num, ((Il2CppArrayBase<PlayerItemContainerUI>)(object)inventorySlotsUI).Length);
		}
		for (int i = 0; i < num; i++)
		{
			ItemData val = localPlayer.inventory[i];
			if (val.count == 0)
			{
				continue;
			}
			ItemDatabaseEntry itemInfo;
			try
			{
				itemInfo = ItemDatabase.GetItemInfo(val.item);
			}
			catch
			{
				continue;
			}
			if (itemInfo != null)
			{
				string text;
				try
				{
					text = ItemDatabase.GetItemName(val.item);
				}
				catch
				{
					text = ((object)(*(Items*)(&val.item))/*cast due to .constrained prefix*/).ToString();
				}
				_weapons.Add(new WeaponEntry
				{
					Slot = i,
					Name = (string.IsNullOrWhiteSpace(text) ? ((object)(*(Items*)(&val.item))/*cast due to .constrained prefix*/).ToString() : text),
					Icon = itemInfo.icon
				});
			}
		}
		byte currentSlot = Player.localCurrentInventorySlot;
		_selectedIndex = _weapons.FindIndex((WeaponEntry weapon) => weapon.Slot == currentSlot);
	}

	private void UpdateSelection()
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: 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_0065: 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_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		if (_weapons.Count == 0)
		{
			return;
		}
		Vector2 val = Vector2.zero;
		if (Gamepad.current != null)
		{
			val = ((InputControl<Vector2>)(object)Gamepad.current.rightStick).ReadValue();
		}
		else if (Mouse.current != null)
		{
			val = ((InputControl<Vector2>)(object)((Pointer)Mouse.current).position).ReadValue() - new Vector2((float)Screen.width * 0.5f, (float)Screen.height * 0.5f);
			val /= Mathf.Max(1f, (float)Mathf.Min(Screen.width, Screen.height) * 0.35f);
		}
		if (!(((Vector2)(ref val)).magnitude < UtilityWheelPlugin.StickDeadzone.Value))
		{
			float num = Mathf.Repeat(Mathf.Atan2(val.x, val.y) * 57.29578f, 360f);
			float num2 = 360f / (float)_weapons.Count;
			int num3 = Mathf.FloorToInt((num + num2 * 0.5f) / num2) % _weapons.Count;
			if (num3 != _selectedIndex)
			{
				_selectedIndex = num3;
				RefreshHighlights();
				UpdateSelectionText();
			}
		}
	}

	private void BuildOverlay()
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Expected O, but got Unknown
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Expected O, but got Unknown
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_0250: Unknown result type (might be due to invalid IL or missing references)
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_029f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_030d: Unknown result type (might be due to invalid IL or missing references)
		//IL_031c: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("UtilityWheel_Canvas", (Type[])(object)new Type[4]
		{
			Il2CppType.Of<RectTransform>(),
			Il2CppType.Of<Canvas>(),
			Il2CppType.Of<CanvasScaler>(),
			Il2CppType.Of<CanvasGroup>()
		});
		val.transform.SetParent(((Component)this).transform, false);
		Canvas component = val.GetComponent<Canvas>();
		component.renderMode = (RenderMode)0;
		component.sortingOrder = 32000;
		CanvasScaler component2 = val.GetComponent<CanvasScaler>();
		component2.uiScaleMode = (ScaleMode)1;
		component2.referenceResolution = new Vector2(1920f, 1080f);
		component2.matchWidthOrHeight = 0.5f;
		_canvasGroup = val.GetComponent<CanvasGroup>();
		_canvasGroup.alpha = 0f;
		_canvasGroup.interactable = false;
		_canvasGroup.blocksRaycasts = false;
		RectTransform component3 = val.GetComponent<RectTransform>();
		Stretch(component3);
		_scrim = CreateImage("ScreenScrim", (Transform)(object)component3, null);
		Stretch(((Graphic)_scrim).rectTransform);
		GameObject val2 = new GameObject("Wheel", (Type[])(object)new Type[1] { Il2CppType.Of<RectTransform>() });
		val2.transform.SetParent((Transform)(object)component3, false);
		_wheelRoot = val2.GetComponent<RectTransform>();
		_wheelRoot.anchorMin = new Vector2(0.5f, 0.5f);
		_wheelRoot.anchorMax = new Vector2(0.5f, 0.5f);
		_wheelRoot.pivot = new Vector2(0.5f, 0.5f);
		_wheelRoot.sizeDelta = new Vector2(620f, 620f);
		_wheelRoot.anchoredPosition = Vector2.zero;
		_circleSprite = CreateCircleSprite();
		_wheelBackdrop = CreateImage("WheelBackdrop", (Transform)(object)_wheelRoot, _circleSprite);
		SetCenteredSize(((Graphic)_wheelBackdrop).rectTransform, 600f, 600f);
		_centerPanel = CreateImage("CenterPanel", (Transform)(object)_wheelRoot, _circleSprite);
		SetCenteredSize(((Graphic)_centerPanel).rectTransform, 220f, 220f);
		_titleLabel = CreateText("Title", (Transform)(object)((Graphic)_centerPanel).rectTransform, 14f, (FontStyles)1);
		((TMP_Text)_titleLabel).text = "UTILITY WHEEL";
		SetAnchored(((TMP_Text)_titleLabel).rectTransform, new Vector2(0f, 46f), new Vector2(190f, 26f));
		_nameLabel = CreateText("WeaponName", (Transform)(object)((Graphic)_centerPanel).rectTransform, 22f, (FontStyles)1);
		SetAnchored(((TMP_Text)_nameLabel).rectTransform, new Vector2(0f, 6f), new Vector2(190f, 58f));
		_hintLabel = CreateText("Hint", (Transform)(object)((Graphic)_centerPanel).rectTransform, 11f, (FontStyles)0);
		((TMP_Text)_hintLabel).text = "RELEASE  " + ButtonHint + "  TO  EQUIP\nB  CANCEL";
		SetAnchored(((TMP_Text)_hintLabel).rectTransform, new Vector2(0f, -52f), new Vector2(190f, 38f));
		val.SetActive(false);
		_built = true;
	}

	private void BuildSlots()
	{
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: 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_0227: Unknown result type (might be due to invalid IL or missing references)
		//IL_0236: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < _slotVisuals.Count; i++)
		{
			if ((Object)(object)_slotVisuals[i].Sector != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_slotVisuals[i].Sector).gameObject);
			}
			if ((Object)(object)_slotVisuals[i].Panel != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_slotVisuals[i].Panel).gameObject);
			}
		}
		_slotVisuals.Clear();
		if (_weapons.Count == 0)
		{
			((TMP_Text)_nameLabel).text = "HOTBAR EMPTY";
			((TMP_Text)_hintLabel).text = "ADD AN ITEM TO YOUR HOTBAR\nB  CANCEL";
			return;
		}
		Sprite[] sectorSprites = GetSectorSprites(_weapons.Count);
		float num = 360f / (float)_weapons.Count;
		Vector2 position = default(Vector2);
		for (int j = 0; j < _weapons.Count; j++)
		{
			Image val = CreateImage("Sector_" + j, (Transform)(object)_wheelRoot, sectorSprites[j]);
			SetCenteredSize(((Graphic)val).rectTransform, 590f, 590f);
			((Component)val).transform.SetAsFirstSibling();
			float num2 = (float)j * num * ((float)Math.PI / 180f);
			((Vector2)(ref position))..ctor(Mathf.Sin(num2) * 208f, Mathf.Cos(num2) * 208f);
			Image val2 = CreateImage("Weapon_" + j, (Transform)(object)_wheelRoot, _circleSprite);
			SetAnchored(((Graphic)val2).rectTransform, position, new Vector2(86f, 86f));
			Outline obj = ((Component)val2).gameObject.AddComponent<Outline>();
			((Shadow)obj).effectDistance = new Vector2(1.5f, -1.5f);
			((Shadow)obj).useGraphicAlpha = true;
			Image val3 = CreateImage("Icon", (Transform)(object)((Graphic)val2).rectTransform, _weapons[j].Icon);
			SetCenteredSize(((Graphic)val3).rectTransform, 62f, 62f);
			val3.preserveAspect = true;
			Image val4 = CreateImage("CurrentMarker", (Transform)(object)((Graphic)val2).rectTransform, _circleSprite);
			SetAnchored(((Graphic)val4).rectTransform, new Vector2(0f, -36f), new Vector2(9f, 9f));
			_slotVisuals.Add(new SlotVisual
			{
				Sector = val,
				Panel = val2,
				Icon = val3,
				CurrentMarker = val4,
				Rect = ((Graphic)val2).rectTransform
			});
		}
		((Component)_centerPanel).transform.SetAsLastSibling();
		RefreshHighlights();
	}

	private void ApplyPalette()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		((Graphic)_scrim).color = new Color(0f, 0f, 0f, 0.34f);
		((Graphic)_wheelBackdrop).color = new Color(_colors.Panel.r, _colors.Panel.g, _colors.Panel.b, 0.28f);
		((Graphic)_centerPanel).color = _colors.Panel;
		((Graphic)_titleLabel).color = _colors.Accent;
		((Graphic)_nameLabel).color = _colors.Text;
		((Graphic)_hintLabel).color = _colors.Muted;
	}

	private void RefreshHighlights()
	{
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		int localCurrentInventorySlot = Player.localCurrentInventorySlot;
		for (int i = 0; i < _slotVisuals.Count; i++)
		{
			bool flag = i == _selectedIndex;
			bool active = i < _weapons.Count && _weapons[i].Slot == localCurrentInventorySlot;
			SlotVisual slotVisual = _slotVisuals[i];
			((Graphic)slotVisual.Sector).color = (Color)(flag ? _colors.AccentSoft : new Color(_colors.PanelSoft.r, _colors.PanelSoft.g, _colors.PanelSoft.b, _colors.PanelSoft.a * 0.66f));
			((Graphic)slotVisual.Panel).color = (Color)(flag ? new Color(_colors.Accent.r, _colors.Accent.g, _colors.Accent.b, 0.42f) : _colors.PanelSoft);
			((Graphic)slotVisual.Icon).color = (Color)(flag ? Color.white : new Color(1f, 1f, 1f, 0.78f));
			((Graphic)slotVisual.CurrentMarker).color = _colors.Accent;
			((Component)slotVisual.CurrentMarker).gameObject.SetActive(active);
			((Transform)slotVisual.Rect).localScale = (flag ? (Vector3.one * 1.16f) : Vector3.one);
			Outline component = ((Component)slotVisual.Panel).GetComponent<Outline>();
			if ((Object)(object)component != (Object)null)
			{
				((Shadow)component).effectColor = (Color)(flag ? _colors.Accent : new Color(_colors.Muted.r, _colors.Muted.g, _colors.Muted.b, 0.45f));
			}
		}
	}

	private void UpdateSelectionText()
	{
		if (_selectedIndex >= 0 && _selectedIndex < _weapons.Count)
		{
			((TMP_Text)_nameLabel).text = _weapons[_selectedIndex].Name.ToUpperInvariant();
			((TMP_Text)_hintLabel).text = "RELEASE  " + ButtonHint + "  TO  EQUIP\nB  CANCEL";
		}
		else if (_weapons.Count > 0)
		{
			((TMP_Text)_nameLabel).text = "SELECT ITEM";
			((TMP_Text)_hintLabel).text = "RIGHT STICK TO SELECT\nB  CANCEL";
		}
	}

	private void DisableInputMaps()
	{
		_disabledMaps.Clear();
		DisableMap(PlayerInputDispatcher.movementMap);
		DisableMap(PlayerInputDispatcher.inventoryMap);
		DisableMap(PlayerInputDispatcher.skillMap);
		DisableMap(PlayerInputDispatcher.drawingMap);
		DisableMap(PlayerInputDispatcher.placeableMap);
	}

	private void DisableMap(InputActionMap map)
	{
		if (map != null && map.enabled)
		{
			map.Disable();
			_disabledMaps.Add(map);
		}
	}

	private void RestoreInputMaps(bool restore)
	{
		if (restore)
		{
			for (int i = 0; i < _disabledMaps.Count; i++)
			{
				InputActionMap val = _disabledMaps[i];
				if (val != null)
				{
					val.Enable();
				}
			}
		}
		_disabledMaps.Clear();
	}

	private void FadeOverlay()
	{
		if (_built && !((Object)(object)_canvasGroup == (Object)null) && ((Component)_canvasGroup).gameObject.activeSelf)
		{
			_canvasGroup.alpha = Mathf.MoveTowards(_canvasGroup.alpha, _targetAlpha, Time.unscaledDeltaTime * 9f);
			if (!_open && _canvasGroup.alpha <= 0.001f)
			{
				_canvasGroup.alpha = 0f;
				((Component)_canvasGroup).gameObject.SetActive(false);
			}
		}
	}

	private Sprite[] GetSectorSprites(int count)
	{
		if (_sectorSprites.TryGetValue(count, out var value))
		{
			return value;
		}
		value = (Sprite[])(object)new Sprite[count];
		for (int i = 0; i < count; i++)
		{
			value[i] = CreateSectorSprite(count, i);
		}
		_sectorSprites[count] = value;
		return value;
	}

	private static Sprite CreateSectorSprite(int count, int index)
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Expected O, but got Unknown
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		float num = 360f / (float)count;
		float num2 = (float)index * num;
		float num3 = Mathf.Max(2f, num * 0.5f - 1.25f);
		Texture2D val = new Texture2D(256, 256, (TextureFormat)4, false)
		{
			name = $"UtilityWheel_Sector_{count}_{index}",
			filterMode = (FilterMode)1,
			wrapMode = (TextureWrapMode)1,
			hideFlags = (HideFlags)61
		};
		Color32[] array = (Color32[])(object)new Color32[65536];
		Vector2 val2 = default(Vector2);
		((Vector2)(ref val2))..ctor(128f, 128f);
		float num4 = 126f;
		float num5 = num4 * 0.39f;
		Vector2 val3 = default(Vector2);
		for (int i = 0; i < 256; i++)
		{
			for (int j = 0; j < 256; j++)
			{
				((Vector2)(ref val3))..ctor((float)j + 0.5f - val2.x, (float)i + 0.5f - val2.y);
				float magnitude = ((Vector2)(ref val3)).magnitude;
				float num6 = Mathf.Repeat(Mathf.Atan2(val3.x, val3.y) * 57.29578f, 360f);
				float num7 = num3 - Mathf.Abs(Mathf.DeltaAngle(num6, num2));
				float num8 = Mathf.Min(num4 - magnitude, magnitude - num5);
				float num9 = Mathf.Clamp01(Mathf.Min(num7 * 0.85f, num8));
				array[i * 256 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)Mathf.RoundToInt(num9 * 255f));
			}
		}
		val.SetPixels32(Il2CppStructArray<Color32>.op_Implicit(array));
		val.Apply(false, true);
		return Sprite.Create(val, new Rect(0f, 0f, 256f, 256f), new Vector2(0.5f, 0.5f), 100f);
	}

	private static Sprite CreateCircleSprite()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Expected O, but got Unknown
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: 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_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false)
		{
			name = "UtilityWheel_Circle",
			filterMode = (FilterMode)1,
			wrapMode = (TextureWrapMode)1,
			hideFlags = (HideFlags)61
		};
		Color32[] array = (Color32[])(object)new Color32[4096];
		Vector2 val2 = default(Vector2);
		((Vector2)(ref val2))..ctor(32f, 32f);
		float num = 31f;
		for (int i = 0; i < 64; i++)
		{
			for (int j = 0; j < 64; j++)
			{
				float num2 = Vector2.Distance(new Vector2((float)j + 0.5f, (float)i + 0.5f), val2);
				float num3 = Mathf.Clamp01(num + 0.75f - num2);
				array[i * 64 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)Mathf.RoundToInt(num3 * 255f));
			}
		}
		val.SetPixels32(Il2CppStructArray<Color32>.op_Implicit(array));
		val.Apply(false, true);
		return Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f), 100f);
	}

	private static Image CreateImage(string name, Transform parent, Sprite sprite)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject(name, (Type[])(object)new Type[3]
		{
			Il2CppType.Of<RectTransform>(),
			Il2CppType.Of<CanvasRenderer>(),
			Il2CppType.Of<Image>()
		});
		val.transform.SetParent(parent, false);
		Image component = val.GetComponent<Image>();
		component.sprite = sprite;
		component.type = (Type)0;
		((Graphic)component).raycastTarget = false;
		return component;
	}

	private static TextMeshProUGUI CreateText(string name, Transform parent, float size, FontStyles style)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject(name, (Type[])(object)new Type[3]
		{
			Il2CppType.Of<RectTransform>(),
			Il2CppType.Of<CanvasRenderer>(),
			Il2CppType.Of<TextMeshProUGUI>()
		});
		val.transform.SetParent(parent, false);
		TextMeshProUGUI component = val.GetComponent<TextMeshProUGUI>();
		((TMP_Text)component).fontSize = size;
		((TMP_Text)component).fontStyle = style;
		((TMP_Text)component).alignment = (TextAlignmentOptions)514;
		((TMP_Text)component).enableWordWrapping = true;
		((TMP_Text)component).overflowMode = (TextOverflowModes)1;
		((Graphic)component).raycastTarget = false;
		((TMP_Text)component).characterSpacing = 1.1f;
		return component;
	}

	private static void Stretch(RectTransform rect)
	{
		//IL_0001: 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_0017: 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)
		rect.anchorMin = Vector2.zero;
		rect.anchorMax = Vector2.one;
		rect.offsetMin = Vector2.zero;
		rect.offsetMax = Vector2.zero;
	}

	private static void SetCenteredSize(RectTransform rect, float width, float height)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		SetAnchored(rect, Vector2.zero, new Vector2(width, height));
	}

	private static void SetAnchored(RectTransform rect, Vector2 position, Vector2 size)
	{
		//IL_000b: 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_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		rect.anchorMin = new Vector2(0.5f, 0.5f);
		rect.anchorMax = new Vector2(0.5f, 0.5f);
		rect.pivot = new Vector2(0.5f, 0.5f);
		rect.anchoredPosition = position;
		rect.sizeDelta = size;
	}
}
internal enum ControllerWheelButton
{
	LeftShoulder,
	RightShoulder
}
[BepInPlugin("com.holden.infernoprotocol.utilitywheel", "Utility Wheel", "0.2.2")]
public sealed class UtilityWheelPlugin : BasePlugin
{
	[HarmonyPatch]
	private static class UtilityWheelPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(Player), "OnInventorySlotSelected")]
		private static bool BeforeNativeSlotSelection()
		{
			return !ShouldSuppressNativeSelection;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SkillWheelManager), "OpenWheel")]
		private static bool BeforeSkillWheelOpen()
		{
			if (Enabled != null && Enabled.Value)
			{
				return !UtilityWheelController.ActivationControlIsPressed;
			}
			return true;
		}
	}

	private static UtilityWheelController _controller;

	private Harmony _harmony;

	internal static ManualLogSource ModLog { get; private set; }

	internal static ConfigEntry<bool> Enabled { get; private set; }

	internal static ConfigEntry<ControllerWheelButton> ControllerButton { get; private set; }

	internal static ConfigEntry<bool> KeyboardFallback { get; private set; }

	internal static ConfigEntry<bool> MatchBetterUI { get; private set; }

	internal static ConfigEntry<int> FallbackPalette { get; private set; }

	internal static ConfigEntry<float> Opacity { get; private set; }

	internal static ConfigEntry<float> StickDeadzone { get; private set; }

	internal static bool ShouldSuppressNativeSelection
	{
		get
		{
			if (Enabled != null && Enabled.Value && UtilityWheelController.ActivationControlIsPressed)
			{
				return !UtilityWheelController.IsCommittingSelection;
			}
			return false;
		}
	}

	public override void Load()
	{
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Expected O, but got Unknown
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Expected O, but got Unknown
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Expected O, but got Unknown
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Expected O, but got Unknown
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Expected O, but got Unknown
		ModLog = ((BasePlugin)this).Log;
		Enabled = ((BasePlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enables the controller utility wheel.");
		ControllerButton = ((BasePlugin)this).Config.Bind<ControllerWheelButton>("Input", "ControllerButton", ControllerWheelButton.LeftShoulder, "Button held to open the wheel: LeftShoulder or RightShoulder.");
		KeyboardFallback = ((BasePlugin)this).Config.Bind<bool>("Input", "KeyboardTabFallback", true, "Also allows holding Tab to open the wheel for testing or keyboard play.");
		MatchBetterUI = ((BasePlugin)this).Config.Bind<bool>("Appearance", "MatchBetterUIPalette", true, "Reads BetterUI's remembered crafting color when BetterUI is installed.");
		FallbackPalette = ((BasePlugin)this).Config.Bind<int>("Appearance", "FallbackPalette", 0, new ConfigDescription("Palette used without BetterUI: 0 green, 1 blue, 2 cyan, 3 violet, 4 amber.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 4), Array.Empty<object>()));
		Opacity = ((BasePlugin)this).Config.Bind<float>("Appearance", "WheelOpacity", 0.72f, new ConfigDescription("Opacity of the radial panels.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.35f, 0.95f), Array.Empty<object>()));
		StickDeadzone = ((BasePlugin)this).Config.Bind<float>("Input", "StickDeadzone", 0.32f, new ConfigDescription("Right-stick distance required to change selection.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.15f, 0.75f), Array.Empty<object>()));
		_controller = ((BasePlugin)this).AddComponent<UtilityWheelController>();
		_harmony = new Harmony("com.holden.infernoprotocol.utilitywheel");
		_harmony.PatchAll(typeof(UtilityWheelPatches));
		ManualLogSource log = ((BasePlugin)this).Log;
		bool flag = default(bool);
		BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(27, 3, ref flag);
		if (flag)
		{
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Utility Wheel");
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("0.2.2");
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded. Hold ");
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ControllerWheelButton>(ControllerButton.Value);
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" to open it.");
		}
		log.LogInfo(val);
	}

	public override bool Unload()
	{
		Harmony harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
		_harmony = null;
		if ((Object)(object)_controller != (Object)null)
		{
			Object.Destroy((Object)(object)_controller);
			_controller = null;
		}
		return true;
	}
}
internal readonly struct WheelColors
{
	internal Color Accent { get; }

	internal Color AccentSoft { get; }

	internal Color Panel { get; }

	internal Color PanelSoft { get; }

	internal Color Text { get; }

	internal Color Muted { get; }

	internal WheelColors(Color accent, Color accentSoft, Color panel, Color panelSoft, Color text, Color muted)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: 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_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: 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)
		//IL_001e: 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_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		Accent = accent;
		AccentSoft = accentSoft;
		Panel = panel;
		PanelSoft = panelSoft;
		Text = text;
		Muted = muted;
	}
}
internal static class UtilityWheelTheme
{
	internal static WheelColors Load()
	{
		//IL_008c: 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_00b4: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		int num = Mathf.Clamp(UtilityWheelPlugin.FallbackPalette.Value, 0, 4);
		if (UtilityWheelPlugin.MatchBetterUI.Value)
		{
			num = ReadBetterUIPalette(num);
		}
		float shift = num switch
		{
			1 => 0.25f, 
			2 => 0.13f, 
			3 => 0.43f, 
			4 => -0.23f, 
			_ => 0f, 
		};
		float num2 = Mathf.Clamp(UtilityWheelPlugin.Opacity.Value, 0.35f, 0.95f);
		return new WheelColors(ShiftedHex("6DFF83", 1f, shift), ShiftedHex("6DFF83", Mathf.Min(0.52f, num2), shift), ShiftedHex("020805", num2 * 0.78f, shift), ShiftedHex("0C2113", num2, shift), ShiftedHex("D9FFD7", 1f, shift), ShiftedHex("8FBC91", 1f, shift));
	}

	private static int ReadBetterUIPalette(int fallback)
	{
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Expected O, but got Unknown
		try
		{
			string path = Path.Combine(Paths.ConfigPath, "com.holden.infernoprotocol.betterui.cfg");
			if (!File.Exists(path))
			{
				return fallback;
			}
			string[] array = File.ReadAllLines(path);
			for (int i = 0; i < array.Length; i++)
			{
				string text = array[i].Trim();
				if (text.StartsWith("ColorPalette", StringComparison.OrdinalIgnoreCase))
				{
					int num = text.IndexOf('=');
					if (num >= 0 && int.TryParse(text.Substring(num + 1).Trim(), out var result))
					{
						return Mathf.Clamp(result, 0, 4);
					}
				}
			}
		}
		catch (Exception ex)
		{
			ManualLogSource modLog = UtilityWheelPlugin.ModLog;
			bool flag = default(bool);
			BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(33, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Could not read BetterUI palette: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
			}
			modLog.LogDebug(val);
		}
		return fallback;
	}

	private static Color ShiftedHex(string hex, float alpha, float shift)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: 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_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		Color val = Hex(hex, alpha);
		if (Mathf.Abs(shift) < 0.001f)
		{
			return val;
		}
		float num = default(float);
		float num2 = default(float);
		float num3 = default(float);
		Color.RGBToHSV(val, ref num, ref num2, ref num3);
		Color result = Color.HSVToRGB(Mathf.Repeat(num + shift, 1f), num2, num3);
		result.a = alpha;
		return result;
	}

	private static Color Hex(string value, float alpha)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		Color white = default(Color);
		if (!ColorUtility.TryParseHtmlString("#" + value, ref white))
		{
			white = Color.white;
		}
		white.a = alpha;
		return white;
	}
}