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