Skip to content

Commit 6662d63

Browse files
committed
Add validation for den coordinate arrays
Validate that all den location coordinates have exactly 3 elements (X, Y, Z) when loading from JSON. Prevents IndexOutOfRangeException crashes if coordinate data is corrupted. Fails fast with clear error message instead of cryptic runtime crash.
1 parent 1c21d81 commit 6662d63

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

SysBot.Pokemon/SV/BotRaid/RotatingRaidBotSV.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4071,7 +4071,19 @@ private static Dictionary<string, float[]> LoadDenLocations(string resourceName)
40714071

40724072
using var reader = new StreamReader(stream);
40734073
string json = reader.ReadToEnd();
4074-
return JsonConvert.DeserializeObject<Dictionary<string, float[]>>(json) ?? [];
4074+
var denLocations = JsonConvert.DeserializeObject<Dictionary<string, float[]>>(json) ?? [];
4075+
4076+
// Validate all coordinate arrays have exactly 3 elements (X, Y, Z)
4077+
foreach (var kvp in denLocations)
4078+
{
4079+
if (kvp.Value.Length != 3)
4080+
{
4081+
throw new InvalidOperationException(
4082+
$"Invalid den location data in {resourceName}: Den '{kvp.Key}' has {kvp.Value.Length} coordinates but expected 3 (X, Y, Z)");
4083+
}
4084+
}
4085+
4086+
return denLocations;
40754087
}
40764088

40774089
/// <summary>

0 commit comments

Comments
 (0)