From 4d1897915091709ec35b3322f7b5be3d856c8379 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Sun, 12 Sep 2021 17:46:31 -0500 Subject: [PATCH] Make unknown ports not throw --- PathfinderAPI/Port/PortManager.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/PathfinderAPI/Port/PortManager.cs b/PathfinderAPI/Port/PortManager.cs index 390b95a4..f33aefef 100644 --- a/PathfinderAPI/Port/PortManager.cs +++ b/PathfinderAPI/Port/PortManager.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; +using BepInEx.Logging; using Pathfinder.Event; using Hacknet; using Hacknet.Security; @@ -61,7 +62,7 @@ public static void LoadPortsFromString(Computer comp, string portString, bool cl { if (clearExisting) comp.ClearPorts(); - foreach (var port in portString.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)) + foreach (var port in portString.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries)) { var portParts = port.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (portParts.Length == 1) @@ -102,7 +103,12 @@ public static void LoadPortsFromStringVanilla(Computer comp, string portsList) if (!int.TryParse(port, out var portNum)) throw new FormatException($"Failed to parse port number from '{port}'"); var data = GetPortDataFromNumber(portNum); - comp.AddPort(data?.Clone() ?? throw new ArgumentException($"No port has the default {port}")); + if (data == null) + { + Logger.Log(LogLevel.Warning, $"{comp.idName} has port {port}, which does not exist"); + continue; + } + comp.AddPort(data.Clone()); } }