Rework range check

- Loops through all entries
- Bumped amount of cols up to 8 for future proofing
- Use Ordinal search
- Actually parse ranges and check if the RowId is allowed
This commit is contained in:
Haselnussbomber 2025-09-20 03:53:26 +02:00
parent 3f037e5d20
commit d8555f207e
No known key found for this signature in database
GPG key ID: BB905BB49E7295D1

View file

@ -1630,37 +1630,56 @@ internal class SeStringEvaluator : IServiceType, ISeStringEvaluator
var isNoun = false; var isNoun = false;
Span<int> cols = stackalloc int[2]; var colIndex = 0;
Span<int> cols = stackalloc int[8];
cols.Clear(); cols.Clear();
var isInRange = false;
if (ranges.StartsWith("noun")) while (!string.IsNullOrWhiteSpace(ranges))
{
// find the end of the current entry
var entryEnd = ranges.IndexOf(',');
if (entryEnd == -1)
entryEnd = ranges.Length;
if (ranges.StartsWith("noun", StringComparison.Ordinal))
{ {
isNoun = true; isNoun = true;
} }
else if (ranges.StartsWith("col")) else if (ranges.StartsWith("col", StringComparison.Ordinal) && colIndex < cols.Length)
{ {
var i = 0; cols[colIndex++] = int.Parse(ranges.AsSpan(4, entryEnd - 4));
while (i < cols.Length && ranges.StartsWith("col-", StringComparison.Ordinal)) }
else if (ranges.StartsWith("tail", StringComparison.Ordinal))
{ {
// find the end of the current "col-#" token // currently not supported, since there are no known uses
var colRangeEnd = ranges.IndexOf(','); context.Builder.Append(payload);
if (colRangeEnd == -1) return false;
colRangeEnd = ranges.Length; }
else
// parse the column index {
cols[i++] = int.Parse(ranges.AsSpan(4, colRangeEnd - 4)); var dash = ranges.IndexOf('-');
if (dash == -1)
{
isInRange |= int.Parse(ranges.AsSpan(0, entryEnd)) == rowId;
}
else
{
isInRange |= rowId >= int.Parse(ranges.AsSpan(0, dash))
&& rowId <= int.Parse(ranges.AsSpan(dash + 1, entryEnd - dash - 1));
}
}
// if it's the end of the string, we're done // if it's the end of the string, we're done
if (colRangeEnd == ranges.Length) if (entryEnd == ranges.Length)
break; break;
// move to the next entry // else, move to the next entry
ranges = ranges[(colRangeEnd + 1)..].TrimStart(); ranges = ranges[(entryEnd + 1)..].TrimStart();
} }
}
else if (ranges.StartsWith("tail")) if (!isInRange)
{ {
// couldn't find any, so we don't handle them :p
context.Builder.Append(payload); context.Builder.Append(payload);
return false; return false;
} }
@ -1678,9 +1697,14 @@ internal class SeStringEvaluator : IServiceType, ISeStringEvaluator
} }
else if (this.dataManager.GetExcelSheet<RawRow>(context.Language, sheetName).TryGetRow(rowId, out var row)) else if (this.dataManager.GetExcelSheet<RawRow>(context.Language, sheetName).TryGetRow(rowId, out var row))
{ {
// the game uses a priority system for columns here. if (colIndex == 0)
// if the first column is empty (for example MainCommand.Alias), then the next one is used (MainCommand.Command) {
for (var i = 0; i < cols.Length; i++) context.Builder.Append(row.ReadStringColumn(0));
return true;
}
else
{
for (var i = 0; i < colIndex; i++)
{ {
var text = row.ReadStringColumn(cols[i]); var text = row.ReadStringColumn(cols[i]);
if (!text.IsEmpty) if (!text.IsEmpty)
@ -1690,6 +1714,7 @@ internal class SeStringEvaluator : IServiceType, ISeStringEvaluator
} }
} }
} }
}
return true; return true;
} }