Decompiled source of ImprovedLoadouts v1.0.0

BepInEx/plugins/ImprovedLoadouts.dll

Decompiled 11 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("ImprovedLoadouts")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.0.0.0")]
[assembly: AssemblyInformationalVersion("0.0.0-alpha.0+da7f22f1fead07f520355976d6c527e064e5416c")]
[assembly: AssemblyProduct("ImprovedLoadouts")]
[assembly: AssemblyTitle("ImprovedLoadouts")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.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;
		}
	}
}
[BepInPlugin("sparroh.improvedloadouts", "ImprovedLoadouts", "1.0.0")]
[MycoMod(/*Could not decode attribute arguments.*/)]
public class ImprovedLoadoutsPlugin : BaseUnityPlugin
{
	public const string PluginGUID = "sparroh.improvedloadouts";

	public const string PluginName = "ImprovedLoadouts";

	public const string PluginVersion = "1.0.0";

	internal static ManualLogSource Logger;

	private static Harmony harmonyInstance;

	private void Awake()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Expected O, but got Unknown
		Logger = ((BaseUnityPlugin)this).Logger;
		harmonyInstance = new Harmony("sparroh.improvedloadouts");
		harmonyInstance.PatchAll(typeof(PlayerDataPatches));
		harmonyInstance.PatchAll(typeof(GearDetailsWindowPatches));
		harmonyInstance.PatchAll(typeof(LoadoutHoverInfoPatches));
		Logger.LogInfo((object)"ImprovedLoadouts loaded successfully.");
	}
}
[HarmonyPatch]
public static class PlayerDataPatches
{
	private const int MAX_LOADOUT_SLOTS = 9;

	private static readonly Type LoadoutType = typeof(PlayerData).GetNestedType("Loadout", BindingFlags.NonPublic);

	private static readonly Type UpgradeEquipDataType = typeof(PlayerData).GetNestedType("UpgradeEquipData", BindingFlags.NonPublic);

	[HarmonyPatch(typeof(GearData), "SaveLoadout")]
	[HarmonyPrefix]
	public static bool SaveLoadoutPrefix(ref GearData __instance, int index, ref object ___loadouts)
	{
		Array array = ___loadouts as Array;
		if (array == null)
		{
			array = (Array)(___loadouts = Array.CreateInstance(LoadoutType, Mathf.Max(index + 1, 9)));
		}
		if (index >= array.Length)
		{
			Array array2 = Array.CreateInstance(LoadoutType, Mathf.Max(index + 1, 9));
			array.CopyTo(array2, 0);
			___loadouts = array2;
		}
		return true;
	}

	[HarmonyPatch(typeof(GearData), "EquipLoadout")]
	[HarmonyPrefix]
	public static bool EquipLoadoutPrefix(ref GearData __instance, int index, ref object ___loadouts, ref bool __result)
	{
		if (!(___loadouts is Array array) || index < 0 || index >= array.Length)
		{
			__result = false;
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(GearData), "IncrementLoadoutIcon")]
	[HarmonyPostfix]
	public static void IncrementLoadoutIconPostfix(ref GearData __instance, int index, ref object ___loadouts)
	{
		Array array = ___loadouts as Array;
		if (array == null)
		{
			array = (Array)(___loadouts = Array.CreateInstance(LoadoutType, Mathf.Max(index + 1, 9)));
		}
		if (index >= array.Length)
		{
			Array array2 = Array.CreateInstance(LoadoutType, Mathf.Max(index + 1, 9));
			array.CopyTo(array2, 0);
			___loadouts = array2;
			array = array2;
		}
		object value = array.GetValue(index);
		if (value == null)
		{
			return;
		}
		try
		{
			FieldInfo field = LoadoutType.GetField("upgrades", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				_ = (field.GetValue(value) as IList)?.Count;
			}
			int num = (field?.GetValue(value) as IList)?.Count ?? 0;
			int num2 = 0;
			Type type = AccessTools.TypeByName("Global");
			object obj = type.GetProperty("Instance")?.GetValue(null);
			if (type.GetProperty("LoadoutIcons")?.GetValue(obj) is Array array3)
			{
				num2 = array3.Length;
			}
			int num3 = num + num2;
			int num5 = (((LoadoutType.GetField("iconIndex")?.GetValue(value) is int num4) ? num4 : 0) + 1) % Mathf.Max(1, num3);
			LoadoutType.GetField("iconIndex")?.SetValue(value, num5);
			try
			{
				Type type2 = AccessTools.TypeByName("GearDetailsWindow");
				object obj2 = null;
				PropertyInfo property = type2.GetProperty("Active", BindingFlags.Static | BindingFlags.Public);
				if (property != null)
				{
					obj2 = property.GetValue(null);
				}
				if (obj2 == null)
				{
					Object[] array4 = Object.FindObjectsOfType(type2);
					if (array4.Length != 0)
					{
						obj2 = array4[0];
					}
				}
				if (obj2 == null)
				{
					return;
				}
				MethodInfo method = type2.GetMethod("UpdateLoadoutIcon", BindingFlags.Instance | BindingFlags.NonPublic);
				if (method != null && type2.GetField("loadoutButtons", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(obj2) is Array array5 && index < array5.Length)
				{
					object value2 = array5.GetValue(index);
					if (value2 != null)
					{
						method.Invoke(obj2, new object[2] { value2, index });
					}
				}
			}
			catch (Exception)
			{
			}
		}
		catch (Exception)
		{
		}
	}

	[HarmonyPatch(typeof(GearData), "GetLoadoutIcon")]
	[HarmonyPostfix]
	public static void GetLoadoutIconPostfix(ref GearData __instance, int index, ref object ___loadouts, ref Sprite __result)
	{
		if (!(___loadouts is Array array) || index < 0 || index >= array.Length)
		{
			return;
		}
		object value = array.GetValue(index);
		if (value == null)
		{
			return;
		}
		try
		{
			FieldInfo? field = LoadoutType.GetField("upgrades", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			_ = field != null;
			IList obj = field?.GetValue(value) as IList;
			if (obj == null || obj.Count == 0)
			{
				return;
			}
		}
		catch (Exception)
		{
			return;
		}
		try
		{
			if (!(LoadoutType.GetField("upgrades", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(value) is IList list) || list.Count == 0)
			{
				return;
			}
			int count = list.Count;
			int num2 = ((LoadoutType.GetField("iconIndex")?.GetValue(value) is int num) ? num : 0);
			if (num2 < count)
			{
				object obj2 = list[num2];
				object obj3 = null;
				try
				{
					MethodInfo method = UpgradeEquipDataType.GetMethod("GetUpgrade", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (method != null)
					{
						object obj4 = method.Invoke(obj2, new object[0]);
						if (obj4 != null)
						{
							PropertyInfo property = obj4.GetType().GetProperty("Upgrade", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
							if (property != null)
							{
								obj3 = property.GetValue(obj4);
								AccessTools.TypeByName("Upgrade").GetProperty("Icon")?.GetValue(obj3);
							}
						}
					}
				}
				catch (Exception)
				{
				}
				if (obj3 != null)
				{
					object? obj5 = AccessTools.TypeByName("Upgrade").GetProperty("Icon")?.GetValue(obj3);
					Sprite val = (Sprite)((obj5 is Sprite) ? obj5 : null);
					if ((Object)(object)val != (Object)null)
					{
						__result = val;
						return;
					}
				}
			}
		}
		catch (Exception)
		{
			return;
		}
		try
		{
			Type type = AccessTools.TypeByName("Global");
			object obj6 = type.GetProperty("Instance")?.GetValue(null);
			if (type.GetProperty("LoadoutIcons")?.GetValue(obj6) is Array array2)
			{
				int num4 = ((LoadoutType.GetField("iconIndex")?.GetValue(value) is int num3) ? num3 : 0);
				int num5 = (LoadoutType.GetField("upgrades", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(value) as IList)?.Count ?? 0;
				int num6 = num4 - num5;
				if (num6 >= 0 && num6 < array2.Length)
				{
					object? value2 = array2.GetValue(num6);
					__result = (Sprite)((value2 is Sprite) ? value2 : null);
				}
			}
		}
		catch (Exception)
		{
		}
	}
}
[HarmonyPatch]
public static class GearDetailsWindowPatches
{
	private const int NEW_LOADOUT_COUNT = 9;

	private static FieldInfo loadoutButtonsField;

	[HarmonyPatch(typeof(GearDetailsWindow), "Setup")]
	[HarmonyPostfix]
	public static void SetupPostfix(ref GearDetailsWindow __instance, IUpgradable upgradable)
	{
		try
		{
			Type typeFromHandle = typeof(PlayerData);
			object obj = typeFromHandle.GetProperty("Instance", BindingFlags.Static | BindingFlags.Public)?.GetValue(null);
			object obj2 = typeFromHandle.GetMethod("GetGearData", new Type[1] { typeof(IUpgradable) })?.Invoke(obj, new object[1] { upgradable });
			if (obj2 != null)
			{
				FieldInfo field = obj2.GetType().GetField("loadouts", BindingFlags.Instance | BindingFlags.NonPublic);
				if (field != null)
				{
					Array array = field.GetValue(obj2) as Array;
					Type nestedType = typeFromHandle.GetNestedType("Loadout", BindingFlags.NonPublic);
					if (array == null || array.Length < 9)
					{
						Array array2 = Array.CreateInstance(nestedType, 9);
						array?.CopyTo(array2, 0);
						field.SetValue(obj2, array2);
					}
				}
			}
		}
		catch (Exception)
		{
		}
		FieldInfo field2 = ((object)__instance).GetType().GetField("loadoutButtons", BindingFlags.Instance | BindingFlags.NonPublic);
		if (field2 != null && field2.GetValue(__instance) is Array array3)
		{
			int length = array3.Length;
			for (int i = 0; i < Mathf.Min(9, length); i++)
			{
				object value = array3.GetValue(i);
				if (value != null)
				{
					object obj3 = value.GetType().GetProperty("gameObject")?.GetValue(value);
					obj3?.GetType().GetMethod("SetActive")?.Invoke(obj3, new object[1] { true });
				}
			}
			_ = 9;
		}
		try
		{
			if (upgradable == null)
			{
				return;
			}
			if (!LoadoutHoverInfoPatches.windowLoadoutNames.TryGetValue(__instance, out var value2))
			{
				value2 = new Dictionary<int, string>();
				LoadoutHoverInfoPatches.windowLoadoutNames[__instance] = value2;
			}
			for (int j = 0; j < 9; j++)
			{
				string text = $"{upgradable.Info.ID}_{j}";
				string @string = PlayerPrefs.GetString("LoadoutName_" + text, "");
				if (!string.IsNullOrEmpty(@string))
				{
					value2[j] = @string;
				}
			}
		}
		catch (Exception)
		{
		}
	}

	private static void UpdateLoadoutIcon(GearDetailsWindow instance, LoadoutHoverInfo button, int index)
	{
		typeof(GearDetailsWindow).GetMethod("UpdateLoadoutIcon", BindingFlags.Instance | BindingFlags.NonPublic)?.Invoke(instance, new object[2] { button, index });
	}
}
[HarmonyPatch]
public static class LoadoutHoverInfoPatches
{
	[HarmonyPatch]
	public class LoadoutRenameDialog : MonoBehaviour
	{
		private static LoadoutRenameDialog Instance;

		private Canvas canvas;

		private Image background;

		private TMP_InputField inputField;

		private Button applyButton;

		private Button cancelButton;

		private TextMeshProUGUI applyText;

		private TextMeshProUGUI cancelText;

		private Action<string> onApplyCallback;

		private Action onCancelCallback;

		private GearDetailsWindow window;

		private int loadoutIndex;

		public static bool IsActive => (Object)(object)Instance != (Object)null;

		public static void Show(Vector2 screenPosition, string currentName, Action<string> onApply, Action onCancel, GearDetailsWindow targetWindow, int targetLoadoutIndex)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			if (IsActive)
			{
				Close();
			}
			WindowSystem windowSystem = GameManager.Instance.WindowSystem;
			GameObject val = new GameObject("LoadoutRenameDialog");
			val.transform.SetParent(((Component)windowSystem).transform, false);
			LoadoutRenameDialog loadoutRenameDialog = val.AddComponent<LoadoutRenameDialog>();
			loadoutRenameDialog.Initialize(screenPosition, currentName, onApply, onCancel, targetWindow, targetLoadoutIndex);
			Instance = loadoutRenameDialog;
		}

		public static void Close()
		{
			if ((Object)(object)Instance != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)Instance).gameObject);
				Instance = null;
			}
		}

		private void Initialize(Vector2 screenPosition, string currentName, Action<string> onApply, Action onCancel, GearDetailsWindow targetWindow, int targetLoadoutIndex)
		{
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Expected O, but got Unknown
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: 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_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: 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_0200: Expected O, but got Unknown
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Expected O, but got Unknown
			//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_041c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0440: Unknown result type (might be due to invalid IL or missing references)
			//IL_0464: Unknown result type (might be due to invalid IL or missing references)
			//IL_0488: Unknown result type (might be due to invalid IL or missing references)
			//IL_0497: Unknown result type (might be due to invalid IL or missing references)
			//IL_049e: Expected O, but got Unknown
			//IL_04e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_050f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0529: Unknown result type (might be due to invalid IL or missing references)
			//IL_0543: Unknown result type (might be due to invalid IL or missing references)
			//IL_0552: Unknown result type (might be due to invalid IL or missing references)
			//IL_0559: Expected O, but got Unknown
			//IL_0594: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0600: Unknown result type (might be due to invalid IL or missing references)
			//IL_0624: Unknown result type (might be due to invalid IL or missing references)
			//IL_0648: Unknown result type (might be due to invalid IL or missing references)
			//IL_0657: Unknown result type (might be due to invalid IL or missing references)
			//IL_065e: Expected O, but got Unknown
			//IL_06a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0703: Unknown result type (might be due to invalid IL or missing references)
			//IL_071f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0729: Expected O, but got Unknown
			//IL_073b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0745: Expected O, but got Unknown
			window = targetWindow;
			loadoutIndex = targetLoadoutIndex;
			onApplyCallback = onApply;
			onCancelCallback = onCancel;
			object? obj = ((object)window).GetType().GetProperty("gameObject")?.GetValue(window);
			GameObject val = (GameObject)((obj is GameObject) ? obj : null);
			if ((Object)(object)val != (Object)null)
			{
				canvas = val.GetComponentInParent<Canvas>();
			}
			if ((Object)(object)canvas == (Object)null)
			{
				canvas = Object.FindObjectOfType<Canvas>();
			}
			if (!((Object)(object)canvas == (Object)null))
			{
				((Component)this).transform.SetParent(((Component)canvas).transform, false);
				CanvasGroup obj2 = ((Component)this).gameObject.AddComponent<CanvasGroup>();
				obj2.alpha = 1f;
				obj2.interactable = true;
				obj2.blocksRaycasts = true;
				GameObject val2 = new GameObject("Background");
				val2.transform.SetParent(((Component)this).transform, false);
				background = val2.AddComponent<Image>();
				((Graphic)background).color = new Color(0.2f, 0.2f, 0.2f, 0.95f);
				Transform transform = ((Component)background).transform;
				((RectTransform)((transform is RectTransform) ? transform : null)).anchorMin = new Vector2(0.5f, 0.5f);
				Transform transform2 = ((Component)background).transform;
				((RectTransform)((transform2 is RectTransform) ? transform2 : null)).anchorMax = new Vector2(0.5f, 0.5f);
				Transform transform3 = ((Component)background).transform;
				((RectTransform)((transform3 is RectTransform) ? transform3 : null)).pivot = new Vector2(0.5f, 0.5f);
				Transform transform4 = ((Component)background).transform;
				((RectTransform)((transform4 is RectTransform) ? transform4 : null)).sizeDelta = new Vector2(300f, 120f);
				Transform transform5 = ((Component)canvas).transform;
				Vector2 val3 = default(Vector2);
				RectTransformUtility.ScreenPointToLocalPointInRectangle((RectTransform)(object)((transform5 is RectTransform) ? transform5 : null), screenPosition, canvas.worldCamera, ref val3);
				val3.x += 300f;
				val3.y += 200f;
				((Component)this).transform.localPosition = Vector2.op_Implicit(val3);
				GameObject val4 = new GameObject("InputField");
				val4.transform.SetParent(((Component)this).transform, false);
				inputField = val4.AddComponent<TMP_InputField>();
				GameObject val5 = new GameObject("Text");
				val5.transform.SetParent(val4.transform, false);
				TextMeshProUGUI val6 = val5.AddComponent<TextMeshProUGUI>();
				inputField.textComponent = (TMP_Text)(object)val6;
				((TMP_Text)val6).fontSize = 24f;
				((Graphic)val6).color = Color.white;
				((TMP_Text)val6).rectTransform.anchorMin = Vector2.zero;
				((TMP_Text)val6).rectTransform.anchorMax = Vector2.one;
				((TMP_Text)val6).rectTransform.sizeDelta = Vector2.zero;
				inputField.text = currentName;
				inputField.caretColor = Color.white;
				((Graphic)val4.AddComponent<Image>()).color = new Color(0.1f, 0.1f, 0.1f, 1f);
				Transform transform6 = ((Component)inputField).transform;
				((RectTransform)((transform6 is RectTransform) ? transform6 : null)).anchorMin = new Vector2(0.5f, 0.5f);
				Transform transform7 = ((Component)inputField).transform;
				((RectTransform)((transform7 is RectTransform) ? transform7 : null)).anchorMax = new Vector2(0.5f, 0.5f);
				Transform transform8 = ((Component)inputField).transform;
				((RectTransform)((transform8 is RectTransform) ? transform8 : null)).pivot = new Vector2(0.5f, 0.5f);
				Transform transform9 = ((Component)inputField).transform;
				((RectTransform)((transform9 is RectTransform) ? transform9 : null)).sizeDelta = new Vector2(250f, 40f);
				Transform transform10 = ((Component)inputField).transform;
				((RectTransform)((transform10 is RectTransform) ? transform10 : null)).anchoredPosition = new Vector2(0f, 20f);
				GameObject val7 = new GameObject("ApplyButton");
				val7.transform.SetParent(((Component)this).transform, false);
				applyButton = val7.AddComponent<Button>();
				((Graphic)val7.AddComponent<Image>()).color = new Color(0.3f, 0.6f, 0.3f, 1f);
				Transform transform11 = ((Component)applyButton).transform;
				((RectTransform)((transform11 is RectTransform) ? transform11 : null)).anchorMin = new Vector2(0.5f, 0.5f);
				Transform transform12 = ((Component)applyButton).transform;
				((RectTransform)((transform12 is RectTransform) ? transform12 : null)).anchorMax = new Vector2(0.5f, 0.5f);
				Transform transform13 = ((Component)applyButton).transform;
				((RectTransform)((transform13 is RectTransform) ? transform13 : null)).pivot = new Vector2(0.5f, 0.5f);
				Transform transform14 = ((Component)applyButton).transform;
				((RectTransform)((transform14 is RectTransform) ? transform14 : null)).sizeDelta = new Vector2(80f, 35f);
				Transform transform15 = ((Component)applyButton).transform;
				((RectTransform)((transform15 is RectTransform) ? transform15 : null)).anchoredPosition = new Vector2(-50f, -35f);
				GameObject val8 = new GameObject("ApplyText");
				val8.transform.SetParent(val7.transform, false);
				applyText = val8.AddComponent<TextMeshProUGUI>();
				((TMP_Text)applyText).text = "Apply";
				((TMP_Text)applyText).fontSize = 20f;
				((Graphic)applyText).color = Color.white;
				((TMP_Text)applyText).alignment = (TextAlignmentOptions)514;
				Transform transform16 = ((TMP_Text)applyText).transform;
				((RectTransform)((transform16 is RectTransform) ? transform16 : null)).anchorMin = Vector2.zero;
				Transform transform17 = ((TMP_Text)applyText).transform;
				((RectTransform)((transform17 is RectTransform) ? transform17 : null)).anchorMax = Vector2.one;
				Transform transform18 = ((TMP_Text)applyText).transform;
				((RectTransform)((transform18 is RectTransform) ? transform18 : null)).sizeDelta = Vector2.zero;
				GameObject val9 = new GameObject("CancelButton");
				val9.transform.SetParent(((Component)this).transform, false);
				cancelButton = val9.AddComponent<Button>();
				((Graphic)val9.AddComponent<Image>()).color = new Color(0.6f, 0.3f, 0.3f, 1f);
				Transform transform19 = ((Component)cancelButton).transform;
				((RectTransform)((transform19 is RectTransform) ? transform19 : null)).anchorMin = new Vector2(0.5f, 0.5f);
				Transform transform20 = ((Component)cancelButton).transform;
				((RectTransform)((transform20 is RectTransform) ? transform20 : null)).anchorMax = new Vector2(0.5f, 0.5f);
				Transform transform21 = ((Component)cancelButton).transform;
				((RectTransform)((transform21 is RectTransform) ? transform21 : null)).pivot = new Vector2(0.5f, 0.5f);
				Transform transform22 = ((Component)cancelButton).transform;
				((RectTransform)((transform22 is RectTransform) ? transform22 : null)).sizeDelta = new Vector2(80f, 35f);
				Transform transform23 = ((Component)cancelButton).transform;
				((RectTransform)((transform23 is RectTransform) ? transform23 : null)).anchoredPosition = new Vector2(50f, -35f);
				GameObject val10 = new GameObject("CancelText");
				val10.transform.SetParent(val9.transform, false);
				cancelText = val10.AddComponent<TextMeshProUGUI>();
				((TMP_Text)cancelText).text = "Cancel";
				((TMP_Text)cancelText).fontSize = 20f;
				((Graphic)cancelText).color = Color.white;
				((TMP_Text)cancelText).alignment = (TextAlignmentOptions)514;
				Transform transform24 = ((TMP_Text)cancelText).transform;
				((RectTransform)((transform24 is RectTransform) ? transform24 : null)).anchorMin = Vector2.zero;
				Transform transform25 = ((TMP_Text)cancelText).transform;
				((RectTransform)((transform25 is RectTransform) ? transform25 : null)).anchorMax = Vector2.one;
				Transform transform26 = ((TMP_Text)cancelText).transform;
				((RectTransform)((transform26 is RectTransform) ? transform26 : null)).sizeDelta = Vector2.zero;
				((UnityEvent)applyButton.onClick).AddListener(new UnityAction(OnApplyClicked));
				((UnityEvent)cancelButton.onClick).AddListener(new UnityAction(OnCancelClicked));
				inputField.ActivateInputField();
				((Selectable)inputField).Select();
			}
		}

		private void OnApplyClicked()
		{
			if (!string.IsNullOrWhiteSpace(inputField.text))
			{
				onApplyCallback?.Invoke(inputField.text);
			}
			Close();
		}

		private void OnCancelClicked()
		{
			onCancelCallback?.Invoke();
			Close();
		}

		private void Update()
		{
			Keyboard current = Keyboard.current;
			if (current != null)
			{
				if (((ButtonControl)current.enterKey).wasPressedThisFrame || ((ButtonControl)current.numpadEnterKey).wasPressedThisFrame)
				{
					OnApplyClicked();
				}
				else if (((ButtonControl)current.escapeKey).wasPressedThisFrame)
				{
					OnCancelClicked();
				}
			}
		}

		private void OnDestroy()
		{
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}
	}

	private static readonly Type LoadoutHoverInfoType = AccessTools.TypeByName("LoadoutHoverInfo");

	private static bool isRenaming = false;

	private static string currentRenameValue = "";

	private static LoadoutHoverInfo currentlyRenamingButton = null;

	private static readonly Dictionary<int, string> loadoutNames = new Dictionary<int, string>();

	internal static readonly Dictionary<GearDetailsWindow, Dictionary<int, string>> windowLoadoutNames = new Dictionary<GearDetailsWindow, Dictionary<int, string>>();

	private static string GetLoadoutName(GearDetailsWindow window, int loadoutIndex)
	{
		try
		{
			if (windowLoadoutNames.TryGetValue(window, out var value) && value.TryGetValue(loadoutIndex, out var value2) && !string.IsNullOrEmpty(value2))
			{
				return value2;
			}
			object? obj = ((object)window).GetType().GetField("upgradable", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(window);
			IUpgradable val = (IUpgradable)((obj is IUpgradable) ? obj : null);
			if (val != null)
			{
				string text = $"{val.Info.ID}_{loadoutIndex}";
				string @string = PlayerPrefs.GetString("LoadoutName_" + text, "");
				if (!string.IsNullOrEmpty(@string))
				{
					if (!windowLoadoutNames.TryGetValue(window, out var value3))
					{
						value3 = new Dictionary<int, string>();
						windowLoadoutNames[window] = value3;
					}
					value3[loadoutIndex] = @string;
					return @string;
				}
			}
		}
		catch (Exception)
		{
		}
		return $"Loadout {loadoutIndex + 1}";
	}

	private static void SetLoadoutName(GearDetailsWindow window, int loadoutIndex, string newName)
	{
		try
		{
			if (!windowLoadoutNames.TryGetValue(window, out var value))
			{
				value = new Dictionary<int, string>();
				windowLoadoutNames[window] = value;
			}
			if (!string.IsNullOrEmpty(newName))
			{
				value[loadoutIndex] = newName;
			}
			else
			{
				value.Remove(loadoutIndex);
			}
			try
			{
				IUpgradable upgradablePrefab = window.UpgradablePrefab;
				if (upgradablePrefab != null)
				{
					string text = $"{upgradablePrefab.Info.ID}_{loadoutIndex}";
					if (!string.IsNullOrEmpty(newName))
					{
						PlayerPrefs.SetString("LoadoutName_" + text, newName);
						PlayerPrefs.Save();
						PlayerPrefs.SetString($"ImprovedLoadouts_Name_{upgradablePrefab.Info.ID}_{loadoutIndex}", newName);
						PlayerPrefs.Save();
					}
					else
					{
						PlayerPrefs.DeleteKey("LoadoutName_" + text);
						PlayerPrefs.Save();
					}
				}
			}
			catch (Exception)
			{
			}
			try
			{
				Type type = AccessTools.TypeByName("HoverInfoDisplay");
				object obj = type.GetProperty("Instance", BindingFlags.Static | BindingFlags.Public)?.GetValue(null);
				if (obj == null)
				{
					return;
				}
				FieldInfo field = type.GetField("currentInfo", BindingFlags.Instance | BindingFlags.NonPublic);
				MethodInfo method = type.GetMethod("SetInfo", BindingFlags.Instance | BindingFlags.Public);
				if (!(field != null) || !(method != null))
				{
					return;
				}
				object value2 = field.GetValue(obj);
				if (((object)window).GetType().GetField("loadoutButtons", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(window) is Array array && loadoutIndex < array.Length)
				{
					object? value3 = array.GetValue(loadoutIndex);
					LoadoutHoverInfo val = (LoadoutHoverInfo)((value3 is LoadoutHoverInfo) ? value3 : null);
					if (value2 != null && value2 == val)
					{
						field.SetValue(obj, null);
						method.Invoke(obj, new object[1] { val });
					}
				}
			}
			catch (Exception)
			{
				try
				{
					Type type2 = AccessTools.TypeByName("HoverInfoDisplay");
					object obj2 = type2.GetProperty("Instance", BindingFlags.Static | BindingFlags.Public)?.GetValue(null);
					if (obj2 != null)
					{
						type2.GetMethod("Deactivate", BindingFlags.Instance | BindingFlags.Public)?.Invoke(obj2, new object[0]);
					}
				}
				catch (Exception)
				{
				}
			}
		}
		catch (Exception)
		{
		}
	}

	private static int FindHoveredButton(GearDetailsWindow window)
	{
		try
		{
			try
			{
				Type type = AccessTools.TypeByName("HoverInfoDisplay");
				object obj = type.GetProperty("Instance", BindingFlags.Static | BindingFlags.Public)?.GetValue(null);
				if (obj != null)
				{
					object obj2 = type.GetField("currentInfo", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(obj);
					if (obj2 != null && ((object)window).GetType().GetField("loadoutButtons", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(window) is Array array)
					{
						for (int i = 0; i < array.Length; i++)
						{
							object? value = array.GetValue(i);
							LoadoutHoverInfo val = (LoadoutHoverInfo)((value is LoadoutHoverInfo) ? value : null);
							if ((Object)(object)val != (Object)null && val == obj2)
							{
								return i;
							}
						}
					}
				}
			}
			catch (Exception)
			{
			}
			try
			{
				Type type2 = AccessTools.TypeByName("UnityEngine.EventSystems.EventSystem");
				object obj3 = type2.GetProperty("current", BindingFlags.Static | BindingFlags.Public)?.GetValue(null);
				if (obj3 != null)
				{
					object? obj4 = type2.GetProperty("currentSelectedGameObject", BindingFlags.Instance | BindingFlags.Public)?.GetValue(obj3);
					GameObject val2 = (GameObject)((obj4 is GameObject) ? obj4 : null);
					if ((Object)(object)val2 != (Object)null)
					{
						LoadoutHoverInfo componentInParent = val2.GetComponentInParent<LoadoutHoverInfo>();
						if ((Object)(object)componentInParent != (Object)null && ((object)window).GetType().GetField("loadoutButtons", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(window) is Array array2)
						{
							for (int j = 0; j < array2.Length; j++)
							{
								if (array2.GetValue(j) == componentInParent)
								{
									return j;
								}
							}
						}
					}
				}
			}
			catch (Exception)
			{
			}
			try
			{
				if (((object)window).GetType().GetField("loadoutButtons", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(window) is Array array3)
				{
					for (int k = 0; k < array3.Length; k++)
					{
						object? value2 = array3.GetValue(k);
						LoadoutHoverInfo val3 = (LoadoutHoverInfo)((value2 is LoadoutHoverInfo) ? value2 : null);
						if ((Object)(object)val3 != (Object)null)
						{
							object? obj5 = ((object)val3).GetType().GetProperty("gameObject")?.GetValue(val3);
							_ = (Object)((obj5 is GameObject) ? obj5 : null) != (Object)null;
						}
					}
				}
			}
			catch (Exception)
			{
			}
		}
		catch (Exception)
		{
		}
		return -1;
	}

	[HarmonyPatch(typeof(LoadoutHoverInfo), "GetTitle")]
	[HarmonyPostfix]
	public static void GetTitlePostfix(ref LoadoutHoverInfo __instance, ref bool __result, out string title, out Color color)
	{
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: 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)
		try
		{
			GearDetailsWindow componentInParent = ((Component)__instance).GetComponentInParent<GearDetailsWindow>();
			if ((Object)(object)componentInParent != (Object)null && ((object)componentInParent).GetType().GetField("loadoutButtons", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(componentInParent) is Array array)
			{
				for (int i = 0; i < array.Length; i++)
				{
					object? value = array.GetValue(i);
					LoadoutHoverInfo val = (LoadoutHoverInfo)((value is LoadoutHoverInfo) ? value : null);
					if ((Object)(object)val != (Object)null && val == __instance)
					{
						string loadoutName = GetLoadoutName(componentInParent, i);
						if (!string.IsNullOrEmpty(loadoutName))
						{
							title = loadoutName + " [L to rename]";
							color = Color.white;
							__result = true;
						}
						else
						{
							title = $"Loadout {i + 1} [L to rename]";
							color = Color.white;
							__result = true;
						}
						return;
					}
				}
			}
			title = TextBlocks.GetString("loadout");
			color = Color.white;
			__result = true;
		}
		catch (Exception)
		{
			title = TextBlocks.GetString("loadout");
			color = Color.white;
			__result = true;
		}
	}

	[HarmonyPatch(typeof(GearDetailsWindow), "Update")]
	[HarmonyPostfix]
	public static void GearDetailsWindowUpdatePostfix(ref GearDetailsWindow __instance)
	{
		//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)
		try
		{
			if (LoadoutRenameDialog.IsActive)
			{
				return;
			}
			Keyboard current = Keyboard.current;
			if (current == null || !((ButtonControl)current.lKey).wasPressedThisFrame)
			{
				return;
			}
			Vector2.op_Implicit(((InputControl<Vector2>)(object)((Pointer)Mouse.current).position).ReadValue());
			if (!(((object)__instance).GetType().GetField("loadoutButtons", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(__instance) is Array array))
			{
				return;
			}
			for (int i = 0; i < array.Length; i++)
			{
				object? value = array.GetValue(i);
				LoadoutHoverInfo val = (LoadoutHoverInfo)((value is LoadoutHoverInfo) ? value : null);
				if ((Object)(object)val != (Object)null && IsHovered(val))
				{
					StartRenameProcess(val, i, __instance);
					return;
				}
			}
			if (array.Length > 0)
			{
				object? value2 = array.GetValue(0);
				LoadoutHoverInfo val2 = (LoadoutHoverInfo)((value2 is LoadoutHoverInfo) ? value2 : null);
				if ((Object)(object)val2 != (Object)null)
				{
					StartRenameProcess(val2, 0, __instance);
				}
			}
		}
		catch (Exception)
		{
		}
	}

	private static bool IsHovered(LoadoutHoverInfo button)
	{
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			Type type = AccessTools.TypeByName("HoverInfoDisplay");
			object obj = type.GetProperty("Instance", BindingFlags.Static | BindingFlags.Public)?.GetValue(null);
			if (obj != null && type.GetField("currentInfo", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(obj) == button)
			{
				return true;
			}
			try
			{
				Camera main = Camera.main;
				if ((Object)(object)main != (Object)null)
				{
					Vector2 val = ((InputControl<Vector2>)(object)((Pointer)Mouse.current).position).ReadValue();
					RaycastHit val2 = default(RaycastHit);
					if (Physics.Raycast(main.ScreenPointToRay(Vector2.op_Implicit(val)), ref val2, float.PositiveInfinity))
					{
						Collider collider = ((RaycastHit)(ref val2)).collider;
						GameObject val3 = ((collider != null) ? ((Component)collider).gameObject : null);
						if ((Object)(object)val3 != (Object)null && (Object)(object)val3.GetComponentInParent<LoadoutHoverInfo>() == (Object)(object)button)
						{
							return true;
						}
					}
					Type type2 = AccessTools.TypeByName("UnityEngine.EventSystems.PointerEventData");
					if (type2 != null)
					{
						object obj2 = Activator.CreateInstance(type2, Object.op_Implicit((Object)(object)EventSystem.current));
						type2.GetField("position")?.SetValue(obj2, val);
						List<RaycastResult> list = new List<RaycastResult>();
						try
						{
							Canvas[] array = Object.FindObjectsOfType<Canvas>();
							foreach (Canvas val4 in array)
							{
								if (!((Object)(object)val4 != (Object)null))
								{
									continue;
								}
								GraphicRaycaster component = ((Component)val4).GetComponent<GraphicRaycaster>();
								if (!((Object)(object)component != (Object)null))
								{
									continue;
								}
								MethodInfo method = ((object)component).GetType().GetMethod("Raycast", BindingFlags.Instance | BindingFlags.Public);
								if (!(method != null))
								{
									continue;
								}
								list.Clear();
								method.Invoke(component, new object[2] { obj2, list });
								foreach (RaycastResult item in list)
								{
									RaycastResult current = item;
									if ((Object)(object)((RaycastResult)(ref current)).gameObject != (Object)null && (Object)(object)((RaycastResult)(ref current)).gameObject.GetComponentInParent<LoadoutHoverInfo>() == (Object)(object)button)
									{
										return true;
									}
								}
							}
						}
						finally
						{
							list.Clear();
						}
					}
				}
			}
			catch (Exception)
			{
			}
			try
			{
				object obj3 = ((object)button).GetType().GetProperty("Active", BindingFlags.Instance | BindingFlags.Public)?.GetValue(button);
				bool flag = default(bool);
				int num;
				if (obj3 is bool)
				{
					flag = (bool)obj3;
					num = 1;
				}
				else
				{
					num = 0;
				}
				if (((uint)num & (flag ? 1u : 0u)) != 0)
				{
					return true;
				}
			}
			catch (Exception)
			{
			}
			return false;
		}
		catch (Exception)
		{
			return false;
		}
	}

	private static void StartRenameProcess(LoadoutHoverInfo button, int loadoutIndex, GearDetailsWindow window)
	{
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			string text = GetLoadoutName(window, loadoutIndex);
			if (string.IsNullOrEmpty(text))
			{
				text = $"Loadout {loadoutIndex + 1}";
			}
			LoadoutRenameDialog.Show(((InputControl<Vector2>)(object)((Pointer)Mouse.current).position).ReadValue(), text, delegate(string newName)
			{
				SetLoadoutName(window, loadoutIndex, newName);
			}, delegate
			{
			}, window, loadoutIndex);
		}
		catch (Exception)
		{
		}
	}

	[HarmonyPatch(typeof(GearData), "SaveLoadout")]
	[HarmonyPostfix]
	public static void SaveLoadoutNamesPostfix(ref GearData __instance, int index)
	{
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Expected O, but got Unknown
		try
		{
			IUpgradable gear = __instance.Gear;
			if (gear == null)
			{
				return;
			}
			Type type = AccessTools.TypeByName("GearDetailsWindow");
			PropertyInfo property = type.GetProperty("Active", BindingFlags.Static | BindingFlags.Public);
			object obj = null;
			if (property != null)
			{
				obj = property.GetValue(null);
			}
			if (obj == null)
			{
				Object[] array = Object.FindObjectsOfType(type);
				if (array.Length != 0)
				{
					obj = array[0];
				}
			}
			if (obj != null && windowLoadoutNames.TryGetValue((GearDetailsWindow)obj, out var value) && value.TryGetValue(index, out var value2))
			{
				string text = $"{gear.Info.ID}_{index}";
				PlayerPrefs.SetString("LoadoutName_" + text, value2);
				PlayerPrefs.Save();
			}
		}
		catch (Exception)
		{
		}
	}
}
[CompilerGenerated]
[ExcludeFromCodeCoverage]
internal static class GitVersionInformation
{
	public const string AssemblySemFileVer = "0.0.1.0";

	public const string AssemblySemVer = "0.0.1.0";

	public const string BranchName = "master";

	public const string BuildMetaData = "";

	public const string CommitDate = "2025-10-17";

	public const string CommitsSinceVersionSource = "1";

	public const string EscapedBranchName = "master";

	public const string FullBuildMetaData = "Branch.master.Sha.da7f22f1fead07f520355976d6c527e064e5416c";

	public const string FullSemVer = "0.0.1-1";

	public const string InformationalVersion = "0.0.1-1+Branch.master.Sha.da7f22f1fead07f520355976d6c527e064e5416c";

	public const string Major = "0";

	public const string MajorMinorPatch = "0.0.1";

	public const string Minor = "0";

	public const string Patch = "1";

	public const string PreReleaseLabel = "";

	public const string PreReleaseLabelWithDash = "";

	public const string PreReleaseNumber = "1";

	public const string PreReleaseTag = "1";

	public const string PreReleaseTagWithDash = "-1";

	public const string SemVer = "0.0.1-1";

	public const string Sha = "da7f22f1fead07f520355976d6c527e064e5416c";

	public const string ShortSha = "da7f22f";

	public const string UncommittedChanges = "16";

	public const string VersionSourceSha = "";

	public const string WeightedPreReleaseNumber = "55001";
}
namespace ImprovedLoadouts
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ImprovedLoadouts";

		public const string PLUGIN_NAME = "ImprovedLoadouts";

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