Decompiled source of PEAK Quick Board v1.8.0

PeakQuickBoard.dll

Decompiled 15 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
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("PeakQuickBoard")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.8.0.0")]
[assembly: AssemblyInformationalVersion("1.8.0")]
[assembly: AssemblyProduct("PeakQuickBoard")]
[assembly: AssemblyTitle("PeakQuickBoard")]
[assembly: AssemblyVersion("1.8.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace PeakQuickBoard
{
	internal static class GameApi
	{
		public const string AirportScene = "Airport";

		private static Type _kioskType;

		private static Type _inviteKioskType;

		private static Type _guiManagerType;

		private static Type _boardingPassType;

		private static Type _gameOverType;

		private static Type _loadingType;

		private static Type _characterType;

		private static Type _ascentsType;

		private static Type _ascentDataType;

		private static Type _runSettingsType;

		private static Type _photonType;

		private static Type _mainCameraType;

		private static Component _mainCamera;

		private static float _nextCameraSearch;

		private static string _labelKey;

		private static string _label;

		private static Type _ascentDataSingleton;

		public static string ActiveScene
		{
			get
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				Scene activeScene = SceneManager.GetActiveScene();
				return ((Scene)(ref activeScene)).name;
			}
		}

		public static bool InAirport => ActiveScene == "Airport";

		public static bool InTitle => ActiveScene == "Title";

		public static bool InRun
		{
			get
			{
				if (!InAirport && !InTitle && !IsLoading)
				{
					return LocalCharacterReady;
				}
				return false;
			}
		}

		public static bool IsLoading
		{
			get
			{
				object obj = GetStatic(_loadingType, "loading");
				bool flag = default(bool);
				int num;
				if (obj is bool)
				{
					flag = (bool)obj;
					num = 1;
				}
				else
				{
					num = 0;
				}
				return (byte)((uint)num & (flag ? 1u : 0u)) != 0;
			}
		}

		public static bool IsHost
		{
			get
			{
				if (_photonType == null)
				{
					return true;
				}
				object obj = GetStatic(_photonType, "OfflineMode");
				bool flag = default(bool);
				int num;
				if (obj is bool)
				{
					flag = (bool)obj;
					num = 1;
				}
				else
				{
					num = 0;
				}
				if (((uint)num & (flag ? 1u : 0u)) == 0)
				{
					obj = GetStatic(_photonType, "IsMasterClient");
					bool flag2 = default(bool);
					int num2;
					if (obj is bool)
					{
						flag2 = (bool)obj;
						num2 = 1;
					}
					else
					{
						num2 = 0;
					}
					return (byte)((uint)num2 & (flag2 ? 1u : 0u)) != 0;
				}
				return true;
			}
		}

		private static object LocalCharacter => GetStatic(_characterType, "localCharacter");

		public static bool LocalCharacterReady
		{
			get
			{
				object localCharacter = LocalCharacter;
				Object val = (Object)((localCharacter is Object) ? localCharacter : null);
				if (val != null)
				{
					return val != (Object)null;
				}
				return false;
			}
		}

		public static bool GameWindowOpen
		{
			get
			{
				object obj = GetStatic(_guiManagerType, "instance");
				bool flag = default(bool);
				int num;
				if (obj != null)
				{
					object member = GetMember(obj, "windowBlockingInput");
					if (member is bool)
					{
						flag = (bool)member;
						num = 1;
					}
					else
					{
						num = 0;
					}
				}
				else
				{
					num = 0;
				}
				return (byte)((uint)num & (flag ? 1u : 0u)) != 0;
			}
		}

		public static bool InCutscene
		{
			get
			{
				if ((Object)(object)_mainCamera == (Object)null && Time.unscaledTime >= _nextCameraSearch)
				{
					_nextCameraSearch = Time.unscaledTime + 1f;
					if (_mainCameraType == null)
					{
						_mainCameraType = Reflect.Type("MainCamera");
					}
					if (_mainCameraType != null)
					{
						Object obj = Object.FindObjectOfType(_mainCameraType);
						_mainCamera = (Component)(object)((obj is Component) ? obj : null);
					}
				}
				if ((Object)(object)_mainCamera != (Object)null)
				{
					return !_mainCamera.gameObject.activeInHierarchy;
				}
				return false;
			}
		}

		public static int CurrentAscent
		{
			get
			{
				object obj = GetStatic(_ascentsType, "currentAscent");
				if (obj is int)
				{
					return (int)obj;
				}
				return 0;
			}
		}

		public static bool IsCustomRun
		{
			get
			{
				object obj = GetStatic(_runSettingsType, "IsCustomRun");
				bool flag = default(bool);
				int num;
				if (obj is bool)
				{
					flag = (bool)obj;
					num = 1;
				}
				else
				{
					num = 0;
				}
				return (byte)((uint)num & (flag ? 1u : 0u)) != 0;
			}
		}

		public static float? AltitudeMeters
		{
			get
			{
				try
				{
					object localCharacter = LocalCharacter;
					Object val = (Object)((localCharacter is Object) ? localCharacter : null);
					if (val == null || val == (Object)null)
					{
						return null;
					}
					object member = GetMember(localCharacter, "refs");
					object obj = ((member == null) ? null : GetMember(member, "stats"));
					if (obj != null && GetMember(obj, "heightInMeters") is float value)
					{
						return value;
					}
				}
				catch
				{
				}
				return null;
			}
		}

		public static void Init()
		{
			_kioskType = Find("AirportCheckInKiosk");
			_inviteKioskType = Find("AirportInviteFriendsKiosk");
			_guiManagerType = Find("GUIManager");
			_boardingPassType = Find("BoardingPass");
			_gameOverType = Find("GameOverHandler");
			_loadingType = Find("LoadingScreenHandler");
			_characterType = Find("Character");
			_ascentsType = Find("Ascents");
			_ascentDataType = Find("AscentData");
			_runSettingsType = Find("RunSettings");
			_photonType = Find("Photon.Pun.PhotonNetwork");
		}

		private static Type Find(string name)
		{
			Type type = Reflect.Type(name);
			if (type == null)
			{
				Plugin.Log.LogWarning((object)("Type not found: " + name));
			}
			return type;
		}

		public static void ApplyPatches(Harmony harmony)
		{
			TryPatch(harmony, _guiManagerType, "UpdateWindowStatus", "GuiManagerPostfix");
			TryPatch(harmony, _boardingPassType, "OnOpen", "BoardingPassOpenPostfix");
		}

		private static void TryPatch(Harmony harmony, Type type, string method, string postfix)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			try
			{
				MethodInfo methodInfo = Reflect.Method(type, method);
				if (methodInfo == null)
				{
					Plugin.Log.LogWarning((object)("Patch skipped: " + type?.Name + "." + method + " not found."));
				}
				else
				{
					harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(GameApi), postfix, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not patch " + method + ": " + ex.Message));
			}
		}

		private static void GuiManagerPostfix(object __instance)
		{
			if (Plugin.MenuOpen)
			{
				SetMember(__instance, "windowBlockingInput", true);
				SetMember(__instance, "windowShowingCursor", true);
			}
		}

		private static void BoardingPassOpenPostfix(object __instance)
		{
			try
			{
				int? num = Plugin.AscentToRestore();
				if (num.HasValue && GetMember(__instance, "ascentIndex") is int num2 && num2 != num.Value)
				{
					SetMember(__instance, "ascentIndex", num.Value);
					Reflect.Method(__instance.GetType(), "UpdateAscent", Type.EmptyTypes)?.Invoke(__instance, null);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not restore ascent: " + ex.Message));
			}
		}

		public static string AscentLabel()
		{
			int currentAscent = CurrentAscent;
			bool isCustomRun = IsCustomRun;
			string text = string.Format("{0}|{1}|{2}", currentAscent, isCustomRun, Plugin.T("en", "fr"));
			if (text == _labelKey)
			{
				return _label;
			}
			string text2 = null;
			try
			{
				if (_ascentDataSingleton == null && _ascentDataType != null)
				{
					_ascentDataSingleton = Reflect.Type("Zorro.Core.SingletonAsset`1")?.MakeGenericType(_ascentDataType);
				}
				if (Reflect.Get(Reflect.GetStatic(_ascentDataSingleton, "Instance"), "ascents") is IList list)
				{
					int num = ((!isCustomRun) ? (currentAscent + 2) : 0);
					if (num >= 0 && num < list.Count && Reflect.Get(list[num], "localizedTitle") is string text3 && !string.IsNullOrEmpty(text3))
					{
						text2 = text3;
					}
				}
			}
			catch
			{
			}
			if (text2 == null)
			{
				text2 = (isCustomRun ? Plugin.T("Custom run", "Partie personnalisée") : ((currentAscent <= 0) ? "Normal" : $"Ascent {currentAscent}"));
			}
			_labelKey = text;
			_label = text2;
			return text2;
		}

		public static Object FindKiosk()
		{
			if (!(_kioskType == null))
			{
				return Object.FindObjectOfType(_kioskType);
			}
			return null;
		}

		public static bool OpenBoardingPass()
		{
			try
			{
				Object val = FindKiosk();
				object obj = GetStatic(_guiManagerType, "instance");
				object obj2 = ((obj == null) ? null : GetMember(obj, "boardingPass"));
				if (val == (Object)null || obj2 == null)
				{
					Plugin.Log.LogError((object)"Check-in kiosk or boarding pass not found.");
					return false;
				}
				MethodInfo methodInfo = Reflect.Method(obj2.GetType(), "Open", Type.EmptyTypes);
				if (methodInfo == null)
				{
					Plugin.Log.LogError((object)"MenuWindow.Open not found.");
					return false;
				}
				SetMember(obj2, "kiosk", val);
				methodInfo.Invoke(obj2, null);
				SetMember(obj2, "kiosk", val);
				return true;
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"OpenBoardingPass : {arg}");
				return false;
			}
		}

		public static bool InviteFriends()
		{
			try
			{
				Object val = ((_inviteKioskType == null) ? null : Object.FindObjectOfType(_inviteKioskType));
				if (val == (Object)null)
				{
					return false;
				}
				MethodInfo methodInfo = Reflect.Method(_inviteKioskType, "Interact");
				if (methodInfo == null)
				{
					return false;
				}
				ParameterInfo[] parameters = methodInfo.GetParameters();
				methodInfo.Invoke(val, (parameters.Length != 1) ? BuildArgs(parameters) : new object[1] { LocalCharacter });
				return true;
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"InviteFriends : {arg}");
				return false;
			}
		}

		public static bool StartGame(int ascent)
		{
			try
			{
				Object val = FindKiosk();
				MethodInfo methodInfo = ((val == (Object)null) ? null : Reflect.Method(_kioskType, "StartGame", new Type[1] { typeof(int) }));
				if (methodInfo == null)
				{
					return false;
				}
				methodInfo.Invoke(val, new object[1] { ascent });
				return true;
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"StartGame : {arg}");
				return false;
			}
		}

		public static bool ReturnToAirport()
		{
			try
			{
				Object val = ((_gameOverType == null) ? null : Object.FindObjectOfType(_gameOverType));
				MethodInfo methodInfo = ((val == (Object)null) ? null : Reflect.Method(_gameOverType, "LoadAirport", Type.EmptyTypes));
				if (methodInfo != null)
				{
					methodInfo.Invoke(val, null);
					return true;
				}
				Plugin.Log.LogWarning((object)"GameOverHandler not found, loading the Airport directly.");
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("GameOverHandler.LoadAirport failed: " + ex.Message));
			}
			return LoadAirportDirect();
		}

		private static bool LoadAirportDirect()
		{
			try
			{
				Object val = ((_loadingType == null) ? null : Object.FindObjectOfType(_loadingType));
				if (val == (Object)null)
				{
					return false;
				}
				MethodInfo methodInfo = Reflect.Method(_loadingType, "LoadSceneProcess");
				MethodInfo methodInfo2 = Reflect.Method(_loadingType, "Load");
				if (methodInfo == null || methodInfo2 == null)
				{
					return false;
				}
				IEnumerator enumerator = (IEnumerator)methodInfo.Invoke(val, BuildArgs(methodInfo.GetParameters(), "Airport", true, true));
				ParameterInfo[] parameters = methodInfo2.GetParameters();
				object[] array = new object[parameters.Length];
				for (int i = 0; i < parameters.Length; i++)
				{
					Type parameterType = parameters[i].ParameterType;
					if (parameterType.IsEnum)
					{
						array[i] = Enum.Parse(parameterType, "Basic");
					}
					else if (typeof(IEnumerator).IsAssignableFrom(parameterType))
					{
						array[i] = enumerator;
					}
					else
					{
						array[i] = (parameters[i].HasDefaultValue ? parameters[i].DefaultValue : null);
					}
				}
				methodInfo2.Invoke(val, array);
				return true;
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Could not load the Airport: {arg}");
				return false;
			}
		}

		private static object[] BuildArgs(ParameterInfo[] ps, params object[] given)
		{
			object[] array = new object[ps.Length];
			for (int i = 0; i < ps.Length; i++)
			{
				if (i < given.Length)
				{
					array[i] = given[i];
				}
				else if (ps[i].HasDefaultValue)
				{
					array[i] = ps[i].DefaultValue;
				}
				else
				{
					array[i] = (ps[i].ParameterType.IsValueType ? Activator.CreateInstance(ps[i].ParameterType) : null);
				}
			}
			return array;
		}

		private static object GetStatic(Type t, string name)
		{
			return Reflect.GetStatic(t, name);
		}

		private static object GetMember(object o, string name)
		{
			return Reflect.Get(o, name);
		}

		private static void SetMember(object o, string name, object value)
		{
			Reflect.Set(o, name, value);
		}
	}
	internal enum Side
	{
		Below,
		Above,
		Left,
		Right
	}
	internal sealed class HudNode
	{
		public int Parent = -1;

		public Side Side;

		public float Ax;

		public float Ay;

		public bool PivotRight;

		public string Text;

		public bool Visible;

		public Vector2 Size;

		public Rect Rect;
	}
	internal sealed class Hud
	{
		public const int Count = 3;

		private const string DefaultLayout = "-1:0:0.990:0.020:1|0:0:0:0:1|1:0:0:0:1";

		private readonly HudNode[] _n = new HudNode[3];

		private readonly ConfigEntry<string> _layoutCfg;

		private int _layoutFrame = -1;

		private int _drag = -1;

		private Vector2 _grab;

		private int _snapTarget = -1;

		private Side _snapSide;

		private float? _guideX;

		private float? _guideY;

		private Rect _snapEdge;

		private readonly HudRenderer _renderer = new HudRenderer();

		private Texture2D _white;

		private static readonly Color[] GroupColors = (Color[])(object)new Color[3]
		{
			new Color(1f, 0.78f, 0.3f),
			new Color(0.35f, 0.85f, 1f),
			new Color(1f, 0.45f, 0.75f)
		};

		private static float Scale => Mathf.Max(0.5f, (float)Screen.height / 1080f);

		private static float Gap => 2f * Scale;

		private static float Margin => 12f * Scale;

		private static float SnapDistance => 18f * Scale;

		public IReadOnlyList<Object> Fonts => _renderer.Fonts;

		public string AutoFontName => _renderer.AutoFontName;

		public Object CurrentFont => _renderer.CurrentFont;

		public Hud(ConfigEntry<string> layoutCfg)
		{
			_layoutCfg = layoutCfg;
			for (int i = 0; i < 3; i++)
			{
				_n[i] = new HudNode();
			}
			Load(_layoutCfg.Value);
		}

		public void ResetLayout()
		{
			Load("-1:0:0.990:0.020:1|0:0:0:0:1|1:0:0:0:1");
			Save();
		}

		private void Load(string s)
		{
			if (!TryParse(s) && !TryParse("-1:0:0.990:0.020:1|0:0:0:0:1|1:0:0:0:1"))
			{
				throw new InvalidOperationException("Invalid default HUD layout");
			}
		}

		private bool TryParse(string s)
		{
			try
			{
				string[] array = (s ?? "").Split('|');
				if (array.Length != 3)
				{
					return false;
				}
				HudNode[] array2 = new HudNode[3];
				for (int i = 0; i < 3; i++)
				{
					string[] array3 = array[i].Split(':');
					if (array3.Length != 5)
					{
						return false;
					}
					array2[i] = new HudNode
					{
						Parent = int.Parse(array3[0], CultureInfo.InvariantCulture),
						Side = (Side)int.Parse(array3[1], CultureInfo.InvariantCulture),
						Ax = Mathf.Clamp01(float.Parse(array3[2], CultureInfo.InvariantCulture)),
						Ay = Mathf.Clamp01(float.Parse(array3[3], CultureInfo.InvariantCulture)),
						PivotRight = (array3[4] == "1")
					};
					if (array2[i].Parent < -1 || array2[i].Parent >= 3 || array2[i].Parent == i)
					{
						return false;
					}
					if (!Enum.IsDefined(typeof(Side), array2[i].Side))
					{
						return false;
					}
				}
				for (int j = 0; j < 3; j++)
				{
					int num = j;
					int num2 = 0;
					while (array2[num].Parent >= 0 && num2++ <= 3)
					{
						num = array2[num].Parent;
					}
					if (array2[num].Parent >= 0)
					{
						return false;
					}
				}
				for (int k = 0; k < 3; k++)
				{
					_n[k].Parent = array2[k].Parent;
					_n[k].Side = array2[k].Side;
					_n[k].Ax = array2[k].Ax;
					_n[k].Ay = array2[k].Ay;
					_n[k].PivotRight = array2[k].PivotRight;
				}
				return true;
			}
			catch
			{
				return false;
			}
		}

		private void Save()
		{
			string[] array = new string[3];
			for (int i = 0; i < 3; i++)
			{
				HudNode hudNode = _n[i];
				array[i] = string.Format(CultureInfo.InvariantCulture, "{0}:{1}:{2:0.0000}:{3:0.0000}:{4}", hudNode.Parent, (int)hudNode.Side, hudNode.Ax, hudNode.Ay, hudNode.PivotRight ? 1 : 0);
			}
			_layoutCfg.Value = string.Join("|", array);
		}

		public void SetTexts(string[] texts)
		{
			for (int i = 0; i < 3; i++)
			{
				_n[i].Text = texts[i];
				_n[i].Visible = !string.IsNullOrEmpty(texts[i]);
			}
			_layoutFrame = -1;
		}

		private int Root(int i)
		{
			int num = 0;
			while (_n[i].Parent >= 0 && num++ <= 3)
			{
				i = _n[i].Parent;
			}
			return i;
		}

		private bool SameGroup(int a, int b)
		{
			return Root(a) == Root(b);
		}

		private static Side Opposite(Side s)
		{
			return s switch
			{
				Side.Below => Side.Above, 
				Side.Above => Side.Below, 
				Side.Left => Side.Right, 
				_ => Side.Left, 
			};
		}

		private static Rect Attach(Rect p, Vector2 size, Side side, bool pivotRight)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_007a: 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_00aa: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			bool flag = ((Rect)(ref p)).width > 0f && ((Rect)(ref p)).height > 0f;
			float num = (flag ? Gap : 0f);
			return (Rect)(side switch
			{
				Side.Below => new Rect(pivotRight ? (((Rect)(ref p)).xMax - size.x) : ((Rect)(ref p)).x, ((Rect)(ref p)).yMax + num, size.x, size.y), 
				Side.Above => new Rect(pivotRight ? (((Rect)(ref p)).xMax - size.x) : ((Rect)(ref p)).x, ((Rect)(ref p)).y - num - size.y, size.x, size.y), 
				Side.Right => new Rect(((Rect)(ref p)).xMax + (flag ? (Gap * 4f) : 0f), ((Rect)(ref p)).y, size.x, size.y), 
				_ => new Rect(((Rect)(ref p)).x - (flag ? (Gap * 4f) : 0f) - size.x, ((Rect)(ref p)).y, size.x, size.y), 
			});
		}

		private Rect RootRect(HudNode n)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			float num = n.Ax * (float)Screen.width;
			float num2 = n.Ay * (float)Screen.height;
			return new Rect(n.PivotRight ? (num - n.Size.x) : num, num2, n.Size.x, n.Size.y);
		}

		private void Layout(bool force = false)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: 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)
			if (!force && _layoutFrame == Time.frameCount)
			{
				return;
			}
			_layoutFrame = Time.frameCount;
			for (int i = 0; i < 3; i++)
			{
				_n[i].Size = (_n[i].Visible ? _renderer.Measure(i, _n[i].Text) : Vector2.zero);
			}
			bool[] array = new bool[3];
			for (int j = 0; j < 3; j++)
			{
				if (_n[j].Parent < 0)
				{
					_n[j].Rect = RootRect(_n[j]);
					array[j] = true;
				}
			}
			for (int k = 0; k < 3; k++)
			{
				for (int l = 0; l < 3; l++)
				{
					HudNode hudNode = _n[l];
					if (!array[l] && array[hudNode.Parent])
					{
						hudNode.Rect = Attach(_n[hudNode.Parent].Rect, hudNode.Size, hudNode.Side, _n[Root(l)].PivotRight);
						array[l] = true;
					}
				}
			}
			for (int m = 0; m < 3; m++)
			{
				if (_n[m].Parent >= 0 || !GroupBounds(m, out var bounds))
				{
					continue;
				}
				float num = 0f;
				float num2 = 0f;
				if (((Rect)(ref bounds)).xMax > (float)Screen.width)
				{
					num = (float)Screen.width - ((Rect)(ref bounds)).xMax;
				}
				if (((Rect)(ref bounds)).x + num < 0f)
				{
					num = 0f - ((Rect)(ref bounds)).x;
				}
				if (((Rect)(ref bounds)).yMax > (float)Screen.height)
				{
					num2 = (float)Screen.height - ((Rect)(ref bounds)).yMax;
				}
				if (((Rect)(ref bounds)).y + num2 < 0f)
				{
					num2 = 0f - ((Rect)(ref bounds)).y;
				}
				if (num == 0f && num2 == 0f)
				{
					continue;
				}
				for (int n = 0; n < 3; n++)
				{
					if (Root(n) == m)
					{
						ref Rect rect = ref _n[n].Rect;
						((Rect)(ref rect)).position = ((Rect)(ref rect)).position + new Vector2(num, num2);
					}
				}
			}
		}

		private bool GroupBounds(int root, out Rect bounds)
		{
			//IL_0001: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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)
			bounds = default(Rect);
			bool flag = false;
			for (int i = 0; i < 3; i++)
			{
				if (Root(i) == root && _n[i].Visible)
				{
					Rect rect = _n[i].Rect;
					bounds = (flag ? Rect.MinMaxRect(Mathf.Min(((Rect)(ref bounds)).xMin, ((Rect)(ref rect)).xMin), Mathf.Min(((Rect)(ref bounds)).yMin, ((Rect)(ref rect)).yMin), Mathf.Max(((Rect)(ref bounds)).xMax, ((Rect)(ref rect)).xMax), Mathf.Max(((Rect)(ref bounds)).yMax, ((Rect)(ref rect)).yMax)) : rect);
					flag = true;
				}
			}
			return flag;
		}

		private void SetRootFromRect(HudNode n, Rect r, bool pivotRight)
		{
			n.Parent = -1;
			n.PivotRight = pivotRight;
			n.Ax = Mathf.Clamp01((pivotRight ? ((Rect)(ref r)).xMax : ((Rect)(ref r)).x) / (float)Screen.width);
			n.Ay = Mathf.Clamp01(((Rect)(ref r)).y / (float)Screen.height);
		}

		private void Reroot(int n)
		{
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			int num = Root(n);
			if (num != n)
			{
				bool pivotRight = _n[num].PivotRight;
				List<int> list = new List<int> { n };
				while (_n[list[list.Count - 1]].Parent >= 0)
				{
					list.Add(_n[list[list.Count - 1]].Parent);
				}
				for (int num2 = list.Count - 1; num2 >= 1; num2--)
				{
					HudNode hudNode = _n[list[num2 - 1]];
					HudNode obj = _n[list[num2]];
					obj.Parent = list[num2 - 1];
					obj.Side = Opposite(hudNode.Side);
				}
				SetRootFromRect(_n[n], _n[n].Rect, pivotRight);
			}
		}

		private void Detach(int n)
		{
			//IL_011d: 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)
			int num = Root(n);
			bool pivotRight = _n[num].PivotRight;
			List<int> list = new List<int>();
			for (int i = 0; i < 3; i++)
			{
				if (_n[i].Parent == n)
				{
					list.Add(i);
				}
			}
			if (_n[n].Parent >= 0)
			{
				foreach (int item in list)
				{
					_n[item].Parent = _n[n].Parent;
					_n[item].Side = _n[n].Side;
				}
			}
			else if (list.Count > 0)
			{
				int num2 = list[0];
				SetRootFromRect(_n[num2], _n[num2].Rect, pivotRight);
				for (int j = 1; j < list.Count; j++)
				{
					_n[list[j]].Parent = num2;
				}
			}
			SetRootFromRect(_n[n], _n[n].Rect, pivotRight);
		}

		private bool SlotTaken(int t, Side s)
		{
			for (int i = 0; i < 3; i++)
			{
				if (_n[i].Parent == t && _n[i].Side == s && _n[i].Visible)
				{
					return true;
				}
			}
			if (_n[t].Parent >= 0 && Opposite(_n[t].Side) == s)
			{
				return _n[_n[t].Parent].Visible;
			}
			return false;
		}

		private void HandleMouse(Rect menuWindow)
		{
			//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_000e: 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: Invalid comparison between Unknown and I4
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Invalid comparison between Unknown and I4
			//IL_0022: 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_00da: Invalid comparison between Unknown and I4
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_0085: 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)
			Event current = Event.current;
			Vector2 mousePosition = current.mousePosition;
			if ((int)current.type == 0 && current.button == 0 && !((Rect)(ref menuWindow)).Contains(mousePosition))
			{
				for (int num = 2; num >= 0; num--)
				{
					if (_n[num].Visible && ((Rect)(ref _n[num].Rect)).Contains(mousePosition))
					{
						if (current.shift)
						{
							Detach(num);
						}
						else
						{
							Reroot(num);
						}
						_drag = num;
						_grab = mousePosition - ((Rect)(ref _n[num].Rect)).position;
						current.Use();
						break;
					}
				}
			}
			else if ((int)current.type == 3 && _drag >= 0)
			{
				MoveDragged(mousePosition - _grab);
				current.Use();
			}
			else if (((int)current.type == 1 || (int)current.rawType == 1) && _drag >= 0)
			{
				Drop();
				current.Use();
			}
		}

		private void MoveDragged(Vector2 wanted)
		{
			//IL_0035: 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_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: 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_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: 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_00dd: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
			HudNode hudNode = _n[_drag];
			_snapTarget = -1;
			_guideX = null;
			_guideY = null;
			float num = SnapDistance;
			Rect snapEdge = default(Rect);
			for (int i = 0; i < 3; i++)
			{
				if (!_n[i].Visible || SameGroup(i, _drag))
				{
					continue;
				}
				bool pivotRight = _n[Root(i)].PivotRight;
				foreach (Side value in Enum.GetValues(typeof(Side)))
				{
					if (!SlotTaken(i, value))
					{
						Rect val = Attach(_n[i].Rect, hudNode.Size, value, pivotRight);
						Vector2 val2 = ((Rect)(ref val)).position - wanted;
						float magnitude = ((Vector2)(ref val2)).magnitude;
						if (magnitude < num)
						{
							num = magnitude;
							snapEdge = val;
							_snapTarget = i;
							_snapSide = value;
						}
					}
				}
			}
			Vector2 val3 = wanted;
			Rect bounds;
			if (_snapTarget >= 0)
			{
				val3 = ((Rect)(ref snapEdge)).position;
				_snapEdge = snapEdge;
			}
			else if (GroupBounds(_drag, out bounds))
			{
				Vector2 val4 = wanted - ((Rect)(ref hudNode.Rect)).position;
				((Rect)(ref bounds)).position = ((Rect)(ref bounds)).position + val4;
				val3 += new Vector2(SnapAxis(((Rect)(ref bounds)).xMin, ((Rect)(ref bounds)).xMax, Screen.width, out _guideX), SnapAxis(((Rect)(ref bounds)).yMin, ((Rect)(ref bounds)).yMax, Screen.height, out _guideY));
			}
			SetRootFromRect(hudNode, new Rect(val3, hudNode.Size), hudNode.PivotRight);
			Layout(force: true);
		}

		private static float SnapAxis(float min, float max, float screen, out float? guide)
		{
			float? num = null;
			float num2 = SnapDistance;
			float result = 0f;
			(float, float)[] array = new(float, float)[3]
			{
				(min, Margin),
				(max, screen - Margin),
				((min + max) / 2f, screen / 2f)
			};
			for (int i = 0; i < array.Length; i++)
			{
				(float, float) tuple = array[i];
				float num3 = Mathf.Abs(tuple.Item1 - tuple.Item2);
				if (num3 < num2)
				{
					num2 = num3;
					result = tuple.Item2 - tuple.Item1;
					num = tuple.Item2;
				}
			}
			guide = num;
			return result;
		}

		private void Drop()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			HudNode hudNode = _n[_drag];
			Rect bounds;
			if (_snapTarget >= 0)
			{
				hudNode.Parent = _snapTarget;
				hudNode.Side = _snapSide;
			}
			else if (GroupBounds(_drag, out bounds))
			{
				bool pivotRight = ((Rect)(ref bounds)).center.x > (float)Screen.width / 2f;
				SetRootFromRect(hudNode, hudNode.Rect, pivotRight);
			}
			_drag = -1;
			_snapTarget = -1;
			_guideX = null;
			_guideY = null;
			Save();
		}

		public void RefreshFonts(bool force)
		{
			_renderer.RefreshFonts(force);
		}

		public void ApplyFont(string wanted)
		{
			_renderer.ApplyFont(wanted);
		}

		public void LateUpdate()
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if (_renderer.Ready && _renderer.UsesTextMeshPro)
			{
				Layout();
				for (int i = 0; i < 3; i++)
				{
					_renderer.Place(i, _n[i].Visible, _n[i].Text, _n[i].Rect, _n[Root(i)].PivotRight);
				}
			}
		}

		public void OnGUI(bool editing, Rect menuWindow)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Invalid comparison between Unknown and I4
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Expected O, but got Unknown
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//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_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0364: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0429: Unknown result type (might be due to invalid IL or missing references)
			//IL_042e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f0: 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_0213: 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_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			if (!_renderer.Ready)
			{
				return;
			}
			if (!editing)
			{
				_drag = -1;
				_snapTarget = -1;
				_guideX = null;
				_guideY = null;
			}
			Layout();
			if (editing)
			{
				HandleMouse(menuWindow);
			}
			if ((int)Event.current.type != 7)
			{
				return;
			}
			if (!_renderer.UsesTextMeshPro)
			{
				for (int i = 0; i < 3; i++)
				{
					if (_n[i].Visible)
					{
						_renderer.DrawFallback(_n[i].Text, _n[i].Rect, _n[Root(i)].PivotRight);
					}
				}
			}
			if (!editing)
			{
				return;
			}
			if ((Object)(object)_white == (Object)null)
			{
				_white = new Texture2D(1, 1);
				_white.SetPixel(0, 0, Color.white);
				_white.Apply();
			}
			Dictionary<int, Color> dictionary = new Dictionary<int, Color>();
			for (int j = 0; j < 3; j++)
			{
				if (!_n[j].Visible)
				{
					continue;
				}
				int num = Root(j);
				int num2 = 0;
				for (int k = 0; k < 3; k++)
				{
					if (Root(k) == num && _n[k].Visible)
					{
						num2++;
					}
				}
				if (!dictionary.TryGetValue(num, out var value))
				{
					value = (dictionary[num] = (Color)((num2 > 1) ? GroupColors[dictionary.Count % GroupColors.Length] : new Color(1f, 1f, 1f, 0.6f)));
				}
				Rect rect = _n[j].Rect;
				((Rect)(ref rect)).xMin = ((Rect)(ref rect)).xMin - 4f;
				((Rect)(ref rect)).xMax = ((Rect)(ref rect)).xMax + 4f;
				((Rect)(ref rect)).yMin = ((Rect)(ref rect)).yMin - 2f;
				((Rect)(ref rect)).yMax = ((Rect)(ref rect)).yMax + 2f;
				if (!((Rect)(ref menuWindow)).Overlaps(rect))
				{
					Frame(rect, value, (j == _drag) ? 2f : 1f);
				}
			}
			Color c = default(Color);
			((Color)(ref c))..ctor(1f, 1f, 1f, 0.5f);
			float? guideX = _guideX;
			if (guideX.HasValue)
			{
				float valueOrDefault = guideX.GetValueOrDefault();
				Fill(new Rect(valueOrDefault, 0f, 1f, (float)Screen.height), c);
			}
			guideX = _guideY;
			if (guideX.HasValue)
			{
				float valueOrDefault2 = guideX.GetValueOrDefault();
				Fill(new Rect(0f, valueOrDefault2, (float)Screen.width, 1f), c);
			}
			if (_snapTarget >= 0)
			{
				Rect rect2 = _n[_snapTarget].Rect;
				Color c2 = default(Color);
				((Color)(ref c2))..ctor(1f, 1f, 1f, 0.8f);
				switch (_snapSide)
				{
				case Side.Below:
					Fill(new Rect(Mathf.Min(((Rect)(ref rect2)).x, ((Rect)(ref _snapEdge)).x), ((Rect)(ref rect2)).yMax, Mathf.Max(((Rect)(ref rect2)).width, ((Rect)(ref _snapEdge)).width), 1f), c2);
					break;
				case Side.Above:
					Fill(new Rect(Mathf.Min(((Rect)(ref rect2)).x, ((Rect)(ref _snapEdge)).x), ((Rect)(ref rect2)).y - 1f, Mathf.Max(((Rect)(ref rect2)).width, ((Rect)(ref _snapEdge)).width), 1f), c2);
					break;
				case Side.Right:
					Fill(new Rect(((Rect)(ref rect2)).xMax + 1f, ((Rect)(ref rect2)).y, 1f, Mathf.Max(((Rect)(ref rect2)).height, ((Rect)(ref _snapEdge)).height)), c2);
					break;
				default:
					Fill(new Rect(((Rect)(ref rect2)).x - 2f, ((Rect)(ref rect2)).y, 1f, Mathf.Max(((Rect)(ref rect2)).height, ((Rect)(ref _snapEdge)).height)), c2);
					break;
				}
			}
		}

		private void Fill(Rect r, Color c)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Color color = GUI.color;
			GUI.color = c;
			GUI.DrawTexture(r, (Texture)(object)_white);
			GUI.color = color;
		}

		private void Frame(Rect r, Color c, float t)
		{
			//IL_0017: 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_003b: 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_005d: 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)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			Fill(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, ((Rect)(ref r)).width, t), c);
			Fill(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).yMax - t, ((Rect)(ref r)).width, t), c);
			Fill(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, t, ((Rect)(ref r)).height), c);
			Fill(new Rect(((Rect)(ref r)).xMax - t, ((Rect)(ref r)).y, t, ((Rect)(ref r)).height), c);
		}
	}
	internal sealed class HudRenderer
	{
		private Type _tmpUgui;

		private Type _tmpText;

		private GameObject _canvasGo;

		private readonly Component[] _texts = (Component[])(object)new Component[3];

		private readonly string[] _lastText = new string[3];

		private readonly Vector2[] _lastSize = (Vector2[])(object)new Vector2[3];

		private float _lastFontSize = -1f;

		private bool _failed;

		private readonly List<Object> _fonts = new List<Object>();

		private string _autoFont;

		private string _appliedKey;

		private readonly Dictionary<Object, Material> _materials = new Dictionary<Object, Material>();

		private const string PreferredFont = "DarumaDropOne";

		private string _lastWanted;

		private readonly bool[] _placedVisible = new bool[3];

		private readonly string[] _placedText = new string[3];

		private readonly Rect[] _placedRect = (Rect[])(object)new Rect[3];

		private readonly bool[] _placedRight = new bool[3];

		private readonly bool[] _placedOnce = new bool[3];

		private GUIStyle _fallbackStyle;

		private static readonly Dictionary<string, object> EnumCache = new Dictionary<string, object>();

		public bool UsesTextMeshPro
		{
			get
			{
				if ((Object)(object)_canvasGo != (Object)null)
				{
					return !_failed;
				}
				return false;
			}
		}

		public bool Ready
		{
			get
			{
				if (!UsesTextMeshPro && !TryInit())
				{
					return _failed;
				}
				return true;
			}
		}

		private float FontSize => 26f * Mathf.Max(0.5f, (float)Screen.height / 1080f);

		public IReadOnlyList<Object> Fonts => _fonts;

		public string AutoFontName => _autoFont;

		public Object CurrentFont { get; private set; }

		private bool TryInit()
		{
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: 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_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			if (_failed || (Object)(object)_canvasGo != (Object)null)
			{
				return UsesTextMeshPro;
			}
			try
			{
				_tmpUgui = Reflect.Type("TMPro.TextMeshProUGUI");
				_tmpText = Reflect.Type("TMPro.TMP_Text");
				if (_tmpUgui == null || _tmpText == null)
				{
					throw new Exception("TextMeshPro not found");
				}
				_canvasGo = new GameObject("PeakQuickBoard_HUD", new Type[2]
				{
					typeof(RectTransform),
					typeof(Canvas)
				});
				Object.DontDestroyOnLoad((Object)(object)_canvasGo);
				Canvas component = _canvasGo.GetComponent<Canvas>();
				component.renderMode = (RenderMode)0;
				component.sortingOrder = 100;
				for (int i = 0; i < 3; i++)
				{
					GameObject val = new GameObject("Text" + i, new Type[1] { typeof(RectTransform) });
					val.transform.SetParent(_canvasGo.transform, false);
					RectTransform val2 = (RectTransform)val.transform;
					Vector2 anchorMin = (val2.anchorMax = new Vector2(0f, 1f));
					val2.anchorMin = anchorMin;
					val2.pivot = new Vector2(0f, 1f);
					Component val4 = val.AddComponent(_tmpUgui);
					Set(val4, "raycastTarget", false);
					Set(val4, "richText", false);
					Set(val4, "color", Color.white);
					SetEnum(val4, "textWrappingMode", "NoWrap");
					Set(val4, "enableWordWrapping", false);
					val.SetActive(false);
					_texts[i] = val4;
				}
				return true;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("TextMeshPro HUD unavailable, using basic text: " + ex.Message));
				_failed = true;
				if ((Object)(object)_canvasGo != (Object)null)
				{
					Object.Destroy((Object)(object)_canvasGo);
				}
				_canvasGo = null;
				return false;
			}
		}

		public void RefreshFonts(bool force)
		{
			if (!UsesTextMeshPro || (!force && _fonts.Count > 0))
			{
				return;
			}
			try
			{
				Type type = Reflect.Type("TMPro.TMP_FontAsset");
				if (type == null)
				{
					return;
				}
				Dictionary<Object, int> usage = new Dictionary<Object, int>();
				Object[] array = Object.FindObjectsOfType(_tmpText);
				foreach (Object val in array)
				{
					Object[] texts = (Object[])(object)_texts;
					if (Array.IndexOf(texts, val) < 0)
					{
						object obj = Get(val, "font");
						Object val2 = (Object)((obj is Object) ? obj : null);
						if (val2 != null && val2 != (Object)null)
						{
							usage[val2] = ((!usage.TryGetValue(val2, out var value)) ? 1 : (value + 1));
						}
					}
				}
				List<Object> list = new List<Object>();
				array = Resources.FindObjectsOfTypeAll(type);
				foreach (Object val3 in array)
				{
					if (val3 != (Object)null && !IsDefaultFont(val3) && !list.Contains(val3))
					{
						list.Add(val3);
					}
				}
				list.Sort(delegate(Object a, Object b)
				{
					bool flag2 = IsPreferredFont(a);
					bool flag3 = IsPreferredFont(b);
					if (flag2 != flag3)
					{
						if (!flag2)
						{
							return 1;
						}
						return -1;
					}
					int value3;
					int num2 = (usage.TryGetValue(a, out value3) ? value3 : 0);
					int value4;
					int num3 = (usage.TryGetValue(b, out value4) ? value4 : 0);
					return (num3 == num2) ? string.CompareOrdinal(a.name, b.name) : num3.CompareTo(num2);
				});
				bool flag = list.Count != _fonts.Count;
				int num = 0;
				while (!flag && num < list.Count)
				{
					flag = !_fonts.Contains(list[num]);
					num++;
				}
				if (!flag)
				{
					return;
				}
				_fonts.Clear();
				_fonts.AddRange(list);
				_autoFont = ((_fonts.Count > 0) ? _fonts[0].name : null);
				_appliedKey = null;
				List<string> list2 = new List<string>();
				foreach (Object font in _fonts)
				{
					list2.Add($"{font.name} ({(usage.TryGetValue(font, out var value2) ? value2 : 0)} texts)");
				}
				Plugin.Log.LogInfo((object)("Game fonts found: " + ((list2.Count > 0) ? string.Join(", ", list2) : "none")));
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Font scan failed: " + ex.Message));
			}
		}

		private static bool IsPreferredFont(Object f)
		{
			return f.name.IndexOf("DarumaDropOne", StringComparison.OrdinalIgnoreCase) >= 0;
		}

		private static bool IsDefaultFont(Object f)
		{
			return f.name.IndexOf("LiberationSans", StringComparison.OrdinalIgnoreCase) >= 0;
		}

		public void ApplyFont(string wanted)
		{
			if (!UsesTextMeshPro || (_appliedKey != null && wanted == _lastWanted))
			{
				return;
			}
			_lastWanted = wanted;
			Object val = null;
			if (!string.IsNullOrEmpty(wanted))
			{
				val = _fonts.Find((Object f) => f != (Object)null && f.name == wanted);
			}
			if (val == (Object)null && _fonts.Count > 0)
			{
				val = _fonts[0];
			}
			string text = ((val != (Object)null) ? val.name : "<default>");
			if (text == _appliedKey)
			{
				return;
			}
			_appliedKey = text;
			CurrentFont = val;
			try
			{
				Component[] texts = _texts;
				foreach (Component o in texts)
				{
					if (val != (Object)null)
					{
						Set(o, "font", val);
					}
					object obj = ((val != (Object)null) ? Get(val, "material") : null);
					Material val2 = (Material)(((obj is Material) ? obj : null) ?? ((object)/*isinst with value type is only supported in some contexts*/));
					Material val3 = OutlinedMaterial((Object)(((object)val) ?? ((object)val2)), val2);
					if ((Object)(object)val3 != (Object)null)
					{
						Set(o, "fontSharedMaterial", val3);
					}
				}
				Array.Clear(_lastText, 0, _lastText.Length);
				Plugin.Log.LogInfo((object)((val != (Object)null) ? ("HUD font: " + val.name) : "HUD font: TextMeshPro default (no game font found yet)"));
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not apply the HUD font: " + ex.Message));
			}
		}

		private Material OutlinedMaterial(Object key, Material source)
		{
			//IL_0030: 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_004c: Expected O, but got Unknown
			//IL_007a: 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)
			if (key == (Object)null || (Object)(object)source == (Object)null)
			{
				return null;
			}
			if (_materials.TryGetValue(key, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			Material val = new Material(source)
			{
				name = ((Object)source).name + " (PeakQuickBoard HUD)"
			};
			if (val.HasProperty("_OutlineWidth"))
			{
				val.EnableKeyword("OUTLINE_ON");
				val.SetFloat("_OutlineWidth", 0.2f);
				val.SetColor("_OutlineColor", Color.black);
				if (val.HasProperty("_FaceDilate"))
				{
					val.SetFloat("_FaceDilate", 0.1f);
				}
			}
			if (val.HasProperty("_UnderlayColor"))
			{
				val.EnableKeyword("UNDERLAY_ON");
				val.SetColor("_UnderlayColor", new Color(0f, 0f, 0f, 0.55f));
				val.SetFloat("_UnderlayOffsetX", 0.5f);
				val.SetFloat("_UnderlayOffsetY", -0.5f);
				if (val.HasProperty("_UnderlayDilate"))
				{
					val.SetFloat("_UnderlayDilate", 0.2f);
				}
				if (val.HasProperty("_UnderlaySoftness"))
				{
					val.SetFloat("_UnderlaySoftness", 0.4f);
				}
			}
			_materials[key] = val;
			return val;
		}

		public Vector2 Measure(int i, string text)
		{
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: 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_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Expected O, but got Unknown
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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_0119: 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_0137: 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_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrEmpty(text))
			{
				return Vector2.zero;
			}
			if (UsesTextMeshPro)
			{
				float fontSize = FontSize;
				if (!Mathf.Approximately(fontSize, _lastFontSize))
				{
					_lastFontSize = fontSize;
					Component[] texts = _texts;
					for (int j = 0; j < texts.Length; j++)
					{
						Set(texts[j], "fontSize", fontSize);
					}
					Array.Clear(_lastText, 0, _lastText.Length);
				}
				if (_lastText[i] == text)
				{
					return _lastSize[i];
				}
				try
				{
					Vector2 val = (Vector2)Reflect.Method(_tmpText, "GetPreferredValues", new Type[1] { typeof(string) }).Invoke(_texts[i], new object[1] { text });
					if (val.x <= 0f || val.y <= 0f)
					{
						((Vector2)(ref val))..ctor((float)text.Length * fontSize * 0.55f, fontSize * 1.2f);
					}
					_lastText[i] = text;
					_lastSize[i] = new Vector2(Mathf.Ceil(val.x) + 2f, Mathf.Ceil(val.y));
					return _lastSize[i];
				}
				catch
				{
					return new Vector2((float)text.Length * fontSize * 0.55f, fontSize * 1.2f);
				}
			}
			EnsureFallbackStyle();
			Vector2 val2 = _fallbackStyle.CalcSize(new GUIContent(text));
			return new Vector2(val2.x + 2f, val2.y + 2f);
		}

		public void Place(int i, bool visible, string text, Rect rect, bool alignRight)
		{
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: 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_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			if (!UsesTextMeshPro)
			{
				return;
			}
			Component val = _texts[i];
			if (!_placedOnce[i] || _placedVisible[i] != visible)
			{
				val.gameObject.SetActive(visible);
				_placedVisible[i] = visible;
			}
			if (!visible)
			{
				_placedOnce[i] = true;
				return;
			}
			if (!_placedOnce[i] || _placedText[i] != text)
			{
				Set(val, "text", text);
				_placedText[i] = text;
			}
			if (!_placedOnce[i] || _placedRight[i] != alignRight)
			{
				SetEnum(val, "alignment", alignRight ? "TopRight" : "TopLeft");
				_placedRight[i] = alignRight;
			}
			if (!_placedOnce[i] || _placedRect[i] != rect)
			{
				RectTransform val2 = (RectTransform)val.transform;
				val2.anchoredPosition = new Vector2(((Rect)(ref rect)).x, 0f - ((Rect)(ref rect)).y);
				val2.sizeDelta = ((Rect)(ref rect)).size;
				_placedRect[i] = rect;
			}
			_placedOnce[i] = true;
		}

		private void EnsureFallbackStyle()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_0053: Expected O, but got Unknown
			if (_fallbackStyle == null)
			{
				_fallbackStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = Mathf.RoundToInt(18f * Mathf.Max(0.5f, (float)Screen.height / 1080f)),
					fontStyle = (FontStyle)1,
					wordWrap = false
				};
			}
		}

		public void DrawFallback(string text, Rect rect, bool alignRight)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			EnsureFallbackStyle();
			_fallbackStyle.alignment = (TextAnchor)(alignRight ? 2 : 0);
			GUIContent val = new GUIContent(text);
			_fallbackStyle.normal.textColor = Color.black;
			for (int i = -1; i <= 1; i++)
			{
				for (int j = -1; j <= 1; j++)
				{
					if (i != 0 || j != 0)
					{
						GUI.Label(new Rect(((Rect)(ref rect)).x + (float)i * 1.5f, ((Rect)(ref rect)).y + (float)j * 1.5f, ((Rect)(ref rect)).width, ((Rect)(ref rect)).height), val, _fallbackStyle);
					}
				}
			}
			_fallbackStyle.normal.textColor = Color.white;
			GUI.Label(rect, val, _fallbackStyle);
		}

		private static object Get(object o, string name)
		{
			return Reflect.Get(o, name);
		}

		private static void Set(object o, string name, object value)
		{
			Reflect.Set(o, name, value);
		}

		private static void SetEnum(object o, string name, string value)
		{
			try
			{
				Type type = Reflect.MemberType(o.GetType(), name);
				if (!(type == null) && type.IsEnum)
				{
					string key = type.FullName + "." + value;
					if (!EnumCache.TryGetValue(key, out var value2))
					{
						value2 = (EnumCache[key] = (Enum.IsDefined(type, value) ? Enum.Parse(type, value) : null));
					}
					if (value2 != null)
					{
						Reflect.Set(o, name, value2);
					}
				}
			}
			catch
			{
			}
		}
	}
	public enum Language
	{
		English,
		Francais
	}
	[BepInPlugin("fr.peakquickboard", "PEAK Quick Board", "1.8.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "fr.peakquickboard";

		public const string Name = "PEAK Quick Board";

		public const string Version = "1.8.0";

		private const int NoAscent = -99;

		internal static ManualLogSource Log;

		private static Plugin _instance;

		private ConfigEntry<Language> _language;

		private ConfigEntry<KeyCode> _boardKey;

		private ConfigEntry<KeyCode> _inviteKey;

		private ConfigEntry<KeyCode> _restartKey;

		private ConfigEntry<KeyCode> _menuKey;

		private ConfigEntry<KeyCode> _hideKey;

		private ConfigEntry<bool> _featBoard;

		private ConfigEntry<bool> _featInvite;

		private ConfigEntry<bool> _featRestart;

		private ConfigEntry<bool> _featAutoHide;

		private ConfigEntry<bool> _featHideKey;

		private ConfigEntry<bool> _hiddenAll;

		private bool _hudSuppressed;

		private ConfigEntry<bool> _autoStartAfterRestart;

		private ConfigEntry<bool> _rememberAscent;

		private ConfigEntry<float> _confirmWindow;

		private ConfigEntry<int> _lastAscent;

		private ConfigEntry<bool> _showAltitude;

		private ConfigEntry<bool> _showAscent;

		private ConfigEntry<bool> _showTimer;

		private ConfigEntry<string> _hudLayout;

		private ConfigEntry<string> _hudFont;

		private Hud _hud;

		private bool _restartPending;

		private int _restartAscent;

		private float _restartArmedUntil = -1f;

		private bool _runArmed;

		private bool _runActive;

		private float _runStart;

		private readonly string[] _hudTexts = new string[3];

		private float _hudNextRefresh;

		private float _fontScanAt = 2f;

		private bool _fontScanForce;

		private int _fontScanTries;

		private string _message;

		private float _messageUntil;

		private bool _menuOpen;

		private ConfigEntry<KeyCode> _rebinding;

		private int _ignoreInputFrame = -1;

		private Rect _window;

		private CursorLockMode _prevLock;

		private bool _prevVisible;

		private static readonly KeyCode[] AllKeys = (KeyCode[])Enum.GetValues(typeof(KeyCode));

		private GUIStyle _warnStyle;

		private GUIStyle _hintStyle;

		private GUIStyle _msgStyle;

		private GUIStyle _titleStyle;

		private GUIStyle _sectionStyle;

		private GUIStyle _labelStyle;

		private GUIStyle _keyStyle;

		private const string QuickResumeGuid = "OnlyCook.PEAKQuickResume";

		private List<KeyValuePair<string, ConfigEntry<KeyCode>>> _foreignKeys;

		private readonly UiKit _ui = new UiKit();

		private int _tab;

		private Vector2? _menuPos;

		private bool _draggingMenu;

		private Vector2 _menuGrab;

		private Rect _menuRect;

		internal static bool MenuOpen
		{
			get
			{
				if ((Object)(object)_instance != (Object)null)
				{
					return _instance._menuOpen;
				}
				return false;
			}
		}

		private bool HiddenAll
		{
			get
			{
				if (_featHideKey.Value)
				{
					return _hiddenAll.Value;
				}
				return false;
			}
		}

		private Rect MenuArea
		{
			get
			{
				//IL_0015: 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)
				if (!_ui.Ready)
				{
					return _window;
				}
				return _menuRect;
			}
		}

		private float RowH => Mathf.Round(44f * _ui.S);

		private float TextSize => 20f * _ui.S;

		internal static string T(string en, string fr)
		{
			if (!((Object)(object)_instance != (Object)null) || _instance._language.Value != Language.Francais)
			{
				return en;
			}
			return fr;
		}

		private void Awake()
		{
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Expected O, but got Unknown
			_instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			_language = ((BaseUnityPlugin)this).Config.Bind<Language>("General", "Language", Language.English, "Mod interface language / Langue de l'interface du mod (English, Francais).");
			_boardKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keys", "OpenBoardingPass", (KeyCode)287, "Airport: open the boarding pass from anywhere.");
			_inviteKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keys", "InviteFriends", (KeyCode)291, "Airport: open the Steam friend invite from anywhere.");
			_restartKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keys", "RestartRun", (KeyCode)289, "In a run: restart the run (press twice to confirm). Host only.");
			_menuKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keys", "ModMenu", (KeyCode)290, "Open / close the mod menu.");
			_hideKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keys", "HideAll", (KeyCode)292, "Hide / show everything the mod displays.");
			_featBoard = ((BaseUnityPlugin)this).Config.Bind<bool>("Features", "BoardingPassAnywhere", true, "Open the boarding pass from anywhere in the Airport.");
			_featInvite = ((BaseUnityPlugin)this).Config.Bind<bool>("Features", "InviteAnywhere", true, "Invite friends from anywhere in the Airport.");
			_featRestart = ((BaseUnityPlugin)this).Config.Bind<bool>("Features", "RestartRun", true, "Restart the run with a key (host).");
			_featAutoHide = ((BaseUnityPlugin)this).Config.Bind<bool>("Features", "HideDuringGameMenus", true, "Hide the HUD while a game menu is open (pause, boarding pass, end screen...) and during cutscenes.");
			_featHideKey = ((BaseUnityPlugin)this).Config.Bind<bool>("Features", "HideAllKey", true, "A key hides / shows everything the mod displays.");
			_hiddenAll = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "HiddenAll", false, "Everything the mod displays is hidden (set with the hide key).");
			_autoStartAfterRestart = ((BaseUnityPlugin)this).Config.Bind<bool>("Restart", "AutoStart", false, "true = after a restart, the plane takes off right away with the same ascent.\nfalse = after a restart, the boarding pass opens.");
			_confirmWindow = ((BaseUnityPlugin)this).Config.Bind<float>("Restart", "ConfirmDelay", 3f, "Time (seconds) to press the restart key a second time.");
			_rememberAscent = ((BaseUnityPlugin)this).Config.Bind<bool>("BoardingPass", "RememberAscent", true, "The boarding pass opens on the last ascent played.");
			_lastAscent = ((BaseUnityPlugin)this).Config.Bind<int>("BoardingPass", "LastAscent", -99, "Filled in automatically by the mod (-99 = none).");
			_showAltitude = ((BaseUnityPlugin)this).Config.Bind<bool>("HUD", "Altitude", true, "Show altitude during a run.");
			_showAscent = ((BaseUnityPlugin)this).Config.Bind<bool>("HUD", "Ascent", true, "Show the ascent during a run.");
			_showTimer = ((BaseUnityPlugin)this).Config.Bind<bool>("HUD", "Timer", true, "Show the time since the run started.");
			_hudLayout = ((BaseUnityPlugin)this).Config.Bind<string>("HUD", "Layout", "", "Position of the HUD elements (set by dragging them while the F9 menu is open).");
			_hudFont = ((BaseUnityPlugin)this).Config.Bind<string>("HUD", "Font", "", "Font of the HUD, among the game's fonts (empty = automatic). Chosen in the F9 menu.");
			_hud = new Hud(_hudLayout);
			GameApi.Init();
			GameApi.ApplyPatches(new Harmony("fr.peakquickboard"));
			SceneManager.sceneLoaded += OnSceneLoaded;
			Log.LogInfo((object)"PEAK Quick Board 1.8.0 loaded.");
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
		}

		internal static int? AscentToRestore()
		{
			if ((Object)(object)_instance == (Object)null || !_instance._rememberAscent.Value)
			{
				return null;
			}
			int value = _instance._lastAscent.Value;
			if (value != -99)
			{
				return value;
			}
			return null;
		}

		private void Update()
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: 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_0108: Unknown result type (might be due to invalid IL or missing references)
			UpdateRunTracking();
			if (_menuOpen && _ui.Ready)
			{
				DrawMenu();
			}
			else
			{
				_ui.Hide();
			}
			if (_rebinding != null)
			{
				CaptureRebind();
			}
			else
			{
				if (Time.frameCount == _ignoreInputFrame)
				{
					return;
				}
				if (Input.GetKeyDown(_menuKey.Value))
				{
					SetMenuOpen(!_menuOpen);
					return;
				}
				if (_menuOpen)
				{
					if (Input.GetKeyDown((KeyCode)27))
					{
						SetMenuOpen(open: false);
					}
					return;
				}
				if (_featBoard.Value && Input.GetKeyDown(_boardKey.Value))
				{
					OnBoardKey();
				}
				if (_featInvite.Value && Input.GetKeyDown(_inviteKey.Value))
				{
					OnInviteKey();
				}
				if (_featRestart.Value && Input.GetKeyDown(_restartKey.Value))
				{
					OnRestartKey();
				}
				if (_featHideKey.Value && Input.GetKeyDown(_hideKey.Value))
				{
					_hiddenAll.Value = !_hiddenAll.Value;
					_hudNextRefresh = 0f;
				}
			}
		}

		private void LateUpdate()
		{
			if (_menuOpen)
			{
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
			}
			if (_fontScanAt >= 0f && Time.unscaledTime >= _fontScanAt)
			{
				_hud.RefreshFonts(_fontScanForce);
				_fontScanForce = false;
				_fontScanTries++;
				_fontScanAt = ((_hud.Fonts.Count == 0 && _fontScanTries < 5) ? (Time.unscaledTime + 3f) : (-1f));
			}
			_hud.ApplyFont(_hudFont.Value);
			bool flag = HudSuppressed();
			if (flag != _hudSuppressed)
			{
				_hudSuppressed = flag;
				_hudNextRefresh = 0f;
			}
			RefreshHud();
			_hud.LateUpdate();
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			bool flag = ((Scene)(ref scene)).name == "Airport" || ((Scene)(ref scene)).name == "Title";
			_runArmed = !flag;
			_runActive = false;
			_hudNextRefresh = 0f;
			_fontScanAt = Time.unscaledTime + 2f;
			_fontScanTries = 0;
			if (_restartPending && ((Scene)(ref scene)).name == "Airport")
			{
				((MonoBehaviour)this).StartCoroutine(AfterAirportLoaded());
			}
		}

		private void UpdateRunTracking()
		{
			if (_runArmed && !_runActive && GameApi.InRun)
			{
				_runArmed = false;
				_runActive = true;
				_runStart = Time.unscaledTime;
				if (!GameApi.IsCustomRun)
				{
					_lastAscent.Value = GameApi.CurrentAscent;
				}
			}
		}

		private void OnBoardKey()
		{
			if (!GameApi.InAirport)
			{
				ShowMessage(T("Only available at the Airport.", "Disponible uniquement à l'aéroport."));
			}
			else if (!GameApi.IsLoading && !GameApi.OpenBoardingPass())
			{
				ShowMessage(T("Could not open the boarding pass (see log).", "Impossible d'ouvrir la carte d'embarquement (voir le log)."));
			}
		}

		private void OnInviteKey()
		{
			if (!GameApi.InAirport)
			{
				ShowMessage(T("Only available at the Airport (otherwise: Pause menu).", "Disponible uniquement à l'aéroport (sinon : menu Pause)."));
			}
			else if (!GameApi.IsLoading && !GameApi.InviteFriends())
			{
				ShowMessage(T("Cannot invite (offline game?).", "Invitation impossible (partie hors ligne ?)."));
			}
		}

		private void OnRestartKey()
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			if (GameApi.InAirport || GameApi.InTitle)
			{
				ShowMessage(T("You are not in a run.", "Tu n'es pas en partie."));
			}
			else
			{
				if (GameApi.IsLoading || _restartPending)
				{
					return;
				}
				if (!GameApi.IsHost)
				{
					ShowMessage(T("Only the host can restart the run.", "Seul l'hôte peut relancer la partie."));
					return;
				}
				if (Time.unscaledTime > _restartArmedUntil)
				{
					_restartArmedUntil = Time.unscaledTime + _confirmWindow.Value;
					string text = KeyName(_restartKey.Value);
					ShowMessage(T("Press " + text + " again to restart the run.", "Appuie encore sur " + text + " pour relancer la partie."), _confirmWindow.Value);
					return;
				}
				_restartArmedUntil = -1f;
				_restartAscent = GameApi.CurrentAscent;
				_restartPending = true;
				ShowMessage(T("Restarting the run...", "Relance de la partie..."));
				Log.LogInfo((object)$"Restart requested (ascent {_restartAscent}).");
				if (!GameApi.ReturnToAirport())
				{
					_restartPending = false;
					ShowMessage(T("Could not return to the Airport (see log).", "Échec du retour à l'aéroport (voir le log)."));
				}
			}
		}

		private IEnumerator AfterAirportLoaded()
		{
			float timeout = Time.unscaledTime + 60f;
			while (Time.unscaledTime < timeout && (GameApi.IsLoading || GameApi.FindKiosk() == (Object)null || !GameApi.LocalCharacterReady))
			{
				yield return null;
			}
			yield return (object)new WaitForSecondsRealtime(1f);
			_restartPending = false;
			if (!GameApi.InAirport)
			{
				yield break;
			}
			if (_autoStartAfterRestart.Value && !GameApi.IsLoading)
			{
				Log.LogInfo((object)$"Auto start (ascent {_restartAscent}).");
				if (GameApi.StartGame(_restartAscent))
				{
					yield break;
				}
			}
			GameApi.OpenBoardingPass();
		}

		private void RefreshHud()
		{
			if (Time.unscaledTime < _hudNextRefresh)
			{
				return;
			}
			_hudNextRefresh = Time.unscaledTime + 0.2f;
			bool flag = _runActive && !GameApi.InAirport && !GameApi.IsLoading;
			bool num = (flag && !_hudSuppressed) || _menuOpen;
			string text = null;
			string text2 = null;
			string text3 = null;
			int num2;
			if (num && _showAltitude.Value)
			{
				if (flag)
				{
					float? altitudeMeters = GameApi.AltitudeMeters;
					if (altitudeMeters.HasValue)
					{
						float valueOrDefault = altitudeMeters.GetValueOrDefault();
						num2 = Mathf.RoundToInt(valueOrDefault);
						goto IL_0090;
					}
				}
				num2 = 1234;
				goto IL_0090;
			}
			goto IL_00ba;
			IL_00ba:
			if (num && _showAscent.Value)
			{
				string text4 = GameApi.AscentLabel();
				text2 = T("Ascent: " + text4, "Difficulté : " + text4);
			}
			if (num && _showTimer.Value)
			{
				string text5 = FormatTime(flag ? (Time.unscaledTime - _runStart) : 0f);
				text3 = T("Time: " + text5, "Temps : " + text5);
			}
			_hudTexts[0] = text;
			_hudTexts[1] = text2;
			_hudTexts[2] = text3;
			_hud.SetTexts(_hudTexts);
			return;
			IL_0090:
			int num3 = num2;
			text = T($"Altitude: {num3} m", $"Altitude : {num3} m");
			goto IL_00ba;
		}

		private static string FormatTime(float seconds)
		{
			TimeSpan timeSpan = TimeSpan.FromSeconds(Math.Max(0f, seconds));
			if (!(timeSpan.TotalHours >= 1.0))
			{
				return $"{timeSpan.Minutes:00}:{timeSpan.Seconds:00}";
			}
			return $"{(int)timeSpan.TotalHours}:{timeSpan.Minutes:00}:{timeSpan.Seconds:00}";
		}

		private void SetMenuOpen(bool open)
		{
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			if (open != _menuOpen)
			{
				_menuOpen = open;
				_rebinding = null;
				_draggingMenu = false;
				_hudNextRefresh = 0f;
				if (open)
				{
					_fontScanAt = Time.unscaledTime;
					_fontScanForce = true;
					_fontScanTries = 0;
				}
				if (open)
				{
					_prevLock = Cursor.lockState;
					_prevVisible = Cursor.visible;
					_window = new Rect((float)(Screen.width - 500) / 2f, (float)(Screen.height - 700) / 2f, 500f, 700f);
				}
				else
				{
					Cursor.lockState = _prevLock;
					Cursor.visible = _prevVisible;
				}
			}
		}

		private void CaptureRebind()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Invalid comparison between Unknown and I4
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Invalid comparison between Unknown and I4
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Invalid comparison between Unknown and I4
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown((KeyCode)27))
			{
				_rebinding = null;
				_ignoreInputFrame = Time.frameCount;
				return;
			}
			KeyCode[] allKeys = AllKeys;
			foreach (KeyCode val in allKeys)
			{
				if ((int)val != 0 && (int)val != 323 && (int)val != 324 && (int)val < 330 && Input.GetKeyDown(val))
				{
					_rebinding.Value = val;
					Log.LogInfo((object)$"Key '{((ConfigEntryBase)_rebinding).Definition.Key}' -> {val}");
					_rebinding = null;
					_ignoreInputFrame = Time.frameCount;
					break;
				}
			}
		}

		private void EnsureStyles()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_0034: Expected O, but got Unknown
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_0083: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Expected O, but got Unknown
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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_00ef: Expected O, but got Unknown
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Expected O, but got Unknown
			//IL_0126: 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_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Expected O, but got Unknown
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			if (_msgStyle == null)
			{
				_msgStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 22,
					alignment = (TextAnchor)4,
					fontStyle = (FontStyle)1
				};
				_titleStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 18,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)4
				};
				_sectionStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 15,
					fontStyle = (FontStyle)1
				};
				_sectionStyle.normal.textColor = new Color(1f, 0.82f, 0.4f);
				_labelStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 14,
					alignment = (TextAnchor)3
				};
				_keyStyle = new GUIStyle(GUI.skin.button)
				{
					fontSize = 14,
					fontStyle = (FontStyle)1
				};
				_warnStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 13
				};
				_warnStyle.normal.textColor = new Color(1f, 0.55f, 0.45f);
				_hintStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 13,
					wordWrap = true
				};
				_hintStyle.normal.textColor = new Color(0.8f, 0.85f, 0.9f);
			}
		}

		private void OnGUI()
		{
			//IL_0021: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_005d: 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)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: 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)
			EnsureStyles();
			_hud.OnGUI(_menuOpen && _rebinding == null, MenuArea);
			if (_menuOpen && !_ui.Ready)
			{
				_window = GUI.Window(85658237, _window, new WindowFunction(DrawWindow), "");
			}
			if (_message != null && Time.unscaledTime <= _messageUntil && (!HiddenAll || _menuOpen))
			{
				Rect val = default(Rect);
				((Rect)(ref val))..ctor(0f, (float)Screen.height * 0.15f, (float)Screen.width, 40f);
				_msgStyle.normal.textColor = Color.black;
				GUI.Label(new Rect(((Rect)(ref val)).x + 2f, ((Rect)(ref val)).y + 2f, ((Rect)(ref val)).width, ((Rect)(ref val)).height), _message, _msgStyle);
				_msgStyle.normal.textColor = Color.white;
				GUI.Label(val, _message, _msgStyle);
			}
		}

		private void DrawWindow(int id)
		{
			//IL_050d: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.Label("PEAK Quick Board  v1.8.0", _titleStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Space(6f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(T("Language", "Langue"), _labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(300f) });
			if (GUILayout.Button((_language.Value == Language.English) ? "English" : "Français", _keyStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) }))
			{
				_language.Value = ((_language.Value == Language.English) ? Language.Francais : Language.English);
				_hudNextRefresh = 0f;
			}
			GUILayout.EndHorizontal();
			Section(T("Features", "Fonctions"));
			Toggle(_featBoard, T("Boarding pass from anywhere", "Embarquement depuis n'importe où"));
			Toggle(_featInvite, T("Invite friends from anywhere", "Inviter des amis depuis n'importe où"));
			Toggle(_featRestart, T("Restart the run (host)", "Relancer la partie (hôte)"));
			Toggle(_featAutoHide, T("Hide the HUD during game menus and cutscenes", "Cacher l'affichage pendant les menus du jeu et les cinématiques"));
			Toggle(_featHideKey, T("Key to hide everything the mod displays", "Touche pour cacher tout l'affichage du mod"));
			Section(T("Keys", "Touches"));
			if (_featBoard.Value)
			{
				KeyRow(T("Open boarding pass (Airport)", "Ouvrir l'embarquement (aéroport)"), _boardKey);
			}
			if (_featInvite.Value)
			{
				KeyRow(T("Invite friends (Airport)", "Inviter des amis (aéroport)"), _inviteKey);
			}
			if (_featRestart.Value)
			{
				KeyRow(T("Restart run (press twice, host)", "Relancer la partie (2 appuis, hôte)"), _restartKey);
			}
			if (_featHideKey.Value)
			{
				KeyRow(T("Hide / show the mod's display", "Cacher / afficher le mod"), _hideKey);
			}
			KeyRow(T("Open this menu", "Ouvrir ce menu"), _menuKey, canUnbind: false);
			Section(T("Restart & boarding", "Relance et embarquement"));
			Toggle(_autoStartAfterRestart, T("After a restart, take off right away", "Après une relance, redécoller directement"));
			Toggle(_rememberAscent, T("Remember the last ascent played", "Retenir la dernière difficulté jouée"));
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(T($"Confirm delay: {_confirmWindow.Value:0.0} s", $"Délai de confirmation : {_confirmWindow.Value:0.0} s"), _labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(230f) });
			float num = Mathf.Round(GUILayout.HorizontalSlider(_confirmWindow.Value, 1f, 10f, Array.Empty<GUILayoutOption>()) * 2f) / 2f;
			if (!Mathf.Approximately(num, _confirmWindow.Value))
			{
				_confirmWindow.Value = num;
			}
			GUILayout.EndHorizontal();
			Section(T("In-run HUD", "Affichage en partie"));
			Toggle(_showAltitude, T("Altitude", "Altitude"));
			Toggle(_showAscent, T("Ascent", "Difficulté"));
			Toggle(_showTimer, T("Run timer", "Chrono de la partie"));
			GUILayout.Label(T("Drag the elements on screen to move them. Near another element, the edges or the center, they snap. Elements snapped together move together; Shift + drag pulls one out.", "Fais glisser les éléments à l'écran pour les déplacer. Près d'un autre élément, des bords ou du centre, ils s'aimantent. Les éléments collés bougent ensemble ; Shift + glisser en décolle un."), _hintStyle, Array.Empty<GUILayoutOption>());
			if (GUILayout.Button(T("Reset layout", "Réinitialiser la disposition"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) }))
			{
				_hud.ResetLayout();
			}
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(T("Font", "Police"), _labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(120f) });
			if (GUILayout.Button(FontLabel(), _keyStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) }))
			{
				NextFont();
			}
			GUILayout.EndHorizontal();
			GUILayout.FlexibleSpace();
			GUILayout.Label((_rebinding != null) ? T("Press a key... (Esc to cancel)", "Appuie sur une touche... (Échap pour annuler)") : T("Click a key to change it.", "Clique sur une touche pour la changer."), _labelStyle, Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button(T("Reset", "Réinitialiser"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
			{
				ResetAll();
			}
			if (GUILayout.Button(T("Close", "Fermer"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
			{
				SetMenuOpen(open: false);
			}
			GUILayout.EndHorizontal();
			GUI.DragWindow(new Rect(0f, 0f, 10000f, 30f));
		}

		private void Section(string title)
		{
			GUILayout.Space(10f);
			GUILayout.Label(title, _sectionStyle, Array.Empty<GUILayoutOption>());
		}

		private void Toggle(ConfigEntry<bool> entry, string label)
		{
			bool flag = GUILayout.Toggle(entry.Value, "  " + label, Array.Empty<GUILayoutOption>());
			if (flag != entry.Value)
			{
				entry.Value = flag;
			}
		}

		private void KeyRow(string label, ConfigEntry<KeyCode> entry, bool canUnbind = true)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Invalid comparison between Unknown and I4
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(label, _labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(270f) });
			if (GUILayout.Button((_rebinding == entry) ? "..." : KeyName(entry.Value), _keyStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) }))
			{
				_rebinding = entry;
			}
			GUI.enabled = canUnbind && (int)entry.Value > 0;
			if (GUILayout.Button("X", _keyStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(32f),
				GUILayout.Height(26f)
			}))
			{
				entry.Value = (KeyCode)0;
				if (_rebinding == entry)
				{
					_rebinding = null;
				}
			}
			GUI.enabled = true;
			GUILayout.EndHorizontal();
			string text = FindConflict(entry);
			if (text != null)
			{
				GUILayout.Label(T("   (!) Also used by: " + text, "   (!) Déjà utilisée par : " + text), _warnStyle, Array.Empty<GUILayoutOption>());
			}
		}

		private string FindConflict(ConfigEntry<KeyCode> entry)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			if ((int)entry.Value == 0 || !KeyInUse(entry))
			{
				return null;
			}
			ConfigEntry<KeyCode>[] array = new ConfigEntry<KeyCode>[5] { _boardKey, _inviteKey, _restartKey, _hideKey, _menuKey };
			foreach (ConfigEntry<KeyCode> val in array)
			{
				if (val != entry && KeyInUse(val) && val.Value == entry.Value)
				{
					return T("another key of this mod", "une autre touche de ce mod");
				}
			}
			foreach (KeyValuePair<string, ConfigEntry<KeyCode>> item in ForeignKeys())
			{
				if (item.Value.Value == entry.Value)
				{
					return item.Key;
				}
			}
			return null;
		}

		private bool KeyInUse(ConfigEntry<KeyCode> key)
		{
			if (key != _boardKey)
			{
				if (key != _inviteKey)
				{
					if (key != _restartKey)
					{
						if (key != _hideKey)
						{
							return true;
						}
						return _featHideKey.Value;
					}
					return _featRestart.Value;
				}
				return _featInvite.Value;
			}
			return _featBoard.Value;
		}

		private bool HudSuppressed()
		{
			if (_menuOpen)
			{
				return false;
			}
			if (HiddenAll)
			{
				return true;
			}
			if (_featAutoHide.Value)
			{
				if (!GameApi.GameWindowOpen)
				{
					return GameApi.InCutscene;
				}
				return true;
			}
			return false;
		}

		private List<KeyValuePair<string, ConfigEntry<KeyCode>>> ForeignKeys()
		{
			if (_foreignKeys != null)
			{
				return _foreignKeys;
			}
			_foreignKeys = new List<KeyValuePair<string, ConfigEntry<KeyCode>>>();
			try
			{
				if (Chainloader.PluginInfos.TryGetValue("OnlyCook.PEAKQuickResume", out var value) && (Object)(object)value.Instance != (Object)null)
				{
					foreach (ConfigDefinition key in value.Instance.Config.Keys)
					{
						if (value.Instance.Config[key] is ConfigEntry<KeyCode> value2)
						{
							_foreignKeys.Add(new KeyValuePair<string, ConfigEntry<KeyCode>>("PEAK Quick Resume (" + key.Key + ")", value2));
						}
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Could not read other mods' keys: " + ex.Message));
			}
			return _foreignKeys;
		}

		private void ResetAll()
		{
			_rebinding = null;
			ConfigEntryBase[] array = (ConfigEntryBase[])(object)new ConfigEntryBase[18]
			{
				(ConfigEntryBase)_featBoard,
				(ConfigEntryBase)_featInvite,
				(ConfigEntryBase)_featRestart,
				(ConfigEntryBase)_featAutoHide,
				(ConfigEntryBase)_featHideKey,
				(ConfigEntryBase)_hiddenAll,
				(ConfigEntryBase)_boardKey,
				(ConfigEntryBase)_inviteKey,
				(ConfigEntryBase)_restartKey,
				(ConfigEntryBase)_hideKey,
				(ConfigEntryBase)_menuKey,
				(ConfigEntryBase)_autoStartAfterRestart,
				(ConfigEntryBase)_rememberAscent,
				(ConfigEntryBase)_confirmWindow,
				(ConfigEntryBase)_showAltitude,
				(ConfigEntryBase)_showAscent,
				(ConfigEntryBase)_showTimer,
				(ConfigEntryBase)_hudFont
			};
			foreach (ConfigEntryBase obj in array)
			{
				obj.BoxedValue = obj.DefaultValue;
			}
			_hud.ResetLayout();
		}

		private string FontLabel()
		{
			if (_hud.Fonts.Count == 0)
			{
				return T("Default (no game font found)", "Par défaut (aucune police du jeu trouvée)");
			}
			if (string.IsNullOrEmpty(_hudFont.Value))
			{
				return "Auto (" + _hud.AutoFontName + ")";
			}
			return _hudFont.Value;
		}

		private void NextFont()
		{
			IReadOnlyList<Object> fonts = _hud.Fonts;
			if (fonts.Count == 0)
			{
				return;
			}
			int num = -1;
			for (int i = 0; i < fonts.Count; i++)
			{
				if (fonts[i] != (Object)null && fonts[i].name == _hudFont.Value)
				{
					num = i;
				}
			}
			_hudFont.Value = ((num + 1 < fonts.Count) ? fonts[num + 1].name : "");
		}

		private unsafe static string KeyName(KeyCode k)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected I4, but got Unknown
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			if ((int)k <= 13)
			{
				if ((int)k == 0)
				{
					return T("None", "Aucune");
				}
				if ((int)k == 13)
				{
					return T("Enter", "Entrée");
				}
			}
			else
			{
				if ((int)k == 32)
				{
					return T("Space", "Espace");
				}
				switch (k - 325)
				{
				case 0:
					return T("Middle click", "Clic molette");
				case 1:
					return T("Mouse 4", "Souris 4");
				case 2:
					return T("Mouse 5", "Souris 5");
				}
			}
			return ((object)(*(KeyCode*)(&k))/*cast due to .constrained prefix*/).ToString();
		}

		private void ShowMessage(string text, float seconds = 2.5f)
		{
			_message = text;
			_messageUntil = Time.unscaledTime + seconds;
		}

		private void DrawMenu()
		{
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: 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_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: 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_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0370: 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_0377: Unknown result type (might be due to invalid IL or missing references)
			//IL_037c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0393: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_039e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0469: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0502: Unknown result type (might be due to invalid IL or missing references)
			//IL_050c: Unknown result type (might be due to invalid IL or missing references)
			//IL_056e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0573: Unknown result type (might be due to invalid IL or missing references)
			//IL_0590: Unknown result type (might be due to invalid IL or missing references)
			//IL_0516: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ce: Unknown result type (might be due to invalid IL or missing references)
			UiKit ui = _ui;
			float s = ui.S;
			ui.SetFont(_hud.CurrentFont);
			float num = Mathf.Round(640f * s);
			float num2 = Mathf.Min(Mathf.Round(760f * s), (float)Screen.height - 20f);
			float num3 = Mathf.Round(26f * s);
			Vector2 val = (Vector2)(((??)_menuPos) ?? new Vector2(((float)Screen.width - num) / 2f, ((float)Screen.height - num2) / 2f));
			val.x = Mathf.Clamp(val.x, 0f, Mathf.Max(0f, (float)Screen.width - num));
			val.y = Mathf.Clamp(val.y, 0f, Mathf.Max(0f, (float)Screen.height - num2));
			Rect val2 = default(Rect);
			((Rect)(ref val2))..ctor(val.x, val.y, num, num2);
			_menuRect = val2;
			ui.Begin();
			ui.Box(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), UiKit.Dim, ring: false, plain: true);
			ui.Box(new Rect(((Rect)(ref val2)).x + 6f * s, ((Rect)(ref val2)).y + 9f * s, num, num2), new Color(0f, 0f, 0f, 0.28f));
			ui.Box(val2, UiKit.Paper);
			Rect r = default(Rect);
			((Rect)(ref r))..ctor(((Rect)(ref val2)).x, ((Rect)(ref val2)).y, num, Mathf.Round(66f * s));
			ui.Box(r, UiKit.Wood);
			ui.Box(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).center.y, num, ((Rect)(ref r)).height / 2f), UiKit.Wood, ring: false, plain: true);
			ui.Box(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).yMax - 3f * s, num, 3f * s), UiKit.WoodDark, ring: false, plain: true);
			ui.Box(val2, UiKit.WoodDark, ring: true);
			ui.Text(new Rect(((Rect)(ref r)).x + num3, ((Rect)(ref r)).y, num - 2f * num3, ((Rect)(ref r)).height), "PEAK Quick Board", 30f * s, UiKit.Cream);
			Rect r2 = default(Rect);
			((Rect)(ref r2))..ctor(((Rect)(ref r)).xMax - num3 - 38f * s, ((Rect)(ref r)).y + (((Rect)(ref r)).height - 38f * s) / 2f, 38f * s, 38f * s);
			Vector2 val3 = ui.Measure("v1.8.0", 17f * s);
			ui.Text(new Rect(((Rect)(ref r2)).x - val3.x - 14f * s, ((Rect)(ref r)).y, val3.x + 2f, ((Rect)(ref r)).height), "v1.8.0", 17f * s, new Color(1f, 0.93f, 0.8f, 0.75f), "Right");
			if (ui.Button(r2, "X", 20f * s))
			{
				SetMenuOpen(open: false);
				ui.End();
				return;
			}
			if (ui.Clicked(r))
			{
				_draggingMenu = true;
				_menuGrab = ui.Mouse - val;
			}
			if (_draggingMenu)
			{
				if (ui.Held)
				{
					_menuPos = ui.Mouse - _menuGrab;
				}
				else
				{
					_draggingMenu = false;
				}
			}
			string[] array = new string[4]
			{
				T("Features", "Fonctions"),
				T("Keys", "Touches"),
				T("Options", "Options"),
				T("Display", "Affichage")
			};
			float num4 = 8f * s;
			float num5 = (num - 2f * num3 - 3f * num4) / 4f;
			float num6 = Mathf.Round(42f * s);
			float num7 = ((Rect)(ref r)).yMax + 18f * s;
			for (int i = 0; i < array.Length; i++)
			{
				if (ui.Button(new Rect(((Rect)(ref val2)).x + num3 + (float)i * (num5 + num4), num7, num5, num6), array[i], 20f * s, _tab == i))
				{
					_tab = i;
					_rebinding = null;
				}
			}
			num7 += num6 + 22f * s;
			Rect c = default(Rect);
			((Rect)(ref c))..ctor(((Rect)(ref val2)).x + num3, num7, num - 2f * num3, 0f);
			switch (_tab)
			{
			case 0:
				DrawFeaturesTab(c);
				break;
			case 1:
				DrawKeysTab(c);
				break;
			case 2:
				DrawOptionsTab(c);
				break;
			default:
				DrawDisplayTab(c);
				break;
			}
			float num8 = Mathf.Round(44f * s);
			float num9 = Mathf.Round(200f * s);
			float num10 = ((Rect)(ref val2)).yMax - num3 - num8;
			ui.Box(new Rect(((Rect)(ref val2)).x + num3, num10 - 16f * s, num - 2f * num3, 2f * s), UiKit.PaperDark, ring: false, plain: true);
			if (ui.Button(new Rect(((Rect)(ref val2)).x + num3, num10, num9, num8), T("Reset all", "Tout réinitialiser"), 19f * s))
			{
				ResetAll();
			}
			if (ui.Button(new Rect(((Rect)(ref val2)).xMax - num3 - num9, num10, num9, num8), T("Close", "Fermer"), 19f * s))
			{
				SetMenuOpen(open: false);
				ui.End();
			}
			else
			{
				ui.End();
			}
		}

		private void DrawFeaturesTab(Rect c)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown