From 0a4fe02a47a56fd9f6a906e08f08626c9ac7afd8 Mon Sep 17 00:00:00 2001 From: frosch Date: Mon, 12 Nov 2012 20:13:02 +0000 Subject: (svn r24713) -Fix [FS#5262]: [NewGRF] Tolerate old NewGRFs returning invalid values via CB 11. --- src/roadveh_cmd.cpp | 2 +- src/train_cmd.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 62eb67915..11830973b 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -169,13 +169,13 @@ static uint GetRoadVehLength(const RoadVehicle *v) if (e->GetGRF() != NULL && e->GetGRF()->grf_version >= 8) { /* Use callback 36 */ veh_len = GetVehicleProperty(v, PROP_ROADVEH_SHORTEN_FACTOR, CALLBACK_FAILED); + if (veh_len != CALLBACK_FAILED && veh_len >= VEHICLE_LENGTH) ErrorUnknownCallbackResult(e->GetGRFID(), CBID_VEHICLE_LENGTH, veh_len); } else { /* Use callback 11 */ veh_len = GetVehicleCallback(CBID_VEHICLE_LENGTH, 0, 0, v->engine_type, v); } if (veh_len == CALLBACK_FAILED) veh_len = e->u.road.shorten_factor; if (veh_len != 0) { - if (veh_len >= VEHICLE_LENGTH) ErrorUnknownCallbackResult(e->GetGRFID(), CBID_VEHICLE_LENGTH, veh_len); length -= Clamp(veh_len, 0, VEHICLE_LENGTH - 1); } diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 34ac24cd8..c7bad3bf0 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -208,13 +208,14 @@ void Train::ConsistChanged(bool same_length) if (e_u->GetGRF() != NULL && e_u->GetGRF()->grf_version >= 8) { /* Use callback 36 */ veh_len = GetVehicleProperty(u, PROP_TRAIN_SHORTEN_FACTOR, CALLBACK_FAILED); + + if (veh_len != CALLBACK_FAILED && veh_len >= VEHICLE_LENGTH) { + ErrorUnknownCallbackResult(e_u->GetGRFID(), CBID_VEHICLE_LENGTH, veh_len); + } } else if (HasBit(e_u->info.callback_mask, CBM_VEHICLE_LENGTH)) { /* Use callback 11 */ veh_len = GetVehicleCallback(CBID_VEHICLE_LENGTH, 0, 0, u->engine_type, u); } - if (veh_len != CALLBACK_FAILED && veh_len >= VEHICLE_LENGTH) { - ErrorUnknownCallbackResult(e_u->GetGRFID(), CBID_VEHICLE_LENGTH, veh_len); - } if (veh_len == CALLBACK_FAILED) veh_len = rvi_u->shorten_factor; veh_len = VEHICLE_LENGTH - Clamp(veh_len, 0, VEHICLE_LENGTH - 1); -- cgit v1.2.3-70-g09d2