Decompiled source of DeselectOwnGizmos v2.1.1

plugins/DeselectOwnGizmos/DeselectOwnGizmos.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.NET.Common;
using BepInExResoniteShim;
using Elements.Core;
using FrooxEngine;
using FrooxEngine.ProtoFlux;
using HarmonyLib;
using SkyFrost.Base;

[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("badhaloninja")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © badhaloninja 2024")]
[assembly: AssemblyFileVersion("2.1.1.0")]
[assembly: AssemblyInformationalVersion("2.1.1+203c7717e79342402ded369d13df53d9558f70cb")]
[assembly: AssemblyProduct("DeselectOwnGizmos")]
[assembly: AssemblyTitle("DeselectOwnGizmos")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/Gyztor/BepisDelesectOwnGizmos")]
[assembly: AssemblyVersion("2.1.1.0")]
[module: RefSafetyRules(11)]
namespace DeselectOwnGizmos;

[ResonitePlugin("dev.badhaloninja.deselectowngizmos", "DeselectOwnGizmos", "2.1.1", "badhaloninja", "https://github.com/Gyztor/BepisDelesectOwnGizmos")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class DeselectOwnGizmos : BasePlugin
{
	[HarmonyPatch]
	private static class ToolPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(DevTool), "GenerateMenuItems")]
		public static void AddDeselectButton(DevTool __instance, ContextMenu menu, SyncRef<Slot> ____currentGizmo, SyncRef<Slot> ____previousGizmo)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Expected O, but got Unknown
			Uri val = ((SkyFrostInterface)((Worker)__instance).Cloud).Assets.GenerateURL("6c6fe0b17b9f9fc07d9c47363988eb98560ff2daf81132bc041bb4ef6a487c18");
			LocaleString val2 = LocaleString.op_Implicit("Deselect Own");
			colorX? val3 = colorX.White;
			menu.AddItem(ref val2, val, ref val3).Button.LocalPressed += (ButtonEventHandler)delegate
			{
				Deselect((Tool)(object)__instance, ____currentGizmo, ____previousGizmo);
			};
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ProtoFluxTool), "GenerateMenuItems")]
		public static void FluxAddDeselectButton(ProtoFluxTool __instance, ContextMenu menu)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			if (ShowOnProtoFluxTool.Value)
			{
				Uri val = ((SkyFrostInterface)((Worker)__instance).Cloud).Assets.GenerateURL("6c6fe0b17b9f9fc07d9c47363988eb98560ff2daf81132bc041bb4ef6a487c18");
				LocaleString val2 = LocaleString.op_Implicit("Deselect Own");
				colorX? val3 = colorX.White;
				menu.AddItem(ref val2, val, ref val3).Button.LocalPressed += (ButtonEventHandler)delegate
				{
					Deselect((Tool)(object)__instance);
				};
			}
		}

		private static void Deselect(Tool tool, SyncRef<Slot> currentGizmo = null, SyncRef<Slot> previousGizmo = null)
		{
			((Worker)tool).World.RootSlot.GetComponentsInChildren<SlotGizmo>((Predicate<SlotGizmo>)IsLocalUserGizmo, false, false, (Predicate<Slot>)null).ForEach((Action<SlotGizmo>)delegate(SlotGizmo s)
			{
				((Component)s).Slot.Destroy();
			});
			InteractionHandler activeHandler = tool.ActiveHandler;
			if (activeHandler != null)
			{
				activeHandler.CloseContextMenu();
			}
			DevTool val = (DevTool)(object)((tool is DevTool) ? tool : null);
			if (val != null)
			{
				currentGizmo.Target = null;
				previousGizmo.Target = null;
				SelectAnchor(val, null);
			}
		}

		private static bool IsLocalUserGizmo(SlotGizmo gizmo)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			World world = ((Worker)gizmo).World;
			RefID referenceID = ((Worker)gizmo).ReferenceID;
			return world.GetUserByAllocationID(((RefID)(ref referenceID)).User).IsLocalUser;
		}

		[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPatch(typeof(DevTool), "SelectAnchor")]
		public static void SelectAnchor(DevTool instance, PointAnchor pointAnchor)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			throw new NotImplementedException("It's a stub");
		}
	}

	[HarmonyPatch(typeof(SlotRecord), "Pressed")]
	private static class GenerateGizmoFromInspector
	{
		public static void Prefix(SlotRecord __instance, ref double ____lastPress)
		{
			if (!((Worker)__instance).World.IsAuthority && ((Worker)__instance).Time.WorldTime - ____lastPress < 0.35 && __instance.TargetSlot.Target != null && !__instance.TargetSlot.Target.IsRootSlot)
			{
				Slot target = __instance.TargetSlot.Target;
				if (target != null)
				{
					GizmoHelper.GetGizmo((Worker)(object)target, false);
				}
			}
		}
	}

	[HarmonyPatch(typeof(DevCreateNewForm), "OpenInspector")]
	private static class GenerateGizmoCreateNew
	{
		public static void Prefix(Slot slot)
		{
			if (!((Worker)slot).World.IsAuthority)
			{
				GizmoHelper.GetGizmo((Worker)(object)slot, false);
			}
		}
	}

	private static ConfigEntry<bool>? ShowOnProtoFluxTool;

	private const string DeselectOwnIcon = "6c6fe0b17b9f9fc07d9c47363988eb98560ff2daf81132bc041bb4ef6a487c18";

	public override void Load()
	{
		ShowOnProtoFluxTool = ((BasePlugin)this).Config.Bind<bool>("General", "ShowOnProtoFluxTool", false, "Adds deselect button to the Protoflux tool");
		((BasePlugin)this).HarmonyInstance.PatchAll();
		((BasePlugin)this).Log.LogInfo((object)"DeselectOwnGizmos mod loaded!");
	}
}
public static class PluginMetadata
{
	public const string GUID = "dev.badhaloninja.deselectowngizmos";

	public const string NAME = "DeselectOwnGizmos";

	public const string VERSION = "2.1.1";

	public const string AUTHORS = "badhaloninja";

	public const string REPOSITORY_URL = "https://github.com/Gyztor/BepisDelesectOwnGizmos";
}