Decompiled source of EnumDropdown v2.2.0

plugins/EnumDropdown/EnumDropdown.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.NET.Common;
using BepInExResoniteShim;
using BepisLocaleLoader;
using Elements.Core;
using FrooxEngine;
using FrooxEngine.FrooxEngine.ProtoFlux.CoreNodes;
using FrooxEngine.ProtoFlux;
using FrooxEngine.ProtoFlux.CoreNodes;
using FrooxEngine.ProtoFlux.Runtimes.Execution;
using FrooxEngine.ProtoFlux.Runtimes.Execution.Nodes;
using FrooxEngine.ProtoFlux.Runtimes.Execution.Nodes.Actions;
using FrooxEngine.ProtoFlux.Runtimes.Execution.Nodes.FrooxEngine.Users;
using FrooxEngine.ProtoFlux.Runtimes.Execution.Nodes.Operators;
using FrooxEngine.UIX;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: AssemblyDescription("Resonite mod that adds a dropdown for enum fields")]
[assembly: ComVisible(false)]
[assembly: Guid("85bbfbc9-747c-42b7-81a4-6b72d89121b9")]
[assembly: TargetFramework(".NETCoreApp,Version=v9.0", FrameworkDisplayName = ".NET 9.0")]
[assembly: AssemblyCompany("badhaloninja, LeCloutPanda")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("2.2.0.0")]
[assembly: AssemblyInformationalVersion("2.2.0+9945959b843f7f01235eafa88947e43ddb0a93e3")]
[assembly: AssemblyProduct("EnumDropdown")]
[assembly: AssemblyTitle("EnumDropdown")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/LeCloutPanda/EnumDropdown")]
[assembly: AssemblyVersion("2.2.0.0")]
[module: RefSafetyRules(11)]
namespace EnumDropdown;

[ResonitePlugin("dev.lecloutpanda.enumdropdown", "EnumDropdown", "2.2.0", "badhaloninja, LeCloutPanda", "https://github.com/LeCloutPanda/EnumDropdown")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class EnumDropdown : BasePlugin
{
	[HarmonyPatch(typeof(EnumMemberEditor), "BuildUI")]
	private class EnumEditorDropdown
	{
		public static void Postfix(EnumMemberEditor __instance, RelayRef<IField> ____target, UIBuilder ui)
		{
			HorizontalLayout componentInChildren = ui.Root.GetComponentInChildren<HorizontalLayout>((Predicate<HorizontalLayout>)null, false, false);
			Slot val = ((componentInChildren != null) ? ((Component)componentInChildren).Slot : null);
			if (val != null)
			{
				ui.NestInto(val);
				AddDropdownBtn(ui, (IField)(object)____target, __instance);
				ui.NestOut();
			}
		}
	}

	private static readonly MethodInfo buildSelectorUI = typeof(EnumDropdown).GetMethod("BuildSelectorUI", (BindingFlags)40);

	private static ConfigEntry<bool> showMoreEnumInfo;

	private static readonly colorX duplicateColor = Sub.PURPLE;

	private static readonly colorX enumColor = Sub.CYAN;

	private static readonly colorX unselectedFlagColor = RadiantUI_Constants.BUTTON_COLOR;

	private static readonly colorX invalidColor = Sub.RED;

	public override void Load()
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Expected O, but got Unknown
		showMoreEnumInfo = ((BasePlugin)this).Config.Bind<bool>("EnumDropdown", "showMoreEnumInfo", false, new ConfigDescription("Show more information about enums in the selector", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.enumdropdown.showMoreEnumInfo.Key", "Settings.dev.lecloutpanda.enumdropdown.showMoreEnumInfo.Description") }));
		((BasePlugin)this).HarmonyInstance.PatchAll();
	}

	public static void AddDropdownBtn(UIBuilder ui, IField target, EnumMemberEditor editor)
	{
		//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_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Expected O, but got Unknown
		IField target2 = target;
		EnumMemberEditor editor2 = editor;
		LocaleString val = LocaleString.op_Implicit("▼");
		Button btn = ui.Button(ref val);
		DestroyOnUserLeaveExtensions.DestroyWhenUserLeaves(((Component)btn).Slot, ((Worker)((Component)btn).Slot).LocalUser);
		((Component)btn).Slot.PersistentSelf = false;
		ReferenceField<User> multiplayerSupport = ((ContainerWorker<Component>)(object)((Component)btn).Slot).AttachComponent<ReferenceField<User>>(true, (Action<ReferenceField<User>>)null);
		ButtonReferenceSet<User> obj = ((ContainerWorker<Component>)(object)((Component)btn).Slot).AttachComponent<ButtonReferenceSet<User>>(true, (Action<ButtonReferenceSet<User>>)null);
		obj.TargetReference.TrySet((IWorldElement)(object)multiplayerSupport.Reference);
		DriveFromLocalUser(obj.SetReference, ((Component)btn).Slot);
		Action val2 = default(Action);
		((SyncField<RefID>)(object)multiplayerSupport.Reference).OnValueChange += delegate
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_003c: Expected O, but got Unknown
			if (multiplayerSupport.Reference.Target != null)
			{
				Slot slot = ((Component)btn).Slot;
				Action obj2 = val2;
				if (obj2 == null)
				{
					Action val3 = delegate
					{
						if (multiplayerSupport.Reference.Target == ((Worker)((Component)btn).Slot).LocalUser)
						{
							multiplayerSupport.Reference.Target = null;
						}
						else
						{
							Button button = btn;
							IField target3 = target2;
							EnumMemberEditor editor3 = editor2;
							User target4 = multiplayerSupport.Reference.Target;
							SpawnEnumSelector((IButton)(object)button, target3, editor3, null, target4);
							multiplayerSupport.Reference.Target = null;
						}
					};
					Action val4 = val3;
					val2 = val3;
					obj2 = val4;
				}
				slot.RunSynchronously(obj2, false);
			}
		};
		btn.LocalPressed += (ButtonEventHandler)delegate(IButton b, ButtonEventData e)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			SpawnEnumSelector(b, target2, editor2, e.globalPoint);
		};
	}

	private static void SpawnEnumSelector(IButton button, IField target, EnumMemberEditor editor, float3? globalPoint = null, User user = null)
	{
		//IL_0059: 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_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: 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_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: 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_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		if ((editor == null && (target == null || !target.ValueType.IsEnum)) || (editor != null && (((MemberEditor)editor).GetMemberValue() == null || !((MemberEditor)editor).GetMemberValue().GetType().IsEnum)))
		{
			return;
		}
		Slot val = BuildEnumSelector(target, editor);
		UserRoot val2 = ((user == null) ? ((Worker)((IComponent)button).Slot).LocalUserRoot : user.Root);
		float3 forward = ((IComponent)button).Slot.Forward;
		float3 val3 = (ref forward) * -0.05f;
		float3 val4 = (ref val3) * val2.GlobalScale;
		RectTransform component = ((ContainerWorker<Component>)(object)((IComponent)button).Slot).GetComponent<RectTransform>((Predicate<RectTransform>)null, false);
		float3 val5 = ((IComponent)button).Slot.GlobalPosition;
		floatQ globalRotation = ((IComponent)button).Slot.GlobalRotation;
		if (component != null)
		{
			Rect val6 = component.ComputeGlobalComputeRect();
			float2 center = ((Rect)(ref val6)).Center;
			Slot slot = ((Component)component.Canvas).Slot;
			forward = float2.op_Implicit(ref center);
			val5 = slot.LocalPointToGlobal(ref forward);
		}
		if (WorldExtensions.IsUserspace(((IWorldElement)button).World) && ((IComponent)button).Slot.GetComponentInParents<RadiantDash>((Predicate<RadiantDash>)null, true, false) != null)
		{
			if (((Worker)val).InputInterface.ScreenActive)
			{
				OverlayManager globallyRegisteredComponent = ((Worker)val).World.GetGloballyRegisteredComponent<OverlayManager>((Predicate<OverlayManager>)null);
				if (globallyRegisteredComponent != null)
				{
					val.Parent = globallyRegisteredComponent.OverlayRoot;
					val.GlobalPosition = float3.Backward;
					val.LocalRotation = floatQ.Identity;
				}
			}
			else
			{
				Slot slot2 = ((Component)((IComponent)button).Slot.GetComponentInParents<RadiantDash>((Predicate<RadiantDash>)null, true, false)).Slot;
				forward = slot2.Forward;
				val4 = (ref forward) * -0.05f;
				forward = slot2.GlobalPosition;
				val.GlobalPosition = (ref forward) + (ref val4);
				forward = val.GlobalPosition;
				float3 localUserViewPosition = ((Worker)val).World.LocalUserViewPosition;
				val3 = (ref forward) - (ref localUserViewPosition);
				float3 normalized = ((float3)(ref val3)).Normalized;
				val.GlobalRotation = floatQ.LookRotation(ref normalized);
			}
		}
		else
		{
			forward = globalPoint.GetValueOrDefault(val5);
			val.GlobalPosition = (ref forward) + (ref val4);
			val.GlobalRotation = globalRotation;
			forward = val.LocalScale;
			val.LocalScale = (ref forward) * val2.GlobalScale;
		}
	}

	public static Slot BuildEnumSelector(IField target, EnumMemberEditor editor)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//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_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		Slot val = ((IWorldElement)target).World.LocalUserSpace.AddSlot("Enum Selector", false);
		UIBuilder val2 = RadiantUI_Panel.SetupPanel(val, LocaleString.op_Implicit("Enum Selector"), new float2(640f, 1200f), true, true);
		float3 localScale = val.LocalScale;
		val.LocalScale = (ref localScale) * 0.0005f;
		RadiantUI_Constants.SetupEditorStyle(val2, false);
		((SyncField<bool>)(object)val2.Canvas.AcceptPhysicalTouch).Value = false;
		val2.Style.TextAlignment = (Alignment)3;
		val2.Style.ForceExpandHeight = false;
		((SyncField<string>)(object)((ContainerWorker<Component>)(object)val).AttachComponent<DynamicVariableSpace>(true, (Action<DynamicVariableSpace>)null).SpaceName).Value = "EnumSelector";
		DestroyOnUserLeaveExtensions.DestroyWhenUserLeaves(val, ((Worker)val).LocalUser);
		val2.ScrollArea((Alignment?)null);
		val2.VerticalLayout(8f, 8f, (Alignment?)null, (bool?)null, (bool?)null);
		val2.FitContent((SizeFit)0, (SizeFit)1);
		val2.Style.MinHeight = 32f;
		global::System.Type type = target.ValueType;
		if (editor != null)
		{
			type = ((MemberEditor)editor).GetMemberValue().GetType();
		}
		((MethodBase)buildSelectorUI.MakeGenericMethod(new global::System.Type[1] { type })).Invoke((object)null, new object[3] { val2, target, editor });
		return val;
	}

	private static void BuildSelectorUI<E>(UIBuilder ui, IField target, EnumMemberEditor editor) where E : struct, global::System.Enum
	{
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		bool flag = ((MemberInfo)typeof(E)).IsDefined(typeof(FlagsAttribute), false);
		if (showMoreEnumInfo.Value)
		{
			string text = (flag ? "Flag" : "Enum");
			((IValue<string>)(object)ui.Root.GetComponentInParents<GenericUIContainer>((Predicate<GenericUIContainer>)null, true, false).Title.Target).Value = $"{((MemberInfo)typeof(E)).Name} {text}<{((global::System.Enum)default(E)).GetTypeCode()}>";
		}
		LocaleString val = LocaleString.op_Implicit("Value:");
		ui.Text(ref val, true, (Alignment?)null, true, (string)null);
		if (flag)
		{
			BuildFlagUI<E>(ui, target, editor);
			val = LocaleString.op_Implicit("Flags:");
			ui.Text(ref val, true, (Alignment?)null, true, (string)null);
		}
		else
		{
			BuildEnumUI<E>(ui);
			val = LocaleString.op_Implicit("All Values:");
			ui.Text(ref val, true, (Alignment?)null, true, (string)null);
		}
		ui.Style.MinHeight = -1f;
		ui.VerticalLayout(8f, 0f, (Alignment?)null, (bool?)null, (bool?)null);
		PopulateValues<E>(ui, ui.Root, target, editor);
	}

	private static void BuildFlagUI<E>(UIBuilder ui, IField target, EnumMemberEditor editor) where E : struct, global::System.Enum
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		LocaleString val = LocaleString.op_Implicit("");
		colorX? val2 = enumColor;
		Button val3 = ui.Button(ref val, ref val2);
		string text = (showMoreEnumInfo.Value ? "{0:d}: {0}" : "{0}");
		E val5;
		IField setValue;
		if (editor != null)
		{
			DynamicValueVariable<E?> val4 = ((ContainerWorker<Component>)(object)((Component)val3).Slot).AttachComponent<DynamicValueVariable<E?>>(true, (Action<DynamicValueVariable<E?>>)null);
			((SyncField<string>)(object)((DynamicVariableBase<E?>)(object)val4).VariableName).Value = "proxy_value";
			object memberValue = ((MemberEditor)editor).GetMemberValue();
			val5 = ((memberValue != null) ? ((E)memberValue) : default(E));
			ButtonValueSet<E?> val6 = ((ContainerWorker<Component>)(object)((Component)val3).Slot).AttachComponent<ButtonValueSet<E?>>(true, (Action<ButtonValueSet<E?>>)null);
			val6.TargetValue.Target = (IField<E?>)(object)val4.Value;
			setValue = (IField)(object)val6.SetValue;
			ValueTextFormatDriverExtensions.DriveFrom<E?>(val3.LabelTextField, (IField<E?>)(object)val6.SetValue, text);
		}
		else
		{
			IField<E> val7 = target as IField<E>;
			val5 = ((IValue<E>)(object)val7).Value;
			ButtonValueSet<E> val8 = ((ContainerWorker<Component>)(object)((Component)val3).Slot).AttachComponent<ButtonValueSet<E>>(true, (Action<ButtonValueSet<E>>)null);
			val8.TargetValue.Target = val7;
			setValue = (IField)(object)val8.SetValue;
			((ContainerWorker<Component>)(object)((Component)val3).Slot).AttachComponent<ButtonDestroy>(true, (Action<ButtonDestroy>)null).Target.TrySet((IWorldElement)(object)ObjectRootExtensions.GetObjectRoot(((Component)val3).Slot, false));
			ValueTextFormatDriverExtensions.DriveFrom<E>(val3.LabelTextField, (IField<E>)(object)val8.SetValue, text);
		}
		setValue.BoxedValue = val5;
		Slot val9 = ((Component)val3).Slot.AddSlot("ENUMSELECTOR.TOGGLEFLAG", true);
		DynamicValueVariable<ulong> obj = ((ContainerWorker<Component>)(object)val9).AttachComponent<DynamicValueVariable<ulong>>(true, (Action<DynamicValueVariable<ulong>>)null);
		((SyncField<string>)(object)((DynamicVariableBase<ulong>)(object)obj).VariableName).Value = "raw_value";
		((SyncField<ulong>)(object)obj.Value).Value = ((IConvertible)(object)val5).ToUInt64((IFormatProvider)(object)CultureInfo.InvariantCulture);
		((SyncField<ulong>)(object)obj.Value).OnValueChange += delegate(SyncField<ulong> field)
		{
			setValue.BoxedValue = EnumUtil.UInt64ToEnum<E>(field.Value);
		};
		SetupEnumXOR(obj.Value, val9);
	}

	private static void BuildEnumUI<E>(UIBuilder ui) where E : struct, global::System.Enum
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		TextField val = ui.TextField("", false, (string)null, false, default(LocaleString));
		LocaleString val2 = LocaleString.op_Implicit("");
		colorX? val3 = colorX.White;
		Button val4 = ui.Button(ref val2, ref val3);
		ButtonPressEventRelay val5 = ((ContainerWorker<Component>)(object)((Component)val4).Slot).AttachComponent<ButtonPressEventRelay>(true, (Action<ButtonPressEventRelay>)null);
		ValueCopyExtensions.DriveFrom<string>((IField<string>)(object)((DynamicVariableBase<Slot>)(object)DynamicReferenceVariableDriverExtensions.DriveFromVariable<Slot>(val5.Target, "")).VariableName, (IField<string>)(object)val.Text.Content, false, false, true);
		ReferenceOptionDescriptionDriver<Slot> obj = ((ContainerWorker<Component>)(object)((Component)val4).Slot).AttachComponent<ReferenceOptionDescriptionDriver<Slot>>(true, (Action<ReferenceOptionDescriptionDriver<Slot>>)null);
		((SyncRef<IField<string>>)(object)obj.Label).Target = val4.LabelTextField;
		((SyncRef<IField<colorX>>)(object)obj.Color).Target = (IField<colorX>)(object)((InteractionElement)val4).BaseColor;
		((SyncRef<SyncRef<Slot>>)(object)obj.Reference).Target = val5.Target;
		ValueCopyExtensions.DriveFrom<string>((IField<string>)(object)((DynamicVariableBase<string>)(object)DynamicValueVariableDriverExtensions.DriveFromVariable<string>((IField<string>)(object)obj.DefaultOption.Label, "")).VariableName, (IField<string>)(object)val.Text.Content, false, false, true);
		((SyncField<colorX>)(object)obj.DefaultOption.Color).Value = enumColor;
		Option<Slot> obj2 = ((SyncElementList<Option<Slot>>)(object)obj.Options).Add();
		((SyncField<string>)(object)obj2.Label).Value = "<i>Invalid Value</i>";
		((SyncField<colorX>)(object)obj2.Color).Value = invalidColor;
	}

	private static void PopulateValues<E>(UIBuilder ui, Slot valuesRoot, IField target, EnumMemberEditor editor) where E : struct, global::System.Enum
	{
		//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f4: Expected O, but got Unknown
		EnumMemberEditor editor2 = editor;
		global::System.Type typeFromHandle = typeof(E);
		if (valuesRoot == null || (editor2 == null && target == null) || !typeFromHandle.IsEnum)
		{
			return;
		}
		bool flag = ((MemberInfo)typeFromHandle).IsDefined(typeof(FlagsAttribute), false);
		ui.Style.MinHeight = 32f;
		Slot enumSelectorRoot = ObjectRootExtensions.GetObjectRoot(valuesRoot, false);
		DynamicValueVariable<ulong> val = null;
		if (flag)
		{
			val = ((ContainerWorker<Component>)(object)valuesRoot).AttachComponent<DynamicValueVariable<ulong>>(true, (Action<DynamicValueVariable<ulong>>)null);
			((SyncField<string>)(object)((DynamicVariableBase<ulong>)(object)val).VariableName).Value = "raw_value";
		}
		DynamicValueVariable<E?> val2 = null;
		E val3 = default(E);
		if (editor2 != null)
		{
			val2 = ((ContainerWorker<Component>)(object)valuesRoot).AttachComponent<DynamicValueVariable<E?>>(true, (Action<DynamicValueVariable<E?>>)null);
			((SyncField<string>)(object)((DynamicVariableBase<E?>)(object)val2).VariableName).Value = "proxy_value";
			((SyncField<E?>)(object)val2.Value).OnValueChange += delegate(SyncField<E?> field)
			{
				if (field.Value.HasValue)
				{
					((MemberEditor)editor2).SetMemberValue((object)field.Value);
					enumSelectorRoot.Destroy();
				}
			};
			object memberValue = ((MemberEditor)editor2).GetMemberValue();
			val3 = ((memberValue != null) ? ((E)memberValue) : default(E));
		}
		else if (target != null)
		{
			val3 = (E)target.BoxedValue;
		}
		((IConvertible)(object)val3).ToUInt64((IFormatProvider)(object)CultureInfo.InvariantCulture);
		string[] names = global::System.Enum.GetNames(typeFromHandle);
		foreach (string text in names)
		{
			E val4 = (E)global::System.Enum.Parse(typeFromHandle, text);
			ulong ulongValue = ((IConvertible)(object)val4).ToUInt64((IFormatProvider)(object)CultureInfo.InvariantCulture);
			if (flag && ulongValue == 0L)
			{
				continue;
			}
			string text2 = (showMoreEnumInfo.Value ? $"{val4:d}: {text}" : text);
			colorX val5 = ((text == ((object)val4).ToString()) ? enumColor : duplicateColor);
			LocaleString val6 = LocaleString.op_Implicit(text2);
			colorX? val7 = val5;
			Button val8 = ui.Button(ref val6, ref val7);
			((SyncField<bool>)(object)val8.RequireLockInToPress).Value = true;
			if (flag)
			{
				BooleanValueDriver<colorX> valueSelectedHighlight = ((ContainerWorker<Component>)(object)((Component)val8).Slot).AttachComponent<BooleanValueDriver<colorX>>(true, (Action<BooleanValueDriver<colorX>>)null);
				IField<colorX> target2 = ((SyncRef<IField<colorX>>)(object)((SyncElementList<ColorDriver>)(object)((InteractionElement)val8).ColorDrivers)[0].ColorDrive).Target;
				((LinkBase<IField<colorX>>)(object)((SyncElementList<ColorDriver>)(object)((InteractionElement)val8).ColorDrivers)[0].ColorDrive).TryLink((IField<colorX>)(object)valueSelectedHighlight.TrueValue);
				ColorDriver obj = ((SyncElementList<ColorDriver>)(object)((InteractionElement)val8).ColorDrivers).Add();
				obj.SetColors(ref unselectedFlagColor);
				((LinkBase<IField<colorX>>)(object)obj.ColorDrive).TryLink((IField<colorX>)(object)valueSelectedHighlight.FalseValue);
				((SyncRef<IField<colorX>>)(object)valueSelectedHighlight.TargetField).TrySet((IWorldElement)(object)target2);
				((ContainerWorker<Component>)(object)((Component)val8).Slot).AttachComponent<ButtonToggle>(true, (Action<ButtonToggle>)null).TargetValue.TrySet((IWorldElement)(object)valueSelectedHighlight.State);
				ButtonDynamicImpulseTriggerWithValue<ulong> obj2 = ((ContainerWorker<Component>)(object)((Component)val8).Slot).AttachComponent<ButtonDynamicImpulseTriggerWithValue<ulong>>(true, (Action<ButtonDynamicImpulseTriggerWithValue<ulong>>)null);
				obj2.Target.Target = enumSelectorRoot;
				((SyncField<string>)(object)obj2.PressedData.Tag).Value = "ENUMSELECTOR.TOGGLEFLAG";
				((SyncField<ulong>)(object)obj2.PressedData.Value).Value = ulongValue;
				((SyncField<ulong>)(object)val.Value).OnValueChange += delegate(SyncField<ulong> field)
				{
					((SyncField<bool>)(object)valueSelectedHighlight.State).Value = (field.Value & ulongValue) >= ulongValue;
				};
				((SyncField<bool>)(object)valueSelectedHighlight.State).Value = ((global::System.Enum)val3).HasFlag((global::System.Enum)val4);
				continue;
			}
			DynamicVariableHelper.CreateReferenceVariable<Slot>(((Component)val8).Slot, text, ((Component)val8).Slot, true);
			DynamicVariableHelper.CreateReferenceVariable<Slot>(((Component)val8).Slot, ulongValue.ToString(), ((Component)val8).Slot, true);
			DynamicVariableHelper.CreateVariable<string>(((Component)val8).Slot, text, text2, true);
			DynamicVariableHelper.CreateVariable<string>(((Component)val8).Slot, ulongValue.ToString(), text2, true);
			ButtonValueSet<E?> obj3 = ((ContainerWorker<Component>)(object)((Component)val8).Slot).AttachComponent<ButtonValueSet<E?>>(true, (Action<ButtonValueSet<E?>>)null);
			SyncRef<IField<E?>> targetValue = obj3.TargetValue;
			IField obj4;
			if (val2 == null)
			{
				obj4 = target;
			}
			else
			{
				IField value = (IField)(object)val2.Value;
				obj4 = value;
			}
			targetValue.TrySet((IWorldElement)(object)obj4);
			((SyncField<E?>)(object)obj3.SetValue).Value = val4;
			if (editor2 == null)
			{
				SyncDelegate<Action> onPressed = ((ContainerWorker<Component>)(object)((Component)val8).Slot).AttachComponent<ButtonActionTrigger>(true, (Action<ButtonActionTrigger>)null).OnPressed;
				Slot obj5 = enumSelectorRoot;
				onPressed.Target = new Action(obj5.Destroy);
			}
		}
	}

	private static void DriveFromLocalUser(SyncRef<User> Target, Slot Root = null)
	{
		//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_003f: Expected O, but got Unknown
		//IL_003e: 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)
		if (Root == null)
		{
			Root = ((SyncElement)Target).Slot;
		}
		Slot val = Root.AddSlot("Local user drive", true);
		LocalUser val2 = ((ContainerWorker<Component>)(object)val).AttachComponent<LocalUser>(true, (Action<LocalUser>)null);
		ProtoFluxNode val3 = (ProtoFluxNode)((ContainerWorker<Component>)(object)val).AttachComponent(ProtoFluxHelper.GetDriverNode(typeof(User)), true, (Action<Component>)null);
		((IDrive)val3).TrySetRootTarget((IWorldElement)(object)Target);
		val3.TryConnectInput(val3.GetInput(0), (INodeOutput)(object)val2, false, false);
		DestroyProxyExtensions.DestroyWhenDestroyed((IDestroyable)(object)Root, (IDestroyable)(object)val, false, true);
	}

	private static void SetupEnumXOR(Sync<ulong> Target, Slot Root)
	{
		DynamicImpulseReceiverWithValue<ulong> val = ((ContainerWorker<Component>)(object)Root).AttachComponent<DynamicImpulseReceiverWithValue<ulong>>(true, (Action<DynamicImpulseReceiverWithValue<ulong>>)null);
		XOR_Ulong val2 = ((ContainerWorker<Component>)(object)Root).AttachComponent<XOR_Ulong>(true, (Action<XOR_Ulong>)null);
		ValueWrite<FrooxEngineContext, ulong> val3 = ((ContainerWorker<Component>)(object)Root).AttachComponent<ValueWrite<FrooxEngineContext, ulong>>(true, (Action<ValueWrite<FrooxEngineContext, ulong>>)null);
		ValueSource<ulong> val4 = ((ContainerWorker<Component>)(object)Root).AttachComponent<ValueSource<ulong>>(true, (Action<ValueSource<ulong>>)null);
		val4.TrySetRootSource((IWorldElement)(object)Target);
		SyncRef<IGlobalValueProxy<string>> tag = val.Tag;
		if (tag.Target == null)
		{
			IGlobalValueProxy<string> val6 = (tag.Target = (IGlobalValueProxy<string>)(object)((ContainerWorker<Component>)(object)Root).AttachComponent<GlobalValue<string>>(true, (Action<GlobalValue<string>>)null));
		}
		((IGlobalValueProxy)val.Tag.Target).TrySetValue((object)Root.Name);
		val2.A.TrySet((IWorldElement)(object)val4);
		val2.B.TrySet((IWorldElement)(object)val.Value);
		val3.Value.TrySet((IWorldElement)(object)val2);
		val.OnTriggered.TrySet((IWorldElement)(object)((ProtoFluxNode)val3).GetOperation(0));
		val3.Variable.Target = (IVariable<FrooxEngineContext, ulong>)(object)val4;
	}
}
public static class PluginMetadata
{
	public const string GUID = "dev.lecloutpanda.enumdropdown";

	public const string NAME = "EnumDropdown";

	public const string VERSION = "2.2.0";

	public const string AUTHORS = "badhaloninja, LeCloutPanda";

	public const string REPOSITORY_URL = "https://github.com/LeCloutPanda/EnumDropdown";
}