Decompiled source of PackageLogistic v1.1.4

PackageLogistic.dll

Decompiled 8 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("PackageLogistic")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PackageLogistic")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("74d0030f-a1b3-492f-9096-cac58b128eec")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PackageLogistic;

internal struct TransportItemIndex
{
	public int planetIndex;

	public int transportIndex;

	public int storageIndex;

	public TransportItemIndex(int planetIndex, int transportIndex, int storageIndex)
	{
		this = default(TransportItemIndex);
		this.planetIndex = planetIndex;
		this.transportIndex = transportIndex;
		this.storageIndex = storageIndex;
	}
}
[BepInPlugin("com.qlvlp.dsp.PackageLogistic", "PackageLogistic", "1.1.4")]
public class PackageLogistic : BaseUnityPlugin
{
	public const string GUID = "com.qlvlp.dsp.PackageLogistic";

	public const string NAME = "PackageLogistic";

	public const string VERSION = "1.1.4";

	private ConfigEntry<bool> autoSpray;

	private ConfigEntry<bool> costProliferator;

	private ConfigEntry<bool> infVeins;

	private ConfigEntry<bool> infItems;

	private ConfigEntry<bool> infSand;

	private ConfigEntry<bool> infBuildings;

	private ConfigEntry<bool> useStorege;

	private ConfigEntry<KeyboardShortcut> hotKey;

	private ConfigEntry<bool> enableMod;

	private ConfigEntry<bool> autoReplenishPackage;

	private ConfigEntry<bool> autoReplenishTPPFuel;

	private HashSet<int> battleBaseStorgeIDs;

	private DeliveryPackage deliveryPackage;

	private Dictionary<int, int> deliveryPackageItems = new Dictionary<int, int>();

	private Dictionary<int, List<TransportItemIndex>> galacticTransportItems = new Dictionary<int, List<TransportItemIndex>>();

	private readonly List<(int, int)> proliferators = new List<(int, int)>();

	private readonly Dictionary<int, int> incPool = new Dictionary<int, int>
	{
		{ 1141, 0 },
		{ 1142, 0 },
		{ 1143, 0 }
	};

	private Dictionary<string, bool> taskState = new Dictionary<string, bool>();

	private int stackSize;

	private const float hydrogenThreshold = 0.6f;

	private bool showGUI;

	private Rect windowRect = new Rect(700f, 250f, 500f, 400f);

	private readonly Texture2D windowTexture = new Texture2D(10, 10);

	private int selectedPanel;

	private readonly Dictionary<int, string> fuelOptions = new Dictionary<int, string>();

	private ConfigEntry<int> fuelId;

	private int selectedFuelIndex;

	private ConfigEntry<bool> infFleet;

	private ConfigEntry<bool> infAmmo;

	private Dictionary<EAmmoType, List<int>> ammos = new Dictionary<EAmmoType, List<int>>();

	private void Start()
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0317: Unknown result type (might be due to invalid IL or missing references)
		hotKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("窗口快捷键", "Key", new KeyboardShortcut((KeyCode)108, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), (ConfigDescription)null);
		enableMod = ((BaseUnityPlugin)this).Config.Bind<bool>("配置", "EnableMod", true, "启用MOD");
		autoReplenishPackage = ((BaseUnityPlugin)this).Config.Bind<bool>("配置", "autoReplenishPackage", true, "自动补充背包中开启过滤的物品(鼠标中键点击格子即可开启过滤)");
		autoSpray = ((BaseUnityPlugin)this).Config.Bind<bool>("配置", "AutoSpray", true, "自动喷涂。自动对物流背包和星际运输站内的其它物品进行喷涂");
		costProliferator = ((BaseUnityPlugin)this).Config.Bind<bool>("配置", "CostProliferator", true, "消耗增产剂。自动喷涂时消耗背包或星际物流站里的增产剂");
		infItems = ((BaseUnityPlugin)this).Config.Bind<bool>("配置", "InfItems", false, "无限物品。物流背包和星际运输站内所有物品无限数量(无法获取成就)");
		infVeins = ((BaseUnityPlugin)this).Config.Bind<bool>("配置", "InfVeins", false, "无限矿物。物流背包和星际运输站内所有矿物无限数量");
		infBuildings = ((BaseUnityPlugin)this).Config.Bind<bool>("配置", "InfBuildings", false, "无限建筑。物流背包和星际运输站内所有建筑无限数量");
		infSand = ((BaseUnityPlugin)this).Config.Bind<bool>("配置", "InfSand", false, "无限沙土。沙土无限数量(固定为1G)");
		useStorege = ((BaseUnityPlugin)this).Config.Bind<bool>("配置", "useStorege", true, "从储物箱和储液罐回收物品");
		autoReplenishTPPFuel = ((BaseUnityPlugin)this).Config.Bind<bool>("配置", "autoReplenishTPPFuel", true, "自动为火力发电站补充燃料");
		fuelId = ((BaseUnityPlugin)this).Config.Bind<int>("配置", "fuelId", 0, "火力发电站燃料ID\n0:自动选择,精炼油和氢储量超60%时,谁多使用谁,否则使用煤,可防止原油裂解反应阻塞\n1006:煤, 1109:石墨, 1007:原油, 1114:精炼油, 1120:氢气, 1801:氢燃料棒, 1011:可燃冰\n5206:能量碎片, 1128:燃烧单元, 1030:木材, 1031:植物燃料");
		fuelOptions.Add(0, "自动");
		fuelOptions.Add(1006, "煤");
		fuelOptions.Add(1109, "石墨");
		fuelOptions.Add(1007, "原油");
		fuelOptions.Add(1114, "精炼油");
		fuelOptions.Add(1120, "氢气");
		fuelOptions.Add(1801, "氢燃料棒");
		fuelOptions.Add(1011, "可燃冰");
		fuelOptions.Add(5206, "能量碎片");
		fuelOptions.Add(1128, "燃烧单元");
		fuelOptions.Add(1030, "木材");
		fuelOptions.Add(1031, "植物燃料");
		selectedFuelIndex = fuelOptions.Keys.ToList().FindIndex((int id) => id == fuelId.Value);
		proliferators.Add((1143, 4));
		proliferators.Add((1142, 2));
		proliferators.Add((1141, 1));
		windowTexture.SetPixels(Enumerable.Repeat<Color>(new Color(0f, 0f, 0f, 1f), 100).ToArray());
		windowTexture.Apply();
		infAmmo = ((BaseUnityPlugin)this).Config.Bind<bool>("配置", "InfAmmo", false, "无限弹药。物流背包和星际运输站内弹药无限数量");
		infFleet = ((BaseUnityPlugin)this).Config.Bind<bool>("配置", "infFleet", false, "无限舰队。物流背包和星际运输站内无人机与战舰无限数量");
		ammos.Add((EAmmoType)1, new List<int> { 1603, 1602, 1601 });
		ammos.Add((EAmmoType)5, new List<int> { 1611, 1610, 1609 });
		ammos.Add((EAmmoType)3, new List<int> { 1606, 1605, 1604 });
		ammos.Add((EAmmoType)4, new List<int> { 1608, 1607 });
		ammos.Add((EAmmoType)6, new List<int> { 1613, 1612 });
		new Thread((ThreadStart)delegate
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PackageLogistic start!");
			while (true)
			{
				DateTime now = DateTime.Now;
				try
				{
					if ((Object)(object)GameMain.instance == (Object)null || GameMain.instance.isMenuDemo || GameMain.isPaused || !GameMain.isRunning || GameMain.data == null)
					{
						((BaseUnityPlugin)this).Logger.LogInfo((object)"Game is not running!");
					}
					else if (enableMod.Value)
					{
						if (infSand.Value && GameMain.mainPlayer.sandCount != 1000000000)
						{
							Traverse.Create((object)GameMain.mainPlayer).Property("sandCount", (object[])null).SetValue((object)1000000000);
						}
						deliveryPackage = GameMain.mainPlayer.deliveryPackage;
						CreateDeliveryPackageItemIndex();
						CreateTransportItemIndex();
						CheckTech();
						FindbattleBaseStorges();
						taskState["ProcessBattleBase"] = false;
						ThreadPool.QueueUserWorkItem(ProcessBattleBase, taskState);
						if (useStorege.Value)
						{
							taskState["ProcessStorage"] = false;
							ThreadPool.QueueUserWorkItem(ProcessStorage, taskState);
						}
						taskState["ProcessTransport"] = false;
						ThreadPool.QueueUserWorkItem(ProcessTransport, taskState);
						taskState["ProcessAssembler"] = false;
						ThreadPool.QueueUserWorkItem(ProcessAssembler, taskState);
						taskState["ProcessMiner"] = false;
						ThreadPool.QueueUserWorkItem(ProcessMiner, taskState);
						taskState["ProcessPowerGenerator"] = false;
						ThreadPool.QueueUserWorkItem(ProcessPowerGenerator, taskState);
						taskState["ProcessPowerExchanger"] = false;
						ThreadPool.QueueUserWorkItem(ProcessPowerExchanger, taskState);
						taskState["ProcessSilo"] = false;
						ThreadPool.QueueUserWorkItem(ProcessSilo, taskState);
						taskState["ProcessEjector"] = false;
						ThreadPool.QueueUserWorkItem(ProcessEjector, taskState);
						taskState["ProcessLab"] = false;
						ThreadPool.QueueUserWorkItem(ProcessLab, taskState);
						taskState["ProcessTurret"] = false;
						ThreadPool.QueueUserWorkItem(ProcessTurret, taskState);
						if (autoReplenishPackage.Value)
						{
							taskState["ProcessPackage"] = false;
							ThreadPool.QueueUserWorkItem(ProcessPackage, taskState);
						}
						List<string> list = new List<string>(taskState.Keys);
						string arg = "";
						while (true)
						{
							bool flag = true;
							DateTime now2 = DateTime.Now;
							for (int i = 0; i < list.Count; i++)
							{
								if (!taskState[list[i]])
								{
									arg = list[i];
									flag = false;
									break;
								}
							}
							if ((now2 - now).TotalMilliseconds >= 1000.0)
							{
								((BaseUnityPlugin)this).Logger.LogError((object)$"{arg} cost time >= 1000 ms");
								break;
							}
							if (flag)
							{
								break;
							}
							Thread.Sleep(5);
						}
					}
				}
				catch (Exception ex)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)"PackageLogistic exception!");
					((BaseUnityPlugin)this).Logger.LogError((object)ex.ToString());
				}
				finally
				{
					double totalMilliseconds = (DateTime.Now - now).TotalMilliseconds;
					((BaseUnityPlugin)this).Logger.LogDebug((object)$"loop cost:{totalMilliseconds}");
					if (totalMilliseconds < 50.0)
					{
						Thread.Sleep((int)(50.0 - totalMilliseconds));
					}
				}
			}
		}).Start();
	}

	private void Update()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		KeyboardShortcut value = hotKey.Value;
		if (((KeyboardShortcut)(ref value)).IsDown())
		{
			showGUI = !showGUI;
		}
	}

	private void OnGUI()
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Expected O, but got Unknown
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		if (showGUI)
		{
			GUI.DrawTexture(windowRect, (Texture)(object)windowTexture);
			windowRect = GUI.Window(0, windowRect, new WindowFunction(WindowFunction), string.Format("{0} {1}", "PackageLogistic", "1.1.4"));
		}
	}

	private void WindowFunction(int windowID)
	{
		string[] array = new string[3] { "主选项", "物品", "战斗" };
		selectedPanel = GUILayout.Toolbar(selectedPanel, array, Array.Empty<GUILayoutOption>());
		switch (selectedPanel)
		{
		case 0:
			MainPanel();
			break;
		case 1:
			ItemPanel();
			break;
		case 2:
			FightPanel();
			break;
		}
		GUI.DragWindow();
	}

	private void MainPanel()
	{
		GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
		GUILayout.Space(10f);
		GUILayout.Label("启用或停止MOD运行", Array.Empty<GUILayoutOption>());
		enableMod.Value = GUILayout.Toggle(enableMod.Value, "启用MOD", Array.Empty<GUILayoutOption>());
		GUILayout.Space(10f);
		GUILayout.Label("自动补充背包中开启过滤的物品", Array.Empty<GUILayoutOption>());
		autoReplenishPackage.Value = GUILayout.Toggle(autoReplenishPackage.Value, "自动补充", Array.Empty<GUILayoutOption>());
		GUILayout.Space(15f);
		GUILayout.Label("自动对物流背包和星际运输站内的其它物品进行喷涂", Array.Empty<GUILayoutOption>());
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		autoSpray.Value = GUILayout.Toggle(autoSpray.Value, "自动喷涂", Array.Empty<GUILayoutOption>());
		costProliferator.Value = GUILayout.Toggle(costProliferator.Value, "消耗增产剂", Array.Empty<GUILayoutOption>());
		GUILayout.EndHorizontal();
		GUILayout.Space(15f);
		useStorege.Value = GUILayout.Toggle(useStorege.Value, "从储物箱和储液罐回收物品", Array.Empty<GUILayoutOption>());
		GUILayout.Space(15f);
		autoReplenishTPPFuel.Value = GUILayout.Toggle(autoReplenishTPPFuel.Value, "自动为火力发电厂补充燃料", Array.Empty<GUILayoutOption>());
		if (autoReplenishTPPFuel.Value)
		{
			selectedFuelIndex = GUILayout.SelectionGrid(selectedFuelIndex, fuelOptions.Values.ToArray(), 4, GUI.skin.toggle, Array.Empty<GUILayoutOption>());
			fuelId.Value = fuelOptions.Keys.ToArray()[selectedFuelIndex];
		}
		GUILayout.Space(5f);
		GUILayout.EndVertical();
	}

	private void ItemPanel()
	{
		GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
		GUILayout.Space(10f);
		GUILayout.Label("物流背包和星际运输站内所有建筑无限数量", Array.Empty<GUILayoutOption>());
		infBuildings.Value = GUILayout.Toggle(infBuildings.Value, "无限建筑", Array.Empty<GUILayoutOption>());
		GUILayout.Space(15f);
		GUILayout.Label("物流背包和星际运输站内所有矿物无限数量", Array.Empty<GUILayoutOption>());
		infVeins.Value = GUILayout.Toggle(infVeins.Value, "无限矿物", Array.Empty<GUILayoutOption>());
		GUILayout.Space(15f);
		GUILayout.Label("物流背包和星际运输站内所有物品无限数量(无法获取成就)", Array.Empty<GUILayoutOption>());
		infItems.Value = GUILayout.Toggle(infItems.Value, "无限物品", Array.Empty<GUILayoutOption>());
		GUILayout.Space(15f);
		GUILayout.Label("沙土无限数量(固定为1G)", Array.Empty<GUILayoutOption>());
		infSand.Value = GUILayout.Toggle(infSand.Value, "无限沙土", Array.Empty<GUILayoutOption>());
		GUILayout.Space(5f);
		GUILayout.EndVertical();
	}

	private void FightPanel()
	{
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Expected O, but got Unknown
		GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
		GUILayout.Space(10f);
		GUILayout.Label("物流背包和星际运输站内所有弹药无限数量", Array.Empty<GUILayoutOption>());
		infAmmo.Value = GUILayout.Toggle(infAmmo.Value, "无限弹药", Array.Empty<GUILayoutOption>());
		GUILayout.Space(15f);
		GUILayout.Label("物流背包和星际运输站内无人机与战舰无限数量", Array.Empty<GUILayoutOption>());
		infFleet.Value = GUILayout.Toggle(infFleet.Value, "无限舰队", Array.Empty<GUILayoutOption>());
		GUILayout.Space(15f);
		if (GUILayout.Button(new GUIContent("清理战场分析基站", "设置不掉落的物品将被丢弃"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(150f) }))
		{
			ClearBattleBase();
		}
		GUILayout.Space(5f);
		GUILayout.EndVertical();
	}

	private void CheckTech()
	{
		((BaseUnityPlugin)this).Logger.LogDebug((object)"CheckTech");
		if (GameMain.history.TechUnlocked(2307) && deliveryPackage.colCount < 5)
		{
			deliveryPackage.colCount = 5;
			deliveryPackage.NotifySizeChange();
		}
		else if (GameMain.history.TechUnlocked(2304) && deliveryPackage.colCount < 4)
		{
			deliveryPackage.colCount = 4;
			deliveryPackage.NotifySizeChange();
		}
		else if ((!GameMain.history.TechUnlocked(1608) && deliveryPackage.colCount < 3) || !deliveryPackage.unlocked)
		{
			deliveryPackage.colCount = 3;
			if (!deliveryPackage.unlocked)
			{
				deliveryPackage.unlocked = true;
			}
			deliveryPackage.NotifySizeChange();
		}
		if (GameMain.history.TechUnlocked(2307))
		{
			stackSize = 5000;
			if (GameMain.mainPlayer.package.size < 160)
			{
				GameMain.mainPlayer.package.SetSize(160);
			}
		}
		else if (GameMain.history.TechUnlocked(2306))
		{
			stackSize = 4000;
			if (GameMain.mainPlayer.package.size < 150)
			{
				GameMain.mainPlayer.package.SetSize(150);
			}
		}
		else if (GameMain.history.TechUnlocked(2305))
		{
			stackSize = 3000;
			if (GameMain.mainPlayer.package.size < 140)
			{
				GameMain.mainPlayer.package.SetSize(140);
			}
		}
		else if (GameMain.history.TechUnlocked(2304))
		{
			stackSize = 2000;
			if (GameMain.mainPlayer.package.size < 130)
			{
				GameMain.mainPlayer.package.SetSize(130);
			}
		}
		else if (GameMain.history.TechUnlocked(2303))
		{
			stackSize = 1000;
			if (GameMain.mainPlayer.package.size < 120)
			{
				GameMain.mainPlayer.package.SetSize(120);
			}
		}
		else if (GameMain.history.TechUnlocked(2302))
		{
			stackSize = 500;
			if (GameMain.mainPlayer.package.size < 110)
			{
				GameMain.mainPlayer.package.SetSize(110);
			}
		}
		else if (GameMain.history.TechUnlocked(2301))
		{
			stackSize = 400;
			if (GameMain.mainPlayer.package.size < 100)
			{
				GameMain.mainPlayer.package.SetSize(100);
			}
		}
		else
		{
			stackSize = 300;
			if (GameMain.mainPlayer.package.size < 90)
			{
				GameMain.mainPlayer.package.SetSize(90);
			}
		}
		if (GameMain.history.TechUnlocked(3510))
		{
			GameMain.history.remoteStationExtraStorage = 40000;
		}
		else if (GameMain.history.TechUnlocked(3509))
		{
			GameMain.history.remoteStationExtraStorage = 15000;
		}
	}

	private void CreateDeliveryPackageItemIndex()
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogDebug((object)"CreateDeliveryPackageItemIndex");
		deliveryPackageItems = new Dictionary<int, int>();
		for (int i = 0; i < deliveryPackage.gridLength; i++)
		{
			GRID val = deliveryPackage.grids[i];
			int num = Math.Min(val.recycleCount, ((GRID)(ref val)).stackSizeModified);
			if (val.itemId <= 0)
			{
				continue;
			}
			if (!deliveryPackageItems.ContainsKey(val.itemId))
			{
				deliveryPackageItems.Add(val.itemId, i);
			}
			else
			{
				deliveryPackageItems[val.itemId] = i;
			}
			ItemProto val2 = ((ProtoSet<ItemProto>)(object)LDB.items).Select(val.itemId);
			if (!val2.CanBuild && stackSize > val2.StackSize)
			{
				deliveryPackage.grids[i].stackSize = stackSize;
			}
			if (infItems.Value)
			{
				deliveryPackage.grids[i].count = num;
			}
			else
			{
				if (infVeins.Value && IsVein(val.itemId))
				{
					if (val.itemId == 1120)
					{
						num = (int)((float)num * 0.6f);
					}
					deliveryPackage.grids[i].count = num;
				}
				if (infBuildings.Value && val2.CanBuild)
				{
					deliveryPackage.grids[i].count = num;
				}
				if (infAmmo.Value && val2.isAmmo)
				{
					deliveryPackage.grids[i].count = num;
				}
				if (infFleet.Value && val2.isFighter)
				{
					deliveryPackage.grids[i].count = num;
				}
			}
			SprayDeliveryPackageItem(i);
		}
	}

	private void CreateTransportItemIndex()
	{
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: 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_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0213: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0242: Unknown result type (might be due to invalid IL or missing references)
		//IL_0271: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogDebug((object)"CreateTransportItemIndex");
		galacticTransportItems = new Dictionary<int, List<TransportItemIndex>>();
		for (int num = GameMain.data.factories.Length - 1; num >= 0; num--)
		{
			PlanetFactory val = GameMain.data.factories[num];
			if (val != null)
			{
				for (int num2 = val.transport.stationPool.Length - 1; num2 >= 0; num2--)
				{
					StationComponent val2 = val.transport.stationPool[num2];
					if (val2 != null && val2.id > 0 && val2.isStellar && !val2.isCollector && !val2.isVeinCollector)
					{
						for (int num3 = val2.storage.Length - 1; num3 >= 0; num3--)
						{
							StationStore val3 = val2.storage[num3];
							if (val3.itemId > 0)
							{
								if (!galacticTransportItems.ContainsKey(val3.itemId))
								{
									galacticTransportItems[val3.itemId] = new List<TransportItemIndex>();
								}
								TransportItemIndex store = new TransportItemIndex(num, num2, num3);
								galacticTransportItems[val3.itemId].Add(new TransportItemIndex(num, num2, num3));
								ItemProto val4 = ((ProtoSet<ItemProto>)(object)LDB.items).Select(val3.itemId);
								if (val4.CanBuild)
								{
									val2.storage[num3].max = Math.Min(val4.StackSize * 10, val3.max);
								}
								if (infItems.Value)
								{
									val2.storage[num3].count = val3.max;
								}
								else
								{
									if (infVeins.Value && IsVein(val3.itemId))
									{
										if (val3.itemId == 1120)
										{
											val2.storage[num3].count = (int)((float)val3.max * 0.6f);
										}
										else
										{
											val2.storage[num3].count = val3.max;
										}
									}
									if (infBuildings.Value && val4.CanBuild)
									{
										val2.storage[num3].count = val3.max;
									}
									if (infAmmo.Value && val4.isAmmo)
									{
										val2.storage[num3].count = val3.max;
									}
									if (infFleet.Value && val4.isFighter)
									{
										val2.storage[num3].count = val3.max;
									}
								}
								SprayTransportItem(store);
							}
						}
					}
				}
			}
		}
	}

	private void FindbattleBaseStorges()
	{
		((BaseUnityPlugin)this).Logger.LogDebug((object)"FindbattleBaseStorges");
		battleBaseStorgeIDs = new HashSet<int>();
		for (int num = GameMain.data.factories.Length - 1; num >= 0; num--)
		{
			PlanetFactory val = GameMain.data.factories[num];
			if (val != null)
			{
				for (int num2 = val.defenseSystem.battleBases.buffer.Length - 1; num2 >= 0; num2--)
				{
					BattleBaseComponent val2 = val.defenseSystem.battleBases.buffer[num2];
					if (val2 != null)
					{
						battleBaseStorgeIDs.Add(val2.storageId);
					}
				}
			}
		}
	}

	private bool HasItem(int itemId)
	{
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		if (deliveryPackageItems.ContainsKey(itemId))
		{
			int num = deliveryPackageItems[itemId];
			if (deliveryPackage.grids[num].count > 0)
			{
				return true;
			}
		}
		else if (galacticTransportItems.ContainsKey(itemId))
		{
			foreach (TransportItemIndex item in galacticTransportItems[itemId])
			{
				if (GameMain.data.factories[item.planetIndex].transport.stationPool[item.transportIndex].storage[item.storageIndex].count > 0)
				{
					return true;
				}
			}
		}
		return false;
	}

	private bool IsVein(int itemId)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		if (new int[4] { 1000, 1116, 1120, 1121 }.Contains(itemId) || (int)LDB.veins.GetVeinTypeByItemId(itemId) != 0)
		{
			return true;
		}
		return false;
	}

	private void SprayDeliveryPackageItem(int index)
	{
		//IL_001a: 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_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: 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_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		if (!autoSpray.Value)
		{
			return;
		}
		GRID val = deliveryPackage.grids[index];
		if (val.itemId <= 0 || val.count <= 0)
		{
			return;
		}
		if (val.itemId == 1141 || val.itemId == 1142 || val.itemId == 1143)
		{
			deliveryPackage.grids[index].inc = deliveryPackage.grids[index].count * 4;
			return;
		}
		ItemProto val2 = ((ProtoSet<ItemProto>)(object)LDB.items).Select(val.itemId);
		if (val2.CanBuild || val2.isFighter)
		{
			return;
		}
		if (!costProliferator.Value && val.inc < val.count * 4)
		{
			deliveryPackage.grids[index].inc = val.count * 4;
			return;
		}
		foreach (var proliferator in proliferators)
		{
			int num = val.count * proliferator.Item2 - val.inc;
			if (num <= 0)
			{
				break;
			}
			int inc = GetInc(proliferator.Item1, num);
			if (inc > 0)
			{
				deliveryPackage.grids[index].inc += inc;
			}
		}
	}

	private void SprayTransportItem(TransportItemIndex store)
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: 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)
		if (!autoSpray.Value)
		{
			return;
		}
		StationComponent val = GameMain.data.factories[store.planetIndex].transport.stationPool[store.transportIndex];
		StationStore val2 = val.storage[store.storageIndex];
		if (val2.itemId <= 0 || val2.count <= 0)
		{
			return;
		}
		if (val2.itemId == 1141 || val2.itemId == 1142 || val2.itemId == 1143)
		{
			val.storage[store.storageIndex].inc = val2.count * 4;
			return;
		}
		ItemProto val3 = ((ProtoSet<ItemProto>)(object)LDB.items).Select(val2.itemId);
		if (val3.CanBuild || val3.isFighter)
		{
			return;
		}
		if (!costProliferator.Value && val2.inc < val2.count * 4)
		{
			val.storage[store.storageIndex].inc = val2.count * 4;
			return;
		}
		foreach (var proliferator in proliferators)
		{
			int num = val2.count * proliferator.Item2 - val2.inc;
			if (num <= 0)
			{
				break;
			}
			int inc = GetInc(proliferator.Item1, num);
			if (inc > 0)
			{
				val.storage[store.storageIndex].inc += inc;
			}
		}
	}

	private int GetInc(int proliferatorId, int count)
	{
		int num = 0;
		int num2;
		switch (proliferatorId)
		{
		case 1143:
			num2 = 75;
			break;
		case 1142:
			num2 = 30;
			break;
		case 1141:
			num2 = 15;
			break;
		default:
			return 0;
		}
		if (count <= 0)
		{
			return 0;
		}
		while (true)
		{
			if (incPool[proliferatorId] >= count)
			{
				incPool[proliferatorId] -= count;
				return num + count;
			}
			num += incPool[proliferatorId];
			count -= incPool[proliferatorId];
			incPool[proliferatorId] = 0;
			int[] array = TakeItem(proliferatorId, 600 / num2);
			if (array[0] == 0)
			{
				break;
			}
			incPool[proliferatorId] = array[0] * num2;
		}
		return num;
	}

	private void ProcessTransport(object state)
	{
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Invalid comparison between Unknown and I4
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Invalid comparison between Unknown and I4
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: 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_0139: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogDebug((object)"ProcessTransport");
		try
		{
			for (int num = GameMain.data.factories.Length - 1; num >= 0; num--)
			{
				PlanetFactory val = GameMain.data.factories[num];
				if (val != null)
				{
					StationComponent[] stationPool = val.transport.stationPool;
					foreach (StationComponent val2 in stationPool)
					{
						if (val2 == null || val2.id <= 0 || val2.isStellar || val2.isCollector || val2.isVeinCollector)
						{
							continue;
						}
						for (int num2 = val2.storage.Length - 1; num2 >= 0; num2--)
						{
							StationStore val3 = val2.storage[num2];
							if (val3.itemId > 0)
							{
								if ((int)val3.localLogic == 1 && val3.count > 0)
								{
									int[] array = AddItem(val3.itemId, val3.count, val3.inc, assembler: false);
									val2.storage[num2].count -= array[0];
									val2.storage[num2].inc -= array[1];
								}
								else if ((int)val3.localLogic == 2)
								{
									int num3 = val3.max - val3.localOrder - val3.remoteOrder - val3.count;
									if (num3 > 0)
									{
										int[] array2 = TakeItem(val3.itemId, num3);
										val2.storage[num2].count += array2[0];
										val2.storage[num2].inc += array2[1];
									}
								}
							}
						}
					}
				}
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)ex);
		}
		finally
		{
			taskState["ProcessTransport"] = true;
		}
	}

	private void ProcessStorage(object state)
	{
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: 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_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogDebug((object)"ProcessStorage");
		try
		{
			for (int num = GameMain.data.factories.Length - 1; num >= 0; num--)
			{
				PlanetFactory val = GameMain.data.factories[num];
				if (val != null)
				{
					StorageComponent[] storagePool = val.factoryStorage.storagePool;
					foreach (StorageComponent val2 in storagePool)
					{
						if (val2 == null || val2.isEmpty || battleBaseStorgeIDs.Contains(val2.id))
						{
							continue;
						}
						for (int num2 = val2.grids.Length - 1; num2 >= 0; num2--)
						{
							GRID val3 = val2.grids[num2];
							if (val3.itemId > 0 && val3.count > 0)
							{
								int[] array = AddItem(val3.itemId, val3.count, val3.inc, assembler: false);
								if (array[0] != 0)
								{
									val2.grids[num2].count -= array[0];
									val2.grids[num2].inc -= array[1];
									if (val2.grids[num2].count <= 0)
									{
										val2.grids[num2].itemId = val2.grids[num2].filter;
									}
								}
							}
						}
						val2.NotifyStorageChange();
					}
					for (int num3 = val.factoryStorage.tankPool.Length - 1; num3 >= 0; num3--)
					{
						TankComponent val4 = val.factoryStorage.tankPool[num3];
						if (val4.id != 0 && val4.fluidId != 0 && val4.fluidCount != 0)
						{
							int[] array2 = AddItem(val4.fluidId, val4.fluidCount, val4.fluidInc, assembler: false);
							val.factoryStorage.tankPool[num3].fluidCount -= array2[0];
							val.factoryStorage.tankPool[num3].fluidInc -= array2[1];
							if (val.factoryStorage.tankPool[num3].fluidCount <= 0)
							{
								val.factoryStorage.tankPool[num3].fluidId = 0;
								val.factoryStorage.tankPool[num3].fluidInc = 0;
							}
						}
					}
				}
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)ex);
		}
		finally
		{
			taskState["ProcessStorage"] = true;
		}
	}

	private void ProcessAssembler(object state)
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogDebug((object)"ProcessAssembler");
		try
		{
			for (int num = GameMain.data.factories.Length - 1; num >= 0; num--)
			{
				PlanetFactory val = GameMain.data.factories[num];
				if (val != null)
				{
					AssemblerComponent[] assemblerPool = val.factorySystem.assemblerPool;
					foreach (AssemblerComponent val2 in assemblerPool)
					{
						if (val2.id <= 0 || val2.recipeId <= 0)
						{
							continue;
						}
						for (int num2 = val2.products.Length - 1; num2 >= 0; num2--)
						{
							if (val2.produced[num2] > 0)
							{
								val2.produced[num2] -= AddItem(val2.products[num2], val2.produced[num2], 0)[0];
							}
						}
						for (int num3 = val2.requires.Length - 1; num3 >= 0; num3--)
						{
							int num4 = Math.Max(val2.requireCounts[num3] * 5 - val2.served[num3], 0);
							if (num4 > 0)
							{
								int[] array = TakeItem(val2.requires[num3], num4);
								val2.served[num3] += array[0];
								val2.incServed[num3] += array[1];
							}
						}
					}
				}
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)ex);
		}
		finally
		{
			taskState["ProcessAssembler"] = true;
		}
	}

	private void ProcessMiner(object state)
	{
		//IL_0055: 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_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Invalid comparison between Unknown and I4
		//IL_010f: 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_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: 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_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: 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_0132: Invalid comparison between Unknown and I4
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogDebug((object)"ProcessMiner");
		try
		{
			for (int num = GameMain.data.factories.Length - 1; num >= 0; num--)
			{
				PlanetFactory val = GameMain.data.factories[num];
				if (val != null)
				{
					for (int num2 = val.factorySystem.minerPool.Length - 1; num2 >= 0; num2--)
					{
						MinerComponent val2 = val.factorySystem.minerPool[num2];
						if (val2.id > 0 && val2.productId > 0 && val2.productCount > 0)
						{
							int[] array = AddItem(val2.productId, val2.productCount, 0, assembler: false);
							val.factorySystem.minerPool[num2].productCount -= array[0];
						}
					}
					StationComponent[] stationPool = val.transport.stationPool;
					foreach (StationComponent val3 in stationPool)
					{
						if (val3 == null || val3.id <= 0)
						{
							continue;
						}
						if (val3.isStellar && val3.isCollector)
						{
							for (int num3 = val3.storage.Length - 1; num3 >= 0; num3--)
							{
								StationStore val4 = val3.storage[num3];
								if (val4.itemId > 0 && val4.count > 0 && (int)val4.remoteLogic == 1)
								{
									int[] array2 = AddItem(val4.itemId, val4.count, 0, assembler: false);
									val3.storage[num3].count -= array2[0];
								}
							}
						}
						else if (val3.isVeinCollector)
						{
							StationStore val5 = val3.storage[0];
							if (val5.itemId > 0 && val5.count > 0 && (int)val5.localLogic == 1)
							{
								int[] array3 = AddItem(val5.itemId, val5.count, 0, assembler: false);
								val3.storage[0].count -= array3[0];
							}
						}
					}
				}
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)ex);
		}
		taskState["ProcessMiner"] = true;
	}

	private int ThermalPowerPlantFuel()
	{
		//IL_008f: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: 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_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_020e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0213: Unknown result type (might be due to invalid IL or missing references)
		//IL_0215: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Unknown result type (might be due to invalid IL or missing references)
		//IL_0230: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogDebug((object)"thermalPowerPlantFuel");
		if (fuelId.Value != 0 && HasItem(fuelId.Value))
		{
			return fuelId.Value;
		}
		float num = 0f;
		float num2 = 0f;
		float num3 = 1f;
		float num4 = 1f;
		float num5 = 0f;
		float num6 = 0f;
		if (deliveryPackageItems.ContainsKey(1114))
		{
			GRID val = deliveryPackage.grids[deliveryPackageItems[1114]];
			num3 += (float)((GRID)(ref val)).stackSizeModified;
			num5 += (float)val.count;
		}
		if (galacticTransportItems.ContainsKey(1114))
		{
			foreach (TransportItemIndex item in galacticTransportItems[1114])
			{
				StationStore val2 = GameMain.data.factories[item.planetIndex].transport.stationPool[item.transportIndex].storage[item.storageIndex];
				if (val2.itemId == 1114)
				{
					num3 += (float)val2.max;
					num5 += (float)val2.count;
				}
			}
		}
		if (deliveryPackageItems.ContainsKey(1120))
		{
			GRID val3 = deliveryPackage.grids[deliveryPackageItems[1120]];
			num4 += (float)((GRID)(ref val3)).stackSizeModified;
			num6 += (float)val3.count;
		}
		if (galacticTransportItems.ContainsKey(1120))
		{
			foreach (TransportItemIndex item2 in galacticTransportItems[1120])
			{
				StationStore val4 = GameMain.data.factories[item2.planetIndex].transport.stationPool[item2.transportIndex].storage[item2.storageIndex];
				if (val4.itemId == 1120)
				{
					num4 += (float)val4.max;
					num6 += (float)val4.count;
				}
			}
		}
		num = num5 / num3;
		num2 = num6 / num4;
		if (num >= num2 && (double)num > 0.6)
		{
			return 1114;
		}
		if (num2 >= num && (double)num2 > 0.6)
		{
			return 1120;
		}
		return 1006;
	}

	private void ProcessPowerGenerator(object state)
	{
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_020d: Unknown result type (might be due to invalid IL or missing references)
		//IL_021a: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogDebug((object)"ProcessPowerGenerator");
		try
		{
			for (int num = GameMain.data.factories.Length - 1; num >= 0; num--)
			{
				PlanetFactory val = GameMain.data.factories[num];
				if (val != null)
				{
					for (int num2 = val.powerSystem.genPool.Length - 1; num2 >= 0; num2--)
					{
						PowerGeneratorComponent val2 = val.powerSystem.genPool[num2];
						if (val2.id > 0)
						{
							if (val2.gamma)
							{
								if (val2.catalystPoint + val2.catalystIncPoint < 3600)
								{
									int[] array = TakeItem(1209, 3);
									if (array[0] > 0)
									{
										val.powerSystem.genPool[num2].catalystId = 1209;
										val.powerSystem.genPool[num2].catalystPoint += array[0] * 3600;
										val.powerSystem.genPool[num2].catalystIncPoint += array[1] * 3600;
									}
								}
								if (val2.productId > 0 && val2.productCount >= 1f)
								{
									int[] array2 = AddItem(val2.productId, (int)val2.productCount, 0);
									val.powerSystem.genPool[num2].productCount -= array2[0];
								}
							}
							else
							{
								int num3 = 0;
								switch (val2.fuelMask)
								{
								case 1:
									if (autoReplenishTPPFuel.Value)
									{
										num3 = ThermalPowerPlantFuel();
									}
									break;
								case 2:
									num3 = 1802;
									break;
								case 4:
									num3 = ((!HasItem(1804)) ? 1803 : 1804);
									break;
								}
								if (num3 != 0)
								{
									if (num3 != val2.fuelId && val2.fuelCount == 0)
									{
										int[] array3 = TakeItem(num3, 5);
										((PowerGeneratorComponent)(ref val.powerSystem.genPool[num2])).SetNewFuel(num3, (short)array3[0], (short)array3[1]);
									}
									else if (num3 == val2.fuelId && val2.fuelCount < 5)
									{
										int[] array4 = TakeItem(num3, 5 - val2.fuelCount);
										val.powerSystem.genPool[num2].fuelCount += (short)array4[0];
										val.powerSystem.genPool[num2].fuelInc += (short)array4[1];
									}
								}
							}
						}
					}
				}
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)ex);
		}
		finally
		{
			taskState["ProcessPowerGenerator"] = true;
		}
	}

	private void ProcessPowerExchanger(object state)
	{
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: 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_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: 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_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: 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_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogDebug((object)"ProcessPowerExchanger");
		try
		{
			for (int num = GameMain.data.factories.Length - 1; num >= 0; num--)
			{
				PlanetFactory val = GameMain.data.factories[num];
				if (val != null)
				{
					for (int num2 = val.powerSystem.excPool.Length - 1; num2 >= 0; num2--)
					{
						PowerExchangerComponent val2 = val.powerSystem.excPool[num2];
						if (val2.targetState == -1f)
						{
							if (val2.fullCount < 3)
							{
								int[] array = TakeItem(val2.fullId, 3 - val2.fullCount);
								val.powerSystem.excPool[num2].fullCount += (short)array[0];
							}
							if (val2.emptyCount > 0)
							{
								int[] array2 = AddItem(val2.emptyId, val2.emptyCount, 0);
								val.powerSystem.excPool[num2].emptyCount -= (short)array2[0];
							}
						}
						else if (val2.targetState == 1f)
						{
							if (val2.emptyCount < 5)
							{
								int[] array3 = TakeItem(val2.emptyId, 5 - val2.emptyCount);
								val.powerSystem.excPool[num2].emptyCount += (short)array3[0];
							}
							if (val2.fullCount > 0)
							{
								int[] array4 = AddItem(val2.fullId, val2.fullCount, 0);
								val.powerSystem.excPool[num2].fullCount -= (short)array4[0];
							}
						}
					}
				}
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)ex);
		}
		finally
		{
			taskState["ProcessPowerExchanger"] = true;
		}
	}

	private void ProcessSilo(object state)
	{
		//IL_0055: 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_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogDebug((object)"ProcessSilo");
		try
		{
			for (int num = GameMain.data.factories.Length - 1; num >= 0; num--)
			{
				PlanetFactory val = GameMain.data.factories[num];
				if (val != null)
				{
					for (int num2 = val.factorySystem.siloPool.Length - 1; num2 >= 0; num2--)
					{
						SiloComponent val2 = val.factorySystem.siloPool[num2];
						if (val2.id > 0 && val2.bulletCount <= 3)
						{
							int[] array = TakeItem(val2.bulletId, 10);
							val.factorySystem.siloPool[num2].bulletCount += array[0];
							val.factorySystem.siloPool[num2].bulletInc += array[1];
						}
					}
				}
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)ex);
		}
		finally
		{
			taskState["ProcessSilo"] = true;
		}
	}

	private void ProcessEjector(object state)
	{
		//IL_0055: 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_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogDebug((object)"ProcessEjector");
		try
		{
			for (int num = GameMain.data.factories.Length - 1; num >= 0; num--)
			{
				PlanetFactory val = GameMain.data.factories[num];
				if (val != null)
				{
					for (int num2 = val.factorySystem.ejectorPool.Length - 1; num2 >= 0; num2--)
					{
						EjectorComponent val2 = val.factorySystem.ejectorPool[num2];
						if (val2.id > 0 && val2.bulletCount <= 5)
						{
							int[] array = TakeItem(val2.bulletId, 15);
							val.factorySystem.ejectorPool[num2].bulletCount += array[0];
							val.factorySystem.ejectorPool[num2].bulletInc += array[1];
						}
					}
				}
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)ex);
		}
		finally
		{
			taskState["ProcessEjector"] = true;
		}
	}

	private void ProcessLab(object state)
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: 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_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: 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_00e3: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogDebug((object)"ProcessLab");
		try
		{
			for (int num = GameMain.data.factories.Length - 1; num >= 0; num--)
			{
				PlanetFactory val = GameMain.data.factories[num];
				if (val != null)
				{
					LabComponent[] labPool = val.factorySystem.labPool;
					foreach (LabComponent val2 in labPool)
					{
						if (val2.id <= 0)
						{
							continue;
						}
						if (val2.recipeId > 0)
						{
							for (int num2 = val2.products.Length - 1; num2 >= 0; num2--)
							{
								if (val2.produced[num2] > 0)
								{
									int[] array = AddItem(val2.products[num2], val2.produced[num2], 0);
									val2.produced[num2] -= array[0];
								}
							}
							for (int num3 = val2.requires.Length - 1; num3 >= 0; num3--)
							{
								int count = val2.requireCounts[num3] * 3 - val2.served[num3] - val2.incServed[num3];
								int[] array2 = TakeItem(val2.requires[num3], count);
								val2.served[num3] += array2[0];
								val2.incServed[num3] += array2[1];
							}
						}
						else
						{
							if (!val2.researchMode)
							{
								continue;
							}
							for (int num4 = val2.matrixPoints.Length - 1; num4 >= 0; num4--)
							{
								if (val2.matrixPoints[num4] > 0 && val2.matrixServed[num4] < val2.matrixPoints[num4] * 3600)
								{
									int[] array3 = TakeItem(LabComponent.matrixIds[num4], val2.matrixPoints[num4]);
									val2.matrixServed[num4] += array3[0] * 3600;
									val2.matrixIncServed[num4] += array3[1] * 3600;
								}
							}
						}
					}
				}
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)ex);
		}
		finally
		{
			taskState["ProcessLab"] = true;
		}
	}

	private void ProcessTurret(object state)
	{
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: 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_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Invalid comparison between Unknown and I4
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogDebug((object)"ProcessTurret");
		try
		{
			for (int num = GameMain.data.factories.Length - 1; num >= 0; num--)
			{
				PlanetFactory val = GameMain.data.factories[num];
				if (val != null)
				{
					for (int num2 = val.defenseSystem.turrets.buffer.Length - 1; num2 >= 0; num2--)
					{
						TurretComponent val2 = val.defenseSystem.turrets.buffer[num2];
						if (val2.id != 0 && (int)val2.type != 2 && (int)val2.ammoType != 0 && val2.itemCount <= 0 && val2.bulletCount <= 0)
						{
							foreach (int item in ammos[val2.ammoType])
							{
								int[] array = TakeItem(item, 50 - val2.itemCount);
								if (array[0] != 0)
								{
									((TurretComponent)(ref val.defenseSystem.turrets.buffer[num2])).SetNewItem(item, (short)array[0], (short)array[1]);
									break;
								}
							}
						}
					}
				}
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)ex);
		}
		finally
		{
			taskState["ProcessTurret"] = true;
		}
	}

	private void ProcessBattleBase(object state)
	{
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_020e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0210: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_0220: Unknown result type (might be due to invalid IL or missing references)
		//IL_0229: Unknown result type (might be due to invalid IL or missing references)
		//IL_0230: Unknown result type (might be due to invalid IL or missing references)
		//IL_023a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0241: Unknown result type (might be due to invalid IL or missing references)
		//IL_0248: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogDebug((object)"ProcessBattleBase");
		try
		{
			_ = new int[3] { 5103, 5102, 5101 };
			for (int num = GameMain.data.factories.Length - 1; num >= 0; num--)
			{
				PlanetFactory val = GameMain.data.factories[num];
				if (val != null)
				{
					for (int num2 = val.defenseSystem.battleBases.buffer.Length - 1; num2 >= 0; num2--)
					{
						BattleBaseComponent val2 = val.defenseSystem.battleBases.buffer[num2];
						if (val2 != null && val2.combatModule != null)
						{
							ModuleFleet val3 = val2.combatModule.moduleFleets[0];
							for (int num3 = val3.fighters.Length - 1; num3 >= 0; num3--)
							{
								ModuleFighter val4 = val3.fighters[num3];
								if (val4.count == 0 && TakeItem(val4.itemId, 1)[0] != 0)
								{
									((ModuleFleet)(ref val3)).AddFighterToPort(num3, val4.itemId);
									break;
								}
							}
							StorageComponent storage = val2.storage;
							bool flag = false;
							for (int num4 = storage.grids.Length - 1 - storage.bans; num4 >= 0; num4--)
							{
								GRID val5 = storage.grids[num4];
								if (val5.itemId > 0 && val5.count > 0)
								{
									int[] array = AddItem(val5.itemId, val5.count, val5.inc, assembler: false);
									if (array[0] != 0)
									{
										flag = true;
										storage.grids[num4].count -= array[0];
										storage.grids[num4].inc -= array[1];
										if (storage.grids[num4].count <= 0)
										{
											storage.grids[num4].itemId = storage.grids[num4].filter;
										}
									}
								}
							}
							for (int i = storage.grids.Length - storage.bans; i < storage.grids.Length; i++)
							{
								GRID val6 = storage.grids[i];
								if (val6.filter != 0 && val6.filter == val6.itemId && val6.count < val6.stackSize)
								{
									int[] array2 = TakeItem(val6.itemId, val6.stackSize - val6.count);
									if (array2[0] != 0)
									{
										flag = true;
										storage.grids[i].count += array2[0];
										storage.grids[i].inc += array2[1];
									}
								}
							}
							if (flag)
							{
								storage.NotifyStorageChange();
							}
						}
					}
				}
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)ex);
		}
		taskState["ProcessBattleBase"] = true;
	}

	private void ClearBattleBase()
	{
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogDebug((object)"ClearBattleBase");
		try
		{
			HashSet<int> enemyDropBans = GameMain.data.trashSystem.enemyDropBans;
			for (int num = GameMain.data.factories.Length - 1; num >= 0; num--)
			{
				PlanetFactory val = GameMain.data.factories[num];
				if (val != null)
				{
					for (int num2 = val.defenseSystem.battleBases.buffer.Length - 1; num2 >= 0; num2--)
					{
						BattleBaseComponent val2 = val.defenseSystem.battleBases.buffer[num2];
						if (val2 != null && val2.storage != null)
						{
							StorageComponent storage = val2.storage;
							if (!storage.isEmpty)
							{
								for (int num3 = storage.grids.Length - 1; num3 >= 0; num3--)
								{
									GRID val3 = storage.grids[num3];
									if (enemyDropBans.Contains(val3.itemId))
									{
										storage.grids[num3].count = 0;
										storage.grids[num3].inc = 0;
										storage.grids[num3].itemId = storage.grids[num3].filter;
									}
								}
								storage.NotifyStorageChange();
							}
						}
					}
				}
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)ex);
		}
	}

	private void ProcessPackage(object state)
	{
		//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_0037: 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_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogDebug((object)"ProcessPackage");
		try
		{
			bool flag = false;
			StorageComponent package = GameMain.mainPlayer.package;
			for (int num = package.grids.Length - 1; num >= 0; num--)
			{
				GRID val = package.grids[num];
				if (val.filter != 0 && val.count < val.stackSize)
				{
					int[] array = TakeItem(val.itemId, val.stackSize - val.count);
					if (array[0] != 0)
					{
						package.grids[num].count += array[0];
						package.grids[num].inc += array[1];
						flag = true;
					}
				}
			}
			if (flag)
			{
				package.NotifyStorageChange();
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)ex);
		}
		finally
		{
			taskState["ProcessPackage"] = true;
		}
	}

	private int[] AddItem(int itemId, int count, int inc, bool assembler = true)
	{
		int[] array = AddDeliveryPackageItem(itemId, count, inc, assembler);
		if (array[0] == count)
		{
			return array;
		}
		int[] array2 = AddTransportItem(itemId, count - array[0], inc - array[1], assembler);
		array2[0] += array[0];
		array2[1] += array[1];
		return array2;
	}

	private int[] AddDeliveryPackageItem(int itemId, int count, int inc, bool assembler = true)
	{
		if (itemId <= 0 || count <= 0 || !deliveryPackageItems.ContainsKey(itemId))
		{
			return new int[2];
		}
		int num = deliveryPackageItems[itemId];
		if (num < 0 || deliveryPackage.grids[num].itemId != itemId)
		{
			return new int[2];
		}
		int num2 = Math.Min(deliveryPackage.grids[num].recycleCount, ((GRID)(ref deliveryPackage.grids[num])).stackSizeModified);
		if (!assembler && itemId == 1120)
		{
			num2 = (int)((float)Math.Min(deliveryPackage.grids[num].recycleCount, ((GRID)(ref deliveryPackage.grids[num])).stackSizeModified) * 0.6f);
		}
		int num3 = num2 - deliveryPackage.grids[num].count;
		if (num3 <= 0)
		{
			return new int[2];
		}
		if (count <= num3)
		{
			deliveryPackage.grids[num].count += count;
			deliveryPackage.grids[num].inc += inc;
			SprayDeliveryPackageItem(num);
			return new int[2] { count, inc };
		}
		deliveryPackage.grids[num].count = num2;
		int num4 = SplitInc(count, inc, num3);
		deliveryPackage.grids[num].inc += num4;
		SprayDeliveryPackageItem(num);
		return new int[2] { num3, num4 };
	}

	private int[] AddTransportItem(int itemId, int count, int inc, bool assembler = true)
	{
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		if (itemId <= 0 || count <= 0 || !galacticTransportItems.ContainsKey(itemId))
		{
			return new int[2];
		}
		int[] array = new int[2];
		foreach (TransportItemIndex item in galacticTransportItems[itemId])
		{
			StationComponent val = GameMain.data.factories[item.planetIndex].transport.stationPool[item.transportIndex];
			StationStore val2 = val.storage[item.storageIndex];
			if (val2.itemId != itemId)
			{
				continue;
			}
			int num = val2.max - val2.localOrder - val2.remoteOrder - val2.count;
			if (!assembler && itemId == 1120)
			{
				num = (int)((float)val2.max * 0.6f) - val2.localOrder - val2.remoteOrder - val2.count;
			}
			if (num > 0)
			{
				if (count <= num)
				{
					val.storage[item.storageIndex].count += count;
					val.storage[item.storageIndex].inc += inc;
					array[0] += count;
					array[1] += inc;
					count = 0;
					inc = 0;
					SprayTransportItem(item);
					break;
				}
				val.storage[item.storageIndex].count += num;
				int num2 = SplitInc(count, inc, num);
				val.storage[item.storageIndex].inc += num2;
				array[0] += num;
				array[1] += num2;
				count -= num;
				inc -= num2;
				SprayTransportItem(item);
			}
		}
		return array;
	}

	private int[] TakeItem(int itemId, int count)
	{
		int[] array = TakeDeliveryPackageItem(itemId, count);
		if (array[0] == count)
		{
			return array;
		}
		int[] array2 = TakeTransportItem(itemId, count - array[0]);
		array2[0] += array[0];
		array2[1] += array[1];
		return array2;
	}

	private int[] TakeDeliveryPackageItem(int itemId, int count)
	{
		if (itemId <= 0 || count <= 0 || !deliveryPackageItems.ContainsKey(itemId))
		{
			return new int[2];
		}
		int num = deliveryPackageItems[itemId];
		if (num < 0 || deliveryPackage.grids[num].itemId != itemId)
		{
			return new int[2];
		}
		if (deliveryPackage.grids[num].count <= deliveryPackage.grids[num].requireCount)
		{
			return new int[2];
		}
		int num2 = deliveryPackage.grids[num].count - deliveryPackage.grids[num].requireCount;
		if (count <= num2)
		{
			int num3 = SplitInc(deliveryPackage.grids[num].count, deliveryPackage.grids[num].inc, count);
			deliveryPackage.grids[num].count -= count;
			deliveryPackage.grids[num].inc -= num3;
			return new int[2] { count, num3 };
		}
		int num4 = SplitInc(deliveryPackage.grids[num].count, deliveryPackage.grids[num].inc, num2);
		deliveryPackage.grids[num].count -= num2;
		deliveryPackage.grids[num].inc -= num4;
		return new int[2] { num2, num4 };
	}

	private int[] TakeTransportItem(int itemId, int count)
	{
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: 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_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		if (itemId <= 0 || count <= 0 || !galacticTransportItems.ContainsKey(itemId))
		{
			return new int[2];
		}
		int[] array = new int[2];
		foreach (TransportItemIndex item in galacticTransportItems[itemId])
		{
			StationComponent val = GameMain.data.factories[item.planetIndex].transport.stationPool[item.transportIndex];
			StationStore val2 = val.storage[item.storageIndex];
			if (val2.itemId == itemId && val2.count > 0)
			{
				if (count <= val2.count)
				{
					int num = SplitInc(val2.count, val2.inc, count);
					val.storage[item.storageIndex].count -= count;
					val.storage[item.storageIndex].inc -= num;
					array[0] += count;
					array[1] += num;
					break;
				}
				count -= val2.count;
				array[0] += val2.count;
				array[1] += val2.inc;
				val.storage[item.storageIndex].count = 0;
				val.storage[item.storageIndex].inc = 0;
			}
		}
		return array;
	}

	private int SplitInc(int count, int inc, int expectCount)
	{
		int num = inc / count;
		int num2 = inc - num * count;
		count -= expectCount;
		int num3 = num2 - count;
		int num4 = ((num3 > 0) ? (num * expectCount + num3) : (num * expectCount));
		inc -= num4;
		return num4;
	}
}