Decompiled source of AdminHammer v1.1.0

plugins/AdminHammer.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using Splatform;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Jatify
{
	internal static class JatifyLook
	{
		private const string Guid = "jatify.ui";

		private static Type _look;

		private static Assembly _from;

		private static readonly Dictionary<string, string> Plain = new Dictionary<string, string>
		{
			["glass"] = "#141416EB",
			["glassLine"] = "#FFFFFF26",
			["line2"] = "#FFFFFF29",
			["raised"] = "#2A2B30F2",
			["raised2"] = "#2C2C32E6",
			["text"] = "#ECEEED",
			["dim"] = "#B4B4BA",
			["mute"] = "#80808A",
			["accent"] = "#22D67E",
			["accentSoft"] = "#22D67E24",
			["ember"] = "#F2703A",
			["emberSoft"] = "#F2703A29",
			["health"] = "#E5484D",
			["stamina"] = "#F5B942",
			["eitr"] = "#5AA9FF"
		};

		private static TMP_FontAsset _valheim;

		internal static bool On => Look() != null;

		private static Type Look()
		{
			if (!Chainloader.PluginInfos.TryGetValue("jatify.ui", out var value) || (Object)(object)value.Instance == (Object)null)
			{
				return null;
			}
			Assembly assembly = ((object)value.Instance).GetType().Assembly;
			if (assembly != _from)
			{
				_from = assembly;
				_look = assembly.GetType("Jatify.UI.Look");
			}
			return _look;
		}

		private static object Call(string method, object arg)
		{
			Type type = Look();
			if (type == null)
			{
				return null;
			}
			try
			{
				return type.GetMethod(method)?.Invoke(null, new object[1] { arg });
			}
			catch
			{
				return null;
			}
		}

		internal static Color C(string token)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			if (Call("Color", token) is Color val && val.a > 0f)
			{
				return val;
			}
			Color result = default(Color);
			if (!Plain.TryGetValue(token, out var value) || !ColorUtility.TryParseHtmlString(value, ref result))
			{
				return Color.white;
			}
			return result;
		}

		internal static Color Color(string token, Color fallback)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			if (!(Call("Color", token) is Color val) || !(val.a > 0f))
			{
				return fallback;
			}
			return val;
		}

		internal static TMP_FontAsset Font(string kind)
		{
			object obj = Call("Font", kind);
			return (TMP_FontAsset)(((obj is TMP_FontAsset) ? obj : null) ?? ((kind == "title") ? Game("Valheim-Norsebold") : ((kind == "lore") ? Game("Valheim-AveriaSerifLibre") : null)) ?? Valheim());
		}

		private static TMP_FontAsset Game(string name)
		{
			TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
			foreach (TMP_FontAsset val in array)
			{
				if (((Object)val).name == name)
				{
					return val;
				}
			}
			return null;
		}

		internal static TMP_FontAsset Font(string kind, TMP_FontAsset fallback)
		{
			object obj = Call("Font", kind);
			return (TMP_FontAsset)(((obj is TMP_FontAsset) ? obj : null) ?? fallback);
		}

		private static TMP_FontAsset Valheim()
		{
			if ((Object)(object)_valheim != (Object)null)
			{
				return _valheim;
			}
			TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
			foreach (TMP_FontAsset val in array)
			{
				if (((Object)val).name.StartsWith("Valheim-AveriaSansLibre"))
				{
					return _valheim = val;
				}
			}
			return _valheim = TMP_Settings.defaultFontAsset;
		}

		internal static Sprite Rounded(int radius)
		{
			object obj = Call("Rounded", radius);
			return (Sprite)((obj is Sprite) ? obj : null);
		}

		internal static Sprite Ring(int radius)
		{
			object obj = Call("Ring", radius);
			return (Sprite)((obj is Sprite) ? obj : null);
		}

		internal static Sprite Icon(string name)
		{
			object obj = Call("Icon", name);
			return (Sprite)((obj is Sprite) ? obj : null);
		}

		internal static RectTransform Node(Transform parent, string name)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			if ((Object)(object)parent != (Object)null)
			{
				val.transform.SetParent(parent, false);
			}
			return (RectTransform)val.transform;
		}

		internal static RectTransform Place(RectTransform r, float x, float y, float w, float h)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 1f);
			r.pivot = val;
			Vector2 anchorMin = (r.anchorMax = val);
			r.anchorMin = anchorMin;
			r.anchoredPosition = new Vector2(x, 0f - y);
			r.sizeDelta = new Vector2(w, h);
			return r;
		}

		internal static RectTransform Fill(RectTransform r, float inset = 0f)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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)
			r.anchorMin = Vector2.zero;
			r.anchorMax = Vector2.one;
			r.pivot = new Vector2(0.5f, 0.5f);
			r.offsetMin = new Vector2(inset, inset);
			r.offsetMax = new Vector2(0f - inset, 0f - inset);
			return r;
		}

		internal static Image Img(Transform parent, Sprite s, Color c, string name = "Image")
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			Image obj = ((Component)Node(parent, name)).gameObject.AddComponent<Image>();
			obj.sprite = s;
			((Graphic)obj).color = c;
			((Graphic)obj).raycastTarget = false;
			return obj;
		}

		internal static Image Box(Transform parent, string name, Color fill, Color line, int radius)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = Node(parent, name);
			Sprite val2 = Ring(radius);
			Image obj = ((Component)val).gameObject.AddComponent<Image>();
			obj.sprite = Rounded(radius);
			obj.type = (Type)1;
			((Graphic)obj).color = fill;
			((Graphic)obj).raycastTarget = true;
			if ((Object)(object)val2 != (Object)null)
			{
				Image obj2 = Img((Transform)(object)val, val2, line, "Line");
				obj2.type = (Type)1;
				Fill(((Graphic)obj2).rectTransform);
			}
			return obj;
		}

		internal static TextMeshProUGUI Text(Transform parent, string s, string font, float size, Color c, TextAlignmentOptions align = (TextAlignmentOptions)4097)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI obj = ((Component)Node(parent, "Text")).gameObject.AddComponent<TextMeshProUGUI>();
			((TMP_Text)obj).font = Font(font);
			((TMP_Text)obj).fontSize = size;
			((Graphic)obj).color = c;
			((TMP_Text)obj).text = s;
			((TMP_Text)obj).alignment = align;
			((Graphic)obj).raycastTarget = false;
			((TMP_Text)obj).textWrappingMode = (TextWrappingModes)0;
			((TMP_Text)obj).overflowMode = (TextOverflowModes)1;
			((TMP_Text)obj).richText = true;
			return obj;
		}

		internal static float Width(TMP_Text t)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			return t.GetPreferredValues(t.text).x;
		}

		internal static Button Click(Graphic target, Action on)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			Button obj = ((Component)target).gameObject.AddComponent<Button>();
			((Selectable)obj).targetGraphic = target;
			ColorBlock colors = ((Selectable)obj).colors;
			((ColorBlock)(ref colors)).highlightedColor = new Color(1.2f, 1.2f, 1.2f);
			((ColorBlock)(ref colors)).pressedColor = new Color(0.85f, 0.85f, 0.85f);
			((ColorBlock)(ref colors)).selectedColor = Color.white;
			((Selectable)obj).colors = colors;
			((UnityEvent)obj.onClick).AddListener((UnityAction)delegate
			{
				on();
			});
			return obj;
		}

		internal static RectTransform Scroll(Transform parent, string name, float x, float y, float w, float h)
		{
			//IL_003d: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			RectTransform obj = Place(Node(parent, name), x, y, w, h);
			((Component)obj).gameObject.AddComponent<RectMask2D>();
			((Graphic)((Component)obj).gameObject.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0f);
			RectTransform val = Node((Transform)(object)obj, "Content");
			val.anchorMin = new Vector2(0f, 1f);
			val.anchorMax = Vector2.one;
			val.pivot = new Vector2(0.5f, 1f);
			val.anchoredPosition = Vector2.zero;
			val.sizeDelta = Vector2.zero;
			ScrollRect obj2 = ((Component)obj).gameObject.AddComponent<ScrollRect>();
			obj2.content = val;
			obj2.horizontal = false;
			obj2.movementType = (MovementType)2;
			obj2.scrollSensitivity = 1500f;
			obj2.inertia = false;
			return val;
		}

		internal static TMP_InputField Field(Transform parent, string placeholder, float x, float y, float w, Action<string> changed)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: 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)
			Image val = Box(parent, "Field", C("raised"), C("line2"), 8);
			Place(((Graphic)val).rectTransform, x, y, w, 34f);
			Sprite val2 = Icon("search");
			float num = 12f;
			if ((Object)(object)val2 != (Object)null)
			{
				Place(((Graphic)Img(((Component)val).transform, val2, C("mute"), "Search")).rectTransform, 10f, 8.5f, 17f, 17f);
				num = 34f;
			}
			RectTransform val3 = Node(((Component)val).transform, "Area");
			Fill(val3);
			val3.offsetMin = new Vector2(num, 4f);
			val3.offsetMax = new Vector2(-10f, -4f);
			((Component)val3).gameObject.AddComponent<RectMask2D>();
			TextMeshProUGUI val4 = Text((Transform)(object)val3, "", "medium", 14f, Color.white, (TextAlignmentOptions)4097);
			Fill(((TMP_Text)val4).rectTransform);
			TextMeshProUGUI val5 = Text((Transform)(object)val3, placeholder, "medium", 14f, C("mute"), (TextAlignmentOptions)4097);
			Fill(((TMP_Text)val5).rectTransform);
			TMP_InputField obj = ((Component)val).gameObject.AddComponent<TMP_InputField>();
			obj.textViewport = val3;
			obj.textComponent = (TMP_Text)(object)val4;
			obj.placeholder = (Graphic)(object)val5;
			obj.fontAsset = ((TMP_Text)val4).font;
			obj.pointSize = 14f;
			obj.customCaretColor = true;
			obj.caretColor = Color.white;
			obj.caretWidth = 2;
			((Behaviour)obj).enabled = false;
			((Behaviour)obj).enabled = true;
			((UnityEvent<string>)(object)obj.onValueChanged).AddListener((UnityAction<string>)delegate(string s)
			{
				changed(s ?? "");
			});
			return obj;
		}

		internal static void Bar(Transform parent, float x, float y, float w, float h, float k, Color fill)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			Image val = Box(parent, "Bar", new Color(1f, 1f, 1f, 0.08f), new Color(0f, 0f, 0f, 0f), (int)Mathf.Max(2f, h / 2f));
			((Graphic)val).raycastTarget = false;
			Place(((Graphic)val).rectTransform, x, y, w, h);
			if (!(k <= 0f))
			{
				Image obj = Box(((Component)val).transform, "Fill", fill, new Color(0f, 0f, 0f, 0f), (int)Mathf.Max(2f, h / 2f));
				((Graphic)obj).raycastTarget = false;
				RectTransform rectTransform = ((Graphic)obj).rectTransform;
				rectTransform.anchorMin = Vector2.zero;
				rectTransform.anchorMax = new Vector2(Mathf.Clamp01(k), 1f);
				Vector2 offsetMin = (rectTransform.offsetMax = Vector2.zero);
				rectTransform.offsetMin = offsetMin;
			}
		}

		internal static void Clear(Transform t)
		{
			for (int num = t.childCount - 1; num >= 0; num--)
			{
				Object.Destroy((Object)(object)((Component)t.GetChild(num)).gameObject);
			}
		}
	}
}
namespace Jatify.AdminHammer
{
	public static class AdminHammerApi
	{
		public sealed class Tab
		{
			public string Name;

			public string Icon;

			public string Title;

			public bool Targets;

			public Action<RectTransform> Build;

			public Action Show;

			public Action Tick;

			public Action<RectTransform> Footer;
		}

		internal static readonly List<Tab> Tabs = new List<Tab>();

		public static Action TargetChanged;

		public static string Target => Plugin.CurrentPanel?.Target ?? "";

		public static void AddTab(Tab tab)
		{
			if (tab == null || string.IsNullOrEmpty(tab.Name))
			{
				throw new ArgumentException("tab needs a Name");
			}
			Tabs.Add(tab);
		}

		public static void Status(string text)
		{
			Panel currentPanel = Plugin.CurrentPanel;
			if (currentPanel != null && currentPanel.Open)
			{
				currentPanel.Flash(text);
			}
			else
			{
				Toast(text);
			}
		}

		public static void Toast(string text)
		{
			MessageHud instance = MessageHud.instance;
			if (instance != null)
			{
				instance.ShowMessage((MessageType)1, text, 0, (Sprite)null, false, true);
			}
		}
	}
	internal static class Catalog
	{
		internal sealed class Entry
		{
			public string Prefab;

			public string Name;

			public string Category;

			public Sprite Icon;

			public bool Boss;

			public bool Tameable;

			public int MaxStack = 1;
		}

		internal static readonly List<Entry> Creatures = new List<Entry>();

		internal static readonly List<Entry> Items = new List<Entry>();

		internal static readonly string[] CreatureCategories = new string[11]
		{
			"Meadows", "Black Forest", "Swamp", "Mountains", "Plains", "Mistlands", "Ashlands", "Deep North", "Ocean", "Bosses",
			"Other"
		};

		internal static readonly string[] ItemCategories = new string[8] { "Materials", "Food", "Weapons", "Ammo", "Armour", "Tools", "Trophies", "Other" };

		private static bool _built;

		private static readonly (Biome biome, string name)[] Progression = new(Biome, string)[9]
		{
			((Biome)1, "Meadows"),
			((Biome)8, "Black Forest"),
			((Biome)2, "Swamp"),
			((Biome)4, "Mountains"),
			((Biome)16, "Plains"),
			((Biome)512, "Mistlands"),
			((Biome)32, "Ashlands"),
			((Biome)64, "Deep North"),
			((Biome)256, "Ocean")
		};

		private static readonly Dictionary<string, string> Wiki = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
		{
			{ "Eikthyr", "Bosses" },
			{ "The Elder", "Bosses" },
			{ "Bonemass", "Bosses" },
			{ "Moder", "Bosses" },
			{ "Yagluth", "Bosses" },
			{ "The Queen", "Bosses" },
			{ "Fader", "Bosses" },
			{ "Kall Fimbulbringer", "Bosses" },
			{ "Brenna", "Bosses" },
			{ "Geirrhafa", "Bosses" },
			{ "Zil & Thungr", "Bosses" },
			{ "Lord Reto", "Bosses" },
			{ "Boar", "Meadows" },
			{ "Neck", "Meadows" },
			{ "Greyling", "Meadows" },
			{ "Greydwarf", "Black Forest" },
			{ "Greydwarf Brute", "Black Forest" },
			{ "Greydwarf Shaman", "Black Forest" },
			{ "Troll", "Black Forest" },
			{ "Skeleton", "Black Forest" },
			{ "Rancid Remains", "Black Forest" },
			{ "Ghost", "Black Forest" },
			{ "Root", "Black Forest" },
			{ "Bear", "Black Forest" },
			{ "Serpent", "Ocean" },
			{ "Abomination", "Swamp" },
			{ "Blob", "Swamp" },
			{ "Oozer", "Swamp" },
			{ "Draugr", "Swamp" },
			{ "Draugr Elite", "Swamp" },
			{ "Leech", "Swamp" },
			{ "Surtling", "Swamp" },
			{ "Wraith", "Swamp" },
			{ "Writhan", "Swamp" },
			{ "Kvastur", "Swamp" },
			{ "Wolf", "Mountains" },
			{ "Drake", "Mountains" },
			{ "Fenring", "Mountains" },
			{ "Stone Golem", "Mountains" },
			{ "Bat", "Mountains" },
			{ "Ulv", "Mountains" },
			{ "Cultist", "Mountains" },
			{ "Deathsquito", "Plains" },
			{ "Lox", "Plains" },
			{ "Fuling", "Plains" },
			{ "Fuling Berserker", "Plains" },
			{ "Fuling Shaman", "Plains" },
			{ "Growth", "Plains" },
			{ "Vile", "Plains" },
			{ "Seeker", "Mistlands" },
			{ "Seeker Soldier", "Mistlands" },
			{ "Seeker Brood", "Mistlands" },
			{ "Gjall", "Mistlands" },
			{ "Tick", "Mistlands" },
			{ "Dvergr Rogue", "Mistlands" },
			{ "Dvergr Mage", "Mistlands" },
			{ "Bonemaw", "Ashlands" },
			{ "Lava Blob", "Ashlands" },
			{ "Fallen Valkyrie", "Ashlands" },
			{ "Charred Warlock", "Ashlands" },
			{ "Charred Warrior", "Ashlands" },
			{ "Charred Marksman", "Ashlands" },
			{ "Charred Twitcher", "Ashlands" },
			{ "Volture", "Ashlands" },
			{ "Morgen", "Ashlands" },
			{ "Asksvin", "Ashlands" },
			{ "Skugg", "Ashlands" },
			{ "Barka", "Deep North" },
			{ "Elaking", "Deep North" },
			{ "Eyeless One", "Deep North" },
			{ "Fallen Warrior", "Deep North" },
			{ "Gammeltroll", "Deep North" },
			{ "Hexen", "Deep North" },
			{ "Krigen", "Deep North" },
			{ "Shapeless Pulp", "Deep North" },
			{ "Tiny Pulp", "Deep North" },
			{ "Moose", "Deep North" },
			{ "Crow", "Black Forest" },
			{ "Gull", "Meadows" },
			{ "Ash Crow", "Ashlands" },
			{ "Leviathan", "Ocean" },
			{ "Deer", "Meadows" },
			{ "Hare", "Mistlands" },
			{ "Baby Seal", "Deep North" },
			{ "Seal", "Deep North" }
		};

		private static readonly Dictionary<string, string> Dungeon = new Dictionary<string, string>
		{
			{ "Skeleton", "Black Forest" },
			{ "Skeleton_Poison", "Black Forest" },
			{ "Ghost", "Black Forest" },
			{ "Troll", "Black Forest" },
			{ "Draugr", "Swamp" },
			{ "Draugr_Elite", "Swamp" },
			{ "Draugr_Ranged", "Swamp" },
			{ "BlobElite", "Swamp" },
			{ "Wraith", "Swamp" },
			{ "Dverger", "Mistlands" },
			{ "DvergerMage", "Mistlands" },
			{ "DvergerMageFire", "Mistlands" },
			{ "DvergerMageIce", "Mistlands" },
			{ "DvergerMageSupport", "Mistlands" },
			{ "SeekerBrood", "Mistlands" },
			{ "SeekerBrute", "Mistlands" }
		};

		internal static event Action IconsChanged;

		internal static void Build()
		{
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			if (_built || (Object)(object)ZNetScene.instance == (Object)null || (Object)(object)ObjectDB.instance == (Object)null || ObjectDB.instance.m_items.Count == 0)
			{
				return;
			}
			_built = true;
			foreach (GameObject item in ObjectDB.instance.m_items)
			{
				ItemDrop val = (((Object)(object)item != (Object)null) ? item.GetComponent<ItemDrop>() : null);
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				SharedData shared = val.m_itemData.m_shared;
				if (shared.m_icons != null && shared.m_icons.Length != 0 && !((Object)(object)shared.m_icons[0] == (Object)null))
				{
					string text = Localization.instance.Localize(shared.m_name);
					if (!string.IsNullOrEmpty(text) && !text.StartsWith("["))
					{
						Items.Add(new Entry
						{
							Prefab = ((Object)item).name,
							Name = text,
							Icon = shared.m_icons[0],
							Category = ItemCategory(shared.m_itemType),
							MaxStack = Mathf.Max(1, shared.m_maxStackSize)
						});
					}
				}
			}
			Items.Sort((Entry a, Entry b) => string.CompareOrdinal(a.Name, b.Name));
			var (homes, rest) = SpawnBiomes();
			foreach (GameObject prefab in ZNetScene.instance.m_prefabs)
			{
				Character val2 = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<Character>() : null);
				if (!((Object)(object)val2 == (Object)null) && !(val2 is Player) && !((Object)(object)prefab.GetComponent<BaseAI>() == (Object)null))
				{
					string text2 = Localization.instance.Localize(val2.m_name);
					if (!string.IsNullOrEmpty(text2) && !text2.StartsWith("["))
					{
						Creatures.Add(new Entry
						{
							Prefab = ((Object)prefab).name,
							Name = text2,
							Icon = TrophyIcon(prefab),
							Boss = val2.m_boss,
							Tameable = ((Object)(object)prefab.GetComponent<Tameable>() != (Object)null),
							Category = Category(val2, ((Object)prefab).name, text2, homes, rest)
						});
					}
				}
			}
			Creatures.Sort((Entry a, Entry b) => string.CompareOrdinal(a.Name, b.Name));
			Portraits();
			Log.Info($"Catalog: {Creatures.Count} creatures, {Items.Count} items");
		}

		private static void Portraits()
		{
			((MonoBehaviour)Plugin.Instance).StartCoroutine(RenderPortraits());
		}

		private static IEnumerator RenderPortraits()
		{
			int n = 0;
			Entry[] array = Creatures.ToArray();
			foreach (Entry entry in array)
			{
				GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab(entry.Prefab) : null);
				if (!((Object)(object)val == (Object)null))
				{
					Sprite val2 = null;
					try
					{
						val2 = RenderManager.Instance.Render(new RenderRequest(val)
						{
							Rotation = Quaternion.Euler(8f, 155f, 0f),
							Width = 128,
							Height = 128,
							UseCache = true
						});
					}
					catch (Exception ex)
					{
						Log.Warn("no portrait for " + entry.Prefab + ": " + ex.Message);
					}
					if ((Object)(object)val2 != (Object)null)
					{
						entry.Icon = val2;
						Catalog.IconsChanged?.Invoke();
					}
					int num = n + 1;
					n = num;
					if (num % 3 == 0)
					{
						yield return null;
					}
				}
			}
		}

		private static Sprite TrophyIcon(GameObject go)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Invalid comparison between Unknown and I4
			CharacterDrop component = go.GetComponent<CharacterDrop>();
			if ((Object)(object)component == (Object)null)
			{
				return null;
			}
			foreach (Drop drop in component.m_drops)
			{
				if (!((Object)(object)drop.m_prefab == (Object)null))
				{
					ItemDrop component2 = drop.m_prefab.GetComponent<ItemDrop>();
					if ((Object)(object)component2 != (Object)null && (int)component2.m_itemData.m_shared.m_itemType == 13)
					{
						return component2.m_itemData.GetIcon();
					}
				}
			}
			return null;
		}

		private static string Category(Character c, string prefab, string name, Dictionary<string, string> homes, Dictionary<string, string> rest)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			if (c.m_boss)
			{
				return "Bosses";
			}
			if (homes.TryGetValue(prefab, out var value))
			{
				return value;
			}
			if (Wiki.TryGetValue(name, out var value2))
			{
				return value2;
			}
			if (rest.TryGetValue(prefab, out var value3))
			{
				return value3;
			}
			return CreatureCategory(c.m_faction);
		}

		private static (Dictionary<string, string> homes, Dictionary<string, string> rest) SpawnBiomes()
		{
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<string, Dictionary<int, int>> dictionary = new Dictionary<string, Dictionary<int, int>>();
			Dictionary<string, Biome> dictionary2 = new Dictionary<string, Biome>();
			GameObject val = (((Object)(object)ZoneSystem.instance != (Object)null) ? ZoneSystem.instance.m_zoneCtrlPrefab : null);
			if ((Object)(object)val != (Object)null)
			{
				SpawnSystem[] componentsInChildren = val.GetComponentsInChildren<SpawnSystem>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					foreach (SpawnSystemList spawnList in componentsInChildren[i].m_spawnLists)
					{
						if (!((Object)(object)spawnList != (Object)null))
						{
							continue;
						}
						foreach (SpawnData sp in spawnList.m_spawners)
						{
							if (sp == null || !sp.m_enabled || (Object)(object)sp.m_prefab == (Object)null)
							{
								continue;
							}
							string name = ((Object)sp.m_prefab).name;
							dictionary2[name] = (Biome)((dictionary2.TryGetValue(name, out var value) ? ((int)value) : 0) | sp.m_biome);
							int num = Array.FindIndex(Progression, ((Biome biome, string name) x) => x.biome == sp.m_biome);
							if (num >= 0)
							{
								if (!dictionary.TryGetValue(name, out var value2))
								{
									value2 = (dictionary[name] = new Dictionary<int, int>());
								}
								value2[num] = (value2.TryGetValue(num, out var value3) ? value3 : 0) + 1;
							}
						}
					}
				}
			}
			Dictionary<string, string> dictionary4 = new Dictionary<string, string>();
			Dictionary<string, string> dictionary5 = new Dictionary<string, string>(Dungeon);
			foreach (KeyValuePair<string, Biome> item in dictionary2)
			{
				if (dictionary.TryGetValue(item.Key, out var value4))
				{
					dictionary4[item.Key] = Progression[(from x in value4
						orderby x.Value descending, x.Key descending
						select x).First().Key].name;
				}
				else
				{
					if (dictionary5.ContainsKey(item.Key))
					{
						continue;
					}
					(Biome, string)[] progression = Progression;
					for (int i = 0; i < progression.Length; i++)
					{
						var (val2, value5) = progression[i];
						if ((item.Value & val2) != 0)
						{
							dictionary5[item.Key] = value5;
							break;
						}
					}
				}
			}
			Log.Info($"spawn-table homes for {dictionary4.Count} creatures");
			return (homes: dictionary4, rest: dictionary5);
		}

		private unsafe static string CreatureCategory(Faction f)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected I4, but got Unknown
			switch (f - 1)
			{
			case 0:
				return "Meadows";
			case 1:
				return "Black Forest";
			case 2:
				return "Swamp";
			case 3:
				return "Swamp";
			case 4:
				return "Mountains";
			case 6:
				return "Plains";
			case 8:
				return "Mistlands";
			case 9:
				return "Mistlands";
			case 5:
				return "Ocean";
			default:
				if (!((object)(*(Faction*)(&f))/*cast due to .constrained prefix*/).ToString().Contains("Ash"))
				{
					return "Other";
				}
				return "Ashlands";
			}
		}

		private static string ItemCategory(ItemType t)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected I4, but got Unknown
			switch (t - 1)
			{
			case 0:
				return "Materials";
			case 1:
				return "Food";
			case 2:
			case 3:
			case 13:
			case 14:
			case 21:
				return "Weapons";
			case 8:
			case 22:
				return "Ammo";
			case 4:
			case 5:
			case 6:
			case 10:
			case 16:
			case 17:
				return "Armour";
			case 18:
				return "Tools";
			case 12:
				return "Trophies";
			default:
				return "Other";
			}
		}
	}
	internal static class Hammer
	{
		internal const string Prefab = "Jatify_AdminHammer";

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

		internal static bool Equipped
		{
			get
			{
				Player localPlayer = Player.m_localPlayer;
				if ((Object)(object)localPlayer == (Object)null)
				{
					return false;
				}
				foreach (ItemData equippedItem in ((Humanoid)localPlayer).GetInventory().GetEquippedItems())
				{
					if ((Object)(object)equippedItem.m_dropPrefab != (Object)null && ((Object)equippedItem.m_dropPrefab).name == "Jatify_AdminHammer")
					{
						return true;
					}
				}
				return false;
			}
		}

		internal static void Register()
		{
			if (ItemManager.Instance.GetItem("Jatify_AdminHammer") == null)
			{
				if ((Object)(object)ObjectDB.instance != (Object)null && ObjectDB.instance.m_items.Count > 0)
				{
					Add();
					Live();
				}
				else
				{
					PrefabManager.OnVanillaPrefabsAvailable += Add;
				}
			}
		}

		private static void Live()
		{
			CustomItem item = ItemManager.Instance.GetItem("Jatify_AdminHammer");
			ObjectDB instance = ObjectDB.instance;
			if (item != null && !((Object)(object)instance == (Object)null) && !((Object)(object)instance.GetItemPrefab("Jatify_AdminHammer") != (Object)null))
			{
				instance.m_items.Add(item.ItemPrefab);
				CustomRecipe recipe = item.Recipe;
				if ((Object)(object)((recipe != null) ? recipe.Recipe : null) != (Object)null)
				{
					instance.m_recipes.Add(item.Recipe.Recipe);
				}
				AccessTools.Method(typeof(ObjectDB), "UpdateRegisters", (Type[])null, (Type[])null)?.Invoke(instance, null);
				ZNetScene instance2 = ZNetScene.instance;
				if ((Object)(object)instance2 != (Object)null && !instance2.m_prefabs.Contains(item.ItemPrefab))
				{
					instance2.m_prefabs.Add(item.ItemPrefab);
					AccessTools.FieldRefAccess<ZNetScene, Dictionary<int, GameObject>>("m_namedPrefabs").Invoke(instance2)[StringExtensionMethods.GetStableHashCode("Jatify_AdminHammer")] = item.ItemPrefab;
				}
			}
		}

		private static void Add()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			PrefabManager.OnVanillaPrefabsAvailable -= Add;
			ItemConfig val = new ItemConfig();
			val.Name = "Admin hammer";
			val.Description = "Right click: the admin panel. Left click: place the creature picked there.";
			val.CraftingStation = CraftingStations.Workbench;
			val.Requirements = (RequirementConfig[])(object)new RequirementConfig[2]
			{
				new RequirementConfig("Wood", 1, 0, false),
				new RequirementConfig("Stone", 1, 0, false)
			};
			CustomItem val2 = new CustomItem("Jatify_AdminHammer", "Hammer", val);
			SharedData shared = val2.ItemDrop.m_itemData.m_shared;
			shared.m_buildPieces = null;
			Tint(val2.ItemPrefab);
			Sprite val3 = RenderManager.Instance.Render(val2.ItemPrefab, RenderManager.IsometricRotation);
			if ((Object)(object)val3 != (Object)null)
			{
				shared.m_icons = (Sprite[])(object)new Sprite[1] { val3 };
			}
			ItemManager.Instance.AddItem(val2);
		}

		private static void Tint(GameObject go)
		{
			Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer obj in componentsInChildren)
			{
				obj.sharedMaterials = ((IEnumerable<Material>)obj.sharedMaterials).Select((Func<Material, Material>)delegate(Material m)
				{
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0012: Expected O, but got Unknown
					//IL_0021: Unknown result type (might be due to invalid IL or missing references)
					//IL_0026: Unknown result type (might be due to invalid IL or missing references)
					//IL_002b: Unknown result type (might be due to invalid IL or missing references)
					if ((Object)(object)m == (Object)null)
					{
						return m;
					}
					Material val = new Material(m);
					if (val.HasProperty("_Color"))
					{
						val.color *= Gold;
					}
					return val;
				}).ToArray();
			}
		}

		internal static bool Equip()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return false;
			}
			foreach (ItemData allItem in ((Humanoid)localPlayer).GetInventory().GetAllItems())
			{
				if ((Object)(object)allItem.m_dropPrefab != (Object)null && ((Object)allItem.m_dropPrefab).name == "Jatify_AdminHammer")
				{
					return ((Humanoid)localPlayer).EquipItem(allItem, true);
				}
			}
			return false;
		}

		internal static void Give()
		{
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null))
			{
				if (!Spawner.CanAdmin)
				{
					((Character)localPlayer).Message((MessageType)2, "Admin hammer: you are not an admin on this server", 0, (Sprite)null, false);
				}
				else if (((Humanoid)localPlayer).GetInventory().AddItem("Jatify_AdminHammer", 1, 1, 0, 0L, "", false, false) == null)
				{
					((Character)localPlayer).Message((MessageType)2, "No room in your inventory", 0, (Sprite)null, false);
				}
			}
		}
	}
	internal sealed class HammerCommand : ConsoleCommand
	{
		public override string Name => "adminhammer";

		public override string Help => "Gives you the Admin hammer (admins only)";

		public override void Run(string[] args)
		{
			Hammer.Give();
		}
	}
	internal static class Log
	{
		private static ManualLogSource _s;

		internal static void Bind(ManualLogSource s)
		{
			if (_s == null)
			{
				_s = s;
			}
		}

		internal static void Info(string m)
		{
			ManualLogSource s = _s;
			if (s != null)
			{
				s.LogInfo((object)m);
			}
		}

		internal static void Warn(string m)
		{
			ManualLogSource s = _s;
			if (s != null)
			{
				s.LogWarning((object)m);
			}
		}
	}
	internal static class Modifiers
	{
		internal sealed class Slider
		{
			public string Name;

			public string Tip;

			public int Default;

			public List<(string name, List<string> keys)> Settings = new List<(string, List<string>)>();
		}

		internal sealed class Toggle
		{
			public string Name;

			public string Tip;

			public string Key;
		}

		internal static readonly List<Slider> Sliders = new List<Slider>();

		internal static readonly List<Toggle> Toggles = new List<Toggle>();

		internal static void Load()
		{
			if (Sliders.Count <= 0)
			{
				try
				{
					FromGame();
				}
				catch (Exception ex)
				{
					Log.Warn("modifier read failed, using the built-in table: " + ex.Message);
				}
				if (Sliders.Count == 0)
				{
					Fallback();
				}
			}
		}

		private static void FromGame()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			if (!(typeof(ServerOptionsGUI).GetField("m_modifiers", BindingFlags.Static | BindingFlags.NonPublic)?.GetValue(null) is KeyUI[] array))
			{
				return;
			}
			KeyUI[] array2 = array;
			foreach (KeyUI val in array2)
			{
				KeySlider val2 = (KeySlider)(object)((val is KeySlider) ? val : null);
				if (val2 != null && (int)val2.m_modifier != 0)
				{
					Slider slider = new Slider
					{
						Name = Words(((object)Unsafe.As<WorldModifiers, WorldModifiers>(ref val2.m_modifier)/*cast due to .constrained prefix*/).ToString()),
						Tip = Loc(val2.m_toolTip),
						Default = val2.m_defaultIndex
					};
					foreach (SliderSetting setting in val2.m_settings)
					{
						slider.Settings.Add((Loc(setting.m_name), new List<string>(setting.m_keys)));
					}
					Sliders.Add(slider);
				}
				else
				{
					KeyToggle t = (KeyToggle)(object)((val is KeyToggle) ? val : null);
					if (t != null && !Toggles.Any((Toggle x) => x.Key == t.m_enabledKey))
					{
						Toggles.Add(new Toggle
						{
							Key = t.m_enabledKey,
							Name = ToggleName(t),
							Tip = Loc(t.m_toolTip)
						});
					}
				}
			}
		}

		private static string Words(string s)
		{
			return Regex.Replace(s, "(?<=[a-z])([A-Z])", (Match m) => " " + m.Value.ToLowerInvariant());
		}

		private static string ToggleName(KeyToggle t)
		{
			string[] array = new string[2]
			{
				t.m_toolTip?.Replace("_tooltip", ""),
				"$menu_" + t.m_enabledKey
			};
			foreach (string text in array)
			{
				if (!string.IsNullOrEmpty(text))
				{
					string text2 = Loc(text);
					if (!string.IsNullOrEmpty(text2) && !text2.StartsWith("[") && !text2.StartsWith("$"))
					{
						return text2;
					}
				}
			}
			return char.ToUpperInvariant(t.m_enabledKey[0]) + t.m_enabledKey.Substring(1);
		}

		private static string Loc(string s)
		{
			if (Localization.instance == null || s == null || !s.StartsWith("$"))
			{
				return s;
			}
			return Localization.instance.Localize(s);
		}

		private static void Fallback()
		{
			Sliders.Add(S("Combat", 2, new(string, string[])[5]
			{
				("Very easy", new string[3] { "playerdamage 125", "enemydamage 50", "enemyspeedsize 90" }),
				("Easy", new string[3] { "playerdamage 110", "enemydamage 75", "enemyspeedsize 95" }),
				("Normal", new string[0]),
				("Hard", new string[4] { "playerdamage 85", "enemydamage 150", "enemyspeedsize 110", "enemyleveluprate 120" }),
				("Very hard", new string[4] { "playerdamage 70", "enemydamage 200", "enemyspeedsize 120", "enemyleveluprate 140" })
			}));
			Sliders.Add(S("Death penalty", 3, new(string, string[])[6]
			{
				("Casual", new string[2] { "deathkeepequip", "SkillReductionRate 15" }),
				("Very easy", new string[1] { "SkillReductionRate 15" }),
				("Easy", new string[1] { "SkillReductionRate 50" }),
				("Normal", new string[0]),
				("Hard", new string[2] { "DeathDeleteUnequipped", "SkillReductionRate 150" }),
				("Hardcore", new string[2] { "deathdeleteitems", "deathskillsreset" })
			}));
			Sliders.Add(S("Resources", 2, new(string, string[])[6]
			{
				("x 0.5", new string[1] { "resourcerate 50" }),
				("x 0.75", new string[1] { "resourcerate 75" }),
				("Normal", new string[0]),
				("x 1.5", new string[1] { "resourcerate 150" }),
				("x 2", new string[1] { "resourcerate 200" }),
				("x 3", new string[1] { "resourcerate 300" })
			}));
			Sliders.Add(S("Raids", 3, new(string, string[])[6]
			{
				("None", new string[1] { "eventrate 0" }),
				("Much less", new string[1] { "eventrate 200" }),
				("Less", new string[1] { "eventrate 150" }),
				("Normal", new string[0]),
				("More", new string[1] { "eventrate 60" }),
				("Much more", new string[1] { "eventrate 30" })
			}));
			Sliders.Add(S("Portals", 1, new(string, string[])[4]
			{
				("Teleport all", new string[1] { "teleportall" }),
				("Normal", new string[0]),
				("No boss portals", new string[1] { "nobossportals" }),
				("No portals", new string[1] { "noportals" })
			}));
			(string, string)[] array = new(string, string)[7]
			{
				("nobuildcost", "No build cost"),
				("nomap", "No map"),
				("passivemobs", "Passive mobs"),
				("playerevents", "Player-based raids"),
				("fire", "Fire hazards"),
				("teleportall", "Teleport all"),
				("noportals", "No portals")
			};
			for (int i = 0; i < array.Length; i++)
			{
				var (key, name) = array[i];
				Toggles.Add(new Toggle
				{
					Key = key,
					Name = name
				});
			}
			static Slider S(string n, int d, params (string, string[])[] xs)
			{
				Slider slider = new Slider
				{
					Name = n,
					Default = d
				};
				for (int j = 0; j < xs.Length; j++)
				{
					var (item, source) = xs[j];
					slider.Settings.Add((item, source.ToList()));
				}
				return slider;
			}
		}

		internal static string KeyName(string key)
		{
			return key.Split(new char[1] { ' ' })[0].ToLowerInvariant();
		}

		internal static HashSet<string> Current()
		{
			return new HashSet<string>(((Object)(object)ZoneSystem.instance != (Object)null) ? (from k in ZoneSystem.instance.GetGlobalKeys()
				select k.ToLowerInvariant()) : Enumerable.Empty<string>());
		}

		internal static int Active(Slider s, HashSet<string> cur)
		{
			int result = -1;
			int num = -1;
			for (int i = 0; i < s.Settings.Count; i++)
			{
				List<string> item = s.Settings[i].keys;
				if (item.All((string k) => cur.Contains(k.ToLowerInvariant())) && item.Count > num)
				{
					result = i;
					num = item.Count;
				}
			}
			return result;
		}

		internal static void Apply(Slider s, int index)
		{
			HashSet<string> hashSet = new HashSet<string>(s.Settings[index].keys.Select(KeyName));
			foreach (string item in s.Settings.SelectMany(((string name, List<string> keys) x) => x.keys).Select(KeyName).Distinct())
			{
				if (!hashSet.Contains(item))
				{
					Spawner.RemoveKey(item);
				}
			}
			foreach (string item2 in s.Settings[index].keys)
			{
				Spawner.SetKey(item2.ToLowerInvariant());
			}
		}

		internal static void Set(Toggle t, bool on)
		{
			if (on)
			{
				Spawner.SetKey(t.Key);
			}
			else
			{
				Spawner.RemoveKey(t.Key);
			}
		}
	}
	internal sealed class Panel
	{
		private enum Tab
		{
			Creatures,
			Items,
			World
		}

		private const float W = 1100f;

		private const float H = 660f;

		private const float Head = 56f;

		private const float Foot = 44f;

		private const float Body = 560f;

		private const float RailW = 232f;

		private const float InsW = 288f;

		private const float WorkW = 580f;

		private readonly RectTransform _root;

		private readonly RectTransform _head;

		private readonly RectTransform _body;

		private readonly RectTransform _foot;

		private RectTransform _cats;

		private RectTransform _toolbar;

		private RectTransform _grid;

		private RectTransform _ins;

		private RectTransform _popup;

		private TMP_InputField _search;

		private int _tab;

		private readonly Dictionary<Tab, string> _cat = new Dictionary<Tab, string>
		{
			[Tab.Creatures] = "Meadows",
			[Tab.Items] = "Materials"
		};

		private readonly Dictionary<Tab, string> _sel = new Dictionary<Tab, string>();

		private string _query = "";

		private int _stars;

		private int _count = 1;

		private int _amount = 10;

		private bool _tamed;

		private bool _place;

		private string _target = "";

		private string _status = "";

		private float _statusUntil;

		private readonly List<RectTransform> _ext = new List<RectTransform>();

		private bool _iconsDirty;

		private float _repaintAt;

		internal bool Open
		{
			get
			{
				if ((Object)(object)_root != (Object)null)
				{
					return ((Component)_root).gameObject.activeSelf;
				}
				return false;
			}
		}

		internal string Target => _target;

		private Tab Ours => (Tab)Mathf.Min(_tab, 2);

		private AdminHammerApi.Tab Ext
		{
			get
			{
				if (_tab < 3 || _tab - 3 >= AdminHammerApi.Tabs.Count)
				{
					return null;
				}
				return AdminHammerApi.Tabs[_tab - 3];
			}
		}

		internal Transform Root => (Transform)(object)_root;

		private List<Catalog.Entry> Source
		{
			get
			{
				if (Ours != Tab.Creatures)
				{
					return Catalog.Items;
				}
				return Catalog.Creatures;
			}
		}

		private string[] Categories
		{
			get
			{
				if (Ours != Tab.Creatures)
				{
					return Catalog.ItemCategories;
				}
				return Catalog.CreatureCategories;
			}
		}

		private Catalog.Entry Selected
		{
			get
			{
				if (!_sel.TryGetValue(Ours, out var p))
				{
					return null;
				}
				return Source.FirstOrDefault((Catalog.Entry e) => e.Prefab == p);
			}
		}

		internal Panel(Transform hudroot)
		{
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: 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)
			_root = AdminHammerUi.Node(hudroot, "AdminHammerPanel");
			RectTransform root = _root;
			RectTransform root2 = _root;
			RectTransform root3 = _root;
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0.5f, 0.5f);
			root3.pivot = val;
			root.anchorMin = (root2.anchorMax = val);
			_root.anchoredPosition = new Vector2(0f, 30f);
			_root.sizeDelta = new Vector2(1100f, 660f);
			AdminHammerUi.Fill(((Graphic)AdminHammerUi.Box((Transform)(object)_root, "Panel", new Color(0.078f, 0.078f, 0.086f, 0.9f), AdminHammerUi.C("glassLine"), 14)).rectTransform);
			_head = AdminHammerUi.Place(AdminHammerUi.Node((Transform)(object)_root, "Head"), 0f, 0f, 1100f, 56f);
			Line((Transform)(object)_root, 0f, 56f, 1100f);
			_body = AdminHammerUi.Place(AdminHammerUi.Node((Transform)(object)_root, "Body"), 0f, 57f, 1100f, 559f);
			Line((Transform)(object)_root, 0f, 616f, 1100f);
			_foot = AdminHammerUi.Place(AdminHammerUi.Node((Transform)(object)_root, "Foot"), 0f, 617f, 1100f, 43f);
			foreach (AdminHammerApi.Tab tab in AdminHammerApi.Tabs)
			{
				RectTransform val3 = AdminHammerUi.Place(AdminHammerUi.Node((Transform)(object)_root, "Ext " + tab.Name), 0f, 57f, 1100f, 559f);
				try
				{
					tab.Build?.Invoke(val3);
				}
				catch (Exception arg)
				{
					Log.Warn($"tab {tab.Name}: {arg}");
				}
				((Component)val3).gameObject.SetActive(false);
				_ext.Add(val3);
			}
			((Component)_root).gameObject.SetActive(false);
			Catalog.IconsChanged += delegate
			{
				if (Open && _tab == 0)
				{
					_iconsDirty = true;
				}
			};
		}

		internal void Toggle()
		{
			if (Open)
			{
				Close();
			}
			else
			{
				Show();
			}
		}

		internal void Show()
		{
			Catalog.Build();
			Modifiers.Load();
			((Component)_root).gameObject.SetActive(true);
			((Transform)_root).SetAsLastSibling();
			BuildTab();
		}

		internal void Close()
		{
			ClosePopup();
			((Component)_root).gameObject.SetActive(false);
		}

		internal void Destroy()
		{
			if ((Object)(object)_root != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_root).gameObject);
			}
		}

		internal void Tick()
		{
			if (!Open)
			{
				return;
			}
			if (Ext != null)
			{
				try
				{
					Ext.Tick?.Invoke();
				}
				catch (Exception arg)
				{
					Log.Warn($"tab {Ext.Name}: {arg}");
				}
			}
			if (_iconsDirty && Time.unscaledTime >= _repaintAt)
			{
				_iconsDirty = false;
				_repaintAt = Time.unscaledTime + 0.5f;
				PaintGrid();
			}
			if (_status.Length > 0 && Time.unscaledTime > _statusUntil)
			{
				_status = "";
				if (Ext == null && Ours != Tab.World)
				{
					PaintInspector();
				}
			}
			if (Input.GetKeyDown((KeyCode)47) && (Object)(object)_search != (Object)null && !_search.isFocused && Ext == null)
			{
				_search.ActivateInputField();
			}
		}

		internal void Flash(string text)
		{
			_status = text;
			_statusUntil = Time.unscaledTime + 2.6f;
			if (Ext == null && Ours != Tab.World)
			{
				PaintInspector();
			}
			else if (Ours == Tab.World && Ext == null)
			{
				PaintWorld();
			}
		}

		private void PaintHead()
		{
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_039b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: 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_023e: 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_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0501: Unknown result type (might be due to invalid IL or missing references)
			//IL_0529: Unknown result type (might be due to invalid IL or missing references)
			//IL_0579: Unknown result type (might be due to invalid IL or missing references)
			//IL_057e: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a5: Unknown result type (might be due to invalid IL or missing references)
			AdminHammerUi.Clear((Transform)(object)_head);
			ClosePopup();
			ObjectDB instance = ObjectDB.instance;
			object obj;
			if (instance == null)
			{
				obj = null;
			}
			else
			{
				GameObject itemPrefab = instance.GetItemPrefab("Jatify_AdminHammer");
				if (itemPrefab == null)
				{
					obj = null;
				}
				else
				{
					ItemDrop component = itemPrefab.GetComponent<ItemDrop>();
					obj = ((component != null) ? component.m_itemData.GetIcon() : null);
				}
			}
			Sprite val = (Sprite)obj;
			if ((Object)(object)val != (Object)null)
			{
				Image obj2 = JatifyLook.Img((Transform)(object)_head, val, Color.white, "Brand");
				obj2.preserveAspect = true;
				AdminHammerUi.Place(((Graphic)obj2).rectTransform, 18f, 14f, 28f, 28f);
			}
			TextMeshProUGUI t = AdminHammerUi.Text((Transform)(object)_head, "AdminHammer", "title", 22f, Color.white, ((Object)(object)val != (Object)null) ? 54f : 18f, 0f, 200f, 56f, (TextAlignmentOptions)4097);
			float num = (((Object)(object)val != (Object)null) ? 54f : 18f) + AdminHammerUi.Width((TMP_Text)(object)t) + 24f;
			List<(string, bool)> list = new List<(string, bool)>
			{
				("Creatures", false),
				("Items", false),
				("World", false)
			};
			list.AddRange(AdminHammerApi.Tabs.Select((AdminHammerApi.Tab tab) => (Name: tab.Name, true)));
			for (int num2 = 0; num2 < list.Count; num2++)
			{
				int k = num2;
				bool flag = num2 == _tab;
				Image val2 = AdminHammerUi.Box((Transform)(object)_head, "Tab", AdminHammerUi.NoColor, AdminHammerUi.NoColor, 1);
				TextMeshProUGUI t2 = AdminHammerUi.Text(((Component)val2).transform, list[num2].Item1, "medium", 14f, flag ? Color.white : AdminHammerUi.C("dim"), 12f, 0f, 200f, 56f, (TextAlignmentOptions)4097);
				float num3 = 12f + AdminHammerUi.Width((TMP_Text)(object)t2) + 12f;
				if (list[num2].Item2)
				{
					Image val3 = AdminHammerUi.Box(((Component)val2).transform, "Addon", AdminHammerUi.NoColor, AdminHammerUi.C("glassLine"), 4);
					((Graphic)val3).raycastTarget = false;
					TextMeshProUGUI obj3 = AdminHammerUi.Text(((Component)val3).transform, "add-on", "mono", 10f, AdminHammerUi.C("mute"), 0f, 0f, 60f, 16f, (TextAlignmentOptions)514);
					float num4 = AdminHammerUi.Width((TMP_Text)(object)obj3) + 8f;
					AdminHammerUi.Place(((Graphic)val3).rectTransform, num3 - 4f, 20f, num4, 16f);
					AdminHammerUi.Fill(((TMP_Text)obj3).rectTransform);
					num3 += num4 + 8f;
				}
				AdminHammerUi.Place(((Graphic)val2).rectTransform, num, 0f, num3, 56f);
				if (flag)
				{
					Image obj4 = AdminHammerUi.Box(((Component)val2).transform, "On", AdminHammerUi.C("accent"), AdminHammerUi.NoColor, 1);
					((Graphic)obj4).raycastTarget = false;
					AdminHammerUi.Place(((Graphic)obj4).rectTransform, 12f, 54f, num3 - 24f, 2f);
				}
				AdminHammerUi.On((Graphic)(object)val2, delegate
				{
					_tab = k;
					_query = "";
					BuildTab();
				});
				num += num3 + 4f;
			}
			float right = 1084f;
			Image obj5 = AdminHammerUi.Box((Transform)(object)_head, "Close", AdminHammerUi.NoColor, AdminHammerUi.C("glassLine"), 8);
			TextMeshProUGUI t3 = AdminHammerUi.Text(((Component)obj5).transform, "Close", "medium", 13f, AdminHammerUi.C("dim"), 12f, 0f, 60f, 32f, (TextAlignmentOptions)4097);
			float num5 = AdminHammerUi.Key(x: 12f + AdminHammerUi.Width((TMP_Text)(object)t3) + 8f, parent: ((Component)obj5).transform, key: "Esc", what: null, h: 32f);
			AdminHammerUi.Place(((Graphic)obj5).rectTransform, right - (num5 - 10f), 12f, num5 - 10f, 32f);
			AdminHammerUi.On((Graphic)(object)obj5, Close);
			right -= num5 - 10f + 10f;
			if (Ours == Tab.World && Ext == null)
			{
				return;
			}
			if (Ext == null || Ext.Targets)
			{
				string text = ((_target.Length > 0) ? _target : ((Ours == Tab.Creatures && Ext == null) ? "Where I aim" : "Me"));
				Image val4 = AdminHammerUi.Box((Transform)(object)_head, "Target", AdminHammerUi.C("raised"), AdminHammerUi.C("glassLine"), 8);
				TextMeshProUGUI t4 = AdminHammerUi.Text(((Component)val4).transform, "Target", "medium", 13f, AdminHammerUi.C("dim"), 12f, 0f, 60f, 32f, (TextAlignmentOptions)4097);
				float tw = 12f + AdminHammerUi.Width((TMP_Text)(object)t4) + 8f;
				Image obj6 = AdminHammerUi.Box(((Component)val4).transform, "Value", AdminHammerUi.C("raised2"), AdminHammerUi.NoColor, 6);
				TextMeshProUGUI t5 = AdminHammerUi.Text(((Component)obj6).transform, text + "  ▾", "medium", 13f, Color.white, 10f, 0f, 160f, 26f, (TextAlignmentOptions)4097);
				float num6 = 10f + AdminHammerUi.Width((TMP_Text)(object)t5) + 12f;
				AdminHammerUi.Place(((Graphic)obj6).rectTransform, tw, 3f, num6, 26f);
				float bw = tw + num6 + 4f;
				AdminHammerUi.Place(((Graphic)val4).rectTransform, right - bw, 12f, bw, 32f);
				AdminHammerUi.On((Graphic)(object)obj6, delegate
				{
					Popup(right - bw + tw, 48f);
				});
			}
		}

		private void Popup(float x, float y)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_popup != (Object)null)
			{
				ClosePopup();
				return;
			}
			List<string> list = new List<string>();
			list.Add("");
			list.AddRange(from p in Spawner.Players()
				select p.name);
			Image val = AdminHammerUi.Box((Transform)(object)_root, "TargetList", new Color(0.094f, 0.094f, 0.106f, 0.98f), AdminHammerUi.C("glassLine"), 8);
			_popup = ((Graphic)val).rectTransform;
			float num = 180f;
			float num2 = 4f;
			foreach (string item in list)
			{
				string n = item;
				bool flag = item == _target;
				Image obj = AdminHammerUi.Box(((Component)val).transform, "Opt", flag ? AdminHammerUi.C("raised2") : AdminHammerUi.NoColor, AdminHammerUi.NoColor, 6);
				AdminHammerUi.Place(((Graphic)obj).rectTransform, 4f, num2, num - 8f, 30f);
				AdminHammerUi.Text(((Component)obj).transform, (item.Length == 0) ? ((Ours == Tab.Creatures && Ext == null) ? "Where I aim" : "Me") : item, "medium", 13f, flag ? Color.white : AdminHammerUi.C("dim"), 10f, 0f, num - 28f, 30f, (TextAlignmentOptions)4097);
				AdminHammerUi.On((Graphic)(object)obj, delegate
				{
					_target = n;
					ClosePopup();
					AdminHammerApi.TargetChanged?.Invoke();
					BuildTab();
				});
				num2 += 32f;
			}
			AdminHammerUi.Place(_popup, Mathf.Min(x, 1100f - num - 8f), y, num, num2 + 2f);
		}

		private void ClosePopup()
		{
			if ((Object)(object)_popup != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_popup).gameObject);
			}
			_popup = null;
		}

		private void BuildTab()
		{
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < _ext.Count; i++)
			{
				((Component)_ext[i]).gameObject.SetActive(_tab - 3 == i);
			}
			PaintHead();
			AdminHammerUi.Clear((Transform)(object)_body);
			_search = null;
			_cats = (_toolbar = (_grid = (_ins = null)));
			((Component)_body).gameObject.SetActive(Ext == null);
			if (Ext != null)
			{
				try
				{
					Ext.Show?.Invoke();
				}
				catch (Exception arg)
				{
					Log.Warn($"tab {Ext.Name}: {arg}");
				}
				PaintFoot();
				return;
			}
			if (Ours == Tab.World)
			{
				PaintWorld();
				PaintFoot();
				return;
			}
			Line((Transform)(object)_body, 232f, 0f, 1f, 559f);
			_search = AdminHammerUi.Search((Transform)(object)_body, "Search " + ((Ours == Tab.Creatures) ? "creatures" : "items"), 12f, 14f, 208f, delegate(string q)
			{
				_query = (q ?? "").Trim().ToLowerInvariant();
				PaintCats();
				PaintToolbar();
				PaintGrid();
			});
			_cats = AdminHammerUi.Scroll((Transform)(object)_body, "Cats", 12f, 60f, 208f, 486f);
			_toolbar = AdminHammerUi.Place(AdminHammerUi.Node((Transform)(object)_body, "Toolbar"), 233f, 0f, 579f, 58f);
			Image obj = AdminHammerUi.Box((Transform)(object)_body, "ToolbarLine", AdminHammerUi.LineSoft, AdminHammerUi.NoColor, 1);
			((Graphic)obj).raycastTarget = false;
			AdminHammerUi.Place(((Graphic)obj).rectTransform, 233f, 58f, 579f, 1f);
			_grid = AdminHammerUi.Scroll((Transform)(object)_body, "Grid", 233f, 59f, 579f, 500f);
			Line((Transform)(object)_body, 812f, 0f, 1f, 559f);
			_ins = AdminHammerUi.Place(AdminHammerUi.Node((Transform)(object)_body, "Inspector"), 813f, 0f, 287f, 559f);
			PaintCats();
			PaintToolbar();
			PaintGrid();
			PaintInspector();
			PaintFoot();
		}

		private List<Catalog.Entry> Visible()
		{
			return ((_query.Length > 0) ? Source.Where((Catalog.Entry e) => e.Name.ToLowerInvariant().Contains(_query) || e.Prefab.ToLowerInvariant().Contains(_query)) : Source.Where((Catalog.Entry e) => e.Category == _cat[Ours])).ToList();
		}

		private void PaintCats()
		{
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_cats == (Object)null)
			{
				return;
			}
			AdminHammerUi.Clear((Transform)(object)_cats);
			float num = 0f;
			string[] categories = Categories;
			foreach (string cat in categories)
			{
				int num2 = Source.Count((Catalog.Entry e) => e.Category == cat);
				if (num2 == 0)
				{
					continue;
				}
				string c = cat;
				AdminHammerUi.CatRow((Transform)(object)_cats, cat, num2, _query.Length == 0 && cat == _cat[Ours], num, 208f, delegate
				{
					_cat[Ours] = c;
					_query = "";
					if ((Object)(object)_search != (Object)null)
					{
						_search.text = "";
					}
					PaintCats();
					PaintToolbar();
					PaintGrid();
				});
				num += 38f;
			}
			_cats.sizeDelta = new Vector2(0f, num);
		}

		private void PaintToolbar()
		{
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_toolbar == (Object)null)
			{
				return;
			}
			AdminHammerUi.Clear((Transform)(object)_toolbar);
			List<Catalog.Entry> list = Visible();
			float num = 563f;
			if (Ours == Tab.Creatures)
			{
				num -= SegW(new string[4] { "1", "3", "5", "10" });
				float x = num;
				AdminHammerUi.Seg((Transform)(object)_toolbar, x, 14f, new string[4] { "1", "3", "5", "10" }, Array.IndexOf(new int[4] { 1, 3, 5, 10 }, _count), delegate(int i)
				{
					_count = (new int[4] { 1, 3, 5, 10 })[i];
					PaintToolbar();
					PaintInspector();
				});
				num = Label((Transform)(object)_toolbar, "Count", x) - 18f;
				num -= SegW(new string[3] { "0★", "1★", "2★" });
				float x2 = num;
				AdminHammerUi.Seg((Transform)(object)_toolbar, x2, 14f, new string[3] { "0★", "1★", "2★" }, _stars, delegate(int i)
				{
					_stars = i;
					PaintToolbar();
					PaintInspector();
				});
				num = Label((Transform)(object)_toolbar, "Stars", x2) - 18f - 38f;
				AdminHammerUi.Switch((Transform)(object)_toolbar, num, 18f, _tamed, delegate(bool on)
				{
					_tamed = on;
					PaintToolbar();
					PaintInspector();
				});
				num = Label((Transform)(object)_toolbar, "Tamed", num);
			}
			else
			{
				string[] labels = new string[4] { "1", "10", "50", "Stack" };
				int[] vals = new int[4] { 1, 10, 50, 0 };
				num -= SegW(labels);
				AdminHammerUi.Seg((Transform)(object)_toolbar, num, 14f, labels, Array.IndexOf(vals, _amount), delegate(int i)
				{
					_amount = vals[i];
					PaintToolbar();
					PaintInspector();
				});
				num = Label((Transform)(object)_toolbar, "Amount", num) - 18f;
				string[] labels2 = new string[2] { "Drop", "Place" };
				num -= SegW(labels2);
				AdminHammerUi.Seg((Transform)(object)_toolbar, num, 14f, labels2, _place ? 1 : 0, delegate(int i)
				{
					_place = i == 1;
					PaintToolbar();
					PaintInspector();
					PaintFoot();
				});
				num = Label((Transform)(object)_toolbar, "Mode", num);
			}
			TextMeshProUGUI obj = AdminHammerUi.Text((Transform)(object)_toolbar, list.Count.ToString(), "mono", 12f, AdminHammerUi.C("mute"), 0f, 1f, 40f, 58f, (TextAlignmentOptions)4097);
			float num2 = AdminHammerUi.Width((TMP_Text)(object)obj);
			TextMeshProUGUI obj2 = AdminHammerUi.Text((Transform)(object)_toolbar, (_query.Length > 0) ? "Results" : _cat[Ours], "bold", 15f, Color.white, 16f, 0f, 200f, 58f, (TextAlignmentOptions)4097);
			float num3 = Mathf.Min(AdminHammerUi.Width((TMP_Text)(object)obj2), num - 16f - 14f - 6f - num2 - 16f);
			((TMP_Text)obj2).rectTransform.sizeDelta = new Vector2(Mathf.Max(20f, num3), 58f);
			AdminHammerUi.Place(((TMP_Text)obj).rectTransform, 16f + Mathf.Max(20f, num3) + 6f, 1f, num2 + 2f, 58f);
		}

		private float Label(Transform parent, string s, float x)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI obj = AdminHammerUi.Text(parent, s, "medium", 12f, AdminHammerUi.C("mute"), 0f, 0f, 80f, 58f, (TextAlignmentOptions)4097);
			float num = AdminHammerUi.Width((TMP_Text)(object)obj);
			AdminHammerUi.Place(((TMP_Text)obj).rectTransform, x - 8f - num, 0f, num + 2f, 58f);
			return x - 8f - num;
		}

		private static float SegW(string[] labels)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			float num = 2f;
			foreach (string s in labels)
			{
				TextMeshProUGUI val = JatifyLook.Text(null, s, "medium", 13f, Color.white, (TextAlignmentOptions)4097);
				num += Mathf.Max(32f, AdminHammerUi.Width((TMP_Text)(object)val) + 20f) + 2f;
				Object.Destroy((Object)(object)((Component)val).gameObject);
			}
			return num;
		}

		private void PaintGrid()
		{
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_grid == (Object)null)
			{
				return;
			}
			AdminHammerUi.Clear((Transform)(object)_grid);
			List<Catalog.Entry> list = Visible();
			Catalog.Entry selected = Selected;
			float num = 177f;
			for (int i = 0; i < list.Count; i++)
			{
				Catalog.Entry e = list[i];
				RectTransform tile = AdminHammerUi.Tile((Transform)(object)_grid, e.Icon, e.Name, selected == e, 16f + (float)(i % 3) * (num + 8f), 14f + (float)(i / 3) * 68f, num, delegate
				{
					_sel[Ours] = e.Prefab;
					_status = "";
					if ((Ours == Tab.Creatures || _place) && _target.Length == 0)
					{
						Act();
					}
					else
					{
						PaintGrid();
						PaintInspector();
					}
				}, delegate
				{
					_sel[Ours] = e.Prefab;
					Act();
				});
				if (Ours == Tab.Creatures && e.Boss)
				{
					AdminHammerUi.Tag(tile, "BOSS", "boss");
				}
			}
			if (list.Count == 0)
			{
				AdminHammerUi.Text((Transform)(object)_grid, "Nothing matches \"" + _query + "\". Try a shorter name.", "medium", 14f, AdminHammerUi.C("mute"), 20f, 24f, 540f, 24f, (TextAlignmentOptions)4097);
			}
			_grid.sizeDelta = new Vector2(0f, 14f + (float)Mathf.CeilToInt((float)list.Count / 3f) * 68f + 10f);
		}

		private void PaintInspector()
		{
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_ins == (Object)null)
			{
				return;
			}
			AdminHammerUi.Clear((Transform)(object)_ins);
			float num = 251f;
			float num2 = 18f;
			Catalog.Entry selected = Selected;
			if (selected == null)
			{
				AdminHammerUi.Para((Transform)(object)_ins, (Ours == Tab.Creatures) ? "Pick a creature to place it where you aim or next to a player." : "Pick an item to drop it in front of you or a player.", 14f, AdminHammerUi.C("mute"), num2, 18f, num, 80f);
				Status(num2, num);
				return;
			}
			AdminHammerUi.IconBox((Transform)(object)_ins, selected.Icon, selected.Name, num2, 18f, 56f, 12);
			((TMP_Text)AdminHammerUi.Text((Transform)(object)_ins, selected.Name, "bold", 18f, Color.white, num2 + 68f, 20f, num - 68f, 28f, (TextAlignmentOptions)4097)).overflowMode = (TextOverflowModes)1;
			AdminHammerUi.Text((Transform)(object)_ins, selected.Prefab, "mono", 12f, AdminHammerUi.C("mute"), num2 + 68f, 48f, num - 68f, 18f, (TextAlignmentOptions)4097);
			float num3 = 92f;
			if (Ours == Tab.Creatures)
			{
				num3 += AdminHammerUi.Meta((Transform)(object)_ins, num2, num3, num, ((selected.Category == "Bosses") ? "Type" : "Biome", (selected.Category == "Bosses") ? "Boss" : selected.Category), ("Stars", (_stars > 0) ? new string('★', _stars) : "None"), ("Count", _count.ToString()), ("Tamed", (!selected.Tameable) ? "Can't be tamed" : (_tamed ? "Yes" : "No")), ("Target", (_target.Length > 0) ? _target : "Where I aim")) + 14f;
				AdminHammerUi.Para((Transform)(object)_ins, (_target.Length > 0) ? $"Spawns {_count} next to {_target}, facing them." : "Clicking a creature closes the panel and a ghost follows your aim. Left click places, the wheel turns it, right click comes back here.", 12.5f, AdminHammerUi.C("mute"), num2, num3, num, 70f);
				AdminHammerUi.Primary((Transform)(object)_ins, (_target.Length > 0) ? ("Spawn next to " + _target) : "Place where I aim", num2, 469f, num, 42f, Act);
			}
			else
			{
				int num4 = ((_amount == 0) ? selected.MaxStack : _amount);
				num3 += AdminHammerUi.Meta((Transform)(object)_ins, num2, num3, num, ("Category", selected.Category), ("Stack size", selected.MaxStack.ToString()), ("Amount", (_amount == 0) ? $"Full stack ({selected.MaxStack})" : _amount.ToString()), ("For", (_target.Length > 0) ? _target : "Me")) + 14f;
				bool flag = _place && _target.Length == 0;
				AdminHammerUi.Para((Transform)(object)_ins, flag ? "Clicking an item closes the panel and it follows your aim. Left click puts the stacks down there, right click comes back here." : "Spills out like a broken chest. Double click a tile to drop straight away.", 12.5f, AdminHammerUi.C("mute"), num2, num3, num, 60f);
				AdminHammerUi.Primary((Transform)(object)_ins, flag ? $"Place {num4} where I aim" : $"Drop {num4}", num2, 469f, num, 42f, Act);
			}
			Status(num2, num);
		}

		private void Status(float x, float w)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			AdminHammerUi.Text((Transform)(object)_ins, _status, "medium", 12f, AdminHammerUi.C("accent"), x, 519f, w, 20f, (TextAlignmentOptions)4097);
		}

		private void PaintWorld()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			AdminHammerUi.Clear((Transform)(object)_body);
			RectTransform val = AdminHammerUi.Scroll((Transform)(object)_body, "World", 0f, 0f, 1100f, 559f);
			float num = 14f;
			float num2 = 18f;
			float num3 = 1064f;
			Image obj = AdminHammerUi.Box((Transform)(object)val, "Banner", AdminHammerUi.C("accentSoft"), AdminHammerUi.NoColor, 10);
			((Graphic)obj).raycastTarget = false;
			AdminHammerUi.Place(((Graphic)obj).rectTransform, num2, num, num3, 40f);
			AdminHammerUi.Text(((Component)obj).transform, "Only the game's own world-modifier settings are used, so the world is never flagged as cheated. Changes apply live on the server.", "medium", 13f, AdminHammerUi.C("accent"), 14f, 0f, num3 - 28f, 40f, (TextAlignmentOptions)4097);
			num += 48f;
			HashSet<string> hashSet = Modifiers.Current();
			AdminHammerUi.Section((Transform)(object)val, "Difficulty", num2 + 2f, num + 6f, 300f);
			num += 30f;
			foreach (Modifiers.Slider slider in Modifiers.Sliders)
			{
				RectTransform parent = WorldRow((Transform)(object)val, slider.Name, slider.Tip, num2, num, num3);
				string[] labels = slider.Settings.Select(((string name, List<string> keys) t) => t.name).ToArray();
				float num4 = SegW(labels);
				Modifiers.Slider sl = slider;
				AdminHammerUi.Seg((Transform)(object)parent, num3 - 14f - num4, 17f, labels, Modifiers.Active(slider, hashSet), delegate(int i)
				{
					Modifiers.Apply(sl, i);
					Flash(sl.Name + ": " + sl.Settings[i].name);
					Later(PaintWorld);
				}, quiet: true);
				num += 72f;
			}
			AdminHammerUi.Section((Transform)(object)val, "Rules", num2 + 2f, num + 6f, 300f);
			num += 30f;
			foreach (Modifiers.Toggle toggle in Modifiers.Toggles)
			{
				RectTransform parent2 = WorldRow((Transform)(object)val, toggle.Name, toggle.Tip, num2, num, num3);
				Modifiers.Toggle tt = toggle;
				AdminHammerUi.Switch((Transform)(object)parent2, num3 - 14f - 38f, 21f, hashSet.Contains(toggle.Key), delegate(bool on)
				{
					Modifiers.Set(tt, on);
					Flash(tt.Name + ": " + (on ? "on" : "off"));
					Later(PaintWorld);
				});
				num += 72f;
			}
			if (_status.Length > 0)
			{
				AdminHammerUi.Text((Transform)(object)val, _status, "medium", 12f, AdminHammerUi.C("accent"), num2 + 2f, num, num3, 20f, (TextAlignmentOptions)4097);
			}
			val.sizeDelta = new Vector2(0f, num + 30f);
		}

		private static RectTransform WorldRow(Transform parent, string name, string tip, float x, float y, float w)
		{
			//IL_000b: 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_004b: 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)
			Image val = AdminHammerUi.Box(parent, "Row", AdminHammerUi.C("raised"), AdminHammerUi.LineSoft, 10);
			((Graphic)val).raycastTarget = false;
			AdminHammerUi.Place(((Graphic)val).rectTransform, x, y, w, 64f);
			AdminHammerUi.Text(((Component)val).transform, name, "bold", 14f, Color.white, 14f, 10f, 520f, 22f, (TextAlignmentOptions)4097);
			if (!string.IsNullOrEmpty(tip))
			{
				((TMP_Text)AdminHammerUi.Text(((Component)val).transform, tip, "medium", 12.5f, AdminHammerUi.C("mute"), 14f, 32f, 520f, 22f, (TextAlignmentOptions)4097)).overflowMode = (TextOverflowModes)1;
			}
			return ((Graphic)val).rectTransform;
		}

		private void PaintFoot()
		{
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			AdminHammerUi.Clear((Transform)(object)_foot);
			float x = 16f;
			float h = 43f;
			if (Ext != null)
			{
				try
				{
					Ext.Footer?.Invoke(_foot);
				}
				catch (Exception arg)
				{
					Log.Warn($"tab {Ext.Name}: {arg}");
				}
			}
			else if (Ours == Tab.Creatures)
			{
				x = AdminHammerUi.Key((Transform)(object)_foot, "Click", (_target.Length == 0) ? "place in the world" : "select", x, h);
				x = AdminHammerUi.Key((Transform)(object)_foot, "Right click", "close", x, h);
				AdminHammerUi.Key((Transform)(object)_foot, Plugin.KeyName, "open or close", x, h);
			}
			else if (Ours == Tab.Items && _place && _target.Length == 0)
			{
				x = AdminHammerUi.Key((Transform)(object)_foot, "Click", "place in the world", x, h);
				x = AdminHammerUi.Key((Transform)(object)_foot, "Right click", "close", x, h);
				AdminHammerUi.Key((Transform)(object)_foot, "/", "search", x, h);
			}
			else if (Ours == Tab.Items)
			{
				x = AdminHammerUi.Key((Transform)(object)_foot, "Click", "select", x, h);
				x = AdminHammerUi.Key((Transform)(object)_foot, "Double click", "drop", x, h);
				x = AdminHammerUi.Key((Transform)(object)_foot, "Right click", "close", x, h);
				AdminHammerUi.Key((Transform)(object)_foot, "/", "search", x, h);
			}
			else
			{
				AdminHammerUi.Key((Transform)(object)_foot, Plugin.KeyName, "open or close", x, h);
			}
			AdminHammerUi.Place(((TMP_Text)AdminHammerUi.Text((Transform)(object)_foot, "Host or server admin only", "medium", 12.5f, AdminHammerUi.C("mute"), 0f, 0f, 300f, h, (TextAlignmentOptions)4100)).rectTransform, 784f, 0f, 300f, h);
		}

		private void Act()
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: 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)
			Catalog.Entry selected = Selected;
			if (selected == null)
			{
				return;
			}
			if (Ours == Tab.Creatures)
			{
				if (_target.Length == 0)
				{
					if (Placer.Begin(selected.Prefab, _stars, _count, _tamed))
					{
						Close();
					}
					return;
				}
				(string, Vector3, Vector3) tuple = Spawner.Players().FirstOrDefault(((string name, Vector3 pos, Vector3 forward) x) => x.name == _target);
				if (tuple.Item1 == null)
				{
					Flash(_target + " is not online");
					return;
				}
				for (int num = 0; num < _count; num++)
				{
					Spawner.Creature(selected.Prefab, tuple.Item2 + tuple.Item3 * 5f + Vector3.up + Random.insideUnitSphere * 2f, Quaternion.LookRotation(-tuple.Item3), _stars, _tamed);
				}
				Flash(string.Format("Spawned {0} × {1}{2}{3} next to {4}", _count, selected.Name, (_stars > 0) ? (" " + new string('★', _stars)) : "", (_tamed && selected.Tameable) ? ", tamed," : "", _target));
				return;
			}
			int num2 = ((_amount == 0) ? selected.MaxStack : _amount);
			if (_place && _target.Length == 0)
			{
				if (Placer.BeginItem(selected.Prefab, num2))
				{
					Close();
				}
				return;
			}
			if (_target.Length == 0)
			{
				Player localPlayer = Player.m_localPlayer;
				if (!((Object)(object)localPlayer == (Object)null))
				{
					Spawner.Spill(selected.Prefab, num2, ((Component)localPlayer).transform.position, ((Component)localPlayer).transform.forward);
					Flash($"Dropped {num2} × {selected.Name} in front of you");
				}
				return;
			}
			(string, Vector3, Vector3) tuple2 = Spawner.Players().FirstOrDefault(((string name, Vector3 pos, Vector3 forward) x) => x.name == _target);
			if (tuple2.Item1 == null)
			{
				Flash(_target + " is not online");
				return;
			}
			Spawner.Spill(selected.Prefab, num2, tuple2.Item2, tuple2.Item3);
			Flash($"Dropped {num2} × {selected.Name} for {_target}");
		}

		private static void Line(Transform parent, float x, float y, float w, float h = 1f)
		{
			//IL_000b: 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)
			Image obj = AdminHammerUi.Box(parent, "Line", AdminHammerUi.C("glassLine"), AdminHammerUi.NoColor, 1);
			((Graphic)obj).raycastTarget = false;
			AdminHammerUi.Place(((Graphic)obj).rectTransform, x, y, w, h);
		}

		private void Later(Action a)
		{
			((MonoBehaviour)Plugin.Instance).StartCoroutine(After(0.6f, a));
		}

		private IEnumerator After(float s, Action a)
		{
			yield return (object)new WaitForSeconds(s);
			if (Open)
			{
				a();
			}
		}
	}
	internal static class Placer
	{
		internal static bool MenuRequested;

		private static string _prefab;

		private static int _stars;

		private static int _count;

		private static bool _tamed;

		private static bool _item;

		private static int _amount;

		private static GameObject _ghost;

		private static float _yaw;

		private static Vector3 _point;

		private static bool _hit;

		private static int _mask;

		internal static bool Active => _prefab != null;

		internal static string Prefab => _prefab;

		internal static bool Begin(string prefab, int stars, int count, bool tamed = false)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			Stop();
			if (!Hammer.Equipped && !Hammer.Equip())
			{
				Hint("Placing creatures needs the Admin hammer in hand: type /adminhammer");
				return false;
			}
			GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab(prefab) : null);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			_prefab = prefab;
			_stars = stars;
			_count = Mathf.Max(1, count);
			_tamed = tamed;
			_item = false;
			_yaw = (((Object)(object)Player.m_localPlayer != (Object)null) ? (((Component)Player.m_localPlayer).transform.eulerAngles.y + 180f) : 0f);
			_mask = LayerMask.GetMask(new string[6] { "Default", "static_solid", "Default_small", "piece", "terrain", "vehicle" });
			_ghost = Ghost(val);
			Hint("Placing " + Localization.instance.Localize(val.GetComponent<Character>()?.m_name ?? prefab) + " - click to place, right click for the menu");
			return true;
		}

		internal static bool BeginItem(string prefab, int amount)
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			Stop();
			if (!Hammer.Equipped && !Hammer.Equip())
			{
				Hint("Placing items needs the Admin hammer in hand: type /adminhammer");
				return false;
			}
			GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(prefab) : null);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			_prefab = prefab;
			_amount = Mathf.Max(1, amount);
			_item = true;
			_yaw = (((Object)(object)Player.m_localPlayer != (Object)null) ? ((Component)Player.m_localPlayer).transform.eulerAngles.y : 0f);
			_mask = LayerMask.GetMask(new string[6] { "Default", "static_solid", "Default_small", "piece", "terrain", "vehicle" });
			_ghost = Ghost(val);
			Hint($"Placing {_amount} × {Localization.instance.Localize(val.GetComponent<ItemDrop>()?.m_itemData.m_shared.m_name ?? prefab)} - click to place, right click for the menu");
			return true;
		}

		internal static void Stop()
		{
			if ((Object)(object)_ghost != (Object)null)
			{
				Object.Destroy((Object)(object)_ghost);
			}
			_ghost = null;
			_prefab = null;
		}

		internal static void Tick()
		{
			//IL_0041: 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_0064: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: 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_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: 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_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: 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_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			if (!Active)
			{
				return;
			}
			if ((Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)GameCamera.instance == (Object)null)
			{
				Stop();
				return;
			}
			if (!Hammer.Equipped)
			{
				Stop();
				return;
			}
			Transform transform = ((Component)GameCamera.instance).transform;
			RaycastHit val = default(RaycastHit);
			_hit = Physics.Raycast(transform.position, transform.forward, ref val, 60f, _mask);
			_point = ((RaycastHit)(ref val)).point;
			float axis = Input.GetAxis("Mouse ScrollWheel");
			if (axis != 0f)
			{
				_yaw += ((axis > 0f) ? 22.5f : (-22.5f));
			}
			if ((Object)(object)_ghost != (Object)null)
			{
				_ghost.SetActive(_hit);
				_ghost.transform.SetPositionAndRotation(_point, Quaternion.Euler(0f, _yaw, 0f));
			}
			if (Input.GetMouseButtonDown(1))
			{
				Stop();
				MenuRequested = true;
			}
			else
			{
				if (Menu.IsVisible())
				{
					return;
				}
				if (_hit && Input.GetMouseButtonDown(0) && _item)
				{
					Spawner.Place(_prefab, _amount, _point, Quaternion.Euler(0f, _yaw, 0f));
				}
				else
				{
					if (!_hit || !Input.GetMouseButtonDown(0))
					{
						return;
					}
					for (int i = 0; i < _count; i++)
					{
						Vector3 val3;
						if (i != 0)
						{
							Vector3 val2 = Vector3.ProjectOnPlane(Random.insideUnitSphere, Vector3.up);
							val3 = ((Vector3)(ref val2)).normalized * Random.Range(1f, 2.5f);
						}
						else
						{
							val3 = Vector3.zero;
						}
						Vector3 val4 = val3;
						Spawner.Creature(_prefab, _point + val4 + Vector3.up * 0.2f, Quaternion.Euler(0f, _yaw, 0f), _stars, _tamed);
					}
				}
			}
		}

		private static GameObject Ghost(GameObject prefab)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			GameObject val = new GameObject("AdminHammerGhostHolder");
			val.SetActive(false);
			GameObject val2 = Object.Instantiate<GameObject>(((Object)(object)prefab.transform.Find("Visual") != (Object)null) ? ((Component)prefab.transform.Find("Visual")).gameObject : prefab, val.transform);
			MonoBehaviour[] componentsInChildren = val2.GetComponentsInChildren<MonoBehaviour>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
			}
			Collider[] componentsInChildren2 = val2.GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren2[i]);
			}
			Rigidbody[] componentsInChildren3 = val2.GetComponentsInChildren<Rigidbody>(true);
			for (int i = 0; i < componentsInChildren3.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren3[i]);
			}
			Animator[] componentsInChildren4 = val2.GetComponentsInChildren<Animator>(true);
			for (int i = 0; i < componentsInChildren4.Length; i++)
			{
				((Behaviour)componentsInChildren4[i]).enabled = false;
			}
			val2.transform.SetParent((Transform)null, false);
			((Object)val2).name = "AdminHammerGhost";
			Object.Destroy((Object)(object)val);
			val2.SetActive(true);
			return val2;
		}

		private static void Hint(string text)
		{
			MessageHud instance = MessageHud.instance;
			if (instance != null)
			{
				instance.ShowMessage((MessageType)1, text, 0, (Sprite)null, false, true);
			}
		}
	}
	[BepInPlugin("jatify.adminhammer", "AdminHammer", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "jatify.adminhammer";

		internal static Plugin Instance;

		private static ConfigEntry<KeyCode> _key;

		private static Panel _panel;

		private static bool _openedByHammer;

		private Harmony _harmony;

		private static int _closedFrame = -1;

		private static readonly List<RaycastResult> _hits = new List<RaycastResult>();

		internal static bool PanelOpen
		{
			get
			{
				if (_panel != null)
				{
					return _panel.Open;
				}
				return false;
			}
		}

		internal static Panel CurrentPanel => _panel;

		internal static string KeyName
		{
			get
			{
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				if (_key == null)
				{
					return "Insert";
				}
				return ((object)_key.Value/*cast due to .constrained prefix*/).ToString();
			}
		}

		internal static bool EscClose()
		{
			if (_panel == null || !_panel.Open)
			{
				return false;
			}
			_panel.Close();
			_closedFrame = Time.frameCount;
			return true;
		}

		private static bool OnRightAction()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			//IL_004b: 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)
			EventSystem current = EventSystem.current;
			if ((Object)(object)current == (Object)null)
			{
				return false;
			}
			_hits.Clear();
			current.RaycastAll(new PointerEventData(current)
			{
				position = Vector2.op_Implicit(Input.mousePosition)
			}, _hits);
			foreach (RaycastResult hit in _hits)
			{
				RaycastResult current2 = hit;
				AdminHammerUi.Clicks componentInParent = ((RaycastResult)(ref current2)).gameObject.GetComponentInParent<AdminHammerUi.Clicks>();
				if ((Object)(object)componentInParent != (Object)null && componentInParent.Right != null)
				{
					return true;
				}
			}
			return false;
		}

		private void Awake()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			Instance = this;
			Log.Bind(((BaseUnityPlugin)this).Logger);
			_key = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "Key", (KeyCode)277, "Opens and closes the admin panel. Not F9 (Valheim cycles the controller layout).");
			_harmony = new Harmony("jatify.adminhammer");
			_harmony.PatchAll(typeof(Plugin).Assembly);
			Hammer.Register();
			if (!CommandManager.Instance.CustomCommands.Any((ConsoleCommand c) => c.Name == "adminhammer"))
			{
				CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new HammerCommand());
			}
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Placer.Stop();
			if (_panel != null)
			{
				_panel.Destroy();
			}
			_panel = null;
		}

		private void Update()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Hud.instance == (Object)null || (Object)(object)Player.m_localPlayer == (Object)null)
			{
				if (_panel != null && !Object.op_Implicit((Object)(object)Hud.instance))
				{
					_panel = null;
				}
				return;
			}
			if (_panel == null)
			{
				_panel = new Panel(Hud.instance.m_rootObject.transform);
			}
			if (Input.GetKeyDown(_key.Value) && !TypingPatch.Active && !Console.IsVisible() && (!((Object)(object)Chat.instance != (Object)null) || !Chat.instance.HasFocus()))
			{
				if (!Spawner.CanAdmin)
				{
					MessageHud instance = MessageHud.instance;
					if (instance != null)
					{
						instance.ShowMessage((MessageType)2, "Admin panel: you are not an admin on this server", 0, (Sprite)null, false, true);
					}
				}
				else
				{
					Placer.Stop();
					_panel.Toggle();
				}
			}
			if (_panel.Open && Input.GetMouseButtonDown(1) && !TypingPatch.Active && !OnRightAction())
			{
				_panel.Close();
				_closedFrame = Time.frameCount;
			}
			if (Hammer.Equipped && !_panel.Open && Time.frameCount != _closedFrame && !Placer.Active && Input.GetMouseButtonDown(1) && !Menu.IsVisible() && !InventoryGui.IsVisible() && !Minimap.IsOpen() && !Console.IsVisible() && (!((Object)(object)Chat.instance != (Object)null) || !Chat.instance.HasFocus()))
			{
				if (!Spawner.CanAdmin)
				{
					MessageHud instance2 = MessageHud.instance;
					if (instance2 != null)
					{
						instance2.ShowMessage((MessageType)2, "Admin hammer: you are not an admin on this server", 0, (Sprite)null, false, true);
					}
				}
				else
				{
					_panel.Show();
					_openedByHammer = true;
				}
			}
			if (_openedByHammer && (!_panel.Open || !Hammer.Equipped))
			{
				if (_panel.Open)
				{
					_panel.Close();
				}
				_openedByHammer = false;
			}
			_panel.Tick();
			Placer.Tick();
			if (Placer.MenuRequested)
			{
				Placer.MenuRequested = false;
				_panel.Show();
				_openedByHammer = Hammer.Equipped;
			}
		}
	}
	[HarmonyPatch(typeof(Menu), "Update")]
	internal static class EscPatch
	{
		private static bool Prefix()
		{
			if (ZInput.GetKeyDown((KeyCode)27, true))
			{
				return !Plugin.EscClose();
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Menu), "IsVisible")]
	internal static class MenuVisiblePatch
	{
		private static void Postfix(ref bool __result)
		{
			if (Plugin.PanelOpen)
			{
				__result = true;
			}
		}
	}
	[HarmonyPatch(typeof(GameCamera), "UpdateMouseCapture")]
	internal static class PanelCursorPatch
	{
		private static bool Prefix()
		{
			if (!Plugin.PanelOpen)
			{
				return true;
			}
			ZCursor.LockState = (CursorLockMode)0;
			ZCursor.Show();
			return false;
		}
	}
	[HarmonyPatch]
	internal static class TypingPatch
	{
		internal static bool Active
		{
			get
			{
				EventSystem current = EventSystem.current;
				GameObject val = ((current != null) ? current.currentSelectedGameObject : null);
				Panel currentPanel = Plugin.CurrentPanel;
				if ((Object)(object)val == (Object)null || currentPanel == null || !currentPanel.Open)
				{
					return false;
				}
				TMP_InputField component = val.GetComponent<TMP_InputField>();
				if ((Object)(object)component != (Object)null && component.isFocused)
				{
					return val.transform.IsChildOf(currentPanel.Root);
				}
				return false;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Chat), "HasFocus")]
		private static void ChatFocus(ref bool __result)
		{
			if (!__result && Active)
			{
				__result = true;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(TextInput), "IsVisible")]
		private static void TextVisible(ref bool __result)
		{
			if (!__result && Active)
			{
				__result = true;
			}
		}
	}
	[HarmonyPatch(typeof(Humanoid), "StartAttack")]
	internal static class NoAttackWhilePlacingPatch
	{
		private static bool Prefix(Humanoid __instance, ref bool __result)
		{
			if (!Placer.Active || (Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
	internal static class Spawner
	{
		internal unsafe static bool CanAdmin
		{
			get
			{
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)ZNet.instance == (Object)null)
				{
					return false;
				}
				if (ZNet.instance.LocalPlayerIsAdminOrHost())
				{
					return true;
				}
				PlatformUserID userId = UserInfo.GetLocalUser().UserId;
				List<string> adminList = ZNet.instance.GetAdminList();
				if (adminList != null)
				{
					if (!adminList.Contains(((object)(*(PlatformUserID*)(&userId))/*cast due to .constrained prefix*/).ToString()))
					{
						return adminList.Contains(userId.m_userID.ToString());
					}
					return true;
				}
				return false;
			}
		}

		internal static void Creature(string prefab, Vector3 pos, Quaternion rot, int stars, bool tamed = false)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab(prefab) : null);
			if ((Object)(object)val == (Object)null)
			{
				Log.Warn("no prefab " + prefab);
				return;
			}
			Character component = Object.Instantiate<GameObject>(val, pos, rot).GetComponent<Character>();
			if ((Object)(object)component != (Object)null && stars > 0)
			{
				component.SetLevel(stars + 1);
			}
			if ((Object)(object)component != (Object)null && tamed && (Object)(object)((Component)component).GetComponent<Tameable>() != (Object)null)
			{
				component.SetTamed(true);
			}
		}

		internal static void Place(string prefab, int amount, Vector3 pos, Quaternion rot)
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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)
			GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(prefab) : null);
			ItemDrop val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null);
			if ((Object)(object)val2 == (Object)null)
			{
				Log.Warn("no item " + prefab);
				return;
			}
			ItemData val3 = val2.m_itemData.Clone();
			val3.m_dropPrefab = val;
			int num = Mathf.Max(1, val3.m_shared.m_maxStackSize);
			int num2 = 0;
			int num3 = amount;
			while (num3 > 0)
			{
				ItemDrop.DropItem(val3, Mathf.Min(num3, num), pos + Vector3.up * (0.15f + 0.25f * (float)num2), rot);
				num3 -= num;
				num2++;
			}
		}

		internal static void Spill(string prefab, int amount, Vector3 at, Vector3 forward)
		{
			//IL_006e: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: 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_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to