Decompiled source of UXAssist v1.0.23

UXAssist.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CommonAPI;
using CommonAPI.Systems;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UXAssist.Common;
using UXAssist.UI;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("UXAssist")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("DSP MOD - UXAssist")]
[assembly: AssemblyFileVersion("1.0.23.0")]
[assembly: AssemblyInformationalVersion("1.0.23+a359f789e73ef39e4f7850d345f1beddecf84e19")]
[assembly: AssemblyProduct("UXAssist")]
[assembly: AssemblyTitle("UXAssist")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.23.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace UXAssist
{
	public static class DysonSpherePatch
	{
		private static class StopEjectOnNodeComplete
		{
			private static Harmony _patch;

			private static HashSet<int>[] _nodeForAbsorb;

			private static bool _initialized;

			public static void Enable(bool on)
			{
				if (on)
				{
					InitNodeForAbsorb();
					if (_patch == null)
					{
						_patch = Harmony.CreateAndPatchAll(typeof(StopEjectOnNodeComplete), (string)null);
					}
					return;
				}
				Harmony patch = _patch;
				if (patch != null)
				{
					patch.UnpatchSelf();
				}
				_patch = null;
				_initialized = false;
				_nodeForAbsorb = null;
			}

			private static void InitNodeForAbsorb()
			{
				_initialized = false;
				_nodeForAbsorb = null;
				GameData data = GameMain.data;
				GalaxyData val = data?.galaxy;
				if (val == null)
				{
					return;
				}
				int starCount = val.starCount;
				_nodeForAbsorb = new HashSet<int>[starCount];
				DysonSphere[] dysonSpheres = data.dysonSpheres;
				if (dysonSpheres == null)
				{
					return;
				}
				DysonSphere[] array = dysonSpheres;
				foreach (DysonSphere val2 in array)
				{
					if (val2?.layersSorted == null)
					{
						continue;
					}
					int index = val2.starData.index;
					if (index >= starCount)
					{
						continue;
					}
					DysonSphereLayer[] layersSorted = val2.layersSorted;
					foreach (DysonSphereLayer val3 in layersSorted)
					{
						if (val3 == null)
						{
							continue;
						}
						for (int num = val3.nodeCursor - 1; num > 0; num--)
						{
							DysonNode val4 = val3.nodePool[num];
							if (val4 != null && val4.id == num && val4.sp >= val4.spMax && val4.cpReqOrder != 0)
							{
								SetNodeForAbsorb(index, val3.id, val4.id, canAbsorb: true);
							}
						}
					}
				}
				_initialized = true;
			}

			private static void SetNodeForAbsorb(int index, int layerId, int nodeId, bool canAbsorb)
			{
				ref HashSet<int> reference = ref _nodeForAbsorb[index];
				if (reference == null)
				{
					reference = new HashSet<int>();
				}
				int item = nodeId * 10 + layerId;
				if (canAbsorb)
				{
					reference.Add(item);
				}
				else
				{
					reference.Remove(item);
				}
			}

			private static void UpdateNodeForAbsorbOnSpChange(DysonNode node)
			{
				if (_initialized && node.sp >= node.spMax && node.cpReqOrder > 0)
				{
					List<DysonShell> shells = node.shells;
					if (shells.Count != 0)
					{
						SetNodeForAbsorb(shells[0].dysonSphere.starData.index, node.layerId, node.id, canAbsorb: true);
					}
				}
			}

			private static void UpdateNodeForAbsorbOnCpChange(DysonNode node)
			{
				if (_initialized && node.sp >= node.spMax && node.cpReqOrder <= 0)
				{
					List<DysonShell> shells = node.shells;
					if (shells.Count != 0)
					{
						SetNodeForAbsorb(shells[0].dysonSphere.starData.index, node.layerId, node.id, canAbsorb: false);
					}
				}
			}

			private static bool AnyNodeForAbsorb(int starIndex)
			{
				HashSet<int> hashSet = _nodeForAbsorb[starIndex];
				if (hashSet != null)
				{
					return hashSet.Count > 0;
				}
				return false;
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(GameMain), "Begin")]
			private static void GameMain_Begin_Postfix()
			{
				InitNodeForAbsorb();
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(GameMain), "End")]
			private static void GameMain_End_Postfix()
			{
				_initialized = false;
				_nodeForAbsorb = null;
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(DysonNode), "RecalcCpReq")]
			private static void DysonNode_RecalcCpReq_Postfix(DysonNode __instance)
			{
				UpdateNodeForAbsorbOnCpChange(__instance);
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(DysonSphereLayer), "RemoveDysonNode")]
			private static void DysonSphereLayer_RemoveDysonNode_Prefix(DysonSphereLayer __instance, int nodeId)
			{
				if (_initialized)
				{
					SetNodeForAbsorb(__instance.starData.index, __instance.id, nodeId, canAbsorb: false);
				}
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(DysonSphere), "ResetNew")]
			private static void DysonSphere_ResetNew_Prefix(DysonSphere __instance)
			{
				if (_nodeForAbsorb != null)
				{
					int index = __instance.starData.index;
					if (index < _nodeForAbsorb.Length && _nodeForAbsorb[index] != null)
					{
						_nodeForAbsorb[index].Clear();
						_nodeForAbsorb[index] = null;
					}
				}
			}

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(EjectorComponent), "InternalUpdate")]
			private static IEnumerable<CodeInstruction> EjectorComponent_InternalUpdate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Expected O, but got Unknown
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Expected O, but got Unknown
				//IL_0059: Unknown result type (might be due to invalid IL or missing references)
				//IL_005f: Expected O, but got Unknown
				//IL_0078: Unknown result type (might be due to invalid IL or missing references)
				//IL_007e: Expected O, but got Unknown
				//IL_0086: 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_009a: Expected O, but got Unknown
				//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bb: Expected O, but got Unknown
				//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00dc: Expected O, but got Unknown
				//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ff: Expected O, but got Unknown
				//IL_0107: Unknown result type (might be due to invalid IL or missing references)
				//IL_010d: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[3]
				{
					new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(EjectorComponent), "orbitId"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Brtrue, (object)null, (string)null)
				}).Advance(2).Insert((CodeInstruction[])(object)new CodeInstruction[7]
				{
					new CodeInstruction(OpCodes.Ldc_I4_0, (object)null),
					new CodeInstruction(OpCodes.Cgt, (object)null),
					new CodeInstruction(OpCodes.Ldarg_2, (object)null),
					new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(DysonSwarm), "starData")),
					new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(StarData), "index")),
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(StopEjectOnNodeComplete), "AnyNodeForAbsorb", (Type[])null, (Type[])null)),
					new CodeInstruction(OpCodes.And, (object)null)
				});
				return val.InstructionEnumeration();
			}

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(DysonNode), "ConstructSp")]
			private static IEnumerable<CodeInstruction> DysonNode_ConstructSp_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Expected O, but got Unknown
				//IL_006b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0076: 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
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.Start().MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(DysonNode), "sp"), (string)null)
				}).Advance(1);
				List<Label> labels = val.Labels;
				val.Labels = new List<Label>();
				val.Insert((CodeInstruction[])(object)new CodeInstruction[2]
				{
					CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Ldarg_0, (object)null), (IEnumerable<Label>)labels),
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(StopEjectOnNodeComplete), "UpdateNodeForAbsorbOnSpChange", (Type[])null, (Type[])null))
				});
				return val.InstructionEnumeration();
			}

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(DysonNode), "ConstructCp")]
			private static IEnumerable<CodeInstruction> DysonNode_ConstructCp_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Expected O, but got Unknown
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Expected O, but got Unknown
				//IL_0059: Unknown result type (might be due to invalid IL or missing references)
				//IL_005f: Expected O, but got Unknown
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0073: Expected O, but got Unknown
				//IL_0081: Unknown result type (might be due to invalid IL or missing references)
				//IL_0087: Expected O, but got Unknown
				//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ae: Expected O, but got Unknown
				//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cd: Expected O, but got Unknown
				//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f0: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.MatchBack(false, (CodeMatch[])(object)new CodeMatch[6]
				{
					new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(DysonNode), "_cpReq"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldc_I4_1, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Sub, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(DysonNode), "_cpReq"), (string)null)
				}).Advance(6).Insert((CodeInstruction[])(object)new CodeInstruction[2]
				{
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(StopEjectOnNodeComplete), "UpdateNodeForAbsorbOnCpChange", (Type[])null, (Type[])null))
				});
				return val.InstructionEnumeration();
			}
		}

		private static class OnlyConstructNodes
		{
			private static Harmony _patch;

			public static void Enable(bool on)
			{
				if (on)
				{
					if (_patch == null)
					{
						_patch = Harmony.CreateAndPatchAll(typeof(OnlyConstructNodes), (string)null);
					}
				}
				else
				{
					Harmony patch = _patch;
					if (patch != null)
					{
						patch.UnpatchSelf();
					}
					_patch = null;
				}
				DysonSphere[] array = GameMain.data?.dysonSpheres;
				if (array == null)
				{
					return;
				}
				DysonSphere[] array2 = array;
				foreach (DysonSphere val in array2)
				{
					if (val != null)
					{
						val.CheckAutoNodes();
						if (val.autoNodeCount <= 0)
						{
							val.PickAutoNode();
							val.PickAutoNode();
							val.PickAutoNode();
							val.PickAutoNode();
						}
					}
				}
			}

			[HarmonyTranspiler]
			[HarmonyPatch(/*Could not decode attribute arguments.*/)]
			private static IEnumerable<CodeInstruction> DysonNode_spReqOrder_Getter_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Expected O, but got Unknown
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Expected O, but got Unknown
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0079: Expected O, but got Unknown
				//IL_0087: Unknown result type (might be due to invalid IL or missing references)
				//IL_008d: Expected O, but got Unknown
				//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ae: Expected O, but got Unknown
				//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bc: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[2]
				{
					new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(DysonNode), "_spReq"), (string)null)
				}).Advance(1).SetInstructionAndAdvance(new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(DysonNode), "spMax")))
					.Insert((CodeInstruction[])(object)new CodeInstruction[3]
					{
						new CodeInstruction(OpCodes.Ldarg_0, (object)null),
						new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(DysonNode), "sp")),
						new CodeInstruction(OpCodes.Sub, (object)null)
					});
				return val.InstructionEnumeration();
			}
		}

		public static ConfigEntry<bool> StopEjectOnNodeCompleteEnabled;

		public static ConfigEntry<bool> OnlyConstructNodesEnabled;

		private static Harmony _dysonSpherePatch;

		public static void Init()
		{
			if (_dysonSpherePatch == null)
			{
				_dysonSpherePatch = Harmony.CreateAndPatchAll(typeof(DysonSpherePatch), (string)null);
			}
			StopEjectOnNodeCompleteEnabled.SettingChanged += delegate
			{
				StopEjectOnNodeComplete.Enable(StopEjectOnNodeCompleteEnabled.Value);
			};
			OnlyConstructNodesEnabled.SettingChanged += delegate
			{
				OnlyConstructNodes.Enable(OnlyConstructNodesEnabled.Value);
			};
			StopEjectOnNodeComplete.Enable(StopEjectOnNodeCompleteEnabled.Value);
			OnlyConstructNodes.Enable(OnlyConstructNodesEnabled.Value);
		}

		public static void Uninit()
		{
			StopEjectOnNodeComplete.Enable(on: false);
			OnlyConstructNodes.Enable(on: false);
			Harmony dysonSpherePatch = _dysonSpherePatch;
			if (dysonSpherePatch != null)
			{
				dysonSpherePatch.UnpatchSelf();
			}
			_dysonSpherePatch = null;
		}

		public static void InitCurrentDysonSphere(int index)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			StarData localStar = GameMain.localStar;
			if (localStar == null)
			{
				return;
			}
			DysonSphere[] array = GameMain.data?.dysonSpheres;
			if (array == null)
			{
				return;
			}
			if (index < 0)
			{
				if (array[localStar.index] != null)
				{
					DysonSphere val = new DysonSphere();
					array[localStar.index] = val;
					val.Init(GameMain.data, localStar);
					val.ResetNew();
				}
				return;
			}
			DysonSphere val2 = array[localStar.index];
			if (((val2 != null) ? val2.layersIdBased[index] : null) == null)
			{
				return;
			}
			DysonRocket[] rocketPool = val2.rocketPool;
			for (int num = val2.rocketCursor - 1; num > 0; num--)
			{
				if (rocketPool[num].id == num && rocketPool[num].nodeLayerId == index)
				{
					val2.RemoveDysonRocket(num);
				}
			}
			val2.RemoveLayer(index);
		}

		[HarmonyTranspiler]
		[HarmonyPriority(800)]
		[HarmonyPatch(typeof(DysonNode), "ConstructCp")]
		private static IEnumerable<CodeInstruction> DysonSpherePatch_DysonNode_ConstructCp_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected O, but got Unknown
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Expected O, but got Unknown
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(instructions, generator);
			val.MatchBack(false, (CodeMatch[])(object)new CodeMatch[2]
			{
				new CodeMatch((OpCode?)OpCodes.Ldc_I4_0, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(DysonShell), "Construct", (Type[])null, (Type[])null), (string)null)
			}).Advance(3).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[6]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(DysonNode), "_cpReq")),
				new CodeInstruction(OpCodes.Ldc_I4_1, (object)null),
				new CodeInstruction(OpCodes.Sub, (object)null),
				new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(DysonNode), "_cpReq"))
			});
			val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[2]
			{
				new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(DysonNode), "RecalcCpReq", (Type[])null, (Type[])null), (string)null)
			});
			List<Label> labels = val.Labels;
			val.RemoveInstructions(2).Labels.AddRange(labels);
			return val.InstructionEnumeration();
		}
	}
	public static class FactoryPatch
	{
		public static class NightLight
		{
			private static Harmony _patch;

			private const float NightLightAngleX = -8f;

			private const float NightLightAngleY = -2f;

			public static bool Enabled;

			private static bool _nightlightInitialized;

			private static bool _mechaOnEarth;

			private static AnimationState _sail;

			private static Light _sunlight;

			public static void Enable(bool on)
			{
				//IL_0068: Unknown result type (might be due to invalid IL or missing references)
				if (on)
				{
					Enabled = _mechaOnEarth;
					if (_patch == null)
					{
						_patch = Harmony.CreateAndPatchAll(typeof(NightLight), (string)null);
					}
					return;
				}
				Enabled = false;
				Harmony patch = _patch;
				if (patch != null)
				{
					patch.UnpatchSelf();
				}
				_patch = null;
				if (!((Object)(object)_sunlight == (Object)null))
				{
					((Component)_sunlight).transform.localEulerAngles = new Vector3(0f, 180f);
				}
			}

			public static void LateUpdate()
			{
				if (_patch != null)
				{
					if (!_nightlightInitialized)
					{
						Ready();
					}
					else
					{
						Go();
					}
				}
			}

			private static void Ready()
			{
				if (GameMain.isRunning && ((Component)GameMain.mainPlayer.controller.model).gameObject.activeInHierarchy)
				{
					if ((TrackedReference)(object)_sail == (TrackedReference)null)
					{
						_sail = GameMain.mainPlayer.animator.sails[GameMain.mainPlayer.animator.sailAnimIndex];
					}
					_nightlightInitialized = true;
				}
			}

			private static void Go()
			{
				//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_010c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0116: Unknown result type (might be due to invalid IL or missing references)
				//IL_0120: 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_0134: Unknown result type (might be due to invalid IL or missing references)
				//IL_013e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0148: 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_0152: 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)
				if (!GameMain.isRunning)
				{
					End();
					return;
				}
				if (TrackedReference.op_Implicit((TrackedReference)(object)_sail) && _sail.enabled)
				{
					_mechaOnEarth = false;
					Enabled = false;
					if (Object.op_Implicit((Object)(object)_sunlight) && Object.op_Implicit((Object)(object)((Component)_sunlight).transform))
					{
						((Component)_sunlight).transform.localEulerAngles = new Vector3(0f, 180f);
						_sunlight = null;
					}
					return;
				}
				if (!_mechaOnEarth)
				{
					if (!Object.op_Implicit((Object)(object)_sunlight))
					{
						UniverseSimulator universeSimulator = GameMain.universeSimulator;
						if (Object.op_Implicit((Object)(object)universeSimulator))
						{
							_sunlight = universeSimulator.LocalStarSimulator()?.sunLight;
						}
						if (!Object.op_Implicit((Object)(object)_sunlight))
						{
							return;
						}
					}
					_mechaOnEarth = true;
					Enabled = NightLightEnabled.Value;
				}
				if (Enabled && Object.op_Implicit((Object)(object)_sunlight))
				{
					((Component)_sunlight).transform.rotation = Quaternion.LookRotation(-GameMain.mainPlayer.transform.up + GameMain.mainPlayer.transform.forward * -8f / 10f + GameMain.mainPlayer.transform.right * -2f / 10f);
				}
			}

			private static void End()
			{
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				_mechaOnEarth = false;
				Enabled = false;
				if ((Object)(object)_sunlight != (Object)null)
				{
					((Component)_sunlight).transform.localEulerAngles = new Vector3(0f, 180f);
					_sunlight = null;
				}
				_sail = null;
				_nightlightInitialized = false;
			}

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(StarSimulator), "LateUpdate")]
			private static IEnumerable<CodeInstruction> StarSimulator_LateUpdate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0032: Expected O, but got Unknown
				//IL_0053: Unknown result type (might be due to invalid IL or missing references)
				//IL_0059: Expected O, but got Unknown
				//IL_007f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0085: Expected O, but got Unknown
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				//IL_0098: Expected O, but got Unknown
				//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b9: Expected O, but got Unknown
				//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00da: Expected O, but got Unknown
				//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fb: Expected O, but got Unknown
				//IL_0103: Unknown result type (might be due to invalid IL or missing references)
				//IL_0109: Expected O, but got Unknown
				//IL_0116: Unknown result type (might be due to invalid IL or missing references)
				//IL_011c: Expected O, but got Unknown
				//IL_0145: Unknown result type (might be due to invalid IL or missing references)
				//IL_014b: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				Label label = generator.DefineLabel();
				Label label2 = generator.DefineLabel();
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[2]
				{
					new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.PropertyGetter(typeof(Component), "transform"), (string)null)
				}).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[7]
				{
					new CodeInstruction(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(NightLight), "Enabled")),
					new CodeInstruction(OpCodes.Brfalse_S, (object)label),
					new CodeInstruction(OpCodes.Call, (object)AccessTools.PropertyGetter(typeof(GameMain), "mainPlayer")),
					new CodeInstruction(OpCodes.Callvirt, (object)AccessTools.PropertyGetter(typeof(Player), "transform")),
					new CodeInstruction(OpCodes.Callvirt, (object)AccessTools.PropertyGetter(typeof(Transform), "up")),
					new CodeInstruction(OpCodes.Stloc_0, (object)null),
					new CodeInstruction(OpCodes.Br_S, (object)label2)
				});
				val.Labels.Add(label);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Stloc_0, (object)null, (string)null)
				}).Advance(1).Labels.Add(label2);
				return val.InstructionEnumeration();
			}

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(PlanetSimulator), "LateUpdate")]
			private static IEnumerable<CodeInstruction> PlanetSimulator_LateUpdate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0032: Expected O, but got Unknown
				//IL_005e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0064: Expected O, but got Unknown
				//IL_0071: Unknown result type (might be due to invalid IL or missing references)
				//IL_0077: Expected O, but got Unknown
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				//IL_0098: Expected O, but got Unknown
				//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b9: Expected O, but got Unknown
				//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00da: Expected O, but got Unknown
				//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e8: Expected O, but got Unknown
				//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fb: Expected O, but got Unknown
				//IL_0137: Unknown result type (might be due to invalid IL or missing references)
				//IL_013d: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				Label label = generator.DefineLabel();
				Label label2 = generator.DefineLabel();
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Stloc_1, (object)null, (string)null)
				}).Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[7]
				{
					new CodeInstruction(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(NightLight), "Enabled")),
					new CodeInstruction(OpCodes.Brfalse_S, (object)label),
					new CodeInstruction(OpCodes.Call, (object)AccessTools.PropertyGetter(typeof(GameMain), "mainPlayer")),
					new CodeInstruction(OpCodes.Callvirt, (object)AccessTools.PropertyGetter(typeof(Player), "transform")),
					new CodeInstruction(OpCodes.Callvirt, (object)AccessTools.PropertyGetter(typeof(Transform), "up")),
					new CodeInstruction(OpCodes.Stloc_2, (object)null),
					new CodeInstruction(OpCodes.Br_S, (object)label2)
				});
				val.Labels.Add(label);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Ldsfld, (object)AccessTools.Field(typeof(FactoryModel), "whiteMode0"), (string)null)
				}).Labels.Add(label2);
				return val.InstructionEnumeration();
			}
		}

		private static class UnlimitInteractive
		{
			private static Harmony _patch;

			public static void Enable(bool enable)
			{
				if (enable)
				{
					if (_patch == null)
					{
						_patch = Harmony.CreateAndPatchAll(typeof(UnlimitInteractive), (string)null);
					}
					return;
				}
				Harmony patch = _patch;
				if (patch != null)
				{
					patch.UnpatchSelf();
				}
				_patch = null;
			}

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(PlayerAction_Inspect), "GetObjectSelectDistance")]
			private static IEnumerable<CodeInstruction> PlayerAction_Inspect_GetObjectSelectDistance_Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				yield return new CodeInstruction(OpCodes.Ldc_R4, (object)10000f);
				yield return new CodeInstruction(OpCodes.Ret, (object)null);
			}
		}

		private static class RemoveSomeConditionBuild
		{
			private static Harmony _patch;

			public static void Enable(bool on)
			{
				if (on)
				{
					if (_patch == null)
					{
						_patch = Harmony.CreateAndPatchAll(typeof(RemoveSomeConditionBuild), (string)null);
					}
					return;
				}
				Harmony patch = _patch;
				if (patch != null)
				{
					patch.UnpatchSelf();
				}
				_patch = null;
			}

			[HarmonyTranspiler]
			[HarmonyPriority(800)]
			[HarmonyPatch(typeof(BuildTool_BlueprintPaste), "CheckBuildConditions")]
			[HarmonyPatch(typeof(BuildTool_Click), "CheckBuildConditions")]
			private static IEnumerable<CodeInstruction> BuildTool_Click_CheckBuildConditions_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Expected O, but got Unknown
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Expected O, but got Unknown
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ae: Expected O, but got Unknown
				//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d5: Expected O, but got Unknown
				//IL_010b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0116: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[6]
				{
					new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(BuildPreview), "desc"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(PrefabDesc), "isInserter"), (string)null),
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction instr) => instr.opcode == OpCodes.Brtrue || instr.opcode == OpCodes.Brtrue_S), (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldloca_S, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.PropertyGetter(typeof(Vector3), "magnitude"), (string)null)
				});
				object operand = val.InstructionAt(3).operand;
				List<Label> labels = val.Labels;
				val.Labels = new List<Label>();
				val.Insert((CodeInstruction[])(object)new CodeInstruction[1] { CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Br, operand), (IEnumerable<Label>)labels) });
				return val.InstructionEnumeration();
			}

			[HarmonyTranspiler]
			[HarmonyPriority(800)]
			[HarmonyPatch(typeof(BuildTool_Path), "CheckBuildConditions")]
			private static IEnumerable<CodeInstruction> BuildTool_Path_CheckBuildConditions_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Expected O, but got Unknown
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Expected O, but got Unknown
				//IL_005a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Expected O, but got Unknown
				//IL_0082: Unknown result type (might be due to invalid IL or missing references)
				//IL_0088: Expected O, but got Unknown
				//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b0: Expected O, but got Unknown
				//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d8: Expected O, but got Unknown
				//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ff: Expected O, but got Unknown
				//IL_0192: Unknown result type (might be due to invalid IL or missing references)
				//IL_0198: Expected O, but got Unknown
				//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c0: Expected O, but got Unknown
				//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e7: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[7]
				{
					new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null),
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction instr) => instr.opcode == OpCodes.Brtrue_S || instr.opcode == OpCodes.Brtrue), (string)null),
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction instr) => instr.opcode == OpCodes.Ldc_I4_S && CodeInstructionExtensions.OperandIs(instr, (object)19)), (string)null),
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction instr) => instr.opcode == OpCodes.Br_S || instr.opcode == OpCodes.Br), (string)null),
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction instr) => instr.opcode == OpCodes.Ldc_I4_S && CodeInstructionExtensions.OperandIs(instr, (object)18)), (string)null),
					new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(BuildPreview), "condition"), (string)null)
				});
				if (val.IsValid)
				{
					List<Label> labels = val.Labels;
					val.Labels = new List<Label>();
					val.RemoveInstructions(7);
					OpCode opcode = val.Opcode;
					if (opcode == OpCodes.Br || opcode == OpCodes.Br_S)
					{
						val.RemoveInstruction();
					}
					val.Labels.AddRange(labels);
				}
				val.Start().MatchForward(false, (CodeMatch[])(object)new CodeMatch[3]
				{
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction instr) => instr.opcode == OpCodes.Ldloc_S || instr.opcode == OpCodes.Ldloc), (string)null),
					new CodeMatch((Func<CodeInstruction, bool>)delegate(CodeInstruction instr)
					{
						if (instr.opcode == OpCodes.Ldc_I4_S || instr.opcode == OpCodes.Ldc_I4)
						{
							long num = Convert.ToInt64(instr.operand);
							if (num >= 16)
							{
								return num <= 20;
							}
							return false;
						}
						return false;
					}, (string)null),
					new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(BuildPreview), "condition"), (string)null)
				});
				if (val.IsValid)
				{
					val.Repeat((Action<CodeMatcher>)delegate(CodeMatcher codeMatcher)
					{
						List<Label> labels2 = codeMatcher.Labels;
						codeMatcher.Labels = new List<Label>();
						codeMatcher.RemoveInstructions(3);
						OpCode opcode2 = codeMatcher.Opcode;
						if (opcode2 == OpCodes.Br || opcode2 == OpCodes.Br_S)
						{
							codeMatcher.RemoveInstruction();
						}
						codeMatcher.Labels.AddRange(labels2);
					}, (Action<string>)null);
				}
				return val.InstructionEnumeration();
			}
		}

		private static class RemoveBuildRangeLimit
		{
			private static Harmony _patch;

			public static void Enable(bool enable)
			{
				if (enable)
				{
					if (_patch == null)
					{
						_patch = Harmony.CreateAndPatchAll(typeof(RemoveBuildRangeLimit), (string)null);
					}
				}
				else
				{
					Harmony patch = _patch;
					if (patch != null)
					{
						patch.UnpatchSelf();
					}
					_patch = null;
				}
				Player mainPlayer = GameMain.mainPlayer;
				PlayerController val = ((mainPlayer != null) ? mainPlayer.controller : null);
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				PlayerAction_Build actionBuild = val.actionBuild;
				if (actionBuild != null)
				{
					BuildTool_Click clickTool = actionBuild.clickTool;
					if (clickTool != null)
					{
						((BuildTool)clickTool)._OnInit();
					}
				}
			}

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(BuildTool_Click), "_OnInit")]
			private static IEnumerable<CodeInstruction> BuildTool_Click__OnInit_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => ci.opcode == OpCodes.Ldc_I4_S && CodeInstructionExtensions.OperandIs(ci, (object)15)), (string)null)
				});
				val.Repeat((Action<CodeMatcher>)delegate(CodeMatcher m)
				{
					m.SetAndAdvance(OpCodes.Ldc_I4, (object)512);
				}, (Action<string>)null);
				return val.InstructionEnumeration();
			}

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(BuildTool_Addon), "CheckBuildConditions")]
			[HarmonyPatch(typeof(BuildTool_Click), "CheckBuildConditions")]
			[HarmonyPatch(typeof(BuildTool_Dismantle), "DetermineMoreChainTargets")]
			[HarmonyPatch(typeof(BuildTool_Dismantle), "DeterminePreviews")]
			[HarmonyPatch(typeof(BuildTool_Inserter), "CheckBuildConditions")]
			[HarmonyPatch(typeof(BuildTool_Path), "CheckBuildConditions")]
			[HarmonyPatch(typeof(BuildTool_Reform), "ReformAction")]
			[HarmonyPatch(typeof(BuildTool_Upgrade), "DetermineMoreChainTargets")]
			[HarmonyPatch(typeof(BuildTool_Upgrade), "DeterminePreviews")]
			private static IEnumerable<CodeInstruction> BuildAreaLimitRemoval_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Expected O, but got Unknown
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Expected O, but got Unknown
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Expected O, but got Unknown
				//IL_0093: Unknown result type (might be due to invalid IL or missing references)
				//IL_0099: Expected O, but got Unknown
				//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ac: Expected O, but got Unknown
				//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d3: Expected O, but got Unknown
				//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fa: Expected O, but got Unknown
				//IL_011b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0121: Expected O, but got Unknown
				//IL_012f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0135: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[9]
				{
					new CodeMatch((OpCode?)null, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.PropertyGetter(typeof(BuildTool), "player"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.PropertyGetter(typeof(Player), "mecha"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(Mecha), "buildArea"), (string)null),
					new CodeMatch((OpCode?)null, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.PropertyGetter(typeof(BuildTool), "player"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.PropertyGetter(typeof(Player), "mecha"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(Mecha), "buildArea"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Mul, (object)null, (string)null)
				});
				val.Repeat((Action<CodeMatcher>)delegate(CodeMatcher m)
				{
					//IL_001f: Unknown result type (might be due to invalid IL or missing references)
					//IL_0025: Expected O, but got Unknown
					m.RemoveInstructions(9).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
					{
						new CodeInstruction(OpCodes.Ldc_R4, (object)100000000f)
					});
				}, (Action<string>)null);
				return val.InstructionEnumeration();
			}
		}

		private static class LargerAreaForUpgradeAndDismantle
		{
			private static Harmony _patch;

			public static void Enable(bool enable)
			{
				if (enable)
				{
					if (_patch == null)
					{
						_patch = Harmony.CreateAndPatchAll(typeof(LargerAreaForUpgradeAndDismantle), (string)null);
					}
					return;
				}
				Harmony patch = _patch;
				if (patch != null)
				{
					patch.UnpatchSelf();
				}
				_patch = null;
			}

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(BuildTool_Dismantle), "DeterminePreviews")]
			[HarmonyPatch(typeof(BuildTool_Upgrade), "DeterminePreviews")]
			private static IEnumerable<CodeInstruction> BuildTools_CursorSizePatch_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => ci.opcode == OpCodes.Ldc_I4_S && CodeInstructionExtensions.OperandIs(ci, (object)11)), (string)null)
				});
				val.Repeat((Action<CodeMatcher>)delegate(CodeMatcher m)
				{
					m.SetAndAdvance(OpCodes.Ldc_I4_S, (object)31);
				}, (Action<string>)null);
				return val.InstructionEnumeration();
			}
		}

		private static class LargerAreaForTerraform
		{
			private static Harmony _patch;

			public static void Enable(bool enable)
			{
				if (enable)
				{
					if (_patch == null)
					{
						_patch = Harmony.CreateAndPatchAll(typeof(LargerAreaForTerraform), (string)null);
					}
					return;
				}
				Harmony patch = _patch;
				if (patch != null)
				{
					patch.UnpatchSelf();
				}
				_patch = null;
			}

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(BuildTool_Reform), "ReformAction")]
			private static IEnumerable<CodeInstruction> BuildTool_Reform_ReformAction_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Expected O, but got Unknown
				//IL_0059: Unknown result type (might be due to invalid IL or missing references)
				//IL_005f: Expected O, but got Unknown
				//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c1: Expected O, but got Unknown
				//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e8: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[2]
				{
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(BuildTool_Reform), "brushSize"), (string)null),
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => ci.opcode == OpCodes.Ldc_I4_S && CodeInstructionExtensions.OperandIs(ci, (object)10)), (string)null)
				});
				val.Repeat((Action<CodeMatcher>)delegate(CodeMatcher m)
				{
					m.Advance(1).SetAndAdvance(OpCodes.Ldc_I4_S, (object)30);
				}, (Action<string>)null);
				val.Start().MatchForward(false, (CodeMatch[])(object)new CodeMatch[2]
				{
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => ci.opcode == OpCodes.Ldc_I4_S && CodeInstructionExtensions.OperandIs(ci, (object)10)), (string)null),
					new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(BuildTool_Reform), "brushSize"), (string)null)
				});
				val.Repeat((Action<CodeMatcher>)delegate(CodeMatcher m)
				{
					m.SetAndAdvance(OpCodes.Ldc_I4_S, (object)30);
				}, (Action<string>)null);
				return val.InstructionEnumeration();
			}
		}

		public static class OffGridBuilding
		{
			private static Harmony _patch;

			private const float SteppedRotationDegrees = 15f;

			private static bool _initialized;

			private static PlanetData _lastPlanet;

			private static Vector3 _lastPos;

			private static string _lastOffsetText;

			public static void Enable(bool enable)
			{
				if (enable)
				{
					if (_patch == null)
					{
						_patch = Harmony.CreateAndPatchAll(typeof(OffGridBuilding), (string)null);
					}
					return;
				}
				Harmony patch = _patch;
				if (patch != null)
				{
					patch.UnpatchSelf();
				}
				_patch = null;
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(UIRoot), "_OnOpen")]
			public static void UIRoot__OnOpen_Postfix()
			{
				if (!_initialized)
				{
					UIGeneralTips.instance.buildCursorTextComp.supportRichText = true;
					UIGeneralTips.instance.entityBriefInfo.entityNameText.supportRichText = true;
					_initialized = true;
				}
			}

			private static void CalculateGridOffset(PlanetData planet, Vector3 pos, out float x, out float y, out float z)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				Vector3 normalized = ((Vector3)(ref pos)).normalized;
				int num = planet.aux.activeGrid?.segment ?? 200;
				float latitudeRadPerGrid = BlueprintUtils.GetLatitudeRadPerGrid(num);
				float longitudeRadPerGrid = BlueprintUtils.GetLongitudeRadPerGrid(BlueprintUtils.GetLongitudeSegmentCount(normalized, num), num);
				float latitudeRad = BlueprintUtils.GetLatitudeRad(normalized);
				float longitudeRad = BlueprintUtils.GetLongitudeRad(normalized);
				x = longitudeRad / longitudeRadPerGrid;
				y = latitudeRad / latitudeRadPerGrid;
				z = (((Vector3)(ref pos)).magnitude - planet.realRadius - 0.2f) / 1.3333333f;
			}

			private static string FormatOffsetFloat(float f)
			{
				return f.ToString("0.0000").TrimEnd(new char[1] { '0' }).TrimEnd(new char[1] { '.' });
			}

			[HarmonyPostfix]
			[HarmonyPriority(0)]
			[HarmonyPatch(typeof(BuildTool_Click), "CheckBuildConditions")]
			[HarmonyPatch(typeof(BuildTool_Path), "CheckBuildConditions")]
			private static void BuildTool_Click_CheckBuildConditions_Postfix(BuildTool __instance)
			{
				//IL_0058: 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_0074: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				int count = __instance.buildPreviews.Count;
				if (count == 0)
				{
					return;
				}
				BuildPreview val = __instance.buildPreviews[count - 1];
				if (!val.desc.isInserter)
				{
					PlanetData planet = __instance.planet;
					if (_lastPlanet != planet || _lastPos != val.lpos)
					{
						CalculateGridOffset(__instance.planet, val.lpos, out var x, out var y, out var z);
						_lastPlanet = planet;
						_lastPos = val.lpos;
						_lastOffsetText = ((z < 0.001f && z > -0.001f) ? ("<color=#ffbfbfff>" + FormatOffsetFloat(x) + "</color>,<color=#bfffbfff>" + FormatOffsetFloat(y) + "</color>") : ("<color=#ffbfbfff>" + FormatOffsetFloat(x) + "</color>,<color=#bfffbfff>" + FormatOffsetFloat(y) + "</color>,<color=#bfbfffff>" + FormatOffsetFloat(z) + "</color>"));
					}
					__instance.actionBuild.model.cursorText = "(" + _lastOffsetText + ")\n" + __instance.actionBuild.model.cursorText;
				}
			}

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(UIEntityBriefInfo), "_OnUpdate")]
			private static IEnumerable<CodeInstruction> UIEntityBriefInfo__OnUpdate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Expected O, but got Unknown
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Expected O, but got Unknown
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Expected O, but got Unknown
				//IL_0087: Unknown result type (might be due to invalid IL or missing references)
				//IL_008d: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[3]
				{
					new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(UIEntityBriefInfo), "entityNameText"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.PropertyGetter(typeof(Text), "preferredWidth"), (string)null)
				});
				val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2]
				{
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					Transpilers.EmitDelegate<Action<UIEntityBriefInfo>>((Action<UIEntityBriefInfo>)delegate(UIEntityBriefInfo entityBriefInfo)
					{
						//IL_0011: 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)
						//IL_0017: Unknown result type (might be due to invalid IL or missing references)
						//IL_0048: Unknown result type (might be due to invalid IL or missing references)
						//IL_0049: Unknown result type (might be due to invalid IL or missing references)
						//IL_005f: Unknown result type (might be due to invalid IL or missing references)
						//IL_0060: Unknown result type (might be due to invalid IL or missing references)
						//IL_0065: Unknown result type (might be due to invalid IL or missing references)
						//IL_0035: Unknown result type (might be due to invalid IL or missing references)
						//IL_003a: 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)
						EntityData val2 = entityBriefInfo.factory.entityPool[entityBriefInfo.entityId];
						if (val2.inserterId <= 0)
						{
							PlanetData planet = entityBriefInfo.factory.planet;
							if (_lastPlanet != planet || _lastPos != val2.pos)
							{
								CalculateGridOffset(planet, val2.pos, out var x, out var y, out var z);
								_lastPlanet = planet;
								_lastPos = val2.pos;
								_lastOffsetText = "<color=#ffbfbfff>" + FormatOffsetFloat(x) + "</color>,<color=#bfffbfff>" + FormatOffsetFloat(y) + "</color>,<color=#bfbfffff>" + FormatOffsetFloat(z) + "</color>";
							}
							Text entityNameText = entityBriefInfo.entityNameText;
							entityNameText.text = entityNameText.text + " (" + _lastOffsetText + ")";
						}
					})
				});
				return val.InstructionEnumeration();
			}

			private static void MatchIgnoreGridAndCheckIfRotatable(CodeMatcher matcher, out Label? ifBlockEntryLabel, out Label? elseBlockEntryLabel)
			{
				//IL_0049: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: Expected O, but got Unknown
				//IL_005e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0064: Expected O, but got Unknown
				//IL_0086: Unknown result type (might be due to invalid IL or missing references)
				//IL_008c: Expected O, but got Unknown
				//IL_009a: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a0: Expected O, but got Unknown
				//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b4: Expected O, but got Unknown
				//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00dc: Expected O, but got Unknown
				//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f1: Expected O, but got Unknown
				//IL_0113: Unknown result type (might be due to invalid IL or missing references)
				//IL_0119: Expected O, but got Unknown
				//IL_0127: Unknown result type (might be due to invalid IL or missing references)
				//IL_012d: Expected O, but got Unknown
				//IL_013c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0142: Expected O, but got Unknown
				Label? thisIfBlockEntryLabel = null;
				Label? thisElseBlockEntryLabel = null;
				matcher.MatchForward(false, (CodeMatch[])(object)new CodeMatch[10]
				{
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.Calls(ci, AccessTools.PropertyGetter(typeof(VFInput), "_ignoreGrid"))), (string)null),
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.Branches(ci, ref thisElseBlockEntryLabel)), (string)null),
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsLdarg(ci, (int?)null)), (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)null, (string)null),
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.LoadsConstant(ci, (Enum)(object)(EMinerType)2)), (string)null),
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.Branches(ci, ref thisIfBlockEntryLabel)), (string)null),
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsLdarg(ci, (int?)null)), (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)null, (string)null)
				});
				ifBlockEntryLabel = thisIfBlockEntryLabel;
				elseBlockEntryLabel = thisElseBlockEntryLabel;
			}

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(BuildTool_Click), "UpdateRaycast")]
			[HarmonyPatch(typeof(BuildTool_Click), "DeterminePreviews")]
			public static IEnumerable<CodeInstruction> AllowOffGridConstruction(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				MatchIgnoreGridAndCheckIfRotatable(val, out var ifBlockEntryLabel, out var _);
				if (val.IsInvalid)
				{
					return instructions;
				}
				val.Advance(2);
				val.Insert((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Br, (object)ifBlockEntryLabel.Value)
				});
				return val.InstructionEnumeration();
			}

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(BuildTool_Click), "DeterminePreviews")]
			public static IEnumerable<CodeInstruction> PreventDraggingWhenOffGrid(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: Expected O, but got Unknown
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Expected O, but got Unknown
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Expected O, but got Unknown
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0073: Expected O, but got Unknown
				//IL_0095: Unknown result type (might be due to invalid IL or missing references)
				//IL_009b: Expected O, but got Unknown
				//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00db: Expected O, but got Unknown
				//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f3: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				Label? exitLabel = null;
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[4]
				{
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.Branches(ci, ref exitLabel)), (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.LoadsConstant(ci, 1L)), (string)null),
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.StoresField(ci, AccessTools.Field(typeof(BuildTool_Click), "isDragging"))), (string)null)
				});
				if (val.IsInvalid)
				{
					return instructions;
				}
				val.Advance(1);
				val.Insert((CodeInstruction[])(object)new CodeInstruction[2]
				{
					new CodeInstruction(OpCodes.Call, (object)AccessTools.PropertyGetter(typeof(VFInput), "_ignoreGrid")),
					new CodeInstruction(OpCodes.Brtrue, (object)exitLabel)
				});
				return val.InstructionEnumeration();
			}

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(BuildTool_Path), "UpdateRaycast")]
			public static IEnumerable<CodeInstruction> AllowOffGridConstructionForPath(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Expected O, but got Unknown
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: Expected O, but got Unknown
				//IL_005a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Expected O, but got Unknown
				//IL_0081: Unknown result type (might be due to invalid IL or missing references)
				//IL_0087: Expected O, but got Unknown
				//IL_0095: Unknown result type (might be due to invalid IL or missing references)
				//IL_009b: Expected O, but got Unknown
				//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c2: Expected O, but got Unknown
				//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d6: Expected O, but got Unknown
				//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fd: Expected O, but got Unknown
				//IL_0120: Unknown result type (might be due to invalid IL or missing references)
				//IL_0126: Expected O, but got Unknown
				//IL_0148: Unknown result type (might be due to invalid IL or missing references)
				//IL_014e: Expected O, but got Unknown
				//IL_0194: Unknown result type (might be due to invalid IL or missing references)
				//IL_019a: Expected O, but got Unknown
				//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01bb: Expected O, but got Unknown
				//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ce: Expected O, but got Unknown
				//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
				//IL_01dc: Expected O, but got Unknown
				//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ea: Expected O, but got Unknown
				//IL_0205: Unknown result type (might be due to invalid IL or missing references)
				//IL_020b: Expected O, but got Unknown
				//IL_0226: Unknown result type (might be due to invalid IL or missing references)
				//IL_022c: Expected O, but got Unknown
				//IL_0234: Unknown result type (might be due to invalid IL or missing references)
				//IL_023a: Expected O, but got Unknown
				//IL_0255: Unknown result type (might be due to invalid IL or missing references)
				//IL_025b: Expected O, but got Unknown
				//IL_0277: Unknown result type (might be due to invalid IL or missing references)
				//IL_027d: Expected O, but got Unknown
				//IL_028f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0295: Expected O, but got Unknown
				//IL_029e: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a4: Expected O, but got Unknown
				//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
				//IL_02e7: Expected O, but got Unknown
				//IL_0303: Unknown result type (might be due to invalid IL or missing references)
				//IL_0309: Expected O, but got Unknown
				//IL_0317: Unknown result type (might be due to invalid IL or missing references)
				//IL_031d: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[10]
				{
					new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.PropertyGetter(typeof(BuildTool), "actionBuild"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(PlayerAction_Build), "planetAux"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(BuildTool_Path), "castGroundPos"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(BuildTool_Path), "castTerrain"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(PlanetAuxData), "Snap", (Type[])null, (Type[])null), (string)null),
					new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(BuildTool_Path), "castGroundPosSnapped"), (string)null)
				});
				if (val.IsInvalid)
				{
					return val.InstructionEnumeration();
				}
				Label label = generator.DefineLabel();
				Label label2 = generator.DefineLabel();
				val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[15]
				{
					new CodeInstruction(OpCodes.Call, (object)AccessTools.PropertyGetter(typeof(VFInput), "_switchModelStyle")),
					new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(InputValue), "pressing")),
					new CodeInstruction(OpCodes.Brfalse, (object)label),
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					new CodeInstruction(OpCodes.Ldflda, (object)AccessTools.Field(typeof(BuildTool_Path), "castGroundPos")),
					new CodeInstruction(OpCodes.Call, (object)AccessTools.PropertyGetter(typeof(Vector3), "normalized")),
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(BuildTool_Path), "planet")),
					new CodeInstruction(OpCodes.Callvirt, (object)AccessTools.PropertyGetter(typeof(PlanetData), "realRadius")),
					new CodeInstruction(OpCodes.Ldc_R4, (object)0.2f),
					new CodeInstruction(OpCodes.Add, (object)null),
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Vector3), "op_Multiply", new Type[2]
					{
						typeof(Vector3),
						typeof(float)
					}, (Type[])null)),
					new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(BuildTool_Path), "castGroundPosSnapped")),
					new CodeInstruction(OpCodes.Br, (object)label2)
				}).Labels.Add(label);
				val.Advance(10).Labels.Add(label2);
				return val.InstructionEnumeration();
			}

			public static IEnumerable<CodeInstruction> PatchToPerformSteppedRotate(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: Expected O, but got Unknown
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_0068: Expected O, but got Unknown
				//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
				//IL_0104: Expected O, but got Unknown
				//IL_010c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0112: Expected O, but got Unknown
				//IL_013d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0143: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				MatchIgnoreGridAndCheckIfRotatable(val, out var ifBlockEntryLabel, out var elseBlockEntryLabel);
				if (val.IsInvalid)
				{
					return instructions;
				}
				while (!val.Labels.Contains(elseBlockEntryLabel.Value))
				{
					val.Advance(1);
				}
				Label? ifBlockExitLabel = null;
				val.MatchBack(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.Branches(ci, ref ifBlockExitLabel)), (string)null)
				});
				if (val.IsInvalid)
				{
					return instructions;
				}
				while (!val.Labels.Contains(ifBlockEntryLabel.Value))
				{
					val.Advance(-1);
				}
				CodeInstruction val2 = val.Instruction.Clone();
				CodeInstruction val3 = CodeInstruction.LoadField(typeof(VFInput), "control", false);
				val.SetAndAdvance(val3.opcode, val3.operand);
				val.Insert((CodeInstruction[])(object)new CodeInstruction[1] { val2 });
				Label label = default(Label);
				val.CreateLabel(ref label);
				val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[4]
				{
					new CodeInstruction(OpCodes.Brfalse, (object)label),
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					CodeInstruction.Call(typeof(OffGridBuilding), "RotateStepped", (Type[])null, (Type[])null),
					new CodeInstruction(OpCodes.Br, (object)ifBlockExitLabel)
				});
				return val.InstructionEnumeration();
			}

			public static void RotateStepped(BuildTool_Click instance)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0051: Unknown result type (might be due to invalid IL or missing references)
				if (VFInput._rotate.onDown)
				{
					instance.yaw += 15f;
					instance.yaw = Mathf.Repeat(instance.yaw, 360f);
					instance.yaw = Mathf.Round(instance.yaw / 15f) * 15f;
				}
				if (VFInput._counterRotate.onDown)
				{
					instance.yaw -= 15f;
					instance.yaw = Mathf.Repeat(instance.yaw, 360f);
					instance.yaw = Mathf.Round(instance.yaw / 15f) * 15f;
				}
			}
		}

		public static class LogisticsCapacityTweaks
		{
			private static Harmony _patch;

			private static KeyCode _lastKey;

			private static long _nextKeyTick;

			private static bool _skipNextEvent;

			public static void Enable(bool enable)
			{
				if (enable)
				{
					if (_patch == null)
					{
						_patch = Harmony.CreateAndPatchAll(typeof(LogisticsCapacityTweaks), (string)null);
					}
					return;
				}
				Harmony patch = _patch;
				if (patch != null)
				{
					patch.UnpatchSelf();
				}
				_patch = null;
			}

			private static bool UpdateKeyPressed(KeyCode code)
			{
				//IL_0000: 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_0012: 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)
				if (!Input.GetKey(code))
				{
					return false;
				}
				if (code != _lastKey)
				{
					_lastKey = code;
					_nextKeyTick = GameMain.instance.timei + 30;
					return true;
				}
				long timei = GameMain.instance.timei;
				if (_nextKeyTick > timei)
				{
					return false;
				}
				_nextKeyTick = timei + 4;
				return true;
			}

			public static void OnUpdate()
			{
				//IL_0000: 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_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_0076: Unknown result type (might be due to invalid IL or missing references)
				//IL_007b: Unknown result type (might be due to invalid IL or missing references)
				//IL_007c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0081: Unknown result type (might be due to invalid IL or missing references)
				//IL_0091: Expected O, but got Unknown
				//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)
				if ((int)_lastKey != 0 && Input.GetKeyUp(_lastKey))
				{
					_lastKey = (KeyCode)0;
				}
				if (!VFInput.noModifier)
				{
					return;
				}
				int num;
				if (UpdateKeyPressed((KeyCode)276))
				{
					num = -10;
				}
				else if (UpdateKeyPressed((KeyCode)275))
				{
					num = 10;
				}
				else if (UpdateKeyPressed((KeyCode)274))
				{
					num = -100;
				}
				else
				{
					if (!UpdateKeyPressed((KeyCode)273))
					{
						return;
					}
					num = 100;
				}
				List<RaycastResult> list = new List<RaycastResult>();
				EventSystem.current.RaycastAll(new PointerEventData(EventSystem.current)
				{
					position = Vector2.op_Implicit(Input.mousePosition)
				}, list);
				foreach (RaycastResult item in list)
				{
					RaycastResult current = item;
					UIStationStorage componentInParent = ((RaycastResult)(ref current)).gameObject.GetComponentInParent<UIStationStorage>();
					if (componentInParent == null)
					{
						continue;
					}
					StationComponent station = componentInParent.station;
					ref StationStore reference = ref station.storage[componentInParent.index];
					int max = reference.max;
					int num2 = max + num;
					if (num2 < 0)
					{
						num2 = 0;
					}
					else
					{
						ModelProto val = ((ProtoSet<ModelProto>)(object)LDB.models).Select((int)componentInParent.stationWindow.factory.entityPool[station.entityId].modelIndex);
						int num3 = 0;
						if (val != null)
						{
							num3 = val.prefabDesc.stationMaxItemCount;
						}
						num3 += (station.isStellar ? GameMain.history.remoteStationExtraStorage : GameMain.history.localStationExtraStorage);
						if (num2 > num3)
						{
							num2 = num3;
						}
					}
					reference.max = num2;
					_skipNextEvent = max / 100 != num2 / 100;
					break;
				}
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(UIStationStorage), "OnMaxSliderValueChange")]
			private static bool UIStationStorage_OnMaxSliderValueChange_Prefix()
			{
				if (!_skipNextEvent)
				{
					return true;
				}
				_skipNextEvent = false;
				return false;
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(PlanetTransport), "OnTechFunctionUnlocked")]
			private static bool PlanetTransport_OnTechFunctionUnlocked_Prefix(PlanetTransport __instance, int _funcId, double _valuelf, int _level)
			{
				switch (_funcId)
				{
				case 30:
				{
					StationComponent[] stationPool2 = __instance.stationPool;
					PlanetFactory factory2 = __instance.factory;
					GameHistoryData history2 = GameMain.history;
					for (int num6 = __instance.stationCursor - 1; num6 > 0; num6--)
					{
						if (stationPool2[num6] != null && stationPool2[num6].id == num6 && (!stationPool2[num6].isStellar || stationPool2[num6].isCollector || stationPool2[num6].isVeinCollector))
						{
							short modelIndex2 = factory2.entityPool[stationPool2[num6].entityId].modelIndex;
							int stationMaxItemCount2 = ((ProtoSet<ModelProto>)(object)LDB.models).Select((int)modelIndex2).prefabDesc.stationMaxItemCount;
							double num7 = (double)(stationMaxItemCount2 + history2.localStationExtraStorage) - _valuelf;
							int num8 = (int)Math.Round(num7);
							double num9 = (double)(stationMaxItemCount2 + history2.localStationExtraStorage) / num7;
							StationStore[] storage2 = stationPool2[num6].storage;
							for (int num10 = storage2.Length - 1; num10 >= 0; num10--)
							{
								if (storage2[num10].max + 10 >= num8)
								{
									storage2[num10].max = Mathf.RoundToInt((float)((double)storage2[num10].max * num9 / 50.0)) * 50;
								}
							}
						}
					}
					break;
				}
				case 31:
				{
					StationComponent[] stationPool = __instance.stationPool;
					PlanetFactory factory = __instance.factory;
					GameHistoryData history = GameMain.history;
					for (int num = __instance.stationCursor - 1; num > 0; num--)
					{
						if (stationPool[num] != null && stationPool[num].id == num && stationPool[num].isStellar && !stationPool[num].isCollector && !stationPool[num].isVeinCollector)
						{
							short modelIndex = factory.entityPool[stationPool[num].entityId].modelIndex;
							int stationMaxItemCount = ((ProtoSet<ModelProto>)(object)LDB.models).Select((int)modelIndex).prefabDesc.stationMaxItemCount;
							double num2 = (double)(stationMaxItemCount + history.remoteStationExtraStorage) - _valuelf;
							int num3 = (int)Math.Round(num2);
							double num4 = (double)(stationMaxItemCount + history.remoteStationExtraStorage) / num2;
							StationStore[] storage = stationPool[num].storage;
							for (int num5 = storage.Length - 1; num5 >= 0; num5--)
							{
								if (storage[num5].max + 10 >= num3)
								{
									storage[num5].max = Mathf.RoundToInt((float)((double)storage[num5].max * num4 / 100.0)) * 100;
								}
							}
						}
					}
					break;
				}
				}
				return false;
			}
		}

		public static class TreatStackingAsSingle
		{
			private static Harmony _patch;

			public static void Enable(bool enable)
			{
				if (enable)
				{
					if (_patch == null)
					{
						_patch = Harmony.CreateAndPatchAll(typeof(TreatStackingAsSingle), (string)null);
					}
					return;
				}
				Harmony patch = _patch;
				if (patch != null)
				{
					patch.UnpatchSelf();
				}
				_patch = null;
			}

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(MonitorComponent), "InternalUpdate")]
			private static IEnumerable<CodeInstruction> MonitorComponent_InternalUpdate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: Expected O, but got Unknown
				//IL_0065: Unknown result type (might be due to invalid IL or missing references)
				//IL_006b: Expected O, but got Unknown
				//IL_0073: Unknown result type (might be due to invalid IL or missing references)
				//IL_0079: 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
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(MonitorComponent), "GetCargoAtIndexByFilter", (Type[])null, (Type[])null), (string)null)
				});
				val.Advance(-3);
				object operand = val.Operand;
				val.Advance(4).Insert((CodeInstruction[])(object)new CodeInstruction[3]
				{
					new CodeInstruction(OpCodes.Ldloca, operand),
					new CodeInstruction(OpCodes.Ldc_I4_1, (object)null),
					new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(Cargo), "stack"))
				});
				return val.InstructionEnumeration();
			}
		}

		private static class QuickBuildAndDismantleLab
		{
			private static Harmony _patch;

			public static void Enable(bool enable)
			{
				if (enable)
				{
					if (_patch == null)
					{
						_patch = Harmony.CreateAndPatchAll(typeof(QuickBuildAndDismantleLab), (string)null);
					}
					return;
				}
				Harmony patch = _patch;
				if (patch != null)
				{
					patch.UnpatchSelf();
				}
				_patch = null;
			}

			private static bool DetermineMoreLabsForDismantle(BuildTool dismantle, int id)
			{
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0054: Unknown result type (might be due to invalid IL or missing references)
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0064: Unknown result type (might be due to invalid IL or missing references)
				//IL_0071: Unknown result type (might be due to invalid IL or missing references)
				//IL_0079: Unknown result type (might be due to invalid IL or missing references)
				//IL_007a: Unknown result type (might be due to invalid IL or missing references)
				//IL_007c: 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_0086: 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_0089: Unknown result type (might be due to invalid IL or missing references)
				//IL_008e: 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_0094: Unknown result type (might be due to invalid IL or missing references)
				//IL_0096: Unknown result type (might be due to invalid IL or missing references)
				//IL_009b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a0: 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_00a3: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_010e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0113: Unknown result type (might be due to invalid IL or missing references)
				//IL_011e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0123: 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_0138: Unknown result type (might be due to invalid IL or missing references)
				//IL_0139: Unknown result type (might be due to invalid IL or missing references)
				//IL_013b: 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_0146: Unknown result type (might be due to invalid IL or missing references)
				//IL_0148: 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_0152: Unknown result type (might be due to invalid IL or missing references)
				//IL_0153: Unknown result type (might be due to invalid IL or missing references)
				//IL_0155: Unknown result type (might be due to invalid IL or missing references)
				//IL_015a: Unknown result type (might be due to invalid IL or missing references)
				//IL_015f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0160: Unknown result type (might be due to invalid IL or missing references)
				//IL_0162: Unknown result type (might be due to invalid IL or missing references)
				//IL_0167: Unknown result type (might be due to invalid IL or missing references)
				//IL_016c: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00df: Expected O, but got Unknown
				//IL_0195: Unknown result type (might be due to invalid IL or missing references)
				//IL_019e: Expected O, but got Unknown
				if (!VFInput._chainReaction)
				{
					return true;
				}
				PlanetFactory factory = dismantle.factory;
				if (!dismantle.GetPrefabDesc(id).isLab)
				{
					return true;
				}
				bool flag = default(bool);
				int num2 = default(int);
				int num = default(int);
				factory.ReadObjectConn(id, 14, ref flag, ref num, ref num2);
				if (num > 0)
				{
					int num3 = default(int);
					while (true)
					{
						factory.ReadObjectConn(num, 14, ref flag, ref num3, ref num2);
						if (num3 <= 0)
						{
							break;
						}
						Pose objectPose = dismantle.GetObjectPose(num);
						PrefabDesc prefabDesc = dismantle.GetPrefabDesc(num);
						BuildPreview item = new BuildPreview
						{
							item = dismantle.GetItemProto(num),
							desc = prefabDesc,
							lpos = objectPose.position,
							lrot = objectPose.rotation,
							lpos2 = objectPose.position,
							lrot2 = objectPose.rotation,
							objId = num,
							needModel = (prefabDesc.lodCount > 0 && (Object)(object)prefabDesc.lodMeshes[0] != (Object)null),
							isConnNode = true
						};
						dismantle.buildPreviews.Add(item);
						num = num3;
					}
				}
				num = id;
				while (true)
				{
					factory.ReadObjectConn(num, 15, ref flag, ref num, ref num2);
					if (num <= 0)
					{
						break;
					}
					Pose objectPose2 = dismantle.GetObjectPose(num);
					PrefabDesc prefabDesc2 = dismantle.GetPrefabDesc(num);
					BuildPreview item2 = new BuildPreview
					{
						item = dismantle.GetItemProto(num),
						desc = prefabDesc2,
						lpos = objectPose2.position,
						lrot = objectPose2.rotation,
						lpos2 = objectPose2.position,
						lrot2 = objectPose2.rotation,
						objId = num,
						needModel = (prefabDesc2.lodCount > 0 && (Object)(object)prefabDesc2.lodMeshes[0] != (Object)null),
						isConnNode = true
					};
					dismantle.buildPreviews.Add(item2);
				}
				return false;
			}

			private static void BuildLabsToTop(BuildTool_Click click)
			{
				if (!click.multiLevelCovering || !VFInput._chainReaction || !((BuildTool)click).GetPrefabDesc(click.castObjectId).isLab)
				{
					return;
				}
				int labLevel = GameMain.history.labLevel;
				PlanetFactory factory = ((BuildTool)click).factory;
				int i = 2;
				int castObjectId = click.castObjectId;
				bool flag = default(bool);
				int num = default(int);
				while (true)
				{
					factory.ReadObjectConn(castObjectId, 14, ref flag, ref castObjectId, ref num);
					if (castObjectId <= 0)
					{
						break;
					}
					i++;
				}
				for (; i < labLevel; i++)
				{
					click.UpdateRaycast();
					click.DeterminePreviews();
					((BuildTool)click).UpdateCollidersForCursor();
					click.UpdateCollidersForGiantBp();
					BuildModel model = ((BuildTool)click).actionBuild.model;
					((BuildTool)click).UpdatePreviewModels(model);
					if (!click.CheckBuildConditions())
					{
						model.ClearAllPreviewsModels();
						model.EarlyGameTickIgnoreActive();
						break;
					}
					((BuildTool)click).UpdatePreviewModelConditions(model);
					((BuildTool)click).UpdateGizmos(model);
					click.CreatePrebuilds();
				}
			}

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(BuildTool_Dismantle), "DeterminePreviews")]
			private static IEnumerable<CodeInstruction> BuildTool_Dismantle_DeterminePreviews_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Expected O, but got Unknown
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Expected O, but got Unknown
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Expected O, but got Unknown
				//IL_0080: Unknown result type (might be due to invalid IL or missing references)
				//IL_0086: Expected O, but got Unknown
				//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a7: Expected O, but got Unknown
				//IL_00af: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b5: Expected O, but got Unknown
				//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d6: Expected O, but got Unknown
				//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f9: Expected O, but got Unknown
				//IL_0101: Unknown result type (might be due to invalid IL or missing references)
				//IL_0107: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[4]
				{
					new CodeMatch((OpCode?)OpCodes.Ldloc_3, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(BuildPreview), "desc"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(PrefabDesc), "isBattleBase"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Brfalse, (object)null, (string)null)
				}).Advance(-1);
				val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[5]
				{
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					new CodeInstruction(OpCodes.Ldloc_3, (object)null),
					new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(BuildPreview), "objId")),
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(QuickBuildAndDismantleLab), "DetermineMoreLabsForDismantle", (Type[])null, (Type[])null)),
					new CodeInstruction(OpCodes.And, (object)null)
				});
				return val.InstructionEnumeration();
			}

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(BuildTool_Click), "_OnTick")]
			private static IEnumerable<CodeInstruction> BuildTool_Click__OnTick_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Expected O, but got Unknown
				//IL_0047: Unknown result type (might be due to invalid IL or missing references)
				//IL_004d: Expected O, but got Unknown
				//IL_0068: Unknown result type (might be due to invalid IL or missing references)
				//IL_006e: Expected O, but got Unknown
				//IL_008b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0091: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[2]
				{
					new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(BuildTool_Click), "CreatePrebuilds", (Type[])null, (Type[])null), (string)null)
				}).Advance(2);
				val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2]
				{
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(QuickBuildAndDismantleLab), "BuildLabsToTop", (Type[])null, (Type[])null))
				});
				return val.InstructionEnumeration();
			}
		}

		public static class ProtectVeinsFromExhaustion
		{
			public static int KeepVeinAmount = 100;

			public static float KeepOilSpeed = 1f;

			private static int _keepOilAmount = Math.Max((int)(KeepOilSpeed / 4E-05f + 0.5f), 2500);

			private static Harmony _patch;

			public static void Enable(bool enable)
			{
				if (enable)
				{
					if (_patch == null)
					{
						_patch = Harmony.CreateAndPatchAll(typeof(ProtectVeinsFromExhaustion), (string)null);
					}
					return;
				}
				Harmony patch = _patch;
				if (patch != null)
				{
					patch.UnpatchSelf();
				}
				_patch = null;
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(MinerComponent), "InternalUpdate")]
			private static bool MinerComponent_InternalUpdate_Prefix(PlanetFactory factory, VeinData[] veinPool, float power, float miningRate, float miningSpeed, int[] productRegister, ref MinerComponent __instance, out uint __result)
			{
				//IL_0012: 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)
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Expected I4, but got Unknown
				//IL_076b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0771: Invalid comparison between Unknown and I4
				//IL_0784: Unknown result type (might be due to invalid IL or missing references)
				//IL_078a: Invalid comparison between Unknown and I4
				//IL_0825: Unknown result type (might be due to invalid IL or missing references)
				//IL_082b: Invalid comparison between Unknown and I4
				//IL_034d: Unknown result type (might be due to invalid IL or missing references)
				//IL_035f: Unknown result type (might be due to invalid IL or missing references)
				//IL_05c3: Unknown result type (might be due to invalid IL or missing references)
				//IL_05cf: Unknown result type (might be due to invalid IL or missing references)
				//IL_05d9: Expected I4, but got Unknown
				//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
				//IL_02c3: Expected I4, but got Unknown
				//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
				//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
				//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
				if (power < 0.1f)
				{
					__result = 0u;
					return false;
				}
				uint num = 0u;
				EMinerType type = __instance.type;
				switch (type - 1)
				{
				case 1:
				{
					if (__instance.veinCount <= 0)
					{
						break;
					}
					if (__instance.time <= __instance.period)
					{
						__instance.time += (int)(power * __instance.speedDamper * (float)__instance.speed * miningSpeed * (float)__instance.veinCount);
						num = 1u;
					}
					if (__instance.time < __instance.period)
					{
						break;
					}
					int num3 = __instance.veins[__instance.currentVeinIndex];
					lock (veinPool)
					{
						if (veinPool[num3].id == 0)
						{
							((MinerComponent)(ref __instance)).RemoveVeinFromArray(__instance.currentVeinIndex);
							((MinerComponent)(ref __instance)).GetMinimumVeinAmount(factory, veinPool);
							if (__instance.veinCount > 1)
							{
								__instance.currentVeinIndex %= __instance.veinCount;
							}
							else
							{
								__instance.currentVeinIndex = 0;
							}
							__instance.time += (int)(power * __instance.speedDamper * (float)__instance.speed * miningSpeed * (float)__instance.veinCount);
							__result = 0u;
							return false;
						}
						if (__instance.productCount >= 50 || (__instance.productId != 0 && __instance.productId != veinPool[num3].productId))
						{
							break;
						}
						__instance.productId = veinPool[num3].productId;
						int num2 = __instance.time / __instance.period;
						int num4 = 0;
						int amount = veinPool[num3].amount;
						if (amount > KeepVeinAmount)
						{
							if (miningRate > 0f)
							{
								int num5 = 0;
								int num6 = amount - KeepVeinAmount;
								if (miningRate < 0.99999f)
								{
									for (int i = 0; i < num2; i++)
									{
										__instance.seed = (uint)((int)((ulong)((long)(__instance.seed % 2147483646 + 1) * 48271L) % 2147483647uL) - 1);
										num5 += (((double)__instance.seed / 2147483646.0 < (double)miningRate) ? 1 : 0);
										num4++;
										if (num5 == num6)
										{
											break;
										}
									}
								}
								else
								{
									num4 = ((num2 > num6) ? num6 : num2);
									num5 = num4;
								}
								if (num5 > 0)
								{
									int groupIndex = veinPool[num3].groupIndex;
									amount = (veinPool[num3].amount -= num5);
									if (amount < __instance.minimumVeinAmount)
									{
										__instance.minimumVeinAmount = amount;
									}
									factory.veinGroups[groupIndex].amount -= num5;
									factory.veinAnimPool[num3].time = ((amount >= 20000) ? 0f : 0.99995f);
									if (amount <= 0)
									{
										int num7 = (int)veinPool[num3].type;
										Vector3 pos = veinPool[num3].pos;
										factory.RemoveVeinWithComponents(num3);
										factory.RecalculateVeinGroup(groupIndex);
										factory.NotifyVeinExhausted(num7, pos);
										((MinerComponent)(ref __instance)).RemoveVeinFromArray(__instance.currentVeinIndex);
										((MinerComponent)(ref __instance)).GetMinimumVeinAmount(factory, veinPool);
									}
									else
									{
										__instance.currentVeinIndex++;
									}
								}
							}
							else
							{
								num4 = num2;
							}
							__instance.productCount += num4;
							lock (productRegister)
							{
								productRegister[__instance.productId] += num4;
								factory.AddMiningFlagUnsafe(veinPool[num3].type);
								factory.AddVeinMiningFlagUnsafe(veinPool[num3].type);
							}
						}
						else if (amount <= 0)
						{
							((MinerComponent)(ref __instance)).RemoveVeinFromArray(__instance.currentVeinIndex);
							((MinerComponent)(ref __instance)).GetMinimumVeinAmount(factory, veinPool);
						}
						else
						{
							__instance.currentVeinIndex++;
						}
						__instance.time -= __instance.period * num4;
						if (__instance.veinCount > 1)
						{
							__instance.currentVeinIndex %= __instance.veinCount;
						}
						else
						{
							__instance.currentVeinIndex = 0;
						}
					}
					break;
				}
				case 2:
				{
					if (__instance.veinCount <= 0)
					{
						break;
					}
					int num3 = __instance.veins[0];
					lock (veinPool)
					{
						int amount2 = veinPool[num3].amount;
						float num8 = (float)amount2 * VeinData.oilSpeedMultiplier;
						if (__instance.time < __instance.period)
						{
							__instance.time += (int)(power * __instance.speedDamper * (float)__instance.speed * miningSpeed * num8 + 0.5f);
							num = 1u;
						}
						if (__instance.time < __instance.period || __instance.productCount >= 50)
						{
							break;
						}
						__instance.productId = veinPool[num3].productId;
						int num2 = __instance.time / __instance.period;
						int num9 = 0;
						if (miningRate > 0f && amount2 > _keepOilAmount)
						{
							int num10 = 0;
							int num11 = amount2 - _keepOilAmount;
							for (int j = 0; j < num2; j++)
							{
								__instance.seed = (uint)((int)((ulong)((long)(__instance.seed % 2147483646 + 1) * 48271L) % 2147483647uL) - 1);
								num10 += (((double)__instance.seed / 2147483646.0 < (double)miningRate) ? 1 : 0);
								num9++;
							}
							if (num10 > 0)
							{
								if (num10 > num11)
								{
									num10 = num11;
								}
								amount2 = (veinPool[num3].amount -= num10);
								VeinGroup[] veinGroups = factory.veinGroups;
								short groupIndex2 = veinPool[num3].groupIndex;
								veinGroups[groupIndex2].amount -= num10;
								factory.veinAnimPool[num3].time = ((amount2 >= 25000) ? 0f : (1f - (float)amount2 * VeinData.oilSpeedMultiplier));
								if (amount2 <= 2500)
								{
									factory.NotifyVeinExhausted((int)veinPool[num3].type, veinPool[num3].pos);
								}
							}
						}
						else if (_keepOilAmount <= 2500)
						{
							num9 = num2;
						}
						if (num9 > 0)
						{
							__instance.productCount += num9;
							lock (productRegister)
							{
								productRegister[__instance.productId] += num9;
							}
							__instance.time -= __instance.period * num9;
						}
					}
					break;
				}
				case 0:
				{
					if (__instance.time < __instance.period)
					{
						__instance.time += (int)(power * __instance.speedDamper * (float)__instance.speed * miningSpeed);
						num = 1u;
					}
					if (__instance.time < __instance.period)
					{
						break;
					}
					int num2 = __instance.time / __instance.period;
					if (__instance.productCount >= 50)
					{
						break;
					}
					__instance.productId = factory.planet.waterItemId;
					if (__instance.productId > 0)
					{
						__instance.productCount += num2;
						lock (productRegister)
						{
							productRegister[__instance.productId] += num2;
						}
					}
					else
					{
						__instance.productId = 0;
					}
					__instance.time -= __instance.period * num2;
					break;
				}
				}
				if (__instance.productCount > 0 && __instance.insertTarget > 0 && __instance.productId > 0)
				{
					double num12 = 36000000.0 / (double)__instance.period * (double)miningSpeed;
					if ((int)__instance.type == 2)
					{
						num12 *= (double)__instance.veinCount;
					}
					else if ((int)__instance.type == 3)
					{
						num12 *= (double)((float)veinPool[__instance.veins[0]].amount * VeinData.oilSpeedMultiplier);
					}
					int num13 = (int)(num12 - 0.01) / 1800 + 1;
					num13 = ((num13 >= 4) ? 4 : ((num13 < 1) ? 1 : num13));
					int num14 = ((__instance.productCount < num13) ? __instance.productCount : num13);
					byte b = default(byte);
					int num15 = factory.InsertInto(__instance.insertTarget, 0, __instance.productId, (byte)num14, (byte)0, ref b);
					__instance.productCount -= num15;
					if (__instance.productCount == 0 && (int)__instance.type