mirror of
https://github.com/celisej567/LibBSP.git
synced 2026-09-23 20:08:40 +03:00
Fix a problem with entity processing that was throwing on a (probably) broken entity in MoHAA's m3l2.bsp.
This commit is contained in:
@@ -197,12 +197,22 @@ namespace LibBSP {
|
|||||||
foreach (string line in lines) {
|
foreach (string line in lines) {
|
||||||
string current = line.Trim(' ', '\t', '\r');
|
string current = line.Trim(' ', '\t', '\r');
|
||||||
|
|
||||||
// Cull everything after a //
|
// Cull everything after a "//"
|
||||||
bool inQuotes = false;
|
bool inQuotes = false;
|
||||||
|
|
||||||
for (int i = 0; i < current.Length; ++i) {
|
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] == '/') {
|
if (!inQuotes && current[i] == '/' && i != 0 && current[i - 1] == '/') {
|
||||||
|
|||||||
@@ -54,9 +54,18 @@ namespace LibBSP {
|
|||||||
for (int offset = 0; offset < data.Length; ++offset) {
|
for (int offset = 0; offset < data.Length; ++offset) {
|
||||||
currentChar = (char)data[offset];
|
currentChar = (char)data[offset];
|
||||||
|
|
||||||
// Allow for escape-sequenced quotes to not affect the state machine.
|
if (currentChar == '\"') {
|
||||||
if (currentChar == '\"' && (offset == 0 || (char)data[offset - 1] != '\\')) {
|
if (offset == 0) {
|
||||||
inQuotes = !inQuotes;
|
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) {
|
if (!inQuotes) {
|
||||||
@@ -89,7 +98,7 @@ namespace LibBSP {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (braceCount != 0) {
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user