Decompiled source of KindredSchematics v1.2.2

KindredSchematics.dll

Decompiled 2 months 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 System.Text.RegularExpressions;
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;
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.2.2")]
[assembly: AssemblyInformationalVersion("0.1.2+2.Branch.main.Sha.62bb8fcf39ee2ebe62410e48ec8f8fdc72e85b10.a9046f96d8204bc6f9162e0318d0ef1bcb59d460")]
[assembly: AssemblyProduct("KindredSchematics")]
[assembly: AssemblyTitle("KindredSchematics")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.2.2")]
[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 delegate void BuffCreated(Entity buffEntity);

		public static bool AddBuff(Entity User, Entity Character, PrefabGUID buffPrefab, float duration = 0f, 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_0115: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: 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)
			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 > -1f && duration != 0f)
					{
						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 == -1f)
					{
						if (entity.Has<LifeTime>())
						{
							LifeTime componentData2 = entity.Read<LifeTime>();
							componentData2.Duration = 0f;
							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);
			}
		}

		public static void RemoveAndAddBuff(Entity userEntity, Entity targetEntity, PrefabGUID buffPrefab, float duration = -1f, BuffCreated callback = null)
		{
			//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_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_0047: 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_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_003e: Unknown result type (might be due to invalid IL or missing references)
			if (!BuffUtility.HasBuff(Core.EntityManager, targetEntity, PrefabIdentifier.op_Implicit(buffPrefab)))
			{
				AddBuff(userEntity, targetEntity, buffPrefab, duration, immortal: true);
				Entity buffEntity = default(Entity);
				if (callback != null && BuffUtility.TryGetBuff(Core.Server.EntityManager, targetEntity, PrefabIdentifier.op_Implicit(buffPrefab), ref buffEntity))
				{
					callback(buffEntity);
				}
			}
			else
			{
				Core.StartCoroutine(RemoveAndAddBuffCoroutine(userEntity, targetEntity, buffPrefab, duration, callback));
			}
		}

		private static IEnumerator RemoveAndAddBuffCoroutine(Entity userEntity, Entity targetEntity, PrefabGUID buffPrefab, float duration, BuffCreated callback)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			RemoveBuff(targetEntity, buffPrefab);
			while (BuffUtility.HasBuff(Core.EntityManager, targetEntity, PrefabIdentifier.op_Implicit(buffPrefab)))
			{
				yield return null;
			}
			AddBuff(userEntity, targetEntity, buffPrefab, duration, immortal: true);
			Entity buffEntity = default(Entity);
			if (callback != null && BuffUtility.TryGetBuff(Core.Server.EntityManager, targetEntity, PrefabIdentifier.op_Implicit(buffPrefab), ref buffEntity))
			{
				callback(buffEntity);
			}
		}
	}
	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 GlowService GlowService { get; } = new GlowService();


		public static RespawnPreventionService RespawnPrevention { get; private set; }

		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_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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Invalid comparison between Unknown and I4
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			//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)
			if (_hasInitialized)
			{
				return;
			}
			_hasInitialized = true;
			KindredSchematics.ComponentSaver.ComponentSaver.PopulateComponentSavers();
			CastleTerritory = new CastleTerritoryService();
			RespawnPrevention = new RespawnPreventionService();
			FoundBuffConverter.InitializeBuffPrefabs();
			Tile.Populate();
			NativeArray<Entity> entitiesByComponentTypes = Helper.GetEntitiesByComponentTypes<Immortal, EntityCategory>(includeAll: false, includeDisabled: true);
			Enumerator<Entity> enumerator = entitiesByComponentTypes.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				EntityCategory componentData = current.Read<EntityCategory>();
				if ((int)((EntityCategory)(ref componentData)).MaterialCategory == 3)
				{
					((EntityCategory)(ref componentData)).MaterialCategory = (MaterialCategory)2;
					current.Write<EntityCategory>(componentData);
				}
			}
			entitiesByComponentTypes.Dispose();
			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 bool Contains(Entity entity)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return entityIndexLookup.ContainsKey(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>();

		private static EntityQuery tilePositionQuery = default(EntityQuery);

		private static readonly PrefabGUID openContainerAbility = new PrefabGUID(-1662046920);

		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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			foreach (Entity entity in entities)
			{
				if (!entity.Has<CastleHeart>())
				{
					string text = GetPrefabGUID(entity).LookupName();
					if (text.StartsWith("TM_") || text.StartsWith("Chain_") || text.StartsWith("BP_") || 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_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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0032: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			Entity result = Entity.Null;
			float num = float.MaxValue;
			maxDistance *= maxDistance;
			NativeArray<Entity> entitiesByComponentTypes = GetEntitiesByComponentTypes<T, Translation>(includeAll: false, includeDisabled: true, includeSpawn: true);
			Enumerator<Entity> enumerator = entitiesByComponentTypes.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				if (startsWith == null || GetPrefabGUID(current).LookupName().StartsWith(startsWith))
				{
					float3 value = current.Read<Translation>().Value;
					float num2 = math.distancesq(float3.op_Implicit(pos), value);
					if (num2 < num && (maxDistance < 0f || num2 < maxDistance))
					{
						num = num2;
						result = current;
					}
				}
			}
			entitiesByComponentTypes.Dispose();
			return result;
		}

		public static Entity FindClosestTilePosition(Vector3 pos)
		{
			//IL_0000: 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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			if (tilePositionQuery == default(EntityQuery))
			{
				EntityManager entityManager = Core.EntityManager;
				EntityQueryDesc[] array = new EntityQueryDesc[1];
				EntityQueryDesc val = new EntityQueryDesc();
				val.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[2]
				{
					new ComponentType(Il2CppType.Of<TilePosition>(), (AccessMode)1),
					new ComponentType(Il2CppType.Of<Translation>(), (AccessMode)1)
				});
				val.Options = (EntityQueryOptions)66;
				array[0] = val;
				tilePositionQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)array);
			}
			Entity result = Entity.Null;
			float num = float.MaxValue;
			NativeArray<Entity> val2 = ((EntityQuery)(ref tilePositionQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			for (int i = 0; i < val2.Length; i++)
			{
				Entity val3 = val2[i];
				if (val3.Has<TilePosition>())
				{
					float3 value = val3.Read<Translation>().Value;
					float num2 = math.distancesq(float3.op_Implicit(pos), value);
					if (num2 < num && GetPrefabGUID(val3).LookupName().StartsWith("TM_"))
					{
						num = num2;
						result = val3;
					}
				}
			}
			val2.Dispose();
			return result;
		}

		public static bool EntityIsChest(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_000f: 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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			if (!entity.Has<InteractAbilityBuffer>())
			{
				return false;
			}
			EntityManager entityManager = Core.EntityManager;
			Enumerator<InteractAbilityBuffer> enumerator = ((EntityManager)(ref entityManager)).GetBufferReadOnly<InteractAbilityBuffer>(entity).GetEnumerator();
			while (enumerator.MoveNext())
			{
				if (enumerator.Current.Ability == openContainerAbility)
				{
					return true;
				}
			}
			return false;
		}
	}
	[BepInPlugin("KindredSchematics", "KindredSchematics", "1.2.2")]
	[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.2.2");
				((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.2.2";
	}
}
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 GlowService
	{
		private static readonly string CONFIG_PATH = Path.Combine(Paths.ConfigPath, "KindredSchematics");

		private static readonly string GLOW_CHOICES_PATH = Path.Combine(CONFIG_PATH, "glowChoices.txt");

		public readonly Dictionary<string, PrefabGUID> glowChoices = new Dictionary<string, PrefabGUID>(StringComparer.InvariantCultureIgnoreCase)
		{
			{
				"InkShadow",
				new PrefabGUID(-1124645803)
			},
			{
				"Cursed",
				new PrefabGUID(1425734039)
			},
			{
				"Howl",
				new PrefabGUID(-91451769)
			},
			{
				"Chaos",
				new PrefabGUID(1163490655)
			},
			{
				"Emerald",
				new PrefabGUID(-1559874083)
			},
			{
				"Poison",
				new PrefabGUID(-1965215729)
			},
			{
				"Agony",
				new PrefabGUID(1025643444)
			},
			{
				"Light",
				new PrefabGUID(178225731)
			}
		};

		private readonly Dictionary<PrefabGUID, string> prefabToGlowName = new Dictionary<PrefabGUID, string>();

		public GlowService()
		{
			//IL_0016: 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_0040: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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)
			LoadGlowChoices();
		}

		private void SaveGlowChoices()
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			if (!Directory.Exists(CONFIG_PATH))
			{
				Directory.CreateDirectory(CONFIG_PATH);
			}
			StringBuilder stringBuilder = new StringBuilder();
			foreach (KeyValuePair<string, PrefabGUID> glowChoice in glowChoices)
			{
				StringBuilder stringBuilder2 = stringBuilder;
				StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(1, 2, stringBuilder2);
				handler.AppendFormatted(glowChoice.Key);
				handler.AppendLiteral("=");
				PrefabGUID value = glowChoice.Value;
				handler.AppendFormatted(((PrefabGUID)(ref value)).GuidHash);
				stringBuilder2.AppendLine(ref handler);
			}
			File.WriteAllText(GLOW_CHOICES_PATH, stringBuilder.ToString());
		}

		private void LoadGlowChoices()
		{
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Expected O, but got Unknown
			//IL_0071: 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: Expected O, but got Unknown
			//IL_0084: 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)
			if (File.Exists(GLOW_CHOICES_PATH))
			{
				glowChoices.Clear();
				string[] array = File.ReadAllLines(GLOW_CHOICES_PATH);
				PrefabGUID val = default(PrefabGUID);
				Entity entity = default(Entity);
				bool flag = default(bool);
				for (int i = 0; i < array.Length; i++)
				{
					string[] array2 = array[i].Split('=');
					if (array2.Length != 2 || !int.TryParse(array2[1], out var result))
					{
						continue;
					}
					((PrefabGUID)(ref val))..ctor(result);
					if (Core.PrefabCollection._PrefabGuidToEntityMap.TryGetValue(val, ref entity))
					{
						if (entity.Has<Buff>())
						{
							glowChoices[array2[0]] = new PrefabGUID(result);
							continue;
						}
						ManualLogSource log = Core.Log;
						BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(34, 2, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Glow choice ");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(array2[0]);
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" of type ");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(val.LookupName());
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" missing buff");
						}
						log.LogWarning(val2);
					}
					else
					{
						ManualLogSource log2 = Core.Log;
						BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(33, 2, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Glow choice ");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(array2[0]);
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" with guid ");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(result);
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" not found");
						}
						log2.LogWarning(val2);
					}
				}
			}
			prefabToGlowName.Clear();
			foreach (KeyValuePair<string, PrefabGUID> glowChoice in glowChoices)
			{
				prefabToGlowName[glowChoice.Value] = glowChoice.Key;
			}
		}

		public void AddNewGlowChoice(PrefabGUID prefab, string name)
		{
			//IL_0007: 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)
			glowChoices[name] = prefab;
			prefabToGlowName[prefab] = name;
			SaveGlowChoices();
		}

		public bool RemoveGlowChoice(string name)
		{
			if (glowChoices.Remove(name))
			{
				SaveGlowChoices();
				return true;
			}
			return false;
		}

		public PrefabGUID GetGlowEntry(string name)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			if (glowChoices.TryGetValue(name, out var value))
			{
				return value;
			}
			return default(PrefabGUID);
		}

		public IEnumerable<(string, PrefabGUID)> ListGlowChoices()
		{
			foreach (KeyValuePair<string, PrefabGUID> glowChoice in glowChoices)
			{
				yield return (glowChoice.Key, glowChoice.Value);
			}
		}

		public string GetGlowName(PrefabGUID guid)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return glowChoices.FirstOrDefault((KeyValuePair<string, PrefabGUID> x) => x.Value == guid).Key;
		}

		public void AddGlow(Entity userEntity, Entity targetEntity, PrefabGUID glowPrefab)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			Buffs.RemoveAndAddBuff(userEntity, targetEntity, glowPrefab, -1f, delegate(Entity glowBuffEntity)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Unknown r