changeset 1408:204cce84300b

FindSound
author Ritor1
date Fri, 26 Jul 2013 18:11:36 +0600
parents d4f57df4c299
children c9e3b93ec570 6bbcb91b3b7d
files Actor.cpp AudioPlayer.cpp CastSpellInfo.cpp Chest.cpp Indoor.cpp mm7_2.cpp mm7_data.cpp mm7_data.h
diffstat 8 files changed, 461 insertions(+), 603 deletions(-) [+]
line wrap: on
line diff
--- a/Actor.cpp	Tue Jul 23 16:34:00 2013 +0600
+++ b/Actor.cpp	Fri Jul 26 18:11:36 2013 +0600
@@ -3041,7 +3041,7 @@
 //----- (00402CED) --------------------------------------------------------
 void Actor::PlaySound(unsigned int uActorID, unsigned int uSoundID)
 {
-  Actor *v2; // eax@1
+  //Actor *v2; // eax@1
   unsigned __int16 v3; // dx@1
   int v4; // eax@3
   int v5; // eax@4
@@ -3053,19 +3053,18 @@
   unsigned int v11; // [sp-Ch] [bp-10h]@10
   int v12; // [sp-8h] [bp-Ch]@10
 
-  v2 = &pActors[uActorID];
-  v3 = v2->pSoundSampleIDs[uSoundID];
+  //v2 = &pActors[uActorID];
+  v3 = pActors[uActorID].pSoundSampleIDs[uSoundID];
   if ( v3 )
   {
-    if ( (signed __int64)v2->pActorBuffs[3].uExpireTime <= 0 )
+    if ( (signed __int64)pActors[uActorID].pActorBuffs[3].uExpireTime <= 0 )
     {
       v12 = 0;
-     
       v8 = -1;
     }
     else
     {
-      v4 = v2->pActorBuffs[3].uPower - 2;
+      v4 = pActors[uActorID].pActorBuffs[3].uPower - 2;
       if ( v4 )
       {
         v5 = v4 - 1;
@@ -3086,7 +3085,6 @@
         v6 = 33075;
       }
       v12 = v6;
-      
       v8 = 0;
     }
     pAudioPlayer->PlaySound((SoundID)(signed __int16)v3, PID(OBJECT_Actor, uActorID), 0, v8, 0, 0, 0, v12);
--- a/AudioPlayer.cpp	Tue Jul 23 16:34:00 2013 +0600
+++ b/AudioPlayer.cpp	Fri Jul 26 18:11:36 2013 +0600
@@ -67,8 +67,6 @@
 //----- (004A9953) --------------------------------------------------------
 void SoundList::Initialize()
 {
-  SoundList *pSoundList; // esi@1
-  signed int v2; // edi@2
   SoundDesc *pSoundDesc; // eax@5
   void *pSoundData; // ebx@7
   unsigned int uSoundSize; // eax@7
@@ -78,72 +76,52 @@
   char pSoundName[120]; // [sp+4h] [bp-A4h]@4
   AILSOUNDINFO pInfo; // [sp+7Ch] [bp-2Ch]@10
   int v12; // [sp+A0h] [bp-8h]@12
-  int a2; // [sp+A4h] [bp-4h]@1
 
-  pSoundList = this;
-  a2 = 1;
   if ( sNumSounds > 1 )
   {
-    v2 = 1;
-    //while ( 1 )
-	do
+    for ( uint i = 1; i < pSoundList->sNumSounds; ++i )
     {
-	  sprintf(pSoundName, "%s", pSounds[v2].pSoundName);
-	 // pSoundList->pSounds[v2].pSoundData[0] = ::LoadSound(pSoundName, (SoundData *)0xFFFFFFFF, pSounds[v2].uSoundID); //Ritor1: it's error - result: no sound
-	  pSoundDesc = &pSoundList->pSounds[v2];
-      if ( pSoundList->pSounds[v2].eType != SOUND_DESC_SYSTEM || (sprintf(pSoundName, "%s", pSounds[v2].pSoundName),
-            pSoundList->pSounds[v2].pSoundData[0] = ::LoadSound(pSoundName, (SoundData *)0xFFFFFFFF, pSounds[v2].uSoundID),
+      sprintf(pSoundName, "%s", pSounds[i].pSoundName);
+      pSoundDesc = &pSoundList->pSounds[i];
+      if ( pSoundList->pSounds[i].eType != SOUND_DESC_SYSTEM || (sprintf(pSoundName, "%s", pSounds[i].pSoundName),
+            pSoundList->pSounds[i].pSoundData[0] = ::LoadSound(pSoundName, (SoundData *)0xFFFFFFFF, pSounds[i].uSoundID),
             !pAudioPlayer->b3DSoundInitialized)
-        || (pSoundDesc = &pSoundList->pSounds[v2], !(pSoundDesc->uFlags & SOUND_DESC_SWAP))
-        || !pSoundDesc->pSoundData[0] ) // нужно перевернуть
-        goto LABEL_17;
+        || (pSoundDesc = &pSoundList->pSounds[i], !(pSoundDesc->uFlags & SOUND_DESC_SWAP))
+        || !pSoundDesc->pSoundData[0] )
+        continue;
       pSoundData = pSoundDesc->pSoundData[0];
       uSoundSize = *(int *)pSoundData;
       pSoundBytes = (char *)pSoundData + 4;
       pType = AIL_file_type(pSoundBytes, uSoundSize);
       if ( !pType )
-        //goto LABEL_15;
-	  {
-		pSoundList->pSounds[v2].bDecompressed = false;
-		goto LABEL_16;
-	  }
+      {
+        pSoundList->pSounds[i].bDecompressed = false;
+        pSoundList->UnloadSound(i, 1);
+        continue;
+      }
       v8 = pType - 1;
       if ( v8 )
-	  {
-        /*break;
-      pSoundList->pSounds[v2].p3DSound = pSoundList->pSounds[v2].pSoundData[0];
-LABEL_16:
-      pSoundList->_4A9DCD(a2, 1);
-LABEL_17:
-      ++a2;
-      ++v2;
-      if ( a2 >= (signed int)pSoundList->uNumSounds )
-        return;
-    }*/
-      if ( v8 == 1 )
       {
-        if ( AIL_WAV_info(pSoundBytes, &pInfo) && pInfo.uChannels != 2 )
+        if ( v8 == 1 )
         {
-          if ( !AIL_decompress_ADPCM(&pInfo, &pSoundList->pSounds[v2].p3DSound, &v12) )
+          if ( AIL_WAV_info(pSoundBytes, &pInfo) && pInfo.uChannels != 2 )
           {
-            pSoundList->pSounds[v2].p3DSound = 0;
-            pSoundList->pSounds[v2].bDecompressed = true;
+            if ( !AIL_decompress_ADPCM(&pInfo, &pSoundList->pSounds[i].p3DSound, &v12) )
+            {
+              pSoundList->pSounds[i].p3DSound = 0;
+              pSoundList->pSounds[i].bDecompressed = true;
+            }
           }
+          pSoundList->UnloadSound(i, 1);
+          continue;
         }
-        goto LABEL_16;
+        pSoundList->pSounds[i].bDecompressed = false;
+        pSoundList->UnloadSound(i, 1);
+        continue;
       }
-//LABEL_15:
-      pSoundList->pSounds[v2].bDecompressed = false;
-      goto LABEL_16;
+      pSoundList->pSounds[i].p3DSound = pSoundList->pSounds[i].pSoundData[0];
+      pSoundList->UnloadSound(i, 1);
     }
-	pSoundList->pSounds[v2].p3DSound = pSoundList->pSounds[v2].pSoundData[0];
-LABEL_16:
-    pSoundList->UnloadSound(a2, 1);
-LABEL_17:
-      ++a2;
-      ++v2;
-	}
-    while ( a2 < pSoundList->sNumSounds );
   }
 }
 
@@ -318,32 +296,23 @@
 //----- (004A9D3E) --------------------------------------------------------
 SoundDesc *SoundList::Release()
 {
-  SoundList *v1; // esi@1
-  signed int v2; // ebx@1
-  int v3; // edi@2
   SoundDesc *result; // eax@3
   void *v5; // ecx@3
 
-  v1 = this;
-  v2 = 0;
   if ( (signed int)this->sNumSounds > 0 )
   {
-    v3 = 0;
-    do
+    for ( uint i = 0; i < (signed int)this->sNumSounds; ++i )
     {
-      result = v1->pSounds;
-      v5 = result[v3].pSoundData[0];
+      result = this->pSounds;
+      v5 = result[i].pSoundData[0];
       if ( v5 )
       {
         ReleaseSoundData(v5);
-        v1->pSounds[v3].pSoundData[0] = 0;
-        result = (SoundDesc *)((char *)&v1->pSounds[v3] + 40);
+        this->pSounds[i].pSoundData[0] = 0;
+        result = (SoundDesc *)((char *)&this->pSounds[i] + 40);
         *(int *)&result->pSoundName[0] &= 0xFFFFFFFEu;
       }
-      ++v2;
-      ++v3;
     }
-    while ( v2 < (signed int)v1->sNumSounds );
   }
   return result;
 }
@@ -1363,7 +1332,6 @@
 }
 
 
-
 //----- (004AAFCF) --------------------------------------------------------
 void AudioPlayer::UpdateSounds()
 {
@@ -1381,7 +1349,7 @@
   SpriteObject *v12; // eax@14
   Actor *v13; // eax@15
   signed int v14; // edx@15
-  BLVDoor *v15; // eax@19
+  BLVDoor *pDoor; // eax@19
   double v16; // st7@22
   double v17; // st6@22
   double v18; // st5@23
@@ -1444,181 +1412,172 @@
     return;
   }
 
-      //v3 = this->b3DSoundInitialized == 0;
-      if (b3DSoundInitialized)
+  //v3 = this->b3DSoundInitialized == 0;
+  if ( b3DSoundInitialized )
+  {
+    __debugbreak(); // refactor refactor
+    //v3 = this->uNum3DSamples == 0;
+    //v5 = this->uNum3DSamples < 0;
+    v59 = 0;
+    if (uNum3DSamples > 0)
+    {
+      v6 = this->p3DSamples;
+      while ( 1 )
       {
-        __debugbreak(); // refactor refactor
-        //v3 = this->uNum3DSamples == 0;
-        //v5 = this->uNum3DSamples < 0;
-        v59 = 0;
-        if (uNum3DSamples > 0)
+        v7 = PID_TYPE(v6->field_4);
+        if ( AIL_3D_sample_status(v6->hSample) == 2 )
+        {
+          AIL_end_3D_sample(v6->hSample);
+          pAudioPlayer->_4ABF23(v6);
+        }
+        if ( AIL_3D_sample_status(v6->hSample) != 4 )
+          goto LABEL_35;
+        v8 = v7 - 1;//
+        if ( v8 )//> 1
+          break;
+        if ( uCurrentlyLoadedLevelType != LEVEL_Indoor )//==1
+          goto LABEL_31;
+        pDoor = &pIndoor->pDoors[PID_ID(v6->field_4)];
+        if ( pDoor->uDoorID )
+        {
+          uNumRepeats = *pDoor->pXOffsets;
+          a1.vWorldPosition.x = (double)uNumRepeats;
+          uNumRepeats = *pDoor->pYOffsets;
+          a1.vWorldPosition.y = (double)uNumRepeats;
+          uNumRepeats = *pDoor->pZOffsets;
+          v11 = (double)uNumRepeats;
+          goto LABEL_21;
+        }
+LABEL_35:
+        ++v59;
+        ++v6;
+        if ( v59 >= pAudioPlayer->uNum3DSamples )
+        {
+          v2 = 0;
+          goto LABEL_37;
+        }
+      }
+
+      v9 = v8 - 1;//
+      if ( v9 )//> 2
+      {
+        v10 = v9 - 1;//
+        if ( !v10 )//3
         {
-          v6 = this->p3DSamples;
-          while ( 1 )
+          v13 = &pActors[PID_ID(v6->field_4)];
+          uNumRepeats = v13->vPosition.x;
+          v14 = v13->vPosition.y;
+          a1.vWorldPosition.x = (double)uNumRepeats;
+          uNumRepeats = v13->vPosition.z;
+          a1.vWorldPosition.y = (double)v14;
+          v11 = (double)uNumRepeats;
+          goto LABEL_21;
+        }
+        if ( v10 != 2 )//4
+        {
+          a1.vWorldPosition.x = (double)pParty->vPosition.x;
+          a1.vWorldPosition.y = (double)pParty->vPosition.y;
+          v11 = (double)pParty->sEyelevel + (double)pParty->vPosition.z;
+          goto LABEL_21;
+        }//5
+        v12 = (SpriteObject *)&pLevelDecorations[PID_ID(v6->field_4)];
+      }
+      else//2
+      {
+        v12 = &pSpriteObjects[PID_ID(v6->field_4)];
+      }
+      a1.vWorldPosition.x = (double)v12->vPosition.x;
+      a1.vWorldPosition.y = (double)v12->vPosition.y;
+      v11 = (double)v12->vPosition.z;
+LABEL_21:
+      a1.vWorldPosition.z = v11;
+      if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+      {
+        v16 = pBLVRenderParams->fCosineNegX;
+        v17 = pBLVRenderParams->fSineNegX;
+        v55 = pBLVRenderParams->fCosineY;
+        v56 = pBLVRenderParams->fSineY;
+        if ( pBLVRenderParams->sPartyRotX )
+        {
+          v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
+          *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
+          v18 = a1.vWorldPosition.z - (double)pParty->vPosition.z;
+          if ( pRenderer->pRenderD3D )
           {
-            v7 = PID_TYPE(v6->field_4);
-            if ( AIL_3D_sample_status(v6->hSample) == 2 )
-            {
-              AIL_end_3D_sample(v6->hSample);
-              pAudioPlayer->_4ABF23(v6);
-            }
-            if ( AIL_3D_sample_status(v6->hSample) != 4 )
-              goto LABEL_35;
-            v8 = v7 - 1;
-            if ( v8 )
-              break;
-            if ( uCurrentlyLoadedLevelType != LEVEL_Indoor )
-              goto LABEL_31;
-            v15 = &pIndoor->pDoors[PID_ID(v6->field_4)];
-            if ( v15->uDoorID )
-            {
-              uNumRepeats = *v15->pXOffsets;
-              a1.vWorldPosition.x = (double)uNumRepeats;
-              uNumRepeats = *v15->pYOffsets;
-              a1.vWorldPosition.y = (double)uNumRepeats;
-              uNumRepeats = *v15->pZOffsets;
-              v11 = (double)uNumRepeats;
-              goto LABEL_21;
-            }
-LABEL_35:
-            ++v59;
-            ++v6;
-            if ( v59 >= pAudioPlayer->uNum3DSamples )
-            {
-              v2 = 0;
-              goto LABEL_37;
-            }
-          }
-
-          v9 = v8 - 1;
-          if ( v9 )
-          {
-            v10 = v9 - 1;
-            if ( !v10 )
-            {
-              v13 = &pActors[PID_ID(v6->field_4)];
-              uNumRepeats = v13->vPosition.x;
-              v14 = v13->vPosition.y;
-              a1.vWorldPosition.x = (double)uNumRepeats;
-              uNumRepeats = v13->vPosition.z;
-              a1.vWorldPosition.y = (double)v14;
-              v11 = (double)uNumRepeats;
-              goto LABEL_21;
-            }
-            if ( v10 != 2 )
-            {
-              a1.vWorldPosition.x = (double)pParty->vPosition.x;
-              a1.vWorldPosition.y = (double)pParty->vPosition.y;
-              v11 = (double)pParty->sEyelevel + (double)pParty->vPosition.z;
-              goto LABEL_21;
-            }
-            v12 = (SpriteObject *)&pLevelDecorations[PID_ID(v6->field_4)];
+            v19 = *(float *)&uNumRepeats * v56 + v58 * v55;
+            v20 = v58 * v56 - *(float *)&uNumRepeats * v55;
           }
           else
           {
-            v12 = &pSpriteObjects[PID_ID(v6->field_4)];
+            v19 = v58 * v55 - *(float *)&uNumRepeats * v56;
+            v20 = v58 * v56 + *(float *)&uNumRepeats * v55;
           }
-          a1.vWorldPosition.x = (double)v12->vPosition.x;
-          a1.vWorldPosition.y = (double)v12->vPosition.y;
-          v11 = (double)v12->vPosition.z;
-LABEL_21:
-          a1.vWorldPosition.z = v11;
-          if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+          a1.vWorldViewPosition.x = v19 * v16 - v18 * v17;
+          a1.vWorldViewPosition.y = v20;
+          a1.vWorldViewPosition.z = v19 * v17 + v18 * v16;
+        }
+        else
+        {
+          v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
+          *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
+          if ( pRenderer->pRenderD3D )
           {
-            v16 = pBLVRenderParams->fCosineNegX;
-            v17 = pBLVRenderParams->fSineNegX;
-            v55 = pBLVRenderParams->fCosineY;
-            v56 = pBLVRenderParams->fSineY;
-            if ( pBLVRenderParams->sPartyRotX )
-            {
-              v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
-              *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
-              v18 = a1.vWorldPosition.z - (double)pParty->vPosition.z;
-              if ( pRenderer->pRenderD3D )
-              {
-                v19 = *(float *)&uNumRepeats * v56 + v58 * v55;
-                v20 = v58 * v56 - *(float *)&uNumRepeats * v55;
-              }
-              else
-              {
-                v19 = v58 * v55 - *(float *)&uNumRepeats * v56;
-                v20 = v58 * v56 + *(float *)&uNumRepeats * v55;
-              }
-              a1.vWorldViewPosition.x = v19 * v16 - v18 * v17;
-              a1.vWorldViewPosition.y = v20;
-              a1.vWorldViewPosition.z = v19 * v17 + v18 * v16;
-            }
-            else
-            {
-              v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
-              *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
-              if ( pRenderer->pRenderD3D )
-              {
-                a1.vWorldViewPosition.x = *(float *)&uNumRepeats * v56 + v58 * v55;
-                v21 = v58 * v56 - *(float *)&uNumRepeats * v55;
-              }
-              else
-              {
-                a1.vWorldViewPosition.x = v58 * v55 - *(float *)&uNumRepeats * v56;
-                v21 = v58 * v56 + *(float *)&uNumRepeats * v55;
-              }
-              a1.vWorldViewPosition.y = v21;
-              a1.vWorldViewPosition.z = a1.vWorldPosition.z - (double)pParty->vPosition.z;
-            }
+            a1.vWorldViewPosition.x = *(float *)&uNumRepeats * v56 + v58 * v55;
+            v21 = v58 * v56 - *(float *)&uNumRepeats * v55;
           }
           else
           {
-LABEL_31:
-            pGame->pIndoorCameraD3D->ViewTransform(&a1, 1u);
+            a1.vWorldViewPosition.x = v58 * v55 - *(float *)&uNumRepeats * v56;
+            v21 = v58 * v56 + *(float *)&uNumRepeats * v55;
           }
-          v58 = a1.vWorldViewPosition.y * -0.012207031;
-          v22 = a1.vWorldViewPosition.x * 0.012207031;
-          *(float *)&uNumRepeats = v22;
-          v23 = abs((signed __int64)v22);
-          v24 = abs(0);
-          v25 = abs((signed __int64)v58);
-          if ( int_get_vector_length(v25, v24, v23) <= 100 )
-          {
-            AIL_set_3D_position(v6->hSample, LODWORD(v58), 0.0, uNumRepeats);
-            v26 = -*(float *)&uNumRepeats;
-            v27 = -v58;
-            AIL_set_3D_orientation(v6->hSample, LODWORD(v27), 0.0, LODWORD(v26), 0.0, 1.0, 0.0);
-          }
-          else
-          {
-            AIL_end_3D_sample(v6->hSample);
-            pAudioPlayer->_4ABF23(v6);
-          }
-          goto LABEL_35;
+          a1.vWorldViewPosition.y = v21;
+          a1.vWorldViewPosition.z = a1.vWorldPosition.z - (double)pParty->vPosition.z;
         }
       }
-
-
-
-
-
-
+      else
+      {
+LABEL_31:
+        pGame->pIndoorCameraD3D->ViewTransform(&a1, 1u);
+      }
+      v58 = a1.vWorldViewPosition.y * -0.012207031;
+      v22 = a1.vWorldViewPosition.x * 0.012207031;
+      *(float *)&uNumRepeats = v22;
+      v23 = abs((signed __int64)v22);
+      v24 = abs(0);
+      v25 = abs((signed __int64)v58);
+      if ( int_get_vector_length(v25, v24, v23) <= 100 )
+      {
+        AIL_set_3D_position(v6->hSample, LODWORD(v58), 0.0, uNumRepeats);
+        v26 = -*(float *)&uNumRepeats;
+        v27 = -v58;
+        AIL_set_3D_orientation(v6->hSample, LODWORD(v27), 0.0, LODWORD(v26), 0.0, 1.0, 0.0);
+      }
+      else
+      {
+        AIL_end_3D_sample(v6->hSample);
+        pAudioPlayer->_4ABF23(v6);
+      }
+      goto LABEL_35;
+    }
+  }
 
 LABEL_37:
   for (uint i = 0; i < uMixerChannels; ++i)
   {
-    auto channel = pMixerChannels + i;
-
-    if (AIL_sample_status(channel->hSample) == AIL::Sample::Done)
+    if (AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Done)
     {
-      AIL_end_sample(channel->hSample);
-      FreeChannel(channel);
+      AIL_end_sample(pMixerChannels[i].hSample);
+      FreeChannel(&pMixerChannels[i]);
     }
   }
 
   for (uint i = 0; i < uMixerChannels; ++i)
   {
-    auto channel = pMixerChannels + i;
-    if (channel->source_pid <= 0)
+    if (pMixerChannels[i].source_pid <= 0)
       continue;
 
-    int source_type = PID_TYPE(channel->source_pid),
-        source_id = PID_ID(channel->source_pid);
+    int source_type = PID_TYPE(pMixerChannels[i].source_pid),
+        source_id = PID_ID(pMixerChannels[i].source_pid);
     int source_x,
         source_y,
         source_z;
@@ -1635,46 +1594,42 @@
         assert(uCurrentlyLoadedLevelType == LEVEL_Indoor);
 
         assert(source_id < pIndoor->uNumDoors);
-        auto door = pIndoor->pDoors + source_id;
-        if (!door->uDoorID)
+        if (!pIndoor->pDoors[source_id].uDoorID)
           continue;
 
-        source_x = door->pXOffsets[0];
-        source_y = door->pYOffsets[0];
-        source_z = door->pZOffsets[0];
+        source_x = pIndoor->pDoors[source_id].pXOffsets[0];
+        source_y = pIndoor->pDoors[source_id].pYOffsets[0];
+        source_z = pIndoor->pDoors[source_id].pZOffsets[0];
       }
       break;
 
       case OBJECT_Item:
       {
         assert(source_id < uNumSpriteObjects);
-        auto object = &pSpriteObjects[source_id];
 
-        source_x = object->vPosition.x;
-        source_y = object->vPosition.y;
-        source_z = object->vPosition.z;
+        source_x = pSpriteObjects[source_id].vPosition.x;
+        source_y = pSpriteObjects[source_id].vPosition.y;
+        source_z = pSpriteObjects[source_id].vPosition.z;
       }
       break;
 
       case OBJECT_Decoration:
       {
         assert(source_id < uNumLevelDecorations);
-        auto object = (SpriteObject *)&pLevelDecorations[source_id];
 
-        source_x = object->vPosition.x;
-        source_y = object->vPosition.y;
-        source_z = object->vPosition.z;
+        source_x = pLevelDecorations[source_id].vPosition.x;
+        source_y = pLevelDecorations[source_id].vPosition.y;
+        source_z = pLevelDecorations[source_id].vPosition.z;
       }
       break;
 
       case OBJECT_Actor:
       {
         assert(source_id < uNumActors);
-        auto actor = &pActors[source_id];
 
-        source_x = actor->vPosition.x;
-        source_y = actor->vPosition.y;
-        source_z = actor->vPosition.z;
+        source_x = pActors[source_id].vPosition.x;
+        source_y = pActors[source_id].vPosition.y;
+        source_z = pActors[source_id].vPosition.z;
       }
       break;
 
@@ -1685,13 +1640,13 @@
 
     if (auto sound_strength = GetSoundStrengthByDistanceFromParty(source_x, source_y, source_z))
     {
-      AIL_set_sample_volume(channel->hSample, sound_strength);
-      AIL_set_sample_pan(channel->hSample, sub_4AB66C(source_x, source_y));
+      AIL_set_sample_volume(pMixerChannels[i].hSample, sound_strength);
+      AIL_set_sample_pan(pMixerChannels[i].hSample, sub_4AB66C(source_x, source_y));
     }
     else
     {
-      AIL_end_sample(channel->hSample);
-      FreeChannel(channel);
+      AIL_end_sample(pMixerChannels[i].hSample);
+      FreeChannel(&pMixerChannels[i]);
     }
   }
 
@@ -1748,9 +1703,39 @@
     if (!decor_desc->SoundOnDawn())
     {
       if (!decor_desc->SoundOnDusk())
-        goto LABEL_84;
+      {
+        if ( v55 == 0.0 )
+        {
+          if ( v56 != 0.0 )
+          {
+            v53 = 8 * _6807B8_level_decorations_ids[i];
+            LOBYTE(v53) = v53 | OBJECT_Decoration;
+            PlaySound((SoundID)decor_desc->uSoundID, v53, uNumRepeats, -1, 0, 0, 0, 0);
+          }
+          continue;
+        }
+        if ( !decor->field_1A )
+          decor->field_1A = (rand() % 15 + 1) << 7;
+        if ( v56 != 0.0 )
+        {
+          v53 = 8 * _6807B8_level_decorations_ids[i];
+          LOBYTE(v53) = v53 | OBJECT_Decoration;
+          PlaySound((SoundID)decor_desc->uSoundID, v53, uNumRepeats, -1, 0, 0, 0, 0);
+        }
+        continue;
+      }
       if ( v55 != 0.0 )
-        goto LABEL_85;
+      {
+        if ( !decor->field_1A )
+          decor->field_1A = (rand() % 15 + 1) << 7;
+        if ( v56 != 0.0 )
+        {
+          v53 = 8 * _6807B8_level_decorations_ids[i];
+          LOBYTE(v53) = v53 | OBJECT_Decoration;
+          PlaySound((SoundID)decor_desc->uSoundID, v53, uNumRepeats, -1, 0, 0, 0, 0);
+        }
+        continue;
+      }
     }
     v56 = 0.0;
 
@@ -1761,26 +1746,28 @@
           LODWORD(v56) = 1;
         LODWORD(v55) = 1;
     }
-LABEL_84:
-      if ( v55 == 0.0 )
+    if ( v55 == 0.0 )
+    {
+      if ( v56 != 0.0 )
       {
-LABEL_87:
-        if ( v56 != 0.0 )
-        {
-          v53 = 8 * _6807B8_level_decorations_ids[i];
-          LOBYTE(v53) = v53 | OBJECT_Decoration;
-          PlaySound((SoundID)decor_desc->uSoundID, v53, uNumRepeats, -1, 0, 0, 0, 0);
-        }
-        continue;
+        v53 = 8 * _6807B8_level_decorations_ids[i];
+        LOBYTE(v53) = v53 | OBJECT_Decoration;
+        PlaySound((SoundID)decor_desc->uSoundID, v53, uNumRepeats, -1, 0, 0, 0, 0);
       }
-LABEL_85:
-      if ( !decor->field_1A )
-        decor->field_1A = (rand() % 15 + 1) << 7;
-      goto LABEL_87;
+      continue;
+    }
+    if ( !decor->field_1A )
+      decor->field_1A = (rand() % 15 + 1) << 7;
+    if ( v56 != 0.0 )
+    {
+      v53 = 8 * _6807B8_level_decorations_ids[i];
+      LOBYTE(v53) = v53 | OBJECT_Decoration;
+      PlaySound((SoundID)decor_desc->uSoundID, v53, uNumRepeats, -1, 0, 0, 0, 0);
+    }
+    continue;
   }
 }
 
-
 //----- (004AB66C) --------------------------------------------------------
 int __fastcall sub_4AB66C(int a1, int a2)
 {
@@ -1795,42 +1782,34 @@
 // 4AB66C: using guessed type int __fastcall sub_4AB66C(int, int);
 
 //----- (004AB6B1) --------------------------------------------------------
-int __fastcall GetSoundStrengthByDistanceFromParty(int a1, int a2, int a3)
+int GetSoundStrengthByDistanceFromParty(int x, int y, int z)
 {
-  int v3; // esi@1
-  int v4; // edi@1
-  int v5; // ST08_4@1
-  int v6; // esi@1
-  int v7; // eax@1
-  int v9; // [sp+10h] [bp+8h]@1
+  int dir_x; // ST08_4@1
+  int dir_y; // esi@1
+  int dir_z; // eax@1
+  int length; // [sp+10h] [bp+8h]@1
 
-  v3 = a2;
-  v4 = a1;
-  v5 = abs(a3 - pParty->vPosition.z);
-  v6 = abs(v3 - pParty->vPosition.y);
-  v7 = abs(v4 - pParty->vPosition.x);
-  v9 = int_get_vector_length(v7, v6, v5);
-  if ( v9 <= 8192 )
-    return 114 - (unsigned __int64)(signed __int64)((double)v9 * 0.0001220703125 * 100.0);
+  dir_z = abs(z - pParty->vPosition.z);
+  dir_y = abs(y - pParty->vPosition.y);
+  dir_x = abs(x - pParty->vPosition.x);
+  length = int_get_vector_length(dir_x, dir_y, dir_z);
+  if ( length <= 8192 )
+    return 114 - (unsigned __int64)(signed __int64)((double)length * 0.0001220703125 * 100.0);
   else
     return 0;
 }
 
-
-
 //----- (004AB71F) --------------------------------------------------------
 void AudioPlayer::StopChannels(int uStartChannel, int uEndChannel)
 {
   //AudioPlayer *v3; // esi@1
   int v4; // ecx@1
-  AudioPlayer_3DSample *v5; // edi@4
+  //AudioPlayer_3DSample *v5; // edi@4
   int v6; // ebx@12
   MixerChannel *pChannel; // edi@14
   //_STREAM *v8; // esi@23
   int v9; // [sp+4h] [bp-4h]@3
 
-  //v3 = this;
-  v4 = 0;
   if ( bPlayerReady )
   {
     if ( b3DSoundInitialized )
@@ -1838,30 +1817,27 @@
       v9 = 0;
       if ( uNum3DSamples > 0 )
       {
-        v5 = p3DSamples;//;(char *)&p3DSamples[0].field_8;
-        do
+        //v5 = p3DSamples;//;(char *)&p3DSamples[0].field_8;
+        for ( v4 = 0; v4 < uNum3DSamples; ++v4 )
         {
           if ( (uStartChannel == -1 || v4 < uStartChannel || v4 > uEndChannel)
-			  && v5->field_8
-			  && pSoundList->pSounds[v5->field_8].eType != SOUND_DESC_SYSTEM)
+			  && p3DSamples[v4].field_8
+			  && pSoundList->pSounds[p3DSamples[v4].field_8].eType != SOUND_DESC_SYSTEM)
           {
-			  AIL_end_3D_sample(v5->hSample);
-            _4ABF23(v5);
-            v5->field_4 = 0;
+            AIL_end_3D_sample(p3DSamples[v4].hSample);
+            _4ABF23(&p3DSamples[v4]);
+            p3DSamples[v4].field_4 = 0;
             v4 = v9;
           }
-          ++v4;
-          v5 += 16;
+          //v5 += 16;
           v9 = v4;
         }
-        while ( v4 < uNum3DSamples );
       }
     }
-    v6 = 0;
     if ( hDigDriver && uMixerChannels > 0 )
     {
       pChannel = pMixerChannels;
-      do
+      for ( v6 = 0; v6 < uMixerChannels; ++v6 )
       {
         if ( (uStartChannel == -1 || v6 < uStartChannel || v6 > uEndChannel)
           && pSoundList->pSounds[pChannel->uSourceTrackIdx].eType != SOUND_DESC_SYSTEM)
@@ -1870,10 +1846,8 @@
           FreeChannel(pChannel);
           pChannel->source_pid = 0;
         }
-        ++v6;
         ++pChannel;
       }
-      while (v6 < uMixerChannels);
     }
     if (hSequence)
       AIL_end_sequence(hSequence);
@@ -1883,7 +1857,6 @@
   }
 }
 
-
 //----- (004AB818) --------------------------------------------------------
 void AudioPlayer::LoadAudioSnd()
 {
@@ -2084,7 +2057,6 @@
   }
 }
 
-
 //----- (004ABC9B) --------------------------------------------------------
 LSTATUS AudioPlayer::CheckA3DSupport(char a2)
 {
@@ -2120,18 +2092,11 @@
 //----- (004ABD5B) --------------------------------------------------------
 void AudioPlayer::Release() //Освободить
 {
-  AudioPlayer *pAudioPlayer; // esi@1
-  int v2; // edi@1
   MixerChannel *pMixerChannel; // ebx@3
   char v4; // dl@5
-  int v5; // ebx@6
   AudioPlayer_3DSample *p3DSample; // edi@7
-  //int v7; // edx@14
-  int v8; // ecx@14
   void *v9; // ecx@15
 
-  pAudioPlayer = this;
-  v2 = 0;
   if ( this->bPlayerReady )
   {
     CloseHandle(pVideoPlayer->hMagicVid);
@@ -2140,32 +2105,27 @@
     if ( pAudioPlayer->uMixerChannels > 0 )
     {
       pMixerChannel = pAudioPlayer->pMixerChannels;
-      do
+      for ( uint i = 0; i < pAudioPlayer->uMixerChannels; ++i )
       {
         AIL_release_sample_handle(pMixerChannel->hSample);
-        ++v2;
         ++pMixerChannel;
       }
-      while ( v2 < pAudioPlayer->uMixerChannels );
     }
     if ( ReadWindowsRegistryInt("Disable3DSound", 0) != 1 )
     {
-      v5 = 0;
       pAudioPlayer->CheckA3DSupport(0);// pAudioPlayer->CheckA3DSupport(v4);
       if ( pAudioPlayer->uNum3DSamples > 0 )
       {
         p3DSample = pAudioPlayer->p3DSamples;
-        do
+        for ( uint i = 0; i < pAudioPlayer->uNum3DSamples; ++i )
         {
           if ( p3DSample->hSample )
           {
             AIL_release_3D_sample_handle(p3DSample->hSample);
             p3DSample->hSample = 0;
           }
-          ++v5;
           ++p3DSample;
         }
-        while ( v5 < pAudioPlayer->uNum3DSamples );
       }
       if ( pAudioPlayer->h3DSoundProvider )
       {
@@ -2173,11 +2133,10 @@
         pAudioPlayer->h3DSoundProvider = 0;
       }
     }
-    v8 = (int)&pAudioPlayer->hAILRedbook;
     if ( pAudioPlayer->hAILRedbook )
     {
       AIL_redbook_stop(pAudioPlayer->hAILRedbook);
-      AIL_redbook_set_volume((HREDBOOK)v8, pAudioPlayer->sRedbookVolume);
+      AIL_redbook_set_volume((HREDBOOK)&pAudioPlayer->hAILRedbook, pAudioPlayer->sRedbookVolume);
       AIL_redbook_close(pAudioPlayer->hAILRedbook);
     }
     AIL_shutdown();
@@ -2192,28 +2151,26 @@
 //----- (004ABE55) --------------------------------------------------------
 void AudioPlayer::FreeChannel(MixerChannel *pChannel)
 {
-  int v2; // ebx@1
+  //int v2; // ebx@1
   //AudioPlayer *v3; // esi@1
-  SoundDesc *v4; // eax@2
+  //SoundDesc *v4; // eax@2
   unsigned __int8 v5; // zf@5
-  unsigned __int8 v6; // sf@5
-  char *v7; // edi@6
+  //unsigned __int8 v6; // sf@5
+  //char *v7; // edi@6
   int num_same_sound_on_channels; // eax@8
-  int v9; // ST04_4@8
+  //int v9; // ST04_4@8
   int v10; // ecx@12
   int v11; // edi@13
   int v12; // eax@13
-  unsigned __int8 v13; // of@13
+  //unsigned __int8 v13; // of@13
   int v14[16]; // [sp+Ch] [bp-48h]@8
   int num_playing_channels; // [sp+4Ch] [bp-8h]@5
-  int v16; // [sp+50h] [bp-4h]@5
+  //int v16; // [sp+50h] [bp-4h]@5
 
-  v2 = 0;
-  //v3 = this;
   if (!pSoundList->pSounds)
     return;
  
-    v4 = &pSoundList->pSounds[pChannel->uSourceTrackIdx];
+    //v4 = &pSoundList->pSounds[pChannel->uSourceTrackIdx];
     if ( pSoundList->pSounds[pChannel->uSourceTrackIdx].eType == SOUND_DESC_SWAP)
     {
       if ( pSoundList->pSounds[pChannel->uSourceTrackIdx].pSoundData[0] && 
@@ -2221,19 +2178,17 @@
       {
         num_playing_channels = 0;
         num_same_sound_on_channels = 0;
-        if ( this->uMixerChannels <=0 )
+        if ( this->uMixerChannels <= 0 )
           goto LABEL_16;
-        do
+        for ( uint i = 0; i < uMixerChannels; i++ )
         {
-          if ( pChannel->uSourceTrackID ==pMixerChannels[v2].uSourceTrackID )
+          if ( pChannel->uSourceTrackID == pMixerChannels[i].uSourceTrackID )
           {
-            v14[num_same_sound_on_channels++] = v2;
-            if ( AIL_sample_status((HSAMPLE)pMixerChannels[v2].hSample) == AIL::Sample::Playing)
+            v14[num_same_sound_on_channels++] = i;
+            if ( AIL_sample_status((HSAMPLE)pMixerChannels[i].hSample) == AIL::Sample::Playing)
               ++num_playing_channels;
           }
-          ++v2;
         }
-        while ( v2 < uMixerChannels );
         if ( !num_playing_channels )
         {
 LABEL_16:
@@ -2246,85 +2201,17 @@
               v11 = v14[v10];
               v12 = 16 * (v14[v10++] + 47);
               pMixerChannels[v11].uSourceTrackID = 0;
-              v13 = __OFSUB__(v10, num_same_sound_on_channels);
-              v6 = v10 - num_same_sound_on_channels < 0;
+              //v13 = __OFSUB__(v10, num_same_sound_on_channels);
+              //v6 = v10 - num_same_sound_on_channels < 0;
               *(unsigned int *)((char *)&bEAXSupported + v12) = 0;
             }
-            while (v10<num_same_sound_on_channels);
+            while (v10 < num_same_sound_on_channels);
           }
         }
       }
     }
 }
 
-
-
-//----- (004AAEA6) --------------------------------------------------------
-int __fastcall sub_4AAEA6_transform(RenderVertexSoft *a1)
-{
-  double v1; // st7@1
-  double v2; // st6@1
-  int result; // eax@1
-  double v4; // st5@2
-  double v5; // st4@3
-  double v6; // st3@3
-  double v7; // st7@6
-  double v8; // st6@7
-  float v9; // [sp+0h] [bp-10h]@1
-  float v10; // [sp+4h] [bp-Ch]@1
-  float v11; // [sp+8h] [bp-8h]@2
-  float v12; // [sp+8h] [bp-8h]@6
-  float v13; // [sp+Ch] [bp-4h]@2
-  float v14; // [sp+Ch] [bp-4h]@6
-
-  v1 = pBLVRenderParams->fCosineNegX;
-  v2 = pBLVRenderParams->fSineNegX;
-  v9 = pBLVRenderParams->fCosineY;
-  v10 = pBLVRenderParams->fSineY;
-  result = 0;
-  if ( pBLVRenderParams->sPartyRotX )
-  {
-    v13 = a1->vWorldPosition.x - (double)pParty->vPosition.x;
-    v11 = a1->vWorldPosition.y - (double)pParty->vPosition.y;
-    v4 = a1->vWorldPosition.z - (double)pParty->vPosition.z;
-    if ( pRenderer->pRenderD3D )
-    {
-      v5 = v11 * pBLVRenderParams->fSineY + v13 * pBLVRenderParams->fCosineY;
-      v6 = v13 * pBLVRenderParams->fSineY - v11 * pBLVRenderParams->fCosineY;
-    }
-    else
-    {
-      v5 = v13 * pBLVRenderParams->fCosineY - v11 * pBLVRenderParams->fSineY;
-      v6 = v13 * pBLVRenderParams->fSineY + v11 * pBLVRenderParams->fCosineY;
-    }
-    a1->vWorldViewPosition.x = v5 * v1 - v4 * v2;
-    a1->vWorldViewPosition.y = v6;
-    a1->vWorldViewPosition.z = v5 * v2 + v4 * v1;
-  }
-  else
-  {
-    v14 = a1->vWorldPosition.x - (double)pParty->vPosition.x;
-    v12 = a1->vWorldPosition.y - (double)pParty->vPosition.y;
-    v7 = a1->vWorldPosition.z - (double)pParty->vPosition.z;
-    if ( pRenderer->pRenderD3D )
-    {
-      a1->vWorldViewPosition.x = v12 * pBLVRenderParams->fSineY + v14 * pBLVRenderParams->fCosineY;
-      v8 = v14 * v10 - v12 * v9;
-    }
-    else
-    {
-      a1->vWorldViewPosition.x = v14 * pBLVRenderParams->fCosineY - v12 * pBLVRenderParams->fSineY;
-      v8 = v14 * v10 + v12 * v9;
-    }
-    a1->vWorldViewPosition.y = v8;
-    a1->vWorldViewPosition.z = v7;
-  }
-  return result;
-}
-
-
-
-
 //----- (004ABF23) --------------------------------------------------------
 void AudioPlayer::_4ABF23(AudioPlayer_3DSample *a2)
 {
@@ -2412,20 +2299,14 @@
 //----- (004AC004) --------------------------------------------------------
 void AudioPlayer::SetEAXPreferences()
 {
-  AudioPlayer *v1; // edi@1
-  _PROVIDER *v2; // ST00_4@2
-  _PROVIDER *v3; // ST00_4@2
   float v4; // [sp+4h] [bp-4h]@2
 
-  v1 = this;
   if ( this->bEAXSupported )
   {
-    v2 = this->h3DSoundProvider;
     v4 = 0.0;
-    AIL_set_3D_provider_preference(v2, "EAX effect volume", (int *)&v4);
-    v3 = v1->h3DSoundProvider;
+    AIL_set_3D_provider_preference(this->h3DSoundProvider, "EAX effect volume", (int *)&v4);
     v4 = 1.0;
-    AIL_set_3D_provider_preference(v3, "EAX damping", (int *)&v4);
+    AIL_set_3D_provider_preference(this->h3DSoundProvider, "EAX damping", (int *)&v4);
   }
 }
 // 4D82DC: using guessed type int __stdcall AIL_set_3D_provider_preference(int, int, int);
@@ -2433,24 +2314,22 @@
 //----- (004AC041) --------------------------------------------------------
 void AudioPlayer::SetMapEAX()
 {
-  AudioPlayer *v1; // esi@1
-  unsigned int v2; // eax@1
+  unsigned int pMapID; // eax@1
   int v3; // [sp+4h] [bp-4h]@3
 
-  v1 = this;
-  v2 = pMapStats->GetMapInfo(pCurrentMapName.data());
-  if ( v1->b3DSoundInitialized && v1->bEAXSupported )
+  pMapID = pMapStats->GetMapInfo(pCurrentMapName.data());
+  if ( this->b3DSoundInitialized && this->bEAXSupported )
   {
-    v3 = pMapStats->pInfos[v2].uEAXEnv;
+    v3 = pMapStats->pInfos[pMapID].uEAXEnv;
     if ( (unsigned int)v3 >= 0x1A )
     {
       SetEAXPreferences();
-      v1->field_214 = -1;
+      this->field_214 = -1;
     }
     else
     {
-      AIL_set_3D_provider_preference(v1->h3DSoundProvider, "EAX environment selection", &v3);
-      v1->field_214 = v3;
+      AIL_set_3D_provider_preference(this->h3DSoundProvider, "EAX environment selection", &v3);
+      this->field_214 = v3;
     }
   }
 }
@@ -2530,154 +2409,110 @@
   return 1;
 }
 
-
 //----- (004A96BE) --------------------------------------------------------
 void ReleaseSoundData(void *_this)
 {
-  int pID; // esi@1
-  char *v2; // eax@1
-
-  pID = 0;
-  v2 = (char *)&pSounds[0].pSoundData;
-  while ( *(void **)v2 != _this )
+  for ( uint i = 0; (void *)&pSounds[i].pSoundData < (void *)&pSounds[2999].pSoundData; i++ )
   {
-    v2 += 128;
-    ++pID;
-	if ( v2 > (void *)&pSounds[2999].pSoundData)//(signed int)&pAudioPlayer->p3DSamples[6].field_8 )
-      return;
+    if ( pSounds[i].pSoundData == _this )
+    {
+      pAllocator->FreeChunk(_this);
+      memset(&pSounds[i], 0, 0x80u);
+    }
   }
-  pAllocator->FreeChunk(_this);
-  memset(&pSounds[pID], 0, 0x80u);
+
 }
 
 //----- (004A96FF) --------------------------------------------------------
-SoundHeader *__fastcall FindSound_BinSearch(unsigned int uStart, unsigned int uEnd, const char *pName)
+struct SoundHeader *FindSound_BinSearch(unsigned int uStart, unsigned int uEnd, const char *pName)
 {
-  unsigned int v3; // ebx@1
-  unsigned int v4; // esi@1
-  SoundHeader *result; // eax@2
+/*  SoundHeader *result; // eax@2
+  SoundHeader *pSound;
   signed int v6; // ebx@11
-  int v7; // edi@13
-  unsigned int v8; // esi@14
-  unsigned int v9; // esi@20
-  unsigned int v10; // [sp+Ch] [bp-4h]@1
 
-  v3 = uEnd;
-  v10 = uEnd;
-  v4 = uStart;
   while ( 1 )
   {
-    v6 = v3 - v4;
-    result = &pAudioPlayer->pSoundHeaders[v6 / 2 + v4];
-    if ( !result )
-      return result;
-    result = (SoundHeader *)_stricmp(pName, result->pSoundName);
-    if ( !result )
-      uFindSound_BinSearch_ResultID = v6 / 2 + v4;
-    if ( v4 == v10 )
-      goto LABEL_17;
-    if ( (signed int)result < 0 )
-      break;
-    if ( v6 <= 4 )
+    v6 = uEnd - uStart;
+    pSound = &pAudioPlayer->pSoundHeaders[v6 / 2 + uStart];
+    if ( !pSound )
+      return false;
+    result = (SoundHeader *)_stricmp(pName, pSound->pSoundName);
+    if ( !_stricmp(pName, pSound->pSoundName) )
+      uFindSound_BinSearch_ResultID = v6 / 2 + uStart;
+    if ( uStart == uEnd )
     {
-      v7 = v4;
-      if ( (signed int)v4 < (signed int)v10 )
-      {
-        v9 = v4;
-        do
-        {
-          result = (SoundHeader *)_stricmp(pName, pAudioPlayer->pSoundHeaders[v9].pSoundName);
-          if ( !result )
-            goto LABEL_24;
-          ++v7;
-          ++v9;
-        }
-        while ( v7 < (signed int)v10 );
-      }
-LABEL_17:
       uFindSound_BinSearch_ResultID = -1;
       return result;
     }
-    v4 += v6 / 2;
+    if ( (signed int)result < 0 )
+      break;
+
+    if ( v6 <= 4 )
+    {
+      if ( (signed int)uStart < (signed int)uEnd )
+      {
+        for ( uint i = uStart; i < (signed int)uEnd; ++i )
+        {
+          if ( !_stricmp(pName, pAudioPlayer->pSoundHeaders[i].pSoundName) )
+          {
+            uFindSound_BinSearch_ResultID = i;
+            return &pAudioPlayer->pSoundHeaders[i];
+          }
+        }
+      }
+      uFindSound_BinSearch_ResultID = -1;
+      return false;
+    }
+
+    uStart += v6 / 2;
 LABEL_10:
-    v3 = v10;
+	;
   }
   if ( v6 > 4 )
   {
-    v10 = v6 / 2 + v4;
+    uEnd = v6 / 2 + uStart;
     goto LABEL_10;
   }
-  v7 = v4;
-  if ( (signed int)v4 >= (signed int)v10 )
-    goto LABEL_17;
-  v8 = v4;
-  while ( 1 )
+  if ( (signed int)uStart >= (signed int)uEnd )
+  {
+    uFindSound_BinSearch_ResultID = -1;
+    return false;
+  }*/
+  for ( uint i = uStart; i < (signed int)uEnd; ++i )
   {
-    result = (SoundHeader *)_stricmp(pName, pAudioPlayer->pSoundHeaders[v8].pSoundName);
-    if ( !result )
-      break;
-    ++v7;
-    ++v8;
-    if ( v7 >= (signed int)v10 )
-      goto LABEL_17;
+    if ( !_stricmp(pName, pAudioPlayer->pSoundHeaders[i].pSoundName) )
+    {
+      uFindSound_BinSearch_ResultID = i;
+      return &pAudioPlayer->pSoundHeaders[i];
+    }
   }
-LABEL_24:
-  uFindSound_BinSearch_ResultID = v7;
-  return result;
+  uFindSound_BinSearch_ResultID = -1;
+  return false;
 }
 // F1B4C8: using guessed type int uFindSound_BinSearch_ResultID;
 
 //----- (004A97C6) --------------------------------------------------------
 SoundData *LoadSound(const char *pSoundName, SoundData *pOutBuff, unsigned int uID)
 {
-  SoundData *v3; // edi@1
-  int v4; // ecx@1
-  //Sound *v5; // eax@1
-  SoundHeader *v6; // esi@5
-  unsigned int *pDecompressedSize; // ebx@5
-  unsigned int v8; // eax@5
-  unsigned int v9; // eax@7
-  SoundData *result; // eax@9
-  int v11; // esi@15
-  int v12; // eax@15
-  char *v13; // ecx@16
-  int v14; // eax@19
-  std::string v15; // [sp-18h] [bp-34h]@12
-  const char *v16; // [sp-8h] [bp-24h]@12
-  int v17; // [sp-4h] [bp-20h]@12
-  char v18; // [sp+Ch] [bp-10h]@12
-  int v19; // [sp+10h] [bp-Ch]@5
   DWORD NumberOfBytesRead; // [sp+14h] [bp-8h]@8
-  const char *pSoundName_; // [sp+18h] [bp-4h]@1
 
-  pSoundName_ = pSoundName;
-  v3 = pOutBuff;
-  v4 = 0;
   for (uint i = 0; i < 3000; ++i)
-      {
-      if (pSounds[i].uID == uID)
-          return pSounds[i].pSoundData;
-      }
-  FindSound_BinSearch(0, pAudioPlayer->uNumSoundHeaders, pSoundName_);
-  if ( uFindSound_BinSearch_ResultID == -1 )
   {
-    result = 0;
-    return result;
+    if (pSounds[i].uID == uID)
+      return pSounds[i].pSoundData;
   }
-  v6 = &pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID];
-  pDecompressedSize = &v6->uDecompressedSize;
-  v8 = v6->uDecompressedSize;
-  v19 = v6->uDecompressedSize;
-  if ( v3 == (SoundData *)-1 )
-    v3 = (SoundData *)pAllocator->AllocNamedChunk(0, v8 + 4, pSoundName_);
-  SetFilePointer(pAudioPlayer->hAudioSnd, v6->uFileOffset, 0, 0);
-  v9 = *pDecompressedSize;
-  if ( (signed int)v6->uCompressedSize >= (signed int)*pDecompressedSize )
+  FindSound_BinSearch(0, pAudioPlayer->uNumSoundHeaders, pSoundName);
+  if ( uFindSound_BinSearch_ResultID == -1 )
+    return 0;
+  if ( pOutBuff == (SoundData *)-1 )
+    pOutBuff = (SoundData *)pAllocator->AllocNamedChunk(0, pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize + 4, pSoundName);
+  SetFilePointer(pAudioPlayer->hAudioSnd, pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uFileOffset, 0, 0);
+  if ( (signed int)pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uCompressedSize >= (signed int)pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize )
   {
-    v6->uCompressedSize = v9;
-    if ( v9 )
+    pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uCompressedSize = pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize;
+    if ( pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize )
     {
-      ReadFile(pAudioPlayer->hAudioSnd, (char *)v3 + 4, v9, &NumberOfBytesRead, 0);
+      ReadFile(pAudioPlayer->hAudioSnd, (char *)pOutBuff + 4, pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize, &NumberOfBytesRead, 0);
     }
     else
     {
@@ -2686,38 +2521,25 @@
   }
   else
   {
-    uID = (unsigned int)malloc(v6->uCompressedSize);
-    ReadFile(pAudioPlayer->hAudioSnd, (LPVOID)uID, v6->uCompressedSize, &NumberOfBytesRead, 0);
-    zlib::MemUnzip((char *)v3 + 4, &v6->uDecompressedSize, (const void *)uID, v6->uCompressedSize);
+    uID = (unsigned int)malloc(pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uCompressedSize);
+    ReadFile(pAudioPlayer->hAudioSnd, (LPVOID)uID, pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uCompressedSize, &NumberOfBytesRead, 0);
+    zlib::MemUnzip((char *)pOutBuff + 4, &pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize, (const void *)uID, pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uCompressedSize);
     free((void *)uID);
   }
-  if ( v3 )
+  if ( pOutBuff )
   {
-    v11 = v19;
-    v12 = 0;
-    *(int *)v3 = v19;
+    *(int *)pOutBuff = pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize;
     uLastLoadedSoundID = 0;
     if ( pSounds[0].pSoundData )
     {
-      v13 = (char *)&pSounds[0].pSoundData;
-      do
-      {
-        v13 += 128;
-        ++v12;
-      }
-      while ( *(int *)v13 );
-      uLastLoadedSoundID = v12;
+      for ( uint i = 0; pSounds[i].pSoundData; i++ )
+        ++uLastLoadedSoundID;
     }
-    v16 = pSounds[v12].SoundName;
-    strcpy((char *)v16, pSoundName_);
-    v14 = uLastLoadedSoundID++ << 7;
-    pSoundList->uTotalLoadedSoundSize += v11;
-    pSounds[uLastLoadedSoundID].pSoundData = v3;
-    result = v3;
+    strcpy((char *)pSounds[uLastLoadedSoundID].SoundName, pSoundName);
+    pSoundList->uTotalLoadedSoundSize += pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize;
+    pSounds[uLastLoadedSoundID].pSoundData = pOutBuff;
+    return pOutBuff;
   }
   else
-  {
-    result = 0;
-  }
-  return result;
+    return 0;
 }
--- a/CastSpellInfo.cpp	Tue Jul 23 16:34:00 2013 +0600
+++ b/CastSpellInfo.cpp	Fri Jul 26 18:11:36 2013 +0600
@@ -166,8 +166,8 @@
   int v440; // eax@843
   int v441; // eax@847
   signed int v445; // edi@857
-  int v446; // ecx@862
-  LevelDecoration *v447; // edi@864
+  //int v446; // ecx@862
+  //LevelDecoration *v447; // edi@864
   __int16 v448; // ax@864
   char *v449; // esi@870
   int v450; // eax@870
@@ -255,7 +255,7 @@
   int v671; // [sp+4h] [bp-E80h]@146
   int v675; // [sp+4h] [bp-E80h]@800
   int v676; // [sp+4h] [bp-E80h]@807
-  int v677; // [sp+4h] [bp-E80h]@861
+  //int v677; // [sp+4h] [bp-E80h]@861
   int v679[800]; // [sp+14h] [bp-E70h]@515
   AIDirection a3; // [sp+C94h] [bp-1F0h]@21
   int v681[4]; // [sp+CB0h] [bp-1D4h]@1137
@@ -2971,31 +2971,26 @@
 							LODWORD(v727) = 1;
 							break;
 						}
-						dword_507CD8 = 1;
-						v677 = 1;
+						OpenedTelekinesis = true;
 						if ( uCurrentlyLoadedLevelType == LEVEL_Indoor)
-							v446 = pIndoor->pFaceExtras[pIndoor->pFaces[v445].uFaceExtraID].uEventID;
+							v448 = pIndoor->pFaceExtras[pIndoor->pFaces[v445].uFaceExtraID].uEventID;
 						else
-							v446 = pOutdoor->pBModels[a2 >> 9].pFaces[v445 & 0x3F].sCogTriggeredID;
-						EventProcessor(v446, a2, v677);
+							v448 = pOutdoor->pBModels[a2 >> 9].pFaces[v445 & 0x3F].sCogTriggeredID;
+						EventProcessor(v448, a2, 1);
 						LODWORD(v727) = 1;
 						break;
 					}
-					v447 = &pLevelDecorations[v445];
-					dword_507CD8 = 1;
-					v448 = v447->field_16_event_id;
-					if (v448)
+					OpenedTelekinesis = true;
+					if ( pLevelDecorations[v445].field_16_event_id )
 					{
-						v677 = 1;
-						v446 = v448;
-						EventProcessor(v446, a2, v677);
+						EventProcessor(v448, a2, 1);
 						LODWORD(v727) = 1;
 						break;
 					}
-					if ( v447->IsInteractive() )
+					if ( pLevelDecorations[v445].IsInteractive() )
 					{
-						activeLevelDecoration = v447;
-						EventProcessor(stru_5E4C90._decor_events[v447->_idx_in_stru123 - 75] + 380, 0, 1);
+						activeLevelDecoration = &pLevelDecorations[v445];
+						EventProcessor(stru_5E4C90._decor_events[pLevelDecorations[v445]._idx_in_stru123 - 75] + 380, 0, 1);
 						activeLevelDecoration = NULL;
 					}
 				}
--- a/Chest.cpp	Tue Jul 23 16:34:00 2013 +0600
+++ b/Chest.cpp	Fri Jul 26 18:11:36 2013 +0600
@@ -166,14 +166,14 @@
       pAudioPlayer->PlaySound(SOUND_8, 0, 0, -1, 0, 0, 0, 0);
       pSpellObject.ExplosionTraps();
       chest->uFlags &= 0xFEu;
-      if ( uActiveCharacter && !qword_A750D8 && !dword_507CD8 )
+      if ( uActiveCharacter && !qword_A750D8 && !OpenedTelekinesis )
       {
         qword_A750D8 = 256i64;
         PlayerSpeechID = SPEECH_5;
         uSpeakingCharacter = uActiveCharacter;
       }
       pIcons_LOD->RemoveTexturesPackFromTextureList();
-      dword_507CD8 = 0;
+      OpenedTelekinesis = false;
       return false;
     }
     chest->uFlags &= 0xFEu;
@@ -183,10 +183,10 @@
   pAudioPlayer->PlaySound(SOUND_OpenChest, 0, 0, -1, 0, 0, 0, 0);
   if ( flag_shout == true )
   {
-    if ( !dword_507CD8 )
+    if ( !OpenedTelekinesis )
       pPlayers[uActiveCharacter]->PlaySound(SPEECH_4, 0);
   }
-  dword_507CD8 = 0;
+  OpenedTelekinesis = false;
   pChestWindow = pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_Chest, uChestID, 0);
   pBtn_ExitCancel = pChestWindow->CreateButton(471, 445, 169,  35, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[79], pIcons_LOD->GetTexture(uExitCancelTextureId), 0);// Exit
                     pChestWindow->CreateButton(  7,   8, 460, 343, 1, 0, UIMSG_CHEST_ClickItem, 0, 0, "", 0);
--- a/Indoor.cpp	Tue Jul 23 16:34:00 2013 +0600
+++ b/Indoor.cpp	Fri Jul 26 18:11:36 2013 +0600
@@ -6908,4 +6908,51 @@
     PortalFace._screen_space_y[bottom_num_vertices] = PortalFace._screen_space_y[0];
   }
   return bottom_num_vertices;
+}
+
+//----- (004AAEA6) --------------------------------------------------------
+int __fastcall sub_4AAEA6_transform(RenderVertexSoft *a1)
+{
+  double v4; // st5@2
+  double v5; // st4@3
+  float v11; // [sp+8h] [bp-8h]@2
+  float v12; // [sp+8h] [bp-8h]@6
+  float v13; // [sp+Ch] [bp-4h]@2
+  float v14; // [sp+Ch] [bp-4h]@6
+
+  if ( pBLVRenderParams->sPartyRotX )
+  {
+    v13 = a1->vWorldPosition.x - (double)pParty->vPosition.x;
+    v11 = a1->vWorldPosition.y - (double)pParty->vPosition.y;
+    v4 = a1->vWorldPosition.z - (double)pParty->vPosition.z;
+    if ( pRenderer->pRenderD3D )
+    {
+      v5 = v11 * pBLVRenderParams->fSineY + v13 * pBLVRenderParams->fCosineY;
+      a1->vWorldViewPosition.y = v13 * pBLVRenderParams->fSineY - v11 * pBLVRenderParams->fCosineY;
+    }
+    else
+    {
+      v5 = v13 * pBLVRenderParams->fCosineY - v11 * pBLVRenderParams->fSineY;
+      a1->vWorldViewPosition.y = v13 * pBLVRenderParams->fSineY + v11 * pBLVRenderParams->fCosineY;
+    }
+    a1->vWorldViewPosition.x = v5 * pBLVRenderParams->fCosineNegX - v4 * pBLVRenderParams->fSineNegX;
+    a1->vWorldViewPosition.z = v5 * pBLVRenderParams->fSineNegX + v4 * pBLVRenderParams->fCosineNegX;
+  }
+  else
+  {
+    v14 = a1->vWorldPosition.x - (double)pParty->vPosition.x;
+    v12 = a1->vWorldPosition.y - (double)pParty->vPosition.y;
+    a1->vWorldViewPosition.z = a1->vWorldPosition.z - (double)pParty->vPosition.z;
+    if ( pRenderer->pRenderD3D )
+    {
+      a1->vWorldViewPosition.x = v12 * pBLVRenderParams->fSineY + v14 * pBLVRenderParams->fCosineY;
+      a1->vWorldViewPosition.y = v14 * pBLVRenderParams->fSineY - v12 * pBLVRenderParams->fCosineY;
+    }
+    else
+    {
+      a1->vWorldViewPosition.x = v14 * pBLVRenderParams->fCosineY - v12 * pBLVRenderParams->fSineY;
+      a1->vWorldViewPosition.y = v14 * pBLVRenderParams->fSineY + v12 * pBLVRenderParams->fCosineY;
+    }
+  }
+  return 0;
 }
\ No newline at end of file
--- a/mm7_2.cpp	Tue Jul 23 16:34:00 2013 +0600
+++ b/mm7_2.cpp	Fri Jul 26 18:11:36 2013 +0600
@@ -3342,33 +3342,29 @@
 // 6836C8: using guessed type int 6836C8_num_decorations_6807E8;
 
 //----- (004621DA) --------------------------------------------------------
-int __fastcall int_get_vector_length(signed int a1, signed int a2, signed int a3)
+int int_get_vector_length(signed int x, signed int y, signed int z)
 {
   signed int v3; // eax@2
-  signed int v4; // eax@3
-  signed int v5; // esi@4
-  signed int v6; // esi@6
-
-  if ( a1 < a2 )
-  {
-    v3 = a1;
-    a1 = a2;
-    a2 = v3;
-  }
-  v4 = a3;
-  if ( a1 < a3 )
-  {
-    v5 = a1;
-    a1 = a3;
-    v4 = v5;
-  }
-  if ( a2 < v4 )
-  {
-    v6 = a2;
-    a2 = v4;
-    v4 = v6;
-  }
-  return (11 * a2 >> 5) + a1 + (v4 >> 2);
+
+  if ( x < y )
+  {
+    v3 = x;
+    x = y;
+    y = v3;
+  }
+  if ( x < z )
+  {
+    v3 = x;
+    x = z;
+    z = v3;
+  }
+  if ( y < z )
+  {
+    v3 = y;
+    y = z;
+    z = v3;
+  }
+  return (11 * y >> 5) + x + (z >> 2);
 }
 
 OPENFILENAMEA ofn;
--- a/mm7_data.cpp	Tue Jul 23 16:34:00 2013 +0600
+++ b/mm7_data.cpp	Fri Jul 26 18:11:36 2013 +0600
@@ -964,7 +964,7 @@
 int dword_507CC0_activ_ch; // weak
 __int64 GameUI_RightPanel_BookFlashTimer; // weak
 int _507CD4_RestUI_hourglass_anim_controller; // weak
-int dword_507CD8; // weak
+bool OpenedTelekinesis;
 std::array<int, 50> dword_50B570; // weak
 std::array<int, 50> dword_50B638; // weak
 stru367 PortalFace;
--- a/mm7_data.h	Tue Jul 23 16:34:00 2013 +0600
+++ b/mm7_data.h	Fri Jul 26 18:11:36 2013 +0600
@@ -607,7 +607,7 @@
 extern int dword_507CC0_activ_ch; // weak
 extern __int64 GameUI_RightPanel_BookFlashTimer; // weak
 extern int _507CD4_RestUI_hourglass_anim_controller; // weak
-extern int dword_507CD8; // weak
+extern bool OpenedTelekinesis; // weak
 extern std::array<int, 50> dword_50B570; // weak
 extern std::array<int, 50> dword_50B638; // weak
 extern struct stru367 PortalFace;
@@ -1293,7 +1293,7 @@
 void __fastcall PrepareToLoadODM(unsigned int bLoading, struct OutdoorCamera *a2);
 void __cdecl sub_461103();
 int __cdecl sub_4613C4();
-int __fastcall int_get_vector_length(signed int a1, signed int a2, signed int a3);
+int int_get_vector_length(signed int x, signed int y, signed int z);
 int __cdecl sub_46224A();
 int __cdecl crt_init_globals_462620();
 void __cdecl crt_init_globals_462659();
@@ -1427,11 +1427,11 @@
 void Present_ColorKey();
 void Present_NoColorKey();
 unsigned int ModulateColor(unsigned int diffuse, float multiplier); // idb
-struct SoundHeader *__fastcall FindSound_BinSearch(unsigned int uStart, unsigned int uEnd, const char *pName);
+struct SoundHeader *FindSound_BinSearch(unsigned int uStart, unsigned int uEnd, const char *pName);
 struct SoundData *LoadSound(const char *pSoundName, struct SoundData *pOutBuff, unsigned int uID);
 int __fastcall sub_4AAEA6_transform(RenderVertexSoft *a1);
 int __fastcall sub_4AB66C(int, int); // weak
-int __fastcall GetSoundStrengthByDistanceFromParty(int a1, int a2, int a3);
+int GetSoundStrengthByDistanceFromParty(int x, int y, int z);
 struct _DIG_DRIVER *Audio_GetFirstHardwareDigitalDriver(void);
 void __cdecl PlayLevelMusic();
 unsigned int __fastcall sub_4B0E07(unsigned int uFaceID); // idb