Decompiled source of DeepMenusPlugin v1.1.0

DeepMenusPlugin.dll

Decompiled a week ago
using System;
using System.Collections;
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 BepInEx.Configuration;
using HarmonyLib;
using Newtonsoft.Json;
using RadialUI;
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("DeepMenusPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Nth Dimension")]
[assembly: AssemblyProduct("DeepMenusPlugin")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("DeepMenusPlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.1.0.0")]
namespace LordAshes;

[BepInPlugin("org.lordashes.plugins.deepmenus", "Deep Menus Plugin", "1.1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class DeepMenusPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(CreatureMenuBoardTool), "Begin")]
	private class PatchOnOp
	{
		private static bool Prefix()
		{
			LoggingPlugin.LogTrace("Resetting Current Menu");
			currentMenu = "";
			return true;
		}
	}

	[CompilerGenerated]
	private sealed class <OpenSubMenu>d__15 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public string menuLocation;

		private CreatureBoardAsset <asset>5__1;

		private FieldInfo <fi>5__2;

		private Dictionary<string, List<ItemArgs>> <subMenuEntries>5__3;

		private MapMenu <mapMenu>5__4;

		private List<ItemArgs>.Enumerator <>s__5;

		private ItemArgs <item>5__6;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <OpenSubMenu>d__15(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<asset>5__1 = null;
			<fi>5__2 = null;
			<subMenuEntries>5__3 = null;
			<mapMenu>5__4 = null;
			<>s__5 = default(List<ItemArgs>.Enumerator);
			<item>5__6 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//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_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = (object)new WaitForSeconds(0.1f);
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				LoggingPlugin.LogDebug("Reopening Sub-Menu " + currentMenu);
				CreaturePresenter.TryGetAsset(new CreatureGuid(RadialUIPlugin.GetLastRadialTargetCreature()), ref <asset>5__1);
				if ((Object)(object)<asset>5__1 != (Object)null)
				{
					<fi>5__2 = (from f in typeof(RadialSubmenu).GetRuntimeFields()
						where f.Name == "subMenuEntries"
						select f).ElementAt(0);
					<subMenuEntries>5__3 = (Dictionary<string, List<ItemArgs>>)<fi>5__2.GetValue(null);
					<mapMenu>5__4 = MapMenuManager.OpenMenu(((Component)<asset>5__1).transform.position + Vector3.up * 0.5f, true);
					<>s__5 = <subMenuEntries>5__3["org.lordashes.plugins.deepmenus" + menuLocation].GetEnumerator();
					try
					{
						while (<>s__5.MoveNext())
						{
							<item>5__6 = <>s__5.Current;
							<mapMenu>5__4.AddItem(<item>5__6);
							<item>5__6 = null;
						}
					}
					finally
					{
						((IDisposable)<>s__5).Dispose();
					}
					<>s__5 = default(List<ItemArgs>.Enumerator);
					<fi>5__2 = null;
					<subMenuEntries>5__3 = null;
					<mapMenu>5__4 = null;
				}
				return false;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	public const string Name = "Deep Menus Plugin";

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

	public const string Version = "1.1.0.0";

	public const string Author = "Lord Ashes";

	public static DeepMenusPlugin _self = null;

	public static string currentMenu = "";

	public static List<ItemArgs> menuItems = new List<ItemArgs>();

	private void Awake()
	{
		//IL_001e: 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_003e: 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_0067: Expected O, but got Unknown
		_self = this;
		LoggingPlugin.SetLogLevel(((BaseUnityPlugin)this).Config.Bind<DiagnosticLevel>("Settings", "Diagnostic Level", (DiagnosticLevel)3, (ConfigDescription)null).Value);
		string? assemblyQualifiedName = ((object)this).GetType().AssemblyQualifiedName;
		DiagnosticLevel logLevel = LoggingPlugin.GetLogLevel();
		Debug.Log((object)(assemblyQualifiedName + ": Active. (Diagnostic Mode = " + ((object)(DiagnosticLevel)(ref logLevel)).ToString() + ")"));
		Harmony val = new Harmony("org.lordashes.plugins.deepmenus");
		val.PatchAll();
	}

	public void CreateSubMenu(string menuLocation, ItemArgs item, Func<bool> checker = null)
	{
		item.Obj = "org.lordashes.plugins.deepmenus" + menuLocation;
		item.Action = delegate
		{
			NavigateTo(item.Title);
		};
		EnsureMenuExists(menuLocation);
		RadialSubmenu.CreateSubMenuItem("org.lordashes.plugins.deepmenus" + menuLocation, item, (Action<HideVolumeItem, string, MapMenuItem>)null, checker);
	}

	public void CreateSubMenuItem(string menuLocation, ItemArgs item, Func<bool> checker = null)
	{
		item.Obj = "org.lordashes.plugins.deepmenus" + menuLocation;
		EnsureMenuExists(menuLocation);
		RadialSubmenu.CreateSubMenuItem("org.lordashes.plugins.deepmenus" + menuLocation, item, (Action<HideVolumeItem, string, MapMenuItem>)null, checker);
	}

	public ItemArgs MakeItemEntry(string item, Action<string, string> callback, Sprite icon, bool fadeName = false, bool closeMenu = true)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: 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_0038: 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_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Expected O, but got Unknown
		return new ItemArgs
		{
			Title = item,
			Action = delegate
			{
				callback(item, currentMenu);
			},
			Icon = icon,
			FadeName = fadeName,
			CloseMenuOnActivate = closeMenu
		};
	}

	public ItemArgs MakeSubMenuEntry(string item, Sprite icon, bool fadeName = false, bool closeMenu = true)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: 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_0038: 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_0048: Expected O, but got Unknown
		return new ItemArgs
		{
			Title = item,
			Action = delegate
			{
				NavigateTo(item);
			},
			Icon = icon,
			FadeName = fadeName,
			CloseMenuOnActivate = closeMenu
		};
	}

	public static void NavigateTo(string selection)
	{
		currentMenu = currentMenu + "/" + selection.ToString();
		LoggingPlugin.LogDebug("Navigating To " + currentMenu);
		((MonoBehaviour)_self).StartCoroutine(OpenSubMenu(currentMenu));
	}

	private void EnsureMenuExists(string menuLocation)
	{
		FieldInfo fieldInfo = (from f in typeof(RadialSubmenu).GetRuntimeFields()
			where f.Name == "subMenuEntries"
			select f).ElementAt(0);
		Dictionary<string, List<ItemArgs>> dictionary = (Dictionary<string, List<ItemArgs>>)fieldInfo.GetValue(null);
		if (!dictionary.ContainsKey("org.lordashes.plugins.deepmenus" + menuLocation))
		{
			dictionary.Add("org.lordashes.plugins.deepmenus" + menuLocation, new List<ItemArgs>());
			fieldInfo.SetValue(null, dictionary);
		}
	}

	[IteratorStateMachine(typeof(<OpenSubMenu>d__15))]
	public static IEnumerator OpenSubMenu(string menuLocation)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <OpenSubMenu>d__15(0)
		{
			menuLocation = menuLocation
		};
	}

	public static void RemoveMenuBranch(string menuLocation)
	{
		menuLocation = "org.lordashes.plugins.deepmenus" + menuLocation;
		FieldInfo field = typeof(RadialSubmenu).GetField("subMenuEntries", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
		if (field != null)
		{
			Dictionary<string, List<ItemArgs>> dictionary = (Dictionary<string, List<ItemArgs>>)field.GetValue(null);
			List<string> list = new List<string>();
			for (int i = 0; i < dictionary.Count; i++)
			{
				LoggingPlugin.LogTrace("Found Entry " + dictionary.ElementAt(i).Key + " With " + dictionary.ElementAt(i).Value.Count + " Entries");
				if (dictionary.ElementAt(i).Key.StartsWith(menuLocation))
				{
					LoggingPlugin.LogTrace("Removing '" + dictionary.ElementAt(i).Key + "'s " + dictionary.ElementAt(i).Value.Count + " Entries");
					list.Add(dictionary.ElementAt(i).Key);
				}
				else
				{
					LoggingPlugin.LogTrace("Keeping '" + dictionary.ElementAt(i).Key + "'s " + dictionary.ElementAt(i).Value.Count + " Entries");
				}
			}
			{
				foreach (string item in list)
				{
					dictionary.Remove(item);
				}
				return;
			}
		}
		LoggingPlugin.LogWarning("Could Not Find Field 'subMenuEntries'");
	}

	public static Dictionary<string, List<ItemArgs>> MenuEntries()
	{
		FieldInfo field = typeof(RadialSubmenu).GetField("subMenuEntries", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
		if (field != null)
		{
			Dictionary<string, List<ItemArgs>> dictionary = (Dictionary<string, List<ItemArgs>>)field.GetValue(null);
			return JsonConvert.DeserializeObject<Dictionary<string, List<ItemArgs>>>(JsonConvert.SerializeObject((object)dictionary));
		}
		return null;
	}
}