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