From 749bd48f3d4a17cbb64d94f01e8c3753a1a560bb Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sat, 20 Dec 2014 10:43:30 +0000 Subject: [PATCH 1/3] Started adding a little bit of ride construct mouse down --- src/ride/ride.c | 8 ++-- src/windows/ride_construction.c | 77 ++++++++++++++++++++++++++++++++- 2 files changed, 79 insertions(+), 6 deletions(-) diff --git a/src/ride/ride.c b/src/ride/ride.c index bf93ac469b..9765daf053 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -702,9 +702,9 @@ static void ride_remove_peeps(int rideIndex) ride->var_14D |= 4; } -void sub_6C683D(int x, int y, int z, int direction, int type, int esi, int edi, int ebp) +int sub_6C683D(int x, int y, int z, int direction, int type, int esi, int edi, int ebp) { - RCT2_CALLPROC_X(0x006C683D, x, (direction << 8) | type, y, z, esi, edi, ebp); + return RCT2_CALLPROC_X(0x006C683D, x, (direction << 8) | type, y, z, esi, edi, ebp)&0x100; } void sub_6C96C0() @@ -893,7 +893,7 @@ int ride_modify(rct_map_element *mapElement, int x, int y) z = mapElement->base_height * 8; direction = mapElement->type & 3; type = mapElement->properties.track.type; - sub_6C683D(x, y, z, direction, type, 0, 0, 0); + if (sub_6C683D(x, y, z, direction, type, 0, 0, 0)) return 0; RCT2_GLOBAL(0x00F440A7, uint8) = rideIndex; RCT2_GLOBAL(0x00F440A6, uint8) = 3; @@ -905,7 +905,7 @@ int ride_modify(rct_map_element *mapElement, int x, int y) RCT2_GLOBAL(0x00F440B0, uint8) = 0; RCT2_GLOBAL(0x00F440B1, uint8) = 0; - if (RCT2_GLOBAL(0x0097CF40 + (ride->type * 8), uint32) & 0x8000) { + if (RCT2_ADDRESS(RCT2_ADDRESS_RIDE_FLAGS, uint64)[ride->type] & 0x8000) { sub_6C84CE(); return 1; } diff --git a/src/windows/ride_construction.c b/src/windows/ride_construction.c index 05acbeca0a..58edbf38b9 100644 --- a/src/windows/ride_construction.c +++ b/src/windows/ride_construction.c @@ -35,8 +35,18 @@ void sub_6b2fa9(rct_windownumber number){ } } +enum { + WIDX_BACKGROUND, + WIDX_TITLE, + WIDX_CLOSE, + WIDX_PAGE_BACKGROUND, + + WIDX_DEMOLISH = 24 +}; + void window_construction_emptysub(){} void window_construction_close(); +void window_construction_mouseup(); void window_construction_maze_close(); @@ -75,7 +85,7 @@ static void* window_construction_maze_events[] = { //0x993EEC static void* window_construction_events[] = { window_construction_close, - (void*)0x6C6E14, + window_construction_mouseup, (void*)0x6C7934, (void*)0x6C6E6A, (void*)0x6C78CD, @@ -247,4 +257,67 @@ void window_construction_maze_close(){ } window_ride_main_open(ride_id); -} \ No newline at end of file +} + +void window_construction_mouseup_demolish(rct_window* w); + +/* rct2: 0x006C6E14 */ +void window_construction_mouseup(){ + short widgetIndex; + rct_window *w; + + window_widget_get_registers(w, widgetIndex); + + RCT2_CALLPROC_X(0x6C6A77, 0, 0, 0, 0, 0, 0, 0); + + switch (widgetIndex){ + case WIDX_CLOSE: + window_close(w); + break; + case 27: + RCT2_CALLPROC_X(0x6C9296, 0, 0, 0, widgetIndex, (int)w, 0, 0); + break; + case 26: + RCT2_CALLPROC_X(0x6C93B8, 0, 0, 0, widgetIndex, (int)w, 0, 0); + break; + case 23: + RCT2_CALLPROC_X(0x6C9F72, 0, 0, 0, widgetIndex, (int)w, 0, 0); + break; + case WIDX_DEMOLISH: + window_construction_mouseup_demolish(w); + break; + case 32: + RCT2_CALLPROC_X(0x6C98AA, 0, 0, 0, widgetIndex, (int)w, 0, 0); + break; + case 29: + RCT2_CALLPROC_X(0x6C7802, 0, 0, 0, widgetIndex, (int)w, 0, 0); + break; + case 30: + RCT2_CALLPROC_X(0x6C7866, 0, 0, 0, widgetIndex, (int)w, 0, 0); + break; + } +} + +/* rct2: 0x006C9BA5 */ +void window_construction_mouseup_demolish(rct_window* w){ + RCT2_CALLPROC_X(0x6C9BA5, 0, 0, 0, 0, (int)w, 0, 0); + return; + + RCT2_GLOBAL(0xF44070, uint32) = 0x80000000; + RCT2_CALLPROC_X(0x006C9627, 0, 0, 0, 0, 0, 0, 0); + + RCT2_GLOBAL(0xF440B8, uint8) = 3; + if (RCT2_GLOBAL(0xF440A6, uint8) == 1){ + //6C9C4F + } + + if (RCT2_GLOBAL(0xF440A6, uint8) != 2){ + //6c9cc4 + //do this + } + + int ride_id = RCT2_GLOBAL(0xF440A7, uint8); + RCT2_GLOBAL(0xF441D2, uint8) = ride_id; + //6c9BFE +} + From a96bf872bf4d9d20d4c0026c3cecee9312463337 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sat, 20 Dec 2014 11:14:26 +0000 Subject: [PATCH 2/3] Added more of demolish. Fixed bug in window_close --- src/interface/window.c | 7 ++++++- src/ride/ride.c | 4 ++-- src/ride/ride.h | 2 ++ src/windows/ride_construction.c | 13 +++++++++---- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/interface/window.c b/src/interface/window.c index e798358e10..c7b573f09c 100644 --- a/src/interface/window.c +++ b/src/interface/window.c @@ -470,10 +470,15 @@ void window_close(rct_window* window) if (window == NULL) return; + // Make a copy of the window class and number incase + // the window order is changed by the close event. + rct_windowclass cls = window->classification; + rct_windownumber number = window->number; + // Call close event of window RCT2_CALLPROC_X(window->event_handlers[WE_CLOSE], 0, 0, 0, 0, (int)window, 0, 0); - window = window_find_by_number(window->classification, window->number); + window = window_find_by_number(cls, number); // Remove viewport if (window->viewport != NULL) { diff --git a/src/ride/ride.c b/src/ride/ride.c index 9765daf053..951ad6e659 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -481,7 +481,7 @@ static rct_window *ride_create_or_find_construction_window(int rideIndex) RCT2_GLOBAL(0x00F440A7, uint8) = rideIndex; w = window_construction_open(rideIndex); } else { - RCT2_CALLPROC_X(0x006C9627, 0, 0, 0, 0, 0, 0, 0); + sub_6C9627(); RCT2_GLOBAL(0x00F440A7, uint8) = rideIndex; } @@ -712,7 +712,7 @@ void sub_6C96C0() RCT2_CALLPROC_X(0x006C96C0, 0, 0, 0, 0, 0, 0, 0); } -static void sub_6C9627() +void sub_6C9627() { switch (RCT2_GLOBAL(0x00F440A6, uint8)) { case 3: diff --git a/src/ride/ride.h b/src/ride/ride.h index c6241ae1f3..3394f1b5bd 100644 --- a/src/ride/ride.h +++ b/src/ride/ride.h @@ -628,6 +628,8 @@ rct_ride_measurement *ride_get_measurement(int rideIndex, rct_string_id *message void ride_breakdown_add_news_item(int rideIndex); rct_peep *ride_find_closest_mechanic(rct_ride *ride, int forInspection); int sub_6CC3FB(int rideIndex); +void sub_6C9627(); +int sub_6C683D(int x, int y, int z, int direction, int type, int esi, int edi, int ebp); void ride_set_map_tooltip(rct_map_element *mapElement); int ride_music_params_update(sint16 x, sint16 y, sint16 z, uint8 rideIndex, uint16 sampleRate, uint32 position, uint8 *tuneId); void ride_music_update_final(); diff --git a/src/windows/ride_construction.c b/src/windows/ride_construction.c index 58edbf38b9..64907bd61b 100644 --- a/src/windows/ride_construction.c +++ b/src/windows/ride_construction.c @@ -203,7 +203,7 @@ void window_construction_close(){ window_get_register(w); - RCT2_CALLPROC_X(0x006C9627, 0, 0, 0, 0, 0, 0, 0); + sub_6C9627(); viewport_set_visibility(0); map_invalidate_map_selection_tiles(); @@ -234,7 +234,7 @@ void window_construction_maze_close(){ window_get_register(w); - RCT2_CALLPROC_X(0x006C9627, 0, 0, 0, 0, 0, 0, 0); + sub_6C9627(); viewport_set_visibility(0); map_invalidate_map_selection_tiles(); @@ -304,7 +304,7 @@ void window_construction_mouseup_demolish(rct_window* w){ return; RCT2_GLOBAL(0xF44070, uint32) = 0x80000000; - RCT2_CALLPROC_X(0x006C9627, 0, 0, 0, 0, 0, 0, 0); + sub_6C9627(); RCT2_GLOBAL(0xF440B8, uint8) = 3; if (RCT2_GLOBAL(0xF440A6, uint8) == 1){ @@ -313,7 +313,12 @@ void window_construction_mouseup_demolish(rct_window* w){ if (RCT2_GLOBAL(0xF440A6, uint8) != 2){ //6c9cc4 - //do this + int eax = RCT2_GLOBAL(0xF440A8, uint16), + ebx = RCT2_GLOBAL(0xF440AF, uint8) || (RCT2_GLOBAL(0xF440AE, uint8) << 8), + ecx = RCT2_GLOBAL(0xF440AA, uint16), + edx = RCT2_GLOBAL(0xF440AC, uint16); + + sub_6C683D(eax, ecx, edx, RCT2_GLOBAL(0xF440AE, uint8), RCT2_GLOBAL(0xF440AF, uint8) & 0x3FF, 0, 0, 0); } int ride_id = RCT2_GLOBAL(0xF440A7, uint8); From acf6ef7b88f528e52efe42dc93f84d2637e5b817 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sat, 20 Dec 2014 13:06:17 +0000 Subject: [PATCH 3/3] Fixed construct bug --- src/ride/ride.c | 17 +++++++++++------ src/ride/ride.h | 2 +- src/windows/ride_construction.c | 4 ++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/ride/ride.c b/src/ride/ride.c index 951ad6e659..10ea7cb8b1 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -702,9 +702,10 @@ static void ride_remove_peeps(int rideIndex) ride->var_14D |= 4; } -int sub_6C683D(int x, int y, int z, int direction, int type, int esi, int edi, int ebp) +int sub_6C683D(int* x, int* y, int z, int direction, int type, int esi, int edi, int ebp) { - return RCT2_CALLPROC_X(0x006C683D, x, (direction << 8) | type, y, z, esi, edi, ebp)&0x100; + int ebx = (direction << 8) | type; + return RCT2_CALLFUNC_X(0x006C683D, x, &ebx, y, &z, &esi, &edi, &ebp)&0x100; } void sub_6C96C0() @@ -716,16 +717,19 @@ void sub_6C9627() { switch (RCT2_GLOBAL(0x00F440A6, uint8)) { case 3: + { + int x = RCT2_GLOBAL(0x00F440A8, uint16), y = RCT2_GLOBAL(0x00F440AA, uint16); sub_6C683D( - RCT2_GLOBAL(0x00F440A8, uint16), - RCT2_GLOBAL(0x00F440AA, uint16), + &x, + &y, RCT2_GLOBAL(0x00F440AC, uint16), RCT2_GLOBAL(0x00F440AE, uint8) & 3, RCT2_GLOBAL(0x00F440AF, uint8), 0, 0, 1 - ); + ); + } break; case 6: case 7: @@ -893,7 +897,8 @@ int ride_modify(rct_map_element *mapElement, int x, int y) z = mapElement->base_height * 8; direction = mapElement->type & 3; type = mapElement->properties.track.type; - if (sub_6C683D(x, y, z, direction, type, 0, 0, 0)) return 0; + + if (sub_6C683D(&x, &y, z, direction, type, 0, 0, 0)) return 0; RCT2_GLOBAL(0x00F440A7, uint8) = rideIndex; RCT2_GLOBAL(0x00F440A6, uint8) = 3; diff --git a/src/ride/ride.h b/src/ride/ride.h index 3394f1b5bd..c5ea1fa671 100644 --- a/src/ride/ride.h +++ b/src/ride/ride.h @@ -629,7 +629,7 @@ void ride_breakdown_add_news_item(int rideIndex); rct_peep *ride_find_closest_mechanic(rct_ride *ride, int forInspection); int sub_6CC3FB(int rideIndex); void sub_6C9627(); -int sub_6C683D(int x, int y, int z, int direction, int type, int esi, int edi, int ebp); +int sub_6C683D(int* x, int* y, int z, int direction, int type, int esi, int edi, int ebp); void ride_set_map_tooltip(rct_map_element *mapElement); int ride_music_params_update(sint16 x, sint16 y, sint16 z, uint8 rideIndex, uint16 sampleRate, uint32 position, uint8 *tuneId); void ride_music_update_final(); diff --git a/src/windows/ride_construction.c b/src/windows/ride_construction.c index 64907bd61b..7863f81f81 100644 --- a/src/windows/ride_construction.c +++ b/src/windows/ride_construction.c @@ -287,7 +287,7 @@ void window_construction_mouseup(){ window_construction_mouseup_demolish(w); break; case 32: - RCT2_CALLPROC_X(0x6C98AA, 0, 0, 0, widgetIndex, (int)w, 0, 0); + RCT2_CALLPROC_X(0x6C78AA, 0, 0, 0, widgetIndex, (int)w, 0, 0); break; case 29: RCT2_CALLPROC_X(0x6C7802, 0, 0, 0, widgetIndex, (int)w, 0, 0); @@ -318,7 +318,7 @@ void window_construction_mouseup_demolish(rct_window* w){ ecx = RCT2_GLOBAL(0xF440AA, uint16), edx = RCT2_GLOBAL(0xF440AC, uint16); - sub_6C683D(eax, ecx, edx, RCT2_GLOBAL(0xF440AE, uint8), RCT2_GLOBAL(0xF440AF, uint8) & 0x3FF, 0, 0, 0); + sub_6C683D(&eax, &ecx, edx, RCT2_GLOBAL(0xF440AE, uint8), RCT2_GLOBAL(0xF440AF, uint8) & 0x3FF, 0, 0, 0); } int ride_id = RCT2_GLOBAL(0xF440A7, uint8);