Decompiled source of StationAssistant v0.1.9
StationAssistant.dll
Decompiled 3 days ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using CatAPI; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.UI; [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: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.0.0")] [module: UnverifiableCode] [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; } } } internal static class PluginInfo { public const string PLUGIN_GUID = "com.yummi.dsp.stationassistant"; public const string PLUGIN_NAME = "StationAssistant"; public const string PLUGIN_VERSION = "0.1.7"; } namespace StationAssistant { internal static class CatFeature { internal static bool Enabled { get; private set; } internal static void Apply() { Enabled = Settings.CatText == "我是一只猫"; if (Enabled) { Plugin.Log.LogInfo((object)"隐藏功能入口已打开,功能尚未定义。"); } } } internal static class ConflictStartup { internal static bool Blocked { get; private set; } internal static bool ScanComplete { get; private set; } internal static void BeginScan(BaseUnityPlugin host) { ((MonoBehaviour)host).StartCoroutine(ScanAfterChainloader()); } private static IEnumerator ScanAfterChainloader() { yield return null; ScanComplete = true; Blocked = LogisticsStationSlotsConflict.IsPresent(); if (Blocked) { ManualLogSource log = Plugin.Log; if (log != null) { log.LogError((object)LogisticsStationSlotsConflict.GetErrorMessage()); } } } internal static void OnMainMenuReady() { if (!ScanComplete) { Blocked = LogisticsStationSlotsConflict.IsPresent(); ScanComplete = true; } if (Blocked || LogisticsStationSlotsConflict.IsPresent()) { Blocked = true; ManualLogSource log = Plugin.Log; if (log != null) { log.LogError((object)LogisticsStationSlotsConflict.GetErrorMessage()); } } else { FeatureStartup.EnableFeatures(); } } } [HarmonyPatch] public static class ControlPanelStoragePaging { private sealed class PageState { public int Page; public int LastStationId = -1; } private static readonly ConditionalWeakTable<StationComponent, PageState> states = new ConditionalWeakTable<StationComponent, PageState>(); internal const int ControlPageSize = 5; private static FieldInfo storageUIsField; private static FieldInfo stationField; private static FieldInfo factoryField; private static bool fieldsTried; private static UIControlPanelStationInspector lastInspector; private static UIControlPanelStationStorage[] lastUis; private static Text pageLabel; private static RectTransform chrome; private static float lastWheel; private static float nextPageTime; internal static bool CursorOverPagingArea() { if (!Settings.ControlScroll || (Object)(object)lastInspector == (Object)null || lastUis == null) { return false; } if (!((Component)lastInspector).gameObject.activeInHierarchy) { return false; } return MouseOverAny(lastUis); } [HarmonyPrefix] [HarmonyPatch(typeof(UIControlPanelStationStorage), "SetData")] [Guard("61111e7e94b232ee")] public static void SetData_Prefix(StationComponent __1, ref int __2) { if (!Settings.ControlScroll || __1 == null) { return; } int num = CountOf(__1); int num2 = 5; if (num > num2) { int num3 = Pages.Start(StateOf(__1).Page, num, num2) + __2; if (num3 < num) { __2 = num3; } } } [HarmonyPostfix] [HarmonyPatch(typeof(UIControlPanelStationInspector), "OnStationIdChange")] [Guard("2e0ac06ebe9e0453")] public static void OnStationIdChange_Postfix(UIControlPanelStationInspector __instance) { //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) if (Settings.ControlScroll && !((Object)(object)__instance.deliveryGroupRectTransform == (Object)null)) { StationComponent val = ((__instance.transport != null && __instance.stationId > 0 && __instance.stationId < __instance.transport.stationPool.Length) ? __instance.transport.stationPool[__instance.stationId] : null); if (val != null && val.storage != null && !val.isCollector && !val.isVeinCollector) { int num = Mathf.Min(val.storage.Length, 5); float y = ((RectTransform)((Component)__instance.storageUIPrefab).transform).sizeDelta.y; RectTransform deliveryGroupRectTransform = __instance.deliveryGroupRectTransform; deliveryGroupRectTransform.anchoredPosition = new Vector2(deliveryGroupRectTransform.anchoredPosition.x, -144f - (float)num * (y + 6f)); } } } [HarmonyPostfix] [HarmonyPatch(typeof(UIControlPanelStationInspector), "_OnUpdate")] [Guard("b89aade680ae7db9")] public static void OnUpdate_Postfix(UIControlPanelStationInspector __instance) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Invalid comparison between Unknown and I4 //IL_011c: Unknown result type (might be due to invalid IL or missing references) if (!Settings.ControlScroll || !EnsureFields()) { Hide(); return; } if ((int)__instance.currentTabPanel != 1) { lastInspector = null; Hide(); return; } object? value = stationField.GetValue(__instance); StationComponent val = (StationComponent)((value is StationComponent) ? value : null); UIControlPanelStationStorage[] array = storageUIsField.GetValue(__instance) as UIControlPanelStationStorage[]; if (val == null || array == null || array.Length == 0) { Hide(); return; } int slots = CountOf(val); int pageSize = 5; int num = Pages.Count(slots, pageSize); if (num <= 1) { lastInspector = null; Hide(); return; } lastInspector = __instance; lastUis = array; for (int i = 5; i < array.Length; i++) { if ((Object)(object)array[i] != (Object)null && ((Component)array[i]).gameObject.activeSelf) { ((Component)array[i]).gameObject.SetActive(false); } } PageState pageState = StateOf(val); if (pageState.LastStationId != val.id) { pageState.LastStationId = val.id; pageState.Page = 0; } int num2 = 0; if (Input.GetKeyDown((KeyCode)281)) { num2 = 1; } else if (Input.GetKeyDown((KeyCode)280)) { num2 = -1; } else if (MouseOverAny(array)) { float y = Input.mouseScrollDelta.y; if (y == 0f) { lastWheel = 0f; } else if (y != lastWheel && Time.unscaledTime >= nextPageTime) { lastWheel = y; nextPageTime = Time.unscaledTime + 0.15f; num2 = ((!(y > 0f)) ? 1 : (-1)); } } if (num2 != 0) { int num3 = pageState.Page + num2; if (num3 < 0) { num3 = 0; } if (num3 >= num) { num3 = num - 1; } if (num3 != pageState.Page) { pageState.Page = num3; Rebind(__instance, val, array); } } EnsureChrome(__instance, array); if ((Object)(object)pageLabel != (Object)null) { pageLabel.text = pageState.Page + 1 + "/" + num; } if ((Object)(object)chrome != (Object)null && !((Component)chrome).gameObject.activeSelf) { ((Component)chrome).gameObject.SetActive(true); } } private static void Rebind(UIControlPanelStationInspector inspector, StationComponent station, UIControlPanelStationStorage[] uis) { object? value = factoryField.GetValue(inspector); PlanetFactory val = (PlanetFactory)((value is PlanetFactory) ? value : null); if (val == null) { return; } int num = CountOf(station); int num2 = Pages.Start(StateOf(station).Page, num, 5); for (int i = 0; i < uis.Length; i++) { if ((Object)(object)uis[i] == (Object)null) { continue; } if (i < 5 && num2 + i < num) { if (!((Component)uis[i]).gameObject.activeSelf) { ((Component)uis[i]).gameObject.SetActive(true); } uis[i].SetData(val, station, i); } else if (((Component)uis[i]).gameObject.activeSelf) { ((Component)uis[i]).gameObject.SetActive(false); } } } private static int CountOf(StationComponent station) { if (station.isCollector || station.isVeinCollector) { return 0; } if (station.storage == null) { return 0; } return station.storage.Length; } private static PageState StateOf(StationComponent station) { if (!states.TryGetValue(station, out var value)) { value = new PageState(); states.Add(station, value); } return value; } private static bool EnsureFields() { if (fieldsTried) { if (storageUIsField != null && stationField != null) { return factoryField != null; } return false; } fieldsTried = true; Type? typeFromHandle = typeof(UIControlPanelStationInspector); storageUIsField = AccessTools.Field(typeFromHandle, "storageUIs"); stationField = AccessTools.Field(typeFromHandle, "station"); factoryField = AccessTools.Field(typeFromHandle, "factory"); if (storageUIsField != null && stationField != null) { return factoryField != null; } return false; } private static bool MouseOverAny(UIControlPanelStationStorage[] uis) { for (int i = 0; i < uis.Length; i++) { if (!((Object)(object)uis[i] == (Object)null) && ((Component)uis[i]).gameObject.activeInHierarchy) { Transform transform = ((Component)uis[i]).transform; RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null); if ((Object)(object)val != (Object)null && MouseOver(val)) { return true; } } } return false; } private static bool MouseOver(RectTransform rect) { //IL_0011: 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_0028: Unknown result type (might be due to invalid IL or missing references) Canvas componentInParent = ((Component)rect).GetComponentInParent<Canvas>(); Camera val = (((Object)(object)componentInParent != (Object)null && (int)componentInParent.renderMode != 0) ? componentInParent.worldCamera : null); return RectTransformUtility.RectangleContainsScreenPoint(rect, Vector2.op_Implicit(Input.mousePosition), val); } private static void EnsureChrome(UIControlPanelStationInspector inspector, UIControlPanelStationStorage[] uis) { //IL_0068: 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_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Expected O, but got Unknown //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)chrome != (Object)null) && uis.Length != 0 && !((Object)(object)uis[0] == (Object)null)) { Transform transform = ((Component)inspector).transform; RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null); if (!((Object)(object)val == (Object)null)) { Text componentInChildren = ((Component)uis[0]).GetComponentInChildren<Text>(true); Font font = (((Object)(object)componentInChildren != (Object)null) ? componentInChildren.font : null); GameObject val2 = new GameObject("station-assistant-cpanel-page", new Type[1] { typeof(RectTransform) }); val2.transform.SetParent((Transform)(object)val, false); chrome = (RectTransform)val2.transform; chrome.anchorMin = new Vector2(0.5f, 1f); chrome.anchorMax = new Vector2(0.5f, 1f); chrome.pivot = new Vector2(0.5f, 1f); chrome.anchoredPosition = new Vector2(0f, -8f); chrome.sizeDelta = new Vector2(140f, 24f); pageLabel = CreateLabel(chrome, font); } } } private static Text CreateLabel(RectTransform parent, Font font) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0026: 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_0056: 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_008a: 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_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: 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_00b7: 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_00cc: 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_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) RectTransform component = Arrow(parent, font, left: true).GetComponent<RectTransform>(); component.anchoredPosition = new Vector2(-48f, 0f - component.sizeDelta.y * 2f); RectTransform component2 = Arrow(parent, font, left: false).GetComponent<RectTransform>(); component2.anchoredPosition = new Vector2(48f, 0f - component2.sizeDelta.y * 2f); GameObject val = new GameObject("label", new Type[2] { typeof(RectTransform), typeof(Text) }); val.transform.SetParent((Transform)(object)parent, false); RectTransform val2 = (RectTransform)val.transform; val2.anchorMin = new Vector2(0.5f, 0.5f); val2.anchorMax = new Vector2(0.5f, 0.5f); val2.pivot = new Vector2(0.5f, 0.5f); val2.sizeDelta = new Vector2(60f, 22f); val2.anchoredPosition = new Vector2(0f, 0f - component2.sizeDelta.y * 2f); Text component3 = val.GetComponent<Text>(); component3.horizontalOverflow = (HorizontalWrapMode)1; component3.verticalOverflow = (VerticalWrapMode)1; component3.text = "1/1"; component3.font = (((Object)(object)font != (Object)null) ? font : Resources.GetBuiltinResource<Font>("Arial.ttf")); component3.fontSize = Mathf.CeilToInt(18.199999f); component3.alignment = (TextAnchor)4; ((Graphic)component3).color = new Color(0.75f, 0.88f, 1f, 0.95f); ((Graphic)component3).raycastTarget = false; return component3; } private static GameObject Arrow(RectTransform parent, Font font, bool left) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Expected O, but got Unknown //IL_0067: 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_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Expected O, but got Unknown //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_011d: 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_0128: 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) GameObject val = new GameObject(left ? "prev" : "next", new Type[3] { typeof(RectTransform), typeof(Image), typeof(Button) }); val.transform.SetParent((Transform)(object)parent, false); ((RectTransform)val.transform).sizeDelta = new Vector2(22f, 20f); ((Graphic)val.GetComponent<Image>()).color = new Color(0.62f, 0.84f, 1f, 0.55f); ((UnityEvent)val.GetComponent<Button>().onClick).AddListener((UnityAction)delegate { Step((!left) ? 1 : (-1)); }); GameObject val2 = new GameObject("t", new Type[2] { typeof(RectTransform), typeof(Text) }); val2.transform.SetParent(val.transform, false); RectTransform val3 = (RectTransform)val2.transform; val3.anchorMin = Vector2.zero; val3.anchorMax = Vector2.one; val3.offsetMin = Vector2.zero; val3.offsetMax = Vector2.zero; Text component = val2.GetComponent<Text>(); component.font = Resources.GetBuiltinResource<Font>("Arial.ttf"); component.fontSize = 14; component.alignment = (TextAnchor)4; component.horizontalOverflow = (HorizontalWrapMode)1; component.verticalOverflow = (VerticalWrapMode)1; ((Graphic)component).color = Color.white; ((Graphic)component).raycastTarget = false; component.text = (left ? "<" : ">"); return val; } private static void Step(int delta) { if ((Object)(object)lastInspector == (Object)null || !EnsureFields()) { return; } object? value = stationField.GetValue(lastInspector); StationComponent val = (StationComponent)((value is StationComponent) ? value : null); UIControlPanelStationStorage[] array = storageUIsField.GetValue(lastInspector) as UIControlPanelStationStorage[]; if (val != null && array != null) { PageState pageState = StateOf(val); int num = Pages.Count(CountOf(val), 5); int num2 = pageState.Page + delta; if (num2 >= 0 && num2 < num && num2 != pageState.Page) { pageState.Page = num2; Rebind(lastInspector, val, array); } } } private static void Hide() { if ((Object)(object)chrome != (Object)null && ((Component)chrome).gameObject.activeSelf) { ((Component)chrome).gameObject.SetActive(false); } } } [HarmonyPatch] public static class DuplicateItemPatch { [HarmonyPrefix] [HarmonyPatch(typeof(UIStationStorage), "OnItemPickerReturn")] [Guard("503e7f1250016a66")] public static bool Station_Prefix(UIStationStorage __instance, ItemProto itemProto) { //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) if (!Settings.AllowDuplicate || itemProto == null || __instance.station == null || !SlotStorage.IsTower(__instance.station)) { return true; } if (__instance.index < 0 || __instance.index >= __instance.station.storage.Length) { return true; } if (!Uses(__instance.station, ((Proto)itemProto).ID)) { return true; } StationStore val = __instance.station.storage[__instance.index]; __instance.stationWindow.transport.SetStationStorage(__instance.station.id, __instance.index, ((Proto)itemProto).ID, (val.max <= 0) ? 1 : val.max, (ELogisticStorage)1, (ELogisticStorage)(__instance.station.isStellar ? 1 : 0), GameMain.mainPlayer); return false; } [HarmonyPrefix] [HarmonyPatch(typeof(UIControlPanelStationStorage), "OnItemPickerReturn")] [Guard("aa616b132d594380")] public static bool Panel_Prefix(UIControlPanelStationStorage __instance, ItemProto itemProto) { //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) if (!Settings.AllowDuplicate || itemProto == null || !__instance.isStationDataValid || !SlotStorage.IsTower(__instance.station)) { return true; } if (__instance.index < 0 || __instance.index >= __instance.station.storage.Length) { return true; } if (!Uses(__instance.station, ((Proto)itemProto).ID)) { return true; } StationStore val = __instance.station.storage[__instance.index]; __instance.masterInspector.transport.SetStationStorage(__instance.station.id, __instance.index, ((Proto)itemProto).ID, (val.max <= 0) ? 1 : val.max, (ELogisticStorage)1, (ELogisticStorage)(__instance.station.isStellar ? 1 : 0), GameMain.mainPlayer); return false; } private static bool Uses(StationComponent station, int itemId) { StationStore[] storage = station.storage; for (int i = 0; i < storage.Length; i++) { if (storage[i].itemId == itemId) { return true; } } return false; } } [HarmonyPatch] public static class HoverIconPatch { private static bool logged; [HarmonyPrefix] [HarmonyPatch(typeof(UIEntityBriefInfo), "_OnCreate")] [Guard("69d3bf097eb80ed0")] public static void OnCreate_Prefix(UIEntityBriefInfo __instance) { Grow(__instance); } [HarmonyPrefix] [HarmonyPatch(typeof(UIEntityBriefInfo), "_OnUpdate")] [Guard("a72ad04c70fde856")] public static void OnUpdate_Prefix(UIEntityBriefInfo __instance) { Grow(__instance); } private static void Grow(UIEntityBriefInfo info) { if (info?.icons == null || info.icons.Length >= 32) { return; } UIIconCountInc val = null; for (int i = 0; i < info.icons.Length; i++) { if ((Object)(object)info.icons[i] != (Object)null) { val = info.icons[i]; break; } } int num = info.icons.Length; Array.Resize(ref info.icons, 32); if (!((Object)(object)val == (Object)null)) { for (int j = num; j < info.icons.Length; j++) { UIIconCountInc val2 = Object.Instantiate<UIIconCountInc>(val, ((Component)val).transform.parent); val2.visible = false; info.icons[j] = val2; } if (!logged) { logged = true; Plugin.Log.LogInfo((object)$"悬停图标 {num} → {info.icons.Length}"); } } } } internal static class LogisticsStationSlotsConflict { internal const string Guid = "local.logisticsstationslots"; internal static bool IsPresent() { if (Chainloader.PluginInfos.ContainsKey("local.logisticsstationslots")) { return true; } foreach (PluginInfo value in Chainloader.PluginInfos.Values) { if (value.Metadata.Name.Equals("LogisticsStationSlots", StringComparison.OrdinalIgnoreCase)) { return true; } if (value.Metadata.GUID.IndexOf("logisticsstationslots", StringComparison.OrdinalIgnoreCase) >= 0) { return true; } } return false; } internal static string GetErrorMessage() { return "Could not load [Station Assistant 0.1.8] because it is incompatible with LogisticsStationSlots (local.logisticsstationslots). This mod has been disabled; uninstall one of them.\n\n无法加载 [Station Assistant 0.1.8],因其与 LogisticsStationSlots(local.logisticsstationslots)不兼容。本 mod 已停用,请卸载其中一个。"; } } [HarmonyPatch] internal static class MainMenuBootstrap { private static BaseUnityPlugin host; private static bool preloadHookFired; internal static void Init(BaseUnityPlugin pluginHost) { host = pluginHost; } [HarmonyPostfix] [HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")] [HarmonyPriority(0)] [Guard("4185730b6448e635")] public static void InvokeOnLoadWorkEnded_Postfix() { if (!preloadHookFired && !((Object)(object)host == (Object)null)) { preloadHookFired = true; ((MonoBehaviour)host).StartCoroutine(AfterPreloadSplash()); } } [HarmonyPostfix] [HarmonyPatch(typeof(UIRoot), "_OnOpen")] [HarmonyPriority(0)] [Guard("05fc7f22583910d4")] public static void UIRoot_OnOpen_Postfix() { if (DSPGame.IsMenuDemo && !((Object)(object)host == (Object)null)) { ((MonoBehaviour)host).StartCoroutine(AfterPreloadSplash()); } } private static IEnumerator AfterPreloadSplash() { if (!VFPreload.done) { yield return (object)new WaitUntil((Func<bool>)(() => VFPreload.done)); } yield return null; ConflictStartup.OnMainMenuReady(); } } internal static class FeatureStartup { private static bool featuresEnabled; internal static void EnableFeatures() { if (!featuresEnabled && !ConflictStartup.Blocked) { featuresEnabled = true; Plugin.Instance.ApplyPatches(); } } } internal static class ManualSlotButton { internal static void Ensure(UIStationWindow window) { //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Expected O, but got Unknown //IL_00e7: 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_0191: Expected O, but got Unknown //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_022c: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Expected O, but got Unknown //IL_025b: Unknown result type (might be due to invalid IL or missing references) //IL_0260: Unknown result type (might be due to invalid IL or missing references) //IL_0273: Unknown result type (might be due to invalid IL or missing references) //IL_0279: 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_027f: Unknown result type (might be due to invalid IL or missing references) //IL_0289: Unknown result type (might be due to invalid IL or missing references) //IL_028a: Unknown result type (might be due to invalid IL or missing references) //IL_0294: Unknown result type (might be due to invalid IL or missing references) //IL_0295: Unknown result type (might be due to invalid IL or missing references) //IL_029f: 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_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_02d9: Unknown result type (might be due to invalid IL or missing references) //IL_02fc: Unknown result type (might be due to invalid IL or missing references) //IL_0307: Expected O, but got Unknown if ((Object)(object)window == (Object)null || (Object)(object)window.windowTrans == (Object)null) { return; } Transform val = ((Transform)window.windowTrans).Find("station-assistant-set-slots"); bool flag = false; int count = 0; if (window.transport != null && window.stationId > 0 && window.stationId < window.transport.stationPool.Length) { StationComponent val2 = window.transport.stationPool[window.stationId]; flag = SlotStorage.IsTower(val2); count = (flag ? val2.storage.Length : 0); } if (!Settings.ManualSlotButton || !flag) { if ((Object)(object)val != (Object)null) { ((Component)val).gameObject.SetActive(false); } return; } if ((Object)(object)val != (Object)null) { ((Component)val).gameObject.SetActive(true); ApplyLayout((RectTransform)val, window); Text componentInChildren = ((Component)val).GetComponentInChildren<Text>(); if ((Object)(object)componentInChildren != (Object)null) { componentInChildren.text = SlotButtonText(count); ((Graphic)componentInChildren).color = Color.white; } return; } UIButton stationSettingTabBtn = window.stationSettingTabBtn; Image val3 = (((Object)(object)stationSettingTabBtn != (Object)null) ? ((Component)stationSettingTabBtn).GetComponent<Image>() : null); Text val4 = (((Object)(object)stationSettingTabBtn != (Object)null) ? ((Component)stationSettingTabBtn).GetComponentInChildren<Text>(true) : null); Font font = (((Object)(object)val4 != (Object)null) ? val4.font : (((Object)(object)window.titleText != (Object)null) ? window.titleText.font : null)); GameObject val5 = new GameObject("station-assistant-set-slots", new Type[3] { typeof(RectTransform), typeof(Image), typeof(Button) }); val5.transform.SetParent((Transform)(object)window.windowTrans, false); Image component = val5.GetComponent<Image>(); if ((Object)(object)val3 != (Object)null && (Object)(object)val3.sprite != (Object)null) { component.sprite = val3.sprite; component.type = val3.type; ((Graphic)component).color = ((Graphic)val3).color; } else { ((Graphic)component).color = new Color(0.16f, 0.28f, 0.38f, 0.9f); } UIStationWindow captured = window; ((UnityEvent)val5.GetComponent<Button>().onClick).AddListener((UnityAction)delegate { Open(captured); }); GameObject val6 = new GameObject("t", new Type[2] { typeof(RectTransform), typeof(Text) }); val6.transform.SetParent(val5.transform, false); RectTransform val7 = (RectTransform)val6.transform; val7.anchorMin = Vector2.zero; val7.anchorMax = Vector2.one; val7.offsetMin = Vector2.zero; val7.offsetMax = Vector2.zero; Text component2 = val6.GetComponent<Text>(); component2.font = font; component2.fontSize = (((Object)(object)val4 != (Object)null) ? val4.fontSize : 13); component2.alignment = (TextAnchor)4; ((Graphic)component2).color = Color.white; ((Graphic)component2).raycastTarget = false; component2.text = SlotButtonText(count); ApplyLayout((RectTransform)val5.transform, window); } private static void ApplyLayout(RectTransform rt, UIStationWindow window) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0060: 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_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: 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_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: 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_0081: Unknown result type (might be due to invalid IL or missing references) RectTransform val = (RectTransform)(((Object)(object)window.stationSettingTabBtn != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null); Rect rect; float num; if ((Object)(object)val != (Object)null) { rect = val.rect; if (((Rect)(ref rect)).width > 1f) { rect = val.rect; num = ((Rect)(ref rect)).width; goto IL_0055; } } num = 132f; goto IL_0055; IL_0089: float num3; float num2 = num3; rt.anchorMin = new Vector2(1f, 1f); rt.anchorMax = new Vector2(1f, 1f); rt.pivot = new Vector2(1f, 1f); float num4; rt.sizeDelta = new Vector2(num4, num2 * 1.3f); rt.anchoredPosition = new Vector2(-16f, 0f - (num2 + 18f)); return; IL_0055: num4 = num; if ((Object)(object)val != (Object)null) { rect = val.rect; if (((Rect)(ref rect)).height > 1f) { rect = val.rect; num3 = ((Rect)(ref rect)).height; goto IL_0089; } } num3 = 26f; goto IL_0089; } private static string SlotButtonText(int count) { return Line.op_Implicit(Lang.En("Slots: " + count).ZhCN("槽位数目 : " + count)); } private static string DialogTitle() { return Line.op_Implicit(Lang.En("Set slot count").ZhCN("设置槽位数目")); } private static void Open(UIStationWindow window) { if (window.transport == null || window.stationId <= 0) { return; } StationComponent station = window.transport.stationPool[window.stationId]; if (!SlotStorage.IsTower(station)) { return; } int num = station.storage.Length; PopNumber.Show(DialogTitle(), num.ToString(), Line.op_Implicit(Lang.En($"Item kinds this station can hold. Current: {num}").ZhCN($"物流塔可容纳的物品数种类,目前为{num}")), (ContentType)2, delegate(string text) { if (int.TryParse(text.Trim(), out var result)) { SlotStorage.SetCount(window.factory, station, result); } }); } } [HarmonyPatch] public static class ModSaveBridge { private struct TailSlot { public int ItemId; public int Count; public int Inc; public int LocalLogic; public int RemoteLogic; public int Max; public int KeepMode; public int KeepInc; public byte PriorityIndex; public byte LockTick; } private sealed class Held { public StationComponent Station; public int PlanetId; public StationStore[] Storage; public StationPriorityLock[] Locks; public TailSlot[] Tail; } internal const string DspModSaveGuid = "crecheng.DSPModSave"; private static readonly List<Held> held = new List<Held>(); internal const string CompanionGuid = "com.yummi.dsp.stationassistant.modsave"; internal static bool Active { get { if (Settings.SaveExtraSlots && Chainloader.PluginInfos.ContainsKey("crecheng.DSPModSave")) { return Chainloader.PluginInfos.ContainsKey("com.yummi.dsp.stationassistant.modsave"); } return false; } } public static void Export(BinaryWriter writer) { writer.Write(1); int num = 0; for (int i = 0; i < ModSaveBridge.held.Count; i++) { if (ModSaveBridge.held[i].Tail != null && ModSaveBridge.held[i].Tail.Length != 0) { num++; } } writer.Write(num); for (int j = 0; j < ModSaveBridge.held.Count; j++) { Held held = ModSaveBridge.held[j]; if (held.Tail != null && held.Tail.Length != 0 && held.Station != null) { writer.Write(held.PlanetId); writer.Write(held.Station.id); writer.Write(held.Station.entityId); writer.Write(held.Tail.Length); for (int k = 0; k < held.Tail.Length; k++) { TailSlot tailSlot = held.Tail[k]; writer.Write(tailSlot.ItemId); writer.Write(tailSlot.Count); writer.Write(tailSlot.Inc); writer.Write(tailSlot.LocalLogic); writer.Write(tailSlot.RemoteLogic); writer.Write(tailSlot.Max); writer.Write(tailSlot.KeepMode); writer.Write(tailSlot.KeepInc); writer.Write(tailSlot.PriorityIndex); writer.Write(tailSlot.LockTick); } } } } public static void Import(BinaryReader reader) { if (!Active || reader.ReadInt32() != 1) { return; } int num = reader.ReadInt32(); GameData data = GameMain.data; for (int i = 0; i < num; i++) { int planetId = reader.ReadInt32(); int stationId = reader.ReadInt32(); int entityId = reader.ReadInt32(); int num2 = reader.ReadInt32(); TailSlot[] array = new TailSlot[num2]; for (int j = 0; j < num2; j++) { array[j] = new TailSlot { ItemId = reader.ReadInt32(), Count = reader.ReadInt32(), Inc = reader.ReadInt32(), LocalLogic = reader.ReadInt32(), RemoteLogic = reader.ReadInt32(), Max = reader.ReadInt32(), KeepMode = reader.ReadInt32(), KeepInc = reader.ReadInt32(), PriorityIndex = reader.ReadByte(), LockTick = reader.ReadByte() }; } Restore(data, planetId, stationId, entityId, array); } } public static void IntoOtherSave() { held.Clear(); } [HarmonyPrefix] [HarmonyPatch(typeof(GameSave), "SaveCurrentGame")] [Guard("642a7f58031c1335")] public static void SaveCurrentGame_Prefix() { Shrink(); } [HarmonyPostfix] [HarmonyPatch(typeof(GameSave), "SaveCurrentGame")] [HarmonyPriority(0)] [Guard("642a7f58031c1335")] public static void SaveCurrentGame_Postfix() { RestoreLive(); } [HarmonyPrefix] [HarmonyPatch(typeof(GameSave), "AutoSave")] [Guard("1b2c479f0b09b60d")] public static void AutoSave_Prefix() { Shrink(); } [HarmonyPostfix] [HarmonyPatch(typeof(GameSave), "AutoSave")] [HarmonyPriority(0)] [Guard("1b2c479f0b09b60d")] public static void AutoSave_Postfix() { RestoreLive(); } private static void Shrink() { //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: 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_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_012a: 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_0146: 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_0152: Expected I4, but got Unknown //IL_0154: 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_0160: Expected I4, but got Unknown //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_017e: 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_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) held.Clear(); if (!Active || GameMain.data?.factories == null) { return; } GameData data = GameMain.data; for (int i = 0; i < data.factoryCount; i++) { PlanetFactory val = data.factories[i]; PlanetTransport val2 = val?.transport; if (val2?.stationPool == null) { continue; } for (int j = 1; j < val2.stationCursor; j++) { StationComponent val3 = val2.stationPool[j]; if (val3 != null && val3.id == j && val3.storage != null && val3.storage.Length > 6 && SlotStorage.IsTower(val3)) { int num = val3.storage.Length - 6; TailSlot[] array = new TailSlot[num]; for (int k = 0; k < num; k++) { StationStore val4 = val3.storage[6 + k]; StationPriorityLock val5 = (StationPriorityLock)((val3.priorityLocks != null && 6 + k < val3.priorityLocks.Length) ? val3.priorityLocks[6 + k] : default(StationPriorityLock)); array[k] = new TailSlot { ItemId = val4.itemId, Count = val4.count, Inc = val4.inc, LocalLogic = (int)val4.localLogic, RemoteLogic = (int)val4.remoteLogic, Max = val4.max, KeepMode = val4.keepMode, KeepInc = (int)(val4.keepIncRatio * 100000f), PriorityIndex = val5.priorityIndex, LockTick = val5.lockTick }; } held.Add(new Held { Station = val3, PlanetId = val.planetId, Storage = val3.storage, Locks = val3.priorityLocks, Tail = array }); StationStore[] array2 = (StationStore[])(object)new StationStore[6]; Array.Copy(val3.storage, array2, 6); StationPriorityLock[] array3 = (StationPriorityLock[])(object)new StationPriorityLock[6]; if (val3.priorityLocks != null) { Array.Copy(val3.priorityLocks, array3, Math.Min(val3.priorityLocks.Length, 6)); } val3.storage = array2; val3.priorityLocks = array3; } } } } private static void RestoreLive() { for (int i = 0; i < ModSaveBridge.held.Count; i++) { Held held = ModSaveBridge.held[i]; if (held.Station != null) { held.Station.storage = held.Storage; held.Station.priorityLocks = held.Locks; } } } private static void Restore(GameData data, int planetId, int stationId, int entityId, TailSlot[] tail) { //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) if (data?.galaxy == null || tail == null || tail.Length == 0) { return; } PlanetFactory val = data.galaxy.PlanetById(planetId)?.factory; if (val?.transport?.stationPool == null || stationId <= 0 || stationId >= val.transport.stationPool.Length) { return; } StationComponent val2 = val.transport.stationPool[stationId]; if (val2 != null && val2.id == stationId && val2.entityId == entityId && val2.storage != null && val2.storage.Length == 6) { int num = 6 + tail.Length; if (num > 32) { num = 32; } StationStore[] array = (StationStore[])(object)new StationStore[num]; Array.Copy(val2.storage, array, 6); StationPriorityLock[] array2 = (StationPriorityLock[])(object)new StationPriorityLock[num]; if (val2.priorityLocks != null) { Array.Copy(val2.priorityLocks, array2, Math.Min(val2.priorityLocks.Length, 6)); } int num2 = num - 6; for (int i = 0; i < num2 && i < tail.Length; i++) { TailSlot tailSlot = tail[i]; array[6 + i] = new StationStore { itemId = tailSlot.ItemId, count = tailSlot.Count, inc = tailSlot.Inc, localLogic = (ELogisticStorage)tailSlot.LocalLogic, remoteLogic = (ELogisticStorage)tailSlot.RemoteLogic, max = tailSlot.Max, keepMode = tailSlot.KeepMode, keepIncRatio = (float)tailSlot.KeepInc * 1E-05f }; array2[6 + i] = new StationPriorityLock { priorityIndex = tailSlot.PriorityIndex, lockTick = tailSlot.LockTick }; } val2.storage = array; val2.priorityLocks = array2; } } } [HarmonyPatch] public static class NumericEditPatch { private static int refreshDepth; private static int pendingMax = int.MinValue; private static bool userEdit; [HarmonyPrefix] [HarmonyPatch(typeof(PlanetTransport), "SetStationStorage")] [Guard("1eb74a6188c74249")] public static void SetStationStorage_Prefix(int itemCountMax) { pendingMax = ((Settings.BreakLimit && userEdit) ? itemCountMax : int.MinValue); } [HarmonyPostfix] [HarmonyPatch(typeof(PlanetTransport), "SetStationStorage")] [Guard("1eb74a6188c74249")] public static void SetStationStorage_Postfix(PlanetTransport __instance, int stationId, int storageIdx) { if (pendingMax != int.MinValue) { int max = pendingMax; pendingMax = int.MinValue; StationComponent stationComponent = __instance.GetStationComponent(stationId); if (stationComponent != null && stationComponent.storage != null && storageIdx >= 0 && storageIdx < stationComponent.storage.Length) { stationComponent.storage[storageIdx].max = max; } } } [HarmonyPostfix] [HarmonyPatch(typeof(UIStationStorage), "_OnUpdate")] [Guard("957c0ae7be9f0a0b")] public static void Storage_OnUpdate(UIStationStorage __instance) { if (Settings.ChangeCapacityUI && __instance.station != null && !((Object)(object)__instance.maxValueText == (Object)null)) { Attach((Component)(object)__instance, __instance.maxValueText, delegate { EditCapacity(__instance.station, __instance.index, __instance.stationWindow.transport); }); } } [HarmonyPostfix] [HarmonyPatch(typeof(UIControlPanelStationStorage), "_OnUpdate")] [Guard("5fb4930620470ae4")] public static void PanelStorage_OnUpdate(UIControlPanelStationStorage __instance) { if (Settings.ChangeCapacityUI && __instance.isStationDataValid && !((Object)(object)__instance.maxValueText == (Object)null) && __instance.station != null) { Attach((Component)(object)__instance, __instance.maxValueText, delegate { EditCapacity(__instance.station, __instance.index, __instance.masterInspector.transport); }); } } [HarmonyPrefix] [HarmonyPatch(typeof(UIStationStorage), "RefreshValues")] [Guard("94abf08893f0dfc3")] public static void Refresh_Prefix() { if (Settings.ChangeCapacityUI) { refreshDepth++; } } [HarmonyPostfix] [HarmonyPatch(typeof(UIStationStorage), "RefreshValues")] [Guard("94abf08893f0dfc3")] public static void Refresh_Postfix() { if (Settings.ChangeCapacityUI) { refreshDepth--; } } [HarmonyPrefix] [HarmonyPatch(typeof(UIControlPanelStationStorage), "RefreshValues")] [Guard("dd4005879a70d9e4")] public static void PanelRefresh_Prefix() { if (Settings.ChangeCapacityUI) { refreshDepth++; } } [HarmonyPostfix] [HarmonyPatch(typeof(UIControlPanelStationStorage), "RefreshValues")] [Guard("dd4005879a70d9e4")] public static void PanelRefresh_Postfix() { if (Settings.ChangeCapacityUI) { refreshDepth--; } } [HarmonyPrefix] [HarmonyPatch(typeof(UIStationStorage), "OnMaxSliderValueChange")] [Guard("a168bac3333c06e9")] public static bool Slider_Prefix() { if (Settings.ChangeCapacityUI) { return refreshDepth <= 0; } return true; } [HarmonyPrefix] [HarmonyPatch(typeof(UIControlPanelStationStorage), "OnMaxSliderValueChange")] [Guard("7aa31034fac15357")] public static bool PanelSlider_Prefix() { if (Settings.ChangeCapacityUI) { return refreshDepth <= 0; } return true; } [HarmonyPostfix] [HarmonyPatch(typeof(UIStationWindow), "_OnUpdate")] [Guard("6c606ffa0548b6f2")] public static void Window_OnUpdate(UIStationWindow __instance) { if (__instance.stationId == 0 || __instance.transport == null) { return; } StationComponent val = __instance.transport.stationPool[__instance.stationId]; if (val == null || val.id != __instance.stationId) { return; } if (Settings.ChangePowerUI && (Object)(object)__instance.maxChargePowerValue != (Object)null) { Attach((Component)(object)__instance, __instance.maxChargePowerValue, delegate { StationComponent val2 = Current(__instance.transport, __instance.stationId); if (val2 != null) { EditPower(__instance.factory, val2, __instance.maxChargePowerSlider, __instance.maxChargePowerValue); } }); } if (Settings.ChangeMinerSpeedUI && (Object)(object)__instance.maxMiningSpeedValue != (Object)null) { Attach((Component)(object)__instance.maxMiningSpeedValue, __instance.maxMiningSpeedValue, delegate { StationComponent val2 = Current(__instance.transport, __instance.stationId); if (val2 != null) { EditMiner(__instance.factory, val2, __instance.maxMiningSpeedSlider, __instance.maxMiningSpeedValue); } }); } if (!Settings.ChangeEnergyMaxUI || !((Object)(object)__instance.energyText != (Object)null)) { return; } Attach((Component)(object)__instance.energyText, __instance.energyText, delegate { StationComponent val2 = Current(__instance.transport, __instance.stationId); if (val2 != null) { EditEnergy(val2); } }); } private static StationComponent Current(PlanetTransport transport, int stationId) { if (transport == null || stationId <= 0 || stationId >= transport.stationPool.Length) { return null; } StationComponent val = transport.stationPool[stationId]; if (val == null || val.id != stationId) { return null; } return val; } [HarmonyPostfix] [HarmonyPatch(typeof(UIControlPanelStationInspector), "_OnUpdate")] [Guard("b89aade680ae7db9")] public static void Inspector_OnUpdate(UIControlPanelStationInspector __instance) { if (__instance.stationId == 0 || __instance.factory == null || __instance.transport == null) { return; } StationComponent val = __instance.transport.stationPool[__instance.stationId]; if (val == null || val.id != __instance.stationId) { return; } if (Settings.ChangePowerUI && (Object)(object)__instance.maxChargePowerValue != (Object)null) { Attach((Component)(object)__instance, __instance.maxChargePowerValue, delegate { StationComponent val2 = Current(__instance.transport, __instance.stationId); if (val2 != null) { EditPower(__instance.factory, val2, __instance.maxChargePowerSlider, __instance.maxChargePowerValue); } }); } if (!Settings.ChangeMinerSpeedUI || !((Object)(object)__instance.maxMiningSpeedValue != (Object)null)) { return; } Attach((Component)(object)__instance.maxMiningSpeedValue, __instance.maxMiningSpeedValue, delegate { StationComponent val2 = Current(__instance.transport, __instance.stationId); if (val2 != null) { EditMiner(__instance.factory, val2, __instance.maxMiningSpeedSlider, __instance.maxMiningSpeedValue); } }); } [HarmonyPostfix] [HarmonyPatch(typeof(UIMinerWindow), "_OnUpdate")] [Guard("58681ea0364989f7")] public static void Miner_OnUpdate(UIMinerWindow __instance) { if (!Settings.ChangeMinerSpeedUI || __instance.minerId == 0 || __instance.factory == null || (Object)(object)__instance.speedText == (Object)null) { return; } Attach((Component)(object)__instance, __instance.speedText, delegate { int speed = __instance.factorySystem.minerPool[__instance.minerId].speed; PopNumber.Show(Line.op_Implicit(Lang.En("Mining speed").ZhCN("采集效率")), speed.ToString(), FieldValue("MinerComponent.speed", "速度值(界面百分比 = 该值 / 100)", "speed (shown percent = value / 100)", speed), (ContentType)2, delegate(string text) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) if (int.TryParse(text.Trim(), out var result)) { MinerComponent val = __instance.factorySystem.minerPool[__instance.minerId]; val.speed = ClampMiner(result, null); __instance.factorySystem.minerPool[__instance.minerId] = val; } }); }); } private static void EditCapacity(StationComponent station, int index, PlanetTransport transport) { if (station == null || station.storage == null || index < 0 || index >= station.storage.Length) { return; } int max = station.storage[index].max; PopNumber.Show(Line.op_Implicit(Lang.En("Item capacity").ZhCN("物品容量")), max.ToString(), FieldValue("StationStore.max", "个", "items", max), (ContentType)2, delegate(string text) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0050: 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_0056: Unknown result type (might be due to invalid IL or missing references) if (!int.TryParse(text.Trim(), out var result) || result < 0) { return; } StationStore val = station.storage[index]; userEdit = true; try { transport.SetStationStorage(station.id, index, val.itemId, result, val.localLogic, val.remoteLogic, GameMain.mainPlayer); } finally { userEdit = false; } }); } private static void EditPower(PlanetFactory factory, StationComponent station, Slider slider, Text label) { if (factory == null || station.pcId <= 0 || station.pcId >= factory.powerSystem.consumerCursor) { return; } long workEnergyPerTick = factory.powerSystem.consumerPool[station.pcId].workEnergyPerTick; PopNumber.Show(Line.op_Implicit(Lang.En("Charge power").ZhCN("充电功率")), workEnergyPerTick.ToString(), FieldValue("workEnergyPerTick", "焦耳每帧", "joules per tick", workEnergyPerTick), (ContentType)2, delegate(string text) { if (long.TryParse(text.Trim(), out var result) && result >= 0) { if (!Settings.BreakLimit && (Object)(object)slider != (Object)null) { long num = (long)((double)slider.minValue * 50000.0); long num2 = (long)((double)slider.maxValue * 50000.0); if (result < num) { result = num; } if (result > num2) { result = num2; } } factory.powerSystem.consumerPool[station.pcId].workEnergyPerTick = result; if ((Object)(object)label != (Object)null) { label.text = FormatChargePowerLabel(result); } if ((Object)(object)slider != (Object)null) { float num3 = (float)((double)result / 50000.0); if (num3 >= slider.minValue && num3 <= slider.maxValue) { slider.SetValueWithoutNotify(num3); } } } }); } private static void EditMiner(PlanetFactory factory, StationComponent station, Slider slider, Text label) { if (factory == null || !station.isVeinCollector || station.minerId <= 0 || station.minerId >= factory.factorySystem.minerCursor) { return; } int speed = factory.factorySystem.minerPool[station.minerId].speed; PopNumber.Show(Line.op_Implicit(Lang.En("Mining speed").ZhCN("采集效率")), speed.ToString(), FieldValue("MinerComponent.speed", "速度值(界面百分比 = 该值 / 100)", "speed (shown percent = value / 100)", speed), (ContentType)2, delegate(string text) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_005f: 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_0079: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) if (int.TryParse(text.Trim(), out var result)) { MinerComponent val = factory.factorySystem.minerPool[station.minerId]; val.speed = ClampMiner(result, slider); factory.factorySystem.minerPool[station.minerId] = val; if ((Object)(object)label != (Object)null) { label.text = ((float)val.speed / 100f).ToString("0") + " %"; } if ((Object)(object)slider != (Object)null) { float num = (float)(val.speed - 10000) / 1000f; if (num >= slider.minValue && num <= slider.maxValue) { slider.SetValueWithoutNotify(num); } } } }); } private static int ClampMiner(int value, Slider slider) { if (Settings.BreakLimit || (Object)(object)slider == (Object)null) { return value; } int num = Mathf.RoundToInt(slider.minValue * 1000f + 10000f); int num2 = Mathf.RoundToInt(slider.maxValue * 1000f + 10000f); if (value < num) { return num; } if (value <= num2) { return value; } return num2; } private static void EditEnergy(StationComponent station) { PopNumber.Show(Line.op_Implicit(Lang.En("Charge cap").ZhCN("充电上限")), station.energyMax.ToString(), FieldValue("energyMax", "焦耳", "joules", station.energyMax), (ContentType)2, delegate(string text) { if (long.TryParse(text.Trim(), out var result) && result >= 1) { station.energyMax = result; if (station.energy > station.energyMax) { station.energy = station.energyMax; } } }); } private static string FormatChargePowerLabel(long workEnergyPerTick) { StringBuilder stringBuilder = new StringBuilder(" W", 12); StringBuilderUtility.WriteKMG(stringBuilder, 8, workEnergyPerTick * 60, true, '\u2009', ' '); return stringBuilder.ToString(); } private static string FieldValue(string variable, string unitZh, string unitEn, long current) { return Line.op_Implicit(Lang.En($"In-game variable: {variable}\nUnit: {unitEn}\nCurrent value: {current}").ZhCN($"游戏内的变量名为 {variable}\n单位是{unitZh}\n目前的值为 {current}")); } private static void Attach(Component owner, Text label, Action action) { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: 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_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009b: 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_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Expected O, but got Unknown if ((Object)(object)label == (Object)null || (Object)(object)((Component)label).transform.Find("station-assistant-dbl") != (Object)null) { return; } GameObject val = new GameObject("station-assistant-dbl", new Type[3] { typeof(RectTransform), typeof(Image), typeof(Button) }); val.transform.SetParent(((Component)label).transform, false); RectTransform val2 = (RectTransform)val.transform; val2.anchorMin = Vector2.zero; val2.anchorMax = Vector2.one; val2.offsetMin = Vector2.zero; val2.offsetMax = Vector2.zero; ((Graphic)val.GetComponent<Image>()).color = new Color(0f, 0f, 0f, 0f); float last = 0f; ((UnityEvent)val.GetComponent<Button>().onClick).AddListener((UnityAction)delegate { float unscaledTime = Time.unscaledTime; if (unscaledTime - last <= 0.35f) { last = 0f; action(); } else { last = unscaledTime; } }); } } [BepInPlugin("com.yummi.dsp.stationassistant", "Station Assistant", "0.1.8")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string PluginGuid = "com.yummi.dsp.stationassistant"; public const string PluginName = "Station Assistant"; public const string PluginVersion = "0.1.8"; private static readonly Harmony harmony = new Harmony("com.yummi.dsp.stationassistant"); private static readonly PatchOptions HarnessOptions = new PatchOptions { ModName = "Station Assistant" }; internal static ManualLogSource Log; internal static Plugin Instance { get; private set; } private void Awake() { Instance = this; Log = ((BaseUnityPlugin)this).Logger; Settings.Bind(((BaseUnityPlugin)this).Config); CatFeature.Apply(); MainMenuBootstrap.Init((BaseUnityPlugin)(object)this); ConflictStartup.BeginScan((BaseUnityPlugin)(object)this); Harness.RegisterConflict("Station Assistant", "local.logisticsstationslots", "LogisticsStationSlots", (string)null); Harness.PatchAll(harmony, typeof(MainMenuBootstrap), HarnessOptions); Log.LogInfo((object)"Station Assistant v0.1.8 等待主菜单就绪后再启用"); } internal void ApplyPatches() { if (LogisticsStationSlotsConflict.IsPresent()) { Log.LogError((object)LogisticsStationSlotsConflict.GetErrorMessage()); return; } Harness.PatchAll(harmony, typeof(StationExpandPatch), HarnessOptions); Harness.PatchAll(harmony, typeof(StationLogicPatch), HarnessOptions); Harness.PatchAll(harmony, typeof(StationWindowPatch), HarnessOptions); Harness.PatchAll(harmony, typeof(ControlPanelStoragePaging), HarnessOptions); Harness.PatchAll(harmony, typeof(WheelZoomGuard), HarnessOptions); Harness.PatchAll(harmony, typeof(HoverIconPatch), HarnessOptions); Harness.PatchAll(harmony, typeof(NumericEditPatch), HarnessOptions); Harness.PatchAll(harmony, typeof(DuplicateItemPatch), HarnessOptions); Harness.PatchAll(harmony, typeof(ModSaveBridge), HarnessOptions); Log.LogInfo((object)"Station Assistant v0.1.8 已加载"); } private void OnDestroy() { harmony.UnpatchSelf(); } } internal static class PopNumber { private sealed class EscClose : MonoBehaviour { internal UIMessageBox box; internal InputField field; private bool wasFocused; private void Update() { if ((Object)(object)box == (Object)null || (Object)(object)field == (Object)null) { ((Behaviour)this).enabled = false; } else if (Input.GetKeyDown((KeyCode)27) && (wasFocused || field.isFocused)) { ((Behaviour)this).enabled = false; box.OnButton1Click(); } else { wasFocused = field.isFocused; } } } private sealed class Follow : MonoBehaviour { internal Text text; internal RectTransform window; internal float gap; private int frames; private void LateUpdate() { //IL_0054: 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_006b: Expected O, but got Unknown Vector3 bottomLocal; if ((Object)(object)text == (Object)null || (Object)(object)window == (Object)null || frames++ > 30) { ((Behaviour)this).enabled = false; } else if (TryGlyphBottom(text, window, out bottomLocal)) { Place((RectTransform)((Component)this).transform, window, bottomLocal, gap); } } } internal static void Show(string title, string initial, string message, ContentType content, Action<string> onConfirm) { //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Expected O, but got Unknown //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Expected O, but got Unknown InputField val = NumberField(); if ((Object)(object)val == (Object)null) { return; } string text = Localization.Translate("Cancel"); string text2 = Localization.Translate("OK"); InputField field = null; UIMessageBox val2 = UIMessageBox.Show(title, message, text, text2, 2, (Response)null, (Response)delegate { if ((Object)(object)field != (Object)null) { onConfirm?.Invoke(field.text); } }); if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.m_WindowTrans == (Object)null) && !((Object)(object)val2.m_MessageText == (Object)null)) { field = Object.Instantiate<InputField>(val, (Transform)(object)val2.m_WindowTrans); ((Object)((Component)field).gameObject).name = "pop-number"; Prepare(field, content, initial); RectTransform val3 = (RectTransform)((Component)field).transform; float height = SourceHeight(val); ResetRect(val3, height); PlaceBetweenMessageAndButtons(val2, val3, height); EscClose escClose = ((Component)field).gameObject.AddComponent<EscClose>(); escClose.box = val2; escClose.field = field; field.ActivateInputField(); if ((Object)(object)EventSystem.current != (Object)null) { EventSystem.current.SetSelectedGameObject(((Component)field).gameObject); } } } private static InputField NumberField() { UIGame val = (((Object)(object)UIRoot.instance != (Object)null) ? UIRoot.instance.uiGame : null); if ((Object)(object)val != (Object)null && (Object)(object)val.dysonEditor != (Object)null && (Object)(object)val.dysonEditor.controlPanel != (Object)null) { UIDEInspector inspector = val.dysonEditor.controlPanel.inspector; if ((Object)(object)inspector != (Object)null && (Object)(object)inspector.layerInfo != (Object)null && (Object)(object)inspector.layerInfo.input0 != (Object)null) { return inspector.layerInfo.input0; } } if ((Object)(object)val != (Object)null && (Object)(object)val.stationWindow != (Object)null && (Object)(object)val.stationWindow.nameInput != (Object)null) { return val.stationWindow.nameInput; } ManualLogSource log = Plugin.Log; if (log != null) { log.LogWarning((object)"PopNumber:找不到可复制的输入框样板,双击编辑无法弹出。"); } return null; } private static void Prepare(InputField field, ContentType content, string initial) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Expected O, but got Unknown //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Expected O, but got Unknown //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Invalid comparison between Unknown and I4 //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_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) UIInputField component = ((Component)field).GetComponent<UIInputField>(); if ((Object)(object)component != (Object)null) { Object.DestroyImmediate((Object)(object)component); } UIButton component2 = ((Component)field).GetComponent<UIButton>(); if ((Object)(object)component2 != (Object)null) { Object.DestroyImmediate((Object)(object)component2); } field.onValueChanged = new OnChangeEvent(); field.onEndEdit = new EndEditEvent(); ((Selectable)field).interactable = true; field.characterLimit = 0; bool flag = (int)content != 3; field.contentType = (ContentType)(flag ? 2 : 3); field.characterValidation = (CharacterValidation)(flag ? 1 : 2); field.text = initial ?? ""; if ((Object)(object)field.placeholder != (Object)null) { ((Behaviour)field.placeholder).enabled = false; } if ((Object)(object)field.textComponent != (Object)null) { field.textComponent.fontStyle = (FontStyle)0; field.textComponent.alignment = (TextAnchor)4; field.textComponent.horizontalOverflow = (HorizontalWrapMode)1; RectTransform rectTransform = ((Graphic)field.textComponent).rectTransform; rectTransform.anchorMin = Vector2.zero; rectTransform.anchorMax = Vector2.one; rectTransform.pivot = new Vector2(0.5f, 0.5f); rectTransform.offsetMin = new Vector2(4f, 1f); rectTransform.offsetMax = new Vector2(-4f, -1f); } } private static float SourceHeight(InputField source) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) Rect rect = ((RectTransform)((Component)source).transform).rect; float height = ((Rect)(ref rect)).height; if (height < 16f || height > 32f) { return 20f; } return height; } private static void ResetRect(RectTransform rt, float height) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_004b: 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) ((Transform)rt).localScale = Vector3.one; ((Transform)rt).localRotation = Quaternion.identity; rt.anchorMin = new Vector2(0.5f, 0.5f); rt.anchorMax = new Vector2(0.5f, 0.5f); rt.pivot = new Vector2(0.5f, 0.5f); rt.sizeDelta = new Vector2(140f, height); } private static void PlaceBetweenMessageAndButtons(UIMessageBox box, RectTransform inputRt, float height) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: 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_00aa: 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_00d0: 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_0060: 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_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) RectTransform windowTrans = box.m_WindowTrans; RectTransform rectTransform = ((Graphic)box.m_MessageText).rectTransform; windowTrans.sizeDelta += new Vector2(0f, height + 8f); Canvas.ForceUpdateCanvases(); Text messageText = box.m_MessageText; if (!TryGlyphBottom(messageText, windowTrans, out var bottomLocal)) { Vector3[] array = (Vector3[])(object)new Vector3[4]; rectTransform.GetWorldCorners(array); bottomLocal = ((Transform)windowTrans).InverseTransformPoint((array[0] + array[3]) * 0.5f); } ((Transform)inputRt).SetParent((Transform)(object)windowTrans, false); inputRt.anchorMin = new Vector2(0.5f, 0.5f); inputRt.anchorMax = new Vector2(0.5f, 0.5f); inputRt.pivot = new Vector2(0.5f, 1f); inputRt.sizeDelta = new Vector2(140f, height); Place(inputRt, windowTrans, bottomLocal, 8f); Follow follow = ((Component)inputRt).gameObject.AddComponent<Follow>(); follow.text = messageText; follow.window = windowTrans; follow.gap = 8f; } private static void Place(RectTransform inputRt, RectTransform window, Vector3 bottomLocal, float gap) { //IL_0006: 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_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) float num = 0.5f - window.pivot.y; Rect rect = window.rect; float num2 = num * ((Rect)(ref rect)).height; inputRt.anchoredPosition = new Vector2(0f, bottomLocal.y - num2 - gap); } private static bool TryGlyphBottom(Text text, RectTransform window, out Vector3 bottomLocal) { //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_005b: 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_0070: 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_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: 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) bottomLocal = Vector3.zero; if ((Object)(object)text == (Object)null) { return false; } IList<UIVertex> verts = text.cachedTextGenerator.verts; if (verts == null || verts.Count == 0) { ((Graphic)text).Rebuild((CanvasUpdate)3); verts = text.cachedTextGenerator.verts; } if (verts == null || verts.Count == 0) { return false; } float num = float.MaxValue; for (int i = 0; i < verts.Count; i++) { if (verts[i].position.y < num) { num = verts[i].position.y; } } float num2 = ((text.pixelsPerUnit > 0f) ? (1f / text.pixelsPerUnit) : 1f); Vector3 val = ((Transform)((Graphic)text).rectTransform).TransformPoint(new Vector3(0f, num * num2, 0f)); bottomLocal = ((Transform)window).InverseTransformPoint(val); return true; } } internal enum TreatKey { AutoStellar, AutoPlanetary, ManualSlotButton, ExpandOnBuild, ExpandOnOpen, StationScroll, ControlScroll, PageSize } internal static class Settings { internal const int MaxSlots = 32; internal const int ConfigSchemaVersion = 2; private static readonly Dictionary<TreatKey, object> treats = new Dictionary<TreatKey, object>(); private static ConfigEntry<int> autoStellar; private static ConfigEntry<int> autoPlanetary; private static ConfigEntry<bool> expandOnBuild; private static ConfigEntry<bool> expandOnOpen; private static ConfigEntry<bool> manualSlotButton; private static ConfigEntry<bool> stationScroll; private static ConfigEntry<bool> controlScroll; private static ConfigEntry<int> pageSize; private static ConfigEntry<bool> changeCapacityUi; private static ConfigEntry<bool> changePowerUi; private static ConfigEntry<bool> changeMinerSpeedUi; private static ConfigEntry<bool> breakLimit; private static ConfigEntry<bool> changeEnergyMaxUi; private static ConfigEntry<bool> saveExtraSlots; private static ConfigEntry<bool> allowDuplicate; private static ConfigEntry<string> cat; internal static int AutoStellar => SlotSetting(TreatKey.AutoStellar, autoStellar); internal static int AutoPlanetary => SlotSetting(TreatKey.AutoPlanetary, autoPlanetary); internal static bool ManualSlotButton => BoolSetting(TreatKey.ManualSlotButton, manualSlotButton); internal static bool StationScroll => BoolSetting(TreatKey.StationScroll, stationScroll); internal static bool ControlScroll => BoolSetting(TreatKey.ControlScroll, controlScroll); internal static int PageSize { get { object value; int num = (treats.TryGetValue(TreatKey.PageSize, out value) ? Convert.ToInt32(value) : pageSize.Value); if (num < 1) { return 1; } if (num <= 32) { return num; } return 32; } } internal static bool ExpandOnBuild => BoolSetting(TreatKey.ExpandOnBuild, expandOnBuild); internal static bool ExpandOnOpen => BoolSetting(TreatKey.ExpandOnOpen, expandOnOpen); internal static bool ChangeCapacityUI => changeCapacityUi.Value; internal static bool ChangePowerUI => changePowerUi.Value; internal static bool ChangeMinerSpeedUI => changeMinerSpeedUi.Value; internal static bool BreakLimit => breakLimit.Value; internal static bool ChangeEnergyMaxUI => changeEnergyMaxUi.Value; internal static bool SaveExtraSlots => saveExtraSlots.Value; internal static bool AllowDuplicate => allowDuplicate.Value; internal static string CatText => cat.Value ?? ""; private static string Desc(string en, string zh) { return en + "\n" + zh; } internal static void Bind(ConfigFile config) { //IL_0002: 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_0018: Expected O, but got Unknown //IL_0359: Unknown result type (might be due to invalid IL or missing references) //IL_035f: Expected O, but got Unknown Harness.ApplyConfigSchema(config, 2, new ConfigSchemaOptions { WipeIfBelow = 2 }); autoStellar = config.Bind<int>("SlotsChange", "AutoStellarSlots", -1, Desc("Target item-kind slot count for interstellar towers. -1 = do not change. Only increases, never shrinks. Max 32. Uses ExpandOnBuild / ExpandOnOpen below.", "星际物流塔目标物品种类数。-1 不改。只增不减,上限 32。是否生效见 ExpandOnBuild / ExpandOnOpen。")); autoPlanetary = config.Bind<int>("SlotsChange", "AutoPlanetarySlots", -1, Desc("Target item-kind slot count for planetary towers. -1 = do not change. Only increases. Max 32.", "行星物流塔目标物品种类数。-1 不改。只增不减,上限 32。")); expandOnBuild = config.Bind<bool>("SlotsChange", "ExpandOnBuild", false, Desc("When placing a logistics tower, expand storage toward AutoStellarSlots / AutoPlanetarySlots.", "建造物流塔时,按上面的自动数目扩容槽位。")); expandOnOpen = config.Bind<bool>("SlotsChange", "ExpandOnOpen", false, Desc("When opening a tower window, expand storage toward the auto targets (existing towers).", "打开物流塔面板时,按自动数目扩容(对已有塔生效)。")); manualSlotButton = config.Bind<bool>("SlotsChange", "ManualSlotButton", true, Desc("Show the “Slots: N” button on the tower window (planetary / interstellar only).", "物流塔面板右上角显示「槽位数目:N」按钮(仅行星/星际塔)。")); stationScroll = config.Bind<bool>("SlotsScroll", "StationPanelScroll", true, Desc("Page through storage rows in the logistics tower window.", "物流塔面板货物栏分页浏览。")); controlScroll = config.Bind<bool>("SlotsScroll", "ControlPanelScroll", true, Desc("Page through logistics tower storage in the total control panel.", "总控面板里物流塔储物栏分页浏览。")); pageSize = config.Bind<int>("SlotsScroll", "PageSize", 6, Desc("Max storage rows per page in the logistics tower window only (1–32). The total control panel is fixed at 5.", "仅物流塔面板分页时每页最多显示的货物栏行数(1–32)。总控面板固定每页 5 行。")); changeCapacityUi = config.Bind<bool>("Numeric", "ChangeCapacityUI", true, Desc("Double-click item capacity numbers.", "双击物品容量数字。")); changePowerUi = config.Bind<bool>("Numeric", "ChangePowerUI", true, Desc("Double-click charge power (workEnergyPerTick).", "双击充电功率(workEnergyPerTick)。")); changeMinerSpeedUi = config.Bind<bool>("Numeric", "ChangeMinerSpeedUI", true, Desc("Double-click advanced miner mining speed.", "双击大型采矿机采集效率。")); breakLimit = config.Bind<bool>("Numeric", "BreakLimit", false, Desc("Allow typed capacity / power / miner values above vanilla slider limits. Does not affect energyMax.", "双击输入的容量、电力、采集效率可超过原版滑条范围。不影响充电上限。")); changeEnergyMaxUi = config.Bind<bool>("Numeric", "ChangeEnergyMaxUI", false, Desc("Double-click the energy text to edit energyMax (ignores BreakLimit).", "双击电量文字修改 energyMax,不走破限开关。")); saveExtraSlots = config.Bind<bool>("Save", "ExtraSlotsInModSave", true, Desc("Store slots beyond 6 in DSPModSave; vanilla save keeps 6. No effect without DSPModSave.", "超过 6 格写入 DSPModSave,原版存档只留 6 格。未装 DSPModSave 时不运行。")); allowDuplicate = config.Bind<bool>("Items", "AllowDuplicateItems", true, Desc("Allow the same item in multiple storage slots.", "允许同一物品进入多个货物栏。")); cat = config.Bind<string>("Special", "YummiIsAGoodCat", "yes", Desc("Cats are good.", "猫猫是好猫。")); Harness.PruneConfigKeys(config, (ConfigDefinition[])(object)new ConfigDefinition[17] { ((ConfigEntryBase)autoStellar).Definition, ((ConfigEntryBase)autoPlanetary).Definition, ((ConfigEntryBase)expandOnBuild).Definition, ((ConfigEntryBase)expandOnOpen).Definition, ((ConfigEntryBase)manualSlotButton).Definition, ((ConfigEntryBase)stationScroll).Definition, ((ConfigEntryBase)controlScroll).Definition, ((ConfigEntryBase)pageSize).Definition, ((ConfigEntryBase)changeCapacityUi).Definition, ((ConfigEntryBase)changePowerUi).Definition, ((ConfigEntryBase)changeMinerSpeedUi).Definition, ((ConfigEntryBase)breakLimit).Definition, ((ConfigEntryBase)changeEnergyMaxUi).Definition, ((ConfigEntryBase)saveExtraSlots).Definition, ((ConfigEntryBase)allowDuplicate).Definition, ((ConfigEntryBase)cat).Definition, new ConfigDefinition("_ConfigSchema", "Version") }); } internal static void Treat(TreatKey key, object value) { treats[key] = value; } private static int SlotSetting(TreatKey key, ConfigEntry<int> entry) { object value; int num = (treats.TryGetValue(key, out value) ? Convert.ToInt32(value) : entry.Value); if (num < 0) { return -1; } if (num <= 32) { return num; } return 32; } private static bool BoolSetting(TreatKey key, ConfigEntry<bool> entry) { if (!treats.TryGetValue(key, out var value)) { return entry.Value; } return Convert.ToBoolean(value); } } public static class Treat { public static void AutoStellarSlots(int value) { Settings.Treat(TreatKey.AutoStellar, value); } public static void AutoPlanetarySlots(int value) { Settings.Treat(TreatKey.AutoPlanetary, value); } public static void ManualSlotButton(bool value) { Settings.Treat(TreatKey.ManualSlotButton, value); } public static void ExpandOnBuild(bool value) { Settings.Treat(TreatKey.ExpandOnBuild, value); } public static void ExpandOnOpen(bool value) { Settings.Treat(TreatKey.ExpandOnOpen, value); } public static void StationPanelScroll(bool value) { Settings.Treat(TreatKey.StationScroll, value); } public static void ControlPanelScroll(bool value) { Settings.Treat(TreatKey.ControlScroll, value); } public static void PageSize(int value) { Settings.Treat(TreatKey.PageSize, value); } } internal static class SlotStorage { internal const int PlanetaryItemId = 2103; internal const int StellarItemId = 2104; internal const int VanillaKeep = 6; internal static bool IsCollectorOrVeinCollector(StationComponent station) { if (station != null) { if (!station.isCollector) { return station.isVeinCollector; } return true; } return false; } internal static bool TryGetLogisticsTowerKind(StationComponent station, out bool stellar) { stellar = false; if (station == null || station.storage == null || IsCollectorOrVeinCollector(station)) { return false; } PlanetFactory val = FindFactory(station); if (val == null || station.entityId <= 0 || station.entityId >= val.entityPool.Length) { return Fallback(station, out stellar); } int modelIndex = val.entityPool[station.entityId].modelIndex; PrefabDesc val2 = ((ProtoSet<ModelProto>)(object)LDB.models).Select(modelIndex)?.prefabDesc; if (val2 != null && (val2.isCollectStation || val2.isVeinCollector)) { return false; } if (IsVanillaItemModel(modelIndex, 2104)) { stellar = true; return true; } if (IsVanillaItemModel(modelIndex, 2103)) { stellar = false; return true; } if (val2 != null && val2.isStation) { stellar = val2.isStellarStation; return true; } return Fallback(station, out stellar); } private static bool Fallback(StationComponent station, out bool stellar) { stellar = station.isStellar; return true; } private static PlanetFactory FindFactory(StationComponent station) { GameData data = GameMain.data; if (data == null) { return null; } if (station.planetId > 0) { GalaxyData galaxy = data.galaxy; PlanetFactory val = ((galaxy == null) ? null : galaxy.PlanetById(station.planetId)?.factory); if (val != null) { return val; } } PlanetFactory val2 = data.localPlanet?.factory; if (Owns(val2, station)) { return val2; } if (data.factories != null) { for (int i = 0; i < data.factoryCount && i < data.factories.Length; i++) { if (Owns(data.factories[i], station)) { return data.factories[i]; } } } return null; } private static bool Owns(PlanetFactory factory, StationComponent station) { if (factory == null || factory.transport == null || factory.transport.stationPool == null) { return false; } StationComponent[] stationPool = factory.transport.stationPool; if (station.id > 0 && station.id < stationPool.Length) { return stationPool[station.id] == station; } return false; } private static bool IsVanillaItemModel(int modelIndex, int itemId) { ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select(itemId); if (val == null || val.ModelCount < 1) { return false; } if (modelIndex >= val.ModelIndex) { return modelIndex < val.ModelIndex + val.ModelCount; } return false; } internal static bool IsTower(StationComponent station) { bool stellar; return TryGetLogisticsTowerKind(station, out stellar); } internal static int AutoTarget(StationComponent station) { if (!TryGetLogisticsTowerKind(station, out var stellar)) { return -1; } if (!stellar) { return Settings.AutoPlanetary; } return Settings.AutoStellar; } internal static void ExpandIfNeeded(StationComponent station, bool onBuild) { if (!(onBuild ? (!Settings.ExpandOnBuild) : (!Settings.ExpandOnOpen)) && IsTower(station)) { int num = AutoTarget(station); if (num >= 0 && station.storage.Length < num) { Resize(station, num); } } } internal static void SetCount(PlanetFactory factory, StationComponent station, int count) { if (!IsTower(station) || factory == null) { return; } if (count < 1) { count = 1; } if (count > 32) { count = 32; } if (count == station.storage.Length) { return; } if (count < station.storage.Length) { for (int num = station.storage.Length - 1; num >= count; num--) { factory.transport.SetStationStorage(station.id, num, 0, 0, (ELogisticStorage)0, (ELogisticStorage)0, GameMain.mainPlayer); } } Resize(station, count); } internal static void Resize(StationComponent station, int count) { StationStore[] array = (StationStore[])(object)new StationStore[count]; Array.Copy(station.storage, array, Math.Min(station.storage.Length, count)); StationPriorityLock[] array2 = (StationPriorityLock[])(object)new StationPriorityLock[count]; if (station.priorityLocks != null) { Array.Copy(station.priorityLocks, array2, Math.Min(station.priorityLocks.Length, count)); } lock (station.storage) { station.priorityLocks = array2; station.storage = array; } } } internal static class Pages { internal static int Count(int slots, int pageSize) { if (pageSize < 1) { pageSize = 1; } if (slots <= pageSize) { return 1; } return (slots + pageSize - 1) / pageSize; } internal static int Start(int page, int slots, int pageSize) { int num = Count(slots, pageSize); if (page < 0) { page = 0; } if (page >= num) { page = num - 1; } if (num <= 1) { return 0; } if (page >= num - 1) { return slots - pageSize; } return page * pageSize; } } [HarmonyPatch] public static class StationExpandPatch { [HarmonyPostfix] [HarmonyPatch(typeof(StationComponent), "Init")] [Guard("7f968c39fde5bbec")] public static void StationComponent_Init_Postfix(StationComponent __instance) { SlotStorage.ExpandIfNeeded(__instance, onBuild: true); } } [HarmonyPatch] public static class StationLogicPatch { private const int VanillaNeedsLength = 6; private const int WarperItemId = 1210; [ThreadStatic] private static int[] needsChunk; private static int[] GetNeedsChunk(int[] needs, int start) { int[] array = needsChunk ?? (needsChunk = new int[6]); bool flag = false; for (int i = 0; i < 6; i++) { int num = start + i; array[i] = ((num < needs.Length) ? needs[num] : 0); flag |= array[i] > 0; } if (!flag) { return null; } return array; } [HarmonyPostfix] [HarmonyPatch(typeof(StationComponent), "UpdateNeeds")] [Guard("87833a246c679fc8")] public static void UpdateNeeds_Postfix(StationComponent __instance) { StationStore[] storage = __instance.storage; int num = storage.Length; if (num <= 5) { return; } lock (storage) { int[] array = __instance.needs; if (array == null || array.Length != num + 1) { array = new int[num + 1]; } bool flag = false; bool flag2 = false; for (int i = 0; i < num; i++) { array[i] = ((storage[i].count < storage[i].max) ? storage[i].itemId : 0); } array[num] = ((__instance.isStellar && __instance.warperCount < __instance.warperMaxCount) ? 1210 : 0); for (int j = 0; j < array.Length; j++) { if (array[j] != 0) { if (j < 6) { flag = true; } else { flag2 = true; } } } if (!flag && flag2) { array[0] = -1; } __instance.needs = array; } } [HarmonyPrefix] [HarmonyPatch(typeof(StationComponent), "UpdateInputSlots")] [Guard("0f49824d6f59bbd9")] public static void UpdateInputSlots_Prefix(StationComponent __instance, out long __state) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Invalid comparison between Unknown and I4 __state = 0L; if (__instance.needs == null || __instance.needs.Length <= 6) { return; } SlotData[] slots = __instance.slots; for (int i = 0; i < slots.Length && i < 64; i++) { if ((int)slots[i].dir == 2 && slots[i].counter == 0 && slots[i].beltId != 0) { __state |= 1L << i; } } } [HarmonyPostfix] [HarmonyPatch(typeof(StationComponent), "UpdateInputSlots")] [Guard("0f49824d6f59bbd9")] public static void UpdateInputSlots_Postfix(StationComponent __instance, CargoTraffic traffic, long __state) { if (__state == 0L) { return; } int[] needs = __instance.needs; SlotData[] slots = __instance.slots; BeltComponent[] beltPool = traffic.beltPool; int num2 = default(int); byte b = default(byte); byte b2 = default(byte); for (int i = 0; i < slots.Length && i < 64; i++) { if ((__state & (1L << i)) == 0L) { continue; } ref SlotData reference = ref slots[i]; if (reference.counter != 0 || reference.beltId == 0) { continue; } CargoPath cargoPath = traffic.GetCargoPath(beltPool[reference.beltId].segPathId); if (cargoPath == null) { continue; } for (int j = 6; j < needs.Length; j += 6) { int[] array = GetNeedsChunk(needs, j); if (array != null) { int num = cargoPath.TryPickItemAtRear(array, ref num2, ref b, ref b2); if (num2 >= 0) { __instance.InputItem(num, j + num2, (int)b, (int)b2); reference.storageIdx = j + num2 + 1; reference.counter = 1; break; } } } } } [HarmonyPostfix] [HarmonyPatch(/*Could not decode attribute arguments.*/)] [Guard("c5ca122186e845f3")] public static void PickFrom_Entity_Postfix(PlanetFactory __instance, ref int __result, int entityId, int offset, int filter, int[] needs, ref byte stack, ref byte inc) { if (__result != 0 || needs == null || needs.Length <= 6) { return; } for (int i = 6; i < needs.Length; i += 6) { int[] array = GetNeedsChunk(needs, i); if (array != null) { __result = __instance.PickFrom(entityId, offset, filter, array, ref stack, ref inc); if (__result != 0) { break; } } } } [HarmonyPostfix] [HarmonyPatch(/*Could not decode attribute arguments.*/)] [Guard("fc3da46f7f47bcc2")] public static void PickFrom_Typed_Postfix(PlanetFactory __instance, ref int __result, uint ioTargetTypedId, int offset, int filter, int[] needs, ref byte stack, ref byte inc) { if (__result != 0 || needs == null || needs.Length <= 6) { return; } for (int i = 6; i < needs.Length; i += 6) { int[] array = GetNeedsChunk(needs, i); if (array != null) { __result = __instance.PickFrom(ioTargetTypedId, offset, filter, array, ref stack, ref inc); if (__result != 0) { break; } } } } [HarmonyPostfix] [HarmonyPatch(typeof(StationComponent), "AddItem")] [Guard("806f415ada529868")] public static void AddItem_Postfix(StationComponent __instance, ref int __result, int itemId, int count, int inc) { StationStore[] storage = __instance.storage; if (__result != 0 || itemId <= 0 || storage.Length <= 6) { return; } lock (storage) { for (int i = 6; i < storage.Length; i++) { if (storage[i].itemId == itemId) { storage[i].count += count; storage[i].inc += inc; __result = count; break; } } } } [HarmonyPostfix] [HarmonyPatch(typeof(StationComponent), "UpdateKeepMode")] [Guard("368147d80661e649")] public static void UpdateKeepMode_Postfix(StationComponent __instance) { StationStore[] storage = __instance.storage; if (storage.Length <= 5) { return; } lock (storage) { for (int i = 5; i < storage.Length; i++) { ref StationStore reference = ref storage[i]; if (reference.keepMode > 0 && reference.itemId > 0) { reference.count = ((reference.keepMode <= 2) ? (reference.max / reference.keepMode) : 0); reference.inc = ((reference.keepMode <= 2) ? ((int)((float)reference.count * reference.keepIncRatio + 1E-05f)) : 0); } } } } [HarmonyPrefix] [HarmonyPatch(typeof(StationComponent), "HasLocalSupply")] [Guard("68234e7bf877386b")] public static bool HasLocalSupply_Prefix(StationComponent __instance, int itemId, int countAtLeast, ref int __result) { return Find(__instance, itemId, countAtLeast, local: true, supply: true, ref __result); } [HarmonyPrefix] [HarmonyPatch(typeof(StationComponent), "HasLocalDemand")] [Guard("e92c52e15b73611e")] public static bool HasLocalDemand_Prefix(StationComponent __instance, int itemId, int countAtLeast, ref int __result) { return Find(__instance, itemId, countAtLeast, local: true, supply: false, ref __result); } [HarmonyPrefix] [HarmonyPatch(typeof(StationComponent), "HasRemoteSupply")] [Guard("df30025f5d70ce61")] public static bool HasRemoteSupply_Prefix(StationComponent __instance, int itemId, int countAtLeast, ref int __result) { return Find(__instance, itemId, countAtLeast, local: false, supply: true, ref __result); } [HarmonyPrefix] [HarmonyPatch(typeof(StationComponent), "HasRemoteDemand")] [Guard("9dfdc98090d92471")] public static bool HasRemoteDemand_Prefix(StationComponent __instance, int itemId, int countAtLeast, ref int __result) { return Find(__instance, itemId, countAtLeast, local: false, supply: false, ref __result); } private static bool Find(StationComponent station, int itemId, int countAtLeast, bool local, bool supply, ref int result) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) StationStore[] storage = station.storage; if (storage == null || storage.Length <= 6) { return true; } result = -1; ELogisticStorage val = (ELogisticStorage)(supply ? 1 : 2); for (int i = 0; i < storage.Length; i++) { ELogisticStorage val2 = (local ? storage[i].localLogic : storage[i].remoteLogic); if (storage[i].itemId == itemId && val2 == val && (supply ? storage[i].count : (storage[i].max - storage[i].count)) >= countAtLeast) { result = i; return false; } } return false; } } [HarmonyPatch] public static class StationWindowPatch { private const int RowTop = -90; private const int RowHeight = 76; private const float ScreenMargin = 80f; private static readonly FieldRef<UIStationWindow, UIStationStorage[]> storageUIsRef = AccessTools.FieldRefAccess<UIStationWindow, UIStationStorage[]>("storageUIs"); private static int page; private static int lastStationId; private static float lastWheel; private static float nextPageTime; private static UIStationWindow lastWindow; private static RectTransform chrome; private static Text pageLabel; internal static bool CursorOverPagingArea() { if (!Settings.StationScroll || (Object)(object)lastWindow == (Object)null || lastWindow.stationId == 0) { return false; } if (!((Component)lastWindow).gameObject.activeInHierarchy) { return false; } return MouseOver(lastWindow.windowTrans); } [HarmonyPrefix] [HarmonyPatch(typeof(UIStationWindow), "OnStationIdChange")] [Guard("a94c837d579532f7")] public static void OnStationIdChange_Prefix(UIStationWindow __instance) { if (((ManualBehaviour)__instance).active && __instance.transport != null && __instance.stationId > 0) { StationComponent val = __instance.transport.stationPool[__instance.stationId]; if (val != null && val.id == __instance.stationId && val.storage != null && SlotStorage.IsTower(val)) { SlotStorage.ExpandIfNeeded(val, onBuild: false); int count = (Settings.StationScroll ? Settings.PageSize : val.storage.Length); EnsureRow