Decompiled source of Faust v0.16.5

BepInEx/plugins/Faust.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using Faust.Config;
using Faust.Services;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.CastleBuilding;
using ProjectM.Gameplay.Systems;
using ProjectM.Network;
using ProjectM.Physics;
using ProjectM.Scripting;
using ProjectM.Terrain;
using Stunlock.Core;
using Stunlock.Network;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Physics;
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("kdpen")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © 2026 Kristopher Penland")]
[assembly: AssemblyDescription("Faust, Lord of Investigation — a server-side information layer for V Rising: the authoritative, global view of players, castles, plots, server entities (V Bloods, NPCs, resource nodes), and server activity. An admin moderation/oversight console you can also share as PvP intel or PvE community features, gated per-feature with an optional item cost (the Faustian toll), cooldown, usage limit, or unlock. Built to run with its companion client Raphael, Lord of Wisdom. Pre-1.0 testing. Server-side only.")]
[assembly: AssemblyFileVersion("0.16.5.0")]
[assembly: AssemblyInformationalVersion("0.16.5+be491f2809922d6fe4ce5b3d97a549515a9aab43")]
[assembly: AssemblyProduct("Faust")]
[assembly: AssemblyTitle("Faust")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.16.5.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class IsUnmanagedAttribute : Attribute
	{
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Faust
{
	internal static class Core
	{
		private static bool _initInProgress;

		private static int _initAttempts;

		private static MonoBehaviour _monoBehaviour;

		public static World Server { get; private set; }

		public static EntityManager EntityManager { get; private set; }

		public static PrefabCollectionSystem PrefabCollectionSystem { get; private set; }

		public static ServerScriptMapper ServerScriptMapper { get; private set; }

		public static ServerGameSettingsSystem ServerGameSettingsSystem { get; private set; }

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

		public static double ServerTime => ServerGameManager.ServerTime;

		public static CastleService Castle { get; private set; }

		public static PlayerInfoService PlayerInfo { get; private set; }

		public static ClanService Clan { get; private set; }

		public static BossService Boss { get; private set; }

		public static WorldScanService WorldScan { get; private set; }

		public static MapMarkerService MapMarkers { get; private set; }

		public static FaustStore Store { get; private set; }

		public static HeatmapStore Heatmap { get; private set; }

		public static UsageService Usage { get; private set; }

		public static UsageStatsService UsageStats { get; private set; }

		public static FeatureControlService Control { get; private set; }

		public static UnlockService Unlock { get; private set; }

		public static KillTrackingService Kills { get; private set; }

		public static ManualLogSource Log => Plugin.PluginLog;

		public static bool IsReady { get; private set; }

		private static MonoBehaviour MonoBehaviour
		{
			get
			{
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)_monoBehaviour == (Object)null)
				{
					_monoBehaviour = (MonoBehaviour)(object)new GameObject("Faust").AddComponent<IgnorePhysicsDebugSystem>();
					Object.DontDestroyOnLoad((Object)(object)((Component)_monoBehaviour).gameObject);
				}
				return _monoBehaviour;
			}
		}

		internal static void InitPersistence()
		{
			Store = new FaustStore();
			Store.Load();
			Heatmap = new HeatmapStore();
			Heatmap.Load();
			Usage = new UsageService();
			Usage.Load();
			UsageStats = new UsageStatsService();
			UsageStats.Load();
			Control = new FeatureControlService();
			Control.Load();
			Unlock = new UnlockService();
			Unlock.Load();
			Kills = new KillTrackingService();
			Kills.Load();
		}

		internal static void TryInitialize(string trigger)
		{
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			//IL_00ce: 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_0150: Expected O, but got Unknown
			if (IsReady || _initInProgress)
			{
				return;
			}
			_initInProgress = true;
			_initAttempts++;
			bool flag = default(bool);
			try
			{
				World val = FindServerWorld();
				BepInExInfoLogInterpolatedStringHandler val2;
				if (val == null)
				{
					if (_initAttempts == 1)
					{
						ManualLogSource log = Log;
						val2 = new BepInExInfoLogInterpolatedStringHandler(56, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Faust init (");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(trigger);
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("): Server world not yet present; will retry.");
						}
						log.LogInfo(val2);
					}
					return;
				}
				PrefabCollectionSystem existingSystemManaged = val.GetExistingSystemManaged<PrefabCollectionSystem>();
				if (existingSystemManaged == null || existingSystemManaged.SpawnableNameToPrefabGuidDictionary.Count == 0)
				{
					if (_initAttempts == 1)
					{
						ManualLogSource log2 = Log;
						val2 = new BepInExInfoLogInterpolatedStringHandler(68, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Faust init (");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(trigger);
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("): PrefabCollectionSystem not yet populated; will retry.");
						}
						log2.LogInfo(val2);
					}
					return;
				}
				Server = val;
				EntityManager = val.EntityManager;
				PrefabCollectionSystem = existingSystemManaged;
				ServerScriptMapper = val.GetExistingSystemManaged<ServerScriptMapper>();
				ServerGameSettingsSystem = val.GetExistingSystemManaged<ServerGameSettingsSystem>();
				Castle = new CastleService();
				PlayerInfo = new PlayerInfoService();
				Clan = new ClanService();
				Boss = new BossService();
				WorldScan = new WorldScanService();
				WorldScan.Load();
				MapMarkers = new MapMarkerService();
				IsReady = true;
				ManualLogSource log3 = Log;
				val2 = new BepInExInfoLogInterpolatedStringHandler(60, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Faust initialized via ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(trigger);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" (attempt #");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(_initAttempts);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("). Prefab map has ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(existingSystemManaged.SpawnableNameToPrefabGuidDictionary.Count);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" entries.");
				}
				log3.LogInfo(val2);
				HeatmapSampler.Start();
				StartCoroutine(KillAutosaveLoop());
			}
			catch (Exception ex)
			{
				ManualLogSource log4 = Log;
				BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(35, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Faust init (");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(trigger);
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(") FAILED on attempt #");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(_initAttempts);
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(": ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<Exception>(ex);
				}
				log4.LogError(val3);
			}
			finally
			{
				_initInProgress = false;
			}
		}

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

		public static Coroutine StartCoroutine(IEnumerator routine)
		{
			return MonoBehaviour.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(routine));
		}

		private static IEnumerator KillAutosaveLoop()
		{
			WaitForSeconds wait = new WaitForSeconds(30f);
			bool flag = default(bool);
			while (true)
			{
				yield return wait;
				try
				{
					Kills?.Flush();
				}
				catch (Exception ex)
				{
					ManualLogSource log = Log;
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(31, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FAUST KILLS] autosave failed: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					}
					log.LogError(val);
				}
			}
		}
	}
	internal static class EntityExtensions
	{
		public static bool Exists(this Entity entity)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			if (entity != Entity.Null)
			{
				EntityManager entityManager = Core.EntityManager;
				return ((EntityManager)(ref entityManager)).Exists(entity);
			}
			return false;
		}

		public static bool Has<T>(this Entity entity)
		{
			//IL_0000: 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_0010: Unknown result type (might be due to invalid IL or missing references)
			if (entity.Exists())
			{
				EntityManager entityManager = Core.EntityManager;
				return ((EntityManager)(ref entityManager)).HasComponent<T>(entity);
			}
			return false;
		}

		public static T Read<T>(this Entity entity) where T : unmanaged
		{
			//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)
			EntityManager entityManager = Core.EntityManager;
			return ((EntityManager)(ref entityManager)).GetComponentData<T>(entity);
		}

		public static bool TryGetComponent<T>(this Entity entity, out T component) where T : unmanaged
		{
			//IL_0000: 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_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			if (entity.Exists())
			{
				EntityManager entityManager = Core.EntityManager;
				if (((EntityManager)(ref entityManager)).HasComponent<T>(entity))
				{
					entityManager = Core.EntityManager;
					component = ((EntityManager)(ref entityManager)).GetComponentData<T>(entity);
					return true;
				}
			}
			component = default(T);
			return false;
		}

		public static ulong GetSteamId(this Entity playerCharacter)
		{
			//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_0019: Unknown result type (might be due to invalid IL or missing references)
			if (playerCharacter.TryGetComponent<PlayerCharacter>(out PlayerCharacter component) && component.UserEntity.TryGetComponent<User>(out User component2))
			{
				return component2.PlatformId;
			}
			return 0uL;
		}

		public static PrefabGUID GetPrefabGuid(this Entity entity)
		{
			//IL_0000: 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_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if (!entity.TryGetComponent<PrefabGUID>(out PrefabGUID component))
			{
				return default(PrefabGUID);
			}
			return component;
		}

		public unsafe static bool TryResolvePlayer(string nameOrId, out ulong steamId, out string resolvedName, out Entity userEntity, out string error)
		{
			//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_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_0056: 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_0078: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			steamId = 0uL;
			resolvedName = null;
			userEntity = Entity.Null;
			error = null;
			if (string.IsNullOrWhiteSpace(nameOrId))
			{
				error = "Provide a character name or steamId.";
				return false;
			}
			ulong result;
			bool flag = ulong.TryParse(nameOrId, out result) && result > 1000;
			NativeArray<Entity> entitiesByComponentType = Query.GetEntitiesByComponentType<User>(includeDisabled: true);
			int num = 0;
			try
			{
				for (int i = 0; i < entitiesByComponentType.Length; i++)
				{
					if (!entitiesByComponentType[i].TryGetComponent<User>(out User component))
					{
						continue;
					}
					if (flag)
					{
						if (component.PlatformId == result)
						{
							steamId = component.PlatformId;
							resolvedName = ((object)(*(FixedString64Bytes*)(&component.CharacterName))/*cast due to .constrained prefix*/).ToString();
							userEntity = entitiesByComponentType[i];
							return true;
						}
						continue;
					}
					string text = ((object)(*(FixedString64Bytes*)(&component.CharacterName))/*cast due to .constrained prefix*/).ToString();
					if (!string.IsNullOrEmpty(text) && text.Contains(nameOrId, StringComparison.OrdinalIgnoreCase))
					{
						num++;
						steamId = component.PlatformId;
						resolvedName = text;
						userEntity = entitiesByComponentType[i];
						if (string.Equals(text, nameOrId, StringComparison.OrdinalIgnoreCase))
						{
							num = 1;
							break;
						}
					}
				}
			}
			finally
			{
				entitiesByComponentType.Dispose();
			}
			if (flag)
			{
				error = $"No player with steamId {result}.";
				return false;
			}
			if (num == 0)
			{
				error = "No player matches '" + nameOrId + "'.";
				return false;
			}
			if (num > 1)
			{
				error = "'" + nameOrId + "' matches multiple players — be more specific or use the steamId.";
				steamId = 0uL;
				userEntity = Entity.Null;
				return false;
			}
			return true;
		}

		public static string GetPrefabName(this PrefabGUID prefabGuid)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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)
			try
			{
				PrefabLookupMap prefabLookupMap = Core.PrefabCollectionSystem._PrefabLookupMap;
				NativeParallelHashMap<PrefabGUID, Entity> guidToEntityMap = prefabLookupMap.GuidToEntityMap;
				if (guidToEntityMap.ContainsKey(prefabGuid))
				{
					return ((PrefabLookupMap)(ref prefabLookupMap)).GetName(prefabGuid);
				}
			}
			catch
			{
			}
			return $"PrefabGuid({prefabGuid._Value})";
		}
	}
	[BepInPlugin("kdpen.Faust", "Faust", "0.16.5")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		internal static Harmony Harmony;

		internal static ManualLogSource PluginLog;

		internal static Plugin Instance { get; private set; }

		public override void Load()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Expected O, but got Unknown
			if (!(Application.productName != "VRisingServer"))
			{
				Instance = this;
				PluginLog = ((BasePlugin)this).Log;
				ManualLogSource log = ((BasePlugin)this).Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(20, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("kdpen.Faust");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" v");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("0.16.5");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loading...");
				}
				log.LogInfo(val);
				Settings.Initialize(((BasePlugin)this).Config);
				Core.InitPersistence();
				Harmony = new Harmony("kdpen.Faust");
				Harmony.PatchAll(Assembly.GetExecutingAssembly());
				int num = Harmony.GetPatchedMethods().Count();
				ManualLogSource log2 = ((BasePlugin)this).Log;
				val = new BepInExInfoLogInterpolatedStringHandler(44, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Harmony patches applied: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" method(s) patched.");
				}
				log2.LogInfo(val);
				CommandRegistry.RegisterAll();
				ManualLogSource log3 = ((BasePlugin)this).Log;
				val = new BepInExInfoLogInterpolatedStringHandler(42, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("kdpen.Faust");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" v");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("0.16.5");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded. Awaiting game data init.");
				}
				log3.LogInfo(val);
			}
		}

		public override bool Unload()
		{
			CommandRegistry.UnregisterAssembly();
			Core.MapMarkers?.Shutdown();
			Core.Store?.CloseAllOpen();
			Core.Heatmap?.Flush();
			Core.Kills?.Flush();
			Harmony harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			return true;
		}
	}
	internal static class Query
	{
		public static NativeArray<Entity> GetEntitiesByComponentType<T>(bool includeDisabled = false, bool includeSpawn = false, bool includePrefab = 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_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_000c: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0036: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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)
			EntityQueryOptions val = (EntityQueryOptions)0;
			if (includeDisabled)
			{
				val = (EntityQueryOptions)(val | 2);
			}
			if (includeSpawn)
			{
				val = (EntityQueryOptions)(val | 0x40);
			}
			if (includePrefab)
			{
				val = (EntityQueryOptions)(val | 1);
			}
			EntityQueryBuilder val2 = new EntityQueryBuilder(AllocatorHandle.op_Implicit((Allocator)2));
			val2 = ((EntityQueryBuilder)(ref val2)).AddAll(new ComponentType(Il2CppType.Of<T>(), (AccessMode)1));
			EntityQueryBuilder val3 = ((EntityQueryBuilder)(ref val2)).WithOptions(val);
			EntityManager entityManager = Core.EntityManager;
			EntityQuery val4 = ((EntityManager)(ref entityManager)).CreateEntityQuery(ref val3);
			NativeArray<Entity> result = ((EntityQuery)(ref val4)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			((EntityQueryBuilder)(ref val3)).Dispose();
			return result;
		}

		public static IEnumerable<Entity> GetUsersOnline()
		{
			NativeArray<Entity> users = GetEntitiesByComponentType<User>(includeDisabled: true);
			try
			{
				for (int i = 0; i < users.Length; i++)
				{
					if (users[i].TryGetComponent<User>(out User component) && component.IsConnected)
					{
						yield return users[i];
					}
				}
			}
			finally
			{
				users.Dispose();
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "kdpen.Faust";

		public const string PLUGIN_NAME = "Faust";

		public const string PLUGIN_VERSION = "0.16.5";
	}
}
namespace Faust.Services
{
	internal sealed class BossService
	{
		public readonly struct BossSnapshot
		{
			public int Guid { get; init; }

			public string Name { get; init; }

			public bool Alive { get; init; }

			public bool Defeated { get; init; }

			public float X { get; init; }

			public float Z { get; init; }

			public string Region { get; init; }

			public float Hp { get; init; }

			public float HpMax { get; init; }

			public int Level { get; init; }
		}

		private const float Sentinel = 10000f;

		private static float MapLimit => Settings.BossMapLimit.Value;

		public List<BossSnapshot> GetBosses()
		{
			//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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_035b: 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_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: 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_00e0: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: 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_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: 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_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: 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_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<int, BossSnapshot> dictionary = new Dictionary<int, BossSnapshot>();
			Dictionary<int, (float, float)> dictionary2 = BuildMapTokenPositions();
			NativeArray<Entity> entitiesByComponentType = Query.GetEntitiesByComponentType<VBloodUnit>(includeDisabled: true);
			try
			{
				float3 val2 = default(float3);
				for (int i = 0; i < entitiesByComponentType.Length; i++)
				{
					Entity val = entitiesByComponentType[i];
					if (!val.Has<VBloodConsumeSource>() || !val.TryGetComponent<Health>(out Health component) || component.Value <= 0f)
					{
						continue;
					}
					int value = val.GetPrefabGuid()._Value;
					if (value == 0)
					{
						continue;
					}
					Translation component2;
					bool flag = val.TryGetComponent<Translation>(out component2);
					LocalToWorld component3;
					bool flag2 = val.TryGetComponent<LocalToWorld>(out component3);
					if (flag || flag2)
					{
						float num;
						float num2;
						bool flag3;
						if (flag && OnMap(component2.Value.x, component2.Value.z))
						{
							num = component2.Value.x;
							num2 = component2.Value.z;
							flag3 = true;
						}
						else if (flag2 && OnMap(((LocalToWorld)(ref component3)).Position.x, ((LocalToWorld)(ref component3)).Position.z))
						{
							num = ((LocalToWorld)(ref component3)).Position.x;
							num2 = ((LocalToWorld)(ref component3)).Position.z;
							flag3 = true;
						}
						else
						{
							num = (flag ? component2.Value.x : ((LocalToWorld)(ref component3)).Position.x);
							num2 = (flag ? component2.Value.z : ((LocalToWorld)(ref component3)).Position.z);
							flag3 = false;
						}
						if (!flag3 && dictionary2.TryGetValue(value, out var value2))
						{
							num = value2.Item1;
							num2 = value2.Item2;
							flag3 = true;
						}
						if (!flag3 && TryFollowerPosition(val, out var x, out var z))
						{
							num = x;
							num2 = z;
							flag3 = true;
						}
						((float3)(ref val2))..ctor(num, flag2 ? ((LocalToWorld)(ref component3)).Position.y : 0f, num2);
						BossSnapshot value3;
						if (flag3)
						{
							int territoryIndexAt = Core.Castle.GetTerritoryIndexAt(val2);
							string region = Core.Castle.GetWorldRegionName(val2) ?? Core.Castle.GetRegionForTerritory(territoryIndexAt);
							value3 = new BossSnapshot
							{
								Guid = value,
								Name = EntityExtensions.GetPrefabName(new PrefabGUID(value)),
								Alive = true,
								Defeated = Core.Unlock.IsDefeatedAnywhere(value),
								X = val2.x,
								Z = val2.z,
								Region = region,
								Hp = component.Value,
								HpMax = component.MaxHealth._Value,
								Level = (val.TryGetComponent<UnitLevel>(out UnitLevel component4) ? component4.Level._Value : 0)
							};
						}
						else
						{
							value3 = new BossSnapshot
							{
								Guid = value,
								Name = EntityExtensions.GetPrefabName(new PrefabGUID(value)),
								Alive = false,
								Defeated = Core.Unlock.IsDefeatedAnywhere(value)
							};
						}
						if (!dictionary.TryGetValue(value, out var value4) || (!value4.Alive && value3.Alive))
						{
							dictionary[value] = value3;
						}
					}
				}
			}
			finally
			{
				entitiesByComponentType.Dispose();
			}
			foreach (int item in Core.Unlock.AllDefeatedGuids())
			{
				if (!dictionary.ContainsKey(item))
				{
					dictionary[item] = new BossSnapshot
					{
						Guid = item,
						Name = EntityExtensions.GetPrefabName(new PrefabGUID(item)),
						Alive = false,
						Defeated = true
					};
				}
			}
			List<BossSnapshot> list = new List<BossSnapshot>(dictionary.Values);
			list.Sort((BossSnapshot a, BossSnapshot b) => (a.Alive != b.Alive) ? ((!a.Alive) ? 1 : (-1)) : string.CompareOrdinal(a.Name, b.Name));
			return list;
		}

		private static Dictionary<int, (float x, float z)> BuildMapTokenPositions()
		{
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Expected O, but got Unknown
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Expected O, but got Unknown
			//IL_0320: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: Expected O, but got Unknown
			//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_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_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: 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_0024: 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_0035: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: 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_0056: 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_0061: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: 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_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: 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_0254: 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_0260: 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_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: 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)
			Dictionary<int, (float, float)> dictionary = new Dictionary<int, (float, float)>();
			bool flag = default(bool);
			try
			{
				NativeArray<Entity> entitiesByComponentType = Query.GetEntitiesByComponentType<Script_BloodAltar_TrackVBloodUnit_Shared>(includeDisabled: true);
				try
				{
					for (int i = 0; i < entitiesByComponentType.Length; i++)
					{
						if (entitiesByComponentType[i].TryGetComponent<Script_BloodAltar_TrackVBloodUnit_Shared>(out Script_BloodAltar_TrackVBloodUnit_Shared component))
						{
							int value = component.TrackedUnit._Value;
							if (value != 0 && OnMap(component.TrackPosition.x, component.TrackPosition.z))
							{
								dictionary[value] = (component.TrackPosition.x, component.TrackPosition.z);
							}
						}
					}
				}
				finally
				{
					entitiesByComponentType.Dispose();
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = Core.Log;
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(40, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FAUST BOSS] altar-track source failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				log.LogWarning(val);
			}
			try
			{
				NativeArray<Entity> entitiesByComponentType2 = Query.GetEntitiesByComponentType<MapIconData>(includeDisabled: true);
				try
				{
					for (int j = 0; j < entitiesByComponentType2.Length; j++)
					{
						Entity entity = entitiesByComponentType2[j];
						if (!entity.TryGetComponent<MapIconData>(out MapIconData component2))
						{
							continue;
						}
						Entity targetUser = component2.TargetUser;
						if (targetUser == Entity.Null || !targetUser.Exists() || !targetUser.Has<VBloodUnit>())
						{
							continue;
						}
						int value2 = targetUser.GetPrefabGuid()._Value;
						if (value2 == 0 || dictionary.ContainsKey(value2))
						{
							continue;
						}
						float x;
						float z;
						if (entity.TryGetComponent<LocalToWorld>(out LocalToWorld component3))
						{
							x = ((LocalToWorld)(ref component3)).Position.x;
							z = ((LocalToWorld)(ref component3)).Position.z;
						}
						else
						{
							if (!entity.TryGetComponent<Translation>(out Translation component4))
							{
								continue;
							}
							x = component4.Value.x;
							z = component4.Value.z;
						}
						if (OnMap(x, z))
						{
							dictionary[value2] = (x, z);
						}
					}
				}
				finally
				{
					entitiesByComponentType2.Dispose();
				}
			}
			catch (Exception ex2)
			{
				ManualLogSource log2 = Core.Log;
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(37, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FAUST BOSS] map-icon source failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex2.Message);
				}
				log2.LogWarning(val);
			}
			try
			{
				NativeArray<Entity> entitiesByComponentType3 = Query.GetEntitiesByComponentType<MapIconTargetEntity>(includeDisabled: true);
				try
				{
					for (int k = 0; k < entitiesByComponentType3.Length; k++)
					{
						Entity entity2 = entitiesByComponentType3[k];
						if (!entity2.TryGetComponent<MapIconTargetEntity>(out MapIconTargetEntity component5))
						{
							continue;
						}
						Entity entity3 = component5.TargetEntity._Entity;
						if (entity3 == Entity.Null || !entity3.Exists() || !entity3.Has<VBloodUnit>())
						{
							continue;
						}
						int value3 = entity3.GetPrefabGuid()._Value;
						if (value3 == 0 || dictionary.ContainsKey(value3))
						{
							continue;
						}
						float x2;
						float z2;
						if (entity2.TryGetComponent<LocalToWorld>(out LocalToWorld component6))
						{
							x2 = ((LocalToWorld)(ref component6)).Position.x;
							z2 = ((LocalToWorld)(ref component6)).Position.z;
						}
						else
						{
							if (!entity2.TryGetComponent<Translation>(out Translation component7))
							{
								continue;
							}
							x2 = component7.Value.x;
							z2 = component7.Value.z;
						}
						if (OnMap(x2, z2))
						{
							dictionary[value3] = (x2, z2);
						}
					}
				}
				finally
				{
					entitiesByComponentType3.Dispose();
				}
			}
			catch (Exception ex3)
			{
				ManualLogSource log3 = Core.Log;
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(39, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FAUST BOSS] map-target source failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex3.Message);
				}
				log3.LogWarning(val);
			}
			return dictionary;
		}

		private static bool TryFollowerPosition(Entity e, out float x, out float z)
		{
			//IL_000e: 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_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_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_0033: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_0072: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			x = (z = 0f);
			if (!e.TryGetComponent<Follower>(out Follower component))
			{
				return false;
			}
			Entity value = component.Followed._Value;
			if (value == Entity.Null || !value.Exists())
			{
				return false;
			}
			if (value.TryGetComponent<Translation>(out Translation component2) && OnMap(component2.Value.x, component2.Value.z))
			{
				x = component2.Value.x;
				z = component2.Value.z;
				return true;
			}
			if (value.TryGetComponent<LocalToWorld>(out LocalToWorld component3) && OnMap(((LocalToWorld)(ref component3)).Position.x, ((LocalToWorld)(ref component3)).Position.z))
			{
				x = ((LocalToWorld)(ref component3)).Position.x;
				z = ((LocalToWorld)(ref component3)).Position.z;
				return true;
			}
			return false;
		}

		public bool TryGetBoss(string nameOrGuid, out BossSnapshot snapshot)
		{
			snapshot = default(BossSnapshot);
			List<BossSnapshot> bosses = GetBosses();
			int result;
			bool flag = int.TryParse(nameOrGuid, out result);
			BossSnapshot? bossSnapshot = null;
			BossSnapshot? bossSnapshot2 = null;
			int num = 0;
			foreach (BossSnapshot item in bosses)
			{
				if (flag && item.Guid == result)
				{
					snapshot = item;
					return true;
				}
				if (item.Name != null)
				{
					if (string.Equals(item.Name, nameOrGuid, StringComparison.OrdinalIgnoreCase))
					{
						bossSnapshot = item;
					}
					else if (item.Name.Contains(nameOrGuid, StringComparison.OrdinalIgnoreCase))
					{
						bossSnapshot2 = item;
						num++;
					}
				}
			}
			if (bossSnapshot.HasValue)
			{
				snapshot = bossSnapshot.Value;
				return true;
			}
			if (bossSnapshot2.HasValue && num == 1)
			{
				snapshot = bossSnapshot2.Value;
				return true;
			}
			return false;
		}

		public List<string> Diagnose(string filter)
		{
			//IL_009c: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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_00e5: 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_0111: 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_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0419: Unknown result type (might be due to invalid IL or missing references)
			//IL_041b: Unknown result type (might be due to invalid IL or missing references)
			if (!string.IsNullOrWhiteSpace(filter) && (filter.Equals("icons", StringComparison.OrdinalIgnoreCase) || filter.Equals("mapicons", StringComparison.OrdinalIgnoreCase)))
			{
				return DiagnoseIcons();
			}
			int result;
			bool flag = int.TryParse(filter, out result);
			bool flag2 = !string.IsNullOrWhiteSpace(filter);
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 0;
			int num5 = 0;
			int num6 = 0;
			int num7 = 0;
			int num8 = 0;
			int num9 = 0;
			int num10 = 0;
			int num11 = 0;
			int num12 = 0;
			List<string> list = new List<string>();
			Dictionary<int, (float, float)> dictionary = BuildMapTokenPositions();
			float num13 = float.MaxValue;
			float num14 = float.MinValue;
			float num15 = float.MaxValue;
			float num16 = float.MinValue;
			Dictionary<(int, int), int> dictionary2 = new Dictionary<(int, int), int>();
			Dictionary<(int, int), int> dictionary3 = new Dictionary<(int, int), int>();
			NativeArray<Entity> entitiesByComponentType = Query.GetEntitiesByComponentType<VBloodUnit>(includeDisabled: true);
			try
			{
				for (int i = 0; i < entitiesByComponentType.Length; i++)
				{
					Entity entity = entitiesByComponentType[i];
					num++;
					int value = entity.GetPrefabGuid()._Value;
					string prefabName = EntityExtensions.GetPrefabName(new PrefabGUID(value));
					bool flag3 = entity.Has<VBloodConsumeSource>();
					if (flag3)
					{
						num2++;
					}
					Health component;
					bool flag4 = entity.TryGetComponent<Health>(out component);
					if (flag4 && component.Value > 0f)
					{
						num3++;
					}
					LocalToWorld component2;
					bool flag5 = entity.TryGetComponent<LocalToWorld>(out component2);
					Translation component3;
					bool flag6 = entity.TryGetComponent<Translation>(out component3);
					bool flag7 = entity.Has<Disabled>();
					if (flag7)
					{
						num7++;
					}
					float num17 = (flag5 ? ((LocalToWorld)(ref component2)).Position.x : 0f);
					float num18 = (flag5 ? ((LocalToWorld)(ref component2)).Position.z : 0f);
					float num19 = (flag6 ? component3.Value.x : 0f);
					float num20 = (flag6 ? component3.Value.z : 0f);
					bool flag8 = flag5 && OnMap(num17, num18);
					bool flag9 = flag6 && OnMap(num19, num20);
					if (!flag5)
					{
						num6++;
					}
					else if (flag8)
					{
						num4++;
						if (num17 < num13)
						{
							num13 = num17;
						}
						if (num17 > num14)
						{
							num14 = num17;
						}
						if (num18 < num15)
						{
							num15 = num18;
						}
						if (num18 > num16)
						{
							num16 = num18;
						}
					}
					else
					{
						num5++;
						if (flag3)
						{
							Bump(dictionary2, num17, num18);
						}
					}
					if (!flag6)
					{
						num10++;
					}
					else if (flag9)
					{
						num8++;
					}
					else
					{
						num9++;
						if (flag3)
						{
							Bump(dictionary3, num19, num20);
						}
					}
					if (flag3 && flag5 && flag6 && !flag8 && flag9)
					{
						num11++;
					}
					(float, float) value2;
					bool flag10 = dictionary.TryGetValue(value, out value2);
					if (flag3 && !flag8 && !flag9 && flag10)
					{
						num12++;
					}
					if (flag2 && (flag ? (value == result) : prefabName.Contains(filter, StringComparison.OrdinalIgnoreCase)))
					{
						list.Add($"{prefabName} guid={value} ltw=({F(num17)},{F(num18)}) tr=({F(num19)},{F(num20)}) token={(flag10 ? $"({F(value2.Item1)},{F(value2.Item2)})" : "-")} cs={B(flag3)} hp={(flag4 ? F(component.Value) : "-")}/{(flag4 ? F(component.MaxHealth._Value) : "-")} disabled={B(flag7)}");
					}
				}
			}
			finally
			{
				entitiesByComponentType.Dispose();
			}
			List<string> list2 = new List<string> { $"VBlood: {num} total · {num2} cs · {num3} alive · LTW[{num4} on/{num5} off/{num6} none] · TR[{num8} on/{num9} off/{num10} none] · {num7} disabled · off-LTW-but-on-TR(cs)={num11}." };
			if (num4 > 0)
			{
				list2.Add($"Placed bounds (LTW): x[{F(num13)}..{F(num14)}] z[{F(num15)}..{F(num16)}].");
			}
			if (dictionary2.Count > 0)
			{
				list2.Add(ClusterLine("Off-map LTW", dictionary2));
			}
			if (dictionary3.Count > 0)
			{
				list2.Add(ClusterLine("Off-map TR", dictionary3));
			}
			if (num11 > 0)
			{
				list2.Add($"⇒ {num11} consume-source bosses are off-map by LocalToWorld but ON-map by Translation " + "— the board should read Translation.");
			}
			list2.Add($"Map tokens: {dictionary.Count} V Blood position(s) resolved (altar-track + TargetUser-icon + TargetEntity-icon); {num12} off-map boss(es) rescued by a token (the combine). {((dictionary.Count == 0) ? "NONE found  no token source carries positions on this server; run '.faust admin bossdiag icons' for the breakdown." : "")}");
			if (flag2)
			{
				list2.Add($"Matches for '{filter}': {list.Count}");
				list2.AddRange(list);
			}
			else if (dictionary2.Count == 0 && num5 == 0)
			{
				list2.Add("No off-map bosses (LTW). Add a name/guid to dump rows, or 'icons' for the map-icon picture.");
			}
			return list2;
		}

		private static bool IsSentinel(float x, float z)
		{
			if (Math.Abs(Math.Abs(x) - 10000f) < 250f)
			{
				return Math.Abs(Math.Abs(z) - 10000f) < 250f;
			}
			return false;
		}

		private static bool OnMap(float x, float z)
		{
			if (!IsSentinel(x, z) && Math.Abs(x) <= MapLimit)
			{
				return Math.Abs(z) <= MapLimit;
			}
			return false;
		}

		private static void Bump(Dictionary<(int, int), int> map, float x, float z)
		{
			(int, int) key = ((int)Math.Round(x / 500f) * 500, (int)Math.Round(z / 500f) * 500);
			map[key] = ((!map.TryGetValue(key, out var value)) ? 1 : (value + 1));
		}

		private static string ClusterLine(string label, Dictionary<(int, int), int> map)
		{
			List<KeyValuePair<(int, int), int>> source = map.OrderByDescending((KeyValuePair<(int, int), int> kv) => kv.Value).Take(6).ToList();
			return $"{label} clusters (~500u, {map.Count} distinct): " + string.Join(" · ", source.Select((KeyValuePair<(int, int), int> kv) => $"({kv.Key.Item1},{kv.Key.Item2})x{kv.Value}"));
		}

		private List<string> DiagnoseIcons()
		{
			//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_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_003c: 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_0059: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 0;
			int num5 = 0;
			int num6 = 0;
			int num7 = 0;
			int num8 = 0;
			List<string> list = new List<string>();
			NativeArray<Entity> entitiesByComponentType = Query.GetEntitiesByComponentType<MapIconData>(includeDisabled: true);
			try
			{
				for (int i = 0; i < entitiesByComponentType.Length; i++)
				{
					Entity entity = entitiesByComponentType[i];
					num++;
					if (!entity.TryGetComponent<MapIconData>(out MapIconData component))
					{
						continue;
					}
					if (entity.Has<MapIconTargetEntity>())
					{
						num8++;
					}
					if (entity.Has<MapIconPosition>())
					{
						num7++;
					}
					Entity targetUser = component.TargetUser;
					int num9;
					if (targetUser != Entity.Null)
					{
						num9 = (targetUser.Exists() ? 1 : 0);
						if (num9 != 0)
						{
							num2++;
						}
					}
					else
					{
						num9 = 0;
					}
					if (num9 == 0 || !targetUser.Has<VBloodUnit>())
					{
						continue;
					}
					num3++;
					float num10 = 0f;
					float num11 = 0f;
					bool flag = false;
					Translation component3;
					if (entity.TryGetComponent<LocalToWorld>(out LocalToWorld component2))
					{
						num10 = ((LocalToWorld)(ref component2)).Position.x;
						num11 = ((LocalToWorld)(ref component2)).Position.z;
						flag = true;
					}
					else if (entity.TryGetComponent<Translation>(out component3))
					{
						num10 = component3.Value.x;
						num11 = component3.Value.z;
						flag = true;
					}
					if (!flag)
					{
						num6++;
					}
					else if (OnMap(num10, num11))
					{
						num4++;
					}
					else
					{
						num5++;
					}
					if (list.Count < 15)
					{
						int value = targetUser.GetPrefabGuid()._Value;
						float v = 0f;
						float v2 = 0f;
						if (targetUser.TryGetComponent<LocalToWorld>(out LocalToWorld component4))
						{
							v = ((LocalToWorld)(ref component4)).Position.x;
							v2 = ((LocalToWorld)(ref component4)).Position.z;
						}
						list.Add($"{EntityExtensions.GetPrefabName(new PrefabGUID(value))} icon=({(flag ? (F(num10) + "," + F(num11)) : "-")}) unit=({F(v)},{F(v2)})");
					}
				}
			}
			finally
			{
				entitiesByComponentType.Dispose();
			}
			List<string> list2 = new List<string>
			{
				$"MapIcons: {num} total · {num2} w/TargetUser · {num3} target a VBlood · {num8} w/MapIconTargetEntity · {num7} w/TilePosition.",
				$"VBlood-icon positions (via TargetUser): {num4} on-map · {num5} off-map · {num6} no-position."
			};
			list2.AddRange(DiagnoseTargetEntityIcons());
			if (num3 == 0)
			{
				list2.Add("No VBlood-linked icons via TargetUser — boss icons link via MapIconTargetEntity (see below).");
			}
			list2.AddRange(list);
			return list2;
		}

		private List<string> DiagnoseTargetEntityIcons()
		{
			//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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_0075: 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_00c2: 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_00b1: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: 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_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: 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_021c: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 0;
			int num5 = 0;
			int num6 = 0;
			int num7 = 0;
			List<string> list = new List<string>();
			try
			{
				NativeArray<Entity> entitiesByComponentType = Query.GetEntitiesByComponentType<MapIconTargetEntity>(includeDisabled: true);
				try
				{
					for (int i = 0; i < entitiesByComponentType.Length; i++)
					{
						Entity entity = entitiesByComponentType[i];
						num++;
						if (!entity.TryGetComponent<MapIconTargetEntity>(out MapIconTargetEntity component))
						{
							continue;
						}
						Entity entity2 = component.TargetEntity._Entity;
						if (entity2 == Entity.Null || !entity2.Exists())
						{
							num3++;
						}
						else if (entity2.Has<VBloodUnit>())
						{
							num2++;
							float num8 = 0f;
							float num9 = 0f;
							bool flag = false;
							Translation component3;
							if (entity.TryGetComponent<LocalToWorld>(out LocalToWorld component2))
							{
								num8 = ((LocalToWorld)(ref component2)).Position.x;
								num9 = ((LocalToWorld)(ref component2)).Position.z;
								flag = true;
							}
							else if (entity.TryGetComponent<Translation>(out component3))
							{
								num8 = component3.Value.x;
								num9 = component3.Value.z;
								flag = true;
							}
							if (!flag)
							{
								num6++;
							}
							else if (OnMap(num8, num9))
							{
								num4++;
							}
							else
							{
								num5++;
							}
							MapIconPosition component4;
							bool flag2 = entity.TryGetComponent<MapIconPosition>(out component4);
							if (flag2)
							{
								num7++;
							}
							if (list.Count < 15)
							{
								int value = entity2.GetPrefabGuid()._Value;
								string value2 = (flag2 ? $"tile=({component4.TilePosition.x},{component4.TilePosition.y}) tilewc=({F((float)(component4.TilePosition.x - 6400) / 2f)},{F((float)(component4.TilePosition.y - 6400) / 2f)})" : "tile=-");
								list.Add($"{EntityExtensions.GetPrefabName(new PrefabGUID(value))} world={(flag ? $"({F(num8)},{F(num9)})" : "-")} {value2}");
							}
						}
					}
				}
				finally
				{
					entitiesByComponentType.Dispose();
				}
			}
			catch (Exception ex)
			{
				return new List<string> { "MapIconTargetEntity scan failed: " + ex.Message };
			}
			List<string> list2 = new List<string>
			{
				$"MapIconTargetEntity: {num} total · {num2} resolve to a VBlood (direct Entity) · {num3} null/unsynced Entity · {num7} w/TilePosition.",
				$"VBlood target-icon positions: {num4} ON-map (these rescue parked bosses) · {num5} off-map · {num6} no-world-pos."
			};
			if (num2 == 0 && num3 > 0)
			{
				list2.Add("⇒ VBlood target-icons resolve with a NULL Entity — need NetworkId resolution (TargetNetworkId) to link them.");
			}
			else if (num2 == 0)
			{
				list2.Add("⇒ No MapIconTargetEntity icons target a VBlood — boss lair positions are NOT in live map icons on this server.");
			}
			else if (num4 == 0)
			{
				list2.Add("⇒ VBlood target-icons exist but NONE carry an on-map world transform — lair pos may live in TilePosition only (see tilewc estimate).");
			}
			list2.AddRange(list);
			return list2;
		}

		private static string F(float v)
		{
			return v.ToString("0", CultureInfo.InvariantCulture);
		}

		private static string B(bool b)
		{
			if (!b)
			{
				return "0";
			}
			return "1";
		}
	}
	internal sealed class CastleService
	{
		public enum PlotState
		{
			Unclaimed,
			Sealed,
			Fueled,
			Decaying
		}

		public readonly struct TerritoryInfo
		{
			public int TerritoryIndex { get; init; }

			public bool HasHeart { get; init; }

			public ulong OwnerSteamId { get; init; }

			public string OwnerName { get; init; }

			public bool OwnerOnline { get; init; }

			public long OwnerLastConnected { get; init; }

			public string Region { get; init; }

			public int SizeBlocks { get; init; }

			public PlotState State { get; init; }

			public long DecaySeconds { get; init; }

			public int HeartLevel { get; init; }

			public int Floors { get; init; }

			public long ClaimedUnix { get; init; }

			public string ClanName { get; init; }

			public long TotalItems { get; init; }
		}

		public readonly struct ResourceSummary
		{
			public int TerritoryIndex { get; init; }

			public ulong OwnerSteamId { get; init; }

			public string OwnerName { get; init; }

			public int Containers { get; init; }

			public long TotalItems { get; init; }

			public List<(int guid, long qty, string name)> Items { get; init; }

			public int Prisoners { get; init; }

			public List<(string name, string bloodType, int bloodQuality)> PrisonerList { get; init; }
		}

		private struct RegionPolygon
		{
			public WorldRegionType Region;

			public Aabb Bounds;

			public float2[] Vertices;
		}

		private const float BLOCK_SIZE = 10f;

		private Dictionary<int2, int> _blockToTerritory;

		private Dictionary<int, string> _territoryRegion;

		private Dictionary<int, float2> _territoryCenters;

		private float2 _mapWorldMin;

		private float2 _mapWorldMax;

		private bool _mapBoundsValid;

		private List<RegionPolygon> _regionPolygons;

		private static float BlockToWorld(float block)
		{
			return (10f * block - 6400f) / 2f;
		}

		private void EnsureBlockMap()
		{
			//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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: 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_00af: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: 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_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: 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_00e2: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: 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_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			if (_blockToTerritory != null)
			{
				return;
			}
			_blockToTerritory = new Dictionary<int2, int>();
			_territoryRegion = new Dictionary<int, string>();
			_territoryCenters = new Dictionary<int, float2>();
			int2 val = default(int2);
			((int2)(ref val))..ctor(int.MaxValue, int.MaxValue);
			int2 val2 = default(int2);
			((int2)(ref val2))..ctor(int.MinValue, int.MinValue);
			NativeArray<Entity> entitiesByComponentType = Query.GetEntitiesByComponentType<CastleTerritory>(includeDisabled: true);
			try
			{
				for (int i = 0; i < entitiesByComponentType.Length; i++)
				{
					int castleTerritoryIndex = entitiesByComponentType[i].Read<CastleTerritory>().CastleTerritoryIndex;
					if (entitiesByComponentType[i].TryGetComponent<TerritoryWorldRegion>(out TerritoryWorldRegion component) && (int)component.Region != 0)
					{
						_territoryRegion[castleTerritoryIndex] = RegionName(component.Region);
					}
					EntityManager entityManager = Core.EntityManager;
					DynamicBuffer<CastleTerritoryBlocks> buffer = ((EntityManager)(ref entityManager)).GetBuffer<CastleTerritoryBlocks>(entitiesByComponentType[i], false);
					long num = 0L;
					long num2 = 0L;
					for (int j = 0; j < buffer.Length; j++)
					{
						int2 blockCoordinate = buffer[j].BlockCoordinate;
						_blockToTerritory[blockCoordinate] = castleTerritoryIndex;
						num += blockCoordinate.x;
						num2 += blockCoordinate.y;
						if (blockCoordinate.x < val.x)
						{
							val.x = blockCoordinate.x;
						}
						if (blockCoordinate.x > val2.x)
						{
							val2.x = blockCoordinate.x;
						}
						if (blockCoordinate.y < val.y)
						{
							val.y = blockCoordinate.y;
						}
						if (blockCoordinate.y > val2.y)
						{
							val2.y = blockCoordinate.y;
						}
					}
					if (buffer.Length > 0)
					{
						_territoryCenters[castleTerritoryIndex] = new float2(BlockToWorld((float)num / (float)buffer.Length), BlockToWorld((float)num2 / (float)buffer.Length));
					}
				}
			}
			finally
			{
				entitiesByComponentType.Dispose();
			}
			if (val2.x >= val.x)
			{
				_mapWorldMin = new float2(BlockToWorld(val.x), BlockToWorld(val.y));
				_mapWorldMax = new float2(BlockToWorld(val2.x), BlockToWorld(val2.y));
				_mapBoundsValid = true;
			}
		}

		public string GetRegionForTerritory(int territoryIndex)
		{
			if (territoryIndex < 0)
			{
				return null;
			}
			EnsureBlockMap();
			if (!_territoryRegion.TryGetValue(territoryIndex, out var value))
			{
				return null;
			}
			return value;
		}

		public bool TryGetTerritoryCenter(int territoryIndex, out float x, out float z)
		{
			//IL_002d: 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)
			x = 0f;
			z = 0f;
			if (territoryIndex < 0)
			{
				return false;
			}
			EnsureBlockMap();
			if (!_territoryCenters.TryGetValue(territoryIndex, out var value))
			{
				return false;
			}
			x = value.x;
			z = value.y;
			return true;
		}

		public bool TryGetMapWorldBounds(out float minX, out float minZ, out float maxX, out float maxZ)
		{
			EnsureBlockMap();
			minX = _mapWorldMin.x;
			minZ = _mapWorldMin.y;
			maxX = _mapWorldMax.x;
			maxZ = _mapWorldMax.y;
			return _mapBoundsValid;
		}

		private void EnsureRegionPolygons()
		{
			//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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0050: 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_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_00b2: 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_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)
			if (_regionPolygons != null)
			{
				return;
			}
			_regionPolygons = new List<RegionPolygon>();
			NativeArray<Entity> entitiesByComponentType = Query.GetEntitiesByComponentType<WorldRegionPolygon>(includeDisabled: true);
			try
			{
				for (int i = 0; i < entitiesByComponentType.Length; i++)
				{
					if (!entitiesByComponentType[i].Has<WorldRegionPolygonVertex>())
					{
						continue;
					}
					WorldRegionPolygon val = entitiesByComponentType[i].Read<WorldRegionPolygon>();
					EntityManager entityManager = Core.EntityManager;
					DynamicBuffer<WorldRegionPolygonVertex> buffer = ((EntityManager)(ref entityManager)).GetBuffer<WorldRegionPolygonVertex>(entitiesByComponentType[i], false);
					if (buffer.Length >= 3)
					{
						float2[] array = (float2[])(object)new float2[buffer.Length];
						for (int j = 0; j < buffer.Length; j++)
						{
							array[j] = buffer[j].VertexPos;
						}
						_regionPolygons.Add(new RegionPolygon
						{
							Region = val.WorldRegion,
							Bounds = val.PolygonBounds,
							Vertices = array
						});
					}
				}
			}
			finally
			{
				entitiesByComponentType.Dispose();
			}
			if (Settings.VerboseLogging.Value)
			{
				ManualLogSource log = Core.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(45, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[FAUST CASTLE] world-region polygons cached: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(_regionPolygons.Count);
				}
				log.LogInfo(val2);
			}
		}

		public string GetWorldRegionName(float3 pos)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_004f: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: 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_0099: Unknown result type (might be due to invalid IL or missing references)
			EnsureRegionPolygons();
			foreach (RegionPolygon regionPolygon in _regionPolygons)
			{
				if (!(pos.x < regionPolygon.Bounds.Min.x) && !(pos.x > regionPolygon.Bounds.Max.x) && !(pos.z < regionPolygon.Bounds.Min.z) && !(pos.z > regionPolygon.Bounds.Max.z) && IsPointInPolygon(regionPolygon.Vertices, pos.x, pos.z))
				{
					return RegionName(regionPolygon.Region);
				}
			}
			return null;
		}

		private string ResolveTerritoryRegion(Entity territoryEntity)
		{
			//IL_0000: 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_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_002a: 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)
			if (territoryEntity.TryGetComponent<TerritoryWorldRegion>(out TerritoryWorldRegion component) && (int)component.Region != 0)
			{
				return RegionName(component.Region);
			}
			if (TryGetTerritorySamplePosition(territoryEntity, out var pos))
			{
				return GetWorldRegionName(pos);
			}
			return null;
		}

		private bool TryGetTerritorySamplePosition(Entity territoryEntity, out float3 pos)
		{
			//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_000c: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			pos = default(float3);
			EntityManager entityManager = Core.EntityManager;
			if (!((EntityManager)(ref entityManager)).HasComponent<CastleTerritoryBlocks>(territoryEntity))
			{
				return false;
			}
			entityManager = Core.EntityManager;
			DynamicBuffer<CastleTerritoryBlocks> buffer = ((EntityManager)(ref entityManager)).GetBuffer<CastleTerritoryBlocks>(territoryEntity, false);
			if (buffer.Length == 0)
			{
				return false;
			}
			pos = BlockCoordToWorldCentre(buffer[0].BlockCoordinate);
			return true;
		}

		private static float3 BlockCoordToWorldCentre(int2 block)
		{
			//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_0045: Unknown result type (might be due to invalid IL or missing references)
			float num = (float)block.x * 10f + 5f;
			float num2 = (float)block.y * 10f + 5f;
			return new float3((num - 6400f) / 2f, 0f, (num2 - 6400f) / 2f);
		}

		private static bool IsPointInPolygon(float2[] polygon, float px, float pz)
		{
			int num = 0;
			int num2 = 0;
			int num3 = polygon.Length - 1;
			while (num2 < polygon.Length)
			{
				if (polygon[num2].y > pz != polygon[num3].y > pz && px < (polygon[num3].x - polygon[num2].x) * (pz - polygon[num2].y) / (polygon[num3].y - polygon[num2].y) + polygon[num2].x)
				{
					num++;
				}
				num3 = num2++;
			}
			return (num & 1) != 0;
		}

		private static float3 ConvertPosToGrid(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));
		}

		private static 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 = ConvertPosToGrid(pos);
			return new int2((int)math.floor(val.x / 10f), (int)math.floor(val.z / 10f));
		}

		public int GetTerritoryIndexAt(float3 pos)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			EnsureBlockMap();
			if (!_blockToTerritory.TryGetValue(ConvertPosToBlockCoord(pos), out var value))
			{
				return -1;
			}
			return value;
		}

		public int GetNearestHeartTerritory(float3 pos)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0058: 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_005f: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			NativeArray<Entity> entitiesByComponentType = Query.GetEntitiesByComponentType<CastleHeart>(includeDisabled: true);
			int result = -1;
			float num = float.MaxValue;
			try
			{
				for (int i = 0; i < entitiesByComponentType.Length; i++)
				{
					if (!entitiesByComponentType[i].Has<LocalToWorld>())
					{
						continue;
					}
					LocalToWorld val = entitiesByComponentType[i].Read<LocalToWorld>();
					float3 position = ((LocalToWorld)(ref val)).Position;
					float num2 = math.distancesq(pos, position);
					if (!(num2 >= num))
					{
						Entity castleTerritoryEntity = entitiesByComponentType[i].Read<CastleHeart>().CastleTerritoryEntity;
						if (castleTerritoryEntity.Exists())
						{
							num = num2;
							result = castleTerritoryEntity.Read<CastleTerritory>().CastleTerritoryIndex;
						}
					}
				}
				return result;
			}
			finally
			{
				entitiesByComponentType.Dispose();
			}
		}

		public bool TryGetTerritory(int territoryIndex, out TerritoryInfo info, bool extras = false)
		{
			//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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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)
			info = default(TerritoryInfo);
			if (territoryIndex < 0)
			{
				return false;
			}
			NativeArray<Entity> entitiesByComponentType = Query.GetEntitiesByComponentType<CastleTerritory>(includeDisabled: true);
			try
			{
				for (int i = 0; i < entitiesByComponentType.Length; i++)
				{
					CastleTerritory val = entitiesByComponentType[i].Read<CastleTerritory>();
					if (val.CastleTerritoryIndex == territoryIndex)
					{
						info = BuildInfo(entitiesByComponentType[i], val, extras);
						return true;
					}
				}
			}
			finally
			{
				entitiesByComponentType.Dispose();
			}
			return false;
		}

		public List<TerritoryInfo> GetFreePlots()
		{
			//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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			List<TerritoryInfo> list = new List<TerritoryInfo>();
			NativeArray<Entity> entitiesByComponentType = Query.GetEntitiesByComponentType<CastleTerritory>(includeDisabled: true);
			try
			{
				for (int i = 0; i < entitiesByComponentType.Length; i++)
				{
					CastleTerritory val = entitiesByComponentType[i].Read<CastleTerritory>();
					if (!val.CastleHeart.Exists())
					{
						list.Add(BuildInfo(entitiesByComponentType[i], val));
					}
				}
			}
			finally
			{
				entitiesByComponentType.Dispose();
			}
			list.Sort((TerritoryInfo a, TerritoryInfo b) => b.SizeBlocks.CompareTo(a.SizeBlocks));
			return list;
		}

		public List<TerritoryInfo> GetAllTerritories()
		{
			//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_0018: 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)
			List<TerritoryInfo> list = new List<TerritoryInfo>();
			NativeArray<Entity> entitiesByComponentType = Query.GetEntitiesByComponentType<CastleTerritory>(includeDisabled: true);
			try
			{
				for (int i = 0; i < entitiesByComponentType.Length; i++)
				{
					list.Add(BuildInfo(entitiesByComponentType[i], entitiesByComponentType[i].Read<CastleTerritory>()));
				}
			}
			finally
			{
				entitiesByComponentType.Dispose();
			}
			list.Sort((TerritoryInfo a, TerritoryInfo b) => b.SizeBlocks.CompareTo(a.SizeBlocks));
			return list;
		}

		public List<TerritoryInfo> GetCastlesByDecay()
		{
			//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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			List<TerritoryInfo> list = new List<TerritoryInfo>();
			NativeArray<Entity> entitiesByComponentType = Query.GetEntitiesByComponentType<CastleTerritory>(includeDisabled: true);
			try
			{
				for (int i = 0; i < entitiesByComponentType.Length; i++)
				{
					CastleTerritory val = entitiesByComponentType[i].Read<CastleTerritory>();
					if (val.CastleHeart.Exists())
					{
						list.Add(BuildInfo(entitiesByComponentType[i], val));
					}
				}
			}
			finally
			{
				entitiesByComponentType.Dispose();
			}
			list.Sort(delegate(TerritoryInfo a, TerritoryInfo b)
			{
				long num = ((a.DecaySeconds < 0) ? long.MaxValue : a.DecaySeconds);
				long value = ((b.DecaySeconds < 0) ? long.MaxValue : b.DecaySeconds);
				return num.CompareTo(value);
			});
			return list;
		}

		public unsafe bool TrySummarizeResources(int territoryIndex, out ResourceSummary summary)
		{
			//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_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_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)
			//IL_0031: 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_0060: 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_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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: 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_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			summary = default(ResourceSummary);
			if (territoryIndex < 0)
			{
				return false;
			}
			Entity val = Entity.Null;
			NativeArray<Entity> entitiesByComponentType = Query.GetEntitiesByComponentType<CastleTerritory>(includeDisabled: true);
			try
			{
				for (int i = 0; i < entitiesByComponentType.Length; i++)
				{
					CastleTerritory val2 = entitiesByComponentType[i].Read<CastleTerritory>();
					if (val2.CastleTerritoryIndex == territoryIndex)
					{
						val = val2.CastleHeart;
						break;
					}
				}
			}
			finally
			{
				entitiesByComponentType.Dispose();
			}
			if (!val.Exists())
			{
				return false;
			}
			ulong ownerSteamId = 0uL;
			string ownerName = "Unknown";
			if (val.TryGetComponent<UserOwner>(out UserOwner component) && ((NetworkedEntity)(ref component.Owner)).GetEntityOnServer().TryGetComponent<User>(out User component2))
			{
				ownerSteamId = component2.PlatformId;
				ownerName = ((object)(*(FixedString64Bytes*)(&component2.CharacterName))/*cast due to .constrained prefix*/).ToString();
			}
			Dictionary<int, long> dictionary = new Dictionary<int, long>();
			int num = 0;
			long num2 = 0L;
			NativeArray<Entity> entitiesByComponentType2 = Query.GetEntitiesByComponentType<CastleHeartConnection>(includeDisabled: true);
			try
			{
				Entity val4 = default(Entity);
				for (int j = 0; j < entitiesByComponentType2.Length; j++)
				{
					Entity val3 = entitiesByComponentType2[j];
					if (!val3.TryGetComponent<CastleHeartConnection>(out CastleHeartConnection component3) || ((NetworkedEntity)(ref component3.CastleHeartEntity)).GetEntityOnServer() != val || !InventoryUtilities.TryGetInventoryEntity<EntityManager>(Core.EntityManager, val3, ref val4, 0))
					{
						continue;
					}
					EntityManager entityManager = Core.EntityManager;
					if (!((EntityManager)(ref entityManager)).HasComponent<InventoryBuffer>(val4))
					{
						continue;
					}
					entityManager = Core.EntityManager;
					DynamicBuffer<InventoryBuffer> buffer = ((EntityManager)(ref entityManager)).GetBuffer<InventoryBuffer>(val4, false);
					bool flag = false;
					for (int k = 0; k < buffer.Length; k++)
					{
						InventoryBuffer val5 = buffer[k];
						int guidHash = ((PrefabGUID)(ref val5.ItemType)).GuidHash;
						if (guidHash != 0 && val5.Amount > 0)
						{
							dictionary.TryGetValue(guidHash, out var value);
							dictionary[guidHash] = value + val5.Amount;
							num2 += val5.Amount;
							flag = true;
						}
					}
					if (flag)
					{
						num++;
					}
				}
			}
			finally
			{
				entitiesByComponentType2.Dispose();
			}
			List<(int, long, string)> list = new List<(int, long, string)>(dictionary.Count);
			foreach (KeyValuePair<int, long> item in dictionary)
			{
				list.Add((item.Key, item.Value, EntityExtensions.GetPrefabName(new PrefabGUID(item.Key))));
			}
			list.Sort(((int guid, long qty, string name) a, (int guid, long qty, string name) b) => b.qty.CompareTo(a.qty));
			List<(string, string, int)> list2 = CollectPrisoners(territoryIndex);
			summary = new ResourceSummary
			{
				TerritoryIndex = territoryIndex,
				OwnerSteamId = ownerSteamId,
				OwnerName = ownerName,
				Containers = num,
				TotalItems = num2,
				Items = list,
				Prisoners = list2.Count,
				PrisonerList = list2
			};
			return true;
		}

		private List<(string name, string bloodType, int bloodQuality)> CollectPrisoners(int territoryIndex)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_0051: Unknown result type (might be due to in