Decompiled source of ImprovedUpgradeSorting v1.0.0

BepInEx/plugins/ImprovedUpgradeSorting.dll

Decompiled 11 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
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.Events;
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("ImprovedUpgradeSorting")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.0.0.0")]
[assembly: AssemblyInformationalVersion("0.0.0-alpha.0+92ac4b54073465d8a743dc0036c462b328b0b367")]
[assembly: AssemblyProduct("ImprovedUpgradeSorting")]
[assembly: AssemblyTitle("ImprovedUpgradeSorting")]
[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;
		}
	}
}
[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.92ac4b54073465d8a743dc0036c462b328b0b367";

	public const string FullSemVer = "0.0.1-1";

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

	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 = "92ac4b54073465d8a743dc0036c462b328b0b367";

	public const string ShortSha = "92ac4b5";

	public const string UncommittedChanges = "16";

	public const string VersionSourceSha = "";

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

		public const string PLUGIN_NAME = "ImprovedUpgradeSorting";

		public const string PLUGIN_VERSION = "0.0.0";
	}
}
namespace MycopunkUpgradeSorting
{
	public class FilterPanelUI
	{
		private GameObject filterPanel;

		private bool isExpanded;

		private bool isInitialized;

		public bool IsExpanded => isExpanded;

		private void CreateFilterPanel()
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_0087: 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_00ab: Expected O, but got Unknown
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			if (isInitialized)
			{
				return;
			}
			GameObject val = GameObject.Find("Gear Details/UpgradeList");
			Transform val2 = null;
			if ((Object)(object)val != (Object)null)
			{
				val2 = val.transform;
			}
			else
			{
				GameObject val3 = GameObject.Find("Gear Details");
				if (!((Object)(object)val3 != (Object)null))
				{
					return;
				}
				val2 = val3.transform;
			}
			filterPanel = new GameObject("UpgradeFilterPanel");
			filterPanel.transform.SetParent(val2, false);
			((Graphic)filterPanel.AddComponent<Image>()).color = new Color(0.1f, 0.1f, 0.1f, 0.9f);
			VerticalLayoutGroup obj = filterPanel.AddComponent<VerticalLayoutGroup>();
			((LayoutGroup)obj).padding = new RectOffset(5, 5, 5, 5);
			((HorizontalOrVerticalLayoutGroup)obj).spacing = 3f;
			((LayoutGroup)obj).childAlignment = (TextAnchor)0;
			((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = false;
			((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = false;
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false;
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = false;
			RectTransform component = filterPanel.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 1f);
			component.anchorMax = new Vector2(0f, 1f);
			component.pivot = new Vector2(0f, 1f);
			component.sizeDelta = new Vector2(200f, 300f);
			component.anchoredPosition = new Vector2(-200f, -80f);
			if (!((Object)(object)filterPanel == (Object)null) && !((Object)(object)filterPanel.transform == (Object)null))
			{
				try
				{
					CreateClearAllFiltersButton();
					CreateRarityFilter();
					CreateFavoriteFilter();
					CreateStatFilters();
				}
				catch (Exception)
				{
					return;
				}
				filterPanel.SetActive(false);
				isInitialized = true;
			}
		}

		private void CreateRarityFilter()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			CreateUITextObject("RarityFilterLabel", "Hide Rarities:", 12f, filterPanel.transform).GetComponent<RectTransform>().sizeDelta = new Vector2(180f, 20f);
			var obj = new[]
			{
				new
				{
					Name = "Standard",
					Rarity = (Rarity)0
				},
				new
				{
					Name = "Rare",
					Rarity = (Rarity)1
				},
				new
				{
					Name = "Epic",
					Rarity = (Rarity)2
				},
				new
				{
					Name = "Exotic",
					Rarity = (Rarity)3
				},
				new
				{
					Name = "Oddity",
					Rarity = (Rarity)4
				}
			};
			UpgradeSortingPlugin.CurrentFilters.HiddenRarities.Clear();
			var array = obj;
			foreach (var anon in array)
			{
				CreateRarityToggleButton(anon.Name, anon.Rarity);
			}
			FixRarityButtonTextPosition();
		}

		private GameObject CreateRarityToggleButton(string text, Rarity rarity)
		{
			//IL_0007: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Expected O, but got Unknown
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Expected O, but got Unknown
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)filterPanel == (Object)null)
				{
					return null;
				}
				GameObject val = new GameObject("FilterButton_" + text.Replace(" ", "_"));
				if ((Object)(object)val == (Object)null)
				{
					return null;
				}
				val.AddComponent<RectTransform>();
				val.transform.SetParent(filterPanel.transform, false);
				Image buttonImage = val.AddComponent<Image>();
				((Graphic)buttonImage).color = new Color(0.3f, 0.3f, 0.3f, 1f);
				Button val2 = val.AddComponent<Button>();
				if ((Object)(object)val2 == (Object)null)
				{
					return null;
				}
				GameObject val3 = new GameObject("Text");
				if ((Object)(object)val3 == (Object)null)
				{
					return null;
				}
				val3.transform.SetParent(val.transform, false);
				TextMeshProUGUI obj = val3.AddComponent<TextMeshProUGUI>();
				((TMP_Text)obj).text = text;
				((TMP_Text)obj).fontSize = 10f;
				((Graphic)obj).color = Color.white;
				((UnityEventBase)val2.onClick).RemoveAllListeners();
				((UnityEvent)val2.onClick).AddListener((UnityAction)delegate
				{
					//IL_000b: Unknown result type (might be due to invalid IL or missing references)
					//IL_005e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0082: Unknown result type (might be due to invalid IL or missing references)
					//IL_0022: 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)
					if (UpgradeSortingPlugin.CurrentFilters.HiddenRarities.Contains(rarity))
					{
						UpgradeSortingPlugin.CurrentFilters.HiddenRarities.Remove(rarity);
						((Graphic)buttonImage).color = new Color(0.3f, 0.3f, 0.3f, 1f);
					}
					else
					{
						UpgradeSortingPlugin.CurrentFilters.HiddenRarities.Add(rarity);
						((Graphic)buttonImage).color = new Color(0.6f, 0.3f, 0.3f, 1f);
					}
					RefreshUpgrades();
				});
				RectTransform component = val.GetComponent<RectTransform>();
				if ((Object)(object)component == (Object)null)
				{
					return null;
				}
				component.sizeDelta = new Vector2(170f, 20f);
				return val;
			}
			catch (Exception)
			{
				return null;
			}
		}

		private void CreateFavoriteFilter()
		{
			//IL_003c: 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_0073: Expected O, but got Unknown
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Expected O, but got Unknown
			CreateUITextObject("FavoriteFilterLabel", "Favorites:", 12f, filterPanel.transform).GetComponent<RectTransform>().sizeDelta = new Vector2(180f, 20f);
			GameObject showAllBtn = null;
			GameObject onlyFavBtn = null;
			GameObject hideFavBtn = null;
			showAllBtn = CreateFilterButton("Show All", (UnityAction)delegate
			{
				UpgradeSortingPlugin.CurrentFilters.FavoriteSetting = FavoriteFilter.ShowAll;
				UpdateFavoriteButtonHighlights(showAllBtn, onlyFavBtn, hideFavBtn, FavoriteFilter.ShowAll);
				RefreshUpgrades();
			});
			onlyFavBtn = CreateFilterButton("Only Favorite", (UnityAction)delegate
			{
				UpgradeSortingPlugin.CurrentFilters.FavoriteSetting = FavoriteFilter.ShowOnlyFavorited;
				UpdateFavoriteButtonHighlights(showAllBtn, onlyFavBtn, hideFavBtn, FavoriteFilter.ShowOnlyFavorited);
				RefreshUpgrades();
			});
			hideFavBtn = CreateFilterButton("Hide Favorite", (UnityAction)delegate
			{
				UpgradeSortingPlugin.CurrentFilters.FavoriteSetting = FavoriteFilter.HideFavorited;
				UpdateFavoriteButtonHighlights(showAllBtn, onlyFavBtn, hideFavBtn, FavoriteFilter.HideFavorited);
				RefreshUpgrades();
			});
			if ((Object)(object)showAllBtn != (Object)null)
			{
				((Selectable)showAllBtn.GetComponent<Button>()).interactable = true;
			}
			if ((Object)(object)onlyFavBtn != (Object)null)
			{
				((Selectable)onlyFavBtn.GetComponent<Button>()).interactable = true;
			}
			if ((Object)(object)hideFavBtn != (Object)null)
			{
				((Selectable)hideFavBtn.GetComponent<Button>()).interactable = true;
			}
			UpdateFavoriteButtonHighlights(showAllBtn, onlyFavBtn, hideFavBtn, FavoriteFilter.ShowAll);
			FixFavoriteButtonTextPosition(showAllBtn);
			FixFavoriteButtonTextPosition(onlyFavBtn);
			FixFavoriteButtonTextPosition(hideFavBtn);
		}

		private void UpdateFavoriteButtonHighlights(GameObject showAllBtn, GameObject onlyFavBtn, GameObject hideFavBtn, FavoriteFilter selectedFilter)
		{
			//IL_0054: 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_007e: 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)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)filterPanel == (Object)null)
			{
				return;
			}
			Color color = default(Color);
			((Color)(ref color))..ctor(0.3f, 0.3f, 0.3f, 1f);
			Color color2 = default(Color);
			((Color)(ref color2))..ctor(0.5f, 0.7f, 0.5f, 1f);
			if ((Object)(object)showAllBtn != (Object)null)
			{
				((Graphic)showAllBtn.GetComponent<Image>()).color = color;
			}
			if ((Object)(object)onlyFavBtn != (Object)null)
			{
				((Graphic)onlyFavBtn.GetComponent<Image>()).color = color;
			}
			if ((Object)(object)hideFavBtn != (Object)null)
			{
				((Graphic)hideFavBtn.GetComponent<Image>()).color = color;
			}
			switch (selectedFilter)
			{
			case FavoriteFilter.ShowAll:
				if ((Object)(object)showAllBtn != (Object)null)
				{
					((Graphic)showAllBtn.GetComponent<Image>()).color = color2;
				}
				break;
			case FavoriteFilter.ShowOnlyFavorited:
				if ((Object)(object)onlyFavBtn != (Object)null)
				{
					((Graphic)onlyFavBtn.GetComponent<Image>()).color = color2;
				}
				break;
			case FavoriteFilter.HideFavorited:
				if ((Object)(object)hideFavBtn != (Object)null)
				{
					((Graphic)hideFavBtn.GetComponent<Image>()).color = color2;
				}
				break;
			}
		}

		private void CreateStatFilters()
		{
			//IL_002f: 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_0044: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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_00dd: Expected O, but got Unknown
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Expected O, but got Unknown
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Expected O, but got Unknown
			//IL_0360: Unknown result type (might be due to invalid IL or missing references)
			CreateUITextObject("StatFilterLabel", "Show Only Upgrades With:", 12f, filterPanel.transform).GetComponent<RectTransform>().sizeDelta = new Vector2(180f, 20f);
			GameObject val = new GameObject("StatPropertyScrollView");
			val.transform.SetParent(filterPanel.transform, false);
			ScrollRect obj = val.AddComponent<ScrollRect>();
			RectTransform component = val.GetComponent<RectTransform>();
			component.sizeDelta = new Vector2(180f, 120f);
			GameObject val2 = new GameObject("Viewport");
			val2.transform.SetParent(val.transform, false);
			((Graphic)val2.AddComponent<Image>()).color = new Color(0.2f, 0.2f, 0.2f, 0.8f);
			RectTransform component2 = val2.GetComponent<RectTransform>();
			component2.sizeDelta = component.sizeDelta;
			GameObject val3 = new GameObject("Content");
			val3.transform.SetParent(val2.transform, false);
			VerticalLayoutGroup obj2 = val3.AddComponent<VerticalLayoutGroup>();
			((LayoutGroup)obj2).padding = new RectOffset(2, 2, 2, 2);
			((HorizontalOrVerticalLayoutGroup)obj2).spacing = 2f;
			((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = false;
			((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = false;
			((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = false;
			((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = false;
			RectTransform component3 = val3.GetComponent<RectTransform>();
			component3.anchorMin = new Vector2(0f, 1f);
			component3.anchorMax = new Vector2(0f, 1f);
			component3.pivot = new Vector2(0f, 1f);
			component3.sizeDelta = new Vector2(component.sizeDelta.x - 4f, 0f);
			ContentSizeFitter obj3 = val3.AddComponent<ContentSizeFitter>();
			obj3.horizontalFit = (FitMode)0;
			obj3.verticalFit = (FitMode)2;
			val2.AddComponent<Mask>().showMaskGraphic = false;
			obj.viewport = component2;
			obj.content = component3;
			obj.horizontal = false;
			obj.vertical = true;
			obj.scrollSensitivity = 1f;
			obj.elasticity = 0.01f;
			obj.inertia = false;
			obj.decelerationRate = 0.01f;
			List<string> contextAwareProperties = GetContextAwareProperties();
			List<GameObject> list = new List<GameObject>();
			foreach (Transform item in val3.transform)
			{
				Transform val4 = item;
				if (((Object)((Component)val4).gameObject).name.StartsWith("StatToggle_") || ((Object)((Component)val4).gameObject).name == "Toggle")
				{
					list.Add(((Component)val4).gameObject);
				}
			}
			foreach (GameObject item2 in list)
			{
				Object.DestroyImmediate((Object)(object)item2);
			}
			foreach (string propertyName in contextAwareProperties.OrderBy((string p) => p))
			{
				string text = propertyName.Replace("_", " ");
				CreateUIToggleObject("StatToggle_" + propertyName, text, 8f, val3.transform, delegate(bool value)
				{
					if (value)
					{
						UpgradeSortingPlugin.CurrentFilters.FilterStats = true;
						if (!UpgradeSortingPlugin.CurrentFilters.StatIncludeList.Contains(propertyName))
						{
							UpgradeSortingPlugin.CurrentFilters.StatIncludeList.Add(propertyName);
						}
					}
					else
					{
						UpgradeSortingPlugin.CurrentFilters.StatIncludeList.Remove(propertyName);
						if (UpgradeSortingPlugin.CurrentFilters.StatIncludeList.Count == 0)
						{
							UpgradeSortingPlugin.CurrentFilters.FilterStats = false;
						}
					}
					RefreshUpgrades();
				}).GetComponent<RectTransform>().sizeDelta = new Vector2(170f, 16f);
			}
		}

		private List<string> GetContextAwareProperties()
		{
			try
			{
				GameObject obj = GameObject.Find("Gear Details");
				GearDetailsWindow val = ((obj != null) ? obj.GetComponent<GearDetailsWindow>() : null);
				bool flag = false;
				if ((Object)(object)val != (Object)null)
				{
					FieldInfo fieldInfo = AccessTools.Field(typeof(GearDetailsWindow), "inSkinMode");
					if (fieldInfo != null)
					{
						try
						{
							flag = (bool)fieldInfo.GetValue(val);
						}
						catch (Exception)
						{
						}
					}
				}
				if (flag)
				{
					return DiscoverSkinProperties();
				}
				return GetCuratedUpgradeProperties();
			}
			catch (Exception)
			{
				return GetCuratedUpgradeProperties();
			}
		}

		private List<string> GetCuratedUpgradeProperties()
		{
			return new List<string>
			{
				"AmmoCapacity", "AutomaticFire", "BatteryCapacity", "BulletsPerShot", "BurstFire", "Carver_Blood", "Charge", "Damage", "FireInterval", "Globbler_Globblometer",
				"Health", "HealthRegenDelay", "HitForce", "MagazineSize", "MaxBounces", "MeleeDamage", "Range", "Recoil", "Reload", "Speed"
			};
		}

		private List<string> DiscoverSkinProperties()
		{
			List<string> list = new List<string>();
			try
			{
				Type skinUpgradePropertyType = typeof(GearUpgradeUI).Assembly.GetType("SkinUpgradeProperty");
				if (skinUpgradePropertyType == null)
				{
					return list;
				}
				foreach (Type item in (from t in skinUpgradePropertyType.Assembly.GetTypes()
					where t.IsClass && !t.IsAbstract && skinUpgradePropertyType.IsAssignableFrom(t) && t.FullName != null && t.FullName.StartsWith("SkinUpgradeProperty_")
					select t).ToList())
				{
					string text = item.Name;
					if (text.StartsWith("SkinUpgradeProperty_"))
					{
						text = text.Substring("SkinUpgradeProperty_".Length);
					}
					list.Add(text);
				}
				list = (from p in list.Distinct()
					orderby p
					select p).ToList();
				return list;
			}
			catch (Exception)
			{
				return list;
			}
		}

		private List<string> DiscoverUpgradeProperties()
		{
			List<string> list = new List<string>();
			try
			{
				Type upgradePropertyType = typeof(GearUpgradeUI).Assembly.GetType("UpgradeProperty");
				if (upgradePropertyType == null)
				{
					return GetFallbackProperties();
				}
				Type skinUpgradePropertyType = typeof(GearUpgradeUI).Assembly.GetType("SkinUpgradeProperty");
				List<Type> list2 = (from t in upgradePropertyType.Assembly.GetTypes()
					where t.IsClass && !t.IsAbstract && (t == upgradePropertyType || upgradePropertyType.IsAssignableFrom(t)) && t.FullName != null && t.FullName.StartsWith("UpgradeProperty_")
					select t).ToList();
				if (skinUpgradePropertyType != null)
				{
					list2 = list2.Where((Type t) => !skinUpgradePropertyType.IsAssignableFrom(t)).ToList();
				}
				foreach (Type item in list2)
				{
					string text = item.Name;
					if (text.StartsWith("UpgradeProperty_"))
					{
						text = text.Substring("UpgradeProperty_".Length);
					}
					list.Add(text);
				}
				list = (from p in list.Distinct()
					orderby p
					select p).ToList();
				if (list.Count == 0)
				{
					return GetFallbackProperties();
				}
				return list;
			}
			catch (Exception)
			{
				return GetFallbackProperties();
			}
		}

		private List<string> GetFallbackProperties()
		{
			return new List<string>
			{
				"Damage", "AmmoCapacity", "FireInterval", "AutomaticFire", "BurstFire", "BulletsPerShot", "Aim", "AmmoOnFire", "Recoil", "Reload",
				"Range", "Health", "Speed"
			};
		}

		private GameObject CreateFilterButton(string text, UnityAction action)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)filterPanel == (Object)null)
				{
					return null;
				}
				GameObject val = new GameObject("FilterButton_" + text.Replace(" ", "_"));
				if ((Object)(object)val == (Object)null)
				{
					return null;
				}
				val.AddComponent<RectTransform>();
				val.transform.SetParent(filterPanel.transform, false);
				((Graphic)val.AddComponent<Image>()).color = new Color(0.3f, 0.3f, 0.3f, 1f);
				Button val2 = val.AddComponent<Button>();
				if ((Object)(object)val2 == (Object)null)
				{
					return null;
				}
				GameObject val3 = new GameObject("Text");
				if ((Object)(object)val3 == (Object)null)
				{
					return null;
				}
				val3.transform.SetParent(val.transform, false);
				TextMeshProUGUI obj = val3.AddComponent<TextMeshProUGUI>();
				((TMP_Text)obj).text = text;
				((TMP_Text)obj).fontSize = 10f;
				((Graphic)obj).color = Color.white;
				((UnityEvent)val2.onClick).AddListener(action);
				RectTransform component = val.GetComponent<RectTransform>();
				if ((Object)(object)component == (Object)null)
				{
					return null;
				}
				component.sizeDelta = new Vector2(170f, 20f);
				return val;
			}
			catch (Exception)
			{
				return null;
			}
		}

		private void RefreshUpgrades()
		{
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: 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_01f0: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = GameObject.Find("Gear Details");
			GearDetailsWindow val = ((obj != null) ? obj.GetComponent<GearDetailsWindow>() : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			try
			{
				FieldInfo fieldInfo = AccessTools.Field(typeof(GearDetailsWindow), "inSkinMode");
				bool flag = false;
				if (fieldInfo != null)
				{
					flag = (bool)fieldInfo.GetValue(val);
				}
				FieldInfo fieldInfo2 = (flag ? AccessTools.Field(typeof(GearDetailsWindow), "currentSortingMethodSkins") : AccessTools.Field(typeof(GearDetailsWindow), "currentSortingMethodUpgrades"));
				SortingMethod val2 = (SortingMethod)0;
				if (fieldInfo2 != null)
				{
					try
					{
						val2 = (SortingMethod)fieldInfo2.GetValue(val);
					}
					catch (Exception)
					{
					}
				}
				FieldInfo fieldInfo3 = AccessTools.Field(typeof(GearDetailsWindow), "upgradeUIs") ?? AccessTools.Field(typeof(GearDetailsWindow), "<upgradeUIs>k__BackingField") ?? AccessTools.Field(typeof(GearDetailsWindow), "upgrades");
				if (fieldInfo3 != null)
				{
					List<GearUpgradeUI> list = (List<GearUpgradeUI>)fieldInfo3.GetValue(val);
					if (list != null)
					{
						int num = 0;
						foreach (GearUpgradeUI item in list)
						{
							bool flag2 = true;
							if (UpgradeSortingPlugin.CurrentFilters.HiddenRarities.Any())
							{
								flag2 &= !UpgradeSortingPlugin.CurrentFilters.HiddenRarities.Contains(((HoverInfoUpgrade)item).Upgrade.Upgrade.Rarity);
							}
							switch (UpgradeSortingPlugin.CurrentFilters.FavoriteSetting)
							{
							case FavoriteFilter.ShowOnlyFavorited:
								flag2 &= ((HoverInfoUpgrade)item).Upgrade.Favorite;
								break;
							case FavoriteFilter.HideFavorited:
								flag2 &= !((HoverInfoUpgrade)item).Upgrade.Favorite;
								break;
							}
							if (UpgradeSortingPlugin.CurrentFilters.FilterStats && UpgradeSortingPlugin.CurrentFilters.StatIncludeList.Any())
							{
								bool flag3 = true;
								foreach (string statInclude in UpgradeSortingPlugin.CurrentFilters.StatIncludeList)
								{
									bool flag4 = false;
									Enumerator properties = ((HoverInfoUpgrade)item).Upgrade.Upgrade.GetProperties();
									while (((Enumerator)(ref properties)).MoveNext())
									{
										string text = ((object)((Enumerator)(ref properties)).Current).GetType().Name;
										if (text.StartsWith("UpgradeProperty_"))
										{
											text = text.Substring("UpgradeProperty_".Length);
										}
										if (text == statInclude)
										{
											flag4 = true;
											break;
										}
									}
									if (!flag4)
									{
										flag3 = false;
										break;
									}
								}
								flag2 = flag2 && flag3;
							}
							((Component)item).gameObject.SetActive(flag2);
							if (flag2)
							{
								num++;
								((Component)item).transform.SetSiblingIndex(num - 1);
							}
						}
						FieldInfo fieldInfo4 = AccessTools.Field(typeof(GearDetailsWindow), "upgradeUICount");
						if (fieldInfo4 != null)
						{
							fieldInfo4.SetValue(val, num);
						}
					}
				}
				AccessTools.Method(typeof(GearDetailsWindow), "SortUpgrades", new Type[2]
				{
					typeof(SortingMethod),
					typeof(bool)
				}, (Type[])null)?.Invoke(val, new object[2] { val2, false });
				try
				{
					AccessTools.Method(typeof(GearDetailsWindow), "SwitchUpgradeView", (Type[])null, (Type[])null)?.Invoke(val, new object[0]);
					AccessTools.Method(typeof(GearDetailsWindow), "SwitchUpgradeView", (Type[])null, (Type[])null)?.Invoke(val, new object[0]);
				}
				catch (Exception)
				{
				}
			}
			catch (Exception)
			{
			}
		}

		public void Toggle()
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			if (!isInitialized)
			{
				CreateFilterPanel();
				if (!isInitialized)
				{
					return;
				}
			}
			isExpanded = !isExpanded;
			if (isExpanded)
			{
				RegenerateStatFilters();
			}
			filterPanel.SetActive(isExpanded);
			filterPanel.GetComponent<RectTransform>().anchoredPosition = (isExpanded ? new Vector2(-190f, -80f) : new Vector2(-200f, -80f));
		}

		public void RegenerateStatFilters()
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Expected O, but got Unknown
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)filterPanel == (Object)null || !isInitialized)
				{
					return;
				}
				Transform val = filterPanel.transform.Find("StatPropertyScrollView/Content");
				if (!((Object)(object)val != (Object)null))
				{
					return;
				}
				GameObject gameObject = ((Component)val).gameObject;
				List<GameObject> list = new List<GameObject>();
				foreach (Transform item in gameObject.transform)
				{
					Transform val2 = item;
					if (((Object)((Component)val2).gameObject).name.StartsWith("StatToggle_") || ((Object)((Component)val2).gameObject).name == "Toggle")
					{
						list.Add(((Component)val2).gameObject);
					}
				}
				foreach (GameObject item2 in list)
				{
					Object.DestroyImmediate((Object)(object)item2);
				}
				UpgradeSortingPlugin.CurrentFilters.StatIncludeList.Clear();
				UpgradeSortingPlugin.CurrentFilters.FilterStats = false;
				foreach (string propertyName in from p in GetContextAwareProperties()
					orderby p
					select p)
				{
					string text = propertyName.Replace("_", " ");
					CreateUIToggleObject("StatToggle_" + propertyName, text, 8f, gameObject.transform, delegate(bool value)
					{
						if (value)
						{
							UpgradeSortingPlugin.CurrentFilters.FilterStats = true;
							if (!UpgradeSortingPlugin.CurrentFilters.StatIncludeList.Contains(propertyName))
							{
								UpgradeSortingPlugin.CurrentFilters.StatIncludeList.Add(propertyName);
							}
						}
						else
						{
							UpgradeSortingPlugin.CurrentFilters.StatIncludeList.Remove(propertyName);
							if (UpgradeSortingPlugin.CurrentFilters.StatIncludeList.Count == 0)
							{
								UpgradeSortingPlugin.CurrentFilters.FilterStats = false;
							}
						}
						RefreshUpgrades();
					}).GetComponent<RectTransform>().sizeDelta = new Vector2(170f, 16f);
				}
			}
			catch (Exception)
			{
			}
		}

		public void RebuildFilterPanel()
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				bool num = isExpanded && (Object)(object)filterPanel != (Object)null && filterPanel.activeSelf;
				if ((Object)(object)filterPanel != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)filterPanel);
				}
				isInitialized = false;
				isExpanded = false;
				CreateFilterPanel();
				if (num)
				{
					filterPanel.SetActive(true);
					filterPanel.GetComponent<RectTransform>().anchoredPosition = new Vector2(10f, -80f);
				}
			}
			catch (Exception)
			{
			}
		}

		private GameObject CreateUITextObject(string objName, string text, float fontSize, Transform parent)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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)
			//IL_0033: Expected O, but got Unknown
			GameObject val = new GameObject(objName);
			val.transform.SetParent(parent, false);
			TextMeshProUGUI obj = val.AddComponent<TextMeshProUGUI>();
			((TMP_Text)obj).text = text;
			((TMP_Text)obj).fontSize = fontSize;
			((Graphic)obj).color = Color.white;
			return val;
		}

		private GameObject CreateUIToggleObject(string objName, string text, float fontSize, Transform parent, UnityAction<bool> onValueChanged)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: 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)
			GameObject val = new GameObject(objName);
			val.transform.SetParent(parent, false);
			Toggle val2 = val.AddComponent<Toggle>();
			((UnityEvent<bool>)(object)val2.onValueChanged).AddListener(onValueChanged);
			((Graphic)val.AddComponent<Image>()).color = new Color(0.4f, 0.4f, 0.4f, 1f);
			GameObject val3 = new GameObject("Text");
			val3.transform.SetParent(val.transform, false);
			TextMeshProUGUI obj = val3.AddComponent<TextMeshProUGUI>();
			((TMP_Text)obj).text = text;
			((TMP_Text)obj).fontSize = fontSize;
			((Graphic)obj).color = Color.white;
			((TMP_Text)obj).alignment = (TextAlignmentOptions)513;
			GameObject val4 = new GameObject("Checkmark");
			val4.transform.SetParent(val.transform, false);
			Image val5 = val4.AddComponent<Image>();
			((Graphic)val5).color = Color.green;
			val2.graphic = (Graphic)(object)val5;
			RectTransform component = ((Component)obj).GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0.3f, 0.1f);
			component.anchorMax = new Vector2(1f, 0.9f);
			component.offsetMin = Vector2.zero;
			component.offsetMax = Vector2.zero;
			RectTransform component2 = ((Component)val5).GetComponent<RectTransform>();
			component2.anchorMin = new Vector2(0.05f, 0.2f);
			component2.anchorMax = new Vector2(0.25f, 0.8f);
			component2.offsetMin = Vector2.zero;
			component2.offsetMax = Vector2.zero;
			return val;
		}

		private void FixFavoriteButtonTextPosition(GameObject buttonGo)
		{
			//IL_0029: 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_0053: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!((Object)(object)buttonGo == (Object)null))
				{
					TextMeshProUGUI[] componentsInChildren = buttonGo.GetComponentsInChildren<TextMeshProUGUI>();
					if (componentsInChildren.Length != 0)
					{
						RectTransform component = ((Component)componentsInChildren[0]).GetComponent<RectTransform>();
						component.anchorMin = new Vector2(0f, 0f);
						component.anchorMax = new Vector2(1f, 1f);
						component.offsetMin = new Vector2(5f, 2f);
						component.offsetMax = new Vector2(-5f, -2f);
						((Transform)component).localPosition = Vector3.zero;
					}
				}
			}
			catch (Exception)
			{
			}
		}

		private void CreateClearAllFiltersButton()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_00c5: 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_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Expected O, but got Unknown
			try
			{
				if ((Object)(object)filterPanel == (Object)null)
				{
					return;
				}
				GameObject val = new GameObject("ClearAllFiltersButton");
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				val.transform.SetParent(filterPanel.transform, false);
				((Graphic)val.AddComponent<Image>()).color = new Color(0.8f, 0.4f, 0.4f, 1f);
				Button val2 = val.AddComponent<Button>();
				if ((Object)(object)val2 == (Object)null)
				{
					return;
				}
				GameObject val3 = new GameObject("Text");
				if ((Object)(object)val3 == (Object)null)
				{
					return;
				}
				val3.transform.SetParent(val.transform, false);
				TextMeshProUGUI val4 = val3.AddComponent<TextMeshProUGUI>();
				((TMP_Text)val4).text = "Clear All Filters";
				((TMP_Text)val4).fontSize = 12f;
				((Graphic)val4).color = Color.white;
				((TMP_Text)val4).alignment = (TextAlignmentOptions)514;
				RectTransform component = val.GetComponent<RectTransform>();
				if ((Object)(object)component == (Object)null)
				{
					return;
				}
				component.sizeDelta = new Vector2(180f, 30f);
				RectTransform component2 = ((Component)val4).GetComponent<RectTransform>();
				component2.anchorMin = Vector2.zero;
				component2.anchorMax = Vector2.one;
				component2.offsetMin = new Vector2(5f, 2f);
				component2.offsetMax = new Vector2(-5f, -2f);
				((UnityEventBase)val2.onClick).RemoveAllListeners();
				((UnityEvent)val2.onClick).AddListener((UnityAction)delegate
				{
					//IL_005e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0064: Expected O, but got Unknown
					//IL_010a: Unknown result type (might be due to invalid IL or missing references)
					//IL_0111: Expected O, but got Unknown
					//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
					//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
					//IL_022a: 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)
					UpgradeSortingPlugin.CurrentFilters.HiddenRarities.Clear();
					UpgradeSortingPlugin.CurrentFilters.FavoriteSetting = FavoriteFilter.ShowAll;
					UpgradeSortingPlugin.CurrentFilters.FilterStats = false;
					UpgradeSortingPlugin.CurrentFilters.StatIncludeList.Clear();
					if ((Object)(object)filterPanel != (Object)null)
					{
						foreach (Transform item in filterPanel.transform)
						{
							Transform val5 = item;
							if (((Object)val5).name.StartsWith("FilterButton_"))
							{
								Image component3 = ((Component)val5).GetComponent<Image>();
								if ((Object)(object)component3 != (Object)null)
								{
									TextMeshProUGUI componentInChildren = ((Component)val5).GetComponentInChildren<TextMeshProUGUI>();
									if (((componentInChildren != null) ? ((TMP_Text)componentInChildren).text : null) != null)
									{
										((Graphic)component3).color = new Color(0.3f, 0.3f, 0.3f, 1f);
									}
								}
							}
						}
					}
					if ((Object)(object)filterPanel != (Object)null)
					{
						GameObject val6 = null;
						GameObject val7 = null;
						GameObject val8 = null;
						foreach (Transform item2 in filterPanel.transform)
						{
							Transform val9 = item2;
							if (((Object)val9).name.StartsWith("FilterButton_"))
							{
								TextMeshProUGUI componentInChildren2 = ((Component)val9).GetComponentInChildren<TextMeshProUGUI>();
								if ((Object)(object)componentInChildren2 != (Object)null)
								{
									switch (((TMP_Text)componentInChildren2).text)
									{
									case "Show All":
										val6 = ((Component)val9).gameObject;
										break;
									case "Only Favorite":
										val7 = ((Component)val9).gameObject;
										break;
									case "Hide Favorite":
										val8 = ((Component)val9).gameObject;
										break;
									}
								}
							}
						}
						if ((Object)(object)val6 != (Object)null)
						{
							((Graphic)val6.GetComponent<Image>()).color = new Color(0.5f, 0.7f, 0.5f, 1f);
						}
						if ((Object)(object)val7 != (Object)null)
						{
							((Graphic)val7.GetComponent<Image>()).color = new Color(0.3f, 0.3f, 0.3f, 1f);
						}
						if ((Object)(object)val8 != (Object)null)
						{
							((Graphic)val8.GetComponent<Image>()).color = new Color(0.3f, 0.3f, 0.3f, 1f);
						}
					}
					RefreshUpgrades();
					RegenerateStatFilters();
				});
				val.SetActive(true);
				((Selectable)val2).interactable = true;
			}
			catch (Exception)
			{
			}
		}

		private void FixRarityButtonTextPosition()
		{
			//IL_0060: 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_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				foreach (Button item in filterPanel.GetComponentsInChildren<Button>().Where(delegate(Button b)
				{
					if (((Object)b).name.StartsWith("FilterButton_"))
					{
						TextMeshProUGUI componentInChildren = ((Component)b).GetComponentInChildren<TextMeshProUGUI>();
						if (componentInChildren == null || !((TMP_Text)componentInChildren).text.Contains("Standard"))
						{
							TextMeshProUGUI componentInChildren2 = ((Component)b).GetComponentInChildren<TextMeshProUGUI>();
							if (componentInChildren2 == null || !((TMP_Text)componentInChildren2).text.Contains("Rare"))
							{
								TextMeshProUGUI componentInChildren3 = ((Component)b).GetComponentInChildren<TextMeshProUGUI>();
								if (componentInChildren3 == null || !((TMP_Text)componentInChildren3).text.Contains("Epic"))
								{
									TextMeshProUGUI componentInChildren4 = ((Component)b).GetComponentInChildren<TextMeshProUGUI>();
									if (componentInChildren4 == null || !((TMP_Text)componentInChildren4).text.Contains("Exotic"))
									{
										TextMeshProUGUI componentInChildren5 = ((Component)b).GetComponentInChildren<TextMeshProUGUI>();
										if (componentInChildren5 == null)
										{
											return false;
										}
										return ((TMP_Text)componentInChildren5).text.Contains("Oddity");
									}
								}
							}
						}
						return true;
					}
					return false;
				}).ToList())
				{
					TextMeshProUGUI[] componentsInChildren = ((Component)item).GetComponentsInChildren<TextMeshProUGUI>();
					if (componentsInChildren.Length != 0)
					{
						RectTransform component = ((Component)componentsInChildren[0]).GetComponent<RectTransform>();
						component.anchorMin = new Vector2(0f, 0f);
						component.anchorMax = new Vector2(1f, 1f);
						component.offsetMin = new Vector2(5f, 2f);
						component.offsetMax = new Vector2(-5f, -2f);
						((Transform)component).localPosition = Vector3.zero;
					}
				}
			}
			catch (Exception)
			{
			}
		}
	}
	public enum CustomSortingMethod
	{
		Name,
		Rarity,
		DamageType,
		RecentlyCollected,
		RecentlyUnequipped,
		Stat,
		Favorite,
		Modifier
	}
	public struct FilterSettings
	{
		public List<Rarity> HiddenRarities;

		public bool FilterStats;

		public List<string> StatIncludeList;

		public FavoriteFilter FavoriteSetting;
	}
	public enum FavoriteFilter
	{
		ShowAll,
		ShowOnlyFavorited,
		HideFavorited
	}
	[BepInPlugin("sparroh.improvedupgradesorting", "ImprovedUpgradeSorting", "1.0.0")]
	[MycoMod(/*Could not decode attribute arguments.*/)]
	public class UpgradeSortingPlugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <DelayedButtonCreation>d__12 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public UpgradeSortingPlugin <>4__this;

			public GearDetailsWindow window;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <DelayedButtonCreation>d__12(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				int num = <>1__state;
				UpgradeSortingPlugin upgradeSortingPlugin = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					upgradeSortingPlugin.CreateFilterButton(window);
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public const string PluginGUID = "sparroh.improvedupgradesorting";

		public const string PluginName = "ImprovedUpgradeSorting";

		public const string PluginVersion = "1.0.0";

		internal static UpgradeSortingPlugin Instance = null;

		internal static ManualLogSource Logger;

		internal FilterPanelUI FilterPanel;

		internal static List<CustomSortingMethod> SortPriorities = new List<CustomSortingMethod>
		{
			CustomSortingMethod.Rarity,
			CustomSortingMethod.Name
		};

		public static Dictionary<Rarity, int> RarityOrder = new Dictionary<Rarity, int>
		{
			{
				(Rarity)4,
				5
			},
			{
				(Rarity)3,
				4
			},
			{
				(Rarity)2,
				3
			},
			{
				(Rarity)1,
				2
			},
			{
				(Rarity)0,
				1
			},
			{
				(Rarity)(-1),
				0
			}
		};

		internal static FilterSettings CurrentFilters = new FilterSettings
		{
			HiddenRarities = new List<Rarity>(),
			FilterStats = false,
			StatIncludeList = new List<string>(),
			FavoriteSetting = FavoriteFilter.ShowAll
		};

		internal static bool? PreviousSkinMode = null;

		private void Awake()
		{
			//IL_0016: 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)
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			Harmony val = new Harmony("sparroh.improvedupgradesorting");
			Logger.LogInfo((object)"ImprovedUpgradeSorting loaded successfully.");
			FilterPanel = new FilterPanelUI();
			val.PatchAll(typeof(GearDetailsWindowpatches));
			val.PatchAll(typeof(SortUpgradesPatch));
		}

		internal void OnGearDetailsWindowOpen(GearDetailsWindow window)
		{
			((MonoBehaviour)window).StartCoroutine(DelayedButtonCreation(window));
		}

		[IteratorStateMachine(typeof(<DelayedButtonCreation>d__12))]
		private IEnumerator DelayedButtonCreation(GearDetailsWindow window)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <DelayedButtonCreation>d__12(0)
			{
				<>4__this = this,
				window = window
			};
		}

		private void CreateFilterButton(GearDetailsWindow window)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_0050: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Expected O, but got Unknown
			try
			{
				GameObject val = GameObject.Find("Gear Details");
				if (!((Object)(object)val == (Object)null))
				{
					GameObject val2 = new GameObject("Mycopunk_FilterButton");
					val2.transform.SetParent(val.transform, false);
					((Graphic)val2.AddComponent<Image>()).color = new Color(0.8f, 0.2f, 0.9f, 1f);
					Button obj = val2.AddComponent<Button>();
					TextMeshProUGUI obj2 = new GameObject("Text").AddComponent<TextMeshProUGUI>();
					((TMP_Text)obj2).transform.SetParent(val2.transform, false);
					((TMP_Text)obj2).text = "FILTER";
					((TMP_Text)obj2).fontSize = 18f;
					((Graphic)obj2).color = Color.white;
					((TMP_Text)obj2).alignment = (TextAlignmentOptions)514;
					RectTransform component = val2.GetComponent<RectTransform>();
					component.anchorMin = new Vector2(0.5f, 1f);
					component.anchorMax = new Vector2(0.5f, 1f);
					component.pivot = new Vector2(0.5f, 1f);
					component.anchoredPosition = new Vector2(50f, -300f);
					component.sizeDelta = new Vector2(150f, 45f);
					RectTransform component2 = ((Component)obj2).GetComponent<RectTransform>();
					component2.anchorMin = Vector2.zero;
					component2.anchorMax = Vector2.one;
					component2.offsetMin = Vector2.zero;
					component2.offsetMax = Vector2.zero;
					val2.SetActive(true);
					((Selectable)obj).interactable = true;
					((Selectable)obj).transition = (Transition)1;
					((Selectable)obj).colors = ColorBlock.defaultColorBlock;
					((UnityEventBase)obj.onClick).RemoveAllListeners();
					((UnityEvent)obj.onClick).AddListener((UnityAction)delegate
					{
						FilterPanel.Toggle();
					});
					LayoutRebuilder.ForceRebuildLayoutImmediate(component);
					Canvas.ForceUpdateCanvases();
				}
			}
			catch (Exception)
			{
			}
		}
	}
	[HarmonyPatch(typeof(GearDetailsWindow))]
	public static class GearDetailsWindowpatches
	{
		private static readonly Comparison<GearUpgradeUI> CompareUpgradesByFullName = delegate(GearUpgradeUI a, GearUpgradeUI b)
		{
			if (((Component)a).gameObject.activeSelf && !((Component)b).gameObject.activeSelf)
			{
				return -1;
			}
			if (!((Component)a).gameObject.activeSelf && ((Component)b).gameObject.activeSelf)
			{
				return 1;
			}
			string instanceName = ((HoverInfoUpgrade)a).Upgrade.Upgrade.GetInstanceName(((HoverInfoUpgrade)a).Upgrade.Seed);
			string instanceName2 = ((HoverInfoUpgrade)b).Upgrade.Upgrade.GetInstanceName(((HoverInfoUpgrade)b).Upgrade.Seed);
			return instanceName.CompareTo(instanceName2);
		};

		private static readonly Comparison<GearUpgradeUI> CompareUpgradesByCustomRarity = delegate(GearUpgradeUI a, GearUpgradeUI b)
		{
			//IL_0048: 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)
			if (((Component)a).gameObject.activeSelf && !((Component)b).gameObject.activeSelf)
			{
				return -1;
			}
			if (!((Component)a).gameObject.activeSelf && ((Component)b).gameObject.activeSelf)
			{
				return 1;
			}
			UpgradeSortingPlugin.RarityOrder.TryGetValue(((HoverInfoUpgrade)a).Upgrade.Upgrade.Rarity, out var value);
			UpgradeSortingPlugin.RarityOrder.TryGetValue(((HoverInfoUpgrade)b).Upgrade.Upgrade.Rarity, out var value2);
			int num = value2.CompareTo(value);
			return (num == 0) ? CompareUpgradesByFullName(a, b) : num;
		};

		private static readonly Comparison<GearUpgradeUI> CompareUpgradesByRecentlyAcquired = delegate(GearUpgradeUI a, GearUpgradeUI b)
		{
			if (((Component)a).gameObject.activeSelf && !((Component)b).gameObject.activeSelf)
			{
				return -1;
			}
			return (!((Component)a).gameObject.activeSelf && ((Component)b).gameObject.activeSelf) ? 1 : (-((HoverInfoUpgrade)a).Upgrade.TimeUnlocked.CompareTo(((HoverInfoUpgrade)b).Upgrade.TimeUnlocked));
		};

		public static Comparison<GearUpgradeUI> GetCustomComparison(CustomSortingMethod method)
		{
			return method switch
			{
				CustomSortingMethod.Name => CompareUpgradesByFullName, 
				CustomSortingMethod.Rarity => CompareUpgradesByCustomRarity, 
				CustomSortingMethod.RecentlyCollected => CompareUpgradesByRecentlyAcquired, 
				_ => CompareUpgradesByFullName, 
			};
		}

		public static Comparison<GearUpgradeUI> CreateChainedComparison(List<CustomSortingMethod> priorities)
		{
			return delegate(GearUpgradeUI a, GearUpgradeUI b)
			{
				foreach (CustomSortingMethod priority in priorities)
				{
					int num = GetCustomComparison(priority)(a, b);
					if (num != 0)
					{
						return num;
					}
				}
				return 0;
			};
		}

		public static List<CustomSortingMethod> GetDynamicPrioritiesForMethod(SortingMethod method)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected I4, but got Unknown
			return (int)method switch
			{
				0 => new List<CustomSortingMethod>
				{
					CustomSortingMethod.Name,
					CustomSortingMethod.Rarity
				}, 
				1 => new List<CustomSortingMethod>
				{
					CustomSortingMethod.Rarity,
					CustomSortingMethod.Name
				}, 
				3 => new List<CustomSortingMethod>
				{
					CustomSortingMethod.RecentlyCollected,
					CustomSortingMethod.Rarity,
					CustomSortingMethod.Name
				}, 
				_ => new List<CustomSortingMethod>
				{
					CustomSortingMethod.Rarity,
					CustomSortingMethod.Name
				}, 
			};
		}

		public static List<GearUpgradeUI> ApplyFilters(List<GearUpgradeUI> upgradeUIs, FilterSettings filters)
		{
			List<GearUpgradeUI> list = new List<GearUpgradeUI>(upgradeUIs.Count);
			foreach (GearUpgradeUI upgradeUI in upgradeUIs)
			{
				if ((filters.FavoriteSetting != FavoriteFilter.ShowOnlyFavorited || ((HoverInfoUpgrade)upgradeUI).Upgrade.Favorite) && (filters.FavoriteSetting != FavoriteFilter.HideFavorited || !((HoverInfoUpgrade)upgradeUI).Upgrade.Favorite))
				{
					list.Add(upgradeUI);
				}
			}
			return list;
		}

		[HarmonyPostfix]
		[HarmonyPatch("OnOpen")]
		private static void OnOpen(GearDetailsWindow __instance)
		{
			try
			{
				FieldInfo fieldInfo = AccessTools.Field(typeof(GearDetailsWindow), "inSkinMode");
				bool flag = false;
				if (fieldInfo != null)
				{
					flag = (bool)fieldInfo.GetValue(__instance);
					if (UpgradeSortingPlugin.PreviousSkinMode.HasValue && UpgradeSortingPlugin.PreviousSkinMode.Value != flag && (Object)(object)UpgradeSortingPlugin.Instance != (Object)null && UpgradeSortingPlugin.Instance.FilterPanel != null)
					{
						UpgradeSortingPlugin.Instance.FilterPanel.RegenerateStatFilters();
					}
					UpgradeSortingPlugin.PreviousSkinMode = flag;
				}
			}
			catch (Exception)
			{
			}
			UpgradeSortingPlugin.Instance.OnGearDetailsWindowOpen(__instance);
		}
	}
	[HarmonyPatch(typeof(GearDetailsWindow), "SortUpgrades", new Type[]
	{
		typeof(SortingMethod),
		typeof(bool)
	})]
	public static class SortUpgradesPatch
	{
		private static bool? lastSkinMode;

		private static int PropertyAwareNameComparison(GearUpgradeUI a, GearUpgradeUI b)
		{
			if (((Component)a).gameObject.activeSelf && !((Component)b).gameObject.activeSelf)
			{
				return -1;
			}
			if (!((Component)a).gameObject.activeSelf && ((Component)b).gameObject.activeSelf)
			{
				return 1;
			}
			try
			{
				string instanceName = ((HoverInfoUpgrade)a).Upgrade.Upgrade.GetInstanceName(((HoverInfoUpgrade)a).Upgrade.Seed);
				string instanceName2 = ((HoverInfoUpgrade)b).Upgrade.Upgrade.GetInstanceName(((HoverInfoUpgrade)b).Upgrade.Seed);
				return instanceName.CompareTo(instanceName2);
			}
			catch (Exception)
			{
				return ((HoverInfoUpgrade)a).Upgrade.Upgrade.Name.CompareTo(((HoverInfoUpgrade)b).Upgrade.Upgrade.Name);
			}
		}

		[HarmonyPostfix]
		public static void Postfix(GearDetailsWindow __instance, SortingMethod method, bool resetScroll)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			FieldInfo fieldInfo = AccessTools.Field(typeof(GearDetailsWindow), "inSkinMode");
			bool flag = false;
			if (fieldInfo != null)
			{
				try
				{
					flag = (bool)fieldInfo.GetValue(__instance);
				}
				catch
				{
				}
			}
			bool flag2 = lastSkinMode.HasValue && lastSkinMode.Value != flag;
			lastSkinMode = flag;
			if ((int)method == 0)
			{
				try
				{
					FieldInfo fieldInfo2 = AccessTools.Field(typeof(GearDetailsWindow), "upgradeUIs") ?? AccessTools.Field(typeof(GearDetailsWindow), "<upgradeUIs>k__BackingField") ?? AccessTools.Field(typeof(GearDetailsWindow), "upgrades");
					if (fieldInfo2 != null)
					{
						List<GearUpgradeUI> list = (List<GearUpgradeUI>)fieldInfo2.GetValue(__instance);
						if (list != null && list.Count >= 2)
						{
							list.Sort(PropertyAwareNameComparison);
						}
					}
				}
				catch (Exception)
				{
				}
			}
			if (!flag2 && HasActiveFilters())
			{
				try
				{
					ApplyFiltersToSortedList(__instance);
				}
				catch (Exception)
				{
				}
			}
		}

		private static bool HasActiveFilters()
		{
			if (!UpgradeSortingPlugin.CurrentFilters.HiddenRarities.Any() && UpgradeSortingPlugin.CurrentFilters.FavoriteSetting == FavoriteFilter.ShowAll)
			{
				if (UpgradeSortingPlugin.CurrentFilters.FilterStats)
				{
					return UpgradeSortingPlugin.CurrentFilters.StatIncludeList.Any();
				}
				return false;
			}
			return true;
		}

		private static void ApplyFiltersToSortedList(GearDetailsWindow window)
		{
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			FieldInfo fieldInfo = AccessTools.Field(typeof(GearDetailsWindow), "upgradeUIs") ?? AccessTools.Field(typeof(GearDetailsWindow), "<upgradeUIs>k__BackingField") ?? AccessTools.Field(typeof(GearDetailsWindow), "upgrades");
			FieldInfo fieldInfo2 = AccessTools.Field(typeof(GearDetailsWindow), "upgradeUICount");
			if (fieldInfo == null || fieldInfo2 == null)
			{
				return;
			}
			List<GearUpgradeUI> list = (List<GearUpgradeUI>)fieldInfo.GetValue(window);
			if (list == null || list.Count == 0)
			{
				return;
			}
			int num = 0;
			foreach (GearUpgradeUI item in list)
			{
				bool flag = true;
				if (UpgradeSortingPlugin.CurrentFilters.HiddenRarities.Any())
				{
					flag &= !UpgradeSortingPlugin.CurrentFilters.HiddenRarities.Contains(((HoverInfoUpgrade)item).Upgrade.Upgrade.Rarity);
				}
				switch (UpgradeSortingPlugin.CurrentFilters.FavoriteSetting)
				{
				case FavoriteFilter.ShowOnlyFavorited:
					flag &= ((HoverInfoUpgrade)item).Upgrade.Favorite;
					break;
				case FavoriteFilter.HideFavorited:
					flag &= !((HoverInfoUpgrade)item).Upgrade.Favorite;
					break;
				}
				if (UpgradeSortingPlugin.CurrentFilters.FilterStats && UpgradeSortingPlugin.CurrentFilters.StatIncludeList.Any())
				{
					bool flag2 = true;
					foreach (string statInclude in UpgradeSortingPlugin.CurrentFilters.StatIncludeList)
					{
						bool flag3 = false;
						Enumerator properties = ((HoverInfoUpgrade)item).Upgrade.Upgrade.GetProperties();
						while (((Enumerator)(ref properties)).MoveNext())
						{
							string text = ((object)((Enumerator)(ref properties)).Current).GetType().Name;
							if (text.StartsWith("UpgradeProperty_"))
							{
								text = text.Substring("UpgradeProperty_".Length);
							}
							if (text == statInclude)
							{
								flag3 = true;
								break;
							}
						}
						if (!flag3)
						{
							flag2 = false;
							break;
						}
					}
					flag = flag && flag2;
				}
				((Component)item).gameObject.SetActive(flag);
				if (flag)
				{
					num++;
					((Component)item).transform.SetSiblingIndex(num - 1);
				}
			}
			try
			{
				fieldInfo2.SetValue(window, num);
			}
			catch
			{
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}