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