diff --git a/src/audio.c b/src/audio.c index 6ad888b962..fe46f41668 100644 --- a/src/audio.c +++ b/src/audio.c @@ -23,6 +23,9 @@ #include "addresses.h" #include "config.h" #include "rct2.h" +#include "sprite.h" +#include "viewport.h" +#include "window.h" int gAudioDeviceCount; audio_device *gAudioDevices = NULL; @@ -193,7 +196,7 @@ int sound_load3dparameters() */ int sound_load3dposition() { - /*if (SUCCEEDED(RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER)->lpVtbl->GetPosition(RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER), &RCT2_GLOBAL(0x009A6084, DS3DBUFFER), 1))) { + /*if (SUCCEEDED(RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER)->lpVtbl->GetPosition(RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER), &RCT2_GLOBAL(0x009A6084, D3DVECTOR), 1))) { return 1; }*/ return 0; @@ -732,7 +735,7 @@ void audio_timefunc(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, D return; } } - if (FAILED(sound_channel->dsbuffer->lpVtbl->Lock(sound_channel->dsbuffer, sound_channel->playpos, var2, (LPVOID*)&buf1, (LPDWORD)&buf1size, (LPVOID*)&buf2, &buf2size, 0))) { + if (FAILED(sound_channel->dsbuffer->lpVtbl->Lock(sound_channel->dsbuffer, sound_channel->playpos, var2, (LPVOID*)&buf1, (LPDWORD)&buf1size, (LPVOID*)&buf2, (LPDWORD)&buf2size, 0))) { // TimeFunc() could not lock DirectSoundBuffer return; } @@ -1178,6 +1181,63 @@ int sound_play_panned(int sound_id, int x) return result; } +/** +* +* rct2: 0x00401B63 +*/ +int sub_401B63(int channel) +{ + if (RCT2_ADDRESS(RCT2_ADDRESS_SOUND_CHANNEL_LIST, rct_sound_channel)[channel].var_0) { + return RCT2_ADDRESS(RCT2_ADDRESS_SOUND_CHANNEL_LIST, rct_sound_channel)[channel].var_160 == 0; + } else { + return 0; + } +} + +/** +* +* rct2: 0x0040194E +*/ +int sound_channel_load_file2(int channel, char* filename, int offset) +{ + if (!RCT2_GLOBAL(0x009E1AA4, int)) { + return 0; + } + if (sub_401B63(channel)) { + sound_channel_stop(channel); + } + if (!sound_channel_load_file(channel, filename, offset)) { + RCT2_ADDRESS(RCT2_ADDRESS_SOUND_CHANNEL_LIST, rct_sound_channel)[channel].var_4 = 0; + return 1; + } + return 0; +} + +/** +* +* rct2: 0x006BD0F8 +*/ +void start_title_music() +{ + if ((RCT2_GLOBAL(0x009AF284, uint32) & (1 << 0)) && RCT2_GLOBAL(0x009AF59D, uint8) & 1 && RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 1) { + if (!RCT2_GLOBAL(0x009AF600, uint8)) { + RCT2_GLOBAL(0x014241BC, uint32) = 1; + int result = sound_channel_load_file2(3, (char*)get_file_path(PATH_ID_CSS17), 0); + RCT2_GLOBAL(0x014241BC, uint32) = 0; + if (result) { + RCT2_GLOBAL(0x014241BC, uint32) = 1; + sound_channel_play(3, 1, 0, 0, 0); + RCT2_GLOBAL(0x014241BC, uint32) = 0; + } + RCT2_GLOBAL(0x009AF600, uint8) = 1; + } + } else { + if (RCT2_GLOBAL(0x009AF600, uint8)) { + stop_title_music(); + } + } +} + /** * * rct2: 0x00401999 @@ -1241,6 +1301,30 @@ int sound_channel_set_volume(int channel, int volume) return 0; } +/** +* +* rct2: 0x006BB991 +*/ +void stop_completed_sounds() +{ + if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32) != -1) { + for (int i = 0; i < 7; i++) { + rct_other_sound* other_sound = &RCT2_ADDRESS(0x009AF484, rct_other_sound)[i]; + if (other_sound->id != (uint16)-1) { + RCT2_GLOBAL(0x014241BC, uint32) = 1; + int isplaying = sound_is_playing(&other_sound->sound); + RCT2_GLOBAL(0x014241BC, uint32) = 0; + if (!isplaying) { + RCT2_GLOBAL(0x014241BC, uint32) = 1; + sound_stop(&other_sound->sound); + RCT2_GLOBAL(0x014241BC, uint32) = 0; + other_sound->id = (uint16)-1; + } + } + } + } +} + /** * * rct2: 0x00404E7F @@ -1519,6 +1603,7 @@ void stop_title_music() RCT2_GLOBAL(0x014241BC, uint32) = 0; } } + RCT2_GLOBAL(0x009AF600, uint8) = 0; } /** diff --git a/src/audio.h b/src/audio.h index 6da01639df..c68b059e96 100644 --- a/src/audio.h +++ b/src/audio.h @@ -22,6 +22,7 @@ #define _AUDIO_H_ #include "rct2.h" +#include "sprite.h" typedef struct { char name[256]; @@ -51,7 +52,8 @@ typedef struct { */ typedef struct rct_sound { LPDIRECTSOUNDBUFFER dsbuffer; - int id; + uint16 id; + uint16 var_8; int has_caps; int var_0C; struct rct_sound* next; @@ -99,10 +101,14 @@ typedef struct { uint16 var_2; rct_sound sound1; // 0x04 uint16 var_18; - uint8 pad_1A[0x06]; + uint16 var_1A; + uint16 var_1C; + uint16 var_1D; rct_sound sound2; // 0x20 uint16 var_34; - uint8 pad_36[0x06]; + uint16 pad_36; + uint16 var_38; + uint16 var_3A; } rct_vehicle_sound; typedef struct { @@ -110,6 +116,17 @@ typedef struct { rct_sound sound; } rct_other_sound; +typedef struct { + uint16 id; + uint8 var_2; + uint8 var_3; + uint8 var_4; + uint16 var_5; + uint8 var_7; + uint16 var_8; + uint16 next; // 0xA +} rct_sound_unknown; + int get_dsound_devices(); int dsound_create_primary_buffer(int a, int device, int channels, int samples, int bits); void audio_timefunc(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2, int channel); @@ -134,6 +151,7 @@ int sound_channel_play(int channel, int a2, int volume, int pan, int frequency); int sound_channel_set_frequency(int channel, int frequency); int sound_channel_set_pan(int channel, int pan); int sound_channel_set_volume(int channel, int volume); +int sound_channel_load_file2(int channel, char* filename, int offset); int sound_channel_load_file(int channel, char* filename, int offset); void sound_channel_free(HMMIO* hmmio, HGLOBAL* hmem); int sound_stop(rct_sound *sound); @@ -145,11 +163,13 @@ rct_sound* sound_remove(rct_sound* sound); rct_sound* sound_begin(); rct_sound* sound_next(rct_sound* sound); void pause_sounds(); +void stop_completed_sounds(); void stop_other_sounds(); void stop_vehicle_sounds(); void stop_ride_music(); void stop_peep_sounds(); void stop_title_music(); +void start_title_music(); void unpause_sounds(); // 0x009AF59C probably does the same job diff --git a/src/game.c b/src/game.c index f67b6f9279..888955bbe0 100644 --- a/src/game.c +++ b/src/game.c @@ -305,7 +305,7 @@ void game_update() if (RCT2_GLOBAL(0x009DEA6E, uint8) == 0) { for (; eax > 0; eax--) { game_logic_update(); - RCT2_CALLPROC_EBPSAFE(0x006BD0F8); // play title screen music + start_title_music(); //RCT2_CALLPROC_EBPSAFE(0x006BD0F8); // play title screen music /* if (rctmem->dword_009E2D74 == 1) { @@ -388,7 +388,7 @@ void game_logic_update() news_item_update_current(); RCT2_CALLPROC_EBPSAFE(0x0067009A); // scenario editor opening of windows for a phase - RCT2_CALLPROC_EBPSAFE(0x006BB991); // removes other sounds that are no longer playing, this is normally called somewhere in rct2_init + 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/peep.c b/src/peep.c index ea85a117e4..447b7c08d1 100644 --- a/src/peep.c +++ b/src/peep.c @@ -330,7 +330,7 @@ void peep_update_crowd_noise() if (visiblePeeps < 0) { // Mute crowd noise if (RCT2_GLOBAL(0x009AF5FC, uint32) != 1) { - RCT2_CALLPROC_1(0x00401A05, int, 2); + sound_channel_stop(2); //RCT2_CALLPROC_1(0x00401A05, int, 2); RCT2_GLOBAL(0x009AF5FC, uint32) = 1; } } else { @@ -345,14 +345,14 @@ void peep_update_crowd_noise() // Check if crowd noise is already playing if (RCT2_GLOBAL(0x009AF5FC, uint32) == 1) { // Load and play crowd noise - if (RCT2_CALLFUNC_3(0x0040194E, int, int, char*, int, 2, (char*)get_file_path(PATH_ID_CSS2), 0)) { - RCT2_CALLPROC_5(0x00401999, int, int, int, int, int, 2, 1, volume, 0, 0); + if (sound_channel_load_file2(2, (char*)get_file_path(PATH_ID_CSS2), 0)) { + sound_channel_play(2, 1, volume, 0, 0); RCT2_GLOBAL(0x009AF5FC, uint32) = volume; } } else { // Alter crowd noise volume if (RCT2_GLOBAL(0x009AF5FC, uint32) != volume) { - RCT2_CALLPROC_2(0x00401AD3, int, int, 2, volume); + sound_channel_set_volume(2, volume);//RCT2_CALLPROC_2(0x00401AD3, int, int, 2, volume); RCT2_GLOBAL(0x009AF5FC, uint32) = volume; } } diff --git a/src/title.c b/src/title.c index adfb25e080..29f7c86774 100644 --- a/src/title.c +++ b/src/title.c @@ -262,7 +262,7 @@ void title_update() if (RCT2_GLOBAL(0x009DEA6E, uint8) == 0) { title_update_showcase(); game_logic_update(); - title_play_music(); + start_title_music();//title_play_music(); } RCT2_GLOBAL(0x009DE518, uint32) &= ~0x80; @@ -304,9 +304,10 @@ void title_update() * * rct2: 0x00678761 */ +// this doesn't seem like it is 0x00678761, supposed to be 0x006BD0F8? static void title_play_music() { - // RCT2_CALLPROC_EBPSAFE(0x006BD0F8); // play title screen music + RCT2_CALLPROC_EBPSAFE(0x006BD0F8); // play title screen music if (!(RCT2_GLOBAL(0x009AF284, uint32) & 1) || !(RCT2_GLOBAL(0x009AF59D, uint8) & 1)) { if (RCT2_GLOBAL(0x009AF600, uint8) != 0) @@ -325,8 +326,8 @@ static void title_play_music() strcat(musicPath, "\\data\\css50.dat"); } - if (RCT2_CALLFUNC_3(0x0040194E, int, int, char*, int, 3, musicPath, 0)) // play music - RCT2_CALLPROC_5(0x00401999, int, int, int, int, int, 3, 1, 0, 0, 0); + if (sound_channel_load_file2(3, musicPath, 0)) // play music + sound_channel_play(3, 1, 0, 0, 0); RCT2_GLOBAL(0x009AF600, uint8) = 1; } diff --git a/src/vehicle.h b/src/vehicle.h index 92ada2f2fd..046d719a34 100644 --- a/src/vehicle.h +++ b/src/vehicle.h @@ -23,6 +23,14 @@ #include "rct2.h" +typedef union { + struct { + uint16 width; + uint16 height; + }; + uint32 both; +} rct_widthheight; + typedef struct { uint8 sprite_identifier; // 0x00 uint8 pad_01[0x03]; @@ -35,8 +43,10 @@ typedef struct { sint16 x; // 0x0E sint16 y; // 0x10 sint16 z; // 0x12 - uint8 pad_14[0x0B]; - uint8 var_1F; + uint8 pad_14[0x02]; + rct_widthheight var_16; + rct_widthheight view; // 0x1A + uint16 var_1E; uint8 pad_20[0x08]; uint32 var_28; uint8 pad_2C[0x04]; @@ -49,10 +59,11 @@ typedef struct { uint8 pad_4A[0x06]; uint8 var_50; uint8 var_51; - uint8 pad_52[0x69]; - uint16 var_BB; - uint16 var_BD; - uint8 pad_BF[0x0D]; + uint8 pad_52[0x2E]; + uint8 var_BB; + uint8 var_BC; + uint8 var_BD; + uint8 pad_BE[0x0E]; uint8 var_CC; uint8 pad_CD[0x09]; uint8 var_D6; diff --git a/src/window_options.c b/src/window_options.c index 8190d761ed..342023204f 100644 --- a/src/window_options.c +++ b/src/window_options.c @@ -526,7 +526,7 @@ static void window_options_dropdown() case WIDX_MUSIC_DROPDOWN: RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_MUSIC, uint8) = (uint8)dropdownIndex; config_save(); - RCT2_CALLPROC_EBPSAFE(0x006BCA9F); + stop_ride_music();//RCT2_CALLPROC_EBPSAFE(0x006BCA9F); window_invalidate(w); break; case WIDX_SOUND_QUALITY_DROPDOWN: