Decompiled source of The Codex v3.0.0

Mods/TheCodex.dll

Decompiled a month 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 HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using TheCodex;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Class1), "The Codex", "3.0", "TheMrEvil", null)]
[assembly: MelonGame("Alvios", "Vellum")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("TheCodex")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+12218b7a83db3f5c39eeafb11cd5bc1208aad717")]
[assembly: AssemblyProduct("TheCodex")]
[assembly: AssemblyTitle("TheCodex")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace TheCodex
{
	public class Class1 : MelonMod
	{
		public enum AbilityTabType
		{
			Primary,
			Secondary,
			Utility,
			Movement,
			Core,
			AllAugments,
			Favorites,
			Tools
		}

		private bool showDropdown;

		private Rect windowRect = new Rect(20f, 20f, 500f, 600f);

		private Vector2 scrollPosition = Vector2.zero;

		private AbilityTabType currentTab;

		private readonly string[] tabNames = new string[8] { "Primary", "Secondary", "Utility", "Movement", "Core", "Augments", "Favorites", "Tools" };

		private string searchText = "";

		private readonly Dictionary<AbilityTabType, string> searchTexts = new Dictionary<AbilityTabType, string>();

		private static readonly Dictionary<PlayerAbilityType, List<AbilityTree>> cachedFullAbilityLists = new Dictionary<PlayerAbilityType, List<AbilityTree>>();

		private static readonly List<AugmentTree> cachedFullCoreList = new List<AugmentTree>();

		private static bool hasInitializedCache = false;

		private static readonly HashSet<string> favorites = new HashSet<string>(StringComparer.Ordinal);

		private static bool favoritesLoaded = false;

		private static MelonPreferences_Category? prefsCategory;

		private static MelonPreferences_Entry<string>? prefsFavoritesEntry;

		private const string PrefsCategoryName = "TheCodex";

		private const string PrefsFavoritesKey = "Favorites";

		private static bool noClipEnabled = false;

		public static bool godModeEnabled = false;

		public static bool blockPlayerAugmentsEnabled = false;

		public static bool infiniteManaEnabled = false;

		private string rerollsInput = string.Empty;

		private int lastAutoFilledRerolls = int.MinValue;

		private string fontPointsInput = string.Empty;

		private int lastAutoFilledFontPoints = int.MinValue;

		public override void OnInitializeMelon()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Expected O, but got Unknown
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Expected O, but got Unknown
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Expected O, but got Unknown
			try
			{
				Harmony val = new Harmony("TheCodex.Patches");
				MethodInfo method = typeof(PlayerHealth).GetMethod("ApplyDamageImmediate", BindingFlags.Instance | BindingFlags.Public);
				if (method != null)
				{
					MethodInfo method2 = typeof(GodModePatches).GetMethod("ApplyDamageImmediatePrefix", BindingFlags.Static | BindingFlags.Public);
					val.Patch((MethodBase)method, new HarmonyMethod(method2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
				else
				{
					MelonLogger.Warning("Could not find PlayerHealth.ApplyDamageImmediate method to patch");
				}
				MethodInfo method3 = typeof(EntityHealth).GetMethod("Die", BindingFlags.Instance | BindingFlags.Public);
				if (method3 != null)
				{
					MethodInfo method4 = typeof(GodModePatches).GetMethod("DiePrefix", BindingFlags.Static | BindingFlags.Public);
					val.Patch((MethodBase)method3, new HarmonyMethod(method4), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
				else
				{
					MelonLogger.Warning("Could not find EntityHealth.Die method to patch");
				}
				Type typeFromHandle = typeof(PlayerControl);
				MethodInfo method5 = typeFromHandle.GetMethod("AddAugment", BindingFlags.Instance | BindingFlags.Public, null, new Type[2]
				{
					typeof(AugmentTree),
					typeof(int)
				}, null);
				if (method5 != null)
				{
					MethodInfo method6 = typeof(AugmentBlockPatches).GetMethod("AddAugmentPrefix", BindingFlags.Static | BindingFlags.Public);
					val.Patch((MethodBase)method5, new HarmonyMethod(method6), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
				else
				{
					MelonLogger.Warning("Could not find PlayerControl.AddAugment(AugmentTree, int) method to patch");
					MethodInfo[] array = (from m in typeFromHandle.GetMethods(BindingFlags.Instance | BindingFlags.Public)
						where m.Name == "AddAugment"
						select m).ToArray();
					MelonLogger.Msg($"Found {array.Length} AddAugment methods:");
					MethodInfo[] array2 = array;
					for (int i = 0; i < array2.Length; i++)
					{
						ParameterInfo[] parameters = array2[i].GetParameters();
						string text = string.Join(", ", parameters.Select((ParameterInfo p) => p.ParameterType.Name));
						MelonLogger.Msg("  AddAugment(" + text + ")");
					}
				}
				try
				{
					Type typeFromHandle2 = typeof(PlayerMana);
					MethodInfo method7 = typeFromHandle2.GetMethod("ConsumeMana", BindingFlags.Instance | BindingFlags.Public, null, new Type[2]
					{
						typeof(float),
						typeof(bool)
					}, null);
					if (method7 != null)
					{
						MethodInfo method8 = typeof(ManaPatches).GetMethod("ConsumeManaPrefix", BindingFlags.Static | BindingFlags.Public);
						val.Patch((MethodBase)method7, new HarmonyMethod(method8), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					}
					else
					{
						MelonLogger.Warning("Could not find PlayerMana.ConsumeMana(float, bool) method to patch");
					}
					MethodInfo method9 = typeFromHandle2.GetMethod("Drain", BindingFlags.Instance | BindingFlags.Public);
					if (method9 != null)
					{
						MethodInfo method10 = typeof(ManaPatches).GetMethod("DrainPrefix", BindingFlags.Static | BindingFlags.Public);
						val.Patch((MethodBase)method9, new HarmonyMethod(method10), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					}
					else
					{
						MelonLogger.Warning("Could not find PlayerMana.Drain method to patch");
					}
				}
				catch (Exception arg)
				{
					MelonLogger.Error($"Failed to apply PlayerMana patches: {arg}");
				}
			}
			catch (Exception arg2)
			{
				MelonLogger.Error($"Failed to apply Harmony patches: {arg2}");
			}
		}

		public override void OnUpdate()
		{
			if (Input.GetKeyDown((KeyCode)61) || Input.GetKeyDown((KeyCode)270))
			{
				showDropdown = !showDropdown;
				if (showDropdown && !hasInitializedCache)
				{
					InitializeAbilityCache();
					InitializeSearchTexts();
				}
				if (showDropdown && !favoritesLoaded)
				{
					LoadFavorites();
				}
			}
			if (showDropdown)
			{
				SetCursorState(unlocked: true);
			}
			ApplyNoClip();
		}

		private void InitializeSearchTexts()
		{
			foreach (AbilityTabType value in Enum.GetValues(typeof(AbilityTabType)))
			{
				if (!searchTexts.ContainsKey(value))
				{
					searchTexts[value] = "";
				}
			}
		}

		private void InitializeAbilityCache()
		{
			//IL_0023: 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_0032: 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)
			try
			{
				MelonLogger.Msg("Initializing ability cache...");
				PlayerAbilityType[] array = new PlayerAbilityType[4];
				RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
				PlayerAbilityType[] array2 = (PlayerAbilityType[])(object)array;
				foreach (PlayerAbilityType val in array2)
				{
					List<AbilityTree> abilitiesForTypeInternal = GetAbilitiesForTypeInternal(val);
					cachedFullAbilityLists[val] = new List<AbilityTree>(abilitiesForTypeInternal);
					MelonLogger.Msg($"Cached {abilitiesForTypeInternal.Count} abilities for type {val}");
				}
				List<AugmentTree> availableCoresInternal = GetAvailableCoresInternal();
				cachedFullCoreList.Clear();
				cachedFullCoreList.AddRange(availableCoresInternal);
				MelonLogger.Msg($"Cached {availableCoresInternal.Count} cores");
				hasInitializedCache = true;
			}
			catch (Exception arg)
			{
				MelonLogger.Error($"Error initializing ability cache: {arg}");
			}
		}

		public override void OnGUI()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Expected O, but got Unknown
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			if (showDropdown)
			{
				GUI.FocusWindow(0);
				GUIStyle val = new GUIStyle(GUI.skin.window);
				val.normal.background = MakeTexture(2, 2, new Color(0.12f, 0.12f, 0.12f, 1f));
				val.hover.background = val.normal.background;
				val.active.background = val.normal.background;
				val.focused.background = val.normal.background;
				val.onNormal.background = val.normal.background;
				val.onHover.background = val.normal.background;
				val.onActive.background = val.normal.background;
				val.onFocused.background = val.normal.background;
				val.normal.textColor = Color.white;
				val.hover.textColor = Color.white;
				val.active.textColor = Color.white;
				val.focused.textColor = Color.white;
				val.onNormal.textColor = Color.white;
				val.onHover.textColor = Color.white;
				val.onActive.textColor = Color.white;
				val.onFocused.textColor = Color.white;
				GUI.depth = 0;
				windowRect = GUILayout.Window(0, windowRect, new WindowFunction(DrawWindow), "The Codex", val, Array.Empty<GUILayoutOption>());
			}
		}

		private void DrawWindow(int windowID)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			GUIStyle val = new GUIStyle(GUI.skin.button);
			val.normal.background = MakeTexture(2, 2, new Color(0.2f, 0.2f, 0.2f, 1f));
			val.normal.textColor = Color.white;
			val.fontSize = 14;
			val.fixedHeight = 30f;
			val.hover.background = MakeTexture(2, 2, new Color(0.3f, 0.3f, 0.3f, 1f));
			val.active.background = val.normal.background;
			GUIStyle val2 = new GUIStyle(val);
			val2.normal.background = MakeTexture(2, 2, new Color(0.4f, 0.4f, 0.4f, 1f));
			val2.normal.textColor = Color.yellow;
			val2.hover.background = val2.normal.background;
			val2.active.background = val2.normal.background;
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			for (int i = 0; i < tabNames.Length; i++)
			{
				AbilityTabType abilityTabType = (AbilityTabType)i;
				GUIStyle val3 = ((currentTab == abilityTabType) ? val2 : val);
				if (GUILayout.Button(tabNames[i], val3, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }))
				{
					currentTab = abilityTabType;
				}
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(10f);
			if (currentTab != AbilityTabType.Tools)
			{
				DrawSearchBar();
				GUILayout.Space(5f);
			}
			scrollPosition = GUILayout.BeginScrollView(scrollPosition, Array.Empty<GUILayoutOption>());
			switch (currentTab)
			{
			case AbilityTabType.Primary:
				DrawAbilityTab((PlayerAbilityType)0, "Primary Abilities");
				break;
			case AbilityTabType.Secondary:
				DrawAbilityTab((PlayerAbilityType)1, "Secondary Abilities");
				break;
			case AbilityTabType.Utility:
				DrawAbilityTab((PlayerAbilityType)2, "Utility Abilities");
				break;
			case AbilityTabType.Movement:
				DrawAbilityTab((PlayerAbilityType)3, "Movement Abilities");
				break;
			case AbilityTabType.Core:
				DrawCoreTab();
				break;
			case AbilityTabType.AllAugments:
				DrawAllAugmentsTab();
				break;
			case AbilityTabType.Favorites:
				DrawFavoritesTab();
				break;
			case AbilityTabType.Tools:
				DrawToolsTab();
				break;
			}
			GUILayout.EndScrollView();
			GUI.DragWindow();
		}

		private void DrawSearchBar()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Expected O, but got Unknown
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			GUIStyle val = new GUIStyle(GUI.skin.textField);
			val.normal.background = MakeTexture(2, 2, new Color(0.15f, 0.15f, 0.15f, 1f));
			val.normal.textColor = Color.white;
			val.fontSize = 14;
			val.fixedHeight = 25f;
			GUIStyle val2 = new GUIStyle(GUI.skin.label);
			val2.normal.textColor = Color.white;
			val2.fontSize = 12;
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Search:", val2, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) });
			string text = (searchTexts.ContainsKey(currentTab) ? searchTexts[currentTab] : "");
			string text2 = GUILayout.TextField(text, val, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			if (text2 != text)
			{
				searchTexts[currentTab] = text2;
			}
			GUIStyle val3 = new GUIStyle(GUI.skin.button);
			val3.normal.background = MakeTexture(2, 2, new Color(0.3f, 0.1f, 0.1f, 1f));
			val3.normal.textColor = Color.white;
			val3.fontSize = 12;
			val3.fixedHeight = 25f;
			val3.hover.background = MakeTexture(2, 2, new Color(0.4f, 0.2f, 0.2f, 1f));
			if (GUILayout.Button("Clear", val3, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) }))
			{
				searchTexts[currentTab] = "";
			}
			GUILayout.EndHorizontal();
		}

		private GUIStyle BuildItemButtonStyle()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			GUIStyle val = new GUIStyle(GUI.skin.button);
			val.normal.background = MakeTexture(2, 2, new Color(0.25f, 0.25f, 0.25f, 1f));
			val.normal.textColor = Color.white;
			val.fontSize = 16;
			val.fixedHeight = 40f;
			val.hover.background = MakeTexture(2, 2, new Color(0.35f, 0.35f, 0.35f, 1f));
			val.active.background = val.normal.background;
			return val;
		}

		private GUIStyle BuildStarButtonStyle(bool isOn)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(GUI.skin.button)
			{
				fontSize = 18,
				fixedWidth = 36f,
				fixedHeight = 40f,
				alignment = (TextAnchor)4
			};
			val.normal.textColor = (isOn ? Color.yellow : Color.white);
			val.hover.textColor = Color.yellow;
			Texture2D background = MakeTexture(2, 2, new Color(0.18f, 0.18f, 0.18f, 1f));
			val.normal.background = background;
			val.hover.background = background;
			val.active.background = background;
			return val;
		}

		private void DrawAbilityTab(PlayerAbilityType abilityType, string tabTitle)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			GUIStyle val = new GUIStyle(GUI.skin.label);
			val.fontSize = 18;
			val.normal.textColor = Color.white;
			val.fontStyle = (FontStyle)1;
			GUILayout.Label(tabTitle, val, Array.Empty<GUILayoutOption>());
			GUILayout.Space(10f);
			AbilityTree currentAbility = GetCurrentAbility(abilityType);
			if ((Object)(object)currentAbility != (Object)null)
			{
				GUIStyle val2 = new GUIStyle(GUI.skin.box);
				val2.normal.background = MakeTexture(2, 2, new Color(0.1f, 0.3f, 0.1f, 1f));
				val2.normal.textColor = Color.green;
				val2.fontSize = 14;
				GUILayout.BeginVertical(val2, Array.Empty<GUILayoutOption>());
				GUILayout.Label("Currently Equipped: " + currentAbility.Root.Name, val2, Array.Empty<GUILayoutOption>());
				GUILayout.EndVertical();
				GUILayout.Space(10f);
			}
			List<AbilityTree> filteredAbilities = GetFilteredAbilities(abilityType);
			if (filteredAbilities.Count == 0)
			{
				string text = (searchTexts.ContainsKey(currentTab) ? searchTexts[currentTab] : "");
				if (!string.IsNullOrEmpty(text))
				{
					GUILayout.Label("No abilities found matching '" + text + "'.", GUI.skin.label, Array.Empty<GUILayoutOption>());
				}
				else
				{
					GUILayout.Label("No abilities available for this type.", GUI.skin.label, Array.Empty<GUILayoutOption>());
				}
				return;
			}
			GUIStyle val3 = BuildItemButtonStyle();
			foreach (AbilityTree item in filteredAbilities)
			{
				string text2 = item.Root.Name;
				bool flag = (Object)(object)currentAbility != (Object)null && ((GraphTree)currentAbility).ID == ((GraphTree)item).ID;
				bool flag2 = IsFavoriteAbility(abilityType, item);
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (GUILayout.Button(flag2 ? "★" : "☆", BuildStarButtonStyle(flag2), Array.Empty<GUILayoutOption>()))
				{
					ToggleFavoriteAbility(abilityType, item);
				}
				if (flag)
				{
					val3.normal.textColor = Color.green;
				}
				else
				{
					val3.normal.textColor = Color.white;
				}
				if (flag)
				{
					text2 += " (Equipped)";
				}
				if (GUILayout.Button(text2, val3, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }) && !flag)
				{
					EquipAbility(abilityType, item);
				}
				GUILayout.EndHorizontal();
			}
		}

		private void DrawCoreTab()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_001e: 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_006d: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			GUIStyle val = new GUIStyle(GUI.skin.label);
			val.fontSize = 18;
			val.normal.textColor = Color.white;
			val.fontStyle = (FontStyle)1;
			GUILayout.Label("Core Selection", val, Array.Empty<GUILayoutOption>());
			GUILayout.Space(10f);
			AugmentTree currentCore = GetCurrentCore();
			if ((Object)(object)currentCore != (Object)null)
			{
				GUIStyle val2 = new GUIStyle(GUI.skin.box);
				val2.normal.background = MakeTexture(2, 2, new Color(0.1f, 0.3f, 0.1f, 1f));
				val2.normal.textColor = Color.green;
				val2.fontSize = 14;
				GUILayout.BeginVertical(val2, Array.Empty<GUILayoutOption>());
				GUILayout.Label("Currently Equipped: " + currentCore.Root.Name, val2, Array.Empty<GUILayoutOption>());
				GUILayout.EndVertical();
				GUILayout.Space(10f);
			}
			List<AugmentTree> filteredCores = GetFilteredCores();
			if (filteredCores.Count == 0)
			{
				string text = (searchTexts.ContainsKey(currentTab) ? searchTexts[currentTab] : "");
				if (!string.IsNullOrEmpty(text))
				{
					GUILayout.Label("No cores found matching '" + text + "'.", GUI.skin.label, Array.Empty<GUILayoutOption>());
				}
				else
				{
					GUILayout.Label("No cores available.", GUI.skin.label, Array.Empty<GUILayoutOption>());
				}
				return;
			}
			GUIStyle val3 = BuildItemButtonStyle();
			foreach (AugmentTree item in filteredCores)
			{
				string text2 = item.Root.Name;
				bool flag = (Object)(object)currentCore != (Object)null && ((GraphTree)currentCore).ID == ((GraphTree)item).ID;
				bool flag2 = IsFavoriteCore(item);
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (GUILayout.Button(flag2 ? "★" : "☆", BuildStarButtonStyle(flag2), Array.Empty<GUILayoutOption>()))
				{
					ToggleFavoriteCore(item);
				}
				if (flag)
				{
					val3.normal.textColor = Color.green;
				}
				else
				{
					val3.normal.textColor = Color.white;
				}
				if (flag)
				{
					text2 += " (Equipped)";
				}
				if (GUILayout.Button(text2, val3, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }) && !flag)
				{
					EquipCore(item);
				}
				GUILayout.EndHorizontal();
			}
		}

		private void DrawAllAugmentsTab()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_001e: 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_0059: Expected O, but got Unknown
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			GUIStyle val = new GUIStyle(GUI.skin.label);
			val.fontSize = 18;
			val.normal.textColor = Color.white;
			val.fontStyle = (FontStyle)1;
			GUILayout.Label("All Augments", val, Array.Empty<GUILayoutOption>());
			GUILayout.Space(10f);
			GUIStyle val2 = new GUIStyle(GUI.skin.button);
			val2.normal.background = MakeTexture(2, 2, new Color(0.25f, 0.25f, 0.25f, 1f));
			val2.normal.textColor = Color.white;
			val2.fontSize = 16;
			val2.fixedHeight = 35f;
			val2.hover.background = MakeTexture(2, 2, new Color(0.35f, 0.35f, 0.35f, 1f));
			val2.active.background = val2.normal.background;
			List<AugmentTree> filteredAugments = GetFilteredAugments();
			if (filteredAugments.Count == 0)
			{
				string text = (searchTexts.ContainsKey(currentTab) ? searchTexts[currentTab] : "");
				if (!string.IsNullOrEmpty(text))
				{
					GUILayout.Label("No augments found matching '" + text + "'.", GUI.skin.label, Array.Empty<GUILayoutOption>());
				}
				else
				{
					GUILayout.Label("No augments available.", GUI.skin.label, Array.Empty<GUILayoutOption>());
				}
				return;
			}
			foreach (AugmentTree item in filteredAugments)
			{
				string text2 = item.Root?.Name ?? "Unnamed Augment";
				bool flag = IsFavoriteAugment(item);
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (GUILayout.Button(flag ? "★" : "☆", BuildStarButtonStyle(flag), Array.Empty<GUILayoutOption>()))
				{
					ToggleFavoriteAugment(item);
				}
				if (GUILayout.Button(text2, val2, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }))
				{
					MelonLogger.Msg("Adding augment: " + text2 + " (ID: " + ((GraphTree)item).ID + ")");
					AddAugment(item);
				}
				GUILayout.EndHorizontal();
			}
		}

		private void DrawFavoritesTab()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Expected O, but got Unknown
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Expected O, but got Unknown
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Expected O, but got Unknown
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			GUIStyle val = new GUIStyle(GUI.skin.label);
			val.fontSize = 18;
			val.normal.textColor = Color.yellow;
			val.fontStyle = (FontStyle)1;
			GUILayout.Label("Favorites", val, Array.Empty<GUILayoutOption>());
			GUILayout.Space(10f);
			string filter = (searchTexts.ContainsKey(AbilityTabType.Favorites) ? searchTexts[AbilityTabType.Favorites] : "");
			DrawFavAbilitySection((PlayerAbilityType)0, "Primary Abilities");
			DrawFavAbilitySection((PlayerAbilityType)1, "Secondary Abilities");
			DrawFavAbilitySection((PlayerAbilityType)2, "Utility Abilities");
			DrawFavAbilitySection((PlayerAbilityType)3, "Movement Abilities");
			List<AugmentTree> list = (from c in GetAvailableCores()
				where IsFavoriteCore(c) && HasFilter(c.Root.Name)
				select c).ToList();
			if (list.Count > 0)
			{
				GUIStyle val2 = new GUIStyle(GUI.skin.label)
				{
					fontSize = 16,
					fontStyle = (FontStyle)1
				};
				val2.normal.textColor = Color.white;
				GUILayout.Label("Cores", val2, Array.Empty<GUILayoutOption>());
				AugmentTree currentCore = GetCurrentCore();
				GUIStyle val3 = BuildItemButtonStyle();
				foreach (AugmentTree item in list)
				{
					string text = item.Root.Name;
					bool flag = (Object)(object)currentCore != (Object)null && ((GraphTree)currentCore).ID == ((GraphTree)item).ID;
					GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
					if (GUILayout.Button("★", BuildStarButtonStyle(isOn: true), Array.Empty<GUILayoutOption>()))
					{
						ToggleFavoriteCore(item);
					}
					val3.normal.textColor = (flag ? Color.green : Color.white);
					if (flag)
					{
						text += " (Equipped)";
					}
					if (GUILayout.Button(text, val3, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }) && !flag)
					{
						EquipCore(item);
					}
					GUILayout.EndHorizontal();
				}
				GUILayout.Space(6f);
			}
			List<AugmentTree> list2 = (from a in GetAddableAugmentTrees()
				where IsFavoriteAugment(a) && HasFilter(a.Root.Name)
				select a).ToList();
			if (list2.Count <= 0)
			{
				return;
			}
			GUIStyle val4 = new GUIStyle(GUI.skin.label)
			{
				fontSize = 16,
				fontStyle = (FontStyle)1
			};
			val4.normal.textColor = Color.white;
			GUILayout.Label("Augments", val4, Array.Empty<GUILayoutOption>());
			GUIStyle val5 = new GUIStyle(GUI.skin.button);
			val5.normal.background = MakeTexture(2, 2, new Color(0.25f, 0.25f, 0.25f, 1f));
			val5.normal.textColor = Color.white;
			val5.fontSize = 16;
			val5.fixedHeight = 35f;
			val5.hover.background = MakeTexture(2, 2, new Color(0.35f, 0.35f, 0.35f, 1f));
			val5.active.background = val5.normal.background;
			foreach (AugmentTree item2 in list2)
			{
				string text2 = item2.Root?.Name ?? "Unnamed Augment";
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (GUILayout.Button("★", BuildStarButtonStyle(isOn: true), Array.Empty<GUILayoutOption>()))
				{
					ToggleFavoriteAugment(item2);
				}
				if (GUILayout.Button(text2, val5, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }))
				{
					MelonLogger.Msg("Adding augment: " + text2 + " (ID: " + ((GraphTree)item2).ID + ")");
					AddAugment(item2);
				}
				GUILayout.EndHorizontal();
			}
			void DrawFavAbilitySection(PlayerAbilityType type, string title)
			{
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0054: 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_0064: Expected O, but got Unknown
				//IL_006a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0087: Unknown result type (might be due to invalid IL or missing references)
				//IL_010b: 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_0122: Unknown result type (might be due to invalid IL or missing references)
				//IL_016a: Unknown result type (might be due to invalid IL or missing references)
				List<AbilityTree> list3 = (from a in GetAbilitiesForType(type)
					where IsFavoriteAbility(type, a) && HasFilter(a.Root.Name)
					select a).ToList();
				if (list3.Count != 0)
				{
					GUIStyle val6 = new GUIStyle(GUI.skin.label)
					{
						fontSize = 16,
						fontStyle = (FontStyle)1
					};
					val6.normal.textColor = Color.white;
					GUILayout.Label(title, val6, Array.Empty<GUILayoutOption>());
					AbilityTree currentAbility = GetCurrentAbility(type);
					GUIStyle val7 = BuildItemButtonStyle();
					foreach (AbilityTree item3 in list3)
					{
						string text3 = item3.Root.Name;
						bool flag2 = (Object)(object)currentAbility != (Object)null && ((GraphTree)currentAbility).ID == ((GraphTree)item3).ID;
						GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
						if (GUILayout.Button("★", BuildStarButtonStyle(isOn: true), Array.Empty<GUILayoutOption>()))
						{
							ToggleFavoriteAbility(type, item3);
						}
						val7.normal.textColor = (flag2 ? Color.green : Color.white);
						if (flag2)
						{
							text3 += " (Equipped)";
						}
						if (GUILayout.Button(text3, val7, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }) && !flag2)
						{
							EquipAbility(type, item3);
						}
						GUILayout.EndHorizontal();
					}
					GUILayout.Space(6f);
				}
			}
			bool HasFilter(string name)
			{
				if (!string.IsNullOrEmpty(filter))
				{
					return (name?.IndexOf(filter, StringComparison.OrdinalIgnoreCase) ?? (-1)) >= 0;
				}
				return true;
			}
		}

		private void DrawToolsTab()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Expected O, but got Unknown
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Expected O, but got Unknown
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Expected O, but got Unknown
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			GUIStyle val = new GUIStyle(GUI.skin.label);
			val.fontSize = 18;
			val.normal.textColor = Color.white;
			val.fontStyle = (FontStyle)1;
			GUIStyle val2 = new GUIStyle(GUI.skin.toggle);
			val2.normal.textColor = Color.white;
			val2.fontSize = 14;
			GUILayout.Label("Tools", val, Array.Empty<GUILayoutOption>());
			GUILayout.Space(10f);
			noClipEnabled = GUILayout.Toggle(noClipEnabled, "No Clip", val2, Array.Empty<GUILayoutOption>());
			godModeEnabled = GUILayout.Toggle(godModeEnabled, "God Mode", val2, Array.Empty<GUILayoutOption>());
			infiniteManaEnabled = GUILayout.Toggle(infiniteManaEnabled, "Infinite Mana", val2, Array.Empty<GUILayoutOption>());
			blockPlayerAugmentsEnabled = GUILayout.Toggle(blockPlayerAugmentsEnabled, "Block Player Pages", val2, Array.Empty<GUILayoutOption>());
			GUILayout.Space(10f);
			try
			{
				int num = 0;
				int num2 = 0;
				if ((Object)(object)PlayerControl.myInstance != (Object)null)
				{
					num = (int)((EntityControl)PlayerControl.myInstance).GetPassiveMod((EntityValue)392, 0f);
					num2 = num - PlayerChoicePanel.RerollsUsed;
				}
				string text = "RerollsInputField";
				if (!(GUI.GetNameOfFocusedControl() == text) && num2 != lastAutoFilledRerolls)
				{
					rerollsInput = num2.ToString();
					lastAutoFilledRerolls = num2;
				}
				GUIStyle val3 = new GUIStyle(GUI.skin.label);
				val3.normal.textColor = Color.white;
				val3.fontSize = 14;
				GUIStyle val4 = new GUIStyle(GUI.skin.textField);
				val4.normal.background = MakeTexture(2, 2, new Color(0.15f, 0.15f, 0.15f, 1f));
				val4.normal.textColor = Color.white;
				val4.fontSize = 14;
				val4.fixedHeight = 25f;
				GUIStyle val5 = new GUIStyle(GUI.skin.button);
				val5.normal.background = MakeTexture(2, 2, new Color(0.2f, 0.3f, 0.2f, 1f));
				val5.normal.textColor = Color.white;
				val5.fontSize = 14;
				val5.fixedHeight = 25f;
				val5.hover.background = MakeTexture(2, 2, new Color(0.25f, 0.4f, 0.25f, 1f));
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUILayout.Label("Rerolls:", val3, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) });
				GUI.SetNextControlName(text);
				rerollsInput = GUILayout.TextField(rerollsInput ?? string.Empty, val4, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
				if (GUILayout.Button("Apply", val5, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) }))
				{
					if (int.TryParse(rerollsInput, out var result))
					{
						PlayerChoicePanel.RerollsUsed = num - result;
						lastAutoFilledRerolls = result;
					}
					else
					{
						MelonLogger.Warning("Invalid rerolls input: '" + rerollsInput + "'");
					}
				}
				GUILayout.EndHorizontal();
				try
				{
					int num3 = 0;
					if ((Object)(object)InkManager.instance != (Object)null)
					{
						num3 = InkManager.MyShards;
					}
					string text2 = "FontPointsInputField";
					if (!(GUI.GetNameOfFocusedControl() == text2) && num3 != lastAutoFilledFontPoints)
					{
						fontPointsInput = num3.ToString();
						lastAutoFilledFontPoints = num3;
					}
					GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
					GUILayout.Label("Font Points:", val3, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(90f) });
					GUI.SetNextControlName(text2);
					fontPointsInput = GUILayout.TextField(fontPointsInput ?? string.Empty, val4, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
					if (GUILayout.Button("Apply", val5, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) }))
					{
						if (int.TryParse(fontPointsInput, out var result2))
						{
							if (result2 < 0)
							{
								result2 = 0;
							}
							int num4 = result2 - num3;
							if (num4 != 0)
							{
								if ((Object)(object)InkManager.instance != (Object)null)
								{
									try
									{
										InkManager.instance.AddInk(num4);
										lastAutoFilledFontPoints = result2;
									}
									catch (Exception ex)
									{
										MelonLogger.Warning("Failed to apply font points change: " + ex.Message);
									}
								}
								else
								{
									MelonLogger.Warning("InkManager.instance is null - cannot change font points");
								}
							}
						}
						else
						{
							MelonLogger.Warning("Invalid font points input: '" + fontPointsInput + "'");
						}
					}
					GUILayout.EndHorizontal();
				}
				catch (Exception ex2)
				{
					MelonLogger.Warning("Font points editor error: " + ex2.Message);
				}
			}
			catch (Exception ex3)
			{
				MelonLogger.Warning("Rerolls editor error: " + ex3.Message);
			}
		}

		private void ApplyNoClip()
		{
			if ((Object)(object)PlayerControl.myInstance == (Object)null)
			{
				return;
			}
			try
			{
				Rigidbody component = ((Component)PlayerControl.myInstance).GetComponent<Rigidbody>();
				Collider[] componentsInChildren = ((Component)PlayerControl.myInstance).GetComponentsInChildren<Collider>();
				Collider[] array;
				if (noClipEnabled)
				{
					if ((Object)(object)component != (Object)null)
					{
						component.isKinematic = true;
					}
					array = componentsInChildren;
					foreach (Collider val in array)
					{
						if ((Object)(object)val != (Object)null)
						{
							val.isTrigger = true;
						}
					}
					return;
				}
				if ((Object)(object)component != (Object)null)
				{
					component.isKinematic = false;
				}
				array = componentsInChildren;
				foreach (Collider val2 in array)
				{
					if ((Object)(object)val2 != (Object)null)
					{
						val2.isTrigger = false;
					}
				}
			}
			catch (Exception arg)
			{
				MelonLogger.Error($"Error applying no clip: {arg}");
			}
		}

		private List<AbilityTree> GetFilteredAbilities(PlayerAbilityType abilityType)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			List<AbilityTree> abilitiesForType = GetAbilitiesForType(abilityType);
			string searchText = (searchTexts.ContainsKey(currentTab) ? searchTexts[currentTab] : "");
			if (string.IsNullOrEmpty(searchText))
			{
				return abilitiesForType;
			}
			return abilitiesForType.Where(delegate(AbilityTree ability)
			{
				AbilityRootNode root = ability.Root;
				return ((root != null) ? root.Name : null) != null && ability.Root.Name.IndexOf(searchText, StringComparison.OrdinalIgnoreCase) >= 0;
			}).ToList();
		}

		private List<AugmentTree> GetFilteredCores()
		{
			List<AugmentTree> availableCores = GetAvailableCores();
			string searchText = (searchTexts.ContainsKey(currentTab) ? searchTexts[currentTab] : "");
			if (string.IsNullOrEmpty(searchText))
			{
				return availableCores;
			}
			return availableCores.Where((AugmentTree core) => core.Root?.Name != null && core.Root.Name.IndexOf(searchText, StringComparison.OrdinalIgnoreCase) >= 0).ToList();
		}

		private List<AugmentTree> GetFilteredAugments()
		{
			List<AugmentTree> addableAugmentTrees = GetAddableAugmentTrees();
			string searchText = (searchTexts.ContainsKey(currentTab) ? searchTexts[currentTab] : "");
			if (string.IsNullOrEmpty(searchText))
			{
				return addableAugmentTrees;
			}
			return addableAugmentTrees.Where((AugmentTree augment) => augment.Root?.Name != null && augment.Root.Name.IndexOf(searchText, StringComparison.OrdinalIgnoreCase) >= 0).ToList();
		}

		private void AddAugment(AugmentTree augmentTree)
		{
			try
			{
				if ((Object)(object)PlayerControl.myInstance != (Object)null)
				{
					MelonLogger.Msg("Adding augment: " + (augmentTree.Root?.Name ?? "Unnamed") + " (ID: " + ((GraphTree)augmentTree).ID + ")");
					((EntityControl)PlayerControl.myInstance).AddAugment(augmentTree, 1);
					MelonLogger.Msg("Successfully added augment: " + (augmentTree.Root?.Name ?? "Unnamed"));
				}
				else
				{
					MelonLogger.Error("PlayerControl.myInstance is null - cannot add augment");
				}
			}
			catch (Exception arg)
			{
				MelonLogger.Error(string.Format("Error adding augment {0}: {1}", augmentTree.Root?.Name ?? "Unnamed", arg));
			}
		}

		private List<AugmentTree> GetAddableAugmentTrees()
		{
			List<AugmentTree> list = new List<AugmentTree>();
			try
			{
				List<AugmentTree> allAugments = GraphDB.GetAllAugments((ModType)0);
				if (allAugments != null)
				{
					foreach (AugmentTree item in allAugments)
					{
						if ((Object)(object)item != (Object)null)
						{
							list.Add(item);
						}
					}
				}
			}
			catch (Exception arg)
			{
				MelonLogger.Error($"Error getting augment trees: {arg}");
			}
			return list.OrderBy<AugmentTree, string>((AugmentTree a) => a.Root?.Name ?? "zzz_Unnamed", StringComparer.OrdinalIgnoreCase).ToList();
		}

		private List<AbilityTree> GetAbilitiesForType(PlayerAbilityType abilityType)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			if (hasInitializedCache && cachedFullAbilityLists.ContainsKey(abilityType))
			{
				return cachedFullAbilityLists[abilityType];
			}
			return GetAbilitiesForTypeInternal(abilityType);
		}

		private List<AbilityTree> GetAbilitiesForTypeInternal(PlayerAbilityType abilityType)
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//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)
			List<AbilityTree> list = new List<AbilityTree>();
			try
			{
				List<AbilityTree> playerAbilities = GraphDB.GetPlayerAbilities(abilityType);
				if (playerAbilities != null)
				{
					foreach (AbilityTree item in playerAbilities)
					{
						if (item != null && item.Root?.PlrAbilityType == (PlayerAbilityType?)abilityType && item.Root.Name != null)
						{
							list.Add(item);
						}
					}
				}
			}
			catch (Exception arg)
			{
				MelonLogger.Error($"Error getting abilities for type {abilityType}: {arg}");
			}
			return list.OrderBy((AbilityTree a) => a.Root.Name).ToList();
		}

		private List<AugmentTree> GetAvailableCores()
		{
			if (hasInitializedCache && cachedFullCoreList.Count > 0)
			{
				return cachedFullCoreList;
			}
			return GetAvailableCoresInternal();
		}

		private List<AugmentTree> GetAvailableCoresInternal()
		{
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			List<AugmentTree> list = new List<AugmentTree>();
			try
			{
				Type typeFromHandle = typeof(PlayerDB);
				FieldInfo field = typeFromHandle.GetField("instance", BindingFlags.Static | BindingFlags.NonPublic);
				if (field != null)
				{
					object value = field.GetValue(null);
					if (value != null)
					{
						FieldInfo field2 = typeFromHandle.GetField("Cores", BindingFlags.Instance | BindingFlags.Public);
						if (field2 != null && field2.GetValue(value) is IEnumerable<object> enumerable)
						{
							foreach (object item in enumerable)
							{
								FieldInfo field3 = item.GetType().GetField("core", BindingFlags.Instance | BindingFlags.Public);
								FieldInfo field4 = item.GetType().GetField("color", BindingFlags.Instance | BindingFlags.Public);
								if (field3 != null && field4 != null)
								{
									object? value2 = field3.GetValue(item);
									AugmentTree val = (AugmentTree)((value2 is AugmentTree) ? value2 : null);
									object value3 = field4.GetValue(item);
									if ((Object)(object)val != (Object)null)
									{
										list.Add(val);
										MelonLogger.Msg($"Found core: {val.Root.Name} (Color: {value3})");
									}
								}
							}
						}
					}
				}
				if (list.Count == 0)
				{
					MelonLogger.Msg("Reflection approach failed, trying static method approach...");
					MagicColor[] array = new MagicColor[8];
					RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
					MagicColor[] array2 = (MagicColor[])(object)array;
					foreach (MagicColor val2 in array2)
					{
						try
						{
							CoreDisplay core = PlayerDB.GetCore(val2);
							if ((Object)(object)core?.core != (Object)null)
							{
								list.Add(core.core);
								MelonLogger.Msg($"Found core via static method: {core.core.Root.Name} (Color: {val2})");
							}
						}
						catch (Exception ex)
						{
							MelonLogger.Warning($"Failed to get core for color {val2}: {ex.Message}");
						}
					}
				}
			}
			catch (Exception arg)
			{
				MelonLogger.Error($"Error getting available cores: {arg}");
			}
			return (from c in list
				group c by ((GraphTree)c).ID into g
				select g.First() into c
				orderby c.Root.Name
				select c).ToList();
		}

		private AbilityTree? GetCurrentAbility(PlayerAbilityType abilityType)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)PlayerControl.myInstance?.actions != (Object)null)
				{
					return PlayerControl.myInstance.actions.GetAbility(abilityType)?.AbilityTree;
				}
			}
			catch (Exception arg)
			{
				MelonLogger.Error($"Error getting current ability for type {abilityType}: {arg}");
			}
			return null;
		}

		private AugmentTree? GetCurrentCore()
		{
			try
			{
				if ((Object)(object)PlayerControl.myInstance?.actions != (Object)null)
				{
					FieldInfo field = ((object)PlayerControl.myInstance.actions).GetType().GetField("core", BindingFlags.Instance | BindingFlags.NonPublic);
					if (field != null)
					{
						object? value = field.GetValue(PlayerControl.myInstance.actions);
						return (AugmentTree?)((value is AugmentTree) ? value : null);
					}
				}
			}
			catch (Exception arg)
			{
				MelonLogger.Error($"Error getting current core: {arg}");
			}
			return null;
		}

		private void EquipAbility(PlayerAbilityType abilityType, AbilityTree ability)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)PlayerControl.myInstance?.actions != (Object)null)
				{
					MelonLogger.Msg($"Equipping {ability.Root.Name} to {abilityType}");
					PlayerControl.myInstance.actions.LoadAbility(abilityType, ((Node)ability.Root).guid, false);
					Settings.SaveLoadout();
					MelonLogger.Msg("Successfully equipped " + ability.Root.Name);
				}
			}
			catch (Exception arg)
			{
				MelonLogger.Error($"Error equipping ability {ability.Root.Name}: {arg}");
			}
		}

		private void EquipCore(AugmentTree core)
		{
			try
			{
				if ((Object)(object)PlayerControl.myInstance?.actions != (Object)null)
				{
					MelonLogger.Msg("Equipping core: " + core.Root.Name);
					PlayerControl.myInstance.actions.SetCore(core);
					Settings.SaveLoadout();
					MelonLogger.Msg("Successfully equipped core " + core.Root.Name);
				}
			}
			catch (Exception arg)
			{
				MelonLogger.Error($"Error equipping core {core.Root.Name}: {arg}");
			}
		}

		private void SetCursorState(bool unlocked)
		{
			if (unlocked)
			{
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
			}
			else
			{
				Cursor.lockState = (CursorLockMode)1;
				Cursor.visible = false;
			}
		}

		private Texture2D MakeTexture(int width, int height, Color color)
		{
			//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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			Color[] array = (Color[])(object)new Color[width * height];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = color;
			}
			Texture2D val = new Texture2D(width, height);
			val.SetPixels(array);
			val.Apply();
			return val;
		}

		private static string MakeAbilityFavKey(PlayerAbilityType type, AbilityTree ability)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected I4, but got Unknown
			return $"A:{(int)type}:{((GraphTree)ability).ID}";
		}

		private static string MakeCoreFavKey(AugmentTree core)
		{
			return "C:" + ((GraphTree)core).ID;
		}

		private static string MakeAugmentFavKey(AugmentTree aug)
		{
			return "G:" + ((GraphTree)aug).ID;
		}

		private static void EnsurePrefs()
		{
			if (prefsCategory == null)
			{
				prefsCategory = MelonPreferences.CreateCategory("TheCodex");
			}
			if (prefsFavoritesEntry == null)
			{
				prefsFavoritesEntry = prefsCategory.CreateEntry<string>("Favorites", "", (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			}
		}

		private static void LoadFavorites()
		{
			try
			{
				EnsurePrefs();
				favorites.Clear();
				string[] array = (prefsFavoritesEntry?.Value ?? string.Empty).Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
				foreach (string item in array)
				{
					favorites.Add(item);
				}
				favoritesLoaded = true;
				MelonLogger.Msg($"Loaded {favorites.Count} favorites");
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("Failed to load favorites: " + ex.Message);
			}
		}

		private static void SaveFavorites()
		{
			try
			{
				EnsurePrefs();
				prefsFavoritesEntry.Value = string.Join(",", favorites);
				MelonPreferences.Save();
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("Failed to save favorites: " + ex.Message);
			}
		}

		private static bool IsFavoriteAbility(PlayerAbilityType type, AbilityTree ability)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return favorites.Contains(MakeAbilityFavKey(type, ability));
		}

		private static bool IsFavoriteCore(AugmentTree core)
		{
			return favorites.Contains(MakeCoreFavKey(core));
		}

		private static bool IsFavoriteAugment(AugmentTree aug)
		{
			return favorites.Contains(MakeAugmentFavKey(aug));
		}

		private static void ToggleFavoriteAbility(PlayerAbilityType type, AbilityTree ability)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			string item = MakeAbilityFavKey(type, ability);
			if (!favorites.Remove(item))
			{
				favorites.Add(item);
			}
			SaveFavorites();
		}

		private static void ToggleFavoriteCore(AugmentTree core)
		{
			string item = MakeCoreFavKey(core);
			if (!favorites.Remove(item))
			{
				favorites.Add(item);
			}
			SaveFavorites();
		}

		private static void ToggleFavoriteAugment(AugmentTree aug)
		{
			string item = MakeAugmentFavKey(aug);
			if (!favorites.Remove(item))
			{
				favorites.Add(item);
			}
			SaveFavorites();
		}
	}
	public static class GodModePatches
	{
		public static bool ApplyDamageImmediatePrefix()
		{
			if (Class1.godModeEnabled)
			{
				return false;
			}
			return true;
		}

		public static bool DiePrefix(EntityHealth __instance)
		{
			if (Class1.godModeEnabled)
			{
				try
				{
					FieldInfo field = typeof(EntityHealth).GetField("control", BindingFlags.Instance | BindingFlags.NonPublic);
					if (field != null)
					{
						object value = field.GetValue(__instance);
						if (value != null && value == PlayerControl.myInstance)
						{
							return false;
						}
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Warning("Failed to check player control in DiePrefix: " + ex.Message);
				}
			}
			return true;
		}
	}
	public static class AugmentBlockPatches
	{
		public static bool AddAugmentPrefix(PlayerControl __instance)
		{
			if (Class1.blockPlayerAugmentsEnabled && (Object)(object)__instance == (Object)(object)PlayerControl.myInstance)
			{
				MelonLogger.Msg("Blocked augment pickup - Block Augments is enabled");
				return false;
			}
			return true;
		}
	}
	public static class ManaPatches
	{
		public static bool ConsumeManaPrefix(PlayerMana __instance, float amount, bool local, ref Dictionary<MagicColor, int> __result)
		{
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Expected O, but got Unknown
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Invalid comparison between Unknown and I4
			//IL_0143: 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)
			if (!Class1.infiniteManaEnabled || !((Object)(object)__instance != (Object)null) || !((Object)(object)__instance.Control == (Object)(object)PlayerControl.myInstance))
			{
				return true;
			}
			__result = new Dictionary<MagicColor, int>();
			try
			{
				if ((Object)(object)__instance.Control == (Object)null || ((EntityControl)__instance.Control).IsDead || amount == 0f)
				{
					return false;
				}
				if (amount < 0f)
				{
					__instance.Recharge(0f - amount);
					return false;
				}
				int num = (int)amount;
				if (num <= 0)
				{
					return false;
				}
				foreach (MagicColor item in __instance.GetNextMana(num))
				{
					if (!__result.ContainsKey(item))
					{
						__result[item] = 0;
					}
					__result[item]++;
					if (!local)
					{
						continue;
					}
					try
					{
						EffectProperties val = new EffectProperties();
						val.StartLoc = (val.OutLoc = __instance.Control.Display.CenterLocation);
						val.SourceControl = (EntityControl)(object)__instance.Control;
						val.Affected = ((Component)__instance.Control).gameObject;
						val.AddMana(item, 1);
						((EntityControl)__instance.Control).TriggerSnippets((EventTrigger)20, val, 1f);
						if ((Object)(object)__instance.Control == (Object)(object)PlayerControl.myInstance && (int)item != 1 && (int)item != 0)
						{
							GameStats.IncrementStat(item, (SignatureStat)5, 1u, false);
						}
					}
					catch (Exception ex)
					{
						MelonLogger.Warning("Failed to trigger mana used effects: " + ex.Message);
					}
				}
				return false;
			}
			catch (Exception ex2)
			{
				MelonLogger.Warning("Infinite mana prefix failed, falling back to original: " + ex2.Message);
				return true;
			}
		}

		public static bool DrainPrefix(PlayerMana __instance)
		{
			if (Class1.infiniteManaEnabled && (Object)(object)__instance != (Object)null && (Object)(object)__instance.Control == (Object)(object)PlayerControl.myInstance)
			{
				return false;
			}
			return true;
		}
	}
}