summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIru Cai <mytbk920423@gmail.com>2018-09-25 09:42:33 +0800
committerIru Cai <mytbk920423@gmail.com>2018-09-25 09:42:33 +0800
commit82dc6f263f267775f3df18345129815b271a7611 (patch)
tree710135061676eabc511766ac7ec11d81f7d78f56
parentc590b935077438ed85ca97477038dbe97fc2fff2 (diff)
downloadrich4-82dc6f263f267775f3df18345129815b271a7611.tar.xz
rewrite entryCallback, game stage
-rw-r--r--csrc/game_init.c12
-rw-r--r--csrc/global.h1
-rw-r--r--csrc/loadsave.c20
-rw-r--r--csrc/main.c47
4 files changed, 46 insertions, 34 deletions
diff --git a/csrc/game_init.c b/csrc/game_init.c
index a0ee827..b156d55 100644
--- a/csrc/game_init.c
+++ b/csrc/game_init.c
@@ -44,7 +44,7 @@ int init_new_game(int a0)
dw_48a354 = malloc(0x96000);
dw_48a358 = malloc(0x96000);
mkf_jump = load_mkf("JUMP.MKF");
- read_mkf(mkf_jump, w_4991b6*4+w_4991b8 /* sign ext */, dw_48a358, NULL);
+ read_mkf(mkf_jump, game_stage*4+w_4991b8 /* sign ext */, dw_48a358, NULL);
fcn_004552b7(dw_48a354, dw_48a358, 0x96000, -16); /* @ bit_functions.c */
dw_48a3a4 = allocate_some_struct(440, 155, 0, 0);
dw_48a3a0 = allocate_some_struct(192, 461, 0, 0);
@@ -93,7 +93,7 @@ int init_new_game(int a0)
dw_46cb54 = w_4991b8; /* sign ext */
- edx = w_4991b6; /* sign ext */
+ edx = game_stage; /* sign ext */
eax = edx*20;
edx = eax+1;
eax = edx * 3;
@@ -101,7 +101,7 @@ int init_new_game(int a0)
eax = dw_48a3b8 + 12 + edx;
dw_48a390 = fcn_00451a97(eax, 0, 0x8a, 15, 41, 133); /* function in data_struct.c */
- edx = w_4991b6; /* sign ext */
+ edx = game_stage; /* sign ext */
eax = edx * 20;
edx = eax + 1;
eax = edx * 12;
@@ -109,7 +109,7 @@ int init_new_game(int a0)
eax += edx;
dw_48a398 = fcn_00451a97(eax, 0, 11, 166, 79, 39);
- edx = w_4991b6; /* sign ext */
+ edx = game_stage; /* sign ext */
eax = edx * 20;
edx = eax + 1;
eax = edx * 12;
@@ -117,7 +117,7 @@ int init_new_game(int a0)
eax += edx;
dw_48a394 = fcn_00451a97(eax, 0, 99, 166, 79, 39);
- edx = w_4991b6; /* sign ext */
+ edx = game_stage; /* sign ext */
eax = edx * 20;
edx = eax + 1;
eax = edx * 3;
@@ -198,7 +198,7 @@ int init_new_game(int a0)
dword [ecx + eax*4 + 0x497328] = 0;
}
}
- eax = w_4991b6 * 4; // sign ext
+ eax = game_stage * 4; // sign ext
edx = w_4991b8 + eax; // sign ext
eax = edx * 48;
edx = eax;
diff --git a/csrc/global.h b/csrc/global.h
index eece702..1b316af 100644
--- a/csrc/global.h
+++ b/csrc/global.h
@@ -28,6 +28,7 @@ char * read_mkf(int mkf_idx, int a1, char *buf, int *bufsize);
extern HINSTANCE ghInstance; // 48a064
extern HWND gwindowHandle; // 48a0d4
extern RECT g_rect; /* struct tagRECT { left, top, right, bottom } @ 0x46cadc */
+int16_t game_stage;
/* card.c */
extern uint8_t card_amount[30];
diff --git a/csrc/loadsave.c b/csrc/loadsave.c
index e46e037..392813d 100644
--- a/csrc/loadsave.c
+++ b/csrc/loadsave.c
@@ -93,11 +93,11 @@ void fcn_00407ad2()
{
fcn_004080f5();
ebx = edi = load_mkf("MAP.MKF");
- eax = (w_4991b6*4+w_4991b8)*2;
+ eax = (game_stage*4+w_4991b8)*2;
dw_474945 = read_mkf(ebx, eax, NULL, NULL);
- eax = (w_4991b6*4+w_4991b8)+16;
+ eax = (game_stage*4+w_4991b8)+16;
dw_48badc = read_mkf(ebx, eax, NULL, NULL);
- eax = w_4991b6*4+w_4991b8+16;
+ eax = game_stage*4+w_4991b8+16;
dw_48bad0 = read_mkf(ebx, eax, NULL, NULL);
memcpy(0x48b6b4, dw_474945 + 0x10, 512);
dw_48bac4 = *(int*)dw_474945 + 0x210;
@@ -108,11 +108,11 @@ void fcn_00407ad2()
if (dw_47493c == 0) {
esi = eax = load_mkf("MAPDAT.MKF");
if (eax != -1) {
- eax = w_4991b6*4+w_4991b8;
+ eax = game_stage*4+w_4991b8;
dw_47493c = read_mkf(esi, eax, NULL, NULL);
unload_mkf(esi);
} else {
- eax = (w_4991b6*4+w_4991b8)*2+1;
+ eax = (game_stage*4+w_4991b8)*2+1;
dw_47493c = read_mkf(ebx, eax, NULL, NULL);
}
/* 0x407c3f */
@@ -175,7 +175,7 @@ void fcn_00407ad2()
}
/* 0x407e0b */
for (ebx = 0; ebx < 5; ebx++) {
- eax = *(int16_t*)0x4991b6; /* sign ext */
+ eax = game_stage; /* sign ext */
eax *= 4;
edx = *(int16_t*)0x4991b8; /* sign ext */
esi = edx + eax;
@@ -183,11 +183,11 @@ void fcn_00407ad2()
*(int*)(0x48ae4c + ebx*4) = read_mkf(edi, eax, NULL, NULL);
}
edx = *(int16_t*)0x4991b8; /* sign ext */
- eax = *(int16_t*)0x4991b6; /* sign ext */
+ eax = game_stage; /* sign ext */
edx += 0x4f;
eax = eax * 4 + edx;
dw_48ae60 = read_mkf(edi, eax, NULL, NULL);
- if (*(int16_t*)0x4991b6 == 0) {
+ if (game_stage == 0) {
for (ebx = 0; ebx < 17; ebx++) {
dw_48ae64[ebx] = read_mkf(edi, ebx+0x57, NULL, NULL);
}
@@ -301,7 +301,7 @@ int load_checkpoint(int n)
fseek(fp, 4, SEEK_SET);
fread(&global_rich4_cfg.day, 4, 1, fp); // read day,month,year
fread(0x4991b8, 2, 1, fp);
- fread(0x4991b6, 2, 1, fp);
+ fread(&game_stage, 2, 1, fp);
fread(&nplayers, 4, 1, fp);
fread(players, sizeof(player_info), 4, fp);
fread(0x499104, 4, 1, fp);
@@ -323,7 +323,7 @@ int load_checkpoint(int n)
fread(0x496980, 0x24, 0xc, fp);
for (int i = 0; i < 12; i++) {
- int32_t edx = (*(int16_t*)0x4991b6) << 2;
+ int32_t edx = game_stage << 2;
edx += (*(int16_t*))0x4991b8;
eax = edx << 2;
eax -= edx; /* eax = edx * 3 */
diff --git a/csrc/main.c b/csrc/main.c
index 65acbd2..eed760d 100644
--- a/csrc/main.c
+++ b/csrc/main.c
@@ -14,6 +14,17 @@ RECT g_rect;
char mid_status[7]; // 0x46cb00
+typedef struct { int16_t x; int16_t y } pos_t;
+pos_t mpos[5] = { // 0x46cb28
+ {190, 380}, // start
+ {328, 380}, // load
+ {468, 378}, // options
+ {328, 450}, // exit
+ {62, 380} // new stage
+};
+
+int16_t game_stage;
+
LRESULT CALLBACK windowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (message < 0x1c) {
@@ -81,9 +92,9 @@ LRESULT CALLBACK windowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPara
LRESULT CALLBACK entryCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (message >= 0x200) {
- if (message == 0x200) {
- edx = (u16)lParam;
- ecx = (lParam >> 16) & 0xffff;
+ if (message == WM_MOUSEMOVE) {
+ int xPos = LOWORD(lParam);
+ int yPos = HIWORD(lParam);
int var_54 = dw_48a184;
RECT r0; // @ esp + 0x40
@@ -92,23 +103,23 @@ LRESULT CALLBACK entryCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP
edi = (i * 2 + 2) * 12;
eax = dw_48a180;
ebx = i * 4;
- r0.left = (s16)word [ebx + 0x46cb28] - (s16)word [edi + eax + 0x10];
- r0.top = (s16)word [ebx + 0x46cb2a] - (s16)word [edi + eax + 0x12];
+ r0.left = mpos[i].x - (s16)word [edi + eax + 0x10];
+ r0.top = mpos[i].y - (s16)word [edi + eax + 0x12];
r0.right = r0.left + (s16)word [edi + eax + 0xc];
r0.bottom = r0.top + (s16)word [edi + eax + 0xe];
- if (edx < r0.left)
+ if (xPos < r0.left)
continue;
- if (ecx < r0.top)
+ if (yPos < r0.top)
continue;
- if (edx >= r0.right)
+ if (xPos >= r0.right)
continue;
- if (ecx >= r0.bottom)
+ if (yPos >= r0.bottom)
continue;
if (i == dw_48a184)
break;
dw_48a184 = i;
IDirectDrawSurface_Lock(pddrawsf2, NULL, &sfdesc1, 1, 0);
- fcn_456418(sfdesc1.lpSurface, dw_48a180 + 12 + edi, (s16)word [ebx + 0x46cb28], (s16)word [ebx + 0x46cb2a]);
+ fcn_456418(sfdesc1.lpSurface, dw_48a180 + 12 + edi, mpos[i].x, mpos[i].y);
IDirectDrawSurface_Unlock(pddrawsf2, NULL);
InvalidateRect(hWnd, &r0, FALSE);
fcn_4542ce(0x48231a, 0);
@@ -122,8 +133,8 @@ LRESULT CALLBACK entryCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP
return 0;
edx = dw_48a180;
eax = dw_48a180 + (var_54 * 2 + 2) * 12;
- r0.left = (s16)word [var_54*4 + 0x46cb28] - (s16)word [eax + 0x10];
- r0.top = (s16)word [var_54*4 + 0x46cb2a] - (s16)word [eax + 0x12];
+ r0.left = mpos[var_54].x - (s16)word [eax + 0x10];
+ r0.top = mpos[var_54].y - (s16)word [eax + 0x12];
r0.right = r0.left + (s16)word [eax + 0xc];
r0.bottom = r0.top + (s16)word [eax + 0xe];
IDirectDrawSurface_Lock(pddrawsf2, NULL, &sfdesc1, 1, 0);
@@ -134,7 +145,7 @@ LRESULT CALLBACK entryCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP
InvalidateRect(hWnd, &r0, FALSE);
return 0;
}
- if (message == 0x201) {
+ if (message == WM_LBUTTONDOWN) {
if (dw_48a184 != -1) {
fcn_4542ce(0x482322, 0);
}
@@ -185,7 +196,7 @@ LRESULT CALLBACK entryCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP
}
return DefWindowProcA(hWnd, message, wParam, lParam);
}
- if (message == 15) {
+ if (message == WM_PAINT) {
PAINTSTRUCT ps;
BeginPaint(hWnd, &ps);
GetCursorPos_35d(&ps.rcPaint);
@@ -202,8 +213,8 @@ int fcn_004029fd()
dw_48a180 = read_mkf(mkf_data, 1, NULL, NULL);
for (int i = 0; i < 5; i++) { // i in ebx
- int t1 = (signed short)word [ebx*4 + 0x46cb28];
- int t2 = (signed short)word [ebx*4 + 0x46cb2a];
+ int t1 = mpos[i].x;
+ int t2 = mpos[i].y;
edx = (i * 2 + 1) * 12;
eax = dw_48a180 + 12;
edx += eax;
@@ -253,7 +264,7 @@ int WINAPI WinMain(HINSTANCE hInstance,
play_avi("START.AVI", &g_rect, 1);
case_401de8_0:
- w_4991b6 = 0;
+ game_stage = 0;
w_4991b8 = 0;
dw_4990f0 = 0;
b_46cafc = 0;
@@ -262,7 +273,7 @@ case_401de8_0:
L401cb3:
switch (ret) {
case 4:
- w_4991b6 = 1;
+ game_stage = 1;
// fallthrough
case 0:
if (init_new_game((int)b_46cafc)==0)