changeset 2541:a902abdfc7f2

1. Renamed class Game to class Engine. 2. Separated game logic as state of FSM from game logic as engine. 3. Found out that many UI screen initializers were optimized away, intially they all returned newly created window as separate object like it is done in CharacterUI_Initialize.
author a.parshin
date Sun, 10 May 2015 01:29:11 +0200
parents abc6a9d079b9
children bacf9809126a
files Arcomage/Arcomage.cpp Build/Visual Studio 2013/World of Might and Magic.vcxproj Build/Visual Studio 2013/World of Might and Magic.vcxproj.filters Engine/Engine.cpp Engine/Engine.h Engine/Events.cpp Engine/Game.cpp Engine/Game.h Engine/Graphics/DecalBuilder.cpp Engine/Graphics/DecorationList.cpp Engine/Graphics/Indoor.cpp Engine/Graphics/IndoorCameraD3D.cpp Engine/Graphics/Level/Decoration.cpp Engine/Graphics/LightmapBuilder.cpp Engine/Graphics/Outdoor.cpp Engine/Graphics/Overlays.cpp Engine/Graphics/PaletteManager.cpp Engine/Graphics/ParticleEngine.cpp Engine/Graphics/Render.cpp Engine/Graphics/RenderD3D11.cpp Engine/Graphics/Sprites.cpp Engine/Graphics/Texture.cpp Engine/Graphics/Viewport.cpp Engine/Graphics/Vis.cpp Engine/Graphics/stru10.cpp Engine/Graphics/stru9.cpp Engine/LOD.cpp Engine/MMT.cpp Engine/MapInfo.cpp Engine/Objects/Actor.cpp Engine/Objects/Chest.cpp Engine/Objects/Items.cpp Engine/Objects/Monsters.cpp Engine/Objects/ObjectList.cpp Engine/Objects/Player.cpp Engine/Objects/SpriteObject.cpp Engine/Party.cpp Engine/SaveLoad.cpp Engine/Spells/CastSpellInfo.cpp Engine/Spells/Spells.cpp Engine/Tables/FactionTable.cpp Engine/Tables/IconFrameTable.cpp Engine/Tables/PlayerFrameTable.cpp Engine/Tables/TileTable.cpp Engine/TurnEngine/TurnEngine.cpp Engine/mm7_data.cpp Engine/mm7_data.h Engine/mm7text_ru.cpp Engine/stuff.h Engine/texts.cpp GUI/GUIButton.cpp GUI/GUIFont.cpp GUI/GUIProgressBar.cpp GUI/GUIWindow.cpp GUI/GUIWindow.h GUI/UI/Books/UIMapBook.cpp GUI/UI/Books/UINotesBooks.cpp GUI/UI/Books/UISpellBook.cpp GUI/UI/UIArena.cpp GUI/UI/UIBooks.cpp GUI/UI/UICharacter.cpp GUI/UI/UIGuilds.cpp GUI/UI/UIHouses.cpp GUI/UI/UIMainMenu.cpp GUI/UI/UIOptions.cpp GUI/UI/UIPartyCreation.cpp GUI/UI/UIPopup.cpp GUI/UI/UIRest.cpp GUI/UI/UISaveLoad.cpp GUI/UI/UIShops.cpp GUI/UI/UITransition.cpp GUI/UI/UiGame.cpp Game/Game.cpp Game/Game.h Game/MainMenu.cpp Game/MainMenu.h IO/Keyboard.cpp IO/Mouse.cpp Media/Audio/AudioPlayer.cpp Media/Audio/OpenALSoundProvider.h Media/MediaPlayer.cpp Media/MediaPlayer.h OSWindow.cpp _deleted.cpp stru6.cpp
diffstat 85 files changed, 9170 insertions(+), 9063 deletions(-) [+]
line wrap: on
line diff
--- a/Arcomage/Arcomage.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Arcomage/Arcomage.cpp	Sun May 10 01:29:11 2015 +0200
@@ -6,19 +6,18 @@
 #include <string>
 
 
-#include "..\Engine/Graphics/Render.h"
+#include "Engine/Engine.h"
+#include "Engine/Graphics/Render.h"
 #include "Arcomage.h"
 #include "Media/Audio/AudioPlayer.h"
-#include "../Engine/Game.h"
-#include "..\Engine/Graphics/Viewport.h"
-#include "../Engine/Timer.h"
+#include "Engine/Graphics/Viewport.h"
+#include "Engine/Timer.h"
 #include "GUI/GUIFont.h"
-#include "../Engine/Party.h"
+#include "Engine/Party.h"
 #include "GUI/GUIWindow.h"
-#include "../Engine/texts.h"
+#include "Engine/texts.h"
 #include <windef.h>
-#include "../Engine/mm7_data.h"
-#include "GUI\UI/UIHouses.h"
+#include "GUI/UI/UIHouses.h"
 
 
 
@@ -559,17 +558,17 @@
   pArcomageGame->stru1.field_0 = 0;
   //v3 = PeekMessageA(&pArcomageGame->msg, 0, 0, 0, PM_REMOVE);
   //if ( pArcomageGame->msg.message == WM_QUIT )
-    //Game_DeinitializeAndTerminate(0);
+    //Engine_DeinitializeAndTerminate(0);
   if ( PeekMessageA(&pArcomageGame->msg, 0, 0, 0, PM_REMOVE) )
   {
     if ( pArcomageGame->msg.message == WM_QUIT )
-      Game_DeinitializeAndTerminate(0);
+      Engine_DeinitializeAndTerminate(0);
     TranslateMessage(&pArcomageGame->msg);
     DispatchMessageA(&pArcomageGame->msg);
   }
   /*if (pAsyncMouse)
   {
-    EnterCriticalSection(&pGame->pThreadWardInstance->csAsyncMouse);
+    EnterCriticalSection(&pEngine->pThreadWardInstance->csAsyncMouse);
     v4 = *((unsigned int *)pAsyncMouse + 7);
     pArcomageGame->mouse_x = *((unsigned int *)pAsyncMouse + 6);
     pArcomageGame->mouse_y = v4;
@@ -596,7 +595,7 @@
     pAsyncMouse->_46B944();
     if ( !*((unsigned char *)pAsyncMouse + 90) )
       pArcomageGame->field_F6 = 1;
-    LeaveCriticalSection(&pGame->pThreadWardInstance->csAsyncMouse);
+    LeaveCriticalSection(&pEngine->pThreadWardInstance->csAsyncMouse);
   }*/
   memcpy(v2, &pArcomageGame->stru1, 0xCu);
   return pArcomageGame->stru1.field_0 != 0;
--- a/Build/Visual Studio 2013/World of Might and Magic.vcxproj	Sat May 09 12:55:58 2015 +0200
+++ b/Build/Visual Studio 2013/World of Might and Magic.vcxproj	Sun May 10 01:29:11 2015 +0200
@@ -93,8 +93,8 @@
     <ClCompile Include="..\..\Arcomage\Arcomage.cpp" />
     <ClCompile Include="..\..\Arcomage\ArcomageCards.cpp" />
     <ClCompile Include="..\..\Engine\Conditions.cpp" />
+    <ClCompile Include="..\..\Engine\Engine.cpp" />
     <ClCompile Include="..\..\Engine\Events.cpp" />
-    <ClCompile Include="..\..\Engine\Game.cpp" />
     <ClCompile Include="..\..\Engine\Graphics\BSPModel.cpp" />
     <ClCompile Include="..\..\Engine\Graphics\DecalBuilder.cpp" />
     <ClCompile Include="..\..\Engine\Graphics\DecorationList.cpp" />
@@ -151,6 +151,8 @@
     <ClCompile Include="..\..\Engine\TurnEngine\TurnEngine.cpp" />
     <ClCompile Include="..\..\Engine\VectorTypes.cpp" />
     <ClCompile Include="..\..\Engine\ZlibWrapper.cpp" />
+    <ClCompile Include="..\..\Game\Game.cpp" />
+    <ClCompile Include="..\..\Game\MainMenu.cpp" />
     <ClCompile Include="..\..\GUI\GUIButton.cpp" />
     <ClCompile Include="..\..\GUI\GUIFont.cpp" />
     <ClCompile Include="..\..\GUI\GUIProgressBar.cpp" />
@@ -252,10 +254,10 @@
     <ClInclude Include="..\..\Engine\Autonotes.h" />
     <ClInclude Include="..\..\Engine\Awards.h" />
     <ClInclude Include="..\..\Engine\Conditions.h" />
+    <ClInclude Include="..\..\Engine\Engine.h" />
     <ClInclude Include="..\..\Engine\ErrorHandling.h" />
     <ClInclude Include="..\..\Engine\Events.h" />
     <ClInclude Include="..\..\Engine\Events2D.h" />
-    <ClInclude Include="..\..\Engine\Game.h" />
     <ClInclude Include="..\..\Engine\Graphics\BSPModel.h" />
     <ClInclude Include="..\..\Engine\Graphics\DecalBuilder.h" />
     <ClInclude Include="..\..\Engine\Graphics\DecorationList.h" />
@@ -322,6 +324,8 @@
     <ClInclude Include="..\..\Engine\TurnEngine\TurnEngine.h" />
     <ClInclude Include="..\..\Engine\VectorTypes.h" />
     <ClInclude Include="..\..\Engine\ZlibWrapper.h" />
+    <ClInclude Include="..\..\Game\Game.h" />
+    <ClInclude Include="..\..\Game\MainMenu.h" />
     <ClInclude Include="..\..\GUI\GUIButton.h" />
     <ClInclude Include="..\..\GUI\GUIFont.h" />
     <ClInclude Include="..\..\GUI\GUIProgressBar.h" />
--- a/Build/Visual Studio 2013/World of Might and Magic.vcxproj.filters	Sat May 09 12:55:58 2015 +0200
+++ b/Build/Visual Studio 2013/World of Might and Magic.vcxproj.filters	Sun May 10 01:29:11 2015 +0200
@@ -109,6 +109,9 @@
     <Filter Include="Engine\Graphics\Shaders">
       <UniqueIdentifier>{740b8731-e3ff-44cb-b6c8-85a64c7cbfc0}</UniqueIdentifier>
     </Filter>
+    <Filter Include="Game">
+      <UniqueIdentifier>{23305bbc-fe74-4523-88b2-155ca91d86f3}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="..\..\lib\zlib\adler32.c">
@@ -438,9 +441,6 @@
     <ClCompile Include="..\..\Engine\Events.cpp">
       <Filter>Engine</Filter>
     </ClCompile>
-    <ClCompile Include="..\..\Engine\Game.cpp">
-      <Filter>Engine</Filter>
-    </ClCompile>
     <ClCompile Include="..\..\Engine\LOD.cpp">
       <Filter>Engine</Filter>
     </ClCompile>
@@ -571,6 +571,15 @@
     <ClCompile Include="..\..\Media\MediaPlayer.cpp">
       <Filter>Media</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\Game\Game.cpp">
+      <Filter>Game</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\Game\MainMenu.cpp">
+      <Filter>Game</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\Engine\Engine.cpp">
+      <Filter>Engine</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\lib\libavcodec\avcodec.h">
@@ -1167,9 +1176,6 @@
     <ClInclude Include="..\..\Engine\Events2D.h">
       <Filter>Engine</Filter>
     </ClInclude>
-    <ClInclude Include="..\..\Engine\Game.h">
-      <Filter>Engine</Filter>
-    </ClInclude>
     <ClInclude Include="..\..\Engine\LOD.h">
       <Filter>Engine</Filter>
     </ClInclude>
@@ -1315,6 +1321,15 @@
     <ClInclude Include="..\..\Media\MediaPlayer.h">
       <Filter>Media</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\Game\Game.h">
+      <Filter>Game</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\Engine\Engine.h">
+      <Filter>Engine</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\Game\MainMenu.h">
+      <Filter>Game</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\lib\OpenAL\lib\x86\avcodec-55.def">
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/Engine.cpp	Sun May 10 01:29:11 2015 +0200
@@ -0,0 +1,3691 @@
+
+
+#define _CRTDBG_MAP_ALLOC
+#include <stdlib.h>
+#include <crtdbg.h>
+
+#define _CRT_SECURE_NO_WARNINGS
+
+#include "Engine/Engine.h"
+
+#include "Arcomage\Arcomage.h"
+
+#include "Engine/Graphics/Vis.h"
+#include "Engine/Graphics/Weather.h"
+#include "Engine/Graphics/LightmapBuilder.h"
+#include "Engine/Graphics/DecalBuilder.h"
+#include "Engine/Graphics/ParticleEngine.h"
+#include "IO/Mouse.h"
+#include "IO/Keyboard.h"
+#include "Engine/Graphics/GammaControl.h"
+#include "stru6.h"
+#include "Engine/Graphics/stru9.h"
+#include "Engine/Graphics/stru10.h"
+
+#include "Engine/Party.h"
+#include "Engine/Graphics/Viewport.h"
+#include "Engine/Timer.h"
+#include "Engine/Graphics/Outdoor.h"
+#include "Engine/Graphics/Overlays.h"
+#include "Media/Audio/AudioPlayer.h"
+#include "Engine/LOD.h"
+#include "GUI/GUIWindow.h"
+#include "Engine/TurnEngine/TurnEngine.h"
+#include "Media/Video/Bink_Smacker.h"
+#include "Engine/Events.h"
+#include "Engine/OurMath.h"
+#include "Engine/texts.h"
+#include "GUI/GUIFont.h"
+#include "Engine/Graphics/Lights.h"
+#include "Engine/Spells/CastSpellInfo.h"
+#include "Engine/Tables/FrameTableInc.h"
+#include "Engine/Objects/Actor.h"
+#include "GUI/GUIProgressBar.h"
+#include "Engine/Objects/ObjectList.h"
+#include "Engine/Graphics/Level/Decoration.h"
+#include "Engine/Graphics/PaletteManager.h"
+#include "GUI/UI/UIHouses.h"
+#include "GUI/UI/UIShops.h"
+#include "GUI/UI/UIPartyCreation.h"
+#include "Engine/SaveLoad.h"
+#include "Engine/Objects/SpriteObject.h"
+#include "Engine/Graphics/Sprites.h"
+#include "Engine/Registry.h"
+#include "Engine/Objects/Chest.h"
+
+#include "GUI/UI/UIGame.h"
+
+#include "Engine/Graphics/DecorationList.h"
+#include "Engine/Tables/IconFrameTable.h"
+#include "Engine/Tables/PlayerFrameTable.h"
+#include "Engine/MapsLongTimer.h"
+#include "Engine/Tables/StorylineTextTable.h"
+#include "Engine/Tables/FactionTable.h"
+#include "Engine/stru123.h"
+#include "Engine/LuaVM.h"
+#include "Engine/Graphics/RenderD3D11.h"
+#include "Engine/MMT.h"
+#include "GUI/NewUI\MainMenu.h"
+
+#include "Game/Game.h"
+
+#include <direct.h>
+
+
+
+
+Engine *pEngine = nullptr;
+
+
+
+
+
+
+
+//----- (00466C40) --------------------------------------------------------
+const wchar_t *MENU_STATE_to_string(MENU_STATE m)
+{
+    switch (m)
+    {
+    case -1:                return L"-1";
+    case MENU_MAIN:         return L"MENU_MAIN";
+    case MENU_NEWGAME:      return L"MENU_NEWGAME";
+    case MENU_CREDITS:      return L"MENU_CREDITS";
+    case MENU_SAVELOAD:     return L"MENU_SAVELOAD";
+    case MENU_EXIT_GAME:    return L"MENU_EXIT_GAME";
+    case MENU_5:            return L"MENU_5";
+    case MENU_CREATEPARTY:  return L"MENU_CREATEPARTY";
+    case MENU_NAMEPANELESC: return L"MENU_NAMEPANELESC";
+    case MENU_CREDITSPROC:  return L"MENU_CREDITSPROC";
+    case MENU_LoadingProcInMainMenu: return L"MENU_LoadingProcInMainMenu";
+    case MENU_DebugBLVLevel:         return L"MENU_DebugBLVLevel";
+    case MENU_CREDITSCLOSE: return L"MENU_CREDITSCLOSE";
+    case MENU_MMT_MAIN_MENU: return L"MENU_MMT_MAIN_MENU";
+    default:                return L"unk";
+    };
+};
+
+
+void SetCurrentMenuID(MENU_STATE uMenu)
+{
+    sCurrentMenuID = uMenu;
+    Log::Warning(L"CurrentMenu = %s \n", MENU_STATE_to_string(uMenu));
+}
+
+//----- (00466CA0) --------------------------------------------------------
+MENU_STATE GetCurrentMenuID()
+{
+    return sCurrentMenuID;
+}
+
+
+
+//----- (00464761) --------------------------------------------------------
+void Engine_DeinitializeAndTerminate(int exitCode)
+{
+    SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
+    ResetCursor_Palettes_LODs_Level_Audio_SFT_Windows();
+    pEngine->Deinitialize();
+    pRenderer->Release();
+    delete window;
+    //if ( !DestroyWindow(hWnd) )
+    //  GetLastError();
+    exit(exitCode);
+}
+
+
+
+
+
+
+
+
+
+
+
+//----- (00435694) --------------------------------------------------------
+void Engine::ToggleFlags2(unsigned int uFlag)
+{
+    unsigned int v2; // eax@1
+
+    v2 = this->uFlags2;
+    if (v2 & uFlag)
+        this->uFlags2 = v2 & ~uFlag;
+    else
+        this->uFlags2 = uFlag | v2;
+}
+
+//----- (0044103C) --------------------------------------------------------
+void Engine::Draw()
+{
+    int v4; // edi@26
+
+    uFlags2 &= ~0x02;
+    if (pParty->_497FC5_check_party_perception_against_level())
+        uFlags2 |= 2;
+
+    pEngine->pIndoorCameraD3D->sRotationX = pParty->sRotationX;
+    pEngine->pIndoorCameraD3D->sRotationY = pParty->sRotationY;
+    pEngine->pIndoorCameraD3D->vPartyPos.x = pParty->vPosition.x - pParty->y_rotation_granularity * cosf(2 * pi_double * pParty->sRotationY / 2048.0);
+    pEngine->pIndoorCameraD3D->vPartyPos.y = pParty->vPosition.y - pParty->y_rotation_granularity * sinf(2 * pi_double * pParty->sRotationY / 2048.0);
+    pEngine->pIndoorCameraD3D->vPartyPos.z = pParty->vPosition.z + pParty->sEyelevel;//193, but real 353
+
+    //pIndoorCamera->Initialize2();
+    pIndoorCameraD3D->CalculateRotations(pParty->sRotationX, pParty->sRotationY);
+    pIndoorCameraD3D->CreateWorldMatrixAndSomeStuff();
+    pIndoorCameraD3D->_4374E8_ProllyBuildFrustrum();
+
+    if (pMovie_Track)
+    {
+        /*if ( !pRenderer->pRenderD3D )
+        {
+        pRenderer->BeginSceneD3D();
+        pMouse->DrawCursorToTarget();
+        pRenderer->DrawBillboards_And_MaybeRenderSpecialEffects_And_EndScene();
+        }*/
+    }
+    else
+    {
+        if (pParty->vPosition.x != pParty->vPrevPosition.x || pParty->sRotationY != pParty->sPrevRotationY || pParty->vPosition.y != pParty->vPrevPosition.y
+            || pParty->sRotationX != pParty->sPrevRotationX || pParty->vPosition.z != pParty->vPrevPosition.z || pParty->sEyelevel != pParty->sPrevEyelevel)
+            pParty->uFlags |= 2u;
+        pParty->vPrevPosition.x = pParty->vPosition.x;
+        pParty->vPrevPosition.y = pParty->vPosition.y;
+        pParty->vPrevPosition.z = pParty->vPosition.z;
+        //v0 = &pRenderer;
+        pParty->sPrevRotationY = pParty->sRotationY;
+        pParty->sPrevRotationX = pParty->sRotationX;
+
+        pParty->sPrevEyelevel = pParty->sEyelevel;
+        pRenderer->BeginSceneD3D();
+
+        //if ( !pRenderer->pRenderD3D )
+        //pMouse->DrawCursorToTarget();
+        if (!PauseGameDrawing() || viewparams->field_48 == 1)
+        {
+            //if ( pRenderer->pRenderD3D )
+            {
+                float v2 = (double)(((signed int)pMiscTimer->uTotalGameTimeElapsed >> 2) & 0x1F) * 0.032258064 * 6.0;
+                //v3 = v2 + 6.7553994e15;
+                //pRenderer->field_1036A8_bitmapid = LODWORD(v3);
+                pRenderer->hd_water_current_frame = floorf(v2 + 0.5f);
+            }
+
+            if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
+                pIndoor->Draw();
+            else if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
+                pOutdoor->Draw();
+            else
+                Error("Invalid level type: %u", uCurrentlyLoadedLevelType);
+
+            //if (pRenderer->pRenderD3D)
+            {
+                pDecalBuilder->DrawBloodsplats();
+                pEngine->pLightmapBuilder->DrawLightmapsType(2);
+            }
+        }
+        pRenderer->DrawBillboards_And_MaybeRenderSpecialEffects_And_EndScene();
+    }
+
+    //DEBUG: force redraw gui
+    viewparams->bRedrawGameUI = true;
+
+
+    pRenderer->BeginScene();
+    //if (pRenderer->pRenderD3D)
+    pMouse->DrawCursorToTarget();
+    if (pOtherOverlayList->bRedraw)
+        viewparams->bRedrawGameUI = true;
+    v4 = viewparams->bRedrawGameUI;
+    GameUI_Footer();
+    if (!viewparams->bRedrawGameUI)
+        GameUI_DrawRightPanelItems();
+    else
+    {
+        GameUI_DrawRightPanelFrames();
+        GameUI_Footer_2();
+        viewparams->bRedrawGameUI = false;
+    }
+    if (!pMovie_Track)//!pVideoPlayer->pSmackerMovie)
+    {
+        GameUI_DrawMinimap(488, 16, 625, 133, viewparams->uMinimapZoom, true);//redraw = pParty->uFlags & 2);
+        if (v4)
+        {
+            if (!PauseGameDrawing() /*&& pRenderer->pRenderD3D*/) // clear game viewport with transparent color
+                pRenderer->FillRectFast(pViewport->uViewportTL_X, pViewport->uViewportTL_Y, pViewport->uViewportBR_X - pViewport->uViewportTL_X,
+                pViewport->uViewportBR_Y - pViewport->uViewportTL_Y + 1,
+                0x7FF);
+            viewparams->field_48 = 0;
+        }
+    }
+
+    viewparams->bRedrawGameUI = pOtherOverlayList->bRedraw;
+    pOtherOverlayList->bRedraw = 0;
+
+    GameUI_DrawPartySpells();
+    if (v4 || pParty->pHirelings[0].evt_C || pParty->pHirelings[1].evt_C)
+        GameUI_DrawHiredNPCs();
+    GameUI_DrawPortraits(v4);
+    GameUI_DrawLifeManaBars();
+    GameUI_DrawCharacterSelectionFrame();
+    if (_44100D_should_alter_right_panel())
+        GameUI_DrawRightPanel();
+    if (!pMovie_Track)
+    {
+        pStru6Instance->DrawPlayerBuffAnims();
+        pOtherOverlayList->DrawTurnBasedIcon(v4);
+        GameUI_DrawTorchlightAndWizardEye();
+    }
+
+
+    static bool render_framerate = false;
+    static float framerate = 0.0f;
+    static uint frames_this_second = 0;
+    static uint last_frame_time = GetTickCount();
+    static uint framerate_time_elapsed = 0;
+
+    if (current_screen_type == SCREEN_GAME && uCurrentlyLoadedLevelType == LEVEL_Outdoor)
+        pWeather->Draw();//Ritor1: my include
+
+    //while(GetTickCount() - last_frame_time < 33 );//FPS control 
+    uint frame_dt = GetTickCount() - last_frame_time;
+    last_frame_time = GetTickCount();
+
+    framerate_time_elapsed += frame_dt;
+    if (framerate_time_elapsed >= 1000)
+    {
+        framerate = frames_this_second *  (1000.0f / framerate_time_elapsed);
+
+        framerate_time_elapsed = 0;
+        frames_this_second = 0;
+        render_framerate = true;
+    }
+
+    ++frames_this_second;
+
+    if (debug_information)
+    {
+        if (render_framerate)
+        {
+            sprintf(pTmpBuf.data(), "FPS: % .4f", framerate);
+            pPrimaryWindow->DrawText(pFontArrus, 494, 0, Color16(0, 0, 0), pTmpBuf.data(), 0, 0, 0);
+        }
+
+        if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
+        {
+            int sector_id = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
+            sprintf(pTmpBuf.data(), "Party Sector ID:        %u/%u\n", sector_id, pIndoor->uNumSectors);
+            pPrimaryWindow->DrawText(pFontArrus, 16, 16, Color16(255, 255, 255), pTmpBuf.data(), 0, 0, Color16(255, 255, 255));
+        }
+        sprintf(pTmpBuf.data(), "Party Position:         % d % d % d", pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
+        pPrimaryWindow->DrawText(pFontArrus, 16, 16 + 16, Color16(255, 255, 255), pTmpBuf.data(), 0, 0, Color16(255, 255, 255));
+
+        if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
+        {
+            uint uFaceID;
+            int sector_id = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
+            int floor_level = BLV_GetFloorLevel(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z + 40, sector_id, &uFaceID);
+            sprintf(pTmpBuf.data(), "BLV_GetFloorLevel: %d   face_id %d\n", floor_level, uFaceID);
+        }
+        else
+        {
+            int on_water, _a6;
+            int floor_level = ODM_GetFloorLevel(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z, 0, &on_water, &_a6, false);
+            sprintf(pTmpBuf.data(), "ODM_GetFloorLevel: %d   on_water: %s    a6 = %d\n", floor_level, on_water ? "true" : "false", _a6);
+        }
+        pPrimaryWindow->DrawText(pFontArrus, 16, 16 + 16 + 16, Color16(255, 255, 255), pTmpBuf.data(), 0, 0, Color16(255, 255, 255));
+    }
+
+    GUI_UpdateWindows();
+    pParty->UpdatePlayersAndHirelingsEmotions();
+
+    _unused_5B5924_is_travel_ui_drawn = false;
+    if (v4)
+        pMouse->bRedraw = true;
+    pMouse->ReadCursorWithItem();
+    pMouse->DrawCursor();
+    pMouse->Activate();
+    pRenderer->EndScene();
+    pRenderer->Present();
+    pParty->uFlags &= ~2;
+}
+
+//----- (0047A815) --------------------------------------------------------
+void Engine::DrawParticles()
+{
+    pParticleEngine->Draw();
+}
+
+
+//----- (0044F192) --------------------------------------------------------
+void Engine::PrepareBloodsplats()
+{
+    for (uint i = 0; i < uNumBloodsplats; ++i)
+    {
+        pBloodsplatContainer->AddBloodsplat(pBloodsplats[i].x, pBloodsplats[i].y, pBloodsplats[i].z,
+            pBloodsplats[i].radius, pBloodsplats[i].r, pBloodsplats[i].g, pBloodsplats[i].b);
+    }
+}
+
+
+//----- (0044F120) --------------------------------------------------------
+void Engine::PushStationaryLights(int a2)
+{
+    Game__StationaryLight* pLight;
+
+    for (int i = 0; i < uNumStationaryLights; ++i)
+    {
+        pLight = &pStationaryLights[i];
+        pStationaryLightsStack->AddLight(pLight->vPosition.x, pLight->vPosition.y, pLight->vPosition.z,
+            pLight->flt_18, pLight->vRGBColor.x, pLight->vRGBColor.y, pLight->vRGBColor.z, _4E94D0_light_type);
+    }
+}
+// 4E94D0: using guessed type char _4E94D0_light_type;
+
+//----- (0044F0FD) --------------------------------------------------------
+void Engine::_44F0FD()
+{
+    ToggleFlags(0x40u);
+
+    if (!(uFlags & 0x40))
+    {
+        uNumBloodsplats = 0;
+        field_E0C = 0;
+    }
+}
+
+//----- (0044F0D8) --------------------------------------------------------
+void Engine::ToggleFlags(uint uMask)
+{
+    if (uFlags & uMask)
+        uFlags &= ~uMask;
+    else
+        uFlags |= uMask;
+}
+
+
+//----- (0044F07B) --------------------------------------------------------
+bool Engine::_44F07B()
+{
+    if (!pKeyboardInstance->IsKeyBeingHeld(VK_SHIFT) && !pKeyboardInstance->IsKeyBeingHeld(VK_LSHIFT) &&
+        !pKeyboardInstance->IsKeyBeingHeld(VK_LSHIFT) || (pKeyboardInstance->WasKeyPressed(VK_F11) == 0 &&
+        pKeyboardInstance->WasKeyPressed(VK_F11)))
+        return true;
+    return false;
+}
+
+//----- (0044EEA7) --------------------------------------------------------
+bool Engine::_44EEA7()
+{
+    //Game *v1; // esi@1
+    //double v2; // st7@2
+    float depth; // ST00_4@9
+    //bool result; // eax@9
+    //unsigned int v5; // eax@14
+    __int64 v6; // kr00_8@21
+    //unsigned int y; // [sp+4h] [bp-24h]@2
+    //unsigned int x; // [sp+8h] [bp-20h]@2
+    Vis_SelectionFilter *v10; // [sp+10h] [bp-18h]@2
+    Vis_SelectionFilter *v11; // [sp+14h] [bp-14h]@2
+    POINT cursor; // [sp+20h] [bp-8h]@1
+
+    //v1 = this;
+    ++qword_5C6DF0;
+    pParticleEngine->UpdateParticles();
+    pMouseInstance->GetCursorPos(&cursor);
+
+    //x = cursor.y;
+    //y = cursor.x;
+    if (sub_4637E0_is_there_popup_onscreen())
+    {
+        v11 = &vis_face_filter;
+        v10 = &vis_sprite_filter_2;
+        depth = pEngine->pIndoorCameraD3D->GetPickDepth();
+    }
+    else
+    {
+        if (uFlags2 & GAME_FLAGS_2_TARGETING_MODE)
+        {
+            v11 = &vis_face_filter;
+            v10 = &vis_sprite_filter_1;
+        }
+        else
+        {
+            v11 = &vis_face_filter;
+            v10 = &vis_sprite_filter_4;
+        }
+        depth = 5120.0;
+    }
+    //depth = v2;
+
+    PickMouse(depth, cursor.x, cursor.y, false, v10, v11);
+    pLightmapBuilder->std__vector_000004_size = 0;
+    pLightmapBuilder->std__vector_183808_size = 0;
+    pDecalBuilder->std__vector_pDecals_size = 0;
+    pDecalBuilder->field_308008 = 0;
+    if (!_44F07B())
+        return false;
+
+    if (uFlags & GAME_FLAGS_1_DRAW_BLV_DEBUGS)
+        pStru10Instance->bDoNotDrawPortalFrustum = false;
+    if ( /*pRenderer->pRenderD3D &&*/ uCurrentlyLoadedLevelType == LEVEL_Outdoor)
+        pRenderer->uFogColor = GetLevelFogColor() & 0xFFFFFF;
+    if (uFlags & 0x0400)
+        uFlags2 |= 0x01;
+    /*if ( !pRenderer->pRenderD3D && uCurrentlyLoadedLevelType == LEVEL_Outdoor && pMobileLightsStack->uNumLightsActive )
+    {
+    uFlags2 |= 0x01;
+    field_E10 = qword_5C6DF0;
+    }*/
+    v6 = qword_5C6DF0 - field_E10;
+    if (qword_5C6DF0 - field_E10 == 1)
+        uFlags2 |= v6;
+    if (uNumStationaryLights_in_pStationaryLightsStack != pStationaryLightsStack->uNumLightsActive)
+    {
+        uFlags2 |= 1;
+        uNumStationaryLights_in_pStationaryLightsStack = pStationaryLightsStack->uNumLightsActive;
+    }
+    return true;
+}
+
+
+//----- (0044EDE4) --------------------------------------------------------
+bool Engine::AlterGamma_BLV(BLVFace *pFace, signed int *pColor)
+{
+    if (uFlags2 & GAME_FLAGS_2_SATURATE_LIGHTMAPS &&
+        pFace->uAttributes & FACE_CAN_SATURATE_COLOR)
+    {
+        *pColor = ReplaceHSV(*pColor, 1.0, fSaturation, -1.0);
+        return true;
+    }
+    else
+        return false;
+}
+
+//----- (0044EE30) --------------------------------------------------------
+bool Engine::AlterGamma_ODM(ODMFace *pFace, signed int *pColor)
+{
+    if (uFlags2 & GAME_FLAGS_2_SATURATE_LIGHTMAPS &&
+        pFace->uAttributes & FACE_CAN_SATURATE_COLOR)
+    {
+        *pColor = ReplaceHSV(*pColor, 1.0, fSaturation, -1.0);
+        return true;
+    }
+    else
+        return false;
+}
+
+
+//----- (004645FA) --------------------------------------------------------
+void Engine::Deinitialize()
+{
+    WriteWindowsRegistryInt("startinwindow", 1);//pRenderer->bWindowMode);
+    //if (pRenderer->bWindowMode)
+    {
+        WriteWindowsRegistryInt("window X", window->GetX());
+        WriteWindowsRegistryInt("window Y", window->GetY());
+    }
+    WriteWindowsRegistryInt("valAlwaysRun", bAlwaysRun);
+    pItemsTable->Release();
+    pNPCStats->Release();
+
+    if (pMouse)
+        pMouse->Deactivate();
+
+    delete pRenderer;
+    pAudioPlayer->Release();//error
+    pNew_LOD->FreeSubIndexAndIO();
+    pGames_LOD->FreeSubIndexAndIO();
+    ClipCursor(0);
+    Engine::Destroy();
+    delete pEventTimer;
+}
+
+//----- (0044EE7C) --------------------------------------------------------
+bool Engine::draw_debug_outlines()
+{
+    if (uFlags & 0x04)
+    {
+        pLightmapBuilder->DrawDebugOutlines(-1);
+        pDecalBuilder->DrawDecalDebugOutlines();
+    }
+    return true;
+}
+
+//----- (0044EC23) --------------------------------------------------------
+int Engine::_44EC23(struct Polygon *a2, int *a3, signed int a4)
+{
+    double v4; // st7@4
+    //double v5; // ST00_8@4
+    signed int v6; // eax@5
+    //double v7; // ST00_8@6
+    signed int result; // eax@8
+    //double v9; // ST00_8@9
+    //double v10; // ST00_8@11
+    float a2a; // [sp+14h] [bp+8h]@4
+    float a3a; // [sp+18h] [bp+Ch]@4
+    float a3b; // [sp+18h] [bp+Ch]@6
+    float a4a; // [sp+1Ch] [bp+10h]@9
+    float a4b; // [sp+1Ch] [bp+10h]@11
+
+    if (this->uFlags2 & 2 && a2->field_59 == 5 && a2->pODMFace->uAttributes & 2)
+    {
+        v4 = (double)a4;
+        a2a = v4;
+        *a3 |= 2u;
+        a3a = (1.0 - this->fSaturation) * v4;
+        //v5 = a3a + 6.7553994e15;
+        //if ( SLODWORD(v5) >= 0 )
+        if (floorf(a3a + 0.5f) >= 0)
+        {
+            a3b = (1.0 - this->fSaturation) * a2a;
+            //v7 = a3b + 6.7553994e15;
+            //v6 = LODWORD(v7);
+            v6 = floorf(a3b + 0.5f);
+        }
+        else
+            v6 = 0;
+        if (a4 >= v6)
+        {
+            a4a = (1.0 - fSaturation) * a2a;
+            //v9 = a4a + 6.7553994e15;
+            //if ( SLODWORD(v9) >= 0 )
+            if (floorf(a4a + 0.5f) >= 0)
+            {
+                a4b = (1.0 - fSaturation) * a2a;
+                //v10 = a4b + 6.7553994e15;
+                //result = LODWORD(v10);
+                result = floorf(a4b + 0.5f);
+            }
+            else
+                result = 0;
+        }
+        else
+            result = a4;
+    }
+    else
+        result = -1;
+    return result;
+}
+
+
+
+//----- (00465C8B) --------------------------------------------------------
+Engine *Engine::Create()
+{
+    return new Engine;
+}
+
+//----- (00465CF3) --------------------------------------------------------
+void Engine::Destroy()
+{
+    delete pEngine;
+    pEngine = nullptr;
+}
+
+//----- (0044ED0A) --------------------------------------------------------
+signed int Engine::_44ED0A(BLVFace *a2, int *a3, signed int a4)
+{
+    double v4; // st7@3
+    //double v5; // ST00_8@3
+    signed int v6; // eax@4
+    //double v7; // ST00_8@5
+    signed int result; // eax@7
+    //double v9; // ST00_8@8
+    //double v10; // ST00_8@10
+    float v11; // [sp+14h] [bp+8h]@3
+    float v12; // [sp+18h] [bp+Ch]@3
+    float v13; // [sp+18h] [bp+Ch]@5
+    float v14; // [sp+1Ch] [bp+10h]@8
+    float v15; // [sp+1Ch] [bp+10h]@10
+
+    if (this->uFlags2 & 2 && a2->uAttributes & 2)
+    {
+        v4 = (double)a4;
+        v11 = v4;
+        *a3 |= 2u;
+        v12 = (1.0 - this->fSaturation) * v4;
+        //v5 = v12 + 6.7553994e15;
+        if (floorf(v12 + 0.5f)/* SLODWORD(v5)*/ >= 0)
+        {
+            v13 = (1.0 - this->fSaturation) * v11;
+            //v7 = v13 + 6.7553994e15;
+            //v6 = LODWORD(v7);
+            v6 = floorf(v13 + 0.5f);
+        }
+        else
+            v6 = 0;
+        if (a4 >= v6)
+        {
+            v14 = (1.0 - fSaturation) * v11;
+            //v9 = v14 + 6.7553994e15;
+            if (floorf(v14 + 0.5f)/* SLODWORD(v9)*/ >= 0)
+            {
+                v15 = (1.0 - fSaturation) * v11;
+                //v10 = v15 + 6.7553994e15;
+                //result = LODWORD(v10);
+                result = floorf(v15 + 0.5f);
+            }
+            else
+                result = 0;
+        }
+        else
+            result = a4;
+    }
+    else
+        result = -1;
+    return result;
+}
+
+
+//----- (0044E4B7) --------------------------------------------------------
+Engine::Engine()
+{
+    uNumStationaryLights = 0;
+    uNumBloodsplats = 0;
+    field_E0C = 0;
+    field_E10 = 0;
+    uNumStationaryLights_in_pStationaryLightsStack = 0;
+    uFlags = 0;
+    uFlags2 = 0;
+
+    //pThreadWardInstance = new ThreadWard;
+    pThreadWardInstance = nullptr;
+    pParticleEngine = new ParticleEngine;
+    pMouse = pMouseInstance = new Mouse;
+    pLightmapBuilder = new LightmapBuilder;
+    pVisInstance = new Vis;
+    pStru6Instance = new stru6;
+    pIndoorCameraD3D = new IndoorCameraD3D;
+    pStru9Instance = new stru9;
+    pStru10Instance = new stru10;
+    //pStru11Instance = new stru11;
+    pStru11Instance = nullptr;
+    //pStru12Instance = new stru12(pStru11Instance);
+    pStru12Instance = nullptr;
+    //pCShow = new CShow;
+    pCShow = nullptr;
+    pKeyboardInstance = new Keyboard;
+    //pGammaController = new GammaController;
+
+    uFlags |= 0x0800;
+    uFlags2 |= 0x24;
+
+    _44F0FD();
+}
+
+//----- (0044E7F3) --------------------------------------------------------
+Engine::~Engine()
+{
+    //delete pGammaController;
+    delete pKeyboardInstance;
+    /*delete pCShow;
+    delete pStru12Instance;
+    delete pStru11Instance;*/
+    delete pStru10Instance;
+    delete pStru9Instance;
+    delete pIndoorCameraD3D;
+    delete pStru6Instance;
+    delete pVisInstance;
+    delete pLightmapBuilder;
+    delete pMouseInstance;
+    delete pParticleEngine;
+    //delete pThreadWardInstance;
+}
+
+//----- (0044EA5E) --------------------------------------------------------
+bool Engine::PickMouse(float fPickDepth, unsigned int uMouseX, unsigned int uMouseY, bool bOutline, Vis_SelectionFilter *sprite_filter, Vis_SelectionFilter *face_filter)
+{
+    /*if (current_screen_type != SCREEN_GAME|| !pRenderer->pRenderD3D)
+    return false;*/
+
+    if (!pVisInstance)
+    {
+        MessageBoxW(nullptr, L"The 'Vis' object pointer has not been instatiated, but CGame::Pick() is trying to call through it.", nullptr, 0);
+        return false;
+    }
+
+    if (uMouseX >= (signed int)pViewport->uScreen_TL_X &&
+        uMouseX <= (signed int)pViewport->uScreen_BR_X &&
+        uMouseY >= (signed int)pViewport->uScreen_TL_Y &&
+        uMouseY <= (signed int)pViewport->uScreen_BR_Y)
+    {
+        pVisInstance->PickMouse(fPickDepth, uMouseX, uMouseY, sprite_filter, face_filter);
+
+        if (bOutline)
+            OutlineSelection();
+    }
+
+    return true;
+}
+// 4E28F8: using guessed type int current_screen_type;
+
+//----- (0044EB12) --------------------------------------------------------
+bool Engine::PickKeyboard(bool bOutline, Vis_SelectionFilter *sprite_filter, Vis_SelectionFilter *face_filter)
+{
+    if (current_screen_type == SCREEN_GAME && pVisInstance /*&& pRenderer->pRenderD3D*/)
+    {
+        bool r = pVisInstance->PickKeyboard(&pVisInstance->default_list, sprite_filter, face_filter);
+
+        if (bOutline)
+            OutlineSelection();
+        return r;
+    }
+    return false;
+}
+/*
+Result::Code Game::PickKeyboard(bool bOutline, struct unnamed_F93E6C *a3, struct unnamed_F93E6C *a4)
+{
+if (dword_4E28F8_PartyCantJumpIfTrue)
+return Result::Generic;
+
+pVis->PickKeyboard(a3, a4);
+if (bOutline)
+Game_outline_selection((int)this);
+return Result::Success;
+}
+*/
+// 4E28F8: using guessed type int current_screen_type;
+
+//----- (0044EB5A) --------------------------------------------------------
+void Engine::OutlineSelection()
+{
+    if (!pVisInstance)
+        return;
+
+    if (!pVisInstance->default_list.uNumPointers)
+        return;
+
+    Vis_ObjectInfo* object_info = pVisInstance->default_list.object_pointers[0];
+    if (object_info)
+        switch (object_info->object_type)
+    {
+        case VisObjectType_Sprite:
+        {
+            Log::Warning(L"Sprite outline currently unsupported");
+            return;
+        }
+
+        case VisObjectType_Face:
+        {
+            if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
+            {
+                ODMFace* face = (ODMFace *)object_info->object;
+                if (face->uAttributes & FACE_OUTLINED)
+                    face->uAttributes &= ~FACE_OUTLINED;
+                else
+                    face->uAttributes |= FACE_OUTLINED;
+            }
+            else if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
+            {
+                BLVFace* face = (BLVFace *)object_info->object;
+                if (face->uAttributes & FACE_OUTLINED)
+                    face->uAttributes &= ~FACE_OUTLINED;
+                else
+                    face->uAttributes |= FACE_OUTLINED;
+            }
+            else
+                Error("Invalid level type", uCurrentlyLoadedLevelType);
+        }
+            break;
+
+        default:
+        {
+            MessageBoxW(nullptr, L"Undefined CObjectInfo type requested in CGame::outline_selection()", nullptr, 0);
+            ExitProcess(0);
+        }
+    }
+}
+
+
+
+
+
+//----- (0042FBDD) --------------------------------------------------------
+void  sub_42FBDD()
+{
+    pAudioPlayer->PlaySound(SOUND_StartMainChoice02, 0, 0, -1, 0, 0, 0, 0);
+    pRenderer->DrawTextureIndexedAlpha(pBtn_YES->uX, pBtn_YES->uY, pBtn_YES->pTextures[0]);
+    pRenderer->Present();
+}
+
+//----- (0042FC15) --------------------------------------------------------
+void CloseWindowBackground()
+{
+    pAudioPlayer->PlaySound(SOUND_StartMainChoice02, -2, 0, -1, 0, 0, 0, 0);
+    pRenderer->DrawTextureIndexedAlpha(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, pBtn_ExitCancel->pTextures[0]);
+    pRenderer->Present();
+}
+
+
+//----- (0046BDC0) --------------------------------------------------------
+void  UpdateUserInput_and_MapSpecificStuff()
+{
+    if (dword_6BE364_game_settings_1 & GAME_SETTINGS_0080_SKIP_USER_INPUT_THIS_FRAME)
+    {
+        dword_6BE364_game_settings_1 &= ~GAME_SETTINGS_0080_SKIP_USER_INPUT_THIS_FRAME;
+        return;
+    }
+
+    if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
+        BLV_UpdateUserInputAndOther();
+    else if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
+        ODM_UpdateUserInputAndOther();
+
+    area_of_effect__damage_evaluate();
+}
+
+//----- (004646F0) --------------------------------------------------------
+void PrepareWorld(unsigned int _0_box_loading_1_fullscreen)
+{
+    //if ( pRenderer->pRenderD3D )
+    pEngine->pVisInstance->_4C1A02();
+    pEventTimer->Pause();
+    pMiscTimer->Pause();
+    pParty->uFlags = 2;
+    CastSpellInfoHelpers::_427D48();
+    ResetCursor_Palettes_LODs_Level_Audio_SFT_Windows();
+    DoPrepareWorld(0, (_0_box_loading_1_fullscreen == 0) + 1);
+    pMiscTimer->Resume();
+    pEventTimer->Resume();
+}
+
+//----- (00464866) --------------------------------------------------------
+void DoPrepareWorld(unsigned int bLoading, int _1_fullscreen_loading_2_box)
+{
+    char *v3; // eax@1
+    unsigned int v5; // eax@3
+    char Str1[20]; // [sp+Ch] [bp-18h]@1
+    unsigned int v9; // [sp+20h] [bp-4h]@1
+
+    v9 = bLoading;
+    ResetCursor_Palettes_LODs_Level_Audio_SFT_Windows();
+    pDecalBuilder->Reset(0);
+    pGameLoadingUI_ProgressBar->Initialize(_1_fullscreen_loading_2_box == 1 ? GUIProgressBar::TYPE_Fullscreen :
+        GUIProgressBar::TYPE_Box);
+    strcpy(Str1, pCurrentMapName);
+    v3 = strtok(Str1, ".");
+    strcpy(Str1, v3);
+    Level_LoadEvtAndStr(Str1);
+    LoadLevel_InitializeLevelEvt();
+    strcpy(Str1, pCurrentMapName);
+    _strrev(Str1);
+    strtok(Str1, ".");
+    _strrev(Str1);
+
+    for (uint i = 0; i < 1000; ++i)
+        pSpriteObjects[i].uObjectDescID = 0;
+
+    v5 = pMapStats->GetMapInfo(pCurrentMapName);
+    bUnderwater = false;
+    uLevelMapStatsID = v5;
+    pEngine->uFlags2 &= 0xFFFFFFF7u;
+    if (!_stricmp(pCurrentMapName, "out15.odm"))
+    {
+        bUnderwater = true;
+        pEngine->uFlags2 |= GAME_FLAGS_2_ALTER_GRAVITY;
+    }
+    pParty->floor_face_pid = 0;
+    if (_stricmp(Str1, "blv"))
+        PrepareToLoadODM(v9, 0);
+    else
+        PrepareToLoadBLV(v9);
+    pAudioPlayer->SetMapEAX();
+    _461103_load_level_sub();
+    if (!_stricmp(pCurrentMapName, "d11.blv") || !_stricmp(pCurrentMapName, "d10.blv"))
+    {
+        //spawning grounds & walls of mist - no loot & exp from monsters
+
+        for (uint i = 0; i < uNumActors; ++i)
+        {
+            pActors[i].pMonsterInfo.uTreasureType = 0;
+            pActors[i].pMonsterInfo.uTreasureDiceRolls = 0;
+            pActors[i].pMonsterInfo.uExp = 0;
+        }
+    }
+    bDialogueUI_InitializeActor_NPC_ID = 0;
+    OnMapLoad();
+    pGameLoadingUI_ProgressBar->Progress();
+    memset(&pRenderer->pBillboardRenderListD3D, 0, sizeof(pRenderer->pBillboardRenderListD3D));
+    pGameLoadingUI_ProgressBar->Release();
+    _flushall();
+}
+
+void IntegrityTest()
+{
+    static_assert(sizeof(MovieHeader) == 44, "Wrong type size");
+    static_assert(sizeof(SoundDesc_mm6) == 112, "Wrong type size");
+    static_assert(sizeof(SoundDesc) == 120, "Wrong type size");
+    static_assert(sizeof(OverlayDesc) == 8, "Wrong type size");
+    static_assert(sizeof(ChestDesc) == 36, "Wrong type size");
+    static_assert(sizeof(ObjectDesc_mm6) == 52, "Wrong type size");
+    static_assert(sizeof(ObjectDesc) == 56, "Wrong type size");
+    static_assert(sizeof(DecorationDesc) == 84, "Wrong type size");
+    static_assert(sizeof(IconFrame) == 32, "Wrong type size");
+    static_assert(sizeof(PlayerFrame) == 10, "Wrong type size");
+    static_assert(sizeof(TextureFrame) == 20, "Wrong type size");
+    static_assert(sizeof(SpriteFrame) == 60, "Wrong type size");
+    static_assert(sizeof(RenderVertexSoft) == 0x30, "Wrong type size");
+    static_assert(sizeof(RenderBillboard) == 0x34, "Wrong type size");
+    static_assert(sizeof(Texture) == 0x48, "Wrong type size");
+    //static_assert(sizeof(RGBTexture) == 0x28, "Wrong type size");
+    //static_assert(sizeof(LODFile_IconsBitmaps) == 0x11BB8 + 4, "Wrong type size"); // + virtual dtor ptr
+    static_assert(sizeof(AudioPlayer) == 0xC84, "Wrong type size");
+    static_assert(sizeof(SoundDesc) == 0x78, "Wrong type size");
+    static_assert(sizeof(stru339_spell_sound) == 0xAFD8, "Wrong type size");
+    //static_assert(sizeof(VideoPlayer) == 0x108 + 4, "Wrong type size");
+    static_assert(sizeof(MovieHeader) == 0x2C, "Wrong type size");
+    static_assert(sizeof(DecorationDesc) == 0x54, "Wrong type size");
+    static_assert(sizeof(ObjectDesc) == 0x38, "Wrong type size");
+    static_assert(sizeof(OverlayDesc) == 0x8, "Wrong type size");
+    static_assert(sizeof(ChestDesc) == 0x24, "Wrong type size");
+    static_assert(sizeof(TileDesc) == 0x1A, "Wrong type size");
+    static_assert(sizeof(MonsterDesc_mm6) == 148, "Wrong type size");
+    static_assert(sizeof(MonsterDesc) == 152, "Wrong type size");
+    static_assert(sizeof(Timer) == 0x28, "Wrong type size");
+    static_assert(sizeof(OtherOverlay) == 0x14, "Wrong type size");
+    static_assert(sizeof(ItemGen) == 0x24, "Wrong type size");
+    static_assert(sizeof(SpriteObject) == 0x70, "Wrong type size");
+    static_assert(sizeof(ItemDesc) == 0x30, "Wrong type size");
+    static_assert(sizeof(ItemsTable) == 0x117A0, "Wrong type size");
+    static_assert(sizeof(Chest) == 0x14CC, "Wrong type size");
+    static_assert(sizeof(MapInfo) == 0x44, "Wrong type size");
+    static_assert(sizeof(SpellInfo) == 0x24, "Wrong type size");
+    static_assert(sizeof(SpellData) == 0x14, "Wrong type size");
+    static_assert(sizeof(SpellBuff) == 0x10, "Wrong type size");
+    static_assert(sizeof(AIDirection) == 0x1C, "Wrong type size");
+    static_assert(sizeof(ActorJob) == 0xC, "Wrong type size");
+    static_assert(sizeof(Actor) == 0x344, "Wrong type size");
+    static_assert(sizeof(LevelDecoration) == 0x20, "Wrong type size");
+    static_assert(sizeof(KeyboardActionMapping) == 0x20C, "Wrong type size");
+    static_assert(sizeof(UIAnimation) == 0xD, "Wrong type size");
+    static_assert(sizeof(SpawnPointMM7) == 0x18, "Wrong type size");
+    static_assert(sizeof(ODMFace) == 0x134, "Wrong type size");
+    static_assert(sizeof(BSPNode) == 0x8, "Wrong type size");
+    static_assert(sizeof(BSPModel) == 0xBC, "Wrong type size");
+    static_assert(sizeof(OutdoorLocation) == 0x1C28C, "Wrong type size");
+    static_assert(sizeof(BLVFace) == 0x60, "Wrong type size");
+    static_assert(sizeof(BLVFaceExtra) == 0x24, "Wrong type size");
+    static_assert(sizeof(BLVSector) == 0x74, "Wrong type size");
+    static_assert(sizeof(BLVLightMM7) == 0x10, "Wrong type size");
+    static_assert(sizeof(BLVDoor) == 0x50, "Wrong type size");
+    static_assert(sizeof(IndoorLocation) == 0x690, "Wrong type size");
+    //static_assert(sizeof(ODMRenderParams) == 0x74, "Wrong type size");
+    static_assert(sizeof(Mouse) == 0x114, "Wrong type size");
+    static_assert(sizeof(Particle_sw) == 0x68, "Wrong type size");
+    static_assert(sizeof(Particle) == 0x68, "Wrong type size");
+    static_assert(sizeof(ParticleEngine) == 0xE430, "Wrong type size");
+    static_assert(sizeof(Lightmap) == 0xC1C, "Wrong type size");
+    static_assert(sizeof(LightmapBuilder) == 0x3CBC38, "Wrong type size");
+    static_assert(sizeof(Vis_SelectionList) == 0x2008, "Wrong type size");
+    static_assert(sizeof(Vis) == 0x20D0, "Wrong type size");
+    static_assert(sizeof(PlayerBuffAnim) == 0x10, "Wrong type size");
+    static_assert(sizeof(ProjectileAnim) == 0x1C, "Wrong type size");
+    static_assert(sizeof(stru6) == 0x5F8, "Wrong type size");
+    static_assert(sizeof(IndoorCameraD3D_Vec3) == 0x10, "Wrong type size");
+    static_assert(sizeof(IndoorCameraD3D_Vec4) == 0x18, "Wrong type size"); //should be 14 (10 vec3 + 4 vdtor)  but 18 coz of his +4 from own vdtor, but it is odd since vdtor already present from vec3
+    //static_assert(sizeof(IndoorCameraD3D) == 0x1A1384, "Wrong type size");
+    static_assert(sizeof(StationaryLight) == 0xC, "Wrong type size");
+    static_assert(sizeof(LightsStack_StationaryLight_) == 0x12C8, "Wrong type size");
+    static_assert(sizeof(MobileLight) == 0x12, "Wrong type size");
+    static_assert(sizeof(LightsStack_MobileLight_) == 0x1C28, "Wrong type size");
+    static_assert(sizeof(Engine) == 0xE78, "Wrong type size");
+    static_assert(sizeof(stru141_actor_collision_object) == 0xA8, "Wrong type size");
+    static_assert(sizeof(ActionQueue) == 0x7C, "Wrong type size");
+    static_assert(sizeof(NPCData) == 0x4C, "Wrong type size");
+    static_assert(sizeof(NPCStats) == 0x17FFC, "Wrong type size");
+    static_assert(sizeof(BspRenderer) == 0x53740, "Wrong type size");
+    static_assert(sizeof(PaletteManager) == 0x267AF0, "Wrong type size");
+    static_assert(sizeof(ViewingParams) == 0x26C, "Wrong type size");
+    //static_assert(sizeof(IndoorCamera) == 0x50, "Wrong type size");
+    static_assert(sizeof(Bloodsplat) == 0x28, "Wrong type size");
+    static_assert(sizeof(BloodsplatContainer) == 0xA0C, "Wrong type size");
+    static_assert(sizeof(TrailParticle) == 0x18, "Wrong type size");
+    static_assert(sizeof(EventIndex) == 0xC, "Wrong type size");
+    static_assert(sizeof(_2devent) == 0x34, "Wrong type size");
+    static_assert(sizeof(MapsLongTimer) == 0x20, "Wrong type size");
+    static_assert(sizeof(SavegameHeader) == 0x64, "Wrong type size");
+    static_assert(sizeof(SavegameList) == 0x3138, "Wrong type size");
+    static_assert(sizeof(StorylineText) == 0x160, "Wrong type size");
+    static_assert(sizeof(FactionTable) == 0x1EF1, "Wrong type size");
+    static_assert(sizeof(Decal) == 0xC20, "Wrong type size");
+    static_assert(sizeof(DecalBuilder) == 0x30C038, "Wrong type size");
+    static_assert(sizeof(MonsterInfo) == 0x58, "Wrong type size");
+    static_assert(sizeof(MonsterStats) == 0x5BA0, "Wrong type size");
+    static_assert(sizeof(RenderD3D) == 0x148, "Wrong type size");
+    //  static_assert(sizeof(Render) == 0x129844, "Wrong type size");
+    static_assert(sizeof(Player) == 0x1B3C, "Wrong type size");
+    static_assert(sizeof(PartyTimeStruct) == 0x678, "Wrong type size");
+    static_assert(sizeof(Party) == 0x16238, "Wrong type size");
+    static_assert(sizeof(GUIButton) == 0xBC, "Wrong type size");
+    static_assert(sizeof(GUIWindow) == 0x54, "Wrong type size");
+    //static_assert(sizeof(GUIProgressBar) == 0x1B8, "Wrong type size");
+    static_assert(sizeof(GUIFont) == 0x1020, "Wrong type size");
+    // static_assert(sizeof(stru262_TurnBased) == 0x40, "Wrong type size");
+    //static_assert(sizeof(ArcomageGame) == 0xFB, "Wrong type size");
+    static_assert(sizeof(CastSpellInfo) == 0x14, "Wrong type size");
+    static_assert(sizeof(ArcomageCard) == 0x6C, "Wrong type size");
+    static_assert(sizeof(stru320) == 0x3FC, "Wrong type size");
+    static_assert(sizeof(TravelInfo) == 0x20, "Wrong type size");
+    static_assert(sizeof(stru336) == 0x798, "Wrong type size");
+    static_assert(sizeof(Vec3_short_) == 6, "Wrong type size");
+    static_assert(sizeof(BLVFace) == 96, "Wrong type size");
+    static_assert(sizeof(BLVFaceExtra) == 36, "Wrong type size");
+    static_assert(sizeof(BLVSector) == 116, "Wrong type size");
+    static_assert(sizeof(LevelDecoration) == 32, "Wrong type size");
+    static_assert(sizeof(BLVLightMM7) == 16, "Wrong type size");
+    static_assert(sizeof(BSPNode) == 8, "Wrong type size");
+    static_assert(sizeof(SpawnPointMM7) == 24, "Wrong type size");
+    static_assert(sizeof(DDM_DLV_Header) == 40, "Wrong type size");
+    static_assert(sizeof(Actor) == 836, "Wrong type size");
+    static_assert(sizeof(SpriteObject) == 112, "Wrong type size");
+    static_assert(sizeof(Chest) == 5324, "Wrong type size");
+    static_assert(sizeof(stru123) == 0xC8, "Wrong type size");
+    static_assert(sizeof(BLVMapOutline) == 12, "Wrong type size");
+    static_assert(sizeof(LODSprite) == 0x28, "Wrong type size");
+}
+
+
+//----- (004647AB) --------------------------------------------------------
+void FinalInitialization()
+{
+    pViewport->SetScreen(viewparams->uSomeX, viewparams->uSomeY, viewparams->uSomeZ, viewparams->uSomeW);
+    pViewport->SetFOV(flt_6BE3A0 * 65536.0f);
+
+    //pIndoorCamera = new IndoorCamera;
+    //pIndoorCamera->Initialize(65, viewparams->uScreen_BttmR_X - viewparams->uScreen_topL_X + 1,
+    //                              viewparams->uScreen_BttmR_Y - viewparams->uScreen_topL_Y + 1);
+
+    InitializeTurnBasedAnimations(&stru_50C198);
+    pBitmaps_LOD->_inlined_sub1();
+    pSprites_LOD->_inlined_sub1();
+    pIcons_LOD->_inlined_sub1();
+}
+// 6BE3A0: using guessed type float flt_6BE3A0;
+
+
+
+//----- (00464E17) --------------------------------------------------------
+bool __fastcall CheckMM7CD(char c)
+{
+    char DstBuf[256] = { 0 };
+    char strCommand[256] = { 0 }; // [sp+10Ch] [bp-118h]@1
+    char Filename[20] = { 0 }; // [sp+20Ch] [bp-18h]@1
+
+    wchar_t pMagicPath[1024];
+    swprintf(pMagicPath, wcslen(L"%C:\\anims\\magic7.vid"), L"%C:\\anims\\magic7.vid", c);
+    if (GetFileAttributesW(pMagicPath) == -1)
+        return false;
+
+    //Open CD audio
+    wsprintfA(strCommand, "open %c: type cdaudio alias CD", c);
+    if (!mciSendStringA(strCommand, DstBuf, 255, 0))
+    {
+        wsprintfA(strCommand, "info CD UPC wait");
+        mciSendStringA(strCommand, DstBuf, 255, 0);
+        wsprintfA(strCommand, "close CD");
+        mciSendStringA(strCommand, DstBuf, 255, 0);
+    }
+
+    memcpy(Filename, "X:\\anims\\magic7.vid", sizeof(Filename));
+    *Filename = c;
+
+    FILE* f = fopen(Filename, "rb");
+    if (!f)
+        return false;
+
+    if (!fseek(f, 0, SEEK_END))
+    {
+        if (!fseek(f, -100, SEEK_CUR))
+            fread(DstBuf, 1, 0x64u, f);
+
+        fclose(f);
+        return true;
+    }
+    fclose(f);
+    return false;
+}
+
+//----- (00464F1B) --------------------------------------------------------
+signed int __stdcall InsertMM7CDDialogFunc(HWND hDlg, int a2, __int16 a3, int a4)
+{
+    char v4; // zf@3
+    int v6; // eax@10
+    int v7; // eax@11
+    int v8; // eax@12
+    int v9; // eax@13
+    BOOL(__stdcall *v10)(HWND, int, LPCSTR); // edi@15
+    const CHAR *v11; // [sp-Ch] [bp-Ch]@15
+    INT_PTR v12; // [sp-4h] [bp-4h]@5
+
+    if (a2 == 272)
+    {
+        hInsertCDWindow = hDlg;
+        v6 = (GetUserDefaultLangID() & 0x3FF) - 7;
+        if (v6)
+        {
+            v7 = v6 - 3;
+            if (v7)
+            {
+                v8 = v7 - 2;
+                if (v8)
+                {
+                    v9 = v8 - 4;
+                    if (v9)
+                    {
+                        if (v9 != 5)
+                            return 0;
+                        SetWindowTextA(hDlg, "Wloz CD-ROM numer 2");
+                        v10 = SetDlgItemTextA;
+                        SetDlgItemTextA(hDlg, 1010, "Wloz CD-ROM numer 2 Might and Magic® VII.");
+                        v11 = "Odwolaj";
+                    }
+                    else
+                    {
+                        SetWindowTextA(hDlg, "Inserire il secondo CD");
+                        v10 = SetDlgItemTextA;
+                        SetDlgItemTextA(hDlg, 1010, "Inserire il secondo CD di Might and Magic® VII.");
+                        v11 = "Annulla";
+                    }
+                }
+                else
+                {
+                    SetWindowTextA(hDlg, "Insérez le CD 2");
+                    v10 = SetDlgItemTextA;
+                    SetDlgItemTextA(hDlg, 1010, "Insérez Might & Magic® VII CD 2.");
+                    v11 = "Supprimer";
+                }
+            }
+            else
+            {
+                SetWindowTextA(hDlg, "Por favor, inserte disco 2");
+                v10 = SetDlgItemTextA;
+                SetDlgItemTextA(hDlg, 1010, "Por favor, inserte disco 2 de Might & Magic® VII.");
+                v11 = "Cancelar";
+            }
+        }
+        else
+        {
+            SetWindowTextA(hDlg, "Bitte CD 2 einlegen");
+            v10 = SetDlgItemTextA;
+            SetDlgItemTextA(hDlg, 1010, "Bitte CD 2 von Might and Magic® VII einlegen.");
+            v11 = "Abbrechen";
+        }
+        v10(hDlg, 2, v11);
+        return 0;
+    }
+    if (a2 == 273)
+    {
+        if (a3 == 2)
+        {
+            v12 = 0;
+            EndDialog(hDlg, v12);
+            return 1;
+        }
+        v4 = a3 == 1;
+    }
+    else
+    {
+        v4 = a2 == 1025;
+    }
+    if (v4)
+    {
+        v12 = 1;
+        EndDialog(hDlg, v12);
+        return 1;
+    }
+    return 0;
+}
+
+//----- (00465061) --------------------------------------------------------
+bool __fastcall FindMM7CD(HWND hWnd, char *pCDDrive)
+{
+    char drive[4] = { 'X', ':', '\\', 0 };
+
+    bool bGotCDFromRegistry = false;
+
+    HKEY hSoftware = nullptr,
+        hNWC = nullptr,
+        hMM7 = nullptr,
+        hVersion = nullptr;
+    if (!RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, KEY_READ | KEY_WOW64_32KEY, &hSoftware))
+    {
+        if (!RegOpenKeyExA(hSoftware, "New World Computing", 0, KEY_READ | KEY_WOW64_32KEY, &hNWC))
+        {
+            if (!RegOpenKeyExA(hNWC, "Might and Magic VII", 0, KEY_READ | KEY_WOW64_32KEY, &hMM7))
+            {
+                if (!RegOpenKeyExA(hMM7, "1.0", 0, KEY_READ | KEY_WOW64_32KEY, &hVersion))
+                {
+                    DWORD cbData = 3;
+                    if (!RegQueryValueExA(hVersion, "CDDrive", 0, 0, (BYTE *)drive, &cbData))
+                        bGotCDFromRegistry = true;
+                }
+                RegCloseKey(hVersion);
+            }
+            RegCloseKey(hMM7);
+        }
+        RegCloseKey(hNWC);
+    }
+    RegCloseKey(hSoftware);
+
+    if (bGotCDFromRegistry)
+        if (CheckMM7CD(*drive))
+        {
+        cMM7GameCDDriveLetter = *drive;
+        return true;
+        }
+
+    while (true)
+    {
+        for (uint i = 0; i < 26; ++i)
+        {
+            drive[0] = 'A' + i;
+
+            if (GetDriveTypeA(drive) == DRIVE_CDROM)
+                if (CheckMM7CD(*drive))
+                {
+                cMM7GameCDDriveLetter = *drive;
+                WriteWindowsRegistryString("CDDrive", drive);
+                return true;
+                }
+        }
+
+        if (DialogBoxParamA(GetModuleHandleW(nullptr), "InsertCD", hWnd, (DLGPROC)InsertMM7CDDialogFunc, 0))
+            continue;
+        return false;
+    }
+}
+
+//----- (004651F4) --------------------------------------------------------
+bool MM7_Initialize(int game_width, int game_height)
+{
+    wchar_t pCurrentDir[1024];
+    _wgetcwd(pCurrentDir, 1024);
+
+    wchar_t pMM6IniFile[1024];
+    wsprintfW(pMM6IniFile, L"%s\\mm6.ini", pCurrentDir);
+
+    bCanLoadFromCD = GetPrivateProfileIntW(L"settings", L"use_cd", 1, pMM6IniFile);
+    if (bNoCD)
+        bCanLoadFromCD = false;
+    if (bCanLoadFromCD)
+    {
+        Log::Warning(L"Checking for CD...");
+        if (!FindMM7CD(nullptr, &cMM7GameCDDriveLetter))
+            return false;
+        Log::Warning(L"...done.");
+    }
+
+
+    srand(GetTickCount());
+
+    pEventTimer = Timer::Create();
+    pEventTimer->Initialize();
+    window = OSWindow::Create(L"Might and Magic® Trilogy", game_width, game_height);//Create  game window
+
+    bool use_d3d11 = false;
+    if (use_d3d11)
+        pRenderer = RenderD3D11::Create();
+    else
+        pRenderer = Render::Create();//Create DirectX
+    if (!pRenderer)
+    {
+        Log::Warning(L"Render creation failed");
+        return false;
+    }
+    else
+    {
+        //bool bWindowMode = ReadWindowsRegistryInt("startinwindow", false);
+        //uint uDefaultDevice = ReadWindowsRegistryInt("D3D Device", 1);
+
+        if (!pRenderer->Initialize(window/*, bColoredLights, uLevelOfDetail, bTinting*/))
+        {
+            Log::Warning(L"Render failed to initialize");
+            return false;
+        }
+    }
+
+    game_starting_year = 1168;
+
+    pParty = new Party;
+    memset(&pParty->pHirelings, 0, sizeof(pParty->pHirelings));
+    pParty->uWalkSpeed = GetPrivateProfileIntW(L"debug", L"walkspeed", 384, pMM6IniFile);
+    pParty->uDefaultEyelevel = GetPrivateProfileIntW(L"party", L"eyelevel", 160, pMM6IniFile);
+    pParty->sEyelevel = pParty->uDefaultEyelevel;
+    pParty->uDefaultPartyHeight = GetPrivateProfileIntW(L"party", L"height", 192, pMM6IniFile);
+    pParty->uPartyHeight = pParty->uDefaultPartyHeight;
+
+    MM6_Initialize(pMM6IniFile);
+
+    pKeyActionMap = new KeyboardActionMapping;
+
+    OnTimer(1);
+    GameUI_StatusBar_UpdateTimedString(1);
+    pEngine = Engine::Create();
+    pMouse = pEngine->pMouseInstance;
+
+
+    pIcons_LOD = new LODFile_IconsBitmaps;
+    if (!pIcons_LOD->Load("data\\icons.lod", "icons"))
+    {
+        MessageBoxW(nullptr, L"Some files are missing\n\nPlease Reinstall.",
+            L"Files Missing", MB_ICONEXCLAMATION);
+        return false;
+    }
+    pIcons_LOD->dword_011BA4 = 0;
+
+    pEvents_LOD = new LODFile_IconsBitmaps;
+    if (!pEvents_LOD->Load("data\\events.lod", "icons"))
+    {
+        MessageBoxW(nullptr, L"Some files are missing\n\nPlease Reinstall.",
+            L"Files Missing", MB_ICONEXCLAMATION);
+        return false;
+    }
+
+    InitializeGameText();
+
+    pBitmaps_LOD = new LODFile_IconsBitmaps;
+    if (!pBitmaps_LOD->Load("data\\bitmaps.lod", "bitmaps"))
+    {
+        MessageBoxA(nullptr, pGlobalTXT_LocalizationStrings[63],
+            pGlobalTXT_LocalizationStrings[184], MB_ICONEXCLAMATION);
+        return false;
+    }
+
+    pSprites_LOD = new LODFile_Sprites;
+    if (!pSprites_LOD->LoadSprites("data\\sprites.lod"))
+    {
+        MessageBoxA(nullptr,
+            pGlobalTXT_LocalizationStrings[63],
+            pGlobalTXT_LocalizationStrings[184], MB_ICONEXCLAMATION);
+        return false;
+    }
+
+
+#if 0
+    if (_access("../MM_VI/data/icons.lod", 0) == 0)
+    {
+        pIcons_LOD_mm6 = new LODFile_IconsBitmaps;
+        if (!pIcons_LOD_mm6->Load("../MM_VI/data/icons.lod", "icons"))
+        {
+            delete pIcons_LOD_mm6;
+            pIcons_LOD_mm6 = nullptr;
+            Log::Warning(L"Unable to load mm6:icons.lod");
+        }
+    }
+    else
+        Log::Warning(L"Unable to find mm6:icons.lod");
+
+    if (_access("../MM_VI/data/bitmaps.lod", 0) == 0)
+    {
+        pBitmaps_LOD_mm6 = new LODFile_IconsBitmaps;
+        if (!pBitmaps_LOD_mm6->Load("../MM_VI/data/bitmaps.lod", "bitmaps"))
+        {
+            delete pBitmaps_LOD_mm6;
+            pBitmaps_LOD_mm6 = nullptr;
+            Log::Warning(L"Unable to load mm6:bitmaps.lod");
+        }
+    }
+    else
+        Log::Warning(L"Unable to find mm6:bitmaps.lod");
+
+    auto mm6_sprite_container_name = bUseLoResSprites ? "../MM_VI/data/spriteLO.lod"
+        : "../MM_VI/data/sprites.lod";
+    if (_access(mm6_sprite_container_name, 0) == 0)
+    {
+        pSprites_LOD_mm6 = new LODFile_Sprites;
+        if (!pSprites_LOD_mm6->LoadSprites(mm6_sprite_container_name))
+        {
+            delete pSprites_LOD_mm6;
+            pSprites_LOD_mm6 = nullptr;
+            Log::Warning(L"Unable to load mm6:sprites.lod");
+        }
+    }
+    else
+        Log::Warning(L"Unable to find mm6:sprites.lod");
+
+
+    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;
+        void *sft_mm7 = pEvents_LOD->LoadRaw("dsft.bin", 1);
+        pSpriteFrameTable = new SpriteFrameTable;
+        pSpriteFrameTable->FromFile(sft_mm6, sft_mm7, sft_mm8);
+        free(sft_mm6);
+        free(sft_mm7);
+        free(sft_mm8);
+
+        void *tft_mm6 = pIcons_LOD_mm6 ? pIcons_LOD_mm6->LoadRaw("dtft.bin", 1) : nullptr,
+            *tft_mm8 = nullptr;
+        void *tft_mm7 = pEvents_LOD->LoadRaw("dtft.bin", 1);
+        pTextureFrameTable = new TextureFrameTable;
+        pTextureFrameTable->FromFile(tft_mm6, tft_mm7, tft_mm8);
+        free(tft_mm6);
+        free(tft_mm7);
+        free(tft_mm8);
+
+        void *tiles_mm6 = pIcons_LOD_mm6 ? pIcons_LOD_mm6->LoadRaw("dtile.bin", 1) : nullptr,
+            *tiles_mm8 = nullptr;
+        void *tiles_mm7 = pEvents_LOD->LoadRaw("dtile.bin", 1);
+        pTileTable = new TileTable;
+        pTileTable->FromFile(tiles_mm6, tiles_mm7, tiles_mm8);
+        free(tiles_mm6);
+        free(tiles_mm7);
+        free(tiles_mm8);
+
+        void *pft_mm6 = pIcons_LOD_mm6 ? pIcons_LOD_mm6->LoadRaw("dpft.bin", 1) : nullptr,
+            *pft_mm8 = nullptr;
+        void *pft_mm7 = pEvents_LOD->LoadRaw("dpft.bin", 1);
+        pPlayerFrameTable = new PlayerFrameTable;
+        pPlayerFrameTable->FromFile(pft_mm6, pft_mm7, pft_mm8);
+        free(pft_mm6);
+        free(pft_mm7);
+        free(pft_mm8);
+
+        void *ift_mm6 = pIcons_LOD_mm6 ? pIcons_LOD_mm6->LoadRaw("dift.bin", 1) : nullptr,
+            *ift_mm8 = nullptr;
+        void *ift_mm7 = pEvents_LOD->LoadRaw("dift.bin", 1);
+        pIconsFrameTable = new IconFrameTable;
+        pIconsFrameTable->FromFile(ift_mm6, ift_mm7, ift_mm8);
+        free(ift_mm6);
+        free(ift_mm7);
+        free(ift_mm8);
+
+        void *decs_mm6 = pIcons_LOD_mm6 ? pIcons_LOD_mm6->LoadRaw("ddeclist.bin", 1) : nullptr,
+            *decs_mm8 = nullptr;
+        void *decs_mm7 = pEvents_LOD->LoadRaw("ddeclist.bin", 1);
+        pDecorationList = new DecorationList;
+        pDecorationList->FromFile(decs_mm6, decs_mm7, decs_mm8);
+        free(decs_mm6);
+        free(decs_mm7);
+        free(decs_mm8);
+
+        void *objs_mm6 = pIcons_LOD_mm6 ? pIcons_LOD_mm6->LoadRaw("dobjlist.bin", 1) : nullptr,
+            *objs_mm8 = nullptr;
+        void *objs_mm7 = pEvents_LOD->LoadRaw("dobjlist.bin", 1);
+        pObjectList = new ObjectList;
+        pObjectList->FromFile(objs_mm6, objs_mm7, objs_mm8);
+        free(objs_mm6);
+        free(objs_mm7);
+        free(objs_mm8);
+
+        void *mons_mm6 = pIcons_LOD_mm6 ? pIcons_LOD_mm6->LoadRaw("dmonlist.bin", 1) : nullptr,
+            *mons_mm8 = nullptr;
+        void *mons_mm7 = pEvents_LOD->LoadRaw("dmonlist.bin", 1);
+        pMonsterList = new MonsterList;
+        pMonsterList->FromFile(mons_mm6, mons_mm7, mons_mm8);
+        free(mons_mm6);
+        free(mons_mm7);
+        free(mons_mm8);
+
+        void *chests_mm6 = pIcons_LOD_mm6 ? pIcons_LOD_mm6->LoadRaw("dchest.bin", 1) : nullptr,
+            *chests_mm8 = nullptr;
+        void *chests_mm7 = pEvents_LOD->LoadRaw("dchest.bin", 1);
+        pChestList = new ChestList;
+        pChestList->FromFile(chests_mm6, chests_mm7, chests_mm8);
+        free(chests_mm6);
+        free(chests_mm7);
+        free(chests_mm8);
+
+        void *overlays_mm6 = pIcons_LOD_mm6 ? pIcons_LOD_mm6->LoadRaw("doverlay.bin", 1) : nullptr,
+            *overlays_mm8 = nullptr;
+        void *overlays_mm7 = pEvents_LOD->LoadRaw("doverlay.bin", 1);
+        pOverlayList = new OverlayList;
+        pOverlayList->FromFile(overlays_mm6, overlays_mm7, overlays_mm8);
+        free(overlays_mm6);
+        free(overlays_mm7);
+        free(overlays_mm8);
+
+        void *sounds_mm6 = pIcons_LOD_mm6 ? pIcons_LOD_mm6->LoadRaw("dsounds.bin", 1) : nullptr,
+            *sounds_mm8 = nullptr;
+        void *sounds_mm7 = pEvents_LOD->LoadRaw("dsounds.bin", 1);
+        pSoundList = new SoundList;
+        pSoundList->FromFile(sounds_mm6, sounds_mm7, sounds_mm8);
+        free(sounds_mm6);
+        free(sounds_mm7);
+        free(sounds_mm8);
+    }
+
+
+
+
+    if (dword_6BE368_debug_settings_2 & DEBUG_SETTINGS_RUN_IN_WIDOW)
+    {
+        //window->SetWindowedMode(game_width, game_height);
+        pRenderer->SwitchToWindow();
+    }
+    else
+    {
+        __debugbreak(); // Nomad
+        window->SetFullscreenMode();
+        pRenderer->InitializeFullscreen();
+    }
+
+    uSoundVolumeMultiplier = min(9, ReadWindowsRegistryInt("soundflag", 9));
+    uMusicVolimeMultiplier = min(9, ReadWindowsRegistryInt("musicflag", 9));
+    uVoicesVolumeMultiplier = min(9, ReadWindowsRegistryInt("CharVoices", 9));
+    bShowDamage = ReadWindowsRegistryInt("ShowDamage", 1) != 0;
+
+    uGammaPos = min(4, ReadWindowsRegistryInt("GammaPos", 4));
+    //pEngine->pGammaController->Initialize(uGammaPos * 0.1 + 0.6);
+
+    if (ReadWindowsRegistryInt("Bloodsplats", 1))
+        pEngine->uFlags2 |= GAME_FLAGS_2_DRAW_BLOODSPLATS;
+    else
+        pEngine->uFlags2 &= ~GAME_FLAGS_2_DRAW_BLOODSPLATS;
+
+    uTurnSpeed = ReadWindowsRegistryInt("TurnDelta", 3);
+
+    if (!bNoSound)
+        pAudioPlayer->Initialize();
+
+    pMediaPlayer = new Media::MPlayer();
+    pMediaPlayer->Initialize(window);
+
+    dword_6BE364_game_settings_1 |= GAME_SETTINGS_4000;
+
+    switch (uTurnSpeed)
+    {
+    case 0: // undefined turn option
+        __debugbreak(); // really shouldn't use this mode
+        uTurnSpeed = 64; //(unsigned int)uCPUSpeed < 199/*MHz*/ ? 128 : 64; // adjust turn speed to estimated fps
+        break;
+
+    case 1:             // 16x
+        Log::Warning(L"x16 Turn Speed"); // really shouldn't use this mode
+        uTurnSpeed = 128;
+        break;
+
+    case 2:             // 32x
+        Log::Warning(L"x32 Turn Speed"); // really shouldn't use this mode
+        uTurnSpeed = 64;
+        break;
+
+    case 3:             // smooth
+        uTurnSpeed = 0;
+        break;
+    }
+
+    return true;
+}
+
+//----- (00465D0B) --------------------------------------------------------
+void SecondaryInitialization()
+{
+    pMouse->Initialize(window);
+
+    pItemsTable = new ItemsTable;
+    pItemsTable->Initialize();
+
+    //pBitmaps_LOD->can_load_hardware_sprites = 1;
+    //pBitmaps_LOD->SetupPalettes(pRenderer->uTargetRBits, pRenderer->uTargetGBits, pRenderer->uTargetBBits);
+    pBitmaps_LOD->SetupPalettes(5, 6, 5);
+    //pIcons_LOD->SetupPalettes(pRenderer->uTargetRBits, pRenderer->uTargetGBits, pRenderer->uTargetBBits);
+    pIcons_LOD->SetupPalettes(5, 6, 5);
+    //pPaletteManager->SetColorChannelInfo(pRenderer->uTargetRBits, pRenderer->uTargetGBits, pRenderer->uTargetBBits);
+    pPaletteManager->SetColorChannelInfo(5, 6, 5);
+
+    pPaletteManager->SetMistColor(128, 128, 128);
+    pPaletteManager->RecalculateAll();
+    //pSprites_LOD->can_load_hardware_sprites = 1;
+    pObjectList->InitializeSprites();
+    pOverlayList->InitializeSprites();
+
+    if (!bNoSound)
+        pSoundList->Initialize();
+
+
+    for (uint i = 0; i < 4; ++i)
+    {
+        static const char *pUIAnimNames[4] =
+        {
+            "glow03", "glow05",
+            "torchA", "wizeyeA"
+        };
+        static unsigned short _4E98D0[4][4] =
+        {
+            { 479, 0, 329, 0 },
+            { 585, 0, 332, 0 },
+            { 468, 0, 0, 0 },
+            { 606, 0, 0, 0 }
+        };
+
+        pUIAnims[i]->uIconID = pIconsFrameTable->FindIcon(pUIAnimNames[i]);
+        pIconsFrameTable->InitializeAnimation(pUIAnims[i]->uIconID);
+
+        pUIAnims[i]->uAnimLength = 0;
+        pUIAnims[i]->uAnimTime = 0;
+        pUIAnims[i]->x = _4E98D0[i][0];
+        pUIAnims[i]->y = _4E98D0[i][2];
+    }
+
+    for (unsigned int i = 0; i < pObjectList->uNumObjects; ++i)
+    {
+        pObjectList->pObjects[i].uParticleTrailColor = pObjectList->pObjects[i].uParticleTrailColorB |
+            ((unsigned int)pObjectList->pObjects[i].uParticleTrailColorG << 8) |
+            ((unsigned int)pObjectList->pObjects[i].uParticleTrailColorR << 16);
+    }
+
+    MainMenuUI_Create();
+    pEngine->pStru6Instance->LoadAnimations();
+
+    for (uint i = 0; i < 7; ++i)
+    {
+        char container_name[64];
+        sprintf(container_name, "HDWTR%03u", i);
+        pRenderer->pHDWaterBitmapIDs[i] = pBitmaps_LOD->LoadTexture(container_name);
+    }
+
+    pNPCStats = new NPCStats;
+    memset(pNPCStats->pNPCData, 0, 0x94BCu);
+    pNPCStats->Initialize();
+
+    Initialize_GlobalEVT();
+    pBitmaps_LOD->_inlined_sub0();
+    pSprites_LOD->_inlined_sub0();
+    pPaletteManager->LockAll();
+
+    _mkdir("Saves");
+    for (uint i = 0; i < 5; ++i)
+        for (uint j = 0; j < 6; ++j)
+        {
+        sprintf(pTmpBuf.data(), "data\\lloyd%d%d.pcx", i, j);
+        remove(pTmpBuf.data());
+        }
+
+    Initialize_GamesLOD_NewLOD();
+    _576E2C_current_minimap_zoom = 512;
+    dword_576E28 = 9;
+}
+
+int max_flight_height = 4000;    //maximum altitude
+bool use_MMT = false;
+bool use_music_folder = true;
+bool for_refactoring = false;
+
+//----- (00462C94) --------------------------------------------------------
+bool MM_Main(const wchar_t *pCmdLine)
+{
+    IntegrityTest();
+
+    lua = new LuaVM;
+    lua->Initialize();
+
+    bool bNoMargareth = false;
+    if (pCmdLine && *pCmdLine)
+    {
+        //if (wcsstr(pCmdLine, L"-usedefs"))
+        //  bDebugResouces = 1;
+        if (wcsstr(pCmdLine, L"-window"))
+            dword_6BE368_debug_settings_2 |= DEBUG_SETTINGS_RUN_IN_WIDOW;
+
+        if (wcsstr(pCmdLine, L"-nointro"))
+            bNoIntro = true;//dword_6BE364_game_settings_1 |= 4;
+        if (wcsstr(pCmdLine, L"-nologo"))
+            bNoLogo = true;//dword_6BE364_game_settings_1 |= 8;
+        if (wcsstr(pCmdLine, L"-nosound"))
+            bNoSound = true; //dword_6BE364_game_settings_1 |= 0x10;
+
+        bWalkSound = ReadWindowsRegistryInt("WalkSound", 1) != 0;
+        if (wcsstr(pCmdLine, L"-nowalksound"))
+            bWalkSound = false;//dword_6BE364_game_settings_1 |= 0x20;
+        if (wcsstr(pCmdLine, L"-novideo"))
+        {
+            dword_6BE364_game_settings_1 |= GAME_SETTINGS_NO_HOUSE_ANIM;
+            bNoVideo = true;
+        }
+        if (wcsstr(pCmdLine, L"-nocd"))
+            bNoCD = true;
+        if (wcsstr(pCmdLine, L"-nomarg"))
+            bNoMargareth = true;
+    }
+
+    //_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF );//Ritor1: for memory test
+
+    if (!MM7_Initialize(640, 480))
+    {
+        Log::Warning(L"MM init: failed");
+        pEngine->Deinitialize();
+        return 1;
+    }
+
+    pEventTimer->Pause();
+
+    SetUserInterface(PartyAlignment_Neutral, false);
+
+    ShowLogoVideo();
+    //ShowIntroVideo_and_LoadingScreen();
+    WriteWindowsRegistryInt("Ran once", 1);
+    dword_6BE364_game_settings_1 |= GAME_SETTINGS_4000;
+    SecondaryInitialization();
+    //pRenderer->SetRasterClipRect(0, 0, window->GetWidth() - 1, window->GetHeight() - 1);
+    FinalInitialization();
+
+    //Ritor1: include
+    if (use_MMT)
+        MMT_MainMenu_Loop();
+
+    Log::Warning(L"MM: entering main loop");
+    while (1)
+    {
+        //MainMenuWindow* main_menu_window = MainMenuWindow::Create();
+        //window->AddControl(main_menu_window);
+        MainMenu_Loop();
+        uGameState = GAME_STATE_PLAYING;
+        while (1)
+        {
+            if (uGameState == GAME_FINISHED || GetCurrentMenuID() == MENU_EXIT_GAME)
+            {
+                pEngine->Deinitialize();
+                return true;
+            }
+
+            if (GetCurrentMenuID() == MENU_NEWGAME)
+            {
+                if (use_music_folder)
+                    alSourceStop(mSourceID);
+                else
+                {
+                    if (pAudioPlayer->hAILRedbook)
+                        AIL_redbook_stop(pAudioPlayer->hAILRedbook);
+                }
+                pParty->Reset();
+                pOtherOverlayList->Reset();
+                strcpy(pCurrentMapName, pStartingMapName);
+                pParty->CreateDefaultParty(0);
+                PlayerCreationUI_Initialize();
+                if (PlayerCreationUI_Loop())
+                {
+                    DeleteCCharFont();
+                    break;
+                }
+                DeleteCCharFont();
+                bFlashQuestBook = true;
+                pMediaPlayer->PlayFullscreenMovie(MOVIE_Emerald, true);
+                SaveNewGame();
+                if (bNoMargareth)
+                    _449B7E_toggle_bit(pParty->_quest_bits, PARTY_QUEST_EMERALD_MARGARETH_OFF, 1);
+                Game_Loop();
+                if (uGameState == GAME_STATE_NEWGAME_OUT_GAMEMENU)
+                {
+                    SetCurrentMenuID(MENU_NEWGAME);
+                    uGameState = GAME_STATE_PLAYING;
+                    continue;
+                }
+                else if (uGameState == GAME_STATE_GAME_QUITTING_TO_MAIN_MENU)
+                    break;
+                assert(false && "Invalid game state");
+            }
+            if (GetCurrentMenuID() == MENU_CREDITS)
+            {
+                if (use_music_folder)
+                    alSourceStop(mSourceID);
+                else
+                {
+                    if (pAudioPlayer->hAILRedbook)
+                        AIL_redbook_stop(pAudioPlayer->hAILRedbook);
+                }
+                MainMenuUI_Credits_Loop();
+                break;
+            }
+            if (GetCurrentMenuID() == MENU_5 || GetCurrentMenuID() == MENU_LoadingProcInMainMenu)
+            {
+                uGameState = GAME_STATE_PLAYING;
+                Game_Loop();
+            }
+            else
+            {
+                if (GetCurrentMenuID() == MENU_DebugBLVLevel)
+                {
+                    pMouse->ChangeActivation(0);
+                    pParty->Reset();
+                    pParty->CreateDefaultParty(1);
+
+                    __debugbreak();
+                    /*extern void CreateDefaultBLVLevel();
+                    CreateDefaultBLVLevel();
+
+                    OPENFILENAMEA ofn;
+                    if ( !GetOpenFileNameA((LPOPENFILENAMEA)&ofn) )
+                    {
+                    pMouse->ChangeActivation(1);
+                    break;
+                    }
+                    _chdir("..\\");
+                    strcpy(pCurrentMapName, ofn.lpstrFileTitle);*/
+                    pMouse->ChangeActivation(1);
+                    Game_Loop();
+                }
+            }
+            if (uGameState == GAME_STATE_LOADING_GAME)
+            {
+                SetCurrentMenuID(MENU_5);
+                uGameState = GAME_STATE_PLAYING;
+                continue;
+            }
+            if (uGameState == GAME_STATE_NEWGAME_OUT_GAMEMENU)
+            {
+                SetCurrentMenuID(MENU_NEWGAME);
+                uGameState = GAME_STATE_PLAYING;
+                continue;
+            }
+            if (uGameState == GAME_STATE_GAME_QUITTING_TO_MAIN_MENU)// from the loaded game
+            {
+                pAudioPlayer->StopChannels(-1, -1);
+                uGameState = GAME_STATE_PLAYING;
+                break;
+            }
+        }
+        if (!bNoSound)
+        {
+            if (use_music_folder)
+            {
+                PlayAudio(L"Music\\14.mp3");
+                alSourcef(mSourceID, AL_GAIN, pSoundVolumeLevels[uMusicVolimeMultiplier]);
+            }
+            else if (pAudioPlayer->hAILRedbook)
+            {
+                pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f);
+                AIL_redbook_stop(pAudioPlayer->hAILRedbook);
+                unsigned int startms, end_ms;
+                AIL_redbook_track_info(pAudioPlayer->hAILRedbook, 14, &startms, &end_ms);
+                AIL_redbook_play(pAudioPlayer->hAILRedbook, startms + 1, end_ms);
+            }
+        }
+    }
+    //lua_close(L);
+    pEngine->Deinitialize();
+    return 1;
+}
+
+
+
+//----- (00466082) --------------------------------------------------------
+void MM6_Initialize(const wchar_t *pIniFilename)
+{
+    size_t v2; // eax@31
+    size_t v3; // ebx@32
+    size_t v4; // edi@36
+    char pDefaultGroundTexture[16]; // [sp+FCh] [bp-8Ch]@32
+    unsigned int v9; // [sp+184h] [bp-4h]@28
+
+    //_getcwd(v5, 120);
+    //sprintfex(pIniFilename, "%s\\mm6.ini", v5);
+    viewparams = new ViewingParams;
+    game_viewport_x = viewparams->uScreen_topL_X = GetPrivateProfileIntW(L"screen", L"vx1", 8, pIniFilename);
+    game_viewport_y = viewparams->uScreen_topL_Y = GetPrivateProfileIntW(L"screen", L"vy1", 8, pIniFilename);
+    game_viewport_z = viewparams->uScreen_BttmR_X = GetPrivateProfileIntW(L"screen", L"vx2", 468, pIniFilename);
+    game_viewport_w = viewparams->uScreen_BttmR_Y = GetPrivateProfileIntW(L"screen", L"vy2", 351, pIniFilename);
+    game_viewport_width = game_viewport_z - game_viewport_x;
+    game_viewport_height = game_viewport_w - game_viewport_y + 1;
+
+
+    pAudioPlayer = new AudioPlayer;
+    pAudioPlayer->uMixerChannels = GetPrivateProfileIntW(L"settings", L"mixerchannels", 16, pIniFilename);
+    if (pAudioPlayer->uMixerChannels > 16)
+        pAudioPlayer->uMixerChannels = 16;
+
+
+    if (GetPrivateProfileIntW(L"debug", L"nomonster", 0, pIniFilename))
+        dword_6BE368_debug_settings_2 |= DEBUG_SETTINGS_NO_ACTORS;
+    if (ReadWindowsRegistryInt("startinwindow", 0))
+        dword_6BE368_debug_settings_2 |= DEBUG_SETTINGS_RUN_IN_WIDOW;
+    if (GetPrivateProfileIntW(L"debug", L"showFR", 0, pIniFilename))
+        dword_6BE368_debug_settings_2 |= DEBUG_SETTINGS_0002_SHOW_FR;
+    if (GetPrivateProfileIntW(L"debug", L"nodamage", 0, pIniFilename))
+        dword_6BE368_debug_settings_2 |= DEBUG_SETTINGS_NO_DAMAGE;
+    if (GetPrivateProfileIntW(L"debug", L"nodecoration", 0, pIniFilename))
+        dword_6BE368_debug_settings_2 |= DEBUG_SETTINGS_NO_DECORATIONS;
+
+    wchar_t pStartingMapNameW[1024];
+    GetPrivateProfileStringW(L"file", L"startmap", L"out01.odm", pStartingMapNameW, 0x20u, pIniFilename);
+    sprintf(pStartingMapName, "%S", pStartingMapNameW);
+
+    v9 = 0;
+    if (strlen(pStartingMapName))
+    {
+        do
+        {
+            if (pStartingMapName[v9] == ' ')
+                pStartingMapName[v9] = 0;
+            ++v9;
+            v2 = strlen(pStartingMapName);
+        } while (v9 < v2);
+    }
+
+    pODMRenderParams = new ODMRenderParams;
+    pODMRenderParams->outdoor_no_mist = GetPrivateProfileIntW(L"debug", L"noMist", 0, pIniFilename);
+    pODMRenderParams->bNoSky = GetPrivateProfileIntW(L"outdoor", L"nosky", 0, pIniFilename);
+    pODMRenderParams->bDoNotRenderDecorations = GetPrivateProfileIntW(L"render", L"nodecorations", 0, pIniFilename);
+    pODMRenderParams->outdoor_no_wavy_water = GetPrivateProfileIntW(L"outdoor", L"nowavywater", 0, pIniFilename);
+    outdoor_grid_band_1 = GetPrivateProfileIntW(L"outdoor", L"gridband1", 10, pIniFilename);
+    outdoor_grid_band_2 = GetPrivateProfileIntW(L"outdoor", L"gridband2", 15, pIniFilename);
+    outdoor_grid_band_3 = GetPrivateProfileIntW(L"outdoor", L"gridband3", 25, pIniFilename);
+    pODMRenderParams->terrain_gamma = GetPrivateProfileIntW(L"outdoor", L"ter_gamma", 0, pIniFilename);
+    pODMRenderParams->building_gamme = GetPrivateProfileIntW(L"outdoor", L"bld_gamma", 0, pIniFilename);
+    pODMRenderParams->shading_dist_shade = GetPrivateProfileIntW(L"shading", L"dist_shade", 2048, pIniFilename);
+    pODMRenderParams->shading_dist_shademist = GetPrivateProfileIntW(L"shading", L"dist_shademist", 4096, pIniFilename);
+
+    pODMRenderParams->shading_dist_mist = GetPrivateProfileIntW(L"shading", L"dist_mist", 0x2000, pIniFilename);//drawing dist 0x2000
+
+    wchar_t pDefaultSkyTextureW[1024];
+    GetPrivateProfileStringW(L"textures", L"sky", L"plansky1", pDefaultSkyTextureW, 0x10u, pIniFilename);
+    sprintf(pDefaultSkyTexture.data(), "%S", pDefaultSkyTextureW);
+
+    wchar_t pDefaultGroundTextureW[1024];
+    GetPrivateProfileStringW(L"textures", L"default", L"dirt", pDefaultGroundTextureW, 0x10u, pIniFilename);
+    sprintf(pDefaultGroundTexture, "%S", pDefaultGroundTextureW);
+
+    wchar_t pFloat[1024];
+    GetPrivateProfileStringW(L"debug", L"recmod1", L"1.0", pFloat, 0x10u, pIniFilename);
+    swscanf(pFloat, L"%f", &flt_6BE3A4_debug_recmod1);
+
+    GetPrivateProfileStringW(L"debug", L"recmod2", L"1.0", pFloat, 0x10u, pIniFilename);
+    swscanf(pFloat, L"%f", &flt_6BE3A8_debug_recmod2);
+
+    flt_6BE3AC_debug_recmod1_x_1_6 = flt_6BE3A4_debug_recmod1 * 1.666666666666667;
+
+    v3 = 0;
+    if (strlen(pDefaultSkyTexture.data()))
+    {
+        do
+        {
+            if (pDefaultSkyTexture[v3] == ' ')
+                pDefaultSkyTexture[v3] = 0;
+            ++v3;
+        } while (v3 < strlen(pDefaultSkyTexture.data()));
+    }
+    v4 = 0;
+    if (strlen(pDefaultGroundTexture))
+    {
+        do
+        {
+            if (pDefaultGroundTexture[v4] == ' ')
+                pDefaultGroundTexture[v4] = 0;
+            ++v4;
+        } while (v4 < strlen(pDefaultGroundTexture));
+    }
+
+    MM7Initialization();
+}
+
+//----- (004666D5) --------------------------------------------------------
+void MM7Initialization()
+{
+    if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
+    {
+        /*if (byte_6BE388_graphicsmode == 0)
+        {
+        outdoor_grid_band_1 = 10;
+        outdoor_grid_band_2 = 15;
+        outdoor_grid_band_3 = 20;
+        pODMRenderParams->shading_dist_mist = 8192;
+        pODMRenderParams->bNoSky = false;
+        LOBYTE(viewparams->field_20) = 0;
+        }*/
+        pODMRenderParams->shading_dist_shade = 2048;
+        pODMRenderParams->terrain_gamma = 0;
+        pODMRenderParams->building_gamme = 0;
+        pODMRenderParams->shading_dist_shademist = 4096;
+        pODMRenderParams->outdoor_no_wavy_water = 0;
+        //_47F4D3_initialize_terrain_bezier_stuff(outdoor_grid_band_1, outdoor_grid_band_2, outdoor_grid_band_3);
+        {
+            pODMRenderParams->outdoor_grid_band_3 = outdoor_grid_band_3;
+            pODMRenderParams->uPickDepth = outdoor_grid_band_3 * 512;
+        }
+    }
+    else
+        LOBYTE(viewparams->field_20) = 0;
+    pParty->uFlags |= 2;
+    viewparams->uSomeY = viewparams->uScreen_topL_Y;
+    viewparams->uSomeX = viewparams->uScreen_topL_X;
+    viewparams->uSomeZ = viewparams->uScreen_BttmR_X;
+    viewparams->uSomeW = viewparams->uScreen_BttmR_Y;
+
+    pViewport->SetScreen(viewparams->uScreen_topL_X, viewparams->uScreen_topL_Y, viewparams->uScreen_BttmR_X, viewparams->uScreen_BttmR_Y);
+    if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
+        pODMRenderParams->Initialize();
+}
+
+//----- (004610AA) --------------------------------------------------------
+void __fastcall PrepareToLoadODM(unsigned int bLoading, ODMRenderParams *a2)
+{
+    pGameLoadingUI_ProgressBar->Reset(27);
+    pSoundList->_4A9D79(0);
+    uCurrentlyLoadedLevelType = LEVEL_Outdoor;
+    ODM_LoadAndInitialize(pCurrentMapName, a2);
+    if (!bLoading)
+        TeleportToStartingPoint(uLevel_StartingPointType);
+    viewparams->_443365();
+    PlayLevelMusic();
+}
+// 6BE35C: using guessed type int uLevel_StartingPointType;
+
+
+
+//----- (004BF91E) --------------------------------------------------------
+unsigned int GameOverMenu(void *ecx0)
+{
+    const char *v1; // eax@2
+    unsigned int result; // eax@3
+    const char *v6; // eax@10
+    const char *v7; // edx@10
+    const char *v8; // ecx@12
+    const char *v9; // eax@14
+    unsigned int v10; // eax@25
+    GUIWindow pWindow; // [sp+34h] [bp-9Ch]@1
+    unsigned int v14; // [sp+A4h] [bp-2Ch]@5
+    void *v15; // [sp+A8h] [bp-28h]@1
+    const char *pInString; // [sp+ACh] [bp-24h]@5
+    unsigned int v17; // [sp+B0h] [bp-20h]@5
+    unsigned int v18; // [sp+B4h] [bp-1Ch]@5
+    unsigned int v19; // [sp+B8h] [bp-18h]@5
+    int v20; // [sp+BCh] [bp-14h]@7
+    GUIFont *pFont; // [sp+C4h] [bp-Ch]@1
+    unsigned __int64 v23; // [sp+C8h] [bp-8h]@5
+    MSG msg;
+
+    v15 = ecx0;
+
+    RGBTexture _this; // [sp+Ch] [bp-C4h]@1
+    //RGBTexture::RGBTexture(&this);
+
+    dword_6BE364_game_settings_1 &= ~GAME_SETTINGS_4000;
+    bGameoverLoop = 1;
+    pMediaPlayer->bStopBeforeSchedule = 0;
+    pAudioPlayer->StopChannels(-1, -1);
+    pRenderer->BeginScene();
+    pRenderer->ClearBlack();
+    pRenderer->EndScene();
+    pRenderer->Present();
+    //pMediaPlayer->pResetflag = 0;
+    _449B57_test_bit(pParty->_quest_bits, 99);
+    _this.Load("winbg.pcx", 2);
+    pRenderer->BeginScene();
+    pRenderer->DrawTextureRGB(0, 0, &_this);
+    pRenderer->EndScene();
+    free(_this.pPixels);
+    _this.pPixels = 0;
+    window_SpeakInHouse = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_MainMenu, 0, 0);
+    pWindow.uFrameX = 75;
+    pWindow.uFrameY = 60;
+    pWindow.uFrameWidth = 469;
+    pWindow.uFrameHeight = 338;
+    pWindow.uFrameZ = 543;
+    pWindow.uFrameW = 397;
+    pFont = LoadFont("endgame.fnt", "FONTPAL", NULL);
+    if (pParty->IsPartyGood())
+        v1 = pGlobalTXT_LocalizationStrings[675];//"Splendid job!  With the activation of the Gate, a thousand worlds lie at your feet.  Perhaps on one of them you will find the Ancients themselves, and return with the fruits their great civilization has to offer your world and your kingdom."
+    else
+    {
+        result = pParty->IsPartyEvil();
+        if (!(short)result)
+            return result;
+        v1 = pGlobalTXT_LocalizationStrings[676];//"Brilliant!  The completion of the Heavenly Forge has provided enough Ancient weapons to crush all resistance to your plans.  Soon the world will bow to your every whim!  Still, you can't help but wonder what was beyond the Gate the other side was trying so hard to build."
+    }
+    pInString = v1;
+    v23 = pParty->uTimePlayed - 138240;
+    v19 = (unsigned int)((signed __int64)((double)(pParty->uTimePlayed - 138240) * 0.234375) / 60 / 60) / 24;
+    v14 = (unsigned int)((signed __int64)((double)(pParty->uTimePlayed - 138240) * 0.234375) / 60 / 60) / 24 / 0x1C / 0xC;
+    v18 = (unsigned int)((signed __int64)((double)(pParty->uTimePlayed - 138240) * 0.234375) / 60 / 60) / 24 / 0x1C % 0xC;
+    v17 = v19 % 0x1C;
+    if (!v19)
+        v19 = 1;
+    pRenderer->BeginScene();
+    pWindow.DrawTitleText(pFont, 1, 0x23, 1, pGlobalTXT_LocalizationStrings[9], 3);//Congratulations!
+    v23 = 0i64;
+    v20 = 0;
+    for (uint i = 0; i < 4; i++)
+    {
+        sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[129], pParty->pPlayers[i].pName, pParty->pPlayers[i].GetBaseLevel(), pClassNames[pParty->pPlayers[i].classType]);//%s the Level %u %s
+        pWindow.DrawTitleText(pFont, 1, i * (LOBYTE(pFont->uFontHeight) - 2) + LOBYTE(pFont->uFontHeight) + 46, 1, pTmpBuf.data(), 3);
+        v23 += pParty->pPlayers[i].uExperience;//__PAIR__(*(int *)(i - 4), *(int *)(i - 8));
+    }
+    v23 = (signed __int64)v23 / v19;
+    v6 = FitTextInAWindow(pInString, pFont, &pWindow, 0xC, 0);
+    pWindow.DrawTitleText(pFont, 1, 5 * (LOBYTE(pFont->uFontHeight) + 11), 1, v6, 0);
+    strcpy(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[37]);//Total Time:
+
+    v7 = pGlobalTXT_LocalizationStrings[56];
+    if (v17 != 1)
+        v7 = pGlobalTXT_LocalizationStrings[57];
+
+    v8 = pGlobalTXT_LocalizationStrings[146];//Month
+    if (v18 != 1)
+        v8 = pGlobalTXT_LocalizationStrings[148];//Months
+
+    v9 = pGlobalTXT_LocalizationStrings[245];
+    if (v14 != 1)
+        v9 = pGlobalTXT_LocalizationStrings[132];
+
+    sprintf(pTmpBuf2.data(), " %lu %s, %lu %s, %lu %s ", v14, v9, v18, v8, v17, v7);
+    strcat(pTmpBuf.data(), pTmpBuf2.data());
+    pWindow.DrawTitleText(pFont, 1, pWindow.uFrameHeight - 2 * LOBYTE(pFont->uFontHeight) - 5, 1, pTmpBuf.data(), 3);
+    sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[94], v23);
+    pWindow.DrawTitleText(pFont, 1, pWindow.uFrameHeight, 1, pTmpBuf.data(), 3);
+    dword_6BE364_game_settings_1 |= GAME_SETTINGS_4000;
+    pRenderer->EndScene();
+    pRenderer->Present();
+    //if ( pRenderer->pRenderD3D )
+    pRenderer->pBeforePresentFunction();
+    pRenderer->SaveWinnersCertificate("MM7_Win.Pcx");
+    free(pFont);
+    window_SpeakInHouse->Release();
+    window_SpeakInHouse = 0;
+    if (v15 == (void *)2)
+        result = pMessageQueue_50CBD0->uNumMessages;
+    else
+    {
+        LODWORD(v23) = GetTickCount() + 5000;
+        while ((unsigned int)v23 > GetTickCount())
+            ;
+        while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
+        {
+            if (msg.message == WM_QUIT)
+                Engine_DeinitializeAndTerminate(0);
+            TranslateMessage(&msg);
+            DispatchMessage(&msg);
+        }
+        if (pMessageQueue_50CBD0->uNumMessages)
+        {
+            LOBYTE(v10) = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
+            pMessageQueue_50CBD0->uNumMessages = v10;
+        }
+        pKeyActionMap->ResetKeys();
+        pKeyActionMap->uLastKeyPressed = 0;
+        do
+        {
+            while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
+            {
+                if (msg.message == WM_QUIT)
+                    Engine_DeinitializeAndTerminate(0);
+                TranslateMessage(&msg);
+                DispatchMessage(&msg);
+            }
+        } while (!pKeyActionMap->uLastKeyPressed);
+        result = pMessageQueue_50CBD0->uNumMessages;
+        if (pMessageQueue_50CBD0->uNumMessages)
+        {
+            result = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
+            pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
+        }
+    }
+    if (v15)
+    {
+        /*if ( (signed int)result < 40 )
+        {
+        pMessageQueue_50CBD0->pMessages[result].eType = UIMSG_Quit;
+        }*/
+        pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Quit, 1, 0);
+    }
+    else
+    {
+        pMessageQueue_50CBD0->AddGUIMessage(UIMSG_ShowFinalWindow, 1, 0);
+        /*if ( (signed int)result < 40 )
+        {
+        pMessageQueue_50CBD0->pMessages[result].eType = UIMSG_C5;
+        pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
+        result = 3 * pMessageQueue_50CBD0->uNumMessages + 3;
+        *(&pMessageQueue_50CBD0->uNumMessages + result) = 0;
+        ++pMessageQueue_50CBD0->uNumMessages;
+        }*/
+    }
+    bGameoverLoop = 0;
+    return result;
+}
+
+//----- (00464479) --------------------------------------------------------
+void ResetCursor_Palettes_LODs_Level_Audio_SFT_Windows()
+{
+    int v0; // esi@9
+
+    if (pMouse)
+        pMouse->SetCursorBitmap("MICON1");
+
+    pPaletteManager->ResetNonLocked();
+    pBitmaps_LOD->ReleaseAll2();
+    pSprites_LOD->DeleteSomeOtherSprites();
+    pIcons_LOD->ReleaseAll2();
+
+    if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
+        pIndoor->Release();
+    else if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
+        pOutdoor->Release();
+
+    pAudioPlayer->StopChannels(-1, -1);
+    pSoundList->_4A9D79(0);
+    uCurrentlyLoadedLevelType = LEVEL_null;
+    pSpriteFrameTable->ResetSomeSpriteFlags();
+    v0 = uNumVisibleWindows;
+    pParty->armageddon_timer = 0;
+    while (v0 > 0)
+        pWindowList[pVisibleWindowsIdxs[v0--] - 1].Release();
+}
+
+//----- (00461103) --------------------------------------------------------
+void _461103_load_level_sub()
+{
+    int v4; // edx@8
+    signed int v6; // esi@14
+    signed int v8; // ecx@16
+    int v12; // esi@25
+    int v13; // eax@26
+    __int16 v14; // ax@41
+    signed int v17; // [sp+14h] [bp-48h]@3
+    signed int v18; // [sp+14h] [bp-48h]@23
+    int v19; // [sp+18h] [bp-44h]@1
+    signed int v20; // [sp+18h] [bp-44h]@14
+    int v21[16]; // [sp+1Ch] [bp-40h]@17
+
+    GenerateItemsInChest();
+    pGameLoadingUI_ProgressBar->Progress();
+    pParty->uFlags |= 2;
+    pParty->field_7B5_in_arena_quest = 0;
+    dword_5C6DF8 = 1;
+    pNPCStats->uNewlNPCBufPos = 0;
+    v19 = pMapStats->GetMapInfo(pCurrentMapName);
+
+    //v15 = 0;
+    for (uint i = 0; i < uNumActors; ++i)
+        //if ( (signed int)uNumActors > 0 )
+    {
+        //Actor* pActor = &pActors[i];
+        //v2 = (char *)&pActors[0].uNPC_ID;
+        //do
+        //{
+        //v3 = pActors[i].pMonsterInfo.uID;
+        v17 = 0;
+        if (pActors[i].pMonsterInfo.uID >= 115 && pActors[i].pMonsterInfo.uID <= 186
+            || pActors[i].pMonsterInfo.uID >= 232 && pActors[i].pMonsterInfo.uID <= 249)
+            v17 = 1;
+        //v1 = 0;
+        v4 = (pActors[i].pMonsterInfo.uID - 1) % 3;
+        if (2 == v4)
+        {
+            if (pActors[i].sNPC_ID && pActors[i].sNPC_ID < 5000)
+                continue;
+        }
+        else
+        {
+            if (v4 != 1)
+            {
+                if (v4 == 0 && pActors[i].sNPC_ID == 0)
+                    pActors[i].sNPC_ID = 0;
+                continue;
+            }
+        }
+        if (pActors[i].sNPC_ID > 0 && pActors[i].sNPC_ID < 5000)
+            continue;
+        if (v17)
+        {
+            pNPCStats->InitializeAdditionalNPCs(&pNPCStats->pAdditionalNPC[pNPCStats->uNewlNPCBufPos], pActors[i].pMonsterInfo.uID, 0, v19);
+            v14 = LOWORD(pNPCStats->uNewlNPCBufPos) + 5000;
+            ++pNPCStats->uNewlNPCBufPos;
+            pActors[i].sNPC_ID = v14;
+            continue;
+        }
+        pActors[i].sNPC_ID = 0;
+        //++v15;
+        //v2 += 836;
+        //}
+        //while ( v15 < (signed int)uNumActors );
+    }
+
+    pGameLoadingUI_ProgressBar->Progress();
+
+    //v5 = uNumActors;
+    v6 = 0;
+    v20 = 0;
+    //v16 = v1;
+
+    for (uint i = 0; i < uNumActors; ++i)
+    {
+        //v7 = (char *)&pActors[0].pMonsterInfo;
+        //do
+        //{
+        for (v8 = 0; v8 < v6; ++v8)
+        {
+            if (v21[v8] == pActors[i].pMonsterInfo.uID - 1)
+                break;
+        }
+
+        if (v8 == v6)
+        {
+            v21[v6++] = pActors[i].pMonsterInfo.uID - 1;
+            v20 = v6;
+            if (v6 == 16)
+                break;
+        }
+        //++v16;
+        //v7 += 836;
+        //}
+        //while ( v16 < (signed int)v5 );
+    }
+
+    pGameLoadingUI_ProgressBar->Progress();
+
+    for (int _v0 = 0; _v0 < v6; ++_v0)
+    {
+        for (v18 = 4; v18; --v18)
+            pSoundList->LoadSound(pMonsterList->pMonsters[v21[_v0]].pSoundSampleIDs[4 - v18], 0);
+        v12 = 0;
+        do
+            v13 = pSoundList->LoadSound(v12++ + word_4EE088_sound_ids[pMonsterStats->pInfos[v21[_v0] + 1].uSpell1ID], 1);
+        while (v13);
+    }
+    //v0 = pGameLoadingUI_ProgressBar;
+    //v1 = 0;
+
+    pGameLoadingUI_ProgressBar->Progress();
+
+    if (dword_6BE368_debug_settings_2 & DEBUG_SETTINGS_NO_ACTORS)
+        uNumActors = 0;
+    if (dword_6BE368_debug_settings_2 & DEBUG_SETTINGS_NO_DECORATIONS)
+        uNumLevelDecorations = 0;
+    init_event_triggers();
+
+    pGameLoadingUI_ProgressBar->Progress();
+
+    pEngine->pIndoorCameraD3D->vPartyPos.x = 0;
+    pEngine->pIndoorCameraD3D->vPartyPos.y = 0;
+    pEngine->pIndoorCameraD3D->vPartyPos.z = 100;
+    pEngine->pIndoorCameraD3D->sRotationX = 0;
+    pEngine->pIndoorCameraD3D->sRotationY = 0;
+    viewparams->bRedrawGameUI = true;
+    uLevel_StartingPointType = MapStartPoint_Party;
+    pSprites_LOD->_461397();
+    pPaletteManager->LockTestAll();
+    if (pParty->pPickedItem.uItemID != 0)
+        pMouse->SetCursorBitmapFromItemID(pParty->pPickedItem.uItemID);
+}
+
+//----- (0042F3D6) --------------------------------------------------------
+void InitializeTurnBasedAnimations(void *_this)
+{
+    for (unsigned int i = 0; i < pIconIDs_Turn.size(); ++i)
+    {
+        char icon_name[32];
+        sprintf(icon_name, "turn%u", i);
+        pIconIDs_Turn[i] = pIconsFrameTable->FindIcon(icon_name);
+        pIconsFrameTable->InitializeAnimation(pIconIDs_Turn[i]);
+    }
+
+    uIconID_TurnStop = pIconsFrameTable->FindIcon("turnstop");
+    uIconID_TurnHour = pIconsFrameTable->FindIcon("turnhour");
+    uIconID_TurnStart = pIconsFrameTable->FindIcon("turnstart");
+    uIconID_CharacterFrame = pIconsFrameTable->FindIcon("aframe1");
+    uSpriteID_Spell11 = pSpriteFrameTable->FastFindSprite("spell11");
+
+    pIconsFrameTable->InitializeAnimation(uIconID_TurnHour);
+    pIconsFrameTable->InitializeAnimation(uIconID_TurnStop);
+    pIconsFrameTable->InitializeAnimation(uIconID_TurnStart);
+    pIconsFrameTable->InitializeAnimation(uIconID_CharacterFrame);
+}
+
+//----- (0046BDA8) --------------------------------------------------------
+unsigned int  GetGravityStrength()
+{
+    int v0; // eax@1
+
+    v0 = ~LOBYTE(pEngine->uFlags2) & 8;
+    LOBYTE(v0) = v0 | 2;
+    return (unsigned int)v0 >> 1;
+}
+
+//----- (00448B45) --------------------------------------------------------
+void  GameUI_StatusBar_UpdateTimedString(unsigned int bForceHide)
+{
+    if (bForceHide || GameUI_Footer_TimeLeft && GetTickCount() >= GameUI_Footer_TimeLeft)
+        GameUI_Footer_TimeLeft = 0;
+}
+
+//----- (0044861E) --------------------------------------------------------
+void __fastcall sub_44861E_set_texture(unsigned int uFaceCog, const char *pFilename)
+{
+    unsigned int texture; // eax@2
+
+    if (uFaceCog)
+    {
+        texture = pBitmaps_LOD->LoadTexture(pFilename);
+        if (texture != -1 ? (int)&pBitmaps_LOD->pTextures[texture] : 0)
+        {
+            pBitmaps_LOD->pTextures[texture].palette_id2 = pPaletteManager->LoadPalette(pBitmaps_LOD->pTextures[texture].palette_id1);
+
+            if (uCurrentlyLoadedLevelType == 1)
+            {
+                if ((signed int)pIndoor->uNumFaceExtras > 1)
+                {
+                    for (uint i = 1; i < (signed int)pIndoor->uNumFaceExtras; ++i)
+                    {
+                        if (pIndoor->pFaceExtras[i].sCogNumber == uFaceCog)
+                        {
+                            if (pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uAttributes & FACE_TEXTURE_FRAME)
+                            {
+                                pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uBitmapID = pTextureFrameTable->FindTextureByName(pFilename);
+                                if (pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uBitmapID)
+                                {
+                                    pTextureFrameTable->LoadAnimationSequenceAndPalettes(pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uBitmapID);
+                                }
+                                else
+                                {
+                                    pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uBitmapID = texture;
+                                    pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uAttributes &= 0xFFFFBFFF;
+                                }
+                            }
+                            else
+                            {
+                                pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uBitmapID = texture;
+                            }
+                        }
+                    }
+                }
+                pParty->uFlags |= 2;
+            }
+            else
+            {
+                for (uint j = 0; j < (unsigned int)pOutdoor->uNumBModels; ++j)
+                {
+                    for (uint i = 0; i < pOutdoor->pBModels[j].uNumFaces; ++i)
+                    {
+                        if (pOutdoor->pBModels[j].pFaces[i].sCogNumber == uFaceCog)
+                        {
+                            if (pOutdoor->pBModels[j].pFaces[i].uAttributes & FACE_TEXTURE_FRAME)
+                            {
+                                pOutdoor->pBModels[j].pFaces[i].uTextureID = pTextureFrameTable->FindTextureByName(pFilename);
+                                if (pOutdoor->pBModels[j].pFaces[i].uTextureID)
+                                    pTextureFrameTable->LoadAnimationSequenceAndPalettes(pOutdoor->pBModels[j].pFaces[i].uTextureID);
+                                else
+                                {
+                                    pOutdoor->pBModels[j].pFaces[i].uTextureID = texture;
+                                    pOutdoor->pBModels[j].pFaces[i].uAttributes &= 0xFFFFBFFF;
+                                }
+                            }
+                            else
+                                pOutdoor->pBModels[j].pFaces[i].uTextureID = texture;
+                        }
+                    }
+                }
+            }
+            pParty->uFlags |= 2;
+        }
+    }
+}
+
+//----- (0044892E) --------------------------------------------------------
+void __fastcall sub_44892E_set_faces_bit(int sCogNumber, int bit, int on)
+{
+    if (sCogNumber)
+    {
+        if (uCurrentlyLoadedLevelType == 1)
+        {
+            for (uint i = 1; i < (unsigned int)pIndoor->uNumFaceExtras; ++i)
+            {
+                if (pIndoor->pFaceExtras[i].sCogNumber == sCogNumber)
+                {
+                    if (on)
+                        pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uAttributes |= bit;
+                    else
+                        pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uAttributes &= ~bit;
+                }
+            }
+            pParty->uFlags |= 2;
+        }
+        else
+        {
+            for (uint j = 0; j < (unsigned int)pOutdoor->uNumBModels; ++j)
+            {
+                for (uint i = 0; i < (unsigned int)pOutdoor->pBModels[j].uNumFaces; ++i)
+                {
+                    if (pOutdoor->pBModels[j].pFaces[i].sCogNumber == sCogNumber)
+                    {
+                        if (on)
+                            pOutdoor->pBModels[j].pFaces[i].uAttributes |= bit;
+                        else
+                            pOutdoor->pBModels[j].pFaces[i].uAttributes &= ~bit;
+                    }
+                }
+            }
+        }
+        pParty->uFlags |= 2;
+    }
+}
+
+//----- (0044882F) --------------------------------------------------------
+void __fastcall SetDecorationSprite(uint16_t uCog, bool bHide, const char *pFileName)
+{
+    for (size_t i = 0; i < uNumLevelDecorations; i++)
+    {
+        if (pLevelDecorations[i].uCog == uCog)
+        {
+            if (pFileName && strcmp(pFileName, "0"))
+            {
+                pLevelDecorations[i].uDecorationDescID = pDecorationList->GetDecorIdByName(pFileName);
+                pDecorationList->InitializeDecorationSprite(pLevelDecorations[i].uDecorationDescID);
+            }
+
+            if (bHide)
+                pLevelDecorations[i].uFlags &= ~LEVEL_DECORATION_INVISIBLE;
+            else
+                pLevelDecorations[i].uFlags |= LEVEL_DECORATION_INVISIBLE;
+
+            pParty->uFlags |= 2;
+        }
+    }
+}
+
+//----- (004356FF) --------------------------------------------------------
+void back_to_game()
+{
+    dword_507BF0_is_there_popup_onscreen = 0;
+    dword_4E455C = 1;
+
+    extern int no_rightlick_in_inventory;
+    no_rightlick_in_inventory = false;
+
+    if (pGUIWindow_ScrollWindow)
+        free_book_subwindow();
+    if (!current_screen_type && !pGUIWindow_Settings)
+        pEventTimer->Resume();
+    viewparams->bRedrawGameUI = 1;
+}
+
+//----- (00494035) --------------------------------------------------------
+void _494035_timed_effects__water_walking_damage__etc()
+{
+    signed __int64 v0; // qax@1
+    unsigned int v4; // edi@1
+    //  signed int v12; // edi@29
+    int v24; // ecx@60
+    int v26; // ecx@64
+    int v28; // ecx@68
+    int v30; // ecx@72
+    int v32; // ecx@76
+    int v34; // ecx@80
+    int v36; // ecx@84
+    int v38; // ecx@88
+    int v40; // ecx@92
+    int v42; // ecx@96
+    bool v43; // ebx@102
+    bool v46; // edi@111
+    //  unsigned int v56; // [sp-8h] [bp-38h]@55
+    //  int v59; // [sp-4h] [bp-34h]@55
+    //  unsigned int v61; // [sp+14h] [bp-1Ch]@1
+    signed int a2a; // [sp+18h] [bp-18h]@47
+    signed int old_day; // [sp+1Ch] [bp-14h]@47
+    signed int old_hour;
+
+    old_day = pParty->uDaysPlayed;
+    old_hour = pParty->uCurrentHour;
+    //auto prev_time = pEventTimer->uTimeElapsed;
+    pParty->uTimePlayed += pEventTimer->uTimeElapsed;
+    v0 = ((signed __int64)(pParty->uTimePlayed * 0.234375) / 60) / 60i64;
+    v4 = (unsigned int)(((unsigned int)v0 / 24) / 7) >> 2;
+    pParty->uCurrentTimeSecond = (signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) % 60;
+    pParty->uCurrentMinute = ((signed __int64)(pParty->uTimePlayed * 0.234375) / 60) % 60;
+    pParty->uCurrentHour = v0 % 24;
+    pParty->uCurrentMonthWeek = ((unsigned int)v0 / 24) / 7 & 3;
+    pParty->uDaysPlayed = (unsigned int)((unsigned int)v0 / 24) % 28;
+    pParty->uCurrentMonth = v4 % 12;
+    pParty->uCurrentYear = v4 / 0xC + game_starting_year;
+    if (pParty->uCurrentHour >= 3 && (old_hour < 3 || pParty->uDaysPlayed > old_day)) // new day dawns
+    {
+        pParty->pHirelings[0].bHasUsedTheAbility = false;
+        pParty->pHirelings[1].bHasUsedTheAbility = false;
+
+        for (uint i = 0; i < pNPCStats->uNumNewNPCs; ++i)
+            pNPCStats->pNewNPCData[i].bHasUsedTheAbility = false;
+
+        ++pParty->days_played_without_rest;
+        if (pParty->days_played_without_rest > 1)
+        {
+            for (uint i = 0; i < 4; ++i)
+                pParty->pPlayers[i].SetCondWeakWithBlockCheck(0);
+
+            if (pParty->uNumFoodRations)
+                Party::TakeFood(1);
+            else
+                for (uint i = 0; i < 4; ++i)
+                    pParty->pPlayers[i].sHealth = pParty->pPlayers[i].sHealth / (pParty->days_played_without_rest + 1) + 1;
+
+            if (pParty->days_played_without_rest > 3)
+                for (uint i = 0; i < 4; ++i)
+                {
+                pParty->pPlayers[i].Zero();
+                if (!pParty->pPlayers[i].IsPertified() && !pParty->pPlayers[i].IsEradicated()
+                    && !pParty->pPlayers[i].IsDead())
+                {
+                    if (rand() % 100 < 5 * pParty->days_played_without_rest)
+                        pParty->pPlayers[i].SetCondDeadWithBlockCheck(0);
+                    if (rand() % 100 < 10 * pParty->days_played_without_rest)
+                        pParty->pPlayers[i].SetCondInsaneWithBlockCheck(0);
+                }
+                }
+        }
+        if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
+            pOutdoor->SetFog();
+
+        for (uint i = 0; i < 4; ++i)
+            pParty->pPlayers[i].uNumDivineInterventionCastsThisDay = 0;
+    }
+
+    if (pParty->uFlags & 4 && pParty->field_6FC < (signed __int64)pParty->uTimePlayed)//water damage
+    {
+        pParty->field_6FC = (signed __int64)pParty->uTimePlayed + 128;
+        viewparams->bRedrawGameUI = true;
+        for (uint pl = 1; pl <= 4; ++pl)
+        {
+            if (pPlayers[pl]->WearsItem(ITEM_RELIC_HARECS_LEATHER, EQUIP_ARMOUR)
+                || pPlayers[pl]->HasEnchantedItemEquipped(71)
+                || pPlayers[pl]->pPlayerBuffs[PLAYER_BUFF_WATER_WALK].uExpireTime > 0)
+                pPlayers[pl]->PlayEmotion(CHARACTER_EXPRESSION_37, 0);
+            else
+            {
+                if (!pPlayers[pl]->HasUnderwaterSuitEquipped())
+                {
+                    pPlayers[pl]->ReceiveDamage((signed __int64)pPlayers[pl]->GetMaxHealth() * 0.1, DMGT_FIRE);
+                    if (pParty->uFlags & 4)
+                    {
+                        strcpy(GameUI_Footer_TimedString.data(), pGlobalTXT_LocalizationStrings[660]);// Âû òîíåòå!
+                        GameUI_Footer_TimeLeft = 128;
+                    }
+                }
+                else
+                    pPlayers[pl]->PlayEmotion(CHARACTER_EXPRESSION_37, 0);
+            }
+        }
+    }
+    if (pParty->uFlags & 0x200 && pParty->field_6FC < (signed __int64)pParty->uTimePlayed) //lava damage
+    {
+        viewparams->bRedrawGameUI = true;
+        pParty->field_6FC = (signed __int64)pParty->uTimePlayed + 128;
+
+        for (uint pl = 1; pl <= 4; pl++)
+        {
+            pPlayers[pl]->ReceiveDamage((signed __int64)pPlayers[pl]->GetMaxHealth() * 0.1, DMGT_FIRE);
+            if (pParty->uFlags & 0x200)
+            {
+                strcpy(GameUI_Footer_TimedString.data(), pGlobalTXT_LocalizationStrings[661]); //Âû ãîðèòå!
+                GameUI_Footer_TimeLeft = 128;
+            }
+        }
+    }
+    _493938_regenerate();
+    uint party_condition_flag = 4;
+    a2a = pEventTimer->uTimeElapsed;
+    if (pParty->uFlags2 & PARTY_FLAGS_2_RUNNING)//çàìåäëåíèå âîññòàíîâëåíèÿ ïðè áåãå
+    {
+        a2a *= 0.5f;
+        if (a2a < 1)
+            a2a = 1;
+    }
+
+    for (uint pl = 1; pl <= 4; pl++)
+    {
+        if (pPlayers[pl]->uTimeToRecovery)
+            pPlayers[pl]->Recover(a2a);//âîññòàíîâëåíèå àêòèâíîñòè
+        if (pPlayers[pl]->GetItemsBonus(CHARACTER_ATTRIBUTE_ENDURANCE) + pPlayers[pl]->sHealth + pPlayers[pl]->uEndurance >= 1
+            || (signed __int64)pPlayers[pl]->pPlayerBuffs[PLAYER_BUFF_PRESERVATION].uExpireTime > 0)
+        {
+            if (pPlayers[pl]->sHealth < 1)
+                pPlayers[pl]->SetCondition(Condition_Unconcious, 0);
+        }
+        else
+            pPlayers[pl]->SetCondition(Condition_Dead, 0);
+        if (pPlayers[pl]->field_E0)
+        {
+            v24 = pPlayers[pl]->field_E0 - pEventTimer->uTimeElapsed;
+            if (v24 > 0)
+                pPlayers[pl]->field_E0 = v24;
+            else
+            {
+                pPlayers[pl]->field_E0 = 0;
+                viewparams->bRedrawGameUI = true;
+            }
+        }
+        if (pPlayers[pl]->field_E4)
+        {
+            v26 = pPlayers[pl]->field_E4 - pEventTimer->uTimeElapsed;
+            if (v26 > 0)
+                pPlayers[pl]->field_E4 = v26;
+            else
+            {
+                pPlayers[pl]->field_E4 = 0;
+                viewparams->bRedrawGameUI = true;
+            }
+        }
+        if (pPlayers[pl]->field_E8)
+        {
+            v28 = pPlayers[pl]->field_E8 - pEventTimer->uTimeElapsed;
+            if (v28 > 0)
+                pPlayers[pl]->field_E8 = v28;
+            else
+            {
+                pPlayers[pl]->field_E8 = 0;
+                viewparams->bRedrawGameUI = true;
+            }
+        }
+        if (pPlayers[pl]->field_EC)
+        {
+            v30 = pPlayers[pl]->field_EC - pEventTimer->uTimeElapsed;
+            if (v30 > 0)
+                pPlayers[pl]->field_EC = v30;
+            else
+            {
+                pPlayers[pl]->field_EC = 0;
+                viewparams->bRedrawGameUI = true;
+            }
+        }
+        if (pPlayers[pl]->field_F0)
+        {
+            v32 = pPlayers[pl]->field_F0 - pEventTimer->uTimeElapsed;
+            if (v32 > 0)
+                pPlayers[pl]->field_F0 = v32;
+            else
+            {
+                pPlayers[pl]->field_F0 = 0;
+                viewparams->bRedrawGameUI = true;
+            }
+        }
+        if (pPlayers[pl]->field_F4)
+        {
+            v34 = pPlayers[pl]->field_F4 - pEventTimer->uTimeElapsed;
+            if (v34 > 0)
+                pPlayers[pl]->field_F4 = v34;
+            else
+            {
+                pPlayers[pl]->field_F4 = 0;
+                viewparams->bRedrawGameUI = true;
+            }
+        }
+        if (pPlayers[pl]->field_F8)
+        {
+            v36 = pPlayers[pl]->field_F8 - pEventTimer->uTimeElapsed;
+            if (v36 > 0)
+                pPlayers[pl]->field_F8 = v36;
+            else
+            {
+                pPlayers[pl]->field_F8 = 0;
+                viewparams->bRedrawGameUI = true;
+            }
+        }
+        if (pPlayers[pl]->field_FC)
+        {
+            v38 = pPlayers[pl]->field_FC - pEventTimer->uTimeElapsed;
+            if (v38 > 0)
+                pPlayers[pl]->field_FC = v38;
+            else
+            {
+                pPlayers[pl]->field_FC = 0;
+                viewparams->bRedrawGameUI = true;
+            }
+        }
+        if (pPlayers[pl]->field_100)
+        {
+            v40 = pPlayers[pl]->field_100 - pEventTimer->uTimeElapsed;
+            if (v40 > 0)
+                pPlayers[pl]->field_100 = v40;
+            else
+            {
+                pPlayers[pl]->field_100 = 0;
+                viewparams->bRedrawGameUI = true;
+            }
+        }
+        if (pPlayers[pl]->field_104)
+        {
+            v42 = pPlayers[pl]->field_104 - pEventTimer->uTimeElapsed;
+            if (v42 > 0)
+                pPlayers[pl]->field_104 = v42;
+            else
+            {
+                pPlayers[pl]->field_104 = 0;
+                viewparams->bRedrawGameUI = true;
+            }
+        }
+        if (pPlayers[pl]->pConditions[Condition_Sleep] | pPlayers[pl]->pConditions[Condition_Paralyzed]
+            | pPlayers[pl]->pConditions[Condition_Unconcious] | pPlayers[pl]->pConditions[Condition_Dead]
+            | pPlayers[pl]->pConditions[Condition_Pertified] | pPlayers[pl]->pConditions[Condition_Eradicated])
+            --party_condition_flag;
+        v43 = (signed __int64)pPlayers[pl]->pPlayerBuffs[PLAYER_BUFF_HASTE].uExpireTime > 0; //ñïåøêà
+
+        for (uint k = 0; k < 24; ++k)
+            pPlayers[pl]->pPlayerBuffs[k].IsBuffExpiredToTime(pParty->uTimePlayed);
+
+        if (v43 && (signed __int64)pPlayers[pl]->pPlayerBuffs[7].uExpireTime <= 0)
+            pPlayers[pl]->SetCondition(Condition_Weak, 0);
+    }
+
+    v46 = (signed __int64)pParty->pPartyBuffs[PARTY_BUFF_HASTE].uExpireTime > 0;
+
+    for (uint i = 0; i < 20; ++i)
+    {
+        if (pParty->pPartyBuffs[i].IsBuffExpiredToTime(pParty->uTimePlayed) == 1)
+            viewparams->bRedrawGameUI = true;
+    }
+
+    if (v46 && (signed __int64)pParty->pPartyBuffs[PARTY_BUFF_HASTE].uExpireTime <= 0)
+    {
+        for (uint i = 0; i < 4; ++i)
+            pParty->pPlayers[i].SetCondition(1, 0);
+    }
+
+    for (uint i = 0; i < 2; ++i)//Ïðîâåðêà â ñîçíàíèè ëè ïåðñ ñäåëàâøèé çàêë íà ïîë¸ò è õîæäåíèå ïî âîäå
+    {
+        SpellBuff* pBuf = &pParty->pPartyBuffs[Party_Spec_Motion_status_ids[i]];
+        if (pBuf->uExpireTime == 0)
+            continue;
+
+        if (!(pBuf->uFlags & 1))
+        {
+            if (!pPlayers[pBuf->uCaster]->CanAct())
+            {
+                pBuf->Reset();
+                if (Party_Spec_Motion_status_ids[i] == PARTY_BUFF_FLY)
+                    pParty->bFlying = false;
+            }
+        }
+    }
+
+    if (!party_condition_flag)
+    {
+        if (current_screen_type != SCREEN_REST)
+        {
+            for (uint pl = 1; pl <= 4; pl++)
+            {
+                if (pPlayers[pl]->pConditions[Condition_Sleep])
+                {
+                    pPlayers[pl]->pConditions[Condition_Sleep] = 0;
+                    party_condition_flag = 1;
+                    break;
+                }
+            }
+            if (!party_condition_flag || _5C35C0_force_party_death)
+                uGameState = GAME_STATE_PARTY_DIED;
+        }
+    }
+
+    if (uActiveCharacter)//âûáîð ñëåäóþùåãî ïîñëå ïðîïóñêàþùåãî õîä
+    {
+        if (current_screen_type != SCREEN_REST)
+        {
+            if (pPlayers[uActiveCharacter]->pConditions[Condition_Sleep]
+                || pPlayers[uActiveCharacter]->pConditions[Condition_Paralyzed]
+                || pPlayers[uActiveCharacter]->pConditions[Condition_Unconcious]
+                || pPlayers[uActiveCharacter]->pConditions[Condition_Dead]
+                || pPlayers[uActiveCharacter]->pConditions[Condition_Pertified]
+                || pPlayers[uActiveCharacter]->pConditions[Condition_Eradicated])
+            {
+                viewparams->bRedrawGameUI = true;
+                uActiveCharacter = pParty->GetNextActiveCharacter();
+            }
+        }
+    }
+}
+
+//----- (00493938) --------------------------------------------------------
+void _493938_regenerate()
+{
+    int current_time; // edi@1
+    int last_reg_time; // qax@1
+    int v4; // eax@2
+    int v5; // edi@5
+    long long *v6; // ecx@5
+    char v7; // sf@5
+    int *v8; // ecx@10
+    int v9; // edi@15
+    signed int v10; // eax@15
+    //  __int16 *v11; // edx@16
+    //  int v12; // eax@20
+    int numberOfActorsAffected; // ebx@20
+    unsigned int v14; // esi@21
+    //unsigned int v15; // ecx@21
+    //unsigned int v16; // eax@21
+    //  int v18; // eax@21
+    signed int v19; // eax@21
+    bool recovery_HP; // ebx@25
+    //  ITEM_EQUIP_TYPE v22; // edi@30
+    signed int v25; // eax@33
+    //  int v26; // eax@35
+    //  int v27; // eax@36
+    //  int v28; // eax@37
+    signed int v31; // ecx@53
+    int actorsAffectedByImmolation[100]; // [sp+4h] [bp-22Ch]@20
+    SpriteObject a1; // [sp+194h] [bp-9Ch]@15
+    Vec3_int_ a3; // [sp+204h] [bp-2Ch]@15
+    bool has_dragon_flag; // [sp+210h] [bp-20h]@22
+    bool lich_jar_flag; // [sp+214h] [bp-1Ch]@25
+    bool zombie_flag; // [sp+218h] [bp-18h]@25
+    bool decrease_HP; // [sp+21Ch] [bp-14h]@25
+    bool lich_flag; // [sp+220h] [bp-10h]@25
+    int v49; // [sp+224h] [bp-Ch]@24
+    bool recovery_SP; // [sp+228h] [bp-8h]@25
+    bool redraw_flag; // [sp+22Ch] [bp-4h]@2
+
+    current_time = (signed int)(signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) / 60;
+    last_reg_time = (signed int)(signed __int64)((double)pParty->uLastRegenerationTime * 0.234375) / 60;
+    if (current_time >= (signed int)last_reg_time + 5)
+    {
+        redraw_flag = false;
+        v4 = (current_time - last_reg_time) / 5;
+        if (pParty->FlyActive())
+        {
+            if (pParty->bFlying)
+            {
+                if (!(pParty->pPartyBuffs[PARTY_BUFF_FLY].uFlags & 1))
+                {
+                    v5 = v4 * pParty->pPartyBuffs[PARTY_BUFF_FLY].uPower;
+                    //cursed_flag = pParty->pPlayers[pParty->pPartyBuffs[PARTY_BUFF_FLY].uCaster - 1].pConditions[Condition_Cursed];//cursed
+                    //v7 = cursed_flag < v5;
+                    //cursed_flag -= v5;
+
+                    v6 = &pParty->pPlayers[pParty->pPartyBuffs[PARTY_BUFF_FLY].uCaster - 1].pConditions[Condition_Cursed];
+
+                    if (*v6 < v5)
+                    {
+                        v6 = 0;
+                        pParty->uFlags &= 0xFFFFFFBFu;
+                        pParty->bFlying = false;
+                        redraw_flag = true;
+                    }
+                }
+            }
+        }
+
+        if (pParty->WaterWalkActive())
+        {
+            if (pParty->uFlags & PARTY_FLAGS_1_STANDING_ON_WATER)
+            {
+                if (!(pParty->pPartyBuffs[PARTY_BUFF_WATER_WALK].uFlags & 1))
+                { // taking on water
+                    v8 = (int *)&pParty->pPlayers[pParty->pPartyBuffs[PARTY_BUFF_WATER_WALK].uCaster - 1].pConditions[Condition_Cursed];//&AA1058_PartyQuickSpellSound[4].pSounds[6972 * pParty->pPartyBuffs[PARTY_BUFF_WATER_WALK].uCaster + 2000];
+                    v7 = *v8 < v4;
+                    *v8 -= v4;
+                    if (v7)
+                    {
+                        *v8 = 0;
+                        pParty->uFlags &= ~PARTY_FLAGS_1_STANDING_ON_WATER;
+                        redraw_flag = true;
+                    }
+                }
+            }
+        }
+
+        if (pParty->ImmolationActive())//Æåðòâà
+        {
+            a3.z = 0;
+            a3.y = 0;
+            a3.x = 0;
+            a1.stru_24.Reset();
+            a1.spell_level = pParty->pPartyBuffs[PARTY_BUFF_IMMOLATION].uPower;
+            a1.spell_skill = pParty->ImmolationSkillLevel();
+            v10 = 0;
+            a1.uType = 1070;
+            a1.spell_id = SPELL_FIRE_IMMOLATION;
+            v10 = 0;
+            for (uint i = 0; i > pObjectList->uNumObjects; i++)
+            {
+                if (pObjectList->pObjects[i].uObjectID == stru_4E3ACC[8].uType)
+                    v10 = i;
+            }
+            a1.uObjectDescID = v10;
+            a1.field_60_distance_related_prolly_lod = 0;
+            a1.uAttributes = 0;
+            a1.uSectorID = 0;
+            a1.uSpriteFrameID = 0;
+            a1.spell_caster_pid = PID(OBJECT_Player, pParty->pPartyBuffs[PARTY_BUFF_IMMOLATION].uCaster);
+            a1.uFacing = 0;
+            a1.uSoundID = 0;
+            numberOfActorsAffected = pParty->_46A89E_immolation_effect(actorsAffectedByImmolation, 100, 307);
+            for (v9 = 0; v9 < numberOfActorsAffected; ++v9)
+            {
+                v14 = actorsAffectedByImmolation[v9];
+                a1.vPosition.x = pActors[v14].vPosition.x;
+                a1.vPosition.y = pActors[v14].vPosition.y;
+                a1.vPosition.z = pActors[v14].vPosition.z;
+                a1.spell_target_pid = PID(OBJECT_Actor, v14);
+                v19 = a1.Create(0, 0, 0, 0);
+                Actor::DamageMonsterFromParty(PID(OBJECT_Item, v19), v14, &a3);
+            }
+        }
+
+        has_dragon_flag = false;
+        if (PartyHasDragon())
+            has_dragon_flag = true;
+
+        for (v49 = 0; v49 < 4; v49++)
+        {
+            recovery_HP = false;
+            recovery_SP = false;
+            decrease_HP = false;
+            lich_flag = false;
+            lich_jar_flag = false;
+            zombie_flag = false;
+
+            for (int v22 = 0; (signed int)v22 < 16; v22++)
+            {
+                if (pParty->pPlayers[v49].HasItemEquipped((ITEM_EQUIP_TYPE)v22))
+                {
+                    uint _idx = pParty->pPlayers[v49].pEquipment.pIndices[v22];
+                    if (pParty->pPlayers[v49].pInventoryItemList[_idx - 1].uItemID > 134)
+                    {
+                        if (pParty->pPlayers[v49].pInventoryItemList[_idx - 1].uItemID == ITEM_RELIC_ETHRICS_STAFF)
+                            decrease_HP = true;
+                        if (pParty->pPlayers[v49].pInventoryItemList[_idx - 1].uItemID == ITEM_ARTIFACT_HERMES_SANDALS)
+                        {
+                            recovery_HP = true;
+                            recovery_SP = true;
+                        }
+                        if (pParty->pPlayers[v49].pInventoryItemList[_idx - 1].uItemID == ITEM_ARTIFACT_MINDS_EYE)
+                            recovery_SP = true;
+                        if (pParty->pPlayers[v49].pInventoryItemList[_idx - 1].uItemID == ITEM_ARTIFACT_HEROS_BELT)
+                            recovery_HP = true;
+                    }
+                    else
+                    {
+                        v25 = pParty->pPlayers[v49].pInventoryItemList[_idx - 1].uSpecEnchantmentType;
+                        if (v25 == 37 //of Regeneration("Regenerate 1hp/x while walking, etc")
+                            || v25 == 44 //of Life("HP (+10), Regen hpts")
+                            || v25 == 50 //of The Phoenix("Fire Res (+30), Regen hpts") && 
+                            || v25 == 54)// of The Troll("End (+15), Regen hpts")
+                            recovery_HP = true;
+                        if (v25 == 38 //of Mana("Regenerate 1sp/x while walking, etc")
+                            || v25 == 47 //of The Eclipse("SP (+10), Regen spts")
+                            || v25 == 55)//of The Unicorn("Luck (+15), Regen spts")
+                            recovery_SP = true;
+                        if (v25 == 66)// of Plenty("Regenerate 1 hp/x and 1 sp/x while walking, etc.")
+                        {
+                            recovery_HP = true;
+                            recovery_SP = true;
+                        }
+                    }
+
+                    if (recovery_HP &&
+                        !pParty->pPlayers[v49].pConditions[Condition_Dead] &&
+                        !pParty->pPlayers[v49].pConditions[Condition_Eradicated])
+                    {
+                        if (pParty->pPlayers[v49].sHealth < pParty->pPlayers[v49].GetMaxHealth())
+                            ++pParty->pPlayers[v49].sHealth;
+                        if (pParty->pPlayers[v49].pConditions[Condition_Unconcious] && pParty->pPlayers[v49].sHealth > 0)
+                            pParty->pPlayers[v49].pConditions[Condition_Unconcious] = 0;
+                        redraw_flag = true;
+                    }
+
+                    if (recovery_SP &&
+                        !pParty->pPlayers[v49].pConditions[Condition_Dead] &&
+                        !pParty->pPlayers[v49].pConditions[Condition_Eradicated])
+                    {
+                        if (pParty->pPlayers[v49].sMana < pParty->pPlayers[v49].GetMaxMana())
+                            ++pParty->pPlayers[v49].sMana;
+                        redraw_flag = true;
+                    }
+
+                    if (decrease_HP &&
+                        !pParty->pPlayers[v49].pConditions[Condition_Dead] &&
+                        !pParty->pPlayers[v49].pConditions[Condition_Eradicated])
+                    {
+                        --pParty->pPlayers[v49].sHealth;
+                        if (!(pParty->pPlayers[v49].pConditions[Condition_Unconcious]) && pParty->pPlayers[v49].sHealth < 0)
+                            pParty->pPlayers[v49].pConditions[Condition_Unconcious] = pParty->uTimePlayed;
+                        if (pParty->pPlayers[v49].sHealth < 1)
+                        {
+                            if (pParty->pPlayers[v49].sHealth + pParty->pPlayers[v49].uEndurance + pParty->pPlayers[v49].GetItemsBonus(CHARACTER_ATTRIBUTE_ENDURANCE) >= 1
+                                || (signed __int64)pParty->pPlayers[v49].pPlayerBuffs[PLAYER_BUFF_PRESERVATION].uExpireTime > 0)
+                                pParty->pPlayers[v49].pConditions[Condition_Unconcious] = pParty->uTimePlayed;
+                            else
+                            {
+                                if (!pParty->pPlayers[v49].pConditions[Condition_Dead])
+                                    pParty->pPlayers[v49].pConditions[Condition_Dead] = pParty->uTimePlayed;
+                            }
+                        }
+                        redraw_flag = true;
+                    }
+                }
+            }
+
+            //regeneration
+            if (pParty->pPlayers[v49].pPlayerBuffs[PLAYER_BUFF_REGENERATION].uExpireTime > 0
+                && !pParty->pPlayers[v49].pConditions[Condition_Dead]
+                && !pParty->pPlayers[v49].pConditions[Condition_Eradicated])
+            {
+                pParty->pPlayers[v49].sHealth += 5 * pParty->pPlayers[v49].pPlayerBuffs[PLAYER_BUFF_REGENERATION].uPower;
+                if (pParty->pPlayers[v49].sHealth > pParty->pPlayers[v49].GetMaxHealth())
+                    pParty->pPlayers[v49].sHealth = pParty->pPlayers[v49].GetMaxHealth();
+                if (pParty->pPlayers[v49].pConditions[Condition_Unconcious] && pParty->pPlayers[v49].sHealth > 0)
+                    pParty->pPlayers[v49].pConditions[Condition_Unconcious] = 0;
+                redraw_flag = true;
+            }
+
+            //for warlock
+            if (has_dragon_flag && pParty->pPlayers[v49].classType == PLAYER_CLASS_WARLOCK)
+            {
+                if (pParty->pPlayers[v49].sMana < pParty->pPlayers[v49].GetMaxMana())
+                    ++pParty->pPlayers[v49].sMana;
+                redraw_flag = true;
+            }
+
+            //for lich
+            if (pParty->pPlayers[v49].classType == PLAYER_CLASS_LICH)
+            {
+                for (v31 = 0; v31 < 126; ++v31)
+                {
+                    if (pParty->pPlayers[v49].pInventoryItemList[v31].uItemID == ITEM_LICH_JAR_FULL)
+                        lich_jar_flag = true;
+                }
+                lich_flag = true;
+            }
+            if (lich_flag && !pParty->pPlayers[v49].pConditions[Condition_Dead]
+                && !pParty->pPlayers[v49].pConditions[Condition_Eradicated])
+            {
+                if (pParty->pPlayers[v49].sHealth > pParty->pPlayers[v49].GetMaxHealth() / 2)
+                    pParty->pPlayers[v49].sHealth = pParty->pPlayers[v49].sHealth - 2;
+                if (pParty->pPlayers[v49].sMana > pParty->pPlayers[v49].GetMaxMana() / 2)
+                    pParty->pPlayers[v49].sMana = pParty->pPlayers[v49].sMana - 2;
+            }
+            if (lich_jar_flag)
+            {
+                if (pParty->pPlayers[v49].sMana < pParty->pPlayers[v49].GetMaxMana())
+                    ++pParty->pPlayers[v49].sMana;
+            }
+
+            //for zombie
+            if (pParty->pPlayers[v49].pConditions[Condition_Zombie])
+                zombie_flag = true;
+            if (zombie_flag && !pParty->pPlayers[v49].pConditions[Condition_Dead]
+                && !pParty->pPlayers[v49].pConditions[Condition_Eradicated])
+            {
+                if (pParty->pPlayers[v49].sHealth > pParty->pPlayers[v49].GetMaxHealth() / 2)
+                    pParty->pPlayers[v49].sHealth = pParty->pPlayers[v49].sHealth - 1;
+                if (pParty->pPlayers[v49].sMana > 0)
+                    pParty->pPlayers[v49].sMana = pParty->pPlayers[v49].sMana - 1;
+            }
+        }
+        pParty->uLastRegenerationTime = pParty->uTimePlayed;
+        if (!viewparams->bRedrawGameUI)
+            viewparams->bRedrawGameUI = redraw_flag;
+    }
+}
+
+//----- (00491E3A) --------------------------------------------------------
+void sub_491E3A()
+{
+    signed int v1; // esi@3
+    unsigned int v3; // eax@7
+    unsigned int v4; // edx@8
+    int v6; // edi@17
+
+    //__debugbreak();//Ritor1
+    for (uint pl = 0; pl < 4; pl++)
+    {
+        if (SoundSetAction[24][0])
+        {
+            v3 = 0;
+            for (v1 = 0; v1 < (signed int)pSoundList->sNumSounds; ++v1)
+            {
+                int ps = 2 * (SoundSetAction[24][0] + 50 * pParty->pPlayers[pl].uVoiceID) + 4998;//6728
+                if (pSoundList->pSL_Sounds[v1].uSoundID == 2 * (SoundSetAction[24][0] + 50 * pParty->pPlayers[pl].uVoiceID) + 4998)
+                    v3 = v1;
+            }
+            pSoundList->UnloadSound(v3, 1);
+            for (v4 = 0; (signed int)v4 < (signed int)pSoundList->sNumSounds; ++v4)
+            {
+                if (pSoundList->pSL_Sounds[v4].uSoundID == 2 * (SoundSetAction[24][0] + 50 * pParty->pPlayers[pl].uVoiceID) + 4999)
+                    pSoundList->UnloadSound(v4, 1);
+            }
+        }
+    }
+    v6 = pIcons_LOD->uNumLoadedFiles - 1;
+    if (v6 >= pIcons_LOD->pFacesLock)
+    {
+        do
+        {
+            pIcons_LOD->pTextures[v6].Release();
+            if (pIcons_LOD->pHardwareTextures)
+            {
+                if (pIcons_LOD->pHardwareTextures[v6])
+                {
+                    pIcons_LOD->pHardwareTextures[v6]->Release();
+                    pIcons_LOD->pHardwareTextures[v6] = 0;
+                }
+            }
+            if (pIcons_LOD->pHardwareSurfaces)
+            {
+                if (pIcons_LOD->pHardwareSurfaces[v6])
+                {
+                    pIcons_LOD->pHardwareSurfaces[v6]->Release();
+                    pIcons_LOD->pHardwareSurfaces[v6] = 0;
+                }
+            }
+            --v6;
+        } while (v6 >= pIcons_LOD->pFacesLock);
+    }
+    pIcons_LOD->uNumLoadedFiles = pIcons_LOD->pFacesLock;
+    pIcons_LOD->pFacesLock = 0;
+}
+// 4ED498: using guessed type char byte_4ED498;
+
+//----- (00494820) --------------------------------------------------------
+unsigned int __fastcall _494820_training_time(unsigned int a1)
+{
+    signed int v1; // eax@1
+
+    v1 = 5;
+    if (a1 % 24 >= 5)
+        v1 = 29;
+    return v1 - a1 % 24;
+}
+
+//----- (00494836) --------------------------------------------------------
+int stru339_spell_sound::AddPartySpellSound(int uSoundID, int a6)
+{
+    int v3; // esi@1
+    int result; // eax@1
+    //stru339_spell_sound *v5; // ebx@1
+    //int *v6; // edi@2
+    unsigned int v7; // eax@3
+    int v8; // [sp+Ch] [bp-8h]@3
+    int v9; // [sp+10h] [bp-4h]@2
+    int a2a; // [sp+1Ch] [bp+8h]@1
+    //return 0;
+    v3 = 0;
+    result = word_4EE088_sound_ids[uSoundID];
+    //v5 = this;
+    a2a = word_4EE088_sound_ids[uSoundID];
+    if (word_4EE088_sound_ids[uSoundID])
+    {
+        //v6 = this->pSoundsOffsets;
+        for (v9 = 0; v9 < 2; ++v9)
+        {
+            v7 = a2a++;
+            result = pSoundList->LoadSound(v7, (char *)this + v3, 44744 - v3, &v8, a6);
+            if (!result)
+                break;
+            a6 += 4;
+            result = v8 + 256;
+            this->pSoundsOffsets[v9] = v3;
+            v3 += result;
+            this->pSoundsSizes[v9] = v8 + 256;
+            //++v6;
+        }
+    }
+    return result;
+}
+// 4EE088: using guessed type __int16 word_4EE088_sound_ids[];
+
+//----- (00443E31) --------------------------------------------------------
+void LoadLevel_InitializeLevelStr()
+{
+
+    //  char Args[100]; 
+    int string_num;
+    int max_string_length;
+    //  int current_string_length;
+    int prev_string_offset;
+
+    if (sizeof(pLevelStrOffsets) != 2000)
+        Log::Warning(L"pLevelStrOffsets: deserialization warning");
+    memset(pLevelStrOffsets.data(), 0, 2000);
+
+    max_string_length = 0;
+    string_num = 1;
+    prev_string_offset = 0;
+    pLevelStrOffsets[0] = 0;
+    for (uint i = 0; i < uLevelStrFileSize; ++i)
+    {
+        if (!pLevelStr[i])
+        {
+            pLevelStrOffsets[string_num] = i + 1;
+            ++string_num;
+            if (i - prev_string_offset > max_string_length)
+                max_string_length = i - prev_string_offset;
+            prev_string_offset = i;
+        }
+    }
+
+    uLevelStrNumStrings = string_num - 1;
+    if (max_string_length > 800)
+        Error("MAX_EVENT_TEXT_LENGTH needs to be increased to %lu", max_string_length + 1);
+
+    if (uLevelStrNumStrings > 0)
+    {
+        for (uint i = 0; i <uLevelStrNumStrings; ++i)
+        {
+            if (RemoveQuotes(&pLevelStr[pLevelStrOffsets[i]]) != &pLevelStr[pLevelStrOffsets[i]])
+                ++pLevelStrOffsets[i];
+        }
+    }
+}
+
+//----- (00443F95) --------------------------------------------------------
+void  OnMapLeave()
+{
+    _evt_raw *test_event;
+    if (uLevelEVT_NumEvents > 0)
+    {
+        for (uint i = 0; i < uLevelEVT_NumEvents; ++i)
+        {
+            test_event = (_evt_raw*)&pLevelEVT[pLevelEVT_Index[i].uEventOffsetInEVT];
+            if (test_event->_e_type == EVENT_OnMapLeave)
+            {
+                EventProcessor(pLevelEVT_Index[i].uEventID, 0, 1, pLevelEVT_Index[i].event_sequence_num);
+            }
+        }
+    }
+}
+
+//----- (00443FDC) --------------------------------------------------------
+void OnMapLoad()
+{
+    int v6; // eax@9
+    unsigned __int64 v8; // qax@26
+    int hours; // ebx@26
+    unsigned __int64 v18; // [sp+Ch] [bp-44h]@12
+    unsigned int seconds; // [sp+14h] [bp-3Ch]@26
+    unsigned __int64 v20; // [sp+1Ch] [bp-34h]@7
+    unsigned int minutes; // [sp+2Ch] [bp-24h]@26
+    unsigned int years; // [sp+34h] [bp-1Ch]@26
+    unsigned int weeks; // [sp+38h] [bp-18h]@26
+    int v26; // [sp+3Ch] [bp-14h]@15
+    unsigned int days; // [sp+3Ch] [bp-14h]@26
+    unsigned int months; // [sp+40h] [bp-10h]@26
+
+    for (uint i = 0; i < uLevelEVT_NumEvents; ++i)
+    {
+        EventIndex pEvent = pLevelEVT_Index[i];
+
+        _evt_raw* _evt = (_evt_raw *)(&pLevelEVT[pEvent.uEventOffsetInEVT]);
+
+        if (_evt->_e_type == EVENT_PlaySound)
+            pSoundList->LoadSound(EVT_DWORD(_evt->v5), 0);
+        else if (_evt->_e_type == EVENT_OnMapReload)
+            EventProcessor(pEvent.uEventID, 0, 0, pEvent.event_sequence_num);
+        else if (_evt->_e_type == EVENT_OnTimer || _evt->_e_type == EVENT_Initialize)
+        {
+            //v3 = &MapsLongTimersList[MapsLongTimers_count];
+            v20 = pOutdoor->loc_time.uLastVisitDay;
+            if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
+                v20 = pIndoor->stru1.uLastVisitDay;
+
+            MapsLongTimersList[MapsLongTimers_count].timer_evt_type = _evt->_e_type;
+            MapsLongTimersList[MapsLongTimers_count].timer_evt_ID = pEvent.uEventID;
+            MapsLongTimersList[MapsLongTimers_count].timer_evt_seq_num = pEvent.event_sequence_num;
+
+            MapsLongTimersList[MapsLongTimers_count].YearsInterval = _evt->v5;
+            MapsLongTimersList[MapsLongTimers_count].MonthsInterval = _evt->v6;
+            MapsLongTimersList[MapsLongTimers_count].WeeksInterval = _evt->v7;
+            MapsLongTimersList[MapsLongTimers_count].HoursInterval = _evt->v8;
+            MapsLongTimersList[MapsLongTimers_count].MinutesInterval = _evt->v9;
+            MapsLongTimersList[MapsLongTimers_count].SecondsInterval = _evt->v10;
+
+
+            v6 = ((unsigned short)_evt->v12 << 8) + _evt->v11;
+
+            MapsLongTimersList[MapsLongTimers_count].time_left_to_fire = ((unsigned short)_evt->v12 << 8) + _evt->v11;
+            MapsLongTimersList[MapsLongTimers_count].IntervalHalfMins = ((unsigned short)_evt->v12 << 8) + _evt->v11;
+            if (MapsLongTimersList[MapsLongTimers_count].timer_evt_type == EVENT_Initialize && !(short)v6)
+            {
+                if (v20)
+                    v18 = pParty->uTimePlayed - v20;
+                else
+                    v18 = 0;
+                v26 = (signed int)(signed __int64)((double)(signed __int64)v18 * 0.234375) / 60 / 60 / 24;
+
+                if (v26 / 7 / 4 / 12 != 0 && MapsLongTimersList[MapsLongTimers_count].YearsInterval ||
+                    v26 / 7 / 4 != 0 && MapsLongTimersList[MapsLongTimers_count].MonthsInterval != 0 ||
+                    v26 / 7 != 0 && MapsLongTimersList[MapsLongTimers_count].WeeksInterval != 0 ||
+                    v26 != 0 || !v20)
+                {
+                    ++MapsLongTimers_count;
+                    MapsLongTimersList[MapsLongTimers_count].NextStartTime = 0;
+                    continue;
+                }
+            }
+            else
+            {
+                v8 = (__int64)((double)pParty->uTimePlayed * 0.234375);
+                seconds = v8 % 60;
+                minutes = (v8 / 60) % 60;
+                hours = ((v8 / 60) / 60) % 24;
+                days = (((v8 / 60) / 60) / 24) % 7;
+                weeks = ((((v8 / 60) / 60) / 24) / 7) % 4;
+                months = (((((v8 / 60) / 60) / 24) / 7) / 4) % 12;
+                years = (((((v8 / 60) / 60) / 24) / 7) / 4) / 12;
+
+                if (MapsLongTimersList[MapsLongTimers_count].YearsInterval)
+                    ++years;
+                else if (MapsLongTimersList[MapsLongTimers_count].MonthsInterval)
+                    ++months;
+                else if (MapsLongTimersList[MapsLongTimers_count].WeeksInterval)
+                    ++weeks;
+                else
+                {
+                    ++days;
+                    hours = MapsLongTimersList[MapsLongTimers_count].HoursInterval;
+                    minutes = MapsLongTimersList[MapsLongTimers_count].MinutesInterval;
+                    seconds = MapsLongTimersList[MapsLongTimers_count].SecondsInterval;
+                }
+                MapsLongTimersList[MapsLongTimers_count].NextStartTime = (signed __int64)((double)((seconds
+                    + 60 * minutes
+                    + 3600 * hours
+                    + 86400 * days
+                    + 604800 * weeks
+                    + 2419200 * months
+                    + 29030400 * years) << 7)
+                    * 0.033333335);
+
+                ++MapsLongTimers_count;
+            }
+        }
+    }
+}
+
+//----- (00444360) --------------------------------------------------------
+void Level_LoadEvtAndStr(const char *pLevelName)
+{
+    char pContainerName[120]; // [sp+8h] [bp-98h]@1
+
+    sprintf(pContainerName, "%s.evt", pLevelName);
+    uLevelEVT_Size = LoadEventsToBuffer(pContainerName, pLevelEVT.data(), 9216);
+
+    sprintf(pContainerName, "%s.str", pLevelName);
+    uLevelStrFileSize = LoadEventsToBuffer(pContainerName, pLevelStr.data(), 9216);
+    if (uLevelStrFileSize)
+        LoadLevel_InitializeLevelStr();
+}
+
+//----- (004452BB) --------------------------------------------------------
+void sub_4452BB()
+{
+    pGUIWindow2->Release();
+    pGUIWindow2 = 0;
+    activeLevelDecoration = _591094_decoration;
+    EventProcessor(dword_5C3418, 0, 1, dword_5C341C);
+    activeLevelDecoration = nullptr;
+    pEventTimer->Resume();
+}
+
+//----- (0044100D) --------------------------------------------------------
+bool _44100D_should_alter_right_panel()
+{
+    return current_screen_type == SCREEN_NPC_DIALOGUE || current_screen_type == SCREEN_CHARACTERS ||
+        current_screen_type == SCREEN_HOUSE || current_screen_type == SCREEN_E ||
+        current_screen_type == SCREEN_CHANGE_LOCATION || current_screen_type == SCREEN_INPUT_BLV || current_screen_type == SCREEN_CASTING;
+}
+
+//----- (0044987B) --------------------------------------------------------
+void Transition_StopSound_Autosave(const char *pMapName, MapStartPoint start_point)
+{
+    pAudioPlayer->StopChannels(-1, -1);
+    pGameLoadingUI_ProgressBar->Initialize(GUIProgressBar::TYPE_None);
+    if (_stricmp(pCurrentMapName, pMapName))
+        SaveGame(1, 0);
+
+    uGameState = GAME_STATE_CHANGE_LOCATION;
+    strcpy(pCurrentMapName, pMapName);
+    uLevel_StartingPointType = start_point;
+}
+// 6BE35C: using guessed type int uLevel_StartingPointType;
+
+//----- (004451A8) --------------------------------------------------------
+void __fastcall sub_4451A8_press_any_key(int a1, int a2, int a4)
+{
+    if (!pGUIWindow2)
+    {
+        if (pParty->uFlags & 2)
+            pEngine->Draw();
+        pAudioPlayer->StopChannels(-1, -1);
+        pMiscTimer->Pause();
+        pEventTimer->Pause();
+        dword_5C3418 = a1;
+        dword_5C341C = a2;
+        _591094_decoration = activeLevelDecoration;
+        pGUIWindow2 = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_GreetingNPC, a4, 0);
+        pGUIWindow2->CreateButton(61, 424, 31, 40, 2, 94, UIMSG_SelectCharacter, 1, '1', "", 0);
+        pGUIWindow2->CreateButton(177, 424, 31, 40, 2, 94, UIMSG_SelectCharacter, 2, '2', "", 0);
+        pGUIWindow2->CreateButton(292, 424, 31, 40, 2, 94, UIMSG_SelectCharacter, 3, '3', "", 0);
+        pGUIWindow2->CreateButton(407, 424, 31, 40, 2, 94, UIMSG_SelectCharacter, 4, '4', "", 0);
+    }
+}
+
+
+
+
+//----- (00448B67) --------------------------------------------------------
+void OnTimer(int)
+{
+    if (pEventTimer->bPaused)
+        return;
+
+    long long v13 = (signed __int64)(pParty->uTimePlayed - _5773B8_event_timer) / 128;
+    if (!v13)
+        return;
+
+    //uint _v2v3 = pParty->uTimePlayed;
+    //v3 = HIDWORD(pParty->uTimePlayed);
+    //v2 = LODWORD(pParty->uTimePlayed);
+
+    _5773B8_event_timer = pParty->uTimePlayed;
+
+    for (uint i = 0; i < MapsLongTimers_count; ++i)
+    {
+        //v4 = (char *)&array_5B5928_timers[0].field_C;
+        MapsLongTimer* timer = &MapsLongTimersList[i];
+        //while ( 1 )
+        //{
+        //v5 = *(short *)v4;
+        if (timer->time_left_to_fire)
+        {
+            if (v13 < timer->time_left_to_fire)
+                timer->time_left_to_fire -= v13;
+            else
+            {
+                timer->time_left_to_fire = timer->IntervalHalfMins;
+                EventProcessor(timer->timer_evt_ID, 0, 1, timer->timer_evt_seq_num);
+            }
+        }
+        else
+        {
+            if (timer->NextStartTime < pParty->uTimePlayed)
+            {
+                uint next_trigger_time = 1 * 60 * 60 * 24; // 1 day
+                if (timer->YearsInterval)
+                    next_trigger_time = 336 * 60 * 60 * 24; // 1 year
+                else if (timer->MonthsInterval)
+                    next_trigger_time = 28 * 60 * 60 * 24; // 1 month
+                else if (timer->WeeksInterval)
+                    next_trigger_time = 7 * 60 * 60 * 24; // 1 week
+
+                timer->NextStartTime += (next_trigger_time * 128) / 3.0f;
+                if (timer->NextStartTime < pParty->uTimePlayed) // make sure in wont fire several times in a row if big time interval has lapsed
+                    timer->NextStartTime = pParty->uTimePlayed;
+
+                EventProcessor(timer->timer_evt_ID, 0, 1, timer->timer_evt_seq_num);
+            }
+        }
+    }
+}
+
+
+
+
+
+
+
+//----- (0044C28F) --------------------------------------------------------
+bool TeleportToNWCDungeon()
+{
+    if (!_stricmp("nwc.blv", pCurrentMapName))
+        return false;
+
+    _5B65A8_npcdata_uflags_or_other = 0;
+    _5B65AC_npcdata_fame_or_other = 0;
+    _5B65B0_npcdata_rep_or_other = 0;
+    _5B65B4_npcdata_loword_house_or_other = 0;
+    _5B65B8_npcdata_hiword_house_or_other = 0;
+    dword_5B65BC = 0;
+    dword_5B65C0 = 0;
+
+    pGameLoadingUI_ProgressBar->uType = GUIProgressBar::TYPE_Fullscreen;
+    Transition_StopSound_Autosave("nwc.blv", MapStartPoint_Party);
+    current_screen_type = SCREEN_GAME;
+    return true;
+}
+
+//----- (00401000) --------------------------------------------------------
+void mm7__vector_constructor(void *a1, int objSize, int numObjs, int(*constructor)(int))
+{
+    void *v4; // esi@2
+
+    if (numObjs > 0)
+    {
+        v4 = a1;
+        for (int i = numObjs; i; --i)
+        {
+            constructor((int)v4);
+            v4 = (char *)v4 + objSize;
+        }
+    }
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/Engine.h	Sun May 10 01:29:11 2015 +0200
@@ -0,0 +1,245 @@
+#pragma once
+#include "Engine/ErrorHandling.h"
+#include "Engine/Log.h"
+#include "Engine/MM7.h"
+#include "Engine/mm7_data.h"
+
+void SetCurrentMenuID(enum MENU_STATE);
+enum MENU_STATE GetCurrentMenuID();
+
+void Engine_DeinitializeAndTerminate(int exitCode);
+
+
+#pragma once
+#include "Engine/VectorTypes.h"
+
+#include "OSAPI.h"
+
+#include "Engine/MapInfo.h"
+
+
+#define GAME_FLAGS_1_01_lightmap_related                 0x01
+#define GAME_FLAGS_1_DRAW_BLV_DEBUGS    0x08
+#define GAME_FLAGS_2_SATURATE_LIGHTMAPS 0x02
+#define GAME_FLAGS_2_ALTER_GRAVITY      0x08
+#define GAME_FLAGS_2_TARGETING_MODE     0x10
+#define GAME_FLAGS_2_DRAW_BLOODSPLATS   0x20
+
+
+
+/*  320 */
+enum GAME_STATE
+{
+    GAME_STATE_PLAYING = 0,
+    GAME_FINISHED = 1,
+    GAME_STATE_CHANGE_LOCATION = 2,
+    GAME_STATE_LOADING_GAME = 3,
+    GAME_STATE_NEWGAME_OUT_GAMEMENU = 4,
+    GAME_STATE_5 = 5,
+    GAME_STATE_STARTING_NEW_GAME = 6,
+    GAME_STATE_GAME_QUITTING_TO_MAIN_MENU = 7,
+    GAME_STATE_PARTY_DIED = 8,
+    GAME_STATE_FINAL_WINDOW = 9,
+    GAME_STATE_A = 10
+};
+
+
+
+/*  105 */
+#pragma pack(push, 1)
+struct Game__StationaryLight
+{
+    Vec3_float_ vPosition;
+    Vec3_float_ vRGBColor;
+    float flt_18;
+};
+#pragma pack(pop)
+
+
+/*  108 */
+#pragma pack(push, 1)
+struct Game_stru0
+{
+    int field_0;
+    unsigned __int8 *ptr_4;
+    int field_8;
+    int field_C;
+};
+#pragma pack(pop)
+
+
+/*  279 */
+#pragma pack(push, 1)
+//Game_stru1
+struct Game_Bloodsplat
+{
+    float x;
+    float y;
+    float z;
+    float r;
+    float g;
+    float b;
+    float radius;
+};
+#pragma pack(pop)
+
+
+class Vis;
+class LightmapBuilder;
+class ParticleEngine;
+class Mouse;
+class Keyboard;
+class ThreadWard;
+class CShow;
+class GammaController;
+struct stru9;
+struct stru10;
+
+/*  104 */
+#pragma pack(push, 1)
+struct Engine
+{
+    static Engine *Create();
+    static void    Destroy();
+
+protected: Engine();
+protected: virtual ~Engine();
+
+
+public:
+    //void _44E904_gamma_saturation_adjust();
+    //bool InitializeGammaController();
+    bool PickMouse(float fPickDepth, unsigned int uMouseX, unsigned int uMouseY, bool bOutline, struct Vis_SelectionFilter *sprite_filter, struct Vis_SelectionFilter *face_filter);
+    bool PickKeyboard(bool bOutline, struct Vis_SelectionFilter *sprite_filter, struct Vis_SelectionFilter *face_filter);
+    void OutlineSelection();
+    signed int _44EC23(struct Polygon *a2, int *a3, signed int a4);
+    signed int _44ED0A(struct BLVFace *a2, int *a3, signed int a4);
+    bool AlterGamma_BLV(struct BLVFace *pFace, signed int *pColor);
+    bool AlterGamma_ODM(struct ODMFace *pFace, signed int *pColor);
+    bool draw_debug_outlines();
+    bool _44EEA7();
+    bool _44F07B();
+    void ToggleFlags(unsigned int uMask);
+    void ToggleFlags2(unsigned int uFlag);
+    void _44F0FD();
+    void PushStationaryLights(int a2);
+    void PrepareBloodsplats();
+    void Deinitialize();
+    void DrawParticles();
+    void Draw();
+
+    //----- (0042EB6A) --------------------------------------------------------
+    struct stru6 *GetStru6() { return this->pStru6Instance; }
+    //----- (0042EB71) --------------------------------------------------------
+    struct IndoorCameraD3D *GetIndoorCamera() { return this->pIndoorCameraD3D; }
+
+
+    //void ( ***vdestructor_ptr)(Game *, bool);
+    Game__StationaryLight pStationaryLights[25];
+    char field_2C0[1092];
+    unsigned int uNumStationaryLights;
+    Game_Bloodsplat pBloodsplats[20];
+    int field_938;
+    int field_93C;
+    int field_940;
+    int field_944;
+    int field_948;
+    int field_94C;
+    int field_950;
+    int field_954;
+    int field_958;
+    int field_95C;
+    int field_960;
+    int field_964;
+    int field_968;
+    int field_96C;
+    int field_970;
+    Mouse *pMouse;
+    int field_978;
+    Game_stru0 stru_97C;
+    char field_98C[1148];
+    int uNumBloodsplats;
+    int field_E0C;
+    __int64 field_E10;
+    int uNumStationaryLights_in_pStationaryLightsStack;
+    unsigned int __depricated1;//unsigned int bGammaControlInitialized;
+    unsigned int uFlags;
+    unsigned int uFlags2;
+    float fSaturation;
+    unsigned __int64 __depricated2;//unsigned __int64 uSomeGammaStartTime;
+    unsigned __int64 __depricated3;//__int64 uSomeGammaDeltaTime;
+    void/*ThreadWard*/ *pThreadWardInstance;
+    ParticleEngine *pParticleEngine;
+    Mouse *pMouseInstance;
+    LightmapBuilder *pLightmapBuilder;
+    Vis *pVisInstance;
+    stru6 *pStru6Instance;
+    IndoorCameraD3D *pIndoorCameraD3D;
+    stru9 *pStru9Instance;
+    stru10 *pStru10Instance;
+    void/*stru11*/ *pStru11Instance;
+    void/*stru12*/ *pStru12Instance;
+    void/*CShow*/ *pCShow;
+    Keyboard *pKeyboardInstance;
+    void *__depricated_4;//GammaController *pGammaController;
+    int field_E74;
+};
+#pragma pack(pop)
+
+
+
+
+
+
+extern Engine *pEngine;
+
+void sub_42FBDD();
+void CloseWindowBackground();
+void back_to_game();
+
+void UpdateUserInput_and_MapSpecificStuff();
+void PrepareWorld(unsigned int _0_box_loading_1_fullscreen);
+void DoPrepareWorld(unsigned int bLoading, int _1_fullscreen_loading_2_box);
+
+//int __stdcall aWinProc(HWND hWnd, UINT Msg, WPARAM wParam, unsigned int lParam);
+int __stdcall InsertMM7CDDialogFunc(HWND hDlg, int a2, __int16 a3, int a4);
+bool __fastcall FindMM7CD(HWND hWnd, char *pCDDrive);
+//bool __fastcall Initialize(HINSTANCE hInst, char *pCmdLine);
+
+void FinalInitialization();
+bool __fastcall CheckMM7CD(char c);
+void SecondaryInitialization();
+
+
+void MM6_Initialize(const wchar_t *pIniFilename);
+void MM7Initialization();
+
+void __fastcall PrepareToLoadODM(unsigned int bLoading, struct ODMRenderParams *a2);
+void MainMenu_Loop();
+unsigned int GameOverMenu(void *ecx0);
+void ResetCursor_Palettes_LODs_Level_Audio_SFT_Windows();
+void _461103_load_level_sub();
+void  InitializeTurnBasedAnimations(void *);
+unsigned int GetGravityStrength();
+void  GameUI_StatusBar_UpdateTimedString(unsigned int bForceHide); // idb
+
+void __fastcall sub_44861E_set_texture(unsigned int uFaceCog, const char *pFilename);
+void __fastcall sub_44892E_set_faces_bit(int sCogNumber, int bit, int on);
+void __fastcall SetDecorationSprite(uint16_t uCog, bool bHide, const char *pFileName); // idb
+void _494035_timed_effects__water_walking_damage__etc();
+void _493938_regenerate();
+void sub_491E3A();
+const char *GetReputationString(signed int a1);
+unsigned int __fastcall _494820_training_time(unsigned int a1);
+void LoadLevel_InitializeLevelStr();
+void OnMapLeave();
+void OnMapLoad();
+void Level_LoadEvtAndStr(const char *pLevelName);
+void sub_4452BB();
+bool _44100D_should_alter_right_panel();
+void Transition_StopSound_Autosave(const char *pMapName, MapStartPoint point); // sub_44987B idb
+
+void __fastcall sub_4451A8_press_any_key(int a1, int a2, int a4);
+
+void OnTimer(int);
+bool TeleportToNWCDungeon();
\ No newline at end of file
--- a/Engine/Events.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Events.cpp	Sun May 10 01:29:11 2015 +0200
@@ -4,16 +4,14 @@
 
 #define _CRT_SECURE_NO_WARNINGS
 
-#include "ErrorHandling.h"
+#include "Engine/Engine.h"
 
 #include "Graphics/Weather.h"
 #include "Graphics/Texture.h"
-#include "mm7_data.h"
 #include "Media/MediaPlayer.h"
 #include "IO/Mouse.h"
 
 #include "MapInfo.h"
-#include "Game.h"
 #include "Graphics/Render.h"
 #include "GUI/GUIWindow.h"
 #include "GUI/GUIProgressBar.h"
@@ -33,10 +31,8 @@
 #include "Events.h"
 #include "Events2D.h"
 #include "..\GUI\UI\UIHouses.h"
-#include "MM7.h"
 #include "Graphics/Level/Decoration.h"
 #include "LuaVM.h"
-#include "Log.h"
 #include "Graphics/DecorationList.h"
 
 
@@ -415,7 +411,7 @@
         pMediaPlayer->bStopBeforeSchedule = 0;
 //        pMediaPlayer->pResetflag = 0;
 
-        v128 = pCurrentScreen;
+        v128 = current_screen_type;
         strcpy(Str, Source);
         v16 = RemoveQuotes(Str);
 		pMediaPlayer->FullscreenMovieLoop(v16, 0/*, _evt->v5*/);
@@ -425,13 +421,13 @@
           v18 = 0;
           LOBYTE(v17) = 1;
           SetUserInterface(PartyAlignment_Good, v17);
-          if ( !_evt->v6 || v128 == 3 )
+          if (!_evt->v6 || v128 == SCREEN_BOOKS)
           {
-            pCurrentScreen = v128;
-            if ( v128 == 3 )
-              pGameLoadingUI_ProgressBar->uType = GUIProgressBar::TYPE_Fullscreen;
-            if ( v128 == 13 )
-              pMediaPlayer->OpenHouseMovie(pAnimatedRooms[uCurrentHouse_Animation].video_name, 1);
+              current_screen_type = (CURRENT_SCREEN)v128;
+              if (v128 == SCREEN_BOOKS)
+                  pGameLoadingUI_ProgressBar->uType = GUIProgressBar::TYPE_Fullscreen;
+              if (v128 == SCREEN_HOUSE)
+                  pMediaPlayer->OpenHouseMovie(pAnimatedRooms[uCurrentHouse_Animation].video_name, 1);
           }
           ++curr_seq_num;
           break;
@@ -442,13 +438,13 @@
           pParty->alignment = PartyAlignment_Evil;
           LOBYTE(v17) = 1;
           SetUserInterface(PartyAlignment_Evil, v17);
-          if ( !_evt->v6 || v128 == 3 )
+          if (!_evt->v6 || v128 == SCREEN_BOOKS)
           {
-            pCurrentScreen = v128;
-            if ( v128 == 3 )
-              pGameLoadingUI_ProgressBar->uType = GUIProgressBar::TYPE_Fullscreen;
-            if ( v128 == 13 )
-              pMediaPlayer->OpenHouseMovie(pAnimatedRooms[uCurrentHouse_Animation].video_name, 1);
+              current_screen_type = (CURRENT_SCREEN)v128;
+              if (v128 == SCREEN_BOOKS)
+                  pGameLoadingUI_ProgressBar->uType = GUIProgressBar::TYPE_Fullscreen;
+              if (v128 == SCREEN_HOUSE)
+                  pMediaPlayer->OpenHouseMovie(pAnimatedRooms[uCurrentHouse_Animation].video_name, 1);
           }
           ++curr_seq_num;
           break;
@@ -459,13 +455,13 @@
           pParty->RestAndHeal();
           pParty->days_played_without_rest = 0;
         }
-        if ( !_evt->v6 || v128 == 3 )
+        if (!_evt->v6 || v128 == SCREEN_BOOKS)
         {
-          pCurrentScreen = v128;
-          if ( v128 == 3 )
-            pGameLoadingUI_ProgressBar->uType = GUIProgressBar::TYPE_Fullscreen;
-          if ( v128 == 13 )
-            pMediaPlayer->OpenHouseMovie(pAnimatedRooms[uCurrentHouse_Animation].video_name, 1);
+            current_screen_type = (CURRENT_SCREEN)v128;
+            if (v128 == SCREEN_BOOKS)
+                pGameLoadingUI_ProgressBar->uType = GUIProgressBar::TYPE_Fullscreen;
+            if (v128 == SCREEN_HOUSE)
+                pMediaPlayer->OpenHouseMovie(pAnimatedRooms[uCurrentHouse_Animation].video_name, 1);
         }
         ++curr_seq_num;
         }
@@ -1129,7 +1125,7 @@
           pGameLoadingUI_ProgressBar->uType = (GUIProgressBar::Type)((activeLevelDecoration == NULL) + 1);
           Transition_StopSound_Autosave(v99, MapStartPoint_Party);
           v133 = 1;
-          if ( pCurrentScreen == SCREEN_HOUSE )
+          if ( current_screen_type == SCREEN_HOUSE )
             {
             if ( uGameState == GAME_STATE_CHANGE_LOCATION )
               {
@@ -1142,7 +1138,7 @@
               window_SpeakInHouse = 0;
               if ( pMessageQueue_50CBD0->uNumMessages )
                 pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-              pCurrentScreen = SCREEN_GAME;
+              current_screen_type = SCREEN_GAME;
               viewparams->bRedrawGameUI = 1;
               pDialogueNPCCount = 0;
               pDialogueWindow->Release();
--- a/Engine/Game.cpp	Sat May 09 12:55:58 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,7427 +0,0 @@
-#define _CRTDBG_MAP_ALLOC
-#include <stdlib.h>
-#include <crtdbg.h>
-
-#define _CRT_SECURE_NO_WARNINGS
-#include "Arcomage\Arcomage.h"
-
-#include "Engine/Graphics/Vis.h"
-#include "Engine/Graphics/Weather.h"
-#include "Engine/Graphics/LightmapBuilder.h"
-#include "Engine/Graphics/DecalBuilder.h"
-#include "Engine/Graphics/ParticleEngine.h"
-#include "IO/Mouse.h"
-#include "IO/Keyboard.h"
-#include "Engine/Graphics/GammaControl.h"
-#include "stru6.h"
-#include "Engine/Graphics/stru9.h"
-#include "Engine/Graphics/stru10.h"
-#include "Engine/ErrorHandling.h"
-
-#include "Game.h"
-#include "Party.h"
-#include "Engine/Graphics/Viewport.h"
-#include "Timer.h"
-#include "Engine/Graphics/Outdoor.h"
-#include "Engine/Graphics/Overlays.h"
-#include "Media/Audio/AudioPlayer.h"
-#include "LOD.h"
-#include "GUI/GUIWindow.h"
-#include "TurnEngine/TurnEngine.h"
-#include "Media/Video/Bink_Smacker.h"
-#include "Events.h"
-#include "OurMath.h"
-#include "texts.h"
-#include "GUI/GUIFont.h"
-#include "Log.h"
-#include "Graphics/Lights.h"
-#include "Spells/CastSpellInfo.h"
-#include "Tables/FrameTableInc.h"
-#include "Objects/Actor.h"
-#include "GUI/GUIProgressBar.h"
-#include "Objects/ObjectList.h"
-#include "Graphics/Level/Decoration.h"
-#include "Graphics/PaletteManager.h"
-#include "..\GUI\UI\UIHouses.h"
-#include "..\GUI\UI\UIShops.h"
-#include "..\GUI\UI\UIPartyCreation.h"
-#include "SaveLoad.h"
-#include "Engine/Objects/SpriteObject.h"
-#include "mm7.h"
-#include "Graphics/Sprites.h"
-#include "Registry.h"
-#include "Objects/Chest.h"
-
-#include "..\GUI\UI\UIGame.h"
-
-#include "Graphics/DecorationList.h"
-#include "Tables/IconFrameTable.h"
-#include "Tables/PlayerFrameTable.h"
-#include "MapsLongTimer.h"
-#include "Tables/StorylineTextTable.h"
-#include "Tables/FactionTable.h"
-#include "stru123.h"
-#include "LuaVM.h"
-#include "Graphics/RenderD3D11.h"
-#include "MMT.h"
-#include "../GUI/NewUI\MainMenu.h"
-#include <direct.h>
-
-
-
-
-
-Game *pGame;
-
-
-
-
-
-//----- (00435694) --------------------------------------------------------
-void Game::ToggleFlags2(unsigned int uFlag)
-{
-  unsigned int v2; // eax@1
-
-  v2 = this->uFlags2;
-  if ( v2 & uFlag )
-    this->uFlags2 = v2 & ~uFlag;
-  else
-    this->uFlags2 = uFlag | v2;
-}
-
-//----- (0044103C) --------------------------------------------------------
-void Game::Draw()
-{
-  int v4; // edi@26
-
-  uFlags2 &= ~0x02;
-  if ( pParty->_497FC5_check_party_perception_against_level() )
-    uFlags2 |= 2;
-
-  pGame->pIndoorCameraD3D->sRotationX = pParty->sRotationX;
-  pGame->pIndoorCameraD3D->sRotationY = pParty->sRotationY;
-  pGame->pIndoorCameraD3D->vPartyPos.x = pParty->vPosition.x - pParty->y_rotation_granularity * cosf(2 * pi_double * pParty->sRotationY / 2048.0);
-  pGame->pIndoorCameraD3D->vPartyPos.y = pParty->vPosition.y - pParty->y_rotation_granularity * sinf(2 * pi_double * pParty->sRotationY / 2048.0);
-  pGame->pIndoorCameraD3D->vPartyPos.z = pParty->vPosition.z + pParty->sEyelevel;//193, but real 353
-
-  //pIndoorCamera->Initialize2();
-  pIndoorCameraD3D->CalculateRotations(pParty->sRotationX, pParty->sRotationY);
-  pIndoorCameraD3D->CreateWorldMatrixAndSomeStuff();
-  pIndoorCameraD3D->_4374E8_ProllyBuildFrustrum();
-
-  if ( pMovie_Track )
-  {
-    /*if ( !pRenderer->pRenderD3D )
-    {
-		pRenderer->BeginSceneD3D();
-		pMouse->DrawCursorToTarget();
-		pRenderer->DrawBillboards_And_MaybeRenderSpecialEffects_And_EndScene();
-	}*/
-  }
-  else
-  {
-    if ( pParty->vPosition.x != pParty->vPrevPosition.x || pParty->sRotationY != pParty->sPrevRotationY || pParty->vPosition.y != pParty->vPrevPosition.y 
-       || pParty->sRotationX != pParty->sPrevRotationX || pParty->vPosition.z != pParty->vPrevPosition.z || pParty->sEyelevel != pParty->sPrevEyelevel )
-      pParty->uFlags |= 2u;
-    pParty->vPrevPosition.x = pParty->vPosition.x;
-    pParty->vPrevPosition.y = pParty->vPosition.y;
-    pParty->vPrevPosition.z = pParty->vPosition.z;
-    //v0 = &pRenderer;
-    pParty->sPrevRotationY = pParty->sRotationY;
-    pParty->sPrevRotationX = pParty->sRotationX;
-
-    pParty->sPrevEyelevel = pParty->sEyelevel;
-    pRenderer->BeginSceneD3D();
-
-    //if ( !pRenderer->pRenderD3D )
-      //pMouse->DrawCursorToTarget();
-    if ( !PauseGameDrawing() || viewparams->field_48 == 1 )
-    {
-      //if ( pRenderer->pRenderD3D )
-      {
-        float v2 = (double)(((signed int)pMiscTimer->uTotalGameTimeElapsed >> 2) & 0x1F) * 0.032258064 * 6.0;
-        //v3 = v2 + 6.7553994e15;
-        //pRenderer->field_1036A8_bitmapid = LODWORD(v3);
-        pRenderer->hd_water_current_frame = floorf(v2 + 0.5f);
-      }
-
-      if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
-        pIndoor->Draw();
-      else if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
-        pOutdoor->Draw();
-      else 
-        Error("Invalid level type: %u", uCurrentlyLoadedLevelType);
-
-      //if (pRenderer->pRenderD3D)
-      {
-        pDecalBuilder->DrawBloodsplats();
-        pGame->pLightmapBuilder->DrawLightmapsType(2);
-      }
-    }
-    pRenderer->DrawBillboards_And_MaybeRenderSpecialEffects_And_EndScene();
-  }
-
-  //DEBUG: force redraw gui
-  viewparams->bRedrawGameUI = true;
-
-
-  pRenderer->BeginScene();
-  //if (pRenderer->pRenderD3D)
-    pMouse->DrawCursorToTarget();
-  if (pOtherOverlayList->bRedraw)
-    viewparams->bRedrawGameUI = true;
-  v4 = viewparams->bRedrawGameUI;
-  GameUI_Footer();
-  if (!viewparams->bRedrawGameUI)
-    GameUI_DrawRightPanelItems();
-  else
-  {
-    GameUI_DrawRightPanelFrames();
-    GameUI_Footer_2();
-    viewparams->bRedrawGameUI = false;
-  }
-  if (!pMovie_Track)//!pVideoPlayer->pSmackerMovie)
-  {
-    GameUI_DrawMinimap(488, 16, 625, 133, viewparams->uMinimapZoom, true);//redraw = pParty->uFlags & 2);
-    if (v4)
-    {
-      if ( !PauseGameDrawing() /*&& pRenderer->pRenderD3D*/) // clear game viewport with transparent color
-        pRenderer->FillRectFast(pViewport->uViewportTL_X, pViewport->uViewportTL_Y, pViewport->uViewportBR_X - pViewport->uViewportTL_X,
-                                pViewport->uViewportBR_Y - pViewport->uViewportTL_Y + 1,
-                                0x7FF);
-      viewparams->field_48 = 0;
-    }
-  }
-
-  viewparams->bRedrawGameUI = pOtherOverlayList->bRedraw;
-  pOtherOverlayList->bRedraw = 0;
-
-  GameUI_DrawPartySpells();
-  if (v4 || pParty->pHirelings[0].evt_C || pParty->pHirelings[1].evt_C )
-    GameUI_DrawHiredNPCs();
-  GameUI_DrawPortraits(v4);
-  GameUI_DrawLifeManaBars();
-  GameUI_DrawCharacterSelectionFrame();
-  if ( _44100D_should_alter_right_panel() )
-    GameUI_DrawRightPanel();
-  if ( !pMovie_Track )
-  {
-    pStru6Instance->DrawPlayerBuffAnims();
-    pOtherOverlayList->DrawTurnBasedIcon(v4);
-    GameUI_DrawTorchlightAndWizardEye();
-  }
-
-
-  static bool render_framerate = false;
-  static float framerate = 0.0f;
-  static uint frames_this_second = 0;
-  static uint last_frame_time = GetTickCount();
-  static uint framerate_time_elapsed = 0;
-
-  if ( pCurrentScreen == SCREEN_GAME && uCurrentlyLoadedLevelType == LEVEL_Outdoor)
-    pWeather->Draw();//Ritor1: my include
-
-  //while(GetTickCount() - last_frame_time < 33 );//FPS control 
-  uint frame_dt = GetTickCount() - last_frame_time;
-  last_frame_time = GetTickCount();
-
-  framerate_time_elapsed += frame_dt;
-  if (framerate_time_elapsed >= 1000)
-  {
-    framerate = frames_this_second *  (1000.0f / framerate_time_elapsed);
-
-    framerate_time_elapsed = 0;
-    frames_this_second = 0;
-    render_framerate = true;
-  }
-
-  ++frames_this_second;
-
-  if ( debug_information )
-  {
-    if (render_framerate)
-    {
-      sprintf(pTmpBuf.data(), "FPS: % .4f", framerate);
-      pPrimaryWindow->DrawText(pFontArrus, 494, 0, Color16(0, 0, 0), pTmpBuf.data(), 0, 0, 0);
-    }
-
-    if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
-    {
-      int sector_id = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
-      sprintf(pTmpBuf.data(), "Party Sector ID:        %u/%u\n", sector_id, pIndoor->uNumSectors);
-      pPrimaryWindow->DrawText(pFontArrus, 16, 16, Color16(255, 255, 255), pTmpBuf.data(), 0, 0, Color16(255, 255, 255));
-    }
-    sprintf(pTmpBuf.data(), "Party Position:         % d % d % d", pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
-    pPrimaryWindow->DrawText(pFontArrus, 16, 16 + 16, Color16(255, 255, 255), pTmpBuf.data(), 0, 0, Color16(255, 255, 255));
-  
-    if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
-    {
-      uint uFaceID;
-      int sector_id = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
-      int floor_level = BLV_GetFloorLevel(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z + 40, sector_id, &uFaceID);
-      sprintf(pTmpBuf.data(), "BLV_GetFloorLevel: %d   face_id %d\n", floor_level, uFaceID);
-    }
-    else
-    {
-      int on_water, _a6;
-      int floor_level = ODM_GetFloorLevel(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z, 0, &on_water, &_a6, false);
-      sprintf(pTmpBuf.data(), "ODM_GetFloorLevel: %d   on_water: %s    a6 = %d\n", floor_level, on_water ? "true" : "false", _a6);
-    }
-    pPrimaryWindow->DrawText(pFontArrus, 16, 16 + 16 + 16, Color16(255, 255, 255), pTmpBuf.data(), 0, 0, Color16(255, 255, 255));
-  }
-
-  GUI_UpdateWindows();
-  pParty->UpdatePlayersAndHirelingsEmotions();
-
-  _unused_5B5924_is_travel_ui_drawn = false;
-  if (v4)
-    pMouse->bRedraw = true;
-  pMouse->ReadCursorWithItem();
-  pMouse->DrawCursor();
-  pMouse->Activate();
-  pRenderer->EndScene();
-  pRenderer->Present();
-  pParty->uFlags &= ~2;
-}
-
-//----- (0047A815) --------------------------------------------------------
-void Game::DrawParticles()
-{
-  pParticleEngine->Draw();
-}
-
-//----- (00463149) --------------------------------------------------------
-void Game::Loop()
-{
-  const char *pLocationName; // [sp-4h] [bp-68h]@74
-  bool bLoading; // [sp+10h] [bp-54h]@1
-  signed int v16; // [sp+14h] [bp-50h]@8
-  MSG Msg; // [sp+28h] [bp-3Ch]@20
-  char Source[64]; // [sp+44h] [bp-20h]@76
-
-  bLoading = sCurrentMenuID == MENU_LoadingProcInMainMenu;
-  SetCurrentMenuID((MENU_STATE)-1);
-  if (bLoading)
-  {
-    pParty->Reset();
-    uGameState = GAME_STATE_PLAYING;
-    LoadGame(uLoadGameUI_SelectedSlot);
-  }
-
-  for (uint i = 1; i < 5; ++i)
-    for (uint j = 1; j < 6; ++j)
-    {
-      sprintf(pTmpBuf.data(), "data\\lloyd%d%d.pcx", i, j);
-      remove(pTmpBuf.data());
-    }
-
-  LoadPlayerPortraintsAndVoices();
-  pIcons_LOD->_inlined_sub1();
-  if ( use_music_folder )
-    alSourcef (mSourceID, AL_GAIN, pSoundVolumeLevels[uMusicVolimeMultiplier]);
-  else
-    pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f);
-
-  while ( 2 )
-  {
-    v16 = 1;
-    pMessageQueue_50CBD0->Flush();
-
-    pPartyActionQueue->uNumActions = 0;
-    if (pParty->bTurnBasedModeOn)
-    {
-      pTurnEngine->End(false);
-      pParty->bTurnBasedModeOn = false;
-    }
-    DoPrepareWorld(bLoading, 1);
-    pEventTimer->Resume();
-    dword_6BE364_game_settings_1 |= GAME_SETTINGS_0080_SKIP_USER_INPUT_THIS_FRAME;
-    // uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions = 0;
-    pCurrentScreen = SCREEN_GAME;
-
-    //if ( pRenderer->pRenderD3D )
-      pGame->pVisInstance->_4C1A02();
-
-    bool game_finished = false;
-    do
-    {
-      while ( PeekMessageA(&Msg, 0, 0, 0, PM_REMOVE) )
-      {
-        if ( Msg.message == WM_QUIT )
-          Game_DeinitializeAndTerminate(0);
-        TranslateMessage(&Msg);
-        DispatchMessageA(&Msg);
-      }
-      if (dword_6BE364_game_settings_1 & GAME_SETTINGS_APP_INACTIVE)
-      {
-        WaitMessage();
-        continue;
-      }
-      pGame->_44EEA7();
-      GameUI_WritePointedObjectStatusString();
-      Keyboard::ProcessInputActions();
-      GameUI_MsgProc();
-      if ( pArcomageGame->bGameInProgress )
-      {
-        ArcomageGame::Loop();
-        pRenderer->Present();
-        continue;
-      }
-
-      pMediaPlayer->HouseMovieLoop();
-   
-      pEventTimer->Update();
-      pMiscTimer->Update();
-
-      OnTimer(0);
-      GameUI_StatusBar_UpdateTimedString(0);
-      if ( pMiscTimer->bPaused && !pEventTimer->bPaused )
-        pMiscTimer->Resume();
-      if ( pEventTimer->bTackGameTime && !pParty->bTurnBasedModeOn )
-        pEventTimer->bTackGameTime = 0;
-      if ( !pEventTimer->bPaused && uGameState == GAME_STATE_PLAYING)
-      {
-        if ( !pEventTimer->bTackGameTime )
-          _494035_timed_effects__water_walking_damage__etc();
-
-        if (dword_6BE364_game_settings_1 & GAME_SETTINGS_0001)
-          dword_6BE364_game_settings_1 &= ~GAME_SETTINGS_0001;
-        else
-        {
-          Actor::UpdateActorAI();
-          UpdateUserInput_and_MapSpecificStuff();
-        }
-      }
-      if ( v16 )
-      {
-        v16 = 0;
-        viewparams->bRedrawGameUI = true;
-      }
-      pAudioPlayer->UpdateSounds();
-      if ( (signed int)uGameState == GAME_STATE_PLAYING )
-      {
-        pGame->Draw();
-        continue;
-      }
-      if (uGameState == GAME_FINISHED)
-      {
-        game_finished = true;
-        continue;
-      }
-      if (uGameState == GAME_STATE_CHANGE_LOCATION)// ñìåíà ëîêàöèè
-      {
-        pAudioPlayer->StopChannels(-1, -1);
-        PrepareWorld(0);
-        uGameState = GAME_STATE_PLAYING;
-        continue;
-      }
-      if ( (signed int)uGameState <= GAME_STATE_5 || uGameState == GAME_STATE_GAME_QUITTING_TO_MAIN_MENU )//GAME_STATE_NEWGAME_OUT_GAMEMENU, GAME_STATE_LOADING_GAME
-      {
-        game_finished = true;
-        continue;
-      }
-      if ( uGameState == GAME_STATE_FINAL_WINDOW )
-      {
-        pRenderer->BeginScene();
-        GUI_UpdateWindows();
-        pRenderer->EndScene();
-        pRenderer->Present();
-        continue;
-      }
-      if ( uGameState != GAME_STATE_PARTY_DIED )
-      {
-        pGame->Draw();
-        continue;
-      }
-      if ( uGameState == GAME_STATE_PARTY_DIED )
-      {
-        pAudioPlayer->StopChannels(-1, -1);
-        memset(&pParty->pHirelings[0], 0, 0x4Cu);
-        memset(&pParty->pHirelings[1], 0, 0x4Cu);
-        for ( int i = 0; i < (signed int)pNPCStats->uNumNewNPCs; ++i )
-        {
-          if ( pNPCStats->pNewNPCData[i].field_24 )
-            pNPCStats->pNewNPCData[i].uFlags &= 0xFFFFFF7Fu;
-        }
-        pMediaPlayer->bStopBeforeSchedule = 0;
-        pMediaPlayer->PlayFullscreenMovie(MOVIE_Death, true);
-        if ( pMovie_Track )
-          pMediaPlayer->Unload();
-        SaveGame(0, 0);
-        ++pParty->uNumDeaths;
-        for ( uint i = 0; i < 4; ++i )
-          pParty->pPlayers[i].SetVariable(VAR_Award, 85);
-        pParty->days_played_without_rest = 0;
-        pParty->uTimePlayed += 0x276000ui64;
-        LOWORD(pParty->uFlags) &= ~0x204;
-        pParty->SetGold(0);
-        pOtherOverlayList->Reset();
-        memset(pParty->pPartyBuffs.data(), 0, 0x140u);
-
-        if ( pParty->bTurnBasedModeOn == 1 )
-        {
-          pTurnEngine->End(true);
-          pParty->bTurnBasedModeOn = 0;
-        }
-        for( int i = 0; i < 4; ++i)
-        {
-          memset(pParty->pPlayers[i].pConditions.data(), 0, 0xA0u);//(pConditions, 0, 160)
-          memset(pParty->pPlayers[i].pPlayerBuffs.data(), 0, 0x180u);//(pPlayerBuffs[0], 0, 384)
-          pParty->pPlayers[i].sHealth = 1;
-          uActiveCharacter = 1;
-        }
-        if (_449B57_test_bit(pParty->_quest_bits, PARTY_QUEST_FINISHED_EMERALD_ISLE))
-        {
-          pParty->vPosition.x = -17331;            // respawn in harmondale
-          pParty->vPosition.y = 12547;
-          pParty->vPosition.z = 465;
-          pParty->sRotationY = 0;
-          pLocationName = "out02.odm";
-        }
-        else
-        {
-          pParty->vPosition.x = 12552;             // respawn on emerald isle
-          pParty->vPosition.y = 1816;
-          pParty->vPosition.z = 0;
-          pParty->sRotationY = 512;
-          pLocationName = "out01.odm";
-        }
-        strcpy(Source, pLocationName);
-        pParty->uFallStartY = pParty->vPosition.z;
-        pParty->sRotationX = 0;
-        pParty->uFallSpeed = 0;
-        pParty->field_6E4 = 0;
-        pParty->field_6E0 = 0;
-        if ( _stricmp(Source, pCurrentMapName) )
-        {
-          strcpy(pCurrentMapName, Source);
-          _5B65A8_npcdata_uflags_or_other = pParty->vPosition.x;
-          _5B65AC_npcdata_fame_or_other = pParty->vPosition.y;
-          _5B65B0_npcdata_rep_or_other = pParty->vPosition.z;
-          _5B65B4_npcdata_loword_house_or_other = pParty->sRotationY;
-          _5B65B8_npcdata_hiword_house_or_other = pParty->sRotationX;
-          dword_5B65C0 = 1;
-          PrepareWorld(1);
-        }
-        Actor::InitializeActors();
-
-        int num_conscious_players = 0;
-        int conscious_players_ids[4] = {-1, -1, -1, -1};
-        for (int i = 0; i < 4; ++i)
-        {
-          if (pParty->pPlayers[i].CanAct())
-            conscious_players_ids[num_conscious_players++] = i;
-        }
-        if (num_conscious_players)
-        {
-          int idx = conscious_players_ids[rand() % num_conscious_players];
-          Assert(idx >= 0);
-          pParty->pPlayers[idx].PlaySound(SPEECH_99, 0);
-        }
-
-        ShowStatusBarString(pGlobalTXT_LocalizationStrings[524], 2);// "Once again you've cheated death!.." "Âû ñíîâà îáõèòðèëè ñìåðòü! …"
-        uGameState = GAME_STATE_PLAYING;
-      }
-    }
-    while (!game_finished);
-
-    pEventTimer->Pause();
-    ResetCursor_Palettes_LODs_Level_Audio_SFT_Windows();
-    if ( uGameState == GAME_STATE_LOADING_GAME )
-    {
-      sub_491E3A();
-      LoadPlayerPortraintsAndVoices();
-      uGameState = GAME_STATE_PLAYING;
-      pIcons_LOD->dword_11B84 = pIcons_LOD->uNumLoadedFiles;
-      bLoading = true;
-      continue;
-    }
-    break;
-  }
-  pCurrentScreen = SCREEN_VIDEO;
-  sub_491E3A();
-}
-
-
-//----- (0044F192) --------------------------------------------------------
-void Game::PrepareBloodsplats()
-{
-  for (uint i = 0; i < uNumBloodsplats; ++i)
-  {
-    pBloodsplatContainer->AddBloodsplat(pBloodsplats[i].x, pBloodsplats[i].y, pBloodsplats[i].z,
-        pBloodsplats[i].radius, pBloodsplats[i].r, pBloodsplats[i].g, pBloodsplats[i].b);
-   }
-}
-
-
-//----- (0044F120) --------------------------------------------------------
-void Game::PushStationaryLights(int a2)
-{
-  Game__StationaryLight* pLight;
- 
-  for( int i = 0; i < uNumStationaryLights; ++i ) 
-      {
-       pLight = &pStationaryLights[i];
-       pStationaryLightsStack->AddLight(pLight->vPosition.x, pLight->vPosition.y, pLight->vPosition.z,
-           pLight->flt_18, pLight->vRGBColor.x, pLight->vRGBColor.y, pLight->vRGBColor.z, _4E94D0_light_type);
-      }
-}
-// 4E94D0: using guessed type char _4E94D0_light_type;
-
-//----- (0044F0FD) --------------------------------------------------------
-void Game::_44F0FD()
-{
-  ToggleFlags(0x40u);
-
-  if ( !(uFlags & 0x40) )
-  {
-    uNumBloodsplats = 0;
-    field_E0C = 0;
-  }
-}
-
-//----- (0044F0D8) --------------------------------------------------------
-void Game::ToggleFlags(uint uMask)
-{
-  if (uFlags & uMask)
-    uFlags &= ~uMask;
-  else
-    uFlags |= uMask;
-}
-
-
-//----- (0044F07B) --------------------------------------------------------
-bool Game::_44F07B()
-{
-  if (!pKeyboardInstance->IsKeyBeingHeld(VK_SHIFT) && !pKeyboardInstance->IsKeyBeingHeld(VK_LSHIFT) &&
-      !pKeyboardInstance->IsKeyBeingHeld(VK_LSHIFT) || (pKeyboardInstance->WasKeyPressed(VK_F11) == 0 &&
-       pKeyboardInstance->WasKeyPressed(VK_F11)))
-    return true;
-  return false;
-}
-
-//----- (0044EEA7) --------------------------------------------------------
-bool Game::_44EEA7()
-{
-  //Game *v1; // esi@1
-  //double v2; // st7@2
-  float depth; // ST00_4@9
-  //bool result; // eax@9
-  //unsigned int v5; // eax@14
-  __int64 v6; // kr00_8@21
-  //unsigned int y; // [sp+4h] [bp-24h]@2
-  //unsigned int x; // [sp+8h] [bp-20h]@2
-  Vis_SelectionFilter *v10; // [sp+10h] [bp-18h]@2
-  Vis_SelectionFilter *v11; // [sp+14h] [bp-14h]@2
-  POINT cursor; // [sp+20h] [bp-8h]@1
-
-  //v1 = this;
-  ++qword_5C6DF0;
-  pParticleEngine->UpdateParticles();
-  pMouseInstance->GetCursorPos(&cursor);
-
-  //x = cursor.y;
-  //y = cursor.x;
-  if ( sub_4637E0_is_there_popup_onscreen() )
-  {
-    v11 = &vis_face_filter;
-    v10 = &vis_sprite_filter_2;
-    depth = pGame->pIndoorCameraD3D->GetPickDepth();
-  }
-  else
-  {
-    if ( uFlags2 & GAME_FLAGS_2_TARGETING_MODE )
-    {
-      v11 = &vis_face_filter;
-      v10 = &vis_sprite_filter_1;
-    }
-    else
-    {
-      v11 = &vis_face_filter;
-      v10 = &vis_sprite_filter_4;
-    }
-    depth = 5120.0;
-  }
-  //depth = v2;
-
-  PickMouse(depth, cursor.x, cursor.y, false, v10, v11);
-  pLightmapBuilder->std__vector_000004_size = 0;
-  pLightmapBuilder->std__vector_183808_size = 0;
-  pDecalBuilder->std__vector_pDecals_size = 0;
-  pDecalBuilder->field_308008 = 0;
-  if (!_44F07B())
-    return false;
-
-    if ( uFlags & GAME_FLAGS_1_DRAW_BLV_DEBUGS)
-      pStru10Instance->bDoNotDrawPortalFrustum = false;
-    if ( /*pRenderer->pRenderD3D &&*/ uCurrentlyLoadedLevelType == LEVEL_Outdoor)
-      pRenderer->uFogColor = GetLevelFogColor() & 0xFFFFFF;
-    if (uFlags & 0x0400)
-      uFlags2 |= 0x01;
-    /*if ( !pRenderer->pRenderD3D && uCurrentlyLoadedLevelType == LEVEL_Outdoor && pMobileLightsStack->uNumLightsActive )
-    {
-      uFlags2 |= 0x01;
-      field_E10 = qword_5C6DF0;
-    }*/
-    v6 = qword_5C6DF0 - field_E10;
-    if ( qword_5C6DF0 - field_E10 == 1 )
-      uFlags2 |= v6;
-    if (uNumStationaryLights_in_pStationaryLightsStack != pStationaryLightsStack->uNumLightsActive )
-    {
-      uFlags2 |= 1;
-      uNumStationaryLights_in_pStationaryLightsStack = pStationaryLightsStack->uNumLightsActive;
-    }
-    return true;
-}
-
-
-//----- (0044EDE4) --------------------------------------------------------
-bool Game::AlterGamma_BLV(BLVFace *pFace, signed int *pColor)
-{
-  if (uFlags2 & GAME_FLAGS_2_SATURATE_LIGHTMAPS &&
-      pFace->uAttributes & FACE_CAN_SATURATE_COLOR)
-  {
-    *pColor = ReplaceHSV(*pColor, 1.0, fSaturation, -1.0);
-    return true;
-  }
-  else
-    return false;
-}
-
-//----- (0044EE30) --------------------------------------------------------
-bool Game::AlterGamma_ODM(ODMFace *pFace, signed int *pColor)
-{
-  if (uFlags2 & GAME_FLAGS_2_SATURATE_LIGHTMAPS &&
-      pFace->uAttributes & FACE_CAN_SATURATE_COLOR)
-  {
-    *pColor = ReplaceHSV(*pColor, 1.0, fSaturation, -1.0);
-    return true;
-  }
-  else
-    return false;
-}
-
-
-//----- (004645FA) --------------------------------------------------------
-void Game::Deinitialize()
-{
-  WriteWindowsRegistryInt("startinwindow", 1);//pRenderer->bWindowMode);
-  //if (pRenderer->bWindowMode)
-  {
-    WriteWindowsRegistryInt("window X", window->GetX());
-    WriteWindowsRegistryInt("window Y", window->GetY());
-  }
-  WriteWindowsRegistryInt("valAlwaysRun", bAlwaysRun);
-  pItemsTable->Release();
-  pNPCStats->Release();
-
-  if (pMouse)
-    pMouse->Deactivate();
-
-  delete pRenderer;
-  pAudioPlayer->Release();//error
-  pNew_LOD->FreeSubIndexAndIO();
-  pGames_LOD->FreeSubIndexAndIO();
-  ClipCursor(0);
-  Game::Destroy();
-  delete pEventTimer;
-}
-
-//----- (0044EE7C) --------------------------------------------------------
-bool Game::draw_debug_outlines()
-{
-  if (uFlags & 0x04)
-  {
-    pLightmapBuilder->DrawDebugOutlines(-1);
-    pDecalBuilder->DrawDecalDebugOutlines();
-  }
-  return true;
-}
-
-//----- (0044EC23) --------------------------------------------------------
-int Game::_44EC23(struct Polygon *a2, int *a3, signed int a4)
-{
-  double v4; // st7@4
-  //double v5; // ST00_8@4
-  signed int v6; // eax@5
-  //double v7; // ST00_8@6
-  signed int result; // eax@8
-  //double v9; // ST00_8@9
-  //double v10; // ST00_8@11
-  float a2a; // [sp+14h] [bp+8h]@4
-  float a3a; // [sp+18h] [bp+Ch]@4
-  float a3b; // [sp+18h] [bp+Ch]@6
-  float a4a; // [sp+1Ch] [bp+10h]@9
-  float a4b; // [sp+1Ch] [bp+10h]@11
-
-  if ( this->uFlags2 & 2 && a2->field_59 == 5 && a2->pODMFace->uAttributes & 2 )
-  {
-    v4 = (double)a4;
-    a2a = v4;
-    *a3 |= 2u;
-    a3a = (1.0 - this->fSaturation) * v4;
-    //v5 = a3a + 6.7553994e15;
-    //if ( SLODWORD(v5) >= 0 )
-    if (floorf(a3a + 0.5f) >= 0 )
-    {
-      a3b = (1.0 - this->fSaturation) * a2a;
-      //v7 = a3b + 6.7553994e15;
-      //v6 = LODWORD(v7);
-      v6 = floorf(a3b + 0.5f);
-    }
-    else
-      v6 = 0;
-    if ( a4 >= v6 )
-    {
-      a4a = (1.0 - fSaturation) * a2a;
-      //v9 = a4a + 6.7553994e15;
-      //if ( SLODWORD(v9) >= 0 )
-      if (floorf(a4a + 0.5f) >= 0)
-      {
-        a4b = (1.0 - fSaturation) * a2a;
-        //v10 = a4b + 6.7553994e15;
-        //result = LODWORD(v10);
-        result = floorf(a4b + 0.5f);
-      }
-      else
-        result = 0;
-    }
-    else
-      result = a4;
-  }
-  else
-    result = -1;
-  return result;
-}
-
-
-
-//----- (00465C8B) --------------------------------------------------------
-Game *Game::Create()
-{
-  return new Game;
-}
-
-//----- (00465CF3) --------------------------------------------------------
-void Game::Destroy()
-{
-  delete pGame;
-  pGame = nullptr;
-}
-
-//----- (0044ED0A) --------------------------------------------------------
-signed int Game::_44ED0A(BLVFace *a2, int *a3, signed int a4)
-{
-  double v4; // st7@3
-  //double v5; // ST00_8@3
-  signed int v6; // eax@4
-  //double v7; // ST00_8@5
-  signed int result; // eax@7
-  //double v9; // ST00_8@8
-  //double v10; // ST00_8@10
-  float v11; // [sp+14h] [bp+8h]@3
-  float v12; // [sp+18h] [bp+Ch]@3
-  float v13; // [sp+18h] [bp+Ch]@5
-  float v14; // [sp+1Ch] [bp+10h]@8
-  float v15; // [sp+1Ch] [bp+10h]@10
-
-  if ( this->uFlags2 & 2 && a2->uAttributes & 2 )
-  {
-    v4 = (double)a4;
-    v11 = v4;
-    *a3 |= 2u;
-    v12 = (1.0 - this->fSaturation) * v4;
-    //v5 = v12 + 6.7553994e15;
-    if (floorf(v12 + 0.5f)/* SLODWORD(v5)*/ >= 0 )
-    {
-      v13 = (1.0 - this->fSaturation) * v11;
-      //v7 = v13 + 6.7553994e15;
-      //v6 = LODWORD(v7);
-      v6 = floorf(v13 + 0.5f);
-    }
-    else
-      v6 = 0;
-    if ( a4 >= v6 )
-    {
-      v14 = (1.0 - fSaturation) * v11;
-      //v9 = v14 + 6.7553994e15;
-      if (floorf(v14 + 0.5f)/* SLODWORD(v9)*/ >= 0 )
-      {
-        v15 = (1.0 - fSaturation) * v11;
-        //v10 = v15 + 6.7553994e15;
-        //result = LODWORD(v10);
-        result = floorf(v15 + 0.5f);
-      }
-      else
-        result = 0;
-    }
-    else
-      result = a4;
-  }
-  else
-    result = -1;
-  return result;
-}
-
-
-//----- (0044E4B7) --------------------------------------------------------
-Game::Game()
-{
-  uNumStationaryLights = 0;
-  uNumBloodsplats = 0;
-  field_E0C = 0;
-  field_E10 = 0;
-  uNumStationaryLights_in_pStationaryLightsStack = 0;
-  uFlags = 0;
-  uFlags2 = 0;
-
-  //pThreadWardInstance = new ThreadWard;
-  pThreadWardInstance = nullptr;
-  pParticleEngine = new ParticleEngine;
-  pMouse = pMouseInstance = new Mouse;
-  pLightmapBuilder = new LightmapBuilder;
-  pVisInstance = new Vis;
-  pStru6Instance = new stru6;
-  pIndoorCameraD3D = new IndoorCameraD3D;
-  pStru9Instance = new stru9;
-  pStru10Instance = new stru10;
-  //pStru11Instance = new stru11;
-  pStru11Instance = nullptr;
-  //pStru12Instance = new stru12(pStru11Instance);
-  pStru12Instance = nullptr;
-  //pCShow = new CShow;
-  pCShow = nullptr;
-  pKeyboardInstance = new Keyboard;
-  //pGammaController = new GammaController;
-
-  uFlags |= 0x0800;
-  uFlags2 |= 0x24;
-
-  _44F0FD();
-}
-
-//----- (0044E7F3) --------------------------------------------------------
-Game::~Game()
-{
-  //delete pGammaController;
-  delete pKeyboardInstance;
-/*delete pCShow;
-  delete pStru12Instance;
-  delete pStru11Instance;*/
-  delete pStru10Instance;
-  delete pStru9Instance;
-  delete pIndoorCameraD3D;
-  delete pStru6Instance;
-  delete pVisInstance;
-  delete pLightmapBuilder;
-  delete pMouseInstance;
-  delete pParticleEngine;
-//delete pThreadWardInstance;
-}
-
-//----- (0044EA5E) --------------------------------------------------------
-bool Game::PickMouse(float fPickDepth, unsigned int uMouseX, unsigned int uMouseY, bool bOutline, Vis_SelectionFilter *sprite_filter, Vis_SelectionFilter *face_filter)
-{
-  /*if (pCurrentScreen != SCREEN_GAME|| !pRenderer->pRenderD3D)
-    return false;*/
-
-  if (!pVisInstance)
-  {
-    MessageBoxW(nullptr, L"The 'Vis' object pointer has not been instatiated, but CGame::Pick() is trying to call through it.", nullptr, 0);
-    return false;
-  }
-
-  if (uMouseX >= (signed int)pViewport->uScreen_TL_X &&
-      uMouseX <= (signed int)pViewport->uScreen_BR_X &&
-      uMouseY >= (signed int)pViewport->uScreen_TL_Y &&
-      uMouseY <= (signed int)pViewport->uScreen_BR_Y)
-  {
-    pVisInstance->PickMouse(fPickDepth, uMouseX, uMouseY, sprite_filter, face_filter);
-
-    if (bOutline)
-      OutlineSelection();
-  }
-
-  return true;
-}
-// 4E28F8: using guessed type int pCurrentScreen;
-
-//----- (0044EB12) --------------------------------------------------------
-bool Game::PickKeyboard(bool bOutline, Vis_SelectionFilter *sprite_filter, Vis_SelectionFilter *face_filter)
-{
-  if (pCurrentScreen == SCREEN_GAME && pVisInstance /*&& pRenderer->pRenderD3D*/)
-  {
-    bool r = pVisInstance->PickKeyboard(&pVisInstance->default_list, sprite_filter, face_filter);
-
-    if (bOutline)
-      OutlineSelection();
-    return r;
-  }
-  return false;
-}
-/*
-Result::Code Game::PickKeyboard(bool bOutline, struct unnamed_F93E6C *a3, struct unnamed_F93E6C *a4)
-{
- if (dword_4E28F8_PartyCantJumpIfTrue)
-   return Result::Generic;
-
- pVis->PickKeyboard(a3, a4);
- if (bOutline)
-   Game_outline_selection((int)this);
- return Result::Success;
-}
-*/
-// 4E28F8: using guessed type int pCurrentScreen;
-
-//----- (0044EB5A) --------------------------------------------------------
-void Game::OutlineSelection()
-{
-  if (!pVisInstance)
-    return;
-
-  if (!pVisInstance->default_list.uNumPointers)
-    return;
-
-  Vis_ObjectInfo* object_info = pVisInstance->default_list.object_pointers[0];
-  if (object_info)
-    switch (object_info->object_type)
-    {
-      case VisObjectType_Sprite:
-      {
-        Log::Warning(L"Sprite outline currently unsupported");
-        return;
-      }
-
-      case VisObjectType_Face:
-      {
-        if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
-        {
-          ODMFace* face = (ODMFace *)object_info->object;
-          if (face->uAttributes & FACE_OUTLINED)
-            face->uAttributes &= ~FACE_OUTLINED;
-          else
-            face->uAttributes |= FACE_OUTLINED;
-        }
-        else if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
-        {
-          BLVFace* face = (BLVFace *)object_info->object;
-          if (face->uAttributes & FACE_OUTLINED)
-            face->uAttributes &= ~FACE_OUTLINED;
-          else
-            face->uAttributes |= FACE_OUTLINED;
-        }
-        else 
-          Error("Invalid level type", uCurrentlyLoadedLevelType);
-      }
-      break;
-
-      default:
-      {
-        MessageBoxW(nullptr, L"Undefined CObjectInfo type requested in CGame::outline_selection()", nullptr, 0);
-        ExitProcess(0);
-      }
-    }
-}
-
-
-
-void DoThatMessageThing()
-{
-    if (pMessageQueue_50CBD0->uNumMessages)
-        pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-}
-
-
-
-void Game_StartDialogue(unsigned int actor_id)
-{
-    if (uActiveCharacter)
-    {
-        viewparams->field_48 = 1;
-
-        DoThatMessageThing();
-
-        dword_5B65D0_dialogue_actor_npc_id = pActors[actor_id].sNPC_ID;
-        GameUI_InitializeDialogue(&pActors[actor_id], true);
-    }
-}
-
-void Game_StartHirelingDialogue(unsigned int hireling_id)
-{
-    if (bNoNPCHiring || pCurrentScreen != 0)
-        return;
-
-    DoThatMessageThing();
-
-    uint hireling_slot = 0;
-    for (uint i = 0; i < 2; ++i)
-    {
-        if (pParty->pHirelings[i].pName)
-            pTmpBuf[hireling_slot++] = i;
-    }
-
-    for (uint i = 0; i < pNPCStats->uNumNewNPCs; ++i)
-    {
-        NPCData *npc = &pNPCStats->pNewNPCData[i];
-        if (npc->Hired()
-            && (!pParty->pHirelings[0].pName || strcmp(npc->pName, pParty->pHirelings[0].pName))
-            && (!pParty->pHirelings[1].pName || strcmp(npc->pName, pParty->pHirelings[1].pName)))
-            {
-                pTmpBuf[hireling_slot++] = i + 2;
-            }
-        }
-
-        if ((signed int)hireling_id + (signed int)pParty->hirelingScrollPosition < hireling_slot)
-        {
-            Actor actor;
-            memset(&actor, 0, sizeof(actor));
-            actor.sNPC_ID += -1 - pParty->hirelingScrollPosition - hireling_id;
-            GameUI_InitializeDialogue(&actor, true);
-        }
-}
-
-
-void Game_StartNewGameWhilePlaying(bool force_start)
-{
-    if (dword_6BE138 == 124 || force_start)
-    {
-        pIcons_LOD->SyncLoadedFilesCount();
-        pIcons_LOD->RemoveTexturesPackFromTextureList();
-        DoThatMessageThing();
-        pGUIWindow_CurrentMenu->Release();
-        uGameState = GAME_STATE_NEWGAME_OUT_GAMEMENU;
-        pCurrentScreen = SCREEN_GAME;
-        viewparams->bRedrawGameUI = 1;
-    }
-    else
-    {
-        ShowStatusBarString(pGlobalTXT_LocalizationStrings[201], 2);// "Are you sure?  Click again to start a New Game"
-        pAudioPlayer->PlaySound(SOUND_quest, 0, 0, -1, 0, 0, 0, 0);
-        dword_6BE138 = 124;
-    }
-    stru_506E40.Release();
-}
-
-void Game_QuitGameWhilePlaying(bool force_quit)
-{
-    if (dword_6BE138 == 132 || force_quit)
-    {
-        pIcons_LOD->SyncLoadedFilesCount();
-        pIcons_LOD->RemoveTexturesPackFromTextureList();
-        if (pMessageQueue_50CBD0->uNumMessages)
-            pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-        pGUIWindow_CurrentMenu->Release();
-        pCurrentScreen = SCREEN_GAME;
-        viewparams->bRedrawGameUI = 1;
-        pAudioPlayer->PlaySound(SOUND_WoodDoorClosing, 0, 0, -1, 0, 0, 0, 0);
-        uGameState = GAME_STATE_GAME_QUITTING_TO_MAIN_MENU;
-    }
-    else
-    {
-        ShowStatusBarString(pGlobalTXT_LocalizationStrings[82], 2);// "Are you sure?  Click again to quit"
-        pAudioPlayer->PlaySound(SOUND_quest, 0, 0, -1, 0, 0, 0, 0);
-        dword_6BE138 = 132;
-    }
-    stru_506E40.Release();
-}
-
-void Game_OpenLoadGameDialog()
-{
-    pIcons_LOD->SyncLoadedFilesCount();
-    pIcons_LOD->RemoveTexturesPackFromTextureList();
-    DoThatMessageThing();
-    pGUIWindow_CurrentMenu->Release();
-    pCurrentScreen = SCREEN_LOADGAME;
-    LoadUI_Load(1);
-}
-
-
-
-//----- (004304E7) --------------------------------------------------------
-void GameUI_MsgProc()
-{
-  unsigned int v2; // edx@7
-  Actor *pActor; // ecx@13
-  int v4; // ecx@18
-  unsigned int v10; // ecx@73
-  int v14; // eax@98
-  int v18; // eax@106
-  float v19; // ST64_4@121
-  float v21; // ST64_4@126
-  float v22; // ST64_4@127
-  unsigned int v24; // ecx@149
-  GUIWindow *pWindow2; // ecx@248
-  bool pKeyBindingFlag; // eax@269
-  unsigned int v33; // eax@277
-  int v37; // eax@341
-  int v38; // eax@358
-  SHORT v39; // ax@365
-  char *v41; // eax@380
-  int v42; // eax@396
-  signed int v44; // eax@398
-  int v45; // edx@398
-  signed int v46; // ecx@398
-  char v47; // zf@399
-  char v48; // zf@405
-  BLVFace *pBLVFace; // ecx@410
-  ODMFace *pODMFace; // ecx@412
-  CastSpellInfo *pSpellInfo; // ecx@415
-  __int16 v53; // ax@431
-  int v54; // eax@432
-  int v55; // ecx@432
-  int v56; // edx@432
-  int v57; // eax@432
-  Player *pPlayer; // edx@442
-  unsigned int pMapNum; // eax@445
-  signed int v60; // ST64_4@459
-  __int16 v63; // dx@479
-  unsigned int v64; // eax@486
-  int v65; // ecx@486
-  int v66; // eax@488
-  char *v67; // eax@489
-  __int16 v68; // dx@498
-  char *v69; // eax@512
-  int v70; // eax@525
-  int v71; // edi@527
-  NPCData *pNPCData3; // esi@527
-  char *v73; // ecx@533
-  signed int v74; // edi@535
-  int v75; // eax@535
-  int v76; // esi@535
-  int v77; // eax@537
-  Player *pPlayer2; // ecx@549
-  signed int v81; // eax@552
-  signed int v83; // ecx@554
-  signed int v84; // ecx@554
-  GUIButton *pButton; // eax@578
-  unsigned int v86; // eax@583
-  const char *v87; // ecx@595
-  const char *v88; // ecx@596
-  unsigned int v90; // eax@602
-  int v91; // edx@605
-  int v92; // eax@605
-  int v93; // edx@605
-  int pPlayerNum; // edx@611
-  int v95; // eax@611
-  unsigned int v97; // eax@624
-  int v98; // eax@636
-  int v103; // eax@671
-  Player *pPlayer4; // ecx@718
-  int v105; // eax@718
-  Player *pPlayer5; // ST78_4@758
-  unsigned int v107; // eax@758
-  unsigned int v108; // eax@758
-  unsigned int v115; // eax@764
-  int v116; // eax@776
-  unsigned int v118; // eax@785
-  unsigned int v119; // ecx@786
-  unsigned int v121; // [sp-28h] [bp-624h]@711
-  unsigned int v123; // [sp-24h] [bp-620h]@711
-  unsigned int v125; // [sp-20h] [bp-61Ch]@711
-  int v127; // [sp-1Ch] [bp-618h]@107
-  unsigned int v128; // [sp-1Ch] [bp-618h]@711
-  GUIButton *pButton2; // [sp-4h] [bp-600h]@59
-  const char *v161; // [sp-4h] [bp-600h]@637
-  KeyToggleType pKeyToggleType; // [sp+0h] [bp-5FCh]@287
-  char *v173; // [sp+0h] [bp-5FCh]@444
-  char *v174; // [sp+0h] [bp-5FCh]@449
-  const char *v177; // [sp+0h] [bp-5FCh]@629
-  char *v178; // [sp+0h] [bp-5FCh]@637
-  signed int thisb; // [sp+14h] [bp-5E8h]@272
-  Player *pPlayer7; // [sp+14h] [bp-5E8h]@373
-  Player *pPlayer8; // [sp+14h] [bp-5E8h]@377
-  char *pMapName; // [sp+14h] [bp-5E8h]@445
-  Player *pPlayer9; // [sp+14h] [bp-5E8h]@455
-  int thisg; // [sp+14h] [bp-5E8h]@467
-  int thish; // [sp+14h] [bp-5E8h]@528
-  signed int thisi; // [sp+14h] [bp-5E8h]@535
-  MapInfo *pMapInfo; // [sp+14h] [bp-5E8h]@604
-  Player *pPlayer10; // [sp+14h] [bp-5E8h]@641
-  int uMessageParam; // [sp+18h] [bp-5E4h]@7
-  int uAction; // [sp+1Ch] [bp-5E0h]@18
-  NPCData *pNPCData4; // [sp+20h] [bp-5DCh]@23
-  unsigned int uNumSeconds; // [sp+24h] [bp-5D8h]@18
-  char v197; // [sp+2Bh] [bp-5D1h]@101
-  enum UIMessageType uMessage; // [sp+2Ch] [bp-5D0h]@7
-  unsigned int v199; // [sp+30h] [bp-5CCh]@7
-  char *v200; // [sp+34h] [bp-5C8h]@518
-  POINT v202; // [sp+40h] [bp-5BCh]@141
-  POINT a2; // [sp+48h] [bp-5B4h]@127
-  POINT v205; // [sp+58h] [bp-5A4h]@171
-  POINT v207; // [sp+68h] [bp-594h]@155
-  POINT v211; // [sp+88h] [bp-574h]@704
-  int v213; // [sp+98h] [bp-564h]@385
-  char pLevelName[32]; // [sp+9Ch] [bp-560h]@380
-  char pOut[32]; // [sp+BCh] [bp-540h]@370
-  FrameTableTxtLine v216; // [sp+DCh] [bp-520h]@524
-  int v217[9]; // [sp+158h] [bp-4A4h]@652
-  FrameTableTxtLine v218; // [sp+17Ch] [bp-480h]@524
-  char a1[64]; // [sp+1F8h] [bp-404h]@467
-  char Str2[128]; // [sp+238h] [bp-3C4h]@527
-  Actor actor; // [sp+2B8h] [bp-344h]@4
-  int currHour;
-
-  dword_50CDC8 = 0;
-  if ( !pEventTimer->bPaused )
-  {
-    pParty->sEyelevel = pParty->uDefaultEyelevel;
-    pParty->uPartyHeight = pParty->uDefaultPartyHeight;
-  }
-  if ( bDialogueUI_InitializeActor_NPC_ID )
-  {
-    //Actor::Actor(&actor);
-    memset(&actor, 0, 0x344u);
-    dword_5B65D0_dialogue_actor_npc_id = bDialogueUI_InitializeActor_NPC_ID;
-    actor.sNPC_ID = bDialogueUI_InitializeActor_NPC_ID;
-    GameUI_InitializeDialogue(&actor, false);
-    bDialogueUI_InitializeActor_NPC_ID = 0;
-  }
-  if ( pMessageQueue_50CBD0->uNumMessages )
-  {
-    //v1 = "";
-    while ( 2 )
-    {
-      if ( !pMessageQueue_50CBD0->uNumMessages )
-        break;
-
-      pMessageQueue_50CBD0->PopMessage(&uMessage, &uMessageParam, (int *)&v199);
-      switch ( uMessage )
-      {
-        case UIMSG_ChangeGameState:
-          uGameState = GAME_FINISHED;
-          continue;
-        case UIMSG_PlayArcomage:
-          BackToHouseMenu();
-          pArcomageGame->bGameInProgress = 1;
-          ArcomageGame::PrepareArcomage();
-          continue;
-
-        case UIMSG_StartNPCDialogue:          Game_StartDialogue(uMessageParam); continue;
-        case UIMSG_StartHireling1Dialogue:
-        case UIMSG_StartHireling2Dialogue:    Game_StartHirelingDialogue(uMessage - UIMSG_StartHireling1Dialogue); continue;
-        case UIMSG_BuyInShop_Identify_Repair: UIShop_Buy_Identify_Repair(); continue;
-        case UIMSG_ClickNPCTopic:             ClickNPCTopic(uMessageParam); continue;
-        case UIMSG_SelectShopDialogueOption:  OnSelectShopDialogueOption(uMessageParam); continue;
-        case UIMSG_SelectNPCDialogueOption:   OnSelectNPCDialogueOption((DIALOGUE_TYPE)uMessageParam); continue;
-        case UIMSG_ClickHouseNPCPortrait:     _4B4224_UpdateNPCTopics(uMessageParam); continue;
-        case UIMSG_StartNewGame:              Game_StartNewGameWhilePlaying(uMessageParam); continue;
-        case UIMSG_Game_OpenLoadGameDialog:   Game_OpenLoadGameDialog(); continue;
-        case UIMSG_Quit:                      Game_QuitGameWhilePlaying(uMessageParam); continue;
-        case UIMSG_80:
-			__debugbreak();
-          pIcons_LOD->SyncLoadedFilesCount();
-          pIcons_LOD->RemoveTexturesPackFromTextureList();
-          pGUIWindow_CurrentMenu->Release();
-          pCurrentScreen = SCREEN_OPTIONS;
-          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_8, 0, 0);
-          continue;
-        case UIMSG_ArrowUp:
-          --pSaveListPosition;
-          if ( pSaveListPosition < 0 )
-            pSaveListPosition = 0;
-          GUIWindow::Create(215, 199, 17, 17, WINDOW_PressedButton2, (int)pBtnArrowUp, 0);
-          continue;
-        case UIMSG_DownArrow:
-          ++pSaveListPosition;
-          if ( pSaveListPosition >= uMessageParam )
-            pSaveListPosition = uMessageParam - 1;
-          GUIWindow::Create(215, 323, 17, 17, WINDOW_PressedButton2, (int)pBtnDownArrow, 0);
-          continue;
-        case UIMSG_Cancel:
-          GUIWindow::Create(350, 302, 106, 42, WINDOW_CloseRestWindowBtn, (int)pBtnCancel, 0);
-          continue;
-        case UIMSG_SaveLoadBtn:
-          GUIWindow::Create(241, 302, 106, 42, WINDOW_SaveLoadBtn, (int)pBtnLoadSlot, 0);
-          continue;
-        case UIMSG_SelectLoadSlot:
-          if ( pGUIWindow_CurrentMenu->receives_keyboard_input_2 == WINDOW_INPUT_IN_PROGRESS)
-            pKeyActionMap->SetWindowInputStatus(WINDOW_INPUT_NONE);
-          if ( pCurrentScreen != SCREEN_SAVEGAME || uLoadGameUI_SelectedSlot != pSaveListPosition + uMessageParam )
-          {
-            v10 = pSaveListPosition + uMessageParam;
-            if ( dword_6BE138 == pSaveListPosition + uMessageParam )
-            {
-              pMessageQueue_50CBD0->AddGUIMessage(UIMSG_SaveLoadBtn, 0, 0);
-              pMessageQueue_50CBD0->AddGUIMessage(UIMSG_LoadGame, 0, 0);
-            }
-            uLoadGameUI_SelectedSlot = v10;
-            dword_6BE138 = v10;
-          }
-          else
-          {
-            pKeyActionMap->EnterText(0, 19, pGUIWindow_CurrentMenu);
-            if ( strcmp(pSavegameHeader[uLoadGameUI_SelectedSlot].pName, pGlobalTXT_LocalizationStrings[72]) )// "Empty"
-              strcpy(pKeyActionMap->pPressedKeysBuffer, pSavegameHeader[uLoadGameUI_SelectedSlot].pName);
-            pKeyActionMap->uNumKeysPressed = strlen(pKeyActionMap->pPressedKeysBuffer);
-          }
-          continue;
-        case UIMSG_LoadGame:
-          if ( pSavegameUsedSlots[uLoadGameUI_SelectedSlot] )
-          {
-            LoadGame(uLoadGameUI_SelectedSlot);
-            uGameState = GAME_STATE_LOADING_GAME;
-          }
-          stru_506E40.Release();
-          continue;
-        case UIMSG_SaveGame:
-          if ( pGUIWindow_CurrentMenu->receives_keyboard_input_2 == WINDOW_INPUT_IN_PROGRESS)
-          {
-            pKeyActionMap->SetWindowInputStatus(WINDOW_INPUT_NONE);
-            strcpy((char *)&pSavegameHeader[uLoadGameUI_SelectedSlot], pKeyActionMap->pPressedKeysBuffer);
-          }
-          DoSavegame(uLoadGameUI_SelectedSlot);
-          stru_506E40.Release();
-          continue;
-        case UIMSG_Game_OpenSaveGameDialog:
-          pGUIWindow_CurrentMenu->Release();
-          pCurrentScreen = SCREEN_SAVEGAME;
-          SaveUI_Load();
-          continue;
-        case UIMSG_Game_OpenOptionsDialog://Open
-          if ( pMessageQueue_50CBD0->uNumMessages )
-            pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-          pGUIWindow_CurrentMenu->Release();
-          viewparams->field_48 = 1;
-          pCurrentScreen = SCREEN_OPTIONS;
-
-          options_menu_skin.uTextureID_Background     = pIcons_LOD->LoadTexture("ControlBG", TEXTURE_16BIT_PALETTE);
-          options_menu_skin.uTextureID_TurnSpeed[2]   = pIcons_LOD->LoadTexture("con_16x", TEXTURE_16BIT_PALETTE);
-          options_menu_skin.uTextureID_TurnSpeed[1]   = pIcons_LOD->LoadTexture("con_32x", TEXTURE_16BIT_PALETTE);
-          options_menu_skin.uTextureID_TurnSpeed[0]   = pIcons_LOD->LoadTexture("con_Smoo", TEXTURE_16BIT_PALETTE);
-          options_menu_skin.uTextureID_ArrowLeft      = pIcons_LOD->LoadTexture("con_ArrL", TEXTURE_16BIT_PALETTE);
-          options_menu_skin.uTextureID_ArrowRight     = pIcons_LOD->LoadTexture("con_ArrR", TEXTURE_16BIT_PALETTE);
-          options_menu_skin.uTextureID_SoundLevels[0] = pIcons_LOD->LoadTexture("convol10", TEXTURE_16BIT_PALETTE);
-          options_menu_skin.uTextureID_SoundLevels[1] = pIcons_LOD->LoadTexture("convol20", TEXTURE_16BIT_PALETTE);
-          options_menu_skin.uTextureID_SoundLevels[2] = pIcons_LOD->LoadTexture("convol30", TEXTURE_16BIT_PALETTE);
-          options_menu_skin.uTextureID_SoundLevels[3] = pIcons_LOD->LoadTexture("convol40", TEXTURE_16BIT_PALETTE);
-          options_menu_skin.uTextureID_SoundLevels[4] = pIcons_LOD->LoadTexture("convol50", TEXTURE_16BIT_PALETTE);
-          options_menu_skin.uTextureID_SoundLevels[5] = pIcons_LOD->LoadTexture("convol60", TEXTURE_16BIT_PALETTE);
-          options_menu_skin.uTextureID_SoundLevels[6] = pIcons_LOD->LoadTexture("convol70", TEXTURE_16BIT_PALETTE);
-          options_menu_skin.uTextureID_SoundLevels[7] = pIcons_LOD->LoadTexture("convol80", TEXTURE_16BIT_PALETTE);
-          options_menu_skin.uTextureID_SoundLevels[8] = pIcons_LOD->LoadTexture("convol90", TEXTURE_16BIT_PALETTE);
-          options_menu_skin.uTextureID_SoundLevels[9] = pIcons_LOD->LoadTexture("convol00", TEXTURE_16BIT_PALETTE);
-          options_menu_skin.uTextureID_FlipOnExit     = pIcons_LOD->LoadTexture("option04", TEXTURE_16BIT_PALETTE);
-          options_menu_skin.uTextureID_AlwaysRun      = pIcons_LOD->LoadTexture("option03", TEXTURE_16BIT_PALETTE);
-          options_menu_skin.uTextureID_ShowDamage     = pIcons_LOD->LoadTexture("option02", TEXTURE_16BIT_PALETTE);
-          options_menu_skin.uTextureID_WalkSound      = pIcons_LOD->LoadTexture("option01", TEXTURE_16BIT_PALETTE);
-
-          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Options, 0, 0);
-          pGUIWindow_CurrentMenu->CreateButton(22, 270,
-                                               pIcons_LOD->GetTexture(options_menu_skin.uTextureID_TurnSpeed[2])->uTextureWidth,
-                                               pIcons_LOD->GetTexture(options_menu_skin.uTextureID_TurnSpeed[2])->uTextureHeight,
-                                               1, 0, UIMSG_SetTurnSpeed, 0x80, 0, "", 0);
-          pGUIWindow_CurrentMenu->CreateButton(93, 270,
-                                               pIcons_LOD->GetTexture(options_menu_skin.uTextureID_TurnSpeed[1])->uTextureWidth,
-                                               pIcons_LOD->GetTexture(options_menu_skin.uTextureID_TurnSpeed[1])->uTextureHeight,
-                                               1, 0, UIMSG_SetTurnSpeed, 0x40u, 0, "", 0);
-          pGUIWindow_CurrentMenu->CreateButton(164, 270,
-                                               pIcons_LOD->GetTexture(options_menu_skin.uTextureID_TurnSpeed[0])->uTextureWidth,
-                                               pIcons_LOD->GetTexture(options_menu_skin.uTextureID_TurnSpeed[0])->uTextureHeight,
-                                               1, 0, UIMSG_SetTurnSpeed, 0, 0, "", 0);
-
-          pGUIWindow_CurrentMenu->CreateButton(20, 303,
-                                               pIcons_LOD->GetTexture(options_menu_skin.uTextureID_WalkSound)->uTextureWidth,
-                                               pIcons_LOD->GetTexture(options_menu_skin.uTextureID_WalkSound)->uTextureHeight,
-                                               1, 0, UIMSG_ToggleWalkSound, 0, 0, "", 0);
-          pGUIWindow_CurrentMenu->CreateButton(128, 303,
-                                               pIcons_LOD->GetTexture(options_menu_skin.uTextureID_ShowDamage)->uTextureWidth,
-                                               pIcons_LOD->GetTexture(options_menu_skin.uTextureID_ShowDamage)->uTextureHeight,
-                                               1, 0, UIMSG_ToggleShowDamage, 0, 0, "", 0);
-          pGUIWindow_CurrentMenu->CreateButton(20, 325,
-                                               pIcons_LOD->GetTexture(options_menu_skin.uTextureID_AlwaysRun)->uTextureWidth,
-                                               pIcons_LOD->GetTexture(options_menu_skin.uTextureID_AlwaysRun)->uTextureHeight,
-                                               1, 0, UIMSG_ToggleAlwaysRun, 0, 0, "", 0);
-          pGUIWindow_CurrentMenu->CreateButton(128, 325,
-                                               pIcons_LOD->GetTexture(options_menu_skin.uTextureID_FlipOnExit)->uTextureWidth,
-                                               pIcons_LOD->GetTexture(options_menu_skin.uTextureID_FlipOnExit)->uTextureHeight,
-                                               1, 0, UIMSG_ToggleFlipOnExit, 0, 0, "", 0);
-
-          pBtn_SliderLeft  = pGUIWindow_CurrentMenu->CreateButton(243, 162, 16, 16, 1, 0, UIMSG_ChangeSoundVolume, 4, 0, "", pIcons_LOD->GetTexture(options_menu_skin.uTextureID_ArrowLeft), 0);
-          pBtn_SliderRight = pGUIWindow_CurrentMenu->CreateButton(435, 162, 16, 16, 1, 0, UIMSG_ChangeSoundVolume, 5, 0, "", pIcons_LOD->GetTexture(options_menu_skin.uTextureID_ArrowRight), 0);
-          pGUIWindow_CurrentMenu->CreateButton(263, 162, 172, 17, 1, 0, UIMSG_ChangeSoundVolume, 0, 0, "", 0);
-
-          pBtn_SliderLeft  = pGUIWindow_CurrentMenu->CreateButton(243, 216, 16, 16, 1, 0, UIMSG_ChangeMusicVolume, 4, 0, "", pIcons_LOD->GetTexture(options_menu_skin.uTextureID_ArrowLeft), 0);
-          pBtn_SliderRight = pGUIWindow_CurrentMenu->CreateButton(435, 216, 16, 16, 1, 0, UIMSG_ChangeMusicVolume, 5, 0, "", pIcons_LOD->GetTexture(options_menu_skin.uTextureID_ArrowRight), 0);
-          pGUIWindow_CurrentMenu->CreateButton(263, 216, 172, 17, 1, 0, UIMSG_ChangeMusicVolume, 0, 0, "", 0);
-
-          pBtn_SliderLeft  = pGUIWindow_CurrentMenu->CreateButton(243, 270, 16, 16, 1, 0, UIMSG_ChangeVoiceVolume, 4, 0, "", pIcons_LOD->GetTexture(options_menu_skin.uTextureID_ArrowLeft), 0);
-          pBtn_SliderRight = pGUIWindow_CurrentMenu->CreateButton(435, 270, 16, 16, 1, 0, UIMSG_ChangeVoiceVolume, 5, 0, "", pIcons_LOD->GetTexture(options_menu_skin.uTextureID_ArrowRight), 0);
-          pGUIWindow_CurrentMenu->CreateButton(263, 270, 172, 17, 1, 0, UIMSG_ChangeVoiceVolume, 0, 0, "", 0);
-
-          pGUIWindow_CurrentMenu->CreateButton(241, 302, 214, 40, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[619], 0); // "Return to Game"
-          pGUIWindow_CurrentMenu->CreateButton( 19, 140, 214, 40, 1, 0, UIMSG_OpenKeyMappingOptions, 0, 0x4Bu, "", 0);
-          pGUIWindow_CurrentMenu->CreateButton( 19, 194, 214, 40, 1, 0, UIMSG_OpenVideoOptions, 0, 86, "", 0);
-          continue;
-
-        case UIMSG_OpenKeyMappingOptions://Open
-          if ( pMessageQueue_50CBD0->uNumMessages )
-            pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-          pGUIWindow_CurrentMenu->Release();
-          viewparams->field_48 = 1;
-          pCurrentScreen = SCREEN_KEYBOARD_OPTIONS;
-          uTextureID_Optkb[0] = pIcons_LOD->LoadTexture("optkb", TEXTURE_16BIT_PALETTE);
-          uTextureID_Optkb[1] = pIcons_LOD->LoadTexture("optkb_h", TEXTURE_16BIT_PALETTE);
-          uTextureID_Optkb[2] = pIcons_LOD->LoadTexture("resume1", TEXTURE_16BIT_PALETTE);
-          uTextureID_Optkb[3] = pIcons_LOD->LoadTexture("optkb_1", TEXTURE_16BIT_PALETTE);
-          uTextureID_Optkb[4] = pIcons_LOD->LoadTexture("optkb_2", TEXTURE_16BIT_PALETTE);
-          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_KeyMappingOptions, 0, 0);
-
-          pGUIWindow_CurrentMenu->CreateButton(241, 302, 214, 40, 1, 0, UIMSG_Escape, 0, 0, "", 0);
-
-          pGUIWindow_CurrentMenu->CreateButton(19, 302, 108, 20, 1, 0, UIMSG_SelectKeyPage1, 0, 0, "", 0);
-          pGUIWindow_CurrentMenu->CreateButton(127, 302, 108, 20, 1, 0, UIMSG_SelectKeyPage2, 0, 0, "", 0);
-          pGUIWindow_CurrentMenu->CreateButton(127, 324, 108, 20, 1, 0, UIMSG_ResetKeyMapping, 0, 0, "", 0);
-          pGUIWindow_CurrentMenu->CreateButton(19, 324, 108, 20, 1, 0, UIMSG_Game_OpenOptionsDialog, 0, 0, "", 0);
-
-          pGUIWindow_CurrentMenu->CreateButton(129, 148, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 0, 0, "", 0);
-          pGUIWindow_CurrentMenu->CreateButton(129, 167, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 1, 0, "", 0);
-          pGUIWindow_CurrentMenu->CreateButton(129, 186, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 2, 0, "", 0);
-          pGUIWindow_CurrentMenu->CreateButton(129, 205, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 3, 0, "", 0);
-          pGUIWindow_CurrentMenu->CreateButton(129, 224, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 4, 0, "", 0);
-          pGUIWindow_CurrentMenu->CreateButton(129, 243, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 5, 0, "", 0);
-          pGUIWindow_CurrentMenu->CreateButton(129, 262, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 6, 0, "", 0);
-          pGUIWindow_CurrentMenu->CreateButton(350, 148, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 7, 0, "", 0);
-          pGUIWindow_CurrentMenu->CreateButton(350, 167, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 8, 0, "", 0);
-          pGUIWindow_CurrentMenu->CreateButton(350, 186, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 9, 0, "", 0);
-          pGUIWindow_CurrentMenu->CreateButton(350, 205, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 10, 0, "", 0);
-          pGUIWindow_CurrentMenu->CreateButton(350, 224, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 11, 0, "", 0);
-          pGUIWindow_CurrentMenu->CreateButton(350, 243, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 12, 0, "", 0);
-          pGUIWindow_CurrentMenu->CreateButton(350, 262, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 13, 0, "", 0);
-
-          uGameMenuUI_CurentlySelectedKeyIdx = -1;
-          KeyboardPageNum = 1;
-          memset(GameMenuUI_InvaligKeyBindingsFlags.data(), 0, sizeof(GameMenuUI_InvaligKeyBindingsFlags));
-          //*(_WORD *)KeyButtonArray[28] = 0;
-          memcpy(pPrevVirtualCidesMapping.data(), pKeyActionMap->pVirtualKeyCodesMapping, 0x78u);
-          continue;
-        case UIMSG_ChangeKeyButton:
-          if ( uGameMenuUI_CurentlySelectedKeyIdx != -1 )
-          {
-            pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);
-            continue;
-          }
-          v14 = uMessageParam;
-          if ( KeyboardPageNum != 1 )
-            v14 = uMessageParam + 14;
-          uGameMenuUI_CurentlySelectedKeyIdx = v14;
-          pKeyActionMap->EnterText(0, 1, pGUIWindow_CurrentMenu);
-          continue;
-        case UIMSG_ResetKeyMapping:
-          v197 = 1;
-          pKeyActionMap->SetDefaultMapping();
-          for ( uint i = 0; i < 28; i++ )
-          {
-            if ( pKeyActionMap->GetActionVKey((enum InputAction)i) != pPrevVirtualCidesMapping[i] )
-            {
-              if ( v197 )
-              {
-                GUI_ReplaceHotkey(LOBYTE(pPrevVirtualCidesMapping[i]), pKeyActionMap->GetActionVKey((enum InputAction)i), 1);
-                v197 = 0;
-              }
-              else
-                GUI_ReplaceHotkey(LOBYTE(pPrevVirtualCidesMapping[i]), pKeyActionMap->GetActionVKey((enum InputAction)i), 0);
-            }
-            pPrevVirtualCidesMapping[i] = pKeyActionMap->GetActionVKey((enum InputAction)i);
-            GameMenuUI_InvaligKeyBindingsFlags[i] = false;
-          }
-          pAudioPlayer->PlaySound(SOUND_chimes, 0, 0, -1, 0, 0, 0, 0);
-          continue;
-        case UIMSG_SelectKeyPage1:
-          KeyboardPageNum = 1;
-          continue;
-        case UIMSG_SelectKeyPage2:
-          KeyboardPageNum = 2;
-          continue;
-        case UIMSG_OpenVideoOptions:
-          if ( pMessageQueue_50CBD0->uNumMessages )
-            pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-          pGUIWindow_CurrentMenu->Release();
-          viewparams->field_48 = 1;
-          pCurrentScreen = SCREEN_VIDEO_OPTIONS;
-          optvid_base_texture_id = pIcons_LOD->LoadTexture("optvid", TEXTURE_16BIT_PALETTE);
-          bloodsplats_texture_id = pIcons_LOD->LoadTexture("opvdH-bs", TEXTURE_16BIT_PALETTE);
-          us_colored_lights_texture_id = pIcons_LOD->LoadTexture("opvdH-cl", TEXTURE_16BIT_PALETTE);
-          tinting_texture_id = pIcons_LOD->LoadTexture("opvdH-tn", TEXTURE_16BIT_PALETTE);
-          uTextureID_507C20 = pIcons_LOD->LoadTexture("con_ArrL", TEXTURE_16BIT_PALETTE);
-          uTextureID_507C24 = pIcons_LOD->LoadTexture("con_ArrR", TEXTURE_16BIT_PALETTE);
-          pTextureIDs_GammaPositions[0] = pIcons_LOD->LoadTexture("convol10", TEXTURE_16BIT_PALETTE);
-          pTextureIDs_GammaPositions[1] = pIcons_LOD->LoadTexture("convol20", TEXTURE_16BIT_PALETTE);
-          pTextureIDs_GammaPositions[2] = pIcons_LOD->LoadTexture("convol30", TEXTURE_16BIT_PALETTE);
-          pTextureIDs_GammaPositions[3] = pIcons_LOD->LoadTexture("convol40", TEXTURE_16BIT_PALETTE);
-          pTextureIDs_GammaPositions[4] = pIcons_LOD->LoadTexture("convol50", TEXTURE_16BIT_PALETTE);
-          pTextureIDs_GammaPositions[5] = pIcons_LOD->LoadTexture("convol60", TEXTURE_16BIT_PALETTE);
-          pTextureIDs_GammaPositions[6] = pIcons_LOD->LoadTexture("convol70", TEXTURE_16BIT_PALETTE);
-          pTextureIDs_GammaPositions[7] = pIcons_LOD->LoadTexture("convol80", TEXTURE_16BIT_PALETTE);
-          pTextureIDs_GammaPositions[8] = pIcons_LOD->LoadTexture("convol90", TEXTURE_16BIT_PALETTE);
-          pTextureIDs_GammaPositions[9] = pIcons_LOD->LoadTexture("convol00", TEXTURE_16BIT_PALETTE);
-          not_available_bloodsplats_texture_id = pIcons_LOD->LoadTexture("opvdG-bs", TEXTURE_16BIT_PALETTE);
-          not_available_us_colored_lights_texture_id = pIcons_LOD->LoadTexture("opvdG-cl", TEXTURE_16BIT_PALETTE);
-          not_available_tinting_texture_id = pIcons_LOD->LoadTexture("opvdG-tn", TEXTURE_16BIT_PALETTE);
-          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_VideoOptions, 0, 0);
-          pGUIWindow_CurrentMenu->CreateButton(0xF1u, 0x12Eu, 0xD6u, 0x28u, 1, 0, UIMSG_Escape, 0, 0, "", 0);
-          //if ( pRenderer->pRenderD3D )
-          {
-            pGUIWindow_CurrentMenu->CreateButton(0x13u, 0x118u, 0xD6u, 0x12u, 1, 0, UIMSG_ToggleBloodsplats, 0, 0, "", 0);
-            pGUIWindow_CurrentMenu->CreateButton(0x13u, 0x12Eu, 0xD6u, 0x12u, 1, 0, UIMSG_ToggleColoredLights, 0, 0, "", 0);
-            pGUIWindow_CurrentMenu->CreateButton(0x13u, 0x144u, 0xD6u, 0x12u, 1, 0, UIMSG_ToggleTint, 0, 0, "", 0);
-          }
-          /*if ( !pRenderer->bWindowMode )
-          {
-            //v0 = 1;
-            if ( pRenderer->IsGammaSupported() )
-            {
-              pBtn_SliderLeft = pGUIWindow_CurrentMenu->CreateButton(0x15u, 0xA1u, 0x10u, 0x10u, 1, 0, UIMSG_1A9, 4u, 0, "", pIcons_LOD->GetTexture(uTextureID_507C20), 0);
-              pBtn_SliderRight = pGUIWindow_CurrentMenu->CreateButton(0xD5u, 0xA1u, 0x10u, 0x10u, 1, 0, UIMSG_1A9, 5u, 0, "", pIcons_LOD->GetTexture(uTextureID_507C24), 0);
-              pGUIWindow_CurrentMenu->CreateButton(42, 162, 170, 18, 1, 0, UIMSG_1A9, 0, 0, "", 0);
-            }
-          }*/
-          continue;
-        case UIMSG_1A9:
-			__debugbreak();
-          if ( uMessageParam == 4 )
-          {
-            //--uGammaPos;
-            if ( (uGammaPos -- -1) < 0 )
-            {
-              uGammaPos = 0;
-              pAudioPlayer->PlaySound(SOUND_ClickMovingSelector, 0, 0, -1, 0, 0, 0, 0);
-              continue;
-            }
-            v19 = (double)(signed int)uGammaPos * 0.1 + 0.6;
-            //pGame->pGammaController->Initialize(v19);
-            GUIWindow::Create(21, 161, 0, 0, WINDOW_PressedButton2, (int)pBtn_SliderLeft, (char *)1);
-            pAudioPlayer->PlaySound(SOUND_ClickMovingSelector, 0, 0, -1, 0, 0, 0, 0);
-            continue;
-          }
-          if ( uMessageParam == 5 )
-          {
-            ++uGammaPos;
-            if ( (signed int)uGammaPos <= 9 )
-            {
-              v21 = (double)(signed int)uGammaPos * 0.1 + 0.6;
-              //pGame->pGammaController->Initialize(v21);
-              GUIWindow::Create(213, 161, 0, 0, WINDOW_PressedButton2, (int)pBtn_SliderRight, (char *)1);
-              pAudioPlayer->PlaySound(SOUND_ClickMovingSelector, 0, 0, -1, 0, 0, 0, 0);
-              continue;
-            }
-            uGammaPos = 9;
-          }
-          else
-          {
-            uGammaPos = (pMouse->GetCursorPos(&a2)->x - 42) / 17;
-            v22 = (double)(signed int)uGammaPos * 0.1 + 0.6;
-            //pGame->pGammaController->Initialize(v22);
-          }
-          pAudioPlayer->PlaySound(SOUND_ClickMovingSelector, 0, 0, -1, 0, 0, 0, 0);
-          continue;
-        case UIMSG_ToggleBloodsplats:
-          pGame->ToggleFlags2(0x20u);
-          continue;
-        case UIMSG_ToggleColoredLights:
-          pRenderer->ToggleColoredLights();
-          continue;
-        case UIMSG_ToggleTint:
-          pRenderer->ToggleTint();
-          continue;
-        case UIMSG_ChangeMusicVolume:
-          if ( uMessageParam == 4 )//-
-          {
-            --uMusicVolimeMultiplier;
-            if ( (char)uMusicVolimeMultiplier < 1 )
-              uMusicVolimeMultiplier = 0;
-            GUIWindow::Create(243, 216, 0, 0, WINDOW_PressedButton2, (int)pBtn_SliderLeft, (char *)1);
-            if ( uMusicVolimeMultiplier )
-              pAudioPlayer->PlaySound(SOUND_hurp, -1, 0, -1, 0, 0, pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f, 0);
-		   
-			if ( use_music_folder )
-              alSourcef (mSourceID, AL_GAIN, pSoundVolumeLevels[uMusicVolimeMultiplier]);
-			else
-              pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f);
-
-            continue;
-          }
-          if ( uMessageParam == 5 )//+
-          {
-            ++uMusicVolimeMultiplier;
-            if ( (char)uMusicVolimeMultiplier > 9 )
-              uMusicVolimeMultiplier = 9;
-            GUIWindow::Create(435, 216, 0, 0, WINDOW_PressedButton2, (int)pBtn_SliderRight, (char *)1);
-            if ( uMusicVolimeMultiplier )
-              pAudioPlayer->PlaySound(SOUND_hurp, -1, 0, -1, 0, 0, pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f, 0);
-		    if ( use_music_folder )
-              alSourcef (mSourceID, AL_GAIN, pSoundVolumeLevels[uMusicVolimeMultiplier]);
-			else
-              pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f);
-            continue;
-          }
-          uMusicVolimeMultiplier = (pMouse->GetCursorPos(&v202)->x - 263) / 17;//for mouse
-          if ( (char)uMusicVolimeMultiplier > 9 )
-            uMusicVolimeMultiplier = 9;
-          if ( uMusicVolimeMultiplier )
-            pAudioPlayer->PlaySound(SOUND_hurp, -1, 0, -1, 0, 0, pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f, 0);
-	      if ( use_music_folder )
-            alSourcef (mSourceID, AL_GAIN, pSoundVolumeLevels[uMusicVolimeMultiplier]);
-		  else
-            pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f);
-          continue;
-        case UIMSG_ChangeSoundVolume:
-          if ( uMessageParam == 4 )//reduce sound level button left
-          {
-            --uSoundVolumeMultiplier;
-            if ( (char)uSoundVolumeMultiplier < 1 )
-              uSoundVolumeMultiplier = 0;
-            GUIWindow::Create(243, 162, 0, 0, WINDOW_PressedButton2, (int)pBtn_SliderLeft, (char *)1);
-            pAudioPlayer->SetMasterVolume(pSoundVolumeLevels[uSoundVolumeMultiplier] * 128.0f);
-            pAudioPlayer->PlaySound(SOUND_church, -1, 0, -1, 0, 0, 0, 0);
-			int v = AIL_redbook_volume(pAudioPlayer->hAILRedbook);
-			//v = v+1;
-			if (v)
-			  __debugbreak();
-            continue;
-          }
-          if ( uMessageParam == 5 )//Increase sound level button right
-          {
-            ++uSoundVolumeMultiplier;
-            if ( (char)uSoundVolumeMultiplier > 8 )
-              uSoundVolumeMultiplier = 9;
-            //v168 = 1;
-            v24 = 435;
-            //v154 = (int)pBtn_SliderRight;
-            GUIWindow::Create(v24, 162, 0, 0, WINDOW_PressedButton2, (int)pBtn_SliderRight, (char *)1);
-            pAudioPlayer->SetMasterVolume(pSoundVolumeLevels[uSoundVolumeMultiplier] * 128.0f);
-            pAudioPlayer->PlaySound(SOUND_church, -1, 0, -1, 0, 0, 0, 0);
-            continue;
-          }
-          uSoundVolumeMultiplier = (pMouse->GetCursorPos(&v207)->x - 263) / 17;
-          if ( (char)uSoundVolumeMultiplier > 8 )
-            uSoundVolumeMultiplier = 9;
-          pAudioPlayer->SetMasterVolume(pSoundVolumeLevels[uSoundVolumeMultiplier] * 128.0f);
-          pAudioPlayer->PlaySound(SOUND_church, -1, 0, -1, 0, 0, 0, 0);
-          continue;
-        case UIMSG_ToggleFlipOnExit:
-          bFlipOnExit = bFlipOnExit == 0;
-          continue;
-        case UIMSG_ToggleAlwaysRun:
-          bAlwaysRun = bAlwaysRun == 0;
-          continue;
-        case UIMSG_ToggleWalkSound:
-          bWalkSound = bWalkSound == 0;
-          continue;
-        case UIMSG_ToggleShowDamage:
-          bShowDamage = bShowDamage == 0;
-          continue;
-        case UIMSG_ChangeVoiceVolume:
-          if ( uMessageParam == 4 )
-          {
-            --uVoicesVolumeMultiplier;
-            if ( (char)uVoicesVolumeMultiplier < 1 )
-              uVoicesVolumeMultiplier = 0;
-            GUIWindow::Create(243, 270, 0, 0, WINDOW_PressedButton2, (int)pBtn_SliderLeft, (char *)1);
-            if ( !uVoicesVolumeMultiplier )
-              continue;
-            pAudioPlayer->PlaySound(SOUND_hf445a, -1, 0, -1, 0, 0, pSoundVolumeLevels[uVoicesVolumeMultiplier] * 128.0f, 0);
-            continue;
-          }
-          if ( uMessageParam == 5 )
-          {
-            ++uVoicesVolumeMultiplier;
-            if ( (char)uVoicesVolumeMultiplier > 8 )
-              uVoicesVolumeMultiplier = 9;
-            GUIWindow::Create(435, 270, 0, 0, WINDOW_PressedButton2, (int)pBtn_SliderRight, (char *)1);
-            if ( !uVoicesVolumeMultiplier )
-              continue;
-            pAudioPlayer->PlaySound(SOUND_hf445a, -1, 0, -1, 0, 0, pSoundVolumeLevels[uVoicesVolumeMultiplier] * 128.0f, 0);
-            continue;
-          }
-          uVoicesVolumeMultiplier = (pMouse->GetCursorPos(&v205)->x - 263) / 17;
-          if ( (char)uVoicesVolumeMultiplier > 8 )
-            uVoicesVolumeMultiplier = 9;
-          if ( !uVoicesVolumeMultiplier )
-            continue;
-          pAudioPlayer->PlaySound(SOUND_hf445a, -1, 0, -1, 0, 0, pSoundVolumeLevels[uVoicesVolumeMultiplier] * 128.0f, 0);
-          continue;
-        case UIMSG_SetTurnSpeed:
-          if ( uMessageParam )
-            pParty->sRotationY = uMessageParam * pParty->sRotationY / uMessageParam;
-          uTurnSpeed = uMessageParam;
-          continue;
-
-        case UIMSG_SetGraphicsMode:
-          /*if ( !bUseLoResSprites )
-          {
-            byte_6BE388_graphicsmode = uMessageParam;
-            MM7Initialization();
-            continue;
-          }
-          if ( uMessageParam )
-          {
-            if ( uMessageParam == 1 )
-            {
-              byte_6BE388_graphicsmode = 0;
-            }
-            else
-            {
-              if ( uMessageParam != 2 )
-                continue;
-              byte_6BE388_graphicsmode = 1;
-            }
-            MM7Initialization();
-            continue;
-          }*/
-          ModalWindow(pNPCTopics[453].pText, UIMSG_0);
-          __debugbreak(); // Nomad: graphicsmode as it was now removed
-          continue;
-
-        case UIMSG_GameMenu_ReturnToGame:
-          pGUIWindow_CurrentMenu->Release();
-          pEventTimer->Resume();
-          pCurrentScreen = SCREEN_GAME;
-          viewparams->bRedrawGameUI = 1;
-          stru_506E40.Release();
-          continue;
-        case UIMSG_OpenQuestBook:
-          if ( pMessageQueue_50CBD0->uNumMessages )
-            pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-          if ( pCurrentScreen )
-            pGUIWindow_CurrentMenu->Release();
-          pEventTimer->Pause();
-          pAudioPlayer->StopChannels(-1, -1);
-          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Book, uMessage, 0);
-          pBooksWindow = GUIWindow::Create(493u, 355u, 0, 0, WINDOW_BooksWindow, (int)pBtn_Quests, 0);
-          bFlashQuestBook = 0;
-          continue;
-        case UIMSG_OpenAutonotes:
-          if ( pMessageQueue_50CBD0->uNumMessages )
-            pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-          if ( pCurrentScreen )
-            pGUIWindow_CurrentMenu->Release();
-          pEventTimer->Pause();
-          pAudioPlayer->StopChannels(-1, -1);
-          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Book, uMessage, 0);
-          pBooksWindow = GUIWindow::Create(527u, 353u, 0, 0, WINDOW_BooksWindow, (int)pBtn_Autonotes, 0);
-          bFlashAutonotesBook = 0;
-          continue;
-        case UIMSG_OpenMapBook:
-          if ( pMessageQueue_50CBD0->uNumMessages )
-            pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-          if ( pCurrentScreen )
-            pGUIWindow_CurrentMenu->Release();
-          pEventTimer->Pause();
-          viewparams->sViewCenterX = pParty->vPosition.x;
-          viewparams->sViewCenterY = pParty->vPosition.y;
-          pAudioPlayer->StopChannels(-1, -1);
-          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Book, uMessage, 0);
-          pBooksWindow = GUIWindow::Create(546, 353, 0, 0, WINDOW_BooksWindow, (int)pBtn_Maps, 0);
-          continue;
-        case UIMSG_OpenCalendar:
-          if ( pMessageQueue_50CBD0->uNumMessages )
-            pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-          if ( pCurrentScreen )
-            pGUIWindow_CurrentMenu->Release();
-          pEventTimer->Pause();
-          pAudioPlayer->StopChannels(-1, -1);
-          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Book, uMessage, 0);
-          pBooksWindow = GUIWindow::Create(570, 354, 0, 0, WINDOW_BooksWindow, (int)pBtn_Calendar, 0);
-          continue;
-        case UIMSG_OpenHistoryBook:
-          if ( pMessageQueue_50CBD0->uNumMessages )
-            pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-          if ( pCurrentScreen )
-            pGUIWindow_CurrentMenu->Release();
-          pEventTimer->Pause();
-          pAudioPlayer->StopChannels(-1, -1);
-          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Book, uMessage, 0);
-          pBooksWindow = GUIWindow::Create(0x258u, 0x169u, 0, 0, WINDOW_BooksWindow, (int)pBtn_History, 0);
-          bFlashHistoryBook = 0;
-          continue;
-        case UIMSG_Escape:// íàæàòèå Escape and return to game
-          back_to_game();
-          if ( pMessageQueue_50CBD0->uNumMessages )
-            pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-          switch ( pCurrentScreen )
-          {
-            case SCREEN_E:
-				__debugbreak();
-            case SCREEN_NPC_DIALOGUE:
-            case SCREEN_CHEST:
-            case SCREEN_CHEST_INVENTORY:
-            case SCREEN_CHANGE_LOCATION:
-            case SCREEN_INPUT_BLV:
-            case SCREEN_QUICK_REFERENCE:
-              if ( dword_50CDC8 )
-                break;
-              CloseWindowBackground();
-              uMessageParam = 1;
-              break;
-            case SCREEN_HOUSE:
-              if ( !dword_50CDC8 )
-              {
-                CloseWindowBackground();
-                uMessageParam = 1;
-                break;
-              }
-              break;
-          }
-          if ( !pModalWindow )
-          {
-            pRenderer->ClearZBuffer(0, 479);
-            viewparams->bRedrawGameUI = 1;
-            viewparams->field_48 = 1;
-            if ( pCurrentScreen )
-            {
-              if ( pCurrentScreen > SCREEN_67 )
-              {
-                if ( pCurrentScreen == SCREEN_QUICK_REFERENCE )
-                {
-                  pIcons_LOD->RemoveTexturesPackFromTextureList();
-                  if ( pGUIWindow_Settings )
-                  {
-                    if ( pCurrentScreen == SCREEN_CHARACTERS )
-                      pMouse->SetCursorBitmap("MICON2");
-                    else
-                    {
-                      pGUIWindow_Settings->Release();
-                      pGUIWindow_Settings = 0;
-                      pMouse->SetCursorBitmap("MICON1");
-                      GameUI_Footer_TimeLeft = 0;
-                      _50C9A0_IsEnchantingInProgress = 0;
-                      back_to_game();
-                    }
-                  }
-                  if ( (signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4 )
-                    uActiveCharacter = pParty->GetNextActiveCharacter();
-                  pGUIWindow_CurrentMenu->Release();
-                  if ( pGUIWindow_CurrentMenu == window_SpeakInHouse )
-                    window_SpeakInHouse = 0;
-                  pGUIWindow_CurrentMenu = 0;
-                  pEventTimer->Resume();
-                  pCurrentScreen = SCREEN_GAME;
-                  viewparams->bRedrawGameUI = 1;
-                  pIcons_LOD->RemoveTexturesFromTextureList();
-                  continue;
-                }
-              }
-              else
-              {
-                if ( pCurrentScreen < SCREEN_64 )
-                {
-                  switch ( pCurrentScreen )
-                  {
-                    case SCREEN_CASTING:
-                      pIcons_LOD->RemoveTexturesPackFromTextureList();
-                      if ( some_active_character )
-                      {
-                        uActiveCharacter = some_active_character;
-                        uActiveCharacter = pParty->GetNextActiveCharacter();
-                        some_active_character = 0;
-                        if ( pParty->bTurnBasedModeOn )
-                          pTurnEngine->ApplyPlayerAction();
-                        _50C9D0_AfterEnchClickEventId = 0;
-                        _50C9D4_AfterEnchClickEventSecondParam = 0;
-                        _50C9D8_AfterEnchClickEventTimeout = 0;
-                      }
-                      if ( ptr_50C9A4_ItemToEnchant && ptr_50C9A4_ItemToEnchant->uItemID )
-                      {
-                        LOBYTE(ptr_50C9A4_ItemToEnchant->uAttributes) &= 0xFu;
-                        _50C9A8_item_enchantment_timer = 0;
-                        ptr_50C9A4_ItemToEnchant = nullptr;
-                      }
-                      if ( pGUIWindow_Settings )
-                      {
-                        if ( pCurrentScreen == SCREEN_CHARACTERS )
-                          pMouse->SetCursorBitmap("MICON2");
-                        else
-                        {
-                          pGUIWindow_Settings->Release();
-                          pGUIWindow_Settings = 0;
-                          pMouse->SetCursorBitmap("MICON1");
-                          GameUI_Footer_TimeLeft = 0;
-                          _50C9A0_IsEnchantingInProgress = 0;
-                          back_to_game();
-                        }
-                       }
-                       if ( (signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4 )
-                       uActiveCharacter = pParty->GetNextActiveCharacter();
-                       pGUIWindow_CurrentMenu->Release();
-                       if ( pGUIWindow_CurrentMenu == window_SpeakInHouse )
-                        window_SpeakInHouse = 0;
-                       pGUIWindow_CurrentMenu = 0;
-                       pEventTimer->Resume();
-                       pCurrentScreen = SCREEN_GAME;
-                       viewparams->bRedrawGameUI = 1;
-                       pIcons_LOD->RemoveTexturesFromTextureList();
-                       continue;
-                    case SCREEN_BOOKS:
-                      pBooksWindow->Release();
-                      //crt_deconstruct_ptr_6A0118();
-                      pBooksWindow = 0;
-                      pEventTimer->Resume();
-                      if ( pGUIWindow_Settings )
-                      {
-                        if ( pCurrentScreen == SCREEN_CHARACTERS )
-                          pMouse->SetCursorBitmap("MICON2");
-                        else
-                        {
-                          pGUIWindow_Settings->Release();
-                          pGUIWindow_Settings = 0;
-                          pMouse->SetCursorBitmap("MICON1");
-                          GameUI_Footer_TimeLeft = 0;
-                          _50C9A0_IsEnchantingInProgress = 0;
-                          back_to_game();
-                        }
-                      }
-                      if ( (signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4 )
-                        uActiveCharacter = pParty->GetNextActiveCharacter();
-                      pGUIWindow_CurrentMenu->Release();
-                      if ( pGUIWindow_CurrentMenu == window_SpeakInHouse )
-                        window_SpeakInHouse = 0;
-                      pGUIWindow_CurrentMenu = 0;
-                      pEventTimer->Resume();
-                      pCurrentScreen = SCREEN_GAME;
-                      viewparams->bRedrawGameUI = 1;
-                      pIcons_LOD->RemoveTexturesFromTextureList();
-                      continue;
-                    case SCREEN_SAVEGAME:
-                    case SCREEN_LOADGAME:
-                      pIcons_LOD->RemoveTexturesPackFromTextureList();
-                      //crt_deconstruct_ptr_6A0118();
-                      stru_506E40.Release();
-                      break;
-                    case SCREEN_CHEST_INVENTORY:
-                      pCurrentScreen = SCREEN_CHEST;
-                      continue;
-                    case SCREEN_CHEST:
-                      pWindow2 = pChestWindow;
-                      pWindow2->Release();
-                      pIcons_LOD->RemoveTexturesPackFromTextureList();
-                      pCurrentScreen = SCREEN_GAME;
-                      viewparams->bRedrawGameUI = 1;
-                      pEventTimer->Resume();
-                      continue;
-                    case SCREEN_19:
-						__debugbreak();
-                      pWindow2 = ptr_507BC8;
-                      pWindow2->Release();
-                      pIcons_LOD->RemoveTexturesPackFromTextureList();
-                      pCurrentScreen = SCREEN_GAME;
-                      viewparams->bRedrawGameUI = 1;
-                      pEventTimer->Resume();
-                      continue;
-                    case SCREEN_OPTIONS://Close
-                      options_menu_skin.Relaease();
-                      pIcons_LOD->SyncLoadedFilesCount();
-                      WriteWindowsRegistryInt("soundflag", (char)uSoundVolumeMultiplier);
-                      WriteWindowsRegistryInt("musicflag", (char)uMusicVolimeMultiplier);
-                      WriteWindowsRegistryInt("CharVoices", (char)uVoicesVolumeMultiplier);
-                      WriteWindowsRegistryInt("WalkSound", bWalkSound);
-                      WriteWindowsRegistryInt("ShowDamage", bShowDamage);
-                      //WriteWindowsRegistryInt("graphicsmode", (unsigned __int8)byte_6BE388_graphicsmode);
-                      WriteWindowsRegistryInt("valAlwaysRun", bAlwaysRun);
-                      WriteWindowsRegistryInt("FlipOnExit", bFlipOnExit);
-                      if ( !uTurnSpeed )
-                      {
-                        WriteWindowsRegistryInt("TurnDelta", 3);
-                        stru_506E40.Release();
-                        break;
-                      }
-                      if ( uTurnSpeed == 64 )
-                      {
-                        WriteWindowsRegistryInt("TurnDelta", 2);
-                        stru_506E40.Release();
-                        break;
-                      }
-                      if ( uTurnSpeed != 128 )
-                        {
-                          stru_506E40.Release();
-                          break;
-                        }
-                      WriteWindowsRegistryInt("TurnDelta", 1);
-                      stru_506E40.Release();
-                      break;
-                    case SCREEN_MENU:
-                      pIcons_LOD->SyncLoadedFilesCount();
-                      pIcons_LOD->RemoveTexturesPackFromTextureList();
-                      pIcons_LOD->SyncLoadedFilesCount();
-                      pIcons_LOD->RemoveTexturesPackFromTextureList();
-                      stru_506E40.Release();
-                      break;
-                    case SCREEN_VIDEO_OPTIONS:
-                      //if ( pRenderer->pRenderD3D )
-                      {
-                        WriteWindowsRegistryInt("Colored Lights", pRenderer->bUseColoredLights);
-                        WriteWindowsRegistryInt("Tinting", pRenderer->bTinting);
-                        WriteWindowsRegistryInt("Bloodsplats", (LOBYTE(pGame->uFlags2) >> 5) & 1);
-                      }
-
-                      stru_506E40.Release();
-                      break;
-
-                    case SCREEN_KEYBOARD_OPTIONS://Return to game
-                      v197 = 1;
-					  pKeyBindingFlag = false;
-                      for ( uint i = 0; i < 28; ++i )
-                      {
-                        if ( GameMenuUI_InvaligKeyBindingsFlags[i] )
-                          pKeyBindingFlag = true;
-                      }
-                      if ( !pKeyBindingFlag )
-                      {
-                        for ( uint i = 0; i < 5; i++ )
-                        {
-                          if ( uTextureID_Optkb[i] )
-                            pIcons_LOD->pTextures[uTextureID_Optkb[i]].Release();
-                        }
-                        memset(&uTextureID_Optkb, 0, 20);
-                        pIcons_LOD->SyncLoadedFilesCount();
-                        for ( uint i = 0; i < 28; ++i )
-                        {
-                          if ( pKeyActionMap->GetActionVKey((enum InputAction)i) != pPrevVirtualCidesMapping[i] )
-                          {
-                            if ( v197 )
-                            {
-                              GUI_ReplaceHotkey(pKeyActionMap->GetActionVKey((enum InputAction)i), LOBYTE(pPrevVirtualCidesMapping[i]), 1);
-                              v197 = 0;
-                            }
-                            else
-                              GUI_ReplaceHotkey(pKeyActionMap->GetActionVKey((enum InputAction)i), LOBYTE(pPrevVirtualCidesMapping[i]), 0);
-                          }
-                          if ( i > 3 && i != 25 && i != 26 )
-                            pKeyToggleType = TOGGLE_OneTimePress;
-                          else
-                            pKeyToggleType = TOGGLE_Continuously;
-                          pKeyActionMap->SetKeyMapping(i, pPrevVirtualCidesMapping[i], pKeyToggleType);
-                        }
-                        pKeyActionMap->StoreMappings();
-                        stru_506E40.Release();
-                        break;
-                      }
-                      pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);
-                      break;
-                    case SCREEN_REST://close rest screen
-                      if ( dword_506F14 )
-                      {
-                        Rest(_506F18_num_minutes_to_sleep);
-                        pParty->pPlayers[3].SetAsleep(false);
-                        pParty->pPlayers[2].SetAsleep(false);
-                        pParty->pPlayers[1].SetAsleep(false);
-                        pParty->pPlayers[0].SetAsleep(false);
-                      }
-                      pTexture_RestUI_CurrentSkyFrame->Release();
-                      pTexture_RestUI_CurrentHourglassFrame->Release();
-                      pTexture_RestUI_CurrentHourglassFrame = 0;
-                      pTexture_RestUI_CurrentSkyFrame = 0;
-                      pIcons_LOD->SyncLoadedFilesCount();
-                      pIcons_LOD->RemoveTexturesPackFromTextureList();
-                      if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor)
-                      {
-                        pOutdoor->UpdateSunlightVectors();
-                        pOutdoor->UpdateFog();
-                      }
-                      _506F18_num_minutes_to_sleep = 0;
-                      dword_506F14 = 0;
-                      if ( pGUIWindow_Settings )
-                      {
-                        if ( pCurrentScreen == SCREEN_CHARACTERS )
-                          pMouse->SetCursorBitmap("MICON2");
-                        else
-                        {
-                          pGUIWindow_Settings->Release();
-                          pGUIWindow_Settings = 0;
-                          pMouse->SetCursorBitmap("MICON1");
-                          GameUI_Footer_TimeLeft = 0;
-                          _50C9A0_IsEnchantingInProgress = 0;
-                          back_to_game();
-                        }
-                      }
-                      if ( (signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4 )
-                        uActiveCharacter = pParty->GetNextActiveCharacter();
-                      pGUIWindow_CurrentMenu->Release();
-                      if ( pGUIWindow_CurrentMenu == window_SpeakInHouse )
-                        window_SpeakInHouse = 0;
-                      pGUIWindow_CurrentMenu = 0;
-                      pEventTimer->Resume();
-                      pCurrentScreen = SCREEN_GAME;
-                      viewparams->bRedrawGameUI = 1;
-                      pIcons_LOD->RemoveTexturesFromTextureList();
-                      continue;
-                    case SCREEN_E:
-						__debugbreak();
-                      pGUIWindow_CurrentMenu->Release();
-                      pCurrentScreen = SCREEN_HOUSE;
-                      pIcons_LOD->RemoveTexturesPackFromTextureList();
-                      continue;
-                    case SCREEN_HOUSE:
-                      if ( uDialogueType )
-                        uDialogueType = 0;
-                      if ( uGameState == GAME_STATE_CHANGE_LOCATION )
-                      {
-                        while ( HouseDialogPressCloseBtn() )
-                          ;
-                      }
-                      else
-                      {
-                        if ( HouseDialogPressCloseBtn() )
-                          continue;
-                      }
-                      GetHouseGoodbyeSpeech();
-                      pAudioPlayer->PlaySound(SOUND_WoodDoorClosing, 814, 0, -1, 0, 0, 0, 0);
-                      pMediaPlayer->Unload();
-                      pGUIWindow_CurrentMenu = window_SpeakInHouse;
-                      if ( pGUIWindow_Settings )
-                      {
-                        if ( pCurrentScreen == SCREEN_CHARACTERS )
-                          pMouse->SetCursorBitmap("MICON2");
-                        else
-                        {
-                          pGUIWindow_Settings->Release();
-                          pGUIWindow_Settings = 0;
-                          pMouse->SetCursorBitmap("MICON1");
-                          GameUI_Footer_TimeLeft = 0;
-                          _50C9A0_IsEnchantingInProgress = 0;
-                          back_to_game();
-                        }
-                      }
-                      if ( (signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4 )
-                        uActiveCharacter = pParty->GetNextActiveCharacter();
-                      pGUIWindow_CurrentMenu->Release();
-                      if ( pGUIWindow_CurrentMenu == window_SpeakInHouse )
-                        window_SpeakInHouse = 0;
-                      pGUIWindow_CurrentMenu = 0;
-                      pEventTimer->Resume();
-                      pCurrentScreen = SCREEN_GAME;
-                      viewparams->bRedrawGameUI = true;
-                      pIcons_LOD->RemoveTexturesFromTextureList();
-                      continue;
-                    case SCREEN_INPUT_BLV://click escape
-                      if ( uCurrentHouse_Animation == 153 )
-                        PlayHouseSound(0x99u, HouseSound_Greeting_2);
-                      pMediaPlayer->Unload();
-                      if ( npcIdToDismissAfterDialogue )
-                      {
-                        pParty->hirelingScrollPosition = 0;
-                        LOBYTE(pNPCStats->pNewNPCData[npcIdToDismissAfterDialogue].uFlags) &= 0x7Fu;
-                        pParty->CountHirelings();
-                        viewparams->bRedrawGameUI = true;
-                        npcIdToDismissAfterDialogue = 0;
-                      }
-                      DialogueEnding();
-                      pCurrentScreen = SCREEN_GAME;
-                      viewparams->bRedrawGameUI = true;
-                      continue;
-                    case SCREEN_NPC_DIALOGUE://click escape
-                      if ( npcIdToDismissAfterDialogue )
-                      {
-                        pParty->hirelingScrollPosition = 0;
-                        LOBYTE(pNPCStats->pNewNPCData[npcIdToDismissAfterDialogue].uFlags) &= 0x7Fu;
-                        pParty->CountHirelings();
-                        viewparams->bRedrawGameUI = true;
-                        npcIdToDismissAfterDialogue = 0;
-                      }
-                      //goto LABEL_317;
-                      DialogueEnding();
-                      pCurrentScreen = SCREEN_GAME;
-                      viewparams->bRedrawGameUI = true;
-                      continue;
-                    case SCREEN_BRANCHLESS_NPC_DIALOG://click escape
-                      memset(GameUI_Footer_TimedString.data(), 0, 0xC8u);
-                      sub_4452BB();
-                      DialogueEnding();
-                      pCurrentScreen = SCREEN_GAME;
-                      viewparams->bRedrawGameUI = true;
-                      continue;
-                    case SCREEN_CHANGE_LOCATION://click escape
-                      if ( pParty->vPosition.x < -22528 )
-                        pParty->vPosition.x = -22528;
-                      if ( pParty->vPosition.x > 22528 )
-                        pParty->vPosition.x = 22528;
-                      if ( pParty->vPosition.y < -22528 )
-                        pParty->vPosition.y = -22528;
-                      if ( pParty->vPosition.y > 22528 )
-                        pParty->vPosition.y = 22528;
-                      DialogueEnding();
-                      pCurrentScreen = SCREEN_GAME;
-                      viewparams->bRedrawGameUI = true;
-                      continue;
-                    case SCREEN_VIDEO:
-                      pMediaPlayer->Unload();
-                      continue;
-                    case SCREEN_CHARACTERS:
-                      CharacterUI_ReleaseButtons();
-                      ReleaseAwardsScrollBar();
-                      pIcons_LOD->RemoveTexturesPackFromTextureList();
-                      if ( pGUIWindow_Settings )
-                      {
-                        if ( pCurrentScreen == SCREEN_CHARACTERS )
-                          pMouse->SetCursorBitmap("MICON2");
-                        else
-                        {
-                          pGUIWindow_Settings->Release();
-                          pGUIWindow_Settings = 0;
-                          pMouse->SetCursorBitmap("MICON1");
-                          GameUI_Footer_TimeLeft = 0;
-                          _50C9A0_IsEnchantingInProgress = 0;
-                          back_to_game();
-                        }
-                      }
-                      if ( (signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4 )
-                        uActiveCharacter = pParty->GetNextActiveCharacter();
-                      pGUIWindow_CurrentMenu->Release();
-                      if ( pGUIWindow_CurrentMenu == window_SpeakInHouse )
-                        window_SpeakInHouse = 0;
-                      pGUIWindow_CurrentMenu = 0;
-                      pEventTimer->Resume();
-                      pCurrentScreen = SCREEN_GAME;
-                      viewparams->bRedrawGameUI = true;
-                      pIcons_LOD->RemoveTexturesFromTextureList();
-                      continue;
-                    default:
-                      if ( pGUIWindow_Settings )
-                      {
-                        if ( pCurrentScreen == SCREEN_CHARACTERS )
-                          pMouse->SetCursorBitmap("MICON2");
-                        else
-                        {
-                          pGUIWindow_Settings->Release();
-                          pGUIWindow_Settings = 0;
-                          pMouse->SetCursorBitmap("MICON1");
-                          GameUI_Footer_TimeLeft = 0;
-                          _50C9A0_IsEnchantingInProgress = 0;
-                          back_to_game();
-                        }
-                      }
-                      if ( (signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4 )
-                        uActiveCharacter = pParty->GetNextActiveCharacter();
-                      pGUIWindow_CurrentMenu->Release();
-                      if ( pGUIWindow_CurrentMenu == window_SpeakInHouse )
-                        window_SpeakInHouse = 0;
-                      pGUIWindow_CurrentMenu = 0;
-                      pEventTimer->Resume();
-                      pCurrentScreen = SCREEN_GAME;
-                      viewparams->bRedrawGameUI = 1;
-                      pIcons_LOD->RemoveTexturesFromTextureList();
-                      continue;
-                  }
-                  if ( pGUIWindow_Settings )
-                  {
-                    if ( pCurrentScreen == SCREEN_CHARACTERS )
-                      pMouse->SetCursorBitmap("MICON2");
-                    else
-                    {
-                      pGUIWindow_Settings->Release();
-                      pGUIWindow_Settings = 0;
-                      pMouse->SetCursorBitmap("MICON1");
-                      GameUI_Footer_TimeLeft = 0;
-                      _50C9A0_IsEnchantingInProgress = 0;
-                      back_to_game();
-                    }
-                  }
-                  if ( (signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4 )
-                    uActiveCharacter = pParty->GetNextActiveCharacter();
-                  pGUIWindow_CurrentMenu->Release();
-                  if ( pGUIWindow_CurrentMenu == window_SpeakInHouse )
-                    window_SpeakInHouse = 0;
-                  pGUIWindow_CurrentMenu = 0;
-                  pEventTimer->Resume();
-                  pCurrentScreen = SCREEN_GAME;
-                  viewparams->bRedrawGameUI = true;
-                  pIcons_LOD->RemoveTexturesFromTextureList();
-                  continue;
-                }
-                CharacterUI_ReleaseButtons();
-                ReleaseAwardsScrollBar();
-                pIcons_LOD->RemoveTexturesPackFromTextureList();
-              }
-              if ( pGUIWindow_Settings )
-              {
-                if ( pCurrentScreen == SCREEN_CHARACTERS )
-                  pMouse->SetCursorBitmap("MICON2");
-                else
-                {
-                  pGUIWindow_Settings->Release();
-                  pGUIWindow_Settings = 0;
-                  pMouse->SetCursorBitmap("MICON1");
-                  GameUI_Footer_TimeLeft = 0;
-                  _50C9A0_IsEnchantingInProgress = 0;
-                  back_to_game();
-                }
-              }
-              if ( (signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4 )
-                uActiveCharacter = pParty->GetNextActiveCharacter();
-              pGUIWindow_CurrentMenu->Release();
-              if ( pGUIWindow_CurrentMenu == window_SpeakInHouse )
-                window_SpeakInHouse = 0;
-              pGUIWindow_CurrentMenu = 0;
-              pEventTimer->Resume();
-              pCurrentScreen = SCREEN_GAME;
-              viewparams->bRedrawGameUI = true;
-              pIcons_LOD->RemoveTexturesFromTextureList();
-              continue;
-            }
-            if ( !pGUIWindow_Settings )//Draw Menu
-            {
-              dword_6BE138 = -1;
-              GUIWindow::Create(0x25Au, 0x1C2u, 0, 0, WINDOW_PressedButton2, (int)pBtn_GameSettings, (char *)1);
-              pEventTimer->Pause();
-              pAudioPlayer->StopChannels(-1, -1);
-              pCurrentScreen = SCREEN_MENU;
-              
-              ++pIcons_LOD->uTexturePacksCount;
-              if ( !pIcons_LOD->uNumPrevLoadedFiles )
-                pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
-
-              pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_OptionsButtons, 0, 0);
-              uTextureID_Options = pIcons_LOD->LoadTexture("options", TEXTURE_16BIT_PALETTE);
-              uTextureID_New1 = pIcons_LOD->LoadTexture("new1", TEXTURE_16BIT_PALETTE);
-              uTextureID_Load1 = pIcons_LOD->LoadTexture("load1", TEXTURE_16BIT_PALETTE);
-              uTextureID_Save1 = pIcons_LOD->LoadTexture("save1", TEXTURE_16BIT_PALETTE);
-              uTextureID_Controls1 = pIcons_LOD->LoadTexture("controls1", TEXTURE_16BIT_PALETTE);
-              uTextureID_Resume1 = pIcons_LOD->LoadTexture("resume1", TEXTURE_16BIT_PALETTE);
-              uTextureID_Quit1 = pIcons_LOD->LoadTexture("quit1", TEXTURE_16BIT_PALETTE);
-              pBtn_NewGame = pGUIWindow_CurrentMenu->CreateButton(0x13u, 0x9Bu, 0xD6u, 0x28u, 1, 0, UIMSG_StartNewGame, 0, 0x4Eu,
-                             pGlobalTXT_LocalizationStrings[614],// "New Game"
-                             pIcons_LOD->GetTexture(uTextureID_New1), 0);
-              pBtn_SaveGame = pGUIWindow_CurrentMenu->CreateButton(0x13u, 0xD1u, 0xD6u, 0x28u, 1, 0, UIMSG_Game_OpenSaveGameDialog, 0, 0x53u,
-                             pGlobalTXT_LocalizationStrings[615],// "Save Game"
-                             pIcons_LOD->GetTexture(uTextureID_Save1), 0);
-              pBtn_LoadGame = pGUIWindow_CurrentMenu->CreateButton(19, 263, 0xD6u, 0x28u, 1, 0, UIMSG_Game_OpenLoadGameDialog, 0, 0x4Cu,
-                             pGlobalTXT_LocalizationStrings[616],// "Load Game"
-                             pIcons_LOD->GetTexture(uTextureID_Load1), 0);
-              pBtn_GameControls = pGUIWindow_CurrentMenu->CreateButton(241, 155, 214, 40, 1, 0, UIMSG_Game_OpenOptionsDialog, 0, 0x43u,
-                             pGlobalTXT_LocalizationStrings[617],// ""Sound, Keyboard, Game Options:""
-                             pIcons_LOD->GetTexture(uTextureID_Controls1), 0);
-              pBtn_QuitGame = pGUIWindow_CurrentMenu->CreateButton(241, 209, 214, 40, 1, 0, UIMSG_Quit, 0, 0x51u,
-                             pGlobalTXT_LocalizationStrings[618],// "Quit"
-                             pIcons_LOD->GetTexture(uTextureID_Quit1), 0);
-              pBtn_Resume = pGUIWindow_CurrentMenu->CreateButton(241, 263, 214, 40, 1, 0, UIMSG_GameMenu_ReturnToGame, 0, 0x52u,
-                             pGlobalTXT_LocalizationStrings[619],// "Return to Game"
-                             pIcons_LOD->GetTexture(uTextureID_Resume1), 0);
-              pGUIWindow_CurrentMenu->_41D08F_set_keyboard_control_group(6, 1, 0, 0);
-              viewparams->field_48 = 1;
-
-              stru_506E40.Release();
-              pRenderer->SaveScreenshot("gamma.pcx", 155, 117);
-              stru_506E40.LoadPCXFile("gamma.pcx", 0);
-
-              continue;
-            }
-            pGUIWindow_Settings->Release();
-            pGUIWindow_Settings = 0;
-            pMouse->SetCursorBitmap("MICON1");
-            GameUI_Footer_TimeLeft = 0;
-            _50C9A0_IsEnchantingInProgress = 0;
-            back_to_game();
-            continue;
-          }
-          ModalWindow_Release();
-          continue;
-        case UIMSG_ScrollNPCPanel://Right and Left button for NPCPanel
-          if ( uMessageParam )
-          {
-            GUIWindow::Create(626, 179, 0, 0, WINDOW_PressedButton2, (int)pBtn_NPCRight, 0);
-            v37 = (pParty->pHirelings[0].pName != 0) + (pParty->pHirelings[1].pName != 0) + (unsigned __int8)pParty->field_70A - 2;
-            if ( pParty->hirelingScrollPosition < v37 )
-            {
-              ++pParty->hirelingScrollPosition;//??? maybe number of the first cell???
-              if ( pParty->hirelingScrollPosition >= v37 )
-                pParty->hirelingScrollPosition = (pParty->pHirelings[0].pName != 0) + (pParty->pHirelings[1].pName != 0) + pParty->field_70A - 2;
-            }
-          }
-          else
-          {
-            GUIWindow::Create(469, 179, 0, 0, WINDOW_PressedButton2, (int)pBtn_NPCLeft, 0);
-            /*if ( pParty->field_709 )
-            {
-              --pParty->field_709;
-              if ( pParty->field_709 < 1 )
-                pParty->field_709 = 0;
-            }*/
-          }
-          GameUI_DrawHiredNPCs();
-          continue;
-        case UIMSG_TransitionUI_Confirm:
-          if ( pMessageQueue_50CBD0->uNumMessages )
-            pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-          dword_50CDC8 = 1;
-          sub_42FBDD();
-          PlayHouseSound(uCurrentHouse_Animation, HouseSound_NotEnoughMoney_TrainingSuccessful);
-
-          if (pMovie_Track)
-            pMediaPlayer->Unload();
-          DialogueEnding();
-          viewparams->bRedrawGameUI = true;
-          if ( dword_59117C_teleportx | dword_591178_teleporty | dword_591174_teleportz | dword_591170_teleport_directiony | dword_59116C_teleport_directionx | dword_591168_teleport_speedz )
-          {
-            if ( dword_59117C_teleportx )
-            {
-              pParty->vPosition.x = dword_59117C_teleportx;
-              _5B65A8_npcdata_uflags_or_other = dword_59117C_teleportx;
-            }
-            if ( dword_591178_teleporty )
-            {
-              pParty->vPosition.y = dword_591178_teleporty;
-              _5B65AC_npcdata_fame_or_other = dword_591178_teleporty;
-            }
-            if ( dword_591174_teleportz )
-            {
-              pParty->vPosition.z = dword_591174_teleportz;
-              _5B65B0_npcdata_rep_or_other = dword_591174_teleportz;
-              pParty->uFallStartY = dword_591174_teleportz;
-            }
-            if ( dword_591170_teleport_directiony )
-            {
-              pParty->sRotationY = dword_591170_teleport_directiony;
-              _5B65B4_npcdata_loword_house_or_other = dword_591170_teleport_directiony;
-            }
-            if ( dword_59116C_teleport_directionx )
-            {
-              pParty->sRotationX = dword_59116C_teleport_directionx;
-              _5B65B8_npcdata_hiword_house_or_other = dword_59116C_teleport_directionx;
-              v38 = dword_591168_teleport_speedz;
-              pParty->uFallSpeed = dword_591168_teleport_speedz;
-              dword_5B65BC = dword_591168_teleport_speedz;
-            }
-            else
-              v38 = dword_5B65BC;
-            if ( *dword_591164_teleport_map_name != 48 )
-            {
-              pGameLoadingUI_ProgressBar->uType = (GUIProgressBar::Type)2;
-              dword_5B65C0 = _5B65A8_npcdata_uflags_or_other | _5B65AC_npcdata_fame_or_other | _5B65B0_npcdata_rep_or_other | _5B65B4_npcdata_loword_house_or_other | _5B65B8_npcdata_hiword_house_or_other | v38;
-              OnMapLeave();
-              Transition_StopSound_Autosave(dword_591164_teleport_map_name, MapStartPoint_Party);
-            }
-          }
-          else
-            EventProcessor(dword_5C3418, 0, 1, dword_5C341C);
-          if ( !_stricmp(byte_6BE3B0.data(), "d05.blv") )
-            pParty->uTimePlayed += 1474560i64;
-          continue;
-        case UIMSG_TransitionWindowCloseBtn:
-          CloseWindowBackground();
-          pMediaPlayer->Unload();
-          DialogueEnding();
-          viewparams->bRedrawGameUI = true;
-          continue;
-        case UIMSG_CycleCharacters:
-          v39 = GetAsyncKeyState(VK_SHIFT);
-          uActiveCharacter = CycleCharacter(v39);
-          viewparams->bRedrawGameUI = true;
-          continue;
-        case UIMSG_OnTravelByFoot:
-          if ( pMessageQueue_50CBD0->uNumMessages )
-            pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-          dword_50CDC8 = 1;
-          sub_42FBDD();
-          //pNPCData4 = (NPCData *)GetTravelTime();
-          strcpy(pOutdoor->pLevelFilename, pCurrentMapName);
-          if ( bUnderwater != 1 && pParty->bFlying
-            || pOutdoor->GetTravelDestination(pParty->vPosition.x, pParty->vPosition.y, pOut, 20) != 1 )
-          {
-            viewparams->bRedrawGameUI = 1;
-            CloseWindowBackground();
-            if ( pParty->vPosition.x < -22528 )
-              pParty->vPosition.x = -22528;
-            if ( pParty->vPosition.x > 22528 )
-              pParty->vPosition.x = 22528;
-            if ( pParty->vPosition.y < -22528 )
-              pParty->vPosition.y = -22528;
-            if ( pParty->vPosition.y > 22528 )
-              pParty->vPosition.y = 22528;
-            DialogueEnding();
-            pCurrentScreen = SCREEN_GAME;
-          }
-          else
-          {
-            pParty->field_6E4 = 0;
-            pParty->field_6E0 = 0;
-            CastSpellInfoHelpers::_427D48();
-            DialogueEnding();
-            pEventTimer->Pause();
-            pGameLoadingUI_ProgressBar->Initialize(GUIProgressBar::TYPE_Box);
-            ++pGameLoadingUI_ProgressBar->uProgressMax;
-            SaveGame(1, 0);
-            pGameLoadingUI_ProgressBar->Progress();
-            RestAndHeal(1440 * (signed int)GetTravelTime());
-            if ( pParty->uNumFoodRations )
-            {
-              pParty->RestAndHeal();
-              if ( ((pParty->uNumFoodRations - (signed int)GetTravelTime()) & 0x80000000u) != 0 )
-              {
-                pPlayer7 = pParty->pPlayers.data();
-                do
-                {
-                  pPlayer7->SetCondition(1, 0);
-                  ++pPlayer7;
-                }
-                while ( (signed int)pPlayer7 < (signed int)pParty->pHirelings.data() );
-                ++pParty->days_played_without_rest;
-              }
-              Party::TakeFood((unsigned int)GetTravelTime());
-            }
-            else
-            {
-              pPlayer8 = pParty->pPlayers.data();
-              do
-              {
-                pPlayer8->SetCondition(1, 0);
-                ++pPlayer8;
-              }
-              while ( (signed int)pPlayer8 < (signed int)pParty->pHirelings.data() );
-              ++pParty->days_played_without_rest;
-            }
-            pPaletteManager->ResetNonLocked();
-            pSpriteFrameTable->ResetSomeSpriteFlags();
-            strcpy(pCurrentMapName, pOut);
-            strcpy(pLevelName, pCurrentMapName);
-            v41 = strtok(pLevelName, ".");
-            strcpy(pLevelName, v41);
-            Level_LoadEvtAndStr(pLevelName);
-            pDecalBuilder->Reset(0);
-            LoadLevel_InitializeLevelEvt();
-            uLevelMapStatsID = pMapStats->GetMapInfo(pCurrentMapName);
-            bUnderwater = 0;
-            bNoNPCHiring = 0;
-            pGame->uFlags2 &= 0xFFFFFFF7u;
-            if ( Is_out15odm_underwater() )
-            {
-              bUnderwater = 1;
-              pGame->uFlags2 |= 8u;
-            }
-            if ( !_stricmp(pCurrentMapName, "out15.odm") || !_stricmp(pCurrentMapName, "d47.blv") )
-              bNoNPCHiring = 1;
-            PrepareToLoadODM(1u, (ODMRenderParams *)1);
-            pAudioPlayer->SetMapEAX();
-            bDialogueUI_InitializeActor_NPC_ID = 0;
-            OnMapLoad();
-            pOutdoor->SetFog();
-            TeleportToStartingPoint(uLevel_StartingPointType);
-            pParty->vPosition.z = GetTerrainHeightsAroundParty2(pParty->vPosition.x, pParty->vPosition.y, &v213, 0);
-            pParty->uFallStartY = pParty->vPosition.z;
-            _461103_load_level_sub();
-            pEventTimer->Resume();
-            viewparams->bRedrawGameUI = 1;
-            pCurrentScreen = SCREEN_GAME;
-            pGameLoadingUI_ProgressBar->Release();
-          }
-          viewparams->bRedrawGameUI = 1;
-          continue;
-        case UIMSG_CHANGE_LOCATION_ClickCencelBtn:
-          CloseWindowBackground();
-          if ( pParty->vPosition.x < -22528 )
-            pParty->vPosition.x = -22528;
-          if ( pParty->vPosition.x > 22528 )
-            pParty->vPosition.x = 22528;
-          if ( pParty->vPosition.y < -22528 )
-            pParty->vPosition.y = -22528;
-          if ( pParty->vPosition.y > 22528 )
-            pParty->vPosition.y = 22528;
-          DialogueEnding();
-          pCurrentScreen = SCREEN_GAME;
-          viewparams->bRedrawGameUI = 1;
-          continue;
-        case UIMSG_CastSpell_Telekinesis:
-          //if ( pRenderer->pRenderD3D )
-            LOWORD(v42) = pGame->pVisInstance->get_picked_object_zbuf_val();
-          /*else
-          {
-            uNumSeconds = (unsigned int)pMouse->GetCursorPos(&v210);
-            pPoint = pMouse->GetCursorPos(&v208);
-            v42 = pRenderer->pActiveZBuffer[*(int *)uNumSeconds + pSRZBufferLineOffsets[pPoint->y]];
-          }*/
-          v44 = (unsigned __int16)v42;
-          v45 = PID_TYPE(v44);
-          uNumSeconds = v44;
-          v46 = PID_ID(v44);
-          if ( v45 == 3 )
-          {
-            v47 = pActors[v46].uAIState == Dead;
-            if ( !v47 )
-              continue;
-            pSpellInfo = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
-            pSpellInfo->uFlags &= ~0x40u;
-            pSpellInfo->uPlayerID_2 = uMessageParam;
-            pSpellInfo->spell_target_pid = v44;
-            pParty->pPlayers[pSpellInfo->uPlayerID].SetRecoveryTime(300);
-            pGUIWindow_Settings->Release();
-            pGUIWindow_Settings = 0;
-            pMouse->SetCursorBitmap("MICON1");
-            GameUI_Footer_TimeLeft = 0;
-            _50C9A0_IsEnchantingInProgress = 0;
-            back_to_game();
-            continue;
-          }
-          if ( v45 == 2 )
-          {
-            v47 = (pObjectList->pObjects[pSpriteObjects[v46].uObjectDescID].uFlags & 0x10) == 0;
-            if ( !v47 )
-              continue;
-            pSpellInfo = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
-            pSpellInfo->uFlags &= ~0x40u;
-            pSpellInfo->uPlayerID_2 = uMessageParam;
-            pSpellInfo->spell_target_pid = v44;
-            pParty->pPlayers[pSpellInfo->uPlayerID].SetRecoveryTime(300);
-            pGUIWindow_Settings->Release();
-            pGUIWindow_Settings = 0;
-            pMouse->SetCursorBitmap("MICON1");
-            GameUI_Footer_TimeLeft = 0;
-            _50C9A0_IsEnchantingInProgress = 0;
-            back_to_game();
-            continue;
-          }
-          if ( v45 == 5 )
-          {
-            v48 = pLevelDecorations[v46].uEventID == 0;
-          }
-          else
-          {
-            if ( v45 != 6 )
-              continue;
-            if ( uCurrentlyLoadedLevelType != 1 )
-            {
-              pODMFace = &pOutdoor->pBModels[v44 >> 9].pFaces[v46 & 0x3F];
-              if ( !pODMFace->Clickable() || !pODMFace->sCogTriggeredID )
-                continue;
-              v44 = uNumSeconds;
-              pSpellInfo = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
-              pSpellInfo->uFlags &= ~0x40u;
-              pSpellInfo->uPlayerID_2 = uMessageParam;
-              pSpellInfo->spell_target_pid = v44;
-              pParty->pPlayers[pSpellInfo->uPlayerID].SetRecoveryTime(300);
-              pGUIWindow_Settings->Release();
-              pGUIWindow_Settings = 0;
-              pMouse->SetCursorBitmap("MICON1");
-              GameUI_Footer_TimeLeft = 0;
-              _50C9A0_IsEnchantingInProgress = 0;
-              back_to_game();
-              continue;
-            }
-            pBLVFace = &pIndoor->pFaces[v46];
-            if ( !pBLVFace->Clickable() )
-              continue;
-            v48 = pIndoor->pFaceExtras[pBLVFace->uFaceExtraID].uEventID == 0;
-          }
-          if ( v48 )
-            continue;
-          pSpellInfo = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
-          pSpellInfo->uFlags &= ~0x40u;
-          pSpellInfo->uPlayerID_2 = uMessageParam;
-          pSpellInfo->spell_target_pid = v44;
-          pParty->pPlayers[pSpellInfo->uPlayerID].SetRecoveryTime(300);
-          pGUIWindow_Settings->Release();
-          pGUIWindow_Settings = 0;
-          pMouse->SetCursorBitmap("MICON1");
-          GameUI_Footer_TimeLeft = 0;
-          _50C9A0_IsEnchantingInProgress = 0;
-          back_to_game();
-          continue;
-        case UIMSG_CastSpell_Character_Big_Improvement://Preservation and blessing, treatment paralysis, hand hammers(individual upgrade)
-        case UIMSG_CastSpell_Character_Small_Improvement://Fate, cure
-        case UIMSG_HiredNPC_CastSpell:
-          if ( pMessageQueue_50CBD0->uNumMessages )
-            pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-          if ( _50C9A0_IsEnchantingInProgress )
-          {
-            uActiveCharacter = uMessageParam;
-            viewparams->bRedrawGameUI = 1;
-          }
-          else
-          {
-            if ( pGUIWindow_Settings )
-            {
-              pSpellInfo = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
-              switch ( uMessage )
-              {
-                case UIMSG_CastSpell_Character_Big_Improvement:
-                  pSpellInfo->uFlags &= ~0x02u;
-                  break;
-                case UIMSG_CastSpell_Character_Small_Improvement:
-                  pSpellInfo->uFlags &= ~0x0100u;
-                  break;
-                case UIMSG_HiredNPC_CastSpell:
-                  pSpellInfo->uFlags &= ~0x0200u;
-                  break;
-              }
-              pSpellInfo->uPlayerID_2 = uMessageParam;
-              pParty->pPlayers[pSpellInfo->uPlayerID].SetRecoveryTime(300);
-              pGUIWindow_Settings->Release();
-              pGUIWindow_Settings = 0;
-              pEventTimer->Resume();
-              pMouse->SetCursorBitmap("MICON1");
-              GameUI_Footer_TimeLeft = 0;
-              _50C9A0_IsEnchantingInProgress = 0;
-            }
-          }
-          continue;
-        case UIMSG_BF:
-			__debugbreak();
-          dword_50CDC8 = 1;
-          sub_42FBDD();
-          SaveGame(1, 0);
-          strcpy(pCurrentMapName, pMapStats->pInfos[uHouse_ExitPic].pFilename);
-          dword_6BE364_game_settings_1 |= GAME_SETTINGS_0001;
-          uGameState = GAME_STATE_CHANGE_LOCATION;
-          //v53 = p2DEvents_minus1_::30[26 * (unsigned int)ptr_507BC0->ptr_1C];
-          v53 = p2DEvents[(unsigned int)window_SpeakInHouse->ptr_1C - 1]._quest_related;
-          if ( v53 < 0 )
-          {
-            v54 = abs(v53) - 1;
-            _5B65B8_npcdata_hiword_house_or_other = 0;
-            dword_5B65BC = 0;
-            v55 = dword_4E4560[v54];
-            _5B65AC_npcdata_fame_or_other = dword_4E4578[v54];
-            v56 = dword_4E4590[v54];
-            v57 = dword_4E45A8[v54];
-            _5B65A8_npcdata_uflags_or_other = v55;
-            _5B65B4_npcdata_loword_house_or_other = v57;
-            _5B65B0_npcdata_rep_or_other = v56;
-            dword_5B65C0 = v55 | _5B65AC_npcdata_fame_or_other | v56 | v57;
-          }
-          HouseDialogPressCloseBtn();
-          //goto LABEL_434;
-          /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
-          {
-            pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape;
-            pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v0;
-            *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
-            ++pMessageQueue_50CBD0->uNumMessages;
-          }*/
-          pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Escape, 1, 0);
-          continue;
-
-        case UIMSG_OnCastTownPortal:
-          pAudioPlayer->StopChannels(-1, -1);
-          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Book, WINDOW_TownPortal, (char *)uMessageParam);
-        continue;
-
-        case UIMSG_OnCastLloydsBeacon:
-          pAudioPlayer->StopChannels(-1, -1);
-          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Book, WINDOW_LloydsBeacon, 0);
-        continue;
-
-        case UIMSG_LloydsBeacon_FlippingBtn:
-          bRecallingBeacon = uMessageParam;
-          v127 = uMessageParam + 204;
-          pAudioPlayer->PlaySound((SoundID)v127, 0, 0, -1, 0, 0, 0, 0);
-          continue;
-        case UIMSG_HintBeaconSlot:
-          if ( !pGUIWindow_CurrentMenu )
-            continue;
-          pPlayer = pPlayers[_506348_current_lloyd_playerid + 1];
-          uNumSeconds = (unsigned int)&pPlayer->pInstalledBeacons[uMessageParam];
-          if ( bRecallingBeacon )
-          {
-            if ( !*((int *)&pSavegameThumbnails[10 * uMessageParam].pPixels ) )
-              continue;
-            v173 = pMapStats->pInfos[pMapStats->sub_410D99_get_map_index(pPlayer->pInstalledBeacons[uMessageParam].SaveFileID)].pName;
-            sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[474], v173);// "Recall to %s"
-            GameUI_SetFooterString(pTmpBuf.data());
-            continue;
-          }
-          pMapNum = pMapStats->GetMapInfo(pCurrentMapName);
-          pMapName = "Not in Map Stats";
-          if ( pMapNum )
-            pMapName = pMapStats->pInfos[pMapNum].pName;
-          if ( !*((int *)&pSavegameThumbnails[10 * uMessageParam].pPixels ) || !pMapNum )
-          {
-            sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[476], pMapName);// "Set to %s"
-            GameUI_SetFooterString(pTmpBuf.data());
-            continue;
-          }
-          v174 = pMapStats->pInfos[pMapStats->sub_410D99_get_map_index(*(short *)(uNumSeconds + 26))].pName;
-          sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[475], (unsigned int)pMapName, v174);// "Set %s over %s"
-          GameUI_SetFooterString(pTmpBuf.data());
-          continue;
-        case UIMSG_CloseAfterInstallBeacon:
-          dword_50CDC8 = 1;
-          pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Escape, 0, 0);
-          /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
-            continue;
-          pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape;
-          pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
-          *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
-          ++pMessageQueue_50CBD0->uNumMessages;*/
-          continue;
-        case UIMSG_InstallBeacon:
-          pPlayer9 = pPlayers[_506348_current_lloyd_playerid + 1];
-          if ( !pPlayer9->pInstalledBeacons[uMessageParam].uBeaconTime && bRecallingBeacon )
-            continue;
-          byte_506360 = 1;
-          pPlayer9->CanCastSpell(uRequiredMana);
-          if ( pParty->bTurnBasedModeOn )
-          {
-            v60 = sRecoveryTime;
-            pParty->pTurnBasedPlayerRecoveryTimes[_506348_current_lloyd_playerid] = sRecoveryTime;
-            pPlayer9->SetRecoveryTime(v60);
-            pTurnEngine->ApplyPlayerAction();
-          }
-          else
-          {
-            pPlayer9->SetRecoveryTime((signed __int64)(flt_6BE3A4_debug_recmod1 * (double)sRecoveryTime * 2.133333333333333));
-          }
-          pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[lloyds_beacon_spell_id], 0, 0, -1, 0, lloyds_beacon_sound_id, 0, 0);
-          if ( bRecallingBeacon )
-          {
-            if ( _stricmp(pCurrentMapName, (const char *)&pGames_LOD->pSubIndices[pPlayer9->pInstalledBeacons[uMessageParam].SaveFileID]) )
-            {
-              SaveGame(1, 0);
-              OnMapLeave();
-              strcpy(pCurrentMapName, (const char *)&pGames_LOD->pSubIndices[pPlayer9->pInstalledBeacons[uMessageParam].SaveFileID]);
-              dword_6BE364_game_settings_1 |= GAME_SETTINGS_0001;
-              uGameState = GAME_STATE_CHANGE_LOCATION;
-              _5B65A8_npcdata_uflags_or_other = pPlayer9->pInstalledBeacons[uMessageParam].PartyPos_X;
-              _5B65AC_npcdata_fame_or_other = pPlayer9->pInstalledBeacons[uMessageParam].PartyPos_Y;
-              _5B65B0_npcdata_rep_or_other = pPlayer9->pInstalledBeacons[uMessageParam].PartyPos_Z;
-              _5B65B4_npcdata_loword_house_or_other = pPlayer9->pInstalledBeacons[uMessageParam].PartyRot_X;
-              _5B65B8_npcdata_hiword_house_or_other = pPlayer9->pInstalledBeacons[uMessageParam].PartyRot_Y;
-              dword_5B65C0 = 1;
-            }
-            else
-            {
-              pParty->vPosition.x = pPlayer9->pInstalledBeacons[uMessageParam].PartyPos_X;
-              pParty->vPosition.y = pPlayer9->pInstalledBeacons[uMessageParam].PartyPos_Y;
-              pParty->vPosition.z = pPlayer9->pInstalledBeacons[uMessageParam].PartyPos_Z;
-              pParty->uFallStartY = pParty->vPosition.z;
-              pParty->sRotationY = pPlayer9->pInstalledBeacons[uMessageParam].PartyRot_X;
-              pParty->sRotationX = pPlayer9->pInstalledBeacons[uMessageParam].PartyRot_Y;
-            }
-            pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Escape, 1, 0);
-            pBooksWindow->Release();
-            pGUIWindow_CurrentMenu->Release();
-            pBooksWindow = 0;
-            pGUIWindow_CurrentMenu = 0;
-          }
-          else
-          {
-            sprintf(a1, "data\\lloyd%d%d.pcx", _506348_current_lloyd_playerid + 1, uMessageParam + 1);
-            pRenderer->SaveScreenshot(a1, 92, 68);
-            LoadThumbnailLloydTexture(uMessageParam, _506348_current_lloyd_playerid + 1);
-            pPlayer9->pInstalledBeacons[uMessageParam].uBeaconTime = pParty->uTimePlayed + (signed __int64)((double)(lloyds_beacon_spell_level << 7) * 0.033333335);
-            pPlayer9->pInstalledBeacons[uMessageParam].PartyPos_X = pParty->vPosition.x;
-            pPlayer9->pInstalledBeacons[uMessageParam].PartyPos_Y = pParty->vPosition.y;
-            pPlayer9->pInstalledBeacons[uMessageParam].PartyPos_Z = pParty->vPosition.z;
-            pPlayer9->pInstalledBeacons[uMessageParam].PartyRot_X = LOWORD(pParty->sRotationY);
-            pPlayer9->pInstalledBeacons[uMessageParam].PartyRot_Y = LOWORD(pParty->sRotationX);
-            if ( (signed int)pGames_LOD->uNumSubDirs / 2 <= 0 )
-              continue;
-            for ( thisg = 0; thisg < (signed int)pGames_LOD->uNumSubDirs / 2; ++thisg )
-            {
-              if ( !_stricmp(pGames_LOD->pSubIndices[thisg].pFilename, pCurrentMapName) )
-                pPlayer9->pInstalledBeacons[uMessageParam].SaveFileID = thisg;
-            }
-          }
-          continue;
-        case UIMSG_ClickTownInTP:
-          if ( uMessageParam )
-          {
-            switch ( uMessageParam )
-            {
-              case 1:
-                v63 = 208;
-                break;
-              case 2:
-                v63 = 207;
-                break;
-              case 3:
-                v63 = 211;
-                break;
-              case 4:
-                v63 = 209;
-                break;
-              default:
-                if ( uMessageParam != 5 )
-                {
-LABEL_486:
-                  SaveGame(1, 0);
-                  v64 = pMapStats->GetMapInfo(pCurrentMapName);
-                  v65 = uMessageParam;
-                  if ( v64 == TownPortalList[uMessageParam].uMapInfoID )
-                  {
-                    pParty->vPosition.x = TownPortalList[v65].pos.x;
-                    pParty->vPosition.y = TownPortalList[v65].pos.y;
-                    pParty->vPosition.z = TownPortalList[v65].pos.z;
-                    pParty->uFallStartY = pParty->vPosition.z;
-                    pParty->sRotationY = TownPortalList[v65].rot_y;
-                    pParty->sRotationX = TownPortalList[v65].rot_x;
-                  }
-                  else
-                  {
-                    SaveGame(1, 0);
-                    OnMapLeave();
-                    dword_6BE364_game_settings_1 |= GAME_SETTINGS_0001;
-                    uGameState = GAME_STATE_CHANGE_LOCATION;
-                    strcpy(pCurrentMapName, pMapStats->pInfos[TownPortalList[uMessageParam].uMapInfoID].pFilename);
-                    dword_5B65C0 = 1;
-                    _5B65A8_npcdata_uflags_or_other = TownPortalList[uMessageParam].pos.x;
-                    _5B65AC_npcdata_fame_or_other = TownPortalList[uMessageParam].pos.y;
-                    _5B65B0_npcdata_rep_or_other = TownPortalList[uMessageParam].pos.z;
-                    v66 = TownPortalList[uMessageParam].rot_x;
-                    _5B65B4_npcdata_loword_house_or_other = TownPortalList[uMessageParam].rot_y;
-                    _5B65B8_npcdata_hiword_house_or_other = v66;
-                    Actor::InitializeActors();
-                  }
-                  v67 = (char*)pGUIWindow_CurrentMenu->Hint;
-                  if ( v67 )
-                    *((int *)v67 + 17) = 1;
-                  else
-                    pParty->pPlayers[(unsigned __int8)town_portal_caster_id].CanCastSpell(0x14u);
-                  /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
-                  {
-                    pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape;
-                    pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v0;
-                    *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
-                    ++pMessageQueue_50CBD0->uNumMessages;
-                  }*/
-                  pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Escape, 1, 0);
-                  continue;
-                }
-                v63 = 210;
-                break;
-            }
-          }
-          else
-          {
-            v63 = 206;
-          }
-          if ( !(unsigned __int16)_449B57_test_bit(pParty->_quest_bits, v63) )
-            return;
-          goto LABEL_486;
-        case UIMSG_HintTownPortal:
-          if ( uMessageParam )
-          {
-            switch ( uMessageParam )
-            {
-              case 1:
-                v68 = 208;
-                break;
-              case 2:
-                v68 = 207;
-                break;
-              case 3:
-                v68 = 211;
-                break;
-              case 4:
-                v68 = 209;
-                break;
-              default:
-                if ( uMessageParam != 5 )
-                  //goto LABEL_506;
-                {
-                  if ( uMessageParam )
-                  {
-                    switch ( uMessageParam )
-                    {
-                    case 1:
-                      v69 = pMapStats->pInfos[4].pName;
-                      break;
-                    case 2:
-                      v69 = pMapStats->pInfos[3].pName;
-                      break;
-                    case 3:
-                      v69 = pMapStats->pInfos[10].pName;
-                      break;
-                    case 4:
-                      v69 = pMapStats->pInfos[7].pName;
-                      break;
-                    default:
-                    if ( uMessageParam != 5 )
-                    {
-                      __debugbreak(); // warning C4700: uninitialized local variable 'v200' used
-                      sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[35], v200);
-                      GameUI_SetFooterString(pTmpBuf.data());
-                      continue;
-                    }
-                    v69 = pMapStats->pInfos[8].pName;
-                    break;
-                  }
-                }
-                else
-                {
-                  v69 = pMapStats->pInfos[21].pName;
-                }
-                sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[35], v69);
-                GameUI_SetFooterString(pTmpBuf.data());
-                continue;
-              }
-              v68 = 210;
-              break;
-            }
-          }
-          else
-          {
-            v68 = 206;
-          }
-          if ( !(unsigned __int16)_449B57_test_bit(pParty->_quest_bits, v68) )
-          {
-            pRenderer->DrawTextureRGB(0, 0x160u, pTexture_StatusBar);
-            continue;
-          }
-//LABEL_506:
-          if ( uMessageParam )
-          {
-            switch ( uMessageParam )
-            {
-              case 1:
-                v69 = pMapStats->pInfos[4].pName;
-                break;
-              case 2:
-                v69 = pMapStats->pInfos[3].pName;
-                break;
-              case 3:
-                v69 = pMapStats->pInfos[10].pName;
-                break;
-              case 4:
-                v69 = pMapStats->pInfos[7].pName;
-                break;
-              default:
-                if ( uMessageParam != 5 )
-                  //goto LABEL_519;
-                  {
-                    sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[35], v200);
-                    GameUI_SetFooterString(pTmpBuf.data());
-                    continue;
-                  }
-                v69 = pMapStats->pInfos[8].pName;
-                break;
-            }
-          }
-          else
-          {
-            v69 = pMapStats->pInfos[21].pName;
-          }
-          sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[35], v69);
-          GameUI_SetFooterString(pTmpBuf.data());
-          continue;
-        case UIMSG_ShowFinalWindow:
-          sprintfex(pFinalMessage.data(), "%s\n \n%s\n \n%s", pGlobalTXT_LocalizationStrings[151],// "Congratulations Adventurer."
-            pGlobalTXT_LocalizationStrings[118],// "We hope that you've enjoyed playing Might and Magic VII as much as we did making it. We have saved this screen as MM7_WIN.PCX in your MM7 directory. You can print it out as proof of your accomplishment."
-            pGlobalTXT_LocalizationStrings[167]);// "- The Might and Magic VII Development Team."   
-          ModalWindow(pFinalMessage.data(), UIMSG_OnFinalWindowClose);
-          uGameState = GAME_STATE_FINAL_WINDOW;
-          continue;
-        case UIMSG_OnFinalWindowClose:
-			__debugbreak();
-          uGameState = GAME_STATE_PLAYING;
-          strcpy((char *)pKeyActionMap->pPressedKeysBuffer, "2");
-          __debugbreak(); // missed break/continue?
-        case UIMSG_DD:
-			__debugbreak();
-          sprintf(pTmpBuf.data(), "%s", pKeyActionMap->pPressedKeysBuffer);
-          memcpy(&v216, txt_file_frametable_parser(pKeyActionMap->pPressedKeysBuffer, &v218), sizeof(v216));
-          if ( v216.uPropCount == 1 )
-          {
-            pNPCData4 = (NPCData *)((signed int)pGames_LOD->uNumSubDirs / 2);
-            v70 = atoi(v216.pProperties[0]);
-            if ( v70 <= 0 || v70 >= 77 )
-              continue;
-            v71 = v70;
-            strcpy(Str2, pMapStats->pInfos[v70].pFilename);
-            pNPCData3 = 0;
-            if ( (signed int)pNPCData4 > 0 )
-            {
-              thish = 0;
-              do
-              {
-                if ( !_stricmp(pGames_LOD->pSubIndices[thish].pFilename, Str2) )
-                  break;
-                ++thish;
-                pNPCData3 = (NPCData *)((char *)pNPCData3 + 1);
-              }
-              while ( (signed int)pNPCData3 < (signed int)pNPCData4 );
-              if ( (signed int)pNPCData3 < (signed int)pNPCData4 )
-              {
-                strcpy(pCurrentMapName, pGames_LOD->pSubIndices[(int)pNPCData3].pFilename);
-                dword_6BE364_game_settings_1 |= GAME_SETTINGS_0001;
-                uGameState = GAME_STATE_CHANGE_LOCATION;
-                OnMapLeave();
-                continue;
-              }
-            }
-            sprintf(Str2, "No map found for %s", pMapStats->pInfos[v71].pName);
-            v73 = Str2;
-          }
-          else
-          {
-            if ( v216.uPropCount != 3 )
-              continue;
-            v74 = atoi(v216.pProperties[0]);
-            thisi = atoi(v216.pProperties[1]);
-            v75 = atoi(v216.pProperties[2]);
-            v76 = v75;
-            if ( uCurrentlyLoadedLevelType == LEVEL_Indoor)
-            {
-              if ( pIndoor->GetSector(v74, thisi, v75) )
-              {
-                v77 = thisi;
-                pParty->vPosition.x = v74;
-                pParty->vPosition.y = v77;
-                pParty->vPosition.z = v76;
-                pParty->uFallStartY = v76;
-                continue;
-              }
-            }
-            else
-            {
-              if ( v74 > -32768 )
-              {
-                if ( v74 < 32768 )
-                {
-                  v77 = thisi;
-                  if ( thisi > -32768 )
-                  {
-                    if ( thisi < 32768 && v76 >= 0 && v76 < 10000 )
-                    {
-                      pParty->vPosition.x = v74;
-                      pParty->vPosition.y = v77;
-                      pParty->vPosition.z = v76;
-                      pParty->uFallStartY = v76;
-                      continue;
-                    }
-                  }
-                }
-              }
-            }
-            pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);
-            v73 = "Can't jump to that location!";
-          }
-          ShowStatusBarString(v73, 6);
-          continue;
-        case UIMSG_CastQuickSpell:
-          if ( bUnderwater == 1 )
-          {
-            ShowStatusBarString(pGlobalTXT_LocalizationStrings[652], 2);// "You can not do that while you are underwater!"
-            pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);
-            continue;
-          }
-          if ( !uActiveCharacter || (pPlayer2 = pPlayers[uActiveCharacter], pPlayer2->uTimeToRecovery) )
-            continue;
-          _42777D_CastSpell_UseWand_ShootArrow(pPlayer2->uQuickSpell, uActiveCharacter - 1, 0, 0, uActiveCharacter);
-          continue;
-        case UIMSG_CastSpell_Monster_Improvement:
-        case UIMSG_CastSpell_Shoot_Monster://FireBlow, Lightning, Ice Lightning, Swarm, 
-          //if ( pRenderer->pRenderD3D )
-          {
-            v81 = pGame->pVisInstance->get_picked_object_zbuf_val();
-          }
-          /*else
-          {
-            uNumSeconds = (unsigned int)pMouse->GetCursorPos(&v206);
-            pPoint2 = pMouse->GetCursorPos(&v201);
-            v81 = pRenderer->pActiveZBuffer[*(int *)uNumSeconds + pSRZBufferLineOffsets[pPoint2->y]];
-          }*/
-          v83 = v81;
-          v44 = (unsigned __int16)v81;
-          v84 = v83 >> 16;
-          if ( PID_TYPE(v44) != 3 || v84 >= 5120 )
-            continue;
-          pSpellInfo = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
-          if ( uMessage == UIMSG_CastSpell_Shoot_Monster )
-          {
-            pSpellInfo->uFlags &= ~0x08;
-          }
-          else
-          {
-            if ( uMessage == UIMSG_CastSpell_Monster_Improvement )
-              pSpellInfo->uFlags &= ~0x0100u;
-            else
-              pSpellInfo->uFlags &= ~0x0200u;
-          }
-          pSpellInfo->uPlayerID_2 = uMessageParam;
-          pSpellInfo->spell_target_pid = v44;
-          pParty->pPlayers[pSpellInfo->uPlayerID].SetRecoveryTime(300);
-          pGUIWindow_Settings->Release();
-          pGUIWindow_Settings = 0;
-          pMouse->SetCursorBitmap("MICON1");
-          GameUI_Footer_TimeLeft = 0;
-          _50C9A0_IsEnchantingInProgress = 0;
-          back_to_game();
-          continue;
-        case UIMSG_1C:
-			__debugbreak();
-          if ( !uActiveCharacter || pCurrentScreen )
-            continue;
-          ptr_507BC8 = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_68, uMessageParam, 0);
-          pCurrentScreen = SCREEN_19;
-          pEventTimer->Pause();
-          continue;
-        case UIMSG_STEALFROMACTOR:
-          if ( !uActiveCharacter )
-            continue;
-          if ( pParty->bTurnBasedModeOn != 1 )
-          {
-            if ( pActors[uMessageParam].uAIState == 5 )
-              pActors[uMessageParam].LootActor();
-            else
-              Actor::StealFrom(uMessageParam);
-            continue;
-          }
-          if ( pTurnEngine->turn_stage == TE_WAIT || pTurnEngine->turn_stage == TE_MOVEMENT )
-            continue;
-          if ( !(pTurnEngine->field_18 & TE_HAVE_PENDING_ACTIONS) )
-          {
-            if ( pActors[uMessageParam].uAIState == 5 )
-              pActors[uMessageParam].LootActor();
-            else
-              Actor::StealFrom(uMessageParam);
-          }
-          continue;
-
-        case UIMSG_Attack:
-          if ( !uActiveCharacter )
-            continue;
-          if ( pParty->bTurnBasedModeOn != 1 )
-          {
-            Player::_42ECB5_PlayerAttacksActor();
-            continue;
-          }
-          if ( pTurnEngine->turn_stage == TE_WAIT || pTurnEngine->turn_stage == TE_MOVEMENT )
-            continue;
-          if ( !(pTurnEngine->field_18 & TE_HAVE_PENDING_ACTIONS) )
-            Player::_42ECB5_PlayerAttacksActor();
-          continue;
-        case UIMSG_ExitRest:
-          GUIWindow::Create(pButton_RestUI_Exit->uX, pButton_RestUI_Exit->uY, 0, 0, WINDOW_CloseRestWindowBtn, (int)pButton_RestUI_Exit, pGlobalTXT_LocalizationStrings[81]);// "Exit Rest"
-          continue;
-        case UIMSG_Wait5Minutes:
-          if ( dword_506F14 == 2 )
-          {
-            ShowStatusBarString(pGlobalTXT_LocalizationStrings[477], 2);// "You are already resting!"
-            pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);
-            continue;
-          }
-          GUIWindow::Create(pButton_RestUI_Wait5Minutes->uX, pButton_RestUI_Wait5Minutes->uY, 0, 0, WINDOW_PressedButton2,
-            (int)pButton_RestUI_Wait5Minutes, pGlobalTXT_LocalizationStrings[238]);// "Wait 5 Minutes"
-          dword_506F14 = 1;
-          _506F18_num_minutes_to_sleep = 5;
-          continue;
-        case UIMSG_Wait1Hour:
-          if ( dword_506F14 == 2 )
-          {
-            ShowStatusBarString(pGlobalTXT_LocalizationStrings[477], 2);// "You are already resting!"
-            pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);
-            continue;
-          }
-          GUIWindow::Create(pButton_RestUI_Wait1Hour->uX, pButton_RestUI_Wait1Hour->uY, 0, 0, WINDOW_PressedButton2,
-            (int)pButton_RestUI_Wait1Hour, pGlobalTXT_LocalizationStrings[239]);// "Wait 1 Hour"
-          dword_506F14 = 1;
-          _506F18_num_minutes_to_sleep = 60;
-          continue;
-        case UIMSG_RentRoom:
-          dword_506F14 = 2;
-          RestUI_Load();
-          v86 = 60 * (_494820_training_time(pParty->uCurrentHour) + 1) - pParty->uCurrentMinute;
-          _506F18_num_minutes_to_sleep = v86;
-          if ( uMessageParam == 111 || uMessageParam == 114 || uMessageParam == 116 ) // 107 = Emerald Isle tavern
-            _506F18_num_minutes_to_sleep = v86 + 12 * 60;
-          dword_506F14 = 2;
-          pParty->RestAndHeal();
-          pParty->days_played_without_rest = 0;
-          pParty->pPlayers[3].SetAsleep(1);
-          pParty->pPlayers[2].SetAsleep(1);
-          pParty->pPlayers[1].SetAsleep(1);
-          pParty->pPlayers[0].SetAsleep(1);
-          continue;
-        case UIMSG_RestWindow:
-          if ( pMessageQueue_50CBD0->uNumMessages )
-            pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-          if ( pCurrentScreen )
-            continue;
-          if ( CheckActors_proximity() )
-          {
-            if ( pParty->bTurnBasedModeOn == 1 )
-            {
-              ShowStatusBarString(pGlobalTXT_LocalizationStrings[478], 2);// "You can't rest in turn-based mode!"
-              continue;
-            }
-            v88 = pGlobalTXT_LocalizationStrings[480];// "There are hostile enemies near!"
-            if ( pParty->uFlags & 0x88 )
-              v88 = pGlobalTXT_LocalizationStrings[479];// "You can't rest here!"
-            ShowStatusBarString(v88, 2);
-            if ( !uActiveCharacter )
-              continue;
-            pPlayers[uActiveCharacter]->PlaySound((PlayerSpeech)13, 0);
-            continue;
-          }
-          if ( pParty->bTurnBasedModeOn == 1 )
-          {
-            ShowStatusBarString(pGlobalTXT_LocalizationStrings[478], 2);// "You can't rest in turn-based mode!"
-            continue;
-          }
-          if ( !(pParty->uFlags & 0x88) )
-          {
-            RestUI_Load();
-            continue;
-          }
-          if ( pParty->bTurnBasedModeOn == 1 )
-          {
-            ShowStatusBarString(pGlobalTXT_LocalizationStrings[478], 2);// "You can't rest in turn-based mode!"
-            continue;
-          }
-          v88 = pGlobalTXT_LocalizationStrings[480];// "There are hostile enemies near!"
-          if ( pParty->uFlags & 0x88 )
-            v88 = pGlobalTXT_LocalizationStrings[479];// "You can't rest here!"
-          ShowStatusBarString(v88, 2u);
-          if ( !uActiveCharacter )
-            continue;
-          pPlayers[uActiveCharacter]->PlaySound((PlayerSpeech)13, 0);
-          continue;
-        case UIMSG_Rest8Hour:
-          if ( dword_506F14 )
-          {
-            ShowStatusBarString(pGlobalTXT_LocalizationStrings[477], 2);// "You are already resting!"
-            pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);
-            continue;
-          }
-          if ( pParty->uNumFoodRations < uRestUI_FoodRequiredToRest )
-          {
-            ShowStatusBarString(pGlobalTXT_LocalizationStrings[482], 2u);// "You don't have enough food to rest"
-            if ( uActiveCharacter && pPlayers[uActiveCharacter]->CanAct() )
-              pPlayers[uActiveCharacter]->PlaySound((PlayerSpeech)SPEECH_108, 0);
-          }
-          else
-          {
-            pParty->pPlayers[3].pConditions[Condition_Sleep] = pParty->uTimePlayed;
-            pParty->pPlayers[2].pConditions[Condition_Sleep] = pParty->uTimePlayed;
-            pParty->pPlayers[1].pConditions[Condition_Sleep] = pParty->uTimePlayed;
-            pParty->pPlayers[0].pConditions[Condition_Sleep] = pParty->uTimePlayed;
-            v90 = pMapStats->GetMapInfo(pCurrentMapName);
-            if ( !v90 )
-              v90 = rand() % (signed int)pMapStats->uNumMaps + 1;
-            pMapInfo = &pMapStats->pInfos[v90];
-            if ( rand() % 100 + 1 <= pMapInfo->Encounter_percent )
-            {
-              v91 = rand() % 100;
-              v92 = pMapInfo->EncM1percent;
-              v93 = v91 + 1;
-              if ( v93 > v92 )
-                pNPCData4 = (NPCData *)((v93 > v92 + pMapInfo->EncM2percent) + 2);
-              else
-                pNPCData4 = (NPCData *)1;
-              if ( !_45063B_spawn_some_monster(pMapInfo, (int)pNPCData4) )
-                pNPCData4 = 0;
-              if ( pNPCData4 )
-              {
-                pPlayerNum = rand() % 4;
-                pParty->pPlayers[pPlayerNum].pConditions[Condition_Sleep] = 0;
-                v95 = rand();
-                Rest(v95 % 6 + 60);
-                _506F18_num_minutes_to_sleep = 0;
-                dword_506F14 = 0;
-                /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
-                {
-                  pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape;
-                  pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
-                  *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
-                  ++pMessageQueue_50CBD0->uNumMessages;
-                }*/
-                pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Escape, 0, 0);
-                ShowStatusBarString(pGlobalTXT_LocalizationStrings[481], 2);// "Encounter!"
-                pAudioPlayer->PlaySound(SOUND_encounter, 0, 0, -1, 0, 0, 0, 0);
-                continue;
-              }
-            }
-            Party::TakeFood(uRestUI_FoodRequiredToRest);
-            _506F18_num_minutes_to_sleep = 480;
-            dword_506F14 = 2;
-            pParty->RestAndHeal();
-            pParty->days_played_without_rest = 0;
-            pParty->pPlayers[3].SetAsleep(1);
-            pParty->pPlayers[2].SetAsleep(1);
-            pParty->pPlayers[1].SetAsleep(1);
-            pParty->pPlayers[0].SetAsleep(1);
-          }
-          continue;
-        case UIMSG_AlreadyResting:
-          if ( dword_506F14 == 2 )
-          {
-            ShowStatusBarString(pGlobalTXT_LocalizationStrings[477], 2);// "You are already resting!"
-            pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);
-            continue;
-          }
-          GUIWindow::Create(pButton_RestUI_WaitUntilDawn->uX, pButton_RestUI_WaitUntilDawn->uY, 0, 0, WINDOW_PressedButton2,
-            (int)pButton_RestUI_WaitUntilDawn, pGlobalTXT_LocalizationStrings[237]);// "Wait until Dawn"
-          v97 = _494820_training_time(pParty->uCurrentHour);
-          dword_506F14 = 1;
-          _506F18_num_minutes_to_sleep = 60 * v97 - pParty->uCurrentMinute;
-          continue;
-        case UIMSG_HintSelectRemoveQuickSpellBtn:
-          if ( quick_spell_at_page && byte_506550 )
-          {
-            v173 = pSpellStats->pInfos[quick_spell_at_page + 11 * pPlayers[uActiveCharacter]->lastOpenedSpellbookPage].pName;
-            sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[483], v173);
-          }
-          else
-          {
-            if ( pPlayers[uActiveCharacter]->uQuickSpell )
-              v177 = pGlobalTXT_LocalizationStrings[584];// "Click here to remove your Quick Spell"
-            else
-              v177 = pGlobalTXT_LocalizationStrings[484];// "Select a spell then click here to set a QuickSpell"
-            strcpy(pTmpBuf.data(), v177);
-          }
-          GameUI_SetFooterString(pTmpBuf.data());
-          continue;
-        case UIMSG_SPellbook_ShowHightlightedSpellInfo:
-          if ( !uActiveCharacter || (uNumSeconds = (unsigned int)pPlayers[uActiveCharacter],
-                !*(char *)(uNumSeconds + 11 * *(char *)(uNumSeconds + 6734) + uMessageParam + 402)) )
-            continue;
-          if ( sub_4637E0_is_there_popup_onscreen() )
-            dword_507B00_spell_info_to_draw_in_popup = uMessageParam + 1;
-          v98 = *(char *)(uNumSeconds + 6734);
-          if ( quick_spell_at_page - 1 == uMessageParam )
-          {
-            v178 = pSpellStats->pInfos[uMessageParam + 11 * v98 + 1].pName;
-            v161 = pGlobalTXT_LocalizationStrings[485];
-          }
-          else
-          {
-            v178 = pSpellStats->pInfos[uMessageParam + 11 * v98 + 1].pName;
-            v161 = pGlobalTXT_LocalizationStrings[486];
-          }
-          sprintfex(pTmpBuf.data(), v161, v178);
-          GameUI_SetFooterString(pTmpBuf.data());
-          continue;
-        case UIMSG_ClickInstallRemoveQuickSpellBtn:
-          GUIWindow::Create(pBtn_InstallRemoveSpell->uX, pBtn_InstallRemoveSpell->uY, 0, 0, WINDOW_PressedButton2, (int)pBtn_InstallRemoveSpell, 0);
-          if ( !uActiveCharacter )
-            continue;
-          pPlayer10 = pPlayers[uActiveCharacter];
-          if ( !byte_506550 || !quick_spell_at_page )
-          {
-            pPlayer10->uQuickSpell = 0;
-            quick_spell_at_page = 0;
-            pAudioPlayer->PlaySound(SOUND_fizzle, 0, 0, -1, 0, 0, 0, 0);
-            continue;
-          }
-          pPlayers[uActiveCharacter]->uQuickSpell = quick_spell_at_page + 11 * pPlayers[uActiveCharacter]->lastOpenedSpellbookPage;
-          AA1058_PartyQuickSpellSound[uActiveCharacter - 1].AddPartySpellSound(pPlayers[uActiveCharacter]->uQuickSpell, uActiveCharacter);
-          if ( uActiveCharacter )
-            pPlayer10->PlaySound(SPEECH_12, 0);
-          byte_506550 = 0;
-          continue;
-        case UIMSG_SpellBook_PressTab://ïåðåëèñòûâàíèå ñòðàíèö êëàâèøåé Tab
-        {
-          if ( !uActiveCharacter )
-            continue;
-          int skill_count = 0;
-          uAction = 0;
-          for ( uint i = 0; i < 9; i++ )
-          {
-            if ( pPlayers[uActiveCharacter]->pActiveSkills[PLAYER_SKILL_FIRE + i] )
-            {
-              if ( pPlayers[uActiveCharacter]->lastOpenedSpellbookPage == i )
-                uAction = skill_count;
-              v217[skill_count++] = i;
-            }
-          }
-          if ( !skill_count )//íåò ñêèëëîâ
-            pAudioPlayer->PlaySound((SoundID)(rand() % 2 + SOUND_TurnPageU), 0, 0, -1, 0, 0, 0, 0);
-          else
-          {
-            if ( GetAsyncKeyState(VK_SHIFT) )
-            {
-              --uAction;
-              if ( uAction < 0 )
-                uAction = skill_count - 1;
-            }
-            else
-            {
-              ++uAction;
-              if ( uAction >= skill_count )
-                uAction = 0;
-            }
-            OnCloseSpellBookPage();
-            pPlayers[uActiveCharacter]->lastOpenedSpellbookPage = LOBYTE(v217[uAction]);
-            pGUIWindow_CurrentMenu->OpenSpellBook();
-            pAudioPlayer->PlaySound((SoundID)(rand() % 2 + SOUND_TurnPageU), 0, 0, -1, 0, 0, 0, 0);
-          }
-          continue;
-        }
-        case UIMSG_OpenSpellbookPage:
-          if ( pTurnEngine->turn_stage == TE_MOVEMENT || !uActiveCharacter || uMessageParam == pPlayers[uActiveCharacter]->lastOpenedSpellbookPage )
-            continue;
-          OnCloseSpellBookPage();
-          pPlayers[uActiveCharacter]->lastOpenedSpellbookPage = uMessageParam;
-          pGUIWindow_CurrentMenu->OpenSpellBook();
-          pAudioPlayer->PlaySound((SoundID)(rand() % 2 + SOUND_TurnPageU), 0, 0, -1, 0, 0, 0, 0);
-          continue;
-        case UIMSG_SelectSpell:
-        {
-          if (pTurnEngine->turn_stage == TE_MOVEMENT)
-            continue;
-          if (!uActiveCharacter)
-            continue;
-
-            //  uNumSeconds = (unsigned int)pPlayers[uActiveCharacter];
-          Player* player = pPlayers[uActiveCharacter];
-          if (player->spellbook.pChapters[player->lastOpenedSpellbookPage].bIsSpellAvailable[uMessageParam])
-              //if ( *(char *)(uNumSeconds + 11 * *(char *)(uNumSeconds + &lastOpenedSpellbookPage) + uMessageParam + 402) )
-          {
-                if ( quick_spell_at_page - 1 == uMessageParam )
-                {
-                  pGUIWindow_CurrentMenu->Release();
-                  pEventTimer->Resume();
-                  viewparams->bRedrawGameUI = 1;
-                  pCurrentScreen = SCREEN_GAME;
-                  pIcons_LOD->RemoveTexturesPackFromTextureList();
-                  v103 = quick_spell_at_page + 11 * player->lastOpenedSpellbookPage;
-                  /*if ( dword_50C9E8 < 40 )
-                  {
-                    dword_50C9EC[3 * dword_50C9E8] = UIMSG_CastSpellFromBook;
-                    dword_50C9EC[3 * dword_50C9E8 + 1] = v103;
-                    dword_50C9EC[3 * dword_50C9E8 + 2] = uActiveCharacter - 1;
-                    ++dword_50C9E8;
-                  }*/
-                  pMessageQueue_50C9E8->AddGUIMessage(UIMSG_CastSpellFromBook, v103, uActiveCharacter - 1);
-                //  pMessageQueue_50CBD0->AddGUIMessage(UIMSG_CastSpellFromBook, v103, uActiveCharacter - 1);
-                }
-                else
-                {
-                  byte_506550 = 1;
-                  quick_spell_at_page = uMessageParam + 1;
-                }
-          }
-        }
-        continue;
-
-        case UIMSG_CastSpellFromBook:
-          if ( pTurnEngine->turn_stage != TE_MOVEMENT )
-            _42777D_CastSpell_UseWand_ShootArrow(uMessageParam, v199, 0, 0, 0);
-        continue;
-
-        case UIMSG_SpellScrollUse:
-			__debugbreak();
-          if ( pTurnEngine->turn_stage != TE_MOVEMENT )
-            _42777D_CastSpell_UseWand_ShootArrow(uMessageParam, v199, 133, 1, 0);
-          continue;
-        case UIMSG_SpellBookWindow:
-          if ( pTurnEngine->turn_stage == TE_MOVEMENT )
-            continue;
-          if ( bUnderwater == true )
-          {
-            ShowStatusBarString(pGlobalTXT_LocalizationStrings[652], 2);// "You can not do that while you are underwater!"
-            pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);
-          }
-          else
-          {
-            if ( pMessageQueue_50CBD0->uNumMessages )
-              pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-            if ( uActiveCharacter && !pPlayers[uActiveCharacter]->uTimeToRecovery )
-            {
-              if ( pCurrentScreen == SCREEN_GAME )
-              {
-                GUIWindow::Create(476, 450, 0, 0, WINDOW_PressedButton2, (int)pBtn_CastSpell, 0);
-                pCurrentScreen = SCREEN_SPELL_BOOK;
-                pEventTimer->Pause();
-                pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_SpellBook, 0, 0);
-                pAudioPlayer->PlaySound(SOUND_48, 0, 0, -1, 0, 0, 0, 0);
-                viewparams->field_48 = 1;
-                continue;
-              }
-              if ( pCurrentScreen != SCREEN_REST && pCurrentScreen != SCREEN_CHARACTERS
-                && (pCurrentScreen <= SCREEN_63 || pCurrentScreen > SCREEN_67) )
-              {
-                pGUIWindow_CurrentMenu->Release();
-                GUIWindow::Create(476, 450, 0, 0, WINDOW_PressedButton2, (int)pBtn_CastSpell, 0);
-                pCurrentScreen = SCREEN_SPELL_BOOK;
-                pEventTimer->Pause();
-                pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_SpellBook, 0, 0);
-                pAudioPlayer->PlaySound(SOUND_48, 0, 0, -1, 0, 0, 0, 0);
-                viewparams->field_48 = 1;
-                continue;
-              }
-            }
-          }
-          continue;
-        case UIMSG_QuickReference:
-          if ( pMessageQueue_50CBD0->uNumMessages )
-            pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-          if ( pCurrentScreen )
-            pGUIWindow_CurrentMenu->Release();
-          ++pIcons_LOD->uTexturePacksCount;
-          if ( !pIcons_LOD->uNumPrevLoadedFiles )
-            pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
-          GUIWindow::Create(0x230u, 0x1C2u, 0, 0, WINDOW_PressedButton2, (int)pBtn_QuickReference, 0);
-          viewparams->bRedrawGameUI = 1;
-          pEventTimer->Pause();
-          pAudioPlayer->StopChannels(-1, -1);
-          pCurrentScreen = SCREEN_QUICK_REFERENCE;
-          pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_QuickReference, 5, 0);
-          papredoll_dbrds[2] = pIcons_LOD->LoadTexture("BUTTEXI1", TEXTURE_16BIT_PALETTE);
-          pBtn_ExitCancel = pGUIWindow_CurrentMenu->CreateButton(0x187u, 0x13Cu, 0x4Bu, 0x21u, 1, 0, UIMSG_Escape, 0, 0,
-                         pGlobalTXT_LocalizationStrings[79],// "Exit"
-                         pIcons_LOD->GetTexture(uTextureID_BUTTDESC2), 0); //, v179);
-          continue;
-        case UIMSG_GameMenuButton:
-          if ( pCurrentScreen )
-          {
-            pGUIWindow_CurrentMenu->Release();
-            pEventTimer->Resume();
-            pCurrentScreen = SCREEN_GAME;
-            viewparams->bRedrawGameUI = 1;
-          }
-
-          stru_506E40.Release();
-          pRenderer->SaveScreenshot("gamma.pcx", 155, 117);
-          stru_506E40.LoadPCXFile("gamma.pcx", 0);
-
-          GUIWindow::Create(0x25Au, 0x1C2u, 0, 0, WINDOW_PressedButton, (int)pBtn_GameSettings, 0);
-//LABEL_453:
-          /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
-            continue;
-          pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape;
-          //goto LABEL_770;
-          pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
-          *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
-          ++pMessageQueue_50CBD0->uNumMessages;*/
-          pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Escape, 0, 0);
-          continue;
-        case UIMSG_ClickAwardScrollBar:
-          books_page_number = 1;
-          if ( pMouse->GetCursorPos(&v211)->y > 178 )
-            books_page_number = -1;
-          continue;
-        case UIMSG_ClickAwardsUpBtn:
-          GUIWindow::Create(pBtn_Up->uX, pBtn_Up->uY, 0, 0, WINDOW_CharactersPressedButton, (int)pBtn_Up, 0);
-          BtnUp_flag = 1;
-          continue;
-        case UIMSG_ClickAwardsDownBtn:
-          GUIWindow::Create(pBtn_Down->uX, pBtn_Down->uY, 0, 0, WINDOW_CharactersPressedButton, (int)pBtn_Down, 0);
-          BtnDown_flag = 1;
-          continue;
-        case UIMSG_ChangeDetaliz:
-          bRingsShownInCharScreen ^= 1;
-          pCharacterScreen_DetalizBtn->Release();
-          pCharacterScreen_DollBtn->Release();
-          if ( bRingsShownInCharScreen )
-          {
-            v128 = pIcons_LOD->GetTexture(uTextureID_detaliz_close_button)->uTextureHeight;
-            v125 = pIcons_LOD->GetTexture(uTextureID_detaliz_close_button)->uTextureWidth;
-            v123 = 445;
-            v121 = 470;
-          }
-          else
-          {
-            v128 = 30;
-            v125 = 30;
-            v123 = 300;
-            v121 = 600;
-          }
-          pCharacterScreen_DetalizBtn = pGUIWindow_CurrentMenu->CreateButton(v121, v123, v125, v128, 1, 0, UIMSG_ChangeDetaliz, 0, 0,
-                         pGlobalTXT_LocalizationStrings[64],// "Detail Toggle"
-                         0);
-          pCharacterScreen_DollBtn = pGUIWindow_CurrentMenu->CreateButton(0x1DCu, 0, 0xA4u, 0x159u, 1, 0, UIMSG_ClickPaperdoll, 0, 0, "", 0);
-          viewparams->bRedrawGameUI = 1;
-          continue;
-        case UIMSG_ClickPaperdoll:
-          OnPaperdollLeftClick();
-          continue;
-        case UIMSG_ClickStatsBtn:
-          pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 100;
-          CharacterUI_ReleaseButtons();
-          ReleaseAwardsScrollBar();
-          GUIWindow::Create(pCharacterScreen_StatsBtn->uX, pCharacterScreen_StatsBtn->uY, 0, 0, WINDOW_CharactersPressedButton, (int)pCharacterScreen_StatsBtn, 0);
-          continue;
-        case UIMSG_ClickSkillsBtn:
-          pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 101;
-          CharacterUI_ReleaseButtons();
-          ReleaseAwardsScrollBar();
-          CharacterUI_SkillsTab_CreateButtons();
-          GUIWindow::Create(pCharacterScreen_SkillsBtn->uX, pCharacterScreen_SkillsBtn->uY, 0, 0, WINDOW_CharactersPressedButton, (int)pCharacterScreen_SkillsBtn, 0);
-          continue;
-        case UIMSG_SkillUp:
-          pPlayer4 = pPlayers[uActiveCharacter];
-          v105 = (int)&pPlayer4->pActiveSkills[uMessageParam];
-          LOWORD(v2) = *(short *)v105;
-          uNumSeconds = v2;
-          if ( pPlayer4->uSkillPoints < (v2 & 0x3F) + 1 )
-          {
-            v87 = pGlobalTXT_LocalizationStrings[488];// "You don't have enough skill points!"
-          }
-          else
-          {
-            if ( (uNumSeconds & 0x3F) < 0x3C )
-            {
-              *(short *)v105 = uNumSeconds + 1;
-              pPlayer4->uSkillPoints -= pPlayer4->pActiveSkills[uMessageParam] & 0x3F;
-              pPlayer4->PlaySound(SPEECH_14, 0);
-              pAudioPlayer->PlaySound((SoundID)SOUND_quest, 0, 0, -1, 0, 0, 0, 0);
-              continue;
-            }
-            v87 = pGlobalTXT_LocalizationStrings[487];// "You have already mastered this skill!"
-          }
-          ShowStatusBarString(v87, 2);
-          continue;
-        case UIMSG_ClickInventoryBtn:
-          pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 103;
-          ReleaseAwardsScrollBar();
-          CharacterUI_ReleaseButtons();
-          GUIWindow::Create(pCharacterScreen_InventoryBtn->uX, pCharacterScreen_InventoryBtn->uY, 0, 0, WINDOW_CharactersPressedButton, (int)pCharacterScreen_InventoryBtn, 0);
-          continue;
-        case UIMSG_ClickExitCharacterWindowBtn:
-          GUIWindow::Create(pCharacterScreen_ExitBtn->uX, pCharacterScreen_ExitBtn->uY, 0, 0, WINDOW_ExitCharacterWindow, (int)pCharacterScreen_ExitBtn, 0);
-          continue;
-        case UIMSG_ClickAwardsBtn:
-          ReleaseAwardsScrollBar();
-          CharacterUI_ReleaseButtons();
-          CreateAwardsScrollBar();
-          pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 102;
-          GUIWindow::Create(pCharacterScreen_AwardsBtn->uX, pCharacterScreen_AwardsBtn->uY, 0, 0, WINDOW_CharactersPressedButton, (int)pCharacterScreen_AwardsBtn, 0);
-          FillAwardsData();
-          continue;
-        case UIMSG_ClickBooksBtn:
-          switch ( uMessageParam )
-          {
-            case 11://Page UP
-              BtnUp_flag = 1;
-              pButton = pBtn_Book_2;
-              break;
-            case 10://Page DOWN
-              BtnDown_flag = 1;
-              pButton = pBtn_Book_1;
-              break;
-            case 0://Zoom plus
-              pButton = pBtn_Book_1;
-              BtnDown_flag = 1;
-              break;
-            case 1://Zoom minus
-              pButton = pBtn_Book_2;
-              BtnUp_flag = 1;
-              break;
-            case 2://Potions
-              Book_PageBtn3_flag = 1;
-              if ( dword_506364 )
-                continue;
-              pButton = pBtn_Book_3;
-              break;
-            case 3://fountains
-              Book_PageBtn4_flag = 1;
-              if ( dword_506364 )
-                continue;
-              pButton = pBtn_Book_4;
-              break;
-            case 4://obelisks
-              Book_PageBtn5_flag = 1;//Autonotes_Obelisks_page_flag
-              if ( dword_506364 )
-                continue;
-              pButton = pBtn_Book_5;
-              break;
-            case 5://seer
-              Book_PageBtn6_flag = 1;//Autonotes_Seer_page_flag
-              if ( dword_506364 )
-                continue;
-              pButton = pBtn_Book_6;
-              break;
-            case 6://misc
-              pButton = pBtn_Autonotes_Misc;
-              Autonotes_Misc_page_flag = 1;
-              break;
-            case 7://Instructors
-              pButton = pBtn_Autonotes_Instructors;
-              Autonotes_Instructors_page_flag = 1;
-              break;
-            default:
-              continue;
-          }
-          GUIWindow::Create(pButton->uX, pButton->uY, 0, 0, WINDOW_PressedButton, (int)pButton, (char *)1);
-          continue;
-        case UIMSG_SelectCharacter:
-          if ( pMessageQueue_50CBD0->uNumMessages )
-            pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-          GameUI_OnPlayerPortraitLeftClick(uMessageParam);
-          continue;
-        case UIMSG_ShowStatus_Funds:
-          v174 = (char *)pParty->uNumGoldInBank;
-          //v158 = pParty->uNumGold + pParty->uNumGoldInBank;
-          sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[489], pParty->uNumGold + pParty->uNumGoldInBank, v174);// "You have %d total gold, %d in the Bank"
-          GameUI_SetFooterString(pTmpBuf.data());
-          continue;
-        case UIMSG_ShowStatus_DateTime:
-          currHour = pParty->uCurrentHour;
-          uNumSeconds = 1;
-          if (pParty->uCurrentHour > 12 )
-          {
-            if (pParty->uCurrentHour >= 24)
-              uNumSeconds = 0;
-            currHour = (currHour - 12);
-          }
-          else 
-          {
-		  	if (pParty->uCurrentHour < 12) // 12:00 is PM
-	            uNumSeconds = 0;
-            if (pParty->uCurrentHour == 0)
-              currHour = 12;
-          }
-          sprintf(pTmpBuf.data(), "%d:%02d%s %s %d %s %d", currHour, pParty->uCurrentMinute, aAMPMNames[uNumSeconds], aDayNames[pParty->uDaysPlayed % 7],
-            7 * pParty->uCurrentMonthWeek + pParty->uDaysPlayed % 7 + 1, aMonthNames[pParty->uCurrentMonth], pParty->uCurrentYear);
-          GameUI_SetFooterString(pTmpBuf.data());
-          continue;
-        case UIMSG_ShowStatus_Food:
-          sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[501], pParty->uNumFoodRations); // "You have %lu food"
-          GameUI_SetFooterString(pTmpBuf.data());
-          continue;
-        case UIMSG_ShowStatus_Player:
-          pPlayer5 = pPlayers[uMessageParam];
-          sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[429], pPlayer5->pName, pClassNames[pPlayer5->classType]);// "%s the %s"
-          strcat(pTmpBuf.data(), ": ");
-          v107 = pPlayer5->GetMajorConditionIdx();
-          strcat(pTmpBuf.data(), aCharacterConditionNames[v107]);
-          GameUI_SetFooterString(pTmpBuf.data());
-          v108 = 8 * uMessageParam - 8;
-          LOBYTE(v108) = v108 | 4;
-          pMouse->uPointingObjectID = PID(OBJECT_Player,v108);
-          continue;
-        case UIMSG_ShowStatus_ManaHP:
-          sprintf(pTmpBuf.data(), "%d / %d %s    %d / %d %s", pPlayers[uMessageParam]->sHealth, pPlayers[uMessageParam]->GetMaxHealth(), 
-                  pGlobalTXT_LocalizationStrings[108], pPlayers[uMessageParam]->sMana, pPlayers[uMessageParam]->GetMaxMana(), 
-                  pGlobalTXT_LocalizationStrings[212]);
-          GameUI_SetFooterString(pTmpBuf.data());
-          continue;
-        case UIMSG_CHEST_ClickItem:
-          if ( pCurrentScreen == SCREEN_CHEST_INVENTORY )
-          {
-            pPlayers[uActiveCharacter]->OnInventoryLeftClick();
-            continue;
-          }
-          Chest::OnChestLeftClick();
-          continue;
-        case UIMSG_InventoryLeftClick:
-          pPlayers[uActiveCharacter]->OnInventoryLeftClick();
-          continue;
-        case UIMSG_MouseLeftClickInGame:
-          /*if ( !pRenderer->pRenderD3D )
-          {
-            if ( pMessageQueue_50CBD0->uNumMessages )
-            pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-            OnGameViewportClick();
-            continue;
-          }*/
-          v115 = pMessageQueue_50CBD0->uNumMessages;
-          if ( !pMessageQueue_50CBD0->uNumMessages )
-          {
-            pMessageQueue_50CBD0->AddGUIMessage(UIMSG_MouseLeftClickInScreen, 0, 0);
-            /*if ( (signed int)v115 < 40 )
-            //goto LABEL_769;
-            {
-              pMessageQueue_50CBD0->pMessages[v115].eType = UIMSG_MouseLeftClickInScreen;
-              pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
-              *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
-              ++pMessageQueue_50CBD0->uNumMessages;
-              continue;
-            }*/
-            continue;
-          }
-          if ( pMessageQueue_50CBD0->pMessages[0].field_8 )
-          {
-            pMessageQueue_50CBD0->uNumMessages = 1;
-            pMessageQueue_50CBD0->AddGUIMessage(UIMSG_MouseLeftClickInScreen, 0, 0);
-            /*v115 = v0;
-            pMessageQueue_50CBD0->uNumMessages = v0;
-            pMessageQueue_50CBD0->pMessages[v115].eType = UIMSG_MouseLeftClickInScreen;
-            pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
-            //goto LABEL_771;
-            *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
-            ++pMessageQueue_50CBD0->uNumMessages;*/
-            continue;
-          }
-          v115 = 0;
-          pMessageQueue_50CBD0->uNumMessages = 0;
-          pMessageQueue_50CBD0->AddGUIMessage(UIMSG_MouseLeftClickInScreen, 0, 0);
-          /*if ( (signed int)v115 < 40 )
-            //goto LABEL_769;
-          {
-            pMessageQueue_50CBD0->pMessages[v115].eType = UIMSG_MouseLeftClickInScreen;
-            pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
-            *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
-            ++pMessageQueue_50CBD0->uNumMessages;
-            continue;
-          }*/
-          continue;
-        case UIMSG_MouseLeftClickInScreen://ñðàáàòûâàåò ïðè íàæàòèè íà ïðàâóþ êíîïêó ìûøè ïîñëå UIMSG_MouseLeftClickInGame
-          if ( pMessageQueue_50CBD0->uNumMessages )
-            pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-          OnGameViewportClick();
-          continue;
-        case UIMSG_F:
-			__debugbreak();
-          //if ( pRenderer->pRenderD3D )
-          {
-            LOWORD(v116) = pGame->pVisInstance->get_picked_object_zbuf_val();
-          }
-          /*else
-          {
-            uNumSeconds = (unsigned int)pMouse->GetCursorPos(&v209);
-            pPoint3 = pMouse->GetCursorPos(&v204);
-            v116 = pRenderer->pActiveZBuffer[*(int *)uNumSeconds + pSRZBufferLineOffsets[pPoint3->y]];
-          }*/
-          pButton2 = (GUIButton *)(unsigned __int16)v116;
-          GUIWindow::Create(0, 0, 0, 0, WINDOW_F, (int)pButton2, 0);
-          continue;
-        case UIMSG_54:
-			__debugbreak();
-          pButton2 = (GUIButton *)uMessageParam;
-          GUIWindow::Create(0, 0, 0, 0, WINDOW_22, (int)pButton2, 0);
-          continue;
-        case UIMSG_Game_Action:
-          if ( pMessageQueue_50CBD0->uNumMessages )
-            pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-          OnPressSpace();
-          continue;
-        case UIMSG_ClickZoomOutBtn:
-          if ( pCurrentScreen )
-            continue;
-          pParty->uFlags |= 2u;
-          GUIWindow::Create(519, 136, 0, 0, WINDOW_PressedButton2, (int)pBtn_ZoomOut, 0);
-          uNumSeconds = 131072;
-          v118 = 2 * viewparams->uMinimapZoom;
-          ++viewparams->field_28;
-          viewparams->uMinimapZoom *= 2;
-          if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor)
-          {
-            if ( (signed int)v118 > 4096 )
-            {
-              viewparams->uMinimapZoom = 4096;
-              viewparams->field_28 = 12;
-            }
-            continue;
-          }
-          v119 = 2048;
-          if ( (signed int)v118 <= 2048 )
-          {
-            _576E2C_current_minimap_zoom = v118;
-            dword_576E28 = viewparams->field_28;
-            break;
-          }
-          viewparams->field_28 = 11;
-          viewparams->uMinimapZoom = v119;
-          _576E2C_current_minimap_zoom = v119;
-          dword_576E28 = viewparams->field_28;
-          break;
-        case UIMSG_ClickZoomInBtn:
-          if ( pCurrentScreen )
-            continue;
-          pParty->uFlags |= 2u;
-          GUIWindow::Create(574, 136, 0, 0, WINDOW_PressedButton2, (int)pBtn_ZoomIn, 0);
-          uNumSeconds = 32768;
-          v118 = (unsigned __int64)((signed __int64)(signed int)viewparams->uMinimapZoom << 15) >> 16;
-          --viewparams->field_28;
-          viewparams->uMinimapZoom = (unsigned __int64)((signed __int64)(signed int)viewparams->uMinimapZoom << 15) >> 16;
-          if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor)
-          {
-            v119 = 512;
-            if ( (signed int)v118 < 512 )
-            {
-              viewparams->field_28 = 9;
-              v118 = v119;
-              viewparams->uMinimapZoom = v119;
-            }
-            _576E2C_current_minimap_zoom = v118;
-            dword_576E28 = viewparams->field_28;
-          }
-          else
-          {
-            if ( (signed int)v118 < 256 )
-            {
-              viewparams->uMinimapZoom = 256;
-              viewparams->field_28 = 8;
-            }
-          }
-        default:
-          continue;
-      }
-    }
-  }
-  pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50C9E8->uNumMessages;//dword_50C9E8;
-  memcpy(pMessageQueue_50CBD0->pMessages, pMessageQueue_50C9E8->pMessages, sizeof(GUIMessage) * pMessageQueue_50C9E8->uNumMessages);
-  //memcpy(pMessageQueue_50CBD0->pMessages, dword_50C9EC, 12 * dword_50C9E8);
-  //dword_50C9E8 = 0;
-
-
-   pMessageQueue_50C9E8->uNumMessages=0;
-  if ( dword_50C9DC )
-  {
-    /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
-    {
-      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)dword_50C9DC;
-      pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = (int)ptr_50C9E0;
-      *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
-      ++pMessageQueue_50CBD0->uNumMessages;
-    }*/
-    pMessageQueue_50CBD0->AddGUIMessage((UIMessageType)dword_50C9DC, (int)ptr_50C9E0, 0);
-    dword_50C9DC = 0;
-  }
-  else
-  {
-    if ( _50C9D0_AfterEnchClickEventId > 0 )
-    {
-      _50C9D8_AfterEnchClickEventTimeout -= pEventTimer->uTimeElapsed;
-      if ( _50C9D8_AfterEnchClickEventTimeout <= 0 )
-      {
-        /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
-        {
-          pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)dword_50C9D0;
-          pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = dword_50C9D4;
-          *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
-          ++pMessageQueue_50CBD0->uNumMessages;
-        }*/
-        pMessageQueue_50CBD0->AddGUIMessage((UIMessageType)_50C9D0_AfterEnchClickEventId, _50C9D4_AfterEnchClickEventSecondParam, 0);
-        _50C9D0_AfterEnchClickEventId = 0;
-        _50C9D4_AfterEnchClickEventSecondParam = 0;
-        _50C9D8_AfterEnchClickEventTimeout = 0;
-      }
-    }
-  }
-  CastSpellInfoHelpers::_427E01_cast_spell();
-}
-//----- (00435748) --------------------------------------------------------
-void  GUI_MainMenuMessageProc()
-{
-  Player *pPlayer; // ebx@2
-  void *v3; // edi@21
-  signed int v4; // eax@29
-//  int v5; // ecx@29
-//  PLAYER_SKILL_TYPE v6; // edi@37
-  GUIWindow *pWindow; // eax@56
-  GUIButton *pButton; // eax@59
-  int v15; // edi@70
-  char v20; // dl@116
-  unsigned int v21; // eax@116
-  unsigned int v25; // eax@120
-  unsigned int v26; // ecx@127
-//  SoundID pSoundID; // [sp-2Ch] [bp-3Ch]@36
-//  signed int v41; // [sp-10h] [bp-20h]@29
-  int pParam; // [sp+4h] [bp-Ch]@3
-  UIMessageType pUIMessageType; // [sp+8h] [bp-8h]@3
-  int pSex; // [sp+Ch] [bp-4h]@3
-
-  if ( pMessageQueue_50CBD0->uNumMessages )
-  {
-    pPlayer = pParty->pPlayers.data();
-    do
-    {
-      int param2;
-      pMessageQueue_50CBD0->PopMessage(&pUIMessageType, &pParam, &param2);
-      //auto player = &pParty->pPlayers[pParam];
-
-      switch (pUIMessageType) // For buttons of window MainMenu
-      {
-        case UIMSG_MainMenu_ShowPartyCreationWnd:
-          GUIWindow::Create(495, 172, 0, 0, WINDOW_PressedButton2, (int)pMainMenu_BtnNew, 0);
-          SetCurrentMenuID(MENU_NEWGAME);
-          break;
-        case UIMSG_MainMenu_ShowLoadWindow:
-          GUIWindow::Create(495, 227, 0, 0, WINDOW_PressedButton2, (int)pMainMenu_BtnLoad, 0);
-          SetCurrentMenuID(MENU_SAVELOAD);
-          break;
-        case UIMSG_ShowCredits:
-          GUIWindow::Create(495, 282, 0, 0, WINDOW_PressedButton2, (int)pMainMenu_BtnCredits, 0);
-          SetCurrentMenuID(MENU_CREDITS);
-          break;
-        case UIMSG_ExitToWindows:
-          GUIWindow::Create(495, 337, 0, 0, WINDOW_PressedButton2, (int)pMainMenu_BtnExit, 0);
-          SetCurrentMenuID(MENU_EXIT_GAME);
-          break;
-        case UIMSG_PlayerCreation_SelectAttribute:
-          pGUIWindow_CurrentMenu->pCurrentPosActiveItem = (pGUIWindow_CurrentMenu->pCurrentPosActiveItem - pGUIWindow_CurrentMenu->pStartingPosActiveItem)
-                                                    % 7 + pGUIWindow_CurrentMenu->pStartingPosActiveItem + 7 * pParam;
-          uPlayerCreationUI_SelectedCharacter = pParam;
-          pAudioPlayer->PlaySound(SOUND_SelectingANewCharacter, 0, 0, -1, 0, 0, 0, 0);
-          break;
-        case UIMSG_PlayerCreation_VoicePrev:
-          pSex = pParty->pPlayers[pParam].GetSexByVoice();
-          do
-          {
-            if (pParty->pPlayers[pParam].uVoiceID == 0)
-              pParty->pPlayers[pParam].uVoiceID = 19;
-            else --pParty->pPlayers[pParam].uVoiceID;
-          }
-          while (pParty->pPlayers[pParam].GetSexByVoice() != pSex);
-          pButton = pCreationUI_BtnPressLeft2[pParam];
-          GUIWindow::Create(pButton->uX, pButton->uY, 0, 0, WINDOW_PressedButton, (int)pButton, (char *)1);
-          pAudioPlayer->PlaySound(SOUND_SelectingANewCharacter, 0, 0, -1, 0, 0, 0, 0);
-          pParty->pPlayers[pParam].PlaySound(SPEECH_PickMe, 0);
-          break;
-        case UIMSG_PlayerCreation_VoiceNext:
-          pSex = pParty->pPlayers[pParam].GetSexByVoice();
-          do
-          {
-            pParty->pPlayers[pParam].uVoiceID = (pParty->pPlayers[pParam].uVoiceID + 1) % 20;
-          }
-          while (pParty->pPlayers[pParam].GetSexByVoice() != pSex);
-          pButton = pCreationUI_BtnPressRight2[pParam];
-          GUIWindow::Create(pButton->uX, pButton->uY, 0, 0, WINDOW_PressedButton, (int)pButton, (char *)1);
-          pAudioPlayer->PlaySound(SOUND_SelectingANewCharacter, 0, 0, -1, 0, 0, 0, 0);
-          pParty->pPlayers[pParam].PlaySound(SPEECH_PickMe, 0);
-          break;
-        case UIMSG_PlayerCreation_FacePrev:
-          //pPlayer = &pParty->pPlayers[pParam];
-          if (!pParty->pPlayers[pParam].uCurrentFace)
-            pParty->pPlayers[pParam].uCurrentFace = 19;
-          else
-            pParty->pPlayers[pParam].uCurrentFace -= 1;
-          pParty->pPlayers[pParam].uVoiceID = pParty->pPlayers[pParam].uCurrentFace;
-          pParty->pPlayers[pParam].SetInitialStats();
-          pParty->pPlayers[pParam].SetSexByVoice();
-          pParty->pPlayers[pParam].RandomizeName();
-          v25 = pParam;
-          pGUIWindow_CurrentMenu->pCurrentPosActiveItem = (pGUIWindow_CurrentMenu->pCurrentPosActiveItem - pGUIWindow_CurrentMenu->pStartingPosActiveItem)
-                                                    % 7 + pGUIWindow_CurrentMenu->pStartingPosActiveItem + 7 * pParam;
-          uPlayerCreationUI_SelectedCharacter = v25;
-          GUIWindow::Create(pCreationUI_BtnPressLeft[v25]->uX, pCreationUI_BtnPressLeft[v25]->uY, 0, 0, WINDOW_PressedButton, (int)pCreationUI_BtnPressLeft[v25], (char *)1);
-          pAudioPlayer->PlaySound(SOUND_SelectingANewCharacter, 0, 0, -1, 0, 0, 0.0, 0);
-          pParty->pPlayers[pParam].PlaySound(SPEECH_PickMe, 0);
-          break;
-        case UIMSG_PlayerCreation_FaceNext:
-          //pPlayer = &pParty->pPlayers[pParam];
-          v20 = (char)((int)pParty->pPlayers[pParam].uCurrentFace + 1) % 20;
-          pParty->pPlayers[pParam].uCurrentFace = v20;
-          pParty->pPlayers[pParam].uVoiceID = v20;
-          pParty->pPlayers[pParam].SetInitialStats();
-          pParty->pPlayers[pParam].SetSexByVoice();
-          pParty->pPlayers[pParam].RandomizeName();
-          v21 = pParam;
-          pGUIWindow_CurrentMenu->pCurrentPosActiveItem = (pGUIWindow_CurrentMenu->pCurrentPosActiveItem - pGUIWindow_CurrentMenu->pStartingPosActiveItem)
-                                                    % 7 + pGUIWindow_CurrentMenu->pStartingPosActiveItem + 7 * pParam;
-          uPlayerCreationUI_SelectedCharacter = v21;
-          GUIWindow::Create(pCreationUI_BtnPressRight[v21]->uX, pCreationUI_BtnPressRight[v21]->uY, 0, 0, WINDOW_PressedButton, (int)pCreationUI_BtnPressRight[v21], (char *)1);
-          pAudioPlayer->PlaySound(SOUND_SelectingANewCharacter, 0, 0, -1, 0, 0, 0, 0);
-          pParty->pPlayers[pParam].PlaySound(SPEECH_PickMe, 0);
-          break;
-        case UIMSG_PlayerCreationClickPlus:
-          GUIWindow::Create(613, 393, 0, 0, WINDOW_PressedButton2, (int)pPlayerCreationUI_BtnPlus, (char *)1);
-          pPlayer[uPlayerCreationUI_SelectedCharacter].IncreaseAttribute((pGUIWindow_CurrentMenu->pCurrentPosActiveItem - pGUIWindow_CurrentMenu->pStartingPosActiveItem) % 7);
-          pAudioPlayer->PlaySound(SOUND_ClickMinus, 0, 0, -1, 0, 0, 0, 0);
-          break;
-        case UIMSG_PlayerCreationClickMinus:
-          GUIWindow::Create(523, 393, 0, 0, WINDOW_PressedButton2, (int)pPlayerCreationUI_BtnMinus, (char *)1);
-          pPlayer[uPlayerCreationUI_SelectedCharacter].DecreaseAttribute((pGUIWindow_CurrentMenu->pCurrentPosActiveItem - pGUIWindow_CurrentMenu->pStartingPosActiveItem) % 7);
-          pAudioPlayer->PlaySound(SOUND_ClickPlus, 0, 0, -1, 0, 0, 0, 0);
-          break;
-        case UIMSG_PlayerCreationSelectActiveSkill:
-          if ( pPlayer[uPlayerCreationUI_SelectedCharacter].GetSkillIdxByOrder(3) == 37 )
-            pParty->pPlayers[uPlayerCreationUI_SelectedCharacter].pActiveSkills[pPlayer[uPlayerCreationUI_SelectedCharacter].GetSkillIdxByOrder(pParam + 4)] = 1;
-          pAudioPlayer->PlaySound(SOUND_ClickSkill, 0, 0, -1, 0, 0, 0, 0);
-          break;
-        case UIMSG_PlayerCreationSelectClass:
-          pPlayer[uPlayerCreationUI_SelectedCharacter].Reset((PLAYER_CLASS_TYPE)pParam);
-          pAudioPlayer->PlaySound(SOUND_SelectingANewCharacter, 0, 0, -1, 0, 0, 0, 0);
-          break;
-        case UIMSG_PlayerCreationClickOK:
-          GUIWindow::Create(580, 431, 0, 0, WINDOW_PressedButton2, (int)pPlayerCreationUI_BtnOK, 0);
-          if ( PlayerCreation_GetUnspentAttributePointCount() || !PlayerCreation_Choose4Skills() )
-            GameUI_Footer_TimeLeft = GetTickCount() + 4000;
-          else
-            uGameState = GAME_STATE_STARTING_NEW_GAME;
-          break;
-        case UIMSG_PlayerCreationClickReset:
-          GUIWindow::Create(527, 431, 0, 0, WINDOW_PressedButton2, (int)pPlayerCreationUI_BtnReset, 0);
-          pParty->Reset();
-          break;
-        case UIMSG_PlayerCreationRemoveUpSkill:
-          v4 = pGUIWindow_CurrentMenu->pCurrentPosActiveItem - pGUIWindow_CurrentMenu->pStartingPosActiveItem;
-          pGUIWindow_CurrentMenu->pCurrentPosActiveItem = v4 % 7 + pGUIWindow_CurrentMenu->pStartingPosActiveItem + 7 * pParam;
-          if ( pPlayer[pParam].GetSkillIdxByOrder(2) != 37 )//37 - None(Íåò)
-            pParty->pPlayers[pParam].pActiveSkills[pPlayer[pParam].GetSkillIdxByOrder(2)] = 0;
-          break;
-        case UIMSG_PlayerCreationRemoveDownSkill:
-          v4 = pGUIWindow_CurrentMenu->pCurrentPosActiveItem - pGUIWindow_CurrentMenu->pStartingPosActiveItem;
-          pGUIWindow_CurrentMenu->pCurrentPosActiveItem = v4 % 7 + pGUIWindow_CurrentMenu->pStartingPosActiveItem + 7 * pParam;
-          if ( pPlayer[pParam].GetSkillIdxByOrder(3) != 37 )//37 - None(Íåò)
-            pParty->pPlayers[pParam].pActiveSkills[pPlayer[pParam].GetSkillIdxByOrder(3)] = 0;
-          break;
-        case UIMSG_PlayerCreationChangeName:
-          pAudioPlayer->PlaySound(SOUND_ClickSkill, 0, 0, -1, 0, 0, 0, 0);
-          v3 = (void *)pParam;
-          uPlayerCreationUI_SelectedCharacter = pParam;
-          pKeyActionMap->EnterText(0, 15, pGUIWindow_CurrentMenu);
-          pGUIWindow_CurrentMenu->ptr_1C = v3;
-          break;
-        case UIMSG_ChangeGameState:
-          uGameState = GAME_FINISHED;
-          break;
-        case UIMSG_ChangeCursor:
-          pMouse->SetCursorBitmap("MICON2");
-          break;
-        case UIMSG_3A:
-          SetCurrentMenuID(MENU_DebugBLVLevel);
-          break;
-        case UIMSG_LoadGame:
-          if (!pSavegameUsedSlots[uLoadGameUI_SelectedSlot])
-            break;
-          SetCurrentMenuID(MENU_LoadingProcInMainMenu);
-          break;
-        case UIMSG_SelectLoadSlot:
-            //main menu save/load wnd   clicking on savegame lines
-          if (pGUIWindow_CurrentMenu->receives_keyboard_input_2 == WINDOW_INPUT_IN_PROGRESS)
-            pKeyActionMap->SetWindowInputStatus(WINDOW_INPUT_NONE);
-          if ( pCurrentScreen != SCREEN_SAVEGAME || uLoadGameUI_SelectedSlot != pParam + pSaveListPosition )
-          {
-            //load clicked line
-              v26 = pParam + pSaveListPosition;
-              if ( dword_6BE138 == pParam + pSaveListPosition )
-              {
-                pMessageQueue_50CBD0->AddGUIMessage(UIMSG_SaveLoadBtn, 0, 0);
-                pMessageQueue_50CBD0->AddGUIMessage(UIMSG_LoadGame, 0, 0);
-              }
-              uLoadGameUI_SelectedSlot = v26;
-              dword_6BE138 = v26;
-          }
-          else
-          {
-            //typing in the line
-              pKeyActionMap->EnterText(0, 19, pGUIWindow_CurrentMenu);
-              strcpy(pKeyActionMap->pPressedKeysBuffer, pSavegameHeader[uLoadGameUI_SelectedSlot].pName);
-              pKeyActionMap->uNumKeysPressed = strlen(pKeyActionMap->pPressedKeysBuffer);
-          }
-          break;
-        case UIMSG_SaveLoadBtn:
-          GUIWindow::Create(pGUIWindow_CurrentMenu->uFrameX + 241, pGUIWindow_CurrentMenu->uFrameY + 302, 61, 28, WINDOW_SaveLoadBtn, (int)pBtnLoadSlot, 0);
-          break;
-        case UIMSG_DownArrow:
-          ++pSaveListPosition;
-          if ( pSaveListPosition >= pParam )
-            pSaveListPosition = pParam - 1;
-          if ( pSaveListPosition < 1 )
-            pSaveListPosition = 0;
-          pWindow = pGUIWindow_CurrentMenu;
-          GUIWindow::Create(pWindow->uFrameX + 215, pGUIWindow_CurrentMenu->uFrameY + 323, 0, 0, WINDOW_PressedButton2, (int)pBtnDownArrow, 0);
-          break;
-        case UIMSG_Cancel:
-          GUIWindow::Create(pGUIWindow_CurrentMenu->uFrameX + 350, pGUIWindow_CurrentMenu->uFrameY + 302, 61, 28, WINDOW_LoadGame_CancelBtn, (int)pBtnCancel, 0);
-          break;
-        case UIMSG_ArrowUp:
-          --pSaveListPosition;
-          if ( pSaveListPosition < 0 )
-            pSaveListPosition = 0;
-          pWindow = pGUIWindow_CurrentMenu;
-          GUIWindow::Create(pWindow->uFrameX + 215, pGUIWindow_CurrentMenu->uFrameY + 197, 0, 0, WINDOW_PressedButton2, (int)pBtnArrowUp, 0);
-          break;
-        case UIMSG_AD:
-          GUIWindow::Create(pMainMenu_BtnNew->uX, pMainMenu_BtnNew->uY, 0, 0, WINDOW_PressedButton2, (int)pMainMenu_BtnNew, 0);
-          SetCurrentMenuID(MENU_LoadingProcInMainMenu);
-          break;
-        case UIMSG_AE:
-          GUIWindow::Create(pMainMenu_BtnExit->uX, pMainMenu_BtnExit->uY, 0, 0, WINDOW_PressedButton2, (int)pMainMenu_BtnExit, 0);
-          SetCurrentMenuID(MENU_DebugBLVLevel);
-          break;
-        case UIMSG_Escape:
-          if ( pModalWindow )
-          {
-            ModalWindow_Release();
-            break;
-          }
-          if ( !(dword_6BE364_game_settings_1 & GAME_SETTINGS_4000))
-            break;
-          v15 = 1;
-          pMediaPlayer->bStopBeforeSchedule = 1;
-          viewparams->bRedrawGameUI = 1;
-          viewparams->field_48 = 1;
-          if ( GetCurrentMenuID() == MENU_MAIN || GetCurrentMenuID() == MENU_MMT_MAIN_MENU
-			 || GetCurrentMenuID() == MENU_CREATEPARTY || GetCurrentMenuID() == MENU_NAMEPANELESC )
-          {
-            //if ( pCurrentScreen == SCREEN_VIDEO )
-              //pVideoPlayer->FastForwardToFrame(pVideoPlayer->pResetflag);			  
-            if (GetCurrentMenuID() == MENU_NAMEPANELESC)  //èç ïàíåëè èçìåíåíèÿ èìåíè
-            {
-              SetCurrentMenuID(MENU_CREATEPARTY);//â îêíî ñîçäàíèÿ ãðóïïû
-              break;
-            }
-            if (GetCurrentMenuID() == MENU_CREDITSPROC)	//èç îêíà Ñîçäàòåëè
-            {
-              SetCurrentMenuID(MENU_CREDITSCLOSE);//â çàêðûòèå Ñîçäàòåëè
-              break;
-            }
-            pMessageQueue_50CBD0->AddGUIMessage(UIMSG_ChangeGameState, 0, 0);
-            break;
-          }
-          if ( GetCurrentMenuID() == MENU_CREDITSPROC && !pCurrentScreen )
-          {
-            //if ( pCurrentScreen == SCREEN_VIDEO )
-              //pVideoPlayer->FastForwardToFrame(pVideoPlayer->pResetflag);
-            if (GetCurrentMenuID() == MENU_NAMEPANELESC)
-            {
-              SetCurrentMenuID(MENU_CREATEPARTY);
-              break;
-            }
-            if (GetCurrentMenuID() == MENU_CREDITSPROC)
-            {
-              SetCurrentMenuID(MENU_CREDITSCLOSE);
-              break;
-            }
-            pMessageQueue_50CBD0->AddGUIMessage(UIMSG_ChangeGameState, 0, 0);
-            break;
-          }
-          if ( pCurrentScreen == SCREEN_LOADGAME )
-          {
-            pIcons_LOD->RemoveTexturesPackFromTextureList();
-            //crt_deconstruct_ptr_6A0118();
-            pTexture_PCX.Release();
-            pTexture_PCX.Load("title.pcx", 0);
-            SetCurrentMenuID(MENU_MAIN);
-            v15 = 1;
-            pGUIWindow_CurrentMenu->Release();
-            pGUIWindow2->Release();
-            pGUIWindow2 = 0;
-            pEventTimer->Resume();
-            pCurrentScreen = SCREEN_GAME;
-            viewparams->bRedrawGameUI = v15;
-            break;
-          }
-          if ( pCurrentScreen == SCREEN_VIDEO )
-          {
-            //pVideoPlayer->Unload();
-          }
-          else
-          {
-            if ( pCurrentScreen != SCREEN_1B )
-            {
-              pGUIWindow_CurrentMenu->Release();
-              pGUIWindow2->Release();
-              pGUIWindow2 = 0;
-              pEventTimer->Resume();
-              pCurrentScreen = SCREEN_GAME;
-              viewparams->bRedrawGameUI = v15;
-              break;
-            }
-            //VideoPlayer::dtor();
-          }
-          break;
-        default:
-          break;
-      }
-    }
-    while ( pMessageQueue_50CBD0->uNumMessages );
-  }
-}
-
-
-
-//----- (0042FBDD) --------------------------------------------------------
-void  sub_42FBDD()
-{
-  pAudioPlayer->PlaySound(SOUND_StartMainChoice02, 0, 0, -1, 0, 0, 0, 0);
-  pRenderer->DrawTextureIndexedAlpha(pBtn_YES->uX, pBtn_YES->uY, pBtn_YES->pTextures[0]);
-  pRenderer->Present();
-}
-
-//----- (0042FC15) --------------------------------------------------------
-void  CloseWindowBackground()
-{
-  pAudioPlayer->PlaySound(SOUND_StartMainChoice02, -2, 0, -1, 0, 0, 0, 0);
-  pRenderer->DrawTextureIndexedAlpha(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, pBtn_ExitCancel->pTextures[0]);
-  pRenderer->Present();
-}
-
-
-//----- (0046BDC0) --------------------------------------------------------
-void  UpdateUserInput_and_MapSpecificStuff()
-{
-	if (dword_6BE364_game_settings_1 & GAME_SETTINGS_0080_SKIP_USER_INPUT_THIS_FRAME)
-	{
-		dword_6BE364_game_settings_1 &= ~GAME_SETTINGS_0080_SKIP_USER_INPUT_THIS_FRAME;
-		return;
-	}
-
-	if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
-		BLV_UpdateUserInputAndOther();
-	else if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
-		ODM_UpdateUserInputAndOther();
-
-	area_of_effect__damage_evaluate();
-}
-
-//----- (004646F0) --------------------------------------------------------
-void PrepareWorld(unsigned int _0_box_loading_1_fullscreen)
-{
-	//if ( pRenderer->pRenderD3D )
-	pGame->pVisInstance->_4C1A02();
-	pEventTimer->Pause();
-	pMiscTimer->Pause();
-	pParty->uFlags = 2;
-	CastSpellInfoHelpers::_427D48();
-	ResetCursor_Palettes_LODs_Level_Audio_SFT_Windows();
-	DoPrepareWorld(0, (_0_box_loading_1_fullscreen == 0) + 1);
-	pMiscTimer->Resume();
-	pEventTimer->Resume();
-}
-
-//----- (00464866) --------------------------------------------------------
-void DoPrepareWorld(unsigned int bLoading, int _1_fullscreen_loading_2_box)
-{
-	char *v3; // eax@1
-	unsigned int v5; // eax@3
-	char Str1[20]; // [sp+Ch] [bp-18h]@1
-	unsigned int v9; // [sp+20h] [bp-4h]@1
-
-	v9 = bLoading;
-	ResetCursor_Palettes_LODs_Level_Audio_SFT_Windows();
-	pDecalBuilder->Reset(0);
-	pGameLoadingUI_ProgressBar->Initialize(_1_fullscreen_loading_2_box == 1 ? GUIProgressBar::TYPE_Fullscreen :
-		GUIProgressBar::TYPE_Box);
-	strcpy(Str1, pCurrentMapName);
-	v3 = strtok(Str1, ".");
-	strcpy(Str1, v3);
-	Level_LoadEvtAndStr(Str1);
-	LoadLevel_InitializeLevelEvt();
-	strcpy(Str1, pCurrentMapName);
-	_strrev(Str1);
-	strtok(Str1, ".");
-	_strrev(Str1);
-
-	for (uint i = 0; i < 1000; ++i)
-		pSpriteObjects[i].uObjectDescID = 0;
-
-	v5 = pMapStats->GetMapInfo(pCurrentMapName);
-	bUnderwater = false;
-	uLevelMapStatsID = v5;
-	pGame->uFlags2 &= 0xFFFFFFF7u;
-	if (!_stricmp(pCurrentMapName, "out15.odm"))
-	{
-		bUnderwater = true;
-		pGame->uFlags2 |= GAME_FLAGS_2_ALTER_GRAVITY;
-	}
-	pParty->floor_face_pid = 0;
-	if (_stricmp(Str1, "blv"))
-		PrepareToLoadODM(v9, 0);
-	else
-		PrepareToLoadBLV(v9);
-	pAudioPlayer->SetMapEAX();
-	_461103_load_level_sub();
-	if (!_stricmp(pCurrentMapName, "d11.blv") || !_stricmp(pCurrentMapName, "d10.blv"))
-	{
-		//spawning grounds & walls of mist - no loot & exp from monsters
-
-		for (uint i = 0; i < uNumActors; ++i)
-		{
-			pActors[i].pMonsterInfo.uTreasureType = 0;
-			pActors[i].pMonsterInfo.uTreasureDiceRolls = 0;
-			pActors[i].pMonsterInfo.uExp = 0;
-		}
-	}
-	bDialogueUI_InitializeActor_NPC_ID = 0;
-	OnMapLoad();
-	pGameLoadingUI_ProgressBar->Progress();
-	memset(&pRenderer->pBillboardRenderListD3D, 0, sizeof(pRenderer->pBillboardRenderListD3D));
-	pGameLoadingUI_ProgressBar->Release();
-	_flushall();
-}
-
-void IntegrityTest()
-{
-	static_assert(sizeof(MovieHeader) == 44, "Wrong type size");
-	static_assert(sizeof(SoundDesc_mm6) == 112, "Wrong type size");
-	static_assert(sizeof(SoundDesc) == 120, "Wrong type size");
-	static_assert(sizeof(OverlayDesc) == 8, "Wrong type size");
-	static_assert(sizeof(ChestDesc) == 36, "Wrong type size");
-	static_assert(sizeof(ObjectDesc_mm6) == 52, "Wrong type size");
-	static_assert(sizeof(ObjectDesc) == 56, "Wrong type size");
-	static_assert(sizeof(DecorationDesc) == 84, "Wrong type size");
-	static_assert(sizeof(IconFrame) == 32, "Wrong type size");
-	static_assert(sizeof(PlayerFrame) == 10, "Wrong type size");
-	static_assert(sizeof(TextureFrame) == 20, "Wrong type size");
-	static_assert(sizeof(SpriteFrame) == 60, "Wrong type size");
-	static_assert(sizeof(RenderVertexSoft) == 0x30, "Wrong type size");
-	static_assert(sizeof(RenderBillboard) == 0x34, "Wrong type size");
-	static_assert(sizeof(Texture) == 0x48, "Wrong type size");
-	//static_assert(sizeof(RGBTexture) == 0x28, "Wrong type size");
-	//static_assert(sizeof(LODFile_IconsBitmaps) == 0x11BB8 + 4, "Wrong type size"); // + virtual dtor ptr
-	static_assert(sizeof(AudioPlayer) == 0xC84, "Wrong type size");
-	static_assert(sizeof(SoundDesc) == 0x78, "Wrong type size");
-	static_assert(sizeof(stru339_spell_sound) == 0xAFD8, "Wrong type size");
-	//static_assert(sizeof(VideoPlayer) == 0x108 + 4, "Wrong type size");
-	static_assert(sizeof(MovieHeader) == 0x2C, "Wrong type size");
-	static_assert(sizeof(DecorationDesc) == 0x54, "Wrong type size");
-	static_assert(sizeof(ObjectDesc) == 0x38, "Wrong type size");
-	static_assert(sizeof(OverlayDesc) == 0x8, "Wrong type size");
-	static_assert(sizeof(ChestDesc) == 0x24, "Wrong type size");
-	static_assert(sizeof(TileDesc) == 0x1A, "Wrong type size");
-	static_assert(sizeof(MonsterDesc_mm6) == 148, "Wrong type size");
-	static_assert(sizeof(MonsterDesc) == 152, "Wrong type size");
-	static_assert(sizeof(Timer) == 0x28, "Wrong type size");
-	static_assert(sizeof(OtherOverlay) == 0x14, "Wrong type size");
-	static_assert(sizeof(ItemGen) == 0x24, "Wrong type size");
-	static_assert(sizeof(SpriteObject) == 0x70, "Wrong type size");
-	static_assert(sizeof(ItemDesc) == 0x30, "Wrong type size");
-	static_assert(sizeof(ItemsTable) == 0x117A0, "Wrong type size");
-	static_assert(sizeof(Chest) == 0x14CC, "Wrong type size");
-	static_assert(sizeof(MapInfo) == 0x44, "Wrong type size");
-	static_assert(sizeof(SpellInfo) == 0x24, "Wrong type size");
-	static_assert(sizeof(SpellData) == 0x14, "Wrong type size");
-	static_assert(sizeof(SpellBuff) == 0x10, "Wrong type size");
-	static_assert(sizeof(AIDirection) == 0x1C, "Wrong type size");
-	static_assert(sizeof(ActorJob) == 0xC, "Wrong type size");
-	static_assert(sizeof(Actor) == 0x344, "Wrong type size");
-	static_assert(sizeof(LevelDecoration) == 0x20, "Wrong type size");
-	static_assert(sizeof(KeyboardActionMapping) == 0x20C, "Wrong type size");
-	static_assert(sizeof(UIAnimation) == 0xD, "Wrong type size");
-	static_assert(sizeof(SpawnPointMM7) == 0x18, "Wrong type size");
-	static_assert(sizeof(ODMFace) == 0x134, "Wrong type size");
-	static_assert(sizeof(BSPNode) == 0x8, "Wrong type size");
-	static_assert(sizeof(BSPModel) == 0xBC, "Wrong type size");
-	static_assert(sizeof(OutdoorLocation) == 0x1C28C, "Wrong type size");
-	static_assert(sizeof(BLVFace) == 0x60, "Wrong type size");
-	static_assert(sizeof(BLVFaceExtra) == 0x24, "Wrong type size");
-	static_assert(sizeof(BLVSector) == 0x74, "Wrong type size");
-	static_assert(sizeof(BLVLightMM7) == 0x10, "Wrong type size");
-	static_assert(sizeof(BLVDoor) == 0x50, "Wrong type size");
-	static_assert(sizeof(IndoorLocation) == 0x690, "Wrong type size");
-	//static_assert(sizeof(ODMRenderParams) == 0x74, "Wrong type size");
-	static_assert(sizeof(Mouse) == 0x114, "Wrong type size");
-	static_assert(sizeof(Particle_sw) == 0x68, "Wrong type size");
-	static_assert(sizeof(Particle) == 0x68, "Wrong type size");
-	static_assert(sizeof(ParticleEngine) == 0xE430, "Wrong type size");
-	static_assert(sizeof(Lightmap) == 0xC1C, "Wrong type size");
-	static_assert(sizeof(LightmapBuilder) == 0x3CBC38, "Wrong type size");
-	static_assert(sizeof(Vis_SelectionList) == 0x2008, "Wrong type size");
-	static_assert(sizeof(Vis) == 0x20D0, "Wrong type size");
-	static_assert(sizeof(PlayerBuffAnim) == 0x10, "Wrong type size");
-	static_assert(sizeof(ProjectileAnim) == 0x1C, "Wrong type size");
-	static_assert(sizeof(stru6) == 0x5F8, "Wrong type size");
-	static_assert(sizeof(IndoorCameraD3D_Vec3) == 0x10, "Wrong type size");
-	static_assert(sizeof(IndoorCameraD3D_Vec4) == 0x18, "Wrong type size"); //should be 14 (10 vec3 + 4 vdtor)  but 18 coz of his +4 from own vdtor, but it is odd since vdtor already present from vec3
-	//static_assert(sizeof(IndoorCameraD3D) == 0x1A1384, "Wrong type size");
-	static_assert(sizeof(StationaryLight) == 0xC, "Wrong type size");
-	static_assert(sizeof(LightsStack_StationaryLight_) == 0x12C8, "Wrong type size");
-	static_assert(sizeof(MobileLight) == 0x12, "Wrong type size");
-	static_assert(sizeof(LightsStack_MobileLight_) == 0x1C28, "Wrong type size");
-	static_assert(sizeof(Game) == 0xE78, "Wrong type size");
-	static_assert(sizeof(stru141_actor_collision_object) == 0xA8, "Wrong type size");
-	static_assert(sizeof(ActionQueue) == 0x7C, "Wrong type size");
-	static_assert(sizeof(NPCData) == 0x4C, "Wrong type size");
-	static_assert(sizeof(NPCStats) == 0x17FFC, "Wrong type size");
-	static_assert(sizeof(BspRenderer) == 0x53740, "Wrong type size");
-	static_assert(sizeof(PaletteManager) == 0x267AF0, "Wrong type size");
-	static_assert(sizeof(ViewingParams) == 0x26C, "Wrong type size");
-	//static_assert(sizeof(IndoorCamera) == 0x50, "Wrong type size");
-	static_assert(sizeof(Bloodsplat) == 0x28, "Wrong type size");
-	static_assert(sizeof(BloodsplatContainer) == 0xA0C, "Wrong type size");
-	static_assert(sizeof(TrailParticle) == 0x18, "Wrong type size");
-	static_assert(sizeof(EventIndex) == 0xC, "Wrong type size");
-	static_assert(sizeof(_2devent) == 0x34, "Wrong type size");
-	static_assert(sizeof(MapsLongTimer) == 0x20, "Wrong type size");
-	static_assert(sizeof(SavegameHeader) == 0x64, "Wrong type size");
-	static_assert(sizeof(SavegameList) == 0x3138, "Wrong type size");
-	static_assert(sizeof(StorylineText) == 0x160, "Wrong type size");
-	static_assert(sizeof(FactionTable) == 0x1EF1, "Wrong type size");
-	static_assert(sizeof(Decal) == 0xC20, "Wrong type size");
-	static_assert(sizeof(DecalBuilder) == 0x30C038, "Wrong type size");
-	static_assert(sizeof(MonsterInfo) == 0x58, "Wrong type size");
-	static_assert(sizeof(MonsterStats) == 0x5BA0, "Wrong type size");
-	static_assert(sizeof(RenderD3D) == 0x148, "Wrong type size");
-	//  static_assert(sizeof(Render) == 0x129844, "Wrong type size");
-	static_assert(sizeof(Player) == 0x1B3C, "Wrong type size");
-	static_assert(sizeof(PartyTimeStruct) == 0x678, "Wrong type size");
-	static_assert(sizeof(Party) == 0x16238, "Wrong type size");
-	static_assert(sizeof(GUIButton) == 0xBC, "Wrong type size");
-	static_assert(sizeof(GUIWindow) == 0x54, "Wrong type size");
-	//static_assert(sizeof(GUIProgressBar) == 0x1B8, "Wrong type size");
-	static_assert(sizeof(GUIFont) == 0x1020, "Wrong type size");
-	// static_assert(sizeof(stru262_TurnBased) == 0x40, "Wrong type size");
-	//static_assert(sizeof(ArcomageGame) == 0xFB, "Wrong type size");
-	static_assert(sizeof(CastSpellInfo) == 0x14, "Wrong type size");
-	static_assert(sizeof(ArcomageCard) == 0x6C, "Wrong type size");
-	static_assert(sizeof(stru320) == 0x3FC, "Wrong type size");
-	static_assert(sizeof(TravelInfo) == 0x20, "Wrong type size");
-	static_assert(sizeof(stru336) == 0x798, "Wrong type size");
-	static_assert(sizeof(Vec3_short_) == 6, "Wrong type size");
-	static_assert(sizeof(BLVFace) == 96, "Wrong type size");
-	static_assert(sizeof(BLVFaceExtra) == 36, "Wrong type size");
-	static_assert(sizeof(BLVSector) == 116, "Wrong type size");
-	static_assert(sizeof(LevelDecoration) == 32, "Wrong type size");
-	static_assert(sizeof(BLVLightMM7) == 16, "Wrong type size");
-	static_assert(sizeof(BSPNode) == 8, "Wrong type size");
-	static_assert(sizeof(SpawnPointMM7) == 24, "Wrong type size");
-	static_assert(sizeof(DDM_DLV_Header) == 40, "Wrong type size");
-	static_assert(sizeof(Actor) == 836, "Wrong type size");
-	static_assert(sizeof(SpriteObject) == 112, "Wrong type size");
-	static_assert(sizeof(Chest) == 5324, "Wrong type size");
-	static_assert(sizeof(stru123) == 0xC8, "Wrong type size");
-	static_assert(sizeof(BLVMapOutline) == 12, "Wrong type size");
-	static_assert(sizeof(LODSprite) == 0x28, "Wrong type size");
-}
-
-
-//----- (00464761) --------------------------------------------------------
-void Game_DeinitializeAndTerminate(int exitCode)
-{
-	SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
-	ResetCursor_Palettes_LODs_Level_Audio_SFT_Windows();
-	pGame->Deinitialize();
-	pRenderer->Release();
-	delete window;
-	//if ( !DestroyWindow(hWnd) )
-	//  GetLastError();
-	exit(exitCode);
-}
-
-//----- (004647AB) --------------------------------------------------------
-void FinalInitialization()
-{
-	pViewport->SetScreen(viewparams->uSomeX, viewparams->uSomeY, viewparams->uSomeZ, viewparams->uSomeW);
-	pViewport->SetFOV(flt_6BE3A0 * 65536.0f);
-
-	//pIndoorCamera = new IndoorCamera;
-	//pIndoorCamera->Initialize(65, viewparams->uScreen_BttmR_X - viewparams->uScreen_topL_X + 1,
-	//                              viewparams->uScreen_BttmR_Y - viewparams->uScreen_topL_Y + 1);
-
-	InitializeTurnBasedAnimations(&stru_50C198);
-	pBitmaps_LOD->_inlined_sub1();
-	pSprites_LOD->_inlined_sub1();
-	pIcons_LOD->_inlined_sub1();
-}
-// 6BE3A0: using guessed type float flt_6BE3A0;
-
-
-
-//----- (00464E17) --------------------------------------------------------
-bool __fastcall CheckMM7CD(char c)
-{
-	char DstBuf[256] = { 0 };
-	char strCommand[256] = { 0 }; // [sp+10Ch] [bp-118h]@1
-	char Filename[20] = { 0 }; // [sp+20Ch] [bp-18h]@1
-
-	wchar_t pMagicPath[1024];
-	swprintf(pMagicPath, wcslen(L"%C:\\anims\\magic7.vid"), L"%C:\\anims\\magic7.vid", c);
-	if (GetFileAttributesW(pMagicPath) == -1)
-		return false;
-
-	//Open CD audio
-	wsprintfA(strCommand, "open %c: type cdaudio alias CD", c);
-    if (!mciSendStringA(strCommand, DstBuf, 255, 0))
-    {
-      wsprintfA(strCommand, "info CD UPC wait");
-      mciSendStringA(strCommand, DstBuf, 255, 0);
-      wsprintfA(strCommand, "close CD");
-      mciSendStringA(strCommand, DstBuf, 255, 0);
-    }
-
-	memcpy(Filename, "X:\\anims\\magic7.vid", sizeof(Filename));
-	*Filename = c;
-
-	FILE* f = fopen(Filename, "rb");
-	if (!f)
-		return false;
-
-	if (!fseek(f, 0, SEEK_END))
-	{
-		if (!fseek(f, -100, SEEK_CUR))
-			fread(DstBuf, 1, 0x64u, f);
-
-		fclose(f);
-		return true;
-	}
-	fclose(f);
-	return false;
-}
-
-//----- (00464F1B) --------------------------------------------------------
-signed int __stdcall InsertMM7CDDialogFunc(HWND hDlg, int a2, __int16 a3, int a4)
-{
-	char v4; // zf@3
-	int v6; // eax@10
-	int v7; // eax@11
-	int v8; // eax@12
-	int v9; // eax@13
-	BOOL(__stdcall *v10)(HWND, int, LPCSTR); // edi@15
-	const CHAR *v11; // [sp-Ch] [bp-Ch]@15
-	INT_PTR v12; // [sp-4h] [bp-4h]@5
-
-	if (a2 == 272)
-	{
-		hInsertCDWindow = hDlg;
-		v6 = (GetUserDefaultLangID() & 0x3FF) - 7;
-		if (v6)
-		{
-			v7 = v6 - 3;
-			if (v7)
-			{
-				v8 = v7 - 2;
-				if (v8)
-				{
-					v9 = v8 - 4;
-					if (v9)
-					{
-						if (v9 != 5)
-							return 0;
-						SetWindowTextA(hDlg, "Wloz CD-ROM numer 2");
-						v10 = SetDlgItemTextA;
-						SetDlgItemTextA(hDlg, 1010, "Wloz CD-ROM numer 2 Might and Magic® VII.");
-						v11 = "Odwolaj";
-					}
-					else
-					{
-						SetWindowTextA(hDlg, "Inserire il secondo CD");
-						v10 = SetDlgItemTextA;
-						SetDlgItemTextA(hDlg, 1010, "Inserire il secondo CD di Might and Magic® VII.");
-						v11 = "Annulla";
-					}
-				}
-				else
-				{
-					SetWindowTextA(hDlg, "Insérez le CD 2");
-					v10 = SetDlgItemTextA;
-					SetDlgItemTextA(hDlg, 1010, "Insérez Might & Magic® VII CD 2.");
-					v11 = "Supprimer";
-				}
-			}
-			else
-			{
-				SetWindowTextA(hDlg, "Por favor, inserte disco 2");
-				v10 = SetDlgItemTextA;
-				SetDlgItemTextA(hDlg, 1010, "Por favor, inserte disco 2 de Might & Magic® VII.");
-				v11 = "Cancelar";
-			}
-		}
-		else
-		{
-			SetWindowTextA(hDlg, "Bitte CD 2 einlegen");
-			v10 = SetDlgItemTextA;
-			SetDlgItemTextA(hDlg, 1010, "Bitte CD 2 von Might and Magic® VII einlegen.");
-			v11 = "Abbrechen";
-		}
-		v10(hDlg, 2, v11);
-		return 0;
-	}
-	if (a2 == 273)
-	{
-		if (a3 == 2)
-		{
-			v12 = 0;
-			EndDialog(hDlg, v12);
-			return 1;
-		}
-		v4 = a3 == 1;
-	}
-	else
-	{
-		v4 = a2 == 1025;
-	}
-	if (v4)
-	{
-		v12 = 1;
-		EndDialog(hDlg, v12);
-		return 1;
-	}
-	return 0;
-}
-
-//----- (00465061) --------------------------------------------------------
-bool __fastcall FindMM7CD(HWND hWnd, char *pCDDrive)
-{
-	char drive[4] = { 'X', ':', '\\', 0 };
-
-	bool bGotCDFromRegistry = false;
-
-	HKEY hSoftware = nullptr,
-		hNWC = nullptr,
-		hMM7 = nullptr,
-		hVersion = nullptr;
-	if (!RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, KEY_READ|KEY_WOW64_32KEY, &hSoftware))
-	{
-		if (!RegOpenKeyExA(hSoftware, "New World Computing", 0, KEY_READ|KEY_WOW64_32KEY, &hNWC))
-		{
-			if (!RegOpenKeyExA(hNWC, "Might and Magic VII", 0, KEY_READ|KEY_WOW64_32KEY, &hMM7))
-			{
-				if (!RegOpenKeyExA(hMM7, "1.0", 0, KEY_READ|KEY_WOW64_32KEY, &hVersion))
-				{
-					DWORD cbData = 3;
-					if (!RegQueryValueExA(hVersion, "CDDrive", 0, 0, (BYTE *)drive, &cbData))
-						bGotCDFromRegistry = true;
-				}
-				RegCloseKey(hVersion);
-			}
-			RegCloseKey(hMM7);
-		}
-		RegCloseKey(hNWC);
-	}
-	RegCloseKey(hSoftware);
-
-	if (bGotCDFromRegistry)
-	if (CheckMM7CD(*drive))
-	{
-		cMM7GameCDDriveLetter = *drive;
-		return true;
-	}
-
-	while (true)
-	{
-		for (uint i = 0; i < 26; ++i)
-		{
-			drive[0] = 'A' + i;
-
-			if (GetDriveTypeA(drive) == DRIVE_CDROM)
-			if (CheckMM7CD(*drive))
-			{
-				cMM7GameCDDriveLetter = *drive;
-				WriteWindowsRegistryString("CDDrive", drive);
-				return true;
-			}
-		}
-
-		if (DialogBoxParamA(GetModuleHandleW(nullptr), "InsertCD", hWnd, (DLGPROC)InsertMM7CDDialogFunc, 0))
-			continue;
-		return false;
-	}
-}
-
-//----- (004651F4) --------------------------------------------------------
-bool MM7_Initialize(int game_width, int game_height)
-{
-	wchar_t pCurrentDir[1024];
-	_wgetcwd(pCurrentDir, 1024);
-
-	wchar_t pMM6IniFile[1024];
-	wsprintfW(pMM6IniFile, L"%s\\mm6.ini", pCurrentDir);
-
-	bCanLoadFromCD = GetPrivateProfileIntW(L"settings", L"use_cd", 1, pMM6IniFile);
-	if (bNoCD)
-		bCanLoadFromCD = false;
-	if (bCanLoadFromCD)
-	{
-		Log::Warning(L"Checking for CD...");
-		if (!FindMM7CD(nullptr, &cMM7GameCDDriveLetter))
-			return false;
-		Log::Warning(L"...done.");
-	}
-
-
-	srand(GetTickCount());
-
-	pEventTimer = Timer::Create();
-	pEventTimer->Initialize();
-	window = OSWindow::Create(L"Might and Magic® Trilogy", game_width, game_height);//Create  game window
-
-	bool use_d3d11 = false;
-	if (use_d3d11)
-		pRenderer = RenderD3D11::Create();
-	else
-		pRenderer = Render::Create();//Create DirectX
-	if (!pRenderer)
-	{
-		Log::Warning(L"Render creation failed");
-		return false;
-	}
-	else
-	{
-		//bool bWindowMode = ReadWindowsRegistryInt("startinwindow", false);
-		//uint uDefaultDevice = ReadWindowsRegistryInt("D3D Device", 1);
-
-		if (!pRenderer->Initialize(window/*, bColoredLights, uLevelOfDetail, bTinting*/))
-		{
-			Log::Warning(L"Render failed to initialize");
-			return false;
-		}
-	}
-
-	game_starting_year = 1168;
-
-	pParty = new Party;
-	memset(&pParty->pHirelings, 0, sizeof(pParty->pHirelings));
-	pParty->uWalkSpeed = GetPrivateProfileIntW(L"debug", L"walkspeed", 384, pMM6IniFile);
-	pParty->uDefaultEyelevel = GetPrivateProfileIntW(L"party", L"eyelevel", 160, pMM6IniFile);
-	pParty->sEyelevel = pParty->uDefaultEyelevel;
-	pParty->uDefaultPartyHeight = GetPrivateProfileIntW(L"party", L"height", 192, pMM6IniFile);
-	pParty->uPartyHeight = pParty->uDefaultPartyHeight;
-
-	MM6_Initialize(pMM6IniFile);
-
-	pKeyActionMap = new KeyboardActionMapping;
-
-	OnTimer(1);
-	GameUI_StatusBar_UpdateTimedString(1);
-	pGame = Game::Create();
-	pMouse = pGame->pMouseInstance;
-
-
-	pIcons_LOD = new LODFile_IconsBitmaps;
-	if (!pIcons_LOD->Load("data\\icons.lod", "icons"))
-	{
-		MessageBoxW(nullptr, L"Some files are missing\n\nPlease Reinstall.",
-			L"Files Missing", MB_ICONEXCLAMATION);
-		return false;
-	}
-	pIcons_LOD->dword_011BA4 = 0;
-
-	pEvents_LOD = new LODFile_IconsBitmaps;
-	if (!pEvents_LOD->Load("data\\events.lod", "icons"))
-	{
-		MessageBoxW(nullptr, L"Some files are missing\n\nPlease Reinstall.",
-			L"Files Missing", MB_ICONEXCLAMATION);
-		return false;
-	}
-
-	InitializeGameText();
-
-	pBitmaps_LOD = new LODFile_IconsBitmaps;
-	if (!pBitmaps_LOD->Load("data\\bitmaps.lod", "bitmaps"))
-	{
-		MessageBoxA(nullptr, pGlobalTXT_LocalizationStrings[63],
-			pGlobalTXT_LocalizationStrings[184], MB_ICONEXCLAMATION);
-		return false;
-	}
-
-	pSprites_LOD = new LODFile_Sprites;
-	if (!pSprites_LOD->LoadSprites("data\\sprites.lod"))
-	{
-		MessageBoxA(nullptr,
-			pGlobalTXT_LocalizationStrings[63],
-			pGlobalTXT_LocalizationStrings[184], MB_ICONEXCLAMATION);
-		return false;
-	}
-
-
-#if 0
-	if (_access("../MM_VI/data/icons.lod", 0) == 0)
-	{
-		pIcons_LOD_mm6 = new LODFile_IconsBitmaps;
-		if (!pIcons_LOD_mm6->Load("../MM_VI/data/icons.lod", "icons"))
-		{
-			delete pIcons_LOD_mm6;
-			pIcons_LOD_mm6 = nullptr;
-			Log::Warning(L"Unable to load mm6:icons.lod");
-		}
-	}
-	else
-		Log::Warning(L"Unable to find mm6:icons.lod");
-
-	if (_access("../MM_VI/data/bitmaps.lod", 0) == 0)
-	{
-		pBitmaps_LOD_mm6 = new LODFile_IconsBitmaps;
-		if (!pBitmaps_LOD_mm6->Load("../MM_VI/data/bitmaps.lod", "bitmaps"))
-		{
-			delete pBitmaps_LOD_mm6;
-			pBitmaps_LOD_mm6 = nullptr;
-			Log::Warning(L"Unable to load mm6:bitmaps.lod");
-		}
-	}
-	else
-		Log::Warning(L"Unable to find mm6:bitmaps.lod");
-
-	auto mm6_sprite_container_name = bUseLoResSprites ? "../MM_VI/data/spriteLO.lod"
-		: "../MM_VI/data/sprites.lod";
-	if (_access(mm6_sprite_container_name, 0) == 0)
-	{
-		pSprites_LOD_mm6 = new LODFile_Sprites;
-		if (!pSprites_LOD_mm6->LoadSprites(mm6_sprite_container_name))
-		{
-			delete pSprites_LOD_mm6;
-			pSprites_LOD_mm6 = nullptr;
-			Log::Warning(L"Unable to load mm6:sprites.lod");
-		}
-	}
-	else
-		Log::Warning(L"Unable to find mm6:sprites.lod");
-
-
-	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;
-		void *sft_mm7 = pEvents_LOD->LoadRaw("dsft.bin", 1);
-		pSpriteFrameTable = new SpriteFrameTable;
-		pSpriteFrameTable->FromFile(sft_mm6, sft_mm7, sft_mm8);
-		free(sft_mm6);
-		free(sft_mm7);
-		free(sft_mm8);
-
-		void *tft_mm6 = pIcons_LOD_mm6 ? pIcons_LOD_mm6->LoadRaw("dtft.bin", 1) : nullptr,
-			*tft_mm8 = nullptr;
-		void *tft_mm7 = pEvents_LOD->LoadRaw("dtft.bin", 1);
-		pTextureFrameTable = new TextureFrameTable;
-		pTextureFrameTable->FromFile(tft_mm6, tft_mm7, tft_mm8);
-		free(tft_mm6);
-		free(tft_mm7);
-		free(tft_mm8);
-
-		void *tiles_mm6 = pIcons_LOD_mm6 ? pIcons_LOD_mm6->LoadRaw("dtile.bin", 1) : nullptr,
-			*tiles_mm8 = nullptr;
-		void *tiles_mm7 = pEvents_LOD->LoadRaw("dtile.bin", 1);
-		pTileTable = new TileTable;
-		pTileTable->FromFile(tiles_mm6, tiles_mm7, tiles_mm8);
-		free(tiles_mm6);
-		free(tiles_mm7);
-		free(tiles_mm8);
-
-		void *pft_mm6 = pIcons_LOD_mm6 ? pIcons_LOD_mm6->LoadRaw("dpft.bin", 1) : nullptr,
-			*pft_mm8 = nullptr;
-		void *pft_mm7 = pEvents_LOD->LoadRaw("dpft.bin", 1);
-		pPlayerFrameTable = new PlayerFrameTable;
-		pPlayerFrameTable->FromFile(pft_mm6, pft_mm7, pft_mm8);
-		free(pft_mm6);
-		free(pft_mm7);
-		free(pft_mm8);
-
-		void *ift_mm6 = pIcons_LOD_mm6 ? pIcons_LOD_mm6->LoadRaw("dift.bin", 1) : nullptr,
-			*ift_mm8 = nullptr;
-		void *ift_mm7 = pEvents_LOD->LoadRaw("dift.bin", 1);
-		pIconsFrameTable = new IconFrameTable;
-		pIconsFrameTable->FromFile(ift_mm6, ift_mm7, ift_mm8);
-		free(ift_mm6);
-		free(ift_mm7);
-		free(ift_mm8);
-
-		void *decs_mm6 = pIcons_LOD_mm6 ? pIcons_LOD_mm6->LoadRaw("ddeclist.bin", 1) : nullptr,
-			*decs_mm8 = nullptr;
-		void *decs_mm7 = pEvents_LOD->LoadRaw("ddeclist.bin", 1);
-		pDecorationList = new DecorationList;
-		pDecorationList->FromFile(decs_mm6, decs_mm7, decs_mm8);
-		free(decs_mm6);
-		free(decs_mm7);
-		free(decs_mm8);
-
-		void *objs_mm6 = pIcons_LOD_mm6 ? pIcons_LOD_mm6->LoadRaw("dobjlist.bin", 1) : nullptr,
-			*objs_mm8 = nullptr;
-		void *objs_mm7 = pEvents_LOD->LoadRaw("dobjlist.bin", 1);
-		pObjectList = new ObjectList;
-		pObjectList->FromFile(objs_mm6, objs_mm7, objs_mm8);
-		free(objs_mm6);
-		free(objs_mm7);
-		free(objs_mm8);
-
-		void *mons_mm6 = pIcons_LOD_mm6 ? pIcons_LOD_mm6->LoadRaw("dmonlist.bin", 1) : nullptr,
-			*mons_mm8 = nullptr;
-		void *mons_mm7 = pEvents_LOD->LoadRaw("dmonlist.bin", 1);
-		pMonsterList = new MonsterList;
-		pMonsterList->FromFile(mons_mm6, mons_mm7, mons_mm8);
-		free(mons_mm6);
-		free(mons_mm7);
-		free(mons_mm8);
-
-		void *chests_mm6 = pIcons_LOD_mm6 ? pIcons_LOD_mm6->LoadRaw("dchest.bin", 1) : nullptr,
-			*chests_mm8 = nullptr;
-		void *chests_mm7 = pEvents_LOD->LoadRaw("dchest.bin", 1);
-		pChestList = new ChestList;
-		pChestList->FromFile(chests_mm6, chests_mm7, chests_mm8);
-		free(chests_mm6);
-		free(chests_mm7);
-		free(chests_mm8);
-
-		void *overlays_mm6 = pIcons_LOD_mm6 ? pIcons_LOD_mm6->LoadRaw("doverlay.bin", 1) : nullptr,
-			*overlays_mm8 = nullptr;
-		void *overlays_mm7 = pEvents_LOD->LoadRaw("doverlay.bin", 1);
-		pOverlayList = new OverlayList;
-		pOverlayList->FromFile(overlays_mm6, overlays_mm7, overlays_mm8);
-		free(overlays_mm6);
-		free(overlays_mm7);
-		free(overlays_mm8);
-
-		void *sounds_mm6 = pIcons_LOD_mm6 ? pIcons_LOD_mm6->LoadRaw("dsounds.bin", 1) : nullptr,
-			*sounds_mm8 = nullptr;
-		void *sounds_mm7 = pEvents_LOD->LoadRaw("dsounds.bin", 1);
-		pSoundList = new SoundList;
-		pSoundList->FromFile(sounds_mm6, sounds_mm7, sounds_mm8);
-		free(sounds_mm6);
-		free(sounds_mm7);
-		free(sounds_mm8);
-	}
-
-
-
-
-	if (dword_6BE368_debug_settings_2 & DEBUG_SETTINGS_RUN_IN_WIDOW)
-	{
-		//window->SetWindowedMode(game_width, game_height);
-		pRenderer->SwitchToWindow();
-	}
-	else
-	{
-		__debugbreak(); // Nomad
-		window->SetFullscreenMode();
-		pRenderer->InitializeFullscreen();
-	}
-
-	uSoundVolumeMultiplier = min(9, ReadWindowsRegistryInt("soundflag", 9));
-	uMusicVolimeMultiplier = min(9, ReadWindowsRegistryInt("musicflag", 9));
-	uVoicesVolumeMultiplier = min(9, ReadWindowsRegistryInt("CharVoices", 9));
-	bShowDamage = ReadWindowsRegistryInt("ShowDamage", 1) != 0;
-
-	uGammaPos = min(4, ReadWindowsRegistryInt("GammaPos", 4));
-	//pGame->pGammaController->Initialize(uGammaPos * 0.1 + 0.6);
-
-	if (ReadWindowsRegistryInt("Bloodsplats", 1))
-		pGame->uFlags2 |= GAME_FLAGS_2_DRAW_BLOODSPLATS;
-	else
-		pGame->uFlags2 &= ~GAME_FLAGS_2_DRAW_BLOODSPLATS;
-
-	uTurnSpeed = ReadWindowsRegistryInt("TurnDelta", 3);
-
-	if (!bNoSound)
-		pAudioPlayer->Initialize();
-
-	pMediaPlayer = new Media::MPlayer();
-	pMediaPlayer->Initialize(window);
-
-	dword_6BE364_game_settings_1 |= GAME_SETTINGS_4000;
-
-	switch (uTurnSpeed)
-	{
-	case 0: // undefined turn option
-		__debugbreak(); // really shouldn't use this mode
-        uTurnSpeed = 64; //(unsigned int)uCPUSpeed < 199/*MHz*/ ? 128 : 64; // adjust turn speed to estimated fps
-		break;
-
-	case 1:             // 16x
-		Log::Warning(L"x16 Turn Speed"); // really shouldn't use this mode
-		uTurnSpeed = 128;
-		break;
-
-	case 2:             // 32x
-		Log::Warning(L"x32 Turn Speed"); // really shouldn't use this mode
-		uTurnSpeed = 64;
-		break;
-
-	case 3:             // smooth
-		uTurnSpeed = 0;
-		break;
-	}
-
-	return true;
-}
-
-//----- (00465D0B) --------------------------------------------------------
-void SecondaryInitialization()
-{
-	pMouse->Initialize(window);
-
-	pItemsTable = new ItemsTable;
-	pItemsTable->Initialize();
-
-	//pBitmaps_LOD->can_load_hardware_sprites = 1;
-	//pBitmaps_LOD->SetupPalettes(pRenderer->uTargetRBits, pRenderer->uTargetGBits, pRenderer->uTargetBBits);
-	pBitmaps_LOD->SetupPalettes(5, 6, 5);
-	//pIcons_LOD->SetupPalettes(pRenderer->uTargetRBits, pRenderer->uTargetGBits, pRenderer->uTargetBBits);
-	pIcons_LOD->SetupPalettes(5, 6, 5);
-	//pPaletteManager->SetColorChannelInfo(pRenderer->uTargetRBits, pRenderer->uTargetGBits, pRenderer->uTargetBBits);
-	pPaletteManager->SetColorChannelInfo(5, 6, 5);
-
-	pPaletteManager->SetMistColor(128, 128, 128);
-	pPaletteManager->RecalculateAll();
-	//pSprites_LOD->can_load_hardware_sprites = 1;
-	pObjectList->InitializeSprites();
-	pOverlayList->InitializeSprites();
-
-	if (!bNoSound)
-		pSoundList->Initialize();
-
-
-	for (uint i = 0; i < 4; ++i)
-	{
-		static const char *pUIAnimNames[4] =
-		{
-			"glow03", "glow05",
-			"torchA", "wizeyeA"
-		};
-		static unsigned short _4E98D0[4][4] =
-		{
-			{ 479, 0, 329, 0 },
-			{ 585, 0, 332, 0 },
-			{ 468, 0, 0, 0 },
-			{ 606, 0, 0, 0 }
-		};
-
-		pUIAnims[i]->uIconID = pIconsFrameTable->FindIcon(pUIAnimNames[i]);
-		pIconsFrameTable->InitializeAnimation(pUIAnims[i]->uIconID);
-
-		pUIAnims[i]->uAnimLength = 0;
-		pUIAnims[i]->uAnimTime = 0;
-		pUIAnims[i]->x = _4E98D0[i][0];
-		pUIAnims[i]->y = _4E98D0[i][2];
-	}
-
-	for (unsigned int i = 0; i < pObjectList->uNumObjects; ++i)
-	{
-		pObjectList->pObjects[i].uParticleTrailColor = pObjectList->pObjects[i].uParticleTrailColorB |
-			((unsigned int)pObjectList->pObjects[i].uParticleTrailColorG << 8) |
-			((unsigned int)pObjectList->pObjects[i].uParticleTrailColorR << 16);
-	}
-
-	MainMenuUI_Create();
-	pGame->pStru6Instance->LoadAnimations();
-
-	for (uint i = 0; i < 7; ++i)
-	{
-		char container_name[64];
-		sprintf(container_name, "HDWTR%03u", i);
-		pRenderer->pHDWaterBitmapIDs[i] = pBitmaps_LOD->LoadTexture(container_name);
-	}
-
-	pNPCStats = new NPCStats;
-	memset(pNPCStats->pNPCData, 0, 0x94BCu);
-	pNPCStats->Initialize();
-
-	Initialize_GlobalEVT();
-	pBitmaps_LOD->_inlined_sub0();
-	pSprites_LOD->_inlined_sub0();
-	pPaletteManager->LockAll();
-
-	_mkdir("Saves");
-	for (uint i = 0; i < 5; ++i)
-	for (uint j = 0; j < 6; ++j)
-	{
-		sprintf(pTmpBuf.data(), "data\\lloyd%d%d.pcx", i, j);
-		remove(pTmpBuf.data());
-	}
-
-	Initialize_GamesLOD_NewLOD();
-	_576E2C_current_minimap_zoom = 512;
-	dword_576E28 = 9;
-}
-
-int max_flight_height = 4000;    //maximum altitude
-bool use_MMT = false;
-bool use_music_folder = true;
-bool for_refactoring = false;
-
-//----- (00462C94) --------------------------------------------------------
-bool MM_Main(const wchar_t *pCmdLine)
-{
-	IntegrityTest();
-
-	lua = new LuaVM;
-	lua->Initialize();
-
-	bool bNoMargareth = false;
-	if (pCmdLine && *pCmdLine)
-	{
-		//if (wcsstr(pCmdLine, L"-usedefs"))
-		//  bDebugResouces = 1;
-		if (wcsstr(pCmdLine, L"-window"))
-			dword_6BE368_debug_settings_2 |= DEBUG_SETTINGS_RUN_IN_WIDOW;
-
-		if (wcsstr(pCmdLine, L"-nointro"))
-			bNoIntro = true;//dword_6BE364_game_settings_1 |= 4;
-		if (wcsstr(pCmdLine, L"-nologo"))
-			bNoLogo = true;//dword_6BE364_game_settings_1 |= 8;
-		if (wcsstr(pCmdLine, L"-nosound"))
-			bNoSound = true; //dword_6BE364_game_settings_1 |= 0x10;
-
-		bWalkSound = ReadWindowsRegistryInt("WalkSound", 1) != 0;
-		if (wcsstr(pCmdLine, L"-nowalksound"))
-			bWalkSound = false;//dword_6BE364_game_settings_1 |= 0x20;
-		if (wcsstr(pCmdLine, L"-novideo"))
-		{
-			dword_6BE364_game_settings_1 |= GAME_SETTINGS_NO_HOUSE_ANIM;
-			bNoVideo = true;
-		}
-		if (wcsstr(pCmdLine, L"-nocd"))
-			bNoCD = true;
-		if (wcsstr(pCmdLine, L"-nomarg"))
-			bNoMargareth = true;
-	}
-
-	//_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF );//Ritor1: for memory test
-
-	if (!MM7_Initialize(640, 480))
-	{
-		Log::Warning(L"MM init: failed");
-		pGame->Deinitialize();
-		return 1;
-	}
-
-	pEventTimer->Pause();
-
-	SetUserInterface(PartyAlignment_Neutral, false);
-
-	ShowLogoVideo();
-	//ShowIntroVideo_and_LoadingScreen();
-	WriteWindowsRegistryInt("Ran once", 1);
-	dword_6BE364_game_settings_1 |= GAME_SETTINGS_4000;
-	SecondaryInitialization();
-	//pRenderer->SetRasterClipRect(0, 0, window->GetWidth() - 1, window->GetHeight() - 1);
-	FinalInitialization();
-
-	//Ritor1: include
-    if (use_MMT)
-	  MMT_MainMenu_Loop();
-
-	Log::Warning(L"MM: entering main loop");
-	while (1)
-	{
-		MainMenuWindow* main_menu_window = MainMenuWindow::Create();
-		window->AddControl(main_menu_window);
-		MainMenu_Loop();
-		uGameState = GAME_STATE_PLAYING;
-		while (1)
-		{
-			if (uGameState == GAME_FINISHED || GetCurrentMenuID() == MENU_EXIT_GAME)
-			{
-				pGame->Deinitialize();
-				return true;
-			}
-
-			if (GetCurrentMenuID() == MENU_NEWGAME)
-			{
-              if ( use_music_folder )
-                alSourceStop(mSourceID);
-              else
-			  {
-				if (pAudioPlayer->hAILRedbook)
-					AIL_redbook_stop(pAudioPlayer->hAILRedbook);
-			  }
-				pParty->Reset();
-				pOtherOverlayList->Reset();
-				strcpy(pCurrentMapName, pStartingMapName);
-				pParty->CreateDefaultParty(0);
-				PlayerCreationUI_Initialize();
-				if (PlayerCreationUI_Loop())
-				{
-					DeleteCCharFont();
-					break;
-				}
-				DeleteCCharFont();
-				bFlashQuestBook = true;
-				pMediaPlayer->PlayFullscreenMovie(MOVIE_Emerald, true);
-				SaveNewGame();
-				if (bNoMargareth)
-					_449B7E_toggle_bit(pParty->_quest_bits, PARTY_QUEST_EMERALD_MARGARETH_OFF, 1);
-				pGame->Loop();
-				if (uGameState == GAME_STATE_NEWGAME_OUT_GAMEMENU)
-				{
-					SetCurrentMenuID(MENU_NEWGAME);
-					uGameState = GAME_STATE_PLAYING;
-					continue;
-				}
-				else if (uGameState == GAME_STATE_GAME_QUITTING_TO_MAIN_MENU)
-					break;
-				assert(false && "Invalid game state");
-			}
-			if (GetCurrentMenuID() == MENU_CREDITS)
-			{
-              if ( use_music_folder )
-                alSourceStop(mSourceID);
-              else
-			  {
-				if (pAudioPlayer->hAILRedbook)
-					AIL_redbook_stop(pAudioPlayer->hAILRedbook);
-			  }
-			  MainMenuUI_Credits_Loop();
-			  break;
-			}
-			if (GetCurrentMenuID() == MENU_5 || GetCurrentMenuID() == MENU_LoadingProcInMainMenu)
-			{
-				uGameState = GAME_STATE_PLAYING;
-				pGame->Loop();
-			}
-			else
-			{
-				if (GetCurrentMenuID() == MENU_DebugBLVLevel)
-				{
-					pMouse->ChangeActivation(0);
-					pParty->Reset();
-					pParty->CreateDefaultParty(1);
-
-					__debugbreak();
-					/*extern void CreateDefaultBLVLevel();
-					CreateDefaultBLVLevel();
-
-					OPENFILENAMEA ofn;
-					if ( !GetOpenFileNameA((LPOPENFILENAMEA)&ofn) )
-					{
-					pMouse->ChangeActivation(1);
-					break;
-					}
-					_chdir("..\\");
-					strcpy(pCurrentMapName, ofn.lpstrFileTitle);*/
-					pMouse->ChangeActivation(1);
-					pGame->Loop();
-				}
-			}
-			if (uGameState == GAME_STATE_LOADING_GAME)
-			{
-				SetCurrentMenuID(MENU_5);
-				uGameState = GAME_STATE_PLAYING;
-				continue;
-			}
-			if (uGameState == GAME_STATE_NEWGAME_OUT_GAMEMENU)
-			{
-				SetCurrentMenuID(MENU_NEWGAME);
-				uGameState = GAME_STATE_PLAYING;
-				continue;
-			}
-			if (uGameState == GAME_STATE_GAME_QUITTING_TO_MAIN_MENU)// from the loaded game
-			{
-				pAudioPlayer->StopChannels(-1, -1);
-				uGameState = GAME_STATE_PLAYING;
-				break;
-			}
-		}
-		if (!bNoSound )
-		{
-		  if ( use_music_folder )
-	      {
-	       PlayAudio(L"Music\\14.mp3");
-	       alSourcef (mSourceID, AL_GAIN, pSoundVolumeLevels[uMusicVolimeMultiplier]);
-	      }
-	      else if ( pAudioPlayer->hAILRedbook)
-		  {
-			pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f);
-			AIL_redbook_stop(pAudioPlayer->hAILRedbook);
-			unsigned int startms, end_ms;
-			AIL_redbook_track_info(pAudioPlayer->hAILRedbook, 14, &startms, &end_ms);
-			AIL_redbook_play(pAudioPlayer->hAILRedbook, startms + 1, end_ms);
-		  }
-		}
-	}
-	//lua_close(L);
-	pGame->Deinitialize();
-	return 1;
-}
-
-
-
-//----- (00466082) --------------------------------------------------------
-void MM6_Initialize(const wchar_t *pIniFilename)
-{
-	size_t v2; // eax@31
-	size_t v3; // ebx@32
-	size_t v4; // edi@36
-	char pDefaultGroundTexture[16]; // [sp+FCh] [bp-8Ch]@32
-	unsigned int v9; // [sp+184h] [bp-4h]@28
-
-	//_getcwd(v5, 120);
-	//sprintfex(pIniFilename, "%s\\mm6.ini", v5);
-	viewparams = new ViewingParams;
-	game_viewport_x = viewparams->uScreen_topL_X = GetPrivateProfileIntW(L"screen", L"vx1", 8, pIniFilename);
-	game_viewport_y = viewparams->uScreen_topL_Y = GetPrivateProfileIntW(L"screen", L"vy1", 8, pIniFilename);
-	game_viewport_z = viewparams->uScreen_BttmR_X = GetPrivateProfileIntW(L"screen", L"vx2", 468, pIniFilename);
-	game_viewport_w = viewparams->uScreen_BttmR_Y = GetPrivateProfileIntW(L"screen", L"vy2", 351, pIniFilename);
-	game_viewport_width = game_viewport_z - game_viewport_x;
-	game_viewport_height = game_viewport_w - game_viewport_y + 1;
-
-
-	pAudioPlayer = new AudioPlayer;
-	pAudioPlayer->uMixerChannels = GetPrivateProfileIntW(L"settings", L"mixerchannels", 16, pIniFilename);
-	if (pAudioPlayer->uMixerChannels > 16)
-		pAudioPlayer->uMixerChannels = 16;
-
-
-	if (GetPrivateProfileIntW(L"debug", L"nomonster", 0, pIniFilename))
-		dword_6BE368_debug_settings_2 |= DEBUG_SETTINGS_NO_ACTORS;
-	if (ReadWindowsRegistryInt("startinwindow", 0))
-		dword_6BE368_debug_settings_2 |= DEBUG_SETTINGS_RUN_IN_WIDOW;
-	if (GetPrivateProfileIntW(L"debug", L"showFR", 0, pIniFilename))
-		dword_6BE368_debug_settings_2 |= DEBUG_SETTINGS_0002_SHOW_FR;
-	if (GetPrivateProfileIntW(L"debug", L"nodamage", 0, pIniFilename))
-		dword_6BE368_debug_settings_2 |= DEBUG_SETTINGS_NO_DAMAGE;
-	if (GetPrivateProfileIntW(L"debug", L"nodecoration", 0, pIniFilename))
-		dword_6BE368_debug_settings_2 |= DEBUG_SETTINGS_NO_DECORATIONS;
-
-	wchar_t pStartingMapNameW[1024];
-	GetPrivateProfileStringW(L"file", L"startmap", L"out01.odm", pStartingMapNameW, 0x20u, pIniFilename);
-	sprintf(pStartingMapName, "%S", pStartingMapNameW);
-
-	v9 = 0;
-	if (strlen(pStartingMapName))
-	{
-		do
-		{
-			if (pStartingMapName[v9] == ' ')
-				pStartingMapName[v9] = 0;
-			++v9;
-			v2 = strlen(pStartingMapName);
-		} while (v9 < v2);
-	}
-
-	pODMRenderParams = new ODMRenderParams;
-	pODMRenderParams->outdoor_no_mist = GetPrivateProfileIntW(L"debug", L"noMist", 0, pIniFilename);
-	pODMRenderParams->bNoSky = GetPrivateProfileIntW(L"outdoor", L"nosky", 0, pIniFilename);
-	pODMRenderParams->bDoNotRenderDecorations = GetPrivateProfileIntW(L"render", L"nodecorations", 0, pIniFilename);
-	pODMRenderParams->outdoor_no_wavy_water = GetPrivateProfileIntW(L"outdoor", L"nowavywater", 0, pIniFilename);
-	outdoor_grid_band_1 = GetPrivateProfileIntW(L"outdoor", L"gridband1", 10, pIniFilename);
-	outdoor_grid_band_2 = GetPrivateProfileIntW(L"outdoor", L"gridband2", 15, pIniFilename);
-	outdoor_grid_band_3 = GetPrivateProfileIntW(L"outdoor", L"gridband3", 25, pIniFilename);
-	pODMRenderParams->terrain_gamma = GetPrivateProfileIntW(L"outdoor", L"ter_gamma", 0, pIniFilename);
-	pODMRenderParams->building_gamme = GetPrivateProfileIntW(L"outdoor", L"bld_gamma", 0, pIniFilename);
-	pODMRenderParams->shading_dist_shade = GetPrivateProfileIntW(L"shading", L"dist_shade", 2048, pIniFilename);
-	pODMRenderParams->shading_dist_shademist = GetPrivateProfileIntW(L"shading", L"dist_shademist", 4096, pIniFilename);
-
-	pODMRenderParams->shading_dist_mist = GetPrivateProfileIntW(L"shading", L"dist_mist", 0x2000, pIniFilename);//drawing dist 0x2000
-
-	wchar_t pDefaultSkyTextureW[1024];
-	GetPrivateProfileStringW(L"textures", L"sky", L"plansky1", pDefaultSkyTextureW, 0x10u, pIniFilename);
-	sprintf(pDefaultSkyTexture.data(), "%S", pDefaultSkyTextureW);
-
-	wchar_t pDefaultGroundTextureW[1024];
-	GetPrivateProfileStringW(L"textures", L"default", L"dirt", pDefaultGroundTextureW, 0x10u, pIniFilename);
-	sprintf(pDefaultGroundTexture, "%S", pDefaultGroundTextureW);
-
-	wchar_t pFloat[1024];
-	GetPrivateProfileStringW(L"debug", L"recmod1", L"1.0", pFloat, 0x10u, pIniFilename);
-	swscanf(pFloat, L"%f", &flt_6BE3A4_debug_recmod1);
-
-	GetPrivateProfileStringW(L"debug", L"recmod2", L"1.0", pFloat, 0x10u, pIniFilename);
-	swscanf(pFloat, L"%f", &flt_6BE3A8_debug_recmod2);
-
-	flt_6BE3AC_debug_recmod1_x_1_6 = flt_6BE3A4_debug_recmod1 * 1.666666666666667;
-
-	v3 = 0;
-	if (strlen(pDefaultSkyTexture.data()))
-	{
-		do
-		{
-			if (pDefaultSkyTexture[v3] == ' ')
-				pDefaultSkyTexture[v3] = 0;
-			++v3;
-		} while (v3 < strlen(pDefaultSkyTexture.data()));
-	}
-	v4 = 0;
-	if (strlen(pDefaultGroundTexture))
-	{
-		do
-		{
-			if (pDefaultGroundTexture[v4] == ' ')
-				pDefaultGroundTexture[v4] = 0;
-			++v4;
-		} while (v4 < strlen(pDefaultGroundTexture));
-	}
-
-	MM7Initialization();
-}
-
-//----- (004666D5) --------------------------------------------------------
-void MM7Initialization()
-{
-	if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
-	{
-		/*if (byte_6BE388_graphicsmode == 0)
-		{
-		outdoor_grid_band_1 = 10;
-		outdoor_grid_band_2 = 15;
-		outdoor_grid_band_3 = 20;
-		pODMRenderParams->shading_dist_mist = 8192;
-		pODMRenderParams->bNoSky = false;
-		LOBYTE(viewparams->field_20) = 0;
-		}*/
-		pODMRenderParams->shading_dist_shade = 2048;
-		pODMRenderParams->terrain_gamma = 0;
-		pODMRenderParams->building_gamme = 0;
-		pODMRenderParams->shading_dist_shademist = 4096;
-		pODMRenderParams->outdoor_no_wavy_water = 0;
-		//_47F4D3_initialize_terrain_bezier_stuff(outdoor_grid_band_1, outdoor_grid_band_2, outdoor_grid_band_3);
-		{
-			pODMRenderParams->outdoor_grid_band_3 = outdoor_grid_band_3;
-			pODMRenderParams->uPickDepth = outdoor_grid_band_3 * 512;
-		}
-	}
-	else
-		LOBYTE(viewparams->field_20) = 0;
-	pParty->uFlags |= 2;
-	viewparams->uSomeY = viewparams->uScreen_topL_Y;
-	viewparams->uSomeX = viewparams->uScreen_topL_X;
-	viewparams->uSomeZ = viewparams->uScreen_BttmR_X;
-	viewparams->uSomeW = viewparams->uScreen_BttmR_Y;
-
-	pViewport->SetScreen(viewparams->uScreen_topL_X, viewparams->uScreen_topL_Y, viewparams->uScreen_BttmR_X, viewparams->uScreen_BttmR_Y);
-	if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
-		pODMRenderParams->Initialize();
-}
-
-//----- (004610AA) --------------------------------------------------------
-void __fastcall PrepareToLoadODM(unsigned int bLoading, ODMRenderParams *a2)
-{
-	pGameLoadingUI_ProgressBar->Reset(27);
-	pSoundList->_4A9D79(0);
-	uCurrentlyLoadedLevelType = LEVEL_Outdoor;
-	ODM_LoadAndInitialize(pCurrentMapName, a2);
-	if (!bLoading)
-		TeleportToStartingPoint(uLevel_StartingPointType);
-	viewparams->_443365();
-	PlayLevelMusic();
-}
-// 6BE35C: using guessed type int uLevel_StartingPointType;
-
-
-//----- (004627B7) --------------------------------------------------------
-void MainMenu_Loop()
-{
-	GUIButton *pButton; // eax@27
-	unsigned int pControlParam; // ecx@35
-	unsigned int pY; // [sp-18h] [bp-54h]@39
-	Texture *pTexture; // [sp-14h] [bp-50h]@39
-	GUIWindow *pWindow; // [sp+4h] [bp-38h]@11
-	MSG msg;
-
-	pCurrentScreen = SCREEN_GAME;
-
-	pGUIWindow2 = 0;
-	pAudioPlayer->StopChannels(-1, -1);
-	pMouse->RemoveHoldingItem();
-
-	pIcons_LOD->_inlined_sub2();
-
-	pWindow_MainMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_MainMenu, 0, 0);
-	Texture* pNew = pIcons_LOD->LoadTexturePtr("title_new", TEXTURE_16BIT_PALETTE);
-	Texture* pLoad = pIcons_LOD->LoadTexturePtr("title_load", TEXTURE_16BIT_PALETTE);
-	Texture* pCredits = pIcons_LOD->LoadTexturePtr("title_cred", TEXTURE_16BIT_PALETTE);
-	Texture* pExit = pIcons_LOD->LoadTexturePtr("title_exit", TEXTURE_16BIT_PALETTE);
-
-	pMainMenu_BtnNew = pWindow_MainMenu->CreateButton(495, 172, pNew->uTextureWidth, pNew->uTextureHeight, 1, 0, UIMSG_MainMenu_ShowPartyCreationWnd, 0, 'N', "", pNew, 0);
-	pMainMenu_BtnLoad = pWindow_MainMenu->CreateButton(495, 227, pLoad->uTextureWidth, pLoad->uTextureHeight, 1, 0, UIMSG_MainMenu_ShowLoadWindow, 1, 'L', "", pLoad, 0);
-	pMainMenu_BtnCredits = pWindow_MainMenu->CreateButton(495, 282, pCredits->uTextureWidth, pCredits->uTextureHeight, 1, 0, UIMSG_ShowCredits, 2, 'C', "", pCredits, 0);
-	pMainMenu_BtnExit = pWindow_MainMenu->CreateButton(495, 337, pExit->uTextureWidth, pExit->uTextureHeight, 1, 0, UIMSG_ExitToWindows, 3, 0, "", pExit, 0);
-
-	pTexture_PCX.Release();
-	pTexture_PCX.Load("title.pcx", 0);
-	SetCurrentMenuID(MENU_MAIN);
-	SetForegroundWindow(window->GetApiHandle());
-	SendMessageW(window->GetApiHandle(), WM_ACTIVATEAPP, 1, 0);
-	while (GetCurrentMenuID() == MENU_MAIN || GetCurrentMenuID() == MENU_SAVELOAD)
-	{
-		POINT pt;
-		pMouse->GetCursorPos(&pt);
-		pWindow = pWindow_MainMenu;
-		if (GetCurrentMenuID() == MENU_SAVELOAD)
-		{
-			if (pCurrentScreen != SCREEN_LOADGAME)
-			{
-				pTexture_PCX.Release();
-				pTexture_PCX.Load("lsave640.pcx", 0);
-				pGUIWindow2 = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_MainMenu, 0, 0);
-				pCurrentScreen = SCREEN_LOADGAME;
-				LoadUI_Load(0);
-			}
-			pWindow = pGUIWindow_CurrentMenu;
-		}
-
-		while (PeekMessageW(&msg, 0, 0, 0, PM_REMOVE))
-		{
-			if (msg.message == WM_QUIT)
-				Game_DeinitializeAndTerminate(0);
-			TranslateMessage(&msg);
-			DispatchMessageW(&msg);
-		}
-
-		if (dword_6BE364_game_settings_1 & GAME_SETTINGS_APP_INACTIVE)
-		{
-			WaitMessage();
-			continue;
-		}
-
-		pRenderer->BeginScene();
-		pRenderer->DrawTextureNew(0, 0, &pTexture_PCX);
-
-		GUI_MainMenuMessageProc();
-		GUI_UpdateWindows();
-
-		if (GetCurrentMenuID() != MENU_MAIN)
-		{
-			if (GetCurrentMenuID() == MENU_LoadingProcInMainMenu)
-			{
-				pIcons_LOD->RemoveTexturesPackFromTextureList();
-				pGUIWindow_CurrentMenu->Release();
-				pGUIWindow_CurrentMenu = 0;
-				pCurrentScreen = SCREEN_GAME;
-				viewparams->bRedrawGameUI = 1;
-			}
-		}
-		else
-		{
-			if (!pModalWindow)// ???
-			{
-				pButton = pWindow->pControlsHead;
-				for (pButton = pWindow->pControlsHead; pButton; pButton = pButton->pNext)
-				{
-					if (pt.x >= (signed int)pButton->uX && pt.x <= (signed int)pButton->uZ
-						&& pt.y >= (signed int)pButton->uY && pt.y <= (signed int)pButton->uW
-						&& pWindow == pWindow_MainMenu)
-					{
-						pControlParam = pButton->msg_param;
-						switch (pControlParam) // backlight for buttons
-						{
-						case 0:
-							pTexture = pNew;
-							pY = 172;
-							break;
-						case 1:
-							pTexture = pLoad;
-							pY = 227;
-							break;
-						case 2:
-							pTexture = pCredits;
-							pY = 282;
-							break;
-						case 3:
-							pTexture = pExit;
-							pY = 337;
-							break;
-						}
-						pRenderer->DrawTextureIndexed(495, pY, pTexture);
-					}
-				}
-			}
-		}
-		pRenderer->EndScene();
-		pRenderer->Present();
-	}
-	GUI_MainMenuMessageProc();
-	pRenderer->BeginScene();
-	GUI_UpdateWindows();
-	pRenderer->EndScene();
-	pRenderer->Present();
-	pTexture_PCX.Release();
-	if (pGUIWindow2)
-	{
-		pGUIWindow2->Release();
-		pGUIWindow2 = 0;
-	}
-	pWindow_MainMenu->Release();
-	pIcons_LOD->RemoveTexturesPackFromTextureList();
-}
-
-//----- (004BF91E) --------------------------------------------------------
-unsigned int GameOverMenu(void *ecx0)
-{
-	const char *v1; // eax@2
-	unsigned int result; // eax@3
-	const char *v6; // eax@10
-	const char *v7; // edx@10
-	const char *v8; // ecx@12
-	const char *v9; // eax@14
-	unsigned int v10; // eax@25
-	GUIWindow pWindow; // [sp+34h] [bp-9Ch]@1
-	unsigned int v14; // [sp+A4h] [bp-2Ch]@5
-	void *v15; // [sp+A8h] [bp-28h]@1
-	const char *pInString; // [sp+ACh] [bp-24h]@5
-	unsigned int v17; // [sp+B0h] [bp-20h]@5
-	unsigned int v18; // [sp+B4h] [bp-1Ch]@5
-	unsigned int v19; // [sp+B8h] [bp-18h]@5
-	int v20; // [sp+BCh] [bp-14h]@7
-	GUIFont *pFont; // [sp+C4h] [bp-Ch]@1
-	unsigned __int64 v23; // [sp+C8h] [bp-8h]@5
-	MSG msg;
-
-	v15 = ecx0;
-
-	RGBTexture _this; // [sp+Ch] [bp-C4h]@1
-	//RGBTexture::RGBTexture(&this);
-
-	dword_6BE364_game_settings_1 &= ~GAME_SETTINGS_4000;
-	bGameoverLoop = 1;
-	pMediaPlayer->bStopBeforeSchedule = 0;
-	pAudioPlayer->StopChannels(-1, -1);
-	pRenderer->BeginScene();
-	pRenderer->ClearBlack();
-	pRenderer->EndScene();
-	pRenderer->Present();
-	//pMediaPlayer->pResetflag = 0;
-	_449B57_test_bit(pParty->_quest_bits, 99);
-	_this.Load("winbg.pcx", 2);
-	pRenderer->BeginScene();
-	pRenderer->DrawTextureRGB(0, 0, &_this);
-	pRenderer->EndScene();
-	free(_this.pPixels);
-	_this.pPixels = 0;
-	window_SpeakInHouse = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_MainMenu, 0, 0);
-	pWindow.uFrameX = 75;
-	pWindow.uFrameY = 60;
-	pWindow.uFrameWidth = 469;
-	pWindow.uFrameHeight = 338;
-	pWindow.uFrameZ = 543;
-	pWindow.uFrameW = 397;
-	pFont = LoadFont("endgame.fnt", "FONTPAL", NULL);
-	if (pParty->IsPartyGood())
-		v1 = pGlobalTXT_LocalizationStrings[675];//"Splendid job!  With the activation of the Gate, a thousand worlds lie at your feet.  Perhaps on one of them you will find the Ancients themselves, and return with the fruits their great civilization has to offer your world and your kingdom."
-	else
-	{
-		result = pParty->IsPartyEvil();
-		if (!(short)result)
-			return result;
-		v1 = pGlobalTXT_LocalizationStrings[676];//"Brilliant!  The completion of the Heavenly Forge has provided enough Ancient weapons to crush all resistance to your plans.  Soon the world will bow to your every whim!  Still, you can't help but wonder what was beyond the Gate the other side was trying so hard to build."
-	}
-	pInString = v1;
-	v23 = pParty->uTimePlayed - 138240;
-	v19 = (unsigned int)((signed __int64)((double)(pParty->uTimePlayed - 138240) * 0.234375) / 60 / 60) / 24;
-	v14 = (unsigned int)((signed __int64)((double)(pParty->uTimePlayed - 138240) * 0.234375) / 60 / 60) / 24 / 0x1C / 0xC;
-	v18 = (unsigned int)((signed __int64)((double)(pParty->uTimePlayed - 138240) * 0.234375) / 60 / 60) / 24 / 0x1C % 0xC;
-	v17 = v19 % 0x1C;
-	if (!v19)
-		v19 = 1;
-	pRenderer->BeginScene();
-	pWindow.DrawTitleText(pFont, 1, 0x23, 1, pGlobalTXT_LocalizationStrings[9], 3);//Congratulations!
-	v23 = 0i64;
-	v20 = 0;
-	for (uint i = 0; i < 4; i++)
-	{
-		sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[129], pParty->pPlayers[i].pName, pParty->pPlayers[i].GetBaseLevel(), pClassNames[pParty->pPlayers[i].classType]);//%s the Level %u %s
-		pWindow.DrawTitleText(pFont, 1, i * (LOBYTE(pFont->uFontHeight) - 2) + LOBYTE(pFont->uFontHeight) + 46, 1, pTmpBuf.data(), 3);
-		v23 += pParty->pPlayers[i].uExperience;//__PAIR__(*(int *)(i - 4), *(int *)(i - 8));
-	}
-	v23 = (signed __int64)v23 / v19;
-	v6 = FitTextInAWindow(pInString, pFont, &pWindow, 0xC, 0);
-	pWindow.DrawTitleText(pFont, 1, 5 * (LOBYTE(pFont->uFontHeight) + 11), 1, v6, 0);
-	strcpy(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[37]);//Total Time:
-
-	v7 = pGlobalTXT_LocalizationStrings[56];
-	if (v17 != 1)
-		v7 = pGlobalTXT_LocalizationStrings[57];
-
-	v8 = pGlobalTXT_LocalizationStrings[146];//Month
-	if (v18 != 1)
-		v8 = pGlobalTXT_LocalizationStrings[148];//Months
-
-	v9 = pGlobalTXT_LocalizationStrings[245];
-	if (v14 != 1)
-		v9 = pGlobalTXT_LocalizationStrings[132];
-
-	sprintf(pTmpBuf2.data(), " %lu %s, %lu %s, %lu %s ", v14, v9, v18, v8, v17, v7);
-	strcat(pTmpBuf.data(), pTmpBuf2.data());
-	pWindow.DrawTitleText(pFont, 1, pWindow.uFrameHeight - 2 * LOBYTE(pFont->uFontHeight) - 5, 1, pTmpBuf.data(), 3);
-	sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[94], v23);
-	pWindow.DrawTitleText(pFont, 1, pWindow.uFrameHeight, 1, pTmpBuf.data(), 3);
-	dword_6BE364_game_settings_1 |= GAME_SETTINGS_4000;
-	pRenderer->EndScene();
-	pRenderer->Present();
-	//if ( pRenderer->pRenderD3D )
-	pRenderer->pBeforePresentFunction();
-	pRenderer->SaveWinnersCertificate("MM7_Win.Pcx");
-	free(pFont);
-	window_SpeakInHouse->Release();
-	window_SpeakInHouse = 0;
-	if (v15 == (void *)2)
-		result = pMessageQueue_50CBD0->uNumMessages;
-	else
-	{
-		LODWORD(v23) = GetTickCount() + 5000;
-		while ((unsigned int)v23 > GetTickCount())
-			;
-		while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
-		{
-			if (msg.message == WM_QUIT)
-				Game_DeinitializeAndTerminate(0);
-			TranslateMessage(&msg);
-			DispatchMessage(&msg);
-		}
-		if (pMessageQueue_50CBD0->uNumMessages)
-		{
-			LOBYTE(v10) = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-			pMessageQueue_50CBD0->uNumMessages = v10;
-		}
-		pKeyActionMap->ResetKeys();
-		pKeyActionMap->uLastKeyPressed = 0;
-		do
-		{
-			while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
-			{
-				if (msg.message == WM_QUIT)
-					Game_DeinitializeAndTerminate(0);
-				TranslateMessage(&msg);
-				DispatchMessage(&msg);
-			}
-		} while (!pKeyActionMap->uLastKeyPressed);
-		result = pMessageQueue_50CBD0->uNumMessages;
-		if (pMessageQueue_50CBD0->uNumMessages)
-		{
-			result = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-			pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-		}
-	}
-	if (v15)
-	{
-		/*if ( (signed int)result < 40 )
-		{
-		pMessageQueue_50CBD0->pMessages[result].eType = UIMSG_Quit;
-		}*/
-		pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Quit, 1, 0);
-	}
-	else
-	{
-		pMessageQueue_50CBD0->AddGUIMessage(UIMSG_ShowFinalWindow, 1, 0);
-		/*if ( (signed int)result < 40 )
-		{
-		pMessageQueue_50CBD0->pMessages[result].eType = UIMSG_C5;
-		pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 1;
-		result = 3 * pMessageQueue_50CBD0->uNumMessages + 3;
-		*(&pMessageQueue_50CBD0->uNumMessages + result) = 0;
-		++pMessageQueue_50CBD0->uNumMessages;
-		}*/
-	}
-	bGameoverLoop = 0;
-	return result;
-}
-
-//----- (00464479) --------------------------------------------------------
-void ResetCursor_Palettes_LODs_Level_Audio_SFT_Windows()
-{
-	int v0; // esi@9
-
-	if (pMouse)
-		pMouse->SetCursorBitmap("MICON1");
-
-	pPaletteManager->ResetNonLocked();
-	pBitmaps_LOD->ReleaseAll2();
-	pSprites_LOD->DeleteSomeOtherSprites();
-	pIcons_LOD->ReleaseAll2();
-
-	if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
-		pIndoor->Release();
-	else if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
-		pOutdoor->Release();
-
-	pAudioPlayer->StopChannels(-1, -1);
-	pSoundList->_4A9D79(0);
-	uCurrentlyLoadedLevelType = LEVEL_null;
-	pSpriteFrameTable->ResetSomeSpriteFlags();
-	v0 = uNumVisibleWindows;
-	pParty->armageddon_timer = 0;
-	while (v0 > 0)
-		pWindowList[pVisibleWindowsIdxs[v0--] - 1].Release();
-}
-
-//----- (00461103) --------------------------------------------------------
-void _461103_load_level_sub()
-{
-	int v4; // edx@8
-	signed int v6; // esi@14
-	signed int v8; // ecx@16
-	int v12; // esi@25
-	int v13; // eax@26
-	__int16 v14; // ax@41
-	signed int v17; // [sp+14h] [bp-48h]@3
-	signed int v18; // [sp+14h] [bp-48h]@23
-	int v19; // [sp+18h] [bp-44h]@1
-	signed int v20; // [sp+18h] [bp-44h]@14
-	int v21[16]; // [sp+1Ch] [bp-40h]@17
-
-	GenerateItemsInChest();
-	pGameLoadingUI_ProgressBar->Progress();
-	pParty->uFlags |= 2;
-	pParty->field_7B5_in_arena_quest = 0;
-	dword_5C6DF8 = 1;
-	pNPCStats->uNewlNPCBufPos = 0;
-	v19 = pMapStats->GetMapInfo(pCurrentMapName);
-
-	//v15 = 0;
-	for (uint i = 0; i < uNumActors; ++i)
-		//if ( (signed int)uNumActors > 0 )
-	{
-		//Actor* pActor = &pActors[i];
-		//v2 = (char *)&pActors[0].uNPC_ID;
-		//do
-		//{
-		//v3 = pActors[i].pMonsterInfo.uID;
-		v17 = 0;
-		if (pActors[i].pMonsterInfo.uID >= 115 && pActors[i].pMonsterInfo.uID <= 186
-			|| pActors[i].pMonsterInfo.uID >= 232 && pActors[i].pMonsterInfo.uID <= 249)
-			v17 = 1;
-		//v1 = 0;
-		v4 = (pActors[i].pMonsterInfo.uID - 1) % 3;
-		if (2 == v4)
-		{
-			if (pActors[i].sNPC_ID && pActors[i].sNPC_ID < 5000)
-				continue;
-		}
-		else
-		{
-			if (v4 != 1)
-			{
-				if (v4 == 0 && pActors[i].sNPC_ID == 0)
-					pActors[i].sNPC_ID = 0;
-				continue;
-			}
-		}
-		if (pActors[i].sNPC_ID > 0 && pActors[i].sNPC_ID < 5000)
-			continue;
-		if (v17)
-		{
-			pNPCStats->InitializeAdditionalNPCs(&pNPCStats->pAdditionalNPC[pNPCStats->uNewlNPCBufPos], pActors[i].pMonsterInfo.uID, 0, v19);
-			v14 = LOWORD(pNPCStats->uNewlNPCBufPos) + 5000;
-			++pNPCStats->uNewlNPCBufPos;
-			pActors[i].sNPC_ID = v14;
-			continue;
-		}
-		pActors[i].sNPC_ID = 0;
-		//++v15;
-		//v2 += 836;
-		//}
-		//while ( v15 < (signed int)uNumActors );
-	}
-
-	pGameLoadingUI_ProgressBar->Progress();
-
-	//v5 = uNumActors;
-	v6 = 0;
-	v20 = 0;
-	//v16 = v1;
-
-	for (uint i = 0; i < uNumActors; ++i)
-	{
-		//v7 = (char *)&pActors[0].pMonsterInfo;
-		//do
-		//{
-		for (v8 = 0; v8 < v6; ++v8)
-		{
-			if (v21[v8] == pActors[i].pMonsterInfo.uID - 1)
-				break;
-		}
-
-		if (v8 == v6)
-		{
-			v21[v6++] = pActors[i].pMonsterInfo.uID - 1;
-			v20 = v6;
-			if (v6 == 16)
-				break;
-		}
-		//++v16;
-		//v7 += 836;
-		//}
-		//while ( v16 < (signed int)v5 );
-	}
-
-	pGameLoadingUI_ProgressBar->Progress();
-
-	for (int _v0 = 0; _v0 < v6; ++_v0)
-	{
-		for (v18 = 4; v18; --v18)
-			pSoundList->LoadSound(pMonsterList->pMonsters[v21[_v0]].pSoundSampleIDs[4 - v18], 0);
-		v12 = 0;
-		do
-		v13 = pSoundList->LoadSound(v12++ + word_4EE088_sound_ids[pMonsterStats->pInfos[v21[_v0] + 1].uSpell1ID], 1);
-		while (v13);
-	}
-	//v0 = pGameLoadingUI_ProgressBar;
-	//v1 = 0;
-
-	pGameLoadingUI_ProgressBar->Progress();
-
-	if (dword_6BE368_debug_settings_2 & DEBUG_SETTINGS_NO_ACTORS)
-		uNumActors = 0;
-	if (dword_6BE368_debug_settings_2 & DEBUG_SETTINGS_NO_DECORATIONS)
-		uNumLevelDecorations = 0;
-	init_event_triggers();
-
-	pGameLoadingUI_ProgressBar->Progress();
-
-	pGame->pIndoorCameraD3D->vPartyPos.x = 0;
-	pGame->pIndoorCameraD3D->vPartyPos.y = 0;
-	pGame->pIndoorCameraD3D->vPartyPos.z = 100;
-	pGame->pIndoorCameraD3D->sRotationX = 0;
-	pGame->pIndoorCameraD3D->sRotationY = 0;
-	viewparams->bRedrawGameUI = true;
-	uLevel_StartingPointType = MapStartPoint_Party;
-	pSprites_LOD->_461397();
-	pPaletteManager->LockTestAll();
-	if (pParty->pPickedItem.uItemID != 0)
-		pMouse->SetCursorBitmapFromItemID(pParty->pPickedItem.uItemID);
-}
-
-//----- (0042F3D6) --------------------------------------------------------
-void InitializeTurnBasedAnimations(void *_this)
-{
-	for (unsigned int i = 0; i < pIconIDs_Turn.size(); ++i)
-	{
-		char icon_name[32];
-		sprintf(icon_name, "turn%u", i);
-		pIconIDs_Turn[i] = pIconsFrameTable->FindIcon(icon_name);
-		pIconsFrameTable->InitializeAnimation(pIconIDs_Turn[i]);
-	}
-
-	uIconID_TurnStop = pIconsFrameTable->FindIcon("turnstop");
-	uIconID_TurnHour = pIconsFrameTable->FindIcon("turnhour");
-	uIconID_TurnStart = pIconsFrameTable->FindIcon("turnstart");
-	uIconID_CharacterFrame = pIconsFrameTable->FindIcon("aframe1");
-	uSpriteID_Spell11 = pSpriteFrameTable->FastFindSprite("spell11");
-
-	pIconsFrameTable->InitializeAnimation(uIconID_TurnHour);
-	pIconsFrameTable->InitializeAnimation(uIconID_TurnStop);
-	pIconsFrameTable->InitializeAnimation(uIconID_TurnStart);
-	pIconsFrameTable->InitializeAnimation(uIconID_CharacterFrame);
-}
-
-//----- (00466C40) --------------------------------------------------------
-const wchar_t *MENU_STATE_to_string(MENU_STATE m)
-{
-	switch (m)
-	{
-	case -1:                return L"-1";
-	case MENU_MAIN:         return L"MENU_MAIN";
-	case MENU_NEWGAME:      return L"MENU_NEWGAME";
-	case MENU_CREDITS:      return L"MENU_CREDITS";
-	case MENU_SAVELOAD:     return L"MENU_SAVELOAD";
-	case MENU_EXIT_GAME:    return L"MENU_EXIT_GAME";
-	case MENU_5:            return L"MENU_5";
-	case MENU_CREATEPARTY:  return L"MENU_CREATEPARTY";
-	case MENU_NAMEPANELESC: return L"MENU_NAMEPANELESC";
-	case MENU_CREDITSPROC:  return L"MENU_CREDITSPROC";
-	case MENU_LoadingProcInMainMenu: return L"MENU_LoadingProcInMainMenu";
-	case MENU_DebugBLVLevel:           return L"MENU_DebugBLVLevel";
-	case MENU_CREDITSCLOSE: return L"MENU_CREDITSCLOSE";
-	case MENU_MMT_MAIN_MENU: return L"MENU_MMT_MAIN_MENU";
-	default:                return L"unk";
-	};
-};
-void SetCurrentMenuID(MENU_STATE uMenu)
-{
-	sCurrentMenuID = uMenu;
-
-	Log::Warning(L"CurrentMenu = %s \n", MENU_STATE_to_string(uMenu));
-}
-
-//----- (00466CA0) --------------------------------------------------------
-MENU_STATE GetCurrentMenuID()
-{
-	return sCurrentMenuID;
-}
-
-//----- (0046BDA8) --------------------------------------------------------
-unsigned int  GetGravityStrength()
-{
-	int v0; // eax@1
-
-	v0 = ~LOBYTE(pGame->uFlags2) & 8;
-	LOBYTE(v0) = v0 | 2;
-	return (unsigned int)v0 >> 1;
-}
-
-//----- (00448B45) --------------------------------------------------------
-void  GameUI_StatusBar_UpdateTimedString(unsigned int bForceHide)
-{
-	if (bForceHide || GameUI_Footer_TimeLeft && GetTickCount() >= GameUI_Footer_TimeLeft)
-		GameUI_Footer_TimeLeft = 0;
-}
-
-//----- (0044861E) --------------------------------------------------------
-void __fastcall sub_44861E_set_texture(unsigned int uFaceCog, const char *pFilename)
-{
-	unsigned int texture; // eax@2
-
-	if (uFaceCog)
-	{
-		texture = pBitmaps_LOD->LoadTexture(pFilename);
-		if (texture != -1 ? (int)&pBitmaps_LOD->pTextures[texture] : 0)
-		{
-			pBitmaps_LOD->pTextures[texture].palette_id2 = pPaletteManager->LoadPalette(pBitmaps_LOD->pTextures[texture].palette_id1);
-
-			if (uCurrentlyLoadedLevelType == 1)
-			{
-				if ((signed int)pIndoor->uNumFaceExtras > 1)
-				{
-					for (uint i = 1; i < (signed int)pIndoor->uNumFaceExtras; ++i)
-					{
-						if (pIndoor->pFaceExtras[i].sCogNumber == uFaceCog)
-						{
-							if (pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uAttributes & FACE_TEXTURE_FRAME)
-							{
-								pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uBitmapID = pTextureFrameTable->FindTextureByName(pFilename);
-								if (pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uBitmapID)
-								{
-									pTextureFrameTable->LoadAnimationSequenceAndPalettes(pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uBitmapID);
-								}
-								else
-								{
-									pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uBitmapID = texture;
-									pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uAttributes &= 0xFFFFBFFF;
-								}
-							}
-							else
-							{
-								pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uBitmapID = texture;
-							}
-						}
-					}
-				}
-				pParty->uFlags |= 2;
-			}
-			else
-			{
-				for (uint j = 0; j < (unsigned int)pOutdoor->uNumBModels; ++j)
-				{
-					for (uint i = 0; i < pOutdoor->pBModels[j].uNumFaces; ++i)
-					{
-						if (pOutdoor->pBModels[j].pFaces[i].sCogNumber == uFaceCog)
-						{
-							if (pOutdoor->pBModels[j].pFaces[i].uAttributes & FACE_TEXTURE_FRAME)
-							{
-								pOutdoor->pBModels[j].pFaces[i].uTextureID = pTextureFrameTable->FindTextureByName(pFilename);
-								if (pOutdoor->pBModels[j].pFaces[i].uTextureID)
-									pTextureFrameTable->LoadAnimationSequenceAndPalettes(pOutdoor->pBModels[j].pFaces[i].uTextureID);
-								else
-								{
-									pOutdoor->pBModels[j].pFaces[i].uTextureID = texture;
-									pOutdoor->pBModels[j].pFaces[i].uAttributes &= 0xFFFFBFFF;
-								}
-							}
-							else
-								pOutdoor->pBModels[j].pFaces[i].uTextureID = texture;
-						}
-					}
-				}
-			}
-			pParty->uFlags |= 2;
-		}
-	}
-}
-
-//----- (0044892E) --------------------------------------------------------
-void __fastcall sub_44892E_set_faces_bit(int sCogNumber, int bit, int on)
-{
-	if (sCogNumber)
-	{
-		if (uCurrentlyLoadedLevelType == 1)
-		{
-			for (uint i = 1; i < (unsigned int)pIndoor->uNumFaceExtras; ++i)
-			{
-				if (pIndoor->pFaceExtras[i].sCogNumber == sCogNumber)
-				{
-					if (on)
-						pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uAttributes |= bit;
-					else
-						pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uAttributes &= ~bit;
-				}
-			}
-			pParty->uFlags |= 2;
-		}
-		else
-		{
-			for (uint j = 0; j < (unsigned int)pOutdoor->uNumBModels; ++j)
-			{
-				for (uint i = 0; i < (unsigned int)pOutdoor->pBModels[j].uNumFaces; ++i)
-				{
-					if (pOutdoor->pBModels[j].pFaces[i].sCogNumber == sCogNumber)
-					{
-						if (on)
-							pOutdoor->pBModels[j].pFaces[i].uAttributes |= bit;
-						else
-							pOutdoor->pBModels[j].pFaces[i].uAttributes &= ~bit;
-					}
-				}
-			}
-		}
-		pParty->uFlags |= 2;
-	}
-}
-
-//----- (0044882F) --------------------------------------------------------
-void __fastcall SetDecorationSprite(uint16_t uCog, bool bHide, const char *pFileName)
-{
-	for (size_t i = 0; i < uNumLevelDecorations; i++)
-	{
-		if (pLevelDecorations[i].uCog == uCog)
-		{
-			if (pFileName && strcmp(pFileName, "0"))
-			{
-				pLevelDecorations[i].uDecorationDescID = pDecorationList->GetDecorIdByName(pFileName);
-				pDecorationList->InitializeDecorationSprite(pLevelDecorations[i].uDecorationDescID);
-			}
-
-			if (bHide)
-				pLevelDecorations[i].uFlags &= ~LEVEL_DECORATION_INVISIBLE;
-			else
-				pLevelDecorations[i].uFlags |= LEVEL_DECORATION_INVISIBLE;
-
-			pParty->uFlags |= 2;
-		}
-	}
-}
-
-//----- (004356FF) --------------------------------------------------------
-void back_to_game()
-{
-	dword_507BF0_is_there_popup_onscreen = 0;
-	dword_4E455C = 1;
-
-	extern int no_rightlick_in_inventory;
-	no_rightlick_in_inventory = false;
-
-	if (pGUIWindow_ScrollWindow)
-		free_book_subwindow();
-	if (!pCurrentScreen && !pGUIWindow_Settings)
-		pEventTimer->Resume();
-	viewparams->bRedrawGameUI = 1;
-}
-
-//----- (00494035) --------------------------------------------------------
-void _494035_timed_effects__water_walking_damage__etc()
-{
-	signed __int64 v0; // qax@1
-	unsigned int v4; // edi@1
-	//  signed int v12; // edi@29
-	int v24; // ecx@60
-	int v26; // ecx@64
-	int v28; // ecx@68
-	int v30; // ecx@72
-	int v32; // ecx@76
-	int v34; // ecx@80
-	int v36; // ecx@84
-	int v38; // ecx@88
-	int v40; // ecx@92
-	int v42; // ecx@96
-	bool v43; // ebx@102
-	bool v46; // edi@111
-	//  unsigned int v56; // [sp-8h] [bp-38h]@55
-	//  int v59; // [sp-4h] [bp-34h]@55
-	//  unsigned int v61; // [sp+14h] [bp-1Ch]@1
-	signed int a2a; // [sp+18h] [bp-18h]@47
-	signed int old_day; // [sp+1Ch] [bp-14h]@47
-	signed int old_hour;
-
-	old_day = pParty->uDaysPlayed;
-	old_hour = pParty->uCurrentHour;
-	//auto prev_time = pEventTimer->uTimeElapsed;
-	pParty->uTimePlayed += pEventTimer->uTimeElapsed;
-	v0 = ((signed __int64)(pParty->uTimePlayed * 0.234375) / 60) / 60i64;
-	v4 = (unsigned int)(((unsigned int)v0 / 24) / 7) >> 2;
-	pParty->uCurrentTimeSecond = (signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) % 60;
-	pParty->uCurrentMinute = ((signed __int64)(pParty->uTimePlayed * 0.234375) / 60) % 60;
-	pParty->uCurrentHour = v0 % 24;
-	pParty->uCurrentMonthWeek = ((unsigned int)v0 / 24) / 7 & 3;
-	pParty->uDaysPlayed = (unsigned int)((unsigned int)v0 / 24) % 28;
-	pParty->uCurrentMonth = v4 % 12;
-	pParty->uCurrentYear = v4 / 0xC + game_starting_year;
-	if (pParty->uCurrentHour >= 3 && (old_hour < 3 || pParty->uDaysPlayed > old_day)) // new day dawns
-	{
-		pParty->pHirelings[0].bHasUsedTheAbility = false;
-		pParty->pHirelings[1].bHasUsedTheAbility = false;
-
-		for (uint i = 0; i < pNPCStats->uNumNewNPCs; ++i)
-			pNPCStats->pNewNPCData[i].bHasUsedTheAbility = false;
-
-		++pParty->days_played_without_rest;
-		if (pParty->days_played_without_rest > 1)
-		{
-			for (uint i = 0; i < 4; ++i)
-				pParty->pPlayers[i].SetCondWeakWithBlockCheck(0);
-
-			if (pParty->uNumFoodRations)
-				Party::TakeFood(1);
-			else
-			for (uint i = 0; i < 4; ++i)
-				pParty->pPlayers[i].sHealth = pParty->pPlayers[i].sHealth / (pParty->days_played_without_rest + 1) + 1;
-
-			if (pParty->days_played_without_rest > 3)
-			for (uint i = 0; i < 4; ++i)
-			{
-				pParty->pPlayers[i].Zero();
-				if (!pParty->pPlayers[i].IsPertified() && !pParty->pPlayers[i].IsEradicated()
-					&& !pParty->pPlayers[i].IsDead())
-				{
-					if (rand() % 100 < 5 * pParty->days_played_without_rest)
-						pParty->pPlayers[i].SetCondDeadWithBlockCheck(0);
-					if (rand() % 100 < 10 * pParty->days_played_without_rest)
-						pParty->pPlayers[i].SetCondInsaneWithBlockCheck(0);
-				}
-			}
-		}
-		if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
-			pOutdoor->SetFog();
-
-		for (uint i = 0; i < 4; ++i)
-			pParty->pPlayers[i].uNumDivineInterventionCastsThisDay = 0;
-	}
-
-	if (pParty->uFlags & 4 && pParty->field_6FC < (signed __int64)pParty->uTimePlayed)//water damage
-	{
-		pParty->field_6FC = (signed __int64)pParty->uTimePlayed + 128;
-		viewparams->bRedrawGameUI = true;
-		for (uint pl = 1; pl <= 4; ++pl)
-		{
-			if (pPlayers[pl]->WearsItem(ITEM_RELIC_HARECS_LEATHER, EQUIP_ARMOUR)
-				|| pPlayers[pl]->HasEnchantedItemEquipped(71)
-				|| pPlayers[pl]->pPlayerBuffs[PLAYER_BUFF_WATER_WALK].uExpireTime > 0)
-				pPlayers[pl]->PlayEmotion(CHARACTER_EXPRESSION_37, 0);
-			else
-			{
-				if (!pPlayers[pl]->HasUnderwaterSuitEquipped())
-				{
-					pPlayers[pl]->ReceiveDamage((signed __int64)pPlayers[pl]->GetMaxHealth() * 0.1, DMGT_FIRE);
-					if (pParty->uFlags & 4)
-					{
-						strcpy(GameUI_Footer_TimedString.data(), pGlobalTXT_LocalizationStrings[660]);// Âû òîíåòå!
-						GameUI_Footer_TimeLeft = 128;
-					}
-				}
-				else
-					pPlayers[pl]->PlayEmotion(CHARACTER_EXPRESSION_37, 0);
-			}
-		}
-	}
-	if (pParty->uFlags & 0x200 && pParty->field_6FC < (signed __int64)pParty->uTimePlayed) //lava damage
-	{
-		viewparams->bRedrawGameUI = true;
-		pParty->field_6FC = (signed __int64)pParty->uTimePlayed + 128;
-
-		for (uint pl = 1; pl <= 4; pl++)
-		{
-			pPlayers[pl]->ReceiveDamage((signed __int64)pPlayers[pl]->GetMaxHealth() * 0.1, DMGT_FIRE);
-			if (pParty->uFlags & 0x200)
-			{
-				strcpy(GameUI_Footer_TimedString.data(), pGlobalTXT_LocalizationStrings[661]); //Âû ãîðèòå!
-				GameUI_Footer_TimeLeft = 128;
-			}
-		}
-	}
-	_493938_regenerate();
-	uint party_condition_flag = 4;
-	a2a = pEventTimer->uTimeElapsed;
-	if (pParty->uFlags2 & PARTY_FLAGS_2_RUNNING)//çàìåäëåíèå âîññòàíîâëåíèÿ ïðè áåãå
-	{
-		a2a *= 0.5f;
-		if (a2a < 1)
-			a2a = 1;
-	}
-
-	for (uint pl = 1; pl <= 4; pl++)
-	{
-		if (pPlayers[pl]->uTimeToRecovery)
-			pPlayers[pl]->Recover(a2a);//âîññòàíîâëåíèå àêòèâíîñòè
-		if (pPlayers[pl]->GetItemsBonus(CHARACTER_ATTRIBUTE_ENDURANCE) + pPlayers[pl]->sHealth + pPlayers[pl]->uEndurance >= 1
-			|| (signed __int64)pPlayers[pl]->pPlayerBuffs[PLAYER_BUFF_PRESERVATION].uExpireTime > 0)
-		{
-			if (pPlayers[pl]->sHealth < 1)
-				pPlayers[pl]->SetCondition(Condition_Unconcious, 0);
-		}
-		else
-			pPlayers[pl]->SetCondition(Condition_Dead, 0);
-		if (pPlayers[pl]->field_E0)
-		{
-			v24 = pPlayers[pl]->field_E0 - pEventTimer->uTimeElapsed;
-			if (v24 > 0)
-				pPlayers[pl]->field_E0 = v24;
-			else
-			{
-				pPlayers[pl]->field_E0 = 0;
-				viewparams->bRedrawGameUI = true;
-			}
-		}
-		if (pPlayers[pl]->field_E4)
-		{
-			v26 = pPlayers[pl]->field_E4 - pEventTimer->uTimeElapsed;
-			if (v26 > 0)
-				pPlayers[pl]->field_E4 = v26;
-			else
-			{
-				pPlayers[pl]->field_E4 = 0;
-				viewparams->bRedrawGameUI = true;
-			}
-		}
-		if (pPlayers[pl]->field_E8)
-		{
-			v28 = pPlayers[pl]->field_E8 - pEventTimer->uTimeElapsed;
-			if (v28 > 0)
-				pPlayers[pl]->field_E8 = v28;
-			else
-			{
-				pPlayers[pl]->field_E8 = 0;
-				viewparams->bRedrawGameUI = true;
-			}
-		}
-		if (pPlayers[pl]->field_EC)
-		{
-			v30 = pPlayers[pl]->field_EC - pEventTimer->uTimeElapsed;
-			if (v30 > 0)
-				pPlayers[pl]->field_EC = v30;
-			else
-			{
-				pPlayers[pl]->field_EC = 0;
-				viewparams->bRedrawGameUI = true;
-			}
-		}
-		if (pPlayers[pl]->field_F0)
-		{
-			v32 = pPlayers[pl]->field_F0 - pEventTimer->uTimeElapsed;
-			if (v32 > 0)
-				pPlayers[pl]->field_F0 = v32;
-			else
-			{
-				pPlayers[pl]->field_F0 = 0;
-				viewparams->bRedrawGameUI = true;
-			}
-		}
-		if (pPlayers[pl]->field_F4)
-		{
-			v34 = pPlayers[pl]->field_F4 - pEventTimer->uTimeElapsed;
-			if (v34 > 0)
-				pPlayers[pl]->field_F4 = v34;
-			else
-			{
-				pPlayers[pl]->field_F4 = 0;
-				viewparams->bRedrawGameUI = true;
-			}
-		}
-		if (pPlayers[pl]->field_F8)
-		{
-			v36 = pPlayers[pl]->field_F8 - pEventTimer->uTimeElapsed;
-			if (v36 > 0)
-				pPlayers[pl]->field_F8 = v36;
-			else
-			{
-				pPlayers[pl]->field_F8 = 0;
-				viewparams->bRedrawGameUI = true;
-			}
-		}
-		if (pPlayers[pl]->field_FC)
-		{
-			v38 = pPlayers[pl]->field_FC - pEventTimer->uTimeElapsed;
-			if (v38 > 0)
-				pPlayers[pl]->field_FC = v38;
-			else
-			{
-				pPlayers[pl]->field_FC = 0;
-				viewparams->bRedrawGameUI = true;
-			}
-		}
-		if (pPlayers[pl]->field_100)
-		{
-			v40 = pPlayers[pl]->field_100 - pEventTimer->uTimeElapsed;
-			if (v40 > 0)
-				pPlayers[pl]->field_100 = v40;
-			else
-			{
-				pPlayers[pl]->field_100 = 0;
-				viewparams->bRedrawGameUI = true;
-			}
-		}
-		if (pPlayers[pl]->field_104)
-		{
-			v42 = pPlayers[pl]->field_104 - pEventTimer->uTimeElapsed;
-			if (v42 > 0)
-				pPlayers[pl]->field_104 = v42;
-			else
-			{
-				pPlayers[pl]->field_104 = 0;
-				viewparams->bRedrawGameUI = true;
-			}
-		}
-		if (pPlayers[pl]->pConditions[Condition_Sleep] | pPlayers[pl]->pConditions[Condition_Paralyzed]
-			| pPlayers[pl]->pConditions[Condition_Unconcious] | pPlayers[pl]->pConditions[Condition_Dead]
-			| pPlayers[pl]->pConditions[Condition_Pertified] | pPlayers[pl]->pConditions[Condition_Eradicated])
-			--party_condition_flag;
-		v43 = (signed __int64)pPlayers[pl]->pPlayerBuffs[PLAYER_BUFF_HASTE].uExpireTime > 0; //ñïåøêà
-
-		for (uint k = 0; k < 24; ++k)
-			pPlayers[pl]->pPlayerBuffs[k].IsBuffExpiredToTime(pParty->uTimePlayed);
-
-		if (v43 && (signed __int64)pPlayers[pl]->pPlayerBuffs[7].uExpireTime <= 0)
-			pPlayers[pl]->SetCondition(Condition_Weak, 0);
-	}
-
-	v46 = (signed __int64)pParty->pPartyBuffs[PARTY_BUFF_HASTE].uExpireTime > 0;
-
-	for (uint i = 0; i < 20; ++i)
-	{
-		if (pParty->pPartyBuffs[i].IsBuffExpiredToTime(pParty->uTimePlayed) == 1)
-			viewparams->bRedrawGameUI = true;
-	}
-
-	if (v46 && (signed __int64)pParty->pPartyBuffs[PARTY_BUFF_HASTE].uExpireTime <= 0)
-	{
-		for (uint i = 0; i < 4; ++i)
-			pParty->pPlayers[i].SetCondition(1, 0);
-	}
-
-	for (uint i = 0; i < 2; ++i)//Ïðîâåðêà â ñîçíàíèè ëè ïåðñ ñäåëàâøèé çàêë íà ïîë¸ò è õîæäåíèå ïî âîäå
-	{
-		SpellBuff* pBuf = &pParty->pPartyBuffs[Party_Spec_Motion_status_ids[i]];
-		if (pBuf->uExpireTime == 0)
-			continue;
-
-		if (!(pBuf->uFlags & 1))
-		{
-			if (!pPlayers[pBuf->uCaster]->CanAct())
-			{
-				pBuf->Reset();
-				if (Party_Spec_Motion_status_ids[i] == PARTY_BUFF_FLY)
-					pParty->bFlying = false;
-			}
-		}
-	}
-
-	if (!party_condition_flag)
-	{
-		if (pCurrentScreen != SCREEN_REST)
-		{
-			for (uint pl = 1; pl <= 4; pl++)
-			{
-				if (pPlayers[pl]->pConditions[Condition_Sleep])
-				{
-					pPlayers[pl]->pConditions[Condition_Sleep] = 0;
-					party_condition_flag = 1;
-					break;
-				}
-			}
-			if (!party_condition_flag || _5C35C0_force_party_death)
-				uGameState = GAME_STATE_PARTY_DIED;
-		}
-	}
-
-	if (uActiveCharacter)//âûáîð ñëåäóþùåãî ïîñëå ïðîïóñêàþùåãî õîä
-	{
-		if (pCurrentScreen != SCREEN_REST)
-		{
-			if (pPlayers[uActiveCharacter]->pConditions[Condition_Sleep]
-				|| pPlayers[uActiveCharacter]->pConditions[Condition_Paralyzed]
-				|| pPlayers[uActiveCharacter]->pConditions[Condition_Unconcious]
-				|| pPlayers[uActiveCharacter]->pConditions[Condition_Dead]
-				|| pPlayers[uActiveCharacter]->pConditions[Condition_Pertified]
-				|| pPlayers[uActiveCharacter]->pConditions[Condition_Eradicated])
-			{
-				viewparams->bRedrawGameUI = true;
-				uActiveCharacter = pParty->GetNextActiveCharacter();
-			}
-		}
-	}
-}
-
-//----- (00493938) --------------------------------------------------------
-void _493938_regenerate()
-{
-	int current_time; // edi@1
-	int last_reg_time; // qax@1
-	int v4; // eax@2
-	int v5; // edi@5
-	long long *v6; // ecx@5
-	char v7; // sf@5
-	int *v8; // ecx@10
-	int v9; // edi@15
-	signed int v10; // eax@15
-	//  __int16 *v11; // edx@16
-	//  int v12; // eax@20
-	int numberOfActorsAffected; // ebx@20
-	unsigned int v14; // esi@21
-	//unsigned int v15; // ecx@21
-	//unsigned int v16; // eax@21
-	//  int v18; // eax@21
-	signed int v19; // eax@21
-	bool recovery_HP; // ebx@25
-	//  ITEM_EQUIP_TYPE v22; // edi@30
-	signed int v25; // eax@33
-	//  int v26; // eax@35
-	//  int v27; // eax@36
-	//  int v28; // eax@37
-	signed int v31; // ecx@53
-	int actorsAffectedByImmolation[100]; // [sp+4h] [bp-22Ch]@20
-	SpriteObject a1; // [sp+194h] [bp-9Ch]@15
-	Vec3_int_ a3; // [sp+204h] [bp-2Ch]@15
-	bool has_dragon_flag; // [sp+210h] [bp-20h]@22
-	bool lich_jar_flag; // [sp+214h] [bp-1Ch]@25
-	bool zombie_flag; // [sp+218h] [bp-18h]@25
-	bool decrease_HP; // [sp+21Ch] [bp-14h]@25
-	bool lich_flag; // [sp+220h] [bp-10h]@25
-	int v49; // [sp+224h] [bp-Ch]@24
-	bool recovery_SP; // [sp+228h] [bp-8h]@25
-	bool redraw_flag; // [sp+22Ch] [bp-4h]@2
-
-	current_time = (signed int)(signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) / 60;
-	last_reg_time = (signed int)(signed __int64)((double)pParty->uLastRegenerationTime * 0.234375) / 60;
-	if (current_time >= (signed int)last_reg_time + 5)
-	{
-		redraw_flag = false;
-		v4 = (current_time - last_reg_time) / 5;
-		if (pParty->FlyActive())
-		{
-			if (pParty->bFlying)
-			{
-				if (!(pParty->pPartyBuffs[PARTY_BUFF_FLY].uFlags & 1))
-				{
-					v5 = v4 * pParty->pPartyBuffs[PARTY_BUFF_FLY].uPower;
-					//cursed_flag = pParty->pPlayers[pParty->pPartyBuffs[PARTY_BUFF_FLY].uCaster - 1].pConditions[Condition_Cursed];//cursed
-					//v7 = cursed_flag < v5;
-					//cursed_flag -= v5;
-
-					v6 = &pParty->pPlayers[pParty->pPartyBuffs[PARTY_BUFF_FLY].uCaster - 1].pConditions[Condition_Cursed];
-
-					if (*v6 < v5)
-					{
-						v6 = 0;
-						pParty->uFlags &= 0xFFFFFFBFu;
-						pParty->bFlying = false;
-						redraw_flag = true;
-					}
-				}
-			}
-		}
-
-		if (pParty->WaterWalkActive())
-		{
-			if (pParty->uFlags & PARTY_FLAGS_1_STANDING_ON_WATER)
-			{
-				if (!(pParty->pPartyBuffs[PARTY_BUFF_WATER_WALK].uFlags & 1))
-				{ // taking on water
-					v8 = (int *)&pParty->pPlayers[pParty->pPartyBuffs[PARTY_BUFF_WATER_WALK].uCaster - 1].pConditions[Condition_Cursed];//&AA1058_PartyQuickSpellSound[4].pSounds[6972 * pParty->pPartyBuffs[PARTY_BUFF_WATER_WALK].uCaster + 2000];
-					v7 = *v8 < v4;
-					*v8 -= v4;
-					if (v7)
-					{
-						*v8 = 0;
-						pParty->uFlags &= ~PARTY_FLAGS_1_STANDING_ON_WATER;
-						redraw_flag = true;
-					}
-				}
-			}
-		}
-
-		if (pParty->ImmolationActive())//Æåðòâà
-		{
-			a3.z = 0;
-			a3.y = 0;
-			a3.x = 0;
-			a1.stru_24.Reset();
-			a1.spell_level = pParty->pPartyBuffs[PARTY_BUFF_IMMOLATION].uPower;
-			a1.spell_skill = pParty->ImmolationSkillLevel();
-			v10 = 0;
-			a1.uType = 1070;
-			a1.spell_id = SPELL_FIRE_IMMOLATION;
-			v10 = 0;
-			for (uint i = 0; i > pObjectList->uNumObjects; i++)
-			{
-				if (pObjectList->pObjects[i].uObjectID == stru_4E3ACC[8].uType)
-					v10 = i;
-			}
-			a1.uObjectDescID = v10;
-			a1.field_60_distance_related_prolly_lod = 0;
-			a1.uAttributes = 0;
-			a1.uSectorID = 0;
-			a1.uSpriteFrameID = 0;
-			a1.spell_caster_pid = PID(OBJECT_Player, pParty->pPartyBuffs[PARTY_BUFF_IMMOLATION].uCaster);
-			a1.uFacing = 0;
-			a1.uSoundID = 0;
-			numberOfActorsAffected = pParty->_46A89E_immolation_effect(actorsAffectedByImmolation, 100, 307);
-			for (v9 = 0; v9 < numberOfActorsAffected; ++v9)
-			{
-				v14 = actorsAffectedByImmolation[v9];
-				a1.vPosition.x = pActors[v14].vPosition.x;
-				a1.vPosition.y = pActors[v14].vPosition.y;
-				a1.vPosition.z = pActors[v14].vPosition.z;
-				a1.spell_target_pid = PID(OBJECT_Actor, v14);
-				v19 = a1.Create(0, 0, 0, 0);
-				Actor::DamageMonsterFromParty(PID(OBJECT_Item, v19), v14, &a3);
-			}
-		}
-
-		has_dragon_flag = false;
-		if (PartyHasDragon())
-			has_dragon_flag = true;
-
-		for (v49 = 0; v49 < 4; v49++)
-		{
-			recovery_HP = false;
-			recovery_SP = false;
-			decrease_HP = false;
-			lich_flag = false;
-			lich_jar_flag = false;
-			zombie_flag = false;
-
-			for (int v22 = 0; (signed int)v22 < 16; v22++)
-			{
-				if (pParty->pPlayers[v49].HasItemEquipped((ITEM_EQUIP_TYPE)v22))
-				{
-					uint _idx = pParty->pPlayers[v49].pEquipment.pIndices[v22];
-					if (pParty->pPlayers[v49].pInventoryItemList[_idx - 1].uItemID > 134)
-					{
-						if (pParty->pPlayers[v49].pInventoryItemList[_idx - 1].uItemID == ITEM_RELIC_ETHRICS_STAFF)
-							decrease_HP = true;
-						if (pParty->pPlayers[v49].pInventoryItemList[_idx - 1].uItemID == ITEM_ARTIFACT_HERMES_SANDALS)
-						{
-							recovery_HP = true;
-							recovery_SP = true;
-						}
-						if (pParty->pPlayers[v49].pInventoryItemList[_idx - 1].uItemID == ITEM_ARTIFACT_MINDS_EYE)
-							recovery_SP = true;
-						if (pParty->pPlayers[v49].pInventoryItemList[_idx - 1].uItemID == ITEM_ARTIFACT_HEROS_BELT)
-							recovery_HP = true;
-					}
-					else
-					{
-						v25 = pParty->pPlayers[v49].pInventoryItemList[_idx - 1].uSpecEnchantmentType;
-						if (v25 == 37 //of Regeneration("Regenerate 1hp/x while walking, etc")
-							|| v25 == 44 //of Life("HP (+10), Regen hpts")
-							|| v25 == 50 //of The Phoenix("Fire Res (+30), Regen hpts") && 
-							|| v25 == 54)// of The Troll("End (+15), Regen hpts")
-							recovery_HP = true;
-						if (v25 == 38 //of Mana("Regenerate 1sp/x while walking, etc")
-							|| v25 == 47 //of The Eclipse("SP (+10), Regen spts")
-							|| v25 == 55)//of The Unicorn("Luck (+15), Regen spts")
-							recovery_SP = true;
-						if (v25 == 66)// of Plenty("Regenerate 1 hp/x and 1 sp/x while walking, etc.")
-						{
-							recovery_HP = true;
-							recovery_SP = true;
-						}
-					}
-
-					if (recovery_HP &&
-						!pParty->pPlayers[v49].pConditions[Condition_Dead] &&
-						!pParty->pPlayers[v49].pConditions[Condition_Eradicated])
-					{
-						if (pParty->pPlayers[v49].sHealth < pParty->pPlayers[v49].GetMaxHealth())
-							++pParty->pPlayers[v49].sHealth;
-						if (pParty->pPlayers[v49].pConditions[Condition_Unconcious] && pParty->pPlayers[v49].sHealth > 0)
-							pParty->pPlayers[v49].pConditions[Condition_Unconcious] = 0;
-						redraw_flag = true;
-					}
-
-					if (recovery_SP &&
-						!pParty->pPlayers[v49].pConditions[Condition_Dead] &&
-						!pParty->pPlayers[v49].pConditions[Condition_Eradicated])
-					{
-						if (pParty->pPlayers[v49].sMana < pParty->pPlayers[v49].GetMaxMana())
-							++pParty->pPlayers[v49].sMana;
-						redraw_flag = true;
-					}
-
-					if (decrease_HP &&
-						!pParty->pPlayers[v49].pConditions[Condition_Dead] &&
-						!pParty->pPlayers[v49].pConditions[Condition_Eradicated])
-					{
-						--pParty->pPlayers[v49].sHealth;
-						if (!(pParty->pPlayers[v49].pConditions[Condition_Unconcious]) && pParty->pPlayers[v49].sHealth < 0)
-							pParty->pPlayers[v49].pConditions[Condition_Unconcious] = pParty->uTimePlayed;
-						if (pParty->pPlayers[v49].sHealth < 1)
-						{
-							if (pParty->pPlayers[v49].sHealth + pParty->pPlayers[v49].uEndurance + pParty->pPlayers[v49].GetItemsBonus(CHARACTER_ATTRIBUTE_ENDURANCE) >= 1
-								|| (signed __int64)pParty->pPlayers[v49].pPlayerBuffs[PLAYER_BUFF_PRESERVATION].uExpireTime > 0)
-								pParty->pPlayers[v49].pConditions[Condition_Unconcious] = pParty->uTimePlayed;
-							else
-							{
-								if (!pParty->pPlayers[v49].pConditions[Condition_Dead])
-									pParty->pPlayers[v49].pConditions[Condition_Dead] = pParty->uTimePlayed;
-							}
-						}
-						redraw_flag = true;
-					}
-				}
-			}
-
-			//regeneration
-			if (pParty->pPlayers[v49].pPlayerBuffs[PLAYER_BUFF_REGENERATION].uExpireTime > 0
-				&& !pParty->pPlayers[v49].pConditions[Condition_Dead]
-				&& !pParty->pPlayers[v49].pConditions[Condition_Eradicated])
-			{
-				pParty->pPlayers[v49].sHealth += 5 * pParty->pPlayers[v49].pPlayerBuffs[PLAYER_BUFF_REGENERATION].uPower;
-				if (pParty->pPlayers[v49].sHealth > pParty->pPlayers[v49].GetMaxHealth())
-					pParty->pPlayers[v49].sHealth = pParty->pPlayers[v49].GetMaxHealth();
-				if (pParty->pPlayers[v49].pConditions[Condition_Unconcious] && pParty->pPlayers[v49].sHealth > 0)
-					pParty->pPlayers[v49].pConditions[Condition_Unconcious] = 0;
-				redraw_flag = true;
-			}
-
-			//for warlock
-			if (has_dragon_flag && pParty->pPlayers[v49].classType == PLAYER_CLASS_WARLOCK)
-			{
-				if (pParty->pPlayers[v49].sMana < pParty->pPlayers[v49].GetMaxMana())
-					++pParty->pPlayers[v49].sMana;
-				redraw_flag = true;
-			}
-
-			//for lich
-			if (pParty->pPlayers[v49].classType == PLAYER_CLASS_LICH)
-			{
-				for (v31 = 0; v31 < 126; ++v31)
-				{
-					if (pParty->pPlayers[v49].pInventoryItemList[v31].uItemID == ITEM_LICH_JAR_FULL)
-						lich_jar_flag = true;
-				}
-				lich_flag = true;
-			}
-			if (lich_flag && !pParty->pPlayers[v49].pConditions[Condition_Dead]
-				&& !pParty->pPlayers[v49].pConditions[Condition_Eradicated])
-			{
-				if (pParty->pPlayers[v49].sHealth > pParty->pPlayers[v49].GetMaxHealth() / 2)
-					pParty->pPlayers[v49].sHealth = pParty->pPlayers[v49].sHealth - 2;
-				if (pParty->pPlayers[v49].sMana > pParty->pPlayers[v49].GetMaxMana() / 2)
-					pParty->pPlayers[v49].sMana = pParty->pPlayers[v49].sMana - 2;
-			}
-			if (lich_jar_flag)
-			{
-				if (pParty->pPlayers[v49].sMana < pParty->pPlayers[v49].GetMaxMana())
-					++pParty->pPlayers[v49].sMana;
-			}
-
-			//for zombie
-			if (pParty->pPlayers[v49].pConditions[Condition_Zombie])
-				zombie_flag = true;
-			if (zombie_flag && !pParty->pPlayers[v49].pConditions[Condition_Dead]
-				&& !pParty->pPlayers[v49].pConditions[Condition_Eradicated])
-			{
-				if (pParty->pPlayers[v49].sHealth > pParty->pPlayers[v49].GetMaxHealth() / 2)
-					pParty->pPlayers[v49].sHealth = pParty->pPlayers[v49].sHealth - 1;
-				if (pParty->pPlayers[v49].sMana > 0)
-					pParty->pPlayers[v49].sMana = pParty->pPlayers[v49].sMana - 1;
-			}
-		}
-		pParty->uLastRegenerationTime = pParty->uTimePlayed;
-		if (!viewparams->bRedrawGameUI)
-			viewparams->bRedrawGameUI = redraw_flag;
-	}
-}
-
-//----- (00491E3A) --------------------------------------------------------
-void sub_491E3A()
-{
-	signed int v1; // esi@3
-	unsigned int v3; // eax@7
-	unsigned int v4; // edx@8
-	int v6; // edi@17
-
-	//__debugbreak();//Ritor1
-	for (uint pl = 0; pl < 4; pl++)
-	{
-		if (SoundSetAction[24][0])
-		{
-			v3 = 0;
-			for (v1 = 0; v1 < (signed int)pSoundList->sNumSounds; ++v1)
-			{
-				int ps = 2 * (SoundSetAction[24][0] + 50 * pParty->pPlayers[pl].uVoiceID) + 4998;//6728
-				if (pSoundList->pSL_Sounds[v1].uSoundID == 2 * (SoundSetAction[24][0] + 50 * pParty->pPlayers[pl].uVoiceID) + 4998)
-					v3 = v1;
-			}
-			pSoundList->UnloadSound(v3, 1);
-			for (v4 = 0; (signed int)v4 < (signed int)pSoundList->sNumSounds; ++v4)
-			{
-				if (pSoundList->pSL_Sounds[v4].uSoundID == 2 * (SoundSetAction[24][0] + 50 * pParty->pPlayers[pl].uVoiceID) + 4999)
-					pSoundList->UnloadSound(v4, 1);
-			}
-		}
-	}
-	v6 = pIcons_LOD->uNumLoadedFiles - 1;
-	if (v6 >= pIcons_LOD->pFacesLock)
-	{
-		do
-		{
-			pIcons_LOD->pTextures[v6].Release();
-			if (pIcons_LOD->pHardwareTextures)
-			{
-				if (pIcons_LOD->pHardwareTextures[v6])
-				{
-					pIcons_LOD->pHardwareTextures[v6]->Release();
-					pIcons_LOD->pHardwareTextures[v6] = 0;
-				}
-			}
-			if (pIcons_LOD->pHardwareSurfaces)
-			{
-				if (pIcons_LOD->pHardwareSurfaces[v6])
-				{
-					pIcons_LOD->pHardwareSurfaces[v6]->Release();
-					pIcons_LOD->pHardwareSurfaces[v6] = 0;
-				}
-			}
-			--v6;
-		} while (v6 >= pIcons_LOD->pFacesLock);
-	}
-	pIcons_LOD->uNumLoadedFiles = pIcons_LOD->pFacesLock;
-	pIcons_LOD->pFacesLock = 0;
-}
-// 4ED498: using guessed type char byte_4ED498;
-
-//----- (00494820) --------------------------------------------------------
-unsigned int __fastcall _494820_training_time(unsigned int a1)
-{
-	signed int v1; // eax@1
-
-	v1 = 5;
-	if (a1 % 24 >= 5)
-		v1 = 29;
-	return v1 - a1 % 24;
-}
-
-//----- (00494836) --------------------------------------------------------
-int stru339_spell_sound::AddPartySpellSound(int uSoundID, int a6)
-{
-	int v3; // esi@1
-	int result; // eax@1
-	//stru339_spell_sound *v5; // ebx@1
-	//int *v6; // edi@2
-	unsigned int v7; // eax@3
-	int v8; // [sp+Ch] [bp-8h]@3
-	int v9; // [sp+10h] [bp-4h]@2
-	int a2a; // [sp+1Ch] [bp+8h]@1
-	//return 0;
-	v3 = 0;
-	result = word_4EE088_sound_ids[uSoundID];
-	//v5 = this;
-	a2a = word_4EE088_sound_ids[uSoundID];
-	if (word_4EE088_sound_ids[uSoundID])
-	{
-		//v6 = this->pSoundsOffsets;
-		for (v9 = 0; v9 < 2; ++v9)
-		{
-			v7 = a2a++;
-			result = pSoundList->LoadSound(v7, (char *)this + v3, 44744 - v3, &v8, a6);
-			if (!result)
-				break;
-			a6 += 4;
-			result = v8 + 256;
-			this->pSoundsOffsets[v9] = v3;
-			v3 += result;
-			this->pSoundsSizes[v9] = v8 + 256;
-			//++v6;
-		}
-	}
-	return result;
-}
-// 4EE088: using guessed type __int16 word_4EE088_sound_ids[];
-
-//----- (00443E31) --------------------------------------------------------
-void LoadLevel_InitializeLevelStr()
-{
-
-	//  char Args[100]; 
-	int string_num;
-	int max_string_length;
-	//  int current_string_length;
-	int prev_string_offset;
-
-	if (sizeof(pLevelStrOffsets) != 2000)
-		Log::Warning(L"pLevelStrOffsets: deserialization warning");
-	memset(pLevelStrOffsets.data(), 0, 2000);
-
-	max_string_length = 0;
-	string_num = 1;
-	prev_string_offset = 0;
-	pLevelStrOffsets[0] = 0;
-	for (uint i = 0; i < uLevelStrFileSize; ++i)
-	{
-		if (!pLevelStr[i])
-		{
-			pLevelStrOffsets[string_num] = i + 1;
-			++string_num;
-			if (i - prev_string_offset > max_string_length)
-				max_string_length = i - prev_string_offset;
-			prev_string_offset = i;
-		}
-	}
-
-	uLevelStrNumStrings = string_num - 1;
-	if (max_string_length > 800)
-		Error("MAX_EVENT_TEXT_LENGTH needs to be increased to %lu", max_string_length + 1);
-
-	if (uLevelStrNumStrings > 0)
-	{
-		for (uint i = 0; i <uLevelStrNumStrings; ++i)
-		{
-			if (RemoveQuotes(&pLevelStr[pLevelStrOffsets[i]]) != &pLevelStr[pLevelStrOffsets[i]])
-				++pLevelStrOffsets[i];
-		}
-	}
-}
-
-//----- (00443F95) --------------------------------------------------------
-void  OnMapLeave()
-{
-	_evt_raw *test_event;
-	if (uLevelEVT_NumEvents > 0)
-	{
-		for (uint i = 0; i < uLevelEVT_NumEvents; ++i)
-		{
-			test_event = (_evt_raw*)&pLevelEVT[pLevelEVT_Index[i].uEventOffsetInEVT];
-			if (test_event->_e_type == EVENT_OnMapLeave)
-			{
-				EventProcessor(pLevelEVT_Index[i].uEventID, 0, 1, pLevelEVT_Index[i].event_sequence_num);
-			}
-		}
-	}
-}
-
-//----- (00443FDC) --------------------------------------------------------
-void OnMapLoad()
-{
-	int v6; // eax@9
-	unsigned __int64 v8; // qax@26
-	int hours; // ebx@26
-	unsigned __int64 v18; // [sp+Ch] [bp-44h]@12
-	unsigned int seconds; // [sp+14h] [bp-3Ch]@26
-	unsigned __int64 v20; // [sp+1Ch] [bp-34h]@7
-	unsigned int minutes; // [sp+2Ch] [bp-24h]@26
-	unsigned int years; // [sp+34h] [bp-1Ch]@26
-	unsigned int weeks; // [sp+38h] [bp-18h]@26
-	int v26; // [sp+3Ch] [bp-14h]@15
-	unsigned int days; // [sp+3Ch] [bp-14h]@26
-	unsigned int months; // [sp+40h] [bp-10h]@26
-
-	for (uint i = 0; i < uLevelEVT_NumEvents; ++i)
-	{
-		EventIndex pEvent = pLevelEVT_Index[i];
-
-		_evt_raw* _evt = (_evt_raw *)(&pLevelEVT[pEvent.uEventOffsetInEVT]);
-
-		if (_evt->_e_type == EVENT_PlaySound)
-			pSoundList->LoadSound(EVT_DWORD(_evt->v5), 0);
-		else if (_evt->_e_type == EVENT_OnMapReload)
-			EventProcessor(pEvent.uEventID, 0, 0, pEvent.event_sequence_num);
-		else if (_evt->_e_type == EVENT_OnTimer || _evt->_e_type == EVENT_Initialize)
-		{
-			//v3 = &MapsLongTimersList[MapsLongTimers_count];
-			v20 = pOutdoor->loc_time.uLastVisitDay;
-			if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
-				v20 = pIndoor->stru1.uLastVisitDay;
-
-			MapsLongTimersList[MapsLongTimers_count].timer_evt_type = _evt->_e_type;
-			MapsLongTimersList[MapsLongTimers_count].timer_evt_ID = pEvent.uEventID;
-			MapsLongTimersList[MapsLongTimers_count].timer_evt_seq_num = pEvent.event_sequence_num;
-
-			MapsLongTimersList[MapsLongTimers_count].YearsInterval = _evt->v5;
-			MapsLongTimersList[MapsLongTimers_count].MonthsInterval = _evt->v6;
-			MapsLongTimersList[MapsLongTimers_count].WeeksInterval = _evt->v7;
-			MapsLongTimersList[MapsLongTimers_count].HoursInterval = _evt->v8;
-			MapsLongTimersList[MapsLongTimers_count].MinutesInterval = _evt->v9;
-			MapsLongTimersList[MapsLongTimers_count].SecondsInterval = _evt->v10;
-
-
-			v6 = ((unsigned short)_evt->v12 << 8) + _evt->v11;
-
-			MapsLongTimersList[MapsLongTimers_count].time_left_to_fire = ((unsigned short)_evt->v12 << 8) + _evt->v11;
-			MapsLongTimersList[MapsLongTimers_count].IntervalHalfMins = ((unsigned short)_evt->v12 << 8) + _evt->v11;
-			if (MapsLongTimersList[MapsLongTimers_count].timer_evt_type == EVENT_Initialize && !(short)v6)
-			{
-				if (v20)
-					v18 = pParty->uTimePlayed - v20;
-				else
-					v18 = 0;
-				v26 = (signed int)(signed __int64)((double)(signed __int64)v18 * 0.234375) / 60 / 60 / 24;
-
-				if (v26 / 7 / 4 / 12 != 0 && MapsLongTimersList[MapsLongTimers_count].YearsInterval ||
-					v26 / 7 / 4 != 0 && MapsLongTimersList[MapsLongTimers_count].MonthsInterval != 0 ||
-					v26 / 7 != 0 && MapsLongTimersList[MapsLongTimers_count].WeeksInterval != 0 ||
-					v26 != 0 || !v20)
-				{
-					++MapsLongTimers_count;
-					MapsLongTimersList[MapsLongTimers_count].NextStartTime = 0;
-					continue;
-				}
-			}
-			else
-			{
-				v8 = (__int64)((double)pParty->uTimePlayed * 0.234375);
-				seconds = v8 % 60;
-				minutes = (v8 / 60) % 60;
-				hours = ((v8 / 60) / 60) % 24;
-				days = (((v8 / 60) / 60) / 24) % 7;
-				weeks = ((((v8 / 60) / 60) / 24) / 7) % 4;
-				months = (((((v8 / 60) / 60) / 24) / 7) / 4) % 12;
-				years = (((((v8 / 60) / 60) / 24) / 7) / 4) / 12;
-
-				if (MapsLongTimersList[MapsLongTimers_count].YearsInterval)
-					++years;
-				else if (MapsLongTimersList[MapsLongTimers_count].MonthsInterval)
-					++months;
-				else if (MapsLongTimersList[MapsLongTimers_count].WeeksInterval)
-					++weeks;
-				else
-				{
-					++days;
-					hours = MapsLongTimersList[MapsLongTimers_count].HoursInterval;
-					minutes = MapsLongTimersList[MapsLongTimers_count].MinutesInterval;
-					seconds = MapsLongTimersList[MapsLongTimers_count].SecondsInterval;
-				}
-				MapsLongTimersList[MapsLongTimers_count].NextStartTime = (signed __int64)((double)((seconds
-					+ 60 * minutes
-					+ 3600 * hours
-					+ 86400 * days
-					+ 604800 * weeks
-					+ 2419200 * months
-					+ 29030400 * years) << 7)
-					* 0.033333335);
-
-				++MapsLongTimers_count;
-			}
-		}
-	}
-}
-
-//----- (00444360) --------------------------------------------------------
-void Level_LoadEvtAndStr(const char *pLevelName)
-{
-	char pContainerName[120]; // [sp+8h] [bp-98h]@1
-
-	sprintf(pContainerName, "%s.evt", pLevelName);
-	uLevelEVT_Size = LoadEventsToBuffer(pContainerName, pLevelEVT.data(), 9216);
-
-	sprintf(pContainerName, "%s.str", pLevelName);
-	uLevelStrFileSize = LoadEventsToBuffer(pContainerName, pLevelStr.data(), 9216);
-	if (uLevelStrFileSize)
-		LoadLevel_InitializeLevelStr();
-}
-
-//----- (004452BB) --------------------------------------------------------
-void sub_4452BB()
-{
-	pGUIWindow2->Release();
-	pGUIWindow2 = 0;
-	activeLevelDecoration = _591094_decoration;
-	EventProcessor(dword_5C3418, 0, 1, dword_5C341C);
-	activeLevelDecoration = nullptr;
-	pEventTimer->Resume();
-}
-
-//----- (0044100D) --------------------------------------------------------
-bool _44100D_should_alter_right_panel()
-{
-	return pCurrentScreen == SCREEN_NPC_DIALOGUE || pCurrentScreen == SCREEN_CHARACTERS ||
-		pCurrentScreen == SCREEN_HOUSE || pCurrentScreen == SCREEN_E ||
-		pCurrentScreen == SCREEN_CHANGE_LOCATION || pCurrentScreen == SCREEN_INPUT_BLV || pCurrentScreen == SCREEN_CASTING;
-}
-
-//----- (0044987B) --------------------------------------------------------
-void Transition_StopSound_Autosave(const char *pMapName, MapStartPoint start_point)
-{
-	pAudioPlayer->StopChannels(-1, -1);
-	pGameLoadingUI_ProgressBar->Initialize(GUIProgressBar::TYPE_None);
-	if (_stricmp(pCurrentMapName, pMapName))
-		SaveGame(1, 0);
-
-	uGameState = GAME_STATE_CHANGE_LOCATION;
-	strcpy(pCurrentMapName, pMapName);
-	uLevel_StartingPointType = start_point;
-}
-// 6BE35C: using guessed type int uLevel_StartingPointType;
-
-//----- (004451A8) --------------------------------------------------------
-void __fastcall sub_4451A8_press_any_key(int a1, int a2, int a4)
-{
-	if (!pGUIWindow2)
-	{
-		if (pParty->uFlags & 2)
-			pGame->Draw();
-		pAudioPlayer->StopChannels(-1, -1);
-		pMiscTimer->Pause();
-		pEventTimer->Pause();
-		dword_5C3418 = a1;
-		dword_5C341C = a2;
-		_591094_decoration = activeLevelDecoration;
-		pGUIWindow2 = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_GreetingNPC, a4, 0);
-		pGUIWindow2->CreateButton(61, 424, 31, 40, 2, 94, UIMSG_SelectCharacter, 1, '1', "", 0);
-		pGUIWindow2->CreateButton(177, 424, 31, 40, 2, 94, UIMSG_SelectCharacter, 2, '2', "", 0);
-		pGUIWindow2->CreateButton(292, 424, 31, 40, 2, 94, UIMSG_SelectCharacter, 3, '3', "", 0);
-		pGUIWindow2->CreateButton(407, 424, 31, 40, 2, 94, UIMSG_SelectCharacter, 4, '4', "", 0);
-	}
-}
-
-
-
-
-//----- (00448B67) --------------------------------------------------------
-void OnTimer(int)
-{
-	if (pEventTimer->bPaused)
-		return;
-
-	long long v13 = (signed __int64)(pParty->uTimePlayed - _5773B8_event_timer) / 128;
-	if (!v13)
-		return;
-
-	//uint _v2v3 = pParty->uTimePlayed;
-	//v3 = HIDWORD(pParty->uTimePlayed);
-	//v2 = LODWORD(pParty->uTimePlayed);
-
-	_5773B8_event_timer = pParty->uTimePlayed;
-
-	for (uint i = 0; i < MapsLongTimers_count; ++i)
-	{
-		//v4 = (char *)&array_5B5928_timers[0].field_C;
-		MapsLongTimer* timer = &MapsLongTimersList[i];
-		//while ( 1 )
-		//{
-		//v5 = *(short *)v4;
-		if (timer->time_left_to_fire)
-		{
-			if (v13 < timer->time_left_to_fire)
-				timer->time_left_to_fire -= v13;
-			else
-			{
-				timer->time_left_to_fire = timer->IntervalHalfMins;
-				EventProcessor(timer->timer_evt_ID, 0, 1, timer->timer_evt_seq_num);
-			}
-		}
-		else
-		{
-			if (timer->NextStartTime < pParty->uTimePlayed)
-			{
-				uint next_trigger_time = 1 * 60 * 60 * 24; // 1 day
-				if (timer->YearsInterval)
-					next_trigger_time = 336 * 60 * 60 * 24; // 1 year
-				else if (timer->MonthsInterval)
-					next_trigger_time = 28 * 60 * 60 * 24; // 1 month
-				else if (timer->WeeksInterval)
-					next_trigger_time = 7 * 60 * 60 * 24; // 1 week
-
-				timer->NextStartTime += (next_trigger_time * 128) / 3.0f;
-				if (timer->NextStartTime < pParty->uTimePlayed) // make sure in wont fire several times in a row if big time interval has lapsed
-					timer->NextStartTime = pParty->uTimePlayed;
-
-				EventProcessor(timer->timer_evt_ID, 0, 1, timer->timer_evt_seq_num);
-			}
-		}
-	}
-}
-
-
-
-
-
-
-
-//----- (0044C28F) --------------------------------------------------------
-bool TeleportToNWCDungeon()
-{
-	if (!_stricmp("nwc.blv", pCurrentMapName))
-		return false;
-
-	_5B65A8_npcdata_uflags_or_other = 0;
-	_5B65AC_npcdata_fame_or_other = 0;
-	_5B65B0_npcdata_rep_or_other = 0;
-	_5B65B4_npcdata_loword_house_or_other = 0;
-	_5B65B8_npcdata_hiword_house_or_other = 0;
-	dword_5B65BC = 0;
-	dword_5B65C0 = 0;
-
-	pGameLoadingUI_ProgressBar->uType = GUIProgressBar::TYPE_Fullscreen;
-	Transition_StopSound_Autosave("nwc.blv", MapStartPoint_Party);
-	pCurrentScreen = SCREEN_GAME;
-	return true;
-}
-
-//----- (00401000) --------------------------------------------------------
-void mm7__vector_constructor(void *a1, int objSize, int numObjs, int(*constructor)(int))
-{
-	void *v4; // esi@2
-
-	if (numObjs > 0)
-	{
-		v4 = a1;
-		for (int i = numObjs; i; --i)
-		{
-			constructor((int)v4);
-			v4 = (char *)v4 + objSize;
-		}
-	}
-}
-
-
-
--- a/Engine/Game.h	Sat May 09 12:55:58 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,239 +0,0 @@
-#pragma once
-#include "VectorTypes.h"
-
-#include "OSAPI.h"
-
-#include "MapInfo.h"
-
-
-#define GAME_FLAGS_1_01_lightmap_related                 0x01
-#define GAME_FLAGS_1_DRAW_BLV_DEBUGS    0x08
-#define GAME_FLAGS_2_SATURATE_LIGHTMAPS 0x02
-#define GAME_FLAGS_2_ALTER_GRAVITY      0x08
-#define GAME_FLAGS_2_TARGETING_MODE     0x10
-#define GAME_FLAGS_2_DRAW_BLOODSPLATS   0x20
-
-
-
-/*  320 */
-enum GAME_STATE
-{
-  GAME_STATE_PLAYING = 0,
-  GAME_FINISHED = 1,
-  GAME_STATE_CHANGE_LOCATION = 2,
-  GAME_STATE_LOADING_GAME = 3,
-  GAME_STATE_NEWGAME_OUT_GAMEMENU = 4,
-  GAME_STATE_5 = 5,
-  GAME_STATE_STARTING_NEW_GAME = 6,
-  GAME_STATE_GAME_QUITTING_TO_MAIN_MENU = 7,
-  GAME_STATE_PARTY_DIED = 8,
-  GAME_STATE_FINAL_WINDOW = 9,
-  GAME_STATE_A = 10
-};
-
-
-
-/*  105 */
-#pragma pack(push, 1)
-struct Game__StationaryLight
-{
-  Vec3_float_ vPosition;
-  Vec3_float_ vRGBColor;
-  float flt_18;
-};
-#pragma pack(pop)
-
-
-/*  108 */
-#pragma pack(push, 1)
-struct Game_stru0
-{
-  int field_0;
-  unsigned __int8 *ptr_4;
-  int field_8;
-  int field_C;
-};
-#pragma pack(pop)
-
-
-/*  279 */
-#pragma pack(push, 1)
-//Game_stru1
-struct Game_Bloodsplat
-{
-  float x;
-  float y;
-  float z;
-  float r;
-  float g;
-  float b;
-  float radius;
-};
-#pragma pack(pop)
-
-
-class Vis;
-class LightmapBuilder;
-class ParticleEngine;
-class Mouse;
-class Keyboard;
-class ThreadWard;
-class CShow;
-class GammaController;
-struct stru9;
-struct stru10;
-
-/*  104 */
-#pragma pack(push, 1)
-struct Game
-{
-  static Game *Create();
-  static void  Destroy();
-
-protected: Game();
-protected: virtual ~Game();
-
-
-public:
-  //void _44E904_gamma_saturation_adjust();
-  //bool InitializeGammaController();
-  bool PickMouse(float fPickDepth, unsigned int uMouseX, unsigned int uMouseY, bool bOutline, struct Vis_SelectionFilter *sprite_filter, struct Vis_SelectionFilter *face_filter);
-  bool PickKeyboard(bool bOutline, struct Vis_SelectionFilter *sprite_filter, struct Vis_SelectionFilter *face_filter);
-  void OutlineSelection();
-  signed int _44EC23(struct Polygon *a2, int *a3, signed int a4);
-  signed int _44ED0A(struct BLVFace *a2, int *a3, signed int a4);
-  bool AlterGamma_BLV(struct BLVFace *pFace, signed int *pColor);
-  bool AlterGamma_ODM(struct ODMFace *pFace, signed int *pColor);
-  bool draw_debug_outlines();
-  bool _44EEA7();
-  bool _44F07B();
-  void ToggleFlags(unsigned int uMask);
-  void ToggleFlags2(unsigned int uFlag);
-  void _44F0FD();
-  void PushStationaryLights(int a2);
-  void PrepareBloodsplats();
-  void Deinitialize();
-  void Loop();
-  void DrawParticles();
-  void Draw();
-
-  //----- (0042EB6A) --------------------------------------------------------
-  struct stru6 *GetStru6() {return this->pStru6Instance;}
-  //----- (0042EB71) --------------------------------------------------------
-  struct IndoorCameraD3D *GetIndoorCamera() {return this->pIndoorCameraD3D;}
-
-
-  //void ( ***vdestructor_ptr)(Game *, bool);
-  Game__StationaryLight pStationaryLights[25];
-  char field_2C0[1092];
-  unsigned int uNumStationaryLights;
-  Game_Bloodsplat pBloodsplats[20];
-  int field_938;
-  int field_93C;
-  int field_940;
-  int field_944;
-  int field_948;
-  int field_94C;
-  int field_950;
-  int field_954;
-  int field_958;
-  int field_95C;
-  int field_960;
-  int field_964;
-  int field_968;
-  int field_96C;
-  int field_970;
-  Mouse *pMouse;
-  int field_978;
-  Game_stru0 stru_97C;
-  char field_98C[1148];
-  int uNumBloodsplats;
-  int field_E0C;
-  __int64 field_E10;
-  int uNumStationaryLights_in_pStationaryLightsStack;
-  unsigned int __depricated1;//unsigned int bGammaControlInitialized;
-  unsigned int uFlags;
-  unsigned int uFlags2;
-  float fSaturation;
-  unsigned __int64 __depricated2;//unsigned __int64 uSomeGammaStartTime;
-  unsigned __int64 __depricated3;//__int64 uSomeGammaDeltaTime;
-  void/*ThreadWard*/ *pThreadWardInstance;
-  ParticleEngine *pParticleEngine;
-  Mouse *pMouseInstance;
-  LightmapBuilder *pLightmapBuilder;
-  Vis *pVisInstance;
-  stru6 *pStru6Instance;
-  IndoorCameraD3D *pIndoorCameraD3D;
-  stru9 *pStru9Instance;
-  stru10 *pStru10Instance;
-  void/*stru11*/ *pStru11Instance;
-  void/*stru12*/ *pStru12Instance;
-  void/*CShow*/ *pCShow;
-  Keyboard *pKeyboardInstance;
-  void *__depricated_4;//GammaController *pGammaController;
-  int field_E74;
-};
-#pragma pack(pop)
-
-
-
-
-
-
-extern Game *pGame;
-
-void sub_42FBDD();
-void CloseWindowBackground();
-void GameUI_MsgProc();
-void back_to_game();
-void GUI_MainMenuMessageProc();
-
-void UpdateUserInput_and_MapSpecificStuff();
-void PrepareWorld(unsigned int _0_box_loading_1_fullscreen);
-void DoPrepareWorld(unsigned int bLoading, int _1_fullscreen_loading_2_box);
-
-//int __stdcall aWinProc(HWND hWnd, UINT Msg, WPARAM wParam, unsigned int lParam);
-int __stdcall InsertMM7CDDialogFunc(HWND hDlg, int a2, __int16 a3, int a4);
-bool __fastcall FindMM7CD(HWND hWnd, char *pCDDrive);
-//bool __fastcall Initialize(HINSTANCE hInst, char *pCmdLine);
-
-void Game_DeinitializeAndTerminate(int exitCode); // idb
-void FinalInitialization();
-bool __fastcall CheckMM7CD(char c);
-void SecondaryInitialization();
-
-
-void MM6_Initialize(const wchar_t *pIniFilename);
-void MM7Initialization();
-
-void __fastcall PrepareToLoadODM(unsigned int bLoading, struct ODMRenderParams *a2);
-void MainMenu_Loop();
-unsigned int GameOverMenu(void *ecx0);
-void ResetCursor_Palettes_LODs_Level_Audio_SFT_Windows();
-void _461103_load_level_sub();
-void  InitializeTurnBasedAnimations(void *);
-void SetCurrentMenuID(enum MENU_STATE); // idb
-enum MENU_STATE GetCurrentMenuID();
-unsigned int GetGravityStrength();
-void  GameUI_StatusBar_UpdateTimedString(unsigned int bForceHide); // idb
-
-void __fastcall sub_44861E_set_texture(unsigned int uFaceCog, const char *pFilename);
-void __fastcall sub_44892E_set_faces_bit(int sCogNumber, int bit, int on);
-void __fastcall SetDecorationSprite(uint16_t uCog, bool bHide, const char *pFileName); // idb
-void _494035_timed_effects__water_walking_damage__etc();
-void _493938_regenerate(); 
-void sub_491E3A();
-const char *GetReputationString(signed int a1);
-unsigned int __fastcall _494820_training_time(unsigned int a1);
-void LoadLevel_InitializeLevelStr();
-void OnMapLeave();
-void OnMapLoad();
-void Level_LoadEvtAndStr(const char *pLevelName);
-void sub_4452BB();
-bool _44100D_should_alter_right_panel();
-void Transition_StopSound_Autosave(const char *pMapName, MapStartPoint point); // sub_44987B idb
-
-void __fastcall sub_4451A8_press_any_key(int a1, int a2, int a4);
-
-void OnTimer(int);
-bool TeleportToNWCDungeon();
\ No newline at end of file
--- a/Engine/Graphics/DecalBuilder.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Graphics/DecalBuilder.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,16 +3,15 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
+#include "Engine/Engine.h"
 #include "DecalBuilder.h"
-#include "../Game.h"
-#include "../Timer.h"
-#include "../stru314.h"
+#include "Engine/Timer.h"
+#include "Engine/stru314.h"
 #include "Outdoor.h"
-#include "../Log.h"
 
 #include "stru9.h"
 
-#include "../OurMath.h"
+#include "Engine/OurMath.h"
 
 
 struct DecalBuilder *pDecalBuilder = new DecalBuilder;
@@ -139,7 +138,7 @@
 		++a6;
       }
     v16 = a4;
-    if ( pGame->pIndoorCameraD3D->_437376(a4, static_AE4F90, (unsigned int *)&a5) == 1 )
+    if ( pEngine->pIndoorCameraD3D->_437376(a4, static_AE4F90, (unsigned int *)&a5) == 1 )
     {
       if ( !a5 )
         return 0;
@@ -157,7 +156,7 @@
   //LODWORD(v36) = (DWORD)&static_AE4F60.field_10;
   static_AE4F60.field_4.z = v16->face_plane.vNormal.z;
   static_AE4F60.dist = v16->face_plane.dist;
-  if ( !pGame->pIndoorCameraD3D->GetFacetOrientation(v16->polygonType, &static_AE4F60.field_4,
+  if ( !pEngine->pIndoorCameraD3D->GetFacetOrientation(v16->polygonType, &static_AE4F60.field_4,
      &static_AE4F60.field_10, &static_AE4F60.field_1C) )
       MessageBoxW(nullptr, L"Error: Failed to get the facet orientation", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\PolyProjector.cpp:101", 0);
   
@@ -280,14 +279,14 @@
   decal->uColorMultiplier = uColorMultiplier;
   decal->uNumVertices = 4;
   decal->field_C14 = a2;
-  result = pGame->pStru9Instance->_4980B9(a11, a10, a9->field_4.x, a9->field_4.y, a9->field_4.z, decal->pVertices, (signed int*)&decal->uNumVertices);
+  result = pEngine->pStru9Instance->_4980B9(a11, a10, a9->field_4.x, a9->field_4.y, a9->field_4.z, decal->pVertices, (signed int*)&decal->uNumVertices);
   if ( result )
   {
     if ( !decal->uNumVertices )
       return 1;
 
-    pGame->pIndoorCameraD3D->ViewTransform(decal->pVertices, (unsigned int)decal->uNumVertices);
-    pGame->pIndoorCameraD3D->Project(decal->pVertices, decal->uNumVertices, 0);
+    pEngine->pIndoorCameraD3D->ViewTransform(decal->pVertices, (unsigned int)decal->uNumVertices);
+    pEngine->pIndoorCameraD3D->Project(decal->pVertices, decal->uNumVertices, 0);
     if ( !(uClipFlags & 1) )
     {
       ++this->field_308008;
@@ -303,13 +302,13 @@
     {
       if ( uClipFlags & 2 )
       {
-        pGame->pIndoorCameraD3D->_436CDC_mess_with_lightmap__clipflag_2(decal->pVertices, decal->uNumVertices, this->pVertices, &a8b);
-        pGame->pIndoorCameraD3D->_437143(a8b, decal->pVertices, this->pVertices, (signed int *)&decal->uNumVertices);
+        pEngine->pIndoorCameraD3D->_436CDC_mess_with_lightmap__clipflag_2(decal->pVertices, decal->uNumVertices, this->pVertices, &a8b);
+        pEngine->pIndoorCameraD3D->_437143(a8b, decal->pVertices, this->pVertices, (signed int *)&decal->uNumVertices);
       }
       else if ( uClipFlags & 4 )
       {
-        pGame->pIndoorCameraD3D->_436F09_mess_with_lightmap__clipflag_4(decal->pVertices, decal->uNumVertices, this->pVertices, &a8b);
-        pGame->pIndoorCameraD3D->_437143(a8b, decal->pVertices, this->pVertices, (signed int *)&decal->uNumVertices);
+        pEngine->pIndoorCameraD3D->_436F09_mess_with_lightmap__clipflag_4(decal->pVertices, decal->uNumVertices, this->pVertices, &a8b);
+        pEngine->pIndoorCameraD3D->_437143(a8b, decal->pVertices, this->pVertices, (signed int *)&decal->uNumVertices);
       }
       else
         MessageBoxA(nullptr, "Undefined clip flag specified", "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\PolyProjector.cpp:258", 0);
@@ -484,10 +483,10 @@
 		else
 			MessageBoxW(nullptr, L"Uknown strip type detected!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\PolyProjector.cpp:434", 0);
         //v21 = uStripType;
-        //v13 = pGame->pIndoorCameraD3D->GetPolygonMinZ(v8, uStripType);
+        //v13 = pEngine->pIndoorCameraD3D->GetPolygonMinZ(v8, uStripType);
         //v21 = uStripType;
-        v28 = pGame->pIndoorCameraD3D->GetPolygonMinZ(a5, uStripType);
-        v26 = pGame->pIndoorCameraD3D->GetPolygonMaxZ(a5, uStripType);
+        v28 = pEngine->pIndoorCameraD3D->GetPolygonMinZ(a5, uStripType);
+        v26 = pEngine->pIndoorCameraD3D->GetPolygonMaxZ(a5, uStripType);
 		if ( a3 - pBloodsplatContainer->std__vector_pBloodsplats[i].radius < pBloodsplatContainer->std__vector_pBloodsplats[i].x &&
 			v31 + pBloodsplatContainer->std__vector_pBloodsplats[i].radius > pBloodsplatContainer->std__vector_pBloodsplats[i].x &&
 			v30 - pBloodsplatContainer->std__vector_pBloodsplats[i].radius < pBloodsplatContainer->std__vector_pBloodsplats[i].y &&
@@ -559,7 +558,7 @@
 void DecalBuilder::DrawDecalDebugOutlines()
 {
   for(int i = 0; i < std__vector_pDecals_size; i++)
-	pGame->pIndoorCameraD3D->debug_outline_sw(std__vector_pDecals[i].pVertices, std__vector_pDecals[i].uNumVertices, 0xC86400u, 0.0);
+	pEngine->pIndoorCameraD3D->debug_outline_sw(std__vector_pDecals[i].pVertices, std__vector_pDecals[i].uNumVertices, 0xC86400u, 0.0);
 }
 
 //----- (0040E4C2) --------------------------------------------------------
--- a/Engine/Graphics/DecorationList.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Graphics/DecorationList.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,11 +3,10 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
+#include "Engine/Engine.h"
 #include "Sprites.h"
 #include "DecorationList.h"
 #include "../Tables/FrameTableInc.h"
-#include "../mm7_data.h"
-#include "../ErrorHandling.h"
 #include "../stru123.h"
 #include "Level\Decoration.h"
 
--- a/Engine/Graphics/Indoor.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Graphics/Indoor.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,7 +3,9 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
-#include "../ErrorHandling.h"
+
+#include "Engine/Engine.h"
+
 #include "../ZlibWrapper.h"
 
 #include "LightmapBuilder.h"
@@ -13,9 +15,8 @@
 #include "../stru367.h"
 
 #include "Outdoor.h"
-#include "../Objects/SpriteObject.h"
-#include "../Events.h"
-#include "../Game.h"
+#include "Engine/Objects/SpriteObject.h"
+#include "Engine/Events.h"
 #include "Viewport.h"
 #include "../Timer.h"
 #include "../Party.h"
@@ -28,12 +29,10 @@
 #include "GUI/GUIProgressBar.h"
 #include "../stru123.h"
 #include "Media/Audio/AudioPlayer.h"
-#include "../Log.h"
 #include "../TurnEngine/TurnEngine.h"
 #include "PaletteManager.h"
 #include "Lights.h"
 
-#include "../MM7.h"
 #include "Sprites.h"
 #include "stru6.h"
 #include "ParticleEngine.h"
@@ -100,7 +99,7 @@
   uNumSpritesDrawnThisFrame = 0;
   uNumBillboardsToDraw = 0;
 
-  if ( !byte_4D864C || !(pGame->uFlags & 0x1000) )  // lightspot around party
+  if ( !byte_4D864C || !(pEngine->uFlags & 0x1000) )  // lightspot around party
   {
     //v2 = pParty->flt_TorchlightColorB + 6.7553994e15;
     //v11 = LOBYTE(v2);
@@ -110,9 +109,9 @@
     //LOBYTE(v1) = _4E94D0_light_type;
     //v4 = pParty->flt_TorchlightColorR + 6.7553994e15;
     //v3 = pParty->flt_TorchlightColorG + 6.7553994e15;
-    pMobileLightsStack->AddLight(pGame->pIndoorCameraD3D->vPartyPos.x,
-                                 pGame->pIndoorCameraD3D->vPartyPos.y,
-                                 pGame->pIndoorCameraD3D->vPartyPos.z,
+    pMobileLightsStack->AddLight(pEngine->pIndoorCameraD3D->vPartyPos.x,
+                                 pEngine->pIndoorCameraD3D->vPartyPos.y,
+                                 pEngine->pIndoorCameraD3D->vPartyPos.z,
                                  pBLVRenderParams->uPartySectorID,
                                  v5,
                                  floorf(pParty->flt_TorchlightColorR + 0.5f),
@@ -133,7 +132,7 @@
       PrepareDecorationsRenderList_BLV(v8->pDecorationIDs[j], v7);
   }
   FindBillboardsLightLevels_BLV();
-  pGame->PrepareBloodsplats();
+  pEngine->PrepareBloodsplats();
 }
 
 //----- (004407D9) --------------------------------------------------------
@@ -143,11 +142,11 @@
 
   this->field_0_timer_ = pEventTimer->uTotalGameTimeElapsed;
 
-  pGame->pIndoorCameraD3D->debug_flags = 0;
+  pEngine->pIndoorCameraD3D->debug_flags = 0;
   if (viewparams->draw_sw_outlines)
-    pGame->pIndoorCameraD3D->debug_flags |= BLV_RENDER_DRAW_SW_OUTLINES;
+    pEngine->pIndoorCameraD3D->debug_flags |= BLV_RENDER_DRAW_SW_OUTLINES;
   if (viewparams->draw_d3d_outlines)
-    pGame->pIndoorCameraD3D->debug_flags |= BLV_RENDER_DRAW_D3D_OUTLINES;
+    pEngine->pIndoorCameraD3D->debug_flags |= BLV_RENDER_DRAW_D3D_OUTLINES;
 
   //v2 = a2;
   //this->field_0_timer_ = a2->field_0_timer;
@@ -160,9 +159,9 @@
   //this->sPartyRotY = a2->sRotationY;
   //v6 = this->vPartyPos.x;
   //this->sPartyRotX = a2->sRotationX;
-  v7 = pIndoor->GetSector(pGame->pIndoorCameraD3D->vPartyPos.x,
-                          pGame->pIndoorCameraD3D->vPartyPos.y,
-                          pGame->pIndoorCameraD3D->vPartyPos.z);
+  v7 = pIndoor->GetSector(pEngine->pIndoorCameraD3D->vPartyPos.x,
+                          pEngine->pIndoorCameraD3D->vPartyPos.y,
+                          pEngine->pIndoorCameraD3D->vPartyPos.z);
   this->uPartySectorID = v7;
   if ( !v7 )
   {
@@ -176,14 +175,14 @@
   }
   //if ( pRenderer->pRenderD3D )
   {
-    //this->sCosineY = stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationY);
-    //this->sSineY = stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationY);
-    //this->sCosineNegX = stru_5C6E00->Cos(-pGame->pIndoorCameraD3D->sRotationX);
-    //this->sSineNegX = stru_5C6E00->Sin(-pGame->pIndoorCameraD3D->sRotationX);
-    //this->fCosineY = cos((3.141592653589793 + 3.141592653589793) * (double)pGame->pIndoorCameraD3D->sRotationY * 0.00048828125);
-    //this->fSineY = sin((3.141592653589793 + 3.141592653589793) * (double)pGame->pIndoorCameraD3D->sRotationY * 0.00048828125);
-    //this->fCosineNegX = cos((3.141592653589793 + 3.141592653589793) * (double)-pGame->pIndoorCameraD3D->sRotationX * 0.00048828125);
-    //this->fSineNegX = sin((3.141592653589793 + 3.141592653589793) * (double)-pGame->pIndoorCameraD3D->sRotationX * 0.00048828125);
+    //this->sCosineY = stru_5C6E00->Cos(pEngine->pIndoorCameraD3D->sRotationY);
+    //this->sSineY = stru_5C6E00->Sin(pEngine->pIndoorCameraD3D->sRotationY);
+    //this->sCosineNegX = stru_5C6E00->Cos(-pEngine->pIndoorCameraD3D->sRotationX);
+    //this->sSineNegX = stru_5C6E00->Sin(-pEngine->pIndoorCameraD3D->sRotationX);
+    //this->fCosineY = cos((3.141592653589793 + 3.141592653589793) * (double)pEngine->pIndoorCameraD3D->sRotationY * 0.00048828125);
+    //this->fSineY = sin((3.141592653589793 + 3.141592653589793) * (double)pEngine->pIndoorCameraD3D->sRotationY * 0.00048828125);
+    //this->fCosineNegX = cos((3.141592653589793 + 3.141592653589793) * (double)-pEngine->pIndoorCameraD3D->sRotationX * 0.00048828125);
+    //this->fSineNegX = sin((3.141592653589793 + 3.141592653589793) * (double)-pEngine->pIndoorCameraD3D->sRotationX * 0.00048828125);
     this->field_64 = pViewport->field_of_view;
     
     this->uViewportX = pViewport->uScreen_TL_X;
@@ -363,7 +362,7 @@
   //}
 
   pParty->uFlags &= ~2;
-  pGame->DrawParticles();
+  pEngine->DrawParticles();
   trail_particle_generator.UpdateParticles();
 }
 
@@ -429,7 +428,7 @@
   if (!pFace->GetTexture())
     return;
 
-  if (!pGame->pIndoorCameraD3D->IsCulled(pFace))
+  if (!pEngine->pIndoorCameraD3D->IsCulled(pFace))
   {
     uNumVerticesa = pFace->uNumVertices;
     for (uint i = 0; i < pFace->uNumVertices; ++i)
@@ -442,21 +441,21 @@
     }
 
     if (!pVertices ||
-        (pGame->pStru9Instance->_498377(pPortalBounding, 4, pVertices, static_vertices_F7C228, &uNumVerticesa), uNumVerticesa) )
+        (pEngine->pStru9Instance->_498377(pPortalBounding, 4, pVertices, static_vertices_F7C228, &uNumVerticesa), uNumVerticesa) )
     {
-      if (pGame->pIndoorCameraD3D->CalcPortalShape(static_vertices_F7C228, &uNumVerticesa,
-                     static_vertices_F7B628, pGame->pIndoorCameraD3D->std__vector_000034_prolly_frustrum, 4, false, 0) != 1 || uNumVerticesa )
+      if (pEngine->pIndoorCameraD3D->CalcPortalShape(static_vertices_F7C228, &uNumVerticesa,
+                     static_vertices_F7B628, pEngine->pIndoorCameraD3D->std__vector_000034_prolly_frustrum, 4, false, 0) != 1 || uNumVerticesa )
       {
         a4a = SHIWORD(stru_F8AD28.uCurrentAmbientLightLevel);
         v17 = (248 - (SHIWORD(stru_F8AD28.uCurrentAmbientLightLevel) << 3))
           | (((248 - (SHIWORD(stru_F8AD28.uCurrentAmbientLightLevel) << 3))
            | ((248 - (SHIWORD(stru_F8AD28.uCurrentAmbientLightLevel) << 3)) << 8)) << 8);
         sub_4B0E07(uFaceID);
-        pGame->pLightmapBuilder->ApplyLights_IndoorFace(uFaceID);
+        pEngine->pLightmapBuilder->ApplyLights_IndoorFace(uFaceID);
         pDecalBuilder->ApplyBloodsplatDecals_IndoorFace(uFaceID);
-        pGame->pIndoorCameraD3D->ViewTransfrom_OffsetUV(static_vertices_F7B628, uNumVerticesa, array_507D30, &stru_F8AD28);
-        pGame->pIndoorCameraD3D->Project(array_507D30, uNumVerticesa, 0);
-        pGame->pLightmapBuilder->std__vector_000004_size = 0;
+        pEngine->pIndoorCameraD3D->ViewTransfrom_OffsetUV(static_vertices_F7B628, uNumVerticesa, array_507D30, &stru_F8AD28);
+        pEngine->pIndoorCameraD3D->Project(array_507D30, uNumVerticesa, 0);
+        pEngine->pLightmapBuilder->std__vector_000004_size = 0;
         if (stru_F8AD28.uNumLightsApplied > 0 || pDecalBuilder->uNumDecals > 0)
         {
           stru_F7B60C.face_plane.vNormal.x = pFace->pFacePlane.vNormal.x;
@@ -467,7 +466,7 @@
         }
 
         if (stru_F8AD28.uNumLightsApplied > 0 && !pFace->Indoor_sky()) //for torchlight(äëÿ ñâåòà ôàêåëîâ)
-          pGame->pLightmapBuilder->ApplyLights(&stru_F8AD28, &stru_F7B60C, uNumVerticesa, array_507D30, pVertices, 0);
+          pEngine->pLightmapBuilder->ApplyLights(&stru_F8AD28, &stru_F7B60C, uNumVerticesa, array_507D30, pVertices, 0);
 
         if (pDecalBuilder->uNumDecals > 0)//îòðèñîâêà ïÿòåí êðîâè
           pDecalBuilder->ApplyDecals(a4a, 1, &stru_F7B60C, uNumVerticesa, array_507D30, pVertices, 0, pFace->uSectorID);
@@ -558,16 +557,16 @@
   if (nodes[node_id].uFaceID == uFaceID)
     return;
   if (!node_id &&
-      pGame->pIndoorCameraD3D->vPartyPos.x >= pFace->pBounding.x1 - 16 &&  // we are probably standing at the portal plane
-      pGame->pIndoorCameraD3D->vPartyPos.x <= pFace->pBounding.x2 + 16 &&
-      pGame->pIndoorCameraD3D->vPartyPos.y >= pFace->pBounding.y1 - 16 &&
-      pGame->pIndoorCameraD3D->vPartyPos.y <= pFace->pBounding.y2 + 16 &&
-      pGame->pIndoorCameraD3D->vPartyPos.z >= pFace->pBounding.z1 - 16 &&
-      pGame->pIndoorCameraD3D->vPartyPos.z <= pFace->pBounding.z2 + 16 )
+      pEngine->pIndoorCameraD3D->vPartyPos.x >= pFace->pBounding.x1 - 16 &&  // we are probably standing at the portal plane
+      pEngine->pIndoorCameraD3D->vPartyPos.x <= pFace->pBounding.x2 + 16 &&
+      pEngine->pIndoorCameraD3D->vPartyPos.y >= pFace->pBounding.y1 - 16 &&
+      pEngine->pIndoorCameraD3D->vPartyPos.y <= pFace->pBounding.y2 + 16 &&
+      pEngine->pIndoorCameraD3D->vPartyPos.z >= pFace->pBounding.z1 - 16 &&
+      pEngine->pIndoorCameraD3D->vPartyPos.z <= pFace->pBounding.z2 + 16 )
   {
-    if ( abs(pFace->pFacePlane_old.dist + pGame->pIndoorCameraD3D->vPartyPos.x * pFace->pFacePlane_old.vNormal.x
-                                        + pGame->pIndoorCameraD3D->vPartyPos.y * pFace->pFacePlane_old.vNormal.y
-                                        + pGame->pIndoorCameraD3D->vPartyPos.z * pFace->pFacePlane_old.vNormal.z) <= 589824 ) // we sure are standing at the portal plane
+    if ( abs(pFace->pFacePlane_old.dist + pEngine->pIndoorCameraD3D->vPartyPos.x * pFace->pFacePlane_old.vNormal.x
+                                        + pEngine->pIndoorCameraD3D->vPartyPos.y * pFace->pFacePlane_old.vNormal.y
+                                        + pEngine->pIndoorCameraD3D->vPartyPos.z * pFace->pFacePlane_old.vNormal.z) <= 589824 ) // we sure are standing at the portal plane
     {
       pTransitionSector = pFace->uSectorID;
       if ( nodes[0].uSectorID == pTransitionSector )  // draw back sector
@@ -585,9 +584,9 @@
     }
   }
 
-  v9 = pFace->pFacePlane_old.vNormal.x * (pIndoor->pVertices[pFace->pVertexIDs[0]].x - pGame->pIndoorCameraD3D->vPartyPos.x)
-     + pFace->pFacePlane_old.vNormal.y * (pIndoor->pVertices[pFace->pVertexIDs[0]].y - pGame->pIndoorCameraD3D->vPartyPos.y)
-     + pFace->pFacePlane_old.vNormal.z * (pIndoor->pVertices[pFace->pVertexIDs[0]].z - pGame->pIndoorCameraD3D->vPartyPos.z);
+  v9 = pFace->pFacePlane_old.vNormal.x * (pIndoor->pVertices[pFace->pVertexIDs[0]].x - pEngine->pIndoorCameraD3D->vPartyPos.x)
+     + pFace->pFacePlane_old.vNormal.y * (pIndoor->pVertices[pFace->pVertexIDs[0]].y - pEngine->pIndoorCameraD3D->vPartyPos.y)
+     + pFace->pFacePlane_old.vNormal.z * (pIndoor->pVertices[pFace->pVertexIDs[0]].z - pEngine->pIndoorCameraD3D->vPartyPos.z);
   if (nodes[node_id].uSectorID != pFace->uSectorID)
     v9 = -v9;
   if (v9 >= 0)
@@ -633,7 +632,7 @@
     nodes[num_nodes].uViewportW = pBLVRenderParams->uViewportW;
     v29 = false;
     if (nodes[node_id].viewing_portal_id == -1)//for first portal
-      v29 = pGame->pStru10Instance->CalcPortalShape(pFace, nodes[num_nodes].std__vector_0007AC, nodes[num_nodes].pPortalBounding);
+      v29 = pEngine->pStru10Instance->CalcPortalShape(pFace, nodes[num_nodes].std__vector_0007AC, nodes[num_nodes].pPortalBounding);
     else//for next portals
     {
       static RenderVertexSoft static_subAddFaceToRenderList_d3d_stru_F7AA08[64];
@@ -647,10 +646,10 @@
       }
 
       unsigned int pNewNumVertices = pFace->uNumVertices;
-      pGame->pIndoorCameraD3D->CalcPortalShape(static_subAddFaceToRenderList_d3d_stru_F7AA08, &pNewNumVertices,
+      pEngine->pIndoorCameraD3D->CalcPortalShape(static_subAddFaceToRenderList_d3d_stru_F7AA08, &pNewNumVertices,
                                                static_subAddFaceToRenderList_d3d_stru_F79E08, nodes[node_id].std__vector_0007AC, 4, 0, 0);
 
-      v29 = pGame->pStru10Instance->_49C5DA(pFace, static_subAddFaceToRenderList_d3d_stru_F79E08, &pNewNumVertices,
+      v29 = pEngine->pStru10Instance->_49C5DA(pFace, static_subAddFaceToRenderList_d3d_stru_F79E08, &pNewNumVertices,
                                             nodes[num_nodes].std__vector_0007AC, nodes[num_nodes].pPortalBounding);
     }
     if ( 1 )
@@ -660,9 +659,9 @@
       nodes[num_nodes].viewing_portal_id = uFaceID;
       AddBspNodeToRenderList(++num_nodes - 1);
     }
-    if (pGame->pIndoorCameraD3D->debug_flags & BLV_RENDER_DRAW_SW_OUTLINES)
-      pGame->pIndoorCameraD3D->PrepareAndDrawDebugOutline(pFace, 0x1E1EFF);
-    //pGame->pIndoorCameraD3D->DebugDrawPortal(pFace);
+    if (pEngine->pIndoorCameraD3D->debug_flags & BLV_RENDER_DRAW_SW_OUTLINES)
+      pEngine->pIndoorCameraD3D->PrepareAndDrawDebugOutline(pFace, 0x1E1EFF);
+    //pEngine->pIndoorCameraD3D->DebugDrawPortal(pFace);
   }
 }
 
@@ -2949,11 +2948,11 @@
   bNoNPCHiring = false;
   pDest = 1;
   uCurrentlyLoadedLevelType = LEVEL_Indoor;
-  pGame->uFlags2 &= 0xFFFFFFF7;//~0x00000008
+  pEngine->uFlags2 &= 0xFFFFFFF7;//~0x00000008
   if ( Is_out15odm_underwater() )
   {
     bUnderwater = true;
-    pGame->uFlags2 |= 8;
+    pEngine->uFlags2 |= 8;
   }
   if ( !_stricmp(pCurrentMapName, "out15.odm") || !_stricmp(pCurrentMapName, "d23.blv") )
     bNoNPCHiring = true;
@@ -3414,7 +3413,7 @@
     if (pActors[i].uAIState == Removed || pActors[i].uAIState == Disabled)
       continue;
 
-    v4 = stru_5C6E00->Atan2(pActors[i].vPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x, pActors[i].vPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y);
+    v4 = stru_5C6E00->Atan2(pActors[i].vPosition.x - pEngine->pIndoorCameraD3D->vPartyPos.x, pActors[i].vPosition.y - pEngine->pIndoorCameraD3D->vPartyPos.y);
     v6 = ((signed int)(pActors[i].uYawAngle + ((signed int)stru_5C6E00->uIntegerPi >> 3) - v4 + stru_5C6E00->uIntegerPi) >> 8) & 7;
     v8 = pActors[i].uCurrentActionTime;
     if ( pParty->bTurnBasedModeOn )
@@ -3453,10 +3452,10 @@
     {
       if ( pBspRenderer->pVisibleSectorIDs_toDrawDecorsActorsEtcFrom[v12] == pActors[i].uSectorID )
       {
-        if ( !pGame->pIndoorCameraD3D->ApplyViewTransform_TrueIfStillVisible_BLV(pActors[i].vPosition.x, pActors[i].vPosition.y, pActors[i].vPosition.z, &x, &y, &z, 1)
+        if ( !pEngine->pIndoorCameraD3D->ApplyViewTransform_TrueIfStillVisible_BLV(pActors[i].vPosition.x, pActors[i].vPosition.y, pActors[i].vPosition.z, &x, &y, &z, 1)
           || abs(x) < abs(y) )
           continue;
-        pGame->pIndoorCameraD3D->Project(x, y, z, &v43, &a6);
+        pEngine->pIndoorCameraD3D->Project(x, y, z, &v43, &a6);
         if (uNumBillboardsToDraw >= 500)
           break;
         ++uNumBillboardsToDraw;
@@ -3474,8 +3473,8 @@
         }
         else
         {*/
-          pBillboardRenderList[uNumBillboardsToDraw - 1].fov_x = pGame->pIndoorCameraD3D->fov_x;
-          pBillboardRenderList[uNumBillboardsToDraw - 1].fov_y = pGame->pIndoorCameraD3D->fov_y;
+          pBillboardRenderList[uNumBillboardsToDraw - 1].fov_x = pEngine->pIndoorCameraD3D->fov_x;
+          pBillboardRenderList[uNumBillboardsToDraw - 1].fov_y = pEngine->pIndoorCameraD3D->fov_y;
           LODWORD(v18) = 0;
           HIDWORD(v18) = floorf(pBillboardRenderList[uNumBillboardsToDraw - 1].fov_x + 0.5f);
           pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_x_scaler_packedfloat = fixpoint_mul(v9->scale, v18 / x);
@@ -3485,7 +3484,7 @@
         if ( pActors[i].pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime <= 0 )
         {
           if ( pActors[i].pActorBuffs[ACTOR_BUFF_MASS_DISTORTION].uExpireTime > 0 )
-            pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_y_scaler_packedfloat = fixpoint_mul(pGame->pStru6Instance->_4A806F(&pActors[i]),
+            pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_y_scaler_packedfloat = fixpoint_mul(pEngine->pStru6Instance->_4A806F(&pActors[i]),
                        pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_y_scaler_packedfloat);
         }
         else
@@ -3546,12 +3545,12 @@
           if ( ( pSpriteObjects[i].uType < 1000 || pSpriteObjects[i].uType >= 10000)
             && (pSpriteObjects[i].uType < 500 || pSpriteObjects[i].uType >= 600)
             && (pSpriteObjects[i].uType < 811 || pSpriteObjects[i].uType >= 815)
-            || pGame->pStru6Instance->_4A81CA(&pSpriteObjects[i]))
+            || pEngine->pStru6Instance->_4A81CA(&pSpriteObjects[i]))
           {
             v4 = pSpriteFrameTable->GetFrame(pObjectList->pObjects[pSpriteObjects[i].uObjectDescID].uSpriteID, pSpriteObjects[i].uSpriteFrameID);
             a6 = v4->uGlowRadius * pSpriteObjects[i].field_22_glow_radius_multiplier;
-            v6 = stru_5C6E00->Atan2(pSpriteObjects[i].vPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x,
-                                    pSpriteObjects[i].vPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y);
+            v6 = stru_5C6E00->Atan2(pSpriteObjects[i].vPosition.x - pEngine->pIndoorCameraD3D->vPartyPos.x,
+                                    pSpriteObjects[i].vPosition.y - pEngine->pIndoorCameraD3D->vPartyPos.y);
             LOWORD(v7) = pSpriteObjects[i].uFacing;
             v9 = ((signed int)(stru_5C6E00->uIntegerPi + ((signed int)stru_5C6E00->uIntegerPi >> 3) + v7 - v6) >> 8) & 7;
             pBillboardRenderList[uNumBillboardsToDraw].HwSpriteID = v4->pHwSpriteIDs[v9];
@@ -3576,10 +3575,10 @@
                                                     pObjectList->pObjects[pSpriteObjects[i].uObjectDescID].uParticleTrailColorG,
                                                     pObjectList->pObjects[pSpriteObjects[i].uObjectDescID].uParticleTrailColorB, _4E94D3_light_type);
             }
-            if ( pGame->pIndoorCameraD3D->ApplyViewTransform_TrueIfStillVisible_BLV(pSpriteObjects[i].vPosition.x, pSpriteObjects[i].vPosition.y,
+            if ( pEngine->pIndoorCameraD3D->ApplyViewTransform_TrueIfStillVisible_BLV(pSpriteObjects[i].vPosition.x, pSpriteObjects[i].vPosition.y,
                                                                                     pSpriteObjects[i].vPosition.z, &x, &y, &z, 1) )
             {
-              pGame->pIndoorCameraD3D->Project(x, y, z, &v36, &v35);
+              pEngine->pIndoorCameraD3D->Project(x, y, z, &v36, &v35);
 
               assert(uNumBillboardsToDraw < 500);
               //if ( (signed int)uNumBillboardsToDraw >= 500 )
@@ -3591,8 +3590,8 @@
               pBillboardRenderList[uNumBillboardsToDraw - 1].uIndoorSectorID = pSpriteObjects[i].uSectorID;
               //if ( pRenderer->pRenderD3D )
               {
-                pBillboardRenderList[uNumBillboardsToDraw - 1].fov_x = pGame->pIndoorCameraD3D->fov_x;
-                pBillboardRenderList[uNumBillboardsToDraw - 1].fov_y = pGame->pIndoorCameraD3D->fov_y;
+                pBillboardRenderList[uNumBillboardsToDraw - 1].fov_x = pEngine->pIndoorCameraD3D->fov_x;
+                pBillboardRenderList[uNumBillboardsToDraw - 1].fov_y = pEngine->pIndoorCameraD3D->fov_y;
                 LODWORD(v18) = 0;
                 HIDWORD(v18) = (int)floorf(pBillboardRenderList[uNumBillboardsToDraw - 1].fov_x + 0.5f);
                 pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_x_scaler_packedfloat = fixpoint_mul(v4->scale, v18 / x);
@@ -3680,9 +3679,9 @@
     pNode = &pIndoor->pNodes[uFirstNode];
     pFace = &pIndoor->pFaces[pSector->pFaceIDs[pNode->uCoplanarOffset]];
     v5 = pFace->pFacePlane_old.dist +
-         pGame->pIndoorCameraD3D->vPartyPos.x * pFace->pFacePlane_old.vNormal.x +
-         pGame->pIndoorCameraD3D->vPartyPos.y * pFace->pFacePlane_old.vNormal.y +
-         pGame->pIndoorCameraD3D->vPartyPos.z * pFace->pFacePlane_old.vNormal.z;//plane equation
+         pEngine->pIndoorCameraD3D->vPartyPos.x * pFace->pFacePlane_old.vNormal.x +
+         pEngine->pIndoorCameraD3D->vPartyPos.y * pFace->pFacePlane_old.vNormal.y +
+         pEngine->pIndoorCameraD3D->vPartyPos.z * pFace->pFacePlane_old.vNormal.z;//plane equation
     if (pFace->Portal() && pFace->uSectorID != node->uSectorID )
       v5 = -v5;
     //v11 = v5 > 0;
@@ -3747,7 +3746,7 @@
     particle.flt_28 = 1.0;
     particle.timeToLive = (rand() & 0x80) + 128;
     particle.uTextureID = pBitmaps_LOD->LoadTexture("effpar01");
-    pGame->pParticleEngine->AddParticle(&particle);
+    pEngine->pParticleEngine->AddParticle(&particle);
     return;
   }
 
@@ -3755,8 +3754,8 @@
     return;
 
   v8 = pLevelDecorations[uDecorationID].field_10_y_rot + ((signed int)stru_5C6E00->uIntegerPi >> 3)
-     - stru_5C6E00->Atan2(pLevelDecorations[uDecorationID].vPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x,
-                          pLevelDecorations[uDecorationID].vPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y);
+     - stru_5C6E00->Atan2(pLevelDecorations[uDecorationID].vPosition.x - pEngine->pIndoorCameraD3D->vPartyPos.x,
+                          pLevelDecorations[uDecorationID].vPosition.y - pEngine->pIndoorCameraD3D->vPartyPos.y);
   v9 = ((signed int)(stru_5C6E00->uIntegerPi + v8) >> 8) & 7;
   v37 = pBLVRenderParams->field_0_timer_;
   if (pParty->bTurnBasedModeOn)
@@ -3772,13 +3771,13 @@
     LOBYTE(v30) = v30 | 0x80;
   if ( (256 << v9) & v11->uFlags )
     v30 |= 4;
-  if ( pGame->pIndoorCameraD3D->ApplyViewTransform_TrueIfStillVisible_BLV(pLevelDecorations[uDecorationID].vPosition.x,
+  if ( pEngine->pIndoorCameraD3D->ApplyViewTransform_TrueIfStillVisible_BLV(pLevelDecorations[uDecorationID].vPosition.x,
                                                                           pLevelDecorations[uDecorationID].vPosition.y,
                                                                           pLevelDecorations[uDecorationID].vPosition.z, &x, &y, &z, 1) )
   {
     if ( abs(x) >= abs(y) )
     {
-      pGame->pIndoorCameraD3D->Project(x, y, z, &a5, &a6);
+      pEngine->pIndoorCameraD3D->Project(x, y, z, &a5, &a6);
 
       assert(uNumBillboardsToDraw < 500);
 
@@ -3797,8 +3796,8 @@
       }
       else
       {*/
-        pBillboardRenderList[uNumBillboardsToDraw - 1].fov_x = pGame->pIndoorCameraD3D->fov_x;
-        pBillboardRenderList[uNumBillboardsToDraw - 1].fov_y = pGame->pIndoorCameraD3D->fov_y;
+        pBillboardRenderList[uNumBillboardsToDraw - 1].fov_x = pEngine->pIndoorCameraD3D->fov_x;
+        pBillboardRenderList[uNumBillboardsToDraw - 1].fov_y = pEngine->pIndoorCameraD3D->fov_y;
         LODWORD(v20) = 0;
         HIDWORD(v20) = floorf(pBillboardRenderList[uNumBillboardsToDraw - 1].fov_x + 0.5f);
         pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_x_scaler_packedfloat = fixpoint_mul(v11->scale, v20 / x);
@@ -3882,30 +3881,30 @@
   int v28; // [sp+1Ch] [bp-Ch]@1
   int v29; // [sp+24h] [bp-4h]@1
 
-  v8 = stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationY);
-  v29 = stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationY);
-  v28 = stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationX);
-  v9 = stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationX);
+  v8 = stru_5C6E00->Cos(pEngine->pIndoorCameraD3D->sRotationY);
+  v29 = stru_5C6E00->Sin(pEngine->pIndoorCameraD3D->sRotationY);
+  v28 = stru_5C6E00->Cos(pEngine->pIndoorCameraD3D->sRotationX);
+  v9 = stru_5C6E00->Sin(pEngine->pIndoorCameraD3D->sRotationX);
   //v11 = -pBLVRenderParams->vPartyPos.y;
   //v26 = -pBLVRenderParams->vPartyPos.x;
   //v27 = v9;
   //v12 = -pBLVRenderParams->vPartyPos.z;
-  if (pGame->pIndoorCameraD3D->sRotationX)
+  if (pEngine->pIndoorCameraD3D->sRotationX)
   {
-    v16 = v8 * -pGame->pIndoorCameraD3D->vPartyPos.x + v29 * -pGame->pIndoorCameraD3D->vPartyPos.y;
-    v17 = -65536 * pGame->pIndoorCameraD3D->vPartyPos.z;
-    this->field_0_party_dir_x = fixpoint_mul(v16, v28) + fixpoint_mul((-pGame->pIndoorCameraD3D->vPartyPos.z) << 16, v9);
-    this->field_4_party_dir_y = v8 * -pGame->pIndoorCameraD3D->vPartyPos.y - v29 * -pGame->pIndoorCameraD3D->vPartyPos.x;
+    v16 = v8 * -pEngine->pIndoorCameraD3D->vPartyPos.x + v29 * -pEngine->pIndoorCameraD3D->vPartyPos.y;
+    v17 = -65536 * pEngine->pIndoorCameraD3D->vPartyPos.z;
+    this->field_0_party_dir_x = fixpoint_mul(v16, v28) + fixpoint_mul((-pEngine->pIndoorCameraD3D->vPartyPos.z) << 16, v9);
+    this->field_4_party_dir_y = v8 * -pEngine->pIndoorCameraD3D->vPartyPos.y - v29 * -pEngine->pIndoorCameraD3D->vPartyPos.x;
     this->field_8_party_dir_z = fixpoint_mul(v17, v28) - fixpoint_mul(v16, v9);
   }
   else
   {
-    this->field_0_party_dir_x = v8 * -pGame->pIndoorCameraD3D->vPartyPos.x + v29 * -pGame->pIndoorCameraD3D->vPartyPos.y;
-    this->field_4_party_dir_y = v8 * -pGame->pIndoorCameraD3D->vPartyPos.y - v29 * -pGame->pIndoorCameraD3D->vPartyPos.x;
-    this->field_8_party_dir_z = (-pGame->pIndoorCameraD3D->vPartyPos.z) << 16;
+    this->field_0_party_dir_x = v8 * -pEngine->pIndoorCameraD3D->vPartyPos.x + v29 * -pEngine->pIndoorCameraD3D->vPartyPos.y;
+    this->field_4_party_dir_y = v8 * -pEngine->pIndoorCameraD3D->vPartyPos.y - v29 * -pEngine->pIndoorCameraD3D->vPartyPos.x;
+    this->field_8_party_dir_z = (-pEngine->pIndoorCameraD3D->vPartyPos.z) << 16;
   }
 
-  if (pGame->pIndoorCameraD3D->sRotationX)
+  if (pEngine->pIndoorCameraD3D->sRotationX)
   {
     v19 = fixpoint_mul(a2, v8) + fixpoint_mul(a3, v29);
 
@@ -3920,7 +3919,7 @@
     this->viewing_angle_from_west_east = a4;
   }
 
-  if (pGame->pIndoorCameraD3D->sRotationX)
+  if (pEngine->pIndoorCameraD3D->sRotationX)
   {
     v21 = fixpoint_mul(a5, v8) + fixpoint_mul(a6, v29);
 
@@ -4538,7 +4537,7 @@
         }
         if ( pIndoor->pFaces[v17].uAttributes & FACE_HAS_EVENT || !pIndoor->pFaceExtras[pIndoor->pFaces[v17].uFaceExtraID].uEventID )
           return 1;
-        if ( pCurrentScreen != SCREEN_BRANCHLESS_NPC_DIALOG )
+        if ( current_screen_type != SCREEN_BRANCHLESS_NPC_DIALOG )
           EventProcessor((signed __int16)pIndoor->pFaceExtras[pIndoor->pFaces[v17].uFaceExtraID].uEventID, a1, 1);
       }
       return 0;
@@ -4844,9 +4843,9 @@
   memset(&PortalFace, 0, sizeof(stru367));
 
   //get direction the face(îïðåäåëåíèå íàïðàâëåííîñòè ôåéñà)*********************************************************************************
-  if ( pFace->pFacePlane_old.vNormal.x * (pIndoor->pVertices[pIndoor->pFaces[uFaceID].pVertexIDs[0]].x - pGame->pIndoorCameraD3D->vPartyPos.x)
-     + pFace->pFacePlane_old.vNormal.y * (pIndoor->pVertices[pIndoor->pFaces[uFaceID].pVertexIDs[0]].y - pGame->pIndoorCameraD3D->vPartyPos.y)
-     + pFace->pFacePlane_old.vNormal.z * (pIndoor->pVertices[pIndoor->pFaces[uFaceID].pVertexIDs[0]].z - pGame->pIndoorCameraD3D->vPartyPos.z) < 0 )
+  if ( pFace->pFacePlane_old.vNormal.x * (pIndoor->pVertices[pIndoor->pFaces[uFaceID].pVertexIDs[0]].x - pEngine->pIndoorCameraD3D->vPartyPos.x)
+     + pFace->pFacePlane_old.vNormal.y * (pIndoor->pVertices[pIndoor->pFaces[uFaceID].pVertexIDs[0]].y - pEngine->pIndoorCameraD3D->vPartyPos.y)
+     + pFace->pFacePlane_old.vNormal.z * (pIndoor->pVertices[pIndoor->pFaces[uFaceID].pVertexIDs[0]].z - pEngine->pIndoorCameraD3D->vPartyPos.z) < 0 )
   {
     PortalFace.direction = true;
   }
@@ -4879,7 +4878,7 @@
   {
     for (uint i = 0; i < pFace->uNumVertices; ++i)
     {
-      pGame->pIndoorCameraD3D->ApplyViewTransform_TrueIfStillVisible_BLV(pIndoor->pVertices[pFace->pVertexIDs[i]].x,
+      pEngine->pIndoorCameraD3D->ApplyViewTransform_TrueIfStillVisible_BLV(pIndoor->pVertices[pFace->pVertexIDs[i]].x,
                                                                      pIndoor->pVertices[pFace->pVertexIDs[i]].y,
                                                                      pIndoor->pVertices[pFace->pVertexIDs[i]].z,
         &PortalFace._view_transformed_z[i + 3], &PortalFace._view_transformed_x[i + 3], &PortalFace._view_transformed_y[i + 3], 0);
@@ -5247,23 +5246,23 @@
   float v13; // [sp+Ch] [bp-4h]@2
   float v14; // [sp+Ch] [bp-4h]@6
 
-  if (pGame->pIndoorCameraD3D->sRotationX)
+  if (pEngine->pIndoorCameraD3D->sRotationX)
   {
     v13 = a1->vWorldPosition.x - (double)pParty->vPosition.x;
     v11 = a1->vWorldPosition.y - (double)pParty->vPosition.y;
     v4 = a1->vWorldPosition.z - (double)pParty->vPosition.z;
     //if ( pRenderer->pRenderD3D )
     //{
-      v5 = v11 * pGame->pIndoorCameraD3D->fRotationYSine + v13 * pGame->pIndoorCameraD3D->fRotationYCosine;
-      a1->vWorldViewPosition.y = v13 * pGame->pIndoorCameraD3D->fRotationYSine - v11 * pGame->pIndoorCameraD3D->fRotationYCosine;
+      v5 = v11 * pEngine->pIndoorCameraD3D->fRotationYSine + v13 * pEngine->pIndoorCameraD3D->fRotationYCosine;
+      a1->vWorldViewPosition.y = v13 * pEngine->pIndoorCameraD3D->fRotationYSine - v11 * pEngine->pIndoorCameraD3D->fRotationYCosine;
     /*}
     else
     {
       v5 = v13 * pBLVRenderParams->fCosineY - v11 * pBLVRenderParams->fSineY;
       a1->vWorldViewPosition.y = v13 * pBLVRenderParams->fSineY + v11 * pBLVRenderParams->fCosineY;
     }*/
-    a1->vWorldViewPosition.x = v5 * pGame->pIndoorCameraD3D->fRotationXCosine - v4 * pGame->pIndoorCameraD3D->fRotationXSine;
-    a1->vWorldViewPosition.z = v5 * pGame->pIndoorCameraD3D->fRotationXSine + v4 * pGame->pIndoorCameraD3D->fRotationXCosine;
+    a1->vWorldViewPosition.x = v5 * pEngine->pIndoorCameraD3D->fRotationXCosine - v4 * pEngine->pIndoorCameraD3D->fRotationXSine;
+    a1->vWorldViewPosition.z = v5 * pEngine->pIndoorCameraD3D->fRotationXSine + v4 * pEngine->pIndoorCameraD3D->fRotationXCosine;
   }
   else
   {
@@ -5272,8 +5271,8 @@
     a1->vWorldViewPosition.z = a1->vWorldPosition.z - (double)pParty->vPosition.z;
     //if ( pRenderer->pRenderD3D )
     //{
-      a1->vWorldViewPosition.x = v12 * pGame->pIndoorCameraD3D->fRotationYSine + v14 * pGame->pIndoorCameraD3D->fRotationYCosine;
-      a1->vWorldViewPosition.y = v14 * pGame->pIndoorCameraD3D->fRotationYSine - v12 * pGame->pIndoorCameraD3D->fRotationYCosine;
+      a1->vWorldViewPosition.x = v12 * pEngine->pIndoorCameraD3D->fRotationYSine + v14 * pEngine->pIndoorCameraD3D->fRotationYCosine;
+      a1->vWorldViewPosition.y = v14 * pEngine->pIndoorCameraD3D->fRotationYSine - v12 * pEngine->pIndoorCameraD3D->fRotationYCosine;
     /*}
     else
     {
--- a/Engine/Graphics/IndoorCameraD3D.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Graphics/IndoorCameraD3D.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,13 +3,12 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
-#include "../ErrorHandling.h"
+#include "Engine/Engine.h"
 #include "IndoorCameraD3D.h"
-#include "../Game.h"
 #include "Indoor.h"
 #include "Viewport.h"
-#include "../LOD.h"
-#include "../OurMath.h"
+#include "Engine/LOD.h"
+#include "Engine/OurMath.h"
 
 #include "stru9.h"
 
@@ -110,33 +109,33 @@
 //  int a2b; // [sp+18h] [bp+Ch]@5
   int a3a; // [sp+1Ch] [bp+10h]@5
 
-  to_x = x - pGame->pIndoorCameraD3D->vPartyPos.x;
-  to_y = y - pGame->pIndoorCameraD3D->vPartyPos.y;
-  if (pGame->pIndoorCameraD3D->sRotationX)
+  to_x = x - pEngine->pIndoorCameraD3D->vPartyPos.x;
+  to_y = y - pEngine->pIndoorCameraD3D->vPartyPos.y;
+  if (pEngine->pIndoorCameraD3D->sRotationX)
   {
-    to_z = (z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16;
+    to_z = (z - pEngine->pIndoorCameraD3D->vPartyPos.z) << 16;
     //if ( pRenderer->pRenderD3D )
     //{
-      v14 = (unsigned __int64)(to_x * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y)
-          + (unsigned __int64)(to_y * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y);
-      v9 = (unsigned __int64)(to_x * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y)
-         - (unsigned __int64)(to_y * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y);
+      v14 = (unsigned __int64)(to_x * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y)
+          + (unsigned __int64)(to_y * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y);
+      v9 = (unsigned __int64)(to_x * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y)
+         - (unsigned __int64)(to_y * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y);
     //}
-    a3a = (z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16;
-    *pOutX = fixpoint_mul(v14, pGame->pIndoorCameraD3D->int_cosine_x) - fixpoint_mul(to_z, pGame->pIndoorCameraD3D->int_sine_x);
+    a3a = (z - pEngine->pIndoorCameraD3D->vPartyPos.z) << 16;
+    *pOutX = fixpoint_mul(v14, pEngine->pIndoorCameraD3D->int_cosine_x) - fixpoint_mul(to_z, pEngine->pIndoorCameraD3D->int_sine_x);
     *pOutZ = v9;
-    *pOutY = fixpoint_mul(v14, pGame->pIndoorCameraD3D->int_sine_x) + fixpoint_mul(a3a, pGame->pIndoorCameraD3D->int_cosine_x);
+    *pOutY = fixpoint_mul(v14, pEngine->pIndoorCameraD3D->int_sine_x) + fixpoint_mul(a3a, pEngine->pIndoorCameraD3D->int_cosine_x);
   }
   else
   {
-    *pOutY = (z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16;
+    *pOutY = (z - pEngine->pIndoorCameraD3D->vPartyPos.z) << 16;
     //if ( pRenderer->pRenderD3D )
     //{
       //v10 = pOutX;
-      *pOutX = (unsigned __int64)(to_x * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y)
-             + (unsigned __int64)(to_y * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y);
-      *pOutZ = (unsigned __int64)(to_x * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y)
-             - (unsigned __int64)(to_y * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y);
+      *pOutX = (unsigned __int64)(to_x * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y)
+             + (unsigned __int64)(to_y * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y);
+      *pOutZ = (unsigned __int64)(to_x * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y)
+             - (unsigned __int64)(to_y * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y);
     //}
   }
   if (!bDoNotShow)
@@ -170,7 +169,7 @@
 //----- (00436523) --------------------------------------------------------
 void IndoorCameraD3D::ViewTransform(RenderVertexSoft *a1a, unsigned int uNumVertices)
 {
-  if (byte_4D864C && pGame->uFlags & 0x80 ||
+  if (byte_4D864C && pEngine->uFlags & 0x80 ||
       uCurrentlyLoadedLevelType == LEVEL_Indoor)
   {
     float sin_x = fRotationXSine,
@@ -180,7 +179,7 @@
 
     //v4 = uNumVertices;
     //v7 = pIndoorCamera->fRotationXSine;
-    if (pGame->pIndoorCameraD3D->sRotationX)
+    if (pEngine->pIndoorCameraD3D->sRotationX)
     {
 
         //_EAX = a1a;
@@ -227,9 +226,9 @@
                                          // 4[pIndoorCamera->fRotationYSine]
                                          // 5[pIndoorCamera->fRotationYCosine]
             }*/
-            st0 = sin_y * (a1a[i].vWorldPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x) - cos_y * (a1a[i].vWorldPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y);
-            st1 = cos_y * (a1a[i].vWorldPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x) + sin_y * (a1a[i].vWorldPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y);
-            st2 = (a1a[i].vWorldPosition.z - pGame->pIndoorCameraD3D->vPartyPos.z);
+            st0 = sin_y * (a1a[i].vWorldPosition.x - pEngine->pIndoorCameraD3D->vPartyPos.x) - cos_y * (a1a[i].vWorldPosition.y - pEngine->pIndoorCameraD3D->vPartyPos.y);
+            st1 = cos_y * (a1a[i].vWorldPosition.x - pEngine->pIndoorCameraD3D->vPartyPos.x) + sin_y * (a1a[i].vWorldPosition.y - pEngine->pIndoorCameraD3D->vPartyPos.y);
+            st2 = (a1a[i].vWorldPosition.z - pEngine->pIndoorCameraD3D->vPartyPos.z);
           }
           if (false)//else
           {
@@ -295,9 +294,9 @@
                                          // 4[pIndoorCamera->fRotationYSine]
                                          // 5[pIndoorCamera->fRotationYCosine]
             }*/
-            st0 = cos_y * (a1a[i].vWorldPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y) + sin_y * (a1a[i].vWorldPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x);
-            st1 = cos_y * (a1a[i].vWorldPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x) - sin_y * (a1a[i].vWorldPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y);
-            st2 = (a1a[i].vWorldPosition.z - pGame->pIndoorCameraD3D->vPartyPos.z);
+            st0 = cos_y * (a1a[i].vWorldPosition.y - pEngine->pIndoorCameraD3D->vPartyPos.y) + sin_y * (a1a[i].vWorldPosition.x - pEngine->pIndoorCameraD3D->vPartyPos.x);
+            st1 = cos_y * (a1a[i].vWorldPosition.x - pEngine->pIndoorCameraD3D->vPartyPos.x) - sin_y * (a1a[i].vWorldPosition.y - pEngine->pIndoorCameraD3D->vPartyPos.y);
+            st2 = (a1a[i].vWorldPosition.z - pEngine->pIndoorCameraD3D->vPartyPos.z);
           }
 
           a1a[i].vWorldViewPosition.x = st1*cos_x - st2*sin_x;
@@ -361,9 +360,9 @@
               fstp    dword ptr [eax+10h]
               fstp    dword ptr [eax+14h]
             }*/
-            a1a[i].vWorldViewPosition.x = cos_y * (a1a[i].vWorldPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x) + sin_y * (a1a[i].vWorldPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y);
-            a1a[i].vWorldViewPosition.y = sin_y * (a1a[i].vWorldPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x) - cos_y * (a1a[i].vWorldPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y);
-            a1a[i].vWorldViewPosition.z = (a1a[i].vWorldPosition.z - pGame->pIndoorCameraD3D->vPartyPos.z);
+            a1a[i].vWorldViewPosition.x = cos_y * (a1a[i].vWorldPosition.x - pEngine->pIndoorCameraD3D->vPartyPos.x) + sin_y * (a1a[i].vWorldPosition.y - pEngine->pIndoorCameraD3D->vPartyPos.y);
+            a1a[i].vWorldViewPosition.y = sin_y * (a1a[i].vWorldPosition.x - pEngine->pIndoorCameraD3D->vPartyPos.x) - cos_y * (a1a[i].vWorldPosition.y - pEngine->pIndoorCameraD3D->vPartyPos.y);
+            a1a[i].vWorldViewPosition.z = (a1a[i].vWorldPosition.z - pEngine->pIndoorCameraD3D->vPartyPos.z);
           }
           if (false)//else
           {
@@ -412,13 +411,13 @@
   v8 = fRotationXCosine;
   result = fRotationXSine;
   v7 = fRotationXSine;
-  vCamToVertexX = a1->vWorldPosition.x - (double)pGame->pIndoorCameraD3D->vPartyPos.x;
-  vCamToVertexY = a1->vWorldPosition.y - (double)pGame->pIndoorCameraD3D->vPartyPos.y;
-  vCamToVertexZ = a1->vWorldPosition.z - (double)pGame->pIndoorCameraD3D->vPartyPos.z;
+  vCamToVertexX = a1->vWorldPosition.x - (double)pEngine->pIndoorCameraD3D->vPartyPos.x;
+  vCamToVertexY = a1->vWorldPosition.y - (double)pEngine->pIndoorCameraD3D->vPartyPos.y;
+  vCamToVertexZ = a1->vWorldPosition.z - (double)pEngine->pIndoorCameraD3D->vPartyPos.z;
   v3 = fRotationYCosine;
   v4 = fRotationYSine;
   v5 = vCamToVertexY * fRotationYSine + fRotationYCosine * vCamToVertexX;
-  if (pGame->pIndoorCameraD3D->sRotationX)
+  if (pEngine->pIndoorCameraD3D->sRotationX)
   {
     v6 = vCamToVertexY * fRotationYSine + fRotationYCosine * vCamToVertexX;
     a1->vWorldViewPosition.x = v5 * fRotationXCosine + fRotationXSine * vCamToVertexZ;
@@ -505,9 +504,9 @@
     return false;
 
   //really strange cull; dot(to_cam, normal) < 0 means we see the BACK face, not font %_%
-  if ( (a2->vWorldPosition.z - (double)pGame->pIndoorCameraD3D->vPartyPos.z) * (double)pFace->pFacePlane_old.vNormal.z
-     + (a2->vWorldPosition.y - (double)pGame->pIndoorCameraD3D->vPartyPos.y) * (double)pFace->pFacePlane_old.vNormal.y
-     + (a2->vWorldPosition.x - (double)pGame->pIndoorCameraD3D->vPartyPos.x) * (double)pFace->pFacePlane_old.vNormal.x < 0.0)
+  if ( (a2->vWorldPosition.z - (double)pEngine->pIndoorCameraD3D->vPartyPos.z) * (double)pFace->pFacePlane_old.vNormal.z
+     + (a2->vWorldPosition.y - (double)pEngine->pIndoorCameraD3D->vPartyPos.y) * (double)pFace->pFacePlane_old.vNormal.y
+     + (a2->vWorldPosition.x - (double)pEngine->pIndoorCameraD3D->vPartyPos.x) * (double)pFace->pFacePlane_old.vNormal.x < 0.0)
     return false;
 
   return true;
@@ -769,9 +768,9 @@
   double v4; // st7@1
   IndoorCameraD3D_Vec3 v8; // [sp+8h] [bp-1Ch]@1
 
-  v8.x = (double)pGame->pIndoorCameraD3D->vPartyPos.x;
-  v8.y = (double)pGame->pIndoorCameraD3D->vPartyPos.y;
-  v8.z = (double)pGame->pIndoorCameraD3D->vPartyPos.z;
+  v8.x = (double)pEngine->pIndoorCameraD3D->vPartyPos.x;
+  v8.y = (double)pEngine->pIndoorCameraD3D->vPartyPos.y;
+  v8.z = (double)pEngine->pIndoorCameraD3D->vPartyPos.z;
   Vec3Transform(a1, a2);
 
   v4 = v8.x * a2->x + v8.y * a2->y + v8.z * a2->z;
@@ -842,9 +841,9 @@
   memcpy(&a2[*pOutNumVertices + 1], &a2[1], sizeof(a2[*pOutNumVertices + 1]));
 
   if ( (signed int)*pOutNumVertices <= 3
-    || (((v18.vWorldPosition.z - (double)pGame->pIndoorCameraD3D->vPartyPos.z) * thisa->face_plane.vNormal.z
-       + (v18.vWorldPosition.y - (double)pGame->pIndoorCameraD3D->vPartyPos.y) * thisa->face_plane.vNormal.y
-       + (v18.vWorldPosition.x - (double)pGame->pIndoorCameraD3D->vPartyPos.x) * thisa->face_plane.vNormal.x < 0.0) ? (v6 = 1.0) : (v6 = -1.0),
+    || (((v18.vWorldPosition.z - (double)pEngine->pIndoorCameraD3D->vPartyPos.z) * thisa->face_plane.vNormal.z
+       + (v18.vWorldPosition.y - (double)pEngine->pIndoorCameraD3D->vPartyPos.y) * thisa->face_plane.vNormal.y
+       + (v18.vWorldPosition.x - (double)pEngine->pIndoorCameraD3D->vPartyPos.x) * thisa->face_plane.vNormal.x < 0.0) ? (v6 = 1.0) : (v6 = -1.0),
         (signed int)*pOutNumVertices <= 0) )
     return 0;
 
@@ -907,7 +906,7 @@
   //bool a6a; // [sp+70h] [bp+1Ch]@5
 
   //v17 = 0.0;
-  //thisa = pGame->pStru9Instance;
+  //thisa = pEngine->pStru9Instance;
   
   static RenderVertexSoft sr_vertices_50D9D8[64];
 
@@ -940,7 +939,7 @@
     a5.x = a4[i].x;
     a5.y = a4[i].y;
     a5.z = a4[i].z;
-    pGame->pStru9Instance->CalcPortalShape(v15, *pOutNumVertices, v14, pOutNumVertices, &a5, a4[i].dot, (char *)&a7a, _unused);
+    pEngine->pStru9Instance->CalcPortalShape(v15, *pOutNumVertices, v14, pOutNumVertices, &a5, a4[i].dot, (char *)&a7a, _unused);
     //v12 = *pOutNumVertices;
     if (*pOutNumVertices < v11)
     {
@@ -1223,7 +1222,7 @@
 
   for (uint i = 0; i < uNumVertices; ++i)
   {
-    if (byte_4D864C && pGame->uFlags & 0x80 || uCurrentlyLoadedLevelType == LEVEL_Indoor)
+    if (byte_4D864C && pEngine->uFlags & 0x80 || uCurrentlyLoadedLevelType == LEVEL_Indoor)
     {
       v7 = 1.0 / pVertices[i].vWorldViewPosition.x;
 
@@ -1356,24 +1355,24 @@
 
   fRotationYSine = sin((pi_double + pi_double) * (double)sRotationY / 2048.0);
   fRotationYCosine = cos((pi_double + pi_double) * (double)sRotationY / 2048.0);
-  if (byte_4D864C && pGame->uFlags & 0x80 || uCurrentlyLoadedLevelType == LEVEL_Indoor)
+  if (byte_4D864C && pEngine->uFlags & 0x80 || uCurrentlyLoadedLevelType == LEVEL_Indoor)
   {
     fRotationXSine = sin((pi_double + pi_double) * (double)-sRotationX / 2048.0);
     fRotationXCosine = cos((pi_double + pi_double) * (double)-sRotationX / 2048.0);
 
-    int_sine_y   = stru_5C6E00->Sin( pGame->pIndoorCameraD3D->sRotationY);
-    int_cosine_y = stru_5C6E00->Cos( pGame->pIndoorCameraD3D->sRotationY);
-    int_sine_x   = stru_5C6E00->Sin(-pGame->pIndoorCameraD3D->sRotationX);
-    int_cosine_x = stru_5C6E00->Cos(-pGame->pIndoorCameraD3D->sRotationX);
+    int_sine_y   = stru_5C6E00->Sin( pEngine->pIndoorCameraD3D->sRotationY);
+    int_cosine_y = stru_5C6E00->Cos( pEngine->pIndoorCameraD3D->sRotationY);
+    int_sine_x   = stru_5C6E00->Sin(-pEngine->pIndoorCameraD3D->sRotationX);
+    int_cosine_x = stru_5C6E00->Cos(-pEngine->pIndoorCameraD3D->sRotationX);
   }
   else
   {
     fRotationXSine = sin((pi_double + pi_double) * (double)sRotationX / 2048.0);
     fRotationXCosine = cos((pi_double + pi_double) * (double)sRotationX / 2048.0);
 
-    int_sine_y   = stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationY);
-    int_cosine_y = stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationY);
-    int_sine_x   = stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationX);
-    int_cosine_x = stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationX);
+    int_sine_y   = stru_5C6E00->Sin(pEngine->pIndoorCameraD3D->sRotationY);
+    int_cosine_y = stru_5C6E00->Cos(pEngine->pIndoorCameraD3D->sRotationY);
+    int_sine_x   = stru_5C6E00->Sin(pEngine->pIndoorCameraD3D->sRotationX);
+    int_cosine_x = stru_5C6E00->Cos(pEngine->pIndoorCameraD3D->sRotationX);
   }
 }
\ No newline at end of file
--- a/Engine/Graphics/Level/Decoration.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Graphics/Level/Decoration.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,9 +3,9 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
+#include "Engine/Engine.h"
 #include "Decoration.h"
 #include "../../Party.h"
-#include "../../ErrorHandling.h"
 
 std::array<LevelDecoration, 3000> pLevelDecorations;
 size_t uNumLevelDecorations;
--- a/Engine/Graphics/LightmapBuilder.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Graphics/LightmapBuilder.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,15 +3,13 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
+#include "Engine/Engine.h"
 #include "LightmapBuilder.h"
-#include "../Game.h"
-#include "../stru314.h"
+#include "Engine/stru314.h"
 #include "Outdoor.h"
-#include "../Log.h"
-#include "../ErrorHandling.h"
 
 #include "Lights.h"
-#include "..\MMT.h"
+#include "Engine/MMT.h"
 #include "stru9.h"
 
 LightsStack_StationaryLight_ *pStationaryLightsStack = new LightsStack_StationaryLight_;
@@ -126,8 +124,8 @@
     }
   }
 
-  minz = pGame->pIndoorCameraD3D->GetPolygonMinZ(a1, uStripType);
-  maxz = pGame->pIndoorCameraD3D->GetPolygonMaxZ(a1, uStripType);
+  minz = pEngine->pIndoorCameraD3D->GetPolygonMinZ(a1, uStripType);
+  maxz = pEngine->pIndoorCameraD3D->GetPolygonMaxZ(a1, uStripType);
 
   float bounding_x1 = tX_0 - (float)pLight->uRadius; //13 976 - 128 = 13848.0
   float bounding_y1 = tY_0 - (float)pLight->uRadius; // 3 800 - 128 = 3672.0
@@ -566,7 +564,7 @@
     for (uint i = 0; i < uNumVertices; ++i)
       memcpy(&static_69B140[i], a5 + i, sizeof(RenderVertexSoft));
 
-    if (pGame->pIndoorCameraD3D->_437376(a3, static_69B140, &uNumVertices) == 1)
+    if (pEngine->pIndoorCameraD3D->_437376(a3, static_69B140, &uNumVertices) == 1)
     {
       if ( !uNumVertices )
         return false;
@@ -579,7 +577,7 @@
   static_69B110.field_4.y = a3->face_plane.vNormal.y;
   static_69B110.field_4.z = a3->face_plane.vNormal.z;
   static_69B110.dist = a3->face_plane.dist;
-  if (!pGame->pIndoorCameraD3D->GetFacetOrientation(a3->polygonType, &static_69B110.field_4,
+  if (!pEngine->pIndoorCameraD3D->GetFacetOrientation(a3->polygonType, &static_69B110.field_4,
           &static_69B110.field_10, &static_69B110.field_1C))
   {
     MessageBoxW(nullptr, L"Error: Failed to get the facet orientation", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:119", 0);
@@ -682,7 +680,7 @@
   lightmap->NumVertices = 4;
 
   //Brightness(ÿðêîñòü)/////////////////////////////////
-  if (~pGame->uFlags2 & 4)
+  if (~pEngine->uFlags2 & 4)
     lightmap->fBrightness = flt_3C8C2C_lightmaps_brightness;
   else
   {
@@ -720,7 +718,7 @@
   }
  //Brightness(ÿðêîñòü)/////////////////////////////////////////////////////
 
-  if (!pGame->pStru9Instance->_4980B9(a9, uNumVertices,
+  if (!pEngine->pStru9Instance->_4980B9(a9, uNumVertices,
                                       a7->field_4.x, a7->field_4.y, a7->field_4.z,
                                       lightmap->pVertices, &lightmap->NumVertices))
     return false;
@@ -732,8 +730,8 @@
   if ( v45 != uNumVertices && v45 > 0 )
     _45C4B9(uNumVertices, a9, lightmap);
 
-  pGame->pIndoorCameraD3D->ViewTransform(lightmap->pVertices, lightmap->NumVertices);
-  pGame->pIndoorCameraD3D->Project(lightmap->pVertices, lightmap->NumVertices, 0);
+  pEngine->pIndoorCameraD3D->ViewTransform(lightmap->pVertices, lightmap->NumVertices);
+  pEngine->pIndoorCameraD3D->Project(lightmap->pVertices, lightmap->NumVertices, 0);
 
   unsigned int _a4 = 0;
   if ( !(uClipFlag & 1) )
@@ -742,13 +740,13 @@
   {
     if ( uClipFlag & 2 )
     {
-      pGame->pIndoorCameraD3D->_436CDC_mess_with_lightmap__clipflag_2(lightmap->pVertices, lightmap->NumVertices, field_3C8C34, &_a4);
-      pGame->pIndoorCameraD3D->_437143(_a4, lightmap->pVertices, field_3C8C34, &lightmap->NumVertices);
+      pEngine->pIndoorCameraD3D->_436CDC_mess_with_lightmap__clipflag_2(lightmap->pVertices, lightmap->NumVertices, field_3C8C34, &_a4);
+      pEngine->pIndoorCameraD3D->_437143(_a4, lightmap->pVertices, field_3C8C34, &lightmap->NumVertices);
     }
     else if ( uClipFlag & 4 )
     {
-      pGame->pIndoorCameraD3D->_436F09_mess_with_lightmap__clipflag_4(lightmap->pVertices, lightmap->NumVertices, field_3C8C34, &_a4);
-      pGame->pIndoorCameraD3D->_437143(_a4, lightmap->pVertices, field_3C8C34, &lightmap->NumVertices);
+      pEngine->pIndoorCameraD3D->_436F09_mess_with_lightmap__clipflag_4(lightmap->pVertices, lightmap->NumVertices, field_3C8C34, &_a4);
+      pEngine->pIndoorCameraD3D->_437143(_a4, lightmap->pVertices, field_3C8C34, &lightmap->NumVertices);
     }
     else
       MessageBoxW(nullptr, L"Undefined clip flag specified", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Light.cpp:330", 0);
@@ -852,7 +850,7 @@
   if (std__vector_000004_size == 0)
     return true;
   
-  if (byte_4D864C && pGame->uFlags & GAME_FLAGS_1_01_lightmap_related)
+  if (byte_4D864C && pEngine->uFlags & GAME_FLAGS_1_01_lightmap_related)
     return true;
 
   pRenderer->BeginLightmaps();
@@ -908,10 +906,10 @@
   {
     float v18;
     if (fabs(z_bias) < 1e-5)
-      v18 = 1.0 - 1.0 / ((1.0f / pGame->pIndoorCameraD3D->GetShadingDistMist()) * pLightmap->pVertices[i].vWorldViewPosition.x * 1000.0);
+      v18 = 1.0 - 1.0 / ((1.0f / pEngine->pIndoorCameraD3D->GetShadingDistMist()) * pLightmap->pVertices[i].vWorldViewPosition.x * 1000.0);
 	else
     {
-      v18 = 1.0 - 1.0 / ((1.0f / pGame->pIndoorCameraD3D->GetShadingDistMist()) * pLightmap->pVertices[i].vWorldViewPosition.x * 1000.0) - z_bias;
+      v18 = 1.0 - 1.0 / ((1.0f / pEngine->pIndoorCameraD3D->GetShadingDistMist()) * pLightmap->pVertices[i].vWorldViewPosition.x * 1000.0) - z_bias;
       if (v18 < 0.000099999997)
         v18 = 0.000099999997;
     }
@@ -1220,9 +1218,9 @@
   bool a2a; // [sp+20h] [bp+8h]@6
 
   __debugbreak();//Not used?
-  result = (bool)pGame->pIndoorCameraD3D;
+  result = (bool)pEngine->pIndoorCameraD3D;
   v3 = this;
-  thisa = pGame->pIndoorCameraD3D;
+  thisa = pEngine->pIndoorCameraD3D;
   if ( bit_one_for_list1__bit_two_for_list2 & 1 )
   {
     v7 = 0;
@@ -1231,7 +1229,7 @@
       v4 = this->std__vector_000004[0].pVertices;
       do
       {
-        pGame->pIndoorCameraD3D->debug_outline_sw(v4, *((unsigned int *)v4 - 1), 0xFF00u, 0.0);
+        pEngine->pIndoorCameraD3D->debug_outline_sw(v4, *((unsigned int *)v4 - 1), 0xFF00u, 0.0);
         ++v7;
         v4 = (RenderVertexSoft *)((char *)v4 + 3100);
         result = v7;
@@ -1247,7 +1245,7 @@
       v5 = v3->std__vector_183808[0].pVertices;
       do
       {
-        pGame->pIndoorCameraD3D->debug_outline_sw(v5, *((unsigned int *)v5 - 1), 0xC04000u, 0.00019999999);
+        pEngine->pIndoorCameraD3D->debug_outline_sw(v5, *((unsigned int *)v5 - 1), 0xC04000u, 0.00019999999);
         ++a2a;
         v5 = (RenderVertexSoft *)((char *)v5 + 3100);
         result = a2a;
--- a/Engine/Graphics/Outdoor.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Graphics/Outdoor.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,39 +3,38 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
-#include "../ErrorHandling.h"
+
+#include "Engine/Engine.h"
 
 #include "stru6.h"
 #include "Weather.h"
 #include "Sprites.h"
 #include "LightmapBuilder.h"
 #include "Outdoor.h"
-#include "../Party.h"
-#include "../Objects/SpriteObject.h"
-#include "../LOD.h"
+#include "Engine/Party.h"
+#include "Engine/Objects/SpriteObject.h"
+#include "Engine/LOD.h"
 #include "PaletteManager.h"
 #include "GUI/GUIProgressBar.h"
 #include "Media/Audio/AudioPlayer.h"
 #include "DecorationList.h"
-#include "../OurMath.h"
-#include "../Objects/ObjectList.h"
-#include "../Game.h"
-#include "../Objects/Actor.h"
-#include "../Objects/Chest.h"
-#include "../stru123.h"
-#include "../Timer.h"
+#include "Engine/OurMath.h"
+#include "Engine/Objects/ObjectList.h"
+#include "Engine/Objects/Actor.h"
+#include "Engine/Objects/Chest.h"
+#include "Engine/stru123.h"
+#include "Engine/Timer.h"
 #include "Viewport.h"
-#include "../Events.h"
+#include "Engine/Events.h"
 #include "ParticleEngine.h"
-#include "../TurnEngine/TurnEngine.h"
-
-#include "../MM7.h"
+#include "Engine/TurnEngine/TurnEngine.h"
+
 #include "Lights.h"
 
 #include "GUI/GUIWindow.h"
 #include "Level/Decoration.h"
-#include "../ZlibWrapper.h"
-#include "../MMT.h"
+#include "Engine/ZlibWrapper.h"
+#include "Engine/MMT.h"
 
 MapStartPoint uLevel_StartingPointType; // weak
 
@@ -84,9 +83,9 @@
 void OutdoorLocation::ExecDraw(unsigned int bRedraw)
 {
 
-  pGame->pIndoorCameraD3D->debug_flags = 0;
+  pEngine->pIndoorCameraD3D->debug_flags = 0;
   if (viewparams->draw_d3d_outlines)
-    pGame->pIndoorCameraD3D->debug_flags |= ODM_RENDER_DRAW_D3D_OUTLINES;
+    pEngine->pIndoorCameraD3D->debug_flags |= ODM_RENDER_DRAW_D3D_OUTLINES;
 
   if (bRedraw || true/*pRenderer->pRenderD3D*/)
   {
@@ -105,7 +104,7 @@
   if ( pParty->uCurrentMinute != pOutdoor->uLastSunlightUpdateMinute )
     pOutdoor->UpdateSunlightVectors();
   pOutdoor->UpdateFog();
-  //pGame->pIndoorCameraD3D->sr_Reset_list_0037C();
+  //pEngine->pIndoorCameraD3D->sr_Reset_list_0037C();
 
   //if (pRenderer->pRenderD3D) // d3d - redraw always
   {
@@ -133,17 +132,17 @@
   /*if ( !pRenderer->pRenderD3D )
   {
     pRenderer->ExecOutdoorDrawSW();
-    pGame->pIndoorCameraD3D->sr_438240_draw_lits();
+    pEngine->pIndoorCameraD3D->sr_438240_draw_lits();
   }*/
-  pGame->PushStationaryLights(-1);
-  pGame->PrepareBloodsplats();
+  pEngine->PushStationaryLights(-1);
+  pEngine->PrepareBloodsplats();
   if (bRedraw)
     pOutdoor->UpdateDiscoveredArea(WorldPosToGridCellX(pParty->vPosition.x), WorldPosToGridCellZ(pParty->vPosition.y), 1);
-  pGame->uFlags2 &= 0xFFFFFFFEu;//~0x00000001
+  pEngine->uFlags2 &= 0xFFFFFFFEu;//~0x00000001
   if (/*pRenderer->pRenderD3D*/true && pRenderer->bUsingSpecular)
-    pGame->pLightmapBuilder->uFlags |= 1;
+    pEngine->pLightmapBuilder->uFlags |= 1;
   else
-    pGame->pLightmapBuilder->uFlags &= 0xFFFFFFFEu;//~0x00000001
+    pEngine->pLightmapBuilder->uFlags &= 0xFFFFFFFEu;//~0x00000001
 
   uNumDecorationsDrawnThisFrame = 0;
   uNumSpritesDrawnThisFrame = 0;
@@ -162,11 +161,11 @@
 void OutdoorLocation::Draw()
 {
   bool redrawWorld = true;
-  if ( !(pParty->uFlags & 2) && !(pGame->uFlags2 & 1) )
+  if ( !(pParty->uFlags & 2) && !(pEngine->uFlags2 & 1) )
     redrawWorld = false;
   pOutdoor->ExecDraw(redrawWorld);
 
-  pGame->DrawParticles();
+  pEngine->DrawParticles();
   //pWeather->Draw();//åñëè ðàñêîììåíòèðîâàòü ñêîðîñòü ñíåãà áûñòðåå
   trail_particle_generator.UpdateParticles();
 }
@@ -623,9 +622,9 @@
     currVertex--;
   }
 
-  if ( ((double)pGame->pIndoorCameraD3D->vPartyPos.x - a2->vWorldPosition.x) * v26
-    + ((double)pGame->pIndoorCameraD3D->vPartyPos.z - a2->vWorldPosition.z) * v25
-    + ((double)pGame->pIndoorCameraD3D->vPartyPos.y - a2->vWorldPosition.y) * v24 > 0.0 )
+  if ( ((double)pEngine->pIndoorCameraD3D->vPartyPos.x - a2->vWorldPosition.x) * v26
+    + ((double)pEngine->pIndoorCameraD3D->vPartyPos.z - a2->vWorldPosition.z) * v25
+    + ((double)pEngine->pIndoorCameraD3D->vPartyPos.y - a2->vWorldPosition.y) * v24 > 0.0 )
   {
 
     v19 = a2[1].vWorldViewPosition.x - a2->vWorldViewPosition.x;
@@ -2438,7 +2437,7 @@
         else
         {
           v49 = 1;
-		  pGame->pStru6Instance->_4A7F74(pActors[i].vPosition.x, pActors[i].vPosition.y, z);
+		  pEngine->pStru6Instance->_4A7F74(pActors[i].vPosition.x, pActors[i].vPosition.y, z);
           v4 = (1.0 - (double)pActors[i].uCurrentActionTime / (double)pActors[i].uCurrentActionLength) *
 			   (double)(2 * pActors[i].uActorHeight);
           z -= floorf(v4 + 0.5f);
@@ -2446,8 +2445,8 @@
             z = pActors[i].vPosition.z;
         }
       }
-      v8 = stru_5C6E00->Atan2(pActors[i].vPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x,
-                              pActors[i].vPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y);
+      v8 = stru_5C6E00->Atan2(pActors[i].vPosition.x - pEngine->pIndoorCameraD3D->vPartyPos.x,
+                              pActors[i].vPosition.y - pEngine->pIndoorCameraD3D->vPartyPos.y);
 	  LOWORD(v9) = pActors[i].uYawAngle;
       v41 = ((signed int)(stru_5C6E00->uIntegerPi + ((signed int)stru_5C6E00->uIntegerPi >> 3) + v9 - v8) >> 8) & 7;
       if ( pParty->bTurnBasedModeOn )
@@ -2486,34 +2485,34 @@
         //LOBYTE(v16) = _4E94D3_light_type;
         pMobileLightsStack->AddLight(x, y, z, 0, v15->uGlowRadius, 0xFFu, 0xFFu, 0xFFu, _4E94D3_light_type);
       }
-      v17 = (x - pGame->pIndoorCameraD3D->vPartyPos.x) << 16;
-      if (pGame->pIndoorCameraD3D->sRotationX)
+      v17 = (x - pEngine->pIndoorCameraD3D->vPartyPos.x) << 16;
+      if (pEngine->pIndoorCameraD3D->sRotationX)
       {
-        v18 = (y - pGame->pIndoorCameraD3D->vPartyPos.y) << 16;
-        v47 = (fixpoint_mul(v17, pGame->pIndoorCameraD3D->int_cosine_y) + fixpoint_mul(v18, pGame->pIndoorCameraD3D->int_sine_y));
-        v50 = fixpoint_mul(v17, pGame->pIndoorCameraD3D->int_sine_y);
-        v53 = fixpoint_mul(v18, pGame->pIndoorCameraD3D->int_cosine_y);
-        v44 = (z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16;
-        v19 = (fixpoint_mul(v44, pGame->pIndoorCameraD3D->int_sine_x) + fixpoint_mul(v47, pGame->pIndoorCameraD3D->int_cosine_x));
-        X = fixpoint_mul(v44, pGame->pIndoorCameraD3D->int_sine_x) + fixpoint_mul(v47, pGame->pIndoorCameraD3D->int_cosine_x);
+        v18 = (y - pEngine->pIndoorCameraD3D->vPartyPos.y) << 16;
+        v47 = (fixpoint_mul(v17, pEngine->pIndoorCameraD3D->int_cosine_y) + fixpoint_mul(v18, pEngine->pIndoorCameraD3D->int_sine_y));
+        v50 = fixpoint_mul(v17, pEngine->pIndoorCameraD3D->int_sine_y);
+        v53 = fixpoint_mul(v18, pEngine->pIndoorCameraD3D->int_cosine_y);
+        v44 = (z - pEngine->pIndoorCameraD3D->vPartyPos.z) << 16;
+        v19 = (fixpoint_mul(v44, pEngine->pIndoorCameraD3D->int_sine_x) + fixpoint_mul(v47, pEngine->pIndoorCameraD3D->int_cosine_x));
+        X = fixpoint_mul(v44, pEngine->pIndoorCameraD3D->int_sine_x) + fixpoint_mul(v47, pEngine->pIndoorCameraD3D->int_cosine_x);
         if ( v19 < 262144 || v19 > pODMRenderParams->shading_dist_mist << 16 )
           continue;
         v20 = v53 - v50;
         v42 = v53 - v50;
-        v21 = (fixpoint_mul(v44, pGame->pIndoorCameraD3D->int_cosine_x) - fixpoint_mul(v47, pGame->pIndoorCameraD3D->int_sine_x));
+        v21 = (fixpoint_mul(v44, pEngine->pIndoorCameraD3D->int_cosine_x) - fixpoint_mul(v47, pEngine->pIndoorCameraD3D->int_sine_x));
       }
       else
       {
-        v48 = (y - pGame->pIndoorCameraD3D->vPartyPos.y) << 16;
-        v51 = fixpoint_mul(v17, pGame->pIndoorCameraD3D->int_cosine_y);
-        v22 = fixpoint_mul(v48, pGame->pIndoorCameraD3D->int_sine_y);
+        v48 = (y - pEngine->pIndoorCameraD3D->vPartyPos.y) << 16;
+        v51 = fixpoint_mul(v17, pEngine->pIndoorCameraD3D->int_cosine_y);
+        v22 = fixpoint_mul(v48, pEngine->pIndoorCameraD3D->int_sine_y);
         X = v22 + v51;
         if ( v22 + v51 < 262144 || v22 + v51 > pODMRenderParams->shading_dist_mist << 16 )
           continue;
-        v23 = fixpoint_mul(((x - pGame->pIndoorCameraD3D->vPartyPos.x) << 16), pGame->pIndoorCameraD3D->int_sine_y);
-        v20 = fixpoint_mul(v48, pGame->pIndoorCameraD3D->int_cosine_y) - v23;
-        v42 = fixpoint_mul(v48, pGame->pIndoorCameraD3D->int_cosine_y) - v23;
-        v21 = (z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16;
+        v23 = fixpoint_mul(((x - pEngine->pIndoorCameraD3D->vPartyPos.x) << 16), pEngine->pIndoorCameraD3D->int_sine_y);
+        v20 = fixpoint_mul(v48, pEngine->pIndoorCameraD3D->int_cosine_y) - v23;
+        v42 = fixpoint_mul(v48, pEngine->pIndoorCameraD3D->int_cosine_y) - v23;
+        v21 = (z - pEngine->pIndoorCameraD3D->vPartyPos.z) << 16;
       }
       v45 = v21;
       v24 = abs(v20);
@@ -2545,7 +2544,7 @@
         {
           if ( pActors[i].pActorBuffs[ACTOR_BUFF_MASS_DISTORTION].uExpireTime > 0 )
           {
-            pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_y_scaler_packedfloat = fixpoint_mul(pGame->pStru6Instance->_4A806F(&pActors[i]),
+            pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_y_scaler_packedfloat = fixpoint_mul(pEngine->pStru6Instance->_4A806F(&pActors[i]),
                    pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_y_scaler_packedfloat);
             LOWORD(v27) = v43;
           }
@@ -4539,8 +4538,8 @@
 	strcpy(Source, &pFilename[v7]);
 	strcpy(pOutdoor->pLevelFilename, Source);
 	pWeather->Initialize();
-	pGame->pIndoorCameraD3D->sRotationY = pParty->sRotationY;
-	pGame->pIndoorCameraD3D->sRotationX = pParty->sRotationX;
+	pEngine->pIndoorCameraD3D->sRotationY = pParty->sRotationY;
+	pEngine->pIndoorCameraD3D->sRotationX = pParty->sRotationX;
 	//pODMRenderParams->RotationToInts();
 	pOutdoor->UpdateSunlightVectors();
 
--- a/Engine/Graphics/Overlays.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Graphics/Overlays.cpp	Sun May 10 01:29:11 2015 +0200
@@ -5,7 +5,7 @@
 
 #define _CRT_SECURE_NO_WARNINGS
 #include <stdlib.h>
-#include "../ErrorHandling.h"
+#include "Engine/Engine.h"
 
 #include "Overlays.h"
 #include "Sprites.h"
@@ -18,8 +18,6 @@
 #include "Render.h"
 #include "GUI/GUIWindow.h"
 
-#include "../mm7_data.h"
-
 
 
 
@@ -88,7 +86,7 @@
   IconFrame *frame; // eax@12
   unsigned int v5; // [sp-8h] [bp-Ch]@4
 
-  if ( pCurrentScreen != SCREEN_GAME || !pParty->bTurnBasedModeOn)
+  if ( current_screen_type != SCREEN_GAME || !pParty->bTurnBasedModeOn)
     return;
 
   if ( pTurnEngine->turn_stage == TE_MOVEMENT )//âñå ïåðñû îòñòðåëÿëèñü(ñæàòûé êóëàê)
@@ -114,7 +112,7 @@
       dword_50C998_turnbased_icon_1A = 0;
   }
 }
-// 4E28F8: using guessed type int pCurrentScreen;
+// 4E28F8: using guessed type int current_screen_type;
 // 50C994: using guessed type int dword_50C994;
 // 50C998: using guessed type int dword_50C998_turnbased_icon_1A;
 
--- a/Engine/Graphics/PaletteManager.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Graphics/PaletteManager.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,14 +3,11 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
-#include "../ErrorHandling.h"
+#include "Engine/Engine.h"
 #include "PaletteManager.h"
-#include "../Game.h"
-#include "../LOD.h"
-#include "../Log.h"
-#include "../OurMath.h"
+#include "Engine/LOD.h"
+#include "Engine/OurMath.h"
 
-#include "../mm7_data.h"
 
 
 
@@ -912,7 +909,7 @@
 {
   int v3; // eax@4
 
-  if ( a3 & 2 || byte_4D864C && BYTE2(pGame->uFlags) & 4 )
+  if ( a3 & 2 || byte_4D864C && BYTE2(pEngine->uFlags) & 4 )
     v3 = 32 * a1 + a2 + 3275;
   else
     v3 = 32 * a1 + a2 + 1675;
@@ -926,7 +923,7 @@
 {
   int v3; // eax@4
 
-  if ( a3 & 2 || byte_4D864C && BYTE2(pGame->uFlags) & 4 )
+  if ( a3 & 2 || byte_4D864C && BYTE2(pEngine->uFlags) & 4 )
     v3 = 32 * a1 + a2 + 3275;
   else
     v3 = 32 * a1 + a2 + 75;
@@ -940,7 +937,7 @@
 {
   char *result; // eax@4
 
-  if ( a2 & 2 || byte_4D864C && BYTE2(pGame->uFlags) & 4 )
+  if ( a2 & 2 || byte_4D864C && BYTE2(pEngine->uFlags) & 4 )
     result = (char *)pPaletteManager->field_199600_palettes[a1];
   else
     result = (char *)pPaletteManager->field_D1600[a1];
@@ -953,7 +950,7 @@
 {
   unsigned __int16 *result; // eax@4
 
-  if ( a2 & 2 || byte_4D864C && BYTE2(pGame->uFlags) & 4 )
+  if ( a2 & 2 || byte_4D864C && BYTE2(pEngine->uFlags) & 4 )
     result = (unsigned __int16 *)pPaletteManager->field_199600_palettes[a1];
   else
     result = (unsigned __int16 *)pPaletteManager->pPalette1[a1];
--- a/Engine/Graphics/ParticleEngine.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Graphics/ParticleEngine.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,13 +3,13 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
+#include "Engine/Engine.h"
 #include "ParticleEngine.h"
-#include "../Timer.h"
+#include "Engine/Timer.h"
 #include "Viewport.h"
 #include "Outdoor.h"
-#include "../Game.h"
-#include "../OurMath.h"
-#include "../LOD.h"
+#include "Engine/OurMath.h"
+#include "Engine/LOD.h"
 
 #include "Sprites.h"
 
@@ -308,7 +308,7 @@
   z_int_ = floorf(pParticle->z + 0.5f);
   /*if ( !pRenderer->pRenderD3D )
   {
-    if (pGame->pIndoorCameraD3D->sRotationX)
+    if (pEngine->pIndoorCameraD3D->sRotationX)
     {
       if (pParticle->type & ParticleType_Line)
       {
@@ -316,22 +316,22 @@
         int _uParticleID = (int)(floorf(pParticle->_x + 0.5f) - pBLVRenderParams->vPartyPos.x) << 16;
         //v12 = pParticle->_y + 6.7553994e15;
         y = (int)(floorf(pParticle->_y + 0.5f) - pBLVRenderParams->vPartyPos.y) << 16;
-        z = (unsigned __int64)(y * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16;
-        HIDWORD(a5) = ((unsigned __int64)((signed int)_uParticleID * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16)
+        z = (unsigned __int64)(y * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16;
+        HIDWORD(a5) = ((unsigned __int64)((signed int)_uParticleID * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16)
                     - z;
-        a6 = (unsigned __int64)((signed int)_uParticleID * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16;
+        a6 = (unsigned __int64)((signed int)_uParticleID * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16;
         //v13 = pParticle->_z + 6.7553994e15;
         _uParticleID = (int)(floorf(pParticle->_z + 0.5f) - pBLVRenderParams->vPartyPos.z) << 16;
-        z = ((unsigned __int64)(SHIDWORD(a5) * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16)
-          - ((unsigned __int64)((signed int)_uParticleID * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16);
+        z = ((unsigned __int64)(SHIDWORD(a5) * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_x) >> 16)
+          - ((unsigned __int64)((signed int)_uParticleID * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_x) >> 16);
         v14 = z;
-        HIDWORD(v13) = (unsigned __int64)(SHIDWORD(a5) * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16;
-        HIDWORD(a5) = (unsigned __int64)((signed int)_uParticleID * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16;
+        HIDWORD(v13) = (unsigned __int64)(SHIDWORD(a5) * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_x) >> 16;
+        HIDWORD(a5) = (unsigned __int64)((signed int)_uParticleID * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_x) >> 16;
         //LODWORD(v15) = pBLVRenderParams->field_40 << 16;
         //HIDWORD(v15) = pBLVRenderParams->field_40 >> 16;
         //v16 = v15 / z;
         v16 = fixpoint_div(pBLVRenderParams->field_40, z);
-        v17 = (unsigned __int64)(y * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16;
+        v17 = (unsigned __int64)(y * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16;
         pParticle->_screenspace_scale = v16;
         _uParticleID = (unsigned __int64)(v16 * (signed __int64)(a6 + v17)) >> 16;
         LODWORD(v18) = pBLVRenderParams->uViewportCenterX
@@ -346,20 +346,20 @@
       }
       int _uParticleID = (x_int - pBLVRenderParams->vPartyPos.x) << 16;
       y = (y_int_ - pBLVRenderParams->vPartyPos.y) << 16;
-      HIDWORD(a5) = ((unsigned __int64)((signed int)_uParticleID * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16)
-                  - ((unsigned __int64)(y * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16);
-      a6 = (unsigned __int64)((signed int)_uParticleID * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16;
-      z_int_4 = (unsigned __int64)(y * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16;
+      HIDWORD(a5) = ((unsigned __int64)((signed int)_uParticleID * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16)
+                  - ((unsigned __int64)(y * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16);
+      a6 = (unsigned __int64)((signed int)_uParticleID * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16;
+      z_int_4 = (unsigned __int64)(y * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16;
       _uParticleID = (z_int_ - pBLVRenderParams->vPartyPos.z) << 16;
-      v21 = (unsigned __int64)((signed int)_uParticleID * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16;
-      v22 = ((unsigned __int64)(SHIDWORD(a5) * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16) - v21;
-      z = ((unsigned __int64)(SHIDWORD(a5) * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16) - v21;
+      v21 = (unsigned __int64)((signed int)_uParticleID * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_x) >> 16;
+      v22 = ((unsigned __int64)(SHIDWORD(a5) * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_x) >> 16) - v21;
+      z = ((unsigned __int64)(SHIDWORD(a5) * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_x) >> 16) - v21;
       if ( v22 < (signed int)0x40000u || v22 > (signed int)0x1F400000u )
         return 0;
       v23 = a6 + z_int_4;
       a2 = a6 + z_int_4;
-      v24 = ((unsigned __int64)((signed int)_uParticleID * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16)
-          + ((unsigned __int64)(SHIDWORD(a5) * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16);
+      v24 = ((unsigned __int64)((signed int)_uParticleID * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_x) >> 16)
+          + ((unsigned __int64)(SHIDWORD(a5) * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_x) >> 16);
     }
     else
     {
@@ -369,17 +369,17 @@
         int _uParticleID = ((int)floorf(pParticle->_x + 0.5f) - pBLVRenderParams->vPartyPos.x) << 16;
         //v26 = pParticle->_y + 6.7553994e15;
         y = ((int)floorf(pParticle->_y + 0.5f) - pBLVRenderParams->vPartyPos.y) << 16;
-        auto _hiword_v25 = (__int64)(y * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16;
-        v27 = ((unsigned __int64)((signed int)_uParticleID * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16) - _hiword_v25;
-        z = ((unsigned __int64)((signed int)_uParticleID * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16) - _hiword_v25;
-        v28 = (unsigned __int64)((signed int)_uParticleID * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16;
+        auto _hiword_v25 = (__int64)(y * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16;
+        v27 = ((unsigned __int64)((signed int)_uParticleID * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16) - _hiword_v25;
+        z = ((unsigned __int64)((signed int)_uParticleID * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16) - _hiword_v25;
+        v28 = (unsigned __int64)((signed int)_uParticleID * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16;
         //a5 = pParticle->_z + 6.7553994e15;
         v29 = ((int)floorf(pParticle->_z + 0.5f) - pBLVRenderParams->vPartyPos.z) << 16;
         //LODWORD(v30) = pBLVRenderParams->field_40 << 16;
         //HIDWORD(v30) = pBLVRenderParams->field_40 >> 16;
         //v31 = v30 / z;
         v31 = fixpoint_div(pBLVRenderParams->field_40, z);
-        v32 = (unsigned __int64)(y * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16;
+        v32 = (unsigned __int64)(y * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16;
         pParticle->_screenspace_scale = v31;
         _uParticleID = (unsigned __int64)(v31 * (signed __int64)(v28 + v32)) >> 16;
         LODWORD(v33) = pBLVRenderParams->uViewportCenterX - ((signed int)((unsigned __int64)(v31 * (signed __int64)(v28 + v32)) >> 16) >> 16);
@@ -391,15 +391,15 @@
       }
       int _uParticleID = (x_int - pBLVRenderParams->vPartyPos.x) << 16;
       y = (y_int_ - pBLVRenderParams->vPartyPos.y) << 16;
-      v36 = (unsigned __int64)(y * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16;
-      v22 = ((unsigned __int64)((signed int)_uParticleID * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16) - v36;
-      z = ((unsigned __int64)((signed int)_uParticleID * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16) - v36;
+      v36 = (unsigned __int64)(y * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16;
+      v22 = ((unsigned __int64)((signed int)_uParticleID * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16) - v36;
+      z = ((unsigned __int64)((signed int)_uParticleID * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16) - v36;
       if ( v22 < 262144 || v22 > 524288000 )
         return 0;
-      v37 = (unsigned __int64)((signed int)_uParticleID * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16;
-      _uParticleID = (unsigned __int64)(y * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16;
-      v23 = v37 + ((unsigned __int64)(y * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16);
-      a2 = v37 + ((unsigned __int64)(y * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16);
+      v37 = (unsigned __int64)((signed int)_uParticleID * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16;
+      _uParticleID = (unsigned __int64)(y * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16;
+      v23 = v37 + ((unsigned __int64)(y * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16);
+      a2 = v37 + ((unsigned __int64)(y * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16);
       v24 = (z_int_ - pBLVRenderParams->vPartyPos.z) << 16;
     }
     int _uParticleID = abs(v23);
@@ -426,7 +426,7 @@
   }*/
 
   int x;
-  if ( !pGame->pIndoorCameraD3D->ApplyViewTransform_TrueIfStillVisible_BLV(
+  if ( !pEngine->pIndoorCameraD3D->ApplyViewTransform_TrueIfStillVisible_BLV(
           x_int,
           y_int_,
           z_int_,
@@ -435,10 +435,10 @@
           &z,
           1) )
     return false;
-  pGame->pIndoorCameraD3D->Project(x, y, z, &pParticle->uScreenSpaceX, &pParticle->uScreenSpaceY);
-  pParticle->flt_5C = pGame->pIndoorCameraD3D->fov_x;
+  pEngine->pIndoorCameraD3D->Project(x, y, z, &pParticle->uScreenSpaceX, &pParticle->uScreenSpaceY);
+  pParticle->flt_5C = pEngine->pIndoorCameraD3D->fov_x;
   //v4 = pParticle->flt_5C;
-  pParticle->flt_60 = pGame->pIndoorCameraD3D->fov_y;
+  pParticle->flt_60 = pEngine->pIndoorCameraD3D->fov_y;
   //v5 = v4 + 6.7553994e15;
   LODWORD(v6) = 0;
   HIDWORD(v6) = floorf(pParticle->flt_5C + 0.5f);
@@ -472,10 +472,10 @@
   int v45; // [sp+40h] [bp-10h]@5
   int X_4; // [sp+48h] [bp-8h]@5
 
-  v3 = stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationX);
-  v44 = stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationX);
-  v4 = stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationY);
-  v5 = stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationY);
+  v3 = stru_5C6E00->Cos(pEngine->pIndoorCameraD3D->sRotationX);
+  v44 = stru_5C6E00->Sin(pEngine->pIndoorCameraD3D->sRotationX);
+  v4 = stru_5C6E00->Cos(pEngine->pIndoorCameraD3D->sRotationY);
+  v5 = stru_5C6E00->Sin(pEngine->pIndoorCameraD3D->sRotationY);
 
   if (pParticles[uID].type == ParticleType_Invalid)
     return false;
@@ -484,30 +484,30 @@
   {
     if (pParticles[uID].type & ParticleType_Line)
     {
-      v11 = fixpoint_sub_unknown(pParticles[uID].x - pGame->pIndoorCameraD3D->vPartyPos.x, v4)
-          + fixpoint_sub_unknown(pParticles[uID].y - pGame->pIndoorCameraD3D->vPartyPos.y, v5);
-      long long _hidword_v12 = fixpoint_mul(v11, v3) + fixpoint_sub_unknown(pParticles[uID].z - pGame->pIndoorCameraD3D->vPartyPos.z, v44);
+      v11 = fixpoint_sub_unknown(pParticles[uID].x - pEngine->pIndoorCameraD3D->vPartyPos.x, v4)
+          + fixpoint_sub_unknown(pParticles[uID].y - pEngine->pIndoorCameraD3D->vPartyPos.y, v5);
+      long long _hidword_v12 = fixpoint_mul(v11, v3) + fixpoint_sub_unknown(pParticles[uID].z - pEngine->pIndoorCameraD3D->vPartyPos.z, v44);
       LODWORD(v13) = 0;
       HIDWORD(v13) = SLOWORD(pODMRenderParams->int_fov_rad);
       pParticles[uID]._screenspace_scale = v13 / _hidword_v12;
       pParticles[uID].uScreenSpaceX = pViewport->uScreenCenterX
                                     - ((signed int)fixpoint_mul(pParticles[uID]._screenspace_scale, (fixpoint_sub_unknown(pParticles[uID].y
-                                    - pGame->pIndoorCameraD3D->vPartyPos.y, v4)
-                                    - fixpoint_sub_unknown(pParticles[uID].x - pGame->pIndoorCameraD3D->vPartyPos.x, v5))) >> 16);
+                                    - pEngine->pIndoorCameraD3D->vPartyPos.y, v4)
+                                    - fixpoint_sub_unknown(pParticles[uID].x - pEngine->pIndoorCameraD3D->vPartyPos.x, v5))) >> 16);
       pParticles[uID].uScreenSpaceY = pViewport->uScreenCenterY
                                     - ((signed int)fixpoint_mul(pParticles[uID]._screenspace_scale, (fixpoint_sub_unknown(pParticles[uID].z
-                                    - pGame->pIndoorCameraD3D->vPartyPos.z, v3)
+                                    - pEngine->pIndoorCameraD3D->vPartyPos.z, v3)
                                     - fixpoint_mul(v11, v44))) >> 16);
       pParticles[uID].sZValue = _hidword_v12;
     }
-    v45 = fixpoint_sub_unknown(pParticles[uID].x - pGame->pIndoorCameraD3D->vPartyPos.x, v4) + fixpoint_sub_unknown(pParticles[uID].y
-                                                 - pGame->pIndoorCameraD3D->vPartyPos.y, v5);
-    X_4 = fixpoint_sub_unknown(pParticles[uID].z - pGame->pIndoorCameraD3D->vPartyPos.z, v44) + fixpoint_mul(v45, v3);
+    v45 = fixpoint_sub_unknown(pParticles[uID].x - pEngine->pIndoorCameraD3D->vPartyPos.x, v4) + fixpoint_sub_unknown(pParticles[uID].y
+                                                 - pEngine->pIndoorCameraD3D->vPartyPos.y, v5);
+    X_4 = fixpoint_sub_unknown(pParticles[uID].z - pEngine->pIndoorCameraD3D->vPartyPos.z, v44) + fixpoint_mul(v45, v3);
     if ( X_4 < 0x40000 )
       return 0;
-    v16 = fixpoint_sub_unknown(pParticles[uID].y - pGame->pIndoorCameraD3D->vPartyPos.y, v4)
-        - fixpoint_sub_unknown(pParticles[uID].x - pGame->pIndoorCameraD3D->vPartyPos.x, v5);
-    v17 = fixpoint_sub_unknown(pParticles[uID].z - pGame->pIndoorCameraD3D->vPartyPos.z, v3) - fixpoint_mul(v45, v44);
+    v16 = fixpoint_sub_unknown(pParticles[uID].y - pEngine->pIndoorCameraD3D->vPartyPos.y, v4)
+        - fixpoint_sub_unknown(pParticles[uID].x - pEngine->pIndoorCameraD3D->vPartyPos.x, v5);
+    v17 = fixpoint_sub_unknown(pParticles[uID].z - pEngine->pIndoorCameraD3D->vPartyPos.z, v3) - fixpoint_mul(v45, v44);
   }
   else
   {
@@ -515,23 +515,23 @@
     {
       LODWORD(v22) = 0;
       HIDWORD(v22) = SLOWORD(pODMRenderParams->int_fov_rad);
-      long long _var_123 = fixpoint_sub_unknown(pParticles[uID].x - pGame->pIndoorCameraD3D->vPartyPos.x, v4)
-                         + fixpoint_sub_unknown(pParticles[uID].y - pGame->pIndoorCameraD3D->vPartyPos.y, v5);
+      long long _var_123 = fixpoint_sub_unknown(pParticles[uID].x - pEngine->pIndoorCameraD3D->vPartyPos.x, v4)
+                         + fixpoint_sub_unknown(pParticles[uID].y - pEngine->pIndoorCameraD3D->vPartyPos.y, v5);
       pParticles[uID]._screenspace_scale = v22 / _var_123;
       pParticles[uID].uScreenSpaceX = pViewport->uScreenCenterX
                         - ((signed int)fixpoint_mul(pParticles[uID]._screenspace_scale, (fixpoint_sub_unknown(pParticles[uID].y
-                        - pGame->pIndoorCameraD3D->vPartyPos.y, v4)
-                        - fixpoint_sub_unknown(pParticles[uID].x - pGame->pIndoorCameraD3D->vPartyPos.x, v5))) >> 16);
+                        - pEngine->pIndoorCameraD3D->vPartyPos.y, v4)
+                        - fixpoint_sub_unknown(pParticles[uID].x - pEngine->pIndoorCameraD3D->vPartyPos.x, v5))) >> 16);
       pParticles[uID].uScreenSpaceY = pViewport->uScreenCenterY - (fixpoint_sub_unknown(pParticles[uID].z, pParticles[uID]._screenspace_scale) >> 16);
       pParticles[uID].sZValue = _var_123;
     }
-    v26 = fixpoint_sub_unknown(pParticles[uID].y - pGame->pIndoorCameraD3D->vPartyPos.y, v5);
-    X_4 = v26 + fixpoint_sub_unknown(pParticles[uID].x - pGame->pIndoorCameraD3D->vPartyPos.x, v4);
+    v26 = fixpoint_sub_unknown(pParticles[uID].y - pEngine->pIndoorCameraD3D->vPartyPos.y, v5);
+    X_4 = v26 + fixpoint_sub_unknown(pParticles[uID].x - pEngine->pIndoorCameraD3D->vPartyPos.x, v4);
     if ( X_4 < 0x40000 || X_4 > (pODMRenderParams->uPickDepth - 1000) << 16 )
       return 0;
     v17 = pParticles[uID].z;
-    v16 = fixpoint_sub_unknown(pParticles[uID].y - pGame->pIndoorCameraD3D->vPartyPos.y, v4)
-        - fixpoint_sub_unknown(pParticles[uID].x - pGame->pIndoorCameraD3D->vPartyPos.x, v5);
+    v16 = fixpoint_sub_unknown(pParticles[uID].y - pEngine->pIndoorCameraD3D->vPartyPos.y, v4)
+        - fixpoint_sub_unknown(pParticles[uID].x - pEngine->pIndoorCameraD3D->vPartyPos.x, v5);
   }
   v40 = v17;
   v28 = abs(v16);
--- a/Engine/Graphics/Render.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Graphics/Render.cpp	Sun May 10 01:29:11 2015 +0200
@@ -4,9 +4,9 @@
 
 #define _CRT_SECURE_NO_WARNINGS
 
-#include "../ZlibWrapper.h"
-#include "../ErrorHandling.h"
-
+#include "Engine/Engine.h"
+
+#include "Engine/ZlibWrapper.h"
 #include "Render.h"
 #include "Media/MediaPlayer.h"
 #include "Sprites.h"
@@ -17,26 +17,23 @@
 #include "DecalBuilder.h"
 #include "ParticleEngine.h"
 #include "Outdoor.h"
-#include "../Party.h"
-#include "../LOD.h"
+#include "Engine/Party.h"
+#include "Engine/LOD.h"
 #include "Viewport.h"
-#include "../OurMath.h"
+#include "Engine/OurMath.h"
 #include "PaletteManager.h"
-#include "../Timer.h"
-#include "../Game.h"
+#include "Engine/Timer.h"
 #include "LightmapBuilder.h"
-#include "../Objects/ObjectList.h"
-#include "../Objects/SpriteObject.h"
+#include "Engine/Objects/ObjectList.h"
+#include "Engine/Objects/SpriteObject.h"
 #include "DecorationList.h"
-#include "../Objects/Actor.h"
-#include "../Log.h"
-#include "../MM7.h"
+#include "Engine/Objects/Actor.h"
 #include "Lights.h"
 #include "Level/Decoration.h"
 #include "Vis.h"
-#include "../Registry.h"
+#include "Engine/Registry.h"
 #include "Weather.h"
-#include "../MMT.h"
+#include "Engine/MMT.h"
 
 
 //#pragma comment(lib, "lib\\legacy_dx\\lib\\ddraw.lib")
@@ -262,12 +259,12 @@
       pTerrainVertices[z * 128 + x].vWorldPosition.x = (-64 + (signed)x) * blockScale;
       pTerrainVertices[z * 128 + x].vWorldPosition.y = (64 - (signed)z) * blockScale;
       pTerrainVertices[z * 128 + x].vWorldPosition.z = heightScale * pOutdoor->pTerrain.pHeightmap[z * 128 + x];
-      pGame->pIndoorCameraD3D->ViewTransform(&pTerrainVertices[z * 128 + x], 1);
-      pGame->pIndoorCameraD3D->Project(&pTerrainVertices[z * 128 + x], 1, 0);
+      pEngine->pIndoorCameraD3D->ViewTransform(&pTerrainVertices[z * 128 + x], 1);
+      pEngine->pIndoorCameraD3D->Project(&pTerrainVertices[z * 128 + x], 1, 0);
     }
   }
 //-------(Îòñå÷åíèå íåâèäèìîé ÷àñòè êàðòû)------------------------------------------------------------------------------------------
-  float direction = (float)(pGame->pIndoorCameraD3D->sRotationY / 256);//direction of the camera(íàïðâëåíèå êàìåðû)
+  float direction = (float)(pEngine->pIndoorCameraD3D->sRotationY / 256);//direction of the camera(íàïðâëåíèå êàìåðû)
   //0-East(B)
   //1-NorthEast(CB)
   //2-North(C)
@@ -391,7 +388,7 @@
         //MessageBoxA(nullptr, "Ritor1: function StackLights_TerrainFace needed refactoring and result - slows", "", 0);
         //__debugbreak();
 
-      pGame->pLightmapBuilder->StackLights_TerrainFace(norm, &Light_tile_dist, array_50AC10, 4, 1);//Ritor1: slows
+      pEngine->pLightmapBuilder->StackLights_TerrainFace(norm, &Light_tile_dist, array_50AC10, 4, 1);//Ritor1: slows
       //pDecalBuilder->_49BE8A(pTilePolygon, norm, &Light_tile_dist, array_50AC10, 4, 1);
       }
       unsigned int a5 = 4;
@@ -411,7 +408,7 @@
 
       int v33 = 0;
       static stru154 static_sub_0048034E_stru_154;
-      pGame->pLightmapBuilder->std__vector_000004_size = 0;
+      pEngine->pLightmapBuilder->std__vector_000004_size = 0;
       if ( stru_F8AD28.uNumLightsApplied > 0 || pDecalBuilder->uNumDecals > 0 )
       {
         if ( neer_clip )
@@ -422,10 +419,10 @@
         if ( pDecalBuilder->uNumDecals > 0 )
           pDecalBuilder->ApplyDecals(31 - pTilePolygon->dimming_level, 4, &static_sub_0048034E_stru_154, a5, array_50AC10, 0, *(float *)&v33, -1);
         if ( stru_F8AD28.uNumLightsApplied > 0 )
-          pGame->pLightmapBuilder->ApplyLights(&stru_F8AD28, &static_sub_0048034E_stru_154, a5, array_50AC10, 0, v33);
-      }
-
-      if ( !byte_4D864C || ~pGame->uFlags & 0x80 )
+          pEngine->pLightmapBuilder->ApplyLights(&stru_F8AD28, &static_sub_0048034E_stru_154, a5, array_50AC10, 0, v33);
+      }
+
+      if ( !byte_4D864C || ~pEngine->uFlags & 0x80 )
       {
         //if ( neer_clip ) //Ritor1: Äà¸ò èñêàæåíèÿ íà ïîäú¸ìå, âîçìîæíî òðåáóåòñÿ ô-öèÿ Áåçüå
         //{
@@ -607,7 +604,7 @@
           //v2 = *((short *)v0 - 14)
     //v2 = object->uType;
     if ( (object->uType < 1000 || object->uType >= 10000) && (object->uType < 500 || object->uType >= 600)
-       || pGame->pStru6Instance->_4A81CA(object) )
+       || pEngine->pStru6Instance->_4A81CA(object) )
     {
             //a5 = *(short *)v0;
       x = object->vPosition.x;
@@ -615,7 +612,7 @@
       z = object->vPosition.z;
       frame = pSpriteFrameTable->GetFrame(object_desc->uSpriteID, object->uSpriteFrameID);
       a6 = frame->uGlowRadius * object->field_22_glow_radius_multiplier;
-      v6 = stru_5C6E00->Atan2(object->vPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x, object->vPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y);
+      v6 = stru_5C6E00->Atan2(object->vPosition.x - pEngine->pIndoorCameraD3D->vPartyPos.x, object->vPosition.y - pEngine->pIndoorCameraD3D->vPartyPos.y);
       //LOWORD(v7) = object->uFacing;
       //v8 = v36;
       v9 = ((signed int)(stru_5C6E00->uIntegerPi + ((signed int)stru_5C6E00->uIntegerPi >> 3) + object->uFacing - v6) >> 8) & 7;
@@ -640,18 +637,18 @@
         //LOBYTE(v11) = _4E94D3_light_type;
         pMobileLightsStack->AddLight(x, y, z, object->uSectorID, a6, 0xFF, 0xFF, 0xFF, _4E94D3_light_type);
       }
-      if (pGame->pIndoorCameraD3D->sRotationX)
-      {
-        v30 = fixpoint_mul((x - pGame->pIndoorCameraD3D->vPartyPos.x) << 16, pGame->pIndoorCameraD3D->int_cosine_y)
-            + fixpoint_mul((y - pGame->pIndoorCameraD3D->vPartyPos.y) << 16, pGame->pIndoorCameraD3D->int_sine_y);
-        v37 = fixpoint_mul((x - pGame->pIndoorCameraD3D->vPartyPos.x) << 16, pGame->pIndoorCameraD3D->int_sine_y);
-        v42 = fixpoint_mul((z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16, pGame->pIndoorCameraD3D->int_sine_x)
-            + fixpoint_mul(v30, pGame->pIndoorCameraD3D->int_cosine_x);
+      if (pEngine->pIndoorCameraD3D->sRotationX)
+      {
+        v30 = fixpoint_mul((x - pEngine->pIndoorCameraD3D->vPartyPos.x) << 16, pEngine->pIndoorCameraD3D->int_cosine_y)
+            + fixpoint_mul((y - pEngine->pIndoorCameraD3D->vPartyPos.y) << 16, pEngine->pIndoorCameraD3D->int_sine_y);
+        v37 = fixpoint_mul((x - pEngine->pIndoorCameraD3D->vPartyPos.x) << 16, pEngine->pIndoorCameraD3D->int_sine_y);
+        v42 = fixpoint_mul((z - pEngine->pIndoorCameraD3D->vPartyPos.z) << 16, pEngine->pIndoorCameraD3D->int_sine_x)
+            + fixpoint_mul(v30, pEngine->pIndoorCameraD3D->int_cosine_x);
         if ( v42 >= 0x40000 && v42 <= pODMRenderParams->shading_dist_mist << 16 )
         {
-          v17 = fixpoint_mul((y - pGame->pIndoorCameraD3D->vPartyPos.y) << 16, pGame->pIndoorCameraD3D->int_cosine_y) - v37;
-          v18 = fixpoint_mul((z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16, pGame->pIndoorCameraD3D->int_cosine_x)
-              - fixpoint_mul(v30, pGame->pIndoorCameraD3D->int_sine_x);
+          v17 = fixpoint_mul((y - pEngine->pIndoorCameraD3D->vPartyPos.y) << 16, pEngine->pIndoorCameraD3D->int_cosine_y) - v37;
+          v18 = fixpoint_mul((z - pEngine->pIndoorCameraD3D->vPartyPos.z) << 16, pEngine->pIndoorCameraD3D->int_cosine_x)
+              - fixpoint_mul(v30, pEngine->pIndoorCameraD3D->int_sine_x);
           if ( abs(v42) >= abs(v17) )
           {
             LODWORD(v23) = 0;
@@ -692,13 +689,13 @@
       }
       else
       {
-        v42 = fixpoint_mul((y - pGame->pIndoorCameraD3D->vPartyPos.y) << 16, pGame->pIndoorCameraD3D->int_sine_y)
-            + fixpoint_mul((x - pGame->pIndoorCameraD3D->vPartyPos.x) << 16, pGame->pIndoorCameraD3D->int_cosine_y);
+        v42 = fixpoint_mul((y - pEngine->pIndoorCameraD3D->vPartyPos.y) << 16, pEngine->pIndoorCameraD3D->int_sine_y)
+            + fixpoint_mul((x - pEngine->pIndoorCameraD3D->vPartyPos.x) << 16, pEngine->pIndoorCameraD3D->int_cosine_y);
         if ( v42 >= 0x40000 && v42 <= pODMRenderParams->shading_dist_mist << 16 )
         {
-          v17 = fixpoint_mul((y - pGame->pIndoorCameraD3D->vPartyPos.y) << 16, pGame->pIndoorCameraD3D->int_cosine_y)
-              - fixpoint_mul(((x - pGame->pIndoorCameraD3D->vPartyPos.x) << 16), pGame->pIndoorCameraD3D->int_sine_y);
-          v18 = (z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16;
+          v17 = fixpoint_mul((y - pEngine->pIndoorCameraD3D->vPartyPos.y) << 16, pEngine->pIndoorCameraD3D->int_cosine_y)
+              - fixpoint_mul(((x - pEngine->pIndoorCameraD3D->vPartyPos.x) << 16), pEngine->pIndoorCameraD3D->int_sine_y);
+          v18 = (z - pEngine->pIndoorCameraD3D->vPartyPos.z) << 16;
           if ( abs(v42) >= abs(v17) )
           {
             LODWORD(v23) = 0;
@@ -1028,8 +1025,8 @@
           #pragma endregion
           //v8 = pSpriteFrameTable->GetFrame(decor_desc->uSpriteID, v6 + v7);
 
-          v10 = (unsigned __int16 *)stru_5C6E00->Atan2(pLevelDecorations[i].vPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x,
-                                                       pLevelDecorations[i].vPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y);
+          v10 = (unsigned __int16 *)stru_5C6E00->Atan2(pLevelDecorations[i].vPosition.x - pEngine->pIndoorCameraD3D->vPartyPos.x,
+                                                       pLevelDecorations[i].vPosition.y - pEngine->pIndoorCameraD3D->vPartyPos.y);
           v38 = 0;
           v13 = ((signed int)(stru_5C6E00->uIntegerPi + ((signed int)stru_5C6E00->uIntegerPi >> 3) + pLevelDecorations[i].field_10_y_rot - (signed int)v10) >> 8) & 7;
           v37 = (unsigned __int16 *)v13;
@@ -1060,18 +1057,18 @@
                                              frame->uGlowRadius, r, g, b_, _4E94D0_light_type);
           }//for light
 
-          v17 = (pLevelDecorations[i].vPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x) << 16;
-          if (pGame->pIndoorCameraD3D->sRotationX)
+          v17 = (pLevelDecorations[i].vPosition.x - pEngine->pIndoorCameraD3D->vPartyPos.x) << 16;
+          if (pEngine->pIndoorCameraD3D->sRotationX)
           {
-            v40 = (pLevelDecorations[i].vPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y) << 16;
-            v18 = fixpoint_mul(v17, pGame->pIndoorCameraD3D->int_cosine_y) + fixpoint_mul(v40, pGame->pIndoorCameraD3D->int_sine_y);
-            v41 = fixpoint_mul((pLevelDecorations[i].vPosition.z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16, pGame->pIndoorCameraD3D->int_sine_x);
-            v19 = fixpoint_mul(v18, pGame->pIndoorCameraD3D->int_cosine_x);
-            v20 = v19 + fixpoint_mul((pLevelDecorations[i].vPosition.z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16, pGame->pIndoorCameraD3D->int_sine_x);
+            v40 = (pLevelDecorations[i].vPosition.y - pEngine->pIndoorCameraD3D->vPartyPos.y) << 16;
+            v18 = fixpoint_mul(v17, pEngine->pIndoorCameraD3D->int_cosine_y) + fixpoint_mul(v40, pEngine->pIndoorCameraD3D->int_sine_y);
+            v41 = fixpoint_mul((pLevelDecorations[i].vPosition.z - pEngine->pIndoorCameraD3D->vPartyPos.z) << 16, pEngine->pIndoorCameraD3D->int_sine_x);
+            v19 = fixpoint_mul(v18, pEngine->pIndoorCameraD3D->int_cosine_x);
+            v20 = v19 + fixpoint_mul((pLevelDecorations[i].vPosition.z - pEngine->pIndoorCameraD3D->vPartyPos.z) << 16, pEngine->pIndoorCameraD3D->int_sine_x);
             if ( v20 >= 0x40000 && v20 <= pODMRenderParams->shading_dist_mist << 16 )
             {
-              v21 = fixpoint_mul(v40, pGame->pIndoorCameraD3D->int_cosine_y) - fixpoint_mul(v17, pGame->pIndoorCameraD3D->int_sine_y);
-              v22 = fixpoint_mul((pLevelDecorations[i].vPosition.z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16, pGame->pIndoorCameraD3D->int_cosine_x) - fixpoint_mul(v18, pGame->pIndoorCameraD3D->int_sine_x);
+              v21 = fixpoint_mul(v40, pEngine->pIndoorCameraD3D->int_cosine_y) - fixpoint_mul(v17, pEngine->pIndoorCameraD3D->int_sine_y);
+              v22 = fixpoint_mul((pLevelDecorations[i].vPosition.z - pEngine->pIndoorCameraD3D->vPartyPos.z) << 16, pEngine->pIndoorCameraD3D->int_cosine_x) - fixpoint_mul(v18, pEngine->pIndoorCameraD3D->int_sine_x);
               if ( 2 * abs(v20) >= abs(v21) )
               {
                 LODWORD(v24) = 0;
@@ -1119,13 +1116,13 @@
           }
           else
           {
-            v42 = (pLevelDecorations[i].vPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x) << 16;
-            v40 = (pLevelDecorations[i].vPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y) << 16;
-            v20 = fixpoint_mul(v17, pGame->pIndoorCameraD3D->int_cosine_y) + fixpoint_mul(v40, pGame->pIndoorCameraD3D->int_sine_y);
+            v42 = (pLevelDecorations[i].vPosition.x - pEngine->pIndoorCameraD3D->vPartyPos.x) << 16;
+            v40 = (pLevelDecorations[i].vPosition.y - pEngine->pIndoorCameraD3D->vPartyPos.y) << 16;
+            v20 = fixpoint_mul(v17, pEngine->pIndoorCameraD3D->int_cosine_y) + fixpoint_mul(v40, pEngine->pIndoorCameraD3D->int_sine_y);
             if ( v20 >= 0x40000 && v20 <= pODMRenderParams->shading_dist_mist << 16 )
             {
-              v21 = fixpoint_mul(v40, pGame->pIndoorCameraD3D->int_cosine_y) - fixpoint_mul(v42, pGame->pIndoorCameraD3D->int_sine_y);
-              v22 = (pLevelDecorations[i].vPosition.z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16;
+              v21 = fixpoint_mul(v40, pEngine->pIndoorCameraD3D->int_cosine_y) - fixpoint_mul(v42, pEngine->pIndoorCameraD3D->int_sine_y);
+              v22 = (pLevelDecorations[i].vPosition.z - pEngine->pIndoorCameraD3D->vPartyPos.z) << 16;
               v42 = v22;
               if ( 2 * abs(v20) >= abs(v21) )
               {
@@ -1188,7 +1185,7 @@
         local_0.flt_28 = 1.0;
         local_0.timeToLive = (rand() & 0x80) + 128;
         local_0.uTextureID = pBitmaps_LOD->LoadTexture("effpar01");
-        pGame->pParticleEngine->AddParticle(&local_0);
+        pEngine->pParticleEngine->AddParticle(&local_0);
       }
     }
   }
@@ -1989,18 +1986,18 @@
   v6 = 0;
   if ( this->uNumD3DSceneBegins && (signed int)uNumVertices >= 3 )
   {
-    //v54 = pGame->pLightmapBuilder->std__vector_000004_size;
-    if ( pGame->pLightmapBuilder->std__vector_000004_size)
+    //v54 = pEngine->pLightmapBuilder->std__vector_000004_size;
+    if ( pEngine->pLightmapBuilder->std__vector_000004_size)
       a2 = -1;
-    pGame->AlterGamma_ODM(a4, &a2);
-    if ( byte_4D864C && pGame->uFlags & GAME_FLAGS_1_01_lightmap_related)
+    pEngine->AlterGamma_ODM(a4, &a2);
+    if ( byte_4D864C && pEngine->uFlags & GAME_FLAGS_1_01_lightmap_related)
     {
       v8 = ::GetActorTintColor(a3->dimming_level, 0, array_50AC10[0].vWorldViewPosition.x, 0, 0);
-      pGame->pLightmapBuilder->DrawLightmaps(/*v8, 0*/);
+      pEngine->pLightmapBuilder->DrawLightmaps(/*v8, 0*/);
     }
     else
     {
-      if ( !pGame->pLightmapBuilder->std__vector_000004_size || byte_4D864C && pGame->uFlags & 2 )
+      if ( !pEngine->pLightmapBuilder->std__vector_000004_size || byte_4D864C && pEngine->uFlags & 2 )
       {
         ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP));
         ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CW));
@@ -2018,7 +2015,7 @@
 		  d3d_vertex_buffer[i].pos.z = 1.0 - 1.0 / ((array_50AC10[i].vWorldViewPosition.x * 1000) / (double)pODMRenderParams->shading_dist_mist);
 		  d3d_vertex_buffer[i].rhw = 1.0 / (array_50AC10[i].vWorldViewPosition.x + 0.0000001);
 		  d3d_vertex_buffer[i].diffuse = ::GetActorTintColor(a3->dimming_level, 0, array_50AC10[i].vWorldViewPosition.x, 0, 0);
-          pGame->AlterGamma_ODM(a4, &d3d_vertex_buffer[i].diffuse);
+          pEngine->AlterGamma_ODM(a4, &d3d_vertex_buffer[i].diffuse);
 
 		  if ( this->bUsingSpecular )
             d3d_vertex_buffer[i].specular = sub_47C3D7_get_fog_specular(0, 0, array_50AC10[i].vWorldViewPosition.x);
@@ -2080,7 +2077,7 @@
         //v50 = (const char *)v5->pRenderD3D->pDevice;
         ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE));
         //(*(void (**)(void))(*(int *)v50 + 88))();
-        pGame->pLightmapBuilder->DrawLightmaps(/*-1, 0*/);
+        pEngine->pLightmapBuilder->DrawLightmaps(/*-1, 0*/);
 	    for (uint i = 0; i < uNumVertices; ++i)
 		{
 		  d3d_vertex_buffer[i].diffuse = a2;
@@ -4450,13 +4447,13 @@
 
   if (pRenderD3D)
   {
-    pGame->draw_debug_outlines();
+    pEngine->draw_debug_outlines();
     DoRenderBillboards_D3D();
-    pGame->pStru6Instance->RenderSpecialEffects();
+    pEngine->pStru6Instance->RenderSpecialEffects();
     pRenderD3D->pDevice->EndScene();
   }
   else
-    pGame->pStru6Instance->RenderSpecialEffects();
+    pEngine->pStru6Instance->RenderSpecialEffects();
 }
 
 //----- (004A2031) --------------------------------------------------------
@@ -4596,18 +4593,18 @@
 
   //v61 = pVertices;
 
-  /*  v9 = pGame->pLightmapBuilder;
+  /*  v9 = pEngine->pLightmapBuilder;
     v65 = v9;
     v10 = v9->std__vector_000004_size;*/
-    if ( byte_4D864C && pGame->uFlags & GAME_FLAGS_1_01_lightmap_related)
+    if ( byte_4D864C && pEngine->uFlags & GAME_FLAGS_1_01_lightmap_related)
     {
       v11 = ::GetActorTintColor(a4->dimming_level, 0, array_50AC10[0].vWorldViewPosition.x, 0, 0);
-      pGame->pLightmapBuilder->DrawLightmaps(/*v11, 0*/);
+      pEngine->pLightmapBuilder->DrawLightmaps(/*v11, 0*/);
     }
     else
     {
-      if (transparent || !pGame->pLightmapBuilder->std__vector_000004_size || 
-          byte_4D864C && pGame->uFlags & 2 )
+      if (transparent || !pEngine->pLightmapBuilder->std__vector_000004_size || 
+          byte_4D864C && pEngine->uFlags & 2 )
       {
         if (clampAtTextureBorders)
           this->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_CLAMP);
@@ -4697,7 +4694,7 @@
         //v63 = (const char *)v7->pRenderD3D->pDevice;
         ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE));
         //(*(void (**)(void))(*(int *)v63 + 88))();
-        pGame->pLightmapBuilder->DrawLightmaps(/*-1, 0*/);
+        pEngine->pLightmapBuilder->DrawLightmaps(/*-1, 0*/);
 	    for (uint i = 0; i < uNumVertices; ++i)
 	    {
 		  d3d_vertex_buffer[i].diffuse = -1;
@@ -4748,8 +4745,8 @@
     }
 
     //if (pIndoorCamera->flags & INDOOR_CAMERA_DRAW_TERRAIN_OUTLINES || pBLVRenderParams->uFlags & INDOOR_CAMERA_DRAW_TERRAIN_OUTLINES)
-    if (pGame->pIndoorCameraD3D->debug_flags & ODM_RENDER_DRAW_TERRAIN_OUTLINES)
-      pGame->pIndoorCameraD3D->debug_outline_d3d(d3d_vertex_buffer, uNumVertices, 0x00FFFFFF, 0.0);
+    if (pEngine->pIndoorCameraD3D->debug_flags & ODM_RENDER_DRAW_TERRAIN_OUTLINES)
+      pEngine->pIndoorCameraD3D->debug_outline_d3d(d3d_vertex_buffer, uNumVertices, 0x00FFFFFF, 0.0);
   }
 // 4A26BC: could not find valid save-restore pair for esi
 // 4D864C: using guessed type char byte_4D864C;
@@ -4873,8 +4870,8 @@
   //for floor and wall(for example Selesta)-------------------
   if (pFace->uPolygonType == POLYGON_InBetweenFloorAndWall || pFace->uPolygonType == POLYGON_Floor)
   {
-    int v69 = (GetTickCount() / 32) - pGame->pIndoorCameraD3D->vPartyPos.x;
-    int v55 = (GetTickCount() / 32) + pGame->pIndoorCameraD3D->vPartyPos.y;
+    int v69 = (GetTickCount() / 32) - pEngine->pIndoorCameraD3D->vPartyPos.x;
+    int v55 = (GetTickCount() / 32) + pEngine->pIndoorCameraD3D->vPartyPos.y;
     for (uint i = 0; i < uNumVertices; ++i)
     {
       array_507D30[i].u = (v69 + array_507D30[i].u) * 0.25f;
@@ -4884,16 +4881,16 @@
     return;
   }
 //---------------------------------------
-  v70 = (signed __int64)((double)(pBLVRenderParams->fov_rad_fixpoint * pGame->pIndoorCameraD3D->vPartyPos.z)//179
+  v70 = (signed __int64)((double)(pBLVRenderParams->fov_rad_fixpoint * pEngine->pIndoorCameraD3D->vPartyPos.z)//179
                        / (((double)pBLVRenderParams->fov_rad_fixpoint + 16192.0)
                         * 65536.0)
                        + (double)pBLVRenderParams->uViewportCenterY);
-  v5 = (double)pGame->pIndoorCameraD3D->sRotationX * 0.0030664064;//0
+  v5 = (double)pEngine->pIndoorCameraD3D->sRotationX * 0.0030664064;//0
   v6 = (signed __int64)((double)pBLVRenderParams->uViewportCenterY//183
                       - (double)pBLVRenderParams->fov_rad_fixpoint
                       / ((cos(v5) * 16192.0 + 0.0000001)
                        * 65535.0)
-                      * (sin(v5) * -16192.0 - (double)pGame->pIndoorCameraD3D->vPartyPos.z));
+                      * (sin(v5) * -16192.0 - (double)pEngine->pIndoorCameraD3D->vPartyPos.z));
 
   stru_8019C8._48653D_frustum_blv(65536, 0, 0, 0, 65536, 0);
   pSkyPolygon.Create_48607B(&stru_8019C8);
@@ -4906,9 +4903,9 @@
   pSkyPolygon.dimming_level = 0;
   pSkyPolygon.uNumVertices = uNumVertices;
 
-  pSkyPolygon.v_18.x = -stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationX + 16);
+  pSkyPolygon.v_18.x = -stru_5C6E00->Sin(pEngine->pIndoorCameraD3D->sRotationX + 16);
   pSkyPolygon.v_18.y = 0;
-  pSkyPolygon.v_18.z = -stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationX + 16);
+  pSkyPolygon.v_18.z = -stru_5C6E00->Cos(pEngine->pIndoorCameraD3D->sRotationX + 16);
 
   memcpy(&array_507D30[uNumVertices], array_507D30, sizeof(array_507D30[uNumVertices]));
   pSkyPolygon.field_24 = 0x2000000;
@@ -5158,9 +5155,9 @@
 
   int sCorrectedColor = uColor;
 
-  if (pGame->pLightmapBuilder->std__vector_000004_size)
+  if (pEngine->pLightmapBuilder->std__vector_000004_size)
     sCorrectedColor = -1;
-  pGame->AlterGamma_BLV(pFace, &sCorrectedColor);
+  pEngine->AlterGamma_BLV(pFace, &sCorrectedColor);
 
   if (pFace->uAttributes & FACE_OUTLINED)
   {
@@ -5170,7 +5167,7 @@
 	  uColor = sCorrectedColor = 0xFF109010;
   }
 
-  if (byte_4D864C && pGame->uFlags & GAME_FLAGS_1_01_lightmap_related)
+  if (byte_4D864C && pEngine->uFlags & GAME_FLAGS_1_01_lightmap_related)
   {
       __debugbreak();
       ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, false));
@@ -5192,11 +5189,11 @@
       ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
               D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
               d3d_vertex_buffer, uNumVertices, 28));
-      pGame->pLightmapBuilder->DrawLightmaps(/*-1, 0*/);
+      pEngine->pLightmapBuilder->DrawLightmaps(/*-1, 0*/);
   }
   else
   {
-    if (!pGame->pLightmapBuilder->std__vector_000004_size || byte_4D864C && pGame->uFlags & 2)
+    if (!pEngine->pLightmapBuilder->std__vector_000004_size || byte_4D864C && pEngine->uFlags & 2)
     {
       for (uint i = 0; i < uNumVertices; ++i)
       {
@@ -5237,7 +5234,7 @@
               d3d_vertex_buffer, uNumVertices, 28));
 
       ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE));
-      pGame->pLightmapBuilder->DrawLightmaps(/*-1, 0*/);
+      pEngine->pLightmapBuilder->DrawLightmaps(/*-1, 0*/);
 
       for (uint i = 0; i < uNumVertices; ++i)
         d3d_vertex_buffer[i].diffuse = sCorrectedColor;
@@ -8502,7 +8499,7 @@
               {
                 if ( pOutdoor->pBModels[model_id].pVertices.pVertices[pOutdoor->pBModels[model_id].pFaces[face_id].pVertexIDs[0]].z == array_73D150[i - 1].vWorldPosition.z )
                   ++v53;
-                pGame->pIndoorCameraD3D->ViewTransform(&array_73D150[i - 1], 1);
+                pEngine->pIndoorCameraD3D->ViewTransform(&array_73D150[i - 1], 1);
                 if ( array_73D150[i - 1].vWorldViewPosition.x < 8.0 || array_73D150[i - 1].vWorldViewPosition.x > pODMRenderParams->shading_dist_mist )
                 {
                   if ( array_73D150[i - 1].vWorldViewPosition.x >= 8.0 )
@@ -8511,7 +8508,7 @@
                     v50 = 1;
                 }
                 else
-                  pGame->pIndoorCameraD3D->Project(&array_73D150[i - 1], 1, 0);
+                  pEngine->pIndoorCameraD3D->Project(&array_73D150[i - 1], 1, 0);
               }
             }
             if ( v53 == pOutdoor->pBModels[model_id].pFaces[face_id].uNumVertices )
@@ -8553,9 +8550,9 @@
               }*/
 
               v40 = (int)&pOutdoor->pBModels[model_id].pFaces[face_id];
-              pGame->pLightmapBuilder->ApplyLights_OutdoorFace(&pOutdoor->pBModels[model_id].pFaces[face_id]);
+              pEngine->pLightmapBuilder->ApplyLights_OutdoorFace(&pOutdoor->pBModels[model_id].pFaces[face_id]);
               pDecalBuilder->ApplyDecals_OutdoorFace(&pOutdoor->pBModels[model_id].pFaces[face_id]);
-              pGame->pLightmapBuilder->std__vector_000004_size = 0;
+              pEngine->pLightmapBuilder->std__vector_000004_size = 0;
               int v31 = 0;
               if ( stru_F8AD28.uNumLightsApplied > 0 || pDecalBuilder->uNumDecals > 0 )
               {
@@ -8569,7 +8566,7 @@
                 }
               }
               if ( stru_F8AD28.uNumLightsApplied > 0 )
-                pGame->pLightmapBuilder->ApplyLights(&stru_F8AD28, &static_RenderBuildingsD3D_stru_73C834, uNumVertices, array_50AC10, 0, (char)v31);
+                pEngine->pLightmapBuilder->ApplyLights(&stru_F8AD28, &static_RenderBuildingsD3D_stru_73C834, uNumVertices, array_50AC10, 0, (char)v31);
               if ( v50 )
               {
                 array_77EC08[pODMRenderParams->uNumPolygons].uNumVertices = ODM_NearClip(pOutdoor->pBModels[model_id].pFaces[face_id].uNumVertices);
@@ -8627,16 +8624,16 @@
   int v38; // [sp+158h] [bp-Ch]@1
   int v39; // [sp+15Ch] [bp-8h]@4
 
-  v30 = (signed __int64)((double)(pODMRenderParams->int_fov_rad * pGame->pIndoorCameraD3D->vPartyPos.z)
+  v30 = (signed __int64)((double)(pODMRenderParams->int_fov_rad * pEngine->pIndoorCameraD3D->vPartyPos.z)
                        / ((double)pODMRenderParams->int_fov_rad + 8192.0)
                        + (double)(pViewport->uScreenCenterY));
-  v34 = cos((double)pGame->pIndoorCameraD3D->sRotationX * 0.0030664064) * 0x2000;//(double)pODMRenderParams->shading_dist_mist, 8192
+  v34 = cos((double)pEngine->pIndoorCameraD3D->sRotationX * 0.0030664064) * 0x2000;//(double)pODMRenderParams->shading_dist_mist, 8192
   v38 = (signed __int64)((double)(pViewport->uScreenCenterY)
                        - (double)pODMRenderParams->int_fov_rad
                        / (v34 + 0.0000001)
-                       * (sin((double)pGame->pIndoorCameraD3D->sRotationX * 0.0030664064)
+                       * (sin((double)pEngine->pIndoorCameraD3D->sRotationX * 0.0030664064)
                         * (double)-0x2000//(double)pODMRenderParams->shading_dist_mist
-                        - (double)pGame->pIndoorCameraD3D->vPartyPos.z));
+                        - (double)pEngine->pIndoorCameraD3D->vPartyPos.z));
   pSkyPolygon.Create_48607B(&stru_8019C8);//çàïîëíÿåòñÿ ptr_38
   pSkyPolygon.ptr_38->_48694B_frustum_sky();
 
@@ -8650,9 +8647,9 @@
     pSkyPolygon.dimming_level = 0;
     pSkyPolygon.uNumVertices = 4;
   //centering(öåíòðóåì)-----------------------------------------------------------------
-    pSkyPolygon.v_18.x = -stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationX + 16);
+    pSkyPolygon.v_18.x = -stru_5C6E00->Sin(pEngine->pIndoorCameraD3D->sRotationX + 16);
     pSkyPolygon.v_18.y = 0;
-    pSkyPolygon.v_18.z = -stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationX + 16);
+    pSkyPolygon.v_18.z = -stru_5C6E00->Cos(pEngine->pIndoorCameraD3D->sRotationX + 16);
   
   //sky wiew position(ïîëîæåíèå íåáà íà ýêðàíå)------------------------------------------
   //                X
@@ -8748,13 +8745,13 @@
 //----- (004226C2) --------------------------------------------------------
 bool PauseGameDrawing()
 {
-  if ( pCurrentScreen != SCREEN_GAME
-    && pCurrentScreen != SCREEN_NPC_DIALOGUE
-    && pCurrentScreen != SCREEN_CHANGE_LOCATION )
-  {
-	  if (pCurrentScreen == SCREEN_INPUT_BLV)
+  if ( current_screen_type != SCREEN_GAME
+    && current_screen_type != SCREEN_NPC_DIALOGUE
+    && current_screen_type != SCREEN_CHANGE_LOCATION )
+  {
+	  if (current_screen_type == SCREEN_INPUT_BLV)
 		  return pMovie_Track;//pSmackerMovie != 0;
-    if ( pCurrentScreen != SCREEN_BRANCHLESS_NPC_DIALOG )
+    if ( current_screen_type != SCREEN_BRANCHLESS_NPC_DIALOG )
       return true;
   }
   return false;
@@ -8863,7 +8860,7 @@
             && pActors[v6].uAIState != Disabled
 			&& pActors[v6].uAIState != Summoned )
           {
-            if ( pGame->pVisInstance->DoesRayIntersectBillboard((double)pDepth, a1a) )
+            if ( pEngine->pVisInstance->DoesRayIntersectBillboard((double)pDepth, a1a) )
             {
               if ( mon_num < 100 )
               {
@@ -8891,7 +8888,7 @@
 
   ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE));
   ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE));
-  ErrD3D(pRenderD3D->pDevice->SetTexture(0, pGame->pIndoorCameraD3D->LoadTextureAndGetHardwarePtr("effpar03")));
+  ErrD3D(pRenderD3D->pDevice->SetTexture(0, pEngine->pIndoorCameraD3D->LoadTextureAndGetHardwarePtr("effpar03")));
   ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
   ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE));
 }
@@ -8921,7 +8918,7 @@
   ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE));
   ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE));
   ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE));
-  ErrD3D(pRenderD3D->pDevice->SetTexture(0, pGame->pIndoorCameraD3D->LoadTextureAndGetHardwarePtr("effpar03")));
+  ErrD3D(pRenderD3D->pDevice->SetTexture(0, pEngine->pIndoorCameraD3D->LoadTextureAndGetHardwarePtr("effpar03")));
   ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
   ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE));
 }
@@ -9012,7 +9009,7 @@
   ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE));
   ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE));
 
-  ErrD3D(pRenderD3D->pDevice->SetTexture(0, pGame->pIndoorCameraD3D->LoadTextureAndGetHardwarePtr("hwsplat04")));
+  ErrD3D(pRenderD3D->pDevice->SetTexture(0, pEngine->pIndoorCameraD3D->LoadTextureAndGetHardwarePtr("hwsplat04")));
 }
 
 
@@ -9067,10 +9064,10 @@
 
     float v15;
     if (fabs(z_bias) < 1e-5)
-      v15 = 1.0 - 1.0 / ((1.0f / pGame->pIndoorCameraD3D->GetShadingDistMist()) * pDecal->pVertices[i].vWorldViewPosition.x * 1000.0);
+      v15 = 1.0 - 1.0 / ((1.0f / pEngine->pIndoorCameraD3D->GetShadingDistMist()) * pDecal->pVertices[i].vWorldViewPosition.x * 1000.0);
     else
     {
-      v15 = 1.0 - 1.0 / ((1.0f / pGame->pIndoorCameraD3D->GetShadingDistMist()) * pDecal->pVertices[i].vWorldViewPosition.x * 1000.0) - z_bias;
+      v15 = 1.0 - 1.0 / ((1.0f / pEngine->pIndoorCameraD3D->GetShadingDistMist()) * pDecal->pVertices[i].vWorldViewPosition.x * 1000.0) - z_bias;
       if (v15 < 0.000099999997)
         v15 = 0.000099999997;
     }
@@ -10516,13 +10513,13 @@
 	int angle; // [sp+24h] [bp-8h]@1
 
 	angle = (signed int)(pODMRenderParams->uCameraFovInDegrees << 11) / 360 / 2;
-	v3 = pOutdoor->pBModels[uModelID].vBoundingCenter.x - pGame->pIndoorCameraD3D->vPartyPos.x;
-	v4 = pOutdoor->pBModels[uModelID].vBoundingCenter.y - pGame->pIndoorCameraD3D->vPartyPos.y;
-	stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationX);
-	v17 = v3 * stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationY) + v4 * stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationY);
-	if (pGame->pIndoorCameraD3D->sRotationX)
-		v17 = fixpoint_mul(v17, stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationX));
-	v19 = v4 * stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationY) - v3 * stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationY);
+	v3 = pOutdoor->pBModels[uModelID].vBoundingCenter.x - pEngine->pIndoorCameraD3D->vPartyPos.x;
+	v4 = pOutdoor->pBModels[uModelID].vBoundingCenter.y - pEngine->pIndoorCameraD3D->vPartyPos.y;
+	stru_5C6E00->Sin(pEngine->pIndoorCameraD3D->sRotationX);
+	v17 = v3 * stru_5C6E00->Cos(pEngine->pIndoorCameraD3D->sRotationY) + v4 * stru_5C6E00->Sin(pEngine->pIndoorCameraD3D->sRotationY);
+	if (pEngine->pIndoorCameraD3D->sRotationX)
+		v17 = fixpoint_mul(v17, stru_5C6E00->Cos(pEngine->pIndoorCameraD3D->sRotationX));
+	v19 = v4 * stru_5C6E00->Cos(pEngine->pIndoorCameraD3D->sRotationY) - v3 * stru_5C6E00->Sin(pEngine->pIndoorCameraD3D->sRotationY);
 	v9 = int_get_vector_length(abs(v3), abs(v4), 0);
 	//v10 = v14 * 188;
 	//v22 = v9;
@@ -11119,29 +11116,29 @@
 	int v25; // [sp+18h] [bp-10h]@1
 	int v27; // [sp+24h] [bp-4h]@1
 
-	v25 = pGame->pIndoorCameraD3D->int_cosine_x;
-	v7 = pGame->pIndoorCameraD3D->int_sine_y;
-	v27 = pGame->pIndoorCameraD3D->int_sine_x;
+	v25 = pEngine->pIndoorCameraD3D->int_cosine_x;
+	v7 = pEngine->pIndoorCameraD3D->int_sine_y;
+	v27 = pEngine->pIndoorCameraD3D->int_sine_x;
 	//v8 = -pIndoorCamera->pos.y;
-	v9 = pGame->pIndoorCameraD3D->int_cosine_y;
+	v9 = pEngine->pIndoorCameraD3D->int_cosine_y;
 	//v26 = -pIndoorCamera->pos.z;
-	v11 = pGame->pIndoorCameraD3D->int_cosine_y * -pGame->pIndoorCameraD3D->vPartyPos.x + pGame->pIndoorCameraD3D->int_sine_y * -pGame->pIndoorCameraD3D->vPartyPos.y;
-	v24 = pGame->pIndoorCameraD3D->int_cosine_y * -pGame->pIndoorCameraD3D->vPartyPos.y - pGame->pIndoorCameraD3D->int_sine_y * -pGame->pIndoorCameraD3D->vPartyPos.x;
-	if (pGame->pIndoorCameraD3D->sRotationX)
+	v11 = pEngine->pIndoorCameraD3D->int_cosine_y * -pEngine->pIndoorCameraD3D->vPartyPos.x + pEngine->pIndoorCameraD3D->int_sine_y * -pEngine->pIndoorCameraD3D->vPartyPos.y;
+	v24 = pEngine->pIndoorCameraD3D->int_cosine_y * -pEngine->pIndoorCameraD3D->vPartyPos.y - pEngine->pIndoorCameraD3D->int_sine_y * -pEngine->pIndoorCameraD3D->vPartyPos.x;
+	if (pEngine->pIndoorCameraD3D->sRotationX)
 	{
-		this->field_0_party_dir_x = fixpoint_mul(v11, pGame->pIndoorCameraD3D->int_cosine_x) +
-			fixpoint_mul((-pGame->pIndoorCameraD3D->vPartyPos.z) << 16, pGame->pIndoorCameraD3D->int_sine_x);
+		this->field_0_party_dir_x = fixpoint_mul(v11, pEngine->pIndoorCameraD3D->int_cosine_x) +
+			fixpoint_mul((-pEngine->pIndoorCameraD3D->vPartyPos.z) << 16, pEngine->pIndoorCameraD3D->int_sine_x);
 		this->field_4_party_dir_y = v24;
-		this->field_8_party_dir_z = fixpoint_mul((-pGame->pIndoorCameraD3D->vPartyPos.z) << 16, v25) - fixpoint_mul(v11, v27);
+		this->field_8_party_dir_z = fixpoint_mul((-pEngine->pIndoorCameraD3D->vPartyPos.z) << 16, v25) - fixpoint_mul(v11, v27);
 	}
 	else
 	{
 		this->field_0_party_dir_x = v11;
 		this->field_4_party_dir_y = v24;
-		this->field_8_party_dir_z = (-pGame->pIndoorCameraD3D->vPartyPos.z) << 16;
+		this->field_8_party_dir_z = (-pEngine->pIndoorCameraD3D->vPartyPos.z) << 16;
 	}
 
-	if (pGame->pIndoorCameraD3D->sRotationX)
+	if (pEngine->pIndoorCameraD3D->sRotationX)
 	{
 		v17 = fixpoint_mul(a2, v9) + fixpoint_mul(a3, v7);
 
@@ -11156,7 +11153,7 @@
 		this->viewing_angle_from_west_east = a4;
 	}
 
-	if (pGame->pIndoorCameraD3D->sRotationX)
+	if (pEngine->pIndoorCameraD3D->sRotationX)
 	{
 		v19 = fixpoint_mul(a5, v9) + fixpoint_mul(a6, v7);
 
--- a/Engine/Graphics/RenderD3D11.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Graphics/RenderD3D11.cpp	Sun May 10 01:29:11 2015 +0200
@@ -1,11 +1,9 @@
 #include <d3dcompiler.h>
 #include <comdef.h> // _com_error
 
-#include "../ErrorHandling.h"
+#include "Engine/Engine.h"
 #include "RenderD3D11.h"
-#include "../mm7_data.h"
 #include "Texture.h"
-#include "../Log.h"
 #include "Sprites.h"
 
 #define ErrorD3D(x)\
--- a/Engine/Graphics/Sprites.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Graphics/Sprites.cpp	Sun May 10 01:29:11 2015 +0200
@@ -5,7 +5,8 @@
 #define _CRT_SECURE_NO_WARNINGS
 #include <string.h>
 #include <algorithm>
-#include "../ErrorHandling.h"
+
+#include "Engine/Engine.h"
 
 #include "Sprites.h"
 #include "PaletteManager.h"
@@ -14,7 +15,6 @@
 
 #include "Outdoor.h"
 #include "DecorationList.h"
-#include "../MM7.h"
 #include "../Objects/Actor.h"
 #include "Level/Decoration.h"
 #include "../OurMath.h"
--- a/Engine/Graphics/Texture.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Graphics/Texture.cpp	Sun May 10 01:29:11 2015 +0200
@@ -5,14 +5,14 @@
 #define _CRT_SECURE_NO_WARNINGS
 #include <stdlib.h>
 
+#include "Engine/Engine.h"
+
 #include "Texture.h"
 #include "../Tables/FrameTableInc.h"
 #include "../LOD.h"
 #include "PaletteManager.h"
-#include "../ErrorHandling.h"
 #include "../ZlibWrapper.h"
 
-#include "../mm7_data.h"
 
 #include "../OurMath.h"
 
--- a/Engine/Graphics/Viewport.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Graphics/Viewport.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,26 +3,25 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
-#include "Viewport.h"
 
+#include "Engine/Engine.h"
 
-#include "../Party.h"
-#include "../OurMath.h"
-#include "../Objects/Actor.h"
+#include "Viewport.h"
+#include "Engine/Party.h"
+#include "Engine/OurMath.h"
+#include "Engine/Objects/Actor.h"
 #include "Outdoor.h"
-#include "../Events.h"
+#include "Engine/Events.h"
 #include "IO/Mouse.h"
-#include "../Objects/SpriteObject.h"
-#include "../Objects/ObjectList.h"
+#include "Engine/Objects/SpriteObject.h"
+#include "Engine/Objects/ObjectList.h"
 #include "DecorationList.h"
-#include "../texts.h"
-#include "../Game.h"
+#include "Engine/texts.h"
 #include "Vis.h"
-#include "../LOD.h"
+#include "Engine/LOD.h"
 #include "GUI/GUIWindow.h"
-#include "../TurnEngine/TurnEngine.h"
-#include "../stru123.h"
-#include "../MM7.h"
+#include "Engine/TurnEngine/TurnEngine.h"
+#include "Engine/stru123.h"
 #include "Level/Decoration.h"
 
 
@@ -278,7 +277,7 @@
 
   v1 = pMouse->GetCursorPos(&a2);
   //if ( pRenderer->pRenderD3D )
-    v0 = pGame->pVisInstance->get_picked_object_zbuf_val();
+    v0 = pEngine->pVisInstance->get_picked_object_zbuf_val();
   //else
   //  v0 = pRenderer->pActiveZBuffer[v1->x + pSRZBufferLineOffsets[v1->y]];
 
--- a/Engine/Graphics/Vis.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Graphics/Vis.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,18 +3,16 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
+
+#include "Engine/Engine.h"
+
 #include "Vis.h"
 #include "Sprites.h"
 #include "../Lod.h"
 #include "Outdoor.h"
-#include "../Game.h"
-#include "../Objects/Actor.h"
+#include "Engine/Objects/Actor.h"
 #include "Viewport.h"
-#include "../OurMath.h"
-#include "../Log.h"
-#include "../ErrorHandling.h"
-
-#include "../MM7.h"
+#include "Engine/OurMath.h"
 #include "Level/Decoration.h"
 
 
@@ -74,8 +72,8 @@
   }
   else assert(false);
 
-  pGame->pIndoorCameraD3D->ViewTransform(static_DetermineFacetIntersection_array_F8F200, face->uNumVertices);
-  pGame->pIndoorCameraD3D->Project(static_DetermineFacetIntersection_array_F8F200, face->uNumVertices, 1);
+  pEngine->pIndoorCameraD3D->ViewTransform(static_DetermineFacetIntersection_array_F8F200, face->uNumVertices);
+  pEngine->pIndoorCameraD3D->Project(static_DetermineFacetIntersection_array_F8F200, face->uNumVertices, 1);
 
   SortVectors_x(static_DetermineFacetIntersection_array_F8F200, 0, face->uNumVertices - 1);
   if (static_DetermineFacetIntersection_array_F8F200[0].vWorldViewPosition.x > pick_depth)
@@ -296,11 +294,11 @@
         BLVFace* face = &pIndoor->pFaces[pFaceID];
         if ( is_part_of_selection(face, filter) )
         {
-          if ( !pGame->pIndoorCameraD3D->IsCulled(face) )
+          if ( !pEngine->pIndoorCameraD3D->IsCulled(face) )
           {
             if ( Intersect_Ray_Face(pRay, pRay + 1, &fDepth, &a1, face, 0xFFFFFFFFu) )
             {
-              pGame->pIndoorCameraD3D->ViewTransform(&a1, 1);
+              pEngine->pIndoorCameraD3D->ViewTransform(&a1, 1);
               v9 = fixpoint_from_float(/*v8, */a1.vWorldViewPosition.x);
               LOWORD(v9) = 0;
               v15 = (void *)((PID(OBJECT_BModel,pFaceID)) + v9);
@@ -352,7 +350,7 @@
         RenderVertexSoft intersection;
         if (Intersect_Ray_Face(pRay, pRay + 1, &fDepth, &intersection, &blv_face, i))
         {
-          pGame->pIndoorCameraD3D->ViewTransform(&intersection, 1);
+          pEngine->pIndoorCameraD3D->ViewTransform(&intersection, 1);
           int v13 = fixpoint_from_float(/*v12, */intersection.vWorldViewPosition.x);
           v13 &= 0xFFFF0000;
           v13 += PID(OBJECT_BModel, j | (i << 6));
@@ -779,7 +777,7 @@
   if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
   {
     //if ( pRenderer->pRenderD3D )
-      v3 = pGame->pIndoorCameraD3D->fov;
+      v3 = pEngine->pIndoorCameraD3D->fov;
     //else
     //  v3 = pIndoorCamera->fov_rad;
   }
@@ -798,7 +796,7 @@
   if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
   {
     //if ( pRenderer->pRenderD3D )
-      v3 = pGame->pIndoorCameraD3D->fov;
+      v3 = pEngine->pIndoorCameraD3D->fov;
     //else
     //  v3 = pIndoorCamera->fov_rad;
   }
@@ -821,16 +819,16 @@
   int outz; // [sp+94h] [bp-Ch]@1
   int outy; // [sp+98h] [bp-8h]@1
   
-  pRotY = pGame->pIndoorCameraD3D->sRotationY + UnprojectX(fMouseX);
-  pRotX = pGame->pIndoorCameraD3D->sRotationX + UnprojectY(fMouseY);
+  pRotY = pEngine->pIndoorCameraD3D->sRotationY + UnprojectX(fMouseX);
+  pRotX = pEngine->pIndoorCameraD3D->sRotationX + UnprojectY(fMouseY);
 
-  pStartR.z = pGame->pIndoorCameraD3D->vPartyPos.z;
-  pStartR.x = pGame->pIndoorCameraD3D->vPartyPos.x;
-  pStartR.y = pGame->pIndoorCameraD3D->vPartyPos.y;
+  pStartR.z = pEngine->pIndoorCameraD3D->vPartyPos.z;
+  pStartR.x = pEngine->pIndoorCameraD3D->vPartyPos.x;
+  pStartR.y = pEngine->pIndoorCameraD3D->vPartyPos.y;
 
-  v11[1].vWorldPosition.x = (double)pGame->pIndoorCameraD3D->vPartyPos.x;
-  v11[1].vWorldPosition.y = (double)pGame->pIndoorCameraD3D->vPartyPos.y;
-  v11[1].vWorldPosition.z = (double)pGame->pIndoorCameraD3D->vPartyPos.z;
+  v11[1].vWorldPosition.x = (double)pEngine->pIndoorCameraD3D->vPartyPos.x;
+  v11[1].vWorldPosition.y = (double)pEngine->pIndoorCameraD3D->vPartyPos.y;
+  v11[1].vWorldPosition.z = (double)pEngine->pIndoorCameraD3D->vPartyPos.z;
 
   pDepth = fixpoint_from_float(fPickDepth);
   Vec3_int_::Rotate(pDepth, pRotY, pRotX, pStartR, &outx, &outy, &outz);
@@ -1511,7 +1509,7 @@
       if ( pFaceID < (signed int)pIndoor->uNumFaces )
       {
         pFace = &pIndoor->pFaces[pFaceID];
-        if ( !pGame->pIndoorCameraD3D->IsCulled(&pIndoor->pFaces[pFaceID]) )
+        if ( !pEngine->pIndoorCameraD3D->IsCulled(&pIndoor->pFaces[pFaceID]) )
         {
           if ( is_part_of_selection(pFace, filter) )
           {
--- a/Engine/Graphics/stru10.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Graphics/stru10.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,11 +3,10 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
+#include "Engine/Engine.h"
 #include "stru10.h"
 #include "Indoor.h"
-#include "../Game.h"
-#include "../Party.h"
-#include "../ErrorHandling.h"
+#include "Engine/Party.h"
 
 
 
@@ -242,7 +241,7 @@
 
   //_ESI = a3;
   //v31 = this;
-  //v6 = pGame->pIndoorCameraD3D;
+  //v6 = pEngine->pIndoorCameraD3D;
   //v7 = a3->uPolygonType;
 
   a1.x = 0.0f;
@@ -670,9 +669,9 @@
   RenderVertexSoft v25; // [sp+10h] [bp-90h]@20
   memcpy(&v25, pOutBounding, sizeof(RenderVertexSoft));
 
-  float _dp = (v25.vWorldPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x) * a1.x +
-              (v25.vWorldPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y) * a1.y +
-              (v25.vWorldPosition.z - pGame->pIndoorCameraD3D->vPartyPos.z) * a1.z;
+  float _dp = (v25.vWorldPosition.x - pEngine->pIndoorCameraD3D->vPartyPos.x) * a1.x +
+              (v25.vWorldPosition.y - pEngine->pIndoorCameraD3D->vPartyPos.y) * a1.y +
+              (v25.vWorldPosition.z - pEngine->pIndoorCameraD3D->vPartyPos.z) * a1.z;
   if (fabs(_dp) < 1e-6f)
   {
     memcpy(&v25, &pOutBounding[1], sizeof(RenderVertexSoft));
@@ -680,7 +679,7 @@
     memcpy(&pOutBounding[3], &v25, sizeof(RenderVertexSoft));
   }
 
-    //if ( byte_4D864C && pGame->uFlags & GAME_FLAGS_1_DRAW_BLV_DEBUGS)
+    //if ( byte_4D864C && pEngine->uFlags & GAME_FLAGS_1_DRAW_BLV_DEBUGS)
     //{
       RenderVertexSoft v26; // [sp+40h] [bp-60h]@20
       if ( draw_portals_loops )
@@ -691,32 +690,32 @@
           v26.vWorldPosition.y = pParty->vPosition.y;
           v26.vWorldPosition.z = pParty->vPosition.z + pParty->sEyelevel;             // frustum
 
-          pGame->pIndoorCameraD3D->do_draw_debug_line_sw(&v26, 0xFF0000u, &pOutBounding[0], 0xFF0000u, 0, 0);
-          pGame->pIndoorCameraD3D->do_draw_debug_line_sw(&v26, 0xFF00u, &pOutBounding[1], 0xFF00u, 0, 0);
-          pGame->pIndoorCameraD3D->do_draw_debug_line_sw(&v26, 0xFFu, &pOutBounding[2], 0xFFu, 0, 0);
-          pGame->pIndoorCameraD3D->do_draw_debug_line_sw(&v26, 0xFFFFFFu, &pOutBounding[3], 0xFFFFFFu, 0, 0);
+          pEngine->pIndoorCameraD3D->do_draw_debug_line_sw(&v26, 0xFF0000u, &pOutBounding[0], 0xFF0000u, 0, 0);
+          pEngine->pIndoorCameraD3D->do_draw_debug_line_sw(&v26, 0xFF00u, &pOutBounding[1], 0xFF00u, 0, 0);
+          pEngine->pIndoorCameraD3D->do_draw_debug_line_sw(&v26, 0xFFu, &pOutBounding[2], 0xFFu, 0, 0);
+          pEngine->pIndoorCameraD3D->do_draw_debug_line_sw(&v26, 0xFFFFFFu, &pOutBounding[3], 0xFFFFFFu, 0, 0);
           bDoNotDrawPortalFrustum = true;
         }
-        pGame->pIndoorCameraD3D->debug_outline_sw(pOutBounding, uNumVertices, 0x1EFF1Eu, 0.00019999999);    // bounding
+        pEngine->pIndoorCameraD3D->debug_outline_sw(pOutBounding, uNumVertices, 0x1EFF1Eu, 0.00019999999);    // bounding
       }
     //}
 
-    //pGame->pIndoorCameraD3D->debug_outline_sw(pFaceLimits,  4, 0xFFF14040, 0.000099999997);     // limits
+    //pEngine->pIndoorCameraD3D->debug_outline_sw(pFaceLimits,  4, 0xFFF14040, 0.000099999997);     // limits
 
-  /*if ( byte_4D864C && pGame->uFlags & GAME_FLAGS_1_DRAW_BLV_DEBUGS)
+  /*if ( byte_4D864C && pEngine->uFlags & GAME_FLAGS_1_DRAW_BLV_DEBUGS)
   {
     RenderVertexSoft v26; // [sp+40h] [bp-60h]@20
     v26.vWorldPosition.x = face_center_x;                                    // corner to center
     v26.vWorldPosition.y = face_center_y;
     v26.vWorldPosition.z = face_center_z;
 
-    pGame->pIndoorCameraD3D->do_draw_debug_line_sw(pFaceLimits, 0xFF00u, &v26, 0xFF0000u, 0, 0);  
+    pEngine->pIndoorCameraD3D->do_draw_debug_line_sw(pFaceLimits, 0xFF00u, &v26, 0xFF0000u, 0, 0);  
   }*/
 
 
         /*if ( byte_4D864C )
   {
-      if ( pGame->uFlags & GAME_FLAGS_1_DRAW_BLV_DEBUGS)*/
+      if ( pEngine->uFlags & GAME_FLAGS_1_DRAW_BLV_DEBUGS)*/
       {
         RenderVertexSoft v25; // [sp+10h] [bp-90h]@20
         RenderVertexSoft v26; // [sp+40h] [bp-60h]@20
@@ -730,7 +729,7 @@
         v26.vWorldPosition.z = face_center_z + a1.z * 400.0f;
 
         if ( draw_portals_loops )
-          pGame->pIndoorCameraD3D->do_draw_debug_line_sw(&v25, -1, &v26, 0xFFFF00u, 0, 0);
+          pEngine->pIndoorCameraD3D->do_draw_debug_line_sw(&v25, -1, &v26, 0xFFFF00u, 0, 0);
       }
   //}
 
@@ -757,8 +756,8 @@
 
   _49CE9E(pFace, pVertices, *pNumVertices, pLimits);
 
-  //if ( byte_4D864C && pGame->uFlags & GAME_FLAGS_1_DRAW_BLV_DEBUGS)
-  //  pGame->pIndoorCameraD3D->debug_outline_sw(a4a, 4u, 0xFF1E1Eu, 0.000099999997);
+  //if ( byte_4D864C && pEngine->uFlags & GAME_FLAGS_1_DRAW_BLV_DEBUGS)
+  //  pEngine->pIndoorCameraD3D->debug_outline_sw(a4a, 4u, 0xFF1E1Eu, 0.000099999997);
   if (CalcFaceBounding(pFace, pLimits, 4, pOutBounding))
     return _49C720(pOutBounding, a5);
   return false;
@@ -771,8 +770,8 @@
   RenderVertexSoft pLimits[4]; // [sp+Ch] [bp-C0h]@1
 
   CalcPolygonLimits(pFace, pLimits);//îïðåäåëåíèå ãðàíèö ïîðòàëà
-  //if ( byte_4D864C && pGame->uFlags & GAME_FLAGS_1_DRAW_BLV_DEBUGS)
- //   pGame->pIndoorCameraD3D->debug_outline_sw(pLimits, 4, 0xFF1E1E, 0.000099999997);
+  //if ( byte_4D864C && pEngine->uFlags & GAME_FLAGS_1_DRAW_BLV_DEBUGS)
+ //   pEngine->pIndoorCameraD3D->debug_outline_sw(pLimits, 4, 0xFF1E1E, 0.000099999997);
   if (CalcFaceBounding(pFace, pLimits, 4, pOutBounding))
     return _49C720(pOutBounding, pPortalDataFrustum) != 0;
   return false;
@@ -784,9 +783,9 @@
 char stru10::_49C720(RenderVertexSoft *pFaceBounding, IndoorCameraD3D_Vec4 *pPortalDataFrustum)
 {
   Vec3_float_ pRayStart; // [sp+4h] [bp-34h]@1
-  pRayStart.x = (double)pGame->pIndoorCameraD3D->vPartyPos.x;
-  pRayStart.y = (double)pGame->pIndoorCameraD3D->vPartyPos.y;
-  pRayStart.z = (double)pGame->pIndoorCameraD3D->vPartyPos.z;
+  pRayStart.x = (double)pEngine->pIndoorCameraD3D->vPartyPos.x;
+  pRayStart.y = (double)pEngine->pIndoorCameraD3D->vPartyPos.y;
+  pRayStart.z = (double)pEngine->pIndoorCameraD3D->vPartyPos.z;
 
   if (FindFaceNormal(&pFaceBounding[0], &pFaceBounding[1], &pRayStart, &pPortalDataFrustum[0]) &&
       FindFaceNormal(&pFaceBounding[1], &pFaceBounding[2], &pRayStart, &pPortalDataFrustum[1]) &&
--- a/Engine/Graphics/stru9.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Graphics/stru9.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,11 +3,12 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
+
+#include "Engine/Engine.h"
+
 #include "stru9.h"
 #include "IndoorCameraD3D.h"
 
-#include "../mm7_data.h"
-
 
 
 //----- (00498377) --------------------------------------------------------
--- a/Engine/LOD.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/LOD.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,11 +3,12 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
-#include "Engine/ErrorHandling.h"
+
+#include "Engine/Engine.h"
+
 #include "LOD.h"
 #include "Engine/Graphics/Render.h"
 #include "Engine/Graphics/Viewport.h"
-#include "mm7_data.h"
 #include "ZlibWrapper.h"
 
 #include "Engine/Graphics/Sprites.h"
--- a/Engine/MMT.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/MMT.cpp	Sun May 10 01:29:11 2015 +0200
@@ -4,20 +4,18 @@
 #include <io.h>
 #define _CRT_SECURE_NO_WARNINGS
 
+#include "Engine/Engine.h"
+
 #include "MMT.h"
 #include "GUI/GUIWindow.h"
 
-#include "mm7_data.h"
 #include "Media/Audio/AudioPlayer.h"
 #include "IO/Mouse.h"
 #include "LOD.h"
 #include "Engine/Graphics/Render.h"
 #include "GUI/GUIFont.h"
 #include "lib/libpng/png.h"
-#include "Engine/ErrorHandling.h"
 #include "Media/Video/Bink_Smacker.h"
-#include "Game.h"
-#include "Log.h"
 
 bool FileExists(const char *fname)
 {
@@ -216,7 +214,7 @@
   char pContainerName[64];
   MSG msg;
 
-  pCurrentScreen = SCREEN_GAME;
+  current_screen_type = SCREEN_GAME;
 
   pGUIWindow2 = 0;
   pAudioPlayer->StopChannels(-1, -1);
@@ -257,7 +255,7 @@
   if (pTexture_PCX.LoadPCXFile(pContainerName, 0) == 1)
 	Error("File not found: %s", pContainerName);
 
-  SetCurrentMenuID(MENU_MMT_MAIN_MENU);//included in enum MENU_STATE in GUIWindows.h
+  SetCurrentMenuID(MENU_MMT_MAIN_MENU);
   SetForegroundWindow(window->GetApiHandle());
   SendMessageW(window->GetApiHandle(), WM_ACTIVATEAPP, 1, 0);
   while (GetCurrentMenuID() == MENU_MMT_MAIN_MENU )
@@ -268,7 +266,7 @@
     while (PeekMessageW(&msg, 0, 0, 0, PM_REMOVE))
     {
       if (msg.message == WM_QUIT)
-        Game_DeinitializeAndTerminate(0);
+        Engine_DeinitializeAndTerminate(0);
       TranslateMessage(&msg);
       DispatchMessageW(&msg);
     }
--- a/Engine/MapInfo.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/MapInfo.cpp	Sun May 10 01:29:11 2015 +0200
@@ -2,10 +2,10 @@
 #include <stdlib.h>
 #include <crtdbg.h>
 
+#include "Engine/Engine.h"
+
 #include "MapInfo.h"
 #include "LOD.h"
-#include "Engine/ErrorHandling.h"
-#include "mm7_data.h"
 #include "texts.h"
 #include "Engine/Objects/ObjectList.h"
 #include "Engine/Objects/SpriteObject.h"
--- a/Engine/Objects/Actor.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Objects/Actor.cpp	Sun May 10 01:29:11 2015 +0200
@@ -4,20 +4,16 @@
 
 #define _CRT_SECURE_NO_WARNINGS
 
+#include "Engine/Engine.h"
+
 #include "../Graphics/PaletteManager.h"
-#include "../ErrorHandling.h"
-
 #include "../Graphics/DecalBuilder.h"
-
 #include "../Graphics/Sprites.h"
 #include "../../stru6.h"
-
-
 #include "Actor.h"
 #include "../OurMath.h"
 #include "../Graphics/Outdoor.h"
 #include "Media/Audio/AudioPlayer.h"
-#include "../Game.h"
 #include "ObjectList.h"
 #include "../Graphics/Overlays.h"
 #include "../Tables/FactionTable.h"
@@ -27,11 +23,8 @@
 #include "../LOD.h"
 #include "../Party.h"
 #include "GUI/GUIWindow.h"
-
-#include "../MM7.h"
 #include "SpriteObject.h"
 #include "../stru298.h"
-#include "../Log.h"
 #include "../Texts.h"
 #include "../Graphics/Level/Decoration.h"
 #include "../Graphics/Viewport.h"
@@ -331,7 +324,7 @@
         v39 = 0;
       actorPtr->pActorBuffs[ACTOR_BUFF_HASTE].Apply(pParty->uTimePlayed + (signed int)(signed __int64)((double)(v39 << 7) * 0.033333335),
         masteryLevel, 0, 0, 0);
-      pGame->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr, 0xFF3C1Eu);
+      pEngine->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr, 0xFF3C1Eu);
       pAudioPlayer->PlaySound((SoundID)SOUND_Haste, PID(OBJECT_Actor, uActorID), 0, -1, 0, 0, 0, 0);
       return;
 
@@ -478,7 +471,7 @@
       actorPtr->pActorBuffs[ACTOR_BUFF_STONESKIN].Apply(
         pParty->uTimePlayed + (signed int)(signed __int64)((double)(v44 << 7) * 0.033333335),
         masteryLevel, realPoints + 5, 0, 0);
-      pGame->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr,0x5C310Eu);
+      pEngine->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr,0x5C310Eu);
       pAudioPlayer->PlaySound((SoundID)SOUND_Stoneskin, PID(OBJECT_Actor,uActorID), 0, -1, 0, 0, 0, 0);
       return;
 
@@ -494,7 +487,7 @@
       actorPtr->pActorBuffs[ACTOR_BUFF_BLESS].Apply(
         pParty->uTimePlayed + (signed int)(signed __int64)((double)(v42 << 7) * 0.033333335),
         masteryLevel, realPoints + 5, 0, 0);
-      pGame->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr,0xC8C805u);
+      pEngine->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr,0xC8C805u);
       pAudioPlayer->PlaySound((SoundID)SOUND_Bless, PID(OBJECT_Actor,uActorID), 0, -1, 0, 0, 0, 0);
       return;
       break;
@@ -509,7 +502,7 @@
       else
         v48 = 0;
       actorPtr->pActorBuffs[ACTOR_BUFF_FATE].Apply(pParty->uTimePlayed + 1280, masteryLevel, v48, 0, 0);
-      pGame->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr,0xC8C805u);
+      pEngine->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr,0xC8C805u);
       pAudioPlayer->PlaySound((SoundID)SOUND_Fate, PID(OBJECT_Actor, uActorID), 0, -1, 0, 0, 0, 0);
       return;
 
@@ -525,7 +518,7 @@
       actorPtr->pActorBuffs[ACTOR_BUFF_HEROISM].Apply(
         pParty->uTimePlayed + (signed int)(signed __int64)((double)(v54 << 7) * 0.033333335),
         masteryLevel, realPoints + 5, 0, 0);
-      pGame->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr,0xC8C805u);
+      pEngine->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr,0xC8C805u);
       pAudioPlayer->PlaySound((SoundID)SOUND_51heroism03, PID(OBJECT_Actor,uActorID), 0, -1, 0, 0, 0, 0);
       return;
 
@@ -540,7 +533,7 @@
         realPoints,
         0,
         0);
-      pGame->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr, 0xA81376u);
+      pEngine->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr, 0xA81376u);
       pAudioPlayer->PlaySound((SoundID)SOUND_51heroism03, PID(OBJECT_Actor, uActorID), 0, -1, 0, 0, 0, 0);
       return;
 
@@ -548,7 +541,7 @@
       actorPtr->sCurrentHP += 5 * realPoints + 10;
       if ( actorPtr->sCurrentHP >= (signed int)actorPtr->pMonsterInfo.uHP )
         actorPtr->sCurrentHP = LOWORD(actorPtr->pMonsterInfo.uHP);
-      pGame->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr, 0xA81376u);
+      pEngine->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr, 0xA81376u);
       pAudioPlayer->PlaySound((SoundID)SOUND_Fate, PID(OBJECT_Actor, uActorID), 0, -1, 0, 0, 0, 0);
       return;
 
@@ -591,7 +584,7 @@
       actorPtr->pActorBuffs[ACTOR_BUFF_DAY_OF_PROTECTION].Apply(
         pParty->uTimePlayed + (signed int)(signed __int64)((double)(v96 << 7) * 0.033333335),
         masteryLevel, realPoints, 0, 0);
-      pGame->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr, 0xFFFFFFu);
+      pEngine->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr, 0xFFFFFFu);
       pAudioPlayer->PlaySound((SoundID)SOUND_94dayofprotection03, PID(OBJECT_Actor, uActorID), 0, -1, 0, 0, 0, 0);
       return;
 
@@ -607,7 +600,7 @@
       actorPtr->pActorBuffs[ACTOR_BUFF_HOUR_OF_POWER].Apply(
         pParty->uTimePlayed + (signed int)(signed __int64)((double)(v94 << 7) * 0.033333335),
         masteryLevel, realPoints + 5, 0, 0);
-      pGame->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr, 0xFFFFFFu);
+      pEngine->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr, 0xFFFFFFu);
       pAudioPlayer->PlaySound((SoundID)SOUND_9armageddon01, PID(OBJECT_Actor, uActorID), 0, -1, 0, 0, 0, 0);
       return;
 
@@ -673,7 +666,7 @@
       actorPtr->pActorBuffs[ACTOR_BUFF_PAIN_REFLECTION].Apply(
         pParty->uTimePlayed + (signed int)(signed __int64)((double)(v68 << 7) * 0.033333335),
         masteryLevel, 0, 0, 0);
-      pGame->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr,0x7E7E7Eu);
+      pEngine->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr,0x7E7E7Eu);
       pAudioPlayer->PlaySound((SoundID)SOUND_Sacrifice2, PID(OBJECT_Actor, uActorID), 0, -1, 0, 0, 0, 0);
       return;
   }
@@ -1910,7 +1903,7 @@
 
   actor->uCurrentActionLength = 8 * pSpriteFrameTable->pSpriteSFrames[actor->pSpriteIDs[ANIM_Bored]].uAnimLength;
 
-  v7 = stru_5C6E00->Atan2(actor->vPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x, actor->vPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y);
+  v7 = stru_5C6E00->Atan2(actor->vPosition.x - pEngine->pIndoorCameraD3D->vPartyPos.x, actor->vPosition.y - pEngine->pIndoorCameraD3D->vPartyPos.y);
   v9 = stru_5C6E00->uIntegerPi + actor->uYawAngle + ((signed int)stru_5C6E00->uIntegerPi >> 3) - v7;
 
   if ( v9 & 0x700 )      // turned away - just stand
@@ -3703,9 +3696,9 @@
   {
     if ( pMonsterStats->pInfos[pMonster->pMonsterInfo.uID].bQuestMonster & 1 )
     {
-      if ( /*pRenderer->pRenderD3D &&*/ pGame->uFlags2 & GAME_FLAGS_2_DRAW_BLOODSPLATS )
+      if ( /*pRenderer->pRenderD3D &&*/ pEngine->uFlags2 & GAME_FLAGS_2_DRAW_BLOODSPLATS )
       {
-        v33 = byte_4D864C && pGame->uFlags & 0x80000 ? 10 * pMonster->uActorRadius : pMonster->uActorRadius;
+        v33 = byte_4D864C && pEngine->uFlags & 0x80000 ? 10 * pMonster->uActorRadius : pMonster->uActorRadius;
         pDecalBuilder->AddBloodsplat((float)pMonster->vPosition.x, (float)pMonster->vPosition.y, (float)pMonster->vPosition.z, 1.0, 0.0, 0.0, (float)v33, 0, 0);
       }
     }
@@ -3981,7 +3974,7 @@
 		v6 = a3 != 0;
 		if (a4)
 			LOBYTE(v6) = v6 | 8;
-		v7 = pGame->pVisInstance->PickClosestActor(OBJECT_Actor, pick_depth, v6, 657456, -1);
+		v7 = pEngine->pVisInstance->PickClosestActor(OBJECT_Actor, pick_depth, v6, 657456, -1);
 		if (v7 != -1)
 			return (unsigned __int16)v7;
 		else return 0;
--- a/Engine/Objects/Chest.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Objects/Chest.cpp	Sun May 10 01:29:11 2015 +0200
@@ -5,7 +5,7 @@
 #define _CRT_SECURE_NO_WARNINGS
 #include <stdio.h>
 
-#include "../ErrorHandling.h"
+#include "Engine/Engine.h"
 
 #include "Items.h"
 #include "Chest.h"
@@ -22,8 +22,6 @@
 #include "ObjectList.h"
 #include "GUI/GUIWindow.h"
 #include "../Timer.h"
-
-#include "../MM7.h"
 #include "SpriteObject.h"
 #include "IO/Mouse.h"
 #include "../Graphics/Viewport.h"
@@ -190,7 +188,7 @@
   pChestWindow = pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Chest, uChestID, 0);
   pBtn_ExitCancel = pChestWindow->CreateButton(471, 445, 169,  35, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[79], pIcons_LOD->GetTexture(uExitCancelTextureId), 0);// Exit
                     pChestWindow->CreateButton(  7,   8, 460, 343, 1, 0, UIMSG_CHEST_ClickItem, 0, 0, "", 0);
-  pCurrentScreen = SCREEN_CHEST;
+  current_screen_type = SCREEN_CHEST;
   pEventTimer->Pause();
   return true;
 }
--- a/Engine/Objects/Items.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Objects/Items.cpp	Sun May 10 01:29:11 2015 +0200
@@ -5,11 +5,12 @@
 #define _CRT_SECURE_NO_WARNINGS
 #include <stdlib.h>
 #include <string>
+
+#include "Engine/Engine.h"
+
 #include "..\..\GUI\UI\UIHouses.h"
 #include "GUI/GUIButton.h"
 
-#include "../ErrorHandling.h"
-
 #include "Items.h"
 #include "../MapInfo.h"
 #include "GUI/GUIWindow.h"
@@ -20,7 +21,6 @@
 #include "../Tables/FactionTable.h"
 #include "../Tables/StorylineTextTable.h"
 #include "../texts.h"
-#include "../mm7_data.h"
 #include "../OurMath.h"
 
 
--- a/Engine/Objects/Monsters.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Objects/Monsters.cpp	Sun May 10 01:29:11 2015 +0200
@@ -6,13 +6,13 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include "../ErrorHandling.h"
+
+#include "Engine/Engine.h"
 
 #include "Monsters.h"
 #include "../Tables/FrameTableInc.h"
 #include "../LOD.h"
 #include "../texts.h"
-#include "../mm7_data.h"
 
 
 
--- a/Engine/Objects/ObjectList.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Objects/ObjectList.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,11 +3,12 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
+
+#include "Engine/Engine.h"
+
 #include "ObjectList.h"
-#include "../mm7_data.h"
 #include "../Graphics/Sprites.h"
 #include "../Tables/FrameTableInc.h"
-#include "../ErrorHandling.h"
 
 //----- (0042EB42) --------------------------------------------------------
 __int16 ObjectList::ObjectIDByItemID(unsigned __int16 uItemID)
--- a/Engine/Objects/Player.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Objects/Player.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,10 +3,11 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
+
+#include "Engine/Engine.h"
+
 #include "stru6.h"
 
-#include "../ErrorHandling.h"
-
 #include "Player.h"
 #include "../Tables/PlayerFrameTable.h"
 #include "Media/Audio/AudioPlayer.h"
@@ -15,7 +16,6 @@
 #include "GUI/GUIWindow.h"
 #include "../Graphics/Viewport.h"
 #include "Actor.h"
-#include "../Game.h"
 #include "IO/Mouse.h"
 #include "../TurnEngine/TurnEngine.h"
 #include "../Events.h"
@@ -29,7 +29,6 @@
 #include "../stru123.h"
 #include "../stru298.h"
 #include "ObjectList.h"
-#include "../MM7.h"
 #include "SpriteObject.h"
 #include "../Graphics/DecalBuilder.h"
 #include "../Spells/CastSpellInfo.h"
@@ -2314,97 +2313,97 @@
       case SPECIAL_ATTACK_CURSE:
         SetCondition(Condition_Cursed, 1);
         pAudioPlayer->PlaySound(SOUND_star1, 0, 0, -1, 0, 0, 0, 0);
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
+        pEngine->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       case SPECIAL_ATTACK_WEAK:
         SetCondition(Condition_Weak, 1);
         pAudioPlayer->PlaySound(SOUND_star1, 0, 0, -1, 0, 0, 0, 0);
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x99, v3);
+        pEngine->pStru6Instance->SetPlayerBuffAnim(0x99, v3);
         return 1;
         break;
       case SPECIAL_ATTACK_SLEEP:
         SetCondition(Condition_Sleep, 1);
         pAudioPlayer->PlaySound(SOUND_star1, 0, 0, -1, 0, 0, 0, 0);
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x99, v3);
+        pEngine->pStru6Instance->SetPlayerBuffAnim(0x99, v3);
         return 1;
         break;
       case SPECIAL_ATTACK_DRUNK:
         SetCondition(Condition_Drunk, 1);
         pAudioPlayer->PlaySound(SOUND_star1, 0, 0, -1, 0, 0, 0, 0);
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x99, v3);
+        pEngine->pStru6Instance->SetPlayerBuffAnim(0x99, v3);
         return 1;
         break;
       case SPECIAL_ATTACK_INSANE:
         SetCondition(Condition_Insane, 1);
         pAudioPlayer->PlaySound(SOUND_star4, 0, 0, -1, 0, 0, 0, 0);
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x99, v3);
+        pEngine->pStru6Instance->SetPlayerBuffAnim(0x99, v3);
         return 1;
         break;
       case SPECIAL_ATTACK_POISON_WEAK:
         SetCondition(Condition_Poison_Weak, 1);
         pAudioPlayer->PlaySound(SOUND_star2, 0, 0, -1, 0, 0, 0, 0);
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x99, v3);
+        pEngine->pStru6Instance->SetPlayerBuffAnim(0x99, v3);
         return 1;
         break;
       case SPECIAL_ATTACK_POISON_MEDIUM:
         SetCondition(Condition_Poison_Medium, 1);
         pAudioPlayer->PlaySound(SOUND_star2, 0, 0, -1, 0, 0, 0, 0);
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x99, v3);
+        pEngine->pStru6Instance->SetPlayerBuffAnim(0x99, v3);
         return 1;
         break;
       case SPECIAL_ATTACK_POISON_SEVERE:
         SetCondition(Condition_Poison_Severe, 1);
         pAudioPlayer->PlaySound(SOUND_star2, 0, 0, -1, 0, 0, 0, 0);
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x99, v3);
+        pEngine->pStru6Instance->SetPlayerBuffAnim(0x99, v3);
         return 1;
         break;
       case SPECIAL_ATTACK_DISEASE_WEAK:
         SetCondition(Condition_Disease_Weak, 1);
         pAudioPlayer->PlaySound(SOUND_star2, 0, 0, -1, 0, 0, 0, 0);
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x99, v3);
+        pEngine->pStru6Instance->SetPlayerBuffAnim(0x99, v3);
         return 1;
         break;
       case SPECIAL_ATTACK_DISEASE_MEDIUM:
         SetCondition(Condition_Disease_Medium, 1);
         pAudioPlayer->PlaySound(SOUND_star2, 0, 0, -1, 0, 0, 0, 0);
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x99, v3);
+        pEngine->pStru6Instance->SetPlayerBuffAnim(0x99, v3);
         return 1;
         break;
       case SPECIAL_ATTACK_DISEASE_SEVERE:
         SetCondition(Condition_Disease_Severe, 1);
         pAudioPlayer->PlaySound(SOUND_star2, 0, 0, -1, 0, 0, 0, 0);
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x99, v3);
+        pEngine->pStru6Instance->SetPlayerBuffAnim(0x99, v3);
         return 1;
         break;
       case SPECIAL_ATTACK_PARALYZED:
         SetCondition(Condition_Paralyzed, 1);
         pAudioPlayer->PlaySound(SOUND_star4, 0, 0, -1, 0, 0, 0, 0);
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
+        pEngine->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       case SPECIAL_ATTACK_UNCONSCIOUS:
         SetCondition(Condition_Unconcious, 1);
         pAudioPlayer->PlaySound(SOUND_star4, 0, 0, -1, 0, 0, 0, 0);
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
+        pEngine->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       case SPECIAL_ATTACK_DEAD:
         SetCondition(Condition_Dead, 1);
         pAudioPlayer->PlaySound(SOUND_eradicate, 0, 0, -1, 0, 0, 0, 0);
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
+        pEngine->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       case SPECIAL_ATTACK_PETRIFIED:
         SetCondition(Condition_Pertified, 1);
         pAudioPlayer->PlaySound(SOUND_eradicate, 0, 0, -1, 0, 0, 0, 0);
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
+        pEngine->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       case SPECIAL_ATTACK_ERADICATED:
         SetCondition(Condition_Eradicated, 1);
         pAudioPlayer->PlaySound(SOUND_eradicate, 0, 0, -1, 0, 0, 0, 0);
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
+        pEngine->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       case SPECIAL_ATTACK_BREAK_ANY:
@@ -2416,7 +2415,7 @@
           v48->SetBroken();
           pAudioPlayer->PlaySound(SOUND_metal_vs_metal03h, 0, 0, -1, 0, 0, 0, 0);
         }
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
+        pEngine->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       case SPECIAL_ATTACK_STEAL:
@@ -2427,34 +2426,34 @@
           v27 = &pActor->ActorHasItems[1];
           if ( pActor->ActorHasItems[1].uItemID )
           {
-            pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
+            pEngine->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
             return 1;
           }
         }
         memcpy(v27, &this->pInventoryItemList[this->pInventoryMatrix[v47]-1], 0x24u);
         RemoveItemAtInventoryIndex(v47);
         pAudioPlayer->PlaySound(SOUND_metal_vs_metal03h, 0, 0, -1, 0, 0, 0, 0);
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
+        pEngine->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       case SPECIAL_ATTACK_AGING:
         PlaySound(SPEECH_42, 0);
         ++this->sAgeModifier;
         pAudioPlayer->PlaySound(SOUND_eleccircle, 0, 0, -1, 0, 0, 0, 0);
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
+        pEngine->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       case SPECIAL_ATTACK_MANA_DRAIN:
         PlaySound(SPEECH_41, 0);
         this->sMana = 0;
         pAudioPlayer->PlaySound(SOUND_eleccircle, 0, 0, -1, 0, 0, 0, 0);
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
+        pEngine->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       case SPECIAL_ATTACK_FEAR:
         SetCondition(Condition_Fear, 1);
         pAudioPlayer->PlaySound(SOUND_star1, 0, 0, -1, 0, 0, 0, 0);
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
+        pEngine->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
         return 1;
         break;
       default:
@@ -4647,7 +4646,7 @@
 
   if ( pParty->pPickedItem.GetItemEquipType() == EQUIP_SPELL_SCROLL )
   {
-    if ( pCurrentScreen == SCREEN_CASTING )
+    if ( current_screen_type == SCREEN_CASTING )
         return;
     if ( !playerAffected->CanAct() )
     {
@@ -4671,7 +4670,7 @@
       pMouse->RemoveHoldingItem();
       pGUIWindow_CurrentMenu->Release();
       pIcons_LOD->RemoveTexturesPackFromTextureList();
-      pCurrentScreen = SCREEN_GAME;
+      current_screen_type = SCREEN_GAME;
       viewparams->bRedrawGameUI = 1;
       _42777D_CastSpell_UseWand_ShootArrow(scroll_id, player_num - 1, 0x85u, 1, 0);
     }
@@ -4679,7 +4678,7 @@
     {
       pMouse->RemoveHoldingItem();
       pMessageQueue_50C9E8->AddGUIMessage(UIMSG_SpellScrollUse, scroll_id, player_num - 1);
-      if ( pCurrentScreen && pGUIWindow_CurrentMenu
+      if ( current_screen_type && pGUIWindow_CurrentMenu
         && (pGUIWindow_CurrentMenu->eWindowType != WINDOW_null))
       {
         pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Escape, 0, 0);
@@ -4866,7 +4865,7 @@
       }
       ShowStatusBarString(pTmpBuf.data(), 2);
       pMouse->RemoveHoldingItem();
-      pGame->pStru6Instance->SetPlayerBuffAnim(SPELL_QUEST_COMPLETED, player_num - 1);
+      pEngine->pStru6Instance->SetPlayerBuffAnim(SPELL_QUEST_COMPLETED, player_num - 1);
       playerAffected->PlaySound(SPEECH_93, 0);
       pAudioPlayer->PlaySound(SOUND_chimes, 0, 0, -1, 0, 0, 0, 0);
       if ( pParty->uDaysPlayed == 6 || pParty->uDaysPlayed == 20 )
@@ -4908,7 +4907,7 @@
       }
       else if ( pParty->pPickedItem.uItemID == 646 ) //Horseshoe
       {
-        pGame->pStru6Instance->SetPlayerBuffAnim(SPELL_QUEST_COMPLETED, player_num - 1);
+        pEngine->pStru6Instance->SetPlayerBuffAnim(SPELL_QUEST_COMPLETED, player_num - 1);
         v5 = PID(OBJECT_Player, player_num + 49);
         pAudioPlayer->PlaySound(SOUND_quest, v5, 0, -1, 0, 0, 0, 0);
         playerAffected->AddVariable(VAR_NumSkillPoints, 2);
@@ -5478,7 +5477,7 @@
       if ( !_449B57_test_bit(pParty->_quest_bits, var_value) && pQuestTable[var_value-1] )
       {
         bFlashQuestBook = 1;
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x96u, GetPlayerIndex());
+        pEngine->pStru6Instance->SetPlayerBuffAnim(0x96u, GetPlayerIndex());
         PlayAwardSound();
         this->PlaySound(SPEECH_93, 0);
       }
@@ -5735,7 +5734,7 @@
     case VAR_AutoNotes:
       if ( !_449B57_test_bit(pParty->_autonote_bits, var_value) && pAutonoteTxt[var_value-1].pText )
       {
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x96u, GetPlayerIndex());
+        pEngine->pStru6Instance->SetPlayerBuffAnim(0x96u, GetPlayerIndex());
         this->PlaySound(SPEECH_96, 0);
         bFlashAutonotesBook = 1;
         _506568_autonote_type = pAutonoteTxt[var_value-1].eType;// dword_72371C[2 * a3];
@@ -5927,7 +5926,7 @@
 void Player::PlayAwardSound_Anim()
 {
   int playerIndex = GetPlayerIndex();
-  pGame->pStru6Instance->SetPlayerBuffAnim(0x96u, playerIndex);
+  pEngine->pStru6Instance->SetPlayerBuffAnim(0x96u, playerIndex);
   PlayAwardSound();
 }
 
@@ -5951,7 +5950,7 @@
     this->*skillToSet = skillValue | currSkillValue & 0xC0;
   }
   int playerIndex = GetPlayerIndex();
-  pGame->pStru6Instance->SetPlayerBuffAnim(0x96u, playerIndex);
+  pEngine->pStru6Instance->SetPlayerBuffAnim(0x96u, playerIndex);
   PlayAwardSound();
 }
 
@@ -6334,7 +6333,7 @@
           this->PlaySound(SPEECH_96, 0);
           bFlashAutonotesBook = 1;
           _506568_autonote_type = pAutonoteTxt[val].eType;
-          pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, GetPlayerIndex());
+          pEngine->pStru6Instance->SetPlayerBuffAnim(0x97u, GetPlayerIndex());
         }
         _449B7E_toggle_bit(pParty->_autonote_bits, val, 1);
         PlayAwardSound();
@@ -6503,7 +6502,7 @@
 void Player::PlayAwardSound_Anim97()
 {
   int playerIndex = GetPlayerIndex();
-  pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, playerIndex);
+  pEngine->pStru6Instance->SetPlayerBuffAnim(0x97u, playerIndex);
   PlayAwardSound();
 }
 
@@ -7097,7 +7096,7 @@
 void Player::PlayAwardSound_Anim98()
 {
   int playerIndex = GetPlayerIndex();
-  pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, playerIndex);
+  pEngine->pStru6Instance->SetPlayerBuffAnim(0x98u, playerIndex);
   PlayAwardSound();
 }
 
@@ -7343,9 +7342,9 @@
             }
             else
             {
-              if ( pMonsterStats->pInfos[actorPtr->pMonsterInfo.uID].bQuestMonster & 1 && pGame->uFlags2 & GAME_FLAGS_2_DRAW_BLOODSPLATS)
+              if ( pMonsterStats->pInfos[actorPtr->pMonsterInfo.uID].bQuestMonster & 1 && pEngine->uFlags2 & GAME_FLAGS_2_DRAW_BLOODSPLATS)
               {
-                int splatRadius = byte_4D864C && BYTE2(pGame->uFlags) & 8 ? 10 * actorPtr->uActorRadius : actorPtr->uActorRadius;
+                int splatRadius = byte_4D864C && BYTE2(pEngine->uFlags) & 8 ? 10 * actorPtr->uActorRadius : actorPtr->uActorRadius;
                 pDecalBuilder->AddBloodsplat(actorPtr->vPosition.x, actorPtr->vPosition.y, actorPtr->vPosition.z, 1.0, 0.0, 0.0, (float)splatRadius, 0, 0);
               }
               Actor::Die(uActorID);
@@ -7535,9 +7534,9 @@
               }
               else
               {
-                if ( pMonsterStats->pInfos[actorPtr->pMonsterInfo.uID].bQuestMonster & 1 && pGame->uFlags2 & GAME_FLAGS_2_DRAW_BLOODSPLATS )
+                if ( pMonsterStats->pInfos[actorPtr->pMonsterInfo.uID].bQuestMonster & 1 && pEngine->uFlags2 & GAME_FLAGS_2_DRAW_BLOODSPLATS )
                 {
-                  int splatRadius = byte_4D864C && BYTE2(pGame->uFlags) & 8 ? 10 * actorPtr->uActorRadius : actorPtr->uActorRadius;
+                  int splatRadius = byte_4D864C && BYTE2(pEngine->uFlags) & 8 ? 10 * actorPtr->uActorRadius : actorPtr->uActorRadius;
                   pDecalBuilder->AddBloodsplat(actorPtr->vPosition.x, actorPtr->vPosition.y, actorPtr->vPosition.z, 1.0, 0.0, 0.0, (float)splatRadius, 0, 0);
                 }
                 Actor::Die(uActorID);
--- a/Engine/Objects/SpriteObject.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Objects/SpriteObject.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,6 +3,9 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
+
+#include "Engine/Engine.h"
+
 #include "Engine/Graphics/Sprites.h"
 #include "Engine/Graphics/BSPModel.h"
 #include "SpriteObject.h"
@@ -13,15 +16,11 @@
 #include "Engine/Graphics/Outdoor.h"
 #include "Engine/Graphics/ParticleEngine.h"
 #include "../Timer.h"
-#include "../Game.h"
 #include "../LOD.h"
 #include "Actor.h"
 #include "../Events.h"
 #include "Media/Audio/AudioPlayer.h"
 #include "Engine/Graphics/Level/Decoration.h"
-
-#include "../MM7.h"
-
 #include "../stru298.h"
 #include "../Random.h"
 
@@ -259,7 +258,7 @@
         Dst.timeToLive = (unsigned __int8)(rand() & 0x80) + 128;
         Dst.uTextureID = pBitmaps_LOD->LoadTexture("effpar01", TEXTURE_DEFAULT);
         Dst.flt_28 = 1.0;
-        pGame->pParticleEngine->AddParticle(&Dst);
+        pEngine->pParticleEngine->AddParticle(&Dst);
       }
       else if ( object->uFlags & OBJECT_DESC_TRIAL_LINE)
       {
@@ -268,7 +267,7 @@
         Dst.timeToLive = 64;
         Dst.uTextureID = 0;
         Dst.flt_28 = 1.0;
-        pGame->pParticleEngine->AddParticle(&Dst);
+        pEngine->pParticleEngine->AddParticle(&Dst);
       }
       else if ( object->uFlags & OBJECT_DESC_TRIAL_PARTICLE )
       {
@@ -277,7 +276,7 @@
         Dst.timeToLive = (unsigned __int8)(rand() & 0x80) + 128;
         Dst.uTextureID = pBitmaps_LOD->LoadTexture("effpar03", TEXTURE_DEFAULT);
         Dst.flt_28 = 1.0;
-        pGame->pParticleEngine->AddParticle(&Dst);
+        pEngine->pParticleEngine->AddParticle(&Dst);
       }
       return;
     }
@@ -366,7 +365,7 @@
           Dst.timeToLive = (unsigned __int8)( rand() & 0x80) + 128;
           Dst.uTextureID = pBitmaps_LOD->LoadTexture("effpar01", TEXTURE_DEFAULT);
           Dst.flt_28 = 1.0;
-          pGame->pParticleEngine->AddParticle(&Dst);
+          pEngine->pParticleEngine->AddParticle(&Dst);
           return;
         }
         else if ( object->uFlags & OBJECT_DESC_TRIAL_LINE )
@@ -376,7 +375,7 @@
           Dst.uDiffuse = rand();
           Dst.timeToLive = 64;
           Dst.flt_28 = 1.0;
-          pGame->pParticleEngine->AddParticle(&Dst);
+          pEngine->pParticleEngine->AddParticle(&Dst);
           return;
         }
         else if ( object->uFlags & OBJECT_DESC_TRIAL_PARTICLE)
@@ -386,7 +385,7 @@
           Dst.timeToLive = (unsigned __int8)(rand() & 0x80) + 128;
           Dst.uTextureID = pBitmaps_LOD->LoadTexture("effpar03", TEXTURE_DEFAULT);
           Dst.flt_28 = 1.0;
-          pGame->pParticleEngine->AddParticle(&Dst);
+          pEngine->pParticleEngine->AddParticle(&Dst);
         }
         return;
       }
@@ -582,7 +581,7 @@
           Dst.timeToLive = (unsigned __int8)(rand() & 0x80) + 128;
           Dst.uTextureID = pBitmaps_LOD->LoadTexture("effpar01", TEXTURE_DEFAULT);
           Dst.flt_28 = 1.0;
-          pGame->pParticleEngine->AddParticle(&Dst);
+          pEngine->pParticleEngine->AddParticle(&Dst);
           return;
         }
         else if ( pObject->uFlags & OBJECT_DESC_TRIAL_LINE )
@@ -592,7 +591,7 @@
           Dst.timeToLive = 64;
           Dst.uTextureID = 0;
           Dst.flt_28 = 1.0;
-          pGame->pParticleEngine->AddParticle(&Dst);
+          pEngine->pParticleEngine->AddParticle(&Dst);
           return;
         }
         else if ( pObject->uFlags & OBJECT_DESC_TRIAL_PARTICLE)
@@ -602,7 +601,7 @@
           Dst.timeToLive = (unsigned __int8)(rand() & 0x80) + 128;
           Dst.uTextureID = pBitmaps_LOD->LoadTexture("effpar03", TEXTURE_DEFAULT);
           Dst.flt_28 = 1.0;
-          pGame->pParticleEngine->AddParticle(&Dst);
+          pEngine->pParticleEngine->AddParticle(&Dst);
         }
         return;
       }
@@ -726,7 +725,7 @@
         Dst.flt_28 = 1.0;
         Dst.timeToLive = (unsigned __int8)(rand() & 0x80) + 128;
         Dst.uTextureID = pBitmaps_LOD->LoadTexture("effpar01", TEXTURE_DEFAULT);
-        pGame->pParticleEngine->AddParticle(&Dst);
+        pEngine->pParticleEngine->AddParticle(&Dst);
         return;
       }
       else if ( pObject->uFlags & OBJECT_DESC_TRIAL_LINE )
@@ -736,7 +735,7 @@
         Dst.timeToLive = 64;
         Dst.uTextureID = 0;
         Dst.flt_28 = 1.0;
-        pGame->pParticleEngine->AddParticle(&Dst);
+        pEngine->pParticleEngine->AddParticle(&Dst);
         return;
       }
       else if ( pObject->uFlags & OBJECT_DESC_TRIAL_PARTICLE)
@@ -746,7 +745,7 @@
         Dst.flt_28 = 1.0;
         Dst.timeToLive = (unsigned __int8)(rand() & 0x80) + 128;
         Dst.uTextureID = pBitmaps_LOD->LoadTexture("effpar03", TEXTURE_DEFAULT);
-        pGame->pParticleEngine->AddParticle(&Dst);
+        pEngine->pParticleEngine->AddParticle(&Dst);
       }
       return;
     }
--- a/Engine/Party.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Party.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,7 +3,8 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
-#include "Engine/ErrorHandling.h"
+
+#include "Engine/Engine.h"
 
 #include "Party.h"
 #include "Timer.h"
@@ -16,17 +17,15 @@
 #include "Engine/Objects/Actor.h"
 #include "GUI/GUIWindow.h"
 #include "texts.h"
-
-#include "MM7.h"
 #include "Engine/Graphics/Outdoor.h"
 #include "LOD.h"
 #include "Engine/Objects/SpriteObject.h"
 #include "Engine/Objects/ObjectList.h"
 
 
-#include "Game.h"
+
 
-Party *pParty; // idb
+Party *pParty = nullptr;
 
 struct ActionQueue *pPartyActionQueue = new ActionQueue;
 
--- a/Engine/SaveLoad.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/SaveLoad.cpp	Sun May 10 01:29:11 2015 +0200
@@ -6,9 +6,9 @@
 #include <io.h>
 #include <direct.h>
 
-#include "Engine/ErrorHandling.h"
+#include "Engine/Engine.h"
+
 #include "ZlibWrapper.h"
-
 #include "SaveLoad.h"
 #include "Party.h"
 #include "LOD.h"
@@ -24,10 +24,8 @@
 #include "Engine/Graphics/Viewport.h"
 #include "stru123.h"
 #include "texts.h"
-#include "Log.h"
 #include "Engine/Graphics/Level/Decoration.h"
 
-#include "Game.h"
 #include "MMT.h"
 
 
@@ -182,7 +180,7 @@
   }
 
   pGUIWindow_CurrentMenu->Release();
-  pCurrentScreen = SCREEN_GAME;
+  current_screen_type = SCREEN_GAME;
 
   viewparams->bRedrawGameUI = true;
 
@@ -271,7 +269,7 @@
   pRenderer->PackScreenshot(150, 112, uncompressed_buff, 1000000, &pLodDirectory.uDataSize);//ñîçäàíèå ñêðèíøîòà
   strcpy(pLodDirectory.pFilename, "image.pcx");
 
-  if (pCurrentScreen == SCREEN_SAVEGAME)
+  if (current_screen_type == SCREEN_SAVEGAME)
   {
     pRenderer->DrawTextureIndexed(8, 8, pIcons_LOD->GetTexture(uTextureID_loadsave));
     pRenderer->DrawTextureIndexed(18, 141, pIcons_LOD->GetTexture(uTextureID_save_up));
@@ -524,7 +522,7 @@
   }
   GUI_UpdateWindows();
   pGUIWindow_CurrentMenu->Release();
-  pCurrentScreen = SCREEN_GAME;
+  current_screen_type = SCREEN_GAME;
   //v3 = pSavegameThumbnails;
   viewparams->bRedrawGameUI = true;
   for (uint i = 0; i < 45; i++)
@@ -539,7 +537,7 @@
   ShowStatusBarString(pGlobalTXT_LocalizationStrings[656], 2);// "Game Saved!"
   viewparams->bRedrawGameUI = true;
 }
-// 4E28F8: using guessed type int pCurrentScreen;
+// 4E28F8: using guessed type int current_screen_type;
 
 //----- (0045E297) --------------------------------------------------------
 void SavegameList::Initialize(unsigned int bHideEmptySlots)
--- a/Engine/Spells/CastSpellInfo.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Spells/CastSpellInfo.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,13 +3,14 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
+
+#include "Engine/Engine.h"
+
 #include "CastSpellInfo.h"
 #include "../Objects/Actor.h"
 #include "../Party.h"
-#include "../MM7.h"
 #include "IO/Mouse.h"
 #include "../../stru6.h"
-#include "../Game.h"
 #include "GUI/GUIWindow.h"
 #include "Media/Audio/AudioPlayer.h"
 #include "../Graphics/Outdoor.h"
@@ -27,7 +28,6 @@
 #include "../texts.h"
 #include "../LOD.h"
 #include "../Graphics/Level/Decoration.h"
-
 #include "..\..\GUI\UI\UIPartyCreation.h"
 
 const size_t CastSpellInfoCount = 10;
@@ -632,7 +632,7 @@
           pActors[mon_id].uAttributes |= ACTOR_AGGRESSOR;
           pActors[mon_id].vVelocity.x = 0;
           pActors[mon_id].vVelocity.y = 0;
-          pGame->GetStru6()->_4A7E89_sparkles_on_actor_after_it_casts_buff(&pActors[mon_id], 0);
+          pEngine->GetStru6()->_4A7E89_sparkles_on_actor_after_it_casts_buff(&pActors[mon_id], 0);
         }
         spell_sound_flag = true;
         break;
@@ -656,7 +656,7 @@
         {
           pActors[mon_id].pActorBuffs[ACTOR_BUFF_SLOWED].Apply(pParty->uTimePlayed + (signed __int64)((double)(signed int)23040 * spell_level * 0.033333335), skill_level, amount, 0, 0);
           pActors[mon_id].uAttributes |= ACTOR_AGGRESSOR;
-          pGame->GetStru6()->_4A7E89_sparkles_on_actor_after_it_casts_buff(&pActors[mon_id], 0);
+          pEngine->GetStru6()->_4A7E89_sparkles_on_actor_after_it_casts_buff(&pActors[mon_id], 0);
         }
         spell_sound_flag = true;
         break;
@@ -782,7 +782,7 @@
         }
         if ( !pPlayer->CanCastSpell(uRequiredMana) )
           break;
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
         pParty->pPlayers[pCastSpell->uPlayerID_2].pPlayerBuffs[PLAYER_BUFF_REGENERATION].Apply(pParty->uTimePlayed + (signed int)(signed __int64)((double)(3600 * spell_level) * 4.2666669), skill_level, amount, 0, 0);
         spell_sound_flag = true;
         break;
@@ -829,10 +829,10 @@
         }
         if ( !pPlayer->CanCastSpell(uRequiredMana) )
           break;
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
         //v90 = (double)(signed int)(3600 * spell_level) * 4.2666669;
         pParty->pPartyBuffs[buff_resist].Apply(pParty->uTimePlayed + (signed int)(signed __int64)((double)(signed int)(3600 * spell_level) * 4.2666669), skill_level, amount, 0, 0);
         spell_sound_flag = true;
@@ -860,10 +860,10 @@
           if ( spell_sound_flag )
           {
             pParty->pPartyBuffs[PARTY_BUFF_HASTE].Apply(pParty->uTimePlayed + (signed int)(signed __int64)((double)(signed int)((int)duration << 7) * 0.033333335), skill_level, 0, 0, 0);
-            pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
-            pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
-            pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
-            pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
+            pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
+            pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
+            pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
+            pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
           }
         }
         break;
@@ -884,7 +884,7 @@
           break;
         if ( skill_level == 1 )
         {
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
           v111 = pOtherOverlayList->_4418B1(10000, pCastSpell->uPlayerID_2 + 310, 0, 65536);
           pParty->pPlayers[pCastSpell->uPlayerID_2].pPlayerBuffs[PLAYER_BUFF_BLESS].Apply(pParty->uTimePlayed +
                                 (signed int)(signed __int64)((double)(signed int)((int)duration << 7) * 0.033333335), 1, amount, v111, 0);
@@ -893,7 +893,7 @@
         }
         for ( uint pl_id = 0; pl_id < 4; pl_id++ )
         {
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pl_id);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pl_id);
           v111 = pOtherOverlayList->_4418B1(10000, pl_id + 310, 0, 65536);
           pParty->pPlayers[pl_id].pPlayerBuffs[1].Apply(pParty->uTimePlayed +
                              (signed int)(signed __int64)((double)(signed int)((int)duration << 7) * 0.033333335), skill_level, amount, v111, 0);
@@ -976,10 +976,10 @@
         }
         if ( !pPlayer->CanCastSpell(uRequiredMana) )
           break;
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
         pParty->pPartyBuffs[buff_resist].Apply(pParty->uTimePlayed +
                        (signed int)(signed __int64)((double)(signed int)((int)duration << 7) * 0.033333335), skill_level, amount, 0, 0);
         spell_sound_flag = true;
@@ -993,10 +993,10 @@
           duration = 60 * spell_level;
         if ( !pPlayer->CanCastSpell(uRequiredMana) )
           break;
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
         pParty->pPartyBuffs[PARTY_BUFF_IMMOLATION].Apply(pParty->uTimePlayed + 
                                (signed __int64)((double)(signed int)((int)duration << 7) * 0.033333335), skill_level, spell_level, 0, 0);
         spell_sound_flag = true;
@@ -1113,8 +1113,8 @@
           pSpellSprite.vPosition.z = pActors[_50BF30_actors_in_viewport_ids[i]].vPosition.z - (unsigned int)(signed __int64)((double)pActors[_50BF30_actors_in_viewport_ids[i]].uActorHeight * -0.8);
           pSpellSprite.spell_target_pid = PID(OBJECT_Actor, _50BF30_actors_in_viewport_ids[i]);
           Actor::DamageMonsterFromParty(PID(OBJECT_Item, pSpellSprite.Create(0, 0, 0, 0)), _50BF30_actors_in_viewport_ids[i], &v700);
-          pGame->GetStru6()->_4A81CA(&pSpellSprite);
-          pGame->GetStru6()->FadeScreen__like_Turn_Undead_and_mb_Armageddon(0xFF3C1E, 0x40);
+          pEngine->GetStru6()->_4A81CA(&pSpellSprite);
+          pEngine->GetStru6()->FadeScreen__like_Turn_Undead_and_mb_Armageddon(0xFF3C1E, 0x40);
         }
         spell_sound_flag = true;
         break;
@@ -1145,10 +1145,10 @@
           break;
         for ( uint pl_id = 0; pl_id < 4; pl_id++ )
           pOtherOverlayList->_4418B1(2010, pl_id + 100, 0, 65536);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
 
         pParty->pPartyBuffs[PARTY_BUFF_FEATHER_FALL].Apply(pParty->uTimePlayed + 
           (signed int)(signed __int64)((double)(signed int)((int)duration << 7) * 0.033333335), skill_level, 0, 0, 0);
@@ -1238,10 +1238,10 @@
         }
         if ( pPlayer->CanCastSpell(uRequiredMana) )
         {
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
           pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].Apply(pParty->uTimePlayed +
                  (signed int)(signed __int64)((double)(signed int)((int)duration << 7) * 0.033333335), skill_level, amount, 0, 0);
           spell_sound_flag = true;
@@ -1473,10 +1473,10 @@
         if ( !pPlayer->CanCastSpell(uRequiredMana) )
           break;
         v169 = pOtherOverlayList->_4418B1(10005, 201, 0, 65536);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
         pParty->pPartyBuffs[PARTY_BUFF_WATER_WALK].Apply(pParty->uTimePlayed + (signed int)(signed __int64)((double)(duration << 7) * 0.033333335),
                                        skill_level, amount, v169, pCastSpell->uPlayerID + 1);
         if ( skill_level == 4 )
@@ -1836,10 +1836,10 @@
         }
         if ( !pPlayer->CanCastSpell(uRequiredMana) )
           break;
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
         pParty->pPartyBuffs[PARTY_BUFF_DETECT_LIFE].Apply(pParty->uTimePlayed + 
             (signed int)(signed __int64)((double)(signed int)((int)amount << 7) * 0.033333335), skill_level, 0, 0, 0);
         spell_sound_flag = true;
@@ -1861,7 +1861,7 @@
           break;
         if ( pCastSpell->spell_target_pid == 0 )
         {
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
           pParty->pPlayers[pCastSpell->uPlayerID_2].pPlayerBuffs[PLAYER_BUFF_FATE].Apply(pParty->uTimePlayed + 1280, skill_level, amount, 0, 0);
           spell_sound_flag = true;
           break;
@@ -1871,7 +1871,7 @@
           mon_id = PID_ID(pCastSpell->spell_target_pid);
           pActors[mon_id].pActorBuffs[ACTOR_BUFF_FATE].Apply(pParty->uTimePlayed + 1280, skill_level, amount, 0, 0);
           pActors[mon_id].uAttributes |= ACTOR_AGGRESSOR;
-          pGame->GetStru6()->_4A7E89_sparkles_on_actor_after_it_casts_buff(&pActors[mon_id], 0);
+          pEngine->GetStru6()->_4A7E89_sparkles_on_actor_after_it_casts_buff(&pActors[mon_id], 0);
         }
         spell_sound_flag = true;
         break;
@@ -1906,7 +1906,7 @@
             break;
           }
         }
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
         spell_sound_flag = true;
         break;
       }
@@ -1920,7 +1920,7 @@
           break;
         if ( skill_level == 1 || skill_level == 2 )
         {
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
           pParty->pPlayers[pCastSpell->uPlayerID_2].pPlayerBuffs[PLAYER_BUFF_PRESERVATION].Apply(pParty->uTimePlayed +
             (signed int)(signed __int64)((double)(signed int)((int)duration << 7) * 0.033333335), skill_level, 0, 0, 0);
           spell_sound_flag = true;
@@ -1928,7 +1928,7 @@
         }
         for ( uint pl_id = 0; pl_id < 4; pl_id++ )
         {
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pl_id);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pl_id);
           pParty->pPlayers[pl_id].pPlayerBuffs[PLAYER_BUFF_PRESERVATION].Apply(pParty->uTimePlayed + 
             (signed int)(signed __int64)((double)(signed int)((int)duration << 7) * 0.033333335), skill_level, 0, 0, 0);
         }
@@ -1944,7 +1944,7 @@
         if ( !pPlayer->CanCastSpell(uRequiredMana) )
           break;
         int mon_num = pRenderer->_46À6ÀÑ_GetActorsInViewport(4096);
-        pGame->GetStru6()->FadeScreen__like_Turn_Undead_and_mb_Armageddon(0xFFFFFF, 192);
+        pEngine->GetStru6()->FadeScreen__like_Turn_Undead_and_mb_Armageddon(0xFFFFFF, 192);
         ++pSpellSprite.uType;
         pSpellSprite.stru_24.Reset();
         pSpellSprite.spell_id = pCastSpell->uSpellID;
@@ -2033,7 +2033,7 @@
             pPlayers[pl_array[i]]->sHealth = pPlayers[pl_array[i]]->GetMaxHealth();
           if ( pPlayers[pl_array[i]]->sHealth > 0 )
             pPlayers[pl_array[i]]->SetUnconcious(0);
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pl_array[i] - 1);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pl_array[i] - 1);
         }
         spell_sound_flag = true;
         break;
@@ -2073,7 +2073,7 @@
           }
           pParty->pPlayers[pCastSpell->uPlayerID_2].SetCondition(Condition_Weak, 1);
           pParty->pPlayers[pCastSpell->uPlayerID_2].sHealth = 1;
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
         }
         spell_sound_flag = true;
         break;
@@ -2091,7 +2091,7 @@
         }
         if ( !pPlayer->CanCastSpell(uRequiredMana) )
           break;
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
         if ( !pParty->pPlayers[pCastSpell->uPlayerID_2].pConditions[Condition_Paralyzed] )
         {
           spell_sound_flag = true;
@@ -2121,7 +2121,7 @@
         }
         if ( !pPlayer->CanCastSpell(uRequiredMana) )
           break;
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
         if ( !pParty->pPlayers[pCastSpell->uPlayerID_2].pConditions[Condition_Fear] )
         {
           spell_sound_flag = true;
@@ -2300,7 +2300,7 @@
         if ( !pPlayer->CanCastSpell(uRequiredMana) )
           break;
         int mon_num = pRenderer->_46À6ÀÑ_GetActorsInViewport(4096);
-        pGame->GetStru6()->FadeScreen__like_Turn_Undead_and_mb_Armageddon(0xA0A0A, 192);
+        pEngine->GetStru6()->FadeScreen__like_Turn_Undead_and_mb_Armageddon(0xA0A0A, 192);
         ++pSpellSprite.uType;
         pSpellSprite.stru_24.Reset();
         pSpellSprite.spell_id = pCastSpell->uSpellID;
@@ -2340,7 +2340,7 @@
           amount = 86400 * spell_level;
         if ( !pPlayer->CanCastSpell(uRequiredMana) )
           break;
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
         if ( pParty->pPlayers[pCastSpell->uPlayerID_2].pConditions[Condition_Insane] )
         {
           if ( !(pParty->pPlayers[pCastSpell->uPlayerID_2].pConditions[Condition_Weak]) )
@@ -2424,7 +2424,7 @@
         }
         if ( !pPlayer->CanCastSpell(uRequiredMana) )
           break;
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
         if ( pParty->pPlayers[pCastSpell->uPlayerID_2].pConditions[Condition_Weak] )
         {
           if ( skill_level == 4 )
@@ -2455,7 +2455,7 @@
         if ( !pCastSpell->spell_target_pid )
         {
           pParty->pPlayers[pCastSpell->uPlayerID_2].Heal(amount);
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
         }
         if (PID_TYPE(pCastSpell->spell_target_pid) == OBJECT_Actor)
         {
@@ -2484,7 +2484,7 @@
         }
         if ( !pPlayer->CanCastSpell(uRequiredMana) )
           break;
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
         if ( pParty->pPlayers[pCastSpell->uPlayerID_2].pConditions[Condition_Poison_Weak] 
           || pParty->pPlayers[pCastSpell->uPlayerID_2].pConditions[Condition_Poison_Medium] 
           || pParty->pPlayers[pCastSpell->uPlayerID_2].pConditions[Condition_Poison_Severe] )
@@ -2508,10 +2508,10 @@
       {
         if ( !pPlayer->CanCastSpell(uRequiredMana) )
           break;
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
         pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].Apply(pParty->uTimePlayed + 
                          (signed __int64)((double)(signed int)((int)(3600 * spell_level) << 7) * 0.033333335), skill_level, spell_level, 0, 0);
         spell_sound_flag = true;
@@ -2523,17 +2523,17 @@
           break;
         if ( skill_level == 4 )
         {
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
           for ( uint pl_id = 0; pl_id < 4; pl_id++)
             pParty->pPlayers[pl_id].pPlayerBuffs[PLAYER_BUFF_HAMMERHANDS].Apply(pParty->uTimePlayed + 
                 (signed int)(signed __int64)((double)(signed int)((int)(3600 * spell_level) << 7) * 0.033333335), 4, spell_level, spell_level, 0);
           spell_sound_flag = true;
           break;
         }
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
         pParty->pPlayers[pCastSpell->uPlayerID_2].pPlayerBuffs[PLAYER_BUFF_HAMMERHANDS].Apply(pParty->uTimePlayed + 
            (signed int)(signed __int64)((double)(signed int)((int)(3600 * spell_level) << 7) * 0.033333335), skill_level, spell_level, spell_level, 0);
         spell_sound_flag = true;
@@ -2547,7 +2547,7 @@
           amount = 86400 * spell_level;
         if ( !pPlayer->CanCastSpell(uRequiredMana) )
           break;
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
         if ( pParty->pPlayers[pCastSpell->uPlayerID_2].pConditions[Condition_Disease_Weak]
           || pParty->pPlayers[pCastSpell->uPlayerID_2].pConditions[Condition_Disease_Medium]
           || pParty->pPlayers[pCastSpell->uPlayerID_2].pConditions[Condition_Disease_Severe] )
@@ -2574,7 +2574,7 @@
           break;
         for ( uint pl_id = 0; pl_id < 4;  ++pl_id )
         {
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pl_id);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pl_id);
           pParty->pPlayers[pl_id].Heal(5 * spell_level + 10);
         }
         spell_sound_flag = true;
@@ -2585,7 +2585,7 @@
         sRecoveryTime -= spell_level;
         if ( !pPlayer->CanCastSpell(uRequiredMana) )
           break;
-        pGame->GetStru6()->FadeScreen__like_Turn_Undead_and_mb_Armageddon(0xAFF0A, 192);
+        pEngine->GetStru6()->FadeScreen__like_Turn_Undead_and_mb_Armageddon(0xAFF0A, 192);
         int mon_num = pRenderer->_46À6ÀÑ_GetActorsInViewport(4096);
         ++pSpellSprite.uType;
         v688.x = 0;
@@ -2670,10 +2670,10 @@
         }
         if ( !pPlayer->CanCastSpell(uRequiredMana) )
           break;
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
         pParty->pPartyBuffs[PARTY_BUFF_DAY_OF_GODS].Apply(pParty->uTimePlayed + 
                           (signed __int64)((double)(signed int)((int)duration << 7) * 0.033333335), skill_level, amount, 0, 0);
         spell_sound_flag = true;
@@ -2716,8 +2716,8 @@
           pSpellSprite.spell_target_pid = PID(OBJECT_Actor, _50BF30_actors_in_viewport_ids[mon_id]);
           Actor::DamageMonsterFromParty(PID(OBJECT_Item, pSpellSprite.Create(0, 0, 0, 0)), _50BF30_actors_in_viewport_ids[mon_id], &v694);
         }
-        //v537 = pGame->GetStru6();
-        pGame->GetStru6()->_4A8BFC();
+        //v537 = pEngine->GetStru6();
+        pEngine->GetStru6()->_4A8BFC();
         spell_sound_flag = true;
         break;
       }
@@ -2734,10 +2734,10 @@
         }
         if ( !pPlayer->CanCastSpell(uRequiredMana) )
           break;
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
-        pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
+        pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
         pParty->pPartyBuffs[PARTY_BUFF_RESIST_BODY].Apply(pParty->uTimePlayed + 
                            (signed __int64)((double)(duration << 7) * 0.033333335), skill_level, amount, 0, 0);
         pParty->pPartyBuffs[PARTY_BUFF_RESIST_MIND].Apply(pParty->uTimePlayed + 
@@ -2773,10 +2773,10 @@
         bool player_weak = false;
         for ( uint pl_id = 0; pl_id < 4; pl_id++ )
         {
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 0);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 1);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 2);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, 3);
           pParty->pPlayers[pl_id].pPlayerBuffs[PLAYER_BUFF_BLESS].Apply(pParty->uTimePlayed + 
             (signed __int64)((double)((300 * amount * spell_level + 60) << 7) * 0.033333335), skill_level, spell_level + 5, 0, 0);
           if ( pParty->pPlayers[pl_id].pConditions[Condition_Weak] )
@@ -2812,7 +2812,7 @@
             pParty->pPlayers[pl_id].pConditions[buff_id] = 0;
           pParty->pPlayers[pl_id].sHealth = pParty->pPlayers[pl_id].GetMaxHealth();
           pParty->pPlayers[pl_id].sMana = pParty->pPlayers[pl_id].GetMaxMana();
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pl_id);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pl_id);
         }
         if ( pPlayer->sAgeModifier + 10 >= 120 )
           pPlayer->sAgeModifier = 120;
@@ -2838,7 +2838,7 @@
           break;
         if (!pCastSpell->spell_target_pid)
         {
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
           if ( pParty->pPlayers[pCastSpell->uPlayerID_2].pConditions[Condition_Dead] )
           {
             pParty->pPlayers[pCastSpell->uPlayerID_2].SetCondition(Condition_Zombie, 1);
@@ -3111,7 +3111,7 @@
           break;
         if ( skill_level != 3 && skill_level != 4 )
         {
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pCastSpell->uPlayerID_2);
           pParty->pPlayers[pCastSpell->uPlayerID_2].pPlayerBuffs[PLAYER_BUFF_PAIN_REFLECTION].Apply(pParty->uTimePlayed + 
                                (signed int)(signed __int64)((double)(signed int)((int)duration << 7) * 0.033333335), skill_level, amount, 0, 0);
           spell_sound_flag = true;
@@ -3119,7 +3119,7 @@
         }
         for ( uint pl_id = 0; pl_id < 4; pl_id++ )
         {
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pl_id);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pl_id);
           pParty->pPlayers[pl_id].pPlayerBuffs[PLAYER_BUFF_PAIN_REFLECTION].Apply(pParty->uTimePlayed + 
                             (signed int)(signed __int64)((double)(signed int)((int)duration << 7) * 0.033333335), skill_level, amount, 0, 0);
         }
@@ -3130,8 +3130,8 @@
       {
         if ( !pPlayer->CanCastSpell(uRequiredMana) )
           break;
-        pGame->GetIndoorCamera();
-        int mon_num = pRenderer->_46À6ÀÑ_GetActorsInViewport((signed __int64)pGame->pIndoorCameraD3D->GetPickDepth());
+        pEngine->GetIndoorCamera();
+        int mon_num = pRenderer->_46À6ÀÑ_GetActorsInViewport((signed __int64)pEngine->pIndoorCameraD3D->GetPickDepth());
         v707.x = 0;
         v707.y = 0;
         v707.z = 0;
@@ -3177,9 +3177,9 @@
           pPlayers[pl_array[j]]->sHealth += (signed __int64)((double)(signed int)amount / (double)pl_num);
           if ( pPlayers[pl_array[j]]->sHealth > pPlayers[pl_array[j]]->GetMaxHealth())
             pPlayers[pl_array[j]]->sHealth = pPlayers[pl_array[j]]->GetMaxHealth();
-          pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pl_array[j]);
+          pEngine->GetStru6()->SetPlayerBuffAnim(pCastSpell->uSpellID, pl_array[j]);
         }
-        pGame->GetStru6()->FadeScreen__like_Turn_Undead_and_mb_Armageddon(0, 64);
+        pEngine->GetStru6()->FadeScreen__like_Turn_Undead_and_mb_Armageddon(0, 64);
         spell_sound_flag = true;
         break;
       }
--- a/Engine/Spells/Spells.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Spells/Spells.cpp	Sun May 10 01:29:11 2015 +0200
@@ -4,7 +4,8 @@
 
 #define _CRT_SECURE_NO_WARNINGS
 #include <stdlib.h>
-#include "../ErrorHandling.h"
+
+#include "Engine/Engine.h"
 
 #include "Spells.h"
 #include "Engine/Graphics/Overlays.h"
@@ -18,7 +19,6 @@
 #include "Engine/Graphics/Indoor.h"
 #include "Media/Audio/AudioPlayer.h"
 #include "Engine/Objects/Actor.h"
-#include "../Game.h"
 #include "stru6.h"
 
 
@@ -565,10 +565,10 @@
         if (pParty->pPlayers[i].IsWeak())
           return;
       pParty->pPartyBuffs[PARTY_BUFF_HASTE].Apply(pParty->uTimePlayed + (signed int)(signed __int64)((double)(v9 * 128) * 0.033333335), skillMasteryPlusOne, 0, 0, 0);
-      pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 0);
-      pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 1);
-      pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 2);
-      pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 3);
+      pEngine->pStru6Instance->SetPlayerBuffAnim(uSpellID, 0);
+      pEngine->pStru6Instance->SetPlayerBuffAnim(uSpellID, 1);
+      pEngine->pStru6Instance->SetPlayerBuffAnim(uSpellID, 2);
+      pEngine->pStru6Instance->SetPlayerBuffAnim(uSpellID, 3);
       pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0);//çâóê àëòàðÿ
       return;
     case SPELL_AIR_SHIELD:
@@ -602,10 +602,10 @@
           uSkill = 9;
           break;
       }
-      pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 0);
-      pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 1);
-      pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 2);
-      pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 3);
+      pEngine->pStru6Instance->SetPlayerBuffAnim(uSpellID, 0);
+      pEngine->pStru6Instance->SetPlayerBuffAnim(uSpellID, 1);
+      pEngine->pStru6Instance->SetPlayerBuffAnim(uSpellID, 2);
+      pEngine->pStru6Instance->SetPlayerBuffAnim(uSpellID, 3);
       v36 = pParty->uTimePlayed + (signed int)(signed __int64)((double)(v9 << 7) * 0.033333335);
       pParty->pPartyBuffs[uSkill].Apply(v36, skillMasteryPlusOne, v60, 0, 0);
       pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0);
@@ -615,10 +615,10 @@
         v38 = 600 * uSkill;
       else
         v38 = 60 * uSkill;
-      pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 0);
-      pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 1);
-      pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 2);
-      pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 3);
+      pEngine->pStru6Instance->SetPlayerBuffAnim(uSpellID, 0);
+      pEngine->pStru6Instance->SetPlayerBuffAnim(uSpellID, 1);
+      pEngine->pStru6Instance->SetPlayerBuffAnim(uSpellID, 2);
+      pEngine->pStru6Instance->SetPlayerBuffAnim(uSpellID, 3);
       v39 = (signed __int64)((double)(v38 << 7) * 0.033333335);
       v36 = pParty->uTimePlayed + v39;
       pParty->pPartyBuffs[PARTY_BUFF_IMMOLATION].Apply(v36, skillMasteryPlusOne, uSkill, 0, 0);
@@ -667,10 +667,10 @@
         uSkill = PARTY_BUFF_RESIST_BODY;
         break;
       }
-      pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 0);
-      pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 1);
-      pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 2);
-      pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 3);
+      pEngine->pStru6Instance->SetPlayerBuffAnim(uSpellID, 0);
+      pEngine->pStru6Instance->SetPlayerBuffAnim(uSpellID, 1);
+      pEngine->pStru6Instance->SetPlayerBuffAnim(uSpellID, 2);
+      pEngine->pStru6Instance->SetPlayerBuffAnim(uSpellID, 3);
       pParty->pPartyBuffs[uSkill].Apply(pParty->uTimePlayed + (signed int)(signed __int64)((double)a6_4 * 4.2666669), skillMasteryPlusOne, v60, 0, 0);
       pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0);
       return;
@@ -690,10 +690,10 @@
         v43 = 4 * uSkill + 10;
         break;
       }
-      pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 0);
-      pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 1);
-      pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 2);
-      pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 3);
+      pEngine->pStru6Instance->SetPlayerBuffAnim(uSpellID, 0);
+      pEngine->pStru6Instance->SetPlayerBuffAnim(uSpellID, 1);
+      pEngine->pStru6Instance->SetPlayerBuffAnim(uSpellID, 2);
+      pEngine->pStru6Instance->SetPlayerBuffAnim(uSpellID, 3);
       v39 = (signed __int64)((double)(v42 << 7) * 0.033333335);
       v36 = pParty->uTimePlayed + v39;
       pParty->pPartyBuffs[PARTY_BUFF_DAY_OF_GODS].Apply(v36, skillMasteryPlusOne, v43, 0, 0);
--- a/Engine/Tables/FactionTable.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Tables/FactionTable.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,8 +3,10 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
+
+#include "Engine/Engine.h"
+
 #include "FactionTable.h"
-#include "../mm7_data.h"
 #include "../LOD.h"
 
 
--- a/Engine/Tables/IconFrameTable.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Tables/IconFrameTable.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,10 +3,11 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
-#include "../ErrorHandling.h"
+
+#include "Engine/Engine.h"
+
 #include "IconFrameTable.h"
 #include "../LOD.h"
-#include "../mm7_data.h"
 #include "FrameTableInc.h"
 
 //----- (00494F3A) --------------------------------------------------------
--- a/Engine/Tables/PlayerFrameTable.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Tables/PlayerFrameTable.cpp	Sun May 10 01:29:11 2015 +0200
@@ -4,11 +4,10 @@
 
 #define _CRT_SECURE_NO_WARNINGS
 
-#include "PlayerFrameTable.h"
+#include "Engine/Engine.h"
 
-#include "../ErrorHandling.h"
+#include "PlayerFrameTable.h"
 #include "FrameTableInc.h"
-#include "../mm7_data.h"
 
 
 //----- (00494AED) --------------------------------------------------------
--- a/Engine/Tables/TileTable.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/Tables/TileTable.cpp	Sun May 10 01:29:11 2015 +0200
@@ -7,14 +7,13 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "../ErrorHandling.h"
+#include "Engine/Engine.h"
+
 #include "TileFrameTable.h"
 #include "FrameTableInc.h"
 #include "Engine/Graphics/PaletteManager.h"
 #include "../LOD.h"
 
-#include "../mm7_data.h"
-
 
 //----- (00487E1D) --------------------------------------------------------
 TileTable::~TileTable()
--- a/Engine/TurnEngine/TurnEngine.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/TurnEngine/TurnEngine.cpp	Sun May 10 01:29:11 2015 +0200
@@ -4,9 +4,8 @@
 
 #define _CRT_SECURE_NO_WARNINGS
 
+#include "Engine/Engine.h"
 
-#include "../MM7.h"
-#include "../mm7_data.h"
 #include "Engine/Objects/Actor.h"
 #include "../Party.h"
 #include "Media/Audio/AudioPlayer.h"
@@ -19,8 +18,6 @@
 
 #include "TurnEngine.h"
 
-
-#include "../Game.h"
 struct stru262_TurnBased *pTurnEngine = new stru262_TurnBased;
 
 
--- a/Engine/mm7_data.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/mm7_data.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,7 +3,8 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
-#include "mm7_data.h"
+
+#include "Engine/Engine.h"
 
 #include "GUI/GUIWindow.h"
 #include "Party.h"
@@ -260,8 +261,6 @@
 #include "Engine/Tables/PlayerFrameTable.h"
 struct PlayerFrameTable *pPlayerFrameTable; // idb
 
-#include "MM7.h"
-
 
 std::array<stat_coord, 26> stat_string_coord = //4E2940
 {{
@@ -335,8 +334,8 @@
 
 float flt_4D84E8 = 0.0f;
 
-int pCurrentScreen = SCREEN_VIDEO; // 004E28F8
-unsigned int uGammaPos;
+enum CURRENT_SCREEN current_screen_type = SCREEN_VIDEO; // 004E28F8
+unsigned int uGammaPos = 0;
 std::array<int, 8> BtnTurnCoord = 
 {{
   0xA4, 0x5D, 0x16, 0xB, 0x5, 0xD, 0x7, 0x3B,
@@ -761,7 +760,7 @@
 int uLastPointedObjectID; // weak
 //unsigned __int8 bMonsterInfoUI_bDollInitialized;
 std::array<const char *, 44> aSpellNames;
-int pMainScreenNum; // weak
+enum CURRENT_SCREEN prev_screen_type; // weak
 int dword_506980_uW; // weak
 int dword_506984_uZ; // weak
 int dword_506988_uY; // weak
--- a/Engine/mm7_data.h	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/mm7_data.h	Sun May 10 01:29:11 2015 +0200
@@ -308,7 +308,7 @@
 
 extern float flt_4D84E8;
 
-extern int pCurrentScreen; // 004E28F8
+extern enum CURRENT_SCREEN current_screen_type; // 004E28F8
 extern unsigned int uGammaPos;
 extern std::array<int, 8> BtnTurnCoord;
 extern std::array<__int16, 4> RightClickPortraitXmin;
@@ -422,7 +422,7 @@
 extern int uLastPointedObjectID; // weak
 //extern unsigned __int8 bMonsterInfoUI_bDollInitialized;
 extern std::array<const char *, 44> aSpellNames;
-extern int pMainScreenNum; // weak
+extern enum CURRENT_SCREEN prev_screen_type; // weak
 extern int dword_506980_uW; // weak
 extern int dword_506984_uZ; // weak
 extern int dword_506988_uY; // weak
--- a/Engine/mm7text_ru.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/mm7text_ru.cpp	Sun May 10 01:29:11 2015 +0200
@@ -7,8 +7,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 
-#include "Log.h"
-#include "Engine/ErrorHandling.h"
+#include "Engine/Engine.h"
 
 
 struct GenderTableEntry
--- a/Engine/stuff.h	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/stuff.h	Sun May 10 01:29:11 2015 +0200
@@ -33,14 +33,3 @@
 
 
 
-inline void log(char *format, ...)
-{
-  va_list va;
-  va_start(va, format);
-  char msg[256];
-  vsprintf(msg, format, va);
-  va_end(va);
-  DWORD w;
-
-  WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), msg, strlen(msg), &w, 0);
-}
\ No newline at end of file
--- a/Engine/texts.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Engine/texts.cpp	Sun May 10 01:29:11 2015 +0200
@@ -5,8 +5,9 @@
 #define _CRT_SECURE_NO_WARNINGS
 #include <string.h>
 
+#include "Engine/Engine.h"
+
 #include "LOD.h"
-#include "mm7_data.h"
 #include "texts.h"
 
 
--- a/GUI/GUIButton.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/GUI/GUIButton.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,11 +3,13 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
+
+#include "Engine/Engine.h"
+
 #include "GUIButton.h"
 #include "GUIWindow.h"
 #include "GUIFont.h"
 
-#include "Engine/mm7_data.h"
 #include "Engine/LOD.h"
 #include "Engine/Texts.h"
 #include "OSWindow.h"
--- a/GUI/GUIFont.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/GUI/GUIFont.cpp	Sun May 10 01:29:11 2015 +0200
@@ -4,15 +4,14 @@
 
 #define _CRT_SECURE_NO_WARNINGS
 #include <string>
-#include "Engine/ErrorHandling.h"
+
+#include "Engine/Engine.h"
 
 #include "Engine/LOD.h"
 #include "GUIFont.h"
 #include "GUIWindow.h"
 #include "Engine/Graphics/Render.h"
 
-#include "Engine/mm7_data.h"
-
 
 extern LODFile_IconsBitmaps *pIcons_LOD;
 
--- a/GUI/GUIProgressBar.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/GUI/GUIProgressBar.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,15 +3,14 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
+#include "Engine/Engine.h"
+
 #include "GUIProgressBar.h"
-#include "Engine/ErrorHandling.h"
 #include "Engine/LOD.h"
 #include "Engine/Party.h"
 #include "Engine/Graphics/Render.h"
 #include "Engine/Tables/IconFrameTable.h"
 
-#include "Engine/mm7_data.h"
-
 
 
 
--- a/GUI/GUIWindow.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/GUI/GUIWindow.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,7 +3,7 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
-#include "Engine/ErrorHandling.h"
+#include "Engine/Engine.h"
 
 #include "GUIWindow.h"
 #include "GUIFont.h"
@@ -23,7 +23,6 @@
 #include "Engine/Awards.h"
 #include "Engine/Objects/Chest.h"
 #include "Engine/Graphics/Outdoor.h"
-#include "Engine/Game.h"
 #include "Engine/Tables/IconFrameTable.h"
 #include "Engine/Objects/Actor.h"
 
@@ -258,7 +257,7 @@
 	case WINDOW_GreetingNPC:
 		{
 		pIcons_LOD->SyncLoadedFilesCount();
-		pCurrentScreen = pMainScreenNum;
+		current_screen_type = prev_screen_type;
 		pKeyActionMap->SetWindowInputStatus(WINDOW_INPUT_CANCELLED);
 		break;
 		}
@@ -275,7 +274,7 @@
 		if ( bFlipOnExit )
 		{
           pParty->sRotationY = (stru_5C6E00->uIntegerDoublePi - 1) & (stru_5C6E00->uIntegerPi + pParty->sRotationY);
-          pGame->pIndoorCameraD3D->sRotationY = pParty->sRotationY;
+          pEngine->pIndoorCameraD3D->sRotationY = pParty->sRotationY;
 		}
 		pParty->uFlags |= 2u;
 		break;
@@ -286,7 +285,7 @@
 		pTexture_outside->Release();
 		pTexture_Dialogue_Background->Release();
 		pIcons_LOD->SyncLoadedFilesCount();
-		pCurrentScreen = pMainScreenNum;
+		current_screen_type = prev_screen_type;
 		break;
 		}
 	case WINDOW_SpellBook:
@@ -305,7 +304,7 @@
         pTexture_outside->Release();
         pTexture_Dialogue_Background->Release();
         pIcons_LOD->SyncLoadedFilesCount();
-        pCurrentScreen = pMainScreenNum;
+        current_screen_type = prev_screen_type;
         break;
 		}
 	case WINDOW_Dialogue:
@@ -316,7 +315,7 @@
         pTexture_Dialogue_Background->Release();
 
         pIcons_LOD->SyncLoadedFilesCount();
-        pCurrentScreen = pMainScreenNum;
+        current_screen_type = prev_screen_type;
         break;
 		}
   case WINDOW_null:
@@ -375,7 +374,7 @@
   pAudioPlayer->StopChannels(-1, -1);
   InitializeBookFonts();
   this->CreateButton(475, 445, 158, 34, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[79], 0); // Close
-  pCurrentScreen = SCREEN_BOOKS;
+  current_screen_type = SCREEN_BOOKS;
   full_num_items_in_book = 0;
   books_primary_item_per_page = 0;
   books_page_number = 0;
@@ -896,7 +895,7 @@
   v4 = (char *)pDialogueNPCCount - 1;
   pRenderer->DrawTextureIndexed(pNPCPortraits_x[0][0] - 4, pNPCPortraits_y[0][0] - 4, &pIcons_LOD->pTextures[uTextureID_50795C]);
   pRenderer->DrawTextureIndexed(pNPCPortraits_x[0][0], pNPCPortraits_y[0][0], pDialogueNPCPortraits[(signed int)v4]);
-  if ( pCurrentScreen == SCREEN_E )
+  if ( current_screen_type == SCREEN_E )
   {
     CharacterUI_InventoryTab_Draw(pPlayers[uActiveCharacter], true);
     if ( pDialogueNPCCount == uNumDialogueNPCPortraits && uHouse_ExitPic )
@@ -1438,8 +1437,8 @@
           break;
           }
         case WINDOW_Dialogue: {
-          pMainScreenNum = pCurrentScreen;
-          pCurrentScreen = SCREEN_NPC_DIALOGUE;
+          prev_screen_type = current_screen_type;
+          current_screen_type = SCREEN_NPC_DIALOGUE;
           pBtn_ExitCancel = pWindow->CreateButton(0x1D7u, 0x1BDu, 0xA9u, 0x23u, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[79], //"Exit"
                          pIcons_LOD->GetTexture(uExitCancelTextureId), 0);
           if ( pWindow->par1C != 1 )
@@ -1530,8 +1529,8 @@
             }
         case WINDOW_ChangeLocation:
         {
-          pMainScreenNum = pCurrentScreen;
-          pCurrentScreen = SCREEN_CHANGE_LOCATION;
+          prev_screen_type = current_screen_type;
+          current_screen_type = SCREEN_CHANGE_LOCATION;
           pBtn_ExitCancel = pWindow->CreateButton(                  566,                   445,  75,  33, 1, 0, UIMSG_CHANGE_LOCATION_ClickCencelBtn, 0, 'N', pGlobalTXT_LocalizationStrings[156], pIcons_LOD->GetTexture(uTextureID_BUTTDESC2), 0);//Îñòàòüñÿ â ýòîé îáëàñòè
           pBtn_YES        = pWindow->CreateButton(                  486,                   445,  75,  33, 1, 0, UIMSG_OnTravelByFoot, 0, 'Y', pWindow->Hint, pIcons_LOD->GetTexture(uTextureID_BUTTYES2), 0);
                             pWindow->CreateButton(pNPCPortraits_x[0][0], pNPCPortraits_y[0][0],  63,  73, 1, 0, UIMSG_OnTravelByFoot, 1, ' ', pWindow->Hint, 0, 0, 0);
@@ -1544,9 +1543,9 @@
           break;
             }
         case WINDOW_GreetingNPC: {// îêíî ïðèâåòñòâèÿ ÍÏÑ
-          pMainScreenNum = pCurrentScreen;
+          prev_screen_type = current_screen_type;
           pKeyActionMap->EnterText(0, 15, pWindow);
-          pCurrentScreen = SCREEN_BRANCHLESS_NPC_DIALOG;
+          current_screen_type = SCREEN_BRANCHLESS_NPC_DIALOG;
           break;
             }
 
@@ -1563,7 +1562,7 @@
   }
   if (eWindowType == WINDOW_HouseInterior)
   {
-    pCurrentScreen = SCREEN_HOUSE;
+    current_screen_type = SCREEN_HOUSE;
     pBtn_ExitCancel = pWindow->CreateButton(471, 445, 169, 35, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[80],//Âûéòè èç çäàíèÿ
                    pIcons_LOD->GetTexture(uExitCancelTextureId), 0);
     for ( v26 = 0; v26 < uNumDialogueNPCPortraits; ++v26 )
@@ -1597,8 +1596,8 @@
   {
     if (eWindowType == WINDOW_Transition)
     {
-      pMainScreenNum = pCurrentScreen;
-      pCurrentScreen = SCREEN_INPUT_BLV;
+      prev_screen_type = current_screen_type;
+      current_screen_type = SCREEN_INPUT_BLV;
       pBtn_ExitCancel = pWindow->CreateButton(0x236u, 0x1BDu, 0x4Bu, 0x21u, 1, 0, UIMSG_TransitionWindowCloseBtn, 0, 'N', pGlobalTXT_LocalizationStrings[34], pIcons_LOD->GetTexture(uTextureID_BUTTDESC2), 0);//Îòìåíà
       pBtn_YES        = pWindow->CreateButton(0x1E6u, 0x1BDu, 0x4Bu, 0x21u, 1, 0, UIMSG_TransitionUI_Confirm, 0, 'Y', pWindow->Hint, pIcons_LOD->GetTexture(uTextureID_BUTTYES2), 0);
                         pWindow->CreateButton(pNPCPortraits_x[0][0], pNPCPortraits_y[0][0], 0x3Fu, 0x49u, 1, 0, UIMSG_TransitionUI_Confirm, 1, 0x20u, pWindow->Hint, 0);
@@ -1630,7 +1629,7 @@
       ShowStatusBarString(pGlobalTXT_LocalizationStrings[39], 2);//Âûáðàòü öåëü
       ++pIcons_LOD->uTexturePacksCount;
       pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 103;
-      pCurrentScreen = SCREEN_CASTING;
+      current_screen_type = SCREEN_CASTING;
       if ( !pIcons_LOD->uNumPrevLoadedFiles )
         pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
     }
@@ -1748,11 +1747,11 @@
       }
       case WINDOW_Chest:
       {
-        if ( pCurrentScreen == SCREEN_CHEST )
+        if ( current_screen_type == SCREEN_CHEST )
         {
           Chest::DrawChestUI(pWindow->par1C);
         }
-        else if ( pCurrentScreen == SCREEN_CHEST_INVENTORY )
+        else if ( current_screen_type == SCREEN_CHEST_INVENTORY )
         {
           pRenderer->ClearZBuffer(0, 479);
           draw_leather();
@@ -1829,7 +1828,7 @@
           pMessageQueue_50CBD0->AddGUIMessage((UIMessageType)(int)ptr_507BD0->ptr_1C, 0, 0);
           pEventTimer->Resume();
           ptr_507BD0->Release();
-          pCurrentScreen = SCREEN_GAME;
+          current_screen_type = SCREEN_GAME;
           viewparams->bRedrawGameUI = true;
           continue;
         }
@@ -1851,7 +1850,7 @@
           ItemGen2.Reset();
           pWindow->Release();
           pEventTimer->Resume();
-          pCurrentScreen = 0;
+          current_screen_type = SCREEN_GAME;
           viewparams->bRedrawGameUI = true;
           v26 = atoi(pKeyActionMap->pPressedKeysBuffer);
           if ( v26 > 0 )
@@ -1957,7 +1956,7 @@
         if ( pHint && pHint != (char *)1 )
           pButton->DrawLabel(pHint, pFontCreate, 0, 0);
         pWindow->Release();
-        if (pCurrentScreen == SCREEN_SAVEGAME)
+        if (current_screen_type == SCREEN_SAVEGAME)
           pMessageQueue_50CBD0->AddGUIMessage(UIMSG_SaveGame, 0, 0);
         else
           pMessageQueue_50CBD0->AddGUIMessage(UIMSG_LoadGame, 0, 0);
@@ -2042,7 +2041,7 @@
           ItemGen2.Reset();
           pWindow->Release();
           pEventTimer->Resume();
-          pCurrentScreen = SCREEN_GAME;
+          current_screen_type = SCREEN_GAME;
           viewparams->bRedrawGameUI = 1;
           v39 = atoi(pKeyActionMap->pPressedKeysBuffer);
           if ( v39 > 0 )
@@ -2105,15 +2104,15 @@
   Dst.DrawTitleText(pFontSmallnum, 0, 0xCu, ui_mainmenu_copyright_color, pGlobalTXT_LocalizationStrings[157], 3);
 }
 
-int modal_window_prev_screen;
+enum CURRENT_SCREEN modal_window_prev_screen_type;
 
 //----- (004141CA) --------------------------------------------------------
 void ModalWindow(const char *pStrHint, UIMessageType OnRelease_message)
 {
   pEventTimer->Pause();
-  modal_window_prev_screen = pCurrentScreen;
+  modal_window_prev_screen_type = current_screen_type;
   pModalWindow = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_ModalWindow, OnRelease_message, pStrHint);
-  pCurrentScreen = SCREEN_MODAL_WINDOW;
+  current_screen_type = SCREEN_MODAL_WINDOW;
 }
 
 //----- (0041420D) --------------------------------------------------------
@@ -2140,7 +2139,7 @@
   pModalWindow->Release();
   pModalWindow = nullptr;
 
-  pCurrentScreen = modal_window_prev_screen;
+  current_screen_type = modal_window_prev_screen_type;
   pEventTimer->Resume();
 }
 
@@ -2587,7 +2586,7 @@
 }
 
 
-// 4E28F8: using guessed type int pCurrentScreen;
+// 4E28F8: using guessed type int current_screen_type;
 
 //----- (0040F82D) --------------------------------------------------------
 void __fastcall ZBuffer_Fill(int *pZBuffer, int uTextureId, int iZValue)
@@ -2684,7 +2683,7 @@
 					if (uActiveCharacter)
 						pPlayers[uActiveCharacter]->PlaySound(SPEECH_NotEnoughGold, 0);
 					if (!dword_7241C8)
-						pGame->Draw();
+						pEngine->Draw();
 					dword_7241C8 = 0;
 					return;
 				}
@@ -2794,7 +2793,7 @@
 		}
 	}
 	if (!dword_7241C8)
-		pGame->Draw();
+		pEngine->Draw();
 	dword_7241C8 = 0;
 }
 
--- a/GUI/GUIWindow.h	Sat May 09 12:55:58 2015 +0200
+++ b/GUI/GUIWindow.h	Sun May 10 01:29:11 2015 +0200
@@ -396,15 +396,15 @@
   SCREEN_BOOKS = 0x3,
   SCREEN_NPC_DIALOGUE = 0x4,
   SCREEN_REST = 0x5,
-  SCREEN_CHARACTERS = 0x7,
+  SCREEN_CHARACTERS = 7,
   SCREEN_SPELL_BOOK = 0x8,
   SCREEN_CREATORS = 0x9,
-  SCREEN_CHEST = 0xA,
-  SCREEN_SAVEGAME = 0xB,
-  SCREEN_LOADGAME = 0xC,
-  SCREEN_HOUSE = 0xD,
-  SCREEN_E = 0xE,
-  SCREEN_CHEST_INVENTORY = 0xF,
+  SCREEN_CHEST = 10,
+  SCREEN_SAVEGAME = 11,
+  SCREEN_LOADGAME = 12,
+  SCREEN_HOUSE = 13,
+  SCREEN_E = 14,
+  SCREEN_CHEST_INVENTORY = 15,
   SCREEN_VIDEO = 0x10,
   SCREEN_CHANGE_LOCATION = 0x11,
   SCREEN_INPUT_BLV = 0x12,
@@ -492,7 +492,7 @@
 MENU_STATE MainMenuUI_Credits_Loop();
 
 // save & load ui
-void SaveUI_Load();
+GUIWindow *SaveUI_Load(enum CURRENT_SCREEN screen);
 void SaveUI_Draw();
 
 void LoadUI_Draw();
@@ -526,13 +526,16 @@
 // game menu ui
 void GameMenuUI_DrawKeyBindings();
 void GameMenuUI_DrawVideoOptions();
+GUIWindow *GameMenuUI_Options_Load();
+GUIWindow *GameMenuUI_OptionsKeymapping_Load();
+GUIWindow *GameMenuUI_OptionsVideo_Load();
 void GameMenuUI_Options_Draw();
 
 
 
 
 // character ui
-struct GUIWindow *CharacterUI_Initialize(unsigned int _this);
+struct GUIWindow *CharacterUI_Initialize(enum CURRENT_SCREEN);
 const char *CharacterUI_GetSkillDescText(unsigned int uPlayerID, PLAYER_SKILL_TYPE uPlayerSkillType);
 void CharacterUI_SkillsTab_ShowHint();
 void CharacterUI_StatsTab_ShowHint();
--- a/GUI/UI/Books/UIMapBook.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/GUI/UI/Books/UIMapBook.cpp	Sun May 10 01:29:11 2015 +0200
@@ -1,7 +1,9 @@
 #define _CRT_SECURE_NO_WARNINGS
+
+#include "Engine/Engine.h"
+
 #include "UIMapBook.h"
 #include "..\..\..\Engine/Events.h"
-#include "..\..\..\Engine/MM7.h"
 #include "..\..\..\Engine/Graphics/Render.h"
 #include "..\..\..\IO/Mouse.h"
 #include "..\UIBooks.h"
@@ -16,8 +18,6 @@
 #include "..\..\..\Engine/OurMath.h"
 #include "..\..\..\Engine/texts.h"
 #include "..\..\..\Engine/Graphics/Level/Decoration.h"
-//
-#include "..\..\..\Engine/mm7_data.h"
 
 
 
--- a/GUI/UI/Books/UINotesBooks.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/GUI/UI/Books/UINotesBooks.cpp	Sun May 10 01:29:11 2015 +0200
@@ -1,5 +1,7 @@
 #define _CRT_SECURE_NO_WARNINGS
-#include "..\..\..\Engine/MM7.h"
+
+#include "Engine/Engine.h"
+
 #include "..\..\..\Engine/Graphics/Render.h"
 #include "..\..\..\IO/Mouse.h"
 #include "..\UIBooks.h"
@@ -14,7 +16,6 @@
 #include "..\..\..\Engine/Autonotes.h"
 #include "..\..\..\Engine/Tables/StorylineTextTable.h"
 #include "..\..\..\Engine/texts.h"
-#include "..\..\..\Engine/mm7_data.h"
 
 //----- (00413D3C) --------------------------------------------------------
 static const char *GetDayPart()
--- a/GUI/UI/Books/UISpellBook.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/GUI/UI/Books/UISpellBook.cpp	Sun May 10 01:29:11 2015 +0200
@@ -1,5 +1,7 @@
 #define _CRT_SECURE_NO_WARNINGS
-#include "..\..\..\Engine/MM7.h"
+
+#include "Engine/Engine.h"
+
 #include "..\..\..\Engine/Graphics/Render.h"
 #include "..\..\..\IO/Mouse.h"
 #include "..\UIBooks.h"
@@ -10,7 +12,6 @@
 #include "..\..\..\Engine/LOD.h"
 #include "..\..\..\Engine/Graphics/Viewport.h"
 #include "..\..\..\Engine/texts.h"
-#include "..\..\..\Engine/mm7_data.h"
 
 std::array<char *, 9> spellbook_texture_filename_suffices = {{"f", "a", "w", "e", "s", "m", "b", "l", "d"}}; // weak
 
--- a/GUI/UI/UIArena.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/GUI/UI/UIArena.cpp	Sun May 10 01:29:11 2015 +0200
@@ -4,7 +4,8 @@
 
 #define _CRT_SECURE_NO_WARNINGS
 
-#include "../../Engine/mm7_data.h"
+#include "Engine/Engine.h"
+
 #include "../../Engine/Graphics/Sprites.h"
 
 #include "../../GUI/GUIWindow.h"
@@ -17,7 +18,6 @@
 #include "../../Engine/Events.h"
 #include "../../Engine/Graphics/Viewport.h"
 #include "../../Engine/texts.h"
-#include "../../Engine/MM7.h"
 
 std::array<Vec2_int_, 20> pMonsterArenaPlacements = 
   {{
--- a/GUI/UI/UIBooks.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/GUI/UI/UIBooks.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,7 +3,9 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
-#include "..\../Engine/MM7.h"
+
+#include "Engine/Engine.h"
+
 #include "UIBooks.h"
 #include "..\../Engine/Graphics/Render.h"
 #include "..\../GUI/GUIWindow.h"
@@ -11,8 +13,6 @@
 #include "..\../Media/Audio/AudioPlayer.h"
 #include "..\../Engine/LOD.h"
 
-#include "..\../Engine/mm7_data.h"
-
 //----- (00413CC6) --------------------------------------------------------
 void BookUI_Draw(WindowType book)
 {
--- a/GUI/UI/UICharacter.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/GUI/UI/UICharacter.cpp	Sun May 10 01:29:11 2015 +0200
@@ -4,10 +4,11 @@
 
 #define _CRT_SECURE_NO_WARNINGS
 #include <algorithm> 
+
+#include "Engine/Engine.h"
+
 #include "UICharacter.h"
-#include "..\../Engine/MM7.h"
 #include "..\../Engine/MapInfo.h"
-#include "..\../Engine/Game.h"
 #include "..\../GUI/GUIWindow.h"
 #include "..\../GUI/GUIFont.h"
 #include "..\../GUI/GUIProgressBar.h"
@@ -22,7 +23,7 @@
 #include "..\../Engine/texts.h"
 #include "..\../IO/Mouse.h"
 
-#include "..\../Engine/mm7_data.h"
+
 
 int bRingsShownInCharScreen; // 5118E0
 
@@ -386,10 +387,8 @@
     PLAYER_SKILL_MIND,     PLAYER_SKILL_BODY,        PLAYER_SKILL_LIGHT,      PLAYER_SKILL_DARK};
 
 //----- (00421626) --------------------------------------------------------
-GUIWindow *CharacterUI_Initialize(unsigned int _this)
+GUIWindow *CharacterUI_Initialize(enum CURRENT_SCREEN screen)
 {
-  GUIWindow *pWindow; // edi@3
-
   ++pIcons_LOD->uTexturePacksCount;
   if ( !pIcons_LOD->uNumPrevLoadedFiles )
     pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
@@ -398,51 +397,52 @@
   pAudioPlayer->StopChannels(-1, -1);
   bRingsShownInCharScreen = false;
   CharacterUI_LoadPaperdollTextures();
-  pCurrentScreen = _this;
+  current_screen_type = screen;
 
-  pWindow = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_CharacterRecord, uActiveCharacter, 0);
-  pCharacterScreen_StatsBtn = pWindow->CreateButton(pViewport->uViewportTL_X + 12, pViewport->uViewportTL_Y + 308,
+  auto wnd = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_CharacterRecord, uActiveCharacter, 0);
+  pCharacterScreen_StatsBtn = wnd->CreateButton(pViewport->uViewportTL_X + 12, pViewport->uViewportTL_Y + 308,
                                 pIcons_LOD->GetTexture(papredoll_dbrds[9])->uTextureWidth,
                                 pIcons_LOD->GetTexture(papredoll_dbrds[9])->uTextureHeight,
                                 1, 0, UIMSG_ClickStatsBtn, 0, 'S', pGlobalTXT_LocalizationStrings[216],// Stats
                                 pIcons_LOD->GetTexture(papredoll_dbrds[10]),
                                 pIcons_LOD->GetTexture(papredoll_dbrds[9]), 0);
-  pCharacterScreen_SkillsBtn = pWindow->CreateButton(pViewport->uViewportTL_X + 102, pViewport->uViewportTL_Y + 308,
+  pCharacterScreen_SkillsBtn = wnd->CreateButton(pViewport->uViewportTL_X + 102, pViewport->uViewportTL_Y + 308,
                                  pIcons_LOD->GetTexture(papredoll_dbrds[7])->uTextureWidth,
                                  pIcons_LOD->GetTexture(papredoll_dbrds[7])->uTextureHeight,
                                  1, 0, UIMSG_ClickSkillsBtn, 0, 'K', pGlobalTXT_LocalizationStrings[205],//Skills
                                  pIcons_LOD->GetTexture(papredoll_dbrds[8]),
                                  pIcons_LOD->GetTexture(papredoll_dbrds[7]), 0);
-  pCharacterScreen_InventoryBtn = pWindow->CreateButton(pViewport->uViewportTL_X + 192, pViewport->uViewportTL_Y + 308,
+  pCharacterScreen_InventoryBtn = wnd->CreateButton(pViewport->uViewportTL_X + 192, pViewport->uViewportTL_Y + 308,
                                     pIcons_LOD->GetTexture(papredoll_dbrds[5])->uTextureWidth,
                                     pIcons_LOD->GetTexture(papredoll_dbrds[5])->uTextureHeight,
                                     1, 0, UIMSG_ClickInventoryBtn, 0, 'I', pGlobalTXT_LocalizationStrings[120], //Inventory
                                     pIcons_LOD->GetTexture(papredoll_dbrds[6]),
                                     pIcons_LOD->GetTexture(papredoll_dbrds[5]), 0);
-  pCharacterScreen_AwardsBtn = pWindow->CreateButton(pViewport->uViewportTL_X + 282, pViewport->uViewportTL_Y + 308,
+  pCharacterScreen_AwardsBtn = wnd->CreateButton(pViewport->uViewportTL_X + 282, pViewport->uViewportTL_Y + 308,
                                  pIcons_LOD->GetTexture(papredoll_dbrds[3])->uTextureWidth,
                                  pIcons_LOD->GetTexture(papredoll_dbrds[3])->uTextureHeight,
                                  1, 0, UIMSG_ClickAwardsBtn, 0, 'A', pGlobalTXT_LocalizationStrings[22], //Awards
                                  pIcons_LOD->GetTexture(papredoll_dbrds[4]),
                                  pIcons_LOD->GetTexture(papredoll_dbrds[3]), 0);
-  pCharacterScreen_ExitBtn = pWindow->CreateButton(pViewport->uViewportTL_X + 371, pViewport->uViewportTL_Y + 308,
+  pCharacterScreen_ExitBtn = wnd->CreateButton(pViewport->uViewportTL_X + 371, pViewport->uViewportTL_Y + 308,
                  pIcons_LOD->GetTexture(papredoll_dbrds[1])->uTextureWidth,
                  pIcons_LOD->GetTexture(papredoll_dbrds[1])->uTextureHeight,
                  1, 0, UIMSG_ClickExitCharacterWindowBtn, 0, 0, pGlobalTXT_LocalizationStrings[79],//Exit
                  pIcons_LOD->GetTexture(papredoll_dbrds[2]),
                  pIcons_LOD->GetTexture(papredoll_dbrds[1]), 0);
-  pWindow->CreateButton(0, 0, 476, 345, 1, 122, UIMSG_InventoryLeftClick, 0, 0, "", 0);
-  pCharacterScreen_DetalizBtn = pWindow->CreateButton(600, 300, 30, 30, 1, 0, UIMSG_ChangeDetaliz, 0, 0, pGlobalTXT_LocalizationStrings[64], 0);
-  pCharacterScreen_DollBtn = pWindow->CreateButton(476, 0, 164, 345, 1, 0, UIMSG_ClickPaperdoll, 0, 0, "", 0);
+  wnd->CreateButton(0, 0, 476, 345, 1, 122, UIMSG_InventoryLeftClick, 0, 0, "", 0);
+  pCharacterScreen_DetalizBtn = wnd->CreateButton(600, 300, 30, 30, 1, 0, UIMSG_ChangeDetaliz, 0, 0, pGlobalTXT_LocalizationStrings[64], 0);
+  pCharacterScreen_DollBtn = wnd->CreateButton(476, 0, 164, 345, 1, 0, UIMSG_ClickPaperdoll, 0, 0, "", 0);
 
-  pWindow->CreateButton( 61, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 1, '1', "", 0);
-  pWindow->CreateButton(177, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 2, '2', "", 0);
-  pWindow->CreateButton(292, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 3, '3', "", 0);
-  pWindow->CreateButton(407, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 4, '4', "", 0);
+  wnd->CreateButton(61, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 1, '1', "", 0);
+  wnd->CreateButton(177, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 2, '2', "", 0);
+  wnd->CreateButton(292, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 3, '3', "", 0);
+  wnd->CreateButton(407, 424, 31, 0, 2, 94, UIMSG_SelectCharacter, 4, '4', "", 0);
 
-  pWindow->CreateButton(0, 0, 0, 0, 1, 0, UIMSG_CycleCharacters, 0, '\t', "", 0);
+  wnd->CreateButton(0, 0, 0, 0, 1, 0, UIMSG_CycleCharacters, 0, '\t', "", 0);
   FillAwardsData();
-  return pWindow;
+
+  return wnd;
 }
 
 //----- (004219BE) --------------------------------------------------------
@@ -454,7 +454,7 @@
   pAudioPlayer->StopChannels(-1, -1);
   bRingsShownInCharScreen = 0;
   CharacterUI_LoadPaperdollTextures();
-  pCurrentScreen = SCREEN_CASTING;
+  current_screen_type = SCREEN_CASTING;
   CS_inventory_window = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_CastSpell_InInventory, (int)this, 0);
   pCharacterScreen_ExitBtn = CS_inventory_window->CreateButton(394, 318, 75, 33, 1, 0, UIMSG_ClickExitCharacterWindowBtn, 0, 0,
                  pGlobalTXT_LocalizationStrings[79], // Close
@@ -1546,7 +1546,7 @@
     }
     else
     {
-      if (player->pInventoryItemList[player->pInventoryMatrix[i] - 1].IsIdentified() || pCurrentScreen != SCREEN_HOUSE)
+      if (player->pInventoryItemList[player->pInventoryMatrix[i] - 1].IsIdentified() || current_screen_type != SCREEN_HOUSE)
       {
         if (player->pInventoryItemList[player->pInventoryMatrix[i] - 1].IsBroken())
           pRenderer->DrawTransparentRedShade(uCellX, uCellY, pTexture);
--- a/GUI/UI/UIGuilds.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/GUI/UI/UIGuilds.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,9 +3,11 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
+
+#include "Engine/Engine.h"
+
 #include "..\../Engine/Objects/Items.h"
 #include "..\../GUI/GUIWindow.h"
-#include "..\../Engine/mm7_data.h"
 #include "..\../Engine/texts.h"
 #include "UIHouses.h"
 #include "..\../GUI/GUIFont.h"
--- a/GUI/UI/UIHouses.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/GUI/UI/UIHouses.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,14 +3,15 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
+
+#include "Engine/Engine.h"
+
 #include "UIGuilds.h"
 #include "UIPartyCreation.h"
 #include "UIShops.h"
 #include "..\../GUI/GUIButton.h"
 #include "..\../Engine/SaveLoad.h"
 #include "..\../Engine/Graphics/Texture.h"
-#include "..\../Engine/mm7_data.h"
-#include "..\../Engine/ErrorHandling.h"
 #include "UIHouses.h"
 #include "..\../Engine/Party.h"
 #include "..\../Engine/texts.h"
@@ -28,8 +29,6 @@
 #include "..\../Engine/Graphics/Viewport.h"
 #include "..\../IO/Keyboard.h"
 #include "..\../Engine/MapInfo.h"
-#include "..\../Engine/Log.h"
-#include "..\../Engine/Game.h"
 #include "..\../Engine/Spells/CastSpellInfo.h"
 
 #include "../../Engine/Graphics/Level/Decoration.h"
@@ -1564,7 +1563,7 @@
         }
         else
         {
-          pGame->pIndoorCameraD3D->sRotationY = 0;
+          pEngine->pIndoorCameraD3D->sRotationY = 0;
 
           pParty->uFlags |= 2u;
           pParty->vPosition.x = pTravel->arrival_x;
--- a/GUI/UI/UIMainMenu.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/GUI/UI/UIMainMenu.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,9 +3,11 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
+
+#include "Engine/Engine.h"
+
 #include "..\../IO/Mouse.h"
 #include "..\../IO/Keyboard.h"
-#include "..\../Engine/ErrorHandling.h"
 
 #include "..\../GUI/GUIWindow.h"
 #include "..\../GUI/GUIFont.h"
@@ -17,8 +19,8 @@
 #include "..\../Engine/texts.h"
 #include "..\../Engine/MMT.h"
 
-#include "..\../Engine/mm7_data.h"
-#include "..\../Engine/Game.h"
+#include "Game/Game.h"
+#include "Game/MainMenu.h"
 
 
 //----- (0041B578) --------------------------------------------------------
@@ -298,7 +300,7 @@
 
   pWindow_MainMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_MainMenu, 0, cred_texturet);
   pWindow_MainMenu->CreateButton(0, 0, 0, 0, 1, 0, UIMSG_Escape, 0, 27, "", 0);
-  pCurrentScreen = SCREEN_CREATORS;
+  current_screen_type = SCREEN_CREATORS;
   SetCurrentMenuID(MENU_CREDITSPROC);
 
   move_Y = 0;
@@ -307,7 +309,7 @@
     while ( PeekMessageA(&Msg, 0, 0, 0, 1) )
     {
       if ( Msg.message == 18 )
-        Game_DeinitializeAndTerminate(0);
+        Engine_DeinitializeAndTerminate(0);
       TranslateMessage(&Msg);
       DispatchMessageA(&Msg);
     }
@@ -328,8 +330,8 @@
       if ( move_Y >= cred_texture.uHeight )
         SetCurrentMenuID(MENU_MAIN);
       pRenderer->Present();
-      pCurrentScreen = SCREEN_GAME;//Ritor1: temporarily, must be corrected GUI_MainMenuMessageProc()
-      GUI_MainMenuMessageProc();
+      current_screen_type = SCREEN_GAME;//Ritor1: temporarily, must be corrected MainMenu_EventLoop()
+      MainMenu_EventLoop();
     }
   }
   while ( GetCurrentMenuID() == MENU_CREDITSPROC );
--- a/GUI/UI/UIOptions.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/GUI/UI/UIOptions.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,21 +3,20 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
-#include "..\../Engine/MM7.h"
+
+#include "Engine/Engine.h"
 
 #include "..\../IO/Keyboard.h"
 #include "..\../Engine/Graphics/IndoorCameraD3D.h"
 #include "..\../Engine/Graphics/GammaControl.h"
 #include "..\../Engine/Graphics/Render.h"
 
-#include "..\../Engine/Game.h"
 #include "..\../GUI/GUIWindow.h"
 #include "..\../GUI/GUIFont.h"
 #include "..\../Media/Audio/AudioPlayer.h"
 #include "..\../Engine/LOD.h"
 #include "..\../Engine/texts.h"
 
-#include "..\../Engine/mm7_data.h"
 
 
 
@@ -52,6 +51,49 @@
   return ui_gamemenu_keys_key_default_color;
 }
 
+
+GUIWindow *GameMenuUI_OptionsKeymapping_Load()
+{
+    uTextureID_Optkb[0] = pIcons_LOD->LoadTexture("optkb", TEXTURE_16BIT_PALETTE);
+    uTextureID_Optkb[1] = pIcons_LOD->LoadTexture("optkb_h", TEXTURE_16BIT_PALETTE);
+    uTextureID_Optkb[2] = pIcons_LOD->LoadTexture("resume1", TEXTURE_16BIT_PALETTE);
+    uTextureID_Optkb[3] = pIcons_LOD->LoadTexture("optkb_1", TEXTURE_16BIT_PALETTE);
+    uTextureID_Optkb[4] = pIcons_LOD->LoadTexture("optkb_2", TEXTURE_16BIT_PALETTE);
+
+    auto wnd = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_KeyMappingOptions, 0, 0);
+
+    wnd->CreateButton(241, 302, 214, 40, 1, 0, UIMSG_Escape, 0, 0, "", 0);
+
+    wnd->CreateButton(19, 302, 108, 20, 1, 0, UIMSG_SelectKeyPage1, 0, 0, "", 0);
+    wnd->CreateButton(127, 302, 108, 20, 1, 0, UIMSG_SelectKeyPage2, 0, 0, "", 0);
+    wnd->CreateButton(127, 324, 108, 20, 1, 0, UIMSG_ResetKeyMapping, 0, 0, "", 0);
+    wnd->CreateButton(19, 324, 108, 20, 1, 0, UIMSG_Game_OpenOptionsDialog, 0, 0, "", 0);
+
+    wnd->CreateButton(129, 148, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 0, 0, "", 0);
+    wnd->CreateButton(129, 167, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 1, 0, "", 0);
+    wnd->CreateButton(129, 186, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 2, 0, "", 0);
+    wnd->CreateButton(129, 205, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 3, 0, "", 0);
+    wnd->CreateButton(129, 224, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 4, 0, "", 0);
+    wnd->CreateButton(129, 243, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 5, 0, "", 0);
+    wnd->CreateButton(129, 262, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 6, 0, "", 0);
+
+    wnd->CreateButton(350, 148, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 7, 0, "", 0);
+    wnd->CreateButton(350, 167, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 8, 0, "", 0);
+    wnd->CreateButton(350, 186, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 9, 0, "", 0);
+    wnd->CreateButton(350, 205, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 10, 0, "", 0);
+    wnd->CreateButton(350, 224, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 11, 0, "", 0);
+    wnd->CreateButton(350, 243, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 12, 0, "", 0);
+    wnd->CreateButton(350, 262, 70, 19, 1, 0, UIMSG_ChangeKeyButton, 13, 0, "", 0);
+
+    uGameMenuUI_CurentlySelectedKeyIdx = -1;
+    KeyboardPageNum = 1;
+    memset(GameMenuUI_InvaligKeyBindingsFlags.data(), 0, sizeof(GameMenuUI_InvaligKeyBindingsFlags));
+    memcpy(pPrevVirtualCidesMapping.data(), pKeyActionMap->pVirtualKeyCodesMapping, 0x78u);
+
+    return wnd;
+}
+
+
 //----- (004142D3) --------------------------------------------------------
 void GameMenuUI_DrawKeyBindings()
 {
@@ -151,6 +193,51 @@
   }
 }
 
+
+GUIWindow *GameMenuUI_OptionsVideo_Load()
+{
+    optvid_base_texture_id = pIcons_LOD->LoadTexture("optvid", TEXTURE_16BIT_PALETTE);
+    bloodsplats_texture_id = pIcons_LOD->LoadTexture("opvdH-bs", TEXTURE_16BIT_PALETTE);
+    us_colored_lights_texture_id = pIcons_LOD->LoadTexture("opvdH-cl", TEXTURE_16BIT_PALETTE);
+    tinting_texture_id = pIcons_LOD->LoadTexture("opvdH-tn", TEXTURE_16BIT_PALETTE);
+    uTextureID_507C20 = pIcons_LOD->LoadTexture("con_ArrL", TEXTURE_16BIT_PALETTE);
+    uTextureID_507C24 = pIcons_LOD->LoadTexture("con_ArrR", TEXTURE_16BIT_PALETTE);
+    pTextureIDs_GammaPositions[0] = pIcons_LOD->LoadTexture("convol10", TEXTURE_16BIT_PALETTE);
+    pTextureIDs_GammaPositions[1] = pIcons_LOD->LoadTexture("convol20", TEXTURE_16BIT_PALETTE);
+    pTextureIDs_GammaPositions[2] = pIcons_LOD->LoadTexture("convol30", TEXTURE_16BIT_PALETTE);
+    pTextureIDs_GammaPositions[3] = pIcons_LOD->LoadTexture("convol40", TEXTURE_16BIT_PALETTE);
+    pTextureIDs_GammaPositions[4] = pIcons_LOD->LoadTexture("convol50", TEXTURE_16BIT_PALETTE);
+    pTextureIDs_GammaPositions[5] = pIcons_LOD->LoadTexture("convol60", TEXTURE_16BIT_PALETTE);
+    pTextureIDs_GammaPositions[6] = pIcons_LOD->LoadTexture("convol70", TEXTURE_16BIT_PALETTE);
+    pTextureIDs_GammaPositions[7] = pIcons_LOD->LoadTexture("convol80", TEXTURE_16BIT_PALETTE);
+    pTextureIDs_GammaPositions[8] = pIcons_LOD->LoadTexture("convol90", TEXTURE_16BIT_PALETTE);
+    pTextureIDs_GammaPositions[9] = pIcons_LOD->LoadTexture("convol00", TEXTURE_16BIT_PALETTE);
+    not_available_bloodsplats_texture_id = pIcons_LOD->LoadTexture("opvdG-bs", TEXTURE_16BIT_PALETTE);
+    not_available_us_colored_lights_texture_id = pIcons_LOD->LoadTexture("opvdG-cl", TEXTURE_16BIT_PALETTE);
+    not_available_tinting_texture_id = pIcons_LOD->LoadTexture("opvdG-tn", TEXTURE_16BIT_PALETTE);
+    auto wnd = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_VideoOptions, 0, 0);
+    wnd->CreateButton(0xF1u, 0x12Eu, 0xD6u, 0x28u, 1, 0, UIMSG_Escape, 0, 0, "", 0);
+    //if ( pRenderer->pRenderD3D )
+    {
+        wnd->CreateButton(0x13u, 0x118u, 0xD6u, 0x12u, 1, 0, UIMSG_ToggleBloodsplats, 0, 0, "", 0);
+        wnd->CreateButton(0x13u, 0x12Eu, 0xD6u, 0x12u, 1, 0, UIMSG_ToggleColoredLights, 0, 0, "", 0);
+        wnd->CreateButton(0x13u, 0x144u, 0xD6u, 0x12u, 1, 0, UIMSG_ToggleTint, 0, 0, "", 0);
+    }
+    /*if ( !pRenderer->bWindowMode )
+    {
+    //v0 = 1;
+    if ( pRenderer->IsGammaSupported() )
+    {
+    pBtn_SliderLeft = pGUIWindow_CurrentMenu->CreateButton(0x15u, 0xA1u, 0x10u, 0x10u, 1, 0, UIMSG_1A9, 4u, 0, "", pIcons_LOD->GetTexture(uTextureID_507C20), 0);
+    pBtn_SliderRight = pGUIWindow_CurrentMenu->CreateButton(0xD5u, 0xA1u, 0x10u, 0x10u, 1, 0, UIMSG_1A9, 5u, 0, "", pIcons_LOD->GetTexture(uTextureID_507C24), 0);
+    pGUIWindow_CurrentMenu->CreateButton(42, 162, 170, 18, 1, 0, UIMSG_1A9, 0, 0, "", 0);
+    }
+    }*/
+
+    return wnd;
+}
+
+
 //----- (00414D9A) --------------------------------------------------------
 void GameMenuUI_DrawVideoOptions()
 {
@@ -178,7 +265,7 @@
   }
   else*/
   {
-    if (pGame->uFlags2 & GAME_FLAGS_2_DRAW_BLOODSPLATS)
+    if (pEngine->uFlags2 & GAME_FLAGS_2_DRAW_BLOODSPLATS)
       pRenderer->DrawTextureIndexed(20, 281, pIcons_LOD->GetTexture(bloodsplats_texture_id));
     if (pRenderer->bUseColoredLights)
       pRenderer->DrawTextureIndexed(20, 303, pIcons_LOD->GetTexture(us_colored_lights_texture_id));
@@ -187,6 +274,80 @@
   }
 }
 
+
+GUIWindow *GameMenuUI_Options_Load()
+{
+    options_menu_skin.uTextureID_Background = pIcons_LOD->LoadTexture("ControlBG", TEXTURE_16BIT_PALETTE);
+    options_menu_skin.uTextureID_TurnSpeed[2] = pIcons_LOD->LoadTexture("con_16x", TEXTURE_16BIT_PALETTE);
+    options_menu_skin.uTextureID_TurnSpeed[1] = pIcons_LOD->LoadTexture("con_32x", TEXTURE_16BIT_PALETTE);
+    options_menu_skin.uTextureID_TurnSpeed[0] = pIcons_LOD->LoadTexture("con_Smoo", TEXTURE_16BIT_PALETTE);
+    options_menu_skin.uTextureID_ArrowLeft = pIcons_LOD->LoadTexture("con_ArrL", TEXTURE_16BIT_PALETTE);
+    options_menu_skin.uTextureID_ArrowRight = pIcons_LOD->LoadTexture("con_ArrR", TEXTURE_16BIT_PALETTE);
+    options_menu_skin.uTextureID_SoundLevels[0] = pIcons_LOD->LoadTexture("convol10", TEXTURE_16BIT_PALETTE);
+    options_menu_skin.uTextureID_SoundLevels[1] = pIcons_LOD->LoadTexture("convol20", TEXTURE_16BIT_PALETTE);
+    options_menu_skin.uTextureID_SoundLevels[2] = pIcons_LOD->LoadTexture("convol30", TEXTURE_16BIT_PALETTE);
+    options_menu_skin.uTextureID_SoundLevels[3] = pIcons_LOD->LoadTexture("convol40", TEXTURE_16BIT_PALETTE);
+    options_menu_skin.uTextureID_SoundLevels[4] = pIcons_LOD->LoadTexture("convol50", TEXTURE_16BIT_PALETTE);
+    options_menu_skin.uTextureID_SoundLevels[5] = pIcons_LOD->LoadTexture("convol60", TEXTURE_16BIT_PALETTE);
+    options_menu_skin.uTextureID_SoundLevels[6] = pIcons_LOD->LoadTexture("convol70", TEXTURE_16BIT_PALETTE);
+    options_menu_skin.uTextureID_SoundLevels[7] = pIcons_LOD->LoadTexture("convol80", TEXTURE_16BIT_PALETTE);
+    options_menu_skin.uTextureID_SoundLevels[8] = pIcons_LOD->LoadTexture("convol90", TEXTURE_16BIT_PALETTE);
+    options_menu_skin.uTextureID_SoundLevels[9] = pIcons_LOD->LoadTexture("convol00", TEXTURE_16BIT_PALETTE);
+    options_menu_skin.uTextureID_FlipOnExit = pIcons_LOD->LoadTexture("option04", TEXTURE_16BIT_PALETTE);
+    options_menu_skin.uTextureID_AlwaysRun = pIcons_LOD->LoadTexture("option03", TEXTURE_16BIT_PALETTE);
+    options_menu_skin.uTextureID_ShowDamage = pIcons_LOD->LoadTexture("option02", TEXTURE_16BIT_PALETTE);
+    options_menu_skin.uTextureID_WalkSound = pIcons_LOD->LoadTexture("option01", TEXTURE_16BIT_PALETTE);
+
+    auto wnd = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Options, 0, 0);
+    wnd->CreateButton(22, 270,
+        pIcons_LOD->GetTexture(options_menu_skin.uTextureID_TurnSpeed[2])->uTextureWidth,
+        pIcons_LOD->GetTexture(options_menu_skin.uTextureID_TurnSpeed[2])->uTextureHeight,
+        1, 0, UIMSG_SetTurnSpeed, 0x80, 0, "", 0);
+    wnd->CreateButton(93, 270,
+        pIcons_LOD->GetTexture(options_menu_skin.uTextureID_TurnSpeed[1])->uTextureWidth,
+        pIcons_LOD->GetTexture(options_menu_skin.uTextureID_TurnSpeed[1])->uTextureHeight,
+        1, 0, UIMSG_SetTurnSpeed, 0x40u, 0, "", 0);
+    wnd->CreateButton(164, 270,
+        pIcons_LOD->GetTexture(options_menu_skin.uTextureID_TurnSpeed[0])->uTextureWidth,
+        pIcons_LOD->GetTexture(options_menu_skin.uTextureID_TurnSpeed[0])->uTextureHeight,
+        1, 0, UIMSG_SetTurnSpeed, 0, 0, "", 0);
+
+    wnd->CreateButton(20, 303,
+        pIcons_LOD->GetTexture(options_menu_skin.uTextureID_WalkSound)->uTextureWidth,
+        pIcons_LOD->GetTexture(options_menu_skin.uTextureID_WalkSound)->uTextureHeight,
+        1, 0, UIMSG_ToggleWalkSound, 0, 0, "", 0);
+    wnd->CreateButton(128, 303,
+        pIcons_LOD->GetTexture(options_menu_skin.uTextureID_ShowDamage)->uTextureWidth,
+        pIcons_LOD->GetTexture(options_menu_skin.uTextureID_ShowDamage)->uTextureHeight,
+        1, 0, UIMSG_ToggleShowDamage, 0, 0, "", 0);
+    wnd->CreateButton(20, 325,
+        pIcons_LOD->GetTexture(options_menu_skin.uTextureID_AlwaysRun)->uTextureWidth,
+        pIcons_LOD->GetTexture(options_menu_skin.uTextureID_AlwaysRun)->uTextureHeight,
+        1, 0, UIMSG_ToggleAlwaysRun, 0, 0, "", 0);
+    wnd->CreateButton(128, 325,
+        pIcons_LOD->GetTexture(options_menu_skin.uTextureID_FlipOnExit)->uTextureWidth,
+        pIcons_LOD->GetTexture(options_menu_skin.uTextureID_FlipOnExit)->uTextureHeight,
+        1, 0, UIMSG_ToggleFlipOnExit, 0, 0, "", 0);
+
+    pBtn_SliderLeft = wnd->CreateButton(243, 162, 16, 16, 1, 0, UIMSG_ChangeSoundVolume, 4, 0, "", pIcons_LOD->GetTexture(options_menu_skin.uTextureID_ArrowLeft), 0);
+    pBtn_SliderRight = wnd->CreateButton(435, 162, 16, 16, 1, 0, UIMSG_ChangeSoundVolume, 5, 0, "", pIcons_LOD->GetTexture(options_menu_skin.uTextureID_ArrowRight), 0);
+    wnd->CreateButton(263, 162, 172, 17, 1, 0, UIMSG_ChangeSoundVolume, 0, 0, "", 0);
+
+    pBtn_SliderLeft = wnd->CreateButton(243, 216, 16, 16, 1, 0, UIMSG_ChangeMusicVolume, 4, 0, "", pIcons_LOD->GetTexture(options_menu_skin.uTextureID_ArrowLeft), 0);
+    pBtn_SliderRight = wnd->CreateButton(435, 216, 16, 16, 1, 0, UIMSG_ChangeMusicVolume, 5, 0, "", pIcons_LOD->GetTexture(options_menu_skin.uTextureID_ArrowRight), 0);
+    wnd->CreateButton(263, 216, 172, 17, 1, 0, UIMSG_ChangeMusicVolume, 0, 0, "", 0);
+
+    pBtn_SliderLeft = wnd->CreateButton(243, 270, 16, 16, 1, 0, UIMSG_ChangeVoiceVolume, 4, 0, "", pIcons_LOD->GetTexture(options_menu_skin.uTextureID_ArrowLeft), 0);
+    pBtn_SliderRight = wnd->CreateButton(435, 270, 16, 16, 1, 0, UIMSG_ChangeVoiceVolume, 5, 0, "", pIcons_LOD->GetTexture(options_menu_skin.uTextureID_ArrowRight), 0);
+    wnd->CreateButton(263, 270, 172, 17, 1, 0, UIMSG_ChangeVoiceVolume, 0, 0, "", 0);
+
+    wnd->CreateButton(241, 302, 214, 40, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[619], 0); // "Return to Game"
+    wnd->CreateButton(19, 140, 214, 40, 1, 0, UIMSG_OpenKeyMappingOptions, 0, 0x4Bu, "", 0);
+    wnd->CreateButton(19, 194, 214, 40, 1, 0, UIMSG_OpenVideoOptions, 0, 86, "", 0);
+
+    return wnd;
+}
+
 //----- (00414F82) --------------------------------------------------------
 void GameMenuUI_Options_Draw()
 {
--- a/GUI/UI/UIPartyCreation.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/GUI/UI/UIPartyCreation.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,12 +3,15 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
+
+#include "Engine/Engine.h"
+
 #include "UIPartyCreation.h"
 #include "..\../IO/Mouse.h"
 #include "..\../IO/Keyboard.h"
-#include "..\../Engine/ErrorHandling.h"
 
-#include "..\../Engine/Game.h"
+#include "Game/Game.h"
+#include "Game/MainMenu.h"
 #include "..\../GUI/GUIWindow.h"
 #include "..\../GUI/GUIFont.h"
 #include "..\../Engine/Party.h"
@@ -19,7 +22,6 @@
 #include "..\../Engine/Tables/IconFrameTable.h"
 #include "..\../Engine/texts.h"
 
-#include "..\../Engine/mm7_data.h"
 #include "..\../Engine/MMT.h"
 
 
@@ -399,7 +401,7 @@
   ++pIcons_LOD->uTexturePacksCount;
   if ( !pIcons_LOD->uNumPrevLoadedFiles )
     pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
-  pCurrentScreen = SCREEN_PARTY_CREATION;
+  current_screen_type = SCREEN_PARTY_CREATION;
   uPlayerCreationUI_ArrowAnim = 0;
   uPlayerCreationUI_SkySliderPos = 0;
   uPlayerCreationUI_SelectedCharacter = 0;
@@ -531,7 +533,7 @@
 
   pFontCChar = LoadFont("cchar.fnt", "FONTPAL", NULL);
 }
-// 4E28F8: using guessed type int pCurrentScreen;
+// 4E28F8: using guessed type int current_screen_type;
 
 //----- (0049750E) --------------------------------------------------------
 void DeleteCCharFont()
@@ -588,7 +590,7 @@
     while ( PeekMessageA(&Msg, 0, 0, 0, PM_REMOVE) )
     {
       if ( Msg.message == WM_QUIT )
-        Game_DeinitializeAndTerminate(0);
+        Engine_DeinitializeAndTerminate(0);
       TranslateMessage(&Msg);
       DispatchMessageA(&Msg);
     }
@@ -597,7 +599,7 @@
     else
     {
       PlayerCreationUI_Draw();
-      GUI_MainMenuMessageProc();
+      MainMenu_EventLoop();
       pRenderer->BeginScene();
       GUI_UpdateWindows();
       pRenderer->EndScene();
--- a/GUI/UI/UIPopup.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/GUI/UI/UIPopup.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,16 +3,17 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
+
+#include "Engine/Engine.h"
+
 #include "UIPopup.h"
 #include "Books\UIMapBook.h"
 #include "UIShops.h"
-#include "..\../Engine/MM7.h"
 
 #include "..\../IO/Mouse.h"
 
 #include "..\../Engine/Graphics/Sprites.h"
 #include "..\../Engine/Graphics/Vis.h"
-#include "..\../Engine/Game.h"
 #include "..\../GUI/GUIWindow.h"
 #include "..\../GUI/GUIFont.h"
 #include "..\../Engine/Party.h"
@@ -26,8 +27,6 @@
 #include "..\../Engine/Graphics/PaletteManager.h"
 #include "..\../Engine/Timer.h"
 #include "..\../Engine/texts.h"
-
-#include "..\../Engine/mm7_data.h"
 #include "..\../Engine/Events.h"
 
 static char static_sub_417BB5_out_string[1200]; // static to a file, not sub actually
@@ -1301,7 +1300,7 @@
   unsigned int pX; // [sp+70h] [bp-8h]@3
   unsigned int pY; // [sp+74h] [bp-4h]@3
 
-  if ( pCurrentScreen == SCREEN_VIDEO || GetCurrentMenuID() == MENU_MAIN )
+  if ( current_screen_type == SCREEN_VIDEO || GetCurrentMenuID() == MENU_MAIN )
     return;
   if ( _this )
   {
@@ -1336,7 +1335,7 @@
   }
 
   pEventTimer->Pause();
-  switch(pCurrentScreen)
+  switch(current_screen_type)
   {
     case SCREEN_CASTING:
     {
@@ -1432,7 +1431,7 @@
           popup_window.uFrameX = pX + 30;
         popup_window.uFrameY = 40;
         //if ( pRenderer->pRenderD3D )
-          v5 = pGame->pVisInstance->get_picked_object_zbuf_val();
+          v5 = pEngine->pVisInstance->get_picked_object_zbuf_val();
         /*else
           v5 = pRenderer->pActiveZBuffer[pX + pSRZBufferLineOffsets[pY]];*/
         if (PID_TYPE((unsigned __int16)v5) == OBJECT_Actor)
@@ -1479,7 +1478,7 @@
     case SCREEN_E:
     case SCREEN_CHEST_INVENTORY:
     {
-      if ( (signed int)pX > 467 && pCurrentScreen != SCREEN_E )
+      if ( (signed int)pX > 467 && current_screen_type != SCREEN_E )
         Inventory_ItemPopupAndAlchemy();
       else if ( (signed int)pY >= 345 )
         break;
--- a/GUI/UI/UIRest.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/GUI/UI/UIRest.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,6 +3,9 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
+
+#include "Engine/Engine.h"
+
 #include "..\../GUI/GUIWindow.h"
 #include "..\../GUI/GUIFont.h"
 #include "..\../Engine/Party.h"
@@ -13,8 +16,6 @@
 #include "..\../Engine/Timer.h"
 #include "..\../Engine/texts.h"
 
-#include "..\../Engine/mm7_data.h"
-
 
 
 //----- (0041F6C1) --------------------------------------------------------
@@ -22,10 +23,10 @@
 {
   if ( !dword_506F14 )
     pAudioPlayer->StopChannels(-1, -1);
-  if ( pCurrentScreen != SCREEN_GAME)
+  if ( current_screen_type != SCREEN_GAME)
   {
     pGUIWindow_CurrentMenu->Release();
-    pCurrentScreen = SCREEN_GAME;
+    current_screen_type = SCREEN_GAME;
     viewparams->bRedrawGameUI = true;
   }
   pEventTimer->Pause();
@@ -59,7 +60,7 @@
   if ( !pIcons_LOD->uNumPrevLoadedFiles )
     pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
 
-  pCurrentScreen = SCREEN_REST;
+  current_screen_type = SCREEN_REST;
   _507CD4_RestUI_hourglass_anim_controller = 0;
   uTextureID_RestUI_restmain = pIcons_LOD->LoadTexture("restmain", TEXTURE_16BIT_PALETTE);
   uTextureID_RestUI_restb1 = pIcons_LOD->LoadTexture("restb1", TEXTURE_16BIT_PALETTE);
--- a/GUI/UI/UISaveLoad.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/GUI/UI/UISaveLoad.cpp	Sun May 10 01:29:11 2015 +0200
@@ -5,8 +5,7 @@
 #define _CRT_SECURE_NO_WARNINGS
 #include <io.h>
 
-#include "..\../Engine/MM7.h"
-#include "..\../Engine/ErrorHandling.h"
+#include "Engine/Engine.h"
 
 #include "..\../IO/Keyboard.h"
 
@@ -18,10 +17,6 @@
 #include "..\../Engine/SaveLoad.h"
 #include "..\../Engine/texts.h"
 
-#include "..\../Engine/mm7_data.h"
-
-#include "..\../Engine/Game.h"
-
 
 //----- (004601B7) --------------------------------------------------------
 static void UI_DrawSaveLoad(bool save)
@@ -172,7 +167,7 @@
   if ( uDialogueType )
   {
     pRenderer->DrawTextureIndexed(8, 8, pIcons_LOD->GetTexture(uTextureID_loadsave));
-    if ( pCurrentScreen == SCREEN_SAVEGAME )
+    if ( current_screen_type == SCREEN_SAVEGAME )
     {
       pRenderer->DrawTextureIndexed(241, 302, pIcons_LOD->GetTexture(uTextureID_LS_saveU));
       pRenderer->DrawTextureIndexed( 18, 141, pIcons_LOD->GetTexture(uTextureID_save_up));
@@ -226,7 +221,7 @@
   }
 
   pLODFile.FreeSubIndexAndIO();
-  if ( pCurrentScreen == SCREEN_SAVEGAME )
+  if ( current_screen_type == SCREEN_SAVEGAME )
   {
     uTextureID_x_d = pIcons_LOD->LoadTexture("x_d", TEXTURE_16BIT_PALETTE);
     uTextureID_LS_ = pIcons_LOD->LoadTexture("LS_saveD",TEXTURE_16BIT_PALETTE);
@@ -252,7 +247,7 @@
 }
 
 //----- (0045E93E) --------------------------------------------------------
-void SaveUI_Load()
+GUIWindow *SaveUI_Load(enum CURRENT_SCREEN screen)
 {
   char *v3; // eax@7
   LODWriteableFile pLODFile; // [sp+1Ch] [bp-248h]@1
@@ -269,7 +264,7 @@
   uTextureID_LS_saveU = pIcons_LOD->LoadTexture("LS_saveU", TEXTURE_16BIT_PALETTE);
   uTextureID_x_u = pIcons_LOD->LoadTexture("x_u", TEXTURE_16BIT_PALETTE);
   pRenderer->DrawTextureIndexed(8, 8, pIcons_LOD->GetTexture(uTextureID_loadsave));
-  if ( pCurrentScreen == SCREEN_SAVEGAME )
+  if (screen == SCREEN_SAVEGAME)
   {
     pRenderer->DrawTextureIndexed(241, 302, pIcons_LOD->GetTexture(uTextureID_LS_saveU));
     pRenderer->DrawTextureIndexed(351, 302, pIcons_LOD->GetTexture(uTextureID_x_u));
@@ -281,7 +276,8 @@
     pRenderer->DrawTextureIndexed(351, 302, pIcons_LOD->GetTexture(uTextureID_x_u));
     pRenderer->DrawTextureIndexed(18, 141, pIcons_LOD->GetTexture(uTextureID_load_up));
   }
-  pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, 25, 199, 0, pGlobalTXT_LocalizationStrings[505], 0, 0, 0);//Read...(×òåíèå...)
+
+  //pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, 25, 199, 0, pGlobalTXT_LocalizationStrings[505], 0, 0, 0);//Read...(×òåíèå...)
   pRenderer->Present();
   pSavegameList->Initialize(1);
   pLODFile.AllocSubIndicesAndIO(300, 0);
@@ -315,16 +311,19 @@
   uTextureID_LS_ = pIcons_LOD->LoadTexture("LS_saveD", TEXTURE_16BIT_PALETTE);
   uTextureID_AR_UP_DN = pIcons_LOD->LoadTexture("AR_UP_DN", TEXTURE_16BIT_PALETTE);
   uTextureID_AR_DN_DN = pIcons_LOD->LoadTexture("AR_DN_DN", TEXTURE_16BIT_PALETTE);
-  pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_SaveLoadButtons, 0, 0);
-  pGUIWindow_CurrentMenu->CreateButton(21, 198, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 0, 0, "", 0);
-  pGUIWindow_CurrentMenu->CreateButton(21, 218, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 1, 0, "", 0);
-  pGUIWindow_CurrentMenu->CreateButton(21, 238, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 2, 0, "", 0);
-  pGUIWindow_CurrentMenu->CreateButton(21, 258, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 3, 0, "", 0);
-  pGUIWindow_CurrentMenu->CreateButton(21, 278, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 4, 0, "", 0);
-  pGUIWindow_CurrentMenu->CreateButton(21, 298, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 5, 0, "", 0);
-  pGUIWindow_CurrentMenu->CreateButton(21, 318, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 6, 0, "", 0);
-  pBtnLoadSlot  = pGUIWindow_CurrentMenu->CreateButton(241, 302, 105, 40, 1, 0, UIMSG_SaveLoadBtn, 0, 0, "", pIcons_LOD->GetTexture(uTextureID_LS_), 0);
-  pBtnCancel    = pGUIWindow_CurrentMenu->CreateButton(350, 302, 105, 40, 1, 0, UIMSG_Cancel, 0, 0, "", pIcons_LOD->GetTexture(uTextureID_x_d), 0);
-  pBtnArrowUp   = pGUIWindow_CurrentMenu->CreateButton(215, 199,  17, 17, 1, 0, UIMSG_ArrowUp, 0, 0, "", pIcons_LOD->GetTexture(uTextureID_AR_UP_DN), 0);
-  pBtnDownArrow = pGUIWindow_CurrentMenu->CreateButton(215, 323,  17, 17, 1, 0, UIMSG_DownArrow, 34, 0, "", pIcons_LOD->GetTexture(uTextureID_AR_DN_DN), 0);
+
+  auto wnd = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_SaveLoadButtons, 0, 0);
+  wnd->CreateButton(21, 198, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 0, 0, "", 0);
+  wnd->CreateButton(21, 218, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 1, 0, "", 0);
+  wnd->CreateButton(21, 238, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 2, 0, "", 0);
+  wnd->CreateButton(21, 258, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 3, 0, "", 0);
+  wnd->CreateButton(21, 278, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 4, 0, "", 0);
+  wnd->CreateButton(21, 298, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 5, 0, "", 0);
+  wnd->CreateButton(21, 318, 191, 18, 1, 0, UIMSG_SelectLoadSlot, 6, 0, "", 0);
+  pBtnLoadSlot =  wnd->CreateButton(241, 302, 105, 40, 1, 0, UIMSG_SaveLoadBtn, 0, 0, "", pIcons_LOD->GetTexture(uTextureID_LS_), 0);
+  pBtnCancel =    wnd->CreateButton(350, 302, 105, 40, 1, 0, UIMSG_Cancel, 0, 0, "", pIcons_LOD->GetTexture(uTextureID_x_d), 0);
+  pBtnArrowUp =   wnd->CreateButton(215, 199,  17, 17, 1, 0, UIMSG_ArrowUp, 0, 0, "", pIcons_LOD->GetTexture(uTextureID_AR_UP_DN), 0);
+  pBtnDownArrow = wnd->CreateButton(215, 323,  17, 17, 1, 0, UIMSG_DownArrow, 34, 0, "", pIcons_LOD->GetTexture(uTextureID_AR_DN_DN), 0);
+
+  return wnd;
 }
\ No newline at end of file
--- a/GUI/UI/UIShops.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/GUI/UI/UIShops.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,10 +3,12 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
+
+#include "Engine/Engine.h"
+
 #include "UIShops.h"
 #include "..\../Engine/Objects/Items.h"
 #include "..\../GUI/GUIWindow.h"
-#include "..\../Engine/mm7_data.h"
 #include "..\../Engine/texts.h"
 #include "UIHouses.h"
 #include "..\../GUI/GUIFont.h"
@@ -1491,7 +1493,7 @@
   unsigned int v79; // [sp+A8h] [bp-Ch]@9
   int uPriceItemService; // [sp+ACh] [bp-8h]@12
 
-  if ( pCurrentScreen == SCREEN_E )
+  if ( current_screen_type == SCREEN_E )
   {
     pPlayers[uActiveCharacter]->OnInventoryLeftClick();
     return;
--- a/GUI/UI/UITransition.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/GUI/UI/UITransition.cpp	Sun May 10 01:29:11 2015 +0200
@@ -5,8 +5,8 @@
 #define _CRT_SECURE_NO_WARNINGS
 #include <io.h>
 
-#include "..\../Engine/ErrorHandling.h"
-#include "..\../Engine/mm7_data.h"
+#include "Engine/Engine.h"
+
 #include "..\../Media/MediaPlayer.h"
 #include "..\../Engine/MapInfo.h"
 #include "..\../GUI/GUIWindow.h"
--- a/GUI/UI/UiGame.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/GUI/UI/UiGame.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,18 +3,17 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
+
+#include "Engine/Engine.h"
+
 #include "..\../Engine/Events.h"
 #include "..\../Engine/Graphics/Texture.h"
-#include "..\../Engine/MM7.h"
-#include "..\../Engine/ErrorHandling.h"
 
 #include "..\../IO/Mouse.h"
 #include "..\../IO/Keyboard.h"
-#include "..\../Engine/mm7_data.h"
 
 #include "..\../Engine/Graphics/Vis.h"
 #include "..\../Engine/MapInfo.h"
-#include "..\../Engine/Game.h"
 #include "..\../GUI/GUIWindow.h"
 #include "..\../GUI/GUIFont.h"
 #include "..\../Engine/Party.h"
@@ -68,7 +67,7 @@
       player->PlaySound(SPEECH_NoRoom, 0);
   }
 
-  if (pCurrentScreen == SCREEN_GAME)
+  if (current_screen_type == SCREEN_GAME)
   {
     viewparams->bRedrawGameUI = true;
     if ( uActiveCharacter != uPlayerID )
@@ -79,18 +78,18 @@
       uActiveCharacter = uPlayerID;
       return;
     }
-    pGUIWindow_CurrentMenu = CharacterUI_Initialize(7);
+    pGUIWindow_CurrentMenu = CharacterUI_Initialize(SCREEN_CHARACTERS);
     return;
   }
-  if ( pCurrentScreen == SCREEN_SPELL_BOOK )
+  if ( current_screen_type == SCREEN_SPELL_BOOK )
     return;
-  if ( pCurrentScreen == SCREEN_CHEST )
+  if ( current_screen_type == SCREEN_CHEST )
   {
     viewparams->bRedrawGameUI = true;
     if ( uActiveCharacter == uPlayerID )
     {
       pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 103;
-      pCurrentScreen = SCREEN_CHEST_INVENTORY;
+      current_screen_type = SCREEN_CHEST_INVENTORY;
       uActiveCharacter = uPlayerID;
       return;
     }
@@ -99,14 +98,14 @@
     uActiveCharacter = uPlayerID;
     return;
   }
-  if ( pCurrentScreen != SCREEN_HOUSE )
+  if ( current_screen_type != SCREEN_HOUSE )
   {
-    if ( pCurrentScreen == SCREEN_E )
+    if ( current_screen_type == SCREEN_E )
     {
       uActiveCharacter = uPlayerID;
       return;
     }
-    if ( pCurrentScreen != SCREEN_CHEST_INVENTORY )
+    if ( current_screen_type != SCREEN_CHEST_INVENTORY )
     {
       viewparams->bRedrawGameUI = true;
       uActiveCharacter = uPlayerID;
@@ -118,7 +117,7 @@
     if ( uActiveCharacter == uPlayerID )
     {
       pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 103;
-      pCurrentScreen = SCREEN_CHEST_INVENTORY;
+      current_screen_type = SCREEN_CHEST_INVENTORY;
       uActiveCharacter = uPlayerID;
       return;
     }
@@ -139,12 +138,10 @@
   {
     __debugbreak(); // fix indexing
     pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 103;
-    pGUIWindow_CurrentMenu = CharacterUI_Initialize(14);
+    pGUIWindow_CurrentMenu = CharacterUI_Initialize(SCREEN_E);
     return;
   }
 }
-// 4E28F8: using guessed type int pCurrentScreen;
-// F8B19C: using guessed type int dword_F8B19C;
 
 //----- (00416B01) --------------------------------------------------------
 void GameUI_DrawNPCPopup(void *_this)//PopupWindowForBenefitAndJoinText
@@ -974,7 +971,7 @@
     
     static bool byte_50697C = false; // 50697C
     byte_50697C = !byte_50697C;
-    if ( byte_50697C && pCurrentScreen != SCREEN_REST )
+    if ( byte_50697C && current_screen_type != SCREEN_REST )
     {
       if (bFlashQuestBook)     pRenderer->DrawTextureIndexedAlpha(493, 355, pIcons_LOD->GetTexture(uTextureID_ib_td1_A));
       if (bFlashAutonotesBook) pRenderer->DrawTextureIndexedAlpha(527, 353, pIcons_LOD->GetTexture(uTextureID_ib_td2_A));
@@ -1176,13 +1173,13 @@
   pMouse->GetClickPos(&pX, &pY);
   if ( pX < 0 || pX > window->GetWidth() - 1 || pY < 0 || pY > window->GetHeight() - 1 )
     return;
-  if ( pCurrentScreen == SCREEN_GAME )
+  if ( current_screen_type == SCREEN_GAME )
   {
     if ( pX <= (window->GetWidth() - 1) * 0.73125 && pY <= (window->GetHeight() - 1) * 0.73125 ) 
     {
       //if ( pRenderer->pRenderD3D )  // inlined mm8::4C1E01
       {
-        pickedObjectPID = pGame->pVisInstance->get_picked_object_zbuf_val();
+        pickedObjectPID = pEngine->pVisInstance->get_picked_object_zbuf_val();
         if ( pX < (unsigned int)pViewport->uScreen_TL_X || pX > (unsigned int)pViewport->uScreen_BR_X
           || pY < (unsigned int)pViewport->uScreen_TL_Y || pY > (unsigned int)pViewport->uScreen_BR_Y )
           pickedObjectPID = -1;
@@ -1383,7 +1380,7 @@
     }
     //The game never gets to this point even in the original. It's also bugged(neither branch displays anything). 
     //TODO fix these and move them up before the window check loop.
-    if ( pCurrentScreen == SCREEN_CHEST )
+    if ( current_screen_type == SCREEN_CHEST )
     {
       Chest::ChestUI_WritePointedObjectStatusString();
       if ( uLastPointedObjectID != 0 )
@@ -1394,7 +1391,7 @@
       uLastPointedObjectID = 0;
       return;
     }
-    else if ( pCurrentScreen == SCREEN_HOUSE )
+    else if ( current_screen_type == SCREEN_HOUSE )
     {
       if ( dialog_menu_id != HOUSE_DIALOGUE_SHOP_BUY_STANDARD
         || (v16 = pRenderer->pActiveZBuffer[pX + pSRZBufferLineOffsets[pY]], v16 == 0)
@@ -1541,7 +1538,7 @@
     //++v1;
   }
   //while ( v1 < 14 );
-  if (pCurrentScreen == SCREEN_GAME || pCurrentScreen == SCREEN_NPC_DIALOGUE)
+  if (current_screen_type == SCREEN_GAME || current_screen_type == SCREEN_NPC_DIALOGUE)
   {
     if (pParty->FlyActive())
     {
@@ -2023,17 +2020,17 @@
 //----- (00441498) --------------------------------------------------------
 void  GameUI_DrawTorchlightAndWizardEye()
 {
-  if (pCurrentScreen == SCREEN_GAME
-      || pCurrentScreen == SCREEN_MENU
-      || pCurrentScreen == SCREEN_OPTIONS
-      || pCurrentScreen == SCREEN_REST
-      || pCurrentScreen == SCREEN_SPELL_BOOK
-      || pCurrentScreen == SCREEN_CHEST
-      || pCurrentScreen == SCREEN_SAVEGAME
-      || pCurrentScreen == SCREEN_LOADGAME
-      || pCurrentScreen == SCREEN_CHEST_INVENTORY
-      || pCurrentScreen == SCREEN_BOOKS
-      || pCurrentScreen == SCREEN_BRANCHLESS_NPC_DIALOG )
+  if (current_screen_type == SCREEN_GAME
+      || current_screen_type == SCREEN_MENU
+      || current_screen_type == SCREEN_OPTIONS
+      || current_screen_type == SCREEN_REST
+      || current_screen_type == SCREEN_SPELL_BOOK
+      || current_screen_type == SCREEN_CHEST
+      || current_screen_type == SCREEN_SAVEGAME
+      || current_screen_type == SCREEN_LOADGAME
+      || current_screen_type == SCREEN_CHEST_INVENTORY
+      || current_screen_type == SCREEN_BOOKS
+      || current_screen_type == SCREEN_BRANCHLESS_NPC_DIALOG )
   {
     if (pParty->TorchlightActive())
     {
@@ -2047,7 +2044,7 @@
     }
   }
 }
-// 4E28F8: using guessed type int pCurrentScreen;
+// 4E28F8: using guessed type int current_screen_type;
 
 
 //----- (00491F87) --------------------------------------------------------
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Game/Game.cpp	Sun May 10 01:29:11 2015 +0200
@@ -0,0 +1,3212 @@
+#include "Engine/Engine.h"
+#include "Engine/Party.h"
+#include "Engine/LOD.h"
+#include "Engine/Events.h"
+#include "Engine/Timer.h"
+#include "Engine/texts.h"
+#include "Engine/SaveLoad.h"
+#include "Engine/Registry.h"
+#include "Engine/Objects/Actor.h"
+#include "Engine/Objects/Chest.h"
+#include "Engine/Objects/ObjectList.h"
+#include "Engine/Objects/SpriteObject.h"
+#include "Engine/Graphics/IRender.h"
+#include "Engine/Graphics/Viewport.h"
+#include "Engine/Graphics/Outdoor.h"
+#include "Engine/Graphics/Overlays.h"
+#include "Engine/Graphics/Sprites.h"
+#include "Engine/Graphics/Vis.h"
+#include "Engine/Graphics/PaletteManager.h"
+#include "Engine/Graphics/DecalBuilder.h"
+#include "Engine/Graphics/Level/Decoration.h"
+#include "Engine/Tables/FrameTableInc.h"
+#include "Engine/TurnEngine/TurnEngine.h"
+#include "Engine/Spells/CastSpellInfo.h"
+
+#include "IO/Keyboard.h"
+#include "IO/Mouse.h"
+
+#include "Arcomage/Arcomage.h"
+
+#include "Media/Audio/AudioPlayer.h"
+#include "Media/Audio/AIL.h"
+
+#include "GUI/GUIWindow.h"
+#include "GUI/GUIProgressBar.h"
+#include "GUI/UI/UIHouses.h"
+#include "GUI/UI/UIShops.h"
+#include "GUI/UI/UIPartyCreation.h"
+#include "GUI/UI/UIGame.h"
+
+#include "Game/Game.h"
+
+
+void DoThatMessageThing()
+{
+    if (pMessageQueue_50CBD0->uNumMessages)
+        pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
+}
+
+
+
+void Game_StartDialogue(unsigned int actor_id)
+{
+    if (uActiveCharacter)
+    {
+        viewparams->field_48 = 1;
+
+        DoThatMessageThing();
+
+        dword_5B65D0_dialogue_actor_npc_id = pActors[actor_id].sNPC_ID;
+        GameUI_InitializeDialogue(&pActors[actor_id], true);
+    }
+}
+
+void Game_StartHirelingDialogue(unsigned int hireling_id)
+{
+    if (bNoNPCHiring || current_screen_type != 0)
+        return;
+
+    DoThatMessageThing();
+
+    uint hireling_slot = 0;
+    for (uint i = 0; i < 2; ++i)
+    {
+        if (pParty->pHirelings[i].pName)
+            pTmpBuf[hireling_slot++] = i;
+    }
+
+    for (uint i = 0; i < pNPCStats->uNumNewNPCs; ++i)
+    {
+        NPCData *npc = &pNPCStats->pNewNPCData[i];
+        if (npc->Hired()
+            && (!pParty->pHirelings[0].pName || strcmp(npc->pName, pParty->pHirelings[0].pName))
+            && (!pParty->pHirelings[1].pName || strcmp(npc->pName, pParty->pHirelings[1].pName)))
+        {
+            pTmpBuf[hireling_slot++] = i + 2;
+        }
+    }
+
+    if ((signed int)hireling_id + (signed int)pParty->hirelingScrollPosition < hireling_slot)
+    {
+        Actor actor;
+        memset(&actor, 0, sizeof(actor));
+        actor.sNPC_ID += -1 - pParty->hirelingScrollPosition - hireling_id;
+        GameUI_InitializeDialogue(&actor, true);
+    }
+}
+
+
+void Game_StartNewGameWhilePlaying(bool force_start)
+{
+    if (dword_6BE138 == 124 || force_start)
+    {
+        pIcons_LOD->SyncLoadedFilesCount();
+        pIcons_LOD->RemoveTexturesPackFromTextureList();
+        DoThatMessageThing();
+        pGUIWindow_CurrentMenu->Release();
+        uGameState = GAME_STATE_NEWGAME_OUT_GAMEMENU;
+        current_screen_type = SCREEN_GAME;
+        viewparams->bRedrawGameUI = 1;
+    }
+    else
+    {
+        ShowStatusBarString(pGlobalTXT_LocalizationStrings[201], 2);// "Are you sure?  Click again to start a New Game"
+        pAudioPlayer->PlaySound(SOUND_quest, 0, 0, -1, 0, 0, 0, 0);
+        dword_6BE138 = 124;
+    }
+    stru_506E40.Release();
+}
+
+void Game_QuitGameWhilePlaying(bool force_quit)
+{
+    if (dword_6BE138 == 132 || force_quit)
+    {
+        pIcons_LOD->SyncLoadedFilesCount();
+        pIcons_LOD->RemoveTexturesPackFromTextureList();
+        DoThatMessageThing();
+        pGUIWindow_CurrentMenu->Release();
+        current_screen_type = SCREEN_GAME;
+        viewparams->bRedrawGameUI = 1;
+        pAudioPlayer->PlaySound(SOUND_WoodDoorClosing, 0, 0, -1, 0, 0, 0, 0);
+        uGameState = GAME_STATE_GAME_QUITTING_TO_MAIN_MENU;
+    }
+    else
+    {
+        ShowStatusBarString(pGlobalTXT_LocalizationStrings[82], 2);// "Are you sure?  Click again to quit"
+        pAudioPlayer->PlaySound(SOUND_quest, 0, 0, -1, 0, 0, 0, 0);
+        dword_6BE138 = 132;
+    }
+    stru_506E40.Release();
+}
+
+void Game_OpenLoadGameDialog()
+{
+    pIcons_LOD->SyncLoadedFilesCount();
+    pIcons_LOD->RemoveTexturesPackFromTextureList();
+    DoThatMessageThing();
+    pGUIWindow_CurrentMenu->Release();
+    current_screen_type = SCREEN_LOADGAME;
+    LoadUI_Load(1);
+}
+
+
+
+//----- (004304E7) --------------------------------------------------------
+void Game_EventLoop()
+{
+    unsigned int v2; // edx@7
+    Actor *pActor; // ecx@13
+    int v4; // ecx@18
+    unsigned int v10; // ecx@73
+    int v14; // eax@98
+    int v18; // eax@106
+    float v19; // ST64_4@121
+    float v21; // ST64_4@126
+    float v22; // ST64_4@127
+    unsigned int v24; // ecx@149
+    GUIWindow *pWindow2; // ecx@248
+    bool pKeyBindingFlag; // eax@269
+    unsigned int v33; // eax@277
+    int v37; // eax@341
+    int v38; // eax@358
+    SHORT v39; // ax@365
+    char *v41; // eax@380
+    int v42; // eax@396
+    signed int v44; // eax@398
+    int v45; // edx@398
+    signed int v46; // ecx@398
+    char v47; // zf@399
+    char v48; // zf@405
+    BLVFace *pBLVFace; // ecx@410
+    ODMFace *pODMFace; // ecx@412
+    CastSpellInfo *pSpellInfo; // ecx@415
+    __int16 v53; // ax@431
+    int v54; // eax@432
+    int v55; // ecx@432
+    int v56; // edx@432
+    int v57; // eax@432
+    Player *pPlayer; // edx@442
+    unsigned int pMapNum; // eax@445
+    signed int v60; // ST64_4@459
+    __int16 v63; // dx@479
+    unsigned int v64; // eax@486
+    int v65; // ecx@486
+    int v66; // eax@488
+    char *v67; // eax@489
+    __int16 v68; // dx@498
+    char *v69; // eax@512
+    int v70; // eax@525
+    int v71; // edi@527
+    NPCData *pNPCData3; // esi@527
+    char *v73; // ecx@533
+    signed int v74; // edi@535
+    int v75; // eax@535
+    int v76; // esi@535
+    int v77; // eax@537
+    Player *pPlayer2; // ecx@549
+    signed int v81; // eax@552
+    signed int v83; // ecx@554
+    signed int v84; // ecx@554
+    GUIButton *pButton; // eax@578
+    unsigned int v86; // eax@583
+    const char *v87; // ecx@595
+    const char *v88; // ecx@596
+    unsigned int v90; // eax@602
+    int v91; // edx@605
+    int v92; // eax@605
+    int v93; // edx@605
+    int pPlayerNum; // edx@611
+    int v95; // eax@611
+    unsigned int v97; // eax@624
+    int v98; // eax@636
+    int v103; // eax@671
+    Player *pPlayer4; // ecx@718
+    int v105; // eax@718
+    Player *pPlayer5; // ST78_4@758
+    unsigned int v107; // eax@758
+    unsigned int v108; // eax@758
+    unsigned int v115; // eax@764
+    int v116; // eax@776
+    unsigned int v118; // eax@785
+    unsigned int v119; // ecx@786
+    unsigned int v121; // [sp-28h] [bp-624h]@711
+    unsigned int v123; // [sp-24h] [bp-620h]@711
+    unsigned int v125; // [sp-20h] [bp-61Ch]@711
+    int v127; // [sp-1Ch] [bp-618h]@107
+    unsigned int v128; // [sp-1Ch] [bp-618h]@711
+    GUIButton *pButton2; // [sp-4h] [bp-600h]@59
+    const char *v161; // [sp-4h] [bp-600h]@637
+    KeyToggleType pKeyToggleType; // [sp+0h] [bp-5FCh]@287
+    char *v173; // [sp+0h] [bp-5FCh]@444
+    char *v174; // [sp+0h] [bp-5FCh]@449
+    const char *v177; // [sp+0h] [bp-5FCh]@629
+    char *v178; // [sp+0h] [bp-5FCh]@637
+    signed int thisb; // [sp+14h] [bp-5E8h]@272
+    Player *pPlayer7; // [sp+14h] [bp-5E8h]@373
+    Player *pPlayer8; // [sp+14h] [bp-5E8h]@377
+    char *pMapName; // [sp+14h] [bp-5E8h]@445
+    Player *pPlayer9; // [sp+14h] [bp-5E8h]@455
+    int thisg; // [sp+14h] [bp-5E8h]@467
+    int thish; // [sp+14h] [bp-5E8h]@528
+    signed int thisi; // [sp+14h] [bp-5E8h]@535
+    MapInfo *pMapInfo; // [sp+14h] [bp-5E8h]@604
+    Player *pPlayer10; // [sp+14h] [bp-5E8h]@641
+    int uMessageParam; // [sp+18h] [bp-5E4h]@7
+    int uAction; // [sp+1Ch] [bp-5E0h]@18
+    NPCData *pNPCData4; // [sp+20h] [bp-5DCh]@23
+    unsigned int uNumSeconds; // [sp+24h] [bp-5D8h]@18
+    char v197; // [sp+2Bh] [bp-5D1h]@101
+    enum UIMessageType uMessage; // [sp+2Ch] [bp-5D0h]@7
+    unsigned int v199; // [sp+30h] [bp-5CCh]@7
+    char *v200; // [sp+34h] [bp-5C8h]@518
+    POINT v202; // [sp+40h] [bp-5BCh]@141
+    POINT a2; // [sp+48h] [bp-5B4h]@127
+    POINT v205; // [sp+58h] [bp-5A4h]@171
+    POINT v207; // [sp+68h] [bp-594h]@155
+    POINT v211; // [sp+88h] [bp-574h]@704
+    int v213; // [sp+98h] [bp-564h]@385
+    char pLevelName[32]; // [sp+9Ch] [bp-560h]@380
+    char pOut[32]; // [sp+BCh] [bp-540h]@370
+    FrameTableTxtLine v216; // [sp+DCh] [bp-520h]@524
+    int v217[9]; // [sp+158h] [bp-4A4h]@652
+    FrameTableTxtLine v218; // [sp+17Ch] [bp-480h]@524
+    char a1[64]; // [sp+1F8h] [bp-404h]@467
+    char Str2[128]; // [sp+238h] [bp-3C4h]@527
+    Actor actor; // [sp+2B8h] [bp-344h]@4
+    int currHour;
+
+    dword_50CDC8 = 0;
+    if (!pEventTimer->bPaused)
+    {
+        pParty->sEyelevel = pParty->uDefaultEyelevel;
+        pParty->uPartyHeight = pParty->uDefaultPartyHeight;
+    }
+    if (bDialogueUI_InitializeActor_NPC_ID)
+    {
+        //Actor::Actor(&actor);
+        memset(&actor, 0, 0x344u);
+        dword_5B65D0_dialogue_actor_npc_id = bDialogueUI_InitializeActor_NPC_ID;
+        actor.sNPC_ID = bDialogueUI_InitializeActor_NPC_ID;
+        GameUI_InitializeDialogue(&actor, false);
+        bDialogueUI_InitializeActor_NPC_ID = 0;
+    }
+    if (pMessageQueue_50CBD0->uNumMessages)
+    {
+        //v1 = "";
+        while (2)
+        {
+            if (!pMessageQueue_50CBD0->uNumMessages)
+                break;
+
+            pMessageQueue_50CBD0->PopMessage(&uMessage, &uMessageParam, (int *)&v199);
+            switch (uMessage)
+            {
+            case UIMSG_ChangeGameState:
+                uGameState = GAME_FINISHED;
+                continue;
+            case UIMSG_PlayArcomage:
+                BackToHouseMenu();
+                pArcomageGame->bGameInProgress = 1;
+                ArcomageGame::PrepareArcomage();
+                continue;
+
+            case UIMSG_StartNPCDialogue:          Game_StartDialogue(uMessageParam); continue;
+            case UIMSG_StartHireling1Dialogue:
+            case UIMSG_StartHireling2Dialogue:    Game_StartHirelingDialogue(uMessage - UIMSG_StartHireling1Dialogue); continue;
+            case UIMSG_BuyInShop_Identify_Repair: UIShop_Buy_Identify_Repair(); continue;
+            case UIMSG_ClickNPCTopic:             ClickNPCTopic(uMessageParam); continue;
+            case UIMSG_SelectShopDialogueOption:  OnSelectShopDialogueOption(uMessageParam); continue;
+            case UIMSG_SelectNPCDialogueOption:   OnSelectNPCDialogueOption((DIALOGUE_TYPE)uMessageParam); continue;
+            case UIMSG_ClickHouseNPCPortrait:     _4B4224_UpdateNPCTopics(uMessageParam); continue;
+            case UIMSG_StartNewGame:              Game_StartNewGameWhilePlaying(uMessageParam); continue;
+            case UIMSG_Game_OpenLoadGameDialog:   Game_OpenLoadGameDialog(); continue;
+            case UIMSG_Quit:                      Game_QuitGameWhilePlaying(uMessageParam); continue;
+            case UIMSG_80:
+                __debugbreak();
+                pIcons_LOD->SyncLoadedFilesCount();
+                pIcons_LOD->RemoveTexturesPackFromTextureList();
+                pGUIWindow_CurrentMenu->Release();
+                current_screen_type = SCREEN_OPTIONS;
+                pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_8, 0, 0);
+                continue;
+            case UIMSG_ArrowUp:
+                --pSaveListPosition;
+                if (pSaveListPosition < 0)
+                    pSaveListPosition = 0;
+                GUIWindow::Create(215, 199, 17, 17, WINDOW_PressedButton2, (int)pBtnArrowUp, 0);
+                continue;
+            case UIMSG_DownArrow:
+                ++pSaveListPosition;
+                if (pSaveListPosition >= uMessageParam)
+                    pSaveListPosition = uMessageParam - 1;
+                GUIWindow::Create(215, 323, 17, 17, WINDOW_PressedButton2, (int)pBtnDownArrow, 0);
+                continue;
+            case UIMSG_Cancel:
+                GUIWindow::Create(350, 302, 106, 42, WINDOW_CloseRestWindowBtn, (int)pBtnCancel, 0);
+                continue;
+            case UIMSG_SaveLoadBtn:
+                GUIWindow::Create(241, 302, 106, 42, WINDOW_SaveLoadBtn, (int)pBtnLoadSlot, 0);
+                continue;
+            case UIMSG_SelectLoadSlot:
+                if (pGUIWindow_CurrentMenu->receives_keyboard_input_2 == WINDOW_INPUT_IN_PROGRESS)
+                    pKeyActionMap->SetWindowInputStatus(WINDOW_INPUT_NONE);
+                if (current_screen_type != SCREEN_SAVEGAME || uLoadGameUI_SelectedSlot != pSaveListPosition + uMessageParam)
+                {
+                    v10 = pSaveListPosition + uMessageParam;
+                    if (dword_6BE138 == pSaveListPosition + uMessageParam)
+                    {
+                        pMessageQueue_50CBD0->AddGUIMessage(UIMSG_SaveLoadBtn, 0, 0);
+                        pMessageQueue_50CBD0->AddGUIMessage(UIMSG_LoadGame, 0, 0);
+                    }
+                    uLoadGameUI_SelectedSlot = v10;
+                    dword_6BE138 = v10;
+                }
+                else
+                {
+                    pKeyActionMap->EnterText(0, 19, pGUIWindow_CurrentMenu);
+                    if (strcmp(pSavegameHeader[uLoadGameUI_SelectedSlot].pName, pGlobalTXT_LocalizationStrings[72]))// "Empty"
+                        strcpy(pKeyActionMap->pPressedKeysBuffer, pSavegameHeader[uLoadGameUI_SelectedSlot].pName);
+                    pKeyActionMap->uNumKeysPressed = strlen(pKeyActionMap->pPressedKeysBuffer);
+                }
+                continue;
+            case UIMSG_LoadGame:
+                if (pSavegameUsedSlots[uLoadGameUI_SelectedSlot])
+                {
+                    LoadGame(uLoadGameUI_SelectedSlot);
+                    uGameState = GAME_STATE_LOADING_GAME;
+                }
+                stru_506E40.Release();
+                continue;
+            case UIMSG_SaveGame:
+                if (pGUIWindow_CurrentMenu->receives_keyboard_input_2 == WINDOW_INPUT_IN_PROGRESS)
+                {
+                    pKeyActionMap->SetWindowInputStatus(WINDOW_INPUT_NONE);
+                    strcpy((char *)&pSavegameHeader[uLoadGameUI_SelectedSlot], pKeyActionMap->pPressedKeysBuffer);
+                }
+                DoSavegame(uLoadGameUI_SelectedSlot);
+                stru_506E40.Release();
+                continue;
+            case UIMSG_Game_OpenSaveGameDialog:
+            {
+                pGUIWindow_CurrentMenu->Release();
+                pGUIWindow_CurrentMenu = SaveUI_Load(current_screen_type = SCREEN_SAVEGAME);
+                continue;
+            }
+            case UIMSG_Game_OpenOptionsDialog://Open
+            {
+                DoThatMessageThing();
+
+                pGUIWindow_CurrentMenu->Release();
+                pGUIWindow_CurrentMenu = GameMenuUI_Options_Load();
+
+                viewparams->field_48 = 1;
+                current_screen_type = SCREEN_OPTIONS;
+
+                continue;
+            }
+
+            case UIMSG_OpenKeyMappingOptions://Open
+            {
+                DoThatMessageThing();
+
+                pGUIWindow_CurrentMenu->Release();
+                pGUIWindow_CurrentMenu = GameMenuUI_OptionsKeymapping_Load();
+
+                viewparams->field_48 = 1;
+                current_screen_type = SCREEN_KEYBOARD_OPTIONS;
+
+                continue;
+            }
+
+            case UIMSG_ChangeKeyButton:
+            {
+                if (uGameMenuUI_CurentlySelectedKeyIdx != -1)
+                {
+                    pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);
+                }
+                else
+                {
+                    uGameMenuUI_CurentlySelectedKeyIdx = uMessageParam;
+                    if (KeyboardPageNum != 1)
+                        uGameMenuUI_CurentlySelectedKeyIdx += 14;
+                    pKeyActionMap->EnterText(0, 1, pGUIWindow_CurrentMenu);
+                }
+                continue;
+            }
+
+            case UIMSG_ResetKeyMapping:
+            {
+                v197 = 1;
+                pKeyActionMap->SetDefaultMapping();
+                for (uint i = 0; i < 28; i++)
+                {
+                    if (pKeyActionMap->GetActionVKey((enum InputAction)i) != pPrevVirtualCidesMapping[i])
+                    {
+                        if (v197)
+                        {
+                            GUI_ReplaceHotkey(LOBYTE(pPrevVirtualCidesMapping[i]), pKeyActionMap->GetActionVKey((enum InputAction)i), 1);
+                            v197 = 0;
+                        }
+                        else
+                            GUI_ReplaceHotkey(LOBYTE(pPrevVirtualCidesMapping[i]), pKeyActionMap->GetActionVKey((enum InputAction)i), 0);
+                    }
+                    pPrevVirtualCidesMapping[i] = pKeyActionMap->GetActionVKey((enum InputAction)i);
+                    GameMenuUI_InvaligKeyBindingsFlags[i] = false;
+                }
+                pAudioPlayer->PlaySound(SOUND_chimes, 0, 0, -1, 0, 0, 0, 0);
+                continue;
+            }
+
+            case UIMSG_SelectKeyPage1:
+                KeyboardPageNum = 1;
+                continue;
+            case UIMSG_SelectKeyPage2:
+                KeyboardPageNum = 2;
+                continue;
+
+            case UIMSG_OpenVideoOptions:
+            {
+                DoThatMessageThing();
+
+                pGUIWindow_CurrentMenu->Release();
+                pGUIWindow_CurrentMenu = GameMenuUI_OptionsVideo_Load();
+                viewparams->field_48 = 1;
+                current_screen_type = SCREEN_VIDEO_OPTIONS;
+
+                continue;
+            }
+
+            case UIMSG_1A9:
+                __debugbreak();
+                if (uMessageParam == 4)
+                {
+                    //--uGammaPos;
+                    if ((uGammaPos-- - 1) < 0)
+                    {
+                        uGammaPos = 0;
+                        pAudioPlayer->PlaySound(SOUND_ClickMovingSelector, 0, 0, -1, 0, 0, 0, 0);
+                        continue;
+                    }
+                    v19 = (double)(signed int)uGammaPos * 0.1 + 0.6;
+                    //pEngine->pGammaController->Initialize(v19);
+                    GUIWindow::Create(21, 161, 0, 0, WINDOW_PressedButton2, (int)pBtn_SliderLeft, (char *)1);
+                    pAudioPlayer->PlaySound(SOUND_ClickMovingSelector, 0, 0, -1, 0, 0, 0, 0);
+                    continue;
+                }
+                if (uMessageParam == 5)
+                {
+                    ++uGammaPos;
+                    if ((signed int)uGammaPos <= 9)
+                    {
+                        v21 = (double)(signed int)uGammaPos * 0.1 + 0.6;
+                        //pEngine->pGammaController->Initialize(v21);
+                        GUIWindow::Create(213, 161, 0, 0, WINDOW_PressedButton2, (int)pBtn_SliderRight, (char *)1);
+                        pAudioPlayer->PlaySound(SOUND_ClickMovingSelector, 0, 0, -1, 0, 0, 0, 0);
+                        continue;
+                    }
+                    uGammaPos = 9;
+                }
+                else
+                {
+                    uGammaPos = (pMouse->GetCursorPos(&a2)->x - 42) / 17;
+                    v22 = (double)(signed int)uGammaPos * 0.1 + 0.6;
+                    //pEngine->pGammaController->Initialize(v22);
+                }
+                pAudioPlayer->PlaySound(SOUND_ClickMovingSelector, 0, 0, -1, 0, 0, 0, 0);
+                continue;
+            case UIMSG_ToggleBloodsplats:
+                pEngine->ToggleFlags2(0x20u);
+                continue;
+            case UIMSG_ToggleColoredLights:
+                pRenderer->ToggleColoredLights();
+                continue;
+            case UIMSG_ToggleTint:
+                pRenderer->ToggleTint();
+                continue;
+            case UIMSG_ChangeMusicVolume:
+                extern bool use_music_folder;
+                if (uMessageParam == 4)//-
+                {
+                    --uMusicVolimeMultiplier;
+                    if ((char)uMusicVolimeMultiplier < 1)
+                        uMusicVolimeMultiplier = 0;
+                    GUIWindow::Create(243, 216, 0, 0, WINDOW_PressedButton2, (int)pBtn_SliderLeft, (char *)1);
+                    if (uMusicVolimeMultiplier)
+                        pAudioPlayer->PlaySound(SOUND_hurp, -1, 0, -1, 0, 0, pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f, 0);
+
+                    if (use_music_folder)
+                        alSourcef(mSourceID, AL_GAIN, pSoundVolumeLevels[uMusicVolimeMultiplier]);
+                    else
+                        pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f);
+
+                    continue;
+                }
+                if (uMessageParam == 5)//+
+                {
+                    ++uMusicVolimeMultiplier;
+                    if ((char)uMusicVolimeMultiplier > 9)
+                        uMusicVolimeMultiplier = 9;
+                    GUIWindow::Create(435, 216, 0, 0, WINDOW_PressedButton2, (int)pBtn_SliderRight, (char *)1);
+                    if (uMusicVolimeMultiplier)
+                        pAudioPlayer->PlaySound(SOUND_hurp, -1, 0, -1, 0, 0, pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f, 0);
+                    if (use_music_folder)
+                        alSourcef(mSourceID, AL_GAIN, pSoundVolumeLevels[uMusicVolimeMultiplier]);
+                    else
+                        pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f);
+                    continue;
+                }
+                uMusicVolimeMultiplier = (pMouse->GetCursorPos(&v202)->x - 263) / 17;//for mouse
+                if ((char)uMusicVolimeMultiplier > 9)
+                    uMusicVolimeMultiplier = 9;
+                if (uMusicVolimeMultiplier)
+                    pAudioPlayer->PlaySound(SOUND_hurp, -1, 0, -1, 0, 0, pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f, 0);
+                if (use_music_folder)
+                    alSourcef(mSourceID, AL_GAIN, pSoundVolumeLevels[uMusicVolimeMultiplier]);
+                else
+                    pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f);
+                continue;
+            case UIMSG_ChangeSoundVolume:
+                if (uMessageParam == 4)//reduce sound level button left
+                {
+                    --uSoundVolumeMultiplier;
+                    if ((char)uSoundVolumeMultiplier < 1)
+                        uSoundVolumeMultiplier = 0;
+                    GUIWindow::Create(243, 162, 0, 0, WINDOW_PressedButton2, (int)pBtn_SliderLeft, (char *)1);
+                    pAudioPlayer->SetMasterVolume(pSoundVolumeLevels[uSoundVolumeMultiplier] * 128.0f);
+                    pAudioPlayer->PlaySound(SOUND_church, -1, 0, -1, 0, 0, 0, 0);
+                    int v = AIL_redbook_volume(pAudioPlayer->hAILRedbook);
+                    //v = v+1;
+                    if (v)
+                        __debugbreak();
+                    continue;
+                }
+                if (uMessageParam == 5)//Increase sound level button right
+                {
+                    ++uSoundVolumeMultiplier;
+                    if ((char)uSoundVolumeMultiplier > 8)
+                        uSoundVolumeMultiplier = 9;
+                    //v168 = 1;
+                    v24 = 435;
+                    //v154 = (int)pBtn_SliderRight;
+                    GUIWindow::Create(v24, 162, 0, 0, WINDOW_PressedButton2, (int)pBtn_SliderRight, (char *)1);
+                    pAudioPlayer->SetMasterVolume(pSoundVolumeLevels[uSoundVolumeMultiplier] * 128.0f);
+                    pAudioPlayer->PlaySound(SOUND_church, -1, 0, -1, 0, 0, 0, 0);
+                    continue;
+                }
+                uSoundVolumeMultiplier = (pMouse->GetCursorPos(&v207)->x - 263) / 17;
+                if ((char)uSoundVolumeMultiplier > 8)
+                    uSoundVolumeMultiplier = 9;
+                pAudioPlayer->SetMasterVolume(pSoundVolumeLevels[uSoundVolumeMultiplier] * 128.0f);
+                pAudioPlayer->PlaySound(SOUND_church, -1, 0, -1, 0, 0, 0, 0);
+                continue;
+            case UIMSG_ToggleFlipOnExit:
+                bFlipOnExit = bFlipOnExit == 0;
+                continue;
+            case UIMSG_ToggleAlwaysRun:
+                bAlwaysRun = bAlwaysRun == 0;
+                continue;
+            case UIMSG_ToggleWalkSound:
+                bWalkSound = bWalkSound == 0;
+                continue;
+            case UIMSG_ToggleShowDamage:
+                bShowDamage = bShowDamage == 0;
+                continue;
+            case UIMSG_ChangeVoiceVolume:
+                if (uMessageParam == 4)
+                {
+                    --uVoicesVolumeMultiplier;
+                    if ((char)uVoicesVolumeMultiplier < 1)
+                        uVoicesVolumeMultiplier = 0;
+                    GUIWindow::Create(243, 270, 0, 0, WINDOW_PressedButton2, (int)pBtn_SliderLeft, (char *)1);
+                    if (!uVoicesVolumeMultiplier)
+                        continue;
+                    pAudioPlayer->PlaySound(SOUND_hf445a, -1, 0, -1, 0, 0, pSoundVolumeLevels[uVoicesVolumeMultiplier] * 128.0f, 0);
+                    continue;
+                }
+                if (uMessageParam == 5)
+                {
+                    ++uVoicesVolumeMultiplier;
+                    if ((char)uVoicesVolumeMultiplier > 8)
+                        uVoicesVolumeMultiplier = 9;
+                    GUIWindow::Create(435, 270, 0, 0, WINDOW_PressedButton2, (int)pBtn_SliderRight, (char *)1);
+                    if (!uVoicesVolumeMultiplier)
+                        continue;
+                    pAudioPlayer->PlaySound(SOUND_hf445a, -1, 0, -1, 0, 0, pSoundVolumeLevels[uVoicesVolumeMultiplier] * 128.0f, 0);
+                    continue;
+                }
+                uVoicesVolumeMultiplier = (pMouse->GetCursorPos(&v205)->x - 263) / 17;
+                if ((char)uVoicesVolumeMultiplier > 8)
+                    uVoicesVolumeMultiplier = 9;
+                if (!uVoicesVolumeMultiplier)
+                    continue;
+                pAudioPlayer->PlaySound(SOUND_hf445a, -1, 0, -1, 0, 0, pSoundVolumeLevels[uVoicesVolumeMultiplier] * 128.0f, 0);
+                continue;
+            case UIMSG_SetTurnSpeed:
+                if (uMessageParam)
+                    pParty->sRotationY = uMessageParam * pParty->sRotationY / uMessageParam;
+                uTurnSpeed = uMessageParam;
+                continue;
+
+            case UIMSG_SetGraphicsMode:
+                /*if ( !bUseLoResSprites )
+                {
+                byte_6BE388_graphicsmode = uMessageParam;
+                MM7Initialization();
+                continue;
+                }
+                if ( uMessageParam )
+                {
+                if ( uMessageParam == 1 )
+                {
+                byte_6BE388_graphicsmode = 0;
+                }
+                else
+                {
+                if ( uMessageParam != 2 )
+                continue;
+                byte_6BE388_graphicsmode = 1;
+                }
+                MM7Initialization();
+                continue;
+                }*/
+                ModalWindow(pNPCTopics[453].pText, UIMSG_0);
+                __debugbreak(); // Nomad: graphicsmode as it was now removed
+                continue;
+
+            case UIMSG_GameMenu_ReturnToGame:
+                pGUIWindow_CurrentMenu->Release();
+                pEventTimer->Resume();
+                current_screen_type = SCREEN_GAME;
+                viewparams->bRedrawGameUI = 1;
+                stru_506E40.Release();
+                continue;
+            case UIMSG_OpenQuestBook:
+                DoThatMessageThing();
+                if (current_screen_type)
+                    pGUIWindow_CurrentMenu->Release();
+                pEventTimer->Pause();
+                pAudioPlayer->StopChannels(-1, -1);
+                pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Book, uMessage, 0);
+                pBooksWindow = GUIWindow::Create(493u, 355u, 0, 0, WINDOW_BooksWindow, (int)pBtn_Quests, 0);
+                bFlashQuestBook = 0;
+                continue;
+            case UIMSG_OpenAutonotes:
+                DoThatMessageThing();
+                if (current_screen_type)
+                    pGUIWindow_CurrentMenu->Release();
+                pEventTimer->Pause();
+                pAudioPlayer->StopChannels(-1, -1);
+                pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Book, uMessage, 0);
+                pBooksWindow = GUIWindow::Create(527u, 353u, 0, 0, WINDOW_BooksWindow, (int)pBtn_Autonotes, 0);
+                bFlashAutonotesBook = 0;
+                continue;
+            case UIMSG_OpenMapBook:
+                DoThatMessageThing();
+                if (current_screen_type)
+                    pGUIWindow_CurrentMenu->Release();
+                pEventTimer->Pause();
+                viewparams->sViewCenterX = pParty->vPosition.x;
+                viewparams->sViewCenterY = pParty->vPosition.y;
+                pAudioPlayer->StopChannels(-1, -1);
+                pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Book, uMessage, 0);
+                pBooksWindow = GUIWindow::Create(546, 353, 0, 0, WINDOW_BooksWindow, (int)pBtn_Maps, 0);
+                continue;
+            case UIMSG_OpenCalendar:
+                DoThatMessageThing();
+                if (current_screen_type)
+                    pGUIWindow_CurrentMenu->Release();
+                pEventTimer->Pause();
+                pAudioPlayer->StopChannels(-1, -1);
+                pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Book, uMessage, 0);
+                pBooksWindow = GUIWindow::Create(570, 354, 0, 0, WINDOW_BooksWindow, (int)pBtn_Calendar, 0);
+                continue;
+            case UIMSG_OpenHistoryBook:
+                DoThatMessageThing();
+                if (current_screen_type)
+                    pGUIWindow_CurrentMenu->Release();
+                pEventTimer->Pause();
+                pAudioPlayer->StopChannels(-1, -1);
+                pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Book, uMessage, 0);
+                pBooksWindow = GUIWindow::Create(0x258u, 0x169u, 0, 0, WINDOW_BooksWindow, (int)pBtn_History, 0);
+                bFlashHistoryBook = 0;
+                continue;
+            case UIMSG_Escape:// íàæàòèå Escape and return to game
+                back_to_game();
+                DoThatMessageThing();
+                switch (current_screen_type)
+                {
+                case SCREEN_E:
+                    __debugbreak();
+                case SCREEN_NPC_DIALOGUE:
+                case SCREEN_CHEST:
+                case SCREEN_CHEST_INVENTORY:
+                case SCREEN_CHANGE_LOCATION:
+                case SCREEN_INPUT_BLV:
+                case SCREEN_QUICK_REFERENCE:
+                    if (dword_50CDC8)
+                        break;
+                    CloseWindowBackground();
+                    uMessageParam = 1;
+                    break;
+                case SCREEN_HOUSE:
+                    if (!dword_50CDC8)
+                    {
+                        CloseWindowBackground();
+                        uMessageParam = 1;
+                        break;
+                    }
+                    break;
+                }
+                if (!pModalWindow)
+                {
+                    pRenderer->ClearZBuffer(0, 479);
+                    viewparams->bRedrawGameUI = 1;
+                    viewparams->field_48 = 1;
+                    if (current_screen_type)
+                    {
+                        if (current_screen_type > SCREEN_67)
+                        {
+                            if (current_screen_type == SCREEN_QUICK_REFERENCE)
+                            {
+                                pIcons_LOD->RemoveTexturesPackFromTextureList();
+                                if (pGUIWindow_Settings)
+                                {
+                                    if (current_screen_type == SCREEN_CHARACTERS)
+                                        pMouse->SetCursorBitmap("MICON2");
+                                    else
+                                    {
+                                        pGUIWindow_Settings->Release();
+                                        pGUIWindow_Settings = 0;
+                                        pMouse->SetCursorBitmap("MICON1");
+                                        GameUI_Footer_TimeLeft = 0;
+                                        _50C9A0_IsEnchantingInProgress = 0;
+                                        back_to_game();
+                                    }
+                                }
+                                if ((signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4)
+                                    uActiveCharacter = pParty->GetNextActiveCharacter();
+                                pGUIWindow_CurrentMenu->Release();
+                                if (pGUIWindow_CurrentMenu == window_SpeakInHouse)
+                                    window_SpeakInHouse = 0;
+                                pGUIWindow_CurrentMenu = 0;
+                                pEventTimer->Resume();
+                                current_screen_type = SCREEN_GAME;
+                                viewparams->bRedrawGameUI = 1;
+                                pIcons_LOD->RemoveTexturesFromTextureList();
+                                continue;
+                            }
+                        }
+                        else
+                        {
+                            if (current_screen_type < SCREEN_64)
+                            {
+                                switch (current_screen_type)
+                                {
+                                case SCREEN_CASTING:
+                                    pIcons_LOD->RemoveTexturesPackFromTextureList();
+                                    if (some_active_character)
+                                    {
+                                        uActiveCharacter = some_active_character;
+                                        uActiveCharacter = pParty->GetNextActiveCharacter();
+                                        some_active_character = 0;
+                                        if (pParty->bTurnBasedModeOn)
+                                            pTurnEngine->ApplyPlayerAction();
+                                        _50C9D0_AfterEnchClickEventId = 0;
+                                        _50C9D4_AfterEnchClickEventSecondParam = 0;
+                                        _50C9D8_AfterEnchClickEventTimeout = 0;
+                                    }
+                                    if (ptr_50C9A4_ItemToEnchant && ptr_50C9A4_ItemToEnchant->uItemID)
+                                    {
+                                        LOBYTE(ptr_50C9A4_ItemToEnchant->uAttributes) &= 0xFu;
+                                        _50C9A8_item_enchantment_timer = 0;
+                                        ptr_50C9A4_ItemToEnchant = nullptr;
+                                    }
+                                    if (pGUIWindow_Settings)
+                                    {
+                                        if (current_screen_type == SCREEN_CHARACTERS)
+                                            pMouse->SetCursorBitmap("MICON2");
+                                        else
+                                        {
+                                            pGUIWindow_Settings->Release();
+                                            pGUIWindow_Settings = 0;
+                                            pMouse->SetCursorBitmap("MICON1");
+                                            GameUI_Footer_TimeLeft = 0;
+                                            _50C9A0_IsEnchantingInProgress = 0;
+                                            back_to_game();
+                                        }
+                                    }
+                                    if ((signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4)
+                                        uActiveCharacter = pParty->GetNextActiveCharacter();
+                                    pGUIWindow_CurrentMenu->Release();
+                                    if (pGUIWindow_CurrentMenu == window_SpeakInHouse)
+                                        window_SpeakInHouse = 0;
+                                    pGUIWindow_CurrentMenu = 0;
+                                    pEventTimer->Resume();
+                                    current_screen_type = SCREEN_GAME;
+                                    viewparams->bRedrawGameUI = 1;
+                                    pIcons_LOD->RemoveTexturesFromTextureList();
+                                    continue;
+                                case SCREEN_BOOKS:
+                                    pBooksWindow->Release();
+                                    //crt_deconstruct_ptr_6A0118();
+                                    pBooksWindow = 0;
+                                    pEventTimer->Resume();
+                                    if (pGUIWindow_Settings)
+                                    {
+                                        if (current_screen_type == SCREEN_CHARACTERS)
+                                            pMouse->SetCursorBitmap("MICON2");
+                                        else
+                                        {
+                                            pGUIWindow_Settings->Release();
+                                            pGUIWindow_Settings = 0;
+                                            pMouse->SetCursorBitmap("MICON1");
+                                            GameUI_Footer_TimeLeft = 0;
+                                            _50C9A0_IsEnchantingInProgress = 0;
+                                            back_to_game();
+                                        }
+                                    }
+                                    if ((signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4)
+                                        uActiveCharacter = pParty->GetNextActiveCharacter();
+                                    pGUIWindow_CurrentMenu->Release();
+                                    if (pGUIWindow_CurrentMenu == window_SpeakInHouse)
+                                        window_SpeakInHouse = 0;
+                                    pGUIWindow_CurrentMenu = 0;
+                                    pEventTimer->Resume();
+                                    current_screen_type = SCREEN_GAME;
+                                    viewparams->bRedrawGameUI = 1;
+                                    pIcons_LOD->RemoveTexturesFromTextureList();
+                                    continue;
+                                case SCREEN_SAVEGAME:
+                                case SCREEN_LOADGAME:
+                                    pIcons_LOD->RemoveTexturesPackFromTextureList();
+                                    //crt_deconstruct_ptr_6A0118();
+                                    stru_506E40.Release();
+                                    break;
+                                case SCREEN_CHEST_INVENTORY:
+                                    current_screen_type = SCREEN_CHEST;
+                                    continue;
+                                case SCREEN_CHEST:
+                                    pWindow2 = pChestWindow;
+                                    pWindow2->Release();
+                                    pIcons_LOD->RemoveTexturesPackFromTextureList();
+                                    current_screen_type = SCREEN_GAME;
+                                    viewparams->bRedrawGameUI = 1;
+                                    pEventTimer->Resume();
+                                    continue;
+                                case SCREEN_19:
+                                    __debugbreak();
+                                    pWindow2 = ptr_507BC8;
+                                    pWindow2->Release();
+                                    pIcons_LOD->RemoveTexturesPackFromTextureList();
+                                    current_screen_type = SCREEN_GAME;
+                                    viewparams->bRedrawGameUI = 1;
+                                    pEventTimer->Resume();
+                                    continue;
+                                case SCREEN_OPTIONS://Close
+                                    options_menu_skin.Relaease();
+                                    pIcons_LOD->SyncLoadedFilesCount();
+                                    WriteWindowsRegistryInt("soundflag", (char)uSoundVolumeMultiplier);
+                                    WriteWindowsRegistryInt("musicflag", (char)uMusicVolimeMultiplier);
+                                    WriteWindowsRegistryInt("CharVoices", (char)uVoicesVolumeMultiplier);
+                                    WriteWindowsRegistryInt("WalkSound", bWalkSound);
+                                    WriteWindowsRegistryInt("ShowDamage", bShowDamage);
+                                    //WriteWindowsRegistryInt("graphicsmode", (unsigned __int8)byte_6BE388_graphicsmode);
+                                    WriteWindowsRegistryInt("valAlwaysRun", bAlwaysRun);
+                                    WriteWindowsRegistryInt("FlipOnExit", bFlipOnExit);
+                                    if (!uTurnSpeed)
+                                    {
+                                        WriteWindowsRegistryInt("TurnDelta", 3);
+                                        stru_506E40.Release();
+                                        break;
+                                    }
+                                    if (uTurnSpeed == 64)
+                                    {
+                                        WriteWindowsRegistryInt("TurnDelta", 2);
+                                        stru_506E40.Release();
+                                        break;
+                                    }
+                                    if (uTurnSpeed != 128)
+                                    {
+                                        stru_506E40.Release();
+                                        break;
+                                    }
+                                    WriteWindowsRegistryInt("TurnDelta", 1);
+                                    stru_506E40.Release();
+                                    break;
+                                case SCREEN_MENU:
+                                    pIcons_LOD->SyncLoadedFilesCount();
+                                    pIcons_LOD->RemoveTexturesPackFromTextureList();
+                                    pIcons_LOD->SyncLoadedFilesCount();
+                                    pIcons_LOD->RemoveTexturesPackFromTextureList();
+                                    stru_506E40.Release();
+                                    break;
+                                case SCREEN_VIDEO_OPTIONS:
+                                    //if ( pRenderer->pRenderD3D )
+                                {
+                                    WriteWindowsRegistryInt("Colored Lights", pRenderer->bUseColoredLights);
+                                    WriteWindowsRegistryInt("Tinting", pRenderer->bTinting);
+                                    WriteWindowsRegistryInt("Bloodsplats", (LOBYTE(pEngine->uFlags2) >> 5) & 1);
+                                }
+
+                                    stru_506E40.Release();
+                                    break;
+
+                                case SCREEN_KEYBOARD_OPTIONS://Return to game
+                                    v197 = 1;
+                                    pKeyBindingFlag = false;
+                                    for (uint i = 0; i < 28; ++i)
+                                    {
+                                        if (GameMenuUI_InvaligKeyBindingsFlags[i])
+                                            pKeyBindingFlag = true;
+                                    }
+                                    if (!pKeyBindingFlag)
+                                    {
+                                        for (uint i = 0; i < 5; i++)
+                                        {
+                                            if (uTextureID_Optkb[i])
+                                                pIcons_LOD->pTextures[uTextureID_Optkb[i]].Release();
+                                        }
+                                        memset(&uTextureID_Optkb, 0, 20);
+                                        pIcons_LOD->SyncLoadedFilesCount();
+                                        for (uint i = 0; i < 28; ++i)
+                                        {
+                                            if (pKeyActionMap->GetActionVKey((enum InputAction)i) != pPrevVirtualCidesMapping[i])
+                                            {
+                                                if (v197)
+                                                {
+                                                    GUI_ReplaceHotkey(pKeyActionMap->GetActionVKey((enum InputAction)i), LOBYTE(pPrevVirtualCidesMapping[i]), 1);
+                                                    v197 = 0;
+                                                }
+                                                else
+                                                    GUI_ReplaceHotkey(pKeyActionMap->GetActionVKey((enum InputAction)i), LOBYTE(pPrevVirtualCidesMapping[i]), 0);
+                                            }
+                                            if (i > 3 && i != 25 && i != 26)
+                                                pKeyToggleType = TOGGLE_OneTimePress;
+                                            else
+                                                pKeyToggleType = TOGGLE_Continuously;
+                                            pKeyActionMap->SetKeyMapping(i, pPrevVirtualCidesMapping[i], pKeyToggleType);
+                                        }
+                                        pKeyActionMap->StoreMappings();
+                                        stru_506E40.Release();
+                                        break;
+                                    }
+                                    pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);
+                                    break;
+                                case SCREEN_REST://close rest screen
+                                    if (dword_506F14)
+                                    {
+                                        Rest(_506F18_num_minutes_to_sleep);
+                                        pParty->pPlayers[3].SetAsleep(false);
+                                        pParty->pPlayers[2].SetAsleep(false);
+                                        pParty->pPlayers[1].SetAsleep(false);
+                                        pParty->pPlayers[0].SetAsleep(false);
+                                    }
+                                    pTexture_RestUI_CurrentSkyFrame->Release();
+                                    pTexture_RestUI_CurrentHourglassFrame->Release();
+                                    pTexture_RestUI_CurrentHourglassFrame = 0;
+                                    pTexture_RestUI_CurrentSkyFrame = 0;
+                                    pIcons_LOD->SyncLoadedFilesCount();
+                                    pIcons_LOD->RemoveTexturesPackFromTextureList();
+                                    if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
+                                    {
+                                        pOutdoor->UpdateSunlightVectors();
+                                        pOutdoor->UpdateFog();
+                                    }
+                                    _506F18_num_minutes_to_sleep = 0;
+                                    dword_506F14 = 0;
+                                    if (pGUIWindow_Settings)
+                                    {
+                                        if (current_screen_type == SCREEN_CHARACTERS)
+                                            pMouse->SetCursorBitmap("MICON2");
+                                        else
+                                        {
+                                            pGUIWindow_Settings->Release();
+                                            pGUIWindow_Settings = 0;
+                                            pMouse->SetCursorBitmap("MICON1");
+                                            GameUI_Footer_TimeLeft = 0;
+                                            _50C9A0_IsEnchantingInProgress = 0;
+                                            back_to_game();
+                                        }
+                                    }
+                                    if ((signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4)
+                                        uActiveCharacter = pParty->GetNextActiveCharacter();
+                                    pGUIWindow_CurrentMenu->Release();
+                                    if (pGUIWindow_CurrentMenu == window_SpeakInHouse)
+                                        window_SpeakInHouse = 0;
+                                    pGUIWindow_CurrentMenu = 0;
+                                    pEventTimer->Resume();
+                                    current_screen_type = SCREEN_GAME;
+                                    viewparams->bRedrawGameUI = 1;
+                                    pIcons_LOD->RemoveTexturesFromTextureList();
+                                    continue;
+                                case SCREEN_E:
+                                    __debugbreak();
+                                    pGUIWindow_CurrentMenu->Release();
+                                    current_screen_type = SCREEN_HOUSE;
+                                    pIcons_LOD->RemoveTexturesPackFromTextureList();
+                                    continue;
+                                case SCREEN_HOUSE:
+                                    if (uDialogueType)
+                                        uDialogueType = 0;
+                                    if (uGameState == GAME_STATE_CHANGE_LOCATION)
+                                    {
+                                        while (HouseDialogPressCloseBtn())
+                                            ;
+                                    }
+                                    else
+                                    {
+                                        if (HouseDialogPressCloseBtn())
+                                            continue;
+                                    }
+                                    GetHouseGoodbyeSpeech();
+                                    pAudioPlayer->PlaySound(SOUND_WoodDoorClosing, 814, 0, -1, 0, 0, 0, 0);
+                                    pMediaPlayer->Unload();
+                                    pGUIWindow_CurrentMenu = window_SpeakInHouse;
+                                    if (pGUIWindow_Settings)
+                                    {
+                                        if (current_screen_type == SCREEN_CHARACTERS)
+                                            pMouse->SetCursorBitmap("MICON2");
+                                        else
+                                        {
+                                            pGUIWindow_Settings->Release();
+                                            pGUIWindow_Settings = 0;
+                                            pMouse->SetCursorBitmap("MICON1");
+                                            GameUI_Footer_TimeLeft = 0;
+                                            _50C9A0_IsEnchantingInProgress = 0;
+                                            back_to_game();
+                                        }
+                                    }
+                                    if ((signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4)
+                                        uActiveCharacter = pParty->GetNextActiveCharacter();
+                                    pGUIWindow_CurrentMenu->Release();
+                                    if (pGUIWindow_CurrentMenu == window_SpeakInHouse)
+                                        window_SpeakInHouse = 0;
+                                    pGUIWindow_CurrentMenu = 0;
+                                    pEventTimer->Resume();
+                                    current_screen_type = SCREEN_GAME;
+                                    viewparams->bRedrawGameUI = true;
+                                    pIcons_LOD->RemoveTexturesFromTextureList();
+                                    continue;
+                                case SCREEN_INPUT_BLV://click escape
+                                    if (uCurrentHouse_Animation == 153)
+                                        PlayHouseSound(0x99u, HouseSound_Greeting_2);
+                                    pMediaPlayer->Unload();
+                                    if (npcIdToDismissAfterDialogue)
+                                    {
+                                        pParty->hirelingScrollPosition = 0;
+                                        LOBYTE(pNPCStats->pNewNPCData[npcIdToDismissAfterDialogue].uFlags) &= 0x7Fu;
+                                        pParty->CountHirelings();
+                                        viewparams->bRedrawGameUI = true;
+                                        npcIdToDismissAfterDialogue = 0;
+                                    }
+                                    DialogueEnding();
+                                    current_screen_type = SCREEN_GAME;
+                                    viewparams->bRedrawGameUI = true;
+                                    continue;
+                                case SCREEN_NPC_DIALOGUE://click escape
+                                    if (npcIdToDismissAfterDialogue)
+                                    {
+                                        pParty->hirelingScrollPosition = 0;
+                                        LOBYTE(pNPCStats->pNewNPCData[npcIdToDismissAfterDialogue].uFlags) &= 0x7Fu;
+                                        pParty->CountHirelings();
+                                        viewparams->bRedrawGameUI = true;
+                                        npcIdToDismissAfterDialogue = 0;
+                                    }
+                                    //goto LABEL_317;
+                                    DialogueEnding();
+                                    current_screen_type = SCREEN_GAME;
+                                    viewparams->bRedrawGameUI = true;
+                                    continue;
+                                case SCREEN_BRANCHLESS_NPC_DIALOG://click escape
+                                    memset(GameUI_Footer_TimedString.data(), 0, 0xC8u);
+                                    sub_4452BB();
+                                    DialogueEnding();
+                                    current_screen_type = SCREEN_GAME;
+                                    viewparams->bRedrawGameUI = true;
+                                    continue;
+                                case SCREEN_CHANGE_LOCATION://click escape
+                                    if (pParty->vPosition.x < -22528)
+                                        pParty->vPosition.x = -22528;
+                                    if (pParty->vPosition.x > 22528)
+                                        pParty->vPosition.x = 22528;
+                                    if (pParty->vPosition.y < -22528)
+                                        pParty->vPosition.y = -22528;
+                                    if (pParty->vPosition.y > 22528)
+                                        pParty->vPosition.y = 22528;
+                                    DialogueEnding();
+                                    current_screen_type = SCREEN_GAME;
+                                    viewparams->bRedrawGameUI = true;
+                                    continue;
+                                case SCREEN_VIDEO:
+                                    pMediaPlayer->Unload();
+                                    continue;
+                                case SCREEN_CHARACTERS:
+                                    CharacterUI_ReleaseButtons();
+                                    ReleaseAwardsScrollBar();
+                                    pIcons_LOD->RemoveTexturesPackFromTextureList();
+                                    if (pGUIWindow_Settings)
+                                    {
+                                        if (current_screen_type == SCREEN_CHARACTERS)
+                                            pMouse->SetCursorBitmap("MICON2");
+                                        else
+                                        {
+                                            pGUIWindow_Settings->Release();
+                                            pGUIWindow_Settings = 0;
+                                            pMouse->SetCursorBitmap("MICON1");
+                                            GameUI_Footer_TimeLeft = 0;
+                                            _50C9A0_IsEnchantingInProgress = 0;
+                                            back_to_game();
+                                        }
+                                    }
+                                    if ((signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4)
+                                        uActiveCharacter = pParty->GetNextActiveCharacter();
+                                    pGUIWindow_CurrentMenu->Release();
+                                    if (pGUIWindow_CurrentMenu == window_SpeakInHouse)
+                                        window_SpeakInHouse = 0;
+                                    pGUIWindow_CurrentMenu = 0;
+                                    pEventTimer->Resume();
+                                    current_screen_type = SCREEN_GAME;
+                                    viewparams->bRedrawGameUI = true;
+                                    pIcons_LOD->RemoveTexturesFromTextureList();
+                                    continue;
+                                default:
+                                    if (pGUIWindow_Settings)
+                                    {
+                                        if (current_screen_type == SCREEN_CHARACTERS)
+                                            pMouse->SetCursorBitmap("MICON2");
+                                        else
+                                        {
+                                            pGUIWindow_Settings->Release();
+                                            pGUIWindow_Settings = 0;
+                                            pMouse->SetCursorBitmap("MICON1");
+                                            GameUI_Footer_TimeLeft = 0;
+                                            _50C9A0_IsEnchantingInProgress = 0;
+                                            back_to_game();
+                                        }
+                                    }
+                                    if ((signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4)
+                                        uActiveCharacter = pParty->GetNextActiveCharacter();
+                                    pGUIWindow_CurrentMenu->Release();
+                                    if (pGUIWindow_CurrentMenu == window_SpeakInHouse)
+                                        window_SpeakInHouse = 0;
+                                    pGUIWindow_CurrentMenu = 0;
+                                    pEventTimer->Resume();
+                                    current_screen_type = SCREEN_GAME;
+                                    viewparams->bRedrawGameUI = 1;
+                                    pIcons_LOD->RemoveTexturesFromTextureList();
+                                    continue;
+                                }
+                                if (pGUIWindow_Settings)
+                                {
+                                    if (current_screen_type == SCREEN_CHARACTERS)
+                                        pMouse->SetCursorBitmap("MICON2");
+                                    else
+                                    {
+                                        pGUIWindow_Settings->Release();
+                                        pGUIWindow_Settings = 0;
+                                        pMouse->SetCursorBitmap("MICON1");
+                                        GameUI_Footer_TimeLeft = 0;
+                                        _50C9A0_IsEnchantingInProgress = 0;
+                                        back_to_game();
+                                    }
+                                }
+                                if ((signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4)
+                                    uActiveCharacter = pParty->GetNextActiveCharacter();
+                                pGUIWindow_CurrentMenu->Release();
+                                if (pGUIWindow_CurrentMenu == window_SpeakInHouse)
+                                    window_SpeakInHouse = 0;
+                                pGUIWindow_CurrentMenu = 0;
+                                pEventTimer->Resume();
+                                current_screen_type = SCREEN_GAME;
+                                viewparams->bRedrawGameUI = true;
+                                pIcons_LOD->RemoveTexturesFromTextureList();
+                                continue;
+                            }
+                            CharacterUI_ReleaseButtons();
+                            ReleaseAwardsScrollBar();
+                            pIcons_LOD->RemoveTexturesPackFromTextureList();
+                        }
+                        if (pGUIWindow_Settings)
+                        {
+                            if (current_screen_type == SCREEN_CHARACTERS)
+                                pMouse->SetCursorBitmap("MICON2");
+                            else
+                            {
+                                pGUIWindow_Settings->Release();
+                                pGUIWindow_Settings = 0;
+                                pMouse->SetCursorBitmap("MICON1");
+                                GameUI_Footer_TimeLeft = 0;
+                                _50C9A0_IsEnchantingInProgress = 0;
+                                back_to_game();
+                            }
+                        }
+                        if ((signed int)uActiveCharacter < 1 || (signed int)uActiveCharacter > 4)
+                            uActiveCharacter = pParty->GetNextActiveCharacter();
+                        pGUIWindow_CurrentMenu->Release();
+                        if (pGUIWindow_CurrentMenu == window_SpeakInHouse)
+                            window_SpeakInHouse = 0;
+                        pGUIWindow_CurrentMenu = 0;
+                        pEventTimer->Resume();
+                        current_screen_type = SCREEN_GAME;
+                        viewparams->bRedrawGameUI = true;
+                        pIcons_LOD->RemoveTexturesFromTextureList();
+                        continue;
+                    }
+                    if (!pGUIWindow_Settings)//Draw Menu
+                    {
+                        dword_6BE138 = -1;
+                        GUIWindow::Create(0x25Au, 0x1C2u, 0, 0, WINDOW_PressedButton2, (int)pBtn_GameSettings, (char *)1);
+                        pEventTimer->Pause();
+                        pAudioPlayer->StopChannels(-1, -1);
+                        current_screen_type = SCREEN_MENU;
+
+                        ++pIcons_LOD->uTexturePacksCount;
+                        if (!pIcons_LOD->uNumPrevLoadedFiles)
+                            pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
+
+                        pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_OptionsButtons, 0, 0);
+                        uTextureID_Options = pIcons_LOD->LoadTexture("options", TEXTURE_16BIT_PALETTE);
+                        uTextureID_New1 = pIcons_LOD->LoadTexture("new1", TEXTURE_16BIT_PALETTE);
+                        uTextureID_Load1 = pIcons_LOD->LoadTexture("load1", TEXTURE_16BIT_PALETTE);
+                        uTextureID_Save1 = pIcons_LOD->LoadTexture("save1", TEXTURE_16BIT_PALETTE);
+                        uTextureID_Controls1 = pIcons_LOD->LoadTexture("controls1", TEXTURE_16BIT_PALETTE);
+                        uTextureID_Resume1 = pIcons_LOD->LoadTexture("resume1", TEXTURE_16BIT_PALETTE);
+                        uTextureID_Quit1 = pIcons_LOD->LoadTexture("quit1", TEXTURE_16BIT_PALETTE);
+                        pBtn_NewGame = pGUIWindow_CurrentMenu->CreateButton(0x13u, 0x9Bu, 0xD6u, 0x28u, 1, 0, UIMSG_StartNewGame, 0, 0x4Eu,
+                            pGlobalTXT_LocalizationStrings[614],// "New Game"
+                            pIcons_LOD->GetTexture(uTextureID_New1), 0);
+                        pBtn_SaveGame = pGUIWindow_CurrentMenu->CreateButton(0x13u, 0xD1u, 0xD6u, 0x28u, 1, 0, UIMSG_Game_OpenSaveGameDialog, 0, 0x53u,
+                            pGlobalTXT_LocalizationStrings[615],// "Save Game"
+                            pIcons_LOD->GetTexture(uTextureID_Save1), 0);
+                        pBtn_LoadGame = pGUIWindow_CurrentMenu->CreateButton(19, 263, 0xD6u, 0x28u, 1, 0, UIMSG_Game_OpenLoadGameDialog, 0, 0x4Cu,
+                            pGlobalTXT_LocalizationStrings[616],// "Load Game"
+                            pIcons_LOD->GetTexture(uTextureID_Load1), 0);
+                        pBtn_GameControls = pGUIWindow_CurrentMenu->CreateButton(241, 155, 214, 40, 1, 0, UIMSG_Game_OpenOptionsDialog, 0, 0x43u,
+                            pGlobalTXT_LocalizationStrings[617],// ""Sound, Keyboard, Game Options:""
+                            pIcons_LOD->GetTexture(uTextureID_Controls1), 0);
+                        pBtn_QuitGame = pGUIWindow_CurrentMenu->CreateButton(241, 209, 214, 40, 1, 0, UIMSG_Quit, 0, 0x51u,
+                            pGlobalTXT_LocalizationStrings[618],// "Quit"
+                            pIcons_LOD->GetTexture(uTextureID_Quit1), 0);
+                        pBtn_Resume = pGUIWindow_CurrentMenu->CreateButton(241, 263, 214, 40, 1, 0, UIMSG_GameMenu_ReturnToGame, 0, 0x52u,
+                            pGlobalTXT_LocalizationStrings[619],// "Return to Game"
+                            pIcons_LOD->GetTexture(uTextureID_Resume1), 0);
+                        pGUIWindow_CurrentMenu->_41D08F_set_keyboard_control_group(6, 1, 0, 0);
+                        viewparams->field_48 = 1;
+
+                        stru_506E40.Release();
+                        pRenderer->SaveScreenshot("gamma.pcx", 155, 117);
+                        stru_506E40.LoadPCXFile("gamma.pcx", 0);
+
+                        continue;
+                    }
+                    pGUIWindow_Settings->Release();
+                    pGUIWindow_Settings = 0;
+                    pMouse->SetCursorBitmap("MICON1");
+                    GameUI_Footer_TimeLeft = 0;
+                    _50C9A0_IsEnchantingInProgress = 0;
+                    back_to_game();
+                    continue;
+                }
+                ModalWindow_Release();
+                continue;
+            case UIMSG_ScrollNPCPanel://Right and Left button for NPCPanel
+                if (uMessageParam)
+                {
+                    GUIWindow::Create(626, 179, 0, 0, WINDOW_PressedButton2, (int)pBtn_NPCRight, 0);
+                    v37 = (pParty->pHirelings[0].pName != 0) + (pParty->pHirelings[1].pName != 0) + (unsigned __int8)pParty->field_70A - 2;
+                    if (pParty->hirelingScrollPosition < v37)
+                    {
+                        ++pParty->hirelingScrollPosition;//??? maybe number of the first cell???
+                        if (pParty->hirelingScrollPosition >= v37)
+                            pParty->hirelingScrollPosition = (pParty->pHirelings[0].pName != 0) + (pParty->pHirelings[1].pName != 0) + pParty->field_70A - 2;
+                    }
+                }
+                else
+                {
+                    GUIWindow::Create(469, 179, 0, 0, WINDOW_PressedButton2, (int)pBtn_NPCLeft, 0);
+                    /*if ( pParty->field_709 )
+                    {
+                    --pParty->field_709;
+                    if ( pParty->field_709 < 1 )
+                    pParty->field_709 = 0;
+                    }*/
+                }
+                GameUI_DrawHiredNPCs();
+                continue;
+            case UIMSG_TransitionUI_Confirm:
+                DoThatMessageThing();
+                dword_50CDC8 = 1;
+                sub_42FBDD();
+                PlayHouseSound(uCurrentHouse_Animation, HouseSound_NotEnoughMoney_TrainingSuccessful);
+
+                if (pMovie_Track)
+                    pMediaPlayer->Unload();
+                DialogueEnding();
+                viewparams->bRedrawGameUI = true;
+                if (dword_59117C_teleportx | dword_591178_teleporty | dword_591174_teleportz | dword_591170_teleport_directiony | dword_59116C_teleport_directionx | dword_591168_teleport_speedz)
+                {
+                    if (dword_59117C_teleportx)
+                    {
+                        pParty->vPosition.x = dword_59117C_teleportx;
+                        _5B65A8_npcdata_uflags_or_other = dword_59117C_teleportx;
+                    }
+                    if (dword_591178_teleporty)
+                    {
+                        pParty->vPosition.y = dword_591178_teleporty;
+                        _5B65AC_npcdata_fame_or_other = dword_591178_teleporty;
+                    }
+                    if (dword_591174_teleportz)
+                    {
+                        pParty->vPosition.z = dword_591174_teleportz;
+                        _5B65B0_npcdata_rep_or_other = dword_591174_teleportz;
+                        pParty->uFallStartY = dword_591174_teleportz;
+                    }
+                    if (dword_591170_teleport_directiony)
+                    {
+                        pParty->sRotationY = dword_591170_teleport_directiony;
+                        _5B65B4_npcdata_loword_house_or_other = dword_591170_teleport_directiony;
+                    }
+                    if (dword_59116C_teleport_directionx)
+                    {
+                        pParty->sRotationX = dword_59116C_teleport_directionx;
+                        _5B65B8_npcdata_hiword_house_or_other = dword_59116C_teleport_directionx;
+                        v38 = dword_591168_teleport_speedz;
+                        pParty->uFallSpeed = dword_591168_teleport_speedz;
+                        dword_5B65BC = dword_591168_teleport_speedz;
+                    }
+                    else
+                        v38 = dword_5B65BC;
+                    if (*dword_591164_teleport_map_name != 48)
+                    {
+                        pGameLoadingUI_ProgressBar->uType = (GUIProgressBar::Type)2;
+                        dword_5B65C0 = _5B65A8_npcdata_uflags_or_other | _5B65AC_npcdata_fame_or_other | _5B65B0_npcdata_rep_or_other | _5B65B4_npcdata_loword_house_or_other | _5B65B8_npcdata_hiword_house_or_other | v38;
+                        OnMapLeave();
+                        Transition_StopSound_Autosave(dword_591164_teleport_map_name, MapStartPoint_Party);
+                    }
+                }
+                else
+                    EventProcessor(dword_5C3418, 0, 1, dword_5C341C);
+                if (!_stricmp(byte_6BE3B0.data(), "d05.blv"))
+                    pParty->uTimePlayed += 1474560i64;
+                continue;
+            case UIMSG_TransitionWindowCloseBtn:
+                CloseWindowBackground();
+                pMediaPlayer->Unload();
+                DialogueEnding();
+                viewparams->bRedrawGameUI = true;
+                continue;
+            case UIMSG_CycleCharacters:
+                v39 = GetAsyncKeyState(VK_SHIFT);
+                uActiveCharacter = CycleCharacter(v39);
+                viewparams->bRedrawGameUI = true;
+                continue;
+            case UIMSG_OnTravelByFoot:
+                DoThatMessageThing();
+                dword_50CDC8 = 1;
+                sub_42FBDD();
+                //pNPCData4 = (NPCData *)GetTravelTime();
+                strcpy(pOutdoor->pLevelFilename, pCurrentMapName);
+                if (bUnderwater != 1 && pParty->bFlying
+                    || pOutdoor->GetTravelDestination(pParty->vPosition.x, pParty->vPosition.y, pOut, 20) != 1)
+                {
+                    viewparams->bRedrawGameUI = 1;
+                    CloseWindowBackground();
+                    if (pParty->vPosition.x < -22528)
+                        pParty->vPosition.x = -22528;
+                    if (pParty->vPosition.x > 22528)
+                        pParty->vPosition.x = 22528;
+                    if (pParty->vPosition.y < -22528)
+                        pParty->vPosition.y = -22528;
+                    if (pParty->vPosition.y > 22528)
+                        pParty->vPosition.y = 22528;
+                    DialogueEnding();
+                    current_screen_type = SCREEN_GAME;
+                }
+                else
+                {
+                    pParty->field_6E4 = 0;
+                    pParty->field_6E0 = 0;
+                    CastSpellInfoHelpers::_427D48();
+                    DialogueEnding();
+                    pEventTimer->Pause();
+                    pGameLoadingUI_ProgressBar->Initialize(GUIProgressBar::TYPE_Box);
+                    ++pGameLoadingUI_ProgressBar->uProgressMax;
+                    SaveGame(1, 0);
+                    pGameLoadingUI_ProgressBar->Progress();
+                    RestAndHeal(1440 * (signed int)GetTravelTime());
+                    if (pParty->uNumFoodRations)
+                    {
+                        pParty->RestAndHeal();
+                        if (((pParty->uNumFoodRations - (signed int)GetTravelTime()) & 0x80000000u) != 0)
+                        {
+                            pPlayer7 = pParty->pPlayers.data();
+                            do
+                            {
+                                pPlayer7->SetCondition(1, 0);
+                                ++pPlayer7;
+                            } while ((signed int)pPlayer7 < (signed int)pParty->pHirelings.data());
+                            ++pParty->days_played_without_rest;
+                        }
+                        Party::TakeFood((unsigned int)GetTravelTime());
+                    }
+                    else
+                    {
+                        pPlayer8 = pParty->pPlayers.data();
+                        do
+                        {
+                            pPlayer8->SetCondition(1, 0);
+                            ++pPlayer8;
+                        } while ((signed int)pPlayer8 < (signed int)pParty->pHirelings.data());
+                        ++pParty->days_played_without_rest;
+                    }
+                    pPaletteManager->ResetNonLocked();
+                    pSpriteFrameTable->ResetSomeSpriteFlags();
+                    strcpy(pCurrentMapName, pOut);
+                    strcpy(pLevelName, pCurrentMapName);
+                    v41 = strtok(pLevelName, ".");
+                    strcpy(pLevelName, v41);
+                    Level_LoadEvtAndStr(pLevelName);
+                    pDecalBuilder->Reset(0);
+                    LoadLevel_InitializeLevelEvt();
+                    uLevelMapStatsID = pMapStats->GetMapInfo(pCurrentMapName);
+                    bUnderwater = 0;
+                    bNoNPCHiring = 0;
+                    pEngine->uFlags2 &= 0xFFFFFFF7u;
+                    if (Is_out15odm_underwater())
+                    {
+                        bUnderwater = 1;
+                        pEngine->uFlags2 |= 8u;
+                    }
+                    if (!_stricmp(pCurrentMapName, "out15.odm") || !_stricmp(pCurrentMapName, "d47.blv"))
+                        bNoNPCHiring = 1;
+                    PrepareToLoadODM(1u, (ODMRenderParams *)1);
+                    pAudioPlayer->SetMapEAX();
+                    bDialogueUI_InitializeActor_NPC_ID = 0;
+                    OnMapLoad();
+                    pOutdoor->SetFog();
+                    TeleportToStartingPoint(uLevel_StartingPointType);
+                    pParty->vPosition.z = GetTerrainHeightsAroundParty2(pParty->vPosition.x, pParty->vPosition.y, &v213, 0);
+                    pParty->uFallStartY = pParty->vPosition.z;
+                    _461103_load_level_sub();
+                    pEventTimer->Resume();
+                    viewparams->bRedrawGameUI = 1;
+                    current_screen_type = SCREEN_GAME;
+                    pGameLoadingUI_ProgressBar->Release();
+                }
+                viewparams->bRedrawGameUI = 1;
+                continue;
+            case UIMSG_CHANGE_LOCATION_ClickCencelBtn:
+                CloseWindowBackground();
+                if (pParty->vPosition.x < -22528)
+                    pParty->vPosition.x = -22528;
+                if (pParty->vPosition.x > 22528)
+                    pParty->vPosition.x = 22528;
+                if (pParty->vPosition.y < -22528)
+                    pParty->vPosition.y = -22528;
+                if (pParty->vPosition.y > 22528)
+                    pParty->vPosition.y = 22528;
+                DialogueEnding();
+                current_screen_type = SCREEN_GAME;
+                viewparams->bRedrawGameUI = 1;
+                continue;
+            case UIMSG_CastSpell_Telekinesis:
+                //if ( pRenderer->pRenderD3D )
+                LOWORD(v42) = pEngine->pVisInstance->get_picked_object_zbuf_val();
+                /*else
+                {
+                uNumSeconds = (unsigned int)pMouse->GetCursorPos(&v210);
+                pPoint = pMouse->GetCursorPos(&v208);
+                v42 = pRenderer->pActiveZBuffer[*(int *)uNumSeconds + pSRZBufferLineOffsets[pPoint->y]];
+                }*/
+                v44 = (unsigned __int16)v42;
+                v45 = PID_TYPE(v44);
+                uNumSeconds = v44;
+                v46 = PID_ID(v44);
+                if (v45 == 3)
+                {
+                    v47 = pActors[v46].uAIState == Dead;
+                    if (!v47)
+                        continue;
+                    pSpellInfo = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
+                    pSpellInfo->uFlags &= ~0x40u;
+                    pSpellInfo->uPlayerID_2 = uMessageParam;
+                    pSpellInfo->spell_target_pid = v44;
+                    pParty->pPlayers[pSpellInfo->uPlayerID].SetRecoveryTime(300);
+                    pGUIWindow_Settings->Release();
+                    pGUIWindow_Settings = 0;
+                    pMouse->SetCursorBitmap("MICON1");
+                    GameUI_Footer_TimeLeft = 0;
+                    _50C9A0_IsEnchantingInProgress = 0;
+                    back_to_game();
+                    continue;
+                }
+                if (v45 == 2)
+                {
+                    v47 = (pObjectList->pObjects[pSpriteObjects[v46].uObjectDescID].uFlags & 0x10) == 0;
+                    if (!v47)
+                        continue;
+                    pSpellInfo = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
+                    pSpellInfo->uFlags &= ~0x40u;
+                    pSpellInfo->uPlayerID_2 = uMessageParam;
+                    pSpellInfo->spell_target_pid = v44;
+                    pParty->pPlayers[pSpellInfo->uPlayerID].SetRecoveryTime(300);
+                    pGUIWindow_Settings->Release();
+                    pGUIWindow_Settings = 0;
+                    pMouse->SetCursorBitmap("MICON1");
+                    GameUI_Footer_TimeLeft = 0;
+                    _50C9A0_IsEnchantingInProgress = 0;
+                    back_to_game();
+                    continue;
+                }
+                if (v45 == 5)
+                {
+                    v48 = pLevelDecorations[v46].uEventID == 0;
+                }
+                else
+                {
+                    if (v45 != 6)
+                        continue;
+                    if (uCurrentlyLoadedLevelType != 1)
+                    {
+                        pODMFace = &pOutdoor->pBModels[v44 >> 9].pFaces[v46 & 0x3F];
+                        if (!pODMFace->Clickable() || !pODMFace->sCogTriggeredID)
+                            continue;
+                        v44 = uNumSeconds;
+                        pSpellInfo = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
+                        pSpellInfo->uFlags &= ~0x40u;
+                        pSpellInfo->uPlayerID_2 = uMessageParam;
+                        pSpellInfo->spell_target_pid = v44;
+                        pParty->pPlayers[pSpellInfo->uPlayerID].SetRecoveryTime(300);
+                        pGUIWindow_Settings->Release();
+                        pGUIWindow_Settings = 0;
+                        pMouse->SetCursorBitmap("MICON1");
+                        GameUI_Footer_TimeLeft = 0;
+                        _50C9A0_IsEnchantingInProgress = 0;
+                        back_to_game();
+                        continue;
+                    }
+                    pBLVFace = &pIndoor->pFaces[v46];
+                    if (!pBLVFace->Clickable())
+                        continue;
+                    v48 = pIndoor->pFaceExtras[pBLVFace->uFaceExtraID].uEventID == 0;
+                }
+                if (v48)
+                    continue;
+                pSpellInfo = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
+                pSpellInfo->uFlags &= ~0x40u;
+                pSpellInfo->uPlayerID_2 = uMessageParam;
+                pSpellInfo->spell_target_pid = v44;
+                pParty->pPlayers[pSpellInfo->uPlayerID].SetRecoveryTime(300);
+                pGUIWindow_Settings->Release();
+                pGUIWindow_Settings = 0;
+                pMouse->SetCursorBitmap("MICON1");
+                GameUI_Footer_TimeLeft = 0;
+                _50C9A0_IsEnchantingInProgress = 0;
+                back_to_game();
+                continue;
+            case UIMSG_CastSpell_Character_Big_Improvement://Preservation and blessing, treatment paralysis, hand hammers(individual upgrade)
+            case UIMSG_CastSpell_Character_Small_Improvement://Fate, cure
+            case UIMSG_HiredNPC_CastSpell:
+                DoThatMessageThing();
+                if (_50C9A0_IsEnchantingInProgress)
+                {
+                    uActiveCharacter = uMessageParam;
+                    viewparams->bRedrawGameUI = 1;
+                }
+                else
+                {
+                    if (pGUIWindow_Settings)
+                    {
+                        pSpellInfo = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
+                        switch (uMessage)
+                        {
+                        case UIMSG_CastSpell_Character_Big_Improvement:
+                            pSpellInfo->uFlags &= ~0x02u;
+                            break;
+                        case UIMSG_CastSpell_Character_Small_Improvement:
+                            pSpellInfo->uFlags &= ~0x0100u;
+                            break;
+                        case UIMSG_HiredNPC_CastSpell:
+                            pSpellInfo->uFlags &= ~0x0200u;
+                            break;
+                        }
+                        pSpellInfo->uPlayerID_2 = uMessageParam;
+                        pParty->pPlayers[pSpellInfo->uPlayerID].SetRecoveryTime(300);
+                        pGUIWindow_Settings->Release();
+                        pGUIWindow_Settings = 0;
+                        pEventTimer->Resume();
+                        pMouse->SetCursorBitmap("MICON1");
+                        GameUI_Footer_TimeLeft = 0;
+                        _50C9A0_IsEnchantingInProgress = 0;
+                    }
+                }
+                continue;
+            case UIMSG_BF:
+                __debugbreak();
+                dword_50CDC8 = 1;
+                sub_42FBDD();
+                SaveGame(1, 0);
+                strcpy(pCurrentMapName, pMapStats->pInfos[uHouse_ExitPic].pFilename);
+                dword_6BE364_game_settings_1 |= GAME_SETTINGS_0001;
+                uGameState = GAME_STATE_CHANGE_LOCATION;
+                //v53 = p2DEvents_minus1_::30[26 * (unsigned int)ptr_507BC0->ptr_1C];
+                v53 = p2DEvents[(unsigned int)window_SpeakInHouse->ptr_1C - 1]._quest_related;
+                if (v53 < 0)
+                {
+                    v54 = abs(v53) - 1;
+                    _5B65B8_npcdata_hiword_house_or_other = 0;
+                    dword_5B65BC = 0;
+                    v55 = dword_4E4560[v54];
+                    _5B65AC_npcdata_fame_or_other = dword_4E4578[v54];
+                    v56 = dword_4E4590[v54];
+                    v57 = dword_4E45A8[v54];
+                    _5B65A8_npcdata_uflags_or_other = v55;
+                    _5B65B4_npcdata_loword_house_or_other = v57;
+                    _5B65B0_npcdata_rep_or_other = v56;
+                    dword_5B65C0 = v55 | _5B65AC_npcdata_fame_or_other | v56 | v57;
+                }
+                HouseDialogPressCloseBtn();
+                //goto LABEL_434;
+                /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+                {
+                pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape;
+                pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v0;
+                *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
+                ++pMessageQueue_50CBD0->uNumMessages;
+                }*/
+                pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Escape, 1, 0);
+                continue;
+
+            case UIMSG_OnCastTownPortal:
+                pAudioPlayer->StopChannels(-1, -1);
+                pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Book, WINDOW_TownPortal, (char *)uMessageParam);
+                continue;
+
+            case UIMSG_OnCastLloydsBeacon:
+                pAudioPlayer->StopChannels(-1, -1);
+                pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Book, WINDOW_LloydsBeacon, 0);
+                continue;
+
+            case UIMSG_LloydsBeacon_FlippingBtn:
+                bRecallingBeacon = uMessageParam;
+                v127 = uMessageParam + 204;
+                pAudioPlayer->PlaySound((SoundID)v127, 0, 0, -1, 0, 0, 0, 0);
+                continue;
+            case UIMSG_HintBeaconSlot:
+                if (!pGUIWindow_CurrentMenu)
+                    continue;
+                pPlayer = pPlayers[_506348_current_lloyd_playerid + 1];
+                uNumSeconds = (unsigned int)&pPlayer->pInstalledBeacons[uMessageParam];
+                if (bRecallingBeacon)
+                {
+                    if (!*((int *)&pSavegameThumbnails[10 * uMessageParam].pPixels))
+                        continue;
+                    v173 = pMapStats->pInfos[pMapStats->sub_410D99_get_map_index(pPlayer->pInstalledBeacons[uMessageParam].SaveFileID)].pName;
+                    sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[474], v173);// "Recall to %s"
+                    GameUI_SetFooterString(pTmpBuf.data());
+                    continue;
+                }
+                pMapNum = pMapStats->GetMapInfo(pCurrentMapName);
+                pMapName = "Not in Map Stats";
+                if (pMapNum)
+                    pMapName = pMapStats->pInfos[pMapNum].pName;
+                if (!*((int *)&pSavegameThumbnails[10 * uMessageParam].pPixels) || !pMapNum)
+                {
+                    sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[476], pMapName);// "Set to %s"
+                    GameUI_SetFooterString(pTmpBuf.data());
+                    continue;
+                }
+                v174 = pMapStats->pInfos[pMapStats->sub_410D99_get_map_index(*(short *)(uNumSeconds + 26))].pName;
+                sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[475], (unsigned int)pMapName, v174);// "Set %s over %s"
+                GameUI_SetFooterString(pTmpBuf.data());
+                continue;
+            case UIMSG_CloseAfterInstallBeacon:
+                dword_50CDC8 = 1;
+                pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Escape, 0, 0);
+                /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
+                continue;
+                pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape;
+                pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
+                *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
+                ++pMessageQueue_50CBD0->uNumMessages;*/
+                continue;
+            case UIMSG_InstallBeacon:
+                pPlayer9 = pPlayers[_506348_current_lloyd_playerid + 1];
+                if (!pPlayer9->pInstalledBeacons[uMessageParam].uBeaconTime && bRecallingBeacon)
+                    continue;
+                byte_506360 = 1;
+                pPlayer9->CanCastSpell(uRequiredMana);
+                if (pParty->bTurnBasedModeOn)
+                {
+                    v60 = sRecoveryTime;
+                    pParty->pTurnBasedPlayerRecoveryTimes[_506348_current_lloyd_playerid] = sRecoveryTime;
+                    pPlayer9->SetRecoveryTime(v60);
+                    pTurnEngine->ApplyPlayerAction();
+                }
+                else
+                {
+                    pPlayer9->SetRecoveryTime((signed __int64)(flt_6BE3A4_debug_recmod1 * (double)sRecoveryTime * 2.133333333333333));
+                }
+                pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[lloyds_beacon_spell_id], 0, 0, -1, 0, lloyds_beacon_sound_id, 0, 0);
+                if (bRecallingBeacon)
+                {
+                    if (_stricmp(pCurrentMapName, (const char *)&pGames_LOD->pSubIndices[pPlayer9->pInstalledBeacons[uMessageParam].SaveFileID]))
+                    {
+                        SaveGame(1, 0);
+                        OnMapLeave();
+                        strcpy(pCurrentMapName, (const char *)&pGames_LOD->pSubIndices[pPlayer9->pInstalledBeacons[uMessageParam].SaveFileID]);
+                        dword_6BE364_game_settings_1 |= GAME_SETTINGS_0001;
+                        uGameState = GAME_STATE_CHANGE_LOCATION;
+                        _5B65A8_npcdata_uflags_or_other = pPlayer9->pInstalledBeacons[uMessageParam].PartyPos_X;
+                        _5B65AC_npcdata_fame_or_other = pPlayer9->pInstalledBeacons[uMessageParam].PartyPos_Y;
+                        _5B65B0_npcdata_rep_or_other = pPlayer9->pInstalledBeacons[uMessageParam].PartyPos_Z;
+                        _5B65B4_npcdata_loword_house_or_other = pPlayer9->pInstalledBeacons[uMessageParam].PartyRot_X;
+                        _5B65B8_npcdata_hiword_house_or_other = pPlayer9->pInstalledBeacons[uMessageParam].PartyRot_Y;
+                        dword_5B65C0 = 1;
+                    }
+                    else
+                    {
+                        pParty->vPosition.x = pPlayer9->pInstalledBeacons[uMessageParam].PartyPos_X;
+                        pParty->vPosition.y = pPlayer9->pInstalledBeacons[uMessageParam].PartyPos_Y;
+                        pParty->vPosition.z = pPlayer9->pInstalledBeacons[uMessageParam].PartyPos_Z;
+                        pParty->uFallStartY = pParty->vPosition.z;
+                        pParty->sRotationY = pPlayer9->pInstalledBeacons[uMessageParam].PartyRot_X;
+                        pParty->sRotationX = pPlayer9->pInstalledBeacons[uMessageParam].PartyRot_Y;
+                    }
+                    pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Escape, 1, 0);
+                    pBooksWindow->Release();
+                    pGUIWindow_CurrentMenu->Release();
+                    pBooksWindow = 0;
+                    pGUIWindow_CurrentMenu = 0;
+                }
+                else
+                {
+                    sprintf(a1, "data\\lloyd%d%d.pcx", _506348_current_lloyd_playerid + 1, uMessageParam + 1);
+                    pRenderer->SaveScreenshot(a1, 92, 68);
+                    LoadThumbnailLloydTexture(uMessageParam, _506348_current_lloyd_playerid + 1);
+                    pPlayer9->pInstalledBeacons[uMessageParam].uBeaconTime = pParty->uTimePlayed + (signed __int64)((double)(lloyds_beacon_spell_level << 7) * 0.033333335);
+                    pPlayer9->pInstalledBeacons[uMessageParam].PartyPos_X = pParty->vPosition.x;
+                    pPlayer9->pInstalledBeacons[uMessageParam].PartyPos_Y = pParty->vPosition.y;
+                    pPlayer9->pInstalledBeacons[uMessageParam].PartyPos_Z = pParty->vPosition.z;
+                    pPlayer9->pInstalledBeacons[uMessageParam].PartyRot_X = LOWORD(pParty->sRotationY);
+                    pPlayer9->pInstalledBeacons[uMessageParam].PartyRot_Y = LOWORD(pParty->sRotationX);
+                    if ((signed int)pGames_LOD->uNumSubDirs / 2 <= 0)
+                        continue;
+                    for (thisg = 0; thisg < (signed int)pGames_LOD->uNumSubDirs / 2; ++thisg)
+                    {
+                        if (!_stricmp(pGames_LOD->pSubIndices[thisg].pFilename, pCurrentMapName))
+                            pPlayer9->pInstalledBeacons[uMessageParam].SaveFileID = thisg;
+                    }
+                }
+                continue;
+            case UIMSG_ClickTownInTP:
+                if (uMessageParam)
+                {
+                    switch (uMessageParam)
+                    {
+                    case 1:
+                        v63 = 208;
+                        break;
+                    case 2:
+                        v63 = 207;
+                        break;
+                    case 3:
+                        v63 = 211;
+                        break;
+                    case 4:
+                        v63 = 209;
+                        break;
+                    default:
+                        if (uMessageParam != 5)
+                        {
+                        LABEL_486:
+                            SaveGame(1, 0);
+                            v64 = pMapStats->GetMapInfo(pCurrentMapName);
+                            v65 = uMessageParam;
+                            if (v64 == TownPortalList[uMessageParam].uMapInfoID)
+                            {
+                                pParty->vPosition.x = TownPortalList[v65].pos.x;
+                                pParty->vPosition.y = TownPortalList[v65].pos.y;
+                                pParty->vPosition.z = TownPortalList[v65].pos.z;
+                                pParty->uFallStartY = pParty->vPosition.z;
+                                pParty->sRotationY = TownPortalList[v65].rot_y;
+                                pParty->sRotationX = TownPortalList[v65].rot_x;
+                            }
+                            else
+                            {
+                                SaveGame(1, 0);
+                                OnMapLeave();
+                                dword_6BE364_game_settings_1 |= GAME_SETTINGS_0001;
+                                uGameState = GAME_STATE_CHANGE_LOCATION;
+                                strcpy(pCurrentMapName, pMapStats->pInfos[TownPortalList[uMessageParam].uMapInfoID].pFilename);
+                                dword_5B65C0 = 1;
+                                _5B65A8_npcdata_uflags_or_other = TownPortalList[uMessageParam].pos.x;
+                                _5B65AC_npcdata_fame_or_other = TownPortalList[uMessageParam].pos.y;
+                                _5B65B0_npcdata_rep_or_other = TownPortalList[uMessageParam].pos.z;
+                                v66 = TownPortalList[uMessageParam].rot_x;
+                                _5B65B4_npcdata_loword_house_or_other = TownPortalList[uMessageParam].rot_y;
+                                _5B65B8_npcdata_hiword_house_or_other = v66;
+                                Actor::InitializeActors();
+                            }
+                            v67 = (char*)pGUIWindow_CurrentMenu->Hint;
+                            if (v67)
+                                *((int *)v67 + 17) = 1;
+                            else
+                                pParty->pPlayers[(unsigned __int8)town_portal_caster_id].CanCastSpell(0x14u);
+                            /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+                            {
+                            pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape;
+                            pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = v0;
+                            *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
+                            ++pMessageQueue_50CBD0->uNumMessages;
+                            }*/
+                            pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Escape, 1, 0);
+                            continue;
+                        }
+                        v63 = 210;
+                        break;
+                    }
+                }
+                else
+                {
+                    v63 = 206;
+                }
+                if (!(unsigned __int16)_449B57_test_bit(pParty->_quest_bits, v63))
+                    return;
+                goto LABEL_486;
+            case UIMSG_HintTownPortal:
+                if (uMessageParam)
+                {
+                    switch (uMessageParam)
+                    {
+                    case 1:
+                        v68 = 208;
+                        break;
+                    case 2:
+                        v68 = 207;
+                        break;
+                    case 3:
+                        v68 = 211;
+                        break;
+                    case 4:
+                        v68 = 209;
+                        break;
+                    default:
+                        if (uMessageParam != 5)
+                            //goto LABEL_506;
+                        {
+                            if (uMessageParam)
+                            {
+                                switch (uMessageParam)
+                                {
+                                case 1:
+                                    v69 = pMapStats->pInfos[4].pName;
+                                    break;
+                                case 2:
+                                    v69 = pMapStats->pInfos[3].pName;
+                                    break;
+                                case 3:
+                                    v69 = pMapStats->pInfos[10].pName;
+                                    break;
+                                case 4:
+                                    v69 = pMapStats->pInfos[7].pName;
+                                    break;
+                                default:
+                                    if (uMessageParam != 5)
+                                    {
+                                        __debugbreak(); // warning C4700: uninitialized local variable 'v200' used
+                                        sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[35], v200);
+                                        GameUI_SetFooterString(pTmpBuf.data());
+                                        continue;
+                                    }
+                                    v69 = pMapStats->pInfos[8].pName;
+                                    break;
+                                }
+                            }
+                            else
+                            {
+                                v69 = pMapStats->pInfos[21].pName;
+                            }
+                            sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[35], v69);
+                            GameUI_SetFooterString(pTmpBuf.data());
+                            continue;
+                        }
+                        v68 = 210;
+                        break;
+                    }
+                }
+                else
+                {
+                    v68 = 206;
+                }
+                if (!(unsigned __int16)_449B57_test_bit(pParty->_quest_bits, v68))
+                {
+                    pRenderer->DrawTextureRGB(0, 0x160u, pTexture_StatusBar);
+                    continue;
+                }
+                //LABEL_506:
+                if (uMessageParam)
+                {
+                    switch (uMessageParam)
+                    {
+                    case 1:
+                        v69 = pMapStats->pInfos[4].pName;
+                        break;
+                    case 2:
+                        v69 = pMapStats->pInfos[3].pName;
+                        break;
+                    case 3:
+                        v69 = pMapStats->pInfos[10].pName;
+                        break;
+                    case 4:
+                        v69 = pMapStats->pInfos[7].pName;
+                        break;
+                    default:
+                        if (uMessageParam != 5)
+                            //goto LABEL_519;
+                        {
+                            sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[35], v200);
+                            GameUI_SetFooterString(pTmpBuf.data());
+                            continue;
+                        }
+                        v69 = pMapStats->pInfos[8].pName;
+                        break;
+                    }
+                }
+                else
+                {
+                    v69 = pMapStats->pInfos[21].pName;
+                }
+                sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[35], v69);
+                GameUI_SetFooterString(pTmpBuf.data());
+                continue;
+            case UIMSG_ShowFinalWindow:
+                sprintfex(pFinalMessage.data(), "%s\n \n%s\n \n%s", pGlobalTXT_LocalizationStrings[151],// "Congratulations Adventurer."
+                    pGlobalTXT_LocalizationStrings[118],// "We hope that you've enjoyed playing Might and Magic VII as much as we did making it. We have saved this screen as MM7_WIN.PCX in your MM7 directory. You can print it out as proof of your accomplishment."
+                    pGlobalTXT_LocalizationStrings[167]);// "- The Might and Magic VII Development Team."   
+                ModalWindow(pFinalMessage.data(), UIMSG_OnFinalWindowClose);
+                uGameState = GAME_STATE_FINAL_WINDOW;
+                continue;
+            case UIMSG_OnFinalWindowClose:
+                __debugbreak();
+                uGameState = GAME_STATE_PLAYING;
+                strcpy((char *)pKeyActionMap->pPressedKeysBuffer, "2");
+                __debugbreak(); // missed break/continue?
+            case UIMSG_DD:
+                __debugbreak();
+                sprintf(pTmpBuf.data(), "%s", pKeyActionMap->pPressedKeysBuffer);
+                memcpy(&v216, txt_file_frametable_parser(pKeyActionMap->pPressedKeysBuffer, &v218), sizeof(v216));
+                if (v216.uPropCount == 1)
+                {
+                    pNPCData4 = (NPCData *)((signed int)pGames_LOD->uNumSubDirs / 2);
+                    v70 = atoi(v216.pProperties[0]);
+                    if (v70 <= 0 || v70 >= 77)
+                        continue;
+                    v71 = v70;
+                    strcpy(Str2, pMapStats->pInfos[v70].pFilename);
+                    pNPCData3 = 0;
+                    if ((signed int)pNPCData4 > 0)
+                    {
+                        thish = 0;
+                        do
+                        {
+                            if (!_stricmp(pGames_LOD->pSubIndices[thish].pFilename, Str2))
+                                break;
+                            ++thish;
+                            pNPCData3 = (NPCData *)((char *)pNPCData3 + 1);
+                        } while ((signed int)pNPCData3 < (signed int)pNPCData4);
+                        if ((signed int)pNPCData3 < (signed int)pNPCData4)
+                        {
+                            strcpy(pCurrentMapName, pGames_LOD->pSubIndices[(int)pNPCData3].pFilename);
+                            dword_6BE364_game_settings_1 |= GAME_SETTINGS_0001;
+                            uGameState = GAME_STATE_CHANGE_LOCATION;
+                            OnMapLeave();
+                            continue;
+                        }
+                    }
+                    sprintf(Str2, "No map found for %s", pMapStats->pInfos[v71].pName);
+                    v73 = Str2;
+                }
+                else
+                {
+                    if (v216.uPropCount != 3)
+                        continue;
+                    v74 = atoi(v216.pProperties[0]);
+                    thisi = atoi(v216.pProperties[1]);
+                    v75 = atoi(v216.pProperties[2]);
+                    v76 = v75;
+                    if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
+                    {
+                        if (pIndoor->GetSector(v74, thisi, v75))
+                        {
+                            v77 = thisi;
+                            pParty->vPosition.x = v74;
+                            pParty->vPosition.y = v77;
+                            pParty->vPosition.z = v76;
+                            pParty->uFallStartY = v76;
+                            continue;
+                        }
+                    }
+                    else
+                    {
+                        if (v74 > -32768)
+                        {
+                            if (v74 < 32768)
+                            {
+                                v77 = thisi;
+                                if (thisi > -32768)
+                                {
+                                    if (thisi < 32768 && v76 >= 0 && v76 < 10000)
+                                    {
+                                        pParty->vPosition.x = v74;
+                                        pParty->vPosition.y = v77;
+                                        pParty->vPosition.z = v76;
+                                        pParty->uFallStartY = v76;
+                                        continue;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                    pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);
+                    v73 = "Can't jump to that location!";
+                }
+                ShowStatusBarString(v73, 6);
+                continue;
+            case UIMSG_CastQuickSpell:
+                if (bUnderwater == 1)
+                {
+                    ShowStatusBarString(pGlobalTXT_LocalizationStrings[652], 2);// "You can not do that while you are underwater!"
+                    pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);
+                    continue;
+                }
+                if (!uActiveCharacter || (pPlayer2 = pPlayers[uActiveCharacter], pPlayer2->uTimeToRecovery))
+                    continue;
+                _42777D_CastSpell_UseWand_ShootArrow(pPlayer2->uQuickSpell, uActiveCharacter - 1, 0, 0, uActiveCharacter);
+                continue;
+            case UIMSG_CastSpell_Monster_Improvement:
+            case UIMSG_CastSpell_Shoot_Monster://FireBlow, Lightning, Ice Lightning, Swarm, 
+                //if ( pRenderer->pRenderD3D )
+            {
+                v81 = pEngine->pVisInstance->get_picked_object_zbuf_val();
+            }
+                /*else
+                {
+                uNumSeconds = (unsigned int)pMouse->GetCursorPos(&v206);
+                pPoint2 = pMouse->GetCursorPos(&v201);
+                v81 = pRenderer->pActiveZBuffer[*(int *)uNumSeconds + pSRZBufferLineOffsets[pPoint2->y]];
+                }*/
+                v83 = v81;
+                v44 = (unsigned __int16)v81;
+                v84 = v83 >> 16;
+                if (PID_TYPE(v44) != 3 || v84 >= 5120)
+                    continue;
+                pSpellInfo = (CastSpellInfo *)pGUIWindow_Settings->ptr_1C;
+                if (uMessage == UIMSG_CastSpell_Shoot_Monster)
+                {
+                    pSpellInfo->uFlags &= ~0x08;
+                }
+                else
+                {
+                    if (uMessage == UIMSG_CastSpell_Monster_Improvement)
+                        pSpellInfo->uFlags &= ~0x0100u;
+                    else
+                        pSpellInfo->uFlags &= ~0x0200u;
+                }
+                pSpellInfo->uPlayerID_2 = uMessageParam;
+                pSpellInfo->spell_target_pid = v44;
+                pParty->pPlayers[pSpellInfo->uPlayerID].SetRecoveryTime(300);
+                pGUIWindow_Settings->Release();
+                pGUIWindow_Settings = 0;
+                pMouse->SetCursorBitmap("MICON1");
+                GameUI_Footer_TimeLeft = 0;
+                _50C9A0_IsEnchantingInProgress = 0;
+                back_to_game();
+                continue;
+            case UIMSG_1C:
+                __debugbreak();
+                if (!uActiveCharacter || current_screen_type)
+                    continue;
+                ptr_507BC8 = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_68, uMessageParam, 0);
+                current_screen_type = SCREEN_19;
+                pEventTimer->Pause();
+                continue;
+            case UIMSG_STEALFROMACTOR:
+                if (!uActiveCharacter)
+                    continue;
+                if (pParty->bTurnBasedModeOn != 1)
+                {
+                    if (pActors[uMessageParam].uAIState == 5)
+                        pActors[uMessageParam].LootActor();
+                    else
+                        Actor::StealFrom(uMessageParam);
+                    continue;
+                }
+                if (pTurnEngine->turn_stage == TE_WAIT || pTurnEngine->turn_stage == TE_MOVEMENT)
+                    continue;
+                if (!(pTurnEngine->field_18 & TE_HAVE_PENDING_ACTIONS))
+                {
+                    if (pActors[uMessageParam].uAIState == 5)
+                        pActors[uMessageParam].LootActor();
+                    else
+                        Actor::StealFrom(uMessageParam);
+                }
+                continue;
+
+            case UIMSG_Attack:
+                if (!uActiveCharacter)
+                    continue;
+                if (pParty->bTurnBasedModeOn != 1)
+                {
+                    Player::_42ECB5_PlayerAttacksActor();
+                    continue;
+                }
+                if (pTurnEngine->turn_stage == TE_WAIT || pTurnEngine->turn_stage == TE_MOVEMENT)
+                    continue;
+                if (!(pTurnEngine->field_18 & TE_HAVE_PENDING_ACTIONS))
+                    Player::_42ECB5_PlayerAttacksActor();
+                continue;
+            case UIMSG_ExitRest:
+                GUIWindow::Create(pButton_RestUI_Exit->uX, pButton_RestUI_Exit->uY, 0, 0, WINDOW_CloseRestWindowBtn, (int)pButton_RestUI_Exit, pGlobalTXT_LocalizationStrings[81]);// "Exit Rest"
+                continue;
+            case UIMSG_Wait5Minutes:
+                if (dword_506F14 == 2)
+                {
+                    ShowStatusBarString(pGlobalTXT_LocalizationStrings[477], 2);// "You are already resting!"
+                    pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);
+                    continue;
+                }
+                GUIWindow::Create(pButton_RestUI_Wait5Minutes->uX, pButton_RestUI_Wait5Minutes->uY, 0, 0, WINDOW_PressedButton2,
+                    (int)pButton_RestUI_Wait5Minutes, pGlobalTXT_LocalizationStrings[238]);// "Wait 5 Minutes"
+                dword_506F14 = 1;
+                _506F18_num_minutes_to_sleep = 5;
+                continue;
+            case UIMSG_Wait1Hour:
+                if (dword_506F14 == 2)
+                {
+                    ShowStatusBarString(pGlobalTXT_LocalizationStrings[477], 2);// "You are already resting!"
+                    pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);
+                    continue;
+                }
+                GUIWindow::Create(pButton_RestUI_Wait1Hour->uX, pButton_RestUI_Wait1Hour->uY, 0, 0, WINDOW_PressedButton2,
+                    (int)pButton_RestUI_Wait1Hour, pGlobalTXT_LocalizationStrings[239]);// "Wait 1 Hour"
+                dword_506F14 = 1;
+                _506F18_num_minutes_to_sleep = 60;
+                continue;
+            case UIMSG_RentRoom:
+                dword_506F14 = 2;
+                RestUI_Load();
+                v86 = 60 * (_494820_training_time(pParty->uCurrentHour) + 1) - pParty->uCurrentMinute;
+                _506F18_num_minutes_to_sleep = v86;
+                if (uMessageParam == 111 || uMessageParam == 114 || uMessageParam == 116) // 107 = Emerald Isle tavern
+                    _506F18_num_minutes_to_sleep = v86 + 12 * 60;
+                dword_506F14 = 2;
+                pParty->RestAndHeal();
+                pParty->days_played_without_rest = 0;
+                pParty->pPlayers[3].SetAsleep(1);
+                pParty->pPlayers[2].SetAsleep(1);
+                pParty->pPlayers[1].SetAsleep(1);
+                pParty->pPlayers[0].SetAsleep(1);
+                continue;
+            case UIMSG_RestWindow:
+                DoThatMessageThing();
+                if (current_screen_type)
+                    continue;
+                if (CheckActors_proximity())
+                {
+                    if (pParty->bTurnBasedModeOn == 1)
+                    {
+                        ShowStatusBarString(pGlobalTXT_LocalizationStrings[478], 2);// "You can't rest in turn-based mode!"
+                        continue;
+                    }
+                    v88 = pGlobalTXT_LocalizationStrings[480];// "There are hostile enemies near!"
+                    if (pParty->uFlags & 0x88)
+                        v88 = pGlobalTXT_LocalizationStrings[479];// "You can't rest here!"
+                    ShowStatusBarString(v88, 2);
+                    if (!uActiveCharacter)
+                        continue;
+                    pPlayers[uActiveCharacter]->PlaySound((PlayerSpeech)13, 0);
+                    continue;
+                }
+                if (pParty->bTurnBasedModeOn == 1)
+                {
+                    ShowStatusBarString(pGlobalTXT_LocalizationStrings[478], 2);// "You can't rest in turn-based mode!"
+                    continue;
+                }
+                if (!(pParty->uFlags & 0x88))
+                {
+                    RestUI_Load();
+                    continue;
+                }
+                if (pParty->bTurnBasedModeOn == 1)
+                {
+                    ShowStatusBarString(pGlobalTXT_LocalizationStrings[478], 2);// "You can't rest in turn-based mode!"
+                    continue;
+                }
+                v88 = pGlobalTXT_LocalizationStrings[480];// "There are hostile enemies near!"
+                if (pParty->uFlags & 0x88)
+                    v88 = pGlobalTXT_LocalizationStrings[479];// "You can't rest here!"
+                ShowStatusBarString(v88, 2u);
+                if (!uActiveCharacter)
+                    continue;
+                pPlayers[uActiveCharacter]->PlaySound((PlayerSpeech)13, 0);
+                continue;
+            case UIMSG_Rest8Hour:
+                if (dword_506F14)
+                {
+                    ShowStatusBarString(pGlobalTXT_LocalizationStrings[477], 2);// "You are already resting!"
+                    pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);
+                    continue;
+                }
+                if (pParty->uNumFoodRations < uRestUI_FoodRequiredToRest)
+                {
+                    ShowStatusBarString(pGlobalTXT_LocalizationStrings[482], 2u);// "You don't have enough food to rest"
+                    if (uActiveCharacter && pPlayers[uActiveCharacter]->CanAct())
+                        pPlayers[uActiveCharacter]->PlaySound((PlayerSpeech)SPEECH_108, 0);
+                }
+                else
+                {
+                    pParty->pPlayers[3].pConditions[Condition_Sleep] = pParty->uTimePlayed;
+                    pParty->pPlayers[2].pConditions[Condition_Sleep] = pParty->uTimePlayed;
+                    pParty->pPlayers[1].pConditions[Condition_Sleep] = pParty->uTimePlayed;
+                    pParty->pPlayers[0].pConditions[Condition_Sleep] = pParty->uTimePlayed;
+                    v90 = pMapStats->GetMapInfo(pCurrentMapName);
+                    if (!v90)
+                        v90 = rand() % (signed int)pMapStats->uNumMaps + 1;
+                    pMapInfo = &pMapStats->pInfos[v90];
+                    if (rand() % 100 + 1 <= pMapInfo->Encounter_percent)
+                    {
+                        v91 = rand() % 100;
+                        v92 = pMapInfo->EncM1percent;
+                        v93 = v91 + 1;
+                        if (v93 > v92)
+                            pNPCData4 = (NPCData *)((v93 > v92 + pMapInfo->EncM2percent) + 2);
+                        else
+                            pNPCData4 = (NPCData *)1;
+                        if (!_45063B_spawn_some_monster(pMapInfo, (int)pNPCData4))
+                            pNPCData4 = 0;
+                        if (pNPCData4)
+                        {
+                            pPlayerNum = rand() % 4;
+                            pParty->pPlayers[pPlayerNum].pConditions[Condition_Sleep] = 0;
+                            v95 = rand();
+                            Rest(v95 % 6 + 60);
+                            _506F18_num_minutes_to_sleep = 0;
+                            dword_506F14 = 0;
+                            /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+                            {
+                            pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape;
+                            pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
+                            *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
+                            ++pMessageQueue_50CBD0->uNumMessages;
+                            }*/
+                            pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Escape, 0, 0);
+                            ShowStatusBarString(pGlobalTXT_LocalizationStrings[481], 2);// "Encounter!"
+                            pAudioPlayer->PlaySound(SOUND_encounter, 0, 0, -1, 0, 0, 0, 0);
+                            continue;
+                        }
+                    }
+                    Party::TakeFood(uRestUI_FoodRequiredToRest);
+                    _506F18_num_minutes_to_sleep = 480;
+                    dword_506F14 = 2;
+                    pParty->RestAndHeal();
+                    pParty->days_played_without_rest = 0;
+                    pParty->pPlayers[3].SetAsleep(1);
+                    pParty->pPlayers[2].SetAsleep(1);
+                    pParty->pPlayers[1].SetAsleep(1);
+                    pParty->pPlayers[0].SetAsleep(1);
+                }
+                continue;
+            case UIMSG_AlreadyResting:
+                if (dword_506F14 == 2)
+                {
+                    ShowStatusBarString(pGlobalTXT_LocalizationStrings[477], 2);// "You are already resting!"
+                    pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);
+                    continue;
+                }
+                GUIWindow::Create(pButton_RestUI_WaitUntilDawn->uX, pButton_RestUI_WaitUntilDawn->uY, 0, 0, WINDOW_PressedButton2,
+                    (int)pButton_RestUI_WaitUntilDawn, pGlobalTXT_LocalizationStrings[237]);// "Wait until Dawn"
+                v97 = _494820_training_time(pParty->uCurrentHour);
+                dword_506F14 = 1;
+                _506F18_num_minutes_to_sleep = 60 * v97 - pParty->uCurrentMinute;
+                continue;
+            case UIMSG_HintSelectRemoveQuickSpellBtn:
+                if (quick_spell_at_page && byte_506550)
+                {
+                    v173 = pSpellStats->pInfos[quick_spell_at_page + 11 * pPlayers[uActiveCharacter]->lastOpenedSpellbookPage].pName;
+                    sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[483], v173);
+                }
+                else
+                {
+                    if (pPlayers[uActiveCharacter]->uQuickSpell)
+                        v177 = pGlobalTXT_LocalizationStrings[584];// "Click here to remove your Quick Spell"
+                    else
+                        v177 = pGlobalTXT_LocalizationStrings[484];// "Select a spell then click here to set a QuickSpell"
+                    strcpy(pTmpBuf.data(), v177);
+                }
+                GameUI_SetFooterString(pTmpBuf.data());
+                continue;
+            case UIMSG_SPellbook_ShowHightlightedSpellInfo:
+                if (!uActiveCharacter || (uNumSeconds = (unsigned int)pPlayers[uActiveCharacter],
+                    !*(char *)(uNumSeconds + 11 * *(char *)(uNumSeconds + 6734) + uMessageParam + 402)))
+                    continue;
+                if (sub_4637E0_is_there_popup_onscreen())
+                    dword_507B00_spell_info_to_draw_in_popup = uMessageParam + 1;
+                v98 = *(char *)(uNumSeconds + 6734);
+                if (quick_spell_at_page - 1 == uMessageParam)
+                {
+                    v178 = pSpellStats->pInfos[uMessageParam + 11 * v98 + 1].pName;
+                    v161 = pGlobalTXT_LocalizationStrings[485];
+                }
+                else
+                {
+                    v178 = pSpellStats->pInfos[uMessageParam + 11 * v98 + 1].pName;
+                    v161 = pGlobalTXT_LocalizationStrings[486];
+                }
+                sprintfex(pTmpBuf.data(), v161, v178);
+                GameUI_SetFooterString(pTmpBuf.data());
+                continue;
+            case UIMSG_ClickInstallRemoveQuickSpellBtn:
+                GUIWindow::Create(pBtn_InstallRemoveSpell->uX, pBtn_InstallRemoveSpell->uY, 0, 0, WINDOW_PressedButton2, (int)pBtn_InstallRemoveSpell, 0);
+                if (!uActiveCharacter)
+                    continue;
+                pPlayer10 = pPlayers[uActiveCharacter];
+                if (!byte_506550 || !quick_spell_at_page)
+                {
+                    pPlayer10->uQuickSpell = 0;
+                    quick_spell_at_page = 0;
+                    pAudioPlayer->PlaySound(SOUND_fizzle, 0, 0, -1, 0, 0, 0, 0);
+                    continue;
+                }
+                pPlayers[uActiveCharacter]->uQuickSpell = quick_spell_at_page + 11 * pPlayers[uActiveCharacter]->lastOpenedSpellbookPage;
+                AA1058_PartyQuickSpellSound[uActiveCharacter - 1].AddPartySpellSound(pPlayers[uActiveCharacter]->uQuickSpell, uActiveCharacter);
+                if (uActiveCharacter)
+                    pPlayer10->PlaySound(SPEECH_12, 0);
+                byte_506550 = 0;
+                continue;
+            case UIMSG_SpellBook_PressTab://ïåðåëèñòûâàíèå ñòðàíèö êëàâèøåé Tab
+            {
+                if (!uActiveCharacter)
+                    continue;
+                int skill_count = 0;
+                uAction = 0;
+                for (uint i = 0; i < 9; i++)
+                {
+                    if (pPlayers[uActiveCharacter]->pActiveSkills[PLAYER_SKILL_FIRE + i])
+                    {
+                        if (pPlayers[uActiveCharacter]->lastOpenedSpellbookPage == i)
+                            uAction = skill_count;
+                        v217[skill_count++] = i;
+                    }
+                }
+                if (!skill_count)//íåò ñêèëëîâ
+                    pAudioPlayer->PlaySound((SoundID)(rand() % 2 + SOUND_TurnPageU), 0, 0, -1, 0, 0, 0, 0);
+                else
+                {
+                    if (GetAsyncKeyState(VK_SHIFT))
+                    {
+                        --uAction;
+                        if (uAction < 0)
+                            uAction = skill_count - 1;
+                    }
+                    else
+                    {
+                        ++uAction;
+                        if (uAction >= skill_count)
+                            uAction = 0;
+                    }
+                    OnCloseSpellBookPage();
+                    pPlayers[uActiveCharacter]->lastOpenedSpellbookPage = LOBYTE(v217[uAction]);
+                    pGUIWindow_CurrentMenu->OpenSpellBook();
+                    pAudioPlayer->PlaySound((SoundID)(rand() % 2 + SOUND_TurnPageU), 0, 0, -1, 0, 0, 0, 0);
+                }
+                continue;
+            }
+            case UIMSG_OpenSpellbookPage:
+                if (pTurnEngine->turn_stage == TE_MOVEMENT || !uActiveCharacter || uMessageParam == pPlayers[uActiveCharacter]->lastOpenedSpellbookPage)
+                    continue;
+                OnCloseSpellBookPage();
+                pPlayers[uActiveCharacter]->lastOpenedSpellbookPage = uMessageParam;
+                pGUIWindow_CurrentMenu->OpenSpellBook();
+                pAudioPlayer->PlaySound((SoundID)(rand() % 2 + SOUND_TurnPageU), 0, 0, -1, 0, 0, 0, 0);
+                continue;
+            case UIMSG_SelectSpell:
+            {
+                if (pTurnEngine->turn_stage == TE_MOVEMENT)
+                    continue;
+                if (!uActiveCharacter)
+                    continue;
+
+                //  uNumSeconds = (unsigned int)pPlayers[uActiveCharacter];
+                Player* player = pPlayers[uActiveCharacter];
+                if (player->spellbook.pChapters[player->lastOpenedSpellbookPage].bIsSpellAvailable[uMessageParam])
+                    //if ( *(char *)(uNumSeconds + 11 * *(char *)(uNumSeconds + &lastOpenedSpellbookPage) + uMessageParam + 402) )
+                {
+                    if (quick_spell_at_page - 1 == uMessageParam)
+                    {
+                        pGUIWindow_CurrentMenu->Release();
+                        pEventTimer->Resume();
+                        viewparams->bRedrawGameUI = 1;
+                        current_screen_type = SCREEN_GAME;
+                        pIcons_LOD->RemoveTexturesPackFromTextureList();
+                        v103 = quick_spell_at_page + 11 * player->lastOpenedSpellbookPage;
+                        /*if ( dword_50C9E8 < 40 )
+                        {
+                        dword_50C9EC[3 * dword_50C9E8] = UIMSG_CastSpellFromBook;
+                        dword_50C9EC[3 * dword_50C9E8 + 1] = v103;
+                        dword_50C9EC[3 * dword_50C9E8 + 2] = uActiveCharacter - 1;
+                        ++dword_50C9E8;
+                        }*/
+                        pMessageQueue_50C9E8->AddGUIMessage(UIMSG_CastSpellFromBook, v103, uActiveCharacter - 1);
+                        //  pMessageQueue_50CBD0->AddGUIMessage(UIMSG_CastSpellFromBook, v103, uActiveCharacter - 1);
+                    }
+                    else
+                    {
+                        byte_506550 = 1;
+                        quick_spell_at_page = uMessageParam + 1;
+                    }
+                }
+            }
+                continue;
+
+            case UIMSG_CastSpellFromBook:
+                if (pTurnEngine->turn_stage != TE_MOVEMENT)
+                    _42777D_CastSpell_UseWand_ShootArrow(uMessageParam, v199, 0, 0, 0);
+                continue;
+
+            case UIMSG_SpellScrollUse:
+                __debugbreak();
+                if (pTurnEngine->turn_stage != TE_MOVEMENT)
+                    _42777D_CastSpell_UseWand_ShootArrow(uMessageParam, v199, 133, 1, 0);
+                continue;
+            case UIMSG_SpellBookWindow:
+                if (pTurnEngine->turn_stage == TE_MOVEMENT)
+                    continue;
+                if (bUnderwater == true)
+                {
+                    ShowStatusBarString(pGlobalTXT_LocalizationStrings[652], 2);// "You can not do that while you are underwater!"
+                    pAudioPlayer->PlaySound(SOUND_error, 0, 0, -1, 0, 0, 0, 0);
+                }
+                else
+                {
+                    DoThatMessageThing();
+                    if (uActiveCharacter && !pPlayers[uActiveCharacter]->uTimeToRecovery)
+                    {
+                        if (current_screen_type == SCREEN_GAME)
+                        {
+                            GUIWindow::Create(476, 450, 0, 0, WINDOW_PressedButton2, (int)pBtn_CastSpell, 0);
+                            current_screen_type = SCREEN_SPELL_BOOK;
+                            pEventTimer->Pause();
+                            pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_SpellBook, 0, 0);
+                            pAudioPlayer->PlaySound(SOUND_48, 0, 0, -1, 0, 0, 0, 0);
+                            viewparams->field_48 = 1;
+                            continue;
+                        }
+                        if (current_screen_type != SCREEN_REST && current_screen_type != SCREEN_CHARACTERS
+                            && (current_screen_type <= SCREEN_63 || current_screen_type > SCREEN_67))
+                        {
+                            pGUIWindow_CurrentMenu->Release();
+                            GUIWindow::Create(476, 450, 0, 0, WINDOW_PressedButton2, (int)pBtn_CastSpell, 0);
+                            current_screen_type = SCREEN_SPELL_BOOK;
+                            pEventTimer->Pause();
+                            pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_SpellBook, 0, 0);
+                            pAudioPlayer->PlaySound(SOUND_48, 0, 0, -1, 0, 0, 0, 0);
+                            viewparams->field_48 = 1;
+                            continue;
+                        }
+                    }
+                }
+                continue;
+            case UIMSG_QuickReference:
+                DoThatMessageThing();
+                if (current_screen_type)
+                    pGUIWindow_CurrentMenu->Release();
+                ++pIcons_LOD->uTexturePacksCount;
+                if (!pIcons_LOD->uNumPrevLoadedFiles)
+                    pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
+                GUIWindow::Create(0x230u, 0x1C2u, 0, 0, WINDOW_PressedButton2, (int)pBtn_QuickReference, 0);
+                viewparams->bRedrawGameUI = 1;
+                pEventTimer->Pause();
+                pAudioPlayer->StopChannels(-1, -1);
+                current_screen_type = SCREEN_QUICK_REFERENCE;
+                pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_QuickReference, 5, 0);
+                papredoll_dbrds[2] = pIcons_LOD->LoadTexture("BUTTEXI1", TEXTURE_16BIT_PALETTE);
+                pBtn_ExitCancel = pGUIWindow_CurrentMenu->CreateButton(0x187u, 0x13Cu, 0x4Bu, 0x21u, 1, 0, UIMSG_Escape, 0, 0,
+                    pGlobalTXT_LocalizationStrings[79],// "Exit"
+                    pIcons_LOD->GetTexture(uTextureID_BUTTDESC2), 0); //, v179);
+                continue;
+            case UIMSG_GameMenuButton:
+                if (current_screen_type)
+                {
+                    pGUIWindow_CurrentMenu->Release();
+                    pEventTimer->Resume();
+                    current_screen_type = SCREEN_GAME;
+                    viewparams->bRedrawGameUI = 1;
+                }
+
+                stru_506E40.Release();
+                pRenderer->SaveScreenshot("gamma.pcx", 155, 117);
+                stru_506E40.LoadPCXFile("gamma.pcx", 0);
+
+                GUIWindow::Create(0x25Au, 0x1C2u, 0, 0, WINDOW_PressedButton, (int)pBtn_GameSettings, 0);
+                //LABEL_453:
+                /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
+                continue;
+                pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape;
+                //goto LABEL_770;
+                pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
+                *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
+                ++pMessageQueue_50CBD0->uNumMessages;*/
+                pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Escape, 0, 0);
+                continue;
+            case UIMSG_ClickAwardScrollBar:
+                books_page_number = 1;
+                if (pMouse->GetCursorPos(&v211)->y > 178)
+                    books_page_number = -1;
+                continue;
+            case UIMSG_ClickAwardsUpBtn:
+                GUIWindow::Create(pBtn_Up->uX, pBtn_Up->uY, 0, 0, WINDOW_CharactersPressedButton, (int)pBtn_Up, 0);
+                BtnUp_flag = 1;
+                continue;
+            case UIMSG_ClickAwardsDownBtn:
+                GUIWindow::Create(pBtn_Down->uX, pBtn_Down->uY, 0, 0, WINDOW_CharactersPressedButton, (int)pBtn_Down, 0);
+                BtnDown_flag = 1;
+                continue;
+            case UIMSG_ChangeDetaliz:
+                bRingsShownInCharScreen ^= 1;
+                pCharacterScreen_DetalizBtn->Release();
+                pCharacterScreen_DollBtn->Release();
+                if (bRingsShownInCharScreen)
+                {
+                    v128 = pIcons_LOD->GetTexture(uTextureID_detaliz_close_button)->uTextureHeight;
+                    v125 = pIcons_LOD->GetTexture(uTextureID_detaliz_close_button)->uTextureWidth;
+                    v123 = 445;
+                    v121 = 470;
+                }
+                else
+                {
+                    v128 = 30;
+                    v125 = 30;
+                    v123 = 300;
+                    v121 = 600;
+                }
+                pCharacterScreen_DetalizBtn = pGUIWindow_CurrentMenu->CreateButton(v121, v123, v125, v128, 1, 0, UIMSG_ChangeDetaliz, 0, 0,
+                    pGlobalTXT_LocalizationStrings[64],// "Detail Toggle"
+                    0);
+                pCharacterScreen_DollBtn = pGUIWindow_CurrentMenu->CreateButton(0x1DCu, 0, 0xA4u, 0x159u, 1, 0, UIMSG_ClickPaperdoll, 0, 0, "", 0);
+                viewparams->bRedrawGameUI = 1;
+                continue;
+            case UIMSG_ClickPaperdoll:
+                OnPaperdollLeftClick();
+                continue;
+            case UIMSG_ClickStatsBtn:
+                pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 100;
+                CharacterUI_ReleaseButtons();
+                ReleaseAwardsScrollBar();
+                GUIWindow::Create(pCharacterScreen_StatsBtn->uX, pCharacterScreen_StatsBtn->uY, 0, 0, WINDOW_CharactersPressedButton, (int)pCharacterScreen_StatsBtn, 0);
+                continue;
+            case UIMSG_ClickSkillsBtn:
+                pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 101;
+                CharacterUI_ReleaseButtons();
+                ReleaseAwardsScrollBar();
+                CharacterUI_SkillsTab_CreateButtons();
+                GUIWindow::Create(pCharacterScreen_SkillsBtn->uX, pCharacterScreen_SkillsBtn->uY, 0, 0, WINDOW_CharactersPressedButton, (int)pCharacterScreen_SkillsBtn, 0);
+                continue;
+            case UIMSG_SkillUp:
+                pPlayer4 = pPlayers[uActiveCharacter];
+                v105 = (int)&pPlayer4->pActiveSkills[uMessageParam];
+                LOWORD(v2) = *(short *)v105;
+                uNumSeconds = v2;
+                if (pPlayer4->uSkillPoints < (v2 & 0x3F) + 1)
+                {
+                    v87 = pGlobalTXT_LocalizationStrings[488];// "You don't have enough skill points!"
+                }
+                else
+                {
+                    if ((uNumSeconds & 0x3F) < 0x3C)
+                    {
+                        *(short *)v105 = uNumSeconds + 1;
+                        pPlayer4->uSkillPoints -= pPlayer4->pActiveSkills[uMessageParam] & 0x3F;
+                        pPlayer4->PlaySound(SPEECH_14, 0);
+                        pAudioPlayer->PlaySound((SoundID)SOUND_quest, 0, 0, -1, 0, 0, 0, 0);
+                        continue;
+                    }
+                    v87 = pGlobalTXT_LocalizationStrings[487];// "You have already mastered this skill!"
+                }
+                ShowStatusBarString(v87, 2);
+                continue;
+            case UIMSG_ClickInventoryBtn:
+                pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 103;
+                ReleaseAwardsScrollBar();
+                CharacterUI_ReleaseButtons();
+                GUIWindow::Create(pCharacterScreen_InventoryBtn->uX, pCharacterScreen_InventoryBtn->uY, 0, 0, WINDOW_CharactersPressedButton, (int)pCharacterScreen_InventoryBtn, 0);
+                continue;
+            case UIMSG_ClickExitCharacterWindowBtn:
+                GUIWindow::Create(pCharacterScreen_ExitBtn->uX, pCharacterScreen_ExitBtn->uY, 0, 0, WINDOW_ExitCharacterWindow, (int)pCharacterScreen_ExitBtn, 0);
+                continue;
+            case UIMSG_ClickAwardsBtn:
+                ReleaseAwardsScrollBar();
+                CharacterUI_ReleaseButtons();
+                CreateAwardsScrollBar();
+                pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 102;
+                GUIWindow::Create(pCharacterScreen_AwardsBtn->uX, pCharacterScreen_AwardsBtn->uY, 0, 0, WINDOW_CharactersPressedButton, (int)pCharacterScreen_AwardsBtn, 0);
+                FillAwardsData();
+                continue;
+            case UIMSG_ClickBooksBtn:
+                switch (uMessageParam)
+                {
+                case 11://Page UP
+                    BtnUp_flag = 1;
+                    pButton = pBtn_Book_2;
+                    break;
+                case 10://Page DOWN
+                    BtnDown_flag = 1;
+                    pButton = pBtn_Book_1;
+                    break;
+                case 0://Zoom plus
+                    pButton = pBtn_Book_1;
+                    BtnDown_flag = 1;
+                    break;
+                case 1://Zoom minus
+                    pButton = pBtn_Book_2;
+                    BtnUp_flag = 1;
+                    break;
+                case 2://Potions
+                    Book_PageBtn3_flag = 1;
+                    if (dword_506364)
+                        continue;
+                    pButton = pBtn_Book_3;
+                    break;
+                case 3://fountains
+                    Book_PageBtn4_flag = 1;
+                    if (dword_506364)
+                        continue;
+                    pButton = pBtn_Book_4;
+                    break;
+                case 4://obelisks
+                    Book_PageBtn5_flag = 1;//Autonotes_Obelisks_page_flag
+                    if (dword_506364)
+                        continue;
+                    pButton = pBtn_Book_5;
+                    break;
+                case 5://seer
+                    Book_PageBtn6_flag = 1;//Autonotes_Seer_page_flag
+                    if (dword_506364)
+                        continue;
+                    pButton = pBtn_Book_6;
+                    break;
+                case 6://misc
+                    pButton = pBtn_Autonotes_Misc;
+                    Autonotes_Misc_page_flag = 1;
+                    break;
+                case 7://Instructors
+                    pButton = pBtn_Autonotes_Instructors;
+                    Autonotes_Instructors_page_flag = 1;
+                    break;
+                default:
+                    continue;
+                }
+                GUIWindow::Create(pButton->uX, pButton->uY, 0, 0, WINDOW_PressedButton, (int)pButton, (char *)1);
+                continue;
+            case UIMSG_SelectCharacter:
+                DoThatMessageThing();
+                GameUI_OnPlayerPortraitLeftClick(uMessageParam);
+                continue;
+            case UIMSG_ShowStatus_Funds:
+                v174 = (char *)pParty->uNumGoldInBank;
+                //v158 = pParty->uNumGold + pParty->uNumGoldInBank;
+                sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[489], pParty->uNumGold + pParty->uNumGoldInBank, v174);// "You have %d total gold, %d in the Bank"
+                GameUI_SetFooterString(pTmpBuf.data());
+                continue;
+            case UIMSG_ShowStatus_DateTime:
+                currHour = pParty->uCurrentHour;
+                uNumSeconds = 1;
+                if (pParty->uCurrentHour > 12)
+                {
+                    if (pParty->uCurrentHour >= 24)
+                        uNumSeconds = 0;
+                    currHour = (currHour - 12);
+                }
+                else
+                {
+                    if (pParty->uCurrentHour < 12) // 12:00 is PM
+                        uNumSeconds = 0;
+                    if (pParty->uCurrentHour == 0)
+                        currHour = 12;
+                }
+                sprintf(pTmpBuf.data(), "%d:%02d%s %s %d %s %d", currHour, pParty->uCurrentMinute, aAMPMNames[uNumSeconds], aDayNames[pParty->uDaysPlayed % 7],
+                    7 * pParty->uCurrentMonthWeek + pParty->uDaysPlayed % 7 + 1, aMonthNames[pParty->uCurrentMonth], pParty->uCurrentYear);
+                GameUI_SetFooterString(pTmpBuf.data());
+                continue;
+            case UIMSG_ShowStatus_Food:
+                sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[501], pParty->uNumFoodRations); // "You have %lu food"
+                GameUI_SetFooterString(pTmpBuf.data());
+                continue;
+            case UIMSG_ShowStatus_Player:
+                pPlayer5 = pPlayers[uMessageParam];
+                sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[429], pPlayer5->pName, pClassNames[pPlayer5->classType]);// "%s the %s"
+                strcat(pTmpBuf.data(), ": ");
+                v107 = pPlayer5->GetMajorConditionIdx();
+                strcat(pTmpBuf.data(), aCharacterConditionNames[v107]);
+                GameUI_SetFooterString(pTmpBuf.data());
+                v108 = 8 * uMessageParam - 8;
+                LOBYTE(v108) = v108 | 4;
+                pMouse->uPointingObjectID = PID(OBJECT_Player, v108);
+                continue;
+            case UIMSG_ShowStatus_ManaHP:
+                sprintf(pTmpBuf.data(), "%d / %d %s    %d / %d %s", pPlayers[uMessageParam]->sHealth, pPlayers[uMessageParam]->GetMaxHealth(),
+                    pGlobalTXT_LocalizationStrings[108], pPlayers[uMessageParam]->sMana, pPlayers[uMessageParam]->GetMaxMana(),
+                    pGlobalTXT_LocalizationStrings[212]);
+                GameUI_SetFooterString(pTmpBuf.data());
+                continue;
+            case UIMSG_CHEST_ClickItem:
+                if (current_screen_type == SCREEN_CHEST_INVENTORY)
+                {
+                    pPlayers[uActiveCharacter]->OnInventoryLeftClick();
+                    continue;
+                }
+                Chest::OnChestLeftClick();
+                continue;
+            case UIMSG_InventoryLeftClick:
+                pPlayers[uActiveCharacter]->OnInventoryLeftClick();
+                continue;
+            case UIMSG_MouseLeftClickInGame:
+                /*if ( !pRenderer->pRenderD3D )
+                {
+                if ( pMessageQueue_50CBD0->uNumMessages )
+                pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
+                OnGameViewportClick();
+                continue;
+                }*/
+                v115 = pMessageQueue_50CBD0->uNumMessages;
+                if (!pMessageQueue_50CBD0->uNumMessages)
+                {
+                    pMessageQueue_50CBD0->AddGUIMessage(UIMSG_MouseLeftClickInScreen, 0, 0);
+                    /*if ( (signed int)v115 < 40 )
+                    //goto LABEL_769;
+                    {
+                    pMessageQueue_50CBD0->pMessages[v115].eType = UIMSG_MouseLeftClickInScreen;
+                    pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
+                    *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
+                    ++pMessageQueue_50CBD0->uNumMessages;
+                    continue;
+                    }*/
+                    continue;
+                }
+                if (pMessageQueue_50CBD0->pMessages[0].field_8)
+                {
+                    pMessageQueue_50CBD0->uNumMessages = 1;
+                    pMessageQueue_50CBD0->AddGUIMessage(UIMSG_MouseLeftClickInScreen, 0, 0);
+                    /*v115 = v0;
+                    pMessageQueue_50CBD0->uNumMessages = v0;
+                    pMessageQueue_50CBD0->pMessages[v115].eType = UIMSG_MouseLeftClickInScreen;
+                    pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
+                    //goto LABEL_771;
+                    *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
+                    ++pMessageQueue_50CBD0->uNumMessages;*/
+                    continue;
+                }
+                v115 = 0;
+                pMessageQueue_50CBD0->uNumMessages = 0;
+                pMessageQueue_50CBD0->AddGUIMessage(UIMSG_MouseLeftClickInScreen, 0, 0);
+                /*if ( (signed int)v115 < 40 )
+                //goto LABEL_769;
+                {
+                pMessageQueue_50CBD0->pMessages[v115].eType = UIMSG_MouseLeftClickInScreen;
+                pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
+                *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
+                ++pMessageQueue_50CBD0->uNumMessages;
+                continue;
+                }*/
+                continue;
+            case UIMSG_MouseLeftClickInScreen://ñðàáàòûâàåò ïðè íàæàòèè íà ïðàâóþ êíîïêó ìûøè ïîñëå UIMSG_MouseLeftClickInGame
+                DoThatMessageThing();
+                OnGameViewportClick();
+                continue;
+            case UIMSG_F:
+                __debugbreak();
+                //if ( pRenderer->pRenderD3D )
+                {
+                    LOWORD(v116) = pEngine->pVisInstance->get_picked_object_zbuf_val();
+                }
+                /*else
+                {
+                uNumSeconds = (unsigned int)pMouse->GetCursorPos(&v209);
+                pPoint3 = pMouse->GetCursorPos(&v204);
+                v116 = pRenderer->pActiveZBuffer[*(int *)uNumSeconds + pSRZBufferLineOffsets[pPoint3->y]];
+                }*/
+                pButton2 = (GUIButton *)(unsigned __int16)v116;
+                GUIWindow::Create(0, 0, 0, 0, WINDOW_F, (int)pButton2, 0);
+                continue;
+            case UIMSG_54:
+                __debugbreak();
+                pButton2 = (GUIButton *)uMessageParam;
+                GUIWindow::Create(0, 0, 0, 0, WINDOW_22, (int)pButton2, 0);
+                continue;
+            case UIMSG_Game_Action:
+                DoThatMessageThing();
+                OnPressSpace();
+                continue;
+            case UIMSG_ClickZoomOutBtn:
+                if (current_screen_type)
+                    continue;
+                pParty->uFlags |= 2u;
+                GUIWindow::Create(519, 136, 0, 0, WINDOW_PressedButton2, (int)pBtn_ZoomOut, 0);
+                uNumSeconds = 131072;
+                v118 = 2 * viewparams->uMinimapZoom;
+                ++viewparams->field_28;
+                viewparams->uMinimapZoom *= 2;
+                if (uCurrentlyLoadedLevelType != LEVEL_Outdoor)
+                {
+                    if ((signed int)v118 > 4096)
+                    {
+                        viewparams->uMinimapZoom = 4096;
+                        viewparams->field_28 = 12;
+                    }
+                    continue;
+                }
+                v119 = 2048;
+                if ((signed int)v118 <= 2048)
+                {
+                    _576E2C_current_minimap_zoom = v118;
+                    dword_576E28 = viewparams->field_28;
+                    break;
+                }
+                viewparams->field_28 = 11;
+                viewparams->uMinimapZoom = v119;
+                _576E2C_current_minimap_zoom = v119;
+                dword_576E28 = viewparams->field_28;
+                break;
+            case UIMSG_ClickZoomInBtn:
+                if (current_screen_type)
+                    continue;
+                pParty->uFlags |= 2u;
+                GUIWindow::Create(574, 136, 0, 0, WINDOW_PressedButton2, (int)pBtn_ZoomIn, 0);
+                uNumSeconds = 32768;
+                v118 = (unsigned __int64)((signed __int64)(signed int)viewparams->uMinimapZoom << 15) >> 16;
+                --viewparams->field_28;
+                viewparams->uMinimapZoom = (unsigned __int64)((signed __int64)(signed int)viewparams->uMinimapZoom << 15) >> 16;
+                if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
+                {
+                    v119 = 512;
+                    if ((signed int)v118 < 512)
+                    {
+                        viewparams->field_28 = 9;
+                        v118 = v119;
+                        viewparams->uMinimapZoom = v119;
+                    }
+                    _576E2C_current_minimap_zoom = v118;
+                    dword_576E28 = viewparams->field_28;
+                }
+                else
+                {
+                    if ((signed int)v118 < 256)
+                    {
+                        viewparams->uMinimapZoom = 256;
+                        viewparams->field_28 = 8;
+                    }
+                }
+            default:
+                continue;
+            }
+        }
+    }
+    pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50C9E8->uNumMessages;//dword_50C9E8;
+    memcpy(pMessageQueue_50CBD0->pMessages, pMessageQueue_50C9E8->pMessages, sizeof(GUIMessage) * pMessageQueue_50C9E8->uNumMessages);
+    //memcpy(pMessageQueue_50CBD0->pMessages, dword_50C9EC, 12 * dword_50C9E8);
+    //dword_50C9E8 = 0;
+
+
+    pMessageQueue_50C9E8->uNumMessages = 0;
+    if (dword_50C9DC)
+    {
+        /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+        {
+        pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)dword_50C9DC;
+        pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = (int)ptr_50C9E0;
+        *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
+        ++pMessageQueue_50CBD0->uNumMessages;
+        }*/
+        pMessageQueue_50CBD0->AddGUIMessage((UIMessageType)dword_50C9DC, (int)ptr_50C9E0, 0);
+        dword_50C9DC = 0;
+    }
+    else
+    {
+        if (_50C9D0_AfterEnchClickEventId > 0)
+        {
+            _50C9D8_AfterEnchClickEventTimeout -= pEventTimer->uTimeElapsed;
+            if (_50C9D8_AfterEnchClickEventTimeout <= 0)
+            {
+                /*if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
+                {
+                pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)dword_50C9D0;
+                pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = dword_50C9D4;
+                *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
+                ++pMessageQueue_50CBD0->uNumMessages;
+                }*/
+                pMessageQueue_50CBD0->AddGUIMessage((UIMessageType)_50C9D0_AfterEnchClickEventId, _50C9D4_AfterEnchClickEventSecondParam, 0);
+                _50C9D0_AfterEnchClickEventId = 0;
+                _50C9D4_AfterEnchClickEventSecondParam = 0;
+                _50C9D8_AfterEnchClickEventTimeout = 0;
+            }
+        }
+    }
+    CastSpellInfoHelpers::_427E01_cast_spell();
+}
+
+
+
+
+
+//----- (00463149) --------------------------------------------------------
+void Game_Loop()
+{
+    const char *pLocationName; // [sp-4h] [bp-68h]@74
+    bool bLoading; // [sp+10h] [bp-54h]@1
+    signed int v16; // [sp+14h] [bp-50h]@8
+    MSG Msg; // [sp+28h] [bp-3Ch]@20
+    char Source[64]; // [sp+44h] [bp-20h]@76
+
+    bLoading = sCurrentMenuID == MENU_LoadingProcInMainMenu;
+    SetCurrentMenuID((MENU_STATE)-1);
+    if (bLoading)
+    {
+        pParty->Reset();
+        uGameState = GAME_STATE_PLAYING;
+        LoadGame(uLoadGameUI_SelectedSlot);
+    }
+
+    for (uint i = 1; i < 5; ++i)
+        for (uint j = 1; j < 6; ++j)
+        {
+        sprintf(pTmpBuf.data(), "data\\lloyd%d%d.pcx", i, j);
+        remove(pTmpBuf.data());
+        }
+
+    extern bool use_music_folder;
+    LoadPlayerPortraintsAndVoices();
+    pIcons_LOD->_inlined_sub1();
+    if (use_music_folder)
+        alSourcef(mSourceID, AL_GAIN, pSoundVolumeLevels[uMusicVolimeMultiplier]);
+    else
+        pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f);
+
+    while (2)
+    {
+        v16 = 1;
+        pMessageQueue_50CBD0->Flush();
+
+        pPartyActionQueue->uNumActions = 0;
+        if (pParty->bTurnBasedModeOn)
+        {
+            pTurnEngine->End(false);
+            pParty->bTurnBasedModeOn = false;
+        }
+        DoPrepareWorld(bLoading, 1);
+        pEventTimer->Resume();
+        dword_6BE364_game_settings_1 |= GAME_SETTINGS_0080_SKIP_USER_INPUT_THIS_FRAME;
+        // uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions = 0;
+        current_screen_type = SCREEN_GAME;
+
+        //if ( pRenderer->pRenderD3D )
+        pEngine->pVisInstance->_4C1A02();
+
+        bool game_finished = false;
+        do
+        {
+            while (PeekMessageA(&Msg, 0, 0, 0, PM_REMOVE))
+            {
+                if (Msg.message == WM_QUIT)
+                    Engine_DeinitializeAndTerminate(0);
+                TranslateMessage(&Msg);
+                DispatchMessageA(&Msg);
+            }
+            if (dword_6BE364_game_settings_1 & GAME_SETTINGS_APP_INACTIVE)
+            {
+                WaitMessage();
+                continue;
+            }
+            pEngine->_44EEA7();
+            GameUI_WritePointedObjectStatusString();
+            Keyboard::ProcessInputActions();
+            Game_EventLoop();
+            if (pArcomageGame->bGameInProgress)
+            {
+                ArcomageGame::Loop();
+                pRenderer->Present();
+                continue;
+            }
+
+            pMediaPlayer->HouseMovieLoop();
+
+            pEventTimer->Update();
+            pMiscTimer->Update();
+
+            OnTimer(0);
+            GameUI_StatusBar_UpdateTimedString(0);
+            if (pMiscTimer->bPaused && !pEventTimer->bPaused)
+                pMiscTimer->Resume();
+            if (pEventTimer->bTackGameTime && !pParty->bTurnBasedModeOn)
+                pEventTimer->bTackGameTime = 0;
+            if (!pEventTimer->bPaused && uGameState == GAME_STATE_PLAYING)
+            {
+                if (!pEventTimer->bTackGameTime)
+                    _494035_timed_effects__water_walking_damage__etc();
+
+                if (dword_6BE364_game_settings_1 & GAME_SETTINGS_0001)
+                    dword_6BE364_game_settings_1 &= ~GAME_SETTINGS_0001;
+                else
+                {
+                    Actor::UpdateActorAI();
+                    UpdateUserInput_and_MapSpecificStuff();
+                }
+            }
+            if (v16)
+            {
+                v16 = 0;
+                viewparams->bRedrawGameUI = true;
+            }
+            pAudioPlayer->UpdateSounds();
+            if ((signed int)uGameState == GAME_STATE_PLAYING)
+            {
+                pEngine->Draw();
+                continue;
+            }
+            if (uGameState == GAME_FINISHED)
+            {
+                game_finished = true;
+                continue;
+            }
+            if (uGameState == GAME_STATE_CHANGE_LOCATION)// ñìåíà ëîêàöèè
+            {
+                pAudioPlayer->StopChannels(-1, -1);
+                PrepareWorld(0);
+                uGameState = GAME_STATE_PLAYING;
+                continue;
+            }
+            if ((signed int)uGameState <= GAME_STATE_5 || uGameState == GAME_STATE_GAME_QUITTING_TO_MAIN_MENU)//GAME_STATE_NEWGAME_OUT_GAMEMENU, GAME_STATE_LOADING_GAME
+            {
+                game_finished = true;
+                continue;
+            }
+            if (uGameState == GAME_STATE_FINAL_WINDOW)
+            {
+                pRenderer->BeginScene();
+                GUI_UpdateWindows();
+                pRenderer->EndScene();
+                pRenderer->Present();
+                continue;
+            }
+            if (uGameState != GAME_STATE_PARTY_DIED)
+            {
+                pEngine->Draw();
+                continue;
+            }
+            if (uGameState == GAME_STATE_PARTY_DIED)
+            {
+                pAudioPlayer->StopChannels(-1, -1);
+                memset(&pParty->pHirelings[0], 0, 0x4Cu);
+                memset(&pParty->pHirelings[1], 0, 0x4Cu);
+                for (int i = 0; i < (signed int)pNPCStats->uNumNewNPCs; ++i)
+                {
+                    if (pNPCStats->pNewNPCData[i].field_24)
+                        pNPCStats->pNewNPCData[i].uFlags &= 0xFFFFFF7Fu;
+                }
+                pMediaPlayer->bStopBeforeSchedule = 0;
+                pMediaPlayer->PlayFullscreenMovie(MOVIE_Death, true);
+                if (pMovie_Track)
+                    pMediaPlayer->Unload();
+                SaveGame(0, 0);
+                ++pParty->uNumDeaths;
+                for (uint i = 0; i < 4; ++i)
+                    pParty->pPlayers[i].SetVariable(VAR_Award, 85);
+                pParty->days_played_without_rest = 0;
+                pParty->uTimePlayed += 0x276000ui64;
+                LOWORD(pParty->uFlags) &= ~0x204;
+                pParty->SetGold(0);
+                pOtherOverlayList->Reset();
+                memset(pParty->pPartyBuffs.data(), 0, 0x140u);
+
+                if (pParty->bTurnBasedModeOn == 1)
+                {
+                    pTurnEngine->End(true);
+                    pParty->bTurnBasedModeOn = 0;
+                }
+                for (int i = 0; i < 4; ++i)
+                {
+                    memset(pParty->pPlayers[i].pConditions.data(), 0, 0xA0u);//(pConditions, 0, 160)
+                    memset(pParty->pPlayers[i].pPlayerBuffs.data(), 0, 0x180u);//(pPlayerBuffs[0], 0, 384)
+                    pParty->pPlayers[i].sHealth = 1;
+                    uActiveCharacter = 1;
+                }
+                if (_449B57_test_bit(pParty->_quest_bits, PARTY_QUEST_FINISHED_EMERALD_ISLE))
+                {
+                    pParty->vPosition.x = -17331;            // respawn in harmondale
+                    pParty->vPosition.y = 12547;
+                    pParty->vPosition.z = 465;
+                    pParty->sRotationY = 0;
+                    pLocationName = "out02.odm";
+                }
+                else
+                {
+                    pParty->vPosition.x = 12552;             // respawn on emerald isle
+                    pParty->vPosition.y = 1816;
+                    pParty->vPosition.z = 0;
+                    pParty->sRotationY = 512;
+                    pLocationName = "out01.odm";
+                }
+                strcpy(Source, pLocationName);
+                pParty->uFallStartY = pParty->vPosition.z;
+                pParty->sRotationX = 0;
+                pParty->uFallSpeed = 0;
+                pParty->field_6E4 = 0;
+                pParty->field_6E0 = 0;
+                if (_stricmp(Source, pCurrentMapName))
+                {
+                    strcpy(pCurrentMapName, Source);
+                    _5B65A8_npcdata_uflags_or_other = pParty->vPosition.x;
+                    _5B65AC_npcdata_fame_or_other = pParty->vPosition.y;
+                    _5B65B0_npcdata_rep_or_other = pParty->vPosition.z;
+                    _5B65B4_npcdata_loword_house_or_other = pParty->sRotationY;
+                    _5B65B8_npcdata_hiword_house_or_other = pParty->sRotationX;
+                    dword_5B65C0 = 1;
+                    PrepareWorld(1);
+                }
+                Actor::InitializeActors();
+
+                int num_conscious_players = 0;
+                int conscious_players_ids[4] = { -1, -1, -1, -1 };
+                for (int i = 0; i < 4; ++i)
+                {
+                    if (pParty->pPlayers[i].CanAct())
+                        conscious_players_ids[num_conscious_players++] = i;
+                }
+                if (num_conscious_players)
+                {
+                    int idx = conscious_players_ids[rand() % num_conscious_players];
+                    Assert(idx >= 0);
+                    pParty->pPlayers[idx].PlaySound(SPEECH_99, 0);
+                }
+
+                ShowStatusBarString(pGlobalTXT_LocalizationStrings[524], 2);// "Once again you've cheated death!.." "Âû ñíîâà îáõèòðèëè ñìåðòü! …"
+                uGameState = GAME_STATE_PLAYING;
+            }
+        } while (!game_finished);
+
+        pEventTimer->Pause();
+        ResetCursor_Palettes_LODs_Level_Audio_SFT_Windows();
+        if (uGameState == GAME_STATE_LOADING_GAME)
+        {
+            sub_491E3A();
+            LoadPlayerPortraintsAndVoices();
+            uGameState = GAME_STATE_PLAYING;
+            pIcons_LOD->dword_11B84 = pIcons_LOD->uNumLoadedFiles;
+            bLoading = true;
+            continue;
+        }
+        break;
+    }
+    current_screen_type = SCREEN_VIDEO;
+    sub_491E3A();
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Game/Game.h	Sun May 10 01:29:11 2015 +0200
@@ -0,0 +1,3 @@
+#pragma once
+
+void Game_Loop();
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Game/MainMenu.cpp	Sun May 10 01:29:11 2015 +0200
@@ -0,0 +1,475 @@
+#include "Engine/Engine.h"
+#include "Engine/Timer.h"
+#include "Engine/Party.h"
+#include "Engine/LOD.h"
+#include "Engine/SaveLoad.h"
+#include "Engine/Graphics/IRender.h"
+#include "Engine/Graphics/Viewport.h"
+
+#include "IO/Mouse.h"
+#include "IO/Keyboard.h"
+
+#include "GUI/GUIWindow.h"
+#include "GUI/GUIButton.h"
+#include "GUI/UI/UIPartyCreation.h"
+
+#include "Media/Audio/AudioPlayer.h"
+
+#include "Game/MainMenu.h"
+
+
+//----- (00435748) --------------------------------------------------------
+void MainMenu_EventLoop()
+{
+    Player *pPlayer; // ebx@2
+    void *v3; // edi@21
+    signed int v4; // eax@29
+    //  int v5; // ecx@29
+    //  PLAYER_SKILL_TYPE v6; // edi@37
+    GUIWindow *pWindow; // eax@56
+    GUIButton *pButton; // eax@59
+    int v15; // edi@70
+    char v20; // dl@116
+    unsigned int v21; // eax@116
+    unsigned int v25; // eax@120
+    unsigned int v26; // ecx@127
+    //  SoundID pSoundID; // [sp-2Ch] [bp-3Ch]@36
+    //  signed int v41; // [sp-10h] [bp-20h]@29
+    int pParam; // [sp+4h] [bp-Ch]@3
+    UIMessageType pUIMessageType; // [sp+8h] [bp-8h]@3
+    int pSex; // [sp+Ch] [bp-4h]@3
+
+    if (pMessageQueue_50CBD0->uNumMessages)
+    {
+        pPlayer = pParty->pPlayers.data();
+        do
+        {
+            int param2;
+            pMessageQueue_50CBD0->PopMessage(&pUIMessageType, &pParam, &param2);
+            //auto player = &pParty->pPlayers[pParam];
+
+            switch (pUIMessageType) // For buttons of window MainMenu
+            {
+            case UIMSG_MainMenu_ShowPartyCreationWnd:
+                GUIWindow::Create(495, 172, 0, 0, WINDOW_PressedButton2, (int)pMainMenu_BtnNew, 0);
+                SetCurrentMenuID(MENU_NEWGAME);
+                break;
+            case UIMSG_MainMenu_ShowLoadWindow:
+                GUIWindow::Create(495, 227, 0, 0, WINDOW_PressedButton2, (int)pMainMenu_BtnLoad, 0);
+                SetCurrentMenuID(MENU_SAVELOAD);
+                break;
+            case UIMSG_ShowCredits:
+                GUIWindow::Create(495, 282, 0, 0, WINDOW_PressedButton2, (int)pMainMenu_BtnCredits, 0);
+                SetCurrentMenuID(MENU_CREDITS);
+                break;
+            case UIMSG_ExitToWindows:
+                GUIWindow::Create(495, 337, 0, 0, WINDOW_PressedButton2, (int)pMainMenu_BtnExit, 0);
+                SetCurrentMenuID(MENU_EXIT_GAME);
+                break;
+            case UIMSG_PlayerCreation_SelectAttribute:
+                pGUIWindow_CurrentMenu->pCurrentPosActiveItem = (pGUIWindow_CurrentMenu->pCurrentPosActiveItem - pGUIWindow_CurrentMenu->pStartingPosActiveItem)
+                    % 7 + pGUIWindow_CurrentMenu->pStartingPosActiveItem + 7 * pParam;
+                uPlayerCreationUI_SelectedCharacter = pParam;
+                pAudioPlayer->PlaySound(SOUND_SelectingANewCharacter, 0, 0, -1, 0, 0, 0, 0);
+                break;
+            case UIMSG_PlayerCreation_VoicePrev:
+                pSex = pParty->pPlayers[pParam].GetSexByVoice();
+                do
+                {
+                    if (pParty->pPlayers[pParam].uVoiceID == 0)
+                        pParty->pPlayers[pParam].uVoiceID = 19;
+                    else --pParty->pPlayers[pParam].uVoiceID;
+                } while (pParty->pPlayers[pParam].GetSexByVoice() != pSex);
+                pButton = pCreationUI_BtnPressLeft2[pParam];
+                GUIWindow::Create(pButton->uX, pButton->uY, 0, 0, WINDOW_PressedButton, (int)pButton, (char *)1);
+                pAudioPlayer->PlaySound(SOUND_SelectingANewCharacter, 0, 0, -1, 0, 0, 0, 0);
+                pParty->pPlayers[pParam].PlaySound(SPEECH_PickMe, 0);
+                break;
+            case UIMSG_PlayerCreation_VoiceNext:
+                pSex = pParty->pPlayers[pParam].GetSexByVoice();
+                do
+                {
+                    pParty->pPlayers[pParam].uVoiceID = (pParty->pPlayers[pParam].uVoiceID + 1) % 20;
+                } while (pParty->pPlayers[pParam].GetSexByVoice() != pSex);
+                pButton = pCreationUI_BtnPressRight2[pParam];
+                GUIWindow::Create(pButton->uX, pButton->uY, 0, 0, WINDOW_PressedButton, (int)pButton, (char *)1);
+                pAudioPlayer->PlaySound(SOUND_SelectingANewCharacter, 0, 0, -1, 0, 0, 0, 0);
+                pParty->pPlayers[pParam].PlaySound(SPEECH_PickMe, 0);
+                break;
+            case UIMSG_PlayerCreation_FacePrev:
+                //pPlayer = &pParty->pPlayers[pParam];
+                if (!pParty->pPlayers[pParam].uCurrentFace)
+                    pParty->pPlayers[pParam].uCurrentFace = 19;
+                else
+                    pParty->pPlayers[pParam].uCurrentFace -= 1;
+                pParty->pPlayers[pParam].uVoiceID = pParty->pPlayers[pParam].uCurrentFace;
+                pParty->pPlayers[pParam].SetInitialStats();
+                pParty->pPlayers[pParam].SetSexByVoice();
+                pParty->pPlayers[pParam].RandomizeName();
+                v25 = pParam;
+                pGUIWindow_CurrentMenu->pCurrentPosActiveItem = (pGUIWindow_CurrentMenu->pCurrentPosActiveItem - pGUIWindow_CurrentMenu->pStartingPosActiveItem)
+                    % 7 + pGUIWindow_CurrentMenu->pStartingPosActiveItem + 7 * pParam;
+                uPlayerCreationUI_SelectedCharacter = v25;
+                GUIWindow::Create(pCreationUI_BtnPressLeft[v25]->uX, pCreationUI_BtnPressLeft[v25]->uY, 0, 0, WINDOW_PressedButton, (int)pCreationUI_BtnPressLeft[v25], (char *)1);
+                pAudioPlayer->PlaySound(SOUND_SelectingANewCharacter, 0, 0, -1, 0, 0, 0.0, 0);
+                pParty->pPlayers[pParam].PlaySound(SPEECH_PickMe, 0);
+                break;
+            case UIMSG_PlayerCreation_FaceNext:
+                //pPlayer = &pParty->pPlayers[pParam];
+                v20 = (char)((int)pParty->pPlayers[pParam].uCurrentFace + 1) % 20;
+                pParty->pPlayers[pParam].uCurrentFace = v20;
+                pParty->pPlayers[pParam].uVoiceID = v20;
+                pParty->pPlayers[pParam].SetInitialStats();
+                pParty->pPlayers[pParam].SetSexByVoice();
+                pParty->pPlayers[pParam].RandomizeName();
+                v21 = pParam;
+                pGUIWindow_CurrentMenu->pCurrentPosActiveItem = (pGUIWindow_CurrentMenu->pCurrentPosActiveItem - pGUIWindow_CurrentMenu->pStartingPosActiveItem)
+                    % 7 + pGUIWindow_CurrentMenu->pStartingPosActiveItem + 7 * pParam;
+                uPlayerCreationUI_SelectedCharacter = v21;
+                GUIWindow::Create(pCreationUI_BtnPressRight[v21]->uX, pCreationUI_BtnPressRight[v21]->uY, 0, 0, WINDOW_PressedButton, (int)pCreationUI_BtnPressRight[v21], (char *)1);
+                pAudioPlayer->PlaySound(SOUND_SelectingANewCharacter, 0, 0, -1, 0, 0, 0, 0);
+                pParty->pPlayers[pParam].PlaySound(SPEECH_PickMe, 0);
+                break;
+            case UIMSG_PlayerCreationClickPlus:
+                GUIWindow::Create(613, 393, 0, 0, WINDOW_PressedButton2, (int)pPlayerCreationUI_BtnPlus, (char *)1);
+                pPlayer[uPlayerCreationUI_SelectedCharacter].IncreaseAttribute((pGUIWindow_CurrentMenu->pCurrentPosActiveItem - pGUIWindow_CurrentMenu->pStartingPosActiveItem) % 7);
+                pAudioPlayer->PlaySound(SOUND_ClickMinus, 0, 0, -1, 0, 0, 0, 0);
+                break;
+            case UIMSG_PlayerCreationClickMinus:
+                GUIWindow::Create(523, 393, 0, 0, WINDOW_PressedButton2, (int)pPlayerCreationUI_BtnMinus, (char *)1);
+                pPlayer[uPlayerCreationUI_SelectedCharacter].DecreaseAttribute((pGUIWindow_CurrentMenu->pCurrentPosActiveItem - pGUIWindow_CurrentMenu->pStartingPosActiveItem) % 7);
+                pAudioPlayer->PlaySound(SOUND_ClickPlus, 0, 0, -1, 0, 0, 0, 0);
+                break;
+            case UIMSG_PlayerCreationSelectActiveSkill:
+                if (pPlayer[uPlayerCreationUI_SelectedCharacter].GetSkillIdxByOrder(3) == 37)
+                    pParty->pPlayers[uPlayerCreationUI_SelectedCharacter].pActiveSkills[pPlayer[uPlayerCreationUI_SelectedCharacter].GetSkillIdxByOrder(pParam + 4)] = 1;
+                pAudioPlayer->PlaySound(SOUND_ClickSkill, 0, 0, -1, 0, 0, 0, 0);
+                break;
+            case UIMSG_PlayerCreationSelectClass:
+                pPlayer[uPlayerCreationUI_SelectedCharacter].Reset((PLAYER_CLASS_TYPE)pParam);
+                pAudioPlayer->PlaySound(SOUND_SelectingANewCharacter, 0, 0, -1, 0, 0, 0, 0);
+                break;
+            case UIMSG_PlayerCreationClickOK:
+                GUIWindow::Create(580, 431, 0, 0, WINDOW_PressedButton2, (int)pPlayerCreationUI_BtnOK, 0);
+                if (PlayerCreation_GetUnspentAttributePointCount() || !PlayerCreation_Choose4Skills())
+                    GameUI_Footer_TimeLeft = GetTickCount() + 4000;
+                else
+                    uGameState = GAME_STATE_STARTING_NEW_GAME;
+                break;
+            case UIMSG_PlayerCreationClickReset:
+                GUIWindow::Create(527, 431, 0, 0, WINDOW_PressedButton2, (int)pPlayerCreationUI_BtnReset, 0);
+                pParty->Reset();
+                break;
+            case UIMSG_PlayerCreationRemoveUpSkill:
+                v4 = pGUIWindow_CurrentMenu->pCurrentPosActiveItem - pGUIWindow_CurrentMenu->pStartingPosActiveItem;
+                pGUIWindow_CurrentMenu->pCurrentPosActiveItem = v4 % 7 + pGUIWindow_CurrentMenu->pStartingPosActiveItem + 7 * pParam;
+                if (pPlayer[pParam].GetSkillIdxByOrder(2) != 37)//37 - None(Íåò)
+                    pParty->pPlayers[pParam].pActiveSkills[pPlayer[pParam].GetSkillIdxByOrder(2)] = 0;
+                break;
+            case UIMSG_PlayerCreationRemoveDownSkill:
+                v4 = pGUIWindow_CurrentMenu->pCurrentPosActiveItem - pGUIWindow_CurrentMenu->pStartingPosActiveItem;
+                pGUIWindow_CurrentMenu->pCurrentPosActiveItem = v4 % 7 + pGUIWindow_CurrentMenu->pStartingPosActiveItem + 7 * pParam;
+                if (pPlayer[pParam].GetSkillIdxByOrder(3) != 37)//37 - None(Íåò)
+                    pParty->pPlayers[pParam].pActiveSkills[pPlayer[pParam].GetSkillIdxByOrder(3)] = 0;
+                break;
+            case UIMSG_PlayerCreationChangeName:
+                pAudioPlayer->PlaySound(SOUND_ClickSkill, 0, 0, -1, 0, 0, 0, 0);
+                v3 = (void *)pParam;
+                uPlayerCreationUI_SelectedCharacter = pParam;
+                pKeyActionMap->EnterText(0, 15, pGUIWindow_CurrentMenu);
+                pGUIWindow_CurrentMenu->ptr_1C = v3;
+                break;
+            case UIMSG_ChangeGameState:
+                uGameState = GAME_FINISHED;
+                break;
+            case UIMSG_ChangeCursor:
+                pMouse->SetCursorBitmap("MICON2");
+                break;
+            case UIMSG_3A:
+                SetCurrentMenuID(MENU_DebugBLVLevel);
+                break;
+            case UIMSG_LoadGame:
+                if (!pSavegameUsedSlots[uLoadGameUI_SelectedSlot])
+                    break;
+                SetCurrentMenuID(MENU_LoadingProcInMainMenu);
+                break;
+            case UIMSG_SelectLoadSlot:
+                //main menu save/load wnd   clicking on savegame lines
+                if (pGUIWindow_CurrentMenu->receives_keyboard_input_2 == WINDOW_INPUT_IN_PROGRESS)
+                    pKeyActionMap->SetWindowInputStatus(WINDOW_INPUT_NONE);
+                if (current_screen_type != SCREEN_SAVEGAME || uLoadGameUI_SelectedSlot != pParam + pSaveListPosition)
+                {
+                    //load clicked line
+                    v26 = pParam + pSaveListPosition;
+                    if (dword_6BE138 == pParam + pSaveListPosition)
+                    {
+                        pMessageQueue_50CBD0->AddGUIMessage(UIMSG_SaveLoadBtn, 0, 0);
+                        pMessageQueue_50CBD0->AddGUIMessage(UIMSG_LoadGame, 0, 0);
+                    }
+                    uLoadGameUI_SelectedSlot = v26;
+                    dword_6BE138 = v26;
+                }
+                else
+                {
+                    //typing in the line
+                    pKeyActionMap->EnterText(0, 19, pGUIWindow_CurrentMenu);
+                    strcpy(pKeyActionMap->pPressedKeysBuffer, pSavegameHeader[uLoadGameUI_SelectedSlot].pName);
+                    pKeyActionMap->uNumKeysPressed = strlen(pKeyActionMap->pPressedKeysBuffer);
+                }
+                break;
+            case UIMSG_SaveLoadBtn:
+                GUIWindow::Create(pGUIWindow_CurrentMenu->uFrameX + 241, pGUIWindow_CurrentMenu->uFrameY + 302, 61, 28, WINDOW_SaveLoadBtn, (int)pBtnLoadSlot, 0);
+                break;
+            case UIMSG_DownArrow:
+                ++pSaveListPosition;
+                if (pSaveListPosition >= pParam)
+                    pSaveListPosition = pParam - 1;
+                if (pSaveListPosition < 1)
+                    pSaveListPosition = 0;
+                pWindow = pGUIWindow_CurrentMenu;
+                GUIWindow::Create(pWindow->uFrameX + 215, pGUIWindow_CurrentMenu->uFrameY + 323, 0, 0, WINDOW_PressedButton2, (int)pBtnDownArrow, 0);
+                break;
+            case UIMSG_Cancel:
+                GUIWindow::Create(pGUIWindow_CurrentMenu->uFrameX + 350, pGUIWindow_CurrentMenu->uFrameY + 302, 61, 28, WINDOW_LoadGame_CancelBtn, (int)pBtnCancel, 0);
+                break;
+            case UIMSG_ArrowUp:
+                --pSaveListPosition;
+                if (pSaveListPosition < 0)
+                    pSaveListPosition = 0;
+                pWindow = pGUIWindow_CurrentMenu;
+                GUIWindow::Create(pWindow->uFrameX + 215, pGUIWindow_CurrentMenu->uFrameY + 197, 0, 0, WINDOW_PressedButton2, (int)pBtnArrowUp, 0);
+                break;
+            case UIMSG_AD:
+                GUIWindow::Create(pMainMenu_BtnNew->uX, pMainMenu_BtnNew->uY, 0, 0, WINDOW_PressedButton2, (int)pMainMenu_BtnNew, 0);
+                SetCurrentMenuID(MENU_LoadingProcInMainMenu);
+                break;
+            case UIMSG_AE:
+                GUIWindow::Create(pMainMenu_BtnExit->uX, pMainMenu_BtnExit->uY, 0, 0, WINDOW_PressedButton2, (int)pMainMenu_BtnExit, 0);
+                SetCurrentMenuID(MENU_DebugBLVLevel);
+                break;
+            case UIMSG_Escape:
+                if (pModalWindow)
+                {
+                    ModalWindow_Release();
+                    break;
+                }
+                if (!(dword_6BE364_game_settings_1 & GAME_SETTINGS_4000))
+                    break;
+                v15 = 1;
+                pMediaPlayer->bStopBeforeSchedule = 1;
+                viewparams->bRedrawGameUI = 1;
+                viewparams->field_48 = 1;
+                if (GetCurrentMenuID() == MENU_MAIN || GetCurrentMenuID() == MENU_MMT_MAIN_MENU
+                    || GetCurrentMenuID() == MENU_CREATEPARTY || GetCurrentMenuID() == MENU_NAMEPANELESC)
+                {
+                    //if ( current_screen_type == SCREEN_VIDEO )
+                    //pVideoPlayer->FastForwardToFrame(pVideoPlayer->pResetflag);			  
+                    if (GetCurrentMenuID() == MENU_NAMEPANELESC)  //èç ïàíåëè èçìåíåíèÿ èìåíè
+                    {
+                        SetCurrentMenuID(MENU_CREATEPARTY);//â îêíî ñîçäàíèÿ ãðóïïû
+                        break;
+                    }
+                    if (GetCurrentMenuID() == MENU_CREDITSPROC)	//èç îêíà Ñîçäàòåëè
+                    {
+                        SetCurrentMenuID(MENU_CREDITSCLOSE);//â çàêðûòèå Ñîçäàòåëè
+                        break;
+                    }
+                    pMessageQueue_50CBD0->AddGUIMessage(UIMSG_ChangeGameState, 0, 0);
+                    break;
+                }
+                if (GetCurrentMenuID() == MENU_CREDITSPROC && !current_screen_type)
+                {
+                    //if ( current_screen_type == SCREEN_VIDEO )
+                    //pVideoPlayer->FastForwardToFrame(pVideoPlayer->pResetflag);
+                    if (GetCurrentMenuID() == MENU_NAMEPANELESC)
+                    {
+                        SetCurrentMenuID(MENU_CREATEPARTY);
+                        break;
+                    }
+                    if (GetCurrentMenuID() == MENU_CREDITSPROC)
+                    {
+                        SetCurrentMenuID(MENU_CREDITSCLOSE);
+                        break;
+                    }
+                    pMessageQueue_50CBD0->AddGUIMessage(UIMSG_ChangeGameState, 0, 0);
+                    break;
+                }
+                if (current_screen_type == SCREEN_LOADGAME)
+                {
+                    pIcons_LOD->RemoveTexturesPackFromTextureList();
+                    //crt_deconstruct_ptr_6A0118();
+                    pTexture_PCX.Release();
+                    pTexture_PCX.Load("title.pcx", 0);
+                    SetCurrentMenuID(MENU_MAIN);
+                    v15 = 1;
+                    pGUIWindow_CurrentMenu->Release();
+                    pGUIWindow2->Release();
+                    pGUIWindow2 = 0;
+                    pEventTimer->Resume();
+                    current_screen_type = SCREEN_GAME;
+                    viewparams->bRedrawGameUI = v15;
+                    break;
+                }
+                if (current_screen_type == SCREEN_VIDEO)
+                {
+                    //pVideoPlayer->Unload();
+                }
+                else
+                {
+                    if (current_screen_type != SCREEN_1B)
+                    {
+                        pGUIWindow_CurrentMenu->Release();
+                        pGUIWindow2->Release();
+                        pGUIWindow2 = 0;
+                        pEventTimer->Resume();
+                        current_screen_type = SCREEN_GAME;
+                        viewparams->bRedrawGameUI = v15;
+                        break;
+                    }
+                    //VideoPlayer::dtor();
+                }
+                break;
+            default:
+                break;
+            }
+        } while (pMessageQueue_50CBD0->uNumMessages);
+    }
+}
+
+
+//----- (004627B7) --------------------------------------------------------
+void MainMenu_Loop()
+{
+    GUIButton *pButton; // eax@27
+    unsigned int pControlParam; // ecx@35
+    unsigned int pY; // [sp-18h] [bp-54h]@39
+    Texture *pTexture; // [sp-14h] [bp-50h]@39
+    GUIWindow *pWindow; // [sp+4h] [bp-38h]@11
+    MSG msg;
+
+    current_screen_type = SCREEN_GAME;
+
+    pGUIWindow2 = 0;
+    pAudioPlayer->StopChannels(-1, -1);
+    pMouse->RemoveHoldingItem();
+
+    pIcons_LOD->_inlined_sub2();
+
+    pWindow_MainMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_MainMenu, 0, 0);
+    Texture* pNew = pIcons_LOD->LoadTexturePtr("title_new", TEXTURE_16BIT_PALETTE);
+    Texture* pLoad = pIcons_LOD->LoadTexturePtr("title_load", TEXTURE_16BIT_PALETTE);
+    Texture* pCredits = pIcons_LOD->LoadTexturePtr("title_cred", TEXTURE_16BIT_PALETTE);
+    Texture* pExit = pIcons_LOD->LoadTexturePtr("title_exit", TEXTURE_16BIT_PALETTE);
+
+    pMainMenu_BtnNew = pWindow_MainMenu->CreateButton(495, 172, pNew->uTextureWidth, pNew->uTextureHeight, 1, 0, UIMSG_MainMenu_ShowPartyCreationWnd, 0, 'N', "", pNew, 0);
+    pMainMenu_BtnLoad = pWindow_MainMenu->CreateButton(495, 227, pLoad->uTextureWidth, pLoad->uTextureHeight, 1, 0, UIMSG_MainMenu_ShowLoadWindow, 1, 'L', "", pLoad, 0);
+    pMainMenu_BtnCredits = pWindow_MainMenu->CreateButton(495, 282, pCredits->uTextureWidth, pCredits->uTextureHeight, 1, 0, UIMSG_ShowCredits, 2, 'C', "", pCredits, 0);
+    pMainMenu_BtnExit = pWindow_MainMenu->CreateButton(495, 337, pExit->uTextureWidth, pExit->uTextureHeight, 1, 0, UIMSG_ExitToWindows, 3, 0, "", pExit, 0);
+
+    pTexture_PCX.Release();
+    pTexture_PCX.Load("title.pcx", 0);
+    SetCurrentMenuID(MENU_MAIN);
+    SetForegroundWindow(window->GetApiHandle());
+    SendMessageW(window->GetApiHandle(), WM_ACTIVATEAPP, 1, 0);
+    while (GetCurrentMenuID() == MENU_MAIN || GetCurrentMenuID() == MENU_SAVELOAD)
+    {
+        POINT pt;
+        pMouse->GetCursorPos(&pt);
+        pWindow = pWindow_MainMenu;
+        if (GetCurrentMenuID() == MENU_SAVELOAD)
+        {
+            if (current_screen_type != SCREEN_LOADGAME)
+            {
+                pTexture_PCX.Release();
+                pTexture_PCX.Load("lsave640.pcx", 0);
+                pGUIWindow2 = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_MainMenu, 0, 0);
+                current_screen_type = SCREEN_LOADGAME;
+                LoadUI_Load(0);
+            }
+            pWindow = pGUIWindow_CurrentMenu;
+        }
+
+        while (PeekMessageW(&msg, 0, 0, 0, PM_REMOVE))
+        {
+            if (msg.message == WM_QUIT)
+                Engine_DeinitializeAndTerminate(0);
+            TranslateMessage(&msg);
+            DispatchMessageW(&msg);
+        }
+
+        if (dword_6BE364_game_settings_1 & GAME_SETTINGS_APP_INACTIVE)
+        {
+            WaitMessage();
+            continue;
+        }
+
+        pRenderer->BeginScene();
+        pRenderer->DrawTextureNew(0, 0, &pTexture_PCX);
+
+        MainMenu_EventLoop();
+        GUI_UpdateWindows();
+
+        if (GetCurrentMenuID() != MENU_MAIN)
+        {
+            if (GetCurrentMenuID() == MENU_LoadingProcInMainMenu)
+            {
+                pIcons_LOD->RemoveTexturesPackFromTextureList();
+                pGUIWindow_CurrentMenu->Release();
+                pGUIWindow_CurrentMenu = 0;
+                current_screen_type = SCREEN_GAME;
+                viewparams->bRedrawGameUI = 1;
+            }
+        }
+        else
+        {
+            if (!pModalWindow)// ???
+            {
+                pButton = pWindow->pControlsHead;
+                for (pButton = pWindow->pControlsHead; pButton; pButton = pButton->pNext)
+                {
+                    if (pt.x >= (signed int)pButton->uX && pt.x <= (signed int)pButton->uZ
+                        && pt.y >= (signed int)pButton->uY && pt.y <= (signed int)pButton->uW
+                        && pWindow == pWindow_MainMenu)
+                    {
+                        pControlParam = pButton->msg_param;
+                        switch (pControlParam) // backlight for buttons
+                        {
+                        case 0:
+                            pTexture = pNew;
+                            pY = 172;
+                            break;
+                        case 1:
+                            pTexture = pLoad;
+                            pY = 227;
+                            break;
+                        case 2:
+                            pTexture = pCredits;
+                            pY = 282;
+                            break;
+                        case 3:
+                            pTexture = pExit;
+                            pY = 337;
+                            break;
+                        }
+                        pRenderer->DrawTextureIndexed(495, pY, pTexture);
+                    }
+                }
+            }
+        }
+        pRenderer->EndScene();
+        pRenderer->Present();
+    }
+    MainMenu_EventLoop();
+    pRenderer->BeginScene();
+    GUI_UpdateWindows();
+    pRenderer->EndScene();
+    pRenderer->Present();
+    pTexture_PCX.Release();
+    if (pGUIWindow2)
+    {
+        pGUIWindow2->Release();
+        pGUIWindow2 = 0;
+    }
+    pWindow_MainMenu->Release();
+    pIcons_LOD->RemoveTexturesPackFromTextureList();
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Game/MainMenu.h	Sun May 10 01:29:11 2015 +0200
@@ -0,0 +1,4 @@
+#pragma once
+
+void MainMenu_Loop();
+void MainMenu_EventLoop();
\ No newline at end of file
--- a/IO/Keyboard.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/IO/Keyboard.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,12 +3,13 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
+
+#include "Engine/Engine.h"
+
 #include "Keyboard.h"
 #include "GUI/GUIWindow.h"
-#include "Engine/Game.h"
 
 #include "Engine/Graphics/Vis.h"
-#include "Engine/MM7.h"
 #include "Engine/Objects/Actor.h"
 #include "Engine/Party.h"
 #include "Engine/Timer.h"
@@ -337,8 +338,8 @@
 
   //if ( pRenderer->pRenderD3D )
   {
-    pGame->PickKeyboard(Keyboard::IsKeyBeingHeld(VK_CONTROL), &vis_sprite_filter_3, &vis_door_filter);
-    int pid = pGame->pVisInstance->get_picked_object_zbuf_val();
+    pEngine->PickKeyboard(Keyboard::IsKeyBeingHeld(VK_CONTROL), &vis_sprite_filter_3, &vis_door_filter);
+    int pid = pEngine->pVisInstance->get_picked_object_zbuf_val();
     if ( pid != -1 )
       DoInteractionWithTopmostZObject(pid & 0xFFFF, PID_ID(pid));
     return;
@@ -461,8 +462,8 @@
   PartyAction partyAction; // [sp-14h] [bp-1Ch]@20
   InputAction inputAction; // [sp+0h] [bp-8h]@7
 
-  pGame->pKeyboardInstance->EnterCriticalSection();
-  Keyboard* pKeyboard = pGame->pKeyboardInstance;
+  pEngine->pKeyboardInstance->EnterCriticalSection();
+  Keyboard* pKeyboard = pEngine->pKeyboardInstance;
   if (!bAlwaysRun)
   {
     if (pKeyboard->IsShiftHeld())
@@ -485,17 +486,17 @@
   /*for ( uint i = 0; i < 30; ++i )
   {
     if ( pKeyActionMap->pToggleTypes[i] )
-      v14 = pGame->pKeyboardInstance->WasKeyPressed(pKeyActionMap->pVirtualKeyCodesMapping[i]);
+      v14 = pEngine->pKeyboardInstance->WasKeyPressed(pKeyActionMap->pVirtualKeyCodesMapping[i]);
     else
-      v14 = pGame->pKeyboardInstance->IsKeyBeingHeld(pKeyActionMap->pVirtualKeyCodesMapping[i]);
+      v14 = pEngine->pKeyboardInstance->IsKeyBeingHeld(pKeyActionMap->pVirtualKeyCodesMapping[i]);
     if ( v14 )
     {
-      if (pCurrentScreen == SCREEN_GAME)
+      if (current_screen_type == SCREEN_GAME)
       {
         pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Game_Action, 0, 0);
         continue;
       }
-      if ( pCurrentScreen == SCREEN_NPC_DIALOGUE || pCurrentScreen == SCREEN_BRANCHLESS_NPC_DIALOG )
+      if ( current_screen_type == SCREEN_NPC_DIALOGUE || current_screen_type == SCREEN_BRANCHLESS_NPC_DIALOG )
       {
         v15 = pMessageQueue_50CBD0->uNumMessages;
         if ( pMessageQueue_50CBD0->uNumMessages )
@@ -531,7 +532,7 @@
         switch ( inputAction )
         {
           case INPUT_MoveForward:
-            if (pCurrentScreen  != SCREEN_GAME)
+            if (current_screen_type  != SCREEN_GAME)
               break;
             if (!pParty->bTurnBasedModeOn)
             {
@@ -554,7 +555,7 @@
             }
             break;
           case INPUT_MoveBackwards:
-            if (pCurrentScreen  != SCREEN_GAME)
+            if (current_screen_type  != SCREEN_GAME)
               break;
             if (!pParty->bTurnBasedModeOn)
             {
@@ -577,7 +578,7 @@
             }
             break;
           case INPUT_StrafeLeft:
-            if (pCurrentScreen  != SCREEN_GAME)
+            if (current_screen_type  != SCREEN_GAME)
               break;
             if (!pParty->bTurnBasedModeOn)
             {
@@ -592,7 +593,7 @@
             pPartyActionQueue->Add(partyAction);
             break;
           case INPUT_StrafeRight:
-            if (pCurrentScreen != SCREEN_GAME)
+            if (current_screen_type != SCREEN_GAME)
               break;
             if (!pParty->bTurnBasedModeOn)
             {
@@ -607,7 +608,7 @@
             pPartyActionQueue->Add(partyAction);
             break;
           case INPUT_TurnLeft:
-            if (pCurrentScreen != SCREEN_GAME)
+            if (current_screen_type != SCREEN_GAME)
               break;
             if ( GetAsyncKeyState(VK_CONTROL) ) // strafing
             {
@@ -631,7 +632,7 @@
               pWeather->OnPlayerTurn(10);
             break;
           case INPUT_TurnRight:
-            if (pCurrentScreen != SCREEN_GAME)
+            if (current_screen_type != SCREEN_GAME)
               break;
             if ( GetAsyncKeyState(VK_CONTROL) )         // strafing
             {
@@ -655,20 +656,20 @@
               pWeather->OnPlayerTurn(-10);
             break;
           case INPUT_Jump:
-            if (pCurrentScreen != SCREEN_GAME || pParty->bTurnBasedModeOn)
+            if (current_screen_type != SCREEN_GAME || pParty->bTurnBasedModeOn)
               break;
             partyAction = (PartyAction)12;
             pPartyActionQueue->Add(partyAction);
             break;
           case INPUT_Yell:
-            if (!pCurrentScreen && uActiveCharacter)
+            if (!current_screen_type && uActiveCharacter)
             {
               pParty->Yell();
               pPlayers[uActiveCharacter]->PlaySound(SPEECH_Yell, 0);
             }
           break;
           case INPUT_Pass:
-            if ( pCurrentScreen )
+            if ( current_screen_type )
               break;
             if (pParty->bTurnBasedModeOn && pTurnEngine->turn_stage == TE_MOVEMENT)
             {
@@ -687,7 +688,7 @@
             }
             break;
           case INPUT_Combat://if press ENTER
-            if (pCurrentScreen == SCREEN_GAME)
+            if (current_screen_type == SCREEN_GAME)
             {
               if (pParty->bTurnBasedModeOn)
               {
@@ -706,7 +707,7 @@
             break;
           case INPUT_CastReady:
             {
-              if (pCurrentScreen != SCREEN_GAME)
+              if (current_screen_type != SCREEN_GAME)
                 break;
               if (pParty->bTurnBasedModeOn && pTurnEngine->turn_stage == TE_MOVEMENT)
               {
@@ -745,7 +746,7 @@
             }
             break;
           case INPUT_Attack:
-            if (pCurrentScreen != SCREEN_GAME)
+            if (current_screen_type != SCREEN_GAME)
               break;
             if (pParty->bTurnBasedModeOn == true && pTurnEngine->turn_stage == TE_MOVEMENT)
             {
@@ -755,12 +756,12 @@
             pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Attack, 0, 0);
             break;
           case INPUT_EventTrigger:
-            if (pCurrentScreen == SCREEN_GAME)
+            if (current_screen_type == SCREEN_GAME)
             {
               pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Game_Action, 0, 0);
               break;
             }
-            if ( pCurrentScreen == SCREEN_NPC_DIALOGUE )
+            if ( current_screen_type == SCREEN_NPC_DIALOGUE )
             {
               if ( pMessageQueue_50CBD0->uNumMessages )
               {
@@ -780,7 +781,7 @@
             }
             break;
           case INPUT_CharCycle:
-            if ( pCurrentScreen == SCREEN_SPELL_BOOK  )
+            if ( current_screen_type == SCREEN_SPELL_BOOK  )
               break;
 
             pMessageQueue_50C9E8->AddGUIMessage(UIMSG_CycleCharacters, 0, 0);
@@ -804,19 +805,19 @@
             pPartyActionQueue->Add(partyAction);
             break;
           case INPUT_FlyUp:
-            if ( pCurrentScreen || pEventTimer->bPaused )
+            if ( current_screen_type || pEventTimer->bPaused )
               break;
             partyAction = (PartyAction)13;
             pPartyActionQueue->Add(partyAction);
             break;
           case INPUT_Land:
-            if ( pCurrentScreen || pEventTimer->bPaused )
+            if ( current_screen_type || pEventTimer->bPaused )
               break;
             partyAction = (PartyAction)15;
             pPartyActionQueue->Add(partyAction);
             break;
           case INPUT_FlyDown:
-            if ( !pCurrentScreen && !pEventTimer->bPaused )
+            if ( !current_screen_type && !pEventTimer->bPaused )
             {
               partyAction = (PartyAction)14;
               pPartyActionQueue->Add(partyAction);
--- a/IO/Mouse.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/IO/Mouse.cpp	Sun May 10 01:29:11 2015 +0200
@@ -4,18 +4,17 @@
 
 #define _CRT_SECURE_NO_WARNINGS
 
-#include "Engine/mm7_data.h"
+#include "Engine/Engine.h"
+
 #include "Mouse.h"
 #include "Engine/Party.h"
 #include "Engine/LOD.h"
-#include "Engine/Game.h"
 
 #include "Engine/TurnEngine/TurnEngine.h"
 #include "Engine/Graphics/Viewport.h"
 #include "GUI/GUIWindow.h"
 #include "Engine/Graphics/Vis.h"
 #include "Engine/Objects/Actor.h"
-#include "Engine/MM7.h"
 #include "Media/Audio/AudioPlayer.h"
 
 
@@ -60,9 +59,9 @@
   if ( !this->bInitialized || !pName )
     return;
   if ( _stricmp("MICON2", pName) )//åñëè êóñîð íå ìèøåíü
-    pGame->uFlags2 &= 0xFFFFFFEF;
+    pEngine->uFlags2 &= 0xFFFFFFEF;
   else
-    pGame->uFlags2 |= 0x10;
+    pEngine->uFlags2 |= 0x10;
   if ( _stricmp(this->pCurrentCursorName, pName) )
     strcpy(this->pCurrentCursorName, pName);
   ClearCursor();
@@ -444,7 +443,7 @@
   unsigned int pX; // [sp+14h] [bp-8h]@7
   unsigned int pY; // [sp+18h] [bp-4h]@7
 
-  if ( pCurrentScreen == SCREEN_VIDEO || sub_4637E0_is_there_popup_onscreen() )
+  if ( current_screen_type == SCREEN_VIDEO || sub_4637E0_is_there_popup_onscreen() )
     return;
   if ( pGUIWindow2 && pGUIWindow2->ptr_1C == (void *)33 )
   {
@@ -467,7 +466,7 @@
 
   extern bool _507B98_ctrl_pressed;
   x = pX;
-  if ( GetCurrentMenuID() != -1 || pCurrentScreen != SCREEN_GAME || !_507B98_ctrl_pressed // stealing cursor
+  if ( GetCurrentMenuID() != -1 || current_screen_type != SCREEN_GAME || !_507B98_ctrl_pressed // stealing cursor
       || (signed int)pX < (signed int)pViewport->uViewportTL_X || (signed int)pX > (signed int)pViewport->uViewportBR_X
       || (signed int)pY < (signed int)pViewport->uViewportTL_Y || (signed int)pY > (signed int)pViewport->uViewportBR_Y)
   {
@@ -536,7 +535,7 @@
   }
   y = pY;
   //if ( pRenderer->pRenderD3D )
-    v5 = pGame->pVisInstance->get_picked_object_zbuf_val();
+    v5 = pEngine->pVisInstance->get_picked_object_zbuf_val();
   /*else
     v5 = pRenderer->pActiveZBuffer[pX + pSRZBufferLineOffsets[pY]];*/
 
@@ -615,7 +614,7 @@
         v12 = pWindowList[v3].field_34;
         if ( pWindowList[v3].pCurrentPosActiveItem - pWindowList[v3].pStartingPosActiveItem - v12 >= 0 )
         {
-          v8 = pCurrentScreen == SCREEN_PARTY_CREATION;
+          v8 = current_screen_type == SCREEN_PARTY_CREATION;
           pWindowList[v3].pCurrentPosActiveItem -= v12;
           if ( v8 )
           {
@@ -646,7 +645,7 @@
         v7 = pWindowList[v3].pCurrentPosActiveItem + pWindowList[v3].field_34;
         if ( v7 < pWindowList[v3].pNumPresenceButton + pWindowList[v3].pStartingPosActiveItem )
         {
-          v8 = pCurrentScreen == SCREEN_PARTY_CREATION;
+          v8 = current_screen_type == SCREEN_PARTY_CREATION;
           pWindowList[v3].pCurrentPosActiveItem = v7;
           if ( v8 )
           {
--- a/Media/Audio/AudioPlayer.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Media/Audio/AudioPlayer.cpp	Sun May 10 01:29:11 2015 +0200
@@ -1,14 +1,15 @@
 #define _CRTDBG_MAP_ALLOC
 #include <stdlib.h>
 #include <crtdbg.h>
+
 #define _CRT_SECURE_NO_WARNINGS
-
 #include <sstream>
+#include <string>
 
-#include <string>
+#include "Engine/Engine.h"
+
 #include "Engine/ZlibWrapper.h"
 
-#include "Engine/mm7_data.h"
 #include "../MediaPlayer.h"
 #include "AudioPlayer.h"
 #include "Engine/Tables/FrameTableInc.h"
@@ -16,20 +17,16 @@
 #include "Engine/Objects/SpriteObject.h"
 #include "Engine/Party.h"
 #include "Engine/Objects/Actor.h"
-#include "Engine/Game.h"
 #include "Engine/Graphics/DecorationList.h"
 #include "Engine/Timer.h"
 #include "Engine/OurMath.h"
 #include "Engine/MapInfo.h"
 #include "GUI/GUIWindow.h"
-#include "Engine/Log.h"
-#include "Engine/ErrorHandling.h"
 #include "Engine/Graphics/Level/Decoration.h"
 #include "Engine/Registry.h"
 
 #include "Media/Video/Bink_Smacker.h"
 
-#include "Engine/MM7.h"
 #include "Engine/MMT.h"
 
 
@@ -1207,7 +1204,7 @@
   if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
     sub_4AAEA6_transform(&pRenderVertexSoft);
   else
-    pGame->pIndoorCameraD3D->ViewTransform(&pRenderVertexSoft, 1);
+    pEngine->pIndoorCameraD3D->ViewTransform(&pRenderVertexSoft, 1);
   if ( pid )
   {
     if ( pid != -1 )
@@ -1340,7 +1337,7 @@
 		  }
 //LABEL_103:
 		  if ( uCurrentlyLoadedLevelType != LEVEL_Indoor )
-            pGame->pIndoorCameraD3D->ViewTransform(&pRenderVertexSoft, 1);
+            pEngine->pIndoorCameraD3D->ViewTransform(&pRenderVertexSoft, 1);
 //LABEL_104:
           AIL_start_3D_sample(*(int *)v42);
           AIL_set_3D_sample_float_distances(*(int **)v42, 100.0, 20.0, 100.0, 20.0);
@@ -1504,11 +1501,11 @@
             a1.vWorldPosition.z = v13->vPosition.z;
             if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
             {
-              v16 = pGame->pIndoorCameraD3D->fRotationXCosine;
-              v17 = pGame->pIndoorCameraD3D->fRotationXSine;
-              v55 = pGame->pIndoorCameraD3D->fRotationYCosine;
-              v56 = pGame->pIndoorCameraD3D->fRotationYSine;
-              if (pGame->pIndoorCameraD3D->sRotationX)
+              v16 = pEngine->pIndoorCameraD3D->fRotationXCosine;
+              v17 = pEngine->pIndoorCameraD3D->fRotationXSine;
+              v55 = pEngine->pIndoorCameraD3D->fRotationYCosine;
+              v56 = pEngine->pIndoorCameraD3D->fRotationYSine;
+              if (pEngine->pIndoorCameraD3D->sRotationX)
               {
                 v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
                 *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
@@ -1546,7 +1543,7 @@
               }
             }
             else
-              pGame->pIndoorCameraD3D->ViewTransform(&a1, 1);
+              pEngine->pIndoorCameraD3D->ViewTransform(&a1, 1);
             v58 = a1.vWorldViewPosition.y * -0.012207031;
             v22 = a1.vWorldViewPosition.x * 0.012207031;
             *(float *)&uNumRepeats = v22;
@@ -1575,11 +1572,11 @@
             a1.vWorldPosition.z = v11;
             if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
             {
-              v16 = pGame->pIndoorCameraD3D->fRotationXCosine;
-              v17 = pGame->pIndoorCameraD3D->fRotationXSine;
-              v55 = pGame->pIndoorCameraD3D->fRotationYCosine;
-              v56 = pGame->pIndoorCameraD3D->fRotationYSine;
-              if (pGame->pIndoorCameraD3D->sRotationX)
+              v16 = pEngine->pIndoorCameraD3D->fRotationXCosine;
+              v17 = pEngine->pIndoorCameraD3D->fRotationXSine;
+              v55 = pEngine->pIndoorCameraD3D->fRotationYCosine;
+              v56 = pEngine->pIndoorCameraD3D->fRotationYSine;
+              if (pEngine->pIndoorCameraD3D->sRotationX)
               {
                 v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
                 *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
@@ -1617,7 +1614,7 @@
               }
             }
             else
-              pGame->pIndoorCameraD3D->ViewTransform(&a1, 1);
+              pEngine->pIndoorCameraD3D->ViewTransform(&a1, 1);
             v58 = a1.vWorldViewPosition.y * -0.012207031;
             v22 = a1.vWorldViewPosition.x * 0.012207031;
             *(float *)&uNumRepeats = v22;
@@ -1649,11 +1646,11 @@
         a1.vWorldPosition.z = v11;
         if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
         {
-          v16 = pGame->pIndoorCameraD3D->fRotationXCosine;
-          v17 = pGame->pIndoorCameraD3D->fRotationXSine;
-          v55 = pGame->pIndoorCameraD3D->fRotationYCosine;
-          v56 = pGame->pIndoorCameraD3D->fRotationYSine;
-          if (pGame->pIndoorCameraD3D->sRotationX)
+          v16 = pEngine->pIndoorCameraD3D->fRotationXCosine;
+          v17 = pEngine->pIndoorCameraD3D->fRotationXSine;
+          v55 = pEngine->pIndoorCameraD3D->fRotationYCosine;
+          v56 = pEngine->pIndoorCameraD3D->fRotationYSine;
+          if (pEngine->pIndoorCameraD3D->sRotationX)
           {
             v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
             *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
@@ -1691,7 +1688,7 @@
           }
         }
         else
-          pGame->pIndoorCameraD3D->ViewTransform(&a1, 1);
+          pEngine->pIndoorCameraD3D->ViewTransform(&a1, 1);
         v58 = a1.vWorldViewPosition.y * -0.012207031;
         v22 = a1.vWorldViewPosition.x * 0.012207031;
         *(float *)&uNumRepeats = v22;
@@ -1714,7 +1711,7 @@
       }
       if ( uCurrentlyLoadedLevelType != LEVEL_Indoor )//==1
       {
-        pGame->pIndoorCameraD3D->ViewTransform(&a1, 1);
+        pEngine->pIndoorCameraD3D->ViewTransform(&a1, 1);
         v58 = a1.vWorldViewPosition.y * -0.012207031;
         v22 = a1.vWorldViewPosition.x * 0.012207031;
         *(float *)&uNumRepeats = v22;
@@ -1747,11 +1744,11 @@
         a1.vWorldPosition.z = v11;
         if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
         {
-          v16 = pGame->pIndoorCameraD3D->fRotationXCosine;
-          v17 = pGame->pIndoorCameraD3D->fRotationXSine;
-          v55 = pGame->pIndoorCameraD3D->fRotationYCosine;
-          v56 = pGame->pIndoorCameraD3D->fRotationYSine;
-          if (pGame->pIndoorCameraD3D->sRotationX)
+          v16 = pEngine->pIndoorCameraD3D->fRotationXCosine;
+          v17 = pEngine->pIndoorCameraD3D->fRotationXSine;
+          v55 = pEngine->pIndoorCameraD3D->fRotationYCosine;
+          v56 = pEngine->pIndoorCameraD3D->fRotationYSine;
+          if (pEngine->pIndoorCameraD3D->sRotationX)
           {
             v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
             *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
@@ -1789,7 +1786,7 @@
           }
         }
         else
-          pGame->pIndoorCameraD3D->ViewTransform(&a1, 1);
+          pEngine->pIndoorCameraD3D->ViewTransform(&a1, 1);
         v58 = a1.vWorldViewPosition.y * -0.012207031;
         v22 = a1.vWorldViewPosition.x * 0.012207031;
         *(float *)&uNumRepeats = v22;
@@ -1958,7 +1955,7 @@
     } */
   }
 
-  if (pCurrentScreen != SCREEN_GAME) //îòêëþ÷åíèå çâóêà äåêîðàöèé ïðè ïåðåêëþ÷åíèè îêíà èãðû
+  if (current_screen_type != SCREEN_GAME) //îòêëþ÷åíèå çâóêà äåêîðàöèé ïðè ïåðåêëþ÷åíèè îêíà èãðû
   {
     if (AIL_sample_status(pMixerChannels[4].hSample) == AIL::Sample::Playing)
       AIL_end_sample(pMixerChannels[4].hSample);
--- a/Media/Audio/OpenALSoundProvider.h	Sat May 09 12:55:58 2015 +0200
+++ b/Media/Audio/OpenALSoundProvider.h	Sun May 10 01:29:11 2015 +0200
@@ -3,8 +3,19 @@
 #include "lib/OpenAL/alc.h"
 #pragma comment(lib, "OpenAL32.lib")
 
-#include "Engine/stuff.h"
-#include "Engine/Log.h"
+#include "Engine/Engine.h"
+
+void log(char *format, ...)
+{
+    va_list va;
+    va_start(va, format);
+    char msg[256];
+    vsprintf(msg, format, va);
+    va_end(va);
+    DWORD w;
+
+    WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), msg, strlen(msg), &w, 0);
+}
 
 class OpenALSoundProvider
 {
--- a/Media/MediaPlayer.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/Media/MediaPlayer.cpp	Sun May 10 01:29:11 2015 +0200
@@ -7,23 +7,24 @@
 
 #define _CRT_SECURE_NO_WARNINGS
 
+#include "Engine/Engine.h"
 
 #include "IO/Mouse.h"
 #include "GUI/GUIWindow.h"
-#include "Engine/mm7_data.h"
 #include "Media/Audio/OpenALSoundProvider.h"
-#include "Engine/Log.h"
 #include "MediaPlayer.h"
 #include "Media/Video/Bink_Smacker.h"
 #include "Media/Audio/AudioPlayer.h"
 #include "Engine/Timer.h"
 #include "Engine/Graphics/Render.h"
-#include "Engine/Game.h"
 #include "Engine/MMT.h"
 
+#include "Game/MainMenu.h"
+
 
 #pragma comment(lib, "Version.lib")
 
+
 using namespace Media;
 
 Media::MPlayer *pMediaPlayer = nullptr;
@@ -1131,7 +1132,7 @@
     bPlaying_Movie = 1;
     field_44 = v4;
     pRenderer->ClearTarget(0);
-    pCurrentScreen = SCREEN_VIDEO;
+    current_screen_type = SCREEN_VIDEO;
 
     auto hwnd = pMediaPlayer->window->GetApiHandle();
 
@@ -1157,7 +1158,7 @@
       while (PeekMessageA(&Msg, hwnd, 0, 0, PM_REMOVE))
       {
         if (Msg.message == WM_QUIT)
-          Game_DeinitializeAndTerminate(0);
+          Engine_DeinitializeAndTerminate(0);
         if (Msg.message == WM_PAINT)
           break;
         TranslateMessage(&Msg);
@@ -1192,7 +1193,7 @@
         BitBlt(dc, 0, 0, client_width, client_height, back_dc, 0, 0, SRCCOPY);
       }
 
-      GUI_MainMenuMessageProc();  
+      MainMenu_EventLoop();  
 
       if (pMediaPlayer->bStopBeforeSchedule == 1)
         Sleep(1000); 
@@ -1205,14 +1206,14 @@
     pMediaPlayer->Unload();
 
     //if (a4 == 1)
-      pCurrentScreen = SCREEN_GAME;
+      current_screen_type = SCREEN_GAME;
 
     pMediaPlayer->bPlaying_Movie = false;
 
     ShowCursor(1);
 
-    /*if ( pCurrentScreen == SCREEN_VIDEO )
-      pCurrentScreen = SCREEN_GAME;*/
+    /*if ( current_screen_type == SCREEN_VIDEO )
+      current_screen_type = SCREEN_GAME;*/
 }
 
 void MPlayer::HouseMovieLoop()
--- a/Media/MediaPlayer.h	Sat May 09 12:55:58 2015 +0200
+++ b/Media/MediaPlayer.h	Sun May 10 01:29:11 2015 +0200
@@ -1,7 +1,9 @@
 #pragma once
 #include "OSWindow.h"
+
+#include "Engine/Engine.h"
+
 #include "Engine/Graphics/Texture.h"
-#include "Engine/ErrorHandling.h"
 
 #pragma pack(push, 1)
 
--- a/OSWindow.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/OSWindow.cpp	Sun May 10 01:29:11 2015 +0200
@@ -5,31 +5,30 @@
 #define _CRT_SECURE_NO_WARNINGS
 
 #include "OSWindow.h"
-#include "Engine/mm7_data.h"
+
+#include "Engine/Engine.h"
+
 #include "Arcomage\Arcomage.h"
 #include "Media/Audio/AudioPlayer.h"
 #include "IO/Mouse.h"
 #include "Engine/Timer.h"
 #include "GUI/GUIWindow.h"
 #include "Engine/Party.h"
-#include "Engine/Game.h"
 #include "Engine/Graphics/IndoorCameraD3D.h"
 #include "IO/Keyboard.h"
 #include "Engine/Graphics/Viewport.h"
 #include "Engine/Graphics/Vis.h"
 #include "Media/Audio/AIL.h"
-#include "Engine/ErrorHandling.h"
-#include "Engine/Log.h"
 #include "Engine/Registry.h"
 #include "Engine/MMT.h"
 
 
-bool wizard_eye = false;         //âêëþ÷èòü íà ïîñòîÿííî îêî ÷àðîäåÿ
-bool change_seasons = false;     //ñìåíà âðåì¸í ãîäà
-bool all_magic = false;           //âêëþ÷èòü âñþ ìàãèþ
-bool debug_information = false;  //èíôîðìàöèÿ fps, ïîëîæåíèå ãðóïïû, óðîâåíü ïîëà è ò.ï.
-bool show_picked_face = false;   //âûäåëèòü àêòèâíûé ôåéñ
-bool draw_portals_loops = false;    //âèäíû ðàìêè ïîðòàëîâ
+bool wizard_eye = false;          // wizard eye always on / âêëþ÷èòü íà ïîñòîÿííî îêî ÷àðîäåÿ
+bool change_seasons = false;      // toggle seasons change / ñìåíà âðåì¸í ãîäà
+bool all_magic = false;           // toggle full spellbook / âêëþ÷èòü âñþ ìàãèþ
+bool debug_information = false;   // toggle debug info / èíôîðìàöèÿ fps, ïîëîæåíèå ãðóïïû, óðîâåíü ïîëà è ò.ï.
+bool show_picked_face = false;    // highlight picked face / âûäåëèòü àêòèâíûé ôåéñ
+bool draw_portals_loops = false;  // show portal frames / âèäíû ðàìêè ïîðòàëîâ
 bool new_speed = false;
 bool bSnow = false;
 bool draw_terrain_dist_mist = false;//íîâàÿ äàëüíîñòü îòðèñîâêè òàéëîâ
@@ -47,8 +46,8 @@
   if (GetCurrentMenuID() == MENU_CREATEPARTY)
     Mouse::UI_OnKeyDown(VK_SELECT);
 
-  if (pGame)
-    pGame->PickMouse(512.0, x, y, false, &vis_sprite_filter_3, &vis_door_filter);
+  if (pEngine)
+    pEngine->PickMouse(512.0, x, y, false, &vis_sprite_filter_3, &vis_door_filter);
 
   Mouse::UI_OnMouseLeftClick(0);
   return true;
@@ -64,8 +63,8 @@
 
   pMouse->SetMouseClick(x, y);
 
-  if (pGame)
-    pGame->PickMouse(pGame->pIndoorCameraD3D->GetPickDepth(), x, y, 0, &vis_sprite_filter_2, &vis_door_filter);
+  if (pEngine)
+    pEngine->PickMouse(pEngine->pIndoorCameraD3D->GetPickDepth(), x, y, 0, &vis_sprite_filter_2, &vis_door_filter);
 
   UI_OnMouseRightClick(0);
   return true;
@@ -190,9 +189,9 @@
     return false;
 
     /*case WM_MBUTTONDOWN:
-      if (pRenderer->pRenderD3D && pGame)
+      if (pRenderer->pRenderD3D && pEngine)
       {
-        pGame->PickMouse(pGame->pIndoorCameraD3D->GetPickDepth(), LOWORD(lParam), HIWORD(lParam), 1, &vis_sprite_filter_3, &vis_face_filter);
+        pEngine->PickMouse(pEngine->pIndoorCameraD3D->GetPickDepth(), LOWORD(lParam), HIWORD(lParam), 1, &vis_sprite_filter_3, &vis_face_filter);
       }
       return false;*/
 
@@ -251,14 +250,14 @@
         }
         if ( wparam >= VK_LEFT && wparam <= VK_DOWN )
         {
-          if ( pCurrentScreen != SCREEN_GAME && pCurrentScreen != SCREEN_MODAL_WINDOW )
+          if ( current_screen_type != SCREEN_GAME && current_screen_type != SCREEN_MODAL_WINDOW )
           {
             if ( !viewparams->field_4C )
               Mouse::UI_OnKeyDown(wparam);
             return 0;
           }
         }
-        if ( pCurrentScreen != SCREEN_GAME && pCurrentScreen != SCREEN_MODAL_WINDOW )
+        if ( current_screen_type != SCREEN_GAME && current_screen_type != SCREEN_MODAL_WINDOW )
           return 0;
       }
 
@@ -793,7 +792,7 @@
     //case 103:  pRenderer->SavePCXScreenshot(); break;
     case 101:  // Quit game
     case 40001: // Menu "File"-> "Exit"
-      pGame->Deinitialize();
+      pEngine->Deinitialize();
       SendMessageW(api_handle, WM_DESTROY, 0, 0);
     break;
 
--- a/_deleted.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/_deleted.cpp	Sun May 10 01:29:11 2015 +0200
@@ -984,7 +984,7 @@
         v28 = v8;
         v27 = (const char *)v5;
         v44 = 10000;
-        pGame->pLightmapBuilder->_45CB89(v5, v8);
+        pEngine->pLightmapBuilder->_45CB89(v5, v8);
         if ( v8 > 0 )
         {
           v9 = a3;
@@ -1185,8 +1185,8 @@
   v28 = v3->sTextureDeltaU << 16;
   v35 = v3->sTextureDeltaV << 16;
   v10 = v2->field_8;
-  v29 = pGame->pIndoorCameraD3D->int_sine_y;
-  v32 = pGame->pIndoorCameraD3D->int_cosine_y;
+  v29 = pEngine->pIndoorCameraD3D->int_sine_y;
+  v32 = pEngine->pIndoorCameraD3D->int_cosine_y;
   a1.field_28 = v2->field_C;
   v11 = v3->field_24;
   v37 = pODMRenderParams->int_fov_rad_inv * (pViewport->uScreenCenterX - v10);
@@ -1281,7 +1281,7 @@
   a1.field_C = v32 - 1;
   a1.field_8 = (v25 << 16) - 65536;
   a1.field_34_palette = (unsigned __int16 *)sr_sub_485E1F(&a2, v2, v38, v3, pODMRenderParams->building_gamme, 1u, 1);
-  if ( byte_4D864C && BYTE1(pGame->uFlags) & 8 )
+  if ( byte_4D864C && BYTE1(pEngine->uFlags) & 8 )
     sr_sub_485975(&a1, (stru315 *)&a2);
   else
     sr_sub_4D6FB0(v1);
@@ -1437,7 +1437,7 @@
             *((float *)v9 - 1) = v11;
             if ( *(float *)&v84 == v11 )
               ++v82;
-            pGame->pIndoorCameraD3D->ViewTransform((RenderVertexSoft *)(v9 - 12), 1u);
+            pEngine->pIndoorCameraD3D->ViewTransform((RenderVertexSoft *)(v9 - 12), 1u);
             if ( *(float *)v9 < 8.0 || (double)pODMRenderParams->shading_dist_mist < *(float *)v9 )
             {
               if ( *(float *)v9 >= 8.0 )
@@ -1447,7 +1447,7 @@
             }
             else
             {
-              pGame->pIndoorCameraD3D->Project((RenderVertexSoft *)(v9 - 12), 1u, 0);
+              pEngine->pIndoorCameraD3D->Project((RenderVertexSoft *)(v9 - 12), 1u, 0);
             }
             v81 += 2;
             v9 += 48;
@@ -1570,7 +1570,7 @@
         
         static stru154 static_sub_004789DE_stru_73C818; // idb
 
-        pGame->pLightmapBuilder->ApplyLights_OutdoorFace((ODMFace *)v3);
+        pEngine->pLightmapBuilder->ApplyLights_OutdoorFace((ODMFace *)v3);
         if ( stru_F8AD28.uNumLightsApplied <= 0 )
         {
           v12->field_108 = 0;
@@ -1584,7 +1584,7 @@
           v55 = static_sub_004789DE_stru_73C818.face_plane.vNormal.x;
           v56 = static_sub_004789DE_stru_73C818.face_plane.vNormal.y;
           v57 = static_sub_004789DE_stru_73C818.face_plane.vNormal.z;
-          pGame->pLightmapBuilder->_45CA88(&stru_F8AD28, array_50AC10, v26, (Vec3_float_ *)&v55);
+          pEngine->pLightmapBuilder->_45CA88(&stru_F8AD28, array_50AC10, v26, (Vec3_float_ *)&v55);
         }
         if ( v74 )
         {
@@ -2334,8 +2334,8 @@
     v8 = v3->ptr_38;
     v42 = ((unsigned __int64)(v3->ptr_38->field_14 * (signed __int64)v7) >> 16) + v8->field_C;
     v40 = ((unsigned __int64)(v8->field_20 * (signed __int64)v7) >> 16) + v3->ptr_38->field_18;
-    v38 = pGame->pIndoorCameraD3D->int_sine_y;
-    HIDWORD(v35) = pGame->pIndoorCameraD3D->int_cosine_y;
+    v38 = pEngine->pIndoorCameraD3D->int_sine_y;
+    HIDWORD(v35) = pEngine->pIndoorCameraD3D->int_cosine_y;
     v45 = v4->field_C;
     v9 = ((unsigned __int64)(v3->v_18.z * (signed __int64)v7) >> 16) + v3->v_18.x;
     v10 = 65536 / SLODWORD(v35) * (pViewport->uScreenCenterX - v4->field_8);
@@ -2684,7 +2684,7 @@
           a1.field_4 = (((v68 + v57) >> v27) - a1.field_30) >> v74;
           a1.field_0 = v58;
           a1.field_28 = v83;
-          if ( byte_4D864C && BYTE1(pGame->uFlags) & 8 )
+          if ( byte_4D864C && BYTE1(pEngine->uFlags) & 8 )
           {
             if ( v3->pODMFace->uPolygonType == 1 )
               sr_sub_485BAE(&a1, &a2);
@@ -2740,7 +2740,7 @@
           a1.field_4 = (((v68 + v63) >> v27) - a1.field_30) >> v74;
           a1.field_0 = v64;
           a1.field_28 = v81;
-          if ( byte_4D864C && BYTE1(pGame->uFlags) & 8 )
+          if ( byte_4D864C && BYTE1(pEngine->uFlags) & 8 )
           {
             if ( v3->pODMFace->uPolygonType == 1 )
               sr_sub_485BAE(&a1, &a2);
@@ -2823,7 +2823,7 @@
           a1.field_4 = (((v68 + v38) >> v27) - a1.field_30) >> v74;
           a1.field_0 = v39;
           a1.field_28 = v83;
-          if ( byte_4D864C && BYTE1(pGame->uFlags) & 8 )
+          if ( byte_4D864C && BYTE1(pEngine->uFlags) & 8 )
           {
             if ( v3->pODMFace->uPolygonType == 1 )
               sr_sub_485A24(&a1, (stru315 *)&a2);
@@ -2879,7 +2879,7 @@
           a1.field_4 = (((v68 + v44) >> v27) - a1.field_30) >> v74;
           a1.field_0 = v45;
           a1.field_28 = v81;
-          if ( byte_4D864C && BYTE1(pGame->uFlags) & 8 )
+          if ( byte_4D864C && BYTE1(pEngine->uFlags) & 8 )
           {
             if ( v3->pODMFace->uPolygonType == 1 )
               sr_sub_485A24(&a1, (stru315 *)&a2);
@@ -3202,7 +3202,7 @@
               WorldPosToGridCellX(v101),
               WorldPosToGridCellZ(v100),
               !byte_4D864C)
-          || !(pGame->uFlags & 0x80))
+          || !(pEngine->uFlags & 0x80))
          && !_481EFA_clip_terrain_poly(v10, v11, v102, v103, 1)) )
         goto LABEL_105;
       if ( v10->vWorldPosition.z != v11->vWorldPosition.z
@@ -3269,16 +3269,16 @@
         array_50AC10[3]._rhw = 1.0 / v29;
         array_50AC10[3].u = 1.0;
         array_50AC10[3].v = 0.0;
-        pGame->pLightmapBuilder->StackLights_TerrainFace(pNormal, &a3a, array_50AC10, 4u, 1);
+        pEngine->pLightmapBuilder->StackLights_TerrainFace(pNormal, &a3a, array_50AC10, 4u, 1);
         if ( stru_F8AD28.uNumLightsApplied <= 0 )
         {
           v17->field_108 = 0;
         }
         else
         {
-          v30 = pGame;
+          v30 = pEngine;
           v17->field_108 = 1;
-          pGame->pLightmapBuilder->_45CA88(&stru_F8AD28, array_50AC10, 4, pNormal);
+          pEngine->pLightmapBuilder->_45CA88(&stru_F8AD28, array_50AC10, 4, pNormal);
         }
         if ( v104->vWorldViewPosition.x < 8.0
           || *(float *)(HIDWORD(v101) + 12) < 8.0
@@ -3385,16 +3385,16 @@
     array_50AC10[2]._rhw = 1.0 / v50;
     array_50AC10[2].u = 1.0;
     array_50AC10[2].v = 1.0;
-    pGame->pLightmapBuilder->StackLights_TerrainFace(pNormala, &v78, array_50AC10, 3u, 0);
+    pEngine->pLightmapBuilder->StackLights_TerrainFace(pNormala, &v78, array_50AC10, 3u, 0);
     if ( stru_F8AD28.uNumLightsApplied <= 0 )
     {
       v38->field_108 = 0;
     }
     else
     {
-      v51 = pGame;
+      v51 = pEngine;
       v38->field_108 = 1;
-      pGame->pLightmapBuilder->_45CA88(&stru_F8AD28, array_50AC10, 3, pNormala);
+      pEngine->pLightmapBuilder->_45CA88(&stru_F8AD28, array_50AC10, 3, pNormala);
     }
     if ( v104->vWorldViewPosition.x < 8.0
       || *(float *)(HIDWORD(v101) + 12) < 8.0
@@ -3479,16 +3479,16 @@
           array_50AC10[2]._rhw = 1.0 / v64;
           array_50AC10[2].u = 1.0;
           array_50AC10[2].v = 0.0;
-          pGame->pLightmapBuilder->StackLights_TerrainFace(pNormalb, &v70, array_50AC10, 3u, 1);
+          pEngine->pLightmapBuilder->StackLights_TerrainFace(pNormalb, &v70, array_50AC10, 3u, 1);
           if ( stru_F8AD28.uNumLightsApplied <= 0 )
           {
             v17->field_108 = 0;
           }
           else
           {
-            v65 = pGame;
+            v65 = pEngine;
             v17->field_108 = 1;
-            pGame->pLightmapBuilder->_45CA88(&stru_F8AD28, array_50AC10, 3, pNormalb);
+            pEngine->pLightmapBuilder->_45CA88(&stru_F8AD28, array_50AC10, 3, pNormalb);
           }
           if ( v104->vWorldViewPosition.x < 8.0 || v103->vWorldViewPosition.x < 8.0 || v102->vWorldViewPosition.x < 8.0 )
           {
@@ -3964,7 +3964,7 @@
   if ( v10 == 1 )
   {
     v11 = 1;
-    if ( byte_4D864C && BYTE1(pGame->uFlags) & 0x10 )
+    if ( byte_4D864C && BYTE1(pEngine->uFlags) & 0x10 )
     {
       v12 = 0;
     }
@@ -4030,7 +4030,7 @@
   a3a = 1;
   if ( a4 )
   {
-    v5 = pGame->_44ED0A(a1, &a3a, 31);
+    v5 = pEngine->_44ED0A(a1, &a3a, 31);
     if ( v5 != -1 )
       a3 = v5;
   }
@@ -4342,7 +4342,7 @@
   }
   else
   {
-    v6 = pGame->_44EC23(a1, &a3a, a4);
+    v6 = pEngine->_44EC23(a1, &a3a, a4);
     if ( v6 == -1 )
       v6 = a3;
     if ( v9 == 1 )
@@ -4385,7 +4385,7 @@
   }
   else
   {
-    v6 = pGame->_44EC23(a1, &a2a, a4);
+    v6 = pEngine->_44EC23(a1, &a2a, a4);
     if ( v6 != -1 )
       a3 = v6;
     if ( v9 == 1 )
@@ -4664,7 +4664,7 @@
                 }
 LABEL_24:
                 v135 = 1;
-                pGame->_44ED0A(v2, &v135, 31);
+                pEngine->_44ED0A(v2, &v135, 31);
                 v104 = sr_sub_47C24C_get_palette(v2, v109, 0, 1);
                 v134 = stru_F8AD28.field_44;
                 v106 = stru_F8AD28.field_48;
@@ -5349,7 +5349,7 @@
     v1 = array_77EC08.data();
     do
     {
-      result = pGame->pLightmapBuilder->_45D3C7_sw(v1);
+      result = pEngine->pLightmapBuilder->_45D3C7_sw(v1);
       ++v0;
       ++v1;
     }
@@ -5822,7 +5822,7 @@
         a1.field_30 = v30 + 4 * stru_5C6E00->Cos(v81 + (v68 >> v66));
         v44 = stru_5C6E00->Sin(v81 + (v30 >> v66));
         a1.field_2C = v68 + 4 * v44;
-        if ( byte_4D864C && BYTE1(pGame->uFlags) & 8 )
+        if ( byte_4D864C && BYTE1(pEngine->uFlags) & 8 )
           sr_sub_485975(&a1, (stru315 *)&a2);
         else
           sr_sub_4D6FB0(v2);
@@ -5886,7 +5886,7 @@
         a1.field_4 = ((v56 >> v76) - v30) >> 4;
         a1.field_0 = ((signed int)v58 - v68) >> 4;
         a1.field_28 = v72;
-        if ( byte_4D864C && BYTE1(pGame->uFlags) & 8 )
+        if ( byte_4D864C && BYTE1(pEngine->uFlags) & 8 )
           sr_sub_485975(&a1, (stru315 *)&a2);
         else
           sr_sub_4D6FB0(v2);
@@ -6059,7 +6059,7 @@
   a1.field_10 = v44 - v31->uWidthLn2 + 16;
   a1.field_C = v32;
   a1.field_8 = v33;
-  if ( byte_4D864C && BYTE1(pGame->uFlags) & 8 )
+  if ( byte_4D864C && BYTE1(pEngine->uFlags) & 8 )
   {
     if ( byte_80AA10 )
       sr_sub_485A24(&a1, (stru315 *)&a2);
@@ -6223,7 +6223,7 @@
   v35.field_10 = v20 - v27->uWidthLn2 + 16;
   v35.field_C = v28 - 1;
   v35.field_8 = (v29 << 16) - 65536;
-  if ( byte_4D864C && BYTE1(pGame->uFlags) & 8 )
+  if ( byte_4D864C && BYTE1(pEngine->uFlags) & 8 )
   {
     if ( byte_80AA10 )
       sr_sub_485D3E(&v35, &v34);
@@ -6471,7 +6471,7 @@
     v77 = v37 / (v73 << 16);
     sr.field_0 = v37 / (v73 << 16);
     sr.field_28 = v73;
-    if ( byte_4D864C && BYTE1(pGame->uFlags) & 8 )
+    if ( byte_4D864C && BYTE1(pEngine->uFlags) & 8 )
     {
       if ( byte_80AA10 )
         sr_sub_485A24(&sr, (stru315 *)&sr2);
@@ -6527,7 +6527,7 @@
     v49 = (((v79 - v4->ptr_38->field_28) >> v78) - sr.field_2C) >> v69;
     sr.field_4 = ((v48 >> v78) - sr.field_30) >> v69;
     sr.field_0 = v49;
-    if ( byte_4D864C && BYTE1(pGame->uFlags) & 8 )
+    if ( byte_4D864C && BYTE1(pEngine->uFlags) & 8 )
     {
       if ( byte_80AA10 )
         sr_sub_485A24(&sr, (stru315 *)&sr2);
@@ -6583,7 +6583,7 @@
       sr.field_4 = ((v58 >> v78) - sr.field_30) >> v69;
       sr.field_0 = v59;
       sr.field_28 = v62;
-      if ( byte_4D864C && BYTE1(pGame->uFlags) & 8 )
+      if ( byte_4D864C && BYTE1(pEngine->uFlags) & 8 )
       {
         if ( byte_80AA10 )
           sr_sub_485A24(&sr, (stru315 *)&sr2);
@@ -6782,7 +6782,7 @@
     {
       a1a.field_30 = v30 + 4 * stru_5C6E00->Cos(X + (v31 >> v39));
       a1a.field_2C = v31 + 4 * stru_5C6E00->Sin(X + (v30 >> i));
-      if ( byte_4D864C && BYTE1(pGame->uFlags) & 8 )
+      if ( byte_4D864C && BYTE1(pEngine->uFlags) & 8 )
         sr_sub_485975(&a1a, (stru315 *)&a2);
       else
         sr_sub_4D6FB0(v1);
@@ -6800,7 +6800,7 @@
     a1a.field_30 = v30 + 4 * stru_5C6E00->Cos(X + (v31 >> (12 - v49)));
     a1a.field_2C = v31 + 4 * stru_5C6E00->Sin(X + (v30 >> i));
     a1a.field_28 = v48;
-    if ( byte_4D864C && BYTE1(pGame->uFlags) & 8 )
+    if ( byte_4D864C && BYTE1(pEngine->uFlags) & 8 )
       sr_sub_485975(&a1a, (stru315 *)&a2);
     else
       sr_sub_4D6FB0(v1);
@@ -8796,78 +8796,78 @@
   stru_F8AD28.uDefaultAmbientLightLevel = v2->field_22;
   if ( pBLVRenderParams->sPartyRotX )
   {
-    v74 = (unsigned __int64)(stru_F8AD28.plane_4.vNormal.y * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16;
-    v74 = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16) - v74;
-    X = (unsigned __int64)(stru_F8AD28.plane_4.vNormal.z * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16;
-    stru_F8AD28.rotated_normal.x = ((unsigned __int64)(v74 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16) - X;
+    v74 = (unsigned __int64)(stru_F8AD28.plane_4.vNormal.y * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16;
+    v74 = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16) - v74;
+    X = (unsigned __int64)(stru_F8AD28.plane_4.vNormal.z * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_x) >> 16;
+    stru_F8AD28.rotated_normal.x = ((unsigned __int64)(v74 * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_x) >> 16) - X;
     stru_F8AD28.rotated_normal.y = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x
-                                                     * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16)
+                                                     * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16)
                                  + ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.y
-                                                     * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16);
-    stru_F8AD28.rotated_normal.z = ((unsigned __int64)(v74 * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16)
+                                                     * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16);
+    stru_F8AD28.rotated_normal.z = ((unsigned __int64)(v74 * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_x) >> 16)
                                  + ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.z
-                                                     * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16);
-    v70 = (unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16;
-    v74 = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16) - v70;
-    v70 = (unsigned __int64)(stru_F8AD28.vec_14.z * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16;
-    stru_F8AD28.vec_60.y = ((unsigned __int64)(v74 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16) - v70;
-    stru_F8AD28.vec_60.z = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16)
-                         + ((unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16);
-    stru_F8AD28.field_6C = ((unsigned __int64)(v74 * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16)
-                         + ((unsigned __int64)(stru_F8AD28.vec_14.z * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16);
-    v70 = (unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16;
-    v74 = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16) - v70;
-    X = (unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16;
-    v72 = (unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16;
-    v70 = (unsigned __int64)(stru_F8AD28.vec_20.z * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16;
-    stru_F8AD28.vec_70.x = ((unsigned __int64)(v74 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16) - v70;
-    stru_F8AD28.vec_70.y = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16)
-                         + ((unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16);
-    stru_F8AD28.vec_70.z = ((unsigned __int64)(v74 * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16)
-                         + ((unsigned __int64)(stru_F8AD28.vec_20.z * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16);
-    v74 = pGame->pIndoorCameraD3D->int_sine_y * pBLVRenderParams->vPartyPos.y
-        - pGame->pIndoorCameraD3D->int_cosine_y * pBLVRenderParams->vPartyPos.x;
-    v11 = -(pGame->pIndoorCameraD3D->int_cosine_y * pBLVRenderParams->vPartyPos.y
-          + pGame->pIndoorCameraD3D->int_sine_y * pBLVRenderParams->vPartyPos.x);
+                                                     * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_x) >> 16);
+    v70 = (unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16;
+    v74 = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16) - v70;
+    v70 = (unsigned __int64)(stru_F8AD28.vec_14.z * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_x) >> 16;
+    stru_F8AD28.vec_60.y = ((unsigned __int64)(v74 * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_x) >> 16) - v70;
+    stru_F8AD28.vec_60.z = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16)
+                         + ((unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16);
+    stru_F8AD28.field_6C = ((unsigned __int64)(v74 * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_x) >> 16)
+                         + ((unsigned __int64)(stru_F8AD28.vec_14.z * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_x) >> 16);
+    v70 = (unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16;
+    v74 = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16) - v70;
+    X = (unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16;
+    v72 = (unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16;
+    v70 = (unsigned __int64)(stru_F8AD28.vec_20.z * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_x) >> 16;
+    stru_F8AD28.vec_70.x = ((unsigned __int64)(v74 * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_x) >> 16) - v70;
+    stru_F8AD28.vec_70.y = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16)
+                         + ((unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16);
+    stru_F8AD28.vec_70.z = ((unsigned __int64)(v74 * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_x) >> 16)
+                         + ((unsigned __int64)(stru_F8AD28.vec_20.z * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_x) >> 16);
+    v74 = pEngine->pIndoorCameraD3D->int_sine_y * pBLVRenderParams->vPartyPos.y
+        - pEngine->pIndoorCameraD3D->int_cosine_y * pBLVRenderParams->vPartyPos.x;
+    v11 = -(pEngine->pIndoorCameraD3D->int_cosine_y * pBLVRenderParams->vPartyPos.y
+          + pEngine->pIndoorCameraD3D->int_sine_y * pBLVRenderParams->vPartyPos.x);
     v73 = -65536 * pBLVRenderParams->vPartyPos.z;
-    v70 = (unsigned __int64)(-65536 * pBLVRenderParams->vPartyPos.z * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16;
-    v12 = ((unsigned __int64)(v74 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16) - v70;
-    v69 = (unsigned __int64)(v74 * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16;
+    v70 = (unsigned __int64)(-65536 * pBLVRenderParams->vPartyPos.z * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_x) >> 16;
+    v12 = ((unsigned __int64)(v74 * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_x) >> 16) - v70;
+    v69 = (unsigned __int64)(v74 * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_x) >> 16;
     v13 = pBLVRenderParams->vPartyPos.y;
-    v70 = ((unsigned __int64)(v74 * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16)
-        + ((unsigned __int64)(-65536 * pBLVRenderParams->vPartyPos.z * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16);
+    v70 = ((unsigned __int64)(v74 * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_x) >> 16)
+        + ((unsigned __int64)(-65536 * pBLVRenderParams->vPartyPos.z * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_x) >> 16);
     v14 = pBLVRenderParams->vPartyPos.x;
   }
   else
   {
-    v70 = (unsigned __int64)(stru_F8AD28.plane_4.vNormal.y * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16;
+    v70 = (unsigned __int64)(stru_F8AD28.plane_4.vNormal.y * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16;
     stru_F8AD28.rotated_normal.x = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x
-                                                     * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16)
+                                                     * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16)
                                  - v70;
     stru_F8AD28.rotated_normal.z = stru_F8AD28.plane_4.vNormal.z;
     stru_F8AD28.rotated_normal.y = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x
-                                                     * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16)
+                                                     * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16)
                                  + ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.y
-                                                     * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16);
-    v70 = (unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16;
-    stru_F8AD28.vec_60.y = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16)
+                                                     * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16);
+    v70 = (unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16;
+    stru_F8AD28.vec_60.y = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16)
                          - v70;
     stru_F8AD28.field_6C = stru_F8AD28.vec_14.z;
-    stru_F8AD28.vec_60.z = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16)
-                         + ((unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16);
-    v70 = (unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16;
-    stru_F8AD28.vec_70.x = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16)
+    stru_F8AD28.vec_60.z = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16)
+                         + ((unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16);
+    v70 = (unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16;
+    stru_F8AD28.vec_70.x = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16)
                          - v70;
-    v69 = (unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16;
+    v69 = (unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16;
     v14 = pBLVRenderParams->vPartyPos.x;
     stru_F8AD28.vec_70.z = stru_F8AD28.vec_20.z;
     v13 = pBLVRenderParams->vPartyPos.y;
-    stru_F8AD28.vec_70.y = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16)
-                         + ((unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16);
-    v12 = pGame->pIndoorCameraD3D->int_sine_y * pBLVRenderParams->vPartyPos.y
-        - pGame->pIndoorCameraD3D->int_cosine_y * pBLVRenderParams->vPartyPos.x;
-    v11 = -(pGame->pIndoorCameraD3D->int_cosine_y * pBLVRenderParams->vPartyPos.y
-          + pGame->pIndoorCameraD3D->int_sine_y * pBLVRenderParams->vPartyPos.x);
+    stru_F8AD28.vec_70.y = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16)
+                         + ((unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16);
+    v12 = pEngine->pIndoorCameraD3D->int_sine_y * pBLVRenderParams->vPartyPos.y
+        - pEngine->pIndoorCameraD3D->int_cosine_y * pBLVRenderParams->vPartyPos.x;
+    v11 = -(pEngine->pIndoorCameraD3D->int_cosine_y * pBLVRenderParams->vPartyPos.y
+          + pEngine->pIndoorCameraD3D->int_sine_y * pBLVRenderParams->vPartyPos.x);
     v70 = -65536 * pBLVRenderParams->vPartyPos.z;
   }
   stru_F8AD28.field_7C = stru_F8AD28.rotated_normal.x;
@@ -9222,74 +9222,74 @@
   stru_F8AD28.uDefaultAmbientLightLevel = 0;
   if ( pBLVRenderParams->sPartyRotX )
   {
-    v0 = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16)
-       - ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.y * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16);
-    stru_F8AD28.rotated_normal.x = ((unsigned __int64)(v0 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16)
+    v0 = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16)
+       - ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.y * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16);
+    stru_F8AD28.rotated_normal.x = ((unsigned __int64)(v0 * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_x) >> 16)
                                  - ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.z
-                                                     * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16);
+                                                     * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_x) >> 16);
     stru_F8AD28.rotated_normal.y = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x
-                                                     * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16)
+                                                     * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16)
                                  + ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.y
-                                                     * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16);
-    stru_F8AD28.rotated_normal.z = ((unsigned __int64)(v0 * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16)
+                                                     * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16);
+    stru_F8AD28.rotated_normal.z = ((unsigned __int64)(v0 * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_x) >> 16)
                                  + ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.z
-                                                     * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16);
-    v1 = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16)
-       - ((unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16);
-    stru_F8AD28.vec_60.y = ((unsigned __int64)(v1 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16)
-                         - ((unsigned __int64)(stru_F8AD28.vec_14.z * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16);
-    stru_F8AD28.vec_60.z = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16)
-                         + ((unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16);
-    stru_F8AD28.field_6C = ((unsigned __int64)(v1 * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16)
-                         + ((unsigned __int64)(stru_F8AD28.vec_14.z * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16);
-    v2 = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16)
-       - ((unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16);
-    stru_F8AD28.vec_70.x = ((unsigned __int64)(v2 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16)
-                         - ((unsigned __int64)(stru_F8AD28.vec_20.z * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16);
-    stru_F8AD28.vec_70.y = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16)
-                         + ((unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16);
-    stru_F8AD28.vec_70.z = ((unsigned __int64)(v2 * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16)
-                         + ((unsigned __int64)(stru_F8AD28.vec_20.z * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16);
-    v3 = -(pGame->pIndoorCameraD3D->int_cosine_y * pBLVRenderParams->vPartyPos.y
-         + pGame->pIndoorCameraD3D->int_sine_y * pBLVRenderParams->vPartyPos.x);
-    v4 = pGame->pIndoorCameraD3D->int_sine_y * pBLVRenderParams->vPartyPos.y
-       - pGame->pIndoorCameraD3D->int_cosine_y * pBLVRenderParams->vPartyPos.x;
-    v5 = ((unsigned __int64)(v4 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16)
-       - ((unsigned __int64)(-65536 * pBLVRenderParams->vPartyPos.z * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16);
+                                                     * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_x) >> 16);
+    v1 = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16)
+       - ((unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16);
+    stru_F8AD28.vec_60.y = ((unsigned __int64)(v1 * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_x) >> 16)
+                         - ((unsigned __int64)(stru_F8AD28.vec_14.z * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_x) >> 16);
+    stru_F8AD28.vec_60.z = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16)
+                         + ((unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16);
+    stru_F8AD28.field_6C = ((unsigned __int64)(v1 * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_x) >> 16)
+                         + ((unsigned __int64)(stru_F8AD28.vec_14.z * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_x) >> 16);
+    v2 = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16)
+       - ((unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16);
+    stru_F8AD28.vec_70.x = ((unsigned __int64)(v2 * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_x) >> 16)
+                         - ((unsigned __int64)(stru_F8AD28.vec_20.z * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_x) >> 16);
+    stru_F8AD28.vec_70.y = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16)
+                         + ((unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16);
+    stru_F8AD28.vec_70.z = ((unsigned __int64)(v2 * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_x) >> 16)
+                         + ((unsigned __int64)(stru_F8AD28.vec_20.z * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_x) >> 16);
+    v3 = -(pEngine->pIndoorCameraD3D->int_cosine_y * pBLVRenderParams->vPartyPos.y
+         + pEngine->pIndoorCameraD3D->int_sine_y * pBLVRenderParams->vPartyPos.x);
+    v4 = pEngine->pIndoorCameraD3D->int_sine_y * pBLVRenderParams->vPartyPos.y
+       - pEngine->pIndoorCameraD3D->int_cosine_y * pBLVRenderParams->vPartyPos.x;
+    v5 = ((unsigned __int64)(v4 * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_x) >> 16)
+       - ((unsigned __int64)(-65536 * pBLVRenderParams->vPartyPos.z * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_x) >> 16);
     v6 = pBLVRenderParams->vPartyPos.z;
-    v7 = ((unsigned __int64)(-65536 * pBLVRenderParams->vPartyPos.z * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_x) >> 16)
-       + ((unsigned __int64)(v4 * (signed __int64)pGame->pIndoorCameraD3D->int_sine_x) >> 16);
+    v7 = ((unsigned __int64)(-65536 * pBLVRenderParams->vPartyPos.z * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_x) >> 16)
+       + ((unsigned __int64)(v4 * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_x) >> 16);
     v8 = pBLVRenderParams->vPartyPos.y;
     v9 = pBLVRenderParams->vPartyPos.x;
   }
   else
   {
     stru_F8AD28.rotated_normal.x = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x
-                                                     * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16)
+                                                     * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16)
                                  - ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.y
-                                                     * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16);
+                                                     * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16);
     stru_F8AD28.rotated_normal.z = stru_F8AD28.plane_4.vNormal.z;
     stru_F8AD28.rotated_normal.y = ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.x
-                                                     * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16)
+                                                     * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16)
                                  + ((unsigned __int64)(stru_F8AD28.plane_4.vNormal.y
-                                                     * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16);
-    stru_F8AD28.vec_60.y = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16)
-                         - ((unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16);
+                                                     * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16);
+    stru_F8AD28.vec_60.y = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16)
+                         - ((unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16);
     stru_F8AD28.field_6C = stru_F8AD28.vec_14.z;
-    stru_F8AD28.vec_60.z = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16)
-                         + ((unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16);
-    stru_F8AD28.vec_70.x = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16)
-                         - ((unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16);
+    stru_F8AD28.vec_60.z = ((unsigned __int64)(stru_F8AD28.vec_14.x * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16)
+                         + ((unsigned __int64)(stru_F8AD28.vec_14.y * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16);
+    stru_F8AD28.vec_70.x = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16)
+                         - ((unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16);
     v8 = pBLVRenderParams->vPartyPos.y;
-    stru_F8AD28.vec_70.y = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pGame->pIndoorCameraD3D->int_sine_y) >> 16)
-                         + ((unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16);
+    stru_F8AD28.vec_70.y = ((unsigned __int64)(stru_F8AD28.vec_20.x * (signed __int64)pEngine->pIndoorCameraD3D->int_sine_y) >> 16)
+                         + ((unsigned __int64)(stru_F8AD28.vec_20.y * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16);
     stru_F8AD28.vec_70.z = stru_F8AD28.vec_20.z;
     v9 = pBLVRenderParams->vPartyPos.x;
-    v5 = pGame->pIndoorCameraD3D->int_sine_y * pBLVRenderParams->vPartyPos.y
-       - pGame->pIndoorCameraD3D->int_cosine_y * pBLVRenderParams->vPartyPos.x;
+    v5 = pEngine->pIndoorCameraD3D->int_sine_y * pBLVRenderParams->vPartyPos.y
+       - pEngine->pIndoorCameraD3D->int_cosine_y * pBLVRenderParams->vPartyPos.x;
     v6 = pBLVRenderParams->vPartyPos.z;
-    v3 = -(pGame->pIndoorCameraD3D->int_cosine_y * pBLVRenderParams->vPartyPos.y
-         + pGame->pIndoorCameraD3D->int_sine_y * pBLVRenderParams->vPartyPos.x);
+    v3 = -(pEngine->pIndoorCameraD3D->int_cosine_y * pBLVRenderParams->vPartyPos.y
+         + pEngine->pIndoorCameraD3D->int_sine_y * pBLVRenderParams->vPartyPos.x);
     v7 = -65536 * pBLVRenderParams->vPartyPos.z;
   }
   stru_F8AD28.field_7C = stru_F8AD28.rotated_normal.x;
@@ -9475,8 +9475,8 @@
               v45 = v14->field_4 >> 3;
               v44 = v16 >> 3;
               v17 = (signed int)((unsigned __int64)(SLODWORD(pBLVRenderParams->field_44) * (signed __int64)v14->field_28) >> 16) >> 3;
-              v52 = (unsigned __int64)(v17 * (signed __int64)-pGame->pIndoorCameraD3D->int_sine_y) >> 16;
-              v53 = (unsigned __int64)(v17 * (signed __int64)pGame->pIndoorCameraD3D->int_cosine_y) >> 16;
+              v52 = (unsigned __int64)(v17 * (signed __int64)-pEngine->pIndoorCameraD3D->int_sine_y) >> 16;
+              v53 = (unsigned __int64)(v17 * (signed __int64)pEngine->pIndoorCameraD3D->int_cosine_y) >> 16;
               v18 = v14->field_28;
               v19 = *(__int16 *)((char *)stru_F8A590.viewport_left_side + v13);
               LOWORD(v18) = 0;
@@ -10920,7 +10920,7 @@
     pMouse->ChangeActivation(0);
   ClipCursor(0);
   MessageBoxA(0, pTmpBuf.data(), "Error", 0x30u);
-  Game_DeinitializeAndTerminate(1);
+  Engine_DeinitializeAndTerminate(1);
 }
 //----- (00466B8C) --------------------------------------------------------
 int  AbortWithError()
@@ -10934,7 +10934,7 @@
     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);
+    Engine_DeinitializeAndTerminate(1);
   }
   return 0;
 }
@@ -11514,7 +11514,7 @@
     v17 = (double)a1->field_A;
     v18 = _45D643_sw((Edge *)v14, v17);
     a2a = v18;
-    if ( byte_4D864C && BYTE1(pGame->uFlags) & 0x80 )
+    if ( byte_4D864C && BYTE1(pEngine->uFlags) & 0x80 )
     {
       HIWORD(result) = HIWORD(a3a);
       a1->field_14 = v18;
@@ -11792,7 +11792,7 @@
   //v1 = this;
   fRotationYSine = sin((3.141592653589793 + 3.141592653589793) * (double)sRotationY * 0.00048828125);
   fRotationYCosine = cos((3.141592653589793 + 3.141592653589793) * (double)sRotationY * 0.00048828125);
-  if ( byte_4D864C && pGame->uFlags & 0x80 || uCurrentlyLoadedLevelType == LEVEL_Indoor)
+  if ( byte_4D864C && pEngine->uFlags & 0x80 || uCurrentlyLoadedLevelType == LEVEL_Indoor)
   {
     fRotationXSine = sin((3.141592653589793 + 3.141592653589793) * (double)-sRotationX * 0.00048828125);
     v2 = (3.141592653589793 + 3.141592653589793) * (double)-sRotationX;
@@ -11817,10 +11817,10 @@
 //----- (0048600E) --------------------------------------------------------
 void ODMRenderParams::RotationToInts()
 {
-  camera_rotation_y_int_sine   = stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationY);
-  camera_rotation_y_int_cosine = stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationY);
-  camera_rotation_x_int_sine   = stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationX);
-  camera_rotation_x_int_cosine = stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationX);
+  camera_rotation_y_int_sine   = stru_5C6E00->Sin(pEngine->pIndoorCameraD3D->sRotationY);
+  camera_rotation_y_int_cosine = stru_5C6E00->Cos(pEngine->pIndoorCameraD3D->sRotationY);
+  camera_rotation_x_int_sine   = stru_5C6E00->Sin(pEngine->pIndoorCameraD3D->sRotationX);
+  camera_rotation_x_int_cosine = stru_5C6E00->Cos(pEngine->pIndoorCameraD3D->sRotationX);
 }
 //----- (004A169E) --------------------------------------------------------
 bool Render::UsingDirect3D()
@@ -12345,9 +12345,9 @@
 
       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);
+      if (pEngine)
+      {
+        pEngine->PickMouse(pEngine->pIndoorCameraD3D->GetPickDepth(), LOWORD(lParam), HIWORD(lParam), 0, &vis_sprite_filter_2, &vis_door_filter);
       }
 
       UI_OnMouseRightClick(0);
@@ -12391,8 +12391,8 @@
         UI_OnKeyDown(VK_SELECT);
       }
 
-      if (pGame)
-        pGame->PickMouse(512.0, LOWORD(lParam), HIWORD(lParam), false, &vis_sprite_filter_3, &vis_door_filter);
+      if (pEngine)
+        pEngine->PickMouse(512.0, LOWORD(lParam), HIWORD(lParam), false, &vis_sprite_filter_3, &vis_door_filter);
 
       UI_OnMouseLeftClick(0);
 
@@ -12410,17 +12410,17 @@
 
       pMouse->SetMouseClick(LOWORD(lParam), HIWORD(lParam));
 
-      if (pGame)
-        pGame->PickMouse(pGame->pIndoorCameraD3D->GetPickDepth(), LOWORD(lParam), HIWORD(lParam), false, &vis_sprite_filter_2, &vis_door_filter);
+      if (pEngine)
+        pEngine->PickMouse(pEngine->pIndoorCameraD3D->GetPickDepth(), LOWORD(lParam), HIWORD(lParam), false, &vis_sprite_filter_2, &vis_door_filter);
 
       UI_OnMouseRightClick(0);
       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);
+      if (pRenderer->pRenderD3D && pEngine)
+      {
+        pEngine->PickMouse(pEngine->pIndoorCameraD3D->GetPickDepth(), LOWORD(lParam), HIWORD(lParam), 1, &vis_sprite_filter_3, &vis_face_filter);
       }
 
       return DefWindowProcW(hWnd, uMsg, wParam, lParam);
@@ -12490,14 +12490,14 @@
         }
         if ( wParam >= VK_LEFT && wParam <= VK_DOWN )
         {
-          if ( pCurrentScreen != SCREEN_GAME && pCurrentScreen != SCREEN_MODAL_WINDOW )
+          if ( current_screen_type != SCREEN_GAME && current_screen_type != SCREEN_MODAL_WINDOW )
           {
             if ( !viewparams->field_4C )
               UI_OnKeyDown(wParam);
             return 0;
           }
         }
-        if ( pCurrentScreen != SCREEN_GAME && pCurrentScreen != SCREEN_MODAL_WINDOW )
+        if ( current_screen_type != SCREEN_GAME && current_screen_type != SCREEN_MODAL_WINDOW )
           return 0;
       }
 
@@ -13062,7 +13062,7 @@
     local_0.r = pRnd->GetRandom() * 800.0 - 400.0;
     local_0.g = pRnd->GetRandom() * 800.0 - 400.0;
     local_0.b = pRnd->GetRandom() * 350.0 + 50.0;
-    pGame->pParticleEngine->AddParticle(&local_0);
+    pEngine->pParticleEngine->AddParticle(&local_0);
     --v3;
   }
   while ( v3 );
@@ -13104,16 +13104,16 @@
     if ( uFaceID == *((short *)v5 + 2982) )
       return;
     if (!node_id
-      && pGame->pIndoorCameraD3D->vPartyPos.x >= v4->pBounding.x1 - 16
-      && pGame->pIndoorCameraD3D->vPartyPos.x <= v4->pBounding.x2 + 16
-      && pGame->pIndoorCameraD3D->vPartyPos.y >= v4->pBounding.y1 - 16
-      && pGame->pIndoorCameraD3D->vPartyPos.y <= v4->pBounding.y2 + 16
-      && pGame->pIndoorCameraD3D->vPartyPos.z >= v4->pBounding.z1 - 16
-      && pGame->pIndoorCameraD3D->vPartyPos.z <= v4->pBounding.z2 + 16 )
-    {
-      if ( abs(v4->pFacePlane_old.dist + pGame->pIndoorCameraD3D->vPartyPos.x * v4->pFacePlane_old.vNormal.x
-                                       + pGame->pIndoorCameraD3D->vPartyPos.y * v4->pFacePlane_old.vNormal.y
-                                       + pGame->pIndoorCameraD3D->vPartyPos.z * v4->pFacePlane_old.vNormal.z) <= 589824 )
+      && pEngine->pIndoorCameraD3D->vPartyPos.x >= v4->pBounding.x1 - 16
+      && pEngine->pIndoorCameraD3D->vPartyPos.x <= v4->pBounding.x2 + 16
+      && pEngine->pIndoorCameraD3D->vPartyPos.y >= v4->pBounding.y1 - 16
+      && pEngine->pIndoorCameraD3D->vPartyPos.y <= v4->pBounding.y2 + 16
+      && pEngine->pIndoorCameraD3D->vPartyPos.z >= v4->pBounding.z1 - 16
+      && pEngine->pIndoorCameraD3D->vPartyPos.z <= v4->pBounding.z2 + 16 )
+    {
+      if ( abs(v4->pFacePlane_old.dist + pEngine->pIndoorCameraD3D->vPartyPos.x * v4->pFacePlane_old.vNormal.x
+                                       + pEngine->pIndoorCameraD3D->vPartyPos.y * v4->pFacePlane_old.vNormal.y
+                                       + pEngine->pIndoorCameraD3D->vPartyPos.z * v4->pFacePlane_old.vNormal.z) <= 589824 )
       {
         v6 = v21->uSectorID;
         if ( v3->nodes[0].uSectorID == v6 )
@@ -13136,9 +13136,9 @@
       v5 = v20;
     }
     v8 = &pIndoor->pVertices[*v4->pVertexIDs];
-    v9 = v4->pFacePlane_old.vNormal.x * (v8->x - pGame->pIndoorCameraD3D->vPartyPos.x)
-       + v4->pFacePlane_old.vNormal.y * (v8->y - pGame->pIndoorCameraD3D->vPartyPos.y)
-       + v4->pFacePlane_old.vNormal.z * (v8->z - pGame->pIndoorCameraD3D->vPartyPos.z);
+    v9 = v4->pFacePlane_old.vNormal.x * (v8->x - pEngine->pIndoorCameraD3D->vPartyPos.x)
+       + v4->pFacePlane_old.vNormal.y * (v8->y - pEngine->pIndoorCameraD3D->vPartyPos.y)
+       + v4->pFacePlane_old.vNormal.z * (v8->z - pEngine->pIndoorCameraD3D->vPartyPos.z);
     if ( *((short *)v5 + 2004) != v4->uSectorID )
       v9 = -v9;
     if ( v9 < 0 )
@@ -13399,8 +13399,8 @@
   int v125; // [sp+6Ch] [bp-8h]@9
   int v126; // [sp+70h] [bp-4h]@9
 
-  v105 = pGame->pIndoorCameraD3D->sRotationY / ((signed int)stru_5C6E00->uIntegerHalfPi / 2);//2
-  pDirectionIndicator1 = stru_5C6E00->uDoublePiMask & (stru_5C6E00->uIntegerDoublePi - pGame->pIndoorCameraD3D->sRotationY);//1536
+  v105 = pEngine->pIndoorCameraD3D->sRotationY / ((signed int)stru_5C6E00->uIntegerHalfPi / 2);//2
+  pDirectionIndicator1 = stru_5C6E00->uDoublePiMask & (stru_5C6E00->uIntegerDoublePi - pEngine->pIndoorCameraD3D->sRotationY);//1536
   pDirectionIndicator2 = stru_5C6E00->uDoublePiMask & (stru_5C6E00->uIntegerPi + pDirectionIndicator1);//512
   v124 = ((pIndoorCamera->uMapGridCellX << 16) + 3 * stru_5C6E00->Cos(stru_5C6E00->uDoublePiMask & (stru_5C6E00->uIntegerPi + pDirectionIndicator1))) >> 16;//88
   v123 = ((pIndoorCamera->uMapGridCellZ << 16) + 3 * stru_5C6E00->Sin(pDirectionIndicator2)) >> 16;// 66
@@ -13959,7 +13959,7 @@
       if ( terrain_76D7C8[i] <= 0 )
         terrain_76D7C8[i] = -terrain_76D7C8[i];
       uEndZ = terrain_76D7C8[i] + 2;
-      //pIndoorCameraD3D_3 = pGame->pIndoorCameraD3D;
+      //pIndoorCameraD3D_3 = pEngine->pIndoorCameraD3D;
       //uEndZ = v75;
       //pIndoorCameraD3D_4 = pIndoorCameraD3D_3;
       uStartZ = terrain_76DBC8[i] - 2;
@@ -13980,7 +13980,7 @@
           ptr_801A04[v127].vWorldPosition.y = (63 - terrain_76D9C8[i]) * 512;
           ptr_801A04[v127].vWorldPosition.z = pOutdoor->GetHeightOnTerrain( z, terrain_76D9C8[i] + 1);
 
-          if ( !byte_4D864C || !(pGame->uFlags & 0x80) )
+          if ( !byte_4D864C || !(pEngine->uFlags & 0x80) )
           {
             pIndoorCameraD3D_4->ViewTransform(&ptr_801A08[v127], 1);
             pIndoorCameraD3D_4->ViewTransform(&ptr_801A04[v127], 1);
@@ -14023,7 +14023,7 @@
       //v90 = terrain_76D5C8[i];
       if ( terrain_76D5C8[i] <= 0 )
         terrain_76D5C8[i] = -terrain_76D5C8[i];
-      pIndoorCameraD3D_4 = pGame->pIndoorCameraD3D;
+      pIndoorCameraD3D_4 = pEngine->pIndoorCameraD3D;
       v107 = terrain_76D5C8[i] + 2;
       if ( terrain_76D9C8[i] - 2 < terrain_76D5C8[i] + 2 )
       {
@@ -14042,7 +14042,7 @@
           ptr_801A04[v86].vWorldPosition.x = (terrain_76DBC8[v86] - 63) << 9;
           ptr_801A04[v86].vWorldPosition.y = v92;
           ptr_801A04[v86].vWorldPosition.z = pOutdoor->GetHeightOnTerrain(terrain_76DBC8[v86] + 1, v116);
-          if ( !byte_4D864C || !(pGame->uFlags & 0x80) )
+          if ( !byte_4D864C || !(pEngine->uFlags & 0x80) )
           {
            pIndoorCameraD3D_4->ViewTransform((RenderVertexSoft *)(char *)ptr_801A08 + v86, 1);
            pIndoorCameraD3D_4->ViewTransform((RenderVertexSoft *)(char *)ptr_801A04 + v86, 1);
@@ -14223,7 +14223,7 @@
                WorldPosToGridCellX(sX),
                WorldPosToGridCellZ(sY),
                !byte_4D864C)
-           || !(pGame->uFlags & 0x80))
+           || !(pEngine->uFlags & 0x80))
           && !_481EFA_clip_terrain_poly(v8, v9, v101, pVertices, 1)) )
       if ( !&terrain_76E5C8[(v5 << 7) + v6] )
         goto LABEL_162
@@ -14246,7 +14246,7 @@
       v97 = WorldPosToGridCellZ(floorf((pVertices->vWorldPosition.z + v8->vWorldPosition.z) / 2 + 0.5f));
       WorldPosToGridCellX(sX);
       WorldPosToGridCellZ(sY);
-      if ((!byte_4D864C || !(pGame->uFlags & 0x80)) && !_481EFA_clip_terrain_poly(v8, pVertices, v101, pVertices2, 1))
+      if ((!byte_4D864C || !(pEngine->uFlags & 0x80)) && !_481EFA_clip_terrain_poly(v8, pVertices, v101, pVertices2, 1))
         if ( v8->vWorldPosition.y != pVertices->vWorldPosition.y || pVertices->vWorldPosition.y != pVertices2->vWorldPosition.y 
              || pVertices2->vWorldPosition.y != v101->vWorldPosition.y )
           break;
@@ -14307,14 +14307,14 @@
             atexit(loc_481199);
           }
           v32 = (struct8 *)array_50AC10;
-          v97 = (int)pGame->pLightmapBuilder;
-          pGame->pLightmapBuilder->StackLights_TerrainFace(norm, &v95, array_50AC10, 4, 1);
+          v97 = (int)pEngine->pLightmapBuilder;
+          pEngine->pLightmapBuilder->StackLights_TerrainFace(norm, &v95, array_50AC10, 4, 1);
           pDecalBuilder->_49BE8A(pTile, norm, &v95, array_50AC10, 4, 1);
           a5 = 4;
-          if ( byte_4D864C && pGame->uFlags & 0x80 )
-          {
-            thisa = pGame->pIndoorCameraD3D;
-            if ( pGame->pIndoorCameraD3D->_4371C3(array_50AC10, &a5, 0) == 1 && !a5 )
+          if ( byte_4D864C && pEngine->uFlags & 0x80 )
+          {
+            thisa = pEngine->pIndoorCameraD3D;
+            if ( pEngine->pIndoorCameraD3D->_4371C3(array_50AC10, &a5, 0) == 1 && !a5 )
               goto LABEL_162;
             thisa->ViewTransform(array_50AC10, a5);
             thisa->Project(array_50AC10, a5, 0);
@@ -14325,7 +14325,7 @@
           v108 = v3a < v102->vWorldViewPosition.x || v3a < pVertices->vWorldViewPosition.x
               || v3a < v101->vWorldViewPosition.x || v3a < pVertices2->vWorldViewPosition.x;
           v33 = 0;
-          pGame->pLightmapBuilder->std__vector_000004_size = 0;
+          pEngine->pLightmapBuilder->std__vector_000004_size = 0;
           if ( stru_F8AD28.uNumLightsApplied > 0 || pDecalBuilder->uNumDecals > 0 )
           {
             if ( this_3 )
@@ -14337,11 +14337,11 @@
               pDecalBuilder->ApplyDecals(31 - pTile->dimming_level, 4, &static_sub_0048034E_stru_154, a5, array_50AC10, 0, *(float *)&v33, -1);
           }
           if ( stru_F8AD28.uNumLightsApplied > 0 )
-            pGame->pLightmapBuilder->ApplyLights(&stru_F8AD28, &static_sub_0048034E_stru_154, a5, array_50AC10, 0, v33);
+            pEngine->pLightmapBuilder->ApplyLights(&stru_F8AD28, &static_sub_0048034E_stru_154, a5, array_50AC10, 0, v33);
           v34 = a5;
           //v35 = byte_4D864C == 0;
           pTile->uNumVertices = a5;
-          if ( !byte_4D864C || ~pGame->uFlags & 0x80 )
+          if ( !byte_4D864C || ~pEngine->uFlags & 0x80 )
           {
             if ( this_3 )
             {
@@ -14392,7 +14392,7 @@
         goto LABEL_162;
       v42 = pOutdoor->GetSomeOtherTileInfo(sX, sY);
       BYTE1(v42) |= 0x80u;
-      v43 = pGame->pLightmapBuilder;
+      v43 = pEngine->pLightmapBuilder;
       *(int *)&v40->flags = v42;
       v44 = v93;
       v40->field_59 = 1;
@@ -14448,14 +14448,14 @@
         Polygon(stru_76D590);
         atexit(loc_48118F);
       }
-      v96 = pGame->pLightmapBuilder;
-      pGame->pLightmapBuilder->StackLights_TerrainFace(v48, (float *)&a4, array_50AC10, 3, 0);
+      v96 = pEngine->pLightmapBuilder;
+      pEngine->pLightmapBuilder->StackLights_TerrainFace(v48, (float *)&a4, array_50AC10, 3, 0);
       pDecalBuilder->_49BE8A(v40, v48, &a4, array_50AC10, 3, 0);
       uNumVertices = 3;
-      if ( byte_4D864C && pGame->uFlags & 0x80 )
-      {
-        thisb = pGame->pIndoorCameraD3D;
-        if ( pGame->pIndoorCameraD3D->_4371C3(array_50AC10, &uNumVertices, 0) == 1 && !uNumVertices )
+      if ( byte_4D864C && pEngine->uFlags & 0x80 )
+      {
+        thisb = pEngine->pIndoorCameraD3D;
+        if ( pEngine->pIndoorCameraD3D->_4371C3(array_50AC10, &uNumVertices, 0) == 1 && !uNumVertices )
         {
 //LABEL_77:
           --pODMRenderParams->uNumPolygons;
@@ -14485,7 +14485,7 @@
       v55 = uNumVertices;
       //v35 = byte_4D864C == 0;
       v40->uNumVertices = uNumVertices;
-      if ( !_76D5C0_static_init_flag || !(pGame->uFlags & 0x80) )
+      if ( !_76D5C0_static_init_flag || !(pEngine->uFlags & 0x80) )
       {
         if ( this_3a )
         {
@@ -14571,14 +14571,14 @@
         __init_flag1 = true;
         stru154::stru154(&static_sub_0048034E_stru_76D578);
       }
-      v96 = pGame->pLightmapBuilder;
-      pGame->pLightmapBuilder->StackLights_TerrainFace(v63, &v87, array_50AC10, 3, 1);
+      v96 = pEngine->pLightmapBuilder;
+      pEngine->pLightmapBuilder->StackLights_TerrainFace(v63, &v87, array_50AC10, 3, 1);
       pDecalBuilder->_49BE8A(v40, v63, &v87, array_50AC10, 3, 1);
       v100 = 3;
-      if ( byte_4D864C && pGame->uFlags & 0x80 )
-      {
-        thisc = pGame->pIndoorCameraD3D;
-        if ( pGame->pIndoorCameraD3D->_4371C3(array_50AC10, (unsigned int *)&v100, 0) == 1 && !v100 )
+      if ( byte_4D864C && pEngine->uFlags & 0x80 )
+      {
+        thisc = pEngine->pIndoorCameraD3D;
+        if ( pEngine->pIndoorCameraD3D->_4371C3(array_50AC10, (unsigned int *)&v100, 0) == 1 && !v100 )
           //goto LABEL_126;
         {
           --pODMRenderParams->uNumPolygons;
@@ -14609,7 +14609,7 @@
       v72 = v100;
       //v35 = byte_4D864C == 0;
       v59->uNumVertices = v100;//???
-      if ( !byte_4D864C && pGame->uFlags & 0x80 )
+      if ( !byte_4D864C && pEngine->uFlags & 0x80 )
         goto LABEL_154;
       if ( this_3b )
       {
--- a/stru6.cpp	Sat May 09 12:55:58 2015 +0200
+++ b/stru6.cpp	Sun May 10 01:29:11 2015 +0200
@@ -3,12 +3,14 @@
 #include <crtdbg.h>
 
 #define _CRT_SECURE_NO_WARNINGS
+
+#include "Engine/Engine.h"
+
 #include "stru6.h"
 
 #include "Engine/Graphics/LightmapBuilder.h"
 #include "Engine/Objects/SpriteObject.h"
 #include "Engine/Graphics/ParticleEngine.h"
-#include "Engine/Game.h"
 #include "Engine/LOD.h"
 #include "Engine/Graphics/Sprites.h"
 #include "Engine/Objects/ObjectList.h"
@@ -21,9 +23,6 @@
 #include "Engine/stru160.h"
 #include "Engine/OurMath.h"
 #include "Engine/Graphics/Lights.h"
-
-#include "Engine/MM7.h"
-
 #include "Engine/Graphics/Indoor.h"
 
 
@@ -222,19 +221,19 @@
     v[1].vWorldPosition.x = p->dstX;
     v[1].vWorldPosition.y = p->dstY;
     v[1].vWorldPosition.z = p->dstZ;
-    pGame->pIndoorCameraD3D->ViewTransform(v, 2);
+    pEngine->pIndoorCameraD3D->ViewTransform(v, 2);
 
     sr_42620A(v);
 
-    pGame->pIndoorCameraD3D->Project(v, 2, 0);
+    pEngine->pIndoorCameraD3D->Project(v, 2, 0);
 
     if (p->uTextureID != -1)
       v12 = pBitmaps_LOD->pHardwareTextures[p->uTextureID];
     else
       v12 = 0;
 
-    v10 = pGame->pIndoorCameraD3D->fov_x / v[1].vWorldViewPosition.x * 20.0;
-    v11 = pGame->pIndoorCameraD3D->fov_x / v[0].vWorldViewPosition.x * 20.0;
+    v10 = pEngine->pIndoorCameraD3D->fov_x / v[1].vWorldViewPosition.x * 20.0;
+    v11 = pEngine->pIndoorCameraD3D->fov_x / v[0].vWorldViewPosition.x * 20.0;
     pRenderer->DrawProjectile(
         v[0].vWorldViewProjX,
         v[0].vWorldViewProjY,
@@ -282,15 +281,15 @@
     local_0.timeToLive = (rand() & 0x40) + 96;
     local_0.uTextureID = uTextureID;
     local_0.flt_28 = 1.0;
-    pGame->pParticleEngine->AddParticle(&local_0);
+    pEngine->pParticleEngine->AddParticle(&local_0);
     local_0.x = x - 4.0;
-    pGame->pParticleEngine->AddParticle(&local_0);
+    pEngine->pParticleEngine->AddParticle(&local_0);
     local_0.x = (double)v5->vPosition.x + 4.0;
     local_0.y = (double)v5->vPosition.y;
     local_0.z = (double)v5->vPosition.z;
-    pGame->pParticleEngine->AddParticle(&local_0);
+    pEngine->pParticleEngine->AddParticle(&local_0);
     local_0.x = (double)v5->vPosition.x - 4.0;
-    pGame->pParticleEngine->AddParticle(&local_0);
+    pEngine->pParticleEngine->AddParticle(&local_0);
     v4->array_4[v5->field_54 & 0x1F].flt_0_x = (double)v5->vPosition.x;
     v4->array_4[v5->field_54 & 0x1F].flt_4_y = (double)v5->vPosition.y;
     v4->array_4[v5->field_54 & 0x1F].flt_8_z = (double)v5->vPosition.z;
@@ -313,9 +312,9 @@
     local_0.flt_28 = 1.0;
     local_0.timeToLive = (rand() & 0x7F) + 128;
     local_0.uTextureID = uTextureID;
-    pGame->pParticleEngine->AddParticle(&local_0);
+    pEngine->pParticleEngine->AddParticle(&local_0);
     local_0.x = (double)a2->vPosition.x - 4.0;
-    pGame->pParticleEngine->AddParticle(&local_0);
+    pEngine->pParticleEngine->AddParticle(&local_0);
   }
 }
 
@@ -342,7 +341,7 @@
     local_0.r = (double)(rand() & 0x1FF) - 255.0;
     local_0.g = (double)(rand() & 0x1FF) - 255.0;
     local_0.b = (double)(rand() & 0x1FF) - 255.0;
-    pGame->pParticleEngine->AddParticle(&local_0);
+    pEngine->pParticleEngine->AddParticle(&local_0);
     --v5;
   }
   while ( v5 );
@@ -378,7 +377,7 @@
     local_0.r = (rand() & 0x1FF) - 255;
     local_0.g = (rand() & 0x1FF) - 255;
     local_0.b = (rand() & 0x1FF) - 255;
-    pGame->pParticleEngine->AddParticle(&local_0);
+    pEngine->pParticleEngine->AddParticle(&local_0);
   }
 
   pStru1->_47829F_sphere_particle((double)a2->vPosition.x, (double)a2->vPosition.y, (double)a2->vPosition.z, 
@@ -435,7 +434,7 @@
   local_0.b = 0.0;
   local_0.uTextureID = pSpriteFrameTable->GetFrame(v2->uSpriteID, v3)->pHwSpriteIDs[0];
   LODWORD(local_0.flt_28) = 0x40000000u;
-  pGame->pParticleEngine->AddParticle(&local_0);
+  pEngine->pParticleEngine->AddParticle(&local_0);
 }
 
 //----- (004A7948) --------------------------------------------------------
@@ -467,7 +466,7 @@
     Dst.r = (double)(rand() & 0x1FF) - 255.0;
     Dst.g = (double)(rand() & 0x1FF) - 255.0;
     Dst.b = (double)(rand() & 0x1FF) - 255.0;
-    pGame->pParticleEngine->AddParticle(&Dst);
+    pEngine->pParticleEngine->AddParticle(&Dst);
     --v6;
   }
   while ( v6 );
@@ -515,41 +514,41 @@
   local_0.r = v7;
   local_0.g = a4;
   local_0.b = a4;
-  pGame->pParticleEngine->AddParticle(&local_0);
+  pEngine->pParticleEngine->AddParticle(&local_0);
   v8 = 0.70710677 * a4;
   uDiffusea = v8;
   local_0.r = v8;
   local_0.g = v8;
   local_0.b = a4;
-  pGame->pParticleEngine->AddParticle(&local_0);
+  pEngine->pParticleEngine->AddParticle(&local_0);
   local_0.g = a1a;
   local_0.r = a4;
   local_0.b = a4;
-  pGame->pParticleEngine->AddParticle(&local_0);
+  pEngine->pParticleEngine->AddParticle(&local_0);
   local_0.r = uDiffusea;
   local_0.b = a4;
   v9 = -uDiffusea;
   uTextureIDa = v9;
   local_0.g = v9;
-  pGame->pParticleEngine->AddParticle(&local_0);
+  pEngine->pParticleEngine->AddParticle(&local_0);
   v10 = -1.0 * a4;
   local_0.r = a1a;
   v12 = v10;
   local_0.g = v10;
   local_0.b = a4;
-  pGame->pParticleEngine->AddParticle(&local_0);
+  pEngine->pParticleEngine->AddParticle(&local_0);
   local_0.b = a4;
   local_0.r = uTextureIDa;
   local_0.g = uTextureIDa;
-  pGame->pParticleEngine->AddParticle(&local_0);
+  pEngine->pParticleEngine->AddParticle(&local_0);
   local_0.r = v12;
   local_0.g = a1a;
   local_0.b = a4;
-  pGame->pParticleEngine->AddParticle(&local_0);
+  pEngine->pParticleEngine->AddParticle(&local_0);
   local_0.r = uTextureIDa;
   local_0.g = uDiffusea;
   local_0.b = a4;
-  pGame->pParticleEngine->AddParticle(&local_0);
+  pEngine->pParticleEngine->AddParticle(&local_0);
 }
 
 //----- (004A7C07) --------------------------------------------------------
@@ -593,14 +592,14 @@
     LODWORD(local_0.flt_28) = 0x40400000u;
     local_0.timeToLive = (v10 & 0x3F) + 64;
     local_0.uTextureID = pSpriteFrameTable->GetFrame(v5->uSpriteID, v3->uSpriteFrameID)->pHwSpriteIDs[0];
-    pGame->pParticleEngine->AddParticle(&local_0);
+    pEngine->pParticleEngine->AddParticle(&local_0);
     v11 = (double)v3->vPosition.x;
     LODWORD(local_0.flt_28) = 0x40800000u;
     local_0.x = v11;
     local_0.y = (double)v3->vPosition.y;
     local_0.z = (double)v3->vPosition.z;
     local_0.timeToLive = (rand() & 0x3F) + 64;
-    pGame->pParticleEngine->AddParticle(&local_0);
+    pEngine->pParticleEngine->AddParticle(&local_0);
     v2->array_4[v3->field_54 & 0x1F].flt_0_x = (double)v3->vPosition.x;
     v2->array_4[v3->field_54 & 0x1F].flt_4_y = (double)v3->vPosition.y;
     v2->array_4[v3->field_54 & 0x1F].flt_8_z = (double)v3->vPosition.z;
@@ -623,7 +622,7 @@
     local_0.b = 0.0;
     local_0.timeToLive = (rand() & 0x3F) + 64;
     local_0.uTextureID = pSpriteFrameTable->GetFrame(v5->uSpriteID, a2->uSpriteFrameID)->pHwSpriteIDs[0];
-    pGame->pParticleEngine->AddParticle(&local_0);
+    pEngine->pParticleEngine->AddParticle(&local_0);
   }
 }
 
@@ -683,7 +682,7 @@
       v4 = rand() << 16;
       Dst.uDiffuse = rand() | v4;
     }
-    pGame->pParticleEngine->AddParticle(&Dst);
+    pEngine->pParticleEngine->AddParticle(&Dst);
     --pActora;
   }
   while ( pActora );
@@ -726,7 +725,7 @@
     local_0.r = pRnd->GetRandom() * 400.0 - 200.0;
     local_0.g = pRnd->GetRandom() * 400.0 - 200.0;
     local_0.b = pRnd->GetRandom() * 150.0 + 50.0;
-    pGame->pParticleEngine->AddParticle(&local_0);
+    pEngine->pParticleEngine->AddParticle(&local_0);
     --v6;
   }
   while ( v6 );
@@ -1955,14 +1954,14 @@
 				v4 = *(float *)(v3 - 4);
 				LODWORD(v37) = *(int *)v3;
 				LODWORD(v36) = *(int *)(v3 + 4);
-				if (pGame->pIndoorCameraD3D->sRotationX)
+				if (pEngine->pIndoorCameraD3D->sRotationX)
 				{
-					v5 = v4 - (double)pGame->pIndoorCameraD3D->vPartyPos.x;
-					v6 = v37 - (double)pGame->pIndoorCameraD3D->vPartyPos.y;
+					v5 = v4 - (double)pEngine->pIndoorCameraD3D->vPartyPos.x;
+					v6 = v37 - (double)pEngine->pIndoorCameraD3D->vPartyPos.y;
 					//if ( pRenderer->pRenderD3D )
 					//{
-					v41 = pGame->pIndoorCameraD3D->fRotationYSine * v6 + pGame->pIndoorCameraD3D->fRotationYCosine * v5;
-					v7 = pGame->pIndoorCameraD3D->fRotationYSine * v5 - pGame->pIndoorCameraD3D->fRotationYCosine * v6;
+					v41 = pEngine->pIndoorCameraD3D->fRotationYSine * v6 + pEngine->pIndoorCameraD3D->fRotationYCosine * v5;
+					v7 = pEngine->pIndoorCameraD3D->fRotationYSine * v5 - pEngine->pIndoorCameraD3D->fRotationYCosine * v6;
 					/*}
 					else
 					{
@@ -1970,26 +1969,26 @@
 					v7 = pBLVRenderParams->fSineY * v5 + pBLVRenderParams->fCosineY * v6;
 					}*/
 					v8 = v7;
-					v9 = v36 - (double)pGame->pIndoorCameraD3D->vPartyPos.z;
-					v10 = pGame->pIndoorCameraD3D->fRotationXCosine * v41 - pGame->pIndoorCameraD3D->fRotationXSine * v9;
+					v9 = v36 - (double)pEngine->pIndoorCameraD3D->vPartyPos.z;
+					v10 = pEngine->pIndoorCameraD3D->fRotationXCosine * v41 - pEngine->pIndoorCameraD3D->fRotationXSine * v9;
 					v11 = v8;
-					v12 = pGame->pIndoorCameraD3D->fRotationXCosine * v9 + pGame->pIndoorCameraD3D->fRotationXSine * v41;
+					v12 = pEngine->pIndoorCameraD3D->fRotationXCosine * v9 + pEngine->pIndoorCameraD3D->fRotationXSine * v41;
 				}
 				else
 				{
-					v42 = v4 - (double)pGame->pIndoorCameraD3D->vPartyPos.x;
-					v39 = v37 - (double)pGame->pIndoorCameraD3D->vPartyPos.y;
+					v42 = v4 - (double)pEngine->pIndoorCameraD3D->vPartyPos.x;
+					v39 = v37 - (double)pEngine->pIndoorCameraD3D->vPartyPos.y;
 					//if ( pRenderer->pRenderD3D )
 					//{
-					v10 = pGame->pIndoorCameraD3D->fRotationYSine * v39 + pGame->pIndoorCameraD3D->fRotationYCosine * v42;
-					v11 = pGame->pIndoorCameraD3D->fRotationYSine * v42 - pGame->pIndoorCameraD3D->fRotationYCosine * v39;
+					v10 = pEngine->pIndoorCameraD3D->fRotationYSine * v39 + pEngine->pIndoorCameraD3D->fRotationYCosine * v42;
+					v11 = pEngine->pIndoorCameraD3D->fRotationYSine * v42 - pEngine->pIndoorCameraD3D->fRotationYCosine * v39;
 					/*}
 					else
 					{
 					v10 = pBLVRenderParams->fCosineY * v42 - pBLVRenderParams->fSineY * v39;
 					v11 = pBLVRenderParams->fSineY * v42 + pBLVRenderParams->fCosineY * v39;
 					}*/
-					v12 = v36 - (double)pGame->pIndoorCameraD3D->vPartyPos.z;
+					v12 = v36 - (double)pEngine->pIndoorCameraD3D->vPartyPos.z;
 				}
 				v13 = v12;
 				//++v2;
@@ -2009,29 +2008,29 @@
 		//do
 		for (v31 = 3; v31; --v31)
 		{
-			v40 = (double)stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationX) * 0.0000152587890625;
-			v32 = (double)stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationX) * 0.0000152587890625;
-			v34 = (double)stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationY) * 0.0000152587890625;
-			v33 = (double)stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationY) * 0.0000152587890625;
+			v40 = (double)stru_5C6E00->Cos(pEngine->pIndoorCameraD3D->sRotationX) * 0.0000152587890625;
+			v32 = (double)stru_5C6E00->Sin(pEngine->pIndoorCameraD3D->sRotationX) * 0.0000152587890625;
+			v34 = (double)stru_5C6E00->Cos(pEngine->pIndoorCameraD3D->sRotationY) * 0.0000152587890625;
+			v33 = (double)stru_5C6E00->Sin(pEngine->pIndoorCameraD3D->sRotationY) * 0.0000152587890625;
 			//v16 = stru_5C6E00->Sin(pODMRenderParams->rotation_y);
 			LODWORD(v38) = *(int *)v15;
 			//UNDEF(v17);
-			v20 = *((float *)v15 - 1) - (double)pGame->pIndoorCameraD3D->vPartyPos.x;
+			v20 = *((float *)v15 - 1) - (double)pEngine->pIndoorCameraD3D->vPartyPos.x;
 			//if ( v19 | v18 )
-			if (pGame->pIndoorCameraD3D->vPartyPos.x == 0)
+			if (pEngine->pIndoorCameraD3D->vPartyPos.x == 0)
 			{
 				v27 = v20;
 				LODWORD(v35) = *((int *)v15 + 1);
-				v28 = v38 - (double)pGame->pIndoorCameraD3D->vPartyPos.y;
+				v28 = v38 - (double)pEngine->pIndoorCameraD3D->vPartyPos.y;
 				v25 = v33 * v28 + v34 * v27;
 				v26 = v34 * v28 - v33 * v27;
 			}
 			else
 			{
 				v21 = v20;
-				v22 = v38 - (double)pGame->pIndoorCameraD3D->vPartyPos.y;
+				v22 = v38 - (double)pEngine->pIndoorCameraD3D->vPartyPos.y;
 				v23 = v33 * v22 + v34 * v21;
-				v24 = *((float *)v15 + 1) - (double)pGame->pIndoorCameraD3D->vPartyPos.z;
+				v24 = *((float *)v15 + 1) - (double)pEngine->pIndoorCameraD3D->vPartyPos.z;
 				v25 = v32 * v24 + v40 * v23;
 				v26 = v34 * v22 - v33 * v21;
 				v35 = v40 * v24 - v32 * v23;
@@ -2126,7 +2125,7 @@
 			v6 = (double)pBLVRenderParams->fov_rad_fixpoint * 0.000015258789 / this->field_B4[i * 4];
 			//if ( pRenderer->pRenderD3D )
 			{
-				pGame->pIndoorCameraD3D->Project(round_to_int(this->field_B4[i * 4]), round_to_int(this->field_B4[i * 4 + 1]), round_to_int(this->field_B4[i * 4 + 2]),
+				pEngine->pIndoorCameraD3D->Project(round_to_int(this->field_B4[i * 4]), round_to_int(this->field_B4[i * 4 + 1]), round_to_int(this->field_B4[i * 4 + 2]),
 					&a5, &a6);
 				this->field_B4[i * 4 + 16] = (double)a5;
 				this->field_B4[i * 4 + 17] = (double)a6;