changeset 21:3fa5d0522f92

Both Bink 1.5.21.0 & 3.0.0.0 support added
author Nomad
date Sat, 13 Oct 2012 20:17:56 +0200
parents e33334611747
children e7ee737cd473
files VideoPlayer.cpp VideoPlayer.h mm7_5.cpp
diffstat 3 files changed, 186 insertions(+), 89 deletions(-) [+]
line wrap: on
line diff
--- a/VideoPlayer.cpp	Sat Oct 13 17:10:23 2012 +0200
+++ b/VideoPlayer.cpp	Sat Oct 13 20:17:56 2012 +0200
@@ -24,6 +24,40 @@
 
 
 
+#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;
+}
+
+
+// 3.15.1.0:
+//      3  15   1   0
+// 0x0003000F00010000
+unsigned __int64 uBinkVersion;
+
+
+
+
+
 
 //----- (004BFE2D) --------------------------------------------------------
 _BINKBUF *VideoPlayer::CreateBinkBuffer(HWND hWindow, unsigned int uWidth, unsigned int uHeight, char a4)
@@ -48,8 +82,18 @@
   {
     v4 = 0;
     v15 = 0;
-    v5 = (_BINKBUF *)malloc(0xA4u);
-    memset(v5, 0, 0xA4u);
+
+    if (uBinkVersion == 0x0001000500150000)
+    {
+      v5 = new _BINKBUF_1_5_21_0;
+      memset(v5, 0, sizeof(_BINKBUF_1_5_21_0));
+    }
+    else if (uBinkVersion == 0x0003000000000000)
+    {
+      v5 = new _BINKBUF_3_0_0_0;
+      memset(v5, 0, sizeof(_BINKBUF_3_0_0_0));
+    }
+
     memset(&v11, 0, 0x7Cu);
     v11.dwSize = 124;
     v11.dwWidth = v13;
@@ -78,8 +122,19 @@
   {
     v4 = 0;
     a2 = 0;
-    v5 = (_BINKBUF *)malloc(0xA4u);
-    memset(v5, 0, 0xA4u);
+    
+
+    if (uBinkVersion == 0x0001000500150000)
+    {
+      v5 = new _BINKBUF_1_5_21_0;
+      memset(v5, 0, sizeof(_BINKBUF_1_5_21_0));
+    }
+    else if (uBinkVersion == 0x0003000000000000)
+    {
+      v5 = new _BINKBUF_3_0_0_0;
+      memset(v5, 0, sizeof(_BINKBUF_3_0_0_0));
+    }
+
     memset(&Dst, 0, 0x6Cu);
     Dst.dwSize = 108;
     Dst.dwWidth = v13;
@@ -136,10 +191,7 @@
   BinkBufferSetScale(v5, v5->uWidth, v5->uHeight);
   return v5;
 }
-// 4D82BC: using guessed type int __stdcall BinkBufferSetOffset(int, int, int);
-// 4D82C4: using guessed type int __stdcall BinkDDSurfaceType(int);
-// 4D82CC: using guessed type int __stdcall BinkBufferSetScale(int, int, int);
-// 6BE384: using guessed type int dword_6BE384_2dacceloff;
+
 
 //----- (004C0133) --------------------------------------------------------
 bool BinkLockBuffer(_BINKBUF *_this)
@@ -164,7 +216,12 @@
         v6 = (IDirectDrawSurface4 *)v1->pTargetDDrawSurface;
         if ( !v6->Lock(0, &v8, 1u, 0) )
           break;
-        BYTE3(v1->uBinkDDSurfaceType) |= 0x80u;
+        
+        if (uBinkVersion < 0x0003000000000000)
+          BYTE3(v1->uBinkDDSurfaceType) |= 0x80u;
+        else
+          BYTE3(v1->uBinkDDSurfaceType) |= 0x04;
+
         if ( v6->Restore() )
           return 0;
       }
@@ -187,7 +244,12 @@
         v2 = v1->pTargetDDrawSurface;
         if ( !v2->Lock(0, (LPDDSURFACEDESC)&v8.lPitch, 1u, 0) )
           break;
-        BYTE3(v1->uBinkDDSurfaceType) |= 4u;
+        
+        if (uBinkVersion < 0x0003000000000000)
+          __asm int 3;
+        else
+          BYTE3(v1->uBinkDDSurfaceType) |= 4u;
+
         if ( v2->Restore() )
           return 0;
       }
@@ -216,7 +278,11 @@
     v2->Unlock(0);
     v1->uDDrawSurfacePitch = 0;
     v1->pDDrawSurfaceData = 0;
-    BYTE3(v1->uBinkDDSurfaceType) &= 0x7Fu;
+
+    if (uBinkVersion < 0x0003000000000000)
+      BYTE3(_this->uBinkDDSurfaceType) &= 0x7F;
+    else
+      BYTE3(_this->uBinkDDSurfaceType) &= 0xFB;
   }
 }
 
@@ -364,10 +430,7 @@
       uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions = 0;
   }
 }
-// 4D82B8: using guessed type int __stdcall BinkWait(int);
-// 4D840C: using guessed type int __stdcall SmackWait(int);
-// 4E28F8: using guessed type int uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions;
-// 6BE364: using guessed type int dword_6BE364_game_settings_1;
+
 
 
 
@@ -411,6 +474,13 @@
   char *v8; // [sp-4h] [bp-18h]@2
   DWORD NumberOfBytesRead; // [sp+10h] [bp-4h]@9
 
+  
+  uint uBinkVersionMajor = -1,
+       uBinkVersionMinor = -1;
+  GetDllVersion(L"BINKW32.DLL", &uBinkVersionMajor, &uBinkVersionMinor);
+  uBinkVersion = (unsigned __int64)uBinkVersionMajor << 32 | uBinkVersionMinor;
+
+
   //v1 = this;
   strcpy(pTmpBuf, "anims\\might7.vid");
   v2 = CreateFileW(L"anims\\might7.vid", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0x8000080u, 0);
@@ -541,7 +611,7 @@
 }
 
 //----- (004BECD5) --------------------------------------------------------
-void VideoPlayer::_4BECD5(unsigned int a2)
+void VideoPlayer::FastForwardToFrame(unsigned int uDstFrameNum)
 {
   VideoPlayer *v2; // esi@1
   unsigned int v3; // eax@1
@@ -550,12 +620,15 @@
   v3 = this->uMovieFormat;
   if ( v3 == 2 )
   {
-    if ( a2 )
+    if (uDstFrameNum)
     {
-      while ( v2->pBinkMovie->FrameRate < a2 )
+      int *pCurrentFrame = uBinkVersion == 0x0001000500150000 ? &((_BINK_1_5_21_0 *)pBinkMovie)->uCurrentFrame :
+                           uBinkVersion == 0x0003000000000000 ? &((_BINK_3_0_0_0  *)pBinkMovie)->uCurrentFrame :
+                           nullptr;
+      while (*pCurrentFrame < uDstFrameNum)
       {
-        BinkDoFrame(v2->pBinkMovie);
-        BinkNextFrame(v2->pBinkMovie);
+        BinkDoFrame(pBinkMovie);
+        BinkNextFrame(pBinkMovie);
       }
     }
   }
@@ -564,9 +637,9 @@
     if ( v3 != 1 )
       return;
     SmackSoundOnOff(this->pSmackerMovie, 0);
-    if ( a2 )
+    if (uDstFrameNum)
     {
-      while ( v2->pSmackerMovie->FrameNum < a2 )
+      while ( v2->pSmackerMovie->FrameNum < uDstFrameNum)
       {
         SmackDoFrame(v2->pSmackerMovie);
         SmackNextFrame(v2->pSmackerMovie);
@@ -575,16 +648,12 @@
   }
   Unload();
 }
-// 4D8298: using guessed type int __stdcall BinkNextFrame(int);
-// 4D829C: using guessed type int __stdcall BinkDoFrame(int);
-// 4D83E4: using guessed type int __stdcall SmackDoFrame(int);
-// 4D83E8: using guessed type int __stdcall SmackNextFrame(int);
-// 4D83EC: using guessed type int __stdcall SmackSoundOnOff(int, int);
+
 
 //----- (004BED4F) --------------------------------------------------------
 void VideoPlayer::BinkDrawFrame(HWND hWnd, int a3, int a4)
 {
-  VideoPlayer *v4; // esi@1
+  //VideoPlayer *v4; // esi@1
   _BINKBUF *v5; // eax@5
   LONG v6; // edx@6
   int v7; // ecx@6
@@ -592,24 +661,24 @@
   struct tagRECT a3a; // [sp+8h] [bp-20h]@10
   struct tagRECT a1; // [sp+18h] [bp-10h]@6
 
-  v4 = this;
+  //v4 = this;
   if ( this->pBinkMovie && this->pBinkBuffer )
   {
-    BinkDoFrame(this->pBinkMovie);
-    BinkGetRects(v4->pBinkMovie, v4->pBinkBuffer->uBinkDDSurfaceType);
-    if ( BinkLockBuffer(v4->pBinkBuffer) )
+    BinkDoFrame(pBinkMovie);
+    BinkGetRects(pBinkMovie, pBinkBuffer->uBinkDDSurfaceType);
+    if ( BinkLockBuffer(pBinkBuffer) )
     {
       BinkCopyToBuffer(
-        v4->pBinkMovie,
-        v4->pBinkBuffer->pDDrawSurfaceData,
-        v4->pBinkBuffer->uDDrawSurfacePitch,
-        v4->pBinkBuffer->uHeight,
+        pBinkMovie,
+        pBinkBuffer->pDDrawSurfaceData,
+        pBinkBuffer->uDDrawSurfacePitch,
+        pBinkBuffer->uHeight,
         0,
         0,
-        v4->pBinkBuffer->uBinkDDSurfaceType);
-      BinkUnlockBuffer(v4->pBinkBuffer);
+        pBinkBuffer->uBinkDDSurfaceType);
+      BinkUnlockBuffer(pBinkBuffer);
     }
-    v5 = v4->pBinkBuffer;
+    v5 = pBinkBuffer;
     if ( pRenderer->bWindowMode )
     {
       v6 = v5->uRectX;
@@ -638,16 +707,23 @@
     a3a.right = v5->uWidth;
     a3a.bottom = v5->uHeight;
     pRenderer->BltToFront(&a1, v5->pTargetDDrawSurface, &a3a, 0x1000000u);
-    if ( v4->pBinkMovie->CurrentFrame != v4->pBinkMovie->Frame - 1 || v4->bLoopPlaying )
-      BinkNextFrame(v4->pBinkMovie);
+    
+    
+    int *pCurrentFrame = uBinkVersion == 0x0001000500150000 ? &((_BINK_1_5_21_0 *)pBinkMovie)->uCurrentFrame :
+                         uBinkVersion == 0x0003000000000000 ? &((_BINK_3_0_0_0  *)pBinkMovie)->uCurrentFrame:
+                         nullptr;
+    int *pNumFrames = uBinkVersion == 0x0001000500150000 ? &((_BINK_1_5_21_0 *)pBinkMovie)->uNumFrames :
+                      uBinkVersion == 0x0003000000000000 ? &((_BINK_3_0_0_0  *)pBinkMovie)->uNumFrames :
+                      nullptr;
+
+    if (*pCurrentFrame != *pNumFrames - 1 || bLoopPlaying)
+      BinkNextFrame(pBinkMovie);
     else
       Unload();
   }
 }
-// 4D8298: using guessed type int __stdcall BinkNextFrame(int);
-// 4D829C: using guessed type int __stdcall BinkDoFrame(int);
-// 4D82A0: using guessed type int __stdcall BinkGetRects(int, int);
-// 4D82C0: using guessed type int __stdcall BinkCopyToBuffer(int, int, int, int, int, int, int);
+
+
 
 //----- (004BEE6B) --------------------------------------------------------
 void VideoPlayer::SmackDrawFrame(HWND hWnd, int a3, int a4)
@@ -823,10 +899,13 @@
 }
 
 
+
+
+
 //----- (004BF141) --------------------------------------------------------
 _BINK *VideoPlayer::OpenBink(const char *pName)
 {
-  VideoPlayer *v2; // esi@1
+  //VideoPlayer *v2; // esi@1
   signed int v3; // edi@1
   int v4; // ebx@2
   signed int v5; // edi@5
@@ -834,41 +913,29 @@
   HANDLE v8; // [sp-8h] [bp-18h]@10
   unsigned int v9; // [sp-4h] [bp-14h]@10
 
-  v2 = this;
-  v3 = 0;
-  if ( (signed int)this->uNumMightVideoHeaders > 0 )
-  {
-    v4 = 0;
-    while ( _strcmpi(v2->pMightVideoHeaders[v4].pVideoName, pName) )
+  for (uint i = 0; i < uNumMightVideoHeaders; ++i)
+    if (!strcmpi(pName, pMightVideoHeaders[i].pVideoName))
     {
-      ++v3;
-      ++v4;
-      if ( v3 >= (signed int)v2->uNumMightVideoHeaders )
-        goto LABEL_5;
+      SetFilePointer(hMightVid, pMightVideoHeaders[i].uFileOffset, 0, FILE_BEGIN);
+
+      if (uBinkVersion < 0x0003000000000000)
+        return BinkOpen(hMightVid, 0x08800000);
+      else
+        return BinkOpen(hMightVid, 0x82000000);
     }
-    SetFilePointer(v2->hMightVid, v2->pMightVideoHeaders[v3].uFileOffset, 0, 0);
-    v9 = 0x8800000u;
-    v8 = v2->hMightVid;
-    return BinkOpen(v8, v9);
-  }
-LABEL_5:
-  v5 = 0;
-  if ( (signed int)v2->uNumMagicVideoHeaders > 0 )
-  {
-    v6 = 0;
-    while ( _strcmpi(v2->pMagicVideoHeaders[v6].pVideoName, pName) )
+
+  for (uint i = 0; i < uNumMagicVideoHeaders; ++i)
+    if (!strcmpi(pName, pMagicVideoHeaders[i].pVideoName))
     {
-      ++v5;
-      ++v6;
-      if ( v5 >= (signed int)v2->uNumMagicVideoHeaders )
-        return 0;
+      SetFilePointer(hMagicVid, pMagicVideoHeaders[i].uFileOffset, 0, FILE_BEGIN);
+
+      if (uBinkVersion < 0x0003000000000000)
+        return BinkOpen(hMagicVid, 0x08800000);
+      else
+        return BinkOpen(hMagicVid, 0x82000000);
     }
-    SetFilePointer(v2->hMagicVid, v2->pMagicVideoHeaders[v5].uFileOffset, 0, 0);
-    v9 = 0x8800000u;
-    v8 = v2->hMagicVid;
-    return BinkOpen(v8, v9);
-  }
-  return 0;
+
+  return nullptr;
 }
 
 //----- (004BF1E6) --------------------------------------------------------
@@ -1027,7 +1094,7 @@
       pBinkMovie = v4->pBinkMovie;
       v4->dword_0000A0 = 1;
       if ( pBinkMovie )
-        v4->pBinkBuffer = CreateBinkBuffer(v4->hWindow, pBinkMovie->Width, pBinkMovie->Height, 0);
+        v4->pBinkBuffer = CreateBinkBuffer(v4->hWindow, pBinkMovie->uWidth, pBinkMovie->uHeight, 0);
     }
     else
     {
@@ -1085,9 +1152,7 @@
     }
   }
 }
-// 4D83BC: using guessed type int __stdcall radmalloc(int);
-// 4D8400: using guessed type int __stdcall SmackToBuffer(int, int, int, int, int, int, int);
-// 6A0D00: using guessed type int uCPUSpeed;
+
 
 //----- (004BF5B2) --------------------------------------------------------
 void VideoPlayer::_4BF5B2()
--- a/VideoPlayer.h	Sat Oct 13 17:10:23 2012 +0200
+++ b/VideoPlayer.h	Sat Oct 13 20:17:56 2012 +0200
@@ -12,16 +12,31 @@
 
 struct _BINK
 {
-  int Width;
-  int Height;
-  int Frame;
-  int CurrentFrame;
+  int uWidth;
+  int uHeight;
+};
+
+struct _BINK_1_5_21_0: public _BINK
+{
+  int uNumFrames;
+  int uCurrentFrame;
   int Data1;
-  int FrameRate;
+  int uFrameRate;
   int field_18[3];
-  int Flags;
+  int uFlags;
 };
 
+struct _BINK_3_0_0_0: public _BINK
+{
+  int unk_0;
+  int unk_1;
+  int uNumFrames;
+  int uCurrentFrame;
+  int _unk2;
+  int _unk_[10];
+};
+
+
 struct _BINKBUF
 {
   int uWidth;
@@ -56,6 +71,23 @@
   int field_74;
   int field_78;
 };
+struct _BINKBUF_1_5_21_0: public _BINKBUF
+{
+  int field_7C;
+  int field_80;
+  int field_84;
+  int field_88;
+  int field_8C;
+  int field_90;
+  int field_94;
+  int field_98;
+  int field_9C;
+  int field_A0;
+};
+
+struct _BINKBUF_3_0_0_0: public _BINKBUF
+{
+};
 #pragma pack(pop)
 
 
@@ -106,7 +138,7 @@
   void Initialize();
   void Prepare();
   void Unload();
-  void _4BECD5(unsigned int a2);
+  void FastForwardToFrame(unsigned int uFrameNum);
   void BinkDrawFrame(HWND hWnd, int a3, int a4);
   void BinkUpdatePalette(HWND hWnd) {}
   void SmackDrawFrame(HWND hWnd, int a3, int a4);
--- a/mm7_5.cpp	Sat Oct 13 17:10:23 2012 +0200
+++ b/mm7_5.cpp	Sat Oct 13 20:17:56 2012 +0200
@@ -3666,7 +3666,7 @@
             v17 = uGame_if_0_else_ui_id__11_save__else_load__8_drawSpellInfoPopup__22_final_window__26_keymapOptions__2_options__28_videoOptions;
 LABEL_83:
             if ( v17 == 16 )
-              pVideoPlayer->_4BECD5(pVideoPlayer->field_40);
+              pVideoPlayer->FastForwardToFrame(pVideoPlayer->field_40);
             if ( GetCurrentMenuID() == 7 )
             {
               v40 = 6;