Decompiled source of ReplicatorPlugin v2.0.0

ReplicatorPlugin.dll

Decompiled 6 days 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.InteropServices;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using ModdingTales;
using Unity.Mathematics;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ReplicatorPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ReplicatorPlugin")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("ReplicatorPlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("2.0.0.0")]
namespace LordAshes;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("org.lordashes.plugins.replicator", "Replicator Plugin", "2.0.0.0")]
public class ReplicatorPlugin : BaseUnityPlugin
{
	public static class Patches
	{
		public class Waypoints
		{
			public TaskCompletionSource<bool> spawnInProgress = null;

			public Vector3 lookAt = Vector3.zero;

			public bool collecting { get; set; } = false;


			public string link { get; set; } = "";


			public RulerType ruler { get; set; } = RulerType.None;


			public List<Vector3> points { get; set; } = new List<Vector3>();

		}

		public enum RulerType
		{
			None = -1,
			Sphere,
			Line,
			Cone,
			Box
		}

		[HarmonyPatch(typeof(CreatureBoardAsset), "OnBaseLoaded")]
		[HarmonyBefore(new string[] { "org.lordashes.plugins.angel.ccm" })]
		public static class PatchOnBaseLoaded
		{
			public static bool Prefix(CreatureBoardAsset __instance)
			{
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				LoggingPlugin.LogDebug("Creature Spawned");
				if (waypoints.spawnInProgress != null)
				{
					((MovableBoardAsset)__instance).JumpRotationTowards(waypoints.lookAt);
					if (waypoints.link != null && waypoints.link != "")
					{
						LoggingPlugin.LogDebug("Replicator ANGEL Creature Spawned. Adding Link.");
						CreatureManager.SetLink(__instance.CreatureId, waypoints.link);
						waypoints.link = null;
					}
					waypoints.spawnInProgress.SetResult(result: true);
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Ruler), "SetNewMode")]
		public static class PatchSetNewMode
		{
			public static bool Prefix(int newModeIndex, bool forceRecreate)
			{
				if (waypoints.collecting)
				{
					string[] obj = new string[5] { "Replicator Plugin: Ruler Mode Change To Type ", null, null, null, null };
					RulerType rulerType = (RulerType)newModeIndex;
					obj[1] = rulerType.ToString();
					obj[2] = " (";
					obj[3] = newModeIndex.ToString();
					obj[4] = ")";
					LoggingPlugin.LogDebug(string.Concat(obj));
					waypoints.ruler = (RulerType)newModeIndex;
					if (newModeIndex == 2)
					{
						SystemMessage.DisplayInfoText("Replicator Plugin:\r\nCone Ruler Not Supported In Replicator Mode", 2.5f, 0f, (Action)null);
						waypoints.collecting = false;
					}
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Ruler), "OnClick")]
		public static class PatchOnClick
		{
			[CompilerGenerated]
			private sealed class <closeRuler>d__2 : IEnumerator<object>, IDisposable, IEnumerator
			{
				private int <>1__state;

				private object <>2__current;

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

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

				[DebuggerHidden]
				public <closeRuler>d__2(int <>1__state)
				{
					this.<>1__state = <>1__state;
				}

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					//IL_0038: Unknown result type (might be due to invalid IL or missing references)
					//IL_0042: Expected O, but got Unknown
					//IL_005f: Unknown result type (might be due to invalid IL or missing references)
					//IL_0069: Expected O, but got Unknown
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						UI_Rulers.EnableRulers(false);
						<>2__current = (object)new WaitForSeconds(0.1f);
						<>1__state = 1;
						return true;
					case 1:
						<>1__state = -1;
						UI_Rulers.EnableRulers(true);
						<>2__current = (object)new WaitForSeconds(0.1f);
						<>1__state = 2;
						return true;
					case 2:
						<>1__state = -1;
						UI_Rulers.EnableRulers(false);
						return false;
					}
				}

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

				[DebuggerHidden]
				void IEnumerator.Reset()
				{
					throw new NotSupportedException();
				}
			}

			public static bool Prefix(Ruler __instance, int buttonId)
			{
				return true;
			}

			public static void Postfix(Ruler __instance, int buttonId)
			{
				//IL_0365: Unknown result type (might be due to invalid IL or missing references)
				//IL_0375: Unknown result type (might be due to invalid IL or missing references)
				//IL_037a: Unknown result type (might be due to invalid IL or missing references)
				//IL_037f: Unknown result type (might be due to invalid IL or missing references)
				//IL_039a: Unknown result type (might be due to invalid IL or missing references)
				//IL_039f: Unknown result type (might be due to invalid IL or missing references)
				//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
				//IL_0491: Unknown result type (might be due to invalid IL or missing references)
				//IL_0496: Unknown result type (might be due to invalid IL or missing references)
				//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_04ba: Unknown result type (might be due to invalid IL or missing references)
				//IL_04f4: Unknown result type (might be due to invalid IL or missing references)
				//IL_0504: Unknown result type (might be due to invalid IL or missing references)
				//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
				//IL_020c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0211: Unknown result type (might be due to invalid IL or missing references)
				//IL_022e: Unknown result type (might be due to invalid IL or missing references)
				LoggingPlugin.LogDebug("Ruler " + ((Object)__instance).name + " Click: Button " + buttonId + ", Collecting: " + waypoints.collecting);
				if (!waypoints.collecting)
				{
					return;
				}
				waypoints.points.Clear();
				GameObject val = GameObject.Find(((Object)__instance).name);
				Vector3 val2;
				if ((Object)(object)val != (Object)null)
				{
					foreach (Transform item in ExtensionMethods.Children(val.transform))
					{
						LoggingPlugin.LogDebug("Ruler " + ((Object)__instance).name + ": Found Child: " + ((Object)item).name + " While Searching For " + waypoints.ruler.ToString() + "Indicator(Clone)");
						if (!(((Object)item).name == waypoints.ruler.ToString() + "Indicator(Clone)"))
						{
							continue;
						}
						LoggingPlugin.LogDebug("Ruler " + ((Object)__instance).name + ": Found " + ((Object)item).name + " With " + ExtensionMethods.Children(((Component)item).transform).Count() + " Children");
						foreach (Transform item2 in ExtensionMethods.Children(((Component)item).transform))
						{
							string text = waypoints.ruler.ToString();
							val2 = item2.position;
							LoggingPlugin.LogDebug(text + " Point: " + ((object)(Vector3)(ref val2)).ToString());
							if (item2.position != Vector3.zero)
							{
								waypoints.points.Add(item2.position);
							}
						}
					}
				}
				LoggingPlugin.LogDebug("Ruler " + ((Object)__instance).name + ": Collecting: " + waypoints.ruler.ToString() + ", Points Count: " + waypoints.points.Count + ", Button: " + buttonId);
				if (waypoints.collecting && waypoints.ruler == RulerType.Sphere && waypoints.points.Count == 2)
				{
					LoggingPlugin.LogDebug("Ruler " + ((Object)__instance).name + ": Applying Selection Based On " + waypoints.ruler);
					val2 = waypoints.points[0] - waypoints.points[1];
					float magnitude = ((Vector3)(ref val2)).magnitude;
					val2 = waypoints.points[0];
					LoggingPlugin.LogDebug("Center = " + ((object)(Vector3)(ref val2)).ToString() + ", Radius = " + magnitude);
					waypoints.collecting = false;
					((MonoBehaviour)_self).StartCoroutine(closeRuler());
					((MonoBehaviour)_self).StartCoroutine(ProcessShape.Sphere(waypoints.points[0], magnitude));
				}
				else if (waypoints.collecting && waypoints.ruler == RulerType.Box && waypoints.points.Count == 2)
				{
					LoggingPlugin.LogDebug("Ruler " + ((Object)__instance).name + ": Applying Selection Based On " + waypoints.ruler);
					waypoints.collecting = false;
					val2 = waypoints.points[0];
					string? text2 = ((object)(Vector3)(ref val2)).ToString();
					val2 = waypoints.points[1];
					LoggingPlugin.LogDebug("Corner1 = " + text2 + ", Corner2 = " + ((object)(Vector3)(ref val2)).ToString());
					((MonoBehaviour)_self).StartCoroutine(closeRuler());
					((MonoBehaviour)_self).StartCoroutine(ProcessShape.Box(waypoints.points[0], waypoints.points[1]));
				}
				else if (waypoints.collecting && waypoints.ruler == RulerType.Line && buttonId == 2)
				{
					LoggingPlugin.LogDebug("Ruler " + ((Object)__instance).name + ": Applying Selection Based On " + waypoints.ruler);
					waypoints.collecting = false;
					((MonoBehaviour)_self).StartCoroutine(closeRuler());
					((MonoBehaviour)_self).StartCoroutine(ProcessShape.Line(waypoints.points));
				}
			}

			[IteratorStateMachine(typeof(<closeRuler>d__2))]
			public static IEnumerator closeRuler()
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <closeRuler>d__2(0);
			}

			public static bool IsPointInsideBox(Vector3 cornerA, Vector3 cornerB, Vector3 point)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: 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_002b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0049: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0078: Unknown result type (might be due to invalid IL or missing references)
				//IL_0081: Unknown result type (might be due to invalid IL or missing references)
				//IL_008a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0093: Unknown result type (might be due to invalid IL or missing references)
				//IL_009d: Unknown result type (might be due to invalid IL or missing references)
				float num = Mathf.Min(cornerA.x, cornerB.x);
				float num2 = Mathf.Max(cornerA.x, cornerB.x);
				float num3 = Mathf.Min(cornerA.y, cornerB.y);
				float num4 = Mathf.Max(cornerA.y, cornerB.y);
				float num5 = Mathf.Min(cornerA.z, cornerB.z);
				float num6 = Mathf.Max(cornerA.z, cornerB.z);
				return point.x >= num && point.x <= num2 && point.y >= num3 && point.y <= num4 && point.z >= num5 && point.z <= num6;
			}
		}

		public static Waypoints waypoints = new Waypoints();
	}

	public static class ProcessShape
	{
		[CompilerGenerated]
		private sealed class <Box>d__2 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public Vector3 corner1;

			public Vector3 corner2;

			private Vector3 <center>5__1;

			private float <z>5__2;

			private float <x>5__3;

			private Vector3 <point>5__4;

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

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

			[DebuggerHidden]
			public <Box>d__2(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0030: 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)
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_004a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0095: Unknown result type (might be due to invalid IL or missing references)
				//IL_009a: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c2: 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: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
				int num = <>1__state;
				if (num != 0)
				{
					if (num != 1)
					{
						return false;
					}
					<>1__state = -1;
					<x>5__3 += 1f;
					goto IL_0105;
				}
				<>1__state = -1;
				LoggingPlugin.LogInfo("Replicating Within Box Base (Rectangle)");
				<center>5__1 = (corner1 + corner2) * 0.5f;
				<z>5__2 = corner1.z;
				goto IL_0135;
				IL_0105:
				if (<x>5__3 <= corner2.x)
				{
					<point>5__4 = new Vector3(<x>5__3, corner1.y, <z>5__2);
					LoggingPlugin.LogDebug("Create Instance At " + ((object)(Vector3)(ref <point>5__4)).ToString());
					<>2__current = SpawnCreatureAt(<point>5__4, GenerateLookAway(<point>5__4, <center>5__1));
					<>1__state = 1;
					return true;
				}
				<z>5__2 += 1f;
				goto IL_0135;
				IL_0135:
				if (<z>5__2 <= corner2.z)
				{
					<x>5__3 = corner1.x;
					goto IL_0105;
				}
				return false;
			}

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

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <Line>d__0 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public List<Vector3> points;

			private int <s>5__1;

			private float <distance>5__2;

			private Vector3 <delta>5__3;

			private int <d>5__4;

			private Vector3 <point>5__5;

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

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

			[DebuggerHidden]
			public <Line>d__0(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_005b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0077: Unknown result type (might be due to invalid IL or missing references)
				//IL_008a: 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_009a: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d7: 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_0104: Unknown result type (might be due to invalid IL or missing references)
				//IL_0117: Unknown result type (might be due to invalid IL or missing references)
				//IL_0126: Unknown result type (might be due to invalid IL or missing references)
				//IL_012b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0130: Unknown result type (might be due to invalid IL or missing references)
				int num = <>1__state;
				if (num != 0)
				{
					if (num != 1)
					{
						return false;
					}
					<>1__state = -1;
					<d>5__4++;
					goto IL_0160;
				}
				<>1__state = -1;
				LoggingPlugin.LogInfo("Replicating Along Line");
				<s>5__1 = 1;
				goto IL_0187;
				IL_0160:
				if ((float)<d>5__4 < <distance>5__2)
				{
					<point>5__5 = points[<s>5__1 - 1] + (float)<d>5__4 * <delta>5__3;
					LoggingPlugin.LogDebug("Create Instance At " + ((object)(Vector3)(ref <point>5__5)).ToString());
					<>2__current = SpawnCreatureAt(<point>5__5, points[<s>5__1 - 1] + (float)(<d>5__4 + 1) * <delta>5__3);
					<>1__state = 1;
					return true;
				}
				<s>5__1++;
				goto IL_0187;
				IL_0187:
				if (<s>5__1 < points.Count)
				{
					<distance>5__2 = Vector3.Distance(points[<s>5__1], points[<s>5__1 - 1]);
					<delta>5__3 = (points[<s>5__1] - points[<s>5__1 - 1]) / <distance>5__2;
					<d>5__4 = 1;
					goto IL_0160;
				}
				return false;
			}

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

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <Sphere>d__1 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public Vector3 center;

			public float radius;

			private int <z>5__1;

			private int <x>5__2;

			private Vector3 <point>5__3;

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

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

			[DebuggerHidden]
			public <Sphere>d__1(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0088: 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_0093: 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)
				//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
				int num = <>1__state;
				if (num != 0)
				{
					if (num != 1)
					{
						return false;
					}
					<>1__state = -1;
					goto IL_010d;
				}
				<>1__state = -1;
				LoggingPlugin.LogInfo("Replicating Within Sphere Base (Circle)");
				<z>5__1 = 0;
				goto IL_0151;
				IL_0151:
				if ((float)<z>5__1 < (radius + 0.5f) * 2f)
				{
					<x>5__2 = 0;
					goto IL_011e;
				}
				return false;
				IL_011e:
				if ((float)<x>5__2 < (radius + 0.5f) * 2f)
				{
					<point>5__3 = new Vector3(center.x - radius + (float)<x>5__2, center.y, center.z - radius + (float)<z>5__1);
					if (Vector3.Distance(center, <point>5__3) <= radius + 0.5f)
					{
						LoggingPlugin.LogDebug("Create Instance At " + ((object)(Vector3)(ref <point>5__3)).ToString());
						<>2__current = SpawnCreatureAt(<point>5__3, GenerateLookAway(<point>5__3, center));
						<>1__state = 1;
						return true;
					}
					goto IL_010d;
				}
				<z>5__1++;
				goto IL_0151;
				IL_010d:
				<x>5__2++;
				goto IL_011e;
			}

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

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[IteratorStateMachine(typeof(<Line>d__0))]
		public static IEnumerator Line(List<Vector3> points)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <Line>d__0(0)
			{
				points = points
			};
		}

		[IteratorStateMachine(typeof(<Sphere>d__1))]
		public static IEnumerator Sphere(Vector3 center, float radius)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <Sphere>d__1(0)
			{
				center = center,
				radius = radius
			};
		}

		[IteratorStateMachine(typeof(<Box>d__2))]
		public static IEnumerator Box(Vector3 corner1, Vector3 corner2)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <Box>d__2(0)
			{
				corner1 = corner1,
				corner2 = corner2
			};
		}
	}

	public class AssetTarget
	{
		public CreatureBoardAsset asset { get; set; }

		public bool selected { get; set; }

		public int distance { get; set; }
	}

	public static class Utility
	{
		public static void PostOnMainPage(BaseUnityPlugin plugin)
		{
			string text = "Lord Ashes" + ("Lord Ashes".ToUpper().EndsWith("S") ? "'" : "'s");
			ModdingUtils.AddPluginToMenuList(plugin, text);
		}
	}

	[CompilerGenerated]
	private sealed class <SpawnCreatureAt>d__2 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public Vector3 position;

		public Vector3 lookAt;

		private CreatureBoardAsset <source>5__1;

		private CreatureDataV4 <data>5__2;

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

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

		[DebuggerHidden]
		public <SpawnCreatureAt>d__2(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			<source>5__1 = null;
			<data>5__2 = default(CreatureDataV4);
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<source>5__1 = null;
				CreaturePresenter.TryGetAsset(LocalClient.SelectedCreatureId, ref <source>5__1);
				if ((Object)(object)<source>5__1 != (Object)null)
				{
					CreatureManager.TryGetCreatureData(LocalClient.SelectedCreatureId, ref <data>5__2);
					<data>5__2.CreatureId = default(CreatureGuid);
					Patches.waypoints.spawnInProgress = new TaskCompletionSource<bool>();
					Patches.waypoints.link = <source>5__1.Link;
					Patches.waypoints.lookAt = lookAt;
					string[] obj = new string[6]
					{
						"Spawning At ",
						((object)(Vector3)(ref position)).ToString(),
						" Rotation ",
						null,
						null,
						null
					};
					Quaternion rotation = ((MovableBoardAsset)<source>5__1).Rotator.rotation;
					obj[3] = ((object)(Quaternion)(ref rotation)).ToString();
					obj[4] = " With Link ";
					obj[5] = ((Patches.waypoints.link != null) ? Patches.waypoints.link : "Null");
					LoggingPlugin.LogDebug(string.Concat(obj));
					CreatureManager.TryCreateAndAddNewCreature(<data>5__2, float3.op_Implicit(position), quaternion.op_Implicit(((MovableBoardAsset)<source>5__1).Rotator.rotation), false, false, false);
					<>2__current = (object)new WaitUntil((Func<bool>)(() => Patches.waypoints.spawnInProgress.Task.IsCompleted));
					<>1__state = 1;
					return true;
				}
				break;
			case 1:
				<>1__state = -1;
				<data>5__2 = default(CreatureDataV4);
				break;
			}
			return false;
		}

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

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	public const string Name = "Replicator Plugin";

	public const string Guid = "org.lordashes.plugins.replicator";

	public const string Version = "2.0.0.0";

	public const string Author = "Lord Ashes";

	public static ReplicatorPlugin _self;

	private KeyboardShortcut toggleReplicatorSelection;

	[IteratorStateMachine(typeof(<SpawnCreatureAt>d__2))]
	public static IEnumerator SpawnCreatureAt(Vector3 position, Vector3 lookAt)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <SpawnCreatureAt>d__2(0)
		{
			position = position,
			lookAt = lookAt
		};
	}

	private static Vector3 GenerateLookAway(Vector3 source, Vector3 lookAt)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = source - lookAt;
		return source + val;
	}

	private void Awake()
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Expected O, but got Unknown
		_self = this;
		LoggingPlugin.SetLogLevel(((BaseUnityPlugin)this).Config.Bind<DiagnosticLevel>("Settings", "Diagnostic Level", (DiagnosticLevel)3, (ConfigDescription)null).Value);
		string? assemblyQualifiedName = ((object)this).GetType().AssemblyQualifiedName;
		DiagnosticLevel logLevel = LoggingPlugin.GetLogLevel();
		LoggingPlugin.LogInfo(assemblyQualifiedName + ": Active. (Diagnostic Mode = " + ((object)(DiagnosticLevel)(ref logLevel)).ToString() + ")");
		toggleReplicatorSelection = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "Activate Replication", new KeyboardShortcut((KeyCode)277, Array.Empty<KeyCode>()), (ConfigDescription)null).Value;
		Harmony val = new Harmony("org.lordashes.plugins.replicator");
		val.PatchAll();
		Utility.PostOnMainPage((BaseUnityPlugin)(object)this);
	}

	private void Update()
	{
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		if (!((KeyboardShortcut)(ref toggleReplicatorSelection)).IsUp())
		{
			return;
		}
		Patches.waypoints.collecting = !Patches.waypoints.collecting;
		if (Patches.waypoints.collecting)
		{
			Patches.waypoints.points.Clear();
			CreatureBoardAsset val = default(CreatureBoardAsset);
			CreaturePresenter.TryGetAsset(LocalClient.SelectedCreatureId, ref val);
			if ((Object)(object)val == (Object)null)
			{
				SystemMessage.DisplayInfoText("Replicator Plugin:\r\nA Source Mini Must Be Selected To Use Replicate.", 2.5f, 0f, (Action)null);
				Patches.waypoints.collecting = false;
			}
			else
			{
				UI_Rulers.EnableRulers(true);
			}
		}
		else
		{
			Patches.waypoints.collecting = false;
			Patches.waypoints.link = null;
		}
	}

	private void OnGUI()
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		if (Patches.waypoints.collecting)
		{
			GUI.Label(new Rect((float)(Screen.width - 320), (float)(Screen.height - 150), 120f, 30f), "[REPLICATOR]");
		}
	}
}