Decompiled source of KindredSchematics v1.1.0

KindredSchematics.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
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.Json;
using System.Text.Json.Serialization;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppSystem.Reflection;
using Il2CppSystem.Text;
using KindredSchematics.Commands.Converter;
using KindredSchematics.ComponentSaver;
using KindredSchematics.Data;
using KindredSchematics.JsonConverters;
using KindredSchematics.Patches;
using KindredSchematics.Services;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.CastleBuilding;
using ProjectM.Network;
using ProjectM.Physics;
using ProjectM.Scripting;
using ProjectM.Shared;
using ProjectM.Tiles;
using Stunlock.Core;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Physics;
using Unity.Scenes;
using Unity.Transforms;
using UnityEngine;
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("KindredSchematics")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Save and load builds")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1+2.Branch.main.Sha.62bb8fcf39ee2ebe62410e48ec8f8fdc72e85b10.26af8728903f6aa0df3c25ec20042c5e4a8a690e")]
[assembly: AssemblyProduct("KindredSchematics")]
[assembly: AssemblyTitle("KindredSchematics")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.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 KindredSchematics
{
	internal static class AabbHelper
	{
		public static bool MatchesOnTwoAxesAndOverlaps(this Aabb thisOne, Aabb other, float tolerance = 0.01f)
		{
			//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_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_001f: 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_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_0045: 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_0050: 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_0064: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			bool flag = Mathf.Abs(thisOne.Min.x - other.Min.x) <= tolerance && Mathf.Abs(thisOne.Max.x - other.Max.x) <= tolerance;
			bool flag2 = Mathf.Abs(thisOne.Min.y - other.Min.y) <= tolerance && Mathf.Abs(thisOne.Max.y - other.Max.y) <= tolerance;
			bool flag3 = Mathf.Abs(thisOne.Min.z - other.Min.z) <= tolerance && Mathf.Abs(thisOne.Max.z - other.Max.z) <= tolerance;
			if (flag && flag2)
			{
				if (thisOne.Min.z <= other.Max.z)
				{
					return thisOne.Max.z >= other.Min.z;
				}
				return false;
			}
			if (flag && flag3)
			{
				if (thisOne.Min.y <= other.Max.y)
				{
					return thisOne.Max.y >= other.Min.y;
				}
				return false;
			}
			if (flag2 && flag3)
			{
				if (thisOne.Min.x <= other.Max.x)
				{
					return thisOne.Max.x >= other.Min.x;
				}
				return false;
			}
			return false;
		}

		public static void MergeAabbsTogether(List<Aabb> aabbs)
		{
			//IL_0017: 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_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_005a: 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_003b: 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_007b: 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)
			for (int i = 0; i < aabbs.Count - 1; i++)
			{
				for (int num = aabbs.Count - 1; num > i; num--)
				{
					Aabb val;
					if (aabbs[i].MatchesOnTwoAxesAndOverlaps(aabbs[num]))
					{
						val = aabbs[i];
						((Aabb)(ref val)).Include(aabbs[num]);
						aabbs.RemoveAt(num);
					}
					else
					{
						val = aabbs[i];
						if (((Aabb)(ref val)).Contains(aabbs[num]))
						{
							aabbs.RemoveAt(num);
						}
						else
						{
							val = aabbs[num];
							if (((Aabb)(ref val)).Contains(aabbs[i]))
							{
								aabbs[i] = aabbs[num];
								aabbs.RemoveAt(num);
							}
						}
					}
				}
			}
		}
	}
	internal class Buffs
	{
		public static bool AddBuff(Entity User, Entity Character, PrefabGUID buffPrefab, int duration = 0, bool immortal = false)
		{
			//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_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_001d: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: 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_00af: 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_0109: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			DebugEventsSystem existingSystemManaged = Core.Server.GetExistingSystemManaged<DebugEventsSystem>();
			ApplyBuffDebugEvent val = default(ApplyBuffDebugEvent);
			val.BuffPrefabGUID = buffPrefab;
			ApplyBuffDebugEvent val2 = val;
			FromCharacter val3 = default(FromCharacter);
			val3.User = User;
			val3.Character = Character;
			FromCharacter val4 = val3;
			Entity entity = default(Entity);
			if (!BuffUtility.TryGetBuff(Core.Server.EntityManager, Character, PrefabIdentifier.op_Implicit(buffPrefab), ref entity))
			{
				existingSystemManaged.ApplyBuff(val4, val2);
				if (BuffUtility.TryGetBuff(Core.Server.EntityManager, Character, PrefabIdentifier.op_Implicit(buffPrefab), ref entity))
				{
					if (entity.Has<CreateGameplayEventsOnSpawn>())
					{
						entity.Remove<CreateGameplayEventsOnSpawn>();
					}
					if (entity.Has<GameplayEventListeners>())
					{
						entity.Remove<GameplayEventListeners>();
					}
					if (immortal)
					{
						entity.Add<Buff_Persists_Through_Death>();
						if (entity.Has<RemoveBuffOnGameplayEvent>())
						{
							entity.Remove<RemoveBuffOnGameplayEvent>();
						}
						if (entity.Has<RemoveBuffOnGameplayEventEntry>())
						{
							entity.Remove<RemoveBuffOnGameplayEventEntry>();
						}
					}
					if (duration > -1 && duration != 0)
					{
						if (!entity.Has<LifeTime>())
						{
							entity.Add<LifeTime>();
							entity.Write<LifeTime>(new LifeTime
							{
								EndAction = (LifeTimeEndAction)2
							});
						}
						LifeTime componentData = entity.Read<LifeTime>();
						componentData.Duration = duration;
						entity.Write<LifeTime>(componentData);
					}
					else if (duration == -1)
					{
						if (entity.Has<LifeTime>())
						{
							LifeTime componentData2 = entity.Read<LifeTime>();
							componentData2.Duration = -1f;
							componentData2.EndAction = (LifeTimeEndAction)0;
							entity.Write<LifeTime>(componentData2);
						}
						if (entity.Has<RemoveBuffOnGameplayEvent>())
						{
							entity.Remove<RemoveBuffOnGameplayEvent>();
						}
						if (entity.Has<RemoveBuffOnGameplayEventEntry>())
						{
							entity.Remove<RemoveBuffOnGameplayEventEntry>();
						}
					}
					return true;
				}
				return false;
			}
			return false;
		}

		public static void RemoveBuff(Entity Character, PrefabGUID buffPrefab)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			Entity val = default(Entity);
			if (BuffUtility.TryGetBuff(Core.EntityManager, Character, PrefabIdentifier.op_Implicit(buffPrefab), ref val))
			{
				DestroyUtility.Destroy(Core.EntityManager, val, (DestroyDebugReason)13, (string)null, 0);
			}
		}
	}
	internal static class Core
	{
		public const int MAX_REPLY_LENGTH = 509;

		private static ServerScriptMapper serverScriptMapper;

		private static MonoBehaviour monoBehaviour;

		private static bool _hasInitialized = false;

		public static World Server { get; } = GetWorld("Server") ?? throw new Exception("There is no Server world (yet). Did you install a server mod on the client?");


		public static EntityManager EntityManager { get; } = Server.EntityManager;


		public static double ServerTime => ServerGameManager.ServerTime;

		public static ServerGameManager ServerGameManager => ServerScriptMapper.GetServerGameManager();

		public static CastleBuildingAttachmentBuffSystem CastleBuildingAttachmentBuffSystem { get; } = Server.GetExistingSystemManaged<CastleBuildingAttachmentBuffSystem>();


		public static CastleTerritoryService CastleTerritory { get; private set; }

		public static PrefabCollectionSystem PrefabCollection { get; } = Server.GetExistingSystemManaged<PrefabCollectionSystem>();


		public static RespawnPreventionService RespawnPrevention { get; } = new RespawnPreventionService();


		public static SchematicService SchematicService { get; } = new SchematicService();


		public static ConfigSettingsService ConfigSettings { get; } = new ConfigSettingsService();


		public static ServerScriptMapper ServerScriptMapper
		{
			get
			{
				if (serverScriptMapper == null)
				{
					serverScriptMapper = Server.GetExistingSystemManaged<ServerScriptMapper>();
				}
				return serverScriptMapper;
			}
		}

		public static ManualLogSource Log { get; } = Plugin.PluginLog;


		public static void LogException(Exception e, [CallerMemberName] string caller = null)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			ManualLogSource log = Log;
			bool flag = default(bool);
			BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(51, 5, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failure in ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(caller);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\nMessage: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(e.Message);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" Inner:");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(e.InnerException?.Message);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\n\nStack: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(e.StackTrace);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\nInner Stack: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(e.InnerException?.StackTrace);
			}
			log.LogError(val);
		}

		internal static void InitializeAfterLoaded()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			if (!_hasInitialized)
			{
				_hasInitialized = true;
				KindredSchematics.ComponentSaver.ComponentSaver.PopulateComponentSavers();
				CastleTerritory = new CastleTerritoryService();
				Tile.Populate();
				ManualLogSource log = Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(29, 0, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("KindredSchematics Initialized");
				}
				log.LogInfo(val);
			}
		}

		private static World GetWorld(string name)
		{
			Enumerator<World> enumerator = World.s_AllWorlds.GetEnumerator();
			while (enumerator.MoveNext())
			{
				World current = enumerator.Current;
				if (current.Name == name)
				{
					return current;
				}
			}
			return null;
		}

		public static Coroutine StartCoroutine(IEnumerator routine)
		{
			//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_0027: Expected O, but got Unknown
			if ((Object)(object)monoBehaviour == (Object)null)
			{
				GameObject val = new GameObject("KindredSchematics");
				monoBehaviour = (MonoBehaviour)(object)val.AddComponent<IgnorePhysicsDebugSystem>();
				Object.DontDestroyOnLoad((Object)val);
			}
			return monoBehaviour.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(routine));
		}

		public static void StopCoroutine(Coroutine coroutine)
		{
			if (!((Object)(object)monoBehaviour == (Object)null))
			{
				monoBehaviour.StopCoroutine(coroutine);
			}
		}
	}
	public static class ECSExtensions
	{
		public unsafe static void Write<T>(this Entity entity, T componentData) where T : struct
		{
			//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_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)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			byte[] array = StructureToByteArray(componentData);
			int num = Marshal.SizeOf<T>();
			fixed (byte* ptr = array)
			{
				EntityManager entityManager = Core.EntityManager;
				((EntityManager)(ref entityManager)).SetComponentDataRaw(entity, val.TypeIndex, (void*)ptr, num);
			}
		}

		public static byte[] StructureToByteArray<T>(T structure) where T : struct
		{
			int num = Marshal.SizeOf(structure);
			byte[] array = new byte[num];
			IntPtr intPtr = Marshal.AllocHGlobal(num);
			Marshal.StructureToPtr(structure, intPtr, fDeleteOld: true);
			Marshal.Copy(intPtr, array, 0, num);
			Marshal.FreeHGlobal(intPtr);
			return array;
		}

		public unsafe static T Read<T>(this Entity entity) where T : struct
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0017: Unknown result type (might be due to invalid IL or missing references)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = Core.EntityManager;
			return Marshal.PtrToStructure<T>(new IntPtr(((EntityManager)(ref entityManager)).GetComponentDataRawRO(entity, val.TypeIndex)));
		}

		public static bool Has<T>(this Entity entity)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = Core.EntityManager;
			return ((EntityManager)(ref entityManager)).HasComponent(entity, val);
		}

		public static string LookupName(this PrefabGUID prefabGuid)
		{
			//IL_0011: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			PrefabCollectionSystem existingSystemManaged = Core.Server.GetExistingSystemManaged<PrefabCollectionSystem>();
			object obj;
			if (!existingSystemManaged.PrefabGuidToNameDictionary.ContainsKey(prefabGuid))
			{
				obj = "GUID Not Found";
			}
			else
			{
				string text = existingSystemManaged.PrefabGuidToNameDictionary[prefabGuid];
				PrefabGUID val = prefabGuid;
				obj = text + " " + ((object)(PrefabGUID)(ref val)).ToString();
			}
			return obj.ToString();
		}

		public static void Add<T>(this Entity entity)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = Core.EntityManager;
			((EntityManager)(ref entityManager)).AddComponent(entity, val);
		}

		public static void Remove<T>(this Entity entity)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = Core.EntityManager;
			((EntityManager)(ref entityManager)).RemoveComponent(entity, val);
		}
	}
	internal class EntityMapper
	{
		private Dictionary<Entity, int> entityIndexLookup = new Dictionary<Entity, int>();

		private List<Entity> entities = new List<Entity>();

		public Entity this[int index] => entities[index];

		public int Count => entities.Count;

		public EntityMapper()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			entityIndexLookup = new Dictionary<Entity, int>();
			entities = new List<Entity>();
			AddEntity(Entity.Null);
		}

		public EntityMapper(IEnumerable<Entity> entitiesToAdd)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			entityIndexLookup = new Dictionary<Entity, int>();
			entities = new List<Entity>();
			AddEntity(Entity.Null);
			foreach (Entity item in entitiesToAdd)
			{
				AddEntity(item);
			}
		}

		public int AddEntity(Entity entity)
		{
			//IL_0000: 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_0023: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			if (entity.Has<Prefab>())
			{
				throw new ArgumentException("Cannot add entities with Prefab component to EntityMapper");
			}
			if (entity.Has<CastleHeart>())
			{
				return 0;
			}
			if (!entityIndexLookup.TryGetValue(entity, out var value))
			{
				value = entities.Count;
				entityIndexLookup[entity] = value;
				entities.Add(entity);
			}
			return value;
		}

		public int IndexOf(Entity entity)
		{
			//IL_0006: 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)
			if (entityIndexLookup.TryGetValue(entity, out var value))
			{
				return value;
			}
			return AddEntity(entity);
		}
	}
	public struct ComponentData
	{
		public string component { get; set; }

		public object data { get; set; }
	}
	public struct EntityData
	{
		public PrefabGUID prefab { get; set; }

		public Vector3? pos { get; set; }

		public Quaternion? rot { get; set; }

		public int2? tilePos { get; set; }

		public int2? tileBoundsMin { get; set; }

		public int2? tileBoundsMax { get; set; }

		public ComponentData[] componentData { get; set; }

		public int[] removals { get; set; }

		public bool? notCastleTeam { get; set; }
	}
	internal class EntityPrefabDiff
	{
		public static EntityData DiffFromPrefab(Entity entity, EntityMapper entityMapper)
		{
			//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_0015: 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_001f: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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_0090: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: 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_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			EntityData result = default(EntityData);
			result.prefab = entity.Read<PrefabGUID>();
			if (entity.Has<Translation>())
			{
				result.pos = float3.op_Implicit(entity.Read<Translation>().Value);
			}
			if (entity.Has<Rotation>())
			{
				result.rot = quaternion.op_Implicit(entity.Read<Rotation>().Value);
			}
			if (entity.Has<TilePosition>())
			{
				result.tilePos = entity.Read<TilePosition>().Tile;
			}
			if (entity.Has<TileBounds>())
			{
				TileBounds val = entity.Read<TileBounds>();
				result.tileBoundsMin = val.Value.Min;
				result.tileBoundsMax = val.Value.Max;
			}
			if (entity.Has<TeamReference>())
			{
				ModifiableEntity value = entity.Read<TeamReference>().Value;
				if (((ModifiableEntity)(ref value)).Value != Entity.Null)
				{
					result.notCastleTeam = !((ModifiableEntity)(ref value)).Value.Has<CastleTeamData>();
				}
			}
			List<ComponentData> list = new List<ComponentData>();
			List<int> list2 = new List<int>();
			PrefabLookupMap prefabLookupMap = Core.PrefabCollection._PrefabLookupMap;
			Entity val2 = default(Entity);
			if (((PrefabLookupMap)(ref prefabLookupMap)).TryGetValue(result.prefab, ref val2))
			{
				EntityManager entityManager = Core.EntityManager;
				List<ComponentType> list3 = ((IEnumerable<ComponentType>)((EntityManager)(ref entityManager)).GetComponentTypes(entity, (Allocator)2).ToArray()).ToList();
				entityManager = Core.EntityManager;
				List<ComponentType> list4 = ((IEnumerable<ComponentType>)((EntityManager)(ref entityManager)).GetComponentTypes(val2, (Allocator)2).ToArray()).ToList();
				list3.Sort((ComponentType a, ComponentType b) => ((object)(ComponentType)(ref a)).ToString().CompareTo(((object)(ComponentType)(ref b)).ToString()));
				list4.Sort((ComponentType a, ComponentType b) => ((object)(ComponentType)(ref a)).ToString().CompareTo(((object)(ComponentType)(ref b)).ToString()));
				int num = 0;
				for (int i = 0; i < list3.Count; i++)
				{
					ComponentType val3 = list3[i];
					ComponentType val4 = list4[num];
					int num2 = ((object)(ComponentType)(ref val3)).ToString().CompareTo(((object)(ComponentType)(ref val4)).ToString());
					if (num2 == 0)
					{
						KindredSchematics.ComponentSaver.ComponentSaver componentSaver = KindredSchematics.ComponentSaver.ComponentSaver.GetComponentSaver(TypeIndex.op_Implicit(val3.TypeIndex));
						if (componentSaver != null)
						{
							object obj = componentSaver.DiffComponents(val2, entity, entityMapper);
							if (obj != null)
							{
								list.Add(new ComponentData
								{
									component = ((MemberInfo)((ComponentType)(ref val3)).GetManagedType()).Name,
									data = obj
								});
							}
						}
						num++;
					}
					else if (num2 < 0)
					{
						KindredSchematics.ComponentSaver.ComponentSaver componentSaver2 = KindredSchematics.ComponentSaver.ComponentSaver.GetComponentSaver(TypeIndex.op_Implicit(val3.TypeIndex));
						if (componentSaver2 != null)
						{
							object obj2 = componentSaver2.SaveComponent(entity, entityMapper);
							if (obj2 != null)
							{
								list.Add(new ComponentData
								{
									component = ((MemberInfo)((ComponentType)(ref val3)).GetManagedType()).Name,
									data = obj2
								});
							}
						}
					}
					else
					{
						if (val4 != new ComponentType(Il2CppType.Of<Prefab>(), (AccessMode)0) && val4 != new ComponentType(Il2CppType.Of<SpawnTag>(), (AccessMode)0))
						{
							list2.Add(TypeIndex.op_Implicit(val4.TypeIndex));
						}
						num++;
						i--;
					}
				}
				if (list.Count > 0)
				{
					result.componentData = list.ToArray();
				}
				if (list2.Count > 0)
				{
					result.removals = list2.ToArray();
				}
			}
			return result;
		}
	}
	internal static class Helper
	{
		public static AdminAuthSystem adminAuthSystem = Core.Server.GetExistingSystemManaged<AdminAuthSystem>();

		public static PrefabGUID GetPrefabGUID(Entity entity)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = Core.EntityManager;
			PrefabGUID componentData = default(PrefabGUID);
			try
			{
				componentData = ((EntityManager)(ref entityManager)).GetComponentData<PrefabGUID>(entity);
				return componentData;
			}
			catch
			{
				((PrefabGUID)(ref componentData))..ctor(0);
			}
			return componentData;
		}

		public static Entity AddItemToInventory(Entity recipient, PrefabGUID guid, int amount)
		{
			//IL_000b: 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_0019: 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_0022: 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_002e: 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_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_003b: 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_0047: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				GameDataSystem existingSystemManaged = Core.Server.GetExistingSystemManaged<GameDataSystem>();
				return InventoryUtilitiesServer.TryAddItem(AddItemSettings.Create(Core.EntityManager, existingSystemManaged.ItemHashLookupMap, false, default(Entity), default(Nullable_Unboxed<int>), false, false, false, default(Nullable_Unboxed<int>)), recipient, guid, amount).NewEntity;
			}
			catch (Exception e)
			{
				Core.LogException(e, "AddItemToInventory");
			}
			return default(Entity);
		}

		public static NativeArray<Entity> GetEntitiesByComponentType<T1>(bool includeAll = false, bool includeDisabled = false, bool includeSpawn = false, bool includePrefab = false, bool includeDestroyed = false)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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_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_001f: 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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_0044: 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_0059: 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_0066: 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_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_0027: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			EntityQueryOptions val = (EntityQueryOptions)0;
			if (includeAll)
			{
				val = (EntityQueryOptions)(val | 0xC3);
			}
			if (includeDisabled)
			{
				val = (EntityQueryOptions)(val | 2);
			}
			if (includeSpawn)
			{
				val = (EntityQueryOptions)(val | 0x40);
			}
			if (includePrefab)
			{
				val = (EntityQueryOptions)(val | 1);
			}
			if (includeDestroyed)
			{
				val = (EntityQueryOptions)(val | 0x80);
			}
			EntityQueryDesc val2 = new EntityQueryDesc();
			val2.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[1]
			{
				new ComponentType(Il2CppType.Of<T1>(), (AccessMode)0)
			});
			val2.Options = val;
			EntityQueryDesc val3 = val2;
			EntityManager entityManager = Core.EntityManager;
			EntityQuery val4 = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)new EntityQueryDesc[1] { val3 });
			return ((EntityQuery)(ref val4)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
		}

		public static NativeArray<Entity> GetEntitiesByComponentTypes<T1, T2>(bool includeAll = false, bool includeDisabled = false, bool includeSpawn = false, bool includePrefab = false, bool includeDestroyed = false)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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_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_001f: 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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_0044: 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_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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_0027: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			EntityQueryOptions val = (EntityQueryOptions)0;
			if (includeAll)
			{
				val = (EntityQueryOptions)(val | 0xC3);
			}
			if (includeDisabled)
			{
				val = (EntityQueryOptions)(val | 2);
			}
			if (includeSpawn)
			{
				val = (EntityQueryOptions)(val | 0x40);
			}
			if (includePrefab)
			{
				val = (EntityQueryOptions)(val | 1);
			}
			if (includeDestroyed)
			{
				val = (EntityQueryOptions)(val | 0x80);
			}
			EntityQueryDesc val2 = new EntityQueryDesc();
			val2.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[2]
			{
				new ComponentType(Il2CppType.Of<T1>(), (AccessMode)0),
				new ComponentType(Il2CppType.Of<T2>(), (AccessMode)0)
			});
			val2.Options = val;
			EntityQueryDesc val3 = val2;
			EntityManager entityManager = Core.EntityManager;
			EntityQuery val4 = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)new EntityQueryDesc[1] { val3 });
			return ((EntityQuery)(ref val4)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
		}

		public static int GetEntityTerritoryIndex(Entity entity)
		{
			//IL_0000: 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_0008: 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_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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: 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_008e: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: 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_007b: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			if (entity.Has<TilePosition>())
			{
				int2 tile = entity.Read<TilePosition>().Tile;
				int territoryIndexFromTileCoord = Core.CastleTerritory.GetTerritoryIndexFromTileCoord(tile);
				if (territoryIndexFromTileCoord != -1)
				{
					return territoryIndexFromTileCoord;
				}
			}
			if (entity.Has<TileBounds>())
			{
				BoundsMinMax value = entity.Read<TileBounds>().Value;
				for (int i = value.Min.x; i <= value.Max.x; i++)
				{
					for (int j = value.Min.y; j <= value.Max.y; j++)
					{
						int territoryIndexFromTileCoord2 = Core.CastleTerritory.GetTerritoryIndexFromTileCoord(new int2(i, j));
						if (territoryIndexFromTileCoord2 != -1)
						{
							return territoryIndexFromTileCoord2;
						}
					}
				}
			}
			if (entity.Has<Translation>())
			{
				float3 value2 = entity.Read<Translation>().Value;
				return Core.CastleTerritory.GetTerritoryIndex(value2);
			}
			if (entity.Has<LocalToWorld>())
			{
				LocalToWorld val = entity.Read<LocalToWorld>();
				float3 position = ((LocalToWorld)(ref val)).Position;
				return Core.CastleTerritory.GetTerritoryIndex(position);
			}
			return -1;
		}

		public static IEnumerable<Entity> GetAllEntitiesInTerritory<T>(int territoryIndex)
		{
			NativeArray<Entity> entities = GetEntitiesByComponentType<T>(includeAll: false, includeDisabled: true, includeSpawn: true);
			Enumerator<Entity> enumerator = entities.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				if (GetEntityTerritoryIndex(current) == territoryIndex)
				{
					yield return current;
				}
			}
			entities.Dispose();
		}

		public static IEnumerable<Entity> GetAllEntitiesInRadius<T>(float2 center, float radius)
		{
			//IL_0008: 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)
			NativeArray<Entity> entities = GetEntitiesByComponentType<T>(includeAll: false, includeDisabled: true, includeSpawn: true);
			Enumerator<Entity> enumerator = entities.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				if (current.Has<Translation>())
				{
					float3 value = current.Read<Translation>().Value;
					if (math.distance(center, ((float3)(ref value)).xz) <= radius)
					{
						yield return current;
					}
				}
			}
			entities.Dispose();
		}

		public static IEnumerable<Entity> GetAllEntitiesInBox<T>(float2 center, float2 halfSize)
		{
			//IL_0008: 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_000f: 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)
			NativeArray<Entity> entities = GetEntitiesByComponentType<T>(includeAll: false, includeDisabled: true, includeSpawn: true);
			Enumerator<Entity> enumerator = entities.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				if (current.Has<Translation>())
				{
					float3 value = current.Read<Translation>().Value;
					if (Mathf.Abs(center.x - value.x) <= halfSize.x && Mathf.Abs(center.y - value.z) <= halfSize.y)
					{
						yield return current;
					}
				}
			}
			entities.Dispose();
		}

		public static float3 ConvertPosToTileGrid(float3 pos)
		{
			//IL_0000: 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_001e: 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)
			return new float3((float)(Mathf.FloorToInt(pos.x * 2f) + 6400), pos.y, (float)(Mathf.FloorToInt(pos.z * 2f) + 6400));
		}

		public unsafe static bool GetAabb(Entity entity, out Aabb aabb)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_006f: 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_0031: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: 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_00c9: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: 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_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			aabb = default(Aabb);
			if (entity.Has<TileBounds>())
			{
				TileBounds val = entity.Read<TileBounds>();
				if (val.Value.Max.x == 0 && val.Value.Max.y == 0 && val.Value.Min.x == 0 && val.Value.Min.y == 0)
				{
					return false;
				}
				float num = 0f;
				float num2 = 0f;
				if (entity.Has<TileData>())
				{
					TileData val2 = entity.Read<TileData>();
					if (val2.Data.IsCreated)
					{
						? unsafePtr = *val2.Data.GetUnsafePtr();
						num = ((TileBlob)unsafePtr).MinHeight;
						num2 = ((TileBlob)unsafePtr).MaxHeight;
					}
				}
				if ((double)num2 <= 0.1)
				{
					num2 = 0.1f;
				}
				float3 value = entity.Read<Translation>().Value;
				aabb.Min = new float3((float)val.Value.Min.x, num + value.y, (float)val.Value.Min.y);
				aabb.Max = new float3((float)val.Value.Max.x, num2 + value.y, (float)val.Value.Max.y);
				return true;
			}
			return false;
		}

		public static bool IsEntityInAabb(Entity entity, Aabb aabb)
		{
			//IL_0000: 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_0010: 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_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_0025: 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)
			if (!entity.Has<Translation>())
			{
				return false;
			}
			float3 value = entity.Read<Translation>().Value;
			if (!((Aabb)(ref aabb)).Contains(ConvertPosToTileGrid(value)))
			{
				if (GetAabb(entity, out var aabb2))
				{
					return ((Aabb)(ref aabb)).Overlaps(aabb2);
				}
				return false;
			}
			return true;
		}

		public static IEnumerable<Entity> GetAllEntitiesInTileAabb<T>(Aabb aabb)
		{
			//IL_0008: 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)
			NativeArray<Entity> entities = GetEntitiesByComponentType<T>(includeAll: false, includeDisabled: true, includeSpawn: true);
			Enumerator<Entity> enumerator = entities.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				if (IsEntityInAabb(current, aabb))
				{
					yield return current;
				}
			}
			entities.Dispose();
		}

		public static void DestroyEntitiesForBuilding(IEnumerable<Entity> entities)
		{
			//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_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			foreach (Entity entity in entities)
			{
				if (!entity.Has<CastleHeart>())
				{
					string text = GetPrefabGUID(entity).LookupName();
					if (text.StartsWith("TM_") || text.StartsWith("Chain_") || entity.Has<CastleBuildingFusedRoot>())
					{
						DestroyEntityAndCastleAttachments(entity);
					}
				}
			}
		}

		public static void DestroyEntityAndCastleAttachments(Entity entity, HashSet<Entity> alreadyVisited = null)
		{
			//IL_000b: 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_001c: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: 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_007c: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_009e: 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_00a6: 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_00ac: 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_00b5: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: 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_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Invalid comparison between Unknown and I4
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			if (alreadyVisited == null)
			{
				alreadyVisited = new HashSet<Entity>();
			}
			if (alreadyVisited.Contains(entity))
			{
				return;
			}
			alreadyVisited.Add(entity);
			EntityManager entityManager = Core.EntityManager;
			NetworkedEntity val;
			if (((EntityManager)(ref entityManager)).HasBuffer<CastleBuildingAttachToParentsBuffer>(entity))
			{
				entityManager = Core.EntityManager;
				Enumerator<CastleBuildingAttachToParentsBuffer> enumerator = ((EntityManager)(ref entityManager)).GetBufferReadOnly<CastleBuildingAttachToParentsBuffer>(entity).GetEnumerator();
				while (enumerator.MoveNext())
				{
					CastleBuildingAttachToParentsBuffer current = enumerator.Current;
					val = current.ParentEntity;
					DestroyEntityAndCastleAttachments(((NetworkedEntity)(ref val)).GetEntityOnServer(), alreadyVisited);
				}
			}
			if (entity.Has<PrefabGUID>() && entity.Read<PrefabGUID>() == Prefabs.TM_Castle_Wall_Tier02_Stone_Window)
			{
				entityManager = Core.EntityManager;
				if (((EntityManager)(ref entityManager)).HasBuffer<CastleBuildingAttachedChildrenBuffer>(entity))
				{
					entityManager = Core.EntityManager;
					Enumerator<CastleBuildingAttachedChildrenBuffer> enumerator2 = ((EntityManager)(ref entityManager)).GetBufferReadOnly<CastleBuildingAttachedChildrenBuffer>(entity).GetEnumerator();
					while (enumerator2.MoveNext())
					{
						CastleBuildingAttachedChildrenBuffer current2 = enumerator2.Current;
						val = current2.ChildEntity;
						Entity entityOnServer = ((NetworkedEntity)(ref val)).GetEntityOnServer();
						if (entityOnServer.Has<EntityCategory>())
						{
							EntityCategory val2 = entityOnServer.Read<EntityCategory>();
							if ((int)((EntityCategory)(ref val2)).MainCategory == 2 && (int)((EntityCategory)(ref val2)).UnitCategory == 0 && (int)((EntityCategory)(ref val2)).StructureCategory == 0 && (int)((EntityCategory)(ref val2)).MaterialCategory == 0 && ModifiableInt.op_Implicit(val2.ResourceLevel) == 0)
							{
								DestroyEntityAndCastleAttachments(entityOnServer, alreadyVisited);
							}
						}
					}
				}
			}
			DestroyUtility.Destroy(Core.EntityManager, entity, (DestroyDebugReason)0, (string)null, 0);
		}

		public static Entity FindClosest<T>(Vector3 pos, string startsWith = null, float maxDistance = -1f)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0036: 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_007c: 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)
			Entity result = Entity.Null;
			float num = float.MaxValue;
			NativeArray<Entity> entitiesByComponentType = GetEntitiesByComponentType<T>(includeAll: false, includeDisabled: true, includeSpawn: true);
			Enumerator<Entity> enumerator = entitiesByComponentType.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				if (current.Has<Translation>() && (startsWith == null || GetPrefabGUID(current).LookupName().StartsWith(startsWith)))
				{
					float3 value = current.Read<Translation>().Value;
					float num2 = Vector3.Distance(pos, float3.op_Implicit(value));
					if (num2 < num && (maxDistance < 0f || num2 < maxDistance))
					{
						num = num2;
						result = current;
					}
				}
			}
			entitiesByComponentType.Dispose();
			return result;
		}
	}
	[BepInPlugin("KindredSchematics", "KindredSchematics", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		private static Harmony _harmony;

		internal static ManualLogSource PluginLog;

		public static Harmony Harmony => _harmony;

		public override void Load()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			PluginLog = ((BasePlugin)this).Log;
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(27, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("KindredSchematics");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" version ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.1.0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
			}
			log.LogInfo(val);
			_harmony = new Harmony("KindredSchematics");
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			CommandRegistry.RegisterAll();
		}

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

		public const string PLUGIN_NAME = "KindredSchematics";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}
namespace KindredSchematics.Services
{
	internal class CastleTerritoryService
	{
		private const float BLOCK_SIZE = 10f;

		private Dictionary<int2, int> blockCoordToTerritoryIndex = new Dictionary<int2, int>();

		public CastleTerritoryService()
		{
			//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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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_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_0043: 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_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)
			NativeArray<Entity> entitiesByComponentType = Helper.GetEntitiesByComponentType<CastleTerritory>(includeAll: true);
			Enumerator<Entity> enumerator = entitiesByComponentType.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				int castleTerritoryIndex = current.Read<CastleTerritory>().CastleTerritoryIndex;
				EntityManager entityManager = Core.EntityManager;
				DynamicBuffer<CastleTerritoryBlocks> buffer = ((EntityManager)(ref entityManager)).GetBuffer<CastleTerritoryBlocks>(current, false);
				for (int i = 0; i < buffer.Length; i++)
				{
					blockCoordToTerritoryIndex[buffer[i].BlockCoordinate] = castleTerritoryIndex;
				}
			}
			entitiesByComponentType.Dispose();
		}

		public int GetTerritoryIndexFromTileCoord(int2 tilePos)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			int2 key = ConvertTileGridToBlockCoord(tilePos);
			if (blockCoordToTerritoryIndex.TryGetValue(key, out var value))
			{
				return value;
			}
			return -1;
		}

		public int GetTerritoryIndex(float3 pos)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			int2 key = ConvertPosToBlockCoord(pos);
			if (blockCoordToTerritoryIndex.TryGetValue(key, out var value))
			{
				return value;
			}
			return -1;
		}

		public Entity GetHeartForTerritory(int territoryIndex)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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)
			if (territoryIndex == -1)
			{
				return Entity.Null;
			}
			NativeArray<Entity> entitiesByComponentType = Helper.GetEntitiesByComponentType<CastleHeart>();
			Enumerator<Entity> enumerator = entitiesByComponentType.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				Entity castleTerritoryEntity = current.Read<CastleHeart>().CastleTerritoryEntity;
				if (!((Entity)(ref castleTerritoryEntity)).Equals(Entity.Null) && castleTerritoryEntity.Read<CastleTerritory>().CastleTerritoryIndex == territoryIndex)
				{
					return current;
				}
			}
			entitiesByComponentType.Dispose();
			return Entity.Null;
		}

		private int2 ConvertPosToBlockCoord(float3 pos)
		{
			//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_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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)
			float3 val = Helper.ConvertPosToTileGrid(pos);
			return new int2((int)math.floor(val.x / 10f), (int)math.floor(val.z / 10f));
		}

		private int2 ConvertTileGridToBlockCoord(int2 tileCoord)
		{
			//IL_0000: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			return new int2((int)math.floor((float)tileCoord.x / 10f), (int)math.floor((float)tileCoord.y / 10f));
		}
	}
	internal class ConfigSettingsService
	{
		private struct Config
		{
			public bool FreeBuildDisabled { get; set; }
		}

		private static readonly string CONFIG_PATH = Path.Combine(Paths.ConfigPath, "KindredSchematics");

		private static readonly string SETTINGS_PATH = Path.Combine(CONFIG_PATH, "settings.json");

		private Config config;

		public bool FreeBuildDisabled
		{
			get
			{
				return config.FreeBuildDisabled;
			}
			set
			{
				config.FreeBuildDisabled = value;
				SaveConfig();
			}
		}

		public ConfigSettingsService()
		{
			LoadConfig();
		}

		private void LoadConfig()
		{
			if (!File.Exists(SETTINGS_PATH))
			{
				config = default(Config);
				SaveConfig();
			}
			else
			{
				string json = File.ReadAllText(SETTINGS_PATH);
				config = JsonSerializer.Deserialize<Config>(json);
			}
		}

		private void SaveConfig()
		{
			if (!Directory.Exists(CONFIG_PATH))
			{
				Directory.CreateDirectory(CONFIG_PATH);
			}
			string contents = JsonSerializer.Serialize(config, new JsonSerializerOptions
			{
				WriteIndented = true,
				IncludeFields = true
			});
			File.WriteAllText(SETTINGS_PATH, contents);
		}
	}
	internal class RespawnPreventionService
	{
		private int preventRespawnsCount;

		private Coroutine respawnPreventionCoroutine;

		private bool preventRespawns => preventRespawnsCount > 0;

		public void PreventRespawns()
		{
			preventRespawnsCount++;
			if (respawnPreventionCoroutine == null)
			{
				respawnPreventionCoroutine = Core.StartCoroutine(KeepFromRespawning());
			}
		}

		public void AllowRespawns()
		{
			preventRespawnsCount--;
			if (preventRespawnsCount < 0)
			{
				preventRespawnsCount = 0;
			}
		}

		private IEnumerator KeepFromRespawning()
		{
			EntityQueryDesc val = new EntityQueryDesc();
			val.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[1]
			{
				new ComponentType(Il2CppType.Of<AutoChainInstanceData>(), (AccessMode)0)
			});
			EntityQueryDesc val2 = val;
			EntityManager entityManager = Core.EntityManager;
			EntityQuery autoChainQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)new EntityQueryDesc[1] { val2 });
			val = new EntityQueryDesc();
			val.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[1]
			{
				new ComponentType(Il2CppType.Of<SpawnRegion>(), (AccessMode)0)
			});
			EntityQueryDesc val3 = val;
			entityManager = Core.EntityManager;
			EntityQuery spawnRegionQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)new EntityQueryDesc[1] { val3 });
			while (preventRespawns)
			{
				double serverTime = Core.ServerTime;
				NativeArray<Entity> val4 = ((EntityQuery)(ref autoChainQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
				Enumerator<Entity> enumerator = val4.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					if (current.Read<AutoChainInstanceData>().NextTransitionAttempt < serverTime + 5.0)
					{
						current.Write<AutoChainInstanceData>(new AutoChainInstanceData
						{
							NextTransitionAttempt = Core.ServerTime + 10.0
						});
					}
				}
				val4.Dispose();
				enumerator = ((EntityQuery)(ref spawnRegionQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2)).GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current2 = enumerator.Current;
					if (current2.Read<SpawnRegion>().LastRespawnAttempt < serverTime + 5.0)
					{
						current2.Write<SpawnRegion>(new SpawnRegion
						{
							LastRespawnAttempt = Core.ServerTime + 10.0
						});
					}
					entityManager = Core.EntityManager;
					if (!((EntityManager)(ref entityManager)).HasBuffer<SpawnRegionSpawnSlotEntry>(current2))
					{
						continue;
					}
					entityManager = Core.EntityManager;
					DynamicBuffer<SpawnRegionSpawnSlotEntry> buffer = ((EntityManager)(ref entityManager)).GetBuffer<SpawnRegionSpawnSlotEntry>(current2, false);
					for (int i = 0; i < buffer.Length; i++)
					{
						SpawnRegionSpawnSlotEntry val5 = buffer[i];
						if (val5.BlockRespawnUntil < serverTime + 5.0)
						{
							val5.BlockRespawnUntil = serverTime + 10.0;
							buffer[i] = val5;
						}
					}
				}
				yield return null;
			}
			respawnPreventionCoroutine = null;
		}
	}
	internal class SchematicService
	{
		private struct Schematic
		{
			public string version { get; set; }

			public Vector3? location { get; set; }

			public int? territoryIndex { get; set; }

			public Aabb boundingBox { get; set; }

			public Aabb[] aabbs { get; set; }

			public EntityData[] entities { get; set; }
		}

		private struct HeartInfo
		{
			public Entity CastleHeart;

			public Entity TeamReference;

			public int TeamValue;
		}

		private static readonly string CONFIG_PATH = Path.Combine(Paths.ConfigPath, "KindredSchematics");

		private readonly List<Entity> usersClearingEntireArea = new List<Entity>();

		private readonly List<Entity> usersPlacingOffGrid = new List<Entity>();

		private GameObject schematicSvcGameObject;

		private IgnorePhysicsDebugSystem schematicMonoBehaviour;

		private HashSet<PrefabGUID> prefabsAllowedToDestroy = new HashSet<PrefabGUID>();

		public Entity CurUserEntity { get; private set; }

		public Entity CurCharEntity { get; private set; }

		public SchematicService()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0069: 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_00af: 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_0096: 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)
			schematicSvcGameObject = new GameObject("SchematicService");
			schematicMonoBehaviour = schematicSvcGameObject.AddComponent<IgnorePhysicsDebugSystem>();
			Enumerator<PrefabGUID, string> enumerator = Core.PrefabCollection._PrefabGuidToNameDictionary.GetEnumerator();
			PrefabGUID val = default(PrefabGUID);
			string text = default(string);
			Entity entity = default(Entity);
			while (enumerator.MoveNext())
			{
				enumerator.Current.Deconstruct(ref val, ref text);
				PrefabGUID val2 = val;
				string text2 = text;
				if (text2.StartsWith("TM_") || text2.StartsWith("Chain_") || (Core.PrefabCollection._PrefabGuidToEntityMap.TryGetValue(val2, ref entity) && entity.Has<CastleBuildingFusedRoot>()))
				{
					prefabsAllowedToDestroy.Add(val2);
				}
			}
		}

		public void StartCoroutine(IEnumerator routine)
		{
			((MonoBehaviour)schematicMonoBehaviour).StartCoroutine(CollectionExtensions.WrapToIl2Cpp(routine));
		}

		public IEnumerable<string> GetSchematics()
		{
			if (!Directory.Exists(CONFIG_PATH))
			{
				yield break;
			}
			foreach (string item in Directory.EnumerateFiles(CONFIG_PATH, "*.schematic"))
			{
				yield return Path.GetFileNameWithoutExtension(item);
			}
		}

		public static JsonSerializerOptions GetJsonOptions()
		{
			return new JsonSerializerOptions
			{
				WriteIndented = true,
				DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault,
				Converters = 
				{
					(JsonConverter)new AabbConverter(),
					(JsonConverter)new AssetGUIDConverter(),
					(JsonConverter)new CurveReferenceConverter(),
					(JsonConverter)new int2Converter(),
					(JsonConverter)new PrefabGUIDConverter(),
					(JsonConverter)new QuaternionConverter(),
					(JsonConverter)new Vector2Converter(),
					(JsonConverter)new Vector3Converter()
				}
			};
		}

		public void SaveSchematic(string name, float3? location = null, float? radius = null, Vector2? halfSize = null, int? territoryIndex = null)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Expected O, but got Unknown
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Expected O, but got Unknown
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Expected O, but got Unknown
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_046d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0474: Expected O, but got Unknown
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ba: Expected O, but got Unknown
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_054d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0554: Expected O, but got Unknown
			//IL_0317: 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_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05bb: Expected O, but got Unknown
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: 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_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0364: Unknown result type (might be due to invalid IL or missing references)
			//IL_0631: Unknown result type (might be due to invalid IL or missing references)
			//IL_0638: Expected O, but got Unknown
			//IL_039b: Unknown result type (might be due to invalid IL or missing references)
			//IL_039d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0389: Unknown result type (might be due to invalid IL or missing references)
			//IL_038b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03de: Unknown result type (might be due to invalid IL or missing references)
			//IL_040b: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0412: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0400: Unknown result type (might be due to invalid IL or missing references)
			//IL_042d: Unknown result type (might be due to invalid IL or missing references)
			//IL_042f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0434: Unknown result type (might be due to invalid IL or missing references)
			//IL_0420: Unknown result type (might be due to invalid IL or missing references)
			//IL_0422: Unknown result type (might be due to invalid IL or missing references)
			//IL_0442: Unknown result type (might be due to invalid IL or missing references)
			//IL_0444: Unknown result type (might be due to invalid IL or missing references)
			float startTime = Time.realtimeSinceStartup;
			ManualLogSource log = Core.Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(18, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(GetElapseTime());
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" Starting to save ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(name);
			}
			log.LogInfo(val);
			Schematic schematic = default(Schematic);
			schematic.version = "1.0";
			schematic.entities = Array.Empty<EntityData>();
			Schematic value = schematic;
			if (territoryIndex.HasValue)
			{
				value.territoryIndex = territoryIndex;
			}
			else
			{
				float3 val2 = Helper.ConvertPosToTileGrid(location.Value);
				value.boundingBox = new Aabb
				{
					Min = val2,
					Max = val2
				};
				float3? val3 = location;
				value.location = (val3.HasValue ? new Vector3?(float3.op_Implicit(val3.GetValueOrDefault())) : null);
			}
			float3 value2;
			IEnumerable<Entity> source;
			if (radius.HasValue)
			{
				value2 = location.Value;
				source = Helper.GetAllEntitiesInRadius<Translation>(((float3)(ref value2)).xz, radius.Value);
			}
			else if (halfSize.HasValue)
			{
				value2 = location.Value;
				source = Helper.GetAllEntitiesInBox<Translation>(((float3)(ref value2)).xz, float2.op_Implicit(halfSize.Value));
			}
			else
			{
				if (!territoryIndex.HasValue)
				{
					ManualLogSource log2 = Core.Log;
					BepInExErrorLogInterpolatedStringHandler val4 = new BepInExErrorLogInterpolatedStringHandler(54, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("Schematic ");
						((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(name);
						((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" has no radius, halfSize, or territory index");
					}
					log2.LogError(val4);
					return;
				}
				source = Helper.GetAllEntitiesInTerritory<Translation>(territoryIndex.Value);
			}
			ManualLogSource log3 = Core.Log;
			val = new BepInExInfoLogInterpolatedStringHandler(23, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(GetElapseTime());
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" Gathered entities for ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(name);
			}
			log3.LogInfo(val);
			List<EntityData> list = new List<EntityData>();
			List<Aabb> list2 = new List<Aabb>();
			EntityMapper entityMapper = new EntityMapper(source.Where(delegate(Entity entity)
			{
				//IL_0000: 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