Decompiled source of HideRMLMenu v0.1.1

plugins/HideRMLMenu/HideRMLMenu.dll

Decompiled 2 days 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.Versioning;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.NET.Common;
using BepisResoniteWrapper;
using FrooxEngine;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: TargetFramework(".NETCoreApp,Version=v10.0", FrameworkDisplayName = ".NET 10.0")]
[assembly: AssemblyCompany("markn2000")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1")]
[assembly: AssemblyProduct("HideRMLMenu")]
[assembly: AssemblyTitle("HideRMLMenu")]
[assembly: InternalsVisibleTo("HideRMLMenu.Checks")]
[assembly: AssemblyVersion("0.1.1.0")]
[module: RefSafetyRules(11)]
namespace HideRMLMenu;

[BepInPlugin("markn2000.HideRMLMenu", "HideRMLMenu", "0.1.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public sealed class Plugin : BasePlugin
{
	public override void Load()
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Expected O, but got Unknown
		Engine current = Engine.Current;
		if (current != null && current.IsReady)
		{
			OnEngineReady();
		}
		else
		{
			ResoniteHooks.OnEngineReady += new Action(OnEngineReady);
		}
	}

	private void OnEngineReady()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Expected O, but got Unknown
		ResoniteHooks.OnEngineReady -= new Action(OnEngineReady);
		try
		{
			((BasePlugin)this).Log.LogInfo((object)(MenuPatches.Apply(((BasePlugin)this).HarmonyInstance) ? "RML menu hiding enabled. Individual mod settings are preserved." : "No RML menu types found. No patches applied."));
		}
		catch (global::System.Exception ex)
		{
			((BasePlugin)this).HarmonyInstance.UnpatchSelf();
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(53, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failed to hide the RML menu. Plugin patches removed: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<global::System.Exception>(ex);
			}
			log.LogError(val);
		}
	}
}
internal static class MenuPatches
{
	private const string Category = "ResoniteModLoader";

	private static global::System.Type[] hiddenTypes = global::System.Array.Empty<global::System.Type>();

	internal static bool Apply(Harmony harmony)
	{
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Expected O, but got Unknown
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Expected O, but got Unknown
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		hiddenTypes = Enumerable.ToArray<global::System.Type>(Enumerable.Where<global::System.Type>(Enumerable.OfType<global::System.Type>((global::System.Collections.IEnumerable)Enumerable.SelectMany<Assembly, global::System.Type>(Enumerable.Where<Assembly>((global::System.Collections.Generic.IEnumerable<Assembly>)AppDomain.CurrentDomain.GetAssemblies(), (Func<Assembly, bool>)((Assembly assembly) => assembly.GetName().Name == "ResoniteModLoader")), (Func<Assembly, global::System.Collections.Generic.IEnumerable<global::System.Type>>)((Assembly assembly) => new global::System.Type[2]
		{
			assembly.GetType("ResoniteModLoader.ModLoaderSettings", false),
			assembly.GetType("ResoniteModLoader.ModSettings", false)
		}))), (Func<global::System.Type, bool>)((global::System.Type type) => typeof(SettingComponent).IsAssignableFrom(type))));
		if (hiddenTypes.Length == 0)
		{
			return false;
		}
		MethodInfo val = AccessTools.DeclaredMethod(typeof(SettingsDataFeed), "GenerateCategory", new global::System.Type[2]
		{
			typeof(SettingCategoryInfo),
			typeof(global::System.Collections.Generic.IReadOnlyList<string>)
		}, (global::System.Type[])null) ?? throw new MissingMethodException("SettingsDataFeed.GenerateCategory");
		MethodInfo val2 = AccessTools.DeclaredMethod(typeof(SettingsDataFeed), "Enumerate", new global::System.Type[4]
		{
			typeof(global::System.Collections.Generic.IReadOnlyList<string>),
			typeof(global::System.Collections.Generic.IReadOnlyList<string>),
			typeof(string),
			typeof(object)
		}, (global::System.Type[])null) ?? throw new MissingMethodException("SettingsDataFeed.Enumerate");
		harmony.Patch((MethodBase)(object)val, (HarmonyMethod)null, new HarmonyMethod(typeof(MenuPatches), "AfterCategory", (global::System.Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		harmony.Patch((MethodBase)(object)val2, (HarmonyMethod)null, new HarmonyMethod(typeof(MenuPatches), "AfterEnumerate", (global::System.Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		return true;
	}

	private static List<global::System.Type> CategoryTypes()
	{
		List<global::System.Type> val = new List<global::System.Type>();
		Settings.GetSettingTypesInCategory("ResoniteModLoader", val);
		return val;
	}

	private unsafe static void AfterCategory(DataFeedCategory __result)
	{
		if (!(((DataFeedItem)__result).ItemKey != "ResoniteModLoader") && Enumerable.All<global::System.Type>((global::System.Collections.Generic.IEnumerable<global::System.Type>)CategoryTypes(), new Func<global::System.Type, bool>((object)hiddenTypes, (global::System.IntPtr)(nint)(delegate*<global::System.Collections.Generic.IEnumerable<global::System.Type>, global::System.Type, bool>)(&Enumerable.Contains<global::System.Type>))))
		{
			((DataFeedItem)__result).InitVisible((Action<IField<bool>>)delegate(IField<bool> field)
			{
				((IValue<bool>)(object)field).Value = false;
			});
		}
	}

	private static void AfterEnumerate(global::System.Collections.Generic.IReadOnlyList<string> path, ref global::System.Collections.Generic.IAsyncEnumerable<DataFeedItem> __result)
	{
		if (((global::System.Collections.Generic.IReadOnlyCollection<string>)path).Count != 1 || path[0] != "ResoniteModLoader")
		{
			return;
		}
		List<global::System.Type> types = CategoryTypes();
		HashSet<string> names = Enumerable.ToHashSet<string>(Enumerable.Where<string>(Enumerable.Select<global::System.Type, string>((global::System.Collections.Generic.IEnumerable<global::System.Type>)hiddenTypes, (Func<global::System.Type, string>)((global::System.Type type) => ((MemberInfo)type).Name)), (Func<string, bool>)((string name) => !Enumerable.Any<global::System.Type>((global::System.Collections.Generic.IEnumerable<global::System.Type>)types, (Func<global::System.Type, bool>)((global::System.Type type) => ((MemberInfo)type).Name == name && !MemoryExtensions.Contains<global::System.Type>(global::System.ReadOnlySpan<global::System.Type>.op_Implicit(hiddenTypes), type, (IEqualityComparer<global::System.Type>)null))))), (IEqualityComparer<string>)(object)StringComparer.Ordinal);
		__result = AsyncEnumerable.Where<DataFeedItem>(__result, (Func<DataFeedItem, bool>)delegate(DataFeedItem item)
		{
			if (!(item is DataFeedGroup) || !names.Contains(item.ItemKey))
			{
				global::System.Collections.Generic.IReadOnlyList<string> groupingParameters = item.GroupingParameters;
				if (groupingParameters != null && ((global::System.Collections.Generic.IReadOnlyCollection<string>)groupingParameters).Count > 0)
				{
					return !names.Contains(groupingParameters[0]);
				}
				return true;
			}
			return false;
		});
	}
}