From 249aaa2b77d279adc4c3b111ea9f734d22aa16b0 Mon Sep 17 00:00:00 2001 From: wfowler Date: Sat, 21 Jul 2018 21:39:46 -0600 Subject: [PATCH] Add a bit of error checking to the detection of Source entity connections. This will make the parser more robust against false positives. --- LibBSP/Source/Structs/Common/Entity.cs | 27 ++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/LibBSP/Source/Structs/Common/Entity.cs b/LibBSP/Source/Structs/Common/Entity.cs index 8a8bcde..50928d6 100644 --- a/LibBSP/Source/Structs/Common/Entity.cs +++ b/LibBSP/Source/Structs/Common/Entity.cs @@ -345,16 +345,23 @@ namespace LibBSP { connection = val.Split((char)0x1B); } if (connection.Length == 5 || connection.Length == 7) { - connections.Add(new EntityConnection { - name = key, - target = connection[0], - action = connection[1], - param = connection[2], - delay = Double.Parse(connection[3], _format), - fireOnce = Int32.Parse(connection[4]), - unknown0 = connection.Length > 5 ? connection[5] : "", - unknown1 = connection.Length > 6 ? connection[6] : "", - }); + try { + connections.Add(new EntityConnection { + name = key, + target = connection[0], + action = connection[1], + param = connection[2], + delay = Double.Parse(connection[3], _format), + fireOnce = Int32.Parse(connection[4]), + unknown0 = connection.Length > 5 ? connection[5] : "", + unknown1 = connection.Length > 6 ? connection[6] : "", + }); + } catch (FormatException) { + // If that fails, assume a false positive and just add this as a normal keyvalue pair. + if (!ContainsKey(key)) { + this[key] = val; + } + } } } else { if (!ContainsKey(key)) {