From 2d75d54f6b09698843f0d4141b5db85920aeb5ce Mon Sep 17 00:00:00 2001 From: Zorchenhimer Date: Sun, 9 Nov 2025 12:13:35 -0500 Subject: [PATCH] [cmd/extract-imgs] Add some padding checks Added some checks and warnings if the palettes didn't immediately follow attribute data and if there were any non-zero bytes after the palette data. The padding at the end of the file/segment seems to be ignored by the engine anyway. --- cmd/extract-imgs.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cmd/extract-imgs.go b/cmd/extract-imgs.go index 5765422..0cf8d49 100644 --- a/cmd/extract-imgs.go +++ b/cmd/extract-imgs.go @@ -369,6 +369,26 @@ func ReadData(raw []byte, tiles []*nesimg.Tile, isSprites bool) ([]*Layer, error layers = append(layers, l) } + if offset != int(dataHeader.PaletteOffset) { + fmt.Printf("[[ offset != dataHeader.PaletteOffset: %04X != %04X ]]\n", offset, dataHeader.PaletteOffset) + } + + // Looks like the data after the palettes is just padding? If there's a non-zero + // byte in there, print a warning. + palend := int(dataHeader.PaletteOffset) + (8*4) + if palend < len(raw) { + nonzero := false + for i := palend; i < len(raw); i++ { + if raw[i] != 0x00 { + nonzero = true + break + } + } + if nonzero { + fmt.Printf("[[ %d bytes of extra data ]]\n", len(raw) - palend) + } + } + return layers, nil }