Decompiled source of GUIMenuPlugin v1.2.0

GUIMenuPlugin.dll

Decompiled 8 months 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 UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("InvestigationPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("InvestigationPlugin")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("InvestigationPlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.2.0.0")]
namespace LordAshes;

[BepInPlugin("org.lordashes.plugins.guimenu", "GUI Menu Plug-In", "1.2.0.0")]
public class GUIMenuPlugin : BaseUnityPlugin
{
	public interface IMenuItem
	{
		string title { get; set; }

		Color color { get; set; }

		Texture2D icon { get; set; }

		bool gmOnly { get; set; }
	}

	public class MenuSelection : IMenuItem
	{
		public string title { get; set; } = "";


		public Color color { get; set; }

		public Texture2D icon { get; set; } = null;


		public string selection { get; set; } = System.Guid.NewGuid().ToString();


		public bool gmOnly { get; set; }

		public MenuSelection()
		{
		}

		public MenuSelection(string selection, bool gmOnly = false)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			this.selection = selection;
			title = selection;
			color = Color.black;
			icon = null;
			this.gmOnly = gmOnly;
		}

		public MenuSelection(string selection, string title, bool gmOnly = false)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			this.selection = selection;
			this.title = title;
			color = Color.black;
			icon = null;
			this.gmOnly = gmOnly;
		}

		public MenuSelection(string selection, string title, Color color, bool gmOnly = false)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			this.selection = selection;
			this.title = title;
			this.color = color;
			icon = null;
			this.gmOnly = gmOnly;
		}

		public MenuSelection(string selection, Texture2D icon, bool gmOnly = false)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			this.selection = selection;
			title = "";
			color = Color.black;
			this.icon = icon;
			this.gmOnly = gmOnly;
		}

		public MenuSelection(string selection, string title, Texture2D icon, bool gmOnly = false)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			this.selection = selection;
			this.title = title;
			color = Color.black;
			this.icon = icon;
			this.gmOnly = gmOnly;
		}

		public MenuSelection(string selection, string title, Color color, Texture2D icon, bool gmOnly = false)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			this.selection = selection;
			this.title = title;
			this.color = color;
			this.icon = icon;
			this.gmOnly = gmOnly;
		}
	}

	public class MenuLink : IMenuItem
	{
		public string title { get; set; } = "";


		public Color color { get; set; }

		public Texture2D icon { get; set; } = null;


		public string link { get; set; } = "";


		public bool gmOnly { get; set; }

		public MenuLink()
		{
		}

		public MenuLink(string link, bool gmOnly = false)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			this.link = link;
			title = link;
			color = Color.black;
			icon = null;
			this.gmOnly = gmOnly;
		}

		public MenuLink(string link, string title, bool gmOnly = false)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			this.link = link;
			this.title = title;
			color = Color.black;
			icon = null;
			this.gmOnly = gmOnly;
		}

		public MenuLink(string link, string title, Color color, bool gmOnly = false)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			this.link = link;
			this.title = title;
			this.color = color;
			icon = null;
			this.gmOnly = gmOnly;
		}

		public MenuLink(string link, Texture2D icon, bool gmOnly = false)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			this.link = link;
			title = "";
			color = Color.black;
			this.icon = icon;
			this.gmOnly = gmOnly;
		}

		public MenuLink(string link, string title, Texture2D icon, bool gmOnly = false)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			this.link = link;
			this.title = title;
			color = Color.black;
			this.icon = icon;
			this.gmOnly = gmOnly;
		}

		public MenuLink(string link, string title, Color color, Texture2D icon, bool gmOnly = false)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			this.link = link;
			this.title = title;
			this.color = color;
			this.icon = icon;
			this.gmOnly = gmOnly;
		}
	}

	public enum MenuStyle
	{
		centre,
		side
	}

	public enum MenuState
	{
		closed,
		opening,
		opened,
		closing
	}

	public class MenuNode
	{
		private List<IMenuItem> _items = new List<IMenuItem>();

		private MenuState state = MenuState.closed;

		public string name { get; set; } = System.Guid.NewGuid().ToString();


		public MenuStyle style { get; set; } = MenuStyle.centre;


		public int position { get; set; } = 0;


		public MenuNode()
		{
		}

		public MenuNode(string name, IMenuItem[] items, MenuStyle style = MenuStyle.centre)
		{
			this.name = name;
			_items = items.ToList();
			this.style = style;
		}

		public void AddSelection(string selection, string title = "", Texture2D icon = null)
		{
			_items.Add(new MenuSelection
			{
				selection = selection,
				title = title,
				icon = icon
			});
		}

		public void AddSelection(MenuSelection selection)
		{
			_items.Add(selection);
		}

		public void AddLink(string link, string title = "", Texture2D icon = null)
		{
			_items.Add(new MenuLink
			{
				link = link,
				title = title,
				icon = icon
			});
		}

		public void AddLink(MenuLink link)
		{
			_items.Add(link);
		}

		public IMenuItem[] GetItems()
		{
			return _items.ToArray();
		}

		public MenuState GetState()
		{
			return state;
		}

		public void SetState(MenuState state)
		{
			this.state = state;
		}

		public void Animate()
		{
			if (state == MenuState.opening)
			{
				position += 4;
				if (position >= 80)
				{
					state = MenuState.opened;
				}
			}
			else if (state == MenuState.closing)
			{
				position -= 4;
				if (position <= 0)
				{
					state = MenuState.closed;
				}
			}
		}
	}

	public class GuiMenu
	{
		private Dictionary<string, MenuNode> _nodes = new Dictionary<string, MenuNode>();

		private Action<string> _callback = null;

		private MenuNode _currentNode = null;

		private string _queueNodeName = null;

		private int animationSpeed = 1;

		private int iconSize = 64;

		private int itemOffset = 68;

		public GuiMenu()
		{
		}

		public GuiMenu(int iconSize, int itemOffset)
		{
			this.iconSize = iconSize;
			this.itemOffset = itemOffset;
		}

		public GuiMenu(MenuNode[] nodes)
		{
			foreach (MenuNode menuNode in nodes)
			{
				_nodes.Add(menuNode.name, menuNode);
			}
		}

		public GuiMenu(MenuNode[] nodes, int iconSize, int itemOffset)
		{
			this.iconSize = iconSize;
			this.itemOffset = itemOffset;
			foreach (MenuNode menuNode in nodes)
			{
				_nodes.Add(menuNode.name, menuNode);
			}
		}

		public void AddNode(MenuNode node)
		{
			_nodes.Add(node.name, node);
		}

		public IMenuItem[] GetNodeItems(string node)
		{
			if (_nodes.ContainsKey(node))
			{
				return _nodes[node].GetItems();
			}
			return null;
		}

		public MenuNode GetNode(string node)
		{
			if (_nodes.ContainsKey(node))
			{
				return _nodes[node];
			}
			return null;
		}

		public MenuNode GetCurrentNode()
		{
			return _currentNode;
		}

		public void Open(string node, Action<string> callback)
		{
			if (GetNode(node) != null)
			{
				_callback = callback;
				Open(node);
			}
		}

		public void Open(string node)
		{
			if (GetNode(node) != null)
			{
				_currentNode = GetNode(node);
				if (_currentNode.style == MenuStyle.centre)
				{
					_currentNode.SetState(MenuState.opened);
				}
				else
				{
					_currentNode.SetState(MenuState.opening);
				}
				_currentNode.SetState(MenuState.opening);
			}
		}

		public void Queue(string node)
		{
			if (GetNode(node) != null)
			{
				_queueNodeName = node;
				if (_currentNode.style == MenuStyle.centre)
				{
					_currentNode.SetState(MenuState.closed);
				}
				else
				{
					_currentNode.SetState(MenuState.closing);
				}
			}
		}

		public void Draw()
		{
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Expected O, but got Unknown
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_037e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_040a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			if (GetCurrentNode() == null)
			{
				return;
			}
			if (GetCurrentNode().GetState() == MenuState.closed && _queueNodeName != null)
			{
				Debug.Log((object)("GUI Menu Plugin: Processing Queue Menu '" + _queueNodeName + "'"));
				Open(_queueNodeName);
				_queueNodeName = null;
			}
			if (GetCurrentNode().GetState() == MenuState.closed && _queueNodeName == null)
			{
				return;
			}
			int num = itemOffset + 2;
			int num2 = 0;
			int num3 = 0;
			IMenuItem[] items = GetCurrentNode().GetItems();
			foreach (IMenuItem menuItem in items)
			{
				if (!menuItem.gmOnly || LocalClient.IsInGmMode)
				{
					num3++;
				}
			}
			IMenuItem[] items2 = GetCurrentNode().GetItems();
			foreach (IMenuItem menuItem2 in items2)
			{
				if (menuItem2.gmOnly && !LocalClient.IsInGmMode)
				{
					continue;
				}
				GUIStyle val = new GUIStyle();
				val.fontStyle = (FontStyle)1;
				val.normal.textColor = menuItem2.color;
				MenuStyle style = GetCurrentNode().style;
				MenuStyle menuStyle = style;
				int num5;
				int num6;
				int num7;
				int num4;
				if (menuStyle == MenuStyle.side)
				{
					if (GetCurrentNode().GetState() == MenuState.opening)
					{
						GetCurrentNode().position = GetCurrentNode().position + animationSpeed;
						if (GetCurrentNode().position >= 80)
						{
							GetCurrentNode().SetState(MenuState.opened);
						}
					}
					if (GetCurrentNode().GetState() == MenuState.closing)
					{
						GetCurrentNode().position = GetCurrentNode().position - animationSpeed;
						if (GetCurrentNode().position <= 0)
						{
							GetCurrentNode().SetState(MenuState.closed);
						}
					}
					num4 = 1920 - GetCurrentNode().position;
					num5 = (1080 - num3 * num) / 2;
					num5 += num2 * num;
					num6 = -70;
					num7 = num / 4;
					val.alignment = (TextAnchor)5;
				}
				else
				{
					num4 = (1920 - num3 * num) / 2;
					num4 += num2 * num;
					num5 = 505;
					num6 = 0;
					num7 = num;
					val.alignment = (TextAnchor)4;
				}
				if (menuItem2.GetType().Name == typeof(MenuSelection).Name)
				{
					if (GUI.Button(new Rect((float)num4, (float)num5, (float)itemOffset, (float)itemOffset), ""))
					{
						Debug.Log((object)("GUI Menu Plugin: Selected Item '" + ((MenuSelection)menuItem2).selection + "'"));
						Close();
						string selection = ((MenuSelection)menuItem2).selection;
						_callback(selection);
					}
					GUI.DrawTexture(new Rect((float)num4, (float)num5, (float)(iconSize + 4), (float)(iconSize + 4)), (Texture)(object)menuItem2.icon, (ScaleMode)2);
					GUI.Label(new Rect((float)(num4 + num6), (float)(num5 + num7), 68f, 32f), menuItem2.title, val);
				}
				else
				{
					if (GUI.Button(new Rect((float)num4, (float)num5, (float)itemOffset, (float)itemOffset), ""))
					{
						Debug.Log((object)("GUI Menu Plugin: Displaying Menu '" + ((MenuLink)menuItem2).link + "'"));
						Queue(((MenuLink)menuItem2).link);
					}
					GUI.DrawTexture(new Rect((float)num4, (float)num5, (float)(iconSize + 4), (float)(iconSize + 4)), (Texture)(object)menuItem2.icon, (ScaleMode)2);
					GUI.Label(new Rect((float)(num4 + num6), (float)(num5 + num7), 68f, 32f), menuItem2.title, val);
				}
				num2++;
			}
		}

		public void Close()
		{
			if (_currentNode != null && _currentNode.GetState() != 0)
			{
				if (_currentNode.style == MenuStyle.centre)
				{
					_currentNode.SetState(MenuState.closed);
				}
				else
				{
					_currentNode.SetState(MenuState.closing);
				}
			}
		}
	}

	public const string Name = "GUI Menu Plug-In";

	public const string Guid = "org.lordashes.plugins.guimenu";

	public const string Version = "1.2.0.0";

	private void Awake()
	{
		Debug.Log((object)"GUI Menu Plugin: Active.");
	}
}