forked from gunslingermod/gunslinger_wpnpatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeaponEvents.pas
3038 lines (2591 loc) · 96.5 KB
/
WeaponEvents.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
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit WeaponEvents;
{$IFDEF FPC}{$MODE DELPHI}{$ENDIF}
interface
uses Vector;
function Init:boolean;
procedure OnWeaponExplode_AfterAnim(wpn:pointer; param:integer);stdcall;
function OnWeaponHide(wpn:pointer):boolean;stdcall;
procedure OnWeaponHideAnmStart(wpn:pointer);stdcall;
procedure OnWeaponShow(wpn:pointer);stdcall;
function OnWeaponAimIn(wpn:pointer):boolean;stdcall;
function OnWeaponAimOut(wpn:pointer):boolean;stdcall;
function Weapon_SetKeyRepeatFlagIfNeeded(wpn:pointer; kfACTTYPE:cardinal):boolean;stdcall;
function CHudItem__OnMotionMark(wpn:pointer):boolean; stdcall;
procedure RPG7ReactiveHit(wpn:pointer); stdcall;
procedure TryShootGLFix(wpn:pointer); stdcall;
implementation
uses Messenger, BaseGameData, Misc, HudItemUtils, WeaponAnims, LightUtils, WeaponAdditionalBuffer, sysutils, ActorUtils, DetectorUtils, strutils, dynamic_caster, weaponupdate, KeyUtils, gunsl_config, xr_Cartridge, ActorDOF, MatVectors, ControllerMonster, collimator, level, WeaponAmmoCounter, xr_RocketLauncher, xr_strings, Throwable, UIUtils, BallisticsCorrection, RayPick, burer, HitUtils;
var
upgrade_weapon_addr:cardinal;
//-------------------------------Ðàçðÿæàíèå ìàãàçèíà-----------------------------
procedure OnUnloadInEndOfAnim(wpn:pointer; param:integer);stdcall;
begin
virtual_CWeaponMagazined__UnloadMagazine(wpn, true);
ForceWpnHudBriefUpdate(wpn);
SetAnimForceReassignStatus(wpn, true);
end;
procedure OnUnloadInMiddleAnim(wpn:pointer; param:integer);stdcall;
begin
virtual_CWeaponMagazined__UnloadMagazine(wpn, true);
ForceWpnHudBriefUpdate(wpn);
MakeLockByConfigParam(wpn, GetHUDSection(wpn), PChar('lock_time_end_'+GetActualCurrentAnim(wpn)));
SetAnimForceReassignStatus(wpn, true);
end;
function OnUnloadMag(wpn:pointer):boolean; stdcall;
var
hud_sect: PChar;
act:pointer;
curanm:PChar;
const
param_name:PChar = 'use_unloadmag_anim';
begin
//âîçâðàòèòü false, åñëè ðàçðÿæàòü îðóæèå ñåé÷àñ íåëüçÿ
result := false;
hud_sect:=GetHUDSection(wpn);
act:=GetActor();
if ((act=nil) or (GetOwner(wpn)<>act)) then begin
result:=true;
exit;
end;
if IsMandatoryAnimatedUnloadMag() and (not CheckActorWeaponAvailabilityWithInform(wpn)) then exit;
if (not game_ini_line_exist(hud_sect, param_name)) or (not game_ini_r_bool(hud_sect, param_name)) then begin
result:=true;
exit;
end;
if WeaponAdditionalBuffer.PlayCustomAnimStatic(wpn, 'anm_unload_mag', 'sndUnload') then begin
curanm:=GetActualCurrentAnim(wpn);
StartCompanionAnimIfNeeded(rightstr(curanm, length(curanm)-4), wpn, false);
//àíèìà íà÷àëà èãðàòüñÿ. Ïîñìîòðèì, êîãäà íàäî ðàçðÿæàòüñÿ
if game_ini_line_exist(hud_sect, PChar('lock_time_start_'+GetActualCurrentAnim(wpn))) then begin
//ðàçðÿæàíèå èäåò ïî ñõåìå âèçóàëüíîãî îòîáðàæåíèÿ ïàòðîíîâ (â ñåðåäèíå àíèìàöèè)
MakeLockByConfigParam(wpn, hud_sect, PChar('lock_time_start_'+curanm), false, OnUnloadInMiddleAnim);
end else if game_ini_line_exist(hud_sect, PChar('lock_time_end_'+curanm)) then begin
//ðàçðÿæàíèå âûïîëíÿåòñÿ ïîñëå àíèìàöèè
MakeLockByConfigParam(wpn, hud_sect, PChar('lock_time_end_'+curanm), false, OnUnloadInEndOfAnim);
end else begin
//íèêàêèõ óêàçàíèé íåò, ïîýòîìó ðàçðÿæàåìñÿ ñðàçó
result := true;
SetAnimForceReassignStatus(wpn, true);
end;
end else begin
//àíèìà íå ñòàðòîâàëà - îðóæèå çàíÿòî
result := true;
end;
end;
procedure UnloadMag_Patch(); stdcall;
asm
//äåëàåì âûðåçàííîå: add esp, 4/test eax, eax
push eax
mov eax, [esp+4]
mov [esp+8], eax
pop eax
add esp, 4
test eax, eax
je @finish
pushad
push ecx
call OnUnloadMag
cmp al, 0
popad
@finish:
end;
//-----------------Îáùèé îáðàáîò÷èê ñîáûòèÿ îòñîåäèíåíèÿ àääîíîâ----------------
procedure OnAddonDetach(wpn:pointer; addontype:integer);stdcall;
var
param_name:PChar;
anim_name:string;
addon_name:PChar;
snd_name:PChar;
hud_sect:PChar;
act:pointer;
key:cardinal;
begin
act:=GetActor();
if ((act=nil) or (GetOwner(wpn)<>act)) or (IsAnimatedAddons() and not CheckActorWeaponAvailabilityWithInform(wpn)) then exit;
param_name:=nil;
snd_name:=nil;
case addontype of
1:begin
addon_name:=GetCurrentScopeSection(wpn);
if addon_name<>nil then begin
param_name:='use_scopedetach_anim';
anim_name:='anm_detach_scope_'+addon_name;
snd_name:='sndScopeDet';
end;
if IsAimNow(wpn) then begin
if IsAlterZoom(wpn) then begin
key:=kWPN_ZOOM_ALTER;
end else begin
key:=kWPN_ZOOM;
end;
if IsAimToggle() then
virtual_Action(wpn, key, kActPress)
else
virtual_Action(wpn, key, kActRelease);
end;
end;
4:begin
param_name:='use_sildetach_anim';
anim_name:='anm_detach_sil';
snd_name:='sndSilDet';
end;
2:begin
param_name:='use_gldetach_anim';
anim_name:='anm_detach_gl';
snd_name:='sndGLDet';
if IsAimNow(wpn) then begin
if IsAimToggle() then
virtual_Action(wpn, kWPN_ZOOM, kActPress)
else
virtual_Action(wpn, kWPN_ZOOM, kActRelease);
end;
end;
else begin
log('WeaponEvents.OnAddonDetach: Invalid addontype!', true);
exit;
end;
end;
hud_sect:=GetHUDSection(wpn);
CHudItem_Play_Snd(wpn, 'sndAddonDetach');
if (not IsAnimatedAddons()) or (param_name=nil) or (not game_ini_line_exist(hud_sect, param_name)) or (not game_ini_r_bool(hud_sect, param_name)) then begin
DetachAddon(wpn, addontype);
exit;
end;
WeaponAdditionalBuffer.PlayCustomAnimStatic(wpn, PChar(anim_name), snd_name, DetachAddon, addontype);
end;
procedure DetachAddon_Patch(addontype:integer);stdcall;
asm
pushad
push addontype
push esi //CWeapon
call OnAddonDetach
popad
end;
function InitDetachAddon(address:cardinal; addontype:byte; nopcount:integer; writejustpush:boolean = false):boolean;
var buf:string;
begin
result:=false;
buf:=chr($6A)+chr(addontype);//ôîðìèðóåì è çàïèñûâàåì àðãóìåíò äëÿ ïàò÷à
if not WriteBufAtAdr(address, PChar(buf), 2) then exit;
if not writejustpush then begin
address:=address+2;//òåïåðü çàïèñûâàåì âûçîâ ïàò÷à è íîïèì ëèøíåå, äàáû àääîí íå èñ÷åç
if not WriteJump(address, cardinal(@DetachAddon_Patch), nopcount, true) then exit;
end;
result:=true;
end;
//-----------------Îáùèé îáðàáîò÷èê ñîáûòèÿ ïðèñîåäèíåíèÿ àääîíîâ----------------
procedure SetNewScopeId(wpn:pointer; new_id:byte); stdcall;
var
buf:WpnBuf;
last_id:cardinal;
begin
buf:=GetBuffer(wpn);
if buf <> nil then begin
if IsScopeAttached(wpn) then begin
last_id:=GetCurrentScopeIndex(wpn);
end else begin
last_id:=$FFFFFFFF;
end;
buf.SetLastScopeId(last_id);
end;
SetCurrentScopeType(wpn, new_id);
end;
procedure CWeaponMagazined__Attach_saveprevscope_Patch(); stdcall;
asm
pushad
xor ecx, ecx
mov cl, al
push ecx
push ebp
call SetNewScopeId
popad
end;
function OnAddonAttach(wpn:pointer; addontype:integer):boolean;stdcall;
var addonname:PChar;
actor:pointer;
snd_name:PChar;
param_name:PChar;
anim_name:string;
hud_sect, sect:PChar;
err_msg:PChar;
key:cardinal;
need_detach_gl, need_detach_sil:boolean;
need_detach_scope_id, tmpid:cardinal;
buf:WpnBuf;
begin
param_name:=nil;
snd_name:=nil;
sect:=GetSection(wpn);
err_msg:=nil;
need_detach_scope_id:=$FFFFFFFF;
need_detach_gl:=false;
need_detach_sil:=false;
buf:=GetBuffer(wpn);
if buf <> nil then begin
buf.need_update_icon:=true;
end;
case addontype of
1:begin
//log ('scope_att');
addonname:=GetCurrentScopeSection(wpn);
if addonname=nil then log('WpnEvents.OnAddonAttach: Scope has no section?!');
addonname:=game_ini_read_string(addonname, 'scope_name');
param_name:='use_scopeattach_anim';
anim_name:='anm_attach_scope_'+addonname;
snd_name:='sndScopeAtt';
if IsScopeAttached(wpn) and (buf <> nil) then begin
err_msg:='gunsl_msg_need_detach_scope';
need_detach_scope_id:=buf.GetLastScopeId();
end;
if IsSilencerAttached(wpn) and game_ini_line_exist(sect, 'restricted_scope_and_sil') and game_ini_r_bool(sect, 'restricted_scope_and_sil') then begin
err_msg:='gunsl_msg_sil_restricts_scope';
need_detach_sil:=true;
end;
if IsGLAttached(wpn) and game_ini_line_exist(sect, 'restricted_scope_and_gl') and game_ini_r_bool(sect, 'restricted_scope_and_gl') then begin
err_msg:='gunsl_msg_gl_restricts_scope';
need_detach_gl:=true;
end;
if IsAimNow(wpn) then begin
if IsAlterZoom(wpn) then begin
key:=kWPN_ZOOM_ALTER;
end else begin
key:=kWPN_ZOOM;
end;
if IsAimToggle() then
virtual_Action(wpn, key, kActPress)
else
virtual_Action(wpn, key, kActRelease);
end;
end;
4:begin
//log ('sil_att');
param_name:='use_silattach_anim';
anim_name:='anm_attach_sil';
snd_name:='sndSilAtt';
addonname:=GetSilencerSection(wpn);
if IsSilencerAttached(wpn) then begin
err_msg:='gunsl_msg_need_detach_silencer';
need_detach_sil:=true;
end;
if IsScopeAttached(wpn) and game_ini_line_exist(sect, 'restricted_scope_and_sil') and game_ini_r_bool(sect, 'restricted_scope_and_sil') then begin
err_msg:='gunsl_msg_scope_restricts_sil';
need_detach_scope_id:=GetCurrentScopeIndex(wpn);
end;
if IsGLAttached(wpn) and game_ini_line_exist(sect, 'restricted_gl_and_sil') and game_ini_r_bool(sect, 'restricted_gl_and_sil') then begin
err_msg:='gunsl_msg_gl_restricts_sil';
need_detach_gl:=true;
end;
end;
2:begin
//log('gl_att');
param_name:='use_glattach_anim';
anim_name:='anm_attach_gl';
snd_name:='sndGLAtt';
addonname:=GetGLSection(wpn);
if IsGLAttached(wpn) then begin
err_msg:='gunsl_msg_need_detach_gl';
need_detach_gl:=true;
end;
if IsScopeAttached(wpn) and game_ini_line_exist(sect, 'restricted_scope_and_gl') and game_ini_r_bool(sect, 'restricted_scope_and_gl') then begin
err_msg:='gunsl_msg_scope_restricts_gl';
need_detach_scope_id:=GetCurrentScopeIndex(wpn);
end;
if IsSilencerAttached(wpn) and game_ini_line_exist(sect, 'restricted_gl_and_sil') and game_ini_r_bool(sect, 'restricted_gl_and_sil') then begin
err_msg:='gunsl_msg_sil_restricts_gl';
need_detach_sil:=true;
end;
end;
else begin
log('WeaponEvents.OnAddonAttach: Invalid addontype!', true);
result:=true;
exit;
end;
end;
hud_sect:=GetHUDSection(wpn);
actor:=GetActor();
if not IsAnimatedAddons() then begin
// ïðî ñáðîñ ôëàãîâ ïðè äåòà÷å íå áåñïîêîèìñÿ - äâèæîê ñàì âûñòàâèì íóæíûé íàì ôëàã ïîñëå òîãî, êàê ìû îòðàáîòàåì
if need_detach_scope_id <> $FFFFFFFF then begin
tmpid:=GetCurrentScopeIndex(wpn);
SetCurrentScopeType(wpn, need_detach_scope_id);
DetachAddon(wpn, 1);
SetCurrentScopeType(wpn, tmpid);
end else if need_detach_gl then begin
DetachAddon(wpn, 2);
end else if need_detach_sil then begin
DetachAddon(wpn, 4);
end;
result:=true;
end else if (actor<>nil) and (actor=GetOwner(wpn)) and (not CheckActorWeaponAvailabilityWithInform(wpn)) then begin
//log('not_available');
result:=false;
end else if err_msg<>nil then begin
//log('att_err');
if (actor<>nil) and (actor=GetOwner(wpn)) then begin
Messenger.SendMessage(err_msg);
end;
result:=false
end else if (actor=nil) or (actor<>GetOwner(wpn)) then begin
//log('actor_not_owner');
result:=true;
end else if (param_name=nil) or (not game_ini_line_exist(hud_sect, param_name)) or (not game_ini_r_bool(hud_sect, param_name)) then begin
//log('no_param');
result:=true;
end else begin
//log (anim_name);
//log('playing...');
result:= WeaponAdditionalBuffer.PlayCustomAnimStatic(wpn, PChar(anim_name), snd_name);
end;
if (not result) then begin
//Ñåé÷àñ ïðèñîåäèíÿòü àääîí íåëüçÿ. Îòñïàâíèì åãî íàçàä â èíâåíòàðü.
if addontype = 1 then SetCurrentScopeType(wpn, 0);
if (actor<>nil) and (actor=GetOwner(wpn)) then CreateObjectToActor(addonname);
end;
if result then begin
CHudItem_Play_Snd(wpn, 'sndAddonAttach');
end else begin
CHudItem_Play_Snd(wpn, 'sndAddonAttachFail');
end;
end;
procedure AttachAddon_Patch{(addontype:integer)}();stdcall;
asm
push ecx
mov ecx, [esp+8]
push esi
push ebx
mov ebx, ecx
//â ìëàäøåì íèááëå ìëàäøåãî áàéòà addontype - òèï àääîíà, â ñòàðøåì íèááëå - èíäåêñ ðåãèñòðà ñ àäðåñîì îðóæèÿ
//1 - ebp, 0 - esi
and ecx, $0000000F
and ebx, $000000F0
shr ebx, 4
//âîññòàíàâëèâàåì èç ñòåêà óêàçàòåëü íà îðóæèå
cmp bx, 0
je @wpnfound
mov esi, ebp
cmp bx, 1
je @wpnfound
@wpnfound:
pushad
push ecx
push esi //CWeapon
call OnAddonAttach
test al, al
popad
je @finish
or byte ptr [esi+$460], cl
@finish:
pop ebx
pop esi
pop ecx
ret 4
end;
function InitAttachAddon(address:cardinal; addontype:byte):boolean;
var buf:string;
begin
result:=false;
buf:=chr($6A)+chr(addontype);//ôîðìèðóåì è çàïèñûâàåì àðãóìåíò äëÿ ïàò÷à
if not WriteBufAtAdr(address, PChar(buf), 2) then exit;
address:=address+2;//òåïåðü çàïèñûâàåì âûçîâ ïàò÷à
if not WriteJump(address, cardinal(@AttachAddon_Patch), 0, true) then exit;
result:=true;
end;
//------------------------------------------------------------------------------
procedure OnCWeaponNetSpawn_middle(wpn:pointer; swpn:pointer);stdcall;
var
scope_id, wpnstate:byte;
begin
if WpnCanShoot(wpn) then begin
//áóôåð ìîæåò óæå áûòü ñîçäàí â load'e - ïðîâåðèì ýòî
if (GetBuffer(wpn)=nil) then begin
WpnBuf.Create(wpn);
end;
end;
//Â 5 ñòàðøèõ áèòàõ íà ñòîðîíå ñåðâåðíîãî îáúåêòà ìû ñîõðàíÿåì èíäåêñ ïðèöåëà
wpnstate:=CSE_GetAddonsFlags(swpn);
scope_id:=wpnstate shr 3;
if scope_id<>0 then begin
SetCurrentScopeType(wpn, scope_id);
wpnstate := wpnstate and $7;
end;
CSE_SetAddonsFlags(swpn, wpnstate);
//ïåðåíåñòè â îáëàñòü äâèæêîâîãî êîäà ïîñëå âû÷èòêè m_flagsAddOnState
if (IsScopeAttached(wpn) or (GetCurrentScopeIndex(wpn) > 0)) and (GetCurrentScopeIndex(wpn) >= GetScopesCount(wpn)) then begin
//Ïðîáëåìà - ïðèöåë íå ñóùåñòâóåò! Ñáðàñûâàåì ôëàã
Log('Invalid scope ID '+inttostr(GetCurrentScopeIndex(wpn))+' for '+GetSection(wpn)+', reset ID', true);
SetCurrentScopeType(wpn, 0);
end;
end;
procedure OnCWeaponNetSpawn_end(wpn:pointer);stdcall;
var
buf:WpnBuf;
i:word;
c:pointer;
sect, scope_sect:PChar;
slot:integer;
visual:pchar;
banned_visuals, banned_item:string;
begin
banned_visuals:=game_ini_read_string_def(GetSection(wpn), 'banned_visuals', '');
visual:=GetWeaponVisualName(wpn);
if (visual<>nil) and (length(banned_visuals) > 0) then begin
banned_visuals:=banned_visuals;
while (GetNextSubStr(banned_visuals, banned_item, ',')) do begin
if visual = banned_item then begin
log('Found banned visual "'+visual+' for '+GetSection(wpn)+', reset it');
visual:=game_ini_read_string_def(GetSection(wpn), 'visual', '');
if length(visual) > 0 then begin
SetWpnVisual(wpn, visual);
end;
break;
end;
end;
end;
//âûñòàâèì ñîõðàíåííûå òèïû ïàòðîíîâ
if WpnCanShoot(wpn) then begin
buf:=GetBuffer(wpn);
if (buf<>nil) then begin
// if (IsGLAttached(wpn)) then log(booltostr(ISGLEnabled(wpn), true));
if (length(buf.ammos)>0) and (length(buf.ammos)=integer(GetAmmoInMagCount(wpn))) then begin
for i:=0 to length(buf.ammos)-1 do begin
sect:=GetMainCartridgeSectionByType(wpn, buf.ammos[i]);
if sect<>nil then begin
c:=GetCartridgeFromMagVector(wpn, i);
CCartridge__Load(c, sect, buf.ammos[i]);
end;
end;
end else begin
if (GetAmmoInMagCount(wpn)>0) and (length(buf.ammos)>0) then begin
log(PChar('There is NO ammotype data in the save??? Weapon '+GetSection(wpn)+':'+inttostr(GetID(wpn))), true)
end else if (length(buf.ammos)<>0) and (length(buf.ammos)=integer(GetAmmoInMagCount(wpn))) then begin
log(PChar('Count of ammotypes in the save is not equal to count of ammo in weapon '+GetSection(wpn)+':'+inttostr(GetID(wpn))), true);
end;
end;
setlength(buf.ammos, 0);
//Ò.ê. load âûïîëíÿåòñÿ ðàíüøå ïðèìåíåíèÿ àïãðåéäîâ, òî âñå âíîñèìûå èìè èçìåíåíèÿ áóäóò åùå íåâàëèäíû!
//Èç-çà ýòîãî ìû âûíóæäåíû âûíîñèòü çàâèñÿùóþ îò íèõ ëîãèêó ñþäà - òóò àïãðåéäû óæå åñòü.
scope_sect:=GetSection(wpn);
if IsScopeAttached(wpn) and (GetScopeStatus(wpn)=2) then begin
scope_sect:=game_ini_read_string(GetCurrentScopeSection(wpn), 'scope_name');
end;
buf.LoadNightBrightnessParamsFromSection(scope_sect);
end;
end;
SetAnimForceReassignStatus(wpn, true);
end;
procedure CWeapon_NetSpawn_Patch_middle();
asm
pushad
pushfd
push edi
push esi
call OnCWeaponNetSpawn_middle
popfd
popad
test edi, edi
mov [esp+$14], eax
ret
end;
procedure CWeapon_NetSpawn_Patch_end();
asm
mov byte ptr [esi+$6a0], al
pushad
pushfd
push esi
call OnCWeaponNetSpawn_end
popfd
popad
ret
end;
//------------------------------------------------------------------------------
procedure OnCWeaponNetDestroy(wpn:pointer);stdcall;
var
buf:WpnBuf;
begin
buf:=WeaponAdditionalBuffer.GetBuffer(wpn);
if buf<>nil then buf.Free;
end;
procedure CWeapon_NetDestroy_Patch();
asm
pushad
pushfd
push esi
call OnCWeaponNetDestroy
popfd
popad
lea edi, [esi+$338];
ret
end;
//---------------Äåéñòâèÿ ïðè ïîêóïêå êàêîãî-òî àïãðåéäà ó ìåõàíèêà-------------
procedure Upgrade_Weapon_Patch(); stdcall;
asm
pushad
pushfd
//push ebx
//call WeaponVisualChanger
popfd
popad
push ecx
lea edx, [esp+$1c]
jmp upgrade_weapon_addr
end;
//-----------------------------------------Ïåðåêëþ÷åíèå ðåæèìîâ îãíÿ------------------------
function OnChangeFireMode(wpn:pointer; new_mode:integer; isPrev:boolean):boolean; stdcall;
var
hud_sect:PChar;
firemode:integer;
anm_name:string;
det_anim:PChar;
res:boolean;
begin
//âîçâðàòèòü false, åñëè íåëüçÿ ñåé÷àñ ìåíÿòü ðåæèì îãíÿ
if isPrev then
result:=Weapon_SetKeyRepeatFlagIfNeeded(wpn, kfPREVFIREMODE)
else
result:=Weapon_SetKeyRepeatFlagIfNeeded(wpn, kfNEXTFIREMODE);
if not result then exit;
hud_sect:=GetHUDSection(wpn);
firemode:=CurrentQueueSize(wpn);
if firemode=new_mode then exit; //îáðàáàòûâàåì ñðàáàòûâàíèå â ñëó÷àå åäèíñòâåííîãî äîñòóïíîãî ðåæèìà ñòðåëüáû
if (hud_sect=nil) or (not game_ini_line_exist(hud_sect, 'use_firemode_change_anim')) or (not game_ini_r_bool(hud_sect, 'use_firemode_change_anim')) then exit;
anm_name:='anm_changefiremode_from_';
if firemode<0 then anm_name:=anm_name+'a' else anm_name:=anm_name+inttostr(firemode);
anm_name:=anm_name+'_to_';
if new_mode<0 then anm_name:=anm_name+'a' else anm_name:=anm_name+inttostr(new_mode);
if IsWeaponJammed(wpn) then begin
res:=WeaponAdditionalBuffer.PlayCustomAnimStatic(wpn, PChar(anm_name), 'sndChangeFireModeJammed');
end else if GetAmmoInMagCount(wpn)<=0 then begin
res:=WeaponAdditionalBuffer.PlayCustomAnimStatic(wpn, PChar(anm_name), 'sndChangeFireModeEmpty');
end else begin
res:=WeaponAdditionalBuffer.PlayCustomAnimStatic(wpn, PChar(anm_name), 'sndChangeFireMode');
end;
if res then begin
SetAnimForceReassignStatus(wpn, true); //for world model
det_anim:=GetActualCurrentAnim(wpn);
StartCompanionAnimIfNeeded(rightstr(det_anim, length(det_anim)-4), wpn, false);
end;
end;
procedure OnChangeFireMode_Patch(); stdcall;
asm
push [esi+$7ac] //ñîõðàíèì òåêóùèé èíäåêñ ðåæèìà ñòðåëüáû
mov [esi+$7ac], edx //çàïèøåì íîâûé èíäåêñ (ïðåäïîëàãàåìûé) ðåæèìà ñòðåëüáû
mov edx, [edi+$1a8]
call edx //îïðåäåëèì ðàçìåð î÷åðåäè äëÿ íîâîãî ðåæèìà ñòðåëüáû
push eax //ïîìåñòèì ñðàçó ðàçìåð î÷åðåäè äëÿ âûçîâà ìåòîäà, åãî óñòàíàâëèâàþùåãî (óäà÷íûé èñõîä)
mov ecx, [esp+$C] //âîññòàíàâëèâàåì òèï ïåðåêëþ÷åíèÿ (âïåðåä/íàçàä, íåÿâíûé àðãóìåíò)
pushad
push ecx
push eax
push esi
call OnChangeFireMode
cmp al, 1
popad
jne @nochange
mov ecx, esi //âñå íîðìàëüíî, âûïîëíÿåì ïåðåêëþ÷åíèå
mov eax, [edi+$218]
call eax //óñòàíàâëèâàåì íîâûé ðàçìåð î÷åðåäè
add esp, 4 //ñíèìàåì ñî ñòåêà íå ïîíàäîáèâøèéñÿ íàì ñòàðûé ðåæèì ñòðåëüáû
jmp @finish
@nochange:
//âñå ïëîõî, ñåé÷àñ ïåðåêëþ÷àòüñÿ íå ìîæåì
add esp, 4 //çàáûâàåì, êàêóþ î÷åðåäü ñîáèðàëèñü âûñòàâëÿòü
pop dword ptr [esi+$7ac] //âîññòàíàâëèâàåì ñòàðûé èíäåêñ
@finish:
ret 4
end;
function InitChangeFireMode(address:cardinal; changetype:byte):boolean;
var buf:string;
begin
result:=false;
buf:=chr($6A)+chr(changetype);//ôîðìèðóåì è çàïèñûâàåì àðãóìåíò äëÿ ïàò÷à
if not WriteBufAtAdr(address, PChar(buf), 2) then exit;
address:=address+2;//òåïåðü çàïèñûâàåì âûçîâ ïàò÷à
if not WriteJump(address, cardinal(@OnChangeFireMode_Patch), 23, true) then exit;
result:=true;
end;
//-------------------------Ñîáûòèå íàçíà÷åíèÿ êëèíà-----------------------------
procedure OnWeaponExplode_AfterAnim(wpn:pointer; param:integer);stdcall;
var
hud_sect:PChar;
trash, element:string;
sitm:pCSE_Abstract;
begin
hud_sect:=GetHUDSection(wpn);
if game_ini_line_exist(hud_sect, 'explosion_trash') then begin
trash:= game_ini_read_string(hud_sect, 'explosion_trash');
while (GetNextSubStr(trash, element, ',')) do begin
sitm:=alife_create(PChar(element), GetPosition(wpn), GetLevelVertexID(wpn), GetGameVertexID(wpn));
if sitm<>nil then CSE_SetAngle(sitm, GetOrientation(wpn));
if sitm<>nil then CSE_SetPosition(sitm, GetPosition(wpn));
end;
end;
if IsScopeAttached(wpn) and (GetScopeStatus(wpn)=2) then alife_create(game_ini_read_string(GetCurrentScopeSection(wpn), 'scope_name'), GetPosition(wpn), GetLevelVertexID(wpn), GetGameVertexID(wpn));
if IsSilencerAttached(wpn) and (GetSilencerStatus(wpn)=2) then alife_create(GetSilencerSection(wpn), GetPosition(wpn), GetLevelVertexID(wpn), GetGameVertexID(wpn));
if IsGLAttached(wpn) and (GetGLStatus(wpn)=2) then alife_create(GetGLSection(wpn), GetPosition(wpn), GetLevelVertexID(wpn), GetGameVertexID(wpn));
alife_release(get_server_object_by_id(GetID(wpn)));
end;
function IsJamProhibited(wpn:pointer):boolean; stdcall;
var
c_cur, c_next:pCCartridge;
ammoc:cardinal;
buf:WpnBuf;
begin
//[bug] â êëàññå ÐÃ-6 âûñòðåë ðàêåòû ïðîèñõîäèò äî çàêëèíà îðóæèÿ, ÷òî ìîæåò ìåøàòü.
if (dynamic_cast(wpn, 0, RTTI_CWeaponMagazined, RTTI_CWeaponRG6, false)<>nil) and (game_ini_r_bool_def(GetHUDSection(wpn), 'no_jam_fire', false)) then begin
buf:=GetBuffer(wpn);
if (buf<>nil) and not buf.rg6_misfire_assign_allowed then begin
result:=true;
exit;
end;
end;
// Åñëè ðåàëüíûé òèï ïàòðîíà â ñòâîëå è ñëåäóþùåãî ïàòðîíà (òîãî, êîòîðûé áóäåò çàðÿæåí ïîñëå âûñòðåëà) îòëè÷àþòñÿ ìåæäó ñîáîé - êëèíèòü íåëüçÿ!
// Èíà÷å íà äðîáîâèêàõ ãèëüçà ïîìåíÿåò öâåò ïîñëå îêîí÷àíèÿ àíèìàöèè çàêëèíà
result:=false;
if IsGrenadeMode(wpn) then exit;
ammoc:=GetAmmoInMagCount(wpn);
if ammoc <= 0 then exit;
c_cur:=GetCartridgeFromMagVector(wpn, ammoc-1);
if ammoc=1 then begin
result:=GetAmmoTypeIndex(wpn, false) <> GetCartridgeType(c_cur);
end else begin
c_next:=GetCartridgeFromMagVector(wpn, ammoc-2);
result:=GetCartridgeType(c_cur)<>GetCartridgeType(c_next);
end;
end;
function OnWeaponJam(wpn:pointer):boolean;stdcall;
//ñåé÷àñ ñ îðóæèåì ïðîèçîéäåò ÷òî-òî íåõîðîøåå...
//âåðíóòü false, åñëè íå ñòðåëÿòü ïåðåä êëèíîì, true - åñëè ñòðåëÿòü
var sect:PChar;
owner:pointer;
startcond, endcond, curcond, startprob, endprob, curprob:single;
anm:string;
buf:WpnBuf;
begin
result:=true;
SetWeaponMisfireStatus(wpn, true);
SetAnimForceReassignStatus(wpn, true);
owner := GetOwner(wpn);
if (owner=nil) or (owner<>GetActor()) then exit;
sect:=GetSection(wpn);
curcond:=GetCurrentCondition(wpn);
if IsActorSuicideNow() then begin
SetWeaponMisfireStatus(wpn, false);
result:=true;
end;
if FindBoolValueInUpgradesDef(wpn, 'can_explose', game_ini_r_bool_def(sect, 'can_explose', false), true) then begin
if curcond<game_ini_r_single_def(sect, 'explode_start_condition', 1) then begin
if random < game_ini_r_single_def(sect, 'explode_probability', 1) then begin
//Ñåé÷àñ îðóæèå âçîðâåòñÿ â ðóêàõ :)
result:=true;
SetExplosed(wpn, true);
if game_ini_line_exist(sect, 'explode_flame_particles') then SetCurrentParticles(wpn, game_ini_read_string(sect, 'explode_flame_particles'), OFFSET_PARTICLE_WEAPON_CURFLAME);
if game_ini_line_exist(sect, 'explode_shell_particles') then SetCurrentParticles(wpn, game_ini_read_string(sect, 'explode_shell_particles'), OFFSET_PARTICLE_WEAPON_CURSHELLS);
if game_ini_line_exist(sect, 'explode_smoke_particles') then SetCurrentParticles(wpn, game_ini_read_string(sect, 'explode_smoke_particles'), OFFSET_PARTICLE_WEAPON_CURSMOKE);
exit;
end;
end;
end;
if game_ini_r_bool_def(sect, 'use_light_misfire', false) and not (IsHolderHasActiveDetector(wpn) and game_ini_r_bool_def(GetHUDSection(wpn), 'disable_light_misfires_with_detector', false)) then begin
startcond:=game_ini_r_single_def(sect, 'light_misfire_start_condition', 1); //ïðè êàêîì ñîñòîÿíèè íà÷íóòñÿ îñå÷êè
endcond:=game_ini_r_single_def(sect, 'light_misfire_end_condition', 0); //ïðè êàêîì çàêîí÷àòñÿ
startprob:=game_ini_r_single_def(sect, 'light_misfire_start_probability', 1); //êàêóþ äîëþ îò êëèíîâ ïðè íà÷àëüíîì ñîñòîÿíèè áóäóò ñîñòàâëÿòü îñå÷êè
endprob:=game_ini_r_single_def(sect, 'light_misfire_end_probability', 0); //êàêóþ äîëþ îò âñåõ êëèíîâ îñå÷êè áóäóò ñîñòàâëÿòü â êîíöå
if (curcond<endcond) then
curprob:=endprob
else if (curcond>startcond) then
curprob:=0
else
curprob:=endprob+curcond*(startprob-endprob)/(startcond-endcond);
if (random<curprob) then begin
//Îñå÷êà! Ñáðàñûâàåì ôëàã êëèíà, à ñòðåëÿòü íå äàåì
SetWeaponMisfireStatus(wpn, false);
result:=false;
//íà÷àëî íàçâàíèÿ ìåòêè - îáÿçàòåëüíî anm_shoot, èíà÷å áóäåò îòðóáàòüñÿ ïî òàéìåðó âûñòðåëà - íå ñðàáîòàåò àíòèáàã
anm:='anm_shoot_lightmisfire';
if IsAimNow(wpn) or IsHolderInAimState(wpn) then begin
anm:=anm+'_aim';
if (GetScopeStatus(wpn)=2) and IsScopeAttached(wpn) and game_ini_r_bool_def(GetHUDSection(wpn), 'aim_scope_anims', true) then anm:=anm+'_scope';
buf:=GetBuffer(wpn);
if buf<>nil then begin
if GetActorActiveItem()=wpn then begin
buf.ApplyLensRecoil(buf.GetMisfireRecoil);
end;
end;
end;
anm:= ModifierStd(wpn, anm);
PlayHUDAnim(wpn, PChar(anm), true);
StartCompanionAnimIfNeeded(rightstr(anm, length(anm)-4), wpn, false);
anm:='lock_time_'+anm;
MakeLockByConfigParam(wpn, GetHUDSection(wpn), PChar(anm), true);
CHudItem_Play_Snd(wpn, 'sndLightMisfire');
SendMessage('gunsl_light_misfire', gd_novice);
exit;
end;
end;
//Êëèí îðóæèÿ. Ïîñìîòðèì, äî âûñòðåëà îí èëè ïîñëå
result:= not game_ini_r_bool_def(GetHUDSection(wpn), 'no_jam_fire', false);
//åñëè äî âûñòðåëà - èãðàåì àíèìó ïåðåõîäà â êëèí âðó÷íóþ
if not result then PlayHUDAnim(wpn, anm_shots_selector(wpn, true), true);
end;
procedure WeaponJammed_Patch(); stdcall;
//ó íàñ îðóæèå äîëæíî áûëî çàêëèíèòü ïðè äàííîì âûñòðåëå
//ìû ñäåëàåì õèòðåå - åñëè ïîíàäîáèòñÿ, òî âûñòàâèì ôëàã êëèíà, íî èãðå ñîîáùèì, ÷òî âñå íîðìàëüíî, è âûñòðåë ïðè ýòîì ïðîèçîéäåò
//Àíèìó âûñòðåëà â çàêëèíèâøåì ñîñòîÿíèè âûñòàâëÿåì îòëè÷íóþ îò îáû÷íîãî âûñòðåëà â WeaponAnims.pas
asm
mov eax, 1
pushad
push esi
call IsJamProhibited
cmp al, 0
popad
je @jam_allowed
mov byte ptr [esi+$45A], 0 //ñáðàñûâàåì âîçìîæíûé çàêëèí
xor eax, eax //ãîâîðèì, ÷òî îñå÷êè íåò
jmp @finish
@jam_allowed:
pushad
push esi
call OnWeaponJam
cmp al, 0
popad
je @finish //åñëè OnWeaponJam âåðíóëà false (íå ñòðåëÿòü ñåé÷àñ) - ïåðåõîäèì
xor eax, eax //ãîâîðèì, ÷òî îñå÷êè íåò
@finish:
end;
//--------------Îòîáðàæåíèå ñîîáùåíèÿ î êëèíå----------------------------------
procedure OnJammedHintShow(); stdcall;
//var
// wpn:pointer;
begin
// wpn:=GetActorActiveItem();
// if (wpn=nil) or not WpnCanShoot(PChar(GetClassName(wpn))) then exit;
// if not (IsExplosed(wpn) or (IsActionProcessing(wpn) and (leftstr(GetCurAnim(wpn), length('anm_fakeshoot'))<>'anm_fakeshoot'))) then begin
// Messenger.SendMessage('gun_jammed', gd_novice);
// end;
end;
procedure OnJammedHintShow_Patch(); stdcall;
asm
pushad
call OnJammedHintShow
popad
end;
//---------------------Ùåë÷êè ïðè îñå÷êàõ/ïóñòîì ìàãàçèíå-----------------------
procedure OnEmptyClick(wpn:pointer);stdcall;
var
anm_started:boolean;
txt:PChar;
act:pointer;
det_anm:PChar;
buf:WpnBuf;
begin
anm_started:=false;
//Ïðè ïàò÷èíãå ìû âûðåçàëè âîñïðîèçâåäåíèå çâóêà. Èñïðàâèì ýòî íåäîðàçóìåíèå îäíîâðåìåííî ñ ïðîèãðûâàíèåì àíèìû.
if not (((GetGLStatus(wpn)=1) or IsGLAttached(wpn)) and IsGLEnabled(wpn)) and IsWeaponJammed(wpn) then begin
txt := 'gunsl_msg_weapon_jammed';
if IsAimNow(wpn) or IsHolderInAimState(wpn) then begin
anm_started:=WeaponAdditionalBuffer.PlayCustomAnimStatic(wpn, 'anm_fakeshoot_aim', 'sndJammedClick', nil, 0, false, true)
end else begin
anm_started:=WeaponAdditionalBuffer.PlayCustomAnimStatic(wpn, 'anm_fakeshoot', 'sndJammedClick', nil, 0, false, true);
end;
end else begin
txt := 'gunsl_msg_weapon_empty';
if IsAimNow(wpn) or IsHolderInAimState(wpn) then begin
anm_started:=WeaponAdditionalBuffer.PlayCustomAnimStatic(wpn, 'anm_fakeshoot_aim', 'sndEmptyClick', nil, 0, false, true);
end else begin
anm_started:=WeaponAdditionalBuffer.PlayCustomAnimStatic(wpn, 'anm_fakeshoot', 'sndEmptyClick', nil, 0, false, true);
end;
end;
act:=GetActor();
if (act<>nil) and (act=GetOwner(wpn)) and anm_started then begin
det_anm:=GetActualCurrentAnim(wpn);
StartCompanionAnimIfNeeded(rightstr(det_anm, length(det_anm)-4), wpn, true);
Messenger.SendMessage(txt, gd_novice);
buf:=GetBuffer(wpn);
if buf<>nil then begin
buf.ApplyLensRecoil(buf.GetMisfireRecoil);
end;
end;
end;
procedure EmptyClick_Patch; stdcall;
asm
pushad
sub ecx, $2e0
push ecx
call OnEmptyClick
popad
ret
end;
//------------------------------------------------------------------------------
function OnWeaponHide(wpn:pointer):boolean;stdcall;
var
act, owner, itm:pointer;
state:cardinal;
begin
//âåðíóòü, ìîæíî ñêðûâàòü èëè íåò
//ðàáîòàåò äëÿ âñåõ CHudItem! êðîìå äåòåêòîðîâ (?)
act:=GetActor();
owner:=GetOwner(wpn);
if (owner<>act) and (act<>nil) then begin
result:=true;
exit;
end;
if not (WpnCanShoot(wpn)) then begin
result:=true;
state:=GetCurrentState(wpn);
if (IsActorSuicideNow() or IsSuicideAnimPlaying(wpn)) then begin
result:=false;
exit;
end;
if (act<>nil) and (owner=act) and IsThrowable(wpn) and ((state=EMissileStates__eReady) or (state=EMissileStates__eThrowStart) or (state=EMissileStates__eThrow) or (state=EMissileStates__eThrowEnd)) then begin
result:=false;
end;
if IsBino(wpn) and (IsAimNow(wpn) or (leftstr(GetActualCurrentAnim(wpn), length('anm_idle_aim'))='anm_idle_aim')) then begin
if IsAimNow(wpn) then begin
if IsAimToggle() then virtual_Action(wpn, kWPN_ZOOM, kActPress) else virtual_Action(wpn, kWPN_ZOOM, kActRelease);
SetActorActionState(act, actModNeedMoveReassign, true);
end;
result:=false
end;
exit;
end;
result:=CanHideWeaponNow(wpn);
if (act<>nil) and (owner=act) then begin