diff mm7_2.cpp @ 1588:e6ac4919b22c

Слияние
author Ritor1
date Mon, 09 Sep 2013 09:13:40 +0600
parents 9a6567c6c76c
children 75fafd8ced59 f408fbf3d9cc 0016b08ab621
line wrap: on
line diff
--- a/mm7_2.cpp	Mon Sep 09 09:13:23 2013 +0600
+++ b/mm7_2.cpp	Mon Sep 09 09:13:40 2013 +0600
@@ -4,9 +4,8 @@
 
 #include <io.h>
 #include <direct.h>
-#include <assert.h>
-#include <windows.h>
-
+
+#include "OSAPI.h"
 
 #include "Texture.h"
 #include "mm7_data.h"
@@ -685,7 +684,7 @@
   char *v9; // eax@14
   unsigned int v10; // eax@25
   GUIWindow pWindow; // [sp+34h] [bp-9Ch]@1
-  MSG Msg; // [sp+88h] [bp-48h]@22
+  //MSG Msg; // [sp+88h] [bp-48h]@22
   unsigned int v14; // [sp+A4h] [bp-2Ch]@5
   void *v15; // [sp+A8h] [bp-28h]@1
   char *pInString; // [sp+ACh] [bp-24h]@5
@@ -805,15 +804,12 @@
     LODWORD(v23) = GetTickCount() + 5000;
     while ( (unsigned int)v23 > GetTickCount() )
       ;
-    while ( 1 )
+    for (MSG msg; PeekMessage(&msg, 0, 0, 0, PM_REMOVE);)
     {
-      v10 = PeekMessageA(&Msg, 0, 0, 0, 1u);
-      if ( !v10 )
-        break;
-      if ( Msg.message == 18 )
+      if (msg.message == WM_QUIT)
         Game_DeinitializeAndTerminate(0);
-      TranslateMessage(&Msg);
-      DispatchMessageA(&Msg);
+      TranslateMessage(&msg);
+      DispatchMessage(&msg);
     }
     if ( pMessageQueue_50CBD0->uNumMessages )
     {
@@ -824,12 +820,12 @@
     pKeyActionMap->uLastKeyPressed = 0;
     do
     {
-      while ( PeekMessageA(&Msg, 0, 0, 0, 1u) )
+      for (MSG msg; PeekMessage(&msg, 0, 0, 0, PM_REMOVE);)
       {
-        if ( Msg.message == 18 )
+        if (msg.message == WM_QUIT)
           Game_DeinitializeAndTerminate(0);
-        TranslateMessage(&Msg);
-        DispatchMessageA(&Msg);
+        TranslateMessage(&msg);
+        DispatchMessage(&msg);
       }
     }
     while ( !pKeyActionMap->uLastKeyPressed );
@@ -3091,32 +3087,6 @@
       event_triggers[num_event_triggers++] = i;
 }
 
-OPENFILENAMEA ofn;
-//----- (0046271C) --------------------------------------------------------
-void CreateDefaultBLVLevel()
-{
-  ofn.lStructSize = 0x4Cu;
-  ofn.hwndOwner = hWnd;
-  ofn.hInstance = 0;
-  ofn.lpstrFilter = "Indoor  BLV Files (*.blv)";
-  ofn.lpstrCustomFilter = 0;
-  ofn.nMaxCustFilter = 0;
-  ofn.nFilterIndex = 0;
-  ofn.lpstrFile = 0;
-  ofn.nMaxFile = 260;
-  ofn.nMaxFileTitle = 512;
-  ofn.lpstrInitialDir = "levels";
-  ofn.lpstrTitle = "Might and Magic VII - Load Which Level?";
-  ofn.Flags = 4;
-  ofn.nFileOffset = 0;
-  ofn.nFileExtension = 0;
-  ofn.lpstrDefExt = "blv";
-  ofn.lCustData = 0;
-  ofn.lpfnHook = 0;
-  ofn.lpTemplateName = 0;
-  ofn.lpstrFileTitle = pTmpBuf.data();
-}
-
 //----- (004627B7) --------------------------------------------------------
 void MainMenu_Loop()
 {
@@ -3171,13 +3141,12 @@
       pWindow = pGUIWindow_CurrentMenu;
     }
 
-    MSG msg;
-    while ( PeekMessageA(&msg, 0, 0, 0, PM_REMOVE) )
+    for (MSG msg; PeekMessage(&msg, 0, 0, 0, PM_REMOVE);)
     {
       if (msg.message == WM_QUIT)
         Game_DeinitializeAndTerminate(0);
       TranslateMessage(&msg);
-      DispatchMessageA(&msg);
+      DispatchMessage(&msg);
     }
     if (dword_6BE364_game_settings_1 & 0x0100)
     {
@@ -3258,33 +3227,40 @@
 }
 
 //----- (004637EB) --------------------------------------------------------
-int __stdcall aWinProc(HWND hWnd, UINT Msg, WPARAM wParam, unsigned int lParam)
+int __stdcall aWinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
-  HANDLE v6; // eax@32
-  HDC v10; // edi@50
-  int v11; // esi@50
-  signed int v13; // eax@135
-  char v29; // dl@209
-  bool v31; // ebx@211
-  float v33; // ST04_4@246
-  float v34; // ST04_4@254
-  struct tagPAINTSTRUCT Paint; // [sp+24h] [bp-48h]@13
-  int pXY[2]; // [sp+64h] [bp-8h]@261
-  int a2; // [sp+7Ch] [bp+10h]@50
-
-  switch (Msg)
-  {
-    case WM_SIZING:  return 1;
+  //HANDLE v6; // eax@32
+  //HDC v10; // edi@50
+  //int v11; // esi@50
+  //signed int v13; // eax@135
+  //char v29; // dl@209
+  //bool v31; // ebx@211
+  //float v33; // ST04_4@246
+  //float v34; // ST04_4@254
+  //struct tagPAINTSTRUCT Paint; // [sp+24h] [bp-48h]@13
+  //int pXY[2]; // [sp+64h] [bp-8h]@261
+  //int a2; // [sp+7Ch] [bp+10h]@50
+
+  switch (uMsg)
+  {
+    case WM_SIZING: return 1;
+    
+    case WM_CREATE:  case WM_NCCREATE:
+    case WM_GETTEXT: case WM_SETTEXT:
     case WM_SHOWWINDOW:
-    case WM_GETTEXT:
-    case WM_SETTEXT: return DefWindowProcW(hWnd, Msg, wParam, lParam);
+      return DefWindowProcW(hWnd, uMsg, wParam, lParam);
+
+    case WM_DESTROY:
+      SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
+      PostQuitMessage(0);
+      return 0;
 
     case WM_WINDOWPOSCHANGED:
     {
       if (pVideoPlayer && pVideoPlayer->AnyMovieLoaded() && pVideoPlayer->pBinkBuffer)
         BinkBufferSetOffset(pVideoPlayer->pBinkBuffer, 0, 0);
 
-      return DefWindowProcW(hWnd, Msg, wParam, lParam);
+      return DefWindowProcW(hWnd, uMsg, wParam, lParam);
     }
 
     case WM_CHAR:
@@ -3292,13 +3268,13 @@
       if (!pKeyActionMap->_459F10(wParam) && !viewparams->field_4C)
         GUI_HandleHotkey(wParam);
     }
-    return DefWindowProcA(hWnd, Msg, wParam, lParam);
+    return DefWindowProcW(hWnd, uMsg, wParam, lParam);
 
 
     case WM_DEVICECHANGE:
     {
       if (wParam == 0x8000)          // CD or some device has been inserted - notify InsertCD dialog
-        PostMessageA(hInsertCDWindow, WM_USER + 1, 0, 0);
+        PostMessageW(hInsertCDWindow, WM_USER + 1, 0, 0);
       return 0;
     }
 
@@ -3310,7 +3286,7 @@
 
         case 101:  // Quit game
         case 40001:
-          SendMessageA(::hWnd, WM_DESTROY, 0, 0);
+          SendMessageW(hWnd, WM_DESTROY, 0, 0);
         return 0;
 
 
@@ -3479,355 +3455,296 @@
 
       }
     }
-    return DefWindowProcA(hWnd, Msg, wParam, lParam);
-  };
-
-  if ( Msg > WM_SYSCOMMAND )
-  {
-    switch ( Msg )
-    {
-      case WM_LBUTTONDOWN:
-        if ( pArcomageGame->bGameInProgress )
-        {
-          pArcomageGame->stru1.field_0 = 7;
-          ArcomageGame::OnMouseClick(0, 1);
-          return DefWindowProcA(hWnd, Msg, wParam, lParam);
-        }
-        goto __handle_mouse_click;
-
-      case WM_RBUTTONDOWN:
-        v31 = 0;
-        if ( !pArcomageGame->bGameInProgress )
-          //goto LABEL_240;
-        {
-          if ( pVideoPlayer->pVideoFrame.pPixels != (unsigned __int16 *)v31 )
-            pVideoPlayer->bStopBeforeSchedule = 1;
-
-          pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
-          if (pGame)
-          {
-            v33 = pGame->pIndoorCameraD3D->GetPickDepth();
-            pGame->PickMouse(v33, (unsigned __int16)lParam, lParam >> 16, v31, &vis_sprite_filter_2, &vis_door_filter);
-          }
-
-            sub_416D62_ShowPopupWindow_MonsterRecord_ItemInfo_etcsub_416D62(0);
-            return DefWindowProcA(hWnd, Msg, wParam, lParam);
-
-        }
-
+    return DefWindowProcW(hWnd, uMsg, wParam, lParam);
+
+    case WM_LBUTTONDOWN:
+      if (pArcomageGame->bGameInProgress)
+      {
+        pArcomageGame->stru1.field_0 = 7;
+        ArcomageGame::OnMouseClick(0, true);
+        return DefWindowProcW(hWnd, uMsg, wParam, lParam);
+      }
+
+      goto __handle_mouse_click;
+
+    case WM_RBUTTONDOWN:
+      if (pArcomageGame->bGameInProgress)
+      {
         pArcomageGame->stru1.field_0 = 8;
-        ArcomageGame::OnMouseClick(1, 1);
-        return DefWindowProcA(hWnd, Msg, wParam, lParam);
-      case WM_LBUTTONUP:
-        if ( !pArcomageGame->bGameInProgress )
-          //goto LABEL_218;
-        {
-          back_to_game();
-          return DefWindowProcA(hWnd, Msg, wParam, lParam);
-        }
-        pArcomageGame->stru1.field_0 = 3;
-        ArcomageGame::OnMouseClick(0, 0);
-        return DefWindowProcA(hWnd, Msg, wParam, lParam);
-      case WM_RBUTTONUP:
-        if ( !pArcomageGame->bGameInProgress )
-        {
-//LABEL_218:
-
-          back_to_game();
-          return DefWindowProcA(hWnd, Msg, wParam, lParam);
-        }
-        pArcomageGame->stru1.field_0 = 4;
-        ArcomageGame::OnMouseClick(1, false);
-        return DefWindowProcA(hWnd, Msg, wParam, lParam);
-
-      case WM_LBUTTONDBLCLK:
-        if ( pArcomageGame->bGameInProgress )
-        {
-          pArcomageGame->stru1.field_0 = 7;
-          return DefWindowProcA(hWnd, Msg, wParam, lParam);
-        }
+        ArcomageGame::OnMouseClick(1, true);
+        return DefWindowProcW(hWnd, uMsg, wParam, lParam);
+      }
+
+      if (pVideoPlayer->pVideoFrame.pPixels)
+        pVideoPlayer->bStopBeforeSchedule = 1;
+
+      pMouse->SetMouseClick(LOWORD(lParam), HIWORD(lParam));
+
+      if (pGame)
+      {
+        pGame->PickMouse(pGame->pIndoorCameraD3D->GetPickDepth(), LOWORD(lParam), HIWORD(lParam), 0, &vis_sprite_filter_2, &vis_door_filter);
+      }
+
+      sub_416D62_ShowPopupWindow_MonsterRecord_ItemInfo_etcsub_416D62(0);
+      return DefWindowProcW(hWnd, uMsg, wParam, lParam);
+
+
+    case WM_LBUTTONUP:
+      if ( !pArcomageGame->bGameInProgress )
+      {
+        back_to_game();
+        return DefWindowProcW(hWnd, uMsg, wParam, lParam);
+      }
+      pArcomageGame->stru1.field_0 = 3;
+      ArcomageGame::OnMouseClick(0, 0);
+      return DefWindowProcW(hWnd, uMsg, wParam, lParam);
+    case WM_RBUTTONUP:
+      if ( !pArcomageGame->bGameInProgress )
+      {
+        back_to_game();
+        return DefWindowProcW(hWnd, uMsg, wParam, lParam);
+      }
+      pArcomageGame->stru1.field_0 = 4;
+      ArcomageGame::OnMouseClick(1, false);
+      return DefWindowProcW(hWnd, uMsg, wParam, lParam);
+
+    case WM_LBUTTONDBLCLK:
+      if ( pArcomageGame->bGameInProgress )
+      {
+        pArcomageGame->stru1.field_0 = 7;
+        return DefWindowProcW(hWnd, uMsg, wParam, lParam);
+      }
         
 __handle_mouse_click:
-        if ( pVideoPlayer->pVideoFrame.pPixels )
+      if (pVideoPlayer->pVideoFrame.pPixels)
+        pVideoPlayer->bStopBeforeSchedule = 1;
+
+      pMouse->SetMouseClick(LOWORD(lParam), HIWORD(lParam));
+
+      if (GetCurrentMenuID() == MENU_CREATEPARTY)
+      {
+        UI_OnKeyDown(VK_SELECT);
+      }
+
+      if (pGame)
+        pGame->PickMouse(512.0, LOWORD(lParam), HIWORD(lParam), false, &vis_sprite_filter_3, &vis_door_filter);
+
+      UI_OnMouseLeftClick(0);
+
+      return DefWindowProcW(hWnd, uMsg, wParam, lParam);
+
+    case WM_RBUTTONDBLCLK:
+      if ( !pArcomageGame->bGameInProgress )
+      {
+        if (pVideoPlayer->pVideoFrame.pPixels)
           pVideoPlayer->bStopBeforeSchedule = 1;
 
-          pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
-
-        if (GetCurrentMenuID() != MENU_CREATEPARTY)
-          pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
-        else
+        pMouse->SetMouseClick(LOWORD(lParam), HIWORD(lParam));
+
+        if (pGame)
         {
-          UI_OnKeyDown(VK_SELECT);
-          pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
-        }
-
-
-          if (pGame)
-            pGame->PickMouse(512.0, (unsigned __int16)lParam, lParam >> 16, false, &vis_sprite_filter_3, &vis_door_filter);
-
-          UI_OnMouseLeftClick(0);
-
-        return DefWindowProcA(hWnd, Msg, wParam, lParam);
-
-      case WM_RBUTTONDBLCLK:
-        v31 = 0;
-        if ( !pArcomageGame->bGameInProgress )
-        {
-//LABEL_240:
-          if ( pVideoPlayer->pVideoFrame.pPixels != (unsigned __int16 *)v31 )
-            pVideoPlayer->bStopBeforeSchedule = 1;
-
-            pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
-          if (pGame)
-          {
-            v33 = pGame->pIndoorCameraD3D->GetPickDepth();
-            pGame->PickMouse(v33, (unsigned __int16)lParam, lParam >> 16, v31, &vis_sprite_filter_2, &vis_door_filter);
-          }
-
-            sub_416D62_ShowPopupWindow_MonsterRecord_ItemInfo_etcsub_416D62(0);
-            return DefWindowProcA(hWnd, Msg, wParam, lParam);
-
+          pGame->PickMouse(pGame->pIndoorCameraD3D->GetPickDepth(), LOWORD(lParam), HIWORD(lParam), false, &vis_sprite_filter_2, &vis_door_filter);
         }
-        pArcomageGame->stru1.field_0 = 8;
-        return DefWindowProcA(hWnd, Msg, wParam, lParam);
-      case WM_MBUTTONDOWN:
-        if ( pRenderer->pRenderD3D )
-        {
-          if ( pGame )
-          {
-            v34 = pGame->pIndoorCameraD3D->GetPickDepth();
-            pGame->PickMouse(v34, (unsigned __int16)lParam, lParam >> 16, 1, &vis_sprite_filter_3, &vis_face_filter);
-            return DefWindowProcA(hWnd, Msg, wParam, lParam);
-          }
-        }
-        if ( !pGame )
-          //goto _def_wnd_proc;
-          return DefWindowProcA(hWnd, Msg, wParam, lParam);
-        return DefWindowProcA(hWnd, Msg, wParam, lParam);
-      case WM_MOUSEMOVE:
-        if ( pArcomageGame->bGameInProgress )
-        {
-          pXY[0] = (unsigned __int16)lParam;
-          pXY[1] = lParam >> 16;
-          ArcomageGame::OnMouseMove((POINT *)pXY);
-          ArcomageGame::OnMouseClick(0, wParam & 1);
-          v29 = (wParam >> 1) & 1;
-          ArcomageGame::OnMouseClick(1, v29 != 0);
-        }
-        else
-        {
-          pMouse->SetMouseClick((unsigned __int16)lParam, lParam >> 16);
-        }
-        return DefWindowProcA(hWnd, Msg, wParam, lParam);
-      default:
-        //goto _def_wnd_proc;
-        return DefWindowProcA(hWnd, Msg, wParam, lParam);
-    }
-  }
-  if ( Msg == WM_SYSCOMMAND )
-  {
-    if ( wParam == SC_SCREENSAVE || wParam == SC_MONITORPOWER )
-      return 0;
-    //goto _def_wnd_proc;
-    return DefWindowProcA(hWnd, Msg, wParam, lParam);
-  }
-  if ( Msg > WM_ACTIVATEAPP )
-  {
-    if ( Msg != WM_KEYFIRST && Msg != WM_WINDOWPOSCHANGED)
-    {
-      if ( Msg == WM_KEYUP && wParam == VK_CONTROL )
+
+        sub_416D62_ShowPopupWindow_MonsterRecord_ItemInfo_etcsub_416D62(0);
+        return DefWindowProcW(hWnd, uMsg, wParam, lParam);
+      }
+
+      pArcomageGame->stru1.field_0 = 8;
+
+      return DefWindowProcW(hWnd, uMsg, wParam, lParam);
+
+    case WM_MBUTTONDOWN:
+      if (pRenderer->pRenderD3D && pGame)
+      {
+        pGame->PickMouse(pGame->pIndoorCameraD3D->GetPickDepth(), LOWORD(lParam), HIWORD(lParam), 1, &vis_sprite_filter_3, &vis_face_filter);
+      }
+
+      return DefWindowProcW(hWnd, uMsg, wParam, lParam);
+
+    case WM_MOUSEMOVE:
+      if ( pArcomageGame->bGameInProgress )
+      {
+        ArcomageGame::OnMouseMove(LOWORD(lParam), HIWORD(lParam));
+        ArcomageGame::OnMouseClick(0, wParam == MK_LBUTTON);
+        ArcomageGame::OnMouseClick(1, wParam == MK_RBUTTON);
+      }
+      else
+      {
+        pMouse->SetMouseClick(LOWORD(lParam), HIWORD(lParam));
+      }
+
+      return DefWindowProcW(hWnd, uMsg, wParam, lParam);
+
+    case WM_SYSCOMMAND:
+      if ( wParam == SC_SCREENSAVE || wParam == SC_MONITORPOWER )
+        return 0;
+
+      return DefWindowProcW(hWnd, uMsg, wParam, lParam);
+
+    case WM_KEYUP:
+      if (wParam == VK_CONTROL)
       {
         dword_507B98_ctrl_pressed = 0;
       }
-      return DefWindowProcA(hWnd, Msg, wParam, lParam);
-    }
-    if ( uGameMenuUI_CurentlySelectedKeyIdx != -1 )
-    {
-      pKeyActionMap->_459F10(wParam);
-      return DefWindowProcA(hWnd, Msg, wParam, lParam);
-    }
-    if ( !pArcomageGame->bGameInProgress )
-    {
-      if ( pVideoPlayer->pVideoFrame.pPixels )
-        pVideoPlayer->bStopBeforeSchedule = 1;
-      if ( wParam == VK_RETURN )
-      {
-        if ( !viewparams->field_4C )
-          UI_OnKeyDown(wParam);
-        return 0;
-      }
-      if ( wParam == VK_CONTROL )
+
+      return DefWindowProcW(hWnd, uMsg, wParam, lParam);
+
+    case WM_KEYDOWN:
+      if ( uGameMenuUI_CurentlySelectedKeyIdx != -1 )
       {
-        dword_507B98_ctrl_pressed = 1;
-        return 0;
-      }
-      if ( wParam == VK_ESCAPE )
-      {
-        pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, window_SpeakInHouse != 0, 0);
-        return 0;
+        pKeyActionMap->_459F10(wParam);
+        return DefWindowProcW(hWnd, uMsg, wParam, lParam);
       }
-      if ( wParam <= VK_HOME )
-        return 0;
-      if ( wParam > VK_DOWN )
+      if ( !pArcomageGame->bGameInProgress )
       {
-        if ( wParam != VK_F4 || pVideoPlayer->AnyMovieLoaded() )
-          return 0;
-        SendMessageA(hWnd, WM_COMMAND, 104, 0);
-        return 0;
-      }
-      if ( wParam >= VK_LEFT && wParam <= VK_DOWN )
-      {
-        if ( pCurrentScreen != SCREEN_GAME && pCurrentScreen != SCREEN_MODAL_WINDOW )
+        if ( pVideoPlayer->pVideoFrame.pPixels )
+          pVideoPlayer->bStopBeforeSchedule = 1;
+        if ( wParam == VK_RETURN )
         {
           if ( !viewparams->field_4C )
             UI_OnKeyDown(wParam);
           return 0;
         }
-      }
-      if ( pCurrentScreen != SCREEN_GAME && pCurrentScreen != SCREEN_MODAL_WINDOW )
-        return 0;
-    }
-
-    pArcomageGame->stru1.field_0 = 1;
-
-    v13 = (unsigned __int16)MapVirtualKeyA((unsigned __int16)wParam, 2u);
-    set_stru1_field_8_InArcomage(v13);
-    if ( wParam == 27 )
-    {
-      pArcomageGame->GameOver = 1;
-      pArcomageGame->field_F4 = 1;
-      pArcomageGame->uGameResult = 2;
-      pArcomageGame->field_B0 = -2;
-      return DefWindowProcA(hWnd, Msg, wParam, lParam);
-    }
-    if ( wParam != 114 )
-    {
-      if ( wParam == 115 && !pVideoPlayer->AnyMovieLoaded() )
-        SendMessageA(hWnd, 0x111u, 0x68u, 0);
-      return DefWindowProcA(hWnd, Msg, wParam, lParam);
-    }
-    SendMessageA(hWnd, WM_COMMAND, 103, 0);
-    return 0;
-  }
-  if ( Msg == WM_ACTIVATEAPP )
-  {
-    if ( wParam && (GetForegroundWindow() == hWnd || GetForegroundWindow() == hInsertCDWindow) )
-    {
-      if ( BYTE1(dword_6BE364_game_settings_1) & 1 )
-      {
-        dword_4E98BC_bApplicationActive = 1;
-        if ( pRenderer->bWindowMode )
+        if ( wParam == VK_CONTROL )
+        {
+          dword_507B98_ctrl_pressed = 1;
+          return 0;
+        }
+        if ( wParam == VK_ESCAPE )
         {
-          v10 = GetDC(0);
-          a2 = GetDeviceCaps(v10, BITSPIXEL);
-          v11 = GetDeviceCaps(v10, PLANES);
-          ReleaseDC(0, v10);
-          if ( a2 != 16 || v11 != 1 )
-            Abortf(pGlobalTXT_LocalizationStrings[62]);
+          pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, window_SpeakInHouse != 0, 0);
+          return 0;
         }
-        BYTE1(dword_6BE364_game_settings_1) &= 0xFEu;
-
-        if ( pArcomageGame->bGameInProgress )
-        {
-          pArcomageGame->field_F9 = 1;
-        }
-        else
+        if ( wParam <= VK_HOME )
+          return 0;
+        if ( wParam > VK_DOWN )
         {
-          if ( BYTE1(dword_6BE364_game_settings_1) & 2 )
-            BYTE1(dword_6BE364_game_settings_1) &= 0xFDu;
-          else
-            pEventTimer->Resume();
-          if ( BYTE1(dword_6BE364_game_settings_1) & 4 )
-            BYTE1(dword_6BE364_game_settings_1) &= 0xFBu;
-          else
-            pMiscTimer->Resume();
-
-          viewparams->bRedrawGameUI = true;
-          if ( pVideoPlayer->pSmackerMovie )
+          if ( wParam != VK_F4 || pVideoPlayer->AnyMovieLoaded() )
+            return 0;
+          SendMessageW(hWnd, WM_COMMAND, 104, 0);
+          return 0;
+        }
+        if ( wParam >= VK_LEFT && wParam <= VK_DOWN )
+        {
+          if ( pCurrentScreen != SCREEN_GAME && pCurrentScreen != SCREEN_MODAL_WINDOW )
           {
-            pRenderer->RestoreFrontBuffer();
-            pRenderer->_4A184C();
-            pVideoPlayer->_4BF5B2();
+            if ( !viewparams->field_4C )
+              UI_OnKeyDown(wParam);
+            return 0;
           }
         }
-        if ( pAudioPlayer->hAILRedbook && !bGameoverLoop && !pVideoPlayer->pSmackerMovie )
-          AIL_redbook_resume(pAudioPlayer->hAILRedbook);
+        if ( pCurrentScreen != SCREEN_GAME && pCurrentScreen != SCREEN_MODAL_WINDOW )
+          return 0;
       }
-    }
-    else
-    {
-      if ( !(dword_6BE364_game_settings_1 & 0x100) )
+
+      pArcomageGame->stru1.field_0 = 1;
+
+      set_stru1_field_8_InArcomage(MapVirtualKey(wParam, MAPVK_VK_TO_CHAR));
+      if ( wParam == 27 )
       {
-        while(initing); //ADDED spinlock to allow int players ets! Gloval
-          dword_4E98BC_bApplicationActive = 0;
-        if ( (pVideoPlayer->pSmackerMovie || pVideoPlayer->pBinkMovie) && pVideoPlayer->bPlayingMovie )
-          pVideoPlayer->bStopBeforeSchedule = 1;
-
-        if ( pRenderer->bUserDirect3D && pRenderer->uAcquiredDirect3DDevice == 1 )
-          SetWindowPos(::hWnd, (HWND)0xFFFFFFFE, 0, 0, 0, 0, 0x18u);
-        ClipCursor(0);
-        dword_6BE364_game_settings_1 |= 0x100u;
-        if ( pEventTimer->bPaused )
-          BYTE1(dword_6BE364_game_settings_1) |= 2u;
-        else
-          pEventTimer->Pause();
-        if ( pMiscTimer->bPaused )
-          BYTE1(dword_6BE364_game_settings_1) |= 4u;
-        else
-          pMiscTimer->Pause();
-
-        pAudioPlayer->StopChannels(-1, -1);
-        if ( pAudioPlayer->hAILRedbook )
-          AIL_redbook_pause(pAudioPlayer->hAILRedbook);
+        pArcomageGame->GameOver = 1;
+        pArcomageGame->field_F4 = 1;
+        pArcomageGame->uGameResult = 2;
+        pArcomageGame->field_B0 = -2;
+        return DefWindowProcW(hWnd, uMsg, wParam, lParam);
+      }
+      if ( wParam != 114 )
+      {
+        if ( wParam == 115 && !pVideoPlayer->AnyMovieLoaded() )
+          SendMessage(hWnd, WM_COMMAND, 0x68u, 0);
+        return DefWindowProcW(hWnd, uMsg, wParam, lParam);
       }
-    }
-    return 0;
-  }
-  if (Msg == WM_CREATE)
-  {
-    auto hDC = GetDC(hWnd);
-    {
-      if (GetDeviceCaps(hDC, BITSPIXEL) < 8)
+      SendMessageW(hWnd, WM_COMMAND, 103, 0);
+      return 0;
+
+    case WM_ACTIVATEAPP:
+      if ( wParam && (GetForegroundWindow() == hWnd || GetForegroundWindow() == hInsertCDWindow) )
       {
-        ReleaseDC(hWnd, hDC);
-        Log::Warning(L"You must be running in 256 color mode or higher.");
-        Abortf("You must be running in 256 color mode or higher. You can change the screen depth with the control panel display icon.");
+        if ( BYTE1(dword_6BE364_game_settings_1) & 1 )
+        {
+          dword_4E98BC_bApplicationActive = 1;
+          if ( pRenderer->bWindowMode )
+          {
+            HDC hDC = GetDC(hWnd);
+            int bitsPerPixel = GetDeviceCaps(hDC, BITSPIXEL);
+            int planes = GetDeviceCaps(hDC, PLANES);
+            ReleaseDC(hWnd, hDC);
+            if (bitsPerPixel != 16 || planes != 1)
+              Error(pGlobalTXT_LocalizationStrings[62]);
+          }
+          BYTE1(dword_6BE364_game_settings_1) &= 0xFEu;
+
+          if ( pArcomageGame->bGameInProgress )
+          {
+            pArcomageGame->field_F9 = 1;
+          }
+          else
+          {
+            if ( BYTE1(dword_6BE364_game_settings_1) & 2 )
+              BYTE1(dword_6BE364_game_settings_1) &= 0xFDu;
+            else
+              pEventTimer->Resume();
+            if ( BYTE1(dword_6BE364_game_settings_1) & 4 )
+              BYTE1(dword_6BE364_game_settings_1) &= 0xFBu;
+            else
+              pMiscTimer->Resume();
+
+            viewparams->bRedrawGameUI = true;
+            if ( pVideoPlayer->pSmackerMovie )
+            {
+              pRenderer->RestoreFrontBuffer();
+              pRenderer->_4A184C();
+              pVideoPlayer->_4BF5B2();
+            }
+          }
+          if ( pAudioPlayer->hAILRedbook && !bGameoverLoop && !pVideoPlayer->pSmackerMovie )
+            AIL_redbook_resume(pAudioPlayer->hAILRedbook);
+        }
       }
-    }
-    ReleaseDC(hWnd, hDC);
-    return 0;
-  }
-  if ( Msg == WM_DESTROY )
-  {
-    v6 = GetCurrentProcess();
-    SetPriorityClass(v6, 0x20u);
-    if ( pGame )
-    {
-
-    }
-
-    PostQuitMessage(0);
-    return 0;
-  }
-  if ( Msg == WM_SETFOCUS )
-  {
-    if ( ::hWnd == (HWND)wParam )
-    {
+      else
+      {
+        if (!(dword_6BE364_game_settings_1 & 0x100))
+        {
+          dword_4E98BC_bApplicationActive = 0;
+          if ( (pVideoPlayer->pSmackerMovie || pVideoPlayer->pBinkMovie) && pVideoPlayer->bPlayingMovie )
+            pVideoPlayer->bStopBeforeSchedule = 1;
+
+          if ( pRenderer->bUserDirect3D && pRenderer->uAcquiredDirect3DDevice == 1 )
+            SetWindowPos(hWnd, (HWND)0xFFFFFFFE, 0, 0, 0, 0, 0x18u);
+          ClipCursor(0);
+          dword_6BE364_game_settings_1 |= 0x100u;
+          if ( pEventTimer->bPaused )
+            BYTE1(dword_6BE364_game_settings_1) |= 2u;
+          else
+            pEventTimer->Pause();
+          if ( pMiscTimer->bPaused )
+            BYTE1(dword_6BE364_game_settings_1) |= 4u;
+          else
+            pMiscTimer->Pause();
+
+          pAudioPlayer->StopChannels(-1, -1);
+          if ( pAudioPlayer->hAILRedbook )
+            AIL_redbook_pause(pAudioPlayer->hAILRedbook);
+        }
+      }
+      return 0;
+
+    case WM_SETFOCUS:
       dword_4E98BC_bApplicationActive = 0;
       if ( pRenderer->bUserDirect3D && pRenderer->uAcquiredDirect3DDevice == 1 )
-        SetWindowPos(::hWnd, (HWND)0xFFFFFFFE, 0, 0, 0, 0, 0x18u);
+        SetWindowPos(hWnd, (HWND)0xFFFFFFFE, 0, 0, 0, 0, 0x18u);
       ClipCursor(0);
-
-    }
-//_def_wnd_proc:
-    return DefWindowProcA(hWnd, Msg, wParam, lParam);
-  }
-  if ( Msg != WM_KILLFOCUS )
-  {
-    if ( Msg == WM_PAINT )
-    {
+      return DefWindowProcW(hWnd, uMsg, wParam, lParam);
+
+    case WM_KILLFOCUS:
+      dword_4E98BC_bApplicationActive = 1;
+      return DefWindowProcW(hWnd, uMsg, wParam, lParam);
+
+    case WM_PAINT:
       if ( !GetUpdateRect(hWnd, 0, 0) || !dword_4E98BC_bApplicationActive && !pRenderer->bWindowMode )
         return 0;
+      PAINTSTRUCT Paint;
       BeginPaint(hWnd, &Paint);
       if ( pArcomageGame->bGameInProgress )
       {
@@ -3844,13 +3761,10 @@
       pRenderer->Present();
       EndPaint(hWnd, &Paint);
       return 0;
-    }
-    //goto _def_wnd_proc;
-    return DefWindowProcA(hWnd, Msg, wParam, lParam);
-  }
-  if ( ::hWnd != (HWND)wParam || (dword_4E98BC_bApplicationActive = 1, pRenderer->bWindowMode) || true )
-    return DefWindowProcA(hWnd, Msg, wParam, lParam);
-
+
+    default:
+      return DefWindowProcA(hWnd, uMsg, wParam, lParam);
+  }
 }
 
 //----- (00464479) --------------------------------------------------------
@@ -3980,12 +3894,12 @@
     pSpriteObjects[i].uObjectDescID = 0;
 
   v5 = pMapStats->GetMapInfo(pCurrentMapName);
-  bUnderwater = 0;
+  bUnderwater = false;
   uLevelMapStatsID = v5;
   pGame->uFlags2 &= 0xFFFFFFF7u;
   if ( !_stricmp(pCurrentMapName, "out15.odm") )
   {
-    bUnderwater = 1;
+    bUnderwater = true;
     pGame->uFlags2 |= 8u;
   }
   pParty->floor_face_pid = 0;
@@ -4384,7 +4298,6 @@
 //----- (004651F4) --------------------------------------------------------
 bool MM7_Initialize()
 {
-initing=true; //ADDED Gloval
   wchar_t pCurrentDir[1024];
   _wgetcwd(pCurrentDir, 1024);
 
@@ -4426,11 +4339,6 @@
   auto hDesktopDC = GetDC(nullptr);
   uint uDesktopWidth = GetDeviceCaps(hDesktopDC, HORZRES);
   uint uDesktopHeight = GetDeviceCaps(hDesktopDC, VERTRES);
-
-  if (GetDeviceCaps(hDesktopDC, BITSPIXEL) != 16 ||
-      GetDeviceCaps(hDesktopDC, PLANES) != 1 )
-    dword_6BE364_game_settings_1 |= 2;
-
   ReleaseDC(nullptr, hDesktopDC);
 
   uint uTotalWinWidth = 2 * GetSystemMetrics(SM_CXFRAME) + 640;
@@ -4452,10 +4360,9 @@
                          uWindowX, uWindowY,
                          640, 480,
                          nullptr,
-                         hOSMenu = nullptr,
+                         nullptr,
                          wcxw.hInstance,
                          nullptr);
-  SetWindowTextW(hWnd, L"Might and Magic VII");
 
   HMENU menu = CreateMenu();
   {
@@ -4664,7 +4571,6 @@
   MoveWindow(hWnd, uWindowX, uWindowY,
     rcClient.left - rcClient.right - rcWindow.left + rcWindow.right + 640,
     rcClient.top - rcClient.bottom - rcWindow.top + rcWindow.bottom + 480, 0);
-  ShowWindow(hWnd, SW_SHOWNORMAL);
 
   pIcons_LOD = new LODFile_IconsBitmaps;
   if (!pIcons_LOD->Load("data\\icons.lod", "icons"))
@@ -4717,7 +4623,7 @@
   }
 
 
-
+#if 0
   if (_access("../MM_VI/data/icons.lod", 0) == 0)
   {
     pIcons_LOD_mm6 = new LODFile_IconsBitmaps;
@@ -4760,54 +4666,48 @@
     Log::Warning(L"Unable to find mm6:sprites.lod");
 
 
-
-  if (bDebugResouces)
-  {
-    pSpriteFrameTable = new SpriteFrameTable;
-    if (!pSpriteFrameTable->FromFileTxt("data\\sft.txt"))
-      Abortf("Unable to open sft.txt");
-
-    pDecorationList = new DecorationList;
-    if (!pDecorationList->FromFileTxt("data\\declist.txt"))
-      Abortf("Unable to open declist.txt");
-
-    pObjectList = new ObjectList;
-    if (!pObjectList->FromFileTxt("data\\objlist.txt"))
-      Abortf("Unable to open objlist.txt");
-
-    pMonsterList = new MonsterList;
-    if (!pMonsterList->FromFileTxt("data\\monlist.txt"))
-      Abortf("Unable to open monlist.txt");
-
-    pIconsFrameTable = new IconFrameTable;
-    if (!pIconsFrameTable->FromFileTxt("data\\ift.txt"))
-      Abortf("Unable to open ift.txt");
-
-    pTextureFrameTable = new TextureFrameTable;
-    if (!pTextureFrameTable->FromFileTxt("data\\tft.def"))
-      Abortf("Unable to open tft.def");
-
-    pTileTable = new TileTable;
-    if (!pTileTable->FromFileTxt("data\\tile.def"))
-      Abortf("Unable to open tile.def");
-
-    pPlayerFrameTable = new PlayerFrameTable;
-    if (!pPlayerFrameTable->FromFileTxt("data\\pft.def"))
-      Abortf("Unable to open pft.def");
-
-    pChestList = new ChestList;
-    if (!pChestList->FromFileTxt("data\\chest.def"))
-      Abortf("Unable to open chest.def");
-
-    pOverlayList = new OverlayList;
-    if (!pOverlayList->FromFileTxt("data\\overlay.def"))
-      Abortf("Unable to open overlay.def");
-
-    pSoundList = new SoundList;
-    if (!pSoundList->FromFileTxt("data\\sounds.def"))
-      Abortf("Unable to open sounds.def");
+  if (_access("../mm8/data/icons.lod", 0) == 0)
+  {
+    pIcons_LOD_mm8 = new LODFile_IconsBitmaps;
+    if (!pIcons_LOD_mm8->Load("../mm8/data/icons.lod", "icons"))
+    {
+      delete pIcons_LOD_mm8;
+      pIcons_LOD_mm8 = nullptr;
+      Log::Warning(L"Unable to load mm8:icons.lod");
+    }
   }
   else
+    Log::Warning(L"Unable to find mm8:icons.lod");
+
+
+  if (_access("../mm8/data/bitmaps.lod", 0) == 0)
+  {
+    pBitmaps_LOD_mm8 = new LODFile_IconsBitmaps;
+    if (!pBitmaps_LOD_mm8->Load("../mm8/data/bitmaps.lod", "bitmaps"))
+    {
+      delete pBitmaps_LOD_mm8;
+      pBitmaps_LOD_mm8 = nullptr;
+      Log::Warning(L"Unable to load mm8:bitmaps.lod");
+    }
+  }
+  else
+    Log::Warning(L"Unable to find mm8:bitmaps.lod");
+  
+
+  if (_access("../mm8/data/sprites.lod", 0) == 0)
+  {
+    pSprites_LOD_mm8 = new LODFile_Sprites;
+    if (!pSprites_LOD_mm8->LoadSprites("../mm8/data/sprites.lod"))
+    {
+      delete pSprites_LOD_mm8;
+      pSprites_LOD_mm8 = nullptr;
+      Log::Warning(L"Unable to load mm8:sprites.lod");
+    }
+  }
+  else
+    Log::Warning(L"Unable to find mm8:sprites.lod");
+#endif
+
   {
     void *sft_mm6 = pIcons_LOD_mm6 ? pIcons_LOD_mm6->LoadRaw("dsft.bin", 1) : nullptr,
          *sft_mm8 = nullptr;
@@ -4910,20 +4810,6 @@
   }
 
 
-  if (bDebugResouces)
-  {
-    pSpriteFrameTable->ToFile();
-    pDecorationList->ToFile();
-    pObjectList->ToFile();
-    pMonsterList->ToFile();
-    pIconsFrameTable->ToFile();
-    pTextureFrameTable->ToFile();
-    pTileTable->ToFile();
-    pPlayerFrameTable->ToFile();
-    pChestList->ToFile();
-    pOverlayList->ToFile();
-    pSoundList->ToFile();
-  }
 
   
   if (dword_6BE364_game_settings_1 & 2 || !(dword_6BE368_debug_settings_2 & 1))// 
@@ -4999,7 +4885,7 @@
       break;
     }
 
-  initing = false; //ADDED Gloval
+  ShowWindow(hWnd, SW_SHOWNORMAL);
   return true;
 }
 
@@ -5182,7 +5068,7 @@
   assert(sizeof(MobileLight) == 0x12);
   assert(sizeof(LightsStack_MobileLight_) == 0x1C28);
   assert(sizeof(Game) == 0xE78);
-  assert(sizeof(stru141) == 0xA8);
+  assert(sizeof(stru141_actor_collision_object) == 0xA8);
   assert(sizeof(ActionQueue) == 0x7C);
   assert(sizeof(NPCData) == 0x4C);
   assert(sizeof(NPCStats) == 0x17FFC);
@@ -5248,19 +5134,6 @@
 //----- (00462C94) --------------------------------------------------------
 bool MM_Main(const wchar_t *pCmdLine)
 {
-  HWND hPrevWnd; // eax@1
-  HWND hPrevWnd_; // esi@1
-  HWND v6; // eax@4
-  int v8; // eax@15
-  //bool v9; // edx@16
-  //OtherOverlay *v10; // esi@44
-  //signed int v11; // edi@44
-  //unsigned int v12; // ecx@56
-  HANDLE v13; // eax@68
-  unsigned int startms; // [sp+8h] [bp-24h]@55
-  RECT Rect; // [sp+Ch] [bp-20h]@15
-  int a2[4]; // [sp+1Ch] [bp-10h]@15
-  
   IntegrityTest();
   char test[1024];
   sprintfex(test, "^Pi[%s]: ^R[;;]", "");
@@ -5312,7 +5185,6 @@
     pGame->Deinitialize();
     return 1;
   }
-  Log::Warning(L"MM init: ok");
 
     pEventTimer->Pause();
 
@@ -5322,7 +5194,7 @@
     dword_6BE364_game_settings_1 |= 0x4000;
     pGame->InitializeGammaController();
     SecondaryInitialization();
-    pRenderer->SetRasterClipRect(0, 0, 639u, 479u);
+    pRenderer->SetRasterClipRect(0, 0, 639, 479);
     FinalInitialization();
 
     Log::Warning(L"MM: entering main loop");
@@ -5395,18 +5267,19 @@
 
 			  pParty->Reset();
 			  pParty->CreateDefaultParty(1);
-
-              extern void CreateDefaultBLVLevel();
+              
+              __debugbreak();
+              /*extern void CreateDefaultBLVLevel();
 			  CreateDefaultBLVLevel();
 
-			  extern OPENFILENAMEA ofn;
+			  OPENFILENAMEA ofn;
 			  if ( !GetOpenFileNameA((LPOPENFILENAMEA)&ofn) )
 			  {
 				pMouse->Activate(1);
 				break;
 			  }
 			  _chdir("..\\");
-			  strcpy(pCurrentMapName, ofn.lpstrFileTitle);
+			  strcpy(pCurrentMapName, ofn.lpstrFileTitle);*/
 			  pMouse->Activate(1);
 			  pGame->Loop();
 		  }
@@ -5434,7 +5307,7 @@
       {
         pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f);
         AIL_redbook_stop(pAudioPlayer->hAILRedbook);
-        unsigned int end_ms;
+        unsigned int startms, end_ms;
         AIL_redbook_track_info(pAudioPlayer->hAILRedbook, 0xE, &startms, &end_ms);
         AIL_redbook_play(pAudioPlayer->hAILRedbook, startms + 1, end_ms);
       }
@@ -5640,40 +5513,6 @@
     pOutdoorCamera->_485F64();
 }
 
-//----- (00466B8C) --------------------------------------------------------
-int  AbortWithError()
-{
-  if ( !aborting_app )
-  {
-    ClipCursor(0);
-    aborting_app = 1;
-    if ( !pRenderer->bWindowMode )
-      pRenderer->ChangeBetweenWinFullscreenModes();
-    if ( MessageBoxA(0, pGlobalTXT_LocalizationStrings[176], pGlobalTXT_LocalizationStrings[59], 0x34u) == 6 )
-      SaveGame(1, 0);                           // "Internal Error"
-                                                // "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?"
-    Game_DeinitializeAndTerminate(1);
-  }
-  return 0;
-}
-// 720018: using guessed type int aborting_app;
-
-//----- (00466BE5) --------------------------------------------------------
-void Abortf(const char *Format, ...)
-{
-  va_list va; // [sp+8h] [bp+8h]@1
-
-  va_start(va, Format);
-  if ( !pRenderer->bWindowMode )
-    pRenderer->ChangeBetweenWinFullscreenModes();
-  vsprintf(pTmpBuf.data(), Format, va);
-  if ( pMouse )
-    pMouse->Activate(0);
-  ClipCursor(0);
-  MessageBoxA(0, pTmpBuf.data(), "Error", 0x30u);
-  Game_DeinitializeAndTerminate(1);
-}
-
 //----- (00466C40) --------------------------------------------------------
 const wchar_t *MENU_STATE_to_string(MENU_STATE m)
 {