Decompiled source of PrisonerBlood v1.0.0

PrisonerBlood.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.Json;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using PrisonerBlood.Models;
using PrisonerBlood.Services;
using ProjectM;
using ProjectM.Behaviours;
using ProjectM.Network;
using ProjectM.Scripting;
using Stunlock.Core;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
using VampireCommandFramework;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("PrisonerBlood")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Server-side V Rising mod that lets players buy prisoners with 100% blood quality and Blood Merlot potions.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PrisonerBlood")]
[assembly: AssemblyTitle("PrisonerBlood")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

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

		private static World _server;

		private static EntityManager _entityManager;

		private static ServerScriptMapper _serverScriptMapper;

		private static DebugEventsSystem _debugEventsSystem;

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

		public static EntityManager EntityManager => (!(_entityManager == default(EntityManager))) ? _entityManager : (_entityManager = Server.EntityManager);

		public static ServerScriptMapper ServerScriptMapper => _serverScriptMapper ?? (_serverScriptMapper = Server.GetExistingSystemManaged<ServerScriptMapper>());

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

		public static DebugEventsSystem DebugEventsSystem => _debugEventsSystem ?? (_debugEventsSystem = Server.GetExistingSystemManaged<DebugEventsSystem>());

		public static ManualLogSource Log => Plugin.PluginLog;

		public static UnitSpawnerService UnitSpawner { get; private set; }

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

		internal static void InitializeAfterLoaded()
		{
			//IL_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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			if (!_hasInitialized)
			{
				_server = GetWorld("Server") ?? throw new Exception("There is no Server world (yet). Did you install a server mod on the client?");
				_entityManager = _server.EntityManager;
				_serverScriptMapper = _server.GetExistingSystemManaged<ServerScriptMapper>();
				_debugEventsSystem = _server.GetExistingSystemManaged<DebugEventsSystem>();
				UnitSpawner = new UnitSpawnerService();
				BuyPrisonerService.Initialize();
				BuyBloodPotionService.Initialize();
				_hasInitialized = true;
				ManualLogSource log = Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(10, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("InitializeAfterLoaded");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" completed");
				}
				log.LogInfo(val);
			}
		}

		internal static World GetWorld(string name)
		{
			Enumerator<World> enumerator = World.s_AllWorlds.GetEnumerator();
			while (enumerator.MoveNext())
			{
				World current = enumerator.Current;
				if (current != null && current.Name == name)
				{
					return current;
				}
			}
			return null;
		}
	}
	public static class ECSExtensions
	{
		public unsafe static void Write<T>(this Entity entity, T componentData) where T : struct
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			byte[] array = StructureToByteArray(componentData);
			int num = Marshal.SizeOf<T>();
			fixed (byte* ptr = array)
			{
				EntityManager entityManager = Core.EntityManager;
				((EntityManager)(ref entityManager)).SetComponentDataRaw(entity, val.TypeIndex, (void*)ptr, num);
			}
		}

		public unsafe static T Read<T>(this Entity entity) where T : struct
		{
			//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_0018: 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;
			void* componentDataRawRO = ((EntityManager)(ref entityManager)).GetComponentDataRawRO(entity, val.TypeIndex);
			return Marshal.PtrToStructure<T>(new IntPtr(componentDataRawRO));
		}

		public unsafe static T ReadRW<T>(this Entity entity) where T : struct
		{
			//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_0018: 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;
			void* componentDataRawRW = ((EntityManager)(ref entityManager)).GetComponentDataRawRW(entity, val.TypeIndex);
			return Marshal.PtrToStructure<T>(new IntPtr(componentDataRawRW));
		}

		public static bool Has<T>(this Entity entity)
		{
			//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)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = Core.EntityManager;
			return ((EntityManager)(ref entityManager)).HasComponent(entity, val);
		}

		public static void Add<T>(this Entity entity)
		{
			//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)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = Core.EntityManager;
			((EntityManager)(ref entityManager)).AddComponent(entity, val);
		}

		public static void Remove<T>(this Entity entity)
		{
			//IL_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)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = Core.EntityManager;
			((EntityManager)(ref entityManager)).RemoveComponent(entity, val);
		}

		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);
			Marshal.StructureToPtr(structure, intPtr, fDeleteOld: true);
			Marshal.Copy(intPtr, array, 0, num);
			Marshal.FreeHGlobal(intPtr);
			return array;
		}
	}
	internal static class Helper
	{
		public static readonly HashSet<BloodType> AllowedBloodTypes = new HashSet<BloodType>
		{
			BloodType.Worker,
			BloodType.Warrior,
			BloodType.Rogue,
			BloodType.Brute,
			BloodType.Scholar,
			BloodType.Draculin,
			BloodType.Creature,
			BloodType.Mutant,
			BloodType.Corrupted
		};

		public static NativeArray<Entity> GetEntitiesByComponentTypes<T1, T2>(bool includeAll = false, bool includeDisabled = false, bool includeSpawn = false, bool includePrefab = false, bool includeDestroyed = false)
		{
			//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_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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//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_0075: 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_007a: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: 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_009e: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: 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);
			}
			EntityQueryBuilder val2 = new EntityQueryBuilder(AllocatorHandle.op_Implicit((Allocator)2));
			val2 = ((EntityQueryBuilder)(ref val2)).AddAll(new ComponentType(Il2CppType.Of<T1>(), (AccessMode)0));
			val2 = ((EntityQueryBuilder)(ref val2)).AddAll(new ComponentType(Il2CppType.Of<T2>(), (AccessMode)0));
			EntityQueryBuilder val3 = ((EntityQueryBuilder)(ref val2)).WithOptions(val);
			EntityManager entityManager = Core.EntityManager;
			EntityQuery val4 = ((EntityManager)(ref entityManager)).CreateEntityQuery(ref val3);
			return ((EntityQuery)(ref val4)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
		}

		public static bool TryGetInventoryEntity(Entity characterEntity, out Entity inventoryEntity)
		{
			//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)
			return InventoryUtilities.TryGetInventoryEntity<EntityManager>(Core.EntityManager, characterEntity, ref inventoryEntity, 0);
		}

		public static int GetItemCountInInventory(Entity characterEntity, PrefabGUID itemPrefab)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = Core.EntityManager;
			if (!TryGetInventoryEntity(characterEntity, out var inventoryEntity))
			{
				return 0;
			}
			if (((EntityManager)(ref entityManager)).HasComponent<InventoryBuffer>(inventoryEntity))
			{
				DynamicBuffer<InventoryBuffer> buffer = ((EntityManager)(ref entityManager)).GetBuffer<InventoryBuffer>(inventoryEntity, false);
				int num = 0;
				for (int i = 0; i < buffer.Length; i++)
				{
					InventoryBuffer val = buffer[i];
					if (((PrefabGUID)(ref val.ItemType)).GuidHash == ((PrefabGUID)(ref itemPrefab)).GuidHash)
					{
						num += val.Amount;
					}
				}
				return num;
			}
			int num2 = 0;
			InventoryBuffer val2 = default(InventoryBuffer);
			for (int j = 0; j < 36; j++)
			{
				if (InventoryUtilities.TryGetItemAtSlot<EntityManager>(entityManager, characterEntity, j, ref val2) && ((PrefabGUID)(ref val2.ItemType)).GuidHash == ((PrefabGUID)(ref itemPrefab)).GuidHash)
				{
					num2 += val2.Amount;
				}
			}
			return num2;
		}

		public static Entity AddItemToInventory(Entity recipient, PrefabGUID guid, int amount)
		{
			//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_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				ServerGameManager serverGameManager = Core.ServerGameManager;
				AddItemResponse val = ((ServerGameManager)(ref serverGameManager)).TryAddInventoryItem(recipient, guid, amount);
				return val.NewEntity;
			}
			catch (Exception e)
			{
				Core.LogException(e, "AddItemToInventory");
			}
			return Entity.Null;
		}

		public static bool TryRemoveItemsFromInventory(Entity characterEntity, PrefabGUID itemPrefab, 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_0007: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = Core.EntityManager;
			if (!TryGetInventoryEntity(characterEntity, out var inventoryEntity))
			{
				return false;
			}
			if (!((EntityManager)(ref entityManager)).HasComponent<InventoryBuffer>(inventoryEntity))
			{
				return false;
			}
			DynamicBuffer<InventoryBuffer> buffer = ((EntityManager)(ref entityManager)).GetBuffer<InventoryBuffer>(inventoryEntity, false);
			int num = amount;
			int num2 = buffer.Length - 1;
			while (num2 >= 0 && num > 0)
			{
				InventoryBuffer val = buffer[num2];
				if (((PrefabGUID)(ref val.ItemType)).GuidHash == ((PrefabGUID)(ref itemPrefab)).GuidHash && val.Amount > 0)
				{
					int num3 = math.min(val.Amount, num);
					val.Amount -= num3;
					num -= num3;
					if (val.Amount <= 0)
					{
						val.ItemType = new PrefabGUID(0);
						val.Amount = 0;
					}
					buffer[num2] = val;
				}
				num2--;
			}
			return num == 0;
		}

		public static void BroadcastSystemMessage(string message)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				FixedString512Bytes val = default(FixedString512Bytes);
				((FixedString512Bytes)(ref val))..ctor(message ?? string.Empty);
				ServerChatUtils.SendSystemMessageToAllClients(Core.EntityManager, ref val);
			}
			catch (Exception e)
			{
				Core.LogException(e, "BroadcastSystemMessage");
			}
		}

		public static void NotifyUser(Entity userEntity, string message)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: 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_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_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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!(userEntity == Entity.Null))
				{
					EntityManager entityManager = Core.EntityManager;
					if (((EntityManager)(ref entityManager)).Exists(userEntity))
					{
						entityManager = Core.EntityManager;
						User componentData = ((EntityManager)(ref entityManager)).GetComponentData<User>(userEntity);
						FixedString512Bytes val = default(FixedString512Bytes);
						((FixedString512Bytes)(ref val))..ctor(message ?? string.Empty);
						ServerChatUtils.SendSystemMessageToClient(Core.EntityManager, componentData, ref val);
					}
				}
			}
			catch (Exception e)
			{
				Core.LogException(e, "NotifyUser");
			}
		}
	}
	[BepInPlugin("PrisonerBlood", "PrisonerBlood", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		internal static Harmony Harmony;

		internal static ManualLogSource PluginLog;

		public override void Load()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			if (!(Application.productName != "VRisingServer"))
			{
				PluginLog = ((BasePlugin)this).Log;
				ManualLogSource log = ((BasePlugin)this).Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(27, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("PrisonerBlood");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" version ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.0");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
				}
				log.LogInfo(val);
				Harmony = new Harmony("PrisonerBlood");
				Harmony.PatchAll(Assembly.GetExecutingAssembly());
				ConfigService.Initialize();
				CommandRegistry.RegisterAll();
			}
		}

		public override bool Unload()
		{
			CommandRegistry.UnregisterAssembly();
			Harmony harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			return true;
		}

		internal static bool HasLoaded()
		{
			World world = Core.GetWorld("Server");
			if (world == null)
			{
				return false;
			}
			PrefabCollectionSystem existingSystemManaged = world.GetExistingSystemManaged<PrefabCollectionSystem>();
			return existingSystemManaged != null && existingSystemManaged.SpawnableNameToPrefabGuidDictionary.Count > 0;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "PrisonerBlood";

		public const string PLUGIN_NAME = "PrisonerBlood";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace PrisonerBlood.Services
{
	internal static class BuffService
	{
		public static bool AddBuff(Entity userEntity, Entity targetEntity, PrefabGUID buffPrefab, int duration = -1, bool immortal = true)
		{
			//IL_0009: 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_0019: 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_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_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00b2: 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_00c1: 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_00d4: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			DebugEventsSystem debugEventsSystem = Core.DebugEventsSystem;
			ApplyBuffDebugEvent val = default(ApplyBuffDebugEvent);
			val.BuffPrefabGUID = buffPrefab;
			ApplyBuffDebugEvent val2 = val;
			FromCharacter val3 = default(FromCharacter);
			val3.User = userEntity;
			val3.Character = targetEntity;
			FromCharacter val4 = val3;
			Entity val5 = default(Entity);
			if (BuffUtility.TryGetBuff<EntityManager>(Core.EntityManager, targetEntity, PrefabIdentifier.op_Implicit(buffPrefab), ref val5))
			{
				return false;
			}
			debugEventsSystem.ApplyBuff(val4, val2);
			Entity entity = default(Entity);
			if (!BuffUtility.TryGetBuff<EntityManager>(Core.EntityManager, targetEntity, PrefabIdentifier.op_Implicit(buffPrefab), ref entity))
			{
				return false;
			}
			if (entity.Has<CreateGameplayEventsOnSpawn>())
			{
				entity.Remove<CreateGameplayEventsOnSpawn>();
			}
			if (entity.Has<GameplayEventListeners>())
			{
				entity.Remove<GameplayEventListeners>();
			}
			if (immortal)
			{
				if (!entity.Has<Buff_Persists_Through_Death>())
				{
					entity.Add<Buff_Persists_Through_Death>();
				}
				if (entity.Has<RemoveBuffOnGameplayEvent>())
				{
					entity.Remove<RemoveBuffOnGameplayEvent>();
				}
				if (entity.Has<RemoveBuffOnGameplayEventEntry>())
				{
					entity.Remove<RemoveBuffOnGameplayEventEntry>();
				}
			}
			if (duration > -1 && duration != 0)
			{
				if (!entity.Has<LifeTime>())
				{
					entity.Add<LifeTime>();
					entity.Write<LifeTime>(new LifeTime
					{
						EndAction = (LifeTimeEndAction)2
					});
				}
				LifeTime componentData = entity.Read<LifeTime>();
				componentData.Duration = duration;
				entity.Write<LifeTime>(componentData);
			}
			else if (duration == -1)
			{
				if (entity.Has<LifeTime>())
				{
					LifeTime componentData2 = entity.Read<LifeTime>();
					componentData2.EndAction = (LifeTimeEndAction)0;
					entity.Write<LifeTime>(componentData2);
				}
				if (entity.Has<RemoveBuffOnGameplayEvent>())
				{
					entity.Remove<RemoveBuffOnGameplayEvent>();
				}
				if (entity.Has<RemoveBuffOnGameplayEventEntry>())
				{
					entity.Remove<RemoveBuffOnGameplayEventEntry>();
				}
			}
			return true;
		}
	}
	internal static class BuyBloodPotionService
	{
		private static readonly string CONFIG_DIR = Path.Combine(Paths.ConfigPath, "PrisonerBlood");

		private static readonly string LOG_FILE = Path.Combine(CONFIG_DIR, "buybloodpotion_log.csv");

		private static readonly object LOG_LOCK = new object();

		private static readonly PrefabGUID BloodPotionPrefab = new PrefabGUID(1223264867);

		public static string CurrencyName => GetCurrency().Name;

		public static void Initialize()
		{
			ConfigService.Initialize();
		}

		public static void Reload()
		{
			ConfigService.Reload();
		}

		public static bool IsEnabled()
		{
			return GetConfig().Enabled;
		}

		public static (PrefabGUID Prefab, string Name) GetCurrency()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			ConfigSection config = GetConfig();
			return (new PrefabGUID(config.CurrencyPrefab), config.CurrencyName);
		}

		public static (int DefaultCost, Dictionary<string, int> Prices) GetPriceSnapshot()
		{
			ConfigSection config = GetConfig();
			return (config.DefaultCost, new Dictionary<string, int>(config.BloodCosts, StringComparer.OrdinalIgnoreCase));
		}

		public static bool TryParseBloodTypeStrict(string input, out BloodType type)
		{
			type = (BloodType)0;
			if (string.IsNullOrWhiteSpace(input))
			{
				return false;
			}
			input = input.Trim();
			if (int.TryParse(input, out var _))
			{
				return false;
			}
			if (!Enum.TryParse<BloodType>(input, ignoreCase: true, out type))
			{
				return false;
			}
			return Helper.AllowedBloodTypes.Contains(type);
		}

		public static void ReplyHelp(Action<string> reply, string warningLine = null)
		{
			var (defaultCost, prices) = GetPriceSnapshot();
			if (!string.IsNullOrWhiteSpace(warningLine))
			{
				reply(warningLine);
			}
			reply("<color=yellow>Command:</color> <color=green>.buy bp <BloodType></color>");
			reply("<color=yellow>Example:</color> <color=green>.buy bp rogue</color>");
			StringBuilder stringBuilder = new StringBuilder();
			StringBuilder stringBuilder2 = stringBuilder;
			StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(89, 1, stringBuilder2);
			handler.AppendLiteral("<color=yellow>Blood types</color> : <color=yellow>Costs</color> (<color=#87CEFA>");
			handler.AppendFormatted(CurrencyName);
			handler.AppendLiteral("</color>)");
			stringBuilder2.AppendLine(ref handler);
			var source = (from x in Helper.AllowedBloodTypes.Select(delegate(BloodType bt)
				{
					string text = bt.ToString();
					int value;
					bool flag = prices.TryGetValue(text, out value);
					int cost = (flag ? value : defaultCost);
					return new
					{
						Name = text,
						Cost = cost,
						IsDefault = !flag
					};
				})
				orderby x.Cost
				select x).ThenBy(x => x.Name, StringComparer.OrdinalIgnoreCase).ToList();
			List<string> source2 = source.Select(x => $"{x.Name} : {x.Cost}").ToList();
			foreach (string[] item in source2.Chunk(3))
			{
				stringBuilder.AppendLine(string.Join(" <color=white>|</color> ", item));
			}
			reply(stringBuilder.ToString().TrimEnd());
			reply("<color=yellow>You will receive 1 Blood Merlot with <color=green>100%</color> blood quality.</color>");
		}

		public static void BuyBloodPotion(Entity senderCharacterEntity, ulong steamId, string playerName, BloodType type, Action<string> reply)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			if (!IsEnabled())
			{
				reply("<color=yellow>Buy Blood Potion:</color> <color=red>Disabled.</color>");
				return;
			}
			EntityManager entityManager = Core.EntityManager;
			if (senderCharacterEntity == Entity.Null || !((EntityManager)(ref entityManager)).Exists(senderCharacterEntity))
			{
				LogPurchase(steamId, playerName, type.ToString(), 0, success: false, "Character not ready");
				reply("<color=red>Character not ready.</color>");
				return;
			}
			int cost = GetCost(type.ToString());
			PrefabGUID item = GetCurrency().Prefab;
			if (!TrySpendCurrency(senderCharacterEntity, cost, out var reason))
			{
				LogPurchase(steamId, playerName, type.ToString(), 0, success: false, reason);
				reply("<color=yellow>Unsuccessful!</color> " + reason + ".");
				return;
			}
			Entity val = Helper.AddItemToInventory(senderCharacterEntity, BloodPotionPrefab, 1);
			if (val == Entity.Null || !((EntityManager)(ref entityManager)).Exists(val))
			{
				Helper.AddItemToInventory(senderCharacterEntity, item, cost);
				LogPurchase(steamId, playerName, type.ToString(), 0, success: false, "Inventory is full");
				reply("<color=yellow>Unsuccessful!</color> Inventory is full.");
				return;
			}
			try
			{
				StoredBlood val2 = default(StoredBlood);
				val2.BloodQuality = 100f;
				val2.PrimaryBloodType = new PrefabGUID((int)type);
				StoredBlood val3 = val2;
				((EntityManager)(ref entityManager)).SetComponentData<StoredBlood>(val, val3);
				LogPurchase(steamId, playerName, type.ToString(), cost, success: true, "Successful");
				reply("<color=green>Success!</color> A blood potion was added to your inventory.");
			}
			catch (Exception ex)
			{
				LogPurchase(steamId, playerName, type.ToString(), cost, success: false, "Set stored blood failed: " + ex.Message);
				reply("<color=red>Blood potion was added, but setting the blood data failed.</color>");
				Core.LogException(ex, "BuyBloodPotion");
			}
		}

		private static bool TrySpendCurrency(Entity characterEntity, int amount, out string reason)
		{
			//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_0036: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			reason = string.Empty;
			try
			{
				if (amount <= 0)
				{
					reason = "Invalid cost";
					return false;
				}
				(PrefabGUID Prefab, string Name) currency = GetCurrency();
				PrefabGUID item = currency.Prefab;
				string item2 = currency.Name;
				int itemCountInInventory = Helper.GetItemCountInInventory(characterEntity, item);
				if (itemCountInInventory < amount)
				{
					reason = $"Not enough {item2} ({itemCountInInventory}/{amount})";
					return false;
				}
				if (!Helper.TryRemoveItemsFromInventory(characterEntity, item, amount))
				{
					reason = "Remove items failed";
					return false;
				}
				return true;
			}
			catch (Exception ex)
			{
				reason = "Exception: " + ex.Message;
				return false;
			}
		}

		private static int GetCost(string bloodTypeName)
		{
			ConfigSection config = GetConfig();
			foreach (KeyValuePair<string, int> bloodCost in config.BloodCosts)
			{
				if (string.Equals(bloodCost.Key, bloodTypeName, StringComparison.OrdinalIgnoreCase))
				{
					return (bloodCost.Value > 0) ? bloodCost.Value : config.DefaultCost;
				}
			}
			return config.DefaultCost;
		}

		private static ConfigSection GetConfig()
		{
			return ConfigService.GetBloodPotionConfig();
		}

		private static void LogPurchase(ulong steamId, string playerName, string bloodType, int cost, bool success, string reason)
		{
			try
			{
				lock (LOG_LOCK)
				{
					Directory.CreateDirectory(CONFIG_DIR);
					bool flag = !File.Exists(LOG_FILE);
					using FileStream stream = new FileStream(LOG_FILE, FileMode.Append, FileAccess.Write, FileShare.Read);
					using StreamWriter streamWriter = new StreamWriter(stream, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
					if (flag)
					{
						streamWriter.WriteLine("server_time,steam_id,player_name,blood_type,cost,success,reason");
					}
					streamWriter.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss},{steamId},{Csv(playerName)},{Csv(bloodType)},{cost},{(success ? "true" : "false")},{Csv(reason)}");
				}
			}
			catch
			{
			}
		}

		private static string Csv(string s)
		{
			if (s == null)
			{
				return "\"\"";
			}
			return "\"" + s.Replace("\"", "\"\"") + "\"";
		}
	}
	internal static class BuyPrisonerService
	{
		private static readonly string CONFIG_DIR = Path.Combine(Paths.ConfigPath, "PrisonerBlood");

		private static readonly string LOG_FILE = Path.Combine(CONFIG_DIR, "buyprisoner_log.csv");

		private static readonly object LOG_LOCK = new object();

		private static readonly PrefabGUID PrisonerPrefab = new PrefabGUID(593505050);

		private static readonly PrefabGUID ImprisonedBuffPrefab = new PrefabGUID(1603329680);

		private const float PrisonCellSearchRadius = 3f;

		public static string CurrencyName => GetCurrency().Name;

		public static void Initialize()
		{
			ConfigService.Initialize();
		}

		public static void Reload()
		{
			ConfigService.Reload();
		}

		public static bool IsEnabled()
		{
			return GetConfig().Enabled;
		}

		public static (PrefabGUID Prefab, string Name) GetCurrency()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			ConfigSection config = GetConfig();
			return (new PrefabGUID(config.CurrencyPrefab), config.CurrencyName);
		}

		public static (int DefaultCost, Dictionary<string, int> Prices) GetPriceSnapshot()
		{
			ConfigSection config = GetConfig();
			return (config.DefaultCost, new Dictionary<string, int>(config.BloodCosts, StringComparer.OrdinalIgnoreCase));
		}

		public static bool TryParseBloodTypeStrict(string input, out BloodType type)
		{
			type = (BloodType)0;
			if (string.IsNullOrWhiteSpace(input))
			{
				return false;
			}
			input = input.Trim();
			if (int.TryParse(input, out var _))
			{
				return false;
			}
			if (!Enum.TryParse<BloodType>(input, ignoreCase: true, out type))
			{
				return false;
			}
			return Helper.AllowedBloodTypes.Contains(type);
		}

		public static void ReplyHelp(Action<string> reply, string warningLine = null)
		{
			var (defaultCost, prices) = GetPriceSnapshot();
			if (!string.IsNullOrWhiteSpace(warningLine))
			{
				reply(warningLine);
			}
			reply("<color=yellow>Command:</color> <color=green>.buy prisoner <BloodType></color>");
			reply("<color=yellow>Example:</color> <color=green>.buy prisoner rogue</color>");
			StringBuilder stringBuilder = new StringBuilder();
			StringBuilder stringBuilder2 = stringBuilder;
			StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(89, 1, stringBuilder2);
			handler.AppendLiteral("<color=yellow>Blood types</color> : <color=yellow>Costs</color> (<color=#87CEFA>");
			handler.AppendFormatted(CurrencyName);
			handler.AppendLiteral("</color>)");
			stringBuilder2.AppendLine(ref handler);
			var source = (from x in Helper.AllowedBloodTypes.Select(delegate(BloodType bt)
				{
					string text = bt.ToString();
					int value;
					bool flag = prices.TryGetValue(text, out value);
					int cost = (flag ? value : defaultCost);
					return new
					{
						Name = text,
						Cost = cost,
						IsDefault = !flag
					};
				})
				orderby x.Cost
				select x).ThenBy(x => x.Name, StringComparer.OrdinalIgnoreCase).ToList();
			List<string> source2 = source.Select(x => $"{x.Name} : {x.Cost}").ToList();
			foreach (string[] item in source2.Chunk(3))
			{
				stringBuilder.AppendLine(string.Join(" <color=white>|</color> ", item));
			}
			reply(stringBuilder.ToString().TrimEnd());
			reply($"<color=yellow>A prisoner with <color=green>100%</color> blood quality will be placed in the nearest empty prison cell you own within {3f:0.0}m.</color>");
		}

		public static void BuyPrisoner(Entity senderUserEntity, Entity senderCharacterEntity, ulong steamId, string playerName, BloodType type, Action<string> reply)
		{
			//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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_00dc: 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_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			if (!IsEnabled())
			{
				reply("<color=yellow>Buy Prisoner:</color> <color=red>Disabled.</color>");
				return;
			}
			EntityManager em = Core.EntityManager;
			if (senderCharacterEntity == Entity.Null || !((EntityManager)(ref em)).Exists(senderCharacterEntity))
			{
				LogPurchase(steamId, playerName, type.ToString(), 0, success: false, "Character not ready");
				reply("<color=red>Character not ready.</color>");
				return;
			}
			int cost = GetCost(type.ToString());
			if (!TryFindClosestEmptyOwnedPrisonCell(senderCharacterEntity, 3f, out var prisonCellEntity, out var prisonCellPosition, out var reason))
			{
				LogPurchase(steamId, playerName, type.ToString(), 0, success: false, reason);
				reply("<color=yellow>Unsuccessful!</color> " + reason);
				return;
			}
			if (!TrySpendCurrency(senderCharacterEntity, cost, out reason))
			{
				LogPurchase(steamId, playerName, type.ToString(), 0, success: false, reason);
				reply("<color=yellow>Unsuccessful!</color> " + reason);
				return;
			}
			Core.UnitSpawner.SpawnWithCallback(senderUserEntity, PrisonerPrefab, new float2(prisonCellPosition.x, prisonCellPosition.z), -1f, delegate(Entity e)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0003: 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_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_0032: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (!(e == Entity.Null) && ((EntityManager)(ref em)).Exists(e))
					{
						SetupPurchasedPrisoner(senderUserEntity, e, prisonCellEntity, type);
						LogPurchase(steamId, playerName, type.ToString(), cost, success: true, "Successful");
						reply("<color=green>Success!</color> A prisoner was placed in your prison cell.");
						string message = $"<color=white>{playerName}</color> just spent <color=#87CEFA>{cost} {CurrencyName}</color> to buy a prisoner with <color=green>100%</color> <color=yellow>{type}</color> blood. Learn more, type <color=green>.buy prisoner help</color>";
						Helper.BroadcastSystemMessage(message);
					}
				}
				catch (Exception ex)
				{
					LogPurchase(steamId, playerName, type.ToString(), 0, success: false, "Spawn callback error: " + ex.Message);
					reply("<color=red>Prisoner spawned but setup failed.</color>");
					Core.LogException(ex, "BuyPrisoner");
				}
			}, prisonCellPosition.y);
		}

		private static void SetupPurchasedPrisoner(Entity senderUserEntity, Entity prisonerEntity, Entity prisonCellEntity, BloodType type)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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_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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: 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_00bb: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = Core.EntityManager;
			if (prisonerEntity.Has<BloodConsumeSource>())
			{
				BloodConsumeSource componentData = ((EntityManager)(ref entityManager)).GetComponentData<BloodConsumeSource>(prisonerEntity);
				componentData.UnitBloodType._Value = new PrefabGUID((int)type);
				componentData.BloodQuality = 100f;
				componentData.CanBeConsumed = true;
				((EntityManager)(ref entityManager)).SetComponentData<BloodConsumeSource>(prisonerEntity, componentData);
			}
			if (prisonerEntity.Has<BehaviourTreeState>())
			{
				BehaviourTreeState componentData2 = prisonerEntity.Read<BehaviourTreeState>();
				componentData2.Value = (GenericEnemyState)2048;
				prisonerEntity.Write<BehaviourTreeState>(componentData2);
			}
			if (prisonerEntity.Has<BehaviourTreeStateMetadata>())
			{
				BehaviourTreeStateMetadata componentData3 = prisonerEntity.Read<BehaviourTreeStateMetadata>();
				componentData3.PreviousState = (GenericEnemyState)2048;
				prisonerEntity.Write<BehaviourTreeStateMetadata>(componentData3);
			}
			if (!prisonerEntity.Has<Imprisoned>())
			{
				prisonerEntity.Add<Imprisoned>();
			}
			prisonerEntity.Write<Imprisoned>(new Imprisoned
			{
				PrisonCellEntity = prisonCellEntity
			});
			PrisonCell componentData4 = prisonCellEntity.Read<PrisonCell>();
			componentData4.ImprisonedEntity = NetworkedEntity.op_Implicit(prisonerEntity);
			prisonCellEntity.Write<PrisonCell>(componentData4);
			if (prisonCellEntity.Has<Prisonstation>())
			{
				Prisonstation componentData5 = prisonCellEntity.Read<Prisonstation>();
				componentData5.HasPrisoner = true;
				prisonCellEntity.Write<Prisonstation>(componentData5);
			}
			BuffService.AddBuff(senderUserEntity, prisonerEntity, ImprisonedBuffPrefab);
		}

		private static bool TryFindClosestEmptyOwnedPrisonCell(Entity senderCharacterEntity, float radius, out Entity prisonCellEntity, out float3 prisonCellPosition, out string reason)
		{
			//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_000d: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: 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_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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			prisonCellEntity = Entity.Null;
			prisonCellPosition = default(float3);
			reason = "No empty owned prison cell found";
			EntityManager entityManager = Core.EntityManager;
			if (!((EntityManager)(ref entityManager)).HasComponent<LocalToWorld>(senderCharacterEntity))
			{
				reason = "Cannot find player position";
				return false;
			}
			if (!((EntityManager)(ref entityManager)).HasComponent<Team>(senderCharacterEntity))
			{
				reason = "Cannot read player team";
				return false;
			}
			LocalToWorld componentData = ((EntityManager)(ref entityManager)).GetComponentData<LocalToWorld>(senderCharacterEntity);
			float3 position = ((LocalToWorld)(ref componentData)).Position;
			int value = ((EntityManager)(ref entityManager)).GetComponentData<Team>(senderCharacterEntity).Value;
			float num = radius * radius;
			NativeArray<Entity> entitiesByComponentTypes = Helper.GetEntitiesByComponentTypes<PrisonCell, LocalToWorld>();
			try
			{
				Enumerator<Entity> enumerator = entitiesByComponentTypes.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					if (!((EntityManager)(ref entityManager)).Exists(current) || !((EntityManager)(ref entityManager)).HasComponent<Team>(current) || ((EntityManager)(ref entityManager)).GetComponentData<Team>(current).Value != value)
					{
						continue;
					}
					PrisonCell componentData2 = ((EntityManager)(ref entityManager)).GetComponentData<PrisonCell>(current);
					Entity entity = componentData2.ImprisonedEntity._Entity;
					if (!(entity != Entity.Null) || !((EntityManager)(ref entityManager)).Exists(entity))
					{
						componentData = ((EntityManager)(ref entityManager)).GetComponentData<LocalToWorld>(current);
						float3 position2 = ((LocalToWorld)(ref componentData)).Position;
						float num2 = math.distancesq(position, position2);
						if (!(num2 > num))
						{
							num = num2;
							prisonCellEntity = current;
							prisonCellPosition = position2;
						}
					}
				}
			}
			finally
			{
				entitiesByComponentTypes.Dispose();
			}
			return prisonCellEntity != Entity.Null;
		}

		private static bool TrySpendCurrency(Entity characterEntity, int amount, out string reason)
		{
			//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_0036: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			reason = string.Empty;
			try
			{
				if (amount <= 0)
				{
					reason = "Invalid cost";
					return false;
				}
				(PrefabGUID Prefab, string Name) currency = GetCurrency();
				PrefabGUID item = currency.Prefab;
				string item2 = currency.Name;
				int itemCountInInventory = Helper.GetItemCountInInventory(characterEntity, item);
				if (itemCountInInventory < amount)
				{
					reason = $"Not enough {item2} ({itemCountInInventory}/{amount})";
					return false;
				}
				if (!Helper.TryRemoveItemsFromInventory(characterEntity, item, amount))
				{
					reason = "Remove items failed";
					return false;
				}
				return true;
			}
			catch (Exception ex)
			{
				reason = "Exception: " + ex.Message;
				return false;
			}
		}

		private static int GetCost(string bloodTypeName)
		{
			ConfigSection config = GetConfig();
			foreach (KeyValuePair<string, int> bloodCost in config.BloodCosts)
			{
				if (string.Equals(bloodCost.Key, bloodTypeName, StringComparison.OrdinalIgnoreCase))
				{
					return (bloodCost.Value > 0) ? bloodCost.Value : config.DefaultCost;
				}
			}
			return config.DefaultCost;
		}

		private static ConfigSection GetConfig()
		{
			return ConfigService.GetPrisonerConfig();
		}

		private static void LogPurchase(ulong steamId, string playerName, string bloodType, int cost, bool success, string reason)
		{
			try
			{
				lock (LOG_LOCK)
				{
					Directory.CreateDirectory(CONFIG_DIR);
					bool flag = !File.Exists(LOG_FILE);
					using FileStream stream = new FileStream(LOG_FILE, FileMode.Append, FileAccess.Write, FileShare.Read);
					using StreamWriter streamWriter = new StreamWriter(stream, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
					if (flag)
					{
						streamWriter.WriteLine("server_time,steam_id,player_name,blood_type,cost,success,reason");
					}
					streamWriter.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss},{steamId},{Csv(playerName)},{Csv(bloodType)},{cost},{(success ? "true" : "false")},{Csv(reason)}");
				}
			}
			catch
			{
			}
		}

		private static string Csv(string s)
		{
			if (s == null)
			{
				return "\"\"";
			}
			return "\"" + s.Replace("\"", "\"\"") + "\"";
		}
	}
	internal static class ConfigService
	{
		private static readonly string CONFIG_DIR = Path.Combine(Paths.ConfigPath, "PrisonerBlood");

		private static readonly string CONFIG_FILE = Path.Combine(CONFIG_DIR, "buyconfig.json");

		private static readonly object IO_LOCK = new object();

		private static DateTime _lastWrite = DateTime.MinValue;

		private static ConfigRoot _root = new ConfigRoot();

		private static readonly JsonSerializerOptions JsonOptions = new JsonSerializerOptions
		{
			AllowTrailingCommas = true,
			PropertyNameCaseInsensitive = true,
			ReadCommentHandling = JsonCommentHandling.Skip,
			WriteIndented = true
		};

		public static string ConfigFileName => "buyconfig.json";

		public static void Initialize()
		{
			Load(force: true);
		}

		public static void Reload()
		{
			Load(force: true);
		}

		public static ConfigSection GetPrisonerConfig()
		{
			Load(force: false);
			lock (IO_LOCK)
			{
				return CloneAndNormalize(_root.Prisoner, CreateDefaultRoot().Prisoner);
			}
		}

		public static ConfigSection GetBloodPotionConfig()
		{
			Load(force: false);
			lock (IO_LOCK)
			{
				return CloneAndNormalize(_root.BloodPotion, CreateDefaultRoot().BloodPotion);
			}
		}

		private static void Load(bool force)
		{
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Expected O, but got Unknown
			lock (IO_LOCK)
			{
				try
				{
					Directory.CreateDirectory(CONFIG_DIR);
					if (!File.Exists(CONFIG_FILE))
					{
						_root = CreateDefaultRoot();
						File.WriteAllText(CONFIG_FILE, JsonSerializer.Serialize(_root, JsonOptions));
						_lastWrite = File.GetLastWriteTime(CONFIG_FILE);
						return;
					}
					DateTime lastWriteTime = File.GetLastWriteTime(CONFIG_FILE);
					if (force || !(lastWriteTime <= _lastWrite))
					{
						string json = File.ReadAllText(CONFIG_FILE);
						_root = JsonSerializer.Deserialize<ConfigRoot>(json, JsonOptions) ?? CreateDefaultRoot();
						NormalizeRoot(_root);
						_lastWrite = lastWriteTime;
					}
				}
				catch (Exception ex)
				{
					ManualLogSource log = Core.Log;
					bool flag = default(bool);
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(33, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ConfigService] Failed to load ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ConfigFileName);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
					}
					log.LogError(val);
					_root = CreateDefaultRoot();
				}
			}
		}

		private static void NormalizeRoot(ConfigRoot root)
		{
			ConfigRoot configRoot = CreateDefaultRoot();
			root.Prisoner = CloneAndNormalize(root.Prisoner, configRoot.Prisoner);
			root.BloodPotion = CloneAndNormalize(root.BloodPotion, configRoot.BloodPotion);
		}

		private static ConfigSection CloneAndNormalize(ConfigSection config, ConfigSection defaults)
		{
			if (config == null)
			{
				config = new ConfigSection();
			}
			if (defaults == null)
			{
				defaults = new ConfigSection();
			}
			Dictionary<string, int> dictionary = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
			foreach (KeyValuePair<string, int> item in config.BloodCosts ?? new Dictionary<string, int>())
			{
				if (!string.IsNullOrWhiteSpace(item.Key) && item.Value > 0)
				{
					dictionary[item.Key.Trim()] = item.Value;
				}
			}
			return new ConfigSection
			{
				Enabled = config.Enabled,
				CurrencyPrefab = ((config.CurrencyPrefab != 0) ? config.CurrencyPrefab : defaults.CurrencyPrefab),
				CurrencyName = (string.IsNullOrWhiteSpace(config.CurrencyName) ? defaults.CurrencyName : config.CurrencyName.Trim()),
				DefaultCost = ((config.DefaultCost > 0) ? config.DefaultCost : defaults.DefaultCost),
				BloodCosts = ((dictionary.Count > 0) ? dictionary : new Dictionary<string, int>(defaults.BloodCosts, StringComparer.OrdinalIgnoreCase))
			};
		}

		private static ConfigRoot CreateDefaultRoot()
		{
			return new ConfigRoot
			{
				Prisoner = new ConfigSection
				{
					Enabled = true,
					CurrencyPrefab = 576389135,
					CurrencyName = "Greater Stygian Shards",
					DefaultCost = 5000,
					BloodCosts = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase)
					{
						{ "Worker", 4000 },
						{ "Creature", 4200 },
						{ "Mutant", 4500 },
						{ "Corrupted", 4800 },
						{ "Draculin", 5000 },
						{ "Warrior", 5200 },
						{ "Rogue", 5500 },
						{ "Brute", 5700 },
						{ "Scholar", 6000 }
					}
				},
				BloodPotion = new ConfigSection
				{
					Enabled = true,
					CurrencyPrefab = 576389135,
					CurrencyName = "Greater Stygian Shards",
					DefaultCost = 500,
					BloodCosts = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase)
					{
						{ "Worker", 300 },
						{ "Creature", 350 },
						{ "Mutant", 400 },
						{ "Corrupted", 450 },
						{ "Draculin", 500 },
						{ "Warrior", 550 },
						{ "Rogue", 600 },
						{ "Brute", 650 },
						{ "Scholar", 700 }
					}
				}
			};
		}
	}
	internal class UnitSpawnerService
	{
		[HarmonyPatch(typeof(UnitSpawnerReactSystem), "OnUpdate")]
		public static class UnitSpawnerReactSystemPatch
		{
			public static bool Enabled { get; set; }

			public static void Prefix(UnitSpawnerReactSystem __instance)
			{
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_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_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				//IL_0068: Unknown result type (might be due to invalid IL or missing references)
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_006f: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_0101: Unknown result type (might be due to invalid IL or missing references)
				if (!Enabled)
				{
					return;
				}
				EntityQuery query = __instance._Query;
				NativeArray<Entity> val = ((EntityQuery)(ref query)).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))
					{
						entityManager = Core.EntityManager;
						LifeTime componentData = ((EntityManager)(ref entityManager)).GetComponentData<LifeTime>(current);
						long key = (long)Mathf.Round(componentData.Duration);
						if (Core.UnitSpawner.PostActions.TryGetValue(key, out (float, Action<Entity>) value))
						{
							var (num, action) = value;
							Core.UnitSpawner.PostActions.Remove(key);
							LifeTimeEndAction endAction = (LifeTimeEndAction)((!(num < 0f)) ? 2 : 0);
							LifeTime val2 = default(LifeTime);
							val2.Duration = num;
							val2.EndAction = endAction;
							LifeTime val3 = val2;
							entityManager = Core.EntityManager;
							((EntityManager)(ref entityManager)).SetComponentData<LifeTime>(current, val3);
							action(current);
						}
					}
				}
				val.Dispose();
			}
		}

		private static readonly Entity EmptyEntity = default(Entity);

		internal const int DefaultMinRange = 1;

		internal const int DefaultMaxRange = 1;

		internal Dictionary<long, (float ActualDuration, Action<Entity> Actions)> PostActions { get; } = new Dictionary<long, (float, Action<Entity>)>();


		public void SpawnWithCallback(Entity user, PrefabGUID unit, float2 position, float duration, Action<Entity> postActions, float yPosition = -1f)
		{
			//IL_0031: 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_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			if (yPosition == -1f)
			{
				EntityManager entityManager = Core.EntityManager;
				Translation componentData = ((EntityManager)(ref entityManager)).GetComponentData<Translation>(user);
				yPosition = componentData.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, 1f, 1f, (float)num);
			PostActions.Add(num, (duration, postActions));
		}

		private 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 PrisonerBlood.Patches
{
	[HarmonyPatch(typeof(ServerBootstrapSystem), "OnUpdate")]
	public static class InitializationPatch
	{
		private static bool _initialized;

		[HarmonyPostfix]
		public static void OneShot_AfterServerBootstrap()
		{
			if (!_initialized && Plugin.HasLoaded())
			{
				_initialized = true;
				Core.InitializeAfterLoaded();
			}
		}
	}
}
namespace PrisonerBlood.Models
{
	public enum BloodType
	{
		Creature = 524822543,
		Warrior = -516976528,
		Rogue = -1620185637,
		Brute = 804798592,
		Scholar = 1476452791,
		Worker = -1776904174,
		Mutant = 1821108694,
		Draculin = 1328126535,
		Corrupted = -1382693416
	}
	internal sealed class ConfigRoot
	{
		public ConfigSection Prisoner { get; set; } = new ConfigSection();


		public ConfigSection BloodPotion { get; set; } = new ConfigSection();

	}
	internal sealed class ConfigSection
	{
		public bool Enabled { get; set; } = true;


		public int CurrencyPrefab { get; set; }

		public string CurrencyName { get; set; } = string.Empty;


		public int DefaultCost { get; set; }

		public Dictionary<string, int> BloodCosts { get; set; } = new Dictionary<string, int>();

	}
}
namespace PrisonerBlood.Commands
{
	[CommandGroup("buy", null)]
	internal static class BuyCommands
	{
		[Command("prisoner", "ps", null, "Buy a prisoner with 100% blood quality into a nearby empty prison cell.", null, false)]
		public static void BuyPrisoner(ChatCommandContext ctx, string arg = "")
		{
			//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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			arg = (arg ?? string.Empty).Trim();
			if (string.IsNullOrWhiteSpace(arg) || arg.Equals("help", StringComparison.OrdinalIgnoreCase))
			{
				BuyPrisonerService.ReplyHelp((Action<string>)ctx.Reply, (string)null);
				return;
			}
			if (!BuyPrisonerService.TryParseBloodTypeStrict(arg, out var type))
			{
				BuyPrisonerService.ReplyHelp((Action<string>)ctx.Reply, "<color=yellow>Invalid blood type.</color>");
				return;
			}
			User val = ctx.Event.SenderUserEntity.Read<User>();
			BuyPrisonerService.BuyPrisoner(ctx.Event.SenderUserEntity, ctx.Event.SenderCharacterEntity, val.PlatformId, ((object)(FixedString64Bytes)(ref val.CharacterName)).ToString(), type, (Action<string>)ctx.Reply);
		}

		[Command("bloodpotion", "bp", null, "Buy a 100% Blood Merlot potion into your inventory.", null, false)]
		public static void BuyBloodPotion(ChatCommandContext ctx, string arg = "")
		{
			//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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			arg = (arg ?? string.Empty).Trim();
			if (string.IsNullOrWhiteSpace(arg) || arg.Equals("help", StringComparison.OrdinalIgnoreCase))
			{
				BuyBloodPotionService.ReplyHelp((Action<string>)ctx.Reply, (string)null);
				return;
			}
			if (!BuyBloodPotionService.TryParseBloodTypeStrict(arg, out var type))
			{
				BuyBloodPotionService.ReplyHelp((Action<string>)ctx.Reply, "<color=yellow>Invalid blood type.</color>");
				return;
			}
			User val = ctx.Event.SenderUserEntity.Read<User>();
			BuyBloodPotionService.BuyBloodPotion(ctx.Event.SenderCharacterEntity, val.PlatformId, ((object)(FixedString64Bytes)(ref val.CharacterName)).ToString(), type, (Action<string>)ctx.Reply);
		}

		[Command("reload", "rl", null, "Reload buyconfig.json.", null, true)]
		public static void Reload(ChatCommandContext ctx)
		{
			ConfigService.Reload();
			ctx.Reply("<color=green>buyconfig.json reloaded.</color>");
		}
	}
}