summaryrefslogtreecommitdiff
path: root/src/newgrf_sound.cpp
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2010-04-20 05:52:51 +0000
committeryexo <yexo@openttd.org>2010-04-20 05:52:51 +0000
commit92e36c87fd77ed9b9de958e9f211aa105a76ca9f (patch)
treebd160ea6a83ed6db87304917bf45ff4d583f0339 /src/newgrf_sound.cpp
parentdf4d8b3bc9f52496b95ed1f5865ee31de1b07590 (diff)
downloadopenttd-92e36c87fd77ed9b9de958e9f211aa105a76ca9f.tar.xz
(svn r19679) -Fix: [NewGRF] make sure newgrfs can't overwrite sound effect properties from other newgrfs
Diffstat (limited to 'src/newgrf_sound.cpp')
-rw-r--r--src/newgrf_sound.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/newgrf_sound.cpp b/src/newgrf_sound.cpp
index 48623647e..9dc5d32dd 100644
--- a/src/newgrf_sound.cpp
+++ b/src/newgrf_sound.cpp
@@ -65,19 +65,26 @@ bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event)
callback = GetVehicleCallback(CBID_VEHICLE_SOUND_EFFECT, event, 0, v->engine_type, v);
if (callback == CALLBACK_FAILED) return false;
- if (callback >= ORIGINAL_SAMPLE_COUNT) callback += file->sound_offset - ORIGINAL_SAMPLE_COUNT;
+ if (callback >= ORIGINAL_SAMPLE_COUNT) {
+ callback -= ORIGINAL_SAMPLE_COUNT;
+ if (callback > file->num_sounds) return false;
+ callback += file->sound_offset;
+ }
- if (callback < GetNumSounds()) SndPlayVehicleFx(callback, v);
+ assert(callback < GetNumSounds());
+ SndPlayVehicleFx(callback, v);
return true;
}
bool PlayTileSound(const GRFFile *file, SoundID sound_id, TileIndex tile)
{
- if (sound_id >= ORIGINAL_SAMPLE_COUNT) sound_id += file->sound_offset - ORIGINAL_SAMPLE_COUNT;
-
- if (sound_id < GetNumSounds()) {
- SndPlayTileFx(sound_id, tile);
- return true;
+ if (sound_id >= ORIGINAL_SAMPLE_COUNT) {
+ sound_id -= ORIGINAL_SAMPLE_COUNT;
+ if (sound_id > file->num_sounds) return false;
+ sound_id += file->sound_offset;
}
- return false;
+
+ assert(sound_id < GetNumSounds());
+ SndPlayTileFx(sound_id, tile);
+ return true;
}