Decompiled source of ItemSpawner v0.1.4

plugins/com.quackandcheese.ItemSpawner.dll

Decompiled 2 weeks 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.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using On;
using Photon.Pun;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.UI;
using Zorro.Core;
using Zorro.Core.CLI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.quackandcheese.ItemSpawner")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.4.0")]
[assembly: AssemblyInformationalVersion("0.1.4+21547c2297ca466d385c36ddeccce17c0bc57199")]
[assembly: AssemblyProduct("com.quackandcheese.ItemSpawner")]
[assembly: AssemblyTitle("ItemSpawner")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.4.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace ItemSpawner
{
	public class ItemSpawnerWindow : MenuWindow
	{
		private Canvas canvas;

		private Transform content;

		private InputAction toggleAction;

		public override bool openOnStart => false;

		public override bool selectOnOpen => false;

		public override bool closeOnPause => true;

		public override bool closeOnUICancel => true;

		public override bool autoHideOnClose => true;

		public override GameObject panel => ((Component)canvas).gameObject;

		private void Awake()
		{
			canvas = ((Component)this).GetComponentInChildren<Canvas>();
			((Component)canvas).gameObject.SetActive(false);
		}

		public override void Initialize()
		{
			content = TransformExtensions.FindChildRecursive(((Component)canvas).transform, "Content");
			RefreshEntries();
			SearchScript searchScript = ((Component)this).gameObject.AddComponent<SearchScript>();
			TMP_InputField component = ((Component)TransformExtensions.FindChildRecursive(((Component)canvas).transform, "SearchBar")).GetComponent<TMP_InputField>();
			searchScript.contentHolder = ((Component)content).gameObject;
			searchScript.searchBar = component;
		}

		public void RefreshEntries()
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Expected O, but got Unknown
			Transform val = TransformExtensions.FindChildRecursive(((Component)canvas).transform, "ItemEntry");
			TMP_FontAsset font = Resources.FindObjectsOfTypeAll<TMP_FontAsset>().ToList().Find((TMP_FontAsset x) => ((Object)x).name == "DarumaDropOne-Regular SDF");
			List<Item> objects = ((DatabaseAsset<ItemDatabase, Item>)(object)SingletonAsset<ItemDatabase>.Instance).Objects;
			foreach (Transform item2 in ((Component)val.parent).transform)
			{
				Transform val2 = item2;
				if ((Object)(object)val2 != (Object)(object)val)
				{
					Object.Destroy((Object)(object)((Component)val2).gameObject);
				}
			}
			foreach (Item item in objects)
			{
				Transform val3 = Object.Instantiate<Transform>(val, ((Component)val).transform.parent);
				TextMeshProUGUI component = ((Component)val3.Find("ItemName")).GetComponent<TextMeshProUGUI>();
				((Object)val3).name = item.UIData.itemName;
				((TMP_Text)component).text = item.UIData.itemName;
				((TMP_Text)component).font = font;
				((Component)val3.Find("ItemIcon")).GetComponent<RawImage>().texture = (Texture)(object)item.UIData.icon;
				((UnityEvent)((Component)val3).GetComponent<Button>().onClick).AddListener((UnityAction)delegate
				{
					Plugin.Spawn(item);
				});
				((Component)val3).gameObject.SetActive(true);
			}
		}

		public void Toggle(CallbackContext _)
		{
			if (!((MenuWindow)this).isOpen)
			{
				((MenuWindow)this).Open();
			}
			else
			{
				((MenuWindow)this).Close();
			}
		}

		private void OnEnable()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			KeyCode toggleKey = Plugin.ToggleKey;
			toggleAction = new InputAction("ToggleItemSpawner", (InputActionType)1, "<Keyboard>/" + ((object)(KeyCode)(ref toggleKey)).ToString().ToLower(), (string)null, (string)null, (string)null);
			toggleAction.performed += Toggle;
			toggleAction.Enable();
		}

		private void OnDisable()
		{
			toggleAction.Disable();
			toggleAction.performed -= Toggle;
			toggleAction.Dispose();
		}
	}
	[ConsoleClassCustomizer("ItemSpawner")]
	[BepInPlugin("com.quackandcheese.ItemSpawner", "ItemSpawner", "0.1.4")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Id = "com.quackandcheese.ItemSpawner";

		internal static ManualLogSource Log { get; private set; } = null;


		internal static AssetBundle Bundle { get; set; } = null;


		internal static KeyCode ToggleKey { get; set; } = (KeyCode)286;


		public static string Name => "ItemSpawner";

		public static string Version => "0.1.4";

		private void Awake()
		{
			//IL_004f: 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_006a: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "itemspawnerui");
			Bundle = AssetBundle.LoadFromFile(text);
			ToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "ToggleKey", (KeyCode)286, "The button to toggle the item spawner UI.").Value;
			GUIManager.Start += new hook_Start(On_GUIManager_Start);
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
		}

		private void On_GUIManager_Start(orig_Start orig, GUIManager self)
		{
			orig.Invoke(self);
			GameObject val = Bundle.LoadAsset<GameObject>("ItemSpawnerUI");
			if ((Object)(object)((Component)self).GetComponentInChildren<ItemSpawnerWindow>() != (Object)null)
			{
				Log.LogWarning((object)"ItemSpawner UI already exists, skipping instantiation.");
				return;
			}
			GameObject val2 = Object.Instantiate<GameObject>(val, ((Component)self).transform);
			ItemSpawnerWindow itemSpawnerWindow = val2.AddComponent<ItemSpawnerWindow>();
			((Component)itemSpawnerWindow).gameObject.SetActive(true);
		}

		[ConsoleCommand]
		public static void Spawn(Item item)
		{
			if (PhotonNetwork.IsConnected && Object.op_Implicit((Object)(object)Character.localCharacter))
			{
				Debug.Log((object)$"Spawn item: {item}");
				Character.localCharacter.refs.items.SpawnItemInHand(((Object)item).name);
			}
		}
	}
	public class SearchScript : MonoBehaviour
	{
		public GameObject contentHolder;

		public TMP_InputField searchBar;

		private List<GameObject> searchElements = new List<GameObject>();

		private void Start()
		{
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Expected O, but got Unknown
			TMP_FontAsset font = Resources.FindObjectsOfTypeAll<TMP_FontAsset>().ToList().Find((TMP_FontAsset x) => ((Object)x).name == "DarumaDropOne-Regular SDF");
			searchBar.textComponent.font = font;
			((TMP_Text)((Component)searchBar.placeholder).gameObject.GetComponent<TextMeshProUGUI>()).font = font;
			((UnityEvent<string>)(object)searchBar.onValueChanged).AddListener((UnityAction<string>)delegate
			{
				Search();
			});
			if ((Object)(object)contentHolder == (Object)null || (Object)(object)searchBar == (Object)null)
			{
				Plugin.Log.LogError((object)"Content holder or search bar is not assigned in the search script!");
				return;
			}
			foreach (Transform item in contentHolder.transform)
			{
				Transform val = item;
				searchElements.Add(((Component)val).gameObject);
			}
		}

		public void Search()
		{
			string text = searchBar.text;
			int length = text.Length;
			foreach (GameObject searchElement in searchElements)
			{
				if (!(((Object)searchElement).name == "ItemEntry"))
				{
					TextMeshProUGUI componentInChildren = searchElement.GetComponentInChildren<TextMeshProUGUI>();
					if (Object.op_Implicit((Object)(object)componentInChildren) && ((TMP_Text)componentInChildren).text.Length >= length)
					{
						string text2 = ((TMP_Text)componentInChildren).text.Substring(0, length);
						bool active = text2.ToLower() == text.ToLower();
						searchElement.SetActive(active);
					}
				}
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}