Skip to content

Commit d19beb5

Browse files
Merge pull request #92 from senko-forks/pr-dyesplosion
Fix dye off by one error and CN exception
2 parents 14a511e + dfdb3d2 commit d19beb5

File tree

1 file changed

+6
-4
lines changed
  • xivModdingFramework/Materials/FileTypes

1 file changed

+6
-4
lines changed

xivModdingFramework/Materials/FileTypes/STM.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public StainingTemplateEntry(byte[] data, int offset, EStainingTemplate template
249249
// No data.
250250
continue;
251251
}
252-
else
252+
else if (arraySize < numDyes)
253253
{
254254
// Indexed array, where we have [n] # of real entries,
255255
// then 254 one-byte index entries referencing those [n] entries.
@@ -287,11 +287,13 @@ public StainingTemplateEntry(byte[] data, int offset, EStainingTemplate template
287287
if(type == StainingTemplateArrayType.Indexed)
288288
{
289289
var nArray = new List<Half[]>();
290-
for (int i = 0; i < numDyes; i++)
290+
// The first entry in the list is an 0xFF byte that we skip
291+
// Since that would leave us with one less value than we need, as dummy value is added for the last dye
292+
for (int i = 1; i < numDyes + 1; i++)
291293
{
292294
try
293295
{
294-
var index = data[indexStart + i];
296+
var index = (i == numDyes) ? 255 : data[indexStart + i];
295297
if (index == 255 || index == 0)
296298
{
297299
if (x < 3)
@@ -402,7 +404,7 @@ public StainingTemplateFile(byte[] data, EStainingTemplate templateType)
402404
offset += oldFormat ? 2 : 4;
403405
}
404406

405-
const int _headerEntrySize = 8;
407+
int _headerEntrySize = oldFormat ? 4 : 8;
406408
var endOfHeader = (8 + (_headerEntrySize * entryCount));
407409

408410
for (int i = 0; i < entryCount; i++)

0 commit comments

Comments
 (0)