comparison mm7_2.cpp @ 1588:e6ac4919b22c

Слияние
author Ritor1
date Mon, 09 Sep 2013 09:13:40 +0600
parents 9a6567c6c76c
children 75fafd8ced59 f408fbf3d9cc 0016b08ab621
comparison
equal deleted inserted replaced
1587:b42e6f35e03d 1588:e6ac4919b22c
2 #define _CRT_SECURE_NO_WARNINGS 2 #define _CRT_SECURE_NO_WARNINGS
3 #endif 3 #endif
4 4
5 #include <io.h> 5 #include <io.h>
6 #include <direct.h> 6 #include <direct.h>
7 #include <assert.h> 7
8 #include <windows.h> 8 #include "OSAPI.h"
9
10 9
11 #include "Texture.h" 10 #include "Texture.h"
12 #include "mm7_data.h" 11 #include "mm7_data.h"
13 #include "VideoPlayer.h" 12 #include "VideoPlayer.h"
14 #include "Sprites.h" 13 #include "Sprites.h"
683 char *v7; // edx@10 682 char *v7; // edx@10
684 char *v8; // ecx@12 683 char *v8; // ecx@12
685 char *v9; // eax@14 684 char *v9; // eax@14
686 unsigned int v10; // eax@25 685 unsigned int v10; // eax@25
687 GUIWindow pWindow; // [sp+34h] [bp-9Ch]@1 686 GUIWindow pWindow; // [sp+34h] [bp-9Ch]@1
688 MSG Msg; // [sp+88h] [bp-48h]@22 687 //MSG Msg; // [sp+88h] [bp-48h]@22
689 unsigned int v14; // [sp+A4h] [bp-2Ch]@5 688 unsigned int v14; // [sp+A4h] [bp-2Ch]@5
690 void *v15; // [sp+A8h] [bp-28h]@1 689 void *v15; // [sp+A8h] [bp-28h]@1
691 char *pInString; // [sp+ACh] [bp-24h]@5 690 char *pInString; // [sp+ACh] [bp-24h]@5
692 unsigned int v17; // [sp+B0h] [bp-20h]@5 691 unsigned int v17; // [sp+B0h] [bp-20h]@5
693 unsigned int v18; // [sp+B4h] [bp-1Ch]@5 692 unsigned int v18; // [sp+B4h] [bp-1Ch]@5
803 else 802 else
804 { 803 {
805 LODWORD(v23) = GetTickCount() + 5000; 804 LODWORD(v23) = GetTickCount() + 5000;
806 while ( (unsigned int)v23 > GetTickCount() ) 805 while ( (unsigned int)v23 > GetTickCount() )
807 ; 806 ;
808 while ( 1 ) 807 for (MSG msg; PeekMessage(&msg, 0, 0, 0, PM_REMOVE);)
809 { 808 {
810 v10 = PeekMessageA(&Msg, 0, 0, 0, 1u); 809 if (msg.message == WM_QUIT)
811 if ( !v10 )
812 break;
813 if ( Msg.message == 18 )
814 Game_DeinitializeAndTerminate(0); 810 Game_DeinitializeAndTerminate(0);
815 TranslateMessage(&Msg); 811 TranslateMessage(&msg);
816 DispatchMessageA(&Msg); 812 DispatchMessage(&msg);
817 } 813 }
818 if ( pMessageQueue_50CBD0->uNumMessages ) 814 if ( pMessageQueue_50CBD0->uNumMessages )
819 { 815 {
820 LOBYTE(v10) = pMessageQueue_50CBD0->pMessages[0].field_8 != 0; 816 LOBYTE(v10) = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
821 pMessageQueue_50CBD0->uNumMessages = v10; 817 pMessageQueue_50CBD0->uNumMessages = v10;
822 } 818 }
823 pKeyActionMap->ResetKeys(); 819 pKeyActionMap->ResetKeys();
824 pKeyActionMap->uLastKeyPressed = 0; 820 pKeyActionMap->uLastKeyPressed = 0;
825 do 821 do
826 { 822 {
827 while ( PeekMessageA(&Msg, 0, 0, 0, 1u) ) 823 for (MSG msg; PeekMessage(&msg, 0, 0, 0, PM_REMOVE);)
828 { 824 {
829 if ( Msg.message == 18 ) 825 if (msg.message == WM_QUIT)
830 Game_DeinitializeAndTerminate(0); 826 Game_DeinitializeAndTerminate(0);
831 TranslateMessage(&Msg); 827 TranslateMessage(&msg);
832 DispatchMessageA(&Msg); 828 DispatchMessage(&msg);
833 } 829 }
834 } 830 }
835 while ( !pKeyActionMap->uLastKeyPressed ); 831 while ( !pKeyActionMap->uLastKeyPressed );
836 result = pMessageQueue_50CBD0->uNumMessages; 832 result = pMessageQueue_50CBD0->uNumMessages;
837 if ( pMessageQueue_50CBD0->uNumMessages ) 833 if ( pMessageQueue_50CBD0->uNumMessages )
3089 for (uint i = 0; i < uNumLevelDecorations; ++i) 3085 for (uint i = 0; i < uNumLevelDecorations; ++i)
3090 if (pLevelDecorations[i].uDecorationDescID == id) 3086 if (pLevelDecorations[i].uDecorationDescID == id)
3091 event_triggers[num_event_triggers++] = i; 3087 event_triggers[num_event_triggers++] = i;
3092 } 3088 }
3093 3089
3094 OPENFILENAMEA ofn;
3095 //----- (0046271C) --------------------------------------------------------
3096 void CreateDefaultBLVLevel()
3097 {
3098 ofn.lStructSize = 0x4Cu;
3099 ofn.hwndOwner = hWnd;
3100 ofn.hInstance = 0;
3101 ofn.lpstrFilter = "Indoor BLV Files (*.blv)";
3102 ofn.lpstrCustomFilter = 0;
3103 ofn.nMaxCustFilter = 0;
3104 ofn.nFilterIndex = 0;
3105 ofn.lpstrFile = 0;
3106 ofn.nMaxFile = 260;
3107 ofn.nMaxFileTitle = 512;
3108 ofn.lpstrInitialDir = "levels";
3109 ofn.lpstrTitle = "Might and Magic VII - Load Which Level?";
3110 ofn.Flags = 4;
3111 ofn.nFileOffset = 0;
3112 ofn.nFileExtension = 0;
3113 ofn.lpstrDefExt = "blv";
3114 ofn.lCustData = 0;
3115 ofn.lpfnHook = 0;
3116 ofn.lpTemplateName = 0;
3117 ofn.lpstrFileTitle = pTmpBuf.data();
3118 }
3119
3120 //----- (004627B7) -------------------------------------------------------- 3090 //----- (004627B7) --------------------------------------------------------
3121 void MainMenu_Loop() 3091 void MainMenu_Loop()
3122 { 3092 {
3123 GUIButton *pButton; // eax@27 3093 GUIButton *pButton; // eax@27
3124 unsigned int pControlParam; // ecx@35 3094 unsigned int pControlParam; // ecx@35
3169 LoadUI_Load(0); 3139 LoadUI_Load(0);
3170 } 3140 }
3171 pWindow = pGUIWindow_CurrentMenu; 3141 pWindow = pGUIWindow_CurrentMenu;
3172 } 3142 }
3173 3143
3174 MSG msg; 3144 for (MSG msg; PeekMessage(&msg, 0, 0, 0, PM_REMOVE);)
3175 while ( PeekMessageA(&msg, 0, 0, 0, PM_REMOVE) )
3176 { 3145 {
3177 if (msg.message == WM_QUIT) 3146 if (msg.message == WM_QUIT)
3178 Game_DeinitializeAndTerminate(0); 3147 Game_DeinitializeAndTerminate(0);
3179 TranslateMessage(&msg); 3148 TranslateMessage(&msg);
3180 DispatchMessageA(&msg); 3149 DispatchMessage(&msg);
3181 } 3150 }
3182 if (dword_6BE364_game_settings_1 & 0x0100) 3151 if (dword_6BE364_game_settings_1 & 0x0100)
3183 { 3152 {
3184 WaitMessage(); 3153 WaitMessage();
3185 } 3154 }
3256 pWindow_MainMenu->Release(); 3225 pWindow_MainMenu->Release();
3257 pIcons_LOD->RemoveTexturesPackFromTextureList(); 3226 pIcons_LOD->RemoveTexturesPackFromTextureList();
3258 } 3227 }
3259 3228
3260 //----- (004637EB) -------------------------------------------------------- 3229 //----- (004637EB) --------------------------------------------------------
3261 int __stdcall aWinProc(HWND hWnd, UINT Msg, WPARAM wParam, unsigned int lParam) 3230 int __stdcall aWinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3262 { 3231 {
3263 HANDLE v6; // eax@32 3232 //HANDLE v6; // eax@32
3264 HDC v10; // edi@50 3233 //HDC v10; // edi@50
3265 int v11; // esi@50 3234 //int v11; // esi@50
3266 signed int v13; // eax@135 3235 //signed int v13; // eax@135
3267 char v29; // dl@209 3236 //char v29; // dl@209
3268 bool v31; // ebx@211 3237 //bool v31; // ebx@211
3269 float v33; // ST04_4@246 3238 //float v33; // ST04_4@246
3270 float v34; // ST04_4@254 3239 //float v34; // ST04_4@254
3271 struct tagPAINTSTRUCT Paint; // [sp+24h] [bp-48h]@13 3240 //struct tagPAINTSTRUCT Paint; // [sp+24h] [bp-48h]@13
3272 int pXY[2]; // [sp+64h] [bp-8h]@261 3241 //int pXY[2]; // [sp+64h] [bp-8h]@261
3273 int a2; // [sp+7Ch] [bp+10h]@50 3242 //int a2; // [sp+7Ch] [bp+10h]@50
3274 3243
3275 switch (Msg) 3244 switch (uMsg)
3276 { 3245 {
3277 case WM_SIZING: return 1; 3246 case WM_SIZING: return 1;
3247
3248 case WM_CREATE: case WM_NCCREATE:
3249 case WM_GETTEXT: case WM_SETTEXT:
3278 case WM_SHOWWINDOW: 3250 case WM_SHOWWINDOW:
3279 case WM_GETTEXT: 3251 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
3280 case WM_SETTEXT: return DefWindowProcW(hWnd, Msg, wParam, lParam); 3252
3253 case WM_DESTROY:
3254 SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
3255 PostQuitMessage(0);
3256 return 0;
3281 3257
3282 case WM_WINDOWPOSCHANGED: 3258 case WM_WINDOWPOSCHANGED:
3283 { 3259 {
3284 if (pVideoPlayer && pVideoPlayer->AnyMovieLoaded() && pVideoPlayer->pBinkBuffer) 3260 if (pVideoPlayer && pVideoPlayer->AnyMovieLoaded() && pVideoPlayer->pBinkBuffer)
3285 BinkBufferSetOffset(pVideoPlayer->pBinkBuffer, 0, 0); 3261 BinkBufferSetOffset(pVideoPlayer->pBinkBuffer, 0, 0);
3286 3262
3287 return DefWindowProcW(hWnd, Msg, wParam, lParam); 3263 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
3288 } 3264 }
3289 3265
3290 case WM_CHAR: 3266 case WM_CHAR:
3291 { 3267 {
3292 if (!pKeyActionMap->_459F10(wParam) && !viewparams->field_4C) 3268 if (!pKeyActionMap->_459F10(wParam) && !viewparams->field_4C)
3293 GUI_HandleHotkey(wParam); 3269 GUI_HandleHotkey(wParam);
3294 } 3270 }
3295 return DefWindowProcA(hWnd, Msg, wParam, lParam); 3271 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
3296 3272
3297 3273
3298 case WM_DEVICECHANGE: 3274 case WM_DEVICECHANGE:
3299 { 3275 {
3300 if (wParam == 0x8000) // CD or some device has been inserted - notify InsertCD dialog 3276 if (wParam == 0x8000) // CD or some device has been inserted - notify InsertCD dialog
3301 PostMessageA(hInsertCDWindow, WM_USER + 1, 0, 0); 3277 PostMessageW(hInsertCDWindow, WM_USER + 1, 0, 0);
3302 return 0; 3278 return 0;
3303 } 3279 }
3304 3280
3305 case WM_COMMAND: 3281 case WM_COMMAND:
3306 { 3282 {
3308 { 3284 {
3309 case 103: pRenderer->SavePCXScreenshot(); return 0; 3285 case 103: pRenderer->SavePCXScreenshot(); return 0;
3310 3286
3311 case 101: // Quit game 3287 case 101: // Quit game
3312 case 40001: 3288 case 40001:
3313 SendMessageA(::hWnd, WM_DESTROY, 0, 0); 3289 SendMessageW(hWnd, WM_DESTROY, 0, 0);
3314 return 0; 3290 return 0;
3315 3291
3316 3292
3317 case 104: 3293 case 104:
3318 pRenderer->ChangeBetweenWinFullscreenModes(); 3294 pRenderer->ChangeBetweenWinFullscreenModes();
3477 } 3453 }
3478 return 0; 3454 return 0;
3479 3455
3480 } 3456 }
3481 } 3457 }
3482 return DefWindowProcA(hWnd, Msg, wParam, lParam); 3458 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
3483 }; 3459
3484 3460 case WM_LBUTTONDOWN:
3485 if ( Msg > WM_SYSCOMMAND ) 3461 if (pArcomageGame->bGameInProgress)
3486 { 3462 {
3487 switch ( Msg ) 3463 pArcomageGame->stru1.field_0 = 7;
3488 { 3464 ArcomageGame::OnMouseClick(0, true);
3489 case WM_LBUTTONDOWN: 3465 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
3490 if ( pArcomageGame->bGameInProgress ) 3466 }
3491 { 3467
3492 pArcomageGame->stru1.field_0 = 7; 3468 goto __handle_mouse_click;
3493 ArcomageGame::OnMouseClick(0, 1); 3469
3494 return DefWindowProcA(hWnd, Msg, wParam, lParam); 3470 case WM_RBUTTONDOWN:
3495 } 3471 if (pArcomageGame->bGameInProgress)
3496 goto __handle_mouse_click; 3472 {
3497
3498 case WM_RBUTTONDOWN:
3499 v31 = 0;
3500 if ( !pArcomageGame->bGameInProgress )
3501 //goto LABEL_240;
3502 {
3503 if ( pVideoPlayer->pVideoFrame.pPixels != (unsigned __int16 *)v31 )
3504 pVideoPlayer->bStopBeforeSchedule = 1;
3505
3506 pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
3507 if (pGame)
3508 {
3509 v33 = pGame->pIndoorCameraD3D->GetPickDepth();
3510 pGame->PickMouse(v33, (unsigned __int16)lParam, lParam >> 16, v31, &vis_sprite_filter_2, &vis_door_filter);
3511 }
3512
3513 sub_416D62_ShowPopupWindow_MonsterRecord_ItemInfo_etcsub_416D62(0);
3514 return DefWindowProcA(hWnd, Msg, wParam, lParam);
3515
3516 }
3517
3518 pArcomageGame->stru1.field_0 = 8; 3473 pArcomageGame->stru1.field_0 = 8;
3519 ArcomageGame::OnMouseClick(1, 1); 3474 ArcomageGame::OnMouseClick(1, true);
3520 return DefWindowProcA(hWnd, Msg, wParam, lParam); 3475 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
3521 case WM_LBUTTONUP: 3476 }
3522 if ( !pArcomageGame->bGameInProgress ) 3477
3523 //goto LABEL_218; 3478 if (pVideoPlayer->pVideoFrame.pPixels)
3524 { 3479 pVideoPlayer->bStopBeforeSchedule = 1;
3525 back_to_game(); 3480
3526 return DefWindowProcA(hWnd, Msg, wParam, lParam); 3481 pMouse->SetMouseClick(LOWORD(lParam), HIWORD(lParam));
3527 } 3482
3528 pArcomageGame->stru1.field_0 = 3; 3483 if (pGame)
3529 ArcomageGame::OnMouseClick(0, 0); 3484 {
3530 return DefWindowProcA(hWnd, Msg, wParam, lParam); 3485 pGame->PickMouse(pGame->pIndoorCameraD3D->GetPickDepth(), LOWORD(lParam), HIWORD(lParam), 0, &vis_sprite_filter_2, &vis_door_filter);
3531 case WM_RBUTTONUP: 3486 }
3532 if ( !pArcomageGame->bGameInProgress ) 3487
3533 { 3488 sub_416D62_ShowPopupWindow_MonsterRecord_ItemInfo_etcsub_416D62(0);
3534 //LABEL_218: 3489 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
3535 3490
3536 back_to_game(); 3491
3537 return DefWindowProcA(hWnd, Msg, wParam, lParam); 3492 case WM_LBUTTONUP:
3538 } 3493 if ( !pArcomageGame->bGameInProgress )
3539 pArcomageGame->stru1.field_0 = 4; 3494 {
3540 ArcomageGame::OnMouseClick(1, false); 3495 back_to_game();
3541 return DefWindowProcA(hWnd, Msg, wParam, lParam); 3496 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
3542 3497 }
3543 case WM_LBUTTONDBLCLK: 3498 pArcomageGame->stru1.field_0 = 3;
3544 if ( pArcomageGame->bGameInProgress ) 3499 ArcomageGame::OnMouseClick(0, 0);
3545 { 3500 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
3546 pArcomageGame->stru1.field_0 = 7; 3501 case WM_RBUTTONUP:
3547 return DefWindowProcA(hWnd, Msg, wParam, lParam); 3502 if ( !pArcomageGame->bGameInProgress )
3548 } 3503 {
3504 back_to_game();
3505 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
3506 }
3507 pArcomageGame->stru1.field_0 = 4;
3508 ArcomageGame::OnMouseClick(1, false);
3509 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
3510
3511 case WM_LBUTTONDBLCLK:
3512 if ( pArcomageGame->bGameInProgress )
3513 {
3514 pArcomageGame->stru1.field_0 = 7;
3515 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
3516 }
3549 3517
3550 __handle_mouse_click: 3518 __handle_mouse_click:
3519 if (pVideoPlayer->pVideoFrame.pPixels)
3520 pVideoPlayer->bStopBeforeSchedule = 1;
3521
3522 pMouse->SetMouseClick(LOWORD(lParam), HIWORD(lParam));
3523
3524 if (GetCurrentMenuID() == MENU_CREATEPARTY)
3525 {
3526 UI_OnKeyDown(VK_SELECT);
3527 }
3528
3529 if (pGame)
3530 pGame->PickMouse(512.0, LOWORD(lParam), HIWORD(lParam), false, &vis_sprite_filter_3, &vis_door_filter);
3531
3532 UI_OnMouseLeftClick(0);
3533
3534 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
3535
3536 case WM_RBUTTONDBLCLK:
3537 if ( !pArcomageGame->bGameInProgress )
3538 {
3539 if (pVideoPlayer->pVideoFrame.pPixels)
3540 pVideoPlayer->bStopBeforeSchedule = 1;
3541
3542 pMouse->SetMouseClick(LOWORD(lParam), HIWORD(lParam));
3543
3544 if (pGame)
3545 {
3546 pGame->PickMouse(pGame->pIndoorCameraD3D->GetPickDepth(), LOWORD(lParam), HIWORD(lParam), false, &vis_sprite_filter_2, &vis_door_filter);
3547 }
3548
3549 sub_416D62_ShowPopupWindow_MonsterRecord_ItemInfo_etcsub_416D62(0);
3550 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
3551 }
3552
3553 pArcomageGame->stru1.field_0 = 8;
3554
3555 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
3556
3557 case WM_MBUTTONDOWN:
3558 if (pRenderer->pRenderD3D && pGame)
3559 {
3560 pGame->PickMouse(pGame->pIndoorCameraD3D->GetPickDepth(), LOWORD(lParam), HIWORD(lParam), 1, &vis_sprite_filter_3, &vis_face_filter);
3561 }
3562
3563 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
3564
3565 case WM_MOUSEMOVE:
3566 if ( pArcomageGame->bGameInProgress )
3567 {
3568 ArcomageGame::OnMouseMove(LOWORD(lParam), HIWORD(lParam));
3569 ArcomageGame::OnMouseClick(0, wParam == MK_LBUTTON);
3570 ArcomageGame::OnMouseClick(1, wParam == MK_RBUTTON);
3571 }
3572 else
3573 {
3574 pMouse->SetMouseClick(LOWORD(lParam), HIWORD(lParam));
3575 }
3576
3577 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
3578
3579 case WM_SYSCOMMAND:
3580 if ( wParam == SC_SCREENSAVE || wParam == SC_MONITORPOWER )
3581 return 0;
3582
3583 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
3584
3585 case WM_KEYUP:
3586 if (wParam == VK_CONTROL)
3587 {
3588 dword_507B98_ctrl_pressed = 0;
3589 }
3590
3591 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
3592
3593 case WM_KEYDOWN:
3594 if ( uGameMenuUI_CurentlySelectedKeyIdx != -1 )
3595 {
3596 pKeyActionMap->_459F10(wParam);
3597 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
3598 }
3599 if ( !pArcomageGame->bGameInProgress )
3600 {
3551 if ( pVideoPlayer->pVideoFrame.pPixels ) 3601 if ( pVideoPlayer->pVideoFrame.pPixels )
3552 pVideoPlayer->bStopBeforeSchedule = 1; 3602 pVideoPlayer->bStopBeforeSchedule = 1;
3553 3603 if ( wParam == VK_RETURN )
3554 pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
3555
3556 if (GetCurrentMenuID() != MENU_CREATEPARTY)
3557 pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
3558 else
3559 {
3560 UI_OnKeyDown(VK_SELECT);
3561 pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
3562 }
3563
3564
3565 if (pGame)
3566 pGame->PickMouse(512.0, (unsigned __int16)lParam, lParam >> 16, false, &vis_sprite_filter_3, &vis_door_filter);
3567
3568 UI_OnMouseLeftClick(0);
3569
3570 return DefWindowProcA(hWnd, Msg, wParam, lParam);
3571
3572 case WM_RBUTTONDBLCLK:
3573 v31 = 0;
3574 if ( !pArcomageGame->bGameInProgress )
3575 {
3576 //LABEL_240:
3577 if ( pVideoPlayer->pVideoFrame.pPixels != (unsigned __int16 *)v31 )
3578 pVideoPlayer->bStopBeforeSchedule = 1;
3579
3580 pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
3581 if (pGame)
3582 {
3583 v33 = pGame->pIndoorCameraD3D->GetPickDepth();
3584 pGame->PickMouse(v33, (unsigned __int16)lParam, lParam >> 16, v31, &vis_sprite_filter_2, &vis_door_filter);
3585 }
3586
3587 sub_416D62_ShowPopupWindow_MonsterRecord_ItemInfo_etcsub_416D62(0);
3588 return DefWindowProcA(hWnd, Msg, wParam, lParam);
3589
3590 }
3591 pArcomageGame->stru1.field_0 = 8;
3592 return DefWindowProcA(hWnd, Msg, wParam, lParam);
3593 case WM_MBUTTONDOWN:
3594 if ( pRenderer->pRenderD3D )
3595 {
3596 if ( pGame )
3597 {
3598 v34 = pGame->pIndoorCameraD3D->GetPickDepth();
3599 pGame->PickMouse(v34, (unsigned __int16)lParam, lParam >> 16, 1, &vis_sprite_filter_3, &vis_face_filter);
3600 return DefWindowProcA(hWnd, Msg, wParam, lParam);
3601 }
3602 }
3603 if ( !pGame )
3604 //goto _def_wnd_proc;
3605 return DefWindowProcA(hWnd, Msg, wParam, lParam);
3606 return DefWindowProcA(hWnd, Msg, wParam, lParam);
3607 case WM_MOUSEMOVE:
3608 if ( pArcomageGame->bGameInProgress )
3609 {
3610 pXY[0] = (unsigned __int16)lParam;
3611 pXY[1] = lParam >> 16;
3612 ArcomageGame::OnMouseMove((POINT *)pXY);
3613 ArcomageGame::OnMouseClick(0, wParam & 1);
3614 v29 = (wParam >> 1) & 1;
3615 ArcomageGame::OnMouseClick(1, v29 != 0);
3616 }
3617 else
3618 {
3619 pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
3620 }
3621 return DefWindowProcA(hWnd, Msg, wParam, lParam);
3622 default:
3623 //goto _def_wnd_proc;
3624 return DefWindowProcA(hWnd, Msg, wParam, lParam);
3625 }
3626 }
3627 if ( Msg == WM_SYSCOMMAND )
3628 {
3629 if ( wParam == SC_SCREENSAVE || wParam == SC_MONITORPOWER )
3630 return 0;
3631 //goto _def_wnd_proc;
3632 return DefWindowProcA(hWnd, Msg, wParam, lParam);
3633 }
3634 if ( Msg > WM_ACTIVATEAPP )
3635 {
3636 if ( Msg != WM_KEYFIRST && Msg != WM_WINDOWPOSCHANGED)
3637 {
3638 if ( Msg == WM_KEYUP && wParam == VK_CONTROL )
3639 {
3640 dword_507B98_ctrl_pressed = 0;
3641 }
3642 return DefWindowProcA(hWnd, Msg, wParam, lParam);
3643 }
3644 if ( uGameMenuUI_CurentlySelectedKeyIdx != -1 )
3645 {
3646 pKeyActionMap->_459F10(wParam);
3647 return DefWindowProcA(hWnd, Msg, wParam, lParam);
3648 }
3649 if ( !pArcomageGame->bGameInProgress )
3650 {
3651 if ( pVideoPlayer->pVideoFrame.pPixels )
3652 pVideoPlayer->bStopBeforeSchedule = 1;
3653 if ( wParam == VK_RETURN )
3654 {
3655 if ( !viewparams->field_4C )
3656 UI_OnKeyDown(wParam);
3657 return 0;
3658 }
3659 if ( wParam == VK_CONTROL )
3660 {
3661 dword_507B98_ctrl_pressed = 1;
3662 return 0;
3663 }
3664 if ( wParam == VK_ESCAPE )
3665 {
3666 pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, window_SpeakInHouse != 0, 0);
3667 return 0;
3668 }
3669 if ( wParam <= VK_HOME )
3670 return 0;
3671 if ( wParam > VK_DOWN )
3672 {
3673 if ( wParam != VK_F4 || pVideoPlayer->AnyMovieLoaded() )
3674 return 0;
3675 SendMessageA(hWnd, WM_COMMAND, 104, 0);
3676 return 0;
3677 }
3678 if ( wParam >= VK_LEFT && wParam <= VK_DOWN )
3679 {
3680 if ( pCurrentScreen != SCREEN_GAME && pCurrentScreen != SCREEN_MODAL_WINDOW )
3681 { 3604 {
3682 if ( !viewparams->field_4C ) 3605 if ( !viewparams->field_4C )
3683 UI_OnKeyDown(wParam); 3606 UI_OnKeyDown(wParam);
3684 return 0; 3607 return 0;
3685 } 3608 }
3686 } 3609 if ( wParam == VK_CONTROL )
3687 if ( pCurrentScreen != SCREEN_GAME && pCurrentScreen != SCREEN_MODAL_WINDOW ) 3610 {
3688 return 0; 3611 dword_507B98_ctrl_pressed = 1;
3689 } 3612 return 0;
3690 3613 }
3691 pArcomageGame->stru1.field_0 = 1; 3614 if ( wParam == VK_ESCAPE )
3692 3615 {
3693 v13 = (unsigned __int16)MapVirtualKeyA((unsigned __int16)wParam, 2u); 3616 pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, window_SpeakInHouse != 0, 0);
3694 set_stru1_field_8_InArcomage(v13); 3617 return 0;
3695 if ( wParam == 27 ) 3618 }
3696 { 3619 if ( wParam <= VK_HOME )
3697 pArcomageGame->GameOver = 1; 3620 return 0;
3698 pArcomageGame->field_F4 = 1; 3621 if ( wParam > VK_DOWN )
3699 pArcomageGame->uGameResult = 2; 3622 {
3700 pArcomageGame->field_B0 = -2; 3623 if ( wParam != VK_F4 || pVideoPlayer->AnyMovieLoaded() )
3701 return DefWindowProcA(hWnd, Msg, wParam, lParam); 3624 return 0;
3702 } 3625 SendMessageW(hWnd, WM_COMMAND, 104, 0);
3703 if ( wParam != 114 ) 3626 return 0;
3704 { 3627 }
3705 if ( wParam == 115 && !pVideoPlayer->AnyMovieLoaded() ) 3628 if ( wParam >= VK_LEFT && wParam <= VK_DOWN )
3706 SendMessageA(hWnd, 0x111u, 0x68u, 0); 3629 {
3707 return DefWindowProcA(hWnd, Msg, wParam, lParam); 3630 if ( pCurrentScreen != SCREEN_GAME && pCurrentScreen != SCREEN_MODAL_WINDOW )
3708 } 3631 {
3709 SendMessageA(hWnd, WM_COMMAND, 103, 0); 3632 if ( !viewparams->field_4C )
3710 return 0; 3633 UI_OnKeyDown(wParam);
3711 } 3634 return 0;
3712 if ( Msg == WM_ACTIVATEAPP ) 3635 }
3713 { 3636 }
3714 if ( wParam && (GetForegroundWindow() == hWnd || GetForegroundWindow() == hInsertCDWindow) ) 3637 if ( pCurrentScreen != SCREEN_GAME && pCurrentScreen != SCREEN_MODAL_WINDOW )
3715 { 3638 return 0;
3716 if ( BYTE1(dword_6BE364_game_settings_1) & 1 ) 3639 }
3717 { 3640
3718 dword_4E98BC_bApplicationActive = 1; 3641 pArcomageGame->stru1.field_0 = 1;
3719 if ( pRenderer->bWindowMode ) 3642
3720 { 3643 set_stru1_field_8_InArcomage(MapVirtualKey(wParam, MAPVK_VK_TO_CHAR));
3721 v10 = GetDC(0); 3644 if ( wParam == 27 )
3722 a2 = GetDeviceCaps(v10, BITSPIXEL); 3645 {
3723 v11 = GetDeviceCaps(v10, PLANES); 3646 pArcomageGame->GameOver = 1;
3724 ReleaseDC(0, v10); 3647 pArcomageGame->field_F4 = 1;
3725 if ( a2 != 16 || v11 != 1 ) 3648 pArcomageGame->uGameResult = 2;
3726 Abortf(pGlobalTXT_LocalizationStrings[62]); 3649 pArcomageGame->field_B0 = -2;
3727 } 3650 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
3728 BYTE1(dword_6BE364_game_settings_1) &= 0xFEu; 3651 }
3729 3652 if ( wParam != 114 )
3730 if ( pArcomageGame->bGameInProgress ) 3653 {
3731 { 3654 if ( wParam == 115 && !pVideoPlayer->AnyMovieLoaded() )
3732 pArcomageGame->field_F9 = 1; 3655 SendMessage(hWnd, WM_COMMAND, 0x68u, 0);
3733 } 3656 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
3734 else 3657 }
3735 { 3658 SendMessageW(hWnd, WM_COMMAND, 103, 0);
3736 if ( BYTE1(dword_6BE364_game_settings_1) & 2 ) 3659 return 0;
3737 BYTE1(dword_6BE364_game_settings_1) &= 0xFDu; 3660
3661 case WM_ACTIVATEAPP:
3662 if ( wParam && (GetForegroundWindow() == hWnd || GetForegroundWindow() == hInsertCDWindow) )
3663 {
3664 if ( BYTE1(dword_6BE364_game_settings_1) & 1 )
3665 {
3666 dword_4E98BC_bApplicationActive = 1;
3667 if ( pRenderer->bWindowMode )
3668 {
3669 HDC hDC = GetDC(hWnd);
3670 int bitsPerPixel = GetDeviceCaps(hDC, BITSPIXEL);
3671 int planes = GetDeviceCaps(hDC, PLANES);
3672 ReleaseDC(hWnd, hDC);
3673 if (bitsPerPixel != 16 || planes != 1)
3674 Error(pGlobalTXT_LocalizationStrings[62]);
3675 }
3676 BYTE1(dword_6BE364_game_settings_1) &= 0xFEu;
3677
3678 if ( pArcomageGame->bGameInProgress )
3679 {
3680 pArcomageGame->field_F9 = 1;
3681 }
3738 else 3682 else
3739 pEventTimer->Resume(); 3683 {
3740 if ( BYTE1(dword_6BE364_game_settings_1) & 4 ) 3684 if ( BYTE1(dword_6BE364_game_settings_1) & 2 )
3741 BYTE1(dword_6BE364_game_settings_1) &= 0xFBu; 3685 BYTE1(dword_6BE364_game_settings_1) &= 0xFDu;
3686 else
3687 pEventTimer->Resume();
3688 if ( BYTE1(dword_6BE364_game_settings_1) & 4 )
3689 BYTE1(dword_6BE364_game_settings_1) &= 0xFBu;
3690 else
3691 pMiscTimer->Resume();
3692
3693 viewparams->bRedrawGameUI = true;
3694 if ( pVideoPlayer->pSmackerMovie )
3695 {
3696 pRenderer->RestoreFrontBuffer();
3697 pRenderer->_4A184C();
3698 pVideoPlayer->_4BF5B2();
3699 }
3700 }
3701 if ( pAudioPlayer->hAILRedbook && !bGameoverLoop && !pVideoPlayer->pSmackerMovie )
3702 AIL_redbook_resume(pAudioPlayer->hAILRedbook);
3703 }
3704 }
3705 else
3706 {
3707 if (!(dword_6BE364_game_settings_1 & 0x100))
3708 {
3709 dword_4E98BC_bApplicationActive = 0;
3710 if ( (pVideoPlayer->pSmackerMovie || pVideoPlayer->pBinkMovie) && pVideoPlayer->bPlayingMovie )
3711 pVideoPlayer->bStopBeforeSchedule = 1;
3712
3713 if ( pRenderer->bUserDirect3D && pRenderer->uAcquiredDirect3DDevice == 1 )
3714 SetWindowPos(hWnd, (HWND)0xFFFFFFFE, 0, 0, 0, 0, 0x18u);
3715 ClipCursor(0);
3716 dword_6BE364_game_settings_1 |= 0x100u;
3717 if ( pEventTimer->bPaused )
3718 BYTE1(dword_6BE364_game_settings_1) |= 2u;
3742 else 3719 else
3743 pMiscTimer->Resume(); 3720 pEventTimer->Pause();
3744 3721 if ( pMiscTimer->bPaused )
3745 viewparams->bRedrawGameUI = true; 3722 BYTE1(dword_6BE364_game_settings_1) |= 4u;
3746 if ( pVideoPlayer->pSmackerMovie ) 3723 else
3747 { 3724 pMiscTimer->Pause();
3748 pRenderer->RestoreFrontBuffer(); 3725
3749 pRenderer->_4A184C(); 3726 pAudioPlayer->StopChannels(-1, -1);
3750 pVideoPlayer->_4BF5B2(); 3727 if ( pAudioPlayer->hAILRedbook )
3751 } 3728 AIL_redbook_pause(pAudioPlayer->hAILRedbook);
3752 } 3729 }
3753 if ( pAudioPlayer->hAILRedbook && !bGameoverLoop && !pVideoPlayer->pSmackerMovie ) 3730 }
3754 AIL_redbook_resume(pAudioPlayer->hAILRedbook); 3731 return 0;
3755 } 3732
3756 } 3733 case WM_SETFOCUS:
3757 else
3758 {
3759 if ( !(dword_6BE364_game_settings_1 & 0x100) )
3760 {
3761 while(initing); //ADDED spinlock to allow int players ets! Gloval
3762 dword_4E98BC_bApplicationActive = 0;
3763 if ( (pVideoPlayer->pSmackerMovie || pVideoPlayer->pBinkMovie) && pVideoPlayer->bPlayingMovie )
3764 pVideoPlayer->bStopBeforeSchedule = 1;
3765
3766 if ( pRenderer->bUserDirect3D && pRenderer->uAcquiredDirect3DDevice == 1 )
3767 SetWindowPos(::hWnd, (HWND)0xFFFFFFFE, 0, 0, 0, 0, 0x18u);
3768 ClipCursor(0);
3769 dword_6BE364_game_settings_1 |= 0x100u;
3770 if ( pEventTimer->bPaused )
3771 BYTE1(dword_6BE364_game_settings_1) |= 2u;
3772 else
3773 pEventTimer->Pause();
3774 if ( pMiscTimer->bPaused )
3775 BYTE1(dword_6BE364_game_settings_1) |= 4u;
3776 else
3777 pMiscTimer->Pause();
3778
3779 pAudioPlayer->StopChannels(-1, -1);
3780 if ( pAudioPlayer->hAILRedbook )
3781 AIL_redbook_pause(pAudioPlayer->hAILRedbook);
3782 }
3783 }
3784 return 0;
3785 }
3786 if (Msg == WM_CREATE)
3787 {
3788 auto hDC = GetDC(hWnd);
3789 {
3790 if (GetDeviceCaps(hDC, BITSPIXEL) < 8)
3791 {
3792 ReleaseDC(hWnd, hDC);
3793 Log::Warning(L"You must be running in 256 color mode or higher.");
3794 Abortf("You must be running in 256 color mode or higher. You can change the screen depth with the control panel display icon.");
3795 }
3796 }
3797 ReleaseDC(hWnd, hDC);
3798 return 0;
3799 }
3800 if ( Msg == WM_DESTROY )
3801 {
3802 v6 = GetCurrentProcess();
3803 SetPriorityClass(v6, 0x20u);
3804 if ( pGame )
3805 {
3806
3807 }
3808
3809 PostQuitMessage(0);
3810 return 0;
3811 }
3812 if ( Msg == WM_SETFOCUS )
3813 {
3814 if ( ::hWnd == (HWND)wParam )
3815 {
3816 dword_4E98BC_bApplicationActive = 0; 3734 dword_4E98BC_bApplicationActive = 0;
3817 if ( pRenderer->bUserDirect3D && pRenderer->uAcquiredDirect3DDevice == 1 ) 3735 if ( pRenderer->bUserDirect3D && pRenderer->uAcquiredDirect3DDevice == 1 )
3818 SetWindowPos(::hWnd, (HWND)0xFFFFFFFE, 0, 0, 0, 0, 0x18u); 3736 SetWindowPos(hWnd, (HWND)0xFFFFFFFE, 0, 0, 0, 0, 0x18u);
3819 ClipCursor(0); 3737 ClipCursor(0);
3820 3738 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
3821 } 3739
3822 //_def_wnd_proc: 3740 case WM_KILLFOCUS:
3823 return DefWindowProcA(hWnd, Msg, wParam, lParam); 3741 dword_4E98BC_bApplicationActive = 1;
3824 } 3742 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
3825 if ( Msg != WM_KILLFOCUS ) 3743
3826 { 3744 case WM_PAINT:
3827 if ( Msg == WM_PAINT )
3828 {
3829 if ( !GetUpdateRect(hWnd, 0, 0) || !dword_4E98BC_bApplicationActive && !pRenderer->bWindowMode ) 3745 if ( !GetUpdateRect(hWnd, 0, 0) || !dword_4E98BC_bApplicationActive && !pRenderer->bWindowMode )
3830 return 0; 3746 return 0;
3747 PAINTSTRUCT Paint;
3831 BeginPaint(hWnd, &Paint); 3748 BeginPaint(hWnd, &Paint);
3832 if ( pArcomageGame->bGameInProgress ) 3749 if ( pArcomageGame->bGameInProgress )
3833 { 3750 {
3834 pArcomageGame->field_F9 = 1; 3751 pArcomageGame->field_F9 = 1;
3835 } 3752 }
3842 } 3759 }
3843 } 3760 }
3844 pRenderer->Present(); 3761 pRenderer->Present();
3845 EndPaint(hWnd, &Paint); 3762 EndPaint(hWnd, &Paint);
3846 return 0; 3763 return 0;
3847 } 3764
3848 //goto _def_wnd_proc; 3765 default:
3849 return DefWindowProcA(hWnd, Msg, wParam, lParam); 3766 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
3850 } 3767 }
3851 if ( ::hWnd != (HWND)wParam || (dword_4E98BC_bApplicationActive = 1, pRenderer->bWindowMode) || true )
3852 return DefWindowProcA(hWnd, Msg, wParam, lParam);
3853
3854 } 3768 }
3855 3769
3856 //----- (00464479) -------------------------------------------------------- 3770 //----- (00464479) --------------------------------------------------------
3857 void ResetCursor_Palettes_LODs_Level_Audio_SFT_Windows() 3771 void ResetCursor_Palettes_LODs_Level_Audio_SFT_Windows()
3858 { 3772 {
3978 3892
3979 for (uint i = 0; i < 1000; ++i) 3893 for (uint i = 0; i < 1000; ++i)
3980 pSpriteObjects[i].uObjectDescID = 0; 3894 pSpriteObjects[i].uObjectDescID = 0;
3981 3895
3982 v5 = pMapStats->GetMapInfo(pCurrentMapName); 3896 v5 = pMapStats->GetMapInfo(pCurrentMapName);
3983 bUnderwater = 0; 3897 bUnderwater = false;
3984 uLevelMapStatsID = v5; 3898 uLevelMapStatsID = v5;
3985 pGame->uFlags2 &= 0xFFFFFFF7u; 3899 pGame->uFlags2 &= 0xFFFFFFF7u;
3986 if ( !_stricmp(pCurrentMapName, "out15.odm") ) 3900 if ( !_stricmp(pCurrentMapName, "out15.odm") )
3987 { 3901 {
3988 bUnderwater = 1; 3902 bUnderwater = true;
3989 pGame->uFlags2 |= 8u; 3903 pGame->uFlags2 |= 8u;
3990 } 3904 }
3991 pParty->floor_face_pid = 0; 3905 pParty->floor_face_pid = 0;
3992 if ( _stricmp(Str1, "blv") ) 3906 if ( _stricmp(Str1, "blv") )
3993 PrepareToLoadODM(v9, 0); 3907 PrepareToLoadODM(v9, 0);
4382 } 4296 }
4383 4297
4384 //----- (004651F4) -------------------------------------------------------- 4298 //----- (004651F4) --------------------------------------------------------
4385 bool MM7_Initialize() 4299 bool MM7_Initialize()
4386 { 4300 {
4387 initing=true; //ADDED Gloval
4388 wchar_t pCurrentDir[1024]; 4301 wchar_t pCurrentDir[1024];
4389 _wgetcwd(pCurrentDir, 1024); 4302 _wgetcwd(pCurrentDir, 1024);
4390 4303
4391 wchar_t pMM6IniFile[1024]; 4304 wchar_t pMM6IniFile[1024];
4392 wsprintfW(pMM6IniFile, L"%s\\mm6.ini", pCurrentDir); 4305 wsprintfW(pMM6IniFile, L"%s\\mm6.ini", pCurrentDir);
4424 } 4337 }
4425 4338
4426 auto hDesktopDC = GetDC(nullptr); 4339 auto hDesktopDC = GetDC(nullptr);
4427 uint uDesktopWidth = GetDeviceCaps(hDesktopDC, HORZRES); 4340 uint uDesktopWidth = GetDeviceCaps(hDesktopDC, HORZRES);
4428 uint uDesktopHeight = GetDeviceCaps(hDesktopDC, VERTRES); 4341 uint uDesktopHeight = GetDeviceCaps(hDesktopDC, VERTRES);
4429
4430 if (GetDeviceCaps(hDesktopDC, BITSPIXEL) != 16 ||
4431 GetDeviceCaps(hDesktopDC, PLANES) != 1 )
4432 dword_6BE364_game_settings_1 |= 2;
4433
4434 ReleaseDC(nullptr, hDesktopDC); 4342 ReleaseDC(nullptr, hDesktopDC);
4435 4343
4436 uint uTotalWinWidth = 2 * GetSystemMetrics(SM_CXFRAME) + 640; 4344 uint uTotalWinWidth = 2 * GetSystemMetrics(SM_CXFRAME) + 640;
4437 uint uTotalWinHeight = GetSystemMetrics(SM_CYCAPTION) + 2 * GetSystemMetrics(SM_CYFRAME) + 480; 4345 uint uTotalWinHeight = GetSystemMetrics(SM_CYCAPTION) + 2 * GetSystemMetrics(SM_CYFRAME) + 480;
4438 4346
4450 hWnd = CreateWindowExW(0, wcxw.lpszClassName, L"Might and Magic VII", 4358 hWnd = CreateWindowExW(0, wcxw.lpszClassName, L"Might and Magic VII",
4451 uWindowStyle = WS_SYSMENU | WS_GROUP | WS_DLGFRAME | WS_BORDER, 4359 uWindowStyle = WS_SYSMENU | WS_GROUP | WS_DLGFRAME | WS_BORDER,
4452 uWindowX, uWindowY, 4360 uWindowX, uWindowY,
4453 640, 480, 4361 640, 480,
4454 nullptr, 4362 nullptr,
4455 hOSMenu = nullptr, 4363 nullptr,
4456 wcxw.hInstance, 4364 wcxw.hInstance,
4457 nullptr); 4365 nullptr);
4458 SetWindowTextW(hWnd, L"Might and Magic VII");
4459 4366
4460 HMENU menu = CreateMenu(); 4367 HMENU menu = CreateMenu();
4461 { 4368 {
4462 HMENU file = CreatePopupMenu(); 4369 HMENU file = CreatePopupMenu();
4463 AppendMenuW(menu, MF_ENABLED | MF_STRING | MF_POPUP, (UINT_PTR)file, L"&File"); 4370 AppendMenuW(menu, MF_ENABLED | MF_STRING | MF_POPUP, (UINT_PTR)file, L"&File");
4662 uWindowWidth = rcClient.left - rcClient.right - rcWindow.left + rcWindow.right + 640; 4569 uWindowWidth = rcClient.left - rcClient.right - rcWindow.left + rcWindow.right + 640;
4663 uWindowHeight = rcClient.top - rcClient.bottom - rcWindow.top + rcWindow.bottom + 480; 4570 uWindowHeight = rcClient.top - rcClient.bottom - rcWindow.top + rcWindow.bottom + 480;
4664 MoveWindow(hWnd, uWindowX, uWindowY, 4571 MoveWindow(hWnd, uWindowX, uWindowY,
4665 rcClient.left - rcClient.right - rcWindow.left + rcWindow.right + 640, 4572 rcClient.left - rcClient.right - rcWindow.left + rcWindow.right + 640,
4666 rcClient.top - rcClient.bottom - rcWindow.top + rcWindow.bottom + 480, 0); 4573 rcClient.top - rcClient.bottom - rcWindow.top + rcWindow.bottom + 480, 0);
4667 ShowWindow(hWnd, SW_SHOWNORMAL);
4668 4574
4669 pIcons_LOD = new LODFile_IconsBitmaps; 4575 pIcons_LOD = new LODFile_IconsBitmaps;
4670 if (!pIcons_LOD->Load("data\\icons.lod", "icons")) 4576 if (!pIcons_LOD->Load("data\\icons.lod", "icons"))
4671 { 4577 {
4672 MessageBoxW(nullptr, 4578 MessageBoxW(nullptr,
4715 pGlobalTXT_LocalizationStrings[184], MB_ICONEXCLAMATION); 4621 pGlobalTXT_LocalizationStrings[184], MB_ICONEXCLAMATION);
4716 return false; 4622 return false;
4717 } 4623 }
4718 4624
4719 4625
4720 4626 #if 0
4721 if (_access("../MM_VI/data/icons.lod", 0) == 0) 4627 if (_access("../MM_VI/data/icons.lod", 0) == 0)
4722 { 4628 {
4723 pIcons_LOD_mm6 = new LODFile_IconsBitmaps; 4629 pIcons_LOD_mm6 = new LODFile_IconsBitmaps;
4724 if (!pIcons_LOD_mm6->Load("../MM_VI/data/icons.lod", "icons")) 4630 if (!pIcons_LOD_mm6->Load("../MM_VI/data/icons.lod", "icons"))
4725 { 4631 {
4758 } 4664 }
4759 else 4665 else
4760 Log::Warning(L"Unable to find mm6:sprites.lod"); 4666 Log::Warning(L"Unable to find mm6:sprites.lod");
4761 4667
4762 4668
4763 4669 if (_access("../mm8/data/icons.lod", 0) == 0)
4764 if (bDebugResouces) 4670 {
4765 { 4671 pIcons_LOD_mm8 = new LODFile_IconsBitmaps;
4766 pSpriteFrameTable = new SpriteFrameTable; 4672 if (!pIcons_LOD_mm8->Load("../mm8/data/icons.lod", "icons"))
4767 if (!pSpriteFrameTable->FromFileTxt("data\\sft.txt")) 4673 {
4768 Abortf("Unable to open sft.txt"); 4674 delete pIcons_LOD_mm8;
4769 4675 pIcons_LOD_mm8 = nullptr;
4770 pDecorationList = new DecorationList; 4676 Log::Warning(L"Unable to load mm8:icons.lod");
4771 if (!pDecorationList->FromFileTxt("data\\declist.txt")) 4677 }
4772 Abortf("Unable to open declist.txt");
4773
4774 pObjectList = new ObjectList;
4775 if (!pObjectList->FromFileTxt("data\\objlist.txt"))
4776 Abortf("Unable to open objlist.txt");
4777
4778 pMonsterList = new MonsterList;
4779 if (!pMonsterList->FromFileTxt("data\\monlist.txt"))
4780 Abortf("Unable to open monlist.txt");
4781
4782 pIconsFrameTable = new IconFrameTable;
4783 if (!pIconsFrameTable->FromFileTxt("data\\ift.txt"))
4784 Abortf("Unable to open ift.txt");
4785
4786 pTextureFrameTable = new TextureFrameTable;
4787 if (!pTextureFrameTable->FromFileTxt("data\\tft.def"))
4788 Abortf("Unable to open tft.def");
4789
4790 pTileTable = new TileTable;
4791 if (!pTileTable->FromFileTxt("data\\tile.def"))
4792 Abortf("Unable to open tile.def");
4793
4794 pPlayerFrameTable = new PlayerFrameTable;
4795 if (!pPlayerFrameTable->FromFileTxt("data\\pft.def"))
4796 Abortf("Unable to open pft.def");
4797
4798 pChestList = new ChestList;
4799 if (!pChestList->FromFileTxt("data\\chest.def"))
4800 Abortf("Unable to open chest.def");
4801
4802 pOverlayList = new OverlayList;
4803 if (!pOverlayList->FromFileTxt("data\\overlay.def"))
4804 Abortf("Unable to open overlay.def");
4805
4806 pSoundList = new SoundList;
4807 if (!pSoundList->FromFileTxt("data\\sounds.def"))
4808 Abortf("Unable to open sounds.def");
4809 } 4678 }
4810 else 4679 else
4680 Log::Warning(L"Unable to find mm8:icons.lod");
4681
4682
4683 if (_access("../mm8/data/bitmaps.lod", 0) == 0)
4684 {
4685 pBitmaps_LOD_mm8 = new LODFile_IconsBitmaps;
4686 if (!pBitmaps_LOD_mm8->Load("../mm8/data/bitmaps.lod", "bitmaps"))
4687 {
4688 delete pBitmaps_LOD_mm8;
4689 pBitmaps_LOD_mm8 = nullptr;
4690 Log::Warning(L"Unable to load mm8:bitmaps.lod");
4691 }
4692 }
4693 else
4694 Log::Warning(L"Unable to find mm8:bitmaps.lod");
4695
4696
4697 if (_access("../mm8/data/sprites.lod", 0) == 0)
4698 {
4699 pSprites_LOD_mm8 = new LODFile_Sprites;
4700 if (!pSprites_LOD_mm8->LoadSprites("../mm8/data/sprites.lod"))
4701 {
4702 delete pSprites_LOD_mm8;
4703 pSprites_LOD_mm8 = nullptr;
4704 Log::Warning(L"Unable to load mm8:sprites.lod");
4705 }
4706 }
4707 else
4708 Log::Warning(L"Unable to find mm8:sprites.lod");
4709 #endif
4710
4811 { 4711 {
4812 void *sft_mm6 = pIcons_LOD_mm6 ? pIcons_LOD_mm6->LoadRaw("dsft.bin", 1) : nullptr, 4712 void *sft_mm6 = pIcons_LOD_mm6 ? pIcons_LOD_mm6->LoadRaw("dsft.bin", 1) : nullptr,
4813 *sft_mm8 = nullptr; 4713 *sft_mm8 = nullptr;
4814 auto sft_mm7 = pEvents_LOD->LoadRaw("dsft.bin", 1); 4714 auto sft_mm7 = pEvents_LOD->LoadRaw("dsft.bin", 1);
4815 pSpriteFrameTable = new SpriteFrameTable; 4715 pSpriteFrameTable = new SpriteFrameTable;
4908 free(sounds_mm7); 4808 free(sounds_mm7);
4909 free(sounds_mm8); 4809 free(sounds_mm8);
4910 } 4810 }
4911 4811
4912 4812
4913 if (bDebugResouces)
4914 {
4915 pSpriteFrameTable->ToFile();
4916 pDecorationList->ToFile();
4917 pObjectList->ToFile();
4918 pMonsterList->ToFile();
4919 pIconsFrameTable->ToFile();
4920 pTextureFrameTable->ToFile();
4921 pTileTable->ToFile();
4922 pPlayerFrameTable->ToFile();
4923 pChestList->ToFile();
4924 pOverlayList->ToFile();
4925 pSoundList->ToFile();
4926 }
4927 4813
4928 4814
4929 if (dword_6BE364_game_settings_1 & 2 || !(dword_6BE368_debug_settings_2 & 1))// 4815 if (dword_6BE364_game_settings_1 & 2 || !(dword_6BE368_debug_settings_2 & 1))//
4930 // color depth != 16 4816 // color depth != 16
4931 // or 4817 // or
4997 case 3u: // smooth 4883 case 3u: // smooth
4998 uTurnSpeed = 0; 4884 uTurnSpeed = 0;
4999 break; 4885 break;
5000 } 4886 }
5001 4887
5002 initing = false; //ADDED Gloval 4888 ShowWindow(hWnd, SW_SHOWNORMAL);
5003 return true; 4889 return true;
5004 } 4890 }
5005 4891
5006 //----- (00465D0B) -------------------------------------------------------- 4892 //----- (00465D0B) --------------------------------------------------------
5007 void SecondaryInitialization() 4893 void SecondaryInitialization()
5180 assert(sizeof(StationaryLight) == 0xC); 5066 assert(sizeof(StationaryLight) == 0xC);
5181 assert(sizeof(LightsStack_StationaryLight_) == 0x12C8); 5067 assert(sizeof(LightsStack_StationaryLight_) == 0x12C8);
5182 assert(sizeof(MobileLight) == 0x12); 5068 assert(sizeof(MobileLight) == 0x12);
5183 assert(sizeof(LightsStack_MobileLight_) == 0x1C28); 5069 assert(sizeof(LightsStack_MobileLight_) == 0x1C28);
5184 assert(sizeof(Game) == 0xE78); 5070 assert(sizeof(Game) == 0xE78);
5185 assert(sizeof(stru141) == 0xA8); 5071 assert(sizeof(stru141_actor_collision_object) == 0xA8);
5186 assert(sizeof(ActionQueue) == 0x7C); 5072 assert(sizeof(ActionQueue) == 0x7C);
5187 assert(sizeof(NPCData) == 0x4C); 5073 assert(sizeof(NPCData) == 0x4C);
5188 assert(sizeof(NPCStats) == 0x17FFC); 5074 assert(sizeof(NPCStats) == 0x17FFC);
5189 assert(sizeof(BspRenderer) == 0x53740); 5075 assert(sizeof(BspRenderer) == 0x53740);
5190 assert(sizeof(PaletteManager) == 0x267AF0); 5076 assert(sizeof(PaletteManager) == 0x267AF0);
5246 bool draw_debug_line = false; 5132 bool draw_debug_line = false;
5247 5133
5248 //----- (00462C94) -------------------------------------------------------- 5134 //----- (00462C94) --------------------------------------------------------
5249 bool MM_Main(const wchar_t *pCmdLine) 5135 bool MM_Main(const wchar_t *pCmdLine)
5250 { 5136 {
5251 HWND hPrevWnd; // eax@1
5252 HWND hPrevWnd_; // esi@1
5253 HWND v6; // eax@4
5254 int v8; // eax@15
5255 //bool v9; // edx@16
5256 //OtherOverlay *v10; // esi@44
5257 //signed int v11; // edi@44
5258 //unsigned int v12; // ecx@56
5259 HANDLE v13; // eax@68
5260 unsigned int startms; // [sp+8h] [bp-24h]@55
5261 RECT Rect; // [sp+Ch] [bp-20h]@15
5262 int a2[4]; // [sp+1Ch] [bp-10h]@15
5263
5264 IntegrityTest(); 5137 IntegrityTest();
5265 char test[1024]; 5138 char test[1024];
5266 sprintfex(test, "^Pi[%s]: ^R[;;]", ""); 5139 sprintfex(test, "^Pi[%s]: ^R[;;]", "");
5267 5140
5268 bool bNoMargareth = false; 5141 bool bNoMargareth = false;
5310 { 5183 {
5311 Log::Warning(L"MM init: failed"); 5184 Log::Warning(L"MM init: failed");
5312 pGame->Deinitialize(); 5185 pGame->Deinitialize();
5313 return 1; 5186 return 1;
5314 } 5187 }
5315 Log::Warning(L"MM init: ok");
5316 5188
5317 pEventTimer->Pause(); 5189 pEventTimer->Pause();
5318 5190
5319 SetUserInterface(PartyAlignment_Neutral, false); 5191 SetUserInterface(PartyAlignment_Neutral, false);
5320 ShowIntroVideo_and_LoadingScreen(); 5192 ShowIntroVideo_and_LoadingScreen();
5321 WriteWindowsRegistryInt("Ran once", 1); 5193 WriteWindowsRegistryInt("Ran once", 1);
5322 dword_6BE364_game_settings_1 |= 0x4000; 5194 dword_6BE364_game_settings_1 |= 0x4000;
5323 pGame->InitializeGammaController(); 5195 pGame->InitializeGammaController();
5324 SecondaryInitialization(); 5196 SecondaryInitialization();
5325 pRenderer->SetRasterClipRect(0, 0, 639u, 479u); 5197 pRenderer->SetRasterClipRect(0, 0, 639, 479);
5326 FinalInitialization(); 5198 FinalInitialization();
5327 5199
5328 Log::Warning(L"MM: entering main loop"); 5200 Log::Warning(L"MM: entering main loop");
5329 while ( 1 ) 5201 while ( 1 )
5330 { 5202 {
5393 { 5265 {
5394 pMouse->Activate(0); 5266 pMouse->Activate(0);
5395 5267
5396 pParty->Reset(); 5268 pParty->Reset();
5397 pParty->CreateDefaultParty(1); 5269 pParty->CreateDefaultParty(1);
5398 5270
5399 extern void CreateDefaultBLVLevel(); 5271 __debugbreak();
5272 /*extern void CreateDefaultBLVLevel();
5400 CreateDefaultBLVLevel(); 5273 CreateDefaultBLVLevel();
5401 5274
5402 extern OPENFILENAMEA ofn; 5275 OPENFILENAMEA ofn;
5403 if ( !GetOpenFileNameA((LPOPENFILENAMEA)&ofn) ) 5276 if ( !GetOpenFileNameA((LPOPENFILENAMEA)&ofn) )
5404 { 5277 {
5405 pMouse->Activate(1); 5278 pMouse->Activate(1);
5406 break; 5279 break;
5407 } 5280 }
5408 _chdir("..\\"); 5281 _chdir("..\\");
5409 strcpy(pCurrentMapName, ofn.lpstrFileTitle); 5282 strcpy(pCurrentMapName, ofn.lpstrFileTitle);*/
5410 pMouse->Activate(1); 5283 pMouse->Activate(1);
5411 pGame->Loop(); 5284 pGame->Loop();
5412 } 5285 }
5413 } 5286 }
5414 if ( uGameState == GAME_STATE_LOADING_GAME ) 5287 if ( uGameState == GAME_STATE_LOADING_GAME )
5432 } 5305 }
5433 if (!bNoSound && pAudioPlayer->hAILRedbook) 5306 if (!bNoSound && pAudioPlayer->hAILRedbook)
5434 { 5307 {
5435 pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f); 5308 pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f);
5436 AIL_redbook_stop(pAudioPlayer->hAILRedbook); 5309 AIL_redbook_stop(pAudioPlayer->hAILRedbook);
5437 unsigned int end_ms; 5310 unsigned int startms, end_ms;
5438 AIL_redbook_track_info(pAudioPlayer->hAILRedbook, 0xE, &startms, &end_ms); 5311 AIL_redbook_track_info(pAudioPlayer->hAILRedbook, 0xE, &startms, &end_ms);
5439 AIL_redbook_play(pAudioPlayer->hAILRedbook, startms + 1, end_ms); 5312 AIL_redbook_play(pAudioPlayer->hAILRedbook, startms + 1, end_ms);
5440 } 5313 }
5441 } 5314 }
5442 5315
5636 viewparams->uSomeW = viewparams->uScreen_BttmR_Y; 5509 viewparams->uSomeW = viewparams->uScreen_BttmR_Y;
5637 5510
5638 pViewport->SetScreen(viewparams->uScreen_topL_X, viewparams->uScreen_topL_Y, viewparams->uScreen_BttmR_X, viewparams->uScreen_BttmR_Y); 5511 pViewport->SetScreen(viewparams->uScreen_topL_X, viewparams->uScreen_topL_Y, viewparams->uScreen_BttmR_X, viewparams->uScreen_BttmR_Y);
5639 if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor ) 5512 if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
5640 pOutdoorCamera->_485F64(); 5513 pOutdoorCamera->_485F64();
5641 }
5642
5643 //----- (00466B8C) --------------------------------------------------------
5644 int AbortWithError()
5645 {
5646 if ( !aborting_app )
5647 {
5648 ClipCursor(0);
5649 aborting_app = 1;
5650 if ( !pRenderer->bWindowMode )
5651 pRenderer->ChangeBetweenWinFullscreenModes();
5652 if ( MessageBoxA(0, pGlobalTXT_LocalizationStrings[176], pGlobalTXT_LocalizationStrings[59], 0x34u) == 6 )
5653 SaveGame(1, 0); // "Internal Error"
5654 // "Might and Magic VII has detected an internal error and will be forced to close. Would you like us to autosave your game before closing?"
5655 Game_DeinitializeAndTerminate(1);
5656 }
5657 return 0;
5658 }
5659 // 720018: using guessed type int aborting_app;
5660
5661 //----- (00466BE5) --------------------------------------------------------
5662 void Abortf(const char *Format, ...)
5663 {
5664 va_list va; // [sp+8h] [bp+8h]@1
5665
5666 va_start(va, Format);
5667 if ( !pRenderer->bWindowMode )
5668 pRenderer->ChangeBetweenWinFullscreenModes();
5669 vsprintf(pTmpBuf.data(), Format, va);
5670 if ( pMouse )
5671 pMouse->Activate(0);
5672 ClipCursor(0);
5673 MessageBoxA(0, pTmpBuf.data(), "Error", 0x30u);
5674 Game_DeinitializeAndTerminate(1);
5675 } 5514 }
5676 5515
5677 //----- (00466C40) -------------------------------------------------------- 5516 //----- (00466C40) --------------------------------------------------------
5678 const wchar_t *MENU_STATE_to_string(MENU_STATE m) 5517 const wchar_t *MENU_STATE_to_string(MENU_STATE m)
5679 { 5518 {