Mercurial > hg > openttd
changeset 18312:1945b084b0dc draft
(svn r23148) -Change: [NewGRF] Check the results of various callbacks for validness.
author | frosch <frosch@openttd.org> |
---|---|
date | Tue, 08 Nov 2011 17:27:13 +0000 |
parents | 09cb5ec03259 |
children | 41bd44368715 |
files | src/economy.cpp src/industry_cmd.cpp src/newgrf_animation_base.h src/object_cmd.cpp src/roadveh_cmd.cpp src/station_cmd.cpp src/train_cmd.cpp src/vehicle.cpp |
diffstat | 8 files changed, 44 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/economy.cpp +++ b/src/economy.cpp @@ -1209,7 +1209,14 @@ if (_settings_game.order.gradual_loading && HasBit(e->info.callback_mask, CBM_VEHICLE_LOAD_AMOUNT)) { uint16 cb_load_amount = GetVehicleCallback(CBID_VEHICLE_LOAD_AMOUNT, 0, 0, v->engine_type, v); - if (cb_load_amount != CALLBACK_FAILED && GB(cb_load_amount, 0, 8) != 0) load_amount = GB(cb_load_amount, 0, 8); + if (cb_load_amount != CALLBACK_FAILED) { + if (e->GetGRF()->grf_version < 8) cb_load_amount = GB(cb_load_amount, 0, 8); + if (cb_load_amount >= 0x100) { + ErrorUnknownCallbackResult(e->GetGRFID(), CBID_VEHICLE_LOAD_AMOUNT, cb_load_amount); + } else if (cb_load_amount != 0) { + load_amount = cb_load_amount; + } + } } GoodsEntry *ge = &st->goods[v->cargo_type];
--- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -1644,7 +1644,10 @@ if (HasBit(indspec->callback_mask, CBM_IND_DECIDE_COLOUR)) { uint16 res = GetIndustryCallback(CBID_INDUSTRY_DECIDE_COLOUR, 0, 0, i, type, INVALID_TILE); - if (res != CALLBACK_FAILED) i->random_colour = GB(res, 0, 4); + if (res != CALLBACK_FAILED) { + if (GB(res, 4, 11) != 0) ErrorUnknownCallbackResult(indspec->grf_prop.grffile->grfid, CBID_INDUSTRY_DECIDE_COLOUR, res); + i->random_colour = GB(res, 0, 4); + } } if (HasBit(indspec->callback_mask, CBM_IND_INPUT_CARGO_TYPES)) { @@ -1652,6 +1655,10 @@ for (uint j = 0; j < lengthof(i->accepts_cargo); j++) { uint16 res = GetIndustryCallback(CBID_INDUSTRY_INPUT_CARGO_TYPES, j, 0, i, type, INVALID_TILE); if (res == CALLBACK_FAILED || GB(res, 0, 8) == CT_INVALID) break; + if (indspec->grf_prop.grffile->grf_version >= 8 && res >= 0x100) { + ErrorUnknownCallbackResult(indspec->grf_prop.grffile->grfid, CBID_INDUSTRY_INPUT_CARGO_TYPES, res); + break; + } i->accepts_cargo[j] = GetCargoTranslation(GB(res, 0, 8), indspec->grf_prop.grffile); } } @@ -1661,6 +1668,10 @@ for (uint j = 0; j < lengthof(i->produced_cargo); j++) { uint16 res = GetIndustryCallback(CBID_INDUSTRY_OUTPUT_CARGO_TYPES, j, 0, i, type, INVALID_TILE); if (res == CALLBACK_FAILED || GB(res, 0, 8) == CT_INVALID) break; + if (indspec->grf_prop.grffile->grf_version >= 8 && res >= 0x100) { + ErrorUnknownCallbackResult(indspec->grf_prop.grffile->grfid, CBID_INDUSTRY_OUTPUT_CARGO_TYPES, res); + break; + } i->produced_cargo[j] = GetCargoTranslation(GB(res, 0, 8), indspec->grf_prop.grffile); } }
--- a/src/newgrf_animation_base.h +++ b/src/newgrf_animation_base.h @@ -45,7 +45,10 @@ uint8 animation_speed = spec->animation.speed; if (HasBit(spec->callback_mask, Tbase::cbm_animation_speed)) { uint16 callback = GetCallback(Tbase::cb_animation_speed, 0, 0, spec, obj, tile, extra_data); - if (callback != CALLBACK_FAILED) animation_speed = Clamp(callback & 0xFF, 0, 16); + if (callback != CALLBACK_FAILED) { + if (callback >= 0x100 && spec->grf_prop.grffile->grf_version >= 8) ErrorUnknownCallbackResult(spec->grf_prop.grffile->grfid, Tbase::cb_animation_speed, callback); + animation_speed = Clamp(callback & 0xFF, 0, 16); + } } /* An animation speed of 2 means the animation frame changes 4 ticks, and
--- a/src/object_cmd.cpp +++ b/src/object_cmd.cpp @@ -93,7 +93,10 @@ if (HasBit(spec->callback_mask, CBM_OBJ_COLOUR)) { uint16 res = GetObjectCallback(CBID_OBJECT_COLOUR, o->colour, 0, spec, o, tile); - if (res != CALLBACK_FAILED) o->colour = GB(res, 0, 8); + if (res != CALLBACK_FAILED) { + if (res >= 0x100) ErrorUnknownCallbackResult(spec->grf_prop.grffile->grfid, CBID_OBJECT_COLOUR, res); + o->colour = GB(res, 0, 8); + } } assert(o->town != NULL);
--- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -165,6 +165,7 @@ uint16 veh_len = GetVehicleCallback(CBID_VEHICLE_LENGTH, 0, 0, v->engine_type, v); if (veh_len != CALLBACK_FAILED) { + if (veh_len >= VEHICLE_LENGTH) ErrorUnknownCallbackResult(v->GetGRFID(), CBID_VEHICLE_LENGTH, veh_len); length -= Clamp(veh_len, 0, VEHICLE_LENGTH - 1); }
--- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1252,7 +1252,13 @@ /* As the station is not yet completely finished, the station does not yet exist. */ uint16 callback = GetStationCallback(CBID_STATION_TILE_LAYOUT, platinfo, 0, statspec, NULL, tile); - if (callback != CALLBACK_FAILED && callback < 8) SetStationGfx(tile, (callback & ~1) + axis); + if (callback != CALLBACK_FAILED) { + if (callback < 8) { + SetStationGfx(tile, (callback & ~1) + axis); + } else { + ErrorUnknownCallbackResult(statspec->grf_prop.grffile->grfid, CBID_STATION_TILE_LAYOUT, callback); + } + } /* Trigger station animation -- after building? */ TriggerStationAnimation(st, tile, SAT_BUILT);
--- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -223,6 +223,10 @@ uint16 veh_len = CALLBACK_FAILED; if (HasBit(e_u->info.callback_mask, CBM_VEHICLE_LENGTH)) { 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);
--- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -835,6 +835,8 @@ if (callback != CALLBACK_FAILED) { if (HasBit(callback, 0)) TriggerVehicle(v, VEHICLE_TRIGGER_CALLBACK_32); // Trigger vehicle trigger 10 if (HasBit(callback, 1)) v->colourmap = PAL_NONE; + + if (callback & ~3) ErrorUnknownCallbackResult(v->GetGRFID(), CBID_VEHICLE_32DAY_CALLBACK, callback); } } @@ -2175,6 +2177,8 @@ uint16 callback = GetVehicleCallback(CBID_VEHICLE_VISUAL_EFFECT, 0, 0, this->engine_type, this); if (callback != CALLBACK_FAILED) { + if (callback >= 0x100 && e->GetGRF()->grf_version >= 8) ErrorUnknownCallbackResult(e->GetGRFID(), CBID_VEHICLE_VISUAL_EFFECT, callback); + callback = GB(callback, 0, 8); /* Avoid accidentally setting 'visual_effect' to the default value * Since bit 6 (disable effects) is set anyways, we can safely erase some bits. */