Decompiled source of Pinned Quests v1.0.0

PinnedQuests.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BrigadeModMenu;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using PinnedQuests;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.Localization;
using UnityEngine.Localization.Components;
using UnityEngine.Localization.Settings;
using UnityEngine.Localization.Tables;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(PinnedQuestsMod), "Pinned Quests", "1.0.0", "Pinned Quests", null)]
[assembly: MelonGame("BoltBlasterGames", "TheSpellBrigade")]
[assembly: MelonOptionalDependencies(new string[] { "BrigadeModMenu" })]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("PinnedQuests")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PinnedQuests")]
[assembly: AssemblyTitle("PinnedQuests")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 BrigadeModMenu
{
	public static class ModMenuCompat
	{
		public static Page Entry(this Page page, MelonPreferences_Entry entry, Func<string> label = null)
		{
			if (entry != null)
			{
				return page.Entry(entry.Raw, label ?? ((Func<string>)(() => entry.DisplayName)));
			}
			return page;
		}

		public static Page Category(this Page page, MelonPreferences_Category category)
		{
			if (category == null)
			{
				return page;
			}
			Menu.HideCategory(category.Identifier);
			foreach (MelonPreferences_Entry e in category.Entries)
			{
				if (e != null && !e.IsHidden)
				{
					page.Entry(e.Raw, (Func<string>)(() => e.DisplayName));
				}
			}
			return page;
		}
	}
}
namespace PinnedQuests
{
	internal sealed class Cards
	{
		private sealed class Card
		{
			public ChallengeId? Id;

			public string SampleText;

			public int SampleValue;

			public int SampleTarget;

			public GameObject Go;

			public TMP_Text Text;

			public TMP_Text Count;

			public RectTransform Fill;

			public Image Icon;

			public Image FillImage;

			public LayoutElement Info;
		}

		private const float IconSize = 112f;

		private static readonly Color Green = new Color(0.45f, 0.85f, 0.4f, 1f);

		public readonly RectTransform Root;

		private readonly List<Card> _cards = new List<Card>();

		private string _built;

		private readonly GridLayoutGroup _grid;

		private static Sprite _style;

		private static string _styleKey;

		private static TMP_FontAsset _font;

		public int Count => _cards.Count;

		public Cards(Transform parent, string name)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			Root = new GameObject(name).AddComponent<RectTransform>();
			((Transform)Root).SetParent(parent, false);
			RectTransform root = Root;
			RectTransform root2 = Root;
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(1f, 0.5f);
			root2.anchorMax = val;
			root.anchorMin = val;
			Root.pivot = new Vector2(1f, 1f);
			_grid = ((Component)Root).gameObject.AddComponent<GridLayoutGroup>();
			_grid.spacing = new Vector2(12f, 12f);
			_grid.startCorner = (Corner)1;
			_grid.startAxis = (Axis)0;
			((LayoutGroup)_grid).childAlignment = (TextAnchor)2;
			ContentSizeFitter obj = ((Component)Root).gameObject.AddComponent<ContentSizeFitter>();
			FitMode horizontalFit = (FitMode)2;
			obj.verticalFit = (FitMode)2;
			obj.horizontalFit = horizontalFit;
		}

		public void Refresh(bool samplesIfEmpty)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			List<ChallengeId> list = new List<ChallengeId>();
			foreach (ChallengeId item in PinnedQuestsMod.Pinned)
			{
				if (PinnedQuestsMod.ShowCompleted.Value || !Quests.Progress(item).done)
				{
					list.Add(item);
				}
			}
			bool flag = list.Count == 0 && samplesIfEmpty;
			string text = (flag ? "samples" : string.Join(",", list));
			if (text != _built)
			{
				_built = text;
				foreach (Card card in _cards)
				{
					if ((Object)(object)card.Go != (Object)null)
					{
						Object.Destroy((Object)(object)card.Go);
					}
				}
				_cards.Clear();
				if (flag)
				{
					_cards.Add(Make(new Card
					{
						SampleText = "Pin quests in the Quests menu to see them here.",
						SampleValue = 120,
						SampleTarget = 500
					}));
					_cards.Add(Make(new Card
					{
						SampleText = "Sample quest: defeat 1,000 enemies.",
						SampleValue = 1000,
						SampleTarget = 1000
					}));
				}
				else
				{
					foreach (ChallengeId item2 in list)
					{
						_cards.Add(Make(new Card
						{
							Id = item2
						}));
					}
				}
			}
			foreach (Card card2 in _cards)
			{
				Update(card2);
			}
		}

		public void Place()
		{
			//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_0034: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: 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)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(PinnedQuestsMod.CardWidth.Value, PinnedQuestsMod.CardHeight.Value);
			if (_grid.cellSize != val)
			{
				_grid.cellSize = val;
				foreach (Card card in _cards)
				{
					if ((Object)(object)card.Info != (Object)null)
					{
						card.Info.preferredWidth = val.x - 112f - 88f;
					}
				}
			}
			QuestLayout value = PinnedQuestsMod.Layout.Value;
			Constraint val2 = (Constraint)((value != QuestLayout.Horizontal) ? 1 : 2);
			int num = ((value != QuestLayout.Grid) ? 1 : Mathf.Max(1, PinnedQuestsMod.Columns.Value));
			if (_grid.constraint != val2)
			{
				_grid.constraint = val2;
			}
			if (_grid.constraintCount != num)
			{
				_grid.constraintCount = num;
			}
			float value2 = PinnedQuestsMod.Size.Value;
			((Transform)Root).localScale = new Vector3(value2, value2, 1f);
			Root.anchoredPosition = new Vector2(0f - PinnedQuestsMod.OffsetX.Value, PinnedQuestsMod.OffsetY.Value);
		}

		private static void Update(Card card)
		{
			//IL_0016: 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_001c: 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)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: 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)
			ChallengeId? id = card.Id;
			int num;
			int num2;
			bool flag;
			if (id.HasValue)
			{
				ChallengeId valueOrDefault = id.GetValueOrDefault();
				(num, num2, flag) = Quests.Progress(valueOrDefault);
				card.Text.text = Quests.Text(valueOrDefault);
				if ((Object)(object)card.Icon.sprite == (Object)null)
				{
					Image icon = card.Icon;
					ChallengeConfiguration obj = Quests.Config(valueOrDefault);
					icon.sprite = ((obj != null) ? obj.Icon : null);
					((Behaviour)card.Icon).enabled = (Object)(object)card.Icon.sprite != (Object)null;
				}
			}
			else
			{
				int sampleValue = card.SampleValue;
				num2 = card.SampleTarget;
				num = sampleValue;
				flag = num >= num2;
				card.Text.text = card.SampleText;
				((Behaviour)card.Icon).enabled = false;
			}
			float num3 = (flag ? 1f : ((num2 > 0) ? Mathf.Clamp01((float)num / (float)num2) : 0f));
			card.Fill.anchorMax = new Vector2(num3, 1f);
			((Graphic)card.FillImage).color = (flag ? Green : QuestCards.Gold);
			card.Count.text = (flag ? "Done" : ((num2 > 1) ? $"{num:N0} / {num2:N0}" : "Not yet"));
			((Graphic)card.Count).color = (flag ? Green : QuestCards.Gold);
		}

		private Card Make(Card card)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = new GameObject("Quest").AddComponent<RectTransform>();
			((Transform)val).SetParent((Transform)(object)Root, false);
			card.Go = ((Component)val).gameObject;
			RectTransform obj = new GameObject("Background").AddComponent<RectTransform>();
			((Transform)obj).SetParent((Transform)(object)val, false);
			obj.anchorMin = Vector2.zero;
			obj.anchorMax = Vector2.one;
			Vector2 offsetMin = (obj.offsetMax = Vector2.zero);
			obj.offsetMin = offsetMin;
			((Component)obj).gameObject.AddComponent<LayoutElement>().ignoreLayout = true;
			Image val2 = ((Component)obj).gameObject.AddComponent<Image>();
			((Graphic)val2).raycastTarget = true;
			if (!ApplyStyle(val2))
			{
				((Graphic)val2).color = new Color(0f, 0f, 0f, 0.6f);
			}
			HorizontalLayoutGroup obj2 = ((Component)val).gameObject.AddComponent<HorizontalLayoutGroup>();
			((LayoutGroup)obj2).padding = Pad(30, 36, 22, 22);
			((HorizontalOrVerticalLayoutGroup)obj2).spacing = 22f;
			((LayoutGroup)obj2).childAlignment = (TextAnchor)3;
			bool childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true);
			((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = childControlWidth;
			((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = false;
			((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = true;
			Image val3 = new GameObject("Icon").AddComponent<Image>();
			((Transform)((Graphic)val3).rectTransform).SetParent((Transform)(object)val, false);
			val3.preserveAspect = true;
			((Graphic)val3).raycastTarget = false;
			LayoutElement obj3 = ((Component)val3).gameObject.AddComponent<LayoutElement>();
			float preferredWidth = (obj3.preferredHeight = 112f);
			obj3.preferredWidth = preferredWidth;
			card.Icon = val3;
			RectTransform val4 = new GameObject("Info").AddComponent<RectTransform>();
			((Transform)val4).SetParent((Transform)(object)val, false);
			VerticalLayoutGroup obj4 = ((Component)val4).gameObject.AddComponent<VerticalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)obj4).spacing = 6f;
			childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj4).childControlHeight = true);
			((HorizontalOrVerticalLayoutGroup)obj4).childControlWidth = childControlWidth;
			((HorizontalOrVerticalLayoutGroup)obj4).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj4).childForceExpandHeight = false;
			((LayoutGroup)obj4).childAlignment = (TextAnchor)3;
			card.Info = ((Component)val4).gameObject.AddComponent<LayoutElement>();
			card.Info.preferredWidth = PinnedQuestsMod.CardWidth.Value - 112f - 88f;
			card.Text = Label((Transform)(object)val4, 38f, Color.white, (TextAlignmentOptions)4097, wrap: true);
			card.Text.enableAutoSizing = true;
			card.Text.fontSizeMin = 20f;
			card.Text.fontSizeMax = 38f;
			card.Text.overflowMode = (TextOverflowModes)1;
			LayoutElement obj5 = ((Component)card.Text).gameObject.AddComponent<LayoutElement>();
			obj5.flexibleHeight = 1f;
			obj5.minHeight = 0f;
			obj5.preferredHeight = 0f;
			Image val5 = new GameObject("Bar").AddComponent<Image>();
			((Transform)((Graphic)val5).rectTransform).SetParent((Transform)(object)val4, false);
			((Graphic)val5).color = new Color(1f, 1f, 1f, 0.15f);
			((Graphic)val5).raycastTarget = false;
			((Component)val5).gameObject.AddComponent<LayoutElement>().preferredHeight = 12f;
			Image val6 = new GameObject("Fill").AddComponent<Image>();
			((Transform)((Graphic)val6).rectTransform).SetParent((Transform)(object)((Graphic)val5).rectTransform, false);
			((Graphic)val6).rectTransform.anchorMin = Vector2.zero;
			((Graphic)val6).rectTransform.anchorMax = new Vector2(0f, 1f);
			RectTransform rectTransform = ((Graphic)val6).rectTransform;
			offsetMin = (((Graphic)val6).rectTransform.offsetMax = Vector2.zero);
			rectTransform.offsetMin = offsetMin;
			((Graphic)val6).raycastTarget = false;
			card.Fill = ((Graphic)val6).rectTransform;
			card.FillImage = val6;
			card.Count = Label((Transform)(object)val4, 34f, QuestCards.Gold, (TextAlignmentOptions)516, wrap: false);
			return card;
		}

		private static bool ApplyStyle(Image bg)
		{
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			string value = PinnedQuestsMod.CardStyle.Value;
			if (string.IsNullOrEmpty(value))
			{
				return false;
			}
			string[] array = value.Split('|');
			if (array.Length < 3)
			{
				return false;
			}
			if (_styleKey != value || (Object)(object)_style == (Object)null || ((Il2CppObjectBase)_style).WasCollected)
			{
				_style = null;
				_styleKey = value;
				foreach (Sprite item in Resources.FindObjectsOfTypeAll<Sprite>())
				{
					if ((Object)(object)item != (Object)null && ((Object)item).name == array[0])
					{
						_style = item;
						break;
					}
				}
			}
			if ((Object)(object)_style == (Object)null)
			{
				return false;
			}
			string[] c = array[1].Split(',');
			bg.sprite = _style;
			bg.type = (Type)((array.Length <= 3 || !int.TryParse(array[3], out var result)) ? 1 : result);
			((Graphic)bg).color = new Color(F(0), F(1), F(2), F(3));
			if (float.TryParse(array[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) && result2 > 0f)
			{
				bg.pixelsPerUnitMultiplier = result2;
			}
			return true;
			float F(int i)
			{
				if (c.Length <= i || !float.TryParse(c[i], NumberStyles.Float, CultureInfo.InvariantCulture, out var result3))
				{
					return 1f;
				}
				return result3;
			}
		}

		internal static TMP_Text Label(Transform parent, float size, Color color, TextAlignmentOptions align, bool wrap)
		{
			//IL_0005: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val = new GameObject("Text").AddComponent<TextMeshProUGUI>();
			((Transform)((TMP_Text)val).rectTransform).SetParent(parent, false);
			TMP_FontAsset val2 = Font();
			if ((Object)(object)val2 != (Object)null)
			{
				((TMP_Text)val).font = val2;
				((TMP_Text)val).fontSharedMaterial = ((TMP_Asset)val2).material;
			}
			((TMP_Text)val).fontSize = size;
			((Graphic)val).color = color;
			((TMP_Text)val).alignment = align;
			((TMP_Text)val).textWrappingMode = (TextWrappingModes)(wrap ? 1 : 0);
			((Graphic)val).raycastTarget = false;
			((TMP_Text)val).outlineWidth = 0.15f;
			((TMP_Text)val).outlineColor = new Color32((byte)0, (byte)0, (byte)0, (byte)180);
			return (TMP_Text)(object)val;
		}

		private static TMP_FontAsset Font()
		{
			if ((Object)(object)_font != (Object)null && !((Il2CppObjectBase)_font).WasCollected)
			{
				return _font;
			}
			foreach (TMP_FontAsset item in Resources.FindObjectsOfTypeAll<TMP_FontAsset>())
			{
				if ((Object)(object)item != (Object)null && ((Object)item).name == "TitilliumWeb-SemiBold SDF")
				{
					return _font = item;
				}
			}
			return null;
		}

		internal static RectOffset Pad(int left, int right, int top, int bottom)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			return new RectOffset
			{
				left = left,
				right = right,
				top = top,
				bottom = bottom
			};
		}

		public void Clamp(RectTransform canvas)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_0042: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)canvas == (Object)null))
			{
				LayoutRebuilder.ForceRebuildLayoutImmediate(Root);
				float value = PinnedQuestsMod.Size.Value;
				Rect rect = Root.rect;
				float num = ((Rect)(ref rect)).width * value;
				rect = Root.rect;
				float num2 = ((Rect)(ref rect)).height * value;
				rect = canvas.rect;
				float width = ((Rect)(ref rect)).width;
				rect = canvas.rect;
				float height = ((Rect)(ref rect)).height;
				float num3 = Mathf.Clamp(PinnedQuestsMod.OffsetX.Value, 0f, Mathf.Max(0f, width - num));
				float num4 = Mathf.Clamp(PinnedQuestsMod.OffsetY.Value, (0f - height) / 2f + num2, height / 2f);
				if (Mathf.Abs(num3 - PinnedQuestsMod.OffsetX.Value) > 0.5f)
				{
					PinnedQuestsMod.OffsetX.Value = Mathf.Round(num3);
				}
				if (Mathf.Abs(num4 - PinnedQuestsMod.OffsetY.Value) > 0.5f)
				{
					PinnedQuestsMod.OffsetY.Value = Mathf.Round(num4);
				}
			}
		}
	}
	internal static class Hud
	{
		private static Cards _cards;

		private static Canvas _canvas;

		private static float _nextSearch;

		private static float _nextUpdate;

		private static bool _dragging;

		private static Vector2 _dragStart;

		private static Vector2 _offsetStart;

		private static IntPtr _run;

		private static float _runStart;

		private static bool _captured;

		private static float _editingUntil;

		internal static RectTransform LiveCards()
		{
			if (!EnsureRoot())
			{
				return null;
			}
			_editingUntil = Time.unscaledTime + 0.3f;
			_dragging = false;
			SetVisible(on: true);
			if (Time.unscaledTime >= _nextUpdate)
			{
				_nextUpdate = Time.unscaledTime + 0.5f;
				_cards.Refresh(samplesIfEmpty: true);
			}
			_cards.Place();
			return _cards.Root;
		}

		public static void Tick()
		{
			if (Time.unscaledTime < _editingUntil)
			{
				return;
			}
			try
			{
				RunManager instance = NetworkSingleton<RunManager>.Instance;
				int num;
				if ((Object)(object)instance != (Object)null)
				{
					num = (instance.runHasStarted ? 1 : 0);
					if (num != 0 && ((Il2CppObjectBase)instance).Pointer != _run)
					{
						_run = ((Il2CppObjectBase)instance).Pointer;
						_runStart = Time.unscaledTime;
						_captured = false;
					}
				}
				else
				{
					num = 0;
				}
				if (num == 0)
				{
					_run = IntPtr.Zero;
				}
				if (!((num != 0 && !ShopOpen()) & (PinnedQuestsMod.Show.Value && PinnedQuestsMod.Pinned.Count > 0)))
				{
					SetVisible(on: false);
					_dragging = false;
				}
				else if (EnsureRoot())
				{
					SetVisible(on: true);
					if (Time.unscaledTime >= _nextUpdate)
					{
						_nextUpdate = Time.unscaledTime + 0.5f;
						_cards.Refresh(samplesIfEmpty: false);
					}
					_cards.Place();
					Mouse();
				}
			}
			catch (Exception ex)
			{
				PinnedQuestsMod.Log.Warning("mission cards: " + ex.Message);
				_nextSearch = Time.unscaledTime + 5f;
				_cards = null;
			}
		}

		private static bool ShopOpen()
		{
			StoreManager instance = NetworkSingleton<StoreManager>.Instance;
			if ((Object)(object)instance != (Object)null)
			{
				if (!instance.IsShopPanelActive)
				{
					return instance.IsExitingStore;
				}
				return true;
			}
			return false;
		}

		private static void SetVisible(bool on)
		{
			if (_cards != null && (Object)(object)_cards.Root != (Object)null && !((Il2CppObjectBase)_cards.Root).WasCollected && ((Component)_cards.Root).gameObject.activeSelf != on)
			{
				((Component)_cards.Root).gameObject.SetActive(on);
			}
		}

		private static bool EnsureRoot()
		{
			if (_cards != null && (Object)(object)_cards.Root != (Object)null && !((Il2CppObjectBase)_cards.Root).WasCollected)
			{
				return true;
			}
			_cards = null;
			if (Time.unscaledTime < _nextSearch)
			{
				return false;
			}
			_nextSearch = Time.unscaledTime + 1f;
			Canvas val = null;
			foreach (SpellSlotsDisplay item in Object.FindObjectsOfType<SpellSlotsDisplay>())
			{
				Canvas componentInParent = ((Component)item).GetComponentInParent<Canvas>();
				val = ((componentInParent != null) ? componentInParent.rootCanvas : null);
				if ((Object)(object)val != (Object)null)
				{
					break;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			_canvas = val;
			_cards = new Cards(((Component)val).transform, "PinnedQuests");
			return true;
		}

		private static void Mouse()
		{
			//IL_001d: 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_0035: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_0128: 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_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			Mouse current = Mouse.current;
			if (current == null || !Cursor.visible)
			{
				_dragging = false;
				return;
			}
			Vector2 val = ((InputControl<Vector2>)(object)((Pointer)current).position).ReadValue();
			Camera val2 = (((Object)(object)_canvas != (Object)null && (int)_canvas.renderMode != 0) ? _canvas.worldCamera : null);
			float num = (((Object)(object)_canvas != (Object)null) ? _canvas.scaleFactor : 1f);
			RectTransform canvas = (((Object)(object)_canvas != (Object)null) ? ((Component)_canvas).GetComponent<RectTransform>() : null);
			if (_dragging)
			{
				Vector2 val3 = (val - _dragStart) / num;
				PinnedQuestsMod.OffsetX.Value = Mathf.Round(_offsetStart.x - val3.x);
				PinnedQuestsMod.OffsetY.Value = Mathf.Round(_offsetStart.y + val3.y);
				_cards.Clamp(canvas);
				if (!current.leftButton.isPressed)
				{
					_dragging = false;
				}
			}
			else if (RectTransformUtility.RectangleContainsScreenPoint(_cards.Root, val, val2))
			{
				if (current.leftButton.wasPressedThisFrame)
				{
					_dragging = true;
					_dragStart = val;
					_offsetStart = new Vector2(PinnedQuestsMod.OffsetX.Value, PinnedQuestsMod.OffsetY.Value);
				}
				float y = ((InputControl<Vector2>)(object)current.scroll).ReadValue().y;
				if (Mathf.Abs(y) > 0.01f)
				{
					PinnedQuestsMod.Size.Value = Mathf.Clamp(Mathf.Round((PinnedQuestsMod.Size.Value + Mathf.Sign(y) * 0.05f) * 100f) / 100f, 0.5f, 2f);
					_cards.Clamp(canvas);
				}
			}
		}
	}
	internal static class MenuPage
	{
		private static bool _registered;

		private static Cards _previewCards;

		private static float _nextPreviewRefresh;

		private static readonly HudElement Element = new HudElement
		{
			Name = "Pinned Quests",
			Build = delegate(RectTransform parent)
			{
				_previewCards = new Cards((Transform)(object)parent, "PinnedQuestsPreview");
				_previewCards.Refresh(samplesIfEmpty: true);
				return _previewCards.Root;
			},
			Place = delegate
			{
				if (_previewCards != null)
				{
					if (Time.unscaledTime >= _nextPreviewRefresh)
					{
						_nextPreviewRefresh = Time.unscaledTime + 0.5f;
						_previewCards.Refresh(samplesIfEmpty: true);
					}
					_previewCards.Place();
				}
			},
			Live = Hud.LiveCards,
			GetOffset = () => new Vector2(0f - PinnedQuestsMod.OffsetX.Value, PinnedQuestsMod.OffsetY.Value),
			SetOffset = delegate(Vector2 v)
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				PinnedQuestsMod.OffsetX.Value = 0f - v.x;
				PinnedQuestsMod.OffsetY.Value = v.y;
			},
			GetSize = () => PinnedQuestsMod.Size.Value,
			SetSize = delegate(float v)
			{
				PinnedQuestsMod.Size.Value = v;
			},
			GetDimensions = () => new Vector2(PinnedQuestsMod.CardWidth.Value, PinnedQuestsMod.CardHeight.Value),
			SetDimensions = delegate(Vector2 d)
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				PinnedQuestsMod.CardWidth.Value = d.x;
				PinnedQuestsMod.CardHeight.Value = d.y;
			},
			MinDimensions = new Vector2(400f, 110f),
			MaxDimensions = new Vector2(1600f, 500f),
			Reset = delegate
			{
				PinnedQuestsMod.OffsetX.Value = PinnedQuestsMod.OffsetX.DefaultValue;
				PinnedQuestsMod.OffsetY.Value = PinnedQuestsMod.OffsetY.DefaultValue;
				PinnedQuestsMod.Size.Value = PinnedQuestsMod.Size.DefaultValue;
				PinnedQuestsMod.CardWidth.Value = PinnedQuestsMod.CardWidth.DefaultValue;
				PinnedQuestsMod.CardHeight.Value = PinnedQuestsMod.CardHeight.DefaultValue;
			}
		};

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal static void Register()
		{
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Expected O, but got Unknown
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Expected O, but got Unknown
			_registered = true;
			HudEditor.Register(Element);
			Menu.AddPage("PinnedQuests", "Pinned Quests").Note((Func<string>)(() => "Pin quests with the pin on each quest in the Quests menu.")).Header((Func<string>)(() => "Pinned"))
				.List((Func<IList<ListEntry>>)PinnedEntries, (Func<string>)(() => "No quests pinned."))
				.Buttons((MenuButton[])(object)new MenuButton[2]
				{
					new MenuButton("Edit Position & Size", (Action)EditLayout, false),
					new MenuButton("Unpin All", (Action)PinnedQuestsMod.UnpinAll, true)
				})
				.Note((Func<string>)(() => "Edit Position & Size: drag and resize the quests over the game's HUD. During a mission you can also drag them, and use the mouse wheel over them to resize."))
				.Header((Func<string>)(() => "During Missions"))
				.Entry(PinnedQuestsMod.Show, () => "Show Pinned Quests")
				.Entry(PinnedQuestsMod.ShowCompleted, () => "Show Completed")
				.Entry(PinnedQuestsMod.Layout, () => "Layout")
				.Entry(PinnedQuestsMod.Columns, () => "Grid Columns")
				.Entry(PinnedQuestsMod.CardWidth, () => "Card Width")
				.Entry(PinnedQuestsMod.CardHeight, () => "Card Height")
				.Entry(PinnedQuestsMod.Size, () => "Size")
				.Entry(PinnedQuestsMod.OffsetX, () => "Position X")
				.Entry(PinnedQuestsMod.OffsetY, () => "Position Y");
			PinnedQuestsMod.Changed += Refresh;
		}

		private static void EditLayout()
		{
			HudEditor.Open(Element);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void Refresh()
		{
			if (_registered)
			{
				Menu.Refresh();
			}
		}

		private static IList<ListEntry> PinnedEntries()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: 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)
			//IL_002a: 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: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			List<ListEntry> list = new List<ListEntry>();
			foreach (ChallengeId item in PinnedQuestsMod.Pinned)
			{
				ChallengeId quest = item;
				list.Add(new ListEntry(Quests.Text(quest), (MenuButton[])(object)new MenuButton[1]
				{
					new MenuButton("Unpin", (Action)delegate
					{
						//IL_0001: Unknown result type (might be due to invalid IL or missing references)
						PinnedQuestsMod.Toggle(quest);
					}, false)
				}));
			}
			return list;
		}
	}
	public enum QuestLayout
	{
		Vertical,
		Horizontal,
		Grid
	}
	public class PinnedQuestsMod : MelonMod
	{
		internal static MelonLogger.Instance Log;

		internal static MelonPreferences_Entry<bool> Show;

		internal static MelonPreferences_Entry<bool> ShowCompleted;

		internal static MelonPreferences_Entry<float> Size;

		internal static MelonPreferences_Entry<float> OffsetX;

		internal static MelonPreferences_Entry<float> OffsetY;

		internal static MelonPreferences_Entry<float> CardWidth;

		internal static MelonPreferences_Entry<float> CardHeight;

		internal static MelonPreferences_Entry<QuestLayout> Layout;

		internal static MelonPreferences_Entry<int> Columns;

		internal static MelonPreferences_Entry<string> PinIcon;

		internal static MelonPreferences_Entry<string> CardStyle;

		private static MelonPreferences_Entry<string> PinnedEntry;

		private static MelonPreferences_Entry<string> TextsEntry;

		private static MelonPreferences_Category _category;

		internal static readonly List<ChallengeId> Pinned = new List<ChallengeId>();

		internal static readonly Dictionary<ChallengeId, string> Texts = new Dictionary<ChallengeId, string>();

		private const string Sep = ";;";

		private const string KeySep = "::";

		internal static event Action Changed;

		public override void OnInitializeMelon()
		{
			Log = base.LoggerInstance;
			_category = MelonPreferences.CreateCategory("PinnedQuests", "Pinned Quests");
			Show = _category.CreateEntry("Show", default_value: true, "Show During Missions", "Show your pinned quests and their progress during missions");
			Layout = _category.CreateEntry("Layout", QuestLayout.Vertical, "Layout", "How the quest cards line up: one under another, side by side, or in a grid");
			Columns = _category.CreateEntry("Columns", 2, "Grid Columns", "How many cards side by side in the Grid layout", is_hidden: false, dont_save_default: false, new ValueRange<int>(1, 6));
			CardWidth = _category.CreateEntry("CardWidth", 780f, "Card Width", "Width of each quest card (drag its side edges in the editor)", is_hidden: false, dont_save_default: false, new ValueRange<float>(400f, 1600f));
			CardHeight = _category.CreateEntry("CardHeight", 170f, "Card Height", "Height of each quest card (drag its top or bottom edge in the editor)", is_hidden: false, dont_save_default: false, new ValueRange<float>(110f, 500f));
			ShowCompleted = _category.CreateEntry("ShowCompleted", default_value: true, "Show Completed", "Keep showing pinned quests once they're completed (marked Done)");
			Size = _category.CreateEntry("Size", 0.75f, "Size", "Size of the quest cards (mouse wheel over them during a mission)", is_hidden: false, dont_save_default: false, new ValueRange<float>(0.5f, 2f));
			OffsetX = _category.CreateEntry("OffsetFromRight", 40f, "Position X", "Distance from the right edge (drag the cards during a mission)", is_hidden: false, dont_save_default: false, new ValueRange<float>(0f, 6000f));
			OffsetY = _category.CreateEntry("OffsetY", 150f, "Position Y", "Distance above the middle of the screen (drag the cards during a mission)", is_hidden: false, dont_save_default: false, new ValueRange<float>(-1100f, 1100f));
			PinIcon = _category.CreateEntry("PinIcon", "", "Pin Icon", "Name of the upgrade screen's pin picture, once found", is_hidden: true);
			CardStyle = _category.CreateEntry("CardBackground", "", "Card Background", "The Quests menu cards' background picture and tint, once seen", is_hidden: true);
			PinnedEntry = _category.CreateEntry("Pinned", "", "Pinned", "Pinned quests (ids, comma-separated)", is_hidden: true);
			TextsEntry = _category.CreateEntry("Descriptions", "", "Descriptions", "Quest descriptions copied from the Quests menu", is_hidden: true);
			Load();
			if (Array.Exists(AppDomain.CurrentDomain.GetAssemblies(), (Assembly a) => a.GetName().Name == "BrigadeModMenu"))
			{
				try
				{
					RegisterMenu();
				}
				catch (Exception ex)
				{
					Log.Warning("Mod Menu page: " + ex.Message);
				}
			}
			Log.Msg($"ready — {Pinned.Count} pinned");
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void RegisterMenu()
		{
			MenuPage.Register();
		}

		public override void OnUpdate()
		{
			QuestCards.Tick();
			Hud.Tick();
		}

		internal static bool IsPinned(ChallengeId id)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return Pinned.Contains(id);
		}

		internal static void Toggle(ChallengeId id)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if (!Pinned.Remove(id))
			{
				Pinned.Add(id);
			}
			Save();
		}

		internal static void UnpinAll()
		{
			Pinned.Clear();
			Save();
		}

		internal static void RememberText(ChallengeId id, string text)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrWhiteSpace(text))
			{
				return;
			}
			text = text.Replace(";;", " ").Replace("::", " ").Trim();
			if (!Texts.TryGetValue(id, out var value) || !(value == text))
			{
				Texts[id] = text;
				if (IsPinned(id))
				{
					SaveTexts();
				}
			}
		}

		private static void Load()
		{
			//IL_0036: 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)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			string[] array = (PinnedEntry.Value ?? "").Split(',');
			for (int i = 0; i < array.Length; i++)
			{
				if (Enum.TryParse<ChallengeId>(array[i].Trim(), out ChallengeId result) && !Pinned.Contains(result))
				{
					Pinned.Add(result);
				}
			}
			array = (TextsEntry.Value ?? "").Split(new string[1] { ";;" }, StringSplitOptions.RemoveEmptyEntries);
			foreach (string text in array)
			{
				int num = text.IndexOf("::", StringComparison.Ordinal);
				if (num > 0 && Enum.TryParse<ChallengeId>(text.Substring(0, num), out ChallengeId result2))
				{
					Texts[result2] = text.Substring(num + "::".Length);
				}
			}
		}

		private unsafe static void Save()
		{
			PinnedEntry.Value = string.Join(",", Pinned.ConvertAll((ChallengeId p) => ((object)(*(ChallengeId*)(&p))/*cast due to .constrained prefix*/).ToString()));
			SaveTexts();
			PinnedQuestsMod.Changed?.Invoke();
		}

		private unsafe static void SaveTexts()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			List<string> list = new List<string>();
			foreach (ChallengeId item in Pinned)
			{
				if (Texts.TryGetValue(item, out var value))
				{
					list.Add(((object)(*(ChallengeId*)(&item))/*cast due to .constrained prefix*/).ToString() + "::" + value);
				}
			}
			TextsEntry.Value = string.Join(";;", list);
			_category.SaveToFile(printmsg: false);
		}
	}
	internal static class QuestCards
	{
		private const string ButtonName = "PinnedQuests_Pin";

		internal static readonly Color Gold = new Color(0.96f, 0.76f, 0.3f, 1f);

		private static readonly Color Bright = new Color(1f, 0.86f, 0.15f, 1f);

		private static readonly Color Off = new Color(0.27f, 0.27f, 0.29f, 1f);

		private static float _next;

		private static readonly Dictionary<IntPtr, ChallengeId> CardQuest = new Dictionary<IntPtr, ChallengeId>();

		private static readonly Dictionary<IntPtr, string> LastText = new Dictionary<IntPtr, string>();

		private static Sprite _pin;

		private static float _nextPinSearch;

		public static void Tick()
		{
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime < _next)
			{
				return;
			}
			_next = Time.unscaledTime + 0.5f;
			try
			{
				foreach (ChallengeCategoryPanel item in Object.FindObjectsOfType<ChallengeCategoryPanel>())
				{
					if ((Object)(object)item == (Object)null || !((Component)item).gameObject.activeInHierarchy)
					{
						continue;
					}
					Dictionary<ChallengeConfiguration, ChallengeProgressPanel> challengeProgressPanelsForConfigurations = item.challengeProgressPanelsForConfigurations;
					if (challengeProgressPanelsForConfigurations == null)
					{
						continue;
					}
					Enumerator<ChallengeConfiguration, ChallengeProgressPanel> enumerator2 = challengeProgressPanelsForConfigurations.GetEnumerator();
					while (enumerator2.MoveNext())
					{
						KeyValuePair<ChallengeConfiguration, ChallengeProgressPanel> current2 = enumerator2.Current;
						ChallengeConfiguration key = current2.Key;
						ChallengeProgressPanel value = current2.Value;
						if (!((Object)(object)key == (Object)null) && !((Object)(object)value == (Object)null) && ((Component)value).gameObject.activeInHierarchy)
						{
							Ensure(value, key.Id);
							if (string.IsNullOrEmpty(PinnedQuestsMod.CardStyle.Value))
							{
								RememberStyle(value);
							}
							Remember(value, key.Id);
						}
					}
				}
			}
			catch (Exception ex)
			{
				PinnedQuestsMod.Log.Warning("quest cards: " + ex.Message);
				_next = Time.unscaledTime + 5f;
			}
		}

		private static void Ensure(ChallengeProgressPanel card, ChallengeId id)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: 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_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			CardQuest[((Il2CppObjectBase)card).Pointer] = id;
			Transform val = ((Component)card).transform.Find("PinnedQuests_Pin");
			if ((Object)(object)val != (Object)null && (Object)(object)((Component)val).GetComponentInChildren<TMP_Text>(true) != (Object)null && (Object)(object)PinSprite() != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)((Component)val).gameObject);
				val = null;
			}
			TMP_Text val2 = null;
			Image val7;
			if ((Object)(object)val == (Object)null)
			{
				RectTransform val3 = new GameObject("PinnedQuests_Pin").AddComponent<RectTransform>();
				((Transform)val3).SetParent(((Component)card).transform, false);
				Vector2 val4 = default(Vector2);
				((Vector2)(ref val4))..ctor(1f, 1f);
				val3.pivot = val4;
				Vector2 anchorMin = (val3.anchorMax = val4);
				val3.anchorMin = anchorMin;
				Sprite val6 = PinSprite();
				val3.sizeDelta = (((Object)(object)val6 != (Object)null) ? new Vector2(64f, 64f) : new Vector2(150f, 52f));
				val3.anchoredPosition = new Vector2(-16f, -12f);
				val7 = ((Component)val3).gameObject.AddComponent<Image>();
				val7.sprite = val6;
				val7.preserveAspect = true;
				if ((Object)(object)val6 == (Object)null)
				{
					((Graphic)val7).color = new Color(0f, 0f, 0f, 0.55f);
				}
				Button obj = ((Component)val3).gameObject.AddComponent<Button>();
				((Selectable)obj).transition = (Transition)0;
				Navigation navigation = ((Selectable)obj).navigation;
				navigation.mode = (Mode)0;
				((Selectable)obj).navigation = navigation;
				IntPtr cardPtr = ((Il2CppObjectBase)card).Pointer;
				((UnityEvent)obj.onClick).AddListener(UnityAction.op_Implicit((Action)delegate
				{
					//IL_0014: Unknown result type (might be due to invalid IL or missing references)
					if (CardQuest.TryGetValue(cardPtr, out var value))
					{
						PinnedQuestsMod.Toggle(value);
					}
					_next = 0f;
				}));
				if ((Object)(object)val6 == (Object)null)
				{
					val2 = (TMP_Text)(object)new GameObject("Text").AddComponent<TextMeshProUGUI>();
					((Transform)val2.rectTransform).SetParent((Transform)(object)val3, false);
					val2.rectTransform.anchorMin = Vector2.zero;
					val2.rectTransform.anchorMax = Vector2.one;
					RectTransform rectTransform = val2.rectTransform;
					anchorMin = (val2.rectTransform.offsetMax = Vector2.zero);
					rectTransform.offsetMin = anchorMin;
					TMP_Text componentInChildren = ((Component)card).GetComponentInChildren<TMP_Text>(true);
					if ((Object)(object)componentInChildren != (Object)null)
					{
						val2.font = componentInChildren.font;
						val2.fontSharedMaterial = componentInChildren.fontSharedMaterial;
					}
					val2.fontSize = 30f;
					val2.fontStyle = (FontStyles)1;
					val2.alignment = (TextAlignmentOptions)514;
					((Graphic)val2).raycastTarget = false;
				}
			}
			else
			{
				val7 = ((Component)val).GetComponent<Image>();
				val2 = ((Component)val).GetComponentInChildren<TMP_Text>(true);
			}
			bool flag = PinnedQuestsMod.IsPinned(id);
			if ((Object)(object)val2 != (Object)null)
			{
				val2.text = (flag ? "Pinned" : "Pin");
				((Graphic)val2).color = (flag ? Bright : Off);
			}
			else if ((Object)(object)val7 != (Object)null)
			{
				((Graphic)val7).color = (flag ? Bright : Off);
			}
		}

		private static void Remember(ChallengeProgressPanel card, ChallengeId id)
		{
			//IL_005c: 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)
			LocalizeStringEvent descriptionLocalizer = ((ChallengePanel)card).descriptionLocalizer;
			TMP_Text val = (((Object)(object)descriptionLocalizer != (Object)null) ? ((Component)descriptionLocalizer).GetComponent<TMP_Text>() : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			string text = null;
			try
			{
				LocalizedString stringReference = descriptionLocalizer.StringReference;
				text = ((stringReference != null) ? ((LocalizedReference)stringReference).TableEntryReference.Key : null);
			}
			catch
			{
			}
			if (!(text != $"Challenge_{id}"))
			{
				string text2 = val.text;
				string value;
				bool num = LastText.TryGetValue(((Il2CppObjectBase)card).Pointer, out value) && value == text2;
				LastText[((Il2CppObjectBase)card).Pointer] = text2;
				if (num)
				{
					PinnedQuestsMod.RememberText(id, text2);
				}
			}
		}

		private static void RememberStyle(ChallengeProgressPanel card)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: 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_0175: 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)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: 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_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Expected I4, but got Unknown
			List<(Image, float)> list = new List<(Image, float)>();
			foreach (Image componentsInChild in ((Component)card).GetComponentsInChildren<Image>(true))
			{
				if (!((Object)(object)componentsInChild.sprite == (Object)null) && !(((Object)((Component)componentsInChild).gameObject).name == "PinnedQuests_Pin"))
				{
					Rect rect = ((Graphic)componentsInChild).rectTransform.rect;
					list.Add((componentsInChild, ((Rect)(ref rect)).width * ((Rect)(ref rect)).height));
				}
			}
			if (list.Count == 0)
			{
				return;
			}
			list.Sort(((Image img, float area) a, (Image img, float area) b) => b.area.CompareTo(a.area));
			List<string> list2 = new List<string>();
			Image val = null;
			foreach (var item2 in list)
			{
				Image item = item2.Item1;
				string text = (((Object)item.sprite).name + " " + ((Object)item).name).ToLowerInvariant();
				if (list2.Count < 8)
				{
					DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(7, 6);
					defaultInterpolatedStringHandler.AppendFormatted(((Object)item).name);
					defaultInterpolatedStringHandler.AppendLiteral("=");
					defaultInterpolatedStringHandler.AppendFormatted(((Object)item.sprite).name);
					defaultInterpolatedStringHandler.AppendLiteral(" ");
					defaultInterpolatedStringHandler.AppendFormatted<Type>(item.type);
					defaultInterpolatedStringHandler.AppendLiteral(" ");
					Rect rect2 = ((Graphic)item).rectTransform.rect;
					defaultInterpolatedStringHandler.AppendFormatted(((Rect)(ref rect2)).width, "0");
					defaultInterpolatedStringHandler.AppendLiteral("x");
					rect2 = ((Graphic)item).rectTransform.rect;
					defaultInterpolatedStringHandler.AppendFormatted(((Rect)(ref rect2)).height, "0");
					defaultInterpolatedStringHandler.AppendLiteral(" a=");
					defaultInterpolatedStringHandler.AppendFormatted(((Graphic)item).color.a, "0.##");
					list2.Add(defaultInterpolatedStringHandler.ToStringAndClear());
				}
				if ((Object)(object)val == (Object)null && !text.Contains("fill") && !text.Contains("progress") && !text.Contains("bar") && !text.Contains("icon") && !text.Contains("mask") && !text.Contains("frame_icon"))
				{
					val = item;
				}
			}
			PinnedQuestsMod.Log.Msg("quest card pictures: " + string.Join("; ", list2));
			if (!((Object)(object)val == (Object)null))
			{
				Color color = ((Graphic)val).color;
				string value = FormattableString.Invariant($"{((Object)val.sprite).name}|{color.r},{color.g},{color.b},{color.a}|{val.pixelsPerUnitMultiplier}|{(int)val.type}");
				PinnedQuestsMod.CardStyle.Value = value;
				PinnedQuestsMod.Log.Msg($"quest card background: {value} ({((Object)val).name})");
			}
		}

		internal static Sprite PinSprite()
		{
			if ((Object)(object)_pin != (Object)null && !((Il2CppObjectBase)_pin).WasCollected)
			{
				return _pin;
			}
			if (Time.unscaledTime < _nextPinSearch)
			{
				return null;
			}
			_nextPinSearch = Time.unscaledTime + 10f;
			try
			{
				string value = PinnedQuestsMod.PinIcon.Value;
				if (!string.IsNullOrEmpty(value))
				{
					foreach (Sprite item in Resources.FindObjectsOfTypeAll<Sprite>())
					{
						if ((Object)(object)item != (Object)null && ((Object)item).name == value)
						{
							return _pin = item;
						}
					}
				}
				foreach (PinView item2 in Resources.FindObjectsOfTypeAll<PinView>())
				{
					ClickableButton val = ((item2 != null) ? item2.pinButton : null);
					if ((Object)(object)val == (Object)null)
					{
						continue;
					}
					Sprite val2 = null;
					List<string> list = new List<string>();
					foreach (Image componentsInChild in ((Component)val).GetComponentsInChildren<Image>(true))
					{
						if (!((Object)(object)componentsInChild.sprite == (Object)null))
						{
							list.Add(((Object)componentsInChild).name + "=" + ((Object)componentsInChild.sprite).name);
							if ((Object)(object)val2 == (Object)null || ((Object)componentsInChild.sprite).name.ToLowerInvariant().Contains("pin"))
							{
								val2 = componentsInChild.sprite;
							}
						}
					}
					if (!((Object)(object)val2 == (Object)null))
					{
						PinnedQuestsMod.Log.Msg($"pin icon: {((Object)val2).name} (from the upgrade cards: {string.Join(", ", list)})");
						PinnedQuestsMod.PinIcon.Value = ((Object)val2).name;
						return _pin = val2;
					}
				}
				foreach (Sprite item3 in Resources.FindObjectsOfTypeAll<Sprite>())
				{
					if (!((Object)(object)item3 == (Object)null))
					{
						string text = ((Object)item3).name.ToLowerInvariant();
						if ((text.Contains("_pin") || text.StartsWith("pin")) && !text.Contains("ping") && !text.Contains("spin"))
						{
							PinnedQuestsMod.Log.Msg("pin icon by name: " + ((Object)item3).name);
							return _pin = item3;
						}
					}
				}
			}
			catch (Exception ex)
			{
				PinnedQuestsMod.Log.Warning("pin icon: " + ex.Message);
			}
			return null;
		}

		internal static void Rebuild()
		{
			foreach (ChallengeCategoryPanel item in Object.FindObjectsOfType<ChallengeCategoryPanel>())
			{
				Dictionary<ChallengeConfiguration, ChallengeProgressPanel> val = ((item != null) ? item.challengeProgressPanelsForConfigurations : null);
				if (val == null)
				{
					continue;
				}
				Enumerator<ChallengeConfiguration, ChallengeProgressPanel> enumerator2 = val.GetEnumerator();
				while (enumerator2.MoveNext())
				{
					ChallengeProgressPanel value = enumerator2.Current.Value;
					Transform val2 = ((value != null) ? ((Component)value).transform.Find("PinnedQuests_Pin") : null);
					if ((Object)(object)val2 != (Object)null)
					{
						Object.Destroy((Object)(object)((Component)val2).gameObject);
					}
				}
			}
		}
	}
	internal static class Quests
	{
		private static Dictionary<ChallengeId, ChallengeConfiguration> _configs;

		private static readonly Regex Placeholder = new Regex("\\{[^{}]*\\}", RegexOptions.Compiled);

		private static readonly Dictionary<ChallengeId, string> FromTable = new Dictionary<ChallengeId, string>();

		public static ChallengeConfiguration Config(ChallengeId id)
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			if (_configs == null)
			{
				Dictionary<ChallengeId, ChallengeConfiguration> dictionary = new Dictionary<ChallengeId, ChallengeConfiguration>();
				try
				{
					List<ChallengeConfiguration> val = ChallengeConfigurationRepository.Get();
					int num = 0;
					while (val != null && num < val.Count)
					{
						ChallengeConfiguration val2 = val[num];
						if ((Object)(object)val2 != (Object)null && !dictionary.ContainsKey(val2.Id))
						{
							dictionary[val2.Id] = val2;
						}
						num++;
					}
				}
				catch (Exception ex)
				{
					PinnedQuestsMod.Log.Warning("quest list: " + ex.Message);
				}
				if (dictionary.Count == 0)
				{
					return null;
				}
				_configs = dictionary;
			}
			if (!_configs.TryGetValue(id, out var value) || !((Object)(object)value != (Object)null) || ((Il2CppObjectBase)value).WasCollected)
			{
				return null;
			}
			return value;
		}

		public static (int value, int target, bool done) Progress(ChallengeId id)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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)
			ChallengeConfiguration val = Config(id);
			int item = (((Object)(object)val != (Object)null) ? Mathf.RoundToInt(val.GetTargetValue()) : 0);
			int item2 = 0;
			bool flag = false;
			try
			{
				LocalPlayer instance = SingletonPersistent<LocalPlayer>.Instance;
				ChallengeManager val2 = ((instance != null) ? instance.GetChallengeManager() : null);
				if (val2 != null)
				{
					Dictionary<ChallengeId, ChallengeProgress> progressForChallenges = val2.ProgressForChallenges;
					if (progressForChallenges != null && progressForChallenges.ContainsKey(id))
					{
						ChallengeProgress val3 = progressForChallenges[id];
						if (val3 != null)
						{
							item2 = val3.Value;
							flag = val3.IsCompleted;
						}
					}
					flag |= val2.IsCompleted(id);
				}
			}
			catch
			{
			}
			return (value: item2, target: item, done: flag);
		}

		public unsafe static string Text(ChallengeId id)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			if (PinnedQuestsMod.Texts.TryGetValue(id, out var value))
			{
				return value;
			}
			if (FromTable.TryGetValue(id, out var value2))
			{
				return value2;
			}
			string text = null;
			try
			{
				StringTable table = ((LocalizedDatabase<StringTable, StringTableEntry>)(object)LocalizationSettings.StringDatabase).GetTable(TableReference.op_Implicit("Localization_Strings"), (Locale)null);
				object obj;
				if (table == null)
				{
					obj = null;
				}
				else
				{
					StringTableEntry entry = ((DetailedLocalizationTable<StringTableEntry>)(object)table).GetEntry($"Challenge_{id}");
					obj = ((entry != null) ? entry.Value : null);
				}
				text = (string)obj;
			}
			catch
			{
			}
			string text2;
			if (string.IsNullOrEmpty(text))
			{
				text2 = Readable(((object)(*(ChallengeId*)(&id))/*cast due to .constrained prefix*/).ToString());
			}
			else
			{
				int item = Progress(id).target;
				text2 = Placeholder.Replace(text, item.ToString("N0"));
			}
			FromTable[id] = text2;
			return text2;
		}

		private static string Readable(string name)
		{
			return Regex.Replace(name, "(?<=[a-z0-9])(?=[A-Z])", " ");
		}
	}
}
namespace PinnedQuests.BepInExPlugin
{
	[BepInPlugin("SpellBrigade.PinnedQuests", "Pinned Quests", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		public const string Guid = "SpellBrigade.PinnedQuests";

		public override void Load()
		{
			MelonCompat.Start<PinnedQuestsMod, Runner>((BasePlugin)(object)this, "SpellBrigade.PinnedQuests");
		}
	}
	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
	{
	}
}