Decompiled source of GK2 AutoKeeper v0.4.1

plugins/AutoKeeper/AutoKeeper.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using AutoKeeper.Bot;
using AutoKeeper.Bot.Tasks;
using AutoKeeper.Config;
using AutoKeeper.Core;
using AutoKeeper.UI;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LazyBearTechnology;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Pathfinding;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[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("focabr")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.4.1.0")]
[assembly: AssemblyInformationalVersion("0.4.1+64d275b600e9f319fc23f37d4c280b4d5505438b")]
[assembly: AssemblyProduct("GK2 AutoKeeper")]
[assembly: AssemblyTitle("AutoKeeper")]
[assembly: AssemblyVersion("0.4.1.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 AutoKeeper
{
	[BepInPlugin("com.focabr.gk2.autokeeper", "GK2 AutoKeeper", "0.4.1")]
	[BepInProcess("GraveyardKeeper2.exe")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "com.focabr.gk2.autokeeper";

		public const string Name = "GK2 AutoKeeper";

		public const string Version = "0.4.1";

		public const string TestedGameVersion = "1.011";

		public const string MinGameVersion = "1.011";

		private Harmony harmony;

		private Overlay overlay;

		private SettingsWindow settingsWindow;

		private NativeSettingsWindow nativeWindow;

		private NativeStatusPanel nativePanel;

		private bool nativePanelGaveUp;

		private float nextPanelTry;

		private bool compatibilityChecked;

		private bool configDirty;

		private float configDirtySince;

		public static Plugin Instance { get; private set; }

		public Settings Settings { get; private set; }

		internal BotController Bot { get; private set; }

		public string BotStatusText
		{
			get
			{
				if (Bot != null)
				{
					if (!string.IsNullOrEmpty(Bot.StateDetail))
					{
						return $"{Bot.State} — {Bot.StateDetail}";
					}
					return Bot.State.ToString();
				}
				return "-";
			}
		}

		public bool IsBotOn
		{
			get
			{
				if (Bot != null)
				{
					return Bot.State != BotController.BotState.Off;
				}
				return false;
			}
		}

		private bool SettingsOpen
		{
			get
			{
				if (!((Object)(object)nativeWindow != (Object)null) || !((LazyWindow<LazyWidgetDataBase>)nativeWindow).IsShown)
				{
					if (settingsWindow != null)
					{
						return settingsWindow.IsOpen;
					}
					return false;
				}
				return true;
			}
		}

		private bool CapturingKey
		{
			get
			{
				if (!((Object)(object)nativeWindow != (Object)null) || !nativeWindow.IsCapturingKey)
				{
					if (settingsWindow != null)
					{
						return settingsWindow.IsCapturingKey;
					}
					return false;
				}
				return true;
			}
		}

		private bool NativePanelShown
		{
			get
			{
				if ((Object)(object)nativePanel != (Object)null)
				{
					return ((Component)nativePanel).gameObject.activeSelf;
				}
				return false;
			}
		}

		public static bool IsGameTooOld(string gameVersion)
		{
			if (gameVersion != null && System.Version.TryParse(gameVersion, out Version result) && System.Version.TryParse("1.011", out Version result2))
			{
				return result < result2;
			}
			return false;
		}

		public void ToggleBot()
		{
			Bot?.Toggle();
		}

		public void ToggleSettingsWindow()
		{
			if ((Object)(object)nativeWindow != (Object)null && ((LazyWindow<LazyWidgetDataBase>)nativeWindow).IsShown)
			{
				((LazyWindow<LazyWidgetDataBase>)nativeWindow).Close();
				return;
			}
			if (settingsWindow.IsOpen)
			{
				settingsWindow.Close();
				return;
			}
			if ((Object)(object)nativeWindow == (Object)null)
			{
				nativeWindow = NativeSettingsWindow.TryCreate(Settings, Bot, out var error);
				if ((Object)(object)nativeWindow == (Object)null)
				{
					ModLog.WarnOnce("native-ui", Lang.T("Tela nativa indisponível (" + error + "); usando a tela simples.", "Native settings window unavailable (" + error + "); using the simple window."));
				}
			}
			if ((Object)(object)nativeWindow != (Object)null)
			{
				try
				{
					((LazyWindow<LazyWidgetDataBase>)nativeWindow).Open((LazyWidgetDataBase)null);
					return;
				}
				catch (Exception arg)
				{
					ModLog.Error(Lang.T($"Falha ao abrir a tela nativa: {arg}", $"Failed to open the native settings window: {arg}"));
					Object.Destroy((Object)(object)((Component)nativeWindow).gameObject);
					nativeWindow = null;
				}
			}
			settingsWindow.Toggle();
		}

		private void Awake()
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			Instance = this;
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = false;
			Settings = new Settings(((BaseUnityPlugin)this).Config);
			((BaseUnityPlugin)this).Config.SettingChanged += delegate
			{
				configDirty = true;
				configDirtySince = Time.unscaledTime;
			};
			((BaseUnityPlugin)this).Config.Save();
			ModLog.Init(((BaseUnityPlugin)this).Logger, Settings);
			harmony = new Harmony("com.focabr.gk2.autokeeper");
			try
			{
				harmony.PatchAll(typeof(Plugin).Assembly);
				ModLog.Detail(Lang.T($"Patches Harmony aplicados: {harmony.GetPatchedMethods().CountSafe()}", $"Harmony patches applied: {harmony.GetPatchedMethods().CountSafe()}"));
			}
			catch (Exception arg)
			{
				ModLog.Error(Lang.T($"Falha ao aplicar patches Harmony — o bot ficará desativado. {arg}", $"Failed to apply Harmony patches — the bot will be disabled. {arg}"));
			}
			Bot = new BotController(Settings);
			GameApi.HookGameLifecycle();
			Bot.Register(new ProcessBodiesTask(Settings, Bot.Navigator));
			overlay = new Overlay(Settings, Bot);
			settingsWindow = new SettingsWindow(Settings, Bot);
			overlay.OnSettingsClicked = ToggleSettingsWindow;
			ModLog.Detail("GK2 AutoKeeper 0.4.1 loaded.");
		}

		private void Update()
		{
			CheckCompatibilityOnce();
			HandleHotkeys();
			Bot.Update(Time.unscaledDeltaTime);
			UpdateStatusPanel();
			SaveConfigIfDirty(!SettingsOpen);
		}

		private void UpdateStatusPanel()
		{
			bool flag = Settings.ShowOverlay.Value && Settings.OverlayGameLook.Value;
			if ((Object)(object)nativePanel == (Object)null)
			{
				if (flag && !nativePanelGaveUp && !(Time.unscaledTime < nextPanelTry) && GameApi.IsMainGameReady)
				{
					nextPanelTry = Time.unscaledTime + 2f;
					nativePanel = NativeStatusPanel.TryCreate(Settings, Bot, ToggleSettingsWindow, WriteDump, out var error, out var retry);
					if ((Object)(object)nativePanel == (Object)null && !retry)
					{
						nativePanelGaveUp = true;
						ModLog.WarnOnce("native-panel", Lang.T("Painel com visual do jogo indisponível (" + error + "); usando o painel simples.", "Game-styled panel unavailable (" + error + "); using the simple panel."));
					}
				}
			}
			else if (nativePanel.Failed)
			{
				Object.Destroy((Object)(object)((Component)nativePanel).gameObject);
				nativePanel = null;
				nativePanelGaveUp = true;
			}
			else if (((Component)nativePanel).gameObject.activeSelf != flag)
			{
				((Component)nativePanel).gameObject.SetActive(flag);
			}
		}

		private void OnGUI()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Invalid comparison between Unknown and I4
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			overlay.Suppressed = NativePanelShown;
			overlay.Draw();
			settingsWindow.Draw();
			if (Event.current == null || (int)Event.current.type != 7)
			{
				return;
			}
			Vector2 mousePosition = Event.current.mousePosition;
			Rect val = overlay.Rect;
			if (((Rect)(ref val)).Contains(mousePosition))
			{
				goto IL_00a3;
			}
			if (settingsWindow.IsOpen)
			{
				val = settingsWindow.Rect;
				if (((Rect)(ref val)).Contains(mousePosition))
				{
					goto IL_00a3;
				}
			}
			int num;
			if (NativePanelShown)
			{
				val = nativePanel.GuiRect;
				num = (((Rect)(ref val)).Contains(mousePosition) ? 1 : 0);
			}
			else
			{
				num = 0;
			}
			goto IL_00a4;
			IL_00a3:
			num = 1;
			goto IL_00a4;
			IL_00a4:
			bool mouseOverUi = (byte)num != 0;
			GameApi.SetModUiState(settingsWindow.IsOpen, mouseOverUi);
		}

		private void OnDestroy()
		{
			Bot?.Stop(Lang.T("plugin descarregado", "plugin unloaded"));
			GameApi.SetModUiState(windowOpen: false, mouseOverUi: false);
			SaveConfigIfDirty(force: true);
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}

		private void SaveConfigIfDirty(bool force)
		{
			if (!configDirty || (!force && !(Time.unscaledTime - configDirtySince > 1f)))
			{
				return;
			}
			configDirty = false;
			try
			{
				((BaseUnityPlugin)this).Config.Save();
			}
			catch (Exception ex)
			{
				ModLog.Warn(Lang.T("Não consegui salvar o .cfg: " + ex.Message, "Could not save the .cfg: " + ex.Message));
			}
		}

		private void CheckCompatibilityOnce()
		{
			//IL_003f: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
			if (!compatibilityChecked && GameApi.IsMainGameReady)
			{
				compatibilityChecked = true;
				ModLog.Detail(Lang.T(string.Format("{0} {1} carregado. {2} = bot, {3} = configurações, {4} = painel.", "GK2 AutoKeeper", "0.4.1", Settings.ToggleBotKey.Value, Settings.OpenSettingsKey.Value, Settings.ToggleOverlayKey.Value), string.Format("{0} {1} loaded. {2} = bot, {3} = settings, {4} = status panel.", "GK2 AutoKeeper", "0.4.1", Settings.ToggleBotKey.Value, Settings.OpenSettingsKey.Value, Settings.ToggleOverlayKey.Value)));
				string gameVersion = GameApi.GetGameVersion();
				if (gameVersion == null)
				{
					ModLog.Warn(Lang.T("Não consegui ler a versão do jogo (GameInfo). O mod pode estar desatualizado.", "Could not read the game version (GameInfo). The mod may be outdated."));
				}
				else if (IsGameTooOld(gameVersion))
				{
					ModLog.Warn(Lang.T("Versão do jogo " + gameVersion + " é antiga: esta versão do mod exige o jogo 1.011 ou mais novo (as extrações da autópsia vão falhar). Atualize o jogo ou use o mod 0.3.44.", "Game version " + gameVersion + " is too old: this mod version needs game 1.011 or newer (autopsy extractions will fail). Update the game or use mod 0.3.44."));
				}
				else if (gameVersion != "1.011")
				{
					ModLog.Warn(Lang.T("Versão do jogo " + gameVersion + " difere da testada (1.011). Se algo falhar, desligue o bot (F8) e verifique atualizações do mod.", "Game version " + gameVersion + " differs from the tested one (1.011). If something fails, turn off the bot (F8) and check for mod updates."));
				}
				else
				{
					ModLog.Detail(Lang.T("Versão do jogo " + gameVersion + " — compatível (testada).", "Game version " + gameVersion + " — compatible (tested)."));
				}
			}
		}

		private void HandleHotkeys()
		{
			try
			{
				HandleHotkeysUnsafe();
			}
			catch (Exception ex)
			{
				ModLog.WarnOnce("hotkeys", Lang.T("Hotkeys indisponíveis (" + ex.GetType().Name + ": " + ex.Message + ").", "Hotkeys unavailable (" + ex.GetType().Name + ": " + ex.Message + ")."));
			}
		}

		private void HandleHotkeysUnsafe()
		{
			//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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			if (!CapturingKey)
			{
				KeyboardShortcut value = Settings.OpenSettingsKey.Value;
				if (((KeyboardShortcut)(ref value)).IsDown())
				{
					ToggleSettingsWindow();
				}
				value = Settings.ToggleBotKey.Value;
				if (((KeyboardShortcut)(ref value)).IsDown())
				{
					Bot.Toggle();
				}
				value = Settings.ToggleOverlayKey.Value;
				if (((KeyboardShortcut)(ref value)).IsDown())
				{
					Settings.ShowOverlay.Value = !Settings.ShowOverlay.Value;
				}
				value = Settings.DumpKey.Value;
				if (((KeyboardShortcut)(ref value)).IsDown())
				{
					WriteDump();
				}
			}
		}

		private void WriteDump()
		{
			string text = GameApi.WriteDiscoveryDump();
			if (text != null)
			{
				ModLog.Detail(Lang.T("Dump de descoberta salvo em: " + text, "Discovery dump saved to: " + text));
				ModLog.Info(Lang.T("Dump salvo: " + Path.GetFileName(text) + " (BepInEx/config/AutoKeeper/dumps)", "Dump saved: " + Path.GetFileName(text) + " (BepInEx/config/AutoKeeper/dumps)"));
			}
		}
	}
	internal static class EnumerableExtensions
	{
		public static int CountSafe<T>(this IEnumerable<T> source)
		{
			if (source == null)
			{
				return 0;
			}
			int num = 0;
			foreach (T item in source)
			{
				_ = item;
				num++;
			}
			return num;
		}
	}
}
namespace AutoKeeper.UI
{
	internal static class GameUiTheme
	{
		public static readonly Color PanelBackground = new Color(0.055f, 0.035f, 0.03f, 0.9f);

		public static readonly Color PanelInner = new Color(0.105f, 0.112f, 0.14f, 0.96f);

		public static readonly Color Border = new Color(0.42f, 0.29f, 0.19f, 1f);

		public static readonly Color Row = new Color(0.16f, 0.1f, 0.08f, 0.85f);

		public static readonly Color Button = new Color(0.28f, 0.12f, 0.07f, 1f);

		public static readonly Color ButtonHover = new Color(0.42f, 0.2f, 0.1f, 1f);

		public static readonly Color ButtonActive = new Color(0.55f, 0.36f, 0.12f, 1f);

		public static readonly Color Label = new Color(0.59f, 0.55f, 0.53f, 1f);

		public static readonly Color Value = new Color(1f, 0.74f, 0f, 1f);

		public static readonly Color Title = new Color(0.95f, 0.89f, 0.78f, 1f);

		public const string LabelHex = "#978C87";

		public const string ValueHex = "#FFBD00";

		public const string TitleHex = "#F2E3C7";

		public const string GoodHex = "#A6D05A";

		public const string BadHex = "#E07A5F";

		public const string MutedHex = "#7D726D";

		private static Font font;

		private static bool fontSearched;

		public static Font Font
		{
			get
			{
				if (!fontSearched)
				{
					fontSearched = true;
					font = FindGameFont();
				}
				return font;
			}
		}

		public static void ResetFontCache()
		{
			if ((Object)(object)font == (Object)null)
			{
				fontSearched = false;
			}
		}

		private static Font FindGameFont()
		{
			try
			{
				TMP_FontAsset[] source = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
				TMP_FontAsset val = ((IEnumerable<TMP_FontAsset>)source).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => (Object)(object)f != (Object)null && (Object)(object)f.sourceFontFile != (Object)null && ((Object)f).name.IndexOf("small_font", StringComparison.OrdinalIgnoreCase) >= 0 && ((Object)f).name.IndexOf("bold", StringComparison.OrdinalIgnoreCase) < 0)) ?? ((IEnumerable<TMP_FontAsset>)source).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => (Object)(object)f != (Object)null && (Object)(object)f.sourceFontFile != (Object)null && ((Object)f).name.IndexOf("bold", StringComparison.OrdinalIgnoreCase) < 0)) ?? ((IEnumerable<TMP_FontAsset>)source).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => (Object)(object)f != (Object)null && (Object)(object)f.sourceFontFile != (Object)null));
				if ((Object)(object)val != (Object)null)
				{
					ModLog.Debug(Lang.T("Fonte do jogo para a UI do mod: " + ((Object)val).name + " (" + ((Object)val.sourceFontFile).name + ")", "Game font for the mod UI: " + ((Object)val).name + " (" + ((Object)val.sourceFontFile).name + ")"));
					return val.sourceFontFile;
				}
			}
			catch (Exception ex)
			{
				ModLog.Debug(Lang.T("Fonte do jogo indisponível: " + ex.Message, "Game font unavailable: " + ex.Message));
			}
			return null;
		}

		public static Texture2D MakeTex(Color c)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			Texture2D val = new Texture2D(1, 1)
			{
				hideFlags = (HideFlags)61
			};
			val.SetPixel(0, 0, c);
			val.Apply();
			return val;
		}

		public static void DrawFramedBox(Rect r, Texture2D fill, Texture2D border)
		{
			//IL_0000: 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)
			GUI.DrawTexture(r, (Texture)(object)border);
			GUI.DrawTexture(new Rect(((Rect)(ref r)).x + 2f, ((Rect)(ref r)).y + 2f, ((Rect)(ref r)).width - 4f, ((Rect)(ref r)).height - 4f), (Texture)(object)fill);
		}
	}
	internal sealed class NativeSettingsWindow : LazyWindow<LazyWidgetDataBase>
	{
		private static readonly FieldInfo SwitchAmountField = AccessTools.Field(typeof(UISwitchButton), "amountLabel");

		private static readonly FieldInfo SwitchIncField = AccessTools.Field(typeof(UISwitchButton), "increaseButton");

		private static readonly FieldInfo SwitchDecField = AccessTools.Field(typeof(UISwitchButton), "decreaseButton");

		private static readonly FieldInfo SwitchHeaderField = AccessTools.Field(typeof(UISwitchButton), "headerLabel");

		private static readonly FieldInfo SliderField = AccessTools.Field(typeof(UISlider), "slider");

		private static readonly FieldInfo SliderIncField = AccessTools.Field(typeof(UISlider), "increaseButton");

		private static readonly FieldInfo SliderDecField = AccessTools.Field(typeof(UISlider), "decreaseButton");

		private static readonly FieldInfo SliderAmountField = AccessTools.Field(typeof(UISlider), "amountLabel");

		private static KeyCode[] keyboardKeys;

		private Settings settings;

		private BotController bot;

		private Transform staging;

		private GameObject switchTemplate;

		private GameObject sliderTemplate;

		private GameObject buttonTemplate;

		private RectTransform content;

		private TextMeshProUGUI titleText;

		private TextMeshProUGUI hintText;

		private TextMeshProUGUI hintStyleSource;

		private bool hintMaterialRefreshLogged;

		private UIDialogWindowButton botButton;

		private readonly List<GameObject> built = new List<GameObject>();

		private SettingTab tab = SettingTab.Bodies;

		private SettingInfo capturing;

		private int captureEndFrame = -1;

		private bool rebuildPending;

		private bool lastBotOn;

		private bool pt;

		public bool IsCapturingKey
		{
			get
			{
				if (capturing == null)
				{
					return Time.frameCount == captureEndFrame;
				}
				return true;
			}
		}

		internal static NativeSettingsWindow TryCreate(Settings settings, BotController bot, out string error)
		{
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Expected O, but got Unknown
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Expected O, but got Unknown
			//IL_01f8: Expected O, but got Unknown
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Expected O, but got Unknown
			GameObject val = null;
			try
			{
				UIGameSettingsWindow window = LazyUI.GetWindow<UIGameSettingsWindow>();
				if ((Object)(object)window == (Object)null)
				{
					error = Lang.T("janela de configurações do jogo indisponível", "game settings window unavailable");
					return null;
				}
				Transform val2 = ((Component)window).transform.Find("GenericWIndowLayout");
				object? obj = AccessTools.Field(typeof(UIGameSettingsWindow), "fullscreenButton")?.GetValue(window);
				UISwitchButton val3 = (UISwitchButton)((obj is UISwitchButton) ? obj : null);
				object? obj2 = AccessTools.Field(typeof(UIGameSettingsWindow), "masterVolumeSlider")?.GetValue(window);
				UISlider val4 = (UISlider)((obj2 is UISlider) ? obj2 : null);
				object? obj3 = AccessTools.Field(typeof(UIGameSettingsWindow), "lazyButton")?.GetValue(window);
				UIDialogWindowButton val5 = (UIDialogWindowButton)((obj3 is UIDialogWindowButton) ? obj3 : null);
				if ((Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null || (Object)(object)val4 == (Object)null || (Object)(object)val5 == (Object)null || SwitchAmountField == null || SliderField == null || SliderAmountField == null)
				{
					error = Lang.T($"peças não encontradas (layout={(Object)(object)val2 != (Object)null}, switch={(Object)(object)val3 != (Object)null}, slider={(Object)(object)val4 != (Object)null}, button={(Object)(object)val5 != (Object)null})", $"parts not found (layout={(Object)(object)val2 != (Object)null}, switch={(Object)(object)val3 != (Object)null}, slider={(Object)(object)val4 != (Object)null}, button={(Object)(object)val5 != (Object)null})");
					return null;
				}
				val = new GameObject("AutoKeeperSettingsWindow", new Type[1] { typeof(RectTransform) });
				val.transform.SetParent(FindUiRoot((Component)(object)window), false);
				CopyRect((RectTransform)((Component)window).transform, (RectTransform)val.transform);
				Canvas obj4 = val.AddComponent<Canvas>();
				obj4.overrideSorting = true;
				obj4.sortingOrder = 460;
				val.AddComponent<GraphicRaycaster>();
				GamepadNavigationController obj5 = val.AddComponent<GamepadNavigationController>();
				obj5.navigationGroupSources = new List<NavigationGroupSource>();
				obj5.useGridSkippedIfListEmpty = true;
				GameObject val6 = new GameObject("AK_Templates", new Type[1] { typeof(RectTransform) });
				val6.transform.SetParent(val.transform, false);
				val6.SetActive(false);
				NativeSettingsWindow nativeSettingsWindow = val.AddComponent<NativeSettingsWindow>();
				nativeSettingsWindow.settings = settings;
				nativeSettingsWindow.bot = bot;
				nativeSettingsWindow.staging = val6.transform;
				nativeSettingsWindow.switchTemplate = CloneInactive(((Component)val3).gameObject, nativeSettingsWindow.staging);
				nativeSettingsWindow.sliderTemplate = CloneInactive(((Component)val4).gameObject, nativeSettingsWindow.staging);
				nativeSettingsWindow.buttonTemplate = CloneInactive(((Component)val5).gameObject, nativeSettingsWindow.staging);
				nativeSettingsWindow.BuildChrome(((Component)val2).gameObject);
				((LazyWidgetBase)nativeSettingsWindow).Init();
				error = null;
				ModLog.Detail(Lang.T("Tela de configurações nativa criada (visual da janela de Configurações do jogo).", "Native settings window created (look of the game's Settings window)."));
				ModLog.Detail(Lang.T("UI nativa: ", "Native UI: ") + nativeSettingsWindow.Describe());
				return nativeSettingsWindow;
			}
			catch (Exception ex)
			{
				error = ex.GetType().Name + ": " + ex.Message;
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
				return null;
			}
		}

		internal static Transform FindUiRoot(Component sourceWindow)
		{
			GUIElements instance = GUIElements.Instance;
			Component val = (Component)(((Object)(object)instance == (Object)null) ? null : /*isinst with value type is only supported in some contexts*/);
			if (!((Object)(object)val != (Object)null))
			{
				return sourceWindow.transform.parent;
			}
			return val.transform;
		}

		internal static GameObject CloneInactive(GameObject template, Transform inactiveParent)
		{
			GameObject val = Object.Instantiate<GameObject>(template, inactiveParent, false);
			((Object)val).name = ((Object)template).name + "_AK";
			LocalizedLabel[] componentsInChildren = val.GetComponentsInChildren<LocalizedLabel>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
			}
			return val;
		}

		private static void CopyRect(RectTransform from, RectTransform to)
		{
			//IL_0002: 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_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			to.anchorMin = from.anchorMin;
			to.anchorMax = from.anchorMax;
			to.pivot = from.pivot;
			to.anchoredPosition = from.anchoredPosition;
			to.sizeDelta = from.sizeDelta;
			((Transform)to).localScale = Vector3.one;
		}

		private void BuildChrome(GameObject srcLayout)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			GameObject val = CloneInactive(srcLayout, staging);
			Transform val2 = val.transform.Find("Content");
			if ((Object)(object)val2 == (Object)null)
			{
				throw new InvalidOperationException(Lang.T("Content não encontrado na janela do jogo", "Content not found in the game's window"));
			}
			for (int num = val2.childCount - 1; num >= 0; num--)
			{
				Object.DestroyImmediate((Object)(object)((Component)val2.GetChild(num)).gameObject);
			}
			content = (RectTransform)val2;
			if ((Object)(object)((Component)content).GetComponent<LayoutGroup>() == (Object)null)
			{
				VerticalLayoutGroup obj = ((Component)content).gameObject.AddComponent<VerticalLayoutGroup>();
				((HorizontalOrVerticalLayoutGroup)obj).spacing = 4f;
				((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = true;
				((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = true;
				((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = false;
				((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false;
			}
			Transform val3 = val.transform.Find("Frame/HeaderGroup/Header");
			titleText = (((Object)(object)val3 != (Object)null) ? ((Component)val3).GetComponent<TextMeshProUGUI>() : null);
			LazyButton[] componentsInChildren = val.GetComponentsInChildren<LazyButton>(true);
			foreach (LazyButton obj2 in componentsInChildren)
			{
				((UnityEventBase)((Button)obj2).onClick).RemoveAllListeners();
				((UnityEvent)((Button)obj2).onClick).AddListener(new UnityAction(((LazyWindow<LazyWidgetDataBase>)this).Close));
			}
			val.transform.SetParent(((Component)this).transform, false);
		}

		private string Describe()
		{
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			LayoutGroup val = (((Object)(object)content != (Object)null) ? ((Component)content).GetComponent<LayoutGroup>() : null);
			string arg = string.Join(",", (from t in ((IEnumerable)((Component)this).transform).Cast<Transform>().SelectMany((Transform t) => ((IEnumerable)t).Cast<Transform>())
				select ((Object)t).name).Take(12));
			string[] obj = new string[12]
			{
				"content=", null, null, null, null, null, null, null, null, null,
				null, null
			};
			object obj2;
			if (!((Object)(object)content != (Object)null))
			{
				obj2 = "-";
			}
			else
			{
				Rect rect = content.rect;
				Vector2 size = ((Rect)(ref rect)).size;
				obj2 = ((Vector2)(ref size)).ToString("0");
			}
			obj[1] = (string)obj2;
			obj[2] = " layout=";
			obj[3] = (((Object)(object)val != (Object)null) ? ((object)val).GetType().Name : "-");
			obj[4] = " switch=";
			obj[5] = Size(switchTemplate);
			obj[6] = " slider=";
			obj[7] = Size(sliderTemplate);
			obj[8] = " button=";
			obj[9] = Size(buttonTemplate);
			obj[10] = " ";
			obj[11] = string.Format("title={0} {1}=[{2}]", (Object)(object)titleText != (Object)null, Lang.T("partes", "parts"), arg);
			return string.Concat(obj);
			static string Size(GameObject g)
			{
				//IL_000f: 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_0019: 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_0021: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)g == (Object)null))
				{
					Rect rect2 = ((RectTransform)g.transform).rect;
					Vector2 size2 = ((Rect)(ref rect2)).size;
					return ((Vector2)(ref size2)).ToString("0");
				}
				return "-";
			}
		}

		public override void Redraw()
		{
			((LazyWidget<LazyWidgetDataBase>)(object)this).Redraw();
			BuildContent();
		}

		protected override void TestDraw()
		{
		}

		protected override bool OnPressedBack()
		{
			if (capturing != null)
			{
				capturing = null;
				captureEndFrame = Time.frameCount;
				rebuildPending = true;
				return true;
			}
			((LazyWindow<LazyWidgetDataBase>)this).Close();
			return true;
		}

		protected override void PrintTips()
		{
			if ((Object)(object)base.lazyButtonTips != (Object)null)
			{
				base.PrintTips();
			}
		}

		public override void Close()
		{
			capturing = null;
			base.Close();
		}

		protected override void Update()
		{
			base.Update();
			HandleKeyCapture();
			bool flag = bot.State != BotController.BotState.Off;
			if (flag != lastBotOn && (Object)(object)botButton != (Object)null)
			{
				lastBotOn = flag;
				DrawButton(botButton, BotButtonText(), bot.Toggle);
			}
			if (rebuildPending)
			{
				rebuildPending = false;
				BuildContent();
			}
			SyncHintStyle(hintText);
		}

		private void BuildContent()
		{
			//IL_0322: 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_032b: Unknown result type (might be due to invalid IL or missing references)
			pt = GameApi.IsGameLanguagePortuguese();
			foreach (GameObject item in built)
			{
				if ((Object)(object)item != (Object)null)
				{
					Object.Destroy((Object)(object)item);
				}
			}
			built.Clear();
			if ((Object)(object)titleText != (Object)null)
			{
				((TMP_Text)titleText).text = "GK2 AutoKeeper 0.4.1";
			}
			SettingTab[] tabs = (SettingTab[])Enum.GetValues(typeof(SettingTab));
			UISwitchButton val = AddSwitch("", tabs.Select(TabName).ToArray(), Array.IndexOf(tabs, tab), delegate(int i)
			{
				tab = tabs[i];
				rebuildPending = true;
			}, T("Categoria: escolha o grupo de opções.", "Category: choose the group of options."));
			hintStyleSource = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponentsInChildren<TextMeshProUGUI>(true).FirstOrDefault() : null);
			AddDivider();
			foreach (SettingInfo item2 in from x in settings.UiSettings
				where x.Tab == tab
				orderby x.Order
				select x)
			{
				AddSettingRow(item2);
			}
			hintText = AddHint();
			AddDivider();
			lastBotOn = bot.State != BotController.BotState.Off;
			botButton = AddButton(BotButtonText(), bot.Toggle, T("Liga ou desliga o bot agora (o mesmo que a tecla F8).", "Turns the bot on or off now (same as the F8 key)."));
			FixWidth(botButton, 308f);
			AddButtonRow((T("Restaurar padrões", "Reset defaults"), delegate
			{
				settings.ResetTab(tab);
				rebuildPending = true;
			}, T("Volta só as opções desta categoria ao valor original.", "Resets only this category's options to their original values.")), (T("Fechar", "Close"), (Action)((LazyWindow<LazyWidgetDataBase>)this).Close, T("Fecha a janela (Esc). As alterações já ficam salvas.", "Closes the window (Esc). Changes are already saved.")));
			LayoutRebuilder.ForceRebuildLayoutImmediate(content);
			CenterSwitch(val);
			if ((Object)(object)hintText != (Object)null)
			{
				TextMeshProUGUI val2 = switchTemplate.GetComponentsInChildren<TextMeshProUGUI>(true).FirstOrDefault();
				string[] obj = new string[6]
				{
					"font=",
					Name((Object)(object)((TMP_Text)hintText).font),
					" material=",
					Name((Object)(object)((TMP_Text)hintText).fontSharedMaterial),
					" ",
					null
				};
				string arg = Name((Object)(object)(((Object)(object)val2 != (Object)null) ? ((TMP_Text)val2).fontSharedMaterial : null));
				Rect rect = ((TMP_Text)hintText).rectTransform.rect;
				obj[5] = $"template={arg} rect={((Rect)(ref rect)).size}";
				string text = string.Concat(obj);
				ModLog.Debug(Lang.T("Caixa de descrição da F11: " + text, "F11 description box: " + text));
			}
			static string Name(Object o)
			{
				if (!(o == (Object)null))
				{
					return o.name;
				}
				return "-";
			}
		}

		private static void CenterSwitch(UISwitchButton sw)
		{
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: 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_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				object? obj = SwitchIncField?.GetValue(sw);
				object? obj2 = ((obj is Component) ? obj : null);
				Transform obj3 = ((obj2 != null) ? ((Component)obj2).transform : null);
				RectTransform val = (RectTransform)(object)((obj3 is RectTransform) ? obj3 : null);
				object? obj4 = SwitchDecField?.GetValue(sw);
				object? obj5 = ((obj4 is Component) ? obj4 : null);
				Transform obj6 = ((obj5 != null) ? ((Component)obj5).transform : null);
				RectTransform val2 = (RectTransform)(object)((obj6 is RectTransform) ? obj6 : null);
				object? obj7 = SwitchAmountField?.GetValue(sw);
				object? obj8 = ((obj7 is TextMeshProUGUI) ? obj7 : null);
				RectTransform val3 = ((obj8 != null) ? ((TMP_Text)obj8).rectTransform : null);
				object? obj9 = SwitchHeaderField?.GetValue(sw);
				TextMeshProUGUI val4 = (TextMeshProUGUI)((obj9 is TextMeshProUGUI) ? obj9 : null);
				Transform transform = ((Component)sw).transform;
				RectTransform val5 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
				if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null || (Object)(object)val5 == (Object)null)
				{
					return;
				}
				if ((Object)(object)val4 != (Object)null)
				{
					((TMP_Text)val4).text = "";
				}
				RectTransform obj10;
				if ((Object)(object)((Transform)val3).parent != (Object)null && (Object)(object)((Transform)val3).parent != (Object)(object)val5)
				{
					Transform parent = ((Transform)val3).parent;
					RectTransform val6 = (RectTransform)(object)((parent is RectTransform) ? parent : null);
					if (val6 != null && (Object)(object)((Transform)val6).parent == (Object)(object)((Transform)val).parent)
					{
						obj10 = val6;
						goto IL_0120;
					}
				}
				obj10 = val3;
				goto IL_0120;
				IL_0120:
				RectTransform val7 = obj10;
				RectTransform[] array = (RectTransform[])(object)new RectTransform[3] { val, val2, val7 };
				Vector3[] array2 = (Vector3[])(object)new Vector3[4];
				bool flag = true;
				Bounds val8 = default(Bounds);
				RectTransform[] array3 = array;
				for (int i = 0; i < array3.Length; i++)
				{
					array3[i].GetWorldCorners(array2);
					Vector3[] array4 = array2;
					foreach (Vector3 val9 in array4)
					{
						Vector3 val10 = ((Transform)val5).InverseTransformPoint(val9);
						if (flag)
						{
							((Bounds)(ref val8))..ctor(val10, Vector3.zero);
							flag = false;
						}
						else
						{
							((Bounds)(ref val8)).Encapsulate(val10);
						}
					}
				}
				Rect rect = val5.rect;
				float num = ((Rect)(ref rect)).center.x - ((Bounds)(ref val8)).center.x;
				if (!(Mathf.Abs(num) < 0.5f))
				{
					array3 = array;
					foreach (RectTransform obj11 in array3)
					{
						obj11.anchoredPosition += new Vector2(num, 0f);
					}
				}
			}
			catch (Exception ex)
			{
				ModLog.Debug(Lang.T("Não consegui centralizar a categoria: " + ex.Message, "Could not center the category: " + ex.Message));
			}
		}

		private void AddSettingRow(SettingInfo s)
		{
			ConfigEntryBase entry = s.Entry;
			Type settingType = entry.SettingType;
			string label = s.Label(pt);
			string text = s.Help(pt);
			if (settingType == typeof(bool))
			{
				ConfigEntry<bool> e = (ConfigEntry<bool>)(object)entry;
				AddSwitch(label, new string[2]
				{
					T("Não", "No"),
					T("Sim", "Yes")
				}, e.Value ? 1 : 0, delegate(int i)
				{
					e.Value = i == 1;
				}, text);
			}
			else if (settingType.IsEnum)
			{
				Array values = Settings.VisibleValues(settingType);
				string[] fields = values.Cast<object>().Select(EnumText).ToArray();
				AddSwitch(label, fields, Array.IndexOf(values, entry.BoxedValue), delegate(int i)
				{
					entry.BoxedValue = values.GetValue(i);
				}, text);
			}
			else if (settingType == typeof(float))
			{
				ConfigEntry<float> e2 = (ConfigEntry<float>)(object)entry;
				AddSlider(label, s, e2.Value, delegate(float v)
				{
					e2.Value = (float)Math.Round(v, 3);
				}, text);
			}
			else if (settingType == typeof(int))
			{
				ConfigEntry<int> e3 = (ConfigEntry<int>)(object)entry;
				AddSlider(label, s, e3.Value, delegate(float v)
				{
					e3.Value = Mathf.RoundToInt(v);
				}, text);
			}
			else if (settingType == typeof(KeyboardShortcut))
			{
				ConfigEntry<KeyboardShortcut> e4 = (ConfigEntry<KeyboardShortcut>)(object)entry;
				UIDialogWindowButton b = null;
				b = AddButton(KeyText(s, e4), delegate
				{
					capturing = s;
					DrawButton(b, label + ": " + T("aperte a nova tecla… (Esc cancela)", "press the new key… (Esc cancels)"), null);
				}, text + " " + T("Clique e aperte a nova tecla.", "Click, then press the new key."));
				FixWidth(b, 270f);
			}
			else if (settingType == typeof(string))
			{
				ConfigEntry<string> val = (ConfigEntry<string>)(object)entry;
				string text2 = (string.IsNullOrEmpty(val.Value) ? T("(automático)", "(automatic)") : val.Value);
				AddSwitch(label, new string[1] { text2 }, 0, null, text + " " + T("(editável no .cfg)", "(editable in the .cfg)")).IsInteractable = false;
			}
		}

		private UISwitchButton AddSwitch(string label, string[] fields, int index, Action<int> onChanged, string help)
		{
			GameObject val = Object.Instantiate<GameObject>(switchTemplate, staging, false);
			UISwitchButton component = val.GetComponent<UISwitchButton>();
			component.Initialize((Action<int>)delegate(int i)
			{
				onChanged?.Invoke(i);
			}, fields, Mathf.Max(0, index), label, (GameKey[])null, (GameKey[])null, true);
			object header = (object)/*isinst with value type is only supported in some contexts*/;
			object? value = SwitchAmountField.GetValue(component);
			SetHeader(val, (TextMeshProUGUI)header, (TextMeshProUGUI)((value is TextMeshProUGUI) ? value : null), label);
			Place(val, help);
			return component;
		}

		private void AddSlider(string label, SettingInfo s, float current, Action<float> onChanged, string help)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Expected O, but got Unknown
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Expected O, but got Unknown
			GameObject val = Object.Instantiate<GameObject>(sliderTemplate, staging, false);
			UISlider component = val.GetComponent<UISlider>();
			Slider slider = (Slider)SliderField.GetValue(component);
			object? obj = SliderIncField?.GetValue(component);
			Button val2 = (Button)((obj is Button) ? obj : null);
			object? obj2 = SliderDecField?.GetValue(component);
			object? obj3 = ((obj2 is Button) ? obj2 : null);
			TextMeshProUGUI amount = (TextMeshProUGUI)SliderAmountField.GetValue(component);
			Object.DestroyImmediate((Object)(object)component);
			float step = ((s.Step > 0f) ? s.Step : 1f);
			int num = Mathf.Max(1, Mathf.RoundToInt((s.Max - s.Min) / step));
			((UnityEventBase)slider.onValueChanged).RemoveAllListeners();
			slider.minValue = 0f;
			slider.maxValue = num;
			slider.wholeNumbers = true;
			slider.SetValueWithoutNotify(Mathf.Clamp(Mathf.Round((current - s.Min) / step), 0f, (float)num));
			((TMP_Text)amount).text = FormatNumber(current, step);
			((UnityEvent<float>)(object)slider.onValueChanged).AddListener((UnityAction<float>)delegate(float x)
			{
				float num2 = Mathf.Clamp(s.Min + x * step, s.Min, s.Max);
				((TMP_Text)amount).text = FormatNumber(num2, step);
				onChanged(num2);
			});
			if (val2 != null)
			{
				((UnityEvent)val2.onClick).AddListener((UnityAction)delegate
				{
					slider.value = Mathf.Min(slider.maxValue, slider.value + 1f);
				});
			}
			if (obj3 != null)
			{
				((UnityEvent)((Button)obj3).onClick).AddListener((UnityAction)delegate
				{
					slider.value = Mathf.Max(slider.minValue, slider.value - 1f);
				});
			}
			SetHeader(val, null, amount, label);
			Place(val, help);
		}

		private void AddButtonRow(params (string text, Action onPressed, string help)[] items)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: 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_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: 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_014e: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("AK_ButtonRow", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent((Transform)(object)content, false);
			((RectTransform)val.transform).sizeDelta = new Vector2(308f, 26f);
			LayoutElement obj = val.AddComponent<LayoutElement>();
			obj.minHeight = 26f;
			obj.preferredHeight = 26f;
			built.Add(val);
			Vector2 val4 = default(Vector2);
			for (int i = 0; i < items.Length; i++)
			{
				(string text, Action onPressed, string help) tuple = items[i];
				string item = tuple.text;
				Action item2 = tuple.onPressed;
				string item3 = tuple.help;
				GameObject val2 = Object.Instantiate<GameObject>(buttonTemplate, staging, false);
				UIDialogWindowButton component = val2.GetComponent<UIDialogWindowButton>();
				Place(val2, item3, val.transform);
				ContentSizeFitter component2 = val2.GetComponent<ContentSizeFitter>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.horizontalFit = (FitMode)0;
					component2.verticalFit = (FitMode)0;
				}
				RectTransform val3 = (RectTransform)val2.transform;
				((Vector2)(ref val4))..ctor(0.5f, 0.5f);
				val3.pivot = val4;
				Vector2 anchorMin = (val3.anchorMax = val4);
				val3.anchorMin = anchorMin;
				val3.sizeDelta = new Vector2(150f, 26f);
				val3.anchoredPosition = new Vector2(((float)i - (float)(items.Length - 1) / 2f) * 158f, 0f);
				DrawButton(component, item, item2);
			}
		}

		private static void FixWidth(UIDialogWindowButton b, float width)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)b == (Object)null))
			{
				ContentSizeFitter component = ((Component)b).GetComponent<ContentSizeFitter>();
				if ((Object)(object)component != (Object)null)
				{
					component.horizontalFit = (FitMode)0;
				}
				RectTransform val = (RectTransform)((Component)b).transform;
				val.sizeDelta = new Vector2(width, val.sizeDelta.y);
				LayoutElement obj = ((Component)b).GetComponent<LayoutElement>() ?? ((Component)b).gameObject.AddComponent<LayoutElement>();
				obj.minWidth = width;
				obj.preferredWidth = width;
			}
		}

		private UIDialogWindowButton AddButton(string text, Action onPressed, string help)
		{
			GameObject val = Object.Instantiate<GameObject>(buttonTemplate, staging, false);
			UIDialogWindowButton component = val.GetComponent<UIDialogWindowButton>();
			Place(val, help);
			DrawButton(component, text, onPressed);
			return component;
		}

		private static void DrawButton(UIDialogWindowButton b, string text, Action onPressed)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			if (!((Object)(object)b == (Object)null))
			{
				b.Draw(new ButtonData(onPressed, text, (Func<bool>)null, false, GameKey.None, text));
			}
		}

		private void AddDivider()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: 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_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: 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_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("AK_Divider", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent((Transform)(object)content, false);
			((RectTransform)val.transform).sizeDelta = new Vector2(310f, 14f);
			LayoutElement obj = val.AddComponent<LayoutElement>();
			obj.minHeight = 14f;
			obj.preferredHeight = 14f;
			obj.minWidth = 310f;
			obj.preferredWidth = 310f;
			GameObject val2 = new GameObject("Line", new Type[1] { typeof(RectTransform) });
			val2.transform.SetParent(val.transform, false);
			Image obj2 = val2.AddComponent<Image>();
			((Graphic)obj2).color = new Color(0.72f, 0.55f, 0.24f, 0.85f);
			((Graphic)obj2).raycastTarget = false;
			RectTransform val3 = (RectTransform)val2.transform;
			val3.anchorMin = new Vector2(0f, 0.5f);
			val3.anchorMax = new Vector2(1f, 0.5f);
			val3.pivot = new Vector2(0.5f, 0.5f);
			val3.anchoredPosition = Vector2.zero;
			val3.sizeDelta = new Vector2(0f, 1.5f);
			built.Add(val);
		}

		private TextMeshProUGUI AddHint()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val = switchTemplate.GetComponentsInChildren<TextMeshProUGUI>(true).FirstOrDefault();
			GameObject val2 = new GameObject("AK_Hint", new Type[1] { typeof(RectTransform) });
			val2.transform.SetParent((Transform)(object)content, false);
			TextMeshProUGUI val3 = val2.AddComponent<TextMeshProUGUI>();
			if ((Object)(object)val != (Object)null)
			{
				((TMP_Text)val3).font = ((TMP_Text)val).font;
				((TMP_Text)val3).fontSharedMaterial = ((TMP_Text)val).fontSharedMaterial;
				((TMP_Text)val3).fontSize = Mathf.Max(12f, ((TMP_Text)val).fontSize * 0.8f);
				((Graphic)val3).color = new Color(0.8f, 0.74f, 0.62f, 1f);
			}
			((TMP_Text)val3).alignment = (TextAlignmentOptions)514;
			((TMP_Text)val3).textWrappingMode = (TextWrappingModes)1;
			((TMP_Text)val3).enableAutoSizing = true;
			((TMP_Text)val3).fontSizeMax = ((TMP_Text)val3).fontSize;
			((TMP_Text)val3).fontSizeMin = Mathf.Max(8f, ((TMP_Text)val3).fontSize * 0.65f);
			((TMP_Text)val3).overflowMode = (TextOverflowModes)1;
			((Graphic)val3).raycastTarget = false;
			((TMP_Text)val3).text = T("Passe o mouse sobre uma opção para ver o que ela faz.", "Hover an option to see what it does.");
			LayoutElement val4 = val2.AddComponent<LayoutElement>();
			val4.minHeight = ((TMP_Text)val3).fontSize * 4.4f;
			val4.preferredHeight = ((TMP_Text)val3).fontSize * 4.4f;
			((RectTransform)val2.transform).sizeDelta = new Vector2(310f, val4.preferredHeight);
			SyncHintStyle(val3);
			built.Add(val2);
			return val3;
		}

		private void SyncHintStyle(TextMeshProUGUI hint)
		{
			if ((Object)(object)hint == (Object)null)
			{
				return;
			}
			TextMeshProUGUI val = hintStyleSource;
			if ((Object)(object)val != (Object)null)
			{
				if ((Object)(object)((TMP_Text)val).font != (Object)null && (Object)(object)((TMP_Text)hint).font != (Object)(object)((TMP_Text)val).font)
				{
					((TMP_Text)hint).font = ((TMP_Text)val).font;
				}
				Material fontSharedMaterial = ((TMP_Text)val).fontSharedMaterial;
				if ((Object)(object)fontSharedMaterial != (Object)null && (Object)(object)((TMP_Text)hint).fontSharedMaterial != (Object)(object)fontSharedMaterial)
				{
					if ((Object)(object)((TMP_Text)hint).fontSharedMaterial == (Object)null && !hintMaterialRefreshLogged)
					{
						hintMaterialRefreshLogged = true;
						ModLog.Detail(Lang.T("Caixa de descrição da F11: o material do texto foi liberado pelo jogo; usando o atual.", "F11 description box: the text material was released by the game; using the current one."));
					}
					((TMP_Text)hint).fontSharedMaterial = fontSharedMaterial;
				}
			}
			if ((Object)(object)((TMP_Text)hint).fontSharedMaterial == (Object)null && (Object)(object)((TMP_Text)hint).font != (Object)null)
			{
				((TMP_Text)hint).fontSharedMaterial = ((TMP_Asset)((TMP_Text)hint).font).material;
			}
		}

		private void Place(GameObject go, string help, Transform parent = null)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			go.transform.SetParent((Transform)(((Object)(object)parent != (Object)null) ? ((object)parent) : ((object)content)), false);
			if (!string.IsNullOrEmpty(help))
			{
				EventTrigger obj = go.GetComponent<EventTrigger>() ?? go.AddComponent<EventTrigger>();
				Entry val = new Entry
				{
					eventID = (EventTriggerType)0
				};
				((UnityEvent<BaseEventData>)(object)val.callback).AddListener((UnityAction<BaseEventData>)delegate
				{
					if ((Object)(object)hintText != (Object)null)
					{
						((TMP_Text)hintText).text = help;
					}
				});
				obj.triggers.Add(val);
			}
			built.Add(go);
		}

		private static void SetHeader(GameObject row, TextMeshProUGUI header, TextMeshProUGUI amount, string label)
		{
			if ((Object)(object)header == (Object)null)
			{
				header = ((IEnumerable<TextMeshProUGUI>)row.GetComponentsInChildren<TextMeshProUGUI>(true)).FirstOrDefault((Func<TextMeshProUGUI, bool>)((TextMeshProUGUI t) => (Object)(object)t != (Object)(object)amount));
			}
			if ((Object)(object)header != (Object)null)
			{
				((TMP_Text)header).text = label;
			}
		}

		private void HandleKeyCapture()
		{
			//IL_006e: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Invalid comparison between Unknown and I4
			//IL_0101: 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)
			if (capturing == null || !Input.anyKeyDown)
			{
				return;
			}
			if (keyboardKeys == null)
			{
				keyboardKeys = ((KeyCode[])Enum.GetValues(typeof(KeyCode))).Where((KeyCode k) => (int)k != 0 && (int)k < 323 && !IsModifier(k)).Distinct().ToArray();
			}
			KeyCode[] array = keyboardKeys;
			foreach (KeyCode val in array)
			{
				if (!Input.GetKeyDown(val))
				{
					continue;
				}
				if ((int)val != 27)
				{
					List<KeyCode> list = new List<KeyCode>();
					if (Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305))
					{
						list.Add((KeyCode)306);
					}
					if (Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303))
					{
						list.Add((KeyCode)304);
					}
					if (Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307))
					{
						list.Add((KeyCode)308);
					}
					((ConfigEntry<KeyboardShortcut>)(object)capturing.Entry).Value = new KeyboardShortcut(val, list.ToArray());
				}
				capturing = null;
				captureEndFrame = Time.frameCount;
				rebuildPending = true;
				break;
			}
		}

		private static bool IsModifier(KeyCode k)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Invalid comparison between Unknown and I4
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Invalid comparison between Unknown and I4
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Invalid comparison between Unknown and I4
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Invalid comparison between Unknown and I4
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Invalid comparison between Unknown and I4
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Invalid comparison between Unknown and I4
			if ((int)k != 306 && (int)k != 305 && (int)k != 304 && (int)k != 303 && (int)k != 308 && (int)k != 307 && (int)k != 310 && (int)k != 309)
			{
				return (int)k == 313;
			}
			return true;
		}

		private string T(string ptText, string enText)
		{
			if (!pt)
			{
				return enText;
			}
			return ptText;
		}

		private string BotButtonText()
		{
			if (bot.State != BotController.BotState.Off)
			{
				return T("Desligar bot", "Stop bot");
			}
			return T("Ligar bot", "Start bot");
		}

		private unsafe string KeyText(SettingInfo s, ConfigEntry<KeyboardShortcut> e)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			string text = s.Label(pt);
			KeyboardShortcut value = e.Value;
			string text2;
			if ((int)((KeyboardShortcut)(ref value)).MainKey != 0)
			{
				value = e.Value;
				text2 = ((object)(*(KeyboardShortcut*)(&value))/*cast due to .constrained prefix*/).ToString();
			}
			else
			{
				text2 = T("nenhuma", "none");
			}
			return text + ": " + text2;
		}

		private string TabName(SettingTab t)
		{
			return t switch
			{
				SettingTab.Bot => T("Geral", "General"), 
				SettingTab.Bodies => T("Corpos", "Bodies"), 
				SettingTab.Autopsy => T("Extração", "Extraction"), 
				SettingTab.Hotkeys => T("Teclas", "Hotkeys"), 
				SettingTab.Overlay => T("Painel", "Panel"), 
				_ => T("Avançado", "Advanced"), 
			};
		}

		private string EnumText(object v)
		{
			if (v is BodyDestination)
			{
				switch ((BodyDestination)v)
				{
				case BodyDestination.Crematorium:
					return T("Crematório", "Crematorium");
				case BodyDestination.LeaveOnTable:
					return T("Deixar na mesa", "Leave on table");
				case BodyDestination.Grave:
					return T("Túmulo (experimental)", "Grave (experimental)");
				}
			}
			if (v is LackOfSleepAction)
			{
				switch ((LackOfSleepAction)v)
				{
				case LackOfSleepAction.Stop:
					return T("Desligar o bot", "Turn off the bot");
				case LackOfSleepAction.Sleep:
					return T("Dormir e continuar", "Sleep, then resume");
				case LackOfSleepAction.KeepWorking:
					return T("Continuar trabalhando", "Keep working");
				}
			}
			if (v is OverlayCorner)
			{
				switch ((OverlayCorner)v)
				{
				case OverlayCorner.TopLeft:
					return T("Superior esquerdo", "Top left");
				case OverlayCorner.TopRight:
					return T("Superior direito", "Top right");
				case OverlayCorner.BottomLeft:
					return T("Inferior esquerdo", "Bottom left");
				case OverlayCorner.BottomRight:
					return T("Inferior direito", "Bottom right");
				}
			}
			if (v is OverlaySize overlaySize)
			{
				if (overlaySize != OverlaySize.Large)
				{
					return T("Pequeno", "Small");
				}
				return T("Grande", "Large");
			}
			return v.ToString();
		}

		private static string FormatNumber(float v, float step)
		{
			if (!(step >= 1f))
			{
				return v.ToString("0.00");
			}
			return v.ToString("0");
		}
	}
	internal sealed class NativeStatusPanel : MonoBehaviour
	{
		private sealed class Section
		{
			public TextMeshProUGUI Header;

			public RectTransform Line;

			public TextMeshProUGUI Body;

			public bool Visible;
		}

		private const float RefreshSeconds = 0.25f;

		private const float WidthSmall = 460f;

		private const float WidthLarge = 320f;

		private const float Margin = 6f;

		private const float Gap = 3f;

		private static readonly FieldInfo SwitchHeaderField = AccessTools.Field(typeof(UISwitchButton), "headerLabel");

		private Settings settings;

		private BotController bot;

		private Action onSettings;

		private Action onDump;

		private RectTransform rootRt;

		private RectTransform headerRt;

		private Transform staging;

		private GameObject labelTemplate;

		private GameObject buttonTemplate;

		private TextMeshProUGUI title;

		private Section status;

		private Section session;

		private Section events;

		private readonly List<UIDialogWindowButton> buttons = new List<UIDialogWindowButton>();

		private readonly List<TextMeshProUGUI> texts = new List<TextMeshProUGUI>();

		private static float SidePad = 19f;

		private float bottomPad = 10f;

		private float topPad = 12f;

		private float nextRefresh;

		private bool layoutDirty = true;

		private bool lastPt;

		private bool lastBotOn;

		private bool buttonsDrawn;

		private OverlayCorner lastCorner = (OverlayCorner)(-1);

		private float panelWidth = 460f;

		private float lastScale = -1f;

		private Vector2 cornerOffset = new Vector2(6f, -6f);

		public Rect GuiRect { get; private set; }

		public bool Failed { get; private set; }

		internal static NativeStatusPanel TryCreate(Settings settings, BotController bot, Action onSettings, Action onDump, out string error, out bool retry)
		{
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Expected O, but got Unknown
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Expected O, but got Unknown
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Expected O, but got Unknown
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = null;
			retry = false;
			try
			{
				UIGameSettingsWindow window = LazyUI.GetWindow<UIGameSettingsWindow>();
				if ((Object)(object)window == (Object)null)
				{
					error = Lang.T("janela de configurações do jogo indisponível", "game settings window unavailable");
					retry = true;
					return null;
				}
				Transform val2 = ((Component)window).transform.Find("GenericWIndowLayout/Frame");
				object? obj = AccessTools.Field(typeof(UIGameSettingsWindow), "fullscreenButton")?.GetValue(window);
				UISwitchButton val3 = (UISwitchButton)((obj is UISwitchButton) ? obj : null);
				object? obj2 = AccessTools.Field(typeof(UIGameSettingsWindow), "lazyButton")?.GetValue(window);
				UIDialogWindowButton val4 = (UIDialogWindowButton)((obj2 is UIDialogWindowButton) ? obj2 : null);
				TextMeshProUGUI val5 = (TextMeshProUGUI)(((Object)(object)val3 != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
				if ((Object)(object)val2 == (Object)null || (Object)(object)val5 == (Object)null || (Object)(object)val4 == (Object)null)
				{
					error = Lang.T($"peças não encontradas (moldura={(Object)(object)val2 != (Object)null}, texto={(Object)(object)val5 != (Object)null}, botão={(Object)(object)val4 != (Object)null})", $"parts not found (frame={(Object)(object)val2 != (Object)null}, text={(Object)(object)val5 != (Object)null}, button={(Object)(object)val4 != (Object)null})");
					return null;
				}
				val = new GameObject("AutoKeeperStatusPanel", new Type[1] { typeof(RectTransform) });
				val.transform.SetParent(NativeSettingsWindow.FindUiRoot((Component)(object)window), false);
				Canvas obj3 = val.AddComponent<Canvas>();
				obj3.overrideSorting = true;
				obj3.sortingOrder = 300;
				val.AddComponent<GraphicRaycaster>();
				GameObject val6 = new GameObject("AK_Templates", new Type[1] { typeof(RectTransform) });
				val6.transform.SetParent(val.transform, false);
				val6.SetActive(false);
				NativeStatusPanel nativeStatusPanel = val.AddComponent<NativeStatusPanel>();
				nativeStatusPanel.settings = settings;
				nativeStatusPanel.bot = bot;
				nativeStatusPanel.onSettings = onSettings;
				nativeStatusPanel.onDump = onDump;
				nativeStatusPanel.rootRt = (RectTransform)val.transform;
				nativeStatusPanel.staging = val6.transform;
				nativeStatusPanel.labelTemplate = NativeSettingsWindow.CloneInactive(((Component)val5).gameObject, nativeStatusPanel.staging);
				nativeStatusPanel.buttonTemplate = NativeSettingsWindow.CloneInactive(((Component)val4).gameObject, nativeStatusPanel.staging);
				RectTransform obj4 = nativeStatusPanel.rootRt;
				RectTransform obj5 = nativeStatusPanel.rootRt;
				Vector2 val7 = (nativeStatusPanel.rootRt.pivot = new Vector2(0f, 1f));
				Vector2 anchorMin = (obj5.anchorMax = val7);
				obj4.anchorMin = anchorMin;
				nativeStatusPanel.rootRt.sizeDelta = new Vector2(460f, 200f);
				nativeStatusPanel.BuildFrame(((Component)val2).gameObject);
				nativeStatusPanel.BuildBody();
				nativeStatusPanel.MeasureChrome();
				error = null;
				ModLog.Detail(Lang.T("Painel de status com o visual do jogo criado: ", "Game-styled status panel created: ") + nativeStatusPanel.Describe(val2));
				return nativeStatusPanel;
			}
			catch (Exception ex)
			{
				error = ex.GetType().Name + ": " + ex.Message;
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
				return null;
			}
		}

		private void BuildFrame(GameObject srcFrame)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Invalid comparison between Unknown and I4
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Expected O, but got Unknown
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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_00ad: 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_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: 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_00f6: 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_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: 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_01a6: 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_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: 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_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: 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_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: 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_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			Image val = (((Object)(object)srcFrame.transform.parent != (Object)null) ? ((Component)srcFrame.transform.parent).GetComponent<Image>() : null);
			if ((Object)(object)val != (Object)null && (Object)(object)val.sprite != (Object)null && (int)val.type == 1 && val.sprite.border != Vector4.zero)
			{
				GameObject val2 = new GameObject("AK_Backdrop", new Type[1] { typeof(RectTransform) });
				val2.transform.SetParent((Transform)(object)rootRt, false);
				Image obj = val2.AddComponent<Image>();
				obj.sprite = val.sprite;
				obj.type = val.type;
				((Graphic)obj).color = ((Graphic)val).color;
				obj.pixelsPerUnitMultiplier = val.pixelsPerUnitMultiplier;
				((Graphic)obj).raycastTarget = true;
				RectTransform val3 = (RectTransform)val2.transform;
				val3.anchorMin = Vector2.zero;
				val3.anchorMax = Vector2.one;
				val3.offsetMin = Vector2.zero;
				val3.offsetMax = Vector2.zero;
			}
			GameObject val4 = NativeSettingsWindow.CloneInactive(srcFrame, staging);
			LazyButton[] componentsInChildren = val4.GetComponentsInChildren<LazyButton>(true);
			foreach (LazyButton obj2 in componentsInChildren)
			{
				((UnityEventBase)((Button)obj2).onClick).RemoveAllListeners();
				((UnityEvent)((Button)obj2).onClick).AddListener(new UnityAction(Hide));
			}
			ContentSizeFitter[] components = val4.GetComponents<ContentSizeFitter>();
			for (int i = 0; i < components.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)components[i]);
			}
			RectTransform val5 = (RectTransform)val4.transform;
			val4.transform.SetParent((Transform)(object)rootRt, false);
			val5.anchorMin = Vector2.zero;
			val5.anchorMax = Vector2.one;
			val5.pivot = new Vector2(0.5f, 0.5f);
			val5.offsetMin = Vector2.zero;
			val5.offsetMax = Vector2.zero;
			Transform obj3 = val4.transform.Find("BackMask");
			RectTransform val6 = (RectTransform)(object)((obj3 is RectTransform) ? obj3 : null);
			if ((Object)(object)val6 != (Object)null && val6.anchorMin == Vector2.zero && val6.anchorMax == Vector2.one)
			{
				SidePad = Mathf.Clamp(Mathf.Max(val6.offsetMin.x, 0f - val6.offsetMax.x) + 6f, 10f, 40f);
				bottomPad = Mathf.Clamp(val6.offsetMin.y + 4f, 8f, 40f);
			}
			Transform val7 = val4.transform.Find("HeaderGroup/Header");
			title = (((Object)(object)val7 != (Object)null) ? ((Component)val7).GetComponent<TextMeshProUGUI>() : null);
			ref RectTransform reference = ref headerRt;
			Transform obj4 = val4.transform.Find("HeaderGroup");
			reference = (RectTransform)(object)((obj4 is RectTransform) ? obj4 : null);
			if ((Object)(object)title != (Object)null)
			{
				((TMP_Text)title).text = "GK2 AutoKeeper 0.4.1";
			}
		}

		private void BuildBody()
		{
			status = AddSection();
			session = AddSection();
			events = AddSection();
			for (int i = 0; i < 4; i++)
			{
				GameObject val = Object.Instantiate<GameObject>(buttonTemplate, staging, false);
				((Object)val).name = "AK_PanelButton" + i;
				val.transform.SetParent((Transform)(object)rootRt, false);
				buttons.Add(val.GetComponent<UIDialogWindowButton>());
			}
		}

		private Section AddSection()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			Section section = new Section
			{
				Header = AddText("AK_SectionHeader"),
				Body = AddText("AK_SectionBody")
			};
			GameObject val = new GameObject("AK_Line", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent((Transform)(object)rootRt, false);
			Image obj = val.AddComponent<Image>();
			((Graphic)obj).color = new Color(0.72f, 0.55f, 0.24f, 0.85f);
			((Graphic)obj).raycastTarget = false;
			section.Line = (RectTransform)val.transform;
			((Component)section.Header).gameObject.SetActive(false);
			((Component)section.Line).gameObject.SetActive(false);
			((Component)section.Body).gameObject.SetActive(false);
			return section;
		}

		private TextMeshProUGUI AddText(string name)
		{
			GameObject val = Object.Instantiate<GameObject>(labelTemplate, staging, false);
			((Object)val).name = name;
			foreach (Transform item in ((IEnumerable)val.transform).Cast<Transform>().ToList())
			{
				Object.Destroy((Object)(object)((Component)item).gameObject);
			}
			LayoutElement[] components = val.GetComponents<LayoutElement>();
			for (int i = 0; i < components.Length; i++)
			{
				Object.Destroy((Object)(object)components[i]);
			}
			ContentSizeFitter[] components2 = val.GetComponents<ContentSizeFitter>();
			for (int i = 0; i < components2.Length; i++)
			{
				Object.Destroy((Object)(object)components2[i]);
			}
			val.transform.SetParent((Transform)(object)rootRt, false);
			TextMeshProUGUI component = val.GetComponent<TextMeshProUGUI>();
			((TMP_Text)component).richText = true;
			((Graphic)component).raycastTarget = false;
			((TMP_Text)component).text = "";
			ForceTextLayout(component);
			texts.Add(component);
			return component;
		}

		private static void ForceTextLayout(TextMeshProUGUI t)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Invalid comparison between Unknown and I4
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Invalid comparison between Unknown and I4
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			if ((int)((TMP_Text)t).horizontalAlignment != 1)
			{
				((TMP_Text)t).horizontalAlignment = (HorizontalAlignmentOptions)1;
			}
			if ((int)((TMP_Text)t).verticalAlignment != 256)
			{
				((TMP_Text)t).verticalAlignment = (VerticalAlignmentOptions)256;
			}
			if (((TMP_Text)t).margin != Vector4.zero)
			{
				((TMP_Text)t).margin = Vector4.zero;
			}
			if (((TMP_Text)t).enableAutoSizing)
			{
				((TMP_Text)t).enableAutoSizing = false;
			}
			if ((int)((TMP_Text)t).textWrappingMode != 1)
			{
				((TMP_Text)t).textWrappingMode = (TextWrappingModes)1;
			}
			if ((int)((TMP_Text)t).overflowMode != 0)
			{
				((TMP_Text)t).overflowMode = (TextOverflowModes)0;
			}
		}

		private void MeasureChrome()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			Canvas.ForceUpdateCanvases();
			if (!((Object)(object)headerRt == (Object)null))
			{
				Vector3[] array = (Vector3[])(object)new Vector3[4];
				headerRt.GetWorldCorners(array);
				float y = ((Transform)rootRt).InverseTransformPoint(array[0]).y;
				topPad = Mathf.Max(topPad, 0f - y + 6f);
			}
		}

		private void Update()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			if (Failed)
			{
				return;
			}
			try
			{
				UpdateUnsafe();
			}
			catch (Exception ex)
			{
				Failed = true;
				GuiRect = Rect.zero;
				ModLog.Warn(Lang.T("Painel com visual do jogo falhou (" + ex.GetType().Name + ": " + ex.Message + "); voltando ao painel simples.", "Game-styled panel failed (" + ex.GetType().Name + ": " + ex.Message + "); back to the simple panel."));
				ModLog.Detail(ex.ToString());
			}
		}

		private void UpdateUnsafe()
		{
			OverlayCorner value = settings.OverlayPosition.Value;
			if (value != lastCorner)
			{
				lastCorner = value;
				ApplyCorner(value);
			}
			ApplyScale();
			bool flag = GameApi.IsGameLanguagePortuguese();
			bool flag2 = bot.State != BotController.BotState.Off;
			if (!buttonsDrawn || flag != lastPt || flag2 != lastBotOn)
			{
				buttonsDrawn = true;
				lastPt = flag;
				lastBotOn = flag2;
				DrawButtons(flag, flag2);
			}
			if (Time.unscaledTime >= nextRefresh)
			{
				nextRefresh = Time.unscaledTime + 0.25f;
				Refresh(flag);
				KeepMaterials();
			}
			if (layoutDirty)
			{
				layoutDirty = false;
				Relayout();
			}
			UpdateGuiRect();
		}

		private void OnDisable()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			GuiRect = Rect.zero;
		}

		public void Hide()
		{
			settings.ShowOverlay.Value = false;
		}

		private void DrawButtons(bool pt, bool botOn)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
			string arg = ((!botOn) ? (pt ? "Ligar bot" : "Bot on") : (pt ? "Desligar bot" : "Bot off"));
			Draw(0, $"{arg} ({settings.ToggleBotKey.Value})", delegate
			{
				bot.Toggle();
			});
			Draw(1, string.Format("{0} ({1})", pt ? "Configurações" : "Settings", settings.OpenSettingsKey.Value), delegate
			{
				onSettings?.Invoke();
			});
			Draw(2, string.Format("{0} ({1})", pt ? "Diagnóstico" : "Diagnostic", settings.DumpKey.Value), delegate
			{
				onDump?.Invoke();
			});
			Draw(3, string.Format("{0} ({1})", pt ? "Fechar" : "Close", settings.ToggleOverlayKey.Value), Hide);
			layoutDirty = true;
		}

		private void Draw(int i, string text, Action onPressed)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			UIDialogWindowButton val = buttons[i];
			if ((Object)(object)val != (Object)null)
			{
				val.Draw(new ButtonData(onPressed, text, (Func<bool>)null, false, GameKey.None, text));
			}
		}

		private void Refresh(bool pt)
		{
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			foreach (TextMeshProUGUI text in texts)
			{
				ForceTextLayout(text);
			}
			StatusContent statusContent = StatusContent.Build(settings, bot, pt);
			if ((Object)(object)title != (Object)null)
			{
				SetText(title, statusContent.Title);
			}
			float num = 0f;
			List<(string, string, bool)> list = new List<(string, string, bool)> { ("Bot:", statusContent.State, false) };
			if (statusContent.Reason != null)
			{
				list.Add((pt ? "Motivo:" : "Reason:", statusContent.Reason, false));
			}
			list.AddRange(from r in statusContent.Rows
				where !r.Session
				select (Label: r.Label, Value: r.Value, Muted: r.Muted));
			foreach (var item in list)
			{
				num = Mathf.Max(num, ((TMP_Text)status.Body).GetPreferredValues(item.Item1).x);
			}
			int num2 = Mathf.CeilToInt(num + 4f);
			StringBuilder stringBuilder = new StringBuilder();
			foreach (var item2 in list)
			{
				if (stringBuilder.Length > 0)
				{
					stringBuilder.Append('\n');
				}
				string value = (item2.Item3 ? StatusContent.Color("#978C87", item2.Item2) : StatusContent.Color("#FFBD00", item2.Item2));
				stringBuilder.Append(StatusContent.Color("#978C87", item2.Item1)).Append("<indent=").Append(num2.ToString(CultureInfo.InvariantCulture))
					.Append('>')
					.Append(value)
					.Append("</indent>");
			}
			if (statusContent.Note != null)
			{
				stringBuilder.Append('\n').Append(statusContent.Note);
			}
			SetSection(status, pt ? "Estado" : "Status", stringBuilder.ToString());
			StatusContent.Pair? pair = statusContent.Rows.Where((StatusContent.Pair r) => r.Session).Select((Func<StatusContent.Pair, StatusContent.Pair?>)((StatusContent.Pair r) => r)).FirstOrDefault();
			SetSection(session, pt ? "Sessão" : "Session", pair.HasValue ? StatusContent.Color("#FFBD00", pair.Value.Value) : null);
			string body = null;
			if (statusContent.Events.Count > 0)
			{
				int clockCol = Mathf.CeilToInt(((TMP_Text)events.Body).GetPreferredValues("00:00").x + 6f);
				body = string.Join("\n", statusContent.Events.Select((StatusContent.EventLine e) => StatusContent.Color("#7D726D", e.Clock) + "<indent=" + clockCol.ToString(CultureInfo.InvariantCulture) + ">" + StatusContent.Color("#F2E3C7", e.Text) + "</indent>"));
			}
			SetSection(events, pt ? "Eventos" : "Events", body);
		}

		private void SetSection(Section s, string header, string body)
		{
			bool flag = !string.IsNullOrEmpty(body);
			if (flag != s.Visible)
			{
				s.Visible = flag;
				((Component)s.Header).gameObject.SetActive(flag);
				((Component)s.Line).gameObject.SetActive(flag);
				((Component)s.Body).gameObject.SetActive(flag);
				layoutDirty = true;
			}
			if (flag)
			{
				SetText(s.Header, StatusContent.Color("#FFBD00", header));
				SetText(s.Body, body);
			}
		}

		private void SetText(TextMeshProUGUI t, string text)
		{
			if (((TMP_Text)t).text != text)
			{
				((TMP_Text)t).text = text;
				layoutDirty = true;
			}
		}

		private void KeepMaterials()
		{
			foreach (TextMeshProUGUI item in texts.Append(title))
			{
				if ((Object)(object)item != (Object)null && (Object)(object)((TMP_Text)item).fontSharedMaterial == (Object)null && (Object)(object)((TMP_Text)item).font != (Object)null)
				{
					((TMP_Text)item).fontSharedMaterial = ((TMP_Asset)((TMP_Text)item).font).material;
				}
			}
		}

		private void Relayout()
		{
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			float num = panelWidth - SidePad * 2f;
			float num2 = topPad;
			Section[] array = new Section[3] { status, session, events };
			foreach (Section section in array)
			{
				if (section.Visible)
				{
					num2 = Place(section.Header, SidePad, num2, num) + 1f;
					Place(section.Line, SidePad, num2, num, 1.5f);
					num2 += 3f;
					num2 = Place(section.Body, SidePad, num2, num) + 6f;
				}
			}
			num2 = PlaceButtons(num2 + 3f, num);
			rootRt.sizeDelta = new Vector2(panelWidth, num2 + bottomPad);
		}

		private float PlaceButtons(float y, float inner)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			List<(RectTransform, float, float, float)> list = new List<(RectTransform, float, float, float)>();
			float num = 0f;
			foreach (UIDialogWindowButton button in buttons)
			{
				if (!((Object)(object)button == (Object)null))
				{
					RectTransform val = (RectTransform)((Component)button).transform;
					float inset;
					float height;
					float num2 = VisibleBounds(val, out inset, out height);
					if (list.Count > 0 && num + 6f + num2 > inner)
					{
						y = PlaceRow(list, num, y, inner);
						list.Clear();
						num = 0f;
					}
					num += ((list.Count > 0) ? 6f : 0f) + num2;
					list.Add((val, num2, inset, height));
				}
			}
			if (list.Count > 0)
			{
				y = PlaceRow(list, num, y, inner);
			}
			return y;
		}

		private static float PlaceRow(List<(RectTransform rt, float width, float inset, float height)> row, float rowWidth, float y, float inner)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			float num = SidePad + Mathf.Max(0f, (inner - rowWidth) / 2f);
			float num2 = 0f;
			foreach (var item in row)
			{
				var (val, _, _, _) = item;
				var (val2, _, _, _) = item;
				Vector2 val3 = (item.rt.pivot = new Vector2(0f, 1f));
				Vector2 anchorMin = (val2.anchorMax = val3);
				val.anchorMin = anchorMin;
				item.rt.anchoredPosition = new Vector2(num - item.inset, 0f - y);
				num += item.width + 6f;
				num2 = Mathf.Max(num2, item.height);
			}
			return y + num2 + 3f;
		}

		private static float VisibleBounds(RectTransform b, out float inset, out float height)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			LayoutRebuilder.ForceRebuildLayoutImmediate(b);
			float num = float.MaxValue;
			float num2 = float.MinValue;
			float num3 = float.MaxValue;
			float num4 = float.MinValue;
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			Graphic[] componentsInChildren = ((Component)b).GetComponentsInChildren<Graphic>(false);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].rectTransform.GetWorldCorners(array);
				Vector3 val = ((Transform)b).InverseTransformPoint(array[0]);
				Vector3 val2 = ((Transform)b).InverseTransformPoint(array[2]);
				num = Mathf.Min(num, val.x);
				num2 = Mathf.Max(num2, val2.x);
				num3 = Mathf.Min(num3, val.y);
				num4 = Mathf.Max(num4, val2.y);
			}
			Rect rect = b.rect;
			if (num > num2)
			{
				inset = 0f;
				height = ((Rect)(ref rect)).height;
				return ((Rect)(ref rect)).width;
			}
			inset = num - ((Rect)(ref rect)).xMin;
			height = Mathf.Max(((Rect)(ref rect)).height, num4 - num3);
			return num2 - num;
		}

		private static float Place(TextMeshProUGUI t, float x, float y, float width)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Ceil(((TMP_Text)t).GetPreferredValues(((TMP_Text)t).text, width, 0f).y);
			Place(((TMP_Text)t).rectTransform, x, y, width, num);
			return y + num;
		}

		private static void Place(RectTransform rt, float x, float y, float width, float height)
		{
			//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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 1f);
			rt.pivot = val;
			Vector2 anchorMin = (rt.anchorMax = val);
			rt.anchorMin = anchorMin;
			rt.anchoredPosition = new Vector2(x, 0f - y);
			rt.sizeDelta = new Vector2(width, height);
		}

		private void ApplyScale()
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			float num = ParentPixelsPerUnit();
			bool num2 = settings.OverlayScale.Value == OverlaySize.Large;
			float num3 = ((num2 || num <= 0f) ? 1f : (Mathf.Max(1f, Mathf.Floor(num / 2f)) / num));
			float num4 = (num2 ? 320f : 460f);
			if (Mathf.Abs(num3 - lastScale) > 0.001f || Math.Abs(num4 - panelWidth) > 0.01f)
			{
				lastScale = num3;
				panelWidth = num4;
				((Transform)rootRt).localScale = new Vector3(num3, num3, 1f);
				layoutDirty = true;
			}
		}

		private float ParentPixelsPerUnit()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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)
			Transform parent = ((Transform)rootRt).parent;
			if ((Object)(object)parent == (Object)null)
			{
				return 1f;
			}
			Canvas componentInParent = ((Component)parent).GetComponentInParent<Canvas>();
			Canvas val = (((Object)(object)componentInParent != (Object)null) ? componentInParent.rootCanvas : null);
			Camera obj = (((Object)(object)val != (Object)null && (int)val.renderMode != 0) ? val.worldCamera : null);
			Vector2 val2 = RectTransformUtility.WorldToScreenPoint(obj, parent.TransformPoint(Vector3.zero));
			Vector2 val3 = RectTransformUtility.WorldToScreenPoint(obj, parent.TransformPoint(new Vector3(100f, 0f, 0f))) - val2;
			return ((Vector2)(ref val3)).magnitude / 100f;
		}

		private void ApplyCorner(OverlayCorner corner)
		{
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			Vector2 val2 = default(Vector2);
			switch (corner)
			{
			case OverlayCorner.TopRight:
				((Vector2)(ref val))..ctor(1f, 1f);
				((Vector2)(ref val2))..ctor(-6f, -6f);
				break;
			case OverlayCorner.BottomLeft:
				((Vector2)(ref val))..ctor(0f, 0f);
				((Vector2)(ref val2))..ctor(6f, 6f);
				break;
			case OverlayCorner.BottomRight:
				((Vector2)(ref val))..ctor(1f, 0f);
				((Vector2)(ref val2))..ctor(-6f, 6f);
				break;
			default:
				((Vector2)(ref val))..ctor(0f, 1f);
				((Vector2)(ref val2))..ctor(6f, -6f);
				break;
			}
			RectTransform obj = rootRt;
			Vector2 anchorMin = (rootRt.anchorMax = val);
			obj.anchorMin = anchorMin;
			layoutDirty = true;
			cornerOffset = val2;
		}

		private void LateUpdate()
		{
			//IL_001d: 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_0032: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: 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)
			if (!Failed && !((Object)(object)rootRt == (Object)null))
			{
				Vector2 val = rootRt.sizeDelta * ((Transform)rootRt).localScale.x;
				Vector2 anchorMin = rootRt.anchorMin;
				Vector2 val2 = default(Vector2);
				((Vector2)(ref val2))..ctor(cornerOffset.x - ((anchorMin.x > 0.5f) ? val.x : 0f), cornerOffset.y + ((anchorMin.y < 0.5f) ? val.y : 0f));
				if (anchorMin.y > 0.5f)
				{
					val2.y = Mathf.Min(val2.y, BelowZoneLabel(val2.x, val.x, anchorMin.x));
				}
				rootRt.anchoredPosition = val2;
			}
		}

		private float BelowZoneLabel(float x, float width, float anchorX)
		{
			//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_0058: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			Rect zoneLabelRectSticky = GameApi.GetZoneLabelRectSticky();
			Transform parent = ((Transform)rootRt).parent;
			RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null);
			if (((Rect)(ref zoneLabelRectSticky)).width <= 0f || (Object)(object)val == (Object)null)
			{
				return float.PositiveInfinity;
			}
			Canvas componentInParent = ((Component)val).GetComponentInParent<Canvas>();
			Canvas val2 = (((Object)(object)componentInParent != (Object)null) ? componentInParent.rootCanvas : null);
			Camera val3 = (((Object)(object)val2 != (Object)null && (int)val2.renderMode != 0) ? val2.worldCamera : null);
			Vector2 val4 = default(Vector2);
			Vector2 val5 = default(Vector2);
			if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(val, new Vector2(((Rect)(ref zoneLabelRectSticky)).xMin, (float)Screen.height - ((Rect)(ref zoneLabelRectSticky)).yMax), val3, ref val4) || !RectTransformUtility.ScreenPointToLocalPointInRectangle(val, new Vector2(((Rect)(ref zoneLabelRectSticky)).xMax, (float)Screen.height - ((Rect)(ref zoneLabelRectSticky)).yMax), val3, ref val5))
			{
				return float.PositiveInfinity;
			}
			Rect rect = val.rect;
			float num = Mathf.Lerp(((Rect)(ref rect)).xMin, ((Rect)(ref rect)).xMax, anchorX) + x;
			if (val5.x <= num || val4.x >= num + width)
			{
				return float.PositiveInfinity;
			}
			return val4.y - ((Rect)(ref rect)).yMax - 6f;
		}

		private void UpdateGuiRect()
		{
			//IL_0024: 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_0054: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			Canvas componentInParent = ((Component)this).GetComponentInParent<Canvas>();
			Canvas val = (((Object)(object)componentInParent != (Object)null) ? componentInParent.rootCanvas : null);
			Camera obj = (((Object)(object)val != (Object)null && (int)val.renderMode != 0) ? val.worldCamera : null);
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			rootRt.GetWorldCorners(array);
			Vector2 val2 = RectTransformUtility.WorldToScreenPoint(obj, array[0]);
			Vector2 val3 = RectTransformUtility.WorldToScreenPoint(obj, array[2]);
			GuiRect = new Rect(val2.x, (float)Screen.height - val3.y, val3.x - val2.x, val3.y - val2.y);
		}

		private string Describe(Transform srcFrame)
		{
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			//IL_0132: 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_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_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or m