Decompiled source of SlotlessInspectorOpener v1.2.0

plugins/SlotlessInspectorOpener.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.NET.Common;
using BepInExResoniteShim;
using Elements.Core;
using FrooxEngine;
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("eia485")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0+b258c72c5e7e5bf46a5dfe6d130beed9be314210")]
[assembly: AssemblyProduct("SlotlessInspectorOpener")]
[assembly: AssemblyTitle("SlotlessInspectorOpener")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/EIA485/NeosSlotlessInspectorOpener")]
[assembly: AssemblyVersion("1.2.0.0")]
[module: RefSafetyRules(11)]
namespace SlotlessInspectorOpener;

[ResonitePlugin("net.eia485.SlotlessInspectorOpener", "SlotlessInspectorOpener", "1.2.0", "eia485", "https://github.com/EIA485/NeosSlotlessInspectorOpener")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class SlotlessInspectorOpener : BasePlugin
{
	[HarmonyPatch]
	private class SlotlessInspectorOpenerPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(InspectorHelper), "OpenInspectorForTarget")]
		private static void OpenInspectorForTargetPrefix(ref IWorldElement target, ref bool openWorkerOnly)
		{
			if (openWorkerOnly || (!PreferWorker.Value && (WorldElementExtensions.FindNearestParent<Slot>(target, (Predicate<Slot>)null) != null || WorldElementExtensions.FindNearestParent<User>(target, (Predicate<User>)null) != null)))
			{
				return;
			}
			openWorkerOnly = true;
			IWorldElement obj = target;
			Worker val = ((obj != null) ? WorldElementExtensions.FindNearestParent<Worker>(obj, (Predicate<Worker>)null) : null);
			if (val != target)
			{
				target = (IWorldElement)(object)val;
				return;
			}
			Worker val2 = WorldElementExtensions.FindNearestParent<Worker>(target.Parent, (Predicate<Worker>)null);
			if (val2 != null)
			{
				target = (IWorldElement)(object)val2;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(WorkerInspector), "BuildUIForComponent")]
		private static void BuildUIForComponentPostfix(WorkerInspector __instance, Worker worker, bool allowContainer)
		{
			//IL_0042: 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_004e: Expected O, but got Unknown
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Expected O, but got Unknown
			if (!DisableButtonInjection.Value && allowContainer && worker.Parent != null && WorldElementExtensions.FindNearestParent<Worker>(worker.Parent, (Predicate<Worker>)null) != null && WorldElementExtensions.FindNearestParent<Slot>((IWorldElement)(object)worker, (Predicate<Slot>)null) == null)
			{
				UIBuilder val = new UIBuilder(((Component)__instance).Slot[0][0], (Slot)null);
				RadiantUI_Constants.SetupEditorStyle(val, false);
				val.Style.MinHeight = 24f;
				val.Style.FlexibleWidth = 0f;
				val.Style.MinWidth = 40f;
				Uri rootUp = Inspector.RootUp;
				colorX? val2 = Sub.PURPLE;
				Button obj = val.Button(rootUp, ref val2);
				RefEditor val3 = ((ContainerWorker<Component>)(object)((Component)obj).Slot[0]).AttachComponent<RefEditor>(true, (Action<RefEditor>)null);
				((SyncRef<ISyncRef>)(object)(AccessTools.Field(((object)val3).GetType(), "_targetRef").GetValue((object)val3) as RelayRef<ISyncRef>)).Target = (ISyncRef)AccessTools.Field(((object)__instance).GetType(), "_targetWorker").GetValue((object)__instance);
				obj.Pressed.Target = (ButtonEventHandler)AccessTools.Method(((object)val3).GetType(), "OpenInspectorButton", (global::System.Type[])null, (global::System.Type[])null).CreateDelegate(typeof(ButtonEventHandler), (object)val3);
			}
		}
	}

	private static ConfigEntry<bool> PreferWorker;

	private static ConfigEntry<bool> DisableButtonInjection;

	private static ManualLogSource log;

	public override void Load()
	{
		log = ((BasePlugin)this).Log;
		PreferWorker = ((BasePlugin)this).Config.Bind<bool>("SlotlessInspectorOpener", "PreferWorker", false, "Prefer parent Workers over Slots.");
		DisableButtonInjection = ((BasePlugin)this).Config.Bind<bool>("SlotlessInspectorOpener", "DisableButtonInjection", false, "Disables injecting show parent buttons into now valid Worker Inspectors");
		((BasePlugin)this).HarmonyInstance.PatchAll();
	}
}
public static class PluginMetadata
{
	public const string GUID = "net.eia485.SlotlessInspectorOpener";

	public const string NAME = "SlotlessInspectorOpener";

	public const string VERSION = "1.2.0";

	public const string AUTHORS = "eia485";

	public const string REPOSITORY_URL = "https://github.com/EIA485/NeosSlotlessInspectorOpener";
}