Decompiled source of SampleAndHoldSim v0.6.12

SampleAndHoldSim.dll

Decompiled 2 months ago
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using CheatEnabler.Patches;
using DysonSphereProgram.Modding.Blackbox;
using HarmonyLib;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("SampleAndHoldSim")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SampleAndHoldSim")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("81abb0fd-fda6-4540-be7c-fc097cd16b18")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.6.12.0")]
[module: UnverifiableCode]
namespace SampleAndHoldSim;

public class Fix_Patch
{
	[HarmonyPrefix]
	[HarmonyPriority(600)]
	[HarmonyPatch(typeof(PowerExchangerComponent), "CalculateActualEnergyPerTick")]
	public static bool CalculateActualEnergyPerTick_Overwrite(ref PowerExchangerComponent __instance, bool isOutput, ref long __result)
	{
		int num;
		if (isOutput)
		{
			num = __instance.poolInc;
		}
		else
		{
			int emptyCount = __instance.emptyCount;
			int emptyInc = __instance.emptyInc;
			num = ((PowerExchangerComponent)(ref __instance)).split_inc(ref emptyCount, ref emptyInc, 1);
		}
		if (num > 0)
		{
			if (num >= Cargo.accTableMilli.Length)
			{
				num = Cargo.accTableMilli.Length - 1;
			}
			__result = __instance.energyPerTick + (long)((double)__instance.energyPerTick * Cargo.accTableMilli[num] + 0.1);
			return false;
		}
		__result = __instance.energyPerTick;
		return false;
	}
}
public class GameData_Patch
{
	private static PlanetFactory[] idleFactories;

	private static PlanetFactory[] workFactories;

	private static long[] workFactoryTimes;

	private static int idleFactoryCount;

	private static int workFactoryCount;

	public static bool DFGroundSystemLogic_Prefix(GameData gameData, long time)
	{
		if (MainManager.UpdatePeriod <= 1)
		{
			return true;
		}
		PlanetFactory localLoadedPlanetFactory = gameData.localLoadedPlanetFactory;
		if (localLoadedPlanetFactory != null)
		{
			localLoadedPlanetFactory.LocalizeEnemies();
		}
		if (time > 0)
		{
			PerformanceMonitor.BeginSample((ECpuWorkEntry)37);
			for (int i = 0; i < workFactoryCount; i++)
			{
				workFactories[i].enemySystem.GameTickLogic(workFactoryTimes[i]);
				workFactories[i].enemySystem.ExecuteDeferredEnemyChange();
			}
			PerformanceMonitor.EndSample((ECpuWorkEntry)37);
			for (int j = 0; j < workFactoryCount; j++)
			{
				EnemyDFGroundSystem enemySystem = workFactories[j].enemySystem;
				if (enemySystem != null && enemySystem.keytick_timer >= 60)
				{
					enemySystem.DecisionAI();
					enemySystem.KeyTickLogic(workFactoryTimes[j]);
					enemySystem.ExecuteDeferredEnemyChange();
					enemySystem.ExecuteDeferredUnitFormation();
					enemySystem.PostKeyTick();
				}
			}
		}
		return false;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(GameMain), "Begin")]
	public static void GameMain_Begin()
	{
		if (GameMain.data != null)
		{
			int num = GameMain.data.factories.Length;
			workFactories = (PlanetFactory[])(object)new PlanetFactory[num];
			idleFactories = (PlanetFactory[])(object)new PlanetFactory[num];
			workFactoryTimes = new long[num];
			MainManager.Init();
			UIstation.SetVeiwStation(-1, -1, 0);
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(GameMain), "End")]
	public static void GameMain_End()
	{
		Plugin.instance.SaveConfig(MainManager.UpdatePeriod, MainManager.FocusLocalFactory);
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(GameData), "GameTick")]
	private static void GameTick_Prefix()
	{
		workFactoryCount = MainManager.SetFactories(workFactories, idleFactories, workFactoryTimes);
		idleFactoryCount = GameMain.data.factoryCount - workFactoryCount;
	}

	public static IEnumerable<CodeInstruction> ReplaceFactories(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Expected O, but got Unknown
		return new CodeMatcher(new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldfld && ((FieldInfo)i.operand).Name == "factories"), (string)null)
		}).Repeat((Action<CodeMatcher>)delegate(CodeMatcher matcher)
		{
			matcher.SetAndAdvance(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(GameData_Patch), "workFactories")).Advance(-2).SetAndAdvance(OpCodes.Nop, (object)null);
		}, (Action<string>)null).InstructionEnumeration(), (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldfld && ((FieldInfo)i.operand).Name == "factoryCount"), (string)null)
		}).Repeat((Action<CodeMatcher>)delegate(CodeMatcher matcher)
		{
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Expected O, but got Unknown
			matcher.SetAndAdvance(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(GameData_Patch), "workFactoryCount")).Advance(-2).SetAndAdvance(OpCodes.Nop, (object)null);
			if (matcher.InstructionAt(1).opcode == OpCodes.Blt)
			{
				matcher.Advance(-6);
				CodeInstruction instruction = matcher.Instruction;
				while (matcher.Opcode != OpCodes.Br)
				{
					if (matcher.Opcode == OpCodes.Ldarg_1)
					{
						matcher.RemoveInstruction().Insert((CodeInstruction[])(object)new CodeInstruction[3]
						{
							new CodeInstruction(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(GameData_Patch), "workFactoryTimes")),
							instruction,
							new CodeInstruction(OpCodes.Ldelem_I8, (object)null)
						});
						matcher.Advance(-2);
					}
					matcher.Advance(-1);
				}
			}
		}, (Action<string>)null).InstructionEnumeration();
	}

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(GameData), "GameTick")]
	private static IEnumerable<CodeInstruction> GameTick_Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Expected O, but got Unknown
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Expected O, but got Unknown
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Expected O, but got Unknown
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Expected O, but got Unknown
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Expected O, but got Unknown
		try
		{
			CodeMatcher val = new CodeMatcher(ReplaceFactories(instructions), (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Callvirt && ((MethodInfo)i.operand).Name == "PrepareTransportData"), (string)null)
			}).Advance(-5).SetAndAdvance(OpCodes.Ldarg_0, (object)null)
				.SetAndAdvance(OpCodes.Ldfld, (object)AccessTools.Field(typeof(GameData), "factories"))
				.SetAndAdvance(OpCodes.Ldarg_0, (object)null)
				.SetAndAdvance(OpCodes.Ldfld, (object)AccessTools.Field(typeof(GameData), "factoryCount"));
			val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[3]
			{
				new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(GameDesc), "get_isCombatMode", (Type[])null, (Type[])null), (string)null),
				new CodeMatch((OpCode?)OpCodes.Brfalse, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null)
			});
			if (val.IsInvalid)
			{
				Log.Error("GameTick_Transpiler: Can't find DFGroundSystemLogic!");
				return val.InstructionEnumeration();
			}
			CodeInstruction val2 = val.InstructionAt(-1);
			val.Insert((CodeInstruction[])(object)new CodeInstruction[4]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldarg_1, (object)null),
				new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(GameData_Patch), "DFGroundSystemLogic_Prefix", (Type[])null, (Type[])null)),
				val2
			});
			return val.InstructionEnumeration();
		}
		catch
		{
			Log.Error("Transpiler GameData.GameTick failed.");
			return instructions;
		}
	}
}
internal class Combat_Patch
{
	[HarmonyTranspiler]
	[HarmonyPatch(typeof(EnemyUnitComponent), "ApproachToTargetPoint_SLancer")]
	[HarmonyPatch(typeof(EnemyUnitComponent), "Attack_SLancer")]
	[HarmonyPatch(typeof(EnemyUnitComponent), "RunBehavior_OrbitTarget_SLancer")]
	private static IEnumerable<CodeInstruction> ScaleDamageDown(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Expected O, but got Unknown
		FieldInfo plasma = AccessTools.Field(typeof(GeneralProjectile), "damage");
		FieldInfo laser = AccessTools.Field(typeof(SpaceLaserOneShot), "damage");
		FieldInfo sweep = AccessTools.Field(typeof(SpaceLaserSweep), "damage");
		return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Stfld && ((FieldInfo)i.operand == plasma || (FieldInfo)i.operand == laser || (FieldInfo)i.operand == sweep)), (string)null)
		}).Repeat((Action<CodeMatcher>)delegate(CodeMatcher matcher)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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
			matcher.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2]
			{
				new CodeInstruction(OpCodes.Ldarg_2, (object)null),
				new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Combat_Patch), "ModDamageDown", (Type[])null, (Type[])null))
			}).Advance(5);
		}, (Action<string>)null).InstructionEnumeration();
	}

	private static int ModDamageDown(int originValue, EnemyDFHiveSystem enemyDFHive)
	{
		if (MainManager.UpdatePeriod <= 1 || enemyDFHive.starData.index == MainManager.FocusStarIndex)
		{
			return originValue;
		}
		return originValue / MainManager.UpdatePeriod;
	}

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(TurretComponent), "Shoot_Plasma")]
	[HarmonyPatch(typeof(TurretComponent), "Shoot_Missile")]
	private static IEnumerable<CodeInstruction> ScaleDamageUp(IEnumerable<CodeInstruction> instructions)
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Expected O, but got Unknown
		FieldInfo plasma = AccessTools.Field(typeof(GeneralProjectile), "damage");
		FieldInfo missile = AccessTools.Field(typeof(GeneralMissile), "damage");
		return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Stfld && ((FieldInfo)i.operand == plasma || (FieldInfo)i.operand == missile)), (string)null)
		}).Repeat((Action<CodeMatcher>)delegate(CodeMatcher matcher)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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
			matcher.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2]
			{
				new CodeInstruction(OpCodes.Ldarg_1, (object)null),
				new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Combat_Patch), "ModDamageUp", (Type[])null, (Type[])null))
			}).Advance(5);
		}, (Action<string>)null).InstructionEnumeration();
	}

	private static int ModDamageUp(int originValue, PlanetFactory factory)
	{
		if (MainManager.UpdatePeriod <= 1 || factory.index == MainManager.FocusFactoryIndex)
		{
			return originValue;
		}
		return originValue * MainManager.UpdatePeriod;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(PlanetATField), "TestRelayCondition")]
	private static bool TestRelayCondition()
	{
		return Plugin.instance.EnableRelayLanding.Value;
	}
}
public struct ProjectileData
{
	public int PlanetId;

	public int TargetId;

	public Vector3 LocalPos;
}
public class FactoryManager
{
	private ConcurrentBag<ProjectileData> dysonBag;

	private readonly List<ProjectileData> dysonList = new List<ProjectileData>();

	private int idleCount;

	public bool IsActive;

	public bool IsNextIdle;

	public int Index;

	public PlanetFactory factory;

	private readonly Dictionary<int, StationData> stationDict = new Dictionary<int, StationData>();

	public long EnergyReqCurrentTick { get; set; }

	public void AddDysonData(int planetId, int targetId, in Vector3 localPos)
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		if (dysonBag == null)
		{
			dysonBag = new ConcurrentBag<ProjectileData>();
		}
		dysonBag.Add(new ProjectileData
		{
			PlanetId = planetId,
			TargetId = targetId,
			LocalPos = localPos
		});
	}

	public void DysonColletEnd()
	{
		if (dysonBag != null)
		{
			idleCount = 0;
			dysonList.Clear();
			ProjectileData result;
			while (dysonBag.TryTake(out result))
			{
				dysonList.Add(result);
			}
		}
	}

	public void DysonIdleTick()
	{
		if (factory.dysonSphere == null)
		{
			return;
		}
		DysonSphere dysonSphere = factory.dysonSphere;
		dysonSphere.energyReqCurrentTick += EnergyReqCurrentTick;
		if (dysonList.Count <= 0)
		{
			return;
		}
		idleCount++;
		foreach (ProjectileData dyson in dysonList)
		{
			if (dyson.TargetId < 0)
			{
				Dyson_Patch.AddBullet(factory.dysonSphere.swarm, dyson);
			}
			else
			{
				Dyson_Patch.AddRocket(factory.dysonSphere, dyson, idleCount);
			}
		}
	}

	public FactoryManager(int index, PlanetFactory factory)
	{
		Index = index;
		this.factory = factory;
	}

	public void SetMineral(StationComponent station, int mineralCount)
	{
		if (!stationDict.TryGetValue(station.id, out var value))
		{
			stationDict.Add(station.id, new StationData(station));
			value = stationDict[station.id];
		}
		StationData.SetMineral(value, mineralCount);
	}

	public void StationAfterTransport()
	{
		if (IsActive)
		{
			Traversal(StationData.ActiveBegin, record: false);
		}
	}

	public void StationAfterTick()
	{
		if (IsActive)
		{
			Traversal(StationData.ActiveEnd, Index == UIstation.ViewFactoryIndex);
		}
		else
		{
			Traversal(StationData.IdleEnd, record: false);
		}
	}

	private void Traversal(Action<StationData, StationComponent> action, bool record)
	{
		PlanetTransport transport = factory.transport;
		for (int i = 1; i < transport.stationCursor; i++)
		{
			if (transport.stationPool[i] != null && transport.stationPool[i].id == i)
			{
				if (!stationDict.ContainsKey(i))
				{
					stationDict.Add(i, new StationData(transport.stationPool[i]));
				}
				action(stationDict[i], transport.stationPool[i]);
				if (record && i == UIstation.VeiwStationId)
				{
					UIstation.Record(stationDict[i]);
				}
			}
		}
	}
}
internal class Ejector_Patch
{
	[HarmonyTranspiler]
	[HarmonyPatch(typeof(EjectorComponent), "InternalUpdate")]
	public static IEnumerable<CodeInstruction> EjectorComponent_Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Expected O, but got Unknown
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Expected O, but got Unknown
		try
		{
			CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(SailBullet), "lBegin"), (string)null)
			});
			CodeInstruction val2 = val.InstructionAt(-1);
			val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(DysonSwarm), "AddBullet", (Type[])null, (Type[])null), (string)null)
			}).Advance(2).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[6]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(EjectorComponent), "planetId")),
				val2,
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(EjectorComponent), "orbitId")),
				Transpilers.EmitDelegate<Action<int, Vector3, int>>((Action<int, Vector3, int>)delegate(int planetId, Vector3 localPos, int orbitId)
				{
					if (MainManager.Planets.TryGetValue(planetId, out var value) && value.IsNextIdle)
					{
						value.AddDysonData(planetId, -orbitId, in localPos);
					}
				})
			});
			return val.InstructionEnumeration();
		}
		catch
		{
			Log.Warn("EjectorComponent.InternalUpdate Transpiler failed.");
			return instructions;
		}
	}
}
internal class Dyson_Patch
{
	[HarmonyTranspiler]
	[HarmonyPatch(typeof(PowerSystem), "RequestDysonSpherePower")]
	private static IEnumerable<CodeInstruction> RequestDysonSpherePower_Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Expected O, but got Unknown
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Expected O, but got Unknown
		try
		{
			CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Stfld && ((FieldInfo)i.operand).Name == "energyReqCurrentTick"), (string)null)
			});
			CodeInstruction val2 = val.InstructionAt(-2);
			val.Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[4]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(PowerSystem), "factory")),
				val2,
				Transpilers.EmitDelegate<Action<PlanetFactory, long>>((Action<PlanetFactory, long>)delegate(PlanetFactory factory, long energyReq)
				{
					if (factory.index < MainManager.Factories.Count)
					{
						MainManager.Factories[factory.index].EnergyReqCurrentTick = energyReq;
					}
				})
			});
			return val.InstructionEnumeration();
		}
		catch
		{
			Log.Warn("PowerSystem.RequestDysonSpherePower Transpiler failed.");
			return instructions;
		}
	}

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(SiloComponent), "InternalUpdate")]
	private static IEnumerable<CodeInstruction> SiloComponent_Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0002: 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_0037: Expected O, but got Unknown
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Expected O, but got Unknown
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Expected O, but got Unknown
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Expected O, but got Unknown
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Expected O, but got Unknown
		try
		{
			CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(DysonSphere), "AddDysonRocket", (Type[])null, (Type[])null), (string)null)
			});
			CodeInstruction val2 = val.InstructionAt(-1);
			val.Advance(2).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[6]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(SiloComponent), "planetId")),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(SiloComponent), "localPos")),
				val2,
				Transpilers.EmitDelegate<Action<int, Vector3, DysonNode>>((Action<int, Vector3, DysonNode>)delegate(int planetId, Vector3 localPos, DysonNode autoDysonNode)
				{
					if (MainManager.Planets.TryGetValue(planetId, out var value) && value.IsNextIdle)
					{
						value.AddDysonData(planetId, (autoDysonNode.layerId << 12) | (autoDysonNode.id & 0xFFF), in localPos);
					}
				})
			});
			return val.InstructionEnumeration();
		}
		catch
		{
			Log.Warn("SiloComponent.InternalUpdate Transpiler failed.");
			return instructions;
		}
	}

	public static void AddBullet(DysonSwarm swarm, ProjectileData projectile)
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: 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_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		ref AstroData[] astrosData = ref GameMain.data.galaxy.astrosData;
		int num = -projectile.TargetId;
		if (swarm.OrbitExist(num))
		{
			VectorLF3 uPos = astrosData[projectile.PlanetId / 100 * 100].uPos;
			SailBullet val = default(SailBullet);
			val.lBegin = projectile.LocalPos;
			val.uBegin = astrosData[projectile.PlanetId].uPos + Maths.QRotateLF(astrosData[projectile.PlanetId].uRot, VectorLF3.op_Implicit(projectile.LocalPos));
			VectorLF3 val2 = VectorLF3.Cross(VectorLF3.op_Implicit(swarm.orbits[num].up), uPos - val.uBegin);
			val.uEnd = uPos + ((VectorLF3)(ref val2)).normalized * (double)swarm.orbits[num].radius;
			val2 = val.uEnd - val.uBegin;
			val.maxt = (float)(((VectorLF3)(ref val2)).magnitude / 4000.0);
			val2 = VectorLF3.Cross(val.uEnd - uPos, VectorLF3.op_Implicit(swarm.orbits[num].up));
			val.uEndVel = VectorLF3.op_Implicit(((VectorLF3)(ref val2)).normalized * Math.Sqrt(swarm.dysonSphere.gravity / swarm.orbits[num].radius));
			swarm.AddBullet(val, num);
		}
	}

	public static void AddRocket(DysonSphere sphere, ProjectileData projectile, int idleCount)
	{
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		ref AstroData[] astrosData = ref GameMain.data.galaxy.astrosData;
		int num = projectile.TargetId >> 12;
		int num2 = projectile.TargetId & 0xFFF;
		DysonNode val = sphere.FindNode(num, num2);
		if (val != null)
		{
			DysonRocket val2 = default(DysonRocket);
			val2.planetId = projectile.PlanetId;
			val2.uPos = astrosData[projectile.PlanetId].uPos + Maths.QRotateLF(astrosData[projectile.PlanetId].uRot, VectorLF3.op_Implicit(projectile.LocalPos + ((Vector3)(ref projectile.LocalPos)).normalized * 6.1f));
			val2.uRot = astrosData[projectile.PlanetId].uRot * Maths.SphericalRotation(projectile.LocalPos, 0f) * Quaternion.Euler(-90f, 0f, 0f);
			val2.uVel = val2.uRot * Vector3.forward;
			val2.uSpeed = 0f;
			val2.launch = ((Vector3)(ref projectile.LocalPos)).normalized;
			ref VectorLF3 uPos = ref val2.uPos;
			uPos -= new VectorLF3(VectorLF3.op_Implicit(val2.uVel)) * 15.0 * (double)idleCount;
			if (val._spReq - val.spOrdered > 0)
			{
				sphere.AddDysonRocket(val2, val);
			}
			else if (sphere.GetAutoNodeCount() > 0 && (val = sphere.GetAutoDysonNode(num2)) != null)
			{
				sphere.AddDysonRocket(val2, val);
			}
		}
	}
}
public class Compatibility
{
	public static class CommonAPI
	{
		public const string GUID = "dsp.common-api.CommonAPI";

		public static void Init(Harmony harmony)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Expected O, but got Unknown
			try
			{
				if (Chainloader.PluginInfos.TryGetValue("dsp.common-api.CommonAPI", out var value))
				{
					Type type = ((object)value.Instance).GetType().Assembly.GetType("CommonAPI.Systems.PlanetExtensionSystem");
					harmony.Patch((MethodBase)type.GetMethod("PowerUpdateOnlySinglethread"), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(GameData_Patch).GetMethod("ReplaceFactories")), (HarmonyMethod)null, (HarmonyMethod)null);
					harmony.Patch((MethodBase)type.GetMethod("PreUpdateOnlySinglethread"), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(GameData_Patch).GetMethod("ReplaceFactories")), (HarmonyMethod)null, (HarmonyMethod)null);
					harmony.Patch((MethodBase)type.GetMethod("UpdateOnlySinglethread"), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(GameData_Patch).GetMethod("ReplaceFactories")), (HarmonyMethod)null, (HarmonyMethod)null);
					harmony.Patch((MethodBase)type.GetMethod("PostUpdateOnlySinglethread"), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(GameData_Patch).GetMethod("ReplaceFactories")), (HarmonyMethod)null, (HarmonyMethod)null);
					Log.Debug("CommonAPI compatibility - OK");
				}
			}
			catch (Exception obj)
			{
				string text = "CommonAPI compatibility failed! Last working version: 1.6.5";
				Log.Warn(text);
				Log.Warn(obj);
				errorMessage = errorMessage + text + "\n";
			}
		}
	}

	public static class DSPOptimizations
	{
		public const string GUID = "com.Selsion.DSPOptimizations";

		public static void Init(Harmony harmony)
		{
			try
			{
				if (Chainloader.PluginInfos.TryGetValue("com.Selsion.DSPOptimizations", out var _))
				{
					harmony.PatchAll(typeof(DSPOptimizations));
					Log.Debug("DSPOptimizations compatibility - OK");
				}
			}
			catch (Exception obj)
			{
				string text = "DSPOptimizations compatibility failed! Last working version: 1.1.16";
				Log.Warn(text);
				Log.Warn(obj);
				errorMessage = errorMessage + text + "\n";
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(StationComponent), "UpdateInputSlots")]
		[HarmonyPatch(typeof(StationComponent), "UpdateOutputSlots")]
		public static bool UpdateSlots_Prefix(CargoTraffic traffic)
		{
			if (MainManager.TryGet(traffic.factory.index, out var factoryData) && !factoryData.IsActive)
			{
				return false;
			}
			return true;
		}
	}

	public static class Auxilaryfunction_Patch
	{
		public const string GUID = "cn.blacksnipe.dsp.Auxilaryfunction";

		private static bool enable = false;

		private static int storedUpdatePeriod = 1;

		public static void Init(Harmony harmony)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			try
			{
				if (Chainloader.PluginInfos.TryGetValue("cn.blacksnipe.dsp.Auxilaryfunction", out var value))
				{
					Type type = ((object)value.Instance).GetType().Assembly.GetType("Auxilaryfunction.Patch.GameTickPatch");
					harmony.Patch((MethodBase)type.GetMethod("set_Enable"), new HarmonyMethod(typeof(Auxilaryfunction_Patch).GetMethod("OnStopFactory")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					Log.Debug("Auxilaryfunction compatibility - OK");
				}
			}
			catch (Exception obj)
			{
				string text = "Auxilaryfunction compatibility failed! Last working version: 2.7.7";
				Log.Warn(text);
				Log.Warn(obj);
				errorMessage = errorMessage + text + "\n";
			}
		}

		public static void OnStopFactory(bool value)
		{
			if (enable != value)
			{
				enable = value;
				if (enable)
				{
					storedUpdatePeriod = MainManager.UpdatePeriod;
					MainManager.UpdatePeriod = 1;
				}
				else
				{
					MainManager.UpdatePeriod = storedUpdatePeriod;
					storedUpdatePeriod = 1;
				}
				Log.Debug($"Auxilaryfunction stop factory:{enable}  ratio => {MainManager.UpdatePeriod}");
			}
		}
	}

	public static class Multfunction_mod_Patch
	{
		public static class Warper
		{
		}

		public const string GUID = "cn.blacksnipe.dsp.Multfuntion_mod";

		public static void Init(Harmony harmony)
		{
			try
			{
				if (Chainloader.PluginInfos.TryGetValue("cn.blacksnipe.dsp.Multfuntion_mod", out var _))
				{
					harmony.PatchAll(typeof(Warper));
					warnMessage += "Multifunction: some game-breaking features are not compatible\nSampleAndHoldSim对Multifunction的改机制功能(跳过太阳帆子弹阶段,星球矿机等)兼容性不佳,可能会造成统计数据异常";
				}
			}
			catch (Exception obj)
			{
				string text = "Multfunction_mod compatibility failed! Last working version: 3.4.4";
				Log.Warn(text);
				Log.Warn(obj);
				errorMessage = errorMessage + text + "\n";
			}
		}
	}

	public static class PlanetMiner
	{
		public const string GUID = "crecheng.PlanetMiner";

		public static void Init(Harmony harmony)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			try
			{
				if (Chainloader.PluginInfos.TryGetValue("crecheng.PlanetMiner", out var value))
				{
					MethodInfo methodInfo = AccessTools.Method(((object)value.Instance).GetType().Assembly.GetType("PlanetMiner.PlanetMiner"), "Miner", (Type[])null, (Type[])null);
					harmony.CreateReversePatcher((MethodBase)methodInfo, new HarmonyMethod(AccessTools.Method(typeof(PlanetMiner), "Miner_Original", (Type[])null, (Type[])null))).Patch((HarmonyReversePatchType)0);
					harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(PlanetMiner), "Miner_Transpiler", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null);
					Log.Debug("PlanetMiner compatibility - OK");
				}
			}
			catch (Exception obj)
			{
				string text = "PlanetMiner compatibility failed! Last working version: 3.0.8";
				Log.Warn(text);
				Log.Warn(obj);
				errorMessage = errorMessage + text + "\n";
			}
		}

		private static IEnumerable<CodeInstruction> Miner_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator iLGenerator)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Expected O, but got Unknown
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Expected O, but got Unknown
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Expected O, but got Unknown
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Expected O, but got Unknown
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Expected O, but got Unknown
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Expected O, but got Unknown
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Expected O, but got Unknown
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Expected O, but got Unknown
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Expected O, but got Unknown
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Expected O, but got Unknown
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Expected O, but got Unknown
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Expected O, but got Unknown
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Expected O, but got Unknown
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Expected O, but got Unknown
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Expected O, but got Unknown
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Expected O, but got Unknown
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Expected O, but got Unknown
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Expected O, but got Unknown
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Expected O, but got Unknown
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Expected O, but got Unknown
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Expected O, but got Unknown
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Expected O, but got Unknown
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Expected O, but got Unknown
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0364: Expected O, but got Unknown
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_0378: Expected O, but got Unknown
			//IL_0386: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: Expected O, but got Unknown
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Expected O, but got Unknown
			//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Expected O, but got Unknown
			//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dc: Expected O, but got Unknown
			try
			{
				CodeMatcher val = new CodeMatcher(instructions, iLGenerator);
				Label label = default(Label);
				val.Advance(2).CreateLabel(ref label);
				val.Insert((CodeInstruction[])(object)new CodeInstruction[8]
				{
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(FactorySystem), "planet")),
					new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(PlanetData), "id")),
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(MainManager), "get_FocusPlanetId", (Type[])null, (Type[])null)),
					new CodeInstruction(OpCodes.Bne_Un_S, (object)label),
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(PlanetMiner), "Miner_Original", (Type[])null, (Type[])null)),
					new CodeInstruction(OpCodes.Ret, (object)null)
				});
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldsfld && ((FieldInfo)i.operand).Name == "frame"), (string)null)
				}).RemoveInstruction().Insert((CodeInstruction[])(object)new CodeInstruction[4]
				{
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(GameMain), "get_gameTick", (Type[])null, (Type[])null)),
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(MainManager), "get_UpdatePeriod", (Type[])null, (Type[])null)),
					new CodeInstruction(OpCodes.Conv_I8, (object)null),
					new CodeInstruction(OpCodes.Div, (object)null)
				});
				val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[2]
				{
					new CodeMatch((OpCode?)OpCodes.Add, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Stfld, (object)AccessTools.Field(typeof(StationComponent), "energy"), (string)null)
				}).Insert((CodeInstruction[])(object)new CodeInstruction[3]
				{
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(MainManager), "get_UpdatePeriod", (Type[])null, (Type[])null)),
					new CodeInstruction(OpCodes.Conv_I8, (object)null),
					new CodeInstruction(OpCodes.Mul, (object)null)
				});
				val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[7]
				{
					new CodeMatch((OpCode?)OpCodes.Ldelema, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldflda, (object)AccessTools.Field(typeof(StationStore), "count"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Dup, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldind_I4, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Conv_I4, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Add, (object)null, (string)null)
				}).Insert((CodeInstruction[])(object)new CodeInstruction[2]
				{
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(MainManager), "get_UpdatePeriod", (Type[])null, (Type[])null)),
					new CodeInstruction(OpCodes.Mul, (object)null)
				});
				val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[6]
				{
					new CodeMatch((OpCode?)OpCodes.Ldelema, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldflda, (object)AccessTools.Field(typeof(StationStore), "count"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Dup, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldind_I4, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldc_I4_S, (object)null, (string)null),
					new CodeMatch((OpCode?)OpCodes.Add, (object)null, (string)null)
				}).Insert((CodeInstruction[])(object)new CodeInstruction[2]
				{
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(MainManager), "get_UpdatePeriod", (Type[])null, (Type[])null)),
					new CodeInstruction(OpCodes.Mul, (object)null)
				});
				return val.InstructionEnumeration();
			}
			catch
			{
				Log.Warn("Transpiler Miner failed.");
				return instructions;
			}
		}

		public static void Miner_Original(FactorySystem _)
		{
		}
	}

	public static class Blackbox_Patch
	{
		public static class Warper
		{
			public static void RevertStats(int factoryIndex)
			{
				foreach (Blackbox blackbox in BlackboxManager.Instance.blackboxes)
				{
					BlackboxSimulation simulation = blackbox.Simulation;
					if (simulation == null || simulation.factoryRef == null || !simulation.factoryRef.TryGetTarget(out var target) || target.index != factoryIndex || !simulation.isWorking)
					{
						continue;
					}
					BlackboxRecipe recipe = blackbox.Recipe;
					int num = ((simulation.timeIdx <= 0) ? (recipe.timeSpend - 1) : (simulation.timeIdx - 1));
					float num2 = recipe.timeSpend;
					float num3 = (float)num / num2;
					float num4 = (float)(num + 1) / num2;
					FactoryProductionStat val = GameMain.data.statistics.production.factoryStatPool[target.index];
					foreach (KeyValuePair<int, int> produce in recipe.produces)
					{
						int num5 = (int)(num4 * (float)produce.Value) - (int)(num3 * (float)produce.Value);
						val.productRegister[produce.Key] -= num5;
					}
					foreach (KeyValuePair<int, int> consume in recipe.consumes)
					{
						int num6 = (int)(num4 * (float)consume.Value) - (int)(num3 * (float)consume.Value);
						val.consumeRegister[consume.Key] -= num6;
					}
				}
			}
		}

		public const string GUID = "dev.raptor.dsp.Blackbox";

		public static bool IsPatched { get; private set; }

		public static void Init(Harmony harmony)
		{
			try
			{
				if (Chainloader.PluginInfos.TryGetValue("dev.raptor.dsp.Blackbox", out var _))
				{
					harmony.PatchAll(typeof(Warper));
					IsPatched = true;
					Log.Debug("Blackbox compatibility - OK");
				}
			}
			catch (Exception obj)
			{
				string text = "Blackbox compatibility failed! Last working version: 0.2.4";
				Log.Warn(text);
				Log.Warn(obj);
				errorMessage = errorMessage + text + "\n";
			}
		}
	}

	public static class CheatEnabler_Patch
	{
		private static class Warper
		{
			private static Harmony patch_sample;

			private static Harmony patch_cheatEnabler;

			public static void Init()
			{
				bool value = DysonSpherePatch.SkipBulletEnabled.Value;
				SkipBulletValueChanged_Prefix(value);
				SkipBulletValueChanged_Postfix(value);
			}

			public static void OnDestory()
			{
				if (patch_sample != null)
				{
					patch_sample.UnpatchSelf();
					patch_sample = null;
				}
				if (patch_cheatEnabler != null)
				{
					patch_cheatEnabler.UnpatchSelf();
					patch_cheatEnabler = null;
				}
			}

			internal static void SkipBulletValueChanged_Prefix(bool enable)
			{
				if (enable)
				{
					if (patch_sample != null)
					{
						Log.Info("patch_sample UnpatchSelf");
						patch_sample.UnpatchSelf();
						patch_sample = null;
					}
				}
				else if (patch_cheatEnabler != null)
				{
					Log.Info("patch_cheatEnabler UnpatchSelf");
					patch_cheatEnabler.UnpatchSelf();
					patch_cheatEnabler = null;
				}
			}

			internal static void SkipBulletValueChanged_Postfix(bool enable)
			{
				if (enable)
				{
					if (patch_cheatEnabler == null)
					{
						Log.Info("patch_cheatEnabler create");
						patch_cheatEnabler = Harmony.CreateAndPatchAll(typeof(SkipBullet_Compat_Patch), "starfi5h.plugin.SampleAndHoldSim.patch_cheatEnabler");
					}
				}
				else if (patch_sample == null)
				{
					Log.Info("patch_sample create");
					patch_sample = Harmony.CreateAndPatchAll(typeof(Ejector_Patch), "starfi5h.plugin.SampleAndHoldSim.patch_sample");
				}
			}
		}

		private static class SkipBullet_Compat_Patch
		{
			[HarmonyTranspiler]
			[HarmonyPatch(typeof(EjectorComponent), "InternalUpdate")]
			private static IEnumerable<CodeInstruction> EjectorComponent_ReplaceAddDysonSail(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_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b6: Expected O, but got Unknown
				try
				{
					CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
					val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
					{
						new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(SkipBulletPatch), "AddDysonSail", (Type[])null, (Type[])null), (string)null)
					});
					if (val.IsInvalid)
					{
						Log.Warn("Unable to replace SkipBulletPatch.AddDysonSail for CheatEnabler");
						return instructions;
					}
					val.RemoveInstruction().Insert((CodeInstruction[])(object)new CodeInstruction[3]
					{
						new CodeInstruction(OpCodes.Ldarg_0, (object)null),
						new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(EjectorComponent), "planetId")),
						new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(SkipBullet_Compat_Patch), "AddDysonSailWithPlanetId", (Type[])null, (Type[])null))
					});
					return val.InstructionEnumeration();
				}
				catch (Exception obj)
				{
					Log.Warn("Error in EjectorComponent_ReplaceAddDysonSail");
					Log.Warn(obj);
					return instructions;
				}
			}

			private static void AddDysonSailWithPlanetId(DysonSwarm swarm, int orbitId, VectorLF3 uPos, VectorLF3 endVec, int planetId)
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				int num = ((planetId == MainManager.FocusPlanetId) ? 1 : MainManager.UpdatePeriod);
				for (int i = 0; i < num; i++)
				{
					SkipBulletPatch.AddDysonSail(swarm, orbitId, uPos, endVec);
				}
			}
		}

		public const string GUID = "org.soardev.cheatenabler";

		public static void Init(Harmony harmony)
		{
			if (!Chainloader.PluginInfos.TryGetValue("org.soardev.cheatenabler", out var _))
			{
				harmony.PatchAll(typeof(Ejector_Patch));
				return;
			}
			try
			{
				harmony.PatchAll(typeof(CheatEnabler_Patch));
				Log.Debug("CheatEnabler compatibility - OK");
			}
			catch (Exception obj)
			{
				string text = "CheatEnabler skipbullet compatibility failed! Last working version: 2.3.26";
				Log.Warn(text);
				Log.Warn(obj);
				errorMessage = errorMessage + text + "\n";
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameMain), "Begin")]
		private static void OnGameBegin()
		{
			try
			{
				Warper.Init();
			}
			catch (Exception obj)
			{
				Log.Warn("CheatEnabler skipbullet compatibility failed! Last working version: 2.3.26");
				Log.Warn(obj);
			}
		}

		public static void OnDestory()
		{
			Warper.OnDestory();
		}
	}

	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static Response <>9__8_0;

		public static Response <>9__8_1;

		internal void <ShowMessage>b__8_0()
		{
			Plugin.instance.WarnIncompat.Value = false;
		}

		internal void <ShowMessage>b__8_1()
		{
			Plugin.instance.WarnIncompat.Value = false;
		}
	}

	private static string errorMessage = "";

	private static string warnMessage = "";

	public static bool IsNoticed { get; set; } = false;


	public static void Init(Harmony harmony)
	{
		CommonAPI.Init(harmony);
		DSPOptimizations.Init(harmony);
		Auxilaryfunction_Patch.Init(harmony);
		Multfunction_mod_Patch.Init(harmony);
		PlanetMiner.Init(harmony);
		Blackbox_Patch.Init(harmony);
		CheatEnabler_Patch.Init(harmony);
		if (!string.IsNullOrEmpty(errorMessage) || !string.IsNullOrEmpty(warnMessage))
		{
			harmony.PatchAll(typeof(Compatibility));
		}
	}

	public static void OnDestory()
	{
		CheatEnabler_Patch.OnDestory();
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")]
	private static void ShowMessage()
	{
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Expected O, but got Unknown
		if (IsNoticed || !Plugin.instance.WarnIncompat.Value)
		{
			return;
		}
		IsNoticed = true;
		if (!string.IsNullOrEmpty(errorMessage))
		{
			errorMessage = "The following compatible patches didn't success:\n模拟帧对以下mod的兼容性补丁失效:\n" + errorMessage;
			string text = errorMessage;
			string text2 = Localization.Translate("确定");
			object obj = <>c.<>9__8_0;
			if (obj == null)
			{
				Response val = delegate
				{
					Plugin.instance.WarnIncompat.Value = false;
				};
				<>c.<>9__8_0 = val;
				obj = (object)val;
			}
			UIMessageBox.Show("SampleAndHoldSim 模拟帧", text, text2, "Don't show", 3, (Response)null, (Response)obj);
		}
		if (string.IsNullOrEmpty(warnMessage))
		{
			return;
		}
		string text3 = warnMessage;
		string text4 = Localization.Translate("确定");
		object obj2 = <>c.<>9__8_1;
		if (obj2 == null)
		{
			Response val2 = delegate
			{
				Plugin.instance.WarnIncompat.Value = false;
			};
			<>c.<>9__8_1 = val2;
			obj2 = (object)val2;
		}
		UIMessageBox.Show("SampleAndHoldSim 模拟帧", text3, text4, "Don't show", 3, (Response)null, (Response)obj2);
	}
}
public static class MainManager
{
	public static int UpdatePeriod { get; set; } = 1;


	public static bool FocusLocalFactory { get; set; } = true;


	public static int StationStoreLowerbound { get; private set; } = -64;


	public static List<FactoryManager> Factories { get; } = new List<FactoryManager>();


	public static Dictionary<int, FactoryManager> Planets { get; } = new Dictionary<int, FactoryManager>();


	public static int FocusStarIndex { get; set; } = -1;


	public static int FocusPlanetId { get; private set; } = -1;


	public static int FocusFactoryIndex { get; private set; } = -1;


	public static void Init()
	{
		Factories.Clear();
		Planets.Clear();
		StationStoreLowerbound = UpdatePeriod * -64;
		Log.Debug("UpdatePeriod = " + UpdatePeriod + ", FocusLocalFactory = " + FocusLocalFactory + ", StoreLowerbound = " + StationStoreLowerbound);
	}

	public static int SetFactories(PlanetFactory[] workFactories, PlanetFactory[] idleFactories, long[] workFactoryTimes)
	{
		for (int i = Factories.Count; i < GameMain.data.factoryCount; i++)
		{
			FactoryManager factoryManager = new FactoryManager(i, GameMain.data.factories[i]);
			Factories.Add(factoryManager);
			Planets.Add(GameMain.data.factories[i].planetId, factoryManager);
		}
		int num = 0;
		int num2 = 0;
		int num3 = (int)GameMain.gameTick;
		PlanetFactory[] factories = GameMain.data.factories;
		PlanetData localPlanet = GameMain.localPlanet;
		int? obj;
		if (localPlanet == null)
		{
			obj = null;
		}
		else
		{
			PlanetFactory factory = localPlanet.factory;
			obj = ((factory != null) ? new int?(factory.index) : null);
		}
		int num4 = obj ?? (-1);
		for (int j = 0; j < GameMain.data.factoryCount; j++)
		{
			if (Factories[j].factory != factories[j])
			{
				Factories[j].factory = factories[j];
			}
			if (FocusLocalFactory && j == num4)
			{
				workFactories[num] = factories[j];
				workFactoryTimes[num] = num3;
				num++;
				Factories[j].IsActive = true;
				Factories[j].IsNextIdle = false;
			}
			else if ((j + num3) % UpdatePeriod == 0)
			{
				workFactories[num] = factories[j];
				workFactoryTimes[num] = num3 / UpdatePeriod;
				num++;
				Factories[j].IsActive = true;
				Factories[j].IsNextIdle = UpdatePeriod > 1;
			}
			else
			{
				idleFactories[num2++] = factories[j];
				Factories[j].IsActive = false;
				Factories[j].IsNextIdle = false;
			}
		}
		FocusFactoryIndex = ((FocusLocalFactory && UpdatePeriod > 1) ? num4 : (-1));
		FocusPlanetId = ((FocusLocalFactory && UpdatePeriod > 1 && GameMain.localPlanet != null) ? GameMain.localPlanet.id : (-1));
		FocusStarIndex = ((FocusLocalFactory && UpdatePeriod > 1 && GameMain.localStar != null) ? GameMain.localStar.index : (-1));
		return num;
	}

	public static bool TryGet(int index, out FactoryManager factoryData)
	{
		factoryData = null;
		if (0 <= index && index < Factories.Count)
		{
			factoryData = Factories[index];
			return true;
		}
		return false;
	}
}
[BepInPlugin("starfi5h.plugin.SampleAndHoldSim", "SampleAndHoldSim", "0.6.12")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	public const string GUID = "starfi5h.plugin.SampleAndHoldSim";

	public const string NAME = "SampleAndHoldSim";

	public const string VERSION = "0.6.12";

	public static Plugin instance;

	private Harmony harmony;

	public ConfigEntry<int> UpdatePeriod;

	public ConfigEntry<bool> FocusLocalFactory;

	public ConfigEntry<int> SliderMaxUpdatePeriod;

	public ConfigEntry<int> UIStationStoragePeriod;

	public ConfigEntry<bool> UnitPerMinute;

	public ConfigEntry<bool> WarnIncompat;

	public ConfigEntry<bool> EnableRelayLanding;

	public void LoadConfig()
	{
		UpdatePeriod = ((BaseUnityPlugin)this).Config.Bind<int>("General", "UpdatePeriod", 5, "Compute actual factory simulation every x ticks.\n更新周期: 每x逻辑帧运行一次实际计算");
		FocusLocalFactory = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "FocusLocalFactory", true, "Let local planet factory always active.使本地工厂保持每帧运行\n");
		SliderMaxUpdatePeriod = ((BaseUnityPlugin)this).Config.Bind<int>("UI", "SliderMaxUpdatePeriod", 10, "Max value of upate period slider\n更新周期滑动条的最大值");
		UIStationStoragePeriod = ((BaseUnityPlugin)this).Config.Bind<int>("UI", "UIStationStoragePeriod", 600, "Display item count change rate in station storages in x ticks. 0 = no display\n显示过去x帧内物流塔货物的流入或流出速率, 0 = 不显示");
		UnitPerMinute = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "UnitPerMinute", false, "If true, show rate in unit per minute. otherwise show rate in unit per second. \ntrue: 显示单位设为每分钟速率 false: 显示每秒速率");
		WarnIncompat = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "WarnIncompat", true, "Show warning for incompatible mods\n显示不兼容mod的警告");
		EnableRelayLanding = ((BaseUnityPlugin)this).Config.Bind<bool>("Combat", "EnableRelayLanding", true, "Allow Dark Fog relay to land on planet.\n允许黑雾中继器登陆星球");
		MainManager.UpdatePeriod = UpdatePeriod.Value;
		MainManager.FocusLocalFactory = FocusLocalFactory.Value;
		UIcontrol.SliderMax = SliderMaxUpdatePeriod.Value;
		UIstation.Period = (int)Math.Ceiling((float)UIStationStoragePeriod.Value / 10f);
		UIstation.UnitPerMinute = UnitPerMinute.Value;
		Log.Debug($"UpdatePeriod:{MainManager.UpdatePeriod} StationUI:{UIstation.Period * 10}");
	}

	public void SaveConfig(int updatePeriod, bool focusLocalFactory)
	{
		UpdatePeriod.Value = updatePeriod;
		FocusLocalFactory.Value = focusLocalFactory;
	}

	public void Awake()
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Expected O, but got Unknown
		instance = this;
		Log.Init(((BaseUnityPlugin)this).Logger);
		LoadConfig();
		GameData_Patch.GameMain_Begin();
		harmony = new Harmony("starfi5h.plugin.SampleAndHoldSim");
		harmony.PatchAll(typeof(GameData_Patch));
		harmony.PatchAll(typeof(ManagerLogic));
		harmony.PatchAll(typeof(UIcontrol));
		harmony.PatchAll(typeof(Dyson_Patch));
		harmony.PatchAll(typeof(Combat_Patch));
		harmony.PatchAll(typeof(Fix_Patch));
		if (UIstation.Period > 0)
		{
			harmony.PatchAll(typeof(UIstation));
		}
		Compatibility.Init(harmony);
	}

	public void OnDestroy()
	{
		Compatibility.OnDestory();
		harmony.UnpatchSelf();
		UIcontrol.OnDestory();
		UIstation.OnDestory();
	}
}
internal class ManagerLogic
{
	private static int threadCount = SystemInfo.processorCount;

	private static long totalHash = 0L;

	[HarmonyPostfix]
	[HarmonyPatch(typeof(MultithreadSystem), "Init")]
	[HarmonyPatch(typeof(MultithreadSystem), "ResetUsedThreadCnt")]
	internal static void Record_UsedThreadCnt(MultithreadSystem __instance)
	{
		threadCount = ((__instance.usedThreadCnt <= 0) ? 1 : __instance.usedThreadCnt);
		Log.Info($"ThreadCount: {threadCount}");
	}

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(ProductionStatistics), "PrepareTick")]
	private static IEnumerable<CodeInstruction> PrepareTick_Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Expected O, but got Unknown
		try
		{
			return new CodeMatcher(instructions, (ILGenerator)null).Start().InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2]
			{
				Transpilers.EmitDelegate<Action>((Action)delegate
				{
					Threading.ForEachParallel(PrepareTick, GameMain.data.factoryCount, threadCount);
				}),
				new CodeInstruction(OpCodes.Ret, (object)null)
			}).InstructionEnumeration();
		}
		catch
		{
			Log.Error("Transpiler ProductionStatistics.PrepareTick failed.");
			return instructions;
		}
	}

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(ProductionStatistics), "GameTick")]
	private static IEnumerable<CodeInstruction> GameTick_Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0002: 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_0037: Expected O, but got Unknown
		try
		{
			return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(FactoryProductionStat), "GameTick", (Type[])null, (Type[])null), (string)null)
			}).Advance(-5).SetOpcodeAndAdvance(OpCodes.Nop)
				.RemoveInstructions(5)
				.Start()
				.Insert((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate<Action>((Action)delegate
				{
					totalHash = 0L;
					Threading.ForEachParallel(GameTick, GameMain.data.factoryCount, threadCount);
					GameMain.data.history.AddTechHash(totalHash);
				}) })
				.InstructionEnumeration();
		}
		catch
		{
			Log.Error("Transpiler ProductionStatistics.GameTick failed.");
			return instructions;
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(StationComponent), "UpdateVeinCollection")]
	private static void UpdateVeinCollection_Prefix(StationComponent __instance, ref int __state)
	{
		__state = __instance.storage[0].count;
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(StationComponent), "UpdateVeinCollection")]
	private static void UpdateVeinCollection_Postfix(StationComponent __instance, int __state, PlanetFactory factory)
	{
		if (MainManager.TryGet(factory.index, out var factoryData) && factoryData.IsActive)
		{
			factoryData.SetMineral(__instance, __instance.storage[0].count - __state);
		}
	}

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(PlanetFactory), "GameTick")]
	private static IEnumerable<CodeInstruction> PlanetTransport_Transpiler1(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0002: 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_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
		try
		{
			return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(true, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Callvirt, (object)AccessTools.Method(typeof(PlanetTransport), "GameTick", (Type[])null, (Type[])null), (string)null)
			}).Advance(1).Insert((CodeInstruction[])(object)new CodeInstruction[2]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				Transpilers.EmitDelegate<Action<PlanetFactory>>((Action<PlanetFactory>)delegate(PlanetFactory factory)
				{
					if (MainManager.TryGet(factory.index, out var factoryData))
					{
						factoryData.StationAfterTransport();
					}
				})
			})
				.InstructionEnumeration();
		}
		catch
		{
			Log.Error("Transpiler PlanetTransport_Transpiler1 failed.");
			return instructions;
		}
	}

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(GameData), "GameTick")]
	private static IEnumerable<CodeInstruction> PlanetTransport_Transpiler2(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: 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_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Expected O, but got Unknown
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Expected O, but got Unknown
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Expected O, but got Unknown
		try
		{
			return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(true, (CodeMatch[])(object)new CodeMatch[5]
			{
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Callvirt && ((MethodInfo)i.operand).Name == "PrepareTransportData"), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Call && ((MethodInfo)i.operand).Name == "get_multithreadSystem"), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Callvirt && ((MethodInfo)i.operand).Name == "Schedule"), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Call && ((MethodInfo)i.operand).Name == "get_multithreadSystem"), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Callvirt && ((MethodInfo)i.operand).Name == "Complete"), (string)null)
			}).Advance(1).Insert((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate<Action>((Action)delegate
			{
				for (int j = 0; j < GameMain.data.factoryCount; j++)
				{
					if (MainManager.TryGet(j, out var factoryData))
					{
						factoryData.StationAfterTransport();
					}
				}
			}) })
				.InstructionEnumeration();
		}
		catch
		{
			Log.Error("PlanetTransport_Transpiler2 failed.");
			return instructions;
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(PowerSystem), "GameTick")]
	private static void PowerSystem_Gametick(PowerSystem __instance, ref long time)
	{
		if (MainManager.TryGet(__instance.factory.index, out var factoryData) && factoryData.IsNextIdle)
		{
			time /= MainManager.UpdatePeriod;
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(KillStatistics), "PrepareTick")]
	private static bool KillStatistics_PrepareTick()
	{
		int updatePeriod = MainManager.UpdatePeriod;
		if (updatePeriod <= 1)
		{
			return true;
		}
		return GameMain.gameTick % updatePeriod == 1;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(KillStatistics), "GameTick")]
	private static bool KillStatistics_GameTick(KillStatistics __instance, long time)
	{
		int updatePeriod = MainManager.UpdatePeriod;
		if (updatePeriod <= 1)
		{
			return true;
		}
		if (GameMain.gameTick % updatePeriod != 0L)
		{
			return false;
		}
		long num = time - updatePeriod;
		if (num < 0)
		{
			num = 0L;
		}
		for (int i = 0; i < __instance.starKillStatPool.Length; i++)
		{
			if (__instance.starKillStatPool[i] != null)
			{
				for (long num2 = num; num2 <= time; num2++)
				{
					__instance.starKillStatPool[i].GameTick(num2);
				}
			}
		}
		for (int j = 0; j < __instance.factoryKillStatPool.Length; j++)
		{
			if (__instance.factoryKillStatPool[j] != null)
			{
				for (long num3 = num; num3 <= time; num3++)
				{
					__instance.factoryKillStatPool[j].GameTick(num3);
				}
			}
		}
		if (__instance.mechaKillStat != null)
		{
			for (long num4 = num; num4 <= time; num4++)
			{
				__instance.mechaKillStat.GameTick(num4);
			}
		}
		return false;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(KillStatistics), "AfterTick")]
	private static bool KillStatistics_AfterTick()
	{
		return false;
	}

	private static void PrepareTick(int index)
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Invalid comparison between Unknown and I4
		FactoryProductionStat val = GameMain.data.statistics.production.factoryStatPool[index];
		MainManager.TryGet(index, out var factoryData);
		if (factoryData == null || factoryData.IsActive || (int)GameMain.data.factories[index].planet.type == 5)
		{
			val.PrepareTick();
			return;
		}
		val.itemChanged = false;
		val.consumeRegister[1210] = 0;
		val.consumeRegister[11901] = 0;
		val.productRegister[11901] = 0;
		val.productRegister[11902] = 0;
		val.productRegister[11903] = 0;
	}

	private static void GameTick(int index)
	{
		GameMain.data.statistics.production.factoryStatPool[index].GameTick(GameMain.gameTick);
		if (MainManager.TryGet(index, out var factoryData))
		{
			factoryData.StationAfterTick();
			if (factoryData.IsActive)
			{
				factoryData.DysonColletEnd();
			}
			else
			{
				Lab_IdleTick(index);
				factoryData.DysonIdleTick();
			}
			if ((!factoryData.IsActive || factoryData.IsNextIdle) && Compatibility.Blackbox_Patch.IsPatched)
			{
				Compatibility.Blackbox_Patch.Warper.RevertStats(index);
			}
		}
	}

	private static void Lab_IdleTick(int index)
	{
		long hashRegister = GameMain.data.statistics.production.factoryStatPool[index].hashRegister;
		if (hashRegister > 0 && GameMain.data.history.currentTech > 0)
		{
			Interlocked.Add(ref totalHash, hashRegister);
		}
	}
}
internal class UIstation
{
	public static bool UnitPerMinute = false;

	public static int ViewFactoryIndex = -1;

	public static int VeiwStationId = -1;

	private static Text[] changeRateText;

	private static int[,] periodArray;

	private static int[] sumArray;

	public static int Period = 60;

	public const int STEP = 10;

	private static int time;

	private static int cursor;

	private static int counter;

	[HarmonyPostfix]
	[HarmonyPatch(typeof(UIStationWindow), "_OnOpen")]
	public static void UIStationWindow_OnOpen(UIStationWindow __instance)
	{
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		SetVeiwStation(__instance.factory.index, __instance.stationId, __instance.storageUIs.Length);
		if (changeRateText == null || changeRateText.Length < __instance.storageUIs.Length)
		{
			changeRateText = (Text[])(object)new Text[__instance.storageUIs.Length];
			for (int i = 0; i < __instance.storageUIs.Length; i++)
			{
				GameObject gameObject = ((Component)__instance.storageUIs[i].countValueText).gameObject;
				GameObject val = Object.Instantiate<GameObject>(gameObject, gameObject.transform.parent);
				((Object)val).name = "SAHS-changeRate";
				val.transform.localPosition = new Vector3(150f, 8.5f, 0f);
				changeRateText[i] = val.GetComponent<Text>();
				changeRateText[i].alignment = (TextAnchor)3;
			}
		}
		for (int j = 0; j < changeRateText.Length; j++)
		{
			((Component)changeRateText[j]).gameObject.SetActive(false);
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(UIStationWindow), "_OnClose")]
	public static void UIStationWindow_OnClose()
	{
		SetVeiwStation(-1, -1, 0);
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(UIStationWindow), "_OnUpdate")]
	public static void UIStationWindow_OnUpdate(UIStationWindow __instance)
	{
		if (GameMain.gameTick % 10 != 0L)
		{
			return;
		}
		if (__instance.stationId != VeiwStationId)
		{
			UIStationWindow_OnOpen(__instance);
			return;
		}
		for (int i = 0; i < __instance.storageUIs.Length; i++)
		{
			if (__instance.storageUIs[i].station == null)
			{
				continue;
			}
			float storageChangeRate = GetStorageChangeRate(i);
			if (storageChangeRate != 0f)
			{
				changeRateText[i].text = GetRateString(storageChangeRate);
				if (!((Component)changeRateText[i]).gameObject.activeSelf)
				{
					((Component)changeRateText[i]).gameObject.SetActive(true);
				}
			}
			else if (((Component)changeRateText[i]).gameObject.activeSelf)
			{
				((Component)changeRateText[i]).gameObject.SetActive(false);
			}
		}
	}

	private static float GetStorageChangeRate(int storageIndex)
	{
		if (periodArray == null || storageIndex >= periodArray.Length || time < 1)
		{
			return 0f;
		}
		return (float)sumArray[storageIndex] * 60f / (float)time / 10f;
	}

	private static string GetRateString(float rate)
	{
		if (UnitPerMinute)
		{
			return $"{rate * 60f:+0.0;-0.0} /min";
		}
		return $"{rate:+0.00;-0.00} /s";
	}

	public static void OnDestory()
	{
		if (changeRateText != null)
		{
			Text[] array = changeRateText;
			for (int i = 0; i < array.Length; i++)
			{
				Object.Destroy((Object)(object)((Component)array[i]).gameObject);
			}
		}
	}

	public static void Record(StationData data)
	{
		if (sumArray.Length < data.tmpCount.Length)
		{
			Log.Warn($"UIstation.Record: length: {sumArray.Length} -> {data.tmpCount.Length}");
			periodArray = new int[Period + 1, data.tmpCount.Length];
			sumArray = new int[data.tmpCount.Length];
			cursor = 0;
			counter = 0;
		}
		for (int i = 0; i < data.tmpCount.Length; i++)
		{
			periodArray[Period, i] += data.tmpCount[i];
		}
		if (++counter >= 10)
		{
			for (int j = 0; j < data.tmpCount.Length; j++)
			{
				sumArray[j] += -periodArray[cursor, j] + periodArray[Period, j];
				periodArray[cursor, j] = periodArray[Period, j];
				periodArray[Period, j] = 0;
			}
			cursor = (cursor + 1) % Period;
			time = ((time < Period) ? (time + 1) : Period);
			counter = 0;
		}
	}

	public static void SetVeiwStation(int factoryId, int stationId, int length)
	{
		if (Period != 0 && (ViewFactoryIndex != factoryId || VeiwStationId != stationId))
		{
			ViewFactoryIndex = factoryId;
			VeiwStationId = stationId;
			if (length > 0)
			{
				periodArray = new int[Period + 1, length];
				sumArray = new int[length];
			}
			else
			{
				periodArray = null;
				sumArray = null;
			}
			time = 0;
			cursor = 0;
			counter = 0;
		}
	}
}
public class UItooltip : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
{
	public string Title;

	public string Text;

	private UIButtonTip tip;

	public void OnPointerEnter(PointerEventData eventData)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		tip = UIButtonTip.Create(true, Title, Text, 3, new Vector2(160f, 0f), 180, ((Component)this).gameObject.transform.parent, "", "");
	}

	public void OnPointerExit(PointerEventData eventData)
	{
		if ((Object)(object)tip != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)tip).gameObject);
		}
		tip = null;
	}

	public void OnDisable()
	{
		if ((Object)(object)tip != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)tip).gameObject);
		}
		tip = null;
	}

	public void OnDestory()
	{
		if ((Object)(object)tip != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)tip).gameObject);
		}
		tip = null;
	}
}
public class StationData
{
	public int[] tmpCount;

	private int[] tmpInc;

	private int tmpWarperCount;

	private int tmpMineralCount;

	public StationData(StationComponent station)
	{
		StationStore[] storage = station.storage;
		SetArray((storage != null) ? storage.Length : 0);
	}

	private void SetArray(int length)
	{
		tmpCount = new int[length];
		tmpInc = new int[length];
	}

	public static void SetMineral(StationData data, int mineralCount)
	{
		data.tmpMineralCount = mineralCount;
	}

	public static void ActiveBegin(StationData data, StationComponent station)
	{
		StationStore[] storage = station.storage;
		int num = ((storage != null) ? storage.Length : 0);
		if (num != data.tmpCount.Length)
		{
			data.SetArray(num);
		}
		for (int i = 0; i < num; i++)
		{
			data.tmpCount[i] = station.storage[i].count;
			data.tmpInc[i] = station.storage[i].inc;
		}
		data.tmpWarperCount = station.warperCount;
	}

	public static void ActiveEnd(StationData data, StationComponent station)
	{
		StationStore[] storage = station.storage;
		int num = ((storage != null) ? storage.Length : 0);
		if (num != data.tmpCount.Length)
		{
			data.SetArray(num);
		}
		for (int i = 0; i < num; i++)
		{
			data.tmpCount[i] = station.storage[i].count - data.tmpCount[i];
			data.tmpInc[i] = station.storage[i].inc - data.tmpInc[i];
		}
		data.tmpWarperCount = station.warperCount - data.tmpWarperCount;
	}

	public static void IdleEnd(StationData data, StationComponent station)
	{
		StationStore[] storage = station.storage;
		int num = ((storage != null) ? storage.Length : 0);
		if (num != data.tmpCount.Length)
		{
			data.SetArray(num);
		}
		for (int i = 0; i < num; i++)
		{
			station.storage[i].count += data.tmpCount[i];
			station.storage[i].inc += data.tmpInc[i];
			if (station.storage[i].count < MainManager.StationStoreLowerbound)
			{
				Log.Debug($"station{station.id} - store{i}: {station.storage[i].count}");
				station.storage[i].count = MainManager.StationStoreLowerbound;
			}
		}
		if (station.isVeinCollector && data.tmpMineralCount > 0)
		{
			station.storage[0].count += data.tmpMineralCount;
		}
		else
		{
			station.warperCount += data.tmpWarperCount;
		}
	}
}
public class Threading
{
	private static readonly ManualResetEvent completeEvent = new ManualResetEvent(initialState: false);

	public static void ForEachParallel(Action<int> work, int dataCount, int workerCount = -1)
	{
		if (workerCount < 0)
		{
			workerCount = Mathf.Max(2, Environment.ProcessorCount);
		}
		else if (workerCount == 0)
		{
			throw new ArgumentException("Need at least 1 worker", "workerCount");
		}
		int currentIndex = dataCount;
		completeEvent.Reset();
		int runningCount = workerCount;
		Exception exceptionThrown = null;
		for (int i = 0; i < workerCount - 1; i++)
		{
			ThreadPool.QueueUserWorkItem(DoWork);
		}
		DoWork(null);
		completeEvent.WaitOne();
		if (exceptionThrown != null)
		{
			throw new TargetInvocationException("An exception was thrown inside one of the threads", exceptionThrown);
		}
		void DoWork(object _)
		{
			try
			{
				while (exceptionThrown == null)
				{
					int num = Interlocked.Decrement(ref currentIndex);
					if (num < 0)
					{
						break;
					}
					work(num);
				}
			}
			catch (Exception ex)
			{
				exceptionThrown = ex;
			}
			finally
			{
				if (Interlocked.Decrement(ref runningCount) <= 0)
				{
					completeEvent.Set();
				}
			}
		}
	}
}
internal class UIcontrol
{
	public static int SliderMax = 10;

	private static bool initialized;

	private static GameObject group;

	private static Slider slider;

	private static InputField input;

	private static Text text_factory;

	private static Toggle toggle_local;

	private static bool eventLock;

	private static UItooltip tip1;

	private static UItooltip tip2;

	private static UItooltip tip3;

	[HarmonyPostfix]
	[HarmonyPatch(typeof(UIPerformancePanel), "_OnOpen")]
	public static void Init()
	{
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Expected O, but got Unknown
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_025e: Unknown result type (might be due to invalid IL or missing references)
		//IL_031a: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)group == (Object)null)
		{
			try
			{
				Slider slider = UIRoot.instance.uiGame.dysonEditor.controlPanel.inspector.layerInfo.slider0;
				InputField input = UIRoot.instance.uiGame.dysonEditor.controlPanel.inspector.layerInfo.input0;
				Text cpuValueText = UIRoot.instance.uiGame.statWindow.performancePanelUI.cpuValueText1;
				GameObject gameObject = ((Component)((Component)UIRoot.instance.optionWindow.fullscreenComp).transform.parent).gameObject;
				GameObject gameObject2 = ((Component)((Component)UIRoot.instance.uiGame.statWindow.performancePanelUI.cpuActiveButton).gameObject.transform.parent).gameObject;
				group = new GameObject("SAHS_Group");
				group.transform.SetParent(gameObject2.transform);
				group.transform.localPosition = new Vector3(200f, 105f);
				group.transform.localScale = Vector3.one;
				GameObject obj = Object.Instantiate<GameObject>(((Component)cpuValueText).gameObject, group.transform);
				((Object)obj).name = "text_factory";
				obj.transform.localPosition = new Vector3(-50f, 9f);
				text_factory = obj.GetComponent<Text>();
				text_factory.text = Localization.Translate("Ratio");
				GameObject obj2 = Object.Instantiate<GameObject>(((Component)input).gameObject, group.transform);
				((Object)obj2).name = "input_UpdatePeriod";
				obj2.transform.localPosition = new Vector3(155f, 1f);
				obj2.GetComponent<RectTransform>().sizeDelta = new Vector2(36f, 20f);
				UIcontrol.input = obj2.GetComponent<InputField>();
				UIcontrol.input.characterValidation = (CharacterValidation)1;
				UIcontrol.input.contentType = (ContentType)2;
				((UnityEvent<string>)(object)UIcontrol.input.onEndEdit).AddListener((UnityAction<string>)OnInputValueEnd);
				tip1 = obj2.AddComponent<UItooltip>();
				tip1.Title = Localization.Translate("Update Period");
				tip1.Text = Localization.Translate("Compute actual factory simulation every x ticks.");
				GameObject obj3 = Object.Instantiate<GameObject>(((Component)slider).gameObject, group.transform);
				((Object)obj3).name = "slider_UpdatePeriod";
				obj3.transform.localPosition = new Vector3(60f, -20f, -2f);
				UIcontrol.slider = obj3.GetComponent<Slider>();
				UIcontrol.slider.minValue = 1f;
				UIcontrol.slider.maxValue = SliderMax;
				UIcontrol.slider.wholeNumbers = true;
				((UnityEvent<float>)(object)UIcontrol.slider.onValueChanged).AddListener((UnityAction<float>)OnSliderChange);
				tip2 = obj3.AddComponent<UItooltip>();
				tip2.Title = Localization.Translate("Update Period");
				tip2.Text = Localization.Translate("Compute actual factory simulation every x ticks.");
				GameObject obj4 = Object.Instantiate<GameObject>(gameObject, group.transform);
				((Object)obj4).name = "checkbox_local";
				obj4.transform.localPosition = new Vector3(60f, -25f, 0f);
				Object.Destroy((Object)(object)obj4.GetComponent<Localizer>());
				Text component = obj4.GetComponent<Text>();
				component.font = text_factory.font;
				component.fontSize = 14;
				component.text = Localization.Translate("Focus local");
				tip3 = obj4.AddComponent<UItooltip>();
				tip3.Title = Localization.Translate("Focus on local factory");
				tip3.Text = Localization.Translate("Let local planet factory always active.");
				toggle_local = obj4.GetComponentInChildren<UIToggle>().toggle;
				((UnityEvent<bool>)(object)toggle_local.onValueChanged).AddListener((UnityAction<bool>)OnToggleChange);
				GameObject gameObject3 = ((Component)toggle_local).gameObject;
				gameObject3.transform.localPosition = new Vector3(70f, 0f);
				gameObject3.transform.localScale = new Vector3(0.75f, 0.75f);
				initialized = true;
				RefreshUI();
			}
			catch
			{
				Log.Error("UI component initial fail!");
			}
		}
	}

	public static void OnDestory()
	{
		Object.Destroy((Object)(object)group);
		tip1?.OnDestory();
		tip2?.OnDestory();
		tip3?.OnDestory();
		initialized = false;
	}

	public static void RefreshUI()
	{
		eventLock = true;
		if (initialized)
		{
			input.text = MainManager.UpdatePeriod.ToString();
			slider.value = MainManager.UpdatePeriod;
			toggle_local.isOn = MainManager.FocusLocalFactory;
		}
		eventLock = false;
	}

	public static void OnSliderChange(float val)
	{
		if (!eventLock)
		{
			val = Mathf.Round(val / 1f) * 1f;
			slider.value = val;
			MainManager.UpdatePeriod = (int)val;
			MainManager.Init();
			RefreshUI();
		}
	}

	public static void OnInputValueEnd(string val)
	{
		if (!eventLock)
		{
			if (int.TryParse(val, out var result) && result >= 1)
			{
				MainManager.UpdatePeriod = result;
				MainManager.Init();
			}
			RefreshUI();
		}
	}

	public static void OnToggleChange(bool val)
	{
		if (!eventLock)
		{
			MainManager.FocusLocalFactory = val;
			RefreshUI();
		}
	}
}
public static class Log
{
	private static ManualLogSource _logger;

	private static int count;

	public static void Init(ManualLogSource logger)
	{
		_logger = logger;
	}

	public static void Error(object obj)
	{
		_logger.LogError(obj);
	}

	public static void Warn(object obj)
	{
		_logger.LogWarning(obj);
	}

	public static void Info(object obj)
	{
		_logger.LogInfo(obj);
	}

	public static void Debug(object obj)
	{
		_logger.LogDebug(obj);
	}

	public static void Print(int period, object obj)
	{
		if (count++ % period == 0)
		{
			_logger.LogDebug(obj);
		}
	}

	public static void PrintInstruction(IEnumerable<CodeInstruction> instructions, int start, int end)
	{
		int num = -1;
		foreach (CodeInstruction instruction in instructions)
		{
			if (num++ > start)
			{
				if (num >= end)
				{
					break;
				}
				if (instruction.opcode == OpCodes.Call || instruction.opcode == OpCodes.Callvirt)
				{
					Warn($"{num,2} {instruction}");
				}
				else if (CodeInstructionExtensions.IsLdarg(instruction, (int?)null))
				{
					Info($"{num,2} {instruction}");
				}
				else
				{
					Debug($"{num,2} {instruction}");
				}
			}
		}
	}
}