summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2011-11-08 17:27:13 +0000
committerfrosch <frosch@openttd.org>2011-11-08 17:27:13 +0000
commit52774235eb6eb8affb7e68b94c490d3f09e7ae31 (patch)
treeaf07d5b6df28b5c9fdcef94e0f67ecec290e1764
parent30874b5e81af0fff2f42d34b9b105ee86666b8ac (diff)
downloadopenttd-52774235eb6eb8affb7e68b94c490d3f09e7ae31.tar.xz
(svn r23148) -Change: [NewGRF] Check the results of various callbacks for validness.
-rw-r--r--src/economy.cpp9
-rw-r--r--src/industry_cmd.cpp13
-rw-r--r--src/newgrf_animation_base.h5
-rw-r--r--src/object_cmd.cpp5
-rw-r--r--src/roadveh_cmd.cpp1
-rw-r--r--src/station_cmd.cpp8
-rw-r--r--src/train_cmd.cpp4
-rw-r--r--src/vehicle.cpp4
8 files changed, 44 insertions, 5 deletions
diff --git a/src/economy.cpp b/src/economy.cpp
index 5ba852bc6..79d8a0b99 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -1209,7 +1209,14 @@ static void LoadUnloadVehicle(Vehicle *front, int *cargo_left)
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];
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index aa6cce7b4..668749678 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -1644,7 +1644,10 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
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 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
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 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
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);
}
}
diff --git a/src/newgrf_animation_base.h b/src/newgrf_animation_base.h
index a3463adb2..695831faa 100644
--- a/src/newgrf_animation_base.h
+++ b/src/newgrf_animation_base.h
@@ -45,7 +45,10 @@ struct AnimationBase {
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
diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp
index 44b221457..32618d9ff 100644
--- a/src/object_cmd.cpp
+++ b/src/object_cmd.cpp
@@ -93,7 +93,10 @@ void BuildObject(ObjectType type, TileIndex tile, CompanyID owner, Town *town, u
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);
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 74e1e9c14..e6198bbc0 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -165,6 +165,7 @@ static uint GetRoadVehLength(const RoadVehicle *v)
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);
}
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index a1fb6e2c4..96251a8fe 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -1252,7 +1252,13 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32
/* 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);
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 3bcfcc64a..bc7898667 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -223,6 +223,10 @@ void Train::ConsistChanged(bool same_length)
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);
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index d990d3d55..b181038bd 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -835,6 +835,8 @@ static void RunVehicleDayProc()
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 @@ void Vehicle::UpdateVisualEffect(bool allow_power_change)
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. */