From 66cbb5fa199eebbf3758f462c8b560e2fad2aa06 Mon Sep 17 00:00:00 2001 From: starfish <50672801+starfi5h@users.noreply.github.com> Date: Tue, 2 Apr 2024 17:25:34 +0800 Subject: [PATCH] try-catch ILSIdleShipBackToWork and ILSWorkShipBackToIdle --- .../ILSIdleShipBackToWorkProcessor.cs | 13 +++++----- .../ILSWorkShipBackToIdleProcessor.cs | 10 ++++++-- NebulaWorld/Logistics/ILSShipManager.cs | 24 ++++++++++--------- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/NebulaNetwork/PacketProcessors/Logistics/ILSIdleShipBackToWorkProcessor.cs b/NebulaNetwork/PacketProcessors/Logistics/ILSIdleShipBackToWorkProcessor.cs index 1ccdd993e..187862c75 100644 --- a/NebulaNetwork/PacketProcessors/Logistics/ILSIdleShipBackToWorkProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Logistics/ILSIdleShipBackToWorkProcessor.cs @@ -1,10 +1,11 @@ #region +using System; using NebulaAPI.Packets; +using NebulaModel.Logger; using NebulaModel.Networking; using NebulaModel.Packets; using NebulaModel.Packets.Logistics; -using NebulaWorld; using NebulaWorld.Logistics; #endregion @@ -16,18 +17,18 @@ public class ILSIdleShipBackToWorkProcessor : PacketProcessor= stationComponent.workShipDatas.Length) + { + return; // Ship count is outside the range + } stationComponent.workShipDatas[stationComponent.workShipCount].stage = -2; stationComponent.workShipDatas[stationComponent.workShipCount].planetA = packet.PlanetA; @@ -71,11 +75,8 @@ public static void IdleShipGetToWork(ILSIdleShipBackToWork packet) stationComponent.workShipDatas[stationComponent.workShipCount].warperCnt = packet.ShipWarperCount; stationComponent.warperCount = packet.StationWarperCount; - if (stationComponent.idleShipCount > 0) - { - stationComponent.workShipCount++; - stationComponent.idleShipCount--; - } + stationComponent.workShipCount++; + stationComponent.idleShipCount--; stationComponent.IdleShipGetToWork(packet.ShipIndex); var shipSailSpeed = GameMain.history.logisticShipSailSpeedModified; @@ -115,14 +116,15 @@ public static void WorkShipBackToIdle(ILSWorkShipBackToIdle packet) { return; // This shouldn't happen, but guard just in case } + if (stationComponent.workShipCount <= 0 || stationComponent.workShipDatas.Length <= packet.WorkShipIndex) + { + return; // Ship count is outside the range + } Array.Copy(stationComponent.workShipDatas, packet.WorkShipIndex + 1, stationComponent.workShipDatas, packet.WorkShipIndex, stationComponent.workShipDatas.Length - packet.WorkShipIndex - 1); - if (stationComponent.workShipCount > 0) - { - stationComponent.workShipCount--; - stationComponent.idleShipCount++; - } + stationComponent.workShipCount--; + stationComponent.idleShipCount++; stationComponent.WorkShipBackToIdle(packet.ShipIndex); Array.Clear(stationComponent.workShipDatas, stationComponent.workShipCount, stationComponent.workShipDatas.Length - stationComponent.workShipCount); @@ -152,7 +154,7 @@ public static void CreateFakeStationComponent(int gId, int planetId, int maxShip stationComponent.shipRenderers = new ShipRenderingData[maxShipCount]; stationComponent.shipUIRenderers = new ShipUIRenderingData[maxShipCount]; stationComponent.workShipCount = 0; - stationComponent.idleShipCount = 0; + stationComponent.idleShipCount = maxShipCount; // add dummy idle ship count to use in ILSShipManager stationComponent.shipDockPos = Vector3.zero; //gets updated later by server packet stationComponent.shipDockRot = Quaternion.identity; // gets updated later by server packet stationComponent.storage = []; // zero-length array for mod compatibility