From d8727e89983b67d8774e99f9d758db71cbf49686 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Tue, 8 Jul 2014 21:58:07 +0100 Subject: [PATCH 1/8] Started reverse of scoll_left --- src/game.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/game.c b/src/game.c index e953141498..e47274f4e9 100644 --- a/src/game.c +++ b/src/game.c @@ -527,7 +527,33 @@ static void game_handle_input_mouse(int x, int y, int state) RCT2_CALLPROC_X(0x006E87B4, x, y, state, widgetIndex, (int)w, (int)widget, 0); break; case INPUT_STATE_SCROLL_LEFT: - RCT2_CALLPROC_X(0x006E8676, x, y, state, widgetIndex, (int)w, (int)widget, 0); + switch (state){ + case 0: + if (widgetIndex != RCT2_GLOBAL(0x9DE524, uint32)){ + //Jump to case 2 after first part + } + if (w->classification != RCT2_GLOBAL(0x9DE51F, uint8)){ + //Jump to case 2 after first part + } + if (w->number != RCT2_GLOBAL(0x9DE520, uint16)){ + //Jump to case 2 after first part + } + + if (RCT2_GLOBAL(0x9DE548, uint16) == 5){ + //Jump 0x6e8735 + } + + if (RCT2_GLOBAL(0x9DE548, uint16) == 10){ + //Jump 0x6e874E + } + + //Call 0x6E9F92 + //0x6E86D3 + break; + case 2: + break; + } + //RCT2_CALLPROC_X(0x006E8676, x, y, state, widgetIndex, (int)w, (int)widget, 0); break; case INPUT_STATE_RESIZING: // RCT2_CALLPROC_X(0x006E8B46, x, y, state, widgetIndex, w, widget, 0); From 16860a88173eed18d853e9e17b832651ea3a2619 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 13 Jul 2014 10:03:50 +0100 Subject: [PATCH 2/8] Added sub_6E9F92 determines scroll action type --- src/game.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/src/game.c b/src/game.c index e47274f4e9..efd6848162 100644 --- a/src/game.c +++ b/src/game.c @@ -343,7 +343,7 @@ 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); static void input_mouseover_widget_flatbutton_invalidate(); static void input_leftmousedown(int x, int y, rct_window *w, int widgetIndex); - +int sub_0x6E9F92(int* x, int* y, int state, rct_window* w, rct_widget* widget); /** * @@ -546,7 +546,7 @@ static void game_handle_input_mouse(int x, int y, int state) if (RCT2_GLOBAL(0x9DE548, uint16) == 10){ //Jump 0x6e874E } - + int cx = sub_0x6E9F92(&x, &y, state, w, widget); //Call 0x6E9F92 //0x6E86D3 break; @@ -590,6 +590,72 @@ static void game_handle_input_mouse(int x, int y, int state) } } +/** + * rct: 0x6E9F92 + * eax: x + * ebx: y + * ecx: state + * esi: w + * edi: widget + */ +int sub_0x6E9F92(int* x, int* y, int state, rct_window* w, rct_widget* widget){ + int scrolls_no = 0; + + for (rct_widget* widg = w->widgets; widg != widget; widg++){ + if (widg->type == WWT_SCROLL){ + scrolls_no ++; + } + } + + if ((w->scrolls[scrolls_no].flags & 1) && (*y >= widget->bottom + w->y - 11)){//Horizontal + + if (*x < widget->left + 11 + w->x) return 1; + + int x_pos = widget->right + w->x; + if (w->scrolls[scrolls_no].flags & 0x10)x_pos -= 11; + + if (*x >= x_pos)return -1; + + x_pos -= 10; + if (*x >= x_pos)return 2; + + if (*x < w->scrolls[scrolls_no].h_thumb_left + widget->left + w->x)return 3; + + if (*x > w->scrolls[scrolls_no].h_thumb_right + widget->left + w->x) return 4; + return 5; + } + else if ((w->scrolls[scrolls_no].flags & 0x10) && (*x >= widget->right + w->x - 11)){//Vertical + + if (*y < widget->top + 11 + w->y)return 6; + + int y_pos = widget->bottom + w->y; + if (w->scrolls[scrolls_no].flags & 0x01)y_pos -= 11; + + if (*y >= y_pos)return -1; + + y_pos -= 10; + if (*y >= y_pos)return 7; + + if (*y < w->scrolls[scrolls_no].v_thumb_top + widget->top + w->y)return 8; + + if (*y > w->scrolls[scrolls_no].v_thumb_bottom + widget->top + w->y)return 9; + + return 10; + } + else{ + *x -= widget->left + w->x; + *y -= widget->top + w->y; + + (*x)--; + if (*x < 0) return -1; + (*y)--; + if (*y < 0) return -1; + *x += w->scrolls[scrolls_no].h_left; + *y += w->scrolls[scrolls_no].v_top; + return 0; + } +} + /** * * rct2: 0x006E9253 From 3cc9863fc5f8764a13e6ea3a142ad2669a5c3860 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 13 Jul 2014 12:13:13 +0100 Subject: [PATCH 3/8] Added switch for scroll state --- src/game.c | 50 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/src/game.c b/src/game.c index efd6848162..e5ceabf6c9 100644 --- a/src/game.c +++ b/src/game.c @@ -527,16 +527,15 @@ static void game_handle_input_mouse(int x, int y, int state) RCT2_CALLPROC_X(0x006E87B4, x, y, state, widgetIndex, (int)w, (int)widget, 0); break; case INPUT_STATE_SCROLL_LEFT: - switch (state){ - case 0: + if (state == 0){ if (widgetIndex != RCT2_GLOBAL(0x9DE524, uint32)){ - //Jump to case 2 after first part + //Jump to 2 after first part } if (w->classification != RCT2_GLOBAL(0x9DE51F, uint8)){ - //Jump to case 2 after first part + //Jump to 2 after first part } if (w->number != RCT2_GLOBAL(0x9DE520, uint16)){ - //Jump to case 2 after first part + //Jump to 2 after first part } if (RCT2_GLOBAL(0x9DE548, uint16) == 5){ @@ -547,11 +546,42 @@ static void game_handle_input_mouse(int x, int y, int state) //Jump 0x6e874E } int cx = sub_0x6E9F92(&x, &y, state, w, widget); - //Call 0x6E9F92 - //0x6E86D3 - break; - case 2: - break; + if (cx != RCT2_GLOBAL(0x9DE548, uint16)){ + //Jump to 2 after first part + } + + switch (cx){ + case 0: + //0x6E871A + break; + case 1: + //0x6E9A60 + break; + case 2: + //0x6E9ABF + break; + case 3: + case 4: + //0x6E87B3 + break; + case 6: + //0x6E9C37 + break; + case 7: + //0x6E9C96 + break; + case 8: + case 9: + //0x6E87B3 + break; + default: + return; + } + }else if (state==2){ + + } + else{ + return; } //RCT2_CALLPROC_X(0x006E8676, x, y, state, widgetIndex, (int)w, (int)widget, 0); break; From cbb913c8afb5a5b8c82f0e4c72123a414851bf17 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Mon, 14 Jul 2014 19:00:25 +0100 Subject: [PATCH 4/8] Added final part of input_scroll_left. Requires more testing --- src/game.c | 57 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/src/game.c b/src/game.c index e5ceabf6c9..1886968978 100644 --- a/src/game.c +++ b/src/game.c @@ -528,60 +528,87 @@ static void game_handle_input_mouse(int x, int y, int state) break; case INPUT_STATE_SCROLL_LEFT: if (state == 0){ - if (widgetIndex != RCT2_GLOBAL(0x9DE524, uint32)){ + if (widgetIndex != RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WIDGETINDEX, uint32)){ //Jump to 2 after first part + goto state2; } - if (w->classification != RCT2_GLOBAL(0x9DE51F, uint8)){ + if (w->classification != RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWCLASS, uint8)){ //Jump to 2 after first part + goto state2; } - if (w->number != RCT2_GLOBAL(0x9DE520, uint16)){ + if (w->number != RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWNUMBER, uint16)){ //Jump to 2 after first part + goto state2; } if (RCT2_GLOBAL(0x9DE548, uint16) == 5){ - //Jump 0x6e8735 + int temp_x = x; + x -= RCT2_GLOBAL(0x9DE538, uint16); + RCT2_GLOBAL(0x9DE538, uint16) = temp_x; + RCT2_CALLPROC_X(0x006E8676, x, temp_x, state, w->number, (int)w, (int)widget, x); } if (RCT2_GLOBAL(0x9DE548, uint16) == 10){ - //Jump 0x6e874E + int temp_y = y; + y -= RCT2_GLOBAL(0x9DE53A, uint16); + RCT2_GLOBAL(0x9DE53A, uint16) = temp_y; + RCT2_CALLPROC_X(0x006E99A9, temp_y, y, state, w->number, (int)w, (int)widget, x); } int cx = sub_0x6E9F92(&x, &y, state, w, widget); if (cx != RCT2_GLOBAL(0x9DE548, uint16)){ //Jump to 2 after first part + goto state2; } switch (cx){ case 0: - //0x6E871A + RCT2_CALLPROC_X(w->event_handlers[WE_TOOL_DRAG], w->number / 18, y, x, y, (int)w, (int)widget, w->event_handlers); break; case 1: - //0x6E9A60 + RCT2_CALLPROC_X(0x006E9A60, x, y, cx, w->number, (int)w, (int)widget, 0); break; case 2: - //0x6E9ABF + RCT2_CALLPROC_X(0x006E9ABF, x, y, cx, w->number, (int)w, (int)widget, 0); break; case 3: case 4: - //0x6E87B3 + return; break; case 6: - //0x6E9C37 + RCT2_CALLPROC_X(0x006E9C37, x, y, cx, w->number, (int)w, (int)widget, 0); break; case 7: - //0x6E9C96 + RCT2_CALLPROC_X(0x006E9C96, x, y, cx, w->number, (int)w, (int)widget, 0); break; case 8: case 9: - //0x6E87B3 + return; break; default: return; } }else if (state==2){ + RCT2_GLOBAL(0x009DE51D, uint8) = 0; +state2: + widgetIndex = widgetIndex;//Purely to make the goto work + + int eax = x, ebx = y, ecx, edx, esi, edi, ebp; + edx = RCT2_GLOBAL(0x9DE520, uint16); + ecx = RCT2_GLOBAL(0x9DE51F, uint8); + esi = (int)w; + edi = (int)widget; + + RCT2_CALLFUNC_X(0x006EA8A0, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + if (esi == 0) return; + ebx = RCT2_GLOBAL(0x9DE54C, uint32); + edi = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WIDGETINDEX, uint32); + rct_widget* widg = &w->widgets[edi]; + w->scrolls[ebx].flags &= 0xFF11; + eax = RCT2_GLOBAL(0x9DE524, uint8) << 8; + eax |= RCT2_GLOBAL(0x9DE51F, uint8) | 0x80; + ebx = RCT2_GLOBAL(0x9DE520, uint16); + RCT2_CALLPROC_X(0x006EA8A0, eax, ebx, ecx, edx, esi, (int)widg, ebp); - } - else{ - return; } //RCT2_CALLPROC_X(0x006E8676, x, y, state, widgetIndex, (int)w, (int)widget, 0); break; From 00381d9313f8bed3cdc0e69c3daed709240a995e Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Fri, 18 Jul 2014 15:48:43 +0100 Subject: [PATCH 5/8] Deleted twice reversed function added note to prevent this happening. Labled global vars where noticed. --- src/addresses.h | 2 + src/game.c | 153 ++++++++++++++---------------------------------- src/widget.c | 35 +++++++---- src/widget.h | 2 +- 4 files changed, 69 insertions(+), 123 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index 612a913bbc..c6c02e7bed 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -112,6 +112,8 @@ #define RCT2_ADDRESS_TOOL_WINDOWCLASS 0x009DE544 #define RCT2_ADDRESS_CURRENT_TOOL 0x009DE545 #define RCT2_ADDRESS_TOOL_WIDGETINDEX 0x009DE546 +#define RCT2_ADDRESS_CURRENT_SCROLL_AREA 0x009DE548 +#define RCT2_ADDRESS_CURRENT_SCROLL_ID 0x009DE54C #define RCT2_ADDRESS_PICKEDUP_PEEP_SPRITE 0x009DE550 #define RCT2_ADDRESS_PICKEDUP_PEEP_X 0x009DE554 diff --git a/src/game.c b/src/game.c index 1886968978..e88552c98a 100644 --- a/src/game.c +++ b/src/game.c @@ -343,7 +343,6 @@ 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); static void input_mouseover_widget_flatbutton_invalidate(); static void input_leftmousedown(int x, int y, rct_window *w, int widgetIndex); -int sub_0x6E9F92(int* x, int* y, int state, rct_window* w, rct_widget* widget); /** * @@ -541,72 +540,74 @@ static void game_handle_input_mouse(int x, int y, int state) goto state2; } - if (RCT2_GLOBAL(0x9DE548, uint16) == 5){ + if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SCROLL_AREA, uint16) == SCROLL_PART_HSCROLLBAR_THUMB){ int temp_x = x; - x -= RCT2_GLOBAL(0x9DE538, uint16); - RCT2_GLOBAL(0x9DE538, uint16) = temp_x; + x -= RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_CURSOR_X, uint16); + RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_CURSOR_X, uint16) = temp_x; RCT2_CALLPROC_X(0x006E8676, x, temp_x, state, w->number, (int)w, (int)widget, x); } - if (RCT2_GLOBAL(0x9DE548, uint16) == 10){ + if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SCROLL_AREA, uint16) == SCROLL_PART_VSCROLLBAR_THUMB){ int temp_y = y; - y -= RCT2_GLOBAL(0x9DE53A, uint16); - RCT2_GLOBAL(0x9DE53A, uint16) = temp_y; + y -= RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_CURSOR_Y, uint16); + RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_CURSOR_Y, uint16) = temp_y; RCT2_CALLPROC_X(0x006E99A9, temp_y, y, state, w->number, (int)w, (int)widget, x); } - int cx = sub_0x6E9F92(&x, &y, state, w, widget); - if (cx != RCT2_GLOBAL(0x9DE548, uint16)){ + int scroll_part; + widget_scroll_get_part(w, widget, x, y, &x, &y, &scroll_part, &state); + + if (scroll_part != RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SCROLL_AREA, uint16)){ //Jump to 2 after first part goto state2; } - switch (cx){ - case 0: - RCT2_CALLPROC_X(w->event_handlers[WE_TOOL_DRAG], w->number / 18, y, x, y, (int)w, (int)widget, w->event_handlers); + switch (scroll_part){ + case SCROLL_PART_VIEW: + RCT2_CALLPROC_X(w->event_handlers[WE_TOOL_DRAG], w->number / 18, y, x, y, (int)w, (int)widget, (int)w->event_handlers); break; - case 1: - RCT2_CALLPROC_X(0x006E9A60, x, y, cx, w->number, (int)w, (int)widget, 0); + case SCROLL_PART_HSCROLLBAR_LEFT: + RCT2_CALLPROC_X(0x006E9A60, x, y, scroll_part, w->number, (int)w, (int)widget, 0); break; - case 2: - RCT2_CALLPROC_X(0x006E9ABF, x, y, cx, w->number, (int)w, (int)widget, 0); + case SCROLL_PART_HSCROLLBAR_RIGHT: + RCT2_CALLPROC_X(0x006E9ABF, x, y, scroll_part, w->number, (int)w, (int)widget, 0); break; - case 3: - case 4: + case SCROLL_PART_HSCROLLBAR_LEFT_TROUGH: + case SCROLL_PART_HSCROLLBAR_RIGHT_TROUGH: return; break; - case 6: - RCT2_CALLPROC_X(0x006E9C37, x, y, cx, w->number, (int)w, (int)widget, 0); + case SCROLL_PART_VSCROLLBAR_TOP: + RCT2_CALLPROC_X(0x006E9C37, x, y, scroll_part, w->number, (int)w, (int)widget, 0); break; - case 7: - RCT2_CALLPROC_X(0x006E9C96, x, y, cx, w->number, (int)w, (int)widget, 0); + case SCROLL_PART_VSCROLLBAR_BOTTOM: + RCT2_CALLPROC_X(0x006E9C96, x, y, scroll_part, w->number, (int)w, (int)widget, 0); break; - case 8: - case 9: + case SCROLL_PART_VSCROLLBAR_TOP_TROUGH: + case SCROLL_PART_VSCROLLBAR_BOTTOM_TROUGH: return; break; default: return; } }else if (state==2){ - RCT2_GLOBAL(0x009DE51D, uint8) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = 0; state2: widgetIndex = widgetIndex;//Purely to make the goto work int eax = x, ebx = y, ecx, edx, esi, edi, ebp; - edx = RCT2_GLOBAL(0x9DE520, uint16); - ecx = RCT2_GLOBAL(0x9DE51F, uint8); + edx = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWNUMBER, uint16); + ecx = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWCLASS, uint8); esi = (int)w; edi = (int)widget; RCT2_CALLFUNC_X(0x006EA8A0, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); if (esi == 0) return; - ebx = RCT2_GLOBAL(0x9DE54C, uint32); + ebx = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SCROLL_ID, uint32); edi = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WIDGETINDEX, uint32); rct_widget* widg = &w->widgets[edi]; - w->scrolls[ebx].flags &= 0xFF11; - eax = RCT2_GLOBAL(0x9DE524, uint8) << 8; - eax |= RCT2_GLOBAL(0x9DE51F, uint8) | 0x80; - ebx = RCT2_GLOBAL(0x9DE520, uint16); + w->scrolls[ebx/sizeof(rct_scroll)].flags &= 0xFF11; + eax = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WIDGETINDEX, uint8) << 8; + eax |= RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWCLASS, uint8) | 0x80; + ebx = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWNUMBER, uint16); RCT2_CALLPROC_X(0x006EA8A0, eax, ebx, ecx, edx, esi, (int)widg, ebp); } @@ -647,72 +648,6 @@ state2: } } -/** - * rct: 0x6E9F92 - * eax: x - * ebx: y - * ecx: state - * esi: w - * edi: widget - */ -int sub_0x6E9F92(int* x, int* y, int state, rct_window* w, rct_widget* widget){ - int scrolls_no = 0; - - for (rct_widget* widg = w->widgets; widg != widget; widg++){ - if (widg->type == WWT_SCROLL){ - scrolls_no ++; - } - } - - if ((w->scrolls[scrolls_no].flags & 1) && (*y >= widget->bottom + w->y - 11)){//Horizontal - - if (*x < widget->left + 11 + w->x) return 1; - - int x_pos = widget->right + w->x; - if (w->scrolls[scrolls_no].flags & 0x10)x_pos -= 11; - - if (*x >= x_pos)return -1; - - x_pos -= 10; - if (*x >= x_pos)return 2; - - if (*x < w->scrolls[scrolls_no].h_thumb_left + widget->left + w->x)return 3; - - if (*x > w->scrolls[scrolls_no].h_thumb_right + widget->left + w->x) return 4; - return 5; - } - else if ((w->scrolls[scrolls_no].flags & 0x10) && (*x >= widget->right + w->x - 11)){//Vertical - - if (*y < widget->top + 11 + w->y)return 6; - - int y_pos = widget->bottom + w->y; - if (w->scrolls[scrolls_no].flags & 0x01)y_pos -= 11; - - if (*y >= y_pos)return -1; - - y_pos -= 10; - if (*y >= y_pos)return 7; - - if (*y < w->scrolls[scrolls_no].v_thumb_top + widget->top + w->y)return 8; - - if (*y > w->scrolls[scrolls_no].v_thumb_bottom + widget->top + w->y)return 9; - - return 10; - } - else{ - *x -= widget->left + w->x; - *y -= widget->top + w->y; - - (*x)--; - if (*x < 0) return -1; - (*y)--; - if (*y < 0) return -1; - *x += w->scrolls[scrolls_no].h_left; - *y += w->scrolls[scrolls_no].v_top; - return 0; - } -} - /** * * rct2: 0x006E9253 @@ -875,7 +810,7 @@ static void input_hscrollbar_leftbutton(rct_window* w) widgetIndex = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WIDGETINDEX, uint16); widget = &w->widgets[widgetIndex]; - scroll = w->scrolls + RCT2_GLOBAL(0x009DE54C, uint32); + scroll = w->scrolls + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SCROLL_ID, uint32); left = scroll->h_left; left -= 3; @@ -917,7 +852,7 @@ static void input_hscrollbar_rightbutton(rct_window* w) widgetIndex = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WIDGETINDEX, uint16); widget = &w->widgets[widgetIndex]; - scroll = w->scrolls + RCT2_GLOBAL(0x009DE54C, uint32); + scroll = w->scrolls + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SCROLL_ID, uint32); left = scroll->h_left; left += 3; @@ -967,7 +902,7 @@ static void input_hscrollbar_left_trough(rct_window* w) widgetIndex = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WIDGETINDEX, uint16); widget = &w->widgets[widgetIndex]; - scroll = w->scrolls + RCT2_GLOBAL(0x009DE54C, uint32); + scroll = w->scrolls + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SCROLL_ID, uint32); left = scroll->h_left; @@ -1012,7 +947,7 @@ static void input_hscrollbar_right_trough(rct_window* w) widgetIndex = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WIDGETINDEX, uint16); widget = &w->widgets[widgetIndex]; - scroll = w->scrolls + RCT2_GLOBAL(0x009DE54C, uint32); + scroll = w->scrolls + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SCROLL_ID, uint32); left = scroll->h_left; @@ -1062,7 +997,7 @@ static void input_vscrollbar_topbutton(rct_window* w) widgetIndex = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WIDGETINDEX, uint16); widget = &w->widgets[widgetIndex]; - scroll = w->scrolls + RCT2_GLOBAL(0x009DE54C, uint32); + scroll = w->scrolls + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SCROLL_ID, uint32); top = scroll->v_top; top -= 3; @@ -1103,7 +1038,7 @@ static void input_vscrollbar_bottombutton(rct_window* w) widgetIndex = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WIDGETINDEX, uint16); widget = &w->widgets[widgetIndex]; - scroll = w->scrolls + RCT2_GLOBAL(0x009DE54C, uint32); + scroll = w->scrolls + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SCROLL_ID, uint32); top = scroll->v_top; top += 3; @@ -1153,7 +1088,7 @@ static void input_vscrollbar_top_trough(rct_window* w) widgetIndex = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WIDGETINDEX, uint16); widget = &w->widgets[widgetIndex]; - scroll = w->scrolls + RCT2_GLOBAL(0x009DE54C, uint32); + scroll = w->scrolls + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SCROLL_ID, uint32); top = scroll->v_top; @@ -1198,7 +1133,7 @@ static void input_vscrollbar_bottom_trough(rct_window* w) widgetIndex = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WIDGETINDEX, uint16); widget = &w->widgets[widgetIndex]; - scroll = w->scrolls + RCT2_GLOBAL(0x009DE54C, uint32); + scroll = w->scrolls + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SCROLL_ID, uint32); top = scroll->v_top; @@ -1307,9 +1242,9 @@ static void input_leftmousedown(int x, int y, rct_window *w, int widgetIndex) edx = 0; // safety widget_scroll_get_part(w, widget, x, y, &eax, &ebx, &ecx, &edx); - RCT2_GLOBAL(0x009DE548, uint16) = ecx; - RCT2_GLOBAL(0x009DE54C, uint32) = edx; - RCT2_CALLPROC_X(w->event_handlers[WE_UNKNOWN_15], RCT2_GLOBAL(0x009DE54C, uint32), ebx, ecx, edx, (int)w, (int)widget, 0); + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SCROLL_AREA, uint16) = ecx; + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SCROLL_ID, uint32) = edx * 12;//We do this because scroll id is not all decompiled + RCT2_CALLPROC_X(w->event_handlers[WE_UNKNOWN_15], RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SCROLL_ID, uint32), ebx, ecx, edx, (int)w, (int)widget, 0); switch (ecx) { case SCROLL_PART_VIEW: RCT2_CALLPROC_X(w->event_handlers[WE_SCROLL_MOUSEDOWN], edx / sizeof(rct_scroll), ebx, eax, ebx, (int)w, (int)widget, 0); diff --git a/src/widget.c b/src/widget.c index d69b239cba..c180d6f6d0 100644 --- a/src/widget.c +++ b/src/widget.c @@ -1000,26 +1000,35 @@ int widget_is_active_tool(rct_window *w, int widgetIndex) return 1; } -void widget_scroll_get_part(rct_window *w, rct_widget* widget, int x, int y, int *output_x, int *output_y, int *output_scroll_area, int *output_dx) +/** + * rct2: 0x006E9F92 + * eax: x / output_x + * ebx: y / output_y + * ecx: output_scroll_area + * edx: scroll_id + * esi: w + * edi: widget + */ +void widget_scroll_get_part(rct_window *w, rct_widget* widget, int x, int y, int *output_x, int *output_y, int *output_scroll_area, int *scroll_id) { rct_widget* iterator = w->widgets; - int scroll_id = 0; + *scroll_id = 0; while (++iterator != widget) { if (iterator->type == WWT_SCROLL) { - scroll_id++; + (*scroll_id)++; break; } } - if ((w->scrolls[scroll_id].flags & 0x01) && y >= (w->y + widget->bottom - 11)) + if ((w->scrolls[*scroll_id].flags & 0x01) && y >= (w->y + widget->bottom - 11)) { //horizon scrollbar int rightOffset = 0; int iteratorLeft = widget->left + w->x; int iteratorRight = widget->right + w->x; - if (w->scrolls[scroll_id].flags & 0x01) + if (w->scrolls[*scroll_id].flags & 0x01) { rightOffset = 11; } @@ -1035,11 +1044,11 @@ void widget_scroll_get_part(rct_window *w, rct_widget* widget, int x, int y, int { *output_scroll_area = SCROLL_PART_HSCROLLBAR_RIGHT; } - else if (x < (widget->left + w->x + w->scrolls[scroll_id].h_thumb_left)) + else if (x < (widget->left + w->x + w->scrolls[*scroll_id].h_thumb_left)) { *output_scroll_area = SCROLL_PART_HSCROLLBAR_LEFT_TROUGH; } - else if (x >(widget->left + w->x + w->scrolls[scroll_id].h_thumb_right)) + else if (x >(widget->left + w->x + w->scrolls[*scroll_id].h_thumb_right)) { *output_scroll_area = SCROLL_PART_HSCROLLBAR_RIGHT_TROUGH; } @@ -1048,13 +1057,13 @@ void widget_scroll_get_part(rct_window *w, rct_widget* widget, int x, int y, int *output_scroll_area = SCROLL_PART_HSCROLLBAR_THUMB; } } - else if ((w->scrolls[scroll_id].flags & 10) || (x >= w->x + widget->right - 11)) + else if ((w->scrolls[*scroll_id].flags & 10) || (x >= w->x + widget->right - 11)) { //vertical scrollbar int bottomOffset = 0; int iteratorTop = widget->top + w->y; int iteratorBottom = widget->bottom + w->y; - if (w->scrolls[scroll_id].flags & 0x01) + if (w->scrolls[*scroll_id].flags & 0x01) { bottomOffset = 11; } @@ -1070,11 +1079,11 @@ void widget_scroll_get_part(rct_window *w, rct_widget* widget, int x, int y, int { *output_scroll_area = SCROLL_PART_VSCROLLBAR_BOTTOM; } - else if (y < (widget->top + w->y + w->scrolls[scroll_id].v_thumb_top)) + else if (y < (widget->top + w->y + w->scrolls[*scroll_id].v_thumb_top)) { *output_scroll_area = SCROLL_PART_VSCROLLBAR_TOP_TROUGH; } - else if (y > (widget->top + w->y + w->scrolls[scroll_id].v_thumb_bottom)) + else if (y >(widget->top + w->y + w->scrolls[*scroll_id].v_thumb_bottom)) { *output_scroll_area = SCROLL_PART_VSCROLLBAR_BOTTOM_TROUGH; } @@ -1097,8 +1106,8 @@ void widget_scroll_get_part(rct_window *w, rct_widget* widget, int x, int y, int } else { - *output_x += w->scrolls[scroll_id].h_left; - *output_y += w->scrolls[scroll_id].v_top; + *output_x += w->scrolls[*scroll_id].h_left; + *output_y += w->scrolls[*scroll_id].v_top; } } } diff --git a/src/widget.h b/src/widget.h index 28019202b9..f0b044a542 100644 --- a/src/widget.h +++ b/src/widget.h @@ -62,5 +62,5 @@ int widget_is_disabled(rct_window *w, int widgetIndex); int widget_is_pressed(rct_window *w, int widgetIndex); int widget_is_highlighted(rct_window *w, int widgetIndex); int widget_is_active_tool(rct_window *w, int widgetIndex); -void widget_scroll_get_part(rct_window *w, rct_widget* widget, int x, int y, int *output_x, int *output_y, int *output_cx, int *output_dx); +void widget_scroll_get_part(rct_window *w, rct_widget* widget, int x, int y, int *output_x, int *output_y, int *output_scroll_area, int *scroll_id); #endif From c4f49bb7cd175342d6a54a8d5a40b60e3c7be04c Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Fri, 18 Jul 2014 15:53:46 +0100 Subject: [PATCH 6/8] Added missing case still not working --- src/game.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/game.c b/src/game.c index e88552c98a..caa1f6190c 100644 --- a/src/game.c +++ b/src/game.c @@ -575,6 +575,7 @@ static void game_handle_input_mouse(int x, int y, int state) case SCROLL_PART_HSCROLLBAR_RIGHT_TROUGH: return; break; + case SCROLL_PART_HSCROLLBAR_THUMB: case SCROLL_PART_VSCROLLBAR_TOP: RCT2_CALLPROC_X(0x006E9C37, x, y, scroll_part, w->number, (int)w, (int)widget, 0); break; From 6727c216e46c13bf9042d34fd293bdd1cd711863 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sat, 19 Jul 2014 11:55:34 +0100 Subject: [PATCH 7/8] fixed bug due to incorrect function calls --- src/game.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/game.c b/src/game.c index caa1f6190c..a4d8e5b64a 100644 --- a/src/game.c +++ b/src/game.c @@ -544,14 +544,16 @@ static void game_handle_input_mouse(int x, int y, int state) int temp_x = x; x -= RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_CURSOR_X, uint16); RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_CURSOR_X, uint16) = temp_x; - RCT2_CALLPROC_X(0x006E8676, x, temp_x, state, w->number, (int)w, (int)widget, x); + RCT2_CALLPROC_X(0x006E98F2, x, temp_x, state, w->number, (int)w, (int)widget, x); + return; } if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SCROLL_AREA, uint16) == SCROLL_PART_VSCROLLBAR_THUMB){ - int temp_y = y; + int temp_y = y; y -= RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_CURSOR_Y, uint16); RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_CURSOR_Y, uint16) = temp_y; - RCT2_CALLPROC_X(0x006E99A9, temp_y, y, state, w->number, (int)w, (int)widget, x); + RCT2_CALLPROC_X(0x006E99A9, temp_y, y, state, w->number, (int)w, (int)widget, y); + return; } int scroll_part; widget_scroll_get_part(w, widget, x, y, &x, &y, &scroll_part, &state); @@ -593,23 +595,16 @@ static void game_handle_input_mouse(int x, int y, int state) RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = 0; state2: widgetIndex = widgetIndex;//Purely to make the goto work + int window_no = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWNUMBER, uint16); + int window_cls = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWCLASS, uint8); + + rct_window* wind = window_find_by_id( window_cls,window_no); + if (wind == NULL) return; + int scroll_id = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SCROLL_ID, uint32); - int eax = x, ebx = y, ecx, edx, esi, edi, ebp; - edx = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWNUMBER, uint16); - ecx = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWCLASS, uint8); - esi = (int)w; - edi = (int)widget; + wind->scrolls[scroll_id/sizeof(rct_scroll)].flags &= 0xFF11; - RCT2_CALLFUNC_X(0x006EA8A0, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); - if (esi == 0) return; - ebx = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SCROLL_ID, uint32); - edi = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WIDGETINDEX, uint32); - rct_widget* widg = &w->widgets[edi]; - w->scrolls[ebx/sizeof(rct_scroll)].flags &= 0xFF11; - eax = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WIDGETINDEX, uint8) << 8; - eax |= RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWCLASS, uint8) | 0x80; - ebx = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWNUMBER, uint16); - RCT2_CALLPROC_X(0x006EA8A0, eax, ebx, ecx, edx, esi, (int)widg, ebp); + window_invalidate_by_id(RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWCLASS, uint8), RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWNUMBER, uint16)); } //RCT2_CALLPROC_X(0x006E8676, x, y, state, widgetIndex, (int)w, (int)widget, 0); From 5f030c6b1eb3b5b48e8e77a2524eaa4b332568d0 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sat, 19 Jul 2014 12:04:32 +0100 Subject: [PATCH 8/8] Cleaned up code to remove goto. --- src/game.c | 59 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/src/game.c b/src/game.c index a4d8e5b64a..4d3fb30dc7 100644 --- a/src/game.c +++ b/src/game.c @@ -344,6 +344,24 @@ static void input_mouseover_widget_check(rct_windowclass windowClass, rct_window static void input_mouseover_widget_flatbutton_invalidate(); static void input_leftmousedown(int x, int y, rct_window *w, int widgetIndex); +/** + * rct2: 0x006E876D + * + */ +void invalidate_scroll(){ + int window_no = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWNUMBER, uint16); + int window_cls = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWCLASS, uint8); + + rct_window* wind = window_find_by_id(window_cls, window_no); + if (wind == NULL) return; + + int scroll_id = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SCROLL_ID, uint32); + //Reset to basic 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)); +} + /** * * rct2: 0x006E8655 @@ -525,19 +543,20 @@ static void game_handle_input_mouse(int x, int y, int state) case INPUT_STATE_VIEWPORT_LEFT: RCT2_CALLPROC_X(0x006E87B4, x, y, state, widgetIndex, (int)w, (int)widget, 0); break; - case INPUT_STATE_SCROLL_LEFT: + case INPUT_STATE_SCROLL_LEFT://0x006E8676 + //RCT2_CALLPROC_X(0x006E8676, x, y, state, widgetIndex, (int)w, (int)widget, 0); if (state == 0){ if (widgetIndex != RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WIDGETINDEX, uint32)){ - //Jump to 2 after first part - goto state2; + invalidate_scroll(); + return; } if (w->classification != RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWCLASS, uint8)){ - //Jump to 2 after first part - goto state2; + invalidate_scroll(); + return; } if (w->number != RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWNUMBER, uint16)){ - //Jump to 2 after first part - goto state2; + invalidate_scroll(); + return; } if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SCROLL_AREA, uint16) == SCROLL_PART_HSCROLLBAR_THUMB){ @@ -555,12 +574,12 @@ static void game_handle_input_mouse(int x, int y, int state) RCT2_CALLPROC_X(0x006E99A9, temp_y, y, state, w->number, (int)w, (int)widget, y); return; } - int scroll_part; - widget_scroll_get_part(w, widget, x, y, &x, &y, &scroll_part, &state); + int scroll_part, scroll_id; + widget_scroll_get_part(w, widget, x, y, &x, &y, &scroll_part, &scroll_id); if (scroll_part != RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SCROLL_AREA, uint16)){ - //Jump to 2 after first part - goto state2; + invalidate_scroll(); + return; } switch (scroll_part){ @@ -592,22 +611,10 @@ static void game_handle_input_mouse(int x, int y, int state) return; } }else if (state==2){ - RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = 0; -state2: - widgetIndex = widgetIndex;//Purely to make the goto work - int window_no = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWNUMBER, uint16); - int window_cls = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWCLASS, uint8); - - rct_window* wind = window_find_by_id( window_cls,window_no); - if (wind == NULL) return; - int scroll_id = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SCROLL_ID, uint32); - - 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)); - + RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_RESET; + invalidate_scroll(); + return; } - //RCT2_CALLPROC_X(0x006E8676, x, y, state, widgetIndex, (int)w, (int)widget, 0); break; case INPUT_STATE_RESIZING: // RCT2_CALLPROC_X(0x006E8B46, x, y, state, widgetIndex, w, widget, 0);