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