-
Notifications
You must be signed in to change notification settings - Fork 9
/
WeaponSoundLoader.pas
569 lines (474 loc) · 21.1 KB
/
WeaponSoundLoader.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
unit WeaponSoundLoader;
{$IFDEF FPC}{$MODE DELPHI}{$ENDIF}
interface
uses xr_strings, MatVectors;
type ref_sound = packed record
_p:{ref_sound_data_ptr}pointer;
end;
type pref_sound = ^ref_sound;
type HUD_SOUND_ITEM_SSnd = packed record
snd:ref_sound;
delay:single;
volume:single; // èç-çà áàãà â HUD_SOUND_ITEM::PlaySound òîëêîì íå ðàáîòàåò; âûðåçàåì èñïîëüçîâàíèå òàì è èñïîëüçóåì â ñâîèõ öåëÿõ
// îòðèöàòåëüíîå ÷èñëî çíà÷èò, ÷òî çâóê "ðàçáëîêèðîâàí". Ìîäóëü îïðåäåëÿåò âàðèàöèþ ÷àñòîòû
end;
type pHUD_SOUND_ITEM_SSnd = ^HUD_SOUND_ITEM_SSnd;
type HUD_SOUND_ITEM = packed record
m_alias:shared_str;
m_activeSnd:pHUD_SOUND_ITEM_SSnd;
m_b_exclusive:byte{bool};
volume:byte; //â îðèãèíàëå íå èñïîëüçóåòñÿ, ïåðåîïðåäåëÿåì ïîä íîâóþ ãðîìêîñòü
_unused2:word;
sounds_start:pHUD_SOUND_ITEM_SSnd;
sounds_end:pHUD_SOUND_ITEM_SSnd;
sounds_mem:pHUD_SOUND_ITEM_SSnd;
end;
type pHUD_SOUND_ITEM = ^HUD_SOUND_ITEM;
type HUD_SOUND_COLLECTION = packed record
first:pHUD_SOUND_ITEM;
last:pHUD_SOUND_ITEM;
mem:pHUD_SOUND_ITEM;
end;
type pHUD_SOUND_COLLECTION = ^HUD_SOUND_COLLECTION;
type CSound_params = packed record
position:Fvector3;
base_volume:single;
volume:single;
freq:single;
min_distance:single;
max_distance:single;
max_ai_distance:single;
end;
type pCSound_params = ^CSound_params;
function Init:boolean;
procedure HUD_SOUND_COLLECTION__LoadSound(hcs:pHUD_SOUND_COLLECTION; section:PChar; config_name:PChar; internal_name:PChar; exclusive:cardinal; snd_type:cardinal);stdcall;
implementation
uses BaseGameData, gunsl_config, HudItemUtils, sysutils, math;
var
sound_load_magazined_addr:cardinal;
sound_load_knife_addr:cardinal;
procedure HUD_SOUND_COLLECTION__LoadSound(hcs:pHUD_SOUND_COLLECTION; section:PChar; config_name:PChar; internal_name:PChar; exclusive:cardinal; snd_type:cardinal);stdcall;
asm
pushad
pushfd
push snd_type
push exclusive
push internal_name
push config_name
push section
mov ecx, hcs
mov eax, xrgame_addr
add eax, $2FB430
call eax // HUD_SOUND_COLLECTION::LoadSound
popfd
popad
end;
procedure LoadSounds_WeaponMagazined(hsc:pHUD_SOUND_COLLECTION; section:PChar); stdcall;
begin
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_changecartridgetype', 'sndChangeCartridgeType', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_reload_empty', 'sndReloadEmpty', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_reload_jammed', 'sndReloadJammed', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_reload_jammed_last', 'sndReloadJammedLast', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_jammed_click', 'sndJammedClick', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_change_grenade', 'sndChangeGrenade', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_load_grenade', 'sndLoadGrenade', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_change_grenade_detector', 'sndChangeGrenadeDetector', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_load_grenade_detector', 'sndLoadGrenadeDetector', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_changecartridgetype_detector', 'sndChangeCartridgeTypeDetector', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_reload_empty_detector', 'sndReloadEmptyDetector', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_reload_jammed_detector', 'sndReloadJammedDetector', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_reload_jammed_last_detector', 'sndReloadJammedLastDetector', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_jammed_click_detector', 'sndJammedClickDetector', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_changefiremode', 'sndChangeFireMode', 1, $80040000);
if game_ini_line_exist(section, 'snd_changefiremode_empty') then
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_changefiremode_empty', 'sndChangeFireModeEmpty', 1, $FFFFFFFF)
else
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_changefiremode', 'sndChangeFireModeEmpty', 1, $FFFFFFFF);
if game_ini_line_exist(section, 'snd_changefiremode_jammed') then
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_changefiremode_jammed', 'sndChangeFireModeJammed', 1, $FFFFFFFF)
else
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_changefiremode', 'sndChangeFireModeJammed', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_sprint_start', 'sndSprintStart', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_sprint_end', 'sndSprintEnd', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_attach_sil', 'sndSilAtt', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_detach_sil', 'sndSilDet', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_attach_scope', 'sndScopeAtt', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_detach_scope', 'sndScopeDet', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_attach_gl', 'sndGLAtt', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_detach_gl', 'sndGLDet', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_unload_mag', 'sndUnload', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_jam', 'sndJam', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_breechblock', 'sndBreechblock', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_suicide_breechblock', 'sndSuicideBreechblock', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_explose', 'sndExplose', 0, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_prepare_detector', 'sndPrepareDet', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_finish_detector', 'sndFinishDet', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_aim_start', 'sndAimStart', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_aim_end', 'sndAimEnd', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_laser_on', 'sndLaserOn', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_laser_off', 'sndLaserOff', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_torch_on', 'sndTorchOn', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_torch_off', 'sndTorchOff', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_open_weapon_empty', 'sndOpenEmpty', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_reload_only', 'sndReloadOnly', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_reload_only_detector', 'sndReloadOnlyDetector', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_reload_only_ammochange', 'sndReloadOnlyAmmochange', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_reload_only_ammochange_detector', 'sndReloadOnlyAmmochangeDetector', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_changecartridgetype_one', 'sndChangeCartridgeTypeOne', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_changecartridgetype_one_detector', 'sndChangeCartridgeTypeOneDetector', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_changecartridgetype_only', 'sndChangeCartridgeTypeOnly', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_changecartridgetype_one_only_detector', 'sndChangeCartridgeTypeDetectorOneOnly', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_changecartridgetype_one_only', 'sndChangeCartridgeTypeOneOnly', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_changecartridgetype_only_detector', 'sndChangeCartridgeTypeDetectorOnly', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_light_misfire', 'sndLightMisfire', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_suicide', 'sndSuicide', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_stop_suicide', 'sndStopSuicide', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_scream_1', 'sndScream1', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_scream_2', 'sndScream2', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_scream_3', 'sndScream3', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_scream_4', 'sndScream4', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_headlamp_on', 'sndHeadlampOn', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_headlamp_off', 'sndHeadlampOff', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_nv_on', 'sndNVOn', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_nv_off', 'sndNVOff', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_kick', 'sndKick', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_add_cartridge_preloaded', 'sndAddCartridgePreloaded', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_close_weapon_preloaded', 'sndClosePreloaded', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_add_cartridge_empty', 'sndAddCartridgeEmpty', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_close_weapon_empty', 'sndCloseEmpty', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_scope_brightness_plus', 'sndScopeBrightnessPlus', 0, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_scope_brightness_minus', 'sndScopeBrightnessMinus', 0, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_scope_zoom_plus', 'sndScopeZoomPlus', 0, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_scope_zoom_minus', 'sndScopeZoomMinus', 0, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_scope_zoom_gyro', 'sndScopeZoomGyro', 0, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_blowout', 'sndBlowout', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_addon_attach', 'sndAddonAttach', 0, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_addon_attach_fail', 'sndAddonAttachFail', 0, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_addon_detach', 'sndAddonDetach', 0, $FFFFFFFF);
end;
procedure LoadSounds_Knife(hsc:pHUD_SOUND_COLLECTION; section:PChar); stdcall;
begin
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_draw', 'sndShow', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_holster', 'sndHide', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_kick_1', 'sndKick1', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_kick_2', 'sndKick2', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_sprint_start', 'sndSprintStart', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_sprint_end', 'sndSprintEnd', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_start_suicide', 'sndPrepareSuicide', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_selfkill', 'sndSelfKill', 1, $80040000);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_stop_suicide', 'sndStopSuicide', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_selfkick', 'sndSelfKick', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_scream_1', 'sndScream1', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_scream_2', 'sndScream2', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_scream_3', 'sndScream3', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_scream_4', 'sndScream4', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_headlamp_on', 'sndHeadlampOn', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_headlamp_off', 'sndHeadlampOff', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_nv_on', 'sndNVOn', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_nv_off', 'sndNVOff', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_kick', 'sndKick', 1, $FFFFFFFF);
HUD_SOUND_COLLECTION__LoadSound(hsc, section, 'snd_burn', 'sndBurned', 1, $FFFFFFFF);
end;
procedure SoundLoader_Knife_Patch; stdcall;
const
sndShot:PChar='sndShot';
asm
pushad
pushfd
push edi //section
lea ecx, [esi+$324]
push ecx //snd_collection
call LoadSounds_Knife
popfd
popad
push sndShot
jmp sound_load_knife_addr
end;
procedure SoundLoader_Magazined_Patch; stdcall;
const
sndReload:PChar='sndReload';
asm
pushad
pushfd
push ebx
push edi
call LoadSounds_WeaponMagazined
popfd
popad
push sndReload
jmp sound_load_magazined_addr
end;
procedure HUD_SOUND_ITEM__StopSound(hud_snd:pHUD_SOUND_ITEM); stdcall;
asm
pushad
mov eax, xrGame_addr
add eax, $2FA380
push hud_snd
call eax
add esp, 4
popad
end;
procedure HUD_SOUND_ITEM__DestroySound(hud_snd:pHUD_SOUND_ITEM); stdcall;
asm
pushad
mov eax, xrGame_addr
add eax, $2FB140
push hud_snd
call eax
add esp, 4
popad
end;
procedure HUD_SOUND_COLLECTION__SetPosition(collection:pHUD_SOUND_COLLECTION; alias:PChar; pos:pFVector3); stdcall;
asm
pushad
mov eax, xrGame_addr
add eax, $2FA440
mov ecx, collection
push pos
push alias
call eax
popad
end;
procedure HUD_SOUND_COLLECTION_UnLoadSound(collection:pHUD_SOUND_COLLECTION; snd:pHUD_SOUND_ITEM); stdcall;
begin
HUD_SOUND_ITEM__StopSound(snd);
HUD_SOUND_ITEM__DestroySound(snd);
collection.last:=(pHUD_SOUND_ITEM(cardinal(collection.last)-sizeof(HUD_SOUND_ITEM)));
if snd<>collection.last then snd^:=collection.last^;
end;
procedure HUD_SOUND_COLLECTION__LoadSound_Patch; stdcall;
asm
pushad
push eax
push esi
call HUD_SOUND_COLLECTION_UnLoadSound
popad
end;
const
GLOBAL_HUD_VOLUME_KOEF:single=0.9;
procedure HUD_SOUND_ITEM__LoadSndVolume(sect:PAnsiChar; param:PAnsiChar; hud_snd:pHUD_SOUND_ITEM); stdcall;
var
vol:cardinal;
maxvol:cardinal;
param_name:string;
begin
param_name:='volume_'+param;
vol:=game_ini_r_int_def(sect, PAnsiChar(param_name), 0); // â ïðîöåíòàõ
R_ASSERT(vol >= 0, PAnsiChar('Parameter "'+param_name+'" in section "'+sect+'" must be >= 0'), 'HUD_SOUND_ITEM__LoadSndVolume');
maxvol:= floor(100 / GLOBAL_HUD_VOLUME_KOEF);
R_ASSERT(vol <= maxvol, PAnsiChar('Parameter "'+param_name+'" in section "'+sect+'" must be <= '+inttostr(maxvol)), 'HUD_SOUND_ITEM__LoadSndVolume');
hud_snd.volume:=byte(vol);
end;
procedure HUD_SOUND_ITEM__LoadSound_loadvolume_Patch(); stdcall;
asm
mov eax, esp
pushad
mov edx,[eax+$148]
push edx
lea edx, [eax+$3c]
push edx
push edi
call HUD_SOUND_ITEM__LoadSndVolume
popad
pop eax //ret addr
add esi, 01
push esi
push ebp
jmp eax
end;
procedure UpdateSoundsPos(collection:pHUD_SOUND_COLLECTION; pos:pFVector3);stdcall;
var
snd:pHUD_SOUND_ITEM;
alias:PAnsiChar;
begin
snd:=collection.first;
while(snd<>collection.last) do begin
if snd.m_activeSnd<>nil then begin
alias:=get_string_value(@snd.m_alias);
if length(alias) > 0 then begin
HUD_SOUND_COLLECTION__SetPosition(collection, alias, pos);
end;
end;
snd:=pHUD_SOUND_ITEM(cardinal(snd)+sizeof(HUD_SOUND_ITEM))
end;
end;
procedure CWeaponMagazined__UpdateSounds_Patch(); stdcall;
asm
pushad
push edx
push esi
call UpdateSoundsPos
popad
end;
function ref_sound__get_params(this:pref_sound):pCSound_params; stdcall;
asm
// Ñêîïèðîâàíî èç äâèæêà
mov result, 0
pushad
mov eax, this
mov eax, [eax]
mov ecx, eax
neg ecx
sbb ecx, ecx
test ecx, $6D09720
je @finish
mov ecx,[eax+$C]
test ecx, ecx
je @finish
mov edx,[ecx]
mov eax,[edx+$24]
call eax
mov result, eax
@finish:
popad
end;
procedure ref_sound__play_at_pos(this:pref_sound; O:pointer; pos:pFVector3; flags:cardinal; d:single); stdcall;
asm
pushad
push d
push flags
push pos
push o
push this
mov ecx, xrgame_addr;
mov ecx, [ecx+$5132a4]
mov ecx, [ecx]
mov edi, [ecx]
mov eax, [edi+$38]
call eax
popad
end;
procedure ref_sound__play_no_feedback(this:pref_sound; O:pointer; flags:cardinal; d:single; pos:pFVector3; vol:psingle; freq:psingle; range:pFVector2); stdcall;
asm
pushad
push range
push freq
push vol
push pos
push d
push flags
push O
push this
mov ecx, xrgame_addr;
mov ecx, [ecx+$5132a4]
mov ecx, [ecx]
mov edi, [ecx]
mov eax, [edi+$3C]
call eax
popad
end;
//Ïðàâêà íà îòêëþ÷åíèå ïðåðûâàíèÿ çâóêà ïðè åãî ðåñòàðòå (äëÿ ñòðåëüáû ãëàâíûì îáðàçîì)
//òàêæå òóò âûïîëíÿåì êîððåêöèþ ÷àñòîòû äëÿ ñòðåëüáû
procedure DecideHowToPlaySnd(snd:pHUD_SOUND_ITEM; O:pointer; pos:pFVector3; flags:cardinal); stdcall;
const
sm_Looped:cardinal = $1;
sm_2D:cardinal = $2;
EPS:single=0.001;
var
params:pCSound_params;
freq, volume:single;
need_freq_variation, sound_unlocked:boolean;
freq_deviation, new_freq, delta:single;
hud_mode:boolean;
begin
freq_deviation:=abs(snd.m_activeSnd.volume);
need_freq_variation := (freq_deviation - 1.0 > EPS);
sound_unlocked:=(snd.m_activeSnd.volume < 0) or IsSndUnlock(); // òåïåðü âìåñòî ãðîìêîñòè ìèíóñ â çíàêå îçíà÷àåò àíëîê çâóêà, à ìîäóëü - èçìåíåíèå ÷àñòîòû
if need_freq_variation then begin
if freq_deviation > 1.0 then begin
delta:=freq_deviation - 1.0;
if delta > 0.9 then delta:=0.9;
freq:=1.0 + (random * 2*delta) - delta;
end else begin
delta:=1.0 - freq_deviation;
if delta > 0.9 then delta:=0.9;
freq:=1.0 - random * delta;
end;
// Log('Freq = '+floattostr(freq)+', unlock = '+booltostr(sound_unlocked, true));
end;
volume:=GLOBAL_HUD_VOLUME_KOEF;
if snd.volume <> 0 then begin //Ãðîìêîñòü ïåðååõàëà â ðàíåå íåèñïîëüçóåìóþ îáëàñòü
volume:= snd.volume / 100;
//Log('Override volume '+floattostr(volume) +' for '+get_string_value(@snd.m_alias));
end;
hud_mode:=((flags and sm_2D)<>0);
if hud_mode then begin
volume:=volume * GetHudSoundVolume();
end;
if (not sound_unlocked) or ((snd.m_b_exclusive<>0) or ((flags and sm_Looped)<>0)) then begin
ref_sound__play_at_pos(@snd.m_activeSnd.snd, O, pos, flags, snd.m_activeSnd.delay);
params:=ref_sound__get_params(@snd.m_activeSnd.snd);
params.volume:=volume;
if need_freq_variation then begin
params.freq:=freq;
end;
end else begin
if need_freq_variation then begin
ref_sound__play_no_feedback(@snd.m_activeSnd.snd, O, flags, snd.m_activeSnd.delay, pos, @volume, @freq, nil);
end else begin
ref_sound__play_no_feedback(@snd.m_activeSnd.snd, O, flags, snd.m_activeSnd.delay, pos, @volume, nil, nil);
end;
end;
end;
procedure HUD_SOUND_ITEM__PlaySound_Patch();
asm
push ebp
mov ebp, esp
pushad
push [ebp+$14]
push [ebp+$10]
push [ebp+$c]
push esi
call DecideHowToPlaySnd
popad
pop ebp
ret $14
end;
function Init:boolean;
var
addr, tmp:cardinal;
begin
result:=false;
sound_load_magazined_addr:=xrGame_addr+$2CFADE;
if not WriteJump(sound_load_magazined_addr, cardinal(@SoundLoader_Magazined_Patch), 5) then exit;
sound_load_knife_addr:=xrGame_addr+$2D4DC2;
if not WriteJump(sound_load_knife_addr, cardinal(@SoundLoader_Knife_Patch), 5) then exit;
if IsSoundPatchNeeded() then begin
//ïåðåçàãðóçêà çâóêà â HUD_SOUND_COLLECTION âìåñòî âûëåòà.
addr:=xrGame_addr+$2FB46C;
nop_code(addr, 37);
if not WriteJump(addr, cardinal(@HUD_SOUND_COLLECTION__LoadSound_Patch), 5, true) then exit;
//Äîáàâëåíèå íîâîé êîððåêòèðîâêè ãðîìêîñòè çâóêà
addr:=xrGame_addr+$2FB0F7;
if not WriteJump(addr, cardinal(@HUD_SOUND_ITEM__LoadSound_loadvolume_Patch), 5, true) then exit;
//Èñïðàâëÿåì êîïèðóþùèé êîíñòðóêòîð, ÷òîáû ïðè ðåñàéçå âåêòîðà ñî çâóêàìè êîïèðîâàëîñü è íàøå çíà÷åíèå ãðîìêîñòè
nop_code(xrGame_addr+$2FAD37, 1, chr($8b));
nop_code(xrGame_addr+$2FAD41, 1, chr($89));
//îáíîâëÿåì ïîçèöèè âñåõ çâóêîâ
addr:=xrGame_addr+$2CCBD3;
if not WriteJump(addr, cardinal(@CWeaponMagazined__UpdateSounds_Patch), 13, true) then exit;
//ôèêñ îáðûâà çâóêà
addr:=xrGame_addr+$2FA652;
if not WriteJump(addr, cardinal(@HUD_SOUND_ITEM__PlaySound_Patch), 5, true) then exit;
//â HUD_SOUND_ITEM::PlaySound â âûçîâå snd.set_volume îòêàçûâàåìñÿ îò èñïîëüçîâàíèÿ hud_snd.m_activeSnd->volume â êà÷åñòâå ìíîæèòåëÿ - âñå ðàâíî íå ðàáîòàåò
nop_code(xrGame_addr+$2fa663, 5);
//â HUD_SOUND_ITEM::PlaySound îòêëþ÷àåì âûçîâ snd.set_volume - áîëåå íå íóæåí, òàê êàê âñå íàñòðîéêè âûïîëíÿþòñÿ íàìè â DecideHowToPlaySnd
nop_code(xrGame_addr+$2fa69d, 1, chr($eb));
//ïåðåâîäèì â ýêñêëþçèâíûé ðåæèì âñå çâóêè òèïà äîñòàâàíèÿ, óáèðàíèÿ è ò.ä.
nop_code(xrGame_addr+$2CFA6B, 1, chr(1));
nop_code(xrGame_addr+$2CFA8C, 1, chr(1));
nop_code(xrGame_addr+$2CFAC2, 1, chr(1));
nop_code(xrGame_addr+$2DE2C6, 1, chr(1));
nop_code(xrGame_addr+$2DE2E7, 1, chr(1));
nop_code(xrGame_addr+$2DE302, 1, chr(1));
nop_code(xrGame_addr+$2C5146, 1, chr(1));
//óâåëè÷èâàåì ìàêñèìàëüíîå ÷èñëî snd_targets
tmp:=20000;
addr:=xrEngine_addr+$939a0;
WriteBufAtAdr(addr, @tmp, 4);
tmp:=32;
WriteBufAtAdr(addr-4, @tmp, 4);
end;
result:=true;
end;
end.