From 2b04c64e9cb91cf8f15b995935bb8dbd9cfd973f Mon Sep 17 00:00:00 2001 From: zsilencer Date: Sun, 24 Aug 2014 04:45:59 -0600 Subject: [PATCH 01/58] More decompiled sound functions --- src/addresses.h | 2 + src/audio.c | 119 ++++++++++++++++++++++++++++++++++++++++--- src/audio.h | 5 ++ src/climate.c | 8 +-- src/intro.c | 6 +-- src/window_options.c | 4 +- 6 files changed, 129 insertions(+), 15 deletions(-) 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) { From 362082980f57d53c091782ea7f26222fec6e8c58 Mon Sep 17 00:00:00 2001 From: zsilencer Date: Sun, 24 Aug 2014 14:30:48 -0600 Subject: [PATCH 02/58] Audio things --- src/addresses.h | 4 ++- src/audio.c | 65 ++++++++++++++++++++++++++++++++++--------------- src/audio.h | 33 ++++++++++++++++++++++--- 3 files changed, 77 insertions(+), 25 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index feca8397a2..e371cafe26 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -108,6 +108,8 @@ #define RCT2_ADDRESS_CURRENT_SOUND_DEVICE 0x009AF280 +#define RCT2_ADDRESS_VEHICLE_SOUND_LIST 0x009AF288 + #define RCT2_ADDRESS_CURENT_CURSOR 0x009DE51C #define RCT2_ADDRESS_INPUT_STATE 0x009DE51D #define RCT2_ADDRESS_CURSOR_DOWN_WINDOWCLASS 0x009DE51F @@ -310,7 +312,7 @@ #define RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER 0x0141ED68 - +#define RCT2_ADDRESS_SOUND_CHANNEL_LIST 0x014262E0 #define RCT2_ADDRESS_WATER_RAISE_COST 0x0141F738 #define RCT2_ADDRESS_WATER_LOWER_COST 0x0141F73C diff --git a/src/audio.c b/src/audio.c index 14778f7926..be4683a9c0 100644 --- a/src/audio.c +++ b/src/audio.c @@ -90,14 +90,15 @@ void sound_play_panned(int sound_id, int x) */ int sound_channel_play(int channel, int a2, int volume, int pan, int frequency) { - RCT2_GLOBAL(0x1426444 + (91 * channel * 4), uint32) = a2; + rct_sound_channel* sound_channel = &RCT2_ADDRESS(RCT2_ADDRESS_SOUND_CHANNEL_LIST, rct_sound_channel)[channel]; + sound_channel->var_164 = a2; sound_channel_set_frequency(channel, frequency); sound_channel_set_pan(channel, pan); sound_channel_set_volume(channel, volume); LPDIRECTSOUNDBUFFER dsbuffer = RCT2_ADDRESS(RCT2_ADDRESS_DSOUND_BUFFERS, LPDIRECTSOUNDBUFFER)[channel]; dsbuffer->lpVtbl->SetCurrentPosition(dsbuffer, 0); dsbuffer->lpVtbl->Play(dsbuffer, 0, 0, DSBPLAY_LOOPING); - RCT2_GLOBAL(0x14262E0 + (91 * channel * 4), uint32) = 1; + sound_channel->var_0 = 1; return 1; } @@ -279,10 +280,10 @@ rct_sound* sound_remove(rct_sound* sound) void pause_sounds() { if (++RCT2_GLOBAL(0x009AF59C, uint8) == 1) { - 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 + stop_other_sounds(); + stop_vehicle_sounds(); + stop_ride_music(); + stop_peep_sounds(); } g_sounds_disabled = 1; } @@ -291,7 +292,7 @@ void pause_sounds() * * rct2: 0x006BCAE5 */ -void pause_other_sounds() +void stop_other_sounds() { if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32) != 0xFFFFFFFF) { if (RCT2_GLOBAL(0x009AF5A8, uint32) != 1) { @@ -319,24 +320,24 @@ void pause_other_sounds() * * rct2: 0x006BABDF */ -void pause_vehicle_sounds() +void stop_vehicle_sounds() { - if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32) != 0xFFFFFFFF) { + if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, sint32) != -1) { 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) { + rct_vehicle_sound* vehicle_sound = &RCT2_ADDRESS(RCT2_ADDRESS_VEHICLE_SOUND_LIST, rct_vehicle_sound)[i]; + if (vehicle_sound->var_0 != 0xFFFF) { + if (vehicle_sound->var_18 != 0xFFFF) { RCT2_GLOBAL(0x014241BC, uint32) = 1; - sound_stop((rct_sound*)&data[0x04]); + sound_stop(&vehicle_sound->sound1); RCT2_GLOBAL(0x014241BC, uint32) = 0; } - if (*(uint16 *)&data[0x34] != 0xFFFF) { + if (vehicle_sound->var_34 != 0xFFFF) { RCT2_GLOBAL(0x014241BC, uint32) = 1; - sound_stop((rct_sound*)&data[0x20]); + sound_stop(&vehicle_sound->sound2); RCT2_GLOBAL(0x014241BC, uint32) = 0; } } - *(uint16 *)&data[0] = 0xFFFF; + vehicle_sound->var_0 = 0xFFFF; } } } @@ -345,14 +346,14 @@ void pause_vehicle_sounds() * * rct2: 0x006BCA9F */ -void pause_ride_music() +void stop_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); + sound_channel_stop(i); RCT2_GLOBAL(0x014241BC, uint32) = 0; data[0] = 0xFF; } @@ -364,18 +365,42 @@ void pause_ride_music() * * rct2: 0x006BD07F */ -void pause_peep_sounds() +void stop_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); + sound_channel_stop(2); RCT2_GLOBAL(0x014241BC, uint32) = 0; RCT2_GLOBAL(0x009AF5FC, uint32) = 1; } } } +/** +* +* rct2: 0x00401A05 +*/ +int sound_channel_stop(int channel) +{ + rct_sound_channel* sound_channel = &RCT2_ADDRESS(RCT2_ADDRESS_SOUND_CHANNEL_LIST, rct_sound_channel)[channel]; + sound_channel->var_0 = 0; + sound_channel->var_160 = 1; + while (InterlockedExchange(&RCT2_GLOBAL(0x009E1AAC, int), 1) != 1) { + Sleep(10); + } + if (sound_channel->var_120) + RCT2_CALLPROC_2(0x00405436, uint32, uint32, sound_channel->var_11C, sound_channel->var_120); // free_sound? + + LPDIRECTSOUNDBUFFER dsbuffer = RCT2_ADDRESS(RCT2_ADDRESS_DSOUND_BUFFERS, LPDIRECTSOUNDBUFFER)[channel]; + if (dsbuffer) { + dsbuffer->lpVtbl->Stop(dsbuffer); + dsbuffer->lpVtbl->Release(dsbuffer); + } + InterlockedExchange(&RCT2_GLOBAL(0x009E1AAC, int), 0); + return 1; +} + /** * * rct2: 0x006BABD8 diff --git a/src/audio.h b/src/audio.h index af98b232a4..ddc9f46d72 100644 --- a/src/audio.h +++ b/src/audio.h @@ -21,6 +21,8 @@ #ifndef _AUDIO_H_ #define _AUDIO_H_ +#include "rct2.h" + typedef struct { char name[256]; } audio_device; @@ -55,6 +57,28 @@ typedef struct rct_sound { struct rct_sound* next; } rct_sound; +typedef struct { + uint32 var_0; + uint8 pad_4[0x118]; + uint32 var_11C; + uint32 var_120; + uint8 pad_124[0x3C]; + uint32 var_160; + uint32 var_164; + uint32 var_168; +} rct_sound_channel; + +typedef struct { + uint16 var_0; + uint16 var_2; + rct_sound sound1; // 0x04 + uint16 var_18; + uint8 pad_1A[0x06]; + rct_sound sound2; // 0x20 + uint16 var_34; + uint8 pad_36[0x06]; +} rct_vehicle_sound; + 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); @@ -68,12 +92,13 @@ 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); void sound_stop(rct_sound *sound); +int sound_channel_stop(int channel); 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 stop_other_sounds(); +void stop_vehicle_sounds(); +void stop_ride_music(); +void stop_peep_sounds(); void unpause_sounds(); // 0x009AF59C probably does the same job From 799797876a712cae699bdeaeb7bdecd9d9b59e9a Mon Sep 17 00:00:00 2001 From: zsilencer Date: Sun, 24 Aug 2014 22:18:01 -0600 Subject: [PATCH 03/58] Audio fixes #361 #355 --- src/audio.c | 136 +++++++++++++++++++++++++++++++++++++++++-- src/audio.h | 10 +++- src/game.c | 2 + src/window_options.c | 6 +- 4 files changed, 145 insertions(+), 9 deletions(-) diff --git a/src/audio.c b/src/audio.c index be4683a9c0..7f123efcd9 100644 --- a/src/audio.c +++ b/src/audio.c @@ -21,6 +21,7 @@ #include #include "audio.h" #include "addresses.h" +#include "config.h" #include "rct2.h" int gAudioDeviceCount; @@ -65,6 +66,86 @@ void audio_get_devices() } } +/** +* +* rct2: 0x006BAB21 +*/ +void audio_6BAB21(void) +{ + if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32) != -1) { + stop_other_sounds(); + stop_peep_sounds(); + RCT2_CALLPROC_EBPSAFE(0x006BD0BD); + if (RCT2_GLOBAL(0x009AF284, uint32) & (1 << 0)) { + stop_ride_music(); + RCT2_GLOBAL(0x014241BC, uint32) = 1; + RCT2_CALLPROC(0x004018F0); // remove multimedia timer + RCT2_GLOBAL(0x014241BC, uint32) = 0; + } + RCT2_GLOBAL(0x014241BC, uint32) = 1; + RCT2_CALLPROC(0x00404C45); + RCT2_CALLPROC(0x00404BD2); + RCT2_GLOBAL(0x014241BC, uint32) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32) = -1; + } +} + +/** +* +* rct2: 0x006BA9B5 +*/ +void audio_init2(int device) +{ + audio_6BAB21(); + for (int i = 0; i < 7; i++) { + rct_vehicle_sound* vehicle_sound = &RCT2_ADDRESS(RCT2_ADDRESS_VEHICLE_SOUND_LIST, rct_vehicle_sound)[i]; + vehicle_sound->id = 0xFFFF; + } + for (int i = 0; i < 7; i++) { + rct_other_sound* other_sound = &RCT2_ADDRESS(0x009AF484, rct_other_sound)[i]; + other_sound->id = 0xFFFF; + } + RCT2_GLOBAL(0x014241BC, uint32) = 1; + int v5 = RCT2_CALLFUNC_5(0x00404932, int, int, int, int, int, int, 0, device, 2, 22050, 16); + RCT2_GLOBAL(0x014241BC, uint32) = 0; + if (!v5) { + return; + } + const char * filepath = get_file_path(2); + RCT2_GLOBAL(0x014241BC, uint32) = 1; + int v8 = RCT2_CALLFUNC_1(0x00404C1A, int, const char *, filepath); + RCT2_GLOBAL(0x014241BC, uint32) = 0; + if (!v8) { + RCT2_GLOBAL(0x014241BC, uint32) = 1; + RCT2_CALLPROC(0x00404BD2); + RCT2_GLOBAL(0x014241BC, uint32) = 0; + return; + } + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32) = device; + int* data = RCT2_ADDRESS(RCT2_ADDRESS_DSOUND_DEVICES + (0x210 * device), int); + RCT2_GLOBAL(0x009AAC5D, uint32) = data[0]; + RCT2_GLOBAL(0x009AAC61, uint32) = data[1]; + RCT2_GLOBAL(0x009AAC65, uint32) = data[2]; + RCT2_GLOBAL(0x009AAC69, uint32) = data[3]; + RCT2_GLOBAL(0x009AAC5C, uint8) = 1; + config_save(); + RCT2_GLOBAL(0x014241BC, uint32) = 1; + int result = RCT2_CALLFUNC(0x004018A6, int); // create multimedia timer + RCT2_GLOBAL(0x014241BC, uint32) = 0; + if (result) { + if ((RCT2_GLOBAL(0x009AF284, uint32) & (1 << 0))) { + for (int i = 0; i < 2; i++) { + RCT2_GLOBAL(0x009AF46C + (i * 8), uint8) = -1; + } + } + } + if (!RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) & 1 << 4) { + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_SOUND_SW_BUFFER, uint32) = RCT2_GLOBAL(0x001425B74, uint32) != RCT2_GLOBAL(0x001425B78, uint32) || RCT2_GLOBAL(0x001425B74, uint32) != RCT2_GLOBAL(0x001425B7C, uint32); + RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) |= 1 << 4; + config_save(); + } +} + /** * * rct2: 0x0040502E @@ -74,14 +155,58 @@ void get_dsound_devices() RCT2_CALLPROC(0x0040502E); } +/** +* +* rct2: 0x00404C6D +*/ int sound_prepare(int sound_id, rct_sound *sound, int var_8, int var_c) { return RCT2_CALLFUNC_4(0x00404C6D, int, int, rct_sound*, int, int, sound_id, sound, var_8, var_c); } -void sound_play_panned(int sound_id, int x) +/** +* +* rct2: 0x006BB76E +*/ +int sound_play_panned(int sound_id, int x) { - RCT2_CALLPROC_X(0x006BB76E, sound_id, x, 0, 0, 0, 0, 0); + //RCT2_CALLPROC_X(0x006BB76E, sound_id, x, 0, 0, 0, 0, 0); + // this function is not complete, need to add in volume and pan adjust + int result = 0; + if (RCT2_GLOBAL(0x009AF59D, uint8) & 1) { + RCT2_GLOBAL(0x00F438AD, uint8) = 0; + int volume = 0; + if (x == 0x8001) { + // stuff to adjust volume + } + int i = 0; + rct_other_sound* other_sound = &RCT2_ADDRESS(0x009AF484, rct_other_sound)[i]; + 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 + return sound_id; + } + } + other_sound->id = sound_id; + int pan; + if (x == 0x8000) { + pan = 0; + } else { + // stuff to adjust pan + } + if (!RCT2_GLOBAL(0x009AAC6D, uint8)) { + pan = 0; + } + + RCT2_GLOBAL(0x014241BC, uint32) = 1; + sound_prepare(sound_id, &other_sound->sound, 1, RCT2_GLOBAL(0x009AAC6E, uint32)); + RCT2_GLOBAL(0x014241BC, uint32) = 0; + RCT2_GLOBAL(0x014241BC, uint32) = 1; + result = sound_play(&other_sound->sound, 0, volume, pan, 0); + RCT2_GLOBAL(0x014241BC, uint32) = 0; + } + return result; } /** @@ -294,7 +419,7 @@ void pause_sounds() */ void stop_other_sounds() { - if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32) != 0xFFFFFFFF) { + if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32) != -1) { if (RCT2_GLOBAL(0x009AF5A8, uint32) != 1) { RCT2_GLOBAL(0x014241BC, uint32) = 1; sound_stop(RCT2_GLOBAL(0x009AF5AC, rct_sound*)); @@ -325,7 +450,7 @@ void stop_vehicle_sounds() if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, sint32) != -1) { for (int i = 0; i < 7; i++) { rct_vehicle_sound* vehicle_sound = &RCT2_ADDRESS(RCT2_ADDRESS_VEHICLE_SOUND_LIST, rct_vehicle_sound)[i]; - if (vehicle_sound->var_0 != 0xFFFF) { + if (vehicle_sound->id != 0xFFFF) { if (vehicle_sound->var_18 != 0xFFFF) { RCT2_GLOBAL(0x014241BC, uint32) = 1; sound_stop(&vehicle_sound->sound1); @@ -337,7 +462,7 @@ void stop_vehicle_sounds() RCT2_GLOBAL(0x014241BC, uint32) = 0; } } - vehicle_sound->var_0 = 0xFFFF; + vehicle_sound->id = 0xFFFF; } } } @@ -396,6 +521,7 @@ int sound_channel_stop(int channel) if (dsbuffer) { dsbuffer->lpVtbl->Stop(dsbuffer); dsbuffer->lpVtbl->Release(dsbuffer); + RCT2_ADDRESS(RCT2_ADDRESS_DSOUND_BUFFERS, LPDIRECTSOUNDBUFFER)[channel] = 0; } InterlockedExchange(&RCT2_GLOBAL(0x009E1AAC, int), 0); return 1; diff --git a/src/audio.h b/src/audio.h index ddc9f46d72..e7430cec61 100644 --- a/src/audio.h +++ b/src/audio.h @@ -33,6 +33,7 @@ extern audio_device *gAudioDevices; void audio_init(); void audio_quit(); void audio_get_devices(); +void audio_init2(int device); #include @@ -69,7 +70,7 @@ typedef struct { } rct_sound_channel; typedef struct { - uint16 var_0; + uint16 id; uint16 var_2; rct_sound sound1; // 0x04 uint16 var_18; @@ -79,9 +80,14 @@ typedef struct { uint8 pad_36[0x06]; } rct_vehicle_sound; +typedef struct { + uint16 id; + rct_sound sound; +} rct_other_sound; + 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_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); diff --git a/src/game.c b/src/game.c index 2ea9e63a97..4b8a8a8cb1 100644 --- a/src/game.c +++ b/src/game.c @@ -388,6 +388,8 @@ 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 + // Update windows window_dispatch_update_all(); diff --git a/src/window_options.c b/src/window_options.c index 952e294d86..8190d761ed 100644 --- a/src/window_options.c +++ b/src/window_options.c @@ -500,13 +500,15 @@ static void window_options_dropdown() switch (widgetIndex) { case WIDX_SOUND_DROPDOWN: - #ifdef _MSC_VER + audio_init2(dropdownIndex); + /*#ifdef _MSC_VER __asm movzx ax, dropdownIndex #else __asm__ ( "movzx ax, %[dropdownIndex] " : : [dropdownIndex] "g" ((char)dropdownIndex) ); #endif // the switch replaces ax value - RCT2_CALLPROC_EBPSAFE(0x006BA9B5); // part of init audio + RCT2_CALLPROC_EBPSAFE(0x006BA9B5); // part of init audio*/ + window_invalidate(w); break; case WIDX_HEIGHT_LABELS_DROPDOWN: From 7f5b501808feed95ec3093143b1e21754f86de3e Mon Sep 17 00:00:00 2001 From: zsilencer Date: Sun, 24 Aug 2014 22:39:37 -0600 Subject: [PATCH 04/58] travis --- src/audio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/audio.c b/src/audio.c index 7f123efcd9..ea9758c378 100644 --- a/src/audio.c +++ b/src/audio.c @@ -511,7 +511,7 @@ int sound_channel_stop(int channel) rct_sound_channel* sound_channel = &RCT2_ADDRESS(RCT2_ADDRESS_SOUND_CHANNEL_LIST, rct_sound_channel)[channel]; sound_channel->var_0 = 0; sound_channel->var_160 = 1; - while (InterlockedExchange(&RCT2_GLOBAL(0x009E1AAC, int), 1) != 1) { + while (InterlockedExchange(&RCT2_GLOBAL(0x009E1AAC, LONG), 1) != 1) { Sleep(10); } if (sound_channel->var_120) @@ -523,7 +523,7 @@ int sound_channel_stop(int channel) dsbuffer->lpVtbl->Release(dsbuffer); RCT2_ADDRESS(RCT2_ADDRESS_DSOUND_BUFFERS, LPDIRECTSOUNDBUFFER)[channel] = 0; } - InterlockedExchange(&RCT2_GLOBAL(0x009E1AAC, int), 0); + InterlockedExchange(&RCT2_GLOBAL(0x009E1AAC, LONG), 0); return 1; } From de918219b07e6dc3abdf5d38118768b4f6c921c6 Mon Sep 17 00:00:00 2001 From: zsilencer Date: Sun, 24 Aug 2014 22:51:17 -0600 Subject: [PATCH 05/58] -march=pentium --- CMakeLists_mingw.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists_mingw.txt b/CMakeLists_mingw.txt index f3df7c65fe..e7fd222dd7 100644 --- a/CMakeLists_mingw.txt +++ b/CMakeLists_mingw.txt @@ -10,7 +10,7 @@ SET(PKG_CONFIG_EXECUTABLE ${COMPILER_PREFIX}-pkg-config) # potential flags to make code more similar to MSVC: # -fshort-wchar -fshort-enums -mms-bitfields # -set(CMAKE_C_FLAGS "-masm=intel -std=gnu99 -fpack-struct=2" CACHE STRING "" FORCE) +set(CMAKE_C_FLAGS "-masm=intel -march=pentium -std=gnu99 -fpack-struct=2" CACHE STRING "" FORCE) set(CMAKE_SHARED_LINKER_FLAGS "-static-libgcc" CACHE STRING "" FORCE) # find and include SDL2 From 9cb6b2ada57d30085003cb81ea6bf62e81ee76c8 Mon Sep 17 00:00:00 2001 From: zsilencer Date: Mon, 25 Aug 2014 11:39:01 -0600 Subject: [PATCH 06/58] compile fix --- CMakeLists_mingw.txt | 2 +- src/audio.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists_mingw.txt b/CMakeLists_mingw.txt index e7fd222dd7..f3df7c65fe 100644 --- a/CMakeLists_mingw.txt +++ b/CMakeLists_mingw.txt @@ -10,7 +10,7 @@ SET(PKG_CONFIG_EXECUTABLE ${COMPILER_PREFIX}-pkg-config) # potential flags to make code more similar to MSVC: # -fshort-wchar -fshort-enums -mms-bitfields # -set(CMAKE_C_FLAGS "-masm=intel -march=pentium -std=gnu99 -fpack-struct=2" CACHE STRING "" FORCE) +set(CMAKE_C_FLAGS "-masm=intel -std=gnu99 -fpack-struct=2" CACHE STRING "" FORCE) set(CMAKE_SHARED_LINKER_FLAGS "-static-libgcc" CACHE STRING "" FORCE) # find and include SDL2 diff --git a/src/audio.c b/src/audio.c index ea9758c378..fb6b639d47 100644 --- a/src/audio.c +++ b/src/audio.c @@ -511,7 +511,7 @@ int sound_channel_stop(int channel) rct_sound_channel* sound_channel = &RCT2_ADDRESS(RCT2_ADDRESS_SOUND_CHANNEL_LIST, rct_sound_channel)[channel]; sound_channel->var_0 = 0; sound_channel->var_160 = 1; - while (InterlockedExchange(&RCT2_GLOBAL(0x009E1AAC, LONG), 1) != 1) { + while (_InterlockedExchange(&RCT2_GLOBAL(0x009E1AAC, LONG), 1) != 1) { Sleep(10); } if (sound_channel->var_120) @@ -523,7 +523,7 @@ int sound_channel_stop(int channel) dsbuffer->lpVtbl->Release(dsbuffer); RCT2_ADDRESS(RCT2_ADDRESS_DSOUND_BUFFERS, LPDIRECTSOUNDBUFFER)[channel] = 0; } - InterlockedExchange(&RCT2_GLOBAL(0x009E1AAC, LONG), 0); + _InterlockedExchange(&RCT2_GLOBAL(0x009E1AAC, LONG), 0); return 1; } From f14a9411c4968f92c1567724b08aa36bede334ec Mon Sep 17 00:00:00 2001 From: adrian17 Date: Mon, 25 Aug 2014 23:51:05 +0200 Subject: [PATCH 07/58] Fix #305, the day value wasn't increased by 1 as it should be --- src/news_item.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/news_item.c b/src/news_item.c index e2053594e5..986502d1fe 100644 --- a/src/news_item.c +++ b/src/news_item.c @@ -264,7 +264,7 @@ void news_item_add_to_queue(uint8 type, rct_string_id string_id, uint32 assoc) newsItem->assoc = assoc; newsItem->ticks = 0; newsItem->month_year = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONTH_YEAR, uint16); - newsItem->day = (days_in_month[(newsItem->month_year & 7)] * RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONTH_TICKS, uint16)) >> 16; + newsItem->day = ((days_in_month[(newsItem->month_year & 7)] * RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONTH_TICKS, uint16)) >> 16) + 1; format_string((char*)0x0141EF68, string_id, (void*)0x013CE952); // overflows possible? newsItem->colour = ((char*)0x0141EF68)[0]; From 5fe03d9929282c22d8629a5440c1457b244cabf4 Mon Sep 17 00:00:00 2001 From: zsilencer Date: Mon, 25 Aug 2014 19:56:20 -0600 Subject: [PATCH 08/58] sound_fill_buffer, sound_prepare --- src/audio.c | 141 +++++++++++++++++++++++++++++++++++++++++++--- src/audio.h | 5 +- src/osinterface.c | 3 +- src/window_ride.c | 1 + 4 files changed, 138 insertions(+), 12 deletions(-) diff --git a/src/audio.c b/src/audio.c index fb6b639d47..9146d2d097 100644 --- a/src/audio.c +++ b/src/audio.c @@ -70,7 +70,7 @@ void audio_get_devices() * * rct2: 0x006BAB21 */ -void audio_6BAB21(void) +void sub_6BAB21(void) { if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32) != -1) { stop_other_sounds(); @@ -96,7 +96,7 @@ void audio_6BAB21(void) */ void audio_init2(int device) { - audio_6BAB21(); + sub_6BAB21(); for (int i = 0; i < 7; i++) { rct_vehicle_sound* vehicle_sound = &RCT2_ADDRESS(RCT2_ADDRESS_VEHICLE_SOUND_LIST, rct_vehicle_sound)[i]; vehicle_sound->id = 0xFFFF; @@ -155,13 +155,132 @@ void get_dsound_devices() RCT2_CALLPROC(0x0040502E); } +/** +* +* rct2: 0x00404D99 +*/ +int sub_404D99(rct_sound* sound, rct_sound* end) +{ + return RCT2_CALLFUNC_2(0x00404D99, int, rct_sound*, rct_sound*, sound, end); +} + +/** +* +* rct2: 0x00405109 +*/ +rct_sound* sub_405109(rct_sound* end) +{ + return RCT2_CALLFUNC_1(0x00405109, rct_sound*, rct_sound*, end); +} + +/** +* +* rct2: 0x00405206 +*/ +int sub_405206(uint16 sound_id) +{ + if (RCT2_GLOBAL(0x009E2B94, uint32) && sound_id < RCT2_GLOBAL(0x009E2B94, uint32)) { + return RCT2_GLOBAL(0x009E2B94, uint32) + RCT2_GLOBAL(0x009E2B94, uint32*)[sound_id + 1]; + } + return 0; +} + +/** +* +* rct2: 0x00405054 +*/ +int sub_405054(int var1, WAVEFORMATEX* waveformat, DWORD* var3, DWORD* buffersize) +{ + *buffersize = *(DWORD*)var1; + *(DWORD *)&waveformat->wFormatTag = var1 + 4; + *var3 = var1 + 22; + return 1; +} + +/** +* +* rct2: 0x00405076 +*/ +int sound_fill_buffer(LPDIRECTSOUNDBUFFER dsbuffer, char* src, int size) +{ + char* buf; + char* buf2; + int buf2size; + if (SUCCEEDED(dsbuffer->lpVtbl->Lock(dsbuffer, 0, size, &buf, &size, &buf2, &buf2size, 0))) { + memset(buf, 0, size); + memcpy(buf, src, size); + if (buf2size) { + memcpy(buf2, &src[size], buf2size); + } + dsbuffer->lpVtbl->Unlock(dsbuffer, buf, size, buf2, buf2size); + return 1; + } + return 0; +} + /** * * rct2: 0x00404C6D */ -int sound_prepare(int sound_id, rct_sound *sound, int var_8, int var_c) +int sound_prepare(int sound_id, rct_sound *sound, int channels, int software) { - return RCT2_CALLFUNC_4(0x00404C6D, int, int, rct_sound*, int, int, sound_id, sound, var_8, var_c); + //return RCT2_CALLFUNC_4(0x00404C6D, int, int, rct_sound*, int, int, sound_id, sound, channels, software); + DSBUFFERDESC bufferdesc; + void* var2 = 0; + + memset(&bufferdesc, 0, sizeof(bufferdesc)); + bufferdesc.dwSize = sizeof(bufferdesc); + rct_sound* begin = RCT2_CALLFUNC(0x00405103, rct_sound*); + if (begin) { + int beginfound = 0; + while (!begin->dsbuffer || begin->id != sound_id || !sub_404D99(sound, begin)) { + begin = sub_405109(begin); + if (!begin) { + beginfound = 1; + break; + } + } + if (!beginfound) { + return 1; + } + } + int b = sub_405206(sound_id); + if (b) { + if (sub_405054(b, (WAVEFORMATEX*)&bufferdesc.lpwfxFormat, (DWORD*)&var2, &bufferdesc.dwBufferBytes)) { + bufferdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_STATIC; + if (channels) { + if (channels == 2) { + bufferdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLPAN | DSBCAPS_CTRLFREQUENCY | DSBCAPS_STATIC; + } else { + bufferdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRL3D | DSBCAPS_STATIC; + } + + if (RCT2_GLOBAL(0x009E2B90, uint32)) { + bufferdesc.dwFlags |= DSBCAPS_CTRLPAN; + } + + if (software) { + bufferdesc.dwFlags |= DSBCAPS_LOCSOFTWARE; + } + + if (SUCCEEDED(RCT2_GLOBAL(0x009E2BA0, LPDIRECTSOUND)->lpVtbl->CreateSoundBuffer(RCT2_GLOBAL(0x009E2BA0, LPDIRECTSOUND), &bufferdesc, &sound->dsbuffer, 0))) { + if (sound_fill_buffer(sound->dsbuffer, var2, bufferdesc.dwBufferBytes)) { + sound->id = sound_id; + DSBCAPS caps; + caps.dwSize = sizeof(caps); + sound->dsbuffer->lpVtbl->GetCaps(sound->dsbuffer, &caps); + sound->has_caps = caps.dwFlags; + RCT2_CALLPROC_1(0x0040511C, rct_sound*, sound); // adds sound to list + return 1; + } + sound->dsbuffer->lpVtbl->Release(sound->dsbuffer); + sound->dsbuffer = 0; + } + } + sound->dsbuffer = 0; + } + } + return 0; } /** @@ -171,7 +290,7 @@ int sound_prepare(int sound_id, rct_sound *sound, int var_8, int var_c) int sound_play_panned(int sound_id, int x) { //RCT2_CALLPROC_X(0x006BB76E, sound_id, x, 0, 0, 0, 0, 0); - // this function is not complete, need to add in volume and pan adjust + // this function is not complete, need to add in volume adjust int result = 0; if (RCT2_GLOBAL(0x009AF59D, uint8) & 1) { RCT2_GLOBAL(0x00F438AD, uint8) = 0; @@ -193,7 +312,12 @@ int sound_play_panned(int sound_id, int x) if (x == 0x8000) { pan = 0; } else { - // stuff to adjust pan + int x2 = x << 16; + uint16 screenwidth = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16); + if (screenwidth < 64) { + screenwidth = 64; + } + pan = ((x2 / screenwidth) - 0x8000) >> 4; } if (!RCT2_GLOBAL(0x009AAC6D, uint8)) { pan = 0; @@ -360,13 +484,14 @@ int sound_set_volume(rct_sound* sound, int volume) * * rct2: 0x00404DD8 */ -void sound_stop(rct_sound* sound) +rct_sound* sound_stop(rct_sound* sound) { if (sound->dsbuffer) { sound->dsbuffer->lpVtbl->Release(sound->dsbuffer); sound->dsbuffer = 0; - sound_remove(sound); + return sound_remove(sound); } + return sound; } /** diff --git a/src/audio.h b/src/audio.h index e7430cec61..ad19e54b3a 100644 --- a/src/audio.h +++ b/src/audio.h @@ -35,7 +35,6 @@ void audio_quit(); void audio_get_devices(); void audio_init2(int device); - #include /** @@ -86,7 +85,7 @@ typedef struct { } rct_other_sound; void get_dsound_devices(); -int sound_prepare(int sound_id, rct_sound *sound, int var_8, int var_c); +int sound_prepare(int sound_id, rct_sound *sound, int channels, int software); int 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); @@ -97,7 +96,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); -void sound_stop(rct_sound *sound); +rct_sound* sound_stop(rct_sound *sound); int sound_channel_stop(int channel); rct_sound* sound_remove(rct_sound* sound); void pause_sounds(); diff --git a/src/osinterface.c b/src/osinterface.c index c86a3f792c..9213603e7d 100644 --- a/src/osinterface.c +++ b/src/osinterface.c @@ -452,6 +452,7 @@ int osinterface_open_common_file_dialog(int type, char *title, char *filename, c OPENFILENAME openFileName; BOOL result; int tmp; + DWORD commonFlags; // Get directory path from given filename strcpy(initialDirectory, filename); @@ -488,7 +489,7 @@ int osinterface_open_common_file_dialog(int type, char *title, char *filename, c RCT2_GLOBAL(0x009E2C74, uint32) = 1; // Open dialog - DWORD commonFlags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_NOCHANGEDIR; + commonFlags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_NOCHANGEDIR; if (type == 0) { openFileName.Flags = commonFlags | OFN_CREATEPROMPT | OFN_OVERWRITEPROMPT; result = GetSaveFileName(&openFileName); diff --git a/src/window_ride.c b/src/window_ride.c index fb0384abeb..66b9e2a23b 100644 --- a/src/window_ride.c +++ b/src/window_ride.c @@ -113,6 +113,7 @@ rct_window *window_ride_open(int rideIndex) ebx++; } RCT2_GLOBAL((int)w + 496, uint16) = ebx; + return w; } /** From f6fde582bfaa7a41927830a580b34350952b9eeb Mon Sep 17 00:00:00 2001 From: zsilencer Date: Mon, 25 Aug 2014 23:11:57 -0600 Subject: [PATCH 09/58] audio work --- src/addresses.h | 2 + src/audio.c | 116 +++++++++++++++++++++++++++++++++++------------- src/audio.h | 13 +++++- 3 files changed, 97 insertions(+), 34 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index 4f620d00bd..700ad084be 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -161,8 +161,10 @@ #define RCT2_ADDRESS_DSOUND_BUFFERS 0x009E1AB0 #define RCT2_ADDRESS_NUM_DSOUND_DEVICES 0x009E2B88 #define RCT2_ADDRESS_DSOUND_DEVICES 0x009E2B8C +#define RCT2_ADDRESS_SOUND_INFO_LIST_OFFSET 0x009E2B94 #define RCT2_ADDRESS_SOUNDLIST_BEGIN 0x009E2B98 #define RCT2_ADDRESS_SOUNDLIST_END 0x009E2B9C +#define RCT2_ADDRESS_DIRECTSOUND 0x009E2BA0 #define RCT2_ADDRESS_CMDLINE 0x009E2D98 diff --git a/src/audio.c b/src/audio.c index 9146d2d097..4bfbf81863 100644 --- a/src/audio.c +++ b/src/audio.c @@ -159,28 +159,49 @@ void get_dsound_devices() * * rct2: 0x00404D99 */ -int sub_404D99(rct_sound* sound, rct_sound* end) +int sound_duplicate(rct_sound* newsound, rct_sound* sound) { - return RCT2_CALLFUNC_2(0x00404D99, int, rct_sound*, rct_sound*, sound, end); + if (FAILED(RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND)->lpVtbl->DuplicateSoundBuffer(RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND), sound->dsbuffer, &newsound->dsbuffer))) { + return 0; + } else { + newsound->id = sound->id; + newsound->has_caps = sound->has_caps; + newsound->var_0C = sound->var_0C; + sound_add(newsound); + return 1; + } +} + +/** +* +* rct2: 0x00405103 +*/ +rct_sound* sound_begin() +{ + return RCT2_GLOBAL(RCT2_ADDRESS_SOUNDLIST_BEGIN, rct_sound*); } /** * * rct2: 0x00405109 */ -rct_sound* sub_405109(rct_sound* end) +rct_sound* sound_next(rct_sound* sound) { - return RCT2_CALLFUNC_1(0x00405109, rct_sound*, rct_sound*, end); + if (RCT2_GLOBAL(RCT2_ADDRESS_SOUNDLIST_END, rct_sound*) == sound) { + return 0; + } else { + return sound->next; + } } /** * * rct2: 0x00405206 */ -int sub_405206(uint16 sound_id) +rct_sound_info* sound_get_info(uint16 sound_id) { - if (RCT2_GLOBAL(0x009E2B94, uint32) && sound_id < RCT2_GLOBAL(0x009E2B94, uint32)) { - return RCT2_GLOBAL(0x009E2B94, uint32) + RCT2_GLOBAL(0x009E2B94, uint32*)[sound_id + 1]; + if (RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_OFFSET, int) && sound_id < RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_OFFSET, int)) { + return (rct_sound_info*)(RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_OFFSET, int) + RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_OFFSET, int*)[sound_id + 1]); } return 0; } @@ -189,11 +210,11 @@ int sub_405206(uint16 sound_id) * * rct2: 0x00405054 */ -int sub_405054(int var1, WAVEFORMATEX* waveformat, DWORD* var3, DWORD* buffersize) +int sound_info_loadvars(rct_sound_info* sound_info, LPWAVEFORMATEX* waveformat, char** data, DWORD* buffersize) { - *buffersize = *(DWORD*)var1; - *(DWORD *)&waveformat->wFormatTag = var1 + 4; - *var3 = var1 + 22; + *buffersize = sound_info->size; + *waveformat = &sound_info->format; + *data = (char*)&sound_info->data; return 1; } @@ -226,27 +247,26 @@ int sound_prepare(int sound_id, rct_sound *sound, int channels, int software) { //return RCT2_CALLFUNC_4(0x00404C6D, int, int, rct_sound*, int, int, sound_id, sound, channels, software); DSBUFFERDESC bufferdesc; - void* var2 = 0; - + char* buffer = 0; memset(&bufferdesc, 0, sizeof(bufferdesc)); bufferdesc.dwSize = sizeof(bufferdesc); - rct_sound* begin = RCT2_CALLFUNC(0x00405103, rct_sound*); - if (begin) { - int beginfound = 0; - while (!begin->dsbuffer || begin->id != sound_id || !sub_404D99(sound, begin)) { - begin = sub_405109(begin); - if (!begin) { - beginfound = 1; + rct_sound* tempsound = sound_begin(); + if (tempsound) { + int wasduplicated = 0; + while (!tempsound->dsbuffer || tempsound->id != sound_id || !sound_duplicate(sound, tempsound)) { + tempsound = sound_next(tempsound); + if (!tempsound) { + wasduplicated = 1; break; } } - if (!beginfound) { + if (!wasduplicated) { return 1; } } - int b = sub_405206(sound_id); - if (b) { - if (sub_405054(b, (WAVEFORMATEX*)&bufferdesc.lpwfxFormat, (DWORD*)&var2, &bufferdesc.dwBufferBytes)) { + rct_sound_info* sound_info = sound_get_info(sound_id); + if (sound_info) { + if (sound_info_loadvars(sound_info, &bufferdesc.lpwfxFormat, &buffer, &bufferdesc.dwBufferBytes)) { bufferdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_STATIC; if (channels) { if (channels == 2) { @@ -254,23 +274,20 @@ int sound_prepare(int sound_id, rct_sound *sound, int channels, int software) } else { bufferdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRL3D | DSBCAPS_STATIC; } - if (RCT2_GLOBAL(0x009E2B90, uint32)) { bufferdesc.dwFlags |= DSBCAPS_CTRLPAN; } - if (software) { bufferdesc.dwFlags |= DSBCAPS_LOCSOFTWARE; } - - if (SUCCEEDED(RCT2_GLOBAL(0x009E2BA0, LPDIRECTSOUND)->lpVtbl->CreateSoundBuffer(RCT2_GLOBAL(0x009E2BA0, LPDIRECTSOUND), &bufferdesc, &sound->dsbuffer, 0))) { - if (sound_fill_buffer(sound->dsbuffer, var2, bufferdesc.dwBufferBytes)) { + if (SUCCEEDED(RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND)->lpVtbl->CreateSoundBuffer(RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND), &bufferdesc, &sound->dsbuffer, 0))) { + if (sound_fill_buffer(sound->dsbuffer, buffer, bufferdesc.dwBufferBytes)) { sound->id = sound_id; DSBCAPS caps; caps.dwSize = sizeof(caps); sound->dsbuffer->lpVtbl->GetCaps(sound->dsbuffer, &caps); sound->has_caps = caps.dwFlags; - RCT2_CALLPROC_1(0x0040511C, rct_sound*, sound); // adds sound to list + sound_add(sound); return 1; } sound->dsbuffer->lpVtbl->Release(sound->dsbuffer); @@ -494,6 +511,22 @@ rct_sound* sound_stop(rct_sound* sound) return sound; } +/** +* +* rct2: 0x0040511C +*/ +rct_sound* sound_add(rct_sound* sound) +{ + if (RCT2_GLOBAL(RCT2_ADDRESS_SOUNDLIST_BEGIN, rct_sound*)) { + RCT2_GLOBAL(RCT2_ADDRESS_SOUNDLIST_END, rct_sound*)->next = sound; + } else { + RCT2_GLOBAL(RCT2_ADDRESS_SOUNDLIST_BEGIN, rct_sound*) = sound; + } + RCT2_GLOBAL(RCT2_ADDRESS_SOUNDLIST_END, rct_sound*) = sound; + sound->next = 0; + return sound; +} + /** * * rct2: 0x00405143 @@ -523,6 +556,24 @@ rct_sound* sound_remove(rct_sound* sound) return result; } +/** +* +* rct2: 0x00405436 +*/ +void sound_channel_free(HMMIO* hmmio, HGLOBAL* hmem) +{ + if(*hmem) + { + GlobalFree(*hmem); + *hmem = 0; + } + if(*hmmio) + { + mmioClose(*hmmio, 0); + *hmmio = 0; + } +} + /** * * rct2: 0x006BABB4 @@ -639,8 +690,9 @@ int sound_channel_stop(int channel) while (_InterlockedExchange(&RCT2_GLOBAL(0x009E1AAC, LONG), 1) != 1) { Sleep(10); } - if (sound_channel->var_120) - RCT2_CALLPROC_2(0x00405436, uint32, uint32, sound_channel->var_11C, sound_channel->var_120); // free_sound? + if (sound_channel->hmem) { + sound_channel_free(&sound_channel->hmmio, &sound_channel->hmem); + } LPDIRECTSOUNDBUFFER dsbuffer = RCT2_ADDRESS(RCT2_ADDRESS_DSOUND_BUFFERS, LPDIRECTSOUNDBUFFER)[channel]; if (dsbuffer) { diff --git a/src/audio.h b/src/audio.h index ad19e54b3a..6009cd40cf 100644 --- a/src/audio.h +++ b/src/audio.h @@ -60,14 +60,20 @@ typedef struct rct_sound { typedef struct { uint32 var_0; uint8 pad_4[0x118]; - uint32 var_11C; - uint32 var_120; + HMMIO hmmio; + HGLOBAL hmem; uint8 pad_124[0x3C]; uint32 var_160; uint32 var_164; uint32 var_168; } rct_sound_channel; +typedef struct { + uint32 size; + WAVEFORMATEX format; + char* data; +} rct_sound_info; + typedef struct { uint16 id; uint16 var_2; @@ -98,7 +104,10 @@ int sound_channel_set_pan(int channel, int pan); int sound_channel_set_volume(int channel, int volume); rct_sound* sound_stop(rct_sound *sound); int sound_channel_stop(int channel); +rct_sound* sound_add(rct_sound* sound); rct_sound* sound_remove(rct_sound* sound); +rct_sound* sound_begin(); +rct_sound* sound_next(rct_sound* sound); void pause_sounds(); void stop_other_sounds(); void stop_vehicle_sounds(); From 08ab2cdfe87b1dc8e182b9c137aa9163129cbf0c Mon Sep 17 00:00:00 2001 From: zsilencer Date: Tue, 26 Aug 2014 16:34:34 -0600 Subject: [PATCH 10/58] some directsound decompilation --- projects/openrct2.vcxproj | 4 +- src/addresses.h | 3 + src/audio.c | 282 +++++++++++++++++++++++++++++++++++--- src/audio.h | 17 ++- src/rct2.c | 2 +- src/title.c | 3 +- 6 files changed, 283 insertions(+), 28 deletions(-) diff --git a/projects/openrct2.vcxproj b/projects/openrct2.vcxproj index 9c079203b5..3077811de3 100644 --- a/projects/openrct2.vcxproj +++ b/projects/openrct2.vcxproj @@ -201,7 +201,7 @@ true - winmm.lib;sdl2.lib;%(AdditionalDependencies) + winmm.lib;sdl2.lib;Dsound.lib;%(AdditionalDependencies) @@ -224,7 +224,7 @@ true true true - winmm.lib;sdl2.lib;%(AdditionalDependencies) + winmm.lib;sdl2.lib;Dsound.lib;%(AdditionalDependencies) xcopy /Y "$(ProjectDir)\..\Data\Language\*.*" "$(TargetDir)\Data\Language\" diff --git a/src/addresses.h b/src/addresses.h index 700ad084be..d6b95d7426 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -165,6 +165,7 @@ #define RCT2_ADDRESS_SOUNDLIST_BEGIN 0x009E2B98 #define RCT2_ADDRESS_SOUNDLIST_END 0x009E2B9C #define RCT2_ADDRESS_DIRECTSOUND 0x009E2BA0 +#define RCT2_ADDRESS_DSOUND_DEVICES_COUNTER 0x009E2BAC #define RCT2_ADDRESS_CMDLINE 0x009E2D98 @@ -316,6 +317,8 @@ #define RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER 0x0141ED68 +#define RCT2_ADDRESS_AUDIO_INFO 0x01425B40 + #define RCT2_ADDRESS_SOUND_CHANNEL_LIST 0x014262E0 #define RCT2_ADDRESS_WATER_RAISE_COST 0x0141F738 diff --git a/src/audio.c b/src/audio.c index 4bfbf81863..ecc2ddb50d 100644 --- a/src/audio.c +++ b/src/audio.c @@ -66,16 +66,79 @@ void audio_get_devices() } } +/** +* +* rct2: 0x00404BD2 +*/ +int sound_release() +{ + sound_stop_all(); + if (RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER)) { + RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER)->lpVtbl->Release(RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER)); + RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER) = 0; + } + if (RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER)) { + RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER)->lpVtbl->Release(RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER)); + RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER) = 0; + } + int result = 0; + if (RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND)) { + result = RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND)->lpVtbl->Release(RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND)); + RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND) = 0; + } + return result; +} + +/** +* +* rct2: 0x00404C45 +*/ +int sound_unmap_info() +{ + if (RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_OFFSET, int)) { + sound_stop_all(); + sound_unmap_file(RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_OFFSET, LPCVOID)); + RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_OFFSET, int) = 0; + return 1; + } + return 0; +} + +/** +* +* rct2: 0x00404DF5 +*/ +int sound_stop_all() +{ + int result = 0; + while (RCT2_GLOBAL(RCT2_ADDRESS_SOUNDLIST_BEGIN, rct_sound*)) { + result = sound_stop(RCT2_GLOBAL(RCT2_ADDRESS_SOUNDLIST_BEGIN, rct_sound*)); + } + return result; +} + +/** +* +* rct2: 0x004068A0 +*/ +int sound_unmap_file(LPCVOID base) +{ + if (base) { + return UnmapViewOfFile(base); + } + return 0; +} + /** * * rct2: 0x006BAB21 */ -void sub_6BAB21(void) +void sub_6BAB21() { if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32) != -1) { stop_other_sounds(); stop_peep_sounds(); - RCT2_CALLPROC_EBPSAFE(0x006BD0BD); + stop_title_music(); if (RCT2_GLOBAL(0x009AF284, uint32) & (1 << 0)) { stop_ride_music(); RCT2_GLOBAL(0x014241BC, uint32) = 1; @@ -83,13 +146,125 @@ void sub_6BAB21(void) RCT2_GLOBAL(0x014241BC, uint32) = 0; } RCT2_GLOBAL(0x014241BC, uint32) = 1; - RCT2_CALLPROC(0x00404C45); - RCT2_CALLPROC(0x00404BD2); + sound_unmap_info(); + sound_release(); RCT2_GLOBAL(0x014241BC, uint32) = 0; RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32) = -1; } } +/** +* +* rct2: 0x000404F28 +*/ +int sound_load3dparameters() +{ + if (SUCCEEDED(RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER)->lpVtbl->GetAllParameters(RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER), &RCT2_GLOBAL(0x009A6084, DS3DBUFFER)))) { + return 1; + } + return 0; +} + +/** +* +* rct2: 0x00404932 +*/ +int dsound_create_primary_buffer(int a, int device, int channels, int samples, int bits) +{ + rct_dsdevice* dsdevice = 0; + if (device) { + if (device > RCT2_GLOBAL(RCT2_ADDRESS_NUM_DSOUND_DEVICES, int)) { + return 0; + } + dsdevice = &RCT2_GLOBAL(RCT2_ADDRESS_DSOUND_DEVICES, rct_dsdevice*)[device]; + } + memset(&RCT2_GLOBAL(RCT2_ADDRESS_AUDIO_INFO, rct_audio_info), 0, sizeof(rct_audio_info)); + RCT2_GLOBAL(RCT2_ADDRESS_AUDIO_INFO, rct_audio_info).var_0 = 1; + RCT2_GLOBAL(RCT2_ADDRESS_AUDIO_INFO, rct_audio_info).channels = channels; + RCT2_GLOBAL(RCT2_ADDRESS_AUDIO_INFO, rct_audio_info).samples = samples; + RCT2_GLOBAL(RCT2_ADDRESS_AUDIO_INFO, rct_audio_info).var_8 = samples * RCT2_GLOBAL(0x01425B4C, uint16); + RCT2_GLOBAL(RCT2_ADDRESS_AUDIO_INFO, rct_audio_info).bytes = bits * channels / 8; + RCT2_GLOBAL(RCT2_ADDRESS_AUDIO_INFO, rct_audio_info).bits = bits; + RCT2_GLOBAL(RCT2_ADDRESS_AUDIO_INFO, rct_audio_info).var_E = 0; + DSBUFFERDESC bufferdesc; + memset(&bufferdesc, 0, sizeof(bufferdesc)); + bufferdesc.dwSize = sizeof(bufferdesc); + if (a) { + if (a != 1) { + return 0; + } + bufferdesc.dwFlags = DSBCAPS_CTRL3D | DSBCAPS_PRIMARYBUFFER; + if (RCT2_GLOBAL(0x009E2B90, uint32)) { + bufferdesc.dwFlags = DSBCAPS_STICKYFOCUS | DSBCAPS_CTRL3D | DSBCAPS_PRIMARYBUFFER; + } + if (FAILED(DirectSoundCreate(&dsdevice->guid, &RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND), 0))) { + return 0; + } + if (FAILED(RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND)->lpVtbl->SetCooperativeLevel(RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND), RCT2_GLOBAL(0x009E2D70, HWND), DSSCL_NORMAL)) || + FAILED(RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND)->lpVtbl->CreateSoundBuffer(RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND), &bufferdesc, &RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER), 0))) { + RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND)->lpVtbl->Release(RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND)); + RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND) = 0; + return 0; + } + if (SUCCEEDED(RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER)->lpVtbl->QueryInterface(RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER), &RCT2_GLOBAL(0x009A4444, IID) /* IID_IDirectSound3DBuffer */, &RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER)))) { + // doesn't seem to ever make it here, below doesn't make sense and is probably remnants of unused 3d sound tests + memset(&RCT2_GLOBAL(0x009A6084, DS3DBUFFER), 0, sizeof(RCT2_GLOBAL(0x009A6084, DS3DBUFFER))); + RCT2_GLOBAL(0x009A6084, DS3DBUFFER).dwSize = sizeof(RCT2_GLOBAL(0x009A6084, DS3DBUFFER)); + + if (sound_load3dparameters()) { + RCT2_GLOBAL(0x009A6084, DS3DBUFFER).vPosition.x = 0.0f; + } + RCT2_GLOBAL(0x009A6084, DS3DBUFFER).vPosition.y = 0.0f; + RCT2_GLOBAL(0x009A6084, DS3DBUFFER).vPosition.x = -1.0f; + RCT2_GLOBAL(0x009A6084, DS3DBUFFER).flMaxDistance = 9.8999996f; + RCT2_GLOBAL(0x009A6084, DS3DBUFFER).flMinDistance = 0.25f; + if (RCT2_CALLFUNC(0x00404F3F, int)) { + if (SUCCEEDED(RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER)->lpVtbl->SetMinDistance(RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER), RCT2_GLOBAL(0x009A6084, DS3DBUFFER).flMinDistance, 1))) { + if (sound_load3dparameters()) { + return 1; + } + } + } + RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER)->lpVtbl->Release(RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER)); + RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER) = 0; + RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER)->lpVtbl->Release(RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER)); + RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND)->lpVtbl->Release(RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND)); + RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND) = 0; + } else { + RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER)->lpVtbl->Release(RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER)); + RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND)->lpVtbl->Release(RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND)); + RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND) = 0; + } + } + bufferdesc.dwFlags = DSBCAPS_PRIMARYBUFFER; + if (RCT2_GLOBAL(0x009E2B90, uint32)) { + bufferdesc.dwFlags = DSBCAPS_STICKYFOCUS | DSBCAPS_PRIMARYBUFFER; + } + if (FAILED(DirectSoundCreate(&dsdevice->guid, &RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND), 0))) { + return 0; + } + if (FAILED(RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND)->lpVtbl->SetCooperativeLevel(RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND), RCT2_GLOBAL(0x009E2D70, HWND), DSSCL_PRIORITY))) { + RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND)->lpVtbl->Release(RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND)); + RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND) = 0; + return 0; + } + RCT2_GLOBAL(0x01425B60, DSCAPS).dwSize = sizeof(DSCAPS); + RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND)->lpVtbl->GetCaps(RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND), &RCT2_GLOBAL(0x01425B60, DSCAPS)); + if (FAILED(RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND)->lpVtbl->CreateSoundBuffer(RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND), &bufferdesc, &RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER), 0))) { + RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER)->lpVtbl->Release(RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER)); + RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND)->lpVtbl->Release(RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND)); + RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND) = 0; + } + WAVEFORMATEX waveformat1, waveformat2; + RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER)->lpVtbl->GetFormat(RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER), &waveformat1, sizeof(WAVEFORMATEX), 0); + RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER)->lpVtbl->SetFormat(RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER), &RCT2_GLOBAL(0x01425B40, WAVEFORMATEX)); + RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER)->lpVtbl->GetFormat(RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER), &waveformat2, sizeof(WAVEFORMATEX), 0); + return 1; +} + /** * * rct2: 0x006BA9B5 @@ -106,7 +281,8 @@ void audio_init2(int device) other_sound->id = 0xFFFF; } RCT2_GLOBAL(0x014241BC, uint32) = 1; - int v5 = RCT2_CALLFUNC_5(0x00404932, int, int, int, int, int, int, 0, device, 2, 22050, 16); + int v5 = dsound_create_primary_buffer(0, device, 2, 22050, 16); + //int v5 = RCT2_CALLFUNC_5(0x00404932, int, int, int, int, int, int, 0, device, 2, 22050, 16); RCT2_GLOBAL(0x014241BC, uint32) = 0; if (!v5) { return; @@ -117,16 +293,16 @@ void audio_init2(int device) RCT2_GLOBAL(0x014241BC, uint32) = 0; if (!v8) { RCT2_GLOBAL(0x014241BC, uint32) = 1; - RCT2_CALLPROC(0x00404BD2); + sound_release(); RCT2_GLOBAL(0x014241BC, uint32) = 0; return; } RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32) = device; - int* data = RCT2_ADDRESS(RCT2_ADDRESS_DSOUND_DEVICES + (0x210 * device), int); - RCT2_GLOBAL(0x009AAC5D, uint32) = data[0]; - RCT2_GLOBAL(0x009AAC61, uint32) = data[1]; - RCT2_GLOBAL(0x009AAC65, uint32) = data[2]; - RCT2_GLOBAL(0x009AAC69, uint32) = data[3]; + rct_dsdevice dsdevice = RCT2_GLOBAL(RCT2_ADDRESS_DSOUND_DEVICES, rct_dsdevice*)[device]; + RCT2_GLOBAL(0x009AAC5D, uint32) = dsdevice.guid.Data1; + RCT2_GLOBAL(0x009AAC61, uint32) = dsdevice.guid.Data2; + RCT2_GLOBAL(0x009AAC65, uint32) = dsdevice.guid.Data3; + RCT2_GLOBAL(0x009AAC69, uint32) = (uint32)dsdevice.guid.Data4; RCT2_GLOBAL(0x009AAC5C, uint8) = 1; config_save(); RCT2_GLOBAL(0x014241BC, uint32) = 1; @@ -146,13 +322,60 @@ void audio_init2(int device) } } +/** +* +* rct2: 0x00404F85 +*/ +BOOL CALLBACK dsound_enum_callback_count(LPGUID lpGuid, LPCSTR lpcstrDescription, LPCSTR lpcstrModule, LPVOID lpContext) +{ + RCT2_GLOBAL(RCT2_ADDRESS_DSOUND_DEVICES_COUNTER, int)++; + return 1; +} + +/** +* +* rct2: 0x00404F91 +*/ +int dsound_count_devices() +{ + RCT2_GLOBAL(RCT2_ADDRESS_DSOUND_DEVICES_COUNTER, int) = 0; + if (SUCCEEDED(DirectSoundEnumerate(dsound_enum_callback_count, 0))) { + return RCT2_GLOBAL(RCT2_ADDRESS_DSOUND_DEVICES_COUNTER, int); + } + return 0; +} + +/** +* +* rct2: 0x00404FB1 +*/ +BOOL CALLBACK dsound_enum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription, LPCSTR lpcstrModule, LPVOID lpContext) +{ + if (lpGuid) { + memcpy(&RCT2_GLOBAL(RCT2_ADDRESS_DSOUND_DEVICES, rct_dsdevice*)[RCT2_GLOBAL(0x01425B54, int)].guid, lpGuid, sizeof(GUID)); + } else { + memset(&RCT2_GLOBAL(RCT2_ADDRESS_DSOUND_DEVICES, rct_dsdevice*)[RCT2_GLOBAL(0x01425B54, int)].guid, 0, sizeof(GUID)); + } + strcpy(RCT2_GLOBAL(RCT2_ADDRESS_DSOUND_DEVICES, rct_dsdevice*)[RCT2_GLOBAL(0x01425B54, int)].desc, lpcstrDescription); + strcpy(RCT2_GLOBAL(RCT2_ADDRESS_DSOUND_DEVICES, rct_dsdevice*)[RCT2_GLOBAL(0x01425B54, int)].drvname, lpcstrModule); + RCT2_GLOBAL(0x01425B54, int)++; + return 1; +} + /** * * rct2: 0x0040502E */ -void get_dsound_devices() +int get_dsound_devices() { - RCT2_CALLPROC(0x0040502E); + RCT2_GLOBAL(RCT2_ADDRESS_NUM_DSOUND_DEVICES, uint32) = dsound_count_devices(); + RCT2_GLOBAL(RCT2_ADDRESS_DSOUND_DEVICES, rct_dsdevice*) = malloc(RCT2_GLOBAL(RCT2_ADDRESS_NUM_DSOUND_DEVICES, uint32) * sizeof(rct_dsdevice)); + if (RCT2_GLOBAL(RCT2_ADDRESS_DSOUND_DEVICES, rct_dsdevice*)) { + RCT2_GLOBAL(0x01425B54, int) = 0; + DirectSoundEnumerate(dsound_enum_callback, 0); + return RCT2_GLOBAL(0x01425B54, int); + } + return 0; } /** @@ -200,7 +423,7 @@ rct_sound* sound_next(rct_sound* sound) */ rct_sound_info* sound_get_info(uint16 sound_id) { - if (RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_OFFSET, int) && sound_id < RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_OFFSET, int)) { + if (RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_OFFSET, int) && sound_id < RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_OFFSET, int*)[0]) { return (rct_sound_info*)(RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_OFFSET, int) + RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_OFFSET, int*)[sound_id + 1]); } return 0; @@ -419,7 +642,7 @@ int sound_channel_set_volume(int channel, int volume) */ int sound_play(rct_sound* sound, int looping, int volume, int pan, int frequency) { - if (sound) { + if (sound->dsbuffer) { sound_set_frequency(sound, frequency); sound_set_pan(sound, pan); sound_set_volume(sound, volume); @@ -444,7 +667,7 @@ int sound_play(rct_sound* sound, int looping, int volume, int pan, int frequency * rct2: 0x00404E53 */ int sound_is_playing(rct_sound* sound){ - if (sound) { + if (sound->dsbuffer) { DWORD status; if (SUCCEEDED(sound->dsbuffer->lpVtbl->GetStatus(sound->dsbuffer, &status))) { if (status & DSBSTATUS_PLAYING || status & DSBSTATUS_LOOPING) @@ -461,7 +684,7 @@ int sound_is_playing(rct_sound* sound){ */ int sound_set_frequency(rct_sound* sound, int frequency) { - if (sound) { + if (sound->dsbuffer) { if (SUCCEEDED(sound->dsbuffer->lpVtbl->SetFrequency(sound->dsbuffer, frequency))) return 1; @@ -475,7 +698,7 @@ int sound_set_frequency(rct_sound* sound, int frequency) */ int sound_set_pan(rct_sound* sound, int pan) { - if (sound) { + if (sound->dsbuffer) { if (SUCCEEDED(sound->dsbuffer->lpVtbl->SetPan(sound->dsbuffer, pan))) return 1; @@ -489,7 +712,7 @@ int sound_set_pan(rct_sound* sound, int pan) */ int sound_set_volume(rct_sound* sound, int volume) { - if (sound) { + if (sound->dsbuffer) { if (SUCCEEDED(sound->dsbuffer->lpVtbl->SetVolume(sound->dsbuffer, volume))) return 1; @@ -501,14 +724,14 @@ int sound_set_volume(rct_sound* sound, int volume) * * rct2: 0x00404DD8 */ -rct_sound* sound_stop(rct_sound* sound) +int sound_stop(rct_sound* sound) { if (sound->dsbuffer) { sound->dsbuffer->lpVtbl->Release(sound->dsbuffer); sound->dsbuffer = 0; - return sound_remove(sound); + return sound_remove(sound) ? 1 : 0; } - return sound; + return 0; } /** @@ -678,6 +901,21 @@ void stop_peep_sounds() } } +/** +* +* rct2: 0x006BD0BD +*/ +void stop_title_music() +{ + if (RCT2_GLOBAL(0x009AF284, uint32) & (1 << 0)) { + if (RCT2_GLOBAL(0x009AF600, uint8) != 0) { + RCT2_GLOBAL(0x014241BC, uint32) = 1; + sound_channel_stop(3); + RCT2_GLOBAL(0x014241BC, uint32) = 0; + } + } +} + /** * * rct2: 0x00401A05 diff --git a/src/audio.h b/src/audio.h index 6009cd40cf..1ce9960cb4 100644 --- a/src/audio.h +++ b/src/audio.h @@ -57,6 +57,16 @@ typedef struct rct_sound { struct rct_sound* next; } rct_sound; +typedef struct { + uint16 var_0; + uint16 channels; + uint32 samples; + uint32 var_8; + uint16 bytes; + uint16 bits; + uint16 var_E; +} rct_audio_info; + typedef struct { uint32 var_0; uint8 pad_4[0x118]; @@ -90,7 +100,7 @@ typedef struct { rct_sound sound; } rct_other_sound; -void get_dsound_devices(); +int get_dsound_devices(); int sound_prepare(int sound_id, rct_sound *sound, int channels, int software); int sound_play_panned(int sound_id, int x); int sound_play(rct_sound* sound, int looping, int volume, int pan, int frequency); @@ -102,7 +112,9 @@ 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); -rct_sound* sound_stop(rct_sound *sound); +int sound_stop(rct_sound *sound); +int sound_stop_all(); +int sound_unmap_file(LPCVOID base); int sound_channel_stop(int channel); rct_sound* sound_add(rct_sound* sound); rct_sound* sound_remove(rct_sound* sound); @@ -113,6 +125,7 @@ void stop_other_sounds(); void stop_vehicle_sounds(); void stop_ride_music(); void stop_peep_sounds(); +void stop_title_music(); void unpause_sounds(); // 0x009AF59C probably does the same job diff --git a/src/rct2.c b/src/rct2.c index b413820fd9..29572477a3 100644 --- a/src/rct2.c +++ b/src/rct2.c @@ -84,7 +84,7 @@ __declspec(dllexport) int StartOpenRCT(HINSTANCE hInstance, HINSTANCE hPrevInsta audio_init(); audio_get_devices(); - RCT2_CALLPROC(0x0040502E); // get_dsound_devices() + get_dsound_devices(); config_init(); language_open(gGeneral_config.language); rct2_init(); diff --git a/src/title.c b/src/title.c index 79a6aae429..adfb25e080 100644 --- a/src/title.c +++ b/src/title.c @@ -22,6 +22,7 @@ #include #include #include "addresses.h" +#include "audio.h" #include "config.h" #include "climate.h" #include "date.h" @@ -309,7 +310,7 @@ static void title_play_music() if (!(RCT2_GLOBAL(0x009AF284, uint32) & 1) || !(RCT2_GLOBAL(0x009AF59D, uint8) & 1)) { if (RCT2_GLOBAL(0x009AF600, uint8) != 0) - RCT2_CALLPROC_EBPSAFE(0x006BD0BD); // stop music + stop_title_music(); return; } From fba1a81e07e21555fda03d37f0612ea507702afd Mon Sep 17 00:00:00 2001 From: zsilencer Date: Tue, 26 Aug 2014 20:23:32 -0600 Subject: [PATCH 11/58] audio_remove_timer, audio_create_timer, map_file, audio_timer_callback --- src/addresses.h | 3 +- src/audio.c | 163 +++++++++++++++++++++++++++++++++++++++++------- src/audio.h | 2 +- 3 files changed, 144 insertions(+), 24 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index d6b95d7426..80ef4cbe20 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -33,6 +33,7 @@ #define RCT2_CALLFUNC_3(address, returnType, a1, a2, a3, v1, v2, v3) (((returnType(*)(a1, a2, a3))(address))(v1, v2, v3)) #define RCT2_CALLFUNC_4(address, returnType, a1, a2, a3, a4, v1, v2, v3, v4) (((returnType(*)(a1, a2, a3, a4))(address))(v1, v2, v3, v4)) #define RCT2_CALLFUNC_5(address, returnType, a1, a2, a3, a4, a5, v1, v2, v3, v4, v5) (((returnType(*)(a1, a2, a3, a4, a5))(address))(v1, v2, v3, v4, v5)) +#define RCT2_CALLFUNC_6(address, returnType, a1, a2, a3, a4, a5, a6, v1, v2, v3, v4, v5, v6) (((returnType(*)(a1, a2, a3, a4, a5, a6))(address))(v1, v2, v3, v4, v5, v6)) #define RCT2_CALLPROC_1(address, a1, v1) RCT2_CALLFUNC_1(address, void, a1, v1) #define RCT2_CALLPROC_2(address, a1, a2, v1, v2) RCT2_CALLFUNC_2(address, void, a1, a2, v1, v2) @@ -161,7 +162,7 @@ #define RCT2_ADDRESS_DSOUND_BUFFERS 0x009E1AB0 #define RCT2_ADDRESS_NUM_DSOUND_DEVICES 0x009E2B88 #define RCT2_ADDRESS_DSOUND_DEVICES 0x009E2B8C -#define RCT2_ADDRESS_SOUND_INFO_LIST_OFFSET 0x009E2B94 +#define RCT2_ADDRESS_SOUND_INFO_LIST_MAPPING 0x009E2B94 #define RCT2_ADDRESS_SOUNDLIST_BEGIN 0x009E2B98 #define RCT2_ADDRESS_SOUNDLIST_END 0x009E2B9C #define RCT2_ADDRESS_DIRECTSOUND 0x009E2BA0 diff --git a/src/audio.c b/src/audio.c index ecc2ddb50d..f970f11256 100644 --- a/src/audio.c +++ b/src/audio.c @@ -70,7 +70,7 @@ void audio_get_devices() * * rct2: 0x00404BD2 */ -int sound_release() +int audio_release() { sound_stop_all(); if (RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER)) { @@ -93,12 +93,12 @@ int sound_release() * * rct2: 0x00404C45 */ -int sound_unmap_info() +int unmap_sound_info() { - if (RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_OFFSET, int)) { + if (RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_MAPPING, LPVOID)) { sound_stop_all(); - sound_unmap_file(RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_OFFSET, LPCVOID)); - RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_OFFSET, int) = 0; + unmap_file(RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_MAPPING, LPVOID)); + RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_MAPPING, LPVOID) = 0; return 1; } return 0; @@ -121,7 +121,7 @@ int sound_stop_all() * * rct2: 0x004068A0 */ -int sound_unmap_file(LPCVOID base) +int unmap_file(LPCVOID base) { if (base) { return UnmapViewOfFile(base); @@ -129,11 +129,33 @@ int sound_unmap_file(LPCVOID base) return 0; } +/** +* +* rct2: 0x004018F0 +*/ +int audio_remove_timer() +{ + for (int i = 0; i < 4; i++) { + sound_channel_stop(i); + } + if (RCT2_GLOBAL(0x009E1AA4, int)) { + timeKillEvent(RCT2_GLOBAL(0x009E1AA0, MMRESULT)); + timeEndPeriod(50); + while (_InterlockedExchange(&RCT2_GLOBAL(0x009E1AAC, LONG), 1) != 1) { + Sleep(100); + } + int result = _InterlockedExchange(&RCT2_GLOBAL(0x009E1AAC, LONG), 0); + RCT2_GLOBAL(0x009E1AA4, int) = 0; + return result; + } + return 0; +} + /** * * rct2: 0x006BAB21 */ -void sub_6BAB21() +void audio_close() { if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32) != -1) { stop_other_sounds(); @@ -142,12 +164,12 @@ void sub_6BAB21() if (RCT2_GLOBAL(0x009AF284, uint32) & (1 << 0)) { stop_ride_music(); RCT2_GLOBAL(0x014241BC, uint32) = 1; - RCT2_CALLPROC(0x004018F0); // remove multimedia timer + audio_remove_timer(); RCT2_GLOBAL(0x014241BC, uint32) = 0; } RCT2_GLOBAL(0x014241BC, uint32) = 1; - sound_unmap_info(); - sound_release(); + unmap_sound_info(); + audio_release(); RCT2_GLOBAL(0x014241BC, uint32) = 0; RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32) = -1; } @@ -265,13 +287,112 @@ int dsound_create_primary_buffer(int a, int device, int channels, int samples, i return 1; } +/** +* +* rct2: 0x004067F9 +*/ +LPVOID map_file(LPCSTR lpFileName, DWORD dwCreationDisposition, DWORD dwNumberOfBytesToMap) +{ + DWORD dwDesiredAccess; + DWORD dwDesiredAccessmap; + DWORD flProtect; + HANDLE filehandle; + HANDLE filemaphandle; + LPVOID address = 0; + if (dwCreationDisposition) { + if (dwCreationDisposition == CREATE_NEW) { + dwDesiredAccess = GENERIC_READ | GENERIC_WRITE; + dwDesiredAccessmap = FILE_MAP_WRITE; + flProtect = PAGE_READWRITE; + dwCreationDisposition = OPEN_ALWAYS; + } + } else { + dwDesiredAccess = GENERIC_READ; + flProtect = PAGE_READONLY; + dwDesiredAccessmap = FILE_MAP_READ; + dwCreationDisposition = OPEN_EXISTING; + } + filehandle = CreateFileA(lpFileName, dwDesiredAccess, 0, 0, dwCreationDisposition, FILE_ATTRIBUTE_NORMAL, 0); + if (filehandle != INVALID_HANDLE_VALUE) { + filemaphandle = CreateFileMappingA(filehandle, 0, flProtect, 0, dwNumberOfBytesToMap, 0); + CloseHandle(filehandle); + if (filemaphandle) { + address = MapViewOfFile(filemaphandle, dwDesiredAccessmap, 0, 0, dwNumberOfBytesToMap); + CloseHandle(filemaphandle); + } + } + return address; +} + +/** +* +* rct2: 0x00404C1A +*/ +int map_sound_info(const char* filename) +{ + if (RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_MAPPING, LPVOID)) { + return 0; + } else { + RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_MAPPING, LPVOID) = map_file(filename, 0, 0); + return RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_MAPPING, LPVOID) != 0; + } +} + +/** +* +* rct2: 0x00401000 +*/ +void sub_401000(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2, int channel) +{ + RCT2_CALLFUNC_6(0x00401000, void, UINT, UINT, DWORD_PTR, DWORD_PTR, DWORD_PTR, int, uTimerID, uMsg, dwUser, dw1, dw2, channel); +} + +/** +* +* rct2: 0x004014DF +*/ +int CALLBACK audio_timer_callback(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2) +{ + if (_InterlockedExchange(&RCT2_GLOBAL(0x009E1AAC, LONG), 1) == 0) { + for (int i = 0; i < 4; i++) { + rct_sound_channel* sound_channel = &RCT2_ADDRESS(RCT2_ADDRESS_SOUND_CHANNEL_LIST, rct_sound_channel)[i]; + if(sound_channel->var_0){ + sub_401000(uTimerID, uMsg, dwUser, dw1, dw2, i); + } + } + return _InterlockedExchange(&RCT2_GLOBAL(0x009E1AAC, LONG), 0); + } + return 0; +} + +/** +* +* rct2: 0x004018A6 +*/ +int audio_create_timer() +{ + if (RCT2_GLOBAL(0x009E1AA4, int)) { + return 0; + } + for (int i = 0; i < 4; i++) { + rct_sound_channel* sound_channel = &RCT2_ADDRESS(RCT2_ADDRESS_SOUND_CHANNEL_LIST, rct_sound_channel)[i]; + sound_channel->var_0 = 0; + } + RCT2_GLOBAL(0x009E1AA0, MMRESULT) = timeSetEvent(50, 10, audio_timer_callback, 0, TIME_PERIODIC); + if (!RCT2_GLOBAL(0x009E1AA0, MMRESULT)) { + return 0; + } + RCT2_GLOBAL(0x009E1AA4, int) = 1; + return 1; +} + /** * * rct2: 0x006BA9B5 */ void audio_init2(int device) { - sub_6BAB21(); + audio_close(); for (int i = 0; i < 7; i++) { rct_vehicle_sound* vehicle_sound = &RCT2_ADDRESS(RCT2_ADDRESS_VEHICLE_SOUND_LIST, rct_vehicle_sound)[i]; vehicle_sound->id = 0xFFFF; @@ -281,19 +402,18 @@ void audio_init2(int device) other_sound->id = 0xFFFF; } RCT2_GLOBAL(0x014241BC, uint32) = 1; - int v5 = dsound_create_primary_buffer(0, device, 2, 22050, 16); - //int v5 = RCT2_CALLFUNC_5(0x00404932, int, int, int, int, int, int, 0, device, 2, 22050, 16); + int successdsound = dsound_create_primary_buffer(0, device, 2, 22050, 16); RCT2_GLOBAL(0x014241BC, uint32) = 0; - if (!v5) { + if (!successdsound) { return; } const char * filepath = get_file_path(2); RCT2_GLOBAL(0x014241BC, uint32) = 1; - int v8 = RCT2_CALLFUNC_1(0x00404C1A, int, const char *, filepath); + int successmap = map_sound_info(filepath); RCT2_GLOBAL(0x014241BC, uint32) = 0; - if (!v8) { + if (!successmap) { RCT2_GLOBAL(0x014241BC, uint32) = 1; - sound_release(); + audio_release(); RCT2_GLOBAL(0x014241BC, uint32) = 0; return; } @@ -306,9 +426,9 @@ void audio_init2(int device) RCT2_GLOBAL(0x009AAC5C, uint8) = 1; config_save(); RCT2_GLOBAL(0x014241BC, uint32) = 1; - int result = RCT2_CALLFUNC(0x004018A6, int); // create multimedia timer + int successtimer = audio_create_timer(); RCT2_GLOBAL(0x014241BC, uint32) = 0; - if (result) { + if (successtimer) { if ((RCT2_GLOBAL(0x009AF284, uint32) & (1 << 0))) { for (int i = 0; i < 2; i++) { RCT2_GLOBAL(0x009AF46C + (i * 8), uint8) = -1; @@ -423,8 +543,8 @@ rct_sound* sound_next(rct_sound* sound) */ rct_sound_info* sound_get_info(uint16 sound_id) { - if (RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_OFFSET, int) && sound_id < RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_OFFSET, int*)[0]) { - return (rct_sound_info*)(RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_OFFSET, int) + RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_OFFSET, int*)[sound_id + 1]); + if (RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_MAPPING, LPVOID) && sound_id < RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_MAPPING, uint32*)[0]) { + return (rct_sound_info*)(RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_MAPPING, int) + RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_MAPPING, uint32*)[sound_id + 1]); } return 0; } @@ -468,7 +588,6 @@ int sound_fill_buffer(LPDIRECTSOUNDBUFFER dsbuffer, char* src, int size) */ int sound_prepare(int sound_id, rct_sound *sound, int channels, int software) { - //return RCT2_CALLFUNC_4(0x00404C6D, int, int, rct_sound*, int, int, sound_id, sound, channels, software); DSBUFFERDESC bufferdesc; char* buffer = 0; memset(&bufferdesc, 0, sizeof(bufferdesc)); diff --git a/src/audio.h b/src/audio.h index 1ce9960cb4..85aba58db8 100644 --- a/src/audio.h +++ b/src/audio.h @@ -114,7 +114,7 @@ int sound_channel_set_pan(int channel, int pan); int sound_channel_set_volume(int channel, int volume); int sound_stop(rct_sound *sound); int sound_stop_all(); -int sound_unmap_file(LPCVOID base); +int unmap_file(LPCVOID base); int sound_channel_stop(int channel); rct_sound* sound_add(rct_sound* sound); rct_sound* sound_remove(rct_sound* sound); From 6250331bd07eca503567609f36ff778ca2bfced7 Mon Sep 17 00:00:00 2001 From: zsilencer Date: Tue, 26 Aug 2014 21:48:47 -0600 Subject: [PATCH 12/58] compile test --- CMakeLists.txt | 2 +- src/audio.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c911bb9fe..74762470ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,6 @@ set_target_properties(${PROJECT} PROPERTIES PREFIX "") TARGET_LINK_LIBRARIES(${PROJECT} ${SDL2_LIBRARIES}) if (WIN32) - target_link_libraries(${PROJECT} winmm.lib -limm32 -lversion) + target_link_libraries(${PROJECT} winmm.lib -limm32 -lversion -ldsound) endif (WIN32) diff --git a/src/audio.c b/src/audio.c index f970f11256..6fe7726f63 100644 --- a/src/audio.c +++ b/src/audio.c @@ -228,7 +228,7 @@ int dsound_create_primary_buffer(int a, int device, int channels, int samples, i RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND) = 0; return 0; } - if (SUCCEEDED(RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER)->lpVtbl->QueryInterface(RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER), &RCT2_GLOBAL(0x009A4444, IID) /* IID_IDirectSound3DBuffer */, &RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER)))) { + if (SUCCEEDED(RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER)->lpVtbl->QueryInterface(RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER), &RCT2_GLOBAL(0x009A4444, IID) /* IID_IDirectSound3DBuffer */, (void**)&RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER)))) { // doesn't seem to ever make it here, below doesn't make sense and is probably remnants of unused 3d sound tests memset(&RCT2_GLOBAL(0x009A6084, DS3DBUFFER), 0, sizeof(RCT2_GLOBAL(0x009A6084, DS3DBUFFER))); RCT2_GLOBAL(0x009A6084, DS3DBUFFER).dwSize = sizeof(RCT2_GLOBAL(0x009A6084, DS3DBUFFER)); @@ -378,7 +378,7 @@ int audio_create_timer() rct_sound_channel* sound_channel = &RCT2_ADDRESS(RCT2_ADDRESS_SOUND_CHANNEL_LIST, rct_sound_channel)[i]; sound_channel->var_0 = 0; } - RCT2_GLOBAL(0x009E1AA0, MMRESULT) = timeSetEvent(50, 10, audio_timer_callback, 0, TIME_PERIODIC); + RCT2_GLOBAL(0x009E1AA0, MMRESULT) = timeSetEvent(50, 10, (LPTIMECALLBACK)audio_timer_callback, 0, TIME_PERIODIC); if (!RCT2_GLOBAL(0x009E1AA0, MMRESULT)) { return 0; } @@ -565,11 +565,11 @@ int sound_info_loadvars(rct_sound_info* sound_info, LPWAVEFORMATEX* waveformat, * * rct2: 0x00405076 */ -int sound_fill_buffer(LPDIRECTSOUNDBUFFER dsbuffer, char* src, int size) +int sound_fill_buffer(LPDIRECTSOUNDBUFFER dsbuffer, char* src, DWORD size) { - char* buf; - char* buf2; - int buf2size; + LPVOID buf; + LPVOID buf2; + DWORD buf2size; if (SUCCEEDED(dsbuffer->lpVtbl->Lock(dsbuffer, 0, size, &buf, &size, &buf2, &buf2size, 0))) { memset(buf, 0, size); memcpy(buf, src, size); From 2a41c031ac400915523739e5e0906d1d746e2e8e Mon Sep 17 00:00:00 2001 From: Duncan Date: Mon, 25 Aug 2014 12:58:59 +0100 Subject: [PATCH 13/58] Added window_peep_event arrays. --- src/window_peep.c | 167 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 161 insertions(+), 6 deletions(-) diff --git a/src/window_peep.c b/src/window_peep.c index 8c7ef1601a..5906b1fb70 100644 --- a/src/window_peep.c +++ b/src/window_peep.c @@ -134,14 +134,169 @@ static void* window_peep_overview_events[] = { (void*)0x69707C }; +static void* window_peep_stats_events[] = { + window_peep_emptysub, + (void*) 0x0069744F, //mouse_up + (void*) 0x00697488, //resize + window_peep_emptysub, + window_peep_emptysub, + (void*) 0x006974ED, + (void*) 0x0069746A, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + (void*) 0x0069707D, //invalidate + (void*) 0x0069711D, //paint + window_peep_emptysub +}; + +static void* window_peep_rides_events[] = { + window_peep_emptysub, + (void*) 0x00697795, //mouse_up + (void*) 0x006978F4, //resize + window_peep_emptysub, + window_peep_emptysub, + (void*) 0x00697959, + (void*) 0x006977B0, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + (void*) 0x0069784E, + (void*) 0x006978CC, + window_peep_emptysub, + (void*) 0x0069789C, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + (void*) 0x00697844, + window_peep_emptysub, + window_peep_emptysub, + (void*) 0x0069757A, //invalidate + (void*) 0x00697637, //paint + (void*) 0x006976FC +}; + +static void* window_peep_finance_events[] = { + window_peep_emptysub, + (void*) 0x00697BDD, //mouse_up + (void*) 0x00697C16, //resize + window_peep_emptysub, + window_peep_emptysub, + (void*) 0x00697C7B, + (void*) 0x00697BF8, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + (void*) 0x00697968, //invalidate + (void*) 0x00697A08, //paint + window_peep_emptysub +}; + +static void* window_peep_thoughts_events[] = { + window_peep_emptysub, + (void*) 0x00697E18, //mouse_up + (void*) 0x00697E33, //resize + window_peep_emptysub, + window_peep_emptysub, + (void*) 0x00697ED2, + (void*) 0x00697EB4, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + (void*) 0x00697C8A, //invalidate + (void*) 0x00697D2A, //paint + window_peep_emptysub +}; + +static void* window_peep_inventory_events[] = { + window_peep_emptysub, + (void*) 0x00698279, //mouse_up + (void*) 0x00698294, //resize + window_peep_emptysub, + window_peep_emptysub, + (void*) 0x00698333, + (void*) 0x00698315, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + window_peep_emptysub, + (void*) 0x00697EE1, //invalidate + (void*) 0x00697F81, //paint + window_peep_emptysub +}; + //0x981D24 void* window_peep_page_events[] = { window_peep_overview_events, - (void*)0x982468, - (void*)0x9824d8, - (void*)0x982548, - (void*)0x9825b8, - (void*)0x982628 + window_peep_stats_events, + window_peep_rides_events, + window_peep_finance_events, + window_peep_thoughts_events, + window_peep_inventory_events }; //0x981D3C @@ -537,4 +692,4 @@ void window_peep_overview_paint(){ if (w->viewport){ window_draw_viewport(dpi, w); } -} \ No newline at end of file +} From edd1651b4d87cd019f484600a9f8f914a669003e Mon Sep 17 00:00:00 2001 From: Duncan Date: Mon, 25 Aug 2014 16:47:01 +0100 Subject: [PATCH 14/58] Added peep_stats_widgets --- src/window_peep.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/window_peep.c b/src/window_peep.c index 5906b1fb70..b393240a81 100644 --- a/src/window_peep.c +++ b/src/window_peep.c @@ -84,10 +84,24 @@ rct_widget window_peep_overview_widgets[] = { { WIDGETS_END }, }; +rct_widget window_peep_stats_widgets[] = { + {WWT_FRAME, 0, 0,191,0,156,-1,-1}, + {WWT_CAPTION, 0, 1,190,1,14,865,829}, + {WWT_CLOSEBOX, 0, 179,189,2,13,824,828}, + {WWT_RESIZE, 1, 0,191,43,156,-1,-1}, + {WWT_TAB, 1, 3,33,17,43,0x2000144E,1938}, + {WWT_TAB, 1, 34,64,17,43,0x2000144E,1940}, + {WWT_TAB, 1, 65,95,17,43,0x2000144E,1941}, + {WWT_TAB, 1, 96,126,17,43,0x2000144E,1942}, + {WWT_TAB, 1, 127,157,17,43,0x2000144E,1943}, + {WWT_TAB, 1, 158,188,17,43,0x2000144E,1944}, + {WIDGETS_END}, +} + //0x981D0C rct_widget *window_peep_page_widgets[] = { window_peep_overview_widgets, - (rct_widget *)0x9AC45C, + window_peep_stats_widgets, (rct_widget *)0x9ac500, (rct_widget *)0x9ac5b4, (rct_widget *)0x9ac658, From dffd689ee6a3479aa48f5aec3e971eb38b939c4a Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Mon, 25 Aug 2014 19:31:53 +0100 Subject: [PATCH 15/58] Added more to window_peep overview paint Moved get_arguments_from_thought to peep.c and added to peep.h Fixed possible crash in viewport_update_position Fixed compile error --- src/peep.c | 38 ++++++++++++++++++++ src/peep.h | 1 + src/viewport.c | 2 +- src/window.h | 2 +- src/window_guest_list.c | 40 +-------------------- src/window_peep.c | 77 ++++++++++++++++++++++++++++++++++------- 6 files changed, 106 insertions(+), 54 deletions(-) diff --git a/src/peep.c b/src/peep.c index caf4016fde..ea85a117e4 100644 --- a/src/peep.c +++ b/src/peep.c @@ -542,6 +542,44 @@ void get_arguments_from_action(rct_peep* peep, uint32 *argument_1, uint32* argum } +/** +* rct2: 0x00698342 +* thought.item (eax) +* thought.type (ebx) +* argument_1 (esi & ebx) +* argument_2 (esi+2) +*/ +void get_arguments_from_thought(rct_peep_thought thought, uint32* argument_1, uint32* argument_2){ + int esi = 0x9AC86C; + + if ((RCT2_ADDRESS(0x981DB1, uint16)[thought.type] & 0xFF) & 1){ + rct_ride* ride = &g_ride_list[thought.item]; + esi = (int)(&(ride->var_04A)); + } + else if ((RCT2_ADDRESS(0x981DB1, uint16)[thought.type] & 0xFF) & 2){ + if (thought.item < 0x20){ + RCT2_GLOBAL(0x9AC86C, uint16) = thought.item + STR_ITEM_START; + } + else{ + RCT2_GLOBAL(0x9AC86C, uint16) = thought.item + STR_ITEM2_START; + } + } + else if ((RCT2_ADDRESS(0x981DB1, uint16)[thought.type] & 0xFF) & 4){ + if (thought.item < 0x20){ + RCT2_GLOBAL(0x9AC86C, uint16) = thought.item + STR_ITEM_SINGULAR_START; + } + else + { + RCT2_GLOBAL(0x9AC86C, uint16) = thought.item + STR_ITEM2_SINGULAR_START; + } + } + else{ + esi = 0x9AC864; //No thought? + } + *argument_1 = ((thought.type + STR_THOUGHT_START) & 0xFFFF) | (*((uint16*)esi) << 16); + *argument_2 = *((uint32*)(esi + 2)); //Always 0 apart from on rides? +} + /** * rct2: 0x00698827 * returns 1 on pickup (CF not set) diff --git a/src/peep.h b/src/peep.h index 0ee2dc1d6d..3f18e5d587 100644 --- a/src/peep.h +++ b/src/peep.h @@ -444,5 +444,6 @@ void peep_update_crowd_noise(); void peep_applause(); rct_peep *peep_generate(int x, int y, int z); void get_arguments_from_action(rct_peep* peep, uint32 *argument_1, uint32* argument_2); +void get_arguments_from_thought(rct_peep_thought thought, uint32* argument_1, uint32* argument_2); #endif diff --git a/src/viewport.c b/src/viewport.c index b5de1c435e..4697b57df3 100644 --- a/src/viewport.c +++ b/src/viewport.c @@ -280,7 +280,7 @@ void viewport_update_position(rct_window *window) if (window->viewport_target_sprite != -1){ rct_sprite* sprite = &g_sprite_list[window->viewport_target_sprite]; - int height = map_element_height(sprite->unknown.x, sprite->unknown.y) - 16; + int height = map_element_height(0xFFFF & sprite->unknown.x, 0xFFFF & sprite->unknown.y) - 16; int underground = sprite->unknown.z < height; RCT2_CALLPROC_X(0x6E7A15, sprite->unknown.x, sprite->unknown.y, sprite->unknown.z, underground, (int)window, (int)viewport, 0); diff --git a/src/window.h b/src/window.h index f2adce2696..d4a9cbb0af 100644 --- a/src/window.h +++ b/src/window.h @@ -203,7 +203,7 @@ typedef struct rct_window { sint16 page; // 0x48A sint16 var_48C; sint16 frame_no; // 0x48E updated every tic for motion in windows sprites - uint16 list_information_type; // 0x490 0 for none + uint16 list_information_type; // 0x490 0 for none, Used as current position of marquee in window_peep sint16 var_492; uint32 var_494; uint8 var_498[0x14]; diff --git a/src/window_guest_list.c b/src/window_guest_list.c index a5953114be..217e7ebb26 100644 --- a/src/window_guest_list.c +++ b/src/window_guest_list.c @@ -135,7 +135,7 @@ static void window_guest_list_find_groups(); static int get_guest_face_sprite_small(rct_peep *peep); static int get_guest_face_sprite_large(rct_peep *peep); static void get_arguments_from_peep(rct_peep *peep, uint32 *argument_1, uint32* argument_2); -void get_arguments_from_thought(rct_peep_thought thought, uint32* argument_1, uint32* argument_2); + /** * * rct2: 0x006992E3 @@ -730,44 +730,6 @@ static int window_guest_list_is_peep_in_filter(rct_peep* peep) return 1; } -/** - * rct2: 0x00698342 - * thought.item (eax) - * thought.type (ebx) - * argument_1 (esi & ebx) - * argument_2 (esi+2) - */ -void get_arguments_from_thought(rct_peep_thought thought, uint32* argument_1, uint32* argument_2){ - int esi = 0x9AC86C; - - if ((RCT2_ADDRESS(0x981DB1, uint16)[thought.type] & 0xFF) & 1){ - rct_ride* ride = &g_ride_list[thought.item]; - esi = (int)(&(ride->var_04A)); - } - else if ((RCT2_ADDRESS(0x981DB1, uint16)[thought.type] & 0xFF) & 2){ - if (thought.item < 0x20){ - RCT2_GLOBAL(0x9AC86C, uint16) = thought.item + STR_ITEM_START; - } - else{ - RCT2_GLOBAL(0x9AC86C, uint16) = thought.item + STR_ITEM2_START; - } - } - else if ((RCT2_ADDRESS(0x981DB1, uint16)[thought.type] & 0xFF) & 4){ - if (thought.item < 0x20){ - RCT2_GLOBAL(0x9AC86C, uint16) = thought.item + STR_ITEM_SINGULAR_START; - } - else - { - RCT2_GLOBAL(0x9AC86C, uint16) = thought.item + STR_ITEM2_SINGULAR_START; - } - } - else{ - esi = 0x9AC864; //No thought? - } - *argument_1 = ((thought.type + STR_THOUGHT_START) & 0xFFFF) | (*((uint16*)esi) << 16); - *argument_2 = *((uint32*)(esi+2)); //Always 0 apart from on rides? -} - /** * rct2:0x0069B7EA * Calculates a hash value (arguments) for comparing peep actions/thoughts diff --git a/src/window_peep.c b/src/window_peep.c index b393240a81..e6be343114 100644 --- a/src/window_peep.c +++ b/src/window_peep.c @@ -85,18 +85,18 @@ rct_widget window_peep_overview_widgets[] = { }; rct_widget window_peep_stats_widgets[] = { - {WWT_FRAME, 0, 0,191,0,156,-1,-1}, - {WWT_CAPTION, 0, 1,190,1,14,865,829}, - {WWT_CLOSEBOX, 0, 179,189,2,13,824,828}, - {WWT_RESIZE, 1, 0,191,43,156,-1,-1}, - {WWT_TAB, 1, 3,33,17,43,0x2000144E,1938}, - {WWT_TAB, 1, 34,64,17,43,0x2000144E,1940}, - {WWT_TAB, 1, 65,95,17,43,0x2000144E,1941}, - {WWT_TAB, 1, 96,126,17,43,0x2000144E,1942}, - {WWT_TAB, 1, 127,157,17,43,0x2000144E,1943}, - {WWT_TAB, 1, 158,188,17,43,0x2000144E,1944}, + {WWT_FRAME, 0, 0, 191, 0, 156, -1, STR_NONE}, + {WWT_CAPTION, 0, 1, 190, 1, 14, 865, STR_WINDOW_TITLE_TIP}, + {WWT_CLOSEBOX, 0, 179, 189, 2, 13, 824, STR_CLOSE_WINDOW_TIP}, + {WWT_RESIZE, 1, 0, 191, 43, 156, -1, STR_NONE}, + {WWT_TAB, 1, 3, 33, 17, 43, 0x2000144E, 1938}, + {WWT_TAB, 1, 34, 64, 17, 43, 0x2000144E, 1940}, + {WWT_TAB, 1, 65, 95, 17, 43, 0x2000144E, 1941}, + {WWT_TAB, 1, 96, 126, 17, 43, 0x2000144E, 1942}, + {WWT_TAB, 1, 127, 157, 17, 43, 0x2000144E, 1943}, + {WWT_TAB, 1, 158, 188, 17, 43, 0x2000144E, 1944}, {WIDGETS_END}, -} +}; //0x981D0C rct_widget *window_peep_page_widgets[] = { @@ -693,8 +693,8 @@ void window_peep_overview_paint(){ //rct_widget *labelWidget; window_paint_get_registers(w, dpi); - RCT2_CALLPROC_X(0x696887, 0, 0, 0, 0, (int)w, (int)dpi, 0); - return; + //RCT2_CALLPROC_X(0x696887, 0, 0, 0, 0, (int)w, (int)dpi, 0); + //return; window_draw_widgets(w, dpi); //6983dd @@ -703,7 +703,58 @@ void window_peep_overview_paint(){ //69861f //69869b //698661 + + // Draw the viewport no sound sprite if (w->viewport){ window_draw_viewport(dpi, w); + rct_viewport* viewport = w->viewport; + if (viewport->flags & VIEWPORT_FLAG_SOUND_ON){ + gfx_draw_sprite(dpi, SPR_HEARING_VIEWPORT, w->x + 2, w->y + 2, 0); + } } + + // Draw the centered label + uint32 argument1, argument2; + rct_peep* peep = GET_PEEP(w->number); + get_arguments_from_action(peep, &argument1, &argument2); + RCT2_GLOBAL(0x13CE952, uint32) = argument1; + RCT2_GLOBAL(0x13CE952 + 4, uint32) = argument2; + rct_widget* widget = &w->widgets[WIDX_ACTION_LBL]; + int x = (widget->left + widget->right) / 2 + w->x; + int y = w->y + widget->top - 1; + int width = widget->right - widget->left; + gfx_draw_string_centred_clipped(dpi, 1191, (void*)0x13CE952, 0, x, y, width); + + // Draw the marquee thought + widget = &w->widgets[WIDX_MARQUEE]; + width = widget->right - widget->left - 3; + int left = widget->left + 2 + w->x; + int top = widget->top + w->y; + int height = widget->bottom - widget->top; + rct_drawpixelinfo* dpi_marquee = clip_drawpixelinfo(dpi, left, width, top, height); + + if (!dpi_marquee)return; + int i = 0; + for (; i < PEEP_MAX_THOUGHTS; ++i){ + if (peep->thoughts[i].type == PEEP_THOUGHT_TYPE_NONE){ + w->list_information_type = 0; + return; + } + if (peep->thoughts[i].var_2 == 1){ // If a fresh thought + break; + } + } + if (i == PEEP_MAX_THOUGHTS){ + w->list_information_type = 0; + return; + } + + get_arguments_from_thought(peep->thoughts[i], &argument1, &argument2); + + RCT2_GLOBAL(0x13CE952, uint32) = argument1; + RCT2_GLOBAL(0x13CE952 + 4, uint32) = argument2; + RCT2_GLOBAL(0x13CE952 + 8, uint16) = 0; + + x = widget->right - widget->left - w->list_information_type; + gfx_draw_string_left(dpi_marquee, 1193, (void*)0x13CE952, 0, x, 0); } From 217b5c12815195c7e747bca3b44b950a67b6d2b8 Mon Sep 17 00:00:00 2001 From: Duncan Date: Tue, 26 Aug 2014 12:30:06 +0100 Subject: [PATCH 16/58] Added remaining window_peep widgets. --- src/window_peep.c | 73 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 66 insertions(+), 7 deletions(-) diff --git a/src/window_peep.c b/src/window_peep.c index e6be343114..b8c59ed308 100644 --- a/src/window_peep.c +++ b/src/window_peep.c @@ -58,7 +58,9 @@ enum WINDOW_PEEP_WIDGET_IDX { WIDX_PICKUP, WIDX_RENAME, WIDX_LOCATE, - WIDX_TRACK + WIDX_TRACK, + + WIDX_RIDE_SCROLL = 10 }; void window_peep_emptysub(){}; @@ -98,14 +100,71 @@ rct_widget window_peep_stats_widgets[] = { {WIDGETS_END}, }; +rct_widget window_peep_rides_widgets[] = { + {WWT_FRAME, 0, 0, 191, 0, 156, -1, STR_NONE}, + {WWT_CAPTION, 0, 1, 190, 1, 14, 865, STR_WINDOW_TITLE_TIP}, + {WWT_CLOSEBOX, 0, 179, 189, 2, 13, 824, STR_CLOSE_WINDOW_TIP}, + {WWT_RESIZE, 1, 0, 191, 43, 156, -1, STR_NONE}, + {WWT_TAB, 1, 3, 33, 17, 43, 0x2000144E, 1938}, + {WWT_TAB, 1, 34, 64, 17, 43, 0x2000144E, 1940}, + {WWT_TAB, 1, 65, 95, 17, 43, 0x2000144E, 1941}, + {WWT_TAB, 1, 96, 126, 17, 43, 0x2000144E, 1942}, + {WWT_TAB, 1, 127, 157, 17, 43, 0x2000144E, 1943}, + {WWT_TAB, 1, 158, 188, 17, 43, 0x2000144E, 1944}, + {WWT_SCROLL, 1, 3, 188, 57, 143, 2, STR_NONE}, + {WIDGETS_END}, +}; + +rct_widget window_peep_finance_widgets[] = { + {WWT_FRAME, 0, 0, 191, 0, 156, -1, STR_NONE}, + {WWT_CAPTION, 0, 1, 190, 1, 14, 865, STR_WINDOW_TITLE_TIP}, + {WWT_CLOSEBOX, 0, 179, 189, 2, 13, 824, STR_CLOSE_WINDOW_TIP}, + {WWT_RESIZE, 1, 0, 191, 43, 156, -1, STR_NONE}, + {WWT_TAB, 1, 3, 33, 17, 43, 0x2000144E, 1938}, + {WWT_TAB, 1, 34, 64, 17, 43, 0x2000144E, 1940}, + {WWT_TAB, 1, 65, 95, 17, 43, 0x2000144E, 1941}, + {WWT_TAB, 1, 96, 126, 17, 43, 0x2000144E, 1942}, + {WWT_TAB, 1, 127, 157, 17, 43, 0x2000144E, 1943}, + {WWT_TAB, 1, 158, 188, 17, 43, 0x2000144E, 1944}, + {WIDGETS_END}, +}; + +rct_widget window_peep_thoughts_widgets[] = { + {WWT_FRAME, 0, 0, 191, 0, 156, -1, STR_NONE}, + {WWT_CAPTION, 0, 1, 190, 1, 14, 865, STR_WINDOW_TITLE_TIP}, + {WWT_CLOSEBOX, 0, 179, 189, 2, 13, 824, STR_CLOSE_WINDOW_TIP}, + {WWT_RESIZE, 1, 0, 191, 43, 156, -1, STR_NONE}, + {WWT_TAB, 1, 3, 33, 17, 43, 0x2000144E, 1938}, + {WWT_TAB, 1, 34, 64, 17, 43, 0x2000144E, 1940}, + {WWT_TAB, 1, 65, 95, 17, 43, 0x2000144E, 1941}, + {WWT_TAB, 1, 96, 126, 17, 43, 0x2000144E, 1942}, + {WWT_TAB, 1, 127, 157, 17, 43, 0x2000144E, 1943}, + {WWT_TAB, 1, 158, 188, 17, 43, 0x2000144E, 1944}, + {WIDGETS_END}, +}; + +rct_widget window_peep_inventory_widgets[] = { + {WWT_FRAME, 0, 0, 191, 0, 156, -1, STR_NONE}, + {WWT_CAPTION, 0, 1, 190, 1, 14, 865, STR_WINDOW_TITLE_TIP}, + {WWT_CLOSEBOX, 0, 179, 189, 2, 13, 824, STR_CLOSE_WINDOW_TIP}, + {WWT_RESIZE, 1, 0, 191, 43, 156, -1, STR_NONE}, + {WWT_TAB, 1, 3, 33, 17, 43, 0x2000144E, 1938}, + {WWT_TAB, 1, 34, 64, 17, 43, 0x2000144E, 1940}, + {WWT_TAB, 1, 65, 95, 17, 43, 0x2000144E, 1941}, + {WWT_TAB, 1, 96, 126, 17, 43, 0x2000144E, 1942}, + {WWT_TAB, 1, 127, 157, 17, 43, 0x2000144E, 1943}, + {WWT_TAB, 1, 158, 188, 17, 43, 0x2000144E, 1944}, + {WIDGETS_END}, +}; + //0x981D0C rct_widget *window_peep_page_widgets[] = { window_peep_overview_widgets, window_peep_stats_widgets, - (rct_widget *)0x9ac500, - (rct_widget *)0x9ac5b4, - (rct_widget *)0x9ac658, - (rct_widget *)0x9ac6FC + window_peep_rides_widgets, + window_peep_finance_widgets, + window_peep_thoughts_widgets, + window_peep_inventory_widgets }; void window_peep_set_page(rct_window* w, int page); @@ -341,8 +400,8 @@ uint32 window_peep_page_enabled_widgets[] = { (1 << WIDX_TAB_3) | (1 << WIDX_TAB_4) | (1 << WIDX_TAB_5) | - (1 << WIDX_TAB_6), //| - //(1 << WIDX_?), + (1 << WIDX_TAB_6) | + (1 << WIDX_RIDE_SCROLL), (1 << WIDX_CLOSE) | (1 << WIDX_TAB_1) | From 28056baf8d1d9fff66d089f58aae94fa11dfeb02 Mon Sep 17 00:00:00 2001 From: Duncan Date: Tue, 26 Aug 2014 13:10:36 +0100 Subject: [PATCH 17/58] Added window_peep_invalidate Not tested. --- src/window_peep.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/window_peep.c b/src/window_peep.c index b8c59ed308..4c1430c0ee 100644 --- a/src/window_peep.c +++ b/src/window_peep.c @@ -817,3 +817,62 @@ void window_peep_overview_paint(){ x = widget->right - widget->left - w->list_information_type; gfx_draw_string_left(dpi_marquee, 1193, (void*)0x13CE952, 0, x, 0); } + +/* rct2: 0x696749*/ +void window_peep_overview_invalidate(){ + rct_window* w; + window_invalidate_get_registers(w); + + if (window_peep_page_widgets[w->page] != w->widgets){ + w->widgets = window_peep_page_widgets[w->page]; + //call 6eaeb8 + } + + w->pressed_widgets &= ~(WIDX_TAB_1 | WIDX_TAB_2 |WIDX_TAB_3 |WIDX_TAB_4 |WIDX_TAB_5 |WIDX_TAB_6); + w->pressed_widgets |= 1 << (w->page + WIDX_TAB_1); + + rct_peep* peep = GET_PEEP(w->number); + RCT2_GLOBAL(0x13CE952,uint16) = peep->name_string_idx; + RCT2_GLOBAL(0x13CE954,uint32) = peep->id; + + w->pressed_widgets &= ~(1<flags & 0x8){ + w->pressed_widgets |= (1<width - 1; + cx = w->height - 1; + window_peep_overview_widgets[WIDX_BACKGROUND].right = ax; + window_peep_overview_widgets[WIDX_BACKGROUND].bottom = cx; + window_peep_overview_widgets[WIDX_PAGE_BACKGROUND].right =ax; + window_peep_overview_widgets[WIDX_PAGE_BACKGROUND].bottom = cx; + ax = w->width - 2; + window_peep_overview_widgets[WIDX_TITLE].right = ax; + ax = w->width - 13; + window_peep_overview_widgets[WIDX_CLOSE].left = ax; + ax = w->width - 3; + window_peep_overview_widgets[WIDX_CLOSE].rigth = ax; + ax = w->width - 26; + cx = w->height - 14; + window_peep_overview_widgets[WIDX_VIEWPORT].right = ax; + window_peep_overview_widgets[WIDX_VIEWPORT].bottom = cx; + cx = w->height - 12; + window_peep_overview_widgets[WIDX_ACTION_LBL].top = cx; + cx = w->height - 3; + window_peep_overview_widgets[WIDX_ACTION_LBL].bottom = cx; + ax = w->width - 24; + window_peep_overview_widgets[WIDX_ACTION_LBL].right = ax; + window_peep_overview_widgets[WIDX_MARQUEE].right = ax; + ax = w->width - 2; + window_peep_overview_widgets[WIDX_PICKUP].right = ax; + window_peep_overview_widgets[WIDX_RENAME].right = ax; + window_peep_overview_widgets[WIDX_LOCATE].right = ax; + window_peep_overview_widgets[WIDX_TRACK].right = ax; + ax = w->width - 25; + window_peep_overview_widgets[WIDX_PICKUP].left = ax; + window_peep_overview_widgets[WIDX_RENAME].left = ax; + window_peep_overview_widgets[WIDX_LOCATE].left = ax; + window_peep_overview_widgets[WIDX_TRACK].left = ax; + + //call 6987ed +} From 92279becc9f7cf3120d2510595e4c75c4581f3a6 Mon Sep 17 00:00:00 2001 From: Duncan Date: Tue, 26 Aug 2014 16:09:38 +0100 Subject: [PATCH 18/58] Added missing call procs in peep invalidate. --- src/window_peep.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/window_peep.c b/src/window_peep.c index 4c1430c0ee..d1032e2668 100644 --- a/src/window_peep.c +++ b/src/window_peep.c @@ -825,7 +825,7 @@ void window_peep_overview_invalidate(){ if (window_peep_page_widgets[w->page] != w->widgets){ w->widgets = window_peep_page_widgets[w->page]; - //call 6eaeb8 + window_init_scroll_widgets(w); } w->pressed_widgets &= ~(WIDX_TAB_1 | WIDX_TAB_2 |WIDX_TAB_3 |WIDX_TAB_4 |WIDX_TAB_5 |WIDX_TAB_6); @@ -874,5 +874,5 @@ void window_peep_overview_invalidate(){ window_peep_overview_widgets[WIDX_LOCATE].left = ax; window_peep_overview_widgets[WIDX_TRACK].left = ax; - //call 6987ed + RCT2_CALLPROC_X(0x6987ED, 0, 0, 0, 0, (int)w, 0, 0); } From d3455b8f2239befcfdeda28444f26d4ef2a13bdf Mon Sep 17 00:00:00 2001 From: Duncan Date: Wed, 27 Aug 2014 12:14:52 +0100 Subject: [PATCH 19/58] cleaned up peep invalidate --- src/window_peep.c | 62 ++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/src/window_peep.c b/src/window_peep.c index d1032e2668..580edec207 100644 --- a/src/window_peep.c +++ b/src/window_peep.c @@ -840,39 +840,35 @@ void window_peep_overview_invalidate(){ w->pressed_widgets |= (1<width - 1; - cx = w->height - 1; - window_peep_overview_widgets[WIDX_BACKGROUND].right = ax; - window_peep_overview_widgets[WIDX_BACKGROUND].bottom = cx; - window_peep_overview_widgets[WIDX_PAGE_BACKGROUND].right =ax; - window_peep_overview_widgets[WIDX_PAGE_BACKGROUND].bottom = cx; - ax = w->width - 2; - window_peep_overview_widgets[WIDX_TITLE].right = ax; - ax = w->width - 13; - window_peep_overview_widgets[WIDX_CLOSE].left = ax; - ax = w->width - 3; - window_peep_overview_widgets[WIDX_CLOSE].rigth = ax; - ax = w->width - 26; - cx = w->height - 14; - window_peep_overview_widgets[WIDX_VIEWPORT].right = ax; - window_peep_overview_widgets[WIDX_VIEWPORT].bottom = cx; - cx = w->height - 12; - window_peep_overview_widgets[WIDX_ACTION_LBL].top = cx; - cx = w->height - 3; - window_peep_overview_widgets[WIDX_ACTION_LBL].bottom = cx; - ax = w->width - 24; - window_peep_overview_widgets[WIDX_ACTION_LBL].right = ax; - window_peep_overview_widgets[WIDX_MARQUEE].right = ax; - ax = w->width - 2; - window_peep_overview_widgets[WIDX_PICKUP].right = ax; - window_peep_overview_widgets[WIDX_RENAME].right = ax; - window_peep_overview_widgets[WIDX_LOCATE].right = ax; - window_peep_overview_widgets[WIDX_TRACK].right = ax; - ax = w->width - 25; - window_peep_overview_widgets[WIDX_PICKUP].left = ax; - window_peep_overview_widgets[WIDX_RENAME].left = ax; - window_peep_overview_widgets[WIDX_LOCATE].left = ax; - window_peep_overview_widgets[WIDX_TRACK].left = ax; + window_peep_overview_widgets[WIDX_BACKGROUND].right = w->width - 1; + window_peep_overview_widgets[WIDX_BACKGROUND].bottom = w->height - 1; + + window_peep_overview_widgets[WIDX_PAGE_BACKGROUND].right =w->width - 1; + window_peep_overview_widgets[WIDX_PAGE_BACKGROUND].bottom = w->height - 1; + + window_peep_overview_widgets[WIDX_TITLE].right = w->width - 2; + + window_peep_overview_widgets[WIDX_CLOSE].left = w->width - 13; + window_peep_overview_widgets[WIDX_CLOSE].rigth = w->width - 3; + + window_peep_overview_widgets[WIDX_VIEWPORT].right = w->width - 26; + window_peep_overview_widgets[WIDX_VIEWPORT].bottom = w->height - 14; + + window_peep_overview_widgets[WIDX_ACTION_LBL].top = w->height - 12; + window_peep_overview_widgets[WIDX_ACTION_LBL].bottom = w->height - 3; + window_peep_overview_widgets[WIDX_ACTION_LBL].right = w->width - 24; + + window_peep_overview_widgets[WIDX_MARQUEE].right = w->width - 24; + + window_peep_overview_widgets[WIDX_PICKUP].right = w->width - 2; + window_peep_overview_widgets[WIDX_RENAME].right = w->width - 2; + window_peep_overview_widgets[WIDX_LOCATE].right = w->width - 2; + window_peep_overview_widgets[WIDX_TRACK].right = w->width - 2; + + window_peep_overview_widgets[WIDX_PICKUP].left = w->width - 25; + window_peep_overview_widgets[WIDX_RENAME].left = w->width - 25; + window_peep_overview_widgets[WIDX_LOCATE].left = w->width - 25; + window_peep_overview_widgets[WIDX_TRACK].left = w->width - 25; RCT2_CALLPROC_X(0x6987ED, 0, 0, 0, 0, (int)w, 0, 0); } From 5bdff85db12f0f0ee3e351b9cfe22069cd29582a Mon Sep 17 00:00:00 2001 From: Duncan Date: Wed, 27 Aug 2014 12:34:47 +0100 Subject: [PATCH 20/58] Added window_align_tabs New cross window compatible version. For window_park and window_peep. --- src/window.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/window.c b/src/window.c index da0de66626..8599f34975 100644 --- a/src/window.c +++ b/src/window.c @@ -1495,4 +1495,18 @@ void RCT2_CALLPROC_WE_MOUSE_DOWN(int address, int widgetIndex, rct_window*w, rc " :[address] "+m" (address), [w] "+m" (w), [widget] "+m" (widget), [widgetIndex] "+m" (widgetIndex): : "eax", "esi", "edx", "edi" ); #endif -} \ No newline at end of file +} + +/* Based on rct2: 0x6987ED and another version from window_park */ +void window_align_tabs( rct_window *w, uint8 start_tab_id, uint8 end_tab_id ) + int x = w->widgets[start_tab_id].left; + int tab_width = w->widgets[start_tab_id].right - w->widgets[start_tab_id].left; + + for (int i = start_tab_id; i < end_tab_id; ++i){ + if ( !(w->disabled_widgets & (1LL << i)) ){ + w->widgets[i].left = x; + w->widgets[i].right = x + tab_width; + x += tab_width + 1; + } + } +} From b1a50459625b603aeab3bfeddfcc933e9a1def72 Mon Sep 17 00:00:00 2001 From: Duncan Date: Wed, 27 Aug 2014 12:35:44 +0100 Subject: [PATCH 21/58] Added window_align_tabs --- src/window.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/window.h b/src/window.h index d4a9cbb0af..eda9d5e0e1 100644 --- a/src/window.h +++ b/src/window.h @@ -460,6 +460,8 @@ void window_guest_list_init_vars_a(); void window_guest_list_init_vars_b(); void window_bubble_list_item(rct_window* w, int item_position); +void window_align_tabs( rct_window *w, uint8 start_tab_id, uint8 end_tab_id ); + void window_new_ride_init_vars(); void window_staff_init_vars(); From 71090c4c6eecceff585760f8dacdaba76707959a Mon Sep 17 00:00:00 2001 From: Duncan Date: Wed, 27 Aug 2014 12:37:01 +0100 Subject: [PATCH 22/58] Now uses window_align_tabs --- src/window_peep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/window_peep.c b/src/window_peep.c index 580edec207..b5d667a3be 100644 --- a/src/window_peep.c +++ b/src/window_peep.c @@ -870,5 +870,5 @@ void window_peep_overview_invalidate(){ window_peep_overview_widgets[WIDX_LOCATE].left = w->width - 25; window_peep_overview_widgets[WIDX_TRACK].left = w->width - 25; - RCT2_CALLPROC_X(0x6987ED, 0, 0, 0, 0, (int)w, 0, 0); + window_align_tabs(w, WIDX_TAB_1, WIDX_TAB_6); } From e84a9606e302fbf199fb3cc53bd7b8df7da34b93 Mon Sep 17 00:00:00 2001 From: Duncan Date: Wed, 27 Aug 2014 12:40:49 +0100 Subject: [PATCH 23/58] Added correct events to peep overview --- src/window_peep.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/window_peep.c b/src/window_peep.c index b5d667a3be..c932526332 100644 --- a/src/window_peep.c +++ b/src/window_peep.c @@ -175,6 +175,7 @@ void window_peep_close(); void window_peep_resize(); void window_peep_overview_mouse_up(); void window_peep_overview_paint(); +void window_peep_overview_invalidate(); static void* window_peep_overview_events[] = { window_peep_close, @@ -202,9 +203,9 @@ static void* window_peep_overview_events[] = { window_peep_emptysub, window_peep_emptysub, window_peep_emptysub, - (void*)0x696749, //Invalidate + window_peep_overview_invalidate, //Invalidate window_peep_overview_paint, //Paint - (void*)0x69707C + window_peep_emptysub }; static void* window_peep_stats_events[] = { From ba2e8f4942e7ab6edbe8d92d06b5fdb8ef1ea671 Mon Sep 17 00:00:00 2001 From: Duncan Date: Wed, 27 Aug 2014 12:48:29 +0100 Subject: [PATCH 24/58] Added viewport_init_wrapper for event --- src/window_peep.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/window_peep.c b/src/window_peep.c index c932526332..4ff895b367 100644 --- a/src/window_peep.c +++ b/src/window_peep.c @@ -176,6 +176,7 @@ void window_peep_resize(); void window_peep_overview_mouse_up(); void window_peep_overview_paint(); void window_peep_overview_invalidate(); +void window_peep_overview_viewport_init_wrapper(); static void* window_peep_overview_events[] = { window_peep_close, @@ -198,7 +199,7 @@ static void* window_peep_overview_events[] = { window_peep_emptysub, window_peep_emptysub, (void*)0x696A6A, - (void*)0x697076, + window_peep_overview_viewport_init_wrapper, window_peep_emptysub, window_peep_emptysub, window_peep_emptysub, @@ -644,6 +645,13 @@ void window_peep_set_page(rct_window* w, int page){ if (listen && w->viewport) w->viewport->flags |= VIEWPORT_FLAG_SOUND_ON; } +void window_peep_overview_viewport_init_wrapper(){ + rct_window* w; + window_get_register(w); + + window_peep_viewport_init(w); +} + /* rct2: 0x0069883C */ void window_peep_viewport_init(rct_window* w){ if (w->page != WINDOW_PEEP_OVERVIEW) return; From 6573dbba4e9f6a8abdcae55a8f6d0eeb9d5c1e71 Mon Sep 17 00:00:00 2001 From: Duncan Date: Wed, 27 Aug 2014 16:49:31 +0100 Subject: [PATCH 25/58] Added start of window_peep_overview_tab_paint Will not compile at present. --- src/window_peep.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/window_peep.c b/src/window_peep.c index 4ff895b367..ab9a1b8823 100644 --- a/src/window_peep.c +++ b/src/window_peep.c @@ -881,3 +881,46 @@ void window_peep_overview_invalidate(){ window_align_tabs(w, WIDX_TAB_1, WIDX_TAB_6); } + +void window_peep_overview_tab_paint( rct_window* w, rct_drawpixelinfo* dpi){ + + if ( w->disabled_widgets & (1ULL<widgets[WIDX_TAB_1].left + 1 + w->x; + //cx + int y = w->widgets[WIDX_TAB_1].top + 1 + w->y; + //bx + int width = w->widgets[WIDX_TAB_1].right - 1 - w->widgets[WIDX_TAB_1].left; + //dx + int height = w->widgets[WIDX_TAB_1].bottom - 1 - w->widgets[WIDX_TAB_1].top; + + if (w->page == WINDOW_PEEP_OVERVIEW){ + height++; + } + + rct_drawpixelinfo* cliped_dpi = clip_drawpixelinfo( dpi, x, width, y, height ); + + if (!cliped_dpi) return; + + int cx = 14; + int dx = 20; + + //ebp + rct_peep* peep = GET_PEEP(w->number); + + + if (peep->type == 1 && peep->staff_type == 3) + dx++; + eax = RCT2_GLOBAL(peep->sprite_type*8 + 0x982708, uint32); + ebx = *eax; + ebx++; + eax = 0; + + if (w->page == WINDOW_PEEP_OVERVIEW){ + ax = w->var_496; + ax &= ~((1<<0)|(1<<1)); + } + ebx += eax; + //698474 +} From 03d75b51b2b99fae7d02576af95cf9bdec1d4532 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Thu, 28 Aug 2014 06:58:57 +0100 Subject: [PATCH 26/58] fix compile mistakes --- src/gfx.c | 4 ++-- src/window.c | 1 + src/window_peep.c | 24 +++++++++++------------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 6e771560a4..fae14f1a7e 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -2276,7 +2276,7 @@ rct_drawpixelinfo* clip_drawpixelinfo(rct_drawpixelinfo* dpi, int left, int widt } int stickOutWidth = newDrawPixelInfo->x + newDrawPixelInfo->width - right; - if (stickOutWidth < 0) { + if (stickOutWidth > 0) { newDrawPixelInfo->width -= stickOutWidth; newDrawPixelInfo->pitch += stickOutWidth; } @@ -2290,7 +2290,7 @@ rct_drawpixelinfo* clip_drawpixelinfo(rct_drawpixelinfo* dpi, int left, int widt } int bp = newDrawPixelInfo->y + newDrawPixelInfo->height - bottom; - if (bp < 0) { + if (bp > 0) { newDrawPixelInfo->height -= bp; } diff --git a/src/window.c b/src/window.c index 8599f34975..27429674d7 100644 --- a/src/window.c +++ b/src/window.c @@ -1499,6 +1499,7 @@ void RCT2_CALLPROC_WE_MOUSE_DOWN(int address, int widgetIndex, rct_window*w, rc /* Based on rct2: 0x6987ED and another version from window_park */ void window_align_tabs( rct_window *w, uint8 start_tab_id, uint8 end_tab_id ) +{ int x = w->widgets[start_tab_id].left; int tab_width = w->widgets[start_tab_id].right - w->widgets[start_tab_id].left; diff --git a/src/window_peep.c b/src/window_peep.c index ab9a1b8823..8d154f4e74 100644 --- a/src/window_peep.c +++ b/src/window_peep.c @@ -79,8 +79,8 @@ rct_widget window_peep_overview_widgets[] = { { WWT_12, 1, 3, 166, 45, 56, 0x0FFFFFFFF, STR_NONE}, // Label Thought marquee { WWT_VIEWPORT, 1, 3, 166, 57, 143, 0x0FFFFFFFF, STR_NONE }, // Viewport { WWT_12, 1, 3, 166, 144, 154, 0x0FFFFFFFF, STR_NONE}, // Label Action - { WWT_FLATBTN, 1, 167, 190, 45, 68, SPR_RENAME, 1706}, // Pickup Button - { WWT_FLATBTN, 1, 167, 190, 69, 92, 0x1430, 1055}, // Rename Button + { WWT_FLATBTN, 1, 167, 190, 45, 68, 0x1436, 1706}, // Pickup Button + { WWT_FLATBTN, 1, 167, 190, 69, 92, SPR_RENAME, 1055}, // Rename Button { WWT_FLATBTN, 1, 167, 190, 93, 116, SPR_LOCATE, STR_LOCATE_SUBJECT_TIP},// Locate Button { WWT_FLATBTN, 1, 167, 190, 117, 140, SPR_TRACK_PEEP, 1930}, // Track Button { WIDGETS_END }, @@ -111,7 +111,7 @@ rct_widget window_peep_rides_widgets[] = { {WWT_TAB, 1, 96, 126, 17, 43, 0x2000144E, 1942}, {WWT_TAB, 1, 127, 157, 17, 43, 0x2000144E, 1943}, {WWT_TAB, 1, 158, 188, 17, 43, 0x2000144E, 1944}, - {WWT_SCROLL, 1, 3, 188, 57, 143, 2, STR_NONE}, + {WWT_SCROLL, 1, 3, 188, 57, 143, 2, STR_NONE}, {WIDGETS_END}, }; @@ -570,7 +570,6 @@ void window_peep_overview_mouse_up(){ window_peep_set_page(w, widgetIndex - WIDX_TAB_1); break; case WIDX_PICKUP: - //696ba6 if (!peep_can_be_picked_up(peep)) { return; } @@ -590,7 +589,6 @@ void window_peep_overview_mouse_up(){ RCT2_CALLPROC_X(0x0069A42F, 0, 0, 0, 0, (int)peep, 0, 0); break; case WIDX_RENAME: - //696e4d window_show_textinput(w, (int)widgetIndex, 0x5AC, 0x5AD, peep->name_string_idx); break; case WIDX_LOCATE: @@ -761,8 +759,8 @@ void window_peep_overview_paint(){ //rct_widget *labelWidget; window_paint_get_registers(w, dpi); - //RCT2_CALLPROC_X(0x696887, 0, 0, 0, 0, (int)w, (int)dpi, 0); - //return; + RCT2_CALLPROC_X(0x696887, 0, 0, 0, 0, (int)w, (int)dpi, 0); + return; window_draw_widgets(w, dpi); //6983dd @@ -830,7 +828,7 @@ void window_peep_overview_paint(){ /* rct2: 0x696749*/ void window_peep_overview_invalidate(){ rct_window* w; - window_invalidate_get_registers(w); + window_get_register(w); if (window_peep_page_widgets[w->page] != w->widgets){ w->widgets = window_peep_page_widgets[w->page]; @@ -838,7 +836,7 @@ void window_peep_overview_invalidate(){ } w->pressed_widgets &= ~(WIDX_TAB_1 | WIDX_TAB_2 |WIDX_TAB_3 |WIDX_TAB_4 |WIDX_TAB_5 |WIDX_TAB_6); - w->pressed_widgets |= 1 << (w->page + WIDX_TAB_1); + w->pressed_widgets |= 1ULL << (w->page + WIDX_TAB_1); rct_peep* peep = GET_PEEP(w->number); RCT2_GLOBAL(0x13CE952,uint16) = peep->name_string_idx; @@ -858,7 +856,7 @@ void window_peep_overview_invalidate(){ window_peep_overview_widgets[WIDX_TITLE].right = w->width - 2; window_peep_overview_widgets[WIDX_CLOSE].left = w->width - 13; - window_peep_overview_widgets[WIDX_CLOSE].rigth = w->width - 3; + window_peep_overview_widgets[WIDX_CLOSE].right = w->width - 3; window_peep_overview_widgets[WIDX_VIEWPORT].right = w->width - 26; window_peep_overview_widgets[WIDX_VIEWPORT].bottom = w->height - 14; @@ -912,13 +910,13 @@ void window_peep_overview_tab_paint( rct_window* w, rct_drawpixelinfo* dpi){ if (peep->type == 1 && peep->staff_type == 3) dx++; - eax = RCT2_GLOBAL(peep->sprite_type*8 + 0x982708, uint32); - ebx = *eax; + int eax = RCT2_GLOBAL(peep->sprite_type*8 + 0x982708, uint32); + int ebx = *(uint32*)eax; ebx++; eax = 0; if (w->page == WINDOW_PEEP_OVERVIEW){ - ax = w->var_496; + int ax = *((uint16*)w + 496 / 2); ax &= ~((1<<0)|(1<<1)); } ebx += eax; From 6f14e48a330ccff726fcc88d1ae8e62a70c87e02 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Thu, 28 Aug 2014 07:04:02 +0100 Subject: [PATCH 27/58] Switched window_park_align tabs to new window version --- src/window_park.c | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/src/window_park.c b/src/window_park.c index 39b982ae1b..58929e5366 100644 --- a/src/window_park.c +++ b/src/window_park.c @@ -576,7 +576,6 @@ static uint32 window_park_page_enabled_widgets[] = { static void window_park_init_viewport(rct_window *w); static void window_park_set_page(rct_window *w, int page); static void window_park_anchor_border_widgets(rct_window *w); -static void window_park_align_tabs(rct_window *w); static void window_park_set_pressed_tab(rct_window *w); static void window_park_draw_tab_images(rct_drawpixelinfo *dpi, rct_window *w); @@ -916,7 +915,7 @@ static void window_park_entrance_invalidate() if (RCT2_GLOBAL(RCT2_ADDRESS_OBJECTIVE_TYPE, uint8) == OBJECTIVE_GUESTS_AND_RATING) w->disabled_widgets |= (1 << WIDX_OPEN_OR_CLOSE); - window_park_align_tabs(w); + window_align_tabs(w, WIDX_TAB_1, WIDX_TAB_7); window_park_anchor_border_widgets(w); // Anchor entrance page specific widgets @@ -1149,7 +1148,7 @@ static void window_park_rating_invalidate() RCT2_GLOBAL(0x013CE952, uint16) = RCT2_GLOBAL(0x013573D4, uint16); RCT2_GLOBAL(0x013CE952 + 2, uint32) = RCT2_GLOBAL(0x013573D8, uint32); - window_park_align_tabs(w); + window_align_tabs(w, WIDX_TAB_1, WIDX_TAB_7); window_park_anchor_border_widgets(w); } @@ -1284,7 +1283,7 @@ static void window_park_guests_invalidate() RCT2_GLOBAL(0x013CE952, uint16) = RCT2_GLOBAL(0x013573D4, uint16); RCT2_GLOBAL(0x013CE952 + 2, uint32) = RCT2_GLOBAL(0x013573D8, uint32); - window_park_align_tabs(w); + window_align_tabs(w, WIDX_TAB_1, WIDX_TAB_7); window_park_anchor_border_widgets(w); } @@ -1434,7 +1433,7 @@ static void window_park_price_invalidate() RCT2_GLOBAL(0x013CE952 + 6, uint32) = RCT2_GLOBAL(RCT2_ADDRESS_PARK_ENTRANCE_FEE, uint16); window_park_price_widgets[WIDX_PRICE].image = RCT2_GLOBAL(RCT2_ADDRESS_PARK_ENTRANCE_FEE, uint16) == 0 ? STR_FREE : 1429; - window_park_align_tabs(w); + window_align_tabs(w, WIDX_TAB_1, WIDX_TAB_7); window_park_anchor_border_widgets(w); } @@ -1543,7 +1542,7 @@ static void window_park_stats_invalidate() RCT2_GLOBAL(0x013CE952, uint16) = RCT2_GLOBAL(0x013573D4, uint16); RCT2_GLOBAL(0x013CE952 + 2, uint32) = RCT2_GLOBAL(0x013573D8, uint32); - window_park_align_tabs(w); + window_align_tabs(w, WIDX_TAB_1, WIDX_TAB_7); window_park_anchor_border_widgets(w); } @@ -1705,7 +1704,7 @@ static void window_park_objective_invalidate() else window_park_objective_widgets[WIDX_ENTER_NAME].type = WWT_EMPTY; - window_park_align_tabs(w); + window_align_tabs(w, WIDX_TAB_1, WIDX_TAB_7); window_park_anchor_border_widgets(w); } @@ -1852,7 +1851,7 @@ static void window_park_awards_invalidate() RCT2_GLOBAL(0x013CE952, uint16) = RCT2_GLOBAL(0x013573D4, uint16); RCT2_GLOBAL(0x013CE952 + 2, uint32) = RCT2_GLOBAL(0x013573D8, uint32); - window_park_align_tabs(w); + window_align_tabs(w, WIDX_TAB_1, WIDX_TAB_7); window_park_anchor_border_widgets(w); } @@ -1945,21 +1944,6 @@ static void window_park_anchor_border_widgets(rct_window *w) w->widgets[WIDX_CLOSE].right = w->width - 3; } -static void window_park_align_tabs(rct_window *w) -{ - int i, x, tab_width; - - x = w->widgets[WIDX_TAB_1].left; - tab_width = w->widgets[WIDX_TAB_1].right - w->widgets[WIDX_TAB_1].left; - for (i = 0; i < 7; i++) { - if (w->disabled_widgets & (1LL << (WIDX_TAB_1 + i))) - continue; - w->widgets[WIDX_TAB_1 + i].left = x; - w->widgets[WIDX_TAB_1 + i].right = x + tab_width; - x += tab_width + 1; - } -} - static void window_park_set_pressed_tab(rct_window *w) { int i; From 1b077af90e39cd05ba382b59d2053cbdeb9567b7 Mon Sep 17 00:00:00 2001 From: hexdec Date: Thu, 28 Aug 2014 01:48:49 +0200 Subject: [PATCH 28/58] Implemented window_staff_peep_fire. Added new window class WC_FIRE_PROMPT. --- src/window.h | 1 + src/window_staff_peep.c | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/window.h b/src/window.h index eda9d5e0e1..1098eba380 100644 --- a/src/window.h +++ b/src/window.h @@ -340,6 +340,7 @@ enum { WC_PEEP = 23, WC_GUEST_LIST = 24, WC_STAFF_LIST = 25, + WC_FIRE_PROMPT = 26, WC_PARK_INFORMATION = 27, WC_FINANCES = 28, WC_TITLE_MENU = 29, diff --git a/src/window_staff_peep.c b/src/window_staff_peep.c index 8131d8bab9..74c74c9642 100644 --- a/src/window_staff_peep.c +++ b/src/window_staff_peep.c @@ -264,7 +264,28 @@ void window_staff_peep_close() /** rct2: 0x6C0A77 */ void window_staff_peep_fire(rct_window* w) { - RCT2_CALLPROC_X(0x6C0A77, 0, 0, 0, 0, (int)w, 0, 0); + // Check if the confirm window already exists. + if (window_bring_to_front_by_id(0x1A, w->number)) { + return; + } + + // Find center of the screen. + int screen_height = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, sint16); + int screen_width = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, sint16); + int x = screen_width/2 - 100; + int y = screen_height/2 - 50; + + rct_window* window_prompt = window_create(x, y, 200, 100, (uint32*)0x992C3C, 0x1A, 0); + window_prompt->widgets = (rct_widget*)0x9AFB4C; + window_prompt->enabled_widgets |= 0x4; + window_prompt->enabled_widgets |= 0x8; + window_prompt->enabled_widgets |= 0x10; + + window_init_scroll_widgets(window_prompt); + + window_prompt->flags |= 0x10; + window_prompt->number = w->number; + window_prompt->colours[0] = 0x9A; } /** From 4b8fbcfd28ac2a5048ebe2ca2e2473253435ed62 Mon Sep 17 00:00:00 2001 From: hexdec Date: Thu, 28 Aug 2014 16:28:19 +0200 Subject: [PATCH 29/58] Added order and stats events for window_staff_peep. --- src/window_staff_peep.c | 70 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/src/window_staff_peep.c b/src/window_staff_peep.c index 74c74c9642..17c58beba9 100644 --- a/src/window_staff_peep.c +++ b/src/window_staff_peep.c @@ -115,13 +115,77 @@ static void* window_staff_peep_overview_events[] = { window_staff_peep_emptysub, (void*)0x6BDD91, //Invalidate (void*)0x6BDEAF, //Paint - (void*)0x6BE62A + window_staff_peep_emptysub +}; + +// 0x992B5C +static void* window_staff_peep_orders_events[] = { + window_staff_peep_emptysub, + (void*)0x6BE7DB, + (void*)0x6BE975, + (void*)0x6BE802, + (void*)0x6BE809, + (void*)0x6BE9DA, + (void*)0x6BE960, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + (void*)0x6BE62B, //Invalidate + (void*)0x6BE7C6, //Paint + window_staff_peep_emptysub +}; + +// 0x992BCC +static void* window_staff_peep_stats_events[] = { + window_staff_peep_emptysub, + (void*)0x6BEBCF, + (void*)0x6BEC1B, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + (void*)0x6BEC80, + (void*)0x6BEBEA, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + window_staff_peep_emptysub, + (void*)0x6BE9E9, //Invalidate + (void*)0x6BEA86, //Paint + window_staff_peep_emptysub }; void* window_staff_peep_page_events[] = { window_staff_peep_overview_events, - (void*)0x992B5C, - (void*)0x992BCC + window_staff_peep_orders_events, + window_staff_peep_stats_events }; uint32 window_staff_peep_page_enabled_widgets[] = { From 5fdc66d446fa16788e05679bac0a3e95ac7bcdca Mon Sep 17 00:00:00 2001 From: hexdec Date: Thu, 28 Aug 2014 16:30:42 +0200 Subject: [PATCH 30/58] Renamed window_staff_peep_mouse_up to window_staff_peep_mouseup. --- src/window_staff_peep.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/window_staff_peep.c b/src/window_staff_peep.c index 17c58beba9..014692acf2 100644 --- a/src/window_staff_peep.c +++ b/src/window_staff_peep.c @@ -84,12 +84,12 @@ void window_staff_peep_set_page(rct_window* w, int page); void window_staff_peep_disable_widgets(rct_window* w); void window_staff_peep_close(); -void window_staff_peep_mouse_up(); +void window_staff_peep_mouseup(); // 0x992AEC static void* window_staff_peep_overview_events[] = { window_staff_peep_close, - window_staff_peep_mouse_up, + window_staff_peep_mouseup, (void*)0x6BE558, (void*)0x6BDF98, (void*)0x6BDFA3, @@ -401,7 +401,7 @@ void window_staff_peep_set_page(rct_window* w, int page) } /** rct2: 0x006BDF55 */ -void window_staff_peep_mouse_up() +void window_staff_peep_mouseup() { short widgetIndex; rct_window* w; From b6f98167c4b97a4b32bf1dcf6100be1ea318c05f Mon Sep 17 00:00:00 2001 From: adrian17 Date: Thu, 28 Aug 2014 17:27:48 +0200 Subject: [PATCH 31/58] Use macros from addresses.h --- src/audio.c | 4 ++-- src/park.c | 2 +- src/scenario.c | 2 +- src/window_new_campaign.c | 2 +- src/window_new_ride.c | 16 ++++++++-------- src/window_research.c | 4 ++-- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/audio.c b/src/audio.c index 6fe7726f63..470862fc9a 100644 --- a/src/audio.c +++ b/src/audio.c @@ -282,7 +282,7 @@ int dsound_create_primary_buffer(int a, int device, int channels, int samples, i } WAVEFORMATEX waveformat1, waveformat2; RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER)->lpVtbl->GetFormat(RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER), &waveformat1, sizeof(WAVEFORMATEX), 0); - RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER)->lpVtbl->SetFormat(RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER), &RCT2_GLOBAL(0x01425B40, WAVEFORMATEX)); + RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER)->lpVtbl->SetFormat(RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER), &RCT2_GLOBAL(RCT2_ADDRESS_AUDIO_INFO, WAVEFORMATEX)); RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER)->lpVtbl->GetFormat(RCT2_GLOBAL(0x009E2BA8, LPDIRECTSOUNDBUFFER), &waveformat2, sizeof(WAVEFORMATEX), 0); return 1; } @@ -683,7 +683,7 @@ int sound_play_panned(int sound_id, int x) } RCT2_GLOBAL(0x014241BC, uint32) = 1; - sound_prepare(sound_id, &other_sound->sound, 1, RCT2_GLOBAL(0x009AAC6E, uint32)); + sound_prepare(sound_id, &other_sound->sound, 1, RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_SOUND_SW_BUFFER, uint32)); RCT2_GLOBAL(0x014241BC, uint32) = 0; RCT2_GLOBAL(0x014241BC, uint32) = 1; result = sound_play(&other_sound->sound, 0, volume, pan, 0); diff --git a/src/park.c b/src/park.c index 1779458712..159017c392 100644 --- a/src/park.c +++ b/src/park.c @@ -90,7 +90,7 @@ void park_init() RCT2_GLOBAL(RCT2_ADDRESS_PARK_ENTRANCE_FEE, money16) = MONEY(10, 00); RCT2_GLOBAL(RCT2_ADDRESS_PEEP_SPAWNS, sint16) = -1; RCT2_GLOBAL(0x013573F8, sint16) = -1; - RCT2_GLOBAL(0x01357CF2, uint16) = 127; + RCT2_GLOBAL(RCT2_ADDRESS_ACTIVE_RESEARCH_TYPES, uint16) = 127; RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_RESEARCH_LEVEL, uint8) = 2; RCT2_GLOBAL(RCT2_ADDRESS_GUEST_INITIAL_CASH, uint16) = MONEY(50,00); // Cash per guest (average) diff --git a/src/scenario.c b/src/scenario.c index a2884a39d0..406179dbaa 100644 --- a/src/scenario.c +++ b/src/scenario.c @@ -139,7 +139,7 @@ void scenario_load(const char *path) sawyercoding_read_chunk(file, (uint8*)RCT2_ADDRESS_CURRENT_PARK_RATING); // Read ? - sawyercoding_read_chunk(file, (uint8*)0x01357CF2); + sawyercoding_read_chunk(file, (uint8*)RCT2_ADDRESS_ACTIVE_RESEARCH_TYPES); // Read ? sawyercoding_read_chunk(file, (uint8*)0x0135832C); diff --git a/src/window_new_campaign.c b/src/window_new_campaign.c index 16cd807000..efe6ad5afd 100644 --- a/src/window_new_campaign.c +++ b/src/window_new_campaign.c @@ -174,7 +174,7 @@ void window_new_campaign_open(sint16 campaignType) numApplicableRides = 0; window_new_campaign_rides[0] = 255; FOR_ALL_RIDES(i, ride) { - if (!(RCT2_GLOBAL(0x0097CF40 + (ride->type * 8), uint32) & 0x03820000)) + if (!(RCT2_GLOBAL(RCT2_ADDRESS_RIDE_FLAGS + (ride->type * 8), uint32) & 0x03820000)) window_new_campaign_rides[numApplicableRides++] = i; } window_new_campaign_rides[numApplicableRides] = 255; diff --git a/src/window_new_ride.c b/src/window_new_ride.c index 296aea59ce..f744a63c24 100644 --- a/src/window_new_ride.c +++ b/src/window_new_ride.c @@ -29,7 +29,7 @@ #include "widget.h" #include "window.h" -#define _window_new_ride_current_tab RCT2_GLOBAL(0x00F43824, uint8) +#define _window_new_ride_current_tab RCT2_GLOBAL(RCT2_ADDRESS_WINDOW_RIDE_LIST_SELECTED_TAB, uint8) typedef struct { uint8 type; @@ -374,7 +374,7 @@ static void window_new_ride_scroll_to_focused_ride(rct_window *w) // Find row index of the focused ride type rct_widget *listWidget = &window_new_ride_widgets[WIDX_RIDE_LIST]; - int focusRideType = RCT2_ADDRESS(0x00F43825, uint16)[_window_new_ride_current_tab]; + int focusRideType = RCT2_ADDRESS(RCT2_ADDRESS_WINDOW_RIDE_LIST_HIGHLIGHTED_ITEM, uint16)[_window_new_ride_current_tab]; int count = 0, row = 0; ride_list_item *listItem = (ride_list_item*)0x00F43523; while (listItem->type != 255 || listItem->entry_index != 255) { @@ -436,7 +436,7 @@ void window_new_ride_open() window_new_ride_populate_list(); - w->new_ride.highlighted_ride_id = RCT2_ADDRESS(0x00F43825, sint16)[_window_new_ride_current_tab]; + w->new_ride.highlighted_ride_id = RCT2_ADDRESS(RCT2_ADDRESS_WINDOW_RIDE_LIST_HIGHLIGHTED_ITEM, sint16)[_window_new_ride_current_tab]; if (w->new_ride.highlighted_ride_id == -1) w->new_ride.highlighted_ride_id = RCT2_GLOBAL(0x00F43523, sint16); @@ -579,7 +579,7 @@ static void window_new_ride_mousedown(int widgetIndex, rct_window *w, rct_widget w->new_ride.selected_ride_countdown = -1; window_new_ride_populate_list(); if (page < WINDOW_NEW_RIDE_PAGE_RESEARCH) { - w->new_ride.highlighted_ride_id = RCT2_ADDRESS(0x00F43825, sint16)[page]; + w->new_ride.highlighted_ride_id = RCT2_ADDRESS(RCT2_ADDRESS_WINDOW_RIDE_LIST_HIGHLIGHTED_ITEM, sint16)[page]; if (w->new_ride.highlighted_ride_id == -1) w->new_ride.highlighted_ride_id = RCT2_GLOBAL(0x00F43523, sint16); } @@ -654,7 +654,7 @@ static void window_new_ride_scrollmousedown() if (item.type == 255 && item.entry_index == 255) return; - RCT2_ADDRESS(0x00F43825, ride_list_item)[_window_new_ride_current_tab] = item; + RCT2_ADDRESS(RCT2_ADDRESS_WINDOW_RIDE_LIST_HIGHLIGHTED_ITEM, ride_list_item)[_window_new_ride_current_tab] = item; w->new_ride.selected_ride_id = *((sint16*)&item); sound_play_panned(SOUND_CLICK_1, w->x + (w->width / 2)); @@ -683,7 +683,7 @@ static void window_new_ride_scrollmouseover() return; w->new_ride.highlighted_ride_id = *((sint16*)&item); - RCT2_ADDRESS(0x00F43825, ride_list_item)[_window_new_ride_current_tab] = item; + RCT2_ADDRESS(RCT2_ADDRESS_WINDOW_RIDE_LIST_HIGHLIGHTED_ITEM, ride_list_item)[_window_new_ride_current_tab] = item; window_invalidate(w); } @@ -715,7 +715,7 @@ static void window_new_ride_invalidate() if (_window_new_ride_current_tab == WINDOW_NEW_RIDE_PAGE_RESEARCH) { window_new_ride_widgets[WIDX_LAST_DEVELOPMENT_BUTTON].type = WWT_EMPTY; - uint32 typeId = RCT2_GLOBAL(0x01357CF4, uint32); + uint32 typeId = RCT2_GLOBAL(RCT2_ADDRESS_LAST_RESEARCHED_ITEM_SUBJECT, uint32); if (typeId != 0xFFFFFFFF) { window_new_ride_widgets[WIDX_LAST_DEVELOPMENT_BUTTON].type = WWT_FLATBTN; window_new_ride_widgets[WIDX_LAST_DEVELOPMENT_BUTTON].image = typeId >= 0x10000 ? 5189 : 5191; @@ -790,7 +790,7 @@ static void window_new_ride_paint() x = w->x + 10; y = w->y + window_new_ride_widgets[WIDX_LAST_DEVELOPMENT_GROUP].top + 12; - uint32 typeId = RCT2_GLOBAL(0x01357CF4, uint32); + uint32 typeId = RCT2_GLOBAL(RCT2_ADDRESS_LAST_RESEARCHED_ITEM_SUBJECT, uint32); if (typeId != 0xFFFFFFFF) { if (typeId >= 0x10000) { rct_ride_type *rideEntry = RCT2_GLOBAL(0x009ACFA4 + (typeId & 0xFF) * 4, rct_ride_type*); diff --git a/src/window_research.c b/src/window_research.c index 0417db1afa..b65fc7dba4 100644 --- a/src/window_research.c +++ b/src/window_research.c @@ -310,7 +310,7 @@ static void window_research_development_invalidate() window_research_set_pressed_tab(w); window_research_development_widgets[WIDX_LAST_DEVELOPMENT_BUTTON].type = WWT_EMPTY; - uint32 typeId = RCT2_GLOBAL(0x01357CF4, uint32); + uint32 typeId = RCT2_GLOBAL(RCT2_ADDRESS_LAST_RESEARCHED_ITEM_SUBJECT, uint32); if (typeId != 0xFFFFFFFF) { window_research_development_widgets[WIDX_LAST_DEVELOPMENT_BUTTON].type = WWT_FLATBTN; window_research_development_widgets[WIDX_LAST_DEVELOPMENT_BUTTON].image = typeId >= 0x10000 ? 5189 : 5191; @@ -377,7 +377,7 @@ static void window_research_development_paint() x = w->x + 10; y = w->y + window_research_development_widgets[WIDX_LAST_DEVELOPMENT_GROUP].top + 12; - uint32 typeId = RCT2_GLOBAL(0x01357CF4, uint32); + uint32 typeId = RCT2_GLOBAL(RCT2_ADDRESS_LAST_RESEARCHED_ITEM_SUBJECT, uint32); int lastDevelopmentFormat; if (typeId != 0xFFFFFFFF) { if (typeId >= 0x10000) { From 563e0ca3dcee57ec297f69883bd567473bff640b Mon Sep 17 00:00:00 2001 From: adrian17 Date: Thu, 28 Aug 2014 20:14:00 +0200 Subject: [PATCH 32/58] Fix wrong condition in audio.c --- src/audio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/audio.c b/src/audio.c index 470862fc9a..678938e21c 100644 --- a/src/audio.c +++ b/src/audio.c @@ -435,7 +435,7 @@ void audio_init2(int device) } } } - if (!RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) & 1 << 4) { + if (!(RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) & 1 << 4)) { RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_SOUND_SW_BUFFER, uint32) = RCT2_GLOBAL(0x001425B74, uint32) != RCT2_GLOBAL(0x001425B78, uint32) || RCT2_GLOBAL(0x001425B74, uint32) != RCT2_GLOBAL(0x001425B7C, uint32); RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) |= 1 << 4; config_save(); From 01789c0781796f9764978aa841d96b4f673a2300 Mon Sep 17 00:00:00 2001 From: zsilencer Date: Thu, 28 Aug 2014 14:05:56 -0600 Subject: [PATCH 33/58] 0x00401000 --- src/audio.c | 180 +++++++++++++++++++++++++++++++++++++++++++++++++++- src/audio.h | 96 ++++++++++++++++++++++++++++ 2 files changed, 275 insertions(+), 1 deletion(-) diff --git a/src/audio.c b/src/audio.c index 6fe7726f63..0299246ac7 100644 --- a/src/audio.c +++ b/src/audio.c @@ -344,7 +344,185 @@ int map_sound_info(const char* filename) */ void sub_401000(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2, int channel) { - RCT2_CALLFUNC_6(0x00401000, void, UINT, UINT, DWORD_PTR, DWORD_PTR, DWORD_PTR, int, uTimerID, uMsg, dwUser, dw1, dw2, channel); + //RCT2_CALLFUNC_6(0x00401000, void, UINT, UINT, DWORD_PTR, DWORD_PTR, DWORD_PTR, int, uTimerID, uMsg, dwUser, dw1, dw2, channel); + rct_sound_unknown* unknown = &RCT2_ADDRESS(0x014262E0, rct_sound_unknown)[channel]; + DWORD status; + DWORD dwCurrentPlayCursor; + DWORD dwCurrentWriteCursor; + int var1; + int var2; + int bufferlost = 0; + char* buf1; + int buf1size; + char* buf2; + int buf2size; + unknown->dsbuffer->lpVtbl->GetStatus(unknown->dsbuffer, &status); + if (status & DSBSTATUS_BUFFERLOST) { + if (FAILED(unknown->dsbuffer->lpVtbl->Restore(unknown->dsbuffer))) { + return; + } + unknown->playpos = 0; + bufferlost = 1; + } + unknown->dsbuffer->lpVtbl->GetCurrentPosition(unknown->dsbuffer, &dwCurrentPlayCursor, &dwCurrentWriteCursor); + if (dwCurrentPlayCursor != unknown->playpos || bufferlost) { + if (unknown->var_168 && !unknown->var_15C) { + if (!unknown->var_160) { + unknown->var_160 = 1; + if (!unknown->var_4) { + LPDIRECTSOUNDBUFFER dsbuffer = RCT2_ADDRESS(RCT2_ADDRESS_DSOUND_BUFFERS, LPDIRECTSOUNDBUFFER)[channel]; + unknown->var_0 = 0; + if (dsbuffer) { + dsbuffer->lpVtbl->Stop(dsbuffer); + dsbuffer->lpVtbl->Release(dsbuffer); + RCT2_ADDRESS(RCT2_ADDRESS_DSOUND_BUFFERS, LPDIRECTSOUNDBUFFER)[channel] = 0; + } + if (unknown->var_120) { + sound_channel_free(&unknown->var_120, &unknown->var_11C); + } + } + } + return; + } + if (dwCurrentPlayCursor >= unknown->playpos) { + var1 = dwCurrentPlayCursor - unknown->playpos; + } else { + var1 = dwCurrentPlayCursor + unknown->var_150 - unknown->playpos; + } + if (bufferlost) { + var2 = 2 * unknown->var_150 / 6; + } else { + var2 = var1; + } + unknown->var_158 += var1; + if (unknown->var_168) { + int var3 = unknown->var_15C; + int* var4 = &unknown->var_15C; + if (var3) { + if (var1 <= var3) { + *var4 = var3 - var1; + } else { + *var4 = 0; + } + if (SUCCEEDED(unknown->dsbuffer->lpVtbl->Lock(unknown->dsbuffer, unknown->playpos, var2, &buf1, &buf1size, &buf2, &buf2size, 0))) { + char var5 = -(((char*)unknown->var_11C + 14) != (char *)8); + var5 &= 0x80; + memset(buf1, var5 + 128, buf1size); + if (buf2 && buf2size) { + char var5 = -(((char*)unknown->var_11C + 14) != (char *)8); + var5 &= 0x80; + memset(buf2, var5 + 128, buf2size); + } + unknown->dsbuffer->lpVtbl->Unlock(unknown->dsbuffer, buf1, buf1size, buf2, buf2size); + unknown->playpos += var2; + if( unknown->playpos >= unknown->var_150) { + unknown->playpos = unknown->playpos - unknown->var_150; + } + return; + } + // TimeFunc() could not lock DirectSoundBuffer + return; + } + } + if (FAILED(unknown->dsbuffer->lpVtbl->Lock(unknown->dsbuffer, unknown->playpos, var2, &buf1, &buf1size, &buf2, &buf2size, 0))) { + // TimeFunc() could not lock DirectSoundBuffer + return; + } + if (buf1size) { + if (unknown->var_160) { + int var5 = -(((char*)unknown->var_11C + 14) != (char *)8); + var5 &= 0x80; + memset(buf1, var5 + 128, buf1size); + goto label49; + } + } + int var7; + RCT2_CALLFUNC_5(0x00405383, int, HMMIO, int, char*, int*, int*, unknown->var_120, buf1size, buf1, &unknown->var_124, &var7); + if (var7 < buf1size) { + if (!unknown->var_164) { + int s = *(char*)((char*)unknown->var_11C + 14); + int t = buf1size - var7; + int v; + if (s == 8) { + v = 128; + } else { + if (s != 16) { + goto label42; + } + v = 0; + } + memset(&buf1[var7], v, t); + label42: + unknown->var_168 = 1; + if (dwCurrentPlayCursor <= unknown->playpos) { + unknown->var_15C = unknown->playpos - dwCurrentPlayCursor; + } else { + unknown->var_15C = unknown->playpos + unknown->var_150 - dwCurrentPlayCursor; + } + goto label49; + } + char* v21 = buf1; + int v38 = buf1size; + do { + v38 -= var7; + v21 += var7; + RCT2_CALLFUNC_1(0x0040153B, int, int, channel); + RCT2_CALLFUNC_5(0x00405383, int, HMMIO, int, char*, int*, int*, unknown->var_120, v38, v21, &unknown->var_124, &var7); + } while(var7 < v38); + } + label49: + if (buf2size == 0 || unknown->var_160 != 0) { + if(buf2 != 0 && buf2size != 0 && unknown->var_160 != 0) { + int var5 = -(*(char*)((char*)unknown->var_11C + 14) != 8); + var5 &= 0x80; + memset(buf2, var5 + 128, buf2size); + } + goto label68; + } + RCT2_CALLFUNC_5(0x00405383, int, HMMIO, int, char*, int*, int*, unknown->var_120, buf2size, buf2, &unknown->var_124, &var7); + if (var7 >= buf2size) { + label68: + unknown->dsbuffer->lpVtbl->Unlock(unknown->dsbuffer, buf1, buf1size, buf2, buf2size); + unknown->playpos += var2; + if( unknown->playpos >= unknown->var_150 ) { + unknown->playpos -= unknown->var_150; + } + if (bufferlost != 0) { + unknown->dsbuffer->lpVtbl->Play(unknown->dsbuffer, 0, 0, DSBPLAY_LOOPING); + } + return; + } + if (unknown->var_164 != 0) { + char* v26 = buf2; + int v27 = buf2size; + do { + v26 += var7; + v27 -= var7; + RCT2_CALLFUNC_1(0x0040153B, int, int, channel); + RCT2_CALLFUNC_5(0x00405383, int, HMMIO, int, char*, int*, int*, unknown->var_120, v27, v26, &unknown->var_124, &var7); + } while(var7 < v27); + goto label68; + } + int s = buf2size - var7; + int v; + if (unknown->var_11C == (HGLOBAL)8) { + v = 128; + } else { + if (unknown->var_11C != (HGLOBAL)16) { + goto label58; + } + v = 0; + } + memset(&buf2[var7], v, s); + label58: + unknown->var_168 = 1; + if (dwCurrentPlayCursor <= unknown->playpos) { + unknown->var_15C = unknown->playpos - dwCurrentPlayCursor; + } else { + unknown->var_15C = unknown->playpos + unknown->var_150 - dwCurrentPlayCursor; + } + goto label68; + } } /** diff --git a/src/audio.h b/src/audio.h index 85aba58db8..b630ba92ce 100644 --- a/src/audio.h +++ b/src/audio.h @@ -100,6 +100,101 @@ typedef struct { rct_sound sound; } rct_other_sound; +typedef struct { + uint32 var_0; + uint32 var_4; + uint32 var_8; + uint16 var_C; + uint16 var_E; + uint32 var_10; + uint32 var_14; + uint32 var_18; + uint32 var_1C; + uint32 var_20; + uint32 var_24; + uint32 var_28; + uint32 var_2C; + uint32 var_30; + uint32 var_34; + uint32 var_38; + uint32 var_3C; + uint32 var_40; + uint32 var_44; + uint32 var_48; + uint32 var_4C; + uint32 var_50; + uint32 var_54; + uint32 var_58; + uint32 var_5C; + uint32 var_60; + uint32 var_64; + uint32 var_68; + uint32 var_6C; + uint32 var_70; + uint32 var_74; + uint32 var_78; + uint32 var_7C; + uint32 var_80; + uint32 var_84; + uint32 var_88; + uint32 var_8C; + uint32 var_90; + uint32 var_94; + uint32 var_98; + uint32 var_9C; + uint32 var_A0; + uint32 var_A4; + uint32 var_A8; + uint32 var_AC; + uint32 var_B0; + uint32 var_B4; + uint32 var_B8; + uint32 var_BC; + uint32 var_C0; + uint32 var_C4; + uint32 var_C8; + uint32 var_CC; + uint32 var_D0; + uint32 var_D4; + uint32 var_D8; + uint32 var_DC; + uint32 var_E0; + uint32 var_E4; + uint32 var_E8; + uint32 var_EC; + uint32 var_F0; + uint32 var_F4; + uint32 var_F8; + uint32 var_FC; + uint32 var_100; + uint32 var_104; + uint32 var_108; + uint32 var_10C; + uint32 var_110; + uint32 var_114; + uint32 var_118; + HGLOBAL var_11C; + HMMIO var_120; + uint32 var_124; + uint32 var_128; + uint32 var_12C; + uint32 var_130; + uint32 var_134; + uint32 var_138; + uint32 var_13C; + uint32 var_140; + uint32 var_144; + uint32 var_148; + LPDIRECTSOUNDBUFFER dsbuffer; // 0x14C + uint32 var_150; + uint32 playpos; // 0x154 + uint32 var_158; + uint32 var_15C; + uint32 var_160; + uint32 var_164; + uint32 var_168; +} rct_sound_unknown; + int get_dsound_devices(); int sound_prepare(int sound_id, rct_sound *sound, int channels, int software); int sound_play_panned(int sound_id, int x); @@ -112,6 +207,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); +void sound_channel_free(HMMIO* hmmio, HGLOBAL* hmem); int sound_stop(rct_sound *sound); int sound_stop_all(); int unmap_file(LPCVOID base); From 77384e45faa6095165d0d917268b3f2a7fc03391 Mon Sep 17 00:00:00 2001 From: hexdec Date: Fri, 29 Aug 2014 00:58:09 +0200 Subject: [PATCH 34/58] Implemented mouseup for window_staff_peep. --- src/game.h | 2 +- src/window_staff_peep.c | 67 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/src/game.h b/src/game.h index 0e1a95035b..1f87d944c0 100644 --- a/src/game.h +++ b/src/game.h @@ -54,7 +54,7 @@ enum GAME_COMMAND { GAME_COMMAND_HIRE_NEW_STAFF_MEMBER, // 29 GAME_COMMAND_30, GAME_COMMAND_31, - GAME_COMMAND_32, + GAME_COMMAND_SET_STAFF_ORDER, GAME_COMMAND_33, GAME_COMMAND_SET_PARK_OPEN, // 34 GAME_COMMAND_35, diff --git a/src/window_staff_peep.c b/src/window_staff_peep.c index 014692acf2..ffbad2eace 100644 --- a/src/window_staff_peep.c +++ b/src/window_staff_peep.c @@ -86,6 +86,10 @@ void window_staff_peep_disable_widgets(rct_window* w); void window_staff_peep_close(); void window_staff_peep_mouseup(); +void window_staff_peep_orders_mouseup(); + +void window_staff_peep_stats_mouseup(); + // 0x992AEC static void* window_staff_peep_overview_events[] = { window_staff_peep_close, @@ -121,7 +125,7 @@ static void* window_staff_peep_overview_events[] = { // 0x992B5C static void* window_staff_peep_orders_events[] = { window_staff_peep_emptysub, - (void*)0x6BE7DB, + window_staff_peep_orders_mouseup, (void*)0x6BE975, (void*)0x6BE802, (void*)0x6BE809, @@ -153,7 +157,7 @@ static void* window_staff_peep_orders_events[] = { // 0x992BCC static void* window_staff_peep_stats_events[] = { window_staff_peep_emptysub, - (void*)0x6BEBCF, + window_staff_peep_stats_mouseup, (void*)0x6BEC1B, window_staff_peep_emptysub, window_staff_peep_emptysub, @@ -409,7 +413,6 @@ void window_staff_peep_mouseup() rct_peep* peep = GET_PEEP(w->number); switch (widgetIndex) { - case WIDX_CLOSE: window_close(w); break; @@ -445,4 +448,62 @@ void window_staff_peep_mouseup() window_show_textinput(w, (int)widgetIndex, 0xBA1, 0xBA2, peep->name_string_idx); break; } +} + +/** rct2: 0x006BE814 */ +void window_staff_peep_set_order(rct_window* w, int order_id) +{ + int eax = 1 << order_id; + + rct_peep* peep = GET_PEEP(w->number); + + int ax = peep->var_C6 ^ eax; + int flags = (ax << 8) | 1; + + game_do_command(peep->x, flags, peep->y, w->number, GAME_COMMAND_SET_STAFF_ORDER, (int)peep, 0); +} + +/** rct2: 0x006BE7DB */ +void window_staff_peep_orders_mouseup() +{ + short widgetIndex; + rct_window* w; + window_widget_get_registers(w, widgetIndex); + + switch (widgetIndex) { + case WIDX_CLOSE: + window_close(w); + break; + case WIDX_TAB_1: + case WIDX_TAB_2: + case WIDX_TAB_3: + window_staff_peep_set_page(w, widgetIndex - WIDX_TAB_1); + break; + case WIDX_VIEWPORT: + case WIDX_BTM_LABEL: + case WIDX_PICKUP: + case WIDX_PATROL: + case WIDX_RENAME: + window_staff_peep_set_order(w, widgetIndex - 8); + break; + } +} + +/** rct2: 0x0006BEBCF */ +void window_staff_peep_stats_mouseup() +{ + short widgetIndex; + rct_window* w; + window_widget_get_registers(w, widgetIndex); + + switch (widgetIndex) { + case WIDX_CLOSE: + window_close(w); + break; + case WIDX_TAB_1: + case WIDX_TAB_2: + case WIDX_TAB_3: + window_staff_peep_set_page(w, widgetIndex - WIDX_TAB_1); + break; + } } \ No newline at end of file From 5c44a07aac9d1f985c74813ec66fc4a72d34df2e Mon Sep 17 00:00:00 2001 From: zsilencer Date: Thu, 28 Aug 2014 17:36:52 -0600 Subject: [PATCH 35/58] sub_405383 --- src/audio.c | 177 +++++++++++++++++++++++++++++++++++----------------- src/audio.h | 113 +++++---------------------------- 2 files changed, 134 insertions(+), 156 deletions(-) diff --git a/src/audio.c b/src/audio.c index 0299246ac7..2683c80652 100644 --- a/src/audio.c +++ b/src/audio.c @@ -338,14 +338,77 @@ int map_sound_info(const char* filename) } } +/** +* +* rct2: 0x00405383 +*/ +MMRESULT sub_405383(HMMIO hmmio, uint32 size, char* buffer, uint32* a4, int* read) +{ + MMIOINFO mmioinfo; + MMRESULT result; + result = mmioGetInfo(hmmio, &mmioinfo, 0); + if (result != 0) { + *read = 0; + return 1; + } + int size2 = size; + if (size > a4[1]) { + size2 = a4[1]; + } + int v8 = 0; + a4[1] -= size2; + if (size2) { + while (1) { + HPSTR p = mmioinfo.pchEndRead; + if (mmioinfo.pchNext == mmioinfo.pchEndRead) { + result = mmioAdvance(hmmio, &mmioinfo, 0); + if (result != 0) { + *read = 0; + return result; + } + p = mmioinfo.pchEndRead; + if (mmioinfo.pchNext == mmioinfo.pchEndRead) { + break; + } + } + int q = p - mmioinfo.pchNext; + if (size2 - v8 < p - mmioinfo.pchNext) { + q = size2 - v8; + } + memcpy(&buffer[v8], mmioinfo.pchNext, q); + mmioinfo.pchNext += q; + v8 += q; + if (v8 >= size2) { + result = mmioSetInfo(hmmio, &mmioinfo, 0); + if (result != 0) { + *read = 0; + return result; + } else { + *read = size2; + return result; + } + } + } + *read = 0; + return 57603; + } + result = mmioSetInfo(hmmio, &mmioinfo, 0); + if (result != 0) { + *read = 0; + return result; + } else { + *read = size2; + return result; + } +} + /** * * rct2: 0x00401000 */ void sub_401000(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2, int channel) { - //RCT2_CALLFUNC_6(0x00401000, void, UINT, UINT, DWORD_PTR, DWORD_PTR, DWORD_PTR, int, uTimerID, uMsg, dwUser, dw1, dw2, channel); - rct_sound_unknown* unknown = &RCT2_ADDRESS(0x014262E0, rct_sound_unknown)[channel]; + rct_sound_channel* soundchannel = &RCT2_ADDRESS(0x014262E0, rct_sound_channel)[channel]; DWORD status; DWORD dwCurrentPlayCursor; DWORD dwCurrentWriteCursor; @@ -356,67 +419,67 @@ void sub_401000(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD int buf1size; char* buf2; int buf2size; - unknown->dsbuffer->lpVtbl->GetStatus(unknown->dsbuffer, &status); + soundchannel->dsbuffer->lpVtbl->GetStatus(soundchannel->dsbuffer, &status); if (status & DSBSTATUS_BUFFERLOST) { - if (FAILED(unknown->dsbuffer->lpVtbl->Restore(unknown->dsbuffer))) { + if (FAILED(soundchannel->dsbuffer->lpVtbl->Restore(soundchannel->dsbuffer))) { return; } - unknown->playpos = 0; + soundchannel->playpos = 0; bufferlost = 1; } - unknown->dsbuffer->lpVtbl->GetCurrentPosition(unknown->dsbuffer, &dwCurrentPlayCursor, &dwCurrentWriteCursor); - if (dwCurrentPlayCursor != unknown->playpos || bufferlost) { - if (unknown->var_168 && !unknown->var_15C) { - if (!unknown->var_160) { - unknown->var_160 = 1; - if (!unknown->var_4) { + soundchannel->dsbuffer->lpVtbl->GetCurrentPosition(soundchannel->dsbuffer, &dwCurrentPlayCursor, &dwCurrentWriteCursor); + if (dwCurrentPlayCursor != soundchannel->playpos || bufferlost) { + if (soundchannel->var_168 && !soundchannel->var_15C) { + if (!soundchannel->var_160) { + soundchannel->var_160 = 1; + if (!soundchannel->var_4) { LPDIRECTSOUNDBUFFER dsbuffer = RCT2_ADDRESS(RCT2_ADDRESS_DSOUND_BUFFERS, LPDIRECTSOUNDBUFFER)[channel]; - unknown->var_0 = 0; + soundchannel->var_0 = 0; if (dsbuffer) { dsbuffer->lpVtbl->Stop(dsbuffer); dsbuffer->lpVtbl->Release(dsbuffer); RCT2_ADDRESS(RCT2_ADDRESS_DSOUND_BUFFERS, LPDIRECTSOUNDBUFFER)[channel] = 0; } - if (unknown->var_120) { - sound_channel_free(&unknown->var_120, &unknown->var_11C); + if (soundchannel->hmmio) { + sound_channel_free(&soundchannel->hmmio, &soundchannel->hmem); } } } return; } - if (dwCurrentPlayCursor >= unknown->playpos) { - var1 = dwCurrentPlayCursor - unknown->playpos; + if (dwCurrentPlayCursor >= soundchannel->playpos) { + var1 = dwCurrentPlayCursor - soundchannel->playpos; } else { - var1 = dwCurrentPlayCursor + unknown->var_150 - unknown->playpos; + var1 = dwCurrentPlayCursor + soundchannel->var_150 - soundchannel->playpos; } if (bufferlost) { - var2 = 2 * unknown->var_150 / 6; + var2 = 2 * soundchannel->var_150 / 6; } else { var2 = var1; } - unknown->var_158 += var1; - if (unknown->var_168) { - int var3 = unknown->var_15C; - int* var4 = &unknown->var_15C; + soundchannel->var_158 += var1; + if (soundchannel->var_168) { + int var3 = soundchannel->var_15C; + int* var4 = &soundchannel->var_15C; if (var3) { if (var1 <= var3) { *var4 = var3 - var1; } else { *var4 = 0; } - if (SUCCEEDED(unknown->dsbuffer->lpVtbl->Lock(unknown->dsbuffer, unknown->playpos, var2, &buf1, &buf1size, &buf2, &buf2size, 0))) { - char var5 = -(((char*)unknown->var_11C + 14) != (char *)8); + if (SUCCEEDED(soundchannel->dsbuffer->lpVtbl->Lock(soundchannel->dsbuffer, soundchannel->playpos, var2, &buf1, &buf1size, &buf2, &buf2size, 0))) { + uint16 var5 = -(soundchannel->var_128 != 8); var5 &= 0x80; memset(buf1, var5 + 128, buf1size); if (buf2 && buf2size) { - char var5 = -(((char*)unknown->var_11C + 14) != (char *)8); + uint16 var5 = -(soundchannel->var_128 != 8); var5 &= 0x80; memset(buf2, var5 + 128, buf2size); } - unknown->dsbuffer->lpVtbl->Unlock(unknown->dsbuffer, buf1, buf1size, buf2, buf2size); - unknown->playpos += var2; - if( unknown->playpos >= unknown->var_150) { - unknown->playpos = unknown->playpos - unknown->var_150; + soundchannel->dsbuffer->lpVtbl->Unlock(soundchannel->dsbuffer, buf1, buf1size, buf2, buf2size); + soundchannel->playpos += var2; + if( soundchannel->playpos >= soundchannel->var_150) { + soundchannel->playpos = soundchannel->playpos - soundchannel->var_150; } return; } @@ -424,23 +487,23 @@ void sub_401000(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD return; } } - if (FAILED(unknown->dsbuffer->lpVtbl->Lock(unknown->dsbuffer, unknown->playpos, var2, &buf1, &buf1size, &buf2, &buf2size, 0))) { + if (FAILED(soundchannel->dsbuffer->lpVtbl->Lock(soundchannel->dsbuffer, soundchannel->playpos, var2, &buf1, &buf1size, &buf2, &buf2size, 0))) { // TimeFunc() could not lock DirectSoundBuffer return; } if (buf1size) { - if (unknown->var_160) { - int var5 = -(((char*)unknown->var_11C + 14) != (char *)8); + if (soundchannel->var_160) { + uint16 var5 = -(soundchannel->var_128 != 8); var5 &= 0x80; memset(buf1, var5 + 128, buf1size); goto label49; } } int var7; - RCT2_CALLFUNC_5(0x00405383, int, HMMIO, int, char*, int*, int*, unknown->var_120, buf1size, buf1, &unknown->var_124, &var7); + sub_405383(soundchannel->hmmio, buf1size, buf1, &soundchannel->var_124, &var7); if (var7 < buf1size) { - if (!unknown->var_164) { - int s = *(char*)((char*)unknown->var_11C + 14); + if (!soundchannel->var_164) { + int s = soundchannel->var_128; int t = buf1size - var7; int v; if (s == 8) { @@ -453,11 +516,11 @@ void sub_401000(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD } memset(&buf1[var7], v, t); label42: - unknown->var_168 = 1; - if (dwCurrentPlayCursor <= unknown->playpos) { - unknown->var_15C = unknown->playpos - dwCurrentPlayCursor; + soundchannel->var_168 = 1; + if (dwCurrentPlayCursor <= soundchannel->playpos) { + soundchannel->var_15C = soundchannel->playpos - dwCurrentPlayCursor; } else { - unknown->var_15C = unknown->playpos + unknown->var_150 - dwCurrentPlayCursor; + soundchannel->var_15C = soundchannel->playpos + soundchannel->var_150 - dwCurrentPlayCursor; } goto label49; } @@ -467,59 +530,59 @@ void sub_401000(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD v38 -= var7; v21 += var7; RCT2_CALLFUNC_1(0x0040153B, int, int, channel); - RCT2_CALLFUNC_5(0x00405383, int, HMMIO, int, char*, int*, int*, unknown->var_120, v38, v21, &unknown->var_124, &var7); + sub_405383(soundchannel->hmmio, v38, v21, &soundchannel->var_124, &var7); } while(var7 < v38); } label49: - if (buf2size == 0 || unknown->var_160 != 0) { - if(buf2 != 0 && buf2size != 0 && unknown->var_160 != 0) { - int var5 = -(*(char*)((char*)unknown->var_11C + 14) != 8); + if (buf2size == 0 || soundchannel->var_160 != 0) { + if(buf2 != 0 && buf2size != 0 && soundchannel->var_160 != 0) { + int var5 = -(soundchannel->var_128 != 8); var5 &= 0x80; memset(buf2, var5 + 128, buf2size); } goto label68; } - RCT2_CALLFUNC_5(0x00405383, int, HMMIO, int, char*, int*, int*, unknown->var_120, buf2size, buf2, &unknown->var_124, &var7); + sub_405383(soundchannel->hmmio, buf2size, buf2, &soundchannel->var_124, &var7); if (var7 >= buf2size) { label68: - unknown->dsbuffer->lpVtbl->Unlock(unknown->dsbuffer, buf1, buf1size, buf2, buf2size); - unknown->playpos += var2; - if( unknown->playpos >= unknown->var_150 ) { - unknown->playpos -= unknown->var_150; + soundchannel->dsbuffer->lpVtbl->Unlock(soundchannel->dsbuffer, buf1, buf1size, buf2, buf2size); + soundchannel->playpos += var2; + if (soundchannel->playpos >= soundchannel->var_150) { + soundchannel->playpos -= soundchannel->var_150; } if (bufferlost != 0) { - unknown->dsbuffer->lpVtbl->Play(unknown->dsbuffer, 0, 0, DSBPLAY_LOOPING); + soundchannel->dsbuffer->lpVtbl->Play(soundchannel->dsbuffer, 0, 0, DSBPLAY_LOOPING); } return; } - if (unknown->var_164 != 0) { + if (soundchannel->var_164 != 0) { char* v26 = buf2; int v27 = buf2size; do { v26 += var7; v27 -= var7; RCT2_CALLFUNC_1(0x0040153B, int, int, channel); - RCT2_CALLFUNC_5(0x00405383, int, HMMIO, int, char*, int*, int*, unknown->var_120, v27, v26, &unknown->var_124, &var7); + sub_405383(soundchannel->hmmio, v27, v26, &soundchannel->var_124, &var7); } while(var7 < v27); goto label68; } int s = buf2size - var7; int v; - if (unknown->var_11C == (HGLOBAL)8) { + if (soundchannel->hmem == (HGLOBAL)8) { v = 128; } else { - if (unknown->var_11C != (HGLOBAL)16) { + if (soundchannel->hmem != (HGLOBAL)16) { goto label58; } v = 0; } memset(&buf2[var7], v, s); label58: - unknown->var_168 = 1; - if (dwCurrentPlayCursor <= unknown->playpos) { - unknown->var_15C = unknown->playpos - dwCurrentPlayCursor; + soundchannel->var_168 = 1; + if (dwCurrentPlayCursor <= soundchannel->playpos) { + soundchannel->var_15C = soundchannel->playpos - dwCurrentPlayCursor; } else { - unknown->var_15C = unknown->playpos + unknown->var_150 - dwCurrentPlayCursor; + soundchannel->var_15C = soundchannel->playpos + soundchannel->var_150 - dwCurrentPlayCursor; } goto label68; } diff --git a/src/audio.h b/src/audio.h index b630ba92ce..625e40591e 100644 --- a/src/audio.h +++ b/src/audio.h @@ -69,10 +69,20 @@ typedef struct { typedef struct { uint32 var_0; - uint8 pad_4[0x118]; - HMMIO hmmio; - HGLOBAL hmem; - uint8 pad_124[0x3C]; + uint32 var_4; + uint8 pad_8[0x114]; + HGLOBAL hmem; // 0x11C + HMMIO hmmio; // 0x120 + uint32 var_124; + uint32 var_128; + uint32 var_12C; + uint32 var_130; + uint8 pad_134[0x18]; + LPDIRECTSOUNDBUFFER dsbuffer; // 0x14C + uint32 var_150; + uint32 playpos; // 0x154 + uint32 var_158; + uint32 var_15C; uint32 var_160; uint32 var_164; uint32 var_168; @@ -100,101 +110,6 @@ typedef struct { rct_sound sound; } rct_other_sound; -typedef struct { - uint32 var_0; - uint32 var_4; - uint32 var_8; - uint16 var_C; - uint16 var_E; - uint32 var_10; - uint32 var_14; - uint32 var_18; - uint32 var_1C; - uint32 var_20; - uint32 var_24; - uint32 var_28; - uint32 var_2C; - uint32 var_30; - uint32 var_34; - uint32 var_38; - uint32 var_3C; - uint32 var_40; - uint32 var_44; - uint32 var_48; - uint32 var_4C; - uint32 var_50; - uint32 var_54; - uint32 var_58; - uint32 var_5C; - uint32 var_60; - uint32 var_64; - uint32 var_68; - uint32 var_6C; - uint32 var_70; - uint32 var_74; - uint32 var_78; - uint32 var_7C; - uint32 var_80; - uint32 var_84; - uint32 var_88; - uint32 var_8C; - uint32 var_90; - uint32 var_94; - uint32 var_98; - uint32 var_9C; - uint32 var_A0; - uint32 var_A4; - uint32 var_A8; - uint32 var_AC; - uint32 var_B0; - uint32 var_B4; - uint32 var_B8; - uint32 var_BC; - uint32 var_C0; - uint32 var_C4; - uint32 var_C8; - uint32 var_CC; - uint32 var_D0; - uint32 var_D4; - uint32 var_D8; - uint32 var_DC; - uint32 var_E0; - uint32 var_E4; - uint32 var_E8; - uint32 var_EC; - uint32 var_F0; - uint32 var_F4; - uint32 var_F8; - uint32 var_FC; - uint32 var_100; - uint32 var_104; - uint32 var_108; - uint32 var_10C; - uint32 var_110; - uint32 var_114; - uint32 var_118; - HGLOBAL var_11C; - HMMIO var_120; - uint32 var_124; - uint32 var_128; - uint32 var_12C; - uint32 var_130; - uint32 var_134; - uint32 var_138; - uint32 var_13C; - uint32 var_140; - uint32 var_144; - uint32 var_148; - LPDIRECTSOUNDBUFFER dsbuffer; // 0x14C - uint32 var_150; - uint32 playpos; // 0x154 - uint32 var_158; - uint32 var_15C; - uint32 var_160; - uint32 var_164; - uint32 var_168; -} rct_sound_unknown; - int get_dsound_devices(); int sound_prepare(int sound_id, rct_sound *sound, int channels, int software); int sound_play_panned(int sound_id, int x); From 0496312cab05c4c777ebf0194842d6d4e44ab269 Mon Sep 17 00:00:00 2001 From: zsilencer Date: Thu, 28 Aug 2014 21:47:35 -0600 Subject: [PATCH 36/58] 0x0040153, 0x0040182 --- src/audio.c | 183 +++++++++++++++++++++++++++++++++++----------------- src/audio.h | 13 ++-- 2 files changed, 130 insertions(+), 66 deletions(-) diff --git a/src/audio.c b/src/audio.c index 7ebe1bb41d..b5d7adf004 100644 --- a/src/audio.c +++ b/src/audio.c @@ -187,6 +187,18 @@ int sound_load3dparameters() return 0; } +/** +* +* rct2: 0x00404F3F +*/ +int sound_load3dposition() +{ + if (SUCCEEDED(RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER)->lpVtbl->GetPosition(RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER), &RCT2_GLOBAL(0x009A6084, DS3DBUFFER), 1))) { + return 1; + } + return 0; +} + /** * * rct2: 0x00404932 @@ -240,7 +252,7 @@ int dsound_create_primary_buffer(int a, int device, int channels, int samples, i RCT2_GLOBAL(0x009A6084, DS3DBUFFER).vPosition.x = -1.0f; RCT2_GLOBAL(0x009A6084, DS3DBUFFER).flMaxDistance = 9.8999996f; RCT2_GLOBAL(0x009A6084, DS3DBUFFER).flMinDistance = 0.25f; - if (RCT2_CALLFUNC(0x00404F3F, int)) { + if (sound_load3dposition()) { if (SUCCEEDED(RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER)->lpVtbl->SetMinDistance(RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER), RCT2_GLOBAL(0x009A6084, DS3DBUFFER).flMinDistance, 1))) { if (sound_load3dparameters()) { return 1; @@ -402,13 +414,64 @@ MMRESULT sub_405383(HMMIO hmmio, uint32 size, char* buffer, uint32* a4, int* rea } } +/** +* +* rct2: 0x00401822 +*/ +int sub_401822(int channel, HMMIO hmmio, LONG offset) +{ + rct_sound_channel* sound_channel = &RCT2_ADDRESS(0x014262E0, rct_sound_channel)[channel]; + LPMMCKINFO v4 = &sound_channel->mmckinfo2; + HMMIO* v5 = &sound_channel->hmmio; + if (RCT2_CALLFUNC_4(0x00405222, int, HMMIO, HMMIO*, HGLOBAL*, LPMMCKINFO, hmmio, &sound_channel->hmmio, &sound_channel->hmem, &sound_channel->mmckinfo2)) { + return -100; + } + if (*(uint16*)sound_channel->hmem != 1) { + sound_channel_free(&sound_channel->hmmio, &sound_channel->hmem); + return -101; + } + if (RCT2_CALLFUNC_4(0x00405465, int, HMMIO*, LPMMCKINFO, LPMMCKINFO, int, &sound_channel->hmmio, &sound_channel->mmckinfo1, &sound_channel->mmckinfo2, offset)) { + sound_channel_free(&sound_channel->hmmio, &sound_channel->hmem); + return -103; + } + sound_channel->var_158 = offset; + return 0; +} + +/** +* +* rct2: 0x0040153B +*/ +int sub_40153B(int channel) +{ + rct_sound_channel* sound_channel = &RCT2_ADDRESS(0x014262E0, rct_sound_channel)[channel]; + if (sound_channel->var_4) { + if (sound_channel->hmmio) { + sound_channel_free(sound_channel->hmmio, sound_channel->hmem); + } + if (sub_401822(channel, &sound_channel->var_8, sound_channel->var_110)) { + return 0; + } + sound_channel->var_164 = sound_channel->var_114; + sound_channel->var_118 = sound_channel->var_110; + sound_channel->var_4 = 0; + } else { + int result = RCT2_CALLFUNC_4(0x00405465, int, HMMIO*, LPMMCKINFO, LPMMCKINFO, int, &sound_channel->hmmio, &sound_channel->mmckinfo1, &sound_channel->mmckinfo2, sound_channel->var_118); + sound_channel->var_158 = sound_channel->var_118; + if (result) { + return 0; + } + } + return 1; +} + /** * * rct2: 0x00401000 */ void sub_401000(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2, int channel) { - rct_sound_channel* soundchannel = &RCT2_ADDRESS(0x014262E0, rct_sound_channel)[channel]; + rct_sound_channel* sound_channel = &RCT2_ADDRESS(0x014262E0, rct_sound_channel)[channel]; DWORD status; DWORD dwCurrentPlayCursor; DWORD dwCurrentWriteCursor; @@ -419,67 +482,67 @@ void sub_401000(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD int buf1size; char* buf2; int buf2size; - soundchannel->dsbuffer->lpVtbl->GetStatus(soundchannel->dsbuffer, &status); + sound_channel->dsbuffer->lpVtbl->GetStatus(sound_channel->dsbuffer, &status); if (status & DSBSTATUS_BUFFERLOST) { - if (FAILED(soundchannel->dsbuffer->lpVtbl->Restore(soundchannel->dsbuffer))) { + if (FAILED(sound_channel->dsbuffer->lpVtbl->Restore(sound_channel->dsbuffer))) { return; } - soundchannel->playpos = 0; + sound_channel->playpos = 0; bufferlost = 1; } - soundchannel->dsbuffer->lpVtbl->GetCurrentPosition(soundchannel->dsbuffer, &dwCurrentPlayCursor, &dwCurrentWriteCursor); - if (dwCurrentPlayCursor != soundchannel->playpos || bufferlost) { - if (soundchannel->var_168 && !soundchannel->var_15C) { - if (!soundchannel->var_160) { - soundchannel->var_160 = 1; - if (!soundchannel->var_4) { + sound_channel->dsbuffer->lpVtbl->GetCurrentPosition(sound_channel->dsbuffer, &dwCurrentPlayCursor, &dwCurrentWriteCursor); + if (dwCurrentPlayCursor != sound_channel->playpos || bufferlost) { + if (sound_channel->var_168 && !sound_channel->var_15C) { + if (!sound_channel->var_160) { + sound_channel->var_160 = 1; + if (!sound_channel->var_4) { LPDIRECTSOUNDBUFFER dsbuffer = RCT2_ADDRESS(RCT2_ADDRESS_DSOUND_BUFFERS, LPDIRECTSOUNDBUFFER)[channel]; - soundchannel->var_0 = 0; + sound_channel->var_0 = 0; if (dsbuffer) { dsbuffer->lpVtbl->Stop(dsbuffer); dsbuffer->lpVtbl->Release(dsbuffer); RCT2_ADDRESS(RCT2_ADDRESS_DSOUND_BUFFERS, LPDIRECTSOUNDBUFFER)[channel] = 0; } - if (soundchannel->hmmio) { - sound_channel_free(&soundchannel->hmmio, &soundchannel->hmem); + if (sound_channel->hmmio) { + sound_channel_free(&sound_channel->hmmio, &sound_channel->hmem); } } } return; } - if (dwCurrentPlayCursor >= soundchannel->playpos) { - var1 = dwCurrentPlayCursor - soundchannel->playpos; + if (dwCurrentPlayCursor >= sound_channel->playpos) { + var1 = dwCurrentPlayCursor - sound_channel->playpos; } else { - var1 = dwCurrentPlayCursor + soundchannel->var_150 - soundchannel->playpos; + var1 = dwCurrentPlayCursor + sound_channel->var_150 - sound_channel->playpos; } if (bufferlost) { - var2 = 2 * soundchannel->var_150 / 6; + var2 = 2 * sound_channel->var_150 / 6; } else { var2 = var1; } - soundchannel->var_158 += var1; - if (soundchannel->var_168) { - int var3 = soundchannel->var_15C; - int* var4 = &soundchannel->var_15C; + sound_channel->var_158 += var1; + if (sound_channel->var_168) { + int var3 = sound_channel->var_15C; + int* var4 = &sound_channel->var_15C; if (var3) { if (var1 <= var3) { *var4 = var3 - var1; } else { *var4 = 0; } - if (SUCCEEDED(soundchannel->dsbuffer->lpVtbl->Lock(soundchannel->dsbuffer, soundchannel->playpos, var2, &buf1, &buf1size, &buf2, &buf2size, 0))) { - uint16 var5 = -(soundchannel->var_128 != 8); + if (SUCCEEDED(sound_channel->dsbuffer->lpVtbl->Lock(sound_channel->dsbuffer, sound_channel->playpos, var2, (LPVOID*)&buf1, (LPDWORD)&buf1size, (LPVOID*)&buf2, &buf2size, 0))) { + uint16 var5 = -(sound_channel->mmckinfo1.cksize != 8); var5 &= 0x80; memset(buf1, var5 + 128, buf1size); if (buf2 && buf2size) { - uint16 var5 = -(soundchannel->var_128 != 8); + uint16 var5 = -(sound_channel->mmckinfo1.cksize != 8); var5 &= 0x80; memset(buf2, var5 + 128, buf2size); } - soundchannel->dsbuffer->lpVtbl->Unlock(soundchannel->dsbuffer, buf1, buf1size, buf2, buf2size); - soundchannel->playpos += var2; - if( soundchannel->playpos >= soundchannel->var_150) { - soundchannel->playpos = soundchannel->playpos - soundchannel->var_150; + sound_channel->dsbuffer->lpVtbl->Unlock(sound_channel->dsbuffer, buf1, buf1size, buf2, buf2size); + sound_channel->playpos += var2; + if (sound_channel->playpos >= sound_channel->var_150) { + sound_channel->playpos = sound_channel->playpos - sound_channel->var_150; } return; } @@ -487,23 +550,23 @@ void sub_401000(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD return; } } - if (FAILED(soundchannel->dsbuffer->lpVtbl->Lock(soundchannel->dsbuffer, soundchannel->playpos, var2, &buf1, &buf1size, &buf2, &buf2size, 0))) { + if (FAILED(sound_channel->dsbuffer->lpVtbl->Lock(sound_channel->dsbuffer, sound_channel->playpos, var2, (LPVOID*)&buf1, (LPDWORD)&buf1size, (LPVOID*)&buf2, &buf2size, 0))) { // TimeFunc() could not lock DirectSoundBuffer return; } if (buf1size) { - if (soundchannel->var_160) { - uint16 var5 = -(soundchannel->var_128 != 8); + if (sound_channel->var_160) { + uint16 var5 = -(sound_channel->mmckinfo1.cksize != 8); var5 &= 0x80; memset(buf1, var5 + 128, buf1size); goto label49; } } int var7; - sub_405383(soundchannel->hmmio, buf1size, buf1, &soundchannel->var_124, &var7); + sub_405383(sound_channel->hmmio, buf1size, buf1, &sound_channel->mmckinfo1, &var7); if (var7 < buf1size) { - if (!soundchannel->var_164) { - int s = soundchannel->var_128; + if (!sound_channel->var_164) { + int s = sound_channel->mmckinfo1.cksize; int t = buf1size - var7; int v; if (s == 8) { @@ -516,11 +579,11 @@ void sub_401000(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD } memset(&buf1[var7], v, t); label42: - soundchannel->var_168 = 1; - if (dwCurrentPlayCursor <= soundchannel->playpos) { - soundchannel->var_15C = soundchannel->playpos - dwCurrentPlayCursor; + sound_channel->var_168 = 1; + if (dwCurrentPlayCursor <= sound_channel->playpos) { + sound_channel->var_15C = sound_channel->playpos - dwCurrentPlayCursor; } else { - soundchannel->var_15C = soundchannel->playpos + soundchannel->var_150 - dwCurrentPlayCursor; + sound_channel->var_15C = sound_channel->playpos + sound_channel->var_150 - dwCurrentPlayCursor; } goto label49; } @@ -529,60 +592,60 @@ void sub_401000(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD do { v38 -= var7; v21 += var7; - RCT2_CALLFUNC_1(0x0040153B, int, int, channel); - sub_405383(soundchannel->hmmio, v38, v21, &soundchannel->var_124, &var7); + sub_40153B(channel);//RCT2_CALLFUNC_1(0x0040153B, int, int, channel); + sub_405383(sound_channel->hmmio, v38, v21, &sound_channel->mmckinfo1, &var7); } while(var7 < v38); } label49: - if (buf2size == 0 || soundchannel->var_160 != 0) { - if(buf2 != 0 && buf2size != 0 && soundchannel->var_160 != 0) { - int var5 = -(soundchannel->var_128 != 8); + if (buf2size == 0 || sound_channel->var_160 != 0) { + if(buf2 != 0 && buf2size != 0 && sound_channel->var_160 != 0) { + int var5 = -(sound_channel->mmckinfo1.cksize != 8); var5 &= 0x80; memset(buf2, var5 + 128, buf2size); } goto label68; } - sub_405383(soundchannel->hmmio, buf2size, buf2, &soundchannel->var_124, &var7); + sub_405383(sound_channel->hmmio, buf2size, buf2, &sound_channel->mmckinfo1, &var7); if (var7 >= buf2size) { label68: - soundchannel->dsbuffer->lpVtbl->Unlock(soundchannel->dsbuffer, buf1, buf1size, buf2, buf2size); - soundchannel->playpos += var2; - if (soundchannel->playpos >= soundchannel->var_150) { - soundchannel->playpos -= soundchannel->var_150; + sound_channel->dsbuffer->lpVtbl->Unlock(sound_channel->dsbuffer, buf1, buf1size, buf2, buf2size); + sound_channel->playpos += var2; + if (sound_channel->playpos >= sound_channel->var_150) { + sound_channel->playpos -= sound_channel->var_150; } if (bufferlost != 0) { - soundchannel->dsbuffer->lpVtbl->Play(soundchannel->dsbuffer, 0, 0, DSBPLAY_LOOPING); + sound_channel->dsbuffer->lpVtbl->Play(sound_channel->dsbuffer, 0, 0, DSBPLAY_LOOPING); } return; } - if (soundchannel->var_164 != 0) { + if (sound_channel->var_164 != 0) { char* v26 = buf2; int v27 = buf2size; do { v26 += var7; v27 -= var7; - RCT2_CALLFUNC_1(0x0040153B, int, int, channel); - sub_405383(soundchannel->hmmio, v27, v26, &soundchannel->var_124, &var7); + sub_40153B(channel);//RCT2_CALLFUNC_1(0x0040153B, int, int, channel); + sub_405383(sound_channel->hmmio, v27, v26, &sound_channel->mmckinfo1, &var7); } while(var7 < v27); goto label68; } int s = buf2size - var7; int v; - if (soundchannel->hmem == (HGLOBAL)8) { + if (sound_channel->hmem == (HGLOBAL)8) { v = 128; } else { - if (soundchannel->hmem != (HGLOBAL)16) { + if (sound_channel->hmem != (HGLOBAL)16) { goto label58; } v = 0; } memset(&buf2[var7], v, s); label58: - soundchannel->var_168 = 1; - if (dwCurrentPlayCursor <= soundchannel->playpos) { - soundchannel->var_15C = soundchannel->playpos - dwCurrentPlayCursor; + sound_channel->var_168 = 1; + if (dwCurrentPlayCursor <= sound_channel->playpos) { + sound_channel->var_15C = sound_channel->playpos - dwCurrentPlayCursor; } else { - soundchannel->var_15C = soundchannel->playpos + soundchannel->var_150 - dwCurrentPlayCursor; + sound_channel->var_15C = sound_channel->playpos + sound_channel->var_150 - dwCurrentPlayCursor; } goto label68; } @@ -1288,7 +1351,7 @@ int sound_channel_stop(int channel) while (_InterlockedExchange(&RCT2_GLOBAL(0x009E1AAC, LONG), 1) != 1) { Sleep(10); } - if (sound_channel->hmem) { + if (sound_channel->hmmio) { sound_channel_free(&sound_channel->hmmio, &sound_channel->hmem); } diff --git a/src/audio.h b/src/audio.h index 625e40591e..2848af7840 100644 --- a/src/audio.h +++ b/src/audio.h @@ -70,14 +70,15 @@ typedef struct { typedef struct { uint32 var_0; uint32 var_4; - uint8 pad_8[0x114]; + uint32 var_8; + uint8 pad_C[0x104]; + uint32 var_110; + uint32 var_114; + uint32 var_118; HGLOBAL hmem; // 0x11C HMMIO hmmio; // 0x120 - uint32 var_124; - uint32 var_128; - uint32 var_12C; - uint32 var_130; - uint8 pad_134[0x18]; + MMCKINFO mmckinfo1; // 0x124 + MMCKINFO mmckinfo2; // 0x138 LPDIRECTSOUNDBUFFER dsbuffer; // 0x14C uint32 var_150; uint32 playpos; // 0x154 From f0ce2dcb1a519fe434043fc6f4225131efc14b4f Mon Sep 17 00:00:00 2001 From: zsilencer Date: Thu, 28 Aug 2014 22:02:05 -0600 Subject: [PATCH 37/58] test --- src/audio.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/audio.c b/src/audio.c index b5d7adf004..0b89bc68d3 100644 --- a/src/audio.c +++ b/src/audio.c @@ -193,9 +193,9 @@ 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, DS3DBUFFER), 1))) { return 1; - } + }*/ return 0; } @@ -354,7 +354,7 @@ int map_sound_info(const char* filename) * * rct2: 0x00405383 */ -MMRESULT sub_405383(HMMIO hmmio, uint32 size, char* buffer, uint32* a4, int* read) +MMRESULT sub_405383(HMMIO hmmio, uint32 size, char* buffer, LPMMCKINFO a4, int* read) { MMIOINFO mmioinfo; MMRESULT result; @@ -364,11 +364,11 @@ MMRESULT sub_405383(HMMIO hmmio, uint32 size, char* buffer, uint32* a4, int* rea return 1; } int size2 = size; - if (size > a4[1]) { - size2 = a4[1]; + if (size > a4->cksize) { + size2 = a4->cksize; } int v8 = 0; - a4[1] -= size2; + a4->cksize -= size2; if (size2) { while (1) { HPSTR p = mmioinfo.pchEndRead; @@ -418,12 +418,12 @@ MMRESULT sub_405383(HMMIO hmmio, uint32 size, char* buffer, uint32* a4, int* rea * * rct2: 0x00401822 */ -int sub_401822(int channel, HMMIO hmmio, LONG offset) +int sub_401822(int channel, HMMIO* hmmio, LONG offset) { rct_sound_channel* sound_channel = &RCT2_ADDRESS(0x014262E0, rct_sound_channel)[channel]; LPMMCKINFO v4 = &sound_channel->mmckinfo2; HMMIO* v5 = &sound_channel->hmmio; - if (RCT2_CALLFUNC_4(0x00405222, int, HMMIO, HMMIO*, HGLOBAL*, LPMMCKINFO, hmmio, &sound_channel->hmmio, &sound_channel->hmem, &sound_channel->mmckinfo2)) { + if (RCT2_CALLFUNC_4(0x00405222, int, HMMIO*, HMMIO*, HGLOBAL*, LPMMCKINFO, hmmio, &sound_channel->hmmio, &sound_channel->hmem, &sound_channel->mmckinfo2)) { return -100; } if (*(uint16*)sound_channel->hmem != 1) { @@ -447,9 +447,9 @@ int sub_40153B(int channel) rct_sound_channel* sound_channel = &RCT2_ADDRESS(0x014262E0, rct_sound_channel)[channel]; if (sound_channel->var_4) { if (sound_channel->hmmio) { - sound_channel_free(sound_channel->hmmio, sound_channel->hmem); + sound_channel_free(&sound_channel->hmmio, &sound_channel->hmem); } - if (sub_401822(channel, &sound_channel->var_8, sound_channel->var_110)) { + if (sub_401822(channel, (HMMIO*)&sound_channel->var_8, sound_channel->var_110)) { return 0; } sound_channel->var_164 = sound_channel->var_114; @@ -475,7 +475,7 @@ void sub_401000(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD DWORD status; DWORD dwCurrentPlayCursor; DWORD dwCurrentWriteCursor; - int var1; + uint32 var1; int var2; int bufferlost = 0; char* buf1; @@ -522,15 +522,15 @@ void sub_401000(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD } sound_channel->var_158 += var1; if (sound_channel->var_168) { - int var3 = sound_channel->var_15C; - int* var4 = &sound_channel->var_15C; + uint32 var3 = sound_channel->var_15C; + uint32* var4 = &sound_channel->var_15C; if (var3) { if (var1 <= var3) { *var4 = var3 - var1; } else { *var4 = 0; } - if (SUCCEEDED(sound_channel->dsbuffer->lpVtbl->Lock(sound_channel->dsbuffer, sound_channel->playpos, var2, (LPVOID*)&buf1, (LPDWORD)&buf1size, (LPVOID*)&buf2, &buf2size, 0))) { + if (SUCCEEDED(sound_channel->dsbuffer->lpVtbl->Lock(sound_channel->dsbuffer, sound_channel->playpos, var2, (LPVOID*)&buf1, (LPDWORD)&buf1size, (LPVOID*)&buf2, (LPDWORD)&buf2size, 0))) { uint16 var5 = -(sound_channel->mmckinfo1.cksize != 8); var5 &= 0x80; memset(buf1, var5 + 128, buf1size); From a2324a278dc5eeef81d70d0ea9984dabf08a00be Mon Sep 17 00:00:00 2001 From: Jackson Davis Date: Thu, 28 Aug 2014 15:11:28 +0100 Subject: [PATCH 38/58] First pass at 0x407074 (mouse read) --- src/input.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/input.c b/src/input.c index 1d10cc4e05..55cf373728 100644 --- a/src/input.c +++ b/src/input.c @@ -43,6 +43,7 @@ static void input_mouseover_widget_flatbutton_invalidate(); void process_mouse_over(int x, int y); void sub_6ED801(int x, int y); void invalidate_scroll(); +static void* sub_407074(); #pragma region Scroll bar input @@ -1557,9 +1558,8 @@ void game_handle_input() */ static void game_get_next_input(int *x, int *y, int *state) { - int eax, ebx, ecx, edx, esi, edi, ebp; - RCT2_CALLFUNC_X(0x00407074, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); - if (eax == 0) { + void* eax = sub_407074(); //RCT2_CALLFUNC_X(0x00407074, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + if (eax == NULL) { *x = gCursorState.x; *y = gCursorState.y; *state = 0; @@ -1762,4 +1762,19 @@ void invalidate_scroll() wind->scrolls[scroll_id / sizeof(rct_scroll)].flags &= 0xFF11; window_invalidate_by_id(RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWCLASS, uint8), RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWNUMBER, uint16)); -} \ No newline at end of file +} + +static void* sub_407074() +{ + int ecx = RCT2_GLOBAL(0x009E2DE8, uint32); + if (ecx != RCT2_GLOBAL(0x009E2DE4, uint32)) { + int eax = ecx + ecx*2; + ecx++; + ecx &= 0x3F; + eax = 0x1424340 + eax*4; + RCT2_GLOBAL(0x009E2DE8, uint32) = ecx; + return (void*)eax; + } else { + return NULL; + } +} From 57a2bc02febdc58055792cc7c415c08e8d65026f Mon Sep 17 00:00:00 2001 From: Jackson Davis Date: Fri, 29 Aug 2014 08:45:10 +0100 Subject: [PATCH 39/58] Add structs/addresses for mouse buffer functions --- src/addresses.h | 3 ++- src/input.c | 27 +++++++++++++-------------- src/osinterface.c | 39 ++++++++++++++++++--------------------- src/osinterface.h | 6 ++++++ 4 files changed, 39 insertions(+), 36 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index 80ef4cbe20..589dc5e69e 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -169,7 +169,8 @@ #define RCT2_ADDRESS_DSOUND_DEVICES_COUNTER 0x009E2BAC #define RCT2_ADDRESS_CMDLINE 0x009E2D98 - +#define RCT2_ADDRESS_MOUSE_READ_INDEX 0x009E2DE8 +#define RCT2_ADDRESS_MOUSE_WRITE_INDEX 0x009E2DE4 #define RCT2_ADDRESS_LAND_RAISE_COST 0x009E2E1C #define RCT2_ADDRESS_LAND_LOWER_COST 0x009E2E20 #define RCT2_ADDRESS_SELECTED_TERRAIN_EDGE 0x009E2E24 diff --git a/src/input.c b/src/input.c index 55cf373728..85e1102131 100644 --- a/src/input.c +++ b/src/input.c @@ -43,7 +43,7 @@ static void input_mouseover_widget_flatbutton_invalidate(); void process_mouse_over(int x, int y); void sub_6ED801(int x, int y); void invalidate_scroll(); -static void* sub_407074(); +static openrct2_mouse_data* get_mouse_input(); #pragma region Scroll bar input @@ -1558,7 +1558,7 @@ void game_handle_input() */ static void game_get_next_input(int *x, int *y, int *state) { - void* eax = sub_407074(); //RCT2_CALLFUNC_X(0x00407074, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + openrct2_mouse_data* eax = get_mouse_input(); if (eax == NULL) { *x = gCursorState.x; *y = gCursorState.y; @@ -1566,9 +1566,9 @@ static void game_get_next_input(int *x, int *y, int *state) return; } - *x = RCT2_GLOBAL(eax + 0, sint32); - *y = RCT2_GLOBAL(eax + 4, sint32); - *state = RCT2_GLOBAL(eax + 8, sint32); + *x = eax->x; + *y = eax->y; + *state = eax->state; //int eax, ebx, ecx, edx, esi, edi, ebp; //RCT2_CALLFUNC_X(0x006E83C7, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); @@ -1764,16 +1764,15 @@ void invalidate_scroll() window_invalidate_by_id(RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWCLASS, uint8), RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWNUMBER, uint16)); } -static void* sub_407074() +/** + * rct2: 0x00407074 + */ +static openrct2_mouse_data* get_mouse_input() { - int ecx = RCT2_GLOBAL(0x009E2DE8, uint32); - if (ecx != RCT2_GLOBAL(0x009E2DE4, uint32)) { - int eax = ecx + ecx*2; - ecx++; - ecx &= 0x3F; - eax = 0x1424340 + eax*4; - RCT2_GLOBAL(0x009E2DE8, uint32) = ecx; - return (void*)eax; + int read_index = RCT2_GLOBAL(RCT2_ADDRESS_MOUSE_READ_INDEX, uint32); + if (read_index != RCT2_GLOBAL(RCT2_ADDRESS_MOUSE_WRITE_INDEX, uint32)) { + RCT2_GLOBAL(RCT2_ADDRESS_MOUSE_READ_INDEX, uint32) = (read_index + 1) & 0x3F; + return &mouse_buffer[read_index]; } else { return NULL; } diff --git a/src/osinterface.c b/src/osinterface.c index 9213603e7d..73a7b25e6b 100644 --- a/src/osinterface.c +++ b/src/osinterface.c @@ -40,11 +40,12 @@ openrct2_cursor gCursorState; const unsigned char *gKeysState; unsigned char *gKeysPressed; unsigned int gLastKeyPressed; +openrct2_mouse_data* mouse_buffer = (openrct2_mouse_data*)0x1424340; static void osinterface_create_window(); static void osinterface_close_window(); static void osinterface_resize(int width, int height); -static void sub_406C96(int actionType); +static void store_mouse_input(int state); static SDL_Window *_window; static SDL_Surface *_surface; @@ -350,7 +351,7 @@ void osinterface_process_messages() RCT2_GLOBAL(0x0142431C, int) = e.button.y; switch (e.button.button) { case SDL_BUTTON_LEFT: - sub_406C96(1); //RCT2_CALLPROC_1(0x00406C96, int, 1); + store_mouse_input(1); gCursorState.left = CURSOR_PRESSED; gCursorState.old = 1; break; @@ -358,7 +359,7 @@ void osinterface_process_messages() gCursorState.middle = CURSOR_PRESSED; break; case SDL_BUTTON_RIGHT: - sub_406C96(3); //RCT2_CALLPROC_1(0x00406C96, int, 3); + store_mouse_input(3); gCursorState.right = CURSOR_PRESSED; gCursorState.old = 2; break; @@ -369,7 +370,7 @@ void osinterface_process_messages() RCT2_GLOBAL(0x0142431C, int) = e.button.y; switch (e.button.button) { case SDL_BUTTON_LEFT: - sub_406C96(2); //RCT2_CALLPROC_1(0x00406C96, int, 2); + store_mouse_input(2); gCursorState.left = CURSOR_RELEASED; gCursorState.old = 3; break; @@ -377,7 +378,7 @@ void osinterface_process_messages() gCursorState.middle = CURSOR_RELEASED; break; case SDL_BUTTON_RIGHT: - sub_406C96(4); //RCT2_CALLPROC_1(0x00406C96, int, 4); + store_mouse_input(4); gCursorState.right = CURSOR_RELEASED; gCursorState.old = 4; break; @@ -599,22 +600,18 @@ char osinterface_get_path_separator() return '\\'; } -void sub_406C96(int actionType) +/** + * rct2: 0x00406C96 + */ +static void store_mouse_input(int state) { - int eax = RCT2_GLOBAL(0x009E2DE4, uint32); - int ecx = eax + 1; - ecx &= 0x3F; //Array of 64 point structs, loop around buffer? - if (ecx != RCT2_GLOBAL(0x009E2DE8, uint32)) { - int edx = RCT2_GLOBAL(0x01424318, uint32); // X - //eax is a struct index here. Mutliplied by then and then 4 for the struct with 3 4 byte fields - //Struct is {int x, int y, int actionType} - eax = eax + eax*2; - eax = 0x01424340 + eax * 4; //get base of struct, address is base of array - *((uint32*)eax) = edx; - edx = RCT2_GLOBAL(0x0142431C, uint32); // Y - *((uint32*)eax + 1) = edx; - edx = actionType; - *((uint32*)eax + 2) = edx; - RCT2_GLOBAL(0x009E2DE4, uint32) = ecx; + int write_index = RCT2_GLOBAL(RCT2_ADDRESS_MOUSE_WRITE_INDEX, uint32); + int next_write_index = (write_index + 1) & 0x3F; //64 length buffer + + if (next_write_index != RCT2_GLOBAL(RCT2_ADDRESS_MOUSE_READ_INDEX, uint32)) { + mouse_buffer[write_index].x = RCT2_GLOBAL(0x01424318, uint32); + mouse_buffer[write_index].y = RCT2_GLOBAL(0x0142431C, uint32); + mouse_buffer[write_index].state = state; + RCT2_GLOBAL(RCT2_ADDRESS_MOUSE_WRITE_INDEX, uint32) = next_write_index; } } diff --git a/src/osinterface.h b/src/osinterface.h index 6d2cade7aa..75fc3b19f1 100644 --- a/src/osinterface.h +++ b/src/osinterface.h @@ -66,6 +66,12 @@ typedef struct { int old; } openrct2_cursor; +typedef struct { + int x, y; + int state; //0 = ? 1 = LeftDown 2 = LeftUp 3 = RightDown 4 = RightUp +} openrct2_mouse_data; + +extern openrct2_mouse_data* mouse_buffer; extern openrct2_cursor gCursorState; extern const unsigned char *gKeysState; extern unsigned char *gKeysPressed; From f5841c24f4a02e22eb89aa91a2117713edc60c30 Mon Sep 17 00:00:00 2001 From: adrian17 Date: Fri, 29 Aug 2014 10:23:57 +0200 Subject: [PATCH 40/58] Move input functions and add an address --- src/addresses.h | 8 ++++++-- src/input.c | 47 ++++++++++++++++++++++++++++++++++++++--------- src/input.h | 2 ++ src/osinterface.c | 21 ++------------------- src/osinterface.h | 6 ------ 5 files changed, 48 insertions(+), 36 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index 589dc5e69e..d46574cc45 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -169,8 +169,10 @@ #define RCT2_ADDRESS_DSOUND_DEVICES_COUNTER 0x009E2BAC #define RCT2_ADDRESS_CMDLINE 0x009E2D98 -#define RCT2_ADDRESS_MOUSE_READ_INDEX 0x009E2DE8 -#define RCT2_ADDRESS_MOUSE_WRITE_INDEX 0x009E2DE4 + +#define RCT2_ADDRESS_MOUSE_READ_INDEX 0x009E2DE8 +#define RCT2_ADDRESS_MOUSE_WRITE_INDEX 0x009E2DE4 + #define RCT2_ADDRESS_LAND_RAISE_COST 0x009E2E1C #define RCT2_ADDRESS_LAND_LOWER_COST 0x009E2E20 #define RCT2_ADDRESS_SELECTED_TERRAIN_EDGE 0x009E2E24 @@ -406,6 +408,8 @@ #define RCT2_ADDRESS_SCREEN_CAP_BPP 0x01423C10 #define RCT2_ADDRESS_SCREEN_CAP_RASTER_STRETCH 0x01423C14 +#define RCT2_ADDRESS_INPUT_QUEUE 0x01424340 + static void RCT2_CALLPROC_EBPSAFE(int address) { #ifdef _MSC_VER diff --git a/src/input.c b/src/input.c index 85e1102131..38d75468f8 100644 --- a/src/input.c +++ b/src/input.c @@ -36,6 +36,13 @@ POINT _dragPosition; +typedef struct { + uint32 x, y; + uint32 state; //1 = LeftDown 2 = LeftUp 3 = RightDown 4 = RightUp +} rct_mouse_data; + +rct_mouse_data* mouse_buffer = RCT2_ADDRESS(RCT2_ADDRESS_INPUT_QUEUE, rct_mouse_data); + static void game_get_next_input(int *x, int *y, int *state); static void input_mouseover(int x, int y, rct_window *w, int widgetIndex); static void input_mouseover_widget_check(rct_windowclass windowClass, rct_windownumber windowNumber, int widgetIndex); @@ -43,7 +50,7 @@ static void input_mouseover_widget_flatbutton_invalidate(); void process_mouse_over(int x, int y); void sub_6ED801(int x, int y); void invalidate_scroll(); -static openrct2_mouse_data* get_mouse_input(); +static rct_mouse_data* get_mouse_input(); #pragma region Scroll bar input @@ -1558,7 +1565,7 @@ void game_handle_input() */ static void game_get_next_input(int *x, int *y, int *state) { - openrct2_mouse_data* eax = get_mouse_input(); + rct_mouse_data* eax = get_mouse_input(); if (eax == NULL) { *x = gCursorState.x; *y = gCursorState.y; @@ -1764,16 +1771,38 @@ void invalidate_scroll() window_invalidate_by_id(RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWCLASS, uint8), RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWNUMBER, uint16)); } +/** +* rct2: 0x00406C96 +*/ +void store_mouse_input(int state) +{ + uint32 write_index = RCT2_GLOBAL(RCT2_ADDRESS_MOUSE_WRITE_INDEX, uint32); + uint32 next_write_index = (write_index + 1) % 64; + + // check if the queue is full + if (next_write_index == RCT2_GLOBAL(RCT2_ADDRESS_MOUSE_READ_INDEX, uint32)) + return; + + rct_mouse_data* item = &mouse_buffer[write_index]; + item->x = RCT2_GLOBAL(0x01424318, uint32); + item->y = RCT2_GLOBAL(0x0142431C, uint32); + item->state = state; + + RCT2_GLOBAL(RCT2_ADDRESS_MOUSE_WRITE_INDEX, uint32) = next_write_index; +} + + /** * rct2: 0x00407074 */ -static openrct2_mouse_data* get_mouse_input() +static rct_mouse_data* get_mouse_input() { - int read_index = RCT2_GLOBAL(RCT2_ADDRESS_MOUSE_READ_INDEX, uint32); - if (read_index != RCT2_GLOBAL(RCT2_ADDRESS_MOUSE_WRITE_INDEX, uint32)) { - RCT2_GLOBAL(RCT2_ADDRESS_MOUSE_READ_INDEX, uint32) = (read_index + 1) & 0x3F; - return &mouse_buffer[read_index]; - } else { + uint32 read_index = RCT2_GLOBAL(RCT2_ADDRESS_MOUSE_READ_INDEX, uint32); + + // check if that location has been written to yet + if (read_index == RCT2_GLOBAL(RCT2_ADDRESS_MOUSE_WRITE_INDEX, uint32)) return NULL; - } + + RCT2_GLOBAL(RCT2_ADDRESS_MOUSE_READ_INDEX, uint32) = (read_index + 1) % 64; + return &mouse_buffer[read_index]; } diff --git a/src/input.h b/src/input.h index a7a1d8ebb6..dd1cc5b3fb 100644 --- a/src/input.h +++ b/src/input.h @@ -24,4 +24,6 @@ void game_handle_input(); void game_handle_keyboard_input(); +void store_mouse_input(int state); + #endif \ No newline at end of file diff --git a/src/osinterface.c b/src/osinterface.c index 73a7b25e6b..fd6aef4b17 100644 --- a/src/osinterface.c +++ b/src/osinterface.c @@ -28,6 +28,7 @@ #include "addresses.h" #include "config.h" #include "gfx.h" +#include "input.h" #include "osinterface.h" #include "screenshot.h" #include "window.h" @@ -40,12 +41,10 @@ openrct2_cursor gCursorState; const unsigned char *gKeysState; unsigned char *gKeysPressed; unsigned int gLastKeyPressed; -openrct2_mouse_data* mouse_buffer = (openrct2_mouse_data*)0x1424340; static void osinterface_create_window(); static void osinterface_close_window(); static void osinterface_resize(int width, int height); -static void store_mouse_input(int state); static SDL_Window *_window; static SDL_Surface *_surface; @@ -598,20 +597,4 @@ int osinterface_ensure_directory_exists(const char *path) char osinterface_get_path_separator() { return '\\'; -} - -/** - * rct2: 0x00406C96 - */ -static void store_mouse_input(int state) -{ - int write_index = RCT2_GLOBAL(RCT2_ADDRESS_MOUSE_WRITE_INDEX, uint32); - int next_write_index = (write_index + 1) & 0x3F; //64 length buffer - - if (next_write_index != RCT2_GLOBAL(RCT2_ADDRESS_MOUSE_READ_INDEX, uint32)) { - mouse_buffer[write_index].x = RCT2_GLOBAL(0x01424318, uint32); - mouse_buffer[write_index].y = RCT2_GLOBAL(0x0142431C, uint32); - mouse_buffer[write_index].state = state; - RCT2_GLOBAL(RCT2_ADDRESS_MOUSE_WRITE_INDEX, uint32) = next_write_index; - } -} +} \ No newline at end of file diff --git a/src/osinterface.h b/src/osinterface.h index 75fc3b19f1..6d2cade7aa 100644 --- a/src/osinterface.h +++ b/src/osinterface.h @@ -66,12 +66,6 @@ typedef struct { int old; } openrct2_cursor; -typedef struct { - int x, y; - int state; //0 = ? 1 = LeftDown 2 = LeftUp 3 = RightDown 4 = RightUp -} openrct2_mouse_data; - -extern openrct2_mouse_data* mouse_buffer; extern openrct2_cursor gCursorState; extern const unsigned char *gKeysState; extern unsigned char *gKeysPressed; From 6473da43b27ea0c87c3a2d0fb45855ddeb9a8c6f Mon Sep 17 00:00:00 2001 From: adrian17 Date: Fri, 29 Aug 2014 11:37:32 +0200 Subject: [PATCH 41/58] Decompiled game_command_set_park_entrance_fee --- src/game.c | 3 ++- src/park.c | 36 ++++++++++++++++++++++++++++++++++++ src/park.h | 2 ++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/game.c b/src/game.c index f67b6f9279..30f4df92b1 100644 --- a/src/game.c +++ b/src/game.c @@ -29,6 +29,7 @@ #include "news_item.h" #include "object.h" #include "osinterface.h" +#include "park.h" #include "peep.h" #include "sawyercoding.h" #include "scenario.h" @@ -942,7 +943,7 @@ static uint32 game_do_command_table[58] = { 0x006666E7, 0x00666A63, 0x006CD8CE, - 0x00669E30, + (uint32)game_command_set_park_entrance_fee, (uint32)game_command_update_staff_colour, // 40 0x006E519A, 0x006E5597, diff --git a/src/park.c b/src/park.c index 159017c392..da3731efc9 100644 --- a/src/park.c +++ b/src/park.c @@ -581,4 +581,40 @@ uint8 calculate_guest_initial_happiness(uint8 percentage) { void park_update_histories() { RCT2_CALLPROC_EBPSAFE(0x0066A231); +} + +/** +* +* rct2: 0x00669E30 +*/ +void game_command_set_park_entrance_fee() +{ + uint8 _bl; + uint16 new_fee; + + #ifdef _MSC_VER + __asm mov _bl, bl + #else + __asm__("mov %[_bl], bl " : [_bl] "+m" (_bl)); + #endif + + #ifdef _MSC_VER + __asm mov new_fee, di + #else + __asm__("mov %[new_fee], di " : [new_fee] "+m" (new_fee)); + #endif + + RCT2_GLOBAL(0x0141F56C, uint8) = 0x10; + + if (_bl & 1){ + RCT2_GLOBAL(RCT2_ADDRESS_PARK_ENTRANCE_FEE, uint16) = new_fee; + + window_invalidate_by_id(WC_PARK_INFORMATION, 0); + } + + #ifdef _MSC_VER + __asm mov ebx, 0 + #else + __asm__("mov ebx, 0 "); + #endif } \ No newline at end of file diff --git a/src/park.h b/src/park.h index bb7d823e86..5c9a85171a 100644 --- a/src/park.h +++ b/src/park.h @@ -59,4 +59,6 @@ void park_update_histories(); uint8 calculate_guest_initial_happiness(uint8 percentage); +void game_command_set_park_entrance_fee(); + #endif From 199946d6821296bea6ca07026d30117d0a582e9a Mon Sep 17 00:00:00 2001 From: hexdec Date: Fri, 29 Aug 2014 02:03:20 +0200 Subject: [PATCH 42/58] Added window_staff_peep_stats_resize. --- src/window_staff_peep.c | 43 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/src/window_staff_peep.c b/src/window_staff_peep.c index ffbad2eace..4ab380d324 100644 --- a/src/window_staff_peep.c +++ b/src/window_staff_peep.c @@ -89,6 +89,7 @@ void window_staff_peep_mouseup(); void window_staff_peep_orders_mouseup(); void window_staff_peep_stats_mouseup(); +void window_staff_peep_stats_resize(); // 0x992AEC static void* window_staff_peep_overview_events[] = { @@ -126,11 +127,11 @@ static void* window_staff_peep_overview_events[] = { static void* window_staff_peep_orders_events[] = { window_staff_peep_emptysub, window_staff_peep_orders_mouseup, - (void*)0x6BE975, + window_staff_peep_stats_resize, (void*)0x6BE802, (void*)0x6BE809, (void*)0x6BE9DA, - (void*)0x6BE960, + (void*)0x6BE960, // update window_staff_peep_emptysub, window_staff_peep_emptysub, window_staff_peep_emptysub, @@ -158,11 +159,11 @@ static void* window_staff_peep_orders_events[] = { static void* window_staff_peep_stats_events[] = { window_staff_peep_emptysub, window_staff_peep_stats_mouseup, - (void*)0x6BEC1B, + window_staff_peep_stats_resize, window_staff_peep_emptysub, window_staff_peep_emptysub, (void*)0x6BEC80, - (void*)0x6BEBEA, + (void*)0x6BEBEA, // update window_staff_peep_emptysub, window_staff_peep_emptysub, window_staff_peep_emptysub, @@ -489,7 +490,7 @@ void window_staff_peep_orders_mouseup() } } -/** rct2: 0x0006BEBCF */ +/** rct2: 0x006BEBCF */ void window_staff_peep_stats_mouseup() { short widgetIndex; @@ -506,4 +507,36 @@ void window_staff_peep_stats_mouseup() window_staff_peep_set_page(w, widgetIndex - WIDX_TAB_1); break; } +} + +/** rct2: 0x006BEC1B and rct2: 0x006BE975 */ +void window_staff_peep_stats_resize() +{ + rct_window* w; + window_get_register(w); + + w->min_width = 190; + w->max_width = 190; + w->min_height = 119; + w->max_height = 119; + + if (w->width < w->min_width) { + w->width = w->min_width; + window_invalidate(w); + } + + if (w->width > w->max_width) { + window_invalidate(w); + w->width = w->max_width; + } + + if (w->height < w->min_height) { + w->height = w->min_height; + window_invalidate(w); + } + + if (w->height > w->max_height) { + window_invalidate(w); + w->height = w->max_height; + } } \ No newline at end of file From 5bd35057712431a01a6244e66a0a7859d843b941 Mon Sep 17 00:00:00 2001 From: hexdec Date: Fri, 29 Aug 2014 15:51:47 +0200 Subject: [PATCH 43/58] Implemented window_staff_peep_overview_resize. --- src/window_staff_peep.c | 66 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 7 deletions(-) diff --git a/src/window_staff_peep.c b/src/window_staff_peep.c index 4ab380d324..9b8c3b3594 100644 --- a/src/window_staff_peep.c +++ b/src/window_staff_peep.c @@ -83,8 +83,9 @@ rct_widget *window_staff_peep_page_widgets[] = { void window_staff_peep_set_page(rct_window* w, int page); void window_staff_peep_disable_widgets(rct_window* w); -void window_staff_peep_close(); -void window_staff_peep_mouseup(); +void window_staff_peep_overview_close(); +void window_staff_peep_overview_mouseup(); +void window_staff_peep_overview_resize(); void window_staff_peep_orders_mouseup(); @@ -93,9 +94,9 @@ void window_staff_peep_stats_resize(); // 0x992AEC static void* window_staff_peep_overview_events[] = { - window_staff_peep_close, - window_staff_peep_mouseup, - (void*)0x6BE558, + window_staff_peep_overview_close, + window_staff_peep_overview_mouseup, + window_staff_peep_overview_resize, (void*)0x6BDF98, (void*)0x6BDFA3, window_staff_peep_emptysub, @@ -317,7 +318,7 @@ void window_staff_peep_disable_widgets(rct_window* w) * Same as window_peep_close. * rct2: 0x006BDFF8 */ -void window_staff_peep_close() +void window_staff_peep_overview_close() { rct_window* w; @@ -406,7 +407,7 @@ void window_staff_peep_set_page(rct_window* w, int page) } /** rct2: 0x006BDF55 */ -void window_staff_peep_mouseup() +void window_staff_peep_overview_mouseup() { short widgetIndex; rct_window* w; @@ -451,6 +452,57 @@ void window_staff_peep_mouseup() } } +/** rct2: 0x006BE558 */ +void window_staff_peep_overview_resize() +{ + rct_window* w; + window_get_register(w); + + window_staff_peep_disable_widgets(w); + + w->min_width = 190; + w->max_width = 500; + w->min_height = 180; + w->max_height = 450; + + if (w->width < w->min_width) { + w->width = w->min_width; + window_invalidate(w); + } + + if (w->width > w->max_width) { + window_invalidate(w); + w->width = w->max_width; + } + + if (w->height < w->min_height) { + w->height = w->min_height; + window_invalidate(w); + } + + if (w->height > w->max_height) { + window_invalidate(w); + w->height = w->max_height; + } + + rct_viewport* viewport = w->viewport; + + if (viewport) { + int new_width = w->width - 30; + int new_height = w->height - 62; + + // Update the viewport size + if (viewport->width != new_width || viewport->height != new_height) { + viewport->width = new_width; + viewport->height = new_height; + viewport->view_width = new_width << viewport->zoom; + viewport->view_height = new_height << viewport->zoom; + } + } + + RCT2_CALLPROC_X(0x006BEDA3, 0, 0, 0, 0, (int)w, 0, 0); +} + /** rct2: 0x006BE814 */ void window_staff_peep_set_order(rct_window* w, int order_id) { From ced3c20bb1d2648808361f0c3d5d8b84284ac6cd Mon Sep 17 00:00:00 2001 From: hexdec Date: Fri, 29 Aug 2014 18:13:17 +0200 Subject: [PATCH 44/58] Implemented overview_mousedown. --- src/window_staff_peep.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/window_staff_peep.c b/src/window_staff_peep.c index 9b8c3b3594..1c24249faa 100644 --- a/src/window_staff_peep.c +++ b/src/window_staff_peep.c @@ -86,6 +86,7 @@ void window_staff_peep_disable_widgets(rct_window* w); void window_staff_peep_overview_close(); void window_staff_peep_overview_mouseup(); void window_staff_peep_overview_resize(); +void window_staff_peep_overview_mousedown(int widgetIndex, rct_window*w, rct_widget* widget); void window_staff_peep_orders_mouseup(); @@ -97,7 +98,7 @@ static void* window_staff_peep_overview_events[] = { window_staff_peep_overview_close, window_staff_peep_overview_mouseup, window_staff_peep_overview_resize, - (void*)0x6BDF98, + window_staff_peep_overview_mousedown, (void*)0x6BDFA3, window_staff_peep_emptysub, (void*)0x6BE602, @@ -503,6 +504,34 @@ void window_staff_peep_overview_resize() RCT2_CALLPROC_X(0x006BEDA3, 0, 0, 0, 0, (int)w, 0, 0); } +/** + * Handle the dropdown of patrol button. + * rct2: 0x006BDF98 + */ +void window_staff_peep_overview_mousedown(int widgetIndex, rct_window* w, rct_widget* widget) +{ + if (widgetIndex != WIDX_PATROL) { + return; + } + + // Dropdown names + gDropdownItemsFormat[0] = 0xD75; + gDropdownItemsFormat[1] = 0xD76; + + int x = widget->left + w->x; + int y = widget->top + w->y;; + int extray = widget->bottom - widget->top + 1; + window_dropdown_show_text(x, y, extray, w->colours[1], 0, 2); + RCT2_GLOBAL(0x009DEBA2, sint16) = 0; + + rct_peep* peep = GET_PEEP(w->number); + + // Disable clear patrol area if no area is set. + if (!(RCT2_ADDRESS(0x013CA672, uint8)[peep->var_C5] & 2)) { + RCT2_GLOBAL(0x009DED34, sint32) |= 1 << 1; + } +} + /** rct2: 0x006BE814 */ void window_staff_peep_set_order(rct_window* w, int order_id) { From 87171772899afae8c0ab2f25a334593a76eca86d Mon Sep 17 00:00:00 2001 From: hexdec Date: Fri, 29 Aug 2014 18:13:32 +0200 Subject: [PATCH 45/58] Implemented overview_dropdown. --- src/window_staff_peep.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/window_staff_peep.c b/src/window_staff_peep.c index 1c24249faa..d19be616f9 100644 --- a/src/window_staff_peep.c +++ b/src/window_staff_peep.c @@ -87,6 +87,7 @@ void window_staff_peep_overview_close(); void window_staff_peep_overview_mouseup(); void window_staff_peep_overview_resize(); void window_staff_peep_overview_mousedown(int widgetIndex, rct_window*w, rct_widget* widget); +void window_staff_peep_overview_dropdown(); void window_staff_peep_orders_mouseup(); @@ -99,7 +100,7 @@ static void* window_staff_peep_overview_events[] = { window_staff_peep_overview_mouseup, window_staff_peep_overview_resize, window_staff_peep_overview_mousedown, - (void*)0x6BDFA3, + window_staff_peep_overview_dropdown, window_staff_peep_emptysub, (void*)0x6BE602, window_staff_peep_emptysub, @@ -532,6 +533,42 @@ void window_staff_peep_overview_mousedown(int widgetIndex, rct_window* w, rct_wi } } +/** rct2: 0x006BDFA3 */ +void window_staff_peep_overview_dropdown() +{ + short widgetIndex, dropdownIndex; + rct_window* w; + + window_dropdown_get_registers(w, widgetIndex, dropdownIndex); + + if (widgetIndex != WIDX_PATROL) { + return; + } + + // Clear patrol + if (dropdownIndex == 1) { + rct_peep* peep = GET_PEEP(w->number); + int edi = peep->var_C5; + int ebx = edi << 9; + + for (int i = 0; i < 128; i++) + { + RCT2_GLOBAL(0x13B0E72 + ebx + i * 4, uint32) = 0; + } + RCT2_GLOBAL(0x13CA672 + edi, uint16) &= 0xFD; // bug?? + + window_invalidate(w); + RCT2_CALLPROC_EBPSAFE(0x006C0C3F); + } + else { + if (!tool_set(w, widgetIndex, 22)) { + show_gridlines(); + RCT2_GLOBAL(0x009DEA50, sint16) = w->number; + window_invalidate(w); + } + } +} + /** rct2: 0x006BE814 */ void window_staff_peep_set_order(rct_window* w, int order_id) { From 9039c196399153f483adb724f6e7ae5281bb1fdd Mon Sep 17 00:00:00 2001 From: hexdec Date: Fri, 29 Aug 2014 18:32:06 +0200 Subject: [PATCH 46/58] Implemented overview_update. --- src/window_staff_peep.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/window_staff_peep.c b/src/window_staff_peep.c index d19be616f9..7a6d76b283 100644 --- a/src/window_staff_peep.c +++ b/src/window_staff_peep.c @@ -88,6 +88,7 @@ void window_staff_peep_overview_mouseup(); void window_staff_peep_overview_resize(); void window_staff_peep_overview_mousedown(int widgetIndex, rct_window*w, rct_widget* widget); void window_staff_peep_overview_dropdown(); +void window_staff_peep_overview_update(rct_window *w); void window_staff_peep_orders_mouseup(); @@ -102,7 +103,7 @@ static void* window_staff_peep_overview_events[] = { window_staff_peep_overview_mousedown, window_staff_peep_overview_dropdown, window_staff_peep_emptysub, - (void*)0x6BE602, + window_staff_peep_overview_update, window_staff_peep_emptysub, window_staff_peep_emptysub, (void*)0x6BDFD8, @@ -569,6 +570,21 @@ void window_staff_peep_overview_dropdown() } } +/** + * Update the animation frame of the tab icon. + * rct2: 0x6BE602 + */ +void window_staff_peep_overview_update(rct_window* w) +{ + int var_496 = RCT2_GLOBAL((int)w + 0x496, uint16); + var_496++; + if (var_496 >= 24) { + var_496 = 0; + } + RCT2_GLOBAL((int)w + 0x496, uint16) = var_496; + window_invalidate_by_id(0x497, w->number); +} + /** rct2: 0x006BE814 */ void window_staff_peep_set_order(rct_window* w, int order_id) { From c50b9d12149bc36799dd56215a8372ed055e57ca Mon Sep 17 00:00:00 2001 From: hexdec Date: Fri, 29 Aug 2014 20:08:48 +0200 Subject: [PATCH 47/58] Implemented stats_update and orders_update. --- src/window_staff_peep.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/window_staff_peep.c b/src/window_staff_peep.c index 7a6d76b283..c531f8d1e6 100644 --- a/src/window_staff_peep.c +++ b/src/window_staff_peep.c @@ -86,14 +86,16 @@ void window_staff_peep_disable_widgets(rct_window* w); void window_staff_peep_overview_close(); void window_staff_peep_overview_mouseup(); void window_staff_peep_overview_resize(); -void window_staff_peep_overview_mousedown(int widgetIndex, rct_window*w, rct_widget* widget); +void window_staff_peep_overview_mousedown(int widgetIndex, rct_window* w, rct_widget* widget); void window_staff_peep_overview_dropdown(); -void window_staff_peep_overview_update(rct_window *w); +void window_staff_peep_overview_update(rct_window* w); void window_staff_peep_orders_mouseup(); +void window_staff_peep_orders_update(rct_window* w); void window_staff_peep_stats_mouseup(); void window_staff_peep_stats_resize(); +void window_staff_peep_stats_update(rct_window* w); // 0x992AEC static void* window_staff_peep_overview_events[] = { @@ -135,7 +137,7 @@ static void* window_staff_peep_orders_events[] = { (void*)0x6BE802, (void*)0x6BE809, (void*)0x6BE9DA, - (void*)0x6BE960, // update + window_staff_peep_orders_update, window_staff_peep_emptysub, window_staff_peep_emptysub, window_staff_peep_emptysub, @@ -167,7 +169,7 @@ static void* window_staff_peep_stats_events[] = { window_staff_peep_emptysub, window_staff_peep_emptysub, (void*)0x6BEC80, - (void*)0x6BEBEA, // update + window_staff_peep_stats_update, window_staff_peep_emptysub, window_staff_peep_emptysub, window_staff_peep_emptysub, @@ -624,6 +626,13 @@ void window_staff_peep_orders_mouseup() } } +/** rct2: 0x006BE960 */ +void window_staff_peep_orders_update(rct_window* w) +{ + w->frame_no++; + window_invalidate_by_id(0x597, w->number); +} + /** rct2: 0x006BEBCF */ void window_staff_peep_stats_mouseup() { @@ -673,4 +682,17 @@ void window_staff_peep_stats_resize() window_invalidate(w); w->height = w->max_height; } +} + +/** rct2: 0x006BEBEA */ +void window_staff_peep_stats_update(rct_window* w) +{ + w->frame_no++; + window_invalidate_by_id(0x697, w->number); + + rct_peep* peep = GET_PEEP(w->number); + if (peep->var_45 && 10) { + peep->var_45 &= 0xEF; + window_invalidate(w); + } } \ No newline at end of file From 24331b781d350d80f7224f7441599052497f94bb Mon Sep 17 00:00:00 2001 From: wolfreak99 Date: Sat, 30 Aug 2014 00:17:01 -0400 Subject: [PATCH 48/58] Corrected about window's credits. Switched the callproc values in the credits to open the proper music/publisher credits. --- src/window_about.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/window_about.c b/src/window_about.c index 6f968ada89..8cf3418380 100644 --- a/src/window_about.c +++ b/src/window_about.c @@ -125,10 +125,10 @@ static void window_about_mouseup() window_close(w); break; case WIDX_MUSIC_CREDITS: - RCT2_CALLPROC_EBPSAFE(0x0066D4EC); + RCT2_CALLPROC_EBPSAFE(0x0066D55B); break; case WIDX_PUBLISHER_CREDITS: - RCT2_CALLPROC_EBPSAFE(0x0066D55B); + RCT2_CALLPROC_EBPSAFE(0x0066D4EC); break; } } @@ -193,4 +193,4 @@ static void window_about_paint() // Licence gfx_draw_string_left(dpi, STR_LICENSED_TO_INFOGRAMES_INTERACTIVE_INC, 0, 0, w->x + 157, w->y + 257); -} \ No newline at end of file +} From d225e74ad0951c9a7649733f1e75345b8bfa17b0 Mon Sep 17 00:00:00 2001 From: zsilencer Date: Fri, 29 Aug 2014 23:53:29 -0600 Subject: [PATCH 49/58] 0x00405465, 0x004016FF, 0x00405222 --- src/audio.c | 176 ++++++++++++++++++++++++++++++++++++++++++++++------ src/audio.h | 14 ++++- 2 files changed, 168 insertions(+), 22 deletions(-) diff --git a/src/audio.c b/src/audio.c index 0b89bc68d3..031e098bea 100644 --- a/src/audio.c +++ b/src/audio.c @@ -354,7 +354,7 @@ int map_sound_info(const char* filename) * * rct2: 0x00405383 */ -MMRESULT sub_405383(HMMIO hmmio, uint32 size, char* buffer, LPMMCKINFO a4, int* read) +MMRESULT mmio_read(HMMIO hmmio, uint32 size, char* buffer, LPMMCKINFO mmckinfo, int* read) { MMIOINFO mmioinfo; MMRESULT result; @@ -364,11 +364,11 @@ MMRESULT sub_405383(HMMIO hmmio, uint32 size, char* buffer, LPMMCKINFO a4, int* return 1; } int size2 = size; - if (size > a4->cksize) { - size2 = a4->cksize; + if (size > mmckinfo->cksize) { + size2 = mmckinfo->cksize; } int v8 = 0; - a4->cksize -= size2; + mmckinfo->cksize -= size2; if (size2) { while (1) { HPSTR p = mmioinfo.pchEndRead; @@ -416,21 +416,157 @@ MMRESULT sub_405383(HMMIO hmmio, uint32 size, char* buffer, LPMMCKINFO a4, int* /** * -* rct2: 0x00401822 +* rct2: 0x00405465 */ -int sub_401822(int channel, HMMIO* hmmio, LONG offset) +MMRESULT mmio_seek(HMMIO* hmmio, LPMMCKINFO mmckinfo1, LPMMCKINFO mmckinfo2, int offset) +{ + mmioSeek(*hmmio, mmckinfo2->dwDataOffset + 4, SEEK_SET); + mmckinfo1->ckid = 1635017060/*DATA*/; + MMRESULT result = mmioDescend(*hmmio, mmckinfo1, mmckinfo2, MMIO_FINDCHUNK); + if (!result) { + mmioSeek(*hmmio, offset, SEEK_CUR); + return 0; + } + return result; +} + +/** +* +* rct2: 0x004016FF +*/ +int sound_channel_load_file(int channel, char* filename, int offset) { rct_sound_channel* sound_channel = &RCT2_ADDRESS(0x014262E0, rct_sound_channel)[channel]; - LPMMCKINFO v4 = &sound_channel->mmckinfo2; - HMMIO* v5 = &sound_channel->hmmio; - if (RCT2_CALLFUNC_4(0x00405222, int, HMMIO*, HMMIO*, HGLOBAL*, LPMMCKINFO, hmmio, &sound_channel->hmmio, &sound_channel->hmem, &sound_channel->mmckinfo2)) { + sound_channel->hmem; + sound_channel->hmmio; + if (mmio_open(filename, &sound_channel->hmmio, &sound_channel->hmem, &sound_channel->mmckinfo2)) { return -100; } if (*(uint16*)sound_channel->hmem != 1) { sound_channel_free(&sound_channel->hmmio, &sound_channel->hmem); return -101; } - if (RCT2_CALLFUNC_4(0x00405465, int, HMMIO*, LPMMCKINFO, LPMMCKINFO, int, &sound_channel->hmmio, &sound_channel->mmckinfo1, &sound_channel->mmckinfo2, offset)) { + if (mmio_seek(&sound_channel->hmmio, &sound_channel->mmckinfo1, &sound_channel->mmckinfo2, offset)) { + sound_channel_free(&sound_channel->hmmio, &sound_channel->hmem); + return -103; + } + sound_channel->var_150 = 120 * *((uint32*)sound_channel->hmem + 2) / 100; + DSBUFFERDESC bufferdesc; + memset(&bufferdesc, 0, sizeof(bufferdesc)); + bufferdesc.dwFlags = RCT2_GLOBAL(0x009E1AA8, uint32) | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLPAN | DSBCAPS_CTRLFREQUENCY; + bufferdesc.dwBufferBytes = sound_channel->var_150; + bufferdesc.lpwfxFormat = sound_channel->hmem; + bufferdesc.dwSize = sizeof(bufferdesc); + int ret = RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND)->lpVtbl->CreateSoundBuffer(RCT2_GLOBAL(RCT2_ADDRESS_DIRECTSOUND, LPDIRECTSOUND), &bufferdesc, &RCT2_ADDRESS(RCT2_ADDRESS_DSOUND_BUFFERS, LPDIRECTSOUNDBUFFER)[channel], 0); + if (FAILED(ret)) { + return -102; + } + sound_channel->dsbuffer = RCT2_ADDRESS(RCT2_ADDRESS_DSOUND_BUFFERS, LPDIRECTSOUNDBUFFER)[channel]; + sound_channel->var_168 = 0; + sound_channel->var_15C = 0; + sound_channel->var_164 = 1; + RCT2_CALLPROC_1(0x004015E7, int, channel); + sound_channel->var_158 = offset; + sound_channel->var_160 = 0; + return 0; +} + +/** +* +* rct2: 0x00405222 +*/ +MMRESULT mmio_open(char* filename, HMMIO* hmmio, HGLOBAL* hmem, LPMMCKINFO mmckinfo) +{ + HGLOBAL* hmemold; + HGLOBAL hmemold2; + HMMIO hmmio1; + MMRESULT result; + MMCKINFO mmckinfo1; + rct_audio_info audio_info; + + hmemold = hmem; + *hmem = 0; + hmmio1 = mmioOpenA(filename, 0, MMIO_ALLOCBUF); + if (hmmio1) { + result = mmioDescend(hmmio1, mmckinfo, 0, 0); + if (result != MMSYSERR_NOERROR) { + goto label20; + } + if (mmckinfo->ckid != 1179011410/*RIFF*/ || mmckinfo->fccType != 1163280727/*WAVE*/) { + result = 57601; + goto label20; + } + mmckinfo1.ckid = 544501094/*fmt*/; + result = mmioDescend(hmmio1, &mmckinfo1, mmckinfo, MMIO_FINDCHUNK); + if (result != MMSYSERR_NOERROR) { + goto label20; + } + if (mmckinfo1.cksize < 16) { + label19: + result = 57601; + goto label20; + } + if (mmioRead(hmmio1, (HPSTR)&audio_info, 16) == 16) { + if (audio_info.var_0 == 1) { + //strcpy(audio_info.var_0, "\x01"); + hmem = 0; + label11: + hmemold2 = GlobalAlloc(0, (uint16)hmem + 18); + *hmemold = hmemold2; + if (!hmemold2) { + result = 57344; + goto label20; + } + memcpy(hmemold2, &audio_info, 16); + *((uint16*)*hmemold + 8) = (uint16)hmem; + if (!(uint16)hmem || mmioRead(hmmio1, (char*)*hmemold + 18, (uint16)hmem) == (uint16)hmem) { + result = mmioAscend(hmmio1, &mmckinfo1, 0); + if (!result) { + goto label24; + } + goto label20; + } + goto label19; + } + if (mmioRead(hmmio1, (HPSTR)&hmem, 2) == 2) { + goto label11; + } + } + result = 57602; + goto label20; + } + result = 57600; + label20: + if (*hmemold) { + GlobalFree(*hmemold); + *hmemold = 0; + } + if (hmmio1) { + mmioClose(hmmio1, 0); + hmmio1 = 0; + } + label24: + *hmmio = hmmio1; + return result; +} + +/** +* +* rct2: 0x00401822 +*/ +int mmio_open_channel(int channel, char* filename, LONG offset) +{ + rct_sound_channel* sound_channel = &RCT2_ADDRESS(0x014262E0, rct_sound_channel)[channel]; + LPMMCKINFO v4 = &sound_channel->mmckinfo2; + HMMIO* v5 = &sound_channel->hmmio; + if (mmio_open(filename, &sound_channel->hmmio, &sound_channel->hmem, &sound_channel->mmckinfo2)) { + return -100; + } + if (*(uint16*)sound_channel->hmem != 1) { + sound_channel_free(&sound_channel->hmmio, &sound_channel->hmem); + return -101; + } + if (mmio_seek(&sound_channel->hmmio, &sound_channel->mmckinfo1, &sound_channel->mmckinfo2, offset)) { sound_channel_free(&sound_channel->hmmio, &sound_channel->hmem); return -103; } @@ -449,14 +585,14 @@ int sub_40153B(int channel) if (sound_channel->hmmio) { sound_channel_free(&sound_channel->hmmio, &sound_channel->hmem); } - if (sub_401822(channel, (HMMIO*)&sound_channel->var_8, sound_channel->var_110)) { + if (mmio_open_channel(channel, sound_channel->filename, sound_channel->var_110)) { return 0; } sound_channel->var_164 = sound_channel->var_114; sound_channel->var_118 = sound_channel->var_110; sound_channel->var_4 = 0; } else { - int result = RCT2_CALLFUNC_4(0x00405465, int, HMMIO*, LPMMCKINFO, LPMMCKINFO, int, &sound_channel->hmmio, &sound_channel->mmckinfo1, &sound_channel->mmckinfo2, sound_channel->var_118); + int result = mmio_seek(&sound_channel->hmmio, &sound_channel->mmckinfo1, &sound_channel->mmckinfo2, sound_channel->var_118); sound_channel->var_158 = sound_channel->var_118; if (result) { return 0; @@ -469,7 +605,7 @@ int sub_40153B(int channel) * * rct2: 0x00401000 */ -void sub_401000(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2, int channel) +void audio_timefunc(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2, int channel) { rct_sound_channel* sound_channel = &RCT2_ADDRESS(0x014262E0, rct_sound_channel)[channel]; DWORD status; @@ -563,7 +699,7 @@ void sub_401000(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD } } int var7; - sub_405383(sound_channel->hmmio, buf1size, buf1, &sound_channel->mmckinfo1, &var7); + mmio_read(sound_channel->hmmio, buf1size, buf1, &sound_channel->mmckinfo1, &var7); if (var7 < buf1size) { if (!sound_channel->var_164) { int s = sound_channel->mmckinfo1.cksize; @@ -592,8 +728,8 @@ void sub_401000(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD do { v38 -= var7; v21 += var7; - sub_40153B(channel);//RCT2_CALLFUNC_1(0x0040153B, int, int, channel); - sub_405383(sound_channel->hmmio, v38, v21, &sound_channel->mmckinfo1, &var7); + sub_40153B(channel); + mmio_read(sound_channel->hmmio, v38, v21, &sound_channel->mmckinfo1, &var7); } while(var7 < v38); } label49: @@ -605,7 +741,7 @@ void sub_401000(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD } goto label68; } - sub_405383(sound_channel->hmmio, buf2size, buf2, &sound_channel->mmckinfo1, &var7); + mmio_read(sound_channel->hmmio, buf2size, buf2, &sound_channel->mmckinfo1, &var7); if (var7 >= buf2size) { label68: sound_channel->dsbuffer->lpVtbl->Unlock(sound_channel->dsbuffer, buf1, buf1size, buf2, buf2size); @@ -624,8 +760,8 @@ void sub_401000(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD do { v26 += var7; v27 -= var7; - sub_40153B(channel);//RCT2_CALLFUNC_1(0x0040153B, int, int, channel); - sub_405383(sound_channel->hmmio, v27, v26, &sound_channel->mmckinfo1, &var7); + sub_40153B(channel); + mmio_read(sound_channel->hmmio, v27, v26, &sound_channel->mmckinfo1, &var7); } while(var7 < v27); goto label68; } @@ -661,7 +797,7 @@ int CALLBACK audio_timer_callback(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DW for (int i = 0; i < 4; i++) { rct_sound_channel* sound_channel = &RCT2_ADDRESS(RCT2_ADDRESS_SOUND_CHANNEL_LIST, rct_sound_channel)[i]; if(sound_channel->var_0){ - sub_401000(uTimerID, uMsg, dwUser, dw1, dw2, i); + audio_timefunc(uTimerID, uMsg, dwUser, dw1, dw2, i); } } return _InterlockedExchange(&RCT2_GLOBAL(0x009E1AAC, LONG), 0); diff --git a/src/audio.h b/src/audio.h index 2848af7840..962d859bf1 100644 --- a/src/audio.h +++ b/src/audio.h @@ -70,8 +70,7 @@ typedef struct { typedef struct { uint32 var_0; uint32 var_4; - uint32 var_8; - uint8 pad_C[0x104]; + char filename[0x108]; // 0x8 uint32 var_110; uint32 var_114; uint32 var_118; @@ -112,6 +111,16 @@ typedef struct { } rct_other_sound; 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); +int audio_release(); +MMRESULT mmio_read(HMMIO hmmio, uint32 size, char* buffer, LPMMCKINFO mmckinfo, int* read); +MMRESULT mmio_seek(HMMIO* hmmio, LPMMCKINFO mmckinfo1, LPMMCKINFO mmckinfo2, int offset); +MMRESULT mmio_open(char* filename, HMMIO* hmmio, HGLOBAL* hmem, LPMMCKINFO mmckinfo); +int audio_remove_timer(); +void audio_close(); +LPVOID map_file(LPCSTR lpFileName, DWORD dwCreationDisposition, DWORD dwNumberOfBytesToMap); +int unmap_sound_info(); int sound_prepare(int sound_id, rct_sound *sound, int channels, int software); int sound_play_panned(int sound_id, int x); int sound_play(rct_sound* sound, int looping, int volume, int pan, int frequency); @@ -123,6 +132,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_file(int channel, char* filename, int offset); void sound_channel_free(HMMIO* hmmio, HGLOBAL* hmem); int sound_stop(rct_sound *sound); int sound_stop_all(); From 4d29aaa6bd41495cdf09a078478183e421fde721 Mon Sep 17 00:00:00 2001 From: adrian17 Date: Sat, 30 Aug 2014 14:31:36 +0200 Subject: [PATCH 50/58] Fix #385, made widget_is_enabled return 1 if true --- src/input.c | 7 ++----- src/widget.c | 4 ++-- src/window.c | 4 ++-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/input.c b/src/input.c index 38d75468f8..437a791c92 100644 --- a/src/input.c +++ b/src/input.c @@ -530,11 +530,8 @@ static void input_leftmousedown(int x, int y, rct_window *w, int widgetIndex) } break; default: - // comment check as it disables the rotate station/building button in construction window -// if (!widget_is_enabled(w, widgetIndex)) -// break; - if (widget_is_disabled(w, widgetIndex)) - break; + if (!widget_is_enabled(w, widgetIndex)) + break; sound_play_panned(SOUND_CLICK_1, w->x + (widget->left + widget->right) / 2); diff --git a/src/widget.c b/src/widget.c index 1006ca3f13..22226cd78f 100644 --- a/src/widget.c +++ b/src/widget.c @@ -946,12 +946,12 @@ static void widget_draw_image(rct_drawpixelinfo *dpi, rct_window *w, int widgetI int widget_is_enabled(rct_window *w, int widgetIndex) { - return w->enabled_widgets & (1LL << widgetIndex); + return (w->enabled_widgets & (1LL << widgetIndex)) ? 1 : 0; } int widget_is_disabled(rct_window *w, int widgetIndex) { - return w->disabled_widgets & (1LL << widgetIndex); + return (w->disabled_widgets & (1LL << widgetIndex)) ? 1 : 0; } int widget_is_pressed(rct_window *w, int widgetIndex) diff --git a/src/window.c b/src/window.c index 27429674d7..355d5770bf 100644 --- a/src/window.c +++ b/src/window.c @@ -1150,7 +1150,7 @@ void window_draw_widgets(rct_window *w, rct_drawpixelinfo *dpi) if ((w->flags & WF_TRANSPARENT) && !(w->flags & WF_5)) gfx_fill_rect(dpi, w->x, w->y, w->x + w->width - 1, w->y + w->height - 1, 0x2000000 | 51); - //some code missing here? Between 006EB18C and 006EB260 + //todo: some code missing here? Between 006EB18C and 006EB260 widgetIndex = 0; for (widget = w->widgets; widget->type != WWT_LAST; widget++) { @@ -1162,7 +1162,7 @@ void window_draw_widgets(rct_window *w, rct_drawpixelinfo *dpi) widgetIndex++; } - //something missing here too? Between 006EC32B and 006EC369 + //todo: something missing here too? Between 006EC32B and 006EC369 if (w->flags & WF_WHITE_BORDER_MASK) { gfx_fill_rect_inset(dpi, w->x, w->y, w->x + w->width - 1, w->y + w->height - 1, 2, 0x10); From 5e96da663407ca1e081483baa521d44811769be7 Mon Sep 17 00:00:00 2001 From: Patrick Wijnings Date: Sat, 30 Aug 2014 15:11:19 +0200 Subject: [PATCH 51/58] Fix definition of PARK_FLAGS_NO_MONEY flag and clean up related code. --- src/award.c | 4 ++-- src/finance.c | 33 ++++++++++++++++++++++++++++---- src/finance.h | 1 + src/game.c | 2 +- src/park.c | 4 ++-- src/park.h | 4 ++-- src/scenario.c | 4 ++-- src/window_game_bottom_toolbar.c | 6 +++--- src/window_park.c | 15 +++++++++++++-- src/window_staff.c | 2 +- 10 files changed, 56 insertions(+), 19 deletions(-) diff --git a/src/award.c b/src/award.c index 397af63a45..d338ca27c1 100644 --- a/src/award.c +++ b/src/award.c @@ -155,7 +155,7 @@ static int award_is_deserved_best_value(int awardType, int activeAwardTypes) return 0; if (activeAwardTypes & (1 << PARK_AWARD_MOST_DISAPPOINTING)) return 0; - if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & (PARK_FLAGS_11 | PARK_FLAGS_PARK_FREE_ENTRY)) + if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & (PARK_FLAGS_NO_MONEY | PARK_FLAGS_PARK_FREE_ENTRY)) return 0; if (RCT2_GLOBAL(RCT2_TOTAL_RIDE_VALUE, money16) < MONEY(10, 00)) return 0; @@ -205,7 +205,7 @@ static int award_is_deserved_worse_value(int awardType, int activeAwardTypes) { if (activeAwardTypes & (1 << PARK_AWARD_BEST_VALUE)) return 0; - if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_11) + if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY) return 0; if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_ENTRANCE_FEE, money16) == MONEY(0, 00)) return 0; diff --git a/src/finance.c b/src/finance.c index 601af718f8..7c2e842b0c 100644 --- a/src/finance.c +++ b/src/finance.c @@ -74,7 +74,7 @@ void finance_pay_wages() rct_peep* peep; uint16 spriteIndex; - if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_11) + if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY) return; FOR_ALL_STAFF(spriteIndex, peep) @@ -89,7 +89,7 @@ void finance_pay_research() { uint8 level; - if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & 0x800) + if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY) return; level = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_RESEARCH_LEVEL, uint8); @@ -106,7 +106,7 @@ void finance_pay_interest() sint16 current_interest = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_INTEREST_RATE, sint16); money32 tempcost = (current_loan * 5 * current_interest) >> 14; // (5 * interest) / 2^14 is pretty close to - if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & 0x800) + if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY) return; finance_payment(tempcost, RCT_EXPENDITURE_TYPE_INTEREST); @@ -127,7 +127,7 @@ void finance_pay_ride_upkeep() ride->var_196 = 25855; // durability? } - if (ride->status != RIDE_STATUS_CLOSED && !(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & 0x800)) { + if (ride->status != RIDE_STATUS_CLOSED && !(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY)) { sint16 upkeep = ride->upkeep_cost; if (upkeep != -1) { ride->var_158 -= upkeep; @@ -185,6 +185,31 @@ void finance_init() { sub_69E869(); } +/** +* +* rct2: 0x0069E79A +*/ +void finance_update_daily_profit() +{ + // 0x0135832C is related to savegames + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PROFIT, money32) = 7 * RCT2_GLOBAL(0x0135832C, money32); + RCT2_GLOBAL(0x0135832C, money32) = 0; + + int32 eax = 0; + + if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY)) + { + + } + + eax /= 4; + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PROFIT, money32) += eax; + RCT2_GLOBAL(0x1358334, money32) += eax; + RCT2_GLOBAL(0x1358338, money32) += 1; + + //invalidate_window(al = 1C, bx = 0) +} + void sub_69E869() { // This subroutine is loan related and is used for cheat detection diff --git a/src/finance.h b/src/finance.h index 02e0dc6aab..e839dd3914 100644 --- a/src/finance.h +++ b/src/finance.h @@ -41,6 +41,7 @@ void finance_pay_interest(); void finance_pay_ride_upkeep(); void finance_reset_history(); void finance_init(); +void finance_update_daily_profit(); void sub_69E869(); #endif \ No newline at end of file diff --git a/src/game.c b/src/game.c index 51923944ee..a7abc48603 100644 --- a/src/game.c +++ b/src/game.c @@ -1860,7 +1860,7 @@ void handle_shortcut_command(int shortcutIndex) break; case SHORTCUT_SHOW_FINANCIAL_INFORMATION: if (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 0x0C)) - if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & 0x800)) + if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY)) window_finances_open(); break; case SHORTCUT_SHOW_RESEARCH_INFORMATION: diff --git a/src/park.c b/src/park.c index ba0457c3fc..94b2371f69 100644 --- a/src/park.c +++ b/src/park.c @@ -103,7 +103,7 @@ void park_init() RCT2_GLOBAL(RCT2_ADDRESS_LAND_COST, uint16) = MONEY(90, 00); RCT2_GLOBAL(RCT2_ADDRESS_CONSTRUCTION_RIGHTS_COST, uint16) = MONEY(40,00); RCT2_GLOBAL(0x01358774, uint16) = 0; - RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) = PARK_FLAGS_11 | PARK_FLAGS_SHOW_REAL_GUEST_NAMES; + RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) = PARK_FLAGS_NO_MONEY | PARK_FLAGS_SHOW_REAL_GUEST_NAMES; park_reset_history(); finance_reset_history(); award_reset(); @@ -427,7 +427,7 @@ static int park_calculate_guest_generation_probability() probability /= 4; // Check if money is enabled - if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_11)) { + if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY)) { // Penalty for overpriced entrance fee relative to total ride value money16 entranceFee = RCT2_GLOBAL(RCT2_ADDRESS_PARK_ENTRANCE_FEE, money16); if (entranceFee > totalRideValue) { diff --git a/src/park.h b/src/park.h index b12fcbad51..8f71122a88 100644 --- a/src/park.h +++ b/src/park.h @@ -35,11 +35,11 @@ enum { PARK_FLAGS_PREF_LESS_INTENSE_RIDES = (1 << 6), PARK_FLAGS_FORBID_MARKETING_CAMPAIGN = (1 << 7), PARK_FLAGS_PREF_MORE_INTENSE_RIDES = (1 << 8), - PARK_FLAGS_11 = (1 << 11), + PARK_FLAGS_NO_MONEY = (1 << 11), PARK_FLAGS_DIFFICULT_GUEST_GENERATION = (1 << 12), PARK_FLAGS_PARK_FREE_ENTRY = (1 << 13), PARK_FLAGS_DIFFICULT_PARK_RATING = (1 << 14), - PARK_FLAGS_NO_MONEY = (1 << 17), + PARK_FLAGS_NO_MONEY_SCENARIO = (1 << 17), // equivalent to PARK_FLAGS_NO_MONEY, but used in scenario editor PARK_FLAGS_18 = (1 << 18) }; diff --git a/src/scenario.c b/src/scenario.c index 441d23f3e0..76c6b9aaeb 100644 --- a/src/scenario.c +++ b/src/scenario.c @@ -223,8 +223,8 @@ void scenario_load_and_play(const rct_scenario_basic *scenario) RCT2_GLOBAL(0x009DEB7C, sint16) = 0; RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, sint32) &= 0xFFFFF7FF; - if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, sint32) & 0x20000) - RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, sint32) |= 0x800; + if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, sint32) & PARK_FLAGS_NO_MONEY_SCENARIO) + RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, sint32) |= PARK_FLAGS_NO_MONEY; RCT2_CALLPROC_EBPSAFE(0x00684AC3); RCT2_CALLPROC_EBPSAFE(0x006DFEE4); news_item_init_queue(); diff --git a/src/window_game_bottom_toolbar.c b/src/window_game_bottom_toolbar.c index dac63397f1..d724ff3f54 100644 --- a/src/window_game_bottom_toolbar.c +++ b/src/window_game_bottom_toolbar.c @@ -171,7 +171,7 @@ static void window_game_bottom_toolbar_mouseup() switch (widgetIndex) { case WIDX_LEFT_OUTSET: case WIDX_MONEY: - if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & 0x800)) + if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY)) window_finances_open(); break; case WIDX_GUESTS: @@ -332,7 +332,7 @@ static void window_game_bottom_toolbar_invalidate() } // Hide money if there is no money - if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & 0x800) { + if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY) { window_game_bottom_toolbar_widgets[WIDX_MONEY].type = WWT_EMPTY; window_game_bottom_toolbar_widgets[WIDX_GUESTS].top = 1; window_game_bottom_toolbar_widgets[WIDX_GUESTS].bottom = 17; @@ -426,7 +426,7 @@ static void window_game_bottom_toolbar_draw_left_panel(rct_drawpixelinfo *dpi, r y = window_game_bottom_toolbar_widgets[WIDX_LEFT_OUTSET].top + w->y + 4; // Draw money - if (!(RCT2_GLOBAL(0x0013573E4, uint32) & 0x800)) { + if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY)) { RCT2_GLOBAL(0x013CE952, int) = DECRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, sint32)); gfx_draw_string_centred( dpi, diff --git a/src/window_park.c b/src/window_park.c index 98caf43f0e..ac7b207403 100644 --- a/src/window_park.c +++ b/src/window_park.c @@ -580,6 +580,7 @@ static void window_park_anchor_border_widgets(rct_window *w); static void window_park_align_tabs(rct_window *w); static void window_park_set_pressed_tab(rct_window *w); static void window_park_draw_tab_images(rct_drawpixelinfo *dpi, rct_window *w); +static void window_park_set_disabled_tabs(rct_window *w); /** * @@ -599,7 +600,7 @@ rct_window *window_park_open() w->list_information_type = -1; w->var_48C = -1; w->var_492 = 0; - RCT2_CALLPROC_X(0x00667F8B, 0, 0, 0, 0, (int)w, 0, 0); + window_park_set_disabled_tabs(w); w->colours[0] = 1; w->colours[1] = 19; w->colours[2] = 19; @@ -607,6 +608,16 @@ rct_window *window_park_open() return w; } +/** + * + * rct2: 0x00667F8B + */ +void window_park_set_disabled_tabs(rct_window *w) +{ + // Disable price tab if money is disabled + w->disabled_widgets = (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY) ? (1 << WIDX_TAB_4) : 0; +} + #pragma region Entrance page /** @@ -2267,7 +2278,7 @@ static void window_park_set_page(rct_window *w, int page) w->var_020 = RCT2_GLOBAL(0x0097BAE0 + (page * 4), uint32); w->event_handlers = window_park_page_events[page]; w->widgets = window_park_page_widgets[page]; - RCT2_CALLPROC_X(0x00667F8B, 0, 0, 0, 0, (int)w, 0, 0); + window_park_set_disabled_tabs(w); window_invalidate(w); RCT2_CALLPROC_X(w->event_handlers[WE_RESIZE], 0, 0, 0, 0, (int)w, 0, 0); diff --git a/src/window_staff.c b/src/window_staff.c index d23545d8f9..7d852e638b 100644 --- a/src/window_staff.c +++ b/src/window_staff.c @@ -663,7 +663,7 @@ void window_staff_paint() { rct2_free(sprite_dpi); } - if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_11)) { + if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY)) { RCT2_GLOBAL(0x013CE952, uint32) = RCT2_ADDRESS(0x00992A00, uint16)[selectedTab]; gfx_draw_string_left(dpi, 1858, (void*)0x013CE952, 0, w->x + 0xA5, w->y + 0x20); } From 4cce2e38836abec452aea546969ccbfd8380f60a Mon Sep 17 00:00:00 2001 From: adrian17 Date: Sat, 30 Aug 2014 15:29:14 +0200 Subject: [PATCH 52/58] Fixed some buttons not working after last commit --- src/window_game_top_toolbar.c | 1 + src/window_options.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/window_game_top_toolbar.c b/src/window_game_top_toolbar.c index b7f624a598..4825f55128 100644 --- a/src/window_game_top_toolbar.c +++ b/src/window_game_top_toolbar.c @@ -170,6 +170,7 @@ void window_game_top_toolbar_open() (1 << WIDX_RIDES) | (1 << WIDX_PARK) | (1 << WIDX_STAFF) | + (1 << WIDX_GUESTS) | (1 << WIDX_CLEAR_SCENERY) | (1ULL << WIDX_FASTFORWARD) | (1ULL << WIDX_RESEARCH); diff --git a/src/window_options.c b/src/window_options.c index 8190d761ed..926b298c5b 100644 --- a/src/window_options.c +++ b/src/window_options.c @@ -230,6 +230,8 @@ void window_options_open() (1ULL << WIDX_MUSIC_DROPDOWN) | (1ULL << WIDX_SOUND_QUALITY) | (1ULL << WIDX_SOUND_QUALITY_DROPDOWN) | + (1ULL << WIDX_LANGUAGE) | + (1ULL << WIDX_LANGUAGE_DROPDOWN) | (1ULL << WIDX_CURRENCY) | (1ULL << WIDX_CURRENCY_DROPDOWN) | (1ULL << WIDX_DISTANCE) | From b253ad56cee021ffc185349cbb763a3b55f80726 Mon Sep 17 00:00:00 2001 From: hexdec Date: Sat, 30 Aug 2014 15:31:44 +0200 Subject: [PATCH 53/58] Fixed typo in window_staff_peep_stats_update. --- src/window_staff_peep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/window_staff_peep.c b/src/window_staff_peep.c index c531f8d1e6..1195812b4b 100644 --- a/src/window_staff_peep.c +++ b/src/window_staff_peep.c @@ -691,7 +691,7 @@ void window_staff_peep_stats_update(rct_window* w) window_invalidate_by_id(0x697, w->number); rct_peep* peep = GET_PEEP(w->number); - if (peep->var_45 && 10) { + if (peep->var_45 & 0x10) { peep->var_45 &= 0xEF; window_invalidate(w); } From 81de6e12340bde133b1b866270ff9d8d96d3d3ba Mon Sep 17 00:00:00 2001 From: zsilencer Date: Sat, 30 Aug 2014 13:44:47 -0600 Subject: [PATCH 54/58] 0x004015E7 --- src/audio.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++--- src/audio.h | 2 ++ 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/audio.c b/src/audio.c index 031e098bea..6ad888b962 100644 --- a/src/audio.c +++ b/src/audio.c @@ -430,6 +430,52 @@ MMRESULT mmio_seek(HMMIO* hmmio, LPMMCKINFO mmckinfo1, LPMMCKINFO mmckinfo2, int return result; } +/** +* +* rct2: 0x004015E7 +*/ +int sub_4015E7(int channel) +{ + char* buf1; + int buf1size; + char* buf2; + int buf2size; + int read; + int zero = 0; + rct_sound_channel* sound_channel = &RCT2_ADDRESS(0x014262E0, rct_sound_channel)[channel]; + LPDIRECTSOUNDBUFFER dsbuffer = RCT2_ADDRESS(RCT2_ADDRESS_DSOUND_BUFFERS, LPDIRECTSOUNDBUFFER)[channel]; + int result = dsbuffer->lpVtbl->Lock(dsbuffer, 0, sound_channel->var_150, (LPVOID*)&buf1, (LPDWORD)&buf1size, (LPVOID*)&buf2, (LPDWORD)&buf2size, 0); + if (SUCCEEDED(result)) { + if (buf1size) { + mmio_read(sound_channel->hmmio, buf1size, buf1, &sound_channel->mmckinfo1, &read); + int r = read; + if (read < buf1size) { + if (sound_channel->var_164) { + char* b = buf1; + int d = buf1size; + do { + d -= r; + b += r; + sub_40153B(channel); + mmio_read(sound_channel->hmmio, d, b, &sound_channel->mmckinfo1, &read); + r = read; + } while(read < d); + } else { + sound_channel->var_168 = 1; + sound_channel->var_15C = read; + rct_audio_info* audio_info = sound_channel->hmem; + uint16 v = ((audio_info->var_E != 8) - 1) & 0x80; + memset(&buf1[read], v, buf1size - r); + } + } + } + result = dsbuffer->lpVtbl->Unlock(dsbuffer, buf1, buf1size, buf2, zero); + sound_channel->var_158 = 0; + sound_channel->playpos = 0; + } + return result; +} + /** * * rct2: 0x004016FF @@ -465,7 +511,7 @@ int sound_channel_load_file(int channel, char* filename, int offset) sound_channel->var_168 = 0; sound_channel->var_15C = 0; sound_channel->var_164 = 1; - RCT2_CALLPROC_1(0x004015E7, int, channel); + sub_4015E7(channel); sound_channel->var_158 = offset; sound_channel->var_160 = 0; return 0; @@ -1052,9 +1098,9 @@ int sound_prepare(int sound_id, rct_sound *sound, int channels, int software) bufferdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_STATIC; if (channels) { if (channels == 2) { - bufferdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLPAN | DSBCAPS_CTRLFREQUENCY | DSBCAPS_STATIC; - } else { bufferdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRL3D | DSBCAPS_STATIC; + } else { + bufferdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLPAN | DSBCAPS_CTRLFREQUENCY | DSBCAPS_STATIC; } if (RCT2_GLOBAL(0x009E2B90, uint32)) { bufferdesc.dwFlags |= DSBCAPS_CTRLPAN; diff --git a/src/audio.h b/src/audio.h index 962d859bf1..6da01639df 100644 --- a/src/audio.h +++ b/src/audio.h @@ -117,6 +117,8 @@ int audio_release(); MMRESULT mmio_read(HMMIO hmmio, uint32 size, char* buffer, LPMMCKINFO mmckinfo, int* read); MMRESULT mmio_seek(HMMIO* hmmio, LPMMCKINFO mmckinfo1, LPMMCKINFO mmckinfo2, int offset); MMRESULT mmio_open(char* filename, HMMIO* hmmio, HGLOBAL* hmem, LPMMCKINFO mmckinfo); +int sub_40153B(int channel); +int sub_4015E7(int channel); int audio_remove_timer(); void audio_close(); LPVOID map_file(LPCSTR lpFileName, DWORD dwCreationDisposition, DWORD dwNumberOfBytesToMap); From 858be90222d25a625c06dfaad1c8f4aede109ab9 Mon Sep 17 00:00:00 2001 From: hexdec Date: Sun, 31 Aug 2014 00:06:11 +0200 Subject: [PATCH 55/58] Added the missing enabled_widgets for window_staff_peep. --- src/window_staff_peep.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/window_staff_peep.c b/src/window_staff_peep.c index 1195812b4b..19a5d8076d 100644 --- a/src/window_staff_peep.c +++ b/src/window_staff_peep.c @@ -213,7 +213,12 @@ uint32 window_staff_peep_page_enabled_widgets[] = { (1 << WIDX_CLOSE) | (1 << WIDX_TAB_1) | (1 << WIDX_TAB_2) | - (1 << WIDX_TAB_3), + (1 << WIDX_TAB_3) | + (1 << WIDX_VIEWPORT) | // Sweep footpaths & Inspect rides + (1 << WIDX_BTM_LABEL) | // Water gardens & Fix rides + (1 << WIDX_PICKUP) | // Empty litter bins + (1 << WIDX_PATROL) | // Mow grass + (1 << WIDX_LOCATE), // Entertainer costume dropdown (1 << WIDX_CLOSE) | (1 << WIDX_TAB_1) | @@ -620,7 +625,6 @@ void window_staff_peep_orders_mouseup() case WIDX_BTM_LABEL: case WIDX_PICKUP: case WIDX_PATROL: - case WIDX_RENAME: window_staff_peep_set_order(w, widgetIndex - 8); break; } From d2e27c042809a1475dc3367ae98790ca0bcb8f38 Mon Sep 17 00:00:00 2001 From: hexdec Date: Sun, 31 Aug 2014 00:16:35 +0200 Subject: [PATCH 56/58] Added Widget enums for window_staff_peep. --- src/window_staff_peep.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/window_staff_peep.c b/src/window_staff_peep.c index 19a5d8076d..555818c920 100644 --- a/src/window_staff_peep.c +++ b/src/window_staff_peep.c @@ -50,7 +50,14 @@ enum WINDOW_STAFF_PEEP_WIDGET_IDX { WIDX_PATROL, WIDX_RENAME, WIDX_LOCATE, - WIDX_FIRE + WIDX_FIRE, + + WIDX_CHECKBOX_1 = 0x8, + WIDX_CHECKBOX_2, + WIDX_CHECKBOX_3, + WIDX_CHECKBOX_4, + + WIDX_COSTUME = 0xD, }; void window_staff_peep_emptysub(){}; @@ -214,11 +221,11 @@ uint32 window_staff_peep_page_enabled_widgets[] = { (1 << WIDX_TAB_1) | (1 << WIDX_TAB_2) | (1 << WIDX_TAB_3) | - (1 << WIDX_VIEWPORT) | // Sweep footpaths & Inspect rides - (1 << WIDX_BTM_LABEL) | // Water gardens & Fix rides - (1 << WIDX_PICKUP) | // Empty litter bins - (1 << WIDX_PATROL) | // Mow grass - (1 << WIDX_LOCATE), // Entertainer costume dropdown + (1 << WIDX_CHECKBOX_1) | + (1 << WIDX_CHECKBOX_2) | + (1 << WIDX_CHECKBOX_3) | + (1 << WIDX_CHECKBOX_4) | + (1 << WIDX_COSTUME), (1 << WIDX_CLOSE) | (1 << WIDX_TAB_1) | @@ -621,11 +628,11 @@ void window_staff_peep_orders_mouseup() case WIDX_TAB_3: window_staff_peep_set_page(w, widgetIndex - WIDX_TAB_1); break; - case WIDX_VIEWPORT: - case WIDX_BTM_LABEL: - case WIDX_PICKUP: - case WIDX_PATROL: - window_staff_peep_set_order(w, widgetIndex - 8); + case WIDX_CHECKBOX_1: + case WIDX_CHECKBOX_2: + case WIDX_CHECKBOX_3: + case WIDX_CHECKBOX_4: + window_staff_peep_set_order(w, widgetIndex - WIDX_CHECKBOX_1); break; } } From b832a7235b00d57cb7e781ce6af096e48aa6fd64 Mon Sep 17 00:00:00 2001 From: Patrick Wijnings Date: Sun, 31 Aug 2014 13:01:50 +0200 Subject: [PATCH 57/58] More PARK_FLAGS_NO_MONEY updates. Implement finance_update_daily_profit(). --- src/addresses.h | 1 + src/finance.c | 50 ++++++++++++++++++++++++++++++++----------- src/park.h | 2 ++ src/scenario.c | 10 ++++----- src/scenario.h | 4 ++-- src/window_new_ride.c | 4 ++-- src/window_peep.c | 2 +- 7 files changed, 50 insertions(+), 23 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index d46574cc45..7bef46848b 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -236,6 +236,7 @@ #define RCT2_ADDRESS_OBJECTIVE_CURRENCY 0x013580FC #define RCT2_ADDRESS_OBJECTIVE_NUM_GUESTS 0x01358100 #define RCT2_ADDRESS_BALANCE_HISTORY 0x0135812C +#define RCT2_ADDRESS_CURRENT_EXPENDITURE 0x0135832C #define RCT2_ADDRESS_CURRENT_PROFIT 0x01358330 #define RCT2_ADDRESS_WEEKLY_PROFIT_HISTORY 0x0135833C #define RCT2_ADDRESS_CURRENT_PARK_VALUE 0x0135853C diff --git a/src/finance.c b/src/finance.c index ffb4496cca..785628ae74 100644 --- a/src/finance.c +++ b/src/finance.c @@ -57,7 +57,7 @@ void finance_payment(money32 amount, rct_expenditure_type type) RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, sint32) = ENCRYPT_MONEY(new_money); RCT2_ADDRESS(RCT2_ADDRESS_EXPENDITURE_TABLE, money32)[type] -= amount; if (RCT2_ADDRESS(0x00988E60, uint32)[type] & 1) - RCT2_GLOBAL(0x0135832C, money32) -= amount; + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_EXPENDITURE, money32) -= amount; // Cumulative amount of money spent this day RCT2_GLOBAL(0x009A9804, uint32) |= 1; // money diry flag @@ -158,11 +158,10 @@ void finance_init() { RCT2_ADDRESS(RCT2_ADDRESS_EXPENDITURE_TABLE, money32)[i] = 0; } - RCT2_GLOBAL(0x0135832C, uint32) = 0; - + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_EXPENDITURE, uint32) = 0; RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PROFIT, money32) = 0; - RCT2_GLOBAL(0x01358334, uint32) = 0; + RCT2_GLOBAL(0x01358334, money32) = 0; RCT2_GLOBAL(0x01358338, uint16) = 0; RCT2_GLOBAL(0x013573DC, money32) = MONEY(10000,00); // Cheat detection @@ -191,23 +190,48 @@ void finance_init() { */ void finance_update_daily_profit() { - // 0x0135832C is related to savegames - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PROFIT, money32) = 7 * RCT2_GLOBAL(0x0135832C, money32); - RCT2_GLOBAL(0x0135832C, money32) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PROFIT, money32) = 7 * RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_EXPENDITURE, money32); + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_EXPENDITURE, money32) = 0; // Reset daily expenditure - int32 eax = 0; + money32 current_profit = 0; if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY)) { + // Staff costs + uint16 sprite_index; + rct_peep *peep; + FOR_ALL_STAFF(sprite_index, peep) { + uint8 staff_type = peep->staff_type; + current_profit -= wage_table[peep->staff_type]; + } + + // Research costs + uint8 level = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_RESEARCH_LEVEL, uint8); + current_profit -= research_cost_table[level]; + + // Loan costs + money32 current_loan = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_LOAN, money32); + current_profit -= current_loan / 600; + + // Ride costs + rct_ride *ride; + int i; + FOR_ALL_RIDES(i, ride) { + if (ride->status != RIDE_STATUS_CLOSED && ride->upkeep_cost != -1) { + current_profit -= 2 * ride->upkeep_cost; + } + } } - eax /= 4; - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PROFIT, money32) += eax; - RCT2_GLOBAL(0x1358334, money32) += eax; - RCT2_GLOBAL(0x1358338, money32) += 1; + // This is not equivalent to / 4 due to rounding of negative numbers + current_profit = current_profit >> 2; - //invalidate_window(al = 1C, bx = 0) + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PROFIT, money32) += current_profit; + RCT2_GLOBAL(0x1358334, money32) += RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PROFIT, money32); + RCT2_GLOBAL(0x1358338, uint16) += 1; + + window_invalidate_by_id(WC_FINANCES, 0); } void sub_69E869() diff --git a/src/park.h b/src/park.h index 8f71122a88..8a27dfdc8d 100644 --- a/src/park.h +++ b/src/park.h @@ -59,4 +59,6 @@ void park_update_histories(); uint8 calculate_guest_initial_happiness(uint8 percentage); +void game_command_set_park_entrance_fee(); + #endif diff --git a/src/scenario.c b/src/scenario.c index e88c4dfa09..9154ce9e81 100644 --- a/src/scenario.c +++ b/src/scenario.c @@ -142,7 +142,7 @@ void scenario_load(const char *path) sawyercoding_read_chunk(file, (uint8*)RCT2_ADDRESS_ACTIVE_RESEARCH_TYPES); // Read ? - sawyercoding_read_chunk(file, (uint8*)0x0135832C); + sawyercoding_read_chunk(file, (uint8*)RCT2_ADDRESS_CURRENT_EXPENDITURE); // Read ? sawyercoding_read_chunk(file, (uint8*)RCT2_ADDRESS_CURRENT_PARK_VALUE); @@ -279,9 +279,9 @@ void scenario_load_and_play(const rct_scenario_basic *scenario) strcat((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2, ".SV6"); memset((void*)0x001357848, 0, 56); - RCT2_GLOBAL(0x0135832C, uint32) = 0; - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PROFIT, sint32) = 0; - RCT2_GLOBAL(0x01358334, uint32) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_EXPENDITURE, uint32) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PROFIT, money32) = 0; + RCT2_GLOBAL(0x01358334, money32) = 0; RCT2_GLOBAL(0x01358338, uint16) = 0; RCT2_GLOBAL(RCT2_ADDRESS_COMPLETED_COMPANY_VALUE, uint32) = 0x80000000; RCT2_GLOBAL(RCT2_ADDRESS_TOTAL_ADMISSIONS, uint32) = 0; @@ -577,7 +577,7 @@ void scenario_update() if ((current_days_in_month * next_month_tick) >> 16 != (current_days_in_month * month_tick) >> 16) { // daily checks - RCT2_CALLPROC_EBPSAFE(0x0069E79A); // daily profit update + finance_update_daily_profit(); // daily profit update RCT2_CALLPROC_EBPSAFE(0x0069C35E); // some kind of peeps days_visited update loop get_local_time(); RCT2_CALLPROC_EBPSAFE(0x0066A13C); // objective 6 dragging diff --git a/src/scenario.h b/src/scenario.h index 4ab1e2d2b2..cbd5b5d764 100644 --- a/src/scenario.h +++ b/src/scenario.h @@ -204,8 +204,8 @@ typedef struct { money32 balance_history[128]; // SC6[11] - uint32 dword_0135832C; - uint32 current_profit; + money32 current_expenditure; + money32 current_profit; uint32 dword_01358334; uint16 word_01358338; uint8 pad_0135833A[2]; diff --git a/src/window_new_ride.c b/src/window_new_ride.c index f744a63c24..9b061810f0 100644 --- a/src/window_new_ride.c +++ b/src/window_new_ride.c @@ -468,7 +468,7 @@ static void window_new_ride_refresh_widget_sizing(rct_window *w) window_new_ride_widgets[WIDX_CURRENTLY_IN_DEVELOPMENT_GROUP].type = WWT_GROUPBOX; window_new_ride_widgets[WIDX_LAST_DEVELOPMENT_GROUP].type = WWT_GROUPBOX; window_new_ride_widgets[WIDX_LAST_DEVELOPMENT_BUTTON].type = WWT_FLATBTN; - if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_11)) + if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY)) window_new_ride_widgets[WIDX_RESEARCH_FUNDING_BUTTON].type = WWT_FLATBTN; width = 300; @@ -944,7 +944,7 @@ static void window_new_ride_paint_ride_information(rct_window *w, rct_drawpixeli } // Price - if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_11)) { + if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY)) { // Get price of ride int unk2 = RCT2_GLOBAL(0x0097CC68 + (item.type * 2), uint8); money32 price = RCT2_GLOBAL(0x0097DD78 + (item.type * 4), uint16); diff --git a/src/window_peep.c b/src/window_peep.c index 8d154f4e74..a85331101c 100644 --- a/src/window_peep.c +++ b/src/window_peep.c @@ -500,7 +500,7 @@ void window_peep_disable_widgets(rct_window* w){ if (!(w->disabled_widgets & (1 << WIDX_PICKUP))) window_invalidate(w); } - if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_11){ + if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY){ disabled_widgets |= (1 << WIDX_TAB_4); //Disable finance tab if no money } w->disabled_widgets = disabled_widgets; From 9a6537209db2f3bd838d4f0d98f07d5da9acc3e0 Mon Sep 17 00:00:00 2001 From: Patrick Wijnings Date: Sun, 31 Aug 2014 13:06:24 +0200 Subject: [PATCH 58/58] Add comment to finance_update_daily_profit(). --- src/finance.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/finance.c b/src/finance.c index 785628ae74..efedfdff63 100644 --- a/src/finance.c +++ b/src/finance.c @@ -228,6 +228,8 @@ void finance_update_daily_profit() current_profit = current_profit >> 2; RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PROFIT, money32) += current_profit; + + // These are related to weekly profit graph RCT2_GLOBAL(0x1358334, money32) += RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PROFIT, money32); RCT2_GLOBAL(0x1358338, uint16) += 1;