summaryrefslogtreecommitdiff
path: root/csrc/main.c
diff options
context:
space:
mode:
authorIru Cai <mytbk920423@gmail.com>2018-09-02 22:32:05 +0800
committerIru Cai <mytbk920423@gmail.com>2018-09-02 22:32:05 +0800
commit683fac617f572a110e39839c6e0691c2d51ec578 (patch)
tree9f2a10632728a785f35674a49d7afb2eb1cb0685 /csrc/main.c
parent7fd904d4021e86ebe34389744153eea18b1b773f (diff)
downloadrich4-683fac617f572a110e39839c6e0691c2d51ec578.tar.xz
WinMain: refactor the switch-case things
Diffstat (limited to 'csrc/main.c')
-rw-r--r--csrc/main.c252
1 files changed, 126 insertions, 126 deletions
diff --git a/csrc/main.c b/csrc/main.c
index 04f30b5..9ed5d44 100644
--- a/csrc/main.c
+++ b/csrc/main.c
@@ -83,133 +83,133 @@ LRESULT CALLBACK windowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPara
}
int WINAPI WinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- int nCmdShow)
+ 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
+ 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 = initialize();
- if (ret == 0) {
- return 0;
- }
- ShowWindow(gwindowHandle, SW_SHOW);
- UpdateWindow(gwindowHandle);
- play_avi("START.AVI", &g_rect, 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;
- }
+ 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 = initialize();
+ if (ret == 0) {
+ return 0;
+ }
+ ShowWindow(gwindowHandle, SW_SHOW);
+ UpdateWindow(gwindowHandle);
+ play_avi("START.AVI", &g_rect, 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);
+ break;
+ case 1:
+switch_401cb8_case_1:
+ fcn_004190cf();
+ b_46cafc = 1;
+ sub_PostMessageA_981(1);
+ break;
+ case 3:
+ sub_UnhookWindowsHookEx_815();
+ DestroyWindow(gwindowHandle);
+ break;
+ default:
+ break;
+ }
+
+start_msg_loop:
+
+ do {
+ MSG msg;
+ while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) {
+ if (msg.message == WM_QUIT)
+ return msg.wParam;
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ } while (mid_status[1] == 0);
+
+ 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 loop_end;
+ 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:
+ ret = 0;
+ fcn_004075c1();
+ if (b_46caf9 == 0)
+ goto L401cb3;
+ break;
+ case 2:
+ fcn_004075c1();
+ goto case_401de8_0;
+ case 3:
+ if (process_checkpoint(0) == -1)
+ goto case_401de8_0;
+ goto switch_401cb8_case_1;
+ default:
+ break;
+ }
+
+loop_end:
+ if (b_46caf9 == 0)
+ goto start_msg_loop;
+ fcn_00451b36();
+ sub_UnhookWindowsHookEx_815();
+ DestroyWindow(gwindowHandle);
+ goto start_msg_loop;
}