Mercurial > might-and-magic-trilogy
view AudioPlayer.cpp @ 127:9eac46182d8f
Слияние
author | Ritor1 |
---|---|
date | Sun, 04 Nov 2012 09:37:39 +0600 |
parents | f76e4ea4a224 |
children | dcd8af594b02 |
line wrap: on
line source
#include <string> #include "AudioPlayer.h" #include "Allocator.h" #include "FrameTableInc.h" #include "Indoor.h" #include "LayingItem.h" #include "Party.h" #include "Actor.h" #include "Game.h" #include "DecorationList.h" #include "Time.h" #include "OSInfo.h" #include "Math.h" #include "MapInfo.h" #include "Log.h" #include "Bink_Smacker.h" #include "mm7_data.h" PCMWAVEFORMAT pcmWaveFormat; int Aureal3D_SplashScreen; int Aureal3D_SplashAudio; int uFindSound_BinSearch_ResultID; // weak int uLastLoadedSoundID; // weak int sLastTrackLengthMS; Sound pSounds[3000]; AudioPlayer *pAudioPlayer; SoundList *pSoundList; stru339_spell_sound stru_A750F8[4]; stru339_spell_sound stru_AA1058[4]; unsigned __int8 uSoundVolumeMultiplier = 4; unsigned __int8 uVoicesVolumeMultiplier = 4; unsigned __int8 uMusicVolimeMultiplier = 4; int bWalkSound; // idb float pSoundVolumeLevels[777]; // idb void ReleaseSoundData(void *_this); //----- (004A9953) -------------------------------------------------------- void SoundList::Initialize() { SoundList *v1; // esi@1 signed int v2; // edi@2 SoundDesc *v3; // eax@5 void *v4; // ebx@7 unsigned int uSoundSize; // eax@7 char *pSoundBytes; // ebx@7 AILFILETYPE v7; // eax@7 int v8; // eax@8 char pSoundName[120]; // [sp+4h] [bp-A4h]@4 AILSOUNDINFO v10; // [sp+7Ch] [bp-2Ch]@10 int v12; // [sp+A0h] [bp-8h]@12 int a2; // [sp+A4h] [bp-4h]@1 v1 = this; a2 = 1; if ( (signed int)this->uNumSounds > 1 ) { v2 = 1; while ( 1 ) { if ( v1->pSounds[v2].eType != SOUND_DESC_SYSTEM || (sprintf(pSoundName, "%s", pSounds[v2].pSoundName), v1->pSounds[v2].pSoundData[0] = ::LoadSound(pSoundName, (SoundData *)0xFFFFFFFF, pSounds[v2].uSoundID), !pAudioPlayer->b3DSoundInitialized) || (v3 = &v1->pSounds[v2], !(v3->uFlags & 2)) || !v3->pSoundData[0] ) goto LABEL_17; v4 = v3->pSoundData[0]; uSoundSize = *(int *)v4; pSoundBytes = (char *)v4 + 4; v7 = AIL_file_type(pSoundBytes, uSoundSize); if ( !v7 ) goto LABEL_15; v8 = v7 - 1; if ( v8 ) break; v1->pSounds[v2].p3DSound = v1->pSounds[v2].pSoundData[0]; LABEL_16: v1->_4A9DCD(a2, 1); LABEL_17: ++a2; ++v2; if ( a2 >= (signed int)v1->uNumSounds ) return; } if ( v8 == 1 ) { if ( AIL_WAV_info(pSoundBytes, &v10) && v10.uChannels != 2 ) { if ( !AIL_decompress_ADPCM(&v10, &v1->pSounds[v2].p3DSound, &v12) ) { v1->pSounds[v2].p3DSound = 0; LOBYTE(v1->pSounds[v2].bDecompressed) = 1; } } goto LABEL_16; } LABEL_15: LOBYTE(v1->pSounds[v2].bDecompressed) = 0; goto LABEL_16; } } //----- (004A9A67) -------------------------------------------------------- __int16 SoundList::_4A9A67(int a1, unsigned int a3) { AILSOUNDINFO v24; // [sp+84h] [bp-28h]@23 if (bNoSound || !uNumSounds) return 0; uint uSoundIdx = 0; SoundDesc *pSound = nullptr; for (uint i = 1; i < uNumSounds; ++i) if (pSounds[i].uSoundID == a1) { uSoundIdx = i; pSound = &pSounds[i]; break; } if (!pSound) return 0; if (pSound->uFlags & 2 && pSound->p3DSound || ~pSound->uFlags & 2 && pSound->pSoundData[0]) return uSoundIdx; if (!pSound->pSoundData[0]) pSound->pSoundData[0] = ::LoadSound(pSound->pSoundName, (SoundData *)0xFFFFFFFF, pSound->uSoundID); if (!pSound->pSoundData[0]) return 0; if (a3) pSound->uFlags |= 1u; if (!pAudioPlayer->b3DSoundInitialized) return uSoundIdx; if (~pSound->uFlags & 2 || !pSound->pSoundData[0]) return uSoundIdx; auto pSoundData = pSound->pSoundData[0]; switch (AIL_file_type((void *)pSoundData->pData, pSoundData->uDataSize)) { default: case AILFILETYPE_UNKNOWN: pSound->bDecompressed = false; return 0; case AILFILETYPE_PCM_WAV: pSound->p3DSound = pSound->pSoundData[0]; return uSoundIdx; case AILFILETYPE_ADPCM_WAV: if (AIL_WAV_info((void *)pSoundData->pData, &v24) && v24.uChannels != 2) { if (!AIL_decompress_ADPCM(&v24, &pSound->p3DSound, &a1) ) { pSound->p3DSound = nullptr; pSound->bDecompressed = true; _4A9DCD(uSoundIdx, 0); } } return uSoundIdx; }; } //----- (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 //v6 = this; v7 = 0; //v22 = this; //v8 = this->uNumSounds == 0; //v9 = (this->uNumSounds & 0x80000000u) != 0; v26 = 0; if (!uNumSounds) return 0; v24 = 0; v25 = 44; while ( 1 ) { v10 = pSounds; 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)uNumSounds ) return 0; } v12 = 0; while ( _strcmpi(pAudioPlayer->pSoundHeaders[v12].pSoundName, v11->pSoundName) ) { ++v7; ++v12; if ( v7 >= (signed int)pAudioPlayer->uNumSoundHeaders ) { 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 ) Abortf("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); } } 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; pSounds->pSoundData[a6 + 30 * v26] = (SoundData *)lpBuffer; *pOutSoundSize = v16; return result; } //----- (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->uNumSounds > 0 ) { v3 = 0; do { result = v1->pSounds; v5 = result[v3].pSoundData[0]; if ( v5 ) { ReleaseSoundData(v5); v1->pSounds[v3].pSoundData[0] = 0; result = (SoundDesc *)((char *)&v1->pSounds[v3] + 40); *(int *)&result->pSoundName[0] &= 0xFFFFFFFEu; } ++v2; ++v3; } while ( v2 < (signed int)v1->uNumSounds ); } return result; } //----- (004A9D79) -------------------------------------------------------- void SoundList::_4A9D79(int a2) { SoundList *v2; // esi@1 int v3; // edi@1 signed int i; // ebx@1 SoundDesc *v5; // eax@2 SOUND_DESC_TYPE v6; // ecx@2 void *v7; // eax@5 v2 = this; v3 = 0; for ( i = 0; i < (signed int)v2->uNumSounds; ++v3 ) { v5 = &v2->pSounds[v3]; v6 = v5->eType; if ( v6 != SOUND_DESC_SYSTEM && (a2 || v6 != SOUND_DESC_LOCK) ) { v7 = v5->pSoundData[0]; if ( v7 ) { ReleaseSoundData(v7); v2->pSounds[v3].pSoundData[0] = 0; } v2->pSounds[v3].uFlags &= 0xFFFFFFFEu; } ++i; } } //----- (004A9DCD) -------------------------------------------------------- void SoundList::_4A9DCD(unsigned int uSoundID, char a3) { unsigned int v3; // esi@1 //SoundList *v4; // edi@1 SoundDesc *v5; // eax@1 void *v6; // ecx@8 v3 = uSoundID; //v4 = this; v5 = &this->pSounds[uSoundID]; if ( v5->eType != SOUND_DESC_SYSTEM ) { if ( v5->uFlags & 2 && v5->p3DSound && a3 ) { if ( LOBYTE(v5->bDecompressed) ) AIL_mem_free_lock(v5->p3DSound); pSounds[v3].p3DSound = 0; pSounds[v3].uFlags &= 0xFFFFFFFEu; } v6 = pSounds[v3].pSoundData[0]; if ( v6 ) { ReleaseSoundData(v6); pSounds[v3].pSoundData[0] = 0; pSounds[v3].uFlags &= 0xFFFFFFFEu; } } } //----- (004A9E3D) -------------------------------------------------------- void SoundList::ToFile() { SoundList *v1; // esi@1 FILE *v2; // eax@1 FILE *v3; // edi@1 v1 = this; v2 = fopen("data\\dsounds.bin", "wb"); v3 = v2; if ( !v2 ) Abortf("Unable to save dsounds.bin!"); fwrite(v1, 4u, 1u, v2); fwrite(v1->pSounds, 0x78u, v1->uNumSounds, v3); fclose(v3); } //----- (004A9E89) -------------------------------------------------------- void *SoundList::FromFile(void *pSerialized) { uNumSounds = *(int *)pSerialized; pSounds = (SoundDesc *)pAllocator->AllocNamedChunk(pSounds, 120 * uNumSounds, "Snd Des."); return memcpy(pSounds, (char *)pSerialized + 4, 120 * uNumSounds); } //----- (004A9ED0) -------------------------------------------------------- int SoundList::FromFileTxt(const char *Args) { SoundList *v2; // ebx@1 __int32 v3; // edi@1 FILE *v4; // eax@1 unsigned int v5; // esi@3 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 FILE *File; // [sp+2F8h] [bp-4h]@1 unsigned int Argsa; // [sp+304h] [bp+8h]@3 v2 = this; pAllocator->FreeChunk(this->pSounds); v3 = 0; v2->pSounds = 0; v2->uNumSounds = 0; v4 = fopen(Args, "r"); File = v4; if ( !v4 ) Abortf("SoundListClass::load - Unable to open file: %s."); v5 = 0; Argsa = 0; if ( fgets(&Buf, 490, v4) ) { do { *strchr(&Buf, 10) = 0; memcpy(&v19, texture_frame_table_txt_parser(&Buf, &v18), sizeof(v19)); if ( v19.field_0 && *v19.pProperties[0] != 47 ) ++Argsa; } while ( fgets(&Buf, 490, File) ); v5 = Argsa; v3 = 0; } v2->uNumSounds = v5; v6 = pAllocator->AllocNamedChunk(v2->pSounds, 120 * v5, "Snd Des."); v2->pSounds = (SoundDesc *)v6; if ( v6 == (void *)v3 ) Abortf("SoundListClass::load - Out of Memory!"); memset(v6, v3, 120 * v2->uNumSounds); v7 = File; v2->uNumSounds = v3; fseek(v7, v3, v3); for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) ) { *strchr(&Buf, 10) = 0; memcpy(&v19, texture_frame_table_txt_parser(&Buf, &v18), sizeof(v19)); if ( v19.field_0 && *v19.pProperties[0] != 47 ) { sprintf(v2->pSounds[v2->uNumSounds].pSoundName, "%s", v19.pProperties[0]); v9 = atoi(v19.pProperties[1]); v10 = v19.pProperties[2]; v2->pSounds[v2->uNumSounds].uSoundID = v9; if ( _strcmpi(v10, "system") ) { if ( _strcmpi(v19.pProperties[2], "swap") ) { v11 = _strcmpi(v19.pProperties[2], "lock"); v12 = v2->pSounds; v13 = v11 == 0; v14 = v2->uNumSounds; if ( v13 ) v12[v14].eType = SOUND_DESC_LOCK; else v12[v14].eType = SOUND_DESC_LEVEL; } else { v2->pSounds[v2->uNumSounds].eType = SOUND_DESC_SWAP; } } else { v2->pSounds[v2->uNumSounds].eType = SOUND_DESC_SYSTEM; } if ( v19.field_0 >= 4 && !_strcmpi(v19.pProperties[3], "3D") ) { v15 = (int)&v2->pSounds[v2->uNumSounds].uFlags; *(int *)v15 |= 2u; } ++v2->uNumSounds; } } fclose(File); return 1; } //----- (004AA13F) -------------------------------------------------------- void AudioPlayer::PlayMusicTrack(MusicID eTrack) { if (!bNoSound && bPlayerReady && hAILRedbook && uMusicVolimeMultiplier) { AIL_redbook_stop(hAILRedbook); AIL_redbook_set_volume(hAILRedbook, (signed)(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0)); AIL_redbook_track_info(hAILRedbook, eTrack, &uCurrentMusicTrackStartMS, &uCurrentMusicTrackEndMS); AIL_redbook_play(hAILRedbook, uCurrentMusicTrackStartMS + 1, uCurrentMusicTrackEndMS); uCurrentMusicTrackLength = ((uCurrentMusicTrackEndMS - uCurrentMusicTrackStartMS) * 128) / 1000; } } //----- (004AA1F3) -------------------------------------------------------- void AudioPlayer::SetMusicVolume(int vol) { if (bPlayerReady) { if (hAILRedbook) AIL_redbook_set_volume(hAILRedbook, vol); } } //----- (004AA214) -------------------------------------------------------- void AudioPlayer::SetMasterVolume(unsigned int uVolume) { AudioPlayer *v2; // esi@1 _DIG_DRIVER *hDrv; // eax@2 v2 = this; if ( this->bPlayerReady ) { hDrv = this->hDigDriver; this->uMasterVolume = uVolume; if ( hDrv ) AIL_set_digital_master_volume(hDrv, uVolume); if ( v2->b3DSoundInitialized ) v2->s3DSoundVolume = (signed __int64)((double)(signed int)uVolume * 0.5); } } // 4D8304: using guessed type int __stdcall AIL_set_digital_master_volume(int, int); //----- (004AA258) -------------------------------------------------------- void AudioPlayer::_4AA258(int a2) { AudioPlayer *v2; // esi@1 int v3; // edi@4 AudioPlayer_3DSample *v4; // ebx@5 int v5; // ebx@11 MixerChannel *v6; // edi@12 v2 = this; if ( this->bPlayerReady ) { if ( this->b3DSoundInitialized && a2 && (v3 = 0, this->uNum3DSamples > 0) ) { v4 = this->p3DSamples; while ( v4->field_4 != a2 || AIL_3D_sample_status(v4->hSample) != 4 ) { ++v3; ++v4; if ( v3 >= v2->uNum3DSamples ) goto LABEL_9; } AIL_end_3D_sample(v2->p3DSamples[v3].hSample); } else { LABEL_9: if ( v2->hDigDriver ) { if ( a2 ) { v5 = 0; if ( v2->uMixerChannels > 0 ) { v6 = v2->pMixerChannels; do { if ( v6->dword_000004 == a2 ) { if ( AIL_sample_status(v6->hSample) == 4 ) { AIL_end_sample(v6->hSample); _4ABE55(v6); } } ++v5; ++v6; } while ( v5 < v2->uMixerChannels ); } } } } } } // 4D82F4: using guessed type int __stdcall AIL_3D_sample_status(int); // 4D82F8: using guessed type int __stdcall AIL_sample_status(int); // 4D82FC: using guessed type int __stdcall AIL_end_sample(int); // 4D8300: using guessed type int __stdcall AIL_end_3D_sample(int); //----- (004AA306) -------------------------------------------------------- void AudioPlayer::PlaySound(SoundID eSoundID, signed int a3, unsigned int uNumRepeats, signed int a5, signed int a6, int a7, unsigned int uVolume, int sPlaybackRate) { AudioPlayer *v9; // esi@1 signed int v10; // edx@5 int *pSoundID; // ecx@6 int v12; // edi@13 signed int v13; // ecx@17 signed int v14; // eax@20 int v15; // eax@24 signed int v16; // eax@25 LayingItem *v17; // eax@28 signed int v18; // eax@29 Actor *v19; // eax@32 signed int v20; // ecx@32 double v21; // st7@32 signed int v22; // ecx@33 AudioPlayer_3DSample *v23; // esi@53 AudioPlayer_3DSample *v24; // esi@61 int v25; // esi@67 double v26; // st7@68 int v27; // ST18_4@68 int v28; // ebx@68 int v29; // eax@68 AudioPlayer_3DSample *v30; // esi@69 int v31; // ST18_4@70 int v32; // ebx@70 int v33; // eax@70 int v34; // eax@70 char v35; // zf@70 signed int v36; // ebx@74 AudioPlayer *v37; // edi@79 AudioPlayer_3DSample *v38; // esi@79 unsigned int v39; // ebx@80 int v40; // eax@81 char *v41; // edi@82 int v42; // esi@82 double v43; // st7@91 LayingItem *v44; // eax@92 Actor *v45; // eax@93 signed int v46; // ecx@93 double v47; // st7@93 BLVDoor *v48; // eax@97 double v49; // st7@104 int v50; // ST18_4@104 int v51; // ebx@104 int v52; // eax@104 float v53; // ST0C_4@106 float v54; // ST04_4@106 AudioPlayer *v55; // edx@106 SoundDesc *v56; // edx@107 LayingItem *v57; // eax@114 int v58; // edx@115 int v59; // ecx@115 Actor *v60; // eax@118 MixerChannel *v61; // esi@126 signed int v62; // esi@133 AudioPlayer *v63; // ebx@133 MixerChannel *v64; // edi@134 int v65; // ebx@141 AudioPlayer *v66; // ecx@142 MixerChannel *v67; // edi@142 int v68; // eax@143 MixerChannel *v69; // edi@149 int v70; // ecx@152 SoundDesc *v71; // eax@153 int v72; // edi@156 MixerChannel *v73; // esi@157 unsigned int v74; // eax@157 int v75; // ebx@159 int v76; // ebx@160 LayingItem *v77; // edi@164 unsigned int v78; // edx@166 unsigned int v79; // ecx@166 int v80; // eax@167 Actor *v81; // edi@168 BLVDoor *v82; // edi@173 int v83; // eax@183 int v84; // eax@183 _SAMPLE *v85; // ST18_4@186 unsigned int v86; // [sp+14h] [bp-60h]@84 int v87; // [sp+14h] [bp-60h]@115 RenderVertexSoft a1; // [sp+24h] [bp-50h]@1 unsigned int v89; // [sp+54h] [bp-20h]@12 int v90; // [sp+58h] [bp-1Ch]@68 float v91; // [sp+5Ch] [bp-18h]@68 unsigned int v92; // [sp+60h] [bp-14h]@10 float v93; // [sp+64h] [bp-10h]@1 signed int varC; // [sp+68h] [bp-Ch]@68 AudioPlayer *v94; // [sp+6Ch] [bp-8h]@1 int v96; // [sp+70h] [bp-4h]@19 signed int uNumRepeatsb; // [sp+84h] [bp+10h]@93 float uNumRepeatsa; // [sp+84h] [bp+10h]@104 float v99; // [sp+8Ch] [bp+18h]@104 signed int v100; // [sp+90h] [bp+1Ch]@32 int v101; // [sp+90h] [bp+1Ch]@52 int v102; // [sp+90h] [bp+1Ch]@60 int v103; // [sp+90h] [bp+1Ch]@68 v9 = this; v35 = this->bPlayerReady == 0; v94 = this; a1.flt_2C = 0.0; LODWORD(v93) = 10000; if ( v35 || !uSoundVolumeMultiplier || !this->hDigDriver || !eSoundID ) return; v10 = 0; if ( (signed int)pSoundList->uNumSounds <= 0 ) { LABEL_9: v10 = 0; } else { pSoundID = (int *)&pSoundList->pSounds->uSoundID; while ( *pSoundID != eSoundID ) { ++v10; pSoundID += 30; if ( v10 >= (signed int)pSoundList->uNumSounds ) goto LABEL_9; } } v92 = v10; if ( !v10 ) return; if ( !v9->b3DSoundInitialized || (v89 = 120 * v10, !(pSoundList->pSounds[v10].uFlags & 2)) ) { v56 = (SoundDesc *)7; if ( a3 < 0 ) { if ( a3 == -1 ) { varC = 13; v96 = 13; goto LABEL_133; } varC = 14; v96 = 14; LABEL_123: if ( a3 ) { if ( a3 != -1 ) { LODWORD(v91) = 0; if ( v94->uMixerChannels > 0 ) { v61 = v94->pMixerChannels; do { if ( AIL_sample_status(v61->hSample) == 4 && v61->dword_000004 == a3 && AIL_sample_status(v61->hSample) == 4 ) { if ( v61->uSourceTrackIdx == v92 ) return; AIL_end_sample(v61->hSample); _4ABE55(v61); } ++LODWORD(v91); ++v61; } while ( SLODWORD(v91) < v94->uMixerChannels ); } } } LABEL_133: v62 = varC; v63 = v94; if ( varC <= v96 ) { v64 = &v94->pMixerChannels[varC]; while ( AIL_sample_status(v64->hSample) != 2 ) { ++v62; ++v64; if ( v62 > v96 ) goto LABEL_140; } AIL_end_sample(v64->hSample); if ( v64->uSourceTrackIdx ) _4ABE55(v64); } LABEL_140: if ( v62 != v96 + 1 ) { LABEL_150: if ( LODWORD(v93) == 10000 ) LODWORD(v93) = v63->uMasterVolume; v70 = 0; if ( !a7 ) { v56 = pSoundList->pSounds; v71 = &pSoundList->pSounds[v92]; if ( !v71->pSoundData[0] ) { if (v71->eType == SOUND_DESC_SWAP) pSoundList->_4A9A67(eSoundID, 0); } } v72 = 4 * (a7 + 30 * v92) + 44; if ( !*(int *)&pSoundList->pSounds->pSoundName[v72] ) return; v73 = &v63->pMixerChannels[v62]; AIL_init_sample(v73->hSample); AIL_set_sample_file(v73->hSample, (void *)(*(int *)&pSoundList->pSounds->pSoundName[v72] + 4 * (a7 == 0)), -1); v74 = uVolume; if ( !uVolume ) v74 = LODWORD(v93); AIL_set_sample_volume(v73->hSample, v74); v75 = a5; if ( a5 != -1 ) { if ( !a5 ) v75 = pParty->vPosition.x; if ( !a6 ) a6 = pParty->vPosition.y; if ( uNumRepeats ) AIL_set_sample_loop_count(v73->hSample, uNumRepeats - 1); v83 = sub_4AB66C(v75, a6); AIL_set_sample_pan(v73->hSample, v83); v84 = GetSoundStrengthByDistanceFromParty(v75, a6, pParty->vPosition.z); AIL_set_sample_volume(v73->hSample, v84); v76 = a3; goto LABEL_184; } v76 = a3; if ( (a3 & 7) == 1 ) { if ( uCurrentlyLoadedLevelType != LEVEL_Indoor ) goto LABEL_184; v82 = &pIndoor->pDoors[a3 >> 3]; if ( !v82->uDoorID ) return; if ( !GetSoundStrengthByDistanceFromParty(*v82->pXOffsets, *v82->pYOffsets, *v82->pZOffsets) ) { AIL_end_sample(v73->hSample); v94->AudioPlayer::_4ABE55(v73); return; } v78 = *v82->pYOffsets; v79 = *v82->pXOffsets; goto LABEL_167; } if ( (a3 & 7) == 2 ) { v77 = &pLayingItems[a3 >> 3]; if ( !GetSoundStrengthByDistanceFromParty(v77->vPosition.x, v77->vPosition.y, v77->vPosition.z) ) return; } else { if ( (a3 & 7) == 3 ) { v81 = &pActors[a3 >> 3]; if ( !GetSoundStrengthByDistanceFromParty(v81->vPosition.x, v81->vPosition.y, v81->vPosition.z) ) return; v78 = v81->vPosition.y; v79 = v81->vPosition.x; goto LABEL_167; } if ( (a3 & 7) != 5 ) { LABEL_184: if ( uNumRepeats ) AIL_set_sample_loop_count(v73->hSample, uNumRepeats - 1); v85 = v73->hSample; v73->uSourceTrackIdx = v92; v73->dword_000004 = v76; v73->uSourceTrackID = eSoundID; AIL_start_sample(v85); if ( sPlaybackRate ) AIL_set_sample_playback_rate(v73->hSample, sPlaybackRate); if ( (v76 & 7) == 4 ) AIL_sample_ms_position(v73->hSample, &sLastTrackLengthMS, 0); return; } v77 = (LayingItem *)&pLevelDecorations[a3 >> 3]; if ( !GetSoundStrengthByDistanceFromParty(v77->vPosition.x, v77->vPosition.y, v77->vPosition.z) ) return; AIL_set_sample_loop_count(v73->hSample, uNumRepeats - 1); } v78 = v77->vPosition.y; v79 = v77->vPosition.x; LABEL_167: v80 = sub_4AB66C(v79, v78); AIL_set_sample_pan(v73->hSample, v80); goto LABEL_184; } v65 = varC; v62 = -1; v91 = v93; if ( varC <= v96 ) { v66 = v94; v67 = &v94->pMixerChannels[varC]; do { v68 = AIL_sample_volume(v67->hSample); if ( v68 < SLODWORD(v91) ) { LODWORD(v91) = v68; v62 = v65; } ++v65; ++v67; } while ( v65 <= v96 ); if ( v62 != -1 ) { LABEL_149: v63 = v94; v69 = &v94->pMixerChannels[v62]; AIL_end_sample(v69->hSample); _4ABE55(v69); goto LABEL_150; } v65 = varC; } v62 = 13; if ( v65 != 13 ) return; goto LABEL_149; } if ( (a3 & 7) == 2 ) { varC = 5; v96 = 7; v57 = &pLayingItems[a3 >> 3]; } else { if ( (a3 & 7) == 3 ) { *(float *)&varC = 0.0; v60 = &pActors[a3 >> 3]; v96 = 3; v58 = v60->vPosition.y; v87 = v60->vPosition.z; v59 = v60->vPosition.x; LABEL_116: LODWORD(v93) = GetSoundStrengthByDistanceFromParty(v59, (int)v56, v87); if ( v93 == 0.0 ) return; goto LABEL_123; } if ( (a3 & 7) != 5 ) { if ( (a3 & 7) == 6 ) { varC = 8; v96 = 9; } else { varC = 10; v96 = 12; } goto LABEL_123; } varC = 4; v96 = 4; v57 = (LayingItem *)&pLevelDecorations[a3 >> 3]; } v87 = v57->vPosition.z; v58 = v57->vPosition.y; v59 = v57->vPosition.x; goto LABEL_116; } v12 = 13; if ( a3 < 0 ) { v15 = v9->uNum3DSamples; if ( a3 == -1 ) { if ( v15 < 16 ) v12 = v15 - 1; v96 = v12; goto LABEL_46; } if ( v15 >= 16 ) v15 = 14; v12 = v15; goto LABEL_45; } if ( (a3 & 7) == 2 ) { v22 = v9->uNum3DSamples; if ( v22 < 16 ) { v12 = 5 * v22 / 16; v96 = 7 * v22 / 16; } else { v96 = 7; v12 = 5; } v17 = &pLayingItems[a3 >> 3]; } else { if ( (a3 & 7) == 3 ) { v18 = v9->uNum3DSamples; v12 = 0; if ( v18 < 16 ) v96 = 3 * v18 / 16; else v96 = 3; v19 = &pActors[a3 >> 3]; v20 = v19->vPosition.y; a1.vWorldPosition.x = (double)v19->vPosition.x; v100 = v19->vPosition.z; a1.vWorldPosition.y = (double)v20; v21 = (double)v100; goto LABEL_47; } if ( (a3 & 7) != 5 ) { v13 = v9->uNum3DSamples; if ( (a3 & 7) == 6 ) { if ( v13 >= 16 ) { v96 = 9; v12 = 8; goto LABEL_46; } v12 = 8 * v13 / 16; v14 = 9 * v13; } else { if ( v13 >= 16 ) { v96 = 12; v12 = 10; LABEL_46: a1.vWorldPosition.x = (double)pParty->vPosition.x; a1.vWorldPosition.y = (double)pParty->vPosition.y; v21 = (double)pParty->sEyelevel + (double)pParty->vPosition.z; goto LABEL_47; } v12 = 10 * v13 / 16; v14 = 12 * v13; } v15 = v14 / 16; LABEL_45: v96 = v15; goto LABEL_46; } v16 = v9->uNum3DSamples; if ( v16 < 16 ) { v12 = v16 / 4; v96 = v16 / 4; } else { v12 = 4; v96 = 4; } v17 = (LayingItem *)&pLevelDecorations[a3 >> 3]; } a1.vWorldPosition.x = (double)v17->vPosition.x; a1.vWorldPosition.y = (double)v17->vPosition.y; v21 = (double)v17->vPosition.z; LABEL_47: a1.vWorldPosition.z = v21; if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) sub_4AAEA6_transform(&a1); else pGame->pIndoorCameraD3D->ViewTransform(&a1, 1u); if ( a3 ) { if ( a3 != -1 ) { v101 = 0; if ( v9->uNum3DSamples > 0 ) { v23 = v94->p3DSamples; do { if ( AIL_3D_sample_status(v23->hSample) == 4 && v23->field_4 == a3 && AIL_3D_sample_status(v23->hSample) == 4 ) { if ( v23->field_8 == v92 ) return; AIL_end_3D_sample(v23->hSample); v94->_4ABF23(v23); } ++v101; ++v23; } while ( v101 < v94->uNum3DSamples ); } } } v102 = v12; if ( v12 <= v96 ) { v24 = &v94->p3DSamples[v12]; while ( AIL_3D_sample_status(v24->hSample) != 2 ) { ++v102; ++v24; if ( v102 > v96 ) goto LABEL_67; } AIL_end_3D_sample(v24->hSample); if ( v24->field_8 ) v94->_4ABF23(v24); } LABEL_67: v25 = v96; if ( v102 == v96 + 1 ) { LODWORD(v91) = -1; v103 = 0; *(float *)&varC = a1.vWorldViewPosition.y * -0.012207031; v93 = 0.0; v26 = a1.vWorldViewPosition.x * 0.012207031; *(float *)&uVolume = v26; v27 = abs((signed __int64)v26); v28 = abs((signed __int64)v93); v29 = abs((signed __int64)*(float *)&varC); v90 = sub_4621DA(v29, v28, v27); sPlaybackRate = v12; if ( v12 > v25 ) goto LABEL_192; v30 = &v94->p3DSamples[v12]; do { AIL_3D_position(v30->hSample, &varC, &v93, (long *)&uVolume); v31 = abs((signed __int64)*(float *)&uVolume); v32 = abs((signed __int64)v93); v33 = abs((signed __int64)*(float *)&varC); v34 = sub_4621DA(v33, v32, v31); v35 = v103 == v34; if ( v103 < v34 ) { v103 = v34; v35 = 1; } if ( v35 && v90 < v103 ) { v36 = sPlaybackRate; LODWORD(v91) = sPlaybackRate; } else { v36 = LODWORD(v91); } ++sPlaybackRate; ++v30; } while ( sPlaybackRate <= v96 ); if ( v36 == -1 ) { LABEL_192: v36 = 13; if ( v12 != 13 ) return; } v37 = v94; v38 = &v94->p3DSamples[v36]; AIL_end_3D_sample(v38->hSample); v37->_4ABF23(v38); v102 = v36; } v39 = v89; if ( pSoundList->pSounds[v89 / 0x78].p3DSound || (LOWORD(v40) = pSoundList->_4A9A67(eSoundID, 0), v40) ) { v41 = (char *)v94 + 16 * v102; v42 = (int)(v41 + 20); if ( AIL_set_3D_sample_file(*((int *)v41 + 5), *(void **)((char *)&pSoundList->pSounds->p3DSound + v39)) ) { if ( uNumRepeats ) v86 = uNumRepeats - 1; else v86 = 1; AIL_set_3D_sample_loop_count(*(int *)v42, v86); if ( a5 == -1 ) { if ( (a3 & 7) == 1 ) { if ( uCurrentlyLoadedLevelType != LEVEL_Indoor ) goto LABEL_103; v48 = &pIndoor->pDoors[a3 >> 3]; if ( !v48->uDoorID ) return; a1.vWorldPosition.x = (double)*v48->pXOffsets; a1.vWorldPosition.y = (double)*v48->pYOffsets; v47 = (double)*v48->pZOffsets; LABEL_101: a1.vWorldPosition.z = v47; if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) { sub_4AAEA6_transform(&a1); goto LABEL_104; } LABEL_103: pGame->pIndoorCameraD3D->ViewTransform(&a1, 1u); LABEL_104: AIL_start_3D_sample(*(int *)v42); AIL_set_3D_sample_float_distances(*(int **)v42, 100.0, 20.0, 100.0, 20.0); AIL_set_3D_sample_volume(*(int **)v42, v94->s3DSoundVolume); v99 = a1.vWorldViewPosition.y * -0.012207031; v49 = a1.vWorldViewPosition.x * 0.012207031; uNumRepeatsa = v49; v50 = abs((signed __int64)v49); v51 = abs(0); v52 = abs((signed __int64)v99); if ( sub_4621DA(v52, v51, v50) <= 100 ) { AIL_set_3D_position((void *)*(int *)v42, LODWORD(v99), 0.0, LODWORD(uNumRepeatsa)); v53 = -uNumRepeatsa; v54 = -v99; AIL_set_3D_orientation((void *)*(int *)v42, LODWORD(v54), 0.0, LODWORD(v53), 0.0, 1.0, 0.0); v55 = v94; *((int *)v41 + 6) = a3; *((int *)v41 + 7) = v92; *(&v55->bEAXSupported + 4 * (v102 + 2)) = eSoundID; } else { AIL_end_3D_sample(*(int **)v42); v94->_4ABF23((AudioPlayer_3DSample *)(v41 + 20)); } return; } if ( (a3 & 7) == 2 ) { v44 = &pLayingItems[a3 >> 3]; } else { if ( (a3 & 7) == 3 ) { v45 = &pActors[a3 >> 3]; v46 = v45->vPosition.y; a1.vWorldPosition.x = (double)v45->vPosition.x; uNumRepeatsb = v45->vPosition.z; a1.vWorldPosition.y = (double)v46; v47 = (double)uNumRepeatsb; goto LABEL_101; } if ( (a3 & 7) != 5 ) { a1.vWorldPosition.x = (double)pParty->vPosition.x; v43 = (double)pParty->vPosition.y; LABEL_100: a1.vWorldPosition.y = v43; v47 = (double)pParty->sEyelevel + (double)pParty->vPosition.z; goto LABEL_101; } v44 = (LayingItem *)&pLevelDecorations[a3 >> 3]; } a1.vWorldPosition.x = (double)v44->vPosition.x; a1.vWorldPosition.y = (double)v44->vPosition.y; v47 = (double)v44->vPosition.z; goto LABEL_101; } a1.vWorldPosition.x = (double)a5; v43 = (double)a6; goto LABEL_100; } } } //----- (0040DEA5) -------------------------------------------------------- void __cdecl AudioPlayer::MessWithChannels() { pAudioPlayer->StopChannels(-1, -1); } //----- (004AAFCF) -------------------------------------------------------- void AudioPlayer::_4AAFCF() { AudioPlayer *v1; // edi@1 int v2; // ebx@1 unsigned __int8 v3; // zf@1 int *v4; // eax@2 unsigned __int8 v5; // sf@4 AudioPlayer_3DSample *v6; // esi@5 int v7; // ebx@6 int v8; // ebx@9 int v9; // ebx@10 int v10; // ebx@11 double v11; // st7@13 LayingItem *v12; // eax@14 Actor *v13; // eax@15 signed int v14; // edx@15 BLVDoor *v15; // eax@19 double v16; // st7@22 double v17; // st6@22 double v18; // st5@23 double v19; // st4@24 double v20; // st3@24 double v21; // st6@28 double v22; // st7@32 int v23; // ST1C_4@32 int v24; // ebx@32 int v25; // eax@32 float v26; // ST10_4@34 float v27; // ST08_4@34 MixerChannel *v28; // esi@38 unsigned __int8 v29; // of@43 MixerChannel *v30; // esi@44 int v31; // eax@45 LayingItem *v32; // eax@49 Actor *v33; // edi@50 int v34; // eax@50 unsigned int v35; // edx@51 unsigned int v36; // ecx@51 LayingItem *v37; // edi@53 int v38; // eax@53 BLVDoor *v39; // edi@56 int v40; // eax@57 int v41; // eax@60 MixerChannel *v42; // edi@65 int v43; // ebx@68 LevelDecoration *v44; // esi@68 int v45; // ST1C_4@68 int v46; // edi@68 int v47; // eax@68 DecorationDesc *v48; // edi@69 __int16 v49; // ax@69 __int16 v50; // ax@70 __int16 v51; // ax@71 __int16 v52; // ax@73 signed int v53; // eax@88 RenderVertexSoft a1; // [sp+24h] [bp-48h]@1 float v55; // [sp+54h] [bp-18h]@22 float v56; // [sp+58h] [bp-14h]@22 int uNumRepeats; // [sp+5Ch] [bp-10h]@15 float v58; // [sp+60h] [bp-Ch]@23 int v59; // [sp+64h] [bp-8h]@4 AudioPlayer *thisa; // [sp+68h] [bp-4h]@1 v1 = this; v2 = 0; thisa = this; v3 = this->bPlayerReady == 0; a1.flt_2C = 0.0; if ( !v3 ) { v4 = &this->field_2D0_time_left; *v4 -= pEventTimer->uTimeElapsed; if ( this->field_2D0_time_left <= 0 ) { v3 = this->b3DSoundInitialized == 0; *v4 = 32; if ( !v3 ) { v3 = this->uNum3DSamples == 0; v5 = this->uNum3DSamples < 0; v59 = 0; if ( !(v5 | v3) ) { v6 = this->p3DSamples; while ( 1 ) { v7 = v6->field_4 & 7; if ( AIL_3D_sample_status(v6->hSample) == 2 ) { AIL_end_3D_sample(v6->hSample); v1->_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[v6->field_4 >> 3]; 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 >= v1->uNum3DSamples ) { v2 = 0; goto LABEL_37; } } v9 = v8 - 1; if ( v9 ) { v10 = v9 - 1; if ( !v10 ) { v13 = &pActors[v6->field_4 >> 3]; 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 = (LayingItem *)&pLevelDecorations[v6->field_4 >> 3]; } else { v12 = &pLayingItems[v6->field_4 >> 3]; } 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 ) { 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; } } 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 ( sub_4621DA(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); v1->_4ABF23(v6); } goto LABEL_35; } } LABEL_37: if ( v1->uMixerChannels > v2 ) { v28 = v1->pMixerChannels; do { if ( AIL_sample_status(v28->hSample) == 2 ) { AIL_end_sample(v28->hSample); v1->_4ABE55(v28); } ++v2; ++v28; } while ( v2 < v1->uMixerChannels ); v2 = 0; } v29 = __OFSUB__(v1->uMixerChannels, v2); v3 = v1->uMixerChannels == v2; v5 = v1->uMixerChannels - v2 < 0; v59 = v2; if ( !((unsigned __int8)(v5 ^ v29) | v3) ) { v30 = v1->pMixerChannels; while ( 1 ) { v31 = v30->dword_000004; if ( (v30->dword_000004 & 7) == 1 ) { if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) { v39 = &pIndoor->pDoors[v31 >> 3]; if ( !v39->uDoorID ) { LABEL_61: v1 = thisa; goto LABEL_62; } v40 = GetSoundStrengthByDistanceFromParty(*v39->pXOffsets, *v39->pYOffsets, *v39->pZOffsets); if ( !v40 ) { LABEL_58: AIL_end_sample(v30->hSample); thisa->_4ABE55(v30); goto LABEL_61; } AIL_set_sample_volume(v30->hSample, v40); v35 = *v39->pYOffsets; v36 = *v39->pXOffsets; LABEL_60: v41 = sub_4AB66C(v36, v35); AIL_set_sample_pan(v30->hSample, v41); goto LABEL_61; } } else { if ( (v30->dword_000004 & 7) == 2 ) { v32 = &pLayingItems[v31 >> 3]; goto LABEL_53; } if ( (v30->dword_000004 & 7) == 3 ) { v33 = &pActors[v31 >> 3]; v34 = GetSoundStrengthByDistanceFromParty(v33->vPosition.x, v33->vPosition.y, v33->vPosition.z); if ( !v34 ) goto LABEL_58; AIL_set_sample_volume(v30->hSample, v34); v35 = v33->vPosition.y; v36 = v33->vPosition.x; goto LABEL_60; } if ( (v30->dword_000004 & 7) == 5 ) { v32 = (LayingItem *)&pLevelDecorations[v31 >> 3]; LABEL_53: v37 = v32; v38 = GetSoundStrengthByDistanceFromParty(v32->vPosition.x, v32->vPosition.y, v32->vPosition.z); if ( !v38 ) goto LABEL_58; AIL_set_sample_volume(v30->hSample, v38); v35 = v37->vPosition.y; v36 = v37->vPosition.x; goto LABEL_60; } } LABEL_62: ++v59; ++v30; if ( v59 >= v1->uMixerChannels ) { v2 = 0; break; } } } if ( pCurrentScreen != v2 ) { v42 = &v1->pMixerChannels[4]; if ( AIL_sample_status(v42->hSample) == 4 ) AIL_end_sample(v42->hSample); return; } v59 = v2; if ( _6807E0_num_decorations_with_sounds_6807B8 <= v2 ) return; while ( 1 ) { LODWORD(v56) = 1; v43 = 4 * v59 + 6817720; v44 = &pLevelDecorations[_6807B8_level_decorations_ids[v59]]; v45 = abs(v44->vPosition.z - pParty->vPosition.z); v46 = abs(v44->vPosition.y - pParty->vPosition.y); v47 = abs(v44->vPosition.x - pParty->vPosition.x); if ( sub_4621DA(v47, v46, v45) <= 8192 ) break; LABEL_89: ++v59; if ( v59 >= _6807E0_num_decorations_with_sounds_6807B8 ) return; } v48 = &pDecorationList->pDecorations[v44->uDecorationDescID]; v49 = v48->uFlags; uNumRepeats = (~(unsigned __int8)v48->uFlags & 0x40) >> 6; if ( HIBYTE(v49) & 3 ) { v50 = v44->field_1A; v55 = 0.0; uNumRepeats = 2; if ( v50 ) { v51 = v50 - 32; v44->field_1A = v51; if ( v51 < 0 ) v44->field_1A = 0; } } v52 = v48->uFlags; if ( !(HIBYTE(v52) & 1) ) { if ( !(HIBYTE(v52) & 2) ) goto LABEL_84; if ( v55 != 0.0 ) goto LABEL_85; } v56 = 0.0; if ( pParty->uCurrentHour >= 5 && pParty->uCurrentHour < 6 || pParty->uCurrentHour >= 0x14 && pParty->uCurrentHour < 0x15 ) { if ( !v44->field_1A && rand() % 100 < 100 ) LODWORD(v56) = 1; LODWORD(v55) = 1; } LABEL_84: if ( v55 == 0.0 ) { LABEL_87: if ( v56 != 0.0 ) { v53 = 8 * *(int *)v43; LOBYTE(v53) = v53 | 5; thisa->PlaySound((SoundID)v48->uSoundID, v53, uNumRepeats, -1, 0, 0, 0, 0); } goto LABEL_89; } LABEL_85: if ( !v44->field_1A ) v44->field_1A = (rand() % 15 + 1) << 7; goto LABEL_87; } } } //----- (004AB66C) -------------------------------------------------------- int __fastcall sub_4AB66C(int a1, int a2) { signed int v2; // eax@1 v2 = stru_5C6E00->uDoublePiMask & (stru_5C6E00->Atan2(a1 - pParty->vPosition.x, a2 - pParty->vPosition.y) - stru_5C6E00->uIntegerHalfPi - pParty->sRotationY); if ( v2 > (signed int)stru_5C6E00->uIntegerPi ) v2 = 2 * stru_5C6E00->uIntegerPi - v2; return (v2 >> 3) - (v2 >> 10); } // 4AB66C: using guessed type int __fastcall sub_4AB66C(int, int); //----- (004AB6B1) -------------------------------------------------------- int __fastcall GetSoundStrengthByDistanceFromParty(int a1, int a2, int a3) { int v3; // esi@1 int v4; // edi@1 int v5; // ST08_4@1 int v6; // esi@1 int v7; // eax@1 int result; // eax@2 int v9; // [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 = sub_4621DA(v7, v6, v5); if ( v9 <= 8192 ) result = 114 - (unsigned __int64)(signed __int64)((double)v9 * 0.0001220703125 * 100.0); else result = 0; return result; } //----- (004AB71F) -------------------------------------------------------- void AudioPlayer::StopChannels(int uStartChannel, int uEndChannel) { //AudioPlayer *v3; // esi@1 int v4; // ecx@1 char *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 ) { v9 = 0; if ( uNum3DSamples > 0 ) { v5 = (char *)&p3DSamples[0].field_8; do { if ( (uStartChannel == -1 || v4 < uStartChannel || v4 > uEndChannel) && *(int *)v5 && pSoundList->pSounds[*(int *)v5].eType != SOUND_DESC_SYSTEM) { AIL_end_3D_sample(*((int **)v5 - 2)); _4ABF23((AudioPlayer_3DSample *)(v5 - 8)); *((int *)v5 - 1) = 0; v4 = v9; } ++v4; v5 += 16; v9 = v4; } while ( v4 < uNum3DSamples ); } } v6 = 0; if ( hDigDriver && uMixerChannels > 0 ) { pChannel = pMixerChannels; do { if ( (uStartChannel == -1 || v6 < uStartChannel || v6 > uEndChannel) && pSoundList->pSounds[pChannel->uSourceTrackIdx].eType != SOUND_DESC_SYSTEM) { AIL_end_sample(pChannel->hSample); _4ABE55(pChannel); pChannel->dword_000004 = 0; } ++v6; ++pChannel; } while (v6 < uMixerChannels); } if (hSequence) AIL_end_sequence(hSequence); //v8 = hStream; if (hStream) AIL_pause_stream(hStream, 1); } } //----- (004AB818) -------------------------------------------------------- void AudioPlayer::LoadAudioSnd() { DWORD NumberOfBytesRead; // [sp+Ch] [bp-4h]@3 hAudioSnd = CreateFileA("Sounds\\Audio.snd", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0x8000080u, 0); if (hAudioSnd == INVALID_HANDLE_VALUE) { Log::Warning(L"Can't open file: %s", L"Sounds\\Audio.snd"); return; } ReadFile(hAudioSnd, &uNumSoundHeaders, 4u, &NumberOfBytesRead, 0); pSoundHeaders = nullptr; pSoundHeaders = (SoundHeader *)pAllocator->AllocNamedChunk(0, 52 * uNumSoundHeaders + 2, 0); ReadFile(hAudioSnd, pSoundHeaders, 52 * uNumSoundHeaders, &NumberOfBytesRead, 0); } //----- (004AB8CE) -------------------------------------------------------- void AudioPlayer::Initialize(HWND hWnd) { //AudioPlayer *v2; // esi@1 int v3; // ebx@1 //_DIG_DRIVER *v4; // eax@1 char v5; // dl@5 _PROVIDER *v6; // eax@9 HWND v7; // ST00_4@9 MixerChannel *pChannel; // edi@14 _SAMPLE *v9; // eax@15 //_REDBOOK *v10; // eax@19 //int v11; // ecx@21 int v12; // [sp+Ch] [bp-Ch]@9 char *Str1; // [sp+10h] [bp-8h]@6 int v14; // [sp+14h] [bp-4h]@5 //v2 = this; v3 = 0; this->hWindow = hWnd; this->hAILRedbook = 0; this->hDigDriver = 0; this->dword_0002AC = 0; this->hSequence = 0; this->uMasterVolume = 127; this->dword_0002C8 = 64; this->dword_0002CC = 2; MSS32_DLL_Initialize(); BINKW32_DLL_Initialize(); SMACKW32_DLL_Initialize(); AIL_startup(); if (bCanLoadFromCD) hAILRedbook = AIL_redbook_open_drive(cMM7GameCDDriveLetter/*cGameCDDriveLetter*/); //else // hAILRedbook = AIL_redbook_open(0); //v4 = Audio_GetFirstHardwareDigitalDriver(); hDigDriver = Audio_GetFirstHardwareDigitalDriver(); if ( hDigDriver ) SmackSoundUseMSS(hDigDriver); if ( ReadWindowsRegistryInt("Disable3DSound", 0) != 1 && pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ) { v14 = 0; bEAXSupported = 0; b3DSoundInitialized = 0; ReadWindowsRegistryString("3DSoundProvider", p3DSoundProvider, 128u, "NONE"); CheckA3DSupport(v5); while ( AIL_enumerate_3D_providers(&v14, (HPROVIDER *)&hWnd, &Str1) ) { if ( !strcmp(Str1, p3DSoundProvider) ) { if ( AIL_open_3D_provider((HPROVIDER)hWnd) ) { bEAXSupported = 0; b3DSoundInitialized = 0; h3DSoundProvider = 0; } else { v6 = (_PROVIDER *)hWnd; v7 = hWnd; b3DSoundInitialized = 1; h3DSoundProvider = v6; uNum3DSamples = 4; AIL_3D_provider_attribute((HPROVIDER)v7, "EAX environment selection", &v12); if ( v12 != -1 ) bEAXSupported = 1; } pAudioPlayer->_4AC0A2(); break; } } } if ( uMixerChannels > 0 ) { pChannel = pMixerChannels; do { v9 = AIL_allocate_sample_handle(hDigDriver); pChannel->hSample = v9; if ( !v9 ) break; ++v3; ++pChannel; } while ( v3 < uMixerChannels ); } uMixerChannels = v3; if ( bPlayerReady ) StopChannels(-1, -1); //v10 = hAILRedbook; bPlayerReady = true; if ( hAILRedbook ) { AIL_redbook_stop(hAILRedbook); uNumRedbookTracks = AIL_redbook_tracks(hAILRedbook); } pAudioPlayer->sRedbookVolume = AIL_redbook_volume(hAILRedbook); pAudioPlayer->SetMasterVolume(pSoundVolumeLevels[uSoundVolumeMultiplier] * 128.0); if ( bPlayerReady && hAILRedbook ) AIL_redbook_set_volume(hAILRedbook, (unsigned __int64)(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0) >> 32); LoadAudioSnd(); } //----- (004ABAF7) -------------------------------------------------------- _DIG_DRIVER *Audio_GetFirstHardwareDigitalDriver(void) { int v0; // ecx@1 unsigned int v1; // ebp@2 size_t v2; // eax@4 signed int v3; // kr14_4@9 char *v5; // [sp+10h] [bp-Ch]@2 unsigned int v6; // [sp+14h] [bp-8h]@1 _DIG_DRIVER *hDrv; // [sp+18h] [bp-4h]@3 static int dword_4F00DC = 22050; static int dword_4F00E0 = 16; static int dword_4F00E4 = 2; AIL_set_preference(15, 0); AIL_set_preference(33, 1); v0 = dword_4F00DC; pAudioPlayer->pDeviceNames[0][0] = 0; pAudioPlayer->uNumDevices = 0; v6 = 0; if ( dword_4F00DC < 11025 ) return 0; v1 = 0; v5 = (char *)pAudioPlayer->array_000BF0; while ( 1 ) { while ( 1 ) { pcmWaveFormat.wf.wFormatTag = 1; pcmWaveFormat.wf.nChannels = dword_4F00E4; pcmWaveFormat.wf.nSamplesPerSec = v0; pcmWaveFormat.wf.nBlockAlign = dword_4F00E4 * dword_4F00E0 / 8; pcmWaveFormat.wBitsPerSample = dword_4F00E0; pcmWaveFormat.wf.nAvgBytesPerSec = v0 * dword_4F00E4 * dword_4F00E0 / 8; if ( !AIL_waveOutOpen(&hDrv, 0, -1, &pcmWaveFormat.wf) ) break; if ( !AIL_get_preference(15) ) goto LABEL_8; v3 = dword_4F00DC; v0 = dword_4F00DC / 2; dword_4F00DC /= 2; if ( v3 / 2 < 11025 ) { if ( dword_4F00E0 == 8 ) { v0 = 22050; dword_4F00E0 = 8; dword_4F00DC = 22050; } goto LABEL_12; } } strcpy(pAudioPlayer->pDeviceNames[v1 / 8], "Device: "); v2 = strlen(pAudioPlayer->pDeviceNames[v1 / 8]); AIL_digital_configuration(hDrv, (int *)v5, (int *)(v5 + 64), (char *)pAudioPlayer->pDeviceNames + v2 + v1 * 16); ++v6; v1 += 8; v5 += 4; pAudioPlayer->uNumDevices = v6; if ( AIL_get_preference(15) ) return hDrv; if ( !strstr(pAudioPlayer->pDeviceNames[v1 / 8 - 1], "Emulated") ) return hDrv; AIL_waveOutClose(hDrv); AIL_set_preference(15, 1); LABEL_8: AIL_set_preference(15, 1); v0 = dword_4F00DC; LABEL_12: if ( v0 < 11025 ) return 0; } } //----- (004ABC9B) -------------------------------------------------------- LSTATUS AudioPlayer::CheckA3DSupport(char a2) { LSTATUS result; // eax@1 DWORD cbData; // [sp+8h] [bp-Ch]@1 int Data; // [sp+Ch] [bp-8h]@1 HKEY hKey; // [sp+10h] [bp-4h]@1 char v6; // [sp+1Ch] [bp+8h]@0 hKey = 0; cbData = 4; Data = 0; result = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Aureal\\A3D", 0, 0x2001Fu, &hKey); if ( !result ) { if ( v6 ) RegQueryValueExA(hKey, "SplashAudio", 0, 0, (LPBYTE)&Aureal3D_SplashAudio, &cbData); else Data = Aureal3D_SplashAudio; RegSetValueExA(hKey, "SplashAudio", 0, 4u, (const BYTE *)&Data, 4u); Data = 0; if ( v6 ) RegQueryValueExA(hKey, "SplashScreen", 0, 0, (LPBYTE)&Aureal3D_SplashScreen, &cbData); else Data = Aureal3D_SplashScreen; RegSetValueExA(hKey, "SplashScreen", 0, 4u, (const BYTE *)&Data, 4u); result = RegCloseKey(hKey); } return result; } // 4ABC9B: inconsistent function type and number of purged bytes //----- (004ABD5B) -------------------------------------------------------- void AudioPlayer::Release() { AudioPlayer *v1; // esi@1 int v2; // edi@1 MixerChannel *v3; // ebx@3 char v4; // dl@5 int v5; // ebx@6 AudioPlayer_3DSample *v6; // edi@7 int v7; // edx@14 int v8; // ecx@14 void *v9; // ecx@15 v1 = this; v2 = 0; if ( this->bPlayerReady ) { CloseHandle(pVideoPlayer->hMagicVid); CloseHandle(pVideoPlayer->hMightVid); v1->StopChannels(-1, -1); if ( v1->uMixerChannels > 0 ) { v3 = v1->pMixerChannels; do { AIL_release_sample_handle(v3->hSample); ++v2; ++v3; } while ( v2 < v1->uMixerChannels ); } if ( ReadWindowsRegistryInt("Disable3DSound", 0) != 1 ) { v5 = 0; v1->CheckA3DSupport(v4); if ( v1->uNum3DSamples > 0 ) { v6 = v1->p3DSamples; do { if ( v6->hSample ) { AIL_release_3D_sample_handle(v6->hSample); v6->hSample = 0; } ++v5; ++v6; } while ( v5 < v1->uNum3DSamples ); } if ( v1->h3DSoundProvider ) { AIL_close_3D_provider(v1->h3DSoundProvider); v1->h3DSoundProvider = 0; } } if ( v1->hAILRedbook ) { AIL_redbook_stop(v1->hAILRedbook); AIL_redbook_set_volume((HREDBOOK)v8, v7); AIL_redbook_close(v1->hAILRedbook); } AIL_shutdown(); pSoundList->Release(); v9 = *(void **)&v1->field_C78[0]; if ( v9 ) ReleaseSoundData(v9); CloseHandle(v1->hAudioSnd); } } //----- (004ABE55) -------------------------------------------------------- void AudioPlayer::_4ABE55(MixerChannel *pChannel) { int v2; // ebx@1 //AudioPlayer *v3; // esi@1 SoundDesc *v4; // eax@2 unsigned __int8 v5; // zf@5 unsigned __int8 v6; // sf@5 char *v7; // edi@6 int v8; // eax@8 int v9; // ST04_4@8 int v10; // ecx@12 int v11; // edi@13 int v12; // eax@13 unsigned __int8 v13; // of@13 int v14[16]; // [sp+Ch] [bp-48h]@8 int v15; // [sp+4Ch] [bp-8h]@5 int v16; // [sp+50h] [bp-4h]@5 v2 = 0; //v3 = this; if ( pSoundList->pSounds ) { v4 = &pSoundList->pSounds[pChannel->uSourceTrackIdx]; if ( v4->eType == SOUND_DESC_SWAP) { if ( v4->pSoundData[0] && !(v4->uFlags & 1) ) { v5 = this->uMixerChannels == 0; v6 = this->uMixerChannels < 0; v15 = 0; v16 = 0; if ( v6 | v5 ) goto LABEL_16; v7 = (char *)this->pMixerChannels; do { if ( pChannel->uSourceTrackID == *((int *)v7 + 3) ) { v8 = v16; v9 = *(int *)v7; ++v16; v14[v8] = v2; if ( AIL_sample_status((HSAMPLE)v9) == 4 ) ++v15; } ++v2; v7 += 16; } while ( v2 < uMixerChannels ); if ( !v15 ) { LABEL_16: pSoundList->_4A9DCD(pChannel->uSourceTrackIdx, 1); v10 = 0; if ( v16 > 0 ) { do { v11 = v14[v10]; v12 = 16 * (v14[v10++] + 47); pMixerChannels[v11].uSourceTrackID = 0; v13 = __OFSUB__(v10, v16); v6 = v10 - v16 < 0; *(unsigned int *)((char *)&bEAXSupported + v12) = 0; } while ( v6 ^ v13 ); } } } } } } // 4D82F8: using guessed type int __stdcall AIL_sample_status(int); // 4ABE55: using guessed type int var_48[16]; //----- (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) { int v2; // ebx@1 //AudioPlayer *v3; // esi@1 SoundDesc *v4; // eax@2 unsigned __int8 v5; // zf@5 unsigned __int8 v6; // sf@5 char *v7; // edi@6 int v8; // eax@8 int v9; // ST04_4@8 int v10; // ecx@12 int v11; // eax@13 unsigned __int8 v12; // of@13 int v13[16]; // [sp+Ch] [bp-48h]@8 int v14; // [sp+4Ch] [bp-8h]@5 int v15; // [sp+50h] [bp-4h]@5 v2 = 0; //v3 = this; if ( pSoundList->pSounds ) { v4 = &pSoundList->pSounds[a2->field_8]; if ( v4->eType == SOUND_DESC_SWAP) { if ( v4->p3DSound && !(v4->uFlags & 1) ) { v5 = this->uNum3DSamples == 0; v6 = this->uNum3DSamples < 0; v14 = 0; v15 = 0; if ( v6 | v5 ) goto LABEL_16; v7 = (char *)this->p3DSamples; do { if ( a2->field_C == *((int *)v7 + 3) ) { v8 = v15; v9 = *(int *)v7; ++v15; v13[v8] = v2; if ( AIL_3D_sample_status((void *)v9) == 4 ) ++v14; } ++v2; v7 += 16; } while ( v2 < uNum3DSamples ); if ( !v14 ) { LABEL_16: pSoundList->_4A9DCD(a2->field_8, 1); v10 = 0; if ( v15 > 0 ) { do { v11 = v13[v10++]; *(&bEAXSupported + 4 * (v11 + 2)) = 0; v12 = __OFSUB__(v10, v15); v6 = v10 - v15 < 0; p3DSamples[v11].field_8 = 0; } while ( v6 ^ v12 ); } } } } } } // 4D82F4: using guessed type int __stdcall AIL_3D_sample_status(int); // 4ABF23: using guessed type int var_48[16]; //----- (004ABFDB) -------------------------------------------------------- void __cdecl PlayLevelMusic() { unsigned int v0; // eax@1 v0 = pMapStats->GetMapInfo(pCurrentMapName); if ( v0 ) pAudioPlayer->PlayMusicTrack((MusicID)pMapStats->pInfos[v0].uRedbookTrackID); } //----- (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; v4 = 1.0; AIL_set_3D_provider_preference(v3, "EAX damping", (int *)&v4); } } // 4D82DC: using guessed type int __stdcall AIL_set_3D_provider_preference(int, int, int); //----- (004AC041) -------------------------------------------------------- void AudioPlayer::SetMapEAX() { AudioPlayer *v1; // esi@1 unsigned int v2; // eax@1 int v3; // [sp+4h] [bp-4h]@3 v1 = this; v2 = pMapStats->GetMapInfo(pCurrentMapName); if ( v1->b3DSoundInitialized && v1->bEAXSupported ) { v3 = pMapStats->pInfos[v2].uEAXEnv; if ( (unsigned int)v3 >= 0x1A ) { SetEAXPreferences(); v1->field_214 = -1; } else { AIL_set_3D_provider_preference(v1->h3DSoundProvider, "EAX environment selection", &v3); v1->field_214 = v3; } } } // 4D82DC: using guessed type int __stdcall AIL_set_3D_provider_preference(int, int, int); //----- (004AC0A2) -------------------------------------------------------- int AudioPlayer::_4AC0A2() { AudioPlayer *v1; // esi@1 unsigned int v2; // eax@1 char v3; // zf@1 int v4; // ebx@1 int *v5; // edi@2 int v6; // eax@4 AudioPlayer_3DSample *v8; // ebx@7 void *v9; // eax@8 int v10; // ebx@14 unsigned int v11; // eax@14 int v12; // [sp+1Ch] [bp-8h]@1 int v13; // [sp+20h] [bp-4h]@6 v1 = this; v2 = pMapStats->GetMapInfo(pCurrentMapName); v3 = v1->b3DSoundInitialized == 0; v4 = v2; v12 = v2; if ( !v3 ) { v5 = &v1->uNum3DSamples; AIL_3D_provider_attribute(v1->h3DSoundProvider, "Maximum supported samples", &v1->uNum3DSamples); if ( v1->uNum3DSamples > 32 ) *v5 = 32; v6 = *v5; if ( !*v5 ) { v1->b3DSoundInitialized = 0; return -1; } v13 = 0; if ( v6 > 0 ) { v8 = v1->p3DSamples; while ( 1 ) { v9 = (void *)AIL_allocate_3D_sample_handle(v1->h3DSoundProvider); v8->hSample = v9; if ( !v9 ) break; AIL_set_3D_sample_float_distances(v9, 4096.0, 256.0, 4096.0, 256.0); AIL_set_3D_sample_volume(v8->hSample, v1->s3DSoundVolume); ++v13; ++v8; if ( v13 >= *v5 ) goto LABEL_12; } *v5 = v13; LABEL_12: v4 = v12; } if ( v1->bEAXSupported ) { v10 = v4; v11 = pMapStats->pInfos[v10].uEAXEnv; v12 = pMapStats->pInfos[v10].uEAXEnv; if ( v11 >= 0x1A ) { pAudioPlayer->SetEAXPreferences(); v1->field_214 = -1; } else { AIL_set_3D_provider_preference(v1->h3DSoundProvider, "EAX environment selection", &v12); v1->field_214 = v12; } } } return 1; } //----- (004A96BE) -------------------------------------------------------- void ReleaseSoundData(void *_this) { int v1; // esi@1 char *v2; // eax@1 v1 = 0; v2 = (char *)&pSounds[0].pSoundData; while ( *(void **)v2 != _this ) { v2 += 128; ++v1; if ( (signed int)v2 >= (signed int)&pAudioPlayer->p3DSamples[6].field_8 ) return; } pAllocator->FreeChunk(_this); memset(&pSounds[v1], 0, 0x80u); } //----- (004A96FF) -------------------------------------------------------- SoundHeader *__fastcall 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 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 *)_strcmpi(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 ) { v7 = v4; if ( (signed int)v4 < (signed int)v10 ) { v9 = v4; do { result = (SoundHeader *)_strcmpi(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; LABEL_10: v3 = v10; } if ( v6 > 4 ) { v10 = v6 / 2 + v4; goto LABEL_10; } v7 = v4; if ( (signed int)v4 >= (signed int)v10 ) goto LABEL_17; v8 = v4; while ( 1 ) { result = (SoundHeader *)_strcmpi(pName, pAudioPlayer->pSoundHeaders[v8].pSoundName); if ( !result ) break; ++v7; ++v8; if ( v7 >= (signed int)v10 ) goto LABEL_17; } LABEL_24: uFindSound_BinSearch_ResultID = v7; return result; } // 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 ) goto LABEL_22; 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 ) { v6->uCompressedSize = v9; if ( v9 ) { ReadFile(pAudioPlayer->hAudioSnd, (char *)v3 + 4, v9, &NumberOfBytesRead, 0); } else { MessageBoxW(nullptr, L"Can't load sound file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Sound.cpp:448", 0); } } 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); free((void *)uID); } if ( v3 ) { v11 = v19; v12 = 0; *(int *)v3 = v19; uLastLoadedSoundID = 0; if ( pSounds[0].pSoundData ) { v13 = (char *)&pSounds[0].pSoundData; do { v13 += 128; ++v12; } while ( *(int *)v13 ); uLastLoadedSoundID = v12; } v16 = pSounds[v12].field_4; strcpy((char *)v16, pSoundName_); v14 = uLastLoadedSoundID++ << 7; pSoundList->uTotalLoadedSoundSize += v11; pSounds[uLastLoadedSoundID].pSoundData = v3; result = v3; } else { LABEL_22: result = 0; } return result; }