Decompiled source of Quiet Badges v0.2.6

plugins/QuietBadges/QuietBadges.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("QuietBadges")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.6.0")]
[assembly: AssemblyInformationalVersion("0.2.6")]
[assembly: AssemblyProduct("QuietBadges")]
[assembly: AssemblyTitle("QuietBadges")]
[assembly: AssemblyVersion("0.2.6.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 QuietBadges
{
	internal sealed class AtlasFont : IDisposable
	{
		private readonly Texture2D _texture;

		private GUIStyle? _fallback;

		public AtlasFont()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("QuietBadges.MenuFont.png") ?? throw new InvalidOperationException("The menu font is missing.");
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			_texture = new Texture2D(2, 2, (TextureFormat)4, false);
			((Object)_texture).name = "QuietBadges UI font";
			((Texture)_texture).filterMode = (FilterMode)1;
			((Texture)_texture).wrapMode = (TextureWrapMode)1;
			if (!ImageConversion.LoadImage(_texture, memoryStream.ToArray(), true))
			{
				throw new InvalidOperationException("The menu font could not be loaded.");
			}
		}

		public static float Width(string text, float size)
		{
			float num = 0f;
			foreach (char key in text)
			{
				num += (FontMetrics.Glyphs.TryGetValue(key, out var value) ? value.Advance : 36f);
			}
			return num * size / 64f;
		}

		public void Draw(Rect rect, string text, float size, Color color, TextAnchor alignment = (TextAnchor)3)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Invalid comparison between Unknown and I4
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: 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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Invalid comparison between Unknown and I4
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: 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)
			if ((int)Event.current.type != 7 || string.IsNullOrEmpty(text))
			{
				return;
			}
			string text2 = text;
			foreach (char key in text2)
			{
				if (!FontMetrics.Glyphs.ContainsKey(key))
				{
					if (_fallback == null)
					{
						_fallback = new GUIStyle(GUI.skin.label)
						{
							clipping = (TextClipping)1
						};
					}
					_fallback.fontSize = (int)(size * 0.8f);
					_fallback.alignment = alignment;
					_fallback.normal.textColor = color;
					GUI.Label(rect, text, _fallback);
					return;
				}
			}
			if (Width(text, size) > ((Rect)(ref rect)).width)
			{
				float num = ((Rect)(ref rect)).width - Width("...", size);
				float num2 = 0f;
				int num3 = 0;
				while (num3 < text.Length && num2 + FontMetrics.Glyphs[text[num3]].Advance * size / 64f <= num)
				{
					num2 += FontMetrics.Glyphs[text[num3++]].Advance * size / 64f;
				}
				text = text.Substring(0, num3) + "...";
			}
			float num4 = Width(text, size);
			float num5 = ((Rect)(ref rect)).x;
			if ((int)alignment == 4)
			{
				num5 += (((Rect)(ref rect)).width - num4) / 2f;
			}
			if ((int)alignment == 5)
			{
				num5 += ((Rect)(ref rect)).width - num4;
			}
			float num6 = size / 64f;
			float num7 = ((Rect)(ref rect)).y + ((Rect)(ref rect)).height / 2f + size * 0.23f;
			Color color2 = GUI.color;
			GUI.color = color;
			text2 = text;
			Rect val2 = default(Rect);
			foreach (char key2 in text2)
			{
				Glyph glyph = FontMetrics.Glyphs[key2];
				Rect val = new Rect(num5 + (float)glyph.Left * num6, num7 + (float)glyph.Top * num6, (float)glyph.W * num6, (float)glyph.H * num6);
				((Rect)(ref val2))..ctor((float)glyph.X / 1024f, 1f - (float)(glyph.Y + glyph.H) / 1024f, (float)glyph.W / 1024f, (float)glyph.H / 1024f);
				GUI.DrawTextureWithTexCoords(val, (Texture)(object)_texture, val2, true);
				num5 += glyph.Advance * num6;
			}
			GUI.color = color2;
		}

		public void Dispose()
		{
			Object.Destroy((Object)(object)_texture);
		}
	}
	internal sealed class BadgeBuildHook
	{
		public MethodInfo Method { get; }

		public FieldInfo? OwnerField { get; }

		private BadgeBuildHook(MethodInfo method, FieldInfo? ownerField = null)
		{
			Method = method;
			OwnerField = ownerField;
		}

		public static BadgeBuildHook Resolve(MethodInfo entry, MethodInfo lockedGetter, FieldInfo status)
		{
			List<CodeInstruction> originalInstructions = PatchProcessor.GetOriginalInstructions((MethodBase)entry, (ILGenerator)null);
			if (HasBadgeLoop(originalInstructions, lockedGetter, status))
			{
				return new BadgeBuildHook(entry);
			}
			List<BadgeBuildHook> list = new List<BadgeBuildHook>();
			foreach (MethodInfo item in (from i in originalInstructions
				where i.opcode == OpCodes.Call || i.opcode == OpCodes.Callvirt
				select i.operand).OfType<MethodInfo>().Distinct())
			{
				if (item.DeclaringType != entry.DeclaringType || item.IsStatic || item.GetParameters().Length != 0 || item.ReturnType != typeof(IEnumerator))
				{
					continue;
				}
				Type type = item.GetCustomAttribute<IteratorStateMachineAttribute>()?.StateMachineType;
				if (type == null || type.DeclaringType != entry.DeclaringType || !type.IsDefined(typeof(CompilerGeneratedAttribute), inherit: false) || !typeof(IEnumerator).IsAssignableFrom(type))
				{
					continue;
				}
				MethodInfo methodInfo = AccessTools.DeclaredMethod(type, "MoveNext", Type.EmptyTypes, (Type[])null);
				if (methodInfo == null || methodInfo.IsStatic || methodInfo.ReturnType != typeof(bool))
				{
					continue;
				}
				List<CodeInstruction> originalInstructions2 = PatchProcessor.GetOriginalInstructions((MethodBase)methodInfo, (ILGenerator)null);
				if (!HasBadgeLoop(originalInstructions2, lockedGetter, status))
				{
					continue;
				}
				FieldInfo[] array = (from f in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
					where f.FieldType == entry.DeclaringType
					select f).ToArray();
				if (array.Length == 1)
				{
					FieldInfo owner = array[0];
					List<CodeInstruction> originalInstructions3 = PatchProcessor.GetOriginalInstructions((MethodBase)item, (ILGenerator)null);
					if (originalInstructions3.Zip(originalInstructions3.Skip(1), (CodeInstruction a, CodeInstruction b) => a.opcode == OpCodes.Ldarg_0 && b.opcode == OpCodes.Stfld && object.Equals(b.operand, owner)).Any((bool v) => v) && originalInstructions2.Any((CodeInstruction i) => i.opcode == OpCodes.Ldfld && object.Equals(i.operand, owner)))
					{
						list.Add(new BadgeBuildHook(methodInfo, owner));
					}
				}
			}
			if (list.Count != 1)
			{
				throw new NotSupportedException("A unique supported badge-building loop was not found; hiding is disabled.");
			}
			return list[0];
		}

		private static bool HasBadgeLoop(IEnumerable<CodeInstruction> body, MethodInfo getter, FieldInfo status)
		{
			if (body.Any((CodeInstruction i) => CodeInstructionExtensions.Calls(i, getter)))
			{
				return body.Any((CodeInstruction i) => i.opcode == OpCodes.Stfld && object.Equals(i.operand, status));
			}
			return false;
		}
	}
	public sealed class BadgeDraft
	{
		private readonly HashSet<string> _hidden = new HashSet<string>(StringComparer.Ordinal);

		public VisibilityMode Mode { get; set; }

		public int SelectionCount => _hidden.Count;

		public string SelectionCsv => string.Join(",", _hidden.OrderBy<string, string>((string s) => s, StringComparer.Ordinal));

		public BadgeDraft(BadgePolicy applied)
		{
			Reset(applied);
		}

		public void Reset(BadgePolicy applied)
		{
			Mode = applied.Mode;
			_hidden.Clear();
			_hidden.UnionWith(applied.HiddenIds);
		}

		public bool IsDirty(BadgePolicy applied)
		{
			if (Mode == applied.Mode)
			{
				return !_hidden.SetEquals(applied.HiddenIds);
			}
			return true;
		}

		public bool IsHidden(string id)
		{
			if (Mode != VisibilityMode.All)
			{
				if (Mode == VisibilityMode.Selected)
				{
					return _hidden.Contains(id);
				}
				return false;
			}
			return true;
		}

		public void Toggle(string id, IEnumerable<string> knownIds)
		{
			bool num = IsHidden(id);
			if (Mode != VisibilityMode.Selected)
			{
				_hidden.Clear();
				if (Mode == VisibilityMode.All)
				{
					_hidden.UnionWith(knownIds);
				}
			}
			Mode = VisibilityMode.Selected;
			if (num)
			{
				_hidden.Remove(id);
			}
			else
			{
				_hidden.Add(id);
			}
		}

		public void Clear()
		{
			_hidden.Clear();
			Mode = VisibilityMode.Selected;
		}

		public BadgePolicy Snapshot()
		{
			return new BadgePolicy(Mode, SelectionCsv);
		}
	}
	public enum VisibilityMode
	{
		Off,
		Selected,
		All
	}
	public sealed class BadgePolicy
	{
		private readonly HashSet<string> _hidden;

		public VisibilityMode Mode { get; }

		public IReadOnlyCollection<string> HiddenIds => (IReadOnlyCollection<string>)(object)_hidden.ToArray();

		public BadgePolicy(VisibilityMode mode, string? hiddenIds)
		{
			Mode = mode;
			_hidden = new HashSet<string>(from s in (hiddenIds ?? string.Empty).Split(new char[4] { ',', ';', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries)
				select s.Trim() into s
				where s.Length != 0
				select s, StringComparer.Ordinal);
		}

		public bool ShouldHide(string id)
		{
			if (Mode != VisibilityMode.All)
			{
				if (Mode == VisibilityMode.Selected)
				{
					return _hidden.Contains(id);
				}
				return false;
			}
			return true;
		}

		public bool LockedForDisplay(bool earnedStateIsLocked, string id, bool isLocalOwner)
		{
			if (!earnedStateIsLocked)
			{
				if (isLocalOwner)
				{
					return ShouldHide(id);
				}
				return false;
			}
			return true;
		}

		public string WithSelection(string id, bool hidden)
		{
			HashSet<string> hashSet = new HashSet<string>(_hidden, StringComparer.Ordinal);
			if (hidden)
			{
				hashSet.Add(id);
			}
			else
			{
				hashSet.Remove(id);
			}
			return string.Join(",", hashSet.OrderBy<string, string>((string s) => s, StringComparer.Ordinal));
		}
	}
	internal static class DisplayPatch
	{
		internal static GameBindings? Api;

		internal static BadgePolicy Policy = new BadgePolicy(VisibilityMode.Off, "");

		internal static Action<string>? ReportFailure;

		internal static bool Faulted;

		internal static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			GameBindings api = Api ?? throw new InvalidOperationException("Game bindings were not initialized.");
			int replacements = 0;
			foreach (CodeInstruction instruction in instructions)
			{
				if (!CodeInstructionExtensions.Calls(instruction, api.BadgeLockedGetter))
				{
					yield return instruction;
					continue;
				}
				CodeInstruction val = new CodeInstruction(OpCodes.Ldarg_0, (object)null);
				val.labels.AddRange(instruction.labels);
				val.blocks.AddRange(instruction.blocks);
				yield return val;
				if (api.BadgeHook.OwnerField != null)
				{
					yield return new CodeInstruction(OpCodes.Ldfld, (object)api.BadgeHook.OwnerField);
				}
				yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(DisplayPatch), "LockedForSash", (Type[])null, (Type[])null));
				replacements++;
			}
			if (replacements == 0)
			{
				throw new NotSupportedException("No supported sash getter calls were found.");
			}
		}

		internal static bool LockedForSash(object badge, object data)
		{
			GameBindings gameBindings = Api ?? throw new InvalidOperationException("Badge bindings are unavailable.");
			bool flag = gameBindings.IsLocked(badge);
			if (flag || Faulted || Policy.Mode == VisibilityMode.Off)
			{
				return flag;
			}
			try
			{
				return Policy.LockedForDisplay(flag, GameBindings.BadgeId(badge), gameBindings.IsLocalData(data));
			}
			catch (Exception ex)
			{
				Faulted = true;
				ReportFailure?.Invoke("Hiding stopped: " + ex.GetBaseException().Message);
				return flag;
			}
		}
	}
	internal readonly struct Glyph
	{
		public readonly int X;

		public readonly int Y;

		public readonly int W;

		public readonly int H;

		public readonly int Left;

		public readonly int Top;

		public readonly float Advance;

		public Glyph(int x, int y, int w, int h, int left, int top, float advance)
		{
			X = x;
			Y = y;
			W = w;
			H = h;
			Left = left;
			Top = top;
			Advance = advance;
		}
	}
	internal static class FontMetrics
	{
		internal static readonly Dictionary<char, Glyph> Glyphs = new Dictionary<char, Glyph>
		{
			[' '] = new Glyph(4, 4, 15, 1, 0, 0, 14.7188f),
			['!'] = new Glyph(25, 4, 18, 44, 0, -42, 17.5938f),
			['"'] = new Glyph(49, 4, 21, 49, 0, -49, 20.5469f),
			['#'] = new Glyph(76, 4, 43, 43, 0, -41, 43.0156f),
			['$'] = new Glyph(125, 4, 32, 48, 0, -43, 32.3906f),
			['%'] = new Glyph(163, 4, 49, 43, 0, -40, 49.2188f),
			['&'] = new Glyph(218, 4, 38, 43, 0, -40, 37.8906f),
			['\''] = new Glyph(262, 4, 13, 48, 0, -48, 12.8594f),
			['('] = new Glyph(281, 4, 21, 44, 0, -40, 21.375f),
			[')'] = new Glyph(308, 4, 20, 43, 0, -39, 19.9688f),
			['*'] = new Glyph(334, 4, 28, 48, 0, -48, 28.2812f),
			['+'] = new Glyph(368, 4, 31, 34, 0, -34, 30.7188f),
			[','] = new Glyph(405, 4, 14, 13, 0, -7, 13.7656f),
			['-'] = new Glyph(425, 4, 24, 23, 0, -23, 23.6875f),
			['.'] = new Glyph(455, 4, 15, 9, 0, -7, 14.7188f),
			['/'] = new Glyph(476, 4, 32, 44, 0, -41, 32f),
			['0'] = new Glyph(514, 4, 43, 43, 0, -41, 43.0781f),
			['1'] = new Glyph(563, 4, 33, 43, 0, -40, 33.2188f),
			['2'] = new Glyph(602, 4, 34, 43, 0, -40, 33.5312f),
			['3'] = new Glyph(642, 4, 34, 46, 0, -43, 34.0469f),
			['4'] = new Glyph(682, 4, 39, 46, 0, -42, 39.1719f),
			['5'] = new Glyph(727, 4, 32, 45, 0, -41, 31.9375f),
			['6'] = new Glyph(765, 4, 35, 46, 0, -44, 34.625f),
			['7'] = new Glyph(806, 4, 36, 43, 0, -40, 36.0938f),
			['8'] = new Glyph(848, 4, 34, 45, 0, -41, 33.9219f),
			['9'] = new Glyph(888, 4, 34, 45, 0, -41, 34.0469f),
			[':'] = new Glyph(928, 4, 16, 32, 0, -32, 16f),
			[';'] = new Glyph(950, 4, 17, 34, 0, -34, 16.5156f),
			['<'] = new Glyph(973, 4, 23, 33, 0, -32, 23.2344f),
			['='] = new Glyph(4, 59, 21, 32, 0, -32, 21.375f),
			['>'] = new Glyph(31, 59, 22, 33, 0, -32, 22.1406f),
			['?'] = new Glyph(59, 59, 34, 46, 0, -44, 34.2344f),
			['@'] = new Glyph(99, 59, 43, 41, 0, -40, 42.875f),
			['A'] = new Glyph(148, 59, 44, 39, 0, -39, 43.7812f),
			['B'] = new Glyph(198, 59, 35, 46, 0, -42, 34.75f),
			['C'] = new Glyph(239, 59, 38, 41, 0, -39, 38.4688f),
			['D'] = new Glyph(283, 59, 39, 42, 0, -40, 39.1094f),
			['E'] = new Glyph(328, 59, 31, 42, 0, -40, 31.1094f),
			['F'] = new Glyph(365, 59, 33, 43, 0, -40, 33.2812f),
			['G'] = new Glyph(404, 59, 39, 43, 0, -40, 38.8438f),
			['H'] = new Glyph(449, 59, 42, 41, 0, -40, 41.7344f),
			['I'] = new Glyph(497, 59, 27, 42, 0, -40, 27.0156f),
			['J'] = new Glyph(530, 59, 35, 46, 0, -42, 35.3906f),
			['K'] = new Glyph(571, 59, 40, 44, 0, -41, 40.0625f),
			['L'] = new Glyph(617, 59, 28, 43, 0, -40, 28.4219f),
			['M'] = new Glyph(651, 59, 50, 41, 0, -40, 50.4375f),
			['N'] = new Glyph(707, 59, 43, 39, 0, -38, 42.5625f),
			['O'] = new Glyph(756, 59, 43, 40, 0, -39, 42.6875f),
			['P'] = new Glyph(805, 59, 38, 41, 0, -39, 37.8906f),
			['Q'] = new Glyph(849, 59, 44, 46, 0, -41, 43.8438f),
			['R'] = new Glyph(899, 59, 41, 43, 0, -41, 40.8281f),
			['S'] = new Glyph(946, 59, 29, 44, 0, -41, 28.9219f),
			['T'] = new Glyph(981, 59, 35, 40, 0, -38, 35.0156f),
			['U'] = new Glyph(4, 111, 42, 38, 0, -38, 42.1094f),
			['V'] = new Glyph(52, 111, 44, 40, 0, -39, 44.1562f),
			['W'] = new Glyph(102, 111, 63, 38, 0, -37, 62.5938f),
			['X'] = new Glyph(171, 111, 44, 44, 0, -41, 43.5781f),
			['Y'] = new Glyph(221, 111, 39, 40, 0, -39, 39.4219f),
			['Z'] = new Glyph(266, 111, 32, 41, 0, -40, 32.25f),
			['['] = new Glyph(304, 111, 19, 44, 0, -41, 18.5f),
			['\\'] = new Glyph(329, 111, 32, 40, 0, -39, 31.5469f),
			[']'] = new Glyph(367, 111, 19, 43, 0, -41, 18.5625f),
			['^'] = new Glyph(392, 111, 24, 48, 0, -48, 24.125f),
			['_'] = new Glyph(422, 111, 32, 10, 0, -8, 31.5469f),
			['`'] = new Glyph(460, 111, 14, 49, 0, -49, 14.2656f),
			['a'] = new Glyph(480, 111, 36, 37, 0, -34, 36.2812f),
			['b'] = new Glyph(522, 111, 33, 45, 0, -43, 32.5156f),
			['c'] = new Glyph(561, 111, 31, 33, 0, -33, 31.1094f),
			['d'] = new Glyph(598, 111, 32, 44, 0, -42, 31.875f),
			['e'] = new Glyph(636, 111, 33, 34, 0, -32, 33.1562f),
			['f'] = new Glyph(675, 111, 31, 44, 0, -42, 30.9062f),
			['g'] = new Glyph(712, 111, 34, 47, 0, -32, 33.7344f),
			['h'] = new Glyph(752, 111, 32, 44, 0, -43, 32f),
			['i'] = new Glyph(790, 111, 17, 44, 0, -42, 16.6406f),
			['j'] = new Glyph(813, 111, 27, 54, 0, -41, 27.1406f),
			['k'] = new Glyph(846, 111, 31, 43, 0, -41, 30.9688f),
			['l'] = new Glyph(883, 111, 23, 39, 0, -39, 22.5938f),
			['m'] = new Glyph(912, 111, 48, 30, 0, -30, 48.4531f),
			['n'] = new Glyph(966, 111, 31, 29, 0, -29, 30.9062f),
			['o'] = new Glyph(4, 171, 34, 31, 0, -31, 33.7969f),
			['p'] = new Glyph(44, 171, 33, 40, 0, -32, 33.2188f),
			['q'] = new Glyph(83, 171, 33, 43, 0, -31, 32.5781f),
			['r'] = new Glyph(122, 171, 28, 33, 0, -32, 27.9688f),
			['s'] = new Glyph(156, 171, 25, 36, 0, -34, 25.4688f),
			['t'] = new Glyph(187, 171, 26, 40, 0, -39, 26.4375f),
			['u'] = new Glyph(219, 171, 32, 31, 0, -30, 32.3906f),
			['v'] = new Glyph(257, 171, 35, 31, 0, -30, 34.75f),
			['w'] = new Glyph(298, 171, 48, 30, 0, -29, 48f),
			['x'] = new Glyph(352, 171, 36, 34, 0, -32, 35.7188f),
			['y'] = new Glyph(394, 171, 34, 41, 0, -32, 33.9219f),
			['z'] = new Glyph(434, 171, 29, 34, 0, -32, 29.375f),
			['{'] = new Glyph(469, 171, 22, 42, 0, -41, 21.7656f),
			['|'] = new Glyph(497, 171, 21, 45, 0, -42, 20.5469f),
			['}'] = new Glyph(524, 171, 23, 43, 0, -40, 22.9688f),
			['~'] = new Glyph(553, 171, 33, 26, 0, -26, 33.2188f),
			['\u00a0'] = new Glyph(592, 171, 15, 1, 0, 0, 14.7188f),
			['¡'] = new Glyph(613, 171, 17, 45, 0, -43, 16.5156f),
			['¢'] = new Glyph(636, 171, 31, 41, 0, -37, 31.4219f),
			['£'] = new Glyph(673, 171, 34, 47, 0, -43, 33.9844f),
			['¤'] = new Glyph(713, 171, 31, 34, 0, -34, 31.2969f),
			['¥'] = new Glyph(750, 171, 33, 44, 0, -43, 33.0312f),
			['¦'] = new Glyph(789, 171, 14, 46, 0, -44, 14.3438f),
			['§'] = new Glyph(809, 171, 31, 55, 0, -45, 30.8438f),
			['\u00a8'] = new Glyph(846, 171, 24, 46, 0, -46, 24.4531f),
			['©'] = new Glyph(876, 171, 44, 42, 0, -40, 44.4844f),
			['ª'] = new Glyph(926, 171, 24, 47, 0, -47, 23.75f),
			['«'] = new Glyph(956, 171, 30, 33, 0, -31, 30.4062f),
			['¬'] = new Glyph(992, 171, 23, 13, 0, -9, 22.7188f),
			['\u00ad'] = new Glyph(4, 232, 1, 1, 0, 0, 0f),
			['®'] = new Glyph(11, 232, 46, 42, 0, -40, 45.9531f),
			['\u00af'] = new Glyph(63, 232, 25, 39, 0, -39, 25.0312f),
			['°'] = new Glyph(94, 232, 25, 46, 0, -46, 25.4688f),
			['±'] = new Glyph(125, 232, 28, 37, 0, -37, 27.8438f),
			['²'] = new Glyph(159, 232, 20, 40, 0, -40, 19.7812f),
			['³'] = new Glyph(185, 232, 17, 41, 0, -41, 17.3438f),
			['\u00b4'] = new Glyph(208, 232, 16, 48, 0, -48, 16.1875f),
			['µ'] = new Glyph(230, 232, 34, 43, 0, -25, 33.7344f),
			['¶'] = new Glyph(270, 232, 44, 44, 0, -41, 43.5781f),
			['·'] = new Glyph(320, 232, 13, 24, 0, -24, 13.1875f),
			['\u00b8'] = new Glyph(339, 232, 20, 16, 0, -7, 20.0938f),
			['¹'] = new Glyph(365, 232, 18, 40, 0, -40, 18.1094f),
			['º'] = new Glyph(389, 232, 25, 47, 0, -47, 24.8906f),
			['»'] = new Glyph(420, 232, 28, 32, 0, -30, 27.6406f),
			['¼'] = new Glyph(454, 232, 45, 43, 0, -41, 45.0625f),
			['½'] = new Glyph(505, 232, 43, 43, 0, -41, 43.1406f),
			['¾'] = new Glyph(554, 232, 48, 41, 0, -40, 47.9375f),
			['¿'] = new Glyph(608, 232, 35, 49, 0, -47, 34.625f),
			['À'] = new Glyph(649, 232, 46, 59, 0, -55, 46.4062f),
			['Á'] = new Glyph(701, 232, 47, 58, 0, -55, 46.9688f),
			['Â'] = new Glyph(754, 232, 47, 58, 0, -54, 47.4844f),
			['Ã'] = new Glyph(807, 232, 48, 55, 0, -53, 47.6094f),
			['Ä'] = new Glyph(861, 232, 46, 55, 0, -52, 45.9531f),
			['Å'] = new Glyph(913, 232, 48, 62, 0, -57, 47.9375f),
			['Æ'] = new Glyph(967, 232, 52, 44, 0, -44, 51.7188f),
			['Ç'] = new Glyph(4, 300, 38, 57, 0, -39, 38.4688f),
			['È'] = new Glyph(48, 300, 30, 58, 0, -55, 29.9531f),
			['É'] = new Glyph(84, 300, 31, 60, 0, -55, 30.7188f),
			['Ê'] = new Glyph(121, 300, 33, 56, 0, -52, 32.5781f),
			['Ë'] = new Glyph(160, 300, 31, 53, 0, -51, 31.4219f),
			['Ì'] = new Glyph(197, 300, 26, 56, 0, -54, 26.0469f),
			['Í'] = new Glyph(229, 300, 25, 56, 0, -52, 25.3438f),
			['Î'] = new Glyph(260, 300, 25, 56, 0, -52, 25.0312f),
			['Ï'] = new Glyph(291, 300, 26, 54, 0, -51, 26.0469f),
			['Ð'] = new Glyph(323, 300, 47, 42, 0, -41, 47.4844f),
			['Ñ'] = new Glyph(376, 300, 43, 54, 0, -52, 42.6875f),
			['Ò'] = new Glyph(425, 300, 43, 56, 0, -53, 43.1406f),
			['Ó'] = new Glyph(474, 300, 43, 56, 0, -53, 43.4531f),
			['Ô'] = new Glyph(523, 300, 43, 57, 0, -53, 42.5625f),
			['Õ'] = new Glyph(572, 300, 35, 49, 0, -47, 35.4531f),
			['Ö'] = new Glyph(613, 300, 44, 54, 0, -53, 43.5781f),
			['×'] = new Glyph(663, 300, 43, 44, 0, -40, 43.0156f),
			['Ø'] = new Glyph(712, 300, 43, 44, 0, -40, 43.4531f),
			['Ù'] = new Glyph(761, 300, 41, 51, 0, -49, 40.8281f),
			['Ú'] = new Glyph(808, 300, 40, 51, 0, -49, 40.25f),
			['Û'] = new Glyph(854, 300, 42, 52, 0, -50, 41.7344f),
			['Ü'] = new Glyph(902, 300, 41, 49, 0, -48, 41.1562f),
			['Ý'] = new Glyph(949, 300, 37, 54, 0, -50, 37.25f),
			['Þ'] = new Glyph(992, 300, 26, 43, 0, -41, 25.9219f),
			['ß'] = new Glyph(4, 366, 35, 46, 0, -42, 35.4531f),
			['à'] = new Glyph(45, 366, 34, 52, 0, -50, 34.4375f),
			['á'] = new Glyph(85, 366, 32, 50, 0, -48, 32.1875f),
			['â'] = new Glyph(123, 366, 33, 48, 0, -46, 33.4062f),
			['ã'] = new Glyph(162, 366, 35, 49, 0, -47, 34.625f),
			['ä'] = new Glyph(203, 366, 35, 48, 0, -47, 35.2031f),
			['å'] = new Glyph(244, 366, 34, 51, 0, -48, 33.8594f),
			['æ'] = new Glyph(284, 366, 48, 37, 0, -34, 48.0625f),
			['ç'] = new Glyph(338, 366, 31, 46, 0, -28, 31.4219f),
			['è'] = new Glyph(375, 366, 34, 50, 0, -48, 34.4375f),
			['é'] = new Glyph(415, 366, 33, 48, 0, -47, 33.4062f),
			['ê'] = new Glyph(454, 366, 34, 50, 0, -48, 33.7344f),
			['ë'] = new Glyph(494, 366, 36, 48, 0, -46, 36.0938f),
			['ì'] = new Glyph(536, 366, 15, 47, 0, -46, 15.4844f),
			['í'] = new Glyph(557, 366, 15, 48, 0, -46, 15.4844f),
			['î'] = new Glyph(578, 366, 25, 46, 0, -46, 25.3438f),
			['ï'] = new Glyph(609, 366, 25, 44, 0, -44, 25.3438f),
			['ð'] = new Glyph(640, 366, 32, 44, 0, -41, 31.75f),
			['ñ'] = new Glyph(678, 366, 34, 44, 0, -44, 33.9844f),
			['ò'] = new Glyph(718, 366, 35, 48, 0, -48, 35.3281f),
			['ó'] = new Glyph(759, 366, 35, 46, 0, -46, 35.0156f),
			['ô'] = new Glyph(800, 366, 37, 48, 0, -47, 36.9219f),
			['õ'] = new Glyph(843, 366, 35, 47, 0, -46, 35.4531f),
			['ö'] = new Glyph(884, 366, 36, 44, 0, -44, 35.7812f),
			['÷'] = new Glyph(926, 366, 26, 35, 0, -35, 25.7969f),
			['ø'] = new Glyph(958, 366, 35, 36, 0, -32, 35.3281f),
			['ù'] = new Glyph(4, 424, 32, 46, 0, -46, 31.875f),
			['ú'] = new Glyph(42, 424, 33, 46, 0, -46, 32.7656f),
			['û'] = new Glyph(81, 424, 33, 48, 0, -48, 32.7656f),
			['ü'] = new Glyph(120, 424, 32, 43, 0, -43, 32f),
			['ý'] = new Glyph(158, 424, 36, 57, 0, -48, 36.4844f),
			['þ'] = new Glyph(200, 424, 28, 52, 0, -40, 28.0938f),
			['ÿ'] = new Glyph(234, 424, 37, 56, 0, -47, 37.25f)
		};
	}
	internal sealed class BadgeEntry
	{
		public string Id = "";

		public string Label = "";

		public bool Earned;

		public Texture? Icon;

		public Rect IconUv = new Rect(0f, 0f, 1f, 1f);
	}
	internal sealed class GameBindings
	{
		private static readonly Dictionary<(Type Type, string Name), MemberInfo?> Members = new Dictionary<(Type, string), MemberInfo>();

		public Type CharacterType;

		public Type CharacterDataType;

		public MethodInfo SetBadgeStatus;

		public BadgeBuildHook BadgeHook;

		public MethodInfo BadgeLockedGetter;

		public FieldInfo BadgeStatus;

		private Type _guiType;

		private Func<bool>? _statsReady;

		public static GameBindings Discover()
		{
			GameBindings gameBindings = new GameBindings();
			gameBindings.CharacterType = RequireType("Character");
			gameBindings.CharacterDataType = RequireType("CharacterData");
			Type type = RequireType("BadgeData");
			gameBindings._guiType = RequireType("GUIManager");
			gameBindings.SetBadgeStatus = AccessTools.DeclaredMethod(gameBindings.CharacterDataType, "SetBadgeStatus", Type.EmptyTypes, (Type[])null) ?? throw new NotSupportedException("CharacterData.SetBadgeStatus() was not found.");
			gameBindings.BadgeLockedGetter = AccessTools.PropertyGetter(type, "IsLocked") ?? throw new NotSupportedException("BadgeData.IsLocked was not found.");
			gameBindings.BadgeStatus = AccessTools.Field(gameBindings.CharacterDataType, "badgeStatus") ?? throw new NotSupportedException("CharacterData.badgeStatus was not found.");
			if (gameBindings.SetBadgeStatus.IsStatic || gameBindings.SetBadgeStatus.ReturnType != typeof(void) || gameBindings.BadgeLockedGetter.IsStatic || gameBindings.BadgeLockedGetter.ReturnType != typeof(bool) || gameBindings.BadgeStatus.FieldType != typeof(bool[]))
			{
				throw new NotSupportedException("PEAK's badge API shape differs from the researched version.");
			}
			gameBindings.BadgeHook = BadgeBuildHook.Resolve(gameBindings.SetBadgeStatus, gameBindings.BadgeLockedGetter, gameBindings.BadgeStatus);
			if (gameBindings.BadgeHook.OwnerField != null)
			{
				MethodInfo methodInfo = AccessTools.PropertyGetter(RequireType("AchievementManager"), "GotStats");
				if (methodInfo == null || !methodInfo.IsStatic || methodInfo.ReturnType != typeof(bool) || methodInfo.GetParameters().Length != 0)
				{
					throw new NotSupportedException("AchievementManager.GotStats has changed; hiding is disabled.");
				}
				gameBindings._statsReady = (Func<bool>)Delegate.CreateDelegate(typeof(Func<bool>), methodInfo);
			}
			return gameBindings;
		}

		private static Type RequireType(string name)
		{
			return Type.GetType(name + ", Assembly-CSharp", throwOnError: false) ?? throw new NotSupportedException("PEAK type missing: " + name);
		}

		internal static object? GetMember(Type type, object? instance, string name)
		{
			(Type, string) key = (type, name);
			if (!Members.TryGetValue(key, out MemberInfo value))
			{
				value = (MemberInfo)(((object)AccessTools.Field(type, name)) ?? ((object)AccessTools.Property(type, name)));
				Members.Add(key, value);
			}
			if (!(value is FieldInfo fieldInfo))
			{
				if (value is PropertyInfo propertyInfo)
				{
					return propertyInfo.GetValue(instance, null);
				}
				return null;
			}
			return fieldInfo.GetValue(instance);
		}

		internal static object? GetMember(object instance, string name)
		{
			return GetMember(instance.GetType(), instance, name);
		}

		public object? LocalData()
		{
			object member = GetMember(CharacterType, null, "localCharacter");
			if (member != null)
			{
				Object val = (Object)((member is Object) ? member : null);
				if (val == null || Object.op_Implicit(val))
				{
					return GetMember(member, "data");
				}
			}
			return null;
		}

		public bool IsLocalData(object data)
		{
			object obj = LocalData();
			if (obj != null)
			{
				return obj == data;
			}
			Component val = (Component)((data is Component) ? data : null);
			if (val != null)
			{
				Component component = val.GetComponent(CharacterType);
				bool flag = default(bool);
				int num;
				if ((Object)(object)component != (Object)null)
				{
					object member = GetMember(component, "IsLocal");
					if (member is bool)
					{
						flag = (bool)member;
						num = 1;
					}
					else
					{
						num = 0;
					}
				}
				else
				{
					num = 0;
				}
				return (byte)((uint)num & (flag ? 1u : 0u)) != 0;
			}
			return false;
		}

		public bool IsLocked(object badge)
		{
			return (bool)BadgeLockedGetter.Invoke(badge, null);
		}

		public bool CanRefresh()
		{
			if (_statsReady != null && !_statsReady())
			{
				return false;
			}
			object member = GetMember(_guiType, null, "instance");
			if (member != null)
			{
				Object val = (Object)((member is Object) ? member : null);
				if (val == null || Object.op_Implicit(val))
				{
					object member2 = GetMember(member, "mainBadgeManager");
					if (member2 != null)
					{
						Object val2 = (Object)((member2 is Object) ? member2 : null);
						if ((val2 == null || Object.op_Implicit(val2)) && GetMember(member2, "badgeData") is Array array)
						{
							return array.Length > 0;
						}
					}
					return false;
				}
			}
			return false;
		}

		public static string BadgeId(object badge)
		{
			object member = GetMember(badge, "linkedAchievement");
			if (member != null && member.ToString() != "NONE")
			{
				return member.ToString();
			}
			Object val = (Object)((badge is Object) ? badge : null);
			if (val == null)
			{
				return "";
			}
			return val.name;
		}

		public List<BadgeEntry> Catalog()
		{
			//IL_013d: 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_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			List<BadgeEntry> list = new List<BadgeEntry>();
			HashSet<string> hashSet = new HashSet<string>(StringComparer.Ordinal);
			object member = GetMember(_guiType, null, "instance");
			object obj = ((member == null) ? null : GetMember(member, "mainBadgeManager"));
			if (obj == null || !(GetMember(obj, "badgeData") is Array array))
			{
				return list;
			}
			foreach (object item in array)
			{
				if (item == null)
				{
					continue;
				}
				Object val = (Object)((item is Object) ? item : null);
				if (val != null && !Object.op_Implicit(val))
				{
					continue;
				}
				string text = BadgeId(item);
				if (text.Length == 0 || !hashSet.Add(text))
				{
					continue;
				}
				string text2 = GetMember(item, "displayName") as string;
				if (string.IsNullOrWhiteSpace(text2))
				{
					text2 = Regex.Replace(text.Replace("_", " "), "(?<=[a-z])(?=[A-Z])", " ");
				}
				BadgeEntry badgeEntry = new BadgeEntry
				{
					Id = text,
					Label = text2,
					Earned = !IsLocked(item)
				};
				object member2 = GetMember(item, "icon");
				badgeEntry.Icon = (Texture?)((member2 is Texture) ? member2 : null);
				Sprite val2 = (Sprite)((member2 is Sprite) ? member2 : null);
				if (val2 != null)
				{
					try
					{
						Rect textureRect = val2.textureRect;
						badgeEntry.Icon = (Texture?)(object)val2.texture;
						badgeEntry.IconUv = new Rect(((Rect)(ref textureRect)).x / (float)((Texture)val2.texture).width, ((Rect)(ref textureRect)).y / (float)((Texture)val2.texture).height, ((Rect)(ref textureRect)).width / (float)((Texture)val2.texture).width, ((Rect)(ref textureRect)).height / (float)((Texture)val2.texture).height);
					}
					catch (UnityException)
					{
						badgeEntry.Icon = null;
					}
				}
				list.Add(badgeEntry);
			}
			return list.OrderByDescending((BadgeEntry r) => r.Earned).ThenBy<BadgeEntry, string>((BadgeEntry r) => r.Label, StringComparer.Ordinal).ToList();
		}

		public void Refresh(object data)
		{
			SetBadgeStatus.Invoke(data, null);
		}
	}
	internal sealed class MenuKeyCapture
	{
		public static readonly KeyCode[] ModifierKeys;

		public bool IsOpen { get; private set; }

		public KeyCode MainKey { get; private set; }

		public KeyCode[] Modifiers { get; private set; } = Array.Empty<KeyCode>();

		public string Error { get; set; } = "";

		public bool HasCandidate => (int)MainKey > 0;

		public string Label
		{
			get
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				if (!HasCandidate)
				{
					return "Press your new key...";
				}
				return Format(MainKey, Modifiers);
			}
		}

		public void Begin()
		{
			IsOpen = true;
			MainKey = (KeyCode)0;
			Modifiers = Array.Empty<KeyCode>();
			Error = "";
		}

		public void Cancel()
		{
			IsOpen = false;
		}

		public static bool IsModifier(KeyCode key)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Invalid comparison between Unknown and I4
			if (Array.IndexOf(ModifierKeys, key) < 0)
			{
				return (int)key == 313;
			}
			return true;
		}

		public bool Capture(KeyCode key, IEnumerable<KeyCode> heldModifiers)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			//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_0028: Invalid comparison between Unknown and I4
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			if (!IsOpen || (int)key == 0)
			{
				return false;
			}
			if ((int)key == 27)
			{
				Cancel();
				return true;
			}
			if (IsModifier(key) || (int)key >= 323)
			{
				return false;
			}
			MainKey = key;
			Modifiers = (from k in heldModifiers.Where(IsModifier).Distinct()
				orderby (int)k
				select k).ToArray();
			Error = "";
			return true;
		}

		public static string Format(KeyCode key, IEnumerable<KeyCode> modifiers)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			return string.Join(" + ", modifiers.Select(KeyName).Concat(new string[1] { KeyName(key) }));
		}

		private unsafe static string KeyName(KeyCode key)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected I4, but got Unknown
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected I4, but got Unknown
			if ((int)key != 0)
			{
				return (key - 48) switch
				{
					0 => "0", 
					1 => "1", 
					2 => "2", 
					3 => "3", 
					4 => "4", 
					5 => "5", 
					6 => "6", 
					7 => "7", 
					8 => "8", 
					9 => "9", 
					_ => (key - 303) switch
					{
						3 => "L Ctrl", 
						2 => "R Ctrl", 
						1 => "L Shift", 
						0 => "R Shift", 
						5 => "L Alt", 
						4 => "R Alt", 
						7 => "L Cmd", 
						6 => "R Cmd", 
						8 => "L Win", 
						9 => "R Win", 
						_ => ((object)(*(KeyCode*)(&key))/*cast due to .constrained prefix*/).ToString(), 
					}, 
				};
			}
			return "Not set";
		}

		static MenuKeyCapture()
		{
			KeyCode[] array = new KeyCode[10];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			ModifierKeys = (KeyCode[])(object)array;
		}
	}
	internal sealed class MenuTheme : IDisposable
	{
		public static readonly Color Ink = C(39, 74, 94);

		public static readonly Color Paper = C(246, 239, 215);

		public static readonly Color Muted = C(112, 119, 113);

		public static readonly Color Blue = C(103, 165, 205);

		public static readonly Color Orange = C(219, 132, 78);

		public static readonly Color Green = C(76, 142, 122);

		public static readonly Color Gold = C(232, 187, 87);

		private readonly Texture2D _dots = MakeDots();

		private readonly Texture2D _stitch = MakeStitch();

		private readonly Texture2D _unchecked = MakeCheckbox(selected: false, enabled: true);

		private readonly Texture2D _checked = MakeCheckbox(selected: true, enabled: true);

		private readonly Texture2D _checkedDisabled = MakeCheckbox(selected: true, enabled: false);

		public readonly AtlasFont Font = new AtlasFont();

		public readonly GUIStyle Search;

		public MenuTheme()
		{
			//IL_0059: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			//IL_007e: 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_0089: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: 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_0109: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(GUI.skin.textField)
			{
				fontSize = 20,
				alignment = (TextAnchor)3,
				padding = new RectOffset(15, 32, 3, 3),
				border = new RectOffset(),
				margin = new RectOffset()
			};
			val.normal.background = null;
			val.normal.textColor = Ink;
			val.hover.background = null;
			val.hover.textColor = Ink;
			val.active.background = null;
			val.active.textColor = Ink;
			val.focused.background = null;
			val.focused.textColor = Ink;
			Search = val;
		}

		public static Color C(byte r, byte g, byte b, byte a = byte.MaxValue)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			return new Color((float)(int)r / 255f, (float)(int)g / 255f, (float)(int)b / 255f, (float)(int)a / 255f);
		}

		public static void Fill(Rect rect, Color color)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_000e: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			if ((int)Event.current.type == 7)
			{
				Color color2 = GUI.color;
				GUI.color = color;
				GUI.DrawTexture(rect, (Texture)(object)Texture2D.whiteTexture);
				GUI.color = color2;
			}
		}

		public void PaperDots(Rect rect)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			if ((int)Event.current.type == 7)
			{
				Color color = GUI.color;
				GUI.color = C(222, 215, 189, 130);
				GUI.DrawTextureWithTexCoords(rect, (Texture)(object)_dots, new Rect(0f, 0f, ((Rect)(ref rect)).width / 24f, ((Rect)(ref rect)).height / 24f), true);
				GUI.color = color;
			}
		}

		public void Panel(Rect r, Color color, float radius = 10f)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			if ((int)Event.current.type == 7 && !(((Rect)(ref r)).width <= 0f) && !(((Rect)(ref r)).height <= 0f))
			{
				float num = Mathf.Max(0f, Mathf.Min(radius, Mathf.Min(((Rect)(ref r)).width, ((Rect)(ref r)).height) / 2f));
				GUI.DrawTexture(r, (Texture)(object)Texture2D.whiteTexture, (ScaleMode)0, true, 0f, color, 0f, num);
			}
		}

		public bool Button(Rect rect, string text, Color color, bool enabled = true, float size = 26f, bool active = false)
		{
			//IL_0018: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: 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_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: 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_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Invalid comparison between Unknown and I4
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: 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_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			bool enabled2 = GUI.enabled;
			GUI.enabled = enabled;
			bool flag = enabled && ((Rect)(ref rect)).Contains(Event.current.mousePosition);
			Panel(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y + 4f, ((Rect)(ref rect)).width, ((Rect)(ref rect)).height), C(38, 66, 78, 65));
			if (active)
			{
				Panel(new Rect(((Rect)(ref rect)).x - 3f, ((Rect)(ref rect)).y - 3f, ((Rect)(ref rect)).width + 6f, ((Rect)(ref rect)).height + 6f), Ink, 12f);
			}
			Panel(rect, (!enabled) ? C(199, 199, 180) : (flag ? Color.Lerp(color, Color.white, 0.12f) : color));
			Color color2 = (enabled ? C(byte.MaxValue, 250, 230, 145) : C(231, 230, 213));
			if ((int)Event.current.type == 7)
			{
				Color color3 = GUI.color;
				GUI.color = color2;
				float num = Mathf.Max(0f, ((Rect)(ref rect)).width - 28f);
				Rect val = default(Rect);
				((Rect)(ref val))..ctor(0f, 0f, num / 14f, 1f);
				GUI.DrawTextureWithTexCoords(new Rect(((Rect)(ref rect)).x + 13f, ((Rect)(ref rect)).y + 6f, num, 1f), (Texture)(object)_stitch, val, true);
				GUI.DrawTextureWithTexCoords(new Rect(((Rect)(ref rect)).x + 13f, ((Rect)(ref rect)).yMax - 7f, num, 1f), (Texture)(object)_stitch, val, true);
				GUI.color = color3;
			}
			Font.Draw(new Rect(((Rect)(ref rect)).x + 10f, ((Rect)(ref rect)).y, ((Rect)(ref rect)).width - 20f, ((Rect)(ref rect)).height), text, size, enabled ? Paper : C(124, 130, 119), (TextAnchor)4);
			bool result = GUI.Button(rect, GUIContent.none, GUIStyle.none);
			GUI.enabled = enabled2;
			return result;
		}

		public void Check(Rect rect, bool selected, bool enabled = true)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_000e: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			if ((int)Event.current.type == 7)
			{
				Color color = GUI.color;
				GUI.color = Color.white;
				GUI.DrawTexture(rect, (Texture)(object)((!selected) ? _unchecked : (enabled ? _checked : _checkedDisabled)));
				GUI.color = color;
			}
		}

		private static Texture2D MakeCheckbox(bool selected, bool enabled)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			//IL_006b: 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)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: 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_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false)
			{
				name = "QuietBadges checkbox " + ((!selected) ? "empty" : (enabled ? "checked" : "disabled")),
				filterMode = (FilterMode)1,
				wrapMode = (TextureWrapMode)1
			};
			Color[] array = (Color[])(object)new Color[4096];
			Color val2 = ((selected && enabled) ? Green : C(150, 148, 125));
			Color val3 = (selected ? Green : Paper);
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float x = ((float)j + 0.5f) / 64f;
					float y = 1f - ((float)i + 0.5f) / 64f;
					float a = RoundedMask(x, y, 0.5f, 0.2f, 64);
					float num = RoundedMask(x, y, 0.4f, 0.1f, 64);
					Color val4 = Color.Lerp(val2, val3, num);
					if (selected)
					{
						float num2 = Mathf.Min(SegmentDistance(x, y, 0.23f, 0.51f, 0.43f, 0.71f), SegmentDistance(x, y, 0.43f, 0.71f, 0.79f, 0.28f));
						float num3 = Mathf.Clamp01(0.5f - (num2 - 0.06f) * 64f);
						val4 = Color.Lerp(val4, Paper, num3);
					}
					val4.a = a;
					array[i * 64 + j] = val4;
				}
			}
			val.SetPixels(array);
			val.Apply(false, true);
			return val;
		}

		private static float RoundedMask(float x, float y, float halfSize, float radius, int resolution)
		{
			float num = Math.Abs(x - 0.5f) - (halfSize - radius);
			float num2 = Math.Abs(y - 0.5f) - (halfSize - radius);
			float num3 = Mathf.Max(num, 0f);
			float num4 = Mathf.Max(num2, 0f);
			float num5 = Mathf.Sqrt(num3 * num3 + num4 * num4) + Mathf.Min(Mathf.Max(num, num2), 0f) - radius;
			return Mathf.Clamp01(0.5f - num5 * (float)resolution);
		}

		private static float SegmentDistance(float x, float y, float ax, float ay, float bx, float by)
		{
			float num = bx - ax;
			float num2 = by - ay;
			float num3 = Mathf.Clamp01(((x - ax) * num + (y - ay) * num2) / (num * num + num2 * num2));
			float num4 = x - (ax + num3 * num);
			float num5 = y - (ay + num3 * num2);
			return Mathf.Sqrt(num4 * num4 + num5 * num5);
		}

		private static Texture2D MakeDots()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(24, 24, (TextureFormat)4, false)
			{
				name = "QuietBadges paper dots",
				filterMode = (FilterMode)1,
				wrapMode = (TextureWrapMode)0
			};
			Color[] array = (Color[])(object)new Color[576];
			for (int i = 0; i < 24; i++)
			{
				for (int j = 0; j < 24; j++)
				{
					float num = (float)j - 11.5f;
					float num2 = (float)i - 11.5f;
					array[i * 24 + j] = new Color(1f, 1f, 1f, Mathf.Clamp01(1.5f - Mathf.Sqrt(num * num + num2 * num2)));
				}
			}
			val.SetPixels(array);
			val.Apply(false, true);
			return val;
		}

		private static Texture2D MakeStitch()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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_0024: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(14, 1, (TextureFormat)4, false)
			{
				name = "QuietBadges button stitch",
				filterMode = (FilterMode)1,
				wrapMode = (TextureWrapMode)0
			};
			Color[] array = (Color[])(object)new Color[14];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = new Color(1f, 1f, 1f, (float)((i < 7) ? 1 : 0));
			}
			val.SetPixels(array);
			val.Apply(false, true);
			return val;
		}

		public void Dispose()
		{
			Font.Dispose();
			Object.Destroy((Object)(object)_dots);
			Object.Destroy((Object)(object)_stitch);
			Object.Destroy((Object)(object)_unchecked);
			Object.Destroy((Object)(object)_checked);
			Object.Destroy((Object)(object)_checkedDisabled);
		}
	}
	internal sealed class ModalInputBridge : IDisposable
	{
		private static ModalInputBridge? _active;

		private readonly Harmony _harmony = new Harmony("mcmannybell.quietbadges.menu-input");

		private readonly ModalInputGate _gate = new ModalInputGate();

		private readonly HashSet<Component> _systems = new HashSet<Component>();

		private readonly List<Behaviour> _modules = new List<Behaviour>();

		private readonly Action<string> _report;

		private readonly Func<object?> _gui;

		private readonly Func<object?> _eventSystem;

		private readonly Action<object, bool> _setBlocking;

		private readonly Action<object, bool> _setShowing;

		private readonly Func<object, bool> _getShowing;

		private readonly MethodInfo _updateWindows;

		private readonly MethodInfo _deactivateModule;

		private readonly Type _moduleType;

		private CursorLockMode _previousLock;

		private bool _previousVisible;

		private bool _ownsCursor;

		private bool _faulted;

		public bool Blocking => _gate.Blocking;

		public ModalInputBridge(Action<string> report)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			_report = report;
			Type type = RequireType("GUIManager");
			Type type2 = RequireType("CursorHandler");
			Type type3 = RequireType("UnityEngine.EventSystems.EventSystem");
			_moduleType = RequireType("UnityEngine.EventSystems.BaseInputModule");
			_gui = StaticGetter(type, "instance");
			_eventSystem = StaticGetter(type3, "current");
			_setBlocking = BoolSetter(type, "windowBlockingInput");
			_setShowing = BoolSetter(type, "windowShowingCursor");
			_getShowing = BoolGetter(type, "windowShowingCursor");
			_updateWindows = RequireVoid(type, "UpdateWindowStatus");
			_deactivateModule = RequireVoid(_moduleType, "DeactivateModule");
			MethodInfo methodInfo = RequireVoid(type, "UpdatePaused");
			MethodInfo methodInfo2 = RequireVoid(type2, "Update");
			MethodInfo methodInfo3 = RequireVoid(type3, "Update");
			try
			{
				_harmony.Patch((MethodBase)_updateWindows, (HarmonyMethod)null, Hook("WindowPostfix", 0), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				_harmony.Patch((MethodBase)methodInfo, Hook("PausePrefix", 800), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				_harmony.Patch((MethodBase)methodInfo2, Hook("CursorPrefix", 800), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				_harmony.Patch((MethodBase)methodInfo3, Hook("EventPrefix", 800), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				_active = this;
			}
			catch
			{
				_harmony.UnpatchSelf();
				throw;
			}
		}

		public void Open()
		{
			//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)
			if (_faulted)
			{
				throw new InvalidOperationException("Menu input protection is unavailable. Restart PEAK and check the log.");
			}
			if (!_gate.Blocking)
			{
				_previousLock = Cursor.lockState;
				_previousVisible = Cursor.visible;
				_ownsCursor = true;
			}
			_gate.Open();
			try
			{
				object obj = _eventSystem();
				Component val = (Component)((obj is Component) ? obj : null);
				if (val != null && Object.op_Implicit((Object)(object)val))
				{
					Suspend(val);
				}
				Maintain();
			}
			catch
			{
				Release();
				throw;
			}
		}

		public void Close()
		{
			_gate.Close(Time.frameCount);
		}

		public void Tick()
		{
			if (!Blocking)
			{
				return;
			}
			try
			{
				if (_gate.Tick(Time.frameCount, !_gate.IsOpen && UnityInput.Current.anyKey))
				{
					Release();
				}
				else
				{
					Maintain();
				}
			}
			catch (Exception ex)
			{
				Fail(ex);
			}
		}

		public void MaintainCursor()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			if (Blocking && Application.isFocused)
			{
				if ((int)Cursor.lockState != 0)
				{
					Cursor.lockState = (CursorLockMode)0;
				}
				if (!Cursor.visible)
				{
					Cursor.visible = true;
				}
			}
		}

		private void Maintain()
		{
			object obj = _gui();
			if (Alive(obj))
			{
				SetWindowFlags(obj);
			}
			MaintainCursor();
		}

		private void SetWindowFlags(object gui)
		{
			_setBlocking(gui, arg2: true);
			_setShowing(gui, arg2: true);
		}

		private void Suspend(Component system, bool rescan = false)
		{
			if (!_systems.Add(system) && !rescan)
			{
				return;
			}
			Component[] components = system.GetComponents(_moduleType);
			foreach (Component obj in components)
			{
				Behaviour val = (Behaviour)(object)((obj is Behaviour) ? obj : null);
				if (val != null && Object.op_Implicit((Object)(object)val) && val.enabled)
				{
					if (!_modules.Contains(val))
					{
						_modules.Add(val);
					}
					_deactivateModule.Invoke(val, null);
					val.enabled = false;
				}
			}
		}

		public void Release()
		{
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			foreach (Component system in _systems)
			{
				if (Object.op_Implicit((Object)(object)system))
				{
					TryCleanup(delegate
					{
						Suspend(system, rescan: true);
					});
				}
			}
			_gate.Reset();
			foreach (Behaviour module in _modules)
			{
				if (Object.op_Implicit((Object)(object)module))
				{
					TryCleanup(delegate
					{
						_deactivateModule.Invoke(module, null);
					});
					TryCleanup(delegate
					{
						module.enabled = true;
					});
				}
			}
			_modules.Clear();
			_systems.Clear();
			if (!_ownsCursor)
			{
				return;
			}
			_ownsCursor = false;
			try
			{
				object obj = _gui();
				bool flag = false;
				if (Alive(obj))
				{
					_updateWindows.Invoke(obj, null);
					flag = _getShowing(obj);
				}
				if (Application.isFocused)
				{
					Cursor.lockState = (CursorLockMode)((!flag) ? ((int)_previousLock) : 0);
					Cursor.visible = flag || _previousVisible;
				}
			}
			catch (Exception ex)
			{
				if (Application.isFocused)
				{
					Cursor.lockState = _previousLock;
					Cursor.visible = _previousVisible;
				}
				_report("Cursor restore: " + ex.GetBaseException().Message);
			}
		}

		private void TryCleanup(Action action)
		{
			try
			{
				action();
			}
			catch (Exception ex)
			{
				_report("Input cleanup: " + ex.GetBaseException().Message);
			}
		}

		private void Fail(Exception ex)
		{
			_faulted = true;
			Release();
			_report("Menu closed because input protection failed: " + ex.GetBaseException().Message);
		}

		private static void WindowPostfix(object __instance)
		{
			ModalInputBridge active = _active;
			if (active == null || !active.Blocking)
			{
				return;
			}
			try
			{
				active.SetWindowFlags(__instance);
			}
			catch (Exception ex)
			{
				active.Fail(ex);
			}
		}

		private static bool PausePrefix()
		{
			if (_active != null)
			{
				return !_active.Blocking;
			}
			return true;
		}

		private static bool CursorPrefix()
		{
			if (_active == null || !_active.Blocking)
			{
				return true;
			}
			_active.MaintainCursor();
			return false;
		}

		private static bool EventPrefix(Component __instance)
		{
			ModalInputBridge active = _active;
			if (active == null || !active.Blocking)
			{
				return true;
			}
			try
			{
				active.Suspend(__instance);
			}
			catch (Exception ex)
			{
				active.Fail(ex);
			}
			return false;
		}

		public void Dispose()
		{
			Release();
			if (_active == this)
			{
				_active = null;
			}
			_harmony.UnpatchSelf();
		}

		private static bool Alive(object? obj)
		{
			if (obj != null)
			{
				Object val = (Object)((obj is Object) ? obj : null);
				if (val != null)
				{
					return Object.op_Implicit(val);
				}
				return true;
			}
			return false;
		}

		private static Type RequireType(string name)
		{
			return AccessTools.TypeByName(name) ?? throw new NotSupportedException("Menu input API missing: " + name);
		}

		private static MethodInfo RequireVoid(Type type, string name)
		{
			MethodInfo methodInfo = AccessTools.Method(type, name, Type.EmptyTypes, (Type[])null);
			if (methodInfo == null || methodInfo.IsStatic || methodInfo.ReturnType != typeof(void))
			{
				throw new NotSupportedException(type.Name + "." + name + "() has changed.");
			}
			return methodInfo;
		}

		private static HarmonyMethod Hook(string name, int priority)
		{
			//IL_0012: 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_001f: Expected O, but got Unknown
			return new HarmonyMethod(AccessTools.Method(typeof(ModalInputBridge), name, (Type[])null, (Type[])null))
			{
				priority = priority
			};
		}

		private static Func<object?> StaticGetter(Type type, string name)
		{
			FieldInfo fieldInfo = AccessTools.Field(type, name);
			Expression expression;
			if (fieldInfo != null && fieldInfo.IsStatic)
			{
				expression = Expression.Field(null, fieldInfo);
			}
			else
			{
				MethodInfo methodInfo = AccessTools.PropertyGetter(type, name);
				if (methodInfo == null || !methodInfo.IsStatic)
				{
					throw new NotSupportedException(type.Name + "." + name + " is unavailable.");
				}
				expression = Expression.Call(methodInfo);
			}
			return Expression.Lambda<Func<object>>(Expression.Convert(expression, typeof(object)), Array.Empty<ParameterExpression>()).Compile();
		}

		private static Action<object, bool> BoolSetter(Type type, string name)
		{
			MethodInfo methodInfo = AccessTools.PropertySetter(type, name);
			if (methodInfo == null || methodInfo.IsStatic || methodInfo.GetParameters().Length != 1 || methodInfo.GetParameters()[0].ParameterType != typeof(bool))
			{
				throw new NotSupportedException(type.Name + "." + name + " setter has changed.");
			}
			ParameterExpression parameterExpression = Expression.Parameter(typeof(object));
			ParameterExpression parameterExpression2 = Expression.Parameter(typeof(bool));
			return Expression.Lambda<Action<object, bool>>(Expression.Call(Expression.Convert(parameterExpression, type), methodInfo, parameterExpression2), new ParameterExpression[2] { parameterExpression, parameterExpression2 }).Compile();
		}

		private static Func<object, bool> BoolGetter(Type type, string name)
		{
			MethodInfo methodInfo = AccessTools.PropertyGetter(type, name);
			if (methodInfo == null || methodInfo.IsStatic || methodInfo.ReturnType != typeof(bool))
			{
				throw new NotSupportedException(type.Name + "." + name + " getter has changed.");
			}
			ParameterExpression parameterExpression = Expression.Parameter(typeof(object));
			return Expression.Lambda<Func<object, bool>>(Expression.Call(Expression.Convert(parameterExpression, type), methodInfo), new ParameterExpression[1] { parameterExpression }).Compile();
		}
	}
	internal sealed class ModalInputGate
	{
		private int _lastBusyFrame;

		public bool IsOpen { get; private set; }

		public bool Blocking { get; private set; }

		public void Open()
		{
			IsOpen = true;
			Blocking = true;
		}

		public void Close(int frame)
		{
			IsOpen = false;
			_lastBusyFrame = frame;
		}

		public bool Tick(int frame, bool inputHeld)
		{
			if (!Blocking || IsOpen)
			{
				return false;
			}
			if (inputHeld)
			{
				_lastBusyFrame = frame;
			}
			else if (frame > _lastBusyFrame + 1)
			{
				Blocking = false;
				return true;
			}
			return false;
		}

		public void Reset()
		{
			IsOpen = false;
			Blocking = false;
		}
	}
	internal enum MenuAction
	{
		None,
		Apply,
		ApplyAndClose,
		Close,
		Refresh,
		SaveKey
	}
	internal sealed class PassportMenu : IDisposable
	{
		private MenuTheme? _theme;

		private readonly List<BadgeEntry> _filtered = new List<BadgeEntry>();

		private string[] _knownIds = Array.Empty<string>();

		private IReadOnlyList<BadgeEntry>? _lastCatalog;

		private string _search = "";

		private bool _earnedOnly = true;

		private bool _refilter = true;

		private bool _confirmClose;

		private bool _searchFocused;

		private bool _resetFocus;

		private Vector2 _scroll;

		private float _scrollGrab;

		private int _scrollControl;

		private const float Width = 1000f;

		private const float Height = 720f;

		private const float Row = 88f;

		public readonly MenuKeyCapture KeyCapture = new MenuKeyCapture();

		public bool BlocksMenuShortcut
		{
			get
			{
				if (!KeyCapture.IsOpen)
				{
					return _searchFocused;
				}
				return true;
			}
		}

		public void Open()
		{
			_confirmClose = false;
			_refilter = true;
			_searchFocused = false;
			_resetFocus = true;
			KeyCapture.Cancel();
		}

		public void Closed()
		{
			KeyCapture.Cancel();
			_searchFocused = false;
			if (_scrollControl != 0 && GUIUtility.hotControl == _scrollControl)
			{
				GUIUtility.hotControl = 0;
			}
		}

		public bool RequestClose(bool dirty)
		{
			if (KeyCapture.IsOpen)
			{
				return false;
			}
			_confirmClose = dirty;
			return !dirty;
		}

		public MenuAction Draw(IReadOnlyList<BadgeEntry> catalog, BadgeDraft draft, BadgePolicy applied, bool available, string status, string keyLabel)
		{
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_003a: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			if (_theme == null)
			{
				_theme = new MenuTheme();
			}
			if (_resetFocus)
			{
				GUI.FocusControl((string)null);
				_resetFocus = false;
			}
			MenuTheme theme = _theme;
			Matrix4x4 matrix = GUI.matrix;
			Color color = GUI.color;
			bool enabled = GUI.enabled;
			int depth = GUI.depth;
			GUI.depth = -1000;
			GUI.enabled = true;
			GUI.color = Color.white;
			float num = Mathf.Max(0.1f, Mathf.Min(1.3f, Mathf.Min((float)(Screen.width - 24) / 1000f, (float)(Screen.height - 24) / 720f)));
			float num2 = ((float)Screen.width - 1000f * num) / 2f;
			float num3 = ((float)Screen.height - 720f * num) / 2f;
			GUI.matrix = Matrix4x4.identity;
			MenuTheme.Fill(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), MenuTheme.C(18, 40, 53, 165));
			GUI.matrix = Matrix4x4.TRS(new Vector3(num2, num3, 0f), Quaternion.identity, new Vector3(num, num, 1f));
			try
			{
				return DrawPage(theme, catalog, draft, applied, available, status, keyLabel);
			}
			finally
			{
				GUI.matrix = matrix;
				GUI.color = color;
				GUI.enabled = enabled;
				GUI.depth = depth;
			}
		}

		private MenuAction DrawPage(MenuTheme t, IReadOnlyList<BadgeEntry> catalog, BadgeDraft draft, BadgePolicy applied, bool available, string status, string keyLabel)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: 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_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0510: Unknown result type (might be due to invalid IL or missing references)
			//IL_0434: Unknown result type (might be due to invalid IL or missing references)
			//IL_0443: Unknown result type (might be due to invalid IL or missing references)
			//IL_0468: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0557: Unknown result type (might be due to invalid IL or missing references)
			//IL_0561: Unknown result type (might be due to invalid IL or missing references)
			//IL_0680: Unknown result type (might be due to invalid IL or missing references)
			//IL_068f: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_07de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0745: Unknown result type (might be due to invalid IL or missing references)
			//IL_074b: Invalid comparison between Unknown and I4
			//IL_0754: Unknown result type (might be due to invalid IL or missing references)
			//IL_0776: Unknown result type (might be due to invalid IL or missing references)
			//IL_08b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0655: Unknown result type (might be due to invalid IL or missing references)
			//IL_065a: Unknown result type (might be due to invalid IL or missing references)
			//IL_094b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0961: Unknown result type (might be due to invalid IL or missing references)
			//IL_09cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_09d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0868: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a09: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_08fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ac3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ac9: Invalid comparison between Unknown and I4
			//IL_0a23: Unknown result type (might be due to invalid IL or missing references)
			//IL_0918: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b9b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bb4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bd8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c24: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b15: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b1b: Invalid comparison between Unknown and I4
			//IL_0ad3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a3e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a56: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a75: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c47: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c40: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c67: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c71: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c9f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ca9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ce0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cf7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cf0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d17: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d21: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d58: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d68: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d8c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d91: Unknown result type (might be due to invalid IL or missing references)
			//IL_0db5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dba: Unknown result type (might be due to invalid IL or missing references)
			//IL_0de3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0df2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e17: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e26: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e46: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e50: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e7f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e89: Unknown result type (might be due to invalid IL or missing references)
			//IL_0eb3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ebd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f14: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f1a: Invalid comparison between Unknown and I4
			bool dirty = draft.IsDirty(applied);
			bool flag = _confirmClose || KeyCapture.IsOpen;
			bool flag2 = available && !flag;
			MenuAction result = MenuAction.None;
			t.Panel(new Rect(5f, 8f, 1000f, 720f), MenuTheme.C(13, 32, 45, 110), 22f);
			t.Panel(new Rect(0f, 0f, 1000f, 720f), MenuTheme.Ink, 22f);
			t.Panel(new Rect(8f, 8f, 984f, 704f), MenuTheme.Paper, 16f);
			t.PaperDots(new Rect(22f, 22f, 956f, 676f));
			t.Font.Draw(new Rect(32f, 16f, 700f, 55f), "QUIET BADGES", 48f, MenuTheme.Ink, (TextAnchor)3);
			t.Font.Draw(new Rect(34f, 69f, 660f, 27f), "Your sash. Your choice.", 25f, MenuTheme.Muted, (TextAnchor)3);
			t.Font.Draw(new Rect(656f, 15f, 250f, 27f), "CHANGE MENU KEY", 21f, MenuTheme.Muted, (TextAnchor)4);
			float size = Mathf.Min(24f, 5520f / Mathf.Max(1f, AtlasFont.Width(keyLabel, 24f)));
			if (t.Button(new Rect(656f, 47f, 250f, 42f), keyLabel, MenuTheme.Blue, !flag, size))
			{
				KeyCapture.Begin();
				GUI.FocusControl((string)null);
				flag = true;
				flag2 = false;
			}
			if (t.Button(new Rect(926f, 30f, 42f, 42f), "X", MenuTheme.Orange, !flag, 27f) && RequestClose(dirty))
			{
				result = MenuAction.Close;
			}
			if (t.Button(new Rect(32f, 114f, 300f, 57f), "SHOW ALL EARNED", MenuTheme.Blue, flag2, 28f, draft.Mode == VisibilityMode.Off))
			{
				draft.Mode = VisibilityMode.Off;
			}
			if (t.Button(new Rect(350f, 114f, 300f, 57f), "HIDE SELECTED", MenuTheme.Green, flag2, 28f, draft.Mode == VisibilityMode.Selected))
			{
				draft.Mode = VisibilityMode.Selected;
			}
			if (t.Button(new Rect(668f, 114f, 300f, 57f), "HIDE ALL", MenuTheme.Orange, flag2, 28f, draft.Mode == VisibilityMode.All))
			{
				draft.Mode = VisibilityMode.All;
			}
			t.Panel(new Rect(32f, 195f, 550f, 43f), MenuTheme.C(217, 210, 181), 8f);
			t.Panel(new Rect(34f, 197f, 546f, 39f), MenuTheme.C(byte.MaxValue, 251, 233), 6f);
			GUI.enabled = flag2;
			GUI.SetNextControlName("QuietBadges.Search");
			string text = GUI.TextField(new Rect(33f, 195f, 549f, 43f), _search, 100, t.Search);
			GUI.enabled = true;
			if (text != _search)
			{
				_search = text;
				_refilter = true;
			}
			if (_search.Length == 0 && GUI.GetNameOfFocusedControl() != "QuietBadges.Search")
			{
				t.Font.Draw(new Rect(48f, 195f, 470f, 43f), "Search badges...", 24f, MenuTheme.Muted, (TextAnchor)3);
			}
			if (_search.Length > 0)
			{
				t.Font.Draw(new Rect(549f, 195f, 25f, 43f), "X", 20f, MenuTheme.Muted, (TextAnchor)4);
				GUI.enabled = flag2;
				if (GUI.Button(new Rect(545f, 198f, 32f, 37f), GUIContent.none, GUIStyle.none))
				{
					_search = "";
					_refilter = true;
					GUI.FocusControl((string)null);
				}
				GUI.enabled = true;
			}
			t.Check(new Rect(608f, 203f, 27f, 27f), _earnedOnly);
			t.Font.Draw(new Rect(647f, 195f, 170f, 43f), "Earned only", 25f, MenuTheme.Ink, (TextAnchor)3);
			GUI.enabled = flag2;
			if (GUI.Button(new Rect(604f, 195f, 214f, 43f), GUIContent.none, GUIStyle.none))
			{
				_earnedOnly = !_earnedOnly;
				_refilter = true;
			}
			GUI.enabled = true;
			if (t.Button(new Rect(838f, 195f, 130f, 43f), "Refresh", MenuTheme.Blue, flag2, 24f))
			{
				result = MenuAction.Refresh;
			}
			if (catalog != _lastCatalog)
			{
				_lastCatalog = catalog;
				_knownIds = catalog.Select((BadgeEntry b) => b.Id).ToArray();
				_refilter = true;
			}
			if (_refilter)
			{
				_filtered.Clear();
				foreach (BadgeEntry item in catalog)
				{
					if ((!_earnedOnly || item.Earned) && (_search.Length == 0 || item.Label.IndexOf(_search, StringComparison.OrdinalIgnoreCase) >= 0 || item.Id.IndexOf(_search, StringComparison.OrdinalIgnoreCase) >= 0))
					{
						_filtered.Add(item);
					}
				}
				_scroll = Vector2.zero;
				_refilter = false;
			}
			t.Font.Draw(new Rect(34f, 249f, 470f, 29f), "CHECK A BADGE TO HIDE IT", 23f, MenuTheme.Ink, (TextAnchor)3);
			t.Font.Draw(new Rect(598f, 249f, 368f, 29f), _filtered.Count + " badges shown", 22f, MenuTheme.Muted, (TextAnchor)5);
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(32f, 286f, 936f, 295f);
			int num = (_filtered.Count + 1) / 2;
			float num2 = Mathf.Max(((Rect)(ref val)).height, (float)num * 88f - 8f);
			bool flag3 = num2 > ((Rect)(ref val)).height;
			if (!flag && (int)Event.current.type == 6 && ((Rect)(ref val)).Contains(Event.current.mousePosition))
			{
				_scroll.y = Mathf.Clamp(_scroll.y + Event.current.delta.y * 30f, 0f, num2 - ((Rect)(ref val)).height);
				Event.current.Use();
			}
			_scroll.y = Mathf.Clamp(_scroll.y, 0f, Mathf.Max(0f, num2 - ((Rect)(ref val)).height));
			GUI.BeginGroup(val);
			int num3 = Mathf.Max(0, (int)(_scroll.y / 88f));
			int num4 = Mathf.Min(num, num3 + 5);
			for (int num5 = num3; num5 < num4; num5++)
			{
				for (int num6 = 0; num6 < 2; num6++)
				{
					int num7 = num5 * 2 + num6;
					if (num7 >= _filtered.Count)
					{
						break;
					}
					BadgeEntry badge = _filtered[num7];
					DrawTile(t, new Rect((float)(num6 * 465), (float)num5 * 88f - _scroll.y, 450f, 80f), badge, draft, flag2);
				}
			}
			if (_filtered.Count == 0)
			{
				t.Font.Draw(new Rect(25f, 81f, 886f, 48f), (catalog.Count == 0) ? "YOUR BADGES WILL APPEAR HERE" : "NO MATCHING BADGES", 33f, MenuTheme.Ink, (TextAnchor)4);
				t.Font.Draw(new Rect(25f, 131f, 886f, 42f), (catalog.Count == 0) ? "Enter the airport, then press Refresh." : "Try another search or turn off Earned only.", 26f, MenuTheme.Muted, (TextAnchor)4);
			}
			GUI.EndGroup();
			if (flag3)
			{
				Rect r = default(Rect);
				((Rect)(ref r))..ctor(958f, 286f, 10f, 295f);
				t.Panel(r, MenuTheme.C(217, 210, 181), 5f);
				float num8 = Mathf.Max(30f, ((Rect)(ref val)).height * ((Rect)(ref val)).height / num2);
				Rect r2 = default(Rect);
				((Rect)(ref r2))..ctor(((Rect)(ref r)).x, ((Rect)(ref r)).y + _scroll.y / (num2 - ((Rect)(ref val)).height) * (((Rect)(ref r)).height - num8), ((Rect)(ref r)).width, num8);
				t.Panel(r2, MenuTheme.Blue, 5f);
				int num9 = (_scrollControl = GUIUtility.GetControlID("QuietBadges.Scroll".GetHashCode(), (FocusType)2));
				Event current2 = Event.current;
				if (!flag && (int)current2.type == 0 && current2.button == 0 && ((Rect)(ref r)).Contains(current2.mousePosition))
				{
					GUIUtility.hotControl = num9;
					_scrollGrab = (((Rect)(ref r2)).Contains(current2.mousePosition) ? (current2.mousePosition.y - ((Rect)(ref r2)).y) : (num8 / 2f));
					_scroll.y = Mathf.Clamp01((current2.mousePosition.y - ((Rect)(ref r)).y - _scrollGrab) / (((Rect)(ref r)).height - num8)) * (num2 - ((Rect)(ref val)).height);
					current2.Use();
				}
				if (!flag && GUIUtility.hotControl == num9)
				{
					if ((int)current2.type == 3)
					{
						_scroll.y = Mathf.Clamp01((current2.mousePosition.y - ((Rect)(ref r)).y - _scrollGrab) / (((Rect)(ref r)).height - num8)) * (num2 - ((Rect)(ref val)).height);
						current2.Use();
					}
					if ((int)current2.type == 1)
					{
						GUIUtility.hotControl = 0;
						current2.Use();
					}
				}
			}
			int num10 = 0;
			int num11 = 0;
			foreach (BadgeEntry item2 in catalog)
			{
				if (item2.Earned)
				{
					num10++;
					if (draft.IsHidden(item2.Id))
					{
						num11++;
					}
				}
			}
			dirty = draft.IsDirty(applied);
			MenuTheme.Fill(new Rect(32f, 598f, 936f, 2f), MenuTheme.C(211, 205, 178));
			t.Font.Draw(new Rect(34f, 604f, 554f, 32f), num11 + " of " + num10 + " earned badges will be hidden", 25f, MenuTheme.Ink, (TextAnchor)3);
			t.Font.Draw(new Rect(600f, 604f, 366f, 32f), dirty ? "UNSAVED CHANGES" : "SETTINGS SAVED", 22f, dirty ? MenuTheme.Orange : MenuTheme.Green, (TextAnchor)5);
			if (t.Button(new Rect(32f, 646f, 242f, 46f), "Clear selection", MenuTheme.Orange, flag2))
			{
				draft.Clear();
			}
			if (t.Button(new Rect(290f, 646f, 156f, 46f), "Revert", MenuTheme.Blue, flag2 && dirty))
			{
				draft.Reset(applied);
			}
			t.Font.Draw(new Rect(464f, 646f, 230f, 46f), status, 20f, available ? MenuTheme.Muted : MenuTheme.Orange, (TextAnchor)3);
			if (t.Button(new Rect(716f, 646f, 252f, 46f), "Apply changes", MenuTheme.Green, flag2 && dirty, 28f))
			{
				result = MenuAction.Apply;
			}
			if (_confirmClose)
			{
				t.Panel(new Rect(8f, 8f, 984f, 704f), MenuTheme.C(22, 43, 52, 190), 16f);
				t.Panel(new Rect(194f, 228f, 612f, 252f), MenuTheme.Ink, 18f);
				t.Panel(new Rect(200f, 234f, 600f, 240f), MenuTheme.Paper, 14f);
				t.Font.Draw(new Rect(226f, 254f, 548f, 49f), "SAVE YOUR CHANGES?", 38f, MenuTheme.Ink, (TextAnchor)4);
				t.Font.Draw(new Rect(226f, 310f, 548f, 32f), "Your sash has not changed yet.", 26f, MenuTheme.Muted, (TextAnchor)4);
				if (t.Button(new Rect(226f, 382f, 172f, 52f), "Keep editing", MenuTheme.Blue, enabled: true, 24f))
				{
					_confirmClose = false;
				}
				if (t.Button(new Rect(414f, 382f, 140f, 52f), "Discard", MenuTheme.Orange, enabled: true, 24f))
				{
					result = MenuAction.Close;
				}
				if (t.Button(new Rect(570f, 382f, 204f, 52f), "Apply & close", MenuTheme.Green, available, 24f))
				{
					result = MenuAction.ApplyAndClose;
				}
			}
			if (KeyCapture.IsOpen)
			{
				result = DrawKeyPicker(t);
			}
			_searchFocused = !flag && GUI.GetNameOfFocusedControl() == "QuietBadges.Search";
			if (Event.current.isMouse || (int)Event.current.type == 6 || Event.current.isKey)
			{
				Event.current.Use();
			}
			return result;
		}

		private MenuAction DrawKeyPicker(MenuTheme t)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: 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_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: 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_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: 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_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			t.Panel(new Rect(8f, 8f, 984f, 704f), MenuTheme.C(22, 43, 52, 190), 16f);
			t.Panel(new Rect(174f, 190f, 652f, 340f), MenuTheme.Ink, 18f);
			t.Panel(new Rect(180f, 196f, 640f, 328f), MenuTheme.Paper, 14f);
			t.Font.Draw(new Rect(206f, 213f, 588f, 50f), "CHOOSE YOUR MENU KEY", 38f, MenuTheme.Ink, (TextAnchor)4);
			t.Font.Draw(new Rect(206f, 269f, 588f, 30f), "Press a key. Add Ctrl, Alt or Shift if you want.", 23f, MenuTheme.Muted, (TextAnchor)4);
			t.Panel(new Rect(206f, 316f, 588f, 64f), MenuTheme.C(222, 234, 205));
			float size = Mathf.Min(32f, 17856f / Mathf.Max(1f, AtlasFont.Width(KeyCapture.Label, 32f)));
			t.Font.Draw(new Rect(221f, 316f, 558f, 64f), KeyCapture.Label, size, MenuTheme.Ink, (TextAnchor)4);
			t.Font.Draw(new Rect(206f, 390f, 588f, 34f), (KeyCapture.Error.Length > 0) ? KeyCapture.Error : "Esc cancels. Badge choices are saved separately.", 22f, (KeyCapture.Error.Length > 0) ? MenuTheme.Orange : MenuTheme.Muted, (TextAnchor)4);
			if (t.Button(new Rect(206f, 448f, 178f, 48f), "Reset to F8", MenuTheme.Blue, enabled: true, 25f))
			{
				KeyCapture.Capture((KeyCode)289, Array.Empty<KeyCode>());
			}
			if (t.Button(new Rect(400f, 448f, 154f, 48f), "Cancel", MenuTheme.Orange, enabled: true, 25f))
			{
				KeyCapture.Cancel();
			}
			if (t.Button(new Rect(570f, 448f, 224f, 48f), "Save key", MenuTheme.Green, KeyCapture.HasCandidate, 27f))
			{
				return MenuAction.SaveKey;
			}
			return MenuAction.None;
		}

		private void DrawTile(MenuTheme t, Rect rect, BadgeEntry badge, BadgeDraft draft, bool enabled)
		{
			//IL_0019: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: 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_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Invalid comparison between Unknown and I4
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: 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_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: 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_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: 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_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_0391: Unknown result type (might be due to invalid IL or missing references)
			//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
			bool flag = draft.IsHidden(badge.Id);
			bool flag2 = enabled && ((Rect)(ref rect)).Contains(Event.current.mousePosition);
			t.Panel(rect, flag ? MenuTheme.Green : MenuTheme.C(212, 202, 169));
			t.Panel(new Rect(((Rect)(ref rect)).x + 2f, ((Rect)(ref rect)).y + 2f, ((Rect)(ref rect)).width - 4f, ((Rect)(ref rect)).height - 4f), flag ? MenuTheme.C(222, 234, 205) : (flag2 ? MenuTheme.C(byte.MaxValue, 250, 230) : MenuTheme.C(239, 230, 199)), 8f);
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((Rect)(ref rect)).x + 13f, ((Rect)(ref rect)).y + 14f, 51f, 51f);
			if ((Object)(object)badge.Icon != (Object)null && (int)Event.current.type == 7)
			{
				Color color = GUI.color;
				GUI.color = (badge.Earned ? Color.white : MenuTheme.C(164, 160, 142));
				float num = (float)badge.Icon.width * ((Rect)(ref badge.IconUv)).width / ((float)badge.Icon.height * ((Rect)(ref badge.IconUv)).height);
				if (num > 1f)
				{
					((Rect)(ref val)).height = ((Rect)(ref val)).height / num;
					((Rect)(ref val)).y = ((Rect)(ref val)).y + (51f - ((Rect)(ref val)).height) / 2f;
				}
				else
				{
					((Rect)(ref val)).width = ((Rect)(ref val)).width * num;
					((Rect)(ref val)).x = ((Rect)(ref val)).x + (51f - ((Rect)(ref val)).width) / 2f;
				}
				GUI.DrawTextureWithTexCoords(val, badge.Icon, badge.IconUv, true);
				GUI.color = color;
			}
			else if ((Object)(object)badge.Icon == (Object)null)
			{
				t.Panel(val, badge.Earned ? MenuTheme.Gold : MenuTheme.C(192, 189, 164), 25f);
				t.Font.Draw(val, "B", 33f, MenuTheme.Paper, (TextAnchor)4);
			}
			t.Font.Draw(new Rect(((Rect)(ref rect)).x + 78f, ((Rect)(ref rect)).y + 9f, 276f, 34f), badge.Label, 27f, MenuTheme.Ink, (TextAnchor)3);
			t.Font.Draw(new Rect(((Rect)(ref rect)).x + 79f, ((Rect)(ref rect)).y + 43f, 268f, 24f), badge.Earned ? "Earned" : "Not earned yet", 20f, MenuTheme.Muted, (TextAnchor)3);
			t.Check(new Rect(((Rect)(ref rect)).x + 394f, ((Rect)(ref rect)).y + 11f, 30f, 30f), flag, enabled);
			t.Font.Draw(new Rect(((Rect)(ref rect)).x + 365f, ((Rect)(ref rect)).y + 45f, 82f, 24f), flag ? "Hidden" : "Visible", 20f, flag ? MenuTheme.Green : MenuTheme.Muted, (TextAnchor)4);
			GUI.enabled = enabled;
			if (GUI.Button(rect, GUIContent.none, GUIStyle.none))
			{
				draft.Toggle(badge.Id, _knownIds);
			}
			GUI.enabled = true;
		}

		public void Dispose()
		{
			_theme?.Dispose();
		}
	}
	[BepInPlugin("mcmannybell.quietbadges", "Quiet Badges", "0.2.6")]
	[BepInProcess("PEAK.exe")]
	[DefaultExecutionOrder(-32000)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "mcmannybell.quietbadges";

		private ConfigEntry<VisibilityMode> _mode;

		private ConfigEntry<string> _selection;

		private ConfigEntry<KeyboardShortcut> _menuKey;

		private GameBindings? _api;

		private Harmony? _harmony;

		private ModalInputBridge? _input;

		private object? _lastData;

		private bool _pendingRefresh;

		private bool _open;

		private bool _ready;

		private bool _attached;

		private bool _committing;

		private float _nextCheck;

		private string _status = "Enter the airport";

		private string _keyLabel = "F8";

		private List<BadgeEntry> _catalog = new List<BadgeEntry>();

		private readonly PassportMenu _menu = new PassportMenu();

		private readonly BadgeDraft _draft = new BadgeDraft(new BadgePolicy(VisibilityMode.Off, ""));

		private void Awake()
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			_mode = ((BaseUnityPlugin)this).Config.Bind<VisibilityMode>("Visibility", "Mode", VisibilityMode.Off, "Off displays earned badges normally. Selected hides chosen IDs. All hides all sash badges.");
			_selection = ((BaseUnityPlugin)this).Config.Bind<string>("Visibility", "HiddenBadgeIds", "", "Comma-separated achievement IDs. Prefer choosing badges in the menu and pressing Apply changes. Only your character is affected.");
			_menuKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Controls", "MenuKey", new KeyboardShortcut((KeyCode)289, Array.Empty<KeyCode>()), "Open Quiet Badges and free the cursor automatically. Change with the menu's key button, or edit here with PEAK closed (for example F9 or F9 + LeftControl).");
			_mode.SettingChanged += SettingsChanged;
			_selection.SettingChanged += SettingsChanged;
			_menuKey.SettingChanged += MenuKeyChanged;
			MenuKeyChanged(this, EventArgs.Empty);
			SceneManager.activeSceneChanged += SceneChanged;
			DisplayPatch.ReportFailure = Fail;
			_ready = true;
			TryAttach();
		}

		private void OnEnable()
		{
			if (_ready)
			{
				TryAttach();
				TryInput();
			}
		}

		private void TryInput()
		{
			if (_input != null)
			{
				return;
			}
			try
			{
				_input = new ModalInputBridge(delegate(string message)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)message);
				});
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Menu input protection unavailable; menu stays closed: " + ex.GetBaseException().Message));
			}
		}

		private void MenuKeyChanged(object sender, EventArgs args)
		{
			//IL_0007: 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_000f: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			KeyboardShortcut value = _menuKey.Value;
			KeyCode mainKey = ((KeyboardShortcut)(ref value)).MainKey;
			value = _menuKey.Value;
			_keyLabel = MenuKeyCapture.Format(mainKey, ((KeyboardShortcut)(ref value)).Modifiers);
		}

		private void TryAttach()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			if (_attached)
			{
				return;
			}
			try
			{
				_api = GameBindings.Discover();
				DisplayPatch.Api = _api;
				DisplayPatch.Faulted = false;
				_harmony = new Harmony("mcmannybell.quietbadges");
				_harmony.Patch((MethodBase)_api.BadgeHook.Method, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(DisplayPatch), "Transpiler", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null);
				_attached = true;
				ApplySettings();
				_status = "Ready for your sash";
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Quiet Badges 0.2.6 attached. PEAK reports version: " + Application.version + ". Badge API and sash-building pattern validated (" + ((_api.BadgeHook.OwnerField == null) ? "direct" : "coroutine") + ")."));
			}
			catch (Exception ex)
			{
				Harmony? harmony = _harmony;
				if (harmony != null)
				{
					harmony.UnpatchSelf();
				}
				_attached = false;
				Fail("Unsupported game/API: " + ex.GetBaseException().Message);
			}
		}

		private void SettingsChanged(object sender, EventArgs args)
		{
			if (!_committing)
			{
				ApplySettings();
			}
		}

		private void ApplySettings()
		{
			DisplayPatch.Policy = new BadgePolicy(_mode.Value, _selection.Value);
			_pendingRefresh = true;
		}

		private bool CommitDraft()
		{
			if (!_attached || DisplayPatch.Faulted)
			{
				return false;
			}
			BadgePolicy badgePolicy = _draft.Snapshot();
			VisibilityMode value = _mode.Value;
			string value2 = _selection.Value;
			bool saveOnConfigSet = ((BaseUnityPlugin)this).Config.SaveOnConfigSet;
			_committing = true;
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = false;
			try
			{
				_mode.Value = badgePolicy.Mode;
				_selection.Value = _draft.SelectionCsv;
				((BaseUnityPlugin)this).Config.Save();
				ApplySettings();
				_draft.Reset(DisplayPatch.Policy);
				_status = "Apply