diff options
author | Iru Cai <mytbk920423@gmail.com> | 2018-08-09 11:54:58 +0800 |
---|---|---|
committer | Iru Cai <mytbk920423@gmail.com> | 2018-08-09 11:54:58 +0800 |
commit | 75057cc0de61fd6f7e80636eda1e8d19f3ab3c29 (patch) | |
tree | 022b425da1fa2eca8b161edc2dac4f4754d6738e /csrc | |
parent | eab0ca23e9530a26d083c7094e14cabe169381ef (diff) | |
download | rich4-75057cc0de61fd6f7e80636eda1e8d19f3ab3c29.tar.xz |
main() and a font function
Diffstat (limited to 'csrc')
-rw-r--r-- | csrc/font.c | 28 | ||||
-rw-r--r-- | csrc/main.c | 215 |
2 files changed, 243 insertions, 0 deletions
diff --git a/csrc/font.c b/csrc/font.c new file mode 100644 index 0000000..0d94b98 --- /dev/null +++ b/csrc/font.c @@ -0,0 +1,28 @@ +#include <windows.h> +#include <stdint.h> + +HFONT gFont; // 0x4762d0 +int gFontHeight; // 0x4762d4 +uint32_t gfa[4]; // 0x4762d8, 0x4762dc, 0x4762e0, 0x4762e4 +const char tfname[] = "\xb2\xd3\xa9\xfa\xc5\xe9"; // 0x4660a0, typeface name + +static inline uint32_t swapbytes3(uint32_t x) +{ + return (((x & 0xff) << 16) | (x & 0xff00) | ((x & 0xff0000) >> 16)); +} + +/* 0x0044f9d8 */ +HFONT create_some_font(int a0, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4) +{ + gfa[2] = swapbytes3(a1); + gfa[3] = swapbytes3(a2); + gfa[0] = a3; + gfa[1] = a4; + int weight = (a3==2)?400:700; + if (gFont != 0) { + DeleteObject(gFont); + } + gFontHeight = a0; + gFont = CreateFontA(-a0, 0, 0, 0, weight, 0, 0, 0, 0x88 /* charset */, 0, 0, 0, 0, tfname); + return gFont; +} diff --git a/csrc/main.c b/csrc/main.c new file mode 100644 index 0000000..e85f7ac --- /dev/null +++ b/csrc/main.c @@ -0,0 +1,215 @@ +#include <windows.h> + +HINSTANCE ghInstance; // 48a064 +gwindowHandle; // 48a0d4 +uint32_t dw_46cadc; + +Surface **sf1; + +char mid_status[7]; // 0x46cb00 +uint32_t windowCallbacks[100]; // 48a010 + +LRESULT CALLBACK windowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + eax = message; + edx = wParam; + ebx = 0; + if (eax < 0x1c) + goto L1; // 401a02 + if (eax <= 0x1c) + goto L2; // 401a10 + if (eax == 0x3b9) + goto L3; // 401b08 + goto L4; // 401b33 + L1: + if (eax == WM_DESTROY) + goto L5; // 041b24 + goto L4; + L2: + if (edx == 0) + goto L6; // 401a9f + if (dw_46cb0b == 0) + goto L7; // 401a87 + if (sf1 == NULL) + goto L8; // 401a31 + (*sf1)->_6c(*sf1); + L8: + if (mid_status[2] != 0) { + mciSendStringA("resume vfw", 0, 0, 0); + } + if (mid_status[3] != 0) { + mciSendStringA("resume mid", 0, 0, 0); + } + if (mid_status[4] != 0) { + mciSendStringA("play cdtrack notify", 0, 0, gwindowHandle); + } + L7: + SetFocus(hWnd); + mid_status[1] = 1; + return 0; // 401b6e + L6: + dw_46cb0b = 1; + mid_status[1] = 0; + if (mid_status[2] != 0) { + mciSendStringA("pause vfw", 0,0,0); + } + if (mid_status[3] != 0) { + mciSendStringA("pause mid", 0, 0, 0); + } + if (mid_status[4] != 0) { + mciSendStringA("stop cdtrack", 0, 0, 0); + } + return 0; + L3: + if (edx != 1) + return 0; + if (mid_status[2] == 0) + goto L15; // 401b1d + fcn_0045174a(); + return 0; + L15: + sub_mciSendStringA_d2c(); + return 0; + L5: + sub_UnhookWindowsHookEx_815(); + PostQuitMessage(0); + return 0; + L4: + ebx = dw_46cad8 << 2; + if (dw_48a010[ebx] == 0) + return DefWindowProcA(hWnd, message, wParam, lParam); + edi = lParam; + return (dw_48a010[ebx](hWnd, message, wParam, lParam)); +} + +int WINAPI WinMain(HINSTANCE hInstance, + HINSTANCE hPrevInstance, + LPSTR lpCmdLine, + int nCmdShow) +{ + ghInstance = hInstance; + WNDCLASS wc = { + .style = 0, + .lpfnWndProc = windowProc, + .cbClsExtra = 0, + .cbWndExtra = 0, + .hInstance = hInstance, + .hIcon = LoadIconA(hInstance, "RICH4_ICON"), // esp+0x14 + .hCursor = LoadCursorA(0, 0x7f00), // esp+0x18 + .hbrBackground = GetStockObject(4), // esp + 0x1c + .lpszMenuName = NULL, + .lpszClassName = "Rich4" + }; // @ esp + + if (RegisterClassA(&wc) == 0) { + return -1; + } + int height = GetSystemMetrics(1); + int width = GetSystemMetrics(0); + gwindowHandle = CreateWindowExA(0, "Rich4", "Rich4", WS_POPUP, 0, 0, width, height, NULL, NULL, ghInstance, NULL); + int ret = sub_MessageBoxA_5d6(); + if (ret == 0) { + return 0; + } + ShowWindow(gwindowHandle, SW_SHOW); + UpdateWindow(gwindowHandle); + play_avi("START.AVI", &dw_46cadc, 1); + case_401de8_0: + w_4991b6 = 0; + w_4991b8 = 0; + dw_4990f0 = 0; + b_46cafc = 0; + ret = fcn_004029fd(); + // jump table: 401cc8 401d08 401d2b 401d18 401cbf + L401cb3: + switch (ret) { + case 4: + w_4991b6 = 1; + // fallthrough + case 0: + if (fcn_00406de7((int)b_46cafc)==0) + goto case_401de8_0; + fcn_00401543(); + fcn_00407ad2(); + fcn_004190cf(); + fcn_004291d6(); + fcn_00415872(); + b_46cafc = 1; + sub_PostMessageA_981(0); + goto case_default_401d2b; + case 1: + switch_401cb8_case_1: + fcn_004190cf(); + b_46cafc = 1; + sub_PostMessageA_981(1); + goto case_default_401d2b; + case 3: + sub_UnhookWindowsHookEx_815(); + L401d24: + DestroyWindow(gwindowHandle); + default: + case_default_401d2b: + loop: + MSG msg; +/* +typedef struct tagMSG { + HWND hwnd; + UINT message; + WPARAM wParam; + LPARAM lParam; + DWORD time; + POINT pt; +} MSG; +*/ + while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) { + if (msg.message == WM_QUIT) + return msg.wParam; + TranslateMessage(&msg); + DispatchMessage(&msg); + } + if (mid_status[1] == 0) + goto loop; + if (dw_475110 != 0) + fcn_004192f7(); + if (b_46cafa != 0) + fcn_0040d7c4(); + eax = dw_49910c * 0x34; + if (b_498ea2[eax] == 0) { + if (b_498ea0[eax] != 0x80) { + dl = b_498ea0[eax] & 0x7f; + b_498ea0[eax] = dl; + sub_SetCursorPos_c55(); + } + } + if (b_46caf8 == 0) + goto 401e03; + mid_status[6] = 0; + bl = b_46caf8; + sub_KillTimer_228(); + fcn_004019d2(); + b_46caf8 = 0; + eax = (int)bl - 1; + switch (eax) { + case 0: + goto case_401de8_0; + case 1: + ebx = 0; + fcn_004075c1(); + if (b_46caf9 == 0) + goto L401cb3; + default: + if (b_46caf9 == 0) + goto case_default_401d2b; // PeekMessageA ... + fcn_00451b36(); + sub_UnhookWindowsHookEx_815(); + goto 401d24; // DestroyWindow(gwindowHandle) ... + case 2: + fcn_004075c1(); + goto case_401de8_0; // after play_avi ... + case 3: + if (process_checkpoint(0) == -1) + goto case_401de8_0; + goto switch_401cb8_case_1; + } + +} |