Fix: GetCargoTranslation could return out-of-bounds index for old-style NewGRF using cargo-slots.

pull/217/head
frosch 3 years ago committed by frosch
parent 63288f80f3
commit 0078554d6a

@ -91,7 +91,10 @@ uint16 GetCargoCallback(CallbackID callback, uint32 param1, uint32 param2, const
CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit)
{
/* Pre-version 7 uses the 'climate dependent' ID in callbacks and properties, i.e. cargo is the cargo ID */
if (grffile->grf_version < 7 && !usebit) return cargo;
if (grffile->grf_version < 7 && !usebit) {
if (cargo >= CargoSpec::GetArraySize() || !CargoSpec::Get(cargo)->IsValid()) return CT_INVALID;
return cargo;
}
/* Other cases use (possibly translated) cargobits */

Loading…
Cancel
Save