From 077d3b9d90dd54094051ff5c92ce45ced0e52406 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Mon, 28 Apr 2014 02:35:23 +0100 Subject: [PATCH 1/5] fix bugs in game_handle_input_mouse --- src/game.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/game.c b/src/game.c index 7c94a2fb76..4feae6733c 100644 --- a/src/game.c +++ b/src/game.c @@ -309,7 +309,7 @@ static void game_handle_input_mouse(int x, int y, int state) window_close_by_id(5, 0); if (w != NULL) - window_bring_to_front(w); + w = window_bring_to_front(w); if (widgetIndex == -1) break; @@ -635,7 +635,7 @@ static void input_leftmousedown(int x, int y, rct_window *w, int widgetIndex) if (w == NULL) return; - window_bring_to_front(w); + w = window_bring_to_front(w); if (widgetIndex == -1) return; @@ -684,7 +684,7 @@ static void input_leftmousedown(int x, int y, rct_window *w, int widgetIndex) RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_SCROLL_LEFT; RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WIDGETINDEX, uint16) = widgetIndex; RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWCLASS, rct_windowclass) = windowClass; - RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWNUMBER, rct_windowclass) = windowNumber; + RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWNUMBER, rct_windownumber) = windowNumber; RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_CURSOR_X, uint16) = x; RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_CURSOR_Y, uint16) = y; From 8b7a940aa4e387a7b64b9756be26d3574bdc9c10 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Mon, 28 Apr 2014 02:35:37 +0100 Subject: [PATCH 2/5] add about window --- projects/openrct2.vcxproj | 1 + projects/openrct2.vcxproj.filters | 3 + src/strings.h | 23 ++++ src/window.h | 3 + src/window_about.c | 199 ++++++++++++++++++++++++++++++ src/window_game_top_toolbar.c | 2 +- 6 files changed, 230 insertions(+), 1 deletion(-) create mode 100644 src/window_about.c diff --git a/projects/openrct2.vcxproj b/projects/openrct2.vcxproj index f42dbdeb6d..6cff1ca042 100644 --- a/projects/openrct2.vcxproj +++ b/projects/openrct2.vcxproj @@ -78,6 +78,7 @@ + diff --git a/projects/openrct2.vcxproj.filters b/projects/openrct2.vcxproj.filters index 80c4dd0124..ae7245d7f1 100644 --- a/projects/openrct2.vcxproj.filters +++ b/projects/openrct2.vcxproj.filters @@ -251,6 +251,9 @@ Source Files + + Windows + diff --git a/src/strings.h b/src/strings.h index 3743e75d2a..583bc4738e 100644 --- a/src/strings.h +++ b/src/strings.h @@ -144,6 +144,24 @@ enum { STR_PAUSE_GAME_TIP = 833, STR_DISC_AND_GAME_OPTIONS_TIP = 834, + STR_ROLLERCOASTER_TYCOON_2 = 848, + STR_VERSION_X = 849, + STR_COPYRIGHT_CS = 850, + STR_DESIGNED_AND_PROGRAMMED_BY_CS = 851, + STR_GRAPHICS_BY_SF = 852, + STR_SOUND_AND_MUSIC_BY_AB = 853, + STR_ADDITIONAL_SOUNDS_RECORDED_BY_DE = 854, + STR_REPRESENTATION_BY_JL = 855, + STR_THANKS_TO = 856, + STR_THANKS_TO_PEOPLE = 857, + STR_CREDIT_SPARE_1 = 858, + STR_CREDIT_SPARE_2 = 859, + STR_CREDIT_SPARE_3 = 860, + STR_CREDIT_SPARE_4 = 861, + STR_CREDIT_SPARE_5 = 862, + STR_CREDIT_SPARE_6 = 863, + STR_CREDIT_SPARE_7 = 864, + STR_SCR_BMP = 890, STR_SCREENSHOT = 891, STR_SCREENSHOT_SAVED_AS = 892, @@ -354,6 +372,11 @@ enum { STR_TUTORIAL = 2856, STR_PRESS_KEY_OR_MOUSE_BUTTON_FOR_CONTROL = 2857, + STR_INFOGRAMES_INTERACTIVE_CREDITS = 2860, + STR_LICENSED_TO_INFOGRAMES_INTERACTIVE_INC = 2861, + STR_MUSIC_ACKNOWLEDGEMENTS_ELLIPSIS = 2862, + STR_MUSIC_ACKNOWLEDGEMENTS = 2863, + STR_LICENCE_AGREEMENT_NOTICE_1 = 2969, STR_LICENCE_AGREEMENT_NOTICE_2 = 2970, diff --git a/src/window.h b/src/window.h index 305ed237d4..41ec37d2e7 100644 --- a/src/window.h +++ b/src/window.h @@ -245,6 +245,8 @@ enum { WC_TOOLTIP = 5, WC_DROPDOWN = 6, WC_ABOUT = 8, + WC_MUSIC_CREDITS = 9, + WC_PUBLISHER_CREDITS = 10, WC_ERROR = 11, WC_RIDE = 12, WC_RIDE_CONSTRUCTION = 13, @@ -321,6 +323,7 @@ void window_set_resize(rct_window *w, int minWidth, int minHeight, int maxWidth, void window_main_open(); void window_game_top_toolbar_open(); void window_game_bottom_toolbar_open(); +void window_about_open(); void window_title_menu_open(); void window_title_exit_open(); void window_title_logo_open(); diff --git a/src/window_about.c b/src/window_about.c new file mode 100644 index 0000000000..c6657996f8 --- /dev/null +++ b/src/window_about.c @@ -0,0 +1,199 @@ +/***************************************************************************** + * Copyright (c) 2014 Ted John + * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. + * + * This file is part of OpenRCT2. + * + * OpenRCT2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + *****************************************************************************/ + +#include +#include "addresses.h" +#include "strings.h" +#include "sprites.h" +#include "widget.h" +#include "window.h" + +static enum WINDOW_ABOUT_WIDGET_IDX { + WIDX_BACKGROUND, + WIDX_TITLE, + WIDX_CLOSE, + WIDX_MUSIC_CREDITS, + WIDX_PUBLISHER_CREDITS +}; + +static rct_widget window_about_widgets[] = { + { WWT_FRAME, 0, 0, 399, 0, 329, 0x0FFFFFFFF, STR_NONE }, // panel / background + { WWT_CAPTION, 0, 1, 398, 1, 14, STR_ROLLERCOASTER_TYCOON_2, STR_WINDOW_TITLE_TIP }, // title bar + { WWT_CLOSEBOX, 0, 387, 397, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, // close x button + { WWT_DROPDOWN_BUTTON, 1, 100, 299, 230, 241, STR_MUSIC_ACKNOWLEDGEMENTS_ELLIPSIS, STR_NONE }, // music credits button + { WWT_DROPDOWN_BUTTON, 1, 157, 356, 307, 318, STR_INFOGRAMES_INTERACTIVE_CREDITS, STR_NONE }, // infogrames credits button + { WIDGETS_END }, +}; + +static void window_about_emptysub() { } +static void window_about_mouseup(); +static void window_about_paint(); + +static uint32 window_about_events[] = { + window_about_emptysub, + window_about_mouseup, + window_about_emptysub, + window_about_emptysub, + window_about_emptysub, + window_about_emptysub, + window_about_emptysub, + window_about_emptysub, + window_about_emptysub, + window_about_emptysub, + window_about_emptysub, + window_about_emptysub, + window_about_emptysub, + window_about_emptysub, + window_about_emptysub, + window_about_emptysub, + window_about_emptysub, + window_about_emptysub, + window_about_emptysub, + window_about_emptysub, + window_about_emptysub, + window_about_emptysub, + window_about_emptysub, + window_about_emptysub, + window_about_emptysub, + window_about_emptysub, + window_about_paint, + window_about_emptysub +}; + +/** + * + * rct2: 0x0066D2AC + */ +void window_about_open() +{ + int x, y; + rct_window* window; + + // Check if window is already open + window = window_bring_to_front_by_id(WC_ABOUT, 0); + if (window != NULL) + return; + + window = window_create( + RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16) / 2 - 200, + max(28, RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16) / 2 - 165), + 400, + 330, + window_about_events, + WC_ABOUT, + 0 + ); + window->widgets = window_about_widgets; + window->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_MUSIC_CREDITS) | (1 << WIDX_PUBLISHER_CREDITS); + + window_init_scroll_widgets(window); + window->colours[0] = 7; + window->colours[1] = 7; + window->colours[2] = 7; +} + +/** + * + * rct2: 0x0066D4D5 + */ +static void window_about_mouseup() +{ + int i; + short widgetIndex; + rct_window *w; + + __asm mov widgetIndex, dx + __asm mov w, esi + + switch (widgetIndex) { + case WIDX_CLOSE: + window_close(w); + break; + case WIDX_MUSIC_CREDITS: + RCT2_CALLPROC_EBPSAFE(0x0066D4EC); + break; + case WIDX_PUBLISHER_CREDITS: + RCT2_CALLPROC_EBPSAFE(0x0066D55B); + break; + } +} + +/** + * + * rct2: 0x0066D321 + */ +static void window_about_paint() +{ + int x, y; + rct_window *w; + rct_drawpixelinfo *dpi; + + __asm mov w, esi + __asm mov dpi, edi + + window_draw_widgets(w, dpi); + + x = w->x + 200; + y = w->y + 17; + + // Version + RCT2_GLOBAL(0x009C383C, uint8) = 49; + gfx_draw_string_centred(dpi, STR_VERSION_X, x, y, 0, 0x009E2D28); + + // Credits + RCT2_GLOBAL(0x009C383C, uint8) = 48; + y += 10; + gfx_draw_string_centred(dpi, STR_COPYRIGHT_CS, x, y, 0, 0x009E2D28); + y += 79; + gfx_draw_string_centred(dpi, STR_DESIGNED_AND_PROGRAMMED_BY_CS, x, y, 0, 0x009E2D28); + y += 10; + gfx_draw_string_centred(dpi, STR_GRAPHICS_BY_SF, x, y, 0, 0x009E2D28); + y += 10; + gfx_draw_string_centred(dpi, STR_SOUND_AND_MUSIC_BY_AB, x, y, 0, 0x009E2D28); + y += 10; + gfx_draw_string_centred(dpi, STR_ADDITIONAL_SOUNDS_RECORDED_BY_DE, x, y, 0, 0x009E2D28); + y += 13; + gfx_draw_string_centred(dpi, STR_REPRESENTATION_BY_JL, x, y, 0, 0x009E2D28); + y += 25; + gfx_draw_string_centred(dpi, STR_THANKS_TO, x, y, 0, 0x009E2D28); + y += 10; + gfx_draw_string_centred(dpi, STR_THANKS_TO_PEOPLE, x, y, 0, 0x009E2D28); + y += 10; + gfx_draw_string_centred(dpi, STR_CREDIT_SPARE_1, x, y, 0, 0x009E2D28); + y += 10; + gfx_draw_string_centred(dpi, STR_CREDIT_SPARE_2, x, y, 0, 0x009E2D28); + y += 10; + gfx_draw_string_centred(dpi, STR_CREDIT_SPARE_3, x, y, 0, 0x009E2D28); + y += 10; + gfx_draw_string_centred(dpi, STR_CREDIT_SPARE_4, x, y, 0, 0x009E2D28); + y += 10; + gfx_draw_string_centred(dpi, STR_CREDIT_SPARE_5, x, y, 0, 0x009E2D28); + y += 10; + gfx_draw_string_centred(dpi, STR_CREDIT_SPARE_6, x, y, 0, 0x009E2D28); + y += 10; + gfx_draw_string_centred(dpi, STR_CREDIT_SPARE_7, x, y, 0, 0x009E2D28); + + // Images + gfx_draw_sprite(dpi, SPR_CREDITS_CHRIS_SAWYER_SMALL, w->x + 92, w->y + 40); + gfx_draw_sprite(dpi, SPR_CREDITS_INFOGRAMES, w->x + 50, w->y + 247); + + // Licence + gfx_draw_string_left(dpi, STR_LICENSED_TO_INFOGRAMES_INTERACTIVE_INC, 0, 0, w->x + 157, w->y + 257); +} \ No newline at end of file diff --git a/src/window_game_top_toolbar.c b/src/window_game_top_toolbar.c index 92a7d4e7b3..959fe03d5b 100644 --- a/src/window_game_top_toolbar.c +++ b/src/window_game_top_toolbar.c @@ -372,7 +372,7 @@ static void window_game_top_toolbar_dropdown() } break; case 3: // about - RCT2_CALLPROC_EBPSAFE(0x0066D2AC); + window_about_open(); break; case 4: // options RCT2_CALLPROC_EBPSAFE(0x006BAC5B); From aeb5e2a0e43d25d156bb7512fca291a876ddb527 Mon Sep 17 00:00:00 2001 From: Alexander Overvoorde Date: Mon, 28 Apr 2014 16:06:07 +0200 Subject: [PATCH 3/5] Add separate key buffer for shortcuts to fix misbehaving panning with keyboard --- src/game.c | 4 ++-- src/osinterface.c | 7 +++++++ src/osinterface.h | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/game.c b/src/game.c index 4feae6733c..5e57312080 100644 --- a/src/game.c +++ b/src/game.c @@ -850,8 +850,8 @@ int get_next_key() { int i; for (i = 0; i < 221; i++) { - if (gKeysState[i]) { - gKeysState[i] = 0; + if (gKeysPressed[i]) { + gKeysPressed[i] = 0; return i; } } diff --git a/src/osinterface.c b/src/osinterface.c index 594a398da2..851462b6dd 100644 --- a/src/osinterface.c +++ b/src/osinterface.c @@ -31,6 +31,7 @@ typedef void(*update_palette_func)(char*, int, int); openrct2_cursor gCursorState; unsigned char* gKeysState; +unsigned char* gKeysPressed; unsigned int gLastKeyPressed; static void osinterface_create_window(); @@ -49,6 +50,9 @@ void osinterface_init() { osinterface_create_window(); + gKeysPressed = malloc(sizeof(unsigned char) * 256); + memset(gKeysPressed, 0, sizeof(unsigned char) * 256); + // RCT2_CALLPROC(0x00404584); // dinput_init() } @@ -253,6 +257,7 @@ void osinterface_process_messages() break; case SDL_KEYDOWN: gLastKeyPressed = e.key.keysym.sym; + gKeysPressed[e.key.keysym.scancode] = 1; break; default: break; @@ -278,6 +283,8 @@ static void osinterface_close_window() void osinterface_free() { + free(gKeysPressed); + osinterface_close_window(); SDL_Quit(); } diff --git a/src/osinterface.h b/src/osinterface.h index ee7e83505f..205d0170a0 100644 --- a/src/osinterface.h +++ b/src/osinterface.h @@ -38,6 +38,7 @@ typedef struct { extern openrct2_cursor gCursorState; extern unsigned char* gKeysState; +extern unsigned char* gKeysPressed; extern unsigned int gLastKeyPressed; void osinterface_init(); From 999429071e1288b183f2297f41fce1c25e406a00 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Mon, 28 Apr 2014 15:29:54 +0100 Subject: [PATCH 4/5] credit author in source code header --- src/osinterface.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/osinterface.c b/src/osinterface.c index 851462b6dd..f2d0ff306a 100644 --- a/src/osinterface.c +++ b/src/osinterface.c @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2014 Ted John + * Copyright (c) 2014 Ted John, Alexander Overvoorde * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. * * This file is part of OpenRCT2. From ce1876127e1be5a4d8395abd280e32f4a539aceb Mon Sep 17 00:00:00 2001 From: Ted John Date: Mon, 28 Apr 2014 17:41:28 +0100 Subject: [PATCH 5/5] fix typo in readme.md --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index c4a0e06119..4671196629 100644 --- a/readme.md +++ b/readme.md @@ -18,7 +18,7 @@ An open source clone of Roller Coaster Tycoon 2 built by decompiling the origina - 3.1 - [Decompiling](#31-decompiling) - 3.2 - [Naming of procedures and variables](#32-naming-of-procedures-and-variables) - 3.3 - [Cleaning and documenting the source code](#33-cleaning-and-documenting-the-source-code) - - 3.4 - [Implementing new featues / fixing bugs](#34-implementing-new-featues--fixing-bugs) + - 3.4 - [Implementing new features / fixing bugs](#34-implementing-new-features--fixing-bugs) - 4 - [Licence](#4-license) # 1 Introduction @@ -65,7 +65,7 @@ Many variables and procedures are referenced in OpenRCT2 only by address. This m ## 3.3 Cleaning and documenting the source code A lot of the source code is undocumented and messy. Whilst the structure of the code should be kept the same so that it closely resembles the original game. Various blocks of code can be moved into smaller functions and macros can be created for common operations. -## 3.4 Implementing new featues / fixing bugs +## 3.4 Implementing new features / fixing bugs If enough of the game has been decompiled to implement a certain feature or fix a certain bug. This can be written. Comments should be added to clearly identify where code has been changed on purpose causing it to differ from the original game assembly. # 4 License