Decompiled source of ArrayEditor v1.0.6

plugins/BepisArrayEditor/BepisArrayEditor.dll

Decompiled a month 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 System.Security;
using System.Security.Permissions;
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: IgnoresAccessChecksTo("FrooxEngine")]
[assembly: AssemblyCompany("Gyztor Mizirath")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.6.0")]
[assembly: AssemblyInformationalVersion("1.0.6+9450c480996f7e4235d36c2e6c5e6036cb62a43d")]
[assembly: AssemblyProduct("BepisArrayEditor")]
[assembly: AssemblyTitle("BepisArrayEditor")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/Gyztor/BepisArrayEditor")]
[assembly: SecurityPermission((SecurityAction)8, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.6.0")]
[module: UnverifiableCode]
[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.6", "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__12_2;

				public static Action<Component> <>9__18_4;

				public static Action <>9__22_0;

				public static Action <>9__22_1;

				public static Action <>9__22_2;

				internal TubePoint <AddTubePointProxying>b__12_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__18_4(Component c)
				{
					((ComponentBase<Component>)(object)c).Destroy();
				}

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

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

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

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

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

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

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

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

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

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

			private static bool _skipListChanges = false;

			private static void AddCurveValueProxying<T>(SyncArrayBase<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)
				System.Collections.Generic.IEnumerator<CurveKey<T>> enumerator = array.GetEnumerator();
				try
				{
					while (((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
				{
					((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>>((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;
						Traverse.Create((object)array).Method("CheckWriteIndex", System.Array.Empty<object>()).GetValue(new object[1] { startIndex });
						Traverse.Create((object)array).Method("InternalWrite", System.Array.Empty<object>()).GetValue(new object[5] { array3, startIndex, 0, array3.Length, true });
						((SyncElement)array).Changed += ArrayChanged;
					}
					AddUpdateProxies<T>(array, val, (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>(SyncArrayBase<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)
				System.Collections.Generic.IEnumerator<LinearKey<T>> enumerator = array.GetEnumerator();
				try
				{
					while (((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
				{
					((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>>((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.CheckWriteIndex(startIndex);
						array.InternalWrite(array3, startIndex, 0, array3.Length, true, true);
						((SyncElement)array).Changed += ArrayChanged;
					}
					AddUpdateProxies<T>(array, val, (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
			{
				System.Collections.Generic.IEnumerator<T> enumerator = ((SyncArrayBase<T>)(object)array).GetEnumerator();
				try
				{
					while (((System.Collections.IEnumerator)enumerator).MoveNext())
					{
						T current = enumerator.Current;
						list.Add().Target = current;
					}
				}
				finally
				{
					((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>((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, (System.Collections.Generic.IEnumerable<SyncRef<T>>)array2);
				};
				list.ElementsRemoved += delegate(SyncElementList<SyncRef<T>> val, int startIndex, int count)
				{
					if (!_skipListChanges && ((SyncArrayBase<T>)(object)array).Count >= startIndex + count)
					{
						((SyncElement)array).Changed -= ArrayChanged;
						((SyncArrayBase<T>)(object)array).Remove(startIndex, count);
						((SyncElement)array).Changed += ArrayChanged;
					}
				};
			}

			private static void AddListValueProxying<T>(SyncArray<T> array, SyncElementList<Sync<T>> list) where T : IEquatable<T>
			{
				System.Collections.Generic.IEnumerator<T> enumerator = ((SyncArrayBase<T>)(object)array).GetEnumerator();
				try
				{
					while (((System.Collections.IEnumerator)enumerator).MoveNext())
					{
						T current = enumerator.Current;
						((SyncField<T>)(object)list.Add()).Value = current;
					}
				}
				finally
				{
					((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>((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, (System.Collections.Generic.IEnumerable<Sync<T>>)array2);
				};
				list.ElementsRemoved += delegate(SyncElementList<Sync<T>> val, int startIndex, int count)
				{
					if (!_skipListChanges && ((SyncArrayBase<T>)(object)array).Count >= startIndex + count)
					{
						((SyncElement)array).Changed -= ArrayChanged;
						((SyncArrayBase<T>)(object)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)
				System.Collections.Generic.IEnumerator<TubePoint> enumerator = ((SyncArrayBase<TubePoint>)(object)array).GetEnumerator();
				try
				{
					while (((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
				{
					((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>((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 && ((SyncArrayBase<TubePoint>)(object)array).Count >= startIndex + count)
					{
						((SyncElement)array).Changed -= ArrayChanged;
						((SyncArrayBase<TubePoint>)(object)array).Remove(startIndex, count);
						((SyncElement)array).Changed += ArrayChanged;
					}
				};
			}

			private static void AddUpdateProxies<T>(SyncArrayBase<LinearKey<T>> array, SyncElementList<Point<T>> list, System.Collections.Generic.IEnumerable<Point<T>> elements) where T : IEquatable<T>
			{
				System.Collections.Generic.IEnumerator<Point<T>> enumerator = elements.GetEnumerator();
				try
				{
					while (((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.SetElement(num, new LinearKey<T>(Sync<float>.op_Implicit(point.Position), Sync<T>.op_Implicit(point.Value)));
								((SyncElement)array).Changed += ArrayChanged;
							}
						};
					}
				}
				finally
				{
					((System.IDisposable)enumerator)?.Dispose();
				}
			}

			private static void AddUpdateProxies<T>(SyncArray<T> array, SyncElementList<Sync<T>> list, System.Collections.Generic.IEnumerable<Sync<T>> elements) where T : IEquatable<T>
			{
				System.Collections.Generic.IEnumerator<Sync<T>> enumerator = elements.GetEnumerator();
				try
				{
					while (((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
				{
					((System.IDisposable)enumerator)?.Dispose();
				}
			}

			private static void AddUpdateProxies<T>(SyncArray<T> array, SyncElementList<SyncRef<T>> list, System.Collections.Generic.IEnumerable<SyncRef<T>> elements) where T : class, IEquatable<T>, IWorldElement
			{
				System.Collections.Generic.IEnumerator<SyncRef<T>> enumerator = elements.GetEnumerator();
				try
				{
					while (((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
				{
					((System.IDisposable)enumerator)?.Dispose();
				}
			}

			private static void AddUpdateProxies(SyncArray<TubePoint> array, SyncElementList<Point<float3>> list, System.Collections.Generic.IEnumerable<Point<float3>> elements)
			{
				System.Collections.Generic.IEnumerator<Point<float3>> enumerator = elements.GetEnumerator();
				try
				{
					while (((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
				{
					((System.IDisposable)enumerator)?.Dispose();
				}
			}

			private static void AddUpdateProxies<T>(SyncArrayBase<CurveKey<T>> array, SyncElementList<Point<T>> list, System.Collections.Generic.IEnumerable<Point<T>> elements) where T : IEquatable<T>
			{
				System.Collections.Generic.IEnumerator<Point<T>> enumerator = elements.GetEnumerator();
				try
				{
					while (((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.SetElement(num, new CurveKey<T>(Sync<float>.op_Implicit(point.Position), Sync<T>.op_Implicit(point.Value), array.GetElement(num).leftTangent, array.GetElement(num).rightTangent));
								((SyncElement)array).Changed += ArrayChanged;
							}
						};
					}
				}
				finally
				{
					((System.IDisposable)enumerator)?.Dispose();
				}
			}

			private static bool Prefix(ISyncArray array, string name, FieldInfo fieldInfo, UIBuilder ui, float labelSize)
			{
				//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
				//IL_013c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_004a: Expected O, but got Unknown
				//IL_022f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0236: Expected O, but got Unknown
				//IL_0348: Unknown result type (might be due to invalid IL or missing references)
				//IL_034f: Expected O, but got Unknown
				//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
				//IL_02cc: Expected O, but got Unknown
				//IL_03be: Unknown result type (might be due to invalid IL or missing references)
				//IL_03c5: Expected O, but got Unknown
				//IL_0549: Unknown result type (might be due to invalid IL or missing references)
				//IL_054e: Unknown result type (might be due to invalid IL or missing references)
				//IL_044e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0455: Expected O, but got Unknown
				if (!ArrayEditorEnabled.Value)
				{
					return true;
				}
				if (!TryGetGenericParameter(typeof(SyncArrayBase<>), ((object)array).GetType(), out System.Type genericParameter))
				{
					ManualLogSource log = Log;
					bool flag = default(bool);
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(21, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<System.Type>(((object)array).GetType());
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is not yet supported");
					}
					log.LogWarning(val);
					return true;
				}
				((ContainerWorker<Component>)(object)((Component)ui.Panel()).Slot).GetComponent<LayoutElement>((Predicate<LayoutElement>)null, false);
				Slot slot = SyncMemberEditorBuilder.GenerateMemberField((ISyncMember)(object)array, name, ui, 0.3f);
				ui.ForceNext = ((ContainerWorker<Component>)(object)slot).AttachComponent<RectTransform>(true, (Action<RectTransform>)null);
				LocaleString val2 = LocaleHelper.AsLocaleKey("ArrayEditing.ProxyArray", (string)null, true, (Dictionary<string, object>)null);
				ui.Text(ref val2, true, (Alignment?)null, true, (string)null);
				ui.NestOut();
				System.Type genericParameter2;
				bool num = TryGetGenericParameter(typeof(SyncLinear<>), ((object)array).GetType(), out genericParameter2);
				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))
				{
					System.Type type = typeof(ValueGradientDriver<>).MakeGenericType(new 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 System.Type[1] { genericParameter2 })).Invoke((object)null, new object[2] { array, val3 });
					}
				}
				else if (flag2 && SupportsLerp(genericParameter3))
				{
					System.Type type2 = typeof(ValueGradientDriver<>).MakeGenericType(new 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 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))
				{
					System.Type type3 = typeof(ValueMultiplexer<>).MakeGenericType(new 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 System.Type[1] { genericParameter })).Invoke((object)null, new object[2] { array, val3 });
					}
				}
				else
				{
					if (!_iWorldElementType.IsAssignableFrom(genericParameter))
					{
						proxySlot.Destroy();
						return false;
					}
					System.Type type4 = typeof(ReferenceMultiplexer<>).MakeGenericType(new 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 System.Type[1] { genericParameter })).Invoke((object)null, new object[2] { array, val3 });
					}
				}
				Slot listSlot;
				if (!((ILinkable)array).IsDriven)
				{
					SyncMemberEditorBuilder.BuildList(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
				{
					val2 = LocaleHelper.AsLocaleKey("ArrayEditting.DrivenArray", (string)null, true, (Dictionary<string, object>)null);
					ui.Text(ref val2, 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_0094: Unknown result type (might be due to invalid IL or missing references)
					//IL_0099: 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>((System.Collections.Generic.IEnumerable<Component>)Enumerable.ToArray<Component>((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 val4 = new UIBuilder(listSlot, listSlot);
						RadiantUI_Constants.SetupEditorStyle(val4, false);
						LocaleString val5 = LocaleHelper.AsLocaleKey("ArrayEditting.DrivenArray", (string)null, true, (Dictionary<string, object>)null);
						val4.Text(ref val5, 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__22_0;
							if (obj == null)
							{
								Action val4 = delegate
								{
									_skipListChanges = false;
								};
								<>c.<>9__22_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__22_1;
							if (obj2 == null)
							{
								Action val5 = delegate
								{
									_skipListChanges = false;
								};
								<>c.<>9__22_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__22_2;
							if (obj3 == null)
							{
								Action val6 = delegate
								{
									_skipListChanges = false;
								};
								<>c.<>9__22_2 = val6;
								obj3 = (object)val6;
							}
							world3.RunSynchronously((Action)obj3, false, (IUpdatable)null, false);
							SyncElementListHelper.EnsureExactElementCount(val3, val.Count);
							System.Type genericParameter;
							bool flag = TryGetGenericParameter(typeof(SyncLinear<>), ((object)val).GetType(), out genericParameter);
							System.Type genericParameter2;
							bool flag2 = TryGetGenericParameter(typeof(SyncCurve<>), ((object)val).GetType(), out genericParameter2);
							if (!TryGetGenericParameter(typeof(SyncArray<>), ((object)val).GetType(), out System.Type genericParameter3))
							{
								break;
							}
							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 System.Type[1] { genericParameter })).Invoke((object)null, new object[2]
									{
										element,
										val.GetElement(num3)
									});
								}
								else if (flag2 && SupportsLerp(genericParameter2))
								{
									((MethodBase)_setCurvePoint.MakeGenericMethod(new 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
				{
					((System.IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
				}
			}

			private static Component GetOrAttachComponent(Slot targetSlot, 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(System.Type type)
			{
				return Traverse.Create(typeof(Coder<>).MakeGenericType(new System.Type[1] { type })).Property<bool>("SupportsLerp", (object[])null).Value;
			}

			private static bool TryGetGenericParameter(System.Type baseType, System.Type concreteType, out System.Type? genericParameter)
			{
				genericParameter = null;
				if (concreteType == null || baseType == null || !baseType.IsGenericType)
				{
					return false;
				}
				if (concreteType.IsGenericType && concreteType.GetGenericTypeDefinition() == baseType)
				{
					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, 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, System.Array.Empty<object>()));
			try
			{
				if (ArrayEditorEnabled.Value)
				{
					((BasePlugin)this).HarmonyInstance.PatchAll();
				}
				Log.LogInfo((object)"BepisArrayEditor Loaded!");
			}
			catch (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<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 (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<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.6";

		public const string AUTHORS = "Gyztor Mizirath";

		public const string REPOSITORY_URL = "https://github.com/Gyztor/BepisArrayEditor";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(/*Could not decode attribute arguments.*/)]
	internal sealed class IgnoresAccessChecksToAttribute : System.Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}