Skip to content

Commit

Permalink
Fixed parsing for BSPs with no entities and escaped quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
Natanxp2 committed Nov 3, 2024
1 parent 6e2158a commit 6d786dd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion AssetUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ public static void findBspUtilityFiles(BSP bsp, List<string> sourceDirectories,
}

// detail file (.vbsp)
Dictionary<string, string> worldspawn = bsp.entityList.First(item => item["classname"] == "worldspawn");
Dictionary<string, string> worldspawn = bsp.entityList.FirstOrDefault(item => item["classname"] == "worldspawn", new Dictionary<string, string>());
if (worldspawn.ContainsKey("detailvbsp"))
{
internalPath = worldspawn["detailvbsp"];
Expand Down
6 changes: 4 additions & 2 deletions BSP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using ValveKeyValue;

namespace BSPPackStandalone
{
Expand Down Expand Up @@ -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, "(?<!\\\\)[\"\"]");
if (!entity.ContainsKey(c[1]))
entity.Add(c[1], c[3]);
entityArrayFormat.Add(Tuple.Create(c[1], c[3]));
Expand Down Expand Up @@ -184,7 +186,7 @@ public void buildTextureList(FileStream bsp, BinaryReader reader)
}

// find skybox materials
Dictionary<string, string> worldspawn = entityList.First(item => item["classname"] == "worldspawn");
Dictionary<string, string> worldspawn = entityList.FirstOrDefault(item => item["classname"] == "worldspawn", new Dictionary<string, string>());
if (worldspawn.ContainsKey("skyname"))
foreach (string s in new string[] { "", "bk", "dn", "ft", "lf", "rt", "up" })
{
Expand Down
2 changes: 1 addition & 1 deletion bspPack.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Version>0.3.1</Version>
<Version>0.3.2</Version>
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
<SelfContained>true</SelfContained>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down

0 comments on commit 6d786dd

Please sign in to comment.