Decompiled source of PrisonerExchange v1.0.6

PrisonerExchange.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Timers;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppSystem.Text;
using Microsoft.CodeAnalysis;
using MortiumGames.Utils;
using PrisonerExchange;
using PrisonerExchange.Data;
using PrisonerExchange.Extensions;
using PrisonerExchange.Models;
using PrisonerExchange.Services;
using PrisonerExchange.Services.Chat;
using PrisonerExchange.Utility;
using ProjectM;
using ProjectM.Behaviours;
using ProjectM.Network;
using ProjectM.Scripting;
using ProjectM.Sequencer;
using ProjectM.Shared;
using Stunlock.Core;
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("PrisonerExchange")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.7.0")]
[assembly: AssemblyInformationalVersion("1.0.7+1.Branch.master.Sha.5971a3d38c0fd3ab782224f1860c5d31c8a932e2.5971a3d38c0fd3ab782224f1860c5d31c8a932e2")]
[assembly: AssemblyProduct("PrisonerExchange")]
[assembly: AssemblyTitle("PrisonerExchange")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.7.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
internal static class Core
{
	private static ServerScriptMapper serverScriptMapper;

	private static bool hasInitialized;

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


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


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


	public static DebugEventsSystem DebugEventsSystem { get; internal set; }

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

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


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

	public static void Initialize()
	{
		if (!hasInitialized)
		{
			DebugEventsSystem = Server.GetExistingSystemManaged<DebugEventsSystem>();
			hasInitialized = true;
		}
	}

	private static World? GetWorld()
	{
		Enumerator<World> enumerator = World.s_AllWorlds.GetEnumerator();
		while (enumerator.MoveNext())
		{
			World current = enumerator.Current;
			if (current.Name == "Server")
			{
				return current;
			}
		}
		return null;
	}
}
namespace MortiumGames.Utils
{
	public static class SequenceUtils
	{
		public static readonly SequenceGUID Smite = new SequenceGUID(-243689524);

		public static void SpawnSequence(Entity target, SequenceGUID guid, int lifetime)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			float3 value = target.Read<Translation>().Value;
			Entity val = default(Entity);
			if (!Core.PrefabCollection._PrefabGuidToEntityMap.TryGetValue(new PrefabGUID(651179295), ref val))
			{
				Plugin.Logger.Error("SequenceUtil", "PrefabEntity not found!");
				return;
			}
			EntityManager entityManager = Core.EntityManager;
			Entity entity = ((EntityManager)(ref entityManager)).Instantiate(val);
			entity.Add<PhysicsCustomTags>();
			entity.Write<Translation>(new Translation
			{
				Value = value
			});
			entity.HasWith<SpawnSequenceForEntity>((Ecs.WithRefHandler<SpawnSequenceForEntity>)delegate(ref SpawnSequenceForEntity ss)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				//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_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				ss.SequenceGuid = guid;
				ss.Target = NetworkedEntity.op_Implicit(target);
				ss.SecondaryTarget = NetworkedEntity.op_Implicit(Entity.Null);
			});
			entity.HasWith<LifeTime>((Ecs.WithRefHandler<LifeTime>)delegate(ref LifeTime lf)
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				lf.Duration = lifetime;
				lf.EndAction = (LifeTimeEndAction)2;
			});
		}
	}
}
namespace PrisonerExchange
{
	internal class Configuration
	{
		internal static bool SellingEnabled { get; private set; }

		internal static bool SwappingEnabled { get; private set; }

		internal static bool AnnounceExchange { get; private set; }

		internal static string? CurrencyPrefab { get; private set; }

		internal static string? CurrencyName { get; private set; }

		internal static int MinimumSalePrice { get; private set; }

		internal static int MaximumSalePrice { get; private set; }

		internal static bool ClanLeaderOnly { get; private set; }

		internal static int CommandCoolDownPeriod { get; private set; }

		internal static int ExpireExchangeAfter { get; private set; }

		internal static void Initialize(ConfigFile config)
		{
			SellingEnabled = config.Bind<bool>("General", "SellingEnabled", true, "Enable or disable the ability to sell prisoners.").Value;
			SwappingEnabled = config.Bind<bool>("General", "SwappingEnabled", true, "Enable or disable the ability to swap prisoners.").Value;
			AnnounceExchange = config.Bind<bool>("General", "AnnounceExchange", true, "Announce completed sales in global chat.").Value;
			CurrencyPrefab = config.Bind<string>("General", "CurrencyPrefab", "-257494203", "Prefab GUID for the currency. (Crystals by default)").Value;
			CurrencyName = config.Bind<string>("General", "CurrencyName", "Crystals", "Name of currency.").Value;
			MinimumSalePrice = config.Bind<int>("General", "MinimumSalePrice", 100, "Set the minimum amount of currency required for a sale.").Value;
			MaximumSalePrice = config.Bind<int>("General", "MaximumSalePrice", 5000, "Set the maximum amount of currency allowed for a sale.").Value;
			ClanLeaderOnly = config.Bind<bool>("General", "ClanLeaderOnly", false, "Only allow clan leader to sell prisoners.").Value;
			CommandCoolDownPeriod = config.Bind<int>("General", "CommandCoolDownPeriod", 5, "Adds a fixed cooldown period for selling/swapping prisoners (minutes).").Value;
			ExpireExchangeAfter = config.Bind<int>("General", "ExpireExchangeAfter", 60, "Automatically expire sales and swap requests. (seconds)").Value;
		}
	}
	internal static class Markup
	{
		public const string HighlightColor = "#def";

		public const string SecondaryColor = "#dda";

		public static string Prefix = Format.Bold(Format.Color("[PE] ", "#ed1"));

		public static string Highlight(int i)
		{
			return Highlight(i.ToString());
		}

		public static string Highlight(string s)
		{
			return Format.Color(Format.Bold(s), "#def");
		}

		public static string Secondary(int i)
		{
			return Secondary(i.ToString());
		}

		public static string Secondary(string s)
		{
			return Format.Color(Format.Bold(s), "#dda");
		}
	}
	[BepInPlugin("PrisonerExchange", "PrisonerExchange", "1.0.7")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		public static ManualLogSource Logger;

		private static Harmony _harmony;

		public static Harmony Harmony => _harmony;

		internal static Plugin Instance { get; private set; }

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

		public void OnGameInitialized()
		{
			if (!WorldUtility.IsServerWorld(Core.Server))
			{
				Logger.Error("EntryPoint", "Plugin is not running on a server world!");
			}
			else
			{
				Core.Initialize();
			}
		}

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

		public const string PLUGIN_NAME = "PrisonerExchange";

		public const string PLUGIN_VERSION = "1.0.7";
	}
}
namespace PrisonerExchange.Utility
{
	public static class BuffUtil
	{
		private static readonly EntityManager Em = Core.EntityManager;

		public static PrefabGUID _electricBuff = new PrefabGUID(1237097606);

		private const int NoDuration = 0;

		private const int DefaultDuration = -1;

		public static bool BuffNpc(Entity character, Entity user, PrefabGUID buff, int duration = -1)
		{
			//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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: 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_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: 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_010d: Unknown result type (might be due to invalid IL or missing references)
			if (Core.DebugEventsSystem == null)
			{
				Core.DebugEventsSystem = Core.Server.GetExistingSystemManaged<DebugEventsSystem>();
			}
			ApplyBuffDebugEvent val = default(ApplyBuffDebugEvent);
			val.BuffPrefabGUID = buff;
			ApplyBuffDebugEvent val2 = val;
			FromCharacter val3 = default(FromCharacter);
			val3.User = user;
			val3.Character = character;
			FromCharacter val4 = val3;
			Entity entity = default(Entity);
			if (!BuffUtility.TryGetBuff<EntityManager>(Em, character, PrefabIdentifier.op_Implicit(buff), ref entity))
			{
				Core.DebugEventsSystem.ApplyBuff(val4, val2);
				if (!BuffUtility.TryGetBuff<EntityManager>(Em, character, PrefabIdentifier.op_Implicit(buff), ref entity))
				{
					Plugin.Logger.Info("BuffUtil", $"Failed to apply buff {((PrefabGUID)(ref buff)).GuidHash} to entity {character.Index}.");
					return false;
				}
				entity.TryRemoveComponent<CreateGameplayEventsOnSpawn>();
				entity.TryRemoveComponent<GameplayEventListeners>();
				if (duration > 0 && duration != -1)
				{
					if (entity.Has<LifeTime>())
					{
						LifeTime data = entity.Read<LifeTime>();
						data.Duration = duration;
						entity.Write<LifeTime>(data);
					}
				}
				else if (duration == 0)
				{
					if (entity.Has<LifeTime>())
					{
						LifeTime data2 = entity.Read<LifeTime>();
						data2.Duration = -1f;
						data2.EndAction = (LifeTimeEndAction)0;
						entity.Write<LifeTime>(data2);
					}
					entity.TryRemoveComponent<RemoveBuffOnGameplayEvent>();
					entity.TryRemoveComponent<RemoveBuffOnGameplayEventEntry>();
				}
				Plugin.Logger.Info("BuffUtil", $"Successfully applied buff {((PrefabGUID)(ref buff)).GuidHash} to entity {character.Index}.");
				return true;
			}
			Plugin.Logger.Info("BuffUtil", $"Buff {((PrefabGUID)(ref buff)).GuidHash} is already present on entity {character.Index}.");
			return false;
		}

		public static bool RemoveBuff(Entity character, PrefabGUID buff)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			Entity val = default(Entity);
			if (BuffUtility.TryGetBuff<EntityManager>(Em, character, PrefabIdentifier.op_Implicit(buff), ref val))
			{
				DestroyUtility.Destroy(Em, val, (DestroyDebugReason)13, (string)null, 0);
				Plugin.Logger.Info("BuffUtil", $"Successfully removed buff {((PrefabGUID)(ref buff)).GuidHash} from entity {character.Index}.");
				return true;
			}
			Plugin.Logger.Info("BuffUtil", $"Successfully removed buff {((PrefabGUID)(ref buff)).GuidHash} from entity {character.Index}.");
			return false;
		}
	}
	public static class DebugUtils
	{
		public static void ExploreEntity(Entity entity)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			StringBuilder val = new StringBuilder();
			EntityDebuggingUtility.DumpEntity(Core.Server, entity, true, val);
			Plugin.Logger.LogInfo((object)((Object)val).ToString());
		}
	}
	public static class EntityUtil
	{
		public static Entity FindClosestInRadius<T>(Entity player, float radius)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			float3 val = float3.zero;
			if (player.TryGetComponent<LocalToWorld>(out LocalToWorld component))
			{
				val = ((LocalToWorld)(ref component)).Position;
			}
			EntityManager entityManager = Core.EntityManager;
			EntityQuery val2 = ((EntityManager)(ref entityManager)).CreateEntityQuery((ComponentType[])(object)new ComponentType[2]
			{
				ComponentType.ReadOnly<T>(),
				ComponentType.ReadOnly<LocalToWorld>()
			});
			NativeArray<Entity> val3 = ((EntityQuery)(ref val2)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			Entity result = Entity.Null;
			float num = radius * radius;
			try
			{
				Enumerator<Entity> enumerator = val3.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					entityManager = Core.EntityManager;
					LocalToWorld componentData = ((EntityManager)(ref entityManager)).GetComponentData<LocalToWorld>(current);
					float3 position = ((LocalToWorld)(ref componentData)).Position;
					float num2 = math.distancesq(val, position);
					if (num2 < num)
					{
						num = num2;
						result = current;
					}
				}
				return result;
			}
			finally
			{
				val3.Dispose();
			}
		}

		public static NativeArray<Entity> GetEntitiesByComponentType<T1>(bool includeAll = false, bool includeDisabled = false, bool includeSpawn = false, bool includePrefab = false, bool includeDestroyed = false)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			EntityQueryOptions val = (EntityQueryOptions)0;
			if (includeAll)
			{
				val = (EntityQueryOptions)(val | 0xC3);
			}
			if (includeDisabled)
			{
				val = (EntityQueryOptions)(val | 2);
			}
			if (includeSpawn)
			{
				val = (EntityQueryOptions)(val | 0x40);
			}
			if (includePrefab)
			{
				val = (EntityQueryOptions)(val | 1);
			}
			if (includeDestroyed)
			{
				val = (EntityQueryOptions)(val | 0x80);
			}
			EntityQueryDesc val2 = new EntityQueryDesc();
			val2.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[1]
			{
				new ComponentType(Il2CppType.Of<T1>(), (AccessMode)0)
			});
			val2.Options = val;
			EntityQueryDesc val3 = val2;
			EntityManager entityManager = Core.EntityManager;
			EntityQuery val4 = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)new EntityQueryDesc[1] { val3 });
			return ((EntityQuery)(ref val4)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
		}

		public static NativeArray<Entity> GetEntitiesByComponentTypes<T1, T2>(bool includeAll = false, bool includeDisabled = false, bool includeSpawn = false, bool includePrefab = false, bool includeDestroyed = false)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			EntityQueryOptions val = (EntityQueryOptions)0;
			if (includeAll)
			{
				val = (EntityQueryOptions)(val | 0xC3);
			}
			if (includeDisabled)
			{
				val = (EntityQueryOptions)(val | 2);
			}
			if (includeSpawn)
			{
				val = (EntityQueryOptions)(val | 0x40);
			}
			if (includePrefab)
			{
				val = (EntityQueryOptions)(val | 1);
			}
			if (includeDestroyed)
			{
				val = (EntityQueryOptions)(val | 0x80);
			}
			EntityQueryDesc val2 = new EntityQueryDesc();
			val2.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[2]
			{
				new ComponentType(Il2CppType.Of<T1>(), (AccessMode)0),
				new ComponentType(Il2CppType.Of<T2>(), (AccessMode)0)
			});
			val2.Options = val;
			EntityQueryDesc val3 = val2;
			EntityManager entityManager = Core.EntityManager;
			EntityQuery val4 = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)new EntityQueryDesc[1] { val3 });
			return ((EntityQuery)(ref val4)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
		}
	}
	public static class UserUtil
	{
		private static UserModel[] All
		{
			get
			{
				//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_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_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0054: Unknown result type (might be due to invalid IL or missing references)
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_0059: Unknown result type (might be due to invalid IL or missing references)
				//IL_005e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				EntityManager entityManager = Core.EntityManager;
				EntityQuery val = ((EntityManager)(ref entityManager)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<User>() });
				NativeArray<Entity> val2 = ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
				List<UserModel> list = new List<UserModel>(val2.Length);
				Enumerator<Entity> enumerator = val2.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					entityManager = Core.EntityManager;
					User componentData = ((EntityManager)(ref entityManager)).GetComponentData<User>(current);
					UserModel item = new UserModel(current, componentData);
					list.Add(item);
				}
				val2.Dispose();
				int num = 0;
				UserModel[] array = new UserModel[list.Count];
				foreach (UserModel item2 in list)
				{
					array[num] = item2;
					num++;
				}
				return array;
			}
		}

		public static UserModel GetCurrentUser(ChatCommandContext ctx)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return GetUserByPlatformId(ctx.User.PlatformId);
		}

		public static UserModel ToUserModel(Entity userEntity)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			EntityManager entityManager = Core.EntityManager;
			User componentData = ((EntityManager)(ref entityManager)).GetComponentData<User>(userEntity);
			return new UserModel(userEntity, componentData);
		}

		private static UserModel GetUserByPlatformId(ulong platformId)
		{
			return All.FirstOrDefault((UserModel u) => u.PlatformId == platformId);
		}

		public static UserModel GetUserByCharacterName(string characterName)
		{
			string characterName2 = characterName;
			if (string.IsNullOrEmpty(characterName2))
			{
				return null;
			}
			return All.FirstOrDefault((UserModel u) => u.CharacterName.Equals(characterName2, StringComparison.OrdinalIgnoreCase));
		}
	}
}
namespace PrisonerExchange.Services
{
	public static class InventoryService
	{
		private static readonly PrefabGUID CurrencyPrefab = new PrefabGUID(int.Parse(Configuration.CurrencyPrefab));

		private static AddItemResponse TryAddUserInventoryItem(Entity characterEntity, PrefabGUID itemGuid, int stacks)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			ServerGameManager serverGameManager = Core.ServerGameManager;
			return ((ServerGameManager)(ref serverGameManager)).TryAddInventoryItem(characterEntity, itemGuid, stacks);
		}

		public static bool AddCurrencyToInventory(UserModel user, int amount)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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_0027: 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)
			AddItemResponse val = TryAddUserInventoryItem(user.User.LocalCharacter._Entity, CurrencyPrefab, amount);
			if (((AddItemResponse)(ref val)).Success)
			{
				return true;
			}
			if (val.RemainingAmount > 0)
			{
				Plugin.Logger.Error("InventoryService", $"{user.CharacterName} only had space for {amount - val.RemainingAmount} {Configuration.CurrencyName}.");
			}
			return false;
		}

		public static bool RemoveCurrencyFromInventory(UserModel user, int amount)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			Entity entity = user.User.LocalCharacter._Entity;
			if (InventoryUtilitiesServer.TryRemoveItem(Core.EntityManager, entity, CurrencyPrefab, amount))
			{
				return true;
			}
			return false;
		}

		public static bool CanAfford(UserModel user, int price)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			Entity entity = user.User.LocalCharacter._Entity;
			int itemAmount = InventoryUtilities.GetItemAmount<EntityManager>(Core.EntityManager, entity, CurrencyPrefab, default(Nullable_Unboxed<int>));
			Plugin.Logger.Info("InventoryService", $"Currency in inventory: {itemAmount}");
			if (itemAmount >= price)
			{
				return true;
			}
			return false;
		}
	}
	public static class PrisonerService
	{
		public static List<PrisonerModel> GetPrisonerList(UserModel user)
		{
			//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_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_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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ec: Unknown result type (might be due to invalid IL or missing references)
			string characterName = user.CharacterName;
			Entity val = ((IEnumerable<Entity>)EntityUtil.GetEntitiesByComponentType<ClanTeam>().ToArray()).FirstOrDefault((Func<Entity, bool>)delegate(Entity e)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				ClanTeam val3 = e.Read<ClanTeam>();
				return ((object)(FixedString64Bytes)(ref val3.Name)).ToString().Equals(characterName, StringComparison.OrdinalIgnoreCase);
			});
			List<PrisonerModel> list = new List<PrisonerModel>();
			int num = 0;
			if (val != Entity.Null)
			{
				num = val.Read<ClanTeam>().TeamValue;
			}
			else
			{
				UserModel userByCharacterName = UserUtil.GetUserByCharacterName(characterName);
				if (userByCharacterName == null)
				{
					return null;
				}
				num = userByCharacterName.Entity.Read<Team>().Value;
			}
			if (num == 0)
			{
				return null;
			}
			Enumerator<Entity> enumerator = EntityUtil.GetEntitiesByComponentType<PrisonCell>().GetEnumerator();
			PrisonCell val2 = default(PrisonCell);
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				EntityManager entityManager = Core.EntityManager;
				if (((EntityManager)(ref entityManager)).TryGetComponentData<PrisonCell>(current, ref val2) && !(val2.ImprisonedEntity._Entity == Entity.Null) && current.TryGetComponent<Team>(out Team component) && component.Value == num)
				{
					PrisonerModel item = new PrisonerModel(val2.ImprisonedEntity._Entity);
					if (!list.Contains(item))
					{
						list.Add(item);
					}
				}
			}
			return list;
		}

		public static void SpawnPrisonerInCell(PrisonerModel.PrisonerInformation prisonerInfo, Entity prisoncellEntity, UserModel initiator)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			PrisonerModel.PrisonerInformation prisonerInfo2 = prisonerInfo;
			UserModel initiator2 = initiator;
			EntityManager entityManager = Core.EntityManager;
			PrisonCell prisonCellData = default(PrisonCell);
			if (!((EntityManager)(ref entityManager)).TryGetComponentData<PrisonCell>(prisoncellEntity, ref prisonCellData))
			{
				Plugin.Logger.Error("PrisonerService", "prisoncellEntity does not contain PrisonCell data.");
			}
			Prisonstation prisonStation = prisoncellEntity.Read<Prisonstation>();
			if (!prisoncellEntity.TryGetComponent<LocalTransform>(out LocalTransform component))
			{
				return;
			}
			float3 position = component.Position;
			UnitSpawnerService.SpawnWithCallback(Entity.Null, prisonerInfo2.PrefabGUID, new float2(position.x, position.z), -1f, delegate(Entity e)
			{
				//IL_0000: 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_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_007d: Unknown result type (might be due to invalid IL or missing references)
				//IL_007f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0080: 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_0086: Unknown result type (might be due to invalid IL or missing references)
				//IL_008e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0093: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_00a1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ac: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f9: 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_010a: 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_0117: 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_0011: 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_0017: 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_0034: 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_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_0061: 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)
				if (e.Has<BloodConsumeSource>())
				{
					EntityManager entityManager2 = Core.EntityManager;
					BloodConsumeSource componentData = ((EntityManager)(ref entityManager2)).GetComponentData<BloodConsumeSource>(e);
					componentData.UnitBloodType._Value = ModifiablePrefabGUID.op_Implicit(prisonerInfo2.BloodInfo.UnitBloodType);
					componentData.BloodQuality = prisonerInfo2.BloodInfo.BloodQuality;
					componentData.CanBeConsumed = true;
					entityManager2 = Core.EntityManager;
					((EntityManager)(ref entityManager2)).SetComponentData<BloodConsumeSource>(e, componentData);
				}
				Imprisoned val = default(Imprisoned);
				val.PrisonCellEntity = prisoncellEntity;
				Imprisoned data = val;
				BehaviourTreeState data2 = e.Read<BehaviourTreeState>();
				data2.Value = (GenericEnemyState)2048;
				BehaviourTreeStateMetadata val2 = e.Read<BehaviourTreeStateMetadata>();
				val2.PreviousState = (GenericEnemyState)2048;
				e.Add<Imprisoned>();
				e.Write<Imprisoned>(data);
				e.Write<BehaviourTreeState>(data2);
				prisonCellData.ImprisonedEntity = NetworkedEntity.op_Implicit(e);
				prisoncellEntity.Write<PrisonCell>(prisonCellData);
				prisonStation.HasPrisoner = true;
				prisoncellEntity.Write<Prisonstation>(prisonStation);
				BuffUtil.BuffNpc(e, initiator2.Entity, new PrefabGUID(1603329680));
				SequenceUtils.SpawnSequence(e, SequenceUtils.Smite, 5);
			}, position.y);
		}

		public static void MovePrisoner(PrisonerModel prisoner, Entity prisoncell, UserModel initiator)
		{
			//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_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_0013: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			Entity prisonerEntity = prisoner.PrisonerEntity;
			PrisonerModel.PrisonerInformation info = prisoner.Info;
			StatChangeUtility.KillEntity(Core.EntityManager, prisonerEntity, Entity.Null, 0.0, (StatChangeReason)1, false);
			Plugin.Logger.Info("PrisonerService", $"Killing sender prisoner {prisonerEntity}.");
			SpawnPrisonerInCell(info, prisoncell, initiator);
		}

		public static bool SwapPrisoner(PrisonerModel prisonerA, PrisonerModel prisonerB, UserModel initiator)
		{
			//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_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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			Entity attachedPrisonCell = GetAttachedPrisonCell(prisonerA);
			Entity attachedPrisonCell2 = GetAttachedPrisonCell(prisonerB);
			if (attachedPrisonCell == Entity.Null || attachedPrisonCell2 == Entity.Null)
			{
				Plugin.Logger.Error("PrisonerService", "Could not get either PrisoncellA or PrisoncellB during prisoner swap.");
				return false;
			}
			PrisonerModel.PrisonerInformation info = prisonerA.Info;
			PrisonerModel.PrisonerInformation info2 = prisonerB.Info;
			EntityManager entityManager = Core.EntityManager;
			if (((EntityManager)(ref entityManager)).HasComponent<Imprisoned>(prisonerA.PrisonerEntity))
			{
				entityManager = Core.EntityManager;
				((EntityManager)(ref entityManager)).RemoveComponent<Imprisoned>(prisonerA.PrisonerEntity);
			}
			entityManager = Core.EntityManager;
			if (((EntityManager)(ref entityManager)).HasComponent<Imprisoned>(prisonerB.PrisonerEntity))
			{
				entityManager = Core.EntityManager;
				((EntityManager)(ref entityManager)).RemoveComponent<Imprisoned>(prisonerB.PrisonerEntity);
			}
			StatChangeUtility.KillEntity(Core.EntityManager, prisonerA.PrisonerEntity, Entity.Null, 0.0, (StatChangeReason)1, false);
			StatChangeUtility.KillEntity(Core.EntityManager, prisonerB.PrisonerEntity, Entity.Null, 0.0, (StatChangeReason)1, false);
			SpawnPrisonerInCell(info, attachedPrisonCell2, initiator);
			SpawnPrisonerInCell(info2, attachedPrisonCell, initiator);
			return true;
		}

		private static Entity GetAttachedPrisonCell(PrisonerModel prisoner)
		{
			//IL_0001: 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_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_000d: Unknown result type (might be due to invalid IL or missing references)
			if (!prisoner.PrisonerEntity.Has<Imprisoned>())
			{
				return Entity.Null;
			}
			return prisoner.PrisonerEntity.Read<Imprisoned>().PrisonCellEntity;
		}

		public static bool HasPrisoner(Entity cellEntity)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = Core.EntityManager;
			PrisonCell val = default(PrisonCell);
			if (!((EntityManager)(ref entityManager)).TryGetComponentData<PrisonCell>(cellEntity, ref val))
			{
				return false;
			}
			if (val.ImprisonedEntity._Entity == Entity.Null)
			{
				return false;
			}
			return true;
		}

		public static bool IsSameTeam(Entity prisoncell, UserModel user)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_001b: Unknown result type (might be due to invalid IL or missing references)
			int value = prisoncell.Read<Team>().Value;
			int value2 = user.User.LocalCharacter._Entity.Read<Team>().Value;
			if (value == value2)
			{
				return true;
			}
			return false;
		}
	}
	public static class SalesService
	{
		private static readonly List<PendingSale> SalesList;

		private static readonly Timer CleanupTimer;

		static SalesService()
		{
			SalesList = new List<PendingSale>();
			CleanupTimer = new Timer(5000.0);
			CleanupTimer.Elapsed += delegate
			{
				RemoveExpiredSales();
			};
			CleanupTimer.AutoReset = true;
			CleanupTimer.Enabled = true;
		}

		public static void AddSale(PendingSale sale)
		{
			SalesList.Add(sale);
			Plugin.Logger.Info("SalesService", $"Prisoner exchange created : Seller={sale.Seller.CharacterName}, Buyer={sale.Buyer.CharacterName}, Price={sale.Price}");
		}

		public static List<PendingSale> GetAll()
		{
			return SalesList;
		}

		public static PendingSale GetSaleBySeller(UserModel seller)
		{
			UserModel seller2 = seller;
			return SalesList.FirstOrDefault((PendingSale s) => s.Seller.PlatformId == seller2.PlatformId);
		}

		public static PendingSale GetSaleByBuyer(UserModel buyer)
		{
			UserModel buyer2 = buyer;
			return SalesList.FirstOrDefault((PendingSale s) => s.Buyer.PlatformId == buyer2.PlatformId);
		}

		public static void RemoveSale(UserModel seller)
		{
			lock (SalesList)
			{
				PendingSale saleBySeller = GetSaleBySeller(seller);
				if (saleBySeller != null)
				{
					SalesList.Remove(saleBySeller);
					Plugin.Logger.Info("SalesService", "Prisoner exchange removed : Seller=" + saleBySeller.Seller.CharacterName + ", Buyer=" + saleBySeller.Buyer.CharacterName);
				}
			}
		}

		public static void ClearAll()
		{
			lock (SalesList)
			{
				SalesList.Clear();
			}
		}

		public static bool SaleExists(UserModel user)
		{
			UserModel user2 = user;
			lock (SalesList)
			{
				return GetAll().Any((PendingSale sale) => sale.Seller.PlatformId == user2.PlatformId);
			}
		}

		private static void RemoveExpiredSales()
		{
			//IL_009d: 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_00b4: 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_00d8: 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)
			lock (SalesList)
			{
				FixedString512Bytes val = default(FixedString512Bytes);
				FixedString512Bytes val2 = default(FixedString512Bytes);
				foreach (PendingSale item in SalesList.Where((PendingSale sale) => (DateTime.UtcNow - sale.CreatedAt).TotalSeconds >= sale.LifetimeSeconds).ToList())
				{
					((FixedString512Bytes)(ref val))..ctor(Markup.Prefix + "Your prisoner exchange request to " + item.Buyer.CharacterName + " has expired.");
					((FixedString512Bytes)(ref val2))..ctor(Markup.Prefix + "The prisoner exchange request from " + item.Seller.CharacterName + " has expired.");
					ServerChatUtils.SendSystemMessageToClient(Core.EntityManager, item.Seller.User, ref val);
					ServerChatUtils.SendSystemMessageToClient(Core.EntityManager, item.Buyer.User, ref val2);
					SalesList.Remove(item);
					BuffUtil.RemoveBuff(item.PrisonerEntity, BuffUtil._electricBuff);
				}
			}
		}
	}
	public static class SwapService
	{
		private static readonly List<PendingSwap> SwapsList;

		private static readonly Timer CleanupTimer;

		static SwapService()
		{
			SwapsList = new List<PendingSwap>();
			CleanupTimer = new Timer(5000.0);
			CleanupTimer.Elapsed += delegate
			{
				RemoveExpiredSwaps();
			};
			CleanupTimer.AutoReset = true;
			CleanupTimer.Enabled = true;
		}

		public static void AddSwap(PendingSwap swap)
		{
			lock (SwapsList)
			{
				SwapsList.Add(swap);
			}
			Plugin.Logger.Info("SwapService", "Created prisoner swap. Initiator=" + swap.Seller.CharacterName + ", Target=" + swap.Buyer.CharacterName);
		}

		public static List<PendingSwap> GetAll()
		{
			lock (SwapsList)
			{
				return SwapsList;
			}
		}

		public static PendingSwap GetActiveSwap(UserModel user)
		{
			UserModel user2 = user;
			lock (SwapsList)
			{
				return SwapsList.FirstOrDefault((PendingSwap s) => s.Seller.PlatformId == user2.PlatformId || s.Buyer.PlatformId == user2.PlatformId);
			}
		}

		public static bool SwapExists(UserModel user)
		{
			UserModel user2 = user;
			lock (SwapsList)
			{
				return SwapsList.Any((PendingSwap s) => s.Seller.PlatformId == user2.PlatformId || s.Buyer.PlatformId == user2.PlatformId);
			}
		}

		public static void RemoveSwap(UserModel seller)
		{
			lock (SwapsList)
			{
				PendingSwap activeSwap = GetActiveSwap(seller);
				if (activeSwap != null)
				{
					SwapsList.Remove(activeSwap);
					Plugin.Logger.Info("SwapService", "Removed prisoner swap from initiator=" + seller.CharacterName);
				}
			}
		}

		public static void ClearAll()
		{
			lock (SwapsList)
			{
				SwapsList.Clear();
			}
		}

		private static void RemoveExpiredSwaps()
		{
			//IL_0063: 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_0095: 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_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			lock (SwapsList)
			{
				FixedString512Bytes val = default(FixedString512Bytes);
				FixedString512Bytes val2 = default(FixedString512Bytes);
				foreach (PendingSwap item in SwapsList.Where((PendingSwap s) => (DateTime.UtcNow - s.CreatedAt).TotalSeconds >= s.LifetimeSeconds).ToList())
				{
					SwapsList.Remove(item);
					if (item.Seller.User.IsConnected)
					{
						((FixedString512Bytes)(ref val))..ctor(Markup.Prefix + "Your prisoner swap request with " + item.Buyer.CharacterName + " has expired.");
						ServerChatUtils.SendSystemMessageToClient(Core.EntityManager, item.Seller.User, ref val);
					}
					if (item.Buyer.User.IsConnected)
					{
						((FixedString512Bytes)(ref val2))..ctor(Markup.Prefix + "A prisoner swap request from " + item.Seller.CharacterName + " has expired.");
						ServerChatUtils.SendSystemMessageToClient(Core.EntityManager, item.Buyer.User, ref val2);
					}
					BuffUtil.RemoveBuff(item.PrisonerA.PrisonerEntity, BuffUtil._electricBuff);
					BuffUtil.RemoveBuff(item.PrisonerB.PrisonerEntity, BuffUtil._electricBuff);
				}
			}
		}
	}
	internal static class UnitSpawnerService
	{
		[HarmonyPatch(typeof(UnitSpawnerReactSystem), "OnUpdate")]
		public static class UnitSpawnerReactSystemPatch
		{
			public static bool Enabled { get; set; }

			public static void Prefix(UnitSpawnerReactSystem __instance)
			{
				//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_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: 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_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_0032: 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_003b: 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_004d: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0095: 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_00e9: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
				//IL_0101: Unknown result type (might be due to invalid IL or missing references)
				//IL_0103: Unknown result type (might be due to invalid IL or missing references)
				//IL_0105: 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_010e: Unknown result type (might be due to invalid IL or missing references)
				//IL_010f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0116: Unknown result type (might be due to invalid IL or missing references)
				if (!Enabled)
				{
					return;
				}
				EntityQuery _query_2099432243_ = __instance.__query_2099432243_0;
				NativeArray<Entity> val = ((EntityQuery)(ref _query_2099432243_)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
				Enumerator<Entity> enumerator = val.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					EntityManager entityManager = Core.EntityManager;
					if (!((EntityManager)(ref entityManager)).HasComponent<LifeTime>(current))
					{
						return;
					}
					entityManager = Core.EntityManager;
					long num = (long)Mathf.Round(((EntityManager)(ref entityManager)).GetComponentData<LifeTime>(current).Duration);
					if (PostActions.TryGetValue(num, out (float, Action<Entity>) value))
					{
						Plugin.Logger.Info("UnitSpawnerService", $"Spawn callback triggered for entity={current}, key={num}");
						var (num2, action) = value;
						PostActions.Remove(num);
						LifeTimeEndAction endAction = (LifeTimeEndAction)((!(num2 < 0f)) ? 2 : 0);
						LifeTime val2 = new LifeTime
						{
							Duration = num2,
							EndAction = endAction
						};
						entityManager = Core.EntityManager;
						((EntityManager)(ref entityManager)).SetComponentData<LifeTime>(current, val2);
						action(current);
					}
				}
				val.Dispose();
			}
		}

		private static readonly Entity EmptyEntity = default(Entity);

		private static readonly Dictionary<long, (float actualDuration, Action<Entity> Actions)> PostActions = new Dictionary<long, (float, Action<Entity>)>();

		public static Entity SpawnWithCallback(Entity user, PrefabGUID unit, float2 position, float duration, Action<Entity> postActions, float yPosition = -1f)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if (Mathf.Approximately(yPosition, -1f))
			{
				EntityManager entityManager = Core.EntityManager;
				yPosition = ((EntityManager)(ref entityManager)).GetComponentData<Translation>(user).Value.y;
			}
			float3 val = default(float3);
			((float3)(ref val))..ctor(position.x, yPosition, position.y);
			UnitSpawnerUpdateSystem existingSystemManaged = Core.Server.GetExistingSystemManaged<UnitSpawnerUpdateSystem>();
			UnitSpawnerReactSystemPatch.Enabled = true;
			long num = NextKey();
			existingSystemManaged.SpawnUnit(EmptyEntity, unit, val, 1, 0f, 0f, (float)num);
			PostActions.Add(num, (duration, postActions));
			return EmptyEntity;
		}

		private static long NextKey()
		{
			Random random = new Random();
			int num = 5;
			long num2;
			do
			{
				num2 = random.NextInt64(10000L) * 3;
				num--;
				if (num < 0)
				{
					throw new Exception("Failed to generate a unique key for UnitSpawnerService");
				}
			}
			while (PostActions.ContainsKey(num2));
			return num2;
		}
	}
}
namespace PrisonerExchange.Services.Chat
{
	public static class CooldownTracker
	{
		private static readonly ConcurrentDictionary<(ulong platFormId, string CommandName), DateTime> Cooldowns = new ConcurrentDictionary<(ulong, string), DateTime>();

		public static bool IsOnCooldown(ulong platFormId, string commandName)
		{
			if (Cooldowns.TryGetValue((platFormId, commandName), out var value))
			{
				return DateTime.UtcNow < value;
			}
			return false;
		}

		public static double GetRemainingSeconds(ulong platFormId, string commandName)
		{
			if (Cooldowns.TryGetValue((platFormId, commandName), out var value))
			{
				TimeSpan timeSpan = value - DateTime.UtcNow;
				if (!(timeSpan.TotalSeconds > 0.0))
				{
					return 0.0;
				}
				return timeSpan.TotalSeconds;
			}
			return 0.0;
		}

		public static void SetCooldown(ulong platFormId, string commandName)
		{
			DateTime value = DateTime.UtcNow.Add(TimeSpan.FromMinutes(Configuration.CommandCoolDownPeriod));
			Cooldowns[(platFormId, commandName)] = value;
		}

		public static void ClearAllCooldowns(ulong platFormId)
		{
			foreach (var key in Cooldowns.Keys)
			{
				if (key.platFormId == platFormId)
				{
					Cooldowns.TryRemove(key, out var _);
				}
			}
		}
	}
	public static class PromptHelper
	{
		public static void UserInput(ChatCommandContext ctx, Action<string> onInput, string instruction = "Please enter a value:", int timeout = 30)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			Action<string> onInput2 = onInput;
			ChatCommandContext ctx2 = ctx;
			ulong platformId = ctx2.Event.User.PlatformId;
			if (instruction != null)
			{
				ctx2.Reply(instruction);
			}
			PromptManager.RequestInput(platformId, delegate(string response)
			{
				onInput2(response);
			}, delegate
			{
				ctx2.Reply("Selection has timed out.");
			}, timeout);
		}
	}
	public static class PromptManager
	{
		private class PromptData
		{
			public Action<string> OnInput;

			public Action OnTimeout;

			public Timer Timeout;
		}

		private static readonly Dictionary<ulong, PromptData> StoredPrompts = new Dictionary<ulong, PromptData>();

		public static void RequestInput(ulong userId, Action<string> onInput, Action onTimeout, int timeoutSeconds = 30)
		{
			Action onTimeout2 = onTimeout;
			CancelPrompt(userId);
			Timer timer = new Timer(timeoutSeconds * 1000);
			timer.Elapsed += delegate
			{
				CancelPrompt(userId);
				onTimeout2?.Invoke();
			};
			timer.AutoReset = false;
			timer.Start();
			StoredPrompts[userId] = new PromptData
			{
				OnInput = onInput,
				OnTimeout = onTimeout2,
				Timeout = timer
			};
		}

		public static bool TryHandleInput(ulong userId, string message)
		{
			if (!StoredPrompts.TryGetValue(userId, out PromptData value))
			{
				return false;
			}
			value.Timeout.Stop();
			StoredPrompts.Remove(userId);
			value.OnInput?.Invoke(message);
			return true;
		}

		public static void CancelPrompt(ulong userId)
		{
			if (StoredPrompts.TryGetValue(userId, out PromptData value))
			{
				value.Timeout.Stop();
				StoredPrompts.Remove(userId);
			}
		}

		public static bool IsWaiting(ulong userId)
		{
			return StoredPrompts.ContainsKey(userId);
		}
	}
	public static class StringBuilders
	{
		public static void AnnounceSale(PendingSale sale)
		{
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			PrisonerModel.PrisonerInformation getPrisonerInformation = sale.GetPrisonerInformation;
			FixedString512Bytes val = default(FixedString512Bytes);
			((FixedString512Bytes)(ref val))..ctor($"{Markup.Prefix}{sale.Buyer.CharacterName} has purchased {getPrisonerInformation.UnitType} with {getPrisonerInformation.BloodQuality}%{getPrisonerInformation.BloodType} from {sale.Seller.CharacterName}!");
			ServerChatUtils.SendSystemMessageToAllClients(Core.EntityManager, ref val);
		}

		public static string SalesInfoMessage(PendingSale sale)
		{
			PrisonerModel.PrisonerInformation getPrisonerInformation = sale.GetPrisonerInformation;
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendLine("<size=15><color=yellow>Prisoner sale request</color></size>");
			StringBuilder stringBuilder2 = stringBuilder;
			StringBuilder stringBuilder3 = stringBuilder2;
			StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(11, 1, stringBuilder2);
			handler.AppendLiteral("From user: ");
			handler.AppendFormatted(Markup.Highlight(sale.Seller.CharacterName));
			stringBuilder3.AppendLine(ref handler);
			stringBuilder2 = stringBuilder;
			StringBuilder stringBuilder4 = stringBuilder2;
			handler = new StringBuilder.AppendInterpolatedStringHandler(8, 2, stringBuilder2);
			handler.AppendLiteral("Price: ");
			handler.AppendFormatted(Markup.Highlight(sale.Price));
			handler.AppendLiteral(" ");
			handler.AppendFormatted(Configuration.CurrencyName);
			stringBuilder4.AppendLine(ref handler);
			stringBuilder2 = stringBuilder;
			StringBuilder stringBuilder5 = stringBuilder2;
			handler = new StringBuilder.AppendInterpolatedStringHandler(15, 1, stringBuilder2);
			handler.AppendLiteral("Prisoner type: ");
			handler.AppendFormatted(getPrisonerInformation.UnitType);
			stringBuilder5.AppendLine(ref handler);
			stringBuilder2 = stringBuilder;
			StringBuilder stringBuilder6 = stringBuilder2;
			handler = new StringBuilder.AppendInterpolatedStringHandler(16, 1, stringBuilder2);
			handler.AppendLiteral("Prisoner blood: ");
			handler.AppendFormatted(Markup.Highlight(getPrisonerInformation.BloodQuality + "% " + getPrisonerInformation.BloodType));
			stringBuilder6.AppendLine(ref handler);
			stringBuilder.AppendLine();
			stringBuilder2 = stringBuilder;
			StringBuilder stringBuilder7 = stringBuilder2;
			handler = new StringBuilder.AppendInterpolatedStringHandler(50, 1, stringBuilder2);
			handler.AppendLiteral("Type ");
			handler.AppendFormatted(Markup.Highlight(".pe acceptsale"));
			handler.AppendLiteral(" while standing next to an empty prison cell.");
			stringBuilder7.AppendLine(ref handler);
			return stringBuilder.ToString();
		}

		public static string SwapInfoMessage(PendingSwap swap)
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendLine("<size=15><color=yellow>Prisoner swap request</color></size>");
			StringBuilder stringBuilder2 = stringBuilder;
			StringBuilder stringBuilder3 = stringBuilder2;
			StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(11, 1, stringBuilder2);
			handler.AppendLiteral("From user: ");
			handler.AppendFormatted(Markup.Highlight(swap.Seller.CharacterName));
			stringBuilder3.AppendLine(ref handler);
			stringBuilder.AppendLine("Offering: " + Markup.Highlight(swap.PrisonerB.Info.UnitType ?? "") + " " + Markup.Secondary(swap.PrisonerB.Info.BloodQuality + "% " + swap.PrisonerB.Info.BloodType));
			stringBuilder.AppendLine("For your: " + Markup.Highlight(swap.PrisonerA.Info.UnitType ?? "") + " " + Markup.Secondary(swap.PrisonerA.Info.BloodQuality + "% " + swap.PrisonerA.Info.BloodType));
			stringBuilder.AppendLine();
			stringBuilder2 = stringBuilder;
			StringBuilder stringBuilder4 = stringBuilder2;
			handler = new StringBuilder.AppendInterpolatedStringHandler(27, 1, stringBuilder2);
			handler.AppendLiteral("Type ");
			handler.AppendFormatted(Markup.Highlight(".pe acceptswap"));
			handler.AppendLiteral(" to complete the swap.");
			stringBuilder4.AppendLine(ref handler);
			return stringBuilder.ToString();
		}

		public static void SendPrisonerList(ChatCommandContext ctx, List<PrisonerModel> list)
		{
			ChatCommandContext ctx2 = ctx;
			StringBuilder sb = new StringBuilder();
			int currentBytes = 0;
			bool isFirstBatch = true;
			sb.AppendLine();
			currentBytes += Encoding.UTF8.GetByteCount("\n");
			for (int i = 0; i < list.Count; i++)
			{
				PrisonerModel.PrisonerInformation info = list[i].Info;
				string s = info.BloodQuality + "% " + info.BloodType;
				string text = $"[{Markup.Secondary(i + 1)}] {Markup.Highlight(info.UnitType)} {Markup.Secondary(s)}";
				int byteCount = Encoding.UTF8.GetByteCount(text + "\n");
				if (currentBytes + byteCount >= 512)
				{
					Flush();
					if (!isFirstBatch)
					{
						sb.AppendLine();
						currentBytes += Encoding.UTF8.GetByteCount("\n");
					}
				}
				sb.AppendLine(text);
				currentBytes += byteCount;
			}
			string text2 = $"{Markup.Secondary("Select")}{Markup.Highlight(" a prisoner by typing a number in chat")} ({Markup.Secondary("!s to cancel")})";
			int byteCount2 = Encoding.UTF8.GetByteCount(text2 + "\n");
			if (currentBytes + byteCount2 >= 512)
			{
				Flush();
			}
			sb.AppendLine();
			sb.AppendLine(text2);
			Flush();
			void Flush()
			{
				if (sb.Length > 0)
				{
					ctx2.Reply(sb.ToString());
					sb.Clear();
					currentBytes = 0;
					isFirstBatch = false;
				}
			}
		}
	}
}
namespace PrisonerExchange.Patches
{
	[HarmonyPatch(typeof(ChatMessageSystem), "OnUpdate")]
	[HarmonyPriority(400)]
	public static class ChatSystemPromptPatch
	{
		public static bool Prefix(ChatMessageSystem __instance)
		{
			//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_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_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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: 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_00a0: 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)
			EntityManager entityManager = ((ComponentSystemBase)__instance).EntityManager;
			EntityQuery _query_661171423_ = __instance.__query_661171423_0;
			NativeArray<Entity> val = ((EntityQuery)(ref _query_661171423_)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			try
			{
				Enumerator<Entity> enumerator = val.GetEnumerator();
				FixedString512Bytes val3 = default(FixedString512Bytes);
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					FromCharacter componentData = ((EntityManager)(ref entityManager)).GetComponentData<FromCharacter>(current);
					ChatMessageEvent componentData2 = ((EntityManager)(ref entityManager)).GetComponentData<ChatMessageEvent>(current);
					User val2 = componentData.User.Read<User>();
					ulong platformId = val2.PlatformId;
					string text = ((object)(FixedString512Bytes)(ref componentData2.MessageText)).ToString().Trim();
					if (PromptManager.IsWaiting(platformId))
					{
						if (text.Equals("!s", StringComparison.OrdinalIgnoreCase))
						{
							PromptManager.CancelPrompt(platformId);
							((FixedString512Bytes)(ref val3))..ctor("Prompt cancelled!");
							ServerChatUtils.SendSystemMessageToClient(entityManager, val2, ref val3);
						}
						else
						{
							PromptManager.TryHandleInput(platformId, text);
						}
						((EntityManager)(ref entityManager)).DestroyEntity(current);
						return false;
					}
				}
			}
			finally
			{
				val.Dispose();
			}
			return true;
		}
	}
}
namespace PrisonerExchange.Models
{
	public class PendingSale
	{
		public UserModel Seller { get; }

		public UserModel Buyer { get; }

		public Entity PrisonerEntity { get; }

		public int Price { get; }

		public DateTime CreatedAt { get; }

		public double LifetimeSeconds { get; }

		public PrisonerModel.PrisonerInformation GetPrisonerInformation => new PrisonerModel(PrisonerEntity).Info;

		public PendingSale(UserModel seller, Entity prisonerEntity, UserModel buyer, int price, double lifetimeSeconds = 120.0)
		{
			//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)
			Seller = seller;
			Buyer = buyer;
			PrisonerEntity = prisonerEntity;
			Price = price;
			CreatedAt = DateTime.UtcNow;
			LifetimeSeconds = lifetimeSeconds;
			base..ctor();
		}
	}
	public class PendingSwap
	{
		public UserModel Seller { get; }

		public UserModel Buyer { get; }

		public PrisonerModel PrisonerA { get; }

		public PrisonerModel PrisonerB { get; }

		public DateTime CreatedAt { get; }

		public double LifetimeSeconds { get; }

		public PendingSwap(UserModel seller, UserModel buyer, PrisonerModel prisonera, PrisonerModel prisonerb, double lifetimeSeconds = 120.0)
		{
			Seller = seller;
			Buyer = buyer;
			PrisonerA = prisonera;
			PrisonerB = prisonerb;
			CreatedAt = DateTime.UtcNow;
			LifetimeSeconds = lifetimeSeconds;
			base..ctor();
		}
	}
	public class PrisonerModel
	{
		public class PrisonerInformation
		{
			public PrefabGUID PrefabGUID { get; init; }

			public BloodConsumeSource BloodInfo { get; init; }

			public string UnitType { get; init; }

			public string BloodType { get; init; }

			public string BloodQuality { get; init; }
		}

		[CompilerGenerated]
		private Entity <prisoner>P;

		public Entity PrisonerEntity => <prisoner>P;

		public PrisonerInformation Info
		{
			get
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: 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_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: 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_0070: Unknown result type (might be due to invalid IL or missing references)
				//IL_0075: Unknown result type (might be due to invalid IL or missing references)
				//IL_007a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0080: 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_0086: Unknown result type (might be due to invalid IL or missing references)
				if (!<prisoner>P.Exists())
				{
					return null;
				}
				PrefabGUID val = PrefabGUID.Empty;
				BloodConsumeSource val2 = default(BloodConsumeSource);
				string unitType = "Unknown";
				string bloodType = "Unknown";
				string bloodQuality = "Unknown";
				if (<prisoner>P.Has<PrefabGUID>())
				{
					val = <prisoner>P.Read<PrefabGUID>();
					unitType = (Prefabs.UnitTypes.TryGetValue(val, out string value) ? value : "Unknown");
				}
				if (<prisoner>P.Has<BloodConsumeSource>())
				{
					val2 = <prisoner>P.Read<BloodConsumeSource>();
					bloodType = (Prefabs.BloodTypes.TryGetValue(ModifiablePrefabGUID.op_Implicit(val2.UnitBloodType), out string value2) ? value2 : "Unknown");
					bloodQuality = val2.BloodQuality.ToString("F0");
				}
				return new PrisonerInformation
				{
					PrefabGUID = val,
					BloodInfo = val2,
					UnitType = unitType,
					BloodType = bloodType,
					BloodQuality = bloodQuality
				};
			}
		}

		public PrisonerModel(Entity prisoner)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			<prisoner>P = prisoner;
			base..ctor();
		}
	}
	public class UserModel
	{
		public Entity Entity { get; }

		public User User { get; }

		public ulong PlatformId { get; }

		public string CharacterName { get; }

		public bool IsAdmin { get; }

		public bool IsClanLeader
		{
			get
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Invalid comparison between Unknown and I4
				if (Entity.TryGetComponent<ClanRole>(out ClanRole component) && (int)component.Value == 2)
				{
					return true;
				}
				return false;
			}
		}

		public UserModel(Entity entity, User userData)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			Entity = entity;
			User = userData;
			PlatformId = userData.PlatformId;
			CharacterName = ((object)(FixedString64Bytes)(ref userData.CharacterName)).ToString();
			IsAdmin = userData.IsAdmin;
			base..ctor();
		}

		public override bool Equals(object obj)
		{
			if (obj is UserModel userModel)
			{
				return PlatformId == userModel.PlatformId;
			}
			return false;
		}

		public override int GetHashCode()
		{
			return PlatformId.GetHashCode();
		}
	}
}
namespace PrisonerExchange.Extensions
{
	internal static class Ecs
	{
		public delegate void WithRefHandler<T>(ref T item);

		private static EntityManager Em => Core.EntityManager;

		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 em = Em;
				return ((EntityManager)(ref em)).Exists(entity);
			}
			return false;
		}

		public static bool HasValue(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)
			return entity != Entity.Null;
		}

		public static bool Has<T>(this Entity entity) where T : struct
		{
			//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 em = Em;
			return ((EntityManager)(ref em)).HasComponent<T>(entity);
		}

		public static bool TryGetComponent<T>(this Entity entity, out T component) where T : struct
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			EntityManager em = Em;
			if (((EntityManager)(ref em)).HasComponent<T>(entity))
			{
				component = entity.Read<T>();
				return true;
			}
			component = default(T);
			return false;
		}

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

		public static void Write<T>(this Entity entity, T data) where T : struct
		{
			//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 em = Em;
			((EntityManager)(ref em)).SetComponentData<T>(entity, data);
		}

		public unsafe static void WriteRaw<T>(this Entity entity, T data) where T : struct
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			byte[] array = StructureToByteArray(data);
			int num = Marshal.SizeOf<T>();
			fixed (byte* ptr = array)
			{
				EntityManager em = Em;
				((EntityManager)(ref em)).SetComponentDataRaw(entity, val.TypeIndex, (void*)ptr, num);
			}
		}

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

		public static void Add<T>(this Entity entity) where T : struct
		{
			//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.Has<T>())
			{
				EntityManager em = Em;
				((EntityManager)(ref em)).AddComponent<T>(entity);
			}
		}

		public static void Remove<T>(this Entity entity)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = Core.EntityManager;
			((EntityManager)(ref entityManager)).RemoveComponent(entity, val);
		}

		public static bool TryRemoveComponent<T>(this Entity entity) where T : struct
		{
			//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.Has<T>())
			{
				EntityManager em = Em;
				((EntityManager)(ref em)).RemoveComponent<T>(entity);
				return true;
			}
			return false;
		}

		private static void With<T>(this Entity entity, WithRefHandler<T> action) where T : struct
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			T item = entity.Read<T>();
			action(ref item);
			EntityManager em = Em;
			((EntityManager)(ref em)).SetComponentData<T>(entity, item);
		}

		public static void AddWith<T>(this Entity entity, WithRefHandler<T> action) where T : struct
		{
			//IL_0000: 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_0008: Unknown result type (might be due to invalid IL or missing references)
			if (!entity.Has<T>())
			{
				entity.Add<T>();
			}
			entity.With(action);
		}

		public static void HasWith<T>(this Entity entity, WithRefHandler<T> action) where T : struct
		{
			//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)
			if (entity.Has<T>())
			{
				entity.With(action);
			}
		}

		public static bool SameTeam(this Entity entityA, Entity entityB)
		{
			//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_0012: 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_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_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			if (!entityA.Exists() || !entityB.Exists())
			{
				return false;
			}
			if (!entityA.Has<Team>() || !entityB.Has<Team>())
			{
				return false;
			}
			Team val = entityA.Read<Team>();
			Team val2 = entityB.Read<Team>();
			return val.Value == val2.Value;
		}
	}
	public static class Log
	{
		public static void Info(this ManualLogSource logger, string context, string message)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(3, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(context);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("] ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(message);
			}
			logger.LogInfo(val);
		}

		public static void Message(this ManualLogSource logger, string context, string message)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			bool flag = default(bool);
			BepInExMessageLogInterpo