Decompiled source of MoreAndQuickLoadouts v1.2.1

MoreAndQuickLoadouts/MoreAndQuickLoadouts.dll

Decompiled 3 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.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Pigeon.Movement;
using Pigeon.UI;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("MayhanGM")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.2.1")]
[assembly: AssemblyInformationalVersion("1.2.1+f601e1c030e6e1c5baf1f117dafef84deae3cf67")]
[assembly: AssemblyProduct("com.mayhan_gm.mycopunk.moreandquickloadouts")]
[assembly: AssemblyTitle("MoreAndQuickLoadouts")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MoreAndQuickLoadouts
{
	[BepInPlugin("MoreAndQuickLoadouts", "com.mayhan_gm.mycopunk.moreandquickloadouts", "1.2.1")]
	[MycoMod(/*Could not decode attribute arguments.*/)]
	public class BasePlugin : BaseUnityPlugin
	{
		private Harmony _harmony;

		internal static ManualLogSource Logger;

		public static int LoadoutSize => PluginConfig.LoadoutSize.Value;

		private void Awake()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			PluginConfig.Init(((BaseUnityPlugin)this).Config);
			NotAnotherTentacleShit.InitializeInputActions();
			_harmony = new Harmony("MoreAndQuickLoadouts");
			_harmony.PatchAll();
			Logger.LogInfo((object)"MoreAndQuickLoadouts loaded.");
		}

		private void OnDestroy()
		{
			NotAnotherTentacleShit.CleanupInputActions();
			_harmony.UnpatchSelf();
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	public class GearDetailsWindow_Awake_Patch
	{
		private static bool _iconsLoaded;

		private static Sprite[] _cachedIcons;

		[HarmonyPatch("Awake")]
		[HarmonyPrefix]
		public static bool PreAwake(GearDetailsWindow __instance)
		{
			if (!_iconsLoaded)
			{
				string text = Path.Combine(Paths.PluginPath, "MoreAndQuickLoadouts", "moreicons");
				AssetBundle val = AssetBundle.LoadFromFile(text);
				Sprite[] array = val.LoadAllAssets<Sprite>();
				Sprite[] loadoutIcons = Global.Instance.LoadoutIcons;
				Sprite[] array2 = (Sprite[])(object)new Sprite[loadoutIcons.Length + array.Length];
				loadoutIcons.CopyTo(array2, 0);
				array.CopyTo(array2, loadoutIcons.Length);
				Global.Instance.LoadoutIcons = array2;
				_cachedIcons = array2;
				_iconsLoaded = true;
				val.Unload(false);
			}
			else if (_cachedIcons != null)
			{
				Global.Instance.LoadoutIcons = _cachedIcons;
			}
			LoadoutInjector loadoutInjector = ((Component)__instance).gameObject.AddComponent<LoadoutInjector>();
			loadoutInjector.target = __instance;
			loadoutInjector.targetCount = BasePlugin.LoadoutSize;
			loadoutInjector.Setup();
			return true;
		}

		[HarmonyPatch(typeof(GearDetailsWindow), "OnClickUp")]
		[HarmonyPrefix]
		public static bool PreOnClickUp()
		{
			return !((Component)LoadoutInjector.Instance.selectIconWindow).gameObject.activeSelf;
		}
	}
	public class LoadoutInjector : MonoBehaviour
	{
		public GearDetailsWindow target;

		public int targetCount;

		public SelectIconWindow selectIconWindow;

		public Transform targetTransform => ((Component)target).transform;

		private int spacingY => 52;

		public static LoadoutInjector Instance { get; private set; }

		public void Awake()
		{
			Instance = this;
		}

		public void Setup()
		{
			SelectIconSetup();
			InjectLoadouts();
		}

		private void SelectIconSetup()
		{
			InfoWindow val = Object.Instantiate<InfoWindow>(Global.Instance.InfoWindow, ((Component)target).transform);
			GameObject gameObject = ((Component)val).gameObject;
			InfoWindow component = gameObject.GetComponent<InfoWindow>();
			if ((Object)(object)component != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component);
			}
			selectIconWindow = gameObject.AddComponent<SelectIconWindow>();
			((Component)selectIconWindow).gameObject.SetActive(false);
			selectIconWindow.Setup(target);
		}

		private void InjectLoadouts()
		{
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Expected O, but got Unknown
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e2: Expected O, but got Unknown
			Transform val = null;
			LoadoutHoverInfo[] buttons = target.loadoutButtons;
			int num = buttons.Length;
			if (targetCount <= num)
			{
				return;
			}
			LoadoutHoverInfo[] array = (LoadoutHoverInfo[])(object)new LoadoutHoverInfo[targetCount];
			for (int j = 0; j < num && j < targetCount; j++)
			{
				array[j] = buttons[j];
			}
			Transform val2 = ((buttons.Length != 0) ? ((Component)buttons[^1]).transform : null);
			for (int num2 = targetTransform.childCount - 1; num2 >= 0; num2--)
			{
				Transform child = targetTransform.GetChild(num2);
				if ((Object)(object)val == (Object)null && ((Object)child).name.StartsWith("IconB"))
				{
					val = child;
				}
			}
			List<Button> list = (from b in ((Component)targetTransform).GetComponentsInChildren<Button>()
				where ((Object)b).name.Contains("IconB")
				select b).ToList();
			for (int k = 0; k < list.Count; k++)
			{
				Button val3 = list[k];
				int persistentEventCount = ((UnityEventBase)val3.OnClickUp).GetPersistentEventCount();
				((UnityEventBase)val3.OnClickUp).RemoveAllListeners();
				for (int num3 = persistentEventCount - 1; num3 >= 0; num3--)
				{
					Object persistentTarget = ((UnityEventBase)val3.OnClickUp).GetPersistentTarget(num3);
					if (((persistentTarget != null) ? persistentTarget.name : null) == null)
					{
					}
					((UnityEventBase)val3.OnClickUp).GetPersistentMethodName(num3);
					((UnityEventBase)val3.OnClickUp).SetPersistentListenerState(num3, (UnityEventCallState)0);
				}
				int i1 = k;
				val3.OnClickUp.AddListener((UnityAction)delegate
				{
					selectIconWindow.OnOpen(buttons[i1]);
				});
				((Component)val3).GetComponent<HoverInfoTextBinding>().primaryLabel = "Select Icon";
			}
			if ((Object)(object)val2 == (Object)null || (Object)(object)val == (Object)null)
			{
				return;
			}
			for (int l = num; l < targetCount; l++)
			{
				string name = $"Loadout{(char)(65 + l)}";
				string name2 = $"IconB_{(char)(65 + l)}";
				GameObject val4 = Object.Instantiate<GameObject>(((Component)val2).gameObject, targetTransform);
				((Object)val4).name = name;
				RectTransform component = val4.GetComponent<RectTransform>();
				component.anchoredPosition = ((Component)val2).GetComponent<RectTransform>().anchoredPosition + new Vector2(0f, (float)(-spacingY * (l - num + 1)));
				LoadoutHoverInfo loadoutHoverInfo = val4.GetComponent<LoadoutHoverInfo>();
				GameObject val5 = Object.Instantiate<GameObject>(((Component)val).gameObject, targetTransform);
				((Object)val5).name = name2;
				RectTransform component2 = val5.GetComponent<RectTransform>();
				component2.anchoredPosition = ((Component)val).GetComponent<RectTransform>().anchoredPosition + new Vector2(0f, (float)(-spacingY * (l - num + 1)));
				Button component3 = val5.GetComponent<Button>();
				if ((Object)(object)component3 != (Object)null)
				{
					int persistentEventCount2 = ((UnityEventBase)component3.OnClickUp).GetPersistentEventCount();
					((UnityEventBase)component3.OnClickUp).RemoveAllListeners();
					for (int num4 = persistentEventCount2 - 1; num4 >= 0; num4--)
					{
						Object persistentTarget2 = ((UnityEventBase)component3.OnClickUp).GetPersistentTarget(num4);
						if (((persistentTarget2 != null) ? persistentTarget2.name : null) == null)
						{
						}
						((UnityEventBase)component3.OnClickUp).GetPersistentMethodName(num4);
						((UnityEventBase)component3.OnClickUp).SetPersistentListenerState(num4, (UnityEventCallState)0);
					}
					component3.OnClickUp.AddListener((UnityAction)delegate
					{
						selectIconWindow.OnOpen(loadoutHoverInfo);
					});
					((Component)component3).GetComponent<HoverInfoTextBinding>().primaryLabel = "Select Icon";
				}
				array[l] = loadoutHoverInfo;
			}
			target.loadoutButtons = array;
		}
	}
	public class LoadoutData
	{
		public string Label;

		public Sprite Icon;

		public GearData GearData;

		public int LoadoutIndex;
	}
	[HarmonyPatch]
	public static class NotAnotherTentacleShit
	{
		private enum LoadoutType
		{
			Weapon,
			Grenade,
			Employee
		}

		private static class Comparing
		{
			internal static bool AreUpgradeListsEqual(IList a, IList b)
			{
				if (a == null && b == null)
				{
					return true;
				}
				if (a == null || b == null || a.Count != b.Count)
				{
					return false;
				}
				return !a.Cast<object>().Where((object x, int i) => !object.Equals(x, b[i])).Any();
			}
		}

		private static InputAction WeaponWheelToggle;

		private static InputAction GrenadeWheelToggle;

		private static InputAction EmployeeWheelToggle;

		private static bool _isLoadoutWheelMode;

		private static bool _initialized;

		private static float _lastLoadoutChangeTime = -999f;

		private static LoadoutType? _activeWheelType;

		private static readonly List<LoadoutData> _currentLoadouts = new List<LoadoutData>();

		private static bool IsTextChatOpen
		{
			get
			{
				try
				{
					return PlayerLook.Instance.IsTextChatOpen;
				}
				catch (Exception arg)
				{
					BasePlugin.Logger.LogError((object)$"Error accessing IsTextChatOpen: {arg}");
					return false;
				}
			}
		}

		public static void InitializeInputActions()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			if (_initialized)
			{
				return;
			}
			try
			{
				WeaponWheelToggle = new InputAction("WeaponWheelToggle", (InputActionType)1, PluginConfig.WeaponLoadoutBinding.Value, (string)null, (string)null, (string)null);
				GrenadeWheelToggle = new InputAction("GrenadeWheelToggle", (InputActionType)1, PluginConfig.GrenadeLoadoutBinding.Value, (string)null, (string)null, (string)null);
				EmployeeWheelToggle = new InputAction("EmployeeWheelToggle", (InputActionType)1, PluginConfig.EmployeeLoadoutBinding.Value, (string)null, (string)null, (string)null);
				WeaponWheelToggle.Enable();
				GrenadeWheelToggle.Enable();
				EmployeeWheelToggle.Enable();
				WeaponWheelToggle.performed += OnWeaponWheelToggle;
				WeaponWheelToggle.canceled += OnWeaponWheelToggle;
				GrenadeWheelToggle.performed += OnGrenadeWheelToggle;
				GrenadeWheelToggle.canceled += OnGrenadeWheelToggle;
				EmployeeWheelToggle.performed += OnEmployeeWheelToggle;
				EmployeeWheelToggle.canceled += OnEmployeeWheelToggle;
				_initialized = true;
			}
			catch (Exception arg)
			{
				BasePlugin.Logger.LogError((object)$"Failed to initialize WeaponWheelToggle InputAction: {arg}");
			}
		}

		public static void CleanupInputActions()
		{
			if (!_initialized)
			{
				return;
			}
			try
			{
				if (WeaponWheelToggle != null)
				{
					WeaponWheelToggle.performed -= OnWeaponWheelToggle;
					WeaponWheelToggle.canceled -= OnWeaponWheelToggle;
					WeaponWheelToggle.Disable();
					WeaponWheelToggle.Dispose();
					WeaponWheelToggle = null;
				}
				if (GrenadeWheelToggle != null)
				{
					GrenadeWheelToggle.performed -= OnGrenadeWheelToggle;
					GrenadeWheelToggle.canceled -= OnGrenadeWheelToggle;
					GrenadeWheelToggle.Disable();
					GrenadeWheelToggle.Dispose();
					GrenadeWheelToggle = null;
				}
				if (EmployeeWheelToggle != null)
				{
					EmployeeWheelToggle.performed -= OnEmployeeWheelToggle;
					EmployeeWheelToggle.canceled -= OnEmployeeWheelToggle;
					EmployeeWheelToggle.Disable();
					EmployeeWheelToggle.Dispose();
					EmployeeWheelToggle = null;
				}
				_initialized = false;
			}
			catch (Exception arg)
			{
				BasePlugin.Logger.LogError((object)$"Failed to cleanup input actions: {arg}");
			}
		}

		[HarmonyPatch(typeof(Highlighter), "HandleQuipWheel")]
		[HarmonyPrefix]
		public static bool Prefix_HandleQuipWheel(Highlighter __instance)
		{
			try
			{
				if ((Object)(object)Player.LocalPlayer == (Object)null || !Player.LocalPlayer.IsAlive)
				{
					return true;
				}
				if (!_isLoadoutWheelMode)
				{
					return true;
				}
				HandleWeaponLoadoutWheel(__instance);
				return false;
			}
			catch (Exception arg)
			{
				BasePlugin.Logger.LogError((object)$"Error in Prefix_HandleQuipWheel: {arg}");
				_isLoadoutWheelMode = false;
				return true;
			}
		}

		private static void OnWeaponWheelToggle(CallbackContext ctx)
		{
			try
			{
				if (!IsTextChatOpen && (!_activeWheelType.HasValue || _activeWheelType == LoadoutType.Weapon))
				{
					WeaponLoadoutWheel(((CallbackContext)(ref ctx)).performed, LoadoutType.Weapon);
				}
			}
			catch (Exception arg)
			{
				BasePlugin.Logger.LogError((object)$"Error in OnWeaponWheelToggle: {arg}");
			}
		}

		private static void OnGrenadeWheelToggle(CallbackContext ctx)
		{
			try
			{
				if (!IsTextChatOpen && (!_activeWheelType.HasValue || _activeWheelType.GetValueOrDefault() == LoadoutType.Grenade))
				{
					WeaponLoadoutWheel(((CallbackContext)(ref ctx)).performed, LoadoutType.Grenade);
				}
			}
			catch (Exception arg)
			{
				BasePlugin.Logger.LogError((object)$"Error in OnGrenadeWheelToggle: {arg}");
			}
		}

		private static void OnEmployeeWheelToggle(CallbackContext ctx)
		{
			try
			{
				if (!IsTextChatOpen && (!_activeWheelType.HasValue || _activeWheelType.GetValueOrDefault() == LoadoutType.Employee))
				{
					WeaponLoadoutWheel(((CallbackContext)(ref ctx)).performed, LoadoutType.Employee);
				}
			}
			catch (Exception arg)
			{
				BasePlugin.Logger.LogError((object)$"Error in OnEmployeeWheelToggle: {arg}");
			}
		}

		private static void HandleWeaponLoadoutWheel(Highlighter highlighterInstance)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_0351: Unknown result type (might be due to invalid IL or missing references)
			//IL_0380: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0414: Unknown result type (might be due to invalid IL or missing references)
			//IL_0407: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)highlighterInstance == (Object)null)
			{
				BasePlugin.Logger.LogError((object)"Highlighter instance is null");
				return;
			}
			try
			{
				float enableEquipWheelTime = Highlighter.Instance.enableEquipWheelTime;
				bool enableQuipWheel = Highlighter.Instance.enableQuipWheel;
				float timeBeforeActivatingWheel = Highlighter.Instance.timeBeforeActivatingWheel;
				Color quipSelectedColor = Highlighter.Instance.quipSelectedColor;
				Color quipUnselectedColor = Highlighter.Instance.quipUnselectedColor;
				float quipSelectedScale = Highlighter.Instance.quipSelectedScale;
				TextMeshProUGUI emoteBinding = Highlighter.Instance.emoteBinding;
				((TMP_Text)emoteBinding).text = "";
				if ((Object)(object)Highlighter.Instance.quipWheel == (Object)null)
				{
					BasePlugin.Logger.LogError((object)"quipWheel GameObject is null");
				}
				else
				{
					if (!enableQuipWheel || Time.unscaledTime - enableEquipWheelTime < timeBeforeActivatingWheel)
					{
						return;
					}
					if (!((Component)Highlighter.Instance.quipWheel).gameObject.activeSelf)
					{
						PlayerInput.EnableMenu();
						((Component)Highlighter.Instance.quipWheel).gameObject.SetActive(true);
						if ((Object)(object)PlayerLook.Instance != (Object)null)
						{
							PlayerLook instance = PlayerLook.Instance;
							int rotationLocksX = instance.RotationLocksX + 1;
							instance.RotationLocksX = rotationLocksX;
							PlayerLook instance2 = PlayerLook.Instance;
							rotationLocksX = instance2.RotationLocksY + 1;
							instance2.RotationLocksY = rotationLocksX;
						}
						if ((Object)(object)Player.LocalPlayer != (Object)null)
						{
							Player.LocalPlayer.LockFiring(true);
						}
						if (_currentLoadouts.Count > 0 && (Object)(object)Highlighter.Instance.quipLabel != (Object)null)
						{
							((TMP_Text)Highlighter.Instance.quipLabel).text = _currentLoadouts[Highlighter.Instance.selectedQuipIndex].Label;
						}
					}
					PlayerControls controls = PlayerInput.Controls;
					object obj;
					MenuActions menu;
					if (controls == null)
					{
						obj = null;
					}
					else
					{
						menu = controls.Menu;
						obj = ((MenuActions)(ref menu)).Point;
					}
					if (obj == null)
					{
						return;
					}
					menu = PlayerInput.Controls.Menu;
					Vector2 val = ((MenuActions)(ref menu)).Point.ReadValue<Vector2>();
					val.x -= (float)Screen.width * 0.5f;
					val.y -= (float)Screen.height * 0.5f;
					if (_currentLoadouts.Count <= 0)
					{
						return;
					}
					float num = 360f / (float)_currentLoadouts.Count;
					float num2 = Mathf.Atan2(val.y, val.x) * 57.29578f;
					if ((double)num2 < 0.0)
					{
						num2 += 360f;
					}
					else if ((double)num2 >= 360.0)
					{
						num2 -= 360f;
					}
					int num3 = 0;
					float num4 = float.MaxValue;
					for (int i = 0; i < _currentLoadouts.Count; i++)
					{
						float num5 = Mathf.Abs(Mathf.DeltaAngle(num2, (float)((double)((float)i * num) + (double)num * 0.5)));
						if (num5 < num4)
						{
							num4 = num5;
							num3 = i;
						}
					}
					if ((Object)(object)Highlighter.Instance.quipSelector != (Object)null)
					{
						((Transform)((Graphic)Highlighter.Instance.quipSelector).rectTransform).localEulerAngles = new Vector3(0f, 0f, Mathf.LerpAngle(((Transform)((Graphic)Highlighter.Instance.quipSelector).rectTransform).localEulerAngles.z, (float)((double)((float)num3 * num + num) + 90.0), 18f * Time.deltaTime));
					}
					if (Highlighter.Instance.quipIcons != null)
					{
						for (int j = 0; j < Mathf.Min(Highlighter.Instance.quipIcons.Count, _currentLoadouts.Count); j++)
						{
							if (!((Object)(object)Highlighter.Instance.quipIcons[j] == (Object)null))
							{
								((Graphic)Highlighter.Instance.quipIcons[j]).color = ((j == num3) ? quipSelectedColor : quipUnselectedColor);
								((Transform)((Graphic)Highlighter.Instance.quipIcons[j]).rectTransform).localScale = (Vector3)((j == num3) ? new Vector3(quipSelectedScale, quipSelectedScale, quipSelectedScale) : Vector3.one);
							}
						}
					}
					if (!((Object)(object)Highlighter.Instance.quipLabel == (Object)null))
					{
						float remainingCooldown = GetRemainingCooldown();
						LoadoutData loadoutData = _currentLoadouts[Highlighter.Instance.selectedQuipIndex];
						((TMP_Text)Highlighter.Instance.quipLabel).text = ((remainingCooldown > 0f) ? $"{loadoutData.Label}\n\n<size=32><color=white>On Cooldown\n{remainingCooldown:F1}s</size></color>" : (loadoutData.Label + "\n\n<size=32><color=white>Ready!</size></color>"));
						if (Highlighter.Instance.selectedQuipIndex != num3)
						{
							Highlighter.Instance.selectedQuipIndex = num3;
						}
					}
				}
			}
			catch (Exception arg)
			{
				BasePlugin.Logger.LogError((object)$"Error in HandleWeaponLoadoutWheel: {arg}");
				throw;
			}
		}

		private static void WeaponLoadoutWheel(bool performed, LoadoutType type)
		{
			try
			{
				if ((Object)(object)Player.LocalPlayer == (Object)null || !Player.LocalPlayer.IsAlive)
				{
					BasePlugin.Logger.LogDebug((object)"Player is null or not alive, ignoring weapon wheel input");
					return;
				}
				Highlighter instance = Highlighter.Instance;
				if ((Object)(object)instance == (Object)null)
				{
					BasePlugin.Logger.LogError((object)"Could not find Highlighter instance");
					return;
				}
				if (performed)
				{
					if (1 == 0)
					{
					}
					GearData val = (GearData)(type switch
					{
						LoadoutType.Weapon => PlayerData.GetGearData((IUpgradable)(object)Player.LocalPlayer.SelectedGear), 
						LoadoutType.Grenade => PlayerData.GetGearData(PlayerData.Instance.grenadeID), 
						LoadoutType.Employee => PlayerData.GetGearData((IUpgradable)(object)Player.LocalPlayer.Character), 
						_ => throw new ArgumentOutOfRangeException("type", type, null), 
					});
					if (1 == 0)
					{
					}
					GearData val2 = val;
					if (val2 == null)
					{
						BasePlugin.Logger.LogError((object)"Could not get weapon gear data");
						return;
					}
					Loadout[] loadouts = val2.loadouts;
					if (loadouts == null || loadouts.Length <= 0)
					{
						BasePlugin.Logger.LogWarning((object)"No loadouts available for current weapon");
						return;
					}
					List<LoadoutData> list = new List<LoadoutData>();
					for (int i = 0; i < loadouts.Length; i++)
					{
						List<UpgradeEquipData> upgrades = loadouts[i].upgrades;
						if (upgrades != null && ((ICollection)upgrades).Count > 0)
						{
							LoadoutData item = new LoadoutData
							{
								Label = $"Loadout {i + 1}",
								Icon = val2.GetLoadoutIcon(i),
								GearData = val2,
								LoadoutIndex = i
							};
							list.Add(item);
						}
					}
					if (list.Count == 0)
					{
						BasePlugin.Logger.LogWarning((object)"No valid loadouts found, weapon wheel will not be activated");
						return;
					}
					_isLoadoutWheelMode = true;
					_activeWheelType = type;
					((TMP_Text)Highlighter.Instance.emoteBinding).text = "";
					((TMP_Text)Highlighter.Instance.emoteLabel).text = val2.Gear.Info.Name;
					Highlighter.Instance.enableQuipWheel = true;
					Highlighter.Instance.enableEquipWheelTime = Time.unscaledTime;
					Highlighter.Instance.selectedQuipIndex = 0;
					SetupLoadouts(instance, list);
					return;
				}
				_activeWheelType = null;
				RectTransform quipWheel = Highlighter.Instance.quipWheel;
				int selectedQuipIndex = Highlighter.Instance.selectedQuipIndex;
				if ((Object)(object)quipWheel != (Object)null && ((Component)quipWheel).gameObject.activeSelf)
				{
					PlayerInput.DisableMenu();
					((Component)quipWheel).gameObject.SetActive(false);
					if ((Object)(object)PlayerLook.Instance != (Object)null)
					{
						PlayerLook instance2 = PlayerLook.Instance;
						int rotationLocksX = instance2.RotationLocksX - 1;
						instance2.RotationLocksX = rotationLocksX;
						PlayerLook instance3 = PlayerLook.Instance;
						rotationLocksX = instance3.RotationLocksY - 1;
						instance3.RotationLocksY = rotationLocksX;
					}
					if ((Object)(object)Player.LocalPlayer != (Object)null)
					{
						Player.LocalPlayer.LockFiring(false);
					}
				}
				Highlighter.Instance.enableQuipWheel = false;
				_isLoadoutWheelMode = false;
				ApplySelectedLoadout(selectedQuipIndex);
			}
			catch (Exception arg)
			{
				BasePlugin.Logger.LogError((object)$"Error in WeaponLoadoutWheel: {arg}");
				_isLoadoutWheelMode = false;
				_activeWheelType = null;
			}
		}

		private static void SetupLoadouts(Highlighter highlighterInstance, List<LoadoutData> loadouts)
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				_currentLoadouts.Clear();
				_currentLoadouts.AddRange(loadouts);
				List<Image> quipIcons = highlighterInstance.quipIcons;
				RectTransform quipWheel = highlighterInstance.quipWheel;
				float quipWheelRadius = highlighterInstance.quipWheelRadius;
				float quipIconSize = highlighterInstance.quipIconSize;
				Image quipSelector = highlighterInstance.quipSelector;
				if (quipIcons == null || (Object)(object)quipWheel == (Object)null)
				{
					BasePlugin.Logger.LogError((object)"Required UI components are null");
					return;
				}
				float num = 360f / (float)loadouts.Count;
				Vector2 anchoredPosition = default(Vector2);
				for (int i = 0; i < loadouts.Count; i++)
				{
					if (i >= quipIcons.Count)
					{
						GameObject val = new GameObject(loadouts[i].Label);
						val.transform.SetParent((Transform)(object)quipWheel, false);
						val.AddComponent<CanvasRenderer>();
						Image val2 = val.AddComponent<Image>();
						((Graphic)val2).raycastTarget = false;
						quipIcons.Add(val2);
					}
					else if (!((Component)quipIcons[i]).gameObject.activeSelf)
					{
						((Component)quipIcons[i]).gameObject.SetActive(true);
					}
					if ((Object)(object)quipIcons[i] != (Object)null)
					{
						quipIcons[i].sprite = loadouts[i].Icon;
						float num2 = (num * (float)i + num * 0.5f) * (MathF.PI / 180f);
						((Vector2)(ref anchoredPosition))..ctor(Mathf.Cos(num2) * quipWheelRadius, Mathf.Sin(num2) * quipWheelRadius);
						((Graphic)quipIcons[i]).rectTransform.anchoredPosition = anchoredPosition;
						((Graphic)quipIcons[i]).rectTransform.sizeDelta = new Vector2(quipIconSize, quipIconSize);
					}
				}
				for (int j = loadouts.Count; j < quipIcons.Count; j++)
				{
					if ((Object)(object)quipIcons[j] != (Object)null && ((Component)quipIcons[j]).gameObject.activeSelf)
					{
						((Component)quipIcons[j]).gameObject.SetActive(false);
					}
				}
				if ((Object)(object)quipSelector != (Object)null)
				{
					quipSelector.fillAmount = num / 360f;
				}
			}
			catch (Exception arg)
			{
				BasePlugin.Logger.LogError((object)$"Error in SetupLoadouts: {arg}");
			}
		}

		private static float GetRemainingCooldown()
		{
			int value = PluginConfig.LoadoutChangeCooldown.Value;
			float num = Time.unscaledTime - _lastLoadoutChangeTime;
			return Mathf.Max(0f, (float)value - num);
		}

		private static void ApplySelectedLoadout(int selectedIndex)
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (selectedIndex < 0 || selectedIndex >= _currentLoadouts.Count)
				{
					BasePlugin.Logger.LogWarning((object)$"Invalid loadout index: {selectedIndex}");
					return;
				}
				float remainingCooldown = GetRemainingCooldown();
				if (remainingCooldown > 0f)
				{
					return;
				}
				LoadoutData loadoutData = _currentLoadouts[selectedIndex];
				if (loadoutData.GearData != null)
				{
					List<UpgradeEquipData> equippedUpgrades = loadoutData.GearData.equippedUpgrades;
					Loadout[] loadouts = loadoutData.GearData.loadouts;
					Loadout val = loadouts[loadoutData.LoadoutIndex];
					if (!Comparing.AreUpgradeListsEqual(equippedUpgrades, val.upgrades))
					{
						EquipAndApply(loadoutData);
						DamagePlayerByPercentage(Player.LocalPlayer, PluginConfig.LoadoutChangeDMGPercent.Value);
						_lastLoadoutChangeTime = Time.unscaledTime;
					}
				}
				else
				{
					BasePlugin.Logger.LogError((object)"Selected loadout has null GearData");
				}
			}
			catch (Exception arg)
			{
				BasePlugin.Logger.LogError((object)$"Error in ApplySelectedLoadout: {arg}");
			}
		}

		private static void EquipAndApply(LoadoutData selectedLoadout)
		{
			selectedLoadout.GearData.EquipLoadout(selectedLoadout.LoadoutIndex);
			if (Player.LocalPlayer.SelectedGearSlot > 0 && Player.LocalPlayer.SelectedGear != null)
			{
				Player.LocalPlayer.SelectedGear.DisableHUD();
				Player.LocalPlayer.SelectedGear.Disable();
			}
			IGear obj = Player.LocalPlayer.Gear[4];
			if (obj != null)
			{
				obj.ApplyUpgrades();
			}
			for (int i = 0; i < Player.LocalPlayer.Gear.Length; i++)
			{
				if (i != 4 && Player.LocalPlayer.Gear[i] != null)
				{
					Player.LocalPlayer.Gear[i].ApplyUpgrades();
				}
			}
			if (Player.LocalPlayer.SelectedGearSlot > 0 && Player.LocalPlayer.SelectedGear != null)
			{
				Player.LocalPlayer.SelectedGear.Enable();
			}
			Player.LocalPlayer.ApplyUpgrades();
			Player.LocalPlayer.SyncSkins();
		}

		private static void DamagePlayerByPercentage(Player player, float percentage)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)player == (Object)null) && player.IsAlive)
			{
				float maxHealth = player.MaxHealth;
				float damage = maxHealth * (percentage / 50f);
				DamageData val = default(DamageData);
				val.damage = damage;
				DamageData val2 = val;
				player.Damage(val2, (IDamageSource)(object)player, ((Component)player).transform.position);
			}
		}
	}
	[HarmonyPatch(typeof(GearData), "SaveLoadout")]
	public class PlayerData_SaveLoadout_Patch
	{
		private static int CustomMaxLoadoutSize => BasePlugin.LoadoutSize;

		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			foreach (CodeInstruction instruction in instructions)
			{
				if (instruction.opcode == OpCodes.Ldc_I4_3)
				{
					yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.PropertyGetter(typeof(PlayerData_SaveLoadout_Patch), "CustomMaxLoadoutSize"));
				}
				else
				{
					yield return instruction;
				}
			}
		}
	}
	[HarmonyPatch(typeof(GearData), "IncrementLoadoutIcon")]
	public class PlayerData_IncrementLoadoutIcon_Patch
	{
		private static int CustomMaxLoadoutSize => BasePlugin.LoadoutSize;

		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			foreach (CodeInstruction instruction in instructions)
			{
				if (instruction.opcode == OpCodes.Ldc_I4_3)
				{
					yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.PropertyGetter(typeof(PlayerData_SaveLoadout_Patch), "CustomMaxLoadoutSize"));
				}
				else
				{
					yield return instruction;
				}
			}
		}
	}
	public static class PluginConfig
	{
		public static ConfigEntry<int> LoadoutSize;

		public static ConfigEntry<int> LoadoutChangeCooldown;

		public static ConfigEntry<float> LoadoutChangeDMGPercent;

		public static ConfigEntry<string> WeaponLoadoutBinding;

		public static ConfigEntry<string> GrenadeLoadoutBinding;

		public static ConfigEntry<string> EmployeeLoadoutBinding;

		public static void Init(ConfigFile config)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			LoadoutSize = config.Bind<int>("General", "LoadoutSize", 5, new ConfigDescription("The number of total available loadouts. (including default ones)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(3, 8), Array.Empty<object>()));
			LoadoutChangeCooldown = config.Bind<int>("General", "LoadoutChangeCooldown", 45, new ConfigDescription("Cooldown for loadout change. (basically balancing it for a bit, but do what you do)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 300), Array.Empty<object>()));
			LoadoutChangeDMGPercent = config.Bind<float>("General", "LoadoutChangeDMGPercent", 100f, new ConfigDescription("Self Damage for loadout change. (basically balancing it for a bit, but do what you do)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			WeaponLoadoutBinding = config.Bind<string>("Bindings", "WeaponLoadoutBinding", "<Keyboard>/h", "Toggle weapon loadout wheel.\n Use Unity Input System control path format. See: https://docs.unity3d.com/Packages/[email protected]/manual/ActionBindings.html#binding-syntax\"");
			GrenadeLoadoutBinding = config.Bind<string>("Bindings", "GrenadeLoadoutBinding", "<Keyboard>/j", "Toggle grenade loadout wheel. \nUse Unity Input System control path format. See: https://docs.unity3d.com/Packages/[email protected]/manual/ActionBindings.html#binding-syntax\".");
			EmployeeLoadoutBinding = config.Bind<string>("Bindings", "EmployeeLoadoutBinding", "<Keyboard>/k", "Toggle employee loadout wheel. \nUse Unity Input System control path format. See: https://docs.unity3d.com/Packages/[email protected]/manual/ActionBindings.html#binding-syntax\"");
		}
	}
	public class SelectIconWindow : MonoBehaviour
	{
		private LoadoutHoverInfo _currentLoadout;

		private static Sprite[] Icons => Global.Instance.LoadoutIcons;

		public GearDetailsWindow Target { get; set; }

		public void Setup(GearDetailsWindow target)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: 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_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Expected O, but got Unknown
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Expected O, but got Unknown
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Expected O, but got Unknown
			BasePlugin.Logger.LogInfo((object)"SelectIconWindow.Setup()");
			Target = target;
			Transform val = ((Component)this).transform.Find("Title");
			TextMeshProUGUI component = ((Component)val).GetComponent<TextMeshProUGUI>();
			((TMP_Text)component).text = "Select Loadout Icon";
			((TMP_Text)component).fontSize = 32f;
			RectTransform val2 = (RectTransform)((Component)val).transform;
			val2.SetSizeWithCurrentAnchors((Axis)1, 64f);
			val2.anchoredPosition = new Vector2(val2.anchoredPosition.x, -48f);
			Transform val3 = ((Component)this).transform.Find("Desc");
			Object.DestroyImmediate((Object)(object)((Component)val3).gameObject.GetComponent<TextMeshPro>());
			RectTransform val4 = ((Component)val3).GetComponent<RectTransform>();
			if ((Object)(object)val4 == (Object)null)
			{
				val4 = ((Component)val3).gameObject.AddComponent<RectTransform>();
			}
			val4.anchorMin = new Vector2(0f, 0f);
			val4.anchorMax = new Vector2(1f, 1f);
			val4.offsetMin = new Vector2(20f, 20f);
			val4.offsetMax = new Vector2(-20f, -100f);
			GridLayoutGroup val5 = ((Component)val3).gameObject.AddComponent<GridLayoutGroup>();
			val5.cellSize = new Vector2(72f, 72f);
			val5.spacing = new Vector2(16f, 16f);
			((LayoutGroup)val5).childAlignment = (TextAnchor)4;
			val5.constraint = (Constraint)1;
			val5.constraintCount = 14;
			ContentSizeFitter val6 = ((Component)val3).gameObject.AddComponent<ContentSizeFitter>();
			val6.horizontalFit = (FitMode)2;
			val6.verticalFit = (FitMode)2;
			for (int j = 0; j < Icons.Length; j++)
			{
				Sprite val7 = Icons[j];
				GameObject val8 = new GameObject($"Icon_{j}");
				val8.transform.SetParent(((Component)val5).transform, false);
				val8.gameObject.SetActive((Object)(object)val7 != (Object)null);
				RectTransform val9 = val8.AddComponent<RectTransform>();
				((Transform)val9).localScale = Vector3.one;
				val9.anchorMin = Vector2.zero;
				val9.anchorMax = Vector2.one;
				val9.sizeDelta = Vector2.zero;
				val9.anchoredPosition = Vector2.zero;
				Image val10 = val8.AddComponent<Image>();
				val10.sprite = val7;
				val10.type = (Type)0;
				val10.preserveAspect = true;
				Button val11 = val8.AddComponent<Button>();
				((Selectable)val11).targetGraphic = (Graphic)(object)val10;
				int i1 = j;
				((UnityEvent)val11.onClick).AddListener((UnityAction)delegate
				{
					SetIcon(i1);
				});
			}
			LayoutRebuilder.ForceRebuildLayoutImmediate(val4);
			Transform obj = ((Component)this).transform.Find("Close");
			if (obj != null)
			{
				((Button)((Component)obj).GetComponent<DefaultButton>()).OnClickUp.AddListener(new UnityAction(OnClose));
			}
			((Component)((Component)this).transform.Find("Ok")).gameObject.SetActive(false);
		}

		private void SetIcon(int i)
		{
			int num = Array.IndexOf(Target.loadoutButtons, _currentLoadout);
			GearData gearData = PlayerData.GetGearData(Target.UpgradablePrefab);
			gearData.loadouts[num].iconIndex = i;
			Target.UpdateLoadoutIcon(_currentLoadout, num);
			OnClose();
		}

		public void OnOpen(LoadoutHoverInfo currentLoadout)
		{
			BasePlugin.Logger.LogInfo((object)"SelectIconWindow.OnOpen()");
			_currentLoadout = currentLoadout;
			((Component)this).gameObject.SetActive(true);
		}

		public void OnClose()
		{
			BasePlugin.Logger.LogInfo((object)"SelectIconWindow.OnClose()");
			_currentLoadout = null;
			((Component)this).gameObject.SetActive(false);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "MoreAndQuickLoadouts";

		public const string PLUGIN_NAME = "com.mayhan_gm.mycopunk.moreandquickloadouts";

		public const string PLUGIN_VERSION = "1.2.1";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}