1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
#include <windows.h>
#include <ddraw.h>
#include "global.h"
HINSTANCE ghInstance; // 48a064
HWND gwindowHandle; // 48a0d4
RECT g_rect;
char mid_status[7]; // 0x46cb00
wProc windowCallbacks[100]; // 48a010
LRESULT CALLBACK windowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (message < 0x1c) {
if (message == WM_DESTROY) {
sub_UnhookWindowsHookEx_815();
PostQuitMessage(0);
return 0;
}
if (windowCallbacks[dw_46cad8] == NULL) {
return DefWindowProcA(hWnd, message, wParam, lParam);
} else {
return (windowCallbacks[dw_46cad8](hWnd, message, wParam, lParam));
}
}
if (message == WM_ACTIVATEAPP) {
if (wParam != 0) {
if (dw_46cb0b != 0) {
if (pddrawsf1 != NULL) {
IDirectDrawSurface_Restore(pddrawsf1);
}
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);
}
}
SetFocus(hWnd);
mid_status[1] = 1;
return 0;
}
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;
}
if (message == MM_MCINOTIFY) {
if (wParam != 1)
return 0;
if (mid_status[2] != 0) {
fcn_0045174a();
return 0;
}
sub_mciSendStringA_d2c();
return 0;
}
if (windowCallbacks[dw_46cad8] == NULL) {
return DefWindowProcA(hWnd, message, wParam, lParam);
} else {
return (windowCallbacks[dw_46cad8](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 = 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 (init_new_game((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;
}
|