Change: Support decoding of NewGRF with out-of-order v2 container and 32bpp-only files. #29
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
GRFCodec assumes v2 container data is used sequentially, however this is not enforced by OpenTTD and some existing NewGRFs are able to use data out of order, or reuse it.
OpenTTD allows this by prescanning all v2 container data and storing the offset for each ID, and I have copied the basic principle from there. Note that, in the case of reusing data, GRFCodec is not aware of this and will happily output multiple copies of the same sprite data. This may be something to address in future but for now simply the ability to decode is nice.
Additionally, previously GRFCodec did not properly export 32bpp files as the condition for outputting the correct nfo line for the first sprite was only used on the line that writes 8bpp sprites. This was added to the 32bpp lines as well, so that 32bpp-only NewGRFs can be decoded.
Note that GRFCodec already does not enforce that an 8bpp is present when encoding, so it was possible for GRFCodec to create a file that it could not decode.
While the NFO specs mention that an 8bpp normal zoom level sprite is required first, this is not checked by GRFCodec, and importantly, it is not checked by OpenTTD either.
The NewGRF file at the following link was used when testing this:
https://bananas.openttd.org/package/newgrf/524f4231