diff --git a/src/addresses.h b/src/addresses.h index efb780f9e5..feca8397a2 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -106,6 +106,8 @@ #define RCT2_ADDRESS_INSTALLED_OBJECT_LIST 0x009ADAE8 +#define RCT2_ADDRESS_CURRENT_SOUND_DEVICE 0x009AF280 + #define RCT2_ADDRESS_CURENT_CURSOR 0x009DE51C #define RCT2_ADDRESS_INPUT_STATE 0x009DE51D #define RCT2_ADDRESS_CURSOR_DOWN_WINDOWCLASS 0x009DE51F diff --git a/src/audio.c b/src/audio.c index 8f2d0cce27..14778f7926 100644 --- a/src/audio.c +++ b/src/audio.c @@ -172,6 +172,22 @@ int sound_play(rct_sound* sound, int looping, int volume, int pan, int frequency return 0; } +/** +* +* rct2: 0x00404E53 +*/ +int sound_is_playing(rct_sound* sound){ + if (sound) { + DWORD status; + if (SUCCEEDED(sound->dsbuffer->lpVtbl->GetStatus(sound->dsbuffer, &status))) { + if (status & DSBSTATUS_PLAYING || status & DSBSTATUS_LOOPING) + return 1; + + } + } + return 0; +} + /** * * rct2: 0x00404ED7 @@ -260,21 +276,112 @@ rct_sound* sound_remove(rct_sound* sound) * * rct2: 0x006BABB4 */ -void pause_sounds() { +void pause_sounds() +{ if (++RCT2_GLOBAL(0x009AF59C, uint8) == 1) { - RCT2_CALLPROC_EBPSAFE(0x006BCAE5); - RCT2_CALLPROC_EBPSAFE(0x006BABDF); - RCT2_CALLPROC_EBPSAFE(0x006BCA9F); - RCT2_CALLPROC_EBPSAFE(0x006BD07F); + pause_other_sounds(); //RCT2_CALLPROC_EBPSAFE(0x006BCAE5); // ? sounds + pause_vehicle_sounds(); //RCT2_CALLPROC_EBPSAFE(0x006BABDF); // vehicle sounds + pause_ride_music(); //RCT2_CALLPROC_EBPSAFE(0x006BCA9F); // ride music + pause_peep_sounds(); //RCT2_CALLPROC_EBPSAFE(0x006BD07F); // peep sounds } g_sounds_disabled = 1; } +/** +* +* rct2: 0x006BCAE5 +*/ +void pause_other_sounds() +{ + if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32) != 0xFFFFFFFF) { + if (RCT2_GLOBAL(0x009AF5A8, uint32) != 1) { + RCT2_GLOBAL(0x014241BC, uint32) = 1; + sound_stop(RCT2_GLOBAL(0x009AF5AC, rct_sound*)); + RCT2_GLOBAL(0x014241BC, uint32) = 0; + RCT2_GLOBAL(0x009AF5A8, uint32) = 1; + } + if (RCT2_GLOBAL(0x009AF5C0, uint32) != 8) { + RCT2_GLOBAL(0x014241BC, uint32) = 1; + sound_stop(RCT2_GLOBAL(0x009AF5C4, rct_sound*)); + RCT2_GLOBAL(0x014241BC, uint32) = 0; + RCT2_GLOBAL(0x009AF5C0, uint32) = 8; + } + if (RCT2_GLOBAL(0x009AF5D8, uint32) != 8) { + RCT2_GLOBAL(0x014241BC, uint32) = 1; + sound_stop(RCT2_GLOBAL(0x009AF5DC, rct_sound*)); + RCT2_GLOBAL(0x014241BC, uint32) = 0; + RCT2_GLOBAL(0x009AF5D8, uint32) = 8; + } + } +} + +/** +* +* rct2: 0x006BABDF +*/ +void pause_vehicle_sounds() +{ + if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32) != 0xFFFFFFFF) { + for (int i = 0; i < 7; i++) { + uint8 * data = RCT2_ADDRESS(0x009AF288 + (i * 60), uint8); + if (*(uint16 *)&data[0] != 0xFFFF) { + if (*(uint16 *)&data[0x18] != 0xFFFF) { + RCT2_GLOBAL(0x014241BC, uint32) = 1; + sound_stop((rct_sound*)&data[0x04]); + RCT2_GLOBAL(0x014241BC, uint32) = 0; + } + if (*(uint16 *)&data[0x34] != 0xFFFF) { + RCT2_GLOBAL(0x014241BC, uint32) = 1; + sound_stop((rct_sound*)&data[0x20]); + RCT2_GLOBAL(0x014241BC, uint32) = 0; + } + } + *(uint16 *)&data[0] = 0xFFFF; + } + } +} + +/** +* +* rct2: 0x006BCA9F +*/ +void pause_ride_music() +{ + if ((RCT2_GLOBAL(0x009AF284, uint32) & (1 << 0))) { + for (int i = 0; i < 2; i++) { + uint8 * data = RCT2_ADDRESS(0x009AF46C + (i * 8), uint8); + if (data[0] != 0xFF) { + RCT2_GLOBAL(0x014241BC, uint32) = 1; + RCT2_CALLPROC_1(0x00401A05, int, i); + RCT2_GLOBAL(0x014241BC, uint32) = 0; + data[0] = 0xFF; + } + } + } +} + +/** +* +* rct2: 0x006BD07F +*/ +void pause_peep_sounds() +{ + if ((RCT2_GLOBAL(0x009AF284, uint32) & (1 << 0))) { + if (RCT2_GLOBAL(0x009AF5FC, uint32) != 1) { + RCT2_GLOBAL(0x014241BC, uint32) = 1; + RCT2_CALLPROC_1(0x00401A05, int, 2); + RCT2_GLOBAL(0x014241BC, uint32) = 0; + RCT2_GLOBAL(0x009AF5FC, uint32) = 1; + } + } +} + /** * * rct2: 0x006BABD8 */ -void unpause_sounds() { +void unpause_sounds() +{ RCT2_GLOBAL(0x009AF59C, uint8)--; g_sounds_disabled = 0; } \ No newline at end of file diff --git a/src/audio.h b/src/audio.h index e40b1416f3..af98b232a4 100644 --- a/src/audio.h +++ b/src/audio.h @@ -59,6 +59,7 @@ void get_dsound_devices(); int sound_prepare(int sound_id, rct_sound *sound, int var_8, int var_c); void sound_play_panned(int sound_id, int x); int sound_play(rct_sound* sound, int looping, int volume, int pan, int frequency); +int sound_is_playing(rct_sound* sound); int sound_set_frequency(rct_sound* sound, int frequency); int sound_set_pan(rct_sound* sound, int pan); int sound_set_volume(rct_sound* sound, int volume); @@ -69,6 +70,10 @@ int sound_channel_set_volume(int channel, int volume); void sound_stop(rct_sound *sound); rct_sound* sound_remove(rct_sound* sound); void pause_sounds(); +void pause_other_sounds(); +void pause_vehicle_sounds(); +void pause_ride_music(); +void pause_peep_sounds(); void unpause_sounds(); // 0x009AF59C probably does the same job diff --git a/src/climate.c b/src/climate.c index 5f1bf8902b..af633917fa 100644 --- a/src/climate.c +++ b/src/climate.c @@ -186,7 +186,7 @@ static void climate_determine_future_weather() */ void climate_update_sound() { - if (RCT2_GLOBAL(0x009AF280, uint32) == 0xFFFFFFFF) + if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32) == 0xFFFFFFFF) return; if (RCT2_GLOBAL(0x009AF59C, uint8) != 0) return; @@ -210,13 +210,13 @@ static void climate_update_rain_sound() } else { // Increase rain sound _rainVolume = min(-1400, _rainVolume + 80); - RCT2_CALLPROC_2(0x00404F0D, rct_sound*, int, &_rainSoundInstance, _rainVolume); + sound_set_volume(&_rainSoundInstance, _rainVolume); } } else if (_rainVolume != 1) { // Decrease rain sound _rainVolume -= 80; if (_rainVolume > -4000) { - RCT2_CALLPROC_2(0x00404F0D, rct_sound*, int, &_rainSoundInstance, _rainVolume); + sound_set_volume(&_rainSoundInstance, _rainVolume); } else { sound_stop(&_rainSoundInstance); _rainVolume = 1; @@ -248,7 +248,7 @@ static void climate_update_thunder_sound() if (_thunderStatus[i] == THUNDER_STATUS_NULL) continue; - if (!RCT2_CALLFUNC_1(0x00404E53, int, rct_sound*, &_thunderSoundInstance[i])) { + if (!sound_is_playing(&_thunderSoundInstance[i])) { sound_stop(&_thunderSoundInstance[i]); _thunderStatus[i] = THUNDER_STATUS_NULL; } diff --git a/src/intro.c b/src/intro.c index 75f3c853cb..8b2ee2fdba 100644 --- a/src/intro.c +++ b/src/intro.c @@ -80,7 +80,7 @@ void intro_update() // Chain lift sound _sound_playing_flag = 0; - if (RCT2_GLOBAL(0x009AF280, sint32) != -1) { + if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, sint32) != -1) { // Prepare and play the sound if (sound_prepare(SOUND_LIFT_7, &_prepared_sound, 0, 1)) if (sound_play(&_prepared_sound, 1, 0, 0, 0)) @@ -157,7 +157,7 @@ void intro_update() } // Play the track friction sound - if (RCT2_GLOBAL(0x009AF280, sint32) != -1) { + if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, sint32) != -1) { // Prepare and play the sound if (sound_prepare(SOUND_TRACK_FRICTION_3, &_prepared_sound, 1, 1)) if (sound_play(&_prepared_sound, 1, -800, 0, 0x3A98)) @@ -188,7 +188,7 @@ void intro_update() } // Play long peep scream sound - if (RCT2_GLOBAL(0x009AF280, sint32) != -1) + if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, sint32) != -1) if (sound_prepare(SOUND_SCREAM_1, &_prepared_sound, 0, 1)) if (sound_play(&_prepared_sound, 0, 0, 0, 0)) _sound_playing_flag = 1; diff --git a/src/window_options.c b/src/window_options.c index 738fe92bdf..952e294d86 100644 --- a/src/window_options.c +++ b/src/window_options.c @@ -379,7 +379,7 @@ static void window_options_mousedown(int widgetIndex, rct_window*w, rct_widget* window_options_show_dropdown(w, widget, gAudioDeviceCount); - gDropdownItemsChecked |= (1 << RCT2_GLOBAL(0x9AF280, uint32)); + gDropdownItemsChecked |= (1 << RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32)); break; case WIDX_HEIGHT_LABELS_DROPDOWN: gDropdownItemsFormat[0] = 1142; @@ -670,7 +670,7 @@ static void window_options_invalidate() window_options_widgets[WIDX_HEIGHT_LABELS_DROPDOWN].type = WWT_DROPDOWN_BUTTON; break; case WINDOW_OPTIONS_PAGE_AUDIO: - currentSoundDevice = RCT2_GLOBAL(0x009AF280, sint32); + currentSoundDevice = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, sint32); // sound devices if (currentSoundDevice == -1 || gAudioDeviceCount == 0) {