Decompiled source of PotatoTweaks v1.5.23

plugins/PotatoTweaks.dll

Decompiled 4 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Common;
using EpicLoot;
using EpicLoot.Adventure;
using EpicLoot.Adventure.Feature;
using EpicLoot.MagicItemEffects;
using EpicLoot_UnityLib;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using PotatoTweaks.DoubleBed;
using TMPro;
using Unity.Collections;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace PotatoTweaks
{
	internal static class AutoDoors
	{
		private sealed class Watched
		{
			internal Door door;

			internal float openedAt;

			internal Bounds doorway;
		}

		[HarmonyPatch(typeof(Door), "Awake")]
		internal static class Register
		{
			private static void Postfix(Door __instance)
			{
				ZNetView view = View.Invoke(__instance);
				if (!Object.op_Implicit((Object)(object)view) || view.GetZDO() == null)
				{
					return;
				}
				Door door = __instance;
				view.Register("PotatoTweaks_CloseDoor", (Action<long>)delegate
				{
					if (view.IsValid() && view.IsOwner() && view.GetZDO().GetInt(ZDOVars.s_state, 0) != 0 && CanInteract(door))
					{
						view.GetZDO().Set(ZDOVars.s_state, 0, false);
					}
				});
			}
		}

		[HarmonyPatch(typeof(Door), "Interact")]
		internal static class Opened
		{
			private static void Prefix(Door __instance, Humanoid character, bool hold, ref bool __state)
			{
				//IL_008d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				__state = !hold && (Object)(object)character == (Object)(object)Player.m_localPlayer && Plugin.DoorsCloseEnabled.Value && Handles(__instance) && State(__instance) == 0;
				if (__state)
				{
					watched.RemoveAll((Watched w) => (Object)(object)w.door == (Object)(object)__instance);
					watched.Add(new Watched
					{
						door = __instance,
						openedAt = Time.time,
						doorway = Doorway(__instance)
					});
				}
			}
		}

		private const string CloseRpc = "PotatoTweaks_CloseDoor";

		internal static readonly Type[] Patches = new Type[2]
		{
			typeof(Register),
			typeof(Opened)
		};

		private static readonly FieldRef<Door, ZNetView> View = AccessTools.FieldRefAccess<Door, ZNetView>("m_nview");

		private static readonly Func<Door, bool> CanInteract = AccessTools.MethodDelegate<Func<Door, bool>>(AccessTools.Method(typeof(Door), "CanInteract", (Type[])null, (Type[])null), (object)null, true);

		private static readonly List<Watched> watched = new List<Watched>();

		private static readonly List<Character> nearby = new List<Character>();

		private static float nextCheck;

		private static bool Handles(Door door)
		{
			if (!Object.op_Implicit((Object)(object)door) || (Object)(object)door.m_keyItem != (Object)null || door.m_canNotBeClosed)
			{
				return false;
			}
			Piece component = ((Component)door).GetComponent<Piece>();
			if (Object.op_Implicit((Object)(object)component))
			{
				return component.IsPlacedByPlayer();
			}
			return false;
		}

		private static int State(Door door)
		{
			ZNetView val = View.Invoke(door);
			if (!Object.op_Implicit((Object)(object)val) || !val.IsValid())
			{
				return 0;
			}
			return val.GetZDO().GetInt(ZDOVars.s_state, 0);
		}

		private static Bounds Doorway(Door door)
		{
			//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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			Bounds bounds = default(Bounds);
			((Bounds)(ref bounds))..ctor(((Component)door).transform.position, Vector3.zero);
			bool flag = false;
			Collider[] componentsInChildren = ((Component)door).GetComponentsInChildren<Collider>();
			foreach (Collider val in componentsInChildren)
			{
				if (!val.isTrigger)
				{
					if (flag)
					{
						((Bounds)(ref bounds)).Encapsulate(val.bounds);
						continue;
					}
					bounds = val.bounds;
					flag = true;
				}
			}
			((Bounds)(ref bounds)).Expand(new Vector3(2f, 1f, 2f));
			return bounds;
		}

		internal static void Update()
		{
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			if (AutoDoors.watched.Count == 0 || Time.time < nextCheck)
			{
				return;
			}
			nextCheck = Time.time + 0.25f;
			float value = Plugin.DoorsCloseSeconds.Value;
			for (int num = AutoDoors.watched.Count - 1; num >= 0; num--)
			{
				Watched watched = AutoDoors.watched[num];
				if (!Object.op_Implicit((Object)(object)watched.door) || !Plugin.DoorsCloseEnabled.Value)
				{
					AutoDoors.watched.RemoveAt(num);
				}
				else if (State(watched.door) == 0)
				{
					if (Time.time - watched.openedAt > 3f)
					{
						AutoDoors.watched.RemoveAt(num);
					}
				}
				else if (!(Time.time - watched.openedAt < value) && !SomeoneInDoorway(watched.doorway))
				{
					ZNetView val = View.Invoke(watched.door);
					if (Object.op_Implicit((Object)(object)val) && val.IsValid())
					{
						val.InvokeRPC("PotatoTweaks_CloseDoor", Array.Empty<object>());
					}
					AutoDoors.watched.RemoveAt(num);
				}
			}
		}

		private static bool SomeoneInDoorway(Bounds doorway)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			nearby.Clear();
			Vector3 center = ((Bounds)(ref doorway)).center;
			Vector3 extents = ((Bounds)(ref doorway)).extents;
			Character.GetCharactersInRange(center, ((Vector3)(ref extents)).magnitude, nearby);
			foreach (Character item in nearby)
			{
				if (Object.op_Implicit((Object)(object)item) && ((Bounds)(ref doorway)).Contains(((Component)item).transform.position))
				{
					return true;
				}
			}
			return false;
		}
	}
	internal static class Chests
	{
		[HarmonyPatch(typeof(Container), "Awake")]
		internal static class Register
		{
			private static void Postfix(Container __instance)
			{
				ZNetView view = View.Invoke(__instance);
				if (!Object.op_Implicit((Object)(object)view) || view.GetZDO() == null)
				{
					return;
				}
				view.Register<string>("PotatoTweaks_ChestName", (Action<long, string>)delegate(long sender, string name)
				{
					if (view.IsValid() && view.IsOwner())
					{
						view.GetZDO().Set(NameKey, Clean(name));
					}
				});
			}
		}

		private sealed class Namer : TextReceiver
		{
			private readonly Container chest;

			internal Namer(Container chest)
			{
				this.chest = chest;
			}

			public string GetText()
			{
				if (!Object.op_Implicit((Object)(object)chest))
				{
					return "";
				}
				return NameOf(chest);
			}

			public void SetText(string text)
			{
				if (Object.op_Implicit((Object)(object)chest))
				{
					ZNetView val = View.Invoke(chest);
					if (Object.op_Implicit((Object)(object)val) && val.IsValid())
					{
						val.InvokeRPC("PotatoTweaks_ChestName", new object[1] { Clean(text) });
					}
				}
			}
		}

		[HarmonyPatch(typeof(Container), "GetHoverText")]
		internal static class HoverName
		{
			private static void Postfix(Container __instance, ref string __result)
			{
				//IL_006b: Unknown result type (might be due to invalid IL or missing references)
				if (!Plugin.ChestNamesEnabled.Value || string.IsNullOrEmpty(__result) || !Allowed(__instance))
				{
					return;
				}
				string text = NameOf(__instance);
				if (text.Length > 0)
				{
					string text2 = Localization.instance.Localize(__instance.m_name);
					if (__result.StartsWith(text2))
					{
						__result = text + __result.Substring(text2.Length);
					}
				}
				__result = __result + "\n[<color=yellow><b>" + KeyText(Plugin.ChestNameKey.Value) + "</b></color>] Name";
			}
		}

		[HarmonyPatch(typeof(Hud), "UpdateCrosshair")]
		[HarmonyPriority(0)]
		internal static class ContentsRow
		{
			private const float Gap = 3f;

			private static RectTransform row;

			private static readonly List<Image> icons = new List<Image>();

			private static readonly List<TextMeshProUGUI> counts = new List<TextMeshProUGUI>();

			private static TextMeshProUGUI more;

			private static float builtSize;

			private static bool broken;

			private static readonly Dictionary<string, KeyValuePair<ItemData, int>> totals = new Dictionary<string, KeyValuePair<ItemData, int>>();

			private static void Postfix(Hud __instance)
			{
				if (broken)
				{
					return;
				}
				try
				{
					Show(__instance);
				}
				catch (Exception ex)
				{
					Plugin.Log.LogError((object)("Chest contents on hover is off until the game restarts: " + ex.GetBaseException().Message));
					broken = true;
					if (Object.op_Implicit((Object)(object)row))
					{
						((Component)row).gameObject.SetActive(false);
					}
				}
			}

			private static void Show(Hud hud)
			{
				//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
				//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
				//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
				//IL_03fa: 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_03bb: Unknown result type (might be due to invalid IL or missing references)
				Container val = ((Plugin.ChestContentsEnabled.Value && !InventoryGui.IsVisible() && ((TMP_Text)hud.m_hoverName).text.Length > 0) ? Hovered() : null);
				Inventory val2 = ((Object.op_Implicit((Object)(object)val) && Allowed(val)) ? val.GetInventory() : null);
				if (val2 == null || val2.NrOfItems() == 0)
				{
					if (Object.op_Implicit((Object)(object)row))
					{
						((Component)row).gameObject.SetActive(false);
					}
					return;
				}
				totals.Clear();
				foreach (ItemData allItem in val2.GetAllItems())
				{
					string name = allItem.m_shared.m_name;
					totals[name] = (totals.TryGetValue(name, out var value) ? new KeyValuePair<ItemData, int>(value.Key, value.Value + allItem.m_stack) : new KeyValuePair<ItemData, int>(allItem, allItem.m_stack));
				}
				List<KeyValuePair<ItemData, int>> list = (from t in totals.Values
					orderby t.Value descending, Localization.instance.Localize(t.Key.m_shared.m_name)
					select t).ToList();
				float num = Plugin.ChestIconSize.Value;
				int value2 = Plugin.ChestIconCount.Value;
				Build(hud.m_hoverName, num, value2);
				((TMP_Text)hud.m_hoverName).ForceMeshUpdate(false, false);
				TMP_TextInfo textInfo = ((TMP_Text)hud.m_hoverName).textInfo;
				TMP_FontAsset val3 = ((textInfo.characterCount > 0 && Object.op_Implicit((Object)(object)textInfo.characterInfo[0].fontAsset)) ? textInfo.characterInfo[0].fontAsset : ((TMP_Text)hud.m_hoverName).font);
				Material val4 = (((Object)(object)val3 == (Object)(object)((TMP_Text)hud.m_hoverName).font) ? ((TMP_Text)hud.m_hoverName).fontSharedMaterial : textInfo.characterInfo[0].material);
				if (!Object.op_Implicit((Object)(object)val4) || (Object)(object)val4.mainTexture != (Object)(object)val3.atlasTexture)
				{
					val4 = ((TMP_Asset)val3).material;
				}
				if ((Object)(object)((TMP_Text)more).font != (Object)(object)val3 || (Object)(object)((TMP_Text)more).fontSharedMaterial != (Object)(object)val4)
				{
					foreach (TextMeshProUGUI item in counts.Append(more))
					{
						((TMP_Text)item).font = val3;
						((TMP_Text)item).fontSharedMaterial = val4;
						((TMP_Text)item).ForceMeshUpdate(true, true);
					}
				}
				int num2 = Mathf.Min(value2, list.Count);
				for (int num3 = 0; num3 < icons.Count; num3++)
				{
					bool flag = num3 < num2;
					((Component)icons[num3]).gameObject.SetActive(flag);
					if (flag)
					{
						icons[num3].sprite = list[num3].Key.GetIcon();
						((TMP_Text)counts[num3]).text = Count(list[num3].Value);
					}
				}
				((Component)more).gameObject.SetActive(list.Count > num2);
				if (list.Count > num2)
				{
					((TMP_Text)more).text = $"+{list.Count - num2} more";
					((Transform)(RectTransform)((TMP_Text)more).transform).localPosition = new Vector3((float)num2 * (num + 3f) + 2f, (0f - num) / 2f, 0f);
				}
				Bounds textBounds = ((TMP_Text)hud.m_hoverName).textBounds;
				((Transform)row).localPosition = new Vector3(((Bounds)(ref textBounds)).min.x, ((Bounds)(ref textBounds)).min.y - 4f, 0f);
				((Component)row).gameObject.SetActive(true);
			}

			private static string Count(int count)
			{
				if (count < 10000)
				{
					if (count < 1000)
					{
						return count.ToString();
					}
					return $"{(float)count / 1000f:0.#}k";
				}
				return $"{count / 1000}k";
			}

			private static void Build(TextMeshProUGUI text, float size, int most)
			{
				//IL_0074: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
				//IL_012c: Unknown result type (might be due to invalid IL or missing references)
				//IL_014e: Unknown result type (might be due to invalid IL or missing references)
				//IL_016b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0171: Unknown result type (might be due to invalid IL or missing references)
				//IL_017a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0199: Unknown result type (might be due to invalid IL or missing references)
				//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f8: 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_0217: Unknown result type (might be due to invalid IL or missing references)
				//IL_0258: Unknown result type (might be due to invalid IL or missing references)
				//IL_025d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0268: Unknown result type (might be due to invalid IL or missing references)
				//IL_0272: Unknown result type (might be due to invalid IL or missing references)
				//IL_0273: Unknown result type (might be due to invalid IL or missing references)
				//IL_0285: Unknown result type (might be due to invalid IL or missing references)
				//IL_028b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0297: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)row) || !Mathf.Approximately(builtSize, size) || icons.Count != most)
				{
					if (Object.op_Implicit((Object)(object)row))
					{
						Object.Destroy((Object)(object)((Component)row).gameObject);
					}
					icons.Clear();
					counts.Clear();
					builtSize = size;
					row = new GameObject("PotatoChestContents", new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
					((Transform)row).SetParent(((TMP_Text)text).transform, false);
					row.pivot = new Vector2(0f, 1f);
					RectTransform obj = row;
					RectTransform obj2 = row;
					Vector2 val = default(Vector2);
					((Vector2)(ref val))..ctor(0.5f, 0.5f);
					obj2.anchorMax = val;
					obj.anchorMin = val;
					row.sizeDelta = new Vector2((float)most * (size + 3f), size);
					float fontSize = Mathf.Max(10f, size * 0.5f);
					for (int i = 0; i < most; i++)
					{
						RectTransform component = new GameObject("Item", new Type[2]
						{
							typeof(RectTransform),
							typeof(Image)
						}).GetComponent<RectTransform>();
						((Transform)component).SetParent((Transform)(object)row, false);
						component.pivot = new Vector2(0f, 1f);
						((Vector2)(ref val))..ctor(0f, 1f);
						component.anchorMax = val;
						component.anchorMin = val;
						component.sizeDelta = new Vector2(size, size);
						((Transform)component).localPosition = new Vector3((float)i * (size + 3f), 0f, 0f);
						Image component2 = ((Component)component).GetComponent<Image>();
						component2.preserveAspect = true;
						((Graphic)component2).raycastTarget = false;
						icons.Add(component2);
						TextMeshProUGUI val2 = Label(text, (Transform)(object)component, fontSize, (TextAlignmentOptions)1028);
						RectTransform val3 = (RectTransform)((TMP_Text)val2).transform;
						val3.anchorMin = Vector2.zero;
						val3.anchorMax = Vector2.one;
						val3.offsetMin = new Vector2(-6f, -3f);
						val3.offsetMax = new Vector2(3f, 0f);
						counts.Add(val2);
					}
					more = Label(text, (Transform)(object)row, fontSize, (TextAlignmentOptions)4097);
					RectTransform val4 = (RectTransform)((TMP_Text)more).transform;
					val4.pivot = new Vector2(0f, 0.5f);
					((Vector2)(ref val))..ctor(0f, 1f);
					val4.anchorMax = val;
					val4.anchorMin = val;
					val4.sizeDelta = new Vector2(120f, size);
				}
			}

			private static TextMeshProUGUI Label(TextMeshProUGUI like, Transform parent, float fontSize, TextAlignmentOptions alignment)
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Expected O, but got Unknown
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				GameObject val = new GameObject("Text", new Type[1] { typeof(RectTransform) });
				val.SetActive(false);
				TextMeshProUGUI obj = val.AddComponent<TextMeshProUGUI>();
				((TMP_Text)obj).transform.SetParent(parent, false);
				((TMP_Text)obj).font = ((TMP_Text)like).font;
				((TMP_Text)obj).fontSharedMaterial = ((TMP_Text)like).fontSharedMaterial;
				((TMP_Text)obj).fontSize = fontSize;
				((TMP_Text)obj).textWrappingMode = (TextWrappingModes)0;
				((TMP_Text)obj).overflowMode = (TextOverflowModes)0;
				((TMP_Text)obj).alignment = alignment;
				((Graphic)obj).color = Color.white;
				((Graphic)obj).raycastTarget = false;
				val.SetActive(true);
				return obj;
			}
		}

		private const string NameRpc = "PotatoTweaks_ChestName";

		private static readonly int NameKey = StringExtensionMethods.GetStableHashCode("potato_chestname");

		private const int NameLimit = 32;

		internal static readonly Type[] Patches = new Type[3]
		{
			typeof(Register),
			typeof(HoverName),
			typeof(ContentsRow)
		};

		private static readonly FieldRef<Container, ZNetView> View = AccessTools.FieldRefAccess<Container, ZNetView>("m_nview");

		private static readonly Func<Container, long, bool> CheckAccess = AccessTools.MethodDelegate<Func<Container, long, bool>>(AccessTools.Method(typeof(Container), "CheckAccess", (Type[])null, (Type[])null), (object)null, true);

		private static bool Allowed(Container chest)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)chest) || Object.op_Implicit((Object)(object)((Component)chest).GetComponent<TombStone>()))
			{
				return false;
			}
			ZNetView val = View.Invoke(chest);
			if (!Object.op_Implicit((Object)(object)val) || !val.IsValid())
			{
				return false;
			}
			if (chest.m_checkGuardStone && !PrivateArea.CheckAccess(((Component)chest).transform.position, 0f, false, false))
			{
				return false;
			}
			return CheckAccess(chest, Game.instance.GetPlayerProfile().GetPlayerID());
		}

		private static string NameOf(Container chest)
		{
			ZNetView val = View.Invoke(chest);
			if (!Object.op_Implicit((Object)(object)val) || !val.IsValid())
			{
				return "";
			}
			return val.GetZDO().GetString(NameKey, "");
		}

		private static Container Hovered()
		{
			GameObject val = (Object.op_Implicit((Object)(object)Player.m_localPlayer) ? ((Humanoid)Player.m_localPlayer).GetHoverObject() : null);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return null;
			}
			return val.GetComponentInParent<Container>();
		}

		private static string KeyText(KeyboardShortcut key)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			List<string> list = ((KeyboardShortcut)(ref key)).Modifiers.Select(KeyName).ToList();
			list.Add(KeyName(((KeyboardShortcut)(ref key)).MainKey));
			return string.Join(" + ", list);
		}

		private unsafe static string KeyName(KeyCode key)
		{
			//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_0024: Expected I4, but got Unknown
			switch (key - 303)
			{
			case 2:
			case 3:
				return "Ctrl";
			case 0:
			case 1:
				return "Shift";
			case 4:
			case 5:
				return "Alt";
			default:
				return ((object)(*(KeyCode*)(&key))/*cast due to .constrained prefix*/).ToString();
			}
		}

		private static string Clean(string name)
		{
			name = (name ?? "").Replace("<", "").Replace(">", "").Replace("\n", " ")
				.Trim();
			if (name.Length <= 32)
			{
				return name;
			}
			return name.Substring(0, 32);
		}

		internal static void Update()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.ChestNamesEnabled.Value || !Object.op_Implicit((Object)(object)Player.m_localPlayer) || !Object.op_Implicit((Object)(object)TextInput.instance))
			{
				return;
			}
			KeyboardShortcut value = Plugin.ChestNameKey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown() && !TextInput.IsVisible() && !Console.IsVisible() && !Menu.IsVisible() && !InventoryGui.IsVisible() && !Minimap.IsOpen() && (!Object.op_Implicit((Object)(object)Chat.instance) || !Chat.instance.HasFocus()) && !StoreGui.IsVisible())
			{
				Container chest = Hovered();
				if (Allowed(chest))
				{
					TextInput.instance.RequestText((TextReceiver)(object)new Namer(chest), "Chest name", 32);
				}
			}
		}
	}
	internal static class CombatEffects
	{
		private enum Source
		{
			None,
			Status,
			CreatureHit,
			Weapon,
			Impact
		}

		[HarmonyPatch]
		internal static class CreatureHits
		{
			private static IEnumerable<MethodBase> TargetMethods()
			{
				yield return AccessTools.Method(typeof(Character), "ApplyDamage", (Type[])null, (Type[])null);
				yield return AccessTools.Method(typeof(Character), "RPC_Damage", (Type[])null, (Type[])null);
			}

			private static void Prefix(Character __instance, out Character __state)
			{
				__state = hitCharacter;
				hitCharacter = __instance;
			}

			private static void Finalizer(Character __state)
			{
				hitCharacter = __state;
			}
		}

		[HarmonyPatch(typeof(StatusEffect), "TriggerStartEffects")]
		internal static class StatusStart
		{
			private static void Prefix(StatusEffect __instance, out StatusEffect __state)
			{
				__state = status;
				status = __instance;
			}

			private static void Finalizer(StatusEffect __state)
			{
				status = __state;
			}
		}

		[HarmonyPatch]
		internal static class StatusTick
		{
			private static IEnumerable<MethodBase> TargetMethods()
			{
				yield return AccessTools.Method(typeof(SE_Burning), "UpdateStatusEffect", (Type[])null, (Type[])null);
				yield return AccessTools.Method(typeof(SE_Poison), "UpdateStatusEffect", (Type[])null, (Type[])null);
				yield return AccessTools.Method(typeof(SE_Stats), "UpdateStatusEffect", (Type[])null, (Type[])null);
			}

			private static void Prefix(StatusEffect __instance, out StatusEffect __state)
			{
				__state = status;
				status = __instance;
			}

			private static void Finalizer(StatusEffect __state)
			{
				status = __state;
			}
		}

		[HarmonyPatch]
		internal static class Weapons
		{
			private static IEnumerable<MethodBase> TargetMethods()
			{
				yield return AccessTools.Method(typeof(Attack), "DoMeleeAttack", (Type[])null, (Type[])null);
				yield return AccessTools.Method(typeof(Attack), "DoAreaAttack", (Type[])null, (Type[])null);
			}

			private static void Prefix(Attack __instance, out Attack __state)
			{
				__state = attack;
				attack = __instance;
			}

			private static void Finalizer(Attack __state)
			{
				attack = __state;
			}
		}

		[HarmonyPatch(typeof(Projectile), "OnHit")]
		internal static class Projectiles
		{
			private static void Prefix(Projectile __instance, out Projectile __state)
			{
				__state = projectile;
				projectile = __instance;
			}

			private static void Finalizer(Projectile __state)
			{
				projectile = __state;
			}
		}

		[HarmonyPatch(typeof(Aoe), "OnHit")]
		internal static class Areas
		{
			private static void Prefix(Aoe __instance, out Aoe __state)
			{
				__state = area;
				area = __instance;
			}

			private static void Finalizer(Aoe __state)
			{
				area = __state;
			}
		}

		[HarmonyPatch(typeof(EffectList), "Create")]
		internal static class Created
		{
			private static void Postfix(EffectList __instance, GameObject[] __result)
			{
				if (__result == null || __result.Length == 0 || !Active || ((Object)(object)status == (Object)null && !Object.op_Implicit((Object)(object)hitCharacter) && attack == null && !Object.op_Implicit((Object)(object)projectile) && !Object.op_Implicit((Object)(object)area)) || Of(__instance) == Source.None)
				{
					return;
				}
				float num = Mathf.Clamp01(Plugin.DimOpacity.Value);
				float num2 = Mathf.Clamp01(Plugin.DimBrightness.Value);
				float size = Mathf.Clamp(Plugin.DimSize.Value, 0.1f, 1f);
				foreach (GameObject val in __result)
				{
					if (Object.op_Implicit((Object)(object)val))
					{
						ParticleSystem[] componentsInChildren = val.GetComponentsInChildren<ParticleSystem>(true);
						for (int j = 0; j < componentsInChildren.Length; j++)
						{
							Dim(componentsInChildren[j], num, num2, size);
						}
						Light[] componentsInChildren2 = val.GetComponentsInChildren<Light>(true);
						foreach (Light obj in componentsInChildren2)
						{
							obj.intensity *= num * num2;
						}
					}
				}
			}
		}

		[ThreadStatic]
		private static Character hitCharacter;

		[ThreadStatic]
		private static StatusEffect status;

		[ThreadStatic]
		private static Attack attack;

		[ThreadStatic]
		private static Projectile projectile;

		[ThreadStatic]
		private static Aoe area;

		private static readonly FieldRef<Projectile, Character> ProjectileOwner = AccessTools.FieldRefAccess<Projectile, Character>("m_owner");

		private static readonly FieldRef<Aoe, Character> AreaOwner = AccessTools.FieldRefAccess<Aoe, Character>("m_owner");

		private static readonly FieldRef<Attack, Humanoid> Attacker = AccessTools.FieldRefAccess<Attack, Humanoid>("m_character");

		private static readonly Dictionary<Type, FieldInfo> TickFields = new Dictionary<Type, FieldInfo>();

		internal static readonly Type[] Patches = new Type[7]
		{
			typeof(CreatureHits),
			typeof(StatusStart),
			typeof(StatusTick),
			typeof(Weapons),
			typeof(Projectiles),
			typeof(Areas),
			typeof(Created)
		};

		private static bool Active
		{
			get
			{
				if (Plugin.DimEnabled.Value)
				{
					if (!(Plugin.DimOpacity.Value < 0.999f) && !(Plugin.DimBrightness.Value < 0.999f))
					{
						return Plugin.DimSize.Value < 0.999f;
					}
					return true;
				}
				return false;
			}
		}

		private static bool Counts(Character character)
		{
			if (Object.op_Implicit((Object)(object)character))
			{
				if (character.IsPlayer())
				{
					return Plugin.DimOnPlayers.Value;
				}
				return true;
			}
			return false;
		}

		private static EffectList TickEffect(StatusEffect effect)
		{
			Type type = ((object)effect).GetType();
			if (!TickFields.TryGetValue(type, out var value))
			{
				value = (TickFields[type] = AccessTools.Field(type, "m_tickEffect"));
			}
			object? obj = value?.GetValue(effect);
			return (EffectList)((obj is EffectList) ? obj : null);
		}

		private static Source Of(EffectList list)
		{
			if ((Object)(object)status != (Object)null && Counts(status.m_character) && (list == status.m_startEffects || list == TickEffect(status)))
			{
				if (!Plugin.DimStatus.Value)
				{
					return Source.None;
				}
				return Source.Status;
			}
			if (Object.op_Implicit((Object)(object)hitCharacter) && Counts(hitCharacter) && (list == hitCharacter.m_hitEffects || list == hitCharacter.m_critHitEffects || list == hitCharacter.m_backstabHitEffects))
			{
				if (!Plugin.DimCreatureHits.Value)
				{
					return Source.None;
				}
				return Source.CreatureHit;
			}
			if (attack != null && Attacker.Invoke(attack) is Player && (list == attack.m_hitEffect || list == attack.GetWeapon()?.m_shared.m_hitEffect))
			{
				if (!Plugin.DimWeapons.Value)
				{
					return Source.None;
				}
				return Source.Weapon;
			}
			if (Object.op_Implicit((Object)(object)projectile) && ProjectileOwner.Invoke(projectile) is Player && list == projectile.m_hitEffects)
			{
				if (!Plugin.DimImpacts.Value)
				{
					return Source.None;
				}
				return Source.Impact;
			}
			if (Object.op_Implicit((Object)(object)area) && AreaOwner.Invoke(area) is Player && list == area.m_hitEffects)
			{
				if (!Plugin.DimImpacts.Value)
				{
					return Source.None;
				}
				return Source.Impact;
			}
			return Source.None;
		}

		private static void Dim(ParticleSystem system, float opacity, float brightness, float size)
		{
			//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_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)
			MainModule main = system.main;
			((MainModule)(ref main)).startColor = Scale(((MainModule)(ref main)).startColor, opacity, brightness);
			((MainModule)(ref main)).startSizeMultiplier = ((MainModule)(ref main)).startSizeMultiplier * size;
		}

		private static Color Scale(Color color, float opacity, float brightness)
		{
			//IL_0000: 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_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			return new Color(color.r * brightness, color.g * brightness, color.b * brightness, color.a * opacity);
		}

		private static Gradient Scale(Gradient gradient, float opacity, float brightness)
		{
			//IL_001e: 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_002e: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			if (gradient == null)
			{
				return null;
			}
			GradientColorKey[] colorKeys = gradient.colorKeys;
			for (int i = 0; i < colorKeys.Length; i++)
			{
				colorKeys[i].color = Scale(colorKeys[i].color, 1f, brightness);
			}
			GradientAlphaKey[] alphaKeys = gradient.alphaKeys;
			for (int j = 0; j < alphaKeys.Length; j++)
			{
				alphaKeys[j].alpha *= opacity;
			}
			Gradient val = new Gradient
			{
				mode = gradient.mode
			};
			val.SetKeys(colorKeys, alphaKeys);
			return val;
		}

		private static MinMaxGradient Scale(MinMaxGradient value, float opacity, float brightness)
		{
			//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_0022: Expected I4, but got Unknown
			//IL_0029: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_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_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			ParticleSystemGradientMode mode = ((MinMaxGradient)(ref value)).mode;
			switch ((int)mode)
			{
			case 0:
				return new MinMaxGradient(Scale(((MinMaxGradient)(ref value)).color, opacity, brightness));
			case 2:
				return new MinMaxGradient(Scale(((MinMaxGradient)(ref value)).colorMin, opacity, brightness), Scale(((MinMaxGradient)(ref value)).colorMax, opacity, brightness));
			case 1:
				return new MinMaxGradient(Scale(((MinMaxGradient)(ref value)).gradient, opacity, brightness));
			case 3:
				return new MinMaxGradient(Scale(((MinMaxGradient)(ref value)).gradientMin, opacity, brightness), Scale(((MinMaxGradient)(ref value)).gradientMax, opacity, brightness));
			case 4:
			{
				MinMaxGradient result = default(MinMaxGradient);
				((MinMaxGradient)(ref result))..ctor(Scale(((MinMaxGradient)(ref value)).gradient, opacity, brightness));
				((MinMaxGradient)(ref result)).mode = (ParticleSystemGradientMode)4;
				return result;
			}
			default:
				return value;
			}
		}
	}
	internal static class ComfortHelper
	{
		internal const string OriginalModId = "com.koendertjh.comforthelper";

		internal static readonly Type[] Patches = new Type[2]
		{
			typeof(ComfortTabPatches),
			typeof(RestingMessage)
		};

		internal static void RegisterCommand()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			new ConsoleCommand("comfort", "Your comfort here and the pieces that would raise it (Potato Tweaks)", new ConsoleEvent(ComfortCommand.Run), false, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
		}

		internal static float MaxComfort()
		{
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			Achievement val = null;
			if ((Object)(object)Achievements.m_instance != (Object)null)
			{
				foreach (AchievementList achievementList in Achievements.m_instance.m_achievementLists)
				{
					foreach (Achievement achievement in achievementList.m_achievements)
					{
						if ((Object)(object)achievement != (Object)null && achievement.m_id == "GrindComfort")
						{
							val = achievement;
						}
					}
				}
			}
			Game instance = Game.instance;
			PlayerProfile val2 = ((instance != null) ? instance.GetPlayerProfile() : null);
			if (val2 == null || (Object)(object)val == (Object)null)
			{
				return 0f;
			}
			PlayerStats val3 = val2.m_playerStats[val.m_difficultyRequirement];
			if (val3 == null || !val3.m_stats.TryGetValue((PlayerStatType)132, out var value))
			{
				return 0f;
			}
			return value;
		}
	}
	internal class Suggestion
	{
		public Piece Piece;

		public int Gain;

		public Piece Replaces;
	}
	internal class ComfortReport
	{
		public bool InShelter;

		public int Current;

		public int BestKnown;

		public int Locked;

		public float MaxReached;

		public readonly List<Suggestion> Suggestions = new List<Suggestion>();
	}
	internal static class Comfort
	{
		private const float Radius = 10f;

		private static readonly List<Piece> s_nearby = new List<Piece>();

		private static List<Piece> s_comfortPrefabs;

		private static ZNetScene s_scene;

		private static readonly string[] GroupNames = Enum.GetNames(typeof(ComfortGroup));

		internal static string GroupOf(Piece piece)
		{
			//IL_0001: 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)
			if ((int)piece.m_comfortGroup == 0)
			{
				return piece.m_name;
			}
			return GroupNames[piece.m_comfortGroup];
		}

		internal static Dictionary<string, Piece> BestNearby(Vector3 position)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<string, Piece> dictionary = new Dictionary<string, Piece>();
			Nearby(position, dictionary, null);
			return dictionary;
		}

		internal static void Nearby(Vector3 position, Dictionary<string, Piece> best, HashSet<string> names)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			s_nearby.Clear();
			Piece.GetAllComfortPiecesInRadius(position, 10f, s_nearby);
			foreach (Piece item in s_nearby)
			{
				names?.Add(item.m_name);
				if (best != null)
				{
					string key = GroupOf(item);
					if (!best.TryGetValue(key, out var value) || item.GetComfort() > value.GetComfort())
					{
						best[key] = item;
					}
				}
			}
		}

		internal static ComfortReport Build(Player player)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			ComfortReport comfortReport = new ComfortReport
			{
				InShelter = player.InShelter(),
				Current = SE_Rested.CalculateComfortLevel(player),
				MaxReached = ComfortHelper.MaxComfort()
			};
			Dictionary<string, Piece> dictionary = BestNearby(((Component)player).transform.position);
			Dictionary<string, Piece> dictionary2 = new Dictionary<string, Piece>();
			Dictionary<string, int> dictionary3 = new Dictionary<string, int>();
			foreach (Piece item in ComfortPrefabs())
			{
				string key = GroupOf(item);
				if (!dictionary3.TryGetValue(key, out var value) || item.m_comfort > value)
				{
					dictionary3[key] = item.m_comfort;
				}
				if (player.IsRecipeKnown(item.m_name) && (!dictionary2.TryGetValue(key, out var value2) || item.m_comfort > value2.m_comfort))
				{
					dictionary2[key] = item;
				}
			}
			int num = 0;
			foreach (KeyValuePair<string, Piece> item2 in dictionary2)
			{
				num += item2.Value.m_comfort;
				dictionary.TryGetValue(item2.Key, out var value3);
				int num2 = item2.Value.m_comfort - (((Object)(object)value3 != (Object)null) ? value3.GetComfort() : 0);
				if (num2 > 0)
				{
					comfortReport.Suggestions.Add(new Suggestion
					{
						Piece = item2.Value,
						Gain = num2,
						Replaces = value3
					});
				}
			}
			comfortReport.BestKnown = 2 + num;
			comfortReport.Locked = dictionary3.Sum((KeyValuePair<string, int> p) => p.Value) - num;
			comfortReport.Suggestions.Sort((Suggestion a, Suggestion b) => b.Gain.CompareTo(a.Gain));
			return comfortReport;
		}

		private static List<Piece> ComfortPrefabs()
		{
			if (s_comfortPrefabs != null && (Object)(object)s_scene == (Object)(object)ZNetScene.instance)
			{
				return s_comfortPrefabs;
			}
			s_scene = ZNetScene.instance;
			s_comfortPrefabs = new List<Piece>();
			if ((Object)(object)s_scene == (Object)null || (Object)(object)ObjectDB.instance == (Object)null)
			{
				return s_comfortPrefabs;
			}
			HashSet<string> hashSet = new HashSet<string>();
			foreach (GameObject item in ObjectDB.instance.m_items)
			{
				PieceTable val = ((!((Object)(object)item != (Object)null)) ? null : item.GetComponent<ItemDrop>()?.m_itemData.m_shared.m_buildPieces);
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				foreach (GameObject piece in val.m_pieces)
				{
					Piece val2 = (((Object)(object)piece != (Object)null) ? piece.GetComponent<Piece>() : null);
					if ((Object)(object)val2 != (Object)null && val2.m_comfort > 0 && hashSet.Add(val2.m_name))
					{
						s_comfortPrefabs.Add(val2);
					}
				}
			}
			return s_comfortPrefabs;
		}

		internal static string Describe(Suggestion suggestion)
		{
			string arg = Localization.instance.Localize(suggestion.Piece.m_name);
			if (!((Object)(object)suggestion.Replaces == (Object)null))
			{
				return $"+{suggestion.Gain} {arg} (instead of {Localization.instance.Localize(suggestion.Replaces.m_name)})";
			}
			return $"+{suggestion.Gain} {arg}";
		}
	}
	internal static class ComfortGroups
	{
		internal unsafe static string Name(ComfortGroup group)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected I4, but got Unknown
			return (int)group switch
			{
				1 => "Fires", 
				2 => "Beds", 
				3 => "Banners", 
				4 => "Seats", 
				5 => "Tables", 
				6 => "Rugs", 
				7 => "Displays", 
				8 => "Decorations", 
				9 => "Garlands", 
				10 => "Lanterns", 
				11 => "Leisure", 
				0 => "Each counts", 
				_ => ((object)(*(ComfortGroup*)(&group))/*cast due to .constrained prefix*/).ToString(), 
			};
		}
	}
	internal sealed class ComfortPieceList : IPieceList
	{
		private readonly ComfortGroup[] _groups = (ComfortGroup[])Enum.GetValues(typeof(ComfortGroup));

		private readonly List<int> _availableTags = new List<int>();

		public string DisplayName { get; }

		public bool ShowTags => true;

		public bool CanCustomizeTags => false;

		public int TagCount => _availableTags.Count;

		public int TagSeparatorIndex => -1;

		public ComfortPieceList(string displayName)
		{
			DisplayName = displayName;
		}

		public string GetTagDisplayName(int index)
		{
			int num = (int)_groups[_availableTags[index]];
			string text = ComfortGroups.Name((ComfortGroup)num);
			int num2 = NearbyState.GroupComfort((ComfortGroup)num);
			if (num2 <= 0)
			{
				return text;
			}
			return $"<color=#7CFC7C>{text} +{num2}</color>";
		}

		public int GetTagIdByIndex(int index)
		{
			return _availableTags[index];
		}

		public void UpdateAvailableTags(PieceTable pieceTable)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			HashSet<ComfortGroup> hashSet = new HashSet<ComfortGroup>();
			foreach (Piece availablePiece in pieceTable.m_availablePieces)
			{
				if (availablePiece.m_comfort > 0)
				{
					hashSet.Add(availablePiece.m_comfortGroup);
				}
			}
			_availableTags.Clear();
			for (int i = 0; i < _groups.Length; i++)
			{
				if (_groups[i] && hashSet.Contains(_groups[i]))
				{
					_availableTags.Add(i);
				}
			}
			int item = Array.IndexOf(_groups, (ComfortGroup)0);
			if (hashSet.Contains((ComfortGroup)0))
			{
				_availableTags.Add(item);
			}
		}

		public void GetAvailablePiecesWithTag(int tagId, PieceTable pieceTable, IList<Piece> resultOut)
		{
			foreach (Piece item in from p in pieceTable.m_availablePieces
				where p.m_comfort > 0 && (tagId < 0 || tagId >= _groups.Length || (int)p.m_comfortGroup == (int)_groups[tagId])
				orderby p.m_comfort descending
				select p)
			{
				resultOut.Add(item);
			}
		}
	}
	internal static class NearbyState
	{
		private static Dictionary<string, Piece> s_best = new Dictionary<string, Piece>();

		private static HashSet<string> s_names = new HashSet<string>();

		private static Dictionary<string, Piece> s_nextBest = new Dictionary<string, Piece>();

		private static HashSet<string> s_nextNames = new HashSet<string>();

		private static float s_nextUpdate;

		internal static int Version { get; private set; }

		internal static bool Update(Player player, bool force = false)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			if (!force && Time.time < s_nextUpdate)
			{
				return false;
			}
			s_nextUpdate = Time.time + 1f;
			s_nextBest.Clear();
			s_nextNames.Clear();
			Comfort.Nearby(((Component)player).transform.position, s_nextBest, s_nextNames);
			bool num = !s_nextNames.SetEquals(s_names) || !SameCounting(s_nextBest, s_best);
			Dictionary<string, Piece> dictionary = s_nextBest;
			Dictionary<string, Piece> dictionary2 = s_best;
			s_best = dictionary;
			s_nextBest = dictionary2;
			HashSet<string> hashSet = s_nextNames;
			HashSet<string> hashSet2 = s_names;
			s_names = hashSet;
			s_nextNames = hashSet2;
			if (num)
			{
				Version++;
			}
			return num;
		}

		private static bool SameCounting(Dictionary<string, Piece> a, Dictionary<string, Piece> b)
		{
			if (a.Count != b.Count)
			{
				return false;
			}
			foreach (KeyValuePair<string, Piece> item in a)
			{
				if (!b.TryGetValue(item.Key, out var value) || value.m_name != item.Value.m_name)
				{
					return false;
				}
			}
			return true;
		}

		internal static bool IsHere(Piece piece)
		{
			return s_names.Contains(piece.m_name);
		}

		internal static bool Counts(Piece piece)
		{
			if (s_best.TryGetValue(Comfort.GroupOf(piece), out var value))
			{
				return value.m_name == piece.m_name;
			}
			return false;
		}

		internal static Piece Counting(Piece piece)
		{
			if (!s_best.TryGetValue(Comfort.GroupOf(piece), out var value))
			{
				return null;
			}
			return value;
		}

		internal unsafe static int GroupComfort(ComfortGroup group)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if ((int)group == 0)
			{
				return s_best.Values.Where((Piece p) => (int)p.m_comfortGroup == 0).Sum((Piece p) => p.GetComfort());
			}
			if (!s_best.TryGetValue(((object)(*(ComfortGroup*)(&group))/*cast due to .constrained prefix*/).ToString(), out var value))
			{
				return 0;
			}
			return value.GetComfort();
		}
	}
	[HarmonyPatch]
	internal static class ComfortTabPatches
	{
		private const string CheckName = "PotatoTweaks_ComfortCheck";

		private static readonly Color Green = new Color(0.45f, 0.95f, 0.45f);

		private static readonly Color Grey = new Color(0.62f, 0.62f, 0.62f);

		private static readonly FieldRef<BuildUi, RectTransform> TabContainerRef = AccessTools.FieldRefAccess<BuildUi, RectTransform>("m_tabContainer");

		private static readonly FieldRef<BuildUi, TabHandler> TabHandlerRef = AccessTools.FieldRefAccess<BuildUi, TabHandler>("m_tabHandler");

		private static readonly FieldRef<BuildUi, List<IPieceList>> PieceListsRef = AccessTools.FieldRefAccess<BuildUi, List<IPieceList>>("m_pieceLists");

		private static readonly FieldRef<BuildUi, int> AvailablePieceCountRef = AccessTools.FieldRefAccess<BuildUi, int>("m_availablePieceCount");

		private static readonly FieldRef<BuildUi, int> CurrentPieceListRef = AccessTools.FieldRefAccess<BuildUi, int>("m_currentPieceList");

		private static readonly FieldRef<BuildUi, List<BuildUiPieceButton>> PieceButtonsRef = AccessTools.FieldRefAccess<BuildUi, List<BuildUiPieceButton>>("m_pieceButtons");

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

		private static int s_hoverVersion = -1;

		[HarmonyPrefix]
		[HarmonyPatch(typeof(BuildUi), "Awake")]
		private static void BeforeAwake(BuildUi __instance, out bool __state)
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//IL_00b6: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Expected O, but got Unknown
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Expected O, but got Unknown
			__state = false;
			if (!Plugin.ComfortTab.Value)
			{
				return;
			}
			RectTransform val = TabContainerRef.Invoke(__instance);
			TabHandler val2 = TabHandlerRef.Invoke(__instance);
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || ((Transform)val).childCount < 2 || val2.m_tabs.Count != ((Transform)val).childCount)
			{
				Plugin.Log.LogWarning((object)"Build menu tabs have an unexpected layout; the Comfort tab is disabled.");
				return;
			}
			RectTransform val3 = (RectTransform)((Transform)val).GetChild(((Transform)val).childCount - 1);
			RectTransform val4 = (RectTransform)((Transform)val).GetChild(((Transform)val).childCount - 2);
			RectTransform val5 = Object.Instantiate<RectTransform>(val3, (Transform)(object)val);
			((Object)val5).name = "PotatoTweaks_ComfortTab";
			if ((Object)(object)((Component)val).GetComponent<LayoutGroup>() == (Object)null)
			{
				val5.anchoredPosition = val3.anchoredPosition + (val3.anchoredPosition - val4.anchoredPosition);
			}
			TMP_Text[] componentsInChildren = ((Component)val5).GetComponentsInChildren<TMP_Text>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].text = Plugin.ComfortTabName.Value;
			}
			Button component = ((Component)val5).GetComponent<Button>();
			component.onClick = new ButtonClickedEvent();
			val2.m_tabs.Add(new Tab
			{
				m_button = component
			});
			__state = true;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(BuildUi), "Awake")]
		private static void AfterAwake(BuildUi __instance, bool __state)
		{
			if (__state)
			{
				PieceListsRef.Invoke(__instance).Add((IPieceList)(object)new ComfortPieceList(Plugin.ComfortTabName.Value));
			}
		}

		private static bool ComfortTabShown(BuildUi buildUi)
		{
			List<IPieceList> list = PieceListsRef.Invoke(buildUi);
			int num = CurrentPieceListRef.Invoke(buildUi);
			if (num >= 0 && num < list.Count)
			{
				return list[num] is ComfortPieceList;
			}
			return false;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(BuildUi), "UpdatePieceButtons")]
		private static void AfterUpdatePieceButtons(BuildUi __instance)
		{
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			bool flag = (Object)(object)localPlayer != (Object)null && (ComfortTabShown(__instance) || Plugin.ComfortChecksEverywhere.Value);
			if (flag)
			{
				NearbyState.Update(localPlayer, force: true);
			}
			foreach (BuildUiPieceButton item in PieceButtonsRef.Invoke(__instance))
			{
				Piece piece = item.Piece;
				bool flag2 = flag && (Object)(object)piece != (Object)null && piece.m_comfort > 0 && NearbyState.IsHere(piece);
				Transform val = ((Component)item).transform.Find("PotatoTweaks_ComfortCheck");
				if ((Object)(object)val == (Object)null)
				{
					if (!flag2)
					{
						continue;
					}
					val = CreateCheck(((Component)item).transform);
				}
				((Component)val).gameObject.SetActive(flag2);
				if (flag2)
				{
					Color color = (NearbyState.Counts(piece) ? Green : Grey);
					Image[] componentsInChildren = ((Component)val).GetComponentsInChildren<Image>(true);
					for (int i = 0; i < componentsInChildren.Length; i++)
					{
						((Graphic)componentsInChildren[i]).color = color;
					}
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Hud), "Update")]
		private static void AfterHudUpdate()
		{
			BuildUi val = (((Object)(object)Hud.instance != (Object)null) ? Hud.instance.m_buildUi : null);
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)val == (Object)null) && !((Object)(object)localPlayer == (Object)null) && ((Behaviour)val).isActiveAndEnabled && (ComfortTabShown(val) || Plugin.ComfortChecksEverywhere.Value) && NearbyState.Update(localPlayer))
			{
				AvailablePieceCountRef.Invoke(val) = -1;
			}
		}

		private static Transform CreateCheck(Transform button)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0024: 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_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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Expected O, but got Unknown
			//IL_00be: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Expected O, but got Unknown
			//IL_00ef: Expected O, but got Unknown
			GameObject val = new GameObject("PotatoTweaks_ComfortCheck", new Type[1] { typeof(RectTransform) });
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent(button, false);
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(1f, 1f);
			val2.anchorMax = val3;
			val2.anchorMin = val3;
			val2.pivot = new Vector2(1f, 1f);
			val2.anchoredPosition = new Vector2(-3f, -3f);
			val2.sizeDelta = new Vector2(18f, 16f);
			((Transform)val2).SetAsLastSibling();
			Bar(val2, new Vector2(5f, 6f), new Vector2(9f, 4f), -45f);
			Bar(val2, new Vector2(11f, 8f), new Vector2(15f, 4f), 50f);
			val.SetActive(false);
			return (Transform)val2;
		}

		private static void Bar(RectTransform parent, Vector2 center, Vector2 size, float angle)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0051: 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_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_0096: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("bar", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Outline)
			});
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent((Transform)(object)parent, false);
			Vector2 anchorMin = (val2.anchorMax = Vector2.zero);
			val2.anchorMin = anchorMin;
			val2.pivot = new Vector2(0.5f, 0.5f);
			val2.anchoredPosition = center;
			val2.sizeDelta = size;
			((Transform)val2).localRotation = Quaternion.Euler(0f, 0f, angle);
			((Graphic)val.GetComponent<Image>()).raycastTarget = false;
			Outline component = val.GetComponent<Outline>();
			((Shadow)component).effectColor = new Color(0f, 0f, 0f, 0.85f);
			((Shadow)component).effectDistance = new Vector2(1f, -1f);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Hud), "SetupPieceInfo")]
		private static void AfterSetupPieceInfo(Hud __instance, Piece piece)
		{
			Player localPlayer = Player.m_localPlayer;
			if (Plugin.ComfortHoverInfo.Value && !((Object)(object)piece == (Object)null) && piece.m_comfort > 0 && !((Object)(object)localPlayer == (Object)null))
			{
				NearbyState.Update(localPlayer);
				if (s_hoverVersion != NearbyState.Version)
				{
					s_hoverTexts.Clear();
					s_hoverVersion = NearbyState.Version;
				}
				if (!s_hoverTexts.TryGetValue(piece.m_name, out var value))
				{
					value = (s_hoverTexts[piece.m_name] = HoverText(piece));
				}
				TMP_Text pieceDescription = __instance.m_pieceDescription;
				pieceDescription.text += value;
			}
		}

		private static string HoverText(Piece piece)
		{
			//IL_001e: 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)
			Localization instance = Localization.instance;
			string text = $"\n\n<color=#ffb347>Comfort +{piece.m_comfort}</color> ";
			text += (((int)piece.m_comfortGroup == 0) ? "(counts once, next to everything else)" : ("(" + ComfortGroups.Name(piece.m_comfortGroup) + ": only the best one nearby counts)"));
			Piece val = NearbyState.Counting(piece);
			if ((Object)(object)val == (Object)null)
			{
				return text + $"\nNothing like it within 10 m: <color=#7CFC7C>+{piece.m_comfort} here</color>.";
			}
			if (val.m_name == piece.m_name)
			{
				return text + "\n<color=#7CFC7C>Already counts here.</color>";
			}
			if (piece.m_comfort > val.GetComfort())
			{
				return text + $"\n{instance.Localize(val.m_name)} counts here now: <color=#7CFC7C>+{piece.m_comfort - val.GetComfort()} more</color> with this one.";
			}
			return text + "\n" + instance.Localize(val.m_name) + " already counts here; this one adds nothing.";
		}
	}
	[HarmonyPatch(typeof(Player), "UpdateEnvStatusEffects")]
	internal static class RestingMessage
	{
		private static bool s_wasResting;

		private static float s_lastShown = -10000f;

		private static void Postfix(Player __instance)
		{
			if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return;
			}
			bool flag = ((Character)__instance).GetSEMan().HaveStatusEffect(SEMan.s_statusEffectResting);
			bool num = flag && !s_wasResting;
			s_wasResting = flag;
			if (!num || !Plugin.ComfortRestingMessage.Value || Time.time - s_lastShown < Plugin.ComfortMessageCooldown.Value)
			{
				return;
			}
			s_lastShown = Time.time;
			ComfortReport comfortReport = Comfort.Build(__instance);
			string text = $"Comfort {comfortReport.Current} (best so far {comfortReport.MaxReached:0}, Comfort is King needs 20)";
			if (comfortReport.Suggestions.Count > 0)
			{
				text = text + "\nTo raise it: " + string.Join(", ", comfortReport.Suggestions.Take(Plugin.ComfortSuggestions.Value).Select(Comfort.Describe));
				if (comfortReport.Suggestions.Count > Plugin.ComfortSuggestions.Value)
				{
					text += ", ... (/comfort lists all)";
				}
			}
			((Character)__instance).Message((MessageType)1, text, 0, (Sprite)null, false);
		}
	}
	internal static class ComfortCommand
	{
		internal static void Run(ConsoleEventArgs args)
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				Say(args, "Load into a world with a character first.");
				return;
			}
			ComfortReport comfortReport = Comfort.Build(localPlayer);
			Say(args, $"Comfort here {comfortReport.Current}, best so far {comfortReport.MaxReached:0} " + "(Comfort is King needs 20).");
			if (!comfortReport.InShelter)
			{
				Say(args, "  You are not under a roof: pieces only count in a shelter.");
			}
			Say(args, $"  With the pieces you know, the most you can reach is {comfortReport.BestKnown}." + ((comfortReport.Locked > 0) ? $" Pieces you haven't unlocked yet add up to {comfortReport.Locked} more." : ""));
			if (comfortReport.Suggestions.Count == 0)
			{
				Say(args, "  Nothing you know would raise it here.");
				return;
			}
			Say(args, "  Within 10 m, add:");
			foreach (Suggestion suggestion in comfortReport.Suggestions)
			{
				Say(args, "    " + Comfort.Describe(suggestion));
			}
		}

		private static void Say(ConsoleEventArgs args, string text)
		{
			if ((Object)(object)args?.Context != (Object)null)
			{
				args.Context.AddString(text);
			}
			else
			{
				Plugin.Log.LogInfo((object)text);
			}
		}
	}
	internal static class ConfigLayout
	{
		private static readonly Dictionary<string, (string Section, Dictionary<string, string> Keys)> Sections = new Dictionary<string, (string, Dictionary<string, string>)>
		{
			{
				"1 - Camera",
				("1 - General", new Dictionary<string, string>
				{
					{ "Enabled", "Camera zoom" },
					{ "Land zoom multiplier", "Camera zoom multiplier on land" },
					{ "Ship zoom distance", "Camera zoom distance on ships" }
				})
			},
			{
				"15 - Carts and boats",
				("1 - General", new Dictionary<string, string>())
			},
			{
				"16 - Map",
				("1 - General", new Dictionary<string, string>
				{
					{ "Reveal radius", "Map reveal radius" },
					{ "Reveal radius while sailing", "Map reveal radius while sailing" },
					{ "Remove death markers button", "Map button to remove death markers" }
				})
			},
			{
				"3 - Ship and cart removal",
				("1 - General", new Dictionary<string, string> { { "Enabled", "Ship and cart removal" } })
			},
			{
				"4 - Tombstone retrieval",
				("1 - General", new Dictionary<string, string>
				{
					{ "Enabled", "Tombstone retrieval" },
					{ "Cooldown seconds", "Tombstone retrieval cooldown seconds" }
				})
			},
			{
				"24 - Sleeping",
				("1 - General", new Dictionary<string, string>
				{
					{ "Share of players needed", "Sleep share of players needed" },
					{ "Emotes count", "Sleep emotes count" },
					{ "Players in bed needed", "Sleep players in bed needed" }
				})
			},
			{
				"7 - Visual effects",
				("2 - Visual effects", new Dictionary<string, string>())
			},
			{
				"30 - Chests",
				("3 - Interface", new Dictionary<string, string>
				{
					{ "Name key", "Chest name key" },
					{ "Show contents", "Chest contents" },
					{ "Icon size", "Chest icon size" },
					{ "Most icons", "Chest most icons" }
				})
			},
			{
				"32 - Station timers",
				("3 - Interface", new Dictionary<string, string> { { "Show timers", "Station timers" } })
			},
			{
				"27 - Comfort",
				("3 - Interface", new Dictionary<string, string>
				{
					{ "Tab name", "Comfort tab name" },
					{ "Check marks in every tab", "Comfort check marks in every tab" },
					{ "Message when resting", "Comfort message when resting" },
					{ "Message cooldown", "Comfort message cooldown" },
					{ "Pieces in the message", "Comfort message pieces" }
				})
			},
			{
				"22 - Loot and items",
				("4 - Items and loot", new Dictionary<string, string>())
			},
			{
				"2 - Dropped items",
				("4 - Items and loot", new Dictionary<string, string>
				{
					{ "Enabled", "Dropped items last longer" },
					{ "Lifetime hours", "Dropped item lifetime hours" }
				})
			},
			{
				"28 - Recycling",
				("4 - Items and loot", new Dictionary<string, string>
				{
					{ "Materials returned", "Recycling materials returned" },
					{ "Count upgrades", "Recycling counts upgrades" },
					{ "Confirm hotbar items", "Recycling confirms hotbar items" }
				})
			},
			{
				"23 - Inventory rows",
				("4 - Items and loot", new Dictionary<string, string>())
			},
			{
				"19 - Spearfishing",
				("4 - Items and loot", new Dictionary<string, string>
				{
					{ "Spears", "Spearfishing with spears" },
					{ "Harpoons", "Spearfishing with harpoons" },
					{ "Bows", "Spearfishing with bows" },
					{ "Crossbows", "Spearfishing with crossbows" }
				})
			},
			{
				"18 - Trophies",
				("5 - Trophies", new Dictionary<string, string>())
			},
			{
				"5 - Skill loss on death",
				("6 - Skill loss on death", new Dictionary<string, string>())
			},
			{
				"6 - Skill XP",
				("7 - Skill XP", new Dictionary<string, string>())
			},
			{
				"12 - Smelters and kilns",
				("8 - Stations and building", new Dictionary<string, string>
				{
					{ "Ore capacity", "Smelter ore capacity" },
					{ "Fuel capacity", "Smelter fuel capacity" },
					{ "Speed", "Smelter speed" },
					{ "Fuel per product", "Smelter fuel per product" },
					{ "Output", "Smelter output" },
					{ "Excluded stations", "Smelter excluded stations" }
				})
			},
			{
				"13 - Fermenters",
				("8 - Stations and building", new Dictionary<string, string>
				{
					{ "Speed", "Fermenter speed" },
					{ "Output", "Fermenter output" }
				})
			},
			{
				"14 - Crafting stations",
				("8 - Stations and building", new Dictionary<string, string> { { "Build range", "Crafting station build range" } })
			},
			{
				"29 - Serving tray",
				("8 - Stations and building", new Dictionary<string, string> { { "Every crafted food", "Serving tray takes every crafted food" } })
			},
			{
				"26 - Wisplight",
				("8 - Stations and building", new Dictionary<string, string>
				{
					{ "Upgrade levels", "Wisplight upgrade levels" },
					{ "Clearing per level", "Wisplight clearing per level" },
					{ "Wisps per level", "Wisplight wisps per level" },
					{ "Silver per level", "Wisplight silver per level" },
					{ "Eitr per level", "Wisplight eitr per level" }
				})
			},
			{
				"31 - Doors",
				("8 - Stations and building", new Dictionary<string, string> { { "Seconds open", "Door seconds open" } })
			},
			{
				"33 - Smoke",
				("8 - Stations and building", new Dictionary<string, string> { { "Passes through", "Smoke passes through" } })
			},
			{
				"17 - Double dragon bed",
				("8 - Stations and building", new Dictionary<string, string>
				{
					{ "Enabled", "Double dragon bed" },
					{ "Blankets", "Double dragon bed blankets" }
				})
			},
			{
				"25 - Item stands",
				("8 - Stations and building", new Dictionary<string, string>
				{
					{ "Items allowed", "Item stand items allowed" },
					{ "Stands", "Item stand pieces" },
					{ "Adjustments", "Item stand adjustments" },
					{ "Largest offset", "Item stand largest offset" },
					{ "Largest size", "Item stand largest size" },
					{ "Default adjustments", "Item stand default adjustments" },
					{ "Simple models", "Item stand simple models" },
					{ "Hide stands holding an item", "Item stand hidden when holding an item" },
					{ "Items closer to the wall", "Item stand items closer to the wall" }
				})
			},
			{
				"9 - Epic Loot bounties",
				("9 - Epic Loot", new Dictionary<string, string>
				{
					{ "Complete on main target", "Bounty complete on main target" },
					{ "Spread out new bounties", "Bounties spread out" },
					{ "Spacing", "Bounty spacing" },
					{ "Extra enchanted copies", "Bounty extra enchanted copies" },
					{ "Guaranteed enchanted item", "Bounty guaranteed enchanted item" },
					{ "Normal star scaling", "Bounty normal star scaling" },
					{ "Overhead health bar", "Bounty overhead health bar" }
				})
			},
			{
				"20 - Epic Loot enchanting table",
				("9 - Epic Loot", new Dictionary<string, string>
				{
					{ "Materials from nearby chests", "Enchanting materials from nearby chests" },
					{ "Chest range", "Enchanting chest range" },
					{ "Double output per item", "Sacrifice double output per item" }
				})
			},
			{
				"21 - Epic Loot enchantments",
				("9 - Epic Loot", new Dictionary<string, string>())
			}
		};

		private static readonly Dictionary<(string, string), (string Section, string Key)> Keys = new Dictionary<(string, string), (string, string)>
		{
			{
				("10 - Bug fixes", "Game bug fixes"),
				("1 - General", "Game bug fixes")
			},
			{
				("10 - Bug fixes", "Tidy other mods config files"),
				("1 - General", "Tidy other mods config files")
			},
			{
				("10 - Bug fixes", "Epic Loot enchantment fixes"),
				("9 - Epic Loot", "Enchantment fixes")
			},
			{
				("10 - Bug fixes", "Epic Loot faster chest loading"),
				("9 - Epic Loot", "Faster chest loading")
			},
			{
				("11 - Quality of life", "Swim skill raises swim speed"),
				("1 - General", "Swim skill raises swim speed")
			},
			{
				("11 - Quality of life", "Sneak skill raises sneak speed"),
				("1 - General", "Sneak skill raises sneak speed")
			},
			{
				("11 - Quality of life", "Tamed animals spare crops"),
				("1 - General", "Tamed animals spare crops")
			},
			{
				("11 - Quality of life", "Live hammer menu"),
				("3 - Interface", "Live hammer menu")
			},
			{
				("11 - Quality of life", "Health bars with build tools"),
				("3 - Interface", "Health bars with build tools")
			},
			{
				("11 - Quality of life", "Combat health bars"),
				("3 - Interface", "Combat health bars")
			},
			{
				("11 - Quality of life", "Attacker health bar range"),
				("3 - Interface", "Attacker health bar range")
			},
			{
				("11 - Quality of life", "Taming info at range"),
				("3 - Interface", "Taming info at range")
			},
			{
				("11 - Quality of life", "Inventory Slots Visibility"),
				("3 - Interface", "Inventory slot visibility")
			},
			{
				("11 - Quality of life", "Hide status effect names"),
				("3 - Interface", "Hide status effect names")
			},
			{
				("11 - Quality of life", "No auto-equip on pickup"),
				("4 - Items and loot", "No auto-equip on pickup")
			},
			{
				("11 - Quality of life", "Auto-pickup key with Equipment & Quick Slots"),
				("4 - Items and loot", "Auto-pickup key with Equipment & Quick Slots")
			},
			{
				("11 - Quality of life", "Tombstone items back in their slots"),
				("1 - General", "Tombstone items back in their slots")
			}
		};

		private static readonly HashSet<(string, string)> Removed = new HashSet<(string, string)>
		{
			("9 - Epic Loot", "Faster chest loading"),
			("9 - Epic Loot", "Eitr cost in tooltips"),
			("9 - Epic Loot", "Bounty normal star scaling")
		};

		private static bool New(string oldSection, string oldKey, out string newSection, out string newKey)
		{
			if (Keys.TryGetValue((oldSection, oldKey), out (string, string) value))
			{
				(newSection, newKey) = value;
				return true;
			}
			if (Sections.TryGetValue(oldSection, out (string, Dictionary<string, string>) value2))
			{
				newSection = value2.Item1;
				newKey = (value2.Item2.TryGetValue(oldKey, out var value3) ? value3 : oldKey);
				return true;
			}
			newSection = (newKey = null);
			return false;
		}

		internal static Dictionary<string, string> WithAliases(Dictionary<string, string> before)
		{
			Dictionary<string, string> dictionary = new Dictionary<string, string>(before);
			foreach (KeyValuePair<string, string> item in before)
			{
				int num = item.Key.IndexOf('|');
				if (num >= 0)
				{
					string oldSection = item.Key.Substring(0, num);
					string oldKey = item.Key.Substring(num + 1);
					if (New(oldSection, oldKey, out var newSection, out var newKey) && !dictionary.ContainsKey(newSection + "|" + newKey))
					{
						dictionary[newSection + "|" + newKey] = item.Value;
					}
				}
			}
			return dictionary;
		}

		internal static void Apply(ConfigFile config, Dictionary<string, string> before)
		{
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Expected O, but got Unknown
			try
			{
				Dictionary<ConfigDefinition, string> dictionary = AccessTools.Property(typeof(ConfigFile), "OrphanedEntries")?.GetValue(config) as Dictionary<ConfigDefinition, string>;
				int num = 0;
				foreach (KeyValuePair<string, string> item in before)
				{
					int num2 = item.Key.IndexOf('|');
					if (num2 < 0)
					{
						continue;
					}
					string oldSection = item.Key.Substring(0, num2);
					string oldKey = item.Key.Substring(num2 + 1);
					if (New(oldSection, oldKey, out var newSection, out var newKey) && !before.ContainsKey(newSection + "|" + newKey))
					{
						ConfigDefinition val = new ConfigDefinition(newSection, newKey);
						if (config.ContainsKey(val))
						{
							ConfigText.SetValue(config[val], item.Value);
							num++;
						}
					}
				}
				int num3 = 0;
				if (dictionary != null)
				{
					foreach (ConfigDefinition item2 in dictionary.Keys.ToList())
					{
						if (Sections.ContainsKey(item2.Section) || Keys.ContainsKey((item2.Section, item2.Key)) || item2.Section == "11 - Quality of life" || Removed.Contains((item2.Section, item2.Key)))
						{
							dictionary.Remove(item2);
							num3++;
						}
					}
				}
				if (num > 0 || num3 > 0)
				{
					config.Save();
					Plugin.Log.LogInfo((object)$"Settings: {num} values carried over to their new places, {num3} old lines tidied away.");
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Couldn't carry the old settings over to the new layout: " + ex.Message));
			}
		}
	}
	internal static class ConfigText
	{
		internal static Dictionary<string, string> Read(string path)
		{
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			try
			{
				if (!File.Exists(path))
				{
					return dictionary;
				}
				string text = "";
				string[] array = File.ReadAllLines(path);
				for (int i = 0; i < array.Length; i++)
				{
					string text2 = array[i].Trim();
					if (text2.Length == 0 || text2.StartsWith("#"))
					{
						continue;
					}
					if (text2.StartsWith("[") && text2.EndsWith("]"))
					{
						text = text2.Substring(1, text2.Length - 2);
						continue;
					}
					int num = text2.IndexOf('=');
					if (num > 0)
					{
						dictionary[text + "|" + text2.Substring(0, num).Trim()] = text2.Substring(num + 1).Trim();
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Couldn't read " + Path.GetFileName(path) + ": " + ex.Message));
			}
			return dictionary;
		}

		internal static void SetValue(ConfigEntryBase entry, string value)
		{
			Set(entry, value);
		}

		private static void Set(ConfigEntryBase entry, string value)
		{
			try
			{
				entry.BoxedValue = TomlTypeConverter.ConvertToValue(value, entry.SettingType);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Couldn't copy '" + value + "' into " + entry.Definition.Key + ": " + ex.Message));
			}
		}

		internal static void CarryOver(ConfigFile config, Dictionary<string, string> before, string oldSection, string oldKey, ConfigEntryBase entry)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			string key = entry.Definition.Section + "|" + entry.Definition.Key;
			if (!before.ContainsKey(key) && before.TryGetValue(oldSection + "|" + oldKey, out var value))
			{
				Set(entry, value);
				if (AccessTools.Property(typeof(ConfigFile), "OrphanedEntries")?.GetValue(config) is Dictionary<ConfigDefinition, string> dictionary)
				{
					dictionary.Remove(new ConfigDefinition(oldSection, oldKey));
				}
				config.Save();
			}
		}

		internal static void DropMoved(ConfigFile config, string otherFile, string otherSection, string oldSection, string oldKey)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			try
			{
				string path = Path.Combine(Paths.ConfigPath, otherFile);
				if (File.Exists(path) && File.ReadAllText(path).Contains(otherSection) && AccessTools.Property(typeof(ConfigFile), "OrphanedEntries")?.GetValue(config) is Dictionary<ConfigDefinition, string> dictionary && dictionary.Remove(new ConfigDefinition(oldSection, oldKey)))
				{
					config.Save();
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Couldn't tidy the moved setting " + oldSection + " / " + oldKey + ": " + ex.Message));
			}
		}

		internal static void CopyBool(ConfigFile config, string otherFile, string section, string key, ConfigEntry<bool> entry)
		{
			if (Read(Path.Combine(Paths.ConfigPath, otherFile)).TryGetValue(section + "|" + key, out var value))
			{
				Set((ConfigEntryBase)(object)entry, value);
			}
		}

		private static void Copy(Dictionary<string, string> other, string section, string key, ConfigEntryBase entry)
		{
			if (other.TryGetValue(section + "|" + key, out var value))
			{
				Set(entry, value);
			}
		}

		internal static void ImportDimmer(ConfigFile config)
		{
			Dictionary<string, string> dictionary = Read(Path.Combine(Paths.ConfigPath, "wheeze.valheim.dimmercombatparticleeffects.cfg"));
			if (dictionary.Count != 0)
			{
				Copy(dictionary, "1 - General", "Enabled", (ConfigEntryBase)(object)Plugin.DimEnabled);
				Copy(dictionary, "2 - Strength", "Opacity", (ConfigEntryBase)(object)Plugin.DimOpacity);
				Copy(dictionary, "2 - Strength", "Brightness", (ConfigEntryBase)(object)Plugin.DimBrightness);
				Copy(dictionary, "2 - Strength", "Size", (ConfigEntryBase)(object)Plugin.DimSize);
				Copy(dictionary, "3 - Sources", "Character hit effects", (ConfigEntryBase)(object)Plugin.DimCreatureHits);
				Copy(dictionary, "3 - Sources", "Weapon hit effects", (ConfigEntryBase)(object)Plugin.DimWeapons);
				Copy(dictionary, "3 - Sources", "Projectile hit effects", (ConfigEntryBase)(object)Plugin.DimImpacts);
				Copy(dictionary, "3 - Sources", "Status effect visuals on creatures", (ConfigEntryBase)(object)Plugin.DimStatus);
				Copy(dictionary, "3 - Sources", "Include hits on players", (ConfigEntryBase)(object)Plugin.DimOnPlayers);
				Plugin.Log.LogInfo((object)"Copied the combat effects dimmer settings from Dimmer Combat Particle Effects.");
			}
		}

		internal static void ImportSpearfishing(ConfigFile config)
		{
			Dictionary<string, string> dictionary = Read(Path.Combine(Paths.ConfigPath, "org.bepinex.plugins.spearfishing.cfg"));
			if (dictionary.Count != 0)
			{
				Copy(dictionary, "General", "EnableSpears", (ConfigEntryBase)(object)Plugin.FishSpears);
				Copy(dictionary, "General", "EnableHarpoons", (ConfigEntryBase)(object)Plugin.FishHarpoons);
				Copy(dictionary, "General", "EnableBows", (ConfigEntryBase)(object)Plugin.FishBows);
				Copy(dictionary, "General", "EnableCrossbows", (ConfigEntryBase)(object)Plugin.FishCrossbows);
				Plugin.Log.LogInfo((object)"Copied the spearfishing settings from Spearfishing.");
			}
		}

		internal static void ImportDropMoreLoot(ConfigFile config)
		{
			Dictionary<string, string> other = Read(Path.Combine(Paths.ConfigPath, "TastyChickenLegs.DropMoreLoot.cfg"));
			if (other.Count == 0)
			{
				return;
			}
			if (!Is("Pickup|Disable Loot Settings", fallback: false))
			{
				Copy(other, "Loot", "Multiplier for monster drops", (ConfigEntryBase)(object)Plugin.LootCreatures);
				Copy(other, "Loot", "Multiplier for resources", (ConfigEntryBase)(object)Plugin.LootResources);
				Copy(other, "Loot", "Multiplier for pickable objects", (ConfigEntryBase)(object)Plugin.LootPickables);
				Plugin.LootTrophies.Value = true;
				if (Is("Whitelist|Enable whitelist filter", fallback: false))
				{
					Copy(other, "Whitelist", "White List Itmes", (ConfigEntryBase)(object)Plugin.LootOnly);
				}
			}
			if (Is("Loot|useWeightReduction", fallback: true))
			{
				Copy(other, "Loot", "percentofweight", (ConfigEntryBase)(object)Plugin.ItemWeight);
			}
			if (Is("Stacking|Enable Stacking", fallback: true))
			{
				Copy(other, "Stacking", "Item Stack Multiplier", (ConfigEntryBase)(object)Plugin.ItemStackSize);
			}
			if (Is("Pickup|Enable Pickup Range", fallback: true))
			{
				Copy(other, "Pickup", "Pickup Range", (ConfigEntryBase)(object)Plugin.PickupRangeSetting);
			}
			Copy(other, "Pickup", "Items Float in Water", (ConfigEntryBase)(object)Plugin.ItemsFloat);
			Plugin.Log.LogInfo((object)"Copied the loot and item settings from DropMoreLoot.");
			bool Is(string key, bool fallback)
			{
				if (!other.TryGetValue(key, out var value))
				{
					return fallback;
				}
				return string.Equals(value, "true", StringComparison.OrdinalIgnoreCase);
			}
		}

		internal static void ImportEpicLootAddons(ConfigFile config)
		{
			Dictionary<string, string> other = Read(Path.Combine(Paths.ConfigPath, "digi.valheim.epiclootaddons.cfg"));
			if (other.Count != 0)
			{
				Copy(other, "Epic Loot Storage Materials - General", "Enabled", (ConfigEntryBase)(object)Plugin.ChestMaterialsEnabled);
				Copy(other, "Epic Loot Storage Materials - General", "Range (m)", (ConfigEntryBase)(object)Plugin.ChestMaterialsRange);
				Copy(other, "Epic Loot Storage Materials - General", "Chest trophies in Sacrifice", (ConfigEntryBase)(object)Plugin.ChestTrophies);
				Copy(other, "Epic Loot Storage Materials - General", "Chest shardstones in Sacrifice", (ConfigEntryBase)(object)Plugin.ChestShardstones);
				Copy(other, "Epic Loot Storage Materials - Sacrifice", "Roll double output per item", (ConfigEntryBase)(object)Plugin.SacrificePerItem);
				if (!On("Epic Loot Storage Materials"))
				{
					ConfigEntry<bool> chestMaterialsEnabled = Plugin.ChestMaterialsEnabled;
					bool value = (Plugin.SacrificePerItem.Value = false);
					chestMaterialsEnabled.Value = value;
				}
				Copy(other, "Epic Loot Fixes - Damage stacking", "Damage effects stack", (ConfigEntryBase)(object)Plugin.DamageStacking);
				Copy(other, "Epic Loot Fixes - Double and Triple Shot", "Normal cost", (ConfigEntryBase)(object)Plugin.ShotNormalCost);
				Copy(other, "Epic Loot Fixes - Double and Triple Shot", "Double Magic Shot doubles the summon limit", (ConfigEntryBase)(object)Plugin.ShotSummonLimit);
				Copy(other, "Epic Loot Fixes - Lucky Loot", "Show Lucky Loot message", (ConfigEntryBase)(object)Plugin.LuckyLootMessage);
				Copy(other, "Epic Loot Fixes - Lucky Loot", "Message position", (ConfigEntryBase)(object)Plugin.LuckyLootPosition);
				Copy(other, "Epic Loot Fixes - Lucky Loot", "Lucky Loot on birds", (ConfigEntryBase)(object)Plugin.LuckyLootBirds);
				if (!On("Epic Loot Fixes"))
				{
					ConfigEntry<bool> damageStacking = Plugin.DamageStacking;
					ConfigEntry<bool> shotNormalCost = Plugin.ShotNormalCost;
					ConfigEntry<bool> shotSummonLimit = Plugin.ShotSummonLimit;
					ConfigEntry<bool> luckyLootMessage = Plugin.LuckyLootMessage;
					bool flag2 = (Plugin.LuckyLootBirds.Value = false);
					bool flag4 = (luckyLootMessage.Value = flag2);
					bool flag6 = (shotSummonLimit.Value = flag4);
					bool value = (shotNormalCost.Value = flag6);
					damageStacking.Value = value;
				}
				if (On("Enchant Glow Toggle"))
				{
					Copy(other, "Enchant Glow Toggle - Always", "Hide Glowing aura", (ConfigEntryBase)(object)Plugin.HideGlowing);
					Copy(other, "Enchant Glow Toggle - Always", "Hide all enchantment effects", (ConfigEntryBase)(object)Plugin.HideEnchantEffects);
					Copy(other, "Enchant Glow Toggle - Always", "Hide legendary textures", (ConfigEntryBase)(object)Plugin.HideLegendaryLooks);
				}
				Copy(other, "Shard Exclusivity - General", "Ignore effect exclusions for shards", (ConfigEntryBase)(object)Plugin.ShardsIgnoreClashes);
				if (!On("Shard Exclusivity"))
				{
					Plugin.ShardsIgnoreClashes.Value = false;
				}
				Plugin.Log.LogInfo((object)"Copied the settings from Epic Loot Add-ons.");
			}
			bool On(string part)
			{
				if (other.TryGetValue("0 - Sub-mods|" + part, out var value2))
				{
					return !string.Equals(value2, "false", StringComparison.OrdinalIgnoreCase);
				}
				return true;
			}
		}

		internal static void ImportTrophyAssister(ConfigFile config)
		{
			Dictionary<string, string> dictionary = Read(Path.Combine(Paths.ConfigPath, "com.koendertjh.trophyassister.cfg"));
			if (dictionary.Count != 0)
			{
				Copy(dictionary, "3 - Pity", "Enabled", (ConfigEntryBase)(object)Plugin.TrophyPity);
				if (dictionary.TryGetValue("3 - Pity|Mode", out var value))
				{
					Plugin.TrophyFlatMode.Value = string.Equals(value, "Flat", StringComparison.OrdinalIgnoreCase);
				}
				Copy(dictionary, "3 - Pity", "GrowthPerKill", (ConfigEntryBase)(object)Plugin.TrophyGrowth);
				Copy(dictionary, "3 - Pity", "RareThreshold", (ConfigEntryBase)(object)Plugin.TrophyRareThreshold);
				Copy(dictionary, "3 - Pity", "RareGrowthPerKill", (ConfigEntryBase)(object)Plugin.TrophyRareGrowth);
				Copy(dictionary, "3 - Pity", "FlatBonusPerKill", (ConfigEntryBase)(object)Plugin.TrophyFlatBonus);
				Copy(dictionary, "3 - Pity", "GuaranteeAfterKills", (ConfigEntryBase)(object)Plugin.TrophyGuarantee);
				Copy(dictionary, "3 - Pity", "OnlyCountMyKills", (ConfigEntryBase)(object)Plugin.TrophyOnlyMine);
				Copy(dictionary, "3 - Pity", "ExtraKillsPerStar", (ConfigEntryBase)(object)Plugin.TrophyExtraKillsPerStar);
				if (dictionary.TryGetValue("3 - Pity|StarKillBonus", out var value2) && string.Equals(value2, "false", StringComparison.OrdinalIgnoreCase))
				{
					Plugin.TrophyExtraKillsPerStar.Value = 0;
				}
				Copy(dictionary, "2 - Base boost", "ChanceMultiplier", (ConfigEntryBase)(object)Plugin.TrophyChanceMultiplier);
				Copy(dictionary, "2 - Base boost", "OnlyUncollected", (ConfigEntryBase)(object)Plugin.TrophyOnlyUncollected);
				Copy(dictionary, "4 - Trophy list", "ShowChances", (ConfigEntryBase)(object)Plugin.TrophyShowChances);
				Copy(dictionary, "4 - Trophy list", "ShowMissing", (ConfigEntryBase)(object)Plugin.TrophyShowMissing);
				Copy(dictionary, "4 - Trophy list", "SpoilerFree", (ConfigEntryBase)(object)Plugin.TrophySpoilerFree);
				Copy(dictionary, "4 - Trophy list", "HiddenTrophies", (ConfigEntryBase)(object)Plugin.TrophyHidden);
				Copy(dictionary, "1 - General", "NotifyOnDrop", (ConfigEntryBase)(object)Plugin.TrophyNotify);
				Copy(dictionary, "1 - General", "ShowPityProgress", (ConfigEntryBase)(object)Plugin.TrophyShowProgress);
				Plugin.Log.LogInfo((object)"Copied the trophy settings from TrophyAssister.");
			}
		}
	}
	internal static class ConfigTidy
	{
		internal static void Run()
		{
			Try("LetMeTameYou tame list", TameListTabs);
		}

		private static void Try(string what, Action fix)
		{
			try
			{
				fix();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Config tidy (" + what + ") skipped: " + ex.GetBaseException().Message));
			}
		}

		private static void TameListTabs()
		{
			string path = Path.Combine(Paths.ConfigPath, "LetMeTameYou_DefaultTameList.yml");
			if (!File.Exists(path))
			{
				return;
			}
			string text = File.ReadAllText(path);
			if (text.IndexOf('\t') < 0)
			{
				return;
			}
			string[] array = text.Split('\n');
			int num = 0;
			for (int i = 0; i < array.Length; i++)
			{
				if (array[i].IndexOf('\t') >= 0 && array[i].TrimStart(' ', '\t').StartsWith("#"))
				{
					array[i] = array[i].Replace("\t", "  ");
					num++;
				}
			}
			if (num != 0)
			{
				File.WriteAllText(path, string.Join("\n", array));
				Plugin.Log.LogInfo((object)$"Config tidy: replaced tabs with spaces in {num} comment lines of LetMeTameYou_DefaultTameList.yml, so LetMeTameYou stops warning about them.");
			}
		}
	}
	[HarmonyPatch(typeof(Minimap), "Update")]
	internal static class DeathMarkers
	{
		private const float CheckInterval = 0.25f;

		private const float ConfirmTime = 3f;

		private const float Gap = 6f;

		private static readonly FieldRef<Minimap, List<PinData>> Pins = AccessTools.FieldRefAccess<Minimap, List<PinData>>("m_pins");

		private static readonly List<PinData> Removing = new List<PinData>();

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

		private static Button button;

		private static TMP_Text label;

		private static float nextCheck;

		private static float confirmUntil;

		private static int shown = -1;

		private static void Postfix(Minimap __instance)
		{
			if (!Object.op_Implicit((Object)(object)__instance.m_largeRoot) || !__instance.m_largeRoot.activeInHierarchy)
			{
				confirmUntil = 0f;
			}
			else
			{
				if (Time.unscaledTime < nextCheck)
				{
					return;
				}
				nextCheck = Time.unscaledTime + 0.25f;
				int num = (Plugin.DeathMarkerButton.Value ? Count(__instance) : 0);
				if (num == 0)
				{
					if (Object.op_Implicit((Object)(object)button))
					{
						((Component)button).gameObject.SetActive(false);
					}
				}
				else if (Object.op_Implicit((Object)(object)button) || Create(__instance))
				{
					((Component)button).gameObject.SetActive(true);
					Place(__instance);
					bool flag = Time.unscaledTime < confirmUntil;
					int num2 = (flag ? (-num) : num);
					if (num2 != shown)
					{
						shown = num2;
						label.text = (flag ? $"Click again: remove {num}" : $"Remove death markers ({num})");
					}
				}
			}
		}

		private static int Count(Minimap map)
		{
			List<PinData> list = Pins.Invoke(map);
			int num = 0;
			if (list != null)
			{
				foreach (PinData item in list)
				{
					if (IsDeathMarker(item))
					{
						num++;
					}
				}
			}
			return num;
		}

		private static bool IsDeathMarker(PinData pin)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Invalid comparison between Unknown and I4
			if (pin != null && (int)pin.m_type == 4)
			{
				return pin.m_save;
			}
			return false;
		}

		private static bool Create(Minimap map)
		{
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Expected O, but got Unknown
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Expected O, but got Unknown
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Expected O, but got Unknown
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			Button val = (Object.op_Implicit((Object)(object)InventoryGui.instance) ? InventoryGui.instance.m_takeAllButton : null);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return false;
			}
			GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, map.m_largeRoot.transform, false);
			((Object)val2).name = "PotatoTweaks_RemoveDeathMarkers";
			UIGamePad[] componentsInChildren = val2.GetComponentsInChildren<UIGamePad>(true);
			foreach (UIGamePad val3 in componentsInChildren)
			{
				if (Object.op_Implicit((Object)(object)val3.m_hint))
				{
					Object.Destroy((Object)(object)val3.m_hint);
				}
				Object.Destroy((Object)(object)val3);
			}
			Localize[] componentsInChildren2 = val2.GetComponentsInChildren<Localize>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				Object.Destroy((Object)(object)componentsInChildren2[i]);
			}
			UITooltip[] componentsInChildren3 = val2.GetComponentsInChildren<UITooltip>(true);
			for (int i = 0; i < componentsInChildren3.Length; i++)
			{
				Object.Destroy((Object)(object)componentsInChildren3[i]);
			}
			(val2.GetComponent<LayoutElement>() ?? val2.AddComponent<LayoutElement>()).ignoreLayout = true;
			button = val2.GetComponent<Button>();
			label = val2.GetComponentInChildren<TMP_Text>(true);
			if (!Object.op_Implicit((Object)(object)button) || !Object.op_Implicit((Object)(object)label))
			{
				Object.Destroy((Object)(object)val2);
				button = null;
				return false;
			}
			button.onClick = new ButtonClickedEvent();
			((UnityEvent)button.onClick).AddListener(new UnityAction(Clicked));
			label.textWrappingMode = (TextWrappingModes)0;
			RectTransform val4 = (RectTransform)val2.transform;
			Vector2 val5 = default(Vector2);
			((Vector2)(ref val5))..ctor(0.5f, 0.5f);
			val4.pivot = val5;
			Vector2 anchorMin = (val4.anchorMax = val5);
			val4.anchorMin = anchorMin;
			val4.sizeDelta = new Vector2(Mathf.Max(val4.sizeDelta.x, 240f), val4.sizeDelta.y);
			shown = -1;
			return true;
		}

		private static void Place(Minimap map)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: 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_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: 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_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: 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_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = (RectTransform)map.m_largeRoot.transform;
			RectTransform val2 = (RectTransform)((Component)button).transform;
			RectTransform val3 = (Object.op_Implicit((Object)(object)map.m_selectedIconDeath) ? ((Graphic)map.m_selectedIconDeath).rectTransform : null);
			object obj;
			if (!Object.op_Implicit((Object)(object)val3))
			{
				obj = null;
			}
			else
			{
				Button componentInParent = ((Component)val3).GetComponentInParent<Button>();
				Transform obj2 = ((componentInParent != null) ? ((Component)componentInParent).transform : null);
				obj = ((object)((obj2 is RectTransform) ? obj2 : null)) ?? ((object)val3);
			}
			RectTransform val4 = (RectTransform)obj;
			Rect rect = val.rect;
			Rect rect2 = val2.rect;
			Vector2 size = ((Rect)(ref rect2)).size;
			Vector2 val8 = default(Vector2);
			if (Object.op_Implicit((Object)(object)val4))
			{
				val4.GetWorldCorners(Corners);
				float num = (((Transform)val).InverseTransformPoint(Corners[0]).y + ((Transform)val).InverseTransformPoint(Corners[2]).y) * 0.5f;
				Transform parent = ((Transform)val4).parent;
				RectTransform val5 = (RectTransform)(object)((parent is RectTransform) ? parent : null);
				if (val5 != null && (Object)(object)val5 != (Object)(object)val)
				{
					rect2 = val5.rect;
					if (((Rect)(ref rect2)).width < ((Rect)(ref rect)).width / 3f)
					{
						val5.GetWorldCorners(Corners);
					}
				}
				Vector3 val6 = ((Transform)val).InverseTransformPoint(Corners[0]);
				Vector3 val7 = ((Transform)val).InverseTransformPoint(Corners[2]);
				val8 = (((val6.x + val7.x) * 0.5f > ((Rect)(ref rect)).center.x) ? new Vector2(val6.x - 6f - size.x * 0.5f, num) : new Vector2(val7.x + 6f + size.x * 0.5f, num));
			}
			else
			{
				((Vector2)(ref val8))..ctor(((Rect)(ref rect)).center.x, ((Rect)(ref rect)).yMin + 6f + size.y * 0.5f);
			}
			val8.x = Mathf.Clamp(val8.x, ((Rect)(ref rect)).xMin + size.x * 0.5f, ((Rect)(ref rect)).xMax - size.x * 0.5f);
			val8.y = Mathf.Clamp(val8.y, ((Rect)(ref rect)).yMin + size.y * 0.5f, ((Rect)(ref rect)).yMax - size.y * 0.5f);
			((Transform)val2).localPosition = new Vector3(val8.x, val8.y, 0f);
		}

		private static void Clicked()
		{
			Minimap instance = Minimap.instance;
			if (!Object.op_Implicit((Object)(object)instance))
			{
				return;
			}
			if (Time.unscaledTime >= confirmUntil)
			{
				confirmUntil = Time.unscaledTime + 3f;
				nextCheck = 0f;
				return;
			}
			confirmUntil = 0f;
			nextCheck = 0f;
			Removing.Clear();
			List<PinData> list = Pins.Invoke(instance);
			if (list != null)
			{
				foreach (PinData item in list)
				{
					if (IsDeathMarker(item))
					{
						Removing.Add(item);
					}
				}
			}
			foreach (PinData item2 in Removing)
			{
				instance.RemovePin(item2);
			}
			if (Removing.Count > 0)
			{
				MessageHud instance2 = MessageHud.instance;
				if (instance2 != null)
				{
					instance2.ShowMessage((MessageType)1, (Removing.Count == 1) ? "Removed 1 death marker" : $"Removed {Removing.Count} death markers", 0, (Sprite)null, false, true);
				}
			}
			Removing.Clear();
		}
	}
	internal static class EpicLootAddons
	{
		internal const string OriginalModId = "digi.valheim.epiclootaddons";

		in