Changeset - r18302:ea9dfce7b13f
[Not reviewed]
master
0 8 0
frosch - 13 years ago 2011-11-08 17:27:13
frosch@openttd.org
(svn r23148) -Change: [NewGRF] Check the results of various callbacks for validness.
8 files changed with 44 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/economy.cpp
Show inline comments
 
@@ -1209,7 +1209,14 @@ static void LoadUnloadVehicle(Vehicle *f
 

	
 
		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];
src/industry_cmd.cpp
Show inline comments
 
@@ -1644,7 +1644,10 @@ static void DoCreateNewIndustry(Industry
 

	
 
	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
 
		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
 
		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);
 
		}
 
	}
src/newgrf_animation_base.h
Show inline comments
 
@@ -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
src/object_cmd.cpp
Show inline comments
 
@@ -93,7 +93,10 @@ void BuildObject(ObjectType type, TileIn
 

	
 
	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);
src/roadveh_cmd.cpp
Show inline comments
 
@@ -165,6 +165,7 @@ static uint GetRoadVehLength(const RoadV
 

	
 
	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);
 
	}
 

	
src/station_cmd.cpp
Show inline comments
 
@@ -1252,7 +1252,13 @@ CommandCost CmdBuildRailStation(TileInde
 

	
 
					/* 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);
src/train_cmd.cpp
Show inline comments
 
@@ -223,6 +223,10 @@ void Train::ConsistChanged(bool same_len
 
		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);
src/vehicle.cpp
Show inline comments
 
@@ -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 al
 
		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. */
0 comments (0 inline, 0 general)