From 6d786dd9afbf054ec8faedda1d3497ada814d3a1 Mon Sep 17 00:00:00 2001 From: Natan Date: Sun, 3 Nov 2024 13:32:53 +0100 Subject: [PATCH] Fixed parsing for BSPs with no entities and escaped quotes --- AssetUtils.cs | 2 +- BSP.cs | 6 ++++-- bspPack.csproj | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/AssetUtils.cs b/AssetUtils.cs index 54a3da1..8610d77 100644 --- a/AssetUtils.cs +++ b/AssetUtils.cs @@ -665,7 +665,7 @@ public static void findBspUtilityFiles(BSP bsp, List sourceDirectories, } // detail file (.vbsp) - Dictionary worldspawn = bsp.entityList.First(item => item["classname"] == "worldspawn"); + Dictionary worldspawn = bsp.entityList.FirstOrDefault(item => item["classname"] == "worldspawn", new Dictionary()); if (worldspawn.ContainsKey("detailvbsp")) { internalPath = worldspawn["detailvbsp"]; diff --git a/BSP.cs b/BSP.cs index eee5aa9..786786a 100644 --- a/BSP.cs +++ b/BSP.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; +using ValveKeyValue; namespace BSPPackStandalone { @@ -151,7 +152,8 @@ public void buildEntityList(FileStream bsp, BinaryReader reader) { if (s.Count() != 0) { - string[] c = s.Split('"'); + // split on non escaped quotes + string[] c = Regex.Split(s, "(? worldspawn = entityList.First(item => item["classname"] == "worldspawn"); + Dictionary worldspawn = entityList.FirstOrDefault(item => item["classname"] == "worldspawn", new Dictionary()); if (worldspawn.ContainsKey("skyname")) foreach (string s in new string[] { "", "bk", "dn", "ft", "lf", "rt", "up" }) { diff --git a/bspPack.csproj b/bspPack.csproj index 62c6870..9b08f3b 100644 --- a/bspPack.csproj +++ b/bspPack.csproj @@ -3,7 +3,7 @@ Exe net8.0 - 0.3.1 + 0.3.2 win-x64;linux-x64 true enable