Decompiled source of NC LC API v0.0.5

NicholaScott.LethalCompany.API.dll

Decompiled a year ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("NicholaScott.LethalCompany.API")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NicholaScott.LethalCompany.API")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("487AF155-B963-4107-A547-6BED3B3F8EAC")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace NicholaScott.LethalCompany.API;

public class LethalInventory
{
	public struct ReducedItem
	{
		public string ID;

		public int CustomData;

		public int CreditValue;

		public bool UsedUp;

		public bool BatteryEmpty;

		public float BatteryCharge;

		public void Write(FastBufferWriter message)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_005f: 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_0076: 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)
			((FastBufferWriter)(ref message)).WriteValueSafe(ID, false);
			((FastBufferWriter)(ref message)).WriteValueSafe<int>(ref CustomData, default(ForPrimitives));
			((FastBufferWriter)(ref message)).WriteValueSafe<int>(ref CreditValue, default(ForPrimitives));
			((FastBufferWriter)(ref message)).WriteValueSafe<bool>(ref UsedUp, default(ForPrimitives));
			((FastBufferWriter)(ref message)).WriteValueSafe<bool>(ref BatteryEmpty, default(ForPrimitives));
			((FastBufferWriter)(ref message)).WriteValueSafe<float>(ref BatteryCharge, default(ForPrimitives));
		}

		public static ReducedItem Read(FastBufferReader message)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0062: 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)
			string iD = default(string);
			((FastBufferReader)(ref message)).ReadValueSafe(ref iD, false);
			int customData = default(int);
			((FastBufferReader)(ref message)).ReadValueSafe<int>(ref customData, default(ForPrimitives));
			int creditValue = default(int);
			((FastBufferReader)(ref message)).ReadValueSafe<int>(ref creditValue, default(ForPrimitives));
			bool usedUp = default(bool);
			((FastBufferReader)(ref message)).ReadValueSafe<bool>(ref usedUp, default(ForPrimitives));
			bool batteryEmpty = default(bool);
			((FastBufferReader)(ref message)).ReadValueSafe<bool>(ref batteryEmpty, default(ForPrimitives));
			float batteryCharge = default(float);
			((FastBufferReader)(ref message)).ReadValueSafe<float>(ref batteryCharge, default(ForPrimitives));
			ReducedItem result = default(ReducedItem);
			result.ID = iD;
			result.CustomData = customData;
			result.CreditValue = creditValue;
			result.UsedUp = usedUp;
			result.BatteryEmpty = batteryEmpty;
			result.BatteryCharge = batteryCharge;
			return result;
		}

		public static ReducedItem From(GrabbableObject item)
		{
			ReducedItem result = default(ReducedItem);
			result.ID = item.itemProperties.itemName.ToLower().Replace(" ", "");
			result.CustomData = (item.itemProperties.saveItemVariable ? item.GetItemDataToSave() : 0);
			result.CreditValue = (item.itemProperties.isScrap ? item.scrapValue : 0);
			result.UsedUp = item.itemUsedUp;
			result.BatteryEmpty = item.itemProperties.requiresBattery && item.insertedBattery.empty;
			result.BatteryCharge = (item.itemProperties.requiresBattery ? item.insertedBattery.charge : 0f);
			return result;
		}

		public void ApplyToGrabbable(GrabbableObject grabbable)
		{
			Item itemProperties = grabbable.itemProperties;
			grabbable.itemUsedUp = UsedUp;
			if (itemProperties.isScrap)
			{
				grabbable.SetScrapValue(CreditValue);
			}
			if (itemProperties.saveItemVariable)
			{
				grabbable.LoadItemSaveData(CustomData);
			}
			if (itemProperties.requiresBattery)
			{
				grabbable.insertedBattery.empty = BatteryEmpty;
				grabbable.insertedBattery.charge = BatteryCharge;
			}
		}
	}

	private enum NetworkMessageType
	{
		ClientSyncAll,
		ClientAddItem,
		ClientRemoveItem,
		ServerAddItem,
		ServerRemoveItem
	}

	private const string SaveKeyContents = "InventoryContents";

	private string NetworkIdentifier { get; set; } = "InventoryDataTransfer";


	public List<ReducedItem> Contents { get; private set; } = new List<ReducedItem>();


	public event Action PreContentsChanged;

	public event Action PostContentsChanged;

	private void AddItem(ReducedItem item)
	{
		this.PreContentsChanged?.Invoke();
		Contents.Add(item);
		this.PostContentsChanged?.Invoke();
	}

	private void RemoveItem(int index)
	{
		this.PreContentsChanged?.Invoke();
		Contents.RemoveAt(index);
		this.PostContentsChanged?.Invoke();
	}

	public void RemoveItemServerRPC(int index = 0, ulong client = 0uL, bool received = false, FastBufferReader data = default(FastBufferReader))
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: 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_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		if (received)
		{
			((FastBufferReader)(ref data)).ReadValueSafe<int>(ref index, default(ForPrimitives));
			RemoveItem(index);
			RemoveItemClientRPC(index, 0uL);
			return;
		}
		FastBufferWriter val = default(FastBufferWriter);
		((FastBufferWriter)(ref val))..ctor(128, (Allocator)2, -1);
		try
		{
			int num = 4;
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives));
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref index, default(ForPrimitives));
			NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage(NetworkIdentifier, 0uL, val, (NetworkDelivery)3);
		}
		finally
		{
			((IDisposable)(FastBufferWriter)(ref val)).Dispose();
		}
	}

	public void AddItemServerRPC(GrabbableObject grabbable)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		AddItemServerRPC(ReducedItem.From(grabbable), 0uL);
	}

	public void AddItemServerRPC(ReducedItem item = default(ReducedItem), ulong client = 0uL, bool received = false, FastBufferReader data = default(FastBufferReader))
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: 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_006e: Unknown result type (might be due to invalid IL or missing references)
		if (received)
		{
			item = ReducedItem.Read(data);
			AddItem(item);
			AddItemClientRPC(item, 0uL);
			return;
		}
		FastBufferWriter val = default(FastBufferWriter);
		((FastBufferWriter)(ref val))..ctor(128, (Allocator)2, -1);
		try
		{
			int num = 3;
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives));
			item.Write(val);
			NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage(NetworkIdentifier, 0uL, val, (NetworkDelivery)3);
		}
		finally
		{
			((IDisposable)(FastBufferWriter)(ref val)).Dispose();
		}
	}

	public void RemoveItemClientRPC(int index = 0, ulong client = 0uL, bool received = false, FastBufferReader data = default(FastBufferReader))
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: 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_007c: 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_0023: Unknown result type (might be due to invalid IL or missing references)
		if (received)
		{
			if (!NetworkManager.Singleton.IsServer)
			{
				((FastBufferReader)(ref data)).ReadValueSafe<int>(ref index, default(ForPrimitives));
				RemoveItem(index);
			}
			return;
		}
		FastBufferWriter val = default(FastBufferWriter);
		((FastBufferWriter)(ref val))..ctor(128, (Allocator)2, -1);
		try
		{
			int num = 2;
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives));
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref index, default(ForPrimitives));
			NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll(NetworkIdentifier, val, (NetworkDelivery)3);
		}
		finally
		{
			((IDisposable)(FastBufferWriter)(ref val)).Dispose();
		}
	}

	public void AddItemClientRPC(ReducedItem item = default(ReducedItem), ulong client = 0uL, bool received = false, FastBufferReader data = default(FastBufferReader))
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: 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_0017: Unknown result type (might be due to invalid IL or missing references)
		if (received)
		{
			if (!NetworkManager.Singleton.IsServer)
			{
				item = ReducedItem.Read(data);
				AddItem(item);
			}
			return;
		}
		FastBufferWriter val = default(FastBufferWriter);
		((FastBufferWriter)(ref val))..ctor(128, (Allocator)2, -1);
		try
		{
			int num = 1;
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives));
			item.Write(val);
			NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll(NetworkIdentifier, val, (NetworkDelivery)3);
		}
		finally
		{
			((IDisposable)(FastBufferWriter)(ref val)).Dispose();
		}
	}

	public void SyncAllClientRPC(bool allClients = false, ulong client = 0uL, bool received = false, FastBufferReader data = default(FastBufferReader))
	{
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: 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_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		if (received)
		{
			if (NetworkManager.Singleton.IsServer)
			{
				return;
			}
			this.PreContentsChanged?.Invoke();
			Contents = Contents ?? new List<ReducedItem>();
			Contents.Clear();
			int num = default(int);
			((FastBufferReader)(ref data)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			if (num > 0)
			{
				for (int i = 0; i < num; i++)
				{
					Contents.Add(ReducedItem.Read(data));
				}
				this.PostContentsChanged?.Invoke();
			}
			return;
		}
		FastBufferWriter val = default(FastBufferWriter);
		((FastBufferWriter)(ref val))..ctor(100 + 20 * Contents.Count, (Allocator)2, -1);
		try
		{
			int num2 = 0;
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num2, default(ForPrimitives));
			num2 = Contents.Count;
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num2, default(ForPrimitives));
			if (Contents.Count > 0)
			{
				for (int j = 0; j < Contents.Count; j++)
				{
					Contents[j].Write(val);
				}
				if (allClients)
				{
					NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll(NetworkIdentifier, val, (NetworkDelivery)3);
				}
				else
				{
					NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage(NetworkIdentifier, client, val, (NetworkDelivery)3);
				}
			}
		}
		finally
		{
			((IDisposable)(FastBufferWriter)(ref val)).Dispose();
		}
	}

	public void RegisterNetworkMessages(string prefix, string suffix = "")
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		NetworkIdentifier = prefix + NetworkIdentifier + suffix;
		NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler(NetworkIdentifier, new HandleNamedMessageDelegate(ReceiveNetworkMessage));
	}

	private void ReceiveNetworkMessage(ulong senderID, FastBufferReader message)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: 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_0062: 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_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		int num = default(int);
		((FastBufferReader)(ref message)).ReadValueSafe<int>(ref num, default(ForPrimitives));
		switch ((NetworkMessageType)num)
		{
		case NetworkMessageType.ClientSyncAll:
			SyncAllClientRPC(allClients: false, 0uL, received: true, message);
			break;
		case NetworkMessageType.ServerAddItem:
		{
			FastBufferReader data = message;
			AddItemServerRPC(default(ReducedItem), senderID, received: true, data);
			break;
		}
		case NetworkMessageType.ClientAddItem:
		{
			FastBufferReader data = message;
			AddItemClientRPC(default(ReducedItem), 0uL, received: true, data);
			break;
		}
		case NetworkMessageType.ServerRemoveItem:
			RemoveItemServerRPC(0, senderID, received: true, message);
			break;
		case NetworkMessageType.ClientRemoveItem:
			RemoveItemClientRPC(0, 0uL, received: true, message);
			break;
		default:
			throw new ArgumentOutOfRangeException();
		}
	}

	public void SaveInventoryContents(string prefix, string suffix = "")
	{
		string text = prefix + "InventoryContentsContentsLength" + suffix;
		string text2 = prefix + "InventoryContentsID" + suffix;
		string text3 = prefix + "InventoryContentsCustomData" + suffix;
		string text4 = prefix + "InventoryContentsCreditValue" + suffix;
		string text5 = prefix + "InventoryContentsUsedUp" + suffix;
		string text6 = prefix + "InventoryContentsBatteryEmpty" + suffix;
		string text7 = prefix + "InventoryContentsBatteryCharge" + suffix;
		ES3.Save<int>(text, Contents.Count, GameNetworkManager.Instance.currentSaveFileName);
		if (Contents.Count == 0)
		{
			ES3.DeleteKey(text2, GameNetworkManager.Instance.currentSaveFileName);
			ES3.DeleteKey(text3, GameNetworkManager.Instance.currentSaveFileName);
			ES3.DeleteKey(text4, GameNetworkManager.Instance.currentSaveFileName);
			ES3.DeleteKey(text5, GameNetworkManager.Instance.currentSaveFileName);
			ES3.DeleteKey(text6, GameNetworkManager.Instance.currentSaveFileName);
			ES3.DeleteKey(text7, GameNetworkManager.Instance.currentSaveFileName);
			return;
		}
		ES3.Save<string[]>(text2, Contents.Select((ReducedItem redI) => redI.ID).ToArray(), GameNetworkManager.Instance.currentSaveFileName);
		ES3.Save<int[]>(text3, Contents.Select((ReducedItem redI) => redI.CustomData).ToArray(), GameNetworkManager.Instance.currentSaveFileName);
		ES3.Save<int[]>(text4, Contents.Select((ReducedItem redI) => redI.CreditValue).ToArray(), GameNetworkManager.Instance.currentSaveFileName);
		ES3.Save<bool[]>(text5, Contents.Select((ReducedItem redI) => redI.UsedUp).ToArray(), GameNetworkManager.Instance.currentSaveFileName);
		ES3.Save<bool[]>(text6, Contents.Select((ReducedItem redI) => redI.BatteryEmpty).ToArray(), GameNetworkManager.Instance.currentSaveFileName);
		ES3.Save<float[]>(text7, Contents.Select((ReducedItem redI) => redI.BatteryCharge).ToArray(), GameNetworkManager.Instance.currentSaveFileName);
	}

	public void LoadInventoryContents(string prefix, string suffix = "")
	{
		Contents.Clear();
		string text = prefix + "InventoryContentsContentsLength" + suffix;
		string text2 = prefix + "InventoryContentsID" + suffix;
		string text3 = prefix + "InventoryContentsCustomData" + suffix;
		string text4 = prefix + "InventoryContentsCreditValue" + suffix;
		string text5 = prefix + "InventoryContentsUsedUp" + suffix;
		string text6 = prefix + "InventoryContentsBatteryEmpty" + suffix;
		string text7 = prefix + "InventoryContentsBatteryCharge" + suffix;
		string currentSaveFileName = GameNetworkManager.Instance.currentSaveFileName;
		int num = (ES3.KeyExists(text, currentSaveFileName) ? ES3.Load<int>(text, currentSaveFileName) : 0);
		if (num != 0 && ES3.KeyExists(text2, currentSaveFileName) && ES3.KeyExists(text3, currentSaveFileName) && ES3.KeyExists(text4, currentSaveFileName) && ES3.KeyExists(text5, currentSaveFileName) && ES3.KeyExists(text6, currentSaveFileName) && ES3.KeyExists(text7, currentSaveFileName))
		{
			string[] array = ES3.Load<string[]>(text2, currentSaveFileName);
			int[] array2 = ES3.Load<int[]>(text3, currentSaveFileName);
			int[] array3 = ES3.Load<int[]>(text4, currentSaveFileName);
			bool[] array4 = ES3.Load<bool[]>(text5, currentSaveFileName);
			bool[] array5 = ES3.Load<bool[]>(text6, currentSaveFileName);
			float[] array6 = ES3.Load<float[]>(text7, currentSaveFileName);
			for (int i = 0; i < num; i++)
			{
				Contents.Add(new ReducedItem
				{
					ID = array[i],
					CustomData = array2[i],
					CreditValue = array3[i],
					UsedUp = array4[i],
					BatteryEmpty = array5[i],
					BatteryCharge = array6[i]
				});
			}
		}
	}
}
[BepInPlugin("NicholaScott.LethalCompany.API", "Lethal Company API", "0.0.5")]
public class NSLCAPI : BaseUnityPlugin
{
}
public static class Extensions
{
	public static T FindPrefab<T>(this StartOfRound instance, Predicate<T> matches) where T : class
	{
		if (typeof(T) == typeof(SpawnableMapObject))
		{
			SelectableLevel[] levels = instance.levels;
			foreach (SelectableLevel val in levels)
			{
				SpawnableMapObject[] spawnableMapObjects = val.spawnableMapObjects;
				foreach (SpawnableMapObject val2 in spawnableMapObjects)
				{
					if (matches(val2 as T))
					{
						return val2 as T;
					}
				}
			}
		}
		if (typeof(T) == typeof(SpawnableOutsideObject))
		{
			SelectableLevel[] levels2 = instance.levels;
			foreach (SelectableLevel val3 in levels2)
			{
				SpawnableOutsideObjectWithRarity[] spawnableOutsideObjects = val3.spawnableOutsideObjects;
				foreach (SpawnableOutsideObjectWithRarity val4 in spawnableOutsideObjects)
				{
					if (matches(val4 as T))
					{
						return val4 as T;
					}
				}
			}
		}
		if (typeof(T) == typeof(Item))
		{
			foreach (Item items in instance.allItemsList.itemsList)
			{
				if (matches(items as T))
				{
					return items as T;
				}
			}
			foreach (NetworkPrefab prefab in NetworkManager.Singleton.NetworkConfig.Prefabs.Prefabs)
			{
				if (matches(prefab.Prefab.GetComponentInChildren<Item>() as T))
				{
					return prefab.Prefab.GetComponentInChildren<Item>() as T;
				}
			}
		}
		if (typeof(T) == typeof(EnemyType))
		{
			SelectableLevel[] levels3 = instance.levels;
			foreach (SelectableLevel val5 in levels3)
			{
				foreach (SpawnableEnemyWithRarity enemy in val5.Enemies)
				{
					if (matches(enemy.enemyType as T))
					{
						return enemy.enemyType as T;
					}
				}
				foreach (SpawnableEnemyWithRarity daytimeEnemy in val5.DaytimeEnemies)
				{
					if (matches(daytimeEnemy.enemyType as T))
					{
						return daytimeEnemy.enemyType as T;
					}
				}
				foreach (SpawnableEnemyWithRarity outsideEnemy in val5.OutsideEnemies)
				{
					if (matches(outsideEnemy.enemyType as T))
					{
						return outsideEnemy.enemyType as T;
					}
				}
			}
		}
		throw new Exception("The provided type " + typeof(T).Name + " isn't supported by FindPrefab");
	}

	public static T FindPrefabByName<T>(this StartOfRound instance, params string[] queries) where T : class
	{
		Predicate<string> doesItPassQueries = (string f) => queries.Aggregate(seed: true, delegate(bool passesQuery, string curQuery)
		{
			string text = f.ToLower();
			curQuery = curQuery.ToLower();
			return passesQuery && (curQuery.StartsWith("!") ? (!text.Contains(curQuery.Substring(1))) : text.Contains(curQuery));
		});
		if (typeof(T) == typeof(SpawnableMapObject))
		{
			return instance.FindPrefab((SpawnableMapObject f) => doesItPassQueries(((Object)f.prefabToSpawn.gameObject).name)) as T;
		}
		if (typeof(T) == typeof(SpawnableOutsideObject))
		{
			return instance.FindPrefab((SpawnableOutsideObject f) => doesItPassQueries(((Object)f.prefabToSpawn.gameObject).name)) as T;
		}
		if (typeof(T) == typeof(Item))
		{
			return instance.FindPrefab((Item f) => doesItPassQueries(f.itemName)) as T;
		}
		if (typeof(T) == typeof(EnemyType))
		{
			return instance.FindPrefab((EnemyType f) => doesItPassQueries(f.enemyName)) as T;
		}
		throw new Exception("The provided type " + typeof(T).Name + " isn't supported by FindPrefab");
	}

	private static Func<TPredicate, bool> CreatePredicateWithQueries<TPredicate>(Func<TPredicate, string> toString, IEnumerable<string> queries)
	{
		return (TPredicate item) => queries.Aggregate(seed: true, delegate(bool passesQuery, string curQuery)
		{
			string text = toString(item).ToLower();
			curQuery = curQuery.ToLower();
			return passesQuery && (curQuery.StartsWith("!") ? (!text.Contains(curQuery.Substring(1))) : text.Contains(curQuery));
		});
	}
}