Fix: JGRPP's NGRF chunk doesn't contain length indicators for fixed-size arrays #456
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.
Before TABLE chunks, SlArray (fixed-size arrays) weren't prefixed with a length indicator. But with the migration to TABLE chunks, they are. This is because otherwise there is no information in the savegame about the length of these fields, and would still require knowledge of the OpenTTD versions that created these chunks.
But, vanilla documented poorly that this was a change made, and with JGR's efforts in JGRPP to switch to TABLE chunks, this was overlooked. Now this doesn't show up when saving/loading games in-game, as everything is compatible. Although trying to load a JGRPP's savegame in Vanilla will also cause trouble.
Either way, BaNaNaS should just be able to load scenarios, no matter what OpenTTD produced them. As such, this proposed change.
It first detects a chunk that is JGRPP specific, which indicates what features are active. We use this for JGRPP to signal to us when the length indicator is there or not; for now the assumption is that
table_newgrf_sl == 1
means it is not there, and that any newer versions do contain it. When version 1 is detected,ident.md5sum
andparam
are hardcoded to their values as in JGRPP:https://github.com/JGRennison/OpenTTD-patches/blob/9f7d25e02d5a4e86a88ebe9a6c83998fdcf7827e/src/sl/newgrf_sl.cpp#L83
PS: It has to be noted, although we detect this issue with the
NGRF
chunk, there might be other chunks effected. But this codebase only actually reads a very select few chunks, so not relevant for this repository.