Decompiled source of GetItemLink v1.4.9

plugins/GetItemLink.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.NET.Common;
using BepInExResoniteShim;
using Elements.Core;
using FrooxEngine;
using FrooxEngine.Store;
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.4.9")]
[assembly: AssemblyInformationalVersion("1.4.9+9622e6750a5a1301386e835181d28dc4f96b0aec")]
[assembly: AssemblyProduct("GetItemLink")]
[assembly: AssemblyTitle("GetItemLink")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/EIA485/NeosGetItemLink")]
[assembly: AssemblyVersion("1.4.9.0")]
[module: RefSafetyRules(11)]
namespace GetItemLink;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[ResonitePlugin("net.eia485.GetItemLink", "GetItemLink", "1.4.9", "eia485", "https://github.com/EIA485/NeosGetItemLink")]
public class GetItemLink : BasePlugin
{
	[HarmonyPatch(typeof(InventoryBrowser))]
	private class GetItemLinkPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("OnItemSelected")]
		public static void OnItemSelectedPrefix(ref SpecialItemType __state, Sync<SpecialItemType> ____lastSpecialItemType)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected I4, but got Unknown
			__state = (SpecialItemType)(int)((SyncField<SpecialItemType>)(object)____lastSpecialItemType).Value;
		}

		[HarmonyPostfix]
		[HarmonyPatch("OnItemSelected")]
		public static void OnItemSelectedPostfix(InventoryBrowser __instance, BrowserItem currentItem, SpecialItemType __state, SyncRef<Slot> ____buttonsRoot)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Expected O, but got Unknown
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Expected O, but got Unknown
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Invalid comparison between Unknown and I4
			InventoryBrowser __instance2 = __instance;
			if (((Worker)__instance2).World != Userspace.UserspaceWorld || (__state == InventoryBrowser.ClassifyItem((InventoryItemUI)(object)((currentItem is InventoryItemUI) ? currentItem : null)) && (int)__state != -1))
			{
				return;
			}
			UIBuilder val = new UIBuilder(____buttonsRoot.Target[0], (Slot)null);
			RadiantUI_Constants.SetupDefaultStyle(val, false);
			HorizontalLayout hori = val.HorizontalLayout(4f, 0f, (Alignment?)null);
			((Component)hori).Slot.Name = "GetItemLink Buttons";
			((SyncField<float>)(object)((DirectionalLayout)hori).PaddingLeft).Value = 1f;
			((ComponentBase<Component>)(object)__instance2).RunInUpdates(0, (Action)delegate
			{
				((SyncField<float>)(object)((DirectionalLayout)hori).PaddingLeft).Value = 0f;
			});
			AddButton((ButtonEventHandler)delegate(IButton button, ButtonEventData eventData)
			{
				ItemLink(button, __instance2.SelectedInventoryItem, type: false);
			}, "Get Asset URI", colorX.Purple, Badges.Cheese, val);
			AddButton((ButtonEventHandler)delegate(IButton button, ButtonEventData eventData)
			{
				ItemLink(button, __instance2.SelectedInventoryItem, type: true);
			}, "Get Record URI", colorX.Brown, Badges.potato, val);
			AddButton((ButtonEventHandler)delegate
			{
				//IL_0070: Unknown result type (might be due to invalid IL or missing references)
				//IL_007a: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: 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_003d: 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)
				ModalOverlayManager componentInParents = ((Component)__instance2).Slot.GetComponentInParents<ModalOverlayManager>((Predicate<ModalOverlayManager>)null, true, false);
				RecordEditForm val3;
				if (componentInParents == null)
				{
					Slot obj = ((Worker)__instance2).LocalUserSpace.AddSlot("Record Edit Form", true);
					float3? val2 = float3.Backward;
					float3 right = float3.Right;
					SlotPositioning.PositionInFrontOfUser(obj, val2, (float3?)((ref right) * 0.5f), 0.7f, (User)null, true, true, false);
					val3 = RecordEditForm.OpenDialogWindow(obj);
				}
				else
				{
					val3 = ((ContainerWorker<Component>)(object)((Component)componentInParents.OpenModalOverlay(new float2(0.25f, 0.8f), LocaleString.op_Implicit("Edit Record"), false, false, true)).Slot).AttachComponent<RecordEditForm>(true, (Action<RecordEditForm>)null);
				}
				Record record = GetRecord(__instance2.SelectedInventoryItem);
				if (record != null)
				{
					((MethodBase)AccessTools.Method(typeof(RecordEditForm), "Setup", (global::System.Type[])null, (global::System.Type[])null)).Invoke((object)val3, new object[2] { null, record });
				}
			}, "Edit Record", colorX.Orange, Dash.Settings, val);
		}

		[HarmonyPrefix]
		[HarmonyPatch("OnChanges")]
		public static void OnChangesPrefix(InventoryBrowser __instance, SyncRef<Slot> ____buttonsRoot)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			if (((Worker)__instance).World != Userspace.UserspaceWorld)
			{
				return;
			}
			Slot obj = ____buttonsRoot.Target[0];
			bool flag = __instance.SelectedInventoryItem != null;
			Slot val = obj.FindChild("GetItemLink Buttons");
			if (val == null)
			{
				return;
			}
			Enumerator<Slot> enumerator = val.Children.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					Slot current = enumerator.Current;
					if (current.Tag == "Get Asset URI")
					{
						((ComponentBase<Component>)(object)((ContainerWorker<Component>)(object)current).GetComponent<Button>((Predicate<Button>)null, false)).Enabled = flag && GetLink(__instance.SelectedInventoryItem, type: false) != null;
						((SyncField<colorX>)(object)((ContainerWorker<Component>)(object)current[0]).GetComponent<Image>((Predicate<Image>)null, false).Tint).Value = colorX.Black;
					}
					else if (current.Tag == "Get Record URI")
					{
						((ComponentBase<Component>)(object)((ContainerWorker<Component>)(object)current).GetComponent<Button>((Predicate<Button>)null, false)).Enabled = flag && GetLink(__instance.SelectedInventoryItem, type: true) != null;
						((SyncField<colorX>)(object)((ContainerWorker<Component>)(object)current[0]).GetComponent<Image>((Predicate<Image>)null, false).Tint).Value = colorX.Black;
					}
					else if (current.Tag == "Edit Record")
					{
						((ComponentBase<Component>)(object)((ContainerWorker<Component>)(object)current).GetComponent<Button>((Predicate<Button>)null, false)).Enabled = flag && GetRecord(__instance.SelectedInventoryItem) != null;
						((SyncField<colorX>)(object)((ContainerWorker<Component>)(object)current[0]).GetComponent<Image>((Predicate<Image>)null, false).Tint).Value = colorX.Black;
					}
				}
			}
			finally
			{
				((global::System.IDisposable)enumerator).Dispose();
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("OnAwake")]
		public static void InitializeSyncMembersPostfix(InventoryBrowser __instance, Sync<SpecialItemType> ____lastSpecialItemType)
		{
			if (((Worker)__instance).World == Userspace.UserspaceWorld)
			{
				((SyncField<SpecialItemType>)(object)____lastSpecialItemType).Value = (SpecialItemType)(-1);
			}
		}
	}

	private static FieldInfo itemInfo = typeof(InventoryItemUI).GetField("Item", (BindingFlags)36);

	private static FieldInfo directoryInfo = typeof(InventoryItemUI).GetField("Directory", (BindingFlags)36);

	private const SpecialItemType UniqueSIT = -1;

	private const string ButtonsRootName = "GetItemLink Buttons";

	private const string GetAssetTag = "Get Asset URI";

	private const string GetRecordTag = "Get Record URI";

	private const string EditRecordTag = "Edit Record";

	public override void Load()
	{
		((BasePlugin)this).HarmonyInstance.PatchAll();
	}

	public static void AddButton(ButtonEventHandler onPress, string tag, colorX tint, Uri sprite, UIBuilder ui)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		colorX? val = tint;
		Button val2 = ui.Button(sprite, ref val);
		Slot slot = ((Component)val2).Slot;
		slot.Tag = tag;
		val2.LocalPressed += onPress;
		((SyncElementList<ColorDriver>)(object)((InteractionElement)val2).ColorDrivers).RemoveAt(((SyncElementList<ColorDriver>)(object)((InteractionElement)val2).ColorDrivers).Count - 1);
		((SyncField<colorX>)(object)((ContainerWorker<Component>)(object)slot[0]).GetComponent<Image>((Predicate<Image>)null, false).Tint).Value = colorX.Black;
		((SyncField<string>)(object)((ContainerWorker<Component>)(object)slot).AttachComponent<Comment>(true, (Action<Comment>)null).Text).Value = "TooltipperyLabel:" + tag;
	}

	public static void ItemLink(IButton button, InventoryItemUI Item, bool type)
	{
		//IL_005c: 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)
		string link = GetLink(Item, type);
		if (link != null)
		{
			Engine.Current.InputInterface.Clipboard.SetText(link);
			((SyncField<colorX>)(object)((ContainerWorker<Component>)(object)((IComponent)button).Slot[0]).GetComponent<Image>((Predicate<Image>)null, false).Tint).Value = colorX.White;
		}
		else
		{
			((SyncField<colorX>)(object)((ContainerWorker<Component>)(object)((IComponent)button).Slot[0]).GetComponent<Image>((Predicate<Image>)null, false).Tint).Value = colorX.Red;
		}
	}

	private static Record GetRecord(InventoryItemUI item)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Expected O, but got Unknown
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		Record val = (Record)itemInfo.GetValue((object)item);
		object result = (object)val;
		if ((int)val == 0)
		{
			result = ((RecordDirectory)directoryInfo.GetValue((object)item)).EntryRecord;
		}
		return (Record)result;
	}

	private static string GetLink(InventoryItemUI item, bool type)
	{
		Record record = GetRecord(item);
		if (!type)
		{
			if (record == null)
			{
				return null;
			}
			return record.AssetURI;
		}
		if (record == null)
		{
			return null;
		}
		return ((object)record.GetUrl(Engine.Current.PlatformProfile)).ToString();
	}
}
public static class PluginMetadata
{
	public const string GUID = "net.eia485.GetItemLink";

	public const string NAME = "GetItemLink";

	public const string VERSION = "1.4.9";

	public const string AUTHORS = "eia485";

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