Decompiled source of BloodRefill v1.2.1

VMods.BloodRefill.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.Json;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Bloodstone.API;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.CastleBuilding;
using ProjectM.Network;
using ProjectM.UI;
using SemanticVersioning;
using Stunlock.Core;
using Stunlock.Localization;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Entities;
using UnityEngine;
using VMods.BloodRefill.Commands;
using VMods.BloodRefill.Commands.VCFCompat;
using VMods.Shared;
using VampireCommandFramework;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("VMods.BloodRefill")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Allows a player to refill his/her blood pool")]
[assembly: AssemblyFileVersion("1.2.1.0")]
[assembly: AssemblyInformationalVersion("1.2.1")]
[assembly: AssemblyProduct("VMods.BloodRefill")]
[assembly: AssemblyTitle("VMods.BloodRefill")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.1.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class IsUnmanagedAttribute : Attribute
	{
	}
}
namespace VMods.Shared
{
	[HarmonyPatch]
	public static class SaveHook
	{
		[HarmonyPatch(typeof(TriggerPersistenceSaveSystem), "TriggerSave")]
		[HarmonyPrefix]
		private static void TriggerSave()
		{
			SaveSystem.SaveAll();
		}

		[HarmonyPatch(typeof(ServerBootstrapSystem), "OnDestroy")]
		[HarmonyPrefix]
		private static void OnDestroy()
		{
			SaveSystem.SaveAll();
		}
	}
	public enum BloodType
	{
		Frailed = -899826404,
		Creature = -77658840,
		Warrior = -1094467405,
		Rogue = 793735874,
		Brute = 581377887,
		Scholar = -586506765,
		Worker = -540707191,
		VBlood = 1557174542,
		Mutant = -2017994753
	}
	public static class BloodTypeExtensions
	{
		public static readonly Dictionary<BloodType, PrefabGUID> BloodTypeToPrefabGUIDMapping = new Dictionary<BloodType, PrefabGUID>
		{
			[BloodType.Creature] = new PrefabGUID(1897056612),
			[BloodType.Warrior] = new PrefabGUID(-1128238456),
			[BloodType.Rogue] = new PrefabGUID(-1030822544),
			[BloodType.Brute] = new PrefabGUID(-1464869978),
			[BloodType.Scholar] = new PrefabGUID(-700632469),
			[BloodType.Worker] = new PrefabGUID(-1342764880),
			[BloodType.Mutant] = new PrefabGUID(572729167)
		};

		public static bool ParseBloodType(this PrefabGUID prefabGUID, out BloodType bloodType)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			int guidHash = prefabGUID.GuidHash;
			if (!Enum.IsDefined(typeof(BloodType), guidHash))
			{
				bloodType = BloodType.Frailed;
				return false;
			}
			bloodType = (BloodType)guidHash;
			return true;
		}

		public static BloodType? ToBloodType(this PrefabGUID prefabGUID)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			int guidHash = prefabGUID.GuidHash;
			if (!Enum.IsDefined(typeof(BloodType), guidHash))
			{
				return null;
			}
			return (BloodType)guidHash;
		}

		public static PrefabGUID ToPrefabGUID(this BloodType bloodType)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return BloodTypeToPrefabGUIDMapping[bloodType];
		}

		public static void ApplyToPlayer(this BloodType bloodType, User user, float quality, int addAmount)
		{
			//IL_0002: 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_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_0031: Unknown result type (might be due to invalid IL or missing references)
			ConsumeBloodDebugEvent val = default(ConsumeBloodDebugEvent);
			val.Source = bloodType.ToPrefabGUID();
			val.Quality = quality;
			val.Amount = addAmount;
			ConsumeBloodDebugEvent val2 = val;
			VWorld.Server.GetExistingSystem<DebugEventsSystem>().ConsumeBloodEvent(user.Index, ref val2);
		}
	}
	[HarmonyPatch]
	public static class DeathHook
	{
		public delegate void DeathEventHandler(DeathEvent deathEvent);

		public static event DeathEventHandler DeathEvent;

		private static void FireDeathEvent(DeathEvent deathEvent)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			DeathHook.DeathEvent?.Invoke(deathEvent);
		}

		[HarmonyPatch(typeof(DeathEventListenerSystem), "OnUpdate")]
		[HarmonyPostfix]
		private static void OnUpdate(DeathEventListenerSystem __instance)
		{
			//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_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_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_0035: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!VWorld.IsServer)
				{
					return;
				}
				EntityQuery deathEventQuery = __instance._DeathEventQuery;
				if (!((EntityQuery)(ref deathEventQuery)).IsEmpty)
				{
					deathEventQuery = __instance._DeathEventQuery;
					Enumerator<DeathEvent> enumerator = ((EntityQuery)(ref deathEventQuery)).ToComponentDataArray<DeathEvent>((Allocator)2).GetEnumerator();
					while (enumerator.MoveNext())
					{
						FireDeathEvent(enumerator.Current);
					}
				}
			}
			catch (Exception ex)
			{
				Utils.Logger.LogError((object)ex.Message);
			}
		}
	}
	public static class Utils
	{
		private struct FakeNull
		{
			public int value;

			public bool has_value;
		}

		private static ComponentType[] _containerComponents;

		public static World CurrentWorld => VWorld.Game;

		public static ManualLogSource Logger { get; private set; }

		public static string PluginName { get; private set; }

		private static ComponentType[] ContainerComponents
		{
			get
			{
				//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_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_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0047: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: Unknown result type (might be due to invalid IL or missing references)
				if (_containerComponents == null)
				{
					_containerComponents = (ComponentType[])(object)new ComponentType[4]
					{
						ComponentType.ReadOnly(Il2CppType.Of<Team>()),
						ComponentType.ReadOnly(Il2CppType.Of<CastleHeartConnection>()),
						ComponentType.ReadOnly(Il2CppType.Of<InventoryBuffer>()),
						ComponentType.ReadOnly(Il2CppType.Of<NameableInteractable>())
					};
				}
				return _containerComponents;
			}
		}

		public static void Initialize(ManualLogSource logger, string pluginName)
		{
			Logger = logger;
			PluginName = pluginName;
		}

		public static void Deinitialize()
		{
			Logger = null;
		}

		public static NativeArray<Entity> GetStashEntities(EntityManager entityManager)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			EntityQuery val = ((EntityManager)(ref entityManager)).CreateEntityQuery(ContainerComponents);
			return ((EntityQuery)(ref val)).ToEntityArray((Allocator)2);
		}

		public static IEnumerable<Entity> GetAlliedStashes(EntityManager entityManager, Entity character)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			ComponentDataFromEntity<Team> getTeam = ((EntityManager)(ref entityManager)).GetComponentDataFromEntity<Team>(false);
			Enumerator<Entity> enumerator = GetStashEntities(entityManager).GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				if (((EntityManager)(ref entityManager)).HasComponent<Team>(current) && ((EntityManager)(ref entityManager)).HasComponent<Team>(character))
				{
					Team val = getTeam[current];
					Team val2 = getTeam[character];
					if (Team.IsAllies(val, val2))
					{
						yield return current;
					}
				}
			}
		}

		public static int GetStashItemCount(EntityManager entityManager, Entity character, PrefabGUID itemGUID, StoredBlood? storedBlood = null)
		{
			//IL_0004: 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_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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			int num2 = 0;
			DynamicBuffer<InventoryBuffer> val = default(DynamicBuffer<InventoryBuffer>);
			StoredBlood val3 = default(StoredBlood);
			foreach (Entity alliedStash in GetAlliedStashes(entityManager, character))
			{
				((EntityManager)(ref entityManager)).TryGetBuffer<InventoryBuffer>(alliedStash, ref val);
				for (int i = 0; i < val.Length; i++)
				{
					InventoryBuffer val2 = val[i];
					if (!(val2.ItemType == itemGUID))
					{
						continue;
					}
					if (storedBlood.HasValue)
					{
						((EntityManager)(ref entityManager)).TryGetComponentData<StoredBlood>(val2.ItemEntity._Entity, ref val3);
						if (storedBlood.Value.BloodType != val3.BloodType || storedBlood.Value.BloodQuality != val3.BloodQuality)
						{
							continue;
						}
					}
					num += val2.Amount;
				}
				num2++;
			}
			if (num2 != 0)
			{
				return num;
			}
			return -1;
		}

		public static string GetItemName(PrefabGUID itemGUID, GameDataSystem gameDataSystem = null, EntityManager? entityManager = null, PrefabLookupMap? prefabLookupMap = null)
		{
			//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_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_00b4: 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_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_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_0069: 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_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_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)
			if (itemGUID == PrefabGUID.Empty)
			{
				return string.Empty;
			}
			EntityManager valueOrDefault = entityManager.GetValueOrDefault();
			if (!entityManager.HasValue)
			{
				valueOrDefault = CurrentWorld.EntityManager;
				entityManager = valueOrDefault;
			}
			if (gameDataSystem == null)
			{
				gameDataSystem = CurrentWorld.GetExistingSystem<GameDataSystem>();
			}
			PrefabLookupMap valueOrDefault2 = prefabLookupMap.GetValueOrDefault();
			if (!prefabLookupMap.HasValue)
			{
				valueOrDefault2 = ((PrefabCollectionSystem_Base)CurrentWorld.GetExistingSystem<PrefabCollectionSystem>()).PrefabLookupMap;
				prefabLookupMap = valueOrDefault2;
			}
			try
			{
				AssetGuid val = GameplayHelper.TryGetItemName(gameDataSystem, entityManager.Value, prefabLookupMap.Value, itemGUID);
				if (Localization.HasKey(val))
				{
					return Localization.Get(val, true);
				}
			}
			catch (Exception)
			{
			}
			return $"[{itemGUID}]";
		}

		public static void SendMessage(Entity userEntity, string message, ServerChatMessageType messageType)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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_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_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_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_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_0070: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			if (VWorld.IsServer)
			{
				EntityManager entityManager = VWorld.Server.EntityManager;
				User val = default(User);
				((EntityManager)(ref entityManager)).TryGetComponentData<User>(userEntity, ref val);
				int index = val.Index;
				NetworkId fromUser = default(NetworkId);
				((EntityManager)(ref entityManager)).TryGetComponentData<NetworkId>(userEntity, ref fromUser);
				Entity val2 = ((EntityManager)(ref entityManager)).CreateEntity((ComponentType[])(object)new ComponentType[3]
				{
					ComponentType.ReadOnly<NetworkEventType>(),
					ComponentType.ReadOnly<SendEventToUser>(),
					ComponentType.ReadOnly<ChatMessageServerEvent>()
				});
				ChatMessageServerEvent val3 = default(ChatMessageServerEvent);
				val3.MessageText = FixedString512.op_Implicit(message);
				val3.MessageType = messageType;
				val3.FromUser = fromUser;
				val3.TimeUTC = DateTime.Now.ToFileTimeUtc();
				ChatMessageServerEvent val4 = val3;
				val2.WithComponentDataVmodAOT<SendEventToUser>((VModsVExtensionsOverride.ActionRefVmod<SendEventToUser>)delegate(ref SendEventToUser us)
				{
					us.UserIndex = index;
				});
				val2.WithComponentDataVmodAOT<NetworkEventType>((VModsVExtensionsOverride.ActionRefVmod<NetworkEventType>)delegate(ref NetworkEventType ev)
				{
					ev.EventId = NetworkEvents.EventId_ChatMessageServerEvent;
					ev.IsAdminEvent = false;
					ev.IsDebugEvent = false;
				});
				((EntityManager)(ref entityManager)).SetComponentData<ChatMessageServerEvent>(val2, val4);
			}
		}

		public static bool TryGetPrefabGUIDForItemName(GameDataSystem gameDataSystem, LocalizationKey itemName, out PrefabGUID prefabGUID)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return TryGetPrefabGUIDForItemName(gameDataSystem, Localization.Get(itemName, true), out prefabGUID);
		}

		public static bool TryGetPrefabGUIDForItemName(GameDataSystem gameDataSystem, string itemName, out PrefabGUID prefabGUID)
		{
			//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_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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_002c: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			Enumerator<PrefabGUID, ItemData> enumerator = gameDataSystem.ItemHashLookupMap.GetEnumerator();
			while (enumerator.MoveNext())
			{
				KeyValue<PrefabGUID, ItemData> current = enumerator.Current;
				if (Localization.Get(gameDataSystem.ManagedDataRegistry.GetOrDefault<ManagedItemData>(current.Key, (ManagedItemData)null).Name, false) == itemName)
				{
					prefabGUID = current.Key;
					return true;
				}
			}
			prefabGUID = PrefabGUID.Empty;
			return false;
		}

		public static bool TryGiveItem(EntityManager entityManager, NativeHashMap<PrefabGUID, ItemData>? itemDataMap, Entity recipient, PrefabGUID itemType, int amount, out int remainingitems, bool dropRemainder = false)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_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_0062: 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)
			NativeHashMap<PrefabGUID, ItemData> valueOrDefault = itemDataMap.GetValueOrDefault();
			if (!itemDataMap.HasValue)
			{
				valueOrDefault = CurrentWorld.GetExistingSystem<GameDataSystem>().ItemHashLookupMap;
				itemDataMap = valueOrDefault;
			}
			AddItemResponse val = InventoryUtilitiesServer.TryAddItem(AddItemSettings.Create(entityManager, itemDataMap.Value, false, default(Entity), default(Nullable_Unboxed<int>), false, false, dropRemainder, default(Nullable_Unboxed<int>)), recipient, itemType, amount);
			remainingitems = val.RemainingAmount;
			return ((AddItemResponse)(ref val)).Success;
		}

		public static void ApplyBuff(Entity user, Entity character, PrefabGUID buffGUID)
		{
			//IL_0002: 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_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			FromCharacter fromCharacter = default(FromCharacter);
			fromCharacter.User = user;
			fromCharacter.Character = character;
			ApplyBuff(fromCharacter, buffGUID);
		}

		public static void ApplyBuff(FromCharacter fromCharacter, PrefabGUID buffGUID)
		{
			//IL_000c: 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_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_001d: Unknown result type (might be due to invalid IL or missing references)
			DebugEventsSystem existingSystem = VWorld.Server.GetExistingSystem<DebugEventsSystem>();
			ApplyBuffDebugEvent val = new ApplyBuffDebugEvent
			{
				BuffPrefabGUID = buffGUID
			};
			existingSystem.ApplyBuff(fromCharacter, val);
		}

		public static void RemoveBuff(FromCharacter fromCharacter, PrefabGUID buffGUID)
		{
			//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)
			RemoveBuff(fromCharacter.Character, buffGUID);
		}

		public static void RemoveBuff(Entity charEntity, PrefabGUID buffGUID, EntityManager? entityManager = null)
		{
			//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_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_002c: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			EntityManager value = entityManager.GetValueOrDefault();
			if (!entityManager.HasValue)
			{
				value = CurrentWorld.EntityManager;
				entityManager = value;
			}
			if (BuffUtility.HasBuff(entityManager.Value, charEntity, buffGUID))
			{
				Entity val = default(Entity);
				BuffUtility.TryGetBuff(entityManager.Value, charEntity, buffGUID, ref val);
				value = entityManager.Value;
				((EntityManager)(ref value)).AddComponent<DestroyTag>(val);
			}
		}

		public static string GetCharacterName(ulong platformId, EntityManager? entityManager = null)
		{
			//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_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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_006c: 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)
			EntityManager value = entityManager.GetValueOrDefault();
			if (!entityManager.HasValue)
			{
				value = CurrentWorld.EntityManager;
				entityManager = value;
			}
			value = entityManager.Value;
			EntityQuery val = ((EntityManager)(ref value)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<User>() });
			Enumerator<Entity> enumerator = ((EntityQuery)(ref val)).ToEntityArray((Allocator)2).GetEnumerator();
			User val2 = default(User);
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				value = entityManager.Value;
				((EntityManager)(ref value)).TryGetComponentData<User>(current, ref val2);
				if (val2.PlatformId == platformId)
				{
					return ((object)(FixedString64)(ref val2.CharacterName)).ToString();
				}
			}
			return null;
		}

		public static AdminLevel GetAdminLevel(Entity userEntity, EntityManager? entityManager = null)
		{
			//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_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_002e: 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_0038: 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)
			EntityManager value = entityManager.GetValueOrDefault();
			if (!entityManager.HasValue)
			{
				value = CurrentWorld.EntityManager;
				entityManager = value;
			}
			value = entityManager.Value;
			AdminUser val = default(AdminUser);
			if (((EntityManager)(ref value)).TryGetComponentData<AdminUser>(userEntity, ref val))
			{
				return val.Level;
			}
			return (AdminLevel)0;
		}

		public static void LogAllComponentTypes(Entity entity, EntityManager? entityManager = null)
		{
			//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_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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_0024: 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_002c: 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_005f: 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_0069: 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_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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			if (entity == Entity.Null)
			{
				return;
			}
			EntityManager value = entityManager.GetValueOrDefault();
			if (!entityManager.HasValue)
			{
				value = CurrentWorld.EntityManager;
				entityManager = value;
			}
			ManualLogSource logger = Logger;
			bool flag = default(bool);
			BepInExMessageLogInterpolatedStringHandler val = new BepInExMessageLogInterpolatedStringHandler(3, 0, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("---");
			}
			logger.LogMessage(val);
			value = entityManager.Value;
			Enumerator<ComponentType> enumerator = ((EntityManager)(ref value)).GetComponentTypes(entity, (Allocator)2).GetEnumerator();
			while (enumerator.MoveNext())
			{
				ComponentType current = enumerator.Current;
				ManualLogSource logger2 = Logger;
				val = new BepInExMessageLogInterpolatedStringHandler(30, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Component Type: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ComponentType>(current);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (Shared? ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(((ComponentType)(ref current)).IsSharedComponent);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(") | ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((ComponentType)(ref current)).GetManagedType().FullName);
				}
				logger2.LogMessage(val);
			}
			ManualLogSource logger3 = Logger;
			val = new BepInExMessageLogInterpolatedStringHandler(3, 0, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("---");
			}
			logger3.LogMessage(val);
		}

		public static void LogAllComponentTypes(EntityQuery entityQuery)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_0058: 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: Expected O, but got Unknown
			Il2CppStructArray<ComponentType> queryTypes = ((EntityQuery)(ref entityQuery)).GetQueryTypes();
			ManualLogSource logger = Logger;
			bool flag = default(bool);
			BepInExMessageLogInterpolatedStringHandler val = new BepInExMessageLogInterpolatedStringHandler(3, 0, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("---");
			}
			logger.LogMessage(val);
			foreach (ComponentType item in (Il2CppArrayBase<ComponentType>)(object)queryTypes)
			{
				ManualLogSource logger2 = Logger;
				val = new BepInExMessageLogInterpolatedStringHandler(22, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Query Component Type: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ComponentType>(item);
				}
				logger2.LogMessage(val);
			}
			ManualLogSource logger3 = Logger;
			val = new BepInExMessageLogInterpolatedStringHandler(3, 0, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("---");
			}
			logger3.LogMessage(val);
		}
	}
	public static class VModsVExtensionsOverride
	{
		public delegate void ActionRefVmod<T>(ref T item);

		public static void WithComponentDataVmod<T>(this Entity entity, ActionRefVmod<T> action) where T : struct
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_002b: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = VWorld.Game.EntityManager;
			T item = default(T);
			((EntityManager)(ref entityManager)).TryGetComponentData<T>(entity, ref item);
			action(ref item);
			entityManager = VWorld.Game.EntityManager;
			((EntityManager)(ref entityManager)).SetComponentData<T>(entity, item);
		}

		public static void WithComponentDataVmodAOT<T>(this Entity entity, ActionRefVmod<T> action) where T : unmanaged
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			T item = VWorld.Game.EntityManager.GetComponentDataAOT<T>(entity);
			action(ref item);
			EntityManager entityManager = VWorld.Game.EntityManager;
			((EntityManager)(ref entityManager)).SetComponentData<T>(entity, item);
		}

		private static Type GetType<T>()
		{
			return Il2CppType.Of<T>();
		}

		public unsafe static T GetComponentDataAOT<T>(this EntityManager entityManager, Entity entity) where T : unmanaged
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			int typeIndex = TypeManager.GetTypeIndex(GetType<T>());
			T* componentDataRawRW = (T*)((EntityManager)(ref entityManager)).GetComponentDataRawRW(entity, typeIndex);
			return *componentDataRawRW;
		}
	}
}
namespace VMods.BloodRefill
{
	public static class BloodRefillConfig
	{
		public static ConfigEntry<bool> BloodRefillEnabled { get; private set; }

		public static ConfigEntry<bool> BloodRefillCreatureEnabled { get; private set; }

		public static ConfigEntry<bool> BloodRefillWarriorEnabled { get; private set; }

		public static ConfigEntry<bool> BloodRefillRogueEnabled { get; private set; }

		public static ConfigEntry<bool> BloodRefillBruteEnabled { get; private set; }

		public static ConfigEntry<bool> BloodRefillScholarEnabled { get; private set; }

		public static ConfigEntry<bool> BloodRefillWorkerEnabled { get; private set; }

		public static ConfigEntry<bool> BloodRefillMutantEnabled { get; private set; }

		public static ConfigEntry<bool> BloodRefillVBloodEnabled { get; private set; }

		public static ConfigEntry<bool> BloodRefillRequiresFeeding { get; private set; }

		public static ConfigEntry<bool> BloodRefillRequiresSameBloodType { get; private set; }

		public static ConfigEntry<bool> BloodRefillExcludeVBloodFromSameBloodTypeCheck { get; private set; }

		public static ConfigEntry<float> BloodRefillDifferentBloodTypeMultiplier { get; private set; }

		public static ConfigEntry<int> BloodRefillVBloodRefillType { get; private set; }

		public static ConfigEntry<int> BloodRefillBloodRefillType { get; private set; }

		public static ConfigEntry<float> BloodRefillVBloodRefillMultiplier { get; private set; }

		public static ConfigEntry<bool> BloodRefillRandomRefill { get; private set; }

		public static ConfigEntry<float> BloodRefillAmount { get; private set; }

		public static ConfigEntry<float> BloodRefillMultiplier { get; private set; }

		public static ConfigEntry<bool> BloodRefillSendRefillMessage { get; private set; }

		public static ConfigEntry<float> BloodRefillBloodCutoffThreshold { get; private set; }

		public static ConfigEntry<float> BloodRefillVBloodCutoffThreshold { get; private set; }

		public static void Initialize(ConfigFile config)
		{
			BloodRefillEnabled = config.Bind<bool>("BloodRefillConfig", "BloodRefillEnabled", true, "Enabled/disable the blood refilling system.");
			BloodRefillRequiresFeeding = config.Bind<bool>("BloodRefillConfig", "BloodRefillRequiresFeeding", true, "When enabled, blood can only be refilled when feeding (i.e. when aborting the feed).");
			BloodRefillRequiresSameBloodType = config.Bind<bool>("BloodRefillConfig", "BloodRefillRequiresSameBloodType", true, "When enabled, blood can only be refilled when the target has the same blood type.");
			BloodRefillCreatureEnabled = config.Bind<bool>("BloodRefillConfig", "BloodRefillCreatureEnabled", true, "When enabled, creature blood can be refilled.");
			BloodRefillWarriorEnabled = config.Bind<bool>("BloodRefillConfig", "BloodRefillWarriorEnabled", true, "When enabled, warrior blood can be refilled.");
			BloodRefillRogueEnabled = config.Bind<bool>("BloodRefillConfig", "BloodRefillRogueEnabled", true, "When enabled, rogue blood can be refilled.");
			BloodRefillBruteEnabled = config.Bind<bool>("BloodRefillConfig", "BloodRefillBruteEnabled", true, "When enabled, brute blood can be refilled.");
			BloodRefillScholarEnabled = config.Bind<bool>("BloodRefillConfig", "BloodRefillScholarEnabled", true, "When enabled, scholar blood can be refilled.");
			BloodRefillScholarEnabled = config.Bind<bool>("BloodRefillConfig", "BloodRefillScholarEnabled", true, "When enabled, scholar blood can be refilled.");
			BloodRefillWorkerEnabled = config.Bind<bool>("BloodRefillConfig", "BloodRefillWorkerEnabled", true, "When enabled, worker blood can be refilled.");
			BloodRefillMutantEnabled = config.Bind<bool>("BloodRefillConfig", "BloodRefillMutantEnabled", true, "When enabled, mutant blood can be refilled.");
			BloodRefillVBloodEnabled = config.Bind<bool>("BloodRefillConfig", "BloodRefillVBloodEnabled", true, "When enabled, V-blood can be refilled.");
			BloodRefillExcludeVBloodFromSameBloodTypeCheck = config.Bind<bool>("BloodRefillConfig", "BloodRefillExcludeVBloodFromSameBloodTypeCheck", true, "When enabled, V-blood is excluded from the 'same blood type' check (i.e. it's always considered to be 'the same blood type' as the player's blood type).");
			BloodRefillVBloodRefillType = config.Bind<int>("BloodRefillConfig", "BloodRefillVBloodRefillType", 3, "0 = disabled (i.e. normal refill); 1 = fully refill; 2 = refill based on V-blood monster level; 3 = refill based on V-blood monster level but not if the player is above BloodRefillVBloodCutoffThreshold % of blood quality. only works when BloodRefillVBloodEnabled is enabled.");
			BloodRefillBloodRefillType = config.Bind<int>("BloodRefillConfig", "BloodRefillBloodRefillType", 1, "0 = disabled (i.e. normal refill); 1 = normal refill but not if the player is above BloodRefillBloodCutoffThreshold % of blood quality.");
			BloodRefillBloodCutoffThreshold = config.Bind<float>("BloodRefillConfig", "BloodRefillBloodCutoffThreshold", 95f, "[Only applies when BloodRefillBloodRefillType is set to 1] The blood quality percentage cutoff threshold (i.e. if the player's blood quality is above this threshold, npc blood will not refill the player's blood).");
			BloodRefillVBloodCutoffThreshold = config.Bind<float>("BloodRefillConfig", "BloodRefillVBloodCutoffThreshold", 95f, "[Only applies when BloodRefillVBloodRefillType is set to 3] The blood quality percentage cutoff threshold (i.e. if the player's blood quality is above this threshold, V-blood will not refill the player's blood).");
			BloodRefillVBloodRefillMultiplier = config.Bind<float>("BloodRefillConfig", "BloodRefillVBloodRefillMultiplier", 0.1f, "[Only applies when BloodRefillVBloodRefillType is set to 2 or 3] The multiplier used in the V-blood refill calculation ('EnemyLevel' * 'BloodRefillVBloodRefillMultiplier' * 'BloodRefillMultiplier').");
			BloodRefillRandomRefill = config.Bind<bool>("BloodRefillConfig", "BloodRefillRandomRefill", true, "When enabled, the amount of refilled blood is randomized (between 1 and the calculated refillable amount).");
			BloodRefillAmount = config.Bind<float>("BloodRefillConfig", "BloodRefillAmount", 1f, "The maximum amount of blood to refill with no level difference, a matching blood type and quality (Expressed in Litres of blood).");
			BloodRefillMultiplier = config.Bind<float>("BloodRefillConfig", "BloodRefillMultiplier", 0.5f, "The multiplier used in the blood refill calculation. [Formula: (('Enemy Level' / 'Player Level') * ((100 - ('Player Blood Quality %' - 'Enemy Blood Quality %')) / 100)) * 'BloodRefillAmount' * '(If applicable) BloodRefillDifferentBloodTypeMultiplier' * 'BloodRefillMultiplier']");
			BloodRefillDifferentBloodTypeMultiplier = config.Bind<float>("BloodRefillConfig", "BloodRefillDifferentBloodTypeMultiplier", 0.1f, "The multiplier used in the blood refill calculation as a penalty for feeding on a different blood type (only works when BloodRefillRequiresSameBloodType is disabled).");
			BloodRefillSendRefillMessage = config.Bind<bool>("BloodRefillConfig", "BloodRefillSendRefillMessage", false, "NOT WORKING: (this will not work until bloodstone gets updated to fix server to client serialization) When enabled, a refill chat message is sent to the player.");
		}
	}
	[BepInPlugin("VMods.BloodRefill", "VMods.BloodRefill", "1.2.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[Reloadable]
	public class Plugin : BasePlugin, IRunOnInitialized
	{
		private Harmony _hooks;

		public sealed override void Load()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (!VWorld.IsServer)
			{
				ManualLogSource log = ((BasePlugin)this).Log;
				bool flag = default(bool);
				BepInExMessageLogInterpolatedStringHandler val = new BepInExMessageLogInterpolatedStringHandler(40, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("VMods.BloodRefill");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" only needs to be installed server side.");
				}
				log.LogMessage(val);
			}
			else
			{
				Utils.Initialize(((BasePlugin)this).Log, "VMods.BloodRefill");
				BloodRefillConfig.Initialize(((BasePlugin)this).Config);
			}
		}

		public void OnGameInitialized()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			try
			{
				if (!VWorld.IsClient)
				{
					BloodRefillSystem.Initialize();
					_hooks = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
					ManualLogSource log = ((BasePlugin)this).Log;
					bool flag = default(bool);
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(22, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("VMods.BloodRefill");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (v");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.2.1");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(") is loaded!");
					}
					log.LogInfo(val);
					((BasePlugin)this).Log.LogInfo((object)"Looking if VCF is installed:");
					if (VMods.BloodRefill.Commands.VCFCompat.Commands.Enabled)
					{
						VMods.BloodRefill.Commands.VCFCompat.Commands.Register();
					}
					else
					{
						((BasePlugin)this).Log.LogWarning((object)"This mod has optional admin commands, you need to install VampireCommandFramework to use them.");
					}
				}
			}
			catch (Exception ex)
			{
				((BasePlugin)this).Log.LogWarning((object)("An error occured:" + ex.Message));
			}
		}

		public sealed override bool Unload()
		{
			if (VWorld.IsClient)
			{
				return true;
			}
			SaveSystem.SaveAll();
			Harmony hooks = _hooks;
			if (hooks != null)
			{
				hooks.UnpatchSelf();
			}
			BloodRefillSystem.Deinitialize();
			((BasePlugin)this).Config.Clear();
			Utils.Deinitialize();
			return true;
		}
	}
	public static class BloodRefillSystem
	{
		public class BloodRefillData
		{
			public bool ShowRefillMessages { get; set; }
		}

		private const string BloodRefillFileName = "BloodRefill.json";

		private static Dictionary<ulong, BloodRefillData> _bloodRefills;

		public static void Initialize()
		{
			_bloodRefills = SaveSystem.Load("BloodRefill.json", () => new Dictionary<ulong, BloodRefillData>());
			SaveSystem.SaveEvent += Save;
			DeathHook.DeathEvent += OnDeath;
		}

		public static void Deinitialize()
		{
			DeathHook.DeathEvent -= OnDeath;
			SaveSystem.SaveEvent -= Save;
		}

		public static void Save()
		{
			SaveSystem.Save("BloodRefill.json", _bloodRefills);
		}

		private static void OnDeath(DeathEvent deathEvent)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_001d: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: 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_0096: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: 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_00e4: 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_00eb: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: 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_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0360: Unknown result type (might be due to invalid IL or missing references)
			//IL_036a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_044f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0451: Unknown result type (might be due to invalid IL or missing references)
			//IL_040a: Unknown result type (might be due to invalid IL or missing references)
			//IL_040c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0416: Unknown result type (might be due to invalid IL or missing references)
			//IL_0427: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				EntityManager entityManager = VWorld.Server.EntityManager;
				PlayerCharacter val = default(PlayerCharacter);
				bool flag = ((EntityManager)(ref entityManager)).TryGetComponentData<PlayerCharacter>(deathEvent.Killer, ref val);
				Equipment val2 = default(Equipment);
				bool flag2 = ((EntityManager)(ref entityManager)).TryGetComponentData<Equipment>(deathEvent.Killer, ref val2);
				Blood val3 = default(Blood);
				bool flag3 = ((EntityManager)(ref entityManager)).TryGetComponentData<Blood>(deathEvent.Killer, ref val3);
				Movement val4 = default(Movement);
				bool flag4 = ((EntityManager)(ref entityManager)).TryGetComponentData<Movement>(deathEvent.Died, ref val4);
				UnitLevel val5 = default(UnitLevel);
				bool flag5 = ((EntityManager)(ref entityManager)).TryGetComponentData<UnitLevel>(deathEvent.Died, ref val5);
				BloodConsumeSource val6 = default(BloodConsumeSource);
				bool flag6 = ((EntityManager)(ref entityManager)).TryGetComponentData<BloodConsumeSource>(deathEvent.Died, ref val6);
				if (!BloodRefillConfig.BloodRefillEnabled.Value || !flag || !flag2 || !flag3 || !flag4 || !flag5 || !flag6)
				{
					return;
				}
				PlayerCharacter val7 = default(PlayerCharacter);
				((EntityManager)(ref entityManager)).TryGetComponentData<PlayerCharacter>(deathEvent.Killer, ref val7);
				Equipment val8 = default(Equipment);
				((EntityManager)(ref entityManager)).TryGetComponentData<Equipment>(deathEvent.Killer, ref val8);
				Blood val9 = default(Blood);
				((EntityManager)(ref entityManager)).TryGetComponentData<Blood>(deathEvent.Killer, ref val9);
				UnitLevel val10 = default(UnitLevel);
				((EntityManager)(ref entityManager)).TryGetComponentData<UnitLevel>(deathEvent.Died, ref val10);
				BloodConsumeSource val11 = default(BloodConsumeSource);
				((EntityManager)(ref entityManager)).TryGetComponentData<BloodConsumeSource>(deathEvent.Died, ref val11);
				Entity userEntity = val7.UserEntity;
				User val12 = default(User);
				((EntityManager)(ref entityManager)).TryGetComponentData<User>(userEntity, ref val12);
				bool flag7 = deathEvent.Killer.Index == deathEvent.Source.Index;
				if (!val9.BloodType.ParseBloodType(out var bloodType) || !val11.UnitBloodType.ParseBloodType(out var bloodType2) || (!BloodRefillConfig.BloodRefillCreatureEnabled.Value && bloodType2 == BloodType.Creature) || (!BloodRefillConfig.BloodRefillWarriorEnabled.Value && bloodType2 == BloodType.Warrior) || (!BloodRefillConfig.BloodRefillRogueEnabled.Value && bloodType2 == BloodType.Rogue) || (!BloodRefillConfig.BloodRefillBruteEnabled.Value && bloodType2 == BloodType.Brute) || (!BloodRefillConfig.BloodRefillScholarEnabled.Value && bloodType2 == BloodType.Scholar) || (!BloodRefillConfig.BloodRefillWorkerEnabled.Value && bloodType2 == BloodType.Worker) || (!BloodRefillConfig.BloodRefillMutantEnabled.Value && bloodType2 == BloodType.Mutant) || (!BloodRefillConfig.BloodRefillVBloodEnabled.Value && bloodType2 == BloodType.VBlood))
				{
					return;
				}
				bool flag8 = bloodType2 == BloodType.VBlood;
				if (!flag8 && BloodRefillConfig.BloodRefillRequiresFeeding.Value && !flag7)
				{
					return;
				}
				bool flag9 = bloodType == bloodType2 || (BloodRefillConfig.BloodRefillExcludeVBloodFromSameBloodTypeCheck.Value && flag8);
				if (BloodRefillConfig.BloodRefillRequiresSameBloodType.Value && !flag9)
				{
					return;
				}
				float num = (flag9 ? 1f : BloodRefillConfig.BloodRefillDifferentBloodTypeMultiplier.Value);
				float num2 = ModifiableFloat.op_Implicit(val8.WeaponLevel) + ModifiableFloat.op_Implicit(val8.ArmorLevel) + ModifiableFloat.op_Implicit(val8.SpellLevel);
				float num3 = val10.Level;
				float num4 = num3 / num2;
				float num5 = (100f - (val9.Quality - val11.BloodQuality)) / 100f;
				float num6 = num4 * num5;
				float num7 = BloodRefillConfig.BloodRefillAmount.Value * 10f * num6;
				num7 *= num;
				if (BloodRefillConfig.BloodRefillRandomRefill.Value)
				{
					num7 = Random.RandomRange(1f, num7);
				}
				if (!flag8)
				{
					int value = BloodRefillConfig.BloodRefillBloodRefillType.Value;
					if (value != 0 && value == 1 && val9.Quality > BloodRefillConfig.BloodRefillBloodCutoffThreshold.Value)
					{
						return;
					}
				}
				else
				{
					switch (BloodRefillConfig.BloodRefillVBloodRefillType.Value)
					{
					case 1:
						num7 = ModifiableFloat.op_Implicit(val9.MaxBlood) - val9.Value;
						break;
					case 2:
						num7 = num3 * BloodRefillConfig.BloodRefillVBloodRefillMultiplier.Value;
						break;
					case 3:
						if (val9.Quality > BloodRefillConfig.BloodRefillVBloodCutoffThreshold.Value)
						{
							return;
						}
						num7 = num3 * BloodRefillConfig.BloodRefillVBloodRefillMultiplier.Value;
						break;
					}
				}
				num7 *= BloodRefillConfig.BloodRefillMultiplier.Value;
				BloodRefillData value2;
				bool flag10 = BloodRefillConfig.BloodRefillSendRefillMessage.Value && (!_bloodRefills.TryGetValue(val12.PlatformId, out value2) || value2.ShowRefillMessages);
				if (!(num7 > 0f))
				{
					return;
				}
				int num8 = (int)Math.Ceiling(num7);
				if (num8 > 0)
				{
					if (flag10)
					{
						float num9 = Math.Min(ModifiableFloat.op_Implicit(val9.MaxBlood), val9.Value + (float)num8);
						_ = (float)(int)((num9 - val9.Value) * 10f) / 100f;
						_ = (float)(int)Math.Round(num9) / 10f;
					}
					bloodType.ApplyToPlayer(val12, val9.Quality, num8);
				}
			}
			catch (Exception ex)
			{
				Utils.Logger.LogError((object)ex.Message);
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "VMods.BloodRefill";

		public const string PLUGIN_NAME = "VMods.BloodRefill";

		public const string PLUGIN_VERSION = "1.2.1";
	}
}
namespace VMods.BloodRefill.Commands
{
	public class SaveSystem
	{
		public delegate void SaveEventHandler();

		private static string ConfigStoragePath = Paths.ConfigPath + "\\VMods\\Storage";

		private static readonly JsonSerializerOptions JsonOptions = new JsonSerializerOptions
		{
			WriteIndented = false,
			IncludeFields = false
		};

		public static event SaveEventHandler SaveEvent;

		private static void FireSaveEvent()
		{
			SaveSystem.SaveEvent?.Invoke();
		}

		public static void SaveAll()
		{
			FireSaveEvent();
		}

		public static void Save<T>(string filename, T data)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			try
			{
				File.WriteAllText(Path.Combine(ConfigStoragePath, filename), JsonSerializer.Serialize(data, JsonOptions));
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Utils.Logger;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(28, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failed to save ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(filename);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("! - Error: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\r\n");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.StackTrace);
				}
				logger.LogError(val);
			}
		}

		public static T Load<T>(string filename, Func<T> getDefaultValue)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			try
			{
				if (!Directory.Exists(ConfigStoragePath))
				{
					Directory.CreateDirectory(ConfigStoragePath);
				}
				string path = Path.Combine(ConfigStoragePath, filename);
				if (!File.Exists(path))
				{
					return getDefaultValue();
				}
				return JsonSerializer.Deserialize<T>(File.ReadAllText(path));
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Utils.Logger;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(28, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failed to load ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(filename);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("! - Error: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\r\n");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.StackTrace);
				}
				logger.LogError(val);
				return getDefaultValue();
			}
		}
	}
}
namespace VMods.BloodRefill.Commands.VCFCompat
{
	public static class Commands
	{
		[CommandGroup("bloodrefill", "blrf")]
		public class BloodRefillCommands
		{
			[Command("saveall", "svall", "bloodrefill saveall/svall", "Saves all data of all VMod plugins", null, true)]
			private static void OnSaveAllCommand(ChatCommandContext command)
			{
				SaveSystem.SaveAll();
				command.Reply("VMod Plugin '" + Utils.PluginName + "' saved successfully.");
			}
		}

		public static bool Enabled { get; private set; }

		static Commands()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			Enabled = ((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.TryGetValue("gg.deca.VampireCommandFramework", out var value);
			if (Enabled)
			{
				ManualLogSource logger = Utils.Logger;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(13, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("VCF Version: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Version>(value.Metadata.Version);
				}
				logger.LogWarning(val);
			}
		}

		public static void Register()
		{
			CommandRegistry.RegisterAll();
		}
	}
}