From 268e7530c2088880ee48d8c68c43632488284577 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Thu, 16 Oct 2014 00:35:42 +0100 Subject: [PATCH] fix #525, creating a ride crashes when footpath window is open --- src/interface/window.h | 3 ++- src/ride/ride.c | 42 ++++++++++++++++++++---------------------- src/windows/ride.c | 6 ++++-- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/interface/window.h b/src/interface/window.h index d61753bbf9..518799508f 100644 --- a/src/interface/window.h +++ b/src/interface/window.h @@ -490,7 +490,8 @@ void window_park_rating_open(); void window_finances_open(); void window_finances_research_open(); void window_new_campaign_open(sint16 campaignType); -void window_ride_main_open(int rideIndex); +rct_window *window_ride_main_open(int rideIndex); +void window_ride_construct(rct_window *w); void window_ride_list_open(); void window_track_place_open(); void window_new_ride_open(); diff --git a/src/ride/ride.c b/src/ride/ride.c index 486406b05b..b9bd7d4e82 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -432,11 +432,7 @@ rct_map_element *ride_find_track_gap(rct_map_element *startTrackElement, int *ou return (rct_map_element*)esi; } -/** - * - * rct2: 0x006B4800 - */ -void ride_construct_new(ride_list_item listItem) +int ride_create_ride(ride_list_item listItem) { int eax, ebx, ecx, edx, esi, edi, ebp; edx = *((uint16*)&listItem); @@ -450,27 +446,29 @@ void ride_construct_new(ride_list_item listItem) esi = GAME_COMMAND_6; game_do_command_p(esi, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); - if (ebx == 0x80000000) { - return; - } + return ebx == 0x80000000 ? -1 : edi; +} - //Looks like edi became the ride index after the command. - eax = edi; +/** + * + * rct2: 0x006B4800 + */ +void ride_construct_new(ride_list_item listItem) +{ rct_window *w; + int rideIndex; - //TODO: replace with window_ride_main_open(eax) - // window_ride_main_open(eax); - RCT2_CALLFUNC_X(0x006ACC28, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); - window_get_register(w); + rideIndex = ride_create_ride(listItem); + if (rideIndex == -1) + return; - ecx = w->classification; - edx = 0x13; - ebp = (int)w; - //TODO: replace with window_ride_main_mouseup() after ride-window_merge - // window_ride_main_mouseup(); - 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); + // Open construction window + // HACK In the original game this created a mouse up event. This has been + // replaced with a direct call to the function that gets called. + // Eventually should be changed so the ride window does not need to be opened. + w = window_ride_main_open(rideIndex); + window_ride_construct(w); + window_close_by_id(WC_RIDE, rideIndex); } /** diff --git a/src/windows/ride.c b/src/windows/ride.c index 8e19b84811..530a5c6d0b 100644 --- a/src/windows/ride.c +++ b/src/windows/ride.c @@ -1142,7 +1142,7 @@ rct_window *window_ride_open(int rideIndex) * * rct2: 0x006ACC28 */ -void window_ride_main_open(int rideIndex) +rct_window *window_ride_main_open(int rideIndex) { rct_window *w; @@ -1173,6 +1173,8 @@ void window_ride_main_open(int rideIndex) window_init_scroll_widgets(w); w->ride.view = 0; window_ride_init_viewport(w); + + return w; } /** @@ -1365,7 +1367,7 @@ static void window_ride_init_viewport(rct_window *w) * * rct2: 0x006B4971 */ -static void window_ride_construct(rct_window *w) +void window_ride_construct(rct_window *w) { int rideIndex = w->number;