Decompiled source of Valkryn v1.2.2

plugins\Valkryn.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.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;
using ValheimModDev.Localization;
using ValheimModDev.QoL;
using ValheimModDev.QoL.Containers;
using ValheimModDev.QoL.Crafting;
using ValheimModDev.QoL.Loot;
using ValheimModDev.QoL.Patches;
using ValheimModDev.QoL.Portals;
using ValheimModDev.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Valkryn")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Valkryn")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("1.2.2")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.2.0")]
namespace ValheimModDev
{
	[BepInPlugin("com.mrkode.valkryn", "VALKRYN", "1.2.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class ValheimModDev : BaseUnityPlugin
	{
		public const string PluginGUID = "com.mrkode.valkryn";

		public const string PluginName = "VALKRYN";

		public const string PluginVersion = "1.2.2";

		public static CustomLocalization Localization = LocalizationManager.Instance.GetLocalization();

		private Harmony harmony;

		private bool playerFound;

		private void Awake()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			Logger.LogInfo((object)"=================================");
			Logger.LogInfo((object)"VALKRYN loaded!");
			Logger.LogInfo((object)"Version: 1.2.2");
			Logger.LogInfo((object)"=================================");
			ModLang.Initialize(((BaseUnityPlugin)this).Config);
			QoLConfig.Bind(((BaseUnityPlugin)this).Config);
			harmony = new Harmony("com.mrkode.valkryn");
			harmony.PatchAll();
		}

		private void Update()
		{
			ControlPanel.Tick();
			if (!ControlPanel.IsOpen)
			{
				RefuelService.Tick();
				SmartDeposit.Tick();
				if (ExtraConfig.IsGroundCollectionActive)
				{
					ItemCollector.Tick();
				}
			}
			PortalNetwork.Tick();
			if (!playerFound)
			{
				Player localPlayer = Player.m_localPlayer;
				if (!((Object)(object)localPlayer == (Object)null))
				{
					playerFound = true;
					Logger.LogInfo((object)("Player found: " + localPlayer.GetPlayerName()));
				}
			}
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}
	}
}
namespace ValheimModDev.UI
{
	internal static class ControlPanel
	{
		private const int LayoutVersion = 3;

		private const float MaxWidth = 860f;

		private const float MaxHeight = 760f;

		private const float MinWidth = 640f;

		private const float MinHeight = 560f;

		private const float ScrollSide = 20f;

		private const float ScrollBottom = 56f;

		private const float ScrollTopList = 186f;

		private const float ScrollTopDetail = 140f;

		private static readonly Vector2 Center;

		private static GameObject root;

		private static Text titleLabel;

		private static Text subtitleLabel;

		private static Text detailTitle;

		private static Text detailDescription;

		private static Text restartNote;

		private static Button closeButton;

		private static Button backButton;

		private static RectTransform categoryRoot;

		private static RectTransform scrollRect;

		private static RectTransform content;

		private static readonly List<Button> categoryButtons;

		private static PanelCategory currentCategory;

		private static PanelFeature currentFeature;

		private static bool isOpen;

		private static int builtLayoutVersion;

		private static float builtWidth;

		private static float builtHeight;

		private static bool capturingKey;

		private static ConfigEntry<KeyboardShortcut> captureEntry;

		private static Button captureButton;

		public static bool IsOpen
		{
			get
			{
				if (isOpen && (Object)(object)root != (Object)null)
				{
					return root.activeSelf;
				}
				return false;
			}
		}

		public static bool IsCapturingKey => capturingKey;

		static ControlPanel()
		{
			//IL_000a: 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)
			Center = new Vector2(0.5f, 0.5f);
			categoryButtons = new List<Button>();
			currentCategory = PanelCategory.Inventory;
			GUIManager.OnCustomGUIAvailable += HandleGuiAvailable;
			ModLang.LanguageChanged += HandleLanguageChanged;
		}

		public static void Tick()
		{
			if (GUIManager.IsHeadless())
			{
				return;
			}
			if (capturingKey)
			{
				TickKeyCapture();
			}
			else if (IsOpenPanelPressed() && !HasTextFocus() && !IsTypingElsewhere())
			{
				if (IsOpen)
				{
					Close();
				}
				else if (CanOpen())
				{
					Open();
				}
			}
		}

		public static void Open()
		{
			if (CanOpen())
			{
				EnsureUi();
				if (!((Object)(object)root == (Object)null))
				{
					currentCategory = PanelCategory.Inventory;
					currentFeature = null;
					root.SetActive(true);
					isOpen = true;
					GUIManager.BlockInput(true);
					RefreshChrome();
					RefreshContent();
					Log("Panel opened");
				}
			}
		}

		public static void Close()
		{
			CancelKeyCapture();
			if ((Object)(object)root != (Object)null)
			{
				root.SetActive(false);
			}
			if (isOpen)
			{
				GUIManager.BlockInput(false);
				Log("Panel closed");
			}
			isOpen = false;
			currentFeature = null;
		}

		public static void HandleEscape()
		{
			if (capturingKey)
			{
				CancelKeyCapture();
			}
			else if (!HasTextFocus())
			{
				Close();
			}
		}

		public static void BeginKeyCapture(ConfigEntry<KeyboardShortcut> entry, Button button)
		{
			if (entry != null && !((Object)(object)button == (Object)null))
			{
				capturingKey = true;
				captureEntry = entry;
				captureButton = button;
				SetButtonLabel(button, ModLang.Get("panel.press_key"));
			}
		}

		public static void CancelKeyCapture()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			if (capturingKey)
			{
				if ((Object)(object)captureButton != (Object)null && captureEntry != null)
				{
					SetButtonLabel(captureButton, ControlPanelWidgets.FormatShortcut(captureEntry.Value));
				}
				capturingKey = false;
				captureEntry = null;
				captureButton = null;
			}
		}

		public static void RefreshOpenContent()
		{
			if (IsOpen)
			{
				RefreshContent();
			}
		}

		public static void LogSettingChanged(string featureId, string settingName, object value)
		{
			Log($"Setting changed: {featureId} / {settingName} = {value}");
		}

		public static bool HasTextFocus()
		{
			EventSystem current = EventSystem.current;
			if ((Object)(object)current == (Object)null || (Object)(object)current.currentSelectedGameObject == (Object)null)
			{
				return false;
			}
			return (Object)(object)current.currentSelectedGameObject.GetComponent<InputField>() != (Object)null;
		}

		internal static void Log(string message)
		{
			Logger.LogDebug((object)("[Valkryn UI] " + message));
		}

		private static void HandleGuiAvailable()
		{
			bool num = isOpen;
			DestroyUi();
			if (num)
			{
				GUIManager.BlockInput(false);
				isOpen = false;
			}
		}

		private static void HandleLanguageChanged()
		{
			if (IsOpen)
			{
				RefreshChrome();
				RefreshContent();
			}
		}

		private static bool CanOpen()
		{
			if (GUIManager.IsHeadless() || GUIManager.Instance == null || (Object)(object)GUIManager.CustomGUIFront == (Object)null)
			{
				return false;
			}
			if ((Object)(object)Player.m_localPlayer == (Object)null)
			{
				return false;
			}
			if (IsTypingElsewhere())
			{
				return false;
			}
			if (InventoryGui.IsVisible() || Menu.IsVisible() || TextInput.IsVisible())
			{
				return false;
			}
			if (StoreGui.IsVisible())
			{
				return false;
			}
			if (IsMapOpen() || PortalConfigUI.IsOpen)
			{
				return false;
			}
			return true;
		}

		private static bool IsTypingElsewhere()
		{
			if (Console.IsVisible() || TextInput.IsVisible())
			{
				return true;
			}
			if ((Object)(object)Chat.instance != (Object)null && (Object)(object)((Terminal)Chat.instance).m_input != (Object)null && ((TMP_InputField)((Terminal)Chat.instance).m_input).isFocused)
			{
				return true;
			}
			return false;
		}

		private static bool IsMapOpen()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			if ((Object)(object)Minimap.instance != (Object)null)
			{
				return (int)Minimap.instance.m_mode == 2;
			}
			return false;
		}

		private static bool IsOpenPanelPressed()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			if (QoLConfig.OpenPanelKey == null)
			{
				return false;
			}
			return IsShortcutDown(QoLConfig.OpenPanelKey.Value);
		}

		private static bool IsShortcutDown(KeyboardShortcut shortcut)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if ((int)((KeyboardShortcut)(ref shortcut)).MainKey == 0 || !Input.GetKeyDown(((KeyboardShortcut)(ref shortcut)).MainKey))
			{
				return false;
			}
			foreach (KeyCode modifier in ((KeyboardShortcut)(ref shortcut)).Modifiers)
			{
				if (!IsModifierHeld(modifier))
				{
					return false;
				}
			}
			return true;
		}

		private static bool IsModifierHeld(KeyCode modifier)
		{
			//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_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Invalid comparison between Unknown and I4
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Invalid comparison between Unknown and I4
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Invalid comparison between Unknown and I4
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Invalid comparison between Unknown and I4
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			if ((int)modifier == 306 || (int)modifier == 305)
			{
				if (!Input.GetKey((KeyCode)306))
				{
					return Input.GetKey((KeyCode)305);
				}
				return true;
			}
			if ((int)modifier == 304 || (int)modifier == 303)
			{
				if (!Input.GetKey((KeyCode)304))
				{
					return Input.GetKey((KeyCode)303);
				}
				return true;
			}
			if ((int)modifier == 308 || (int)modifier == 307)
			{
				if (!Input.GetKey((KeyCode)308))
				{
					return Input.GetKey((KeyCode)307);
				}
				return true;
			}
			return Input.GetKey(modifier);
		}

		private static void TickKeyCapture()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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_0051: Invalid comparison between Unknown and I4
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Invalid comparison between Unknown and I4
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Invalid comparison between Unknown and I4
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown((KeyCode)27))
			{
				CancelKeyCapture();
			}
			else
			{
				if (!Input.anyKeyDown)
				{
					return;
				}
				KeyCode val = (KeyCode)0;
				foreach (KeyCode value in Enum.GetValues(typeof(KeyCode)))
				{
					if ((int)value != 0 && !IsModifierKey(value) && (int)value != 323 && (int)value != 324 && (int)value != 325 && Input.GetKeyDown(value))
					{
						val = value;
						break;
					}
				}
				if ((int)val != 0)
				{
					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);
					}
					KeyboardShortcut val3 = default(KeyboardShortcut);
					((KeyboardShortcut)(ref val3))..ctor(val, list.ToArray());
					captureEntry.Value = val3;
					Log($"Setting changed: panel_key / {((ConfigEntryBase)captureEntry).Definition.Key} = {val3}");
					SetButtonLabel(captureButton, ControlPanelWidgets.FormatShortcut(val3));
					capturingKey = false;
					captureEntry = null;
					captureButton = null;
				}
			}
		}

		private static bool IsModifierKey(KeyCode key)
		{
			//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
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Invalid comparison between Unknown and I4
			if ((int)key != 306 && (int)key != 305 && (int)key != 304 && (int)key != 303 && (int)key != 308 && (int)key != 307 && (int)key != 310 && (int)key != 309 && (int)key != 311)
			{
				return (int)key == 312;
			}
			return true;
		}

		private static void EnsureUi()
		{
			//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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: 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_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ac: Expected O, but got Unknown
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0422: Unknown result type (might be due to invalid IL or missing references)
			//IL_042c: Expected O, but got Unknown
			GetPanelSize(out var width, out var height);
			if (!((Object)(object)root != (Object)null) || builtLayoutVersion < 3 || !Mathf.Approximately(builtWidth, width) || !Mathf.Approximately(builtHeight, height))
			{
				DestroyUi();
				GameObject customGUIFront = GUIManager.CustomGUIFront;
				GUIManager instance = GUIManager.Instance;
				if (!((Object)(object)customGUIFront == (Object)null) && instance != null)
				{
					root = instance.CreateWoodpanel(customGUIFront.transform, Center, Center, Vector2.zero, width, height, false);
					((Object)root).name = "ValkrynControlPanel";
					titleLabel = ControlPanelWidgets.CreateLabel(instance, root.transform, ModLang.Get("panel.title"), new Vector2(width / 2f - 120f, -16f), 240f, 32f, 24, instance.AveriaSerifBold, instance.ValheimOrange, (TextAnchor)4);
					CenterLabel(titleLabel, width, -16f, 240f, 32f);
					subtitleLabel = ControlPanelWidgets.CreateLabel(instance, root.transform, ModLang.Get("panel.subtitle"), new Vector2(width / 2f - 120f, -46f), 240f, 22f, 16, instance.AveriaSerif, Color.white, (TextAnchor)4);
					CenterLabel(subtitleLabel, width, -46f, 240f, 22f);
					categoryRoot = new GameObject("Categories", new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
					((Transform)categoryRoot).SetParent(root.transform, false);
					categoryRoot.anchorMin = new Vector2(0.5f, 1f);
					categoryRoot.anchorMax = new Vector2(0.5f, 1f);
					categoryRoot.pivot = new Vector2(0.5f, 1f);
					categoryRoot.anchoredPosition = new Vector2(0f, -64f);
					categoryRoot.sizeDelta = new Vector2(width - 36f, 68f);
					BuildCategoryButtons(width - 36f);
					detailTitle = ControlPanelWidgets.CreateLabel(instance, root.transform, string.Empty, new Vector2(24f, -74f), width - 48f, 24f, 18, instance.AveriaSerifBold, instance.ValheimOrange, (TextAnchor)3);
					detailDescription = ControlPanelWidgets.CreateLabel(instance, root.transform, string.Empty, new Vector2(24f, -98f), width - 48f, 20f, 13, instance.AveriaSerif, Color.white, (TextAnchor)3);
					restartNote = ControlPanelWidgets.CreateLabel(instance, root.transform, string.Empty, new Vector2(24f, -118f), width - 48f, 16f, 12, instance.AveriaSerif, instance.ValheimOrange, (TextAnchor)3);
					float width2 = width - 40f;
					float height2 = height - 186f - 56f;
					scrollRect = ControlPanelWidgets.CreateScrollArea(root.transform, width2, height2, out content).GetComponent<RectTransform>();
					ApplyScrollLayout(showCategories: true);
					closeButton = instance.CreateButton(ModLang.Get("panel.close"), root.transform, Center, Center, Vector2.zero, 130f, 36f).GetComponent<Button>();
					Transform transform = ((Component)closeButton).transform;
					PlaceFooter((RectTransform)(object)((transform is RectTransform) ? transform : null), 80f, 28f, 130f, 36f);
					((UnityEvent)closeButton.onClick).AddListener(new UnityAction(Close));
					backButton = instance.CreateButton(ModLang.Get("panel.back"), root.transform, Center, Center, Vector2.zero, 130f, 36f).GetComponent<Button>();
					Transform transform2 = ((Component)backButton).transform;
					PlaceFooter((RectTransform)(object)((transform2 is RectTransform) ? transform2 : null), -80f, 28f, 130f, 36f);
					((UnityEvent)backButton.onClick).AddListener(new UnityAction(ShowCategoryList));
					((Transform)categoryRoot).SetAsLastSibling();
					((Component)closeButton).transform.SetAsLastSibling();
					((Component)backButton).transform.SetAsLastSibling();
					builtLayoutVersion = 3;
					builtWidth = width;
					builtHeight = height;
					root.SetActive(false);
				}
			}
		}

		private static void BuildCategoryButtons(float areaWidth)
		{
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			categoryButtons.Clear();
			int num = 4;
			float num2 = (areaWidth - 6f * (float)(num - 1)) / (float)num;
			PanelCategory[] categoryOrder = ControlPanelCatalog.CategoryOrder;
			for (int i = 0; i < categoryOrder.Length; i++)
			{
				int num3 = i / num;
				int num4 = i % num;
				int num5 = Mathf.Min(num, categoryOrder.Length - num3 * num);
				float num6 = (0f - (num2 * (float)num5 + 6f * (float)(num5 - 1))) / 2f + num2 / 2f + (float)num4 * (num2 + 6f);
				float num7 = (float)(-num3) * 34f - 14f;
				Button val = ControlPanelWidgets.CreateCategoryButton((Transform)(object)categoryRoot, categoryOrder[i], num2, 28f, SelectCategory);
				Transform transform = ((Component)val).transform;
				Transform obj = ((transform is RectTransform) ? transform : null);
				((RectTransform)obj).anchorMin = Center;
				((RectTransform)obj).anchorMax = Center;
				((RectTransform)obj).pivot = Center;
				((RectTransform)obj).anchoredPosition = new Vector2(num6, num7);
				((RectTransform)obj).sizeDelta = new Vector2(num2, 28f);
				categoryButtons.Add(val);
			}
		}

		private static void SelectCategory(PanelCategory category)
		{
			currentCategory = category;
			currentFeature = null;
			Log($"Category changed: {category}");
			RefreshChrome();
			RefreshContent();
		}

		private static void ShowCategoryList()
		{
			currentFeature = null;
			RefreshChrome();
			RefreshContent();
		}

		private static void ShowFeature(PanelFeature feature)
		{
			currentFeature = feature;
			Log("Feature opened: " + feature.Id);
			RefreshChrome();
			RefreshContent();
		}

		private static void RefreshChrome()
		{
			if ((Object)(object)titleLabel != (Object)null)
			{
				titleLabel.text = ModLang.Get("panel.title");
			}
			if ((Object)(object)subtitleLabel != (Object)null)
			{
				subtitleLabel.text = ModLang.Get("panel.subtitle");
			}
			if ((Object)(object)closeButton != (Object)null)
			{
				SetButtonLabel(closeButton, ModLang.Get("panel.close"));
			}
			if ((Object)(object)backButton != (Object)null)
			{
				SetButtonLabel(backButton, ModLang.Get("panel.back"));
				((Component)backButton).gameObject.SetActive(currentFeature != null);
			}
			bool flag = currentFeature == null;
			if ((Object)(object)categoryRoot != (Object)null)
			{
				((Component)categoryRoot).gameObject.SetActive(flag);
			}
			if ((Object)(object)detailTitle != (Object)null)
			{
				((Component)detailTitle).gameObject.SetActive(!flag);
				detailTitle.text = ((currentFeature != null) ? currentFeature.Name() : string.Empty);
			}
			if ((Object)(object)detailDescription != (Object)null)
			{
				((Component)detailDescription).gameObject.SetActive(!flag);
				detailDescription.text = ((currentFeature != null) ? currentFeature.Description() : string.Empty);
			}
			if ((Object)(object)restartNote != (Object)null)
			{
				bool flag2 = currentFeature != null && (currentFeature.RequiresRestart || currentFeature.PartialRestart);
				((Component)restartNote).gameObject.SetActive(flag2);
				if (flag2)
				{
					restartNote.text = (currentFeature.RequiresRestart ? ModLang.Get("panel.restart") : ModLang.Get("panel.restart.partial"));
				}
			}
			for (int i = 0; i < categoryButtons.Count && i < ControlPanelCatalog.CategoryOrder.Length; i++)
			{
				ControlPanelWidgets.SetCategorySelected(categoryButtons[i], ControlPanelCatalog.CategoryOrder[i] == currentCategory);
				SetButtonLabel(categoryButtons[i], ControlPanelCatalog.CategoryName(ControlPanelCatalog.CategoryOrder[i]));
			}
			ApplyScrollLayout(flag);
		}

		private static void RefreshContent()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			if ((Object)(object)content == (Object)null)
			{
				return;
			}
			ControlPanelWidgets.ClearChildren((Transform)(object)content);
			Rect rect = content.rect;
			float num;
			if (!(((Rect)(ref rect)).width > 100f))
			{
				num = builtWidth - 72f;
			}
			else
			{
				rect = content.rect;
				num = ((Rect)(ref rect)).width;
			}
			float width = num;
			if (currentFeature == null)
			{
				foreach (PanelFeature item in ControlPanelCatalog.ForCategory(currentCategory))
				{
					ControlPanelWidgets.CreateFeatureRow((Transform)(object)content, width, item, ShowFeature);
				}
				return;
			}
			if (currentFeature.Enabled != null)
			{
				ControlPanelWidgets.CreateSettingRow((Transform)(object)content, width, currentFeature, PanelSetting.NamedBool(currentFeature.Enabled, "panel.enable"));
			}
			foreach (PanelSetting setting in currentFeature.Settings)
			{
				ControlPanelWidgets.CreateSettingRow((Transform)(object)content, width, currentFeature, setting);
			}
		}

		private static void GetPanelSize(out float width, out float height)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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)
			float num = Screen.width;
			float num2 = Screen.height;
			RectTransform val = (((Object)(object)GUIManager.CustomGUIFront != (Object)null) ? GUIManager.CustomGUIFront.GetComponent<RectTransform>() : null);
			if ((Object)(object)val != (Object)null)
			{
				Rect rect = val.rect;
				if (((Rect)(ref rect)).width > 1f)
				{
					rect = val.rect;
					if (((Rect)(ref rect)).height > 1f)
					{
						rect = val.rect;
						num = ((Rect)(ref rect)).width;
						rect = val.rect;
						num2 = ((Rect)(ref rect)).height;
					}
				}
			}
			width = Mathf.Clamp(Mathf.Min(860f, num * 0.58f), 640f, 860f);
			height = Mathf.Clamp(Mathf.Min(760f, num2 * 0.86f), 560f, 760f);
		}

		private static void ApplyScrollLayout(bool showCategories)
		{
			//IL_0013: 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_0031: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)scrollRect == (Object)null))
			{
				scrollRect.anchorMin = Vector2.zero;
				scrollRect.anchorMax = Vector2.one;
				scrollRect.pivot = Center;
				scrollRect.offsetMin = new Vector2(20f, 56f);
				scrollRect.offsetMax = new Vector2(-20f, showCategories ? (-186f) : (-140f));
			}
		}

		private static void CenterLabel(Text label, float panelWidth, float yFromTop, float width, float height)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)label == (Object)null))
			{
				RectTransform rectTransform = ((Graphic)label).rectTransform;
				rectTransform.anchorMin = new Vector2(0.5f, 1f);
				rectTransform.anchorMax = new Vector2(0.5f, 1f);
				rectTransform.pivot = new Vector2(0.5f, 1f);
				rectTransform.anchoredPosition = new Vector2(0f, yFromTop);
				rectTransform.sizeDelta = new Vector2(width, height);
			}
		}

		private static void PlaceFooter(RectTransform rect, float x, float y, float width, float height)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)rect == (Object)null))
			{
				rect.anchorMin = new Vector2(0.5f, 0f);
				rect.anchorMax = new Vector2(0.5f, 0f);
				rect.pivot = Center;
				rect.anchoredPosition = new Vector2(x, y);
				rect.sizeDelta = new Vector2(width, height);
			}
		}

		private static void SetButtonLabel(Button button, string text)
		{
			if (!((Object)(object)button == (Object)null))
			{
				Text componentInChildren = ((Component)button).GetComponentInChildren<Text>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					componentInChildren.text = text;
				}
			}
		}

		private static void DestroyUi()
		{
			CancelKeyCapture();
			categoryButtons.Clear();
			if ((Object)(object)root != (Object)null)
			{
				Object.Destroy((Object)(object)root);
			}
			root = null;
			titleLabel = null;
			subtitleLabel = null;
			detailTitle = null;
			detailDescription = null;
			restartNote = null;
			closeButton = null;
			backButton = null;
			categoryRoot = null;
			scrollRect = null;
			content = null;
			builtLayoutVersion = 0;
		}
	}
	[HarmonyPatch(typeof(Menu), "Update")]
	internal static class ControlPanelMenuPatch
	{
		private static bool Prefix()
		{
			if (!ControlPanel.IsOpen)
			{
				return true;
			}
			if (Input.GetKeyDown((KeyCode)27))
			{
				ControlPanel.HandleEscape();
			}
			return false;
		}
	}
	internal enum PanelCategory
	{
		Inventory,
		Production,
		World,
		Player,
		Interaction,
		Interface
	}
	internal enum PanelSettingKind
	{
		Boolean,
		Integer,
		Float,
		Choice,
		Key,
		Text,
		Action
	}
	internal sealed class PanelChoice
	{
		public object Value { get; }

		public string LabelKey { get; }

		public PanelChoice(object value, string labelKey)
		{
			Value = value;
			LabelKey = labelKey;
		}

		public string Display()
		{
			return ModLang.Get(LabelKey);
		}
	}
	internal sealed class PanelSetting
	{
		public string ConfigTextKey { get; private set; }

		public string NameKey { get; private set; }

		public string DescriptionKey { get; private set; }

		public ConfigEntryBase Entry { get; private set; }

		public PanelSettingKind Kind { get; private set; }

		public PanelChoice[] Choices { get; private set; }

		public Action Action { get; private set; }

		public bool RequiresRestart { get; private set; }

		public bool PartialRestart { get; private set; }

		public string DisplayName()
		{
			if (!string.IsNullOrEmpty(ConfigTextKey))
			{
				return ModLang.GetConfigName(ConfigTextKey);
			}
			return ModLang.Get(NameKey);
		}

		public string DisplayDescription()
		{
			if (!string.IsNullOrEmpty(ConfigTextKey))
			{
				return ModLang.GetConfigDescription(ConfigTextKey);
			}
			if (!string.IsNullOrEmpty(DescriptionKey))
			{
				return ModLang.Get(DescriptionKey);
			}
			return string.Empty;
		}

		public static PanelSetting Bool(ConfigEntry<bool> entry, string textKey)
		{
			return new PanelSetting
			{
				ConfigTextKey = textKey,
				Entry = (ConfigEntryBase)(object)entry,
				Kind = PanelSettingKind.Boolean
			};
		}

		public static PanelSetting NamedBool(ConfigEntry<bool> entry, string nameKey)
		{
			return new PanelSetting
			{
				NameKey = nameKey,
				Entry = (ConfigEntryBase)(object)entry,
				Kind = PanelSettingKind.Boolean
			};
		}

		public static PanelSetting Int(ConfigEntry<int> entry, string textKey, bool restart = false, bool partialRestart = false)
		{
			return new PanelSetting
			{
				ConfigTextKey = textKey,
				Entry = (ConfigEntryBase)(object)entry,
				Kind = PanelSettingKind.Integer,
				RequiresRestart = restart,
				PartialRestart = partialRestart
			};
		}

		public static PanelSetting Float(ConfigEntry<float> entry, string textKey)
		{
			return new PanelSetting
			{
				ConfigTextKey = textKey,
				Entry = (ConfigEntryBase)(object)entry,
				Kind = PanelSettingKind.Float
			};
		}

		public static PanelSetting Key(ConfigEntry<KeyboardShortcut> entry, string textKey)
		{
			return new PanelSetting
			{
				ConfigTextKey = textKey,
				Entry = (ConfigEntryBase)(object)entry,
				Kind = PanelSettingKind.Key
			};
		}

		public static PanelSetting Text(ConfigEntry<string> entry, string textKey)
		{
			return new PanelSetting
			{
				ConfigTextKey = textKey,
				Entry = (ConfigEntryBase)(object)entry,
				Kind = PanelSettingKind.Text
			};
		}

		public static PanelSetting Choice(ConfigEntryBase entry, string textKey, params PanelChoice[] choices)
		{
			return new PanelSetting
			{
				ConfigTextKey = textKey,
				Entry = entry,
				Kind = PanelSettingKind.Choice,
				Choices = choices
			};
		}

		public static PanelSetting Act(string nameKey, string descriptionKey, Action action)
		{
			return new PanelSetting
			{
				NameKey = nameKey,
				DescriptionKey = descriptionKey,
				Kind = PanelSettingKind.Action,
				Action = action
			};
		}
	}
	internal sealed class PanelFeature
	{
		public string Id { get; private set; }

		public PanelCategory Category { get; private set; }

		public string NameKey { get; private set; }

		public string DescriptionKey { get; private set; }

		public ConfigEntry<bool> Enabled { get; private set; }

		public IReadOnlyList<PanelSetting> Settings { get; private set; }

		public bool RequiresRestart { get; private set; }

		public bool PartialRestart { get; private set; }

		public Func<string> Summary { get; private set; }

		public bool HasConfigure
		{
			get
			{
				if (Settings != null)
				{
					return Settings.Count > 0;
				}
				return false;
			}
		}

		public string Name()
		{
			return ModLang.Get(NameKey);
		}

		public string Description()
		{
			return ModLang.Get(DescriptionKey);
		}

		public static PanelFeature Create(string id, PanelCategory category, string nameKey, string descriptionKey, ConfigEntry<bool> enabled = null, PanelSetting[] settings = null, bool restart = false, bool partialRestart = false, Func<string> summary = null)
		{
			return new PanelFeature
			{
				Id = id,
				Category = category,
				NameKey = nameKey,
				DescriptionKey = descriptionKey,
				Enabled = enabled,
				Settings = (settings ?? Array.Empty<PanelSetting>()),
				RequiresRestart = restart,
				PartialRestart = partialRestart,
				Summary = summary
			};
		}
	}
	internal static class ControlPanelCatalog
	{
		public static readonly PanelCategory[] CategoryOrder = new PanelCategory[6]
		{
			PanelCategory.Inventory,
			PanelCategory.Production,
			PanelCategory.World,
			PanelCategory.Player,
			PanelCategory.Interaction,
			PanelCategory.Interface
		};

		private static List<PanelFeature> features;

		public static IReadOnlyList<PanelFeature> All
		{
			get
			{
				if (features == null)
				{
					features = Build();
				}
				return features;
			}
		}

		public static string CategoryName(PanelCategory category)
		{
			return category switch
			{
				PanelCategory.Inventory => ModLang.Get("panel.category.inventory"), 
				PanelCategory.Production => ModLang.Get("panel.category.production"), 
				PanelCategory.World => ModLang.Get("panel.category.world"), 
				PanelCategory.Player => ModLang.Get("panel.category.player"), 
				PanelCategory.Interaction => ModLang.Get("panel.category.interaction"), 
				_ => ModLang.Get("panel.category.interface"), 
			};
		}

		public static List<PanelFeature> ForCategory(PanelCategory category)
		{
			List<PanelFeature> list = new List<PanelFeature>();
			foreach (PanelFeature item in All)
			{
				if (item.Category == category)
				{
					list.Add(item);
				}
			}
			return list;
		}

		private static List<PanelFeature> Build()
		{
			List<PanelFeature> list = new List<PanelFeature>();
			list.Add(PanelFeature.Create("smart_deposit", PanelCategory.Inventory, "panel.feature.smart_deposit", "panel.feature.smart_deposit.desc", QoLConfig.EnableQuickStore, new PanelSetting[2]
			{
				PanelSetting.Key(QoLConfig.QuickStoreKey, "inventory.quick_store_key"),
				PanelSetting.Int(QoLConfig.QuickStoreRange, "inventory.quick_store_range")
			}, restart: false, partialRestart: false, () => $"{QoLConfig.QuickStoreRange.Value}m"));
			list.Add(PanelFeature.Create("store_existing", PanelCategory.Inventory, "panel.feature.store_existing", "panel.feature.store_existing.desc", QoLConfig.EnableDepositExisting, new PanelSetting[1] { PanelSetting.Bool(QoLConfig.DisableWhenAzuAutoStore, "inventory.disable_azu_autostore") }));
			list.Add(PanelFeature.Create("organize", PanelCategory.Inventory, "panel.feature.organize", "panel.feature.organize.desc", QoLConfig.EnableSortInventory));
			list.Add(PanelFeature.Create("inventory_ui", PanelCategory.Inventory, "panel.feature.inventory_ui", "panel.feature.inventory_ui.desc", QoLConfig.EnableInventoryUi, new PanelSetting[2]
			{
				PanelSetting.Bool(QoLConfig.EnableTrashSlot, "inventory.enable_trash"),
				PanelSetting.Act("panel.reset_position", "panel.reset_position.desc", delegate
				{
					QoLConfig.InventoryUiUseCustomPosition.Value = false;
				})
			}));
			list.Add(PanelFeature.Create("stack_multiplier", PanelCategory.Inventory, "panel.feature.stack_multiplier", "panel.feature.stack_multiplier.desc", QoLConfig.EnableStackMultiplier, new PanelSetting[1] { PanelSetting.Int(QoLConfig.StackMultiplier, "inventory.stack_multiplier", restart: true) }, restart: true, partialRestart: false, () => $"{QoLConfig.StackMultiplier.Value}x"));
			list.Add(PanelFeature.Create("carry_weight", PanelCategory.Inventory, "panel.feature.carry_weight", "panel.feature.carry_weight.desc", QoLConfig.EnableCarryWeight, new PanelSetting[1] { PanelSetting.Int(QoLConfig.CarryWeight, "inventory.carry_weight") }, restart: false, partialRestart: false, () => QoLConfig.CarryWeight.Value.ToString()));
			list.Add(PanelFeature.Create("item_weight", PanelCategory.Inventory, "panel.feature.item_weight", "panel.feature.item_weight.desc", QoLConfig.EnableItemWeightReduction, new PanelSetting[1] { PanelSetting.Int(QoLConfig.ItemWeightReductionPercent, "inventory.item_weight_reduction") }, restart: false, partialRestart: false, () => $"{QoLConfig.ItemWeightReductionPercent.Value}%"));
			list.Add(PanelFeature.Create("smart_crafting", PanelCategory.Inventory, "panel.feature.smart_crafting", "panel.feature.smart_crafting.desc", SmartCraftingConfig.EnableSmartCrafting, new PanelSetting[8]
			{
				PanelSetting.Int(SmartCraftingConfig.SearchRadius, "crafting.search_radius"),
				PanelSetting.Bool(SmartCraftingConfig.UsePlayerInventory, "crafting.use_inventory"),
				PanelSetting.Bool(SmartCraftingConfig.UseNearbyChests, "crafting.use_chests"),
				PanelSetting.Bool(SmartCraftingConfig.IgnoreFavorites, "crafting.ignore_favorites"),
				PanelSetting.Bool(SmartCraftingConfig.IgnoreEquippedItems, "crafting.ignore_equipped"),
				PanelSetting.Bool(SmartCraftingConfig.IgnoreHotbarItems, "crafting.ignore_hotbar"),
				PanelSetting.Bool(SmartCraftingConfig.DisableWhenAzuCraftyBoxes, "crafting.disable_azu_crafty_boxes"),
				PanelSetting.Bool(SmartCraftingConfig.EnableDebugLogging, "crafting.debug")
			}, restart: false, partialRestart: false, () => $"{SmartCraftingConfig.SearchRadius.Value}m"));
			list.Add(PanelFeature.Create("favorites", PanelCategory.Inventory, "panel.feature.favorites", "panel.feature.favorites.desc"));
			list.Add(PanelFeature.Create("fast_production", PanelCategory.Production, "panel.feature.fast_production", "panel.feature.fast_production.desc", QoLConfig.EnableProductionSpeed, new PanelSetting[1] { PanelSetting.Int(QoLConfig.ProductionSpeed, "production.speed") }, restart: false, partialRestart: false, () => $"{QoLConfig.ProductionSpeed.Value}x"));
			list.Add(PanelFeature.Create("fermenter", PanelCategory.Production, "panel.feature.fermenter", "panel.feature.fermenter.desc", QoLConfig.EnableFermenterSpeed, new PanelSetting[1] { PanelSetting.Int(QoLConfig.FermenterSpeed, "production.fermenter_speed") }, restart: false, partialRestart: false, () => $"{QoLConfig.FermenterSpeed.Value}x"));
			list.Add(PanelFeature.Create("passive", PanelCategory.Production, "panel.feature.passive", "panel.feature.passive.desc", QoLConfig.EnablePassiveProduction, new PanelSetting[1] { PanelSetting.Int(QoLConfig.PassiveProductionSpeed, "production.passive_speed") }, restart: false, partialRestart: false, () => $"{QoLConfig.PassiveProductionSpeed.Value}x"));
			list.Add(PanelFeature.Create("cooking", PanelCategory.Production, "panel.feature.cooking", "panel.feature.cooking.desc", QoLConfig.EnableCookingSpeed, new PanelSetting[1] { PanelSetting.Int(QoLConfig.CookingSpeed, "production.cooking_speed") }, restart: false, partialRestart: false, () => $"{QoLConfig.CookingSpeed.Value}x"));
			list.Add(PanelFeature.Create("smelter_capacity", PanelCategory.Production, "panel.feature.smelter_capacity", "panel.feature.smelter_capacity.desc", QoLConfig.EnableSmelterCapacity, new PanelSetting[1] { PanelSetting.Int(QoLConfig.SmelterCapacity, "production.capacity", restart: false, partialRestart: true) }, restart: false, partialRestart: true, () => QoLConfig.SmelterCapacity.Value.ToString()));
			list.Add(PanelFeature.Create("bulk_refuel", PanelCategory.Production, "panel.feature.bulk_refuel", "panel.feature.bulk_refuel.desc", QoLConfig.EnableBulkDeposit, new PanelSetting[3]
			{
				PanelSetting.Bool(QoLConfig.EnableAreaRefuel, "refueling.area_enable"),
				PanelSetting.Key(QoLConfig.AreaRefuelKey, "refueling.area_key"),
				PanelSetting.Float(QoLConfig.AreaRefuelRadius, "refueling.area_radius")
			}, restart: false, partialRestart: false, () => $"{QoLConfig.AreaRefuelRadius.Value:0}m"));
			list.Add(PanelFeature.Create("auto_repair", PanelCategory.Production, "panel.feature.auto_repair", "panel.feature.auto_repair.desc", QoLConfig.EnableAutoRepair));
			list.Add(PanelFeature.Create("world_drop_multiplier", PanelCategory.World, "panel.feature.world_drop_multiplier", "panel.feature.world_drop_multiplier.desc", QoLConfig.EnableWorldDropMultiplier, new PanelSetting[2]
			{
				PanelSetting.Int(QoLConfig.WorldDropMultiplier, "resources.multiplier"),
				PanelSetting.Bool(QoLConfig.EnableStackedDrops, "resources.stacked_drops")
			}, restart: false, partialRestart: false, () => $"{QoLConfig.WorldDropMultiplier.Value}x"));
			list.Add(PanelFeature.Create("mob_drop_multiplier", PanelCategory.World, "panel.feature.mob_drop_multiplier", "panel.feature.mob_drop_multiplier.desc", QoLConfig.EnableMobDropMultiplier, new PanelSetting[1] { PanelSetting.Int(QoLConfig.MobDropMultiplier, "resources.mob_multiplier") }, restart: false, partialRestart: false, () => $"{QoLConfig.MobDropMultiplier.Value}x"));
			list.Add(PanelFeature.Create("container_drop_multiplier", PanelCategory.World, "panel.feature.container_drop_multiplier", "panel.feature.container_drop_multiplier.desc", QoLConfig.EnableContainerDropMultiplier, new PanelSetting[1] { PanelSetting.Int(QoLConfig.ContainerDropMultiplier, "resources.container_multiplier") }, restart: false, partialRestart: false, () => $"{QoLConfig.ContainerDropMultiplier.Value}x"));
			list.Add(PanelFeature.Create("plant_growth", PanelCategory.World, "panel.feature.plant_growth", "panel.feature.plant_growth.desc", QoLConfig.EnablePlantGrowth, new PanelSetting[1] { PanelSetting.Int(QoLConfig.PlantGrowthSpeed, "world.growth_speed") }, restart: false, partialRestart: false, () => $"{QoLConfig.PlantGrowthSpeed.Value}x"));
			list.Add(PanelFeature.Create("no_fog", PanelCategory.World, "panel.feature.no_fog", "panel.feature.no_fog.desc", QoLConfig.EnableNoFog));
			list.Add(PanelFeature.Create("mining", PanelCategory.World, "panel.feature.mining", "panel.feature.mining.desc", QoLConfig.EnableExtraMining, new PanelSetting[2]
			{
				PanelSetting.Choice((ConfigEntryBase)(object)QoLConfig.MiningDamagePercent, "mining.damage_percent", new PanelChoice(25, "panel.pct.25"), new PanelChoice(50, "panel.pct.50"), new PanelChoice(100, "panel.pct.100")),
				PanelSetting.Bool(QoLConfig.MiningExtraDurability, "mining.extra_durability")
			}));
			list.Add(PanelFeature.Create("portals", PanelCategory.World, "panel.feature.portals", "panel.feature.portals.desc", ExtraConfig.EnablePortals, new PanelSetting[2]
			{
				PanelSetting.Choice((ConfigEntryBase)(object)ExtraConfig.PortalItemMode, "portals.item_mode", new PanelChoice(0, "portal.vanilla"), new PanelChoice(1, "portal.anyitem"), new PanelChoice(2, "portal.custom")),
				PanelSetting.Bool(ExtraConfig.Bidirectional, "portals.bidirectional")
			}));
			list.Add(PanelFeature.Create("instant_loot", PanelCategory.World, "panel.feature.instant_loot", "panel.feature.instant_loot.desc", QoLConfig.EnableInstantLoot));
			list.Add(PanelFeature.Create("stamina", PanelCategory.Player, "panel.feature.stamina", "panel.feature.stamina.desc", QoLConfig.EnableHalfStamina));
			list.Add(PanelFeature.Create("no_build_stamina", PanelCategory.Player, "panel.feature.no_build_stamina", "panel.feature.no_build_stamina.desc", ExtraConfig.NoBuildStamina));
			list.Add(PanelFeature.Create("tools", PanelCategory.Player, "panel.feature.tools", "panel.feature.tools.desc", QoLConfig.EnableUnbreakableHammer, new PanelSetting[1] { PanelSetting.Bool(QoLConfig.ProtectAllBuildingTools, "tools.protect_all") }));
			list.Add(PanelFeature.Create("keep_inventory", PanelCategory.Player, "panel.feature.keep_inventory", "panel.feature.keep_inventory.desc", QoLConfig.EnableKeepInventoryOnDeath));
			list.Add(PanelFeature.Create("free_boss_summon", PanelCategory.Player, "panel.feature.free_boss_summon", "panel.feature.free_boss_summon.desc", QoLConfig.EnableFreeBossSummon));
			list.Add(PanelFeature.Create("skip_intro", PanelCategory.Player, "panel.feature.skip_intro", "panel.feature.skip_intro.desc", QoLConfig.EnableSkipIntro, null, restart: true));
			list.Add(PanelFeature.Create("quick_interact", PanelCategory.Interaction, "panel.feature.quick_interact", "panel.feature.quick_interact.desc", ExtraConfig.EnableQuickInteract));
			list.Add(PanelFeature.Create("panel_key", PanelCategory.Interface, "panel.feature.panel_key", "panel.feature.panel_key.desc", null, new PanelSetting[1] { PanelSetting.Key(QoLConfig.OpenPanelKey, "interface.open_panel_key") }));
			list.Add(PanelFeature.Create("clock", PanelCategory.Interface, "panel.feature.clock", "panel.feature.clock.desc", QoLConfig.EnableGameClock, new PanelSetting[2]
			{
				PanelSetting.Bool(QoLConfig.EnableLocalClock, "clock.local"),
				PanelSetting.Bool(QoLConfig.Clock24Hour, "clock.format24")
			}));
			list.Add(PanelFeature.Create("language", PanelCategory.Interface, "panel.feature.language", "panel.feature.language.desc", null, new PanelSetting[1] { PanelSetting.Choice((ConfigEntryBase)(object)ModLang.LanguageEntry, "general.language", new PanelChoice("English", "panel.lang.english"), new PanelChoice("Portuguese", "panel.lang.portuguese")) }));
			return list;
		}
	}
	internal static class ControlPanelWidgets
	{
		private static readonly Vector2 Center = new Vector2(0.5f, 0.5f);

		private static readonly Color DescriptionColor = new Color(0.85f, 0.82f, 0.75f, 1f);

		public const float FeatureRowHeight = 78f;

		public const float SettingRowHeight = 56f;

		public static GameObject CreateScrollArea(Transform parent, float width, float height, out RectTransform content)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Expected O, but got Unknown
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Expected O, but got Unknown
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Expected O, but got Unknown
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Expected O, but got Unknown
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: Unknown result type (might be due to invalid IL or missing references)
			//IL_039f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
			GUIManager instance = GUIManager.Instance;
			GameObject val = new GameObject("ValkrynPanelScroll", new Type[4]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(ScrollRect),
				typeof(RectMask2D)
			});
			val.transform.SetParent(parent, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = Center;
			component.anchorMax = Center;
			component.pivot = Center;
			component.sizeDelta = new Vector2(width, height);
			Image component2 = val.GetComponent<Image>();
			((Graphic)component2).color = new Color(0f, 0f, 0f, 0.35f);
			((Graphic)component2).raycastTarget = true;
			GameObject val2 = new GameObject("Viewport", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(RectMask2D)
			});
			val2.transform.SetParent(val.transform, false);
			RectTransform component3 = val2.GetComponent<RectTransform>();
			component3.anchorMin = Vector2.zero;
			component3.anchorMax = Vector2.one;
			component3.offsetMin = new Vector2(6f, 6f);
			component3.offsetMax = new Vector2(-18f, -6f);
			Image component4 = val2.GetComponent<Image>();
			((Graphic)component4).color = new Color(0f, 0f, 0f, 0f);
			((Graphic)component4).raycastTarget = true;
			GameObject val3 = new GameObject("Content", new Type[3]
			{
				typeof(RectTransform),
				typeof(VerticalLayoutGroup),
				typeof(ContentSizeFitter)
			});
			val3.transform.SetParent(val2.transform, false);
			content = val3.GetComponent<RectTransform>();
			content.anchorMin = new Vector2(0f, 1f);
			content.anchorMax = new Vector2(1f, 1f);
			content.pivot = new Vector2(0.5f, 1f);
			content.anchoredPosition = Vector2.zero;
			content.sizeDelta = new Vector2(0f, 0f);
			VerticalLayoutGroup component5 = val3.GetComponent<VerticalLayoutGroup>();
			((LayoutGroup)component5).childAlignment = (TextAnchor)1;
			((HorizontalOrVerticalLayoutGroup)component5).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)component5).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)component5).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)component5).childForceExpandHeight = false;
			((HorizontalOrVerticalLayoutGroup)component5).spacing = 6f;
			((LayoutGroup)component5).padding = new RectOffset(4, 4, 4, 8);
			ContentSizeFitter component6 = val3.GetComponent<ContentSizeFitter>();
			component6.horizontalFit = (FitMode)0;
			component6.verticalFit = (FitMode)2;
			GameObject val4 = new GameObject("Scrollbar", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Scrollbar)
			});
			val4.transform.SetParent(val.transform, false);
			RectTransform component7 = val4.GetComponent<RectTransform>();
			component7.anchorMin = new Vector2(1f, 0f);
			component7.anchorMax = new Vector2(1f, 1f);
			component7.pivot = new Vector2(1f, 0.5f);
			component7.sizeDelta = new Vector2(10f, -12f);
			component7.anchoredPosition = new Vector2(-4f, 0f);
			((Graphic)val4.GetComponent<Image>()).color = new Color(0f, 0f, 0f, 0.65f);
			GameObject val5 = new GameObject("Handle", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val5.transform.SetParent(val4.transform, false);
			RectTransform component8 = val5.GetComponent<RectTransform>();
			component8.anchorMin = Vector2.zero;
			component8.anchorMax = Vector2.one;
			component8.offsetMin = Vector2.zero;
			component8.offsetMax = Vector2.zero;
			Image component9 = val5.GetComponent<Image>();
			((Graphic)component9).color = Color.white;
			Scrollbar component10 = val4.GetComponent<Scrollbar>();
			component10.direction = (Direction)2;
			component10.handleRect = component8;
			((Selectable)component10).targetGraphic = (Graphic)(object)component9;
			component10.value = 1f;
			ScrollRect component11 = val.GetComponent<ScrollRect>();
			component11.viewport = component3;
			component11.content = content;
			component11.horizontal = false;
			component11.vertical = true;
			component11.movementType = (MovementType)2;
			component11.scrollSensitivity = 40f;
			component11.verticalScrollbar = component10;
			component11.verticalScrollbarVisibility = (ScrollbarVisibility)2;
			component11.verticalScrollbarSpacing = 2f;
			if (instance != null)
			{
				instance.ApplyScrollRectStyle(component11);
				instance.ApplyScrollbarStyle(component10);
			}
			return val;
		}

		public static void ClearChildren(Transform parent)
		{
			if (!((Object)(object)parent == (Object)null))
			{
				for (int num = parent.childCount - 1; num >= 0; num--)
				{
					Object.Destroy((Object)(object)((Component)parent.GetChild(num)).gameObject);
				}
			}
		}

		public static Button CreateCategoryButton(Transform parent, PanelCategory category, float width, float height, Action<PanelCategory> onClick)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			Button component = GUIManager.Instance.CreateButton(ControlPanelCatalog.CategoryName(category), parent, Center, Center, Vector2.zero, width, height).GetComponent<Button>();
			PanelCategory captured = category;
			((UnityEvent)component.onClick).AddListener((UnityAction)delegate
			{
				onClick(captured);
			});
			return component;
		}

		public static void SetCategorySelected(Button button, bool selected)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)button == (Object)null))
			{
				Text componentInChildren = ((Component)button).GetComponentInChildren<Text>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					((Graphic)componentInChildren).color = (selected ? GUIManager.Instance.ValheimOrange : Color.white);
				}
			}
		}

		public static GameObject CreateFeatureRow(Transform parent, float width, PanelFeature feature, Action<PanelFeature> onConfigure)
		{
			//IL_0047: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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_011b: 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_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Expected O, but got Unknown
			GameObject val = CreateRow(parent, width, 78f, "Feature_" + feature.Id);
			GUIManager instance = GUIManager.Instance;
			CreateLabel(instance, val.transform, feature.Name(), new Vector2(10f, -8f), width - 130f, 24f, 16, instance.AveriaSerifBold, instance.ValheimOrange, (TextAnchor)3);
			if (feature.Enabled != null)
			{
				CreateStatusToggle(instance, val.transform, feature, new Vector2(width - 78f, -10f));
			}
			CreateLabel(instance, val.transform, feature.Description(), new Vector2(10f, -30f), width - 24f, 20f, 13, instance.AveriaSerif, DescriptionColor, (TextAnchor)3);
			string text = ((feature.Summary != null) ? feature.Summary() : string.Empty);
			if (!string.IsNullOrEmpty(text))
			{
				CreateLabel(instance, val.transform, text, new Vector2(10f, -52f), 160f, 20f, 13, instance.AveriaSerif, Color.white, (TextAnchor)3);
			}
			if (feature.HasConfigure)
			{
				Button component = instance.CreateButton(ModLang.Get("panel.configure"), val.transform, Center, Center, Vector2.zero, 120f, 24f).GetComponent<Button>();
				Transform transform = ((Component)component).transform;
				Place((RectTransform)(object)((transform is RectTransform) ? transform : null), width - 70f, -52f, 120f, 24f);
				PanelFeature captured = feature;
				((UnityEvent)component.onClick).AddListener((UnityAction)delegate
				{
					onConfigure(captured);
				});
			}
			return val;
		}

		public static GameObject CreateSettingRow(Transform parent, float width, PanelFeature feature, PanelSetting setting)
		{
			//IL_002f: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: 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)
			GameObject val = CreateRow(parent, width, 56f, "Setting");
			GUIManager instance = GUIManager.Instance;
			CreateLabel(instance, val.transform, setting.DisplayName(), new Vector2(10f, -6f), width - 180f, 22f, 15, instance.AveriaSerifBold, Color.white, (TextAnchor)3);
			string text = setting.DisplayDescription();
			if (!string.IsNullOrEmpty(text))
			{
				CreateLabel(instance, val.transform, text, new Vector2(10f, -30f), width - 24f, 20f, 12, instance.AveriaSerif, DescriptionColor, (TextAnchor)3);
			}
			if (setting.RequiresRestart || setting.PartialRestart)
			{
				string text2 = (setting.RequiresRestart ? ModLang.Get("panel.restart") : ModLang.Get("panel.restart.partial"));
				CreateLabel(instance, val.transform, text2, new Vector2(width - 170f, -6f), 160f, 18f, 11, instance.AveriaSerif, instance.ValheimOrange, (TextAnchor)5);
			}
			PlaceSettingControl(instance, val.transform, feature, setting, width);
			return val;
		}

		public static Text CreateLabel(GUIManager gui, Transform parent, string text, Vector2 topLeft, float width, float height, int fontSize, Font font, Color color, TextAnchor align)
		{
			//IL_000d: 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)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_009c: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = gui.CreateText(text, parent, new Vector2(0f, 1f), new Vector2(0f, 1f), Vector2.zero, font, fontSize, color, true, Color.black, width, height, false);
			Text component = obj.GetComponent<Text>();
			if ((Object)(object)component != (Object)null)
			{
				component.alignment = align;
				component.horizontalOverflow = (HorizontalWrapMode)0;
				component.verticalOverflow = (VerticalWrapMode)0;
			}
			RectTransform component2 = obj.GetComponent<RectTransform>();
			component2.anchorMin = new Vector2(0f, 1f);
			component2.anchorMax = new Vector2(0f, 1f);
			component2.pivot = new Vector2(0f, 1f);
			component2.anchoredPosition = topLeft;
			component2.sizeDelta = new Vector2(width, height);
			return component;
		}

		public static void Place(RectTransform rect, float centerX, float centerYFromTop, float width, float height)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)rect == (Object)null))
			{
				rect.anchorMin = new Vector2(0f, 1f);
				rect.anchorMax = new Vector2(0f, 1f);
				rect.pivot = Center;
				rect.anchoredPosition = new Vector2(centerX, centerYFromTop);
				rect.sizeDelta = new Vector2(width, height);
			}
		}

		public static void WriteEntry(PanelFeature feature, PanelSetting setting, object value)
		{
			if (setting.Entry == null)
			{
				return;
			}
			object obj = BoxForEntry(setting.Entry, value);
			if (obj == null)
			{
				return;
			}
			ConfigDescription description = setting.Entry.Description;
			AcceptableValueBase val = ((description != null) ? description.AcceptableValues : null);
			if (val != null && !val.IsValid(obj))
			{
				obj = ClampToAcceptable(setting.Entry, obj);
				if (obj == null || !val.IsValid(obj))
				{
					return;
				}
			}
			if (!object.Equals(setting.Entry.BoxedValue, obj))
			{
				setting.Entry.BoxedValue = obj;
				ControlPanel.LogSettingChanged(feature.Id, setting.DisplayName(), obj);
			}
		}

		public unsafe static string FormatShortcut(KeyboardShortcut shortcut)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			if ((int)((KeyboardShortcut)(ref shortcut)).MainKey != 0)
			{
				return ((object)(*(KeyboardShortcut*)(&shortcut))/*cast due to .constrained prefix*/).ToString();
			}
			return "—";
		}

		private static GameObject CreateRow(Transform parent, float width, float height, string name)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_0070: 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_009c: Expected O, but got Unknown
			GameObject val = new GameObject(name, new Type[3]
			{
				typeof(RectTransform),
				typeof(LayoutElement),
				typeof(Image)
			});
			val.transform.SetParent(parent, false);
			val.GetComponent<RectTransform>().sizeDelta = new Vector2(width, height);
			LayoutElement component = val.GetComponent<LayoutElement>();
			component.minHeight = height;
			component.preferredHeight = height;
			component.flexibleWidth = 1f;
			Image component2 = val.GetComponent<Image>();
			((Graphic)component2).color = new Color(0f, 0f, 0f, 0.18f);
			((Graphic)component2).raycastTarget = false;
			return val;
		}

		private static void CreateStatusToggle(GUIManager gui, Transform parent, PanelFeature feature, Vector2 topLeft)
		{
			//IL_0039: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			Toggle component = gui.CreateToggle(parent, 22f, 22f).GetComponent<Toggle>();
			Transform transform = ((Component)component).transform;
			Transform obj = ((transform is RectTransform) ? transform : null);
			((RectTransform)obj).anchorMin = new Vector2(0f, 1f);
			((RectTransform)obj).anchorMax = new Vector2(0f, 1f);
			((RectTransform)obj).pivot = new Vector2(0f, 1f);
			((RectTransform)obj).anchoredPosition = topLeft;
			((RectTransform)obj).sizeDelta = new Vector2(22f, 22f);
			component.isOn = feature.Enabled.Value;
			((UnityEvent<bool>)(object)component.onValueChanged).AddListener((UnityAction<bool>)delegate(bool value)
			{
				if (feature.Enabled.Value != value)
				{
					feature.Enabled.Value = value;
					ControlPanel.LogSettingChanged(feature.Id, "Enabled", value);
					ControlPanel.RefreshOpenContent();
				}
			});
			((Graphic)CreateLabel(gui, parent, feature.Enabled.Value ? ModLang.Get("panel.on") : ModLang.Get("panel.off"), new Vector2(topLeft.x + 26f, topLeft.y), 40f, 22f, 13, gui.AveriaSerifBold, Color.white, (TextAnchor)3)).raycastTarget = false;
		}

		private static void PlaceSettingControl(GUIManager gui, Transform parent, PanelFeature feature, PanelSetting setting, float width)
		{
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Expected O, but got Unknown
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Expected O, but got Unknown
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			switch (setting.Kind)
			{
			case PanelSettingKind.Boolean:
			{
				Toggle component3 = gui.CreateToggle(parent, 22f, 22f).GetComponent<Toggle>();
				Transform transform5 = ((Component)component3).transform;
				Place((RectTransform)(object)((transform5 is RectTransform) ? transform5 : null), width + -96f, -16f, 22f, 22f);
				ConfigEntry<bool> val2 = (ConfigEntry<bool>)(object)setting.Entry;
				component3.isOn = val2.Value;
				((UnityEvent<bool>)(object)component3.onValueChanged).AddListener((UnityAction<bool>)delegate(bool value)
				{
					WriteEntry(feature, setting, value);
				});
				break;
			}
			case PanelSettingKind.Integer:
			case PanelSettingKind.Float:
			case PanelSettingKind.Text:
			{
				ContentType val = (ContentType)((setting.Kind == PanelSettingKind.Integer) ? 2 : ((setting.Kind == PanelSettingKind.Float) ? 3 : 0));
				InputField field = gui.CreateInputField(parent, Center, Center, Vector2.zero, val, (string)null, 14, 150f, 28f).GetComponent<InputField>();
				Transform transform4 = ((Component)field).transform;
				Place((RectTransform)(object)((transform4 is RectTransform) ? transform4 : null), width + -96f, -16f, 150f, 28f);
				field.text = setting.Entry.BoxedValue?.ToString() ?? string.Empty;
				((UnityEvent<string>)(object)field.onEndEdit).AddListener((UnityAction<string>)delegate(string text)
				{
					ApplyTextValue(feature, setting, field, text);
				});
				break;
			}
			case PanelSettingKind.Choice:
			{
				Dropdown component2 = gui.CreateDropDown(parent, Center, Center, Vector2.zero, 14, 160f, 28f).GetComponent<Dropdown>();
				Transform transform3 = ((Component)component2).transform;
				Place((RectTransform)(object)((transform3 is RectTransform) ? transform3 : null), width + -96f, -16f, 160f, 28f);
				PopulateChoices(component2, setting);
				((UnityEvent<int>)(object)component2.onValueChanged).AddListener((UnityAction<int>)delegate(int index)
				{
					if (index >= 0 && index < setting.Choices.Length)
					{
						WriteEntry(feature, setting, setting.Choices[index].Value);
					}
				});
				break;
			}
			case PanelSettingKind.Key:
			{
				Button keyButton = gui.CreateButton(FormatShortcut(((ConfigEntry<KeyboardShortcut>)(object)setting.Entry).Value), parent, Center, Center, Vector2.zero, 160f, 28f).GetComponent<Button>();
				Transform transform2 = ((Component)keyButton).transform;
				Place((RectTransform)(object)((transform2 is RectTransform) ? transform2 : null), width + -96f, -16f, 160f, 28f);
				((UnityEvent)keyButton.onClick).AddListener((UnityAction)delegate
				{
					ControlPanel.BeginKeyCapture((ConfigEntry<KeyboardShortcut>)(object)setting.Entry, keyButton);
				});
				break;
			}
			case PanelSettingKind.Action:
			{
				Button component = gui.CreateButton(setting.DisplayName(), parent, Center, Center, Vector2.zero, 160f, 28f).GetComponent<Button>();
				Transform transform = ((Component)component).transform;
				Place((RectTransform)(object)((transform is RectTransform) ? transform : null), width + -96f, -16f, 160f, 28f);
				((UnityEvent)component.onClick).AddListener((UnityAction)delegate
				{
					setting.Action?.Invoke();
					ControlPanel.LogSettingChanged(feature.Id, setting.DisplayName(), "action");
				});
				break;
			}
			}
		}

		private static void PopulateChoices(Dropdown dropdown, PanelSetting setting)
		{
			List<string> list = new List<string>();
			int value = 0;
			object boxedValue = setting.Entry.BoxedValue;
			for (int i = 0; i < setting.Choices.Length; i++)
			{
				PanelChoice panelChoice = setting.Choices[i];
				list.Add(panelChoice.Display());
				if (ValuesEqual(boxedValue, panelChoice.Value))
				{
					value = i;
				}
			}
			dropdown.ClearOptions();
			dropdown.AddOptions(list);
			dropdown.value = value;
			dropdown.RefreshShownValue();
		}

		private static void ApplyTextValue(PanelFeature feature, PanelSetting setting, InputField field, string text)
		{
			if (setting.Kind == PanelSettingKind.Integer)
			{
				if (int.TryParse(text, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result) || int.TryParse(text, NumberStyles.Integer, CultureInfo.CurrentCulture, out result))
				{
					WriteEntry(feature, setting, result);
				}
			}
			else if (setting.Kind == PanelSettingKind.Float)
			{
				if (float.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) || float.TryParse(text, NumberStyles.Float, CultureInfo.CurrentCulture, out result2))
				{
					WriteEntry(feature, setting, result2);
				}
			}
			else
			{
				WriteEntry(feature, setting, text ?? string.Empty);
			}
			field.text = setting.Entry.BoxedValue?.ToString() ?? string.Empty;
		}

		private static object BoxForEntry(ConfigEntryBase entry, object value)
		{
			Type settingType = entry.SettingType;
			if (settingType == typeof(bool))
			{
				return Convert.ToBoolean(value, CultureInfo.InvariantCulture);
			}
			if (settingType == typeof(int))
			{
				return Convert.ToInt32(value, CultureInfo.InvariantCulture);
			}
			if (settingType == typeof(float))
			{
				return Convert.ToSingle(value, CultureInfo.InvariantCulture);
			}
			if (settingType == typeof(string))
			{
				return value?.ToString() ?? string.Empty;
			}
			return value;
		}

		private static object ClampToAcceptable(ConfigEntryBase entry, object value)
		{
			ConfigDescription description = entry.Description;
			if (((description != null) ? description.AcceptableValues : null) is AcceptableValueRange<int> val && value is int num)
			{
				return Mathf.Clamp(num, val.MinValue, val.MaxValue);
			}
			ConfigDescription description2 = entry.Description;
			if (((description2 != null) ? description2.AcceptableValues : null) is AcceptableValueRange<float> val2 && value is float num2)
			{
				return Mathf.Clamp(num2, val2.MinValue, val2.MaxValue);
			}
			return value;
		}

		private static bool ValuesEqual(object left, object right)
		{
			if (left == null || right == null)
			{
				return left == right;
			}
			if (left is string || right is string)
			{
				return string.Equals(Convert.ToString(left, CultureInfo.InvariantCulture), Convert.ToString(right, CultureInfo.InvariantCulture), StringComparison.OrdinalIgnoreCase);
			}
			return left.Equals(Convert.ChangeType(right, left.GetType(), CultureInfo.InvariantCulture));
		}
	}
	internal static class GameClock
	{
		private static GameObject root;

		private static Text label;

		public static void Refresh()
		{
			if ((Object)(object)label == (Object)null || (Object)(object)EnvMan.instance == (Object)null)
			{
				return;
			}
			bool value = QoLConfig.EnableGameClock.Value;
			bool value2 = QoLConfig.EnableLocalClock.Value;
			if (!value && !value2)
			{
				if (Object.op_Implicit((Object)(object)root))
				{
					root.SetActive(false);
				}
				return;
			}
			if (Object.op_Implicit((Object)(object)root))
			{
				root.SetActive(true);
			}
			string text = "";
			if (value)
			{
				int currentDay = EnvMan.instance.GetCurrentDay();
				text = string.Format("{0} {1}  {2}", ModLang.Get("clock.day"), currentDay, FormatTime(GameHour(), GameMinute()));
			}
			if (value2)
			{
				DateTime now = DateTime.Now;
				string text2 = FormatTime(now.Hour, now.Minute);
				string text3 = ModLang.Get("clock.local");
				text = ((text.Length == 0) ? (text3 + " " + text2) : (text + "\n" + text3 + " " + text2));
			}
			label.text = text;
		}

		private static int GameHour()
		{
			return Mathf.FloorToInt(EnvMan.instance.GetDayFraction() * 24f);
		}

		private static int GameMinute()
		{
			float num = EnvMan.instance.GetDayFraction() * 24f;
			int num2 = Mathf.FloorToInt(num);
			return Mathf.FloorToInt((num - (float)num2) * 60f);
		}

		private static string FormatTime(int hour24, int minute)
		{
			int num = Mathf.Clamp(hour24, 0, 23);
			minute = Mathf.Clamp(minute, 0, 59);
			if (QoLConfig.Clock24Hour.Value)
			{
				return $"{num:00}:{minute:00}";
			}
			string arg = ((num >= 12) ? "PM" : "AM");
			int num2 = num % 12;
			if (num2 == 0)
			{
				num2 = 12;
			}
			return $"{num2}:{minute:00} {arg}";
		}

		internal static void Ensure(Minimap minimap)
		{
			//IL_0048: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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)
			if (!((Object)(object)minimap?.m_smallRoot == (Object)null) && GUIManager.Instance != null && !Object.op_Implicit((Object)(object)root))
			{
				root = GUIManager.Instance.CreateText("", minimap.m_smallRoot.transform, new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), new Vector2(0f, -14f), GUIManager.Instance.AveriaSerif, 16, GUIManager.Instance.ValheimOrange, true, Color.black, 220f, 40f, false);
				label = root.GetComponent<Text>();
				if ((Object)(object)label == (Object)null)
				{
					label = root.GetComponentInChildren<Text>();
				}
				if ((Object)(object)label != (Object)null)
				{
					label.alignment = (TextAnchor)1;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Minimap), "Awake")]
	internal static class GameClockMinimapAwakePatch
	{
		private static void Postfix(Minimap __instance)
		{
			GameClock.Ensure(__instance);
		}
	}
	[HarmonyPatch(typeof(Minimap), "Update")]
	internal static class GameClockMinimapUpdatePatch
	{
		private static void Postfix(Minimap __instance)
		{
			GameClock.Ensure(__instance);
			GameClock.Refresh();
		}
	}
	internal static class PortalConfigUI
	{
		private const int LayoutVersion = 2;

		private const float PanelWidth = 540f;

		private const float PanelHeight = 400f;

		private const float LabelWidth = 140f;

		private const float LabelRightX = -105f;

		private const float FieldLeftX = -95f;

		private const float FieldWidth = 320f;

		private const float FieldHeight = 34f;

		private const float TitleY = 150f;

		private const float NameRowY = 85f;

		private const float DestinationRowY = 35f;

		private const float DefaultRowY = -15f;

		private const float FooterY = -140f;

		private const float FooterButtonWidth = 140f;

		private static readonly Vector2 CenterAnchor;

		private static GameObject root;

		private static InputField nameField;

		private static Dropdown destDropdown;

		private static Toggle defaultToggle;

		private static TeleportWorld currentPortal;

		private static readonly List<string> destIds;

		private static int builtLayoutVersion;

		public static bool IsOpen
		{
			get
			{
				if ((Object)(object)root != (Object)null)
				{
					return root.activeSelf;
				}
				return false;
			}
		}

		static PortalConfigUI()
		{
			//IL_000a: 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)
			CenterAnchor = new Vector2(0.5f, 0.5f);
			destIds = new List<string>();
			GUIManager.OnCustomGUIAvailable += EnsureUi;
		}

		public static void Show(TeleportWorld portal)
		{
			if (!((Object)(object)portal == (Object)null) && GUIManager.Instance != null)
			{
				EnsureUi();
				if (!((Object)(object)root == (Object)null))
				{
					currentPortal = portal;
					PortalNetwork.ScanWorldPortals();
					PortalNetwork.Register(portal);
					PopulateFields();
					root.SetActive(true);
					GUIManager.BlockInput(true);
				}
			}
		}

		public static void Cancel()
		{
			Close(_: false);
		}

		public static void Confirm()
		{
			if ((Object)(object)currentPortal == (Object)null)
			{
				Close(_: false);
				return;
			}
			string destId = ((destIds.Count > 0 && destDropdown.value >= 0 && destDropdown.value < destIds.Count) ? destIds[destDropdown.value] : null);
			string name = (((Object)(object)nameField != (Object)null) ? nameField.text : string.Empty);
			bool defaultPortal = (Object)(object)defaultToggle != (Object)null && defaultToggle.isOn;
			PortalNetwork.ApplyConfig(currentPortal, name, destId, defaultPortal, markDestFavorite: false);
			Close(_: true);
		}

		private static void Close(bool _)
		{
			if ((Object)(object)root != (Object)null)
			{
				root.SetActive(false);
			}
			GUIManager.BlockInput(false);
			currentPortal = null;
		}

		private static void EnsureUi()
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: 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_017f: 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_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Expected O, but got Unknown
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Expected O, but got Unknown
			if ((Object)(object)root != (Object)null && builtLayoutVersion >= 2)
			{
				return;
			}
			if ((Object)(object)root != (Object)null)
			{
				Object.Destroy((Object)(object)root);
				root = null;
				nameField = null;
				destDropdown = null;
				defaultToggle = null;
			}
			GameObject customGUIFront = GUIManager.CustomGUIFront;
			if (!((Object)(object)customGUIFront == (Object)null))
			{
				GUIManager instance = GUIManager.Instance;
				root = instance.CreateWoodpanel(customGUIFront.transform, CenterAnchor, CenterAnchor, Vector2.zero, 540f, 400f, false);
				Text component = instance.CreateText(ModLang.Get("portal.ui.title"), root.transform, CenterAnchor, CenterAnchor, new Vector2(0f, 150f), instance.AveriaSerifBold, 22, instance.ValheimOrange, true, Color.black, 500f, 36f, false).GetComponent<Text>();
				if ((Object)(object)component != (Object)null)
				{
					component.alignment = (TextAnchor)4;
				}
				CreateLabel(instance, ModLang.Get("portal.ui.name"), 85f);
				nameField = instance.CreateInputField(root.transform, CenterAnchor, CenterAnchor, Vector2.zero, (ContentType)0, (string)null, 16, 320f, 34f).GetComponent<InputField>();
				PlaceControl(((Component)nameField).GetComponent<RectTransform>(), -95f, 85f, 320f, 34f, leftAlign: true);
				CreateLabel(instance, ModLang.Get("portal.ui.destination"), 35f);
				destDropdown = instance.CreateDropDown(root.transform, CenterAnchor, CenterAnchor, Vector2.zero, 16, 320f, 34f).GetComponent<Dropdown>();
				PlaceControl(((Component)destDropdown).GetComponent<RectTransform>(), -95f, 35f, 320f, 34f, leftAlign: true);
				CreateLabel(instance, ModLang.Get("portal.ui.default"), -15f);
				defaultToggle = instance.CreateToggle(root.transform, 28f, 28f).GetComponent<Toggle>();
				PlaceControl(((Component)defaultToggle).GetComponent<RectTransform>(), -95f, -15f, 28f, 28f, leftAlign: true);
				Button component2 = instance.CreateButton(ModLang.Get("portal.ui.cancel"), root.transform, CenterAnchor, CenterAnchor, new Vector2(-90f, -140f), 140f, 40f).GetComponent<Button>();
				PlaceControl(((Component)component2).GetComponent<RectTransform>(), -90f, -140f, 140f, 40f);
				((UnityEvent)component2.onClick).AddListener(new UnityAction(Cancel));
				Button component3 = instance.CreateButton(ModLang.Get("portal.ui.ok"), root.transform, CenterAnchor, CenterAnchor, new Vector2(90f, -140f), 140f, 40f).GetComponent<Button>();
				PlaceControl(((Component)component3).GetComponent<RectTransform>(), 90f, -140f, 140f, 40f);
				((UnityEvent)component3.onClick).AddListener(new UnityAction(Confirm));
				builtLayoutVersion = 2;
				root.SetActive(false);
			}
		}

		private static void CreateLabel(GUIManager gui, string text, float rowY)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = gui.CreateText(text, root.transform, CenterAnchor, CenterAnchor, Vector2.zero, gui.AveriaSerif, 16, Color.white, true, Color.black, 140f, 30f, false);
			Text component = obj.GetComponent<Text>();
			if ((Object)(object)component != (Object)null)
			{
				component.alignment = (TextAnchor)5;
			}
			PlaceControl(obj.GetComponent<RectTransform>(), -105f, rowY, 140f, 30f, leftAlign: false, rightAlign: true);
		}

		private static void PlaceControl(RectTransform rect, float x, float y, float width, float height, bool leftAlign = false, bool rightAlign = false)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)rect == (Object)null))
			{
				rect.anchorMin = CenterAnchor;
				rect.anchorMax = CenterAnchor;
				rect.pivot = (rightAlign ? new Vector2(1f, 0.5f) : (leftAlign ? new Vector2(0f, 0.5f) : new Vector2(0.5f, 0.5f)));
				rect.anchoredPosition = new Vector2(x, y);
				rect.sizeDelta = new Vector2(width, height);
			}
		}

		private static void PopulateFields()
		{
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			string id = PortalNetwork.IdOf(currentPortal);
			PortalRec portalRec = PortalNetwork.Find(id);
			if ((Object)(object)nameField != (Object)null)
			{
				nameField.text = portalRec?.Name ?? currentPortal.GetText() ?? "Portal";
			}
			if ((Object)(object)defaultToggle != (Object)null)
			{
				defaultToggle.isOn = portalRec?.Favorite ?? false;
			}
			destIds.Clear();
			List<string> list = new List<string>();
			PortalRec portalRec2 = portalRec ?? new PortalRec
			{
				Id = id,
				X = ((Component)currentPortal).transform.position.x,
				Y = ((Component)currentPortal).transform.position.y,
				Z = ((Component)currentPortal).transform.position.z
			};
			foreach (PortalRec item in PortalNetwork.AllExcept(id))
			{
				destIds.Add(item.Id);
				list.Add(PortalNetwork.FormatPortalLabel(item) + " (" + PortalNetwork.FormatDistance(portalRec2, item) + ")");
			}
			if (!((Object)(object)destDropdown != (Object)null))
			{
				return;
			}
			destDropdown.ClearOptions();
			if (list.Count == 0)
			{
				list.Add(ModLang.Get("portal.ui.no_destination"));
				destIds.Add(string.Empty);
			}
			destDropdown.AddOptions(list);
			destDropdown.value = 0;
			List<PortalRec> list2 = PortalNetwork.DestinationsOf(id);
			if (list2.Count > 0)
			{
				int num = destIds.IndexOf(list2[0].Id);
				if (num >= 0)
				{
					destDropdown.value = num;
				}
			}
			destDropdown.RefreshShownValue();
		}
	}
	[HarmonyPatch(typeof(Player), "Update")]
	internal static class PortalConfigUiUpdatePatch
	{
		private static void Postfix()
		{
			if (PortalConfigUI.IsOpen && ExtraConfig.EnablePortals.Value && Input.GetKeyDown((KeyCode)27))
			{
				PortalConfigUI.Cancel();
			}
		}
	}
	internal static class TrashPanel
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__35_0;

			public static UnityAction <>9__35_1;

			internal void <EnsureUi>b__35_0()
			{
				SetAll(value: true);
			}

			internal void <EnsureUi>b__35_1()
			{
				SetAll(value: false);
			}
		}

		private const float PanelWidth = 600f;

		private const float PanelHeight = 480f;

		private const float TitleY = 210f;

		private const float ListWidth = 540f;

		private const float ListHeight = 330f;

		private const float ListCenterY = 5f;

		private const float RowHeight = 40f;

		private const float FooterY = -200f;

		private const float FooterButtonWidth = 140f;

		private const float FooterButtonHeight = 40f;

		private static readonly Vector2 CenterAnchor;

		private static readonly Color ListBackground;

		private static GameObject root;

		private static RectTransform content;

		private static ScrollRect scroll;

		private static Text emptyText;

		private static Text deleteLabel;

		private static Button deleteButton;

		private static readonly List<ItemData> listed;

		private static readonly List<Toggle> toggles;

		private static readonly HashSet<ItemData> marked;

		private static bool refreshing;

		public static bool IsOpen
		{
			get
			{
				if ((Object)(object)root != (Object)null)
				{
					return root.activeSelf;
				}
				return false;
			}
		}

		static TrashPanel()
		{
			//IL_000a: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			CenterAnchor = new Vector2(0.5f, 0.5f);
			ListBackground = new Color(0f, 0f, 0f, 0.35f);
			listed = new List<ItemData>();
			toggles = new List<Toggle>();
			marked = new HashSet<ItemData>();
			GUIManager.OnCustomGUIAvailable += EnsureUi;
		}

		public static void Show()
		{
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null) && GUIManager.Instance != null)
			{
				EnsureUi();
				if (!((Object)(object)root == (Object)null))
				{
					Populate(localPlayer);
					root.SetActive(true);
					GUIManager.BlockInput(true);
				}
			}
		}

		public static void Close()
		{
			if (!((Object)(object)root == (Object)null) && root.activeSelf)
			{
				root.SetActive(false);
				GUIManager.BlockInput(false);
				marked.Clear();
				listed.Clear();
			}
		}

		private static void Confirm()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || marked.Count == 0)
			{
				Close();
				return;
			}
			Inventory inventory = ((Humanoid)localPlayer).GetInventory();
			int num = 0;
			foreach (ItemData item in new List<ItemData>(marked))
			{
				if (item != null && !Favorites.IsProtected(item) && inventory.ContainsItem(item))
				{
					InventoryUi.RemoveItemFromInventory(localPlayer, inventory, item, item.m_stack);
					num++;
				}
			}
			if (num > 0)
			{
				inventory.Changed(false, false);
				if ((Object)(object)InventoryGui.instance != (Object)null)
				{
					InventoryGui.instance.UpdateCraftingPanel(false);
				}
				((Character)localPlayer).Message((MessageType)1, string.Format(ModLang.Get("inventory.trash_destroyed_many"), num), 0, (Sprite)null, false);
			}
			Close();
		}

		private static void SetAll(bool value)
		{
			refreshing = true;
			foreach (Toggle toggle in toggles)
			{
				toggle.isOn = value;
			}
			refreshing = false;
			marked.Clear();
			if (value)
			{
				foreach (ItemData item in listed)
				{
					marked.Add(item);
				}
			}
			RefreshDeleteButton();
		}

		private static void RefreshDeleteButton()
		{
			if ((Object)(object)deleteLabel != (Object)null)
			{
				deleteLabel.text = string.Format(ModLang.Get("trash.panel.delete"), marked.Count);
			}
			if ((Object)(object)deleteButton != (Object)null)
			{
				((Selectable)deleteButton).interactable = marked.Count > 0;
			}
		}

		private static void Populate(Player player)
		{
			for (int num = ((Transform)content).childCount - 1; num >= 0; num--)
			{
				Object.Destroy((Object)(object)((Component)((Transform)content).GetChild(num)).gameObject);
			}
			toggles.Clear();
			listed.Clear();
			marked.Clear();
			foreach (ItemData allItem in ((Humanoid)player).GetInventory().GetAllItems())
			{
				if (allItem != null && !Favorites.IsProtected(allItem))
				{
					listed.Add(allItem);
				}
			}
			GUIManager instance = GUIManager.Instance;
			foreach (ItemData item in listed)
			{
				BuildRow(instance, item);
			}
			((Component)emptyText).gameObject.SetActive(listed.Count == 0);
			scroll.verticalNormalizedPosition = 1f;
			RefreshDeleteButton();
		}

		private static void BuildRow(GUIManager gui, ItemData item)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: 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_0152: Expected O, but got Unknown
			GameObject val = new GameObject("TrashRow", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent((Transform)(object)content, false);
			LayoutElement obj = val.AddComponent<LayoutElement>();
			obj.preferredHeight = 40f;
			obj.minHeight = 40f;
			HorizontalLayoutGroup obj2 = val.AddComponent<HorizontalLayoutGroup>();
			((LayoutGroup)obj2).padding = new RectOffset(10, 10, 4, 4);
			((HorizontalOrVerticalLayoutGroup)obj2).spacing = 10f;
			((LayoutGroup)obj2).childAlignment = (TextAnchor)3;
			((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = false;
			((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = false;
			Toggle component = gui.CreateToggle(val.transform, 28f, 28f).GetComponent<Toggle>();
			SetSize(((Component)component).gameObject, 28f, 28f);
			component.isOn = false;
			ItemData captured = item;
			((UnityEvent<bool>)(object)component.onValueChanged).AddListener((UnityAction<bool>)delegate(bool isOn)
			{
				if (!refreshing)
				{
					if (isOn)
					{
						marked.Add(captured);
					}
					else
					{
						marked.Remove(captured);
					}
					RefreshDeleteButton();
				}
			});
			toggles.Add(component);
			GameObject val2 = new GameObject("Icon", new Type[1] { typeof(RectTransform) });
			val2.transform.SetParent(val.transform, false);
			Image obj3 = val2.AddComponent<Image>();
			obj3.sprite = item.GetIcon();
			obj3.preserveAspect = true;
			((Graphic)obj3).raycastTarget = false;
			SetSize(val2, 32f, 32f);
			LayoutElement obj4 = ((Component)CreateRowText(gui, val.transform, Localize(item.m_shared.m_name), (TextAnchor)3)).gameObject.AddComponent<LayoutElement>();
			obj4.flexibleWidth = 1f;
			obj4.minWidth = 100f;
			SetSize(((Component)CreateRowText(gui, val.transform, "x" + item.m_stack, (TextAnchor)5)).gameObject, 70f, 30f);
		}

		private static string Localize(string key)
		{
			if (Localization.instance == null)
			{
				return key;
			}
			return Localization.instance.Localize(key);
		}

		private static void SetSize(GameObject go, float width, float height)
		{
			LayoutElement obj = go.GetComponent<LayoutElement>() ?? go.AddComponent<LayoutElement>();
			obj.preferredWidth = width;
			obj.minWidth = width;
			obj.preferredHeight = height;
			obj.minHeight = height;
		}

		private static Text CreateRowText(GUIManager gui, Transform parent, string value, TextAnchor anchor)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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)
			GameObject val = new GameObject("Text", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			Text obj = val.AddComponent<Text>();
			obj.font = gui.AveriaSerif;
			obj.fontSize = 16;
			((Graphic)obj).color = Color.white;