Decompiled source of Faust v0.15.0

BepInEx/plugins/Faust.dll

Decompiled 3 hours 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.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, objects, 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, or unlock. Built to run with its companion client Raphael, Lord of Wisdom. Pre-1.0 testing. Server-side only.")]
[assembly: AssemblyFileVersion("0.15.0.0")]
[assembly: AssemblyInformationalVersion("0.15.0+5301ddd2c961057a2094fb1bd35667879409d6a8")]
[assembly: AssemblyProduct("Faust")]
[assembly: AssemblyTitle("Faust")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.15.0.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 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 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();
		}

		internal static void TryInitialize(string trigger)
		{
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: 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_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: 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();
				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();
			}
			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));
		}
	}
	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.15.0")]
	[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.15.0");
					((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.15.0");
					((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();
			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.15.0";
	}
}
namespace Faust.Services
{
	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_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			List<(string, string, int)> list = new List<(string, string, int)>();
			NativeArray<Entity> val = default(NativeArray<Entity>);
			try
			{
				val = Query.GetEntitiesByComponentType<ImprisonedBuff>(includeDisabled: true);
				for (int i = 0; i < val.Length; i++)
				{
					Entity buffTarget;
					try
					{
						buffTarget = CreateGameplayEventServerUtility.GetBuffTarget(Core.EntityManager, val[i]);
					}
					catch
					{
						continue;
					}
					if (!buffTarget.Exists() || !buffTarget.Has<LocalToWorld>())
					{
						continue;
					}
					LocalToWorld val2 = buffTarget.Read<LocalToWorld>();
					if (GetTerritoryIndexAt(((LocalToWorld)(ref val2)).Position) == territoryIndex)
					{
						string item = (buffTarget.Has<PrefabGUID>() ? buffTarget.Read<PrefabGUID>().GetPrefabName() : "Prisoner");
						string item2 = "-";
						int item3 = -1;
						if (buffTarget.Has<Blood>())
						{
							Blood val3 = buffTarget.Read<Blood>();
							item2 = val3.BloodType.GetPrefabName();
							item3 = (int)Math.Round(val3.Quality);
						}
						list.Add((item, item2, item3));
					}
				}
			}
			catch (Exception ex)
			{
				if (Settings.VerboseLogging.Value)
				{
					ManualLogSource log = Core.Log;
					bool flag = default(bool);
					BepInExWarningLogInterpolatedStringHandler val4 = new BepInExWarningLogInterpolatedStringHandler(40, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("[FAUST CASTLE] CollectPrisoners failed: ");
						((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(ex.Message);
					}
					log.LogWarning(val4);
				}
			}
			finally
			{
				if (val.IsCreated)
				{
					val.Dispose();
				}
			}
			return list;
		}

		private unsafe TerritoryInfo BuildInfo(Entity territoryEntity, CastleTerritory ct, bool extras = false)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_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_003b: 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_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_0125: 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_013b: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: 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)
			//IL_019d: 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)
			int sizeBlocks = 0;
			EntityManager entityManager = Core.EntityManager;
			if (((EntityManager)(ref entityManager)).HasComponent<CastleTerritoryBlocks>(territoryEntity))
			{
				entityManager = Core.EntityManager;
				sizeBlocks = ((EntityManager)(ref entityManager)).GetBuffer<CastleTerritoryBlocks>(territoryEntity, false).Length;
			}
			string region = ResolveTerritoryRegion(territoryEntity);
			Entity castleHeart = ct.CastleHeart;
			if (!castleHeart.Exists())
			{
				return new TerritoryInfo
				{
					TerritoryIndex = ct.CastleTerritoryIndex,
					HasHeart = false,
					Region = region,
					SizeBlocks = sizeBlocks,
					State = PlotState.Unclaimed,
					DecaySeconds = 0L,
					HeartLevel = -1,
					Floors = -1,
					ClaimedUnix = -1L,
					ClanName = null,
					TotalItems = -1L
				};
			}
			CastleHeart val = castleHeart.Read<CastleHeart>();
			ulong ownerSteamId = 0uL;
			string ownerName = "Unknown";
			bool ownerOnline = false;
			long ownerLastConnected = 0L;
			Entity ownerUserEntity = Entity.Null;
			if (castleHeart.TryGetComponent<UserOwner>(out UserOwner component))
			{
				Entity entityOnServer = ((NetworkedEntity)(ref component.Owner)).GetEntityOnServer();
				if (entityOnServer.TryGetComponent<User>(out User component2))
				{
					ownerUserEntity = entityOnServer;
					ownerSteamId = component2.PlatformId;
					ownerName = ((object)(*(FixedString64Bytes*)(&component2.CharacterName))/*cast due to .constrained prefix*/).ToString();
					ownerOnline = component2.IsConnected;
					ownerLastConnected = component2.TimeLastConnected;
				}
			}
			PlotState state;
			long decaySeconds;
			if (double.IsPositiveInfinity(val.FuelEndTime))
			{
				state = PlotState.Sealed;
				decaySeconds = -1L;
			}
			else
			{
				double val2 = FuelTimeRemaining(val);
				state = ((val.FuelEndTime - Core.ServerTime > 0.0 || val.FuelQuantity > 0) ? PlotState.Fueled : PlotState.Decaying);
				decaySeconds = (long)Math.Max(0.0, val2);
			}
			int heartLevel = -1;
			int floors = -1;
			long totalItems = -1L;
			string clanName = null;
			if (extras)
			{
				ComputeHeartExtras(castleHeart, out floors, out totalItems);
				heartLevel = ResolveHeartLevel(castleHeart);
				clanName = ResolveOwnerClan(ownerUserEntity);
			}
			return new TerritoryInfo
			{
				TerritoryIndex = ct.CastleTerritoryIndex,
				HasHeart = true,
				OwnerSteamId = ownerSteamId,
				OwnerName = ownerName,
				OwnerOnline = ownerOnline,
				OwnerLastConnected = ownerLastConnected,
				Region = region,
				SizeBlocks = sizeBlocks,
				State = state,
				DecaySeconds = decaySeconds,
				HeartLevel = heartLevel,
				Floors = floors,
				ClaimedUnix = -1L,
				ClanName = clanName,
				TotalItems = totalItems
			};
		}

		private void ComputeHeartExtras(Entity heart, out int floors, out long totalItems)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Expected O, but got Unknown
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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_00b1: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			floors = -1;
			totalItems = -1L;
			try
			{
				HashSet<int> hashSet = new HashSet<int>();
				long num = 0L;
				bool flag = false;
				NativeArray<Entity> entitiesByComponentType = Query.GetEntitiesByComponentType<CastleHeartConnection>(includeDisabled: true);
				try
				{
					Entity val3 = default(Entity);
					for (int i = 0; i < entitiesByComponentType.Length; i++)
					{
						Entity val = entitiesByComponentType[i];
						if (!val.TryGetComponent<CastleHeartConnection>(out CastleHeartConnection component) || ((NetworkedEntity)(ref component.CastleHeartEntity)).GetEntityOnServer() != heart)
						{
							continue;
						}
						if (val.Has<CastleFloor>() && val.Has<LocalToWorld>())
						{
							LocalToWorld val2 = val.Read<LocalToWorld>();
							hashSet.Add((int)math.round(((LocalToWorld)(ref val2)).Position.y));
						}
						if (!InventoryUtilities.TryGetInventoryEntity<EntityManager>(Core.EntityManager, val, ref val3, 0))
						{
							continue;
						}
						EntityManager entityManager = Core.EntityManager;
						if (!((EntityManager)(ref entityManager)).HasComponent<InventoryBuffer>(val3))
						{
							continue;
						}
						flag = true;
						entityManager = Core.EntityManager;
						DynamicBuffer<InventoryBuffer> buffer = ((EntityManager)(ref entityManager)).GetBuffer<InventoryBuffer>(val3, false);
						for (int j = 0; j < buffer.Length; j++)
						{
							InventoryBuffer val4 = buffer[j];
							if (((PrefabGUID)(ref val4.ItemType)).GuidHash != 0 && val4.Amount > 0)
							{
								num += val4.Amount;
							}
						}
					}
				}
				finally
				{
					entitiesByComponentType.Dispose();
				}
				if (hashSet.Count > 0)
				{
					floors = hashSet.Count;
				}
				if (flag)
				{
					totalItems = num;
				}
			}
			catch (Exception ex)
			{
				if (Settings.VerboseLogging.Value)
				{
					ManualLogSource log = Core.Log;
					bool flag2 = default(bool);
					BepInExWarningLogInterpolatedStringHandler val5 = new BepInExWarningLogInterpolatedStringHandler(42, 1, ref flag2);
					if (flag2)
					{
						((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("[FAUST CASTLE] ComputeHeartExtras failed: ");
						((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(ex.Message);
					}
					log.LogWarning(val5);
				}
			}
		}

		private int ResolveHeartLevel(Entity heart)
		{
			return -1;
		}

		private unsafe string ResolveOwnerClan(Entity ownerUserEntity)
		{
			//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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!ownerUserEntity.Exists() || !ownerUserEntity.TryGetComponent<User>(out User component))
				{
					return null;
				}
				ref NetworkedEntity clanEntity = ref component.ClanEntity;
				object obj = NetworkedEntity.Empty;
				if (((object)Unsafe.As<NetworkedEntity, NetworkedEntity>(ref clanEntity)/*cast due to .constrained prefix*/).Equals(obj))
				{
					return null;
				}
				Entity entityOnServer = ((NetworkedEntity)(ref component.ClanEntity)).GetEntityOnServer();
				if (entityOnServer.Exists() && entityOnServer.Has<ClanTeam>())
				{
					ClanTeam val = entityOnServer.Read<ClanTeam>();
					string text = ((object)(*(FixedString64Bytes*)(&val.Name))/*cast due to .constrained prefix*/).ToString();
					return string.IsNullOrWhiteSpace(text) ? null : text;
				}
			}
			catch (Exception ex)
			{
				if (Settings.VerboseLogging.Value)
				{
					ManualLogSource log = Core.Log;
					bool flag = default(bool);
					BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(40, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[FAUST CASTLE] ResolveOwnerClan failed: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
					}
					log.LogWarning(val2);
				}
			}
			return null;
		}

		private static double FuelTimeRemaining(CastleHeart ch)
		{
			//IL_0031: 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)
			float num = Mathf.Min(Core.ServerGameSettingsSystem.Settings.CastleBloodEssenceDrainModifier, 3f);
			if (num <= 0f)
			{
				num = 1f;
			}
			double num2 = 480f / num;
			return ch.FuelEndTime - Core.ServerTime + num2 * (double)ch.FuelQuantity;
		}

		public unsafe static string RegionName(WorldRegionType region)
		{
			return Regex.Replace(((object)(*(WorldRegionType*)(&region))/*cast due to .constrained prefix*/).ToString().Replace("_", ""), "(?<!^)([A-Z])", " $1");
		}

		public static string StateWire(PlotState s)
		{
			return s switch
			{
				PlotState.Sealed => "sealed", 
				PlotState.Fueled => "fueled", 
				PlotState.Decaying => "decaying", 
				_ => "unclaimed", 
			};
		}
	}
	internal sealed class ClanService
	{
		public readonly struct ClanInfo
		{
			public string Name { get; init; }

			public int Members { get; init; }

			public int Online { get; init; }

			public int Castles { get; init; }

			public string Leader { get; init; }
		}

		public readonly struct Composition
		{
			public int Clans { get; init; }

			public int Clanned { get; init; }

			public int Independent { get; init; }

			public int OnlineClanned { get; init; }

			public int OnlineIndependent { get; init; }

			public int Largest { get; init; }

			public double AvgSize { get; init; }

			public List<ClanInfo> ClanList { get; init; }
		}

		public readonly struct ClanMember
		{
			public string Name { get; init; }

			public bool Online { get; init; }

			public bool Leader { get; init; }
		}

		public unsafe List<ClanMember> GetClanMembers(string name)
		{
			//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_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_002e: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Invalid comparison between Unknown and I4
			//IL_00fb: 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_0122: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrWhiteSpace(name))
			{
				return null;
			}
			List<ClanMember> result = null;
			NativeArray<Entity> entitiesByComponentType = Query.GetEntitiesByComponentType<ClanTeam>(includeDisabled: true);
			try
			{
				for (int i = 0; i < entitiesByComponentType.Length; i++)
				{
					Entity val = entitiesByComponentType[i];
					EntityManager entityManager = Core.EntityManager;
					if (!((EntityManager)(ref entityManager)).HasComponent<ClanMemberStatus>(val))
					{
						continue;
					}
					ClanTeam val2 = val.Read<ClanTeam>();
					string text = ((object)(*(FixedString64Bytes*)(&val2.Name))/*cast due to .constrained prefix*/).ToString();
					if (!string.Equals(text, name, StringComparison.OrdinalIgnoreCase) && !string.Equals(Wire.Safe(text), name, StringComparison.OrdinalIgnoreCase))
					{
						continue;
					}
					entityManager = Core.EntityManager;
					DynamicBuffer<ClanMemberStatus> buffer = ((EntityManager)(ref entityManager)).GetBuffer<ClanMemberStatus>(val, false);
					entityManager = Core.EntityManager;
					? val3;
					if (!((EntityManager)(ref entityManager)).HasComponent<SyncToUserBuffer>(val))
					{
						val3 = default(DynamicBuffer<SyncToUserBuffer>);
					}
					else
					{
						entityManager = Core.EntityManager;
						val3 = ((EntityManager)(ref entityManager)).GetBuffer<SyncToUserBuffer>(val, false);
					}
					DynamicBuffer<SyncToUserBuffer> val4 = (DynamicBuffer<SyncToUserBuffer>)val3;
					List<ClanMember> list = new List<ClanMember>(buffer.Length);
					for (int j = 0; j < buffer.Length; j++)
					{
						bool leader = (int)buffer[j].ClanRole == 2;
						string name2 = null;
						bool online = false;
						if (val4.IsCreated && j < val4.Length && val4[j].UserEntity.TryGetComponent<User>(out User component))
						{
							name2 = ((object)(*(FixedString64Bytes*)(&component.CharacterName))/*cast due to .constrained prefix*/).ToString();
							online = component.IsConnected;
						}
						list.Add(new ClanMember
						{
							Name = name2,
							Online = online,
							Leader = leader
						});
					}
					list.Sort(delegate(ClanMember a, ClanMember b)
					{
						if (a.Leader != b.Leader)
						{
							if (!a.Leader)
							{
								return 1;
							}
							return -1;
						}
						return (a.Online != b.Online) ? ((!a.Online) ? 1 : (-1)) : string.Compare(a.Name, b.Name, StringComparison.OrdinalIgnoreCase);
					});
					result = list;
					break;
				}
			}
			finally
			{
				entitiesByComponentType.Dispose();
			}
			return result;
		}

		public unsafe Dictionary<ulong, string> GetPlayerClanNames()
		{
			//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_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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<ulong, string> dictionary = new Dictionary<ulong, string>();
			NativeArray<Entity> entitiesByComponentType = Query.GetEntitiesByComponentType<ClanTeam>(includeDisabled: true);
			try
			{
				for (int i = 0; i < entitiesByComponentType.Length; i++)
				{
					Entity val = entitiesByComponentType[i];
					EntityManager entityManager = Core.EntityManager;
					if (!((EntityManager)(ref entityManager)).HasComponent<ClanMemberStatus>(val))
					{
						continue;
					}
					entityManager = Core.EntityManager;
					if (!((EntityManager)(ref entityManager)).HasComponent<SyncToUserBuffer>(val))
					{
						continue;
					}
					ClanTeam val2 = val.Read<ClanTeam>();
					string value = ((object)(*(FixedString64Bytes*)(&val2.Name))/*cast due to .constrained prefix*/).ToString();
					entityManager = Core.EntityManager;
					DynamicBuffer<SyncToUserBuffer> buffer = ((EntityManager)(ref entityManager)).GetBuffer<SyncToUserBuffer>(val, false);
					for (int j = 0; j < buffer.Length; j++)
					{
						if (buffer[j].UserEntity.TryGetComponent<User>(out User component))
						{
							dictionary[component.PlatformId] = value;
						}
					}
				}
				return dictionary;
			}
			finally
			{
				entitiesByComponentType.Dispose();
			}
		}

		public unsafe Composition GetComposition()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: 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_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: 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_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Invalid comparison between Unknown and I4
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 0;
			NativeArray<Entity> entitiesByComponentType = Query.GetEntitiesByComponentType<User>(includeDisabled: true);
			try
			{
				for (int i = 0; i < entitiesByComponentType.Length; i++)
				{
					if (!entitiesByComponentType[i].TryGetComponent<User>(out User component))
					{
						continue;
					}
					ref NetworkedEntity clanEntity = ref component.ClanEntity;
					object obj = NetworkedEntity.Empty;
					if (((object)Unsafe.As<NetworkedEntity, NetworkedEntity>(ref clanEntity)/*cast due to .constrained prefix*/).Equals(obj))
					{
						num2++;
						if (component.IsConnected)
						{
							num4++;
						}
					}
					else
					{
						num++;
						if (component.IsConnected)
						{
							num3++;
						}
					}
				}
			}
			finally
			{
				entitiesByComponentType.Dispose();
			}
			Dictionary<int, int> dictionary = new Dictionary<int, int>();
			NativeArray<Entity> entitiesByComponentType2 = Query.GetEntitiesByComponentType<CastleHeart>(includeDisabled: true);
			try
			{
				for (int j = 0; j < entitiesByComponentType2.Length; j++)
				{
					if (entitiesByComponentType2[j].TryGetComponent<Team>(out Team component2))
					{
						dictionary.TryGetValue(component2.Value, out var value);
						dictionary[component2.Value] = value + 1;
					}
				}
			}
			finally
			{
				entitiesByComponentType2.Dispose();
			}
			List<ClanInfo> list = new List<ClanInfo>();
			int num5 = 0;
			NativeArray<Entity> entitiesByComponentType3 = Query.GetEntitiesByComponentType<ClanTeam>(includeDisabled: true);
			try
			{
				for (int k = 0; k < entitiesByComponentType3.Length; k++)
				{
					Entity val = entitiesByComponentType3[k];
					EntityManager entityManager = Core.EntityManager;
					if (!((EntityManager)(ref entityManager)).HasComponent<ClanMemberStatus>(val))
					{
						continue;
					}
					entityManager = Core.EntityManager;
					DynamicBuffer<ClanMemberStatus> buffer = ((EntityManager)(ref entityManager)).GetBuffer<ClanMemberStatus>(val, false);
					if (buffer.Length == 0)
					{
						continue;
					}
					entityManager = Core.EntityManager;
					? val2;
					if (!((EntityManager)(ref entityManager)).HasComponent<SyncToUserBuffer>(val))
					{
						val2 = default(DynamicBuffer<SyncToUserBuffer>);
					}
					else
					{
						entityManager = Core.EntityManager;
						val2 = ((EntityManager)(ref entityManager)).GetBuffer<SyncToUserBuffer>(val, false);
					}
					DynamicBuffer<SyncToUserBuffer> val3 = (DynamicBuffer<SyncToUserBuffer>)val2;
					int num6 = 0;
					string leader = "";
					for (int l = 0; l < buffer.Length; l++)
					{
						if (val3.IsCreated && l < val3.Length && val3[l].UserEntity.TryGetComponent<User>(out User component3))
						{
							if (component3.IsConnected)
							{
								num6++;
							}
							if ((int)buffer[l].ClanRole == 2)
							{
								leader = ((object)(*(FixedString64Bytes*)(&component3.CharacterName))/*cast due to .constrained prefix*/).ToString();
							}
						}
					}
					int value2;
					int castles = (dictionary.TryGetValue(val.Read<ClanTeam>().TeamValue, out value2) ? value2 : 0);
					ClanInfo item = default(ClanInfo);
					ClanTeam val4 = val.Read<ClanTeam>();
					item.Name = ((object)(*(FixedString64Bytes*)(&val4.Name))/*cast due to .constrained prefix*/).ToString();
					item.Members = buffer.Length;
					item.Online = num6;
					item.Castles = castles;
					item.Leader = leader;
					list.Add(item);
					if (buffer.Length > num5)
					{
						num5 = buffer.Length;
					}
				}
			}
			finally
			{
				entitiesByComponentType3.Dispose();
			}
			list.Sort((ClanInfo a, ClanInfo b) => b.Members.CompareTo(a.Members));
			return new Composition
			{
				Clans = list.Count,
				Clanned = num,
				Independent = num2,
				OnlineClanned = num3,
				OnlineIndependent = num4,
				Largest = num5,
				AvgSize = ((list.Count == 0) ? 0.0 : ((double)num / (double)list.Count)),
				ClanList = list
			};
		}
	}
	internal static class FaustAccessGate
	{
		internal readonly struct GateResult
		{
			public bool Allowed { get; init; }

			public string DenyWire { get; init; }

			public FeatureConfig Feature { get; init; }

			public bool CostOwed { get; init; }

			public static GateResult Deny(string wire)
			{
				return new GateResult
				{
					Allowed = false,
					DenyWire = wire
				};
			}

			public static GateResult Allow(FeatureConfig f, bool costOwed)
			{
				return new GateResult
				{
					Allowed = true,
					Feature = f,
					CostOwed = costOwed
				};
			}
		}

		private static readonly Dictionary<ulong, double> _lastQuery = new Dictionary<ulong, double>();

		private static double NowSeconds => (double)DateTime.UtcNow.Ticks / 10000000.0;

		public static GateResult TryAuthorize(ChatCommandContext ctx, string featureKey, bool bypassAccess = false)
		{
			//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_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			if (!Core.IsReady)
			{
				return GateResult.Deny("[FAUST:err] code=notready");
			}
			if (!Settings.Enabled.Value)
			{
				return GateResult.Deny("[FAUST:err] code=disabled feature=" + featureKey);
			}
			FeatureConfig featureConfig = Settings.Feature(featureKey);
			if (featureConfig == null)
			{
				return GateResult.Deny("[FAUST:err] code=disabled feature=" + featureKey);
			}
			if (!Core.Control.IsAvailable(featureKey, out var code, out var secsLeft))
			{
				return GateResult.Deny($"[FAUST:err] code={code} feature={featureKey} secs={secsLeft}");
			}
			if (featureConfig.Access == AccessLevel.Off)
			{
				return GateResult.Deny("[FAUST:err] code=disabled feature=" + featureKey);
			}
			User user = ctx.Event.User;
			bool isAdmin = user.IsAdmin;
			bool flag = isAdmin && featureConfig.AdminsExempt.Value;
			if (Settings.RateLimitSeconds.Value > 0 && (!isAdmin || !Settings.RateLimitAdminsExempt.Value))
			{
				double nowSeconds = NowSeconds;
				if (_lastQuery.TryGetValue(user.PlatformId, out var value))
				{
					double num = (double)Settings.RateLimitSeconds.Value - (nowSeconds - value);
					if (num > 0.0)
					{
						return GateResult.Deny($"[FAUST:err] code=ratelimit feature={featureKey} secs={(int)Math.Ceiling(num)}");
					}
				}
				_lastQuery[user.PlatformId] = nowSeconds;
			}
			if (!flag && !bypassAccess && !Core.Unlock.IsUnlocked(user.PlatformId, featureConfig, out var need))
			{
				return GateResult.Deny("[FAUST:err] code=locked feature=" + featureKey + " need=" + need);
			}
			if (!bypassAccess && !flag && featureConfig.Access == AccessLevel.AdminOnly && !isAdmin)
			{
				return GateResult.Deny("[FAUST:err] code=noaccess feature=" + featureKey);
			}
			if (!flag && !PvpAllowed(featureConfig))
			{
				return GateResult.Deny("[FAUST:err] code=pvp feature=" + featureKey);
			}
			if (!flag && featureConfig.HasProximity && !Proximity.PlayerNear(ctx.Event.SenderCharacterEntity, featureConfig.RequireNearPrefab.Value, featureConfig.RequireNearDistance.Value))
			{
				string value2 = featureConfig.RequireNearDistance.Value.ToString("0.#", CultureInfo.InvariantCulture);
				return GateResult.Deny($"[FAUST:err] code=notnear feature={featureKey} item={featureConfig.RequireNearPrefab.Value} dist={value2}");
			}
			if (!flag && !Core.Usage.Check(user.PlatformId, featureConfig, out var denyCode, out var secsLeft2))
			{
				Core.UsageStats?.RecordCooldownHit(featureKey);
				return GateResult.Deny($"[FAUST:err] code={denyCode} feature={featureKey} secs={secsLeft2}");
			}
			bool flag2 = !flag && featureConfig.HasCost;
			if (flag2 && !RequesterHasItem(ctx, featureConfig))
			{
				return GateResult.Deny($"[FAUST:err] code=cost feature={featureKey} item={featureConfig.CostItemGuid.Value} qty={featureConfig.CostQuantity.Value}");
			}
			return GateResult.Allow(featureConfig, flag2);
		}

		public static void Commit(ChatCommandContext ctx, GateResult gate)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_00ae: Expected O, but got Unknown
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			if (!gate.Allowed || gate.Feature == null)
			{
				return;
			}
			User user = ctx.Event.User;
			Core.Usage.Record(user.PlatformId, gate.Feature);
			if (gate.CostOwed)
			{
				ConsumeItem(ctx, gate.Feature);
			}
			Core.UsageStats?.RecordUse(gate.Feature.Key, user.PlatformId, gate.CostOwed, gate.CostOwed ? gate.Feature.CostQuantity.Value : 0);
			if (Settings.AuditQueries.Value)
			{
				ManualLogSource log = Core.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(38, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FAUST AUDIT] steamId=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ulong>(user.PlatformId);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ran '");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(gate.Feature.Key);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' charged=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(gate.CostOwed);
				}
				log.LogInfo(val);
			}
		}

		private static bool RequesterHasItem(ChatCommandContext ctx, FeatureConfig f)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_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)
			Entity senderCharacterEntity = ctx.Event.SenderCharacterEntity;
			Entity val = default(Entity);
			if (!InventoryUtilities.TryGetInventoryEntity<EntityManager>(Core.EntityManager, senderCharacterEntity, ref val, 0))
			{
				return false;
			}
			ServerGameManager serverGameManager = Core.ServerGameManager;
			return ((ServerGameManager)(ref serverGameManager)).GetInventoryItemCount(val, new PrefabGUID(f.CostItemGuid.Value)) >= f.CostQuantity.Value;
		}

		private static void ConsumeItem(ChatCommandContext ctx, FeatureConfig f)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			Entity senderCharacterEntity = ctx.Event.SenderCharacterEntity;
			Entity val = default(Entity);
			if (InventoryUtilities.TryGetInventoryEntity<EntityManager>(Core.EntityManager, senderCharacterEntity, ref val, 0))
			{
				ServerGameManager serverGameManager = Core.ServerGameManager;
				((ServerGameManager)(ref serverGameManager)).TryRemoveInventoryItem(val, new PrefabGUID(f.CostItemGuid.Val