Decompiled source of ResoniteYAP v1.2.0

plugins/ResoniteYAP/ResoniteYAP.dll

Decompiled a month ago
using System;
using System.Collections;
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.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.NET.Common;
using BepInExResoniteShim;
using BepisResoniteWrapper;
using Elements.Core;
using FrooxEngine;
using FrooxEngine.ProtoFlux;
using FrooxEngine.UIX;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: TargetFramework(".NETCoreApp,Version=v9.0", FrameworkDisplayName = ".NET 9.0")]
[assembly: AssemblyCompany("yosh, NepuShiro")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0+ee766c013aabf7e08456619a0aa5425062599113")]
[assembly: AssemblyProduct("YAP")]
[assembly: AssemblyTitle("ResoniteYAP")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/NepuShiro/ResoniteYAP")]
[assembly: AssemblyVersion("1.2.0.0")]
[module: RefSafetyRules(11)]
namespace YAP;

internal enum MatchAlgo
{
	CherryPick,
	Fzy
}
public static class FzyMatcher
{
	private const float SCORE_CONSEC = 0.7f;

	private const float SCORE_UPPER = 0.7f;

	private const float SCORE_GAP_LEADING = -0.2f;

	private const float SCORE_GAP_INNER = -0.05f;

	private const float SCORE_GAP_TRAILING = -0.05f;

	private const float MAX_SCORE = 1f / 0f;

	private const float MIN_SCORE = -1f / 0f;

	private const int MAX_LEN = 64;

	private static float[] BEST_MATCH = new float[64];

	private static float[] BEST = new float[64];

	public unsafe static bool HasMatch(global::System.ReadOnlySpan<char> haystack, global::System.ReadOnlySpan<char> needle)
	{
		if (haystack.Length < needle.Length)
		{
			return false;
		}
		global::System.ReadOnlySpan<char> readOnlySpan = haystack;
		for (int i = 0; i < needle.Length; i++)
		{
			int num = MemoryExtensions.IndexOf<char>(readOnlySpan, *(char*)needle[i]);
			if (num == -1)
			{
				return false;
			}
			readOnlySpan = readOnlySpan.Slice(num + 1);
		}
		return true;
	}

	public unsafe static float Score(global::System.ReadOnlySpan<char> haystack, global::System.ReadOnlySpan<char> haystack_lower, global::System.ReadOnlySpan<char> needle, global::System.ReadOnlySpan<char> needle_lower)
	{
		if (haystack.Length == needle.Length)
		{
			return 1f / 0f;
		}
		float num = -1f / 0f;
		float num2 = -1f / 0f;
		float num3 = -1f / 0f;
		for (int i = 0; i < needle.Length; i++)
		{
			float num4 = ((i == needle.Length - 1) ? (-0.05f) : (-0.05f));
			for (int j = 0; j < haystack.Length; j++)
			{
				if (*(ushort*)needle_lower[i] == *(ushort*)haystack_lower[j])
				{
					float num5 = -1f / 0f;
					float num6 = (char.IsUpper(*(char*)haystack[j]) ? 0.7f : 0f);
					if (i == 0)
					{
						num5 = (float)j * -0.2f + num6;
					}
					else if (j > 0)
					{
						num5 = Math.Max(num2 + num6, num + 0.7f);
					}
					num = BEST_MATCH[j];
					num2 = BEST[j];
					BEST_MATCH[j] = num5;
					num3 = Math.Max(num5, num3 + num4);
				}
				else
				{
					num = BEST_MATCH[j];
					num2 = BEST[j];
					BEST_MATCH[j] = -1f / 0f;
					num3 += num4;
				}
				BEST[j] = num3;
			}
		}
		return BEST[haystack.Length - 1];
	}
}
[HarmonyPatch(typeof(ComponentSelector), "SetupUI")]
public static class Patch_SetupUI
{
	public static bool Prefix(ComponentSelector __instance, SyncRef<Slot> ____uiRoot, Sync<string> ____rootPath, SyncType ____genericType)
	{
		//IL_00bc: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		ComponentSelector __instance2 = __instance;
		if (!Plugin.Enabled.Value)
		{
			return true;
		}
		MethodInfo method = ((object)__instance2).GetType().GetMethod("OnAddComponentPressed", (BindingFlags)36);
		ButtonEventHandler<string> val = ((method != null) ? method.CreateDelegate(typeof(ButtonEventHandler<string>), (object)__instance2) : null) as ButtonEventHandler<string>;
		MethodInfo method2 = ((object)__instance2).GetType().GetMethod("OpenGenericTypesPressed", (BindingFlags)36);
		ButtonEventHandler<string> val2 = ((method2 != null) ? method2.CreateDelegate(typeof(ButtonEventHandler<string>), (object)__instance2) : null) as ButtonEventHandler<string>;
		if (val == null || val2 == null)
		{
			Plugin.Log.LogError((object)"Can't find methods for opening components/types!");
			return true;
		}
		UIBuilder val3 = RadiantUI_Panel.SetupPanel(((Component)__instance2).Slot, LocaleHelper.AsLocaleKey(Plugin.SelectorTitle.Value, (string)null, true, (Dictionary<string, object>)null), Plugin.SelectorSize.Value, true, true);
		RadiantUI_Constants.SetupEditorStyle(val3, true);
		val3.Style.TextAlignment = (Alignment)3;
		val3.Style.ForceExpandHeight = false;
		val3.VerticalLayout(8f, 8f, (Alignment?)null, (bool?)null, (bool?)null);
		val3.HorizontalLayout(8f, 0f, (Alignment?)null);
		val3.Style.MinHeight = Plugin.SearchSize.Value;
		val3.Style.FlexibleWidth = 1f;
		TextField val4 = val3.TextField((string)null, false, (string)null, false, LocaleString.op_Implicit("<alpha=#77>Search..."));
		((SyncField<FinishAction>)(object)val4.Editor.Target.FinishHandling).Value = (FinishAction)2;
		val3.Style.FlexibleWidth = -1f;
		val3.Style.MinWidth = 64f;
		LocaleString val5 = LocaleString.op_Implicit("∅");
		((ContainerWorker<Component>)(object)((Component)val3.Button(ref val5)).Slot).AttachComponent<ButtonValueSet<string>>(true, (Action<ButtonValueSet<string>>)null).TargetValue.Target = (IField<string>)(object)val4.Text.Content;
		val3.Style.MinWidth = -1f;
		val3.Style.MinHeight = -1f;
		val3.NestOut();
		val3.Style.FlexibleHeight = 1f;
		val3.OverlappingLayout(0f, (Alignment?)null);
		ScrollRect scrollRect = val3.ScrollArea((Alignment?)null);
		Slot root = val3.Root;
		val3.VerticalLayout(8f, 0f, (Alignment?)null, (bool?)null, (bool?)null);
		val3.FitContent((SizeFit)0, (SizeFit)1);
		root.ActiveSelf = false;
		val3.NestOut();
		val3.ScrollArea((Alignment?)null);
		val3.VerticalLayout(8f, 0f, (Alignment?)null, (bool?)null, (bool?)null);
		val3.FitContent((SizeFit)0, (SizeFit)1);
		____uiRoot.Target = val3.Root;
		__instance2.BuildUI((string)null, false, (string)null, false);
		Picker picker = new Picker(SyncRef<Slot>.op_Implicit(____uiRoot), root, val4, val, val2);
		((SyncField<string>)(object)____rootPath).OnValueChange += picker.RootPathValueChanged;
		((SyncField<int>)(object)val4.Text.CaretPosition).OnValueChange += picker.CaretPositionChanged;
		((SyncField<string>)(object)val4.Text.Content).OnValueChange += picker.SearchTermChanged;
		Action val6 = default(Action);
		((SyncElement)val4.Text.Content).Changed += delegate
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_0029: Expected O, but got Unknown
			World world = ((Worker)__instance2).World;
			Action obj = val6;
			if (obj == null)
			{
				Action val7 = delegate
				{
					//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)
					((SyncField<float2>)(object)scrollRect.NormalizedPosition).Value = default(float2);
				};
				Action val8 = val7;
				val6 = val7;
				obj = val8;
			}
			world.RunSynchronously(obj, false, (IUpdatable)null, false);
		};
		((SyncField<global::System.Type>)(object)____genericType).OnValueChange += picker.GenericTypeChanged;
		return false;
	}
}
public class Picker
{
	private readonly Slot _normRoot;

	private readonly Slot _searchRoot;

	private Util.MatchType _matchType;

	private readonly UIBuilder _searchUi;

	private readonly TextField _searchField;

	private readonly FontCollection _fontCollection;

	private readonly ButtonEventHandler<string> _onAddPressed;

	private readonly ButtonEventHandler<string> _onGenericPressed;

	public Picker(Slot normRoot, Slot searchRoot, TextField searchField, ButtonEventHandler<string> onAddPressed, ButtonEventHandler<string> onGenericPressed)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Expected O, but got Unknown
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: 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)
		_normRoot = normRoot;
		_searchRoot = searchRoot;
		_searchField = searchField;
		_onAddPressed = onAddPressed;
		_onGenericPressed = onGenericPressed;
		_searchUi = new UIBuilder(searchRoot, (Slot)null);
		RadiantUI_Constants.SetupEditorStyle(_searchUi, true);
		_searchUi.Style.TextAlignment = Plugin.TextAlignment.Value;
		_searchUi.Style.ButtonTextAlignment = Plugin.TextAlignment.Value;
		_searchUi.Style.MinHeight = (Plugin.UseCustomResultSize.Value ? Plugin.ResultSize.Value : (Plugin.ShowPath.Value ? 64f : 32f));
		BooleanValueDriver<bool> obj = ((ContainerWorker<Component>)(object)searchRoot.Parent.Parent).AttachComponent<BooleanValueDriver<bool>>(true, (Action<BooleanValueDriver<bool>>)null);
		ValueCopyExtensions.DriveFrom<bool>((IField<bool>)(object)obj.State, (IField<bool>)(object)searchRoot.ActiveSelf_Field, false, false, true);
		((SyncRef<IField<bool>>)(object)obj.TargetField).Target = (IField<bool>)(object)normRoot.ActiveSelf_Field;
		((SyncField<bool>)(object)obj.FalseValue).Value = true;
		_fontCollection = ((ContainerWorker<Component>)(object)searchRoot.Parent.Parent).AttachComponent<FontCollection>(true, (Action<FontCollection>)null);
		DynamicSpriteFont val = ((ContainerWorker<Component>)(object)searchRoot.Parent.Parent).AttachComponent<DynamicSpriteFont>(true, (Action<DynamicSpriteFont>)null);
		val.AddSprite("circle", Black_Border.Circle_10pc, 1.25f);
		_fontCollection.FontSets.Add((IAssetProvider<FontSet>)(object)((ContainerWorker<Component>)(object)((Worker)searchRoot).World.RootSlot).GetComponent<FontChain>((Predicate<FontChain>)null, false));
		_fontCollection.FontSets.Add((IAssetProvider<FontSet>)(object)val);
	}

	public void SwitchToNorm()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Expected O, but got Unknown
		((Worker)_searchRoot).World.RunSynchronously((Action)([CompilerGenerated] () =>
		{
			_searchRoot.ActiveSelf = false;
		}), false, (IUpdatable)null, false);
	}

	public void SwitchToSearch()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Expected O, but got Unknown
		((Worker)_searchRoot).World.RunSynchronously((Action)([CompilerGenerated] () =>
		{
			_searchRoot.ActiveSelf = true;
		}), false, (IUpdatable)null, false);
	}

	public void SearchTermChanged(SyncField<string> stringField)
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Expected O, but got Unknown
		SyncField<string> stringField2 = stringField;
		((Worker)_searchRoot).World.RunSynchronously((Action)delegate
		{
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: Unknown result type (might be due to invalid IL or missing references)
			_searchRoot.DestroyChildren(false, true, false, (Predicate<Slot>)null);
			if (stringField2.Value == null)
			{
				SwitchToNorm();
				return;
			}
			string text = stringField2.Value;
			string text2 = null;
			int num = stringField2.Value.IndexOf('<', (StringComparison)4);
			if (num != -1)
			{
				text = stringField2.Value.Substring(0, num);
				string value = stringField2.Value;
				int num2 = num;
				text2 = value.Substring(num2, value.Length - num2).TrimEnd();
				if (text2 == "<>")
				{
					text2 = "<dummy>";
				}
			}
			float num3 = (Plugin.SingleClick.Value ? 0f : 0.35f);
			global::System.Collections.Generic.IEnumerator<Util.TypeInfo> enumerator = Util.AlgorithmDelegate.Invoke(text, _matchType, Plugin.SearchLimit.Value).GetEnumerator();
			try
			{
				while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
				{
					Util.TypeInfo current = enumerator.Current;
					bool isGenericTypeDefinition = current.Type.IsGenericTypeDefinition;
					colorX val = (isGenericTypeDefinition ? Sub.GREEN : Sub.CYAN);
					ButtonEventHandler<string> val2 = (isGenericTypeDefinition ? _onGenericPressed : _onAddPressed);
					string text3 = (isGenericTypeDefinition ? ReflectionExtensions.GetNiceName(current.Type, "<", ">", "+") : ((MemberInfo)current.Type).Name);
					long orderOffset = 0L;
					string text4 = ((_matchType == Util.MatchType.ProtoFlux) ? current.Category.Replace("ProtoFlux/Runtimes/Execution/Nodes/", "") : current.Category);
					global::System.Type type = null;
					string text5;
					if (isGenericTypeDefinition)
					{
						try
						{
							text5 = Path.Combine(current.Category, current.Type.AssemblyQualifiedName);
						}
						catch (ArgumentException)
						{
							continue;
						}
						if (text2 != null)
						{
							global::System.Type type2 = Util.ParseGenericReal(current.Type, text2, ((Worker)_normRoot).World);
							if (type2 != (global::System.Type)null)
							{
								val = Sub.PURPLE;
								val2 = _onAddPressed;
								text5 = ((Worker)_normRoot).World.Types.EncodeType(type2);
								text3 = ((MemberInfo)current.Type).Name.Substring(0, ((MemberInfo)current.Type).Name.IndexOf('`')) + text2;
								orderOffset = -1024L;
								type = type2.GetGenericArguments()[0];
							}
						}
					}
					else
					{
						text5 = ((Worker)_normRoot).World.Types.EncodeType(current.Type);
					}
					string text6 = $"<noparse={text3.Length}>{text3}";
					colorX val4;
					if (Plugin.ShowCircle.Value)
					{
						val4 = DatatypeColorHelper.GetTypeColor(type ?? current.Type);
						string text7 = ((colorX)(ref val4)).ToHexString(false, "#");
						text6 = "<color=" + text7 + "><sprite name=\"circle\" tint=true></color>" + text6;
					}
					if (Plugin.ShowPath.Value)
					{
						string text8 = (Plugin.PathNewLine.Value ? "<br>" : "  ");
						val4 = ((colorX)(ref val)).SetValue(1f);
						string text9 = ((colorX)(ref val4)).ToHexString(false, "#");
						text6 = $"{text6}{text8}<color={text9}><size=62%><line-height=133%><nobr>[{text4}]</closeall>";
					}
					UIBuilder searchUi = _searchUi;
					LocaleString val5 = LocaleString.op_Implicit(text6);
					colorX? val6 = val;
					Button val7 = searchUi.Button<string>(ref val5, ref val6, val2, text5, num3);
					((Component)val7).Slot.OrderOffset = orderOffset;
					if (Plugin.ShowPath.Value)
					{
						Text val8 = (Text)((IWorldElement)val7.LabelTextField).Parent;
						((SyncRef<IAssetProvider<FontSet>>)(object)val8.Font).Target = (IAssetProvider<FontSet>)(object)_fontCollection;
						((SyncField<float>)(object)val8.Size).Value = 24.44582f;
					}
				}
			}
			finally
			{
				((global::System.IDisposable)enumerator)?.Dispose();
			}
		}, false, (IUpdatable)null, false);
	}

	public void CaretPositionChanged(SyncField<int> intField)
	{
		if (intField.Value == -1 && string.IsNullOrWhiteSpace(Sync<string>.op_Implicit(_searchField.Text.Content)))
		{
			SwitchToNorm();
		}
		else if (!_searchRoot.ActiveSelf)
		{
			SwitchToSearch();
		}
	}

	public void GenericTypeChanged(SyncField<global::System.Type> typeField)
	{
		if (typeField.Value != (global::System.Type)null)
		{
			SwitchToNorm();
		}
	}

	public void RootPathValueChanged(SyncField<string> stringField)
	{
		string value = stringField.Value;
		_matchType = ((value != null && value.StartsWith("ProtoFlux/Runtimes/")) ? Util.MatchType.ProtoFlux : Util.MatchType.Components);
	}
}
[ResonitePlugin("NepuShiro.ResoniteYAP", "YAP", "1.2.0", "yosh, NepuShiro", "https://github.com/NepuShiro/ResoniteYAP")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BasePlugin
{
	[CompilerGenerated]
	private static class <>O
	{
		public static Func<string, Util.MatchType, int, global::System.Collections.Generic.IEnumerable<Util.TypeInfo>> <0>__FindMatchesCherryPick;

		public static Func<string, Util.MatchType, int, global::System.Collections.Generic.IEnumerable<Util.TypeInfo>> <1>__FindMatchesFzy;

		public static Action <2>__InitLibrary;
	}

	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static EventHandler <>9__14_0;

		internal void <Load>b__14_0(object? _, EventArgs _)
		{
			Func<string, Util.MatchType, int, global::System.Collections.Generic.IEnumerable<Util.TypeInfo>> algorithmDelegate = ((MatchAlgorithm.Value != 0) ? new Func<string, Util.MatchType, int, global::System.Collections.Generic.IEnumerable<Util.TypeInfo>>(Util.FindMatchesFzy) : new Func<string, Util.MatchType, int, global::System.Collections.Generic.IEnumerable<Util.TypeInfo>>(Util.FindMatchesCherryPick));
			Util.AlgorithmDelegate = algorithmDelegate;
		}
	}

	internal static ManualLogSource Log;

	internal static ConfigEntry<bool>? Enabled;

	internal static ConfigEntry<bool>? SingleClick;

	internal static ConfigEntry<int>? SearchLimit;

	internal static ConfigEntry<MatchAlgo>? MatchAlgorithm;

	internal static ConfigEntry<string>? SelectorTitle;

	internal static ConfigEntry<float2>? SelectorSize;

	internal static ConfigEntry<Alignment>? TextAlignment;

	internal static ConfigEntry<float>? SearchSize;

	internal static ConfigEntry<bool>? UseCustomResultSize;

	internal static ConfigEntry<float>? ResultSize;

	internal static ConfigEntry<bool>? ShowCircle;

	internal static ConfigEntry<bool>? ShowPath;

	internal static ConfigEntry<bool>? PathNewLine;

	public override void Load()
	{
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Expected O, but got Unknown
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Expected O, but got Unknown
		//IL_0239: Unknown result type (might be due to invalid IL or missing references)
		//IL_023f: Expected O, but got Unknown
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Expected O, but got Unknown
		Log = ((BasePlugin)this).Log;
		Enabled = ((BasePlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable the search in the component selector.");
		SingleClick = ((BasePlugin)this).Config.Bind<bool>("General", "Single Click", false, "Use single click instead of double click for search results.");
		SearchLimit = ((BasePlugin)this).Config.Bind<int>("General", "Search Limit", 50, new ConfigDescription("Amount of search results to show (5-200)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(5, 200), global::System.Array.Empty<object>()));
		MatchAlgorithm = ((BasePlugin)this).Config.Bind<MatchAlgo>("General", "Algorithm", MatchAlgo.Fzy, "Algorithm to use for matching search terms.");
		SelectorTitle = ((BasePlugin)this).Config.Bind<string>("General", "Selector Title", "ComponentSelector.Title", "Title of the component selector.");
		SelectorSize = ((BasePlugin)this).Config.Bind<float2>("Layout", "Selector Size", new float2(640f, 1200f), "Size of the component selector.");
		TextAlignment = ((BasePlugin)this).Config.Bind<Alignment>("Layout", "Text Alignment", (Alignment)3, "Text alignment for search results.");
		SearchSize = ((BasePlugin)this).Config.Bind<float>("Layout", "Search Size", 64f, "Size of the search bar.");
		UseCustomResultSize = ((BasePlugin)this).Config.Bind<bool>("Layout", "Use Custom Result Size", false, "Use custom result size instead of the default.");
		ResultSize = ((BasePlugin)this).Config.Bind<float>("Layout", "Custom Result Size", 64f, "Size of the search results.");
		ShowCircle = ((BasePlugin)this).Config.Bind<bool>("Display", "Show Circle", false, "Show a circle colored by the component type in the search results.");
		ShowPath = ((BasePlugin)this).Config.Bind<bool>("Display", "Show Path", false, "Show the path to the selected component.");
		PathNewLine = ((BasePlugin)this).Config.Bind<bool>("Display", "Path Newline", true, "Use a newline for the path.");
		ConfigEntry<MatchAlgo>? matchAlgorithm = MatchAlgorithm;
		object obj = <>c.<>9__14_0;
		if (obj == null)
		{
			EventHandler val = delegate
			{
				Func<string, Util.MatchType, int, global::System.Collections.Generic.IEnumerable<Util.TypeInfo>> algorithmDelegate = ((MatchAlgorithm.Value != 0) ? new Func<string, Util.MatchType, int, global::System.Collections.Generic.IEnumerable<Util.TypeInfo>>(Util.FindMatchesFzy) : new Func<string, Util.MatchType, int, global::System.Collections.Generic.IEnumerable<Util.TypeInfo>>(Util.FindMatchesCherryPick));
				Util.AlgorithmDelegate = algorithmDelegate;
			};
			<>c.<>9__14_0 = val;
			obj = (object)val;
		}
		matchAlgorithm.SettingChanged += (EventHandler)obj;
		object obj2 = <>O.<2>__InitLibrary;
		if (obj2 == null)
		{
			Action val2 = Util.InitLibrary;
			<>O.<2>__InitLibrary = val2;
			obj2 = (object)val2;
		}
		ResoniteHooks.OnEngineReady += (Action)obj2;
		((BasePlugin)this).HarmonyInstance.PatchAll();
		ManualLogSource log = Log;
		bool flag = default(bool);
		BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag);
		if (flag)
		{
			((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Plugin ");
			((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>("NepuShiro.ResoniteYAP");
			((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" is loaded!");
		}
		log.LogInfo(val3);
	}
}
public static class Util
{
	public enum MatchType
	{
		Components,
		ProtoFlux
	}

	public record struct TypeInfo(global::System.Type Type, string NameLower, string Category)
	{
		[CompilerGenerated]
		public override readonly string ToString()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			StringBuilder val = new StringBuilder();
			val.Append("TypeInfo");
			val.Append(" { ");
			if (PrintMembers(val))
			{
				val.Append(' ');
			}
			val.Append('}');
			return ((object)val).ToString();
		}

		[CompilerGenerated]
		private readonly bool PrintMembers(StringBuilder builder)
		{
			builder.Append("Type = ");
			builder.Append((object)Type);
			builder.Append(", NameLower = ");
			builder.Append((object)NameLower);
			builder.Append(", Category = ");
			builder.Append((object)Category);
			return true;
		}
	}

	internal static Func<string, MatchType, int, global::System.Collections.Generic.IEnumerable<TypeInfo>> AlgorithmDelegate = FindMatchesFzy;

	private static readonly Dictionary<MatchType, HashSet<TypeInfo>> Library = new Dictionary<MatchType, HashSet<TypeInfo>>();

	public static void InitLibrary()
	{
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Expected O, but got Unknown
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		global::System.DateTime utcNow = global::System.DateTime.UtcNow;
		List<TypeInfo> val = new List<TypeInfo>();
		global::System.Collections.Generic.IEnumerator<AssemblyTypeRegistry> enumerator = ((global::System.Collections.Generic.IEnumerable<AssemblyTypeRegistry>)GlobalTypeRegistry.CoreAssemblies).GetEnumerator();
		try
		{
			while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
			{
				global::System.Collections.Generic.IEnumerator<global::System.Type> enumerator2 = ((global::System.Collections.Generic.IEnumerable<global::System.Type>)enumerator.Current.Types).GetEnumerator();
				try
				{
					while (((global::System.Collections.IEnumerator)enumerator2).MoveNext())
					{
						global::System.Type current = enumerator2.Current;
						if (current.IsSubclassOf(typeof(Component)) && !current.IsAbstract)
						{
							CategoryAttribute customAttribute = CustomAttributeExtensions.GetCustomAttribute<CategoryAttribute>((MemberInfo)(object)current, true);
							string category = ((customAttribute != null) ? Enumerable.FirstOrDefault<string>((global::System.Collections.Generic.IEnumerable<string>)customAttribute.Paths) : null) ?? "Uncategorized";
							val.Add(new TypeInfo
							{
								Type = current,
								NameLower = ((MemberInfo)current).Name.ToLowerInvariant(),
								Category = category
							});
						}
					}
				}
				finally
				{
					((global::System.IDisposable)enumerator2)?.Dispose();
				}
			}
		}
		finally
		{
			((global::System.IDisposable)enumerator)?.Dispose();
		}
		ILookup<bool, TypeInfo> val2 = Enumerable.ToLookup<TypeInfo, bool>((global::System.Collections.Generic.IEnumerable<TypeInfo>)val, (Func<TypeInfo, bool>)((TypeInfo x) => x.Type.IsSubclassOf(typeof(ProtoFluxNode))));
		Library[MatchType.Components] = new HashSet<TypeInfo>(val2[false]);
		Library[MatchType.ProtoFlux] = new HashSet<TypeInfo>(val2[true]);
		ManualLogSource log = Plugin.Log;
		bool flag = default(bool);
		BepInExDebugLogInterpolatedStringHandler val3 = new BepInExDebugLogInterpolatedStringHandler(27, 1, ref flag);
		if (flag)
		{
			((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Time to enumerate types: ");
			TimeSpan val4 = global::System.DateTime.UtcNow - utcNow;
			((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<double>(((TimeSpan)(ref val4)).TotalMilliseconds);
			((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("ms");
		}
		log.LogDebug(val3);
	}

	public static global::System.Type? ParseGenericReal(global::System.Type type, string generic, World world)
	{
		string text = type.FullName.Substring(0, type.FullName.IndexOf('`')) + generic;
		global::System.Type type2 = world.Types.ParseNiceType(text, true);
		if (type2 == (global::System.Type)null || !type2.IsConstructedGenericType)
		{
			return null;
		}
		PropertyInfo property = type2.GetProperty("IsValidGenericType", (BindingFlags)88);
		if (property != (PropertyInfo)null && !(bool)property.GetValue((object)null))
		{
			return null;
		}
		return type2;
	}

	public static float StringScoreCherry(string s, string[] q)
	{
		float num = 0f;
		for (int i = 0; i < q.Length; i++)
		{
			if (!s.Contains(q[i], (StringComparison)4))
			{
				return 0f;
			}
			num += (float)q[i].Length / ((float)(s.Length + i) + 1f);
		}
		return num;
	}

	public static global::System.Collections.Generic.IEnumerable<TypeInfo> FindMatchesCherryPick(string query, MatchType matchType, int limit)
	{
		//IL_001b: 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_004c: Unknown result type (might be due to invalid IL or missing references)
		string[] q = query.Split(' ', (StringSplitOptions)3);
		List<ValueTuple<TypeInfo, float>> val = new List<ValueTuple<TypeInfo, float>>();
		Enumerator<TypeInfo> enumerator = Library[matchType].GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				TypeInfo current = enumerator.Current;
				float num = StringScoreCherry(((MemberInfo)current.Type).Name, q);
				if (num > 0f)
				{
					val.Add(new ValueTuple<TypeInfo, float>(current, num));
				}
			}
		}
		finally
		{
			((global::System.IDisposable)enumerator).Dispose();
		}
		return Enumerable.Select<ValueTuple<TypeInfo, float>, TypeInfo>(Enumerable.Take<ValueTuple<TypeInfo, float>>((global::System.Collections.Generic.IEnumerable<ValueTuple<TypeInfo, float>>)Enumerable.OrderByDescending<ValueTuple<TypeInfo, float>, float>((global::System.Collections.Generic.IEnumerable<ValueTuple<TypeInfo, float>>)val, (Func<ValueTuple<TypeInfo, float>, float>)((ValueTuple<TypeInfo, float> s) => s.Item2)), limit), (Func<ValueTuple<TypeInfo, float>, TypeInfo>)((ValueTuple<TypeInfo, float> s) => s.Item1));
	}

	public static global::System.Collections.Generic.IEnumerable<TypeInfo> FindMatchesFzy(string query, MatchType matchType, int limit)
	{
		//IL_0018: 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_007e: Unknown result type (might be due to invalid IL or missing references)
		string text = query.ToLowerInvariant();
		List<ValueTuple<TypeInfo, float>> val = new List<ValueTuple<TypeInfo, float>>();
		Enumerator<TypeInfo> enumerator = Library[matchType].GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				TypeInfo current = enumerator.Current;
				if (FzyMatcher.HasMatch(string.op_Implicit(current.NameLower), string.op_Implicit(text)))
				{
					float num = FzyMatcher.Score(string.op_Implicit(((MemberInfo)current.Type).Name), string.op_Implicit(current.NameLower), string.op_Implicit(query), string.op_Implicit(text));
					if (num > 0f)
					{
						val.Add(new ValueTuple<TypeInfo, float>(current, num));
					}
				}
			}
		}
		finally
		{
			((global::System.IDisposable)enumerator).Dispose();
		}
		return Enumerable.Select<ValueTuple<TypeInfo, float>, TypeInfo>(Enumerable.Take<ValueTuple<TypeInfo, float>>((global::System.Collections.Generic.IEnumerable<ValueTuple<TypeInfo, float>>)Enumerable.OrderByDescending<ValueTuple<TypeInfo, float>, float>((global::System.Collections.Generic.IEnumerable<ValueTuple<TypeInfo, float>>)val, (Func<ValueTuple<TypeInfo, float>, float>)((ValueTuple<TypeInfo, float> s) => s.Item2)), limit), (Func<ValueTuple<TypeInfo, float>, TypeInfo>)((ValueTuple<TypeInfo, float> s) => s.Item1));
	}
}
public static class PluginMetadata
{
	public const string GUID = "NepuShiro.ResoniteYAP";

	public const string NAME = "YAP";

	public const string VERSION = "1.2.0";

	public const string AUTHORS = "yosh, NepuShiro";

	public const string REPOSITORY_URL = "https://github.com/NepuShiro/ResoniteYAP";
}