Decompiled source of Corebound v0.1.0

plugins/Corebound.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GUIFramework;
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.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[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 Corebound
{
	public static class AdminNet
	{
		private const string HelloRpc = "CB_AdmHello";

		private const string IsRpc = "CB_AdmIs";

		private const string ActRpc = "CB_AdmAct";

		private const string DataRpc = "CB_AdmData";

		private const string NoteRpc = "CB_AdmNote";

		private const string HealRpc = "CB_AdmHeal";

		private const string FreezeRpc = "CB_AdmFreeze";

		private const string EnvRpc = "CB_AdmEnv";

		private const string PurgeRpc = "CB_AdmPurge";

		private const string FixRpc = "CB_AdmFix";

		public static bool IsAdmin;

		public static bool Frozen;

		public static readonly Dictionary<string, string> Data = new Dictionary<string, string>();

		private static bool s_registered;

		private static ZRoutedRpc s_rpcFor;

		private static readonly Dictionary<long, float> s_joined = new Dictionary<long, float>();

		private static readonly HashSet<long> s_frozen = new HashSet<long>();

		private static readonly List<string> s_log = new List<string>();

		private static float s_started = -1f;

		private static string LogFile => Path.Combine(Paths.ConfigPath, "corebound_adminlog_" + ((ZNet.World != null) ? ZNet.World.m_uid.ToString() : "world") + ".txt");

		public static event Action Changed;

		public static void Register()
		{
			if (ZRoutedRpc.instance == null || s_rpcFor == ZRoutedRpc.instance)
			{
				return;
			}
			s_rpcFor = ZRoutedRpc.instance;
			s_registered = true;
			if (s_started < 0f)
			{
				s_started = Time.realtimeSinceStartup;
			}
			ZRoutedRpc.instance.Register("CB_AdmHello", (Action<long>)OnHello);
			ZRoutedRpc.instance.Register<bool, bool>("CB_AdmIs", (Action<long, bool, bool>)delegate(long s, bool admin, bool frozen)
			{
				if (FromServer(s))
				{
					IsAdmin = admin;
					SetFrozen(frozen);
					AdminNet.Changed?.Invoke();
				}
			});
			ZRoutedRpc.instance.Register<string, string, string>("CB_AdmAct", (Action<long, string, string, string>)OnAct);
			ZRoutedRpc.instance.Register<string, string>("CB_AdmData", (Action<long, string, string>)delegate(long s, string kind, string text)
			{
				if (FromServer(s))
				{
					Data[kind] = text;
					AdminNet.Changed?.Invoke();
				}
			});
			ZRoutedRpc.instance.Register<string>("CB_AdmNote", (Action<long, string>)delegate(long s, string msg)
			{
				if (FromServer(s))
				{
					Player localPlayer = Player.m_localPlayer;
					if (localPlayer != null)
					{
						((Character)localPlayer).Message((MessageType)1, msg, 0, (Sprite)null, false);
					}
				}
			});
			ZRoutedRpc.instance.Register("CB_AdmHeal", (Action<long>)delegate(long s)
			{
				if (FromServer(s) && (Object)(object)Player.m_localPlayer != (Object)null)
				{
					((Character)Player.m_localPlayer).Heal(((Character)Player.m_localPlayer).GetMaxHealth(), true);
					((Character)Player.m_localPlayer).AddStamina(9999f);
				}
			});
			ZRoutedRpc.instance.Register<bool>("CB_AdmFreeze", (Action<long, bool>)delegate(long s, bool on)
			{
				if (FromServer(s))
				{
					SetFrozen(on);
				}
			});
			ZRoutedRpc.instance.Register<string>("CB_AdmEnv", (Action<long, string>)delegate(long s, string env)
			{
				if (FromServer(s) && (Object)(object)EnvMan.instance != (Object)null)
				{
					EnvMan.instance.SetForceEnvironment(env);
				}
			});
			ZRoutedRpc.instance.Register<long, float>("CB_AdmPurge", (Action<long, long, float>)delegate(long s, long creator, float r)
			{
				if (FromServer(s))
				{
					Purge(creator, r);
				}
			});
			ZRoutedRpc.instance.Register("CB_AdmFix", (Action<long>)delegate(long s)
			{
				if (FromServer(s))
				{
					FixCores();
				}
			});
			if ((Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer())
			{
				LoadLog();
			}
		}

		private static bool FromServer(long sender)
		{
			if (ZRoutedRpc.instance != null)
			{
				return sender == ZRoutedRpc.instance.GetServerPeerID();
			}
			return false;
		}

		public static void Hello()
		{
			ZRoutedRpc instance = ZRoutedRpc.instance;
			if (instance != null)
			{
				instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "CB_AdmHello", Array.Empty<object>());
			}
		}

		public static void Act(string action, string a = "", string b = "")
		{
			ZRoutedRpc instance = ZRoutedRpc.instance;
			if (instance != null)
			{
				instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "CB_AdmAct", new object[3]
				{
					action,
					a ?? "",
					b ?? ""
				});
			}
		}

		private static void SetFrozen(bool on)
		{
			if (Frozen != on)
			{
				Frozen = on;
				Player localPlayer = Player.m_localPlayer;
				if (localPlayer != null)
				{
					((Character)localPlayer).Message((MessageType)2, on ? "An admin has frozen you in place." : "You can move again.", 0, (Sprite)null, false);
				}
			}
		}

		private static void Purge(long creator, float r)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			int num = 0;
			foreach (Piece item in SceneCache.All<Piece>(0f))
			{
				if ((Object)(object)item == (Object)null || item.GetCreator() != creator)
				{
					continue;
				}
				Vector3 val = ((Component)item).transform.position - ((Component)localPlayer).transform.position;
				if (!(((Vector3)(ref val)).sqrMagnitude > r * r))
				{
					ZNetView component = ((Component)item).GetComponent<ZNetView>();
					if (!((Object)(object)component == (Object)null) && component.IsValid())
					{
						component.ClaimOwnership();
						ZNetScene.instance.Destroy(((Component)item).gameObject);
						num++;
					}
				}
			}
			((Character)localPlayer).Message((MessageType)2, $"Removed {num} pieces.", 0, (Sprite)null, false);
			Act("note", $"purge done: {num} pieces removed");
		}

		private static void FixCores()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			int num = 0;
			foreach (ItemData allItem in ((Humanoid)localPlayer).GetInventory().GetAllItems())
			{
				if (allItem.m_customData.Remove("cb.ko"))
				{
					num++;
				}
			}
			((Humanoid)localPlayer).GetInventory().Changed(false, false);
			((Character)localPlayer).Message((MessageType)2, (num > 0) ? "An admin fixed your Soul Cores." : "Your Soul Cores were fine.", 0, (Sprite)null, false);
		}

		private static bool Admin(long sender)
		{
			if ((Object)(object)ZNet.instance == (Object)null)
			{
				return false;
			}
			if (sender == ZNet.GetUID())
			{
				return true;
			}
			ZNetPeer peer = ZNet.instance.GetPeer(sender);
			if (peer != null)
			{
				return ZNet.instance.ListContainsId(ZNet.instance.m_adminList, peer.m_rpc.GetSocket().GetHostName());
			}
			return false;
		}

		private static long PlayerIdOf(long uid, out string name, out Vector3 pos, out ZDO z)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			name = null;
			pos = Vector3.zero;
			z = null;
			if (uid == ZNet.GetUID() && (Object)(object)Player.m_localPlayer != (Object)null)
			{
				name = Player.m_localPlayer.GetPlayerName();
				pos = ((Component)Player.m_localPlayer).transform.position;
				z = ((Character)Player.m_localPlayer).m_nview.GetZDO();
				return Player.m_localPlayer.GetPlayerID();
			}
			ZNetPeer peer = ZNet.instance.GetPeer(uid);
			if (peer == null)
			{
				return 0L;
			}
			z = ZDOMan.instance.GetZDO(peer.m_characterID);
			name = peer.m_playerName;
			pos = ((z != null) ? z.GetPosition() : peer.m_refPos);
			if (z == null)
			{
				return 0L;
			}
			return z.GetLong(ZDOVars.s_playerID, 0L);
		}

		private static IEnumerable<long> Uids()
		{
			if ((Object)(object)Player.m_localPlayer != (Object)null && ZNet.instance.IsServer())
			{
				yield return ZNet.GetUID();
			}
			foreach (ZNetPeer peer in ZNet.instance.GetPeers())
			{
				if (peer.m_characterID != ZDOID.None)
				{
					yield return peer.m_uid;
				}
			}
		}

		private static void OnHello(long sender)
		{
			if (!((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer())
			{
				if (!s_joined.ContainsKey(sender))
				{
					s_joined[sender] = Time.realtimeSinceStartup;
				}
				string name;
				Vector3 pos;
				ZDO z;
				long item = PlayerIdOf(sender, out name, out pos, out z);
				ZRoutedRpc.instance.InvokeRoutedRPC(sender, "CB_AdmIs", new object[2]
				{
					Admin(sender),
					s_frozen.Contains(item)
				});
			}
		}

		private static void Reply(long to, string kind, string text)
		{
			ZRoutedRpc.instance.InvokeRoutedRPC(to, "CB_AdmData", new object[2]
			{
				kind,
				text ?? ""
			});
		}

		private static void Note(long to, string msg)
		{
			ZRoutedRpc.instance.InvokeRoutedRPC(to, "CB_AdmNote", new object[1] { msg });
		}

		private static void OnAct(long sender, string action, string a, string b)
		{
			//IL_0a7a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a88: Unknown result type (might be due to invalid IL or missing references)
			//IL_0728: Unknown result type (might be due to invalid IL or missing references)
			//IL_0729: Unknown result type (might be due to invalid IL or missing references)
			//IL_0733: Unknown result type (might be due to invalid IL or missing references)
			//IL_0738: Unknown result type (might be due to invalid IL or missing references)
			//IL_073d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0742: Unknown result type (might be due to invalid IL or missing references)
			//IL_074f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c0f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0609: Unknown result type (might be due to invalid IL or missing references)
			//IL_060b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0615: Unknown result type (might be due to invalid IL or missing references)
			//IL_061a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0627: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0949: Unknown result type (might be due to invalid IL or missing references)
			//IL_094e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0969: Unknown result type (might be due to invalid IL or missing references)
			//IL_0975: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0549: Unknown result type (might be due to invalid IL or missing references)
			//IL_0558: Unknown result type (might be due to invalid IL or missing references)
			//IL_0567: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer())
			{
				return;
			}
			if (!Admin(sender))
			{
				Note(sender, "Admins only.");
				return;
			}
			PlayerIdOf(sender, out var name, out var pos, out var z);
			long.TryParse(a, out var result);
			string text = null;
			Vector3 pos2;
			switch (action)
			{
			case "players":
			{
				StringBuilder stringBuilder2 = new StringBuilder();
				foreach (long item2 in Uids())
				{
					string name3;
					Vector3 pos3;
					ZDO z2;
					long num3 = PlayerIdOf(item2, out name3, out pos3, out z2);
					if (num3 != 0L)
					{
						float num4 = ((z2 != null) ? z2.GetFloat(ZDOVars.s_health, 0f) : 0f);
						float value;
						float num5 = (s_joined.TryGetValue(item2, out value) ? (Time.realtimeSinceStartup - value) : 0f);
						string text2 = ((WorldGenerator.instance != null) ? ((object)WorldGenerator.instance.GetBiome(pos3)/*cast due to .constrained prefix*/).ToString() : "");
						stringBuilder2.Append(string.Format("{0}|{1}|{2}|{3}|{4:0}|{5:0}|{6:0}|{7:0}|{8:0}|{9}|{10}|{11}\n", item2, num3, name3, Guilds.Of(num3)?.Tag ?? "", pos3.x, pos3.y, pos3.z, num4, num5, s_frozen.Contains(num3) ? 1 : 0, text2, BossProgress.Short(z2)));
					}
				}
				Reply(sender, "players", stringBuilder2.ToString());
				return;
			}
			case "goto":
			{
				PlayerIdOf(result, out var name5, out var pos4, out z);
				ZRoutedRpc.instance.InvokeRoutedRPC(sender, "RPC_TeleportPlayer", new object[3]
				{
					pos4 + Vector3.up * 1f,
					Quaternion.identity,
					true
				});
				text = "went to " + name5;
				break;
			}
			case "gotopos":
			{
				string[] array = a.Split(new char[1] { ',' });
				if (array.Length < 2 || !float.TryParse(array[0], out var result3) || !float.TryParse(array[1], out var result4))
				{
					return;
				}
				float num6 = ((WorldGenerator.instance != null) ? (WorldGenerator.instance.GetHeight(result3, result4) + 2f) : 50f);
				ZRoutedRpc.instance.InvokeRoutedRPC(sender, "RPC_TeleportPlayer", new object[3]
				{
					(object)new Vector3(result3, num6, result4),
					Quaternion.identity,
					true
				});
				text = $"went to ({result3:0}, {result4:0})";
				break;
			}
			case "bring":
			{
				PlayerIdOf(result, out var name4, out pos2, out z);
				ZRoutedRpc.instance.InvokeRoutedRPC(result, "RPC_TeleportPlayer", new object[3]
				{
					pos + Vector3.forward * 2f + Vector3.up,
					Quaternion.identity,
					true
				});
				text = "brought " + name4;
				break;
			}
			case "heal":
			{
				PlayerIdOf(result, out var name2, out pos2, out z);
				ZRoutedRpc.instance.InvokeRoutedRPC(result, "CB_AdmHeal", Array.Empty<object>());
				text = "healed " + name2;
				break;
			}
			case "fixcores":
			{
				PlayerIdOf(result, out var name6, out pos2, out z);
				ZRoutedRpc.instance.InvokeRoutedRPC(result, "CB_AdmFix", Array.Empty<object>());
				text = "fixed " + name6 + "'s Soul Cores";
				break;
			}
			case "freeze":
			{
				string name7;
				long item = PlayerIdOf(result, out name7, out pos2, out z);
				bool flag = b == "1";
				if (flag)
				{
					s_frozen.Add(item);
				}
				else
				{
					s_frozen.Remove(item);
				}
				ZRoutedRpc.instance.InvokeRoutedRPC(result, "CB_AdmFreeze", new object[1] { flag });
				text = (flag ? "froze" : "unfroze") + " " + name7;
				break;
			}
			case "kick":
				ZNet.instance.Kick(a);
				text = "kicked " + a;
				break;
			case "ban":
				ZNet.instance.Ban(a);
				text = "banned " + a;
				break;
			case "unban":
				ZNet.instance.Unban(a);
				text = "unbanned " + a;
				break;
			case "bans":
				Reply(sender, "bans", string.Join("\n", ZNet.instance.m_bannedList.GetList()));
				return;
			case "bases":
			{
				StringBuilder stringBuilder3 = new StringBuilder();
				int stableHashCode = StringExtensionMethods.GetStableHashCode("guard_stone");
				int stableHashCode2 = StringExtensionMethods.GetStableHashCode("CB_TownShrine");
				foreach (ZDO value2 in ZDOMan.instance.m_objectsByID.Values)
				{
					if (value2 != null)
					{
						int prefab = value2.GetPrefab();
						if ((prefab == stableHashCode || prefab == stableHashCode2) && value2.GetLong(ZDOVars.s_creator, 0L) == result)
						{
							Vector3 position = value2.GetPosition();
							stringBuilder3.Append(string.Format("{0}|{1:0}|{2:0}\n", (prefab == stableHashCode) ? "Ward" : "Town Shrine", position.x, position.z));
						}
					}
				}
				Reply(sender, "bases", stringBuilder3.ToString());
				return;
			}
			case "wardlog":
				Reply(sender, "wardlog", string.Join("\n", Protection.LogLines.AsEnumerable().Reverse().Take(200)));
				return;
			case "adminlog":
				Reply(sender, "adminlog", string.Join("\n", s_log.AsEnumerable().Reverse().Take(200)));
				return;
			case "purge":
			{
				float.TryParse(b, out var result2);
				ZRoutedRpc.instance.InvokeRoutedRPC(sender, "CB_AdmPurge", new object[2]
				{
					result,
					Mathf.Clamp(result2, 5f, 60f)
				});
				text = $"removed player {result}'s builds within {result2:0} m of ({pos.x:0}, {pos.z:0})";
				break;
			}
			case "resetwards":
			{
				string pre = "cb_ward_" + result + "_";
				foreach (string item3 in (from k in ZoneSystem.instance.GetGlobalKeys()
					where k.StartsWith(pre)
					select k).ToList())
				{
					ZoneSystem.instance.RemoveGlobalKey(item3);
				}
				text = $"reset the ward count of player {result}";
				break;
			}
			case "g_tag":
			case "g_name":
			case "g_lead":
			case "g_kick":
			case "g_disband":
			{
				string text3 = Guilds.AdminDo(action, a, b);
				if (text3 != null)
				{
					Note(sender, text3);
					return;
				}
				text = action.Substring(2) + " guild [" + a + "] " + b;
				break;
			}
			case "respawn":
				Note(sender, WorldRespawn.Command("now"));
				text = "world respawn now";
				break;
			case "morning":
			{
				EnvMan instance3 = EnvMan.instance;
				if (instance3 != null)
				{
					instance3.SkipToMorning();
				}
				text = "skipped to morning";
				break;
			}
			case "weather":
				ZRoutedRpc.instance.InvokeRoutedRPC(0L, "CB_AdmEnv", new object[1] { a });
				text = (string.IsNullOrEmpty(a) ? "weather back to normal" : ("weather set to " + a));
				break;
			case "raid":
			{
				RandEventSystem instance2 = RandEventSystem.instance;
				if (instance2 != null)
				{
					instance2.SetRandomEventByName(a, pos);
				}
				text = "started event " + a;
				break;
			}
			case "stopraid":
			{
				RandEventSystem instance = RandEventSystem.instance;
				if (instance != null)
				{
					instance.ResetRandomEvent();
				}
				text = "stopped the event";
				break;
			}
			case "announce":
				ZRoutedRpc.instance.InvokeRoutedRPC(0L, "ShowMessage", new object[2] { 2, a });
				text = "announced \"" + a + "\"";
				break;
			case "info":
			{
				float num2 = Time.realtimeSinceStartup - s_started;
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append($"Players online: {Uids().Count()}\n");
				stringBuilder.Append($"Up for: {(int)(num2 / 3600f)} h {(int)(num2 % 3600f / 60f)} min\n");
				stringBuilder.Append($"World objects: {ZDOMan.instance.m_objectsByID.Count}\n");
				stringBuilder.Append($"Day: {(((Object)(object)EnvMan.instance != (Object)null) ? EnvMan.instance.GetDay() : 0)}\n");
				stringBuilder.Append($"Guilds: {Guilds.All.Count}\n");
				stringBuilder.Append(string.Format("Protection: {0}, ward limit {1}, buffer {2:0} m\n", Plugin.ProtectionEnabled.Value ? "on" : "off", Plugin.MaxWards.Value, Plugin.WardBuffer.Value));
				stringBuilder.Append($"Respawn every {Plugin.RespawnDays.Value:0.#} days · worker output x{Plugin.WorkerOutput.Value:0.##} · expeditions {Plugin.ExpeditionSeconds.Value:0} s\n");
				stringBuilder.Append($"Stack size {Plugin.StackSize.Value} · capture {Plugin.CaptureChanceFullHealth.Value:P0}-{Plugin.CaptureChanceNearDeath.Value:P0}");
				Reply(sender, "info", stringBuilder.ToString());
				return;
			}
			case "trips":
			{
				int num = 0;
				foreach (ZDO value3 in ZDOMan.instance.m_objectsByID.Values)
				{
					if (value3 != null && value3.GetLong(OffscreenTrips.ZAway, 0L) > 1)
					{
						value3.Set(OffscreenTrips.ZAway, 1L);
						num++;
					}
				}
				Note(sender, $"{num} workers on off-screen trips will come home now.");
				text = $"finished {num} worker trips";
				break;
			}
			case "tool":
				text = "used tool: " + a + " " + b;
				break;
			case "note":
				text = a;
				break;
			default:
				Note(sender, "Unknown admin action.");
				return;
			}
			if (text != null)
			{
				Log(name, text);
			}
		}

		private static void LoadLog()
		{
			s_log.Clear();
			try
			{
				if (File.Exists(LogFile))
				{
					s_log.AddRange(File.ReadAllLines(LogFile).Reverse().Take(500)
						.Reverse());
				}
			}
			catch
			{
			}
		}

		private static void Log(string who, string what)
		{
			string text = $"{DateTime.Now:yyyy-MM-dd HH:mm} {who}: {what}";
			s_log.Add(text);
			if (s_log.Count > 500)
			{
				s_log.RemoveRange(0, s_log.Count - 500);
			}
			try
			{
				File.AppendAllText(LogFile, text + "\n");
			}
			catch
			{
			}
			Plugin.Log.LogInfo((object)("admin: " + text));
		}
	}
	[HarmonyPatch(typeof(Game), "Start")]
	public static class AdminNetRegister
	{
		[HarmonyPostfix]
		private static void Postfix()
		{
			AdminNet.Register();
		}
	}
	[HarmonyPatch(typeof(Player), "OnSpawned")]
	public static class AdminNetHello
	{
		[HarmonyPostfix]
		private static void Postfix(Player __instance)
		{
			if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				AdminNet.Hello();
			}
		}
	}
	[HarmonyPatch(typeof(Player), "SetControls")]
	public static class AdminFreeze
	{
		[HarmonyPrefix]
		private static void Prefix(Player __instance, ref Vector3 movedir, ref bool attack, ref bool attackHold, ref bool secondaryAttack, ref bool secondaryAttackHold, ref bool jump, ref bool run, ref bool autoRun, ref bool dodge)
		{
			//IL_0016: 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)
			if (AdminNet.Frozen && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
			{
				movedir = Vector3.zero;
				attack = (attackHold = (secondaryAttack = (secondaryAttackHold = (jump = (run = (autoRun = (dodge = false)))))));
			}
		}
	}
	public static class AdminPanel
	{
		private enum Page
		{
			Players,
			Protection,
			Guilds,
			World,
			Tools
		}

		private class Row
		{
			public long Uid;

			public long Id;

			public string Name;

			public string Tag;

			public string Biome;

			public string Bosses = "";

			public float X;

			public float Y;

			public float Z;

			public float Hp;

			public float On;

			public bool Frozen;
		}

		private class Reply : TextReceiver
		{
			public Action<string> Done;

			public string GetText()
			{
				return "";
			}

			public void SetText(string text)
			{
				if (!string.IsNullOrWhiteSpace(text))
				{
					string t = text.Trim();
					s_afterInput = delegate
					{
						Done?.Invoke(t);
					};
				}
			}
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__ToggleGhost;

			public static UnityAction <1>__Request;
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__17_0;

			public static Action <>9__17_1;

			public static Action <>9__17_2;

			public static Func<string, bool> <>9__29_9;

			public static Func<string, bool> <>9__29_0;

			public static UnityAction <>9__31_0;

			public static UnityAction <>9__31_1;

			public static Func<string, bool> <>9__31_3;

			public static Func<string, bool> <>9__31_2;

			public static Func<KeyValuePair<string, (int n, long id, string pos)>, int> <>9__31_4;

			public static Func<Guilds.Guild, string> <>9__33_0;

			public static Func<Guilds.Guild, bool> <>9__33_1;

			public static Func<Guilds.Member, Guilds.Rank> <>9__33_8;

			public static UnityAction <>9__35_0;

			public static UnityAction <>9__35_1;

			public static Action<string> <>9__35_6;

			public static UnityAction <>9__35_2;

			public static Func<RandomEvent, bool> <>9__35_3;

			public static Func<RandomEvent, string> <>9__35_4;

			public static UnityAction <>9__35_11;

			public static UnityAction <>9__35_5;

			public static Func<string, bool> <>9__36_15;

			public static Action<string> <>9__36_14;

			public static UnityAction <>9__36_0;

			public static UnityAction <>9__36_1;

			public static UnityAction <>9__36_2;

			public static UnityAction <>9__36_3;

			public static UnityAction <>9__36_4;

			public static UnityAction <>9__36_5;

			public static UnityAction <>9__36_6;

			public static UnityAction <>9__36_7;

			public static UnityAction <>9__36_8;

			public static UnityAction <>9__36_9;

			public static UnityAction <>9__36_10;

			public static UnityAction <>9__36_11;

			public static Action<string> <>9__36_16;

			public static UnityAction <>9__36_12;

			public static UnityAction <>9__36_13;

			internal void <Build>b__17_0()
			{
				s_open = true;
				s_dirty = true;
				GuildPanel.Close();
			}

			internal void <Build>b__17_1()
			{
				s_dirty = true;
			}

			internal void <Build>b__17_2()
			{
				if (s_page == Page.Guilds)
				{
					s_dirty = true;
				}
			}

			internal bool <Players>b__29_9(string l)
			{
				return l.Contains("|");
			}

			internal bool <Players>b__29_0(string l)
			{
				return l.Trim().Length > 0;
			}

			internal void <ProtectionPage>b__31_0()
			{
				s_showAdminLog = false;
				Request();
			}

			internal void <ProtectionPage>b__31_1()
			{
				s_showAdminLog = true;
				Request();
			}

			internal bool <ProtectionPage>b__31_3(string l)
			{
				return l.Length > 0;
			}

			internal bool <ProtectionPage>b__31_2(string l)
			{
				return l.Length > 0;
			}

			internal int <ProtectionPage>b__31_4(KeyValuePair<string, (int n, long id, string pos)> k)
			{
				return k.Value.n;
			}

			internal string <GuildsPage>b__33_0(Guilds.Guild g)
			{
				return g.Tag;
			}

			internal bool <GuildsPage>b__33_1(Guilds.Guild g)
			{
				return g.Tag == s_guild;
			}

			internal Guilds.Rank <GuildsPage>b__33_8(Guilds.Member m)
			{
				return m.Rank;
			}

			internal void <World>b__35_0()
			{
				AdminNet.Act("respawn");
			}

			internal void <World>b__35_1()
			{
				AdminNet.Act("morning");
			}

			internal void <World>b__35_2()
			{
				Ask("Message to everyone", 120, delegate(string t)
				{
					AdminNet.Act("announce", t);
				});
			}

			internal void <World>b__35_6(string t)
			{
				AdminNet.Act("announce", t);
			}

			internal bool <World>b__35_3(RandomEvent e)
			{
				if (e != null)
				{
					return !string.IsNullOrEmpty(e.m_name);
				}
				return false;
			}

			internal string <World>b__35_4(RandomEvent e)
			{
				return e.m_name;
			}

			internal void <World>b__35_11()
			{
				AdminNet.Act("stopraid");
			}

			internal void <World>b__35_5()
			{
				AdminNet.Act("info");
			}

			internal void <Tools>b__36_0()
			{
				Ask("Creature (prefab, then level and aspect, e.g. Troll 3 Fire)", 60, delegate(string t)
				{
					List<string> list = new List<string> { "spawn" };
					list.AddRange(from s in t.Split(new char[1] { ' ' })
						where s.Length > 0
						select s);
					Run(list.ToArray());
				});
			}

			internal void <Tools>b__36_14(string t)
			{
				List<string> list = new List<string> { "spawn" };
				list.AddRange(from s in t.Split(new char[1] { ' ' })
					where s.Length > 0
					select s);
				Run(list.ToArray());
			}

			internal bool <Tools>b__36_15(string s)
			{
				return s.Length > 0;
			}

			internal void <Tools>b__36_1()
			{
				Run("zoo");
			}

			internal void <Tools>b__36_2()
			{
				Run("zoo", "clear");
			}

			internal void <Tools>b__36_3()
			{
				Run("give", "5");
			}

			internal void <Tools>b__36_4()
			{
				Run("give", "5", "all");
			}

			internal void <Tools>b__36_5()
			{
				AdminNet.Act("trips");
			}

			internal void <Tools>b__36_6()
			{
				Run("skyisland", "admin");
			}

			internal void <Tools>b__36_7()
			{
				Run("skyisland", "8");
			}

			internal void <Tools>b__36_8()
			{
				if (Armed("adminisle"))
				{
					Run("skyisland", "admin", "remove");
				}
			}

			internal void <Tools>b__36_9()
			{
				Run("skyisland", "key", "60");
			}

			internal void <Tools>b__36_10()
			{
				Run("skyisland", "key", "1440");
			}

			internal void <Tools>b__36_11()
			{
				Run("skyisland", "key", "10080");
			}

			internal void <Tools>b__36_12()
			{
				Ask("Key lasts how many minutes?", 8, delegate(string t)
				{
					Run("skyisland", "key", t);
				});
			}

			internal void <Tools>b__36_16(string t)
			{
				Run("skyisland", "key", t);
			}

			internal void <Tools>b__36_13()
			{
				Run("skyisland", "key", "0");
			}
		}

		private static Button s_tab;

		private static GameObject s_panel;

		private static GameObject s_body;

		private static bool s_open;

		private static bool s_dirty;

		private static Page s_page = Page.Players;

		private static int s_scroll;

		private static bool s_showAdminLog;

		private static string s_armed;

		private static float s_armedAt;

		private static string s_basesFor;

		private static string s_guild;

		private static int s_event;

		private static Action s_afterInput;

		private static readonly string[] Weathers = new string[7] { "Clear", "Twilight_Clear", "Rain", "ThunderStorm", "Misty", "SnowStorm", "Ashrain" };

		private static float W
		{
			get
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				Rect rect = ((RectTransform)s_panel.transform).rect;
				return ((Rect)(ref rect)).width;
			}
		}

		private static float H
		{
			get
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				Rect rect = ((RectTransform)s_panel.transform).rect;
				return ((Rect)(ref rect)).height;
			}
		}

		public static void Close()
		{
			s_open = false;
		}

		public static void Update(InventoryGui gui)
		{
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: 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)
			//IL_00f1: 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)
			if (s_afterInput != null && !TextInput.IsVisible())
			{
				Action action = s_afterInput;
				s_afterInput = null;
				action();
				s_dirty = true;
			}
			if ((Object)(object)gui == (Object)null || (Object)(object)gui.m_tabCraft == (Object)null || GUIManager.Instance == null)
			{
				return;
			}
			if ((Object)(object)s_tab == (Object)null)
			{
				Build(gui);
			}
			if ((Object)(object)s_tab == (Object)null)
			{
				return;
			}
			bool flag = AdminNet.IsAdmin && InventoryGui.IsVisible() && (Object)(object)gui.m_crafting != (Object)null && ((Component)gui.m_crafting).gameObject.activeInHierarchy;
			((Component)s_tab).gameObject.SetActive(flag);
			RectTransform val = (RectTransform)(((object)GuildPanel.TabRect) ?? ((object)(RectTransform)((Component)gui.m_tabCraft).transform));
			RectTransform val2 = (RectTransform)((Component)s_tab).transform;
			Vector2 anchoredPosition = val.anchoredPosition;
			Rect rect = val.rect;
			val2.anchoredPosition = anchoredPosition + new Vector2(((Rect)(ref rect)).width + 6f, 0f);
			if (!flag)
			{
				s_open = false;
			}
			if (s_panel.activeSelf != s_open)
			{
				s_panel.SetActive(s_open);
				if (s_open)
				{
					s_panel.transform.SetAsLastSibling();
					Request();
				}
			}
			if (s_open)
			{
				((Selectable)s_tab).interactable = false;
				((Selectable)gui.m_tabCraft).interactable = true;
				if ((Object)(object)gui.m_tabUpgrade != (Object)null)
				{
					((Selectable)gui.m_tabUpgrade).interactable = true;
				}
				if (s_dirty)
				{
					s_dirty = false;
					Refresh();
				}
			}
			else
			{
				((Selectable)s_tab).interactable = true;
			}
		}

		private static void Build(InventoryGui gui)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//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_006f: Expected O, but got Unknown
			//IL_009f: 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_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Expected O, but got Unknown
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Expected O, but got Unknown
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(((Component)gui.m_tabCraft).gameObject, ((Component)gui.m_tabCraft).transform.parent);
			((Object)val).name = "cb_tab_admin";
			s_tab = val.GetComponent<Button>();
			s_tab.onClick = new ButtonClickedEvent();
			ButtonClickedEvent onClick = s_tab.onClick;
			object obj = <>c.<>9__17_0;
			if (obj == null)
			{
				UnityAction val2 = delegate
				{
					s_open = true;
					s_dirty = true;
					GuildPanel.Close();
				};
				<>c.<>9__17_0 = val2;
				obj = (object)val2;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj);
			TMP_Text[] componentsInChildren = val.GetComponentsInChildren<TMP_Text>(true);
			foreach (TMP_Text obj2 in componentsInChildren)
			{
				obj2.text = "ADMIN";
				((Graphic)obj2).color = new Color(1f, 0.55f, 0.45f);
			}
			Text[] componentsInChildren2 = val.GetComponentsInChildren<Text>(true);
			foreach (Text obj3 in componentsInChildren2)
			{
				obj3.text = "ADMIN";
				((Graphic)obj3).color = new Color(1f, 0.55f, 0.45f);
			}
			s_panel = new GameObject("cb_admin_panel", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			s_panel.transform.SetParent((Transform)(object)gui.m_crafting, false);
			((Graphic)s_panel.GetComponent<Image>()).color = new Color(0.15f, 0.1f, 0.08f, 1f);
			RectTransform val3 = (RectTransform)s_panel.transform;
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			((RectTransform)((Component)gui.m_tabCraft).transform).GetWorldCorners(array);
			float y = ((Transform)gui.m_crafting).InverseTransformPoint(array[0]).y;
			val3.anchorMin = Vector2.zero;
			val3.anchorMax = Vector2.one;
			val3.offsetMin = new Vector2(18f, 18f);
			Rect rect = gui.m_crafting.rect;
			val3.offsetMax = new Vector2(-18f, 0f - (((Rect)(ref rect)).yMax - y) - 4f);
			s_body = new GameObject("body", new Type[1] { typeof(RectTransform) });
			s_body.transform.SetParent(s_panel.transform, false);
			RectTransform val4 = (RectTransform)s_body.transform;
			val4.anchorMin = Vector2.zero;
			val4.anchorMax = Vector2.one;
			Vector2 offsetMin = (val4.offsetMax = Vector2.zero);
			val4.offsetMin = offsetMin;
			s_panel.SetActive(false);
			AdminNet.Changed += delegate
			{
				s_dirty = true;
			};
			Guilds.Changed += delegate
			{
				if (s_page == Page.Guilds)
				{
					s_dirty = true;
				}
			};
		}

		private static void Request()
		{
			switch (s_page)
			{
			case Page.Players:
				AdminNet.Act("players");
				AdminNet.Act("bans");
				break;
			case Page.Protection:
				AdminNet.Act(s_showAdminLog ? "adminlog" : "wardlog");
				if (!s_showAdminLog)
				{
					AdminNet.Act("players");
				}
				break;
			case Page.World:
				AdminNet.Act("info");
				break;
			case Page.Guilds:
				break;
			}
		}

		private static string Get(string kind)
		{
			if (!AdminNet.Data.TryGetValue(kind, out var value))
			{
				return "";
			}
			return value;
		}

		private static bool Armed(string key)
		{
			if (s_armed == key && Time.time - s_armedAt < 4f)
			{
				s_armed = null;
				return true;
			}
			s_armed = key;
			s_armedAt = Time.time;
			s_dirty = true;
			return false;
		}

		private static string ArmLabel(string key, string label)
		{
			if (!(s_armed == key) || !(Time.time - s_armedAt < 4f))
			{
				return label;
			}
			return "<color=#ff6655>Sure?</color>";
		}

		private static void Refresh()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Expected O, but got Unknown
			foreach (Transform item in s_body.transform)
			{
				Object.Destroy((Object)(object)((Component)item).gameObject);
			}
			float num = 10f;
			string[] array = new string[5] { "Players", "Protection", "Guilds", "World", "Tools" };
			float num2 = (W - 40f) / (float)array.Length;
			for (int i = 0; i < array.Length; i++)
			{
				Page p = (Page)i;
				Button((s_page == p) ? ("<color=#ffcc66>" + array[i] + "</color>") : array[i], 20f + (float)i * num2, num, num2 - 6f, 30f, (UnityAction)delegate
				{
					s_page = p;
					s_scroll = 0;
					Request();
				}, center: true);
			}
			num += 40f;
			switch (s_page)
			{
			case Page.Players:
				Players(num);
				break;
			case Page.Protection:
				ProtectionPage(num);
				break;
			case Page.Guilds:
				GuildsPage(num);
				break;
			case Page.World:
				World(num);
				break;
			case Page.Tools:
				Tools(num);
				break;
			}
		}

		private static List<Row> PlayerRows()
		{
			List<Row> list = new List<Row>();
			string[] array = Get("players").Split(new char[1] { '\n' });
			for (int i = 0; i < array.Length; i++)
			{
				string[] array2 = array[i].Split(new char[1] { '|' });
				if (array2.Length >= 11)
				{
					Row row = new Row
					{
						Name = array2[2],
						Tag = array2[3],
						Biome = array2[10],
						Frozen = (array2[9] == "1"),
						Bosses = ((array2.Length > 11) ? array2[11] : "")
					};
					long.TryParse(array2[0], out row.Uid);
					long.TryParse(array2[1], out row.Id);
					float.TryParse(array2[4], out row.X);
					float.TryParse(array2[5], out row.Y);
					float.TryParse(array2[6], out row.Z);
					float.TryParse(array2[7], out row.Hp);
					float.TryParse(array2[8], out row.On);
					list.Add(row);
				}
			}
			return list;
		}

		private static void Players(float y)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			//IL_0084: 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_008f: Expected O, but got Unknown
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Expected O, but got Unknown
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Expected O, but got Unknown
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Expected O, but got Unknown
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_0381: Expected O, but got Unknown
			//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b0: Expected O, but got Unknown
			//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03df: Expected O, but got Unknown
			//IL_0419: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Expected O, but got Unknown
			//IL_045e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0469: Expected O, but got Unknown
			//IL_0726: Unknown result type (might be due to invalid IL or missing references)
			//IL_0731: Expected O, but got Unknown
			//IL_05dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e8: Expected O, but got Unknown
			string text = (((Object)(object)Player.m_localPlayer != (Object)null && ((Character)Player.m_localPlayer).InGhostMode()) ? "<color=#9be37a>Ghost mode: ON</color>" : "Ghost mode: off");
			float y2 = y;
			object obj = <>O.<0>__ToggleGhost;
			if (obj == null)
			{
				UnityAction val = ToggleGhost;
				<>O.<0>__ToggleGhost = val;
				obj = (object)val;
			}
			Button(text, 20f, y2, 170f, 28f, (UnityAction)obj, center: true);
			float x = W - 120f;
			float y3 = y;
			object obj2 = <>O.<1>__Request;
			if (obj2 == null)
			{
				UnityAction val2 = Request;
				<>O.<1>__Request = val2;
				obj2 = (object)val2;
			}
			Button("Refresh", x, y3, 100f, 28f, (UnityAction)obj2, center: true);
			y += 36f;
			List<Row> list = PlayerRows();
			if (list.Count == 0)
			{
				Label("<color=#888888>Loading...</color>", 20f, y, W - 40f, 24f);
				return;
			}
			int num = Mathf.Max(1, (int)((H - y - 130f) / 56f));
			Pager(ref y, list.Count, num);
			foreach (Row r in list.Skip(s_scroll).Take(num))
			{
				string text2 = ((r.Tag.Length > 0) ? ("[" + r.Tag + "] ") : "");
				Label(string.Format("<b>{0}{1}</b>  <color=#bbbbbb>{2} ({3:0}, {4:0}) · {5:0} hp · on {6} min · bosses: {7}</color>{8}", text2, r.Name, r.Biome, r.X, r.Z, r.Hp, (int)(r.On / 60f), (r.Bosses.Length > 0) ? r.Bosses : "none", r.Frozen ? "  <color=#7fd8ff>FROZEN</color>" : ""), 20f, y, W - 40f, 22f, 14);
				y += 22f;
				float num2 = 20f;
				float num3 = (W - 40f) / 8f;
				string uid = r.Uid.ToString();
				string id = r.Id.ToString();
				string name = r.Name;
				Button("Go to", num2, y, num3 - 4f, 26f, (UnityAction)delegate
				{
					AdminNet.Act("goto", uid);
				}, center: true);
				num2 += num3;
				Button("Bring", num2, y, num3 - 4f, 26f, (UnityAction)delegate
				{
					AdminNet.Act("bring", uid);
				}, center: true);
				num2 += num3;
				Button("Heal", num2, y, num3 - 4f, 26f, (UnityAction)delegate
				{
					AdminNet.Act("heal", uid);
				}, center: true);
				num2 += num3;
				Button(r.Frozen ? "Unfreeze" : "Freeze", num2, y, num3 - 4f, 26f, (UnityAction)delegate
				{
					AdminNet.Act("freeze", uid, r.Frozen ? "0" : "1");
					AdminNet.Act("players");
				}, center: true);
				num2 += num3;
				Button("Bases", num2, y, num3 - 4f, 26f, (UnityAction)delegate
				{
					s_basesFor = name;
					AdminNet.Act("bases", id);
				}, center: true);
				num2 += num3;
				Button("Fix cores", num2, y, num3 - 4f, 26f, (UnityAction)delegate
				{
					AdminNet.Act("fixcores", uid);
				}, center: true);
				num2 += num3;
				Button(ArmLabel("kick" + id, "Kick"), num2, y, num3 - 4f, 26f, (UnityAction)delegate
				{
					if (Armed("kick" + id))
					{
						AdminNet.Act("kick", name);
					}
				}, center: true);
				num2 += num3;
				Button(ArmLabel("ban" + id, "<color=#ff8866>Ban</color>"), num2, y, num3 - 4f, 26f, (UnityAction)delegate
				{
					if (Armed("ban" + id))
					{
						AdminNet.Act("ban", name);
					}
				}, center: true);
				y += 34f;
			}
			if (s_basesFor != null)
			{
				List<string> list2 = (from l in Get("bases").Split(new char[1] { '\n' })
					where l.Contains("|")
					select l).ToList();
				Label("<color=#ffcc66>" + s_basesFor + "'s bases</color>" + ((list2.Count == 0) ? "  <color=#888888>none found</color>" : ""), 20f, y, W - 40f, 22f, 14);
				y += 24f;
				float num4 = 20f;
				foreach (string item in list2.Take(6))
				{
					string[] array = item.Split(new char[1] { '|' });
					string pos = array[1] + "," + array[2];
					Button(array[0] + " (" + array[1] + ", " + array[2] + ")", num4, y, (W - 40f) / 3f - 4f, 26f, (UnityAction)delegate
					{
						AdminNet.Act("gotopos", pos);
					}, center: true);
					num4 += (W - 40f) / 3f;
					if (num4 > W - 60f)
					{
						num4 = 20f;
						y += 30f;
					}
				}
				y += 32f;
			}
			List<string> list3 = (from l in Get("bans").Split(new char[1] { '\n' })
				where l.Trim().Length > 0
				select l).ToList();
			Label("<color=#ffcc66>Banned</color>" + ((list3.Count == 0) ? "  <color=#888888>no one</color>" : ""), 20f, H - 60f, 120f, 22f, 14);
			float num5 = 140f;
			foreach (string item2 in list3.Take(4))
			{
				string who = item2.Trim();
				Button("Unban " + who, num5, H - 64f, 140f, 26f, (UnityAction)delegate
				{
					AdminNet.Act("unban", who);
					AdminNet.Act("bans");
				}, center: true);
				num5 += 146f;
			}
		}

		private static void ToggleGhost()
		{
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null))
			{
				bool flag = !((Character)localPlayer).InGhostMode();
				localPlayer.SetGhostMode(flag);
				AdminNet.Act("tool", "ghost mode", flag ? "on" : "off");
			}
		}

		private static void ProtectionPage(float y)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			//IL_0493: Unknown result type (might be due to invalid IL or missing references)
			//IL_049e: Expected O, but got Unknown
			//IL_04df: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ea: Expected O, but got Unknown
			//IL_0507: Unknown result type (might be due to invalid IL or missing references)
			//IL_0512: Expected O, but got Unknown
			//IL_0642: Unknown result type (might be due to invalid IL or missing references)
			//IL_064d: Expected O, but got Unknown
			string text = (s_showAdminLog ? "Ward log" : "<color=#ffcc66>Ward log</color>");
			float y2 = y;
			object obj = <>c.<>9__31_0;
			if (obj == null)
			{
				UnityAction val = delegate
				{
					s_showAdminLog = false;
					Request();
				};
				<>c.<>9__31_0 = val;
				obj = (object)val;
			}
			Button(text, 20f, y2, 130f, 28f, (UnityAction)obj, center: true);
			string text2 = (s_showAdminLog ? "<color=#ffcc66>Admin log</color>" : "Admin log");
			float y3 = y;
			object obj2 = <>c.<>9__31_1;
			if (obj2 == null)
			{
				UnityAction val2 = delegate
				{
					s_showAdminLog = true;
					Request();
				};
				<>c.<>9__31_1 = val2;
				obj2 = (object)val2;
			}
			Button(text2, 156f, y3, 130f, 28f, (UnityAction)obj2, center: true);
			float x = W - 120f;
			float y4 = y;
			object obj3 = <>O.<1>__Request;
			if (obj3 == null)
			{
				UnityAction val3 = Request;
				<>O.<1>__Request = val3;
				obj3 = (object)val3;
			}
			Button("Refresh", x, y4, 100f, 28f, (UnityAction)obj3, center: true);
			y += 36f;
			if (s_showAdminLog)
			{
				List<string> list = (from l in Get("adminlog").Split(new char[1] { '\n' })
					where l.Length > 0
					select l).ToList();
				int num = Mathf.Max(1, (int)((H - y - 20f) / 22f));
				Pager(ref y, list.Count, num);
				foreach (string item in list.Skip(s_scroll).Take(num))
				{
					Label(item, 20f, y, W - 40f, 22f, 13);
					y += 22f;
				}
				if (list.Count == 0)
				{
					Label("<color=#888888>Nothing yet.</color>", 20f, y, W - 40f, 22f);
				}
				return;
			}
			List<string> list2 = (from l in Get("wardlog").Split(new char[1] { '\n' })
				where l.Length > 0
				select l).ToList();
			DateTime dateTime = DateTime.Now.AddDays(-1.0);
			Dictionary<string, (int, long, string)> dictionary = new Dictionary<string, (int, long, string)>();
			foreach (string item2 in list2)
			{
				if (item2.Length >= 17 && DateTime.TryParseExact(item2.Substring(0, 16), "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out var result) && !(result < dateTime))
				{
					int num2 = item2.IndexOf(" tried to ", StringComparison.Ordinal);
					if (num2 >= 17)
					{
						string key = item2.Substring(17, num2 - 17);
						long.TryParse(item2.Contains("#") ? item2.Substring(item2.LastIndexOf('#') + 1) : "0", out var result2);
						string text3 = Pos(item2);
						dictionary[key] = (dictionary.TryGetValue(key, out var value) ? (value.Item1 + 1, (result2 != 0L) ? result2 : value.Item2, value.Item3 ?? text3) : (1, result2, text3));
					}
				}
			}
			Label("<color=#ffcc66>Hotspots (blocked attempts, last 24 h)</color>", 20f, y, W - 40f, 22f, 14);
			y += 24f;
			if (dictionary.Count == 0)
			{
				Label("<color=#888888>No one.</color>", 20f, y, W - 40f, 22f);
				y += 24f;
			}
			foreach (KeyValuePair<string, (int, long, string)> item3 in dictionary.OrderByDescending<KeyValuePair<string, (int, long, string)>, int>((KeyValuePair<string, (int n, long id, string pos)> k) => k.Value.n).Take(4))
			{
				string key2 = item3.Key;
				string id = item3.Value.Item2.ToString();
				string pos = item3.Value.Item3;
				Label($"<b>{key2}</b> <color=#ff8866>{item3.Value.Item1}</color>", 20f, y + 3f, 170f, 24f, 14);
				if (pos != null)
				{
					Button("Go there", 190f, y, 90f, 26f, (UnityAction)delegate
					{
						AdminNet.Act("gotopos", pos);
					}, center: true);
				}
				if (item3.Value.Item2 != 0L)
				{
					Button(ArmLabel("purge" + id, "Remove builds 20 m"), 286f, y, 160f, 26f, (UnityAction)delegate
					{
						if (Armed("purge" + id))
						{
							AdminNet.Act("purge", id, "20");
						}
					}, center: true);
					Button("Reset wards", 452f, y, 110f, 26f, (UnityAction)delegate
					{
						AdminNet.Act("resetwards", id);
					}, center: true);
				}
				y += 30f;
			}
			y += 6f;
			Label("<color=#ffcc66>Ward log</color>  <color=#bbbbbb>(newest first; Go jumps there)</color>", 20f, y, W - 40f, 22f, 14);
			y += 24f;
			int num3 = Mathf.Max(1, (int)((H - y - 20f) / 26f));
			Pager(ref y, list2.Count, num3);
			foreach (string item4 in list2.Skip(s_scroll).Take(num3))
			{
				string pos2 = Pos(item4);
				Label(item4.Contains(" #") ? item4.Substring(0, item4.LastIndexOf(" #")) : item4, 20f, y + 3f, W - 100f, 24f, 13);
				if (pos2 != null)
				{
					Button("Go", W - 70f, y, 50f, 24f, (UnityAction)delegate
					{
						AdminNet.Act("gotopos", pos2);
					}, center: true);
				}
				y += 26f;
			}
			if (list2.Count == 0)
			{
				Label("<color=#888888>Nothing blocked yet.</color>", 20f, y, W - 40f, 22f);
			}
		}

		private static string Pos(string line)
		{
			int num = line.LastIndexOf(" at (", StringComparison.Ordinal);
			int num2 = ((num >= 0) ? line.IndexOf(')', num) : (-1));
			if (num < 0 || num2 < 0)
			{
				return null;
			}
			return line.Substring(num + 5, num2 - num - 5).Replace(" ", "");
		}

		private static void GuildsPage(float y)
		{
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Expected O, but got Unknown
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Expected O, but got Unknown
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Expected O, but got Unknown
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Expected O, but got Unknown
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d9: Expected O, but got Unknown
			//IL_038a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0395: Expected O, but got Unknown
			List<Guilds.Guild> list = Guilds.All.OrderBy((Guilds.Guild g) => g.Tag).ToList();
			if (list.Count == 0)
			{
				Label("<color=#888888>No guilds.</color>", 20f, y, W - 40f, 24f);
				return;
			}
			int num = Mathf.Max(1, (int)((H - y - 200f) / 32f));
			Pager(ref y, list.Count, num);
			foreach (Guilds.Guild item in list.Skip(s_scroll).Take(num))
			{
				string tag = item.Tag;
				Label($"<color={item.Color}>[{item.Tag}] {item.Name}</color>  <color=#bbbbbb>{item.Members.Count} · {item.Leader?.Name}</color>", 20f, y + 4f, W - 380f, 24f, 14);
				Button((s_guild == tag) ? "<color=#ffcc66>Members</color>" : "Members", W - 360f, y, 84f, 26f, (UnityAction)delegate
				{
					s_guild = ((s_guild == tag) ? null : tag);
				}, center: true);
				Button("Rename", W - 272f, y, 76f, 26f, (UnityAction)delegate
				{
					Ask("New guild name", 24, delegate(string n)
					{
						AdminNet.Act("g_name", tag, n);
					});
				}, center: true);
				Button("Tag", W - 192f, y, 56f, 26f, (UnityAction)delegate
				{
					Ask("New tag (2-4 letters)", 4, delegate(string t)
					{
						AdminNet.Act("g_tag", tag, t);
					});
				}, center: true);
				Button(ArmLabel("gd" + tag, "<color=#ff8866>Disband</color>"), W - 132f, y, 112f, 26f, (UnityAction)delegate
				{
					if (Armed("gd" + tag))
					{
						AdminNet.Act("g_disband", tag);
					}
				}, center: true);
				y += 32f;
			}
			Guilds.Guild guild = Guilds.All.FirstOrDefault((Guilds.Guild g) => g.Tag == s_guild);
			if (guild == null)
			{
				return;
			}
			y += 6f;
			Label("<color=#ffcc66>[" + guild.Tag + "] members</color>", 20f, y, W - 40f, 22f, 14);
			y += 24f;
			foreach (Guilds.Member item2 in guild.Members.OrderByDescending((Guilds.Member m) => m.Rank).Take(8))
			{
				string id = item2.Id.ToString();
				string tag2 = guild.Tag;
				Label($"{item2.Name} <color=#bbbbbb>{item2.Rank}</color>", 20f, y + 3f, W - 260f, 24f, 14);
				if (item2.Rank != Guilds.Rank.Leader)
				{
					Button("Make leader", W - 230f, y, 110f, 24f, (UnityAction)delegate
					{
						AdminNet.Act("g_lead", tag2, id);
					}, center: true);
				}
				Button(ArmLabel("gk" + id, "Remove"), W - 114f, y, 94f, 24f, (UnityAction)delegate
				{
					if (Armed("gk" + id))
					{
						AdminNet.Act("g_kick", tag2, id);
					}
				}, center: true);
				y += 28f;
			}
		}

		private static void World(float y)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Expected O, but got Unknown
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Expected O, but got Unknown
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Expected O, but got Unknown
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: Expected O, but got Unknown
			//IL_0419: Unknown result type (might be due to invalid IL or missing references)
			//IL_041e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Expected O, but got Unknown
			//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b9: Expected O, but got Unknown
			float num = (W - 40f) / 3f;
			float y2 = y;
			float w = num - 6f;
			object obj = <>c.<>9__35_0;
			if (obj == null)
			{
				UnityAction val = delegate
				{
					AdminNet.Act("respawn");
				};
				<>c.<>9__35_0 = val;
				obj = (object)val;
			}
			Button("Respawn world now", 20f, y2, w, 30f, (UnityAction)obj, center: true);
			float x = 20f + num;
			float y3 = y;
			float w2 = num - 6f;
			object obj2 = <>c.<>9__35_1;
			if (obj2 == null)
			{
				UnityAction val2 = delegate
				{
					AdminNet.Act("morning");
				};
				<>c.<>9__35_1 = val2;
				obj2 = (object)val2;
			}
			Button("Skip to morning", x, y3, w2, 30f, (UnityAction)obj2, center: true);
			float x2 = 20f + num * 2f;
			float y4 = y;
			float w3 = num - 6f;
			object obj3 = <>c.<>9__35_2;
			if (obj3 == null)
			{
				UnityAction val3 = delegate
				{
					Ask("Message to everyone", 120, delegate(string t)
					{
						AdminNet.Act("announce", t);
					});
				};
				<>c.<>9__35_2 = val3;
				obj3 = (object)val3;
			}
			Button("Announce...", x2, y4, w3, 30f, (UnityAction)obj3, center: true);
			y += 40f;
			Label("<color=#ffcc66>Weather</color>", 20f, y, W - 40f, 22f, 14);
			y += 24f;
			float num2 = 20f;
			float num3 = (W - 40f) / 4f;
			foreach (string item in Weathers.Concat(new string[1] { "" }))
			{
				string env = item;
				Button((env.Length == 0) ? "<color=#ffcc66>Normal</color>" : env.Replace("_", " "), num2, y, num3 - 6f, 26f, (UnityAction)delegate
				{
					AdminNet.Act("weather", env);
				}, center: true);
				num2 += num3;
				if (num2 > W - 60f)
				{
					num2 = 20f;
					y += 30f;
				}
			}
			y += 38f;
			List<string> events = (((Object)(object)RandEventSystem.instance != (Object)null) ? (from e in RandEventSystem.instance.m_events
				where e != null && !string.IsNullOrEmpty(e.m_name)
				select e.m_name).Distinct().ToList() : new List<string>());
			Label("<color=#ffcc66>Raids and events</color>", 20f, y, W - 40f, 22f, 14);
			y += 24f;
			if (events.Count > 0)
			{
				s_event = Mathf.Clamp(s_event, 0, events.Count - 1);
				string ev = events[s_event];
				Button("◀", 20f, y, 30f, 28f, (UnityAction)delegate
				{
					s_event = (s_event - 1 + events.Count) % events.Count;
				}, center: true);
				Label("<color=#ffcc66>" + ev + "</color>", 56f, y + 4f, 220f, 24f, 14);
				Button("▶", 280f, y, 30f, 28f, (UnityAction)delegate
				{
					s_event = (s_event + 1) % events.Count;
				}, center: true);
				Button("Start here", 320f, y, 110f, 28f, (UnityAction)delegate
				{
					AdminNet.Act("raid", ev);
				}, center: true);
				float y5 = y;
				object obj4 = <>c.<>9__35_11;
				if (obj4 == null)
				{
					UnityAction val4 = delegate
					{
						AdminNet.Act("stopraid");
					};
					<>c.<>9__35_11 = val4;
					obj4 = (object)val4;
				}
				Button("Stop", 436f, y5, 80f, 28f, (UnityAction)obj4, center: true);
			}
			y += 40f;
			Label("<color=#ffcc66>Server</color>", 20f, y, 200f, 22f, 14);
			float x3 = W - 120f;
			float y6 = y - 4f;
			object obj5 = <>c.<>9__35_5;
			if (obj5 == null)
			{
				UnityAction val5 = delegate
				{
					AdminNet.Act("info");
				};
				<>c.<>9__35_5 = val5;
				obj5 = (object)val5;
			}
			Button("Refresh", x3, y6, 100f, 26f, (UnityAction)obj5, center: true);
			y += 24f;
			Label(Get("info"), 20f, y, W - 40f, H - y - 10f, 14);
		}

		private static void Tools(float y)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_00d0: 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_00db: Expected O, but got Unknown
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Expected O, but got Unknown
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Expected O, but got Unknown
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Expected O, but got Unknown
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Expected O, but got Unknown
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Expected O, but got Unknown
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Expected O, but got Unknown
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Expected O, but got Unknown
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Expected O, but got Unknown
			//IL_036c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_0377: Expected O, but got Unknown
			//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03af: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: Expected O, but got Unknown
			//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f9: Expected O, but got Unknown
			//IL_0432: Unknown result type (might be due to invalid IL or missing references)
			//IL_0437: Unknown result type (might be due to invalid IL or missing references)
			//IL_043d: Expected O, but got Unknown
			//IL_0476: Unknown result type (might be due to invalid IL or missing references)
			//IL_047b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0481: Expected O, but got Unknown
			string text = (((Object)(object)Player.m_localPlayer != (Object)null && ((Character)Player.m_localPlayer).InGhostMode()) ? "<color=#9be37a>Ghost mode: ON</color> (invisible)" : "Ghost mode: off");
			float y2 = y;
			float w = W - 40f;
			object obj = <>O.<0>__ToggleGhost;
			if (obj == null)
			{
				UnityAction val = ToggleGhost;
				<>O.<0>__ToggleGhost = val;
				obj = (object)val;
			}
			Button(text, 20f, y2, w, 30f, (UnityAction)obj);
			y += 40f;
			Label("<color=#bbbbbb>Ghost mode: other players can't see you, your name or your map dot, and monsters ignore you.</color>", 20f, y, W - 40f, 40f, 13);
			y += 44f;
			float num = (W - 40f) / 3f;
			float y3 = y;
			float w2 = num - 6f;
			object obj2 = <>c.<>9__36_0;
			if (obj2 == null)
			{
				UnityAction val2 = delegate
				{
					Ask("Creature (prefab, then level and aspect, e.g. Troll 3 Fire)", 60, delegate(string t)
					{
						List<string> list = new List<string> { "spawn" };
						list.AddRange(from s in t.Split(new char[1] { ' ' })
							where s.Length > 0
							select s);
						Run(list.ToArray());
					});
				};
				<>c.<>9__36_0 = val2;
				obj2 = (object)val2;
			}
			Button("Spawn creature...", 20f, y3, w2, 30f, (UnityAction)obj2, center: true);
			float x = 20f + num;
			float y4 = y;
			float w3 = num - 6f;
			object obj3 = <>c.<>9__36_1;
			if (obj3 == null)
			{
				UnityAction val3 = delegate
				{
					Run("zoo");
				};
				<>c.<>9__36_1 = val3;
				obj3 = (object)val3;
			}
			Button("Aspect zoo (Boar)", x, y4, w3, 30f, (UnityAction)obj3, center: true);
			float x2 = 20f + num * 2f;
			float y5 = y;
			float w4 = num - 6f;
			object obj4 = <>c.<>9__36_2;
			if (obj4 == null)
			{
				UnityAction val4 = delegate
				{
					Run("zoo", "clear");
				};
				<>c.<>9__36_2 = val4;
				obj4 = (object)val4;
			}
			Button("Clear zoo", x2, y5, w4, 30f, (UnityAction)obj4, center: true);
			y += 38f;
			float y6 = y;
			float w5 = num - 6f;
			object obj5 = <>c.<>9__36_3;
			if (obj5 == null)
			{
				UnityAction val5 = delegate
				{
					Run("give", "5");
				};
				<>c.<>9__36_3 = val5;
				obj5 = (object)val5;
			}
			Button("Give 5 Soul Cores", 20f, y6, w5, 30f, (UnityAction)obj5, center: true);
			float x3 = 20f + num;
			float y7 = y;
			float w6 = num - 6f;
			object obj6 = <>c.<>9__36_4;
			if (obj6 == null)
			{
				UnityAction val6 = delegate
				{
					Run("give", "5", "all");
				};
				<>c.<>9__36_4 = val6;
				obj6 = (object)val6;
			}
			Button("Give every core tier", x3, y7, w6, 30f, (UnityAction)obj6, center: true);
			float x4 = 20f + num * 2f;
			float y8 = y;
			float w7 = num - 6f;
			object obj7 = <>c.<>9__36_5;
			if (obj7 == null)
			{
				UnityAction val7 = delegate
				{
					AdminNet.Act("trips");
				};
				<>c.<>9__36_5 = val7;
				obj7 = (object)val7;
			}
			Button("Bring all workers home", x4, y8, w7, 30f, (UnityAction)obj7, center: true);
			y += 44f;
			Label("<color=#ffcc66>Admin Island</color>", 20f, y, W - 40f, 22f, 14);
			y += 24f;
			float y9 = y;
			float w8 = num - 6f;
			object obj8 = <>c.<>9__36_6;
			if (obj8 == null)
			{
				UnityAction val8 = delegate
				{
					Run("skyisland", "admin");
				};
				<>c.<>9__36_6 = val8;
				obj8 = (object)val8;
			}
			Button("Place it in front of me", 20f, y9, w8, 30f, (UnityAction)obj8, center: true);
			float x5 = 20f + num;
			float y10 = y;
			float w9 = num - 6f;
			object obj9 = <>c.<>9__36_7;
			if (obj9 == null)
			{
				UnityAction val9 = delegate
				{
					Run("skyisland", "8");
				};
				<>c.<>9__36_7 = val9;
				obj9 = (object)val9;
			}
			Button("Go there", x5, y10, w9, 30f, (UnityAction)obj9, center: true);
			string text2 = ArmLabel("adminisle", "<color=#ff8866>Remove it</color>");
			float x6 = 20f + num * 2f;
			float y11 = y;
			float w10 = num - 6f;
			object obj10 = <>c.<>9__36_8;
			if (obj10 == null)
			{
				UnityAction val10 = delegate
				{
					if (Armed("adminisle"))
					{
						Run("skyisland", "admin", "remove");
					}
				};
				<>c.<>9__36_8 = val10;
				obj10 = (object)val10;
			}
			Button(text2, x6, y11, w10, 30f, (UnityAction)obj10, center: true);
			y += 36f;
			float num2 = (W - 40f) / 5f;
			float y12 = y;
			float w11 = num2 - 6f;
			object obj11 = <>c.<>9__36_9;
			if (obj11 == null)
			{
				UnityAction val11 = delegate
				{
					Run("skyisland", "key", "60");
				};
				<>c.<>9__36_9 = val11;
				obj11 = (object)val11;
			}
			Button("Key: 1 hour", 20f, y12, w11, 30f, (UnityAction)obj11, center: true);
			float x7 = 20f + num2;
			float y13 = y;
			float w12 = num2 - 6f;
			object obj12 = <>c.<>9__36_10;
			if (obj12 == null)
			{
				UnityAction val12 = delegate
				{
					Run("skyisland", "key", "1440");
				};
				<>c.<>9__36_10 = val12;
				obj12 = (object)val12;
			}
			Button("Key: 1 day", x7, y13, w12, 30f, (UnityAction)obj12, center: true);
			float x8 = 20f + num2 * 2f;
			float y14 = y;
			float w13 = num2 - 6f;
			object obj13 = <>c.<>9__36_11;
			if (obj13 == null)
			{
				UnityAction val13 = delegate
				{
					Run("skyisland", "key", "10080");
				};
				<>c.<>9__36_11 = val13;
				obj13 = (object)val13;
			}
			Button("Key: 1 week", x8, y14, w13, 30f, (UnityAction)obj13, center: true);
			float x9 = 20f + num2 * 3f;
			float y15 = y;
			float w14 = num2 - 6f;
			object obj14 = <>c.<>9__36_12;
			if (obj14 == null)
			{
				UnityAction val14 = delegate
				{
					Ask("Key lasts how many minutes?", 8, delegate(string t)
					{
						Run("skyisland", "key", t);
					});
				};
				<>c.<>9__36_12 = val14;
				obj14 = (object)val14;
			}
			Button("Key: custom...", x9, y15, w14, 30f, (UnityAction)obj14, center: true);
			float x10 = 20f + num2 * 4f;
			float y16 = y;
			float w15 = num2 - 6f;
			object obj15 = <>c.<>9__36_13;
			if (obj15 == null)
			{
				UnityAction val15 = delegate
				{
					Run("skyisland", "key", "0");
				};
				<>c.<>9__36_13 = val15;
				obj15 = (object)val15;
			}
			Button("Key: forever", x10, y16, w15, 30f, (UnityAction)obj15, center: true);
			y += 38f;
			Label("<color=#bbbbbb>Keys go into your inventory; hand them out. Anyone at the Admin Island without a key is warned and sent back to the spawn. Keys crumble when their time is up.</color>", 20f, y, W - 40f, 40f, 13);
			y += 44f;
			Label("<color=#bbbbbb>\"Fix cores\" for a player's stuck or knocked-out companions is on the Players page.</color>", 20f, y, W - 40f, 40f, 13);
		}

		private static void Run(params string[] args)
		{
			((ConsoleCommand)new CoreCommands()).Run(args);
			AdminNet.Act("tool", string.Join(" ", args));
		}

		private static void Pager(ref float y, int count, int per)
		{
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Expected O, but got Unknown
			if (count <= per)
			{
				s_scroll = 0;
				return;
			}
			s_scroll = Mathf.Clamp(s_scroll, 0, Mathf.Max(0, count - per));
			int num = s_scroll / per + 1;
			int num2 = (count + per - 1) / per;
			Button("‹", W - 120f, y - 4f, 40f, 26f, (UnityAction)delegate
			{
				s_scroll = Mathf.Max(0, s_scroll - per);
			}, center: true);
			Label($"{num}/{num2}", W - 76f, y, 40f, 24f, 14);
			Button("›", W - 40f, y - 4f, 32f, 26f, (UnityAction)delegate
			{
				s_scroll = Mathf.Min(count - 1, s_scroll + per);
			}, center: true);
			y += 28f;
		}

		private static void Ask(string topic, int limit, Action<string> done)
		{
			if ((Object)(object)TextInput.instance != (Object)null)
			{
				TextInput.instance.RequestText((TextReceiver)(object)new Reply
				{
					Done = done
				}, topic, limit);
			}
		}

		private static void Label(string text, float x, float y, float w, float h, int size = 15)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = GUIManager.Instance.CreateText(text, s_body.transform, new Vector2(0f, 1f), new Vector2(0f, 1f), Vector2.zero, GUIManager.Instance.AveriaSerifBold, size, new Color(0.93f, 0.89f, 0.8f), true, Color.black, w, h, false);
			RectTransform val = (RectTransform)obj.transform;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0f, 1f);
			val.anchorMax = val2;
			val.anchorMin = val2;
			val.pivot = new Vector2(0f, 1f);
			val.anchoredPosition = new Vector2(x, 0f - y);
			val.sizeDelta = new Vector2(w, h);
			Text component = obj.GetComponent<Text>();
			if ((Object)(object)component != (Object)null)
			{
				component.alignment = (TextAnchor)0;
				component.supportRichText = true;
				component.horizontalOverflow = (HorizontalWrapMode)0;
				component.verticalOverflow = (VerticalWrapMode)1;
			}
		}

		private static void Button(string text, float x, float y, float w, float h, UnityAction click, bool center = false)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: 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_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Expected O, but got Unknown
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Expected O, but got Unknown
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = GUIManager.Instance.CreateButton(text, s_body.transform, new Vector2(0f, 1f), new Vector2(0f, 1f), Vector2.zero, w, h);
			RectTransform val = (RectTransform)obj.transform;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0f, 1f);
			val.anchorMax = val2;
			val.anchorMin = val2;
			val.pivot = new Vector2(0f, 1f);
			val.anchoredPosition = new Vector2(x, 0f - y);
			val.sizeDelta = new Vector2(w, h);
			Text componentInChildren = obj.GetComponentInChildren<Text>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				componentInChildren.supportRichText = true;
				componentInChildren.fontSize = 13;
				componentInChildren.resizeTextForBestFit = true;
				componentInChildren.resizeTextMinSize = 9;
				componentInChildren.resizeTextMaxSize = 14;
				componentInChildren.alignment = (TextAnchor)(center ? 4 : 3);
				if (!center)
				{
					RectTransform val3 = (RectTransform)((Component)componentInChildren).transform;
					val3.offsetMin = new Vector2(10f, val3.offsetMin.y);
				}
			}
			((UnityEvent)obj.GetComponent<Button>().onClick).AddListener((UnityAction)delegate
			{
				click.Invoke();
				s_dirty = true;
			});
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "Update")]
	public static class AdminPanelUpdate
	{
		[HarmonyPostfix]
		private static void Postfix(InventoryGui __instance)
		{
			AdminPanel.Update(__instance);
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "OnTabCraftPressed")]
	public static class AdminPanelCraft
	{
		[HarmonyPostfix]
		private static void Postfix()
		{
			AdminPanel.Close();
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "OnTabUpgradePressed")]
	public static class AdminPanelUpgrade
	{
		[HarmonyPostfix]
		private static void Postfix()
		{
			AdminPanel.Close();
		}
	}
	public static class AspectIcons
	{
		private const int Size = 64;

		private const int Super = 4;

		private static readonly Dictionary<Aspect, Sprite> s_icons = new Dictionary<Aspect, Sprite>();

		public static Sprite Get(Aspect a)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			if (a == Aspect.None)
			{
				return null;
			}
			if (s_icons.TryGetValue(a, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			Func<float, float, bool> func = Shape(a);
			if (func == null)
			{
				return null;
			}
			Color col = default(Color);
			ColorUtility.TryParseHtmlString(Aspects.Color.TryGetValue(a, out var value2) ? value2 : "#ffffff", ref col);
			Texture2D val = Draw(func, col);
			((Object)val).name = "cb_icon_" + a;
			value = Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f), 100f);
			((Object)value).name = ((Object)val).name;
			s_icons[a] = value;
			return value;
		}

		internal static bool Circle(float x, float y, float cx, float cy, float r)
		{
			return (x - cx) * (x - cx) + (y - cy) * (y - cy) <= r * r;
		}

		internal static bool Ring(float x, float y, float cx, float cy, float r0, float r1)
		{
			float num = (x - cx) * (x - cx) + (y - cy) * (y - cy);
			if (num <= r1 * r1)
			{
				return num >= r0 * r0;
			}
			return false;
		}

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

		internal static bool Poly(float x, float y, float[] p)
		{
			bool flag = false;
			int i = 0;
			int num = p.Length - 2;
			for (; i < p.Length; i += 2)
			{
				float num2 = p[i];
				float num3 = p[i + 1];
				float num4 = p[num];
				float num5 = p[num + 1];
				if (num3 > y != num5 > y && x < (num4 - num2) * (y - num3) / (num5 - num3) + num2)
				{
					flag = !flag;
				}
				num = i;
			}
			return flag;
		}

		internal static Func<float, float, bool> Shape(Aspect a)
		{
			return a switch
			{
				Aspect.Fire => (float x, float y) => Circle(x, y, 0f, -0.32f, 0.5f) || Poly(x, y, new float[6] { -0.48f, -0.25f, -0.1f, 0.88f, 0.48f, -0.25f }) || Poly(x, y, new float[6] { 0.15f, -0.1f, 0.62f, 0.45f, 0.5f, -0.35f }), 
				Aspect.Frost => delegate(float x, float y)
				{
					for (int i = 0; i < 3; i++)
					{
						float num = (float)i * (float)Math.PI / 3f;
						float num2 = Mathf.Cos(num);
						float num3 = Mathf.Sin(num);
						if (Seg(x, y, (0f - num2) * 0.85f, (0f - num3) * 0.85f, num2 * 0.85f, num3 * 0.85f, 0.1f))
						{
							return true;
						}
						float[] array = new float[2] { 1f, -1f };
						foreach (float num4 in array)
						{
							float num5 = num2 * 0.5f * num4;
							float num6 = num3 * 0.5f * num4;
							for (int k = -1; k <= 1; k += 2)
							{
								float num7 = num + ((num4 > 0f) ? 0f : ((float)Math.PI)) + (float)k * 0.8f;
								if (Seg(x, y, num5, num6, num5 + Mathf.Cos(num7) * 0.3f, num6 + Mathf.Sin(num7) * 0.3f, 0.075f))
								{
									return true;
								}
							}
						}
					}
					return Circle(x, y, 0f, 0f, 0.16f);
				}, 
				Aspect.Water => (float x, float y) => Circle(x, y, 0f, -0.28f, 0.55f) || Poly(x, y, new float[6] { -0.5f, -0.06f, 0f, 0.9f, 0.5f, -0.06f }), 
				Aspect.Electric => (float x, float y) => Poly(x, y, new float[12]
				{
					0.22f, 0.92f, -0.5f, -0.02f, -0.05f, -0.02f, -0.25f, -0.92f, 0.52f, 0.12f,
					0.06f, 0.12f
				}), 
				Aspect.Poison => (float x, float y) => Ring(x, y, -0.3f, -0.35f, 0.18f, 0.48f) || Ring(x, y, 0.38f, 0.05f, 0.12f, 0.34f) || Ring(x, y, -0.05f, 0.62f, 0.06f, 0.24f), 
				Aspect.Dark => (float x, float y) => Circle(x, y, 0f, 0f, 0.82f) && !Circle(x, y, 0.38f, 0.22f, 0.68f), 
				Aspect.Nature => delegate(float x, float y)
				{
					float num = Mathf.Cos(-0.785f);
					float num2 = Mathf.Sin(-0.785f);
					float num3 = x * num - y * num2;
					float num4 = x * num2 + y * num;
					bool num5 = Circle(num3, num4, 0f, -0.55f, 0.95f) && Circle(num3, num4, 0f, 0.55f, 0.95f) && Mathf.Abs(num3) < 0.9f;
					bool flag = Mathf.Abs(num4) < 0.045f && num3 > -0.7f && num3 < 0.75f;
					return (num5 && !flag) || Seg(x, y, -0.62f, -0.62f, -0.88f, -0.88f, 0.07f);
				}, 
				Aspect.Stone => (float x, float y) => Poly(x, y, new float[12]
				{
					-0.85f, -0.62f, -0.62f, 0.15f, -0.18f, 0.7f, 0.42f, 0.55f, 0.85f, -0.05f,
					0.68f, -0.62f
				}) && !Seg(x, y, -0.12f, 0.62f, 0.05f, 0.1f, 0.05f) && !Seg(x, y, 0.05f, 0.1f, -0.15f, -0.25f, 0.05f), 
				Aspect.Beast => (float x, float y) => Circle(x, y, 0f, -0.38f, 0.4f) || Circle(x, y, -0.62f, 0.12f, 0.19f) || Circle(x, y, -0.25f, 0.5f, 0.2f) || Circle(x, y, 0.25f, 0.5f, 0.2f) || Circle(x, y, 0.62f, 0.12f, 0.19f), 
				Aspect.Arcane => (float x, float y) => Poly(x, y, new float[16]
				{
					0f, 0.92f, 0.2f, 0.2f, 0.92f, 0f, 0.2f, -0.2f, 0f, -0.92f,
					-0.2f, -0.2f, -0.92f, 0f, -0.2f, 0.2f
				}) || (Ring(x, y, 0f, 0f, 0.6f, 0.7f) && !Poly(x, y, new float[16]
				{
					0f, 0.92f, 0.2f, 0.2f, 0.92f, 0f, 0.2f, -0.2f, 0f, -0.92f,
					-0.2f, -0.2f, -0.92f, 0f, -0.2f, 0.2f
				})), 
				_ => null, 
			};
		}

		private static Texture2D Draw(Func<float, float, bool> shape, Color col)
		{
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: 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)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: 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_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Expected O, but got Unknown
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			int num = 256;
			bool[,] array = new bool[num, num];
			for (int i = 0; i < num; i++)
			{
				for (int j = 0; j < num; j++)
				{
					array[j, i] = shape((((float)j + 0.5f) / (float)num * 2f - 1f) / 0.84f, (((float)i + 0.5f) / (float)num * 2f - 1f) / 0.84f);
				}
			}
			int num2 = 12;
			bool[,] array2 = new bool[num, num];
			for (int k = 0; k < num; k++)
			{
				for (int l = 0; l < num; l++)
				{
					bool flag = false;
					for (int m = Math.Max(0, l - num2); m <= Math.Min(num - 1, l + num2); m++)
					{
						if (flag)
						{
							break;
						}
						flag = array[m, k];
					}
					array2[l, k] = flag;
				}
			}
			bool[,] array3 = new bool[num, num];
			for (int n = 0; n < num; n++)
			{
				for (int num3 = 0; num3 < num; num3++)
				{
					bool flag2 = false;
					for (int num4 = Math.Max(0, n - num2); num4 <= Math.Min(num - 1, n + num2); num4++)
					{
						if (flag2)
						{
							break;
						}
						flag2 = array2[num3, num4];
					}
					array3[num3, n] = flag2;
				}
			}
			Color val = Color.Lerp(col, Color.white, 0.45f);
			Color val2 = Color.Lerp(col, Color.black, 0.2f);
			Color val3 = default(Color);
			((Color)(ref val3))..ctor(0.08f, 0.06f, 0.05f, 1f);
			Texture2D val4 = new Texture2D(64, 64, (TextureFormat)4, false)
			{
				wrapMode = (TextureWrapMode)1,
				filterMode = (FilterMode)1
			};
			Color[] array4 = (Color[])(object)new Color[4096];
			for (int num5 = 0; num5 < 64; num5++)
			{
				for (int num6 = 0; num6 < 64; num6++)
				{
					int num7 = 0;
					int num8 = 0;
					for (int num9 = 0; num9 < 4; num9++)
					{
						for (int num10 = 0; num10 < 4; num10++)
						{
							if (array[num6 * 4 + num10, num5 * 4 + num9])
							{
								num7++;
							}
							if (array3[num6 * 4 + num10, num5 * 4 + num9])
							{
								num8++;
							}
						}
					}
					float num11 = (float)num7 / 16f;
					float num12 = (float)num8 / 16f;
					Color val5 = Color.Lerp(val2, val, (float)num5 / 63f);
					Color val6 = Color.Lerp(val3, val5, (num12 > 0f) ? (num11 / num12) : 0f);
					val6.a = num12;
					array4[num5 * 64 + num6] = val6;
				}
			}
			val4.SetPixels(array4);
			val4.Apply(false);
			return val4;
		}
	}
	public enum Aspect
	{
		None,
		Fire,
		Frost,
		Water,
		Electric,
		Poison,
		Dark,
		Nature,
		Stone,
		Beast,
		Arcane
	}
	public static class Aspects
	{
		private struct Def
		{
			public DamageType[] Resist;

			public DamageType[] Weak;
		}

		public static readonly int ZAspect = StringExtensionMethods.GetStableHashCode("cb_aspect");

		public static readonly int ZShiny = StringExtensionMethods.GetStableHashCode("cb_shiny");

		public static Aspect PendingAspect;

		public static bool SuppressNext;

		public static bool PendingShiny;

		public static readonly Dictionary<Aspect, string> Color = new Dictionary<Aspect, string>
		{
			[Aspect.Fire] = "#ff6a2a",
			[Aspect.Frost] = "#9fe3ff",
			[Aspect.Water] = "#3d8bff",
			[Aspect.Electric] = "#ffe14a",
			[Aspect.Poison] = "#8fd14f",
			[Aspect.Dark] = "#a77bd6",
			[Aspect.Nature] = "#4caf50",
			[Aspect.Stone] = "#b0a089",
			[Aspect.Beast] = "#d9a066",
			[Aspect.Arcane] = "#e07bff"
		};

		private static readonly Dictionary<Aspect, Def> Defence = new Dictionary<Aspect, Def>
		{
			[Aspect.Fire] = D(R((DamageType)32), W((DamageType)64)),
			[Aspect.Frost] = D(R((DamageType)64), W((DamageType)32)),
			[Aspect.Water] = D(R((DamageType)32), W((DamageType)128)),
			[Aspect.Electric] = D(R((DamageType)128), W((DamageType)1)),
			[Aspect.Poison] = D(R((DamageType)256), W((DamageType)512)),
			[Aspect.Dark] = D(R((DamageType)2), W((DamageType)512)),
			[Aspect.Nature] = D(R((DamageType)256), W((DamageType)32, (DamageType)2)),
			[Aspect.Stone] = D(R((DamageType)2, (DamageType)4), W((DamageType)1)),
			[Aspect.Beast] = D(R((DamageType)1), W((DamageType)4)),
			[Aspect.Arcane] = D(R((DamageType)128, (DamageType)512), W((DamageType)4))
		};

		private static readonly Dictionary<string, Aspect> Natural = new Dictionary<string, Aspect>
		{
			["Sheep_TW"] = Aspect.Beast,
			["Lamb_TW"] = Aspect.Beast,
			["GreydwarfMage_TW"] = Aspect.Nature,
			["SkeletonMage_TW"] = Aspect.Dark,
			["FenringMage_TW"] = Aspect.Frost,
			["GoblinMage_TW"] = Aspect.Fire,
			["CorruptedDvergerMage_TW"] = Aspect.Arcane,
			["Fox_TW"] = Aspect.Beast,
			["FoxCub_TW"] = Aspect.Beast,
			["Razorback_TW"] = Aspect.Beast,
			["RazorbackPiggy_TW"] = Aspect.Beast,
			["GDAncientShaman_TW"] = Aspect.Nature,
			["GDAncientShaman_rootspawn_TW"] = Aspect.Nature,
			["BossAsmodeus_TW"] = Aspect.Fire,
			["BossSvalt_TW"] = Aspect.Dark,
			["BurningHunger_TW"] = Aspect.Fire,
			["RottingElk_TW"] = Aspect.Poison,
			["Crawler_TW"] = Aspect.Poison,
			["DamnedOne_TW"] = Aspect.Dark,
			["HelWraith_TW"] = Aspect.Dark,
			["BossVrykolathas_TW"] = Aspect.Dark,
			["GrizzlyBear_TW"] = Aspect.Beast,
			["GrizzlyBearCub_TW"] = Aspect.Beast,
			["ObsidianGolem_TW"] = Aspect.Stone,
			["Shark_TW"] = Aspect.Water,
			["Prowler_TW"] = Aspect.Beast,
			["ProwlerCub_TW"] = Aspect.Beast,
			["Boar"] = Aspect.Beast,
			["Deer"] = Aspect.Beast,
			["Neck"] = Aspect.Water,
			["Hare"] = Aspect.Beast,
			["Chicken"] = Aspect.Beast,
			["Hen"] = Aspect.Beast,
			["Lox"] = Aspect.Beast,
			["Bjorn"] = Aspect.Beast,
			["Greyling"] = Aspect.Nature,
			["Greydwarf"] = Aspect.Nature,
			["Greydwarf_Elite"] = Aspect.Stone,
			["Greydwarf_Shaman"] = Aspect.Poison,
			["Troll"] = Aspect.Stone,
			["Skeleton"] = Aspect.Dark,
			["Skeleton_Poison"] = Aspect.Poison,
			["Ghost"] = Aspect.Dark,
			["Wraith"] = Aspect.Dark,
			["Draugr"] = Aspect.Dark,
			["Draugr_Elite"] = Aspect.Dark,
			["Draugr_Ranged"] = Aspect.Dark,
			["Blob"] = Aspect.Poison,
			["BlobElite"] = Aspect.Poison,
			["BlobTar"] = Aspect.Dark,
			["Leech"] = Aspect.Water,
			["Surtling"] = Aspect.Fire,
			["Abomination"] = Aspect.Nature,
			["Wolf"] = Aspect.Frost,
			["Fenring"] = Aspect.Frost,
			["Fenring_Cultist"] = Aspect.Fire,
			["Hatchling"] = Aspect.Frost,
			["CB_DragonQueen"] = Aspect.Frost,
			["StoneGolem"] = Aspect.Stone,
			["Ulv"] = Aspect.Frost,
			["Bat"] = Aspect.Dark,
			["Deathsquito"] = Aspect.Poison,
			["Goblin"] = Aspect.Fire,
			["GoblinArcher"] = Aspect.Fire,
			["GoblinBrute"] = Aspect.Stone,
			["GoblinShaman"] = Aspect.Fire,
			["Serpent"] = Aspect.Water,
			["Seeker"] = Aspect.Arcane,
			["SeekerBrute"] = Aspect.Arcane,
			["SeekerBrood"] = Aspect.Arcane,
			["Gjall"] = Aspect.Arcane,
			["Tick"] = Aspect.Arcane,
			["Dverger"] = Aspect.Arcane,
			["DvergerMage"] = Aspect.Arcane,
			["DvergerMageFire"] = Aspect.Fire,
			["DvergerMageIce"] = Aspect.Frost,
			["DvergerMageSupport"] = Aspect.Arcane,
			["Charred_Melee"] = Aspect.Fire,
			["Charred_Archer"] = Aspect.Fire,
			["Charred_Twitcher"] = Aspect.Fire,
			["Charred_Mage"] = Aspect.Fire,
			["Asksvin"] = Aspect.Fire,
			["Volture"] = Aspect.Fire,
			["Morgen"] = Aspect.Dark,
			["FallenValkyrie"] = Aspect.Electric,
			["BonemawSerpent"] = Aspect.Fire,
			["Eikthyr"] = Aspect.Electric,
			["gd_king"] = Aspect.Nature,
			["Bonemass"] = Aspect.Poison,
			["Dragon"] = Aspect.Frost,
			["GoblinKing"] = Aspect.Fire,
			["SeekerQueen"] = Aspect.Arcane,
			["Fader"] = Aspect.Fire,
			["Seal"] = Aspect.Water,
			["BabySeal"] = Aspect.Water,
			["FrostTroll"] = Aspect.Frost,
			["Moose"] = Aspect.Beast,
			["JotunWarrior"] = Aspect.Stone,
			["JotunWitch"] = Aspect.Arcane,
			["Kvastur"] = Aspect.Dark,
			["Writhan"] = Aspect.Dark,
			["Barka"] = Aspect.Frost,
			["DvergerDeepNorth"] = Aspect.Frost,
			["FrozenKing"] = Aspect.Frost
		};

		private static readonly Dictionary<Biome, Aspect[]> BiomePool = new Dictionary<Biome, Aspect[]>
		{
			[(Biome)1] = new Aspect[3]
			{
				Aspect.Beast,
				Aspect.Nature,
				Aspect.Water
			},
			[(Biome)8] = new Aspect[3]
			{
				Aspect.Nature,
				Aspect.Dark,
				Aspect.Stone
			},
			[(Biome)2] = new Aspect[3]
			{
				Aspect.Poison,
				Aspect.Dark,
				Aspect.Water
			},
			[(Biome)4] = new Aspect[3]
			{
				Aspect.Frost,
				Aspect.Stone,
				Aspect.Electric
			},
			[(Biome)16] = new Aspect[3]
			{
				Aspect.Beast,
				Aspect.Fire,
				Aspect.Electric
			},
			[(Biome)512] = new Aspect[3]
			{
				Aspect.Arcane,
				Aspect.Dark,
				Aspect.Electric
			},
			[(Biome)32] = new Aspect[3]
			{
				Aspect.Fire,
				Aspect.Dark,
				Aspect.Stone
			},
			[(Biome)64] = new Aspect[3]
			{
				Aspect.Frost,
				Aspect.Water,
				Aspect.Arcane
			},
			[(Biome)256] = new Aspect[3]
			{
				Aspect.Water,
				Aspect.Electric,
				Aspect.Frost
			}
		};

		private static Def D(DamageType[] r, DamageType[] w)
		{
			return new Def
			{
				Resist = r,
				Weak = w
			};
		}

		private static DamageType[] R(params DamageType[] t)
		{
			return t;
		}

		private static DamageType[] W(params DamageType[] t)
		{
			return t;
		}

		public static bool Eligible(Character c)
		{
			if ((Object)(object)c != (Object)null && !c.IsPlayer() && (Object)(object)c.GetBaseAI() != (Object)null && (Object)(object)c.m_nview != (Object)null && c.m_nview.GetZDO() != null)
			{
				return !IsSummon(c);
			}
			return false;
		}

		public static bool IsSummon(Character c)
		{
			Tameable val = (((Object)(object)c != (Object)null) ? ((Component)c).GetComponent<Tameable>() : null);
			if ((Object)(object)val != (Object)null)
			{
				if (!(val.m_unsummonDistance > 0f))
				{
					return val.m_unsummonOnOwnerLogoutSeconds > 0f;
				}
				return true;
			}
			return false;
		}

		public static Aspect Get(Character c, out bool shiny)
		{
			shiny = false;
			if (!Eligible(c))
			{
				return Aspect.None;
			}
			ZDO zDO = c.m_nview.GetZDO();
			shiny = zDO.GetBool(ZShiny, false);
			return (Aspect)zDO.GetInt(ZAspect, 0);
		}

		public static Aspect Get(Character c)
		{
			bool shiny;
			return Get(c, out shiny);
		}

		public static void Roll(Character c, out Aspect aspect, out bool shiny)
		{
			//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)
			//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)
			string prefabName = Utils.GetPrefabName(((Component)c).gameObject);
			Biome key = Heightmap.FindBiome(((Component)c).transform.position);
			if (!BiomePool.TryGetValue(key, out var value))
			{
				value = BiomePool[(Biome)1];
			}
			if (!Natural.TryGetValue(prefabName, out var value2))
			{
				value2 = value[0];
			}
			shiny = false;
			if (c.IsBoss())
			{
				aspect = (Aspect)Rng.Range(1, 11);
				return;
			}
			float value3 = Rng.Value;
			if (value3 < Plugin.ShinyChance.Value)
			{
				List<Aspect> list = new List<Aspect>();
				for (Aspect aspect2 = Aspect.Fire; aspect2 <= Aspect.Arcane; aspect2++)
				{
					if (aspect2 != value2 && Array.IndexOf(value, aspect2) < 0)
					{
						list.Add(aspect2);
					}
				}
				aspect = list[Rng.Range(0, list.Count)];
				shiny = true;
			}
			else if (c.IsBoss() || value3 < Plugin.ShinyChance.Value + Plugin.NaturalChance.Value)
			{
				aspect = value2;
			}
			else
			{
				aspect = value[Rng.Range(0, value.Length)];
			}
		}

		public static Aspect RareAspect(Character c)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			Biome key = Heightmap.FindBiome(((Component)c).transform.position);
			if (!BiomePool.TryGetValue(key, out var value))
			{
				value = BiomePool[(Biome)1];
			}
			if (!Natural.TryGetValue(Utils.GetPrefabName(((Component)c).gameObject), out var value2))
			{
				value2 = value[0];
			}
			List<Aspect> list = new List<Aspect>();
			for (Aspect aspect = Aspect.Fire; aspect <= Aspect.Arcane; aspect++)
			{
				if (aspect != value2 && Array.IndexOf(value, aspect) < 0)
				{
					list.Add(aspect);
				}
			}
			if (list.Count != 0)
			{
				return list[Rng.Range(0, list.Count)];
			}
			return Aspect.None;
		}

		public static void Set(Character c, Aspect a, bool shiny)
		{
			ZDO zDO = c.m_nview.GetZDO();
			zDO.Set(ZAspect, (int)a, false);
			zDO.Set(ZShiny, shiny);
			((Component)c).GetComponent<AspectHolder>()?.Apply(force: true);
		}

		public static string Label(Aspect a, bool shiny)
		{
			if (a == Aspect.None)
			{
				return "";
			}
			string text = $"<color={Color[a]}>{a}</color>";
			if (!shiny)
			{
				return text;
			}
			return "<color=#ffd700>Shiny</color> " + text;
		}

		public static void ApplyDefence(ref DamageModifiers mods, Aspect a)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			if (Defence.TryGetValue(a, out var value))
			{
				DamageType[] resist = value.Resist;
				foreach (DamageType t in resist)
				{
					Upgrade(ref mods, t, (DamageModifier)1);
				}
				resist = value.Weak;
				foreach (DamageType t2 in resist)
				{
					Downgrade(ref mods, t2, (DamageModifier)2);
				}
			}
		}

		private static void Upgrade(ref DamageModifiers mods, DamageType t, DamageModifier to)
		{
			//IL_0001: 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_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Invalid comparison between Unknown and I4
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Invalid comparison between Unknown and I4
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Invalid comparison between Unknown and I4
			DamageModifier modifier = ((DamageModifiers)(ref mods)).GetModifier(t);
			if ((int)modifier == 0 || (int)modifier == 8 || (int)modifier == 2 || (int)modifier == 6 || (int)modifier == 7)
			{
				Set(ref mods, t, to);
			}
		}

		private static void Downgrade(ref DamageModifiers mods, DamageType t, DamageModifier to)
		{
			//IL_0001: 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_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL o