Decompiled source of CheatEnabler v2.3.15

CheatEnabler.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CommonAPI.Systems;
using HarmonyLib;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using UXAssist;
using UXAssist.Common;
using UXAssist.UI;
using UnityEngine;
using UnityEngine.Events;

[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("CheatEnabler")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("DSP MOD - CheatEnabler")]
[assembly: AssemblyFileVersion("2.3.15.0")]
[assembly: AssemblyInformationalVersion("2.3.15+a359f789e73ef39e4f7850d345f1beddecf84e19")]
[assembly: AssemblyProduct("CheatEnabler")]
[assembly: AssemblyTitle("CheatEnabler")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.3.15.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 CheatEnabler
{
	public static class AbnormalDisabler
	{
		public static ConfigEntry<bool> Enabled;

		private static Dictionary<int, AbnormalityDeterminator> _savedDeterminators;

		private static Harmony _patch;

		public static void Init()
		{
			if (_patch == null)
			{
				_patch = Harmony.CreateAndPatchAll(typeof(AbnormalDisabler), (string)null);
			}
		}

		public static void Uninit()
		{
			Harmony patch = _patch;
			if (patch != null)
			{
				patch.UnpatchSelf();
			}
			_patch = null;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(AbnormalityLogic), "NotifyBeforeGameSave")]
		[HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnAssemblerRecipePick")]
		[HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnGameBegin")]
		[HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnMechaForgeTaskComplete")]
		[HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnUnlockTech")]
		[HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnUseConsole")]
		private static bool DisableAbnormalLogic()
		{
			return !Enabled.Value;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(AbnormalityLogic), "InitDeterminators")]
		private static void DisableAbnormalDeterminators(AbnormalityLogic __instance)
		{
			_savedDeterminators = __instance.determinators;
			Enabled.SettingChanged += delegate
			{
				if (Enabled.Value)
				{
					_savedDeterminators = __instance.determinators;
					__instance.determinators = new Dictionary<int, AbnormalityDeterminator>();
					{
						foreach (KeyValuePair<int, AbnormalityDeterminator> savedDeterminator in _savedDeterminators)
						{
							((DeterminatorBase)savedDeterminator.Value).OnUnregEvent();
						}
						return;
					}
				}
				__instance.determinators = _savedDeterminators;
				foreach (KeyValuePair<int, AbnormalityDeterminator> savedDeterminator2 in _savedDeterminators)
				{
					((DeterminatorBase)savedDeterminator2.Value).OnRegEvent();
				}
			};
			_savedDeterminators = __instance.determinators;
			if (!Enabled.Value)
			{
				return;
			}
			__instance.determinators = new Dictionary<int, AbnormalityDeterminator>();
			foreach (KeyValuePair<int, AbnormalityDeterminator> savedDeterminator3 in _savedDeterminators)
			{
				((DeterminatorBase)savedDeterminator3.Value).OnUnregEvent();
			}
		}
	}
	[BepInPlugin("org.soardev.cheatenabler", "CheatEnabler", "2.3.15")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class CheatEnabler : BaseUnityPlugin
	{
		public static readonly ManualLogSource Logger = Logger.CreateLogSource("CheatEnabler");

		private void Awake()
		{
			DevShortcuts.Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DevShortcuts", false, "Enable DevMode shortcuts");
			AbnormalDisabler.Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DisableAbnormalChecks", false, "disable all abnormal checks");
			TechPatch.Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "UnlockTech", false, "Unlock clicked tech by holding key-modifilers(Shift/Alt/Ctrl)");
			FactoryPatch.ImmediateEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Build", "ImmediateBuild", false, "Build immediately");
			FactoryPatch.ArchitectModeEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Build", "Architect", false, "Architect Mode");
			FactoryPatch.NoConditionEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Build", "BuildWithoutCondition", false, "Build without condition");
			FactoryPatch.NoCollisionEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Build", "NoCollision", false, "No collision");
			FactoryPatch.BeltSignalGeneratorEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Build", "BeltSignalGenerator", false, "Belt signal generator");
			FactoryPatch.BeltSignalNumberAltFormat = ((BaseUnityPlugin)this).Config.Bind<bool>("Build", "BeltSignalNumberFormat", false, "Belt signal number format alternative format (AAAA=generation speed in minutes, B=proliferate points, C=stack count):\n  AAAABC by default\n  BCAAAA as alternative");
			FactoryPatch.BeltSignalCountRecipeEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Build", "BeltSignalCountRecipe", false, "Belt signal count all raws and intermediates in statistics");
			FactoryPatch.RemovePowerSpaceLimitEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Build", "RemovePowerDistanceLimit", false, "Remove distance limit for wind turbines and geothermals");
			FactoryPatch.BoostWindPowerEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Build", "BoostWindPower", false, "Boost wind power");
			FactoryPatch.BoostSolarPowerEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Build", "BoostSolarPower", false, "Boost solar power");
			FactoryPatch.BoostFuelPowerEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Build", "BoostFuelPower", false, "Boost fuel power");
			FactoryPatch.BoostGeothermalPowerEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Build", "BoostGeothermalPower", false, "Boost geothermal power");
			ResourcePatch.InfiniteResourceEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Planet", "AlwaysInfiniteResource", false, "always infinite natural resource");
			ResourcePatch.FastMiningEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Planet", "FastMining", false, "super-fast mining speed");
			PlanetPatch.WaterPumpAnywhereEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Planet", "WaterPumpAnywhere", false, "Can pump water anywhere (while water type is not None)");
			PlanetPatch.TerraformAnywayEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Planet", "TerraformAnyway", false, "Can do terraform without enough soil piless");
			PlayerPatch.InstantTeleportEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Player", "InstantTeleport", false, "Enable instant teleport (like that in Sandbox mode)");
			DysonSpherePatch.SkipBulletEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("DysonSphere", "SkipBullet", false, "Skip bullet");
			DysonSpherePatch.SkipAbsorbEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("DysonSphere", "SkipAbsorb", false, "Skip absorption");
			DysonSpherePatch.QuickAbsorbEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("DysonSphere", "QuickAbsorb", false, "Quick absorb");
			DysonSpherePatch.EjectAnywayEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("DysonSphere", "EjectAnyway", false, "Eject anyway");
			DysonSpherePatch.OverclockEjectorEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("DysonSphere", "OverclockEjector", false, "Overclock ejector");
			DysonSpherePatch.OverclockSiloEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("DysonSphere", "OverclockSilo", false, "Overclock silo");
			CombatPatch.MechaInvincibleEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Battle", "MechaInvincible", false, "Mecha and Drones/Fleets invincible");
			CombatPatch.BuildingsInvincibleEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Battle", "BuildingsInvincible", false, "Buildings invincible");
			UIConfigWindow.Init();
			DevShortcuts.Init();
			AbnormalDisabler.Init();
			TechPatch.Init();
			FactoryPatch.Init();
			ResourcePatch.Init();
			PlanetPatch.Init();
			PlayerPatch.Init();
			DysonSpherePatch.Init();
			CombatPatch.Init();
		}

		private void OnDestroy()
		{
			CombatPatch.Uninit();
			DysonSpherePatch.Uninit();
			PlayerPatch.Uninit();
			PlanetPatch.Uninit();
			ResourcePatch.Uninit();
			FactoryPatch.Uninit();
			TechPatch.Uninit();
			AbnormalDisabler.Uninit();
			DevShortcuts.Uninit();
		}

		private void Update()
		{
			if (!VFInput.inputing)
			{
				FactoryPatch.OnUpdate();
			}
		}
	}
	public static class CombatPatch
	{
		private static class MechaInvincible
		{
			private static Harmony _patch;

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

			[HarmonyTranspiler]
			[HarmonyPatch(/*Could not decode attribute arguments.*/)]
			private static IEnumerable<CodeInstruction> Player_get_invincible_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_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Expected O, but got Unknown
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.Start().RemoveInstructions(val.Length).Insert((CodeInstruction[])(object)new CodeInstruction[2]
				{
					new CodeInstruction(OpCodes.Ldc_I4_1, (object)null),
					new CodeInstruction(OpCodes.Ret, (object)null)
				});
				return val.InstructionEnumeration();
			}

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(SkillSystem), "DamageGroundObjectByLocalCaster")]
			[HarmonyPatch(typeof(SkillSystem), "DamageGroundObjectByRemoteCaster")]
			[HarmonyPatch(typeof(SkillSystem), "DamageObject")]
			private static IEnumerable<CodeInstruction> SkillSystem_DamageObject_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator, MethodBase __originalMethod)
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Expected O, but got Unknown
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: 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_007a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0080: Expected O, but got Unknown
				//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a8: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[4]
				{
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsLdarg(ci, (int?)null)), (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(SkillTargetLocal), "type"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldc_I4_6, (object)null, (string)null),
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => ci.opcode == OpCodes.Bne_Un || ci.opcode == OpCodes.Bne_Un_S), (string)null)
				});
				val.Repeat((Action<CodeMatcher>)delegate(CodeMatcher m)
				{
					//IL_0015: Unknown result type (might be due to invalid IL or missing references)
					//IL_001b: Expected O, but got Unknown
					//IL_0042: Unknown result type (might be due to invalid IL or missing references)
					//IL_0048: Expected O, but got Unknown
					m.Advance(4).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2]
					{
						new CodeInstruction(OpCodes.Ldc_I4_0, (object)null),
						new CodeInstruction(OpCodes.Starg_S, (object)((__originalMethod.Name == "DamageObject") ? 1 : 2))
					});
				}, (Action<string>)null);
				return val.InstructionEnumeration();
			}
		}

		private static class BuildingsInvincible
		{
			private static Harmony _patch;

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

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(SkillSystem), "DamageGroundObjectByLocalCaster")]
			[HarmonyPatch(typeof(SkillSystem), "DamageGroundObjectByRemoteCaster")]
			private static IEnumerable<CodeInstruction> SkillSystem_DamageObject_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
				//IL_0059: Unknown result type (might be due to invalid IL or missing references)
				//IL_005f: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ba: 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
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[4]
				{
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsLdarg(ci, (int?)null)), (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(SkillTargetLocal), "type"), (string)null),
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => ci.opcode == OpCodes.Brtrue || ci.opcode == OpCodes.Brtrue_S), (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldarg_1, (object)null, (string)null)
				}).Advance(3).Insert((CodeInstruction[])(object)new CodeInstruction[2]
				{
					new CodeInstruction(OpCodes.Ldc_I4_0, (object)null),
					new CodeInstruction(OpCodes.Starg_S, (object)2)
				});
				return val.InstructionEnumeration();
			}
		}

		public static ConfigEntry<bool> MechaInvincibleEnabled;

		public static ConfigEntry<bool> BuildingsInvincibleEnabled;

		public static void Init()
		{
			MechaInvincibleEnabled.SettingChanged += delegate
			{
				MechaInvincible.Enable(MechaInvincibleEnabled.Value);
			};
			BuildingsInvincibleEnabled.SettingChanged += delegate
			{
				BuildingsInvincible.Enable(BuildingsInvincibleEnabled.Value);
			};
			MechaInvincible.Enable(MechaInvincibleEnabled.Value);
			BuildingsInvincible.Enable(BuildingsInvincibleEnabled.Value);
		}

		public static void Uninit()
		{
			BuildingsInvincible.Enable(on: false);
			MechaInvincible.Enable(on: false);
		}
	}
	public static class DevShortcuts
	{
		public static ConfigEntry<bool> Enabled;

		private static Harmony _patch;

		private static PlayerAction_Test _test;

		public static void Init()
		{
			if (_patch == null)
			{
				_patch = Harmony.CreateAndPatchAll(typeof(DevShortcuts), (string)null);
			}
			Enabled.SettingChanged += delegate
			{
				if (_test != null)
				{
					_test.active = Enabled.Value;
				}
			};
		}

		public static void Uninit()
		{
			Harmony patch = _patch;
			if (patch != null)
			{
				patch.UnpatchSelf();
			}
			_patch = null;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlayerController), "Init")]
		private static void PlayerController_Init_Postfix(PlayerController __instance)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			int num = __instance.actions.Length;
			PlayerAction[] array = (PlayerAction[])(object)new PlayerAction[num + 1];
			for (int i = 0; i < num; i++)
			{
				array[i] = __instance.actions[i];
			}
			_test = new PlayerAction_Test();
			((PlayerAction)_test).Init(__instance.player);
			_test.active = Enabled.Value;
			array[num] = (PlayerAction)(object)_test;
			__instance.actions = array;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlayerAction_Test), "GameTick")]
		private static void PlayerAction_Test_GameTick_Postfix(PlayerAction_Test __instance)
		{
			__instance.Update();
		}

		[HarmonyTranspiler]
		[HarmonyPatch(typeof(PlayerAction_Test), "Update")]
		private static IEnumerable<CodeInstruction> PlayerAction_Test_Update_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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Expected O, but got Unknown
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Expected O, but got Unknown
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(instructions, generator);
			val.End().MatchBack(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(PlayerAction_Test), "active"), (string)null)
			});
			int pos = val.Pos;
			val.Start().RemoveInstructions(pos).MatchForward(false, (CodeMatch[])(object)new CodeMatch[3]
			{
				new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(GameMain), "get_sandboxToolsEnabled", (Type[])null, (Type[])null), (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldc_I4_0, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ceq, (object)null, (string)null)
			});
			List<Label> labels = val.Labels;
			val.SetInstructionAndAdvance(CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Ldc_I4_1, (object)null), (IEnumerable<Label>)labels)).RemoveInstructions(2);
			val.Start().MatchForward(false, (CodeMatch[])(object)new CodeMatch[2]
			{
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction instr) => (instr.opcode == OpCodes.Ldc_I4_S || instr.opcode == OpCodes.Ldc_I4) && CodeInstructionExtensions.OperandIs(instr, (object)97)), (string)null),
				new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(Input), "GetKeyDown", new Type[1] { typeof(KeyCode) }, (Type[])null), (string)null)
			});
			labels = val.Labels;
			val.Labels = null;
			val.RemoveInstructions(2);
			val.Opcode = OpCodes.Br;
			val.Labels = labels;
			return val.InstructionEnumeration();
		}
	}
	public static class DysonSpherePatch
	{
		private static class SkipBulletPatch
		{
			private struct DysonSailCache
			{
				public DysonSail Sail;

				public int OrbitId;

				public void FromData(in VectorLF3 delta1, in VectorLF3 delta2, int orbitId)
				{
					Sail.px = (float)delta1.x;
					Sail.py = (float)delta1.y;
					Sail.pz = (float)delta1.z;
					Sail.vx = (float)delta2.x;
					Sail.vy = (float)delta2.y;
					Sail.vz = (float)delta2.z;
					Sail.gs = 1f;
					OrbitId = orbitId;
				}
			}

			private static long _sailLifeTime;

			private static DysonSailCache[][] _sailsCache;

			private static int[] _sailsCacheLen;

			private static int[] _sailsCacheCapacity;

			private static Harmony _patch;

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

			private static void UpdateSailLifeTime()
			{
				if (GameMain.history != null)
				{
					_sailLifeTime = (long)(GameMain.history.solarSailLife * 60f + 0.1f);
				}
			}

			private static void UpdateSailsCacheForThisGame()
			{
				if (GameMain.data?.galaxy != null)
				{
					int starCount = GameMain.data.galaxy.starCount;
					_sailsCache = new DysonSailCache[starCount][];
					_sailsCacheLen = new int[starCount];
					_sailsCacheCapacity = new int[starCount];
					Array.Clear(_sailsCacheLen, 0, starCount);
					Array.Clear(_sailsCacheCapacity, 0, starCount);
				}
			}

			private static void SetSailsCacheCapacity(int index, int capacity)
			{
				DysonSailCache[] array = new DysonSailCache[capacity];
				int num = _sailsCacheLen[index];
				if (num > 0)
				{
					Array.Copy(_sailsCache[index], array, num);
				}
				_sailsCache[index] = array;
				_sailsCacheCapacity[index] = capacity;
			}

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

			[HarmonyPostfix]
			[HarmonyPatch(typeof(GameHistoryData), "UnlockTechFunction")]
			private static void GameHistoryData_SetForNewGame_Postfix(int func)
			{
				if (func == 12)
				{
					UpdateSailLifeTime();
				}
			}

			[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_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Expected O, but got Unknown
				//IL_0056: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: Expected O, but got Unknown
				//IL_0091: Unknown result type (might be due to invalid IL or missing references)
				//IL_0097: Expected O, but got Unknown
				//IL_009f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a5: Expected O, but got Unknown
				//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c6: Expected O, but got Unknown
				//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d9: Expected O, but got Unknown
				//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ed: Expected O, but got Unknown
				//IL_010a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0110: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Ldc_R4, (object)10f, (string)null)
				}).Advance(2);
				int pos = val.Pos;
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Pop, (object)null, (string)null)
				}).Advance(1);
				int pos2 = val.Pos;
				val.Start().Advance(pos).RemoveInstructions(pos2 - pos)
					.Insert((CodeInstruction[])(object)new CodeInstruction[6]
					{
						new CodeInstruction(OpCodes.Ldarg_2, (object)null),
						new CodeInstruction(OpCodes.Ldarg_0, (object)null),
						new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(EjectorComponent), "orbitId")),
						new CodeInstruction(OpCodes.Ldloc_S, (object)8),
						new CodeInstruction(OpCodes.Ldloc_S, (object)10),
						new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(SkipBulletPatch), "AddDysonSail", (Type[])null, (Type[])null))
					});
				return val.InstructionEnumeration();
			}

			private static void AddDysonSail(DysonSwarm swarm, int orbitId, VectorLF3 uPos, VectorLF3 endVec)
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_006b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0070: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
				int index = swarm.starData.index;
				VectorLF3 delta = endVec - swarm.starData.uPosition;
				VectorLF3 delta2 = VectorLF3.Cross(endVec - uPos, VectorLF3.op_Implicit(swarm.orbits[orbitId].up));
				VectorLF3 val = ((VectorLF3)(ref delta2)).normalized * Math.Sqrt(swarm.dysonSphere.gravity / swarm.orbits[orbitId].radius);
				lock (swarm)
				{
					DysonSailCache[] array = _sailsCache[index];
					int num = _sailsCacheLen[index];
					if (array == null)
					{
						SetSailsCacheCapacity(index, 256);
						array = _sailsCache[index];
					}
					else
					{
						int num2 = _sailsCacheCapacity[index];
						if (num >= num2)
						{
							SetSailsCacheCapacity(index, num2 * 2);
							array = _sailsCache[index];
						}
					}
					_sailsCacheLen[index] = num + 1;
					ref DysonSailCache reference = ref array[num];
					delta2 = val + RandomTable.SphericNormal(ref swarm.randSeed, 0.5);
					reference.FromData(in delta, in delta2, orbitId);
				}
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(DysonSwarm), "GameTick")]
			public static void DysonSwarm_GameTick_Prefix(DysonSwarm __instance, long time)
			{
				//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
				int index = __instance.starData.index;
				int num = _sailsCacheLen[index];
				if (num == 0)
				{
					return;
				}
				_sailsCacheLen[index] = 0;
				DysonSailCache[] array = _sailsCache[index];
				long num2 = time + _sailLifeTime;
				int num3 = num - 1;
				if (_instantAbsorb)
				{
					DysonSphere dysonSphere = __instance.dysonSphere;
					DysonSphereLayer[] layersSorted = dysonSphere.layersSorted;
					int layerCount = dysonSphere.layerCount;
					int[] productRegister = dysonSphere.productRegister;
					int[] consumeRegister = dysonSphere.consumeRegister;
					if (layerCount > 0)
					{
						int num4 = ((int)time >> 4) % layerCount;
						for (int num5 = layerCount - 1; num5 >= 0; num5--)
						{
							DysonSphereLayer obj = layersSorted[(num4 + num5) % layerCount];
							DysonNode[] nodePool = obj.nodePool;
							int num6 = obj.nodeCursor - 1;
							if (num6 > 0)
							{
								int num7 = (int)time % num6;
								for (int num8 = num6; num8 > 0; num8--)
								{
									int num9 = (num7 + num8) % num6 + 1;
									DysonNode val = nodePool[num9];
									if (val != null && val.id == num9 && val.sp >= val.spMax)
									{
										while (val.cpReqOrder > 0)
										{
											val.cpOrdered++;
											if (val.ConstructCp() == null)
											{
												break;
											}
											if (num3 == 0)
											{
												productRegister[11901] += num;
												consumeRegister[11901] += num;
												productRegister[11903] += num;
												return;
											}
											num3--;
										}
									}
								}
							}
						}
					}
					int num10 = num - 1 - num3;
					if (num10 > 0)
					{
						productRegister[11901] += num10;
						consumeRegister[11901] += num10;
						productRegister[11903] += num10;
					}
				}
				while (num3 >= 0)
				{
					__instance.AddSolarSail(array[num3].Sail, array[num3].OrbitId, num2);
					num3--;
				}
			}
		}

		private static class SkipAbsorbPatch
		{
			private static Harmony _patch;

			public static void Enable(bool on)
			{
				_instantAbsorb = SkipAbsorbEnabled.Value && QuickAbsorbEnabled.Value;
				if (on)
				{
					if (_patch == null)
					{
						_patch = Harmony.CreateAndPatchAll(typeof(SkipAbsorbPatch), (string)null);
					}
					return;
				}
				Harmony patch = _patch;
				if (patch != null)
				{
					patch.UnpatchSelf();
				}
				_patch = null;
			}

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(DysonSwarm), "AbsorbSail")]
			private static IEnumerable<CodeInstruction> DysonSwarm_AbsorbSail_Transpiler2(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_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Expected O, but got Unknown
				//IL_006a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0070: Expected O, but got Unknown
				//IL_008d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0093: Expected O, but got Unknown
				//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a6: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d5: Expected O, but got Unknown
				//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f6: 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
				//IL_011e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0124: Expected O, but got Unknown
				//IL_012c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0132: Expected O, but got Unknown
				//IL_013b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0141: Expected O, but got Unknown
				//IL_014a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0150: Expected O, but got Unknown
				//IL_0159: Unknown result type (might be due to invalid IL or missing references)
				//IL_015f: Expected O, but got Unknown
				//IL_0168: Unknown result type (might be due to invalid IL or missing references)
				//IL_016e: Expected O, but got Unknown
				//IL_0177: Unknown result type (might be due to invalid IL or missing references)
				//IL_018f: Expected O, but got Unknown
				//IL_0199: Unknown result type (might be due to invalid IL or missing references)
				//IL_019f: Expected O, but got Unknown
				//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c3: Expected O, but got Unknown
				//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d2: Expected O, but got Unknown
				//IL_01db: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e1: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				Label label = generator.DefineLabel();
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(ExpiryOrder), "index"), (string)null)
				}).Advance(1).RemoveInstructions(val.Length - val.Pos)
					.Insert((CodeInstruction[])(object)new CodeInstruction[18]
					{
						new CodeInstruction(OpCodes.Ldarg_1, (object)null),
						new CodeInstruction(OpCodes.Callvirt, (object)AccessTools.Method(typeof(DysonNode), "ConstructCp", (Type[])null, (Type[])null)),
						new CodeInstruction(OpCodes.Brfalse_S, (object)label),
						new CodeInstruction(OpCodes.Ldarg_0, (object)null),
						new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(DysonSwarm), "dysonSphere")),
						new CodeInstruction(OpCodes.Call, (object)AccessTools.PropertyGetter(typeof(DysonSphere), "productRegister")),
						new CodeInstruction(OpCodes.Ldc_I4, (object)11903),
						new CodeInstruction(OpCodes.Ldelema, (object)typeof(int)),
						new CodeInstruction(OpCodes.Dup, (object)null),
						new CodeInstruction(OpCodes.Ldind_I4, (object)null),
						new CodeInstruction(OpCodes.Ldc_I4_1, (object)null),
						new CodeInstruction(OpCodes.Add, (object)null),
						new CodeInstruction(OpCodes.Stind_I4, (object)null),
						CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Ldarg_0, (object)null), new Label[1] { label }),
						new CodeInstruction(OpCodes.Ldloc_1, (object)null),
						new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(DysonSwarm), "RemoveSolarSail", (Type[])null, (Type[])null)),
						new CodeInstruction(OpCodes.Ldc_I4_1, (object)null),
						new CodeInstruction(OpCodes.Ret, (object)null)
					});
				return val.InstructionEnumeration();
			}
		}

		private static class QuickAbsorbPatch
		{
			private static Harmony _patch;

			public static void Enable(bool on)
			{
				_instantAbsorb = SkipAbsorbEnabled.Value && QuickAbsorbEnabled.Value;
				if (on)
				{
					if (_patch == null)
					{
						_patch = Harmony.CreateAndPatchAll(typeof(QuickAbsorbPatch), (string)null);
					}
					return;
				}
				Harmony patch = _patch;
				if (patch != null)
				{
					patch.UnpatchSelf();
				}
				_patch = null;
			}

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(DysonSphereLayer), "GameTick")]
			private static IEnumerable<CodeInstruction> DysonSphereLayer_GameTick_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_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Expected O, but got Unknown
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0053: 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_0094: Unknown result type (might be due to invalid IL or missing references)
				//IL_009a: 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_00d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00da: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.Start().InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[3]
				{
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					new CodeInstruction(OpCodes.Ldarg_1, (object)null),
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(QuickAbsorbPatch), "DoAbsorb", (Type[])null, (Type[])null))
				}).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(DysonSphereLayer), "dysonSphere"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(DysonSphere), "swarm"), (string)null)
				})
					.Insert((CodeInstruction[])(object)new CodeInstruction[1]
					{
						new CodeInstruction(OpCodes.Ret, (object)null)
					});
				return val.InstructionEnumeration();
			}

			private static void DoAbsorb(DysonSphereLayer layer, long gameTick)
			{
				int num = layer.nodeCursor - 1;
				if (num <= 0)
				{
					return;
				}
				DysonNode[] nodePool = layer.nodePool;
				DysonSwarm swarm = layer.dysonSphere.swarm;
				int num2 = ((int)gameTick >> 6) % num;
				for (int num3 = num - ((int)gameTick & 0x3F); num3 > 0; num3 -= 64)
				{
					int num4 = (num2 + num3) % num + 1;
					DysonNode val = nodePool[num4];
					if (val != null && val.id == num4 && val.sp >= val.spMax)
					{
						for (int num5 = val.cpReqOrder; num5 > 0; num5--)
						{
							if (!swarm.AbsorbSail(val, gameTick))
							{
								return;
							}
						}
					}
				}
			}
		}

		private static class EjectAnywayPatch
		{
			private static Harmony _patch;

			public static void Enable(bool on)
			{
				if (on)
				{
					if (_patch == null)
					{
						_patch = Harmony.CreateAndPatchAll(typeof(EjectAnywayPatch), (string)null);
					}
					return;
				}
				Harmony patch = _patch;
				if (patch != null)
				{
					patch.UnpatchSelf();
				}
				_patch = 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_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Expected O, but got Unknown
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0063: Expected O, but got Unknown
				//IL_0083: Unknown result type (might be due to invalid IL or missing references)
				//IL_0089: Expected O, but got Unknown
				//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c0: Expected O, but got Unknown
				//IL_00db: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e1: Expected O, but got Unknown
				//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ef: 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_010b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0111: 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 instr) => instr.opcode == OpCodes.Ldc_R8 && Math.Abs((double)instr.operand - 0.08715574) < 1E-08), (string)null)
				});
				int num = val.Pos - 3;
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.And, (object)null, (string)null)
				}).Advance(1).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.And, (object)null, (string)null)
				});
				int num2 = val.Pos - 2;
				val.Start().Advance(num).RemoveInstructions(num2 - num)
					.Insert((CodeInstruction[])(object)new CodeInstruction[5]
					{
						new CodeInstruction(OpCodes.Ldarg_0, (object)null),
						new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(EjectorComponent), "bulletCount")),
						new CodeInstruction(OpCodes.Ldc_I4_0, (object)null),
						new CodeInstruction(OpCodes.Cgt, (object)null),
						new CodeInstruction(OpCodes.Stloc_S, (object)13)
					});
				return val.InstructionEnumeration();
			}
		}

		private static class OverclockEjector
		{
			private static Harmony _patch;

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

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(EjectorComponent), "InternalUpdate")]
			private static IEnumerable<CodeInstruction> EjectAndSiloComponent_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_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: Expected O, but got Unknown
				//IL_004b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0051: Expected O, but got Unknown
				//IL_007a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0080: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Stloc_1, (object)null, (string)null)
				}).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2]
				{
					new CodeInstruction(OpCodes.Ldc_I4_S, (object)10),
					new CodeInstruction(OpCodes.Mul, (object)null)
				}).Advance(1);
				int pos = val.Pos;
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Stloc_1, (object)null, (string)null)
				}).Advance(1);
				int pos2 = val.Pos;
				val.Start().Advance(pos).RemoveInstructions(pos2 - pos);
				return val.InstructionEnumeration();
			}

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(UIEjectorWindow), "_OnUpdate")]
			private static IEnumerable<CodeInstruction> UIEjectAndSiloWindow__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_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Expected O, but got Unknown
				//IL_0061: Unknown result type (might be due to invalid IL or missing references)
				//IL_0067: Expected O, but got Unknown
				//IL_0083: Unknown result type (might be due to invalid IL or missing references)
				//IL_0089: Expected O, but got Unknown
				//IL_0091: Unknown result type (might be due to invalid IL or missing references)
				//IL_0097: Expected O, but got Unknown
				//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c6: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Ldsfld, (object)AccessTools.Field(typeof(Cargo), "accTableMilli"), (string)null)
				}).Advance(-1);
				object operand = val.Operand;
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Stloc_S, operand, (string)null)
				}).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2]
				{
					new CodeInstruction(OpCodes.Ldc_R4, (object)10f),
					new CodeInstruction(OpCodes.Mul, (object)null)
				}).Advance(1);
				int pos = val.Pos;
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Stloc_S, operand, (string)null)
				}).Advance(1);
				int pos2 = val.Pos;
				val.Start().Advance(pos).RemoveInstructions(pos2 - pos);
				return val.InstructionEnumeration();
			}
		}

		private static class OverclockSilo
		{
			private static Harmony _patch;

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

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(SiloComponent), "InternalUpdate")]
			private static IEnumerable<CodeInstruction> EjectAndSiloComponent_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_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: Expected O, but got Unknown
				//IL_004b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0051: Expected O, but got Unknown
				//IL_007a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0080: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Stloc_1, (object)null, (string)null)
				}).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2]
				{
					new CodeInstruction(OpCodes.Ldc_I4_S, (object)10),
					new CodeInstruction(OpCodes.Mul, (object)null)
				}).Advance(1);
				int pos = val.Pos;
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Stloc_1, (object)null, (string)null)
				}).Advance(1);
				int pos2 = val.Pos;
				val.Start().Advance(pos).RemoveInstructions(pos2 - pos);
				return val.InstructionEnumeration();
			}

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(UISiloWindow), "_OnUpdate")]
			private static IEnumerable<CodeInstruction> UIEjectAndSiloWindow__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_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Expected O, but got Unknown
				//IL_0061: Unknown result type (might be due to invalid IL or missing references)
				//IL_0067: Expected O, but got Unknown
				//IL_0083: Unknown result type (might be due to invalid IL or missing references)
				//IL_0089: Expected O, but got Unknown
				//IL_0091: Unknown result type (might be due to invalid IL or missing references)
				//IL_0097: Expected O, but got Unknown
				//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c6: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Ldsfld, (object)AccessTools.Field(typeof(Cargo), "accTableMilli"), (string)null)
				}).Advance(-1);
				object operand = val.Operand;
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Stloc_S, operand, (string)null)
				}).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2]
				{
					new CodeInstruction(OpCodes.Ldc_R4, (object)10f),
					new CodeInstruction(OpCodes.Mul, (object)null)
				}).Advance(1);
				int pos = val.Pos;
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Stloc_S, operand, (string)null)
				}).Advance(1);
				int pos2 = val.Pos;
				val.Start().Advance(pos).RemoveInstructions(pos2 - pos);
				return val.InstructionEnumeration();
			}
		}

		public static ConfigEntry<bool> SkipBulletEnabled;

		public static ConfigEntry<bool> SkipAbsorbEnabled;

		public static ConfigEntry<bool> QuickAbsorbEnabled;

		public static ConfigEntry<bool> EjectAnywayEnabled;

		public static ConfigEntry<bool> OverclockEjectorEnabled;

		public static ConfigEntry<bool> OverclockSiloEnabled;

		private static bool _instantAbsorb;

		private static Harmony _dysonSpherePatch;

		public static void Init()
		{
			SkipBulletEnabled.SettingChanged += delegate
			{
				SkipBulletPatch.Enable(SkipBulletEnabled.Value);
			};
			SkipAbsorbEnabled.SettingChanged += delegate
			{
				SkipAbsorbPatch.Enable(SkipAbsorbEnabled.Value);
			};
			QuickAbsorbEnabled.SettingChanged += delegate
			{
				QuickAbsorbPatch.Enable(QuickAbsorbEnabled.Value);
			};
			EjectAnywayEnabled.SettingChanged += delegate
			{
				EjectAnywayPatch.Enable(EjectAnywayEnabled.Value);
			};
			OverclockEjectorEnabled.SettingChanged += delegate
			{
				OverclockEjector.Enable(OverclockEjectorEnabled.Value);
			};
			OverclockSiloEnabled.SettingChanged += delegate
			{
				OverclockSilo.Enable(OverclockSiloEnabled.Value);
			};
			SkipBulletPatch.Enable(SkipBulletEnabled.Value);
			SkipAbsorbPatch.Enable(SkipAbsorbEnabled.Value);
			QuickAbsorbPatch.Enable(QuickAbsorbEnabled.Value);
			EjectAnywayPatch.Enable(EjectAnywayEnabled.Value);
			OverclockEjector.Enable(OverclockEjectorEnabled.Value);
			OverclockSilo.Enable(OverclockSiloEnabled.Value);
			if (_dysonSpherePatch == null)
			{
				_dysonSpherePatch = Harmony.CreateAndPatchAll(typeof(DysonSpherePatch), (string)null);
			}
		}

		public static void Uninit()
		{
			Harmony dysonSpherePatch = _dysonSpherePatch;
			if (dysonSpherePatch != null)
			{
				dysonSpherePatch.UnpatchSelf();
			}
			_dysonSpherePatch = null;
			SkipBulletPatch.Enable(on: false);
			SkipAbsorbPatch.Enable(on: false);
			QuickAbsorbPatch.Enable(on: false);
			EjectAnywayPatch.Enable(on: false);
			OverclockEjector.Enable(on: false);
			OverclockSilo.Enable(on: false);
		}

		[HarmonyTranspiler]
		[HarmonyPatch(typeof(DysonNode), "OrderConstructCp")]
		private static IEnumerable<CodeInstruction> DysonNode_OrderConstructCp_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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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
			CodeMatcher val = new CodeMatcher(instructions, generator);
			val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(DysonSwarm), "AbsorbSail", (Type[])null, (Type[])null), (string)null)
			}).Advance(1).SetInstructionAndAdvance(new CodeInstruction(OpCodes.Pop, (object)null))
				.Insert((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Ret, (object)null)
				});
			return val.InstructionEnumeration();
		}

		[HarmonyTranspiler]
		[HarmonyPatch(typeof(DysonSwarm), "AbsorbSail")]
		private static IEnumerable<CodeInstruction> DysonSwarm_AbsorbSail_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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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
			CodeMatcher val = new CodeMatcher(instructions, generator);
			val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(ExpiryOrder), "time"), (string)null)
			}).Advance(1).Insert((CodeInstruction[])(object)new CodeInstruction[6]
			{
				new CodeInstruction(OpCodes.Ldarg_1, (object)null),
				new CodeInstruction(OpCodes.Ldarg_1, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(DysonNode), "cpOrdered")),
				new CodeInstruction(OpCodes.Ldc_I4_1, (object)null),
				new CodeInstruction(OpCodes.Add, (object)null),
				new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(DysonNode), "cpOrdered"))
			});
			return val.InstructionEnumeration();
		}
	}
	public static class FactoryPatch
	{
		private static class ImmediateBuild
		{
			private static Harmony _immediatePatch;

			public static void Enable(bool enable)
			{
				if (enable)
				{
					if (_immediatePatch == null)
					{
						Player mainPlayer = GameMain.mainPlayer;
						PlanetFactory val = ((mainPlayer != null) ? mainPlayer.factory : null);
						if (val != null)
						{
							ArrivePlanet(val);
						}
						_immediatePatch = Harmony.CreateAndPatchAll(typeof(ImmediateBuild), (string)null);
					}
				}
				else
				{
					Harmony immediatePatch = _immediatePatch;
					if (immediatePatch != null)
					{
						immediatePatch.UnpatchSelf();
					}
					_immediatePatch = null;
				}
			}

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(BuildTool_Addon), "CreatePrebuilds")]
			[HarmonyPatch(typeof(BuildTool_BlueprintPaste), "CreatePrebuilds")]
			[HarmonyPatch(typeof(BuildTool_Click), "CreatePrebuilds")]
			[HarmonyPatch(typeof(BuildTool_Inserter), "CreatePrebuilds")]
			[HarmonyPatch(typeof(BuildTool_Path), "CreatePrebuilds")]
			private static IEnumerable<CodeInstruction> 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_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Expected O, but got Unknown
				//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f5: Expected O, but got Unknown
				//IL_0111: Unknown result type (might be due to invalid IL or missing references)
				//IL_0117: Expected O, but got Unknown
				//IL_0134: Unknown result type (might be due to invalid IL or missing references)
				//IL_013a: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.End().MatchBack(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Ret, (object)null, (string)null)
				});
				if (val.IsInvalid)
				{
					CheatEnabler.Logger.LogWarning((object)"Failed to patch CreatePrebuilds");
					return val.InstructionEnumeration();
				}
				val.Advance(-1);
				if (val.Opcode != OpCodes.Nop && (val.Opcode != OpCodes.Call || !CodeInstructionExtensions.OperandIs(val.Instruction, (MemberInfo)AccessTools.Method(typeof(GC), "Collect", (Type[])null, (Type[])null))))
				{
					CheatEnabler.Logger.LogWarning((object)$"Failed to patch CreatePrebuilds: last instruction is not `Nop` or `Call GC.Collect()`: {val.Instruction}");
					return val.InstructionEnumeration();
				}
				List<Label> labels = val.Labels;
				val.Labels = new List<Label>();
				val.Insert((CodeInstruction[])(object)new CodeInstruction[3]
				{
					CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Ldarg_0, (object)null), (IEnumerable<Label>)labels),
					new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(BuildTool), "factory")),
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(FactoryPatch), "ArrivePlanet", (Type[])null, (Type[])null))
				});
				return val.InstructionEnumeration();
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(PlanetFunctions), "BuildOrbitalCollectors")]
			private static void UXAssist_PlanetFunctions_BuildOrbitalCollectors_Postfix()
			{
				Player mainPlayer = GameMain.mainPlayer;
				PlanetFactory val = ((mainPlayer != null) ? mainPlayer.factory : null);
				if (val != null)
				{
					ArrivePlanet(val);
				}
			}
		}

		private static class ArchitectMode
		{
			private static Harmony _patch;

			private static bool[] _canBuildItems;

			public static void Enable(bool enable)
			{
				if (enable)
				{
					if (_patch == null)
					{
						Player mainPlayer = GameMain.mainPlayer;
						PlanetFactory val = ((mainPlayer != null) ? mainPlayer.factory : null);
						if (val != null)
						{
							ArrivePlanet(val);
						}
						_patch = Harmony.CreateAndPatchAll(typeof(ArchitectMode), (string)null);
					}
				}
				else
				{
					Harmony patch = _patch;
					if (patch != null)
					{
						patch.UnpatchSelf();
					}
					_patch = null;
				}
			}

			[HarmonyPrefix]
			[HarmonyPatch(/*Could not decode attribute arguments.*/)]
			[HarmonyPatch(/*Could not decode attribute arguments.*/)]
			public static bool TakeTailItemsPatch(StorageComponent __instance, int itemId)
			{
				if (__instance == null || __instance.id != GameMain.mainPlayer.package.id)
				{
					return true;
				}
				if (itemId <= 0)
				{
					return true;
				}
				if (_canBuildItems == null)
				{
					DoInit();
				}
				if (itemId < 12000)
				{
					return !_canBuildItems[itemId];
				}
				return true;
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(StorageComponent), "GetItemCount", new Type[] { typeof(int) })]
			public static void GetItemCountPatch(StorageComponent __instance, int itemId, ref int __result)
			{
				if (__result <= 99 && __instance != null && __instance.id == GameMain.mainPlayer.package.id && itemId > 0)
				{
					if (_canBuildItems == null)
					{
						DoInit();
					}
					if (itemId < 12000 && _canBuildItems[itemId])
					{
						__result = 100;
					}
				}
			}

			private static void DoInit()
			{
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Invalid comparison between Unknown and I4
				_canBuildItems = new bool[12000];
				ItemProto[] dataArray = ((ProtoSet<ItemProto>)(object)LDB.items).dataArray;
				foreach (ItemProto val in dataArray)
				{
					if (((int)val.Type == 5 || val.CanBuild) && ((Proto)val).ID < 12000)
					{
						_canBuildItems[((Proto)val).ID] = true;
					}
				}
			}
		}

		private static class NoConditionBuild
		{
			private static Harmony _noConditionPatch;

			public static void Enable(bool on)
			{
				GameData data = GameMain.data;
				if (data != null)
				{
					WarningSystem warningSystem = data.warningSystem;
					if (warningSystem != null)
					{
						warningSystem.UpdateCriticalWarningText();
					}
				}
				if (on)
				{
					if (_noConditionPatch == null)
					{
						_noConditionPatch = Harmony.CreateAndPatchAll(typeof(NoConditionBuild), (string)null);
					}
					return;
				}
				Harmony noConditionPatch = _noConditionPatch;
				if (noConditionPatch != null)
				{
					noConditionPatch.UnpatchSelf();
				}
				_noConditionPatch = null;
			}

			[HarmonyTranspiler]
			[HarmonyPriority(0)]
			[HarmonyPatch(typeof(BuildTool_Addon), "CheckBuildConditions")]
			[HarmonyPatch(typeof(BuildTool_Inserter), "CheckBuildConditions")]
			[HarmonyPatch(typeof(BuildTool_Path), "CheckBuildConditions")]
			private static IEnumerable<CodeInstruction> BuildTool_CheckBuildConditions_Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				yield return new CodeInstruction(OpCodes.Ldc_I4_1, (object)null);
				yield return new CodeInstruction(OpCodes.Ret, (object)null);
			}

			[HarmonyTranspiler]
			[HarmonyPriority(0)]
			[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_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Expected O, but got Unknown
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: 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_0067: Unknown result type (might be due to invalid IL or missing references)
				//IL_006d: Expected O, but got Unknown
				//IL_0075: Unknown result type (might be due to invalid IL or missing references)
				//IL_007b: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				Label label = generator.DefineLabel();
				val.Start().InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[5]
				{
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(NoConditionBuild), "CheckForMiner", (Type[])null, (Type[])null)),
					new CodeInstruction(OpCodes.Brfalse_S, (object)label),
					new CodeInstruction(OpCodes.Ldc_I4_1, (object)null),
					new CodeInstruction(OpCodes.Ret, (object)null)
				});
				val.Labels.Add(label);
				return val.InstructionEnumeration();
			}

			public static bool CheckForMiner(BuildTool tool)
			{
				foreach (BuildPreview buildPreview in tool.buildPreviews)
				{
					PrefabDesc val = buildPreview?.item?.prefabDesc;
					if (val != null && (val.veinMiner || val.oilMiner))
					{
						return false;
					}
				}
				return true;
			}
		}

		public static class BeltSignalGenerator
		{
			private class BeltSignal
			{
				public int SignalId;

				public int SpeedLimit;

				public byte Stack;

				public byte Inc;

				public int Progress;

				public Tuple<int, float>[] Sources;

				public float[] SourceProgress;
			}

			private class ItemSource
			{
				public float Count;

				public Dictionary<int, float> From;

				public Dictionary<int, float> Extra;
			}

			private static Harmony _beltSignalPatch;

			private static Dictionary<int, BeltSignal>[] _signalBelts;

			private static Dictionary<long, int> _portalFrom;

			private static Dictionary<int, HashSet<long>> _portalTo;

			private static int _signalBeltsCapacity;

			private static bool _initialized;

			private static readonly Dictionary<int, ItemSource> ItemSources = new Dictionary<int, ItemSource>();

			private static bool _itemSourcesInitialized;

			public static void Enable(bool on)
			{
				if (on)
				{
					InitSignalBelts();
					if (_beltSignalPatch == null)
					{
						_beltSignalPatch = Harmony.CreateAndPatchAll(typeof(BeltSignalGenerator), (string)null);
					}
					return;
				}
				Harmony beltSignalPatch = _beltSignalPatch;
				if (beltSignalPatch != null)
				{
					beltSignalPatch.UnpatchSelf();
				}
				_beltSignalPatch = null;
				_initialized = false;
				_signalBelts = null;
				_signalBeltsCapacity = 0;
			}

			public static void OnAltFormatChanged()
			{
				if (_signalBelts == null)
				{
					return;
				}
				PlanetFactory[] array = GameMain.data?.factories;
				if (array == null)
				{
					return;
				}
				int factoryCount = GameMain.data.factoryCount;
				bool value = BeltSignalNumberAltFormat.Value;
				for (int num = Math.Min(_signalBelts.Length, factoryCount) - 1; num >= 0; num--)
				{
					PlanetFactory val = array[num];
					CargoTraffic val2 = val?.cargoTraffic;
					if (val2 != null)
					{
						SignData[] entitySignPool = val.entitySignPool;
						if (entitySignPool != null)
						{
							Dictionary<int, BeltSignal> dictionary = _signalBelts[num];
							if (dictionary != null)
							{
								foreach (KeyValuePair<int, BeltSignal> item in dictionary)
								{
									int key = item.Key;
									ref BeltComponent reference = ref val2.beltPool[key];
									if (reference.id != key)
									{
										continue;
									}
									ref SignData reference2 = ref entitySignPool[reference.entityId];
									if (reference2.iconId0 >= 1000)
									{
										BeltSignal value2 = item.Value;
										int num2 = value2.Inc / value2.Stack;
										if (value)
										{
											reference2.count0 = value2.SpeedLimit + value2.Stack * 10000 + num2 * 100000;
										}
										else
										{
											reference2.count0 = value2.SpeedLimit * 100 + value2.Stack + num2 * 10;
										}
									}
								}
							}
						}
					}
				}
			}

			private static void InitSignalBelts()
			{
				if (!GameMain.isRunning)
				{
					return;
				}
				_signalBelts = new Dictionary<int, BeltSignal>[64];
				_signalBeltsCapacity = 64;
				_portalFrom = new Dictionary<long, int>();
				_portalTo = new Dictionary<int, HashSet<long>>();
				PlanetFactory[] array = GameMain.data?.factories;
				if (array == null)
				{
					return;
				}
				PlanetFactory[] array2 = array;
				foreach (PlanetFactory val in array2)
				{
					SignData[] array3 = val?.entitySignPool;
					if (array3 == null)
					{
						continue;
					}
					CargoTraffic cargoTraffic = val.cargoTraffic;
					BeltComponent[] beltPool = cargoTraffic.beltPool;
					for (int num = cargoTraffic.beltCursor - 1; num > 0; num--)
					{
						if (beltPool[num].id != num)
						{
							continue;
						}
						ref SignData reference = ref array3[beltPool[num].entityId];
						uint iconId = reference.iconId0;
						if (iconId == 0)
						{
							continue;
						}
						int num2 = Mathf.RoundToInt(reference.count0);
						if (iconId >= 1000)
						{
							if (iconId >= 20000)
							{
								continue;
							}
						}
						else
						{
							switch (iconId)
							{
							case 404u:
								SetSignalBelt(val.index, num, (int)iconId, 0);
								continue;
							case 600u:
								break;
							case 601u:
							case 602u:
							case 603u:
							case 604u:
							case 605u:
							case 606u:
							case 607u:
							case 608u:
							case 609u:
								if (num2 > 0)
								{
									SetSignalBeltPortalTo(val.index, num, num2);
								}
								continue;
							default:
								continue;
							}
						}
						if (num2 > 0)
						{
							SetSignalBelt(val.index, num, (int)iconId, num2);
						}
					}
				}
				_initialized = true;
			}

			private static Dictionary<int, BeltSignal> GetOrCreateSignalBelts(int index)
			{
				if (index < 0)
				{
					return null;
				}
				Dictionary<int, BeltSignal> dictionary;
				if (index >= _signalBeltsCapacity)
				{
					int num = _signalBeltsCapacity * 2;
					Dictionary<int, BeltSignal>[] array = new Dictionary<int, BeltSignal>[num];
					Array.Copy(_signalBelts, array, _signalBeltsCapacity);
					_signalBelts = array;
					_signalBeltsCapacity = num;
				}
				else
				{
					dictionary = _signalBelts[index];
					if (dictionary != null)
					{
						return dictionary;
					}
				}
				dictionary = new Dictionary<int, BeltSignal>();
				_signalBelts[index] = dictionary;
				return dictionary;
			}

			private static Dictionary<int, BeltSignal> GetSignalBelts(int index)
			{
				if (index < 0 || index >= _signalBeltsCapacity)
				{
					return null;
				}
				return _signalBelts[index];
			}

			private static void SetSignalBelt(int factory, int beltId, int signalId, int number)
			{
				int num;
				int num2;
				int num3;
				if (signalId >= 1000)
				{
					if (!BeltSignalNumberAltFormat.Value)
					{
						num = Mathf.Clamp(number % 10, 1, 4);
						num2 = number / 10 % 10 * num;
						num3 = number / 100;
					}
					else
					{
						num = Mathf.Clamp(number / 10000 % 10, 1, 4);
						num2 = number / 100000 % 10 * num;
						num3 = number % 10000;
					}
				}
				else
				{
					num = 0;
					num2 = 0;
					num3 = number;
				}
				if (num3 > 3600)
				{
					num3 = 3600;
				}
				Dictionary<int, BeltSignal> orCreateSignalBelts = GetOrCreateSignalBelts(factory);
				if (orCreateSignalBelts.TryGetValue(beltId, out var value))
				{
					value.SpeedLimit = num3;
					value.Stack = (byte)num;
					value.Inc = (byte)num2;
					value.Progress = 0;
					if (value.SignalId != signalId)
					{
						value.SignalId = signalId;
						AddSourcesToBeltSignal(value, signalId);
					}
					return;
				}
				BeltSignal beltSignal = new BeltSignal
				{
					SignalId = signalId,
					SpeedLimit = num3,
					Stack = (byte)num,
					Inc = (byte)num2
				};
				if (signalId >= 1000)
				{
					AddSourcesToBeltSignal(beltSignal, signalId);
				}
				orCreateSignalBelts[beltId] = beltSignal;
			}

			private static void AddSourcesToBeltSignal(BeltSignal beltSignal, int itemId)
			{
				Dictionary<int, float> dictionary = new Dictionary<int, float>();
				Dictionary<int, float> dictionary2 = new Dictionary<int, float>();
				CalculateAllProductions(dictionary, dictionary2, itemId);
				foreach (KeyValuePair<int, float> item in dictionary2)
				{
					if (!dictionary.TryGetValue(itemId, out var value) || !(value >= item.Value))
					{
						dictionary[itemId] = item.Value;
					}
				}
				dictionary.Remove(itemId);
				int num = dictionary.Count;
				if (num == 0)
				{
					beltSignal.Sources = null;
					beltSignal.SourceProgress = null;
					return;
				}
				Tuple<int, float>[] array = new Tuple<int, float>[num];
				float[] sourceProgress = new float[num];
				foreach (KeyValuePair<int, float> item2 in dictionary)
				{
					array[--num] = Tuple.Create(item2.Key, item2.Value);
				}
				beltSignal.Sources = array;
				beltSignal.SourceProgress = sourceProgress;
			}

			private static void SetSignalBeltPortalTo(int factory, int beltId, int number)
			{
				long num = ((long)factory << 32) | (uint)beltId;
				_portalFrom[num] = number;
				if (!_portalTo.TryGetValue(number, out var value))
				{
					value = new HashSet<long>();
					_portalTo[number] = value;
				}
				value.Add(num);
			}

			private static void RemoveSignalBelt(int factory, int beltId)
			{
				GetSignalBelts(factory)?.Remove(beltId);
			}

			private static void RemovePlanetSignalBelts(int factory)
			{
				GetSignalBelts(factory)?.Clear();
			}

			private static void RemoveSignalBeltPortalEnd(int factory, int beltId)
			{
				long num = ((long)factory << 32) | (uint)beltId;
				if (_portalFrom.TryGetValue(num, out var value))
				{
					_portalFrom.Remove(beltId);
					if (_portalTo.TryGetValue(value, out var value2))
					{
						value2.Remove(num);
					}
				}
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(GameMain), "Begin")]
			private static void GameMain_Begin_Postfix()
			{
				if (BeltSignalGeneratorEnabled.Value)
				{
					InitSignalBelts();
				}
				InitItemSources();
			}

			[HarmonyPostfix]
			[HarmonyPatch(/*Could not decode attribute arguments.*/)]
			private static void DigitalSystem_Constructor_Postfix(PlanetData _planet)
			{
				if (BeltSignalGeneratorEnabled.Value && GameMain.mainPlayer != null)
				{
					PlanetFactory val = _planet?.factory;
					if (val != null)
					{
						RemovePlanetSignalBelts(val.index);
					}
				}
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(CargoTraffic), "RemoveBeltComponent")]
			public static void CargoTraffic_RemoveBeltComponent_Prefix(int id)
			{
				if (_initialized)
				{
					PlanetData localPlanet = GameMain.localPlanet;
					if (localPlanet != null)
					{
						RemoveSignalBeltPortalEnd(localPlanet.factoryIndex, id);
						RemoveSignalBelt(localPlanet.factoryIndex, id);
					}
				}
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(CargoTraffic), "SetBeltSignalIcon")]
			public static void CargoTraffic_SetBeltSignalIcon_Postfix(CargoTraffic __instance, int signalId, int entityId)
			{
				if (!_initialized)
				{
					return;
				}
				PlanetData localPlanet = GameMain.localPlanet;
				if (localPlanet == null)
				{
					return;
				}
				PlanetFactory factory = __instance.factory;
				bool flag = false;
				int num;
				if (signalId >= 1000)
				{
					if (signalId < 20000)
					{
						goto IL_005d;
					}
				}
				else if (signalId >= 601)
				{
					if (signalId <= 609)
					{
						num = Mathf.RoundToInt(factory.entitySignPool[entityId].count0);
						int factoryIndex = localPlanet.factoryIndex;
						int beltId = factory.entityPool[entityId].beltId;
						if (num > 0)
						{
							SetSignalBeltPortalTo(factoryIndex, beltId, num);
						}
						RemoveSignalBelt(factoryIndex, beltId);
						return;
					}
				}
				else
				{
					if (signalId == 404)
					{
						num = 0;
						flag = true;
						goto IL_00c8;
					}
					if (signalId == 600)
					{
						goto IL_005d;
					}
				}
				num = 0;
				goto IL_00c8;
				IL_00c8:
				int factoryIndex2 = localPlanet.factoryIndex;
				int beltId2 = factory.entityPool[entityId].beltId;
				if (flag)
				{
					SetSignalBelt(factoryIndex2, beltId2, signalId, num);
				}
				else
				{
					RemoveSignalBelt(factoryIndex2, beltId2);
				}
				RemoveSignalBeltPortalEnd(factoryIndex2, beltId2);
				return;
				IL_005d:
				num = Mathf.RoundToInt(factory.entitySignPool[entityId].count0);
				if (num > 0)
				{
					flag = true;
				}
				goto IL_00c8;
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(CargoTraffic), "SetBeltSignalNumber")]
			public static void CargoTraffic_SetBeltSignalNumber_Postfix(CargoTraffic __instance, float number, int entityId)
			{
				if (!_initialized)
				{
					return;
				}
				PlanetData localPlanet = GameMain.localPlanet;
				if (localPlanet == null)
				{
					return;
				}
				PlanetFactory factory = __instance.factory;
				SignData[] entitySignPool = factory.entitySignPool;
				uint iconId;
				if (entitySignPool[entityId].iconType == 0 || (iconId = entitySignPool[entityId].iconId0) == 0)
				{
					return;
				}
				if (iconId >= 1000)
				{
					if (iconId >= 20000)
					{
						return;
					}
				}
				else
				{
					switch (iconId)
					{
					default:
						return;
					case 601u:
					case 602u:
					case 603u:
					case 604u:
					case 605u:
					case 606u:
					case 607u:
					case 608u:
					case 609u:
					{
						int factoryIndex = localPlanet.factoryIndex;
						int beltId = factory.entityPool[entityId].beltId;
						RemoveSignalBeltPortalEnd(factoryIndex, beltId);
						SetSignalBeltPortalTo(factoryIndex, beltId, Mathf.RoundToInt(number));
						return;
					}
					case 600u:
						break;
					}
				}
				int factoryIndex2 = localPlanet.factoryIndex;
				int beltId2 = factory.entityPool[entityId].beltId;
				int num = Mathf.RoundToInt(number);
				if (num == 0)
				{
					RemoveSignalBelt(factoryIndex2, beltId2);
				}
				else
				{
					SetSignalBelt(factoryIndex2, beltId2, (int)iconId, num);
				}
			}

			public static void ProcessBeltSignals()
			{
				//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
				if (!_initialized)
				{
					return;
				}
				PlanetFactory[] array = GameMain.data?.factories;
				if (array == null)
				{
					return;
				}
				PerformanceMonitor.BeginSample((ECpuWorkEntry)9);
				PlanetFactory[] array2 = array;
				int progress = default(int);
				byte b5 = default(byte);
				byte b3 = default(byte);
				Cargo val2 = default(Cargo);
				int num6 = default(int);
				byte b = default(byte);
				byte b2 = default(byte);
				byte b4 = default(byte);
				foreach (PlanetFactory val in array2)
				{
					if (val == null)
					{
						continue;
					}
					Dictionary<int, BeltSignal> signalBelts = GetSignalBelts(val.index);
					if (signalBelts == null || signalBelts.Count == 0)
					{
						continue;
					}
					FactoryProductionStat obj = GameMain.statistics.production.factoryStatPool[val.index];
					int[] productRegister = obj.productRegister;
					int[] consumeRegister = obj.consumeRegister;
					bool value = BeltSignalCountRecipeEnabled.Value;
					CargoTraffic cargoTraffic = val.cargoTraffic;
					foreach (KeyValuePair<int, BeltSignal> item3 in signalBelts)
					{
						BeltSignal value2 = item3.Value;
						int signalId = value2.SignalId;
						if (signalId >= 1000)
						{
							if (signalId >= 20000)
							{
								continue;
							}
							bool flag = value2.SpeedLimit > 0;
							if (flag)
							{
								value2.Progress += value2.SpeedLimit;
								progress = value2.Progress;
								if (progress < 3600)
								{
									continue;
								}
								if (progress > 18000)
								{
									value2.Progress = 14400;
								}
							}
							int key = item3.Key;
							ref BeltComponent reference = ref cargoTraffic.beltPool[key];
							CargoPath cargoPath = cargoTraffic.GetCargoPath(reference.segPathId);
							if (cargoPath == null)
							{
								continue;
							}
							byte stack = value2.Stack;
							byte inc = value2.Inc;
							if (!cargoPath.TryInsertItem(reference.segIndex + reference.segPivotOffset, signalId, stack, inc))
							{
								continue;
							}
							if (flag)
							{
								value2.Progress -= 3600;
							}
							productRegister[signalId] += stack;
							if (!value)
							{
								continue;
							}
							Tuple<int, float>[] sources = value2.Sources;
							if (sources == null)
							{
								continue;
							}
							float[] sourceProgress = value2.SourceProgress;
							float num = (int)stack;
							for (int num2 = sources.Length - 1; num2 >= 0; num2--)
							{
								float num3 = sourceProgress[num2] + sources[num2].Item2 * num;
								if (num3 > 0f)
								{
									int item = sources[num2].Item1;
									int num4 = Mathf.CeilToInt(num3);
									productRegister[item] += num4;
									consumeRegister[item] += num4;
									sourceProgress[num2] = num3 - (float)num4;
								}
								else
								{
									sourceProgress[num2] = num3;
								}
							}
							continue;
						}
						switch (signalId)
						{
						case 404:
						{
							int key3 = item3.Key;
							ref BeltComponent reference4 = ref cargoTraffic.beltPool[key3];
							CargoPath cargoPath3 = cargoTraffic.GetCargoPath(reference4.segPathId);
							int num7;
							if (cargoPath3 != null && (num7 = cargoPath3.TryPickItem(reference4.segIndex + reference4.segPivotOffset - 5, 12, ref b5, ref b3)) > 0)
							{
								consumeRegister[num7] += b5;
							}
							break;
						}
						case 600:
						{
							if (!_portalTo.TryGetValue(value2.SpeedLimit, out var value3))
							{
								break;
							}
							int key2 = item3.Key;
							ref BeltComponent reference2 = ref cargoTraffic.beltPool[key2];
							CargoPath cargoPath2 = cargoTraffic.GetCargoPath(reference2.segPathId);
							if (cargoPath2 == null)
							{
								break;
							}
							int num5 = reference2.segIndex + reference2.segPivotOffset;
							if (!cargoPath2.GetCargoAtIndex(num5, ref val2, ref num6, ref progress))
							{
								break;
							}
							short item2 = val2.item;
							Cargo[] cargoPool = cargoPath2.cargoContainer.cargoPool;
							byte inc2 = cargoPool[num6].inc;
							byte stack2 = cargoPool[num6].stack;
							foreach (long item4 in value3)
							{
								CargoTraffic cargoTraffic2 = array[(int)(item4 >> 32)].cargoTraffic;
								ref BeltComponent reference3 = ref cargoTraffic2.beltPool[(int)(item4 & 0x7FFFFFFF)];
								cargoPath2 = cargoTraffic2.GetCargoPath(reference3.segPathId);
								if (cargoPath2 != null && cargoPath2.TryInsertItem(reference3.segIndex + reference3.segPivotOffset, (int)item2, stack2, inc2))
								{
									cargoPath2.TryPickItem(num5 - 5, 12, ref b, ref b2);
									if (b2 != inc2 || b != stack2)
									{
										cargoPath2.TryPickItem(num5 - 5, 12, ref b3, ref b4);
									}
									break;
								}
							}
							break;
						}
						}
					}
				}
				PerformanceMonitor.EndSample((ECpuWorkEntry)9);
			}

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(GameData), "GameTick")]
			public static IEnumerable<CodeInstruction> GameData_GameTick_Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				//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_0067: Unknown result type (might be due to invalid IL or missing references)
				//IL_006d: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(PerformanceMonitor), "EndSample", (Type[])null, (Type[])null), (string)null)
				}).Advance(1).Insert((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(BeltSignalGenerator), "ProcessBeltSignals", (Type[])null, (Type[])null))
				});
				return val.InstructionEnumeration();
			}

			private static void InitItemSources()
			{
				if (_itemSourcesInitialized)
				{
					return;
				}
				VeinProto[] dataArray = ((ProtoSet<VeinProto>)(object)LDB.veins).dataArray;
				foreach (VeinProto val in dataArray)
				{
					ItemSources[val.MiningItem] = new ItemSource
					{
						Count = 1f
					};
				}
				ItemProto[] dataArray2 = ((ProtoSet<ItemProto>)(object)LDB.items).dataArray;
				foreach (ItemProto val2 in dataArray2)
				{
					if (!string.IsNullOrEmpty(val2.MiningFrom))
					{
						ItemSources[((Proto)val2).ID] = new ItemSource
						{
							Count = 1f
						};
					}
				}
				ItemSources[1208] = new ItemSource
				{
					Count = 1f
				};
				RecipeProto[] dataArray3 = ((ProtoSet<RecipeProto>)(object)LDB.recipes).dataArray;
				RecipeProto[] array = dataArray3;
				foreach (RecipeProto val3 in array)
				{
					if (!val3.Explicit || ((Proto)val3).ID == 58 || ((Proto)val3).ID == 121)
					{
						continue;
					}
					int[] results = val3.Results;
					int[] resultCounts = val3.ResultCounts;
					int num = results.Length;
					for (int j = 0; j < num; j++)
					{
						if (ItemSources.ContainsKey(results[j]))
						{
							continue;
						}
						ItemSource itemSource = new ItemSource
						{
							Count = resultCounts[j],
							From = new Dictionary<int, float>()
						};
						int[] items = val3.Items;
						int[] itemCounts = val3.ItemCounts;
						int num2 = items.Length;
						for (int k = 0; k < num2; k++)
						{
							itemSource.From[items[k]] = itemCounts[k];
						}
						if (num > 1)
						{
							itemSource.Extra = new Dictionary<int, float>();
							for (int l = 0; l < num; l++)
							{
								if (j != l)
								{
									itemSource.Extra[results[l]] = resultCounts[l];
								}
							}
						}
						ItemSources[results[j]] = itemSource;
					}
				}
				array = dataArray3;
				foreach (RecipeProto val4 in array)
				{
					if (val4.Explicit)
					{
						continue;
					}
					int[] results2 = val4.Results;
					int[] resultCounts2 = val4.ResultCounts;
					int num3 = results2.Length;
					for (int m = 0; m < num3; m++)
					{
						if (ItemSources.ContainsKey(results2[m]))
						{
							continue;
						}
						ItemSource itemSource2 = new ItemSource
						{
							Count = resultCounts2[m],
							From = new Dictionary<int, float>()
						};
						int[] items2 = val4.Items;
						int[] itemCounts2 = val4.ItemCounts;
						int num4 = items2.Length;
						for (int n = 0; n < num4; n++)
						{
							itemSource2.From[items2[n]] = itemCounts2[n];
						}
						if (num3 > 1)
						{
							itemSource2.Extra = new Dictionary<int, float>();
							for (int num5 = 0; num5 < num3; num5++)
							{
								if (m != num5)
								{
									itemSource2.Extra[results2[num5]] = resultCounts2[num5];
								}
							}
						}
						ItemSources[results2[m]] = itemSource2;
					}
				}
				_itemSourcesInitialized = true;
			}

			private static void CalculateAllProductions(IDictionary<int, float> result, IDictionary<int, float> extra, int itemId, float count = 1f)
			{
				if (!ItemSources.TryGetValue(itemId, out var value))
				{
					return;
				}
				float num = 1f;
				if (Math.Abs(count - value.Count) > 1E-06f)
				{
					num = count / value.Count;
				}
				result.TryGetValue(itemId, out var value2);
				result[itemId] = value2 + count;
				if (value.Extra != null)
				{
					foreach (KeyValuePair<int, float> item in value.Extra)
					{
						extra.TryGetValue(item.Key, out var value3);
						extra[item.Key] = value3 + num * item.Value;
					}
				}
				if (value.From == null)
				{
					return;
				}
				foreach (KeyValuePair<int, float> item2 in value.From)
				{
					CalculateAllProductions(result, extra, item2.Key, num * item2.Value);
				}
			}
		}

		private static class RemovePowerSpaceLimit
		{
			private static Harmony _patch;

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

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(BuildTool_Click), "CheckBuildConditions")]
			[HarmonyPatch(typeof(BuildTool_BlueprintPaste), "CheckBuildConditions")]
			private static IEnumerable<CodeInstruction> BuildTool_CheckBuildConditions_Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				//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_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, (ILGenerator)null);
				val.Start().MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Ldc_R4, (object)110.25f, (string)null)
				});
				if (val.IsValid)
				{
					val.Repeat((Action<CodeMatcher>)delegate(CodeMatcher codeMatcher)
					{
						codeMatcher.SetAndAdvance(OpCodes.Ldc_R4, (object)1f);
					}, (Action<string>)null);
				}
				val.Start().MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Ldc_R4, (object)144f, (string)null)
				});
				if (val.IsValid)
				{
					val.Repeat((Action<CodeMatcher>)delegate(CodeMatcher codeMatcher)
					{
						codeMatcher.SetAndAdvance(OpCodes.Ldc_R4, (object)1f);
					}, (Action<string>)null);
				}
				return val.InstructionEnumeration();
			}
		}

		private static class BoostWindPower
		{
			private static Harmony _patch;

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

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(PowerGeneratorComponent), "EnergyCap_Wind")]
			private static IEnumerable<CodeInstruction> PowerGeneratorComponent_EnergyCap_Wind_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_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_002f: Expected O, but got Unknown
				//IL_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Expected O, but got Unknown
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				//IL_005e: 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_007e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0084: Expected O, but got Unknown
				//IL_009f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a5: Expected O, but got Unknown
				//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bd: Expected O, but got Unknown
				//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cb: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.Start().RemoveInstructions(val.Length);
				val.Insert((CodeInstruction[])(object)new CodeInstruction[8]
				{
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					new CodeInstruction(OpCodes.Ldarg_1, (object)null),
					new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(PowerGeneratorComponent), "currentStrength")),
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					new CodeInstruction(OpCodes.Ldc_I8, (object)500000000L),
					new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(PowerGeneratorComponent), "capacityCurrentTick")),
					new CodeInstruction(OpCodes.Ldc_I8, (object)500000000L),
					new CodeInstruction(OpCodes.Ret, (object)null)
				});
				return val.InstructionEnumeration();
			}
		}

		private static class BoostSolarPower
		{
			private static Harmony _patch;

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

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(PowerGeneratorComponent), "EnergyCap_PV")]
			private static IEnumerable<CodeInstruction> PowerGeneratorComponent_EnergyCap_PV_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_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Expected O, but got Unknown
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Expected O, but got Unknown
				//IL_005b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0061: Expected O, but got Unknown
				//IL_0069: Unknown result type (might be due to invalid IL or missing references)
				//IL_006f: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a8: Expected O, but got Unknown
				//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c0: Expected O, but got Unknown
				//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ce: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.Start().RemoveInstructions(val.Length).Insert((CodeInstruction[])(object)new CodeInstruction[8]
				{
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					new CodeInstruction(OpCodes.Ldarg_S, (object)4),
					new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(PowerGeneratorComponent), "currentStrength")),
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					new CodeInstruction(OpCodes.Ldc_I8, (object)600000000L),
					new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(PowerGeneratorComponent), "capacityCurrentTick")),
					new CodeInstruction(OpCodes.Ldc_I8, (object)600000000L),
					new CodeInstruction(OpCodes.Ret, (object)null)
				});
				return val.InstructionEnumeration();
			}
		}

		private static class BoostFuelPower
		{
			private static Harmony _patch;

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

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(PowerGeneratorComponent), "EnergyCap_Fuel")]
			private static IEnumerable<CodeInstruction> PowerGeneratorComponent_EnergyCap_Fuel_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_004b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0051: Expected O, but got Unknown
				//IL_007c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0088: Expected O, but got Unknown
				//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00aa: Expected O, but got Unknown
				//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b8: Expected O, but got Unknown
				//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cb: Expected O, but got Unknown
				//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e3: Expected O, but got Unknown
				//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f6: Expected O, but got Unknown
				//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
				//IL_0116: Expected O, but got Unknown
				//IL_0132: Unknown result type (might be due to invalid IL or missing references)
				//IL_0138: Expected O, but got Unknown
				//IL_0140: Unknown result type (might be due to invalid IL or missing references)
				//IL_0146: Expected O, but got Unknown
				//IL_0154: Unknown result type (might be due to invalid IL or missing references)
				//IL_015a: Expected O, but got Unknown
				//IL_016d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0173: Expected O, but got Unknown
				//IL_0181: Unknown result type (might be due to invalid IL or missing references)
				//IL_0187: Expected O, but got Unknown
				//IL_019a: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b2: Expected O, but got Unknown
				//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d4: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				Label label = generator.DefineLabel();
				Label label2 = generator.DefineLabel();
				Label label3 = generator.DefineLabel();
				val.Start().MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(PowerGeneratorComponent), "capacityCurrentTick"), (string)null)
				});
				List<Label> labels = val.Labels;
				val.Labels = new List<Label>();
				val.Insert((CodeInstruction[])(object)new CodeInstruction[14]
				{
					CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Ldarg_0, (object)null), (IEnumerable<Label>)labels),
					new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(PowerGeneratorComponent), "fuelMask")),
					new CodeInstruction(OpCodes.Ldc_I4_4, (object)null),
					new CodeInstruction(OpCodes.Bne_Un_S, (object)label),
					new CodeInstruction(OpCodes.Ldc_I8, (object)10000L),
					new CodeInstruction(OpCodes.Br_S, (object)label3),
					CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Ldarg_0, (object)null), new Label[1] { label }),
					new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(PowerGeneratorComponent), "fuelMask")),
					new CodeInstruction(OpCodes.Ldc_I4_2, (object)null),
					new CodeInstruction(OpCodes.Bne_Un_S, (object)label2),
					new CodeInstruction(OpCodes.Ldc_I8, (object)20000L),
					new CodeInstruction(OpCodes.Br_S, (object)label3),
					CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Ldc_I8, (object)50000L), new Label[1] { label2 }),
					CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Mul, (object)null), new Label[1] { label3 })
				});
				return val.InstructionEnumeration();
			}
		}

		private static class BoostGeothermalPower
		{
			private static Harmony _patch;

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

			[HarmonyTranspiler]
			[HarmonyPatch(typeof(PowerGeneratorComponent), "EnergyCap_GTH")]
			private static IEnumerable<CodeInstruction> PowerGeneratorComponent_EnergyCap_GTH_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_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: 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_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: 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_009e: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a4: Expected O, but got Unknown
				//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c5: Expected O, but got Unknown
				//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00dd: Expected O, but got Unknown
				//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00eb: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, generator);
				val.Start().RemoveInstructions(val.Length).Insert((CodeInstruction[])(object)new CodeInstruction[9]
				{
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(PowerGeneratorComponent), "gthStrength")),
					new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(PowerGeneratorComponent), "currentStrength")),
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					new CodeInstruction(OpCodes.Ldc_I8, (object)2000000000L),
					new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(PowerGeneratorComponent), "capacityCurrentTick")),
					new CodeInstruction(OpCodes.Ldc_I8, (object)2000000000L),
					new CodeInstruction(OpCodes.Ret, (object)null)
				});
				return val.InstructionEnumeration();
			}
		}

		public static ConfigEntry<bool> ImmediateEnabled;

		public static ConfigEntry<bool> ArchitectModeEnabled;

		public static ConfigEntry<bool> NoConditionEnabled;

		public static ConfigEntry<bool> NoCollisionEnabled;

		public static ConfigEntry<bool> BeltSignalGeneratorEnabled;

		public static ConfigEntry<bool> BeltSignalNumberAltFormat;

		public static ConfigEntry<bool> BeltSignalCountRecipeEnabled;

		public static ConfigEntry<bool> RemovePowerSpaceLimitE