Decompiled source of BattlefieldAnalysisBaseDeliver v4.0.2

BattlefieldAnalysisBaseDeliver.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BattlefieldAnalysisBaseDeliver.Patches;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("YourName")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("允许配送无人机从战场分析基站直接取物品")]
[assembly: AssemblyFileVersion("4.0.2.0")]
[assembly: AssemblyInformationalVersion("4.0.2+6aafb5d134cccf8cfa5c5ad10eca6d3f16fd6aa7")]
[assembly: AssemblyProduct("BattlefieldAnalysisBaseDeliver")]
[assembly: AssemblyTitle("BattlefieldAnalysisBaseDeliver")]
[assembly: AssemblyVersion("4.0.2.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BattlefieldAnalysisBaseDeliver
{
	[BepInPlugin("un1eagle.battlefieldanalysisbasedeliver", "战场分析基站配送支持", "4.0.2")]
	public class Plugin : BaseUnityPlugin
	{
		public static ManualLogSource? Log;

		public static ConfigEntry<bool> EnableDebugLog;

		public static ConfigEntry<int> BattleBaseCourierCount;

		public static ConfigEntry<float> BattleBaseCourierSpeedMultiplier;

		public static ConfigEntry<int> BattleBaseCourierCarryCapacity;

		public static ConfigEntry<int> BattleBasePickupPartitionStackSize;

		public static bool DebugLog()
		{
			return EnableDebugLog?.Value ?? false;
		}

		public static int GetBattleBaseCourierCount()
		{
			int num = BattleBaseCourierCount?.Value ?? 20;
			if (num < 1)
			{
				return 1;
			}
			if (num > 200)
			{
				return 200;
			}
			return num;
		}

		public static float GetBattleBaseCourierSpeedMultiplier()
		{
			float num = BattleBaseCourierSpeedMultiplier?.Value ?? 2f;
			if (num < 0.1f)
			{
				return 0.1f;
			}
			if (num > 10f)
			{
				return 10f;
			}
			return num;
		}

		public static int GetBattleBaseCourierCarryCapacity()
		{
			int num = BattleBaseCourierCarryCapacity?.Value ?? 100;
			if (num < 1)
			{
				return 1;
			}
			if (num > 5000)
			{
				return 5000;
			}
			return num;
		}

		public static int GetBattleBasePickupPartitionStackSize()
		{
			int num = BattleBasePickupPartitionStackSize?.Value ?? 2000;
			if (num <= 0)
			{
				return 0;
			}
			if (num > 10000)
			{
				return 10000;
			}
			return num;
		}

		private void Awake()
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Expected O, but got Unknown
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Expected O, but got Unknown
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Expected O, but got Unknown
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Expected O, but got Unknown
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Expected O, but got Unknown
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Expected O, but got Unknown
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Expected O, but got Unknown
			//IL_02db: Expected O, but got Unknown
			//IL_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Expected O, but got Unknown
			//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Expected O, but got Unknown
			//IL_041e: Unknown result type (might be due to invalid IL or missing references)
			//IL_042b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"[战场分析基站配送支持] 正在加载... (GUID: un1eagle.battlefieldanalysisbasedeliver)");
			EnableDebugLog = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableDebugLog", false, "为 true 时在日志中输出详细的调试信息,用于排查问题。正常使用时建议设置为 false。");
			BattleBaseCourierCount = ((BaseUnityPlugin)this).Config.Bind<int>("General", "BattleBaseCourierCount", 20, new ConfigDescription("每个战场基站的无人机总数(1~200,默认 20)。修改后需重新进入存档或重新加载星球后生效。", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 200), Array.Empty<object>()));
			BattleBaseCourierSpeedMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "BattleBaseCourierSpeedMultiplier", 2f, new ConfigDescription("基站无人机速度倍率(在游戏物流速度基础上的倍数,0.1~10,默认 2.0)。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 10f), Array.Empty<object>()));
			BattleBaseCourierCarryCapacity = ((BaseUnityPlugin)this).Config.Bind<int>("General", "BattleBaseCourierCarryCapacity", 100, new ConfigDescription("基站无人机单次运载量(1~5000,默认 100)。", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 5000), Array.Empty<object>()));
			BattleBasePickupPartitionStackSize = ((BaseUnityPlugin)this).Config.Bind<int>("General", "BattleBasePickupPartitionStackSize", 2000, "基站拾取分区槽位堆叠上限(0=不修改,>0 时统一设置该值,默认 2000)。");
			Harmony val = new Harmony("un1eagle.battlefieldanalysisbasedeliver");
			MethodInfo methodInfo = AccessTools.Method(typeof(PlanetFactory), "Init", (Type[])null, (Type[])null);
			if (methodInfo != null)
			{
				val.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(PlanetFactory_Init_Patch), "Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				ManualLogSource? log = Log;
				if (log != null)
				{
					log.LogInfo((object)"[战场分析基站配送支持] ✓ PlanetFactory.Init 补丁已应用");
				}
			}
			MethodInfo methodInfo2 = AccessTools.Method(typeof(PlanetFactory), "Import", (Type[])null, (Type[])null);
			if (methodInfo2 != null)
			{
				val.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(PlanetFactory_Import_Patch), "Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				ManualLogSource? log2 = Log;
				if (log2 != null)
				{
					log2.LogInfo((object)"[战场分析基站配送支持] ✓ PlanetFactory.Import 补丁已应用(清理旧虚拟配送器)");
				}
			}
			MethodInfo methodInfo3 = AccessTools.Method(typeof(PlanetFactory), "Free", (Type[])null, (Type[])null);
			if (methodInfo3 != null)
			{
				val.Patch((MethodBase)methodInfo3, new HarmonyMethod(typeof(PlanetFactory_Free_Patch), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				ManualLogSource? log3 = Log;
				if (log3 != null)
				{
					log3.LogInfo((object)"[战场分析基站配送支持] ✓ PlanetFactory.Free 补丁已应用");
				}
			}
			MethodInfo methodInfo4 = AccessTools.Method(typeof(BattleBaseComponent), "InternalUpdate", (Type[])null, (Type[])null);
			if (methodInfo4 != null)
			{
				val.Patch((MethodBase)methodInfo4, (HarmonyMethod)null, new HarmonyMethod(typeof(BattleBaseComponent_InternalUpdate_Patch), "Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				ManualLogSource? log4 = Log;
				if (log4 != null)
				{
					log4.LogInfo((object)"[战场分析基站配送支持] ✓ BattleBaseComponent.InternalUpdate 补丁已应用(核心逻辑)");
				}
			}
			else
			{
				ManualLogSource? log5 = Log;
				if (log5 != null)
				{
					log5.LogWarning((object)"[战场分析基站配送支持] ⚠ 未找到 BattleBaseComponent.InternalUpdate 方法!");
				}
			}
			MethodInfo methodInfo5 = AccessTools.Method(typeof(BattleBaseComponent), "AutoPickTrash", (Type[])null, (Type[])null);
			if (methodInfo5 != null)
			{
				val.Patch((MethodBase)methodInfo5, new HarmonyMethod(typeof(BattleBaseComponent_AutoPickTrashLifeExtend_Patch), "Prefix", (Type[])null), new HarmonyMethod(typeof(BattleBaseComponent_AutoPickTrashLifeExtend_Patch), "Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				ManualLogSource? log6 = Log;
				if (log6 != null)
				{
					log6.LogInfo((object)"[战场分析基站配送支持] ✓ BattleBaseComponent.AutoPickTrash 补丁已应用(部分拾取+30秒寿命)");
				}
			}
			else
			{
				ManualLogSource? log7 = Log;
				if (log7 != null)
				{
					log7.LogWarning((object)"[战场分析基站配送支持] ⚠ 未找到 BattleBaseComponent.AutoPickTrash 方法!");
				}
			}
			MethodInfo methodInfo6 = AccessTools.Method(typeof(LogisticCourierRenderer), "Update", (Type[])null, (Type[])null);
			if (methodInfo6 != null)
			{
				val.Patch((MethodBase)methodInfo6, (HarmonyMethod)null, new HarmonyMethod(typeof(LogisticCourierRenderer_Update_Patch), "Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				ManualLogSource? log8 = Log;
				if (log8 != null)
				{
					log8.LogInfo((object)"[战场分析基站配送支持] ✓ LogisticCourierRenderer.Update 补丁已应用(无人机可见)");
				}
			}
			else
			{
				ManualLogSource? log9 = Log;
				if (log9 != null)
				{
					log9.LogWarning((object)"[战场分析基站配送支持] ⚠ 未找到 LogisticCourierRenderer.Update 方法!");
				}
			}
			MethodInfo methodInfo7 = AccessTools.Method(typeof(GameData), "Export", (Type[])null, (Type[])null);
			if (methodInfo7 != null)
			{
				val.Patch((MethodBase)methodInfo7, new HarmonyMethod(typeof(GameData_Export_Patch), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				ManualLogSource? log10 = Log;
				if (log10 != null)
				{
					log10.LogInfo((object)"[战场分析基站配送支持] ✓ GameData.Export 补丁已应用(存档安全)");
				}
			}
			else
			{
				ManualLogSource? log11 = Log;
				if (log11 != null)
				{
					log11.LogWarning((object)"[战场分析基站配送支持] ⚠ 未找到 GameData.Export 方法!");
				}
			}
			MethodInfo methodInfo8 = AccessTools.Method(typeof(GameData), "Import", (Type[])null, (Type[])null);
			if (methodInfo8 != null)
			{
				val.Patch((MethodBase)methodInfo8, (HarmonyMethod)null, new HarmonyMethod(typeof(GameData_Import_Patch), "Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				ManualLogSource? log12 = Log;
				if (log12 != null)
				{
					log12.LogInfo((object)"[战场分析基站配送支持] ✓ GameData.Import 补丁已应用(自动重新派遣)");
				}
			}
			else
			{
				ManualLogSource? log13 = Log;
				if (log13 != null)
				{
					log13.LogWarning((object)"[战场分析基站配送支持] ⚠ 未找到 GameData.Import 方法!");
				}
			}
			ManualLogSource? log14 = Log;
			if (log14 != null)
			{
				log14.LogInfo((object)"[战场分析基站配送支持] ========================================");
			}
			ManualLogSource? log15 = Log;
			if (log15 != null)
			{
				log15.LogInfo((object)"[战场分析基站配送支持] ✅ 加载完成!基站直接派遣方案");
			}
			ManualLogSource? log16 = Log;
			if (log16 != null)
			{
				log16.LogInfo((object)string.Format("[{0}] \ud83d\udce6 战场基站无人机数量: {1},速度倍率: {2},单次运载量: {3}(可在配置中修改)", "战场分析基站配送支持", GetBattleBaseCourierCount(), GetBattleBaseCourierSpeedMultiplier(), GetBattleBaseCourierCarryCapacity()));
			}
			ManualLogSource? log17 = Log;
			if (log17 != null)
			{
				log17.LogInfo((object)string.Format("[{0}] \ud83d\udce5 拾取分区 stackSize 配置: {1}(0 表示不修改)", "战场分析基站配送支持", GetBattleBasePickupPartitionStackSize()));
			}
			ManualLogSource? log18 = Log;
			if (log18 != null)
			{
				log18.LogInfo((object)"[战场分析基站配送支持] \ud83d\ude80 无需虚拟配送器,性能优化");
			}
			ManualLogSource? log19 = Log;
			if (log19 != null)
			{
				log19.LogInfo((object)"[战场分析基站配送支持] \ud83d\udcbe 存档安全,自动兼容旧方案");
			}
			ManualLogSource? log20 = Log;
			if (log20 != null)
			{
				log20.LogInfo((object)"[战场分析基站配送支持] ========================================");
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "un1eagle.battlefieldanalysisbasedeliver";

		public const string PLUGIN_NAME = "战场分析基站配送支持";

		public const string PLUGIN_VERSION = "4.0.2";
	}
}
namespace BattlefieldAnalysisBaseDeliver.Patches
{
	[HarmonyPatch(typeof(BattleBaseComponent), "AutoPickTrash")]
	public static class BattleBaseComponent_AutoPickTrashLifeExtend_Patch
	{
		public struct WatchState
		{
			public List<WatchEntry> Entries;
		}

		public struct WatchEntry
		{
			public int Index;

			public int ItemId;

			public int OldCount;
		}

		private const int START_SEED_MULTIPLIER = 4;

		private const int MAX_ATTEMPTS_PER_CALL = 4;

		private const int LIFE_EXTEND_FRAMES = 1800;

		private const int LIFE_MAX_FRAMES = 3600;

		[HarmonyPrefix]
		public static void Prefix(BattleBaseComponent __instance, PlanetFactory factory, TrashSystem trashSystem, long time, ref WatchState __state)
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: 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)
			__state = default(WatchState);
			try
			{
				if (__instance == null || factory == null || trashSystem?.container == null)
				{
					return;
				}
				EnsurePickupPartitionStackSize(__instance);
				ref EntityData reference = ref factory.entityPool[__instance.entityId];
				if (reference.id != __instance.entityId)
				{
					return;
				}
				TrashContainer container = trashSystem.container;
				int trashCursor = container.trashCursor;
				if (trashCursor <= 0)
				{
					return;
				}
				TrashObject[] trashObjPool = container.trashObjPool;
				TrashData[] trashDataPool = container.trashDataPool;
				int astroId = factory.planet.astroId;
				Vector3 pos = reference.pos;
				float x = pos.x;
				float y = pos.y;
				float z = pos.z;
				float num = __instance.pickRange * __instance.pickRange;
				int num2 = (int)((time * 4 + __instance.id) % 1000000000);
				List<WatchEntry> list = new List<WatchEntry>(4);
				for (int i = num2; i < num2 + trashCursor; i++)
				{
					int num3 = i % trashCursor;
					if (trashObjPool[num3].item <= 0 || trashObjPool[num3].expire >= 0 || trashDataPool[num3].nearPlanetId != astroId)
					{
						continue;
					}
					float num4 = trashDataPool[num3].lPos.x - x;
					float num5 = num4 * num4;
					if (num5 >= num)
					{
						continue;
					}
					float num6 = trashDataPool[num3].lPos.y - y;
					float num7 = num6 * num6;
					if (num7 >= num)
					{
						continue;
					}
					float num8 = trashDataPool[num3].lPos.z - z;
					float num9 = num8 * num8;
					if (!(num9 >= num) && !(num5 + num7 + num9 >= num))
					{
						list.Add(new WatchEntry
						{
							Index = num3,
							ItemId = trashObjPool[num3].item,
							OldCount = trashObjPool[num3].count
						});
						if (list.Count >= 4)
						{
							break;
						}
					}
				}
				__state = new WatchState
				{
					Entries = list
				};
			}
			catch (Exception ex)
			{
				ManualLogSource? log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)("[战场分析基站配送支持] AutoPickTrashLifeExtend Prefix 异常: " + ex.Message));
				}
			}
		}

		private static void EnsurePickupPartitionStackSize(BattleBaseComponent battleBase)
		{
			try
			{
				int battleBasePickupPartitionStackSize = Plugin.GetBattleBasePickupPartitionStackSize();
				if (battleBasePickupPartitionStackSize <= 0)
				{
					return;
				}
				StorageComponent storage = battleBase.storage;
				if (storage == null || storage.grids == null || storage.size <= 0)
				{
					return;
				}
				int num = storage.size - storage.bans;
				if (num <= 0)
				{
					return;
				}
				if (num > storage.grids.Length)
				{
					num = storage.grids.Length;
				}
				bool flag = false;
				for (int i = 0; i < num; i++)
				{
					if (storage.grids[i].stackSize != battleBasePickupPartitionStackSize)
					{
						storage.grids[i].stackSize = battleBasePickupPartitionStackSize;
						flag = true;
					}
				}
				if (flag)
				{
					storage.NotifyStorageChange();
				}
			}
			catch (Exception ex)
			{
				ManualLogSource? log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)("[战场分析基站配送支持] EnsurePickupPartitionStackSize 异常: " + ex.Message));
				}
			}
		}

		[HarmonyPostfix]
		public static void Postfix(TrashSystem trashSystem, WatchState __state)
		{
			try
			{
				if (trashSystem?.container == null || __state.Entries == null || __state.Entries.Count == 0)
				{
					return;
				}
				TrashContainer container = trashSystem.container;
				TrashObject[] trashObjPool = container.trashObjPool;
				TrashData[] trashDataPool = container.trashDataPool;
				int trashCursor = container.trashCursor;
				foreach (WatchEntry entry in __state.Entries)
				{
					int index = entry.Index;
					if (index < 0 || index >= trashCursor)
					{
						continue;
					}
					int item = trashObjPool[index].item;
					int count = trashObjPool[index].count;
					if (item == entry.ItemId && count > 0 && count < entry.OldCount)
					{
						int life = trashDataPool[index].life;
						if (life > 0 && life < 3600)
						{
							int num = life + 1800;
							trashDataPool[index].life = ((num > 3600) ? 3600 : num);
						}
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource? log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)("[战场分析基站配送支持] AutoPickTrashLifeExtend Postfix 异常: " + ex.Message));
				}
			}
		}
	}
	[HarmonyPatch(typeof(BattleBaseComponent), "InternalUpdate")]
	public static class BattleBaseComponent_InternalUpdate_Patch
	{
		private const int STATION_ENDID_OFFSET = 20000;

		private const int STATION_WARPER_STORAGE_ENDID_OFFSET = 30000;

		private const int SUPPLY_FETCH_ENDID_OFFSET = 40000;

		[HarmonyPostfix]
		private static void Postfix(BattleBaseComponent __instance, PlanetFactory factory)
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (__instance == null || factory == null || __instance.id <= 0 || __instance.entityId <= 0)
				{
					return;
				}
				int id = __instance.id;
				BaseLogisticSystem orCreate = BattleBaseLogisticsManager.GetOrCreate(factory.planetId, id);
				UpdateCouriers(orCreate, __instance, factory);
				DispatchContext dispatchContext = BattleBaseLogisticsManager.TryGetDispatchContext(orCreate, __instance, factory, __instance.entityId);
				if (dispatchContext == null)
				{
					return;
				}
				int num = 0;
				foreach (DispenserDemand demand in dispatchContext.Demands)
				{
					if (orCreate.idleCount > 0)
					{
						if (DispatchCourier(orCreate, __instance, factory, demand, dispatchContext.BasePosition, dispatchContext.CurrentInventory))
						{
							num++;
						}
						continue;
					}
					break;
				}
				if (num > 0 && Plugin.DebugLog())
				{
					ManualLogSource? log = Plugin.Log;
					if (log != null)
					{
						log.LogInfo((object)string.Format("[{0}] \ud83d\udce6 基站[{1}] 共派遣 {2} 个无人机,剩余空闲={3}", "战场分析基站配送支持", id, num, orCreate.idleCount));
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource? log2 = Plugin.Log;
				if (log2 != null)
				{
					log2.LogError((object)("[战场分析基站配送支持] BattleBaseComponent.InternalUpdate 异常: " + ex.Message + "\n" + ex.StackTrace));
				}
			}
		}

		private static bool DispatchCourier(BaseLogisticSystem logistics, BattleBaseComponent battleBase, PlanetFactory factory, DispenserDemand demand, Vector3 basePosition, Dictionary<int, int> currentInventory)
		{
			//IL_000c: 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_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: 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_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: 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_015a: 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_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: 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_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_0304: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d9: 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)
			//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0401: Unknown result type (might be due to invalid IL or missing references)
			//IL_0403: Unknown result type (might be due to invalid IL or missing references)
			//IL_042b: Unknown result type (might be due to invalid IL or missing references)
			//IL_043b: Unknown result type (might be due to invalid IL or missing references)
			//IL_044b: Unknown result type (might be due to invalid IL or missing references)
			//IL_045b: Unknown result type (might be due to invalid IL or missing references)
			//IL_046b: Unknown result type (might be due to invalid IL or missing references)
			//IL_047b: Unknown result type (might be due to invalid IL or missing references)
			//IL_048b: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (demand.IsSupplyFetch)
				{
					return DispatchSupplyFetchCourier(logistics, battleBase, factory, demand, basePosition);
				}
				int itemId = demand.itemId;
				int num = Plugin.GetBattleBaseCourierCarryCapacity();
				if (demand.needCount > 0 && demand.needCount < num)
				{
					num = demand.needCount;
				}
				int num2 = (currentInventory.ContainsKey(itemId) ? currentInventory[itemId] : 0);
				int actualCount = 0;
				int inc = 0;
				if (!TakeItemFromBase(battleBase, itemId, num, out actualCount, out inc))
				{
					return false;
				}
				if (actualCount <= 0)
				{
					return false;
				}
				int num3 = num2 - actualCount;
				Vector3 position = demand.position;
				float num4 = Vector3.Distance(basePosition, position);
				int num5 = -1;
				for (int i = 0; i < logistics.couriers.Length; i++)
				{
					if (logistics.couriers[i].maxt <= 0f)
					{
						num5 = i;
						break;
					}
				}
				if (num5 < 0)
				{
					ReturnItemToBase(battleBase, itemId, actualCount, inc);
					return false;
				}
				int endId = (demand.IsMechaSlot ? (-(demand.slotIndex + 1)) : (demand.IsStationTower ? ((demand.IsWarperStorageDemand ? 30000 : 20000) + demand.stationId) : demand.dispenserId));
				float maxt = num4;
				Vector3 begin = basePosition;
				Vector3 end = position;
				if (demand.IsMechaSlot)
				{
					begin = basePosition;
					end = basePosition;
					maxt = 1f;
				}
				logistics.couriers[num5] = new CourierData
				{
					begin = begin,
					end = end,
					endId = endId,
					direction = 1f,
					maxt = maxt,
					t = 0f,
					itemId = itemId,
					itemCount = actualCount,
					inc = inc,
					gene = num5
				};
				logistics.idleCount--;
				logistics.workingCount++;
				if (demand.IsMechaSlot)
				{
					Player mainPlayer = GameMain.mainPlayer;
					DeliveryPackage val = ((mainPlayer != null) ? mainPlayer.deliveryPackage : null);
					if (val?.grids != null && demand.slotIndex >= 0 && demand.slotIndex < val.grids.Length)
					{
						val.grids[demand.slotIndex].ordered += actualCount;
					}
				}
				else if (!demand.IsStationTower && demand.dispenserId > 0)
				{
					DispenserComponent dispenser = BattleBaseLogisticsManager.GetDispenser(factory, demand.dispenserId);
					if (dispenser != null)
					{
						dispenser.storageOrdered += actualCount;
					}
				}
				else if (demand.IsStationTower && !demand.IsWarperStorageDemand)
				{
					StationComponent stationComponent = factory.transport.GetStationComponent(demand.stationId);
					if (stationComponent?.storage != null && demand.StationStorageIndex >= 0 && demand.StationStorageIndex < stationComponent.storage.Length)
					{
						stationComponent.storage[demand.StationStorageIndex].localOrder += actualCount;
					}
				}
				if (Plugin.DebugLog())
				{
					EntityData val2 = factory.entityPool[battleBase.entityId];
					Quaternion rot = val2.rot;
					Vector3 eulerAngles = ((Quaternion)(ref rot)).eulerAngles;
					string itemName = GetItemName(itemId);
					string text = (demand.IsMechaSlot ? $"机甲槽位[{demand.slotIndex}]" : (demand.IsStationTower ? $"物流塔[{demand.stationId}]" : $"配送器[{demand.dispenserId}]"));
					ManualLogSource? log = Plugin.Log;
					if (log != null)
					{
						log.LogInfo((object)string.Format("[{0}] \ud83d\ude80 派遣: 基站[{1}] → {2} 物品={3}(ID:{4}) 派遣={5} 剩余={6} 紧急度={7:F2} | 基站pos=({8:F2},{9:F2},{10:F2}) mag={11:F2} rot=({12:F4},{13:F4},{14:F4},{15:F4}) 欧拉=({16:F1},{17:F1},{18:F1})°", "战场分析基站配送支持", battleBase.id, text, itemName, itemId, actualCount, num3, demand.urgency, val2.pos.x, val2.pos.y, val2.pos.z, ((Vector3)(ref val2.pos)).magnitude, rot.x, rot.y, rot.z, rot.w, eulerAngles.x, eulerAngles.y, eulerAngles.z));
					}
				}
				return true;
			}
			catch (Exception ex)
			{
				ManualLogSource? log2 = Plugin.Log;
				if (log2 != null)
				{
					log2.LogError((object)("[战场分析基站配送支持] DispatchCourier 异常: " + ex.Message));
				}
				return false;
			}
		}

		private static bool DispatchSupplyFetchCourier(BaseLogisticSystem logistics, BattleBaseComponent battleBase, PlanetFactory factory, DispenserDemand demand, Vector3 basePosition)
		{
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_013a: 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)
			int battleBaseCourierCarryCapacity = Plugin.GetBattleBaseCourierCarryCapacity();
			int num = Math.Min(demand.needCount, battleBaseCourierCarryCapacity);
			if (num <= 0)
			{
				return false;
			}
			DispenserComponent dispenser = BattleBaseLogisticsManager.GetDispenser(factory, demand.dispenserId);
			if (dispenser == null)
			{
				return false;
			}
			int dispenserStockPublic = BattleBaseLogisticsManager.GetDispenserStockPublic(dispenser, demand.itemId);
			if (dispenserStockPublic <= 0)
			{
				return false;
			}
			num = Math.Min(num, dispenserStockPublic);
			int num2 = -1;
			for (int i = 0; i < logistics.couriers.Length; i++)
			{
				if (logistics.couriers[i].maxt <= 0f)
				{
					num2 = i;
					break;
				}
			}
			if (num2 < 0)
			{
				return false;
			}
			dispenser.storageOrdered -= num;
			BattleBaseLogisticsManager.AddBaseFetchInFlight(factory.planetId, battleBase.id, demand.itemId, num);
			float maxt = Vector3.Distance(basePosition, demand.position);
			logistics.couriers[num2] = new CourierData
			{
				begin = basePosition,
				end = demand.position,
				endId = 40000 + demand.dispenserId,
				direction = 1f,
				maxt = maxt,
				t = 0f,
				itemId = demand.itemId,
				itemCount = 0,
				inc = 0,
				gene = num
			};
			logistics.idleCount--;
			logistics.workingCount++;
			if (Plugin.DebugLog())
			{
				string itemName = GetItemName(demand.itemId);
				ManualLogSource? log = Plugin.Log;
				if (log != null)
				{
					log.LogInfo((object)string.Format("[{0}] \ud83d\ude80 拉货派遣: 基站[{1}] → 供应配送器[{2}] 物品={3}(ID:{4}) 预留={5}", "战场分析基站配送支持", battleBase.id, demand.dispenserId, itemName, demand.itemId, num));
				}
			}
			return true;
		}

		private static void UpdateCouriers(BaseLogisticSystem logistics, BattleBaseComponent battleBase, PlanetFactory factory)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: 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_0062: 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_0068: 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_0073: 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_0092: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0821: Unknown result type (might be due to invalid IL or missing references)
			//IL_0826: Unknown result type (might be due to invalid IL or missing references)
			//IL_082d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0832: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: 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_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_09d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_09d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_09e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_09e5: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (logistics.workingCount <= 0)
				{
					return;
				}
				float logisticCourierSpeedModified = GameMain.history.logisticCourierSpeedModified;
				logisticCourierSpeedModified *= Plugin.GetBattleBaseCourierSpeedMultiplier();
				float num = logisticCourierSpeedModified * (1f / 60f);
				EntityData val = factory.entityPool[battleBase.entityId];
				Vector3 val2 = ((((Vector3)(ref val.pos)).sqrMagnitude < 1E-06f) ? Vector3.up : ((Vector3)(ref val.pos)).normalized);
				Vector3 basePos = val.pos + val2 * 7.5f;
				Vector3? val3 = ((GameMain.mainPlayer != null) ? new Vector3?(GameMain.mainPlayer.position) : null);
				for (int i = 0; i < logistics.couriers.Length; i++)
				{
					ref CourierData reference = ref logistics.couriers[i];
					if (reference.maxt <= 0f)
					{
						continue;
					}
					if (reference.endId < 0 && reference.direction > 0f && val3.HasValue)
					{
						UpdateCourierToMecha(ref reference, basePos, val3.Value, logisticCourierSpeedModified);
					}
					else
					{
						reference.t += num * reference.direction;
					}
					if (reference.direction > 0f && reference.t >= reference.maxt)
					{
						reference.t = reference.maxt;
						if (reference.endId >= 40000)
						{
							int dispenserId = reference.endId - 40000;
							int gene = reference.gene;
							int battleBaseCourierCarryCapacity = Plugin.GetBattleBaseCourierCarryCapacity();
							TakeItemFromDispenser(factory, dispenserId, reference.itemId, Math.Min(gene, battleBaseCourierCarryCapacity), out var actualCount, out var inc);
							DispenserComponent dispenser = BattleBaseLogisticsManager.GetDispenser(factory, dispenserId);
							if (actualCount > 0)
							{
								if (actualCount < gene && dispenser != null)
								{
									dispenser.storageOrdered += gene - actualCount;
								}
								reference.itemCount = actualCount;
								reference.inc = inc;
								reference.direction = -1f;
								continue;
							}
							if (dispenser != null)
							{
								dispenser.storageOrdered += gene;
							}
							BattleBaseLogisticsManager.AddBaseFetchInFlight(factory.planetId, battleBase.id, reference.itemId, -gene);
							reference.maxt = 0f;
							reference.begin = Vector3.zero;
							reference.end = Vector3.zero;
							reference.endId = 0;
							reference.direction = 0f;
							reference.itemId = 0;
							reference.itemCount = 0;
							reference.inc = 0;
							reference.gene = 0;
							logistics.workingCount--;
							logistics.idleCount++;
							continue;
						}
						bool flag;
						if (reference.endId < 0)
						{
							int num2 = -(reference.endId + 1);
							flag = DeliverToMecha(num2, reference.itemId, reference.itemCount, reference.inc);
							Player mainPlayer = GameMain.mainPlayer;
							DeliveryPackage val4 = ((mainPlayer != null) ? mainPlayer.deliveryPackage : null);
							if (val4?.grids != null && num2 >= 0 && num2 < val4.grids.Length)
							{
								val4.grids[num2].ordered -= reference.itemCount;
							}
							if (Plugin.DebugLog() && flag)
							{
								string itemName = GetItemName(reference.itemId);
								ManualLogSource? log = Plugin.Log;
								if (log != null)
								{
									log.LogInfo((object)string.Format("[{0}] \ud83d\udcec 送货成功: 机甲槽位[{1}] 物品={2}(ID:{3})x{4}", "战场分析基站配送支持", num2, itemName, reference.itemId, reference.itemCount));
								}
							}
						}
						else if (reference.endId >= 20000)
						{
							bool num3 = reference.endId >= 30000;
							int num4 = (num3 ? (reference.endId - 30000) : (reference.endId - 20000));
							int itemCount = reference.itemCount;
							int num5 = DeliverToStation(factory, num4, reference.itemId, reference.itemCount, reference.inc);
							flag = num5 >= reference.itemCount;
							if (!num3)
							{
								BattleBaseLogisticsManager.DecrementStationSlotLocalOrder(factory, num4, reference.itemId, itemCount);
							}
							if (num5 > 0)
							{
								if (Plugin.DebugLog())
								{
									string itemName2 = GetItemName(reference.itemId);
									ManualLogSource? log2 = Plugin.Log;
									if (log2 != null)
									{
										log2.LogInfo((object)(string.Format("[{0}] \ud83d\udcec 送货成功: 物流塔[{1}] 物品={2}(ID:{3})x{4}", "战场分析基站配送支持", num4, itemName2, reference.itemId, num5) + ((num5 < reference.itemCount) ? $" 剩余{reference.itemCount - num5}返还" : "")));
									}
								}
								if (num5 >= reference.itemCount)
								{
									reference.itemId = 0;
									reference.itemCount = 0;
									reference.inc = 0;
								}
								else
								{
									reference.itemCount -= num5;
									reference.inc = 0;
								}
							}
						}
						else
						{
							flag = DeliverToDispenser(factory, reference.endId, reference.itemId, reference.itemCount, reference.inc);
							DispenserComponent dispenser2 = BattleBaseLogisticsManager.GetDispenser(factory, reference.endId);
							if (dispenser2 != null)
							{
								dispenser2.storageOrdered -= reference.itemCount;
							}
							if (Plugin.DebugLog() && flag)
							{
								string itemName3 = GetItemName(reference.itemId);
								ManualLogSource? log3 = Plugin.Log;
								if (log3 != null)
								{
									log3.LogInfo((object)string.Format("[{0}] \ud83d\udcec 送货成功: 配送器[{1}] 物品={2}(ID:{3})x{4}", "战场分析基站配送支持", reference.endId, itemName3, reference.itemId, reference.itemCount));
								}
							}
						}
						if (flag)
						{
							reference.itemId = 0;
							reference.itemCount = 0;
							reference.inc = 0;
						}
						else if (Plugin.DebugLog())
						{
							string itemName4 = GetItemName(reference.itemId);
							string text = ((reference.endId < 0) ? $"机甲槽位[{-reference.endId - 1}]" : ((reference.endId >= 30000) ? $"物流塔[{reference.endId - 30000}]翘曲器小格" : ((reference.endId >= 20000) ? $"物流塔[{reference.endId - 20000}]" : $"配送器[{reference.endId}]")));
							ManualLogSource? log4 = Plugin.Log;
							if (log4 != null)
							{
								log4.LogWarning((object)string.Format("[{0}] ⚠\ufe0f 送货失败: {1} 物品={2}(ID:{3})x{4},将返还到基站", "战场分析基站配送支持", text, itemName4, reference.itemId, reference.itemCount));
							}
						}
						reference.direction = -1f;
					}
					else
					{
						if (!(reference.direction < 0f) || !(reference.t <= 0f))
						{
							continue;
						}
						reference.t = 0f;
						if (reference.endId >= 40000)
						{
							if (reference.itemId > 0 && reference.itemCount > 0)
							{
								DeliverToBaseInputPartition(battleBase, factory, reference.itemId, reference.itemCount, reference.inc);
								BattleBaseLogisticsManager.AddBaseFetchInFlight(factory.planetId, battleBase.id, reference.itemId, -reference.itemCount);
								DispenserComponent dispenser3 = BattleBaseLogisticsManager.GetDispenser(factory, reference.endId - 40000);
								if (dispenser3 != null)
								{
									dispenser3.storageOrdered += reference.itemCount;
								}
								if (Plugin.DebugLog())
								{
									string itemName5 = GetItemName(reference.itemId);
									ManualLogSource? log5 = Plugin.Log;
									if (log5 != null)
									{
										log5.LogInfo((object)string.Format("[{0}] \ud83d\udce5 拉货送达: 基站[{1}] 输入区 物品={2}(ID:{3})x{4}", "战场分析基站配送支持", battleBase.id, itemName5, reference.itemId, reference.itemCount));
									}
								}
							}
							reference.maxt = 0f;
							reference.begin = Vector3.zero;
							reference.end = Vector3.zero;
							reference.endId = 0;
							reference.direction = 0f;
							reference.itemId = 0;
							reference.itemCount = 0;
							reference.inc = 0;
							reference.gene = 0;
							logistics.workingCount--;
							logistics.idleCount++;
							if (Plugin.DebugLog())
							{
								ManualLogSource? log6 = Plugin.Log;
								if (log6 != null)
								{
									log6.LogInfo((object)string.Format("[{0}] \ud83c\udfe0 无人机返回: 基站[{1}] 空闲={2}", "战场分析基站配送支持", battleBase.id, logistics.idleCount));
								}
							}
							continue;
						}
						if (reference.endId >= 20000 && reference.endId < 30000 && reference.itemId > 0 && reference.itemCount > 0)
						{
							int stationId = reference.endId - 20000;
							BattleBaseLogisticsManager.DecrementStationSlotLocalOrder(factory, stationId, reference.itemId, reference.itemCount);
						}
						if (reference.itemId > 0 && reference.itemCount > 0)
						{
							ReturnItemToBase(battleBase, reference.itemId, reference.itemCount, reference.inc);
							if (Plugin.DebugLog())
							{
								string itemName6 = GetItemName(reference.itemId);
								ManualLogSource? log7 = Plugin.Log;
								if (log7 != null)
								{
									log7.LogInfo((object)string.Format("[{0}] \ud83d\udce6 返还物品: 基站[{1}] 物品={2}(ID:{3})x{4}", "战场分析基站配送支持", battleBase.id, itemName6, reference.itemId, reference.itemCount));
								}
							}
						}
						reference.maxt = 0f;
						reference.begin = Vector3.zero;
						reference.end = Vector3.zero;
						reference.endId = 0;
						reference.direction = 0f;
						reference.itemId = 0;
						reference.itemCount = 0;
						reference.inc = 0;
						logistics.workingCount--;
						logistics.idleCount++;
						if (Plugin.DebugLog())
						{
							ManualLogSource? log8 = Plugin.Log;
							if (log8 != null)
							{
								log8.LogInfo((object)string.Format("[{0}] \ud83c\udfe0 无人机返回: 基站[{1}] 空闲={2}", "战场分析基站配送支持", battleBase.id, logistics.idleCount));
							}
						}
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource? log9 = Plugin.Log;
				if (log9 != null)
				{
					log9.LogError((object)("[战场分析基站配送支持] UpdateCouriers 异常: " + ex.Message));
				}
			}
		}

		private static void UpdateCourierToMecha(ref CourierData courier, Vector3 basePos, Vector3 playerPos, float courierSpeed)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_0066: 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_0073: 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_0082: 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_008f: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: 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_00d3: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: 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_00f4: 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_0231: 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_0117: 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_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: 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_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: 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_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			Vector3 end = courier.end;
			float num = playerPos.x - end.x;
			float num2 = playerPos.y - end.y;
			float num3 = playerPos.z - end.z;
			float num4 = (float)Math.Sqrt(num * num + num2 * num2 + num3 * num3);
			float num5 = (float)Math.Sqrt((playerPos.x - basePos.x) * (playerPos.x - basePos.x) + (playerPos.y - basePos.y) * (playerPos.y - basePos.y) + (playerPos.z - basePos.z) * (playerPos.z - basePos.z));
			float num6 = (float)Math.Sqrt(end.x * end.x + end.y * end.y + end.z * end.z);
			float num7 = (float)Math.Sqrt(playerPos.x * playerPos.x + playerPos.y * playerPos.y + playerPos.z * playerPos.z);
			if (num4 < 1.4f)
			{
				double num8 = Math.Sqrt(basePos.x * basePos.x + basePos.y * basePos.y + basePos.z * basePos.z);
				double num9 = Math.Sqrt(playerPos.x * playerPos.x + playerPos.y * playerPos.y + playerPos.z * playerPos.z);
				double num10 = (double)(basePos.x * playerPos.x + basePos.y * playerPos.y + basePos.z * playerPos.z) / (num8 * num9);
				if (num10 < -1.0)
				{
					num10 = -1.0;
				}
				else if (num10 > 1.0)
				{
					num10 = 1.0;
				}
				courier.begin = basePos;
				courier.maxt = (float)(Math.Acos(num10) * ((num8 + num9) * 0.5));
				courier.maxt = (float)Math.Sqrt((double)(courier.maxt * courier.maxt) + (num8 - num9) * (num8 - num9));
				courier.t = courier.maxt;
				return;
			}
			courier.begin = end;
			float num11 = courierSpeed * (1f / 60f) / num4;
			if (num11 > 1f)
			{
				num11 = 1f;
			}
			float num12 = num * num11;
			float num13 = num2 * num11;
			float num14 = num3 * num11;
			float num15 = num4 / courierSpeed;
			if (num15 < 0.03333333f)
			{
				num15 = 0.03333333f;
			}
			float num16 = (num7 - num6) / num15 * (1f / 60f);
			end.x += num12;
			end.y += num13;
			end.z += num14;
			float num17 = (float)Math.Sqrt(end.x * end.x + end.y * end.y + end.z * end.z);
			if (num17 > 1E-05f)
			{
				float num18 = (num6 + num16) / num17;
				end.x *= num18;
				end.y *= num18;
				end.z *= num18;
			}
			courier.end = end;
			if (num5 > courier.maxt)
			{
				courier.maxt = num5;
			}
			courier.t = num4;
			if (courier.t >= courier.maxt * 0.99f)
			{
				courier.t = courier.maxt * 0.99f;
			}
		}

		private static bool TakeItemFromBase(BattleBaseComponent battleBase, int itemId, int maxCount, out int actualCount, out int inc)
		{
			actualCount = 0;
			inc = 0;
			try
			{
				if (battleBase.storage == null)
				{
					return false;
				}
				MethodInfo method = ((object)battleBase.storage).GetType().GetMethod("TakeItem", BindingFlags.Instance | BindingFlags.Public);
				if (method == null)
				{
					return false;
				}
				object[] array = new object[3] { itemId, maxCount, 0 };
				object obj = method.Invoke(battleBase.storage, array);
				if (obj == null)
				{
					return false;
				}
				actualCount = (int)obj;
				inc = (int)array[2];
				return actualCount > 0;
			}
			catch (Exception ex)
			{
				ManualLogSource? log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)("[战场分析基站配送支持] TakeItemFromBase 异常: " + ex.Message));
				}
				return false;
			}
		}

		private static void ReturnItemToBase(BattleBaseComponent battleBase, int itemId, int count, int inc)
		{
			try
			{
				if (battleBase.storage != null)
				{
					MethodInfo method = ((object)battleBase.storage).GetType().GetMethod("AddItem", BindingFlags.Instance | BindingFlags.Public, null, new Type[5]
					{
						typeof(int),
						typeof(int),
						typeof(int),
						typeof(int).MakeByRefType(),
						typeof(bool)
					}, null);
					if (!(method == null))
					{
						object[] parameters = new object[5] { itemId, count, inc, 0, false };
						method.Invoke(battleBase.storage, parameters);
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource? log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)("[战场分析基站配送支持] ReturnItemToBase 异常: " + ex.Message));
				}
			}
		}

		private static bool DeliverToMecha(int slotIndex, int itemId, int count, int inc)
		{
			try
			{
				Player mainPlayer = GameMain.mainPlayer;
				if (((mainPlayer != null) ? mainPlayer.packageUtility : null) == null)
				{
					return false;
				}
				if (itemId <= 0 || count <= 0 || itemId == 1099)
				{
					return false;
				}
				int num = default(int);
				int num2 = mainPlayer.packageUtility.AddItemToAllPackages(itemId, count, slotIndex, inc, ref num, 0);
				if (num2 > 0)
				{
					mainPlayer.NotifyReplenishPreferred(itemId, num2);
					return true;
				}
				return false;
			}
			catch (Exception ex)
			{
				ManualLogSource? log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)("[战场分析基站配送支持] DeliverToMecha 异常: " + ex.Message + "\n" + ex.StackTrace));
				}
				return false;
			}
		}

		private static int DeliverToStation(PlanetFactory factory, int stationId, int itemId, int count, int inc)
		{
			try
			{
				if (factory?.transport == null)
				{
					return 0;
				}
				if (stationId <= 0)
				{
					return 0;
				}
				StationComponent stationComponent = factory.transport.GetStationComponent(stationId);
				if (stationComponent == null || stationComponent.id != stationId)
				{
					return 0;
				}
				if (itemId == 1210)
				{
					if (!stationComponent.isStellar || stationComponent.warperMaxCount <= 0)
					{
						return 0;
					}
					int num = Math.Min(count, Math.Max(0, stationComponent.warperMaxCount - stationComponent.warperCount));
					stationComponent.warperCount += num;
					int num2 = count - num;
					if (num2 <= 0)
					{
						return num;
					}
					int num3 = stationComponent.AddItem(1210, num2, inc);
					return num + num3;
				}
				return stationComponent.AddItem(itemId, count, inc);
			}
			catch (Exception ex)
			{
				ManualLogSource? log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)("[战场分析基站配送支持] DeliverToStation 异常: " + ex.Message + "\n" + ex.StackTrace));
				}
				return 0;
			}
		}

		private static bool DeliverToDispenser(PlanetFactory factory, int dispenserId, int itemId, int count, int inc)
		{
			try
			{
				if (factory?.transport == null)
				{
					if (Plugin.DebugLog())
					{
						ManualLogSource? log = Plugin.Log;
						if (log != null)
						{
							log.LogWarning((object)"[战场分析基站配送支持] 送货失败: factory.transport 为 null");
						}
					}
					return false;
				}
				FieldInfo field = ((object)factory.transport).GetType().GetField("dispenserPool", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field == null)
				{
					if (Plugin.DebugLog())
					{
						ManualLogSource? log2 = Plugin.Log;
						if (log2 != null)
						{
							log2.LogWarning((object)"[战场分析基站配送支持] 送货失败: dispenserPoolField 为 null");
						}
					}
					return false;
				}
				Array array = field.GetValue(factory.transport) as Array;
				if (array == null || dispenserId <= 0 || dispenserId >= array.Length)
				{
					if (Plugin.DebugLog())
					{
						ManualLogSource? log3 = Plugin.Log;
						if (log3 != null)
						{
							log3.LogWarning((object)string.Format("[{0}] 送货失败: dispenserId={1} 无效(范围: 1-{2})", "战场分析基站配送支持", dispenserId, array?.Length ?? 0));
						}
					}
					return false;
				}
				object? value = array.GetValue(dispenserId);
				DispenserComponent val = (DispenserComponent)((value is DispenserComponent) ? value : null);
				if (val == null || val.id != dispenserId)
				{
					if (Plugin.DebugLog())
					{
						ManualLogSource? log4 = Plugin.Log;
						if (log4 != null)
						{
							log4.LogWarning((object)string.Format("[{0}] 送货失败: dispenser[{1}] 为 null 或 id 不匹配", "战场分析基站配送支持", dispenserId));
						}
					}
					return false;
				}
				if (val.storage?.bottomStorage == null)
				{
					if (Plugin.DebugLog())
					{
						ManualLogSource? log5 = Plugin.Log;
						if (log5 != null)
						{
							log5.LogWarning((object)string.Format("[{0}] 送货失败: dispenser[{1}].storage.bottomStorage 为 null", "战场分析基站配送支持", dispenserId));
						}
					}
					return false;
				}
				FieldInfo field2 = ((object)val.storage.bottomStorage).GetType().GetField("entityId", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field2 == null)
				{
					if (Plugin.DebugLog())
					{
						ManualLogSource? log6 = Plugin.Log;
						if (log6 != null)
						{
							log6.LogWarning((object)"[战场分析基站配送支持] 送货失败: entityIdField 为 null");
						}
					}
					return false;
				}
				int num = (int)field2.GetValue(val.storage.bottomStorage);
				if (num <= 0)
				{
					if (Plugin.DebugLog())
					{
						ManualLogSource? log7 = Plugin.Log;
						if (log7 != null)
						{
							log7.LogWarning((object)"[战场分析基站配送支持] 送货失败: bottomStorage.entityId 无效");
						}
					}
					return false;
				}
				int num2 = default(int);
				int num3 = factory.InsertIntoStorage(num, itemId, count, inc, ref num2, true);
				int num4 = count - num3;
				if (num4 > 0)
				{
					FieldInfo field3 = ((object)val).GetType().GetField("holdupPackage", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					FieldInfo field4 = ((object)val).GetType().GetField("holdupItemCount", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (field3 != null && field4 != null)
					{
						Array array2 = field3.GetValue(val) as Array;
						int num5 = (int)field4.GetValue(val);
						if (array2 != null && num5 < array2.Length)
						{
							bool flag = false;
							for (int i = 0; i < num5; i++)
							{
								object value2 = array2.GetValue(i);
								if (value2 == null)
								{
									continue;
								}
								FieldInfo field5 = value2.GetType().GetField("itemId");
								if (!(field5 != null) || (int)field5.GetValue(value2) != itemId)
								{
									continue;
								}
								FieldInfo field6 = value2.GetType().GetField("count");
								FieldInfo field7 = value2.GetType().GetField("inc");
								if (!(field6 != null) || !(field7 != null))
								{
									continue;
								}
								int num6 = (int)field6.GetValue(value2);
								int num7 = (int)field7.GetValue(value2);
								field6.SetValue(value2, num6 + num4);
								field7.SetValue(value2, num7 + num2);
								array2.SetValue(value2, i);
								flag = true;
								if (Plugin.DebugLog())
								{
									string itemName = GetItemName(itemId);
									ManualLogSource? log8 = Plugin.Log;
									if (log8 != null)
									{
										log8.LogInfo((object)string.Format("[{0}] \ud83d\udce6 送货到缓存区: 配送器[{1}] 物品={2}(ID:{3}) 直接插入={4} 缓存={5}", "战场分析基站配送支持", dispenserId, itemName, itemId, num3, num4));
									}
								}
								break;
							}
							if (!flag)
							{
								Type elementType = array2.GetType().GetElementType();
								if (elementType != null)
								{
									object obj = Activator.CreateInstance(elementType);
									FieldInfo field8 = obj.GetType().GetField("itemId");
									FieldInfo field9 = obj.GetType().GetField("count");
									FieldInfo field10 = obj.GetType().GetField("inc");
									if (field8 != null && field9 != null && field10 != null)
									{
										field8.SetValue(obj, itemId);
										field9.SetValue(obj, num4);
										field10.SetValue(obj, num2);
										array2.SetValue(obj, num5);
										field4.SetValue(val, num5 + 1);
										if (Plugin.DebugLog())
										{
											string itemName2 = GetItemName(itemId);
											ManualLogSource? log9 = Plugin.Log;
											if (log9 != null)
											{
												log9.LogInfo((object)string.Format("[{0}] \ud83d\udce6 送货到缓存区(新增): 配送器[{1}] 物品={2}(ID:{3}) 直接插入={4} 缓存={5}", "战场分析基站配送支持", dispenserId, itemName2, itemId, num3, num4));
											}
										}
									}
								}
							}
						}
					}
				}
				else if (Plugin.DebugLog())
				{
					string itemName3 = GetItemName(itemId);
					ManualLogSource? log10 = Plugin.Log;
					if (log10 != null)
					{
						log10.LogInfo((object)string.Format("[{0}] \ud83d\udcec 送货成功(直接插入): 配送器[{1}] 物品={2}(ID:{3})x{4}", "战场分析基站配送支持", dispenserId, itemName3, itemId, count));
					}
				}
				val.pulseSignal = 2;
				return true;
			}
			catch (Exception ex)
			{
				ManualLogSource? log11 = Plugin.Log;
				if (log11 != null)
				{
					log11.LogError((object)("[战场分析基站配送支持] DeliverToDispenser 异常: " + ex.Message + "\n" + ex.StackTrace));
				}
				return false;
			}
		}

		private static void TakeItemFromDispenser(PlanetFactory factory, int dispenserId, int itemId, int maxCount, out int actualCount, out int inc)
		{
			actualCount = 0;
			inc = 0;
			try
			{
				DispenserComponent dispenser = BattleBaseLogisticsManager.GetDispenser(factory, dispenserId);
				if (dispenser?.storage?.bottomStorage == null)
				{
					return;
				}
				Type type = ((object)dispenser.storage.bottomStorage).GetType();
				MethodInfo method = type.GetMethod("TakeItem", BindingFlags.Instance | BindingFlags.Public);
				FieldInfo field = type.GetField("nextStorage", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (method == null)
				{
					return;
				}
				object obj = dispenser.storage.bottomStorage;
				int num = maxCount;
				int num2 = 0;
				while (obj != null && num > 0)
				{
					object[] array = new object[3] { itemId, num, 0 };
					if (method.Invoke(obj, array) is int num3 && num3 > 0)
					{
						actualCount += num3;
						num -= num3;
						num2 = (int)array[2];
					}
					obj = field?.GetValue(obj);
				}
				inc = num2;
			}
			catch (Exception ex)
			{
				ManualLogSource? log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)("[战场分析基站配送支持] TakeItemFromDispenser 异常: " + ex.Message));
				}
			}
		}

		private static void DeliverToBaseInputPartition(BattleBaseComponent battleBase, PlanetFactory factory, int itemId, int count, int inc)
		{
			try
			{
				if (battleBase != null && factory != null && itemId > 0 && count > 0)
				{
					int num = default(int);
					factory.InsertIntoStorage(battleBase.entityId, itemId, count, inc, ref num, true);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource? log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)("[战场分析基站配送支持] DeliverToBaseInputPartition 异常: " + ex.Message));
				}
			}
		}

		private static string GetItemName(int itemId)
		{
			try
			{
				ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select(itemId);
				if (val != null && !string.IsNullOrEmpty(((Proto)val).name))
				{
					return Localization.Translate(((Proto)val).name);
				}
			}
			catch
			{
			}
			return $"item_{itemId}";
		}
	}
	public class BaseLogisticSystem
	{
		public int battleBaseId;

		public int planetId;

		public CourierData[] couriers = (CourierData[])(object)new CourierData[20];

		public int idleCount = 20;

		public int workingCount;

		public Dictionary<int, int> lastInventory = new Dictionary<int, int>();

		public int cooldownCounter;

		public const int DISPATCH_INTERVAL = 60;

		public const float DRONE_AT_BASE_HEIGHT_OFFSET = 7.5f;

		public int CourierCapacity
		{
			get
			{
				CourierData[] array = couriers;
				if (array == null)
				{
					return 0;
				}
				return array.Length;
			}
		}
	}
	public class DispenserDemand
	{
		public int dispenserId;

		public int entityId;

		public int storageId;

		public int itemId;

		public int currentStock;

		public int maxStock;

		public float urgency;

		public Vector3 position;

		public float distance;

		public bool IsMechaSlot;

		public int slotIndex;

		public int needCount;

		public bool IsStationTower;

		public int stationId;

		public bool IsWarperStorageDemand;

		public int StationStorageIndex;

		public bool IsSupplyFetch;
	}
	public class DispatchContext
	{
		public List<DispenserDemand> Demands;

		public Dictionary<int, int> CurrentInventory;

		public Vector3 BasePosition;

		public DispatchContext(List<DispenserDemand> demands, Dictionary<int, int> currentInventory, Vector3 basePosition)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			Demands = demands;
			CurrentInventory = currentInventory;
			BasePosition = basePosition;
		}
	}
	public static class BattleBaseLogisticsManager
	{
		private static Dictionary<int, Dictionary<int, BaseLogisticSystem>> _systems = new Dictionary<int, Dictionary<int, BaseLogisticSystem>>();

		private static Dictionary<(int planetId, int battleBaseId, int itemId), int> _baseFetchInFlight = new Dictionary<(int, int, int), int>();

		private static object _inFlightLock = new object();

		private static object _lock = new object();

		private const int STATION_ENDID_OFFSET = 20000;

		private const int STATION_WARPER_STORAGE_ENDID_OFFSET = 30000;

		private const int ITEMID_WARPER = 1210;

		public static BaseLogisticSystem GetOrCreate(int planetId, int battleBaseId)
		{
			lock (_lock)
			{
				if (!_systems.ContainsKey(planetId))
				{
					_systems[planetId] = new Dictionary<int, BaseLogisticSystem>();
				}
				if (!_systems[planetId].ContainsKey(battleBaseId))
				{
					int battleBaseCourierCount = Plugin.GetBattleBaseCourierCount();
					_systems[planetId][battleBaseId] = new BaseLogisticSystem
					{
						battleBaseId = battleBaseId,
						planetId = planetId,
						couriers = (CourierData[])(object)new CourierData[battleBaseCourierCount],
						idleCount = battleBaseCourierCount,
						workingCount = 0
					};
				}
				return _systems[planetId][battleBaseId];
			}
		}

		public static IEnumerable<BaseLogisticSystem> GetAllForPlanet(int planetId)
		{
			lock (_lock)
			{
				if (_systems.TryGetValue(planetId, out Dictionary<int, BaseLogisticSystem> value))
				{
					return value.Values.ToList();
				}
				return Enumerable.Empty<BaseLogisticSystem>();
			}
		}

		public static bool HasWarperCourierInTransitToStation(int planetId, int stationId)
		{
			int num = 20000 + stationId;
			int num2 = 30000 + stationId;
			foreach (BaseLogisticSystem item in GetAllForPlanet(planetId))
			{
				if (item.couriers == null)
				{
					continue;
				}
				for (int i = 0; i < item.couriers.Length; i++)
				{
					ref CourierData reference = ref item.couriers[i];
					if (!(reference.maxt <= 0f) && !(reference.direction <= 0f) && reference.itemId == 1210 && (reference.endId == num || reference.endId == num2))
					{
						return true;
					}
				}
			}
			return false;
		}

		public static int GetIncomingToDispenser(int planetId, int dispenserId, int itemId)
		{
			if (dispenserId <= 0 || itemId <= 0)
			{
				return 0;
			}
			int num = 0;
			foreach (BaseLogisticSystem item in GetAllForPlanet(planetId))
			{
				if (item.couriers == null)
				{
					continue;
				}
				for (int i = 0; i < item.couriers.Length; i++)
				{
					ref CourierData reference = ref item.couriers[i];
					if (!(reference.maxt <= 0f) && !(reference.direction <= 0f) && reference.endId == dispenserId && reference.itemId == itemId)
					{
						num += reference.itemCount;
					}
				}
			}
			return num;
		}

		public static DispenserComponent? GetDispenser(PlanetFactory factory, int dispenserId)
		{
			if (factory?.transport == null || dispenserId <= 0)
			{
				return null;
			}
			PlanetTransport transport = factory.transport;
			FieldInfo field = ((object)transport).GetType().GetField("dispenserPool", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field == null)
			{
				return null;
			}
			if (!(field.GetValue(transport) is Array array) || dispenserId >= array.Length)
			{
				return null;
			}
			object? value = array.GetValue(dispenserId);
			DispenserComponent val = (DispenserComponent)((value is DispenserComponent) ? value : null);
			if (val == null || val.id != dispenserId)
			{
				return null;
			}
			return val;
		}

		public static void DecrementStationSlotLocalOrder(PlanetFactory factory, int stationId, int itemId, int amount)
		{
			if (factory?.transport == null || stationId <= 0 || itemId <= 0 || amount <= 0)
			{
				return;
			}
			StationComponent stationComponent = factory.transport.GetStationComponent(stationId);
			if (stationComponent?.storage == null)
			{
				return;
			}
			for (int i = 0; i < stationComponent.storage.Length; i++)
			{
				if (stationComponent.storage[i].itemId == itemId)
				{
					stationComponent.storage[i].localOrder -= amount;
					break;
				}
			}
		}

		public static int GetBaseFetchInFlight(int planetId, int battleBaseId, int itemId)
		{
			lock (_inFlightLock)
			{
				int value;
				return _baseFetchInFlight.TryGetValue((planetId, battleBaseId, itemId), out value) ? value : 0;
			}
		}

		public static void AddBaseFetchInFlight(int planetId, int battleBaseId, int itemId, int delta)
		{
			if (delta == 0)
			{
				return;
			}
			lock (_inFlightLock)
			{
				(int, int, int) key = (planetId, battleBaseId, itemId);
				int num = (_baseFetchInFlight.TryGetValue(key, out var value) ? value : 0);
				num += delta;
				if (num <= 0)
				{
					_baseFetchInFlight.Remove(key);
				}
				else
				{
					_baseFetchInFlight[key] = num;
				}
			}
		}

		public static void Clear(int planetId)
		{
			lock (_lock)
			{
				_systems.Remove(planetId);
				lock (_inFlightLock)
				{
					foreach (var item in (from kv in _baseFetchInFlight
						where kv.Key.planetId == planetId
						select kv.Key).ToList())
					{
						_baseFetchInFlight.Remove(item);
					}
				}
				if (Plugin.DebugLog())
				{
					ManualLogSource? log = Plugin.Log;
					if (log != null)
					{
						log.LogInfo((object)string.Format("[{0}] 清理基站物流系统:行星[{1}]", "战场分析基站配送支持", planetId));
					}
				}
			}
		}

		public static void ClearAll()
		{
			lock (_lock)
			{
				_systems.Clear();
				lock (_inFlightLock)
				{
					_baseFetchInFlight.Clear();
				}
				if (Plugin.DebugLog())
				{
					ManualLogSource? log = Plugin.Log;
					if (log != null)
					{
						log.LogInfo((object)"[战场分析基站配送支持] 清理所有基站物流系统");
					}
				}
			}
		}

		public static bool HasInventoryChanged(BaseLogisticSystem logistics, Dictionary<int, int> currentInventory)
		{
			if (logistics.lastInventory.Count != currentInventory.Count)
			{
				return true;
			}
			foreach (KeyValuePair<int, int> item in currentInventory)
			{
				if (!logistics.lastInventory.TryGetValue(item.Key, out var value) || value != item.Value)
				{
					return true;
				}
			}
			return false;
		}

		public static List<(int itemId, int needCount)> ScanBaseInputDemands(object battleBase, int planetId, int battleBaseId)
		{
			List<(int, int)> list = new List<(int, int)>();
			try
			{
				object obj = (battleBase?.GetType().GetField("storage", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))?.GetValue(battleBase);
				if (obj == null)
				{
					return list;
				}
				FieldInfo field = obj.GetType().GetField("size", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				FieldInfo field2 = obj.GetType().GetField("bans", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				FieldInfo field3 = obj.GetType().GetField("grids", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field == null || field2 == null || field3 == null)
				{
					return list;
				}
				int num2 = ((field.GetValue(obj) is int num) ? num : 0);
				int num4 = ((field2.GetValue(obj) is int num3) ? num3 : 0);
				int num5 = num2 - num4;
				if (num5 >= num2 || num4 <= 0)
				{
					return list;
				}
				if (!(field3.GetValue(obj) is Array array))
				{
					return list;
				}
				Dictionary<int, int> dictionary = new Dictionary<int, int>();
				for (int i = num5; i < num2; i++)
				{
					object value = array.GetValue(i);
					if (value == null)
					{
						continue;
					}
					FieldInfo field4 = value.GetType().GetField("filter");
					FieldInfo field5 = value.GetType().GetField("itemId");
					FieldInfo field6 = value.GetType().GetField("count");
					FieldInfo field7 = value.GetType().GetField("stackSize");
					if (field4 == null || field6 == null || field7 == null)
					{
						continue;
					}
					int num7 = ((field4.GetValue(value) is int num6) ? num6 : 0);
					int num9 = ((field5 != null && field5.GetValue(value) is int num8) ? num8 : num7);
					if (num9 <= 0)
					{
						num9 = num7;
					}
					if (num9 <= 0)
					{
						continue;
					}
					int num11 = ((field6.GetValue(value) is int num10) ? num10 : 0);
					int num13 = ((field7.GetValue(value) is int num12) ? num12 : 1000);
					if (num11 < num13)
					{
						int num14 = num13 - num11;
						if (!dictionary.ContainsKey(num9))
						{
							dictionary[num9] = 0;
						}
						dictionary[num9] += num14;
					}
				}
				foreach (KeyValuePair<int, int> item in dictionary)
				{
					int key = item.Key;
					int value2 = item.Value;
					int baseFetchInFlight = GetBaseFetchInFlight(planetId, battleBaseId, key);
					int num15 = Math.Max(0, value2 - baseFetchInFlight);
					if (num15 > 0)
					{
						list.Add((key, num15));
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource? log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)("[战场分析基站配送支持] ScanBaseInputDemands 异常: " + ex.Message));
				}
			}
			return list;
		}

		public static List<DispenserDemand> ScanSupplyDispensers(PlanetFactory factory, Vector3 basePosition, HashSet<int> neededItemIds)
		{
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Invalid comparison between Unknown and I4
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			List<DispenserDemand> list = new List<DispenserDemand>();
			if (neededItemIds == null || neededItemIds.Count == 0)
			{
				return list;
			}
			try
			{
				PlanetTransport val = factory?.transport;
				if (val == null)
				{
					return list;
				}
				FieldInfo field = ((object)val).GetType().GetField("dispenserPool", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				FieldInfo field2 = ((object)val).GetType().GetField("dispenserCursor", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field == null || field2 == null)
				{
					return list;
				}
				Array array = field.GetValue(val) as Array;
				object value = field2.GetValue(val);
				if (array == null || value == null)
				{
					return list;
				}
				int num = Convert.ToInt32(value);
				EntityData[] entityPool = factory.entityPool;
				if (entityPool == null)
				{
					return list;
				}
				for (int i = 1; i < num && i < array.Length; i++)
				{
					object value2 = array.GetValue(i);
					if (value2 == null)
					{
						continue;
					}
					DispenserComponent val2 = (DispenserComponent)((value2 is DispenserComponent) ? value2 : null);
					if (val2 == null || val2.id != i || (int)val2.storageMode != 1 || val2.filter <= 0 || !neededItemIds.Contains(val2.filter))
					{
						continue;
					}
					int dispenserStock = GetDispenserStock(val2, val2.filter);
					if (dispenserStock <= 0)
					{
						continue;
					}
					int num2 = Math.Max(0, -val2.storageOrdered);
					int num3 = Math.Max(0, dispenserStock - num2);
					if (num3 <= 0)
					{
						continue;
					}
					Vector3 val3 = Vector3.zero;
					if (val2.entityId > 0 && val2.entityId < entityPool.Length)
					{
						EntityData val4 = entityPool[val2.entityId];
						if (val4.id > 0)
						{
							val3 = val4.pos;
						}
					}
					float distance = Vector3.Distance(basePosition, val3);
					list.Add(new DispenserDemand
					{
						IsSupplyFetch = true,
						dispenserId = val2.id,
						entityId = val2.entityId,
						storageId = 0,
						itemId = val2.filter,
						currentStock = num3,
						maxStock = 0,
						needCount = 0,
						urgency = 0f,
						position = val3,
						distance = distance
					});
				}
				list.Sort((DispenserDemand a, DispenserDemand b) => a.distance.CompareTo(b.distance));
			}
			catch (Exception ex)
			{
				ManualLogSource? log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)("[战场分析基站配送支持] ScanSupplyDispensers 异常: " + ex.Message));
				}
			}
			return list;
		}

		public static List<DispenserDemand> ScanDispenserDemands(PlanetFactory factory, Vector3 basePosition, Dictionary<int, int> baseInventory)
		{
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Invalid comparison between Unknown and I4
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: 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_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: 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_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			List<DispenserDemand> list = new List<DispenserDemand>();
			try
			{
				if (factory == null)
				{
					return list;
				}
				PlanetTransport transport = factory.transport;
				if (transport == null)
				{
					return list;
				}
				FieldInfo field = ((object)transport).GetType().GetField("dispenserPool", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				FieldInfo field2 = ((object)transport).GetType().GetField("dispenserCursor", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field == null || field2 == null)
				{
					return list;
				}
				Array array = field.GetValue(transport) as Array;
				object value = field2.GetValue(transport);
				if (array == null || value == null)
				{
					return list;
				}
				int num = Convert.ToInt32(value);
				for (int i = 1; i < num && i < array.Length; i++)
				{
					object value2 = array.GetValue(i);
					if (value2 == null)
					{
						continue;
					}
					DispenserComponent val = (DispenserComponent)((value2 is DispenserComponent) ? value2 : null);
					if (val == null || val.id != i || (int)val.storageMode != 2 || val.filter <= 0 || val.holdupItemCount > 0 || !baseInventory.ContainsKey(val.filter) || baseInventory[val.filter] <= 0)
					{
						continue;
					}
					int dispenserStock = GetDispenserStock(val, val.filter);
					int dispenserMaxStock = GetDispenserMaxStock(val);
					int num2 = Math.Max(0, val.storageOrdered);
					if (dispenserMaxStock > 0 && dispenserStock + num2 >= dispenserMaxStock)
					{
						continue;
					}
					Vector3 val2 = Vector3.zero;
					EntityData[] entityPool = factory.entityPool;
					if (val.entityId > 0 && entityPool != null && val.entityId < entityPool.Length)
					{
						EntityData val3 = entityPool[val.entityId];
						if (val3.id > 0)
						{
							val2 = val3.pos;
						}
					}
					float distance = Vector3.Distance(basePosition, val2);
					float urgency = ((dispenserMaxStock > 0) ? ((float)(dispenserStock + num2) / (float)dispenserMaxStock) : 1f);
					int storageId = 0;
					if (val.storage?.bottomStorage != null)
					{
						FieldInfo field3 = ((object)val.storage.bottomStorage).GetType().GetField("id");
						if (field3 != null)
						{
							storageId = (int)field3.GetValue(val.storage.bottomStorage);
						}
					}
					list.Add(new DispenserDemand
					{
						dispenserId = val.id,
						entityId = val.entityId,
						storageId = storageId,
						itemId = val.filter,
						currentStock = dispenserStock,
						maxStock = dispenserMaxStock,
						urgency = urgency,
						position = val2,
						distance = distance
					});
				}
				list.Sort(delegate(DispenserDemand a, DispenserDemand b)
				{
					int num3 = a.urgency.CompareTo(b.urgency);
					return (num3 != 0) ? num3 : a.distance.CompareTo(b.distance);
				});
			}
			catch (Exception ex)
			{
				ManualLogSource? log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)("[战场分析基站配送支持] ScanDispenserDemands 异常: " + ex.Message));
				}
			}
			return list;
		}

		public static List<DispenserDemand> ScanStationDemands(PlanetFactory factory, Vector3 basePosition, Dictionary<int, int> baseInventory)
		{
			//IL_0090: 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_0097: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Invalid comparison between Unknown and I4
			//IL_00b1: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: 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)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: 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_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: 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_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: 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_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			List<DispenserDemand> list = new List<DispenserDemand>();
			try
			{
				if (factory == null)
				{
					return list;
				}
				PlanetTransport transport = factory.transport;
				if (transport == null)
				{
					return list;
				}
				StationComponent[] stationPool = transport.stationPool;
				if (stationPool == null)
				{
					return list;
				}
				int stationCursor = transport.stationCursor;
				EntityData[] entityPool = factory.entityPool;
				if (entityPool == null)
				{
					return list;
				}
				for (int i = 1; i < stationCursor && i < stationPool.Length; i++)
				{
					StationComponent val = stationPool[i];
					if (val == null || val.id != i || val.storage == null)
					{
						continue;
					}
					for (int j = 0; j < val.storage.Length; j++)
					{
						StationStore val2 = val.storage[j];
						if (val2.itemId <= 0 || (int)val2.localLogic != 2)
						{
							continue;
						}
						int num = val2.count + val2.localOrder;
						if (num >= val2.max || val2.max - num <= 0 || !baseInventory.ContainsKey(val2.itemId) || baseInventory[val2.itemId] <= 0)
						{
							continue;
						}
						Vector3 val3 = Vector3.zero;
						if (val.entityId > 0 && val.entityId < entityPool.Length)
						{
							EntityData val4 = entityPool[val.entityId];
							if (val4.id > 0)
							{
								val3 = val4.pos;
							}
						}
						float distance = Vector3.Distance(basePosition, val3);
						float urgency = ((val2.max > 0) ? ((float)num / (float)val2.max) : 1f);
						list.Add(new DispenserDemand
						{
							IsStationTower = true,
							stationId = val.id,
							StationStorageIndex = j,
							dispenserId = 0,
							entityId = val.entityId,
							storageId = 0,
							itemId = val2.itemId,
							currentStock = num,
							maxStock = val2.max,
							urgency = urgency,
							position = val3,
							distance = distance
						});
					}
					if (!val.isStellar || val.warperMaxCount <= 0 || val.warperCount >= val.warperMaxCount || !baseInventory.TryGetValue(1210, out var value) || value <= 0 || HasWarperCourierInTransitToStation(factory.planetId, val.id))
					{
						continue;
					}
					int needCount = val.warperMaxCount - val.warperCount;
					Vector3 val5 = Vector3.zero;
					if (val.entityId > 0 && val.entityId < entityPool.Length)
					{
						EntityData val6 = entityPool[val.entityId];
						if (val6.id > 0)
						{
							val5 = val6.pos;
						}
					}
					float distance2 = Vector3.Distance(basePosition, val5);
					float urgency2 = ((val.warperMaxCount > 0) ? ((float)val.warperCount / (float)val.warperMaxCount) : 1f);
					list.Add(new DispenserDemand
					{
						IsStationTower = true,
						stationId = val.id,
						IsWarperStorageDemand = true,
						dispenserId = 0,
						entityId = val.entityId,
						storageId = 0,
						itemId = 1210,
						currentStock = val.warperCount,
						maxStock = val.warperMaxCount,
						needCount = needCount,
						urgency = urgency2,
						position = val5,
						distance = distance2
					});
				}
				list.Sort(delegate(DispenserDemand a, DispenserDemand b)
				{
					int num2 = a.urgency.CompareTo(b.urgency);
					return (num2 != 0) ? num2 : a.distance.CompareTo(b.distance);
				});
			}
			catch (Exception ex)
			{
				ManualLogSource? log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)("[战场分析基站配送支持] ScanStationDemands 异常: " + ex.Message));
				}
			}
			return list;
		}

		public static List<DispenserDemand> ScanMechaDemands(PlanetFactory factory, Vector3 basePosition, Dictionary<int, int> baseInventory)
		{
			//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_00bf: 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_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			List<DispenserDemand> list = new List<DispenserDemand>();
			try
			{
				if (factory == null)
				{
					return list;
				}
				Player mainPlayer = GameMain.mainPlayer;
				if (mainPlayer == null || !mainPlayer.isAlive || mainPlayer.sailing)
				{
					return list;
				}
				DeliveryPackage deliveryPackage = mainPlayer.deliveryPackage;
				PlayerPackageUtility packageUtility = mainPlayer.packageUtility;
				if (deliveryPackage == null || packageUtility == null)
				{
					return list;
				}
				if (!deliveryPackage.unlockedAndEnabled)
				{
					return list;
				}
				PlanetData planet = factory.planet;
				if (planet == null || GameMain.localPlanet != planet || !planet.loaded || !planet.factoryLoaded)
				{
					return list;
				}
				GRID[] grids = deliveryPackage.grids;
				if (grids == null)
				{
					return list;
				}
				Vector3 position = mainPlayer.position;
				if (((Vector3)(ref position)).sqrMagnitude < 0.01f)
				{
					return list;
				}
				float distance = Vector3.Distance(basePosition, position);
				for (int i = 0; i < deliveryPackage.gridLength; i++)
				{
					if (!deliveryPackage.IsGridActive(i) || grids[i].itemId <= 0)
					{
						continue;
					}
					int itemId = grids[i].itemId;
					if (itemId == 1099 || !baseInventory.ContainsKey(itemId) || baseInventory[itemId] <= 0)
					{
						continue;
					}
					int num = grids[i].count + packageUtility.GetPackageItemCountIncludeHandItem(itemId);
					int clampedRequireCount = ((GRID)(ref grids[i])).clampedRequireCount;
					if (num < clampedRequireCount && ((GRID)(ref grids[i])).stackSizeModified - grids[i].count + packageUtility.GetPackageItemCapacity(itemId) > 0)
					{
						int num2 = clampedRequireCount - num;
						if (num2 > 0)
						{
							float urgency = ((clampedRequireCount > 0) ? ((float)num / (float)clampedRequireCount) : 1f);
							list.Add(new DispenserDemand
							{
								IsMechaSlot = true,
								slotIndex = i,
								needCount = num2,
								dispenserId = 0,
								entityId = 0,
								storageId = 0,
								itemId = itemId,
								currentStock = num,
								maxStock = clampedRequireCount,
								urgency = urgency,
								position = position,
								distance = distance
							});
						}
					}
				}
				list.Sort(delegate(DispenserDemand a, DispenserDemand b)
				{
					int num3 = a.urgency.CompareTo(b.urgency);
					return (num3 != 0) ? num3 : a.distance.CompareTo(b.distance);
				});
			}
			catch (Exception ex)
			{
				ManualLogSource? log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)("[战场分析基站配送支持] ScanMechaDemands 异常: " + ex.Message));
				}
			}
			return list;
		}

		public static DispatchContext? TryGetDispatchContext(BaseLogisticSystem logistics, object battleBase, PlanetFactory factory, int entityId)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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_0129: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: 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_0212: Unknown result type (might be due to invalid IL or missing references)
			if (logistics == null || battleBase == null || factory == null)
			{
				return null;
			}
			logistics.cooldownCounter++;
			if (logistics.cooldownCounter < 60)
			{
				return null;
			}
			logistics.cooldownCounter = 0;
			Dictionary<int, int> baseInventory = GetBaseInventory(battleBase);
			if (!HasInventoryChanged(logistics, baseInventory) && (logistics.idleCount <= 0 || baseInventory.Count == 0))
			{
				return null;
			}
			if (logistics.idleCount <= 0)
			{
				return null;
			}
			Vector3 basePosition = Vector3.zero;
			if (entityId >= 0 && factory.entityPool != null && entityId < factory.entityPool.Length)
			{
				EntityData val = factory.entityPool[entityId];
				Vector3 val2 = ((((Vector3)(ref val.pos)).sqrMagnitude < 1E-06f) ? Vector3.up : ((Vector3)(ref val.pos)).normalized);
				basePosition = val.pos + val2 * 7.5f;
			}
			List<DispenserDemand> list = ScanMechaDemands(factory, basePosition, baseInventory);
			List<DispenserDemand> list2 = ScanStationDemands(factory, basePosition, baseInventory);
			List<DispenserDemand> list3 = ScanDispenserDemands(factory, basePosition, baseInventory);
			int planetId = factory.planetId;
			int battleBaseId = logistics.battleBaseId;
			List<(int itemId, int needCount)> list4 = ScanBaseInputDemands(battleBase, planetId, battleBaseId);
			HashSet<int> neededItemIds = new HashSet<int>(list4.Select(((int itemId, int needCount) x) => x.itemId));
			List<DispenserDemand> list5 = ScanSupplyDispensers(factory, basePosition, neededItemIds);
			List<DispenserDemand> list6 = new List<DispenserDemand>();
			int battleBaseCourierCarryCapacity = Plugin.GetBattleBaseCourierCarryCapacity();
			foreach (var (num, num2) in list4)
			{
				if (num2 <= 0)
				{
					continue;
				}
				foreach (DispenserDemand item in list5)
				{
					if (item.itemId == num)
					{
						int num3 = Math.Min(num2, Math.Min(battleBaseCourierCarryCapacity, item.currentStock));
						if (num3 > 0)
						{
							list6.Add(new DispenserDemand
							{
								IsSupplyFetch = true,
								dispenserId = item.dispenserId,
								entityId = item.entityId,
								storageId = 0,
								itemId = num,
								currentStock = item.currentStock,
								maxStock = 0,
								needCount = num3,
								urgency = 1f,
								position = item.position,
								distance = item.distance
							});
							break;
						}
					}
				}
			}
			List<DispenserDemand> list7 = new List<DispenserDemand>(list.Count + list2.Count + list3.Count + list6.Count);
			list7.AddRange(list);
			list7.AddRange(list2);
			list7.AddRange(list3);
			list7.AddRange(list6);
			list7.Sort(delegate(DispenserDemand a, DispenserDemand b)
			{
				int num4 = ((!a.IsMechaSlot) ? (a.IsStationTower ? 2 : ((!a.IsSupplyFetch) ? 1 : 3)) : 0);
				int value = ((!b.IsMechaSlot) ? (b.IsStationTower ? 2 : ((!b.IsSupplyFetch) ? 1 : 3)) : 0);
				int num5 = num4.CompareTo(value);
				if (num5 != 0)
				{
					return num5;
				}
				if (a.IsStationTower && b.IsStationTower && a.stationId == b.stationId && a.itemId == 1210 && b.itemId == 1210 && a.IsWarperStorageDemand != b.IsWarperStorageDemand)
				{
					if (!a.IsWarperStorageDemand)
					{
						return 1;
					}
					return -1;
				}
				int num6 = a.urgency.CompareTo(b.urgency);
				return (num6 != 0) ? num6 : a.distance.CompareTo(b.distance);
			});
			if (list7.Count == 0)
			{
				logistics.lastInventory = new Dictionary<int, int>(baseInventory);
				return null;
			}
			return new DispatchContext(list7, baseInventory, basePosition);
		}

		public static int GetDispenserStockPublic(DispenserComponent dispenser, int itemId)
		{
			return GetDispenserStock(dispenser, itemId);
		}

		private static int GetDispenserStock(DispenserComponent dispenser, int itemId)
		{
			try
			{
				if (dispenser.storage?.bottomStorage == null)
				{
					return 0;
				}
				Type type = ((object)dispenser.storage.bottomStorage).GetType();
				FieldInfo field = type.GetField("grids", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				FieldInfo field2 = type.GetField("nextStorage", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field == null)
				{
					return 0;
				}
				int num = 0;
				for (object obj = dispenser.storage.bottomStorage; obj != null; obj = field2?.GetValue(obj))
				{
					if (field.GetValue(obj) is Array array)
					{
						for (int i = 0; i < array.Length; i++)
						{
							object value = array.GetValue(i);
							if (value != null)
							{
								FieldInfo field3 = value.GetType().GetField("itemId");
								FieldInfo field4 = value.GetType().GetField("count");
								int num2 = ((field3 != null) ? ((int)field3.GetValue(value)) : 0);
								int num3 = ((field4 != null) ? ((int)field4.GetValue(value)) : 0);
								if (num2 == itemId)
								{
									num += num3;
								}
							}
						}
					}
				}
				return num;
			}
			catch
			{
				return 0;
			}
		}

		private static int GetDispenserMaxStock(DispenserComponent dispenser)
		{
			try
			{
				if (dispenser.storage?.bottomStorage == null)
				{
					return 0;
				}
				Type type = ((object)dispenser.storage.bottomStorage).GetType();
				FieldInfo field = type.GetField("size", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				FieldInfo field2 = type.GetField("bans", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				FieldInfo field3 = type.GetField("nextStorage", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field == null || field2 == null)
				{
					return 0;
				}
				int num = 0;
				for (object obj = dispenser.storage.bottomStorage; obj != null; obj = field3?.GetValue(obj))
				{
					int num3 = ((field.GetValue(obj) is int num2) ? num2 : 0);
					int num5 = ((field2.GetValue(obj) is int num4) ? num4 : 0);
					num += Math.Max(0, num3 - num5);
				}
				if (num == 0)
				{
					return 0;
				}
				int num6 = 1000;
				ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select(dispenser.filter);
				if (val != null)
				{
					num6 = val.StackSize;
				}
				return num * num6;
			}
			catch
			{
				return 0;
			}
		}

		public static Dictionary<int, int