changeset 2451:0eb0826e18b3

Слияние
author Ritor1
date Fri, 25 Jul 2014 14:19:14 +0600
parents 90349b8048a5 (diff) e40805af239b (current diff)
children 5991abe37c1d
files AudioPlayer.cpp
diffstat 20 files changed, 729 insertions(+), 969 deletions(-) [+]
line wrap: on
line diff
--- a/Arcomage.cpp	Thu Jul 24 19:55:55 2014 +0100
+++ b/Arcomage.cpp	Fri Jul 25 14:19:14 2014 +0600
@@ -8,7 +8,7 @@
 
 #include "Render.h"
 #include "Arcomage.h"
-#include "VideoPlayer.h"
+#include "MediaPlayer.h"
 #include "AudioPlayer.h"
 #include "Mouse.h"
 #include "Game.h"
@@ -1114,7 +1114,7 @@
   pArcomageGame->bGameInProgress = false;
   viewparams->bRedrawGameUI = true;
   if ( pMovie_Track )
-    pVideoPlayer->_4BF5B2();
+    pMediaPlayer->_4BF5B2();
   for( int i = 0; i < 12; ++i )
     pSoundList->UnloadSound(am_sounds[i], 1);
 }
--- a/Build/Visual Studio 2010/World of Might and Magic.vcxproj	Thu Jul 24 19:55:55 2014 +0100
+++ b/Build/Visual Studio 2010/World of Might and Magic.vcxproj	Fri Jul 25 14:19:14 2014 +0600
@@ -244,7 +244,6 @@
     <ClCompile Include="..\..\UI\UIShops.cpp" />
     <ClCompile Include="..\..\UI\UITransition.cpp" />
     <ClCompile Include="..\..\VectorTypes.cpp" />
-    <ClCompile Include="..\..\VideoPlayer.cpp" />
     <ClCompile Include="..\..\Viewport.cpp" />
     <ClCompile Include="..\..\Vis.cpp" />
     <ClCompile Include="..\..\Weather.cpp" />
@@ -486,7 +485,6 @@
     <ClInclude Include="..\..\UI\UIBooks.h" />
     <ClInclude Include="..\..\UI\UIHouses.h" />
     <ClInclude Include="..\..\VectorTypes.h" />
-    <ClInclude Include="..\..\VideoPlayer.h" />
     <ClInclude Include="..\..\Viewport.h" />
     <ClInclude Include="..\..\Vis.h" />
     <ClInclude Include="..\..\Weather.h" />
--- a/Build/Visual Studio 2010/World of Might and Magic.vcxproj.filters	Thu Jul 24 19:55:55 2014 +0100
+++ b/Build/Visual Studio 2010/World of Might and Magic.vcxproj.filters	Fri Jul 25 14:19:14 2014 +0600
@@ -76,7 +76,6 @@
     <ClInclude Include="..\..\TileFrameTable.h" />
     <ClInclude Include="..\..\TurnEngine.h" />
     <ClInclude Include="..\..\VectorTypes.h" />
-    <ClInclude Include="..\..\VideoPlayer.h" />
     <ClInclude Include="..\..\Viewport.h" />
     <ClInclude Include="..\..\Vis.h" />
     <ClInclude Include="..\..\Weather.h" />
@@ -706,7 +705,6 @@
     <ClCompile Include="..\..\TileTable.cpp" />
     <ClCompile Include="..\..\TurnEngine.cpp" />
     <ClCompile Include="..\..\VectorTypes.cpp" />
-    <ClCompile Include="..\..\VideoPlayer.cpp" />
     <ClCompile Include="..\..\Viewport.cpp" />
     <ClCompile Include="..\..\Vis.cpp" />
     <ClCompile Include="..\..\Weather.cpp" />
--- a/CShow.h	Thu Jul 24 19:55:55 2014 +0100
+++ b/CShow.h	Fri Jul 25 14:19:14 2014 +0600
@@ -1,5 +1,5 @@
 #pragma once
-#include "VideoPlayer.h"
+#include "MediaPlayer.h"
 #include "ErrorHandling.h"
 
 
@@ -16,23 +16,23 @@
   MOVIE_Outro = 0x7,
 };
 
-inline void PlayFullscreenMovie(MovieType movie, bool bShowMouseAfterPlayback = false)
+inline void PlayFullscreenMovie(MovieType movie_type, bool bShowMouseAfterPlayback = false)
 {
   extern unsigned int bNoVideo;
   if (bNoVideo) return;
 
-  switch (movie)
+  switch (movie_type)
   {
-    case MOVIE_3DOLogo: pVideoPlayer->MovieLoop("3dologo", 0);        break;
-	case MOVIE_NWCLogo: pVideoPlayer->MovieLoop("new world logo", 0); break;
-	case MOVIE_JVC:     pVideoPlayer->MovieLoop("jvc", 0);            break;
-	case MOVIE_Intro:   pVideoPlayer->MovieLoop("Intro", 0);          break;
-	case MOVIE_Emerald: pVideoPlayer->MovieLoop("Intro Post", 0);     break;
-	case MOVIE_Death:   pVideoPlayer->MovieLoop("losegame", 2);       break;
-	case MOVIE_Outro:   pVideoPlayer->MovieLoop("end_seq1", 20);      break;
+    case MOVIE_3DOLogo: pMediaPlayer->GlobalMovieLoop("3dologo", 0);        break;
+	case MOVIE_NWCLogo: pMediaPlayer->GlobalMovieLoop("new world logo", 0); break;
+	case MOVIE_JVC:     pMediaPlayer->GlobalMovieLoop("jvc", 0);            break;
+	case MOVIE_Intro:   pMediaPlayer->GlobalMovieLoop("Intro", 0);          break;
+	case MOVIE_Emerald: pMediaPlayer->GlobalMovieLoop("Intro Post", 0);     break;
+	case MOVIE_Death:   pMediaPlayer->GlobalMovieLoop("losegame", 2);       break;
+	case MOVIE_Outro:   pMediaPlayer->GlobalMovieLoop("end_seq1", 20);      break;
 
     default:
-      Error("Invalid movie requested: %u", movie);
+      Error("Invalid movie requested: %u", movie_type);
       break;
   }
 }
--- a/Events.cpp	Thu Jul 24 19:55:55 2014 +0100
+++ b/Events.cpp	Fri Jul 25 14:19:14 2014 +0600
@@ -10,7 +10,7 @@
 #include "Weather.h"
 #include "Texture.h"
 #include "mm7_data.h"
-#include "VideoPlayer.h"
+#include "MediaPlayer.h"
 #include "Mouse.h"
 
 #include "MapInfo.h"
@@ -457,18 +457,18 @@
         v12 = (char *)&item.uExpireTime + strlen(Source) + 7;
         if ( *v12 == 32 )
           *v12 = 0;
-        if (pVideoPlayer->bBufferLoaded)
-          pVideoPlayer->Unload();
-        pVideoPlayer->bStopBeforeSchedule = 0;
-        pVideoPlayer->pResetflag = 0;
+        if (pMediaPlayer->bPlaying_Movie)
+          pMediaPlayer->Unload();
+        pMediaPlayer->bStopBeforeSchedule = 0;
+//        pMediaPlayer->pResetflag = 0;
 
         v128 = pCurrentScreen;
         strcpy(Str, Source);
         v16 = RemoveQuotes(Str);
-		pVideoPlayer->MovieLoop(v16, 0/*, _evt->v5*/);
+		pMediaPlayer->GlobalMovieLoop(v16, 0/*, _evt->v5*/);
         if ( !_stricmp(v16, "arbiter good") )
-                {
-                  pParty->alignment = PartyAlignment_Good;
+        {
+          pParty->alignment = PartyAlignment_Good;
           v18 = 0;
           LOBYTE(v17) = 1;
           SetUserInterface(PartyAlignment_Good, v17);
@@ -478,7 +478,7 @@
             if ( v128 == 3 )
               pGameLoadingUI_ProgressBar->uType = GUIProgressBar::TYPE_Fullscreen;
             if ( v128 == 13 )
-              pVideoPlayer->OpenHouseMovie(pAnimatedRooms[uCurrentHouse_Animation].video_name, 1u);
+              pMediaPlayer->OpenHouseMovie(pAnimatedRooms[uCurrentHouse_Animation].video_name, 1u);
           }
           ++curr_seq_num;
           break;
@@ -495,7 +495,7 @@
             if ( v128 == 3 )
               pGameLoadingUI_ProgressBar->uType = GUIProgressBar::TYPE_Fullscreen;
             if ( v128 == 13 )
-              pVideoPlayer->OpenHouseMovie(pAnimatedRooms[uCurrentHouse_Animation].video_name, 1u);
+              pMediaPlayer->OpenHouseMovie(pAnimatedRooms[uCurrentHouse_Animation].video_name, 1);
           }
           ++curr_seq_num;
           break;
@@ -512,7 +512,7 @@
           if ( v128 == 3 )
             pGameLoadingUI_ProgressBar->uType = GUIProgressBar::TYPE_Fullscreen;
           if ( v128 == 13 )
-            pVideoPlayer->OpenHouseMovie(pAnimatedRooms[uCurrentHouse_Animation].video_name, 1);
+            pMediaPlayer->OpenHouseMovie(pAnimatedRooms[uCurrentHouse_Animation].video_name, 1);
         }
         ++curr_seq_num;
         }
@@ -694,7 +694,7 @@
           if ( window_SpeakInHouse->par1C == 165 )
             {
             HouseDialogPressCloseBtn();
-            pVideoPlayer->Unload();
+            pMediaPlayer->Unload();
             window_SpeakInHouse->Release();
             pParty->uFlags &= ~2;
             activeLevelDecoration = (LevelDecoration*)1;
@@ -721,7 +721,7 @@
           else
             {
             if ( window_SpeakInHouse->par1C == 553 )
-              pVideoPlayer->bLoopPlaying = 0;
+              pMediaPlayer->bLoopPlaying = 0;
             }
           }
 
@@ -1184,7 +1184,7 @@
               dialog_menu_id = HOUSE_DIALOGUE_NULL;
               while ( HouseDialogPressCloseBtn() )
                 ;
-              pVideoPlayer->Unload();
+              pMediaPlayer->Unload();
               window_SpeakInHouse->Release();
               window_SpeakInHouse = 0;
               if ( pMessageQueue_50CBD0->uNumMessages )
--- a/GUIWindow.cpp	Thu Jul 24 19:55:55 2014 +0100
+++ b/GUIWindow.cpp	Fri Jul 25 14:19:14 2014 +0600
@@ -11,7 +11,6 @@
 #include "LOD.h"
 #include "Keyboard.h"
 #include "OurMath.h"
-#include "VideoPlayer.h"
 #include "MapInfo.h"
 #include "Timer.h"
 #include "AudioPlayer.h"
--- a/Game.cpp	Thu Jul 24 19:55:55 2014 +0100
+++ b/Game.cpp	Fri Jul 25 14:19:14 2014 +0600
@@ -29,7 +29,6 @@
 #include "LOD.h"
 #include "GUIWindow.h"
 #include "TurnEngine.h"
-#include "VideoPlayer.h"
 #include "Bink_Smacker.h"
 #include "Events.h"
 #include "Arcomage.h"
@@ -353,7 +352,7 @@
         continue;
       }
 
-      pVideoPlayer->_inlined_in_463149();
+      pMediaPlayer->HouseMovieLoop();
       
       pEventTimer->Update();
       pMiscTimer->Update();
@@ -428,9 +427,10 @@
           if ( pNPCStats->pNewNPCData[i].field_24 )
             pNPCStats->pNewNPCData[i].uFlags &= 0xFFFFFF7Fu;
         }
-        pVideoPlayer->PlayDeathMovie();
+        pMediaPlayer->bStopBeforeSchedule = 0;
+        PlayFullscreenMovie(MOVIE_Death, true);
         if ( pMovie_Track )
-          pVideoPlayer->Unload();
+          pMediaPlayer->Unload();
         SaveGame(0, 0);
         ++pParty->uNumDeaths;
         for ( uint i = 0; i < 4; ++i )
@@ -1240,7 +1240,7 @@
           uGameState = GAME_FINISHED;
           continue;
         case UIMSG_PlayArcomage:
-          pVideoPlayer->_4BF5B2();
+          pMediaPlayer->_4BF5B2();
           pArcomageGame->bGameInProgress = 1;
           ArcomageGame::PrepareArcomage();
           continue;
@@ -1693,8 +1693,8 @@
         case UIMSG_ToggleTint:
           pRenderer->ToggleTint();
           continue;
-        case UIMSG_ChangeMusicVolume:  // 
-          if ( uMessageParam == 4 )// 
+        case UIMSG_ChangeMusicVolume:
+          if ( uMessageParam == 4 )//-
           {
             --uMusicVolimeMultiplier;
             if ( (char)uMusicVolimeMultiplier < 1 )
@@ -1705,7 +1705,7 @@
             pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f);
             continue;
           }
-          if ( uMessageParam == 5 )// 
+          if ( uMessageParam == 5 )//+
           {
             ++uMusicVolimeMultiplier;
             if ( (char)uMusicVolimeMultiplier > 9 )
@@ -1716,7 +1716,7 @@
             pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f);
             continue;
           }
-          uMusicVolimeMultiplier = (pMouse->GetCursorPos(&v202)->x - 263) / 17;//   
+          uMusicVolimeMultiplier = (pMouse->GetCursorPos(&v202)->x - 263) / 17;//for mouse
           if ( (char)uMusicVolimeMultiplier > 9 )
             uMusicVolimeMultiplier = 9;
           if ( uMusicVolimeMultiplier )
@@ -2152,7 +2152,7 @@
                         stru_506E40.Release();
                         break;
                       }
-					  pAudioPlayer->PlaySound((SoundID)27, 0, 0, -1, 0, 0, 0, 0);
+                      pAudioPlayer->PlaySound((SoundID)27, 0, 0, -1, 0, 0, 0, 0);
                       break;
                     case SCREEN_REST://close rest screen
                       if ( dword_506F14 )
@@ -2222,7 +2222,7 @@
                       }
                       GetHouseGoodbyeSpeech();
                       pAudioPlayer->PlaySound(SOUND_7, 814, 0, -1, 0, 0, 0, 0);
-                      pVideoPlayer->Unload();
+                      pMediaPlayer->Unload();
                       pGUIWindow_CurrentMenu = window_SpeakInHouse;
                       if ( pGUIWindow_Settings )
                       {
@@ -2252,7 +2252,7 @@
                     case SCREEN_INPUT_BLV://click escape
                       if ( uCurrentHouse_Animation == 153 )
                         PlayHouseSound(0x99u, HouseSound_Greeting_2);
-                      pVideoPlayer->Unload();
+                      pMediaPlayer->Unload();
                       if ( npcIdToDismissAfterDialogue )
                       {
                         pParty->hirelingScrollPosition = 0;
@@ -2300,7 +2300,7 @@
                       viewparams->bRedrawGameUI = true;
                       continue;
                     case SCREEN_VIDEO:
-                      pVideoPlayer->Unload();
+                      pMediaPlayer->Unload();
                       continue;
                     case SCREEN_CHARACTERS:
                       CharacterUI_ReleaseButtons();
@@ -2502,8 +2502,8 @@
           sub_42FBDD();
           PlayHouseSound(uCurrentHouse_Animation, HouseSound_NotEnoughMoney_TrainingSuccessful);
 
-          if (pVideoPlayer->AnyMovieLoaded())
-            pVideoPlayer->Unload();
+          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 )
@@ -2554,7 +2554,7 @@
           continue;
         case UIMSG_TransitionWindowCloseBtn:
           CloseWindowBackground();
-          pVideoPlayer->Unload();
+          pMediaPlayer->Unload();
           DialogueEnding();
           viewparams->bRedrawGameUI = true;
           continue;
@@ -4367,7 +4367,7 @@
           if ( !(dword_6BE364_game_settings_1 & GAME_SETTINGS_4000))
             break;
           v15 = 1;
-          pVideoPlayer->bStopBeforeSchedule = 1;
+          pMediaPlayer->bStopBeforeSchedule = 1;
           viewparams->bRedrawGameUI = 1;
           viewparams->field_48 = 1;
           if ( GetCurrentMenuID() == MENU_MAIN || GetCurrentMenuID() == MENU_MMT_MAIN_MENU
--- a/MMT.cpp	Thu Jul 24 19:55:55 2014 +0100
+++ b/MMT.cpp	Fri Jul 25 14:19:14 2014 +0600
@@ -12,7 +12,6 @@
 #include "Mouse.h"
 #include "LOD.h"
 #include "Render.h"
-#include "VideoPlayer.h"
 #include "CShow.h"
 #include "GUIFont.h"
 #include "lib/libpng/png.h"
@@ -24,17 +23,17 @@
   //unsigned int uTrackStartMS; // [sp+34h] [bp-8h]@8
   //unsigned int uTrackEndMS; // [sp+38h] [bp-4h]@8
 
-  pVideoPlayer->bStopBeforeSchedule = false;
-  pVideoPlayer->pResetflag = 0;
+  pMediaPlayer->bStopBeforeSchedule = false;
+//  pMediaPlayer->pResetflag = 0;
   bGameoverLoop = 1;
   if (!bNoVideo)
   {
     pRenderer->PresentBlackScreen();
     PlayFullscreenMovie(MOVIE_3DOLogo, true);
-    if ( !pVideoPlayer->bStopBeforeSchedule )
+    if ( !pMediaPlayer->bStopBeforeSchedule )
     {
       PlayFullscreenMovie(MOVIE_NWCLogo, true);
-      if ( !pVideoPlayer->bStopBeforeSchedule )
+      if ( !pMediaPlayer->bStopBeforeSchedule )
         PlayFullscreenMovie(MOVIE_JVC, true);
     }
   }
@@ -48,7 +47,7 @@
   free(tex.pPixels);
   tex.pPixels = 0;
   MainMenuUI_LoadFontsAndSomeStuff();
-  DrawMMTCopyrightWindow();//   
+  DrawMMTCopyrightWindow();//Text message in  menu
 
   pRenderer->EndScene();
   pRenderer->Present();
@@ -161,7 +160,7 @@
       i++;
     }
   }
-  //Ritor1: temporarily stopped, needed change RGBTexture structure/         ()RGBTexture
+  //Ritor1: temporarily stopped, needed change RGBTexture structure
   /*for (int i = 0; i < width * height; ++i)
     tex->pPalette16[i] = 0x7FF;
   memset(tex->pLevelOfDetail0_prolly_alpha_mask, 1, sizeof(unsigned __int8) * width * height);*/
@@ -180,25 +179,25 @@
   pCurrentScreen = SCREEN_GAME;
 
   pGUIWindow2 = 0;
-  pAudioPlayer->StopChannels(-1, -1);/// 
+  pAudioPlayer->StopChannels(-1, -1);
 
   //if (!bNoSound )
-    //PlayAudio(L"Sounds\\New_Sounds/Stronghold_Theme.mp3");// 3
+    //PlayAudio(L"Sounds\\New_Sounds/Stronghold_Theme.mp3");
   //if (!bNoVideo )
     //pVideoPlayer->PlayMovie(L"Anims\\New_Video/3DOLOGO.smk");
 
-  pMouse->RemoveHoldingItem();//   
+  pMouse->RemoveHoldingItem();
 
   pIcons_LOD->_inlined_sub2();
 
-  //  
-  //WINDOW_MainMenu   GUIWindow.h
+  //Create new window
+  //WINDOW_MainMenu included in GUIWindow.h
   pWindow_MMT_MainMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_MainMenu, 0, 0);
 
-  // 
+  //load buttons
   //Texture* MMT_MM6      = pIcons_LOD->LoadTexturePtr("title_new", TEXTURE_16BIT_PALETTE);
 
-  sprintf(pContainerName, "data\\New_Icons/%s", "mm6_button_oval.png");// png  
+  sprintf(pContainerName, "data\\New_Icons/%s", "mm6_button_oval.png");
   Texture* MMT_MM6 = LoadPNG(pContainerName);
 								
   Texture* MMT_MM7      = pIcons_LOD->LoadTexturePtr("title_load", TEXTURE_16BIT_PALETTE);
@@ -214,11 +213,11 @@
 
   pTexture_PCX.Release();
 
-  sprintf(pContainerName, "data\\New_Icons/%s", "MMTTITLE.pcx");// pcx  
+  sprintf(pContainerName, "data\\New_Icons/%s", "MMTTITLE.pcx");
   if (pTexture_PCX.LoadPCXFile(pContainerName, 0) == 1)
 	  Error("File not found: %s", pContainerName);
 
-  SetCurrentMenuID(MENU_MMT_MAIN_MENU);//  enum MENU_STATE  GUIWindows.h
+  SetCurrentMenuID(MENU_MMT_MAIN_MENU);//included in enum MENU_STATE in GUIWindows.h
   SetForegroundWindow(window->GetApiHandle());
   SendMessageW(window->GetApiHandle(), WM_ACTIVATEAPP, 1, 0);
   while (GetCurrentMenuID() == MENU_MMT_MAIN_MENU )
@@ -243,7 +242,7 @@
       pRenderer->BeginScene();
       pRenderer->DrawTextureRGB(0, 0, &pTexture_PCX);
 
-      MMT_MenuMessageProc();//     
+      MMT_MenuMessageProc();//for  menu
       GUI_UpdateWindows();
 
       if ( !pModalWindow )// ???
@@ -255,7 +254,7 @@
              && cursor.y >= (signed int)pButton->uY && cursor.y <= (signed int)pButton->uW )
            {
             pControlParam = pButton->msg_param;
-            switch (pControlParam) //  
+            switch (pControlParam) // backlight for buttons
             {
               case 0:
                 pTexture = MMT_MM6;
@@ -283,7 +282,7 @@
                 pY = window->GetHeight() - 35;
                 break;
             }
-            pRenderer->DrawTextureIndexed(pX, pY, pTexture); // 
+            pRenderer->DrawTextureIndexed(pX, pY, pTexture);
            }
           }
         }
@@ -297,7 +296,7 @@
   pRenderer->EndScene();
   pRenderer->Present();
 
-  // 
+  //remove resurs
   pTexture_PCX.Release();
   if ( pGUIWindow2 )
   {
@@ -323,12 +322,30 @@
 
       switch (pUIMessageType)
       {
-        case UIMSG_MMT_MainMenu_MM7: //  7
+        case UIMSG_MMT_MainMenu_MM6:
+          //video
+          //SetCurrentMenuID(MENU_MAIN_MM6);
+          pAudioPlayer->PlaySound((SoundID)27, 0, 0, -1, 0, 0, 0, 0);//temporarily
+          break;
+        case UIMSG_MMT_MainMenu_MM7: //new button for 7
           //GUIWindow::Create(495, 172, 0, 0, WINDOW_PressedButton2, (int)pMainMenu_BtnNew, 0);
           alSourceStop(mSourceID);
-          ShowMM7IntroVideo_and_LoadingScreen();
+          pMediaPlayer->ShowMM7IntroVideo_and_LoadingScreen();
           SetCurrentMenuID(MENU_MAIN);
           break;
+        case UIMSG_MMT_MainMenu_MM8:
+          //video
+          //SetCurrentMenuID(MENU_MAIN_MM8);
+          pAudioPlayer->PlaySound((SoundID)27, 0, 0, -1, 0, 0, 0, 0);//temporarily
+          break;
+        case UIMSG_MMT_MainMenu_Continue:
+          //video
+          //SetCurrentMenuID(MENU_MAIN_Continue);
+          pAudioPlayer->PlaySound((SoundID)27, 0, 0, -1, 0, 0, 0, 0);//temporarily
+          break;
+        case UIMSG_ExitToWindows:
+          GUIWindow::Create(495, 337, 0, 0, WINDOW_PressedButton2, (int)pMainMenu_BtnExit, 0);
+          SetCurrentMenuID(MENU_EXIT_GAME);
 
         default:
           break;
--- a/MediaPlayer.cpp	Thu Jul 24 19:55:55 2014 +0100
+++ b/MediaPlayer.cpp	Fri Jul 25 14:19:14 2014 +0600
@@ -21,16 +21,31 @@
 #include <vector>
 #include <deque>
 
+#define _CRT_SECURE_NO_WARNINGS
+
+#include "mm7_unsorted_subs.h"
+#include "Mouse.h"
+#include "Game.h"
+#include "Party.h"
+#include "GUIWindow.h"
+#include "texts.h"
+#include "UI\UIHouses.h"
 #include "stuff.h"
+#include "mm7_data.h"
 #include "OpenALSoundProvider.h"
-
 #include "Log.h"
+#include "MediaPlayer.h"
+#include "CShow.h"
+#include "Bink_Smacker.h"
+#include "AudioPlayer.h"
+#include "Timer.h"
+#include "Render.h"
 
-#include "MediaPlayer.h"
-#include "Log.h"
+#pragma comment(lib, "Version.lib")
+
 using namespace Media;
 
-Media::MPlayer *pMediaPlayer;
+Media::MPlayer *pMediaPlayer = nullptr;
 Media::IMovie *pMovie_Track;
 Media::ITrack *pAudio_Track;
 Movie *movie;
@@ -139,12 +154,6 @@
     size_t  current_pos;
 };
 
-bool end_current_file;
-bool loop_current_file;
-DWORD time_video_begin;
-int current_movie_width;
-int current_movie_height;
-
 OpenALSoundProvider *provider = nullptr;
 
 static int av_num_bytes_per_sample(AVSampleFormat sample_fmt)
@@ -767,10 +776,10 @@
     OpenALSoundProvider::TrackBuffer *device_buffer;
 };
 
-class Movie: public Media::IMovie//    Media::IMovie
+class Movie: public Media::IMovie
 {
   public:
-    inline Movie()//   
+    inline Movie()
     {
       this->movie_filename[0] = 0;
       this->width = 0;
@@ -844,26 +853,14 @@
       width = dst_width;
       height = dst_height;
       // Open video file
-      //  ( 2)
-      // avformat_open_input           
-      //AVFormatContext.       NULL,    libavformat  
-      //  .   2       .
       if (avformat_open_input(&format_ctx, filenamea, nullptr, nullptr) >= 0)
       {
         // Retrieve stream information
-        //  
-        //.. avformat_open_input    ,        
-        // .    avformat_find_stream_info.( 3)
         if (avformat_find_stream_info(format_ctx, nullptr) >= 0)
         {
           // Dump information about file onto standard error
-          // pFormatCtx->streams
-          //  format_context->streams     . 
-          //   format_context->nb_streams.
-          //           av_dump_format.
           av_dump_format(format_ctx, 0, filenamea, 0);
 
-          //pFormatCtx->streams -  ,  pFormatCtx->nb_streams,   .
           if (!av_open_audio_stream(format_ctx, &audio))
           {
             Error("Cannot open audio stream: %s", filenamea);
@@ -879,30 +876,29 @@
           //Ritor1: include 
 		  if (_stricmp("binkvideo", video.dec->name) ) 
 		  {
-			current_movie_width = video.dec_ctx->width;
-			current_movie_height = video.dec_ctx->height;
+			pMediaPlayer->current_movie_width = video.dec_ctx->width;
+			pMediaPlayer->current_movie_height = video.dec_ctx->height;
 		  }
 		  else
 		  {
-			current_movie_width = width;
-			current_movie_height = height;
+			pMediaPlayer->current_movie_width = width;
+			pMediaPlayer->current_movie_height = height;
 	      }
 		  //
           decoding_packet = new AVPacket;
           av_init_packet(decoding_packet);
       
 		  // Allocate video frame
-		  //   
           decoding_frame = avcodec_alloc_frame();
 
           audio_data_in_device = provider->CreateStreamingTrack16(audio.dec_ctx->channels, audio.dec_ctx->sample_rate, 2);
           return true;
         }
         fprintf(stderr, "ffmpeg: Unable to find stream info\n");
-        return Release(), false; //     
+        return Release(), false; 
       }
       fprintf(stderr, "ffmpeg: Unable to open input file\n");
-      return Release(), false; //    
+      return Release(), false;
     }
 
 	bool LoadFromLOD(HANDLE h, int readFunction(void*, uint8_t*, int), int64_t seekFunction(void*, int64_t, int), int width, int height)
@@ -917,66 +913,56 @@
 		return Load(L"dummyFilename", width, height, 0);
 	}
 
-    virtual void GetNextFrame(double dt, void *dst_surface)//   
+    virtual void GetNextFrame(double dt, void *dst_surface)
     {
-      playback_time += dt;// 
+      playback_time += dt;
 
-      //     (AVPacket),      (AVFrame).
       AVPacket *avpacket = decoding_packet;
       AVFrame *avframe = decoding_frame;
-      
-	  // avframe
+
       avcodec_get_frame_defaults(avframe);
 
       int desired_frame_number = floor(playback_time * video.dec_ctx->time_base.den / video.dec_ctx->time_base.num + 0.5);
       if (last_resampled_frame_num == desired_frame_number)
       {
-        memcpy(dst_surface, last_resampled_frame_data[0], current_movie_height * last_resampled_frame_linesize[0]);
+        memcpy(dst_surface, last_resampled_frame_data[0], pMediaPlayer->current_movie_height * last_resampled_frame_linesize[0]);
         return;
       }
 
       volatile int frameFinished = false;
 
-	  // 
       // keep reading packets until we hit the end or find a video packet
       do
       {
-        if (loop_current_file)
+        if (pMediaPlayer->loop_current_file)
         {
           //Now seek back to the beginning of the stream
           if (video.dec_ctx->frame_number >= video.stream->duration - 1 )
-            end_current_file = true;
+            pMediaPlayer->bPlaying_Movie = false;
         }
-        // 
-        if (av_read_frame(format_ctx, avpacket) < 0) // 
+        if (av_read_frame(format_ctx, avpacket) < 0)
         {
           // probably movie is finished
-          end_current_file = true;
+          pMediaPlayer->bPlaying_Movie = false;
           av_free_packet(avpacket);
 		  return;
         }
 		// Is this a packet from the video stream?
         // audio packet - queue into playing
-        //    
         if (avpacket->stream_index == audio.stream_idx)
         {
           MemoryStream audio_data;
           if (DecodeAudioFrame(audio.dec_ctx, avpacket, avframe, &audio_data, &num_audio_samples))
             provider->Stream16(audio_data_in_device, num_audio_samples, audio_data.Ptr());
           //continue;
-        } //    audio_data
+        }
 
 		// Decode video frame
-        //  
         // video packet - decode & maybe show
         else if (avpacket->stream_index == video.stream_idx)
         {
           do
           {
-	       // avcodec_decode_video2        ,
-           //    (codec_context).     frame_finished  
-           //    (         frame_finished  
-           //     ).
             if (avcodec_decode_video2(video.dec_ctx, avframe, (int *)&frameFinished, avpacket) < 0)
               __debugbreak();
           } while (!frameFinished);
@@ -995,27 +981,24 @@
         uint8_t       *rescaled_data[4] = {nullptr, nullptr, nullptr, nullptr};
         int            rescaled_linesize[4] = {0, 0, 0, 0};
 
-        if (av_image_alloc(rescaled_data, rescaled_linesize, current_movie_width, current_movie_height, rescaled_format, 1) >= 0)
+        if (av_image_alloc(rescaled_data, rescaled_linesize, pMediaPlayer->current_movie_width, pMediaPlayer->current_movie_height, rescaled_format, 1) >= 0)
         {
-          //    
           SwsContext *converter = sws_getContext(avframe->width, avframe->height, (AVPixelFormat)avframe->format,
-                                               current_movie_width, current_movie_height, rescaled_format,
+                                               pMediaPlayer->current_movie_width, pMediaPlayer->current_movie_height, rescaled_format,
                                                SWS_BICUBIC, nullptr, nullptr, nullptr);
-          //  ()
           sws_scale(converter, avframe->data, avframe->linesize, 0, avframe->height, rescaled_data, rescaled_linesize);
           sws_freeContext(converter);
 
-          //   
-          memcpy(dst_surface, rescaled_data[0], current_movie_height * rescaled_linesize[0]);
+          memcpy(dst_surface, rescaled_data[0], pMediaPlayer->current_movie_height * rescaled_linesize[0]);
 
           last_resampled_frame_num = desired_frame_number;
           memcpy(last_resampled_frame_data, rescaled_data, sizeof(rescaled_data));
           memcpy(last_resampled_frame_linesize, rescaled_linesize, sizeof(rescaled_linesize));
-          //av_freep(&rescaled_data[0]);//   
+          //av_freep(&rescaled_data[0]);
         }
       }
       else
-        memset(dst_surface, 0, width * current_movie_height * 4);
+        memset(dst_surface, 0, width * pMediaPlayer->current_movie_height * 4);
 
       // Free the packet that was allocated by av_read_frame
       av_free_packet(avpacket);
@@ -1050,7 +1033,7 @@
     int             last_resampled_frame_linesize[4];
 };	
 
-ITrack *MPlayer::LoadTrack(const wchar_t *filename) // mp3
+ITrack *MPlayer::LoadTrack(const wchar_t *filename)
 {
   auto audio_track = new Track;
   Log::Warning(L"allocation dynamic memory for audio_track\n");
@@ -1076,6 +1059,425 @@
   return movie;
 }
 
+//----- (004BE9D8) --------------------------------------------------------
+void MPlayer::Initialize(OSWindow *target_window)
+{
+  DWORD NumberOfBytesRead; // [sp+10h] [bp-4h]@9
+    
+  window = target_window;
+
+  unsigned int uBinkVersionMajor = -1,
+               uBinkVersionMinor = -1;
+  //GetDllVersion(L"BINKW32.DLL", &uBinkVersionMajor, &uBinkVersionMinor);
+  //uBinkVersion = (unsigned __int64)uBinkVersionMajor << 32 | uBinkVersionMinor;
+
+  strcpy(pTmpBuf.data(), "anims\\might7.vid");
+  hMightVid = CreateFileW(L"anims\\might7.vid", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0x8000080, 0);
+  if ( hMightVid == INVALID_HANDLE_VALUE )
+  {
+    sprintf(pTmpBuf2.data(), "Can't open file - anims\\%s.smk", pTmpBuf.data());
+    MessageBoxA(0, pTmpBuf2.data(), "Video File Error", 0);
+    return;
+  }
+  strcpy(pTmpBuf.data(), "anims\\magic7.vid");
+  hMagicVid = CreateFileW(L"anims\\magic7.vid", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0x8000080, 0);
+  if ( hMagicVid == INVALID_HANDLE_VALUE )
+  {
+    if ( !bCanLoadFromCD )
+    {
+       sprintf(pTmpBuf2.data(), "Can't open file - anims\\%s.smk", pTmpBuf.data());
+       MessageBoxA(0, pTmpBuf2.data(), "Video File Error", 0);
+       return;
+    }
+    sprintf(pTmpBuf2.data(), "%c:\\%s", (unsigned __int8)cMM7GameCDDriveLetter, pTmpBuf.data());
+    hMagicVid = CreateFileA(pTmpBuf2.data(), GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0x8000080, 0);
+    if ( hMagicVid == (HANDLE)INVALID_HANDLE_VALUE )
+    {
+      sprintf(pTmpBuf2.data(), "Can't open file - %s", pTmpBuf.data());
+      MessageBoxA(0, pTmpBuf2.data(), "Video File Error", 0);
+      return;
+    }
+  }
+  ReadFile(hMightVid, &uNumMightVideoHeaders, 4, &NumberOfBytesRead, 0);
+  ReadFile(hMagicVid, &uNumMagicVideoHeaders, 4, &NumberOfBytesRead, 0);
+  pMightVideoHeaders = (MovieHeader *)malloc(sizeof(MovieHeader) * uNumMightVideoHeaders + 2);
+  pMagicVideoHeaders = (MovieHeader *)malloc(sizeof(MovieHeader) * uNumMagicVideoHeaders + 2);
+  ReadFile(hMightVid, pMightVideoHeaders, 44 * uNumMightVideoHeaders, &NumberOfBytesRead, 0);
+  ReadFile(hMagicVid, pMagicVideoHeaders, 44 * uNumMagicVideoHeaders, &NumberOfBytesRead, 0);
+}
+
+//----- (004BF411) --------------------------------------------------------
+void MPlayer::OpenGlobalMovie(const char *pFilename, unsigned int bLoop/*, int ScreenSizeFlag*/)
+{
+  if (!this->bPlaying_Movie)
+  {
+    pEventTimer->Pause();
+	if (pAudioPlayer->hAILRedbook)
+		AIL_redbook_pause(pAudioPlayer->hAILRedbook);
+
+	bStopBeforeSchedule = false;
+	bFirstFrame = false;
+	this->bLoopPlaying = bLoop;
+	LoadMovie(pFilename);
+	return;
+  }
+}
+
+//----- (004BF28F) --------------------------------------------------------
+void MPlayer::OpenHouseMovie(const char *pMovieName, unsigned int a3_1)
+{
+  if (!this->bPlaying_Movie)
+  {
+    //Prepare();
+    pEventTimer->Pause();
+    if (pAudioPlayer->hAILRedbook)
+      AIL_redbook_pause(pAudioPlayer->hAILRedbook);
+
+    bStopBeforeSchedule = false;
+    bFirstFrame = false;
+
+    this->bLoopPlaying = a3_1;
+    /*if ( LOBYTE(this->field_104) == 1 )
+    {
+      MessageBoxA(nullptr, "Unsupported Bink playback!", "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Video.cpp:925", 0);
+      return;
+    }*/
+
+    LoadMovie(pMovieName);
+	time_video_begin = GetTickCount();
+  }
+}
+
+//----- (004BE70E) --------------------------------------------------------
+void MPlayer::GlobalMovieLoop(const char *pMovieName, int a2/*, int ScreenSizeFlag, int a4*/)
+{
+  int v4; // ebp@1
+  MSG Msg; // [sp+Ch] [bp-1Ch]@12
+
+  v4 = a2;
+  if ( dword_6BE364_game_settings_1 & (GAME_SETTINGS_NO_HOUSE_ANIM | GAME_SETTINGS_NO_INTRO) ||
+	   bNoVideo)
+    return;
+
+    if ( a2 == 2 )
+      v4 = 0;
+    ShowCursor(0);
+    OpenGlobalMovie(pMovieName, 0);
+    bPlaying_Movie = 1;
+    field_44 = v4;
+    pRenderer->ClearTarget(0);
+    pCurrentScreen = SCREEN_VIDEO;
+
+    auto hwnd = pMediaPlayer->window->GetApiHandle();
+
+    RECT rc_client;
+    GetClientRect(hwnd, &rc_client);
+    int client_width = rc_client.right - rc_client.left,
+        client_height = rc_client.bottom - rc_client.top;
+
+    HDC     dc = GetDC(hwnd);
+    HDC     back_dc = CreateCompatibleDC(dc);
+	HBITMAP back_bmp = CreateCompatibleBitmap(dc, client_width, client_height);
+	auto    frame_buffer = new char[client_width * client_height * 4];
+    SelectObject(back_dc, back_bmp);
+
+	DWORD t = GetTickCount();
+
+	bPlaying_Movie = true;
+
+    while (true)
+    {
+      if (pMediaPlayer->bStopBeforeSchedule)
+        break;
+      while (PeekMessageA(&Msg, hwnd, 0, 0, PM_REMOVE))
+      {
+        if (Msg.message == WM_QUIT)
+          Game_DeinitializeAndTerminate(0);
+        if (Msg.message == WM_PAINT)
+          break;
+        TranslateMessage(&Msg);
+        DispatchMessageA(&Msg);
+      }
+
+      double dt = (GetTickCount() - t) / 1000.0; 
+      t = GetTickCount();
+
+      pMovie_Track->GetNextFrame(dt, frame_buffer);	
+
+      if (!bPlaying_Movie)
+        break;
+
+      if (frame_buffer)
+      {
+        // draw to hwnd
+        BITMAPINFO bmi;
+        bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+        bmi.bmiHeader.biWidth = client_width;
+        bmi.bmiHeader.biHeight = -client_height;
+        bmi.bmiHeader.biPlanes = 1;
+        bmi.bmiHeader.biBitCount = 32;
+        bmi.bmiHeader.biCompression = BI_RGB;
+        bmi.bmiHeader.biSizeImage = 0;
+        bmi.bmiHeader.biXPelsPerMeter = 0;
+        bmi.bmiHeader.biYPelsPerMeter = 0;
+        bmi.bmiHeader.biClrUsed = 0;
+        bmi.bmiHeader.biClrImportant = 0;
+        GetDIBits(back_dc, back_bmp, 0, client_height, 0, &bmi, DIB_RGB_COLORS);
+        SetDIBits(back_dc, back_bmp, 0, client_height, frame_buffer, &bmi, DIB_RGB_COLORS);
+        BitBlt(dc, 0, 0, client_width, client_height, back_dc, 0, 0, SRCCOPY);
+      }
+
+      GUI_MainMenuMessageProc();  
+
+      if (pMediaPlayer->bStopBeforeSchedule == 1)
+        Sleep(1000); 
+    }
+	delete [] frame_buffer;
+	DeleteObject(back_bmp);
+	DeleteObject(back_dc);
+	ReleaseDC(hwnd, dc);
+
+    pMediaPlayer->Unload();
+
+    //if (a4 == 1)
+      pCurrentScreen = SCREEN_GAME;
+
+    pMediaPlayer->bPlaying_Movie = false;
+
+    ShowCursor(1);
+
+    /*if ( pCurrentScreen == SCREEN_VIDEO )
+      pCurrentScreen = SCREEN_GAME;*/
+}
+
+void MPlayer::HouseMovieLoop()
+{
+	if (pMovie_Track && !bNoVideo)
+	{
+		pRenderer->BeginScene();
+		pMouse->DrawCursorToTarget();
+
+        Log::Warning(L"smacker");
+        loop_current_file = true;
+        pRenderer->BeginScene();
+        if (!bPlaying_Movie)//reload
+        {
+          unsigned int width = game_viewport_width;
+          unsigned int height = game_viewport_height;
+	      MovieRelease();
+
+          SetFilePointer(hVidFile, uOffset, nullptr, FILE_BEGIN);
+          pMovie_Track = nullptr;
+	      Log::Warning(L"reload pMovie_Track");
+          pMovie_Track = pMediaPlayer->LoadMovieFromLOD(hVidFile, &readFunction, &seekFunction, width, height);
+          bPlaying_Movie = true;
+        }
+        //else 
+        //{
+          double dt = (GetTickCount() - time_video_begin) / 1000.0;
+          //dt = 1.0/15.0;
+          time_video_begin = GetTickCount();
+
+          //log("dt=%.5f\n", dt);
+
+          auto image = new char[current_movie_width * current_movie_height * 4];
+
+          pMovie_Track->GetNextFrame(dt, image);
+
+          int image_array[460 * 344];//game_viewport_width * game_viewport_height
+          if (image)
+          {
+            memcpy(image_array, image, sizeof (image_array));
+            for (unsigned int y = 8; y < 8 + game_viewport_height; ++y)//  
+            {
+              for (unsigned int x = 8; x < 8 + game_viewport_width; ++x)
+              {
+                auto p = (unsigned __int32 *)pRenderer->pTargetSurface + x + y * pRenderer->uTargetSurfacePitch;
+                *p = image_array[((x - 8) + ((y - 8)*game_viewport_width))];
+              }
+            }
+            delete[] image;
+          }
+       //}
+        pRenderer->EndScene();
+		pMouse->ReadCursorWithItem();
+		pRenderer->EndScene();
+	}
+}
+ 
+//----- (004BF5B2) --------------------------------------------------------
+void MPlayer::_4BF5B2()
+{
+  pMouse->_469E24();
+  if ( window_SpeakInHouse && window_SpeakInHouse->ptr_1C == (void *)165 && !pMovie_Track)//!this->pSmackerMovie )
+  {
+    bGameoverLoop = true;
+    HouseDialogPressCloseBtn();
+    window_SpeakInHouse->Release();
+    pParty->uFlags &= 0xFFFFFFFD;
+    if ( EnterHouse(HOUSE_BODY_GUILD_ERATHIA) )
+    {
+      pAudioPlayer->PlaySound(SOUND_Invalid, 0, 0, -1, 0, 0, 0, 0);
+      window_SpeakInHouse = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_HouseInterior, 165, 0);
+      window_SpeakInHouse->CreateButton(0x3Du, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 1, 0x31, "", 0);
+      window_SpeakInHouse->CreateButton(0xB1u, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 2, 0x32, "", 0);
+      window_SpeakInHouse->CreateButton(0x124u, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 3, 0x33, "", 0);
+      window_SpeakInHouse->CreateButton(0x197u, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 4, 0x34, "", 0);
+    }
+    bGameoverLoop = 0;
+  }
+}
+
+//----- (004BF73A) --------------------------------------------------------
+void MPlayer::SelectMovieType()
+{
+  char Source[32]; // [sp+Ch] [bp-40h]@1
+
+  strcpy(Source, this->pCurrentMovieName);
+  pMediaPlayer->Unload();
+  if ( this->uMovieType == 1 )
+    OpenHouseMovie(Source, LOBYTE(this->bLoopPlaying));
+  else if ( this->uMovieType == 2 )
+    OpenGlobalMovie(Source, LOBYTE(this->bLoopPlaying));
+  else
+    __debugbreak();
+}
+
+void MPlayer::LoadMovie(const char *pFilename)
+{
+  char pVideoNameBik[120]; // [sp+Ch] [bp-28h]@2
+  char pVideoNameSmk[120]; // [sp+Ch] [bp-28h]@2
+
+  sprintf(pVideoNameBik, "%s.bik", pFilename);
+  sprintf(pVideoNameSmk, "%s.smk", pFilename);
+  for (uint i = 0; i < uNumMightVideoHeaders; ++i)
+  {
+    if (!_stricmp(pVideoNameSmk, pMightVideoHeaders[i].pVideoName))
+    {
+      hVidFile = hMightVid;
+      uOffset = pMightVideoHeaders[i].uFileOffset;
+      uSize = pMightVideoHeaders[i + 1].uFileOffset - uOffset;
+      this->uMovieType = 2;
+    }
+  }
+  for (uint i = 0; i < uNumMagicVideoHeaders; ++i)
+  {
+    if (!_stricmp(pVideoNameBik, pMagicVideoHeaders[i].pVideoName))
+    {
+      hVidFile = hMagicVid;
+      uOffset = pMagicVideoHeaders[i].uFileOffset;
+      uSize = pMagicVideoHeaders[i + 1].uFileOffset - uOffset;
+      this->uMovieType = 1;
+    }
+    if (!_stricmp(pVideoNameSmk, pMagicVideoHeaders[i].pVideoName))
+    {
+      hVidFile = hMagicVid;
+      uOffset = pMagicVideoHeaders[i].uFileOffset;
+      uSize = pMagicVideoHeaders[i + 1].uFileOffset - uOffset;
+      this->uMovieType = 2;
+    }
+  }
+  if (!hVidFile)
+  {
+    pMediaPlayer->Unload();
+    MessageBoxA(0, "MediaPlayer error", "MediaPlayer Error", 0);
+    return;
+  }
+
+  SetFilePointer(hVidFile, uOffset, 0, FILE_BEGIN);
+  strcpy(this->pCurrentMovieName, pFilename);
+
+  auto hwnd = pMediaPlayer->window->GetApiHandle();
+  RECT rc_client;
+  GetClientRect(hwnd, &rc_client);
+  int client_width = rc_client.right - rc_client.left,
+      client_height = rc_client.bottom - rc_client.top;
+
+  pMovie_Track = pMediaPlayer->LoadMovieFromLOD(hVidFile, &readFunction, &seekFunction, client_width, client_height);
+}
+
+
+//----- (004BF794) --------------------------------------------------------
+void MPlayer::ShowMM7IntroVideo_and_LoadingScreen()
+{
+  RGBTexture tex; // [sp+Ch] [bp-30h]@1
+  unsigned int uTrackStartMS; // [sp+34h] [bp-8h]@8
+  unsigned int uTrackEndMS; // [sp+38h] [bp-4h]@8
+
+  pMediaPlayer->bStopBeforeSchedule = false;
+//  pMediaPlayer->pResetflag = 0;
+  bGameoverLoop = true;
+  if (!bNoVideo)
+  {
+    pRenderer->PresentBlackScreen();
+    if ( !pMediaPlayer->bStopBeforeSchedule )
+      PlayFullscreenMovie(MOVIE_Intro, true);
+  }
+
+  tex.Load("mm6title.pcx", 2);
+  pRenderer->BeginScene();
+  pRenderer->DrawTextureRGB(0, 0, &tex);
+  free(tex.pPixels);
+  tex.pPixels = 0;
+
+  //LoadFonts_and_DrawCopyrightWindow();
+  DrawMM7CopyrightWindow();
+
+  pRenderer->EndScene();
+  pRenderer->Present();
+
+  #ifndef _DEBUG
+    Sleep(1500);   // let the copyright window stay for a while
+  #endif
+
+  if (!bNoSound && pAudioPlayer->hAILRedbook )
+  {
+    pAudioPlayer->SetMusicVolume((signed __int64)(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0));
+    AIL_redbook_stop(pAudioPlayer->hAILRedbook);
+    AIL_redbook_track_info(pAudioPlayer->hAILRedbook, 14, &uTrackStartMS, &uTrackEndMS);
+    AIL_redbook_play(pAudioPlayer->hAILRedbook, uTrackStartMS + 1, uTrackEndMS);
+  }
+  bGameoverLoop = false;
+}
+
+//----- (004BEBD7) --------------------------------------------------------
+void MPlayer::Unload()
+{
+  bPlaying_Movie = false;
+  uMovieType = 0;
+  memset(pCurrentMovieName, 0, 0x40);
+  if ( pAudioPlayer->hAILRedbook && !bGameoverLoop )
+    AIL_redbook_resume(pAudioPlayer->hAILRedbook);
+  pEventTimer->Resume();
+
+  pMovie_Track->Release();
+  delete pMovie_Track;
+  pMovie_Track = nullptr;
+}
+
+int MPlayer::readFunction(void* opaque, uint8_t* buf, int buf_size)
+{
+  HANDLE stream = (HANDLE)opaque;
+  //int numBytes = stream->read((char*)buf, buf_size);
+  int numBytes;
+  ReadFile(stream, (char *)buf, buf_size, (LPDWORD)&numBytes, NULL);
+  return numBytes;
+}
+
+int64_t MPlayer::seekFunction(void* opaque, int64_t offset, int whence)
+{
+  if (whence == AVSEEK_SIZE)
+    return pMediaPlayer->uSize;
+  HANDLE h = (HANDLE)opaque;
+  LARGE_INTEGER li;
+  li.QuadPart = offset;
+
+  if (!SetFilePointerEx(h, li, (PLARGE_INTEGER)&li, FILE_BEGIN))
+    return -1;
+  return li.QuadPart;
+}
+
+
 IMovie *MPlayer::LoadMovieFromLOD(HANDLE h, int readFunction(void*, uint8_t*, int), int64_t seekFunction(void*, int64_t, int), int width, int height)
 {
 	movie = new Movie;
@@ -1103,6 +1505,9 @@
 
 MPlayer::MPlayer()
 {
+  bPlaying_Movie = false;
+  //pSmackMovieBlit = nullptr;
+
   static int libavcodec_initialized = false;
 
   if (!libavcodec_initialized)
@@ -1111,14 +1516,15 @@
     avcodec_register_all();
 
     // Register all available file formats and codecs
-    //  ffmpeg( 1)
-    //           .
-    //              .
     av_register_all();
 
     libavcodec_initialized = true;
   }
 
+  bStopBeforeSchedule = false;
+//  pResetflag = 0;
+  pMovie_Track = nullptr;
+
   if (!provider)
   {
     provider = new OpenALSoundProvider;
@@ -1131,6 +1537,10 @@
 {
 	delete provider;
 	Log::Warning(L"delete dynamic memory for provider\n");
+
+    bStopBeforeSchedule = false;
+//    pResetflag = 0;
+    pVideoFrame.Release();
 }
 
 void PlayAudio(const wchar_t * pFilename)
@@ -1154,19 +1564,4 @@
   delete movie;
   Log::Warning(L"delete dynamic memory for movie\n");
   movie = nullptr;
-}
-
-//////////////////////////////////////////////////////////////////////////
-//Included from a VideoPlayer.cpp file/   VideoPlayer.cpp/
-//////////////////////////////////////////////////////////////////////////
-
-//used in void VideoPlayer::Initialize(OSWindow *target_window) for open .vid files
-MovieHeader *pMightVideoHeaders;
-MovieHeader *pMagicVideoHeaders;
-HANDLE hMightVid;
-HANDLE hMagicVid;
-unsigned __int64 uBinkVersion;
-unsigned int uNumMightVideoHeaders;
-unsigned int uNumMagicVideoHeaders;
-//
-
+}
\ No newline at end of file
--- a/MediaPlayer.h	Thu Jul 24 19:55:55 2014 +0100
+++ b/MediaPlayer.h	Fri Jul 25 14:19:14 2014 +0600
@@ -1,4 +1,44 @@
 #pragma once
+#include "OSWindow.h"
+#include "Texture.h"
+#include "MediaPlayer.h"
+
+#pragma pack(push, 1)
+
+#pragma pack(pop)
+
+#pragma pack(push, 1)
+#pragma pack(pop)
+
+
+
+extern "C"
+{
+#include "lib/libavcodec/avcodec.h"
+#include "lib/libavformat/avformat.h"
+#include "lib/libavutil/avutil.h"
+#include "lib/libavutil/imgutils.h"
+#include "lib/libswscale/swscale.h"
+#include "lib/libswresample/swresample.h"
+#include "lib/libavutil/opt.h"
+}
+#pragma comment(lib, "avcodec.lib")
+#pragma comment(lib, "avformat.lib")
+#pragma comment(lib, "avutil.lib")
+#pragma comment(lib, "swscale.lib")
+#pragma comment(lib, "swresample.lib")
+
+#include "lib/OpenAL/al.h"
+#include "lib/OpenAL/alc.h"
+#pragma comment(lib, "OpenAL32.lib")
+
+#pragma pack(push, 1)
+
+struct MovieHeader
+{
+  char pVideoName[40];
+  unsigned int uFileOffset;
+};
 
 namespace Media
 {
@@ -19,6 +59,7 @@
 	  virtual void Play() = 0;
       virtual void GetNextFrame(double dt, void *target_surface) = 0;
       virtual void Release() = 0;
+
   };
 
   class MPlayer
@@ -27,46 +68,67 @@
                MPlayer();
       virtual ~MPlayer();
 
-      ITrack *LoadTrack(const wchar_t *name);
+	  //for video/////////////////////////////////////////////////
+      RGBTexture pVideoFrame;
+      int field_44;//final video
+      unsigned int bFirstFrame;
+      unsigned int bLoopPlaying;
+      unsigned int bStopBeforeSchedule;
+      OSWindow *window;
+      int uMovieType;//0 - null, 1 - bik, 2 - smk
+      char pCurrentMovieName[64];
+      char pVideoFrameTextureFilename[32];
+	  MovieHeader *pMightVideoHeaders;
+      MovieHeader *pMagicVideoHeaders;
+      HANDLE hMightVid;
+      HANDLE hMagicVid;
+      unsigned int uNumMightVideoHeaders;
+      unsigned int uNumMagicVideoHeaders;
+	  bool bPlaying_Movie;
+      bool loop_current_file;
+      DWORD time_video_begin;
+      int current_movie_width;
+      int current_movie_height;
+
+      HANDLE hVidFile;
+      int uSize;
+      int uOffset;
+
+      void Initialize(OSWindow *window);
+
+      void OpenGlobalMovie(const char *pFilename, unsigned int bLoop);
+      void OpenHouseMovie(const char *pMovieName, unsigned int a3_1);
+
+	  void _4BF5B2();
+      void LoadMovie(const char *);
+      void SelectMovieType();
+
+	  void GlobalMovieLoop(const char *pMovieName, int a2);
+      void HouseMovieLoop();
+
+      void ShowMM7IntroVideo_and_LoadingScreen();
+      void Unload();
+	  ///////////////////////////////////////////////
+
       IMovie *LoadMovie(const wchar_t *name, int width, int height, int cache_ms);
       IMovie *LoadMovieFromLOD(HANDLE h, int readFunction(void*, uint8_t*, int), int64_t seekFunction(void*, int64_t, int), int width, int height);
+
+
+      ITrack *LoadTrack(const wchar_t *name);
+
+  protected:
+    static int readFunction(void *, uint8_t *, int);
+    static int64_t seekFunction(void *, int64_t, int);
   };
 };
-
+#pragma pack(pop)
 extern Media::MPlayer *pMediaPlayer;
 extern Media::IMovie *pMovie_Track;
 extern Media::ITrack *pAudio_Track;
 extern class Movie *movie;
 
-extern bool end_current_file;
-extern bool loop_current_file;
-extern DWORD time_video_begin;
-extern int current_movie_width;
-extern int current_movie_height;
-
 extern int mSourceID;
 
-//int64_t seekFunction(void* opaque, int64_t offset, int whence);
 extern void PlayMovie(const wchar_t * pFilename);
 extern void PlayAudio(const wchar_t * pFilename);
 extern void MovieRelease();
-
-//////////////////////////////////////////////////////////////////////////
-//Included from a VideoPlayer.h file/   VideoPlayer.h/
-//////////////////////////////////////////////////////////////////////////
-
-//used in void VideoPlayer::Initialize(OSWindow *target_window) for open .vid files
-struct MovieHeader
-{
-  char pVideoName[40];
-  unsigned int uFileOffset;
-};
-
-extern MovieHeader *pMightVideoHeaders;
-extern MovieHeader *pMagicVideoHeaders;
-extern HANDLE hMightVid;
-extern HANDLE hMagicVid;
-extern unsigned __int64 uBinkVersion;
-extern unsigned int uNumMightVideoHeaders;
-extern unsigned int uNumMagicVideoHeaders;
-//
\ No newline at end of file
--- a/NPC.cpp	Thu Jul 24 19:55:55 2014 +0100
+++ b/NPC.cpp	Fri Jul 25 14:19:14 2014 +0600
@@ -1,6 +1,7 @@
 #define _CRTDBG_MAP_ALLOC
 #include <stdlib.h>
 #include <crtdbg.h>
+
 #define _CRT_SECURE_NO_WARNINGS
 #include "mm7_unsorted_subs.h"
 #include "texts.h"
@@ -12,7 +13,7 @@
 #include "Party.h"
 #include "NPC.h"
 #include "GUIWindow.h"
-#include "VideoPlayer.h"
+#include "MediaPlayer.h"
 #include "Events.h"
 #include "UI\UIHouses.h"
 #include "Indoor.h"
@@ -290,7 +291,6 @@
 			test_string=tmp_pos+1;
 			} while ((decode_step<2)&&!break_loop);
 		}
-//_CrtDumpMemoryLeaks();
 	free(pNPCTopicTXT_Raw);
 	pNPCTopicTXT_Raw = (char *)pEvents_LOD->LoadRaw("npctopic.txt", 0);
 	strtok(pNPCTopicTXT_Raw, "\r");
@@ -1575,7 +1575,7 @@
   if ( uActiveCharacter )
     pPlayers[uActiveCharacter]->PlaySound((PlayerSpeech)61, 0);
 _return:
-  pVideoPlayer->_4BF5B2();//HouseVideo
+  pMediaPlayer->_4BF5B2();//HouseVideo
 }
 //----- (004B29F2) --------------------------------------------------------
 const char * ContractSelectText( int pEventCode )
--- a/OSWindow.cpp	Thu Jul 24 19:55:55 2014 +0100
+++ b/OSWindow.cpp	Fri Jul 25 14:19:14 2014 +0600
@@ -8,7 +8,7 @@
 #include "mm7_data.h"
 #include "Arcomage.h"
 #include "AudioPlayer.h"
-#include "VideoPlayer.h"
+#include "MediaPlayer.h"
 #include "Mouse.h"
 #include "Timer.h"
 #include "GUIWindow.h"
@@ -44,8 +44,8 @@
   if (UIControl::OnMouseLeftClick(x, y))
     return true;
 
-  if (pVideoPlayer->pVideoFrame.pPixels)
-    pVideoPlayer->bStopBeforeSchedule = true;
+  //if (pMediaPlayer->bPlaying_Movie)
+    //pMediaPlayer->bPlaying_Movie = false;
 
   pMouse->SetMouseClick(x, y);
 
@@ -64,8 +64,8 @@
   if (UIControl::OnMouseRightClick(x, y))
     return true;
 
-  if (pVideoPlayer->pVideoFrame.pPixels)
-    pVideoPlayer->bStopBeforeSchedule = true;
+  if (pMediaPlayer->bPlaying_Movie)
+    pMediaPlayer->bPlaying_Movie = false;
 
   pMouse->SetMouseClick(x, y);
 
@@ -225,8 +225,8 @@
       }
       if ( !pArcomageGame->bGameInProgress )
       {
-        if ( pVideoPlayer->pVideoFrame.pPixels )
-          pVideoPlayer->bStopBeforeSchedule = 1;
+        if ( pMediaPlayer->bPlaying_Movie )
+          pMediaPlayer->bPlaying_Movie = false;
         if ( wparam == VK_RETURN )
         {
           if ( !viewparams->field_4C )
@@ -247,7 +247,7 @@
           return 0;
         if ( wparam > VK_DOWN )
         {
-          if ( wparam != VK_F4 || pVideoPlayer->AnyMovieLoaded() )
+          if ( wparam != VK_F4 || pMovie_Track )
             return 0;
 
           // F4 - toggle fullscreen
@@ -280,7 +280,7 @@
       }
       if ( wparam != 114 )
       {
-        if ( wparam == 115 && !pVideoPlayer->AnyMovieLoaded() )
+        if ( wparam == 115 && !pMovie_Track )
           SendMessage(api_handle, WM_COMMAND, 104, 0);
         return false;
       }
@@ -336,9 +336,8 @@
         if (!(dword_6BE364_game_settings_1 & GAME_SETTINGS_APP_INACTIVE))
         {
           dword_4E98BC_bApplicationActive = 0;
-          if ( pMovie_Track//(pVideoPlayer->pSmackerMovie || pVideoPlayer->pBinkMovie) 
-			  && pVideoPlayer->bPlayingMovie )
-            pVideoPlayer->bStopBeforeSchedule = 1;
+          if ( pMovie_Track  )
+            pMediaPlayer->bPlaying_Movie = true;
 
           ClipCursor(0);
           dword_6BE364_game_settings_1 |= GAME_SETTINGS_APP_INACTIVE;
@@ -466,15 +465,9 @@
   {
     CREATESTRUCTA* cs = (CREATESTRUCTA *)(lparam);
     OSWindow* window = (OSWindow *)cs->lpCreateParams;
-	// SetWindowLongPtr    .     
-	//       .
     SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR)window);
     return DefWindowProcW(hwnd, msg, wparam, lparam);
   }
-  // GetWindowLongPtr     .       
-  //      .
-  //GWLP_USERDATA -   ,   .      , 
-  //  .     .
   OSWindow* window = (OSWindow *)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
   if (window && window->api_handle == hwnd)	//Uninitialized memory access
   {
@@ -482,19 +475,15 @@
     if (window->WinApiMessageProc(msg, wparam, lparam, &result))//Unhandled application exception
       return result;
   }
-  // DefWindowProc     ,       
-  // ,    .    ,    . 
   return DefWindowProcW(hwnd, msg, (WPARAM)wparam, (LPARAM)lparam);
 }
 
-
 void OSWindow::Show()
 {
   ShowWindow(api_handle, SW_SHOWNORMAL);
   UpdateWindow(api_handle);
 }
 
-
 void OSWindow::SetCursor(const char *cursor_name)
 {
   POINT cursor_pos;
@@ -505,19 +494,19 @@
     SetClassLongPtrW(api_handle, GCLP_HCURSOR, (LONG)LoadCursorW(NULL, IDC_ARROW));
   else if (!strcmp(cursor_name, "MICON2") )
   {
-    //HCURSOR hCurs1; //   
+    //HCURSOR hCurs1;
  
-    //     . 
+    // Create target 
  
-    //pMouse->uCursorTextureID = pIcons_LOD->LoadTexture(cursor_name, TEXTURE_16BIT_PALETTE);//  
-    //hCurs1 = LoadCursor(NULL, L"Target");//,   / 
+    //pMouse->uCursorTextureID = pIcons_LOD->LoadTexture(cursor_name, TEXTURE_16BIT_PALETTE);
+    //hCurs1 = LoadCursor(NULL, L"Target");
     SetClassLongPtrW(api_handle, GCLP_HCURSOR, (LONG)LoadCursorW(NULL, IDC_CROSS));
 
   }
   else if (!strcmp(cursor_name, "MICON3") )
     SetClassLongPtrW(api_handle, GCLP_HCURSOR, (LONG)LoadCursorW(NULL, IDC_WAIT));
 
-  //ClientToScreen(api_handle, &cursor_pos); //     
+  //ClientToScreen(api_handle, &cursor_pos); //???
   SetCursorPos(cursor_pos.x, cursor_pos.y);
 }
 
@@ -891,26 +880,26 @@
     }
     break;
         //SubMenu "Other"
-    case 40101:  wizard_eye = true;  break;                           //  
-    case 40102:  wizard_eye = false;  break;                          //  
-    case 40103:  pODMRenderParams->shading_dist_mist = 0x6000;  break;//   
-    case 40104:  pODMRenderParams->shading_dist_mist = 0x2000;  break;////   
-    case 40105:  change_seasons = true;  break;                           //   
-    case 40106:  change_seasons = false;  break;                          //   
-    case 40107:  all_magic = true;  break;                           //  (    )
-    case 40108:  all_magic = false;  break;                          //  
-    case 40109:  debug_information = true;  break;                           //  fps,  ,    ..
-    case 40110:  debug_information = false;  break;                          //  fps,  ,    ..
-    case 40111:  show_picked_face = true;  break;                           //   
-    case 40112:  show_picked_face = false;  break;                          //   
-    case 40113:  draw_portals_loops = true;  break;                           //   
-    case 40114:  draw_portals_loops = false;  break;                          //   
-    case 40115:  new_speed = true;  break;                           //  
-    case 40116:  new_speed = false;  break;                          //  
-    case 40117:  bSnow = true;  break;                           // 
-    case 40118:  bSnow = false;  break;                          // 
-    case 40119:  draw_terrain_dist_mist = true;  break;                           //   
-    case 40120:  draw_terrain_dist_mist = false;  break;                          //   
+    case 40101:  wizard_eye = true;  break;
+    case 40102:  wizard_eye = false;  break;
+    case 40103:  pODMRenderParams->shading_dist_mist = 0x6000;  break;
+    case 40104:  pODMRenderParams->shading_dist_mist = 0x2000;  break;
+    case 40105:  change_seasons = true;  break;
+    case 40106:  change_seasons = false;  break;
+    case 40107:  all_magic = true;  break;
+    case 40108:  all_magic = false;  break;
+    case 40109:  debug_information = true;  break;
+    case 40110:  debug_information = false;  break;
+    case 40111:  show_picked_face = true;  break;
+    case 40112:  show_picked_face = false;  break;
+    case 40113:  draw_portals_loops = true;  break;
+    case 40114:  draw_portals_loops = false;  break;
+    case 40115:  new_speed = true;  break;
+    case 40116:  new_speed = false;  break;
+    case 40117:  bSnow = true;  break;
+    case 40118:  bSnow = false;  break;
+    case 40119:  draw_terrain_dist_mist = true;  break;
+    case 40120:  draw_terrain_dist_mist = false;  break;
 
   }
 
--- a/Render.cpp	Thu Jul 24 19:55:55 2014 +0100
+++ b/Render.cpp	Fri Jul 25 14:19:14 2014 +0600
@@ -9,7 +9,7 @@
 
 #include "Render.h"
 #include "Outdoor_stuff.h"
-#include "VideoPlayer.h"
+#include "MediaPlayer.h"
 #include "Sprites.h"
 #include "Mouse.h"
 #include "GammaControl.h"
@@ -8246,8 +8246,8 @@
         v5->uParticleTrailColor = v5->uParticleTrailColorB | (v4 << 8);
       }
       SetUserInterface(pParty->alignment, true);
-      if ( pVideoPlayer->pVideoFrame.pPixels )
-        pVideoPlayer->pVideoFrame.Load(pVideoPlayer->pVideoFrameTextureFilename, 1);
+      if ( pMediaPlayer->pVideoFrame.pPixels )
+        pMediaPlayer->pVideoFrame.Load(pMediaPlayer->pVideoFrameTextureFilename, 1);
       if ( sCurrentMenuID != MENU_CREATEPARTY )
       {
         if ( sCurrentMenuID == MENU_CREDITSPROC )
@@ -8282,8 +8282,8 @@
       ShowWindow(hWnd, SW_SHOWNORMAL);
     }*/
     pMouse->bActive = true;
-    if ( pVideoPlayer->AnyMovieLoaded() )
-      pVideoPlayer->SelectMovieType();
+    if ( pMovie_Track )
+      pMediaPlayer->SelectMovieType();
     if (dword_6BE364_game_settings_1 & GAME_SETTINGS_0800)
       dword_6BE364_game_settings_1 &= ~GAME_SETTINGS_0800;
     else
--- a/SaveLoad.cpp	Thu Jul 24 19:55:55 2014 +0100
+++ b/SaveLoad.cpp	Fri Jul 25 14:19:14 2014 +0600
@@ -26,9 +26,9 @@
 #include "stru123.h"
 #include "texts.h"
 #include "Log.h"
-#include "VideoPlayer.h"
 #include "Level/Decoration.h"
 #include "Render.h"
+#include "MediaPlayer.h"
 
 #include "mm7_data.h"
 
@@ -574,7 +574,7 @@
   void *pSave; // [sp+170h] [bp-8h]@3
 
   if ( pMovie_Track )
-    pVideoPlayer->Unload();
+    pMediaPlayer->Unload();
   pSave = malloc(1000000);
   pNew_LOD->CloseWriteFile();
   remove("data\\new.lod");// new.lod
--- a/UI/UIHouses.cpp	Thu Jul 24 19:55:55 2014 +0100
+++ b/UI/UIHouses.cpp	Fri Jul 25 14:19:14 2014 +0600
@@ -25,7 +25,7 @@
 #include "..\Outdoor.h"
 #include "..\Outdoor_stuff.h"
 #include "..\AudioPlayer.h"
-#include "..\VideoPlayer.h"
+#include "..\MediaPlayer.h"
 #include "..\Monsters.h"
 #include "..\Viewport.h"
 #include "..\Keyboard.h"
@@ -893,7 +893,7 @@
 		uTextureID_right_panel_loop = uTextureID_right_panel;
 		if ( uNumDialogueNPCPortraits == 1 )
 			pDialogueNPCCount = 1;
-		pVideoPlayer->OpenHouseMovie(pAnimatedRooms[uCurrentHouse_Animation].video_name, 1u);
+		pMediaPlayer->OpenHouseMovie(pAnimatedRooms[uCurrentHouse_Animation].video_name, 1u);
 		dword_5C35D4 = 1;
 		if ( (signed int)uHouseID < 139 || (signed int)uHouseID > 172 )
         {
@@ -2059,7 +2059,7 @@
         dialog_menu_id = HOUSE_DIALOGUE_NULL;
         HouseDialogPressCloseBtn();
         GetHouseGoodbyeSpeech();
-        pVideoPlayer->Unload();
+        pMediaPlayer->Unload();
         /*if ( pMessageQueue_50CBD0->uNumMessages )
           pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
         pMessageQueue_50CBD0->pMessages[0].eType = UIMSG_RentRoom;
@@ -3329,13 +3329,13 @@
   {
     case -1:
       _4B4224_UpdateNPCTopics((int)((char *)pDialogueNPCCount - 1));
-      pVideoPlayer->_4BF5B2();
+      pMediaPlayer->_4BF5B2();
       break;
 
     case HOUSE_DIALOGUE_SHOP_DISPLAY_EQUIPMENT:
     case HOUSE_DIALOGUE_LEARN_SKILLS:
     case HOUSE_DIALOGUE_TAVERN_ARCOMAGE_MAIN:
-      pVideoPlayer->_4BF5B2();
+      pMediaPlayer->_4BF5B2();
       UI_CreateEndConversationButton();
       dialog_menu_id = HOUSE_DIALOGUE_MAIN;
       InitializaDialogueOptions(in_current_building_type);
@@ -3352,7 +3352,7 @@
     case HOUSE_DIALOGUE_TAVERN_ARCOMAGE_RULES:
     case HOUSE_DIALOGUE_TAVERN_ARCOMAGE_VICTORY_CONDITIONS:
     case HOUSE_DIALOGUE_TAVERN_ARCOMAGE_RESULT:
-      pVideoPlayer->_4BF5B2();
+      pMediaPlayer->_4BF5B2();
       UI_CreateEndConversationButton();
       dialog_menu_id = HOUSE_DIALOGUE_TAVERN_ARCOMAGE_MAIN;
       InitializaDialogueOptions_Tavern(in_current_building_type);
@@ -3380,11 +3380,11 @@
         }
       }
 
-      pVideoPlayer->_4BF5B2();
+      pMediaPlayer->_4BF5B2();
       break;
 
     default:
-      pVideoPlayer->_4BF5B2();
+      pMediaPlayer->_4BF5B2();
       dialog_menu_id = HOUSE_DIALOGUE_MAIN;
       InitializaDialogueOptions(in_current_building_type);
       break;
--- a/UI/UITransition.cpp	Thu Jul 24 19:55:55 2014 +0100
+++ b/UI/UITransition.cpp	Fri Jul 25 14:19:14 2014 +0600
@@ -8,7 +8,7 @@
 #include "..\ErrorHandling.h"
 #include "..\mm7_unsorted_subs.h"
 #include "..\mm7_data.h"
-#include "..\VideoPlayer.h"
+#include "..\MediaPlayer.h"
 #include "..\MapInfo.h"
 #include "..\GUIWindow.h"
 #include "..\GUIFont.h"
@@ -56,7 +56,7 @@
   if (anim_id)
   {
     if ( !IndoorLocation::GetLocationIndex(pLocationName) )
-      pVideoPlayer->OpenHouseMovie(pAnimatedRooms[p2DEvents[anim_id - 1].uAnimationID].video_name, 1);
+      pMediaPlayer->OpenHouseMovie(pAnimatedRooms[p2DEvents[anim_id - 1].uAnimationID].video_name, 1);
   }
   else if ( !IndoorLocation::GetLocationIndex(pLocationName) )
   {
--- a/VideoPlayer.cpp	Thu Jul 24 19:55:55 2014 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,543 +0,0 @@
-#define _CRTDBG_MAP_ALLOC
-#include <stdlib.h>
-#include <crtdbg.h>
-
-#define _CRT_SECURE_NO_WARNINGS
-
-#include "mm7_unsorted_subs.h"
-#include "Bink_Smacker.h"
-
-#include "mm7_data.h"
-#include "CShow.h"
-#include "Mouse.h"
-
-#include "VideoPlayer.h"
-#include "MediaPlayer.h"
-#include "AudioPlayer.h"
-#include "Game.h"
-#include "Render.h"
-#include "Party.h"
-#include "GUIWindow.h"
-#include "Timer.h"
-#include "Log.h"
-#include "texts.h"
-#include "UI\UIHouses.h"
-
-VideoPlayer *pVideoPlayer = nullptr;
-
- #pragma comment(lib, "Version.lib")
-bool GetDllVersion(const wchar_t *pDllName, uint *pMajor, uint *pMinor)
-{
-  uint uVersionSize = GetFileVersionInfoSizeW(pDllName, nullptr);
-  void *pVersionData = HeapAlloc(GetProcessHeap(), 0, uVersionSize);
-  {
-    GetFileVersionInfoW(pDllName, 0, uVersionSize, pVersionData);
-
-    VS_FIXEDFILEINFO *pInfo = nullptr;
-    UINT              uInfoSize = 0;
-    VerQueryValueW(pVersionData, L"\\", (void **)&pInfo, &uInfoSize);
-
-    if (!pMajor || !pMinor)
-    {
-      HeapFree(GetProcessHeap(), 0, pVersionData);
-      return false;
-    }
-    *pMajor = pInfo->dwFileVersionMS;
-    *pMinor = pInfo->dwFileVersionLS;
-  }
-  HeapFree(GetProcessHeap(), 0, pVersionData);
-  return true;
-}
-
-//----- (004BF794) --------------------------------------------------------
-void ShowMM7IntroVideo_and_LoadingScreen()
-{
-  RGBTexture tex; // [sp+Ch] [bp-30h]@1
-  unsigned int uTrackStartMS; // [sp+34h] [bp-8h]@8
-  unsigned int uTrackEndMS; // [sp+38h] [bp-4h]@8
-
-  pVideoPlayer->bStopBeforeSchedule = false;
-  pVideoPlayer->pResetflag = 0;
-  bGameoverLoop = true;
-  if (!bNoVideo)
-  {
-    pRenderer->PresentBlackScreen();
-    if ( !pVideoPlayer->bStopBeforeSchedule )
-      PlayFullscreenMovie(MOVIE_Intro, true);
-  }
-//  char pContainerName[64];
-
-  tex.Load("mm6title.pcx", 2);
-  pRenderer->BeginScene();
-  pRenderer->DrawTextureRGB(0, 0, &tex);
-  free(tex.pPixels);
-  tex.pPixels = 0;
-
-  //LoadFonts_and_DrawCopyrightWindow();
-  DrawMM7CopyrightWindow();
-
-  pRenderer->EndScene();
-  pRenderer->Present();
-
-  #ifndef _DEBUG
-    Sleep(1500);   // let the copyright window stay for a while
-  #endif
-
-  if (!bNoSound && pAudioPlayer->hAILRedbook )
-  {
-    pAudioPlayer->SetMusicVolume((signed __int64)(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0));
-    AIL_redbook_stop(pAudioPlayer->hAILRedbook);
-    AIL_redbook_track_info(pAudioPlayer->hAILRedbook, 14, &uTrackStartMS, &uTrackEndMS);
-    AIL_redbook_play(pAudioPlayer->hAILRedbook, uTrackStartMS + 1, uTrackEndMS);
-  }
-  bGameoverLoop = false;
-}
-
-//----- (004BE70E) --------------------------------------------------------
-void VideoPlayer::MovieLoop(const char *pMovieName, int a2/*, int ScreenSizeFlag, int a4*/)
-{
-  int v4; // ebp@1
-  MSG Msg; // [sp+Ch] [bp-1Ch]@12
-
-  v4 = a2;
-  if ( dword_6BE364_game_settings_1 & (GAME_SETTINGS_NO_HOUSE_ANIM | GAME_SETTINGS_NO_INTRO) ||
-	   bNoVideo)
-    return;
-
-    if ( a2 == 2 )
-      v4 = 0;
-    ShowCursor(0);// 
-    OpenGlobalMovie(pMovieName, 0);
-    bPlayingMovie = 1;
-    field_44 = v4;
-    pRenderer->ClearTarget(0);
-    pCurrentScreen = SCREEN_VIDEO;
-
-    auto hwnd = pVideoPlayer->window->GetApiHandle();
-
-    RECT rc_client;
-    GetClientRect(hwnd, &rc_client);
-    int client_width = rc_client.right - rc_client.left,
-        client_height = rc_client.bottom - rc_client.top;
-
-    HDC     dc = GetDC(hwnd);
-    HDC     back_dc = CreateCompatibleDC(dc);
-	HBITMAP back_bmp = CreateCompatibleBitmap(dc, client_width, client_height);
-	auto    frame_buffer = new char[client_width * client_height * 4];
-    SelectObject(back_dc, back_bmp);
-
-	DWORD t = GetTickCount();//    
-
-	end_current_file = false;//   
-
-    while (true) //  
-    {
-      if (pVideoPlayer->bStopBeforeSchedule)
-        break;
-      while (PeekMessageA(&Msg, hwnd, 0, 0, PM_REMOVE))
-      {
-        if (Msg.message == WM_QUIT)
-          Game_DeinitializeAndTerminate(0);
-        if (Msg.message == WM_PAINT)
-          break;
-        TranslateMessage(&Msg);
-        DispatchMessageA(&Msg);
-      }
-
-      double dt = (GetTickCount() - t) / 1000.0; // 
-      t = GetTickCount();
-
-      pMovie_Track->GetNextFrame(dt, frame_buffer);	//  
-
-      if (end_current_file)//   ?
-        break;
-
-      if (frame_buffer)
-      {
-        // draw to hwnd
-        BITMAPINFO bmi;
-        bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
-        bmi.bmiHeader.biWidth = client_width;
-        bmi.bmiHeader.biHeight = -client_height;
-        bmi.bmiHeader.biPlanes = 1;
-        bmi.bmiHeader.biBitCount = 32;
-        bmi.bmiHeader.biCompression = BI_RGB;
-        bmi.bmiHeader.biSizeImage = 0;
-        bmi.bmiHeader.biXPelsPerMeter = 0;
-        bmi.bmiHeader.biYPelsPerMeter = 0;
-        bmi.bmiHeader.biClrUsed = 0;
-        bmi.bmiHeader.biClrImportant = 0;
-        GetDIBits(back_dc, back_bmp, 0, client_height, 0, &bmi, DIB_RGB_COLORS);
-        SetDIBits(back_dc, back_bmp, 0, client_height, frame_buffer, &bmi, DIB_RGB_COLORS);
-        BitBlt(dc, 0, 0, client_width, client_height, back_dc, 0, 0, SRCCOPY);
-      }
-
-      GUI_MainMenuMessageProc();  // , ..   dt = 0.03, image - ???
-
-      if (pVideoPlayer->bStopBeforeSchedule == 1)// 
-        Sleep(1000); //  
-    }
-	delete [] frame_buffer;
-	DeleteObject(back_bmp);
-	DeleteObject(back_dc);
-	ReleaseDC(hwnd, dc);
-
-    pVideoPlayer->Unload();
-
-    //if (a4 == 1)
-      pCurrentScreen = SCREEN_GAME;
-
-    pVideoPlayer->bPlayingMovie = 0;
-
-    ShowCursor(1);// 
-
-    /*if ( pCurrentScreen == SCREEN_VIDEO )
-      pCurrentScreen = SCREEN_GAME;*/
-}
-
-//----- (004BE9D8) --------------------------------------------------------
-void VideoPlayer::Initialize(OSWindow *target_window)
-{
-  DWORD NumberOfBytesRead; // [sp+10h] [bp-4h]@9
-    
-  window = target_window;
-
-  uint uBinkVersionMajor = -1,
-       uBinkVersionMinor = -1;
-  GetDllVersion(L"BINKW32.DLL", &uBinkVersionMajor, &uBinkVersionMinor);
-  uBinkVersion = (unsigned __int64)uBinkVersionMajor << 32 | uBinkVersionMinor;
-
-  strcpy(pTmpBuf.data(), "anims\\might7.vid");
-  hMightVid = CreateFileW(L"anims\\might7.vid", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0x8000080, 0);
-  if ( hMightVid == INVALID_HANDLE_VALUE )
-  {
-    sprintf(pTmpBuf2.data(), "Can't open file - anims\\%s.smk", pTmpBuf.data());
-    MessageBoxA(0, pTmpBuf2.data(), "Video File Error", 0);
-    return;
-  }
-  strcpy(pTmpBuf.data(), "anims\\magic7.vid");
-  hMagicVid = CreateFileW(L"anims\\magic7.vid", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0x8000080, 0);
-  if ( hMagicVid == INVALID_HANDLE_VALUE )
-  {
-    if ( !bCanLoadFromCD )
-    {
-       sprintf(pTmpBuf2.data(), "Can't open file - anims\\%s.smk", pTmpBuf.data());
-       MessageBoxA(0, pTmpBuf2.data(), "Video File Error", 0);
-       return;
-    }
-    sprintf(pTmpBuf2.data(), "%c:\\%s", (unsigned __int8)cMM7GameCDDriveLetter, pTmpBuf.data());
-    hMagicVid = CreateFileA(pTmpBuf2.data(), GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0x8000080, 0);
-    if ( hMagicVid == (HANDLE)INVALID_HANDLE_VALUE )
-    {
-      sprintf(pTmpBuf2.data(), "Can't open file - %s", pTmpBuf.data());
-      MessageBoxA(0, pTmpBuf2.data(), "Video File Error", 0);
-      return;
-    }
-  }
-  ReadFile(hMightVid, &uNumMightVideoHeaders, 4, &NumberOfBytesRead, 0);
-  ReadFile(hMagicVid, &uNumMagicVideoHeaders, 4, &NumberOfBytesRead, 0);
-  pMightVideoHeaders = (MovieHeader *)malloc(sizeof(MovieHeader) * uNumMightVideoHeaders + 2);
-  pMagicVideoHeaders = (MovieHeader *)malloc(sizeof(MovieHeader) * uNumMagicVideoHeaders + 2);
-  ReadFile(hMightVid, pMightVideoHeaders, 44 * uNumMightVideoHeaders, &NumberOfBytesRead, 0);
-  ReadFile(hMagicVid, pMagicVideoHeaders, 44 * uNumMagicVideoHeaders, &NumberOfBytesRead, 0);
-}
-
-//----- (004BEBD7) --------------------------------------------------------
-void VideoPlayer::Unload()
-{
-  if ( pSmackMovieBlit )
-  {
-    SmackBlitClose(pSmackMovieBlit);
-    pSmackMovieBlit = 0;
-  }
-  bBufferLoaded = 0;
-  uMovieFormat = 0;
-  uMovieFormatSwapped = 0;
-  memset(pCurrentMovieName, 0, 0x40);
-  if ( pAudioPlayer->hAILRedbook && !bGameoverLoop )
-    AIL_redbook_resume(pAudioPlayer->hAILRedbook);
-  pEventTimer->Resume();
-
-  pMovie_Track->Release();
-  delete pMovie_Track;
-  pMovie_Track = nullptr;
-}
-
-void VideoPlayer::_inlined_in_463149()
-{
-	if (pMovie_Track && !bNoVideo)
-	{
-		pRenderer->BeginScene();
-		pMouse->DrawCursorToTarget();
-		UpdatePalette();
-		pMouse->ReadCursorWithItem();
-		pRenderer->EndScene();
-	}
-}
-
-void VideoPlayer::UpdatePalette() //UpdateVideo
-{
-  Log::Warning(L"smacker");
-  loop_current_file = true;// 
-  pRenderer->BeginScene();
-  if (end_current_file)// /
-  {
-    unsigned int width = game_viewport_width;
-    unsigned int height = game_viewport_height;
-	MovieRelease();
-
-    SetFilePointer(hVidFile, uOffset, nullptr, FILE_BEGIN);
-    pMovie_Track = nullptr;
-	Log::Warning(L"reload pMovie_Track");
-    pMovie_Track = pMediaPlayer->LoadMovieFromLOD(hVidFile, &readFunction, &seekFunction, width, height);
-	end_current_file = false;
-  }
-  //else 
-  //{
-      double dt = (GetTickCount() - time_video_begin) / 1000.0;
-      //dt = 1.0/15.0;
-      time_video_begin = GetTickCount();
-
-      //log("dt=%.5f\n", dt);
-
-      auto image = new char[current_movie_width * current_movie_height * 4];
-
-      pMovie_Track->GetNextFrame(dt, image);
-
-    int image_array[460 * 344];//game_viewport_width * game_viewport_height
-    if (image)
-    {
-      memcpy(image_array, image, sizeof (image_array));
-      for (unsigned int y = 8; y < 8 + game_viewport_height; ++y)//  
-      {
-        for (unsigned int x = 8; x < 8 + game_viewport_width; ++x)
-        {
-          auto p = (unsigned __int32 *)pRenderer->pTargetSurface + x + y * pRenderer->uTargetSurfacePitch;
-          *p = image_array[((x - 8) + ((y - 8)*game_viewport_width))];
-        }
-      }
-      delete[] image;
-    }
-  //}
-  pRenderer->EndScene();
-}
-
-//----- (004BF28F) --------------------------------------------------------
-void VideoPlayer::OpenHouseMovie(const char *pMovieName, unsigned int a3_1)
-{
-  if (!this->bBufferLoaded)
-  {
-    //Prepare();
-    pEventTimer->Pause();
-    if (pAudioPlayer->hAILRedbook)
-      AIL_redbook_pause(pAudioPlayer->hAILRedbook);
-
-    bStopBeforeSchedule = false;
-    bBufferLoaded = 1;
-    bPlayingMovie = false;
-    bFirstFrame = false;
-    bUsingSmackerMMX = SmackUseMMX(1);
-
-    this->bLoopPlaying = a3_1;
-    if ( LOBYTE(this->field_104) == 1 )
-    {
-      MessageBoxA(nullptr, "Unsupported Bink playback!", "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Video.cpp:925", 0);
-      return;
-    }
-
-    LoadMovie(pMovieName);
-	time_video_begin = GetTickCount();
-  }
-}
-
-//----- (004BF3F9) --------------------------------------------------------
-bool VideoPlayer::AnyMovieLoaded()
-{
-  return pMovie_Track != 0;
-  /*if (pMovie_Track)
-	return pMovie_Track;// pSmackerMovie || pBinkMovie;
-  else
-	  return false;*/
-}
-
-//----- (004BF411) --------------------------------------------------------
-void VideoPlayer::OpenGlobalMovie(const char *pFilename, unsigned int bLoop/*, int ScreenSizeFlag*/)
-{
-//  unsigned int v10; // eax@11
-
-  if (!this->bBufferLoaded)
-  {
-    pEventTimer->Pause();
-	if (pAudioPlayer->hAILRedbook)
-		AIL_redbook_pause(pAudioPlayer->hAILRedbook);
-
-	bStopBeforeSchedule = false;
-	bBufferLoaded = 1;
-	bPlayingMovie = false;
-	bFirstFrame = false;
-	bUsingSmackerMMX = SmackUseMMX(1);
-	this->bLoopPlaying = bLoop;
-	LoadMovie(pFilename);
-	return;
-  }
-}
-
- //----- (004BF5B2) --------------------------------------------------------
-void VideoPlayer::_4BF5B2()
-{
-	//__debugbreak();
-	
-  /*if ( this->uMovieFormat == 2 )
-  {
-    BinkGoto(pBinkMovie, 1, 0);
-    BinkDoFrame(pBinkMovie);
-    BinkNextFrame(pBinkMovie);
-  }
-  else
-  {
-    if ( this->uMovieFormat != 1 )
-      return;
-    SmackGoto(pSmackerMovie, 1);
-    if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
-    {
-      SmackDoFrame(pSmackerMovie);
-      SmackNextFrame(pSmackerMovie);
-    }
-  }*/
-  pMouse->_469E24();
-  if ( window_SpeakInHouse && window_SpeakInHouse->ptr_1C == (void *)165 && !pMovie_Track)//!this->pSmackerMovie )
-  {
-    bGameoverLoop = true;
-    HouseDialogPressCloseBtn();
-    window_SpeakInHouse->Release();
-    pParty->uFlags &= 0xFFFFFFFD;
-    if ( EnterHouse(HOUSE_BODY_GUILD_ERATHIA) )
-    {
-      pAudioPlayer->PlaySound(SOUND_Invalid, 0, 0, -1, 0, 0, 0, 0);
-      window_SpeakInHouse = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_HouseInterior, 165, 0);
-      window_SpeakInHouse->CreateButton(0x3Du, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 1, 0x31, "", 0);
-      window_SpeakInHouse->CreateButton(0xB1u, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 2, 0x32, "", 0);
-      window_SpeakInHouse->CreateButton(0x124u, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 3, 0x33, "", 0);
-      window_SpeakInHouse->CreateButton(0x197u, 0x1A8u, 0x1Fu, 0, 2, 94, UIMSG_SelectCharacter, 4, 0x34, "", 0);
-    }
-    bGameoverLoop = 0;
-  }
-}
-
-//----- (004BF73A) --------------------------------------------------------
-void VideoPlayer::SelectMovieType()
-{
-  char Source[32]; // [sp+Ch] [bp-40h]@1
-
-  strcpy(Source, this->pCurrentMovieName);
-  Unload();
-  if ( this->uMovieFormatSwapped == 1 )
-    OpenHouseMovie(Source, LOBYTE(this->bLoopPlaying));
-  else if ( this->uMovieFormatSwapped == 2 )
-    OpenGlobalMovie(Source, LOBYTE(this->bLoopPlaying));
-  else
-    __debugbreak();
-}
-
-//----- (004BF8F6) --------------------------------------------------------
-void VideoPlayer::PlayDeathMovie()
-{
-  bStopBeforeSchedule = 0;
-  pResetflag = 0;
-  PlayFullscreenMovie(MOVIE_Death, true);
-  //pGame->pCShow->PlayMovie(MOVIE_Death, 1);
-}
-
-//----- (004BE6F5) --------------------------------------------------------
-VideoPlayer::VideoPlayer() :
-bBufferLoaded(0),
-  //pBinkMovie(nullptr), pBinkBuffer(nullptr),
-  //pSmackerMovie(nullptr), pSmackerBuffer(nullptr), 
-  pSmackMovieBlit(nullptr)
-{
-  //RGBTexture::RGBTexture(&pVideoPlayer->pVideoFrame);
-  bStopBeforeSchedule = false;
-  pResetflag = 0;
-  pMediaPlayer = new Media::MPlayer;// 
-  Log::Warning(L"allocation dynamic memory for pMediaPlayer\n");
-  pMovie_Track = nullptr;
-  //pBinkMovie = nullptr;
-}
-
-int VideoPlayer::readFunction(void* opaque, uint8_t* buf, int buf_size)
-{
-  HANDLE stream = (HANDLE)opaque;
-  //int numBytes = stream->read((char*)buf, buf_size);
-  int numBytes;
-  ReadFile(stream, (char *)buf, buf_size, (LPDWORD)&numBytes, NULL);
-  return numBytes;
-}
-
-int64_t VideoPlayer::seekFunction(void* opaque, int64_t offset, int whence)
-{
-  if (whence == AVSEEK_SIZE)
-    return pVideoPlayer->uSize;
-  HANDLE h = (HANDLE)opaque;
-  LARGE_INTEGER li;
-  li.QuadPart = offset;
-
-  if (!SetFilePointerEx(h, li, (PLARGE_INTEGER)&li, FILE_BEGIN))
-    return -1;
-  return li.QuadPart;
-}
-
-void VideoPlayer::LoadMovie(const char *pFilename)
-{
-  char pVideoNameBik[120]; // [sp+Ch] [bp-28h]@2
-  char pVideoNameSmk[120]; // [sp+Ch] [bp-28h]@2
-
-  sprintf(pVideoNameBik, "%s.bik", pFilename);
-  sprintf(pVideoNameSmk, "%s.smk", pFilename);
-  for (uint i = 0; i < uNumMightVideoHeaders; ++i)
-  {
-    if (!_stricmp(pVideoNameSmk, pMightVideoHeaders[i].pVideoName))
-    {
-      hVidFile = hMightVid;
-      uOffset = pMightVideoHeaders[i].uFileOffset;
-      uSize = pMightVideoHeaders[i + 1].uFileOffset - uOffset;
-      this->uMovieFormat = 1;
-      this->uMovieFormatSwapped = 2;
-    }
-  }
-  for (uint i = 0; i < uNumMagicVideoHeaders; ++i)
-  {
-    if (!_stricmp(pVideoNameBik, pMagicVideoHeaders[i].pVideoName))
-    {
-      hVidFile = hMagicVid;
-      uOffset = pMagicVideoHeaders[i].uFileOffset;
-      uSize = pMagicVideoHeaders[i + 1].uFileOffset - uOffset;
-      this->uMovieFormat = 2;
-      this->uMovieFormatSwapped = 1;
-    }
-    if (!_stricmp(pVideoNameSmk, pMagicVideoHeaders[i].pVideoName))
-    {
-      hVidFile = hMagicVid;
-      uOffset = pMagicVideoHeaders[i].uFileOffset;
-      uSize = pMagicVideoHeaders[i + 1].uFileOffset - uOffset;
-      this->uMovieFormat = 1;
-      this->uMovieFormatSwapped = 2;
-    }
-  }
-  if (!hVidFile)
-  {
-    Unload();
-    MessageBoxA(0, "VideoPlayer error", "VideoPlayer Error", 0);
-    return;
-  }
-
-  SetFilePointer(hVidFile, uOffset, 0, FILE_BEGIN);
-  strcpy(this->pCurrentMovieName, pFilename);
-
-  auto hwnd = pVideoPlayer->window->GetApiHandle();
-  RECT rc_client;
-  GetClientRect(hwnd, &rc_client);
-  int client_width = rc_client.right - rc_client.left,
-      client_height = rc_client.bottom - rc_client.top;
-
-  pMovie_Track = pMediaPlayer->LoadMovieFromLOD(hVidFile, &readFunction, &seekFunction, client_width, client_height);
-}
--- a/VideoPlayer.h	Thu Jul 24 19:55:55 2014 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,97 +0,0 @@
-#pragma once
-#include "OSWindow.h"
-#include "Texture.h"
-#include "MediaPlayer.h"
-
-#pragma pack(push, 1)
-
-#pragma pack(pop)
-
-#pragma pack(push, 1)
-#pragma pack(pop)
-
-void ShowMM7IntroVideo_and_LoadingScreen();
-
-extern "C"
-{
-#include "lib/libavcodec/avcodec.h"
-#include "lib/libavformat/avformat.h"
-#include "lib/libavutil/avutil.h"
-#include "lib/libavutil/imgutils.h"
-#include "lib/libswscale/swscale.h"
-#include "lib/libswresample/swresample.h"
-#include "lib/libavutil/opt.h"
-}
-#pragma comment(lib, "avcodec.lib")
-#pragma comment(lib, "avformat.lib")
-#pragma comment(lib, "avutil.lib")
-#pragma comment(lib, "swscale.lib")
-#pragma comment(lib, "swresample.lib")
-
-#include "lib/OpenAL/al.h"
-#include "lib/OpenAL/alc.h"
-#pragma comment(lib, "OpenAL32.lib")
-
-#pragma pack(push, 1)
-struct VideoPlayer
-{
-  VideoPlayer();
-  //----- (004BECBD) --------------------------------------------------------
-  virtual ~VideoPlayer()
-  {
-    bStopBeforeSchedule = false;
-    pResetflag = 0;
-    pVideoFrame.Release();
-  }
-
-  void Initialize(OSWindow *window);
-  void Unload();
-
-  void OpenHouseMovie(const char *pMovieName, unsigned int a3_1);//0x4BF28F
-  void PlayDeathMovie();
-  bool AnyMovieLoaded();
-  void OpenGlobalMovie(const char *pFilename, unsigned int bLoop);
-  void _4BF5B2();
-  void SelectMovieType();//0x4BF73A
-  void _inlined_in_463149();
-
-  void MovieLoop(const char *pMovieName, int a2);
-  void UpdatePalette();
-  void LoadMovie(const char *);
-
-  RGBTexture pVideoFrame;
-  int field_34;
-
-  int pResetflag;
-  int field_44;
-
-  int uBinkDirectDrawSurfaceType;
-  int bBufferLoaded;
-  unsigned int bPlayingMovie;
-  unsigned int bFirstFrame;
-  unsigned int bUsingSmackerMMX;
-  unsigned int bLoopPlaying;
-  int field_68;
-  unsigned int bStopBeforeSchedule;
-  OSWindow *window;
-  struct _SMACKBLIT *pSmackMovieBlit;
-
-  char field_88[20];
-  unsigned int uMovieFormat;
-  int uMovieFormatSwapped;
-  char pCurrentMovieName[64];
-  char pVideoFrameTextureFilename[32];
-  int field_104;
-
-  HANDLE hVidFile;
-  int uSize;
-  int uOffset;
-
-  protected:
-    static int readFunction(void *, uint8_t *, int);
-    static int64_t seekFunction(void *, int64_t, int);
-};
-#pragma pack(pop)
-
-extern VideoPlayer *pVideoPlayer;
-extern LRESULT __stdcall wWinProc(HWND hwnd, unsigned int msg, WPARAM wparam, LPARAM lparam);
\ No newline at end of file
--- a/_deleted.cpp	Thu Jul 24 19:55:55 2014 +0100
+++ b/_deleted.cpp	Fri Jul 25 14:19:14 2014 +0600
@@ -14644,4 +14644,15 @@
       goto LABEL_154;
     }
   }
+//----- (004BF3F9) --------------------------------------------------------
+bool MPlayer::AnyMovieLoaded()
+{
+  return pMovie_Track != 0;
+}
+//----- (004BF8F6) --------------------------------------------------------
+void MPlayer::PlayDeathMovie()
+{
+  bStopBeforeSchedule = 0;
+  PlayFullscreenMovie(MOVIE_Death, true);
+}
 */
\ No newline at end of file
--- a/mm7_2.cpp	Thu Jul 24 19:55:55 2014 +0100
+++ b/mm7_2.cpp	Fri Jul 25 14:19:14 2014 +0600
@@ -158,13 +158,13 @@
 
   dword_6BE364_game_settings_1 &= ~GAME_SETTINGS_4000;
   bGameoverLoop = 1;
-  pVideoPlayer->bStopBeforeSchedule = 0;
+  pMediaPlayer->bStopBeforeSchedule = 0;
   pAudioPlayer->StopChannels(-1, -1);
   pRenderer->BeginScene();
   pRenderer->ClearBlack();
   pRenderer->EndScene();
   pRenderer->Present();
-  pVideoPlayer->pResetflag = 0;
+  //pMediaPlayer->pResetflag = 0;
   _449B57_test_bit(pParty->_quest_bits, 99);
   _this.Load("winbg.pcx", 2);
   pRenderer->BeginScene();
@@ -216,9 +216,9 @@
   if ( v17 != 1 )
     v7 = pGlobalTXT_LocalizationStrings[57];
 
-  v8 = pGlobalTXT_LocalizationStrings[146];//Month, 
+  v8 = pGlobalTXT_LocalizationStrings[146];//Month
   if ( v18 != 1 )
-    v8 = pGlobalTXT_LocalizationStrings[148];//Months,
+    v8 = pGlobalTXT_LocalizationStrings[148];//Months
 
   v9 = pGlobalTXT_LocalizationStrings[245];
   if ( v14 != 1 )
@@ -911,18 +911,15 @@
 {
   GUIButton *pButton; // eax@27
   unsigned int pControlParam; // ecx@35
-//  int v10; // ecx@36
-//  int v11; // ecx@37
   unsigned int pY; // [sp-18h] [bp-54h]@39
   Texture *pTexture; // [sp-14h] [bp-50h]@39
-//  GUIButton *pButton2; // [sp+0h] [bp-3Ch]@27
   GUIWindow *pWindow; // [sp+4h] [bp-38h]@11
   
   pCurrentScreen = SCREEN_GAME;
 
   pGUIWindow2 = 0;
-  pAudioPlayer->StopChannels(-1, -1);/// 
-  pMouse->RemoveHoldingItem();//   
+  pAudioPlayer->StopChannels(-1, -1);
+  pMouse->RemoveHoldingItem();
 
   pIcons_LOD->_inlined_sub2();
 
@@ -1003,7 +1000,7 @@
                 && pWindow == pWindow_MainMenu )
            {
             pControlParam = pButton->msg_param;
-            switch (pControlParam) //  
+            switch (pControlParam) // backlight for buttons
             {
               case 0:
               pTexture = pNew;
@@ -1022,7 +1019,7 @@
               pY = 337;
               break;
             }
-            pRenderer->DrawTextureIndexed(495, pY, pTexture); // 
+            pRenderer->DrawTextureIndexed(495, pY, pTexture);
            }
           }
         }
@@ -1145,12 +1142,8 @@
 //----- (00464866) --------------------------------------------------------
 void DoPrepareWorld(unsigned int bLoading, int _1_fullscreen_loading_2_box)
 {
-  //int v2; // esi@1
   char *v3; // eax@1
-  //char *v4; // eax@1
   unsigned int v5; // eax@3
-  //size_t v6; // ecx@10
-  //char *v7; // eax@11
   char Str1[20]; // [sp+Ch] [bp-18h]@1
   unsigned int v9; // [sp+20h] [bp-4h]@1
 
@@ -1207,7 +1200,6 @@
   _flushall();
 }
 
-
 //----- (00464E17) --------------------------------------------------------
 bool __fastcall CheckMM7CD(char c)
 {
@@ -1461,7 +1453,6 @@
 
   pKeyActionMap = new KeyboardActionMapping;
 
-  // _CrtDumpMemoryLeaks();
   OnTimer(1);
   GameUI_StatusBar_UpdateTimedString(1);
   pGame = Game::Create();
@@ -1724,8 +1715,8 @@
   if (!bNoSound)
     pAudioPlayer->Initialize();
 
-  pVideoPlayer = new VideoPlayer();
-  pVideoPlayer->Initialize(window);
+  pMediaPlayer = new Media::MPlayer();
+  pMediaPlayer->Initialize(window);
 
   dword_6BE364_game_settings_1 |= GAME_SETTINGS_4000;
 
@@ -1977,8 +1968,8 @@
   static_assert(sizeof(LODSprite) == 0x28, "Wrong type size");
 }
 
-bool new_sky = false;            // ( )
-int max_flight_height = 4000;    //  
+bool new_sky = false;            //new sky(need texture)
+int max_flight_height = 4000;    //maximum altitude
 
 
 
@@ -2033,9 +2024,9 @@
   uCPUSpeed = Rect.bottom;*/
   uCPUSpeed = 2048; // about 2GHz
 
-  //_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF );//Ritor1: for memory test(  )
+  //_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF );//Ritor1: for memory test
 
-  if (!MM7_Initialize(640, 480))//  
+  if (!MM7_Initialize(640, 480))
   {
     Log::Warning(L"MM init: failed");
     pGame->Deinitialize();
@@ -2177,15 +2168,10 @@
 //----- (00466082) --------------------------------------------------------
 void MM6_Initialize(const wchar_t *pIniFilename)
 {
-  //int v0; // eax@1
-  //UINT v1; // eax@18
   size_t v2; // eax@31
   size_t v3; // ebx@32
   size_t v4; // edi@36
-  //char v5[120]; // [sp+Ch] [bp-17Ch]@1
-  //char String[120]; // [sp+84h] [bp-104h]@32
   char pDefaultGroundTexture[16]; // [sp+FCh] [bp-8Ch]@32
-  //char pIniFilename[120]; // [sp+10Ch] [bp-7Ch]@1
   unsigned int v9; // [sp+184h] [bp-4h]@28
 
   //_getcwd(v5, 120);
@@ -2246,11 +2232,7 @@
   pODMRenderParams->shading_dist_shade     = GetPrivateProfileIntW(L"shading", L"dist_shade", 2048, pIniFilename);
   pODMRenderParams->shading_dist_shademist = GetPrivateProfileIntW(L"shading", L"dist_shademist", 4096, pIniFilename);
 
-  //int dist = 0x2000;
-
-  //if ( new_draw_object_dist )
-      //dist = 0x6000;
-  pODMRenderParams->shading_dist_mist = GetPrivateProfileIntW(L"shading", L"dist_mist", 0x2000, pIniFilename);//  0x2000
+  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);
@@ -2405,103 +2387,55 @@
   char *v11; // edx@20
   unsigned __int16 v12; // ax@23
   int v13; // eax@27
-//  unsigned int v14; // ebx@33
   int v16; // eax@36
-//  unsigned int v17; // eax@37
   __int16 v18; // di@37
   signed int v19; // edx@37
-//  unsigned __int8 v20; // sf@37
-//  char *v21; // ecx@38
   unsigned __int16 v22; // ax@41
-//  unsigned int v23; // eax@46
   signed int v24; // ebx@46
   char *v25; // edx@47
-//  int v26; // edx@54
-//  int v27; // edx@55
-//  int v28; // edx@56
-//  int v29; // edx@57
-//  unsigned __int16 v30; // ax@60
-//  unsigned int v31; // ecx@60
-//  int v32; // edi@60
-//  unsigned int v33; // eax@65
   signed int v34; // edx@65
-//  char *v35; // ecx@66
   unsigned __int16 v36; // ax@69
   int v37; // ST14_4@72
   int v38; // eax@72
   int v39; // ST10_4@72
   int v40; // ST0C_4@72
-  //int v41; // edx@76
-//  int v42; // edx@77
-//  int v43; // edx@78
   unsigned __int8 v44; // zf@79
-//  int v45; // edx@79
-//  unsigned __int16 v46; // ax@80
   int v47; // eax@81
-//  int v48; // edx@87
-//  int v49; // edx@88
-//  int v50; // edx@89
   signed int v52; // ebx@93
-//  char *v53; // edx@94
-//  unsigned __int16 v54; // ax@98
-//  unsigned int v55; // ecx@98
   signed int v56; // ebx@98
-//  char *v57; // edx@99
   unsigned __int16 v58; // ax@102
   unsigned __int16 v59; // ax@107
-//  unsigned int v60; // ecx@107
   signed int v61; // ebx@107
-//  char *v62; // edx@108
   unsigned __int16 v63; // ax@111
   int v64; // ebx@114
   signed int v65; // eax@114
-//  unsigned int v66; // edi@123
-//  unsigned __int16 v67; // ax@124
-//  unsigned int v68; // ecx@124
   signed int v69; // ebx@124
-//  char *v70; // edx@125
   unsigned __int16 v71; // ax@128
   unsigned int v72; // ebx@131
   int v78; // eax@133
-//  char v79; // zf@139
-//  unsigned int v80; // eax@140
   signed int v81; // edx@140
-//  char *v82; // ecx@141
   unsigned __int16 v83; // ax@144
-//  unsigned __int16 v84; // ax@151
-//  unsigned int v85; // ecx@151
   signed int v86; // ebx@151
-//  char *v87; // edx@152
   unsigned __int16 v88; // ax@155
   unsigned int v89; // eax@158
   int v90; // ST34_4@159
   int v91; // eax@159
   unsigned int v92; // eax@163
-//  unsigned int v93; // eax@177
-//  char *v94; // ecx@178
   unsigned __int16 v95; // ax@181
   unsigned __int16 v96; // ax@184
   int v97; // eax@185
-//  unsigned __int16 v98; // ax@191
   char v100; // ST18_1@198
   int v102; // eax@198
   signed int v106; // eax@208
   unsigned int v107; // edx@220
   signed int v108; // ebx@225
-//  unsigned int v109; // eax@234
   signed int v110; // ebx@234
-//  char *v111; // ecx@235
   unsigned __int16 v112; // ax@238
   unsigned __int16 v113; // si@241
   int v114; // eax@242
   int v115; // eax@245
-//  unsigned __int16 v117; // ax@251
-//  unsigned int v118; // ecx@251
   signed int v119; // ebx@251
-//  char *v120; // edx@252
   unsigned __int16 v121; // ax@255
-//  unsigned int v122; // eax@260
-//  char *v123; // edx@261
   int v124; // eax@267
   int v125; // [sp-20h] [bp-4Ch]@28
   char v132; // [sp-8h] [bp-34h]@131
@@ -2511,18 +2445,15 @@
   int v137; // [sp+10h] [bp-1Ch]@208
   signed int v138; // [sp+14h] [bp-18h]@207
   signed int v139; // [sp+18h] [bp-14h]@208
-//  char *v140; // [sp+1Ch] [bp-10h]@61
   signed int v141; // [sp+1Ch] [bp-10h]@117
   unsigned int v142; // [sp+1Ch] [bp-10h]@158
   signed int v143; // [sp+1Ch] [bp-10h]@172
-//  char *v144; // [sp+1Ch] [bp-10h]@192
   signed int v146; // [sp+20h] [bp-Ch]@60
   int v147; // [sp+20h] [bp-Ch]@72
   signed int v148; // [sp+20h] [bp-Ch]@158
   unsigned __int16 v150; // [sp+20h] [bp-Ch]@208
   signed int v152; // [sp+24h] [bp-8h]@208
 
-  //:    
   object = &pObjectList->pObjects[pSpriteObjects[uLayingItemID].uObjectDescID];
   //v151 = PID_TYPE(a2);
   if ( PID_TYPE(a2) == OBJECT_Actor)