From cbe49300b86868591b2776470b75681476578d30 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Wed, 31 Dec 2014 14:54:23 +0000 Subject: [PATCH 1/2] Fixed sounds not playing properly when paused. Labeled max sounds offset. Prevented crash on null dereference --- src/addresses.h | 1 + src/audio/audio.c | 2 +- src/config.c | 2 +- src/game.c | 4 ++-- src/input.c | 3 +++ src/windows/options.c | 2 +- 6 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index 0479a24fb6..8418f05662 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -70,6 +70,7 @@ #define RCT2_ADDRESS_CONFIG_MUSIC 0x009AAC72 #define RCT2_ADDRESS_CONFIG_FLAGS 0x009AAC74 +#define RCT2_ADDRESS_CONFIG_MAX_NO_SOUNDS 0x009AAC76 #define RCT2_ADDRESS_CONFIG_SOUND_QUALITY 0x009AAC77 #define RCT2_ADDRESS_CONFIG_METRIC 0x009AAC78 #define RCT2_ADDRESS_CONFIG_TEMPERATURE 0x009AAC79 diff --git a/src/audio/audio.c b/src/audio/audio.c index 8137a37f8f..42e436e3c4 100644 --- a/src/audio/audio.c +++ b/src/audio/audio.c @@ -1481,7 +1481,7 @@ int sound_play_panned(int sound_id, int ebx, sint16 x, sint16 y, sint16 z) while (other_sound->id != 0xFFFF) { i++; other_sound = &RCT2_ADDRESS(0x009AF484, rct_other_sound)[i]; - if (i > RCT2_GLOBAL(0x009AAC76, uint8)) { // too many sounds playing + if (i > RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_MAX_NO_SOUNDS, uint8)) { // too many sounds playing return sound_id; } } diff --git a/src/config.c b/src/config.c index 7a2b188608..6287d08f2c 100644 --- a/src/config.c +++ b/src/config.c @@ -871,7 +871,7 @@ void config_dat_load() RCT2_GLOBAL(0x009AAC75, sint8) = RCT2_ADDRESS(0x009AF601, sint8)[RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_SOUND_QUALITY, sint8)]; - RCT2_GLOBAL(0x009AAC76, sint8) = RCT2_ADDRESS(0x009AF604, sint8)[RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_SOUND_QUALITY, sint8)]; + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_MAX_NO_SOUNDS, sint8) = RCT2_ADDRESS(0x009AF604, sint8)[RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_SOUND_QUALITY, sint8)]; RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_HEIGHT_MARKERS, sint16) = 0; if (!(RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) & CONFIG_FLAG_SHOW_HEIGHT_AS_UNITS)) RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_HEIGHT_MARKERS, sint16) = (RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_METRIC, sint8) + 1) * 256; diff --git a/src/game.c b/src/game.c index d30caa3185..3addf119bf 100644 --- a/src/game.c +++ b/src/game.c @@ -272,6 +272,8 @@ void game_update() update_palette_effects(); update_rain_animation(); + stop_completed_sounds(); // removes other sounds that are no longer playing, this is normally called somewhere in rct2_init + if (RCT2_GLOBAL(0x009AAC73, uint8) != 255) { RCT2_GLOBAL(0x009AAC73, uint8)++; if (RCT2_GLOBAL(0x009AAC73, uint8) == 255) @@ -309,8 +311,6 @@ void game_logic_update() news_item_update_current(); editor_open_windows_for_current_step(); - stop_completed_sounds(); // removes other sounds that are no longer playing, this is normally called somewhere in rct2_init - // Update windows window_dispatch_update_all(); diff --git a/src/input.c b/src/input.c index da3ca92ffe..896ff4596a 100644 --- a/src/input.c +++ b/src/input.c @@ -1004,6 +1004,9 @@ void input_state_widget_pressed( int x, int y, int state, int widgetIndex, rct_w if (!w) break; + if (!widget) + break; + int mid_point_x = (widget->left + widget->right) / 2 + w->x; sound_play_panned(5, mid_point_x, 0, 0, 0); if (cursor_w_class != w->classification || cursor_w_number != w->number || widgetIndex != cursor_widgetIndex) diff --git a/src/windows/options.c b/src/windows/options.c index b91ea8c68a..a2c58afb79 100644 --- a/src/windows/options.c +++ b/src/windows/options.c @@ -512,7 +512,7 @@ static void window_options_dropdown() case WIDX_SOUND_QUALITY_DROPDOWN: // TODO: no clue what this does (and if it's correct) RCT2_GLOBAL(0x009AAC75, uint8) = RCT2_GLOBAL(0x009AF601 + dropdownIndex, uint8); - RCT2_GLOBAL(0x009AAC76, uint8) = RCT2_GLOBAL(0x009AF604 + dropdownIndex, uint8); + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_MAX_NO_SOUNDS, uint8) = RCT2_GLOBAL(0x009AF604 + dropdownIndex, uint8); gSound_config.sound_quality = (sint8)dropdownIndex; config_save(); window_invalidate(w); From 4257d0bcc4ec215e972869841789ba3ffa9c9350 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Wed, 31 Dec 2014 15:04:20 +0000 Subject: [PATCH 2/2] Labelled offset to redundant max vehicle sounds. --- src/addresses.h | 4 ++++ src/config.c | 2 +- src/ride/vehicle.c | 2 +- src/windows/options.c | 3 +-- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index 8418f05662..194e111b50 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -70,6 +70,10 @@ #define RCT2_ADDRESS_CONFIG_MUSIC 0x009AAC72 #define RCT2_ADDRESS_CONFIG_FLAGS 0x009AAC74 + +// MAX vehicle sounds not used anymore +#define RCT2_ADDRESS_CONFIG_MAX_VEHICLE_SOUNDS 0x009AAC75 + #define RCT2_ADDRESS_CONFIG_MAX_NO_SOUNDS 0x009AAC76 #define RCT2_ADDRESS_CONFIG_SOUND_QUALITY 0x009AAC77 #define RCT2_ADDRESS_CONFIG_METRIC 0x009AAC78 diff --git a/src/config.c b/src/config.c index 6287d08f2c..5dd2b18a75 100644 --- a/src/config.c +++ b/src/config.c @@ -870,7 +870,7 @@ void config_dat_load() */ - RCT2_GLOBAL(0x009AAC75, sint8) = RCT2_ADDRESS(0x009AF601, sint8)[RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_SOUND_QUALITY, sint8)]; + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_MAX_VEHICLE_SOUNDS, sint8) = RCT2_ADDRESS(0x009AF601, sint8)[RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_SOUND_QUALITY, sint8)]; RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_MAX_NO_SOUNDS, sint8) = RCT2_ADDRESS(0x009AF604, sint8)[RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_SOUND_QUALITY, sint8)]; RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_HEIGHT_MARKERS, sint16) = 0; if (!(RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) & CONFIG_FLAG_SHOW_HEIGHT_AS_UNITS)) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 19b32d97e5..41741979d1 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -305,7 +305,7 @@ void vehicle_sounds_update() while (vehicle_sound->id != (uint16)-1) { vehicle_sound++; i++; - if (i >= countof(gVehicleSoundList)/*i >= RCT2_GLOBAL(0x009AAC75, uint8)*/) { + if (i >= countof(gVehicleSoundList)/*i >= RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_MAX_VEHICLE_SOUNDS, uint8)*/) { vehicle_sound_params = (rct_vehicle_sound_params*)((int)vehicle_sound_params + 10); goto label28; } diff --git a/src/windows/options.c b/src/windows/options.c index a2c58afb79..33a926693c 100644 --- a/src/windows/options.c +++ b/src/windows/options.c @@ -510,8 +510,7 @@ static void window_options_dropdown() window_invalidate(w); break; case WIDX_SOUND_QUALITY_DROPDOWN: - // TODO: no clue what this does (and if it's correct) - RCT2_GLOBAL(0x009AAC75, uint8) = RCT2_GLOBAL(0x009AF601 + dropdownIndex, uint8); + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_MAX_VEHICLE_SOUNDS, uint8) = RCT2_GLOBAL(0x009AF601 + dropdownIndex, uint8); RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_MAX_NO_SOUNDS, uint8) = RCT2_GLOBAL(0x009AF604 + dropdownIndex, uint8); gSound_config.sound_quality = (sint8)dropdownIndex; config_save();