Decompiled source of LogisticsStationSlots v1.0.3

BepInEx/plugins/LogisticsStationSlots.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using xiaoye97;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3")]
[assembly: AssemblyMetadata("AI_Assisted_Creation", "This assembly was partially or fully created with the assistance of Generative AI (e.g., Code Suggestions, Refactoring, Documentation Generation).")]
[assembly: AssemblyMetadata("AI_Model_Vendor", "DeepSeek")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.3.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 LogisticsStationSlots
{
	[HarmonyPatch]
	internal static class ControlPanelStoragePaging
	{
		private sealed class PageState
		{
			public int Page;

			public int LastStationId = -1;

			public Canvas Canvas;

			public int DiagCount;

			public float LastScroll;
		}

		private const int DefaultPageSize = 6;

		private const int MaxDiagLogs = 6;

		private static int _pageSize = 6;

		private static readonly ConditionalWeakTable<StationComponent, PageState> _states = new ConditionalWeakTable<StationComponent, PageState>();

		private static float _nextPageTime;

		private static Text _pageLabel;

		private static UIControlPanelStationInspector _lastInspector;

		private static UIControlPanelStationStorage[] _lastUis;

		private static FieldInfo _fStorageUIs;

		private static FieldInfo _fStation;

		private static FieldInfo _fFactory;

		private static FieldInfo _fWidgetStation;

		private static bool _fieldsTried;

		private static bool EnsureFields()
		{
			if (_fieldsTried)
			{
				if (_fStorageUIs != null && _fStation != null)
				{
					return _fFactory != null;
				}
				return false;
			}
			_fieldsTried = true;
			try
			{
				Type? typeFromHandle = typeof(UIControlPanelStationInspector);
				_fStorageUIs = AccessTools.Field(typeFromHandle, "storageUIs");
				_fStation = AccessTools.Field(typeFromHandle, "station");
				_fFactory = AccessTools.Field(typeFromHandle, "factory");
				_fWidgetStation = AccessTools.Field(typeof(UIControlPanelStationStorage), "station");
			}
			catch (Exception ex)
			{
				LogisticsStationSlotsPlugin.Log.LogWarning((object)("总控面板储物栏翻页:取字段失败 " + ex.Message));
			}
			if (_fStorageUIs == null || _fStation == null || _fFactory == null)
			{
				LogisticsStationSlotsPlugin.Log.LogWarning((object)"总控面板储物栏翻页:原版字段名不匹配(storageUIs / station / factory),本功能停用");
			}
			if (_fStorageUIs != null && _fStation != null)
			{
				return _fFactory != null;
			}
			return false;
		}

		private static bool Enabled()
		{
			ConfigEntry<bool> stationControlPanelPaging = LogisticsStationSlotsPlugin.StationControlPanelPaging;
			if (stationControlPanelPaging == null || !stationControlPanelPaging.Value)
			{
				return false;
			}
			return LogisticsStationSlotsPlugin.StationEnabled?.Value ?? false;
		}

		private static int ValidCount(StationComponent station)
		{
			if (station.isCollector || station.isVeinCollector)
			{
				if (station.collectionIds != null)
				{
					return station.collectionIds.Length;
				}
				return 0;
			}
			if (station.storage != null)
			{
				return station.storage.Length;
			}
			return 0;
		}

		private static PageState StateOf(StationComponent station)
		{
			if (!_states.TryGetValue(station, out var value))
			{
				value = new PageState();
				_states.Add(station, value);
			}
			return value;
		}

		private static int ClampPage(PageState state, int valid)
		{
			int num = ((valid > _pageSize) ? ((valid - 1) / _pageSize) : 0);
			if (state.Page > num)
			{
				state.Page = num;
			}
			if (state.Page < 0)
			{
				state.Page = 0;
			}
			return state.Page;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(UIControlPanelStationStorage), "SetData")]
		private static void SetData_Prefix(StationComponent __1, ref int __2)
		{
			if (!Enabled() || __1 == null)
			{
				return;
			}
			int num = ValidCount(__1);
			if (num <= _pageSize)
			{
				return;
			}
			int num2 = ClampPage(StateOf(__1), num);
			if (num2 > 0)
			{
				int num3 = num2 * _pageSize + __2;
				if (num3 < num)
				{
					__2 = num3;
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIControlPanelStationInspector), "_OnUpdate")]
		private static void OnUpdate_Postfix(UIControlPanelStationInspector __instance)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			if (!Enabled() || !EnsureFields())
			{
				return;
			}
			object value = _fStation.GetValue(__instance);
			StationComponent val = (StationComponent)((value is StationComponent) ? value : null);
			UIControlPanelStationStorage[] array = _fStorageUIs.GetValue(__instance) as UIControlPanelStationStorage[];
			if (val == null || array == null || array.Length == 0)
			{
				return;
			}
			_pageSize = array.Length;
			int num = ValidCount(val);
			if (num <= _pageSize)
			{
				_lastInspector = null;
				_lastUis = null;
				if ((Object)_pageLabel != (Object)null)
				{
					PageIndicator.Update(_pageLabel, 0, 0);
				}
				return;
			}
			_lastInspector = __instance;
			_lastUis = array;
			PageState pageState = StateOf(val);
			if (pageState.LastStationId != val.id)
			{
				pageState.LastStationId = val.id;
				pageState.Page = 0;
			}
			EnsurePageLabel(__instance, array);
			PageIndicator.Update(_pageLabel, pageState.Page, (num - 1) / _pageSize);
			int num2 = 0;
			if (Input.GetKeyDown((KeyCode)281))
			{
				num2 = 1;
			}
			else if (Input.GetKeyDown((KeyCode)280))
			{
				num2 = -1;
			}
			if (num2 == 0)
			{
				float y = Input.mouseScrollDelta.y;
				if (y == 0f)
				{
					pageState.LastScroll = 0f;
					return;
				}
				if (y == pageState.LastScroll)
				{
					return;
				}
				pageState.LastScroll = y;
				Diag_(__instance, pageState, array, num, y);
				if (Input.GetMouseButton(0) || Time.unscaledTime < _nextPageTime || !StorageShowingStation(val, array) || !MouseOverStorage(__instance, pageState, array))
				{
					return;
				}
				num2 = ((!(y > 0f)) ? 1 : (-1));
				_nextPageTime = Time.unscaledTime + 0.05f;
			}
			if (num2 != 0)
			{
				int num3 = ClampPage(pageState, num);
				pageState.Page = num3 + num2;
				pageState.Page = ClampPage(pageState, num);
				if (pageState.Page != num3)
				{
					_nextPageTime = Time.unscaledTime + 0.15f;
					Rebind(__instance, val, array);
					LogisticsStationSlotsPlugin.Log.LogInfo((object)$"总控面板储物栏翻页:第 {num3 + 1} → {pageState.Page + 1} 页(共 {(num + _pageSize - 1) / _pageSize} 页)");
				}
			}
		}

		private static void EnsurePageLabel(UIControlPanelStationInspector inspector, UIControlPanelStationStorage[] uis)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)_pageLabel != (Object)null) && !((Object)inspector == (Object)null) && uis != null && uis.Length != 0 && !((Object)uis[0] == (Object)null))
			{
				Transform transform = ((Component)inspector).transform;
				RectTransform val = (RectTransform)((transform is RectTransform) ? transform : null);
				Text componentInChildren = ((Component)uis[0]).GetComponentInChildren<Text>(true);
				if (!((Object)val == (Object)null) && !((Object)componentInChildren == (Object)null))
				{
					_pageLabel = PageIndicator.Create("beltstation-cpanel-page-label", val, componentInChildren, new Vector2(0f, -22f), (TextAnchor)4, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f));
				}
			}
		}

		internal static bool CursorOverPagingArea()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Expected O, but got Unknown
			UIControlPanelStationInspector lastInspector = _lastInspector;
			UIControlPanelStationStorage[] lastUis = _lastUis;
			if ((Object)lastInspector == (Object)null || lastUis == null || lastUis.Length == 0)
			{
				return false;
			}
			if ((Object)((Component)lastInspector).gameObject == (Object)null || !((Component)lastInspector).gameObject.activeInHierarchy)
			{
				return false;
			}
			if (_fStation == null)
			{
				return false;
			}
			StationComponent station = (StationComponent)_fStation.GetValue(lastInspector);
			if (!StorageShowingStation(station, lastUis))
			{
				return false;
			}
			return MouseOverStorage(lastInspector, StateOf(station), lastUis);
		}

		private static bool StorageShowingStation(StationComponent station, UIControlPanelStationStorage[] uis)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			if (_fWidgetStation == null)
			{
				return true;
			}
			for (int i = 0; i < uis.Length; i++)
			{
				if ((Object)uis[i] == (Object)null)
				{
					continue;
				}
				try
				{
					if (_fWidgetStation.GetValue(uis[i]) == station)
					{
						return true;
					}
				}
				catch
				{
					return true;
				}
			}
			return false;
		}

		private static bool MouseOverStorage(UIControlPanelStationInspector inspector, PageState state, UIControlPanelStationStorage[] uis)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			Camera val = CameraFor((Component)inspector, state);
			Vector2 val2 = Vector2.op_Implicit(Input.mousePosition);
			for (int i = 0; i < uis.Length; i++)
			{
				if (!((Object)uis[i] == (Object)null) && ((Component)uis[i]).gameObject.activeInHierarchy)
				{
					Transform transform = ((Component)uis[i]).transform;
					RectTransform val3 = (RectTransform)((transform is RectTransform) ? transform : null);
					if ((Object)val3 != (Object)null && RectTransformUtility.RectangleContainsScreenPoint(val3, val2, val))
					{
						return true;
					}
				}
			}
			return false;
		}

		private static Camera CameraFor(Component c, PageState state)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)state.Canvas == (Object)null)
			{
				state.Canvas = c.GetComponentInParent<Canvas>();
			}
			Canvas canvas = state.Canvas;
			if (!((Object)canvas != (Object)null) || (int)canvas.renderMode == 0)
			{
				return null;
			}
			return canvas.worldCamera;
		}

		private static void Rebind(UIControlPanelStationInspector inspector, StationComponent station, UIControlPanelStationStorage[] uis)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			object value = _fFactory.GetValue(inspector);
			PlanetFactory val = (PlanetFactory)((value is PlanetFactory) ? value : null);
			if (val == null)
			{
				return;
			}
			int num = ValidCount(station);
			int num2 = StateOf(station).Page * _pageSize;
			try
			{
				for (int i = 0; i < uis.Length; i++)
				{
					UIControlPanelStationStorage val2 = uis[i];
					if ((Object)val2 == (Object)null)
					{
						continue;
					}
					if (num2 + i < num)
					{
						if (!((Component)val2).gameObject.activeSelf)
						{
							((Component)val2).gameObject.SetActive(true);
						}
						val2.SetData(val, station, i);
					}
					else if (((Component)val2).gameObject.activeSelf)
					{
						((Component)val2).gameObject.SetActive(false);
					}
				}
			}
			catch (Exception ex)
			{
				LogisticsStationSlotsPlugin.Log.LogWarning((object)("总控面板储物栏翻页刷新失败: " + ex.Message));
			}
		}

		private static void Diag_(UIControlPanelStationInspector inspector, PageState state, UIControlPanelStationStorage[] uis, int valid, float scroll)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			//IL_00b3: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Expected O, but got Unknown
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Expected O, but got Unknown
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Expected O, but got Unknown
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Expected O, but got Unknown
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: 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_02cd: Unknown result type (might be due to invalid IL or missing references)
			if ((scroll == 0f && state.DiagCount > 0) || state.DiagCount >= 6)
			{
				return;
			}
			state.DiagCount++;
			StringBuilder stringBuilder = new StringBuilder();
			Canvas val = (((Object)state.Canvas != (Object)null) ? state.Canvas : (state.Canvas = ((Component)inspector).GetComponentInParent<Canvas>()));
			Camera val2 = CameraFor((Component)inspector, state);
			Vector2 val3 = Vector2.op_Implicit(Input.mousePosition);
			StringBuilder stringBuilder2 = stringBuilder.Append("总控面板翻页诊断:valid=").Append(valid).Append(" pageSize=")
				.Append(_pageSize)
				.Append(" canvas=");
			object obj = (((Object)val == (Object)null) ? "无" : ((object)val.renderMode/*cast due to .constrained prefix*/).ToString());
			stringBuilder2.Append((string)obj).Append(" camera=").Append(((Object)val2 == (Object)null) ? "null" : ((Object)val2).name)
				.Append(" 鼠标=")
				.Append(val3.x.ToString("F0"))
				.Append(',')
				.Append(val3.y.ToString("F0"))
				.Append(" VFInput=")
				.Append(VFInput.mouseWheel.ToString("F2"))
				.Append(" rawScroll=")
				.Append(Input.mouseScrollDelta.y.ToString("F2"))
				.Append(" 按住左键=")
				.Append(Input.GetMouseButton(0));
			for (int i = 0; i < uis.Length && i < 3; i++)
			{
				UIControlPanelStationStorage val4 = uis[i];
				if (!((Object)val4 == (Object)null))
				{
					Transform transform = ((Component)val4).transform;
					RectTransform val5 = (RectTransform)((transform is RectTransform) ? transform : null);
					if (!((Object)val5 == (Object)null))
					{
						Vector3 val6 = Vector2.op_Implicit(RectTransformUtility.WorldToScreenPoint(val2, ((Transform)val5).position));
						stringBuilder.Append("\n  #").Append(i).Append(" active=")
							.Append(((Component)val4).gameObject.activeInHierarchy)
							.Append(" 中心屏幕坐标=")
							.Append(val6.x.ToString("F0"))
							.Append(',')
							.Append(val6.y.ToString("F0"))
							.Append(" sizeDelta=")
							.Append(val5.sizeDelta.x.ToString("F0"))
							.Append('x')
							.Append(val5.sizeDelta.y.ToString("F0"))
							.Append(" 命中=")
							.Append(RectTransformUtility.RectangleContainsScreenPoint(val5, val3, val2));
					}
				}
			}
			LogisticsStationSlotsPlugin.Log.LogInfo((object)stringBuilder.ToString());
		}
	}
	internal static class PageIndicator
	{
		private static readonly HashSet<string> _logged = new HashSet<string>();

		internal static Text Create(string name, RectTransform anchor, Text fontSource, Vector2 offset, TextAnchor alignment, Vector2 anchorRef, Vector2 pivot)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_0050: Expected O, but got Unknown
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Expected O, but got Unknown
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Expected O, but got Unknown
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Expected O, but got Unknown
			//IL_017a: 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)
			if ((Object)anchor == (Object)null)
			{
				return null;
			}
			Font val = ResolveFont(fontSource, anchor);
			GameObject val2 = new GameObject(name, new Type[2]
			{
				typeof(RectTransform),
				typeof(Text)
			});
			val2.transform.SetParent((Transform)anchor, false);
			RectTransform val3 = (RectTransform)val2.transform;
			val3.anchorMin = anchorRef;
			val3.anchorMax = anchorRef;
			val3.pivot = pivot;
			val3.anchoredPosition = offset;
			val3.sizeDelta = new Vector2(90f, 30f);
			((Transform)val3).SetAsLastSibling();
			Text component = val2.GetComponent<Text>();
			component.font = val;
			component.fontSize = (((Object)fontSource != (Object)null && fontSource.fontSize > 0) ? fontSource.fontSize : 14);
			component.fontStyle = (FontStyle)(((Object)fontSource != (Object)null) ? ((int)fontSource.fontStyle) : 0);
			component.alignment = alignment;
			((Graphic)component).color = new Color(0.75f, 0.88f, 1f, 0.95f);
			((Graphic)component).raycastTarget = false;
			component.verticalOverflow = (VerticalWrapMode)1;
			component.text = string.Empty;
			if (_logged.Add(name))
			{
				Rect rect = anchor.rect;
				LogisticsStationSlotsPlugin.Log.LogInfo((object)(string.Format("页码标识已创建:{0} font={1} size={2}", name, ((Object)val == (Object)null) ? "NULL" : ((Object)val).name, component.fontSize) + $" anchoredPos=({val3.anchoredPosition.x:F0},{val3.anchoredPosition.y:F0})" + $" anchorSize=({((Rect)(ref rect)).width:F0}x{((Rect)(ref rect)).height:F0}) parent={((Object)anchor).name}"));
			}
			if ((Object)val == (Object)null)
			{
				LogisticsStationSlotsPlugin.Log.LogWarning((object)"页码标识:找不到可用字体,文字不会显示");
			}
			return component;
		}

		internal static void Update(Text label, int page, int maxPage)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			if ((Object)label == (Object)null)
			{
				return;
			}
			bool flag = maxPage > 0;
			if (((Component)label).gameObject.activeSelf != flag)
			{
				((Component)label).gameObject.SetActive(flag);
			}
			if (flag)
			{
				string text = page + 1 + "/" + (maxPage + 1);
				if (label.text != text)
				{
					label.text = text;
				}
			}
		}

		private static Font ResolveFont(Text source, RectTransform anchor)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			if ((Object)source != (Object)null && (Object)source.font != (Object)null)
			{
				return source.font;
			}
			Transform val = (Transform)anchor;
			int num = 0;
			while (num < 8 && (Object)val != (Object)null)
			{
				Text[] componentsInChildren = ((Component)val).GetComponentsInChildren<Text>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					if ((Object)componentsInChildren[i] != (Object)null && (Object)componentsInChildren[i].font != (Object)null)
					{
						return componentsInChildren[i].font;
					}
				}
				num++;
				val = val.parent;
			}
			return null;
		}
	}
	[BepInPlugin("local.logisticsstationslots", "LogisticsStationSlots", "1.0.3")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class LogisticsStationSlotsPlugin : BaseUnityPlugin
	{
		public const string Guid = "local.logisticsstationslots";

		public const string PluginName = "LogisticsStationSlots";

		public const string PluginVersion = "1.0.3";

		private const string LDBToolGuid = "me.xiaoye97.plugin.Dyson.LDBTool";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> StationEnabled;

		internal static ConfigEntry<int> StationMaxItemKinds;

		internal static ConfigEntry<bool> StationExtraSlotInput;

		internal static ConfigEntry<bool> StationControlPanelPaging;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			StationEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Station", "Enabled", true, "启用物流站扩容。 | Enable logistics station expansion.");
			StationMaxItemKinds = ((BaseUnityPlugin)this).Config.Bind<int>("Station", "MaxItemKinds", 12, "物流站的货物栏数。原版货物栏:物流运输站(2103) 4 格、星际物流运输站(2104) 5 格(星际站另有 1 个空间翘曲器专用格,不计入货物栏;界面上会各多显示 1 格)。超过 6 格时本插件会接管 AddItem、四个供需查询、悬停图标数组和面板分页——那几处原版按固定格数写死,不接管的话多出来的格位货物入库会凭空消失。★ 本插件不改单格库存上限,那个值请在物流站面板上自己设。 | Vanilla cargo slots: 4 for 2103, 5 for 2104 (the interstellar station also has one dedicated space-warper slot, not counted). Above 6 the plugin takes over AddItem, the four supply/demand queries, the hover icon array and window paging. Per-slot capacity is NOT touched - set it in the station panel yourself.");
			StationExtraSlotInput = ((BaseUnityPlugin)this).Config.Bind<bool>("Station", "FixExtraSlotInput", true, "★ 修「扩容出来的额外格位,外接传送带喂不进物品」。\n原版把 needs 数组写死成 6 项:needs[0..4] 对应 storage[0..4],needs[5] 是空间翘曲器专用槽(走 warperCount,不落在 storage 里);而三个消费端(UpdateNeeds 的写入、UpdateInputSlots 的「有没有格位要货」求和、CargoPath.TryPickItemAtRear 的物品匹配)全都只认这 6 项。\n后果:storage 索引 5 起的格位没有任何 needs 槽位可用 —— 外接传送带一律喂不进去(无人机/运输船不受影响,它们走 AddItem)。\n本项开启时不动原版那张需求表,而是在原版跑完之后,用插件自己的一张表再问传送带一轮,专门服务额外格位 —— 原版前 5 格的行为一个字节都不受影响。\n关掉 = 回到原状(额外格位只能靠无人机/运输船入库)。 | Fix belt input for the expanded slots. The plugin asks the belt once more with its own demand table after vanilla has run, so vanilla's own slots are never disturbed. Off = vanilla behaviour.");
			StationControlPanelPaging = ((BaseUnityPlugin)this).Config.Bind<bool>("Station", "ControlPanelPaging", true, "让总控制面板里的物流站储物栏也能看到扩容出来的第 7~12 格。\n物流站有两套互不相干的界面:它自己的面板(UIStationWindow,本插件已改为翻页)和总控制面板(UIControlPanel*,原版只显示前 6 格、而且右侧没有滚动条)。\n本项不改任何排版(格位尺寸、坐标、页面高度全不动),只把 6 个格位控件的「索引」整体平移一页:在储物栏区域滚鼠标滚轮翻页,第 2 页显示第 7~12 格。\n关掉 = 总控面板回到只显示前 6 格。 | Let the Total Control Panel's station view page through all expanded slots with the mouse wheel. Off = vanilla (first 6 slots only).");
			_harmony = new Harmony("local.logisticsstationslots");
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			StationPatches.LoadConfig();
			LDBTool.PostAddDataAction = (Action)Delegate.Combine(LDBTool.PostAddDataAction, new Action(OnPostAddData));
			Log.LogInfo((object)"LogisticsStationSlots v1.0.3 已加载 / loaded.");
		}

		private static void OnPostAddData()
		{
			try
			{
				StationPatches.ApplyPrefab();
			}
			catch (Exception ex)
			{
				Log.LogError((object)("物流站扩容失败 / station expand failed: " + ex));
			}
		}

		private void OnDestroy()
		{
			try
			{
				LDBTool.PostAddDataAction = (Action)Delegate.Remove(LDBTool.PostAddDataAction, new Action(OnPostAddData));
				if (_harmony != null)
				{
					_harmony.UnpatchSelf();
					_harmony = null;
				}
			}
			catch (Exception ex)
			{
				if (Log != null)
				{
					Log.LogWarning((object)("OnDestroy: " + ex.Message));
				}
			}
		}
	}
	[HarmonyPatch]
	internal static class StationInputSlotFix
	{
		private const int FirstExtraSlot = 5;

		private const int BatchSize = 6;

		[ThreadStatic]
		private static int[] _demand;

		[ThreadStatic]
		private static int[] _owner;

		[ThreadStatic]
		private static int _rotate;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StationComponent), "UpdateInputSlots")]
		private static void UpdateInputSlots_Postfix(StationComponent __instance, CargoTraffic __0)
		{
			ConfigEntry<bool> stationExtraSlotInput = LogisticsStationSlotsPlugin.StationExtraSlotInput;
			if (stationExtraSlotInput == null || !stationExtraSlotInput.Value)
			{
				return;
			}
			StationStore[] storage = __instance.storage;
			if (storage != null && storage.Length > 5)
			{
				int num = CollectDemand(storage, storage.Length - 5);
				if (num != 0)
				{
					FeedFromBelts(__instance, __0, storage, num);
				}
			}
		}

		private static int CollectDemand(StationStore[] storage, int extraSlots)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			if (_demand == null)
			{
				_demand = new int[6];
				_owner = new int[6];
			}
			Array.Clear(_demand, 0, 6);
			Array.Clear(_owner, 0, 6);
			int num = (_rotate % extraSlots + extraSlots) % extraSlots;
			int num2 = 0;
			for (int i = 0; i < extraSlots; i++)
			{
				if (num2 >= 6)
				{
					break;
				}
				int num3 = 5 + (num + i) % extraSlots;
				StationStore val = storage[num3];
				if (val.itemId != 0 && val.count < val.max)
				{
					_demand[num2] = val.itemId;
					_owner[num2] = num3;
					num2++;
				}
			}
			_rotate = (num + num2) % extraSlots;
			return num2;
		}

		private static void FeedFromBelts(StationComponent station, CargoTraffic traffic, StationStore[] storage, int demandCount)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Invalid comparison between Unknown and I4
			SlotData[] slots = station.slots;
			if (slots == null)
			{
				return;
			}
			BeltComponent[] beltPool = traffic.beltPool;
			if (beltPool == null)
			{
				return;
			}
			lock (storage)
			{
				for (int i = 0; i < slots.Length; i++)
				{
					ref SlotData reference = ref slots[i];
					if ((int)reference.dir != 2 || reference.counter > 0 || reference.beltId == 0)
					{
						continue;
					}
					CargoPath cargoPath = traffic.GetCargoPath(beltPool[reference.beltId].segPathId);
					if (cargoPath == null)
					{
						continue;
					}
					int num = -1;
					byte b = 0;
					byte b2 = 0;
					int num2 = cargoPath.TryPickItemAtRear(_demand, ref num, ref b, ref b2);
					if (num < 0 || num >= demandCount || _demand[num] == 0)
					{
						continue;
					}
					int num3 = _owner[num];
					if (num3 >= 5 && num3 < storage.Length && storage[num3].itemId == num2)
					{
						station.InputItem(num2, num3, (int)b, (int)b2);
						reference.storageIdx = num3 + 1;
						reference.counter = 1;
						if (storage[num3].count >= storage[num3].max)
						{
							_demand[num] = 0;
							_owner[num] = 0;
						}
					}
				}
			}
		}
	}
	[HarmonyPatch]
	internal static class StationPatches
	{
		private const float RowHeight = 76f;

		private const float PanelClearance = 16f;

		private static readonly int[] TargetItems = new int[2] { 2103, 2104 };

		private static readonly HashSet<int> TargetProtoIds = new HashSet<int>();

		private static int _kinds;

		private static readonly FieldInfo StorageUIsField = AccessTools.Field(typeof(UIStationWindow), "storageUIs");

		private static int _currentPage;

		private static int _lastStationId;

		private static int _currentMaxPage;

		private static Scrollbar _pageScrollbar;

		private static bool _syncingScrollbar;

		private static Text _pageLabel;

		private static UIStationWindow _lastWindow;

		private static int RequiredIconCount => (_kinds + 3) / 4 * 4;

		private static UIStationStorage[] GetStorageUIs(UIStationWindow window)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			if ((Object)window == (Object)null || StorageUIsField == null)
			{
				return null;
			}
			return StorageUIsField.GetValue(window) as UIStationStorage[];
		}

		internal static void LoadConfig()
		{
			ConfigEntry<bool> stationEnabled = LogisticsStationSlotsPlugin.StationEnabled;
			if (stationEnabled == null || !stationEnabled.Value)
			{
				_kinds = 0;
			}
			else
			{
				_kinds = Math.Max(0, LogisticsStationSlotsPlugin.StationMaxItemKinds.Value);
			}
		}

		internal static void ApplyPrefab()
		{
			TargetProtoIds.Clear();
			ConfigEntry<bool> stationEnabled = LogisticsStationSlotsPlugin.StationEnabled;
			if (stationEnabled == null || !stationEnabled.Value)
			{
				_kinds = 0;
				LogisticsStationSlotsPlugin.Log.LogInfo((object)"物流站扩容:已关闭(Enabled = false)");
				return;
			}
			LoadConfig();
			if (_kinds <= 0)
			{
				LogisticsStationSlotsPlugin.Log.LogInfo((object)"物流站扩容:货物栏数量是 0,没有任何改动");
				return;
			}
			int[] targetItems = TargetItems;
			for (int i = 0; i < targetItems.Length; i++)
			{
				Apply(targetItems[i]);
			}
			if (TargetProtoIds.Count == 0)
			{
				LogisticsStationSlotsPlugin.Log.LogWarning((object)"物流站扩容:一个目标站点都没改到,请检查物品 ID");
			}
		}

		private static void Apply(int itemId)
		{
			ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select(itemId);
			ModelProto val2 = ((val != null) ? ((ProtoSet<ModelProto>)(object)LDB.models).Select(val.ModelIndex) : null);
			if (val2?.prefabDesc == null || !val2.prefabDesc.isStation)
			{
				LogisticsStationSlotsPlugin.Log.LogWarning((object)$"物流站扩容:物品 {itemId} 不是物流站或没有 prefabDesc,跳过");
				return;
			}
			int stationMaxItemKinds = val2.prefabDesc.stationMaxItemKinds;
			int stationMaxItemCount = val2.prefabDesc.stationMaxItemCount;
			if (_kinds > 0)
			{
				val2.prefabDesc.stationMaxItemKinds = _kinds;
			}
			TargetProtoIds.Add(itemId);
			LogisticsStationSlotsPlugin.Log.LogInfo((object)($"物流站扩容:{((Proto)val).name} 货物栏 {stationMaxItemKinds} → {val2.prefabDesc.stationMaxItemKinds} 格" + $"(单格库存上限 {stationMaxItemCount} 保持原版,本插件不再改动)"));
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(StationComponent), "AddItem")]
		private static bool StationComponent_AddItem(StationComponent __instance, int itemId, int count, int inc, ref int __result)
		{
			StationStore[] storage = __instance.storage;
			if (storage == null || storage.Length <= 6)
			{
				return true;
			}
			__result = 0;
			if (itemId <= 0)
			{
				return false;
			}
			lock (storage)
			{
				for (int i = 0; i < storage.Length; i++)
				{
					if (storage[i].itemId == itemId)
					{
						storage[i].count += count;
						storage[i].inc += inc;
						__result = count;
						return false;
					}
				}
			}
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(StationComponent), "HasLocalSupply")]
		private static bool StationComponent_HasLocalSupply(StationComponent __instance, int itemId, int countAtLeast, ref int __result)
		{
			return FindSlot(__instance, itemId, countAtLeast, local: true, supply: true, ref __result);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(StationComponent), "HasLocalDemand")]
		private static bool StationComponent_HasLocalDemand(StationComponent __instance, int itemId, int countAtLeast, ref int __result)
		{
			return FindSlot(__instance, itemId, countAtLeast, local: true, supply: false, ref __result);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(StationComponent), "HasRemoteSupply")]
		private static bool StationComponent_HasRemoteSupply(StationComponent __instance, int itemId, int countAtLeast, ref int __result)
		{
			return FindSlot(__instance, itemId, countAtLeast, local: false, supply: true, ref __result);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(StationComponent), "HasRemoteDemand")]
		private static bool StationComponent_HasRemoteDemand(StationComponent __instance, int itemId, int countAtLeast, ref int __result)
		{
			return FindSlot(__instance, itemId, countAtLeast, local: false, supply: false, ref __result);
		}

		private static bool FindSlot(StationComponent station, int itemId, int countAtLeast, bool local, bool supply, ref int result)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Invalid comparison between Unknown and I4
			StationStore[] storage = station.storage;
			if (storage == null || storage.Length <= 6)
			{
				return true;
			}
			result = -1;
			for (int i = 0; i < storage.Length; i++)
			{
				if (storage[i].itemId == itemId && (int)(local ? storage[i].localLogic : storage[i].remoteLogic) == (supply ? 1 : 2) && !(supply ? (storage[i].count < countAtLeast) : (storage[i].max - storage[i].count < countAtLeast)))
				{
					result = i;
					return false;
				}
			}
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(UIEntityBriefInfo), "_OnCreate")]
		private static void UIEntityBriefInfo_OnCreate(UIEntityBriefInfo __instance)
		{
			int requiredIconCount = RequiredIconCount;
			if (requiredIconCount > 0 && __instance.icons != null && __instance.icons.Length < requiredIconCount)
			{
				int num = __instance.icons.Length;
				Array.Resize(ref __instance.icons, requiredIconCount);
				LogisticsStationSlotsPlugin.Log.LogInfo((object)$"悬停信息框:图标数组 {num} → {requiredIconCount}(货物栏 {_kinds} 格)");
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(UIEntityBriefInfo), "_OnUpdate")]
		private static void UIEntityBriefInfo_OnUpdate(UIEntityBriefInfo __instance)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			int requiredIconCount = RequiredIconCount;
			if (requiredIconCount <= 0)
			{
				return;
			}
			UIIconCountInc[] icons = __instance.icons;
			if (icons == null || icons.Length >= requiredIconCount)
			{
				return;
			}
			UIIconCountInc val = null;
			for (int i = 0; i < icons.Length; i++)
			{
				if ((Object)icons[i] != (Object)null)
				{
					val = icons[i];
					break;
				}
			}
			if (!((Object)val == (Object)null))
			{
				int num = icons.Length;
				Array.Resize(ref __instance.icons, requiredIconCount);
				UIIconCountInc[] icons2 = __instance.icons;
				for (int j = num; j < icons2.Length; j++)
				{
					UIIconCountInc val2 = Object.Instantiate<UIIconCountInc>(val, ((Component)val).transform.parent);
					CommonUtils.SetTransformIdentity((Component)val2);
					val2.visible = false;
					icons2[j] = val2;
				}
				LogisticsStationSlotsPlugin.Log.LogInfo((object)$"悬停信息框:图标数组 {num} → {icons2.Length}(货物栏 {_kinds} 格,运行时补齐)");
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(UIStationWindow), "_OnUpdate")]
		private static void UIStationWindow_OnUpdate(UIStationWindow __instance)
		{
			if (_kinds <= 6 || __instance.stationId == 0)
			{
				return;
			}
			PlanetTransport transport = __instance.transport;
			if (transport?.stationPool == null || __instance.stationId >= transport.stationPool.Length)
			{
				return;
			}
			StationComponent val = transport.stationPool[__instance.stationId];
			if (val == null || val.id != __instance.stationId)
			{
				return;
			}
			UIStationStorage[] storageUIs = GetStorageUIs(__instance);
			if (storageUIs == null || storageUIs.Length == 0)
			{
				return;
			}
			StationStore[] storage = val.storage;
			int num = ((storage != null) ? storage.Length : 0);
			if (num <= storageUIs.Length)
			{
				return;
			}
			if (__instance.stationId != _lastStationId)
			{
				_lastStationId = __instance.stationId;
				_currentPage = 0;
			}
			int num2 = (num - 1) / storageUIs.Length;
			if (num2 > 0)
			{
				_currentPage += PageStep(__instance);
			}
			_currentMaxPage = num2;
			EnsureScrollbar(__instance);
			if (_currentPage < 0)
			{
				_currentPage = 0;
			}
			if (_currentPage > num2)
			{
				_currentPage = num2;
			}
			for (int i = 0; i < storageUIs.Length; i++)
			{
				int num3 = _currentPage * storageUIs.Length + i;
				if (num3 < num)
				{
					if (storageUIs[i].station != val || storageUIs[i].index != num3)
					{
						storageUIs[i].station = val;
						storageUIs[i].index = num3;
						((ManualBehaviour)storageUIs[i])._Open();
					}
				}
				else if (storageUIs[i].station != null)
				{
					storageUIs[i].station = null;
					storageUIs[i].index = 0;
					((ManualBehaviour)storageUIs[i])._Close();
				}
			}
			SyncScrollbar(num2);
			_lastWindow = __instance;
			EnsurePageLabel(__instance, storageUIs);
			PageIndicator.Update(_pageLabel, _currentPage, num2);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIStationWindow), "_OnClose")]
		private static void UIStationWindow_OnClose()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			_lastWindow = null;
			if ((Object)_pageLabel != (Object)null)
			{
				PageIndicator.Update(_pageLabel, 0, 0);
			}
		}

		private static void EnsurePageLabel(UIStationWindow window, UIStationStorage[] uis)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)_pageLabel != (Object)null) && !((Object)window == (Object)null) && uis != null && uis.Length != 0 && !((Object)uis[0] == (Object)null))
			{
				RectTransform windowTrans = window.windowTrans;
				Text componentInChildren = ((Component)uis[0]).GetComponentInChildren<Text>(true);
				if (!((Object)windowTrans == (Object)null) && !((Object)componentInChildren == (Object)null))
				{
					_pageLabel = PageIndicator.Create("beltstation-page-label", windowTrans, componentInChildren, new Vector2(0f, -22f), (TextAnchor)4, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f));
				}
			}
		}

		internal static bool CursorOverPagingArea()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			UIStationWindow lastWindow = _lastWindow;
			if ((Object)lastWindow == (Object)null || _kinds <= 6)
			{
				return false;
			}
			if ((Object)((Component)lastWindow).gameObject == (Object)null || !((Component)lastWindow).gameObject.activeInHierarchy)
			{
				return false;
			}
			if (lastWindow.stationId == 0)
			{
				return false;
			}
			return MouseOverWindow(lastWindow);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIStationWindow), "RefreshTrans")]
		private static void UIStationWindow_RefreshTrans(UIStationWindow __instance, StationComponent station)
		{
			//IL_0069: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			if (_kinds <= 6 || station == null)
			{
				return;
			}
			StationStore[] storage = station.storage;
			int num = ((storage != null) ? storage.Length : 0);
			if (num > 6)
			{
				UIStationStorage[] storageUIs = GetStorageUIs(__instance);
				int num2 = ((storageUIs != null && storageUIs.Length != 0) ? storageUIs.Length : 6);
				int num3 = ((num > num2) ? num2 : num) - num;
				if (num3 != 0)
				{
					float num4 = 76f * (float)num3 + ((num3 > 0) ? 16f : 0f);
					Vector2 sizeDelta = __instance.windowTrans.sizeDelta;
					__instance.windowTrans.sizeDelta = new Vector2(sizeDelta.x, sizeDelta.y + num4);
				}
			}
		}

		private static int PageStep(UIStationWindow window)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown((KeyCode)281))
			{
				return 1;
			}
			if (Input.GetKeyDown((KeyCode)280))
			{
				return -1;
			}
			float num = VFInput.mouseWheel;
			if (num == 0f)
			{
				num = Input.mouseScrollDelta.y;
			}
			if (num == 0f)
			{
				return 0;
			}
			if (!MouseOverWindow(window))
			{
				return 0;
			}
			if (!(num > 0f))
			{
				return 1;
			}
			return -1;
		}

		private static bool MouseOverWindow(UIStationWindow window)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			RectTransform windowTrans = window.windowTrans;
			if ((Object)windowTrans == (Object)null)
			{
				return false;
			}
			Canvas componentInParent = ((Component)window).GetComponentInParent<Canvas>();
			Camera val = (((Object)componentInParent != (Object)null && (int)componentInParent.renderMode != 0) ? componentInParent.worldCamera : null);
			return RectTransformUtility.RectangleContainsScreenPoint(windowTrans, Vector2.op_Implicit(Input.mousePosition), val);
		}

		private static void EnsureScrollbar(UIStationWindow window)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: 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_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Expected O, but got Unknown
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Expected O, but got Unknown
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: 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_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Expected O, but got Unknown
			//IL_022b: 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_0238: Expected O, but got Unknown
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Expected O, but got Unknown
			if ((Object)_pageScrollbar != (Object)null)
			{
				return;
			}
			UIStationStorage[] storageUIs = GetStorageUIs(window);
			if (storageUIs == null || storageUIs.Length == 0 || (Object)storageUIs[0] == (Object)null)
			{
				return;
			}
			Transform transform = ((Component)storageUIs[0]).transform;
			RectTransform val = (RectTransform)((transform is RectTransform) ? transform : null);
			if (!((Object)val == (Object)null))
			{
				Rect rect = val.rect;
				if (!(((Rect)(ref rect)).width <= 0f))
				{
					GameObject val2 = new GameObject("beltstation-page-scrollbar", new Type[3]
					{
						typeof(RectTransform),
						typeof(Image),
						typeof(Scrollbar)
					});
					val2.transform.SetParent(((Transform)val).parent, false);
					RectTransform val3 = (RectTransform)val2.transform;
					val3.anchorMin = new Vector2(0f, 1f);
					val3.anchorMax = new Vector2(0f, 1f);
					val3.pivot = new Vector2(0f, 1f);
					val3.anchoredPosition = new Vector2(val.anchoredPosition.x + ((Rect)(ref rect)).width + 4f, val.anchoredPosition.y);
					val3.sizeDelta = new Vector2(10f, 76f * (float)storageUIs.Length);
					((Graphic)val2.GetComponent<Image>()).color = new Color(1f, 1f, 1f, 0.08f);
					GameObject val4 = new GameObject("Sliding Area", new Type[1] { typeof(RectTransform) });
					val4.transform.SetParent((Transform)val3, false);
					RectTransform val5 = (RectTransform)val4.transform;
					val5.anchorMin = Vector2.zero;
					val5.anchorMax = Vector2.one;
					val5.offsetMin = Vector2.zero;
					val5.offsetMax = Vector2.zero;
					GameObject val6 = new GameObject("Handle", new Type[2]
					{
						typeof(RectTransform),
						typeof(Image)
					});
					val6.transform.SetParent((Transform)val5, false);
					RectTransform val7 = (RectTransform)val6.transform;
					val7.offsetMin = Vector2.zero;
					val7.offsetMax = Vector2.zero;
					Image component = val6.GetComponent<Image>();
					((Graphic)component).color = new Color(0.62f, 0.84f, 1f, 0.55f);
					_pageScrollbar = val2.GetComponent<Scrollbar>();
					_pageScrollbar.direction = (Direction)3;
					_pageScrollbar.handleRect = val7;
					((Selectable)_pageScrollbar).targetGraphic = (Graphic)component;
					((UnityEvent<float>)(object)_pageScrollbar.onValueChanged).AddListener((UnityAction<float>)OnScrollbarValueChanged);
					LogisticsStationSlotsPlugin.Log.LogInfo((object)$"物流站面板已加入页码滚动条(每页 {storageUIs.Length} 格)");
				}
			}
		}

		private static void SyncScrollbar(int maxPage)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			if (!((Object)_pageScrollbar == (Object)null))
			{
				bool flag = maxPage > 0;
				if (((Component)_pageScrollbar).gameObject.activeSelf != flag)
				{
					((Component)_pageScrollbar).gameObject.SetActive(flag);
				}
				if (flag)
				{
					_syncingScrollbar = true;
					_pageScrollbar.numberOfSteps = maxPage + 1;
					_pageScrollbar.size = 1f / (float)(maxPage + 1);
					_pageScrollbar.value = (float)_currentPage / (float)maxPage;
					_syncingScrollbar = false;
				}
			}
		}

		private static void OnScrollbarValueChanged(float value)
		{
			if (!_syncingScrollbar && _currentMaxPage > 0)
			{
				_currentPage = Mathf.RoundToInt(value * (float)_currentMaxPage);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameData), "Import")]
		private static void GameData_Import(GameData __instance)
		{
			if (_kinds <= 6 || __instance == null || __instance.factories == null)
			{
				return;
			}
			int num = 0;
			for (int i = 0; i < __instance.factoryCount; i++)
			{
				PlanetFactory val = __instance.factories[i];
				PlanetTransport val2 = val?.transport;
				if (val2?.stationPool == null || val.entityPool == null)
				{
					continue;
				}
				for (int j = 1; j < val2.stationCursor; j++)
				{
					StationComponent val3 = val2.stationPool[j];
					if (val3?.storage == null || val3.id != j || val3.isCollector || val3.isVeinCollector)
					{
						continue;
					}
					int entityId = val3.entityId;
					if (entityId <= 0 || entityId >= val.entityPool.Length)
					{
						continue;
					}
					int protoId = val.entityPool[entityId].protoId;
					if (!TargetProtoIds.Contains(protoId))
					{
						continue;
					}
					ModelProto val4 = ((ProtoSet<ModelProto>)(object)LDB.models).Select((int)val.entityPool[entityId].modelIndex);
					if (val4?.prefabDesc == null)
					{
						continue;
					}
					int stationMaxItemKinds = val4.prefabDesc.stationMaxItemKinds;
					if (stationMaxItemKinds > 0 && val3.storage.Length < stationMaxItemKinds)
					{
						Array.Resize(ref val3.storage, stationMaxItemKinds);
						if (val3.priorityLocks != null && val3.priorityLocks.Length < stationMaxItemKinds)
						{
							Array.Resize(ref val3.priorityLocks, stationMaxItemKinds);
						}
						num++;
					}
				}
			}
			if (num > 0)
			{
				LogisticsStationSlotsPlugin.Log.LogInfo((object)$"物流站扩容:已把 {num} 个已建成物流站的货物栏扩到 {_kinds} 格");
			}
		}
	}
	[HarmonyPatch]
	internal static class WheelZoomGuard
	{
		private static bool Suppress()
		{
			try
			{
				if (StationPatches.CursorOverPagingArea())
				{
					return true;
				}
			}
			catch
			{
			}
			try
			{
				if (ControlPanelStoragePaging.CursorOverPagingArea())
				{
					return true;
				}
			}
			catch
			{
			}
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(VFInput), "get__cameraZoomIn")]
		private static bool ZoomIn_Prefix(ref float __result)
		{
			if (!Suppress())
			{
				return true;
			}
			__result = 0f;
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(VFInput), "get__cameraZoomOut")]
		private static bool ZoomOut_Prefix(ref float __result)
		{
			if (!Suppress())
			{
				return true;
			}
			__result = 0f;
			return false;
		}
	}
}