Decompiled source of CrimsonUtility v0.1.4

CrimsonUtility.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.Json;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using CrimsonUtility.Services;
using CrimsonUtility.Structs;
using CrimsonUtility.Utility;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.CastleBuilding;
using ProjectM.Network;
using ProjectM.Scripting;
using Stunlock.Core;
using Stunlock.Network;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
using VAMP;
using VAMP.Data;
using VAMP.Models;
using VAMP.Services;
using VAMP.Utilities;
using VampireCommandFramework;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("CrimsonUtility")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Created with VRising.ModTemplate, you should edit this.")]
[assembly: AssemblyFileVersion("0.1.4.0")]
[assembly: AssemblyInformationalVersion("0.1.4+1.Branch.master.Sha.899ecbae2d864f5607fead757449d744b43bb52d.899ecbae2d864f5607fead757449d744b43bb52d")]
[assembly: AssemblyProduct("CrimsonUtility")]
[assembly: AssemblyTitle("CrimsonUtility")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.4.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;
		}
	}
}
[CommandGroup("utility", "util")]
internal static class ProtectionCommands
{
}
[HarmonyPatch]
internal static class StartCraftingSystemPatch
{
	[HarmonyPatch(typeof(StartCraftingSystem), "OnUpdate")]
	public static void Prefix(StartCraftingSystem __instance)
	{
		//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)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: 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_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		if (!Core.hasInitialized || !Settings.CraftBlocker.Value)
		{
			return;
		}
		EntityQuery startCraftItemEventQuery = __instance._StartCraftItemEventQuery;
		NativeArray<Entity> val = ((EntityQuery)(ref startCraftItemEventQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
		try
		{
			Enumerator<Entity> enumerator = val.GetEnumerator();
			StartCraftItemEvent val2 = default(StartCraftItemEvent);
			FromCharacter val3 = default(FromCharacter);
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				DevUtil.Dump(current, "CraftStart.txt");
				if (EntityUtil.TryGetComponent<StartCraftItemEvent>(current, ref val2) && EntityUtil.TryGetComponent<FromCharacter>(current, ref val3))
				{
					PrefabGUID recipeId = val2.RecipeId;
					GetItemFromRecipePrefab(Core.SystemService.PrefabCollectionSystem._PrefabGuidToEntityMap.ContainsKey(recipeId) ? Core.SystemService.PrefabCollectionSystem._PrefabGuidToEntityMap[recipeId] : Entity.Null);
					if (Database.BlockedCrafts.Contains(recipeId))
					{
						EntityManager entityManager = Core.EntityManager;
						Entity val4 = ((EntityManager)(ref entityManager)).CreateEntity((ComponentType[])(object)new ComponentType[3]
						{
							ComponentType.ReadOnly<NetworkEventType>(),
							ComponentType.ReadOnly<StopCraftItemEvent>(),
							ComponentType.ReadOnly<FromCharacter>()
						});
						EntityUtil.Write<NetworkEventType>(val4, new NetworkEventType
						{
							EventId = NetworkEvents.EventId_StopCraftItemEvent,
							IsAdminEvent = false,
							IsDebugEvent = false
						});
						EntityUtil.Write<StopCraftItemEvent>(val4, new StopCraftItemEvent
						{
							Workstation = val2.Workstation,
							RecipeGuid = val2.RecipeId
						});
						EntityUtil.Write<FromCharacter>(val4, val3);
					}
				}
			}
		}
		finally
		{
			val.Dispose();
		}
	}

	private static PrefabGUID GetItemFromRecipePrefab(Entity recipePrefab)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		if (EntityUtil.Exists(recipePrefab) && EntityUtil.Has<RecipeData>(recipePrefab))
		{
			return EntityUtil.ReadBuffer<RecipeOutputBuffer>(recipePrefab)[0].Guid;
		}
		return PrefabGUID.Empty;
	}
}
namespace CrimsonUtility
{
	[BepInPlugin("CrimsonUtility", "CrimsonUtility", "0.1.4")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		private Harmony _harmony;

		internal static Plugin Instance { get; private set; }

		public static Settings Settings { get; private set; }

		public static Harmony Harmony => Instance._harmony;

		public static ManualLogSource LogInstance => ((BasePlugin)Instance).Log;

		public static string ConfigFiles => Path.Combine(Paths.ConfigPath, "CrimsonUtility");

		public static GolemService GolemService { get; private set; }

		public static Database Database { get; internal set; }

		public override void Load()
		{
			Instance = this;
			Settings = default(Settings);
			if (Settings.InitConfig())
			{
				_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
				CommandRegistry.RegisterAll();
				Events.OnCoreLoaded = (Action)Delegate.Combine(Events.OnCoreLoaded, new Action(Loaded));
			}
		}

		public void Loaded()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			GolemService = new GolemService();
			Database = new Database();
			ActivityTracking.InitializeData();
			ActivityTracking.StartLoop();
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(27, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("CrimsonUtility");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" version ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("0.1.4");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
			}
			log.LogInfo(val);
		}

		public override bool Unload()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			return true;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "CrimsonUtility";

		public const string PLUGIN_NAME = "CrimsonUtility";

		public const string PLUGIN_VERSION = "0.1.4";
	}
}
namespace CrimsonUtility.Utility
{
	public static class ChatUtility
	{
		public static void ReplyWithPagination(ChatCommandContext ctx, string response)
		{
			if (response.Length <= ChatUtil.MESSAGE_LIMIT)
			{
				ctx.Reply(response);
				return;
			}
			List<string> list = SplitMessage(response, ChatUtil.MESSAGE_LIMIT);
			for (int i = 0; i < list.Count; i++)
			{
				string text = ((list.Count > 1) ? $" ({i + 1}/{list.Count})" : "");
				ctx.Reply(list[i] + text);
			}
		}

		private static List<string> SplitMessage(string message, int maxLength)
		{
			List<string> list = new List<string>();
			if (string.IsNullOrEmpty(message))
			{
				return list;
			}
			string[] array = message.Split('\n');
			string text = "";
			string[] array2 = array;
			foreach (string text2 in array2)
			{
				if (text.Length + text2.Length + 1 > maxLength)
				{
					if (!string.IsNullOrEmpty(text))
					{
						list.Add(text.TrimEnd());
						text = "";
					}
					if (text2.Length > maxLength)
					{
						List<string> collection = SplitLongLine(text2, maxLength);
						list.AddRange(collection);
					}
					else
					{
						text = text2 + "\n";
					}
				}
				else
				{
					text = text + text2 + "\n";
				}
			}
			if (!string.IsNullOrEmpty(text))
			{
				list.Add(text.TrimEnd());
			}
			return list;
		}

		private static List<string> SplitLongLine(string line, int maxLength)
		{
			List<string> list = new List<string>();
			string[] array = line.Split(' ');
			string text = "";
			string[] array2 = array;
			foreach (string text2 in array2)
			{
				if (text.Length + text2.Length + 1 > maxLength)
				{
					if (!string.IsNullOrEmpty(text))
					{
						list.Add(text.TrimEnd());
						text = "";
					}
					if (text2.Length > maxLength)
					{
						list.Add(text2.Substring(0, maxLength - 3) + "...");
					}
					else
					{
						text = text2 + " ";
					}
				}
				else
				{
					text = text + text2 + " ";
				}
			}
			if (!string.IsNullOrEmpty(text))
			{
				list.Add(text.TrimEnd());
			}
			return list;
		}
	}
	public static class TimeUtility
	{
		public static string FormatRemainder(DateTime date)
		{
			return FormatRemainder(date - DateTime.Now);
		}

		public static string FormatRemainder(TimeSpan remainder)
		{
			string text = string.Empty;
			if (remainder.Days > 0)
			{
				text += $"{remainder.Days} day{((remainder.Days > 1) ? "s" : "")}, ";
			}
			if (remainder.Hours > 0)
			{
				text += $"{remainder.Hours} hour{((remainder.Hours > 1) ? "s" : "")}, ";
			}
			if (remainder.Minutes > 0)
			{
				text += $"{remainder.Minutes} minute{((remainder.Minutes > 1) ? "s" : "")}, ";
			}
			if (remainder.Seconds > 0)
			{
				text += $"{remainder.Seconds} second{((remainder.Seconds > 1) ? "s" : "")}";
			}
			if (text.EndsWith(", "))
			{
				text = text.Substring(0, text.Length - 2);
			}
			return text;
		}
	}
}
namespace CrimsonUtility.Structs
{
	public class Database
	{
		public static string CraftBlockFile = Path.Combine(Plugin.ConfigFiles, "craft_block.txt");

		public static List<PrefabGUID> BlockedCrafts;

		public static List<int> ProtectedPlots;

		public Database()
		{
			BlockedCrafts = new List<PrefabGUID>();
			LoadBlockedCrafts();
		}

		public static void LoadBlockedCrafts()
		{
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Expected O, but got Unknown
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			if (!Settings.CraftBlocker.Value)
			{
				return;
			}
			bool flag = default(bool);
			if (File.Exists(CraftBlockFile))
			{
				try
				{
					string[] array = File.ReadAllLines(CraftBlockFile);
					foreach (string text in array)
					{
						if (!text.StartsWith("#") && int.TryParse(text, out var result))
						{
							BlockedCrafts.Add(new PrefabGUID(result));
						}
					}
					ManualLogSource logInstance = Plugin.LogInstance;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(23, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Loaded ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(BlockedCrafts.Count);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" blocked crafts.");
					}
					logInstance.LogInfo(val);
					return;
				}
				catch (Exception ex)
				{
					ManualLogSource logInstance2 = Plugin.LogInstance;
					BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(31, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Failed to load blocked crafts: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
					}
					logInstance2.LogError(val2);
					return;
				}
			}
			Directory.CreateDirectory(Path.GetDirectoryName(CraftBlockFile));
			File.Create(CraftBlockFile).Close();
		}
	}
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	public readonly struct Settings
	{
		public static ConfigEntry<bool> ToggleMod { get; private set; }

		public static ConfigEntry<bool> CraftBlocker { get; private set; }

		public static bool InitConfig()
		{
			ToggleMod = InitConfigEntry("General", "ToggleMod", defaultValue: false, "Enable or disable the mod.");
			CraftBlocker = InitConfigEntry("Systems", "CraftBlocker", defaultValue: false, "Blocks crafting of items that are listed in the craft_block.txt file");
			return ToggleMod.Value;
		}

		public static ConfigEntry<T> InitConfigEntry<T>(string section, string key, T defaultValue, string description)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			ConfigEntry<T> val = ((BasePlugin)Plugin.Instance).Config.Bind<T>(section, key, defaultValue, description);
			string text = Path.Combine(Paths.ConfigPath, "CrimsonUtility.cfg");
			ConfigEntry<T> val2 = default(ConfigEntry<T>);
			if (File.Exists(text) && new ConfigFile(text, true).TryGetEntry<T>(section, key, ref val2))
			{
				val.Value = val2.Value;
			}
			return val;
		}
	}
}
namespace CrimsonUtility.Services
{
	public static class ActivityTracking
	{
		public static string ActivityFile = Path.Combine(Plugin.ConfigFiles, "activity_tracking.json");

		public static int DataRetentionWeeks = 5;

		public static int loops = 0;

		public static Dictionary<string, List<ActivityData>> ActivityByWeek { get; set; }

		public static void StartLoop()
		{
			Core.StartCoroutine(Loop());
		}

		public static void InitializeData()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			if (ActivityByWeek != null)
			{
				return;
			}
			ActivityByWeek = new Dictionary<string, List<ActivityData>>();
			if (!Directory.Exists(Plugin.ConfigFiles))
			{
				Directory.CreateDirectory(Plugin.ConfigFiles);
			}
			if (!File.Exists(ActivityFile))
			{
				return;
			}
			try
			{
				ActivityByWeek = JsonSerializer.Deserialize<Dictionary<string, List<ActivityData>>>(File.ReadAllText(ActivityFile));
			}
			catch (Exception ex)
			{
				ManualLogSource logInstance = Plugin.LogInstance;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(29, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Error loading activity data: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				logInstance.LogError(val);
				ActivityByWeek = new Dictionary<string, List<ActivityData>>();
			}
		}

		public static string GetCurrentWeekKey()
		{
			return GetWeekKey(DateTime.Now);
		}

		public static string GetWeekKey(DateTime date)
		{
			int weekOfYear = CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(date, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
			int num = date.Year;
			if (weekOfYear == 1 && date.Month == 12)
			{
				num++;
			}
			else if (weekOfYear >= 52 && date.Month == 1)
			{
				num--;
			}
			return $"{num}-W{weekOfYear:D2}";
		}

		public static void AddData(ulong playerId)
		{
			InitializeData();
			string currentWeekKey = GetCurrentWeekKey();
			if (!ActivityByWeek.ContainsKey(currentWeekKey))
			{
				ActivityByWeek[currentWeekKey] = new List<ActivityData>();
			}
			List<ActivityData> list = ActivityByWeek[currentWeekKey];
			if (list.Exists((ActivityData x) => x.player_id == playerId))
			{
				list.First((ActivityData x) => x.player_id == playerId).login = DateTime.Now;
			}
			else
			{
				list.Add(new ActivityData(playerId));
			}
		}

		public static void LogTime(ulong playerId, bool isLoggedIn)
		{
			InitializeData();
			string currentWeekKey = GetCurrentWeekKey();
			if (ActivityByWeek.ContainsKey(currentWeekKey) && ActivityByWeek[currentWeekKey].Exists((ActivityData x) => x.player_id == playerId))
			{
				ActivityByWeek[currentWeekKey].First((ActivityData x) => x.player_id == playerId).LogTime(isLoggedIn);
			}
		}

		public static void LogAll()
		{
			InitializeData();
			string currentWeekKey = GetCurrentWeekKey();
			if (!ActivityByWeek.ContainsKey(currentWeekKey))
			{
				ActivityByWeek[currentWeekKey] = new List<ActivityData>();
			}
			List<User> list = (from x in PlayerService.GetUsersOnline()
				select EntityUtil.Read<User>(x)).ToList();
			foreach (ActivityData data in ActivityByWeek[currentWeekKey])
			{
				data.LogTime(list.Exists((User x) => x.PlatformId == data.player_id));
			}
		}

		public static void SubmitTimes()
		{
			InitializeData();
			RemoveOldData();
			string contents = JsonSerializer.Serialize(ActivityByWeek);
			File.WriteAllText(ActivityFile, contents);
		}

		public static void RemoveOldData()
		{
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			if (ActivityByWeek == null)
			{
				return;
			}
			string weekKey = GetWeekKey(DateTime.Now.AddDays(-DataRetentionWeeks * 7));
			List<string> list = new List<string>();
			foreach (string key in ActivityByWeek.Keys)
			{
				if (IsWeekOlderThan(key, weekKey))
				{
					list.Add(key);
				}
			}
			foreach (string item in list)
			{
				ActivityByWeek.Remove(item);
			}
			if (list.Count > 0)
			{
				ManualLogSource logInstance = Plugin.LogInstance;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(53, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Removed ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(list.Count);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" weeks of old activity data older than ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(DataRetentionWeeks);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" weeks");
				}
				logInstance.LogInfo(val);
			}
		}

		private static bool IsWeekOlderThan(string weekKey1, string weekKey2)
		{
			if (!TryParseWeekKey(weekKey1, out var year, out var week) || !TryParseWeekKey(weekKey2, out var year2, out var week2))
			{
				return false;
			}
			if (year < year2)
			{
				return true;
			}
			if (year > year2)
			{
				return false;
			}
			return week < week2;
		}

		private static bool TryParseWeekKey(string weekKey, out int year, out int week)
		{
			year = 0;
			week = 0;
			if (string.IsNullOrEmpty(weekKey) || !weekKey.Contains("-W"))
			{
				return false;
			}
			string[] array = weekKey.Split('-');
			if (array.Length != 2 || !array[1].StartsWith("W"))
			{
				return false;
			}
			if (!int.TryParse(array[0], out year))
			{
				return false;
			}
			return int.TryParse(array[1].Substring(1), out week);
		}

		public static List<(ulong PlayerId, double TotalSeconds)> GetLowestActivityPlayers(int count, int numberOfWeeks = 4)
		{
			InitializeData();
			List<string> recentWeekKeys = GetRecentWeekKeys(numberOfWeeks);
			Dictionary<ulong, double> dictionary = new Dictionary<ulong, double>();
			foreach (string item in recentWeekKeys)
			{
				if (!ActivityByWeek.ContainsKey(item))
				{
					continue;
				}
				foreach (ActivityData item2 in ActivityByWeek[item])
				{
					if (!dictionary.ContainsKey(item2.player_id))
					{
						dictionary[item2.player_id] = 0.0;
					}
					dictionary[item2.player_id] += item2.seconds;
				}
			}
			return (from kvp in dictionary
				select (PlayerId: kvp.Key, TotalSeconds: kvp.Value) into item
				orderby item.TotalSeconds
				select item).Take(count).ToList();
		}

		public static List<(ulong PlayerId, double TotalSeconds)> GetLowestActivityPlayers(List<ulong> playerIds, int count, int numberOfWeeks = 4)
		{
			InitializeData();
			if (playerIds == null || playerIds.Count == 0)
			{
				return new List<(ulong, double)>();
			}
			HashSet<ulong> hashSet = new HashSet<ulong>(playerIds);
			List<string> recentWeekKeys = GetRecentWeekKeys(numberOfWeeks);
			Dictionary<ulong, double> dictionary = new Dictionary<ulong, double>();
			foreach (ulong playerId in playerIds)
			{
				dictionary[playerId] = 0.0;
			}
			foreach (string item in recentWeekKeys)
			{
				if (!ActivityByWeek.ContainsKey(item))
				{
					continue;
				}
				foreach (ActivityData item2 in ActivityByWeek[item])
				{
					if (hashSet.Contains(item2.player_id))
					{
						dictionary[item2.player_id] += item2.seconds;
					}
				}
			}
			return (from kvp in dictionary
				select (PlayerId: kvp.Key, TotalSeconds: kvp.Value) into item
				orderby item.TotalSeconds
				select item).Take(count).ToList();
		}

		public static double GetPlayerTotalActivity(ulong playerId, int numberOfWeeks = 4)
		{
			InitializeData();
			List<string> recentWeekKeys = GetRecentWeekKeys(numberOfWeeks);
			double num = 0.0;
			foreach (string item in recentWeekKeys)
			{
				if (!ActivityByWeek.ContainsKey(item))
				{
					continue;
				}
				foreach (ActivityData item2 in ActivityByWeek[item].Where((ActivityData p) => p.player_id == playerId))
				{
					num += item2.seconds;
				}
			}
			return num;
		}

		public static double GetPlayerWeeklyActivity(ulong playerId, string weekKey)
		{
			InitializeData();
			if (!ActivityByWeek.ContainsKey(weekKey))
			{
				return 0.0;
			}
			return ActivityByWeek[weekKey].FirstOrDefault((ActivityData p) => p.player_id == playerId)?.seconds ?? 0.0;
		}

		public static List<string> GetRecentWeekKeys(int numberOfWeeks)
		{
			List<string> list = new List<string>();
			DateTime now = DateTime.Now;
			for (int i = 0; i < numberOfWeeks; i++)
			{
				DateTime date = now.AddDays(-i * 7);
				list.Add(GetWeekKey(date));
			}
			return list;
		}

		public static Dictionary<string, double> GetPlayerWeeklyBreakdown(ulong playerId, int numberOfWeeks = 8)
		{
			InitializeData();
			List<string> recentWeekKeys = GetRecentWeekKeys(numberOfWeeks);
			Dictionary<string, double> dictionary = new Dictionary<string, double>();
			foreach (string item in recentWeekKeys)
			{
				dictionary[item] = GetPlayerWeeklyActivity(playerId, item);
			}
			return dictionary;
		}

		public static IEnumerator Loop()
		{
			while (true)
			{
				yield return (object)new WaitForSeconds(190f);
				LogAll();
				loops++;
				if (loops >= 1)
				{
					SubmitTimes();
					loops = 0;
				}
			}
		}
	}
	public class ActivityData
	{
		public ulong player_id { get; set; }

		public DateTime login { get; set; } = DateTime.MinValue;

		public double seconds { get; set; }

		public ActivityData()
		{
		}

		public ActivityData(ulong playerId)
		{
			player_id = playerId;
			login = DateTime.Now;
			seconds = 0.0;
		}

		public void LogTime(bool isLoggedIn)
		{
			if (!(login == DateTime.MinValue))
			{
				double totalSeconds = (DateTime.Now - login).TotalSeconds;
				seconds += totalSeconds;
				if (!isLoggedIn)
				{
					login = DateTime.MinValue;
				}
				else
				{
					login = DateTime.Now;
				}
			}
		}

		public double SubmitTime()
		{
			double result = seconds;
			seconds = 0.0;
			return result;
		}
	}
	public class GolemService
	{
		public static EntityQuery GolemQuery;

		public GolemService()
		{
			//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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0049: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = Core.EntityManager;
			EntityQueryDesc[] array = new EntityQueryDesc[1];
			EntityQueryDesc val = new EntityQueryDesc();
			val.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[4]
			{
				ComponentType.ReadOnly<SiegeWeapon>(),
				ComponentType.ReadOnly<UserOwner>(),
				ComponentType.ReadOnly<BlueprintData>(),
				ComponentType.ReadOnly<CreateGameplayEventsOnTimePassed>()
			});
			array[0] = val;
			GolemQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)array);
		}

		public static bool TryGetTimeUntilReady(Entity golem, out TimeSpan timeUntil)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			ServerGameManager serverGameManager = Core.ServerGameManager;
			Entity val = default(Entity);
			if (((ServerGameManager)(ref serverGameManager)).TryGetBuff(golem, PrefabIdentifier.op_Implicit(new PrefabGUID(-1602570831)), ref val))
			{
				Age val2 = EntityUtil.Read<Age>(val);
				LifeTime val3 = EntityUtil.Read<LifeTime>(val);
				timeUntil = TimeSpan.FromSeconds(val3.Duration - val2.Value);
				return true;
			}
			timeUntil = TimeSpan.Zero;
			return false;
		}

		public static bool TryGetUser(Entity golem, out User user)
		{
			//IL_0001: 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_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			user = default(User);
			if (EntityUtil.Has<UserOwner>(golem))
			{
				user = EntityUtil.Read<User>(EntityUtil.Read<UserOwner>(golem).Owner._Entity);
				return true;
			}
			return false;
		}
	}
	internal class RaidService
	{
		private static readonly object _lock = new object();

		private static Dictionary<Entity, CastleHeart> Raids = new Dictionary<Entity, CastleHeart>();

		private static bool active = false;

		private static Coroutine monitorCoroutine = null;

		public static bool TryGetRaidNext(int currentIndex, out Entity heart)
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_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: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			if (!active || Raids.Count == 0)
			{
				heart = Entity.Null;
				return false;
			}
			try
			{
				List<Entity> list = Raids.Keys.ToList();
				if (currentIndex == -1)
				{
					heart = list.FirstOrDefault();
					return EntityUtil.Exists(heart);
				}
				if (currentIndex >= list.Count - 1)
				{
					heart = list[0];
					return EntityUtil.Exists(heart);
				}
				heart = list[currentIndex + 1];
				return EntityUtil.Exists(heart);
			}
			catch (Exception ex)
			{
				ManualLogSource logInstance = Plugin.LogInstance;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(25, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Error in TryGetRaidNext: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				logInstance.LogError(val);
				heart = Entity.Null;
				return false;
			}
		}

		public static void StartRaidMonitor(Entity breached)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Expected O, but got Unknown
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			if (!EntityUtil.Exists(breached))
			{
				Plugin.LogInstance.LogWarning((object)"StartRaidMonitor: Breached entity does not exist");
				return;
			}
			try
			{
				Entity val = (EntityUtil.Has<CastleHeartConnection>(breached) ? EntityUtil.Read<CastleHeartConnection>(breached).CastleHeartEntity._Entity : Entity.Null);
				if (!EntityUtil.Exists(val))
				{
					Plugin.LogInstance.LogWarning((object)"StartRaidMonitor: Castle heart entity does not exist");
					return;
				}
				if (!EntityUtil.Has<CastleHeart>(val))
				{
					Plugin.LogInstance.LogWarning((object)"StartRaidMonitor: Entity does not have CastleHeart component");
					return;
				}
				CastleHeart value = EntityUtil.Read<CastleHeart>(val);
				lock (_lock)
				{
					if (!Raids.ContainsKey(val))
					{
						if (!active)
						{
							Raids.Clear();
							Raids.Add(val, value);
							StopMonitorIfRunning();
							monitorCoroutine = Core.StartCoroutine(RaidMonitor());
						}
						else
						{
							Raids.Add(val, value);
						}
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logInstance = Plugin.LogInstance;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(27, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Error in StartRaidMonitor: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
				}
				logInstance.LogError(val2);
			}
		}

		private static void StopMonitorIfRunning()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			if (monitorCoroutine == null)
			{
				return;
			}
			try
			{
				Core.StopCoroutine(monitorCoroutine);
			}
			catch (Exception ex)
			{
				ManualLogSource logInstance = Plugin.LogInstance;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(26, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Error stopping coroutine: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				logInstance.LogError(val);
			}
			monitorCoroutine = null;
		}

		public static void Shutdown()
		{
			StopMonitorIfRunning();
			lock (_lock)
			{
				active = false;
				Raids.Clear();
			}
		}

		private static IEnumerator RaidMonitor()
		{
			active = true;
			yield return null;
			bool flag = default(bool);
			bool flag2 = default(bool);
			while (active)
			{
				try
				{
					lock (_lock)
					{
						if (Raids.Count == 0)
						{
							active = false;
							monitorCoroutine = null;
							break;
						}
						List<Entity> list = new List<Entity>();
						foreach (KeyValuePair<Entity, CastleHeart> raid in Raids)
						{
							Entity key = raid.Key;
							if (!EntityUtil.Exists(key))
							{
								list.Add(key);
								continue;
							}
							if (!EntityUtil.Has<CastleHeart>(key))
							{
								list.Add(key);
								continue;
							}
							try
							{
								CastleHeart val = EntityUtil.Read<CastleHeart>(key);
								if (!((CastleHeart)(ref val)).IsSieged())
								{
									list.Add(key);
								}
							}
							catch (Exception ex)
							{
								ManualLogSource logInstance = Plugin.LogInstance;
								BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(29, 1, ref flag);
								if (flag)
								{
									((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Error checking castle heart: ");
									((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
								}
								logInstance.LogError(val2);
								list.Add(key);
							}
						}
						foreach (Entity item in list)
						{
							Raids.Remove(item);
						}
					}
				}
				catch (Exception ex2)
				{
					ManualLogSource logInstance2 = Plugin.LogInstance;
					BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(22, 1, ref flag2);
					if (flag2)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Error in RaidMonitor: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex2.Message);
					}
					logInstance2.LogError(val2);
				}
				yield return (object)new WaitForSeconds(1f);
			}
		}
	}
}
namespace CrimsonUtility.Patches
{
	[HarmonyPatch(typeof(ServerBootstrapSystem), "OnUserConnected")]
	public static class OnUserConnectedPatch
	{
		public unsafe static void Postfix(ServerBootstrapSystem __instance, NetConnectionId netConnectionId)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				EntityManager entityManager = ((ComponentSystemBase)__instance).EntityManager;
				int num = __instance._NetEndPointToApprovedUserIndex[netConnectionId];
				Entity userEntity = ((Il2CppArrayBase<ServerClient>)(object)__instance._ApprovedUsersLookup)[num].UserEntity;
				User componentData = ((EntityManager)(ref entityManager)).GetComponentData<User>(userEntity);
				if (!((FixedString64Bytes)(ref componentData.CharacterName)).IsEmpty)
				{
					((object)(*(FixedString64Bytes*)(&componentData.CharacterName))/*cast due to .constrained prefix*/).ToString();
					ActivityTracking.AddData(componentData.PlatformId);
				}
			}
			catch (Exception ex)
			{
				((BasePlugin)Plugin.Instance).Log.LogError((object)ex.Message);
			}
		}
	}
	[HarmonyPatch(typeof(ServerBootstrapSystem), "OnUserDisconnected")]
	public static class OnUserDisconnectedPatch
	{
		private unsafe static void Prefix(ServerBootstrapSystem __instance, NetConnectionId netConnectionId, ConnectionStatusChangeReason connectionStatusReason, string extraData)
		{
			//IL_001b: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				int num = __instance._NetEndPointToApprovedUserIndex[netConnectionId];
				ServerClient val = ((Il2CppArrayBase<ServerClient>)(object)__instance._ApprovedUsersLookup)[num];
				EntityManager entityManager = ((ComponentSystemBase)__instance).EntityManager;
				User componentData = ((EntityManager)(ref entityManager)).GetComponentData<User>(val.UserEntity);
				if (!((FixedString64Bytes)(ref componentData.CharacterName)).IsEmpty)
				{
					((object)(*(FixedString64Bytes*)(&componentData.CharacterName))/*cast due to .constrained prefix*/).ToString();
					ActivityTracking.LogTime(componentData.PlatformId, isLoggedIn: false);
				}
			}
			catch
			{
			}
		}
	}
	[HarmonyPatch(typeof(Destroy_TravelBuffSystem), "OnUpdate")]
	public class Destroy_TravelBuffSystem_Patch
	{
		private static void Postfix(Destroy_TravelBuffSystem __instance)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_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_0046: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//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_0083: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			if (Core.PlayerService == null)
			{
				return;
			}
			EntityQuery _query_615927226_ = __instance.__query_615927226_0;
			Enumerator<Entity> enumerator = ((EntityQuery)(ref _query_615927226_)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2)).GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				EntityManager entityManager = ((ComponentSystemBase)__instance).EntityManager;
				PrefabGUID componentData = ((EntityManager)(ref entityManager)).GetComponentData<PrefabGUID>(current);
				if (((PrefabGUID)(ref componentData)).Equals(Prefabs.AB_Interact_TombCoffinSpawn_Travel))
				{
					entityManager = ((ComponentSystemBase)__instance).EntityManager;
					Entity owner = ((EntityManager)(ref entityManager)).GetComponentData<EntityOwner>(current).Owner;
					entityManager = ((ComponentSystemBase)__instance).EntityManager;
					if (!((EntityManager)(ref entityManager)).HasComponent<PlayerCharacter>(owner))
					{
						break;
					}
					entityManager = ((ComponentSystemBase)__instance).EntityManager;
					Entity userEntity = ((EntityManager)(ref entityManager)).GetComponentData<PlayerCharacter>(owner).UserEntity;
					entityManager = ((ComponentSystemBase)__instance).EntityManager;
					ActivityTracking.AddData(((EntityManager)(ref entityManager)).GetComponentData<User>(userEntity).PlatformId);
				}
			}
		}
	}
	[HarmonyPatch]
	internal static class DeathEventListenerSystemPatch
	{
		private static readonly PrefabGUID siegeGolem = Prefabs.AB_Shapeshift_Golem_T02_Buff;

		[HarmonyPatch(typeof(DeathEventListenerSystem), "OnUpdate")]
		private unsafe static void Postfix(DeathEventListenerSystem __instance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: 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)
			EntityQuery deathEventQuery = __instance._DeathEventQuery;
			NativeArray<DeathEvent> val = ((EntityQuery)(ref deathEventQuery)).ToComponentDataArray<DeathEvent>(AllocatorHandle.op_Implicit((Allocator)2));
			if (!Core.hasInitialized)
			{
				return;
			}
			try
			{
				Enumerator<DeathEvent> enumerator = val.GetEnumerator();
				Entity val3 = default(Entity);
				UserOwner val4 = default(UserOwner);
				while (enumerator.MoveNext())
				{
					DeathEvent current = enumerator.Current;
					if (!EntityUtil.Has<AnnounceCastleBreached>(current.Died))
					{
						continue;
					}
					StatChangeReason statChangeReason = current.StatChangeReason;
					if (((object)(*(StatChangeReason*)(&statChangeReason))/*cast due to .constrained prefix*/).Equals((object)(StatChangeReason)15))
					{
						ServerGameManager serverGameManager = Core.ServerGameManager;
						Entity killer = current.Killer;
						PrefabGUID val2 = siegeGolem;
						if (((ServerGameManager)(ref serverGameManager)).TryGetBuff(killer, ((PrefabGUID)(ref val2)).ToIdentifier(), ref val3))
						{
							RaidService.StartRaidMonitor(current.Died);
						}
						else if (EntityUtil.TryGetComponent<UserOwner>(current.Killer, ref val4))
						{
							RaidService.StartRaidMonitor(current.Died);
						}
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logInstance = Plugin.LogInstance;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val5 = new BepInExInfoLogInterpolatedStringHandler(44, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("Exited DeathEventListenerSystem hook early: ");
					((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<Exception>(ex);
				}
				logInstance.LogInfo(val5);
			}
			finally
			{
				val.Dispose();
			}
		}
	}
}
namespace CrimsonUtility.Commands
{
	[CommandGroup("utility", "util")]
	internal static class ActivityCommands
	{
		[Command("InactiveCastles", "ic", null, null, null, true)]
		public static void InactiveKeeps(ChatCommandContext ctx, int count = 10, int weeks = 4)
		{
			//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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			NativeArray<Entity> val = ((EntityQuery)(ref CastleHeartService.CastleHeartQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			List<ulong> list = new List<ulong>();
			Enumerator<Entity> enumerator = val.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				if (EntityUtil.Exists(current) && EntityUtil.Has<UserOwner>(current))
				{
					UserOwner val2 = EntityUtil.Read<UserOwner>(current);
					if (EntityUtil.Exists(val2.Owner._Entity))
					{
						User val3 = EntityUtil.Read<User>(val2.Owner._Entity);
						list.Add(val3.PlatformId);
					}
				}
			}
			if (list.Count == 0)
			{
				ctx.Reply("No castles found.");
				return;
			}
			List<(ulong PlayerId, double TotalSeconds)> lowestActivityPlayers = ActivityTracking.GetLowestActivityPlayers(list, count, weeks);
			List<string> list2 = new List<string>();
			Player val4 = default(Player);
			foreach (var item in lowestActivityPlayers)
			{
				if (PlayerService.TryFindBySteam(item.PlayerId, ref val4))
				{
					string text = FormatPlayTime(item.TotalSeconds);
					list2.Add("• " + val4.Name + ": " + text);
				}
			}
			string value = ((weeks == 1) ? "week" : "weeks");
			string text2 = $"<color=#def>Least Active Castle Owners</color> (Past {weeks} {value}):\n";
			if (list2.Count == 0)
			{
				text2 += "No activity data found for castle owners.";
			}
			else
			{
				text2 += string.Join("\n", list2);
				text2 += $"\n\nShowing {list2.Count} of {list.Count} castle owners";
			}
			ChatUtility.ReplyWithPagination(ctx, text2);
		}

		[Command("CheckActivity", "activity", null, null, null, true)]
		public static void CheckActivity(ChatCommandContext ctx, string name, int weeks = 4)
		{
			Player val = default(Player);
			if (!PlayerService.TryFindByName(name, ref val))
			{
				ctx.Reply("Player '" + name + "' not found");
				return;
			}
			string value = FormatPlayTime(ActivityTracking.GetPlayerTotalActivity(val.SteamID, weeks));
			string value2 = ((weeks == 1) ? "week" : "weeks");
			ctx.Reply($"<color=#def>{val.Name}</color>'s activity (Past {weeks} {value2}): {value}");
		}

		[Command("ActivityBreakdown", "ab", null, null, null, true)]
		public static void ActivityBreakdown(ChatCommandContext ctx, string name, int weeks = 4)
		{
			Player val = default(Player);
			if (!PlayerService.TryFindByName(name, ref val))
			{
				ctx.Reply("Player '" + name + "' not found");
				return;
			}
			Dictionary<string, double> playerWeeklyBreakdown = ActivityTracking.GetPlayerWeeklyBreakdown(val.SteamID, weeks);
			List<string> recentWeekKeys = ActivityTracking.GetRecentWeekKeys(weeks);
			string text = "<color=#def>" + val.Name + "</color>'s Weekly Activity Breakdown:\n";
			double num = 0.0;
			List<string> list = new List<string>();
			foreach (string item in recentWeekKeys)
			{
				double num2 = (playerWeeklyBreakdown.ContainsKey(item) ? playerWeeklyBreakdown[item] : 0.0);
				num += num2;
				string text2 = ((num2 > 0.0) ? FormatPlayTime(num2) : "No activity");
				string text3 = FormatWeekDisplay(item);
				list.Add("• " + text3 + ": " + text2);
			}
			text += string.Join("\n", list);
			text = text + "\n\n<color=#def>Total</color>: " + FormatPlayTime(num);
			ctx.Reply(text);
		}

		[Command("TopActive", "ta", null, null, null, true)]
		public static void TopActive(ChatCommandContext ctx, int count = 10, int weeks = 4)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			List<(ulong PlayerId, double TotalSeconds)> list = (from x in ActivityTracking.GetLowestActivityPlayers(EntityUtil.GetEntitiesByComponentType<User>(false, false, false, false, false).Length, weeks)
				orderby x.TotalSeconds descending
				select x).Take(count).ToList();
			List<string> list2 = new List<string>();
			Player val = default(Player);
			foreach (var item in list)
			{
				if (PlayerService.TryFindBySteam(item.PlayerId, ref val) && !(item.TotalSeconds <= 0.0))
				{
					string text = FormatPlayTime(item.TotalSeconds);
					list2.Add("• " + val.Name + ": " + text);
				}
			}
			string value = ((weeks == 1) ? "week" : "weeks");
			string text2 = $"<color=#def>Most Active Players</color> (Past {weeks} {value}):\n";
			text2 = ((list2.Count != 0) ? (text2 + string.Join("\n", list2)) : (text2 + "No activity data found."));
			ChatUtility.ReplyWithPagination(ctx, text2);
		}

		[Command("ActivityStats", "as", null, null, null, true)]
		public static void ActivityStats(ChatCommandContext ctx, int weeks = 4)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			NativeArray<Entity> entitiesByComponentType = EntityUtil.GetEntitiesByComponentType<User>(false, false, false, false, false);
			List<(ulong, double)> lowestActivityPlayers = ActivityTracking.GetLowestActivityPlayers(entitiesByComponentType.Length, weeks);
			if (lowestActivityPlayers.Count == 0)
			{
				ctx.Reply("No activity data available.");
				return;
			}
			List<(ulong, double)> list = lowestActivityPlayers.Where<(ulong, double)>(((ulong PlayerId, double TotalSeconds) x) => x.TotalSeconds > 0.0).ToList();
			double num = list.Sum<(ulong, double)>(((ulong PlayerId, double TotalSeconds) x) => x.TotalSeconds);
			double totalSeconds = ((list.Count > 0) ? (num / (double)list.Count) : 0.0);
			List<(ulong, double)> list2 = list.OrderByDescending<(ulong, double), double>(((ulong PlayerId, double TotalSeconds) x) => x.TotalSeconds).ToList();
			double totalSeconds2 = 0.0;
			if (list2.Count > 0)
			{
				int num2 = list2.Count / 2;
				totalSeconds2 = ((list2.Count % 2 == 0) ? ((list2[num2 - 1].Item2 + list2[num2].Item2) / 2.0) : list2[num2].Item2);
			}
			string value = ((weeks == 1) ? "week" : "weeks");
			string text = $"<color=#def>Server Activity Stats</color> (Past {weeks} {value}):\n\n";
			text += $"<color=#def>Players with Activity</color>: {list.Count} / {entitiesByComponentType.Length}\n";
			text = text + "<color=#def>Total Playtime</color>: " + FormatPlayTime(num) + "\n";
			text = text + "<color=#def>Average Playtime</color>: " + FormatPlayTime(totalSeconds) + "\n";
			text = text + "<color=#def>Median Playtime</color>: " + FormatPlayTime(totalSeconds2) + "\n";
			if (list2.Count > 0)
			{
				text = text + "<color=#def>Most Active</color>: " + FormatPlayTime(list2.First().Item2) + "\n";
				text = text + "<color=#def>Least Active</color>: " + FormatPlayTime(list2.Last().Item2);
			}
			ChatUtility.ReplyWithPagination(ctx, text);
		}

		[Command("InactivePlayers", "ip", null, null, null, true)]
		public static void InactivePlayers(ChatCommandContext ctx, int count = 10, int weeks = 4)
		{
			List<(ulong PlayerId, double TotalSeconds)> lowestActivityPlayers = ActivityTracking.GetLowestActivityPlayers(count, weeks);
			List<string> list = new List<string>();
			Player val = default(Player);
			foreach (var item in lowestActivityPlayers)
			{
				if (PlayerService.TryFindBySteam(item.PlayerId, ref val))
				{
					string text = ((item.TotalSeconds > 0.0) ? FormatPlayTime(item.TotalSeconds) : "No activity");
					list.Add("• " + val.Name + ": " + text);
				}
			}
			string value = ((weeks == 1) ? "week" : "weeks");
			string text2 = $"<color=#def>Least Active Players</color> (Past {weeks} {value}):\n";
			text2 = ((list.Count != 0) ? (text2 + string.Join("\n", list)) : (text2 + "No player data found."));
			ChatUtility.ReplyWithPagination(ctx, text2);
		}

		private static string FormatPlayTime(double totalSeconds)
		{
			if (totalSeconds <= 0.0)
			{
				return "0 minutes";
			}
			return TimeUtility.FormatRemainder(TimeSpan.FromSeconds(totalSeconds));
		}

		private static string FormatWeekDisplay(string weekKey)
		{
			if (string.IsNullOrEmpty(weekKey) || !weekKey.Contains("-W"))
			{
				return weekKey;
			}
			string[] array = weekKey.Split('-');
			if (array.Length != 2 || !array[1].StartsWith("W"))
			{
				return weekKey;
			}
			if (int.TryParse(array[0], out var result) && int.TryParse(array[1].Substring(1), out var result2))
			{
				return $"Week {result2}, {result}";
			}
			return weekKey;
		}
	}
	[CommandGroup("utility", "util")]
	internal static class CastleCommands
	{
		[Command("CastleTiles", "ct", null, null, null, true)]
		public static void CastleTiles(ChatCommandContext ctx, int min, int max)
		{
			//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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			NativeArray<Entity> val = ((EntityQuery)(ref CastleHeartService.CastleHeartQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			List<(string, int)> list = new List<(string, int)>();
			int num = 0;
			int num2 = 0;
			Enumerator<Entity> enumerator = val.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				if (!EntityUtil.Exists(current) || !EntityUtil.Has<UserOwner>(current))
				{
					continue;
				}
				UserOwner val2 = EntityUtil.Read<UserOwner>(current);
				if (EntityUtil.Exists(val2.Owner._Entity) && EntityUtil.Has<User>(val2.Owner._Entity))
				{
					CastleHeart val3 = EntityUtil.Read<CastleHeart>(current);
					num++;
					User val4 = EntityUtil.Read<User>(val2.Owner._Entity);
					string value = ((FixedString64Bytes)(ref val4.CharacterName)).Value;
					list.Add((value, val3.FloorCount));
					if (val3.FloorCount >= min && val3.FloorCount <= max)
					{
						num2++;
					}
				}
			}
			double value2 = ((num > 0) ? ((double)num2 / (double)num * 100.0) : 0.0);
			string text = $"Castles with {min}-{max} floor tiles: {num2}/{num} ({value2:F2}%)";
			ctx.Reply(text);
		}

		[Command("CastleTilesPlayer", "ctp", null, null, null, true)]
		public static void ListTiles(ChatCommandContext ctx, string name)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			Player val = default(Player);
			if (!PlayerService.TryFindByName(name, ref val))
			{
				ctx.Reply("Player " + name + " not found.");
				return;
			}
			Entity val2 = default(Entity);
			if (!CastleHeartService.TryGetByOwnerUser(EntityUtil.Read<User>(val.User), ref val2))
			{
				ctx.Reply("Player " + name + " does not own a castle.");
				return;
			}
			CastleHeart val3 = EntityUtil.Read<CastleHeart>(val2);
			ctx.Reply($"{val.Name}'s castle tiles: {val3.FloorCount}");
		}

		[Command("CastleTilesMax", "ctm", null, null, null, true)]
		public static void ListMaxTiles(ChatCommandContext ctx)
		{
			//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_001b: 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_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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			NativeArray<Entity> val = ((EntityQuery)(ref CastleHeartService.CastleHeartQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			List<(string, int)> list = new List<(string, int)>();
			int num = 0;
			Enumerator<Entity> enumerator = val.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				if (EntityUtil.Exists(current) && EntityUtil.Has<UserOwner>(current))
				{
					UserOwner val2 = EntityUtil.Read<UserOwner>(current);
					if (EntityUtil.Exists(val2.Owner._Entity) && EntityUtil.Has<User>(val2.Owner._Entity) && EntityUtil.Has<CastleHeart>(current))
					{
						CastleHeart val3 = EntityUtil.Read<CastleHeart>(current);
						num++;
						User val4 = EntityUtil.Read<User>(val2.Owner._Entity);
						string value = ((FixedString64Bytes)(ref val4.CharacterName)).Value;
						list.Add((value, val3.FloorCount));
					}
				}
			}
			if (num == 0)
			{
				ctx.Reply("No valid castles found.");
				return;
			}
			string value2 = "";
			int num2 = 0;
			foreach (var (text, num3) in list)
			{
				if (num3 > num2)
				{
					value2 = text;
					num2 = num3;
				}
			}
			string text2 = $"Castle owner with most tiles: {value2} ({num2} tiles)";
			ctx.Reply(text2);
		}
	}
	[CommandGroup("utility", "util")]
	internal static class ListCommands
	{
		private static readonly PrefabGUID SiegeGolem = new PrefabGUID(914043867);

		[Command("ListRaids", "lr", null, null, null, true)]
		public unsafe static void ListRaids(ChatCommandContext ctx)
		{
			//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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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)
			NativeArray<Entity> val = ((EntityQuery)(ref CastleHeartService.CastleHeartQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			List<Entity> list = new List<Entity>();
			Enumerator<Entity> enumerator = val.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				CastleHeart val2 = EntityUtil.Read<CastleHeart>(current);
				if (((CastleHeart)(ref val2)).IsSieged())
				{
					list.Add(current);
				}
			}
			if (list.Count == 0)
			{
				ctx.Reply("No raids found.");
				return;
			}
			string text = "\nCastles Under Raid (By Owner Name):\n";
			foreach (Entity item in list)
			{
				User val3 = EntityUtil.Read<User>(EntityUtil.Read<UserOwner>(item).Owner._Entity);
				string text2 = text;
				FixedString64Bytes characterName = val3.CharacterName;
				text = text2 + ((object)(*(FixedString64Bytes*)(&characterName))/*cast due to .constrained prefix*/).ToString() + "\n";
			}
			ctx.Reply(text);
		}

		[Command("ListGolems", "lg", null, null, null, true)]
		public static void ListGolems(ChatCommandContext ctx)
		{
			//IL_001b: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			IEnumerable<Entity> usersOnline = PlayerService.GetUsersOnline();
			string text = "";
			bool flag = false;
			Entity val = default(Entity);
			foreach (Entity item in usersOnline)
			{
				ServerGameManager serverGameManager = Core.ServerGameManager;
				Entity entity = EntityUtil.Read<User>(item).LocalCharacter._Entity;
				PrefabGUID siegeGolem = SiegeGolem;
				if (!((ServerGameManager)(ref serverGameManager)).TryGetBuff(entity, ((PrefabGUID)(ref siegeGolem)).ToIdentifier(), ref val))
				{
					continue;
				}
				DevUtil.Dump(val, "GolemBuff.txt");
				if (EntityUtil.Has<LifeTime>(val))
				{
					if (!flag)
					{
						text += "\nActive Golems:\n";
						flag = true;
					}
					LifeTime val2 = EntityUtil.Read<LifeTime>(val);
					User val3 = EntityUtil.Read<User>(item);
					Health val4 = EntityUtil.Read<Health>(val3.LocalCharacter._Entity);
					DateTime now = DateTime.Now;
					now.AddSeconds(val2.Duration);
					text += $"{val3.CharacterName} - {val4.Value}HP - Expires in {TimeUtility.FormatRemainder(now)}\n";
				}
			}
			NativeArray<Entity> val5 = ((EntityQuery)(ref GolemService.GolemQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			bool flag2 = false;
			bool flag3 = false;
			List<string> list = new List<string>();
			List<string> list2 = new List<string>();
			Enumerator<Entity> enumerator2 = val5.GetEnumerator();
			while (enumerator2.MoveNext())
			{
				Entity current2 = enumerator2.Current;
				if (!GolemService.TryGetUser(current2, out var user))
				{
					continue;
				}
				if (GolemService.TryGetTimeUntilReady(current2, out var timeUntil))
				{
					if (!flag2)
					{
						flag2 = true;
					}
					list.Add($"{user.CharacterName} - InstanceID = {current2.Index} - Summoned in {TimeUtility.FormatRemainder(timeUntil)}\n");
				}
				else
				{
					if (!flag3)
					{
						flag3 = true;
					}
					list2.Add($"{user.CharacterName} - InstanceID = {current2.Index}\n");
				}
			}
			val5.Dispose();
			if (flag3)
			{
				text += "\nSummoned Golems:\n";
				foreach (string item2 in list2)
				{
					text += item2;
				}
			}
			if (flag2)
			{
				text += "\nSummoning Golems:\n";
				foreach (string item3 in list)
				{
					text += item3;
				}
			}
			if (string.IsNullOrEmpty(text))
			{
				text = "No golems found.";
			}
			ctx.Reply(text);
		}
	}
	[CommandGroup("dev", null)]
	internal static class TempCommands
	{
		[Command("UnbindPlayer", null, null, null, null, true)]
		public static void UnbindPlayer(ChatCommandContext ctx, string player)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_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)
			//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)
			Player val = default(Player);
			if (!PlayerService.TryFindByName(player, ref val))
			{
				ctx.Reply("Player " + player + " not found.");
				return;
			}
			User val2 = EntityUtil.Read<User>(val.User);
			KickPlayer(val.User);
			ctx.Reply("Player " + player + " unbound.");
			val2 = EntityUtil.Read<User>(val.User);
			val2.PlatformId = 0uL;
			EntityUtil.Write<User>(val.User, val2);
		}

		[Command("SwapPlayers", "swap", null, null, null, true)]
		public static void SwapPlayers(ChatCommandContext ctx, string player1, string player2)
		{
			//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_004d: 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)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			Player val = default(Player);
			if (!PlayerService.TryFindByName(player1, ref val))
			{
				ctx.Reply("Player " + player1 + " not found.");
				return;
			}
			Player val2 = default(Player);
			if (!PlayerService.TryFindByName(player2, ref val2))
			{
				ctx.Reply("Player " + player2 + " not found.");
				return;
			}
			User val3 = EntityUtil.Read<User>(val.User);
			User val4 = EntityUtil.Read<User>(val2.User);
			KickPlayer(val.User);
			KickPlayer(val2.User);
			ctx.Reply($"Players {val3.CharacterName} and {val4.CharacterName} swapped.");
			val3 = EntityUtil.Read<User>(val.User);
			val4 = EntityUtil.Read<User>(val2.User);
			ref ulong platformId = ref val3.PlatformId;
			ref ulong platformId2 = ref val4.PlatformId;
			ulong platformId3 = val4.PlatformId;
			ulong platformId4 = val3.PlatformId;
			platformId = platformId3;
			platformId2 = platformId4;
			EntityUtil.Write<User>(val.User, val3);
			EntityUtil.Write<User>(val2.User, val4);
		}

		public static void KickPlayer(Entity userEntity)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: 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_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = Core.EntityManager;
			User val = EntityUtil.Read<User>(userEntity);
			if (val.IsConnected && val.PlatformId != 0L)
			{
				Entity val2 = ((EntityManager)(ref entityManager)).CreateEntity((ComponentType[])(object)new ComponentType[3]
				{
					ComponentType.ReadOnly<NetworkEventType>(),
					ComponentType.ReadOnly<SendEventToUser>(),
					ComponentType.ReadOnly<KickEvent>()
				});
				EntityUtil.Write<KickEvent>(val2, new KickEvent
				{
					PlatformId = val.PlatformId
				});
				EntityUtil.Write<SendEventToUser>(val2, new SendEventToUser
				{
					UserIndex = val.Index
				});
				EntityUtil.Write<NetworkEventType>(val2, new NetworkEventType
				{
					EventId = NetworkEvents.EventId_KickEvent,
					IsAdminEvent = false,
					IsDebugEvent = false
				});
			}
		}
	}
	[CommandGroup("utility", "util")]
	internal static class TPCommands
	{
		private static Dictionary<string, int> RaidIndex = new Dictionary<string, int>();

		[Command("TPGolem", "tpg", null, null, null, true)]
		public static void TPToGolem(ChatCommandContext ctx, int instanceId)
		{
			//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_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			Enumerator<Entity> enumerator = ((EntityQuery)(ref GolemService.GolemQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2)).GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				if (current.Index == instanceId)
				{
					TeleportToEntity(ctx.User, current);
					return;
				}
			}
			ctx.Reply("No golem found with that instance id. Find targetable golems with .utility listgolems.");
		}

		[Command("TPRaid", "tpr", null, null, null, true)]
		public unsafe static void TPToRaid(ChatCommandContext ctx)
		{
			//IL_0003: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			User user = ctx.User;
			string key = ((object)(*(FixedString64Bytes*)(&user.CharacterName))/*cast due to .constrained prefix*/).ToString();
			if (RaidIndex.ContainsKey(key))
			{
				num = RaidIndex[key] + 1;
			}
			NativeArray<Entity> val = ((EntityQuery)(ref CastleHeartService.CastleHeartQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			List<Entity> list = new List<Entity>();
			Enumerator<Entity> enumerator = val.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				CastleHeart val2 = EntityUtil.Read<CastleHeart>(current);
				if (((CastleHeart)(ref val2)).IsSieged())
				{
					list.Add(current);
				}
			}
			if (list.Count == 0)
			{
				ctx.Reply("No raids found.");
				return;
			}
			num %= list.Count;
			TeleportToEntity(ctx.User, list[num]);
			RaidIndex[key] = num;
		}

		[Command("TPCastle", "tpc", null, null, null, true)]
		public static void TPToCastle(ChatCommandContext ctx, string playerName)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			Player val = default(Player);
			if (!PlayerService.TryFindByName(playerName, ref val))
			{
				ctx.Reply("No player found with the name " + playerName + ".");
				return;
			}
			Entity user = val.User;
			Entity val2 = default(Entity);
			if (!EntityUtil.Exists(user))
			{
				ctx.Reply("Player entity is invalid for " + playerName + ".");
			}
			else if (CastleHeartService.TryGetByOwnerUser(EntityUtil.Read<User>(user), ref val2))
			{
				if (!EntityUtil.Exists(val2))
				{
					ctx.Reply("Castle heart entity is invalid for " + playerName + ".");
				}
				else
				{
					TeleportToEntity(ctx.User, val2);
				}
			}
			else
			{
				ctx.Reply("Could not locate a castle heart for " + playerName + ".");
			}
		}

		[Command("TPCastleId", "tpcid", null, null, null, true)]
		public static void TPToCastleById(ChatCommandContext ctx, ulong playerId)
		{
			Player val = default(Player);
			if (!PlayerService.TryFindBySteam(playerId, ref val))
			{
				ctx.Reply($"No player found with the ID {playerId}.");
			}
			else
			{
				TPToCastle(ctx, val.Name.ToString());
			}
		}

		[Command("TPNamed", "tpname", null, null, null, true)]
		public unsafe static void TPToNamed(ChatCommandContext ctx, string name, int index = 0)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrEmpty(name))
			{
				ctx.Reply("Name cannot be empty.");
				return;
			}
			index--;
			Player val = PlayerService.PlayerFromUser(ctx.User);
			NativeArray<Entity> entitiesByComponentType = EntityUtil.GetEntitiesByComponentType<NameableInteractable>(true, true, true, false, false);
			entitiesByComponentType = EntityUtil.SortEntitiesByDistance(entitiesByComponentType, new float3(0f, 0f, 0f));
			bool flag = false;
			List<Entity> list = new List<Entity>();
			Enumerator<Entity> enumerator = entitiesByComponentType.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				NameableInteractable val2 = EntityUtil.Read<NameableInteractable>(current);
				if (((object)(*(FixedString64Bytes*)(&val2.Name))/*cast due to .constrained prefix*/).ToString() == name && EntityUtil.Has<LocalToWorld>(current))
				{
					list.Add(current);
				}
			}
			entitiesByComponentType.Dispose();
			if (index == -1)
			{
				foreach (Entity item in list)
				{
					LocalToWorld val3 = EntityUtil.Read<LocalToWorld>(item);
					float3 position = ((LocalToWorld)(ref val3)).Position;
					val3 = EntityUtil.Read<LocalToWorld>(val.Character);
					float3 position2 = ((LocalToWorld)(ref val3)).Position;
					if (Vector3.Distance(new Vector3(position.x, position.y, position.z), new Vector3(position2.x, position2.y, position2.z)) < 20f)
					{
						flag = true;
						continue;
					}
					TeleportToEntity(ctx.User, item);
					return;
				}
				if (flag)
				{
					ctx.Reply("Standing next to the only entity with the name " + name + ".");
				}
				else
				{
					ctx.Reply("No entity found with the name " + name + ".");
				}
			}
			else if (index > list.Count - 1)
			{
				ctx.Reply($"Index out of range. Max index: {list.Count}");
			}
			else
			{
				TeleportToEntity(ctx.User, list[index]);
			}
		}

		private unsafe static void TeleportToEntity(User user, Entity target)
		{
			//IL_0000: 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_0038: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//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)
			if (!EntityUtil.Has<LocalToWorld>(target))
			{
				User val = user;
				NameableInteractable val2 = EntityUtil.Read<NameableInteractable>(target);
				ChatUtil.SystemSendUser(val, "Couldn't find object with the name " + ((object)(*(FixedString64Bytes*)(&val2.Name))/*cast due to .constrained prefix*/).ToString() + " with a position in the world.");
				return;
			}
			LocalToWorld val3 = EntityUtil.Read<