GB: Don't read ghost slots

Read count from list, instead of using the full capacity.
Malformed lists (truncated via count) with ghost slots should have those ghost slots ignored.
This commit is contained in:
Kurt 2024-05-13 18:14:40 -05:00
parent 215f892f11
commit bbfec1fb29
2 changed files with 4 additions and 2 deletions

View file

@ -173,7 +173,8 @@ public static class PokeList1
var ofsStr1 = ofsBody + (capacity * lengthBody); var ofsStr1 = ofsBody + (capacity * lengthBody);
var ofsStr2 = ofsStr1 + (capacity * stringLength); var ofsStr2 = ofsStr1 + (capacity * stringLength);
for (int i = 0; i < capacity; i++) var count = Math.Min(capacity, input[0]);
for (int i = 0; i < count; i++)
{ {
var species = input[1 + i]; var species = input[1 + i];
var body = input.Slice(ofsBody, lengthBody); var body = input.Slice(ofsBody, lengthBody);

View file

@ -177,7 +177,8 @@ public static class PokeList2
var ofsStr1 = ofsBody + (capacity * lengthBody); var ofsStr1 = ofsBody + (capacity * lengthBody);
var ofsStr2 = ofsStr1 + (capacity * stringLength); var ofsStr2 = ofsStr1 + (capacity * stringLength);
for (int i = 0; i < capacity; i++) var count = Math.Min(capacity, input[0]);
for (int i = 0; i < count; i++)
{ {
var species = input[1 + i]; var species = input[1 + i];
var body = input.Slice(ofsBody, lengthBody); var body = input.Slice(ofsBody, lengthBody);