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