Mercurial > mm7
annotate AudioPlayer.cpp @ 889:279a315ff122
* first cast_spell clean
* feather fall fix
author | zipi |
---|---|
date | Tue, 02 Apr 2013 23:02:04 +0100 |
parents | ceef50611567 |
children | c45d51b3f4f4 |
rev | line source |
---|---|
0 | 1 #include <string> |
378 | 2 #include <assert.h> |
0 | 3 |
4 #include "AudioPlayer.h" | |
5 #include "Allocator.h" | |
6 #include "FrameTableInc.h" | |
7 #include "Indoor.h" | |
515
cb0ad52d6a26
LayingItem -> SpriteObject (long-waited rename, old name was inaccurate and confused people)
Nomad
parents:
412
diff
changeset
|
8 #include "SpriteObject.h" |
0 | 9 #include "Party.h" |
10 #include "Actor.h" | |
11 #include "Game.h" | |
12 #include "DecorationList.h" | |
13 #include "Time.h" | |
14 #include "OSInfo.h" | |
15 #include "Math.h" | |
16 #include "MapInfo.h" | |
378 | 17 #include "Actor.h" |
18 #include "GUIWindow.h" | |
0 | 19 #include "Log.h" |
20 | |
21 #include "Bink_Smacker.h" | |
22 | |
23 #include "mm7_data.h" | |
848 | 24 #include "MM7.h" |
0 | 25 |
26 | |
27 PCMWAVEFORMAT pcmWaveFormat; | |
28 | |
29 int Aureal3D_SplashScreen; | |
30 int Aureal3D_SplashAudio; | |
31 int uFindSound_BinSearch_ResultID; // weak | |
32 int uLastLoadedSoundID; // weak | |
33 int sLastTrackLengthMS; | |
34 Sound pSounds[3000]; | |
35 AudioPlayer *pAudioPlayer; | |
36 SoundList *pSoundList; | |
37 | |
38 | |
39 stru339_spell_sound stru_A750F8[4]; | |
40 stru339_spell_sound stru_AA1058[4]; | |
41 | |
42 | |
43 | |
44 unsigned __int8 uSoundVolumeMultiplier = 4; | |
45 unsigned __int8 uVoicesVolumeMultiplier = 4; | |
46 unsigned __int8 uMusicVolimeMultiplier = 4; | |
47 int bWalkSound; // idb | |
48 | |
49 float pSoundVolumeLevels[10] = | |
50 { | |
328 | 51 0.0000000f, 0.1099999f, 0.2199999f, 0.3300000f, 0.4399999f, |
52 0.5500000f, 0.6600000f, 0.7699999f, 0.8799999f, 0.9900000f | |
53 }; | |
0 | 54 |
55 | |
56 | |
57 | |
58 void ReleaseSoundData(void *_this); | |
59 | |
60 | |
61 | |
62 | |
63 //----- (004A9953) -------------------------------------------------------- | |
64 void SoundList::Initialize() | |
65 { | |
66 SoundList *pSoundList; // esi@1 | |
67 signed int v2; // edi@2 | |
68 SoundDesc *pSoundDesc; // eax@5 | |
69 void *pSoundData; // ebx@7 | |
70 unsigned int uSoundSize; // eax@7 | |
71 char *pSoundBytes; // ebx@7 | |
72 AILFILETYPE pType; // eax@7 | |
73 int v8; // eax@8 | |
74 char pSoundName[120]; // [sp+4h] [bp-A4h]@4 | |
75 AILSOUNDINFO pInfo; // [sp+7Ch] [bp-2Ch]@10 | |
76 int v12; // [sp+A0h] [bp-8h]@12 | |
77 int a2; // [sp+A4h] [bp-4h]@1 | |
78 | |
79 pSoundList = this; | |
80 a2 = 1; | |
764 | 81 if ( sNumSounds > 1 ) |
0 | 82 { |
83 v2 = 1; | |
84 //while ( 1 ) | |
85 do | |
86 { | |
87 sprintf(pSoundName, "%s", pSounds[v2].pSoundName); | |
153 | 88 // pSoundList->pSounds[v2].pSoundData[0] = ::LoadSound(pSoundName, (SoundData *)0xFFFFFFFF, pSounds[v2].uSoundID); //Ritor1: it's error - result: no sound |
0 | 89 pSoundDesc = &pSoundList->pSounds[v2]; |
90 if ( pSoundList->pSounds[v2].eType != SOUND_DESC_SYSTEM || (sprintf(pSoundName, "%s", pSounds[v2].pSoundName), | |
91 pSoundList->pSounds[v2].pSoundData[0] = ::LoadSound(pSoundName, (SoundData *)0xFFFFFFFF, pSounds[v2].uSoundID), | |
92 !pAudioPlayer->b3DSoundInitialized) | |
592 | 93 || (pSoundDesc = &pSoundList->pSounds[v2], !(pSoundDesc->uFlags & SOUND_DESC_SWAP)) |
0 | 94 || !pSoundDesc->pSoundData[0] ) // нужно перевернуть |
95 goto LABEL_17; | |
96 pSoundData = pSoundDesc->pSoundData[0]; | |
97 uSoundSize = *(int *)pSoundData; | |
98 pSoundBytes = (char *)pSoundData + 4; | |
99 pType = AIL_file_type(pSoundBytes, uSoundSize); | |
100 if ( !pType ) | |
101 //goto LABEL_15; | |
102 { | |
764 | 103 pSoundList->pSounds[v2].bDecompressed = false; |
0 | 104 goto LABEL_16; |
105 } | |
106 v8 = pType - 1; | |
107 if ( v8 ) | |
108 { | |
109 /*break; | |
110 pSoundList->pSounds[v2].p3DSound = pSoundList->pSounds[v2].pSoundData[0]; | |
111 LABEL_16: | |
112 pSoundList->_4A9DCD(a2, 1); | |
113 LABEL_17: | |
114 ++a2; | |
115 ++v2; | |
116 if ( a2 >= (signed int)pSoundList->uNumSounds ) | |
117 return; | |
118 }*/ | |
119 if ( v8 == 1 ) | |
120 { | |
121 if ( AIL_WAV_info(pSoundBytes, &pInfo) && pInfo.uChannels != 2 ) | |
122 { | |
123 if ( !AIL_decompress_ADPCM(&pInfo, &pSoundList->pSounds[v2].p3DSound, &v12) ) | |
124 { | |
125 pSoundList->pSounds[v2].p3DSound = 0; | |
764 | 126 pSoundList->pSounds[v2].bDecompressed = true; |
0 | 127 } |
128 } | |
129 goto LABEL_16; | |
130 } | |
131 //LABEL_15: | |
764 | 132 pSoundList->pSounds[v2].bDecompressed = false; |
0 | 133 goto LABEL_16; |
134 } | |
135 pSoundList->pSounds[v2].p3DSound = pSoundList->pSounds[v2].pSoundData[0]; | |
136 LABEL_16: | |
764 | 137 pSoundList->UnloadSound(a2, 1); |
0 | 138 LABEL_17: |
139 ++a2; | |
140 ++v2; | |
141 } | |
764 | 142 while ( a2 < pSoundList->sNumSounds ); |
0 | 143 } |
144 } | |
145 | |
146 //----- (004A9A67) -------------------------------------------------------- | |
147 __int16 SoundList::LoadSound(int a1, unsigned int a3) | |
148 { | |
149 AILSOUNDINFO v24; // [sp+84h] [bp-28h]@23 | |
150 | |
764 | 151 if (bNoSound || !sNumSounds) |
0 | 152 return 0; |
153 | |
154 uint uSoundIdx = 0; | |
155 SoundDesc *pSound = nullptr; | |
764 | 156 for (uint i = 1; i < sNumSounds; ++i) |
0 | 157 if (pSounds[i].uSoundID == a1) |
158 { | |
159 uSoundIdx = i; | |
160 pSound = &pSounds[i]; | |
161 break; | |
162 } | |
163 if (!pSound) | |
164 return 0; | |
165 | |
592 | 166 if (pSound->uFlags & SOUND_DESC_SWAP && pSound->p3DSound || |
167 ~pSound->uFlags & SOUND_DESC_SWAP && pSound->pSoundData[0]) | |
0 | 168 return uSoundIdx; |
169 | |
170 if (!pSound->pSoundData[0]) | |
171 pSound->pSoundData[0] = ::LoadSound(pSound->pSoundName, (SoundData *)0xFFFFFFFF, pSound->uSoundID); | |
172 | |
173 if (!pSound->pSoundData[0]) | |
174 return 0; | |
175 | |
176 if (a3) | |
592 | 177 pSound->uFlags |= SOUND_DESC_SYSTEM; |
0 | 178 |
179 if (!pAudioPlayer->b3DSoundInitialized) | |
180 return uSoundIdx; | |
181 | |
592 | 182 if (~pSound->uFlags & SOUND_DESC_SWAP || !pSound->pSoundData[0]) |
0 | 183 return uSoundIdx; |
184 | |
185 | |
186 auto pSoundData = pSound->pSoundData[0]; | |
187 switch (AIL_file_type((void *)pSoundData->pData, pSoundData->uDataSize)) | |
188 { | |
189 default: | |
190 case AILFILETYPE_UNKNOWN: | |
191 pSound->bDecompressed = false; | |
192 return 0; | |
193 | |
194 case AILFILETYPE_PCM_WAV: | |
195 pSound->p3DSound = pSound->pSoundData[0]; | |
196 return uSoundIdx; | |
197 | |
198 case AILFILETYPE_ADPCM_WAV: | |
199 if (AIL_WAV_info((void *)pSoundData->pData, &v24) && v24.uChannels != 2) | |
200 { | |
201 if (!AIL_decompress_ADPCM(&v24, &pSound->p3DSound, &a1) ) | |
202 { | |
203 pSound->p3DSound = nullptr; | |
204 pSound->bDecompressed = true; | |
764 | 205 UnloadSound(uSoundIdx, 0); |
0 | 206 } |
207 } | |
208 return uSoundIdx; | |
209 }; | |
210 } | |
211 | |
212 //----- (004A9BBD) -------------------------------------------------------- | |
213 int SoundList::LoadSound(unsigned int a2, LPVOID lpBuffer, int uBufferSizeLeft, int *pOutSoundSize, int a6) | |
214 { | |
215 //SoundList *v6; // edi@1 | |
216 signed int v7; // esi@1 | |
217 //unsigned __int8 v8; // zf@1 | |
218 //unsigned __int8 v9; // sf@1 | |
219 SoundDesc *v10; // eax@3 | |
220 SoundDesc *v11; // ecx@3 | |
221 int v12; // ebx@7 | |
222 int result; // eax@13 | |
223 SoundHeader *v14; // esi@16 | |
224 DWORD *v15; // edi@16 | |
225 int v16; // ebx@16 | |
226 unsigned int v17; // eax@18 | |
227 void *v18; // ebx@19 | |
228 std::string v19; // [sp-18h] [bp-38h]@22 | |
229 const char *v20; // [sp-8h] [bp-28h]@22 | |
230 int v21; // [sp-4h] [bp-24h]@22 | |
231 //SoundList *v22; // [sp+Ch] [bp-14h]@1 | |
232 SoundDesc *Args; // [sp+10h] [bp-10h]@3 | |
233 unsigned int v24; // [sp+14h] [bp-Ch]@2 | |
234 int v25; // [sp+18h] [bp-8h]@2 | |
235 int v26; // [sp+1Ch] [bp-4h]@1 | |
236 | |
237 //v6 = this; | |
238 v7 = 0; | |
239 //v22 = this; | |
240 //v8 = this->uNumSounds == 0; | |
241 //v9 = (this->uNumSounds & 0x80000000u) != 0; | |
242 v26 = 0; | |
764 | 243 if (!sNumSounds) |
0 | 244 return 0; |
245 | |
246 | |
247 v24 = 0; | |
248 v25 = 44; | |
249 while ( 1 ) | |
250 { | |
251 v10 = pSounds; | |
252 v11 = &v10[v24 / 0x78]; | |
253 Args = &v10[v24 / 0x78]; | |
254 if ( a2 == v10[v24 / 0x78].uSoundID ) | |
255 { | |
256 if ( a6 == v7 && *(int *)&v10->pSoundName[v25] != v7 ) | |
257 return v26; | |
258 if ( (signed int)pAudioPlayer->uNumSoundHeaders > v7 ) | |
259 break; | |
260 } | |
261 LABEL_12: | |
262 ++v26; | |
263 v25 += 120; | |
264 v24 += 120; | |
764 | 265 if ( v26 >= (signed int)sNumSounds ) |
0 | 266 return 0; |
267 } | |
268 v12 = 0; | |
269 while ( _strcmpi(pAudioPlayer->pSoundHeaders[v12].pSoundName, v11->pSoundName) ) | |
270 { | |
271 ++v7; | |
272 ++v12; | |
273 if ( v7 >= (signed int)pAudioPlayer->uNumSoundHeaders ) | |
274 { | |
275 v7 = 0; | |
276 goto LABEL_12; | |
277 } | |
278 v11 = Args; | |
279 } | |
280 v14 = &pAudioPlayer->pSoundHeaders[v7]; | |
281 v15 = (DWORD *)&v14->uDecompressedSize; | |
282 a2 = v14->uDecompressedSize; | |
283 v16 = a2; | |
284 if ( (signed int)a2 > uBufferSizeLeft ) | |
285 Abortf("Sound %s is size %i bytes, sound buffer size is %i bytes", Args, a2, uBufferSizeLeft); | |
286 SetFilePointer(pAudioPlayer->hAudioSnd, v14->uFileOffset, 0, 0); | |
287 v17 = v14->uCompressedSize; | |
288 if ( (signed int)v17 >= (signed int)*v15 ) | |
289 { | |
290 if ( v17 == *v15 ) | |
291 { | |
292 ReadFile(pAudioPlayer->hAudioSnd, lpBuffer, *v15, (LPDWORD)&Args, 0); | |
293 } | |
294 else | |
295 { | |
296 MessageBoxW(nullptr, L"Can't load sound file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Sound.cpp:666", 0); | |
297 } | |
298 } | |
299 else | |
300 { | |
301 v18 = malloc(v14->uCompressedSize); | |
302 ReadFile(pAudioPlayer->hAudioSnd, v18, v14->uCompressedSize, (LPDWORD)&Args, 0); | |
303 zlib::MemUnzip(lpBuffer, &v14->uDecompressedSize, v18, v14->uCompressedSize); | |
304 free(v18); | |
305 v16 = a2; | |
306 } | |
307 result = v26; | |
308 pSounds->pSoundData[a6 + 30 * v26] = (SoundData *)lpBuffer; | |
309 *pOutSoundSize = v16; | |
310 | |
311 return result; | |
312 } | |
313 | |
314 //----- (004A9D3E) -------------------------------------------------------- | |
315 SoundDesc *SoundList::Release() | |
316 { | |
317 SoundList *v1; // esi@1 | |
318 signed int v2; // ebx@1 | |
319 int v3; // edi@2 | |
320 SoundDesc *result; // eax@3 | |
321 void *v5; // ecx@3 | |
322 | |
323 v1 = this; | |
324 v2 = 0; | |
764 | 325 if ( (signed int)this->sNumSounds > 0 ) |
0 | 326 { |
327 v3 = 0; | |
328 do | |
329 { | |
330 result = v1->pSounds; | |
331 v5 = result[v3].pSoundData[0]; | |
332 if ( v5 ) | |
333 { | |
334 ReleaseSoundData(v5); | |
335 v1->pSounds[v3].pSoundData[0] = 0; | |
336 result = (SoundDesc *)((char *)&v1->pSounds[v3] + 40); | |
337 *(int *)&result->pSoundName[0] &= 0xFFFFFFFEu; | |
338 } | |
339 ++v2; | |
340 ++v3; | |
341 } | |
764 | 342 while ( v2 < (signed int)v1->sNumSounds ); |
0 | 343 } |
344 return result; | |
345 } | |
346 | |
347 //----- (004A9D79) -------------------------------------------------------- | |
348 void SoundList::_4A9D79(int a2) | |
349 { | |
350 SoundList *v2; // esi@1 | |
351 int v3; // edi@1 | |
352 signed int i; // ebx@1 | |
353 SoundDesc *v5; // eax@2 | |
354 SOUND_DESC_TYPE v6; // ecx@2 | |
355 void *v7; // eax@5 | |
356 | |
357 v2 = this; | |
358 v3 = 0; | |
764 | 359 for ( i = 0; i < (signed int)v2->sNumSounds; ++v3 ) |
0 | 360 { |
361 v5 = &v2->pSounds[v3]; | |
362 v6 = v5->eType; | |
363 if ( v6 != SOUND_DESC_SYSTEM && (a2 || v6 != SOUND_DESC_LOCK) ) | |
364 { | |
365 v7 = v5->pSoundData[0]; | |
366 if ( v7 ) | |
367 { | |
368 ReleaseSoundData(v7); | |
369 v2->pSounds[v3].pSoundData[0] = 0; | |
370 } | |
592 | 371 v2->pSounds[v3].uFlags &= ~SOUND_DESC_SYSTEM; |
0 | 372 } |
373 ++i; | |
374 } | |
375 } | |
376 | |
377 //----- (004A9DCD) -------------------------------------------------------- | |
764 | 378 void SoundList::UnloadSound(unsigned int uSoundID, char a3) |
0 | 379 { |
764 | 380 if ( pSounds[uSoundID].eType != SOUND_DESC_SYSTEM ) |
0 | 381 { |
764 | 382 if ( (pSounds[uSoundID].uFlags & SOUND_DESC_SWAP) && pSounds[uSoundID].p3DSound && a3 ) |
0 | 383 { |
764 | 384 if ( pSounds[uSoundID].bDecompressed) |
385 AIL_mem_free_lock(pSounds[uSoundID].p3DSound); | |
386 pSounds[uSoundID].p3DSound = 0; | |
387 pSounds[uSoundID].uFlags &= ~SOUND_DESC_SYSTEM; | |
0 | 388 } |
764 | 389 if ( pSounds[uSoundID].pSoundData[0] ) |
0 | 390 { |
764 | 391 ReleaseSoundData(pSounds[uSoundID].pSoundData[0]); |
392 pSounds[uSoundID].pSoundData[0] = NULL; | |
393 pSounds[uSoundID].uFlags &= ~SOUND_DESC_SYSTEM; | |
0 | 394 } |
395 } | |
396 } | |
397 | |
398 | |
399 //----- (004A9E3D) -------------------------------------------------------- | |
400 void SoundList::ToFile() | |
401 { | |
402 SoundList *v1; // esi@1 | |
403 FILE *v2; // eax@1 | |
404 FILE *v3; // edi@1 | |
405 | |
406 v1 = this; | |
407 v2 = fopen("data\\dsounds.bin", "wb"); | |
408 v3 = v2; | |
409 if ( !v2 ) | |
410 Abortf("Unable to save dsounds.bin!"); | |
411 fwrite(v1, 4u, 1u, v2); | |
764 | 412 fwrite(v1->pSounds, 0x78u, v1->sNumSounds, v3); |
0 | 413 fclose(v3); |
414 } | |
415 | |
416 //----- (004A9E89) -------------------------------------------------------- | |
417 void *SoundList::FromFile(void *pSerialized) | |
418 { | |
764 | 419 sNumSounds = *(int *)pSerialized; |
420 pSounds = (SoundDesc *)pAllocator->AllocNamedChunk(pSounds, 120 * sNumSounds, "Snd Des."); | |
421 return memcpy(pSounds, (char *)pSerialized + 4, 120 * sNumSounds); | |
0 | 422 } |
423 | |
424 //----- (004A9ED0) -------------------------------------------------------- | |
425 int SoundList::FromFileTxt(const char *Args) | |
426 { | |
427 SoundList *v2; // ebx@1 | |
428 __int32 v3; // edi@1 | |
429 FILE *v4; // eax@1 | |
430 unsigned int v5; // esi@3 | |
431 void *v6; // eax@9 | |
432 FILE *v7; // ST0C_4@11 | |
433 char *i; // eax@11 | |
434 int v9; // eax@14 | |
435 const char *v10; // ST0C_4@14 | |
436 int v11; // eax@18 | |
437 SoundDesc *v12; // ecx@18 | |
438 char v13; // zf@18 | |
439 unsigned int v14; // eax@18 | |
440 int v15; // eax@23 | |
441 char Buf; // [sp+Ch] [bp-2F0h]@3 | |
442 FrameTableTxtLine v18; // [sp+200h] [bp-FCh]@4 | |
443 FrameTableTxtLine v19; // [sp+27Ch] [bp-80h]@4 | |
444 FILE *File; // [sp+2F8h] [bp-4h]@1 | |
445 unsigned int Argsa; // [sp+304h] [bp+8h]@3 | |
446 | |
447 v2 = this; | |
448 pAllocator->FreeChunk(this->pSounds); | |
449 v3 = 0; | |
450 v2->pSounds = 0; | |
764 | 451 v2->sNumSounds = 0; |
0 | 452 v4 = fopen(Args, "r"); |
453 File = v4; | |
454 if ( !v4 ) | |
455 Abortf("SoundListClass::load - Unable to open file: %s."); | |
456 v5 = 0; | |
457 Argsa = 0; | |
458 if ( fgets(&Buf, 490, v4) ) | |
459 { | |
460 do | |
461 { | |
462 *strchr(&Buf, 10) = 0; | |
703 | 463 memcpy(&v19, txt_file_frametable_parser(&Buf, &v18), sizeof(v19)); |
701 | 464 if ( v19.uPropCount && *v19.pProperties[0] != 47 ) |
0 | 465 ++Argsa; |
466 } | |
467 while ( fgets(&Buf, 490, File) ); | |
468 v5 = Argsa; | |
469 v3 = 0; | |
470 } | |
764 | 471 v2->sNumSounds = v5; |
0 | 472 v6 = pAllocator->AllocNamedChunk(v2->pSounds, 120 * v5, "Snd Des."); |
473 v2->pSounds = (SoundDesc *)v6; | |
474 if ( v6 == (void *)v3 ) | |
475 Abortf("SoundListClass::load - Out of Memory!"); | |
764 | 476 memset(v6, v3, 120 * v2->sNumSounds); |
0 | 477 v7 = File; |
764 | 478 v2->sNumSounds = v3; |
0 | 479 fseek(v7, v3, v3); |
480 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) ) | |
481 { | |
482 *strchr(&Buf, 10) = 0; | |
703 | 483 memcpy(&v19, txt_file_frametable_parser(&Buf, &v18), sizeof(v19)); |
701 | 484 if ( v19.uPropCount && *v19.pProperties[0] != 47 ) |
0 | 485 { |
764 | 486 sprintf(v2->pSounds[v2->sNumSounds].pSoundName, "%s", v19.pProperties[0]); |
0 | 487 v9 = atoi(v19.pProperties[1]); |
488 v10 = v19.pProperties[2]; | |
764 | 489 v2->pSounds[v2->sNumSounds].uSoundID = v9; |
0 | 490 if ( _strcmpi(v10, "system") ) |
491 { | |
492 if ( _strcmpi(v19.pProperties[2], "swap") ) | |
493 { | |
494 v11 = _strcmpi(v19.pProperties[2], "lock"); | |
495 v12 = v2->pSounds; | |
496 v13 = v11 == 0; | |
764 | 497 v14 = v2->sNumSounds; |
0 | 498 if ( v13 ) |
499 v12[v14].eType = SOUND_DESC_LOCK; | |
500 else | |
501 v12[v14].eType = SOUND_DESC_LEVEL; | |
502 } | |
503 else | |
504 { | |
764 | 505 v2->pSounds[v2->sNumSounds].eType = SOUND_DESC_SWAP; |
0 | 506 } |
507 } | |
508 else | |
509 { | |
764 | 510 v2->pSounds[v2->sNumSounds].eType = SOUND_DESC_SYSTEM; |
0 | 511 } |
701 | 512 if ( v19.uPropCount >= 4 && !_strcmpi(v19.pProperties[3], "3D") ) |
0 | 513 { |
764 | 514 v15 = (int)&v2->pSounds[v2->sNumSounds].uFlags; |
592 | 515 *(int *)v15 |= SOUND_DESC_SWAP; |
0 | 516 } |
764 | 517 ++v2->sNumSounds; |
0 | 518 } |
519 } | |
520 fclose(File); | |
521 return 1; | |
522 } | |
523 | |
524 //----- (004AA13F) -------------------------------------------------------- | |
525 void AudioPlayer::PlayMusicTrack(MusicID eTrack) | |
526 { | |
527 if (!bNoSound && bPlayerReady && hAILRedbook && uMusicVolimeMultiplier) | |
528 { | |
529 AIL_redbook_stop(hAILRedbook); | |
328 | 530 AIL_redbook_set_volume(hAILRedbook, (signed)pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f); |
0 | 531 AIL_redbook_track_info(hAILRedbook, eTrack, &uCurrentMusicTrackStartMS, &uCurrentMusicTrackEndMS); |
532 AIL_redbook_play(hAILRedbook, uCurrentMusicTrackStartMS + 1, uCurrentMusicTrackEndMS); | |
533 uCurrentMusicTrackLength = ((uCurrentMusicTrackEndMS - uCurrentMusicTrackStartMS) * 128) / 1000; | |
534 } | |
535 } | |
536 | |
537 | |
538 //----- (004AA1F3) -------------------------------------------------------- | |
539 void AudioPlayer::SetMusicVolume(int vol) | |
540 { | |
541 if (bPlayerReady) | |
542 { | |
543 if (hAILRedbook) | |
544 AIL_redbook_set_volume(hAILRedbook, vol); | |
545 } | |
546 } | |
547 | |
548 //----- (004AA214) -------------------------------------------------------- | |
328 | 549 void AudioPlayer::SetMasterVolume(float fVolume) |
0 | 550 { |
328 | 551 if ( bPlayerReady ) |
0 | 552 { |
328 | 553 uMasterVolume = fVolume; |
554 if ( hDigDriver ) | |
555 AIL_set_digital_master_volume(hDigDriver, fVolume); | |
556 if ( b3DSoundInitialized ) | |
557 s3DSoundVolume = fVolume * 0.5f; | |
0 | 558 } |
559 } | |
560 // 4D8304: using guessed type int __stdcall AIL_set_digital_master_volume(int, int); | |
561 | |
562 //----- (004AA258) -------------------------------------------------------- | |
563 void AudioPlayer::_4AA258(int a2) | |
564 { | |
565 AudioPlayer *v2; // esi@1 | |
566 int v3; // edi@4 | |
567 AudioPlayer_3DSample *v4; // ebx@5 | |
568 int v5; // ebx@11 | |
569 MixerChannel *v6; // edi@12 | |
570 | |
571 v2 = this; | |
572 if ( this->bPlayerReady ) | |
573 { | |
574 if ( this->b3DSoundInitialized && a2 && (v3 = 0, this->uNum3DSamples > 0) ) | |
575 { | |
576 v4 = this->p3DSamples; | |
577 while ( v4->field_4 != a2 || AIL_3D_sample_status(v4->hSample) != 4 ) | |
578 { | |
579 ++v3; | |
580 ++v4; | |
581 if ( v3 >= v2->uNum3DSamples ) | |
582 goto LABEL_9; | |
583 } | |
584 AIL_end_3D_sample(v2->p3DSamples[v3].hSample); | |
585 } | |
586 else | |
587 { | |
588 LABEL_9: | |
589 if ( v2->hDigDriver ) | |
590 { | |
591 if ( a2 ) | |
592 { | |
593 v5 = 0; | |
594 if ( v2->uMixerChannels > 0 ) | |
595 { | |
596 v6 = v2->pMixerChannels; | |
597 do | |
598 { | |
378 | 599 if ( v6->source_pid == a2 ) |
0 | 600 { |
379 | 601 if ( AIL_sample_status(v6->hSample) == AIL::Sample::Playing) |
0 | 602 { |
603 AIL_end_sample(v6->hSample); | |
764 | 604 FreeChannel(v6); |
0 | 605 } |
606 } | |
607 ++v5; | |
608 ++v6; | |
609 } | |
610 while ( v5 < v2->uMixerChannels ); | |
611 } | |
612 } | |
613 } | |
614 } | |
615 } | |
616 } | |
617 | |
618 //----- (004AA306) -------------------------------------------------------- | |
619 void AudioPlayer::PlaySound(SoundID eSoundID, signed int a3, unsigned int uNumRepeats, signed int PartyX, signed int PartyY, int a7, unsigned int uVolume, int sPlaybackRate) | |
620 { | |
621 //AudioPlayer *pAudioPlayer1; // esi@1 | |
388 | 622 //signed int pNum; // edx@5 |
623 //int *pSoundID; // ecx@6 | |
0 | 624 int v12; // edi@13 |
625 signed int v13; // ecx@17 | |
626 signed int v14; // eax@20 | |
627 int v15; // eax@24 | |
628 signed int v16; // eax@25 | |
515
cb0ad52d6a26
LayingItem -> SpriteObject (long-waited rename, old name was inaccurate and confused people)
Nomad
parents:
412
diff
changeset
|
629 SpriteObject *pLayingItem; // eax@28 |
0 | 630 signed int v18; // eax@29 |
631 Actor *pActor1; // eax@32 | |
632 signed int v20; // ecx@32 | |
633 double v21; // st7@32 | |
634 signed int v22; // ecx@33 | |
635 AudioPlayer_3DSample *pAudioPlayer_3DSample; // esi@53 | |
636 AudioPlayer_3DSample *pAudioPlayer_3DSample1; // esi@61 | |
637 int v25; // esi@67 | |
638 double v26; // st7@68 | |
639 int v27; // ST18_4@68 | |
640 int v28; // ebx@68 | |
641 int v29; // eax@68 | |
642 AudioPlayer_3DSample *pAudioPlayer_3DSample2; // esi@69 | |
643 int v31; // ST18_4@70 | |
644 int v32; // ebx@70 | |
645 int v33; // eax@70 | |
646 int v34; // eax@70 | |
647 char v35; // zf@70 | |
648 signed int v36; // ebx@74 | |
649 //AudioPlayer *pAudioPlayer2; // edi@79 | |
650 AudioPlayer_3DSample *pAudioPlayer_3DSample3; // esi@79 | |
388 | 651 //unsigned int v39; // ebx@80 |
0 | 652 int v40; // eax@81 |
653 char *v41; // edi@82 | |
654 int v42; // esi@82 | |
655 double v43; // st7@91 | |
515
cb0ad52d6a26
LayingItem -> SpriteObject (long-waited rename, old name was inaccurate and confused people)
Nomad
parents:
412
diff
changeset
|
656 SpriteObject *pLayingItem2; // eax@92 |
0 | 657 Actor *pActor; // eax@93 |
658 signed int v46; // ecx@93 | |
659 double v47; // st7@93 | |
660 BLVDoor *pBLVDoor; // eax@97 | |
661 double v49; // st7@104 | |
662 int v50; // ST18_4@104 | |
663 int v51; // ebx@104 | |
664 int v52; // eax@104 | |
665 float v53; // ST0C_4@106 | |
666 float v54; // ST04_4@106 | |
667 //AudioPlayer *pAudioPlayer3; // edx@106 | |
668 SoundDesc *pSoundDesc; // edx@107 | |
515
cb0ad52d6a26
LayingItem -> SpriteObject (long-waited rename, old name was inaccurate and confused people)
Nomad
parents:
412
diff
changeset
|
669 SpriteObject *pLayingItem3; // eax@114 |
388 | 670 //int v58; // edx@115 |
671 //int v59; // ecx@115 | |
672 //Actor *pActor2; // eax@118 | |
673 //MixerChannel *pMixerChannel; // esi@126 | |
0 | 674 signed int v62; // esi@133 |
675 //AudioPlayer *pAudioPlayer4; // ebx@133 | |
388 | 676 //MixerChannel *pMixerChannel2; // edi@134 |
677 //int v65; // ebx@141 | |
0 | 678 //AudioPlayer *pAudioPlayer5; // ecx@142 |
388 | 679 //MixerChannel *pMixerChannel3; // edi@142 |
0 | 680 int v68; // eax@143 |
388 | 681 //MixerChannel *pMixerChannel4; // edi@149 |
682 //int v70; // ecx@152 | |
683 //SoundDesc *pSoundDesc2; // eax@153 | |
684 //int v72; // edi@156 | |
685 //MixerChannel *pMixerChannel5; // esi@157 | |
686 //unsigned int pVolume; // eax@157 | |
687 //int pPartyX; // ebx@159 | |
688 //int v76; // ebx@160 | |
515
cb0ad52d6a26
LayingItem -> SpriteObject (long-waited rename, old name was inaccurate and confused people)
Nomad
parents:
412
diff
changeset
|
689 //SpriteObject *pLayingItem4; // edi@164 |
388 | 690 //unsigned int pPosY; // edx@166 |
691 //unsigned int pPosX; // ecx@166 | |
692 //int v80; // eax@167 | |
693 //Actor *pActor3; // edi@168 | |
694 //BLVDoor *pBLVDoor2; // edi@173 | |
695 //int v83; // eax@183 | |
696 //int v84; // eax@183 | |
697 //_SAMPLE *v85; // ST18_4@186 | |
0 | 698 unsigned int v86; // [sp+14h] [bp-60h]@84 |
388 | 699 //int v87; // [sp+14h] [bp-60h]@115 |
0 | 700 RenderVertexSoft pRenderVertexSoft; // [sp+24h] [bp-50h]@1 |
388 | 701 //unsigned int v89; // [sp+54h] [bp-20h]@12 |
0 | 702 int v90; // [sp+58h] [bp-1Ch]@68 |
703 float v91; // [sp+5Ch] [bp-18h]@68 | |
704 //unsigned int v92; // [sp+60h] [bp-14h]@10 | |
705 float v93; // [sp+64h] [bp-10h]@1 | |
706 signed int varC; // [sp+68h] [bp-Ch]@68 | |
388 | 707 //AudioPlayer *pAudioPlayer; // [sp+6Ch] [bp-8h]@1 |
0 | 708 int v96; // [sp+70h] [bp-4h]@19 |
709 signed int uNumRepeatsb; // [sp+84h] [bp+10h]@93 | |
710 float uNumRepeatsa; // [sp+84h] [bp+10h]@104 | |
711 float v99; // [sp+8Ch] [bp+18h]@104 | |
712 signed int v100; // [sp+90h] [bp+1Ch]@32 | |
713 int v101; // [sp+90h] [bp+1Ch]@52 | |
714 int v102; // [sp+90h] [bp+1Ch]@60 | |
715 int v103; // [sp+90h] [bp+1Ch]@68 | |
716 | |
388 | 717 if (!bPlayerReady) |
718 return; | |
719 if (!uSoundVolumeMultiplier) | |
720 return; | |
721 if (!hDigDriver) | |
722 return; | |
723 if (eSoundID == SOUND_Invalid) | |
0 | 724 return; |
388 | 725 |
726 //pAudioPlayer = this; | |
727 //v35 = this->bPlayerReady == 0; | |
728 //pAudioPlayer = this; | |
729 //LODWORD(v93) = 10000; | |
730 int sample_volume = 10000; | |
731 | |
732 | |
733 int sound_id = 0; | |
764 | 734 for (uint i = 0; i < pSoundList->sNumSounds; ++i) |
388 | 735 if (pSoundList->pSounds[i].uSoundID == eSoundID) |
736 { | |
737 sound_id = i; | |
738 break; | |
739 } | |
740 | |
741 if (!sound_id) | |
0 | 742 { |
388 | 743 Log::Warning(L"SoundID = %u not found", eSoundID); |
744 return; | |
0 | 745 } |
388 | 746 |
747 int start_channel = 0, | |
748 end_channel = 0; | |
749 | |
764 | 750 assert(sound_id < pSoundList->sNumSounds); |
388 | 751 auto sound_desc = pSoundList->pSounds + sound_id; |
752 if (!b3DSoundInitialized || sound_desc->Is3D()) | |
0 | 753 { |
388 | 754 if (!a3) // generic sound like from UI |
755 { | |
756 start_channel = 10; | |
757 end_channel = 12; | |
758 goto LABEL_133; | |
759 } | |
760 else if (a3 == -1) // exclusive sounds - can override | |
0 | 761 { |
388 | 762 start_channel = 13; |
763 end_channel = 13; | |
764 goto LABEL_133; | |
765 } | |
766 else | |
767 { | |
768 if (a3 < 0) // exclusive sounds - no override | |
0 | 769 { |
388 | 770 start_channel = 14; |
771 end_channel = 14; | |
772 goto LABEL_123; | |
0 | 773 } |
388 | 774 else |
0 | 775 { |
848 | 776 int object_type = PID_TYPE(a3), |
777 object_id = PID_ID(a3); | |
388 | 778 switch (object_type) |
0 | 779 { |
388 | 780 case OBJECT_BLVDoor: |
781 case OBJECT_Player: | |
782 { | |
783 start_channel = 10; | |
784 end_channel = 12; | |
785 goto LABEL_133; | |
786 } | |
787 break; | |
788 | |
789 case OBJECT_Actor: | |
790 { | |
791 start_channel = 0; | |
792 end_channel = 3; | |
793 | |
794 assert(object_id < uNumActors); | |
795 auto actor = &pActors[object_id]; | |
796 | |
797 sample_volume = GetSoundStrengthByDistanceFromParty(actor->vPosition.x, actor->vPosition.y, actor->vPosition.z); | |
798 if (!sample_volume) | |
799 return; | |
800 goto LABEL_123; | |
801 } | |
802 | |
803 case OBJECT_Decoration: | |
0 | 804 { |
388 | 805 start_channel = 4; |
806 end_channel = 4; | |
807 | |
808 assert(object_id < uNumLevelDecorations); | |
809 auto decor = &pLevelDecorations[object_id]; | |
810 | |
811 sample_volume = GetSoundStrengthByDistanceFromParty(decor->vPosition.x, decor->vPosition.y, decor->vPosition.z); | |
812 if (!sample_volume) | |
813 return; | |
814 goto LABEL_123; | |
0 | 815 } |
388 | 816 break; |
817 | |
818 case OBJECT_Item: | |
819 { | |
820 start_channel = 5; | |
821 end_channel = 7; | |
822 | |
515
cb0ad52d6a26
LayingItem -> SpriteObject (long-waited rename, old name was inaccurate and confused people)
Nomad
parents:
412
diff
changeset
|
823 assert(object_id < uNumSpriteObjects); |
cb0ad52d6a26
LayingItem -> SpriteObject (long-waited rename, old name was inaccurate and confused people)
Nomad
parents:
412
diff
changeset
|
824 auto object = &pSpriteObjects[object_id]; |
388 | 825 |
826 sample_volume = GetSoundStrengthByDistanceFromParty(object->vPosition.x, object->vPosition.y, object->vPosition.z); | |
827 if (!sample_volume) | |
828 return; | |
829 goto LABEL_123; | |
830 } | |
831 break; | |
832 | |
833 case OBJECT_BModel: | |
834 { | |
835 start_channel = 8; | |
836 end_channel = 9; | |
837 goto LABEL_123; | |
838 } | |
839 break; | |
840 | |
841 default: | |
842 assert(false); | |
0 | 843 } |
844 } | |
388 | 845 } |
846 | |
847 | |
848 | |
849 | |
850 | |
851 | |
852 LABEL_123: | |
853 for (uint i = 0; i < uMixerChannels; ++i) | |
854 { | |
855 auto channel = pMixerChannels + i; | |
856 if (channel->source_pid == a3 && | |
857 AIL_sample_status(channel->hSample) == AIL::Sample::Playing) | |
858 { | |
859 if (channel->uSourceTrackIdx == sound_id) | |
860 return; // already playing the same sound from the same source - return | |
861 | |
862 AIL_end_sample(channel->hSample); // requested new sound from the same source - end & switch | |
764 | 863 FreeChannel(channel); |
388 | 864 } |
865 } | |
866 | |
0 | 867 LABEL_133: |
388 | 868 v62 = start_channel; |
0 | 869 //pAudioPlayer4 = pAudioPlayer; |
388 | 870 for (v62 = start_channel; v62 <= end_channel; ++v62) |
0 | 871 { |
388 | 872 auto channel = pMixerChannels + v62; |
873 if (AIL_sample_status(channel->hSample) == AIL::Sample::Done) | |
874 { | |
875 AIL_end_sample(channel->hSample); | |
876 if (channel->uSourceTrackIdx) | |
764 | 877 FreeChannel(channel); |
388 | 878 break; |
879 } | |
880 } | |
881 /*if ( start_channel <= end_channel) | |
882 { | |
883 pMixerChannel2 = &pAudioPlayer->pMixerChannels[start_channel]; | |
379 | 884 while ( AIL_sample_status(pMixerChannel2->hSample) != AIL::Sample::Done) |
0 | 885 { |
886 ++v62; | |
887 ++pMixerChannel2; | |
388 | 888 if ( v62 > end_channel ) |
0 | 889 goto LABEL_140; |
890 } | |
891 AIL_end_sample(pMixerChannel2->hSample); | |
892 if ( pMixerChannel2->uSourceTrackIdx ) | |
893 _4ABE55(pMixerChannel2); | |
894 } | |
388 | 895 LABEL_140:*/ |
896 | |
897 if (v62 > end_channel) // no free channel - occupy the quitest one | |
0 | 898 { |
388 | 899 v62 = -1; |
900 | |
901 int min_volume = sample_volume; | |
902 for (uint i = start_channel; i <= end_channel; ++i) | |
0 | 903 { |
388 | 904 auto channel = pMixerChannels + i; |
905 | |
906 int volume = AIL_sample_volume(channel->hSample); | |
907 if (volume < min_volume) | |
0 | 908 { |
388 | 909 min_volume = volume; |
910 v62 = i; | |
0 | 911 } |
912 } | |
388 | 913 /*v65 = start_channel; |
914 v91 = v93; | |
915 if (start_channel <= end_channel) | |
0 | 916 { |
917 //pAudioPlayer5 = pAudioPlayer; | |
388 | 918 pMixerChannel3 = &pAudioPlayer->pMixerChannels[start_channel]; |
0 | 919 do |
920 { | |
921 v68 = AIL_sample_volume(pMixerChannel3->hSample); | |
922 if ( v68 < SLODWORD(v91) ) | |
923 { | |
924 LODWORD(v91) = v68; | |
925 v62 = v65; | |
926 } | |
927 ++v65; | |
928 ++pMixerChannel3; | |
929 } | |
388 | 930 while ( v65 <= end_channel );*/ |
931 | |
932 if (v62 == -1) // no free channels at all - only channel 13 allows override (a3 == -1) | |
0 | 933 { |
388 | 934 if (start_channel != 13) |
935 return; | |
936 v62 = 13; | |
0 | 937 } |
388 | 938 |
939 auto channel = &pMixerChannels[v62]; | |
940 AIL_end_sample(channel->hSample); | |
764 | 941 FreeChannel(channel); |
0 | 942 } |
388 | 943 |
944 if (v62 > end_channel)//10!=13 | |
0 | 945 return; |
388 | 946 |
947 //LABEL_150: | |
948 if (sample_volume == 10000) | |
949 sample_volume = uMasterVolume; | |
950 | |
951 //v70 = 0; | |
952 if ( !a7 ) | |
953 { | |
954 //pSoundDesc = pSoundList->pSounds; | |
955 //pSoundDesc2 = &pSoundList->pSounds[sound_id]; | |
956 if (!sound_desc->pSoundData[0]) | |
957 { | |
958 if (sound_desc->eType == SOUND_DESC_SWAP) | |
959 pSoundList->LoadSound(eSoundID, 0); | |
960 } | |
961 } | |
962 //v72 = 4 * (a7 + 30 * sound_id) + 44; | |
963 if (!pSoundList->pSounds[sound_id].pSoundData[a7]) | |
964 return; | |
965 | |
966 //pMixerChannel5 = &pAudioPlayer->pMixerChannels[v62]; | |
967 auto channel = &pMixerChannels[v62]; | |
968 AIL_init_sample(channel->hSample); | |
969 AIL_set_sample_file(channel->hSample, (char *)pSoundList->pSounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1); | |
970 if (uVolume) | |
971 sample_volume = uVolume; | |
972 AIL_set_sample_volume(channel->hSample, sample_volume); | |
973 | |
848 | 974 int object_type = PID_TYPE(a3), |
975 object_id = PID_ID(a3); | |
388 | 976 if (PartyX != -1) |
977 { | |
978 if (!PartyX) PartyX = pParty->vPosition.x; | |
979 if (!PartyY) PartyY = pParty->vPosition.y; | |
980 AIL_set_sample_pan(channel->hSample, sub_4AB66C(PartyX, PartyY)); | |
981 AIL_set_sample_volume(channel->hSample, GetSoundStrengthByDistanceFromParty(PartyX, PartyY, pParty->vPosition.z)); | |
982 } | |
983 else if (object_type == OBJECT_BLVDoor) | |
0 | 984 { |
388 | 985 assert(uCurrentlyLoadedLevelType == LEVEL_Indoor); |
986 | |
987 assert(object_id < pIndoor->uNumDoors); | |
988 auto door = &pIndoor->pDoors[object_id]; | |
989 if (!door->uDoorID) | |
0 | 990 return; |
388 | 991 |
992 if (!GetSoundStrengthByDistanceFromParty(door->pXOffsets[0], door->pYOffsets[0], door->pZOffsets[0])) | |
0 | 993 { |
388 | 994 AIL_end_sample(channel->hSample); |
764 | 995 FreeChannel(channel); |
388 | 996 return; |
0 | 997 } |
388 | 998 AIL_set_sample_pan(channel->hSample, sub_4AB66C(door->pXOffsets[0], door->pYOffsets[0])); |
999 } | |
1000 else if (object_type == OBJECT_Item) | |
1001 { | |
515
cb0ad52d6a26
LayingItem -> SpriteObject (long-waited rename, old name was inaccurate and confused people)
Nomad
parents:
412
diff
changeset
|
1002 assert(object_id < uNumSpriteObjects); |
cb0ad52d6a26
LayingItem -> SpriteObject (long-waited rename, old name was inaccurate and confused people)
Nomad
parents:
412
diff
changeset
|
1003 auto object = &pSpriteObjects[object_id]; |
388 | 1004 if (!GetSoundStrengthByDistanceFromParty(object->vPosition.x, object->vPosition.y, object->vPosition.z) ) |
1005 return; | |
1006 AIL_set_sample_pan(channel->hSample, sub_4AB66C(object->vPosition.x, object->vPosition.y)); | |
1007 } | |
1008 else if (object_type == OBJECT_Actor) | |
1009 { | |
1010 assert(object_id < uNumActors); | |
1011 auto actor = &pActors[object_id]; | |
1012 if (!GetSoundStrengthByDistanceFromParty(actor->vPosition.x, actor->vPosition.y, actor->vPosition.z)) | |
1013 return; | |
1014 AIL_set_sample_pan(channel->hSample, sub_4AB66C(actor->vPosition.x, actor->vPosition.y)); | |
0 | 1015 } |
388 | 1016 else if (object_type == OBJECT_Decoration) |
1017 { | |
1018 assert(object_id < uNumLevelDecorations); | |
1019 auto decor = &pLevelDecorations[object_id]; | |
1020 if (!GetSoundStrengthByDistanceFromParty(decor->vPosition.x, decor->vPosition.y, decor->vPosition.z)) | |
1021 return; | |
1022 AIL_set_sample_pan(channel->hSample, sub_4AB66C(decor->vPosition.x, decor->vPosition.y)); | |
1023 } | |
1024 | |
1025 //LABEL_184: | |
1026 if (uNumRepeats) | |
1027 AIL_set_sample_loop_count(channel->hSample, uNumRepeats - 1); | |
1028 channel->uSourceTrackIdx = sound_id; | |
1029 channel->source_pid = a3; | |
1030 channel->uSourceTrackID = eSoundID; | |
1031 int rval = AIL_start_sample(channel->hSample); | |
1032 if ( sPlaybackRate ) | |
1033 AIL_set_sample_playback_rate(channel->hSample, sPlaybackRate); | |
1034 if (object_type == OBJECT_Player) | |
1035 AIL_sample_ms_position(channel->hSample, &sLastTrackLengthMS, 0); | |
1036 return; | |
0 | 1037 } |
388 | 1038 |
1039 | |
1040 | |
1041 | |
1042 __debugbreak(); // 3d sound stuff, refactor | |
0 | 1043 v12 = 13; |
1044 if ( a3 < 0 ) | |
1045 { | |
1046 v15 = pAudioPlayer->uNum3DSamples; | |
1047 if ( a3 == -1 ) | |
1048 { | |
1049 if ( v15 < 16 ) | |
1050 v12 = v15 - 1; | |
1051 v96 = v12; | |
1052 //goto LABEL_46; | |
1053 pRenderVertexSoft.vWorldPosition.x = (double)pParty->vPosition.x; | |
1054 pRenderVertexSoft.vWorldPosition.y = (double)pParty->vPosition.y; | |
1055 v21 = (double)pParty->sEyelevel + (double)pParty->vPosition.z; | |
1056 goto LABEL_47; | |
1057 } | |
1058 if ( v15 >= 16 ) | |
1059 v15 = 14; | |
1060 v12 = v15; | |
1061 //goto LABEL_45; | |
1062 v96 = v15; | |
1063 pRenderVertexSoft.vWorldPosition.x = (double)pParty->vPosition.x; | |
1064 pRenderVertexSoft.vWorldPosition.y = (double)pParty->vPosition.y; | |
1065 v21 = (double)pParty->sEyelevel + (double)pParty->vPosition.z; | |
1066 goto LABEL_47; | |
1067 } | |
848 | 1068 if ( PID_TYPE(a3) == 2 ) |
0 | 1069 { |
1070 v22 = pAudioPlayer->uNum3DSamples; | |
1071 if ( v22 < 16 ) | |
1072 { | |
1073 v12 = 5 * v22 / 16; | |
1074 v96 = 7 * v22 / 16; | |
1075 } | |
1076 else | |
1077 { | |
1078 v96 = 7; | |
1079 v12 = 5; | |
1080 } | |
848 | 1081 pLayingItem = &pSpriteObjects[PID_ID(a3)]; |
0 | 1082 } |
1083 else | |
1084 { | |
848 | 1085 if ( PID_TYPE(a3) == 3 ) |
0 | 1086 { |
1087 v18 = pAudioPlayer->uNum3DSamples; | |
1088 v12 = 0; | |
1089 if ( v18 < 16 ) | |
1090 v96 = 3 * v18 / 16; | |
1091 else | |
1092 v96 = 3; | |
848 | 1093 pActor1 = &pActors[PID_ID(a3)]; |
0 | 1094 v20 = pActor1->vPosition.y; |
1095 pRenderVertexSoft.vWorldPosition.x = (double)pActor1->vPosition.x; | |
1096 v100 = pActor1->vPosition.z; | |
1097 pRenderVertexSoft.vWorldPosition.y = (double)v20; | |
1098 v21 = (double)v100; | |
1099 goto LABEL_47; | |
1100 } | |
848 | 1101 if ( PID_TYPE(a3) != 5 ) |
0 | 1102 { |
1103 v13 = pAudioPlayer->uNum3DSamples; | |
848 | 1104 if ( PID_TYPE(a3) == 6 ) |
0 | 1105 { |
1106 if ( v13 >= 16 ) | |
1107 { | |
1108 v96 = 9; | |
1109 v12 = 8; | |
1110 //goto LABEL_46; | |
1111 pRenderVertexSoft.vWorldPosition.x = (double)pParty->vPosition.x; | |
1112 pRenderVertexSoft.vWorldPosition.y = (double)pParty->vPosition.y; | |
1113 v21 = (double)pParty->sEyelevel + (double)pParty->vPosition.z; | |
1114 goto LABEL_47; | |
1115 } | |
1116 v12 = 8 * v13 / 16; | |
1117 v14 = 9 * v13; | |
1118 } | |
1119 else | |
1120 { | |
1121 if ( v13 >= 16 ) | |
1122 { | |
1123 v96 = 12; | |
1124 v12 = 10; | |
1125 //LABEL_46: | |
1126 pRenderVertexSoft.vWorldPosition.x = (double)pParty->vPosition.x; | |
1127 pRenderVertexSoft.vWorldPosition.y = (double)pParty->vPosition.y; | |
1128 v21 = (double)pParty->sEyelevel + (double)pParty->vPosition.z; | |
1129 goto LABEL_47; | |
1130 } | |
1131 v12 = 10 * v13 / 16; | |
1132 v14 = 12 * v13; | |
1133 } | |
1134 v15 = v14 / 16; | |
1135 //LABEL_45: | |
1136 v96 = v15; | |
1137 //goto LABEL_46; | |
1138 pRenderVertexSoft.vWorldPosition.x = (double)pParty->vPosition.x; | |
1139 pRenderVertexSoft.vWorldPosition.y = (double)pParty->vPosition.y; | |
1140 v21 = (double)pParty->sEyelevel + (double)pParty->vPosition.z; | |
1141 goto LABEL_47; | |
1142 } | |
1143 v16 = pAudioPlayer->uNum3DSamples; | |
1144 if ( v16 < 16 ) | |
1145 { | |
1146 v12 = v16 / 4; | |
1147 v96 = v16 / 4; | |
1148 } | |
1149 else | |
1150 { | |
1151 v12 = 4; | |
1152 v96 = 4; | |
1153 } | |
848 | 1154 pLayingItem = (SpriteObject *)&pLevelDecorations[PID_ID(a3)]; |
0 | 1155 } |
1156 pRenderVertexSoft.vWorldPosition.x = (double)pLayingItem->vPosition.x; | |
1157 pRenderVertexSoft.vWorldPosition.y = (double)pLayingItem->vPosition.y; | |
1158 v21 = (double)pLayingItem->vPosition.z; | |
1159 LABEL_47: | |
1160 pRenderVertexSoft.vWorldPosition.z = v21; | |
1161 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) | |
1162 sub_4AAEA6_transform(&pRenderVertexSoft); | |
1163 else | |
1164 pGame->pIndoorCameraD3D->ViewTransform(&pRenderVertexSoft, 1); | |
1165 if ( a3 ) | |
1166 { | |
1167 if ( a3 != -1 ) | |
1168 { | |
1169 v101 = 0; | |
1170 if ( pAudioPlayer->uNum3DSamples > 0 ) | |
1171 { | |
1172 pAudioPlayer_3DSample = pAudioPlayer->p3DSamples; | |
1173 do | |
1174 { | |
1175 if ( AIL_3D_sample_status(pAudioPlayer_3DSample->hSample) == 4 | |
1176 && pAudioPlayer_3DSample->field_4 == a3 && AIL_3D_sample_status(pAudioPlayer_3DSample->hSample) == 4 ) | |
1177 { | |
388 | 1178 if ( pAudioPlayer_3DSample->field_8 == sound_id ) |
0 | 1179 return; |
1180 AIL_end_3D_sample(pAudioPlayer_3DSample->hSample); | |
1181 pAudioPlayer->_4ABF23(pAudioPlayer_3DSample); | |
1182 } | |
1183 ++v101; | |
1184 ++pAudioPlayer_3DSample; | |
1185 } | |
1186 while ( v101 < pAudioPlayer->uNum3DSamples ); | |
1187 } | |
1188 } | |
1189 } | |
1190 v102 = v12; | |
1191 if ( v12 <= v96 ) | |
1192 { | |
1193 pAudioPlayer_3DSample1 = &pAudioPlayer->p3DSamples[v12]; | |
1194 while ( AIL_3D_sample_status(pAudioPlayer_3DSample1->hSample) != 2 ) | |
1195 { | |
1196 ++v102; | |
1197 ++pAudioPlayer_3DSample1; | |
1198 if ( v102 > v96 ) | |
1199 goto LABEL_67; | |
1200 } | |
1201 AIL_end_3D_sample(pAudioPlayer_3DSample1->hSample); | |
1202 if ( pAudioPlayer_3DSample1->field_8 ) | |
1203 pAudioPlayer->_4ABF23(pAudioPlayer_3DSample1); | |
1204 } | |
1205 LABEL_67: | |
1206 v25 = v96; | |
1207 if ( v102 == v96 + 1 ) | |
1208 { | |
1209 LODWORD(v91) = -1; | |
1210 v103 = 0; | |
1211 *(float *)&varC = pRenderVertexSoft.vWorldViewPosition.y * -0.012207031; | |
1212 v93 = 0.0; | |
1213 v26 = pRenderVertexSoft.vWorldViewPosition.x * 0.012207031; | |
1214 *(float *)&uVolume = v26; | |
1215 v27 = abs((signed __int64)v26); | |
1216 v28 = abs((signed __int64)v93); | |
1217 v29 = abs((signed __int64)*(float *)&varC); | |
322 | 1218 v90 = int_get_vector_length(v29, v28, v27); |
0 | 1219 sPlaybackRate = v12; |
1220 if ( v12 > v25 ) | |
1221 goto LABEL_192; | |
1222 pAudioPlayer_3DSample2 = &pAudioPlayer->p3DSamples[v12]; | |
1223 do | |
1224 { | |
1225 AIL_3D_position(pAudioPlayer_3DSample2->hSample, &varC, &v93, (long *)&uVolume); | |
1226 v31 = abs((signed __int64)*(float *)&uVolume); | |
1227 v32 = abs((signed __int64)v93); | |
1228 v33 = abs((signed __int64)*(float *)&varC); | |
322 | 1229 v34 = int_get_vector_length(v33, v32, v31); |
0 | 1230 v35 = v103 == v34; |
1231 if ( v103 < v34 ) | |
1232 { | |
1233 v103 = v34; | |
1234 v35 = 1; | |
1235 } | |
1236 if ( v35 && v90 < v103 ) | |
1237 { | |
1238 v36 = sPlaybackRate; | |
1239 LODWORD(v91) = sPlaybackRate; | |
1240 } | |
1241 else | |
1242 { | |
1243 v36 = LODWORD(v91); | |
1244 } | |
1245 ++sPlaybackRate; | |
1246 ++pAudioPlayer_3DSample2; | |
1247 } | |
1248 while ( sPlaybackRate <= v96 ); | |
1249 if ( v36 == -1 ) | |
1250 { | |
1251 LABEL_192: | |
1252 v36 = 13; | |
1253 if ( v12 != 13 ) | |
1254 return; | |
1255 } | |
1256 //pAudioPlayer2 = pAudioPlayer; | |
1257 pAudioPlayer_3DSample3 = &pAudioPlayer->p3DSamples[v36]; | |
1258 AIL_end_3D_sample(pAudioPlayer_3DSample3->hSample); | |
1259 pAudioPlayer->_4ABF23(pAudioPlayer_3DSample3); | |
1260 v102 = v36; | |
1261 } | |
388 | 1262 //v39 = v89; |
1263 if ( pSoundList->pSounds[sound_id].p3DSound || (LOWORD(v40) = pSoundList->LoadSound(eSoundID, 0), v40) ) | |
0 | 1264 { |
1265 v41 = (char *)pAudioPlayer + 16 * v102; | |
1266 v42 = (int)(v41 + 20); | |
388 | 1267 if ( AIL_set_3D_sample_file(*((int *)v41 + 5), *(void **)((char *)&pSoundList->pSounds->p3DSound + sound_id * sizeof(SoundDesc))) ) |
0 | 1268 { |
1269 if ( uNumRepeats ) | |
1270 v86 = uNumRepeats - 1; | |
1271 else | |
1272 v86 = 1; | |
1273 AIL_set_3D_sample_loop_count(*(int *)v42, v86); | |
1274 if ( PartyX == -1 ) | |
1275 { | |
848 | 1276 if ( PID_TYPE(a3) == 1 ) |
0 | 1277 { |
1278 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) | |
1279 { | |
1280 //goto LABEL_103; | |
848 | 1281 pBLVDoor = &pIndoor->pDoors[PID_ID(a3)]; |
0 | 1282 if ( !pBLVDoor->uDoorID ) |
1283 return; | |
1284 pRenderVertexSoft.vWorldPosition.x = (double)*pBLVDoor->pXOffsets; | |
1285 pRenderVertexSoft.vWorldPosition.y = (double)*pBLVDoor->pYOffsets; | |
1286 v47 = (double)*pBLVDoor->pZOffsets; | |
1287 LABEL_101: | |
1288 pRenderVertexSoft.vWorldPosition.z = v47; | |
1289 //if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) | |
1290 //{ | |
1291 sub_4AAEA6_transform(&pRenderVertexSoft); | |
1292 //goto LABEL_104; | |
1293 //} | |
1294 } | |
1295 //LABEL_103: | |
1296 if ( uCurrentlyLoadedLevelType != LEVEL_Indoor ) | |
1297 pGame->pIndoorCameraD3D->ViewTransform(&pRenderVertexSoft, 1); | |
1298 //LABEL_104: | |
1299 AIL_start_3D_sample(*(int *)v42); | |
1300 AIL_set_3D_sample_float_distances(*(int **)v42, 100.0, 20.0, 100.0, 20.0); | |
1301 AIL_set_3D_sample_volume(*(int **)v42, pAudioPlayer->s3DSoundVolume); | |
1302 v99 = pRenderVertexSoft.vWorldViewPosition.y * -0.012207031; | |
1303 v49 = pRenderVertexSoft.vWorldViewPosition.x * 0.012207031; | |
1304 uNumRepeatsa = v49; | |
1305 v50 = abs((signed __int64)v49); | |
1306 v51 = abs(0); | |
1307 v52 = abs((signed __int64)v99); | |
322 | 1308 if ( int_get_vector_length(v52, v51, v50) <= 100 ) |
0 | 1309 { |
1310 AIL_set_3D_position((void *)*(int *)v42, LODWORD(v99), 0.0, LODWORD(uNumRepeatsa)); | |
1311 v53 = -uNumRepeatsa; | |
1312 v54 = -v99; | |
1313 AIL_set_3D_orientation((void *)*(int *)v42, LODWORD(v54), 0.0, LODWORD(v53), 0.0, 1.0, 0.0); | |
1314 //pAudioPlayer3 = pAudioPlayer; | |
1315 *((int *)v41 + 6) = a3; | |
388 | 1316 *((int *)v41 + 7) = sound_id; |
0 | 1317 *(&pAudioPlayer->bEAXSupported + 4 * (v102 + 2)) = eSoundID; |
1318 } | |
1319 else | |
1320 { | |
1321 AIL_end_3D_sample(*(int **)v42); | |
1322 pAudioPlayer->_4ABF23((AudioPlayer_3DSample *)(v41 + 20)); | |
1323 } | |
1324 return; | |
1325 } | |
848 | 1326 if ( PID_TYPE(a3) == 2 ) |
0 | 1327 { |
848 | 1328 pLayingItem2 = &pSpriteObjects[PID_ID(a3)]; |
0 | 1329 } |
1330 else | |
1331 { | |
848 | 1332 if ( PID_TYPE(a3) == 3 ) |
0 | 1333 { |
848 | 1334 pActor = &pActors[PID_ID(a3)]; |
0 | 1335 v46 = pActor->vPosition.y; |
1336 pRenderVertexSoft.vWorldPosition.x = (double)pActor->vPosition.x; | |
1337 uNumRepeatsb = pActor->vPosition.z; | |
1338 pRenderVertexSoft.vWorldPosition.y = (double)v46; | |
1339 v47 = (double)uNumRepeatsb; | |
1340 goto LABEL_101; | |
1341 } | |
848 | 1342 if ( PID_TYPE(a3) != 5 ) |
0 | 1343 { |
1344 pRenderVertexSoft.vWorldPosition.x = (double)pParty->vPosition.x; | |
1345 v43 = (double)pParty->vPosition.y; | |
1346 LABEL_100: | |
1347 pRenderVertexSoft.vWorldPosition.y = v43; | |
1348 v47 = (double)pParty->sEyelevel + (double)pParty->vPosition.z; | |
1349 goto LABEL_101; | |
1350 } | |
848 | 1351 pLayingItem2 = (SpriteObject *)&pLevelDecorations[PID_ID(a3)]; |
0 | 1352 } |
1353 pRenderVertexSoft.vWorldPosition.x = (double)pLayingItem2->vPosition.x; | |
1354 pRenderVertexSoft.vWorldPosition.y = (double)pLayingItem2->vPosition.y; | |
1355 v47 = (double)pLayingItem2->vPosition.z; | |
1356 goto LABEL_101; | |
1357 } | |
1358 pRenderVertexSoft.vWorldPosition.x = (double)PartyX; | |
1359 v43 = (double)PartyY; | |
1360 goto LABEL_100; | |
1361 } | |
1362 } | |
1363 } | |
1364 | |
1365 //----- (0040DEA5) -------------------------------------------------------- | |
1366 void __cdecl AudioPlayer::MessWithChannels() | |
1367 { | |
1368 pAudioPlayer->StopChannels(-1, -1); | |
1369 } | |
1370 | |
1371 | |
1372 | |
1373 //----- (004AAFCF) -------------------------------------------------------- | |
378 | 1374 void AudioPlayer::UpdateSounds() |
0 | 1375 { |
378 | 1376 //AudioPlayer *pAudioPlayer; // edi@1 |
0 | 1377 int v2; // ebx@1 |
378 | 1378 //unsigned __int8 v3; // zf@1 |
1379 //int *v4; // eax@2 | |
1380 //unsigned __int8 v5; // sf@4 | |
0 | 1381 AudioPlayer_3DSample *v6; // esi@5 |
1382 int v7; // ebx@6 | |
1383 int v8; // ebx@9 | |
1384 int v9; // ebx@10 | |
1385 int v10; // ebx@11 | |
1386 double v11; // st7@13 | |
515
cb0ad52d6a26
LayingItem -> SpriteObject (long-waited rename, old name was inaccurate and confused people)
Nomad
parents:
412
diff
changeset
|
1387 SpriteObject *v12; // eax@14 |
0 | 1388 Actor *v13; // eax@15 |
1389 signed int v14; // edx@15 | |
1390 BLVDoor *v15; // eax@19 | |
1391 double v16; // st7@22 | |
1392 double v17; // st6@22 | |
1393 double v18; // st5@23 | |
1394 double v19; // st4@24 | |
1395 double v20; // st3@24 | |
1396 double v21; // st6@28 | |
1397 double v22; // st7@32 | |
1398 int v23; // ST1C_4@32 | |
1399 int v24; // ebx@32 | |
1400 int v25; // eax@32 | |
1401 float v26; // ST10_4@34 | |
1402 float v27; // ST08_4@34 | |
378 | 1403 //MixerChannel *v28; // esi@38 |
1404 //unsigned __int8 v29; // of@43 | |
1405 //MixerChannel *v30; // esi@44 | |
1406 //int v31; // eax@45 | |
515
cb0ad52d6a26
LayingItem -> SpriteObject (long-waited rename, old name was inaccurate and confused people)
Nomad
parents:
412
diff
changeset
|
1407 //SpriteObject *v32; // eax@49 |
378 | 1408 //Actor *v33; // edi@50 |
1409 //int v34; // eax@50 | |
1410 //unsigned int v35; // edx@51 | |
1411 //unsigned int v36; // ecx@51 | |
515
cb0ad52d6a26
LayingItem -> SpriteObject (long-waited rename, old name was inaccurate and confused people)
Nomad
parents:
412
diff
changeset
|
1412 //SpriteObject *v37; // edi@53 |
0 | 1413 int v38; // eax@53 |
378 | 1414 //BLVDoor *v39; // edi@56 |
1415 //int v40; // eax@57 | |
1416 //int v41; // eax@60 | |
379 | 1417 //MixerChannel *v42; // edi@65 |
1418 //int v43; // ebx@68 | |
1419 //LevelDecoration *v44; // esi@68 | |
1420 //int v45; // ST1C_4@68 | |
1421 //int v46; // edi@68 | |
1422 //int v47; // eax@68 | |
1423 //DecorationDesc *v48; // edi@69 | |
1424 //__int16 v49; // ax@69 | |
1425 //__int16 v50; // ax@70 | |
0 | 1426 __int16 v51; // ax@71 |
379 | 1427 //__int16 v52; // ax@73 |
0 | 1428 signed int v53; // eax@88 |
1429 RenderVertexSoft a1; // [sp+24h] [bp-48h]@1 | |
1430 float v55; // [sp+54h] [bp-18h]@22 | |
1431 float v56; // [sp+58h] [bp-14h]@22 | |
1432 int uNumRepeats; // [sp+5Ch] [bp-10h]@15 | |
1433 float v58; // [sp+60h] [bp-Ch]@23 | |
1434 int v59; // [sp+64h] [bp-8h]@4 | |
378 | 1435 //AudioPlayer *thisa; // [sp+68h] [bp-4h]@1 |
0 | 1436 |
378 | 1437 //pAudioPlayer = this; |
0 | 1438 v2 = 0; |
378 | 1439 //thisa = this; |
1440 //v3 = this->bPlayerReady == 0; | |
1441 //a1.flt_2C = 0.0; | |
1442 if (!bPlayerReady) | |
1443 return; | |
1444 | |
1445 if (field_2D0_time_left <= pEventTimer->uTimeElapsed) | |
1446 field_2D0_time_left = 32; | |
1447 else | |
0 | 1448 { |
378 | 1449 field_2D0_time_left -= pEventTimer->uTimeElapsed; |
1450 return; | |
1451 } | |
1452 | |
1453 //v3 = this->b3DSoundInitialized == 0; | |
1454 if (b3DSoundInitialized) | |
0 | 1455 { |
378 | 1456 __debugbreak(); // refactor refactor |
1457 //v3 = this->uNum3DSamples == 0; | |
1458 //v5 = this->uNum3DSamples < 0; | |
0 | 1459 v59 = 0; |
378 | 1460 if (uNum3DSamples > 0) |
0 | 1461 { |
1462 v6 = this->p3DSamples; | |
1463 while ( 1 ) | |
1464 { | |
848 | 1465 v7 = PID_TYPE(v6->field_4); |
0 | 1466 if ( AIL_3D_sample_status(v6->hSample) == 2 ) |
1467 { | |
1468 AIL_end_3D_sample(v6->hSample); | |
11 | 1469 pAudioPlayer->_4ABF23(v6); |
0 | 1470 } |
1471 if ( AIL_3D_sample_status(v6->hSample) != 4 ) | |
1472 goto LABEL_35; | |
1473 v8 = v7 - 1; | |
1474 if ( v8 ) | |
1475 break; | |
1476 if ( uCurrentlyLoadedLevelType != LEVEL_Indoor ) | |
1477 goto LABEL_31; | |
848 | 1478 v15 = &pIndoor->pDoors[PID_ID(v6->field_4)]; |
0 | 1479 if ( v15->uDoorID ) |
1480 { | |
1481 uNumRepeats = *v15->pXOffsets; | |
1482 a1.vWorldPosition.x = (double)uNumRepeats; | |
1483 uNumRepeats = *v15->pYOffsets; | |
1484 a1.vWorldPosition.y = (double)uNumRepeats; | |
1485 uNumRepeats = *v15->pZOffsets; | |
1486 v11 = (double)uNumRepeats; | |
1487 goto LABEL_21; | |
1488 } | |
1489 LABEL_35: | |
1490 ++v59; | |
1491 ++v6; | |
11 | 1492 if ( v59 >= pAudioPlayer->uNum3DSamples ) |
0 | 1493 { |
1494 v2 = 0; | |
1495 goto LABEL_37; | |
1496 } | |
1497 } | |
378 | 1498 |
0 | 1499 v9 = v8 - 1; |
1500 if ( v9 ) | |
1501 { | |
1502 v10 = v9 - 1; | |
1503 if ( !v10 ) | |
1504 { | |
848 | 1505 v13 = &pActors[PID_ID(v6->field_4)]; |
0 | 1506 uNumRepeats = v13->vPosition.x; |
1507 v14 = v13->vPosition.y; | |
1508 a1.vWorldPosition.x = (double)uNumRepeats; | |
1509 uNumRepeats = v13->vPosition.z; | |
1510 a1.vWorldPosition.y = (double)v14; | |
1511 v11 = (double)uNumRepeats; | |
1512 goto LABEL_21; | |
1513 } | |
1514 if ( v10 != 2 ) | |
1515 { | |
1516 a1.vWorldPosition.x = (double)pParty->vPosition.x; | |
1517 a1.vWorldPosition.y = (double)pParty->vPosition.y; | |
1518 v11 = (double)pParty->sEyelevel + (double)pParty->vPosition.z; | |
1519 goto LABEL_21; | |
1520 } | |
848 | 1521 v12 = (SpriteObject *)&pLevelDecorations[PID_ID(v6->field_4)]; |
0 | 1522 } |
1523 else | |
1524 { | |
848 | 1525 v12 = &pSpriteObjects[PID_ID(v6->field_4)]; |
0 | 1526 } |
1527 a1.vWorldPosition.x = (double)v12->vPosition.x; | |
1528 a1.vWorldPosition.y = (double)v12->vPosition.y; | |
1529 v11 = (double)v12->vPosition.z; | |
1530 LABEL_21: | |
1531 a1.vWorldPosition.z = v11; | |
1532 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) | |
1533 { | |
1534 v16 = pBLVRenderParams->fCosineNegX; | |
1535 v17 = pBLVRenderParams->fSineNegX; | |
1536 v55 = pBLVRenderParams->fCosineY; | |
1537 v56 = pBLVRenderParams->fSineY; | |
1538 if ( pBLVRenderParams->sPartyRotX ) | |
1539 { | |
1540 v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x; | |
1541 *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y; | |
1542 v18 = a1.vWorldPosition.z - (double)pParty->vPosition.z; | |
1543 if ( pRenderer->pRenderD3D ) | |
1544 { | |
1545 v19 = *(float *)&uNumRepeats * v56 + v58 * v55; | |
1546 v20 = v58 * v56 - *(float *)&uNumRepeats * v55; | |
1547 } | |
1548 else | |
1549 { | |
1550 v19 = v58 * v55 - *(float *)&uNumRepeats * v56; | |
1551 v20 = v58 * v56 + *(float *)&uNumRepeats * v55; | |
1552 } | |
1553 a1.vWorldViewPosition.x = v19 * v16 - v18 * v17; | |
1554 a1.vWorldViewPosition.y = v20; | |
1555 a1.vWorldViewPosition.z = v19 * v17 + v18 * v16; | |
1556 } | |
1557 else | |
1558 { | |
1559 v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x; | |
1560 *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y; | |
1561 if ( pRenderer->pRenderD3D ) | |
1562 { | |
1563 a1.vWorldViewPosition.x = *(float *)&uNumRepeats * v56 + v58 * v55; | |
1564 v21 = v58 * v56 - *(float *)&uNumRepeats * v55; | |
1565 } | |
1566 else | |
1567 { | |
1568 a1.vWorldViewPosition.x = v58 * v55 - *(float *)&uNumRepeats * v56; | |
1569 v21 = v58 * v56 + *(float *)&uNumRepeats * v55; | |
1570 } | |
1571 a1.vWorldViewPosition.y = v21; | |
1572 a1.vWorldViewPosition.z = a1.vWorldPosition.z - (double)pParty->vPosition.z; | |
1573 } | |
1574 } | |
1575 else | |
1576 { | |
1577 LABEL_31: | |
1578 pGame->pIndoorCameraD3D->ViewTransform(&a1, 1u); | |
1579 } | |
1580 v58 = a1.vWorldViewPosition.y * -0.012207031; | |
1581 v22 = a1.vWorldViewPosition.x * 0.012207031; | |
1582 *(float *)&uNumRepeats = v22; | |
1583 v23 = abs((signed __int64)v22); | |
1584 v24 = abs(0); | |
1585 v25 = abs((signed __int64)v58); | |
322 | 1586 if ( int_get_vector_length(v25, v24, v23) <= 100 ) |
0 | 1587 { |
1588 AIL_set_3D_position(v6->hSample, LODWORD(v58), 0.0, uNumRepeats); | |
1589 v26 = -*(float *)&uNumRepeats; | |
1590 v27 = -v58; | |
1591 AIL_set_3D_orientation(v6->hSample, LODWORD(v27), 0.0, LODWORD(v26), 0.0, 1.0, 0.0); | |
1592 } | |
1593 else | |
1594 { | |
1595 AIL_end_3D_sample(v6->hSample); | |
11 | 1596 pAudioPlayer->_4ABF23(v6); |
0 | 1597 } |
1598 goto LABEL_35; | |
1599 } | |
1600 } | |
378 | 1601 |
1602 | |
1603 | |
1604 | |
1605 | |
1606 | |
1607 | |
0 | 1608 LABEL_37: |
378 | 1609 for (uint i = 0; i < uMixerChannels; ++i) |
1610 { | |
1611 auto channel = pMixerChannels + i; | |
1612 | |
390 | 1613 if (AIL_sample_status(channel->hSample) == AIL::Sample::Done) |
1614 { | |
1615 AIL_end_sample(channel->hSample); | |
764 | 1616 FreeChannel(channel); |
390 | 1617 } |
378 | 1618 } |
1619 | |
1620 for (uint i = 0; i < uMixerChannels; ++i) | |
1621 { | |
1622 auto channel = pMixerChannels + i; | |
390 | 1623 if (channel->source_pid <= 0) |
1624 continue; | |
1625 | |
848 | 1626 int source_type = PID_TYPE(channel->source_pid), |
1627 source_id = PID_ID(channel->source_pid); | |
378 | 1628 int source_x, |
1629 source_y, | |
1630 source_z; | |
1631 | |
1632 switch (source_type) | |
1633 { | |
1634 case 0: | |
1635 case OBJECT_Player: | |
411 | 1636 case OBJECT_BModel: |
378 | 1637 continue; |
1638 | |
1639 case OBJECT_BLVDoor: | |
0 | 1640 { |
378 | 1641 assert(uCurrentlyLoadedLevelType == LEVEL_Indoor); |
1642 | |
1643 assert(source_id < pIndoor->uNumDoors); | |
1644 auto door = pIndoor->pDoors + source_id; | |
1645 if (!door->uDoorID) | |
1646 continue; | |
1647 | |
1648 source_x = door->pXOffsets[0]; | |
1649 source_y = door->pYOffsets[0]; | |
1650 source_z = door->pZOffsets[0]; | |
0 | 1651 } |
378 | 1652 break; |
1653 | |
1654 case OBJECT_Item: | |
379 | 1655 { |
515
cb0ad52d6a26
LayingItem -> SpriteObject (long-waited rename, old name was inaccurate and confused people)
Nomad
parents:
412
diff
changeset
|
1656 assert(source_id < uNumSpriteObjects); |
cb0ad52d6a26
LayingItem -> SpriteObject (long-waited rename, old name was inaccurate and confused people)
Nomad
parents:
412
diff
changeset
|
1657 auto object = &pSpriteObjects[source_id]; |
379 | 1658 |
1659 source_x = object->vPosition.x; | |
1660 source_y = object->vPosition.y; | |
1661 source_z = object->vPosition.z; | |
1662 } | |
1663 break; | |
1664 | |
378 | 1665 case OBJECT_Decoration: |
0 | 1666 { |
379 | 1667 assert(source_id < uNumLevelDecorations); |
515
cb0ad52d6a26
LayingItem -> SpriteObject (long-waited rename, old name was inaccurate and confused people)
Nomad
parents:
412
diff
changeset
|
1668 auto object = (SpriteObject *)&pLevelDecorations[source_id]; |
378 | 1669 |
1670 source_x = object->vPosition.x; | |
1671 source_y = object->vPosition.y; | |
1672 source_z = object->vPosition.z; | |
0 | 1673 } |
378 | 1674 break; |
1675 | |
1676 case OBJECT_Actor: | |
1677 { | |
1678 assert(source_id < uNumActors); | |
1679 auto actor = pActors + source_id; | |
1680 | |
1681 source_x = actor->vPosition.x; | |
1682 source_y = actor->vPosition.y; | |
1683 source_z = actor->vPosition.z; | |
1684 } | |
1685 break; | |
1686 | |
1687 default: | |
408 | 1688 assert(false); |
378 | 1689 continue; |
1690 } | |
1691 | |
1692 if (auto sound_strength = GetSoundStrengthByDistanceFromParty(source_x, source_y, source_z)) | |
1693 { | |
1694 AIL_set_sample_volume(channel->hSample, sound_strength); | |
1695 AIL_set_sample_pan(channel->hSample, sub_4AB66C(source_x, source_y)); | |
1696 } | |
1697 else | |
1698 { | |
1699 AIL_end_sample(channel->hSample); | |
764 | 1700 FreeChannel(channel); |
378 | 1701 } |
1702 } | |
1703 | |
1704 | |
379 | 1705 |
1706 if (pCurrentScreen != SCREEN_GAME) | |
1707 { | |
1708 auto channel = &pMixerChannels[4]; | |
1709 if (AIL_sample_status(channel->hSample) == AIL::Sample::Playing) | |
1710 AIL_end_sample(channel->hSample); | |
1711 return; | |
1712 } | |
1713 if (!_6807E0_num_decorations_with_sounds_6807B8) | |
1714 return; | |
1715 | |
378 | 1716 v55 = 0; |
379 | 1717 //v59 = 0; |
1718 for (uint i = 0; i < _6807E0_num_decorations_with_sounds_6807B8; ++i) | |
1719 { | |
1720 //while ( 1 ) | |
1721 //{ | |
0 | 1722 LODWORD(v56) = 1; |
379 | 1723 //v43 = _6807B8_level_decorations_ids[v59]; |
1724 //v44 = &pLevelDecorations[_6807B8_level_decorations_ids[v59]]; | |
1725 //v45 = abs(v44->vPosition.z - pParty->vPosition.z); | |
1726 //v46 = abs(v44->vPosition.y - pParty->vPosition.y); | |
1727 //v47 = abs(v44->vPosition.x - pParty->vPosition.x); | |
1728 auto decor = &pLevelDecorations[_6807B8_level_decorations_ids[i]]; | |
1729 if (int_get_vector_length(decor->vPosition.x - pParty->vPosition.x, | |
1730 decor->vPosition.y - pParty->vPosition.y, | |
1731 decor->vPosition.z - pParty->vPosition.z) > 8192) | |
1732 continue; | |
1733 | |
1734 auto decor_desc = &pDecorationList->pDecorations[decor->uDecorationDescID]; | |
1735 //v48 = &pDecorationList->pDecorations[decor->uDecorationDescID]; | |
1736 //v49 = v48->uFlags; | |
592 | 1737 uNumRepeats = (~(unsigned __int8)decor_desc->uFlags & DECORATION_SLOW_LOOP) >> 6; |
379 | 1738 |
1739 if (decor_desc->SoundOnDawn() || decor_desc->SoundOnDusk()) | |
1740 { | |
1741 //v50 = decor->field_1A; | |
0 | 1742 v55 = 0.0; |
1743 uNumRepeats = 2; | |
379 | 1744 if (decor->field_1A) |
0 | 1745 { |
379 | 1746 v51 = decor->field_1A - 32; |
1747 decor->field_1A = v51; | |
0 | 1748 if ( v51 < 0 ) |
379 | 1749 decor->field_1A = 0; |
0 | 1750 } |
379 | 1751 } |
1752 | |
1753 //v52 = v48->uFlags; | |
1754 if (!decor_desc->SoundOnDawn()) | |
1755 { | |
1756 if (!decor_desc->SoundOnDusk()) | |
1757 goto LABEL_84; | |
1758 if ( v55 != 0.0 ) | |
1759 goto LABEL_85; | |
1760 } | |
1761 v56 = 0.0; | |
1762 | |
1763 if (pParty->uCurrentHour >= 5 && pParty->uCurrentHour < 6 || | |
1764 pParty->uCurrentHour >= 20 && pParty->uCurrentHour < 21) | |
1765 { | |
1766 if ( !decor->field_1A && rand() % 100 < 100 ) | |
0 | 1767 LODWORD(v56) = 1; |
1768 LODWORD(v55) = 1; | |
379 | 1769 } |
0 | 1770 LABEL_84: |
1771 if ( v55 == 0.0 ) | |
1772 { | |
1773 LABEL_87: | |
1774 if ( v56 != 0.0 ) | |
1775 { | |
379 | 1776 v53 = 8 * _6807B8_level_decorations_ids[i]; |
1777 LOBYTE(v53) = v53 | OBJECT_Decoration; | |
1778 PlaySound((SoundID)decor_desc->uSoundID, v53, uNumRepeats, -1, 0, 0, 0, 0); | |
0 | 1779 } |
379 | 1780 continue; |
0 | 1781 } |
1782 LABEL_85: | |
379 | 1783 if ( !decor->field_1A ) |
1784 decor->field_1A = (rand() % 15 + 1) << 7; | |
0 | 1785 goto LABEL_87; |
379 | 1786 } |
0 | 1787 } |
1788 | |
1789 | |
1790 //----- (004AB66C) -------------------------------------------------------- | |
1791 int __fastcall sub_4AB66C(int a1, int a2) | |
1792 { | |
1793 signed int v2; // eax@1 | |
1794 | |
1795 v2 = stru_5C6E00->uDoublePiMask & (stru_5C6E00->Atan2(a1 - pParty->vPosition.x, a2 - pParty->vPosition.y) | |
147 | 1796 - stru_5C6E00->uIntegerHalfPi - pParty->sRotationY); |
0 | 1797 if ( v2 > (signed int)stru_5C6E00->uIntegerPi ) |
1798 v2 = 2 * stru_5C6E00->uIntegerPi - v2; | |
1799 return (v2 >> 3) - (v2 >> 10); | |
1800 } | |
1801 // 4AB66C: using guessed type int __fastcall sub_4AB66C(int, int); | |
1802 | |
1803 //----- (004AB6B1) -------------------------------------------------------- | |
1804 int __fastcall GetSoundStrengthByDistanceFromParty(int a1, int a2, int a3) | |
1805 { | |
1806 int v3; // esi@1 | |
1807 int v4; // edi@1 | |
1808 int v5; // ST08_4@1 | |
1809 int v6; // esi@1 | |
1810 int v7; // eax@1 | |
1811 int v9; // [sp+10h] [bp+8h]@1 | |
1812 | |
1813 v3 = a2; | |
1814 v4 = a1; | |
1815 v5 = abs(a3 - pParty->vPosition.z); | |
1816 v6 = abs(v3 - pParty->vPosition.y); | |
1817 v7 = abs(v4 - pParty->vPosition.x); | |
322 | 1818 v9 = int_get_vector_length(v7, v6, v5); |
0 | 1819 if ( v9 <= 8192 ) |
322 | 1820 return 114 - (unsigned __int64)(signed __int64)((double)v9 * 0.0001220703125 * 100.0); |
0 | 1821 else |
322 | 1822 return 0; |
0 | 1823 } |
1824 | |
1825 | |
1826 | |
1827 //----- (004AB71F) -------------------------------------------------------- | |
1828 void AudioPlayer::StopChannels(int uStartChannel, int uEndChannel) | |
1829 { | |
1830 //AudioPlayer *v3; // esi@1 | |
1831 int v4; // ecx@1 | |
82 | 1832 AudioPlayer_3DSample *v5; // edi@4 |
0 | 1833 int v6; // ebx@12 |
1834 MixerChannel *pChannel; // edi@14 | |
1835 //_STREAM *v8; // esi@23 | |
1836 int v9; // [sp+4h] [bp-4h]@3 | |
1837 | |
1838 //v3 = this; | |
1839 v4 = 0; | |
1840 if ( bPlayerReady ) | |
1841 { | |
1842 if ( b3DSoundInitialized ) | |
1843 { | |
1844 v9 = 0; | |
1845 if ( uNum3DSamples > 0 ) | |
1846 { | |
82 | 1847 v5 = p3DSamples;//;(char *)&p3DSamples[0].field_8; |
0 | 1848 do |
1849 { | |
1850 if ( (uStartChannel == -1 || v4 < uStartChannel || v4 > uEndChannel) | |
82 | 1851 && v5->field_8 |
1852 && pSoundList->pSounds[v5->field_8].eType != SOUND_DESC_SYSTEM) | |
0 | 1853 { |
82 | 1854 AIL_end_3D_sample(v5->hSample); |
1855 _4ABF23(v5); | |
1856 v5->field_4 = 0; | |
0 | 1857 v4 = v9; |
1858 } | |
1859 ++v4; | |
1860 v5 += 16; | |
1861 v9 = v4; | |
1862 } | |
1863 while ( v4 < uNum3DSamples ); | |
1864 } | |
1865 } | |
1866 v6 = 0; | |
1867 if ( hDigDriver && uMixerChannels > 0 ) | |
1868 { | |
1869 pChannel = pMixerChannels; | |
1870 do | |
1871 { | |
1872 if ( (uStartChannel == -1 || v6 < uStartChannel || v6 > uEndChannel) | |
1873 && pSoundList->pSounds[pChannel->uSourceTrackIdx].eType != SOUND_DESC_SYSTEM) | |
1874 { | |
1875 AIL_end_sample(pChannel->hSample); | |
764 | 1876 FreeChannel(pChannel); |
378 | 1877 pChannel->source_pid = 0; |
0 | 1878 } |
1879 ++v6; | |
1880 ++pChannel; | |
1881 } | |
1882 while (v6 < uMixerChannels); | |
1883 } | |
1884 if (hSequence) | |
1885 AIL_end_sequence(hSequence); | |
1886 //v8 = hStream; | |
1887 if (hStream) | |
1888 AIL_pause_stream(hStream, 1); | |
1889 } | |
1890 } | |
1891 | |
1892 | |
1893 //----- (004AB818) -------------------------------------------------------- | |
1894 void AudioPlayer::LoadAudioSnd() | |
1895 { | |
1896 DWORD NumberOfBytesRead; // [sp+Ch] [bp-4h]@3 | |
1897 | |
1898 hAudioSnd = CreateFileA("Sounds\\Audio.snd", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0x8000080u, 0); | |
1899 if (hAudioSnd == INVALID_HANDLE_VALUE) | |
1900 { | |
1901 Log::Warning(L"Can't open file: %s", L"Sounds\\Audio.snd"); | |
1902 return; | |
1903 } | |
1904 | |
1905 ReadFile(hAudioSnd, &uNumSoundHeaders, 4u, &NumberOfBytesRead, 0); | |
1906 pSoundHeaders = nullptr; | |
1907 pSoundHeaders = (SoundHeader *)pAllocator->AllocNamedChunk(0, 52 * uNumSoundHeaders + 2, 0); | |
1908 ReadFile(hAudioSnd, pSoundHeaders, 52 * uNumSoundHeaders, &NumberOfBytesRead, 0); | |
1909 } | |
1910 | |
1911 //----- (004AB8CE) -------------------------------------------------------- | |
1912 void AudioPlayer::Initialize(HWND hWnd) | |
1913 { | |
1914 //AudioPlayer *v2; // esi@1 | |
1915 int v3; // ebx@1 | |
1916 //_DIG_DRIVER *v4; // eax@1 | |
1917 char v5; // dl@5 | |
1918 _PROVIDER *v6; // eax@9 | |
1919 HWND v7; // ST00_4@9 | |
1920 MixerChannel *pChannel; // edi@14 | |
1921 _SAMPLE *v9; // eax@15 | |
1922 //_REDBOOK *v10; // eax@19 | |
1923 //int v11; // ecx@21 | |
1924 int v12; // [sp+Ch] [bp-Ch]@9 | |
1925 char *Str1; // [sp+10h] [bp-8h]@6 | |
1926 int v14; // [sp+14h] [bp-4h]@5 | |
1927 | |
1928 //v2 = this; | |
1929 v3 = 0; | |
1930 this->hWindow = hWnd; | |
1931 this->hAILRedbook = 0; | |
1932 this->hDigDriver = 0; | |
1933 this->dword_0002AC = 0; | |
1934 this->hSequence = 0; | |
1935 this->uMasterVolume = 127; | |
1936 this->dword_0002C8 = 64; | |
1937 this->dword_0002CC = 2; | |
1938 | |
1939 MSS32_DLL_Initialize(); | |
1940 BINKW32_DLL_Initialize(); | |
1941 SMACKW32_DLL_Initialize(); | |
1942 | |
1943 AIL_startup(); | |
1944 if (bCanLoadFromCD) | |
1945 hAILRedbook = AIL_redbook_open_drive(cMM7GameCDDriveLetter/*cGameCDDriveLetter*/); | |
1946 //else | |
1947 // hAILRedbook = AIL_redbook_open(0); | |
1948 //v4 = Audio_GetFirstHardwareDigitalDriver(); | |
1949 | |
1950 hDigDriver = Audio_GetFirstHardwareDigitalDriver(); | |
1951 if ( hDigDriver ) | |
1952 SmackSoundUseMSS(hDigDriver); | |
1953 if ( ReadWindowsRegistryInt("Disable3DSound", 0) != 1 && pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ) | |
1954 { | |
1955 v14 = 0; | |
1956 bEAXSupported = 0; | |
1957 b3DSoundInitialized = 0; | |
1958 ReadWindowsRegistryString("3DSoundProvider", p3DSoundProvider, 128u, "NONE"); | |
1959 CheckA3DSupport(v5); | |
1960 while ( AIL_enumerate_3D_providers(&v14, (HPROVIDER *)&hWnd, &Str1) ) | |
1961 { | |
1962 if ( !strcmp(Str1, p3DSoundProvider) ) | |
1963 { | |
1964 if ( AIL_open_3D_provider((HPROVIDER)hWnd) ) | |
1965 { | |
1966 bEAXSupported = 0; | |
1967 b3DSoundInitialized = 0; | |
1968 h3DSoundProvider = 0; | |
1969 } | |
1970 else | |
1971 { | |
1972 v6 = (_PROVIDER *)hWnd; | |
1973 v7 = hWnd; | |
1974 b3DSoundInitialized = 1; | |
1975 h3DSoundProvider = v6; | |
1976 uNum3DSamples = 4; | |
1977 AIL_3D_provider_attribute((HPROVIDER)v7, "EAX environment selection", &v12); | |
1978 if ( v12 != -1 ) | |
1979 bEAXSupported = 1; | |
1980 } | |
1981 pAudioPlayer->_4AC0A2(); | |
1982 break; | |
1983 } | |
1984 } | |
1985 } | |
1986 if ( uMixerChannels > 0 ) | |
1987 { | |
1988 pChannel = pMixerChannels; | |
1989 do | |
1990 { | |
1991 v9 = AIL_allocate_sample_handle(hDigDriver); | |
1992 pChannel->hSample = v9; | |
1993 if ( !v9 ) | |
1994 break; | |
1995 ++v3; | |
1996 ++pChannel; | |
1997 } | |
1998 while ( v3 < uMixerChannels ); | |
1999 } | |
2000 uMixerChannels = v3; | |
2001 if ( bPlayerReady ) | |
2002 StopChannels(-1, -1); | |
2003 //v10 = hAILRedbook; | |
2004 bPlayerReady = true; | |
2005 if ( hAILRedbook ) | |
2006 { | |
2007 AIL_redbook_stop(hAILRedbook); | |
2008 uNumRedbookTracks = AIL_redbook_tracks(hAILRedbook); | |
2009 } | |
2010 pAudioPlayer->sRedbookVolume = AIL_redbook_volume(hAILRedbook); | |
328 | 2011 pAudioPlayer->SetMasterVolume(pSoundVolumeLevels[uSoundVolumeMultiplier] * 128.0f); |
0 | 2012 if ( bPlayerReady && hAILRedbook ) |
328 | 2013 AIL_redbook_set_volume(hAILRedbook, (unsigned __int64)(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f) >> 32); |
0 | 2014 LoadAudioSnd(); |
2015 } | |
2016 | |
2017 //----- (004ABAF7) -------------------------------------------------------- | |
2018 _DIG_DRIVER *Audio_GetFirstHardwareDigitalDriver(void) | |
2019 { | |
2020 int v0; // ecx@1 | |
2021 unsigned int v1; // ebp@2 | |
2022 size_t v2; // eax@4 | |
2023 signed int v3; // kr14_4@9 | |
2024 char *v5; // [sp+10h] [bp-Ch]@2 | |
2025 unsigned int v6; // [sp+14h] [bp-8h]@1 | |
2026 _DIG_DRIVER *hDrv; // [sp+18h] [bp-4h]@3 | |
2027 | |
2028 static int dword_4F00DC = 22050; | |
2029 static int dword_4F00E0 = 16; | |
2030 static int dword_4F00E4 = 2; | |
2031 | |
2032 AIL_set_preference(15, 0); | |
2033 AIL_set_preference(33, 1); | |
2034 v0 = dword_4F00DC; | |
2035 pAudioPlayer->pDeviceNames[0][0] = 0; | |
2036 pAudioPlayer->uNumDevices = 0; | |
2037 v6 = 0; | |
2038 | |
2039 if ( dword_4F00DC < 11025 ) | |
2040 return 0; | |
2041 v1 = 0; | |
2042 v5 = (char *)pAudioPlayer->array_000BF0; | |
2043 while ( 1 ) | |
2044 { | |
2045 while ( 1 ) | |
2046 { | |
2047 pcmWaveFormat.wf.wFormatTag = 1; | |
2048 pcmWaveFormat.wf.nChannels = dword_4F00E4; | |
2049 pcmWaveFormat.wf.nSamplesPerSec = v0; | |
2050 pcmWaveFormat.wf.nBlockAlign = dword_4F00E4 * dword_4F00E0 / 8; | |
2051 pcmWaveFormat.wBitsPerSample = dword_4F00E0; | |
2052 pcmWaveFormat.wf.nAvgBytesPerSec = v0 * dword_4F00E4 * dword_4F00E0 / 8; | |
2053 if ( !AIL_waveOutOpen(&hDrv, 0, -1, &pcmWaveFormat.wf) ) | |
2054 break; | |
2055 if ( !AIL_get_preference(15) ) | |
2056 goto LABEL_8; | |
2057 v3 = dword_4F00DC; | |
2058 v0 = dword_4F00DC / 2; | |
2059 dword_4F00DC /= 2; | |
2060 if ( v3 / 2 < 11025 ) | |
2061 { | |
2062 if ( dword_4F00E0 == 8 ) | |
2063 { | |
2064 v0 = 22050; | |
2065 dword_4F00E0 = 8; | |
2066 dword_4F00DC = 22050; | |
2067 } | |
2068 goto LABEL_12; | |
2069 } | |
2070 } | |
2071 strcpy(pAudioPlayer->pDeviceNames[v1 / 8], "Device: "); | |
2072 v2 = strlen(pAudioPlayer->pDeviceNames[v1 / 8]); | |
2073 AIL_digital_configuration(hDrv, (int *)v5, (int *)(v5 + 64), (char *)pAudioPlayer->pDeviceNames + v2 + v1 * 16); | |
2074 ++v6; | |
2075 v1 += 8; | |
2076 v5 += 4; | |
2077 pAudioPlayer->uNumDevices = v6; | |
2078 if ( AIL_get_preference(15) ) | |
2079 return hDrv; | |
2080 if ( !strstr(pAudioPlayer->pDeviceNames[v1 / 8 - 1], "Emulated") ) | |
2081 return hDrv; | |
2082 AIL_waveOutClose(hDrv); | |
2083 AIL_set_preference(15, 1); | |
2084 LABEL_8: | |
2085 AIL_set_preference(15, 1); | |
2086 v0 = dword_4F00DC; | |
2087 LABEL_12: | |
2088 if ( v0 < 11025 ) | |
2089 return 0; | |
2090 } | |
2091 } | |
2092 | |
2093 | |
2094 //----- (004ABC9B) -------------------------------------------------------- | |
2095 LSTATUS AudioPlayer::CheckA3DSupport(char a2) | |
2096 { | |
2097 LSTATUS result; // eax@1 | |
2098 DWORD cbData; // [sp+8h] [bp-Ch]@1 | |
2099 int Data; // [sp+Ch] [bp-8h]@1 | |
2100 HKEY hKey; // [sp+10h] [bp-4h]@1 | |
2101 char v6; // [sp+1Ch] [bp+8h]@0 | |
222 | 2102 v6=0; //to fix |
0 | 2103 hKey = 0; |
2104 cbData = 4; | |
2105 Data = 0; | |
2106 result = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Aureal\\A3D", 0, 0x2001Fu, &hKey); | |
2107 if ( !result ) | |
2108 { | |
2109 if ( v6 ) | |
2110 RegQueryValueExA(hKey, "SplashAudio", 0, 0, (LPBYTE)&Aureal3D_SplashAudio, &cbData); | |
2111 else | |
2112 Data = Aureal3D_SplashAudio; | |
2113 RegSetValueExA(hKey, "SplashAudio", 0, 4u, (const BYTE *)&Data, 4u); | |
2114 Data = 0; | |
2115 if ( v6 ) | |
2116 RegQueryValueExA(hKey, "SplashScreen", 0, 0, (LPBYTE)&Aureal3D_SplashScreen, &cbData); | |
2117 else | |
2118 Data = Aureal3D_SplashScreen; | |
2119 RegSetValueExA(hKey, "SplashScreen", 0, 4u, (const BYTE *)&Data, 4u); | |
2120 result = RegCloseKey(hKey); | |
2121 } | |
2122 return result; | |
2123 } | |
2124 // 4ABC9B: inconsistent function type and number of purged bytes | |
2125 | |
2126 //----- (004ABD5B) -------------------------------------------------------- | |
4 | 2127 void AudioPlayer::Release() //Освободить |
0 | 2128 { |
4 | 2129 AudioPlayer *pAudioPlayer; // esi@1 |
0 | 2130 int v2; // edi@1 |
4 | 2131 MixerChannel *pMixerChannel; // ebx@3 |
0 | 2132 char v4; // dl@5 |
2133 int v5; // ebx@6 | |
4 | 2134 AudioPlayer_3DSample *p3DSample; // edi@7 |
24 | 2135 //int v7; // edx@14 |
0 | 2136 int v8; // ecx@14 |
2137 void *v9; // ecx@15 | |
2138 | |
4 | 2139 pAudioPlayer = this; |
0 | 2140 v2 = 0; |
2141 if ( this->bPlayerReady ) | |
2142 { | |
2143 CloseHandle(pVideoPlayer->hMagicVid); | |
2144 CloseHandle(pVideoPlayer->hMightVid); | |
4 | 2145 pAudioPlayer->StopChannels(-1, -1); |
2146 if ( pAudioPlayer->uMixerChannels > 0 ) | |
0 | 2147 { |
4 | 2148 pMixerChannel = pAudioPlayer->pMixerChannels; |
0 | 2149 do |
2150 { | |
4 | 2151 AIL_release_sample_handle(pMixerChannel->hSample); |
0 | 2152 ++v2; |
4 | 2153 ++pMixerChannel; |
0 | 2154 } |
4 | 2155 while ( v2 < pAudioPlayer->uMixerChannels ); |
0 | 2156 } |
2157 if ( ReadWindowsRegistryInt("Disable3DSound", 0) != 1 ) | |
2158 { | |
2159 v5 = 0; | |
24 | 2160 pAudioPlayer->CheckA3DSupport(0);// pAudioPlayer->CheckA3DSupport(v4); |
4 | 2161 if ( pAudioPlayer->uNum3DSamples > 0 ) |
0 | 2162 { |
4 | 2163 p3DSample = pAudioPlayer->p3DSamples; |
0 | 2164 do |
2165 { | |
4 | 2166 if ( p3DSample->hSample ) |
0 | 2167 { |
4 | 2168 AIL_release_3D_sample_handle(p3DSample->hSample); |
2169 p3DSample->hSample = 0; | |
0 | 2170 } |
2171 ++v5; | |
4 | 2172 ++p3DSample; |
0 | 2173 } |
4 | 2174 while ( v5 < pAudioPlayer->uNum3DSamples ); |
0 | 2175 } |
4 | 2176 if ( pAudioPlayer->h3DSoundProvider ) |
0 | 2177 { |
4 | 2178 AIL_close_3D_provider(pAudioPlayer->h3DSoundProvider); |
2179 pAudioPlayer->h3DSoundProvider = 0; | |
0 | 2180 } |
2181 } | |
24 | 2182 v8 = (int)&pAudioPlayer->hAILRedbook; |
4 | 2183 if ( pAudioPlayer->hAILRedbook ) |
0 | 2184 { |
4 | 2185 AIL_redbook_stop(pAudioPlayer->hAILRedbook); |
24 | 2186 AIL_redbook_set_volume((HREDBOOK)v8, pAudioPlayer->sRedbookVolume); |
4 | 2187 AIL_redbook_close(pAudioPlayer->hAILRedbook); |
0 | 2188 } |
2189 AIL_shutdown(); | |
2190 pSoundList->Release(); | |
4 | 2191 v9 = *(void **)&pAudioPlayer->field_C78[0]; |
0 | 2192 if ( v9 ) |
2193 ReleaseSoundData(v9); | |
4 | 2194 CloseHandle(pAudioPlayer->hAudioSnd); |
0 | 2195 } |
2196 } | |
2197 | |
2198 //----- (004ABE55) -------------------------------------------------------- | |
764 | 2199 void AudioPlayer::FreeChannel(MixerChannel *pChannel) |
0 | 2200 { |
2201 int v2; // ebx@1 | |
2202 //AudioPlayer *v3; // esi@1 | |
2203 SoundDesc *v4; // eax@2 | |
2204 unsigned __int8 v5; // zf@5 | |
2205 unsigned __int8 v6; // sf@5 | |
2206 char *v7; // edi@6 | |
764 | 2207 int num_same_sound_on_channels; // eax@8 |
0 | 2208 int v9; // ST04_4@8 |
2209 int v10; // ecx@12 | |
2210 int v11; // edi@13 | |
2211 int v12; // eax@13 | |
2212 unsigned __int8 v13; // of@13 | |
2213 int v14[16]; // [sp+Ch] [bp-48h]@8 | |
764 | 2214 int num_playing_channels; // [sp+4Ch] [bp-8h]@5 |
0 | 2215 int v16; // [sp+50h] [bp-4h]@5 |
2216 | |
2217 v2 = 0; | |
2218 //v3 = this; | |
390 | 2219 if (!pSoundList->pSounds) |
2220 return; | |
2221 | |
0 | 2222 v4 = &pSoundList->pSounds[pChannel->uSourceTrackIdx]; |
764 | 2223 if ( pSoundList->pSounds[pChannel->uSourceTrackIdx].eType == SOUND_DESC_SWAP) |
0 | 2224 { |
764 | 2225 if ( pSoundList->pSounds[pChannel->uSourceTrackIdx].pSoundData[0] && |
2226 !(pSoundList->pSounds[pChannel->uSourceTrackIdx].uFlags & SOUND_DESC_SYSTEM) ) | |
0 | 2227 { |
764 | 2228 num_playing_channels = 0; |
2229 num_same_sound_on_channels = 0; | |
2230 if ( this->uMixerChannels <=0 ) | |
0 | 2231 goto LABEL_16; |
2232 do | |
2233 { | |
764 | 2234 if ( pChannel->uSourceTrackID ==pMixerChannels[v2].uSourceTrackID ) |
0 | 2235 { |
764 | 2236 v14[num_same_sound_on_channels++] = v2; |
2237 if ( AIL_sample_status((HSAMPLE)pMixerChannels[v2].hSample) == AIL::Sample::Playing) | |
2238 ++num_playing_channels; | |
0 | 2239 } |
2240 ++v2; | |
2241 } | |
2242 while ( v2 < uMixerChannels ); | |
764 | 2243 if ( !num_playing_channels ) |
0 | 2244 { |
2245 LABEL_16: | |
764 | 2246 pSoundList->UnloadSound(pChannel->uSourceTrackIdx, 1); |
0 | 2247 v10 = 0; |
764 | 2248 if ( num_same_sound_on_channels > 0 ) |
0 | 2249 { |
2250 do | |
2251 { | |
2252 v11 = v14[v10]; | |
764 | 2253 v10++; |
0 | 2254 pMixerChannels[v11].uSourceTrackID = 0; |
764 | 2255 pMixerChannels[v11].hSample = NULL; |
0 | 2256 } |
764 | 2257 while (v10<num_same_sound_on_channels); |
0 | 2258 } |
2259 } | |
2260 } | |
2261 } | |
2262 } | |
2263 | |
2264 | |
2265 | |
2266 //----- (004AAEA6) -------------------------------------------------------- | |
2267 int __fastcall sub_4AAEA6_transform(RenderVertexSoft *a1) | |
2268 { | |
2269 double v1; // st7@1 | |
2270 double v2; // st6@1 | |
2271 int result; // eax@1 | |
2272 double v4; // st5@2 | |
2273 double v5; // st4@3 | |
2274 double v6; // st3@3 | |
2275 double v7; // st7@6 | |
2276 double v8; // st6@7 | |
2277 float v9; // [sp+0h] [bp-10h]@1 | |
2278 float v10; // [sp+4h] [bp-Ch]@1 | |
2279 float v11; // [sp+8h] [bp-8h]@2 | |
2280 float v12; // [sp+8h] [bp-8h]@6 | |
2281 float v13; // [sp+Ch] [bp-4h]@2 | |
2282 float v14; // [sp+Ch] [bp-4h]@6 | |
2283 | |
2284 v1 = pBLVRenderParams->fCosineNegX; | |
2285 v2 = pBLVRenderParams->fSineNegX; | |
2286 v9 = pBLVRenderParams->fCosineY; | |
2287 v10 = pBLVRenderParams->fSineY; | |
2288 result = 0; | |
2289 if ( pBLVRenderParams->sPartyRotX ) | |
2290 { | |
2291 v13 = a1->vWorldPosition.x - (double)pParty->vPosition.x; | |
2292 v11 = a1->vWorldPosition.y - (double)pParty->vPosition.y; | |
2293 v4 = a1->vWorldPosition.z - (double)pParty->vPosition.z; | |
2294 if ( pRenderer->pRenderD3D ) | |
2295 { | |
2296 v5 = v11 * pBLVRenderParams->fSineY + v13 * pBLVRenderParams->fCosineY; | |
2297 v6 = v13 * pBLVRenderParams->fSineY - v11 * pBLVRenderParams->fCosineY; | |
2298 } | |
2299 else | |
2300 { | |
2301 v5 = v13 * pBLVRenderParams->fCosineY - v11 * pBLVRenderParams->fSineY; | |
2302 v6 = v13 * pBLVRenderParams->fSineY + v11 * pBLVRenderParams->fCosineY; | |
2303 } | |
2304 a1->vWorldViewPosition.x = v5 * v1 - v4 * v2; | |
2305 a1->vWorldViewPosition.y = v6; | |
2306 a1->vWorldViewPosition.z = v5 * v2 + v4 * v1; | |
2307 } | |
2308 else | |
2309 { | |
2310 v14 = a1->vWorldPosition.x - (double)pParty->vPosition.x; | |
2311 v12 = a1->vWorldPosition.y - (double)pParty->vPosition.y; | |
2312 v7 = a1->vWorldPosition.z - (double)pParty->vPosition.z; | |
2313 if ( pRenderer->pRenderD3D ) | |
2314 { | |
2315 a1->vWorldViewPosition.x = v12 * pBLVRenderParams->fSineY + v14 * pBLVRenderParams->fCosineY; | |
2316 v8 = v14 * v10 - v12 * v9; | |
2317 } | |
2318 else | |
2319 { | |
2320 a1->vWorldViewPosition.x = v14 * pBLVRenderParams->fCosineY - v12 * pBLVRenderParams->fSineY; | |
2321 v8 = v14 * v10 + v12 * v9; | |
2322 } | |
2323 a1->vWorldViewPosition.y = v8; | |
2324 a1->vWorldViewPosition.z = v7; | |
2325 } | |
2326 return result; | |
2327 } | |
2328 | |
2329 | |
2330 | |
2331 | |
2332 //----- (004ABF23) -------------------------------------------------------- | |
2333 void AudioPlayer::_4ABF23(AudioPlayer_3DSample *a2) | |
2334 { | |
2335 int v2; // ebx@1 | |
2336 //AudioPlayer *v3; // esi@1 | |
2337 SoundDesc *v4; // eax@2 | |
2338 unsigned __int8 v5; // zf@5 | |
2339 unsigned __int8 v6; // sf@5 | |
2340 char *v7; // edi@6 | |
2341 int v8; // eax@8 | |
2342 int v9; // ST04_4@8 | |
2343 int v10; // ecx@12 | |
2344 int v11; // eax@13 | |
2345 unsigned __int8 v12; // of@13 | |
2346 int v13[16]; // [sp+Ch] [bp-48h]@8 | |
2347 int v14; // [sp+4Ch] [bp-8h]@5 | |
2348 int v15; // [sp+50h] [bp-4h]@5 | |
2349 | |
2350 v2 = 0; | |
2351 //v3 = this; | |
2352 if ( pSoundList->pSounds ) | |
2353 { | |
2354 v4 = &pSoundList->pSounds[a2->field_8]; | |
2355 if ( v4->eType == SOUND_DESC_SWAP) | |
2356 { | |
592 | 2357 if ( v4->p3DSound && !(v4->uFlags & SOUND_DESC_SYSTEM) ) |
0 | 2358 { |
2359 v5 = this->uNum3DSamples == 0; | |
2360 v6 = this->uNum3DSamples < 0; | |
2361 v14 = 0; | |
2362 v15 = 0; | |
2363 if ( v6 | v5 ) | |
2364 goto LABEL_16; | |
2365 v7 = (char *)this->p3DSamples; | |
2366 do | |
2367 { | |
2368 if ( a2->field_C == *((int *)v7 + 3) ) | |
2369 { | |
2370 v8 = v15; | |
2371 v9 = *(int *)v7; | |
2372 ++v15; | |
2373 v13[v8] = v2; | |
2374 if ( AIL_3D_sample_status((void *)v9) == 4 ) | |
2375 ++v14; | |
2376 } | |
2377 ++v2; | |
2378 v7 += 16; | |
2379 } | |
2380 while ( v2 < uNum3DSamples ); | |
2381 if ( !v14 ) | |
2382 { | |
2383 LABEL_16: | |
764 | 2384 pSoundList->UnloadSound(a2->field_8, 1); |
0 | 2385 v10 = 0; |
2386 if ( v15 > 0 ) | |
2387 { | |
2388 do | |
2389 { | |
2390 v11 = v13[v10++]; | |
2391 *(&bEAXSupported + 4 * (v11 + 2)) = 0; | |
2392 v12 = __OFSUB__(v10, v15); | |
2393 v6 = v10 - v15 < 0; | |
2394 p3DSamples[v11].field_8 = 0; | |
2395 } | |
2396 while ( v6 ^ v12 ); | |
2397 } | |
2398 } | |
2399 } | |
2400 } | |
2401 } | |
2402 } | |
2403 // 4D82F4: using guessed type int __stdcall AIL_3D_sample_status(int); | |
2404 // 4ABF23: using guessed type int var_48[16]; | |
2405 | |
2406 //----- (004ABFDB) -------------------------------------------------------- | |
2407 void __cdecl PlayLevelMusic() | |
2408 { | |
2409 unsigned int v0; // eax@1 | |
2410 | |
2411 v0 = pMapStats->GetMapInfo(pCurrentMapName); | |
2412 if ( v0 ) | |
2413 pAudioPlayer->PlayMusicTrack((MusicID)pMapStats->pInfos[v0].uRedbookTrackID); | |
2414 } | |
2415 | |
2416 //----- (004AC004) -------------------------------------------------------- | |
2417 void AudioPlayer::SetEAXPreferences() | |
2418 { | |
2419 AudioPlayer *v1; // edi@1 | |
2420 _PROVIDER *v2; // ST00_4@2 | |
2421 _PROVIDER *v3; // ST00_4@2 | |
2422 float v4; // [sp+4h] [bp-4h]@2 | |
2423 | |
2424 v1 = this; | |
2425 if ( this->bEAXSupported ) | |
2426 { | |
2427 v2 = this->h3DSoundProvider; | |
2428 v4 = 0.0; | |
2429 AIL_set_3D_provider_preference(v2, "EAX effect volume", (int *)&v4); | |
2430 v3 = v1->h3DSoundProvider; | |
2431 v4 = 1.0; | |
2432 AIL_set_3D_provider_preference(v3, "EAX damping", (int *)&v4); | |
2433 } | |
2434 } | |
2435 // 4D82DC: using guessed type int __stdcall AIL_set_3D_provider_preference(int, int, int); | |
2436 | |
2437 //----- (004AC041) -------------------------------------------------------- | |
2438 void AudioPlayer::SetMapEAX() | |
2439 { | |
2440 AudioPlayer *v1; // esi@1 | |
2441 unsigned int v2; // eax@1 | |
2442 int v3; // [sp+4h] [bp-4h]@3 | |
2443 | |
2444 v1 = this; | |
2445 v2 = pMapStats->GetMapInfo(pCurrentMapName); | |
2446 if ( v1->b3DSoundInitialized && v1->bEAXSupported ) | |
2447 { | |
2448 v3 = pMapStats->pInfos[v2].uEAXEnv; | |
2449 if ( (unsigned int)v3 >= 0x1A ) | |
2450 { | |
2451 SetEAXPreferences(); | |
2452 v1->field_214 = -1; | |
2453 } | |
2454 else | |
2455 { | |
2456 AIL_set_3D_provider_preference(v1->h3DSoundProvider, "EAX environment selection", &v3); | |
2457 v1->field_214 = v3; | |
2458 } | |
2459 } | |
2460 } | |
2461 // 4D82DC: using guessed type int __stdcall AIL_set_3D_provider_preference(int, int, int); | |
2462 | |
2463 //----- (004AC0A2) -------------------------------------------------------- | |
2464 int AudioPlayer::_4AC0A2() | |
2465 { | |
2466 AudioPlayer *v1; // esi@1 | |
2467 unsigned int v2; // eax@1 | |
2468 char v3; // zf@1 | |
2469 int v4; // ebx@1 | |
2470 int *v5; // edi@2 | |
2471 int v6; // eax@4 | |
2472 AudioPlayer_3DSample *v8; // ebx@7 | |
2473 void *v9; // eax@8 | |
2474 int v10; // ebx@14 | |
2475 unsigned int v11; // eax@14 | |
2476 int v12; // [sp+1Ch] [bp-8h]@1 | |
2477 int v13; // [sp+20h] [bp-4h]@6 | |
2478 | |
2479 v1 = this; | |
2480 v2 = pMapStats->GetMapInfo(pCurrentMapName); | |
2481 v3 = v1->b3DSoundInitialized == 0; | |
2482 v4 = v2; | |
2483 v12 = v2; | |
2484 if ( !v3 ) | |
2485 { | |
2486 v5 = &v1->uNum3DSamples; | |
2487 AIL_3D_provider_attribute(v1->h3DSoundProvider, "Maximum supported samples", &v1->uNum3DSamples); | |
2488 if ( v1->uNum3DSamples > 32 ) | |
2489 *v5 = 32; | |
2490 v6 = *v5; | |
2491 if ( !*v5 ) | |
2492 { | |
2493 v1->b3DSoundInitialized = 0; | |
2494 return -1; | |
2495 } | |
2496 v13 = 0; | |
2497 if ( v6 > 0 ) | |
2498 { | |
2499 v8 = v1->p3DSamples; | |
2500 while ( 1 ) | |
2501 { | |
2502 v9 = (void *)AIL_allocate_3D_sample_handle(v1->h3DSoundProvider); | |
2503 v8->hSample = v9; | |
2504 if ( !v9 ) | |
2505 break; | |
2506 AIL_set_3D_sample_float_distances(v9, 4096.0, 256.0, 4096.0, 256.0); | |
2507 AIL_set_3D_sample_volume(v8->hSample, v1->s3DSoundVolume); | |
2508 ++v13; | |
2509 ++v8; | |
2510 if ( v13 >= *v5 ) | |
2511 goto LABEL_12; | |
2512 } | |
2513 *v5 = v13; | |
2514 LABEL_12: | |
2515 v4 = v12; | |
2516 } | |
2517 if ( v1->bEAXSupported ) | |
2518 { | |
2519 v10 = v4; | |
2520 v11 = pMapStats->pInfos[v10].uEAXEnv; | |
2521 v12 = pMapStats->pInfos[v10].uEAXEnv; | |
2522 if ( v11 >= 0x1A ) | |
2523 { | |
2524 pAudioPlayer->SetEAXPreferences(); | |
2525 v1->field_214 = -1; | |
2526 } | |
2527 else | |
2528 { | |
2529 AIL_set_3D_provider_preference(v1->h3DSoundProvider, "EAX environment selection", &v12); | |
2530 v1->field_214 = v12; | |
2531 } | |
2532 } | |
2533 } | |
2534 return 1; | |
2535 } | |
2536 | |
2537 | |
2538 //----- (004A96BE) -------------------------------------------------------- | |
2539 void ReleaseSoundData(void *_this) | |
2540 { | |
24 | 2541 int pID; // esi@1 |
0 | 2542 char *v2; // eax@1 |
2543 | |
24 | 2544 pID = 0; |
0 | 2545 v2 = (char *)&pSounds[0].pSoundData; |
2546 while ( *(void **)v2 != _this ) | |
2547 { | |
2548 v2 += 128; | |
24 | 2549 ++pID; |
28 | 2550 if ( v2 > (void *)&pSounds[2999].pSoundData)//(signed int)&pAudioPlayer->p3DSamples[6].field_8 ) |
0 | 2551 return; |
2552 } | |
2553 pAllocator->FreeChunk(_this); | |
24 | 2554 memset(&pSounds[pID], 0, 0x80u); |
0 | 2555 } |
2556 | |
2557 //----- (004A96FF) -------------------------------------------------------- | |
2558 SoundHeader *__fastcall FindSound_BinSearch(unsigned int uStart, unsigned int uEnd, const char *pName) | |
2559 { | |
2560 unsigned int v3; // ebx@1 | |
2561 unsigned int v4; // esi@1 | |
2562 SoundHeader *result; // eax@2 | |
2563 signed int v6; // ebx@11 | |
2564 int v7; // edi@13 | |
2565 unsigned int v8; // esi@14 | |
2566 unsigned int v9; // esi@20 | |
2567 unsigned int v10; // [sp+Ch] [bp-4h]@1 | |
2568 | |
2569 v3 = uEnd; | |
2570 v10 = uEnd; | |
2571 v4 = uStart; | |
2572 while ( 1 ) | |
2573 { | |
2574 v6 = v3 - v4; | |
2575 result = &pAudioPlayer->pSoundHeaders[v6 / 2 + v4]; | |
2576 if ( !result ) | |
2577 return result; | |
2578 result = (SoundHeader *)_strcmpi(pName, result->pSoundName); | |
2579 if ( !result ) | |
2580 uFindSound_BinSearch_ResultID = v6 / 2 + v4; | |
2581 if ( v4 == v10 ) | |
2582 goto LABEL_17; | |
2583 if ( (signed int)result < 0 ) | |
2584 break; | |
2585 if ( v6 <= 4 ) | |
2586 { | |
2587 v7 = v4; | |
2588 if ( (signed int)v4 < (signed int)v10 ) | |
2589 { | |
2590 v9 = v4; | |
2591 do | |
2592 { | |
2593 result = (SoundHeader *)_strcmpi(pName, pAudioPlayer->pSoundHeaders[v9].pSoundName); | |
2594 if ( !result ) | |
2595 goto LABEL_24; | |
2596 ++v7; | |
2597 ++v9; | |
2598 } | |
2599 while ( v7 < (signed int)v10 ); | |
2600 } | |
2601 LABEL_17: | |
2602 uFindSound_BinSearch_ResultID = -1; | |
2603 return result; | |
2604 } | |
2605 v4 += v6 / 2; | |
2606 LABEL_10: | |
2607 v3 = v10; | |
2608 } | |
2609 if ( v6 > 4 ) | |
2610 { | |
2611 v10 = v6 / 2 + v4; | |
2612 goto LABEL_10; | |
2613 } | |
2614 v7 = v4; | |
2615 if ( (signed int)v4 >= (signed int)v10 ) | |
2616 goto LABEL_17; | |
2617 v8 = v4; | |
2618 while ( 1 ) | |
2619 { | |
2620 result = (SoundHeader *)_strcmpi(pName, pAudioPlayer->pSoundHeaders[v8].pSoundName); | |
2621 if ( !result ) | |
2622 break; | |
2623 ++v7; | |
2624 ++v8; | |
2625 if ( v7 >= (signed int)v10 ) | |
2626 goto LABEL_17; | |
2627 } | |
2628 LABEL_24: | |
2629 uFindSound_BinSearch_ResultID = v7; | |
2630 return result; | |
2631 } | |
2632 // F1B4C8: using guessed type int uFindSound_BinSearch_ResultID; | |
2633 | |
2634 //----- (004A97C6) -------------------------------------------------------- | |
2635 SoundData *LoadSound(const char *pSoundName, SoundData *pOutBuff, unsigned int uID) | |
2636 { | |
2637 SoundData *v3; // edi@1 | |
2638 int v4; // ecx@1 | |
2639 //Sound *v5; // eax@1 | |
2640 SoundHeader *v6; // esi@5 | |
2641 unsigned int *pDecompressedSize; // ebx@5 | |
2642 unsigned int v8; // eax@5 | |
2643 unsigned int v9; // eax@7 | |
2644 SoundData *result; // eax@9 | |
2645 int v11; // esi@15 | |
2646 int v12; // eax@15 | |
2647 char *v13; // ecx@16 | |
2648 int v14; // eax@19 | |
2649 std::string v15; // [sp-18h] [bp-34h]@12 | |
2650 const char *v16; // [sp-8h] [bp-24h]@12 | |
2651 int v17; // [sp-4h] [bp-20h]@12 | |
2652 char v18; // [sp+Ch] [bp-10h]@12 | |
2653 int v19; // [sp+10h] [bp-Ch]@5 | |
2654 DWORD NumberOfBytesRead; // [sp+14h] [bp-8h]@8 | |
2655 const char *pSoundName_; // [sp+18h] [bp-4h]@1 | |
2656 | |
2657 pSoundName_ = pSoundName; | |
2658 v3 = pOutBuff; | |
2659 v4 = 0; | |
2660 for (uint i = 0; i < 3000; ++i) | |
764 | 2661 { |
2662 if (pSounds[i].uID == uID) | |
2663 return pSounds[i].pSoundData; | |
2664 } | |
0 | 2665 FindSound_BinSearch(0, pAudioPlayer->uNumSoundHeaders, pSoundName_); |
2666 if ( uFindSound_BinSearch_ResultID == -1 ) | |
24 | 2667 { |
2668 result = 0; | |
2669 return result; | |
2670 } | |
0 | 2671 v6 = &pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID]; |
2672 pDecompressedSize = &v6->uDecompressedSize; | |
2673 v8 = v6->uDecompressedSize; | |
2674 v19 = v6->uDecompressedSize; | |
2675 if ( v3 == (SoundData *)-1 ) | |
2676 v3 = (SoundData *)pAllocator->AllocNamedChunk(0, v8 + 4, pSoundName_); | |
2677 SetFilePointer(pAudioPlayer->hAudioSnd, v6->uFileOffset, 0, 0); | |
2678 v9 = *pDecompressedSize; | |
2679 if ( (signed int)v6->uCompressedSize >= (signed int)*pDecompressedSize ) | |
2680 { | |
2681 v6->uCompressedSize = v9; | |
2682 if ( v9 ) | |
2683 { | |
2684 ReadFile(pAudioPlayer->hAudioSnd, (char *)v3 + 4, v9, &NumberOfBytesRead, 0); | |
2685 } | |
2686 else | |
2687 { | |
2688 MessageBoxW(nullptr, L"Can't load sound file!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Sound.cpp:448", 0); | |
2689 } | |
2690 } | |
2691 else | |
2692 { | |
2693 uID = (unsigned int)malloc(v6->uCompressedSize); | |
2694 ReadFile(pAudioPlayer->hAudioSnd, (LPVOID)uID, v6->uCompressedSize, &NumberOfBytesRead, 0); | |
2695 zlib::MemUnzip((char *)v3 + 4, &v6->uDecompressedSize, (const void *)uID, v6->uCompressedSize); | |
2696 free((void *)uID); | |
2697 } | |
2698 if ( v3 ) | |
2699 { | |
2700 v11 = v19; | |
2701 v12 = 0; | |
2702 *(int *)v3 = v19; | |
2703 uLastLoadedSoundID = 0; | |
2704 if ( pSounds[0].pSoundData ) | |
2705 { | |
2706 v13 = (char *)&pSounds[0].pSoundData; | |
2707 do | |
2708 { | |
2709 v13 += 128; | |
2710 ++v12; | |
2711 } | |
2712 while ( *(int *)v13 ); | |
2713 uLastLoadedSoundID = v12; | |
2714 } | |
24 | 2715 v16 = pSounds[v12].SoundName; |
0 | 2716 strcpy((char *)v16, pSoundName_); |
2717 v14 = uLastLoadedSoundID++ << 7; | |
2718 pSoundList->uTotalLoadedSoundSize += v11; | |
2719 pSounds[uLastLoadedSoundID].pSoundData = v3; | |
2720 result = v3; | |
2721 } | |
2722 else | |
2723 { | |
2724 result = 0; | |
2725 } | |
2726 return result; | |
2727 } |