NPCs.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using NPCs.Data;
using NPCs.Services;
using ProjectM;
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.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("NPCs")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("NPCs is a server-side V Rising mod featuring automated scheduled NPC spawning, manual spawning and despawning, custom NPC teams, and multiple spawn points.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("NPCs")]
[assembly: AssemblyTitle("NPCs")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

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

		private static World _server;

		private static EntityManager _entityManager;

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

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

		public static ManualLogSource Log => Plugin.PluginLog;

		public static void LogException(Exception e, [CallerMemberName] string caller = null)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			ManualLogSource log = Log;
			bool flag = default(bool);
			BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(52, 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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			if (!_hasInitialized)
			{
				_server = GetWorld("Server") ?? throw new Exception("There is no Server world (yet). Did you install a server mod on the client?");
				_entityManager = _server.EntityManager;
				NpcService.Initialize();
				_hasInitialized = true;
				ManualLogSource log = Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(10, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("InitializeAfterLoaded");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" completed");
				}
				log.LogInfo(val);
			}
		}

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

		public unsafe static T Read<T>(this Entity entity) where T : struct
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = Core.EntityManager;
			void* componentDataRawRO = ((EntityManager)(ref entityManager)).GetComponentDataRawRO(entity, val.TypeIndex);
			return Marshal.PtrToStructure<T>(new IntPtr(componentDataRawRO));
		}

		public unsafe static T ReadRW<T>(this Entity entity) where T : struct
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = Core.EntityManager;
			void* componentDataRawRW = ((EntityManager)(ref entityManager)).GetComponentDataRawRW(entity, val.TypeIndex);
			return Marshal.PtrToStructure<T>(new IntPtr(componentDataRawRW));
		}

		public static bool Has<T>(this Entity entity)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = Core.EntityManager;
			return ((EntityManager)(ref entityManager)).HasComponent(entity, val);
		}

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

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

		private static byte[] StructureToByteArray<T>(T structure) where T : struct
		{
			int num = Marshal.SizeOf(structure);
			byte[] array = new byte[num];
			IntPtr intPtr = Marshal.AllocHGlobal(num);
			Marshal.StructureToPtr(structure, intPtr, fDeleteOld: true);
			Marshal.Copy(intPtr, array, 0, num);
			Marshal.FreeHGlobal(intPtr);
			return array;
		}
	}
	internal static class Helper
	{
		public static List<Entity> GetAllEntitiesInRadius<T>(float2 center2D, float radius) where T : struct
		{
			//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_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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_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_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_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_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_0086: 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)
			EntityManager entityManager = Core.EntityManager;
			List<Entity> list = new List<Entity>();
			EntityQuery val = ((EntityManager)(ref entityManager)).CreateEntityQuery((ComponentType[])(object)new ComponentType[2]
			{
				ComponentType.ReadOnly<T>(),
				ComponentType.ReadOnly<LocalToWorld>()
			});
			NativeArray<Entity> val2 = ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			float num = radius * radius;
			Enumerator<Entity> enumerator = val2.GetEnumerator();
			float2 val3 = default(float2);
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				LocalToWorld componentData = ((EntityManager)(ref entityManager)).GetComponentData<LocalToWorld>(current);
				float3 position = ((LocalToWorld)(ref componentData)).Position;
				((float2)(ref val3))..ctor(position.x, position.z);
				if (math.distancesq(center2D, val3) <= num)
				{
					list.Add(current);
				}
			}
			val2.Dispose();
			return list;
		}

		public static void BroadcastSystemMessage(string message)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				FixedString512Bytes val = default(FixedString512Bytes);
				((FixedString512Bytes)(ref val))..ctor(message ?? string.Empty);
				ServerChatUtils.SendSystemMessageToAllClients(Core.EntityManager, ref val);
			}
			catch (Exception e)
			{
				Core.LogException(e, "BroadcastSystemMessage");
			}
		}
	}
	[BepInPlugin("NPCs", "NPCs", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		internal static Harmony Harmony;

		internal static ManualLogSource PluginLog;

		internal static Plugin Instance;

		public static ConfigEntry<bool> ModEnabled;

		public static ConfigEntry<bool> BroadcastEnable;

		public static ConfigEntry<string> BroadcastMessage;

		public static ConfigEntry<float> LifetimeSeconds;

		public static ConfigEntry<int> HourlySpawnAtMinute;

		public static ConfigEntry<int> HourlySpawnAtSecond;

		public override void Load()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Expected O, but got Unknown
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Expected O, but got Unknown
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Expected O, but got Unknown
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Expected O, but got Unknown
			if (!(Application.productName != "VRisingServer"))
			{
				Instance = this;
				PluginLog = ((BasePlugin)this).Log;
				ManualLogSource log = ((BasePlugin)this).Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(27, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("NPCs");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" version ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.0");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
				}
				log.LogInfo(val);
				ModEnabled = ((BasePlugin)this).Config.Bind<bool>("General", "ModEnabled", true, "Enable or disable the mod");
				BroadcastEnable = ((BasePlugin)this).Config.Bind<bool>("General", "BroadcastEnable", true, "Enable or disable the broadcast message when NPCs spawn");
				BroadcastMessage = ((BasePlugin)this).Config.Bind<string>("General", "BroadcastMessage", "<color=green>NPCs have spawned</color>", "Broadcast message shown when NPCs spawn");
				LifetimeSeconds = ((BasePlugin)this).Config.Bind<float>("Timer", "LifetimeSeconds", 1200f, new ConfigDescription("How long NPCs stay alive in seconds before auto-despawning", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 3599f), Array.Empty<object>()));
				HourlySpawnAtMinute = ((BasePlugin)this).Config.Bind<int>("Schedule", "HourlySpawnAtMinute", 0, new ConfigDescription("Minute of each hour to spawn", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 59), Array.Empty<object>()));
				HourlySpawnAtSecond = ((BasePlugin)this).Config.Bind<int>("Schedule", "HourlySpawnAtSecond", 0, new ConfigDescription("Second of each hour to spawn", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 59), Array.Empty<object>()));
				Harmony = new Harmony("NPCs");
				Harmony.PatchAll(Assembly.GetExecutingAssembly());
				NpcService.Initialize();
				CommandRegistry.RegisterAll();
			}
		}

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

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

		public const string PLUGIN_NAME = "NPCs";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace NPCs.Services
{
	internal static class NpcService
	{
		private static readonly string CONFIG_DIR = Path.Combine(Paths.ConfigPath, "NPCs");

		private static readonly string CONFIG_NPC_TEAMS_FILE = Path.Combine(CONFIG_DIR, "npc_teams.json");

		private static readonly object IO_LOCK = new object();

		private const float DespawnExtraRadius = 12f;

		private static DateTime _nextSpawnLocal;

		private static bool _schedulerInited;

		private static bool _despawnArmed;

		private static DateTime _despawnDueLocal;

		private static DateTime _nextErrorLogLocal = DateTime.MinValue;

		public static Dictionary<string, TeamConfig> Teams = new Dictionary<string, TeamConfig>(StringComparer.OrdinalIgnoreCase);

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

		public static DateTime NextSpawnLocal => _nextSpawnLocal;

		public static void Initialize()
		{
			Load();
			InitScheduler();
		}

		public static void InitScheduler()
		{
			if (!_schedulerInited)
			{
				_schedulerInited = true;
				_nextSpawnLocal = ComputeNextHourAt(DateTime.Now);
			}
		}

		public static void Reload()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			DespawnNpc();
			((BasePlugin)Plugin.Instance).Config.Reload();
			Load();
			_despawnArmed = false;
			_nextSpawnLocal = ComputeNextHourAt(DateTime.Now);
			ManualLogSource log = Core.Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(54, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[NPCs] Config reloaded. Next auto-spawn scheduled at: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<DateTime>(_nextSpawnLocal, "HH:mm:ss");
			}
			log.LogInfo(val);
		}

		public static void Load()
		{
			try
			{
				lock (IO_LOCK)
				{
					if (!Directory.Exists(CONFIG_DIR))
					{
						Directory.CreateDirectory(CONFIG_DIR);
					}
					if (!File.Exists(CONFIG_NPC_TEAMS_FILE))
					{
						GenerateDefaultConfig();
						return;
					}
					string json = File.ReadAllText(CONFIG_NPC_TEAMS_FILE);
					Teams = JsonSerializer.Deserialize<Dictionary<string, TeamConfig>>(json, JsonOptions) ?? new Dictionary<string, TeamConfig>(StringComparer.OrdinalIgnoreCase);
				}
			}
			catch (Exception e)
			{
				Core.LogException(e, "Load");
				Teams = new Dictionary<string, TeamConfig>(StringComparer.OrdinalIgnoreCase);
			}
		}

		public static void Save()
		{
			try
			{
				lock (IO_LOCK)
				{
					if (!Directory.Exists(CONFIG_DIR))
					{
						Directory.CreateDirectory(CONFIG_DIR);
					}
					string contents = JsonSerializer.Serialize(Teams, JsonOptions);
					File.WriteAllText(CONFIG_NPC_TEAMS_FILE, contents);
				}
			}
			catch (Exception e)
			{
				Core.LogException(e, "Save");
			}
		}

		public static void SpawnNpc(Entity user)
		{
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected O, but got Unknown
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!Plugin.ModEnabled.Value)
				{
					return;
				}
				DespawnNpc();
				UnitSpawnerUpdateSystem existingSystemManaged = Core.Server.GetExistingSystemManaged<UnitSpawnerUpdateSystem>();
				Random random = new Random();
				bool flag = default(bool);
				PrefabGUID val2 = default(PrefabGUID);
				float3 val3 = default(float3);
				foreach (TeamConfig value2 in Teams.Values)
				{
					if (value2?.SpawnPoints == null || value2.SpawnPoints.Count == 0 || value2.Prefabs == null || value2.Prefabs.Count == 0)
					{
						continue;
					}
					foreach (SimpleVec3 spawnPoint in value2.SpawnPoints)
					{
						foreach (KeyValuePair<string, int> prefab in value2.Prefabs)
						{
							if (!int.TryParse(prefab.Key, out var result))
							{
								continue;
							}
							if (!WhitelistPrefabs.IsAllowed(result))
							{
								ManualLogSource log = Core.Log;
								BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(42, 1, ref flag);
								if (flag)
								{
									((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[NPCs] Spawn skipped for unlisted prefab: ");
									((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(result);
								}
								log.LogWarning(val);
								continue;
							}
							((PrefabGUID)(ref val2))..ctor(result);
							int value = prefab.Value;
							for (int i = 0; i < value; i++)
							{
								float num = (float)(random.NextDouble() * 2.0 - 1.0) * value2.RandomAround;
								float num2 = (float)(random.NextDouble() * 2.0 - 1.0) * value2.RandomAround;
								((float3)(ref val3))..ctor(spawnPoint.X + num, spawnPoint.Y, spawnPoint.Z + num2);
								existingSystemManaged.SpawnUnit(Entity.Null, val2, val3, 1, 1f, 1f, Plugin.LifetimeSeconds.Value);
							}
						}
					}
				}
				if (Plugin.BroadcastEnable.Value)
				{
					Helper.BroadcastSystemMessage(Plugin.BroadcastMessage.Value);
				}
				Core.Log.LogInfo((object)"[NPCs] Spawned NPCs successfully.");
			}
			catch (Exception e)
			{
				Core.LogException(e, "SpawnNpc");
			}
		}

		public static int DespawnNpc(float extraRadius = 12f, string specificTeam = null, string specificPrefab = null)
		{
			//IL_0004: 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_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Expected O, but got Unknown
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0412: Unknown result type (might be due to invalid IL or missing references)
			//IL_0417: Unknown result type (might be due to invalid IL or missing references)
			//IL_041c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0382: Unknown result type (might be due to invalid IL or missing references)
			//IL_0386: Unknown result type (might be due to invalid IL or missing references)
			//IL_042a: Unknown result type (might be due to invalid IL or missing references)
			//IL_042b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Expected O, but got Unknown
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				int num = 0;
				EntityManager entityManager = Core.EntityManager;
				Dictionary<int, List<(float2, float)>> dictionary = new Dictionary<int, List<(float2, float)>>();
				bool flag = default(bool);
				float2 item2 = default(float2);
				foreach (KeyValuePair<string, TeamConfig> team in Teams)
				{
					if (specificTeam != null && !string.Equals(team.Key, specificTeam, StringComparison.OrdinalIgnoreCase))
					{
						continue;
					}
					TeamConfig value = team.Value;
					if (value.SpawnPoints == null || value.SpawnPoints.Count == 0 || value.Prefabs == null || value.Prefabs.Count == 0)
					{
						continue;
					}
					float item = (value.RandomAround + extraRadius) * (value.RandomAround + extraRadius);
					List<int> list = new List<int>();
					foreach (KeyValuePair<string, int> prefab in value.Prefabs)
					{
						if ((!string.IsNullOrEmpty(specificPrefab) && !string.Equals(prefab.Key, specificPrefab, StringComparison.OrdinalIgnoreCase)) || !int.TryParse(prefab.Key, out var result))
						{
							continue;
						}
						if (WhitelistPrefabs.IsAllowed(result))
						{
							list.Add(result);
							continue;
						}
						ManualLogSource log = Core.Log;
						BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(44, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[NPCs] Despawn skipped for unlisted prefab: ");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(result);
						}
						log.LogWarning(val);
					}
					foreach (SimpleVec3 spawnPoint in value.SpawnPoints)
					{
						((float2)(ref item2))..ctor(spawnPoint.X, spawnPoint.Z);
						foreach (int item3 in list)
						{
							if (!dictionary.ContainsKey(item3))
							{
								dictionary[item3] = new List<(float2, float)>();
							}
							dictionary[item3].Add((item2, item));
						}
					}
				}
				if (dictionary.Count == 0)
				{
					return 0;
				}
				EntityQueryDesc val2 = new EntityQueryDesc();
				val2.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[3]
				{
					ComponentType.ReadOnly<PrefabGUID>(),
					ComponentType.ReadOnly<Translation>(),
					ComponentType.ReadOnly<Health>()
				});
				val2.Options = (EntityQueryOptions)2;
				EntityQueryDesc val3 = val2;
				EntityQuery val4 = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)new EntityQueryDesc[1] { val3 });
				NativeArray<Entity> val5 = ((EntityQuery)(ref val4)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
				NativeArray<PrefabGUID> val6 = ((EntityQuery)(ref val4)).ToComponentDataArray<PrefabGUID>(AllocatorHandle.op_Implicit((Allocator)2));
				NativeArray<Translation> val7 = ((EntityQuery)(ref val4)).ToComponentDataArray<Translation>(AllocatorHandle.op_Implicit((Allocator)2));
				List<Entity> list2 = new List<Entity>();
				float2 val9 = default(float2);
				for (int i = 0; i < val5.Length; i++)
				{
					PrefabGUID val8 = val6[i];
					int guidHash = ((PrefabGUID)(ref val8)).GuidHash;
					if (!dictionary.TryGetValue(guidHash, out var value2))
					{
						continue;
					}
					((float2)(ref val9))..ctor(val7[i].Value.x, val7[i].Value.z);
					foreach (var item4 in value2)
					{
						if (math.distancesq(val9, item4.Item1) <= item4.Item2)
						{
							list2.Add(val5[i]);
							break;
						}
					}
				}
				val5.Dispose();
				val6.Dispose();
				val7.Dispose();
				foreach (Entity item5 in list2)
				{
					if (((EntityManager)(ref entityManager)).Exists(item5))
					{
						DestroyUtility.Destroy(entityManager, item5, (DestroyDebugReason)13, (string)null, 0);
						num++;
					}
				}
				Core.Log.LogInfo((object)"[NPCs] Despawned NPCs successfully.");
				return num;
			}
			catch (Exception e)
			{
				Core.LogException(e, "DespawnNpc");
				return 0;
			}
		}

		public static void TickScheduler()
		{
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.ModEnabled.Value)
			{
				return;
			}
			DateTime now = DateTime.Now;
			if (_despawnArmed && now >= _despawnDueLocal)
			{
				_despawnArmed = false;
				try
				{
					DespawnNpc();
				}
				catch (Exception e)
				{
					if (now > _nextErrorLogLocal)
					{
						Core.LogException(e, "TickScheduler");
						_nextErrorLogLocal = now.AddMinutes(5.0);
					}
				}
			}
			if (!(now >= _nextSpawnLocal))
			{
				return;
			}
			_nextSpawnLocal = ComputeNextHourAt(now);
			_despawnArmed = true;
			_despawnDueLocal = now.AddSeconds(Plugin.LifetimeSeconds.Value + 1f);
			try
			{
				SpawnNpc(Entity.Null);
			}
			catch (Exception e2)
			{
				if (now > _nextErrorLogLocal)
				{
					Core.LogException(e2, "TickScheduler");
					_nextErrorLogLocal = now.AddMinutes(5.0);
				}
			}
		}

		private static DateTime ComputeNextHourAt(DateTime now)
		{
			DateTime dateTime = new DateTime(now.Year, now.Month, now.Day, now.Hour, Plugin.HourlySpawnAtMinute.Value, Plugin.HourlySpawnAtSecond.Value);
			if (dateTime <= now)
			{
				return dateTime.AddHours(1.0);
			}
			return dateTime;
		}

		private static void GenerateDefaultConfig()
		{
			Teams.Clear();
			Teams.Add("villager", new TeamConfig
			{
				RandomAround = 18f,
				Prefabs = new Dictionary<string, int>
				{
					{ "-1670130821", 1 },
					{ "-1224027101", 5 },
					{ "-2025921616", 5 }
				}
			});
			Teams.Add("nun", new TeamConfig
			{
				RandomAround = 4f,
				Prefabs = new Dictionary<string, int>
				{
					{ "-700632469", 1 },
					{ "1772642154", 4 }
				}
			});
			Teams.Add("guard", new TeamConfig
			{
				RandomAround = 8f,
				Prefabs = new Dictionary<string, int>
				{
					{ "847893333", 1 },
					{ "203103783", 1 },
					{ "37713289", 1 },
					{ "1730498275", 2 },
					{ "2005508157", 2 },
					{ "-249647316", 1 }
				}
			});
			Teams.Add("warrior", new TeamConfig
			{
				RandomAround = 12f,
				Prefabs = new Dictionary<string, int>
				{
					{ "426583055", 2 },
					{ "2128996433", 2 },
					{ "-930333806", 2 },
					{ "794228023", 2 },
					{ "1148936156", 2 },
					{ "1728773109", 2 },
					{ "1745498602", 1 },
					{ "-1464869978", 1 },
					{ "1185952775", 1 },
					{ "1406393857", 1 },
					{ "-700632469", 1 },
					{ "1660801216", 1 }
				}
			});
			Teams.Add("vamp", new TeamConfig
			{
				RandomAround = 10f,
				Prefabs = new Dictionary<string, int>
				{
					{ "-1076780215", 2 },
					{ "1912966420", 2 },
					{ "981369753", 2 },
					{ "-65981941", 1 },
					{ "-494298686", 1 },
					{ "-1009917656", 1 },
					{ "-653348998", 1 },
					{ "1980594081", 1 },
					{ "16593505050", 4 }
				}
			});
			Teams.Add("horse", new TeamConfig
			{
				RandomAround = 5f,
				Prefabs = new Dictionary<string, int> { { "1149585723", 4 } }
			});
			Save();
		}
	}
}
namespace NPCs.Patches
{
	[HarmonyPatch(typeof(ServerBootstrapSystem), "OnUpdate")]
	internal static class InitializationPatch
	{
		private static void Postfix()
		{
			if (Plugin.HasLoaded())
			{
				Core.InitializeAfterLoaded();
			}
		}
	}
	[HarmonyPatch(typeof(ServerBootstrapSystem), "OnUpdate")]
	internal static class NpcAutoSpawnPatch
	{
		private static float _nextTick;

		private static bool _loggedOnce;

		private static void Postfix()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			if (Time.time < _nextTick)
			{
				return;
			}
			_nextTick = Time.time + 1f;
			try
			{
				NpcService.TickScheduler();
			}
			catch (Exception ex)
			{
				if (!_loggedOnce)
				{
					_loggedOnce = true;
					ManualLogSource log = Core.Log;
					bool flag = default(bool);
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(32, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[NPCs] Scheduler not ready yet: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					}
					log.LogWarning(val);
				}
			}
		}
	}
}
namespace NPCs.Data
{
	public class TeamConfig
	{
		public float RandomAround { get; set; } = 5f;


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


		public List<SimpleVec3> SpawnPoints { get; set; } = new List<SimpleVec3>();

	}
	public struct SimpleVec3
	{
		public float X { get; set; }

		public float Y { get; set; }

		public float Z { get; set; }

		public SimpleVec3(float3 v)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			X = v.x;
			Y = v.y;
			Z = v.z;
		}

		public float3 ToFloat3()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return new float3(X, Y, Z);
		}
	}
	internal static class WhitelistPrefabs
	{
		private static readonly Dictionary<int, string> AllowedPrefabs = new Dictionary<int, string>
		{
			{ 2138173476, "CHAR_ArchMage_FlameSphere" },
			{ -2013903325, "CHAR_ArchMage_VBlood" },
			{ 692079022, "CHAR_Arena_HealthOrb" },
			{ -1128238456, "CHAR_Bandit_Bomber" },
			{ 1896428751, "CHAR_Bandit_Bomber_VBlood" },
			{ 1854211210, "CHAR_Bandit_Chaosarrow_GateBoss_Minor" },
			{ 763273073, "CHAR_Bandit_Chaosarrow_VBlood" },
			{ -1030822544, "CHAR_Bandit_Deadeye" },
			{ -2122682556, "CHAR_Bandit_Fisherman_VBlood" },
			{ 2122229952, "CHAR_Bandit_Foreman_VBlood" },
			{ 17609984, "CHAR_Bandit_Foreman_VBlood_GateBoss_Minor" },
			{ 1124739990, "CHAR_Bandit_Frostarrow_VBlood" },
			{ -1301144178, "CHAR_Bandit_Hunter" },
			{ 343676339, "CHAR_Bandit_Hunter_MicroPOI_Cocoon" },
			{ 2057508774, "CHAR_Bandit_Mugger" },
			{ 1069072707, "CHAR_Bandit_Prisoner_Villager_Female" },
			{ 286320185, "CHAR_Bandit_Prisoner_Villager_Male" },
			{ -1194643220, "CHAR_Bandit_Rascal" },
			{ 1220569089, "CHAR_Bandit_Scout" },
			{ -309264723, "CHAR_Bandit_Stalker" },
			{ 1106149033, "CHAR_Bandit_Stalker_VBlood" },
			{ -2025101517, "CHAR_Bandit_StoneBreaker_VBlood" },
			{ -1420322422, "CHAR_Bandit_StoneBreaker_VBlood_GateBoss_Minor" },
			{ 923140362, "CHAR_Bandit_Thief" },
			{ -301730941, "CHAR_Bandit_Thug" },
			{ -198252716, "CHAR_Bandit_Thug_MicroPOI_Cocoon" },
			{ 478580792, "CHAR_Bandit_Tourok_GateBoss_Minor" },
			{ -1659822956, "CHAR_Bandit_Tourok_VBlood" },
			{ -589412777, "CHAR_Bandit_Trapper" },
			{ -1554428547, "CHAR_Bandit_Wolf" },
			{ 1743532914, "CHAR_Bandit_Worker_Gatherer" },
			{ -2039670689, "CHAR_Bandit_Worker_Miner" },
			{ 1309418594, "CHAR_Bandit_Worker_Woodcutter" },
			{ 1112948824, "CHAR_BatVampire_VBlood" },
			{ 326501064, "CHAR_Blackfang_Alchemist" },
			{ -1669199769, "CHAR_Blackfang_CarverBoss_VBlood" },
			{ 1209580976, "CHAR_Blackfang_DartFlinger" },
			{ -1383529374, "CHAR_Blackfang_Livith_VBlood" },
			{ 1295855316, "CHAR_Blackfang_Lucie_VBlood" },
			{ -1733829912, "CHAR_Blackfang_Lurker" },
			{ 591725925, "CHAR_Blackfang_Morgana_VBlood" },
			{ -1562098554, "CHAR_Blackfang_Peon" },
			{ -699233841, "CHAR_Blackfang_Peon_Miner" },
			{ 1924724671, "CHAR_Blackfang_PeonCarryingBarrel" },
			{ 1451256919, "CHAR_Blackfang_PeonLogCarryer" },
			{ 1531777139, "CHAR_Blackfang_Sentinel" },
			{ 761646020, "CHAR_Blackfang_Striker" },
			{ 173259239, "CHAR_Blackfang_Valyr_VBlood" },
			{ 1439742793, "CHAR_Blackfang_ValyrCauldron" },
			{ 1864177126, "CHAR_Blackfang_Venomblade" },
			{ -436956599, "CHAR_Blackfang_Viper" },
			{ -1508046438, "CHAR_Blackfang_WoodCarver" },
			{ -625375348, "CHAR_Blackfang_WoodCarver_Worshipper" },
			{ 1900336326, "CHAR_Carriage_BanditAnimal" },
			{ 1866779672, "CHAR_Carriage_BanditCopper" },
			{ -364183632, "CHAR_Carriage_BanditPlank" },
			{ -1190354298, "CHAR_Carriage_BanditPrisoners" },
			{ 855721879, "CHAR_Carriage_BanditSulfur" },
			{ -1395711815, "CHAR_Carriage_BlackfangBastion" },
			{ -2075236675, "CHAR_Carriage_BlackfangSouth" },
			{ -84975023, "CHAR_Carriage_ChuchGrape" },
			{ -1048977650, "CHAR_Carriage_ChuchSilver" },
			{ 177376927, "CHAR_Carriage_ChurchLegion" },
			{ 400170781, "CHAR_Carriage_ChurchMutants" },
			{ 213173421, "CHAR_Carriage_MilitiaCotton" },
			{ 769065062, "CHAR_Carriage_MilitiaIron" },
			{ -75106506, "CHAR_Carriage_MilitiaQuartz" },
			{ -799718518, "CHAR_CarriageHorse_BanditAnimal" },
			{ -443327719, "CHAR_CarriageHorse_BanditCopper" },
			{ -1859852856, "CHAR_CarriageHorse_BanditPlank" },
			{ -1761137820, "CHAR_CarriageHorse_BanditPrisoners" },
			{ -1193126567, "CHAR_CarriageHorse_BanditSulfur" },
			{ 731857280, "CHAR_CarriageHorse_BlackfangBastion" },
			{ 96544496, "CHAR_CarriageHorse_BlackfangSouth" },
			{ 803219139, "CHAR_CarriageHorse_ChuchGrape" },
			{ -1588337666, "CHAR_CarriageHorse_ChuchSilver" },
			{ 452018442, "CHAR_CarriageHorse_ChurchLegion" },
			{ -1666526529, "CHAR_CarriageHorse_ChurchMutants" },
			{ -755774482, "CHAR_CarriageHorse_MilitiaCotton" },
			{ 1510247015, "CHAR_CarriageHorse_MilitiaIron" },
			{ 374565592, "CHAR_CarriageHorse_MilitiaQuartz" },
			{ 426583055, "CHAR_ChurchOfLight_Archer" },
			{ 114912615, "CHAR_ChurchOfLight_Cardinal_VBlood" },
			{ 1745498602, "CHAR_ChurchOfLight_CardinalAide" },
			{ -1464869978, "CHAR_ChurchOfLight_Cleric" },
			{ -1449314709, "CHAR_ChurchOfLight_EnchantedCross" },
			{ 2128996433, "CHAR_ChurchOfLight_Footman" },
			{ -930333806, "CHAR_ChurchOfLight_Knight_2H" },
			{ 794228023, "CHAR_ChurchOfLight_Knight_Shield" },
			{ 1185952775, "CHAR_ChurchOfLight_Lightweaver" },
			{ 924132254, "CHAR_ChurchOfLight_Miner_Standard" },
			{ -26105228, "CHAR_ChurchOfLight_Overseer_VBlood" },
			{ 1728773109, "CHAR_ChurchOfLight_Paladin" },
			{ -740796338, "CHAR_ChurchOfLight_Paladin_VBlood" },
			{ 1406393857, "CHAR_ChurchOfLight_Priest" },
			{ 1148936156, "CHAR_ChurchOfLight_Rifleman" },
			{ 891705701, "CHAR_ChurchOfLight_SlaveMaster_Enforcer" },
			{ -240536861, "CHAR_ChurchOfLight_SlaveMaster_Sentry" },
			{ -1875351031, "CHAR_ChurchOfLight_SlaveRuffian" },
			{ -1387838833, "CHAR_ChurchOfLight_SlaveRuffian_Cover" },
			{ 1917502536, "CHAR_ChurchOfLight_SmiteOrb" },
			{ 192051202, "CHAR_ChurchOfLight_Sommelier_VBlood" },
			{ -1224027101, "CHAR_ChurchOfLight_Villager_Female" },
			{ -2025921616, "CHAR_ChurchOfLight_Villager_Male" },
			{ 1107541186, "CHAR_CopperGolem" },
			{ -1697944553, "CHAR_Corrupted_Bear_Standard" },
			{ 1029047051, "CHAR_Corrupted_Crow" },
			{ 1780171587, "CHAR_Corrupted_Deer" },
			{ 616274140, "CHAR_Corrupted_Wolf" },
			{ -575831311, "CHAR_CreatureDeer_Mutated" },
			{ 1570140219, "CHAR_CreatureMoose_Mutated" },
			{ -2072914343, "CHAR_Critter_Rat" },
			{ -1587402408, "CHAR_Critter_Silkworm" },
			{ -372256748, "CHAR_Critter_VerminNest_Rat" },
			{ 2055824593, "CHAR_Cultist_Pyromancer" },
			{ 1807491570, "CHAR_Cultist_Slicer" },
			{ 1105583702, "CHAR_Cursed_Bear_Spirit" },
			{ -559819989, "CHAR_Cursed_Bear_Standard" },
			{ 575918722, "CHAR_Cursed_MonsterToad" },
			{ -744966291, "CHAR_Cursed_Mosquito" },
			{ -935560085, "CHAR_Cursed_MountainBeast_SpiritDouble" },
			{ -1936575244, "CHAR_Cursed_MountainBeast_VBlood" },
			{ -2046268156, "CHAR_Cursed_Nightlurker" },
			{ -203043163, "CHAR_Cursed_ToadKing_VBlood" },
			{ 1478790879, "CHAR_Cursed_ToadSpitter" },
			{ -56441915, "CHAR_Cursed_Witch" },
			{ -1399273168, "CHAR_Cursed_Witch_Exploding_Mosquito" },
			{ -54072010, "CHAR_Cursed_Witch_NetherDemon" },
			{ -910296704, "CHAR_Cursed_Witch_VBlood" },
			{ -218175217, "CHAR_Cursed_Wolf" },
			{ 407089231, "CHAR_Cursed_Wolf_Spirit" },
			{ 658578725, "CHAR_Cursed_WormTerror" },
			{ 1406266284, "CHAR_Dracula_BloodSoul" },
			{ 55100532, "CHAR_Dracula_BloodSoul_Heart" },
			{ -2092104425, "CHAR_Dracula_ShadowBatSwarm" },
			{ 32692466, "CHAR_Dracula_SpellStone_LargeBlood" },
			{ -1388651766, "CHAR_EmeryElemental" },
			{ 1787640747, "CHAR_EmeryGolem" },
			{ -578677530, "CHAR_Farmland_Wolf" },
			{ 721166952, "CHAR_Farmlands_Cow" },
			{ -1342764880, "CHAR_Farmlands_Farmer" },
			{ 729746981, "CHAR_Farmlands_HostileVillager_Female_FryingPan" },
			{ 1576267559, "CHAR_Farmlands_HostileVillager_Female_Pitchfork" },
			{ -164116132, "CHAR_Farmlands_HostileVillager_Male_Club" },
			{ -864975423, "CHAR_Farmlands_HostileVillager_Male_Shovel" },
			{ -81727312, "CHAR_Farmlands_HostileVillager_Male_Torch" },
			{ -1353870145, "CHAR_Farmlands_HostileVillager_Male_Unarmed" },
			{ -951976780, "CHAR_Farmlands_HostileVillager_Werewolf" },
			{ -1356006948, "CHAR_Farmlands_Pig" },
			{ 947731555, "CHAR_Farmlands_Ram" },
			{ 1012307512, "CHAR_Farmlands_Sheep" },
			{ 1635167941, "CHAR_Farmlands_SheepOld" },
			{ 1420480270, "CHAR_Farmlands_SmallPig" },
			{ 525027204, "CHAR_Farmlands_Villager_Female" },
			{ 1772642154, "CHAR_Farmlands_Villager_Female_Sister" },
			{ 1887807944, "CHAR_Farmlands_Villager_Male" },
			{ -893091615, "CHAR_Farmlands_Woodcutter_Standard" },
			{ 2097040330, "CHAR_Forest_AngryMoose" },
			{ -1391546313, "CHAR_Forest_Bear_Dire_Vblood" },
			{ 1043643344, "CHAR_Forest_Bear_Standard" },
			{ -2002658567, "CHAR_Forest_Crow" },
			{ 1897056612, "CHAR_Forest_Deer" },
			{ 1696014952, "CHAR_Forest_Deer_StayCloseToSpawn" },
			{ -831097925, "CHAR_Forest_Moose" },
			{ -1418430647, "CHAR_Forest_Wolf" },
			{ -1905691330, "CHAR_Forest_Wolf_VBlood" },
			{ 1318855899, "CHAR_Frostarrow_GateBoss_Minor" },
			{ -1084690188, "CHAR_GateBoss_Pixie" },
			{ -1065970933, "CHAR_Geomancer_Human_VBlood" },
			{ 1756241788, "CHAR_Gloomrot_AceIncinerator" },
			{ -1707267769, "CHAR_Gloomrot_Batoon" },
			{ 172235178, "CHAR_Gloomrot_Iva_VBlood" },
			{ 1233988687, "CHAR_Gloomrot_Monster_VBlood" },
			{ 106480588, "CHAR_Gloomrot_Purifier_VBlood" },
			{ -440174408, "CHAR_Gloomrot_Purifier_VBlood_GateBoss_Major" },
			{ -322293503, "CHAR_Gloomrot_Pyro" },
			{ 1732477970, "CHAR_Gloomrot_Railgunner" },
			{ 2054432370, "CHAR_Gloomrot_RailgunSergeant_VBlood" },
			{ 1401026468, "CHAR_Gloomrot_SentryOfficer" },
			{ -1082044089, "CHAR_Gloomrot_SentryTurret" },
			{ 709450349, "CHAR_Gloomrot_SpiderTank_Driller" },
			{ -884401089, "CHAR_Gloomrot_SpiderTank_Gattler" },
			{ 1655577903, "CHAR_Gloomrot_SpiderTank_LightningRod" },
			{ -2018710724, "CHAR_Gloomrot_SpiderTank_Zapper" },
			{ 674807351, "CHAR_Gloomrot_Tazer" },
			{ 820492683, "CHAR_Gloomrot_Technician" },
			{ -825299465, "CHAR_Gloomrot_Technician_Labworker" },
			{ 814083983, "CHAR_Gloomrot_TheProfessor_VBlood" },
			{ -293507834, "CHAR_Gloomrot_TractorBeamer" },
			{ 1216169364, "CHAR_Gloomrot_Villager_Female" },
			{ -732208863, "CHAR_Gloomrot_Villager_Male" },
			{ -1101874342, "CHAR_Gloomrot_Voltage_VBlood" },
			{ -427888732, "CHAR_Gloomrot_Voltage_VBlood_GateBoss_Major" },
			{ 192241915, "CHAR_GoldGolem" },
			{ -221278041, "CHAR_Graveyard_Crow" },
			{ -1846851895, "CHAR_Harpy_Dasher" },
			{ -1407234470, "CHAR_Harpy_FeatherDuster" },
			{ 685266977, "CHAR_Harpy_Matriarch_VBlood" },
			{ 1462269123, "CHAR_Harpy_Scratcher" },
			{ 1224283123, "CHAR_Harpy_Sorceress" },
			{ 1405099312, "CHAR_Harpy_Sorceress_NetherDemon" },
			{ 302393064, "CHAR_IceElemental" },
			{ 763796308, "CHAR_IronGolem" },
			{ -1794508086, "CHAR_IronGolem_NetherDemon" },
			{ -1076780215, "CHAR_Legion_Assassin" },
			{ 593505050, "CHAR_Legion_BatSwarm" },
			{ -1055380229, "CHAR_Legion_BatSwarm_Lesser" },
			{ 1912966420, "CHAR_Legion_BloodProphet" },
			{ -2080231735, "CHAR_Legion_BloodProphet_Lesser" },
			{ 981369753, "CHAR_Legion_Dreadhorn" },
			{ -1140588645, "CHAR_Legion_DreadHorn_Lesser" },
			{ -65981941, "CHAR_Legion_Gargoyle" },
			{ 280858720, "CHAR_Legion_Gargoyle_StatueSpawn" },
			{ -392776091, "CHAR_Legion_Gargoyle_Styx" },
			{ -669027288, "CHAR_Legion_Guardian_DraculaMinion" },
			{ 1144208724, "CHAR_Legion_Guardian_DraculaMinion_Lesser" },
			{ -1266036232, "CHAR_Legion_HighLord_GroundSword" },
			{ -494298686, "CHAR_Legion_NightMaiden" },
			{ 2111003460, "CHAR_Legion_NightMaiden_Lesser" },
			{ -1009917656, "CHAR_Legion_Nightmare" },
			{ -981051151, "CHAR_Legion_Nightmare_Lesser" },
			{ 1980594081, "CHAR_Legion_Shadowkin" },
			{ -1200074387, "CHAR_Legion_Shadowkin_Lesser" },
			{ -653348998, "CHAR_Legion_Vargulf" },
			{ 2049379982, "CHAR_Legion_Vargulf_Lesser" },
			{ -1252779334, "CHAR_Manticore_Airborne" },
			{ -767167590, "CHAR_Manticore_FarbaneSuprise" },
			{ -393555055, "CHAR_Manticore_VBlood" },
			{ 1527640414, "CHAR_Mantrap_Corrupted" },
			{ -1915060856, "CHAR_Mantrap_Corrupted_XL" },
			{ -878541676, "CHAR_Mantrap_Dull" },
			{ 2016963774, "CHAR_Mantrap_Nest" },
			{ 173817657, "CHAR_Mantrap_Standard" },
			{ -1670130821, "CHAR_Militia_BellRinger" },
			{ -680831417, "CHAR_Militia_BishopOfDunley_VBlood" },
			{ 847893333, "CHAR_Militia_Bomber" },
			{ 85290673, "CHAR_Militia_ConstrainingPole" },
			{ 956965183, "CHAR_Militia_Crossbow" },
			{ 1660801216, "CHAR_Militia_Devoted" },
			{ -1254618756, "CHAR_Militia_EyeOfGod" },
			{ 619948378, "CHAR_Militia_Fabian_VBlood" },
			{ 826666431, "CHAR_Militia_FabiansSteed" },
			{ 910988233, "CHAR_Militia_Glassblower_VBlood" },
			{ 1730498275, "CHAR_Militia_Guard" },
			{ -29797003, "CHAR_Militia_Guard_VBlood" },
			{ 1494126678, "CHAR_Militia_Guard_VBlood_GateBoss_Minor" },
			{ 2005508157, "CHAR_Militia_Heavy" },
			{ -235172198, "CHAR_Militia_Horseman" },
			{ -1914181232, "CHAR_Militia_Horseman_Mount" },
			{ -249647316, "CHAR_Militia_Hound" },
			{ -1373413273, "CHAR_Militia_Hound_VBlood" },
			{ -784265984, "CHAR_Militia_HoundMaster_VBlood" },
			{ 2090982759, "CHAR_Militia_InkCrawler" },
			{ 1688478381, "CHAR_Militia_Leader_VBlood" },
			{ 1990744594, "CHAR_Militia_Leader_VBlood_GateBoss_Major" },
			{ -63435588, "CHAR_Militia_Light" },
			{ 203103783, "CHAR_Militia_Longbowman" },
			{ 850622034, "CHAR_Militia_Longbowman_LightArrow_Vblood" },
			{ -1072754152, "CHAR_Militia_Miner_Standard" },
			{ -700632469, "CHAR_Militia_Nun" },
			{ -99012450, "CHAR_Militia_Nun_VBlood" },
			{ -1719333743, "CHAR_Militia_Rider" },
			{ 1945956671, "CHAR_Militia_Scribe_VBlood" },
			{ 37713289, "CHAR_Militia_Torchbearer" },
			{ -614820237, "CHAR_Militia_Undead_Infiltrator" },
			{ -1977168943, "CHAR_Monster_LightningPillar" },
			{ 1149585723, "CHAR_Mount_Horse" },
			{ 1938756250, "CHAR_Mutant_Bear_Standard" },
			{ 823276204, "CHAR_Mutant_FleshGolem" },
			{ -1025552087, "CHAR_Mutant_FleshGolem_PrisonVariant" },
			{ -375581934, "CHAR_Mutant_RatHorror" },
			{ 1092792896, "CHAR_Mutant_Spitter" },
			{ 572729167, "CHAR_Mutant_Wolf" },
			{ 1239832946, "CHAR_Noctem_Crow" },
			{ 1786690263, "CHAR_Ocean_Blowfish" },
			{ 470753758, "CHAR_Ocean_Piranha" },
			{ -1737346940, "CHAR_Paladin_DivineAngel" },
			{ -76116724, "CHAR_Paladin_FallenAngel" },
			{ 1434914085, "CHAR_Pixie" },
			{ -484556888, "CHAR_Poloma_VBlood" },
			{ -1381375644, "CHAR_Poloma_VBlood_GateBoss_Minor" },
			{ 218843465, "CHAR_RatHorror_Mutant_MutantBlood" },
			{ 20817667, "CHAR_RockElemental" },
			{ 577495705, "CHAR_RockElemental_NetherDemon" },
			{ -1750347680, "CHAR_Scarecrow" },
			{ -371347062, "CHAR_SeaSerpent" },
			{ -694393029, "CHAR_SeaSerpent_Hard" },
			{ -764515001, "CHAR_Spider_Baneling" },
			{ 342127250, "CHAR_Spider_Broodmother" },
			{ -581295882, "CHAR_Spider_Forest" },
			{ 574276383, "CHAR_Spider_Forestling" },
			{ 2136899683, "CHAR_Spider_Melee" },
			{ -548489519, "CHAR_Spider_Queen_VBlood" },
			{ -943858353, "CHAR_Spider_Queen_VBlood_GateBoss_Major" },
			{ 2103131615, "CHAR_Spider_Range" },
			{ 1078424589, "CHAR_Spider_Spiderling" },
			{ 1767714956, "CHAR_Spider_Spiderling_VerminNest" },
			{ -779411607, "CHAR_StoneGolem" },
			{ -1089337069, "CHAR_Treant" },
			{ 1496810447, "CHAR_Treant_Corrupted" },
			{ -2037006512, "CHAR_Treant_NetherDemon" },
			{ -753453016, "CHAR_Undead_ArenaChampion_VBlood" },
			{ -861407720, "CHAR_Undead_ArmoredSkeletonCrossbow_Dunley" },
			{ -195077008, "CHAR_Undead_ArmoredSkeletonCrossbow_Farbane" },
			{ -1365627158, "CHAR_Undead_Assassin" },
			{ 577478542, "CHAR_Undead_BishopOfDeath_VBlood" },
			{ -1822337177, "CHAR_Undead_BishopOfDeath_VBlood_GateBoss_Minor" },
			{ 939467639, "CHAR_Undead_BishopOfShadows_VBlood" },
			{ -1805216630, "CHAR_Undead_BishopOfShadows_VBlood_GateBoss_Major" },
			{ 1971653132, "CHAR_Undead_CursedSmith_FloatingWeapon_Axe" },
			{ -1099451233, "CHAR_Undead_CursedSmith_FloatingWeapon_Base" },
			{ -55245645, "CHAR_Undead_CursedSmith_FloatingWeapon_Mace" },
			{ 769910415, "CHAR_Undead_CursedSmith_FloatingWeapon_Slashers" },
			{ 233127264, "CHAR_Undead_CursedSmith_FloatingWeapon_Spear" },
			{ -2020619708, "CHAR_Undead_CursedSmith_FloatingWeapon_Sword" },
			{ 326378955, "CHAR_Undead_CursedSmith_VBlood" },
			{ -236166535, "CHAR_Undead_FlyingSkull" },
			{ 849891426, "CHAR_Undead_GhostAssassin" },
			{ -1146194149, "CHAR_Undead_GhostBanshee" },
			{ -458883491, "CHAR_Undead_GhostGuardian" },
			{ -85729652, "CHAR_Undead_GhostMilitia_Crossbow" },
			{ -1618703048, "CHAR_Undead_GhostMilitia_Light" },
			{ 2105565286, "CHAR_Undead_Ghoul_Armored_Farmlands" },
			{ -1967480038, "CHAR_Undead_Guardian" },
			{ -558928562, "CHAR_Undead_Infiltrator_AfterShadow" },
			{ 613251918, "CHAR_Undead_Infiltrator_VBlood" },
			{ -982850914, "CHAR_Undead_Infiltrator_VBlood_GateBoss_Major" },
			{ -1365931036, "CHAR_Undead_Leader_Vblood" },
			{ -989493184, "CHAR_Undead_Leader_Vblood_GateBoss_Minor" },
			{ -572568236, "CHAR_Undead_Necromancer" },
			{ -1653554504, "CHAR_Undead_Priest" },
			{ 153390636, "CHAR_Undead_Priest_VBlood" },
			{ -1722506709, "CHAR_Undead_RottingGhoul" },
			{ 678628353, "CHAR_Undead_ShadowSoldier" },
			{ -361904832, "CHAR_Undead_ShadowSoldier_GateBoss" },
			{ -1789347076, "CHAR_Undead_SkeletonApprentice" },
			{ 597386568, "CHAR_Undead_SkeletonCrossbow_Base" },
			{ 1250474035, "CHAR_Undead_SkeletonCrossbow_Farbane_OLD" },
			{ 1395549638, "CHAR_Undead_SkeletonCrossbow_Graveyard" },
			{ -1380216646, "CHAR_Undead_SkeletonGolem" },
			{ -1115032717, "CHAR_Undead_SkeletonGolem_NetherDemon" },
			{ -1287507270, "CHAR_Undead_SkeletonMage" },
			{ 952695804, "CHAR_Undead_SkeletonSoldier_Armored_Dunley" },
			{ -837329073, "CHAR_Undead_SkeletonSoldier_Armored_Farbane" },
			{ -603934060, "CHAR_Undead_SkeletonSoldier_Base" },
			{ -1642110920, "CHAR_Undead_SkeletonSoldier_Infiltrator" },
			{ -1584807109, "CHAR_Undead_SkeletonSoldier_Withered" },
			{ 1640311129, "CHAR_Undead_UndyingGhoul" },
			{ 128488545, "CHAR_Undead_ZealousCultist_Ghost" },
			{ -1208888966, "CHAR_Undead_ZealousCultist_VBlood" },
			{ -1189707552, "CHAR_Undead_ZealousCultist_VBlood_GateBoss_Major" },
			{ 1857865401, "CHAR_Unholy_DeathKnight" },
			{ -1928607398, "CHAR_Unholy_FallenAngel" },
			{ 834333879, "CHAR_Unholy_UnstableArachnid" },
			{ -1106602776, "CHAR_Unholy_UnstableArachnid_Small" },
			{ 495971434, "CHAR_Vampire_BloodKnight_VBlood" },
			{ -1884553416, "CHAR_Vampire_CrimsonIronMaiden" },
			{ -1671572471, "CHAR_Vampire_Cultist_BloodCrystal" },
			{ -1208066429, "CHAR_Vampire_Cultist_BloodCrystal_Female" },
			{ 407967118, "CHAR_Vampire_Cultist_Channeling" },
			{ 57255106, "CHAR_Vampire_Cultist_Channeling_Female" },
			{ 2018586909, "CHAR_Vampire_Cultist_Patrolling" },
			{ -1610391169, "CHAR_Vampire_Cultist_Patrolling_Female" },
			{ -1438710930, "CHAR_Vampire_Cultist_PrayingArmsOut" },
			{ -1074322242, "CHAR_Vampire_Cultist_PrayingArmsOut_Female" },
			{ -1832935107, "CHAR_Vampire_Cultist_PrayingGround" },
			{ -2086433846, "CHAR_Vampire_Cultist_PrayingGround_Female" },
			{ -19416663, "CHAR_Vampire_Cultist_Whittling" },
			{ -1925881340, "CHAR_Vampire_Cultist_Whittling_Female" },
			{ -327335305, "CHAR_Vampire_Dracula_VBlood" },
			{ 1809382006, "CHAR_Vampire_Dracula_VeilOfBatsIllusion" },
			{ -496360395, "CHAR_Vampire_HighLord_VBlood" },
			{ 795262842, "CHAR_Vampire_IceRanger_VBlood" },
			{ -1117581429, "CHAR_Vampire_Withered" },
			{ -2039908510, "CHAR_Vermin_DireRat_VBlood" },
			{ -1722278689, "CHAR_Vermin_GiantRat" },
			{ -19165577, "CHAR_Vermin_WickedRat_Rare" },
			{ 336560131, "CHAR_VHunter_CastleMan" },
			{ -1968372384, "CHAR_VHunter_Jade_VBlood" },
			{ 282791819, "CHAR_VHunter_Jade_VBlood_GateBoss_Major" },
			{ 2009018555, "CHAR_VHunter_Leader_GateBoss_Minor" },
			{ -1449631170, "CHAR_VHunter_Leader_VBlood" },
			{ 109969450, "CHAR_Villager_CursedWanderer_VBlood" },
			{ -1160778038, "CHAR_Villager_CursedWanderer_VBlood_GateBoss_Major" },
			{ -1942352521, "CHAR_Villager_Tailor_VBlood" },
			{ 468179469, "CHAR_Wendigo_GateBoss_Major" },
			{ 24378719, "CHAR_Wendigo_VBlood" },
			{ -1505705712, "CHAR_WerewolfChieftain_Human" },
			{ -1699898875, "CHAR_WerewolfChieftain_ShadowClone" },
			{ 2079933370, "CHAR_WerewolfChieftain_VBlood_GateBoss_Major" },
			{ 2041915372, "CHAR_Winter_Bear_Standard" },
			{ -779632831, "CHAR_Winter_Moose" },
			{ 134039094, "CHAR_Winter_Wolf" },
			{ -1347412392, "CHAR_Winter_Yeti_VBlood" },
			{ 666177656, "CHAR_Winter_Yeti_VBlood_GateBoss_Major" }
		};

		public static bool IsAllowed(int guidHash)
		{
			return AllowedPrefabs.ContainsKey(guidHash);
		}

		public static string GetName(int guidHash)
		{
			if (AllowedPrefabs.TryGetValue(guidHash, out var value))
			{
				return value;
			}
			return "Unknown_Prefab";
		}

		public static bool TryGetHash(string input, out int guidHash)
		{
			if (int.TryParse(input, out guidHash))
			{
				return AllowedPrefabs.ContainsKey(guidHash);
			}
			foreach (KeyValuePair<int, string> allowedPrefab in AllowedPrefabs)
			{
				if (string.Equals(allowedPrefab.Value, input, StringComparison.OrdinalIgnoreCase) || string.Equals(allowedPrefab.Value.Substring(5), input, StringComparison.OrdinalIgnoreCase))
				{
					guidHash = allowedPrefab.Key;
					return true;
				}
			}
			guidHash = 0;
			return false;
		}
	}
}
namespace NPCs.Commands
{
	[CommandGroup("npc", null)]
	internal static class NpcCommands
	{
		[Command("addteam", "at", null, "Add a new team or add/update a prefab in an existing team.", null, true)]
		public static void AddTeam(ChatCommandContext ctx, string teamName, string prefab, int amount)
		{
			if (!WhitelistPrefabs.TryGetHash(prefab, out var guidHash))
			{
				ctx.Reply("<color=red>Prefab " + prefab + " is invalid or not allowed!</color>");
				return;
			}
			bool flag = false;
			if (!NpcService.Teams.TryGetValue(teamName, out var value))
			{
				value = new TeamConfig
				{
					RandomAround = 5f
				};
				NpcService.Teams[teamName] = value;
				flag = true;
			}
			TeamConfig teamConfig = value;
			if (teamConfig.Prefabs == null)
			{
				Dictionary<string, int> dictionary2 = (teamConfig.Prefabs = new Dictionary<string, int>());
			}
			value.Prefabs[guidHash.ToString()] = amount;
			NpcService.Save();
			string name = WhitelistPrefabs.GetName(guidHash);
			if (flag)
			{
				ctx.Reply($"<color=green>Created team {teamName}.</color> Added: {name} x{amount}");
			}
			else
			{
				ctx.Reply($"<color=green>Updated team {teamName}.</color> Added/updated: {name} x{amount}");
			}
		}

		[Command("removeteam", "rt", null, "Remove an entire team or a specific prefab from a team.", null, true)]
		public static void RemoveTeam(ChatCommandContext ctx, string teamName, string prefab = "")
		{
			if (NpcService.Teams.TryGetValue(teamName, out var value))
			{
				if (string.IsNullOrEmpty(prefab))
				{
					int num = NpcService.DespawnNpc(12f, teamName);
					NpcService.Teams.Remove(teamName);
					NpcService.Save();
					ctx.Reply($"<color=green>Removed team {teamName}.</color> Despawned {num} {((num == 1) ? "NPC" : "NPCs")}.");
					return;
				}
				if (!WhitelistPrefabs.TryGetHash(prefab, out var guidHash))
				{
					ctx.Reply("<color=red>Prefab " + prefab + " is invalid or not allowed!</color>");
					return;
				}
				string text = guidHash.ToString();
				string name = WhitelistPrefabs.GetName(guidHash);
				if (value.Prefabs != null && value.Prefabs.ContainsKey(text))
				{
					int num2 = NpcService.DespawnNpc(12f, teamName, text);
					value.Prefabs.Remove(text);
					NpcService.Save();
					ctx.Reply($"<color=green>Removed: {name} from team {teamName}.</color> Despawned {num2} {((num2 == 1) ? "NPC" : "NPCs")}.");
				}
				else
				{
					ctx.Reply($"<color=red>{name} not found in team {teamName}!</color>");
				}
			}
			else
			{
				ctx.Reply("<color=red>Team " + teamName + " not found in the configuration!</color>");
			}
		}

		[Command("addpoint", "ap", null, "Add a spawn point for a specific team.", null, true)]
		public static void AddSpawnPoint(ChatCommandContext ctx, string teamName)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			if (!NpcService.Teams.TryGetValue(teamName, out var value))
			{
				ctx.Reply("<color=red>Team " + teamName + " not found in the configuration!</color>");
				return;
			}
			float3 value2 = ctx.Event.SenderCharacterEntity.Read<Translation>().Value;
			TeamConfig teamConfig = value;
			if (teamConfig.SpawnPoints == null)
			{
				List<SimpleVec3> list2 = (teamConfig.SpawnPoints = new List<SimpleVec3>());
			}
			value.SpawnPoints.Add(new SimpleVec3(value2));
			NpcService.Save();
			ctx.Reply("<color=green>Added spawn point for " + teamName + ".</color>");
		}

		[Command("removepoint", "rp", null, "Remove all spawn points for a specific team.", null, true)]
		public static void RemoveSpawnPoint(ChatCommandContext ctx, string teamName)
		{
			if (!NpcService.Teams.TryGetValue(teamName, out var value))
			{
				ctx.Reply("<color=red>Team " + teamName + " not found in the configuration!</color>");
				return;
			}
			if (value.SpawnPoints == null || value.SpawnPoints.Count == 0)
			{
				ctx.Reply("<color=yellow>Team " + teamName + " has no spawn points to remove!</color>");
				return;
			}
			int num = NpcService.DespawnNpc(12f, teamName);
			int count = value.SpawnPoints.Count;
			value.SpawnPoints.Clear();
			NpcService.Save();
			ctx.Reply($"<color=green>Removed {count} spawn points for {teamName}.</color> Despawned {num} {((num == 1) ? "NPC" : "NPCs")}.");
		}

		[Command("manualspawn", "ms", null, "Manually spawn all NPCs.", null, true)]
		public static void Spawn(ChatCommandContext ctx)
		{
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.ModEnabled.Value)
			{
				ctx.Reply("<color=red>Mod: disabled!</color>");
				return;
			}
			if (NpcService.Teams == null || NpcService.Teams.Count == 0)
			{
				ctx.Reply("<color=red>No teams found!</color> Use <color=green>.npc addteam <teamName> <prefab> <amount></color>");
				return;
			}
			if (NpcService.Teams.Values.All((TeamConfig t) => t.SpawnPoints == null || t.SpawnPoints.Count == 0))
			{
				ctx.Reply("<color=red>No spawn points found!</color> Use <color=green>.npc addpoint <teamName></color>");
				return;
			}
			Entity senderCharacterEntity = ctx.Event.SenderCharacterEntity;
			NpcService.SpawnNpc(senderCharacterEntity);
			Core.Log.LogInfo((object)"[NPCs] Manual spawn initiated by admin.");
			ctx.Reply("<color=green>NPCs manually spawned successfully.</color>");
		}

		[Command("manualdespawn", "md", null, "Manually despawn all NPCs.", null, true)]
		public static void Despawn(ChatCommandContext ctx)
		{
			NpcService.DespawnNpc();
			Core.Log.LogInfo((object)"[NPCs] Manual despawn initiated by admin.");
			ctx.Reply("<color=green>NPCs manually despawned successfully.</color>");
		}

		[Command("config", "c", null, "Display the general mod configuration.", null, true)]
		public static void Config(ChatCommandContext ctx)
		{
			StringBuilder stringBuilder = new StringBuilder();
			string value = (Plugin.ModEnabled.Value ? "enabled" : "disabled");
			string value2 = (Plugin.BroadcastEnable.Value ? "enabled" : "disabled");
			string value3 = Regex.Replace(Plugin.BroadcastMessage.Value, "<.*?>", string.Empty);
			TimeSpan timeSpan = NpcService.NextSpawnLocal - DateTime.Now;
			if (timeSpan.TotalSeconds < 0.0)
			{
				timeSpan = TimeSpan.Zero;
			}
			string value4 = NpcService.NextSpawnLocal.ToString("HH:mm:ss");
			string value5 = $"{timeSpan.Minutes}m {timeSpan.Seconds}s";
			string value6 = $"XX:{Plugin.HourlySpawnAtMinute.Value:D2}:{Plugin.HourlySpawnAtSecond.Value:D2}";
			stringBuilder.AppendLine("<color=yellow>NPCs Configuration</color>");
			StringBuilder stringBuilder2 = stringBuilder;
			StringBuilder stringBuilder3 = stringBuilder2;
			StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(5, 1, stringBuilder2);
			handler.AppendLiteral("Mod: ");
			handler.AppendFormatted(value);
			stringBuilder3.AppendLine(ref handler);
			stringBuilder2 = stringBuilder;
			StringBuilder stringBuilder4 = stringBuilder2;
			handler = new StringBuilder.AppendInterpolatedStringHandler(11, 1, stringBuilder2);
			handler.AppendLiteral("Broadcast: ");
			handler.AppendFormatted(value2);
			stringBuilder4.AppendLine(ref handler);
			stringBuilder2 = stringBuilder;
			StringBuilder stringBuilder5 = stringBuilder2;
			handler = new StringBuilder.AppendInterpolatedStringHandler(9, 1, stringBuilder2);
			handler.AppendLiteral("Message: ");
			handler.AppendFormatted(value3);
			stringBuilder5.AppendLine(ref handler);
			stringBuilder2 = stringBuilder;
			StringBuilder stringBuilder6 = stringBuilder2;
			handler = new StringBuilder.AppendInterpolatedStringHandler(36, 3, stringBuilder2);
			handler.AppendLiteral("Spawn schedule: ");
			handler.AppendFormatted(value6);
			handler.AppendLiteral(", Next spawn: ");
			handler.AppendFormatted(value4);
			handler.AppendLiteral(" (in ");
			handler.AppendFormatted(value5);
			handler.AppendLiteral(")");
			stringBuilder6.AppendLine(ref handler);
			stringBuilder2 = stringBuilder;
			StringBuilder stringBuilder7 = stringBuilder2;
			handler = new StringBuilder.AppendInterpolatedStringHandler(11, 1, stringBuilder2);
			handler.AppendLiteral("Lifetime: ");
			handler.AppendFormatted(Plugin.LifetimeSeconds.Value);
			handler.AppendLiteral("s");
			stringBuilder7.AppendLine(ref handler);
			ctx.Reply(stringBuilder.ToString().TrimEnd());
		}

		[Command("team", "t", null, "List all NPC teams and their detailed settings.", null, true)]
		public static void List(ChatCommandContext ctx, string teamName = "")
		{
			Dictionary<string, TeamConfig> teams = NpcService.Teams;
			if (teams == null || teams.Count == 0)
			{
				ctx.Reply("<color=yellow>NPC teams</color>\nNo teams configured. Use <color=green>.npc addteam <teamName> <prefab> <amount></color>");
				return;
			}
			StringBuilder stringBuilder = new StringBuilder();
			if (!string.IsNullOrEmpty(teamName) && teams.TryGetValue(teamName, out var value))
			{
				int value2 = value.SpawnPoints?.Count ?? 0;
				float randomAround = value.RandomAround;
				StringBuilder stringBuilder2 = stringBuilder;
				StringBuilder stringBuilder3 = stringBuilder2;
				StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(27, 3, stringBuilder2);
				handler.AppendLiteral("[");
				handler.AppendFormatted(teamName);
				handler.AppendLiteral("] radius: ");
				handler.AppendFormatted(randomAround);
				handler.AppendLiteral(", spawn points: ");
				handler.AppendFormatted(value2);
				stringBuilder3.AppendLine(ref handler);
				if (value.Prefabs != null && value.Prefabs.Count > 0)
				{
					foreach (KeyValuePair<string, int> prefab in value.Prefabs)
					{
						string key = prefab.Key;
						int value3 = prefab.Value;
						string value4 = key;
						if (int.TryParse(key, out var result))
						{
							value4 = WhitelistPrefabs.GetName(result);
						}
						stringBuilder2 = stringBuilder;
						StringBuilder stringBuilder4 = stringBuilder2;
						handler = new StringBuilder.AppendInterpolatedStringHandler(2, 2, stringBuilder2);
						handler.AppendFormatted(value4);
						handler.AppendLiteral(" x");
						handler.AppendFormatted(value3);
						stringBuilder4.AppendLine(ref handler);
					}
				}
			}
			else
			{
				stringBuilder.AppendLine("<color=yellow>NPC teams</color>");
				foreach (KeyValuePair<string, TeamConfig> item in teams)
				{
					string key2 = item.Key;
					TeamConfig value5 = item.Value;
					int value6 = value5.SpawnPoints?.Count ?? 0;
					float randomAround2 = value5.RandomAround;
					StringBuilder stringBuilder2 = stringBuilder;
					StringBuilder stringBuilder5 = stringBuilder2;
					StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(27, 3, stringBuilder2);
					handler.AppendLiteral("[");
					handler.AppendFormatted(key2);
					handler.AppendLiteral("] radius: ");
					handler.AppendFormatted(randomAround2);
					handler.AppendLiteral(", spawn points: ");
					handler.AppendFormatted(value6);
					stringBuilder5.AppendLine(ref handler);
				}
			}
			ctx.Reply(stringBuilder.ToString().TrimEnd());
		}

		[Command("reload", "rl", null, "Reload npc_teams.json and NPCs.cfg", null, true)]
		public static void Reload(ChatCommandContext ctx)
		{
			NpcService.Reload();
			ctx.Reply("<color=green>Configs reloaded.</color>");
		}
	}
}