From 6de4fa1fcf9a284b26637e79d1127199f3252a03 Mon Sep 17 00:00:00 2001 From: zsilencer Date: Mon, 1 Sep 2014 15:42:56 -0600 Subject: [PATCH] low-hanging fruit --- src/addresses.h | 3 + src/osinterface.c | 174 +++++++++++++++++++++++++++++++++++++++++++++- src/osinterface.h | 5 ++ 3 files changed, 181 insertions(+), 1 deletion(-) diff --git a/src/addresses.h b/src/addresses.h index 80ef4cbe20..c3a3f343db 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -170,6 +170,9 @@ #define RCT2_ADDRESS_CMDLINE 0x009E2D98 +#define RCT2_ADDRESS_PROGRESSBAR_HFONT 0x009E2DEC +#define RCT2_ADDRESS_PROGRESSBAR_HWND 0x009E2DF8 + #define RCT2_ADDRESS_LAND_RAISE_COST 0x009E2E1C #define RCT2_ADDRESS_LAND_LOWER_COST 0x009E2E20 #define RCT2_ADDRESS_SELECTED_TERRAIN_EDGE 0x009E2E24 diff --git a/src/osinterface.c b/src/osinterface.c index 9213603e7d..4f8a1565e3 100644 --- a/src/osinterface.c +++ b/src/osinterface.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include @@ -442,6 +441,179 @@ void osinterface_set_fullscreen_mode(int mode){ config_save(); } +/** + * + * rct2: 0x00407E6E + */ +int osinterface_progressbar_create(char* title, int a2) +{ + DWORD style = WS_VISIBLE | WS_BORDER | WS_DLGFRAME; + if (a2) { + style = WS_VISIBLE | WS_BORDER | WS_DLGFRAME | PBS_SMOOTH; + } + int width = 340; + int height = GetSystemMetrics(SM_CYCAPTION) + 24; + HWND hwnd = CreateWindowExA(WS_EX_TOPMOST | WS_EX_DLGMODALFRAME, "msctls_progress32", title, style, (RCT2_GLOBAL(0x01423C08, sint32) - width) / 2, (RCT2_GLOBAL(0x01423C0C, sint32) - height) / 2, width, height, 0, 0, RCT2_GLOBAL(RCT2_ADDRESS_HINSTANCE, HINSTANCE), 0); + RCT2_GLOBAL(RCT2_ADDRESS_PROGRESSBAR_HWND, HWND) = hwnd; + if (hwnd) { + RCT2_GLOBAL(0x009E2DFC, uint32) = 1; + if (RCT2_GLOBAL(RCT2_ADDRESS_PROGRESSBAR_HFONT, HFONT)) { + SendMessageA(hwnd, WM_SETFONT, (WPARAM)RCT2_GLOBAL(RCT2_ADDRESS_PROGRESSBAR_HFONT, HFONT), 1); + } + SetWindowTextA(hwnd, title); + osinterface_progressbar_setmax(0xFF); + osinterface_progressbar_setpos(0); + return 1; + } else { + return 0; + } +} + +/** + * + * rct2: 0x00407F16 + */ +int osinterface_progressbar_destroy() +{ + if (DestroyWindow(RCT2_GLOBAL(RCT2_ADDRESS_PROGRESSBAR_HWND, HWND))) { + RCT2_GLOBAL(0x009E2DFC, uint32) = 0; + return 1; + } else { + return 0; + } +} + +/** + * + * rct2: 0x00407F2E + */ +LRESULT osinterface_progressbar_setmax(int max) +{ + SendMessageA(RCT2_GLOBAL(RCT2_ADDRESS_PROGRESSBAR_HWND, HWND), PBM_SETRANGE, MAKEWPARAM(0, max), 0); + return SendMessageA(RCT2_GLOBAL(RCT2_ADDRESS_PROGRESSBAR_HWND, HWND), PBM_SETSTEP, 1, 0); +} + +/** + * + * rct2: 0x00407F60 + */ +LRESULT osinterface_progressbar_setpos(WPARAM wparam) +{ + return SendMessageA(RCT2_GLOBAL(RCT2_ADDRESS_PROGRESSBAR_HWND, HWND), PBM_SETPOS, wparam, 0); +} + +/** + * + * rct2: 0x00407F78 + */ +int osinterface_file_seek_from_begin(HANDLE handle, int offset) +{ + return SetFilePointer(handle, offset, 0, FILE_BEGIN); +} + +/** + * + * rct2: 0x00407F8B + */ +int osinterface_file_seek_from_current(HANDLE handle, int offset) +{ + return SetFilePointer(handle, offset, 0, FILE_CURRENT); +} + +/** + * + * rct2: 0x00407F9E + */ +int osinterface_file_seek_from_end(HANDLE handle, int offset) +{ + return SetFilePointer(handle, offset, 0, FILE_END); +} + +/** + * + * rct2: 0x00407FB1 + */ +int osinterface_file_read(HANDLE handle, void* data, int size) +{ + DWORD read; + BOOL result; + if (size == -1) { + DWORD current = SetFilePointer(handle, 0, 0, FILE_CURRENT); + DWORD remaining = SetFilePointer(handle, 0, 0, FILE_END) - current; + result = ReadFile(handle, data, remaining, &read, 0); + } else { + result = ReadFile(handle, data, size, &read, 0); + } + if (result) { + return read; + } else { + return -1; + } +} + +/** + * + * rct2: 0x00408024 + */ +int osinterface_file_write(HANDLE handle, const void* data, int size) +{ + DWORD written; + if (WriteFile(handle, data, size, &written, 0)) { + return written; + } else { + return -1; + } +} + +/** + * + * rct2: 0x0040804A + */ +int osinterface_file_close(HANDLE handle) +{ + if (handle) { + return CloseHandle(handle); + } else { + return 1; + } +} + +/** + * + * rct2: 0x00408060 + */ +HANDLE osinterface_file_open(char* filename) +{ + return CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS | FILE_ATTRIBUTE_NORMAL, 0); +} + +/** + * + * rct2: 0x0040807D + */ +HANDLE osinterface_file_create(char* filename) +{ + return CreateFileA(filename, GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); +} + +/** + * + * rct2: 0x00408099 + */ +int osinterface_file_move(char* srcfilename, char* dstfilename) +{ + return (MoveFileA(srcfilename, dstfilename) != 0) - 1; +} + +/** + * + * rct2: 0x004080AF + */ +int osinterface_file_delete(char* filename) +{ + return (DeleteFileA(filename) != 0) - 1; +} + /** * * rct2: 0x004080EA diff --git a/src/osinterface.h b/src/osinterface.h index 6d2cade7aa..8465a5f1d5 100644 --- a/src/osinterface.h +++ b/src/osinterface.h @@ -21,6 +21,8 @@ #ifndef _SDL_INTERFACE_H_ #define _SDL_INTERFACE_H_ +#include + enum { CURSOR_UP = 0, CURSOR_DOWN = 1, @@ -79,6 +81,9 @@ void osinterface_update_palette(char* colours, int start_index, int num_colours) void osinterface_set_fullscreen_mode(int mode); +LRESULT osinterface_progressbar_setmax(int max); +LRESULT osinterface_progressbar_setpos(WPARAM wparam); + void osinterface_set_cursor(char cursor); int osinterface_open_common_file_dialog(int type, char *title, char *filename, char *filterPattern, char *filterName);