summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIru Cai <mytbk920423@gmail.com>2018-09-25 07:43:02 +0800
committerIru Cai <mytbk920423@gmail.com>2018-09-25 07:45:07 +0800
commitf38b1e589c9a8000911ce14642f496c4267b71d6 (patch)
treec861aa7556e744cf5d3cce3ce37b3cad098f412e
parent0248e480c58e8e1de8f64d258999634b1db06cd0 (diff)
downloadrich4-f38b1e589c9a8000911ce14642f496c4267b71d6.tar.xz
name fcn_4018e7 as register_wait_callback, and move it to window_util
-rw-r--r--csrc/cards_ui.c26
-rw-r--r--csrc/game_init.c3
-rw-r--r--csrc/global.h2
-rw-r--r--csrc/main.c12
-rw-r--r--csrc/media_init.c6
-rw-r--r--csrc/tools_ui.c3
-rw-r--r--csrc/window_util.c34
-rw-r--r--csrc/window_util.h14
8 files changed, 64 insertions, 36 deletions
diff --git a/csrc/cards_ui.c b/csrc/cards_ui.c
index 77b65ac..d284f10 100644
--- a/csrc/cards_ui.c
+++ b/csrc/cards_ui.c
@@ -6,6 +6,7 @@
#include "player_info.h"
#include "global.h"
#include "sound_struct.h"
+#include "window_util.h"
uint8_t player_cards[60]; // 0x499120
int selected_card; // 0x48c544
@@ -54,29 +55,6 @@ rich4_card cards_table[] = {
{ "\xaf\x51\xc0\x74\xa5\x64", 3, 70, 0, 0 }, /* 乌龟卡 */
};
-int fcn_4018e7(wProc a1, int a2)
-{
- dw_46cad8++;
- windowCallbacks[dw_46cad8] = a1;
- PostMessageA(gwindowHandle, 0x401, 0, a2);
- while (1) {
- MSG msg;
- if (PeekMessageA(&msg, 0, 0, 0, 1) == 0)
- continue;
- if (msg.message == 0x402) {
- dw_46cad8--;
- return msg.lParam;
- }
- TranslateMessage(&msg);
- DispatchMessageA(&msg);
- }
-}
-
-void Post_0402_Message(LPARAM lp)
-{
- PostMessageA(gwindowHandle, 0x402, 0, lp);
-}
-
sound_struct snd0 = {1, NULL}; // 0x00482322
sound_struct snd1 = {3, NULL}; // 0x0048233a
sound_struct snd2; // 0x0048cae0
@@ -196,7 +174,7 @@ void cards_ui()
IDirectDrawSurface_Lock(pddrawsf2, NULL, &sfdesc1, 1, 0);
fcn_004563f5(sfdesc1.lpSurface, edi+12, 14, 130);
IDirectDrawSurface_Unlock(pddrawsf2, NULL);
- ebx = fcn_4018e7(cardProc, 0);
+ ebx = register_wait_callback(cardProc, 0);
fcn_00451edb(ebp, 0, 0x8028);
if (ebx != 0) {
edx = cards_table[ebx].name_ptr; /* cards_table has 8 bytes per item */
diff --git a/csrc/game_init.c b/csrc/game_init.c
index 444dc7e..cf28c98 100644
--- a/csrc/game_init.c
+++ b/csrc/game_init.c
@@ -4,6 +4,7 @@
*/
#include "player_info.h"
+#include "window_util.h"
int mkf_jump; // 0x48a3b0
@@ -126,7 +127,7 @@ int init_new_game(int a0)
sub.WINMM.dll_mciSendStringA_9cf(0x8001); /* TODO: 0x4549cf */
- int res = fcn_4018e7(0x404e44, a0); /* function in cards_ui.c */
+ int res = register_wait_callback(0x404e44, a0);
*(int*)(esp + 4) = res;
unload_mkf(mkf_jump);
diff --git a/csrc/global.h b/csrc/global.h
index 348a1be..eece702 100644
--- a/csrc/global.h
+++ b/csrc/global.h
@@ -28,8 +28,6 @@ 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 */
-typedef LRESULT (CALLBACK *wProc)(HWND, UINT, WPARAM, LPARAM);
-extern wProc windowCallbacks[100]; // 48a010
/* card.c */
extern uint8_t card_amount[30];
diff --git a/csrc/main.c b/csrc/main.c
index 94f98b2..65acbd2 100644
--- a/csrc/main.c
+++ b/csrc/main.c
@@ -6,13 +6,13 @@
#include <windows.h>
#include <ddraw.h>
#include "global.h"
+#include "window_util.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)
{
@@ -22,10 +22,10 @@ LRESULT CALLBACK windowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPara
PostQuitMessage(0);
return 0;
}
- if (windowCallbacks[dw_46cad8] == NULL) {
+ if (windowCallbacks[cb_top] == NULL) {
return DefWindowProcA(hWnd, message, wParam, lParam);
} else {
- return (windowCallbacks[dw_46cad8](hWnd, message, wParam, lParam));
+ return (windowCallbacks[cb_top](hWnd, message, wParam, lParam));
}
}
if (message == WM_ACTIVATEAPP) {
@@ -71,10 +71,10 @@ LRESULT CALLBACK windowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPara
sub_mciSendStringA_d2c();
return 0;
}
- if (windowCallbacks[dw_46cad8] == NULL) {
+ if (windowCallbacks[cb_top] == NULL) {
return DefWindowProcA(hWnd, message, wParam, lParam);
} else {
- return (windowCallbacks[dw_46cad8](hWnd, message, wParam, lParam));
+ return (windowCallbacks[cb_top](hWnd, message, wParam, lParam));
}
}
@@ -213,7 +213,7 @@ int fcn_004029fd()
create_some_font(0x10, 0xf0f0f0, 0x101010, 3, 1);
draw_some_text(dw_48a180 + 12, "V3.11", 638, 470, 6);
sub.WINMM.dll_mciSendStringA_9cf(0);
- ebx = fcn_4018e7(entryCallback, 0);
+ ebx = register_wait_callback(entryCallback, 0);
sub.WINMM.dll_mciSendStringA_acb();
free(dw_48a180);
return ebx;
diff --git a/csrc/media_init.c b/csrc/media_init.c
index 6ba19f8..eae6081 100644
--- a/csrc/media_init.c
+++ b/csrc/media_init.c
@@ -7,6 +7,7 @@
#include "data_struct.h"
#include "player_info.h"
#include "sound_struct.h"
+#include "window_util.h"
DDSURFACEDESC sfdesc1; // 0x0048a068
DDSURFACEDESC sfdesc2; // 0x0048a0f8
@@ -186,7 +187,7 @@ LRESULT CALLBACK kbdProc(
/* hotkey 0x497172 */
k = R4_KEY(global_rich4_cfg.hotkeys[5]); /* cancel */
if (wParam == k && R4_KEY_RELEASED(lParam)) {
- if (b_46cafe != 0 && dw_46cad8 == 1) {
+ if (b_46cafe != 0 && cb_top == 1) {
uint32_t ebx = 0;
for (size_t i = 0; i < nplayers; i++) {
if (players[i].who_plays == 1 &&
@@ -672,7 +673,8 @@ bool initialize()
mid_status[5] = 0;
memset(0x4990f0, 0, 4);
dw_474938 = malloc(387200);
- dw_474930 = dw_474934 = dw_46cad8 = 0;
+ dw_474930 = dw_474934 = 0;
+ cb_top = 0;
windowCallbacks[0] = NULL;
b_47e771 = 0;
return 1;
diff --git a/csrc/tools_ui.c b/csrc/tools_ui.c
index 3577721..4b90950 100644
--- a/csrc/tools_ui.c
+++ b/csrc/tools_ui.c
@@ -4,6 +4,7 @@
*/
#include "player_info.h"
+#include "window_util.h"
const char str_cross_sym[] = "\xa1\xd1%d"; // x%d
@@ -151,7 +152,7 @@ void tools_ui()
fcn.004563f5(sfdesc1.lpSurface, edi + 0x18, 0xe, 0x82);
IDirectDrawSurface_Unlock(pddrawsf2, NULL);
- esi = fcn_4018e7(toolsProc, 0);
+ esi = register_wait_callback(toolsProc, 0);
IDirectDrawSurface_Lock(pddrawsf2, 0, &sfdesc1, 1, 0);
fcn.004563f5(sfdesc1.lpSurface, dw_48c558, 0, 40);
diff --git a/csrc/window_util.c b/csrc/window_util.c
new file mode 100644
index 0000000..41c857a
--- /dev/null
+++ b/csrc/window_util.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2018 Iru Cai <mytbk920423@gmail.com>
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include "window_util.h"
+
+wProc windowCallbacks[100]; // 48a010
+int cb_top = 0; // 0x46cad8
+
+extern HWND gwindowHandle;
+
+int register_wait_callback(wProc a1, int a2)
+{
+ cb_top++;
+ windowCallbacks[cb_top] = a1;
+ PostMessageA(gwindowHandle, 0x401, 0, a2);
+ while (1) {
+ MSG msg;
+ if (PeekMessageA(&msg, 0, 0, 0, 1) == 0)
+ continue;
+ if (msg.message == 0x402) {
+ cb_top--;
+ return msg.lParam;
+ }
+ TranslateMessage(&msg);
+ DispatchMessageA(&msg);
+ }
+}
+
+void Post_0402_Message(LPARAM lp)
+{
+ PostMessageA(gwindowHandle, 0x402, 0, lp);
+}
diff --git a/csrc/window_util.h b/csrc/window_util.h
new file mode 100644
index 0000000..af4dbd9
--- /dev/null
+++ b/csrc/window_util.h
@@ -0,0 +1,14 @@
+/*
+ * Copyright (C) 2018 Iru Cai <mytbk920423@gmail.com>
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include <windows.h>
+
+extern int cb_top;
+
+typedef LRESULT (CALLBACK *wProc)(HWND, UINT, WPARAM, LPARAM);
+extern wProc windowCallbacks[100]; // 48a010
+
+int register_wait_callback(wProc a1, int a2);
+void Post_0402_Message(LPARAM lp);