Decompiled source of Hide Completed Quests v1.1.1

HideCompletedQuests.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using HideCompletedQuests;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(HideCompletedQuestsMod), "Hide Completed Quests", "1.1.1", "Hide Completed Quests", null)]
[assembly: MelonGame("BoltBlasterGames", "TheSpellBrigade")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("HideCompletedQuests")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1")]
[assembly: AssemblyProduct("HideCompletedQuests")]
[assembly: AssemblyTitle("HideCompletedQuests")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 HideCompletedQuests
{
	public class HideCompletedQuestsMod : MelonMod
	{
		internal static MelonLogger.Instance Log;

		private static MelonPreferences_Category _category;

		internal static MelonPreferences_Entry<bool> HideCompleted;

		internal static MelonPreferences_Entry<bool> Hotkey;

		internal static MelonPreferences_Entry<bool> ShowButton;

		private static readonly Dictionary<IntPtr, ChallengeCategoryPanel> CategoryPanels = new Dictionary<IntPtr, ChallengeCategoryPanel>();

		private static ChallengesPanel _menu;

		private static bool _focusAfterChange;

		private static int _lastToggleFrame = -1;

		public override void OnInitializeMelon()
		{
			Log = base.LoggerInstance;
			_category = MelonPreferences.CreateCategory("HideCompletedQuests", "Hide Completed Quests");
			HideCompleted = _category.CreateEntry("HideCompleted", default_value: false, "Hide Completed", "Hide quests you have already completed in the quest menu");
			ShowButton = _category.CreateEntry("ShowButton", default_value: true, "Show Toggle Button", "Show the Hide Completed button at the end of the quest category row");
			Hotkey = _category.CreateEntry("Hotkey", default_value: true, "H Key Toggles", "Press H while the quest menu is open to toggle hiding completed quests");
			_category.SaveToFile(printmsg: false);
			HideCompleted.OnEntryValueChanged.Subscribe(delegate
			{
				RefreshAll();
			});
			ShowButton.OnEntryValueChanged.Subscribe(delegate
			{
				ToggleButton.RefreshVisibility();
			});
			if ((1u & (Patch(typeof(ChallengeCategoryPanel), "Open", "CategoryPanelPostfix") ? 1u : 0u) & (Patch(typeof(ChallengeCategoryPanel), "SpawnChallengePanels", "CategoryPanelPostfix") ? 1u : 0u) & (Patch(typeof(ChallengeCategoryPanel), "UpdateChallengeVisuals", "CategoryPanelPostfix") ? 1u : 0u) & (Patch(typeof(ChallengesPanel), "Open", "MenuOpenPostfix") ? 1u : 0u) & (Patch(typeof(ChallengesPanel), "ChangePanel", "ChangePanelPostfix", "ChangePanelPrefix") ? 1u : 0u) & (Patch(typeof(ChallengesPanel), "ShowPanel", "LeaveButtonPostfix") ? 1u : 0u) & (Patch(typeof(ChallengesPanel), "Close", "LeaveButtonPostfix") ? 1u : 0u)) != 0)
			{
				Log.Msg("ready — use the checkmark button after Misc, or H, in the quest menu");
			}
		}

		private bool Patch(Type type, string method, string postfix, string prefix = null)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			try
			{
				MethodInfo methodInfo = AccessTools.Method(type, method, (Type[])null, (Type[])null) ?? throw new MissingMethodException(type.Name + "." + method + " not found");
				base.HarmonyInstance.Patch((MethodBase)methodInfo, (prefix == null) ? ((HarmonyMethod)null) : new HarmonyMethod(typeof(HideCompletedQuestsMod), prefix, (Type[])null), new HarmonyMethod(typeof(HideCompletedQuestsMod), postfix, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				return true;
			}
			catch (Exception ex)
			{
				Log.Error($"failed to hook {type.Name}.{method}: {ex.Message}");
				return false;
			}
		}

		private static void CategoryPanelPostfix(ChallengeCategoryPanel __instance)
		{
			try
			{
				ChallengeCategoryPanel val = ((__instance != null) ? ((Il2CppObjectBase)__instance).TryCast<ChallengeCategoryPanel>() : null);
				if (!((Object)(object)val == (Object)null))
				{
					CategoryPanels[((Il2CppObjectBase)val).Pointer] = val;
					Apply(val);
				}
			}
			catch (Exception ex)
			{
				Log.Warning("quest list: " + ex.Message);
			}
		}

		private static void MenuOpenPostfix(ChallengesPanel __instance)
		{
			try
			{
				ChallengesPanel val = ((__instance != null) ? ((Il2CppObjectBase)__instance).TryCast<ChallengesPanel>() : null);
				if (!((Object)(object)val == (Object)null))
				{
					_menu = val;
					ToggleButton.Ensure(val);
					RefreshAll();
				}
			}
			catch (Exception value)
			{
				Log.Warning($"quest menu: {value}");
			}
		}

		private static bool ChangePanelPrefix(ChallengesPanel __instance, int direction)
		{
			_focusAfterChange = false;
			try
			{
				ChallengesPanel val = ((__instance != null) ? ((Il2CppObjectBase)__instance).TryCast<ChallengesPanel>() : null);
				if ((Object)(object)val == (Object)null || !ShowButton.Value)
				{
					return true;
				}
				List<CategoryButtonPanelPair> pairs = val.pairs;
				if (pairs == null || pairs.Count == 0)
				{
					return true;
				}
				int num = pairs.IndexOf(val.currentPair);
				bool flag = num == pairs.Count - 1;
				bool flag2 = num == 0;
				if (ToggleButton.NavFocused)
				{
					if (direction < 0 && flag)
					{
						ToggleButton.SetNavFocus(focus: false, restoreTab: true);
						ChallengesPanelSoundPlayer soundPlayer = val.soundPlayer;
						if (soundPlayer != null)
						{
							soundPlayer.PlayOpenChallengeCategorySound();
						}
						return false;
					}
					ToggleButton.SetNavFocus(focus: false);
					return true;
				}
				if (direction > 0 && flag)
				{
					ToggleButton.SetNavFocus(focus: true);
					return false;
				}
				if (direction < 0 && flag2)
				{
					_focusAfterChange = true;
				}
			}
			catch (Exception ex)
			{
				Log.Warning("tab cycle: " + ex.Message);
			}
			return true;
		}

		private static void ChangePanelPostfix()
		{
			if (_focusAfterChange)
			{
				_focusAfterChange = false;
				ToggleButton.SetNavFocus(focus: true);
			}
		}

		private static void LeaveButtonPostfix()
		{
			if (!_focusAfterChange)
			{
				ToggleButton.SetNavFocus(focus: false);
			}
		}

		public override void OnUpdate()
		{
			ToggleButton.Tick();
			if (!Hotkey.Value || (Object)(object)_menu == (Object)null)
			{
				return;
			}
			try
			{
				if (_menu.isOpen && ((Behaviour)_menu).isActiveAndEnabled)
				{
					Keyboard current = Keyboard.current;
					if (current != null && ((ButtonControl)current.hKey).wasPressedThisFrame)
					{
						Toggle();
					}
				}
			}
			catch
			{
				_menu = null;
			}
		}

		internal static void Toggle()
		{
			if (Time.frameCount != _lastToggleFrame)
			{
				_lastToggleFrame = Time.frameCount;
				HideCompleted.Value = !HideCompleted.Value;
				_category.SaveToFile(printmsg: false);
			}
		}

		private static void RefreshAll()
		{
			foreach (var (key, val2) in new List<KeyValuePair<IntPtr, ChallengeCategoryPanel>>(CategoryPanels))
			{
				if ((Object)(object)val2 == (Object)null)
				{
					CategoryPanels.Remove(key);
					continue;
				}
				try
				{
					Apply(val2);
				}
				catch (Exception ex)
				{
					Log.Warning("quest list: " + ex.Message);
				}
			}
			ToggleButton.RefreshVisibility();
		}

		private static void Apply(ChallengeCategoryPanel panel)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<ChallengeConfiguration, ChallengeProgressPanel> challengeProgressPanelsForConfigurations = panel.challengeProgressPanelsForConfigurations;
			if (challengeProgressPanelsForConfigurations == null)
			{
				return;
			}
			bool value = HideCompleted.Value;
			ChallengeManager challengeManager = GetChallengeManager();
			bool flag = false;
			Enumerator<ChallengeConfiguration, ChallengeProgressPanel> enumerator = challengeProgressPanelsForConfigurations.GetEnumerator();
			while (enumerator.MoveNext())
			{
				KeyValuePair<ChallengeConfiguration, ChallengeProgressPanel> current = enumerator.Current;
				ChallengeProgressPanel value2 = current.Value;
				ChallengeConfiguration key = current.Key;
				if (!((Object)(object)value2 == (Object)null) && !((Object)(object)key == (Object)null))
				{
					bool flag2 = !value || challengeManager == null || !challengeManager.IsCompleted(key.Id);
					if (((Component)value2).gameObject.activeSelf != flag2)
					{
						((Component)value2).gameObject.SetActive(flag2);
						flag = true;
					}
				}
			}
			if (flag && (Object)(object)panel.contentParent != (Object)null)
			{
				RectTransform val = ((Il2CppObjectBase)panel.contentParent).TryCast<RectTransform>();
				if ((Object)(object)val != (Object)null)
				{
					LayoutRebuilder.ForceRebuildLayoutImmediate(val);
				}
			}
		}

		private static ChallengeManager GetChallengeManager()
		{
			try
			{
				LocalPlayer instance = SingletonPersistent<LocalPlayer>.Instance;
				return (instance != null) ? instance.GetChallengeManager() : null;
			}
			catch
			{
				return null;
			}
		}
	}
	internal static class ToggleButton
	{
		private sealed class Masks
		{
			public Sprite[] Bands;

			public Sprite Badge;

			public float Scale;
		}

		private const string Name = "HideCompletedQuests_Button";

		private const float NormalScale = 0.95f;

		private const float HoverScale = 1.1f;

		private const float NormalBrightness = 0.7f;

		private const float HoverBrightness = 1f;

		private static readonly Color Engraved = new Color(0.13f, 0.12f, 0.16f, 1f);

		private static GameObject _root;

		private static RectTransform _rootRect;

		private static Image _stone;

		private static Image _carved;

		private static Image _icon;

		private static Image[] _bands;

		private static readonly Color StoneFace = new Color(0.286f, 0.259f, 0.353f, 1f);

		private static readonly float[] BandShades = new float[4] { 0.55f, 1f, 1.22f, 1.58f };

		private static Canvas _canvas;

		private static float _fadeSeconds = 0.12f;

		private static float _lit = -1f;

		private static float _hover;

		private static bool _hookHover;

		private static bool _navFocus;

		private static ChallengesPanel _menu;

		private static ButtonInteractionHookSoundPlayer _sound;

		private static Masks _masks;

		private static GameObject _previousSelection;

		internal static bool NavFocused
		{
			get
			{
				if (_navFocus && (Object)(object)_root != (Object)null)
				{
					return _root.activeInHierarchy;
				}
				return false;
			}
		}

		internal static void SetNavFocus(bool focus, bool restoreTab = false)
		{
			if (_navFocus == focus)
			{
				return;
			}
			_navFocus = focus;
			if ((Object)(object)_root == (Object)null)
			{
				return;
			}
			try
			{
				ChallengesPanel menu = _menu;
				object obj;
				if (menu == null)
				{
					obj = null;
				}
				else
				{
					CategoryButtonPanelPair currentPair = menu.currentPair;
					obj = ((currentPair != null) ? currentPair.ChallengeCategoryButton : null);
				}
				ChallengeCategoryButton val = (ChallengeCategoryButton)obj;
				if ((Object)(object)val != (Object)null && (focus || restoreTab))
				{
					if (focus)
					{
						((SelectableButton)val).Deselect();
						val.HideProgressText();
					}
					else
					{
						((SelectableButton)val).Select();
						val.ShowProgressText();
					}
				}
				EventSystem current = EventSystem.current;
				if (focus)
				{
					ChallengesPanel menu2 = _menu;
					if (menu2 != null)
					{
						ChallengesPanelSoundPlayer soundPlayer = menu2.soundPlayer;
						if (soundPlayer != null)
						{
							soundPlayer.PlayOpenChallengeCategorySound();
						}
					}
					_previousSelection = ((current != null) ? current.currentSelectedGameObject : null);
					if ((Object)(object)current != (Object)null)
					{
						current.SetSelectedGameObject(_root);
					}
				}
				else
				{
					_hookHover = false;
					if ((Object)(object)current != (Object)null && (Object)(object)current.currentSelectedGameObject != (Object)null && ((Il2CppObjectBase)current.currentSelectedGameObject).Pointer == ((Il2CppObjectBase)_root).Pointer)
					{
						current.SetSelectedGameObject(_previousSelection);
					}
					_previousSelection = null;
				}
			}
			catch (Exception ex)
			{
				HideCompletedQuestsMod.Log.Warning("focus: " + ex.Message);
			}
		}

		internal static void PlayClick()
		{
			try
			{
				ButtonInteractionHookSoundPlayer sound = _sound;
				if (sound != null)
				{
					sound.PlayClickSound();
				}
			}
			catch
			{
			}
		}

		internal static void Ensure(ChallengesPanel menu)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Invalid comparison between Unknown and I4
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_root != (Object)null && (Object)(object)_root.transform.parent != (Object)null)
			{
				RefreshVisibility();
				return;
			}
			ChallengeCategoryButton val = null;
			ChallengeCategoryButton val2 = null;
			Enumerator<CategoryButtonPanelPair> enumerator = menu.pairs.GetEnumerator();
			while (enumerator.MoveNext())
			{
				CategoryButtonPanelPair current = enumerator.Current;
				ChallengeCategoryButton val3 = ((current != null) ? current.ChallengeCategoryButton : null);
				if (!((Object)(object)val3 == (Object)null))
				{
					val2 = val3;
					if ((int)val3.ChallengeCategory == 4)
					{
						val = val3;
					}
				}
			}
			if (val == null)
			{
				val = val2;
			}
			if ((Object)(object)val == (Object)null)
			{
				HideCompletedQuestsMod.Log.Warning("quest category buttons not found; use H or Mod List to toggle");
				return;
			}
			GameObject val4 = Object.Instantiate<GameObject>(((Component)val).gameObject, ((Component)val).transform.parent, false);
			((Object)val4).name = "HideCompletedQuests_Button";
			val4.transform.SetAsLastSibling();
			Animator component = val4.GetComponent<Animator>();
			_fadeSeconds = HoverSeconds(component);
			foreach (Behaviour component4 in val4.GetComponents<Behaviour>())
			{
				component4.enabled = true;
			}
			if ((Object)(object)component != (Object)null)
			{
				((Behaviour)component).enabled = false;
			}
			Button component2 = val4.GetComponent<Button>();
			if ((Object)(object)component2 != (Object)null)
			{
				((Selectable)component2).interactable = true;
			}
			_rootRect = val4.GetComponent<RectTransform>();
			float y = ((Component)val).GetComponent<RectTransform>().sizeDelta.y;
			_rootRect.sizeDelta = new Vector2(y, y);
			ChallengeCategoryButton component3 = val4.GetComponent<ChallengeCategoryButton>();
			if ((Object)(object)((component3 != null) ? component3.categoryProgressText : null) != (Object)null)
			{
				component3.categoryProgressText.text = "";
			}
			Transform val5 = val4.transform.Find("Button_Image");
			if ((Object)(object)val5 != (Object)null)
			{
				for (int i = 0; i < val5.childCount; i++)
				{
					((Component)val5.GetChild(i)).gameObject.SetActive(false);
				}
				_stone = ((Component)val5).GetComponent<Image>();
			}
			if (_stone == null)
			{
				_stone = val4.GetComponentInChildren<Image>(true);
			}
			Sprite val6 = FindSquareStone(menu);
			if ((Object)(object)_stone != (Object)null)
			{
				if ((Object)(object)val6 != (Object)null)
				{
					_stone.sprite = val6;
				}
				_stone.preserveAspect = true;
			}
			if (component2 != null)
			{
				((UnityEvent)component2.onClick).AddListener(UnityAction.op_Implicit((Action)HideCompletedQuestsMod.Toggle));
			}
			if ((Object)(object)component3 != (Object)null)
			{
				((ButtonInteractionHook)component3).OnHighlight += Action.op_Implicit((Action)delegate
				{
					_hookHover = true;
				});
				((ButtonInteractionHook)component3).OnUnhighlight += Action.op_Implicit((Action)delegate
				{
					_hookHover = false;
				});
			}
			_canvas = val4.GetComponentInParent<Canvas>();
			_sound = val4.GetComponentInChildren<ButtonInteractionHookSoundPlayer>(true);
			_menu = menu;
			BuildIcon(menu, ((Object)(object)val5 != (Object)null) ? val5 : val4.transform, y);
			_root = val4;
			_hover = 0f;
			_hookHover = false;
			_navFocus = false;
			_lit = (HideCompletedQuestsMod.HideCompleted.Value ? 0f : 1f);
			ApplyLook();
			RefreshVisibility();
			MelonLogger.Instance log = HideCompletedQuestsMod.Log;
			DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(46, 4);
			defaultInterpolatedStringHandler.AppendLiteral("button added after ");
			defaultInterpolatedStringHandler.AppendFormatted(((Object)val).name);
			defaultInterpolatedStringHandler.AppendLiteral(" (stone: ");
			Image stone = _stone;
			object value;
			if (stone == null)
			{
				value = null;
			}
			else
			{
				Sprite sprite = stone.sprite;
				value = ((sprite != null) ? ((Object)sprite).name : null);
			}
			defaultInterpolatedStringHandler.AppendFormatted((string?)value);
			defaultInterpolatedStringHandler.AppendLiteral(", icon: ");
			Image icon = _icon;
			object value2;
			if (icon == null)
			{
				value2 = null;
			}
			else
			{
				Sprite sprite2 = icon.sprite;
				value2 = ((sprite2 != null) ? ((Object)sprite2).name : null);
			}
			defaultInterpolatedStringHandler.AppendFormatted((string?)value2);
			defaultInterpolatedStringHandler.AppendLiteral(", fade: ");
			defaultInterpolatedStringHandler.AppendFormatted(_fadeSeconds, "0.00");
			defaultInterpolatedStringHandler.AppendLiteral("s)");
			log.Msg(defaultInterpolatedStringHandler.ToStringAndClear());
		}

		internal static void RefreshVisibility()
		{
			if ((Object)(object)_root != (Object)null)
			{
				_root.SetActive(HideCompletedQuestsMod.ShowButton.Value);
			}
		}

		internal static void Tick()
		{
			if ((Object)(object)_root == (Object)null || !_root.activeInHierarchy)
			{
				_hookHover = false;
				_navFocus = false;
				return;
			}
			float num = Time.unscaledDeltaTime / _fadeSeconds;
			if (_navFocus && ConfirmPressed())
			{
				HideCompletedQuestsMod.Toggle();
				PlayClick();
			}
			float num2 = (HideCompletedQuestsMod.HideCompleted.Value ? 0f : 1f);
			_lit = Mathf.MoveTowards(_lit, num2, num);
			float num3 = ((_navFocus || _hookHover || PointerOver()) ? 1f : 0f);
			_hover = Mathf.MoveTowards(_hover, num3, num);
			ApplyLook();
		}

		private static bool ConfirmPressed()
		{
			Keyboard current = Keyboard.current;
			if (current != null && (((ButtonControl)current.enterKey).wasPressedThisFrame || ((ButtonControl)current.numpadEnterKey).wasPressedThisFrame || ((ButtonControl)current.spaceKey).wasPressedThisFrame))
			{
				return true;
			}
			Gamepad current2 = Gamepad.current;
			if (current2 != null)
			{
				return current2.buttonSouth.wasPressedThisFrame;
			}
			return false;
		}

		private static bool PointerOver()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			Mouse current = Mouse.current;
			if (current == null || (Object)(object)_rootRect == (Object)null)
			{
				return false;
			}
			Camera val = (((Object)(object)_canvas != (Object)null && (int)_canvas.renderMode != 0) ? _canvas.worldCamera : null);
			return RectTransformUtility.RectangleContainsScreenPoint(_rootRect, ((InputControl<Vector2>)(object)((Pointer)current).position).ReadValue(), val);
		}

		private static void ApplyLook()
		{
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: 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_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_icon == (Object)null)
			{
				return;
			}
			float num = Mathf.SmoothStep(0f, 1f, _hover);
			float num2 = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01(_lit));
			float num3 = Mathf.Lerp(0.7f, 1f, num);
			if ((Object)(object)_stone != (Object)null)
			{
				float num4 = Mathf.Lerp(0.95f, 1.1f, num);
				((Transform)((Graphic)_stone).rectTransform).localScale = new Vector3(num4, num4, 1f);
				((Graphic)_stone).color = new Color(num3, num3, num3, 1f);
			}
			float k = num3 / 0.7f;
			Color c = Scale(StoneFace, num3);
			if (_bands != null)
			{
				for (int i = 0; i < _bands.Length; i++)
				{
					((Graphic)_bands[i]).color = Scale(c, BandShades[i]);
				}
			}
			((Graphic)_carved).color = Scale(Engraved, k);
			Color val = Scale(Color.white, Mathf.Lerp(0.92f, 1f, num));
			((Graphic)_icon).color = new Color(val.r, val.g, val.b, num2);
		}

		private static Color Scale(Color c, float k)
		{
			//IL_0005: 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_0029: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			return new Color(Mathf.Min(1f, c.r * k), Mathf.Min(1f, c.g * k), Mathf.Min(1f, c.b * k), c.a);
		}

		private static void BuildIcon(ChallengesPanel menu, Transform parent, float stoneHeight)
		{
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: 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_011a: Unknown result type (might be due to invalid IL or missing references)
			Sprite val = null;
			try
			{
				ChallengeCategoryPanel componentInChildren = ((Component)menu).GetComponentInChildren<ChallengeCategoryPanel>(true);
				GameObject val2 = ((componentInChildren != null) ? componentInChildren.challengeProgressPanelPrefab : null);
				Transform obj = (((Object)(object)val2 != (Object)null) ? FindDeep(val2.transform, "Check_Image") : null);
				object obj2;
				if (obj == null)
				{
					obj2 = null;
				}
				else
				{
					Image component = ((Component)obj).GetComponent<Image>();
					obj2 = ((component != null) ? component.sprite : null);
				}
				val = (Sprite)obj2;
			}
			catch (Exception ex)
			{
				HideCompletedQuestsMod.Log.Warning("checkmark icon: " + ex.Message);
			}
			if (val == null)
			{
				val = FindSprite("ui_lobby_ready");
			}
			float num = stoneHeight * 0.5f;
			if (_masks == null)
			{
				_masks = CarveMasks(val);
			}
			if (_masks != null)
			{
				float size = num * _masks.Scale;
				_bands = (Image[])(object)new Image[_masks.Bands.Length];
				for (int i = 0; i < _bands.Length; i++)
				{
					_bands[i] = Layer("PocketBand" + i, parent, _masks.Bands[i], size, Vector2.zero);
				}
				_carved = Layer("Engraved", parent, _masks.Badge, num, Vector2.zero);
			}
			else
			{
				_carved = Layer("Engraved", parent, val, num, Vector2.zero);
			}
			_icon = Layer("Glow", parent, val, num, Vector2.zero);
		}

		private static Masks CarveMasks(Sprite source)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Expected O, but got Unknown
			//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_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: 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_0122: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)source == (Object)null)
			{
				return null;
			}
			RenderTexture val = null;
			RenderTexture active = RenderTexture.active;
			try
			{
				Texture2D texture = source.texture;
				Rect textureRect = source.textureRect;
				val = RenderTexture.GetTemporary(((Texture)texture).width, ((Texture)texture).height, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)2);
				Graphics.Blit((Texture)(object)texture, val);
				RenderTexture.active = val;
				int num = Mathf.RoundToInt(((Rect)(ref textureRect)).width);
				int num2 = Mathf.RoundToInt(((Rect)(ref textureRect)).height);
				Texture2D val2 = new Texture2D(num, num2, (TextureFormat)4, false);
				val2.ReadPixels(new Rect(((Rect)(ref textureRect)).x, ((Rect)(ref textureRect)).y, (float)num, (float)num2), 0, 0);
				Il2CppStructArray<Color> pixels = val2.GetPixels();
				Object.Destroy((Object)val2);
				int num3 = Mathf.Max(3, Mathf.RoundToInt((float)num * 0.14f));
				int num4 = num + 2 * num3;
				int num5 = num2 + 2 * num3;
				bool[] array = new bool[num4 * num5];
				for (int i = 0; i < num2; i++)
				{
					for (int j = 0; j < num; j++)
					{
						Color val3 = ((Il2CppArrayBase<Color>)(object)pixels)[i * num + j];
						float num6 = 0.299f * val3.r + 0.587f * val3.g + 0.114f * val3.b;
						array[(i + num3) * num4 + j + num3] = val3.a > 0.5f && num6 > 0.55f;
					}
				}
				bool[] array2 = new bool[num4 * num5];
				Stack<int> stack = new Stack<int>();
				for (int k = 0; k < num4; k++)
				{
					stack.Push(k);
					stack.Push((num5 - 1) * num4 + k);
				}
				for (int l = 0; l < num5; l++)
				{
					stack.Push(l * num4);
					stack.Push(l * num4 + num4 - 1);
				}
				while (stack.Count > 0)
				{
					int num7 = stack.Pop();
					if (!array2[num7] && !array[num7])
					{
						array2[num7] = true;
						int num8 = num7 % num4;
						int num9 = num7 / num4;
						if (num8 > 0)
						{
							stack.Push(num7 - 1);
						}
						if (num8 < num4 - 1)
						{
							stack.Push(num7 + 1);
						}
						if (num9 > 0)
						{
							stack.Push(num7 - num4);
						}
						if (num9 < num5 - 1)
						{
							stack.Push(num7 + num4);
						}
					}
				}
				bool[] array3 = new bool[num4 * num5];
				int num10 = num3 * num3;
				for (int m = 0; m < num5; m++)
				{
					for (int n = 0; n < num4; n++)
					{
						if (array2[m * num4 + n])
						{
							continue;
						}
						if ((n <= 0 || !array2[m * num4 + n - 1]) && (n >= num4 - 1 || !array2[m * num4 + n + 1]) && (m <= 0 || !array2[(m - 1) * num4 + n]) && (m >= num5 - 1 || !array2[(m + 1) * num4 + n]))
						{
							array3[m * num4 + n] = true;
							continue;
						}
						for (int num11 = -num3; num11 <= num3; num11++)
						{
							for (int num12 = -num3; num12 <= num3; num12++)
							{
								if (num12 * num12 + num11 * num11 <= num10)
								{
									int num13 = n + num12;
									int num14 = m + num11;
									if (num13 >= 0 && num13 < num4 && num14 >= 0 && num14 < num5)
									{
										array3[num14 * num4 + num13] = true;
									}
								}
							}
						}
					}
				}
				int num15 = -1;
				int num16 = num5;
				for (int num17 = 0; num17 < num5; num17++)
				{
					for (int num18 = 0; num18 < num4; num18++)
					{
						int num19 = num17 * num4 + num18;
						if (!array2[num19])
						{
							array3[num19] = false;
						}
						if (array3[num19])
						{
							num15 = Mathf.Max(num15, num17);
							num16 = Mathf.Min(num16, num17);
						}
					}
				}
				bool[][] array4 = new bool[BandShades.Length][];
				for (int num20 = 0; num20 < array4.Length; num20++)
				{
					array4[num20] = new bool[num4 * num5];
				}
				float num21 = Mathf.Max(1, num15 - num16 + 1);
				for (int num22 = 0; num22 < num5; num22++)
				{
					for (int num23 = 0; num23 < num4; num23++)
					{
						int num24 = num22 * num4 + num23;
						if (array3[num24])
						{
							float num25 = ((float)(num15 - num22) + 0.5f) / num21;
							array4[Mathf.Min(array4.Length - 1, (int)(num25 * (float)array4.Length))][num24] = true;
						}
					}
				}
				float pixelsPerUnit = source.pixelsPerUnit;
				Masks masks = new Masks
				{
					Bands = (Sprite[])(object)new Sprite[array4.Length],
					Badge = MaskSprite(Crop(array, num4, num3, num, num2), num, num2, pixelsPerUnit),
					Scale = (float)num4 / (float)num
				};
				for (int num26 = 0; num26 < array4.Length; num26++)
				{
					masks.Bands[num26] = MaskSprite(array4[num26], num4, num5, pixelsPerUnit);
				}
				return masks;
			}
			catch (Exception ex)
			{
				HideCompletedQuestsMod.Log.Warning("carved badge: " + ex.Message);
				return null;
			}
			finally
			{
				RenderTexture.active = active;
				if ((Object)(object)val != (Object)null)
				{
					RenderTexture.ReleaseTemporary(val);
				}
			}
		}

		private static bool[] Crop(bool[] src, int srcW, int pad, int w, int h)
		{
			bool[] array = new bool[w * h];
			for (int i = 0; i < h; i++)
			{
				for (int j = 0; j < w; j++)
				{
					array[i * w + j] = src[(i + pad) * srcW + j + pad];
				}
			}
			return array;
		}

		private static Sprite MaskSprite(bool[] mask, int w, int h, float ppu)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(w, h, (TextureFormat)4, false)
			{
				hideFlags = (HideFlags)61,
				filterMode = (FilterMode)1,
				wrapMode = (TextureWrapMode)1
			};
			Color32[] array = (Color32[])(object)new Color32[w * h];
			Color32 val2 = default(Color32);
			((Color32)(ref val2))..ctor(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
			Color32 val3 = default(Color32);
			((Color32)(ref val3))..ctor(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)0);
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = (mask[i] ? val2 : val3);
			}
			val.SetPixels32(Il2CppStructArray<Color32>.op_Implicit(array));
			val.Apply();
			Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)w, (float)h), new Vector2(0.5f, 0.5f), ppu);
			((Object)obj).hideFlags = (HideFlags)61;
			return obj;
		}

		private static Image Layer(string name, Transform parent, Sprite sprite, float size, Vector2 offset)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_0038: 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: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			RectTransform obj = new GameObject("HideCompletedQuests_" + name).AddComponent<RectTransform>();
			((Transform)obj).SetParent(parent, false);
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0.5f, 0.5f);
			obj.pivot = val;
			Vector2 anchorMin = (obj.anchorMax = val);
			obj.anchorMin = anchorMin;
			obj.sizeDelta = new Vector2(size, size);
			obj.anchoredPosition = offset;
			Image obj2 = ((Component)obj).gameObject.AddComponent<Image>();
			obj2.sprite = sprite;
			obj2.preserveAspect = true;
			((Graphic)obj2).raycastTarget = false;
			return obj2;
		}

		private static Transform FindDeep(Transform t, string name)
		{
			if (((Object)t).name == name)
			{
				return t;
			}
			for (int i = 0; i < t.childCount; i++)
			{
				Transform val = FindDeep(t.GetChild(i), name);
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			return null;
		}

		private static float HoverSeconds(Animator animator)
		{
			try
			{
				object obj;
				if (animator == null)
				{
					obj = null;
				}
				else
				{
					RuntimeAnimatorController runtimeAnimatorController = animator.runtimeAnimatorController;
					obj = ((runtimeAnimatorController != null) ? runtimeAnimatorController.animationClips : null);
				}
				Il2CppReferenceArray<AnimationClip> val = (Il2CppReferenceArray<AnimationClip>)obj;
				if (val != null)
				{
					foreach (AnimationClip item in (Il2CppArrayBase<AnimationClip>)(object)val)
					{
						if ((Object)(object)item != (Object)null && ((Object)item).name.ToLowerInvariant().Contains("highlight") && item.length > 0.01f)
						{
							return Mathf.Clamp(item.length, 0.05f, 0.5f);
						}
					}
				}
			}
			catch
			{
			}
			return 0.12f;
		}

		private static Sprite FindSquareStone(ChallengesPanel menu)
		{
			Sprite val = FindSprite("button_small_1");
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			try
			{
				PanelSwitcher instance = Singleton<PanelSwitcher>.Instance;
				if ((Object)(object)instance != (Object)null)
				{
					Enumerator<ButtonPanelPair> enumerator = instance.pairs.GetEnumerator();
					while (enumerator.MoveNext())
					{
						ButtonPanelPair current = enumerator.Current;
						if ((Object)(object)((current != null) ? current.Panel : null) == (Object)null || (Object)(object)current.Button == (Object)null || ((Il2CppObjectBase)current.Panel).Pointer != ((Il2CppObjectBase)menu).Pointer)
						{
							continue;
						}
						foreach (Image componentsInChild in ((Component)current.Button).GetComponentsInChildren<Image>(true))
						{
							Sprite sprite = componentsInChild.sprite;
							string text = ((sprite != null) ? ((Object)sprite).name : null) ?? "";
							if (text.StartsWith("button_") && !text.Contains("glow") && !text.Contains("highlight"))
							{
								return componentsInChild.sprite;
							}
						}
					}
				}
			}
			catch (Exception ex)
			{
				HideCompletedQuestsMod.Log.Warning("square stone: " + ex.Message);
			}
			return null;
		}

		private static Sprite FindSprite(string name)
		{
			foreach (Sprite item in Resources.FindObjectsOfTypeAll<Sprite>())
			{
				if ((Object)(object)item != (Object)null && ((Object)item).name == name)
				{
					return item;
				}
			}
			return null;
		}
	}
}
namespace HideCompletedQuests.BepInExPlugin
{
	[BepInPlugin("SpellBrigade.HideCompletedQuests", "Hide Completed Quests", "1.1.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		public const string Guid = "SpellBrigade.HideCompletedQuests";

		public override void Load()
		{
			MelonCompat.Start<HideCompletedQuestsMod, Runner>((BasePlugin)(object)this, "SpellBrigade.HideCompletedQuests");
		}
	}
	public class Runner : MonoBehaviour
	{
		public Runner(IntPtr ptr)
			: base(ptr)
		{
		}

		private void Update()
		{
			MelonCompat.Update();
		}
	}
}
namespace MelonLoader
{
	[AttributeUsage(AttributeTargets.Assembly)]
	public sealed class MelonInfoAttribute : Attribute
	{
		public MelonInfoAttribute(Type type, string name, string version, string author, string downloadLink = null)
		{
		}
	}
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	public sealed class MelonGameAttribute : Attribute
	{
		public MelonGameAttribute(string developer = null, string name = null)
		{
		}
	}
	[AttributeUsage(AttributeTargets.Assembly)]
	public sealed class MelonOptionalDependenciesAttribute : Attribute
	{
		public MelonOptionalDependenciesAttribute(params string[] names)
		{
		}
	}
	public abstract class MelonBase
	{
		public MelonLogger.Instance LoggerInstance { get; internal set; }

		public Harmony HarmonyInstance { get; internal set; }

		public static object FindMelon(string name, string author)
		{
			try
			{
				foreach (PluginInfo value in ((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.Values)
				{
					if (((value != null) ? value.Metadata : null) != null && string.Equals(value.Metadata.Name, name, StringComparison.OrdinalIgnoreCase) && value.Instance != null)
					{
						return value;
					}
				}
			}
			catch
			{
			}
			return null;
		}
	}
	public abstract class MelonMod : MelonBase
	{
		public virtual void OnInitializeMelon()
		{
		}

		public virtual void OnLateInitializeMelon()
		{
		}

		public virtual void OnUpdate()
		{
		}

		public virtual void OnLateUpdate()
		{
		}

		public virtual void OnFixedUpdate()
		{
		}

		public virtual void OnGUI()
		{
		}

		public virtual void OnApplicationQuit()
		{
		}

		public virtual void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
		}

		public virtual void OnSceneWasInitialized(int buildIndex, string sceneName)
		{
		}

		public virtual void OnSceneWasUnloaded(int buildIndex, string sceneName)
		{
		}
	}
	public static class MelonLogger
	{
		public sealed class Instance
		{
			private readonly ManualLogSource _log;

			public Instance(ManualLogSource log)
			{
				_log = log;
			}

			public void Msg(string text)
			{
				_log.LogInfo((object)text);
			}

			public void Msg(object value)
			{
				_log.LogInfo(value);
			}

			public void Msg(string format, params object[] args)
			{
				_log.LogInfo((object)string.Format(format, args));
			}

			public void Warning(string text)
			{
				_log.LogWarning((object)text);
			}

			public void Warning(object value)
			{
				_log.LogWarning(value);
			}

			public void Error(string text)
			{
				_log.LogError((object)text);
			}

			public void Error(object value)
			{
				_log.LogError(value);
			}

			public void Error(string text, Exception e)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Expected O, but got Unknown
				ManualLogSource log = _log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(1, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\n");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(e);
				}
				log.LogError(val);
			}
		}
	}
	public static class MelonCompat
	{
		internal static ConfigFile Config;

		private static MelonMod _mod;

		private static bool _lateInit;

		public static void Start<TMod, TRunner>(BasePlugin plugin, string harmonyId) where TMod : MelonMod, new() where TRunner : MonoBehaviour
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			Config = plugin.Config;
			_mod = new TMod
			{
				LoggerInstance = new MelonLogger.Instance(plugin.Log),
				HarmonyInstance = new Harmony(harmonyId)
			};
			try
			{
				_mod.HarmonyInstance.PatchAll(typeof(TMod).Assembly);
			}
			catch (Exception ex)
			{
				ManualLogSource log = plugin.Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(17, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Harmony patches: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				log.LogError(val);
			}
			_mod.OnInitializeMelon();
			HookScenes();
			ClassInjector.RegisterTypeInIl2Cpp<TRunner>();
			plugin.AddComponent<TRunner>();
		}

		private static void HookScenes()
		{
			SceneManager.sceneLoaded += DelegateSupport.ConvertDelegate<UnityAction<Scene, LoadSceneMode>>((Delegate)new Action<Scene, LoadSceneMode>(OnSceneLoaded));
			SceneManager.sceneUnloaded += DelegateSupport.ConvertDelegate<UnityAction<Scene>>((Delegate)new Action<Scene>(OnSceneUnloaded));
		}

		private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			Guard(delegate
			{
				_mod.OnSceneWasLoaded(((Scene)(ref scene)).buildIndex, ((Scene)(ref scene)).name);
			});
			Guard(delegate
			{
				_mod.OnSceneWasInitialized(((Scene)(ref scene)).buildIndex, ((Scene)(ref scene)).name);
			});
		}

		private static void OnSceneUnloaded(Scene scene)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			Guard(delegate
			{
				_mod.OnSceneWasUnloaded(((Scene)(ref scene)).buildIndex, ((Scene)(ref scene)).name);
			});
		}

		public static void Update()
		{
			if (_mod != null)
			{
				if (!_lateInit)
				{
					_lateInit = true;
					Guard(_mod.OnLateInitializeMelon);
				}
				_mod.OnUpdate();
			}
		}

		public static void LateUpdate()
		{
			_mod?.OnLateUpdate();
		}

		public static void FixedUpdate()
		{
			_mod?.OnFixedUpdate();
		}

		public static void OnGUI()
		{
			_mod?.OnGUI();
		}

		public static void Quit()
		{
			_mod?.OnApplicationQuit();
		}

		private static void Guard(Action a)
		{
			try
			{
				a();
			}
			catch (Exception ex)
			{
				_mod.LoggerInstance.Error(ex.ToString());
			}
		}
	}
	public static class MelonPreferences
	{
		private static readonly Dictionary<string, MelonPreferences_Category> Categories = new Dictionary<string, MelonPreferences_Category>();

		public static MelonPreferences_Category CreateCategory(string identifier, string displayName = null, bool is_hidden = false, bool is_inlined = false)
		{
			if (!Categories.TryGetValue(identifier, out var value))
			{
				value = (Categories[identifier] = new MelonPreferences_Category(identifier, displayName ?? identifier)
				{
					IsHidden = is_hidden
				});
			}
			return value;
		}

		public static MelonPreferences_Category GetCategory(string identifier)
		{
			if (!Categories.TryGetValue(identifier, out var value))
			{
				return null;
			}
			return value;
		}

		public static void Save()
		{
			ConfigFile config = MelonCompat.Config;
			if (config != null)
			{
				config.Save();
			}
		}
	}
	public sealed class MelonPreferences_Category
	{
		public readonly List<MelonPreferences_Entry> Entries = new List<MelonPreferences_Entry>();

		public string Identifier { get; }

		public string DisplayName { get; }

		public bool IsHidden { get; internal set; }

		internal MelonPreferences_Category(string identifier, string displayName)
		{
			Identifier = identifier;
			DisplayName = displayName;
		}

		public MelonPreferences_Entry<T> CreateEntry<T>(string identifier, T default_value, string display_name = null, string description = null, bool is_hidden = false, bool dont_save_default = false, ValueValidator validator = null, string oldIdentifier = null)
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			ConfigurationManagerAttributes configurationManagerAttributes = new ConfigurationManagerAttributes
			{
				DispName = (display_name ?? identifier),
				Browsable = (!is_hidden && !IsHidden),
				Order = -Entries.Count,
				Category = DisplayName
			};
			AcceptableValueBase val = validator?.ToAcceptable(typeof(T));
			ConfigEntry<T> cfg = MelonCompat.Config.Bind<T>(Identifier, identifier, default_value, new ConfigDescription(description ?? "", val, new object[1] { configurationManagerAttributes }));
			MelonPreferences_Entry<T> melonPreferences_Entry = new MelonPreferences_Entry<T>(this, cfg, identifier, display_name ?? identifier, description, is_hidden);
			Entries.Add(melonPreferences_Entry);
			return melonPreferences_Entry;
		}

		public MelonPreferences_Entry GetEntry(string identifier)
		{
			return Entries.Find((MelonPreferences_Entry e) => e.Identifier == identifier);
		}

		public MelonPreferences_Entry<T> GetEntry<T>(string identifier)
		{
			return GetEntry(identifier) as MelonPreferences_Entry<T>;
		}

		public bool HasEntry(string identifier)
		{
			return GetEntry(identifier) != null;
		}

		public void SaveToFile(bool printmsg = true)
		{
			ConfigFile config = MelonCompat.Config;
			if (config != null)
			{
				config.Save();
			}
		}

		public void LoadFromFile(bool printmsg = true)
		{
			ConfigFile config = MelonCompat.Config;
			if (config != null)
			{
				config.Reload();
			}
		}
	}
	public abstract class MelonPreferences_Entry
	{
		public readonly MelonEvent<object, object> OnEntryValueChangedUntyped = new MelonEvent<object, object>();

		public MelonPreferences_Category Category { get; protected set; }

		public string Identifier { get; protected set; }

		public string DisplayName { get; protected set; }

		public string Description { get; protected set; }

		public bool IsHidden { get; protected set; }

		public abstract ConfigEntryBase Raw { get; }

		public abstract object BoxedValue { get; set; }

		public abstract void ResetToDefault();
	}
	public sealed class MelonPreferences_Entry<T> : MelonPreferences_Entry
	{
		private readonly ConfigEntry<T> _cfg;

		private T _last;

		public readonly MelonEvent<T, T> OnEntryValueChanged = new MelonEvent<T, T>();

		public readonly MelonEvent<T, T> OnValueChanged;

		public T Value
		{
			get
			{
				return _cfg.Value;
			}
			set
			{
				_cfg.Value = value;
			}
		}

		public T DefaultValue => (T)((ConfigEntryBase)_cfg).DefaultValue;

		public override ConfigEntryBase Raw => (ConfigEntryBase)(object)_cfg;

		public override object BoxedValue
		{
			get
			{
				return ((ConfigEntryBase)_cfg).BoxedValue;
			}
			set
			{
				((ConfigEntryBase)_cfg).BoxedValue = value;
			}
		}

		internal MelonPreferences_Entry(MelonPreferences_Category category, ConfigEntry<T> cfg, string identifier, string displayName, string description, bool hidden)
		{
			base.Category = category;
			_cfg = cfg;
			base.Identifier = identifier;
			base.DisplayName = displayName;
			base.Description = description;
			base.IsHidden = hidden;
			OnValueChanged = OnEntryValueChanged;
			_last = cfg.Value;
			cfg.SettingChanged += OnSettingChanged;
		}

		private void OnSettingChanged(object sender, EventArgs e)
		{
			T last = _last;
			_last = _cfg.Value;
			if (!EqualityComparer<T>.Default.Equals(last, _last))
			{
				OnEntryValueChanged.Invoke(last, _last);
				OnEntryValueChangedUntyped.Invoke(last, _last);
			}
		}

		public override void ResetToDefault()
		{
			_cfg.Value = DefaultValue;
		}
	}
	public sealed class MelonEvent<T1, T2>
	{
		private readonly List<Action<T1, T2>> _handlers = new List<Action<T1, T2>>();

		public void Subscribe(Action<T1, T2> handler, int priority = 0, bool unsubscribeOnFirstInvocation = false)
		{
			_handlers.Add(handler);
		}

		public void Unsubscribe(Action<T1, T2> handler)
		{
			_handlers.Remove(handler);
		}

		internal void Invoke(T1 a, T2 b)
		{
			Action<T1, T2>[] array = _handlers.ToArray();
			foreach (Action<T1, T2> action in array)
			{
				try
				{
					action(a, b);
				}
				catch (Exception ex)
				{
					Debug.LogError(Object.op_Implicit(ex.ToString()));
				}
			}
		}
	}
	public sealed class ConfigurationManagerAttributes
	{
		public string DispName;

		public bool? Browsable;

		public int? Order;

		public string Category;
	}
}
namespace MelonLoader.Preferences
{
	public abstract class ValueValidator
	{
		public abstract AcceptableValueBase ToAcceptable(Type type);
	}
	public sealed class ValueRange<T> : ValueValidator where T : IComparable
	{
		public T MinValue { get; }

		public T MaxValue { get; }

		public ValueRange(T min, T max)
		{
			MinValue = min;
			MaxValue = max;
		}

		public override AcceptableValueBase ToAcceptable(Type type)
		{
			if (!(type == typeof(T)))
			{
				return null;
			}
			return (AcceptableValueBase)(object)new AcceptableValueRange<T>(MinValue, MaxValue);
		}
	}
}
namespace Il2CppTMPro
{
	internal static class NamespaceStandIn
	{
	}
}
namespace Il2Cpp
{
	internal static class NamespaceStandIn
	{
	}
}