Decompiled source of ArrayEditor v1.0.2

plugins/BepisArrayEditor/BepisArrayEditor.dll

Decompiled 15 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
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=v10.0", FrameworkDisplayName = ".NET 10.0")]
[assembly: AssemblyCompany("Gyztor Mizirath")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+80b8f00e832bb50e2bd6eeae181f1b980c075c26")]
[assembly: AssemblyProduct("BepisArrayEditor")]
[assembly: AssemblyTitle("BepisArrayEditor")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/Gyztor/BepisArrayEditor")]
[assembly: AssemblyVersion("1.0.2.0")]
[module: RefSafetyRules(11)]
namespace BepisArrayEditor;

[HarmonyPatch]
[HarmonyPatchCategory("ListUIImprovements")]
internal sealed class ListUIImprovements
{
	[HarmonyPatch(typeof(ListEditor), "BuildListElement")]
	private static bool Prefix(UIBuilder ui)
	{
		if (BepisArrayEditor.ArrayEditorListUIImprovemts.Value)
		{
			ui.Style.MinHeight = 24f;
		}
		return true;
	}

	[HarmonyPatch(typeof(SyncMemberEditorBuilder), "GenerateMemberField")]
	private static bool Prefix(ISyncMember member, UIBuilder ui)
	{
		if (!BepisArrayEditor.ArrayEditorListUIImprovemts.Value || !(((IWorldElement)member).Parent is ISyncList) || !(member is SyncObject))
		{
			return true;
		}
		((ContainerWorker<Component>)(object)((Component)ui.CurrentRect).Slot).AttachComponent<HorizontalLayout>(true, (Action<HorizontalLayout>)null);
		LayoutElement component = ((ContainerWorker<Component>)(object)((Component)ui.CurrentRect).Slot).GetComponent<LayoutElement>((Predicate<LayoutElement>)null, false);
		if (component != null)
		{
			((SyncField<float>)(object)component.MinWidth).Value = 48f;
			((SyncField<float>)(object)component.FlexibleWidth).Value = -1f;
		}
		return true;
	}
}
[ResonitePlugin("xyz.gyztormizirath.BepisArrayEditor", "BepisArrayEditor", "1.0.2", "Gyztor Mizirath", "https://github.com/Gyztor/BepisArrayEditor")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class BepisArrayEditor : BasePlugin
{
	[HarmonyPatch(typeof(SyncMemberEditorBuilder), "BuildArray")]
	internal sealed class ArrayEditor
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Func<Point<float3>, TubePoint> <>9__14_2;

			public static Action<Component> <>9__20_4;

			public static Action <>9__24_0;

			public static Action <>9__24_1;

			public static Action <>9__24_2;

			internal TubePoint <AddTubePointProxying>b__14_2(Point<float3> point)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				return new TubePoint(((SyncField<float3>)(object)point.Value).Value, ((SyncField<float>)(object)point.Position).Value);
			}

			internal void <Prefix>b__20_4(Component c)
			{
				((ComponentBase<Component>)(object)c).Destroy();
			}

			internal void <ArrayChanged>b__24_0()
			{
				_skipListChanges = false;
			}

			internal void <ArrayChanged>b__24_1()
			{
				_skipListChanges = false;
			}

			internal void <ArrayChanged>b__24_2()
			{
				_skipListChanges = false;
			}
		}

		private static readonly MethodInfo _addCurveValueProxying = AccessTools.Method(typeof(ArrayEditor), "AddCurveValueProxying", (global::System.Type[])null, (global::System.Type[])null);

		private static readonly MethodInfo _addLinearValueProxying = AccessTools.Method(typeof(ArrayEditor), "AddLinearValueProxying", (global::System.Type[])null, (global::System.Type[])null);

		private static readonly MethodInfo _addListReferenceProxying = AccessTools.Method(typeof(ArrayEditor), "AddListReferenceProxying", (global::System.Type[])null, (global::System.Type[])null);

		private static readonly MethodInfo _addListValueProxying = AccessTools.Method(typeof(ArrayEditor), "AddListValueProxying", (global::System.Type[])null, (global::System.Type[])null);

		private static readonly global::System.Type _iWorldElementType = typeof(IWorldElement);

		private static readonly MethodInfo _setLinearPoint = AccessTools.Method(typeof(ArrayEditor), "SetLinearPoint", (global::System.Type[])null, (global::System.Type[])null);

		private static readonly MethodInfo _setCurvePoint = AccessTools.Method(typeof(ArrayEditor), "SetCurvePoint", (global::System.Type[])null, (global::System.Type[])null);

		private static readonly MethodInfo _buildList = typeof(SyncMemberEditorBuilder).GetMethod("BuildList", (BindingFlags)40);

		private static readonly MethodInfo _generateMemberField = typeof(SyncMemberEditorBuilder).GetMethod("GenerateMemberField", (BindingFlags)40);

		private static bool _skipListChanges = false;

		private static void AddCurveValueProxying<T>(SyncArray<CurveKey<T>> array, SyncElementList<Point<T>> list) where T : IEquatable<T>
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			global::System.Collections.Generic.IEnumerator<CurveKey<T>> enumerator = array.GetEnumerator();
			try
			{
				while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
				{
					CurveKey<T> current = enumerator.Current;
					Point<T> obj = list.Add();
					((SyncField<float>)(object)obj.Position).Value = current.time;
					((SyncField<T>)(object)obj.Value).Value = current.value;
				}
			}
			finally
			{
				((global::System.IDisposable)enumerator)?.Dispose();
			}
			AddUpdateProxies<T>(array, list, list.Elements);
			list.ElementsAdded += delegate(SyncElementList<Point<T>> val, int startIndex, int count)
			{
				Point<T>[] array2 = Enumerable.ToArray<Point<T>>(Enumerable.Take<Point<T>>(Enumerable.Skip<Point<T>>(val.Elements, startIndex), count));
				CurveKey<T>[] array3 = Enumerable.ToArray<CurveKey<T>>(Enumerable.Select<Point<T>, CurveKey<T>>((global::System.Collections.Generic.IEnumerable<Point<T>>)array2, (Func<Point<T>, CurveKey<T>>)((Point<T> point) => new CurveKey<T>(Sync<float>.op_Implicit(point.Position), Sync<T>.op_Implicit(point.Value)))));
				if (!_skipListChanges)
				{
					((SyncElement)array).Changed -= ArrayChanged;
					array.Insert(array3, startIndex);
					((SyncElement)array).Changed += ArrayChanged;
				}
				AddUpdateProxies<T>(array, val, (global::System.Collections.Generic.IEnumerable<Point<T>>)array2);
			};
			list.ElementsRemoved += delegate(SyncElementList<Point<T>> val, int startIndex, int count)
			{
				if (!_skipListChanges && array.Count >= startIndex + count)
				{
					((SyncElement)array).Changed -= ArrayChanged;
					array.Remove(startIndex, count);
					((SyncElement)array).Changed += ArrayChanged;
				}
			};
		}

		private static void AddLinearValueProxying<T>(SyncArray<LinearKey<T>> array, SyncElementList<Point<T>> list) where T : IEquatable<T>
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			global::System.Collections.Generic.IEnumerator<LinearKey<T>> enumerator = array.GetEnumerator();
			try
			{
				while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
				{
					LinearKey<T> current = enumerator.Current;
					Point<T> obj = list.Add();
					((SyncField<float>)(object)obj.Position).Value = current.time;
					((SyncField<T>)(object)obj.Value).Value = current.value;
				}
			}
			finally
			{
				((global::System.IDisposable)enumerator)?.Dispose();
			}
			AddUpdateProxies<T>(array, list, list.Elements);
			list.ElementsAdded += delegate(SyncElementList<Point<T>> val, int startIndex, int count)
			{
				Point<T>[] array2 = Enumerable.ToArray<Point<T>>(Enumerable.Take<Point<T>>(Enumerable.Skip<Point<T>>(val.Elements, startIndex), count));
				LinearKey<T>[] array3 = Enumerable.ToArray<LinearKey<T>>(Enumerable.Select<Point<T>, LinearKey<T>>((global::System.Collections.Generic.IEnumerable<Point<T>>)array2, (Func<Point<T>, LinearKey<T>>)((Point<T> point) => new LinearKey<T>(Sync<float>.op_Implicit(point.Position), Sync<T>.op_Implicit(point.Value)))));
				if (!_skipListChanges)
				{
					((SyncElement)array).Changed -= ArrayChanged;
					array.Insert(array3, startIndex);
					((SyncElement)array).Changed += ArrayChanged;
				}
				AddUpdateProxies<T>(array, val, (global::System.Collections.Generic.IEnumerable<Point<T>>)array2);
			};
			list.ElementsRemoved += delegate(SyncElementList<Point<T>> val, int startIndex, int count)
			{
				if (!_skipListChanges && array.Count >= startIndex + count)
				{
					((SyncElement)array).Changed -= ArrayChanged;
					array.Remove(startIndex, count);
					((SyncElement)array).Changed += ArrayChanged;
				}
			};
		}

		private static void AddListReferenceProxying<T>(SyncArray<T> array, SyncElementList<SyncRef<T>> list) where T : class, IEquatable<T>, IWorldElement
		{
			global::System.Collections.Generic.IEnumerator<T> enumerator = array.GetEnumerator();
			try
			{
				while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
				{
					T current = enumerator.Current;
					list.Add().Target = current;
				}
			}
			finally
			{
				((global::System.IDisposable)enumerator)?.Dispose();
			}
			AddUpdateProxies<T>(array, list, list.Elements);
			list.ElementsAdded += delegate(SyncElementList<SyncRef<T>> val, int startIndex, int count)
			{
				SyncRef<T>[] array2 = Enumerable.ToArray<SyncRef<T>>(Enumerable.Take<SyncRef<T>>(Enumerable.Skip<SyncRef<T>>(val.Elements, startIndex), count));
				T[] array3 = Enumerable.ToArray<T>(Enumerable.Select<SyncRef<T>, T>((global::System.Collections.Generic.IEnumerable<SyncRef<T>>)array2, (Func<SyncRef<T>, T>)((SyncRef<T> syncRef) => syncRef.Target)));
				if (!_skipListChanges)
				{
					((SyncElement)array).Changed -= ArrayChanged;
					array.Insert(array3, startIndex);
					((SyncElement)array).Changed += ArrayChanged;
				}
				AddUpdateProxies<T>(array, val, (global::System.Collections.Generic.IEnumerable<SyncRef<T>>)array2);
			};
			list.ElementsRemoved += delegate(SyncElementList<SyncRef<T>> val, int startIndex, int count)
			{
				if (!_skipListChanges && array.Count >= startIndex + count)
				{
					((SyncElement)array).Changed -= ArrayChanged;
					array.Remove(startIndex, count);
					((SyncElement)array).Changed += ArrayChanged;
				}
			};
		}

		private static void AddListValueProxying<T>(SyncArray<T> array, SyncElementList<Sync<T>> list) where T : IEquatable<T>
		{
			global::System.Collections.Generic.IEnumerator<T> enumerator = array.GetEnumerator();
			try
			{
				while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
				{
					T current = enumerator.Current;
					((SyncField<T>)(object)list.Add()).Value = current;
				}
			}
			finally
			{
				((global::System.IDisposable)enumerator)?.Dispose();
			}
			AddUpdateProxies<T>(array, list, list.Elements);
			list.ElementsAdded += delegate(SyncElementList<Sync<T>> val, int startIndex, int count)
			{
				Sync<T>[] array2 = Enumerable.ToArray<Sync<T>>(Enumerable.Take<Sync<T>>(Enumerable.Skip<Sync<T>>(val.Elements, startIndex), count));
				T[] array3 = Enumerable.ToArray<T>(Enumerable.Select<Sync<T>, T>((global::System.Collections.Generic.IEnumerable<Sync<T>>)array2, (Func<Sync<T>, T>)((Sync<T> sync) => ((SyncField<T>)(object)sync).Value)));
				if (!_skipListChanges)
				{
					((SyncElement)array).Changed -= ArrayChanged;
					array.Insert(array3, startIndex);
					((SyncElement)array).Changed += ArrayChanged;
				}
				AddUpdateProxies<T>(array, val, (global::System.Collections.Generic.IEnumerable<Sync<T>>)array2);
			};
			list.ElementsRemoved += delegate(SyncElementList<Sync<T>> val, int startIndex, int count)
			{
				if (!_skipListChanges && array.Count >= startIndex + count)
				{
					((SyncElement)array).Changed -= ArrayChanged;
					array.Remove(startIndex, count);
					((SyncElement)array).Changed += ArrayChanged;
				}
			};
		}

		private static void AddTubePointProxying(SyncArray<TubePoint> array, SyncElementList<Point<float3>> list)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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)
			global::System.Collections.Generic.IEnumerator<TubePoint> enumerator = array.GetEnumerator();
			try
			{
				while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
				{
					TubePoint current = enumerator.Current;
					Point<float3> obj = list.Add();
					((SyncField<float>)(object)obj.Position).Value = ((TubePoint)(ref current)).radius;
					((SyncField<float3>)(object)obj.Value).Value = ((TubePoint)(ref current)).position;
				}
			}
			finally
			{
				((global::System.IDisposable)enumerator)?.Dispose();
			}
			AddUpdateProxies(array, list, list.Elements);
			list.ElementsAdded += delegate(SyncElementList<Point<float3>> val, int startIndex, int count)
			{
				Point<float3>[] array2 = Enumerable.ToArray<Point<float3>>(Enumerable.Take<Point<float3>>(Enumerable.Skip<Point<float3>>(val.Elements, startIndex), count));
				TubePoint[] array3 = Enumerable.ToArray<TubePoint>(Enumerable.Select<Point<float3>, TubePoint>((global::System.Collections.Generic.IEnumerable<Point<float3>>)array2, (Func<Point<float3>, TubePoint>)((Point<float3> point) => new TubePoint(((SyncField<float3>)(object)point.Value).Value, ((SyncField<float>)(object)point.Position).Value))));
				if (!_skipListChanges)
				{
					((SyncElement)array).Changed -= ArrayChanged;
					array.Insert(array3, startIndex);
					((SyncElement)array).Changed += ArrayChanged;
				}
				AddUpdateProxies(array, val, array2);
			};
			list.ElementsRemoved += delegate(SyncElementList<Point<float3>> val, int startIndex, int count)
			{
				if (!_skipListChanges && array.Count >= startIndex + count)
				{
					((SyncElement)array).Changed -= ArrayChanged;
					array.Remove(startIndex, count);
					((SyncElement)array).Changed += ArrayChanged;
				}
			};
		}

		private static void AddUpdateProxies<T>(SyncArray<LinearKey<T>> array, SyncElementList<Point<T>> list, global::System.Collections.Generic.IEnumerable<Point<T>> elements) where T : IEquatable<T>
		{
			global::System.Collections.Generic.IEnumerator<Point<T>> enumerator = elements.GetEnumerator();
			try
			{
				while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
				{
					Point<T> point = enumerator.Current;
					((SyncObject)point).Changed += delegate
					{
						//IL_0076: Unknown result type (might be due to invalid IL or missing references)
						if (!_skipListChanges)
						{
							int num = list.IndexOfElement(point);
							((SyncElement)array).Changed -= ArrayChanged;
							array[num] = new LinearKey<T>(Sync<float>.op_Implicit(point.Position), Sync<T>.op_Implicit(point.Value));
							((SyncElement)array).Changed += ArrayChanged;
						}
					};
				}
			}
			finally
			{
				((global::System.IDisposable)enumerator)?.Dispose();
			}
		}

		private static void AddUpdateProxies<T>(SyncArray<T> array, SyncElementList<Sync<T>> list, global::System.Collections.Generic.IEnumerable<Sync<T>> elements) where T : IEquatable<T>
		{
			global::System.Collections.Generic.IEnumerator<Sync<T>> enumerator = elements.GetEnumerator();
			try
			{
				while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
				{
					Sync<T> sync = enumerator.Current;
					((SyncField<T>)(object)sync).OnValueChange += delegate
					{
						if (!_skipListChanges)
						{
							int num = list.IndexOfElement(sync);
							((SyncElement)array).Changed -= ArrayChanged;
							array[num] = ((SyncField<T>)(object)sync).Value;
							((SyncElement)array).Changed += ArrayChanged;
						}
					};
				}
			}
			finally
			{
				((global::System.IDisposable)enumerator)?.Dispose();
			}
		}

		private static void AddUpdateProxies<T>(SyncArray<T> array, SyncElementList<SyncRef<T>> list, global::System.Collections.Generic.IEnumerable<SyncRef<T>> elements) where T : class, IEquatable<T>, IWorldElement
		{
			global::System.Collections.Generic.IEnumerator<SyncRef<T>> enumerator = elements.GetEnumerator();
			try
			{
				while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
				{
					SyncRef<T> sync = enumerator.Current;
					((SyncField<RefID>)(object)sync).OnValueChange += delegate
					{
						if (!_skipListChanges)
						{
							int num = list.IndexOfElement(sync);
							((SyncElement)array).Changed -= ArrayChanged;
							array[num] = sync.Target;
							((SyncElement)array).Changed += ArrayChanged;
						}
					};
				}
			}
			finally
			{
				((global::System.IDisposable)enumerator)?.Dispose();
			}
		}

		private static void AddUpdateProxies(SyncArray<TubePoint> array, SyncElementList<Point<float3>> list, global::System.Collections.Generic.IEnumerable<Point<float3>> elements)
		{
			global::System.Collections.Generic.IEnumerator<Point<float3>> enumerator = elements.GetEnumerator();
			try
			{
				while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
				{
					Point<float3> point = enumerator.Current;
					((SyncObject)point).Changed += delegate
					{
						//IL_002c: Unknown result type (might be due to invalid IL or missing references)
						//IL_007d: Unknown result type (might be due to invalid IL or missing references)
						if (!_skipListChanges)
						{
							int num = list.IndexOfElement(point);
							TubePoint val = default(TubePoint);
							((TubePoint)(ref val))..ctor(((SyncField<float3>)(object)point.Value).Value, ((SyncField<float>)(object)point.Position).Value);
							((SyncElement)array).Changed -= ArrayChanged;
							array[num] = val;
							((SyncElement)array).Changed += ArrayChanged;
						}
					};
				}
			}
			finally
			{
				((global::System.IDisposable)enumerator)?.Dispose();
			}
		}

		private static void AddUpdateProxies<T>(SyncArray<CurveKey<T>> array, SyncElementList<Point<T>> list, global::System.Collections.Generic.IEnumerable<Point<T>> elements) where T : IEquatable<T>
		{
			global::System.Collections.Generic.IEnumerator<Point<T>> enumerator = elements.GetEnumerator();
			try
			{
				while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
				{
					Point<T> point = enumerator.Current;
					((SyncObject)point).Changed += delegate
					{
						//IL_0082: Unknown result type (might be due to invalid IL or missing references)
						//IL_0098: 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)
						if (!_skipListChanges)
						{
							int num = list.IndexOfElement(point);
							((SyncElement)array).Changed -= ArrayChanged;
							array[num] = new CurveKey<T>(Sync<float>.op_Implicit(point.Position), Sync<T>.op_Implicit(point.Value), array[num].leftTangent, array[num].rightTangent);
							((SyncElement)array).Changed += ArrayChanged;
						}
					};
				}
			}
			finally
			{
				((global::System.IDisposable)enumerator)?.Dispose();
			}
		}

		private static bool Prefix(ISyncArray array, string name, FieldInfo fieldInfo, UIBuilder ui, float labelSize)
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Expected O, but got Unknown
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Expected O, but got Unknown
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_0369: Expected O, but got Unknown
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Expected O, but got Unknown
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03df: Expected O, but got Unknown
			//IL_0578: Unknown result type (might be due to invalid IL or missing references)
			//IL_057d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0468: Unknown result type (might be due to invalid IL or missing references)
			//IL_046f: Expected O, but got Unknown
			if (!ArrayEditorEnabled.Value)
			{
				return true;
			}
			if (!TryGetGenericParameter(typeof(SyncArray<>), ((object)array).GetType(), out global::System.Type genericParameter))
			{
				return false;
			}
			((ContainerWorker<Component>)(object)((Component)ui.Panel()).Slot).GetComponent<LayoutElement>((Predicate<LayoutElement>)null, false);
			Slot slot = (Slot)((MethodBase)_generateMemberField).Invoke((object)null, new object[4] { array, name, ui, 0.3f });
			ManualLogSource log = Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(24, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Ran GenerateMemberField ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Slot>(slot);
			}
			log.LogInfo(val);
			ui.ForceNext = ((ContainerWorker<Component>)(object)slot).AttachComponent<RectTransform>(true, (Action<RectTransform>)null);
			LocaleString val2 = LocaleString.op_Implicit("(Proxy Array)");
			ui.Text(ref val2, true, (Alignment?)null, true, (string)null);
			ui.NestOut();
			global::System.Type genericParameter2;
			bool num = TryGetGenericParameter(typeof(SyncLinear<>), ((object)array).GetType(), out genericParameter2);
			global::System.Type genericParameter3;
			bool flag2 = TryGetGenericParameter(typeof(SyncCurve<>), ((object)array).GetType(), out genericParameter3);
			string text = $"{name}-{((IWorldElement)array).ReferenceID}-Proxy";
			Slot assetsSlot = ui.World.AssetsSlot;
			bool flag3 = false;
			Slot proxySlot = assetsSlot.FindChild(text);
			if (proxySlot == null)
			{
				proxySlot = assetsSlot.AddSlot(text, true);
				WorldElementExtensions.FindNearestParent<IDestroyable>((IWorldElement)(object)array, (Predicate<IDestroyable>)null).Destroyed += delegate
				{
					proxySlot.Destroy();
				};
				flag3 = true;
			}
			proxySlot.PersistentSelf = false;
			((ContainerWorker<Component>)(object)proxySlot).GetComponentOrAttach<DestroyOnUserLeave>((Predicate<DestroyOnUserLeave>)((DestroyOnUserLeave d) => d.TargetUser.Target == ((Worker)slot).LocalUser)).TargetUser.Target = ((Worker)slot).LocalUser;
			ISyncList val3;
			FieldInfo syncMemberFieldInfo;
			if (num && SupportsLerp(genericParameter2))
			{
				global::System.Type type = typeof(ValueGradientDriver<>).MakeGenericType(new global::System.Type[1] { genericParameter2 });
				bool attachedNew;
				Component orAttachComponent = GetOrAttachComponent(proxySlot, type, out attachedNew);
				val3 = (ISyncList)((Worker)orAttachComponent).GetSyncMember("Points");
				syncMemberFieldInfo = ((Worker)orAttachComponent).GetSyncMemberFieldInfo("Points");
				if (attachedNew)
				{
					((MethodBase)_addLinearValueProxying.MakeGenericMethod(new global::System.Type[1] { genericParameter2 })).Invoke((object)null, new object[2] { array, val3 });
				}
			}
			else if (flag2 && SupportsLerp(genericParameter3))
			{
				global::System.Type type2 = typeof(ValueGradientDriver<>).MakeGenericType(new global::System.Type[1] { genericParameter3 });
				bool attachedNew2;
				Component orAttachComponent2 = GetOrAttachComponent(proxySlot, type2, out attachedNew2);
				val3 = (ISyncList)((Worker)orAttachComponent2).GetSyncMember("Points");
				syncMemberFieldInfo = ((Worker)orAttachComponent2).GetSyncMemberFieldInfo("Points");
				if (attachedNew2)
				{
					((MethodBase)_addCurveValueProxying.MakeGenericMethod(new global::System.Type[1] { genericParameter3 })).Invoke((object)null, new object[2] { array, val3 });
				}
			}
			else if (genericParameter == typeof(TubePoint))
			{
				bool attachedNew3;
				Component orAttachComponent3 = GetOrAttachComponent(proxySlot, typeof(ValueGradientDriver<float3>), out attachedNew3);
				val3 = (ISyncList)((Worker)orAttachComponent3).GetSyncMember("Points");
				syncMemberFieldInfo = ((Worker)orAttachComponent3).GetSyncMemberFieldInfo("Points");
				if (attachedNew3)
				{
					AddTubePointProxying((SyncArray<TubePoint>)(object)array, (SyncElementList<Point<float3>>)(object)val3);
				}
			}
			else if (Coder.IsEnginePrimitive(genericParameter))
			{
				global::System.Type type3 = typeof(ValueMultiplexer<>).MakeGenericType(new global::System.Type[1] { genericParameter });
				bool attachedNew4;
				Component orAttachComponent4 = GetOrAttachComponent(proxySlot, type3, out attachedNew4);
				val3 = (ISyncList)((Worker)orAttachComponent4).GetSyncMember("Values");
				syncMemberFieldInfo = ((Worker)orAttachComponent4).GetSyncMemberFieldInfo("Values");
				if (attachedNew4)
				{
					((MethodBase)_addListValueProxying.MakeGenericMethod(new global::System.Type[1] { genericParameter })).Invoke((object)null, new object[2] { array, val3 });
				}
			}
			else
			{
				if (!_iWorldElementType.IsAssignableFrom(genericParameter))
				{
					proxySlot.Destroy();
					return false;
				}
				global::System.Type type4 = typeof(ReferenceMultiplexer<>).MakeGenericType(new global::System.Type[1] { genericParameter });
				bool attachedNew5;
				Component orAttachComponent5 = GetOrAttachComponent(proxySlot, type4, out attachedNew5);
				val3 = (ISyncList)((Worker)orAttachComponent5).GetSyncMember("References");
				syncMemberFieldInfo = ((Worker)orAttachComponent5).GetSyncMemberFieldInfo("References");
				if (attachedNew5)
				{
					((MethodBase)_addListReferenceProxying.MakeGenericMethod(new global::System.Type[1] { genericParameter })).Invoke((object)null, new object[2] { array, val3 });
				}
			}
			Slot listSlot;
			if (!((ILinkable)array).IsDriven)
			{
				((MethodBase)_buildList).Invoke((object)null, new object[4] { val3, name, syncMemberFieldInfo, ui });
				listSlot = ui.Current;
				((ContainerWorker<Component>)(object)listSlot).GetComponentOrAttach<DestroyOnUserLeave>((Predicate<DestroyOnUserLeave>)((DestroyOnUserLeave d) => d.TargetUser.Target == ((Worker)slot).LocalUser)).TargetUser.Target = ((Worker)slot).LocalUser;
				listSlot.PersistentSelf = false;
				((IChangeable)array).Changed += ArrayDriveCheck;
			}
			else
			{
				LocaleString val4 = LocaleString.op_Implicit("(array is driven)");
				ui.Text(ref val4, true, (Alignment?)null, true, (string)null);
			}
			if (flag3)
			{
				((IChangeable)array).Changed += ArrayChanged;
			}
			return false;
			void ArrayDriveCheck(IChangeable changeable)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_0080: Unknown result type (might be due to invalid IL or missing references)
				//IL_0085: Unknown result type (might be due to invalid IL or missing references)
				//IL_008c: Expected O, but got Unknown
				//IL_0091: 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)
				if (((ILinkable)(ISyncArray)changeable).IsDriven)
				{
					listSlot.DestroyChildren(false, true, false, (Predicate<Slot>)null);
					CollectionExtensions.Do<Component>((global::System.Collections.Generic.IEnumerable<Component>)Enumerable.ToArray<Component>((global::System.Collections.Generic.IEnumerable<Component>)(object)((ContainerWorker<Component>)(object)listSlot).Components), (Action<Component>)delegate(Component c)
					{
						((ComponentBase<Component>)(object)c).Destroy();
					});
					((SyncField<float>)(object)((ContainerWorker<Component>)(object)listSlot).AttachComponent<LayoutElement>(true, (Action<LayoutElement>)null).MinHeight).Value = 24f;
					UIBuilder val5 = new UIBuilder(listSlot, listSlot);
					RadiantUI_Constants.SetupEditorStyle(val5, false);
					LocaleString val6 = LocaleString.op_Implicit("(array is driven)");
					val5.Text(ref val6, true, (Alignment?)null, true, (string)null);
					Slot obj = proxySlot;
					if (obj != null)
					{
						obj.Destroy();
					}
					((IChangeable)array).Changed -= ArrayDriveCheck;
				}
			}
		}

		private static void SetLinearPoint<T>(Point<T> point, LinearKey<T> arrayElem) where T : IEquatable<T>
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			((SyncField<float>)(object)point.Position).Value = arrayElem.time;
			((SyncField<T>)(object)point.Value).Value = arrayElem.value;
		}

		private static void SetCurvePoint<T>(Point<T> point, CurveKey<T> arrayElem) where T : IEquatable<T>
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			((SyncField<float>)(object)point.Position).Value = arrayElem.time;
			((SyncField<T>)(object)point.Value).Value = arrayElem.value;
		}

		private static void SetTubePoint(Point<float3> point, TubePoint arrayElem)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			((SyncField<float>)(object)point.Position).Value = ((TubePoint)(ref arrayElem)).radius;
			((SyncField<float3>)(object)point.Value).Value = ((TubePoint)(ref arrayElem)).position;
		}

		private static void ArrayChanged(IChangeable changeable)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Expected O, but got Unknown
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Expected O, but got Unknown
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Expected O, but got Unknown
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Expected O, but got Unknown
			//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
			Log.LogDebug((object)"Array Changed");
			ISyncArray val = (ISyncArray)changeable;
			if (((ILinkable)val).IsDriven)
			{
				((IChangeable)val).Changed -= ArrayChanged;
				return;
			}
			string text = $"{((ISyncMember)val).Name}-{((IWorldElement)val).ReferenceID}-Proxy";
			Slot val2 = ((IWorldElement)val).World.AssetsSlot.FindChild(text);
			if (val2 == null)
			{
				return;
			}
			ISyncList val3 = null;
			ComponentEnumerator<Component> enumerator = ((ContainerWorker<Component>)(object)val2).Components.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					Component current = enumerator.Current;
					if (((object)current).GetType().IsGenericType && ((object)current).GetType().GetGenericTypeDefinition() == typeof(ValueMultiplexer<>))
					{
						ISyncMember syncMember = ((Worker)current).GetSyncMember("Values");
						val3 = (ISyncList)(object)((syncMember is ISyncList) ? syncMember : null);
						_skipListChanges = true;
						World world = ((IWorldElement)val3).World;
						object obj = <>c.<>9__24_0;
						if (obj == null)
						{
							Action val4 = delegate
							{
								_skipListChanges = false;
							};
							<>c.<>9__24_0 = val4;
							obj = (object)val4;
						}
						world.RunSynchronously((Action)obj, false, (IUpdatable)null, false);
						SyncElementListHelper.EnsureExactElementCount(val3, val.Count);
						for (int num = 0; num < val.Count; num++)
						{
							((IField)val3.GetElement(num)).BoxedValue = val.GetElement(num);
						}
					}
					else if (((object)current).GetType().IsGenericType && ((object)current).GetType().GetGenericTypeDefinition() == typeof(ReferenceMultiplexer<>))
					{
						ISyncMember syncMember2 = ((Worker)current).GetSyncMember("References");
						val3 = (ISyncList)(object)((syncMember2 is ISyncList) ? syncMember2 : null);
						_skipListChanges = true;
						World world2 = ((IWorldElement)val3).World;
						object obj2 = <>c.<>9__24_1;
						if (obj2 == null)
						{
							Action val5 = delegate
							{
								_skipListChanges = false;
							};
							<>c.<>9__24_1 = val5;
							obj2 = (object)val5;
						}
						world2.RunSynchronously((Action)obj2, false, (IUpdatable)null, false);
						SyncElementListHelper.EnsureExactElementCount(val3, val.Count);
						for (int num2 = 0; num2 < val.Count; num2++)
						{
							((ISyncRef)val3.GetElement(num2)).Target = (IWorldElement)val.GetElement(num2);
						}
					}
					else
					{
						if (!((object)current).GetType().IsGenericType || !(((object)current).GetType().GetGenericTypeDefinition() == typeof(ValueGradientDriver<>)))
						{
							continue;
						}
						ISyncMember syncMember3 = ((Worker)current).GetSyncMember("Points");
						val3 = (ISyncList)(object)((syncMember3 is ISyncList) ? syncMember3 : null);
						_skipListChanges = true;
						World world3 = ((IWorldElement)val3).World;
						object obj3 = <>c.<>9__24_2;
						if (obj3 == null)
						{
							Action val6 = delegate
							{
								_skipListChanges = false;
							};
							<>c.<>9__24_2 = val6;
							obj3 = (object)val6;
						}
						world3.RunSynchronously((Action)obj3, false, (IUpdatable)null, false);
						SyncElementListHelper.EnsureExactElementCount(val3, val.Count);
						global::System.Type genericParameter;
						bool flag = TryGetGenericParameter(typeof(SyncLinear<>), ((object)val).GetType(), out genericParameter);
						global::System.Type genericParameter2;
						bool flag2 = TryGetGenericParameter(typeof(SyncCurve<>), ((object)val).GetType(), out genericParameter2);
						if (!TryGetGenericParameter(typeof(SyncArray<>), ((object)val).GetType(), out global::System.Type genericParameter3))
						{
							break;
						}
						global::System.Type type = genericParameter3;
						for (int num3 = 0; num3 < val.Count; num3++)
						{
							ISyncMember element = val3.GetElement(num3);
							if (flag && SupportsLerp(genericParameter))
							{
								((MethodBase)_setLinearPoint.MakeGenericMethod(new global::System.Type[1] { genericParameter })).Invoke((object)null, new object[2]
								{
									element,
									val.GetElement(num3)
								});
							}
							else if (flag2 && SupportsLerp(genericParameter2))
							{
								((MethodBase)_setCurvePoint.MakeGenericMethod(new global::System.Type[1] { genericParameter2 })).Invoke((object)null, new object[2]
								{
									element,
									val.GetElement(num3)
								});
							}
							else if (type == typeof(TubePoint))
							{
								SetTubePoint((Point<float3>)(object)element, (TubePoint)val.GetElement(num3));
							}
						}
					}
				}
			}
			finally
			{
				((global::System.IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private static Component GetOrAttachComponent(Slot targetSlot, global::System.Type type, out bool attachedNew)
		{
			attachedNew = false;
			Component val = ((ContainerWorker<Component>)(object)targetSlot).GetComponent(type, false);
			if (val == null)
			{
				val = ((ContainerWorker<Component>)(object)targetSlot).AttachComponent(type, true, (Action<Component>)null);
				attachedNew = true;
			}
			return val;
		}

		private static bool SupportsLerp(global::System.Type type)
		{
			return Traverse.Create(typeof(Coder<>).MakeGenericType(new global::System.Type[1] { type })).Property<bool>("SupportsLerp", (object[])null).Value;
		}

		private static bool TryGetGenericParameter(global::System.Type baseType, global::System.Type concreteType, out global::System.Type? genericParameter)
		{
			genericParameter = null;
			if (concreteType == null || baseType == null || !baseType.IsGenericType)
			{
				return false;
			}
			if (concreteType.IsGenericType && concreteType.GetGenericTypeDefinition() == baseType)
			{
				global::System.Type[] genericArguments = concreteType.GetGenericArguments();
				if (genericArguments.Length != 0)
				{
					genericParameter = genericArguments[0];
					return true;
				}
			}
			return TryGetGenericParameter(baseType, concreteType.BaseType, out genericParameter);
		}
	}

	internal static ManualLogSource Log;

	internal static ConfigEntry<bool> ArrayEditorEnabled;

	internal static ConfigEntry<bool> ArrayEditorListUIImprovemts;

	public override void Load()
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Expected O, but got Unknown
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Expected O, but got Unknown
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Expected O, but got Unknown
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Expected O, but got Unknown
		Log = ((BasePlugin)this).Log;
		ArrayEditorEnabled = ((BasePlugin)this).Config.Bind<bool>("Array Editor", "Enable ArrayEditor", true, new ConfigDescription("Enables the Array Editor Mod.", (AcceptableValueBase)null, global::System.Array.Empty<object>()));
		ArrayEditorListUIImprovemts = ((BasePlugin)this).Config.Bind<bool>("Array Editor", "Enable List UI Improvements", true, new ConfigDescription("Enables some List UI changes to make it a bit more nicer to use.", (AcceptableValueBase)null, global::System.Array.Empty<object>()));
		try
		{
			if (ArrayEditorEnabled.Value)
			{
				((BasePlugin)this).HarmonyInstance.PatchAll();
			}
			Log.LogInfo((object)"BepisArrayEditor Loaded!");
		}
		catch (global::System.Exception ex)
		{
			ManualLogSource log = Log;
			bool flag = default(bool);
			BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(34, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("BepisArrayEditor failed to patch: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<global::System.Exception>(ex);
			}
			log.LogError(val);
		}
		ArrayEditorEnabled.SettingChanged += (EventHandler)([CompilerGenerated] (object? e, EventArgs s) =>
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			if (ArrayEditorEnabled.Value)
			{
				try
				{
					Log.LogInfo((object)"Enabling BepisArrayEditor");
					((BasePlugin)this).HarmonyInstance.PatchAll();
					return;
				}
				catch (global::System.Exception ex2)
				{
					ManualLogSource log2 = Log;
					bool flag2 = default(bool);
					BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(34, 1, ref flag2);
					if (flag2)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("BepisArrayEditor failed to patch: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<global::System.Exception>(ex2);
					}
					log2.LogError(val2);
					return;
				}
			}
			Log.LogInfo((object)"Disabling BepisArrayEditor");
			((BasePlugin)this).HarmonyInstance.UnpatchSelf();
		});
	}
}
public static class PluginMetadata
{
	public const string GUID = "xyz.gyztormizirath.BepisArrayEditor";

	public const string NAME = "BepisArrayEditor";

	public const string VERSION = "1.0.2";

	public const string AUTHORS = "Gyztor Mizirath";

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