Decompiled source of AutoUpgrade v1.2.0

AutoUpgrade.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using Assets.Scripts.Inventory__Items__Pickups;
using Assets.Scripts.Saves___Serialization.Progression.Achievements;
using AutoUpgradeMod.Core;
using AutoUpgradeMod.Models;
using AutoUpgradeMod.UI;
using AutoUpgradeMod.Utils;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[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;
		}
	}
}
namespace AutoUpgradeMod
{
	[BepInPlugin("anro_AutoUpgrade", "AutoUpgrade", "1.2.0")]
	public class Plugin : BasePlugin
	{
		[HarmonyPatch(typeof(UpgradePicker), "ShuffleUpgrades")]
		public class UpgradePicker_ShuffleUpgrades_Patch
		{
			private static void Postfix(UpgradePicker __instance)
			{
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Expected O, but got Unknown
				try
				{
					AutoUpgradeUI.QueueAutoSelection(__instance);
				}
				catch (Exception ex)
				{
					ManualLogSource log = Log;
					bool flag = default(bool);
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(30, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Error queuing auto-selection: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					}
					log.LogError(val);
				}
			}
		}

		[HarmonyPatch(typeof(DeathScreen), "GoToMenu")]
		public class DeathScreen_GoToMenu_Patch
		{
			private static void Prefix()
			{
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Expected O, but got Unknown
				try
				{
					if ((Object)(object)AutoUpgradeUI.Instance != (Object)null)
					{
						AutoUpgradeUI.Instance.ClearNotifications();
					}
				}
				catch (Exception ex)
				{
					ManualLogSource log = Plugin.log;
					bool flag = default(bool);
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(22, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("GoToMenu patch error: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					}
					log.LogError(val);
				}
			}
		}

		[HarmonyPatch(typeof(PauseUi), "Restart")]
		public class PauseUi_Restart_Patch
		{
			private static void Prefix()
			{
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Expected O, but got Unknown
				try
				{
					if ((Object)(object)AutoUpgradeUI.Instance != (Object)null)
					{
						AutoUpgradeUI.Instance.ClearNotifications();
					}
				}
				catch (Exception ex)
				{
					ManualLogSource log = Plugin.log;
					bool flag = default(bool);
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(21, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Restart patch error: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					}
					log.LogError(val);
				}
			}
		}

		public const string MODNAME = "AutoUpgrade";

		public const string AUTHOR = "anro";

		public const string GUID = "anro_AutoUpgrade";

		public const string VERSION = "1.2.0";

		private static ManualLogSource log;

		private static Harmony harmony;

		public static ManualLogSource Log => log;

		public Plugin()
		{
			log = ((BasePlugin)this).Log;
		}

		public override void Load()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Expected O, but got Unknown
			ManualLogSource obj = log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(14, 3, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Loading ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("AutoUpgrade");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" v");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.2.0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" by ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("anro");
			}
			obj.LogInfo(val);
			PriorityManager.Initialize(Log);
			ConfigManager.Initialize(((BasePlugin)this).Config, Log);
			AutoSelector.Initialize(Log);
			ConfigManager.LoadPriorityList();
			ClassInjector.RegisterTypeInIl2Cpp<AutoUpgradeUI>();
			AutoUpgradeUI.Initialize(Log);
			((BasePlugin)this).AddComponent<AutoUpgradeUI>();
			harmony = new Harmony("anro_AutoUpgrade");
			harmony.PatchAll();
			ManualLogSource obj2 = log;
			val = new BepInExInfoLogInterpolatedStringHandler(47, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("anro_AutoUpgrade");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded with unified priority system!");
			}
			obj2.LogInfo(val);
		}
	}
}
namespace AutoUpgradeMod.Utils
{
	public static class StyleHelper
	{
		private static GUIStyle _menuBox;

		private static GUIStyle _sectionBox;

		private static GUIStyle _headerLabel;

		private static GUIStyle _itemLabel;

		private static GUIStyle _button;

		private static GUIStyle _smallButton;

		private static GUIStyle _disabledButton;

		private static GUIStyle _windowStyle;

		private static GUIStyle _toggleStyle;

		public static GUIStyle MenuBox
		{
			get
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Expected O, but got Unknown
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_004a: Expected O, but got Unknown
				//IL_006a: Unknown result type (might be due to invalid IL or missing references)
				if (_menuBox == null)
				{
					_menuBox = new GUIStyle(GUI.skin.box);
					_menuBox.padding = new RectOffset
					{
						left = 15,
						right = 15,
						top = 15,
						bottom = 15
					};
					_menuBox.normal.background = MakeTex(2, 2, new Color(0.2f, 0.2f, 0.2f, 1f));
				}
				return _menuBox;
			}
		}

		public static GUIStyle SectionBox
		{
			get
			{
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Expected O, but got Unknown
				//IL_0023: 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_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_004d: Expected O, but got Unknown
				//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_005e: 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_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0078: Expected O, but got Unknown
				//IL_0098: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b8: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d2: Expected O, but got Unknown
				if (_sectionBox == null)
				{
					_sectionBox = new GUIStyle(GUI.skin.box);
					_sectionBox.padding = new RectOffset
					{
						left = 10,
						right = 10,
						top = 10,
						bottom = 10
					};
					_sectionBox.margin = new RectOffset
					{
						left = 0,
						right = 0,
						top = 5,
						bottom = 5
					};
					_sectionBox.normal.background = MakeTex(2, 2, new Color(0.15f, 0.15f, 0.15f, 1f));
					_sectionBox.border = new RectOffset
					{
						left = 2,
						right = 2,
						top = 2,
						bottom = 2
					};
				}
				return _sectionBox;
			}
		}

		public static GUIStyle HeaderLabel
		{
			get
			{
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Expected O, but got Unknown
				//IL_004e: 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_006d: 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_007b: 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_008e: Expected O, but got Unknown
				if (_headerLabel == null)
				{
					_headerLabel = new GUIStyle(GUI.skin.label);
					_headerLabel.fontSize = 14;
					_headerLabel.fontStyle = (FontStyle)1;
					_headerLabel.normal.textColor = new Color(1f, 0.92f, 0.016f);
					_headerLabel.alignment = (TextAnchor)3;
					_headerLabel.padding = new RectOffset
					{
						left = 5,
						right = 5,
						top = 5,
						bottom = 5
					};
				}
				return _headerLabel;
			}
		}

		public static GUIStyle ItemLabel
		{
			get
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Expected O, but got Unknown
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_0057: 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_0065: Unknown result type (might be due to invalid IL or missing references)
				//IL_0071: Expected O, but got Unknown
				if (_itemLabel == null)
				{
					_itemLabel = new GUIStyle(GUI.skin.label);
					_itemLabel.fontSize = 12;
					_itemLabel.normal.textColor = Color.white;
					_itemLabel.alignment = (TextAnchor)3;
					_itemLabel.padding = new RectOffset
					{
						left = 5,
						right = 5,
						top = 2,
						bottom = 2
					};
				}
				return _itemLabel;
			}
		}

		public static GUIStyle Button
		{
			get
			{
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Expected O, but got Unknown
				//IL_0023: 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_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Expected O, but got Unknown
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				//IL_006a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0076: Expected O, but got Unknown
				//IL_0097: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e4: 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)
				if (_button == null)
				{
					_button = new GUIStyle(GUI.skin.button);
					_button.padding = new RectOffset
					{
						left = 10,
						right = 10,
						top = 6,
						bottom = 6
					};
					_button.margin = new RectOffset
					{
						left = 2,
						right = 2,
						top = 2,
						bottom = 2
					};
					_button.fontSize = 12;
					_button.fontStyle = (FontStyle)0;
					_button.normal.textColor = Color.white;
					_button.hover.textColor = new Color(1f, 0.92f, 0.016f);
					_button.normal.background = MakeTex(2, 2, new Color(0.3f, 0.3f, 0.3f, 1f));
					_button.hover.background = MakeTex(2, 2, new Color(0.4f, 0.4f, 0.4f, 1f));
				}
				return _button;
			}
		}

		public static GUIStyle SmallButton
		{
			get
			{
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Expected O, but got Unknown
				//IL_0023: 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_002f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0049: Expected O, but got Unknown
				//IL_004e: 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_005a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0061: 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_0074: Expected O, but got Unknown
				//IL_0095: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
				//IL_0111: Unknown result type (might be due to invalid IL or missing references)
				if (_smallButton == null)
				{
					_smallButton = new GUIStyle(GUI.skin.button);
					_smallButton.padding = new RectOffset
					{
						left = 6,
						right = 6,
						top = 4,
						bottom = 4
					};
					_smallButton.margin = new RectOffset
					{
						left = 2,
						right = 2,
						top = 2,
						bottom = 2
					};
					_smallButton.fontSize = 11;
					_smallButton.fontStyle = (FontStyle)0;
					_smallButton.normal.textColor = Color.white;
					_smallButton.hover.textColor = new Color(1f, 0.92f, 0.016f);
					_smallButton.normal.background = MakeTex(2, 2, new Color(0.3f, 0.3f, 0.3f, 1f));
					_smallButton.hover.background = MakeTex(2, 2, new Color(0.4f, 0.4f, 0.4f, 1f));
				}
				return _smallButton;
			}
		}

		public static GUIStyle DisabledButton
		{
			get
			{
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Expected O, but got Unknown
				//IL_0023: 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_002f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0049: Expected O, but got Unknown
				//IL_004e: 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_005a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0061: 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_0074: Expected O, but got Unknown
				//IL_00a9: 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_00fb: 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)
				if (_disabledButton == null)
				{
					_disabledButton = new GUIStyle(GUI.skin.button);
					_disabledButton.padding = new RectOffset
					{
						left = 6,
						right = 6,
						top = 4,
						bottom = 4
					};
					_disabledButton.margin = new RectOffset
					{
						left = 2,
						right = 2,
						top = 2,
						bottom = 2
					};
					_disabledButton.fontSize = 11;
					_disabledButton.fontStyle = (FontStyle)0;
					_disabledButton.normal.textColor = new Color(0.5f, 0.5f, 0.5f, 0.8f);
					_disabledButton.hover.textColor = new Color(0.5f, 0.5f, 0.5f, 0.8f);
					_disabledButton.normal.background = MakeTex(2, 2, new Color(0.2f, 0.2f, 0.2f, 0.8f));
					_disabledButton.hover.background = MakeTex(2, 2, new Color(0.2f, 0.2f, 0.2f, 0.8f));
				}
				return _disabledButton;
			}
		}

		public static GUIStyle WindowStyle
		{
			get
			{
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Expected O, but got Unknown
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0086: Unknown result type (might be due to invalid IL or missing references)
				//IL_009a: 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)
				//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00be: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d3: Expected O, but got Unknown
				//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e4: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fe: Expected O, but got Unknown
				if (_windowStyle == null)
				{
					_windowStyle = new GUIStyle(GUI.skin.window);
					_windowStyle.normal.background = MakeTex(2, 2, new Color(0.15f, 0.15f, 0.15f, 1f));
					_windowStyle.onNormal.background = MakeTex(2, 2, new Color(0.15f, 0.15f, 0.15f, 1f));
					_windowStyle.normal.textColor = Color.white;
					_windowStyle.onNormal.textColor = Color.white;
					_windowStyle.padding = new RectOffset
					{
						left = 10,
						right = 10,
						top = 25,
						bottom = 10
					};
					_windowStyle.border = new RectOffset
					{
						left = 4,
						right = 4,
						top = 4,
						bottom = 4
					};
					_windowStyle.fontSize = 14;
					_windowStyle.fontStyle = (FontStyle)1;
				}
				return _windowStyle;
			}
		}

		public static GUIStyle ToggleStyle
		{
			get
			{
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Expected O, but got Unknown
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				//IL_0089: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e2: Expected O, but got Unknown
				if (_toggleStyle == null)
				{
					_toggleStyle = new GUIStyle(GUI.skin.toggle);
					_toggleStyle.fontSize = 12;
					_toggleStyle.normal.textColor = new Color(1f, 0.4f, 0.4f);
					_toggleStyle.onNormal.textColor = new Color(0.4f, 1f, 0.4f);
					_toggleStyle.hover.textColor = new Color(1f, 0.5f, 0.5f);
					_toggleStyle.onHover.textColor = new Color(0.5f, 1f, 0.5f);
					_toggleStyle.padding = new RectOffset
					{
						left = 20,
						right = 5,
						top = 2,
						bottom = 2
					};
				}
				return _toggleStyle;
			}
		}

		private static Texture2D MakeTex(int width, int height, Color col)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			Color[] array = (Color[])(object)new Color[width * height];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = col;
			}
			Texture2D val = new Texture2D(width, height);
			val.SetPixels(Il2CppStructArray<Color>.op_Implicit(array));
			val.Apply();
			return val;
		}

		public static void ResetStyles()
		{
			_menuBox = null;
			_sectionBox = null;
			_headerLabel = null;
			_itemLabel = null;
			_button = null;
			_smallButton = null;
			_disabledButton = null;
			_windowStyle = null;
			_toggleStyle = null;
		}
	}
}
namespace AutoUpgradeMod.UI
{
	public class AutoUpgradeUI : MonoBehaviour
	{
		private class Notification
		{
			public string itemName;

			public string rarity;

			public int fromLevel;

			public int toLevel;

			public List<(string name, string rarity)> choices;

			public float timestamp;
		}

		private static ManualLogSource log;

		private static HashSet<string> discoveredWeapons = new HashSet<string>();

		private static HashSet<string> discoveredTomes = new HashSet<string>();

		private int discoveryRetryCount;

		private const int MAX_DISCOVERY_RETRIES = 5;

		private bool showMenu;

		private Rect menuRect = new Rect(100f, 50f, 950f, 850f);

		private const int WINDOW_ID = 99999;

		private bool autoSelectionEnabled = true;

		private Vector2 weaponScrollPosition = Vector2.zero;

		private Vector2 tomeScrollPosition = Vector2.zero;

		private List<Notification> notifications = new List<Notification>();

		private const float NOTIFICATION_LIFETIME = 60f;

		private const int MAX_NOTIFICATIONS = 4;

		private Vector2 notificationScrollPosition = Vector2.zero;

		private GUIStyle cachedSelectedStyle;

		private GUIStyle cachedChoiceStyle;

		private float cachedChoicesPrefixWidth;

		private float cachedBulletWidth;

		private static UpgradePicker pendingPicker = null;

		private static float delayUntilTime = 0f;

		private static bool isProcessing = false;

		private const float NORMAL_DELAY = 0.005f;

		private const float RETRY_DELAY = 0.01f;

		private static bool lastSelectionWasManual = false;

		private static int retryCount = 0;

		private const int MAX_RETRIES = 2;

		private bool showMaxLevelDialog;

		private int currentEditingIndex = -1;

		private int tempMaxLevel = -1;

		public static AutoUpgradeUI Instance { get; private set; }

		public AutoUpgradeUI(IntPtr ptr)
			: base(ptr)
		{
		}//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)


		private void AddSpace(float pixels)
		{
			GUILayout.Label("", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(pixels) });
		}

		public static void Initialize(ManualLogSource logger)
		{
			log = logger;
			log.LogInfo((object)"AutoUpgradeUI initialized");
		}

		private void Start()
		{
			Instance = this;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			((MonoBehaviour)this).Invoke("DiscoverItems", 2f);
			ManualLogSource obj = log;
			if (obj != null)
			{
				obj.LogInfo((object)"AutoUpgradeUI component started");
			}
		}

		private void Update()
		{
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Expected O, but got Unknown
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Expected O, but got Unknown
			if (isProcessing || !((Object)(object)pendingPicker != (Object)null) || !(Time.time >= delayUntilTime) || !autoSelectionEnabled)
			{
				return;
			}
			isProcessing = true;
			UpgradePicker val = pendingPicker;
			pendingPicker = null;
			bool flag = default(bool);
			try
			{
				if (AutoSelector.ProcessAutoSelection(val))
				{
					ManualLogSource val2 = log;
					if (val2 != null)
					{
						BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(36, 2, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Manual selection triggered (retry ");
							((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(retryCount);
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("/");
							((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(2);
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(")");
						}
						val2.LogInfo(val3);
					}
					if (retryCount < 2 && (Object)(object)val != (Object)null)
					{
						retryCount++;
						pendingPicker = val;
						delayUntilTime = Time.time + 0.01f;
						val2 = log;
						if (val2 != null)
						{
							BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(15, 1, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Queuing retry #");
								((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(retryCount);
							}
							val2.LogInfo(val3);
						}
						isProcessing = false;
					}
					else
					{
						lastSelectionWasManual = true;
					}
				}
				else
				{
					lastSelectionWasManual = false;
					retryCount = 0;
				}
			}
			catch (Exception ex)
			{
				ManualLogSource val2 = log;
				if (val2 != null)
				{
					BepInExErrorLogInterpolatedStringHandler val4 = new BepInExErrorLogInterpolatedStringHandler(25, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("Delayed selection error: ");
						((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(ex.Message);
					}
					val2.LogError(val4);
				}
				if ((Object)(object)((val != null) ? val.levelupScreen : null) != (Object)null)
				{
					((Component)val.levelupScreen).gameObject.SetActive(true);
				}
			}
			finally
			{
				isProcessing = false;
			}
		}

		public static void QueueAutoSelection(UpgradePicker picker)
		{
			if ((Object)(object)picker == (Object)null)
			{
				return;
			}
			pendingPicker = picker;
			retryCount = 0;
			if (lastSelectionWasManual)
			{
				delayUntilTime = Time.time + 0.01f;
				ManualLogSource obj = log;
				if (obj != null)
				{
					obj.LogInfo((object)"Queued with extended delay (post-manual)");
				}
			}
			else
			{
				delayUntilTime = Time.time + 0.005f;
			}
		}

		private void OnGUI()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Invalid comparison between Unknown and I4
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Invalid comparison between Unknown and I4
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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_006f: Expected O, but got Unknown
			GUI.color = Color.white;
			GUI.backgroundColor = Color.white;
			if ((int)Event.current.type == 4 && (int)Event.current.keyCode == 282)
			{
				showMenu = !showMenu;
				if (showMenu)
				{
					StyleHelper.ResetStyles();
					cachedSelectedStyle = null;
					cachedChoiceStyle = null;
				}
				ManualLogSource val = log;
				if (val != null)
				{
					bool flag = default(bool);
					BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(5, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Menu ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(showMenu ? "opened" : "closed");
					}
					val.LogInfo(val2);
				}
			}
			if (showMenu)
			{
				menuRect = GUI.Window(99999, menuRect, WindowFunction.op_Implicit((Action<int>)DrawMainMenu), "AutoUpgrade - Unified Priority List", StyleHelper.WindowStyle);
			}
			if (showMaxLevelDialog)
			{
				DrawMaxLevelDialog();
			}
			DrawNotifications();
		}

		private void DrawMainMenu(int windowID)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Expected O, but got Unknown
			GUI.color = Color.white;
			GUI.backgroundColor = Color.white;
			GUI.contentColor = Color.white;
			GUI.DragWindow(new Rect(0f, 0f, 10000f, 20f));
			GUILayout.BeginVertical(StyleHelper.MenuBox, Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal((Il2CppReferenceArray<GUILayoutOption>)null);
			GUILayout.Label("AutoUpgrade - Unified Priority List", StyleHelper.HeaderLabel, (Il2CppReferenceArray<GUILayoutOption>)null);
			GUILayout.FlexibleSpace();
			if (GUILayout.Button("X", StyleHelper.SmallButton, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(30f) }))
			{
				showMenu = false;
				ManualLogSource obj = log;
				if (obj != null)
				{
					obj.LogInfo((object)"Menu closed via [X] button");
				}
			}
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal((Il2CppReferenceArray<GUILayoutOption>)null);
			string text = (autoSelectionEnabled ? " Auto-selection: ON" : " Auto-selection: OFF");
			bool flag = GUILayout.Toggle(autoSelectionEnabled, text, StyleHelper.ToggleStyle, (Il2CppReferenceArray<GUILayoutOption>)null);
			if (flag != autoSelectionEnabled)
			{
				autoSelectionEnabled = flag;
				if (!autoSelectionEnabled)
				{
					pendingPicker = null;
				}
				ManualLogSource val = log;
				if (val != null)
				{
					bool flag2 = default(bool);
					BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(15, 1, ref flag2);
					if (flag2)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Auto-selection ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(autoSelectionEnabled ? "enabled" : "disabled");
					}
					val.LogInfo(val2);
				}
			}
			GUILayout.EndHorizontal();
			AddSpace(10f);
			DrawPriorityListSection();
			AddSpace(10f);
			int weaponCount = PriorityManager.GetWeaponCount();
			int tomeCount = PriorityManager.GetTomeCount();
			int itemCount = PriorityManager.GetItemCount();
			GUILayout.Label($"{itemCount}/8 slots used - {weaponCount}W, {tomeCount}T", StyleHelper.ItemLabel, (Il2CppReferenceArray<GUILayoutOption>)null);
			AddSpace(10f);
			DrawAddItemsSection();
			AddSpace(10f);
			GUILayout.BeginHorizontal((Il2CppReferenceArray<GUILayoutOption>)null);
			if (GUILayout.Button("Clear All", StyleHelper.Button, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }))
			{
				PriorityManager.Clear();
				ConfigManager.SavePriorityList();
				ManualLogSource obj2 = log;
				if (obj2 != null)
				{
					obj2.LogInfo((object)"Priority list cleared via Clear All button");
				}
			}
			GUILayout.FlexibleSpace();
			if (GUILayout.Button("Close", StyleHelper.Button, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }))
			{
				showMenu = false;
				ManualLogSource obj3 = log;
				if (obj3 != null)
				{
					obj3.LogInfo((object)"Menu closed via Close button");
				}
			}
			GUILayout.EndHorizontal();
			GUILayout.EndVertical();
		}

		private void DrawPriorityListSection()
		{
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Expected O, but got Unknown
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Expected O, but got Unknown
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Expected O, but got Unknown
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Expected O, but got Unknown
			GUILayout.BeginVertical(StyleHelper.SectionBox, Array.Empty<GUILayoutOption>());
			GUILayout.Label("Priority List", StyleHelper.HeaderLabel, (Il2CppReferenceArray<GUILayoutOption>)null);
			AddSpace(5f);
			List<PriorityItem> priorityList = PriorityManager.GetPriorityList();
			if (priorityList.Count == 0)
			{
				GUILayout.Label("No items in priority list. Click [+] below to add items.", StyleHelper.ItemLabel, (Il2CppReferenceArray<GUILayoutOption>)null);
			}
			else
			{
				bool flag = default(bool);
				for (int i = 0; i < priorityList.Count; i++)
				{
					PriorityItem priorityItem = priorityList[i];
					GUILayout.BeginHorizontal((i % 2 == 0) ? StyleHelper.SectionBox : GUI.skin.box, Array.Empty<GUILayoutOption>());
					string value = FormatItemName(priorityItem.itemName);
					GUILayout.Label($"#{i + 1}: {value} ({priorityItem.TypeLabel}) Max: {priorityItem.MaxLevelDisplay}", StyleHelper.ItemLabel, (Il2CppReferenceArray<GUILayoutOption>)null);
					GUILayout.FlexibleSpace();
					bool num = i == 0;
					GUIStyle val = (num ? StyleHelper.DisabledButton : StyleHelper.SmallButton);
					GUI.enabled = !num;
					if (GUILayout.Button("↑", val, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(30f) }))
					{
						PriorityManager.MoveUp(i);
						ConfigManager.SavePriorityList();
						ManualLogSource val2 = log;
						if (val2 != null)
						{
							BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(33, 1, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Moved item '");
								((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(priorityItem.itemName);
								((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("' up in priority list");
							}
							val2.LogInfo(val3);
						}
					}
					GUI.enabled = true;
					bool num2 = i == priorityList.Count - 1;
					GUIStyle val4 = (num2 ? StyleHelper.DisabledButton : StyleHelper.SmallButton);
					GUI.enabled = !num2;
					if (GUILayout.Button("↓", val4, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(30f) }))
					{
						PriorityManager.MoveDown(i);
						ConfigManager.SavePriorityList();
						ManualLogSource val2 = log;
						if (val2 != null)
						{
							BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(35, 1, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Moved item '");
								((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(priorityItem.itemName);
								((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("' down in priority list");
							}
							val2.LogInfo(val3);
						}
					}
					GUI.enabled = true;
					if (GUILayout.Button("Edit Max", StyleHelper.SmallButton, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) }))
					{
						showMaxLevelDialog = true;
						currentEditingIndex = i;
						tempMaxLevel = priorityItem.maxLevel;
						ManualLogSource val2 = log;
						if (val2 != null)
						{
							BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(31, 1, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Opening max level dialog for '");
								((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(priorityItem.itemName);
								((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("'");
							}
							val2.LogInfo(val3);
						}
					}
					if (GUILayout.Button("Remove", StyleHelper.SmallButton, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) }))
					{
						PriorityManager.RemoveItem(i);
						ConfigManager.SavePriorityList();
						AddNotification("Removed '" + priorityItem.itemName + "' from priority list");
						ManualLogSource val2 = log;
						if (val2 != null)
						{
							BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(34, 1, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Removed item '");
								((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(priorityItem.itemName);
								((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("' from priority list");
							}
							val2.LogInfo(val3);
						}
					}
					GUILayout.EndHorizontal();
				}
			}
			GUILayout.EndVertical();
		}

		private void DrawAddItemsSection()
		{
			//IL_00bb: 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)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Expected O, but got Unknown
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Expected O, but got Unknown
			GUILayout.BeginVertical(StyleHelper.SectionBox, Array.Empty<GUILayoutOption>());
			GUILayout.Label("Add Items", StyleHelper.HeaderLabel, (Il2CppReferenceArray<GUILayoutOption>)null);
			AddSpace(5f);
			int weaponCount = PriorityManager.GetWeaponCount();
			int tomeCount = PriorityManager.GetTomeCount();
			List<string> list = GetDiscoveredWeapons();
			List<string> list2 = GetDiscoveredTomes();
			GUILayout.BeginHorizontal((Il2CppReferenceArray<GUILayoutOption>)null);
			GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(((Rect)(ref menuRect)).width / 2f - 20f) });
			GUILayout.Label($"WEAPONS ({weaponCount}/4)", StyleHelper.HeaderLabel, (Il2CppReferenceArray<GUILayoutOption>)null);
			AddSpace(3f);
			weaponScrollPosition = GUILayout.BeginScrollView(weaponScrollPosition, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(200f) });
			bool flag2 = default(bool);
			foreach (string item in list)
			{
				GUILayout.BeginHorizontal((Il2CppReferenceArray<GUILayoutOption>)null);
				GUILayout.Label(FormatItemName(item), StyleHelper.ItemLabel, (Il2CppReferenceArray<GUILayoutOption>)null);
				GUILayout.FlexibleSpace();
				bool num = PriorityManager.HasItem(item);
				bool flag = !PriorityManager.CanAddWeapon();
				int num2;
				GUIStyle obj;
				if (!num)
				{
					num2 = ((!flag) ? 1 : 0);
					if (num2 != 0)
					{
						obj = StyleHelper.SmallButton;
						goto IL_013b;
					}
				}
				else
				{
					num2 = 0;
				}
				obj = StyleHelper.DisabledButton;
				goto IL_013b;
				IL_013b:
				GUIStyle val = obj;
				GUI.enabled = (byte)num2 != 0;
				if (GUILayout.Button("+", val, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(30f) }) && PriorityManager.TryAddItem(item, isWeapon: true))
				{
					ConfigManager.SavePriorityList();
					AddNotification("Added " + item + " to priority list");
					ManualLogSource val2 = log;
					if (val2 != null)
					{
						BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(32, 1, ref flag2);
						if (flag2)
						{
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Added weapon '");
							((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(item);
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("' to priority list");
						}
						val2.LogInfo(val3);
					}
				}
				GUI.enabled = true;
				GUILayout.EndHorizontal();
			}
			GUILayout.EndScrollView();
			GUILayout.EndVertical();
			GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(((Rect)(ref menuRect)).width / 2f - 20f) });
			GUILayout.Label($"TOMES ({tomeCount}/4)", StyleHelper.HeaderLabel, (Il2CppReferenceArray<GUILayoutOption>)null);
			AddSpace(3f);
			tomeScrollPosition = GUILayout.BeginScrollView(tomeScrollPosition, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(200f) });
			foreach (string item2 in list2)
			{
				GUILayout.BeginHorizontal((Il2CppReferenceArray<GUILayoutOption>)null);
				GUILayout.Label(FormatItemName(item2), StyleHelper.ItemLabel, (Il2CppReferenceArray<GUILayoutOption>)null);
				GUILayout.FlexibleSpace();
				bool num3 = PriorityManager.HasItem(item2);
				bool flag3 = !PriorityManager.CanAddTome();
				int num4;
				GUIStyle obj2;
				if (!num3)
				{
					num4 = ((!flag3) ? 1 : 0);
					if (num4 != 0)
					{
						obj2 = StyleHelper.SmallButton;
						goto IL_02f4;
					}
				}
				else
				{
					num4 = 0;
				}
				obj2 = StyleHelper.DisabledButton;
				goto IL_02f4;
				IL_02f4:
				GUIStyle val4 = obj2;
				GUI.enabled = (byte)num4 != 0;
				if (GUILayout.Button("+", val4, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(30f) }) && PriorityManager.TryAddItem(item2, isWeapon: false))
				{
					ConfigManager.SavePriorityList();
					AddNotification("Added " + item2 + " to priority list");
					ManualLogSource val2 = log;
					if (val2 != null)
					{
						BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(30, 1, ref flag2);
						if (flag2)
						{
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Added tome '");
							((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(item2);
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("' to priority list");
						}
						val2.LogInfo(val3);
					}
				}
				GUI.enabled = true;
				GUILayout.EndHorizontal();
			}
			GUILayout.EndScrollView();
			GUILayout.EndVertical();
			GUILayout.EndHorizontal();
			GUILayout.EndVertical();
		}

		private void DrawMaxLevelDialog()
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			float num = 500f;
			float num2 = 350f;
			float num3 = ((float)Screen.width - num) / 2f;
			float num4 = 100f;
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(num3, num4, num, num2);
			List<PriorityItem> priorityList = PriorityManager.GetPriorityList();
			if (currentEditingIndex < 0 || currentEditingIndex >= priorityList.Count)
			{
				showMaxLevelDialog = false;
				return;
			}
			PriorityItem priorityItem = priorityList[currentEditingIndex];
			GUI.Window(100000, val, WindowFunction.op_Implicit((Action<int>)DrawMaxLevelDialogContent), $"Edit Max Level for: {priorityItem.itemName} ({priorityItem.TypeLabel})", GUI.skin.window);
		}

		private void DrawMaxLevelDialogContent(int windowID)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: 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_0499: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a0: Expected O, but got Unknown
			//IL_0423: Unknown result type (might be due to invalid IL or missing references)
			//IL_042a: Expected O, but got Unknown
			GUI.color = Color.white;
			GUI.backgroundColor = Color.white;
			GUI.contentColor = Color.white;
			GUILayout.BeginVertical(StyleHelper.MenuBox, Array.Empty<GUILayoutOption>());
			AddSpace(10f);
			GUILayout.Label((tempMaxLevel == -1) ? "Current: ∞" : $"Current: {tempMaxLevel}", StyleHelper.ItemLabel, (Il2CppReferenceArray<GUILayoutOption>)null);
			AddSpace(10f);
			GUILayout.Label("Increment:", StyleHelper.ItemLabel, (Il2CppReferenceArray<GUILayoutOption>)null);
			GUILayout.BeginHorizontal((Il2CppReferenceArray<GUILayoutOption>)null);
			if (GUILayout.Button("+1", StyleHelper.SmallButton, Array.Empty<GUILayoutOption>()))
			{
				if (tempMaxLevel == -1)
				{
					tempMaxLevel = 1;
				}
				else
				{
					tempMaxLevel++;
				}
			}
			if (GUILayout.Button("+5", StyleHelper.SmallButton, Array.Empty<GUILayoutOption>()))
			{
				if (tempMaxLevel == -1)
				{
					tempMaxLevel = 5;
				}
				else
				{
					tempMaxLevel += 5;
				}
			}
			if (GUILayout.Button("+10", StyleHelper.SmallButton, Array.Empty<GUILayoutOption>()))
			{
				if (tempMaxLevel == -1)
				{
					tempMaxLevel = 10;
				}
				else
				{
					tempMaxLevel += 10;
				}
			}
			if (GUILayout.Button("+25", StyleHelper.SmallButton, Array.Empty<GUILayoutOption>()))
			{
				if (tempMaxLevel == -1)
				{
					tempMaxLevel = 25;
				}
				else
				{
					tempMaxLevel += 25;
				}
			}
			GUILayout.EndHorizontal();
			AddSpace(10f);
			GUILayout.Label("Decrement:", StyleHelper.ItemLabel, (Il2CppReferenceArray<GUILayoutOption>)null);
			GUILayout.BeginHorizontal((Il2CppReferenceArray<GUILayoutOption>)null);
			if (GUILayout.Button("-1", StyleHelper.SmallButton, Array.Empty<GUILayoutOption>()))
			{
				if (tempMaxLevel == -1)
				{
					tempMaxLevel = 1;
				}
				else if (tempMaxLevel > 1)
				{
					tempMaxLevel--;
				}
			}
			if (GUILayout.Button("-5", StyleHelper.SmallButton, Array.Empty<GUILayoutOption>()))
			{
				if (tempMaxLevel == -1)
				{
					tempMaxLevel = 1;
				}
				else
				{
					tempMaxLevel = Math.Max(1, tempMaxLevel - 5);
				}
			}
			if (GUILayout.Button("-10", StyleHelper.SmallButton, Array.Empty<GUILayoutOption>()))
			{
				if (tempMaxLevel == -1)
				{
					tempMaxLevel = 1;
				}
				else
				{
					tempMaxLevel = Math.Max(1, tempMaxLevel - 10);
				}
			}
			if (GUILayout.Button("-25", StyleHelper.SmallButton, Array.Empty<GUILayoutOption>()))
			{
				if (tempMaxLevel == -1)
				{
					tempMaxLevel = 1;
				}
				else
				{
					tempMaxLevel = Math.Max(1, tempMaxLevel - 25);
				}
			}
			GUILayout.EndHorizontal();
			AddSpace(10f);
			GUILayout.Label("Quick Set:", StyleHelper.ItemLabel, (Il2CppReferenceArray<GUILayoutOption>)null);
			GUILayout.BeginHorizontal((Il2CppReferenceArray<GUILayoutOption>)null);
			if (GUILayout.Button("1", StyleHelper.Button, Array.Empty<GUILayoutOption>()))
			{
				tempMaxLevel = 1;
			}
			if (GUILayout.Button("5", StyleHelper.Button, Array.Empty<GUILayoutOption>()))
			{
				tempMaxLevel = 5;
			}
			if (GUILayout.Button("10", StyleHelper.Button, Array.Empty<GUILayoutOption>()))
			{
				tempMaxLevel = 10;
			}
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal((Il2CppReferenceArray<GUILayoutOption>)null);
			if (GUILayout.Button("50", StyleHelper.Button, Array.Empty<GUILayoutOption>()))
			{
				tempMaxLevel = 50;
			}
			if (GUILayout.Button("100", StyleHelper.Button, Array.Empty<GUILayoutOption>()))
			{
				tempMaxLevel = 100;
			}
			if (GUILayout.Button("Unlimited", StyleHelper.Button, Array.Empty<GUILayoutOption>()))
			{
				tempMaxLevel = -1;
			}
			GUILayout.EndHorizontal();
			AddSpace(20f);
			GUILayout.BeginHorizontal((Il2CppReferenceArray<GUILayoutOption>)null);
			if (GUILayout.Button("Save", StyleHelper.Button, Array.Empty<GUILayoutOption>()))
			{
				bool flag = default(bool);
				if (tempMaxLevel >= 1 || tempMaxLevel == -1)
				{
					PriorityManager.SetMaxLevel(currentEditingIndex, tempMaxLevel);
					ConfigManager.SavePriorityList();
					List<PriorityItem> priorityList = PriorityManager.GetPriorityList();
					if (currentEditingIndex < priorityList.Count)
					{
						PriorityItem priorityItem = priorityList[currentEditingIndex];
						string text = ((tempMaxLevel == -1) ? "unlimited" : tempMaxLevel.ToString());
						ManualLogSource val = log;
						if (val != null)
						{
							BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(28, 2, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Updated max level for '");
								((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(priorityItem.itemName);
								((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("' to ");
								((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(text);
							}
							val.LogInfo(val2);
						}
						AddNotification("Updated max level for '" + priorityItem.itemName + "' to " + text);
					}
					showMaxLevelDialog = false;
				}
				else
				{
					ManualLogSource val = log;
					if (val != null)
					{
						BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(60, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Invalid max level value: ");
							((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(tempMaxLevel);
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(". Must be >= 1 or -1 for unlimited.");
						}
						val.LogWarning(val3);
					}
				}
			}
			GUILayout.FlexibleSpace();
			if (GUILayout.Button("Cancel", StyleHelper.Button, Array.Empty<GUILayoutOption>()))
			{
				showMaxLevelDialog = false;
				ManualLogSource obj = log;
				if (obj != null)
				{
					obj.LogInfo((object)"Max level dialog cancelled");
				}
			}
			GUILayout.EndHorizontal();
			GUILayout.EndVertical();
		}

		private string FormatItemName(string internalName)
		{
			if (string.IsNullOrEmpty(internalName))
			{
				return internalName;
			}
			if (internalName.StartsWith("Weapon"))
			{
				return internalName.Substring(6);
			}
			if (internalName.StartsWith("Tome"))
			{
				return internalName.Substring(4) + " Tome";
			}
			return internalName;
		}

		public void DiscoverItems()
		{
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Expected O, but got Unknown
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Expected O, but got Unknown
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Expected O, but got Unknown
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Expected O, but got Unknown
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Expected O, but got Unknown
			bool flag = default(bool);
			try
			{
				ManualLogSource val;
				if ((Object)(object)DataManager.Instance == (Object)null)
				{
					discoveryRetryCount++;
					if (discoveryRetryCount < 5)
					{
						val = log;
						if (val != null)
						{
							BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(67, 2, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("DataManager not available yet, retrying in 2 seconds (attempt ");
								((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(discoveryRetryCount);
								((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("/");
								((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(5);
								((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(")...");
							}
							val.LogWarning(val2);
						}
						((MonoBehaviour)this).Invoke("DiscoverItems", 2f);
						return;
					}
					val = log;
					if (val != null)
					{
						BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(48, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("DataManager failed to initialize after ");
							((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(5);
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" attempts");
						}
						val.LogError(val3);
					}
					return;
				}
				HashSet<string> hashSet = new HashSet<string>();
				HashSet<string> hashSet2 = new HashSet<string>();
				List<WeaponData> allWeapons = DataManager.Instance.GetAllWeapons();
				if (allWeapons != null)
				{
					Enumerator<WeaponData> enumerator = allWeapons.GetEnumerator();
					while (enumerator.MoveNext())
					{
						WeaponData current = enumerator.Current;
						if (!((Object)(object)current != (Object)null))
						{
							continue;
						}
						try
						{
							string name = ((Object)current).name;
							if (!string.IsNullOrEmpty(name))
							{
								hashSet.Add(name);
							}
						}
						catch (Exception ex)
						{
							val = log;
							if (val != null)
							{
								BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(27, 1, ref flag);
								if (flag)
								{
									((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Failed to get weapon name: ");
									((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
								}
								val.LogWarning(val2);
							}
						}
					}
				}
				List<TomeData> allTomes = DataManager.Instance.GetAllTomes();
				if (allTomes != null)
				{
					Enumerator<TomeData> enumerator2 = allTomes.GetEnumerator();
					while (enumerator2.MoveNext())
					{
						TomeData current2 = enumerator2.Current;
						if (!((Object)(object)current2 != (Object)null))
						{
							continue;
						}
						try
						{
							string name2 = ((Object)current2).name;
							if (!string.IsNullOrEmpty(name2))
							{
								hashSet2.Add(name2);
							}
						}
						catch (Exception ex2)
						{
							val = log;
							if (val != null)
							{
								BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(25, 1, ref flag);
								if (flag)
								{
									((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Failed to get tome name: ");
									((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex2.Message);
								}
								val.LogWarning(val2);
							}
						}
					}
				}
				discoveredWeapons = hashSet;
				discoveredTomes = hashSet2;
				val = log;
				if (val != null)
				{
					BepInExInfoLogInterpolatedStringHandler val4 = new BepInExInfoLogInterpolatedStringHandler(27, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("Discovered ");
						((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(hashSet.Count);
						((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" weapons, ");
						((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(hashSet2.Count);
						((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" tomes");
					}
					val.LogInfo(val4);
				}
			}
			catch (Exception ex3)
			{
				ManualLogSource val = log;
				if (val != null)
				{
					BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(21, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("DiscoverItems error: ");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex3.Message);
					}
					val.LogError(val3);
				}
			}
		}

		public static List<string> GetDiscoveredWeapons()
		{
			return discoveredWeapons.OrderBy((string w) => w).ToList();
		}

		public static List<string> GetDiscoveredTomes()
		{
			return discoveredTomes.OrderBy((string t) => t).ToList();
		}

		public void AddNotification(string message)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			notifications.Add(new Notification
			{
				itemName = message,
				rarity = "Common",
				fromLevel = 0,
				toLevel = 0,
				choices = new List<(string, string)>(),
				timestamp = Time.time
			});
			ManualLogSource val = log;
			if (val != null)
			{
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(14, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Notification: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(message);
				}
				val.LogInfo(val2);
			}
		}

		public void AddNotificationWithRarity(string itemName, string rarity, int fromLevel, int toLevel, List<(string, string)> choices)
		{
			while (notifications.Count >= 4)
			{
				notifications.RemoveAt(0);
			}
			notifications.Add(new Notification
			{
				itemName = itemName,
				rarity = rarity,
				fromLevel = fromLevel,
				toLevel = toLevel,
				choices = choices,
				timestamp = Time.time
			});
		}

		private void DrawNotifications()
		{
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			//IL_010e: 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_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: 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_0448: Unknown result type (might be due to invalid IL or missing references)
			//IL_0460: Unknown result type (might be due to invalid IL or missing references)
			//IL_039f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
			if (notifications.Count == 0)
			{
				return;
			}
			float currentTime = Time.time;
			if (notifications.Count > 0 && currentTime - notifications[0].timestamp > 60f)
			{
				notifications.RemoveAll((Notification n) => currentTime - n.timestamp > 60f);
				if (notifications.Count == 0)
				{
					return;
				}
			}
			if (cachedSelectedStyle == null)
			{
				cachedSelectedStyle = new GUIStyle(GUI.skin.label);
				cachedSelectedStyle.fontSize = 20;
				cachedSelectedStyle.fontStyle = (FontStyle)1;
				cachedSelectedStyle.wordWrap = false;
				cachedSelectedStyle.clipping = (TextClipping)0;
				cachedChoiceStyle = new GUIStyle(GUI.skin.label);
				cachedChoiceStyle.fontSize = 14;
				cachedChoiceStyle.fontStyle = (FontStyle)0;
				cachedChoiceStyle.clipping = (TextClipping)0;
				cachedChoicesPrefixWidth = cachedChoiceStyle.CalcSize(new GUIContent("Choices: ")).x;
				cachedBulletWidth = cachedChoiceStyle.CalcSize(new GUIContent(" • ")).x;
			}
			float num = 700f;
			float num2 = 280f;
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(20f, (float)Screen.height - num2 - 120f, num, num2);
			Color backgroundColor = GUI.backgroundColor;
			GUI.backgroundColor = new Color(0f, 0f, 0f, 0.3f);
			GUI.Box(val, "", GUI.skin.box);
			GUI.backgroundColor = backgroundColor;
			int count = notifications.Count;
			float num3 = ((Rect)(ref val)).y + 25f;
			for (int num4 = count - 1; num4 >= 0; num4--)
			{
				Notification notification = notifications[num4];
				float num5 = currentTime - notification.timestamp;
				float num6 = 1f - num5 / 60f * 0.5f;
				string text = ((notification.toLevel > 0) ? $"→ {notification.itemName} (Lv{notification.fromLevel} → Lv{notification.toLevel})" : ("→ " + notification.itemName));
				cachedSelectedStyle.normal.textColor = new Color(0f, 0f, 0f, num6 * 0.7f);
				GUI.Label(new Rect(((Rect)(ref val)).x + 11f, num3 + 1f, num - 20f, 28f), text, cachedSelectedStyle);
				cachedSelectedStyle.normal.textColor = GetRarityColor(notification.rarity, num6);
				GUI.Label(new Rect(((Rect)(ref val)).x + 10f, num3, num - 20f, 28f), text, cachedSelectedStyle);
				num3 += 26f;
				if (notification.choices != null && notification.choices.Count > 0)
				{
					float num7 = ((Rect)(ref val)).x + 20f;
					for (int i = 0; i < notification.choices.Count; i++)
					{
						(string, string) tuple = notification.choices[i];
						if (i > 0)
						{
							cachedChoiceStyle.normal.textColor = new Color(0.5f, 0.5f, 0.5f, num6);
							GUI.Label(new Rect(num7, num3, 40f, 22f), "  •  ", cachedChoiceStyle);
							num7 += 32f;
						}
						cachedChoiceStyle.normal.textColor = new Color(0f, 0f, 0f, num6 * 0.7f);
						GUI.Label(new Rect(num7 + 1f, num3 + 1f, 280f, 22f), tuple.Item1, cachedChoiceStyle);
						cachedChoiceStyle.normal.textColor = GetRarityColor(tuple.Item2, num6);
						GUI.Label(new Rect(num7, num3, 280f, 22f), tuple.Item1, cachedChoiceStyle);
						num7 += (float)(tuple.Item1.Length * 8 + 10);
					}
					num3 += 22f;
				}
				num3 += 12f;
			}
		}

		private Color GetRarityColor(string rarity, float alpha)
		{
			//IL_019e: 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_0104: 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)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: 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_0188: Unknown result type (might be due to invalid IL or missing references)
			return (Color)(rarity switch
			{
				"Common" => new Color(0.4f, 1f, 0.4f, alpha), 
				"Uncommon" => new Color(0.3f, 0.7f, 1f, alpha), 
				"Rare" => new Color(0.8f, 0.4f, 1f, alpha), 
				"Epic" => new Color(1f, 0.3f, 0.3f, alpha), 
				"Legendary" => new Color(1f, 0.9f, 0.2f, alpha), 
				"New" => new Color(1f, 1f, 1f, alpha), 
				"NotInList" => new Color(0.5f, 0.5f, 0.5f, alpha), 
				_ => new Color(0.5f, 0.5f, 0.5f, alpha), 
			});
		}

		public void ClearNotifications()
		{
			notifications.Clear();
			ManualLogSource obj = log;
			if (obj != null)
			{
				obj.LogInfo((object)"Notifications cleared");
			}
		}
	}
}
namespace AutoUpgradeMod.Models
{
	[Serializable]
	public class PriorityItem
	{
		public string itemName;

		public bool isWeapon;

		public int maxLevel;

		public string TypeLabel
		{
			get
			{
				if (!isWeapon)
				{
					return "T";
				}
				return "W";
			}
		}

		public string MaxLevelDisplay
		{
			get
			{
				if (maxLevel != -1)
				{
					return maxLevel.ToString();
				}
				return "∞";
			}
		}

		public PriorityItem(string name, bool weapon, int max)
		{
			itemName = name;
			isWeapon = weapon;
			maxLevel = max;
		}
	}
}
namespace AutoUpgradeMod.Core
{
	public static class AutoSelector
	{
		private static ManualLogSource log;

		public static void Initialize(ManualLogSource logger)
		{
			log = logger;
			log.LogInfo((object)"AutoSelector initialized");
		}

		public static bool ProcessAutoSelection(UpgradePicker picker)
		{
			//IL_040c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Expected O, but got Unknown
			//IL_0396: Unknown result type (might be due to invalid IL or missing references)
			//IL_039d: Expected O, but got Unknown
			//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d3: Expected O, but got Unknown
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Expected O, but got Unknown
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Expected O, but got Unknown
			//IL_0351: Unknown result type (might be due to invalid IL or missing references)
			bool flag2 = default(bool);
			try
			{
				if ((Object)(object)picker == (Object)null)
				{
					log.LogError((object)"AutoSelector: Picker is null, cannot process selection");
					return true;
				}
				Il2CppReferenceArray<UpgradeButton> buttons = picker.buttons;
				if (buttons == null || ((Il2CppArrayBase<UpgradeButton>)(object)buttons).Count == 0)
				{
					log.LogWarning((object)"AutoSelector: No upgrade buttons available");
					return true;
				}
				List<PriorityItem> priorityList = PriorityManager.GetPriorityList();
				if (priorityList.Count == 0)
				{
					log.LogInfo((object)"AutoSelector: Priority list is empty - skipping auto-selection");
					EnsureLevelupScreenVisible(picker);
					return true;
				}
				List<(int, string, UpgradeButton, int)> list = new List<(int, string, UpgradeButton, int)>();
				List<(int, string, UpgradeButton, int, bool)> list2 = new List<(int, string, UpgradeButton, int, bool)>();
				BepInExInfoLogInterpolatedStringHandler val2;
				for (int i = 0; i < priorityList.Count; i++)
				{
					PriorityItem priorityItem = priorityList[i];
					string itemName = priorityItem.itemName;
					int maxLevel = priorityItem.maxLevel;
					UpgradeButton val = IsItemAvailable(picker, itemName);
					if (!((Object)(object)val == (Object)null))
					{
						int currentLevel = GetCurrentLevel(picker, itemName);
						bool flag = IsAtMaxLevel(currentLevel, maxLevel);
						ERarity rarity = val.rarity;
						string text = ((object)(ERarity)(ref rarity)).ToString();
						if (text == "New")
						{
							flag = false;
						}
						int rarityRank = GetRarityRank(text);
						list2.Add((i, itemName, val, rarityRank, flag));
						ManualLogSource obj = log;
						val2 = new BepInExInfoLogInterpolatedStringHandler(40, 5, ref flag2);
						if (flag2)
						{
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("  Found: ");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(itemName);
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" (Rarity=");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(text);
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(", Lv=");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(currentLevel);
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(", MaxLv=");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(maxLevel);
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(", AtMax=");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<bool>(flag);
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(")");
						}
						obj.LogInfo(val2);
					}
				}
				if (list2.Count == 0)
				{
					log.LogInfo((object)"No priority items in choices - manual selection required");
					EnsureLevelupScreenVisible(picker);
					return true;
				}
				List<(int, string, UpgradeButton, int, bool)> list3 = list2.Where<(int, string, UpgradeButton, int, bool)>(((int priorityIndex, string itemName, UpgradeButton button, int rarityRank, bool atMaxLevel) c) => !c.atMaxLevel).ToList();
				if (list3.Count > 0)
				{
					list = list3.Select<(int, string, UpgradeButton, int, bool), (int, string, UpgradeButton, int)>(((int priorityIndex, string itemName, UpgradeButton button, int rarityRank, bool atMaxLevel) c) => (c.priorityIndex, c.itemName, c.button, c.rarityRank)).ToList();
				}
				else
				{
					list = list2.Select<(int, string, UpgradeButton, int, bool), (int, string, UpgradeButton, int)>(((int priorityIndex, string itemName, UpgradeButton button, int rarityRank, bool atMaxLevel) c) => (c.priorityIndex, c.itemName, c.button, c.rarityRank)).ToList();
					log.LogInfo((object)"All candidates at max level - selecting best anyway");
				}
				int highestRarity = list.Max<(int, string, UpgradeButton, int)>(((int priorityIndex, string itemName, UpgradeButton button, int rarityRank) c) => c.rarityRank);
				(int, string, UpgradeButton, int) tuple = (from c in list.Where<(int, string, UpgradeButton, int)>(((int priorityIndex, string itemName, UpgradeButton button, int rarityRank) c) => c.rarityRank == highestRarity).ToList()
					orderby c.priorityIndex
					select c).First();
				ManualLogSource obj2 = log;
				val2 = new BepInExInfoLogInterpolatedStringHandler(16, 3, ref flag2);
				if (flag2)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Selected: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(tuple.Item2);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" (#");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(tuple.Item1 + 1);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(", ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<ERarity>(tuple.Item3.rarity);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(")");
				}
				obj2.LogInfo(val2);
				SelectUpgrade(picker, tuple.Item3, tuple.Item2);
				return false;
			}
			catch (Exception ex)
			{
				ManualLogSource obj3 = log;
				BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(42, 1, ref flag2);
				if (flag2)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("AutoSelector: ProcessAutoSelection error: ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.Message);
				}
				obj3.LogError(val3);
				ManualLogSource obj4 = log;
				val3 = new BepInExErrorLogInterpolatedStringHandler(13, 1, ref flag2);
				if (flag2)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Stack trace: ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.StackTrace);
				}
				obj4.LogError(val3);
				try
				{
					EnsureLevelupScreenVisible(picker);
				}
				catch (Exception ex2)
				{
					ManualLogSource obj5 = log;
					val3 = new BepInExErrorLogInterpolatedStringHandler(46, 1, ref flag2);
					if (flag2)
					{
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("AutoSelector: Failed to show level-up screen: ");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex2.Message);
					}
					obj5.LogError(val3);
				}
				return true;
			}
		}

		private static int GetRarityRank(string rarity)
		{
			return rarity switch
			{
				"New" => 10, 
				"Common" => 1, 
				"Uncommon" => 2, 
				"Rare" => 3, 
				"Epic" => 4, 
				"Legendary" => 5, 
				_ => 0, 
			};
		}

		private static UpgradeButton IsItemAvailable(UpgradePicker picker, string itemName)
		{
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Expected O, but got Unknown
			try
			{
				if ((Object)(object)picker == (Object)null || picker.buttons == null)
				{
					return null;
				}
				string text = null;
				string text2 = null;
				if (itemName.StartsWith("Tome"))
				{
					text = itemName.Substring(4) + " Tome";
				}
				else if (itemName.StartsWith("Weapon"))
				{
					text2 = itemName.Substring(6);
				}
				foreach (UpgradeButton item in (Il2CppArrayBase<UpgradeButton>)(object)picker.buttons)
				{
					if (!((Object)(object)item == (Object)null) && !item.isItem)
					{
						string upgradeName = GetUpgradeName(item);
						if (upgradeName == itemName)
						{
							return item;
						}
						if (text != null && upgradeName == text)
						{
							return item;
						}
						if (text2 != null && upgradeName == text2)
						{
							return item;
						}
					}
				}
				return null;
			}
			catch (Exception ex)
			{
				ManualLogSource obj = log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(44, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AutoSelector: IsItemAvailable error for '");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(itemName);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("': ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				obj.LogError(val);
				return null;
			}
		}

		private static int GetCurrentLevel(UpgradePicker picker, string itemName)
		{
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Expected O, but got Unknown
			try
			{
				if ((Object)(object)picker == (Object)null || picker.buttons == null)
				{
					return 0;
				}
				string text = null;
				string text2 = null;
				if (itemName.StartsWith("Tome"))
				{
					text = itemName.Substring(4) + " Tome";
				}
				else if (itemName.StartsWith("Weapon"))
				{
					text2 = itemName.Substring(6);
				}
				foreach (UpgradeButton item in (Il2CppArrayBase<UpgradeButton>)(object)picker.buttons)
				{
					if (!((Object)(object)item == (Object)null) && item.upgradable != null)
					{
						string upgradeName = GetUpgradeName(item);
						if (upgradeName == itemName || (text != null && upgradeName == text) || (text2 != null && upgradeName == text2))
						{
							return item.upgradable.GetLevel();
						}
					}
				}
				return 0;
			}
			catch (Exception ex)
			{
				ManualLogSource obj = log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(44, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AutoSelector: GetCurrentLevel error for '");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(itemName);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("': ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				obj.LogError(val);
				return 0;
			}
		}

		private static bool IsAtMaxLevel(int currentLevel, int maxLevel)
		{
			if (maxLevel == -1)
			{
				return false;
			}
			return currentLevel >= maxLevel;
		}

		private static void SelectUpgrade(UpgradePicker picker, UpgradeButton upgrade, string itemName)
		{
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Expected O, but got Unknown
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Expected O, but got Unknown
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Expected O, but got Unknown
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Expected O, but got Unknown
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			bool flag = default(bool);
			try
			{
				if ((Object)(object)upgrade == (Object)null)
				{
					ManualLogSource obj = log;
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(47, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AutoSelector: Cannot select null upgrade for '");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(itemName);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'");
					}
					obj.LogError(val);
					return;
				}
				ERarity rarity = upgrade.rarity;
				string rarity2 = ((object)(ERarity)(ref rarity)).ToString();
				int num = ((upgrade.upgradable != null) ? upgrade.upgradable.GetLevel() : 0);
				int toLevel = num + 1;
				List<(string, string)> list = new List<(string, string)>();
				List<PriorityItem> priorityList = PriorityManager.GetPriorityList();
				try
				{
					foreach (UpgradeButton item2 in (Il2CppArrayBase<UpgradeButton>)(object)picker.buttons)
					{
						if ((Object)(object)item2 == (Object)null || item2.isItem)
						{
							continue;
						}
						string choiceName = GetUpgradeName(item2);
						if (choiceName == "Unknown")
						{
							continue;
						}
						string text = FormatItemName(choiceName);
						object obj2;
						if (!priorityList.Exists((PriorityItem p) => p.itemName == choiceName || (p.itemName.StartsWith("Tome") && p.itemName.Substring(4) + " Tome" == choiceName) || (p.itemName.StartsWith("Weapon") && p.itemName.Substring(6) == choiceName)))
						{
							obj2 = "NotInList";
						}
						else
						{
							rarity = item2.rarity;
							obj2 = ((object)(ERarity)(ref rarity)).ToString();
						}
						string item = (string)obj2;
						if (item2.upgradable != null)
						{
							int level = item2.upgradable.GetLevel();
							if (level > 0)
							{
								text += $" (Lv{level})";
							}
						}
						list.Add((text, item));
					}
				}
				catch (Exception ex)
				{
					ManualLogSource obj3 = log;
					BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(30, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Failed to build choices list: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
					}
					obj3.LogWarning(val2);
				}
				picker.SelectUpgrade(upgrade.upgradable, upgrade.upgradeOffer, upgrade, upgrade.rarity);
				try
				{
					if ((Object)(object)AutoUpgradeUI.Instance != (Object)null)
					{
						string itemName2 = FormatItemName(itemName);
						AutoUpgradeUI.Instance.AddNotificationWithRarity(itemName2, rarity2, num, toLevel, list);
					}
				}
				catch (Exception ex2)
				{
					ManualLogSource obj4 = log;
					BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(29, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Failed to show notification: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex2.Message);
					}
					obj4.LogWarning(val2);
				}
			}
			catch (Exception ex3)
			{
				ManualLogSource obj5 = log;
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(42, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AutoSelector: SelectUpgrade error for '");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(itemName);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("': ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex3.Message);
				}
				obj5.LogError(val);
				ManualLogSource obj6 = log;
				val = new BepInExErrorLogInterpolatedStringHandler(13, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Stack trace: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex3.StackTrace);
				}
				obj6.LogError(val);
				log.LogError((object)"Selection failed - user must select manually");
				try
				{
					EnsureLevelupScreenVisible(picker);
				}
				catch (Exception ex4)
				{
					ManualLogSource obj7 = log;
					val = new BepInExErrorLogInterpolatedStringHandler(46, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AutoSelector: Failed to show level-up screen: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex4.Message);
					}
					obj7.LogError(val);
				}
			}
		}

		private static void EnsureLevelupScreenVisible(UpgradePicker picker)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			try
			{
				if (!((Object)(object)picker == (Object)null))
				{
					LevelupScreen levelupScreen = picker.levelupScreen;
					if ((Object)(object)levelupScreen != (Object)null && !((Component)levelupScreen).gameObject.activeSelf)
					{
						((Component)levelupScreen).gameObject.SetActive(true);
						log.LogInfo((object)"AutoSelector: Re-enabled level-up screen for manual selection");
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource obj = log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(48, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AutoSelector: EnsureLevelupScreenVisible error: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				obj.LogError(val);
			}
		}

		private static string GetUpgradeName(UpgradeButton button)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			try
			{
				if ((Object)(object)button == (Object)null)
				{
					return "Unknown";
				}
				if (button.isItem && (Object)(object)button.itemData != (Object)null)
				{
					return ((UnlockableBase)button.itemData).GetName() ?? "Item";
				}
				if (button.upgradable != null)
				{
					return button.upgradable.GetName() ?? "Upgrade";
				}
			}
			catch (Exception ex)
			{
				ManualLogSource obj = log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(36, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AutoSelector: GetUpgradeName error: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				obj.LogError(val);
			}
			return "Unknown";
		}

		private static bool IsUpgradeOwned(UpgradeButton button)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			try
			{
				if ((Object)(object)button == (Object)null)
				{
					return false;
				}
				if (button.isItem)
				{
					return false;
				}
				if (button.upgradable == null)
				{
					return false;
				}
				return button.upgradable.GetLevel() > 0;
			}
			catch (Exception ex)
			{
				ManualLogSource obj = log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(36, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AutoSelector: IsUpgradeOwned error: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				obj.LogError(val);
				return false;
			}
		}

		private static string FormatItemName(string internalName)
		{
			if (string.IsNullOrEmpty(internalName))
			{
				return internalName;
			}
			if (internalName.StartsWith("Weapon"))
			{
				return internalName.Substring(6);
			}
			if (internalName.StartsWith("Tome"))
			{
				return internalName.Substring(4) + " Tome";
			}
			return internalName;
		}
	}
	public static class ConfigManager
	{
		private class OldSlotData
		{
			public string name;

			public int maxLevel;
		}

		private static ConfigFile config;

		private static ManualLogSource log;

		private static ConfigEntry<string> priorityConfig;

		private const string OLD_WEAPON_SLOTS_KEY = "WeaponSlots";

		private const string OLD_TOME_SLOTS_KEY = "TomeSlots";

		private const string OLD_ACTIVE_WEAPON_SLOTS_KEY = "ActiveWeaponSlots";

		private const string OLD_ACTIVE_TOME_SLOTS_KEY = "ActiveTomeSlots";

		private const string NEW_PRIORITY_KEY = "Priority";

		public static void Initialize(ConfigFile configFile, ManualLogSource logger)
		{
			config = configFile;
			log = logger;
			log.LogInfo((object)"ConfigManager initializing...");
			bool num = MigrateFromOldFormat();
			priorityConfig = config.Bind<string>("Priority", "Priority", "", "Unified priority list format: ItemName:W/T:MaxLevel|ItemName:W/T:MaxLevel|...");
			if (num)
			{
				log.LogInfo((object)"ConfigManager initialized with migration from old format");
			}
			else
			{
				log.LogInfo((object)"ConfigManager initialized");
			}
		}

		public static bool LoadPriorityList()
		{
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Expected O, but got Unknown
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			bool flag = default(bool);
			try
			{
				if (priorityConfig == null)
				{
					log.LogError((object)"Cannot load priority list: ConfigManager not initialized");
					return false;
				}
				string value = priorityConfig.Value;
				if (string.IsNullOrWhiteSpace(value))
				{
					log.LogInfo((object)"Priority config is empty, starting with empty list");
					PriorityManager.SetPriorityList(new List<PriorityItem>());
					return true;
				}
				List<PriorityItem> list = ParseUnifiedFormat(value);
				if (list == null)
				{
					log.LogError((object)"Failed to parse priority list from config");
					return false;
				}
				bool num = PriorityManager.SetPriorityList(list);
				if (num)
				{
					ManualLogSource obj = log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(28, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Loaded priority list: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(list.Count);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" items");
					}
					obj.LogInfo(val);
				}
				else
				{
					log.LogError((object)"Failed to set priority list in PriorityManager");
				}
				return num;
			}
			catch (Exception ex)
			{
				ManualLogSource obj2 = log;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(29, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Error loading priority list: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
				}
				obj2.LogError(val2);
				ManualLogSource obj3 = log;
				val2 = new BepInExErrorLogInterpolatedStringHandler(13, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Stack trace: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.StackTrace);
				}
				obj3.LogError(val2);
				PriorityManager.SetPriorityList(new List<PriorityItem>());
				return false;
			}
		}

		public static bool SavePriorityList()
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Expected O, but got Unknown
			bool flag = default(bool);
			try
			{
				if (priorityConfig == null)
				{
					log.LogError((object)"Cannot save priority list: ConfigManager not initialized");
					return false;
				}
				List<PriorityItem> priorityList = PriorityManager.GetPriorityList();
				string value = SerializeUnifiedFormat(priorityList);
				priorityConfig.Value = value;
				ManualLogSource obj = log;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(27, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Saved priority list: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(priorityList.Count);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" items");
				}
				obj.LogInfo(val);
				return true;
			}
			catch (Exception ex)
			{
				ManualLogSource obj2 = log;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(28, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Error saving priority list: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
				}
				obj2.LogError(val2);
				ManualLogSource obj3 = log;
				val2 = new BepInExErrorLogInterpolatedStringHandler(13, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Stack trace: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.StackTrace);
				}
				obj3.LogError(val2);
				return false;
			}
		}

		private static string SerializeUnifiedFormat(List<PriorityItem> items)
		{
			if (items == null || items.Count == 0)
			{
				return "";
			}
			List<string> list = new List<string>();
			foreach (PriorityItem item in items)
			{
				string value = item.itemName.Replace("|", "\\|").Replace(":", "\\:");
				string value2 = (item.isWeapon ? "W" : "T");
				string value3 = item.maxLevel.ToString();
				list.Add($"{value}:{value2}:{value3}");
			}
			return string.Join("|", list);
		}

		private static List<PriorityItem> ParseUnifiedFormat(string data)
		{
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Expected O, but got Unknown
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Expected O, but got Unknown
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Expected O, but got Unknown
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Expected O, but got Unknown
			bool flag = default(bool);
			try
			{
				List<PriorityItem> list = new List<PriorityItem>();
				if (string.IsNullOrWhiteSpace(data))
				{
					return list;
				}
				foreach (string item in SplitRespectingEscapes(data, '|'))
				{
					if (string.IsNullOrWhiteSpace(item))
					{
						continue;
					}
					List<string> list2 = SplitRespectingEscapes(item, ':');
					if (list2.Count != 3)
					{
						ManualLogSource obj = log;
						BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(58, 2, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Invalid priority entry format (expected 3 parts, got ");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(list2.Count);
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("): '");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(item);
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'");
						}
						obj.LogWarning(val);
						continue;
					}
					string text = list2[0].Replace("\\:", ":").Replace("\\|", "|").Trim();
					string text2 = list2[1].Trim().ToUpper();
					string text3 = list2[2].Trim();
					if (string.IsNullOrWhiteSpace(text))
					{
						ManualLogSource obj2 = log;
						BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(39, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Skipping entry with empty item name: '");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(item);
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'");
						}
						obj2.LogWarning(val);
						continue;
					}
					bool weapon;
					if (text2 == "W")
					{
						weapon = true;
					}
					else
					{
						if (!(text2 == "T"))
						{
							ManualLogSource obj3 = log;
							BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(45, 2, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Invalid item type '");
								((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text2);
								((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' for '");
								((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
								((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' (expected W or T)");
							}
							obj3.LogWarning(val);
							continue;
						}
						weapon = false;
					}
					if (!int.TryParse(text3, out var result))
					{
						ManualLogSource obj4 = log;
						BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(27, 2, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Invalid max level '");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text3);
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' for '");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'");
						}
						obj4.LogWarning(val);
					}
					else if (result < -1 || result == 0 || result > 999)
					{
						ManualLogSource obj5 = log;
						BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(47, 2, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Invalid max level ");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(result);
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" for '");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' (must be -1 or 1-999)");
						}
						obj5.LogWarning(val);
					}
					else
					{
						list.Add(new PriorityItem(text, weapon, result));
					}
				}
				return list;
			}
			catch (Exception ex)
			{
				ManualLogSource obj6 = log;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(30, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Error parsing unified format: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
				}
				obj6.LogError(val2);
				return null;
			}
		}

		private static List<string> SplitRespectingEscapes(string input, char delimiter)
		{
			List<string> list = new List<string>();
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 0; i < input.Length; i++)
			{
				if (input[i] == '\\' && i + 1 < input.Length && input[i + 1] == delimiter)
				{
					stringBuilder.Append('\\');
					stringBuilder.Append(delimiter);
					i++;
				}
				else if (input[i] == delimiter)
				{
					list.Add(stringBuilder.ToString());
					stringBuilder.Clear();
				}
				else
				{
					stringBuilder.Append(input[i]);
				}
			}
			list.Add(stringBuilder.ToString());
			return list;
		}

		private static bool MigrateFromOldFormat()
		{
			//IL_059b: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a2: Expected O, but got Unknown
			//IL_05d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d8: Expected O, but got Unknown
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Expected O, but got Unknown
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Expected O, but got Unknown
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Expected O, but got Unknown
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Expected O, but got Unknown
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Expected O, but got Unknown
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Expected O, but got Unknown
			//IL_048d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0494: Expected O, but got Unknown
			//IL_04fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0504: Expected O, but got Unknown
			//IL_053f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0546: Expected O, but got Unknown
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Expected O, but got Unknown
			//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Expected O, but got Unknown
			bool flag2 = default(bool);
			try
			{
				log.LogInfo((object)"Checking for old config format...");
				if (!string.I