From 4f5dc9b33e12729276b9b9319a67c1e918789278 Mon Sep 17 00:00:00 2001 From: Balletie Date: Tue, 2 Sep 2014 17:52:23 +0200 Subject: [PATCH 1/5] Initial crack at decompiling 0x006B4800 --- src/game.h | 2 +- src/ride.c | 42 +++++++++++++++++++++++++++++++++++++++++- src/ride.h | 1 + src/window_new_ride.c | 5 +++-- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/game.h b/src/game.h index 1f87d944c0..b3d4f15adb 100644 --- a/src/game.h +++ b/src/game.h @@ -25,7 +25,7 @@ enum GAME_COMMAND { GAME_COMMAND_0, GAME_COMMAND_1, GAME_COMMAND_TOGGLE_PAUSE, // 2 - GAME_COMMAND_3, + GAME_COMMAND_3, //Has something to do with ride construction GAME_COMMAND_4, GAME_COMMAND_LOAD_OR_QUIT, // 5 GAME_COMMAND_6, diff --git a/src/ride.c b/src/ride.c index 546817e186..c7ad062a1b 100644 --- a/src/ride.c +++ b/src/ride.c @@ -20,6 +20,7 @@ #include #include "addresses.h" +#include "game.h" #include "map.h" #include "news_item.h" #include "sprite.h" @@ -422,6 +423,45 @@ rct_map_element *ride_find_track_gap(rct_map_element *startTrackElement, int *ou return (rct_map_element*)esi; } +/** + * + * rct2: 0x006B4800 + */ +void ride_construct_new(uint8 ah, uint8 al) +{ + int eax, ebx, ecx, edx, esi, edi, ebp; + edx = 0; + edx = ah; + edx << 8; //Set high byte + edx += al;//Set low byte + eax = 0; + ecx = 0; + ebx = 1; + + RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TITLE, uint16) = 0x3DC; + + game_do_command_p(GAME_COMMAND_6, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + if (ebx == 0x80000000) { + return; + } + + //Looks like edi became the ride index after the command. + eax = edi; + rct_window *w; + short widgetIndex; + + //TODO: replace with window_ride_main_open(eax) + // window_ride_main_open(eax); + RCT2_CALLPROC_X(0x006ACC28, eax, 0, 0, 0, 0, 0, 0); + window_widget_get_registers(w, widgetIndex); + + //TODO: replace with window_ride_main_mouseup() after ride-window_merge + // window_ride_main_mouseup(); + RCT2_CALLPROC_X(0x006AF17E, 0, 0, 0, widgetIndex, (int)w, 0, 0); + rct_window *ride_window = window_find_by_id(w->classification, w->number); //class here + window_close(ride_window); +} + /** * * rct2: 0x006CC056 @@ -431,4 +471,4 @@ int ride_try_construct(rct_map_element *trackMapElement) // Success stored in carry flag which can't be accessed after call using is macro RCT2_CALLPROC_X(0x006CC056, 0, 0, 0, (int)trackMapElement, 0, 0, 0); return 1; -} \ No newline at end of file +} diff --git a/src/ride.h b/src/ride.h index dca498d637..3639d80577 100644 --- a/src/ride.h +++ b/src/ride.h @@ -384,6 +384,7 @@ void ride_update_favourited_stat(); void ride_check_all_reachable(); rct_map_element *sub_6CAF80(int rideIndex, int *outX, int *outY); rct_map_element *ride_find_track_gap(rct_map_element *startTrackElement, int *outX, int *outY); +void ride_construct_new(uint8 ah, uint8 al); int ride_try_construct(rct_map_element *trackMapElement); #endif diff --git a/src/window_new_ride.c b/src/window_new_ride.c index 9b061810f0..9df4bdec1d 100644 --- a/src/window_new_ride.c +++ b/src/window_new_ride.c @@ -989,5 +989,6 @@ static void window_new_ride_select(rct_window *w) } // Show ride construction window - RCT2_CALLPROC_X(0x006B4800, *((sint16*)&item), 0, 0, 0, 0, 0, 0); -} \ No newline at end of file + //RCT2_CALLPROC_X(0x006B4800, *((sint16*)&item), 0, 0, 0, 0, 0, 0); + ride_construct_new(item.type, item.entry_index); +} From 7cc79d95c1670bf042cce221ecc66a2e761ccbb2 Mon Sep 17 00:00:00 2001 From: Jackson Davis Date: Tue, 2 Sep 2014 17:56:30 +0200 Subject: [PATCH 2/5] First pass at 6CB70A --- src/window_footpath.c | 47 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/src/window_footpath.c b/src/window_footpath.c index 01e4db3cb5..626049e2eb 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_6CB70A(uint8 al); static void* window_footpath_events[] = { window_footpath_close, @@ -226,7 +227,7 @@ static void window_footpath_close() window_get_register(w); RCT2_CALLPROC_EBPSAFE(0x006A7831); - RCT2_CALLPROC_X(0x006CB70A, 0, 0, 0, 0, 0, 0, 0); + sub_6CB70A(0); //RCT2_CALLPROC_X(0x006CB70A, 0, 0, 0, 0, 0, 0, 0); RCT2_CALLPROC_EBPSAFE(0x0068AB1B); RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_FLAGS, uint16) &= ~2; window_invalidate_by_id(WC_TOP_TOOLBAR, 0); @@ -677,7 +678,7 @@ static int window_footpath_set_provisional_path(int type, int x, int y, int z, i eax = 3; if (RCT2_GLOBAL(0x00F3EFA4, uint8) & 2) eax = 1; - RCT2_CALLPROC_X(0x006CB70A, eax, 0, 0, 0, 0, 0, 0); + sub_6CB70A((uint8)eax); //RCT2_CALLPROC_X(0x006CB70A, eax, 0, 0, 0, 0, 0, 0); } return cost; @@ -827,3 +828,45 @@ loc_6A79B0: RCT2_CALLPROC_EBPSAFE(0x006A855C); } +static void sub_6CB70A(uint8 al) +{ + rct_window* window = window_get_main(); + + if(window != NULL) { + rct_viewport* edi = window->viewport; + uint32 invalidate = 0; + + switch(al) { + case 0: { //Set all these flags to 0, and invalidate if any were active + uint16 mask = VIEWPORT_FLAG_UNDERGROUND_INSIDE | VIEWPORT_FLAG_SEETHROUGH_RIDES | + VIEWPORT_FLAG_SEETHROUGH_SCENERY | VIEWPORT_FLAG_INVISIBLE_SUPPORTS | + VIEWPORT_FLAG_LAND_HEIGHTS | VIEWPORT_FLAG_TRACK_HEIGHTS | + VIEWPORT_FLAG_PATH_HEIGHTS | VIEWPORT_FLAG_INVISIBLE_PEEPS | + VIEWPORT_FLAG_HIDE_BASE | VIEWPORT_FLAG_HIDE_VERTICAL; + + invalidate += edi->flags & mask; + edi->flags &= ~mask; + break; + } + case 1: //6CB79D + case 4: //6CB7C4 + //Set underground on, invalidate if it was off + invalidate += !(edi->flags & VIEWPORT_FLAG_UNDERGROUND_INSIDE); + edi->flags |= VIEWPORT_FLAG_UNDERGROUND_INSIDE; + break; + case 2: //6CB7EB + //Set track heights on, invalidate if off + invalidate += !(edi->flags & VIEWPORT_FLAG_TRACK_HEIGHTS); + edi->flags |= VIEWPORT_FLAG_TRACK_HEIGHTS; + break; + case 3: //6CB7B1 + case 5: //6CB7D8 + //Set underground off, invalidate if it was on + invalidate += edi->flags & VIEWPORT_FLAG_UNDERGROUND_INSIDE; + edi->flags &= ~((uint16)VIEWPORT_FLAG_UNDERGROUND_INSIDE); + break; + } + if (invalidate != 0) + window_invalidate(window); + } +} From c6bb6f5809ed76df3d7605da57a077d38bc6c8a3 Mon Sep 17 00:00:00 2001 From: Jackson Davis Date: Tue, 2 Sep 2014 19:10:49 +0200 Subject: [PATCH 3/5] Move to viewport.c --- src/viewport.c | 47 +++++++++++++++++++++++++++++++++++++++++++ src/viewport.h | 1 + src/window_footpath.c | 47 ++----------------------------------------- 3 files changed, 50 insertions(+), 45 deletions(-) diff --git a/src/viewport.c b/src/viewport.c index 4697b57df3..e47bc4f653 100644 --- a/src/viewport.c +++ b/src/viewport.c @@ -1039,3 +1039,50 @@ void hide_construction_rights() } } } + +/** + * + * rct2: 0x006CB70A + */ +void viewport_set_visibility(uint8 mode) +{ + rct_window* window = window_get_main(); + + if(window != NULL) { + rct_viewport* edi = window->viewport; + uint32 invalidate = 0; + + switch(mode) { + case 0: { //Set all these flags to 0, and invalidate if any were active + uint16 mask = VIEWPORT_FLAG_UNDERGROUND_INSIDE | VIEWPORT_FLAG_SEETHROUGH_RIDES | + VIEWPORT_FLAG_SEETHROUGH_SCENERY | VIEWPORT_FLAG_INVISIBLE_SUPPORTS | + VIEWPORT_FLAG_LAND_HEIGHTS | VIEWPORT_FLAG_TRACK_HEIGHTS | + VIEWPORT_FLAG_PATH_HEIGHTS | VIEWPORT_FLAG_INVISIBLE_PEEPS | + VIEWPORT_FLAG_HIDE_BASE | VIEWPORT_FLAG_HIDE_VERTICAL; + + invalidate += edi->flags & mask; + edi->flags &= ~mask; + break; + } + case 1: //6CB79D + case 4: //6CB7C4 + //Set underground on, invalidate if it was off + invalidate += !(edi->flags & VIEWPORT_FLAG_UNDERGROUND_INSIDE); + edi->flags |= VIEWPORT_FLAG_UNDERGROUND_INSIDE; + break; + case 2: //6CB7EB + //Set track heights on, invalidate if off + invalidate += !(edi->flags & VIEWPORT_FLAG_TRACK_HEIGHTS); + edi->flags |= VIEWPORT_FLAG_TRACK_HEIGHTS; + break; + case 3: //6CB7B1 + case 5: //6CB7D8 + //Set underground off, invalidate if it was on + invalidate += edi->flags & VIEWPORT_FLAG_UNDERGROUND_INSIDE; + edi->flags &= ~((uint16)VIEWPORT_FLAG_UNDERGROUND_INSIDE); + break; + } + if (invalidate != 0) + window_invalidate(window); + } +} diff --git a/src/viewport.h b/src/viewport.h index 19c436d0e6..9b709f8d03 100644 --- a/src/viewport.h +++ b/src/viewport.h @@ -60,5 +60,6 @@ void show_land_rights(); void hide_land_rights(); void show_construction_rights(); void hide_construction_rights(); +void viewport_set_visibility(uint8 mode); #endif diff --git a/src/window_footpath.c b/src/window_footpath.c index 626049e2eb..1e70c75998 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_6CB70A(uint8 al); static void* window_footpath_events[] = { window_footpath_close, @@ -227,7 +226,7 @@ static void window_footpath_close() window_get_register(w); RCT2_CALLPROC_EBPSAFE(0x006A7831); - sub_6CB70A(0); //RCT2_CALLPROC_X(0x006CB70A, 0, 0, 0, 0, 0, 0, 0); + viewport_set_visibility(0); RCT2_CALLPROC_EBPSAFE(0x0068AB1B); RCT2_GLOBAL(RCT2_ADDRESS_MAP_SELECTION_FLAGS, uint16) &= ~2; window_invalidate_by_id(WC_TOP_TOOLBAR, 0); @@ -678,7 +677,7 @@ static int window_footpath_set_provisional_path(int type, int x, int y, int z, i eax = 3; if (RCT2_GLOBAL(0x00F3EFA4, uint8) & 2) eax = 1; - sub_6CB70A((uint8)eax); //RCT2_CALLPROC_X(0x006CB70A, eax, 0, 0, 0, 0, 0, 0); + viewport_set_visibility((uint8)eax); } return cost; @@ -828,45 +827,3 @@ loc_6A79B0: RCT2_CALLPROC_EBPSAFE(0x006A855C); } -static void sub_6CB70A(uint8 al) -{ - rct_window* window = window_get_main(); - - if(window != NULL) { - rct_viewport* edi = window->viewport; - uint32 invalidate = 0; - - switch(al) { - case 0: { //Set all these flags to 0, and invalidate if any were active - uint16 mask = VIEWPORT_FLAG_UNDERGROUND_INSIDE | VIEWPORT_FLAG_SEETHROUGH_RIDES | - VIEWPORT_FLAG_SEETHROUGH_SCENERY | VIEWPORT_FLAG_INVISIBLE_SUPPORTS | - VIEWPORT_FLAG_LAND_HEIGHTS | VIEWPORT_FLAG_TRACK_HEIGHTS | - VIEWPORT_FLAG_PATH_HEIGHTS | VIEWPORT_FLAG_INVISIBLE_PEEPS | - VIEWPORT_FLAG_HIDE_BASE | VIEWPORT_FLAG_HIDE_VERTICAL; - - invalidate += edi->flags & mask; - edi->flags &= ~mask; - break; - } - case 1: //6CB79D - case 4: //6CB7C4 - //Set underground on, invalidate if it was off - invalidate += !(edi->flags & VIEWPORT_FLAG_UNDERGROUND_INSIDE); - edi->flags |= VIEWPORT_FLAG_UNDERGROUND_INSIDE; - break; - case 2: //6CB7EB - //Set track heights on, invalidate if off - invalidate += !(edi->flags & VIEWPORT_FLAG_TRACK_HEIGHTS); - edi->flags |= VIEWPORT_FLAG_TRACK_HEIGHTS; - break; - case 3: //6CB7B1 - case 5: //6CB7D8 - //Set underground off, invalidate if it was on - invalidate += edi->flags & VIEWPORT_FLAG_UNDERGROUND_INSIDE; - edi->flags &= ~((uint16)VIEWPORT_FLAG_UNDERGROUND_INSIDE); - break; - } - if (invalidate != 0) - window_invalidate(window); - } -} From 51b377b7b99a7cba41423d2efa4029e7f6766c51 Mon Sep 17 00:00:00 2001 From: Balletie Date: Tue, 2 Sep 2014 20:33:23 +0200 Subject: [PATCH 4/5] Construction window is shown, but with very weird results still --- src/ride.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/ride.c b/src/ride.c index c7ad062a1b..bbf88144e4 100644 --- a/src/ride.c +++ b/src/ride.c @@ -437,10 +437,13 @@ void ride_construct_new(uint8 ah, uint8 al) eax = 0; ecx = 0; ebx = 1; + edi = 0; + esi = 0; RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TITLE, uint16) = 0x3DC; - game_do_command_p(GAME_COMMAND_6, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + esi = GAME_COMMAND_6; + game_do_command_p(esi, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); if (ebx == 0x80000000) { return; } @@ -452,12 +455,15 @@ void ride_construct_new(uint8 ah, uint8 al) //TODO: replace with window_ride_main_open(eax) // window_ride_main_open(eax); - RCT2_CALLPROC_X(0x006ACC28, eax, 0, 0, 0, 0, 0, 0); - window_widget_get_registers(w, widgetIndex); + RCT2_CALLFUNC_X(0x006ACC28, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + window_get_register(w); + ecx = w->classification; + edx = 0x13; + ebp = (int)w; //TODO: replace with window_ride_main_mouseup() after ride-window_merge // window_ride_main_mouseup(); - RCT2_CALLPROC_X(0x006AF17E, 0, 0, 0, widgetIndex, (int)w, 0, 0); + RCT2_CALLFUNC_X(0x006AF17E, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); rct_window *ride_window = window_find_by_id(w->classification, w->number); //class here window_close(ride_window); } From 91ca6401b5cf1dc436a09fc09e53301018dc6b71 Mon Sep 17 00:00:00 2001 From: Balletie Date: Tue, 2 Sep 2014 23:38:59 +0200 Subject: [PATCH 5/5] Fixes the last bug --- src/ride.c | 7 ++----- src/ride.h | 2 +- src/window_new_ride.c | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/ride.c b/src/ride.c index bbf88144e4..43798a15db 100644 --- a/src/ride.c +++ b/src/ride.c @@ -427,13 +427,10 @@ rct_map_element *ride_find_track_gap(rct_map_element *startTrackElement, int *ou * * rct2: 0x006B4800 */ -void ride_construct_new(uint8 ah, uint8 al) +void ride_construct_new(int list_item) { int eax, ebx, ecx, edx, esi, edi, ebp; - edx = 0; - edx = ah; - edx << 8; //Set high byte - edx += al;//Set low byte + edx = list_item; eax = 0; ecx = 0; ebx = 1; diff --git a/src/ride.h b/src/ride.h index 3639d80577..0c452f956d 100644 --- a/src/ride.h +++ b/src/ride.h @@ -384,7 +384,7 @@ void ride_update_favourited_stat(); void ride_check_all_reachable(); rct_map_element *sub_6CAF80(int rideIndex, int *outX, int *outY); rct_map_element *ride_find_track_gap(rct_map_element *startTrackElement, int *outX, int *outY); -void ride_construct_new(uint8 ah, uint8 al); +void ride_construct_new(int list_item); int ride_try_construct(rct_map_element *trackMapElement); #endif diff --git a/src/window_new_ride.c b/src/window_new_ride.c index 9df4bdec1d..d63c5ef2c8 100644 --- a/src/window_new_ride.c +++ b/src/window_new_ride.c @@ -990,5 +990,5 @@ static void window_new_ride_select(rct_window *w) // Show ride construction window //RCT2_CALLPROC_X(0x006B4800, *((sint16*)&item), 0, 0, 0, 0, 0, 0); - ride_construct_new(item.type, item.entry_index); + ride_construct_new(*((sint16*)&item)); }