Decompiled source of Krool World UI v0.9.3

KroolWorldUI.dll

Decompiled 21 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using KroolWorldUI.Features;
using Microsoft.CodeAnalysis;
using Splatform;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("SettingsDoc")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("KroolWorldUI")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.9.3.0")]
[assembly: AssemblyInformationalVersion("0.9.3+468a43211becd74f0aa53a4308a621d9fb4c2032")]
[assembly: AssemblyProduct("KroolWorldUI")]
[assembly: AssemblyTitle("KroolWorldUI")]
[assembly: AssemblyVersion("0.9.3.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace KroolWorldUI
{
	internal static class ConfigText
	{
		internal sealed class Hidden
		{
			internal static readonly Hidden Tag = new Hidden();
		}

		internal static bool IsHidden(ConfigEntryBase entry)
		{
			ConfigDescription description = entry.Description;
			if (description == null)
			{
				return false;
			}
			return description.Tags?.Any((object t) => t is Hidden) == true;
		}

		internal static string Pretty(string key)
		{
			return Regex.Replace(key, "(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])", " ");
		}

		internal static string Value(object value)
		{
			//IL_002b: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			if (!(value is bool))
			{
				if (!(value is float num))
				{
					if (!(value is Color c))
					{
						if (!(value is Enum obj))
						{
							if (value == null)
							{
								return "";
							}
							return value.ToString();
						}
						return Pretty(obj.ToString());
					}
					return Hex(c);
				}
				return num.ToString("0.###", CultureInfo.InvariantCulture);
			}
			if (!(bool)value)
			{
				return "Off";
			}
			return "On";
		}

		internal static string Options(ConfigEntryBase entry)
		{
			ConfigDescription description = entry.Description;
			AcceptableValueBase val = ((description != null) ? description.AcceptableValues : null);
			if (!(val is AcceptableValueRange<float> val2))
			{
				if (val is AcceptableValueRange<int> val3)
				{
					return $"{val3.MinValue} to {val3.MaxValue}";
				}
				if (entry.SettingType.IsEnum)
				{
					return string.Join(", ", Enum.GetNames(entry.SettingType).Select(Pretty));
				}
				if (entry.SettingType == typeof(Color))
				{
					return "Hex RRGGBBAA (AA = opacity)";
				}
				if (entry.SettingType == typeof(KeyboardShortcut))
				{
					return "Any key";
				}
				return "";
			}
			return Value(val2.MinValue) + " to " + Value(val2.MaxValue);
		}

		internal static string Tooltip(ConfigEntryBase entry)
		{
			ConfigDescription description = entry.Description;
			string text = ((description != null) ? description.Description : null) ?? "";
			text = text + "\n\nDefault: " + Value(entry.DefaultValue);
			string text2 = Options(entry);
			ConfigDescription description2 = entry.Description;
			if (((description2 != null) ? description2.AcceptableValues : null) != null)
			{
				text = text + "    Range: " + text2;
			}
			else if (entry.SettingType == typeof(Color))
			{
				text += "    (hex RRGGBBAA, AA = opacity)";
			}
			return text.Trim();
		}

		internal static string Hex(Color c)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			return $"{B(c.r):X2}{B(c.g):X2}{B(c.b):X2}{B(c.a):X2}";
			static int B(float v)
			{
				return Mathf.Clamp(Mathf.RoundToInt(v * 255f), 0, 255);
			}
		}
	}
	[BepInPlugin("krool.kroolworldui", "Krool World UI", "0.9.3")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "krool.kroolworldui";

		public const string Name = "Krool World UI";

		public const string Version = "0.9.3";

		public const string Flavor = "";

		internal static Plugin Instance;

		internal static ManualLogSource Log;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			BindAll(((BaseUnityPlugin)this).Config);
			((Component)this).gameObject.AddComponent<SettingsWindow>();
			_harmony = new Harmony("krool.kroolworldui");
			_harmony.PatchAll(typeof(Plugin).Assembly);
			Log.LogInfo((object)"Krool World UI 0.9.3 loaded");
		}

		internal static void BindAll(ConfigFile config)
		{
			SettingsWindow.BindConfig(config);
			SkillXpBars.BindConfig(config);
			WeightDisplay.BindConfig(config);
			FoodDecay.BindConfig(config);
			FoodCallout.BindConfig(config);
			BuildMaterials.BindConfig(config);
			DayNightBar.BindConfig(config);
			RestedCountdown.BindConfig(config);
			SaveCountdown.BindConfig(config);
			BenchPins.BindConfig(config);
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	internal class SettingsWindow : MonoBehaviour
	{
		private class Styles
		{
			public readonly GUIStyle Window;

			public readonly GUIStyle Header;

			public readonly GUIStyle HeaderButton;

			public readonly GUIStyle Label;

			public readonly GUIStyle Value;

			public readonly GUIStyle Hint;

			public readonly GUIStyle Tooltip;

			public readonly GUIStyle Button;

			public readonly GUIStyle Small;

			public readonly GUIStyle Slider;

			public readonly GUIStyle Thumb;

			public readonly GUIStyle Field;

			public readonly Texture2D RowHover;

			public readonly Texture2D ArrowRight;

			public readonly Texture2D ArrowDown;

			private static readonly Color Wood = new Color(0.13f, 0.09f, 0.06f, 0.96f);

			private static readonly Color WoodLight = new Color(0.24f, 0.17f, 0.11f, 1f);

			private static readonly Color WoodHover = new Color(0.33f, 0.24f, 0.15f, 1f);

			private static readonly Color Gold = new Color(0.87f, 0.7f, 0.36f, 1f);

			private static readonly Color Parchment = new Color(0.92f, 0.87f, 0.78f, 1f);

			private static readonly Color Muted = new Color(0.7f, 0.64f, 0.55f, 1f);

			public Styles()
			{
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_002b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0032: 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_0045: Expected O, but got Unknown
				//IL_0045: 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_0054: Expected O, but got Unknown
				//IL_0054: Unknown result type (might be due to invalid IL or missing references)
				//IL_005b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: 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_0077: Unknown result type (might be due to invalid IL or missing references)
				//IL_0083: Expected O, but got Unknown
				//IL_0089: 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_0098: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b7: Expected O, but got Unknown
				//IL_00b7: 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_00c6: Expected O, but got Unknown
				//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d5: Expected O, but got Unknown
				//IL_00da: Expected O, but got Unknown
				//IL_00f9: 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_0125: Unknown result type (might be due to invalid IL or missing references)
				//IL_014c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0156: Expected O, but got Unknown
				//IL_016d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0182: Unknown result type (might be due to invalid IL or missing references)
				//IL_0190: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c0: 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_0220: Unknown result type (might be due to invalid IL or missing references)
				//IL_0248: Unknown result type (might be due to invalid IL or missing references)
				//IL_0252: Expected O, but got Unknown
				//IL_025c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0266: Expected O, but got Unknown
				//IL_0285: Unknown result type (might be due to invalid IL or missing references)
				//IL_028a: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a9: 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_02bd: Expected O, but got Unknown
				//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
				//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
				//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
				//IL_0306: Unknown result type (might be due to invalid IL or missing references)
				//IL_030b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0339: Unknown result type (might be due to invalid IL or missing references)
				//IL_033e: Unknown result type (might be due to invalid IL or missing references)
				//IL_036c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0371: Unknown result type (might be due to invalid IL or missing references)
				//IL_038a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0394: Expected O, but got Unknown
				//IL_039b: Unknown result type (might be due to invalid IL or missing references)
				//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
				//IL_03ad: Expected O, but got Unknown
				//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_03c2: Expected O, but got Unknown
				//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
				//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
				//IL_03fc: Unknown result type (might be due to invalid IL or missing references)
				//IL_0406: Expected O, but got Unknown
				//IL_0411: Unknown result type (might be due to invalid IL or missing references)
				//IL_041b: Expected O, but got Unknown
				//IL_0426: Unknown result type (might be due to invalid IL or missing references)
				//IL_042b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0445: Unknown result type (might be due to invalid IL or missing references)
				//IL_044a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0464: Unknown result type (might be due to invalid IL or missing references)
				//IL_0469: Unknown result type (might be due to invalid IL or missing references)
				//IL_04a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_04ad: Expected O, but got Unknown
				//IL_04b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_04bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
				//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_04d8: Expected O, but got Unknown
				//IL_04de: Unknown result type (might be due to invalid IL or missing references)
				//IL_04e3: Unknown result type (might be due to invalid IL or missing references)
				//IL_04ed: Unknown result type (might be due to invalid IL or missing references)
				//IL_0513: Unknown result type (might be due to invalid IL or missing references)
				//IL_0514: Unknown result type (might be due to invalid IL or missing references)
				Font font = FindValheimFont();
				Window = new GUIStyle(GUI.skin.window)
				{
					font = font,
					fontSize = 22,
					fontStyle = (FontStyle)1,
					padding = new RectOffset(16, 16, 50, 14),
					border = new RectOffset(4, 4, 4, 4),
					alignment = (TextAnchor)1,
					contentOffset = new Vector2(0f, -40f),
					wordWrap = false,
					clipping = (TextClipping)1
				};
				SetAll(Window, Tex(Wood, Gold), Gold);
				Header = new GUIStyle
				{
					padding = new RectOffset(0, 6, 3, 3),
					margin = new RectOffset(0, 0, 2, 2),
					border = new RectOffset(2, 2, 2, 2)
				};
				Header.normal.background = Tex(new Color(0.19f, 0.13f, 0.08f, 1f), new Color(0.45f, 0.35f, 0.18f, 1f));
				HeaderButton = Text(font, 19, Gold, (FontStyle)1);
				HeaderButton.alignment = (TextAnchor)3;
				HeaderButton.padding = new RectOffset(28, 4, 0, 0);
				HeaderButton.richText = true;
				HeaderButton.hover.textColor = Parchment;
				HeaderButton.active.textColor = Parchment;
				Label = Text(font, 16, Parchment, (FontStyle)0);
				Label.alignment = (TextAnchor)3;
				Label.fixedHeight = 26f;
				Value = Text(font, 16, Gold, (FontStyle)0);
				Value.alignment = (TextAnchor)5;
				Value.fixedHeight = 26f;
				Hint = Text(font, 14, Muted, (FontStyle)0);
				Hint.alignment = (TextAnchor)3;
				Hint.fixedHeight = 24f;
				Tooltip = Text(font, 15, Parchment, (FontStyle)0);
				Tooltip.wordWrap = true;
				Tooltip.padding = new RectOffset(10, 10, 8, 8);
				Tooltip.border = new RectOffset(2, 2, 2, 2);
				Tooltip.normal.background = Tex(new Color(0.08f, 0.055f, 0.035f, 0.98f), Gold);
				Button = new GUIStyle(GUI.skin.button)
				{
					font = font,
					fontSize = 16
				};
				SetAll(Button, Tex(WoodLight, Gold), Parchment);
				Button.hover.background = Tex(WoodHover, Gold);
				Button.active.background = Tex(Gold, Gold);
				Button.onNormal.background = Tex(new Color(0.45f, 0.33f, 0.16f, 1f), Gold);
				Button.onHover.background = Tex(new Color(0.52f, 0.39f, 0.2f, 1f), Gold);
				Button.border = new RectOffset(2, 2, 2, 2);
				Small = new GUIStyle(Button)
				{
					fontSize = 13
				};
				Slider = new GUIStyle(GUI.skin.horizontalSlider);
				Slider.normal.background = Tex(WoodLight, WoodLight);
				Slider.fixedHeight = 6f;
				Slider.margin = new RectOffset(4, 4, 11, 4);
				Thumb = new GUIStyle(GUI.skin.horizontalSliderThumb);
				Thumb.normal.background = Tex(Gold, Gold);
				Thumb.hover.background = Tex(Parchment, Parchment);
				Thumb.active.background = Tex(Parchment, Parchment);
				Thumb.fixedWidth = 12f;
				Thumb.fixedHeight = 18f;
				Thumb.margin = new RectOffset(0, 0, -6, 0);
				Field = new GUIStyle(GUI.skin.textField)
				{
					font = font,
					fontSize = 16,
					alignment = (TextAnchor)3
				};
				SetAll(Field, Tex(Wood, Gold), Parchment);
				Color val = default(Color);
				((Color)(ref val))..ctor(1f, 0.85f, 0.55f, 0.07f);
				RowHover = Tex(val, val);
				ArrowRight = Arrow(down: false);
				ArrowDown = Arrow(down: true);
			}

			private static GUIStyle Text(Font font, int size, Color color, FontStyle style = (FontStyle)0)
			{
				//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_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: 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_002b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Expected O, but got Unknown
				GUIStyle val = new GUIStyle(GUI.skin.label)
				{
					font = font,
					fontSize = size,
					fontStyle = style,
					wordWrap = false,
					clipping = (TextClipping)1
				};
				val.normal.textColor = color;
				return val;
			}

			private static void SetAll(GUIStyle s, Texture2D bg, Color text)
			{
				//IL_0068: Unknown result type (might be due to invalid IL or missing references)
				GUIStyleState[] array = (GUIStyleState[])(object)new GUIStyleState[8] { s.normal, s.hover, s.active, s.focused, s.onNormal, s.onHover, s.onActive, s.onFocused };
				foreach (GUIStyleState val in array)
				{
					if ((Object)(object)bg != (Object)null)
					{
						val.background = bg;
					}
					val.textColor = text;
				}
			}

			private static Texture2D Tex(Color fill, Color border)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Expected O, but got Unknown
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				Texture2D val = new Texture2D(8, 8)
				{
					hideFlags = (HideFlags)61,
					filterMode = (FilterMode)0
				};
				Color[] array = (Color[])(object)new Color[64];
				for (int i = 0; i < 8; i++)
				{
					for (int j = 0; j < 8; j++)
					{
						array[i * 8 + j] = ((j == 0 || i == 0 || j == 7 || i == 7) ? border : fill);
					}
				}
				val.SetPixels(array);
				val.Apply();
				return val;
			}

			private static Texture2D Arrow(bool down)
			{
				//IL_0004: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: 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_0019: Expected O, but got Unknown
				//IL_0090: 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_0095: Unknown result type (might be due to invalid IL or missing references)
				Texture2D val = new Texture2D(24, 24)
				{
					hideFlags = (HideFlags)61,
					filterMode = (FilterMode)1
				};
				Color[] array = (Color[])(object)new Color[576];
				for (int i = 0; i < 24; i++)
				{
					for (int j = 0; j < 24; j++)
					{
						float num = (down ? (23 - i) : j);
						float num2 = (down ? j : i);
						float num3 = (19f - num) * 0.5f;
						bool flag = num >= 5f && num <= 19f && Mathf.Abs(num2 - 11.5f) <= num3;
						array[i * 24 + j] = (flag ? Gold : Color.clear);
					}
				}
				val.SetPixels(array);
				val.Apply();
				return val;
			}

			private static Font FindValheimFont()
			{
				Font[] source = Resources.FindObjectsOfTypeAll<Font>();
				return ((IEnumerable<Font>)source).FirstOrDefault((Func<Font, bool>)((Font f) => ((Object)f).name == "AveriaSerifLibre-Bold")) ?? ((IEnumerable<Font>)source).FirstOrDefault((Func<Font, bool>)((Font f) => ((Object)f).name.StartsWith("AveriaSerifLibre"))) ?? GUI.skin.font;
			}
		}

		[HarmonyPatch(typeof(PlayerController), "TakeInput")]
		private static class BlockControllerInput
		{
			private static void Postfix(ref bool __result)
			{
				if (IsOpen)
				{
					__result = false;
				}
			}
		}

		[HarmonyPatch(typeof(Player), "TakeInput")]
		private static class BlockPlayerInput
		{
			private static void Postfix(ref bool __result)
			{
				if (IsOpen)
				{
					__result = false;
				}
			}
		}

		[HarmonyPatch(typeof(ZInput), "GetMouseScrollWheel")]
		private static class BlockScrollWheel
		{
			private static void Postfix(ref float __result)
			{
				if (IsOpen)
				{
					__result = 0f;
				}
			}
		}

		[HarmonyPatch(typeof(GameCamera), "UpdateMouseCapture")]
		private static class FreeCursor
		{
			private static void Postfix()
			{
				if (IsOpen)
				{
					Cursor.lockState = (CursorLockMode)0;
					Cursor.visible = true;
				}
			}
		}

		[HarmonyPatch(typeof(Menu), "Update")]
		private static class SwallowEscape
		{
			private static bool Prefix()
			{
				return !IsOpen;
			}
		}

		internal static ConfigEntry<KeyboardShortcut> ToggleKey;

		private static ConfigEntry<string> ExpandedSections;

		private const int WindowId = 1264014665;

		private const float RefHeight = 1080f;

		private const float LabelWidth = 180f;

		private const float ControlHeight = 26f;

		private const float TooltipDelay = 0.35f;

		private const float TooltipWidth = 340f;

		private const float TitleBand = 46f;

		private const float ResetWidth = 56f;

		private const float ScrollbarWidth = 22f;

		private Rect _window = new Rect(80f, 80f, 540f, 700f);

		private Vector2 _scroll;

		private ConfigEntryBase _capturingKey;

		private readonly Dictionary<ConfigEntryBase, string> _colorEdits = new Dictionary<ConfigEntryBase, string>();

		private readonly HashSet<string> _expanded = new HashSet<string>();

		private bool _preview;

		private bool _previewWas;

		private bool _wasSaveOnSet;

		private bool _closeRequested;

		private Rect _listRect;

		private readonly Dictionary<object, Rect> _rowRects = new Dictionary<object, Rect>();

		private object _hoverKey;

		private object _nextHoverKey;

		private string _hoverTip;

		private string _nextHoverTip;

		private float _hoverSince;

		private Styles _styles;

		internal static bool IsOpen { get; private set; }

		internal static bool Previewing { get; private set; }

		internal static void BindConfig(ConfigFile config)
		{
			//IL_0015: 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_0057: Expected O, but got Unknown
			ToggleKey = config.Bind<KeyboardShortcut>("General", "SettingsKey", new KeyboardShortcut((KeyCode)288, Array.Empty<KeyCode>()), "Key that opens this settings window.");
			ExpandedSections = config.Bind<string>("General", "ExpandedSections", "", new ConfigDescription("Settings window sections left open, remembered for next time.", (AcceptableValueBase)null, new object[1] { ConfigText.Hidden.Tag }));
		}

		private void Awake()
		{
			string[] array = ExpandedSections.Value.Split('|');
			foreach (string text in array)
			{
				if (text.Length > 0)
				{
					_expanded.Add(text);
				}
			}
		}

		private void Update()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if (_capturingKey == null)
			{
				KeyboardShortcut value = ToggleKey.Value;
				if (((KeyboardShortcut)(ref value)).IsDown() && !TextFocusElsewhere())
				{
					SetOpen(!IsOpen);
				}
				else if (IsOpen && Input.GetKeyDown((KeyCode)27))
				{
					_closeRequested = true;
				}
			}
			UpdatePreview();
		}

		private void UpdatePreview()
		{
			bool flag = (Previewing = IsOpen && _preview && (Object)(object)Player.m_localPlayer != (Object)null);
			if (flag)
			{
				SkillXpBarStack.GetOrCreate()?.Preview(((Character)Player.m_localPlayer).GetSkills());
				FoodCalloutHud.Preview(on: true, !_previewWas && FoodCallout.Sound.Value);
				SaveCountdownHud.Preview(on: true);
				RestedCountdownHud.Preview(on: true);
			}
			else if (_previewWas)
			{
				FoodCalloutHud.Preview(on: false, playSound: false);
				SaveCountdownHud.Preview(on: false);
				RestedCountdownHud.Preview(on: false);
			}
			_previewWas = flag;
		}

		private void LateUpdate()
		{
			if (_closeRequested)
			{
				_closeRequested = false;
				SetOpen(open: false);
			}
		}

		private static bool TextFocusElsewhere()
		{
			if (!Console.IsVisible() && !TextInput.IsVisible())
			{
				if ((Object)(object)Chat.instance != (Object)null)
				{
					return Chat.instance.HasFocus();
				}
				return false;
			}
			return true;
		}

		private void SetOpen(bool open)
		{
			if (open != IsOpen)
			{
				ConfigFile config = ((BaseUnityPlugin)Plugin.Instance).Config;
				if (open)
				{
					_wasSaveOnSet = config.SaveOnConfigSet;
					config.SaveOnConfigSet = false;
				}
				else
				{
					config.Save();
					config.SaveOnConfigSet = _wasSaveOnSet;
					_capturingKey = null;
					_preview = false;
					_colorEdits.Clear();
					_hoverKey = null;
				}
				IsOpen = open;
			}
		}

		private void OnDestroy()
		{
			if (IsOpen)
			{
				SetOpen(open: false);
			}
		}

		private void OnGUI()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Expected O, but got Unknown
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Invalid comparison between Unknown and I4
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Invalid comparison between Unknown and I4
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			if (IsOpen)
			{
				if (_styles == null)
				{
					_styles = new Styles();
				}
				float num = (float)Screen.height / 1080f;
				GUI.matrix = Matrix4x4.Scale(new Vector3(num, num, 1f));
				float num2 = (float)Screen.width / num;
				((Rect)(ref _window)).height = Mathf.Min(700f, 1040f);
				((Rect)(ref _window)).x = Mathf.Clamp(((Rect)(ref _window)).x, 0f, Mathf.Max(0f, num2 - ((Rect)(ref _window)).width));
				((Rect)(ref _window)).y = Mathf.Clamp(((Rect)(ref _window)).y, 0f, 1080f - ((Rect)(ref _window)).height);
				_window = GUI.Window(1264014665, _window, new WindowFunction(DrawWindow), "Krool World UI v0.9.3", _styles.Window);
				if (_capturingKey != null && (int)Event.current.type == 4 && (int)Event.current.keyCode != 0)
				{
					KeyCode keyCode = Event.current.keyCode;
					_capturingKey.BoxedValue = (((int)keyCode == 27) ? _capturingKey.DefaultValue : ((object)new KeyboardShortcut(keyCode, Array.Empty<KeyCode>())));
					_capturingKey = null;
					Event.current.Use();
				}
			}
		}

		private void DrawWindow(int id)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Invalid comparison between Unknown and I4
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Expected O, but got Unknown
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			ConfigFile config = ((BaseUnityPlugin)Plugin.Instance).Config;
			bool flag = (int)Event.current.type == 7;
			Vector2 mousePosition = Event.current.mousePosition;
			bool mouseInList = ((Rect)(ref _listRect)).Contains(mousePosition);
			if (flag)
			{
				_nextHoverKey = null;
				_nextHoverTip = null;
			}
			List<(string, List<ConfigEntryBase>)> list = (from k in config.Keys
				group k by k.Section into g
				select (Name: g.Key, Entries: (from d in g
					select config[d] into e
					where !ConfigText.IsHidden(e)
					select e).ToList()) into s
				where s.Entries.Count > 0
				select s).ToList();
			GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) });
			GUILayout.Label("Hover a setting for details.", _styles.Hint, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MinWidth(0f) });
			GUILayout.FlexibleSpace();
			if (GUILayout.Button("Expand all", _styles.Small, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(96f),
				GUILayout.Height(24f)
			}))
			{
				SetExpanded(list.Select<(string, List<ConfigEntryBase>), string>(((string Name, List<ConfigEntryBase> Entries) s) => s.Name), open: true);
			}
			if (GUILayout.Button("Collapse all", _styles.Small, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(96f),
				GUILayout.Height(24f)
			}))
			{
				SetExpanded(list.Select<(string, List<ConfigEntryBase>), string>(((string Name, List<ConfigEntryBase> Entries) s) => s.Name), open: false);
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(6f);
			_scroll = GUILayout.BeginScrollView(_scroll, false, false, GUIStyle.none, GUI.skin.verticalScrollbar, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandHeight(true) });
			foreach (var (name, entries) in list)
			{
				DrawSection(name, entries, mouseInList);
			}
			GUILayout.EndScrollView();
			if (flag)
			{
				_listRect = GUILayoutUtility.GetLastRect();
			}
			GUILayout.Space(8f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			bool flag2 = (GUI.enabled = (Object)(object)Player.m_localPlayer != (Object)null);
			_preview = GUILayout.Toggle(_preview, new GUIContent(flag2 ? "Preview on HUD" : "Preview on HUD (in game only)"), _styles.Button, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(32f) });
			GUI.enabled = true;
			GUILayout.FlexibleSpace();
			if (GUILayout.Button("Close", _styles.Button, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(110f),
				GUILayout.Height(32f)
			}))
			{
				SetOpen(open: false);
			}
			GUILayout.EndHorizontal();
			if (flag)
			{
				UpdateTooltip(mousePosition);
			}
			GUI.DragWindow(new Rect(0f, 0f, 10000f, 46f));
		}

		private void DrawSection(string name, List<ConfigEntryBase> entries, bool mouseInList)
		{
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Invalid comparison between Unknown and I4
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: 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_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			ConfigEntryBase val = ((IEnumerable<ConfigEntryBase>)entries).FirstOrDefault((Func<ConfigEntryBase, bool>)((ConfigEntryBase e) => e.Definition.Key == "Enabled" && e.SettingType == typeof(bool)));
			bool flag = _expanded.Contains(name);
			int num = entries.Count(IsChanged);
			GUILayout.BeginHorizontal(_styles.Header, Array.Empty<GUILayoutOption>());
			if (GUILayout.Button((num > 0) ? $"{name}   <size=13><color=#B3A38C>{num} changed</color></size>" : name, _styles.HeaderButton, (GUILayoutOption[])(object)new GUILayoutOption[3]
			{
				GUILayout.MinWidth(0f),
				GUILayout.ExpandWidth(true),
				GUILayout.Height(30f)
			}))
			{
				SetExpanded(new string[1] { name }, !flag);
			}
			if ((int)Event.current.type == 7)
			{
				Rect lastRect = GUILayoutUtility.GetLastRect();
				GUI.DrawTexture(new Rect(((Rect)(ref lastRect)).x + 8f, ((Rect)(ref lastRect)).center.y - 6f, 12f, 12f), (Texture)(object)(flag ? _styles.ArrowDown : _styles.ArrowRight));
			}
			if (num > 0 && GUILayout.Button("Reset all", _styles.Small, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(76f),
				GUILayout.Height(24f)
			}))
			{
				ResetAll(entries);
			}
			if (val != null)
			{
				OnOff(val, 64f);
			}
			GUILayout.EndHorizontal();
			string text;
			if (val == null)
			{
				text = "Click to " + (flag ? "hide" : "show") + " these settings.";
			}
			else
			{
				ConfigDescription description = val.Description;
				text = ((description != null) ? description.Description : null) + "\n\nClick the name to " + (flag ? "hide" : "show") + " its settings.";
			}
			string tip = text;
			TrackHover(name, tip, mouseInList);
			if (flag)
			{
				Color color = GUI.color;
				if (val != null && !(bool)val.BoxedValue)
				{
					GUI.color = new Color(1f, 1f, 1f, 0.5f);
				}
				foreach (ConfigEntryBase entry in entries)
				{
					if (entry != val)
					{
						DrawEntry(entry, mouseInList);
					}
				}
				GUI.color = color;
				GUILayout.Space(8f);
			}
			GUILayout.Space(4f);
		}

		private unsafe void DrawEntry(ConfigEntryBase entry, bool mouseInList)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: Unknown result type (might be due to invalid IL or missing references)
			//IL_038a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0391: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Invalid comparison between Unknown and I4
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_039e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ae: 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_03bc: 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_03d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0473: Unknown result type (might be due to invalid IL or missing references)
			if (mouseInList && (int)Event.current.type == 7 && _rowRects.TryGetValue(entry, out var value) && ((Rect)(ref value)).Contains(Event.current.mousePosition))
			{
				GUI.DrawTexture(value, (Texture)(object)_styles.RowHover);
			}
			ConfigDescription description = entry.Description;
			AcceptableValueBase val = ((description != null) ? description.AcceptableValues : null);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Space(6f);
			GUIContent val2 = new GUIContent(ConfigText.Pretty(entry.Definition.Key));
			float num = Mathf.Max(180f, _styles.Label.CalcSize(val2).x + 8f);
			GUILayout.Label(val2, _styles.Label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(num) });
			object boxedValue = entry.BoxedValue;
			if (!(boxedValue is bool))
			{
				if (!(boxedValue is float num2))
				{
					if (!(boxedValue is int num3))
					{
						if (!(boxedValue is Enum obj))
						{
							if (!(boxedValue is Color val3))
							{
								if (!(boxedValue is KeyboardShortcut val4))
								{
									goto IL_04e7;
								}
								GUILayout.FlexibleSpace();
								if (GUILayout.Button((_capturingKey == entry) ? "Press a key (Esc = default)" : ((object)(*(KeyboardShortcut*)(&val4))/*cast due to .constrained prefix*/).ToString(), _styles.Button, (GUILayoutOption[])(object)new GUILayoutOption[2]
								{
									GUILayout.MinWidth(150f),
									GUILayout.Height(26f)
								}))
								{
									_capturingKey = entry;
								}
							}
							else
							{
								GUILayout.FlexibleSpace();
								Rect rect = GUILayoutUtility.GetRect(26f, 26f, (GUILayoutOption[])(object)new GUILayoutOption[2]
								{
									GUILayout.Width(26f),
									GUILayout.Height(26f)
								});
								if ((int)Event.current.type == 7)
								{
									Color color = GUI.color;
									GUI.color = new Color(val3.r, val3.g, val3.b, color.a);
									GUI.DrawTexture(rect, (Texture)(object)Texture2D.whiteTexture);
									GUI.color = color;
								}
								if (!_colorEdits.TryGetValue(entry, out var value2))
								{
									value2 = ConfigText.Hex(val3);
								}
								string text = GUILayout.TextField(value2, 8, _styles.Field, (GUILayoutOption[])(object)new GUILayoutOption[2]
								{
									GUILayout.Width(110f),
									GUILayout.Height(26f)
								});
								if (text != value2)
								{
									_colorEdits[entry] = text;
									Color val5 = default(Color);
									if ((text.Length == 6 || text.Length == 8) && ColorUtility.TryParseHtmlString("#" + text, ref val5))
									{
										entry.BoxedValue = val5;
									}
								}
							}
						}
						else
						{
							GUILayout.FlexibleSpace();
							if (GUILayout.Button(ConfigText.Value(obj), _styles.Button, (GUILayoutOption[])(object)new GUILayoutOption[2]
							{
								GUILayout.MinWidth(150f),
								GUILayout.Height(26f)
							}))
							{
								Array values = Enum.GetValues(obj.GetType());
								int num4 = Array.IndexOf(values, obj);
								entry.BoxedValue = values.GetValue((num4 + 1) % values.Length);
							}
						}
					}
					else
					{
						if (!(val is AcceptableValueRange<int> val6))
						{
							goto IL_04e7;
						}
						int num5 = Mathf.RoundToInt(GUILayout.HorizontalSlider((float)num3, (float)val6.MinValue, (float)val6.MaxValue, _styles.Slider, _styles.Thumb, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }));
						GUILayout.Label(num5.ToString(), _styles.Value, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(56f) });
						if (num5 != num3)
						{
							entry.BoxedValue = num5;
						}
					}
				}
				else
				{
					if (!(val is AcceptableValueRange<float> val7))
					{
						goto IL_04e7;
					}
					bool flag = val7.MaxValue - val7.MinValue >= 50f;
					float num6 = GUILayout.HorizontalSlider(num2, val7.MinValue, val7.MaxValue, _styles.Slider, _styles.Thumb, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
					GUILayout.Label(num2.ToString(flag ? "0" : "0.##"), _styles.Value, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(56f) });
					if (num6 != num2)
					{
						float num7 = (flag ? 1f : 0.01f);
						entry.BoxedValue = Mathf.Clamp(Mathf.Round(num6 / num7) * num7, val7.MinValue, val7.MaxValue);
					}
				}
			}
			else
			{
				GUILayout.FlexibleSpace();
				OnOff(entry, 80f);
			}
			goto IL_0569;
			IL_0569:
			if (IsChanged(entry))
			{
				if (GUILayout.Button("Reset", _styles.Small, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(52f),
					GUILayout.Height(24f)
				}))
				{
					ResetAll((IEnumerable<ConfigEntryBase>)(object)new ConfigEntryBase[1] { entry });
				}
			}
			else
			{
				GUILayout.Space(56f);
			}
			GUILayout.EndHorizontal();
			TrackHover(entry, ConfigText.Tooltip(entry), mouseInList);
			return;
			IL_04e7:
			string serializedValue = entry.GetSerializedValue();
			float num8 = Mathf.Max(120f, ((Rect)(ref _listRect)).width - 22f - 6f - num - 56f - 24f);
			string text2 = GUILayout.TextField(serializedValue, _styles.Field, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(num8),
				GUILayout.Height(26f)
			});
			if (text2 != serializedValue)
			{
				try
				{
					entry.SetSerializedValue(text2);
				}
				catch
				{
				}
			}
			goto IL_0569;
		}

		private void OnOff(ConfigEntryBase entry, float width)
		{
			bool flag = (bool)entry.BoxedValue;
			bool flag2 = GUILayout.Toggle(flag, flag ? "On" : "Off", _styles.Button, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(width),
				GUILayout.Height(24f)
			});
			if (flag2 != flag)
			{
				entry.BoxedValue = flag2;
			}
		}

		private void TrackHover(object key, string tip, bool mouseInList)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			if ((int)Event.current.type == 7)
			{
				Rect lastRect = GUILayoutUtility.GetLastRect();
				_rowRects[key] = lastRect;
				if (mouseInList && ((Rect)(ref lastRect)).Contains(Event.current.mousePosition))
				{
					_nextHoverKey = key;
					_nextHoverTip = tip;
				}
			}
		}

		private void UpdateTooltip(Vector2 mouse)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			if (!object.Equals(_nextHoverKey, _hoverKey))
			{
				_hoverKey = _nextHoverKey;
				_hoverSince = Time.unscaledTime;
			}
			_hoverTip = _nextHoverTip;
			if (_hoverKey != null && !string.IsNullOrEmpty(_hoverTip) && _capturingKey == null && GUIUtility.hotControl == 0 && !(Time.unscaledTime - _hoverSince < 0.35f))
			{
				GUIContent val = new GUIContent(_hoverTip);
				float num = Mathf.Min(340f, ((Rect)(ref _window)).width - 16f);
				float num2 = _styles.Tooltip.CalcHeight(val, num);
				float num3 = mouse.x + 16f;
				float num4 = mouse.y + 22f;
				if (num3 + num > ((Rect)(ref _window)).width - 8f)
				{
					num3 = ((Rect)(ref _window)).width - 8f - num;
				}
				if (num4 + num2 > ((Rect)(ref _window)).height - 8f)
				{
					num4 = mouse.y - num2 - 10f;
				}
				GUI.Label(new Rect(Mathf.Max(8f, num3), Mathf.Max(8f, num4), num, num2), val, _styles.Tooltip);
			}
		}

		private void SetExpanded(IEnumerable<string> names, bool open)
		{
			foreach (string name in names)
			{
				if (open)
				{
					_expanded.Add(name);
				}
				else
				{
					_expanded.Remove(name);
				}
			}
			ExpandedSections.Value = string.Join("|", _expanded.OrderBy((string n) => n));
		}

		private void ResetAll(IEnumerable<ConfigEntryBase> entries)
		{
			foreach (ConfigEntryBase entry in entries)
			{
				entry.BoxedValue = entry.DefaultValue;
				_colorEdits.Remove(entry);
			}
		}

		private static bool IsChanged(ConfigEntryBase entry)
		{
			return !object.Equals(entry.BoxedValue, entry.DefaultValue);
		}
	}
}
namespace KroolWorldUI.Features
{
	internal static class BenchPins
	{
		internal enum PinIcon
		{
			Fire,
			House,
			Hammer,
			Dot,
			Portal
		}

		internal enum Naming
		{
			RandomName,
			StationName,
			NoName
		}

		internal enum Stations
		{
			WorkbenchOnly,
			AllCraftingStations
		}

		[HarmonyPatch(typeof(Player), "PlacePiece")]
		private static class PinOnPlace
		{
			private static void Postfix(Player __instance, Piece piece, Vector3 pos)
			{
				//IL_0065: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (Enabled.Value && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && !((Object)(object)piece == (Object)null) && !((Object)(object)Minimap.instance == (Object)null))
					{
						CraftingStation componentInChildren = ((Component)piece).GetComponentInChildren<CraftingStation>(true);
						if (!((Object)(object)componentInChildren == (Object)null) && (PinStations.Value != Stations.WorkbenchOnly || !(componentInChildren.m_name != "$piece_workbench")))
						{
							AddPin(componentInChildren, pos);
						}
					}
				}
				catch (Exception arg)
				{
					Plugin.Log.LogError((object)$"Bench pin: {arg}");
				}
			}
		}

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<Stations> PinStations;

		internal static ConfigEntry<PinIcon> Icon;

		internal static ConfigEntry<Naming> Names;

		internal static ConfigEntry<float> SkipNearPinMeters;

		internal static ConfigEntry<bool> Announce;

		internal static ConfigEntry<string> NamePrefixes;

		internal static ConfigEntry<string> NameSuffixes;

		private const string Section = "Bench Pins";

		private const string WorkbenchName = "$piece_workbench";

		private const string DefaultPrefixes = "Ulf, Hrafn, Jarn, Frost, Grim, Skjold, Bjorn, Eld, Svart, Thor, Odin, Rune, Troll, Mead, Ash, Ygg, Valk, Draugr, Fenris, Storm, Iron, Wolf, Raven, Boar, Elk, Ember, Hel, Njord, Sig, Hjalm, Gunn, Kald, Myrk, Vind, Stein, Gull, Sol, Eikthyr, Bonemass, Greyling";

		private const string DefaultSuffixes = "heim, gard, vik, stad, borg, holt, fjord, hall, by, hold, keep, stead, haven, mark, fell, dal, ness, wall, rest, ford, hof, skali, rock, watch, hearth";

		private static FieldRef<Minimap, List<PinData>> _pins;

		private static List<PinData> Pins(Minimap map)
		{
			return (_pins ?? (_pins = AccessTools.FieldRefAccess<Minimap, List<PinData>>("m_pins"))).Invoke(map);
		}

		internal static void BindConfig(ConfigFile config)
		{
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			Enabled = config.Bind<bool>("Bench Pins", "Enabled", true, "Adds a map pin when you build a workbench, so you can find your camps again. This adds a pin to your map like you would by hand; removing the bench leaves the pin.");
			PinStations = config.Bind<Stations>("Bench Pins", "PinStations", Stations.WorkbenchOnly, "Workbench Only, or every crafting station (forge, stonecutter, artisan table, and so on).");
			Icon = config.Bind<PinIcon>("Bench Pins", "Icon", PinIcon.House, "Which map pin icon to use.");
			Names = config.Bind<Naming>("Bench Pins", "Names", Naming.RandomName, "Random Name: a Norse-sounding name from Name Prefixes + Name Suffixes. Station Name: \"Workbench\". No Name: just the icon.");
			SkipNearPinMeters = config.Bind<float>("Bench Pins", "SkipNearPinMeters", 50f, new ConfigDescription("No new pin if one is already on your map this close (meters), so a base gets one pin, not one per bench. 0 = always pin.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 200f), Array.Empty<object>()));
			Announce = config.Bind<bool>("Bench Pins", "Announce", true, "Show the new pin's name in the top-left messages.");
			NamePrefixes = config.Bind<string>("Bench Pins", "NamePrefixes", "Ulf, Hrafn, Jarn, Frost, Grim, Skjold, Bjorn, Eld, Svart, Thor, Odin, Rune, Troll, Mead, Ash, Ygg, Valk, Draugr, Fenris, Storm, Iron, Wolf, Raven, Boar, Elk, Ember, Hel, Njord, Sig, Hjalm, Gunn, Kald, Myrk, Vind, Stein, Gull, Sol, Eikthyr, Bonemass, Greyling", "First halves of random names, separated by commas.");
			NameSuffixes = config.Bind<string>("Bench Pins", "NameSuffixes", "heim, gard, vik, stad, borg, holt, fjord, hall, by, hold, keep, stead, haven, mark, fell, dal, ness, wall, rest, ford, hof, skali, rock, watch, hearth", "Second halves of random names, separated by commas.");
		}

		private static void AddPin(CraftingStation station, Vector3 pos)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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)
			Minimap instance = Minimap.instance;
			List<PinData> list = Pins(instance);
			float near = SkipNearPinMeters.Value;
			if (!(near > 0f) || !list.Any((PinData p) => p.m_save && Utils.DistanceXZ(p.m_pos, pos) < near))
			{
				string text = Localization.instance.Localize(station.m_name);
				string text2 = Names.Value switch
				{
					Naming.StationName => text, 
					Naming.NoName => "", 
					_ => RandomName(list), 
				};
				PinData val = instance.AddPin(pos, (PinType)Icon.Value, text2, true, false, 0L, default(PlatformUserID));
				if (Announce.Value)
				{
					((Character)Player.m_localPlayer).Message((MessageType)1, "$msg_pin_added: " + ((text2.Length > 0) ? text2 : text), 0, val?.m_icon, false);
				}
			}
		}

		internal static string RandomName(List<PinData> pins)
		{
			string[] array = Split(NamePrefixes.Value, "Ulf, Hrafn, Jarn, Frost, Grim, Skjold, Bjorn, Eld, Svart, Thor, Odin, Rune, Troll, Mead, Ash, Ygg, Valk, Draugr, Fenris, Storm, Iron, Wolf, Raven, Boar, Elk, Ember, Hel, Njord, Sig, Hjalm, Gunn, Kald, Myrk, Vind, Stein, Gull, Sol, Eikthyr, Bonemass, Greyling");
			string[] array2 = Split(NameSuffixes.Value, "heim, gard, vik, stad, borg, holt, fjord, hall, by, hold, keep, stead, haven, mark, fell, dal, ness, wall, rest, ford, hof, skali, rock, watch, hearth");
			string name = "";
			for (int i = 0; i < 12; i++)
			{
				name = array[Random.Range(0, array.Length)] + array2[Random.Range(0, array2.Length)];
				if (pins == null || !pins.Any((PinData p) => p.m_name == name))
				{
					break;
				}
			}
			return name;
		}

		private static string[] Split(string list, string fallback)
		{
			string[] array = (from s in list.Split(',')
				select s.Trim() into s
				where s.Length > 0
				select s).ToArray();
			if (array.Length == 0)
			{
				return Split(fallback, "x");
			}
			return array;
		}
	}
	internal static class BuildMaterials
	{
		internal enum Place
		{
			BesideBuildInfo,
			Custom
		}

		internal enum Show
		{
			Always,
			WhenKnown,
			WhenCarried,
			Never
		}

		[HarmonyPatch(typeof(Hud), "Update")]
		private static class EnsureOnHud
		{
			private static void Postfix()
			{
				if (Enabled.Value)
				{
					BuildMaterialsHud.Ensure();
				}
			}
		}

		internal static readonly (string Key, string Prefab, Show Default)[] Materials = new(string, string, Show)[11]
		{
			("Wood", "Wood", Show.WhenKnown),
			("Stone", "Stone", Show.WhenKnown),
			("CoreWood", "RoundLog", Show.WhenKnown),
			("FineWood", "FineWood", Show.WhenKnown),
			("Resin", "Resin", Show.WhenCarried),
			("BronzeNails", "BronzeNails", Show.WhenCarried),
			("IronNails", "IronNails", Show.WhenCarried),
			("BlackMarble", "BlackMarble", Show.WhenCarried),
			("YggdrasilWood", "YggdrasilWood", Show.WhenCarried),
			("Grausten", "Grausten", Show.WhenCarried),
			("Ashwood", "Blackwood", Show.WhenCarried)
		};

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<bool> SelectedPiece;

		internal static ConfigEntry<Show>[] MaterialShow;

		internal static ConfigEntry<string> OtherMaterials;

		internal static ConfigEntry<bool> CanBuildCount;

		internal static ConfigEntry<Place> Placement;

		internal static ConfigEntry<float> AnchorX;

		internal static ConfigEntry<float> AnchorY;

		private const string Section = "Build Materials";

		internal static void BindConfig(ConfigFile config)
		{
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Expected O, but got Unknown
			Enabled = config.Bind<bool>("Build Materials", "Enabled", true, "While a build tool is out, count the materials you carry, so you can watch your wood and stone as you build.");
			SelectedPiece = config.Bind<bool>("Build Materials", "SelectedPiece", true, "List what the selected piece costs, each with how many you carry. Red when you are short.");
			CanBuildCount = config.Bind<bool>("Build Materials", "CanBuildCount", true, "Show how many of the selected piece your materials cover.");
			Placement = config.Bind<Place>("Build Materials", "Placement", Place.BesideBuildInfo, "Beside Build Info: right of the selected-piece box at the bottom center. Custom: placed by Anchor X and Anchor Y.");
			AnchorX = config.Bind<float>("Build Materials", "AnchorX", 0.8f, new ConfigDescription("Custom placement: left edge (0 = left of screen, 1 = right).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			AnchorY = config.Bind<float>("Build Materials", "AnchorY", 0.1f, new ConfigDescription("Custom placement: bottom edge (0 = bottom of screen, 1 = top).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			MaterialShow = new ConfigEntry<Show>[Materials.Length];
			for (int i = 0; i < Materials.Length; i++)
			{
				string text = ConfigText.Pretty(Materials[i].Key);
				MaterialShow[i] = config.Bind<Show>("Build Materials", Materials[i].Key, Materials[i].Default, "When to list " + text + ". When Known: once your character has picked one up. When Carried: only while you have some.");
			}
			OtherMaterials = config.Bind<string>("Build Materials", "OtherMaterials", "", "More materials to always list, by the names the game shows, separated by commas (for example: Copper, Deer Hide).");
		}
	}
	internal class BuildMaterialsHud : MonoBehaviour
	{
		private class Row
		{
			public GameObject Root;

			public Image Icon;

			public TMP_Text Name;

			public TMP_Text Count;
		}

		private const float Width = 210f;

		private const float RowHeight = 28f;

		private const float Pad = 6f;

		private const float Gap = 12f;

		private const float RefreshSeconds = 0.2f;

		private static BuildMaterialsHud _instance;

		private static bool _failed;

		private RectTransform _rect;

		private CanvasGroup _group;

		private TMP_Text _template;

		private RectTransform _buildInfo;

		private float _nextRefresh;

		private SharedData[] _common;

		private string _otherFrom;

		private readonly List<SharedData> _other = new List<SharedData>();

		private readonly List<Row> _rows = new List<Row>();

		private TMP_Text _footer;

		private readonly Vector3[] _corners = (Vector3[])(object)new Vector3[4];

		internal static void Ensure()
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_instance != (Object)null || _failed)
			{
				return;
			}
			Hud instance = Hud.instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.m_rootObject == (Object)null || (Object)(object)instance.m_healthText == (Object)null || (Object)(object)Player.m_localPlayer == (Object)null)
			{
				return;
			}
			try
			{
				GameObject val = new GameObject("KroolWorldUI_BuildMaterials", new Type[2]
				{
					typeof(RectTransform),
					typeof(CanvasGroup)
				});
				val.transform.SetParent(instance.m_rootObject.transform, false);
				BuildMaterialsHud buildMaterialsHud = (_instance = val.AddComponent<BuildMaterialsHud>());
				buildMaterialsHud._rect = (RectTransform)val.transform;
				buildMaterialsHud._rect.pivot = Vector2.zero;
				buildMaterialsHud._rect.sizeDelta = new Vector2(210f, 40f);
				buildMaterialsHud._group = val.GetComponent<CanvasGroup>();
				buildMaterialsHud._group.alpha = 0f;
				buildMaterialsHud._group.blocksRaycasts = false;
				buildMaterialsHud._group.interactable = false;
				HudKit.ToastBackground(val.transform);
				buildMaterialsHud._template = instance.m_healthText;
				buildMaterialsHud._buildInfo = (RectTransform)(((Object)(object)instance.m_buildHud != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
				buildMaterialsHud._footer = HudKit.NewText(buildMaterialsHud._template, val.transform, "footer", (TextAlignmentOptions)4097, HudKit.Muted, 15f);
			}
			catch (Exception arg)
			{
				_failed = true;
				Plugin.Log.LogError((object)$"Build materials disabled for this session: {arg}");
			}
		}

		private void OnDestroy()
		{
			if ((Object)(object)_instance == (Object)(object)this)
			{
				_instance = null;
			}
		}

		private void Update()
		{
			if (_failed)
			{
				return;
			}
			try
			{
				Tick();
			}
			catch (Exception arg)
			{
				_failed = true;
				Plugin.Log.LogError((object)$"Build materials disabled for this session after an error: {arg}");
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}

		private void Tick()
		{
			Player localPlayer = Player.m_localPlayer;
			bool flag = (Object)(object)localPlayer != (Object)null && ((Character)localPlayer).InPlaceMode();
			bool flag2 = SettingsWindow.IsOpen && SettingsWindow.Previewing;
			if (!BuildMaterials.Enabled.Value || !((Object)(object)localPlayer != (Object)null) || !(flag || flag2) || InventoryGui.IsVisible() || Minimap.IsOpen() || Menu.IsVisible())
			{
				_group.alpha = 0f;
				return;
			}
			if (Time.unscaledTime >= _nextRefresh)
			{
				_nextRefresh = Time.unscaledTime + 0.2f;
				Refresh(localPlayer, flag ? localPlayer.GetSelectedPiece() : null);
			}
			_group.alpha = ((_rows.Count > 0 && _rows[0].Root.activeSelf) ? 1f : 0f);
			Place();
		}

		private void Refresh(Player player, Piece piece)
		{
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: 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_0347: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: 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_0393: Expected O, but got Unknown
			//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
			Inventory inventory = ((Humanoid)player).GetInventory();
			int num = 0;
			int num2 = int.MaxValue;
			bool flag = false;
			HashSet<string> hashSet = new HashSet<string>();
			if ((Object)(object)piece != (Object)null && BuildMaterials.SelectedPiece.Value && piece.m_resources != null)
			{
				Requirement[] resources = piece.m_resources;
				foreach (Requirement val in resources)
				{
					SharedData val2 = val?.m_resItem?.m_itemData?.m_shared;
					if (val2 != null && val.m_amount > 0 && hashSet.Add(val2.m_name))
					{
						int num3 = inventory.CountItems(val2.m_name, -1, true);
						flag = true;
						num2 = Mathf.Min(num2, num3 / val.m_amount);
						Color countColor = ((num3 >= val.m_amount) ? HudKit.Parchment : HudKit.Warn);
						SetRow(num++, val2, $"{num3}<size=75%><color=#{Hex(HudKit.Muted)}>  /{val.m_amount}</color></size>", countColor);
					}
				}
			}
			Resolve();
			bool flag2 = !UsingTerrainTool(player);
			if (_common != null && flag2)
			{
				for (int j = 0; j < _common.Length; j++)
				{
					SharedData val3 = _common[j];
					if (val3 != null && !hashSet.Contains(val3.m_name))
					{
						int num4 = inventory.CountItems(val3.m_name, -1, true);
						if (BuildMaterials.MaterialShow[j].Value switch
						{
							BuildMaterials.Show.Always => true, 
							BuildMaterials.Show.WhenKnown => num4 > 0 || player.IsKnownMaterial(val3.m_name), 
							BuildMaterials.Show.WhenCarried => num4 > 0, 
							_ => false, 
						} && hashSet.Add(val3.m_name))
						{
							SetRow(num++, val3, num4.ToString(), HudKit.Parchment);
						}
					}
				}
			}
			foreach (SharedData item in _other)
			{
				if (flag2 && hashSet.Add(item.m_name))
				{
					SetRow(num++, item, inventory.CountItems(item.m_name, -1, true).ToString(), HudKit.Parchment);
				}
			}
			for (int k = num; k < _rows.Count; k++)
			{
				_rows[k].Root.SetActive(false);
			}
			bool flag3 = (Object)(object)piece != (Object)null && (player.NoCostCheat() || ((Object)(object)ZoneSystem.instance != (Object)null && ZoneSystem.instance.GetGlobalKey(piece.FreeBuildKey())));
			bool flag4 = BuildMaterials.CanBuildCount.Value && flag && !flag3;
			((Component)_footer).gameObject.SetActive(flag4);
			if (flag4)
			{
				_footer.text = ((num2 > 0) ? $"Enough for <color=#{Hex(HudKit.Gold)}>{num2}</color>" : ("<color=#" + Hex(HudKit.Warn) + ">Not enough</color>"));
			}
			int num5 = num + (flag4 ? 1 : 0);
			for (int l = 0; l < num; l++)
			{
				Lay((RectTransform)_rows[l].Root.transform, l);
			}
			if (flag4)
			{
				Lay(_footer.rectTransform, num);
			}
			_rect.sizeDelta = new Vector2(210f, 28f * (float)Mathf.Max(1, num5) + 12f);
		}

		private void Lay(RectTransform rt, int i)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			rt.anchorMin = new Vector2(0f, 1f);
			rt.anchorMax = new Vector2(1f, 1f);
			rt.pivot = new Vector2(0.5f, 1f);
			rt.offsetMin = new Vector2(6f + (((Object)(object)rt == (Object)(object)_footer.rectTransform) ? 4f : 0f), -6f - 28f * (float)(i + 1));
			rt.offsetMax = new Vector2(-6f, -6f - 28f * (float)i);
		}

		private void SetRow(int index, SharedData shared, string count, Color countColor)
		{
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			while (_rows.Count <= index)
			{
				_rows.Add(NewRow());
			}
			Row row = _rows[index];
			row.Root.SetActive(true);
			Sprite val = ((shared.m_icons != null && shared.m_icons.Length != 0) ? shared.m_icons[0] : null);
			row.Icon.sprite = val;
			((Behaviour)row.Icon).enabled = (Object)(object)val != (Object)null;
			row.Name.text = ((Localization.instance != null) ? Localization.instance.Localize(shared.m_name) : shared.m_name);
			row.Count.text = count;
			((Graphic)row.Count).color = countColor;
		}

		private Row NewRow()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: 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_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: 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_0193: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("row", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(((Component)this).transform, false);
			Image val2 = HudKit.NewImage("icon", val.transform, Color.white);
			val2.preserveAspect = true;
			RectTransform rectTransform = ((Graphic)val2).rectTransform;
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0f, 0.5f);
			rectTransform.anchorMax = val3;
			rectTransform.anchorMin = val3;
			rectTransform.pivot = new Vector2(0f, 0.5f);
			rectTransform.sizeDelta = new Vector2(24f, 24f);
			rectTransform.anchoredPosition = Vector2.zero;
			TMP_Text val4 = HudKit.NewText(_template, val.transform, "name", (TextAlignmentOptions)4097, HudKit.Parchment, 16f);
			val4.overflowMode = (TextOverflowModes)1;
			val4.rectTransform.offsetMin = new Vector2(30f, 0f);
			val4.rectTransform.offsetMax = new Vector2(-78f, 0f);
			TMP_Text val5 = HudKit.NewText(_template, val.transform, "count", (TextAlignmentOptions)4100, HudKit.Parchment);
			RectTransform rectTransform2 = val5.rectTransform;
			rectTransform2.anchorMin = new Vector2(1f, 0f);
			rectTransform2.anchorMax = new Vector2(1f, 1f);
			rectTransform2.pivot = new Vector2(1f, 0.5f);
			rectTransform2.sizeDelta = new Vector2(76f, 0f);
			rectTransform2.anchoredPosition = new Vector2(-2f, 0f);
			return new Row
			{
				Root = val,
				Icon = val2,
				Name = val4,
				Count = val5
			};
		}

		private void Resolve()
		{
			string text = BuildMaterials.OtherMaterials.Value ?? "";
			if ((_common != null && text == _otherFrom) || (Object)(object)ObjectDB.instance == (Object)null || ObjectDB.instance.m_items.Count == 0)
			{
				return;
			}
			Dictionary<string, SharedData> dictionary = new Dictionary<string, SharedData>();
			Dictionary<string, SharedData> dictionary2 = new Dictionary<string, SharedData>();
			foreach (GameObject item in ObjectDB.instance.m_items)
			{
				SharedData val = ((!((Object)(object)item != (Object)null)) ? null : item.GetComponent<ItemDrop>()?.m_itemData?.m_shared);
				if (val != null)
				{
					dictionary[Key(((Object)item).name)] = val;
					string key = Key((Localization.instance != null) ? Localization.instance.Localize(val.m_name) : val.m_name);
					if (!dictionary2.ContainsKey(key))
					{
						dictionary2[key] = val;
					}
				}
			}
			if (_common == null)
			{
				_common = (SharedData[])(object)new SharedData[BuildMaterials.Materials.Length];
				for (int i = 0; i < _common.Length; i++)
				{
					dictionary.TryGetValue(Key(BuildMaterials.Materials[i].Prefab), out _common[i]);
					if (_common[i] == null)
					{
						Plugin.Log.LogWarning((object)("Build materials: item '" + BuildMaterials.Materials[i].Prefab + "' not found."));
					}
				}
			}
			_otherFrom = text;
			_other.Clear();
			string[] array = text.Split(',');
			foreach (string text2 in array)
			{
				string text3 = Key(text2);
				if (text3.Length == 0)
				{
					continue;
				}
				if (dictionary2.TryGetValue(text3, out var value) || dictionary.TryGetValue(text3, out value))
				{
					if (!_other.Contains(value))
					{
						_other.Add(value);
					}
				}
				else
				{
					Plugin.Log.LogWarning((object)("Build materials: no item named '" + text2.Trim() + "'."));
				}
			}
		}

		private static bool UsingTerrainTool(Player player)
		{
			if (!((Character)player).InPlaceMode())
			{
				return false;
			}
			foreach (ItemData equippedItem in ((Humanoid)player).GetInventory().GetEquippedItems())
			{
				string text = (((Object)(object)equippedItem?.m_dropPrefab != (Object)null) ? ((Object)equippedItem.m_dropPrefab).name : null);
				if (text == "Hoe" || text == "Cultivator")
				{
					return true;
				}
			}
			return false;
		}

		private static string Key(string s)
		{
			return new string((s ?? "").Where((char c) => !char.IsWhiteSpace(c)).ToArray()).ToLowerInvariant();
		}

		private static string Hex(Color c)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return ColorUtility.ToHtmlStringRGB(c);
		}

		private void Place()
		{
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			bool flag = BuildMaterials.Placement.Value == BuildMaterials.Place.BesideBuildInfo;
			if (flag && (Object)(object)_buildInfo != (Object)null && ((Component)_buildInfo).gameObject.activeInHierarchy)
			{
				_buildInfo.GetWorldCorners(_corners);
				float x = _corners[2].x;
				float x2 = _corners[0].x;
				float y = _corners[0].y;
				float num = 12f * ((Transform)_rect).lossyScale.x;
				Rect rect = _rect.rect;
				float num2 = ((Rect)(ref rect)).width * ((Transform)_rect).lossyScale.x;
				float num3 = ((x + num + num2 <= (float)Screen.width) ? (x + num) : (x2 - num - num2));
				RectTransform rect2 = _rect;
				Vector2 anchorMin = (_rect.anchorMax = Vector2.zero);
				rect2.anchorMin = anchorMin;
				((Transform)_rect).position = new Vector3(num3, y, ((Transform)_rect).position.z);
			}
			else
			{
				Vector2 val = (flag ? new Vector2(0.5f, 0f) : new Vector2(BuildMaterials.AnchorX.Value, BuildMaterials.AnchorY.Value));
				_rect.anchorMin = val;
				_rect.anchorMax = val;
				_rect.anchoredPosition = (Vector2)(flag ? new Vector2(270f, 95f) : Vector2.zero);
			}
		}
	}
	internal static class DayNightBar
	{
		[HarmonyPatch(typeof(Minimap), "Update")]
		private static class EnsureOnMinimap
		{
			private static void Postfix(Minimap __instance)
			{
				if (Enabled.Value)
				{
					DayNightBarHud.Ensure(__instance);
				}
			}
		}

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<bool> Countdown;

		internal static ConfigEntry<bool> DayNumber;

		internal static ConfigEntry<bool> Clock;

		internal static ConfigEntry<float> DuskWarningSeconds;

		internal static ConfigEntry<int> BarHeight;

		internal static ConfigEntry<Color> DayColor;

		internal static ConfigEntry<Color> NightColor;

		private const string Section = "Day Night Bar";

		internal const float Dawn = 0.15f;

		internal const float Dusk = 0.85f;

		internal static void BindConfig(ConfigFile config)
		{
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Expected O, but got Unknown
			//IL_00f1: 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)
			Enabled = config.Bind<bool>("Day Night Bar", "Enabled", true, "A day and night bar above the minimap: where you are in the day, and how long until dusk or dawn.");
			Countdown = config.Bind<bool>("Day Night Bar", "Countdown", true, "Show the time left until dusk (by day) or dawn (by night).");
			DayNumber = config.Bind<bool>("Day Night Bar", "DayNumber", true, "Show the day number.");
			Clock = config.Bind<bool>("Day Night Bar", "Clock", false, "Show the time of day as a 24-hour clock: 06:00 is sunrise, 18:00 sunset.");
			DuskWarningSeconds = config.Bind<float>("Day Night Bar", "DuskWarningSeconds", 60f, new ConfigDescription("The dusk countdown turns orange this many seconds before night. 0 = never.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 300f), Array.Empty<object>()));
			BarHeight = config.Bind<int>("Day Night Bar", "BarHeight", 10, new ConfigDescription("Bar height in HUD pixels.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(6, 18), Array.Empty<object>()));
			DayColor = config.Bind<Color>("Day Night Bar", "DayColor", new Color(0.86f, 0.68f, 0.32f, 0.85f), "Color of the day part.");
			NightColor = config.Bind<Color>("Day Night Bar", "NightColor", new Color(0.13f, 0.17f, 0.36f, 0.9f), "Color of the night part.");
		}

		internal static bool TryGetTime(out float fraction, out float dayLength, out int day)
		{
			fraction = 0f;
			dayLength = 0f;
			day = 0;
			EnvMan instance = EnvMan.instance;
			ZNet instance2 = ZNet.instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance2 == (Object)null || instance.m_dayLengthSec <= 0)
			{
				return false;
			}
			double timeSeconds = instance2.GetTimeSeconds();
			dayLength = instance.m_dayLengthSec;
			fraction = (float)(timeSeconds % (double)dayLength / (double)dayLength);
			day = instance.GetDay();
			return true;
		}

		internal static float SunFraction(float f)
		{
			if (f >= 0.15f && f <= 0.85f)
			{
				return 0.25f + (f - 0.15f) / 0.70000005f * 0.5f;
			}
			if (f < 0.5f)
			{
				return f / 0.15f * 0.25f;
			}
			return 0.75f + (f - 0.85f) / 0.14999998f * 0.25f;
		}
	}
	internal class DayNightBarHud : MonoBehaviour
	{
		private const float Inset = 6f;

		private const float Above = 6f;

		private const float TextHeight = 18f;

		private const float TextGap = 1f;

		private const int StripWidth = 256;

		private static DayNightBarHud _instance;

		private static bool _failed;

		private static Texture2D _sun;

		private static Texture2D _moon;

		private RectTransform _rect;

		private RawImage _strip;

		private Texture2D _stripTex;

		private Color _stripDay;

		private Color _stripNight;

		private RectTransform _sunIcon;

		private RectTransform _moonLeft;

		private RectTransform _moonRight;

		private RectTransform _marker;

		private TMP_Text _left;

		private TMP_Text _center;

		private TMP_Text _right;

		private int _height = -1;

		internal static void Ensure(Minimap map)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_instance != (Object)null || _failed || (Object)(object)map.m_smallRoot == (Object)null || (Object)(object)map.m_biomeNameSmall == (Object)null)
			{
				return;
			}
			try
			{
				GameObject val = new GameObject("KroolWorldUI_DayNightBar", new Type[1] { typeof(RectTransform) });
				val.transform.SetParent(map.m_smallRoot.transform, false);
				(_instance = val.AddComponent<DayNightBarHud>()).Build(map.m_biomeNameSmall);
			}
			catch (Exception arg)
			{
				_failed = true;
				Plugin.Log.LogError((object)$"Day night bar disabled for this session: {arg}");
			}
		}

		private void OnDestroy()
		{
			if ((Object)(object)_instance == (Object)(object)this)
			{
				_instance = null;
			}
		}

		private void Build(TMP_Text template)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: 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_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: 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_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			_rect = (RectTransform)((Component)this).transform;
			_rect.anchorMin = new Vector2(0f, 1f);
			_rect.anchorMax = new Vector2(1f, 1f);
			_rect.pivot = new Vector2(0.5f, 0f);
			GameObject val = new GameObject("strip", new Type[2]
			{
				typeof(RectTransform),
				typeof(RawImage)
			});
			val.transform.SetParent(((Component)this).transform, false);
			_strip = val.GetComponent<RawImage>();
			((Graphic)_strip).raycastTarget = false;
			Outline obj = val.AddComponent<Outline>();
			((Shadow)obj).effectColor = new Color(0f, 0f, 0f, 0.6f);
			((Shadow)obj).effectDistance = new Vector2(1f, -1f);
			RectTransform rectTransform = ((Graphic)_strip).rectTransform;
			rectTransform.anchorMin = new Vector2(0f, 0f);
			rectTransform.anchorMax = new Vector2(1f, 0f);
			rectTransform.pivot = new Vector2(0.5f, 0f);
			rectTransform.anchoredPosition = Vector2.zero;
			if ((Object)(object)_sun == (Object)null)
			{
				_sun = SunTexture();
			}
			if ((Object)(object)_moon == (Object)null)
			{
				_moon = MoonTexture();
			}
			_sunIcon = Icon("sun", _sun, new Color(1f, 0.86f, 0.45f, 1f));
			_moonLeft = Icon("moon", _moon, new Color(0.82f, 0.88f, 1f, 1f));
			_moonRight = Icon("moon", _moon, new Color(0.82f, 0.88f, 1f, 1f));
			Image val2 = HudKit.NewImage("now", ((Component)this).transform, Color.white);
			((Shadow)((Component)val2).gameObject.AddComponent<Outline>()).effectColor = new Color(0f, 0f, 0f, 0.85f);
			_marker = ((Graphic)val2).rectTransform;
			RectTransform marker = _marker;
			RectTransform marker2 = _marker;
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0f, 0f);
			marker2.anchorMax = val3;
			marker.anchorMin = val3;
			_marker.pivot = new Vector2(0.5f, 0.5f);
			_left = Label(template, "day", (TextAlignmentOptions)1025);
			_center = Label(template, "clock", (TextAlignmentOptions)1026);
			_right = Label(template, "countdown", (TextAlignmentOptions)1028);
		}

		private RectTransform Icon(string name, Texture2D tex, Color color)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_0070: 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)
			GameObject val = new GameObject(name, new Type[2]
			{
				typeof(RectTransform),
				typeof(RawImage)
			});
			val.transform.SetParent(((Component)this).transform, false);
			RawImage component = val.GetComponent<RawImage>();
			component.texture = (Texture)(object)tex;
			((Graphic)component).color = color;
			((Graphic)component).raycastTarget = false;
			RectTransform rectTransform = ((Graphic)component).rectTransform;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0f, 0f);
			rectTransform.anchorMax = val2;
			rectTransform.anchorMin = val2;
			rectTransform.pivot = new Vector2(0.5f, 0.5f);
			return rectTransform;
		}

		private TMP_Text Label(TMP_Text template, string name, TextAlignmentOptions align)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: 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)
			//IL_003e: 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)
			TMP_Text obj = HudKit.NewText(template, ((Component)this).transform, name, align, HudKit.Parchment, 14f);
			RectTransform rectTransform = obj.rectTransform;
			rectTransform.anchorMin = new Vector2(0f, 0f);
			rectTransform.anchorMax = new Vector2(1f, 0f);
			rectTransform.pivot = new Vector2(0.5f, 0f);
			return obj;
		}

		private void LateUpdate()
		{
			if (_failed)
			{
				return;
			}
			try
			{
				Tick();
			}
			catch (Exception arg)
			{
				_failed = true;
				Plugin.Log.LogError((object)$"Day night bar disabled for this session after an error: {arg}");
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}

		private void Tick()
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			float fraction;
			float dayLength;
			int day;
			bool flag = DayNightBar.Enabled.Value && (Object)(object)Player.m_localPlayer != (Object)null && DayNightBar.TryGetTime(out fraction, out dayLength, out day);
			for (int i = 0; i < ((Component)this).transform.childCount; i++)
			{
				((Component)((Component)this).transform.GetChild(i)).gameObject.SetActive(flag);
			}
			if (flag)
			{
				DayNightBar.TryGetTime(out var fraction2, out var dayLength2, out var day2);
				Layout();
				UpdateStrip();
				RectTransform marker = _marker;
				RectTransform marker2 = _marker;
				Vector2 val = default(Vector2);
				((Vector2)(ref val))..ctor(fraction2, 0f);
				marker2.anchorMax = val;
				marker.anchorMin = val;
				bool flag2 = fraction2 >= 0.15f && fraction2 < 0.85f;
				float num = (flag2 ? ((0.85f - fraction2) * dayLength2) : ((((fraction2 < 0.15f) ? 0.15f : 1.15f) - fraction2) * dayLength2));
				_left.text = (DayNightBar.DayNumber.Value ? DayText(day2) : "");
				if (DayNightBar.Clock.Value)
				{
					int num2 = Mathf.FloorToInt(DayNightBar.SunFraction(fraction2) * 24f * 60f) % 1440;
					_center.text = $"<mspace=0.55em>{num2 / 60:00}:{num2 % 60:00}</mspace>";
				}
				else
				{
					_center.text = "";
				}
				if (DayNightBar.Countdown.Value)
				{
					Color val2 = (Color)((flag2 && num <= DayNightBar.DuskWarningSeconds.Value) ? HudKit.Warn : (flag2 ? HudKit.Gold : new Color(0.7f, 0.78f, 1f, 1f)));
					_right.text = (flag2 ? "Dusk" : "Dawn") + " in <color=#" + ColorUtility.ToHtmlStringRGB(val2) + "><mspace=0.55em>" + Clock(num) + "</mspace></color>";
				}
				else
				{
					_right.text = "";
				}
			}
		}

		private static string DayText(int day)
		{
			string text = ((Localization.instance != null) ? Localization.instance.Localize("$msg_newday", new string[1] { day.ToString() }) : "");
			if (!string.IsNullOrEmpty(text) && !text.StartsWith("["))
			{
				return text;
			}
			return $"Day {day}";
		}

		private static string Clock(float seconds)
		{
			int num = Mathf.Max(0, Mathf.CeilToInt(seconds));
			return $"{num / 60}:{num % 60:00}";
		}

		private void Layout()
		{
			//IL_002c: 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_005f: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			int value = DayNightBar.BarHeight.Value;
			if (value != _height)
			{
				_height = value;
				_rect.anchoredPosition = new Vector2(0f, 6f);
				_rect.sizeDelta = new Vector2(-12f, (float)value);
				((Graphic)_strip).rectTransform.sizeDelta = new Vector2(0f, (float)value);
				float num = (float)value + 8f;
				Place(_sunIcon, 0.5f, num);
				Place(_moonLeft, 0.075f, num - 2f);
				Place(_moonRight, 0.925f, num - 2f);
				_marker.sizeDelta = new Vector2(2f, (float)value + 6f);
				_marker.anchoredPosition = new Vector2(0f, (float)value * 0.5f);
				TMP_Text[] array = (TMP_Text[])(object)new TMP_Text[3] { _left, _center, _right };
				for (int i = 0; i < array.Length; i++)
				{
					RectTransform rectTransform = array[i].rectTransform;
					rectTransform.sizeDelta = new Vector2(0f, 18f);
					rectTransform.anchoredPosition = new Vector2(0f, (float)value + 1f + 2f);
				}
			}
		}

		private void Place(RectTransform icon, float at, float size)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(at, 0f);
			icon.anchorMax = val;
			icon.anchorMin = val;
			icon.sizeDelta = new Vector2(size, size);
			icon.anchoredPosition = new Vector2(0f, (float)_height * 0.5f);
		}

		private void UpdateStrip()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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_0049: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			Color value = DayNightBar.DayColor.Value;
			Color value2 = DayNightBar.NightColor.Value;
			if (!((Object)(object)_stripTex != (Object)null) || !(value == _stripDay) || !(value2 == _stripNight))
			{
				_stripDay = value;
				_stripNight = value2;
				if ((Object)(object)_stripTex == (Object)null)
				{
					_stripTex = new Texture2D(256, 1, (TextureFormat)4, false)
					{
						wrapMode = (TextureWrapMode)1,
						filterMode = (FilterMode)1,
						hideFlags = (HideFlags)61
					};
				}
				Color[] array = (Color[])(object)new Color[256];
				for (int i = 0; i < 256; i++)
				{
					float num = ((float)i + 0.5f) / 256f;
					float num2 = Mathf.Min(Mathf.SmoothStep(0f, 1f, (num - 0.15f + 0.02f) / 0.04f), Mathf.SmoothStep(0f, 1f, (0.87f - num) / 0.04f));
					array[i] = Color.Lerp(value2, value, num2);
				}
				_stripTex.SetPixels(array);
				_stripTex.Apply();
				_strip.texture = (Texture)(object)_stripTex;
			}
		}

		private static Texture2D SunTexture()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			//IL_0044: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(32, 32, (TextureFormat)4, false)
			{
				hideFlags = (HideFlags)61
			};
			Color[] array = (Color[])(object)new Color[1024];
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(15.5f, 15.5f);
			for (int i = 0; i < 32; i++)
			{
				for (int j = 0; j < 32; j++)
				{
					Vector2 val3 = new Vector2((float)j, (float)i) - val2;
					float magnitude = ((Vector2)(ref val3)).magnitude;
					float num = Mathf.Clamp01(8.5f - magnitude);
					float num2 = Mathf.Pow(Mathf.Abs(Mathf.Cos(Mathf.Atan2(val3.y, val3.x) * 4f)), 12f);
					float num3 = ((magnitude > 10f && magnitude < 15f) ? (num2 * Mathf.Clamp01(15f - magnitude)) : 0f);
					array[i * 32 + j] = new Color(1f, 1f, 1f, Mathf.Clamp01(num + num3));
				}
			}
			val.SetPixels(array);
			val.Apply();
			return val;
		}

		private static Texture2D MoonTexture()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_00be: 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)
			Texture2D val = new Texture2D(32, 32, (TextureFormat)4, false)
			{
				hideFlags = (HideFlags)61
			};
			Color[] array = (Color[])(object)new Color[1024];
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(15.5f, 15.5f);
			Vector2 val3 = val2 + new Vector2(5f, 3f);
			Vector2 val4 = default(Vector2);
			for (int i = 0; i < 32; i++)
			{
				for (int j = 0; j < 32; j++)
				{
					((Vector2)(ref val4))..ctor((float)j, (float)i);
					Vector2 val5 = val4 - val2;
					float num = Mathf.Clamp01(12f - ((Vector2)(ref val5)).magnitude);
					val5 = val4 - val3;
					float num2 = Mathf.Clamp01(11f - ((Vector2)(ref val5)).magnitude);
					array[i * 32 + j] = new Color(1f, 1f, 1f, Mathf.Clamp01(num - num2));
				}
			}
			val.SetPixels(array);
			val.Apply();
			return val;
		}
	}
	internal static class FoodCallout
	{
		internal enum EmptyWhen
		{
			NoFood,
			AnySlotEmpty
		}

		[HarmonyPatch(typeof(Hud), "Update")]
		private static class EnsureOnHud
		{
			private static void Postfix()
			{
				if (Enabled.Value)
				{
					FoodCalloutHud.Ensure();
				}
			}
		}

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<bool> RunningOut;

		internal static ConfigEntry<float> ThresholdMinutes;

		internal static ConfigEntry<bool> CanEatAgain;

		internal static ConfigEntry<bool> NoFood;

		internal static ConfigEntry<EmptyWhen> NoFoodWhen;

		internal static ConfigEntry<KeyboardShortcut> DismissKey;

		internal static ConfigEntry<float> ShowSeconds;

		internal static ConfigEntry<bool> Sound;

		internal static ConfigEntry<float> SoundVolume;

		internal static ConfigEntry<float> AnchorX;

		internal static ConfigEntry<float> AnchorY;

		private const string Section = "Food Reminder";

		internal static void BindConfig(ConfigFile config)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			//IL_00d0: 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_0117: Expected O, but got Unknown
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Expected O, but got Unknown
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Expected O, but got Unknown
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Expected O, but got Unknown
			Enabled = config.Bind<bool>("Food Reminder", "Enabled", true, "Food reminders on the HUD. The switches below pick which ones.");
			RunningOut = config.Bind<bool>("Food Reminder", "RunningOut", true, "Remind when a food has less than Threshold Minutes left.");
			ThresholdMinutes = config.Bind<float>("Food Reminder", "ThresholdMinutes", 4f, new ConfigDescription("Running-out reminder: minutes left that trigger it.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 15f), Array.Empty<object>()));
			CanEatAgain = config.Bind<bool>("Food Reminder", "CanEatAgain", false, "Remind when a food can be eaten again (the game allows it once half its time has passed).");
			NoFood = config.Bind<bool>("Food Reminder", "NoFoodMessage", true, "Keep a message up while you have no food, until you eat or press Dismiss Key. Shows on a new character after the arrival, and after respawning.");
			NoFoodWhen = config.Bind<EmptyWhen>("Food Reminder", "NoFoodWhen", EmptyWhen.NoFood, "No Food: only when all your food is gone. Any Slot Empty: whenever a food slot is free.");
			DismissKey = config.Bind<KeyboardShortcut>("Food Reminder", "DismissKey", new KeyboardShortcut((KeyCode)8, Array.Empty<KeyCode>()), "Hides the no-food message until you next eat.");
			ShowSeconds = config.Bind<float>("Food Reminder", "ShowSeconds", 6f, new ConfigDescription("How long a reminder stays on screen.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, 20f), Array.Empty<object>()));
			Sound = config.Bind<bool>("Food Reminder", "Sound", true, "Play a soft chime with each reminder.");
			SoundVolume = config.Bind<float>("Food Reminder", "SoundVolume", 0.35f, new ConfigDescription("Chime volume (also follows the game's sound settings).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 1f), Array.Empty<object>()));
			AnchorX = config.Bind<float>("Food Reminder", "AnchorX", 0.5f, new ConfigDescription("Horizontal position of the reminder's center (0 = left, 1 = right).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			AnchorY = config.Bind<float>("Food Reminder", "AnchorY", 0.84f, new ConfigDescription("Vertical position of the reminder's top edge (0 = bottom, 1 = top). It moves down on its own to clear the raid banner.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		}
	}
	internal class FoodCalloutHud : MonoBehaviour
	{
		private enum Kind
		{
			RunningOut,
			CanEat,
			NoFood,
			Sample
		}

		private class Row
		{
			public string Key;

			public Kind Kind;

			public GameObject Root;

			public RectTransform Rect;

			public CanvasGroup Group;