From b02463478b39eee78d4b3ad30bee8b9ac2e01c49 Mon Sep 17 00:00:00 2001 From: zsilencer Date: Mon, 1 Sep 2014 00:12:46 -0600 Subject: [PATCH 1/7] few basic functions decompiled and small bug fix --- src/audio.c | 89 +++++++++++++++++++++++++++++++++++++++++++- src/audio.h | 26 +++++++++++-- src/game.c | 4 +- src/peep.c | 8 ++-- src/title.c | 9 +++-- src/vehicle.h | 23 +++++++++--- src/window_options.c | 2 +- 7 files changed, 139 insertions(+), 22 deletions(-) diff --git a/src/audio.c b/src/audio.c index 6ad888b962..fe46f41668 100644 --- a/src/audio.c +++ b/src/audio.c @@ -23,6 +23,9 @@ #include "addresses.h" #include "config.h" #include "rct2.h" +#include "sprite.h" +#include "viewport.h" +#include "window.h" int gAudioDeviceCount; audio_device *gAudioDevices = NULL; @@ -193,7 +196,7 @@ int sound_load3dparameters() */ int sound_load3dposition() { - /*if (SUCCEEDED(RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER)->lpVtbl->GetPosition(RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER), &RCT2_GLOBAL(0x009A6084, DS3DBUFFER), 1))) { + /*if (SUCCEEDED(RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER)->lpVtbl->GetPosition(RCT2_GLOBAL(0x009E2BA4, LPDIRECTSOUND3DBUFFER), &RCT2_GLOBAL(0x009A6084, D3DVECTOR), 1))) { return 1; }*/ return 0; @@ -732,7 +735,7 @@ void audio_timefunc(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, D return; } } - if (FAILED(sound_channel->dsbuffer->lpVtbl->Lock(sound_channel->dsbuffer, sound_channel->playpos, var2, (LPVOID*)&buf1, (LPDWORD)&buf1size, (LPVOID*)&buf2, &buf2size, 0))) { + if (FAILED(sound_channel->dsbuffer->lpVtbl->Lock(sound_channel->dsbuffer, sound_channel->playpos, var2, (LPVOID*)&buf1, (LPDWORD)&buf1size, (LPVOID*)&buf2, (LPDWORD)&buf2size, 0))) { // TimeFunc() could not lock DirectSoundBuffer return; } @@ -1178,6 +1181,63 @@ int sound_play_panned(int sound_id, int x) return result; } +/** +* +* rct2: 0x00401B63 +*/ +int sub_401B63(int channel) +{ + if (RCT2_ADDRESS(RCT2_ADDRESS_SOUND_CHANNEL_LIST, rct_sound_channel)[channel].var_0) { + return RCT2_ADDRESS(RCT2_ADDRESS_SOUND_CHANNEL_LIST, rct_sound_channel)[channel].var_160 == 0; + } else { + return 0; + } +} + +/** +* +* rct2: 0x0040194E +*/ +int sound_channel_load_file2(int channel, char* filename, int offset) +{ + if (!RCT2_GLOBAL(0x009E1AA4, int)) { + return 0; + } + if (sub_401B63(channel)) { + sound_channel_stop(channel); + } + if (!sound_channel_load_file(channel, filename, offset)) { + RCT2_ADDRESS(RCT2_ADDRESS_SOUND_CHANNEL_LIST, rct_sound_channel)[channel].var_4 = 0; + return 1; + } + return 0; +} + +/** +* +* rct2: 0x006BD0F8 +*/ +void start_title_music() +{ + if ((RCT2_GLOBAL(0x009AF284, uint32) & (1 << 0)) && RCT2_GLOBAL(0x009AF59D, uint8) & 1 && RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 1) { + if (!RCT2_GLOBAL(0x009AF600, uint8)) { + RCT2_GLOBAL(0x014241BC, uint32) = 1; + int result = sound_channel_load_file2(3, (char*)get_file_path(PATH_ID_CSS17), 0); + RCT2_GLOBAL(0x014241BC, uint32) = 0; + if (result) { + RCT2_GLOBAL(0x014241BC, uint32) = 1; + sound_channel_play(3, 1, 0, 0, 0); + RCT2_GLOBAL(0x014241BC, uint32) = 0; + } + RCT2_GLOBAL(0x009AF600, uint8) = 1; + } + } else { + if (RCT2_GLOBAL(0x009AF600, uint8)) { + stop_title_music(); + } + } +} + /** * * rct2: 0x00401999 @@ -1241,6 +1301,30 @@ int sound_channel_set_volume(int channel, int volume) return 0; } +/** +* +* rct2: 0x006BB991 +*/ +void stop_completed_sounds() +{ + if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32) != -1) { + for (int i = 0; i < 7; i++) { + rct_other_sound* other_sound = &RCT2_ADDRESS(0x009AF484, rct_other_sound)[i]; + if (other_sound->id != (uint16)-1) { + RCT2_GLOBAL(0x014241BC, uint32) = 1; + int isplaying = sound_is_playing(&other_sound->sound); + RCT2_GLOBAL(0x014241BC, uint32) = 0; + if (!isplaying) { + RCT2_GLOBAL(0x014241BC, uint32) = 1; + sound_stop(&other_sound->sound); + RCT2_GLOBAL(0x014241BC, uint32) = 0; + other_sound->id = (uint16)-1; + } + } + } + } +} + /** * * rct2: 0x00404E7F @@ -1519,6 +1603,7 @@ void stop_title_music() RCT2_GLOBAL(0x014241BC, uint32) = 0; } } + RCT2_GLOBAL(0x009AF600, uint8) = 0; } /** diff --git a/src/audio.h b/src/audio.h index 6da01639df..c68b059e96 100644 --- a/src/audio.h +++ b/src/audio.h @@ -22,6 +22,7 @@ #define _AUDIO_H_ #include "rct2.h" +#include "sprite.h" typedef struct { char name[256]; @@ -51,7 +52,8 @@ typedef struct { */ typedef struct rct_sound { LPDIRECTSOUNDBUFFER dsbuffer; - int id; + uint16 id; + uint16 var_8; int has_caps; int var_0C; struct rct_sound* next; @@ -99,10 +101,14 @@ typedef struct { uint16 var_2; rct_sound sound1; // 0x04 uint16 var_18; - uint8 pad_1A[0x06]; + uint16 var_1A; + uint16 var_1C; + uint16 var_1D; rct_sound sound2; // 0x20 uint16 var_34; - uint8 pad_36[0x06]; + uint16 pad_36; + uint16 var_38; + uint16 var_3A; } rct_vehicle_sound; typedef struct { @@ -110,6 +116,17 @@ typedef struct { rct_sound sound; } rct_other_sound; +typedef struct { + uint16 id; + uint8 var_2; + uint8 var_3; + uint8 var_4; + uint16 var_5; + uint8 var_7; + uint16 var_8; + uint16 next; // 0xA +} rct_sound_unknown; + int get_dsound_devices(); int dsound_create_primary_buffer(int a, int device, int channels, int samples, int bits); void audio_timefunc(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2, int channel); @@ -134,6 +151,7 @@ int sound_channel_play(int channel, int a2, int volume, int pan, int frequency); int sound_channel_set_frequency(int channel, int frequency); int sound_channel_set_pan(int channel, int pan); int sound_channel_set_volume(int channel, int volume); +int sound_channel_load_file2(int channel, char* filename, int offset); int sound_channel_load_file(int channel, char* filename, int offset); void sound_channel_free(HMMIO* hmmio, HGLOBAL* hmem); int sound_stop(rct_sound *sound); @@ -145,11 +163,13 @@ rct_sound* sound_remove(rct_sound* sound); rct_sound* sound_begin(); rct_sound* sound_next(rct_sound* sound); void pause_sounds(); +void stop_completed_sounds(); void stop_other_sounds(); void stop_vehicle_sounds(); void stop_ride_music(); void stop_peep_sounds(); void stop_title_music(); +void start_title_music(); void unpause_sounds(); // 0x009AF59C probably does the same job diff --git a/src/game.c b/src/game.c index f67b6f9279..888955bbe0 100644 --- a/src/game.c +++ b/src/game.c @@ -305,7 +305,7 @@ void game_update() if (RCT2_GLOBAL(0x009DEA6E, uint8) == 0) { for (; eax > 0; eax--) { game_logic_update(); - RCT2_CALLPROC_EBPSAFE(0x006BD0F8); // play title screen music + start_title_music(); //RCT2_CALLPROC_EBPSAFE(0x006BD0F8); // play title screen music /* if (rctmem->dword_009E2D74 == 1) { @@ -388,7 +388,7 @@ void game_logic_update() news_item_update_current(); RCT2_CALLPROC_EBPSAFE(0x0067009A); // scenario editor opening of windows for a phase - RCT2_CALLPROC_EBPSAFE(0x006BB991); // removes other sounds that are no longer playing, this is normally called somewhere in rct2_init + stop_completed_sounds(); // removes other sounds that are no longer playing, this is normally called somewhere in rct2_init // Update windows window_dispatch_update_all(); diff --git a/src/peep.c b/src/peep.c index ea85a117e4..447b7c08d1 100644 --- a/src/peep.c +++ b/src/peep.c @@ -330,7 +330,7 @@ void peep_update_crowd_noise() if (visiblePeeps < 0) { // Mute crowd noise if (RCT2_GLOBAL(0x009AF5FC, uint32) != 1) { - RCT2_CALLPROC_1(0x00401A05, int, 2); + sound_channel_stop(2); //RCT2_CALLPROC_1(0x00401A05, int, 2); RCT2_GLOBAL(0x009AF5FC, uint32) = 1; } } else { @@ -345,14 +345,14 @@ void peep_update_crowd_noise() // Check if crowd noise is already playing if (RCT2_GLOBAL(0x009AF5FC, uint32) == 1) { // Load and play crowd noise - if (RCT2_CALLFUNC_3(0x0040194E, int, int, char*, int, 2, (char*)get_file_path(PATH_ID_CSS2), 0)) { - RCT2_CALLPROC_5(0x00401999, int, int, int, int, int, 2, 1, volume, 0, 0); + if (sound_channel_load_file2(2, (char*)get_file_path(PATH_ID_CSS2), 0)) { + sound_channel_play(2, 1, volume, 0, 0); RCT2_GLOBAL(0x009AF5FC, uint32) = volume; } } else { // Alter crowd noise volume if (RCT2_GLOBAL(0x009AF5FC, uint32) != volume) { - RCT2_CALLPROC_2(0x00401AD3, int, int, 2, volume); + sound_channel_set_volume(2, volume);//RCT2_CALLPROC_2(0x00401AD3, int, int, 2, volume); RCT2_GLOBAL(0x009AF5FC, uint32) = volume; } } diff --git a/src/title.c b/src/title.c index adfb25e080..29f7c86774 100644 --- a/src/title.c +++ b/src/title.c @@ -262,7 +262,7 @@ void title_update() if (RCT2_GLOBAL(0x009DEA6E, uint8) == 0) { title_update_showcase(); game_logic_update(); - title_play_music(); + start_title_music();//title_play_music(); } RCT2_GLOBAL(0x009DE518, uint32) &= ~0x80; @@ -304,9 +304,10 @@ void title_update() * * rct2: 0x00678761 */ +// this doesn't seem like it is 0x00678761, supposed to be 0x006BD0F8? static void title_play_music() { - // RCT2_CALLPROC_EBPSAFE(0x006BD0F8); // play title screen music + RCT2_CALLPROC_EBPSAFE(0x006BD0F8); // play title screen music if (!(RCT2_GLOBAL(0x009AF284, uint32) & 1) || !(RCT2_GLOBAL(0x009AF59D, uint8) & 1)) { if (RCT2_GLOBAL(0x009AF600, uint8) != 0) @@ -325,8 +326,8 @@ static void title_play_music() strcat(musicPath, "\\data\\css50.dat"); } - if (RCT2_CALLFUNC_3(0x0040194E, int, int, char*, int, 3, musicPath, 0)) // play music - RCT2_CALLPROC_5(0x00401999, int, int, int, int, int, 3, 1, 0, 0, 0); + if (sound_channel_load_file2(3, musicPath, 0)) // play music + sound_channel_play(3, 1, 0, 0, 0); RCT2_GLOBAL(0x009AF600, uint8) = 1; } diff --git a/src/vehicle.h b/src/vehicle.h index 92ada2f2fd..046d719a34 100644 --- a/src/vehicle.h +++ b/src/vehicle.h @@ -23,6 +23,14 @@ #include "rct2.h" +typedef union { + struct { + uint16 width; + uint16 height; + }; + uint32 both; +} rct_widthheight; + typedef struct { uint8 sprite_identifier; // 0x00 uint8 pad_01[0x03]; @@ -35,8 +43,10 @@ typedef struct { sint16 x; // 0x0E sint16 y; // 0x10 sint16 z; // 0x12 - uint8 pad_14[0x0B]; - uint8 var_1F; + uint8 pad_14[0x02]; + rct_widthheight var_16; + rct_widthheight view; // 0x1A + uint16 var_1E; uint8 pad_20[0x08]; uint32 var_28; uint8 pad_2C[0x04]; @@ -49,10 +59,11 @@ typedef struct { uint8 pad_4A[0x06]; uint8 var_50; uint8 var_51; - uint8 pad_52[0x69]; - uint16 var_BB; - uint16 var_BD; - uint8 pad_BF[0x0D]; + uint8 pad_52[0x2E]; + uint8 var_BB; + uint8 var_BC; + uint8 var_BD; + uint8 pad_BE[0x0E]; uint8 var_CC; uint8 pad_CD[0x09]; uint8 var_D6; diff --git a/src/window_options.c b/src/window_options.c index 8190d761ed..342023204f 100644 --- a/src/window_options.c +++ b/src/window_options.c @@ -526,7 +526,7 @@ static void window_options_dropdown() case WIDX_MUSIC_DROPDOWN: RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_MUSIC, uint8) = (uint8)dropdownIndex; config_save(); - RCT2_CALLPROC_EBPSAFE(0x006BCA9F); + stop_ride_music();//RCT2_CALLPROC_EBPSAFE(0x006BCA9F); window_invalidate(w); break; case WIDX_SOUND_QUALITY_DROPDOWN: From ba6d0bee30fd1fcf57c99c7a6d93cfa4406f6519 Mon Sep 17 00:00:00 2001 From: Jackson Davis Date: Mon, 1 Sep 2014 16:55:51 +0100 Subject: [PATCH 2/7] First pass at 6EE65A --- src/window_footpath.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/window_footpath.c b/src/window_footpath.c index 451816cb38..db6146c5a8 100644 --- a/src/window_footpath.c +++ b/src/window_footpath.c @@ -120,6 +120,7 @@ static void window_footpath_tooldrag(); static void window_footpath_toolup(); static void window_footpath_invalidate(); static void window_footpath_paint(); +static void sub_6EE65A(rct_window* w); static void* window_footpath_events[] = { window_footpath_close, @@ -201,7 +202,7 @@ void window_footpath_open() (1 << WIDX_CONSTRUCT_BRIDGE_OR_TUNNEL); window_init_scroll_widgets(window); - RCT2_CALLPROC_EBPSAFE(0x006EE65A); + sub_6EE65A(window); //RCT2_CALLPROC_EBPSAFE(0x006EE65A); show_gridlines(); window->colours[0] = 24; window->colours[1] = 24; @@ -825,4 +826,38 @@ loc_6A78EF: loc_6A79B0: RCT2_CALLPROC_EBPSAFE(0x006A855C); -} \ No newline at end of file +} + +static void sub_6EE65A(rct_window* window) +{ + uint16 ax = window->x; + uint16 bx = window->y; + uint16 cx = window->width; + uint16 dx = window->height; + cx += ax; + dx += bx; + for (rct_window* w = g_window_list; w < RCT2_GLOBAL(RCT2_ADDRESS_NEW_WINDOW_PTR, rct_window*); w++) { + if (w == window) + continue; + if (w->flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT)) + continue; + if (w->x >= cx) + continue; + if (w->x + w->width <= ax) + continue; + if (w->y >= dx) + continue; + if (w->y + w->height <= bx) + continue; + window_invalidate(w); + cx += 13; + if (cx >= RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16)) + continue; + cx -= 10; + cx -= w->x; + w->x += cx; + window_invalidate(w); + if (w->viewport != NULL) + w->viewport->x += cx; + } +} From f0d42616598c60b792bf1fbfec58a526cd1a8997 Mon Sep 17 00:00:00 2001 From: Jackson Davis Date: Mon, 1 Sep 2014 17:10:15 +0100 Subject: [PATCH 3/7] Move 6EE65A to window.c + minor refactor --- src/window.c | 35 +++++++++++++++++++++++++++++++++++ src/window.h | 1 + src/window_footpath.c | 36 +----------------------------------- 3 files changed, 37 insertions(+), 35 deletions(-) diff --git a/src/window.c b/src/window.c index 355d5770bf..e81a530965 100644 --- a/src/window.c +++ b/src/window.c @@ -1511,3 +1511,38 @@ void window_align_tabs( rct_window *w, uint8 start_tab_id, uint8 end_tab_id ) } } } + +/** + * Finds overlapping windows and moves them if possible + * rct2: 0x006EE65A + */ +void window_move_overlapping(rct_window* window) +{ + uint16 cx = window->width + window->x; + uint16 dx = window->height + window->y; + + for (rct_window* w = g_window_list; w < RCT2_GLOBAL(RCT2_ADDRESS_NEW_WINDOW_PTR, rct_window*); w++) { + if (w == window) + continue; + if (w->flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT)) + continue; + if (w->x >= cx) + continue; + if (w->x + w->width <= window->x) + continue; + if (w->y >= dx) + continue; + if (w->y + w->height <= window->y) + continue; + window_invalidate(w); + cx += 13; + if (cx >= RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16)) + continue; + cx -= 10; + cx -= w->x; + w->x += cx; + window_invalidate(w); + if (w->viewport != NULL) + w->viewport->x += cx; + } +} diff --git a/src/window.h b/src/window.h index 1098eba380..440ed28b40 100644 --- a/src/window.h +++ b/src/window.h @@ -469,6 +469,7 @@ void window_staff_init_vars(); void window_event_helper(rct_window* w, short widgetIndex, WINDOW_EVENTS event); void RCT2_CALLPROC_WE_MOUSE_DOWN(int address, int widgetIndex, rct_window*w, rct_widget* widget); +void window_move_overlapping(rct_window* window); #ifdef _MSC_VER #define window_get_register(w) \ diff --git a/src/window_footpath.c b/src/window_footpath.c index db6146c5a8..f852be5ecc 100644 --- a/src/window_footpath.c +++ b/src/window_footpath.c @@ -120,7 +120,6 @@ static void window_footpath_tooldrag(); static void window_footpath_toolup(); static void window_footpath_invalidate(); static void window_footpath_paint(); -static void sub_6EE65A(rct_window* w); static void* window_footpath_events[] = { window_footpath_close, @@ -202,7 +201,7 @@ void window_footpath_open() (1 << WIDX_CONSTRUCT_BRIDGE_OR_TUNNEL); window_init_scroll_widgets(window); - sub_6EE65A(window); //RCT2_CALLPROC_EBPSAFE(0x006EE65A); + window_move_overlapping(window); show_gridlines(); window->colours[0] = 24; window->colours[1] = 24; @@ -828,36 +827,3 @@ loc_6A79B0: RCT2_CALLPROC_EBPSAFE(0x006A855C); } -static void sub_6EE65A(rct_window* window) -{ - uint16 ax = window->x; - uint16 bx = window->y; - uint16 cx = window->width; - uint16 dx = window->height; - cx += ax; - dx += bx; - for (rct_window* w = g_window_list; w < RCT2_GLOBAL(RCT2_ADDRESS_NEW_WINDOW_PTR, rct_window*); w++) { - if (w == window) - continue; - if (w->flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT)) - continue; - if (w->x >= cx) - continue; - if (w->x + w->width <= ax) - continue; - if (w->y >= dx) - continue; - if (w->y + w->height <= bx) - continue; - window_invalidate(w); - cx += 13; - if (cx >= RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16)) - continue; - cx -= 10; - cx -= w->x; - w->x += cx; - window_invalidate(w); - if (w->viewport != NULL) - w->viewport->x += cx; - } -} From fc2c3bdb51a1d3a9f925bc3d1ff2696f5c29f981 Mon Sep 17 00:00:00 2001 From: Jackson Davis Date: Mon, 1 Sep 2014 22:06:50 +0200 Subject: [PATCH 4/7] Rename 6EE65A to push_others_right + refactor --- src/window.c | 67 +++++++++++++++++++++---------------------- src/window.h | 2 +- src/window_footpath.c | 2 +- 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/src/window.c b/src/window.c index e81a530965..9e04d0982e 100644 --- a/src/window.c +++ b/src/window.c @@ -828,6 +828,38 @@ rct_window *window_bring_to_front(rct_window *w) return w; } +/** + * + * rct2: 0x006EE65A + */ +void window_push_others_right(rct_window* window) +{ + + for (rct_window* w = g_window_list; w < RCT2_GLOBAL(RCT2_ADDRESS_NEW_WINDOW_PTR, rct_window*); w++) { + if (w == window) + continue; + if (w->flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT)) + continue; + if (w->x >= window->x + window->width) + continue; + if (w->x + w->width <= window->x) + continue; + if (w->y >= window->y + window->height) + continue; + if (w->y + w->height <= window->y) + continue; + + window_invalidate(w); + if (window->x + window->width + 13 >= RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16)) + continue; + uint16 push_amount = window->x + window->height - w->x + 3; + w->x += push_amount; + window_invalidate(w); + if (w->viewport != NULL) + w->viewport->x += push_amount; + } +} + /** * * rct2: 0x006EE6EA @@ -871,6 +903,7 @@ void window_push_others_below(rct_window *w1) } } + /** * * rct2: 0x006EE2E4 @@ -1512,37 +1545,3 @@ void window_align_tabs( rct_window *w, uint8 start_tab_id, uint8 end_tab_id ) } } -/** - * Finds overlapping windows and moves them if possible - * rct2: 0x006EE65A - */ -void window_move_overlapping(rct_window* window) -{ - uint16 cx = window->width + window->x; - uint16 dx = window->height + window->y; - - for (rct_window* w = g_window_list; w < RCT2_GLOBAL(RCT2_ADDRESS_NEW_WINDOW_PTR, rct_window*); w++) { - if (w == window) - continue; - if (w->flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT)) - continue; - if (w->x >= cx) - continue; - if (w->x + w->width <= window->x) - continue; - if (w->y >= dx) - continue; - if (w->y + w->height <= window->y) - continue; - window_invalidate(w); - cx += 13; - if (cx >= RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16)) - continue; - cx -= 10; - cx -= w->x; - w->x += cx; - window_invalidate(w); - if (w->viewport != NULL) - w->viewport->x += cx; - } -} diff --git a/src/window.h b/src/window.h index 440ed28b40..86aa034349 100644 --- a/src/window.h +++ b/src/window.h @@ -396,6 +396,7 @@ int window_get_scroll_size(rct_window *w, int scrollIndex, int *width, int *heig rct_window *window_bring_to_front_by_id(rct_windowclass cls, rct_windownumber number); rct_window *window_bring_to_front(rct_window *w); +void window_push_others_right(rct_window *w); void window_push_others_below(rct_window *w1); rct_window *window_get_main(); @@ -469,7 +470,6 @@ void window_staff_init_vars(); void window_event_helper(rct_window* w, short widgetIndex, WINDOW_EVENTS event); void RCT2_CALLPROC_WE_MOUSE_DOWN(int address, int widgetIndex, rct_window*w, rct_widget* widget); -void window_move_overlapping(rct_window* window); #ifdef _MSC_VER #define window_get_register(w) \ diff --git a/src/window_footpath.c b/src/window_footpath.c index f852be5ecc..01e4db3cb5 100644 --- a/src/window_footpath.c +++ b/src/window_footpath.c @@ -201,7 +201,7 @@ void window_footpath_open() (1 << WIDX_CONSTRUCT_BRIDGE_OR_TUNNEL); window_init_scroll_widgets(window); - window_move_overlapping(window); + window_push_others_right(window); show_gridlines(); window->colours[0] = 24; window->colours[1] = 24; From 4b3150449aaf99de86dfe409408c3e6b1b1206b1 Mon Sep 17 00:00:00 2001 From: Jackson Davis Date: Mon, 1 Sep 2014 22:22:54 +0200 Subject: [PATCH 5/7] Fix typo --- src/window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/window.c b/src/window.c index 9e04d0982e..4351d90d1a 100644 --- a/src/window.c +++ b/src/window.c @@ -852,7 +852,7 @@ void window_push_others_right(rct_window* window) window_invalidate(w); if (window->x + window->width + 13 >= RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16)) continue; - uint16 push_amount = window->x + window->height - w->x + 3; + uint16 push_amount = window->x + window->width - w->x + 3; w->x += push_amount; window_invalidate(w); if (w->viewport != NULL) From 6de4fa1fcf9a284b26637e79d1127199f3252a03 Mon Sep 17 00:00:00 2001 From: zsilencer Date: Mon, 1 Sep 2014 15:42:56 -0600 Subject: [PATCH 6/7] low-hanging fruit --- src/addresses.h | 3 + src/osinterface.c | 174 +++++++++++++++++++++++++++++++++++++++++++++- src/osinterface.h | 5 ++ 3 files changed, 181 insertions(+), 1 deletion(-) diff --git a/src/addresses.h b/src/addresses.h index 80ef4cbe20..c3a3f343db 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -170,6 +170,9 @@ #define RCT2_ADDRESS_CMDLINE 0x009E2D98 +#define RCT2_ADDRESS_PROGRESSBAR_HFONT 0x009E2DEC +#define RCT2_ADDRESS_PROGRESSBAR_HWND 0x009E2DF8 + #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/osinterface.c b/src/osinterface.c index 9213603e7d..4f8a1565e3 100644 --- a/src/osinterface.c +++ b/src/osinterface.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include @@ -442,6 +441,179 @@ void osinterface_set_fullscreen_mode(int mode){ config_save(); } +/** + * + * rct2: 0x00407E6E + */ +int osinterface_progressbar_create(char* title, int a2) +{ + DWORD style = WS_VISIBLE | WS_BORDER | WS_DLGFRAME; + if (a2) { + style = WS_VISIBLE | WS_BORDER | WS_DLGFRAME | PBS_SMOOTH; + } + int width = 340; + int height = GetSystemMetrics(SM_CYCAPTION) + 24; + HWND hwnd = CreateWindowExA(WS_EX_TOPMOST | WS_EX_DLGMODALFRAME, "msctls_progress32", title, style, (RCT2_GLOBAL(0x01423C08, sint32) - width) / 2, (RCT2_GLOBAL(0x01423C0C, sint32) - height) / 2, width, height, 0, 0, RCT2_GLOBAL(RCT2_ADDRESS_HINSTANCE, HINSTANCE), 0); + RCT2_GLOBAL(RCT2_ADDRESS_PROGRESSBAR_HWND, HWND) = hwnd; + if (hwnd) { + RCT2_GLOBAL(0x009E2DFC, uint32) = 1; + if (RCT2_GLOBAL(RCT2_ADDRESS_PROGRESSBAR_HFONT, HFONT)) { + SendMessageA(hwnd, WM_SETFONT, (WPARAM)RCT2_GLOBAL(RCT2_ADDRESS_PROGRESSBAR_HFONT, HFONT), 1); + } + SetWindowTextA(hwnd, title); + osinterface_progressbar_setmax(0xFF); + osinterface_progressbar_setpos(0); + return 1; + } else { + return 0; + } +} + +/** + * + * rct2: 0x00407F16 + */ +int osinterface_progressbar_destroy() +{ + if (DestroyWindow(RCT2_GLOBAL(RCT2_ADDRESS_PROGRESSBAR_HWND, HWND))) { + RCT2_GLOBAL(0x009E2DFC, uint32) = 0; + return 1; + } else { + return 0; + } +} + +/** + * + * rct2: 0x00407F2E + */ +LRESULT osinterface_progressbar_setmax(int max) +{ + SendMessageA(RCT2_GLOBAL(RCT2_ADDRESS_PROGRESSBAR_HWND, HWND), PBM_SETRANGE, MAKEWPARAM(0, max), 0); + return SendMessageA(RCT2_GLOBAL(RCT2_ADDRESS_PROGRESSBAR_HWND, HWND), PBM_SETSTEP, 1, 0); +} + +/** + * + * rct2: 0x00407F60 + */ +LRESULT osinterface_progressbar_setpos(WPARAM wparam) +{ + return SendMessageA(RCT2_GLOBAL(RCT2_ADDRESS_PROGRESSBAR_HWND, HWND), PBM_SETPOS, wparam, 0); +} + +/** + * + * rct2: 0x00407F78 + */ +int osinterface_file_seek_from_begin(HANDLE handle, int offset) +{ + return SetFilePointer(handle, offset, 0, FILE_BEGIN); +} + +/** + * + * rct2: 0x00407F8B + */ +int osinterface_file_seek_from_current(HANDLE handle, int offset) +{ + return SetFilePointer(handle, offset, 0, FILE_CURRENT); +} + +/** + * + * rct2: 0x00407F9E + */ +int osinterface_file_seek_from_end(HANDLE handle, int offset) +{ + return SetFilePointer(handle, offset, 0, FILE_END); +} + +/** + * + * rct2: 0x00407FB1 + */ +int osinterface_file_read(HANDLE handle, void* data, int size) +{ + DWORD read; + BOOL result; + if (size == -1) { + DWORD current = SetFilePointer(handle, 0, 0, FILE_CURRENT); + DWORD remaining = SetFilePointer(handle, 0, 0, FILE_END) - current; + result = ReadFile(handle, data, remaining, &read, 0); + } else { + result = ReadFile(handle, data, size, &read, 0); + } + if (result) { + return read; + } else { + return -1; + } +} + +/** + * + * rct2: 0x00408024 + */ +int osinterface_file_write(HANDLE handle, const void* data, int size) +{ + DWORD written; + if (WriteFile(handle, data, size, &written, 0)) { + return written; + } else { + return -1; + } +} + +/** + * + * rct2: 0x0040804A + */ +int osinterface_file_close(HANDLE handle) +{ + if (handle) { + return CloseHandle(handle); + } else { + return 1; + } +} + +/** + * + * rct2: 0x00408060 + */ +HANDLE osinterface_file_open(char* filename) +{ + return CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS | FILE_ATTRIBUTE_NORMAL, 0); +} + +/** + * + * rct2: 0x0040807D + */ +HANDLE osinterface_file_create(char* filename) +{ + return CreateFileA(filename, GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); +} + +/** + * + * rct2: 0x00408099 + */ +int osinterface_file_move(char* srcfilename, char* dstfilename) +{ + return (MoveFileA(srcfilename, dstfilename) != 0) - 1; +} + +/** + * + * rct2: 0x004080AF + */ +int osinterface_file_delete(char* filename) +{ + return (DeleteFileA(filename) != 0) - 1; +} + /** * * rct2: 0x004080EA diff --git a/src/osinterface.h b/src/osinterface.h index 6d2cade7aa..8465a5f1d5 100644 --- a/src/osinterface.h +++ b/src/osinterface.h @@ -21,6 +21,8 @@ #ifndef _SDL_INTERFACE_H_ #define _SDL_INTERFACE_H_ +#include + enum { CURSOR_UP = 0, CURSOR_DOWN = 1, @@ -79,6 +81,9 @@ void osinterface_update_palette(char* colours, int start_index, int num_colours) void osinterface_set_fullscreen_mode(int mode); +LRESULT osinterface_progressbar_setmax(int max); +LRESULT osinterface_progressbar_setpos(WPARAM wparam); + void osinterface_set_cursor(char cursor); int osinterface_open_common_file_dialog(int type, char *title, char *filename, char *filterPattern, char *filterName); From 6dd4110b8926a42a26d22255e8c1ad7845df7467 Mon Sep 17 00:00:00 2001 From: zsilencer Date: Mon, 1 Sep 2014 19:59:39 -0600 Subject: [PATCH 7/7] useless functions decompiled --- src/addresses.h | 2 +- src/osinterface.c | 84 +++++++++++++++++++++++++++++++++++++++++++---- src/osinterface.h | 16 +++++++-- 3 files changed, 92 insertions(+), 10 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index c3a3f343db..9ddbfa0cc6 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -170,7 +170,7 @@ #define RCT2_ADDRESS_CMDLINE 0x009E2D98 -#define RCT2_ADDRESS_PROGRESSBAR_HFONT 0x009E2DEC +#define RCT2_ADDRESS_HFONT 0x009E2DEC #define RCT2_ADDRESS_PROGRESSBAR_HWND 0x009E2DF8 #define RCT2_ADDRESS_LAND_RAISE_COST 0x009E2E1C diff --git a/src/osinterface.c b/src/osinterface.c index 4f8a1565e3..9cd7ab2197 100644 --- a/src/osinterface.c +++ b/src/osinterface.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "addresses.h" #include "config.h" @@ -441,6 +442,77 @@ void osinterface_set_fullscreen_mode(int mode){ config_save(); } +/** + * + * rct2: 0x00407978 + */ +int osinterface_407978(rct2_install_info* install_info, char* source, char* font, uint8 charset) +{ + char subkey[MAX_PATH]; + char subkey2[MAX_PATH]; + strcpy(subkey, "Software\\Infogrames\\"); + strcat(subkey, source); + strcpy(subkey2, "Software\\Fish Technology Group\\"); + strcat(subkey2, source); + LOGFONTA lf; + memset(&lf, 0, sizeof(lf)); + lf.lfCharSet = charset; + lf.lfHeight = 12; + lf.lfWeight = 400; + strcpy(lf.lfFaceName, font); + RCT2_GLOBAL(RCT2_ADDRESS_HFONT, HFONT) = CreateFontIndirectA(&lf); + HKEY hkey; + if (RegOpenKeyA(HKEY_LOCAL_MACHINE, subkey, &hkey) != ERROR_SUCCESS && RegOpenKeyA(HKEY_LOCAL_MACHINE, subkey2, &hkey) != ERROR_SUCCESS) { + return 0; + } else { + DWORD type; + DWORD size = 260; + RegQueryValueExA(hkey, "Title", 0, &type, install_info->title, &size); + size = 260; + RegQueryValueExA(hkey, "Path", 0, &type, install_info->path, &size); + install_info->var_20C = 235960; + size = 4; + RegQueryValueExA(hkey, "InstallLevel", 0, &type, (LPBYTE)&install_info->installlevel, &size); + for (int i = 0; i <= 15; i++) { + char name[100]; + sprintf(name, "AddonPack%d", i); + size = sizeof(install_info->addon[i]); + if (RegQueryValueExA(hkey, name, 0, &type, install_info->addon[i], &size) == ERROR_SUCCESS) { + install_info->addons |= (1 << i); + } + } + RegCloseKey(hkey); + return 1; + } +} + +/** + * + * rct2: 0x00407D80 + */ +int osinterface_get_cursor_pos(int* x, int* y) +{ + POINT point; + GetCursorPos(&point); + *x = point.x; + *y = point.y; +} + +/** + * + * rct2: 0x00407E15 + */ +int osinterface_print_window_message(UINT msg, WPARAM wparam, LPARAM lparam) +{ + const char* msgname = "NULL"; + // get the string representation of the msg id, from 190 different values in 0x009A61D8 - 0x009A8873 + // not going to bother reading those since this function is going to be unused and taken out anyways + char temp[1024]; + sprintf(temp, "Message id = %s (%i), wParam = 0x%x, lParam = 0x%x\n", msgname, msg, wparam, lparam); + OutputDebugStringA(temp); + return 1; +} + /** * * rct2: 0x00407E6E @@ -457,8 +529,8 @@ int osinterface_progressbar_create(char* title, int a2) RCT2_GLOBAL(RCT2_ADDRESS_PROGRESSBAR_HWND, HWND) = hwnd; if (hwnd) { RCT2_GLOBAL(0x009E2DFC, uint32) = 1; - if (RCT2_GLOBAL(RCT2_ADDRESS_PROGRESSBAR_HFONT, HFONT)) { - SendMessageA(hwnd, WM_SETFONT, (WPARAM)RCT2_GLOBAL(RCT2_ADDRESS_PROGRESSBAR_HFONT, HFONT), 1); + if (RCT2_GLOBAL(RCT2_ADDRESS_HFONT, HFONT)) { + SendMessageA(hwnd, WM_SETFONT, (WPARAM)RCT2_GLOBAL(RCT2_ADDRESS_HFONT, HFONT), 1); } SetWindowTextA(hwnd, title); osinterface_progressbar_setmax(0xFF); @@ -487,19 +559,19 @@ int osinterface_progressbar_destroy() * * rct2: 0x00407F2E */ -LRESULT osinterface_progressbar_setmax(int max) +void osinterface_progressbar_setmax(int max) { SendMessageA(RCT2_GLOBAL(RCT2_ADDRESS_PROGRESSBAR_HWND, HWND), PBM_SETRANGE, MAKEWPARAM(0, max), 0); - return SendMessageA(RCT2_GLOBAL(RCT2_ADDRESS_PROGRESSBAR_HWND, HWND), PBM_SETSTEP, 1, 0); + SendMessageA(RCT2_GLOBAL(RCT2_ADDRESS_PROGRESSBAR_HWND, HWND), PBM_SETSTEP, 1, 0); } /** * * rct2: 0x00407F60 */ -LRESULT osinterface_progressbar_setpos(WPARAM wparam) +void osinterface_progressbar_setpos(int pos) { - return SendMessageA(RCT2_GLOBAL(RCT2_ADDRESS_PROGRESSBAR_HWND, HWND), PBM_SETPOS, wparam, 0); + SendMessageA(RCT2_GLOBAL(RCT2_ADDRESS_PROGRESSBAR_HWND, HWND), PBM_SETPOS, MAKEWPARAM(pos, 0), 0); } /** diff --git a/src/osinterface.h b/src/osinterface.h index 8465a5f1d5..a9480bb0db 100644 --- a/src/osinterface.h +++ b/src/osinterface.h @@ -21,7 +21,7 @@ #ifndef _SDL_INTERFACE_H_ #define _SDL_INTERFACE_H_ -#include +#include "rct2.h" enum { CURSOR_UP = 0, @@ -68,6 +68,16 @@ typedef struct { int old; } openrct2_cursor; +typedef struct { + uint32 installlevel; + char title[260]; + char path[260]; + uint32 var_20C; + uint8 pad_210[0x100]; + char addon[15][0x80]; + uint32 addons; //0xB10 +} rct2_install_info; + extern openrct2_cursor gCursorState; extern const unsigned char *gKeysState; extern unsigned char *gKeysPressed; @@ -81,8 +91,8 @@ void osinterface_update_palette(char* colours, int start_index, int num_colours) void osinterface_set_fullscreen_mode(int mode); -LRESULT osinterface_progressbar_setmax(int max); -LRESULT osinterface_progressbar_setpos(WPARAM wparam); +void osinterface_progressbar_setmax(int max); +void osinterface_progressbar_setpos(int pos); void osinterface_set_cursor(char cursor);