Decompiled source of Toggles v1.1.0

plugins/Toggles/Toggles.dll

Decompiled 4 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.NET.Common;
using BepInExResoniteShim;
using BepisLocaleLoader;
using Elements.Core;
using FrooxEngine;
using FrooxEngine.ProtoFlux;
using FrooxEngine.UIX;
using HarmonyLib;
using Renderite.Shared;
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("LeCloutPanda, NepuShiro, art0007i")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+ea4d86f3b53bba6c8742f2f9113dd16f773b5e47")]
[assembly: AssemblyProduct("Toggles")]
[assembly: AssemblyTitle("Toggles")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/lecloutpanda/Toggles")]
[assembly: AssemblyVersion("1.1.0.0")]
[module: RefSafetyRules(11)]
[CompilerGenerated]
internal delegate TResult <>f__AnonymousDelegate0<T1, T2, T3, T4, T5, TResult>(T1 arg1, T2 arg2, T3 arg3, out T4 arg4, T5 arg5 = default(T5));
namespace Toggles;

[ResonitePlugin("dev.lecloutpanda.Toggles", "Toggles", "1.1.0", "LeCloutPanda, NepuShiro, art0007i", "https://github.com/lecloutpanda/Toggles")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BasePlugin
{
	[HarmonyPatch]
	public static class WikiIntegrationPatches
	{
		[CompilerGenerated]
		private sealed class <InspectorTranspiler>d__1 : global::System.Collections.Generic.IEnumerable<CodeInstruction>, global::System.Collections.IEnumerable, global::System.Collections.Generic.IEnumerator<CodeInstruction>, global::System.Collections.IEnumerator, global::System.IDisposable
		{
			private int <>1__state;

			private CodeInstruction <>2__current;

			private int <>l__initialThreadId;

			private global::System.Collections.Generic.IEnumerable<CodeInstruction> codes;

			public global::System.Collections.Generic.IEnumerable<CodeInstruction> <>3__codes;

			private bool <found>5__2;

			private global::System.Collections.Generic.IEnumerator<CodeInstruction> <>7__wrap2;

			CodeInstruction global::System.Collections.Generic.IEnumerator<CodeInstruction>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object global::System.Collections.IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <InspectorTranspiler>d__1(int <>1__state)
			{
				this.<>1__state = <>1__state;
				<>l__initialThreadId = Environment.CurrentManagedThreadId;
			}

			[DebuggerHidden]
			void global::System.IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || (uint)(num - 1) <= 1u)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<>7__wrap2 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_006a: Unknown result type (might be due to invalid IL or missing references)
				//IL_008f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0099: Expected O, but got Unknown
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<found>5__2 = false;
						<>7__wrap2 = codes.GetEnumerator();
						<>1__state = -3;
						break;
					case 1:
						<>1__state = -3;
						break;
					case 2:
						<>1__state = -3;
						break;
					}
					if (((global::System.Collections.IEnumerator)<>7__wrap2).MoveNext())
					{
						CodeInstruction current = <>7__wrap2.Current;
						if (CodeInstructionExtensions.Calls(current, wikiFunc))
						{
							<found>5__2 = true;
							<>2__current = new CodeInstruction(OpCodes.Call, (object)((global::System.Delegate)(object)new Func<Slot, global::System.Type, Hyperlink>(FakeWikiFuncInspector)).Method);
							<>1__state = 1;
							return true;
						}
						<>2__current = current;
						<>1__state = 2;
						return true;
					}
					<>m__Finally1();
					<>7__wrap2 = null;
					if (!<found>5__2)
					{
						Log.LogError((object)"Failed to patch WikiIntegrationComponentPatch");
					}
					return false;
				}
				catch
				{
					//try-fault
					((global::System.IDisposable)this).Dispose();
					throw;
				}
			}

			bool global::System.Collections.IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<>7__wrap2 != null)
				{
					((global::System.IDisposable)<>7__wrap2).Dispose();
				}
			}

			[DebuggerHidden]
			void global::System.Collections.IEnumerator.Reset()
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				throw new NotSupportedException();
			}

			[DebuggerHidden]
			global::System.Collections.Generic.IEnumerator<CodeInstruction> global::System.Collections.Generic.IEnumerable<CodeInstruction>.GetEnumerator()
			{
				<InspectorTranspiler>d__1 <InspectorTranspiler>d__;
				if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
				{
					<>1__state = 0;
					<InspectorTranspiler>d__ = this;
				}
				else
				{
					<InspectorTranspiler>d__ = new <InspectorTranspiler>d__1(0);
				}
				<InspectorTranspiler>d__.codes = <>3__codes;
				return <InspectorTranspiler>d__;
			}

			[DebuggerHidden]
			global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator()
			{
				return (global::System.Collections.IEnumerator)((global::System.Collections.Generic.IEnumerable<CodeInstruction>)this).GetEnumerator();
			}
		}

		[CompilerGenerated]
		private sealed class <ProtofluxToolTranspiler>d__2 : global::System.Collections.Generic.IEnumerable<CodeInstruction>, global::System.Collections.IEnumerable, global::System.Collections.Generic.IEnumerator<CodeInstruction>, global::System.Collections.IEnumerator, global::System.IDisposable
		{
			private int <>1__state;

			private CodeInstruction <>2__current;

			private int <>l__initialThreadId;

			private global::System.Collections.Generic.IEnumerable<CodeInstruction> codes;

			public global::System.Collections.Generic.IEnumerable<CodeInstruction> <>3__codes;

			private bool <found>5__2;

			private global::System.Collections.Generic.IEnumerator<CodeInstruction> <>7__wrap2;

			CodeInstruction global::System.Collections.Generic.IEnumerator<CodeInstruction>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object global::System.Collections.IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <ProtofluxToolTranspiler>d__2(int <>1__state)
			{
				this.<>1__state = <>1__state;
				<>l__initialThreadId = Environment.CurrentManagedThreadId;
			}

			[DebuggerHidden]
			void global::System.IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || (uint)(num - 1) <= 1u)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<>7__wrap2 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_006a: Unknown result type (might be due to invalid IL or missing references)
				//IL_008f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0099: Expected O, but got Unknown
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<found>5__2 = false;
						<>7__wrap2 = codes.GetEnumerator();
						<>1__state = -3;
						break;
					case 1:
						<>1__state = -3;
						break;
					case 2:
						<>1__state = -3;
						break;
					}
					if (((global::System.Collections.IEnumerator)<>7__wrap2).MoveNext())
					{
						CodeInstruction current = <>7__wrap2.Current;
						if (CodeInstructionExtensions.Calls(current, wikiFunc))
						{
							<found>5__2 = true;
							<>2__current = new CodeInstruction(OpCodes.Call, (object)((global::System.Delegate)(object)new Func<Slot, global::System.Type, Hyperlink>(FakeWikiFuncProtoflux)).Method);
							<>1__state = 1;
							return true;
						}
						<>2__current = current;
						<>1__state = 2;
						return true;
					}
					<>m__Finally1();
					<>7__wrap2 = null;
					if (!<found>5__2)
					{
						Log.LogError((object)"Failed to patch ProtofluxPatch");
					}
					return false;
				}
				catch
				{
					//try-fault
					((global::System.IDisposable)this).Dispose();
					throw;
				}
			}

			bool global::System.Collections.IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<>7__wrap2 != null)
				{
					((global::System.IDisposable)<>7__wrap2).Dispose();
				}
			}

			[DebuggerHidden]
			void global::System.Collections.IEnumerator.Reset()
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				throw new NotSupportedException();
			}

			[DebuggerHidden]
			global::System.Collections.Generic.IEnumerator<CodeInstruction> global::System.Collections.Generic.IEnumerable<CodeInstruction>.GetEnumerator()
			{
				<ProtofluxToolTranspiler>d__2 <ProtofluxToolTranspiler>d__;
				if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
				{
					<>1__state = 0;
					<ProtofluxToolTranspiler>d__ = this;
				}
				else
				{
					<ProtofluxToolTranspiler>d__ = new <ProtofluxToolTranspiler>d__2(0);
				}
				<ProtofluxToolTranspiler>d__.codes = <>3__codes;
				return <ProtofluxToolTranspiler>d__;
			}

			[DebuggerHidden]
			global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator()
			{
				return (global::System.Collections.IEnumerator)((global::System.Collections.Generic.IEnumerable<CodeInstruction>)this).GetEnumerator();
			}
		}

		private static MethodInfo wikiFunc = AccessTools.Method(typeof(Hyperlink), "AttachForWikiPage", (global::System.Type[])null, (global::System.Type[])null);

		[IteratorStateMachine(typeof(<InspectorTranspiler>d__1))]
		[HarmonyPatch(typeof(WorkerInspector), "BuildUIForComponent")]
		[HarmonyTranspiler]
		public static global::System.Collections.Generic.IEnumerable<CodeInstruction> InspectorTranspiler(global::System.Collections.Generic.IEnumerable<CodeInstruction> codes)
		{
			bool found = false;
			global::System.Collections.Generic.IEnumerator<CodeInstruction> enumerator = codes.GetEnumerator();
			try
			{
				while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
				{
					CodeInstruction current = enumerator.Current;
					if (CodeInstructionExtensions.Calls(current, wikiFunc))
					{
						found = true;
						yield return new CodeInstruction(OpCodes.Call, (object)((global::System.Delegate)(object)new Func<Slot, global::System.Type, Hyperlink>(FakeWikiFuncInspector)).Method);
					}
					else
					{
						yield return current;
					}
				}
			}
			finally
			{
				((global::System.IDisposable)enumerator)?.Dispose();
			}
			if (!found)
			{
				Log.LogError((object)"Failed to patch WikiIntegrationComponentPatch");
			}
		}

		[IteratorStateMachine(typeof(<ProtofluxToolTranspiler>d__2))]
		[HarmonyPatch(typeof(ProtoFluxTool), "GenerateMenuItems")]
		[HarmonyTranspiler]
		public static global::System.Collections.Generic.IEnumerable<CodeInstruction> ProtofluxToolTranspiler(global::System.Collections.Generic.IEnumerable<CodeInstruction> codes)
		{
			bool found = false;
			global::System.Collections.Generic.IEnumerator<CodeInstruction> enumerator = codes.GetEnumerator();
			try
			{
				while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
				{
					CodeInstruction current = enumerator.Current;
					if (CodeInstructionExtensions.Calls(current, wikiFunc))
					{
						found = true;
						yield return new CodeInstruction(OpCodes.Call, (object)((global::System.Delegate)(object)new Func<Slot, global::System.Type, Hyperlink>(FakeWikiFuncProtoflux)).Method);
					}
					else
					{
						yield return current;
					}
				}
			}
			finally
			{
				((global::System.IDisposable)enumerator)?.Dispose();
			}
			if (!found)
			{
				Log.LogError((object)"Failed to patch ProtofluxPatch");
			}
		}

		public static Hyperlink? FakeWikiFuncInspector(Slot slot, global::System.Type type)
		{
			if (WIKI_INTEGRATION_INSPECTOR.Value)
			{
				return Hyperlink.AttachForWikiPage(slot, type);
			}
			slot.Destroy();
			return null;
		}

		public static Hyperlink? FakeWikiFuncProtoflux(Slot slot, global::System.Type type)
		{
			if (WIKI_INTEGRATION_PROTOFLUX.Value)
			{
				return Hyperlink.AttachForWikiPage(slot, type);
			}
			slot.Destroy();
			return null;
		}
	}

	[HarmonyPatch(typeof(InventoryBrowser))]
	public static class InventoryBrowserPatch
	{
		[HarmonyPatch("OnItemSelected")]
		[HarmonyPostfix]
		public static void Postfix(SyncRef<Button> ____addCurrentAvatar, SyncRef<Button> ____copyLink)
		{
			try
			{
				if (!INVENTORY_SAVE_AVATAR_BUTTON.Value)
				{
					Button target = ____addCurrentAvatar.Target;
					if (target != null)
					{
						((Component)target).Slot.ActiveSelf = false;
					}
				}
				if (!INVENTORY_GET_URL_BUTTON.Value)
				{
					Button target2 = ____copyLink.Target;
					if (target2 != null)
					{
						((Component)target2).Slot.ActiveSelf = false;
					}
				}
			}
			catch (global::System.Exception ex)
			{
				Log.LogError((object)ex);
			}
		}
	}

	[HarmonyPatch(typeof(ProtoFluxTool), "GenerateMenuItems")]
	private class HideOverviewPatch
	{
		private static readonly MethodInfo ToggleOverviewMethod = AccessTools.Method(typeof(ProtoFluxTool), "ToggleOverviewMode", (global::System.Type[])null, (global::System.Type[])null);

		[HarmonyTranspiler]
		private static global::System.Collections.Generic.IEnumerable<CodeInstruction> Transpiler(global::System.Collections.Generic.IEnumerable<CodeInstruction> codes, ILGenerator generator)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			//IL_00bc: 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_00ce: Expected O, but got Unknown
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Expected O, but got Unknown
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Expected O, but got Unknown
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Expected O, but got Unknown
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Expected O, but got Unknown
			MethodInfo val = AccessTools.Method(typeof(ContextMenu), "AddItem", new global::System.Type[4]
			{
				typeof(LocaleString).MakeByRefType(),
				typeof(Uri),
				typeof(colorX?).MakeByRefType(),
				typeof(ButtonEventHandler)
			}, (global::System.Type[])null);
			List<CodeInstruction> val2 = Enumerable.ToList<CodeInstruction>(codes);
			CodeMatcher val3 = new CodeMatcher((global::System.Collections.Generic.IEnumerable<CodeInstruction>)val2, generator);
			val3.MatchStartForward((CodeMatch[])(object)new CodeMatch[2]
			{
				new CodeMatch((OpCode?)OpCodes.Ldarg_2, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldstr, (object)"Tools.ProtoFlux.Overview", (string)null)
			});
			if (!val3.IsValid)
			{
				return (global::System.Collections.Generic.IEnumerable<CodeInstruction>)val2;
			}
			int pos = val3.Pos;
			val3.MatchEndForward((CodeMatch[])(object)new CodeMatch[2]
			{
				new CodeMatch((OpCode?)OpCodes.Callvirt, (object)val, (string)null),
				new CodeMatch((OpCode?)OpCodes.Pop, (object)null, (string)null)
			});
			if (!val3.IsValid)
			{
				return (global::System.Collections.Generic.IEnumerable<CodeInstruction>)val2;
			}
			int pos2 = val3.Pos;
			val3.Start().Advance(pos).RemoveInstructions(pos2 - pos + 1)
				.Insert((CodeInstruction[])(object)new CodeInstruction[3]
				{
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					new CodeInstruction(OpCodes.Ldarg_2, (object)null),
					new CodeInstruction(OpCodes.Call, (object)((global::System.Delegate)(object)new Action<ProtoFluxTool, ContextMenu>(AddItemProxy)).Method)
				});
			return val3.InstructionEnumeration();
		}

		private static void AddItemProxy(ProtoFluxTool tool, ContextMenu menu)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (PROTOFLUX_OVERVIEW_BUTTON.Value && menu != null)
				{
					LocaleString val = LocaleHelper.AsLocaleKey("Tools.ProtoFlux.Overview", (string)null, true, (Dictionary<string, object>)null);
					colorX? val2 = new colorX(1f, 1f, 0f, 1f, (ColorProfile)1);
					menu.AddItem(ref val, (Uri)null, ref val2, ToggleOverviewMethod.CreateDelegate<ButtonEventHandler>((object)tool));
				}
			}
			catch (global::System.Exception ex)
			{
				Log.LogError((object)ex);
			}
		}
	}

	[HarmonyPatch]
	public static class DevToolPatches
	{
		[HarmonyPatch]
		public static class DevToolAddItemPatch
		{
			private static MethodBase TargetMethod()
			{
				return (MethodBase)(object)AccessTools.Method(typeof(ContextMenu), "AddItem", new global::System.Type[4]
				{
					typeof(LocaleString).MakeByRefType(),
					typeof(Uri),
					typeof(colorX?).MakeByRefType(),
					typeof(ButtonEventHandler)
				}, (global::System.Type[])null);
			}

			[HarmonyPostfix]
			private static void Postfix(ContextMenu __instance, in LocaleString label, Uri? icon, in colorX? color, ButtonEventHandler action)
			{
				//IL_0052: Unknown result type (might be due to invalid IL or missing references)
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_007c: 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_008e: Expected O, but got Unknown
				//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00af: Expected O, but got Unknown
				if (__instance == null || !((Component)__instance).Slot.ActiveUser.IsLocalUser || !DEVTOOL_GIZMOSNAPPING_BUTTON.Value || label.content != "Tools.Dev.Scale" || Dynvar == null)
				{
					return;
				}
				LocaleString val = LocaleLoader.T("Settings.dev.lecloutpanda.Toggles.DevTool.GizmoSnapping", "Toggle Gizmo Snapping", true, (Dictionary<string, object>)null);
				Uri val2 = new Uri("resdb:///2cc67da92ecbf3ff611e177f8e53aca5d535dd6339f0779b3dc8d660ed0585c3.png");
				colorX? val3 = (Sync<bool>.op_Implicit(Dynvar.Value) ? colorX.Green : colorX.Red);
				ContextMenuItem item = __instance.AddItem(ref val, val2, ref val3);
				item.Button.LocalPressed += (ButtonEventHandler)delegate
				{
					//IL_002e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0057: Unknown result type (might be due to invalid IL or missing references)
					//IL_0050: Unknown result type (might be due to invalid IL or missing references)
					if (Dynvar != null)
					{
						DevTool? tool = _tool;
						if (tool != null)
						{
							DynamicVariableHelper.WriteDynamicVariable<bool>(((Component)tool).Slot, "Mod.Toggles/ToggleGizmoSnapping", !Sync<bool>.op_Implicit(Dynvar.Value));
						}
						((SyncField<colorX>)(object)item.Color).Value = (Sync<bool>.op_Implicit(Dynvar.Value) ? colorX.Green : colorX.Red);
						DEVTOOL_GIZMOSNAPPING_VALUE.Value = Sync<bool>.op_Implicit(Dynvar.Value);
					}
				};
			}
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Action<ITool> <>9__13_2;

			public static Action<World> <>9__13_1;

			public static EventHandler <>9__13_0;

			public static Predicate<DynamicVariableSpace> <>9__14_1;

			public static Predicate<DynamicValueVariable<bool>> <>9__14_2;

			internal void <InitSubs>b__13_0(object? _, EventArgs _)
			{
				List<World> val = Pool.BorrowList<World>();
				Engine.Current.WorldManager.GetWorlds(val);
				CollectionExtensions.Do<World>((global::System.Collections.Generic.IEnumerable<World>)val, (Action<World>)delegate(World w)
				{
					CollectionExtensions.Do<ITool>(InteractionHandlerExtensions.GetActiveTools(w.LocalUser), (Action<ITool>)delegate(ITool t)
					{
						//IL_0043: Unknown result type (might be due to invalid IL or missing references)
						if (t != null && ((IComponent)t).Slot.ActiveUser.IsLocalUser)
						{
							Slot slot = ((IComponent)t).Slot;
							ToolMultiplexer val2 = (ToolMultiplexer)(object)((t is ToolMultiplexer) ? t : null);
							if (val2 != null)
							{
								slot = ((IComponent)val2.ActiveTool).Slot;
							}
							DynamicVariableHelper.WriteDynamicVariable<bool>(slot, "Mod.Toggles/ToggleGizmoSnapping", DEVTOOL_GIZMOSNAPPING_VALUE.Value);
						}
					});
				});
			}

			internal void <InitSubs>b__13_1(World w)
			{
				CollectionExtensions.Do<ITool>(InteractionHandlerExtensions.GetActiveTools(w.LocalUser), (Action<ITool>)delegate(ITool t)
				{
					//IL_0043: Unknown result type (might be due to invalid IL or missing references)
					if (t != null && ((IComponent)t).Slot.ActiveUser.IsLocalUser)
					{
						Slot slot = ((IComponent)t).Slot;
						ToolMultiplexer val = (ToolMultiplexer)(object)((t is ToolMultiplexer) ? t : null);
						if (val != null)
						{
							slot = ((IComponent)val.ActiveTool).Slot;
						}
						DynamicVariableHelper.WriteDynamicVariable<bool>(slot, "Mod.Toggles/ToggleGizmoSnapping", DEVTOOL_GIZMOSNAPPING_VALUE.Value);
					}
				});
			}

			internal void <InitSubs>b__13_2(ITool t)
			{
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				if (t != null && ((IComponent)t).Slot.ActiveUser.IsLocalUser)
				{
					Slot slot = ((IComponent)t).Slot;
					ToolMultiplexer val = (ToolMultiplexer)(object)((t is ToolMultiplexer) ? t : null);
					if (val != null)
					{
						slot = ((IComponent)val.ActiveTool).Slot;
					}
					DynamicVariableHelper.WriteDynamicVariable<bool>(slot, "Mod.Toggles/ToggleGizmoSnapping", DEVTOOL_GIZMOSNAPPING_VALUE.Value);
				}
			}

			internal bool <SetupDynvars>b__14_1(DynamicVariableSpace x)
			{
				return ((SyncField<string>)(object)x.SpaceName).Value == "Mod.Toggles";
			}

			internal bool <SetupDynvars>b__14_2(DynamicValueVariable<bool> x)
			{
				return ((SyncField<string>)(object)((DynamicVariableBase<bool>)(object)x).VariableName).Value == "Mod.Toggles/ToggleGizmoSnapping";
			}
		}

		[CompilerGenerated]
		private sealed class <ToggleSnappingTranspiler>d__16 : global::System.Collections.Generic.IEnumerable<CodeInstruction>, global::System.Collections.IEnumerable, global::System.Collections.Generic.IEnumerator<CodeInstruction>, global::System.Collections.IEnumerator, global::System.IDisposable
		{
			private int <>1__state;

			private CodeInstruction <>2__current;

			private int <>l__initialThreadId;

			private global::System.Collections.Generic.IEnumerable<CodeInstruction> codes;

			public global::System.Collections.Generic.IEnumerable<CodeInstruction> <>3__codes;

			private MethodInfo <lookFor>5__2;

			private bool <found>5__3;

			private global::System.Collections.Generic.IEnumerator<CodeInstruction> <>7__wrap3;

			CodeInstruction global::System.Collections.Generic.IEnumerator<CodeInstruction>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object global::System.Collections.IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <ToggleSnappingTranspiler>d__16(int <>1__state)
			{
				this.<>1__state = <>1__state;
				<>l__initialThreadId = Environment.CurrentManagedThreadId;
			}

			[DebuggerHidden]
			void global::System.IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || (uint)(num - 1) <= 1u)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<lookFor>5__2 = null;
				<>7__wrap3 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_008a: 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_00b9: Expected O, but got Unknown
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<lookFor>5__2 = AccessTools.Method(typeof(SnapHelper), "GetBestSnapPoint", (global::System.Type[])null, (global::System.Type[])null);
						<found>5__3 = false;
						<>7__wrap3 = codes.GetEnumerator();
						<>1__state = -3;
						break;
					case 1:
						<>1__state = -3;
						break;
					case 2:
						<>1__state = -3;
						break;
					}
					if (((global::System.Collections.IEnumerator)<>7__wrap3).MoveNext())
					{
						CodeInstruction current = <>7__wrap3.Current;
						if (CodeInstructionExtensions.Calls(current, <lookFor>5__2))
						{
							<found>5__3 = true;
							<>2__current = new CodeInstruction(OpCodes.Call, (object)((global::System.Delegate)new <>f__AnonymousDelegate0<World, float3, float, IPointSnappable, Predicate<IPointSnappable>, float3?>(BestSnapPointDummy)).Method);
							<>1__state = 1;
							return true;
						}
						<>2__current = current;
						<>1__state = 2;
						return true;
					}
					<>m__Finally1();
					<>7__wrap3 = null;
					if (!<found>5__3)
					{
						Log.LogError((object)"Failed to patch ToggleSnappingTranspiler");
					}
					return false;
				}
				catch
				{
					//try-fault
					((global::System.IDisposable)this).Dispose();
					throw;
				}
			}

			bool global::System.Collections.IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<>7__wrap3 != null)
				{
					((global::System.IDisposable)<>7__wrap3).Dispose();
				}
			}

			[DebuggerHidden]
			void global::System.Collections.IEnumerator.Reset()
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				throw new NotSupportedException();
			}

			[DebuggerHidden]
			global::System.Collections.Generic.IEnumerator<CodeInstruction> global::System.Collections.Generic.IEnumerable<CodeInstruction>.GetEnumerator()
			{
				<ToggleSnappingTranspiler>d__16 <ToggleSnappingTranspiler>d__;
				if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
				{
					<>1__state = 0;
					<ToggleSnappingTranspiler>d__ = this;
				}
				else
				{
					<ToggleSnappingTranspiler>d__ = new <ToggleSnappingTranspiler>d__16(0);
				}
				<ToggleSnappingTranspiler>d__.codes = <>3__codes;
				return <ToggleSnappingTranspiler>d__;
			}

			[DebuggerHidden]
			global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator()
			{
				return (global::System.Collections.IEnumerator)((global::System.Collections.Generic.IEnumerable<CodeInstruction>)this).GetEnumerator();
			}
		}

		private const string DynvarSpaceName = "Mod.Toggles";

		private const string DynvarName = "Mod.Toggles/ToggleGizmoSnapping";

		private static DevTool? _tool;

		[field: CompilerGenerated]
		private static DynamicVariableSpace? DynvarSpace
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			set;
		}

		[field: CompilerGenerated]
		private static DynamicValueVariable<bool>? Dynvar
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			set;
		}

		private static bool ShouldSnap => ((SyncField<bool>)(object)Dynvar?.Value).Value ?? true;

		internal static void InitSubs()
		{
			//IL_0019: 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_0024: Expected O, but got Unknown
			ConfigEntry<bool> dEVTOOL_GIZMOSNAPPING_VALUE = DEVTOOL_GIZMOSNAPPING_VALUE;
			object obj = <>c.<>9__13_0;
			if (obj == null)
			{
				EventHandler val = delegate
				{
					List<World> val2 = Pool.BorrowList<World>();
					Engine.Current.WorldManager.GetWorlds(val2);
					CollectionExtensions.Do<World>((global::System.Collections.Generic.IEnumerable<World>)val2, (Action<World>)delegate(World w)
					{
						CollectionExtensions.Do<ITool>(InteractionHandlerExtensions.GetActiveTools(w.LocalUser), (Action<ITool>)delegate(ITool t)
						{
							//IL_0043: Unknown result type (might be due to invalid IL or missing references)
							if (t != null && ((IComponent)t).Slot.ActiveUser.IsLocalUser)
							{
								Slot slot = ((IComponent)t).Slot;
								ToolMultiplexer val3 = (ToolMultiplexer)(object)((t is ToolMultiplexer) ? t : null);
								if (val3 != null)
								{
									slot = ((IComponent)val3.ActiveTool).Slot;
								}
								DynamicVariableHelper.WriteDynamicVariable<bool>(slot, "Mod.Toggles/ToggleGizmoSnapping", DEVTOOL_GIZMOSNAPPING_VALUE.Value);
							}
						});
					});
				};
				<>c.<>9__13_0 = val;
				obj = (object)val;
			}
			dEVTOOL_GIZMOSNAPPING_VALUE.SettingChanged += (EventHandler)obj;
		}

		[HarmonyPatch(typeof(DevTool), "OnEquipped")]
		[HarmonyPostfix]
		private static void SetupDynvars(DevTool __instance)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			if (__instance == null || ((Component)__instance).Slot.ActiveUser != ((Worker)__instance).LocalUser || WorldExtensions.IsUserspace(((Worker)__instance).World))
			{
				return;
			}
			_tool = __instance;
			((ComponentBase<Component>)(object)__instance).RunInUpdates(3, (Action)delegate
			{
				DynvarSpace = ((ContainerWorker<Component>)(object)((Component)__instance).Slot).GetComponentOrAttach<DynamicVariableSpace>((Predicate<DynamicVariableSpace>)((DynamicVariableSpace x) => ((SyncField<string>)(object)x.SpaceName).Value == "Mod.Toggles"));
				if (DynvarSpace != null)
				{
					((ComponentBase<Component>)(object)DynvarSpace).Persistent = false;
					((SyncField<string>)(object)DynvarSpace.SpaceName).Value = "Mod.Toggles";
					((SyncField<bool>)(object)DynvarSpace.OnlyDirectBinding).Value = true;
					Dynvar = ((ContainerWorker<Component>)(object)((Component)__instance).Slot).GetComponentOrAttach<DynamicValueVariable<bool>>((Predicate<DynamicValueVariable<bool>>)((DynamicValueVariable<bool> x) => ((SyncField<string>)(object)((DynamicVariableBase<bool>)(object)x).VariableName).Value == "Mod.Toggles/ToggleGizmoSnapping"));
					if (Dynvar != null)
					{
						((ComponentBase<Component>)(object)Dynvar).Persistent = false;
						((SyncField<string>)(object)((DynamicVariableBase<bool>)(object)Dynvar).VariableName).Value = "Mod.Toggles/ToggleGizmoSnapping";
						((SyncField<bool>)(object)Dynvar.Value).Value = DEVTOOL_GIZMOSNAPPING_VALUE.Value;
					}
				}
			});
		}

		[IteratorStateMachine(typeof(<ToggleSnappingTranspiler>d__16))]
		[HarmonyPatch(typeof(Gizmo), "UpdatePoint", new global::System.Type[]
		{
			typeof(Component),
			typeof(float3),
			typeof(float3)
		})]
		[HarmonyTranspiler]
		public static global::System.Collections.Generic.IEnumerable<CodeInstruction> ToggleSnappingTranspiler(global::System.Collections.Generic.IEnumerable<CodeInstruction> codes)
		{
			MethodInfo lookFor = AccessTools.Method(typeof(SnapHelper), "GetBestSnapPoint", (global::System.Type[])null, (global::System.Type[])null);
			bool found = false;
			global::System.Collections.Generic.IEnumerator<CodeInstruction> enumerator = codes.GetEnumerator();
			try
			{
				while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
				{
					CodeInstruction current = enumerator.Current;
					if (CodeInstructionExtensions.Calls(current, lookFor))
					{
						found = true;
						yield return new CodeInstruction(OpCodes.Call, (object)((global::System.Delegate)new <>f__AnonymousDelegate0<World, float3, float, IPointSnappable, Predicate<IPointSnappable>, float3?>(BestSnapPointDummy)).Method);
					}
					else
					{
						yield return current;
					}
				}
			}
			finally
			{
				((global::System.IDisposable)enumerator)?.Dispose();
			}
			if (!found)
			{
				Log.LogError((object)"Failed to patch ToggleSnappingTranspiler");
			}
		}

		private static float3? BestSnapPointDummy(World world, float3 globalPoint, float checkRadius, out IPointSnappable snappable, Predicate<IPointSnappable> snappableFilter = null)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			if (!ShouldSnap)
			{
				snappable = null;
				return null;
			}
			return SnapHelper.GetBestSnapPoint(world, globalPoint, checkRadius, ref snappable, snappableFilter);
		}
	}

	[HarmonyPatch]
	public static class ContactsPagePatches
	{
		[HarmonyPatch(typeof(ContactItem), "Update", new global::System.Type[]
		{
			typeof(Contact),
			typeof(ContactData)
		})]
		private class ContactItemUpdatePatch
		{
			public static void Postfix(Contact contact, ContactData data, SyncRef<Button> ____joinButton)
			{
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Invalid comparison between Unknown and I4
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				if (!CONTACT_ASK_TO_JOIN_BUTTON.Value && contact.IsAccepted && (int)contact.ContactStatus == 5 && data != null && data.CurrentSessionInfo == null && (int)data.CurrentStatus.OnlineStatus.GetValueOrDefault() != 0 && ____joinButton != null)
				{
					Button target = ____joinButton.Target;
					if (target != null)
					{
						((Component)target).Slot.ActiveSelf = false;
					}
				}
			}
		}
	}

	internal static ManualLogSource Log;

	private static ConfigEntry<bool> INVENTORY_SAVE_AVATAR_BUTTON;

	private static ConfigEntry<bool> INVENTORY_GET_URL_BUTTON;

	private static ConfigEntry<bool> PROTOFLUX_OVERVIEW_BUTTON;

	private static ConfigEntry<bool> DEVTOOL_GIZMOSNAPPING_BUTTON;

	private static ConfigEntry<bool> DEVTOOL_GIZMOSNAPPING_VALUE;

	private static ConfigEntry<bool> CONTACT_ASK_TO_JOIN_BUTTON;

	private static ConfigEntry<bool> WIKI_INTEGRATION_INSPECTOR;

	private static ConfigEntry<bool> WIKI_INTEGRATION_PROTOFLUX;

	public override void Load()
	{
		//IL_003f: 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_0054: Expected O, but got Unknown
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Expected O, but got Unknown
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Expected O, but got Unknown
		//IL_0108: 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)
		//IL_011d: Expected O, but got Unknown
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Expected O, but got Unknown
		//IL_018e: 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_01a3: Expected O, but got Unknown
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Expected O, but got Unknown
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0229: Expected O, but got Unknown
		Log = ((BasePlugin)this).Log;
		((BasePlugin)this).HarmonyInstance.PatchAll();
		INVENTORY_SAVE_AVATAR_BUTTON = ((BasePlugin)this).Config.Bind<bool>("Inventory", "Inventory Save Avatar Button", true, new ConfigDescription("Toggle generation of 'Save Avatar' button in inventory", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.Toggles.Inventory.ToggleSaveAvatarButton", "Settings.dev.lecloutpanda.Toggles.Inventory.ToggleSaveAvatarButton.Description") }));
		INVENTORY_GET_URL_BUTTON = ((BasePlugin)this).Config.Bind<bool>("Inventory", "Inventory Get Item Url Button", true, new ConfigDescription("Toggle generation of 'Get Url' button in inventory", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.Toggles.Inventory.ToggleGetUrlButton", "Settings.dev.lecloutpanda.Toggles.Inventory.ToggleGetUrlButton.Description") }));
		PROTOFLUX_OVERVIEW_BUTTON = ((BasePlugin)this).Config.Bind<bool>("Protoflux Tool", "Overview Button", true, new ConfigDescription("Toggle generation of 'Overview' context menu button on protoflux tools", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.Toggles.ProtofluxTool.ToggleOverviewButton", "Settings.dev.lecloutpanda.Toggles.ProtofluxTool.ToggleOverviewButton.Description") }));
		DEVTOOL_GIZMOSNAPPING_BUTTON = ((BasePlugin)this).Config.Bind<bool>("Dev Tool", "Gizmo Snapping Button", true, new ConfigDescription("Toggle generation of a 'Gizmo Snapping' context menu button in the 'Gizmo Options' menu on a Dev Tool", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.Toggles.DevTool.ToggleGizmoSnappingButton", "Settings.dev.lecloutpanda.Toggles.DevTool.ToggleGizmoSnappingButton.Description") }));
		DEVTOOL_GIZMOSNAPPING_VALUE = ((BasePlugin)this).Config.Bind<bool>("Dev Tool", "Default Gizmo Snapping Value", true, new ConfigDescription("Default value for 'Gizmo Snapping'", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.Toggles.DevTool.DefaultGizmoSnappingValue", "Settings.dev.lecloutpanda.Toggles.DevTool.DefaultGizmoSnappingValue.Description") }));
		CONTACT_ASK_TO_JOIN_BUTTON = ((BasePlugin)this).Config.Bind<bool>("Contacts", "Ask To Join Button", true, new ConfigDescription("Toggle Visibility of 'Ask To Join' button", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.Toggles.Contacts.ToggleAskToJoinButton", "Settings.dev.lecloutpanda.Toggles.Contacts.ToggleAskToJoinButton.Description") }));
		WIKI_INTEGRATION_INSPECTOR = ((BasePlugin)this).Config.Bind<bool>("Misc", "Wiki Integration Inspector", true, new ConfigDescription("Toggle 'Wiki Hyperlink' button for components in inspectors", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.Toggles.Misc.ToggleWikiIntegrationInspector", "Settings.dev.lecloutpanda.Toggles.Misc.ToggleWikiIntegrationInspector.Description") }));
		WIKI_INTEGRATION_PROTOFLUX = ((BasePlugin)this).Config.Bind<bool>("Misc", "Wiki Integration Protoflux", true, new ConfigDescription("Toggle 'Wiki Hyperlink' button for the protoflux tool context menu item", (AcceptableValueBase)null, new object[1] { (object)new ConfigLocale("Settings.dev.lecloutpanda.Toggles.Misc.ToggleWikiIntegrationProtoflux", "Settings.dev.lecloutpanda.Toggles.Misc.ToggleWikiIntegrationProtoflux.Description") }));
		DevToolPatches.InitSubs();
	}
}
public static class PluginMetadata
{
	public const string GUID = "dev.lecloutpanda.Toggles";

	public const string NAME = "Toggles";

	public const string VERSION = "1.1.0";

	public const string AUTHORS = "LeCloutPanda, NepuShiro, art0007i";

	public const string REPOSITORY_URL = "https://github.com/lecloutpanda/Toggles";
}