From c99c59a117ef83c013eea9cec9bcdef3199d5809 Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Wed, 29 Oct 2025 22:30:10 +0800 Subject: [PATCH] work in progress --- LogisticHub/Module/Miner.cs | 6 ++-- LogisticHub/Module/StationManager.cs | 43 +++++++++++++++------------- LogisticHub/Module/VeinManager.cs | 12 +++++++- 3 files changed, 36 insertions(+), 25 deletions(-) diff --git a/LogisticHub/Module/Miner.cs b/LogisticHub/Module/Miner.cs index 13856d2..3141ef8 100644 --- a/LogisticHub/Module/Miner.cs +++ b/LogisticHub/Module/Miner.cs @@ -1,7 +1,6 @@ using System; using BepInEx.Configuration; using HarmonyLib; -using UnityEngine; using UXAssist.Common; using Random = UnityEngine.Random; using GameLogicProc = UXAssist.Common.GameLogic; @@ -72,7 +71,6 @@ public class Miner : PatchImpl private static void OnGameBegin() { - VeinManager.Clear(); _frame = 0L; UpdateMiningCostRate(); UpdateSpeedScale(); @@ -135,7 +133,6 @@ public class Miner : PatchImpl var frameCounter = _frame / 1200000L; if (frameCounter <= 0) return; _frame -= frameCounter * 1200000L; - // LogisticHub.Logger.LogDebug($"FrameCounter: {frameCounter}"); DeepProfiler.BeginSample(DPEntry.Miner); var data = GameMain.data; @@ -155,6 +152,7 @@ public class Miner : PatchImpl { foreach (var storageIndex in demands[itemIndex]) { + LogisticHub.Logger.LogDebug($"StorageIndex: {storageIndex}"); var station = planetTransport.stationPool[storageIndex / 100]; if (station == null) continue; @@ -195,7 +193,7 @@ public class Miner : PatchImpl for (var i = planetTransport.stationCursor - 1; i > 0; i--) { var stationComponent = planetTransport.stationPool[i]; - if (stationComponent.isCollector || stationComponent.isVeinCollector || stationComponent.energy * 2 >= stationComponent.energyMax) continue; + if (stationComponent == null || stationComponent.isCollector || stationComponent.isVeinCollector || stationComponent.energy * 2 >= stationComponent.energyMax) continue; var index = (stationComponent.isStellar ? FuelIlsSlot.Value : FuelPlsSlot.Value) - 1; var storage = stationComponent.storage; if (index < 0 || index >= storage.Length) diff --git a/LogisticHub/Module/StationManager.cs b/LogisticHub/Module/StationManager.cs index 58f0c5b..8b75631 100644 --- a/LogisticHub/Module/StationManager.cs +++ b/LogisticHub/Module/StationManager.cs @@ -54,34 +54,37 @@ public class StationManager : PatchImpl public static void Init() { - GameLogicProc.OnGameBegin += () => - { - _stations = null; - var data = GameMain.data; - for (var index = data.factoryCount - 1; index >= 0; index--) - { - var factory = data.factories[index]; - if (factory == null || factory.index != index) continue; - var planetIndex = factory.index; - var stations = StationsByPlanet(planetIndex); - var transport = factory.transport; - var pool = transport.stationPool; - for (var i = transport.stationCursor - 1; i > 0; i--) - { - var station = pool[i]; - if (station == null || station.id != i || station.isCollector || station.isVeinCollector) continue; - UpdateStationInfo(stations, station); - } - } - }; + GameLogicProc.OnGameBegin += OnGameBegin; Enable(true); } public static void Uninit() { + GameLogicProc.OnGameBegin -= OnGameBegin; Enable(false); } + private static void OnGameBegin() + { + _stations = null; + var data = GameMain.data; + for (var index = data.factoryCount - 1; index >= 0; index--) + { + var factory = data.factories[index]; + if (factory == null || factory.index != index) continue; + var planetIndex = factory.index; + var stations = StationsByPlanet(planetIndex); + var transport = factory.transport; + var pool = transport.stationPool; + for (var i = transport.stationCursor - 1; i > 0; i--) + { + var station = pool[i]; + if (station == null || station.id != i || station.isCollector || station.isVeinCollector) continue; + UpdateStationInfo(stations, station); + } + } + } + private static int ItemIdToIndex(int itemId) { return itemId switch diff --git a/LogisticHub/Module/VeinManager.cs b/LogisticHub/Module/VeinManager.cs index 17f0b87..ee8edec 100644 --- a/LogisticHub/Module/VeinManager.cs +++ b/LogisticHub/Module/VeinManager.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using HarmonyLib; using UXAssist.Common; +using GameLogicProc = UXAssist.Common.GameLogic; namespace LogisticHub.Module; @@ -19,16 +20,25 @@ public class VeinManager : PatchImpl public static void Init() { Enable(true); + GameLogicProc.OnGameBegin += OnGameBegin; } public static void Uninit() { + GameLogicProc.OnGameBegin -= OnGameBegin; Enable(false); } - public static void Clear() + private static void OnGameBegin() { _veins = null; + var data = GameMain.data; + for (var index = data.factoryCount - 1; index >= 0; index--) + { + var factory = data.factories[index]; + if (factory == null || factory.index != index) continue; + RecalcVeins(factory); + } } public static ProductVeinData[] GetVeins(int planetIndex)