Fix a problem with entity processing that was throwing on a (probably) broken entity in MoHAA's m3l2.bsp.

This commit is contained in:
wfowler
2018-07-14 21:28:02 -06:00
parent 7fc89ecd4f
commit c8a4bcb22d
2 changed files with 27 additions and 8 deletions

View File

@@ -197,12 +197,22 @@ namespace LibBSP {
foreach (string line in lines) {
string current = line.Trim(' ', '\t', '\r');
// Cull everything after a //
// Cull everything after a "//"
bool inQuotes = false;
for (int i = 0; i < current.Length; ++i) {
if (current[i] == '\"' && (i == 0 || current[i - 1] != '\\')) {
inQuotes = !inQuotes;
if (current[i] == '\"') {
if (i == 0) {
inQuotes = !inQuotes;
} else if (current[i - 1] != '\\') {
// Allow for escape-sequenced quotes to not affect the state machine, but only if the quote isn't at the end of a line.
// Some Source engine entities use escape sequence quotes in values, but MoHAA has a map with an obvious erroneous backslash before a quote at the end of a line.
if (inQuotes && (i + 1 >= current.Length || current[i + 1] == '\n' || current[i + 1] == '\r')) {
inQuotes = false;
}
} else {
inQuotes = !inQuotes;
}
}
if (!inQuotes && current[i] == '/' && i != 0 && current[i - 1] == '/') {

View File

@@ -54,9 +54,18 @@ namespace LibBSP {
for (int offset = 0; offset < data.Length; ++offset) {
currentChar = (char)data[offset];
// Allow for escape-sequenced quotes to not affect the state machine.
if (currentChar == '\"' && (offset == 0 || (char)data[offset - 1] != '\\')) {
inQuotes = !inQuotes;
if (currentChar == '\"') {
if (offset == 0) {
inQuotes = !inQuotes;
} else if ((char)data[offset - 1] != '\\') {
// Allow for escape-sequenced quotes to not affect the state machine, but only if the quote isn't at the end of a line.
// Some Source engine entities use escape sequence quotes in values, but MoHAA has a map with an obvious erroneous backslash before a quote at the end of a line.
if (inQuotes && (offset + 1 >= data.Length || (char)data[offset + 1] == '\n' || (char)data[offset + 1] == '\r')) {
inQuotes = false;
}
} else {
inQuotes = !inQuotes;
}
}
if (!inQuotes) {
@@ -89,7 +98,7 @@ namespace LibBSP {
}
if (braceCount != 0) {
throw new ArgumentException(string.Format("Brace mismatch when parsing entities! Brace level: {0}", braceCount));
throw new ArgumentException(string.Format("Brace mismatch when parsing entities! Entity: {0} Brace level: {1}", Count, braceCount));
}
}