Decompiled source of TimeWeatherHud v1.1.0

plugins/TimeWeatherHud.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyCompany("TimeWeatherHud")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+fdc653eb84a2a1e150ac954b2de87c82b225e85a")]
[assembly: AssemblyProduct("TimeWeatherHud")]
[assembly: AssemblyTitle("TimeWeatherHud")]
[assembly: AssemblyVersion("1.1.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace TimeWeatherHud
{
	internal enum WeatherKind
	{
		Clear,
		Cloudy,
		Mist,
		Rain,
		Storm,
		Snow,
		Blizzard,
		Ash,
		Boss,
		Indoor,
		Unknown
	}
	internal static class GameClock
	{
		private static readonly MethodInfo GetDayNoArgs = AccessTools.Method(typeof(EnvMan), "GetCurrentDay", Type.EmptyTypes, (Type[])null) ?? AccessTools.Method(typeof(EnvMan), "GetDay", Type.EmptyTypes, (Type[])null);

		private static readonly MethodInfo GetDayWithTime = AccessTools.Method(typeof(EnvMan), "GetDay", new Type[1] { typeof(double) }, (Type[])null);

		private static readonly FieldInfo DayLengthField = AccessTools.Field(typeof(EnvMan), "m_dayLengthSec");

		public static bool Ready
		{
			get
			{
				if ((Object)(object)EnvMan.instance != (Object)null)
				{
					return (Object)(object)ZNet.instance != (Object)null;
				}
				return false;
			}
		}

		public static int Day
		{
			get
			{
				EnvMan instance = EnvMan.instance;
				try
				{
					if (GetDayNoArgs != null)
					{
						return Convert.ToInt32(GetDayNoArgs.Invoke(instance, null));
					}
					if (GetDayWithTime != null)
					{
						return Convert.ToInt32(GetDayWithTime.Invoke(instance, new object[1] { ZNet.instance.GetTimeSeconds() }));
					}
				}
				catch (Exception)
				{
				}
				long val = ((DayLengthField != null) ? Convert.ToInt64(DayLengthField.GetValue(instance)) : 1800);
				return (int)(ZNet.instance.GetTimeSeconds() / (double)Math.Max(1L, val));
			}
		}

		public static float DayFraction => EnvMan.instance.GetDayFraction();

		public static bool IsNight => EnvMan.IsNight();

		public static string EnvironmentName => EnvMan.instance.GetCurrentEnvironment()?.m_name ?? "";

		public static string FormatTime(bool use24Hour)
		{
			int num = Mathf.FloorToInt(DayFraction * 24f * 60f) % 1440;
			int num2 = num / 60;
			int num3 = num % 60;
			if (use24Hour)
			{
				return $"{num2:00}:{num3:00}";
			}
			string arg = ((num2 < 12) ? "AM" : "PM");
			int num4 = ((num2 % 12 == 0) ? 12 : (num2 % 12));
			return $"{num4}:{num3:00} {arg}";
		}

		public static WeatherKind Classify(string env)
		{
			string text = (env ?? "").ToLowerInvariant();
			if (text.Length == 0)
			{
				return WeatherKind.Unknown;
			}
			string[] array = new string[8] { "eikthyr", "gdking", "bonemass", "moder", "goblinking", "queen", "fader", "boss" };
			foreach (string value in array)
			{
				if (text.Contains(value))
				{
					return WeatherKind.Boss;
				}
			}
			if (text.Contains("crypt") || text.Contains("cave") || text.Contains("dungeon") || text.Contains("interior"))
			{
				return WeatherKind.Indoor;
			}
			if (text.Contains("ash") || text.Contains("cinder"))
			{
				return WeatherKind.Ash;
			}
			if (text.Contains("snowstorm") || text.Contains("blizzard"))
			{
				return WeatherKind.Blizzard;
			}
			if (text.Contains("snow"))
			{
				return WeatherKind.Snow;
			}
			if (text.Contains("thunder") || text.Contains("storm"))
			{
				return WeatherKind.Storm;
			}
			if (text.Contains("rain"))
			{
				return WeatherKind.Rain;
			}
			if (text.Contains("mist") || text.Contains("fog"))
			{
				return WeatherKind.Mist;
			}
			if (text.Contains("dark") || text.Contains("cloud"))
			{
				return WeatherKind.Cloudy;
			}
			if (text.Contains("clear") || text.Contains("heath") || text.Contains("twilight"))
			{
				return WeatherKind.Clear;
			}
			return WeatherKind.Unknown;
		}
	}
	internal static class GameFont
	{
		private static TMP_FontAsset _font;

		private static Material _material;

		public static bool Ready => (Object)(object)_font != (Object)null;

		public static bool TryFind()
		{
			if ((Object)(object)_font != (Object)null)
			{
				return true;
			}
			if (Plugin.UseGameFont.Value)
			{
				if ((Object)(object)Hud.instance != (Object)null)
				{
					TMP_Text val = null;
					TMP_Text[] componentsInChildren = ((Component)Hud.instance).GetComponentsInChildren<TMP_Text>(true);
					foreach (TMP_Text val2 in componentsInChildren)
					{
						if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.font == (Object)null))
						{
							if ((Object)(object)val == (Object)null)
							{
								val = val2;
							}
							if (IsValheimSerif(((Object)val2.font).name))
							{
								val = val2;
								break;
							}
						}
					}
					if ((Object)(object)val != (Object)null)
					{
						_font = val.font;
					}
				}
				if ((Object)(object)_font == (Object)null)
				{
					TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
					foreach (TMP_FontAsset val3 in array)
					{
						if ((Object)(object)val3 != (Object)null && IsValheimSerif(((Object)val3).name))
						{
							_font = val3;
							break;
						}
					}
				}
			}
			if ((Object)(object)_font == (Object)null)
			{
				_font = TMP_Settings.defaultFontAsset;
			}
			if ((Object)(object)_font == (Object)null)
			{
				return false;
			}
			_material = MakeCrispMaterial(_font);
			int num = ((_font.fallbackFontAssetTable != null) ? _font.fallbackFontAssetTable.Count : 0);
			Plugin.Log.LogInfo((object)string.Format("HUD font: {0} (fallback fonts: {1}, material: {2})", ((Object)_font).name, num, ((Object)(object)_material != (Object)null) ? ((Object)_material).name : "default"));
			return true;
		}

		private static Material MakeCrispMaterial(TMP_FontAsset font)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)font == (Object)null || (Object)(object)((TMP_Asset)font).material == (Object)null)
			{
				return null;
			}
			Material val = new Material(((TMP_Asset)font).material)
			{
				name = "TimeWeatherHud Crisp"
			};
			SetIf(val, "_Sharpness", 0.35f);
			SetIf(val, "_FaceDilate", 0.05f);
			SetIf(val, "_OutlineWidth", 0f);
			if (val.HasProperty("_UnderlayColor"))
			{
				val.EnableKeyword("UNDERLAY_ON");
				val.SetColor("_UnderlayColor", new Color(0f, 0f, 0f, 0.85f));
				SetIf(val, "_UnderlayOffsetX", 0.55f);
				SetIf(val, "_UnderlayOffsetY", -0.55f);
				SetIf(val, "_UnderlayDilate", 0.1f);
				SetIf(val, "_UnderlaySoftness", 0.05f);
			}
			return val;
		}

		private static void SetIf(Material m, string prop, float value)
		{
			if (m.HasProperty(prop))
			{
				m.SetFloat(prop, value);
			}
		}

		public static void Apply(TMP_Text text)
		{
			text.font = _font;
			if ((Object)(object)_material != (Object)null)
			{
				text.fontSharedMaterial = _material;
			}
		}

		private static bool IsValheimSerif(string name)
		{
			if (name != null)
			{
				return name.IndexOf("Averia", StringComparison.OrdinalIgnoreCase) >= 0;
			}
			return false;
		}
	}
	internal class HudRenderer : MonoBehaviour
	{
		private struct Segment
		{
			public Texture2D Icon;

			public string Label;

			public Color Color;
		}

		private class SegmentView
		{
			public RawImage Divider;

			public RawImage Icon;

			public TextMeshProUGUI Label;

			public TextMeshProUGUI LabelShadow;

			public float Width;
		}

		private const float CompassHeight = 26f;

		private const float ReadoutHeight = 18f;

		private const float CompassInset = 3f;

		private const float CardinalSize = 15f;

		private const float MinorCardinalSize = 12f;

		private const float DegreeSize = 10f;

		private const float ReadoutSize = 13f;

		private static readonly Color North = new Color(0.95f, 0.35f, 0.25f);

		private static readonly string[] Cardinals = new string[8] { "N", "NE", "E", "SE", "S", "SW", "W", "NW" };

		private RectTransform _strip;

		private readonly List<RawImage> _ticks = new List<RawImage>();

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

		private RawImage _centerLine;

		private RawImage _marker;

		private TextMeshProUGUI _readout;

		private TextMeshProUGUI _readoutShadow;

		private Texture2D _markerTex;

		private const float PanelHeight = 38f;

		private const float IconSize = 24f;

		private const float PadX = 14f;

		private const float Gap = 7f;

		private const float SectionGap = 16f;

		private const float PanelFontSize = 18f;

		private const float RefreshSeconds = 0.25f;

		private const int MaxSegments = 2;

		private static readonly Color Gold = new Color(1f, 0.8f, 0.45f);

		private static readonly Color Text = new Color(0.93f, 0.88f, 0.8f);

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

		private static readonly Color Shadow = new Color(0f, 0f, 0f, 0.85f);

		private static readonly Vector2 ShadowOffset = new Vector2(1f, -1.5f);

		private readonly List<Segment> _segments = new List<Segment>();

		private readonly List<SegmentView> _segmentViews = new List<SegmentView>();

		private float _nextRefresh;

		private float _contentWidth;

		private bool _built;

		private GameObject _canvasObject;

		private Canvas _canvas;

		private RectTransform _root;

		private RawImage _frame;

		private RawImage _hLine;

		private Texture2D _frameTex;

		private Texture2D _hLineTex;

		private Texture2D _vLineTex;

		private Texture2D _whiteTex;

		private const float MarkerRowHeight = 24f;

		private const float PinIconSize = 15f;

		private const float PinTextSize = 9.5f;

		private const float EdgeMargin = 9f;

		private const float EdgeStep = 15f;

		private readonly List<Marker> _markers = new List<Marker>();

		private RectTransform _pinRow;

		private readonly List<Image> _pinIcons = new List<Image>();

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

		private static float Heading()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			Camera main = Camera.main;
			Transform val = (((Object)(object)main != (Object)null) ? ((Component)main).transform : (((Object)(object)Player.m_localPlayer != (Object)null) ? ((Component)Player.m_localPlayer).transform : null));
			if (!((Object)(object)val == (Object)null))
			{
				return Mathf.Repeat(val.eulerAngles.y, 360f);
			}
			return 0f;
		}

		private void BuildCompass()
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			_strip = NewRect("CompassStrip", (Transform)(object)_root);
			((Component)_strip).gameObject.AddComponent<RectMask2D>();
			_markerTex = MakeTriangle(24, 16);
			_centerLine = NewImage("CompassCenter", (Transform)(object)_root, (Texture)(object)_whiteTex);
			((Graphic)_centerLine).color = new Color(Gold.r, Gold.g, Gold.b, 0.55f);
			_marker = NewImage("CompassMarker", (Transform)(object)_root, (Texture)(object)_markerTex);
			((Graphic)_marker).color = Gold;
			_readoutShadow = NewText("HeadingShadow", (Transform)(object)_root, 13f, (TextAlignmentOptions)514);
			((Graphic)_readoutShadow).color = Shadow;
			_readout = NewText("Heading", (Transform)(object)_root, 13f, (TextAlignmentOptions)514);
			((Graphic)_readout).color = Gold;
			BuildMarkers();
		}

		private void SetCompassActive(bool on)
		{
			SetActive((Component)(object)_strip, on);
			SetActive((Component)(object)_centerLine, on);
			SetActive((Component)(object)_marker, on);
			SetActive((Component)(object)_readout, on && Plugin.ShowHeading.Value);
			SetActive((Component)(object)_readoutShadow, on: false);
			if (!on)
			{
				SetActive((Component)(object)_pinRow, on: false);
			}
		}

		private void LayoutCompass(float top, float width, float boxHeight)
		{
			//IL_014d: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			float num = width - 6f;
			float num2 = 20f;
			Place(_strip, 3f, top + 3f, num, num2);
			float num3 = Heading();
			float value = Plugin.CompassRange.Value;
			float num4 = value / 2f;
			float num5 = num / value;
			float num6 = num / 2f;
			int num7 = 0;
			int num8 = 0;
			int num9 = Mathf.CeilToInt((num3 - num4) / 5f) * 5;
			int num10 = Mathf.FloorToInt((num3 + num4) / 5f) * 5;
			for (int i = num9; i <= num10; i += 5)
			{
				float num11 = (float)i - num3;
				float x = num6 + num11 * num5;
				float num12 = EdgeFade(Mathf.Abs(num11) / num4);
				if (!(num12 <= 0.01f))
				{
					int num13 = (i % 360 + 360) % 360;
					if (num13 % 45 == 0)
					{
						bool flag = num13 % 90 == 0;
						Color color = ((num13 == 0) ? North : (flag ? Gold : Text));
						Mark(num8++, x, num2 - 3f, Cardinals[num13 / 45], flag ? 15f : 12f, color, num12);
					}
					else if (num13 % 15 == 0)
					{
						Mark(num8++, x, num2 - 5f, num13.ToString(), 10f, Dim, num12);
						Tick(num7++, x, num2, 5f, num12 * 0.8f);
					}
					else
					{
						Tick(num7++, x, num2, 3f, num12 * 0.5f);
					}
				}
			}
			for (int j = num7; j < _ticks.Count; j++)
			{
				SetActive((Component)(object)_ticks[j], on: false);
			}
			for (int k = num8; k < _marks.Count; k++)
			{
				SetActive((Component)(object)_marks[k], on: false);
			}
			LayoutMarkers(top + 26f - 3f, width, num3);
			float num14 = width / 2f;
			float num15 = top + 3f;
			Place(((Graphic)_centerLine).rectTransform, num14 - 0.75f, num15 + 5f, 1.5f, num2 - 5f);
			Place(((Graphic)_marker).rectTransform, num14 - 5f, num15 - 1f, 10f, 7f);
			if (Plugin.ShowHeading.Value)
			{
				int num16 = Mathf.RoundToInt(num3) % 360;
				string text = num16 + "°  " + Cardinals[Mathf.RoundToInt((float)num16 / 45f) % 8];
				if (((TMP_Text)_readout).text != text)
				{
					((TMP_Text)_readout).text = text;
					((TMP_Text)_readoutShadow).text = text;
				}
				Place(((TMP_Text)_readoutShadow).rectTransform, num14 - 60f + ShadowOffset.x, boxHeight - ShadowOffset.y, 120f, 18f);
				Place(((TMP_Text)_readout).rectTransform, num14 - 60f, boxHeight, 120f, 18f);
			}
		}

		private static float EdgeFade(float t)
		{
			return 1f - Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.55f, 1f, t));
		}

		private void Tick(int index, float x, float innerH, float length, float alpha)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			if (index >= _ticks.Count)
			{
				_ticks.Add(NewImage("Tick", (Transform)(object)_strip, (Texture)(object)_whiteTex));
			}
			RawImage obj = _ticks[index];
			SetActive((Component)(object)obj, on: true);
			((Graphic)obj).color = new Color(Text.r, Text.g, Text.b, alpha);
			Place(((Graphic)obj).rectTransform, x - 0.5f, innerH - length - 1f, 1f, length);
		}

		private void Mark(int index, float x, float height, string text, float size, Color color, float alpha)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			if (index >= _marks.Count)
			{
				_marks.Add(NewText("Mark", (Transform)(object)_strip, size, (TextAlignmentOptions)514));
			}
			TextMeshProUGUI val = _marks[index];
			SetActive((Component)(object)val, on: true);
			if (((TMP_Text)val).text != text)
			{
				((TMP_Text)val).text = text;
			}
			if (!Mathf.Approximately(((TMP_Text)val).fontSize, size))
			{
				((TMP_Text)val).fontSize = size;
			}
			((Graphic)val).color = new Color(color.r, color.g, color.b, alpha);
			Place(((TMP_Text)val).rectTransform, x - 20f, 0f, 40f, height);
		}

		private static Texture2D MakeTriangle(int w, int h)
		{
			//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_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(w, h, (TextureFormat)4, false)
			{
				wrapMode = (TextureWrapMode)1,
				filterMode = (FilterMode)1,
				hideFlags = (HideFlags)61
			};
			for (int i = 0; i < h; i++)
			{
				float num = ((float)i + 0.5f) / (float)h * ((float)w / 2f);
				for (int j = 0; j < w; j++)
				{
					float num2 = Mathf.Clamp01(num - Mathf.Abs((float)j + 0.5f - (float)w / 2f) + 0.5f);
					val.SetPixel(j, i, new Color(1f, 1f, 1f, num2));
				}
			}
			val.Apply();
			return val;
		}

		private void Update()
		{
			//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)
			KeyboardShortcut value = Plugin.ToggleKey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown() && (Object)(object)Player.m_localPlayer != (Object)null)
			{
				Plugin.Enabled.Value = !Plugin.Enabled.Value;
				Plugin.Log.LogInfo((object)("HUD " + (Plugin.Enabled.Value ? "shown" : "hidden")));
			}
			bool flag = ShouldShow();
			if (flag && !_built)
			{
				_built = TryBuild();
			}
			flag &= _built;
			if ((Object)(object)_canvasObject != (Object)null && _canvasObject.activeSelf != flag)
			{
				_canvasObject.SetActive(flag);
			}
			if (flag)
			{
				if (Time.unscaledTime >= _nextRefresh)
				{
					_nextRefresh = Time.unscaledTime + 0.25f;
					Rebuild();
				}
				Layout();
			}
		}

		private void OnDestroy()
		{
			if ((Object)(object)_canvasObject != (Object)null)
			{
				Object.Destroy((Object)(object)_canvasObject);
			}
		}

		private static bool ShouldShow()
		{
			if (!Plugin.Enabled.Value || (Object)(object)Player.m_localPlayer == (Object)null || !GameClock.Ready)
			{
				return false;
			}
			if ((Object)(object)Hud.instance == (Object)null || Traverse.Create((object)Hud.instance).Field("m_userHidden").GetValue<bool>())
			{
				return false;
			}
			if (Minimap.IsOpen() || InventoryGui.IsVisible() || Menu.IsVisible())
			{
				return false;
			}
			return true;
		}

		private void Rebuild()
		{
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			_segments.Clear();
			try
			{
				bool isNight = GameClock.IsNight;
				if (Plugin.ShowDay.Value || Plugin.ShowTime.Value)
				{
					string text = "";
					if (Plugin.ShowDay.Value)
					{
						text = Lang.T("day", GameClock.Day);
					}
					if (Plugin.ShowTime.Value)
					{
						text = text + ((text.Length > 0) ? "  ·  " : "") + GameClock.FormatTime(Plugin.Use24Hour.Value);
					}
					_segments.Add(new Segment
					{
						Icon = (isNight ? Icons.MoonIcon : Icons.SunIcon),
						Label = text,
						Color = Gold
					});
				}
				if (Plugin.ShowWeather.Value)
				{
					string environmentName = GameClock.EnvironmentName;
					WeatherKind kind = GameClock.Classify(environmentName);
					_segments.Add(new Segment
					{
						Icon = Icons.Weather(kind, isNight),
						Label = Lang.Weather(kind, environmentName),
						Color = Text
					});
				}
			}
			catch (Exception ex)
			{
				_segments.Clear();
				Plugin.Log.LogWarning((object)("Could not read time/weather: " + ex.Message));
				_nextRefresh = Time.unscaledTime + 5f;
			}
			try
			{
				MarkerTracker.Collect(_markers, ((Component)Player.m_localPlayer).transform.position);
			}
			catch (Exception ex2)
			{
				_markers.Clear();
				Plugin.Log.LogWarning((object)("Could not read map pins: " + ex2.Message));
			}
			_contentWidth = 28f;
			for (int i = 0; i < _segmentViews.Count; i++)
			{
				SegmentView segmentView = _segmentViews[i];
				bool flag = i < _segments.Count;
				SetActive((Component)(object)segmentView.Icon, flag);
				SetActive((Component)(object)segmentView.Label, flag);
				SetActive((Component)(object)segmentView.LabelShadow, on: false);
				SetActive((Component)(object)segmentView.Divider, flag && i > 0);
				if (flag)
				{
					Segment segment = _segments[i];
					segmentView.Icon.texture = (Texture)(object)segment.Icon;
					string text2 = BoldHangul(segment.Label);
					if (((TMP_Text)segmentView.Label).text != text2)
					{
						((TMP_Text)segmentView.Label).text = text2;
						((TMP_Text)segmentView.LabelShadow).text = text2;
						segmentView.Width = ((TMP_Text)segmentView.Label).GetPreferredValues(text2).x;
					}
					((Graphic)segmentView.Label).color = segment.Color;
					_contentWidth += 31f + segmentView.Width + ((i > 0) ? 33f : 0f);
				}
			}
		}

		private void Layout()
		{
			bool flag = _segments.Count > 0;
			bool value = Plugin.ShowCompass.Value;
			SetActive((Component)(object)_frame, flag || value);
			SetActive((Component)(object)_hLine, flag && value);
			SetCompassActive(value);
			if (!flag && !value)
			{
				return;
			}
			float num = Mathf.Max(flag ? _contentWidth : 0f, value ? Plugin.CompassWidth.Value : 0f);
			float num2 = ((flag && value) ? 61f : (flag ? 38f : 26f));
			if (value && _markers.Count > 0)
			{
				num2 += 24f;
			}
			float h = num2 + ((value && Plugin.ShowHeading.Value) ? 18f : 0f);
			PlaceRoot(num, h);
			UpdateFrame(num, num2);
			if (flag)
			{
				LayoutPanel(num);
				if (value)
				{
					Place(((Graphic)_hLine).rectTransform, 8f, 37f, num - 16f, 1f);
				}
			}
			if (value)
			{
				LayoutCompass(flag ? 35f : 0f, num, num2);
			}
		}

		private void LayoutPanel(float width)
		{
			float num = (width - _contentWidth) / 2f + 14f;
			for (int i = 0; i < _segments.Count && i < _segmentViews.Count; i++)
			{
				SegmentView segmentView = _segmentViews[i];
				if (i > 0)
				{
					num += 16f;
					Place(((Graphic)segmentView.Divider).rectTransform, num, 6f, 1f, 26f);
					num += 17f;
				}
				Place(((Graphic)segmentView.Icon).rectTransform, num, 7f, 24f, 24f);
				num += 31f;
				Place(((TMP_Text)segmentView.LabelShadow).rectTransform, num + ShadowOffset.x, 0f - ShadowOffset.y, segmentView.Width + 4f, 38f);
				Place(((TMP_Text)segmentView.Label).rectTransform, num, 0f, segmentView.Width + 4f, 38f);
				num += segmentView.Width;
			}
		}

		private void PlaceRoot(float w, float h)
		{
			//IL_0104: 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)
			//IL_0106: 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_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: 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_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			float value = Plugin.OffsetX.Value;
			float value2 = Plugin.OffsetY.Value;
			Vector2 val = default(Vector2);
			Vector2 anchoredPosition = default(Vector2);
			switch (Plugin.Anchor.Value)
			{
			case HudAnchor.TopLeft:
				((Vector2)(ref val))..ctor(0f, 1f);
				((Vector2)(ref anchoredPosition))..ctor(value, 0f - value2);
				break;
			case HudAnchor.TopRight:
				((Vector2)(ref val))..ctor(1f, 1f);
				((Vector2)(ref anchoredPosition))..ctor(0f - value, 0f - value2);
				break;
			case HudAnchor.BottomLeft:
				((Vector2)(ref val))..ctor(0f, 0f);
				((Vector2)(ref anchoredPosition))..ctor(value, value2);
				break;
			case HudAnchor.BottomRight:
				((Vector2)(ref val))..ctor(1f, 0f);
				((Vector2)(ref anchoredPosition))..ctor(0f - value, value2);
				break;
			case HudAnchor.BottomCenter:
				((Vector2)(ref val))..ctor(0.5f, 0f);
				((Vector2)(ref anchoredPosition))..ctor(value, value2);
				break;
			default:
				((Vector2)(ref val))..ctor(0.5f, 1f);
				((Vector2)(ref anchoredPosition))..ctor(value, 0f - value2);
				break;
			}
			RectTransform root = _root;
			RectTransform root2 = _root;
			Vector2 val2 = (_root.pivot = val);
			Vector2 anchorMin = (root2.anchorMax = val2);
			root.anchorMin = anchorMin;
			_root.anchoredPosition = anchoredPosition;
			_root.sizeDelta = new Vector2(w, h);
			float value3 = Plugin.Scale.Value;
			((Transform)_root).localScale = new Vector3(value3, value3, 1f);
		}

		private void UpdateFrame(float width, float height)
		{
			float num = _canvas.scaleFactor * Plugin.Scale.Value;
			int num2 = Mathf.Max(8, Mathf.RoundToInt(width * num));
			int num3 = Mathf.Max(8, Mathf.RoundToInt(height * num));
			if ((Object)(object)_frameTex == (Object)null || ((Texture)_frameTex).width != num2 || ((Texture)_frameTex).height != num3)
			{
				if ((Object)(object)_frameTex != (Object)null)
				{
					Object.Destroy((Object)(object)_frameTex);
				}
				_frameTex = PanelArt.Frame(num2, num3, num);
				_frame.texture = (Texture)(object)_frameTex;
			}
			Place(((Graphic)_frame).rectTransform, 0f, 0f, width, height);
		}

		private bool TryBuild()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: 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)
			if (!GameFont.TryFind())
			{
				return false;
			}
			_canvasObject = new GameObject("TimeWeatherHudCanvas");
			_canvasObject.transform.SetParent(((Component)this).transform, false);
			_canvas = _canvasObject.AddComponent<Canvas>();
			_canvas.renderMode = (RenderMode)0;
			_canvas.pixelPerfect = true;
			_canvas.sortingOrder = 1;
			CanvasScaler obj = _canvasObject.AddComponent<CanvasScaler>();
			obj.uiScaleMode = (ScaleMode)1;
			obj.referenceResolution = new Vector2(1920f, 1080f);
			obj.screenMatchMode = (ScreenMatchMode)0;
			obj.matchWidthOrHeight = 1f;
			_root = NewRect("Hud", _canvasObject.transform);
			_hLineTex = PanelArt.FadeLine(horizontal: true);
			_vLineTex = PanelArt.FadeLine(horizontal: false);
			_whiteTex = MakeFlat(Color.white);
			_frame = NewImage("Frame", (Transform)(object)_root, null);
			for (int i = 0; i < 2; i++)
			{
				SegmentView segmentView = new SegmentView
				{
					Divider = NewImage("Divider" + i, (Transform)(object)_root, (Texture)(object)_vLineTex),
					Icon = NewImage("Icon" + i, (Transform)(object)_root, null),
					LabelShadow = NewText("LabelShadow" + i, (Transform)(object)_root, 18f, (TextAlignmentOptions)4097),
					Label = NewText("Label" + i, (Transform)(object)_root, 18f, (TextAlignmentOptions)4097)
				};
				((Graphic)segmentView.LabelShadow).color = Shadow;
				_segmentViews.Add(segmentView);
			}
			_hLine = NewImage("Line", (Transform)(object)_root, (Texture)(object)_hLineTex);
			BuildCompass();
			_nextRefresh = 0f;
			return true;
		}

		private static RectTransform NewRect(string name, Transform parent)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0031: 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_0044: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			RectTransform val2 = (RectTransform)val.transform;
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0f, 1f);
			val2.pivot = val3;
			Vector2 anchorMin = (val2.anchorMax = val3);
			val2.anchorMin = anchorMin;
			return val2;
		}

		private static RawImage NewImage(string name, Transform parent, Texture texture)
		{
			RawImage obj = ((Component)NewRect(name, parent)).gameObject.AddComponent<RawImage>();
			obj.texture = texture;
			((Graphic)obj).raycastTarget = false;
			return obj;
		}

		private static TextMeshProUGUI NewText(string name, Transform parent, float size, TextAlignmentOptions align)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI obj = ((Component)NewRect(name, parent)).gameObject.AddComponent<TextMeshProUGUI>();
			GameFont.Apply((TMP_Text)(object)obj);
			((TMP_Text)obj).fontSize = size;
			((TMP_Text)obj).alignment = align;
			((TMP_Text)obj).textWrappingMode = (TextWrappingModes)0;
			((TMP_Text)obj).overflowMode = (TextOverflowModes)0;
			((TMP_Text)obj).richText = true;
			((Graphic)obj).raycastTarget = false;
			return obj;
		}

		private static void Place(RectTransform rt, float x, float y, float w, float h)
		{
			//IL_0004: 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)
			rt.anchoredPosition = new Vector2(x, 0f - y);
			rt.sizeDelta = new Vector2(w, h);
		}

		private static void SetActive(Component c, bool on)
		{
			if ((Object)(object)c != (Object)null && c.gameObject.activeSelf != on)
			{
				c.gameObject.SetActive(on);
			}
		}

		internal static string BoldHangul(string text)
		{
			StringBuilder stringBuilder = new StringBuilder(text.Length + 16);
			bool flag = false;
			foreach (char c in text)
			{
				bool flag2 = IsHangul(c);
				if (flag2 && !flag)
				{
					stringBuilder.Append("<b>");
					flag = true;
				}
				else if (!flag2 && flag)
				{
					stringBuilder.Append("</b>");
					flag = false;
				}
				if (c == '<')
				{
					stringBuilder.Append("<noparse><</noparse>");
				}
				else
				{
					stringBuilder.Append(c);
				}
			}
			if (flag)
			{
				stringBuilder.Append("</b>");
			}
			return stringBuilder.ToString();
		}

		private static bool IsHangul(char ch)
		{
			if ((ch < '가' || ch > '힣') && (ch < 'ᄀ' || ch > 'ᇿ'))
			{
				if (ch >= '\u3130')
				{
					return ch <= '\u318f';
				}
				return false;
			}
			return true;
		}

		private static Texture2D MakeFlat(Color c)
		{
			//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_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false)
			{
				hideFlags = (HideFlags)61
			};
			val.SetPixel(0, 0, c);
			val.Apply();
			return val;
		}

		private void BuildMarkers()
		{
			_pinRow = NewRect("MarkerRow", (Transform)(object)_root);
			((Component)_pinRow).gameObject.AddComponent<RectMask2D>();
		}

		private void LayoutMarkers(float y, float width, float heading)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: 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_0281: Unknown result type (might be due to invalid IL or missing references)
			bool flag = _markers.Count > 0 && (Object)(object)Player.m_localPlayer != (Object)null;
			SetActive((Component)(object)_pinRow, flag);
			if (!flag)
			{
				return;
			}
			float num = width - 6f;
			Place(_pinRow, 3f, y, num, 24f);
			float value = Plugin.CompassRange.Value;
			float num2 = value / 2f;
			float num3 = num / value;
			float num4 = num / 2f;
			Vector3 position = ((Component)Player.m_localPlayer).transform.position;
			int count = _markers.Count;
			int num5 = 0;
			int num6 = 0;
			for (int i = 0; i < count; i++)
			{
				int index = count - 1 - i;
				Marker marker = _markers[index];
				float num7 = marker.Position.x - position.x;
				float num8 = marker.Position.z - position.z;
				float num9 = Mathf.Atan2(num7, num8) * 57.29578f;
				float num10 = Mathf.DeltaAngle(heading, num9);
				bool num11 = Mathf.Abs(num10) <= num2;
				float num12 = (num11 ? Mathf.Clamp(num4 + num10 * num3, 9f, num - 9f) : ((!(num10 < 0f)) ? (num - 9f - 15f * (float)num6++) : (9f + 15f * (float)num5++)));
				float num13 = (num11 ? Mathf.Lerp(1f, 0.6f, Mathf.InverseLerp(0.7f, 1f, Mathf.Abs(num10) / num2)) : 0.4f);
				Image obj = PinIcon(i);
				obj.sprite = marker.Icon;
				((Graphic)obj).color = (((Object)(object)marker.Icon != (Object)null) ? new Color(1f, 1f, 1f, num13) : new Color(Gold.r, Gold.g, Gold.b, num13));
				Place(((Graphic)obj).rectTransform, num12 - 7.5f, 1f, 15f, 15f);
				TextMeshProUGUI val = PinLabel(i);
				if (!num11)
				{
					SetActive((Component)(object)val, on: false);
					continue;
				}
				string text = Lang.Distance(Mathf.Sqrt(num7 * num7 + num8 * num8));
				if (((TMP_Text)val).text != text)
				{
					((TMP_Text)val).text = text;
				}
				((Graphic)val).color = new Color(Text.r, Text.g, Text.b, num13);
				Place(((TMP_Text)val).rectTransform, num12 - 26f, 14f, 52f, 10f);
			}
			for (int j = count; j < _pinIcons.Count; j++)
			{
				SetActive((Component)(object)_pinIcons[j], on: false);
			}
			for (int k = count; k < _pinLabels.Count; k++)
			{
				SetActive((Component)(object)_pinLabels[k], on: false);
			}
		}

		private Image PinIcon(int index)
		{
			while (_pinIcons.Count <= index)
			{
				Image val = ((Component)NewRect("Pin", (Transform)(object)_pinRow)).gameObject.AddComponent<Image>();
				val.preserveAspect = true;
				((Graphic)val).raycastTarget = false;
				_pinIcons.Add(val);
			}
			SetActive((Component)(object)_pinIcons[index], on: true);
			return _pinIcons[index];
		}

		private TextMeshProUGUI PinLabel(int index)
		{
			while (_pinLabels.Count <= index)
			{
				_pinLabels.Add(NewText("PinDistance", (Transform)(object)_pinRow, 9.5f, (TextAlignmentOptions)514));
			}
			SetActive((Component)(object)_pinLabels[index], on: true);
			return _pinLabels[index];
		}
	}
	internal static class Icons
	{
		private delegate Color Shader(float x, float y);

		private const int Size = 64;

		private static readonly Color Sun = new Color(1f, 0.78f, 0.3f);

		private static readonly Color Moon = new Color(0.86f, 0.9f, 1f);

		private static readonly Color CloudLight = new Color(0.9f, 0.9f, 0.92f);

		private static readonly Color CloudDark = new Color(0.55f, 0.58f, 0.64f);

		private static readonly Color Water = new Color(0.45f, 0.78f, 1f);

		private static readonly Color Bolt = new Color(1f, 0.85f, 0.25f);

		private static readonly Color SnowWhite = new Color(0.97f, 0.99f, 1f);

		private static readonly Color Ember = new Color(1f, 0.5f, 0.18f);

		private static readonly Color BossRed = new Color(0.95f, 0.25f, 0.2f);

		private static readonly Color Stone = new Color(0.62f, 0.55f, 0.48f);

		private static readonly Color Outline = new Color(0.05f, 0.035f, 0.025f, 0.95f);

		private static readonly Dictionary<string, Texture2D> Cache = new Dictionary<string, Texture2D>();

		public static Texture2D SunIcon => Get("sun", DrawSun);

		public static Texture2D MoonIcon => Get("moon", DrawMoon);

		public static Texture2D Weather(WeatherKind kind, bool night)
		{
			switch (kind)
			{
			case WeatherKind.Clear:
				if (!night)
				{
					return SunIcon;
				}
				return MoonIcon;
			case WeatherKind.Cloudy:
				return Get("cloudy", (Shader s) => Cloud(s, 0f, CloudDark));
			case WeatherKind.Mist:
				return Get("mist", DrawMist);
			case WeatherKind.Rain:
				return Get("rain", (Shader s) => Precip(s, CloudDark, (float x, float y) => Drop(x, y, Water)));
			case WeatherKind.Storm:
				return Get("storm", DrawStorm);
			case WeatherKind.Snow:
				return Get("snow", (Shader s) => Precip(s, CloudLight, (float x, float y) => Dot(x, y, 3.2f, SnowWhite)));
			case WeatherKind.Blizzard:
				return Get("blizzard", DrawBlizzard);
			case WeatherKind.Ash:
				return Get("ash", (Shader s) => Precip(s, new Color(0.35f, 0.3f, 0.28f), (float x, float y) => Dot(x, y, 3f, Ember)));
			case WeatherKind.Boss:
				return Get("boss", DrawBoss);
			case WeatherKind.Indoor:
				return Get("indoor", DrawIndoor);
			default:
				return Get("cloudy", (Shader s) => Cloud(s, 0f, CloudDark));
			}
		}

		private static Texture2D Get(string key, Func<Shader, Shader> build)
		{
			if (Cache.TryGetValue(key, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			value = Render(build(null));
			Cache[key] = value;
			return value;
		}

		private static Texture2D Get(string key, Func<Shader> build)
		{
			if (Cache.TryGetValue(key, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			value = Render(build());
			Cache[key] = value;
			return value;
		}

		private static Texture2D Render(Shader shader)
		{
			//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_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0050: 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)
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1,
				wrapMode = (TextureWrapMode)1,
				hideFlags = (HideFlags)61
			};
			Color[] array = (Color[])(object)new Color[4096];
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					array[i * 64 + j] = shader((float)j + 0.5f, (float)(63 - i) + 0.5f);
				}
			}
			val.SetPixels(array);
			val.Apply(false);
			return val;
		}

		private static Color Fill(float d, Color c)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			if (d > 2.6f)
			{
				return Color.clear;
			}
			float num = Mathf.Clamp01(0.5f - d);
			float num2 = Mathf.Clamp01(2.1f - d) * (1f - num);
			Color result = Color.Lerp(Outline, c, num);
			result.a = Mathf.Max(num, num2 * Outline.a);
			return result;
		}

		private static Color Over(Color top, Color bottom)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_002a: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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)
			float num = top.a + bottom.a * (1f - top.a);
			if (num <= 0f)
			{
				return Color.clear;
			}
			Color result = (top * top.a + bottom * bottom.a * (1f - top.a)) / num;
			result.a = num;
			return result;
		}

		private static float Circle(float x, float y, float cx, float cy, float r)
		{
			return Mathf.Sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy)) - r;
		}

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

		private static Shader DrawSun()
		{
			return delegate(float x, float y)
			{
				//IL_008e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0093: Unknown result type (might be due to invalid IL or missing references)
				float num = Circle(x, y, 32f, 32f, 12f);
				for (int i = 0; i < 8; i++)
				{
					float num2 = (float)i * (float)Math.PI / 4f;
					num = Mathf.Min(num, Segment(x, y, 32f + Mathf.Cos(num2) * 19f, 32f + Mathf.Sin(num2) * 19f, 32f + Mathf.Cos(num2) * 26f, 32f + Mathf.Sin(num2) * 26f, 2.6f));
				}
				return Fill(num, Sun);
			};
		}

		private static Shader DrawMoon()
		{
			return (float x, float y) => Fill(Mathf.Max(Circle(x, y, 30f, 32f, 20f), 0f - Circle(x, y, 40f, 26f, 17f)), Moon);
		}

		private static Shader Cloud(Shader below, float dy, Color color)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			return delegate(float x, float y)
			{
				//IL_0095: Unknown result type (might be due to invalid IL or missing references)
				//IL_009a: Unknown result type (might be due to invalid IL or missing references)
				//IL_009f: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
				Color val = Fill(Mathf.Min(Mathf.Min(Circle(x, y, 22f, 34f - dy, 11f), Circle(x, y, 36f, 27f - dy, 14f)), Mathf.Min(Circle(x, y, 47f, 36f - dy, 9f), Segment(x, y, 20f, 41f - dy, 48f, 41f - dy, 5f))), color);
				return (below != null) ? Over(val, below(x, y)) : val;
			};
		}

		private static Shader Cloud(Shader below, float dy)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			return Cloud(below, dy, CloudLight);
		}

		private static Shader Precip(Shader _, Color cloud, Func<float, float, Shader> particle)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			Shader p1 = particle(22f, 54f);
			Shader p2 = particle(33f, 58f);
			Shader p3 = particle(44f, 54f);
			return Cloud((float x, float y) => Over(p1(x, y), Over(p2(x, y), p3(x, y))), 8f, cloud);
		}

		private static Shader Drop(float cx, float cy, Color c)
		{
			//IL_0014: 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)
			return (float x, float y) => Fill(Segment(x, y, cx + 2f, cy - 5f, cx - 1f, cy + 3f, 2.4f), c);
		}

		private static Shader Dot(float cx, float cy, float r, Color c)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			return (float x, float y) => Fill(Circle(x, y, cx, cy, r), c);
		}

		private static Shader DrawStorm()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			return Cloud((float x, float y) => Fill(Mathf.Min(Segment(x, y, 37f, 42f, 29f, 52f, 2.8f), Mathf.Min(Segment(x, y, 29f, 52f, 37f, 52f, 2.8f), Segment(x, y, 37f, 52f, 28f, 62f, 2.8f))), Bolt), 8f, CloudDark);
		}

		private static Shader DrawBlizzard()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			return Cloud(delegate(float x, float y)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_007d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0082: Unknown result type (might be due to invalid IL or missing references)
				//IL_0087: Unknown result type (might be due to invalid IL or missing references)
				//IL_0088: Unknown result type (might be due to invalid IL or missing references)
				//IL_008d: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
				Color bottom = Color.clear;
				float[] array = new float[4] { 18f, 30f, 42f, 54f };
				float[] array2 = new float[4] { 50f, 57f, 50f, 57f };
				for (int i = 0; i < array.Length; i++)
				{
					float num = array[i];
					float num2 = array2[i];
					bottom = Over(Fill(Mathf.Min(Segment(x, y, num - 4f, num2, num + 4f, num2, 1.5f), Segment(x, y, num, num2 - 4f, num, num2 + 4f, 1.5f)), SnowWhite), bottom);
				}
				return Over(Fill(Segment(x, y, 8f, 44f, 24f, 44f, 1.6f), CloudLight), bottom);
			}, 10f, CloudLight);
		}

		private static Shader DrawMist()
		{
			return (float x, float y) => Fill(Mathf.Min(Mathf.Min(Segment(x, y, 12f, 22f, 44f, 22f, 3.5f), Segment(x, y, 20f, 32f, 54f, 32f, 3.5f)), Mathf.Min(Segment(x, y, 10f, 42f, 40f, 42f, 3.5f), Segment(x, y, 24f, 52f, 52f, 52f, 3.5f))), CloudLight);
		}

		private static Shader DrawBoss()
		{
			return delegate(float x, float y)
			{
				//IL_0074: Unknown result type (might be due to invalid IL or missing references)
				//IL_0079: Unknown result type (might be due to invalid IL or missing references)
				float num = Mathf.Min(Circle(x, y, 32f, 28f, 17f), Segment(x, y, 25f, 44f, 39f, 44f, 5f));
				float num2 = Mathf.Min(Circle(x, y, 25f, 29f, 4.5f), Circle(x, y, 39f, 29f, 4.5f));
				return Fill(Mathf.Max(num, 0f - num2), BossRed);
			};
		}

		private static Shader DrawIndoor()
		{
			return delegate(float x, float y)
			{
				//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
				//IL_00af: Unknown result type (might be due to invalid IL or missing references)
				float num = Mathf.Min(Mathf.Max(Circle(x, y, 32f, 30f, 20f), y - 30f), Mathf.Max(Mathf.Abs(x - 32f) - 20f, Mathf.Max(30f - y, y - 54f)));
				float num2 = Mathf.Min(Mathf.Max(Circle(x, y, 32f, 32f, 11f), y - 32f), Mathf.Max(Mathf.Abs(x - 32f) - 11f, Mathf.Max(32f - y, y - 56f)));
				return Fill(Mathf.Max(num, 0f - num2), Stone);
			};
		}
	}
	internal static class Lang
	{
		private static readonly Dictionary<string, string[]> Table = new Dictionary<string, string[]>
		{
			["day"] = new string[2] { "Day {0}", "{0}일차" },
			["weather_Clear"] = new string[2] { "Clear", "맑음" },
			["weather_Cloudy"] = new string[2] { "Cloudy", "흐림" },
			["weather_Mist"] = new string[2] { "Mist", "안개" },
			["weather_Rain"] = new string[2] { "Rain", "비" },
			["weather_Storm"] = new string[2] { "Thunderstorm", "뇌우" },
			["weather_Snow"] = new string[2] { "Snow", "눈" },
			["weather_Blizzard"] = new string[2] { "Blizzard", "눈보라" },
			["weather_Ash"] = new string[2] { "Ash rain", "재 비" },
			["weather_Boss"] = new string[2] { "Boss", "보스" },
			["weather_Indoor"] = new string[2] { "Indoors", "실내" },
			["settings_title"] = new string[2] { "HUD Settings", "HUD 설정" },
			["menu_button"] = new string[2] { "HUD Settings", "HUD 설정" },
			["close"] = new string[2] { "Close", "닫기" },
			["tab_Markers"] = new string[2] { "Markers", "마커" },
			["tab_Hud"] = new string[2] { "HUD", "HUD" },
			["tab_Compass"] = new string[2] { "Compass", "나침반" },
			["tab_General"] = new string[2] { "General", "기타" },
			["set_show_hud"] = new string[2] { "Show the HUD", "HUD 표시" },
			["set_show_day"] = new string[2] { "Show the day", "날짜 표시" },
			["set_show_time"] = new string[2] { "Show the time", "시간 표시" },
			["set_show_weather"] = new string[2] { "Show the weather", "날씨 표시" },
			["set_24h"] = new string[2] { "24-hour clock (off = AM/PM)", "24시간제 (끄면 오전/오후)" },
			["set_anchor"] = new string[2] { "Position", "위치" },
			["anchor_TopLeft"] = new string[2] { "Top left", "왼쪽 위" },
			["anchor_TopCenter"] = new string[2] { "Top", "위 가운데" },
			["anchor_TopRight"] = new string[2] { "Top right", "오른쪽 위" },
			["anchor_BottomLeft"] = new string[2] { "Bottom left", "왼쪽 아래" },
			["anchor_BottomCenter"] = new string[2] { "Bottom", "아래 가운데" },
			["anchor_BottomRight"] = new string[2] { "Bottom right", "오른쪽 아래" },
			["set_offset_x"] = new string[2] { "Move sideways", "좌우 이동" },
			["set_offset_y"] = new string[2] { "Move from the edge", "가장자리에서 거리" },
			["set_scale"] = new string[2] { "Size", "크기" },
			["set_show_compass"] = new string[2] { "Show the compass", "나침반 표시" },
			["set_show_heading"] = new string[2] { "Show the heading (e.g. 127° SE)", "방위각 표시 (예: 127° SE)" },
			["set_width"] = new string[2] { "Window width", "창 너비" },
			["set_degrees"] = new string[2] { "Visible degrees", "보이는 각도" },
			["set_max_markers"] = new string[2] { "Max markers", "최대 마커 수" },
			["set_max_distance"] = new string[2] { "Max marker distance", "마커 최대 거리" },
			["unlimited"] = new string[2] { "No limit", "제한 없음" },
			["set_language"] = new string[2] { "Language", "언어" },
			["lang_Auto"] = new string[2] { "Game language", "게임 언어" },
			["lang_English"] = new string[2] { "English", "English" },
			["lang_Korean"] = new string[2] { "한국어", "한국어" },
			["set_game_font"] = new string[2] { "Use the game font", "게임 글꼴 사용" },
			["set_game_font_hint"] = new string[2] { "Applies after restarting the game.", "게임을 다시 켜면 적용돼요." },
			["set_keys"] = new string[2] { "Shortcuts", "단축키" },
			["key_toggle"] = new string[2] { "Show / hide the HUD", "HUD 켜기/끄기" },
			["key_settings"] = new string[2] { "Open this window", "이 창 열기" },
			["key_menu"] = new string[2] { "Also from", "여기서도 열기" },
			["key_menu_value"] = new string[2] { "ESC menu > HUD Settings", "ESC 메뉴 > HUD 설정" },
			["set_keys_hint"] = new string[2] { "Change keys in BepInEx/config/lazly.valheim.timeweatherhud.cfg", "단축키는 BepInEx/config/lazly.valheim.timeweatherhud.cfg 에서 바꿀 수 있어요." },
			["set_reset"] = new string[2] { "Reset to defaults", "처음 설정으로 되돌리기" },
			["map_me"] = new string[2] { "My position", "내 위치" },
			["map_hint"] = new string[2] { "Click a pin to show / hide it on the compass  ·  drag to move  ·  wheel to zoom", "핀을 누르면 나침반에 표시/해제  ·  끌어서 이동  ·  휠로 확대/축소" },
			["map_unavailable"] = new string[2] { "The map is not available.", "지도를 불러올 수 없어요." },
			["marker_title"] = new string[2] { "Compass Markers", "나침반 마커" },
			["marker_hint"] = new string[2] { "Checked map pins appear on the compass. A checked group includes new pins too.", "체크한 지도 핀이 나침반에 떠요. 종류를 체크하면 새 핀까지 모두 떠요." },
			["marker_show"] = new string[2] { "Show markers on the compass", "나침반에 마커 표시" },
			["marker_all"] = new string[2] { "all {0}", "전체 {0}개" },
			["marker_clear"] = new string[2] { "Uncheck all", "모두 해제" },
			["marker_close"] = new string[2] { "Close", "닫기" },
			["marker_empty"] = new string[2] { "No map pins yet. Add pins on the map (M) first.", "아직 지도 핀이 없어요. 지도(M)에서 핀을 먼저 찍어 주세요." },
			["pin_Death"] = new string[2] { "Tombstones", "무덤" },
			["pin_Boss"] = new string[2] { "Boss locations", "보스 위치" },
			["pin_Bed"] = new string[2] { "Bed (spawn point)", "침대 (부활 지점)" },
			["pin_Icon0"] = new string[2] { "Fire pins", "불 핀" },
			["pin_Icon1"] = new string[2] { "House pins", "집 핀" },
			["pin_Icon2"] = new string[2] { "Hammer pins", "망치 핀" },
			["pin_Icon3"] = new string[2] { "Dot pins", "점 핀" },
			["pin_Icon4"] = new string[2] { "Portal pins", "포탈 핀" },
			["pin1_Death"] = new string[2] { "Tombstone", "무덤" },
			["pin1_Boss"] = new string[2] { "Boss", "보스" },
			["pin1_Bed"] = new string[2] { "Bed", "침대" },
			["pin1_Icon0"] = new string[2] { "Fire pin", "불 핀" },
			["pin1_Icon1"] = new string[2] { "House pin", "집 핀" },
			["pin1_Icon2"] = new string[2] { "Hammer pin", "망치 핀" },
			["pin1_Icon3"] = new string[2] { "Dot pin", "점 핀" },
			["pin1_Icon4"] = new string[2] { "Portal pin", "포탈 핀" }
		};

		private static bool _korean;

		private static float _nextCheck = -1f;

		public static bool IsKorean
		{
			get
			{
				if (Time.unscaledTime >= _nextCheck)
				{
					_nextCheck = Time.unscaledTime + 3f;
					_korean = Resolve();
				}
				return _korean;
			}
		}

		public unsafe static string PinType(PinType type)
		{
			if (!Table.ContainsKey("pin_" + ((object)(*(PinType*)(&type))/*cast due to .constrained prefix*/).ToString()))
			{
				return ((object)(*(PinType*)(&type))/*cast due to .constrained prefix*/).ToString();
			}
			return T("pin_" + ((object)(*(PinType*)(&type))/*cast due to .constrained prefix*/).ToString());
		}

		public static string PinName(PinData pin)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrEmpty(pin.m_name))
			{
				return PinSingle(pin.m_type);
			}
			if (pin.m_name.StartsWith("$hud_mapday") && int.TryParse(pin.m_name.Substring("$hud_mapday".Length).Trim(), out var result))
			{
				return T("day", result);
			}
			if (pin.m_name.IndexOf('$') < 0 || Localization.instance == null)
			{
				return pin.m_name;
			}
			try
			{
				return Localization.instance.Localize(pin.m_name);
			}
			catch (Exception)
			{
				return pin.m_name;
			}
		}

		public unsafe static string PinSingle(PinType type)
		{
			if (!Table.ContainsKey("pin1_" + ((object)(*(PinType*)(&type))/*cast due to .constrained prefix*/).ToString()))
			{
				return ((object)(*(PinType*)(&type))/*cast due to .constrained prefix*/).ToString();
			}
			return T("pin1_" + ((object)(*(PinType*)(&type))/*cast due to .constrained prefix*/).ToString());
		}

		public static string Distance(float meters)
		{
			if (!(meters < 1000f))
			{
				return (meters / 1000f).ToString("0.0") + "km";
			}
			return Mathf.RoundToInt(meters) + "m";
		}

		public static string T(string key, params object[] args)
		{
			if (!Table.TryGetValue(key, out var value))
			{
				return key;
			}
			string text = value[IsKorean ? 1u : 0u];
			if (args.Length != 0)
			{
				return string.Format(text, args);
			}
			return text;
		}

		public static string Weather(WeatherKind kind, string envName)
		{
			if (kind != WeatherKind.Unknown)
			{
				return T("weather_" + kind);
			}
			if (!string.IsNullOrEmpty(envName))
			{
				return envName.Replace('_', ' ');
			}
			return "-";
		}

		private static bool Resolve()
		{
			switch (Plugin.Language.Value)
			{
			case UiLanguage.Korean:
				return true;
			case UiLanguage.English:
				return false;
			default:
				if (Localization.instance == null)
				{
					return false;
				}
				return Traverse.Create((object)Localization.instance).Method("GetSelectedLanguage", Array.Empty<object>()).GetValue() as string == "Korean";
			}
		}
	}
	internal static class MapBaker
	{
		private static readonly Color Fog = new Color(0.46f, 0.42f, 0.36f);

		private static readonly Color Shallow = new Color(0.33f, 0.5f, 0.56f);

		private static readonly Color Deep = new Color(0.1f, 0.19f, 0.3f);

		private const int NoiseSize = 256;

		private static float[] _noise;

		public static int TextureSize { get; private set; } = 2048;

		public static float PixelSize { get; private set; } = 12f;

		public static Texture2D Bake(int outSize)
		{
			//IL_0375: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0381: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a1: Expected O, but got Unknown
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: 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_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: 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_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Minimap instance = Minimap.instance;
				if ((Object)(object)instance == (Object)null)
				{
					Plugin.Log.LogWarning((object)"Map bake: Minimap is not ready");
					return null;
				}
				Traverse val = Traverse.Create((object)instance);
				int value = val.Field("m_textureSize").GetValue<int>();
				float value2 = val.Field("m_pixelSize").GetValue<float>();
				if (value > 0)
				{
					TextureSize = value;
				}
				if (value2 > 0f)
				{
					PixelSize = value2;
				}
				object value3 = val.Field("m_mapTexture").GetValue();
				Texture2D val2 = (Texture2D)((value3 is Texture2D) ? value3 : null);
				object value4 = val.Field("m_heightTexture").GetValue();
				Texture2D tex = (Texture2D)((value4 is Texture2D) ? value4 : null);
				object value5 = val.Field("m_forestMaskTexture").GetValue();
				Texture2D val3 = (Texture2D)((value5 is Texture2D) ? value5 : null);
				if ((Object)(object)val2 == (Object)null)
				{
					Plugin.Log.LogWarning((object)"Map bake: no m_mapTexture");
					return null;
				}
				int width = ((Texture)val2).width;
				Color32[] pixels = val2.GetPixels32();
				float[] array = ReadHeights(tex, width);
				Color32[] array2 = (((Object)(object)val3 != (Object)null && ((Texture)val3).width == width) ? val3.GetPixels32() : null);
				Func<int, bool> func = ExploredReader(val.Field("m_explored").GetValue(), val.Field("m_exploredOthers").GetValue());
				float num = (((Object)(object)ZoneSystem.instance != (Object)null) ? ZoneSystem.instance.m_waterLevel : 30f);
				int num2 = Mathf.Max(1, width / outSize);
				int num3 = width / num2;
				Color32[] array3 = (Color32[])(object)new Color32[num3 * num3];
				for (int i = 0; i < num3; i++)
				{
					int num4 = i * num2;
					for (int j = 0; j < num3; j++)
					{
						int num5 = j * num2;
						int num6 = num4 * width + num5;
						Color val4;
						if (func != null && !func(num6))
						{
							float num7 = Cloud(j, i);
							val4 = Fog * (0.86f + num7 * 0.24f);
						}
						else
						{
							val4 = Color32.op_Implicit(pixels[num6]);
							float num8 = ((array != null) ? array[num6] : (num + 1f));
							if (num8 < num)
							{
								val4 = Color.Lerp(Shallow, Deep, Mathf.Clamp01((num - num8) / 40f));
							}
							else
							{
								if (array2 != null)
								{
									val4 = Color.Lerp(val4, val4 * 0.62f, (float)(int)array2[num6].r / 255f * 0.8f);
								}
								if (array != null)
								{
									float num9 = array[num4 * width + Mathf.Min(width - 1, num5 + num2)] - array[num4 * width + Mathf.Max(0, num5 - num2)];
									float num10 = array[Mathf.Min(width - 1, num4 + num2) * width + num5] - array[Mathf.Max(0, num4 - num2) * width + num5];
									float num11 = Mathf.Clamp(1f + (num10 - num9) * 0.02f, 0.72f, 1.2f);
									((Color)(ref val4))..ctor(val4.r * num11, val4.g * num11, val4.b * num11);
								}
								if (num8 < num + 1.5f)
								{
									val4 = Color.Lerp(val4, new Color(0.78f, 0.72f, 0.55f), 0.5f);
								}
							}
						}
						val4.a = 1f;
						array3[i * num3 + j] = Color32.op_Implicit(val4);
					}
				}
				Texture2D val5 = new Texture2D(num3, num3, (TextureFormat)4, false)
				{
					wrapMode = (TextureWrapMode)1,
					filterMode = (FilterMode)1,
					hideFlags = (HideFlags)61
				};
				val5.SetPixels32(array3);
				val5.Apply(false);
				return val5;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Map bake failed: " + ex));
				return null;
			}
		}

		private static float Cloud(int x, int y)
		{
			if (_noise == null)
			{
				_noise = new float[65536];
				for (int i = 0; i < 256; i++)
				{
					for (int j = 0; j < 256; j++)
					{
						float num = (float)j / 256f;
						float num2 = (float)i / 256f;
						_noise[i * 256 + j] = n(j, i) * (1f - num) * (1f - num2) + n(j - 256, i) * num * (1f - num2) + n(j, i - 256) * (1f - num) * num2 + n(j - 256, i - 256) * num * num2;
					}
				}
			}
			return _noise[y % 256 * 256 + x % 256];
			static float n(float px, float py)
			{
				return Mathf.PerlinNoise(px * 0.035f, py * 0.035f) * 0.7f + Mathf.PerlinNoise(px * 0.11f, py * 0.11f) * 0.3f;
			}
		}

		private static float[] ReadHeights(Texture2D tex, int size)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Invalid comparison between Unknown and I4
			if ((Object)(object)tex == (Object)null || ((Texture)tex).width != size)
			{
				return null;
			}
			float[] array = new float[size * size];
			if ((int)tex.format == 15)
			{
				byte[] rawTextureData = tex.GetRawTextureData();
				for (int i = 0; i < array.Length && i * 2 + 1 < rawTextureData.Length; i++)
				{
					array[i] = Mathf.HalfToFloat((ushort)(rawTextureData[i * 2] | (rawTextureData[i * 2 + 1] << 8)));
				}
			}
			else
			{
				Color[] pixels = tex.GetPixels();
				for (int j = 0; j < array.Length; j++)
				{
					array[j] = pixels[j].r;
				}
			}
			return array;
		}

		private static Func<int, bool> ExploredReader(object mine, object others)
		{
			Func<int, bool> a = Reader(mine);
			Func<int, bool> b = Reader(others);
			if (a == null && b == null)
			{
				return null;
			}
			return (int i) => (a != null && a(i)) || (b != null && b(i));
		}

		private static Func<int, bool> Reader(object value)
		{
			BitArray bits = value as BitArray;
			if (bits != null)
			{
				return (int i) => i < bits.Length && bits[i];
			}
			bool[] arr = value as bool[];
			if (arr != null)
			{
				return (int i) => i < arr.Length && arr[i];
			}
			return null;
		}
	}
	internal class MarkerMapView : MonoBehaviour, IDragHandler, IEventSystemHandler, IScrollHandler
	{
		private class PinView
		{
			private readonly RectTransform _root;

			private readonly RawImage _halo;

			private readonly Image _icon;

			private PinData _pin;

			public PinView(Transform parent)
			{
				//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)
				_root = UiKit.Rect("MapPin", parent);
				_halo = UiKit.Raw("Halo", (Transform)(object)_root, 0f, 0f, 32f, 32f);
				RectTransform val = UiKit.Rect("Icon", (Transform)(object)_root);
				UiKit.Place(val, 5f, 5f, 22f, 22f);
				_icon = ((Component)val).gameObject.AddComponent<Image>();
				_icon.preserveAspect = true;
				((Graphic)_icon).raycastTarget = true;
				UiKit.Clickable((Graphic)(object)_icon, OnClick, Color.white, Color.white);
			}

			public void Show(PinData pin, Vector2 p, bool on, float unit)
			{
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				//IL_008c: 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)
				_pin = pin;
				if (!((Component)_root).gameObject.activeSelf)
				{
					((Component)_root).gameObject.SetActive(true);
				}
				UiKit.Place(_root, p.x - 16f, p.y - 16f, 32f, 32f);
				_icon.sprite = pin.m_icon;
				((Graphic)_icon).color = new Color(1f, 1f, 1f, on ? 1f : 0.5f);
				((Component)_halo).gameObject.SetActive(on);
				if (on)
				{
					_halo.texture = (Texture)(object)PanelArt.Circle(32f, unit, on: true);
					((Graphic)_halo).color = new Color(1f, 1f, 1f, 0.55f);
				}
			}

			public void Hide()
			{
				if (((Component)_root).gameObject.activeSelf)
				{
					((Component)_root).gameObject.SetActive(false);
				}
			}

			private void OnClick()
			{
				if (_pin != null)
				{
					MarkerTracker.SetPin(_pin, !MarkerTracker.IsPinOn(_pin));
				}
			}
		}

		private const float MinZoom = 1f;

		private const float MaxZoom = 48f;

		private const float PinSize = 22f;

		private const float HaloSize = 32f;

		private Func<float> _unit;

		private RectTransform _viewport;

		private RawImage _map;

		private Texture2D _baked;

		private float _bakedAt;

		private float _w;

		private float _h;

		private int _textureSize = 2048;

		private float _pixelSize = 12f;

		private Vector2 _center = new Vector2(0.5f, 0.5f);

		private float _zoom = 8f;

		private RectTransform _pinLayer;

		private readonly List<PinView> _pins = new List<PinView>();

		private readonly List<PinData> _data = new List<PinData>();

		private Image _player;

		private bool _hasMap;

		public bool HasMap => _hasMap;

		public void Init(RectTransform viewport, float w, float h, Func<float> unit)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			_viewport = viewport;
			_w = w;
			_h = h;
			_unit = unit;
			_map = UiKit.Raw("GameMap", (Transform)(object)viewport, 0f, 0f, w, h, raycast: true);
			((Graphic)_map).color = new Color(0.1f, 0.08f, 0.06f, 1f);
			Rebake();
			_pinLayer = UiKit.Rect("Pins", (Transform)(object)viewport);
			UiKit.Place(_pinLayer, 0f, 0f, w, h);
			RectTransform val = UiKit.Rect("Player", (Transform)(object)viewport);
			_player = ((Component)val).gameObject.AddComponent<Image>();
			((Graphic)_player).raycastTarget = false;
			_player.sprite = PlayerSprite();
			((Component)_player).gameObject.SetActive((Object)(object)_player.sprite != (Object)null);
		}

		public void Rebake()
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_baked != (Object)null && Time.unscaledTime - _bakedAt < 30f)
			{
				return;
			}
			_bakedAt = Time.unscaledTime;
			Texture2D val = MapBaker.Bake(4096);
			if (!((Object)(object)val == (Object)null))
			{
				if ((Object)(object)_baked != (Object)null)
				{
					Object.Destroy((Object)(object)_baked);
				}
				_baked = val;
				_map.texture = (Texture)(object)val;
				((Graphic)_map).color = Color.white;
				_textureSize = MapBaker.TextureSize;
				_pixelSize = MapBaker.PixelSize;
				_hasMap = true;
			}
		}

		private static Sprite PlayerSprite()
		{
			try
			{
				object value = Traverse.Create((object)Minimap.instance).Field("m_largeMarker").GetValue();
				Component val = (Component)((value is Component) ? value : null);
				Image val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<Image>() : null);
				return ((Object)(object)val2 != (Object)null) ? val2.sprite : null;
			}
			catch (Exception)
			{
				return null;
			}
		}

		private void OnDestroy()
		{
			if ((Object)(object)_baked != (Object)null)
			{
				Object.Destroy((Object)(object)_baked);
			}
		}

		public void CenterOnPlayer()
		{
			//IL_0019: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Player.m_localPlayer != (Object)null)
			{
				_center = WorldToUV(((Component)Player.m_localPlayer).transform.position);
			}
			Clamp();
		}

		public void Zoom(float factor)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			ZoomAt(new Vector2(_w / 2f, _h / 2f), factor);
		}

		public void SetPins(List<PinData> pins)
		{
			_data.Clear();
			_data.AddRange(pins);
		}

		private void LateUpdate()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: 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_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			Rect val = ViewUV();
			_map.uvRect = val;
			float unit = _unit();
			int num = 0;
			for (int i = 0; i < 2; i++)
			{
				foreach (PinData datum in _data)
				{
					bool flag = MarkerTracker.IsShown(datum);
					if (flag == (i == 1))
					{
						Vector2 val2 = UVToLocal(val, WorldToUV(datum.m_pos));
						if (!(val2.x < -32f) && !(val2.y < -32f) && !(val2.x > _w + 32f) && !(val2.y > _h + 32f))
						{
							PinAt(num++).Show(datum, val2, flag, unit);
						}
					}
				}
			}
			for (int j = num; j < _pins.Count; j++)
			{
				_pins[j].Hide();
			}
			if ((Object)(object)_player.sprite != (Object)null && (Object)(object)Player.m_localPlayer != (Object)null)
			{
				Vector2 val3 = UVToLocal(val, WorldToUV(((Component)Player.m_localPlayer).transform.position));
				UiKit.Place(((Graphic)_player).rectTransform, val3.x - 13f, val3.y - 13f, 26f, 26f);
				((Graphic)_player).rectTransform.pivot = new Vector2(0.5f, 0.5f);
				((Graphic)_player).rectTransform.anchoredPosition = new Vector2(val3.x, 0f - val3.y);
				Camera main = Camera.main;
				float num2 = (((Object)(object)main != (Object)null) ? ((Component)main).transform.eulerAngles.y : ((Component)Player.m_localPlayer).transform.eulerAngles.y);
				((Transform)((Graphic)_player).rectTransform).localEulerAngles = new Vector3(0f, 0f, 0f - num2);
				((Component)_player).transform.SetAsLastSibling();
			}
		}

		private PinView PinAt(int index)
		{
			while (_pins.Count <= index)
			{
				_pins.Add(new PinView((Transform)(object)_pinLayer));
			}
			return _pins[index];
		}

		public void OnDrag(PointerEventData e)
		{
			//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)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			float num = _unit();
			Rect val = ViewUV();
			_center.x -= e.delta.x / num / _w * ((Rect)(ref val)).width;
			_center.y -= e.delta.y / num / _h * ((Rect)(ref val)).height;
			Clamp();
		}

		public void OnScroll(PointerEventData e)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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)
			Vector2 val = default(Vector2);
			if (!Mathf.Approximately(e.scrollDelta.y, 0f) && RectTransformUtility.ScreenPointToLocalPointInRectangle(_viewport, e.position, (Camera)null, ref val))
			{
				Vector2 anchorLocal = default(Vector2);
				((Vector2)(ref anchorLocal))..ctor(val.x, 0f - val.y);
				ZoomAt(anchorLocal, (e.scrollDelta.y > 0f) ? 1.3f : 0.7692308f);
			}
		}

		private void ZoomAt(Vector2 anchorLocal, float factor)
		{
			//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_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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)
			Vector2 val = LocalToUV(ViewUV(), anchorLocal);
			_zoom = Mathf.Clamp(_zoom * factor, 1f, 48f);
			Rect val2 = ViewUV();
			_center = new Vector2(val.x - (anchorLocal.x / _w - 0.5f) * ((Rect)(ref val2)).width, val.y - ((_h - anchorLocal.y) / _h - 0.5f) * ((Rect)(ref val2)).height);
			Clamp();
		}

		private Rect ViewUV()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			float num = 1f / _zoom;
			float num2 = num * (_w / _h);
			return new Rect(_center.x - num2 / 2f, _center.y - num / 2f, num2, num);
		}

		private void Clamp()
		{
			_zoom = Mathf.Clamp(_zoom, 1f, 48f);
			float num = 1f / _zoom;
			float num2 = num * (_w / _h);
			_center.x = ((num2 >= 1f) ? 0.5f : Mathf.Clamp(_center.x, num2 / 2f, 1f - num2 / 2f));
			_center.y = ((num >= 1f) ? 0.5f : Mathf.Clamp(_center.y, num / 2f, 1f - num / 2f));
		}

		private Vector2 WorldToUV(Vector3 world)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			float num = (float)_textureSize / 2f;
			return new Vector2((world.x / _pixelSize + num) / (float)_textureSize, (world.z / _pixelSize + num) / (float)_textureSize);
		}

		private Vector3 UVToWorld(Vector2 uv)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			float num = (float)_textureSize / 2f;
			return new Vector3((uv.x * (float)_textureSize - num) * _pixelSize, 0f, (uv.y * (float)_textureSize - num) * _pixelSize);
		}

		private Vector2 UVToLocal(Rect uv, Vector2 p)
		{
			//IL_0000: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			return new Vector2((p.x - ((Rect)(ref uv)).x) / ((Rect)(ref uv)).width * _w, _h - (p.y - ((Rect)(ref uv)).y) / ((Rect)(ref uv)).height * _h);
		}

		private Vector2 LocalToUV(Rect uv, Vector2 p)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			return new Vector2(((Rect)(ref uv)).x + p.x / _w * ((Rect)(ref uv)).width, ((Rect)(ref uv)).y + (_h - p.y) / _h * ((Rect)(ref uv)).height);
		}
	}
	internal struct Marker
	{
		public Vector3 Position;

		public Sprite Icon;

		public string Name;
	}
	internal static class MarkerTracker
	{
		private static readonly FieldInfo PinsField = AccessTools.Field(typeof(Minimap), "m_pins");

		private static readonly HashSet<string> Transient = new HashSet<string> { "None", "Player", "Ping", "Shout", "RandomEvent", "EventArea" };

		private static readonly string FilePath = Path.Combine(Paths.ConfigPath, "lazly.valheim.timeweatherhud.markers.txt");

		private static Dictionary<string, HashSet<string>> _all;

		private static string _scope;

		public static List<PinData> ListablePins()
		{
			List<PinData> list = new List<PinData>();
			if ((Object)(object)Minimap.instance == (Object)null || !(PinsField?.GetValue(Minimap.instance) is List<PinData> list2))
			{
				return list;
			}
			foreach (PinData item in list2)
			{
				if (item != null && !Transient.Contains(((object)Unsafe.As<PinType, PinType>(ref item.m_type)/*cast due to .constrained prefix*/).ToString()))
				{
					list.Add(item);
				}
			}
			return list;
		}

		public unsafe static string TypeKey(PinType type)
		{
			return "type:" + ((object)(*(PinType*)(&type))/*cast due to .constrained prefix*/).ToString();
		}

		public static string PinKey(PinData pin)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return $"pin:{pin.m_type}:{Mathf.RoundToInt(pin.m_pos.x)}:{Mathf.RoundToInt(pin.m_pos.z)}";
		}

		public static bool IsTypeOn(PinType type)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return Selection().Contains(TypeKey(type));
		}

		public static bool IsPinOn(PinData pin)
		{
			return Selection().Contains(PinKey(pin));
		}

		public static bool IsShown(PinData pin)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			if (!IsTypeOn(pin.m_type))
			{
				return IsPinOn(pin);
			}
			return true;
		}

		public static void SetType(PinType type, bool on)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			Set(TypeKey(type), on);
		}

		public static void SetPin(PinData pin, bool on)
		{
			Set(PinKey(pin), on);
		}

		public static void ClearAll()
		{
			Selection().Clear();
			Save();
		}

		public static void Collect(List<Marker> into, Vector3 from)
		{
			//IL_0041: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			into.Clear();
			if (!Plugin.ShowMarkers.Value)
			{
				return;
			}
			float value = Plugin.MarkerMaxDistance.Value;
			List<KeyValuePair<float, Marker>> list = new List<KeyValuePair<float, Marker>>();
			foreach (PinData item in ListablePins())
			{
				if (IsShown(item))
				{
					float num = Utils.DistanceXZ(from, item.m_pos);
					if (!(value > 0f) || !(num > value))
					{
						list.Add(new KeyValuePair<float, Marker>(num, new Marker
						{
							Position = item.m_pos,
							Icon = item.m_icon,
							Name = item.m_name
						}));
					}
				}
			}
			list.Sort((KeyValuePair<float, Marker> a, KeyValuePair<float, Marker> b) => a.Key.CompareTo(b.Key));
			for (int num2 = 0; num2 < list.Count && num2 < Plugin.MaxMarkers.Value; num2++)
			{
				into.Add(list[num2].Value);
			}
		}

		private static HashSet<string> Selection()
		{
			Load();
			string text = CurrentScope();
			if (_scope != text)
			{
				_scope = text;
			}
			if (!_all.TryGetValue(text, out var value))
			{
				value = new HashSet<string> { "type:Death" };
				_all[text] = value;
			}
			return value;
		}

		private static void Set(string key, bool on)
		{
			HashSet<string> hashSet = Selection();
			if (on ? hashSet.Add(key) : hashSet.Remove(key))
			{
				Save();
			}
		}

		private static string CurrentScope()
		{
			string obj = (((Object)(object)ZNet.instance != (Object)null) ? ZNet.instance.GetWorldName() : "?");
			string text = (((Object)(object)Player.m_localPlayer != (Object)null) ? Player.m_localPlayer.GetPlayerName() : "?");
			return (obj + "/" + text).Replace("|", "_");
		}

		private static void Load()
		{
			if (_all != null)
			{
				return;
			}
			_all = new Dictionary<string, HashSet<string>>();
			try
			{
				if (!File.Exists(FilePath))
				{
					return;
				}
				string[] array = File.ReadAllLines(FilePath);
				for (int i = 0; i < array.Length; i++)
				{
					string text = array[i].Trim();
					int num = text.IndexOf('|');
					if (text.Length != 0 && !text.StartsWith("#") && num > 0)
					{
						string key = text.Substring(0, num);
						string text2 = text.Substring(num + 1);
						if (!_all.TryGetValue(key, out var value))
						{
							value = (_all[key] = new HashSet<string>());
						}
						if (text2.Length > 0)
						{
							value.Add(text2);
						}
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not read marker selection: " + ex.Message));
			}
		}

		private static void Save()
		{
			try
			{
				List<string> list = new List<string> { "# TimeWeatherHud compass markers: <world>/<character>|<type:... or pin:...>" };
				foreach (KeyValuePair<string, HashSet<string>> item in _all)
				{
					list.Add(item.Key + "|");
					foreach (string item2 in item.Value)
					{
						list.Add(item.Key + "|" + item2);
					}
				}
				File.WriteAllLines(FilePath, list.ToArray());
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not save marker selection: " + ex.Message));
			}
		}
	}
	[HarmonyPatch]
	internal static class MenuButtonPatch
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__OnClick;
		}

		private const string ButtonName = "TimeWeatherHud_SettingsButton";

		private static readonly FieldInfo SettingsButtonField = AccessTools.Field(typeof(Menu), "m_settingsButton");

		private static readonly FieldInfo EntriesParentField = AccessTools.Field(typeof(Menu), "menuEntriesParent");

		private static readonly FieldInfo MenuDialogField = AccessTools.Field(typeof(Menu), "m_menuDialog");

		private static readonly MethodInfo MenuHide = AccessTools.Method(typeof(Menu), "Hide", Type.EmptyTypes, (Type[])null);

		private static bool _loggedFailure;

		private static IEnumerable<MethodBase> TargetMethods()
		{
			return from m in ((IEnumerable<string>)new string[2] { "Start", "Show" }).Select((Func<string, MethodBase>)((string n) => AccessTools.DeclaredMethod(typeof(Menu), n, Type.EmptyTypes, (Type[])null)))
				where m != null
				select m;
		}

		private static bool Prepare()
		{
			return TargetMethods().Any();
		}

		private static void Postfix(Menu __instance)
		{
			try
			{
				EnsureButton(__instance);
			}
			catch (Exception ex)
			{
				Fail("error: " + ex);
			}
		}

		private static void EnsureButton(Menu menu)
		{
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Expected O, but got Unknown
			//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_012a: Expected O, but got Unknown
			object? obj = SettingsButtonField?.GetValue(menu);
			Button val = (Button)(((obj is Button) ? obj : null) ?? FindSettingsButton(menu));
			if ((Object)(object)val == (Object)null)
			{
				Fail("the game's Settings button was not found");
				return;
			}
			Transform parent = ((Component)val).transform.parent;
			Transform val2 = parent.Find("TimeWeatherHud_SettingsButton");
			if ((Object)(object)val2 != (Object)null)
			{
				SetLabel(((Component)val2).gameObject);
				val2.SetSiblingIndex(((Component)val).transform.GetSiblingIndex() + 1);
				return;
			}
			GameObject val3 = Object.Instantiate<GameObject>(((Component)val).gameObject, parent);
			((Object)val3).name = "TimeWeatherHud_SettingsButton";
			val3.SetActive(true);
			val3.transform.SetSiblingIndex(((Component)val).transform.GetSiblingIndex() + 1);
			Component[] componentsInChildren = val3.GetComponentsInChildren<Component>(true);
			foreach (Component val4 in componentsInChildren)
			{
				if ((Object)(object)val4 != (Object)null && ((object)val4).GetType().Name == "Localize")
				{
					Object.DestroyImmediate((Object)(object)val4);
				}
			}
			Button component = val3.GetComponent<Button>();
			component.onClick = new ButtonClickedEvent();
			ButtonClickedEvent onClick = component.onClick;
			object obj2 = <>O.<0>__OnClick;
			if (obj2 == null)
			{
				UnityAction val5 = OnClick;
				<>O.<0>__OnClick = val5;
				obj2 = (object)val5;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj2);
			SetLabel(val3);
			object? obj3 = EntriesParentField?.GetValue(menu);
			RectTransform val6 = (RectTransform)((obj3 is RectTransform) ? obj3 : null);
			if (val6 != null)
			{
				LayoutRebuilder.MarkLayoutForRebuild(val6);
			}
			else
			{
				RectTransform val7 = (RectTransform)(object)((parent is RectTransform) ? parent : null);
				if (val7 != null)
				{
					LayoutRebuilder.MarkLayoutForRebuild(val7);
				}
			}
			Plugin.Log.LogInfo((object)("Added the HUD Settings button to the ESC menu (after '" + ((Object)val).name + "' in '" + ((Object)parent).name + "')"));
		}

		private static Button FindSettingsButton(Menu menu)
		{
			object? obj = MenuDialogField?.GetValue(menu);
			return ((IEnumerable<Button>)((Component)(((obj is Transform) ? obj : null) ?? ((Component)menu).transform)).GetComponentsInChildren<Button>(true)).FirstOrDefault((Func<Button, bool>)((Button b) => ((Object)b).name.IndexOf("setting", StringComparison.OrdinalIgnoreCase) >= 0));
		}

		private static void OnClick()
		{
			if ((Object)(object)Menu.instance != (Object)null)
			{
				MenuHide?.Invoke(Menu.instance, null);
			}
			SettingsWindow.Open();
		}

		private static void SetLabel(GameObject go)
		{
			TMP_Text componentInChildren = go.GetComponentInChildren<TMP_Text>(true);
			string text = Lang.T("menu_button");
			if ((Object)(object)componentInChildren != (Object)null && componentInChildren.text != text)
			{
				componentInChildren.text = text;
			}
		}

		private static void Fail(string why)
		{
			if (!_loggedFailure)
			{
				_loggedFailure = true;
				Plugin.Log.LogWarning((object)("Could not add the HUD Settings button to the ESC menu: " + why));
			}
		}
	}
	[HarmonyPatch]
	internal static class BlockScrollWheelPatch
	{
		private static MethodBase TargetMethod()
		{
			return AccessTools.Method(typeof(ZInput), "GetMouseScrollWheel", Type.EmptyTypes, (Type[])null);
		}

		private static bool Prepare()
		{
			return TargetMethod() != null;
		}

		private static void Postfix(ref float __result)
		{
			if (SettingsWindow.BlocksInput)
			{
				__result = 0f;
			}
		}
	}
	internal static class PanelArt
	{
		private enum Kind
		{
			Button = 1,
			Box,
			Inset,
			Track,
			Circle,
			Frame
		}

		private static readonly Color OuterLine = new Color(0.03f, 0.02f, 0.012f, 0.95f);

		private static readonly Color GoldTop = new Color(0.98f, 0.82f, 0.5f, 1f);

		private static readonly Color GoldBottom = new Color(0.5f, 0.34f, 0.17f, 1f);

		private static readonly Color InnerLine = new Color(0.04f, 0.028f, 0.018f, 0.92f);

		private static readonly Color FillTop = new Color(0.2f, 0.15f, 0.1f, 0.86f);

		private static readonly Color FillBottom = new Color(0.065f, 0.045f, 0.03f, 0.9f);

		private static readonly Color Line = new Color(0.86f, 0.67f, 0.4f, 0.8f);

		private static readonly Color BronzeTop = new Color(0.66f, 0.49f, 0.28f, 1f);

		private static readonly Color BronzeBottom = new Color(0.42f, 0.3f, 0.17f, 1f);

		private static readonly Dictionary<long, Texture2D> Cache = new Dictionary<long, Texture2D>();

		public static Texture2D Frame(int w, int h, float unit)
		{
			//IL_0099: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: 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)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = NewTexture(w, h);
			Color[] array = (Color[])(object)new Color[w * h];
			float r = 6f * unit;
			float num = 1.2f * unit;
			float num2 = 1.6f * unit;
			float num3 = 1f * unit;
			for (int i = 0; i < h; i++)
			{
				float num4 = (float)(h - 1 - i) + 0.5f;
				float num5 = num4 / (float)h;
				for (int j = 0; j < w; j++)
				{
					float num6 = (float)j + 0.5f;
					float num7 = RoundedBox(num6, num4, w, h, r);
					if (num7 > 0.5f)
					{
						array[i * w + j] = Color.clear;
						continue;
					}
					float num8 = 0f - num7;
					Color val2 = Color.Lerp(FillTop, FillBottom, num5);
					float num9 = 0.07f * Mathf.Clamp01(1f - num4 / ((float)h * 0.5f));
					((Color)(ref val2))..ctor(val2.r + num9, val2.g + num9 * 0.85f, val2.b + num9 * 0.6f, val2.a);
					float num10 = Mathf.Clamp01(Mathf.Min(num6, (float)w - num6) / ((float)w * 0.18f));
					float num11 = Mathf.Lerp(0.72f, 1f, num10 * num10 * (3f - 2f * num10));
					((Color)(ref val2))..ctor(val2.r * num11, val2.g * num11, val2.b * num11, val2.a);
					Color val3 = Color.Lerp(OuterLine, Color.Lerp(GoldTop, GoldBottom, num5), Band(num8 - num));
					val3 = Color.Lerp(val3, InnerLine, Band(num8 - num - num2));
					val3 = Color.Lerp(val3, val2, Band(num8 - num - num2 - num3));
					val3.a *= Mathf.Clamp01(0.5f - num7);
					array[i * w + j] = val3;
				}
			}
			val.SetPixels(array);
			val.Apply(false);
			return val;
		}

		public static Texture2D FadeLine(bool horizontal)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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)
			Texture2D val = (horizontal ? NewTexture(128, 1) : NewTexture(1, 128));
			Color[] array = (Color[])(object)new Color[128];
			for (int i = 0; i < 128; i++)
			{
				float num = Mathf.Clamp01(Mathf.Min((float)i + 0.5f, (float)(128 - i) - 0.5f) / 38.4f);
				Color line = Line;
				line.a *= num * num * (3f - 2f * num);
				array[i] = line;
			}
			val.SetPixels(array);
			val.Apply(false);
			return val;
		}

		public static Texture2D Button(float w, float h, float unit, bool on)
		{
			return Cached(Kind.Button, w, h, unit, on, (int pw, int ph) => Rounded(pw, ph, 4f * unit, 1f * unit, 1.2f * unit, on ? GoldTop : BronzeTop, on ? GoldBottom : BronzeBottom, on ? new Color(0.38f, 0.28f, 0.18f, 0.98f) : new Color(0.27f, 0.2f, 0.14f, 0.96f), on ? new Color(0.2f, 0.15f, 0.1f, 0.98f) : new Color(0.14f, 0.1f, 0.07f, 0.96f)));
		}

		public static Texture2D Box(float size, float unit, bool on)
		{
			return Cached(Kind.Box, size, size, unit, on, (int pw, int ph) => Rounded(pw, ph, 3f * unit, 0.8f * unit, 1.6f * unit, on ? GoldTop : BronzeTop, on ? GoldBottom : BronzeBottom, new Color(0.07f, 0.05f, 0.035f, 0.95f), new Color(0.03f, 0.02f, 0.015f, 0.95f)));
		}

		public static Texture2D Inset(float w, float h, float unit)
		{
			return Cached(Kind.Inset, w, h, unit, on: false, (int pw, int ph) => Rounded(pw, ph, 5f * unit, 0f, 1f * unit, new Color(0.45f, 0.33f, 0.19f, 0.9f), new Color(0.3f, 0.22f, 0.13f, 0.9f), new Color(0.02f, 0.015f, 0.01f, 0.6f), new Color(0.04f, 0.03f, 0.02f, 0.5f)));
		}

		public static Texture2D Track(float w, float h, float unit)
		{
			return Cached(Kind.Track, w, h, unit, on: false, (int pw, int ph) => Rounded(pw, ph, (float)ph / 2f, 0.6f * unit, 1f * unit, BronzeTop, BronzeBottom, new Color(0.03f, 0.02f, 0.015f, 0.95f), new Color(0.06f, 0.045f, 0.03f, 0.95f)));
		}

		public static Texture2D Circle(float size, float unit, bool on)
		{
			return Cached(Kind.Circle, size, size, unit, on, (int pw, int ph) => Rounded(pw, ph, (float)pw / 2f, 1f * unit, 0f, OuterLine, OuterLine, on ? new Color(1f, 0.84f, 0.5f, 1f) : new Color(0.95f, 0.9f, 0.8f, 1f), on ? new Color(0.85f, 0.6f, 0.3f, 1f) : new Color(0.75