From 7be8253dc9749dca2d702f87c75600e0f81731cf Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Tue, 18 Sep 2018 21:18:03 -0500 Subject: [PATCH] Implement "mainmenu.cpp" in DiabloUI (#297) --- DiabloUI/_temp_data.cpp | 11 +- DiabloUI/_temp_funcs.h | 19 +-- DiabloUI/diabloui.h | 2 +- DiabloUI/mainmenu.cpp | 276 ++++++++++++++++++---------------------- 4 files changed, 144 insertions(+), 164 deletions(-) diff --git a/DiabloUI/_temp_data.cpp b/DiabloUI/_temp_data.cpp index 01f521eb0..812604a66 100644 --- a/DiabloUI/_temp_data.cpp +++ b/DiabloUI/_temp_data.cpp @@ -14,6 +14,7 @@ int doom_cpp_float_value = 2139095040; // weak int fade_cpp_float_value = 2139095040; // weak int focus_cpp_float_value = 2139095040; // weak int local_cpp_float_value = 2139095040; // weak +int mainmenu_cpp_float_value = 2139095040; // weak int Title_cpp_float_value = 2139095040; // weak int titlesnd_cpp_float_value = 2139095040; // weak int dword_10022258 = 4; // weak @@ -43,8 +44,8 @@ int dword_10022B10[2] = { 1116, 0 }; int dword_10022B34[2] = { 1038, 0 }; int dword_10022B3C[3] = { 1056, 1054, 0 }; int dword_10022B48[2] = { 1065, 0 }; -int dword_10022BE0[2] = { 1042, 0 }; -int dword_10022BE8[6] = { 1044, 1001, 1002, 1003, 2, 0 }; +int menumsgs_1option[2] = { 1042, 0 }; +int menumsgs_5options[6] = { 1044, 1001, 1002, 1003, 2, 0 }; int dword_10022C4C[2] = { 1038, 0 }; int dword_10022C54[2] = { 1080, 0 }; int dword_10022C5C[2] = { 1108, 0 }; @@ -236,9 +237,9 @@ tagPALETTEENTRY artpal[256]; HGDIOBJ objPalette; // idb BYTE *gpCursorArt; BYTE *gpCursorArt2; -int dword_1002A0D4; // weak -char byte_1002A0D8; // idb -int dword_1002A118; // weak +int mainmenu_cpp_float; // weak +char menu_version_str[64]; +int menu_item_timer; // weak int dword_1002A120; // weak int dword_1002A124; // weak int dword_1002A128; // weak diff --git a/DiabloUI/_temp_funcs.h b/DiabloUI/_temp_funcs.h index 9a5e56240..2f559a4c3 100644 --- a/DiabloUI/_temp_funcs.h +++ b/DiabloUI/_temp_funcs.h @@ -292,15 +292,16 @@ void __cdecl local_SetCursorDefault(); void __fastcall local_SetDiabloCursor(HWND hWnd); -signed int MainMenu_10008164(); -//int __stdcall UiMainMenuDialog(char *, int, int, int); // idb -int __fastcall MainMenu_100081E3(int a1, int a2, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); -void UNKCALL MainMenu_10008354(HWND hDlg); -int __fastcall MainMenu_10008391(int a1, int a2); -void UNKCALL MainMenu_100083A8(HWND hWnd); -int __fastcall MainMenu_1000845A(int a1, int a2, int a3); -BOOL MainMenu_100084D5(); -LRESULT __fastcall MainMenu_100084FA(HWND hWnd, int a2); +void __cdecl j_MainMenu_cpp_init(); +void __cdecl MainMenu_cpp_init(); +BOOL __stdcall UiMainMenuDialog(char *name, int *pdwResult, void (__stdcall *fnSound)(char *file), int a4); +LRESULT __stdcall MainMenu_WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); +void __fastcall MainMenu_KillAndFreeMenu(HWND hWnd); +void __fastcall MainMenu_SetMenuTimer(HWND hWnd); +void __fastcall MainMenu_LoadMenuGFX(HWND hWnd); +void __fastcall MainMenu_DoOptions(HWND hWnd, int option, int PlaySelect); +BOOL __cdecl MainMenu_CheckEnoughMemory(); +void __fastcall MainMenu_CheckWParamFocus(HWND hWnd, WPARAM wParam); int Modem_1000855D(); diff --git a/DiabloUI/diabloui.h b/DiabloUI/diabloui.h index c977ac8c1..85b35e862 100644 --- a/DiabloUI/diabloui.h +++ b/DiabloUI/diabloui.h @@ -37,7 +37,7 @@ int __stdcall UiValidPlayerName(char *a1); int __stdcall UiSelHeroMultDialog(void *fninfo, void *fncreate, void *fnremove, void *fnstats, int *a5, int *a6, char *name); int __stdcall UiSelHeroSingDialog(void *fninfo, void *fncreate, void *fnremove, void *fnstats, int *a5, char *name, int *difficulty); void __stdcall UiCreditsDialog(int a1); -int __stdcall UiMainMenuDialog(char *name, int *a2, void *fnSound, int a4); +BOOL __stdcall UiMainMenuDialog(char *name, int *pdwResult, void (__stdcall *fnSound)(char *file), int a4); int __stdcall UiProgressDialog(HWND window, char *msg, int a3, void *fnfunc, int a5); int __cdecl UiProfileGetString(); void __cdecl UiProfileCallback(); diff --git a/DiabloUI/mainmenu.cpp b/DiabloUI/mainmenu.cpp index ab042291d..e37174af5 100644 --- a/DiabloUI/mainmenu.cpp +++ b/DiabloUI/mainmenu.cpp @@ -1,43 +1,38 @@ // ref: 0x10008164 -signed int MainMenu_10008164() { return 0; } -/* { - signed int result; // eax - - result = 2139095040; - dword_1002A0D4 = 2139095040; - return result; -} */ -// 1002A0D4: using guessed type int dword_1002A0D4; +void __cdecl MainMenu_cpp_init() +{ + mainmenu_cpp_float = mainmenu_cpp_float_value; +} +// 1001F434: using guessed type int mainmenu_cpp_float_value; +// 1002A0D4: using guessed type int mainmenu_cpp_float; // ref: 0x1000816F -int __stdcall UiMainMenuDialog(char *name, int *a2, void *fnSound, int a4) { return 0; } -/* { +BOOL __stdcall UiMainMenuDialog(char *name, int *pdwResult, void (__stdcall *fnSound)(char *file), int a4) +{ int v4; // eax int v5; // esi - dword_1002A118 = a4; - TitleSnd_10010306((void *)a3); - artfont_10001159(); - byte_1002A0D8 = 0; - if ( a1 ) - strncpy((char *)&byte_1002A0D8, a1, 0x40u); - v4 = SDrawGetFrameWindow(); - v5 = SDlgDialogBoxParam(hInstance, "MAINMENU_DIALOG", v4, MainMenu_100081E3, 0); + menu_item_timer = a4; + TitleSnd_SetSoundFunction(fnSound); + artfont_LoadAllFonts(); + menu_version_str[0] = 0; + if ( name ) + strncpy(menu_version_str, name, 0x40u); + v4 = (int)SDrawGetFrameWindow(); + v5 = SDlgDialogBoxParam(ghUiInst, "MAINMENU_DIALOG", v4, MainMenu_WndProc, 0); if ( v5 == 5 ) - artfont_100010C8(); - if ( a2 ) - *(_DWORD *)a2 = v5; + artfont_FreeAllFonts(); + if ( pdwResult ) + *pdwResult = v5; return 1; -} */ -// 10010370: using guessed type int __stdcall SDlgDialogBoxParam(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD); +} // 10010382: using guessed type _DWORD __stdcall SDrawGetFrameWindow(); -// 1002A118: using guessed type int dword_1002A118; +// 1002A118: using guessed type int menu_item_timer; // ref: 0x100081E3 -int __stdcall MainMenu_100081E3(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { return 0; } -/* { +LRESULT __stdcall MainMenu_WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) +{ HWND v5; // eax - int v6; // [esp+0h] [ebp-Ch] if ( Msg <= 0x113 ) { @@ -45,7 +40,7 @@ int __stdcall MainMenu_100081E3(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lPara { if ( Msg == 2 ) { - MainMenu_10008354(hWnd); + MainMenu_KillAndFreeMenu(hWnd); } else if ( Msg > 0x103 ) { @@ -58,37 +53,37 @@ int __stdcall MainMenu_100081E3(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lPara { if ( Msg == 272 ) { - MainMenu_100083A8(hWnd); + MainMenu_LoadMenuGFX(hWnd); PostMessageA(hWnd, 0x7E8u, 0, 0); return 1; } if ( Msg == 273 ) { - MainMenu_10008391(hWnd); + MainMenu_SetMenuTimer(hWnd); switch ( HIWORD(wParam) ) { case 7: - Focus_100075B7(hWnd, (HWND)lParam); + Focus_GetAndBlitSpin(hWnd, lParam); break; case 6: - Focus_10007458((void *)lParam); - Focus_100075DC(hWnd, (HWND)lParam); + Focus_CheckPlayMove(lParam); + Focus_DoBlitSpinIncFrame(hWnd, (HWND)lParam); break; case 0: - MainMenu_100084FA(hWnd, (unsigned short)wParam); + MainMenu_CheckWParamFocus(hWnd, (unsigned short)wParam); break; } } } } - return SDlgDefDialogProc(hWnd, Msg, wParam, lParam); + return (LRESULT)SDlgDefDialogProc(hWnd, Msg, (HDC)wParam, (HWND)lParam); } - if ( wParam == 3 && !DiabloUI_10005C2A() ) + if ( wParam == 3 && !DiabloUI_GetSpawned() ) { - if ( dword_10029728 ) - MainMenu_1000845A((int)hWnd, 6, 0); + if ( app_is_active ) + MainMenu_DoOptions(hWnd, 6, 0); else - MainMenu_10008391(hWnd); + MainMenu_SetMenuTimer(hWnd); } return 0; } @@ -97,156 +92,139 @@ int __stdcall MainMenu_100081E3(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lPara if ( Msg <= 0x202 ) goto LABEL_34; if ( Msg <= 0x203 ) - return SDlgDefDialogProc(hWnd, Msg, wParam, lParam); + return (LRESULT)SDlgDefDialogProc(hWnd, Msg, (HDC)wParam, (HWND)lParam); if ( Msg <= 0x205 ) { LABEL_34: - MainMenu_10008391(hWnd); - return SDlgDefDialogProc(hWnd, Msg, wParam, lParam); + MainMenu_SetMenuTimer(hWnd); + return (LRESULT)SDlgDefDialogProc(hWnd, Msg, (HDC)wParam, (HWND)lParam); } if ( Msg == 2024 ) { - if ( !Fade_1000739F() ) - Fade_100073FD(hWnd, v6); + if ( !Fade_CheckRange5() ) + Fade_SetFadeTimer((int)hWnd); return 0; } } - return SDlgDefDialogProc(hWnd, Msg, wParam, lParam); -} */ -// 1001037C: using guessed type int __stdcall SDlgDefDialogProc(_DWORD, _DWORD, _DWORD, _DWORD); + return (LRESULT)SDlgDefDialogProc(hWnd, Msg, (HDC)wParam, (HWND)lParam); +} // 10010382: using guessed type _DWORD __stdcall SDrawGetFrameWindow(); -// 10029728: using guessed type int dword_10029728; +// 10029728: using guessed type int app_is_active; // ref: 0x10008354 -void UNKCALL MainMenu_10008354(HWND hDlg) { return; } -/* { - HWND v1; // esi - _DWORD *v2; // eax - - v1 = hDlg; - Title_100100E7(hDlg); - Focus_10007818(v1); - Doom_10006C53(v1, (int *)&unk_10022BE8); - Doom_10006C53(v1, (int *)&unk_10022BE0); - v2 = (_DWORD *)GetWindowLongA(v1, -21); - local_10007F72(v2); - return local_1000811B(); -} */ +void __fastcall MainMenu_KillAndFreeMenu(HWND hWnd) +{ + void **v2; // eax + + Title_KillTitleTimer(hWnd); + Focus_KillFocusTimer(hWnd); + Doom_DeleteFreeProcs(hWnd, menumsgs_5options); + Doom_DeleteFreeProcs(hWnd, menumsgs_1option); + v2 = (void **)GetWindowLongA(hWnd, -21); + local_FreeMemPtr(v2); + local_SetCursorDefault(); +} // ref: 0x10008391 -int UNKCALL MainMenu_10008391(void *arg) { return 0; } -/* { - return SDlgSetTimer(arg, 3, 1000 * dword_1002A118, 0); -} */ -// 10010412: using guessed type int __stdcall SDlgSetTimer(_DWORD, _DWORD, _DWORD, _DWORD); -// 1002A118: using guessed type int dword_1002A118; +void __fastcall MainMenu_SetMenuTimer(HWND hWnd) +{ + SDlgSetTimer((int)hWnd, 3, 1000 * menu_item_timer, 0); +} +// 1002A118: using guessed type int menu_item_timer; // ref: 0x100083A8 -void UNKCALL MainMenu_100083A8(HWND hWnd) { return; } -/* { - HWND v1; // esi - int v2; // eax - int *v3; // edi +void __fastcall MainMenu_LoadMenuGFX(HWND hWnd) +{ + DWORD *v2; // eax MAPDST bool v4; // zf const char *v5; // eax HWND v6; // eax - HWND v7; // ST1C_4 - HWND v9; // [esp+0h] [ebp-8h] - v1 = hWnd; - v2 = local_10007F46(); - v3 = (int *)v2; + v2 = local_AllocWndLongData(); if ( v2 ) { - SetWindowLongA(v1, -21, v2); - v4 = DiabloUI_10005C2A() == 0; + SetWindowLongA(hWnd, -21, (LONG)v2); + v4 = DiabloUI_GetSpawned() == 0; v5 = "ui_art\\swmmenu.pcx"; if ( v4 ) v5 = "ui_art\\mainmenu.pcx"; - local_10007944((int)v1, 0, &byte_10029448, -1, 1, (int)v5, v3, v3 + 1, 0); - Fade_100073C5(v1, 1); + local_LoadArtWithPal(hWnd, 0, &nullcharacter, -1, 1, v5, (BYTE **)v2, v2 + 1, 0); + Fade_NoInputAndArt(hWnd, 1); } - v6 = GetDlgItem(v1, 1042); - SetWindowTextA(v6, &byte_1002A0D8); - Doom_100068AB(v1, (int *)&unk_10022BE0, 1); - Doom_1000658C(v1, (int *)&unk_10022BE8, 6, 1); - Focus_100077E9((int)v1, "ui_art\\focus42.pcx", v9); - Title_1001009E(v1, (int)"ui_art\\smlogo.pcx", v7); - MainMenu_10008391(v1); - return local_10007DE9(v1, (int *)&unk_10022BE8); -} */ + v6 = GetDlgItem(hWnd, 1042); + SetWindowTextA(v6, menu_version_str); + Doom_ParseWndProc3(hWnd, menumsgs_1option, 1); + Doom_ParseWndProcs(hWnd, menumsgs_5options, 6, 1); + Focus_SetFocusTimer(hWnd, "ui_art\\focus42.pcx"); + Title_LoadImgSetTimer(hWnd, "ui_art\\smlogo.pcx"); + MainMenu_SetMenuTimer(hWnd); + local_DoUiWndProc2(hWnd, (DWORD *)menumsgs_5options); +} // ref: 0x1000845A -int __fastcall MainMenu_1000845A(int a1, int a2, int a3) { return 0; } -/* { - int v3; // esi - int v4; // edi - - v3 = a1; - v4 = a2; - SDlgKillTimer(a1, 3); - if ( DiabloUI_10005C2A() && v4 == 3 ) +void __fastcall MainMenu_DoOptions(HWND hWnd, int option, int PlaySelect) +{ + SDlgKillTimer((int)hWnd, 3); + if ( DiabloUI_GetSpawned() && option == 3 ) { - SelYesNo_1000FD77(v3, 0x46u, 1); - return SDlgSetTimer(v3, 3, 1000 * dword_1002A118, 0); + SelYesNo_1000FD77((int)hWnd, 0x46u, 1); +LABEL_7: + SDlgSetTimer((int)hWnd, 3, 1000 * menu_item_timer, 0); + return; } - if ( v4 == 2 && !MainMenu_100084D5() ) + if ( option == 2 && !MainMenu_CheckEnoughMemory() ) { - SelYesNo_1000FD77(v3, 0x4Eu, 1); - return SDlgSetTimer(v3, 3, 1000 * dword_1002A118, 0); + SelYesNo_1000FD77((int)hWnd, 0x4Eu, 1); + goto LABEL_7; } - Fade_100073B4(); - if ( a3 ) - TitleSnd_1001031F(); - Fade_100072BE(10); - return SDlgEndDialog(v3, v4); -} */ -// 10010376: using guessed type int __stdcall SDlgEndDialog(_DWORD, _DWORD); -// 10010412: using guessed type int __stdcall SDlgSetTimer(_DWORD, _DWORD, _DWORD, _DWORD); -// 10010418: using guessed type int __stdcall SDlgKillTimer(_DWORD, _DWORD); -// 1002A118: using guessed type int dword_1002A118; + Fade_Range5SetZero(); + if ( PlaySelect ) + TitleSnd_PlaySelectSound(); + Fade_UpdatePaletteRange(10); + SDlgEndDialog(hWnd, (HANDLE)option); +} +// 1002A118: using guessed type int menu_item_timer; // ref: 0x100084D5 -BOOL MainMenu_100084D5() { return 0; } -/* { +BOOL __cdecl MainMenu_CheckEnoughMemory() +{ struct _MEMORYSTATUS Buffer; // [esp+0h] [ebp-20h] Buffer.dwLength = 32; GlobalMemoryStatus(&Buffer); return Buffer.dwTotalPhys > 0xDAC000; -} */ +} // ref: 0x100084FA -LRESULT __fastcall MainMenu_100084FA(HWND hWnd, int a2) { return 0; } -/* { - HWND v2; // esi - LRESULT result; // eax - HWND v4; // eax - LONG v5; // eax - int v6; // [esp-8h] [ebp-Ch] +void __fastcall MainMenu_CheckWParamFocus(HWND hWnd, WPARAM wParam) +{ + HWND v3; // eax + LONG v4; // eax + int v5; // [esp-8h] [ebp-Ch] - v2 = hWnd; - switch ( a2 ) + switch ( wParam ) { - case 1: - v4 = GetFocus(); - v5 = GetWindowLongA(v4, -12); - return SendMessageA(v2, 0x111u, v5, 0); - case 2: - v6 = 5; - return MainMenu_1000845A((int)hWnd, v6, 1); - case 1001: - v6 = 2; - return MainMenu_1000845A((int)hWnd, v6, 1); - case 1002: - v6 = 3; - return MainMenu_1000845A((int)hWnd, v6, 1); - case 1003: - v6 = 4; - return MainMenu_1000845A((int)hWnd, v6, 1); + case 1u: + v3 = GetFocus(); + v4 = GetWindowLongA(v3, -12); + SendMessageA(hWnd, 0x111u, v4, 0); + return; + case 2u: + v5 = 5; + goto LABEL_12; + case 0x3E9u: + v5 = 2; + goto LABEL_12; + case 0x3EAu: + v5 = 3; + goto LABEL_12; + case 0x3EBu: + v5 = 4; +LABEL_12: + MainMenu_DoOptions(hWnd, v5, 1); + return; + case 0x414u: + MainMenu_DoOptions(hWnd, 1, 1); + break; } - result = a2 - 1044; - if ( a2 == 1044 ) - result = MainMenu_1000845A((int)hWnd, 1, 1); - return result; -} */ +}