Decompiled source of SpawnBox v1.3.0

SpawnBox.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HG;
using Microsoft.CodeAnalysis;
using On.RoR2;
using RoR2;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SpawnBox")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3.0+b550a5dd85d4a39a14c0655723f733fc8bad98e0")]
[assembly: AssemblyProduct("SpawnBox")]
[assembly: AssemblyTitle("SpawnBox")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 SpawnBox
{
	internal static class AllySpawnerTab
	{
		private class Row
		{
			public GameObject MasterPrefab;

			public string DisplayName;

			public Texture Icon;

			public string Key;

			public bool IsFavorite;
		}

		private const int IconSize = 24;

		private static readonly List<Row> allRows = new List<Row>();

		private static string search = "";

		private static string quantityText = "1";

		private static Vector2 scroll;

		private static readonly List<GameObject> spawnedObjects = new List<GameObject>();

		private static ConfigEntry<string> favoritesEntry;

		private static readonly HashSet<string> favorites = new HashSet<string>();

		private const string ExcludedMasterName = "HaulerDroneMaster";

		private static void LoadFavorites()
		{
			favoritesEntry = SpawnBoxPlugin.PluginConfig.Bind<string>("Favorites", "Allies", "", "Comma-separated list of favorited ally master names.");
			favorites.Clear();
			string[] array = favoritesEntry.Value.Split(',');
			foreach (string text in array)
			{
				if (!string.IsNullOrEmpty(text))
				{
					favorites.Add(text);
				}
			}
		}

		private static void SaveFavorites()
		{
			favoritesEntry.Value = string.Join(",", favorites);
		}

		private static void SortRows()
		{
			allRows.Sort((Row a, Row b) => (a.IsFavorite != b.IsFavorite) ? ((!a.IsFavorite) ? 1 : (-1)) : string.Compare(a.DisplayName, b.DisplayName));
		}

		public static void BuildList()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Invalid comparison between Unknown and I4
			LoadFavorites();
			allRows.Clear();
			foreach (CharacterMaster allAiMaster in MasterCatalog.allAiMasters)
			{
				if (!((Object)(object)allAiMaster == (Object)null) && !((Object)(object)allAiMaster.bodyPrefab == (Object)null) && (int)allAiMaster.teamIndex == 1 && !(((Object)((Component)allAiMaster).gameObject).name == "HaulerDroneMaster"))
				{
					CharacterBody component = allAiMaster.bodyPrefab.GetComponent<CharacterBody>();
					if (!((Object)(object)component == (Object)null) && !string.IsNullOrEmpty(component.baseNameToken))
					{
						string name = ((Object)((Component)allAiMaster).gameObject).name;
						allRows.Add(new Row
						{
							MasterPrefab = ((Component)allAiMaster).gameObject,
							DisplayName = Language.GetString(component.baseNameToken),
							Icon = component.portraitIcon,
							Key = name,
							IsFavorite = favorites.Contains(name)
						});
					}
				}
			}
			SortRows();
			SpawnBoxPlugin.Log.LogInfo((object)$"SpawnBox: {allRows.Count} allies available.");
		}

		public static void Draw()
		{
			//IL_0090: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Search:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) });
			search = GUILayout.TextField(search, Array.Empty<GUILayoutOption>());
			GUILayout.Label("Qty:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(30f) });
			quantityText = GUILayout.TextField(quantityText, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(40f) });
			GUILayout.EndHorizontal();
			GUILayout.Label("High values may impact performance.", Array.Empty<GUILayoutOption>());
			bool flag = false;
			scroll = GUILayout.BeginScrollView(scroll, Array.Empty<GUILayoutOption>());
			foreach (Row allRow in allRows)
			{
				if (!string.IsNullOrEmpty(search) && allRow.DisplayName.IndexOf(search, StringComparison.OrdinalIgnoreCase) < 0)
				{
					continue;
				}
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (GUILayout.Button(allRow.IsFavorite ? "Unpin" : "Pin", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(45f) }))
				{
					allRow.IsFavorite = !allRow.IsFavorite;
					if (allRow.IsFavorite)
					{
						favorites.Add(allRow.Key);
					}
					else
					{
						favorites.Remove(allRow.Key);
					}
					SaveFavorites();
					flag = true;
				}
				if ((Object)(object)allRow.Icon != (Object)null)
				{
					GUILayout.Label(allRow.Icon, (GUILayoutOption[])(object)new GUILayoutOption[2]
					{
						GUILayout.Width(24f),
						GUILayout.Height(24f)
					});
				}
				else
				{
					GUILayout.Space(24f);
				}
				GUILayout.Label(allRow.DisplayName, Array.Empty<GUILayoutOption>());
				if (GUILayout.Button("Spawn", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) }))
				{
					SpawnMany(allRow.MasterPrefab, ParseQuantity());
				}
				GUILayout.EndHorizontal();
			}
			GUILayout.EndScrollView();
			if (flag)
			{
				SortRows();
			}
		}

		private static int ParseQuantity()
		{
			if (!int.TryParse(quantityText, out var result) || result <= 0)
			{
				return 1;
			}
			return result;
		}

		private static void SpawnMany(GameObject masterPrefab, int count)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_00a0: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active)
			{
				return;
			}
			LocalUser firstLocalUser = LocalUserManager.GetFirstLocalUser();
			CharacterBody val = ((firstLocalUser != null) ? firstLocalUser.cachedBody : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			for (int i = 0; i < count; i++)
			{
				float num = 360f / (float)count * (float)i;
				Vector3 val2 = Quaternion.Euler(0f, num, 0f) * (val.transform.forward * 5f);
				Vector3 position = val.transform.position + val2;
				CharacterMaster val3 = new MasterSummon
				{
					masterPrefab = masterPrefab,
					position = position,
					rotation = Quaternion.identity,
					teamIndexOverride = (TeamIndex)1,
					useAmbientLevel = true
				}.Perform();
				if ((Object)(object)val3 != (Object)null)
				{
					((Component)val3).gameObject.AddComponent<SetDontDestroyOnLoad>();
					spawnedObjects.Add(((Component)val3).gameObject);
				}
			}
		}

		internal static int SpawnedCount()
		{
			int num = 0;
			foreach (GameObject spawnedObject in spawnedObjects)
			{
				if ((Object)(object)spawnedObject != (Object)null)
				{
					num++;
				}
			}
			return num;
		}

		internal static void DespawnAll()
		{
			foreach (GameObject spawnedObject in spawnedObjects)
			{
				if ((Object)(object)spawnedObject != (Object)null)
				{
					NetworkServer.Destroy(spawnedObject);
				}
			}
			spawnedObjects.Clear();
		}
	}
	internal static class EnemySpawnerTab
	{
		private class Row
		{
			public GameObject MasterPrefab;

			public string DisplayName;

			public Texture Icon;

			public string Key;

			public bool IsFavorite;
		}

		private const int IconSize = 24;

		private static readonly List<Row> allRows = new List<Row>();

		private static string search = "";

		private static string quantityText = "1";

		private static Vector2 scroll;

		private static readonly List<GameObject> spawnedObjects = new List<GameObject>();

		private static ConfigEntry<string> favoritesEntry;

		private static readonly HashSet<string> favorites = new HashSet<string>();

		internal static readonly List<EliteDef> eliteOptions = new List<EliteDef>();

		internal static string[] eliteLabels = new string[1] { "None" };

		private static int selectedEliteIndex = 0;

		private static bool spawnAsAlly = false;

		public static void BuildEliteList()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Invalid comparison between Unknown and I4
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected I4, but got Unknown
			eliteOptions.Clear();
			List<string> list = new List<string> { "None" };
			EliteDef[] eliteDefs = EliteCatalog.eliteDefs;
			foreach (EliteDef val in eliteDefs)
			{
				if (!((Object)(object)val == (Object)null) && (int)val.eliteIndex != -1)
				{
					eliteOptions.Add(val);
					list.Add((!string.IsNullOrEmpty(val.modifierToken)) ? Language.GetString(val.modifierToken) : $"Elite {(int)val.eliteIndex}");
				}
			}
			eliteLabels = list.ToArray();
			if (selectedEliteIndex >= eliteLabels.Length)
			{
				selectedEliteIndex = 0;
			}
			SpawnBoxPlugin.Log.LogInfo((object)$"SpawnBox: {eliteOptions.Count} elite affixes available.");
		}

		private static void LoadFavorites()
		{
			favoritesEntry = SpawnBoxPlugin.PluginConfig.Bind<string>("Favorites", "Enemies", "", "Comma-separated list of favorited enemy master names.");
			favorites.Clear();
			string[] array = favoritesEntry.Value.Split(',');
			foreach (string text in array)
			{
				if (!string.IsNullOrEmpty(text))
				{
					favorites.Add(text);
				}
			}
		}

		private static void SaveFavorites()
		{
			favoritesEntry.Value = string.Join(",", favorites);
		}

		private static void SortRows()
		{
			allRows.Sort((Row a, Row b) => (a.IsFavorite != b.IsFavorite) ? ((!a.IsFavorite) ? 1 : (-1)) : string.Compare(a.DisplayName, b.DisplayName));
		}

		public static void BuildList()
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Invalid comparison between Unknown and I4
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Invalid comparison between Unknown and I4
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			LoadFavorites();
			allRows.Clear();
			HashSet<BodyIndex> hashSet = new HashSet<BodyIndex>();
			foreach (SurvivorDef allSurvivorDef in SurvivorCatalog.allSurvivorDefs)
			{
				if (!((Object)(object)allSurvivorDef == (Object)null) && !((Object)(object)allSurvivorDef.bodyPrefab == (Object)null))
				{
					CharacterBody component = allSurvivorDef.bodyPrefab.GetComponent<CharacterBody>();
					if ((Object)(object)component != (Object)null)
					{
						hashSet.Add(component.bodyIndex);
					}
				}
			}
			foreach (CharacterMaster allAiMaster in MasterCatalog.allAiMasters)
			{
				if (!((Object)(object)allAiMaster == (Object)null) && !((Object)(object)allAiMaster.bodyPrefab == (Object)null) && ((int)allAiMaster.teamIndex == 2 || (int)allAiMaster.teamIndex == 4))
				{
					CharacterBody component2 = allAiMaster.bodyPrefab.GetComponent<CharacterBody>();
					if (!((Object)(object)component2 == (Object)null) && !string.IsNullOrEmpty(component2.baseNameToken) && !hashSet.Contains(component2.bodyIndex))
					{
						string name = ((Object)((Component)allAiMaster).gameObject).name;
						allRows.Add(new Row
						{
							MasterPrefab = ((Component)allAiMaster).gameObject,
							DisplayName = Language.GetString(component2.baseNameToken),
							Icon = component2.portraitIcon,
							Key = name,
							IsFavorite = favorites.Contains(name)
						});
					}
				}
			}
			SortRows();
			SpawnBoxPlugin.Log.LogInfo((object)$"SpawnBox: {allRows.Count} enemies available.");
		}

		public static void Draw()
		{
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Search:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) });
			search = GUILayout.TextField(search, Array.Empty<GUILayoutOption>());
			GUILayout.Label("Qty:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(30f) });
			quantityText = GUILayout.TextField(quantityText, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(40f) });
			GUILayout.EndHorizontal();
			GUILayout.Label("High values may impact performance.", Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Elite:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) });
			if (GUILayout.Button("<", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(24f) }))
			{
				selectedEliteIndex = (selectedEliteIndex - 1 + eliteLabels.Length) % eliteLabels.Length;
			}
			GUILayout.Label(eliteLabels[selectedEliteIndex], (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(140f) });
			if (GUILayout.Button(">", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(24f) }))
			{
				selectedEliteIndex = (selectedEliteIndex + 1) % eliteLabels.Length;
			}
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Team:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) });
			if (GUILayout.Toggle(!spawnAsAlly, "Bad (enemy)", GUIStyle.op_Implicit("button"), Array.Empty<GUILayoutOption>()))
			{
				spawnAsAlly = false;
			}
			if (GUILayout.Toggle(spawnAsAlly, "Good (ally)", GUIStyle.op_Implicit("button"), Array.Empty<GUILayoutOption>()))
			{
				spawnAsAlly = true;
			}
			GUILayout.EndHorizontal();
			if (spawnAsAlly)
			{
				GUILayout.Label("Spawning on your team - some enemies may not behave safely off-script (report any that misbehave).", Array.Empty<GUILayoutOption>());
			}
			bool flag = false;
			scroll = GUILayout.BeginScrollView(scroll, Array.Empty<GUILayoutOption>());
			foreach (Row allRow in allRows)
			{
				if (!string.IsNullOrEmpty(search) && allRow.DisplayName.IndexOf(search, StringComparison.OrdinalIgnoreCase) < 0)
				{
					continue;
				}
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (GUILayout.Button(allRow.IsFavorite ? "Unpin" : "Pin", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(45f) }))
				{
					allRow.IsFavorite = !allRow.IsFavorite;
					if (allRow.IsFavorite)
					{
						favorites.Add(allRow.Key);
					}
					else
					{
						favorites.Remove(allRow.Key);
					}
					SaveFavorites();
					flag = true;
				}
				if ((Object)(object)allRow.Icon != (Object)null)
				{
					GUILayout.Label(allRow.Icon, (GUILayoutOption[])(object)new GUILayoutOption[2]
					{
						GUILayout.Width(24f),
						GUILayout.Height(24f)
					});
				}
				else
				{
					GUILayout.Space(24f);
				}
				GUILayout.Label(allRow.DisplayName, Array.Empty<GUILayoutOption>());
				if (GUILayout.Button("Spawn", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) }))
				{
					SpawnMany(allRow.MasterPrefab, ParseQuantity());
				}
				GUILayout.EndHorizontal();
			}
			GUILayout.EndScrollView();
			if (flag)
			{
				SortRows();
			}
		}

		private static int ParseQuantity()
		{
			if (!int.TryParse(quantityText, out var result) || result <= 0)
			{
				return 1;
			}
			return result;
		}

		private static void SpawnMany(GameObject masterPrefab, int count)
		{
			//IL_0072: 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_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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active)
			{
				return;
			}
			LocalUser firstLocalUser = LocalUserManager.GetFirstLocalUser();
			CharacterBody val = ((firstLocalUser != null) ? firstLocalUser.cachedBody : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			EliteDef val2 = ((selectedEliteIndex > 0 && selectedEliteIndex - 1 < eliteOptions.Count) ? eliteOptions[selectedEliteIndex - 1] : null);
			for (int i = 0; i < count; i++)
			{
				float num = 360f / (float)count * (float)i;
				Vector3 val3 = Quaternion.Euler(0f, num, 0f) * (val.transform.forward * 5f);
				Vector3 position = val.transform.position + val3;
				CharacterMaster val4 = new MasterSummon
				{
					masterPrefab = masterPrefab,
					position = position,
					rotation = Quaternion.identity,
					teamIndexOverride = (TeamIndex)(spawnAsAlly ? 1 : 2),
					useAmbientLevel = true
				}.Perform();
				if (Object.op_Implicit((Object)(object)val4) && (Object)(object)val2 != (Object)null && Object.op_Implicit((Object)(object)val4.inventory) && Object.op_Implicit((Object)(object)val2.eliteEquipmentDef))
				{
					val4.inventory.SetEquipmentIndex(val2.eliteEquipmentDef.equipmentIndex, false);
				}
				if (Object.op_Implicit((Object)(object)val4))
				{
					if (spawnAsAlly)
					{
						((Component)val4).gameObject.AddComponent<SetDontDestroyOnLoad>();
					}
					spawnedObjects.Add(((Component)val4).gameObject);
				}
			}
		}

		internal static int SpawnedCount()
		{
			int num = 0;
			foreach (GameObject spawnedObject in spawnedObjects)
			{
				if ((Object)(object)spawnedObject != (Object)null)
				{
					num++;
				}
			}
			return num;
		}

		internal static void DespawnAll()
		{
			foreach (GameObject spawnedObject in spawnedObjects)
			{
				if ((Object)(object)spawnedObject != (Object)null)
				{
					NetworkServer.Destroy(spawnedObject);
				}
			}
			spawnedObjects.Clear();
		}
	}
	internal static class EquipmentSpawnerTab
	{
		private class Row
		{
			public EquipmentIndex Index;

			public string DisplayName;

			public Texture Icon;

			public string Key;

			public bool IsFavorite;
		}

		private const int IconSize = 24;

		private static readonly List<Row> allRows = new List<Row>();

		private static string search = "";

		private static Vector2 scroll;

		private static ConfigEntry<string> favoritesEntry;

		private static readonly HashSet<string> favorites = new HashSet<string>();

		private static void LoadFavorites()
		{
			favoritesEntry = SpawnBoxPlugin.PluginConfig.Bind<string>("Favorites", "Equipment", "", "Comma-separated list of favorited equipment names.");
			favorites.Clear();
			string[] array = favoritesEntry.Value.Split(',');
			foreach (string text in array)
			{
				if (!string.IsNullOrEmpty(text))
				{
					favorites.Add(text);
				}
			}
		}

		private static void SaveFavorites()
		{
			favoritesEntry.Value = string.Join(",", favorites);
		}

		private static void SortRows()
		{
			allRows.Sort((Row a, Row b) => (a.IsFavorite != b.IsFavorite) ? ((!a.IsFavorite) ? 1 : (-1)) : string.Compare(a.DisplayName, b.DisplayName));
		}

		public unsafe static void BuildList()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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)
			LoadFavorites();
			allRows.Clear();
			AllEquipmentEnumerator enumerator = EquipmentCatalog.allEquipment.GetEnumerator();
			try
			{
				while (((AllEquipmentEnumerator)(ref enumerator)).MoveNext())
				{
					EquipmentIndex current = ((AllEquipmentEnumerator)(ref enumerator)).Current;
					EquipmentDef equipmentDef = EquipmentCatalog.GetEquipmentDef(current);
					if (!((Object)(object)equipmentDef == (Object)null) && equipmentDef.canDrop)
					{
						string text = ((object)(*(EquipmentIndex*)(&current))/*cast due to .constrained prefix*/).ToString();
						allRows.Add(new Row
						{
							Index = current,
							DisplayName = Language.GetString(equipmentDef.nameToken),
							Icon = equipmentDef.pickupIconTexture,
							Key = text,
							IsFavorite = favorites.Contains(text)
						});
					}
				}
			}
			finally
			{
				((IDisposable)(*(AllEquipmentEnumerator*)(&enumerator))/*cast due to .constrained prefix*/).Dispose();
			}
			SortRows();
			SpawnBoxPlugin.Log.LogInfo((object)$"SpawnBox: {allRows.Count} equipment available.");
		}

		public static void Draw()
		{
			//IL_0042: 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_0180: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Search:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) });
			search = GUILayout.TextField(search, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			bool flag = false;
			scroll = GUILayout.BeginScrollView(scroll, Array.Empty<GUILayoutOption>());
			foreach (Row allRow in allRows)
			{
				if (!string.IsNullOrEmpty(search) && allRow.DisplayName.IndexOf(search, StringComparison.OrdinalIgnoreCase) < 0)
				{
					continue;
				}
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (GUILayout.Button(allRow.IsFavorite ? "Unpin" : "Pin", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(45f) }))
				{
					allRow.IsFavorite = !allRow.IsFavorite;
					if (allRow.IsFavorite)
					{
						favorites.Add(allRow.Key);
					}
					else
					{
						favorites.Remove(allRow.Key);
					}
					SaveFavorites();
					flag = true;
				}
				if ((Object)(object)allRow.Icon != (Object)null)
				{
					GUILayout.Label(allRow.Icon, (GUILayoutOption[])(object)new GUILayoutOption[2]
					{
						GUILayout.Width(24f),
						GUILayout.Height(24f)
					});
				}
				else
				{
					GUILayout.Space(24f);
				}
				GUILayout.Label(allRow.DisplayName, Array.Empty<GUILayoutOption>());
				if (GUILayout.Button("Give", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) }))
				{
					GiveEquipment(allRow.Index);
				}
				GUILayout.EndHorizontal();
			}
			GUILayout.EndScrollView();
			if (flag)
			{
				SortRows();
			}
		}

		private static void GiveEquipment(EquipmentIndex index)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkServer.active)
			{
				LocalUser firstLocalUser = LocalUserManager.GetFirstLocalUser();
				CharacterBody val = ((firstLocalUser != null) ? firstLocalUser.cachedBody : null);
				Inventory val2 = (((Object)(object)val != (Object)null) ? val.inventory : null);
				if (!((Object)(object)val2 == (Object)null))
				{
					val2.SetEquipmentIndex(index, false);
				}
			}
		}
	}
	internal static class InteractableSpawnerTab
	{
		private class Row
		{
			public string Path;

			public string DisplayName;

			public Texture Icon;

			public bool IsFavorite;
		}

		private const string PathPrefix = "SpawnCards/InteractableSpawnCard/";

		private const int IconSize = 24;

		private static readonly List<Row> allRows = new List<Row>();

		private static readonly Random rng = new Random();

		private static string search = "";

		private static Vector2 scroll;

		private static ConfigEntry<string> favoritesEntry;

		private static readonly HashSet<string> favorites = new HashSet<string>();

		private static readonly List<GameObject> spawnedObjects = new List<GameObject>();

		private static void LoadFavorites()
		{
			favoritesEntry = SpawnBoxPlugin.PluginConfig.Bind<string>("Favorites", "Interactables", "", "Comma-separated list of favorited interactable paths.");
			favorites.Clear();
			string[] array = favoritesEntry.Value.Split(',');
			foreach (string text in array)
			{
				if (!string.IsNullOrEmpty(text))
				{
					favorites.Add(text);
				}
			}
		}

		private static void SaveFavorites()
		{
			favoritesEntry.Value = string.Join(",", favorites);
		}

		private static void SortRows()
		{
			allRows.Sort((Row a, Row b) => (a.IsFavorite != b.IsFavorite) ? ((!a.IsFavorite) ? 1 : (-1)) : string.Compare(a.DisplayName, b.DisplayName));
		}

		public static void BuildList()
		{
			LoadFavorites();
			allRows.Clear();
			List<string> list = new List<string>();
			LegacyResourcesAPI.GetAllPaths(list);
			foreach (string item in list)
			{
				if (string.IsNullOrEmpty(item) || !item.StartsWith("SpawnCards/InteractableSpawnCard/"))
				{
					continue;
				}
				Texture icon = null;
				InteractableSpawnCard val = LegacyResourcesAPI.Load<InteractableSpawnCard>(item);
				if ((Object)(object)val != (Object)null && (Object)(object)((SpawnCard)val).prefab != (Object)null)
				{
					PingInfoProvider component = ((SpawnCard)val).prefab.GetComponent<PingInfoProvider>();
					if ((Object)(object)component != (Object)null && (Object)(object)component.pingIconOverride != (Object)null)
					{
						icon = (Texture)(object)component.pingIconOverride.texture;
					}
				}
				allRows.Add(new Row
				{
					Path = item,
					DisplayName = item.Substring("SpawnCards/InteractableSpawnCard/".Length),
					Icon = icon,
					IsFavorite = favorites.Contains(item)
				});
			}
			SortRows();
			SpawnBoxPlugin.Log.LogInfo((object)$"SpawnBox: {allRows.Count} interactables available.");
		}

		public static void Draw()
		{
			//IL_0042: 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)
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Search:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) });
			search = GUILayout.TextField(search, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			bool flag = false;
			scroll = GUILayout.BeginScrollView(scroll, Array.Empty<GUILayoutOption>());
			foreach (Row allRow in allRows)
			{
				if (!string.IsNullOrEmpty(search) && allRow.DisplayName.IndexOf(search, StringComparison.OrdinalIgnoreCase) < 0)
				{
					continue;
				}
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (GUILayout.Button(allRow.IsFavorite ? "Unpin" : "Pin", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(45f) }))
				{
					allRow.IsFavorite = !allRow.IsFavorite;
					if (allRow.IsFavorite)
					{
						favorites.Add(allRow.Path);
					}
					else
					{
						favorites.Remove(allRow.Path);
					}
					SaveFavorites();
					flag = true;
				}
				if ((Object)(object)allRow.Icon != (Object)null)
				{
					GUILayout.Label(allRow.Icon, (GUILayoutOption[])(object)new GUILayoutOption[2]
					{
						GUILayout.Width(24f),
						GUILayout.Height(24f)
					});
				}
				else
				{
					GUILayout.Space(24f);
				}
				GUILayout.Label(allRow.DisplayName, Array.Empty<GUILayoutOption>());
				if (GUILayout.Button("Spawn", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) }))
				{
					SpawnAt(allRow.Path);
				}
				GUILayout.EndHorizontal();
			}
			GUILayout.EndScrollView();
			if (flag)
			{
				SortRows();
			}
		}

		private static void SpawnAt(string path)
		{
			//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_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_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_0066: 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_007d: Expected O, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			if (!NetworkServer.active)
			{
				return;
			}
			InteractableSpawnCard val = LegacyResourcesAPI.Load<InteractableSpawnCard>(path);
			if (!Object.op_Implicit((Object)(object)val))
			{
				SpawnBoxPlugin.Log.LogWarning((object)("SpawnBox: could not load interactable spawn card at " + path + "."));
				return;
			}
			LocalUser firstLocalUser = LocalUserManager.GetFirstLocalUser();
			CharacterBody val2 = ((firstLocalUser != null) ? firstLocalUser.cachedBody : null);
			if (!((Object)(object)val2 == (Object)null))
			{
				DirectorPlacementRule val3 = new DirectorPlacementRule
				{
					placementMode = (PlacementMode)1,
					position = val2.corePosition,
					minDistance = 5f,
					maxDistance = 20f
				};
				DirectorSpawnRequest val4 = new DirectorSpawnRequest((SpawnCard)(object)val, val3, new Xoroshiro128Plus((ulong)rng.Next()));
				GameObject val5 = (Object.op_Implicit((Object)(object)DirectorCore.instance) ? DirectorCore.instance.TrySpawnObject(val4) : null);
				if (Object.op_Implicit((Object)(object)val5))
				{
					spawnedObjects.Add(val5);
				}
				else
				{
					SpawnBoxPlugin.Log.LogWarning((object)("SpawnBox: DirectorCore failed to spawn interactable at " + path + "."));
				}
			}
		}

		internal static int SpawnedCount()
		{
			int num = 0;
			foreach (GameObject spawnedObject in spawnedObjects)
			{
				if ((Object)(object)spawnedObject != (Object)null)
				{
					num++;
				}
			}
			return num;
		}

		internal static void DespawnAll()
		{
			foreach (GameObject spawnedObject in spawnedObjects)
			{
				if ((Object)(object)spawnedObject != (Object)null)
				{
					NetworkServer.Destroy(spawnedObject);
				}
			}
			spawnedObjects.Clear();
		}
	}
	internal static class ItemSpawnerTab
	{
		private class Row
		{
			public ItemIndex Index;

			public string DisplayName;

			public Texture Icon;

			public string Key;

			public bool IsFavorite;
		}

		private const int IconSize = 24;

		private static readonly List<Row> allRows = new List<Row>();

		private static string search = "";

		private static string quantityText = "1";

		private static string goldText = "500";

		private static Vector2 scroll;

		private static ConfigEntry<string> favoritesEntry;

		private static readonly HashSet<string> favorites = new HashSet<string>();

		private static void LoadFavorites()
		{
			favoritesEntry = SpawnBoxPlugin.PluginConfig.Bind<string>("Favorites", "Items", "", "Comma-separated list of favorited item names.");
			favorites.Clear();
			string[] array = favoritesEntry.Value.Split(',');
			foreach (string text in array)
			{
				if (!string.IsNullOrEmpty(text))
				{
					favorites.Add(text);
				}
			}
		}

		private static void SaveFavorites()
		{
			favoritesEntry.Value = string.Join(",", favorites);
		}

		private static void SortRows()
		{
			allRows.Sort((Row a, Row b) => (a.IsFavorite != b.IsFavorite) ? ((!a.IsFavorite) ? 1 : (-1)) : string.Compare(a.DisplayName, b.DisplayName));
		}

		public static void BuildList()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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_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_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)
			LoadFavorites();
			allRows.Clear();
			Enumerator<ItemDef> enumerator = ItemCatalog.allItemDefs.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					ItemDef current = enumerator.Current;
					if (!((Object)(object)current == (Object)null) && !current.hidden && CategoryOf(current.tier) && current.DoesNotContainTag((ItemTag)9))
					{
						string text = ((object)current.itemIndex/*cast due to .constrained prefix*/).ToString();
						allRows.Add(new Row
						{
							Index = current.itemIndex,
							DisplayName = Language.GetString(current.nameToken),
							Icon = current.pickupIconTexture,
							Key = text,
							IsFavorite = favorites.Contains(text)
						});
					}
				}
			}
			finally
			{
				((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
			}
			SortRows();
			SpawnBoxPlugin.Log.LogInfo((object)$"SpawnBox: {allRows.Count} items available.");
		}

		private static bool CategoryOf(ItemTier tier)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			if ((int)tier <= 4 || tier - 6 <= 3)
			{
				return true;
			}
			return false;
		}

		public static void Draw()
		{
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Gold:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) });
			goldText = GUILayout.TextField(goldText, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) });
			if (GUILayout.Button("Give", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) }))
			{
				GiveGold();
			}
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Search:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) });
			search = GUILayout.TextField(search, Array.Empty<GUILayoutOption>());
			GUILayout.Label("Qty:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(30f) });
			quantityText = GUILayout.TextField(quantityText, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(40f) });
			GUILayout.EndHorizontal();
			bool flag = false;
			scroll = GUILayout.BeginScrollView(scroll, Array.Empty<GUILayoutOption>());
			foreach (Row allRow in allRows)
			{
				if (!string.IsNullOrEmpty(search) && allRow.DisplayName.IndexOf(search, StringComparison.OrdinalIgnoreCase) < 0)
				{
					continue;
				}
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (GUILayout.Button(allRow.IsFavorite ? "Unpin" : "Pin", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(45f) }))
				{
					allRow.IsFavorite = !allRow.IsFavorite;
					if (allRow.IsFavorite)
					{
						favorites.Add(allRow.Key);
					}
					else
					{
						favorites.Remove(allRow.Key);
					}
					SaveFavorites();
					flag = true;
				}
				if ((Object)(object)allRow.Icon != (Object)null)
				{
					GUILayout.Label(allRow.Icon, (GUILayoutOption[])(object)new GUILayoutOption[2]
					{
						GUILayout.Width(24f),
						GUILayout.Height(24f)
					});
				}
				else
				{
					GUILayout.Space(24f);
				}
				GUILayout.Label(allRow.DisplayName, Array.Empty<GUILayoutOption>());
				if (GUILayout.Button("Give", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) }))
				{
					GiveQuantity(allRow.Index, ParseQuantity());
				}
				GUILayout.EndHorizontal();
			}
			GUILayout.EndScrollView();
			if (flag)
			{
				SortRows();
			}
		}

		private static int ParseQuantity()
		{
			if (!int.TryParse(quantityText, out var result) || result <= 0)
			{
				return 1;
			}
			return result;
		}

		private static void GiveQuantity(ItemIndex index, int count)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkServer.active)
			{
				LocalUser firstLocalUser = LocalUserManager.GetFirstLocalUser();
				CharacterBody val = ((firstLocalUser != null) ? firstLocalUser.cachedBody : null);
				Inventory val2 = (((Object)(object)val != (Object)null) ? val.inventory : null);
				if (!((Object)(object)val2 == (Object)null))
				{
					val2.GiveItemPermanent(index, count);
				}
			}
		}

		private static void GiveGold()
		{
			if (NetworkServer.active)
			{
				LocalUser firstLocalUser = LocalUserManager.GetFirstLocalUser();
				CharacterBody val = ((firstLocalUser != null) ? firstLocalUser.cachedBody : null);
				CharacterMaster val2 = (((Object)(object)val != (Object)null) ? val.master : null);
				if (!((Object)(object)val2 == (Object)null) && uint.TryParse(goldText, out var result))
				{
					val2.GiveMoney(result);
				}
			}
		}
	}
	[BepInPlugin("dileppy.spawnbox", "SpawnBox", "1.3.0")]
	public class SpawnBoxPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "dileppy.spawnbox";

		public const string PluginName = "SpawnBox";

		public const string PluginVersion = "1.3.0";

		internal static SpawnBoxPlugin Instance;

		internal static ManualLogSource Log;

		internal static ConfigFile PluginConfig;

		private bool windowOpen;

		private int activeTab;

		private Rect windowRect = new Rect(100f, 100f, 420f, 500f);

		private KeyCode toggleKey;

		private void Awake()
		{
			//IL_003c: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			PluginConfig = ((BaseUnityPlugin)this).Config;
			toggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "ToggleKey", (KeyCode)283, "Key that opens the SpawnBox window.").Value;
			ItemCatalog.Init += new hook_Init(ItemCatalog_Init);
			MasterCatalog.Init += new hook_Init(MasterCatalog_Init);
			EquipmentCatalog.Init += new hook_Init(EquipmentCatalog_Init);
			EliteCatalog.Init += new hook_Init(EliteCatalog_Init);
			SurvivorCatalog.Init += new hook_Init(SurvivorCatalog_Init);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"SpawnBox v1.3.0 online.");
		}

		private void OnDestroy()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			ItemCatalog.Init -= new hook_Init(ItemCatalog_Init);
			MasterCatalog.Init -= new hook_Init(MasterCatalog_Init);
			EquipmentCatalog.Init -= new hook_Init(EquipmentCatalog_Init);
			EliteCatalog.Init -= new hook_Init(EliteCatalog_Init);
			SurvivorCatalog.Init -= new hook_Init(SurvivorCatalog_Init);
		}

		private void ItemCatalog_Init(orig_Init orig)
		{
			orig.Invoke();
			ItemSpawnerTab.BuildList();
		}

		private void MasterCatalog_Init(orig_Init orig)
		{
			orig.Invoke();
			AllySpawnerTab.BuildList();
			InteractableSpawnerTab.BuildList();
		}

		private void EliteCatalog_Init(orig_Init orig)
		{
			orig.Invoke();
			EnemySpawnerTab.BuildEliteList();
		}

		private void SurvivorCatalog_Init(orig_Init orig)
		{
			orig.Invoke();
			EnemySpawnerTab.BuildList();
			SurvivorSpawnerTab.BuildList();
		}

		private void EquipmentCatalog_Init(orig_Init orig)
		{
			orig.Invoke();
			EquipmentSpawnerTab.BuildList();
		}

		private void Update()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown(toggleKey))
			{
				windowOpen = !windowOpen;
			}
		}

		private void OnGUI()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			if (windowOpen)
			{
				windowRect = GUILayout.Window(((Object)this).GetInstanceID(), windowRect, new WindowFunction(DrawWindow), "SpawnBox", Array.Empty<GUILayoutOption>());
			}
		}

		private void DrawWindow(int id)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Toggle(activeTab == 0, "Items", GUIStyle.op_Implicit("button"), Array.Empty<GUILayoutOption>()))
			{
				activeTab = 0;
			}
			if (GUILayout.Toggle(activeTab == 1, "Equipment", GUIStyle.op_Implicit("button"), Array.Empty<GUILayoutOption>()))
			{
				activeTab = 1;
			}
			if (GUILayout.Toggle(activeTab == 2, "Allies", GUIStyle.op_Implicit("button"), Array.Empty<GUILayoutOption>()))
			{
				activeTab = 2;
			}
			if (GUILayout.Toggle(activeTab == 3, "Enemies", GUIStyle.op_Implicit("button"), Array.Empty<GUILayoutOption>()))
			{
				activeTab = 3;
			}
			if (GUILayout.Toggle(activeTab == 4, "Interactables", GUIStyle.op_Implicit("button"), Array.Empty<GUILayoutOption>()))
			{
				activeTab = 4;
			}
			if (GUILayout.Toggle(activeTab == 5, "Survivors", GUIStyle.op_Implicit("button"), Array.Empty<GUILayoutOption>()))
			{
				activeTab = 5;
			}
			if (GUILayout.Toggle(activeTab == 6, "Settings", GUIStyle.op_Implicit("button"), Array.Empty<GUILayoutOption>()))
			{
				activeTab = 6;
			}
			GUILayout.EndHorizontal();
			if (activeTab == 0)
			{
				ItemSpawnerTab.Draw();
			}
			else if (activeTab == 1)
			{
				EquipmentSpawnerTab.Draw();
			}
			else if (activeTab == 2)
			{
				AllySpawnerTab.Draw();
			}
			else if (activeTab == 3)
			{
				EnemySpawnerTab.Draw();
			}
			else if (activeTab == 4)
			{
				InteractableSpawnerTab.Draw();
			}
			else if (activeTab == 5)
			{
				SurvivorSpawnerTab.Draw();
			}
			else
			{
				SettingsTab.Draw();
			}
			GUI.DragWindow();
		}
	}
	internal static class SettingsTab
	{
		public static void Draw()
		{
			GUILayout.Label("Despawn everything SpawnBox has spawned, by category.", Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label($"Allies: {AllySpawnerTab.SpawnedCount()} spawned", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(160f) });
			if (GUILayout.Button("Despawn Allies", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(140f) }))
			{
				AllySpawnerTab.DespawnAll();
			}
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label($"Enemies: {EnemySpawnerTab.SpawnedCount()} spawned", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(160f) });
			if (GUILayout.Button("Despawn Enemies", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(140f) }))
			{
				EnemySpawnerTab.DespawnAll();
			}
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label($"Survivors: {SurvivorSpawnerTab.SpawnedCount()} spawned", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(160f) });
			if (GUILayout.Button("Despawn Survivors", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(140f) }))
			{
				SurvivorSpawnerTab.DespawnAll();
			}
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label($"Interactables: {InteractableSpawnerTab.SpawnedCount()} spawned", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(160f) });
			if (GUILayout.Button("Despawn Interactables", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(140f) }))
			{
				InteractableSpawnerTab.DespawnAll();
			}
			GUILayout.EndHorizontal();
		}
	}
	internal static class SurvivorSpawnerTab
	{
		private class Row
		{
			public GameObject MasterPrefab;

			public string DisplayName;

			public Texture Icon;

			public string Key;

			public bool IsFavorite;
		}

		private const int IconSize = 24;

		private static readonly List<Row> allRows = new List<Row>();

		private static string search = "";

		private static string quantityText = "1";

		private static bool spawnAsAlly = true;

		private static int selectedEliteIndex = 0;

		private static Vector2 scroll;

		private static readonly List<GameObject> spawnedObjects = new List<GameObject>();

		private static ConfigEntry<string> favoritesEntry;

		private static readonly HashSet<string> favorites = new HashSet<string>();

		private static void LoadFavorites()
		{
			favoritesEntry = SpawnBoxPlugin.PluginConfig.Bind<string>("Favorites", "Survivors", "", "Comma-separated list of favorited survivor master names.");
			favorites.Clear();
			string[] array = favoritesEntry.Value.Split(',');
			foreach (string text in array)
			{
				if (!string.IsNullOrEmpty(text))
				{
					favorites.Add(text);
				}
			}
		}

		private static void SaveFavorites()
		{
			favoritesEntry.Value = string.Join(",", favorites);
		}

		private static void SortRows()
		{
			allRows.Sort((Row a, Row b) => (a.IsFavorite != b.IsFavorite) ? ((!a.IsFavorite) ? 1 : (-1)) : string.Compare(a.DisplayName, b.DisplayName));
		}

		public static void BuildList()
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Invalid comparison between Unknown and I4
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Invalid comparison between Unknown and I4
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			LoadFavorites();
			allRows.Clear();
			HashSet<BodyIndex> hashSet = new HashSet<BodyIndex>();
			foreach (SurvivorDef allSurvivorDef in SurvivorCatalog.allSurvivorDefs)
			{
				if (!((Object)(object)allSurvivorDef == (Object)null) && !((Object)(object)allSurvivorDef.bodyPrefab == (Object)null))
				{
					CharacterBody component = allSurvivorDef.bodyPrefab.GetComponent<CharacterBody>();
					if ((Object)(object)component != (Object)null)
					{
						hashSet.Add(component.bodyIndex);
					}
				}
			}
			foreach (CharacterMaster allAiMaster in MasterCatalog.allAiMasters)
			{
				if (!((Object)(object)allAiMaster == (Object)null) && !((Object)(object)allAiMaster.bodyPrefab == (Object)null) && ((int)allAiMaster.teamIndex == 2 || (int)allAiMaster.teamIndex == 4))
				{
					CharacterBody component2 = allAiMaster.bodyPrefab.GetComponent<CharacterBody>();
					if (!((Object)(object)component2 == (Object)null) && !string.IsNullOrEmpty(component2.baseNameToken) && hashSet.Contains(component2.bodyIndex))
					{
						string name = ((Object)((Component)allAiMaster).gameObject).name;
						allRows.Add(new Row
						{
							MasterPrefab = ((Component)allAiMaster).gameObject,
							DisplayName = Language.GetString(component2.baseNameToken),
							Icon = component2.portraitIcon,
							Key = name,
							IsFavorite = favorites.Contains(name)
						});
					}
				}
			}
			SortRows();
			SpawnBoxPlugin.Log.LogInfo((object)$"SpawnBox: {allRows.Count} survivors available.");
		}

		public static void Draw()
		{
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Search:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) });
			search = GUILayout.TextField(search, Array.Empty<GUILayoutOption>());
			GUILayout.Label("Qty:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(30f) });
			quantityText = GUILayout.TextField(quantityText, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(40f) });
			GUILayout.EndHorizontal();
			GUILayout.Label("High values may impact performance.", Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Elite:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) });
			if (GUILayout.Button("<", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(24f) }))
			{
				selectedEliteIndex = (selectedEliteIndex - 1 + EnemySpawnerTab.eliteLabels.Length) % EnemySpawnerTab.eliteLabels.Length;
			}
			GUILayout.Label(EnemySpawnerTab.eliteLabels[selectedEliteIndex], (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(140f) });
			if (GUILayout.Button(">", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(24f) }))
			{
				selectedEliteIndex = (selectedEliteIndex + 1) % EnemySpawnerTab.eliteLabels.Length;
			}
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Team:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) });
			if (GUILayout.Toggle(!spawnAsAlly, "Bad (enemy)", GUIStyle.op_Implicit("button"), Array.Empty<GUILayoutOption>()))
			{
				spawnAsAlly = false;
			}
			if (GUILayout.Toggle(spawnAsAlly, "Good (ally)", GUIStyle.op_Implicit("button"), Array.Empty<GUILayoutOption>()))
			{
				spawnAsAlly = true;
			}
			GUILayout.EndHorizontal();
			bool flag = false;
			scroll = GUILayout.BeginScrollView(scroll, Array.Empty<GUILayoutOption>());
			foreach (Row allRow in allRows)
			{
				if (!string.IsNullOrEmpty(search) && allRow.DisplayName.IndexOf(search, StringComparison.OrdinalIgnoreCase) < 0)
				{
					continue;
				}
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (GUILayout.Button(allRow.IsFavorite ? "Unpin" : "Pin", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(45f) }))
				{
					allRow.IsFavorite = !allRow.IsFavorite;
					if (allRow.IsFavorite)
					{
						favorites.Add(allRow.Key);
					}
					else
					{
						favorites.Remove(allRow.Key);
					}
					SaveFavorites();
					flag = true;
				}
				if ((Object)(object)allRow.Icon != (Object)null)
				{
					GUILayout.Label(allRow.Icon, (GUILayoutOption[])(object)new GUILayoutOption[2]
					{
						GUILayout.Width(24f),
						GUILayout.Height(24f)
					});
				}
				else
				{
					GUILayout.Space(24f);
				}
				GUILayout.Label(allRow.DisplayName, Array.Empty<GUILayoutOption>());
				if (GUILayout.Button("Spawn", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) }))
				{
					SpawnMany(allRow.MasterPrefab, ParseQuantity());
				}
				GUILayout.EndHorizontal();
			}
			GUILayout.EndScrollView();
			if (flag)
			{
				SortRows();
			}
		}

		private static int ParseQuantity()
		{
			if (!int.TryParse(quantityText, out var result) || result <= 0)
			{
				return 1;
			}
			return result;
		}

		private static void SpawnMany(GameObject masterPrefab, int count)
		{
			//IL_0072: 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_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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active)
			{
				return;
			}
			LocalUser firstLocalUser = LocalUserManager.GetFirstLocalUser();
			CharacterBody val = ((firstLocalUser != null) ? firstLocalUser.cachedBody : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			EliteDef val2 = ((selectedEliteIndex > 0 && selectedEliteIndex - 1 < EnemySpawnerTab.eliteOptions.Count) ? EnemySpawnerTab.eliteOptions[selectedEliteIndex - 1] : null);
			for (int i = 0; i < count; i++)
			{
				float num = 360f / (float)count * (float)i;
				Vector3 val3 = Quaternion.Euler(0f, num, 0f) * (val.transform.forward * 5f);
				Vector3 position = val.transform.position + val3;
				CharacterMaster val4 = new MasterSummon
				{
					masterPrefab = masterPrefab,
					position = position,
					rotation = Quaternion.identity,
					teamIndexOverride = (TeamIndex)(spawnAsAlly ? 1 : 2),
					useAmbientLevel = true
				}.Perform();
				if (Object.op_Implicit((Object)(object)val4) && (Object)(object)val2 != (Object)null && Object.op_Implicit((Object)(object)val4.inventory) && Object.op_Implicit((Object)(object)val2.eliteEquipmentDef))
				{
					val4.inventory.SetEquipmentIndex(val2.eliteEquipmentDef.equipmentIndex, false);
				}
				if (Object.op_Implicit((Object)(object)val4))
				{
					if (spawnAsAlly)
					{
						((Component)val4).gameObject.AddComponent<SetDontDestroyOnLoad>();
					}
					spawnedObjects.Add(((Component)val4).gameObject);
				}
			}
		}

		internal static int SpawnedCount()
		{
			int num = 0;
			foreach (GameObject spawnedObject in spawnedObjects)
			{
				if ((Object)(object)spawnedObject != (Object)null)
				{
					num++;
				}
			}
			return num;
		}

		internal static void DespawnAll()
		{
			foreach (GameObject spawnedObject in spawnedObjects)
			{
				if ((Object)(object)spawnedObject != (Object)null)
				{
					NetworkServer.Destroy(spawnedObject);
				}
			}
			spawnedObjects.Clear();
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SpawnBox";

		public const string PLUGIN_NAME = "SpawnBox";

		public const string PLUGIN_VERSION = "1.3.0";
	}
}