Decompiled source of CrimsonHunt v0.1.0

CrimsonHunt.dll

Decompiled 2 months ago
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.Json;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Bloodstone.API;
using Bloodstone.Hooks;
using Bloody.Core;
using Bloody.Core.API.v1;
using CrimsonHunt.Hooks;
using CrimsonHunt.Structs;
using CrimsonHunt.Utils;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Network;
using ProjectM.Shared;
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.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("CrimsonHunt")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Created with VRising.ModTemplate, you should edit this.")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+6.Branch.master.Sha.d1a8292a24bc0386a445428532f3c6042424dc55")]
[assembly: AssemblyProduct("CrimsonHunt")]
[assembly: AssemblyTitle("CrimsonHunt")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace CrimsonHunt
{
	[BepInPlugin("CrimsonHunt", "CrimsonHunt", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[Reloadable]
	public class Plugin : BasePlugin, IRunOnInitialized
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static GameFrameUpdateEventHandler <0>__HandleHuntFrame;
		}

		private Harmony _harmony;

		public static ManualLogSource LogInstance { get; private set; }

		public static Settings Settings { get; private set; }

		public override void Load()
		{
			LogInstance = ((BasePlugin)this).Log;
			Settings = new Settings(((BasePlugin)this).Config);
			Settings.InitConfig();
			Database.InitDatabase("player_hunts");
			if (!VWorld.IsServer)
			{
				((BasePlugin)this).Log.LogWarning((object)"This plugin is a server-only plugin.");
			}
			CommandRegistry.RegisterAll();
		}

		public void OnGameInitialized()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			if (!VWorld.IsClient)
			{
				_harmony = new Harmony("CrimsonHunt");
				_harmony.PatchAll();
				Core.InitializeAfterLoaded();
				ManualLogSource log = ((BasePlugin)this).Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("CrimsonHunt");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
				}
				log.LogInfo(val);
			}
		}

		public override bool Unload()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			CommandRegistry.UnregisterAssembly();
			((BasePlugin)this).Config.Clear();
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			object obj = <>O.<0>__HandleHuntFrame;
			if (obj == null)
			{
				GameFrameUpdateEventHandler val = ActionScheduler.HandleHuntFrame;
				<>O.<0>__HandleHuntFrame = val;
				obj = (object)val;
			}
			GameFrame.OnUpdate -= (GameFrameUpdateEventHandler)obj;
			return true;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "CrimsonHunt";

		public const string PLUGIN_NAME = "CrimsonHunt";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}
namespace CrimsonHunt.Utils
{
	internal static class Core
	{
		public static World Server = VWorld.Server;

		public static EntityManager EntityManager = Server.EntityManager;

		public static ManualLogSource Log = Plugin.LogInstance;

		private static bool _hasInitialized = false;

		public static PlayerService Players { get; internal set; }

		public static UnitSpawnerService UnitSpawner { get; internal set; }

		public static PrefabService Prefabs { get; internal set; }

		public static void LogException(Exception e, [CallerMemberName] string caller = null)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			if (!_hasInitialized)
			{
				Players = new PlayerService();
				UnitSpawner = new UnitSpawnerService();
				Prefabs = new PrefabService();
				ActionScheduler.StartTimer();
				_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);
			}
		}

		private static World GetWorld(string name)
		{
			Enumerator<World> enumerator = World.s_AllWorlds.GetEnumerator();
			while (enumerator.MoveNext())
			{
				World current = enumerator.Current;
				if (current.Name == name)
				{
					return current;
				}
			}
			return null;
		}
	}
	public static class Il2cppService
	{
		public static NativeArray<Entity> GetEntitiesByComponentTypes<T1>(bool includeAll = false)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//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_0036: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			EntityQueryOptions options = (EntityQueryOptions)(includeAll ? 195 : 0);
			EntityQueryDesc val = new EntityQueryDesc();
			val.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[1]
			{
				new ComponentType(Il2CppType.Of<T1>(), (AccessMode)0)
			});
			val.Options = options;
			EntityQueryDesc val2 = val;
			EntityManager entityManager = VWorld.Server.EntityManager;
			EntityQuery val3 = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)new EntityQueryDesc[1] { val2 });
			return ((EntityQuery)(ref val3)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
		}

		public static NativeArray<Entity> GetEntitiesByComponentTypes<T1, T2>(bool includeAll = false)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//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_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_0048: 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_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)
			EntityQueryOptions options = (EntityQueryOptions)(includeAll ? 195 : 0);
			EntityQueryDesc val = new EntityQueryDesc();
			val.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[2]
			{
				new ComponentType(Il2CppType.Of<T1>(), (AccessMode)0),
				new ComponentType(Il2CppType.Of<T2>(), (AccessMode)0)
			});
			val.Options = options;
			EntityQueryDesc val2 = val;
			EntityManager entityManager = VWorld.Server.EntityManager;
			EntityQuery val3 = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)new EntityQueryDesc[1] { val2 });
			return ((EntityQuery)(ref val3)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
		}

		public static NativeArray<Entity> GetEntitiesByComponentTypes<T1, T2, T3>(bool includeAll = false)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//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_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_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_005a: 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_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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			EntityQueryOptions options = (EntityQueryOptions)(includeAll ? 195 : 0);
			EntityQueryDesc val = new EntityQueryDesc();
			val.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[3]
			{
				new ComponentType(Il2CppType.Of<T1>(), (AccessMode)0),
				new ComponentType(Il2CppType.Of<T2>(), (AccessMode)0),
				new ComponentType(Il2CppType.Of<T3>(), (AccessMode)0)
			});
			val.Options = options;
			EntityQueryDesc val2 = val;
			EntityManager entityManager = VWorld.Server.EntityManager;
			EntityQuery val3 = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)new EntityQueryDesc[1] { val2 });
			return ((EntityQuery)(ref val3)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
		}
	}
	internal class PlayerService
	{
		private Dictionary<FixedString64Bytes, PlayerData> NamePlayerCache = new Dictionary<FixedString64Bytes, PlayerData>();

		private Dictionary<ulong, PlayerData> SteamPlayerCache = new Dictionary<ulong, PlayerData>();

		internal bool TryFindSteam(ulong steamId, out PlayerData playerData)
		{
			return SteamPlayerCache.TryGetValue(steamId, out playerData);
		}

		internal bool TryFindName(FixedString64Bytes name, out PlayerData playerData)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return NamePlayerCache.TryGetValue(name, out playerData);
		}

		internal PlayerService()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: 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_00ad: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Expected O, but got Unknown
			NamePlayerCache.Clear();
			SteamPlayerCache.Clear();
			EntityQueryDesc[] array = new EntityQueryDesc[1];
			EntityQueryDesc val = new EntityQueryDesc();
			val.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<User>() });
			val.Options = (EntityQueryOptions)2;
			array[0] = val;
			EntityQuery val2 = ((EntityManager)(ref Core.EntityManager)).CreateEntityQuery((EntityQueryDesc[])(object)array);
			Enumerator<Entity> enumerator = ((EntityQuery)(ref val2)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2)).GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				User componentData = ((EntityManager)(ref Core.EntityManager)).GetComponentData<User>(current);
				PlayerData value = new PlayerData(componentData.CharacterName, componentData.PlatformId, componentData.IsConnected, current, componentData.LocalCharacter._Entity);
				NamePlayerCache.TryAdd(FixedString64Bytes.op_Implicit(((object)(FixedString64Bytes)(ref componentData.CharacterName)).ToString().ToLower()), value);
				SteamPlayerCache.TryAdd(componentData.PlatformId, value);
			}
			IEnumerable<string> enumerable = from p in NamePlayerCache.Values
				where p.IsOnline
				select $"\t{p.CharacterName}";
			ManualLogSource log = Core.Log;
			bool flag = default(bool);
			BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(58, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Player Cache Created with ");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(NamePlayerCache.Count);
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" entries total, listing ");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(enumerable.Count());
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" online:");
			}
			log.LogWarning(val3);
			Core.Log.LogWarning((object)string.Join("\n", enumerable));
		}

		internal void UpdatePlayerCache(Entity userEntity, string oldName, string newName, bool forceOffline = false)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_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_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_0044: 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_0060: 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)
			User componentData = ((EntityManager)(ref Core.EntityManager)).GetComponentData<User>(userEntity);
			NamePlayerCache.Remove(FixedString64Bytes.op_Implicit(oldName.ToLower()));
			if (forceOffline)
			{
				componentData.IsConnected = false;
			}
			PlayerData value = new PlayerData(FixedString64Bytes.op_Implicit(newName), componentData.PlatformId, componentData.IsConnected, userEntity, componentData.LocalCharacter._Entity);
			NamePlayerCache[FixedString64Bytes.op_Implicit(newName.ToLower())] = value;
			SteamPlayerCache[componentData.PlatformId] = value;
		}

		internal bool RenamePlayer(Entity userEntity, Entity charEntity, FixedString64Bytes newName)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_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_0059: 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)
			DebugEventsSystem existingSystemManaged = Core.Server.GetExistingSystemManaged<DebugEventsSystem>();
			NetworkId componentData = ((EntityManager)(ref Core.EntityManager)).GetComponentData<NetworkId>(userEntity);
			User componentData2 = ((EntityManager)(ref Core.EntityManager)).GetComponentData<User>(userEntity);
			RenameUserDebugEvent val = new RenameUserDebugEvent
			{
				NewName = newName,
				Target = componentData
			};
			FromCharacter val2 = new FromCharacter
			{
				User = userEntity,
				Character = charEntity
			};
			existingSystemManaged.RenameUser(val2, val);
			UpdatePlayerCache(userEntity, ((object)(FixedString64Bytes)(ref componentData2.CharacterName)).ToString(), ((object)(FixedString64Bytes)(ref newName)).ToString());
			return true;
		}

		public static User GetUserComponente(Entity userEntity)
		{
			//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)
			EntityManager entityManager = VWorld.Server.EntityManager;
			return ((EntityManager)(ref entityManager)).GetComponentData<User>(userEntity);
		}

		public static bool BuffPlayer(Entity character, Entity user, PrefabGUID buff, int duration = -1, bool persistsThroughDeath = false)
		{
			//IL_000b: 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_002b: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_006e: 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_0076: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: 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_0103: 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_00e1: 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_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: 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_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: 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_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			List<PrefabGUID> list = new List<PrefabGUID>
			{
				new PrefabGUID(-1703886455),
				new PrefabGUID(-238197495),
				new PrefabGUID(1068709119),
				new PrefabGUID(-1161197991)
			};
			DebugEventsSystem existingSystemManaged = VWorld.Server.GetExistingSystemManaged<DebugEventsSystem>();
			ApplyBuffDebugEvent val = default(ApplyBuffDebugEvent);
			val.BuffPrefabGUID = buff;
			ApplyBuffDebugEvent val2 = val;
			FromCharacter val3 = default(FromCharacter);
			val3.User = user;
			val3.Character = character;
			FromCharacter val4 = val3;
			Entity val5 = default(Entity);
			if (BuffUtility.TryGetBuff(VWorld.Server.EntityManager, character, PrefabIdentifier.op_Implicit(buff), ref val5))
			{
				return false;
			}
			existingSystemManaged.ApplyBuff(val4, val2);
			if (!BuffUtility.TryGetBuff(VWorld.Server.EntityManager, character, PrefabIdentifier.op_Implicit(buff), ref val5))
			{
				return false;
			}
			if (list.Contains(buff))
			{
				if (ECSExtensions.Has<CreateGameplayEventsOnSpawn>(val5))
				{
					ECSExtensions.Remove<CreateGameplayEventsOnSpawn>(val5);
				}
				if (ECSExtensions.Has<GameplayEventListeners>(val5))
				{
					ECSExtensions.Remove<GameplayEventListeners>(val5);
				}
			}
			if (persistsThroughDeath)
			{
				ECSExtensions.Add<Buff_Persists_Through_Death>(val5);
				if (ECSExtensions.Has<RemoveBuffOnGameplayEvent>(val5))
				{
					ECSExtensions.Remove<RemoveBuffOnGameplayEvent>(val5);
				}
				if (ECSExtensions.Has<RemoveBuffOnGameplayEventEntry>(val5))
				{
					ECSExtensions.Remove<RemoveBuffOnGameplayEventEntry>(val5);
				}
			}
			if (duration > 0 && duration != -1)
			{
				if (ECSExtensions.Has<LifeTime>(val5))
				{
					LifeTime val6 = ECSExtensions.Read<LifeTime>(val5);
					val6.Duration = duration;
					ECSExtensions.Write<LifeTime>(val5, val6);
				}
			}
			else if (duration == 0)
			{
				if (ECSExtensions.Has<LifeTime>(val5))
				{
					LifeTime val7 = ECSExtensions.Read<LifeTime>(val5);
					val7.Duration = -1f;
					val7.EndAction = (LifeTimeEndAction)0;
					ECSExtensions.Write<LifeTime>(val5, val7);
				}
				if (ECSExtensions.Has<RemoveBuffOnGameplayEvent>(val5))
				{
					ECSExtensions.Remove<RemoveBuffOnGameplayEvent>(val5);
				}
				if (ECSExtensions.Has<RemoveBuffOnGameplayEventEntry>(val5))
				{
					ECSExtensions.Remove<RemoveBuffOnGameplayEventEntry>(val5);
				}
			}
			return true;
		}

		public static void UnbuffCharacter(Entity character, PrefabGUID buffGUID)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			Entity val = default(Entity);
			if (BuffUtility.TryGetBuff(VWorld.Server.EntityManager, character, PrefabIdentifier.op_Implicit(buffGUID), ref val))
			{
				DestroyUtility.Destroy(VWorld.Server.EntityManager, val, (DestroyDebugReason)13, (string)null, 0);
			}
		}
	}
	internal class PrefabService
	{
		internal Dictionary<string, (string Name, PrefabGUID Prefab)> NameToGuid { get; init; } = new Dictionary<string, (string, PrefabGUID)>();


		internal PrefabService()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			Dictionary<string, PrefabGUID> spawnableNameToPrefabGuidDictionary = Core.Server.GetExistingSystemManaged<PrefabCollectionSystem>().SpawnableNameToPrefabGuidDictionary;
			ManualLogSource log = Core.Log;
			bool flag = default(bool);
			BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(19, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Spawnable prefabs: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(spawnableNameToPrefabGuidDictionary.Count);
			}
			log.LogDebug(val);
			Enumerator<string, PrefabGUID> enumerator = spawnableNameToPrefabGuidDictionary.GetEnumerator();
			while (enumerator.MoveNext())
			{
				KeyValuePair<string, PrefabGUID> current = enumerator.Current;
				if (!NameToGuid.TryAdd(current.Key.ToLowerInvariant(), (current.Key, current.Value)))
				{
					ManualLogSource log2 = Core.Log;
					val = new BepInExDebugLogInterpolatedStringHandler(25, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(current.Key);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" exist already, skipping.");
					}
					log2.LogDebug(val);
				}
			}
		}

		internal bool TryGetItem(string input, out PrefabGUID prefab)
		{
			//IL_0034: 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)
			string text = input.ToLowerInvariant();
			(string, PrefabGUID) value;
			bool result = NameToGuid.TryGetValue(text, out value) || NameToGuid.TryGetValue("item_" + text, out value);
			prefab = value.Item2;
			return result;
		}

		internal PrefabGUID GetGUIDByName(string value)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			return NameToGuid[value.ToLowerInvariant()].Prefab;
		}

		public static string GetPrefabName(PrefabGUID hashCode)
		{
			//IL_0023: 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_0029: Unknown result type (might be due to invalid IL or missing references)
			PrefabCollectionSystem existingSystemManaged = VWorld.Server.GetExistingSystemManaged<PrefabCollectionSystem>();
			string result = "Nonexistent";
			if (((PrefabGUID)(ref hashCode)).GuidHash == 0)
			{
				return result;
			}
			try
			{
				Entity val = ((PrefabLookupMap)(ref ((PrefabCollectionSystem_Base)existingSystemManaged).PrefabLookupMap))[hashCode];
				return ((object)(Entity)(ref val)).ToString();
			}
			catch
			{
				return "NoPrefabName";
			}
		}
	}
	internal class UnitSpawnerService
	{
		[HarmonyPatch(typeof(UnitSpawnerReactSystem), "OnUpdate")]
		public static class UnitSpawnerReactSystem_Patch
		{
			public static bool Enabled { get; set; }

			public static void Prefix(UnitSpawnerReactSystem __instance)
			{
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Expected O, but got Unknown
				//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_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_007a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0080: Expected O, but got Unknown
				//IL_00b1: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c7: 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_00e2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e8: Expected O, but got Unknown
				//IL_010a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0158: Unknown result type (might be due to invalid IL or missing references)
				//IL_015e: Expected O, but got Unknown
				//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
				//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
				//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
				//IL_01de: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
				if (!Enabled)
				{
					return;
				}
				EntityQuery _query_2099432189_ = __instance.__query_2099432189_0;
				NativeArray<Entity> val = ((EntityQuery)(ref _query_2099432189_)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
				ManualLogSource log = Core.Log;
				bool flag = default(bool);
				BepInExDebugLogInterpolatedStringHandler val2 = new BepInExDebugLogInterpolatedStringHandler(40, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Processing ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(val.Length);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" in UnitSpawnerReactionSystem");
				}
				log.LogDebug(val2);
				Enumerator<Entity> enumerator = val.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					ManualLogSource log2 = Core.Log;
					val2 = new BepInExDebugLogInterpolatedStringHandler(27, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Checking if ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(current.Index);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" has lifetime..");
					}
					log2.LogDebug(val2);
					if (!((EntityManager)(ref Core.EntityManager)).HasComponent<LifeTime>(current))
					{
						break;
					}
					LifeTime componentData = ((EntityManager)(ref Core.EntityManager)).GetComponentData<LifeTime>(current);
					long num = (long)Mathf.Round(componentData.Duration);
					ManualLogSource log3 = Core.Log;
					val2 = new BepInExDebugLogInterpolatedStringHandler(34, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Found durationKey ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<long>(num);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" from LifeTime(");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<float>(componentData.Duration);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(")");
					}
					log3.LogDebug(val2);
					if (Core.UnitSpawner.PostActions.TryGetValue(num, out (float, Action<Entity>) value))
					{
						(float, Action<Entity>) tuple = value;
						float item = tuple.Item1;
						Action<Entity> item2 = tuple.Item2;
						ManualLogSource log4 = Core.Log;
						val2 = new BepInExDebugLogInterpolatedStringHandler(38, 2, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Found post actions for ");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<long>(num);
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" with ");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<float>(item);
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" duration");
						}
						log4.LogDebug(val2);
						Core.UnitSpawner.PostActions.Remove(num);
						LifeTimeEndAction endAction = (LifeTimeEndAction)((!(item < 0f)) ? 2 : 0);
						LifeTime val3 = new LifeTime
						{
							Duration = item,
							EndAction = endAction
						};
						((EntityManager)(ref Core.EntityManager)).SetComponentData<LifeTime>(current, val3);
						item2(current);
					}
				}
			}
		}

		private static Entity empty_entity;

		internal const int DEFAULT_MINRANGE = 1;

		internal const int DEFAULT_MAXRANGE = 1;

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

		public void Spawn(Entity user, PrefabGUID unit, int count, float2 position, float minRange = 1f, float maxRange = 2f, float duration = -1f)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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)
			Translation componentData = ((EntityManager)(ref Core.EntityManager)).GetComponentData<Translation>(user);
			float3 val = default(float3);
			((float3)(ref val))..ctor(position.x, componentData.Value.y, position.y);
			Core.Server.GetExistingSystemManaged<UnitSpawnerUpdateSystem>().SpawnUnit(empty_entity, unit, val, count, minRange, maxRange, duration);
		}

		public void SpawnWithCallback(Entity user, PrefabGUID unit, float2 position, float duration, Action<Entity> postActions)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_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_001f: 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_0046: 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)
			Translation componentData = ((EntityManager)(ref Core.EntityManager)).GetComponentData<Translation>(user);
			float3 val = default(float3);
			((float3)(ref val))..ctor(position.x, componentData.Value.y, position.y);
			UnitSpawnerUpdateSystem existingSystemManaged = Core.Server.GetExistingSystemManaged<UnitSpawnerUpdateSystem>();
			UnitSpawnerReactSystem_Patch.Enabled = true;
			long num = NextKey();
			existingSystemManaged.SpawnUnit(empty_entity, unit, val, 1, 1f, 1f, (float)num);
			PostActions.Add(num, (duration, postActions));
		}

		internal 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 CrimsonHunt.Structs
{
	public class Database
	{
		private static Database INSTANCE;

		public static int ExpBonus;

		public string DbPath { get; set; }

		public Dictionary<ulong, PlayerStats> PlayerExp { get; set; }

		public DateTime Dumped { get; set; }

		public Database(string _path, string _fileName)
		{
			DbPath = Path.Combine(_path, _fileName + ".json");
			PlayerExp = new Dictionary<ulong, PlayerStats>();
			Dumped = DateTime.Now;
		}

		public static void InitDatabase(string fileName)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			INSTANCE = new Database(Path.Combine(Paths.ConfigPath, "CrimsonHunt"), fileName);
			if (File.Exists(INSTANCE.DbPath))
			{
				string json = File.ReadAllText(INSTANCE.DbPath);
				try
				{
					INSTANCE.PlayerExp = JsonSerializer.Deserialize<Dictionary<ulong, PlayerStats>>(json);
				}
				catch (Exception ex)
				{
					Plugin.LogInstance.LogWarning((object)ex.Message);
				}
			}
			ManualLogSource logInstance = Plugin.LogInstance;
			bool flag = default(bool);
			BepInExMessageLogInterpolatedStringHandler val = new BepInExMessageLogInterpolatedStringHandler(26, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Database loaded: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(INSTANCE.PlayerExp.Count);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" entries.");
			}
			logInstance.LogMessage(val);
		}

		public static Database Data()
		{
			return INSTANCE;
		}

		public float GetExp(Player player)
		{
			if (!PlayerExp.TryGetValue(player.SteamID, out var value))
			{
				return 0f;
			}
			return value.Exp;
		}

		public void UpdateExp(Player player, Entity boss)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			int num = ModifiableInt.op_Implicit(ECSExtensions.Read<UnitLevel>(boss).Level);
			ManualLogSource logInstance = Plugin.LogInstance;
			bool flag = default(bool);
			BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(34, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Player defeated a boss with level ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num);
			}
			logInstance.LogDebug(val);
			Equipment val2 = ECSExtensions.Read<Equipment>(player.Character);
			((Equipment)(ref val2)).GetFullLevel();
			float num2 = (float)num / 10f;
			ManualLogSource logInstance2 = Plugin.LogInstance;
			val = new BepInExDebugLogInterpolatedStringHandler(14, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Add ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(num2);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" to player");
			}
			logInstance2.LogDebug(val);
			if (ExpBonus != 0)
			{
				num2 *= 1f + (float)ExpBonus / 100f;
			}
			UpdateExp(player, (int)num2);
		}

		public void UpdateExp(Player player, int value)
		{
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			PlayerStats value2;
			bool num = PlayerExp.TryGetValue(player.SteamID, out value2);
			int expNeeded = (from x in Settings.GetLevels()
				orderby x.ExpNeeded descending
				select x).ToList().First().ExpNeeded;
			PlayerStats playerStats;
			if (num)
			{
				playerStats = PlayerExp[player.SteamID];
				playerStats.Name = player.Name;
				playerStats.IsAdmin = player.IsAdmin;
				playerStats.Exp = ((playerStats.Exp + (float)value > (float)expNeeded) ? ((float)expNeeded) : (playerStats.Exp + (float)value));
			}
			else
			{
				playerStats = new PlayerStats
				{
					Name = player.Name,
					IsAdmin = player.IsAdmin,
					Exp = value
				};
			}
			HuntLevel prestige = GetPrestige(playerStats.Exp);
			int level = playerStats.Level;
			playerStats.Level = prestige.Level;
			if (num)
			{
				PlayerExp[player.SteamID] = playerStats;
			}
			else
			{
				PlayerExp.Add(player.SteamID, playerStats);
			}
			CheckForItemRewards(player, level, prestige);
			AddPrestigeBuff(player, playerStats, prestige, level);
			ServerChatUtils.SendSystemMessageToClient(VWorld.Server.EntityManager, ECSExtensions.Read<User>(player.User), $"Hunt Score [Lvl: <color=#ffc905>{prestige.Level}</color> ~ (<color=#ffc905>{playerStats.Exp.ToString("0.##", CultureInfo.InvariantCulture)}</color>/<color=#ffc905>{prestige.ExpNeeded}</color>)]");
		}

		private static void CheckForItemRewards(Player player, int curLevel, HuntLevel newLevel)
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: 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)
			if (newLevel.Level <= curLevel)
			{
				return;
			}
			PrefabGUID val = default(PrefabGUID);
			foreach (HuntLevel item in (from x in Settings.GetLevels()
				orderby x.Level
				select x).ToList())
			{
				if (item.Level > curLevel && item.Level <= newLevel.Level && item.HuntReward.ItemHash != 0)
				{
					((PrefabGUID)(ref val))..ctor(item.HuntReward.ItemHash);
					UserSystem.TryAddUserInventoryItem(player.Character, val, item.HuntReward.ItemQuantity);
					ServerChatUtils.SendSystemMessageToClient(VWorld.Server.EntityManager, ECSExtensions.Read<User>(player.User), $"Hunt Level [Lvl: <color=#ffc905>{item.Level}</color> ~ Reward: (<color=#ffc905>{item.HuntReward.ItemQuantity} {ECSExtensions.LookupName(val)}</color>");
				}
			}
		}

		private static void AddPrestigeBuff(Player player, PlayerStats stats, HuntLevel prestige, int curLevel)
		{
			//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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			if (prestige.Level <= curLevel)
			{
				return;
			}
			EntityManager entityManager = VWorld.Server.EntityManager;
			if (!BuffUtility.HasBuff(entityManager, player.Character, PrefabIdentifier.op_Implicit(new PrefabGUID(-1133938228))))
			{
				PlayerService.BuffPlayer(player.Character, player.User, new PrefabGUID(-1133938228), 2);
			}
			string text = prestige.Message.Replace("{player}", player.Name).Replace("{level}", prestige.Level.ToString());
			ServerChatUtils.SendSystemMessageToAllClients(entityManager, text);
			foreach (HuntLevel item in (from x in Settings.GetLevels()
				orderby x.Level
				select x).ToList())
			{
				if (item.HuntReward.EffectHash == 0)
				{
					continue;
				}
				if (stats.Level > item.Level && BuffUtility.HasBuff(entityManager, player.Character, PrefabIdentifier.op_Implicit(new PrefabGUID(item.HuntReward.EffectHash))))
				{
					PlayerService.UnbuffCharacter(player.Character, new PrefabGUID(item.HuntReward.EffectHash));
				}
				if (stats.Level == item.Level)
				{
					if (!BuffUtility.HasBuff(entityManager, player.Character, PrefabIdentifier.op_Implicit(new PrefabGUID(item.HuntReward.EffectHash))))
					{
						PlayerService.BuffPlayer(player.Character, player.User, new PrefabGUID(item.HuntReward.EffectHash), 0, persistsThroughDeath: true);
					}
					break;
				}
			}
		}

		public static HuntLevel GetPrestige(float exp)
		{
			List<HuntLevel> list = (from x in Settings.GetLevels()
				orderby x.Level
				select x).ToList();
			HuntLevel huntLevel = new HuntLevel();
			huntLevel.Level = 0;
			huntLevel.ExpNeeded = 0;
			huntLevel.Message = "";
			HuntLevel result = huntLevel;
			for (int i = 0; i < list.Count; i++)
			{
				result.ExpNeeded = list.ElementAt(i).ExpNeeded;
				if (!(exp >= (float)list.ElementAt(i).ExpNeeded))
				{
					break;
				}
				result.Level = list.ElementAt(i).Level;
				result.Message = list.ElementAt(i).Message;
			}
			return result;
		}

		public void SaveDatabase(bool check = true)
		{
			if (!(DateTime.Now - Dumped < TimeSpan.FromMinutes(1.0) && check))
			{
				DateTime now = DateTime.Now;
				string contents = JsonSerializer.Serialize(PlayerExp, new JsonSerializerOptions
				{
					WriteIndented = true
				});
				File.WriteAllText(DbPath, contents);
				Dumped = now;
			}
		}

		public List<PlayerStats> GetTopScores(int amount)
		{
			return PlayerExp.Values.OrderByDescending((PlayerStats x) => x.Exp).Take(amount).ToList();
		}
	}
	public struct PlayerStats
	{
		public string Name { get; set; }

		public bool IsAdmin { get; set; }

		public float Exp { get; set; }

		public int Level { get; set; }
	}
	public struct HuntLevel
	{
		public int Level { get; set; }

		public int ExpNeeded { get; set; }

		public HuntReward HuntReward { get; set; }

		public string Message { get; set; }

		public HuntLevel(int _level, int _expNeeded, HuntReward _reward, string _message)
		{
			Level = _level;
			ExpNeeded = _expNeeded;
			HuntReward = _reward;
			Message = _message;
		}

		public HuntLevel()
		{
			Level = 0;
			ExpNeeded = 0;
			HuntReward = default(HuntReward);
			Message = null;
		}
	}
	public struct HuntReward
	{
		public int EffectHash { get; set; }

		public int ItemHash { get; set; }

		public int ItemQuantity { get; set; }

		public HuntReward(int effectHash, int itemHash, int itemQuantity)
		{
			EffectHash = effectHash;
			ItemHash = itemHash;
			ItemQuantity = itemQuantity;
		}

		public HuntReward()
		{
			EffectHash = 0;
			ItemHash = 0;
			ItemQuantity = 0;
		}
	}
	public struct KillEvent
	{
		public DateTime Killed { get; set; }

		public Entity Boss { get; set; }

		public string BossName { get; set; }

		public List<Player> Players { get; set; }

		public KillEvent(Entity _boss, string _bossName)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			Killed = DateTime.Now;
			Boss = _boss;
			BossName = _bossName;
			Players = new List<Player>();
		}

		public readonly void AddPlayer(Player player)
		{
			if (Players.Where((Player x) => x.Name == player.Name).ToList().Count == 0)
			{
				Players.Add(player);
			}
		}
	}
	public struct PlayerData
	{
		public FixedString64Bytes CharacterName { get; set; }

		public ulong SteamID { get; set; }

		public bool IsOnline { get; set; }

		public Entity UserEntity { get; set; }

		public Entity CharEntity { get; set; }

		public PlayerData(FixedString64Bytes _characterName = default(FixedString64Bytes), ulong _steamID = 0uL, bool _isOnline = false, Entity _userEntity = default(Entity), Entity _charEntity = default(Entity))
		{
			//IL_0001: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			CharacterName = _characterName;
			SteamID = _steamID;
			IsOnline = _isOnline;
			UserEntity = _userEntity;
			CharEntity = _charEntity;
		}
	}
	public class Player
	{
		public string Name { get; set; }

		public ulong SteamID { get; set; }

		public bool IsOnline { get; set; }

		public bool IsAdmin { get; set; }

		public Entity User { get; set; }

		public Entity Character { get; set; }

		public Player(Entity userEntity = default(Entity), Entity charEntity = default(Entity))
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			User = userEntity;
			User val = ECSExtensions.Read<User>(User);
			Character = val.LocalCharacter._Entity;
			Name = ((object)(FixedString64Bytes)(ref val.CharacterName)).ToString();
			IsOnline = val.IsConnected;
			IsAdmin = val.IsAdmin;
			SteamID = val.PlatformId;
		}
	}
	public readonly struct Settings
	{
		private readonly ConfigFile CONFIG;

		private readonly ConfigEntry<bool> ENABLE_MOD;

		private readonly ConfigEntry<bool> ENABLE_BOUNTY;

		public static readonly string CONFIG_PATH = Path.Combine(Paths.ConfigPath, "CrimsonHunt");

		private static readonly string PRESTIGE = Path.Combine(CONFIG_PATH, "hunt_levels.json");

		private static List<HuntLevel> HUNT_LEVELS = new List<HuntLevel>();

		public Settings(ConfigFile config)
		{
			CONFIG = config;
			ENABLE_MOD = CONFIG.Bind<bool>("Config", "EnableMod", true, "Enable or disable the mod");
			ENABLE_BOUNTY = CONFIG.Bind<bool>("Config", "EnableHunt", true, "Enable or disable v blood hunting");
		}

		public void InitConfig()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			WriteConfig();
			HUNT_LEVELS.Clear();
			HUNT_LEVELS = JsonSerializer.Deserialize<List<HuntLevel>>(File.ReadAllText(PRESTIGE));
			ManualLogSource logInstance = Plugin.LogInstance;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(13, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Mod enabled: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(ENABLE_MOD.Value);
			}
			logInstance.LogInfo(val);
		}

		public void WriteConfig()
		{
			if (!Directory.Exists(CONFIG_PATH))
			{
				Directory.CreateDirectory(CONFIG_PATH);
			}
			if (!File.Exists(PRESTIGE))
			{
				HUNT_LEVELS.Add(new HuntLevel(1, 1000, new HuntReward(), "{player} has reached {level}!"));
				HUNT_LEVELS.Add(new HuntLevel(2, 2000, new HuntReward(), "{player} has reached {level}!"));
				string contents = JsonSerializer.Serialize(HUNT_LEVELS, new JsonSerializerOptions
				{
					WriteIndented = true
				});
				File.WriteAllText(PRESTIGE, contents);
			}
		}

		public bool GetActiveSystem(Systems type)
		{
			return type switch
			{
				Systems.ENABLE => ENABLE_MOD.Value, 
				Systems.BOUNTY => ENABLE_BOUNTY.Value, 
				_ => false, 
			};
		}

		public string ToggleSystem()
		{
			ENABLE_BOUNTY.Value = !ENABLE_BOUNTY.Value;
			if (!ENABLE_BOUNTY.Value)
			{
				return "disabled";
			}
			return "enabled";
		}

		public static List<HuntLevel> GetLevels()
		{
			return HUNT_LEVELS;
		}
	}
	public enum Systems
	{
		ENABLE,
		BOUNTY
	}
}
namespace CrimsonHunt.Hooks
{
	internal class ActionScheduler
	{
		public static List<KillEvent> KillEvents = new List<KillEvent>();

		public static Action action;

		public static DateTime lastDateMinute = DateTime.Now;

		private static DateTime lastDateSecond = DateTime.Now;

		private static Dictionary<string, DateTime> lastCheck = new Dictionary<string, DateTime>();

		public static void HandleHuntFrame()
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.Settings.GetActiveSystem(Systems.ENABLE))
			{
				return;
			}
			Database.Data().SaveDatabase();
			for (int num = KillEvents.Count - 1; num >= 0; num--)
			{
				if (!(DateTime.Now - KillEvents[num].Killed < TimeSpan.FromSeconds(1.0)))
				{
					foreach (Player player in KillEvents[num].Players)
					{
						Database.Data().UpdateExp(player, KillEvents[num].Boss);
					}
					KillEvents.RemoveAt(num);
				}
			}
		}

		public static void StartTimer()
		{
			Plugin.LogInstance.LogInfo((object)"Start Timner for BloodyBoss");
			action = delegate
			{
				DateTime now = DateTime.Now;
				if (lastDateMinute.ToString("HH:mm") != now.ToString("HH:mm"))
				{
					HandleHuntFrame();
				}
				ActionSchedulerPatch.RunActionOnceAfterFrames(action, 30);
			};
			ActionSchedulerPatch.RunActionOnceAfterFrames(action, 30);
		}
	}
	[HarmonyPatch]
	public class ActionSchedulerPatch
	{
		public static int CurrentFrameCount = 0;

		public static ConcurrentQueue<Action> actionsToExecuteOnMainThread = new ConcurrentQueue<Action>();

		public static List<Timer> activeTimers;

		[HarmonyPatch(typeof(RandomizedSpawnChainUpdateSystem), "OnUpdate")]
		[HarmonyPostfix]
		public static void Postfix()
		{
			CurrentFrameCount++;
			Action result;
			while (actionsToExecuteOnMainThread.TryDequeue(out result))
			{
				result?.Invoke();
			}
		}

		public static Timer RunActionEveryInterval(Action action, double intervalInSeconds)
		{
			return new Timer(delegate
			{
				actionsToExecuteOnMainThread.Enqueue(action);
			}, null, TimeSpan.FromSeconds(intervalInSeconds), TimeSpan.FromSeconds(intervalInSeconds));
		}

		public static Timer RunActionOnceAfterDelay(Action action, double delayInSeconds)
		{
			Timer timer = null;
			timer = new Timer(delegate
			{
				actionsToExecuteOnMainThread.Enqueue(delegate
				{
					action();
					timer?.Dispose();
				});
			}, null, TimeSpan.FromSeconds(delayInSeconds), Timeout.InfiniteTimeSpan);
			return timer;
		}

		public static Timer RunActionOnceAfterFrames(Action action, int frameDelay)
		{
			int startFrame = CurrentFrameCount;
			Timer timer = null;
			timer = new Timer(delegate
			{
				if (CurrentFrameCount - startFrame >= frameDelay)
				{
					actionsToExecuteOnMainThread.Enqueue(delegate
					{
						action();
					});
					timer?.Dispose();
				}
			}, null, TimeSpan.Zero, TimeSpan.FromMilliseconds(8.0));
			return timer;
		}

		public static Timer RunActionAtTime(Action action, DateTime scheduledTime)
		{
			DateTime now = DateTime.Now;
			TimeSpan timeSpan = scheduledTime - now;
			if (timeSpan.TotalMilliseconds < 0.0)
			{
				return null;
			}
			return RunActionOnceAfterDelay(action, timeSpan.TotalSeconds);
		}

		public static void RunActionOnMainThread(Action action)
		{
			actionsToExecuteOnMainThread.Enqueue(delegate
			{
				action();
			});
		}
	}
	[HarmonyPatch]
	internal class GameFrame_Hook
	{
		[HarmonyPatch("ProjectM.GameBootstrap", "Start")]
		[HarmonyPostfix]
		public static void ServerDetours()
		{
			Plugin.LogInstance.LogInfo((object)"Game has bootstrapped. Worlds and systems now exist.");
		}
	}
	[HarmonyPatch]
	internal class Hunt
	{
		[HarmonyPatch(typeof(VBloodSystem), "OnUpdate")]
		[HarmonyPrefix]
		public static void OnUpdate_Prefix(VBloodSystem __instance)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0065: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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_00c5: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: 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)
			if (!Plugin.Settings.GetActiveSystem(Systems.ENABLE) || __instance.EventList.IsEmpty)
			{
				return;
			}
			Enumerator<VBloodConsumed> enumerator = __instance.EventList.GetEnumerator();
			PlayerCharacter val = default(PlayerCharacter);
			while (enumerator.MoveNext())
			{
				VBloodConsumed current = enumerator.Current;
				FixedString128Bytes _bossId = __instance._PrefabCollectionSystem._PrefabDataLookup[current.Source].AssetName;
				Entity vBlood = GetVBlood(__instance, current);
				Plugin.LogInstance.LogMessage((object)"VBloodSystem.OnUpdate");
				EntityManager entityManager = VWorld.Server.EntityManager;
				if (!((EntityManager)(ref entityManager)).TryGetComponentData<PlayerCharacter>(current.Target, ref val) || ((object)(FixedString128Bytes)(ref _bossId)).ToString() == "CHAR_Vermin_DireRat_VBlood" || vBlood == Entity.Null)
				{
					continue;
				}
				Player player = new Player(val.UserEntity);
				if (ActionScheduler.KillEvents.Where((KillEvent x) => x.BossName == ((object)(FixedString128Bytes)(ref _bossId)).ToString()).ToList().Count == 0)
				{
					KillEvent item = new KillEvent(vBlood, ((object)(FixedString128Bytes)(ref _bossId)).ToString());
					ActionScheduler.KillEvents.Add(item);
				}
				foreach (KillEvent killEvent in ActionScheduler.KillEvents)
				{
					if (killEvent.BossName == ((object)(FixedString128Bytes)(ref _bossId)).ToString())
					{
						killEvent.AddPlayer(player);
					}
				}
			}
		}

		private static Entity GetVBlood(VBloodSystem __instance, VBloodConsumed _event)
		{
			//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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = ((ComponentSystemBase)__instance).EntityManager;
			EntityQueryDesc[] array = new EntityQueryDesc[1];
			EntityQueryDesc val = new EntityQueryDesc();
			val.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<VBloodUnit>() });
			val.Options = (EntityQueryOptions)195;
			array[0] = val;
			EntityQuery val2 = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)array);
			NativeArray<Entity> val3 = ((EntityQuery)(ref val2)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			Entity result = Entity.Null;
			Enumerator<Entity> enumerator = val3.GetEnumerator();
			PrefabGUID val4 = default(PrefabGUID);
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				entityManager = VWorld.Server.EntityManager;
				if (((EntityManager)(ref entityManager)).TryGetComponentData<PrefabGUID>(current, ref val4) && ((PrefabGUID)(ref val4)).GuidHash == ((PrefabGUID)(ref _event.Source)).GuidHash)
				{
					result = current;
					break;
				}
			}
			return result;
		}
	}
}
namespace CrimsonHunt.Commands
{
	[CommandGroup("crimsonhunt", "bloodhunt")]
	internal class ActivateDeactivate
	{
		[Command("toggle", "t", null, "Activates / Deactivates the plugin.", null, true)]
		public static void ToggleSystem(ChatCommandContext ctx, string reason)
		{
			//IL_0015: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			string value = Plugin.Settings.ToggleSystem();
			Player player = new Player(ctx.Event.SenderUserEntity);
			string[] array = reason.Split("#");
			StringBuilder stringBuilder = new StringBuilder();
			StringBuilder stringBuilder2 = stringBuilder;
			StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(79, 2, stringBuilder2);
			handler.AppendLiteral("The Crimson Hunt system was <color=#ffc905>");
			handler.AppendFormatted(value);
			handler.AppendLiteral("</color> by <color=#ffc905>");
			handler.AppendFormatted(player.Name);
			handler.AppendLiteral("</color>!");
			stringBuilder2.Append(ref handler);
			if (!Plugin.Settings.GetActiveSystem(Systems.BOUNTY))
			{
				stringBuilder.Append(" Reason: <color=#cc2936>");
				for (int i = 0; i < array.Length; i++)
				{
					stringBuilder.Append(array[i]);
					if (i < array.Length - 1)
					{
						stringBuilder.Append(' ');
					}
				}
				stringBuilder.Append("</color>.");
			}
			ServerChatUtils.SendSystemMessageToAllClients(VWorld.Server.EntityManager, stringBuilder.ToString());
		}
	}
	[CommandGroup("crimsonhunt", "bloodhunt")]
	internal class DumpDatabase
	{
		[Command("dumpdb", "ddb", null, "Dumps the database manually.", null, true)]
		public static void Dump(ChatCommandContext ctx)
		{
			Database.Data().SaveDatabase(check: false);
			ctx.Reply($"Database Dumped! {Database.Data().PlayerExp.Count} entries");
		}
	}
	[CommandGroup("crimsonhunt", "bloodhunt")]
	internal class Event
	{
		[Command("event", null, null, "Toggle exp event.", null, true)]
		public static void ToggleExpEvent(ChatCommandContext ctx, int expBuff)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			Player player = new Player(ctx.Event.SenderUserEntity);
			if (expBuff >= 0)
			{
				Database.ExpBonus = expBuff;
				string text = ((expBuff == 0) ? ("<color=#ffc905>" + player.Name + "</color> has deactivated the <color=#ffc905>Hunt Event</color>!") : $"<color=#ffc905>{player.Name}</color> activated an <color=#ffc905>Hunt Event</color>. EXP: <color=#ffc905>+{expBuff}%</color>");
				ctx.Reply("Hunt Event " + ((expBuff == 0) ? "deactivated" : "activated") + "!");
				ServerChatUtils.SendSystemMessageToAllClients(VWorld.Server.EntityManager, text);
			}
		}
	}
	[CommandGroup("crimsonhunt", "bloodhunt")]
	internal class Leaderboard
	{
		[Command("leaderboard", "top", "Returns the top 5 Hunt Scores", null, null, false)]
		public static void GetLeaderboard(ChatCommandContext context)
		{
			List<PlayerStats> topScores = Database.Data().GetTopScores(5);
			string text = "BloodHunt Leaderboard:\n";
			for (int i = 0; i < topScores.Count; i++)
			{
				text += $"{i + 1}: <color=#ffc905>{topScores[i].Name}</color> : <color=#ffc905>{topScores[i].Exp}</color>\n";
			}
			context.Reply(text);
		}
	}
	[CommandGroup("crimsonhunt", "bloodhunt")]
	internal class ReloadCmd
	{
		[Command("reload", "rl", null, "Reloads the config of Crimson Hunt.", null, true)]
		public static void ReloadNotify(ChatCommandContext ctx)
		{
			Plugin.Settings.InitConfig();
			Database.Data().SaveDatabase();
			Database.InitDatabase("player_hunts");
			ctx.Reply($"Crimson Hunt reloaded! {Database.Data().PlayerExp.Count} entries.");
		}
	}
	[CommandGroup("crimsonhunt", "bloodhunt")]
	internal class Reward
	{
		[Command("reward", "r", null, "Give yourself a reward of hunt points", null, true)]
		public static void GiveScore(ChatCommandContext ctx, int amount)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			Player player = new Player(ctx.Event.SenderUserEntity);
			Database.Data().UpdateExp(player, amount);
		}
	}
	[CommandGroup("crimsonhunt", "bloodhunt")]
	internal class Score
	{
		[Command("score", null, null, "Get your current hunt score", null, false)]
		public static void GetScore(ChatCommandContext context)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			Player player = new Player(context.Event.SenderUserEntity);
			float exp = Database.Data().GetExp(player);
			HuntLevel prestige = Database.GetPrestige(exp);
			context.Reply($"Hunt Score progress [Lvl: <color=#ffc905>{prestige.Level}</color> ~ (<color=#ffc905>{exp.ToString("0.##", CultureInfo.InvariantCulture)}</color>/<color=#ffc905>{prestige.ExpNeeded}</color>)]");
		}
	}
	[CommandGroup("crimsonhunt", "bloodhunt")]
	internal class ToggleEffectCmd
	{
		[Command("mode", null, null, "Toggle crimson hunt effects.", null, false)]
		public static void ToggleHuntEffects(ChatCommandContext ctx)
		{
			//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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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_00e1: 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_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: 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_0119: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = VWorld.Server.EntityManager;
			Player player = new Player(ctx.Event.SenderUserEntity);
			HuntLevel prestige = Database.GetPrestige(Database.Data().GetExp(player));
			if (prestige.Level == 0)
			{
				ServerChatUtils.SendSystemMessageToClient(entityManager, ECSExtensions.Read<User>(player.User), $"You dont have any hunt score [Lvl: <color=#ffc905>{prestige.Level}</color>]");
				return;
			}
			foreach (HuntLevel level in Settings.GetLevels())
			{
				if (level.HuntReward.EffectHash != 0 && level.Level <= prestige.Level)
				{
					if (BuffUtility.HasBuff(entityManager, player.Character, PrefabIdentifier.op_Implicit(new PrefabGUID(level.HuntReward.EffectHash))))
					{
						PlayerService.UnbuffCharacter(player.Character, new PrefabGUID(level.HuntReward.EffectHash));
						ServerChatUtils.SendSystemMessageToClient(entityManager, ECSExtensions.Read<User>(player.User), $"Your hunt effect [Rank: <color=#ffc905>{level.Level}</color>] was removed!");
					}
					else
					{
						PlayerService.BuffPlayer(player.Character, player.User, new PrefabGUID(level.HuntReward.EffectHash), 0, persistsThroughDeath: true);
						ServerChatUtils.SendSystemMessageToClient(entityManager, ECSExtensions.Read<User>(player.User), $"Your hunt effect [Rank: <color=#ffc905>{level.Level}</color>] was added!");
					}
				}
			}
		}
	}
}