Decompiled source of CarriageTracker v1.0.25

CarriageTracker.dll

Decompiled 9 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
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;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppSystem.Reflection;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Network;
using ProjectM.Scripting;
using ProjectM.Shared;
using Stunlock.Core;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
using UnityEngine.Profiling;
using UnityEngine.Scripting;
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("Bazarov")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Carriages on the map for everyone, chat announcements when they set out, and automatic carriage starts in every act where players are online.")]
[assembly: AssemblyFileVersion("1.0.25.0")]
[assembly: AssemblyInformationalVersion("1.0.25+06d3c588c667cef4ebf6b640a0e48cf5588188c0")]
[assembly: AssemblyProduct("CarriageTracker")]
[assembly: AssemblyTitle("CarriageTracker")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.25.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CarriageTracker
{
	internal static class Acts
	{
		public record Boss(int Act, string Name, int Level);

		public record PlayerAct(int Act, string Boss, int BossLevel, int Drunk, int ByVBlood, int Opened, int Level, bool ByLevel);

		public record RouteAct(int Level, SortedSet<int> Acts, bool Manual);

		public record OnlinePlayer(string Name, PlayerAct Act);

		private static readonly Dictionary<string, Boss> Bosses = new Dictionary<string, Boss>(StringComparer.OrdinalIgnoreCase)
		{
			["CHAR_Forest_Wolf_VBlood"] = new Boss(1, "Alpha the White Wolf", 16),
			["CHAR_Bandit_Frostarrow_VBlood"] = new Boss(1, "Keely the Frost Archer", 20),
			["CHAR_Bandit_StoneBreaker_VBlood"] = new Boss(1, "Errol the Stonebreaker", 20),
			["CHAR_Bandit_Foreman_VBlood"] = new Boss(1, "Rufus the Foreman", 20),
			["CHAR_Bandit_Stalker_VBlood"] = new Boss(1, "Grayson the Armourer", 27),
			["CHAR_Undead_BishopOfDeath_VBlood"] = new Boss(1, "Goreswine the Ravager", 27),
			["CHAR_Bandit_Chaosarrow_VBlood"] = new Boss(1, "Lidia the Chaos Archer", 30),
			["CHAR_Bandit_Bomber_VBlood"] = new Boss(1, "Clive the Firestarter", 30),
			["CHAR_Vermin_DireRat_VBlood"] = new Boss(1, "Nibbles the Putrid Rat", 30),
			["CHAR_Bandit_Fisherman_VBlood"] = new Boss(1, "Finn the Fisherman", 32),
			["CHAR_Poloma_VBlood"] = new Boss(1, "Polora the Feywalker", 35),
			["CHAR_Forest_Bear_Dire_Vblood"] = new Boss(1, "Kodia the Ferocious Bear", 35),
			["CHAR_Undead_Priest_VBlood"] = new Boss(1, "Nicholaus the Fallen", 35),
			["CHAR_Bandit_Tourok_VBlood"] = new Boss(1, "Quincey the Bandit King", 37),
			["CHAR_Villager_Tailor_VBlood"] = new Boss(2, "Beatrice the Tailor", 40),
			["CHAR_Militia_Guard_VBlood"] = new Boss(2, "Vincent the Frostbringer", 44),
			["CHAR_Militia_Nun_VBlood"] = new Boss(2, "Christina the Sun Priestess", 44),
			["CHAR_VHunter_Leader_VBlood"] = new Boss(2, "Tristan the Vampire Hunter", 44),
			["CHAR_Militia_Fabian_VBlood"] = new Boss(2, "Sir Erwin the Gallant Cavalier", 46),
			["CHAR_Undead_Leader_Vblood"] = new Boss(2, "Kriig the Undead General", 47),
			["CHAR_Undead_BishopOfShadows_VBlood"] = new Boss(2, "Leandra the Shadow Priestess", 47),
			["CHAR_Militia_Scribe_VBlood"] = new Boss(2, "Maja the Dark Savant", 47),
			["CHAR_Undead_Infiltrator_VBlood"] = new Boss(2, "Bane the Shadowblade", 50),
			["CHAR_Militia_Glassblower_VBlood"] = new Boss(2, "Grethel the Glassblower", 50),
			["CHAR_Militia_Longbowman_LightArrow_Vblood"] = new Boss(2, "Meredith the Bright Archer", 50),
			["CHAR_Geomancer_Human_VBlood"] = new Boss(2, "Terah the Geomancer", 53),
			["CHAR_Wendigo_VBlood"] = new Boss(2, "Frostmaw the Mountain Terror", 53),
			["CHAR_Vampire_IceRanger_VBlood"] = new Boss(2, "General Elena the Hollow", 53),
			["CHAR_Undead_ArenaChampion_VBlood"] = new Boss(2, "Gaius the Cursed Champion", 55),
			["CHAR_Vampire_HighLord_VBlood"] = new Boss(2, "General Cassius the Betrayer", 57),
			["CHAR_VHunter_Jade_VBlood"] = new Boss(2, "Jade the Vampire Hunter", 57),
			["CHAR_Militia_BishopOfDunley_VBlood"] = new Boss(2, "Raziel the Shepherd", 57),
			["CHAR_Militia_Leader_VBlood"] = new Boss(2, "Octavian the Militia Captain", 58),
			["CHAR_Gloomrot_Iva_VBlood"] = new Boss(3, "Ziva the Engineer", 60),
			["CHAR_Gloomrot_Voltage_VBlood"] = new Boss(3, "Domina the Blade Dancer", 60),
			["CHAR_Gloomrot_Purifier_VBlood"] = new Boss(3, "Angram the Purifier", 61),
			["CHAR_Spider_Queen_VBlood"] = new Boss(3, "Ungora the Spider Queen", 63),
			["CHAR_Villager_CursedWanderer_VBlood"] = new Boss(3, "Ben the Old Wanderer", 63),
			["CHAR_Undead_ZealousCultist_VBlood"] = new Boss(3, "Foulrot the Soultaker", 63),
			["CHAR_Cursed_ToadKing_VBlood"] = new Boss(3, "Albert the Duke of Balaton", 64),
			["CHAR_WerewolfChieftain_Human"] = new Boss(3, "Willfred the Village Elder", 64),
			["CHAR_Undead_CursedSmith_VBlood"] = new Boss(3, "Cyril the Cursed Smith", 65),
			["CHAR_ChurchOfLight_Overseer_VBlood"] = new Boss(4, "Sir Magnus the Overseer", 66),
			["CHAR_ChurchOfLight_Sommelier_VBlood"] = new Boss(4, "Baron du Bouchon the Sommelier", 70),
			["CHAR_Harpy_Matriarch_VBlood"] = new Boss(4, "Morian the Stormwing Matriarch", 70),
			["CHAR_ArchMage_VBlood"] = new Boss(4, "Mairwyn the Elementalist", 70),
			["CHAR_Gloomrot_TheProfessor_VBlood"] = new Boss(4, "Henry Blackbrew the Doctor", 74),
			["CHAR_Blackfang_Livith_VBlood"] = new Boss(4, "Jakira the Shadow Huntress", 75),
			["CHAR_Blackfang_CarverBoss_VBlood"] = new Boss(4, "Stavros the Carver", 75),
			["CHAR_Blackfang_Lucie_VBlood"] = new Boss(4, "Lucile the Venom Alchemist", 76),
			["CHAR_Cursed_Witch_VBlood"] = new Boss(4, "Matka the Curse Weaver", 76),
			["CHAR_Winter_Yeti_VBlood"] = new Boss(4, "Terrorclaw the Ogre", 76),
			["CHAR_ChurchOfLight_Cardinal_VBlood"] = new Boss(4, "Azariel the Sunbringer", 79),
			["CHAR_Gloomrot_RailgunSergeant_VBlood"] = new Boss(4, "Voltatia the Power Master", 79),
			["CHAR_Blackfang_Valyr_VBlood"] = new Boss(4, "Dantos the Forgebinder", 82),
			["CHAR_BatVampire_VBlood"] = new Boss(4, "Lord Styx the Night Champion", 84),
			["CHAR_Cursed_MountainBeast_VBlood"] = new Boss(4, "Gorecrusher the Behemoth", 84),
			["CHAR_Vampire_BloodKnight_VBlood"] = new Boss(4, "General Valencia the Depraved", 84),
			["CHAR_ChurchOfLight_Paladin_VBlood"] = new Boss(4, "Solarus the Immaculate", 86),
			["CHAR_Manticore_VBlood"] = new Boss(4, "Talzur the Winged Horror", 86),
			["CHAR_Gloomrot_Monster_VBlood"] = new Boss(4, "Adam the Firstborn", 88),
			["CHAR_Blackfang_Morgana_VBlood"] = new Boss(4, "Megara the Serpent Queen", 88),
			["CHAR_Vampire_Dracula_VBlood"] = new Boss(4, "Dracula the Immortal King", 91)
		};

		private static readonly Dictionary<int, string> Finals = FindFinals();

		private static string _manualRaw;

		private static Dictionary<string, SortedSet<int>> _manual = new Dictionary<string, SortedSet<int>>(StringComparer.OrdinalIgnoreCase);

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

		private static Dictionary<int, string> FindFinals()
		{
			Dictionary<int, Boss> dictionary = new Dictionary<int, Boss>();
			Dictionary<int, string> dictionary2 = new Dictionary<int, string>();
			foreach (KeyValuePair<string, Boss> boss in Bosses)
			{
				if (!dictionary.TryGetValue(boss.Value.Act, out var value) || boss.Value.Level > value.Level)
				{
					dictionary[boss.Value.Act] = boss.Value;
					dictionary2[boss.Value.Act] = boss.Key;
				}
			}
			return dictionary2;
		}

		public static string Roman(int act)
		{
			return act switch
			{
				1 => "I", 
				2 => "II", 
				3 => "III", 
				4 => "IV", 
				_ => "?", 
			};
		}

		public static int OfLevel(int level)
		{
			return ActLogic.OfLevel(level);
		}

		public static int LevelOf(EntityManager em, PrefabCollectionSystem prefabs, PrefabGUID guid)
		{
			//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_0009: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			Entity val = default(Entity);
			if (!prefabs._PrefabGuidToEntityMap.TryGetValue(guid, ref val))
			{
				return 0;
			}
			if (!Caravans.Has<UnitLevel>(em, val))
			{
				return 0;
			}
			return ((EntityManager)(ref em)).GetComponentData<UnitLevel>(val).Level._Value;
		}

		public static int LevelOfUser(EntityManager em, Entity userEntity)
		{
			//IL_0002: 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_000b: 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_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_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_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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_004f: 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)
			if (!((EntityManager)(ref em)).Exists(userEntity) || !Caravans.Has<User>(em, userEntity))
			{
				return 0;
			}
			User componentData = ((EntityManager)(ref em)).GetComponentData<User>(userEntity);
			Entity entityOnServer = ((NetworkedEntity)(ref componentData.LocalCharacter)).GetEntityOnServer();
			if (entityOnServer == Entity.Null || !((EntityManager)(ref em)).Exists(entityOnServer) || !Caravans.Has<Equipment>(em, entityOnServer))
			{
				return 0;
			}
			Equipment componentData2 = ((EntityManager)(ref em)).GetComponentData<Equipment>(entityOnServer);
			return (int)Math.Floor(((Equipment)(ref componentData2)).GetFullLevel());
		}

		public static PlayerAct OfUser(EntityManager em, PrefabCollectionSystem prefabs, Entity userEntity)
		{
			//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_001b: 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_0023: 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_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: 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_002e: 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_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_0042: 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_0073: 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)
			//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_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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			int num = 1;
			int num2 = -1;
			int num3 = 0;
			int num4 = 0;
			string boss = null;
			List<(int, bool)> list = new List<(int, bool)>();
			Entity val = Entity.Null;
			if (((EntityManager)(ref em)).Exists(userEntity) && Caravans.Has<ProgressionMapper>(em, userEntity))
			{
				ProgressionMapper componentData = ((EntityManager)(ref em)).GetComponentData<ProgressionMapper>(userEntity);
				val = ((NetworkedEntity)(ref componentData.ProgressionEntity)).GetEntityOnServer();
			}
			if (val != Entity.Null && ((EntityManager)(ref em)).Exists(val) && ((EntityManager)(ref em)).HasBuffer<UnlockedVBlood>(val))
			{
				DynamicBuffer<UnlockedVBlood> buffer = ((EntityManager)(ref em)).GetBuffer<UnlockedVBlood>(val, false);
				string text = default(string);
				for (int i = 0; i < buffer.Length; i++)
				{
					PrefabGUID vBlood = buffer[i].VBlood;
					num3++;
					bool flag = false;
					PrefabLookupMap prefabLookupMap = prefabs._PrefabLookupMap;
					int num5;
					int num6;
					string text2;
					if (((PrefabLookupMap)(ref prefabLookupMap)).TryGetName(vBlood, ref text) && text != null && Bosses.TryGetValue(text, out var value))
					{
						num5 = value.Act;
						num6 = value.Level;
						text2 = value.Name;
						flag = Finals.TryGetValue(num5, out var value2) && value2.Equals(text, StringComparison.OrdinalIgnoreCase);
					}
					else
					{
						num6 = LevelOf(em, prefabs, vBlood);
						num5 = OfLevel(num6);
						text2 = text ?? ((PrefabGUID)(ref vBlood)).GuidHash.ToString();
					}
					if (num5 > 0)
					{
						list.Add((num5, flag));
						if (flag && num5 < 4)
						{
							num4 = Math.Max(num4, num5);
						}
						if (num5 > num || (num5 == num && num6 > num2))
						{
							num = num5;
							num2 = num6;
							boss = text2;
						}
					}
				}
			}
			int num7 = ActLogic.ByVBlood(list);
			int level = LevelOfUser(em, userEntity);
			int num8 = ActLogic.Of(Settings.PlayerActMode, num7, level);
			return new PlayerAct(num8, boss, Math.Max(0, num2), num3, num7, num4, level, num8 != num7);
		}

		public unsafe static List<OnlinePlayer> Online(EntityManager em, PrefabCollectionSystem prefabs)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_0048: 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_0051: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			List<OnlinePlayer> list = new List<OnlinePlayer>();
			EntityQuery val = Queries.Get(em, "User", false, Ct<User>.RO);
			NativeArray<Entity> val2 = ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			try
			{
				Enumerator<Entity> enumerator = val2.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					User componentData = ((EntityManager)(ref em)).GetComponentData<User>(current);
					if (componentData.IsConnected)
					{
						list.Add(new OnlinePlayer(((object)(*(FixedString64Bytes*)(&componentData.CharacterName))/*cast due to .constrained prefix*/).ToString(), OfUser(em, prefabs, current)));
					}
				}
				return list;
			}
			finally
			{
				val2.Dispose();
			}
		}

		public static OnlinePlayer Leader(List<OnlinePlayer> players)
		{
			OnlinePlayer onlinePlayer = null;
			foreach (OnlinePlayer player in players)
			{
				if (onlinePlayer == null || player.Act.Act > onlinePlayer.Act.Act || (player.Act.Act == onlinePlayer.Act.Act && player.Act.BossLevel > onlinePlayer.Act.BossLevel))
				{
					onlinePlayer = player;
				}
			}
			return onlinePlayer;
		}

		private static Dictionary<string, SortedSet<int>> Manual()
		{
			string text = Settings.RouteActs.Value ?? "";
			if (text == _manualRaw)
			{
				return _manual;
			}
			_manual = ActLogic.ParseRouteActs(text);
			_manualRaw = text;
			return _manual;
		}

		public static HashSet<int> WithRoutes(EntityManager em, PrefabCollectionSystem prefabs)
		{
			//IL_0006: 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)
			HashSet<int> hashSet = new HashSet<int>();
			foreach (Routes.Route item in Routes.All(em, prefabs))
			{
				if (!Settings.Excluded(item.Key))
				{
					hashSet.UnionWith(OfRoute(em, prefabs, item).Acts);
				}
			}
			return hashSet;
		}

		public static List<int> Served(int playerAct, HashSet<int> actsWithRoutes)
		{
			return ActLogic.Served(playerAct, actsWithRoutes, Settings.EmptyActMode);
		}

		public static RouteAct OfRoute(EntityManager em, PrefabCollectionSystem prefabs, Routes.Route route)
		{
			//IL_001c: 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_0040: 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_004b: 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_0071: 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_0079: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			if (!LevelCache.TryGetValue(route.Key, out var value))
			{
				value = 0;
				if (((EntityManager)(ref em)).Exists(route.Patrol) && ((EntityManager)(ref em)).HasBuffer<UnitCompositionGroupUnitEntry>(route.Patrol))
				{
					DynamicBuffer<UnitCompositionGroupUnitEntry> buffer = ((EntityManager)(ref em)).GetBuffer<UnitCompositionGroupUnitEntry>(route.Patrol, false);
					string text = default(string);
					for (int i = 0; i < buffer.Length; i++)
					{
						if (buffer[i].Unit is PrefabGUID val)
						{
							PrefabLookupMap prefabLookupMap = prefabs._PrefabLookupMap;
							if (!((PrefabLookupMap)(ref prefabLookupMap)).TryGetName(val, ref text) || text == null || !text.StartsWith("CHAR_CarriageHorse_", StringComparison.Ordinal))
							{
								value = Math.Max(value, LevelOf(em, prefabs, val));
							}
						}
					}
				}
				LevelCache[route.Key] = value;
			}
			bool isManual;
			SortedSet<int> acts = ActLogic.RouteActs(route.Key, value, Manual(), out isManual);
			return new RouteAct(value, acts, isManual);
		}

		public static SortedSet<int> OfRouteKey(EntityManager em, PrefabCollectionSystem prefabs, string key)
		{
			//IL_0006: 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)
			SortedSet<int> sortedSet = new SortedSet<int>();
			foreach (Routes.Route item in Routes.All(em, prefabs))
			{
				if (item.Key == key)
				{
					sortedSet.UnionWith(OfRoute(em, prefabs, item).Acts);
				}
			}
			return sortedSet;
		}
	}
	internal static class AutoStart
	{
		private static readonly Dictionary<int, DateTime> LastStart = new Dictionary<int, DateTime>();

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

		private static bool _toldBloodcraft;

		private static readonly Random Rng = new Random();

		private static DateTime _ready = DateTime.MinValue;

		public static readonly List<LateText> LastResults = new List<LateText>();

		private static string _lastBlocked = "";

		private static DateTime LastOf(int act)
		{
			if (!LastStart.TryGetValue(act, out var value))
			{
				return _ready;
			}
			return value;
		}

		public static double MinutesLeft(int act)
		{
			if (_ready == DateTime.MinValue)
			{
				return Settings.AutoInterval.Value;
			}
			return Math.Max(0.0, (LastOf(act).AddMinutes(Settings.AutoInterval.Value) - DateTime.UtcNow).TotalMinutes);
		}

		public static void Restart()
		{
			LastStart.Clear();
			_ready = DateTime.UtcNow;
		}

		public static void Tick()
		{
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			if (Settings.AutoInterval.Value <= 0 || Settings.GameOnly || Starter.Paused)
			{
				return;
			}
			World val = Caravans.ServerWorld();
			PrefabCollectionSystem val2 = ((val == null) ? null : Caravans.Prefabs(val));
			if (val2 == null)
			{
				return;
			}
			if (_ready == DateTime.MinValue)
			{
				_ready = DateTime.UtcNow;
				return;
			}
			if (!_toldBloodcraft)
			{
				_toldBloodcraft = true;
				Plugin.Info($"CarriageTracker auto: player act by {Settings.PlayerActMode}, act without routes uses {Settings.EmptyActMode}; Bloodcraft {(Plugin.HasBloodcraft ? "found: the character level is its level" : "not found: the character level is the gear level")}");
			}
			List<(bool, LateText)> list = Run(val.EntityManager, val2, force: false);
			if (list.Count == 0)
			{
				return;
			}
			string text = string.Join(" | ", list.FindAll(((bool Started, LateText Text) r) => !r.Started).ConvertAll(((bool Started, LateText Text) r) => r.Text.ToString()));
			if (!list.Exists(((bool Started, LateText Text) r) => r.Started) && text == _lastBlocked)
			{
				return;
			}
			_lastBlocked = text;
			LastResults.Clear();
			foreach (var item in list)
			{
				LastResults.Add(item.Item2);
				if (item.Item1)
				{
					Plugin.Info($"CarriageTracker auto: {item.Item2}");
				}
				else
				{
					Plugin.Trace($"CarriageTracker auto: {item.Item2}");
				}
			}
		}

		public static List<(bool Started, LateText Text)> Run(EntityManager em, PrefabCollectionSystem prefabs, bool force)
		{
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_04da: Unknown result type (might be due to invalid IL or missing references)
			//IL_059a: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0635: Unknown result type (might be due to invalid IL or missing references)
			//IL_063d: Unknown result type (might be due to invalid IL or missing references)
			List<(bool, LateText)> list = new List<(bool, LateText)>();
			if (Starter.Paused)
			{
				list.Add((false, new LateText(() => L.T("cleanup.paused"))));
				return list;
			}
			if (Settings.GameOnly)
			{
				list.Add((false, new LateText(() => L.T("auto.gameonly"))));
				return list;
			}
			GameCheck.Ensure();
			if (!GameCheck.StartsOk)
			{
				list.Add((false, new LateText(() => L.T("start.broken", GameCheck.Missing))));
				return list;
			}
			List<Acts.OnlinePlayer> list2 = Acts.Online(em, prefabs);
			if (list2.Count == 0)
			{
				if (force)
				{
					list.Add((false, new LateText(() => L.T("auto.nobody"))));
				}
				return list;
			}
			List<int> list3 = new List<int>();
			if (Settings.LeaderScope)
			{
				list3.Add(Acts.Leader(list2).Act.Act);
			}
			else
			{
				foreach (Acts.OnlinePlayer item in list2)
				{
					if (!list3.Contains(item.Act.Act))
					{
						list3.Add(item.Act.Act);
					}
				}
			}
			list3.Sort((int a, int b) => b.CompareTo(a));
			List<Routes.Route> list4 = Routes.All(em, prefabs).FindAll((Routes.Route r) => !Settings.Excluded(r.Key));
			Dictionary<(int, int), SortedSet<int>> routeActs = new Dictionary<(int, int), SortedSet<int>>();
			HashSet<int> hashSet = new HashSet<int>();
			foreach (Routes.Route item2 in list4)
			{
				SortedSet<int> acts = Acts.OfRoute(em, prefabs, item2).Acts;
				routeActs[(item2.Patrol.Index, item2.Patrol.Version)] = acts;
				hashSet.UnionWith(acts);
			}
			int num = Math.Max(1, Settings.AutoInterval.Value);
			int maxPerAct = Math.Max(1, Settings.AutoMaxPerAct.Value);
			int maxTotal = Math.Max(1, Settings.AutoMaxTotal.Value);
			HashSet<int> hashSet2 = new HashSet<int>();
			DateTime utcNow = DateTime.UtcNow;
			List<int> list5 = new List<int>();
			foreach (int playerAct in list3)
			{
				List<int> list6 = ActLogic.Served(playerAct, hashSet, Settings.EmptyActMode);
				if (list6.Count == 0)
				{
					list.Add((false, new LateText(() => L.T("auto.noroutes", L.Act(playerAct)))));
				}
				foreach (int item3 in list6)
				{
					if (!list5.Contains(item3))
					{
						list5.Add(item3);
					}
				}
			}
			foreach (int act in list5)
			{
				if (!hashSet2.Add(act) || (!force && utcNow < LastOf(act).AddMinutes(num)))
				{
					continue;
				}
				if (Starter.AutoCount() >= maxTotal)
				{
					int total = Starter.AutoCount();
					list.Add((false, new LateText(() => L.T("auto.maxtotal", total, maxTotal))));
					break;
				}
				if (Starter.AutoCount(act) >= maxPerAct)
				{
					int inAct = Starter.AutoCount(act);
					list.Add((false, new LateText(() => L.T("auto.maxact", L.Act(act), inAct, maxPerAct))));
					continue;
				}
				List<Routes.Route> list7 = list4.FindAll((Routes.Route r) => InAct(r, act));
				List<Routes.Route> list8 = new List<Routes.Route>();
				List<RouteSnap> list9 = new List<RouteSnap>();
				foreach (Routes.Route item4 in list7)
				{
					RouteSnap routeSnap = Routes.Snap(em, item4);
					if (RouteLogic.IsFree(RouteLogic.Classify(routeSnap)))
					{
						list8.Add(item4);
						list9.Add(routeSnap);
					}
				}
				if (list8.Count == 0)
				{
					list.Add((false, new LateText(() => L.T("auto.busy", L.Act(act)))));
					continue;
				}
				DateTime value;
				int index = RouteLogic.Choose(list9, Settings.ResetToStart.Value, Settings.RotatePick, (string id) => (!LastRouteStart.TryGetValue(id, out value)) ? DateTime.MinValue : value, Rng);
				Routes.Route pick = list8[index];
				if (!Starter.TryStart(em, pick, Entity.Null, out var text, auto: true, act, $", picked from {list8.Count} free: {RouteLogic.Groups(list9)}, this one {RouteLogic.Group(list9[index])}"))
				{
					list.Add((false, text));
					continue;
				}
				Progress stops = Routes.StopsOf(em, pick.Patrol);
				LastStart[act] = utcNow;
				LastRouteStart[list9[index].Ident] = utcNow;
				int freeCount = list8.Count;
				list.Add((true, new LateText(() => L.T("auto.started", Routes.Name(pick), L.Act(act), freeCount, Routes.StopText(stops)))));
			}
			return list;
			bool InAct(Routes.Route r, int item)
			{
				//IL_0007: 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)
				return routeActs[(r.Patrol.Index, r.Patrol.Version)].Contains(item);
			}
		}
	}
	public enum Kind
	{
		None,
		Container,
		Cart,
		Horse
	}
	internal static class Caravans
	{
		public record Found(Kind Kind, string Route, Entity Entity, float3 Pos, bool Empty, bool Frozen, string Status, Entity Patrol, Progress Stops, bool Orphan);

		public record Caravan(string Route, Entity Target, float3 Pos, LateText Note, bool Frozen, bool Icon, Entity Patrol, Progress Stops, string State);

		private const string ContainerPrefix = "TM_CarriageContainer_";

		private const string HorsePrefix = "CHAR_CarriageHorse_";

		private const string CartPrefix = "CHAR_Carriage_";

		private static readonly Dictionary<int, (Kind Kind, string Route)> Kinds = new Dictionary<int, (Kind, string)>();

		private static World _world;

		private static PrefabCollectionSystem _prefabs;

		private static readonly Dictionary<string, (Type Type, ComponentType Ct)> RawTypes = new Dictionary<string, (Type, ComponentType)>();

		public static World ServerWorld()
		{
			World world = _world;
			if (world != null && world.IsCreated)
			{
				return world;
			}
			_world = null;
			_prefabs = null;
			if (World.s_AllWorlds == null)
			{
				return null;
			}
			Enumerator<World> enumerator = World.s_AllWorlds.GetEnumerator();
			while (enumerator.MoveNext())
			{
				World current = enumerator.Current;
				if (current.Name == "Server" && current.IsCreated)
				{
					Queries.Reset();
					Doomed.Reset();
					Proxies.Reset();
					Starter.TrialReset();
					_world = current;
					return current;
				}
			}
			return null;
		}

		public static PrefabCollectionSystem Prefabs(World world)
		{
			if (_prefabs != null && world == _world)
			{
				return _prefabs;
			}
			PrefabCollectionSystem existingSystemManaged = world.GetExistingSystemManaged<PrefabCollectionSystem>();
			if (existingSystemManaged == null || !existingSystemManaged.GameDataInitialized)
			{
				return null;
			}
			if (world == _world)
			{
				_prefabs = existingSystemManaged;
			}
			return existingSystemManaged;
		}

		public static bool Has<T>(EntityManager em, Entity e)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			return ((EntityManager)(ref em)).HasComponent(e, Ct<T>.RO);
		}

		public static (Kind Kind, string Route) Classify(PrefabCollectionSystem prefabs, PrefabGUID guid)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (Kinds.TryGetValue(((PrefabGUID)(ref guid)).GuidHash, out (Kind, string) value))
			{
				return value;
			}
			(Kind, string) tuple = (Kind.None, null);
			PrefabLookupMap prefabLookupMap = prefabs._PrefabLookupMap;
			string text = default(string);
			if (((PrefabLookupMap)(ref prefabLookupMap)).TryGetName(guid, ref text) && !string.IsNullOrEmpty(text))
			{
				if (text.StartsWith("TM_CarriageContainer_", StringComparison.Ordinal))
				{
					tuple = (Kind.Container, text.Substring("TM_CarriageContainer_".Length));
				}
				else if (text.StartsWith("CHAR_CarriageHorse_", StringComparison.Ordinal))
				{
					tuple = (Kind.Horse, text.Substring("CHAR_CarriageHorse_".Length));
				}
				else if (text.StartsWith("CHAR_Carriage_", StringComparison.Ordinal))
				{
					tuple = (Kind.Cart, text.Substring("CHAR_Carriage_".Length));
				}
			}
			Kinds[((PrefabGUID)(ref guid)).GuidHash] = tuple;
			return tuple;
		}

		public static bool IsCaravanEntity(EntityManager em, PrefabCollectionSystem prefabs, Entity e)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			if (Has<PrefabGUID>(em, e))
			{
				return Classify(prefabs, ((EntityManager)(ref em)).GetComponentData<PrefabGUID>(e)).Kind != Kind.None;
			}
			return false;
		}

		internal static bool IsEmpty(EntityManager em, Entity container)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: 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_001c: 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_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_0042: Unknown result type (might be due to invalid IL or missing references)
			Entity val = default(Entity);
			if (!InventoryUtilities.TryGetInventoryEntity<EntityManager>(em, container, ref val, 0))
			{
				return false;
			}
			if (!((EntityManager)(ref em)).HasBuffer<InventoryBuffer>(val))
			{
				return false;
			}
			DynamicBuffer<InventoryBuffer> buffer = ((EntityManager)(ref em)).GetBuffer<InventoryBuffer>(val, false);
			for (int i = 0; i < buffer.Length; i++)
			{
				InventoryBuffer val2 = buffer[i];
				if (((PrefabGUID)(ref val2.ItemType)).GuidHash != 0 && buffer[i].Amount > 0)
				{
					return false;
				}
			}
			return true;
		}

		private static void Collect(EntityManager em, PrefabCollectionSystem prefabs, string name, ComponentType? marker, List<Found> found, HashSet<(int, int)> seen, ref int scanned)
		{
			//IL_003b: 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_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_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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_0034: 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_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_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_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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: 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)
			EntityQuery val = (marker.HasValue ? Queries.Get(em, "scan " + name, true, Ct<PrefabGUID>.RO, Ct<NetworkId>.RO, marker.Value) : Queries.Get(em, "scan " + name, true, Ct<PrefabGUID>.RO, Ct<NetworkId>.RO));
			NativeArray<Entity> val2 = ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			try
			{
				Enumerator<Entity> enumerator = val2.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					scanned++;
					(Kind, string) info = Classify(prefabs, ((EntityManager)(ref em)).GetComponentData<PrefabGUID>(current));
					if (info.Item1 != Kind.None && seen.Add((current.Index, current.Version)))
					{
						found.Add(Describe(em, current, info));
					}
				}
			}
			finally
			{
				val2.Dispose();
			}
		}

		private static Found Describe(EntityManager em, Entity e, (Kind Kind, string Route) info)
		{
			//IL_0009: 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_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//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_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_0048: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_00a7: 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_0063: 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_0086: 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_006c: 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)
			bool empty = info.Kind == Kind.Container && IsEmpty(em, e);
			float3 val = PositionOf(em, e);
			bool flag = false;
			string text = null;
			Entity patrol = Entity.Null;
			Progress stops = null;
			if (info.Kind == Kind.Cart && TryGetPatrol(em, e, out patrol))
			{
				stops = Routes.StopsOf(em, patrol);
				text = Routes.MoveStatus(em, patrol);
				float3 val2 = PositionOf(em, patrol);
				if (!OnMap(val) && OnMap(val2))
				{
					val = val2;
					flag = true;
				}
			}
			bool orphan = info.Kind == Kind.Cart && !flag && OnMap(val) && !Pulled(em, e, val, text);
			return new Found(info.Kind, info.Route, e, val, empty, flag, text, patrol, stops, orphan);
		}

		public static Found Recheck(EntityManager em, PrefabCollectionSystem prefabs, Entity e)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: 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_0017: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			if (e == Entity.Null || !((EntityManager)(ref em)).Exists(e) || !Has<PrefabGUID>(em, e))
			{
				return null;
			}
			(Kind, string) info = Classify(prefabs, ((EntityManager)(ref em)).GetComponentData<PrefabGUID>(e));
			if (info.Item1 != Kind.None)
			{
				return Describe(em, e, info);
			}
			return null;
		}

		public static List<Found> FastScan(EntityManager em, PrefabCollectionSystem prefabs, out int scanned)
		{
			//IL_000f: 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_0028: 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)
			scanned = 0;
			List<Found> list = new List<Found>();
			HashSet<(int, int)> seen = new HashSet<(int, int)>();
			Collect(em, prefabs, "carts", Ct<Script_CarriageData>.RO, list, seen, ref scanned);
			Collect(em, prefabs, "inventories", Ct<InventoryInstanceElement>.RO, list, seen, ref scanned);
			return list;
		}

		public static List<Found> FullScan(EntityManager em, PrefabCollectionSystem prefabs, out int scanned)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			scanned = 0;
			List<Found> list = new List<Found>();
			Collect(em, prefabs, "all", null, list, new HashSet<(int, int)>(), ref scanned);
			return list;
		}

		private static bool Pulled(EntityManager em, Entity cart, float3 cartPos, string move)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: 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_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_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_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_0030: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_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_0068: 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)
			if (!Has<Script_CarriageData>(em, cart))
			{
				return false;
			}
			Script_CarriageData componentData = ((EntityManager)(ref em)).GetComponentData<Script_CarriageData>(cart);
			Entity entityOnServer = ((NetworkedEntity)(ref componentData.Horse)).GetEntityOnServer();
			bool flag = entityOnServer != Entity.Null && ((EntityManager)(ref em)).Exists(entityOnServer);
			float3 val = (float3)(flag ? PositionOf(em, entityOnServer) : default(float3));
			return CaravanRules.Pulled(flag, flag && OnMap(val), flag ? Dist2(val, cartPos) : float.MaxValue, move);
		}

		public static List<Caravan> Build(List<Found> found)
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			List<Found> list = found.FindAll((Found f) => f.Kind == Kind.Container && CaravanRules.ShowContainer(f.Empty, OnMap(f.Pos)));
			List<Found> list2 = found.FindAll((Found f) => f.Kind == Kind.Cart);
			List<Caravan> list3 = new List<Caravan>();
			bool value = Settings.IconOnLoot.Value;
			bool value2 = Settings.IconOnFrozen.Value;
			foreach (Found item in list)
			{
				list3.Add(new Caravan(item.Route, item.Entity, item.Pos, new LateText(() => L.T("note.loot")), Frozen: false, value, Entity.Null, null, "loot"));
			}
			foreach (Found cart in list2)
			{
				bool lootInPlace = list.Exists((Found c) => c.Route == cart.Route && Dist2(c.Pos, cart.Pos) < 15f);
				if (!CaravanRules.ShowCart(OnMap(cart.Pos), lootInPlace, cart.Status, cart.Orphan))
				{
					continue;
				}
				Progress progress = cart.Stops;
				string status = cart.Status;
				string text = ((cart.Stops != null) ? (" stop " + cart.Stops.Log) : "");
				if (!cart.Frozen)
				{
					list3.Add(new Caravan(cart.Route, cart.Entity, cart.Pos, new LateText(() => L.T("note.moving", StopNote())), Frozen: false, Icon: true, cart.Patrol, cart.Stops, "moving" + text));
					continue;
				}
				list3.Add(new Caravan(cart.Route, cart.Entity, cart.Pos, new LateText(() => L.T("note.frozen", status, StopNote())), Frozen: true, value2, cart.Patrol, cart.Stops, "frozen (" + cart.Status + ")" + text));
				string StopNote()
				{
					string text2 = Routes.StopText(progress);
					if (text2.Length <= 0)
					{
						return "";
					}
					return ", " + text2;
				}
			}
			return list3;
		}

		internal unsafe static object ReadRaw(EntityManager em, Entity e, string typeName)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_008d: 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_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)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			if (!RawTypes.TryGetValue(typeName, out (Type, ComponentType) value))
			{
				Type type = GameTypes.Find(typeName);
				value = (type, (ComponentType)((type == null) ? default(ComponentType) : ComponentType.ReadOnly(Il2CppType.From(type))));
				RawTypes[typeName] = value;
				if (type == null)
				{
					Plugin.Warn("CarriageTracker: game type " + typeName + " not found");
				}
			}
			if (value.Item1 == null || e == Entity.Null || !((EntityManager)(ref em)).Exists(e) || !((EntityManager)(ref em)).HasComponent(e, value.Item2))
			{
				return null;
			}
			void* componentDataRawRO = ((EntityManager)(ref em)).GetComponentDataRawRO(e, value.Item2.TypeIndex);
			if (componentDataRawRO != null)
			{
				return Marshal.PtrToStructure(new IntPtr(componentDataRawRO), value.Item1);
			}
			return null;
		}

		internal static object Field(object boxed, string name)
		{
			return boxed?.GetType().GetField(name)?.GetValue(boxed);
		}

		internal static bool TryGetPatrol(EntityManager em, Entity cart, out Entity patrol)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_003b: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_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_0076: Unknown result type (might be due to invalid IL or missing references)
			patrol = Entity.Null;
			if (!Has<Script_CarriageData>(em, cart))
			{
				return false;
			}
			Script_CarriageData componentData = ((EntityManager)(ref em)).GetComponentData<Script_CarriageData>(cart);
			Entity entityOnServer = ((NetworkedEntity)(ref componentData.Horse)).GetEntityOnServer();
			if (entityOnServer == Entity.Null || !((EntityManager)(ref em)).Exists(entityOnServer) || !Has<SpawnedBy>(em, entityOnServer))
			{
				return false;
			}
			patrol = ((EntityManager)(ref em)).GetComponentData<SpawnedBy>(entityOnServer).Value;
			if (patrol != Entity.Null)
			{
				return ((EntityManager)(ref em)).Exists(patrol);
			}
			return false;
		}

		public static bool OnMap(float3 p)
		{
			//IL_0000: 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)
			if (Math.Abs(p.x) <= 4000f)
			{
				return Math.Abs(p.z) <= 4000f;
			}
			return false;
		}

		public static float3 PositionOf(EntityManager em, Entity entity)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			if (Has<LocalToWorld>(em, entity))
			{
				LocalToWorld componentData = ((EntityManager)(ref em)).GetComponentData<LocalToWorld>(entity);
				return ((LocalToWorld)(ref componentData)).Position;
			}
			if (Has<Translation>(em, entity))
			{
				return ((EntityManager)(ref em)).GetComponentData<Translation>(entity).Value;
			}
			return float3.zero;
		}

		public static float Dist2(float3 a, float3 b)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_0017: 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)
			return math.distance(new float2(a.x, a.z), new float2(b.x, b.z));
		}

		public static string Direction(float dx, float dz)
		{
			double num = (Math.Atan2(dx, dz) * 180.0 / Math.PI + 360.0) % 360.0;
			return L.T("dir." + (int)Math.Round(num / 45.0) % 8);
		}
	}
	internal static class Ct<T>
	{
		public static readonly ComponentType RO = ComponentType.ReadOnly(Il2CppType.Of<T>());

		public static readonly ComponentType RW = ComponentType.ReadWrite(Il2CppType.Of<T>());
	}
	internal static class Queries
	{
		private static readonly Dictionary<string, EntityQuery> Made = new Dictionary<string, EntityQuery>();

		public static void Reset()
		{
			Made.Clear();
		}

		public static EntityQuery Get(EntityManager em, string name, bool includeDisabled, params ComponentType[] all)
		{
			//IL_0014: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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_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_0064: 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_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)
			if (Made.TryGetValue(name, out var value))
			{
				return value;
			}
			EntityQueryBuilder val = default(EntityQueryBuilder);
			((EntityQueryBuilder)(ref val))..ctor(AllocatorHandle.op_Implicit((Allocator)2));
			foreach (ComponentType val2 in all)
			{
				val = ((EntityQueryBuilder)(ref val)).AddAll(val2);
			}
			if (includeDisabled)
			{
				val = ((EntityQueryBuilder)(ref val)).WithOptions((EntityQueryOptions)2);
			}
			value = ((EntityManager)(ref em)).CreateEntityQuery(ref val);
			((EntityQueryBuilder)(ref val)).Dispose();
			Made[name] = value;
			return value;
		}
	}
	internal static class GameTypes
	{
		private static readonly Dictionary<string, Type> Cache = new Dictionary<string, Type>();

		public static Type Find(string simpleName)
		{
			if (Cache.TryGetValue(simpleName, out var value))
			{
				return value;
			}
			Type type = null;
			Type type2 = null;
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				string text = assembly.GetName().Name ?? "";
				if (!text.StartsWith("ProjectM", StringComparison.Ordinal) && !text.StartsWith("Stunlock", StringComparison.Ordinal))
				{
					continue;
				}
				Type[] types;
				try
				{
					types = assembly.GetTypes();
				}
				catch (ReflectionTypeLoadException ex)
				{
					types = ex.Types;
				}
				catch
				{
					continue;
				}
				Type[] array = types;
				foreach (Type type3 in array)
				{
					if (!(type3 == null) && !(type3.Name != simpleName) && type3.IsValueType)
					{
						if (type3.Namespace != null && type3.Namespace.StartsWith("ProjectM", StringComparison.Ordinal))
						{
							type = type3;
							break;
						}
						if ((object)type2 == null)
						{
							type2 = type3;
						}
					}
				}
				if (type != null)
				{
					break;
				}
			}
			if ((object)type == null)
			{
				type = type2;
			}
			Cache[simpleName] = type;
			return type;
		}
	}
	[CommandGroup("carriage", "cv")]
	public class Commands
	{
		private static bool Ready(ChatCommandContext ctx, out EntityManager em, out PrefabCollectionSystem prefabs)
		{
			//IL_0001: 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)
			em = default(EntityManager);
			World val = Caravans.ServerWorld();
			prefabs = ((val == null) ? null : Caravans.Prefabs(val));
			if (prefabs == null)
			{
				ctx.Reply(L.T("world.notready"));
				return false;
			}
			em = val.EntityManager;
			return true;
		}

		private static List<(Caravans.Caravan C, float Dist, string Dir)> Sorted(ChatCommandContext ctx, out EntityManager em)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//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_007f: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			em = default(EntityManager);
			World val = Caravans.ServerWorld();
			if (val == null || !Tracker.Fresh())
			{
				ctx.Reply(L.T("world.notready"));
				return null;
			}
			em = val.EntityManager;
			float3 val2 = Caravans.PositionOf(em, ctx.Event.SenderCharacterEntity);
			List<(Caravans.Caravan, float, string)> list = new List<(Caravans.Caravan, float, string)>();
			foreach (Caravans.Caravan item in Tracker.Current)
			{
				list.Add((item, Caravans.Dist2(item.Pos, val2), Caravans.Direction(item.Pos.x - val2.x, item.Pos.z - val2.z)));
			}
			list.Sort(((Caravans.Caravan C, float Dist, string Dir) a, (Caravans.Caravan C, float Dist, string Dir) b) => a.Dist.CompareTo(b.Dist));
			return list;
		}

		[Command("list", "l", null, "Caravans on the map, nearest first", null, false)]
		public void List(ChatCommandContext ctx)
		{
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			EntityManager em;
			List<(Caravans.Caravan, float, string)> list = Sorted(ctx, out em);
			if (list == null)
			{
				return;
			}
			if (list.Count == 0)
			{
				ctx.Reply(L.T("list.empty"));
				return;
			}
			ctx.Reply(L.T("list.head", list.Count));
			for (int i = 0; i < list.Count; i++)
			{
				var (caravan, num, text) = list[i];
				ctx.Reply(L.T("list.item", i + 1, Routes.Name(caravan.Route, caravan.Patrol), Math.Round(num), text, caravan.Note));
			}
		}

		[Command("mark", "m", "[number]", "Map marker on a caravan, the nearest by default", null, false)]
		public void Mark(ChatCommandContext ctx, int number = 1)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			EntityManager em;
			List<(Caravans.Caravan, float, string)> list = Sorted(ctx, out em);
			if (list != null)
			{
				if (list.Count == 0)
				{
					ctx.Reply(L.T("list.empty"));
					return;
				}
				if (number < 1 || number > list.Count)
				{
					ctx.Reply(L.T("mark.bad", number));
					return;
				}
				var (caravan, num, text) = list[number - 1];
				SetMarker(ctx, em, caravan.Pos);
				ctx.Reply(L.T("mark.ok", Routes.Name(caravan.Route, caravan.Patrol), Math.Round(num), text, caravan.Note));
			}
		}

		private static void SetMarker(ChatCommandContext ctx, EntityManager em, float3 pos)
		{
			//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_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_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_0031: 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_0037: 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_0057: 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_0069: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			Entity val = ((EntityManager)(ref em)).CreateEntity((ComponentType[])(object)new ComponentType[3]
			{
				Ct<FromCharacter>.RW,
				Ct<SetMapMarkerEvent>.RW,
				Ct<ReceiveNetworkEventTag>.RW
			});
			((EntityManager)(ref em)).SetComponentData<FromCharacter>(val, new FromCharacter
			{
				User = ctx.Event.SenderUserEntity,
				Character = ctx.Event.SenderCharacterEntity
			});
			((EntityManager)(ref em)).SetComponentData<SetMapMarkerEvent>(val, new SetMapMarkerEvent
			{
				Position = new float2(pos.x, pos.z)
			});
		}

		[Command("routemark", "rm", "<number from .cv routes>", "Map marker on the point of a route from .cv routes", null, false)]
		public void RouteMark(ChatCommandContext ctx, int number)
		{
			//IL_0015: 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_0056: 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_0062: 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_0073: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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)
			//IL_00b3: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			if (RouteCommandAllowed(ctx) && Ready(ctx, out var em, out var prefabs))
			{
				List<Routes.Route> list = Routes.All(em, prefabs);
				if (number < 1 || number > list.Count)
				{
					ctx.Reply(L.T("start.bad", number));
					return;
				}
				Routes.Route route = list[number - 1];
				float3 val = Caravans.PositionOf(em, route.Patrol);
				float3 val2 = Caravans.PositionOf(em, ctx.Event.SenderCharacterEntity);
				SetMarker(ctx, em, val);
				ctx.Reply(L.T("routemark.ok", Routes.Name(route), Math.Round(Caravans.Dist2(val, val2)), Caravans.Direction(val.x - val2.x, val.z - val2.z)));
			}
		}

		private static bool RouteCommandAllowed(ChatCommandContext ctx)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if (Settings.RouteCommandsForAll.Value || ctx.Event.User.IsAdmin)
			{
				return true;
			}
			ctx.Reply(L.T("routes.adminonly"));
			return false;
		}

		[Command("routes", "r", null, "All carriage routes with region, level, act and state", null, false)]
		public void RoutesList(ChatCommandContext ctx)
		{
			//IL_0015: 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_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_0065: 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_0074: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			if (RouteCommandAllowed(ctx) && Ready(ctx, out var em, out var prefabs))
			{
				List<Routes.Route> list = Routes.All(em, prefabs);
				float3 val = Caravans.PositionOf(em, ctx.Event.SenderCharacterEntity);
				ctx.Reply(L.T("routes.head", list.Count));
				for (int i = 0; i < list.Count; i++)
				{
					Routes.Route route = list[i];
					float3 val2 = Caravans.PositionOf(em, route.Patrol);
					Acts.RouteAct routeAct = Acts.OfRoute(em, prefabs, route);
					string text = Routes.StopText(Routes.StopsOf(em, route.Patrol));
					ctx.Reply(L.T("routes.item", i + 1, Routes.Name(route), route.Key, routeAct.Level, L.ActList(routeAct.Acts), routeAct.Manual ? L.T("routes.manual") : "", Routes.Describe(em, route.Patrol), Starter.IsRunning(route.Patrol) ? L.T("routes.running") : "", Math.Round(Caravans.Dist2(val2, val)), Caravans.Direction(val2.x - val.x, val2.z - val.z), (text.Length > 0) ? (", " + text) : "", Settings.Excluded(route.Key) ? L.T("routes.excluded") : "", L.Region(ActLogic.Region(route.Key))));
				}
			}
		}

		[Command("act", "a", null, "Your act (by V Blood or level, see PlayerAct) and the carriage routes you get", null, false)]
		public void Act(ChatCommandContext ctx)
		{
			//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_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			if (!Ready(ctx, out var em, out var prefabs))
			{
				return;
			}
			Acts.PlayerAct playerAct = Acts.OfUser(em, prefabs, ctx.Event.SenderUserEntity);
			string text = (playerAct.ByLevel ? L.T("act.bylevel", playerAct.Level) : "");
			string text2 = ((playerAct.Boss == null) ? L.T("act.none", L.Act(playerAct.Act), text) : L.T("act.mine", L.Act(playerAct.Act), text, playerAct.Drunk, playerAct.Boss, playerAct.BossLevel));
			if (playerAct.Opened > 0 && playerAct.ByVBlood == playerAct.Opened + 1 && !playerAct.ByLevel)
			{
				text2 += L.T("act.next", L.Act(playerAct.Opened), L.Act(playerAct.ByVBlood));
			}
			if (Settings.PlayerActMode != PlayerActBy.VBlood && !playerAct.ByLevel && playerAct.Level > 0)
			{
				text2 += L.T("act.level", playerAct.Level);
			}
			ctx.Reply(text2);
			List<Acts.OnlinePlayer> list = Acts.Online(em, prefabs);
			if (list.Count > 1 && (Settings.ShowOthersActs.Value || ctx.Event.User.IsAdmin))
			{
				List<string> list2 = new List<string>();
				foreach (Acts.OnlinePlayer item2 in list)
				{
					list2.Add(item2.Name + " - " + L.Act(item2.Act.Act));
				}
				foreach (string item3 in ChatLines.Pack(list2, ", ", L.T("act.online", "")))
				{
					ctx.Reply(item3);
				}
			}
			List<int> list3 = Acts.Served(playerAct.Act, Acts.WithRoutes(em, prefabs));
			if (list3.Count == 0)
			{
				ctx.Reply(L.T("act.noroutes", L.Act(playerAct.Act)));
				return;
			}
			if (!list3.Contains(playerAct.Act))
			{
				ctx.Reply(L.T("act.empty", L.Act(playerAct.Act), L.ActList(list3)));
			}
			List<string> list4 = new List<string>();
			foreach (Routes.Route item4 in Routes.All(em, prefabs))
			{
				if (!Settings.Excluded(item4.Key))
				{
					string item = Routes.Name(item4);
					if (Acts.OfRoute(em, prefabs, item4).Acts.Overlaps(list3) && !list4.Contains(item))
					{
						list4.Add(item);
					}
				}
			}
			foreach (string item5 in ChatLines.Pack(list4, ", ", L.T("act.routes", L.ActList(list3), "")))
			{
				ctx.Reply(item5);
			}
		}

		[Command("icon", null, "<merchant|unknown|vblood|number>", "Change the caravan map icon. Numbers: .cv icons", null, true)]
		public void Icon(ChatCommandContext ctx, string icon)
		{
			//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_004c: 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_0057: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
			if (!Ready(ctx, out var em, out var prefabs))
			{
				return;
			}
			if (!Settings.TryParseIcon(icon, out var guid))
			{
				ctx.Reply(L.T("icon.bad", icon, Settings.IconPresetNames));
				return;
			}
			PrefabGUID val = default(PrefabGUID);
			((PrefabGUID)(ref val))..ctor(guid);
			Entity e = default(Entity);
			if (!prefabs._PrefabGuidToEntityMap.TryGetValue(val, ref e) || !Caravans.Has<MapIconData>(em, e))
			{
				ctx.Reply(L.T("icon.notmap", icon));
				return;
			}
			if (Settings.IconGuid != guid)
			{
				HashSet<int> hashSet = Icons.Ours();
				hashSet.Remove(guid);
				Settings.OldIcons.Value = string.Join(",", hashSet);
				Settings.Icon.Value = icon.Trim();
				Settings.Save();
			}
			Tracker.Tick(forceFull: false);
			PrefabLookupMap prefabLookupMap = prefabs._PrefabLookupMap;
			string text = default(string);
			if (!((PrefabLookupMap)(ref prefabLookupMap)).TryGetName(val, ref text))
			{
				text = "?";
			}
			ctx.Reply(L.T("icon.ok", text, guid) + " " + Tracker.LastStats);
		}

		[Command("icons", null, "[filter] [page]", "Map icons of the game with their numbers, for .cv icon", null, true)]
		public void IconList(ChatCommandContext ctx, string filter = "all", int page = 1)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//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_0048: 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)
			if (!Ready(ctx, out var _, out var prefabs))
			{
				return;
			}
			bool flag = filter.Equals("all", StringComparison.OrdinalIgnoreCase);
			List<(string, int)> list = new List<(string, int)>();
			Enumerator<PrefabGUID, Entity> enumerator = prefabs._PrefabGuidToEntityMap.GetEnumerator();
			string text = default(string);
			while (enumerator.MoveNext())
			{
				KeyValue<PrefabGUID, Entity> current = enumerator.Current;
				PrefabLookupMap prefabLookupMap = prefabs._PrefabLookupMap;
				if (((PrefabLookupMap)(ref prefabLookupMap)).TryGetName(current.Key, ref text) && !string.IsNullOrEmpty(text) && text.StartsWith("MapIcon", StringComparison.OrdinalIgnoreCase) && (flag || text.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0))
				{
					string item = text;
					PrefabGUID key = current.Key;
					list.Add((item, ((PrefabGUID)(ref key)).GuidHash));
				}
			}
			list.Sort(((string Name, int Guid) a, (string Name, int Guid) b) => string.CompareOrdinal(a.Name, b.Name));
			foreach (var item2 in list)
			{
				Plugin.Info($"CarriageTracker icon: {item2.Item1} {item2.Item2}");
			}
			int num = Math.Max(1, (list.Count + 15 - 1) / 15);
			page = Math.Clamp(page, 1, num);
			ctx.Reply(L.T("icons.head", list.Count, page, num));
			for (int num2 = (page - 1) * 15; num2 < list.Count && num2 < page * 15; num2++)
			{
				ctx.Reply($"{list[num2].Item1} ({list[num2].Item2})");
			}
		}

		[Command("mode", null, "<direct|proxy>", "direct - icon on the caravan itself, proxy - on a separate marker", null, true)]
		public void Mode(ChatCommandContext ctx, string mode)
		{
			mode = mode.ToLowerInvariant();
			if (mode != "direct" && mode != "proxy")
			{
				ctx.Reply(L.T("mode.bad"));
				return;
			}
			Settings.IconMode.Value = mode;
			Settings.Save();
			if (!Tracker.Tick(forceFull: false))
			{
				ctx.Reply(L.T("world.notready"));
			}
			else
			{
				ctx.Reply(Tracker.LastStats);
			}
		}

		[Command("stats", null, null, "Results of the last check", null, true)]
		public void Stats(ChatCommandContext ctx)
		{
			ctx.Reply(Tracker.LastStats);
		}

		[Command("refresh", null, null, "Fast and full caravan search right now", null, true)]
		public void Refresh(ChatCommandContext ctx)
		{
			if (!Tracker.Tick(forceFull: true))
			{
				ctx.Reply(L.T("world.notready"));
			}
			else
			{
				ctx.Reply(Tracker.LastStats);
			}
		}

		[Command("lang", null, "<en|ru>", "Your language of the mod's chat messages", null, false)]
		public void Lang(ChatCommandContext ctx, string lang)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			lang = lang.Trim().ToLowerInvariant();
			if (!L.Known(lang))
			{
				ctx.Reply("en | ru");
				return;
			}
			bool flag = Languages.Set(ctx.Event.User.PlatformId, lang);
			L.Use(lang);
			ctx.Reply(flag ? L.T("lang.ok") : (L.T("lang.ok") + " " + L.T("lang.unsaved")));
		}

		[Command("start", null, "<number from .cv routes>", "Start a caravan on a route now", null, true)]
		public void StartCaravan(ChatCommandContext ctx, int number)
		{
			//IL_000d: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			if (Ready(ctx, out var em, out var prefabs))
			{
				List<Routes.Route> list = Routes.All(em, prefabs);
				if (number < 1 || number > list.Count)
				{
					ctx.Reply(L.T("start.bad", number));
				}
				else
				{
					ctx.Reply(Starter.Start(em, list[number - 1], ctx.Event.SenderUserEntity));
				}
			}
		}

		[Command("startstatus", "ss", null, "How the started caravans are doing", null, true)]
		public void StartStatus(ChatCommandContext ctx)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			if (!Ready(ctx, out var em, out var _))
			{
				return;
			}
			foreach (string item in Starter.Status(em))
			{
				ctx.Reply(item);
			}
		}

		[Command("stop", null, null, "Stop tracking all started caravans and restore normal route settings", null, true)]
		public void StopAll(ChatCommandContext ctx)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			if (Ready(ctx, out var em, out var _))
			{
				ctx.Reply(L.T("stop.ok", Starter.StopAll(em)));
			}
		}

		[Command("auto", null, "[minutes]", "Auto-start: no number - status, number - interval in minutes per act, 0 - off", null, true)]
		public void Auto(ChatCommandContext ctx, int minutes = -1)
		{
			if (minutes >= 0)
			{
				Settings.AutoInterval.Value = minutes;
				Settings.Save();
				if (minutes > 0)
				{
					AutoStart.Restart();
				}
			}
			int value = Settings.AutoInterval.Value;
			ctx.Reply(SourceText());
			if (Settings.GameOnly)
			{
				return;
			}
			if (value <= 0)
			{
				ctx.Reply(L.T("auto.off"));
				return;
			}
			ctx.Reply(L.T("auto.status", value, Settings.LeaderScope ? L.T("auto.scope.leader") : L.T("auto.scope.all"), Settings.AutoMaxPerAct.Value, Settings.AutoMaxTotal.Value, Starter.AutoCount()));
			List<string> list = new List<string>();
			for (int i = 1; i <= 4; i++)
			{
				list.Add(L.T("auto.actline", L.Act(i), Starter.AutoCount(i), Math.Ceiling(AutoStart.MinutesLeft(i))));
			}
			foreach (string item in ChatLines.Pack(list, "; "))
			{
				ctx.Reply(item);
			}
			if (AutoStart.LastResults.Count <= 0)
			{
				return;
			}
			foreach (string item2 in ChatLines.Pack(AutoStart.LastResults.ConvertAll((LateText t) => t.ToString()), "; ", L.T("auto.last", "")))
			{
				ctx.Reply(item2);
			}
		}

		private static string SourceText()
		{
			return L.T("source.now", Settings.ModOnly ? L.T("source.mod") : (Settings.GameOnly ? L.T("source.game") : L.T("source.both"))) + ((Settings.ModOnly && Settings.AutoInterval.Value <= 0) ? (" " + L.T("auto.modoff")) : "");
		}

		[Command("source", null, "[mod|game|both]", "Who starts caravans: only the mod, only the game, or both", null, true)]
		public void Source(ChatCommandContext ctx, string source = "")
		{
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			if (!Ready(ctx, out var em, out var prefabs))
			{
				return;
			}
			if (source.Length > 0)
			{
				string text = source.Trim().ToLowerInvariant() switch
				{
					"mod" => "Mod", 
					"game" => "Game", 
					"both" => "Both", 
					_ => null, 
				};
				if (text == null)
				{
					ctx.Reply("mod | game | both");
					return;
				}
				Settings.Source.Value = text;
				Settings.Save();
				Plugin.Info("CarriageTracker: source set to " + text + " by command");
				if (text != "Game")
				{
					AutoStart.Restart();
				}
				Starter.ApplySource(em, prefabs);
			}
			ctx.Reply(SourceText());
		}

		[Command("cleanup", null, null, "Before removing the mod: stop starts, give routes the game's settings back, remove the mod's icons", null, true)]
		public void Cleanup(ChatCommandContext ctx)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			if (Ready(ctx, out var em, out var prefabs))
			{
				(int, int, int) tuple = Starter.Cleanup(em, prefabs);
				Tracker.Tick(forceFull: false);
				Plugin.Info($"CarriageTracker: cleanup by command: stopped {tuple.Item1} starts, restored {tuple.Item2} routes and {tuple.Item3} units, " + "icons removed; the mod changes nothing more until the server restarts");
				ctx.Reply(L.T("cleanup.ok", tuple.Item1, tuple.Item2, tuple.Item3));
			}
		}

		[Command("autonow", "an", null, "Run auto-start right now, ignoring the interval", null, true)]
		public void AutoNow(ChatCommandContext ctx)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			if (!Ready(ctx, out var em, out var prefabs))
			{
				return;
			}
			List<(bool, LateText)> list = AutoStart.Run(em, prefabs, force: true);
			if (list.Count == 0)
			{
				ctx.Reply(L.T("auto.nothing"));
				return;
			}
			foreach (var item in list)
			{
				Plugin.Info($"CarriageTracker auto (command): {item.Item2}");
				ctx.Reply(item.Item2.ToString());
			}
		}
	}
	[CommandGroup("cvdiag", null)]
	public class DiagCommands
	{
		private sealed class StopSeen
		{
			public int ChunkX;

			public int ChunkZ;

			public bool Exact;

			public float X;

			public float Z;

			public string How;

			public readonly List<string> Users = new List<string>();
		}

		private static readonly string[] ScriptTypes = new string[4] { "Script_CarriageData", "Script_CarriageDriverData", "Script_CarriageCollidersData", "Script_RespawnCarriageUponLost_Data" };

		private static readonly string[] Interesting = new string[33]
		{
			"Carriage", "Script_", "Respawn", "Spawn", "Route", "Travel", "Path", "Patrol", "Waypoint", "Timer",
			"Lifetime", "Follow", "Horse", "Driver", "Mount", "Lost", "Teleport", "Move", "Idle", "Disable",
			"Hidden", "Owner", "Attach", "Translation", "Transform", "Chain", "Leader", "Group", "Squad", "Minion",
			"Master", "Region", "Range"
		};

		private static readonly List<Entity> Refs = new List<Entity>();

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

		private static MethodInfo _getBuffer;

		private static readonly string[] PrefabMarks = new string[10] { "VBlood", "Boss", "Soul", "Shard", "Incursion", "Rift", "Gate", "DropTable", "Consume", "Unlock" };

		private static readonly Regex StopPattern = new Regex("Chunk=(-?\\d+),\\s*(-?\\d+), BusStopGuid=([0-9a-fA-F\\-]+)", RegexOptions.Compiled);

		private static readonly Regex PositionPattern = new Regex("Position=\\((-?[\\d.]+), -?[\\d.]+, (-?[\\d.]+)\\)", RegexOptions.Compiled);

		[Command("comps", null, "[radius]", "Components of the nearest caravan object", null, true)]
		public void Comps(ChatCommandContext ctx, int radius = 10)
		{
			//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_003a: 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_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_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_005e: 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_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_0076: 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_0081: 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_009b: 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_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: 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_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: 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_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: 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_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			World val = Caravans.ServerWorld();
			PrefabCollectionSystem val2 = ((val == null) ? null : Caravans.Prefabs(val));
			if (val2 == null)
			{
				ctx.Reply(L.T("world.notready"));
				return;
			}
			EntityManager entityManager = val.EntityManager;
			float3 b = Caravans.PositionOf(entityManager, ctx.Event.SenderCharacterEntity);
			Entity val3 = Entity.Null;
			float num = float.MaxValue;
			EntityQueryBuilder val4 = new EntityQueryBuilder(AllocatorHandle.op_Implicit((Allocator)2));
			val4 = ((EntityQueryBuilder)(ref val4)).AddAll(Ct<PrefabGUID>.RO);
			EntityQueryBuilder val5 = ((EntityQueryBuilder)(ref val4)).WithOptions((EntityQueryOptions)2);
			EntityQuery val6 = ((EntityManager)(ref entityManager)).CreateEntityQuery(ref val5);
			((EntityQueryBuilder)(ref val5)).Dispose();
			NativeArray<Entity> val7 = ((EntityQuery)(ref val6)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			try
			{
				Enumerator<Entity> enumerator = val7.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					if (Caravans.Classify(val2, ((EntityManager)(ref entityManager)).GetComponentData<PrefabGUID>(current)).Kind != Kind.None)
					{
						float num2 = Caravans.Dist2(Caravans.PositionOf(entityManager, current), b);
						if (num2 <= (float)radius && num2 < num)
						{
							num = num2;
							val3 = current;
						}
					}
				}
			}
			finally
			{
				val7.Dispose();
				((EntityQuery)(ref val6)).Dispose();
			}
			if (val3 == Entity.Null)
			{
				ctx.Reply($"No caravan objects within {radius} m.");
				return;
			}
			List<string> list = new List<string>();
			NativeArray<ComponentType> componentTypes = ((EntityManager)(ref entityManager)).GetComponentTypes(val3, (Allocator)2);
			try
			{
				for (int i = 0; i < componentTypes.Length; i++)
				{
					list.Add(((MemberInfo)TypeManager.GetType(componentTypes[i].TypeIndex)).Name);
				}
			}
			finally
			{
				componentTypes.Dispose();
			}
			list.Sort(StringComparer.Ordinal);
			PrefabLookupMap prefabLookupMap = val2._PrefabLookupMap;
			string text = default(string);
			if (!((PrefabLookupMap)(ref prefabLookupMap)).TryGetName(((EntityManager)(ref entityManager)).GetComponentData<PrefabGUID>(val3), ref text))
			{
				text = "?";
			}
			Plugin.Info("CarriageTracker comps " + text + ": " + string.Join(", ", list));
			ctx.Reply($"{text}, {Math.Round(num)} m, components: {list.Count}. Full list in the server log.");
			for (int j = 0; j < list.Count; j += 6)
			{
				ctx.Reply(string.Join(", ", list.GetRange(j, Math.Min(6, list.Count - j))));
			}
			List<string> list2 = new List<string>();
			NativeArray<ComponentType> componentTypes2 = ((EntityManager)(ref entityManager)).GetComponentTypes(val3, (Allocator)2);
			try
			{
				for (int k = 0; k < componentTypes2.Length; k++)
				{
					Type type = TypeManager.GetType(componentTypes2[k].TypeIndex);
					if (type == (Type)null || !IsTimer(((MemberInfo)type).Name))
					{
						continue;
					}
					Type type2 = ManagedByFullName(type.FullName);
					string text2;
					if (type2 == null || !type2.IsValueType)
					{
						text2 = "(unreadable)";
					}
					else if (type2.GetFields(BindingFlags.Instance | BindingFlags.Public).Length == 0)
					{
						text2 = "(tag without data)";
					}
					else
					{
						try
						{
							object obj = ReadRaw(entityManager, val3, componentTypes2[k], type2);
							text2 = ((obj == null) ? "null" : Fields(obj, entityManager, val2, 0));
						}
						catch (Exception ex)
						{
							text2 = "<" + (ex.Message ?? "").Split('\n')[0] + ">";
						}
					}
					list2.Add(((MemberInfo)type).Name + ": " + text2);
				}
			}
			finally
			{
				componentTypes2.Dispose();
			}
			foreach (string item in list2)
			{
				Plugin.Info("CarriageTracker comps " + text + " " + item);
				foreach (string item2 in ChatLines.Pack(item.Split(", "), ", "))
				{
					ctx.Reply(item2);
				}
			}
		}

		private static bool IsTimer(string name)
		{
			if (!name.StartsWith("Destroy", StringComparison.Ordinal) && name.IndexOf("LifeTime", StringComparison.OrdinalIgnoreCase) < 0)
			{
				return name.StartsWith("Age", StringComparison.Ordinal);
			}
			return true;
		}

		[Command("near", null, "[radius]", "Objects around you with names and ids", null, true)]
		public void Near(ChatCommandContext ctx, int radius = 8)
		{
			//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_003a: 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_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_0057: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_0090: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			World val = Caravans.ServerWorld();
			PrefabCollectionSystem val2 = ((val == null) ? null : Caravans.Prefabs(val));
			if (val2 == null)
			{
				ctx.Reply(L.T("world.notready"));
				return;
			}
			EntityManager entityManag