changeset 2227:e87b5709a502

LoadSound
author Ritor1
date Thu, 20 Feb 2014 22:26:13 +0600
parents 5944810e88e2
children b65e71eadd1b
files AudioPlayer.cpp
diffstat 1 files changed, 43 insertions(+), 117 deletions(-) [+]
line wrap: on
line diff
--- a/AudioPlayer.cpp	Thu Feb 20 12:20:49 2014 +0600
+++ b/AudioPlayer.cpp	Thu Feb 20 22:26:13 2014 +0600
@@ -194,124 +194,66 @@
 //----- (004A9BBD) --------------------------------------------------------
 int SoundList::LoadSound(unsigned int a2, LPVOID lpBuffer, int uBufferSizeLeft, int *pOutSoundSize, int a6)
 {
-  //SoundList *v6; // edi@1
-  signed int v7; // esi@1
-  //unsigned __int8 v8; // zf@1
-  //unsigned __int8 v9; // sf@1
-  SoundDesc *v10; // eax@3
-  SoundDesc *v11; // ecx@3
-  int v12; // ebx@7
-  int result; // eax@13
-  SoundHeader *v14; // esi@16
-  DWORD *v15; // edi@16
-  int v16; // ebx@16
-  unsigned int v17; // eax@18
   void *v18; // ebx@19
-  std::string v19; // [sp-18h] [bp-38h]@22
-  const char *v20; // [sp-8h] [bp-28h]@22
-  int v21; // [sp-4h] [bp-24h]@22
-  //SoundList *v22; // [sp+Ch] [bp-14h]@1
-  SoundDesc *Args; // [sp+10h] [bp-10h]@3
-  unsigned int v24; // [sp+14h] [bp-Ch]@2
-  int v25; // [sp+18h] [bp-8h]@2
-  int v26; // [sp+1Ch] [bp-4h]@1
+  DWORD NumberOfBytesRead;
 
-  //v6 = this;
-  v7 = 0;
-  //v22 = this;
-  //v8 = this->uNumSounds == 0;
-  //v9 = (this->uNumSounds & 0x80000000u) != 0;
-  v26 = 0;
   if (!sNumSounds)
     return 0;
 
-
-    v24 = 0;
-    v25 = 44;
-    while ( 1 )
-    {
-      v10 = pSL_Sounds;
-      v11 = &v10[v24 / 0x78];
-      Args = &v10[v24 / 0x78];
-      if ( a2 == v10[v24 / 0x78].uSoundID )
-      {
-        if ( a6 == v7 && *(int *)&v10->pSoundName[v25] != v7 )
-          return v26;
-        if ( (signed int)pAudioPlayer->uNumSoundHeaders > v7 )
-          break;
-      }
-LABEL_12:
-      ++v26;
-      v25 += 120;
-      v24 += 120;
-      if ( v26 >= (signed int)sNumSounds )
-        return 0;
-    }
-    v12 = 0;
-    while ( _stricmp(pAudioPlayer->pSoundHeaders[v12].pSoundName, v11->pSoundName) )
+  for ( uint i = 0; i < sNumSounds; ++i )
+  {
+    if ( a2 == pSL_Sounds[i].uSoundID )
     {
-      ++v7;
-      ++v12;
-      if ( v7 >= (signed int)pAudioPlayer->uNumSoundHeaders )
+      if ( !a6 && pSL_Sounds[i].pSoundData )
+        return i;
+      for ( uint j = 0; j < (signed int)pAudioPlayer->uNumSoundHeaders; ++j )
       {
-        v7 = 0;
-        goto LABEL_12;
-      }
-      v11 = Args;
-    }
-    v14 = &pAudioPlayer->pSoundHeaders[v7];
-    v15 = (DWORD *)&v14->uDecompressedSize;
-    a2 = v14->uDecompressedSize;
-    v16 = a2;
-    if ( (signed int)a2 > uBufferSizeLeft )
-      Error("Sound %s is size %i bytes, sound buffer size is %i bytes", Args, a2, uBufferSizeLeft);
-
-    SetFilePointer(pAudioPlayer->hAudioSnd, v14->uFileOffset, 0, 0);
-    v17 = v14->uCompressedSize;
-    if ( (signed int)v17 >= (signed int)*v15 )
-    {
-      if ( v17 == *v15 )
-      {
-        ReadFile(pAudioPlayer->hAudioSnd, lpBuffer, *v15, (LPDWORD)&Args, 0);
-      }
-      else
-      {
-      MessageBoxW(nullptr, L"Can't load sound file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Sound.cpp:666", 0);
+        if ( !_stricmp(pAudioPlayer->pSoundHeaders[j].pSoundName, pSL_Sounds[i].pSoundName) )
+        {
+          if ( (signed int)pAudioPlayer->pSoundHeaders[j].uDecompressedSize > uBufferSizeLeft )
+            Error("Sound %s is size %i bytes, sound buffer size is %i bytes", pSL_Sounds[i].pSoundName, pAudioPlayer->pSoundHeaders[j].uDecompressedSize, uBufferSizeLeft);
+          SetFilePointer(pAudioPlayer->hAudioSnd, pAudioPlayer->pSoundHeaders[j].uFileOffset, 0, 0);
+          if ( (signed int)pAudioPlayer->pSoundHeaders[j].uCompressedSize >= (signed int)pAudioPlayer->pSoundHeaders[j].uDecompressedSize )
+          {
+            if ( pAudioPlayer->pSoundHeaders[j].uCompressedSize == pAudioPlayer->pSoundHeaders[j].uDecompressedSize )
+              ReadFile(pAudioPlayer->hAudioSnd, lpBuffer, pAudioPlayer->pSoundHeaders[j].uDecompressedSize, &NumberOfBytesRead, 0);
+            else
+              MessageBoxW(nullptr, L"Can't load sound file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Sound.cpp:666", 0);
+          }
+          else
+          {
+            v18 = malloc(pAudioPlayer->pSoundHeaders[j].uCompressedSize);
+            ReadFile(pAudioPlayer->hAudioSnd, v18, pAudioPlayer->pSoundHeaders[j].uCompressedSize, &NumberOfBytesRead, 0);
+            zlib::MemUnzip(lpBuffer, &pAudioPlayer->pSoundHeaders[j].uDecompressedSize, v18, pAudioPlayer->pSoundHeaders[j].uCompressedSize);
+            free(v18);
+          }
+          pSL_Sounds[i].pSoundData[a6] = (SoundData *)lpBuffer;
+          *pOutSoundSize = a2;
+          return i;
+        }
       }
     }
-    else
-    {
-      v18 = malloc(v14->uCompressedSize);
-      ReadFile(pAudioPlayer->hAudioSnd, v18, v14->uCompressedSize, (LPDWORD)&Args, 0);
-      zlib::MemUnzip(lpBuffer, &v14->uDecompressedSize, v18, v14->uCompressedSize);
-      free(v18);
-      v16 = a2;
-    }
-    result = v26;
-    pSL_Sounds->pSoundData[a6 + 30 * v26] = (SoundData *)lpBuffer;
-    *pOutSoundSize = v16;
-
-  return result;
+  }
+  return 0;
 }
 
 //----- (004A9D3E) --------------------------------------------------------
 SoundDesc *SoundList::Release()
 {
   SoundDesc *result; // eax@3
-  void *v5; // ecx@3
+  //void *v5; // ecx@3
 
   if ( (signed int)this->sNumSounds > 0 )
   {
     for ( uint i = 0; i < (signed int)this->sNumSounds; ++i )
     {
       result = this->pSL_Sounds;
-      v5 = result[i].pSoundData[0];
-      if ( v5 )
+      //v5 = this->pSL_Sounds[i].pSoundData[0];
+      if ( this->pSL_Sounds[i].pSoundData[0] )
       {
-        ReleaseSoundData(v5);
+        ReleaseSoundData(this->pSL_Sounds[i].pSoundData[0]);
         this->pSL_Sounds[i].pSoundData[0] = 0;
-        result = (SoundDesc *)((char *)&this->pSL_Sounds[i] + 40);
-        *(int *)&result->pSoundName[0] &= 0xFFFFFFFEu;
+        this->pSL_Sounds[i].uFlags &= 0xFFFFFFFE;
       }
     }
   }
@@ -404,13 +346,6 @@
   void *v6; // eax@9
   FILE *v7; // ST0C_4@11
   char *i; // eax@11
-  int v9; // eax@14
-  const char *v10; // ST0C_4@14
-  int v11; // eax@18
-  SoundDesc *v12; // ecx@18
-  char v13; // zf@18
-  unsigned int v14; // eax@18
-  int v15; // eax@23
   char Buf; // [sp+Ch] [bp-2F0h]@3
   FrameTableTxtLine v18; // [sp+200h] [bp-FCh]@4
   FrameTableTxtLine v19; // [sp+27Ch] [bp-80h]@4
@@ -458,21 +393,15 @@
     if ( v19.uPropCount && *v19.pProperties[0] != 47 )
     {
       sprintf(this->pSL_Sounds[this->sNumSounds].pSoundName, "%s", v19.pProperties[0]);
-      v9 = atoi(v19.pProperties[1]);
-      v10 = v19.pProperties[2];
-      this->pSL_Sounds[this->sNumSounds].uSoundID = v9;
-      if ( _stricmp(v10, "system") )
+      this->pSL_Sounds[this->sNumSounds].uSoundID = atoi(v19.pProperties[1]);
+      if ( _stricmp(v19.pProperties[2], "system") )
       {
         if ( _stricmp(v19.pProperties[2], "swap") )
         {
-          v11 = _stricmp(v19.pProperties[2], "lock");
-          v12 = this->pSL_Sounds;
-          v13 = v11 == 0;
-          v14 = this->sNumSounds;
-          if ( v13 )
-            v12[v14].eType = SOUND_DESC_LOCK;
+          if ( !_stricmp(v19.pProperties[2], "lock") )
+            this->pSL_Sounds[this->sNumSounds].eType = SOUND_DESC_LOCK;
           else
-            v12[v14].eType = SOUND_DESC_LEVEL;
+            this->pSL_Sounds[this->sNumSounds].eType = SOUND_DESC_LEVEL;
         }
         else
           this->pSL_Sounds[this->sNumSounds].eType = SOUND_DESC_SWAP;
@@ -480,10 +409,7 @@
       else
         this->pSL_Sounds[this->sNumSounds].eType = SOUND_DESC_SYSTEM;
       if ( v19.uPropCount >= 4 && !_stricmp(v19.pProperties[3], "3D") )
-      {
-        v15 = (int)&this->pSL_Sounds[this->sNumSounds].uFlags;
-        *(int *)v15 |= SOUND_DESC_SWAP;
-      }
+        this->pSL_Sounds[this->sNumSounds].uFlags |= SOUND_DESC_SWAP;
       ++this->sNumSounds;
     }
   }