-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathHudItemUtils.pas
2365 lines (1968 loc) · 50.3 KB
/
HudItemUtils.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 HudItemUtils;
{$IFDEF FPC}{$MODE DELPHI}{$ENDIF}
interface
uses MatVectors, WeaponSoundLoader, UIUtils;
type CMotionDef = packed record
bone_or_part:word;
motion:word;
speed:word;
power:word;
accrue:word;
falloff:word;
flags:cardinal;
marks_vec_start:pointer;
marks_vec_end:pointer;
marks_vec_end2:pointer;
end;
pCMotionDef = ^CMotionDef;
function Init():boolean;
function GetPlayerHud():pointer; stdcall;
procedure player_hud__attach_item(wpn:pointer); stdcall;
procedure ChangeParticles(wpn:pointer; name:PChar; particle_type:cardinal); stdcall;
function GetAttachableHudItem(index:cardinal):pointer; stdcall;
function GetCHudItemFromAttachableHudItem(ahi:pointer):pointer; stdcall;
procedure PlayAnimIdle(wpn: pointer); stdcall;
//function GetPositionVector(obj:pointer):pointer;
//function GetCurrentHud(wpn: pointer):pointer; stdcall;
procedure PlayHudAnim(wpn: pointer; anim_name:PChar; bMixIn:boolean); stdcall;
function get_addons_state(wpn:pointer):cardinal; stdcall;
procedure set_addons_state(wpn:pointer; state:cardinal); stdcall;
function IsScopeAttached(wpn:pointer):boolean; stdcall;
function IsSilencerAttached(wpn:pointer):boolean; stdcall;
function IsGLAttached(wpn:pointer):boolean; stdcall;
function IsGLEnabled(wpn:pointer):boolean; stdcall; //UNSAFE! Ëó÷øå èñïîëüçîâàòü IsGrenadeMode! Åñëè íå âûõîäèò, òî ïåðåä âûçîâîì îáÿçàòåëüíî óáåäèòüñÿ, ÷òî ãðàíàòîìåò íà îðóæèè âîîáùå ÅÑÒÜ! Íåêîòîðûå êëàññû îðóæèÿ íå ïîääåðæèâàþò ãðàíàòîìåò, è òîãäà ôóíêöèÿ ìîæåò âîçâðàòèòü ìóñîð èëè äàæå ñãåíåðèðîâàòü âûëåò!
procedure SetGLEnabled(wpn:pointer; state:boolean); stdcall;
function IsWeaponJammed(wpn:pointer):boolean; stdcall;
function CurrentQueueSize(wpn:pointer):integer; stdcall;
function GetInstalledUpgradesCount(wpn:pointer):cardinal; stdcall;
function GetInstalledUpgradeSection(wpn:pointer; index:cardinal):PChar; stdcall;
function FindBoolValueInUpgradesDef(wpn:pointer; key:PChar; def:boolean; scan_after_nodefault:boolean=false):boolean; stdcall;
function FindStrValueInUpgradesDef(wpn:pointer; key:PChar; def:PChar):PChar; stdcall;
function FindIntValueInUpgradesDef(wpn:pointer; key:PChar; def:integer):integer; stdcall;
function ModifyFloatUpgradedValue(wpn:pointer; key:PChar; def:single):single; stdcall;
function GetSection(wpn:pointer):PChar; stdcall;
function GetID(inventoryitem:pointer):word; stdcall;
function GetWeaponVisualName(wpn:pointer):pchar; stdcall;
function GetHUDSection(wpn:pointer):PChar; stdcall;
function GetScopeStatus(wpn:pointer):cardinal; stdcall;
function GetSilencerStatus(wpn:pointer):cardinal; stdcall;
function GetGLStatus(wpn:pointer):cardinal; stdcall;
function GetCurrentScopeSection(wpn:pointer):PChar; stdcall;
function GetScopesCount(wpn:pointer):cardinal; stdcall;
function GetCurrentScopeIndex(wpn:pointer):integer; stdcall;
function GetScopeSection(wpn:pointer; index:cardinal):PChar; stdcall;
procedure SetWpnVisual(wpn:pointer; name:pchar);stdcall;
procedure SetObjectVisual(obj:pointer; name:pchar);stdcall;
procedure SetHUDSection(wpn:pointer; new_hud_section:PChar); stdcall;
function GetAmmoInMagCount(wpn:pointer):cardinal; stdcall;
function GetAmmoInGLCount(wpn:pointer):cardinal; stdcall;
procedure SetAmmoInGLCount(wpn:pointer; cnt:cardinal); stdcall;
function GetCurrentAmmoCount(wpn:pointer):integer; stdcall;
procedure SetCurrentAmmoCount(wpn:pointer; cnt:integer); stdcall;
function GetOwner(wpn:pointer):pointer; stdcall;
function IsAimNow(wpn:pointer):boolean; stdcall;
function GetAimFactor(wpn:pointer):single; stdcall;
procedure SetAimFactor(wpn:pointer; f:single); stdcall;
function IsZoomHideCrosshair(wpn:pointer):boolean; stdcall;
function IsTriStateReload(wpn:pointer):boolean; stdcall;
function GetCurrentState(wpn:pointer):integer; stdcall;
procedure CHudItem_Play_Snd(itm:pointer; alias:PChar); stdcall;
procedure CHudItem_StopAllSounds(itm:pointer); stdcall;
function GetLevelVertexID(wpn:pointer):cardinal; stdcall;
function GetGameVertexID(wpn:pointer):cardinal; stdcall;
function GetSilencerSection(wpn:pointer):PChar; stdcall;
procedure DetachAddon(wpn:pointer; addon_type:integer);stdcall;
function GetGLSection(wpn:pointer):PChar; stdcall;
procedure SetShootLockTime(wpn:pointer; time:single);stdcall;
function GetShootLockTime(wpn:pointer):single;stdcall;
function GetOneShotTime(wpn:pointer):single;stdcall;
procedure SetCurrentScopeType(wpn:pointer; scope_type:byte); stdcall;
function GetCurrentCondition(wpn:pointer):single; stdcall;
procedure SetCondition(wpn:pointer; cond:single); stdcall;
function GetPosition(wpn:pointer):pointer; stdcall;
function GetOrientation(wpn:pointer):pointer; stdcall;
function GetActualCurrentAnim(wpn:pointer):PChar; stdcall;
procedure CSE_SetPosition(swpn:pointer; pos:pointer); stdcall;
procedure CSE_SetAngle(swpn:pointer; ang:pointer); stdcall;
procedure SetCurrentParticles(wpn:pointer; name:PChar; part_type:cardinal); stdcall;
function GetMagCapacity(wpn:pointer):cardinal; stdcall;
procedure SetMagCapacityInCurrentWeaponMode(wpn:pointer; cnt:integer); stdcall;
function GetNextState(wpn:pointer):integer; stdcall;
procedure SetWeaponMisfireStatus(wpn:pointer; status:boolean); stdcall;
procedure ForceWpnHudBriefUpdate(wpn:pointer); stdcall;
procedure PlayCycle (obj:pointer; anim:PChar; mix_in:boolean);stdcall;
function QueueFiredCount(wpn:pointer):integer; stdcall;
procedure SetQueueFiredCount(wpn:pointer; cnt:cardinal); stdcall;
function GetCurrentMotionDef(wpn:pointer):pCMotionDef; stdcall;
function CSE_GetWpnState(swpn:pointer):byte; stdcall;
procedure CSE_SetWpnState(swpn:pointer; s:byte); stdcall;
function CSE_GetAddonsFlags(swpn:pointer):byte; stdcall;
procedure CSE_SetAddonsFlags(swpn:pointer; s:byte); stdcall;
function GetClassName(wpn:pointer):string; stdcall;
function WpnCanShoot(wpn:pointer):boolean;stdcall;
function WpnIsDetector(wpn:pointer):boolean;stdcall;
function IsKnife(wpn:pointer):boolean;stdcall;
function IsThrowable(wpn:pointer):boolean;stdcall;
function IsBino(wpn:pointer):boolean;stdcall;
function IsBM16(wpn:pointer):boolean;stdcall;
function IsDetector(wpn:pointer):boolean;stdcall;
function GetAnimTimeState(wpn:pointer; what:cardinal=$2FC):cardinal; stdcall;
procedure SetSubState(wpn:pointer; substate:byte); stdcall;
function GetSubState(wpn:pointer):byte; stdcall;
{function CountOfCurrentAmmoInRuck(wpn:pointer):cardinal; stdcall;
function CountOfOtherAmmoInRuck(wpn:pointer):cardinal; stdcall;}
procedure SetCurrentState(wpn:pointer; status:cardinal); stdcall;
procedure SetNextState(wpn:pointer; status:cardinal); stdcall;
procedure SetZoomStatus(wpn:pointer; status:boolean); stdcall;
procedure SetZoomFactor(wpn:pointer; factor:single); stdcall;
function IsAimToggle():boolean; stdcall;
function virtual_Action(wpn:pointer; cmd:cardinal; flags:cardinal):boolean; stdcall;
function virtual_IKinematicsAnimated__LL_MotionID(IKinematicsAnimated:pointer; name:PChar):integer; stdcall;
procedure virtual_CHudItem_PlaySound(CHudItem:pointer; alias:PChar; position_ptr:pointer); stdcall;
procedure virtual_CHudItem_SwitchState(Weapon:pointer; state:cardinal); stdcall;
procedure virtual_CShootingObject_FireStart(Weapon:pointer); stdcall;
procedure virtual_CWeaponMagazined__UnloadMagazine(wpn:pointer; spawn_ammo:boolean);stdcall;
procedure virtual_CWeaponMagazined__ReloadMagazine(wpn:pointer);stdcall;
procedure virtual_CWeaponMagazined__OnEmptyClick(wpn:pointer);stdcall;
procedure virtual_CWeaponShotgun__AddCartridge(wpn:pointer; cnt:cardinal);stdcall;
function CWeaponShotgun__HaveCartridgeInInventory(wpn:pointer; cnt:cardinal):boolean; stdcall; //äîëæíî ðàáîòàòü è äëÿ îñòàëüíîãî îðóæèÿ
function CHudItem__HudItemData(CHudItem:pointer):{attachable_hud_item*}pointer; stdcall;
function CHudItem__GetHUDMode(CHudItem:pointer):boolean; stdcall;
procedure CHudItem__PlayHUDMotion(wpn: pointer; anim_name:PChar; bMixIn:boolean; state:cardinal); stdcall;
procedure SetHandsPosOffset(attachable_hud_item:pointer; v:pFVector3);
procedure SetHandsRotOffset(attachable_hud_item:pointer; v:pFVector3);
function GetHandsPosOffset(attachable_hud_item:pointer):FVector3;
function GetHandsRotOffset(attachable_hud_item:pointer):FVector3;
procedure attachable_hud_item__GetBoneOffsetPosDir(this:pointer; bone:PChar;dest_pos:pFVector3; dest_dir:pFVector3; bone_offset:pFVector3);stdcall;
procedure CShootingObject__StartFlameParticles(wpn:pointer);stdcall;
procedure CShootingObject__UpdateParticles(wpn:pointer; CParticlesObject:pointer; pos:pFVector3; vel:pFVector3);stdcall;
procedure CShootingObject__StartParticles(wpn:pointer; CParticlesObject:pointer; particles_name:PChar; pos:pFVector3; vel:pFVector3; auto_remove_flag:boolean);stdcall;
procedure CShootingObject__StopParticles(wpn:pointer; CParticlesObject:pointer); stdcall;
procedure SetParticlesHudStatus(CParticlesObject:pointer; status:boolean); stdcall;
procedure virtual_CShootingObject__FireEnd(wpn:pointer); stdcall;
function GetLastFP(wpn:pointer):FVector3;
function GetLastFD(wpn:pointer):FVector3;
function GetXFORM(wpn:pointer):pFMatrix4x4;stdcall;
procedure SetWorkingState(wpn:pointer; state:boolean); stdcall;
procedure AllowWeaponInertion(wpn:pointer; status:boolean);stdcall;
function IsPending(wpn:pointer):boolean; stdcall;
procedure StartPending(wpn:pointer); stdcall;
procedure EndPending(wpn:pointer); stdcall;
function GetSoundCollection(wpn:pointer):pHUD_SOUND_COLLECTION; stdcall;
function PlaySoundByAnimName(wpn:pointer; anm:string):boolean;
function IsGrenadeMode(wpn:pointer):boolean; stdcall;
procedure PerformSwitchGL(wpn:pointer); stdcall;
function HasDifferentFireModes(wpn:pointer):boolean; stdcall;
function SetQueueFired(wpn:pointer; status:boolean):cardinal; stdcall;
function HasBinocularVision(wpn:pointer):boolean; stdcall;
function GetHudFlags():cardinal; stdcall;
function GetWeaponZoomUI(wpn:pointer):pCUIWindow; stdcall;
function IsWeaponNightVisionPPExist(wpn:pointer):boolean; stdcall;
function CWeapon__CheckForMisfire(wpn:pointer):boolean; stdcall;
const
OFFSET_PARTICLE_WEAPON_CURFLAME:cardinal = $42C;
OFFSET_PARTICLE_WEAPON_CURSHELLS:cardinal = $410;
OFFSET_PARTICLE_WEAPON_CURSMOKE:cardinal = $438;
ANM_TIME_START:cardinal=$304;
ANM_TIME_CUR:cardinal=$300;
ANM_TIME_END:cardinal=$308;
EWeaponStates__eFire:cardinal = $5;
EWeaponStates__eFire2:cardinal = $6;
EWeaponStates__eReload:cardinal = $7;
EWeaponStates__eMisfire:cardinal = $8;
EWeaponStates__eMagEmpty:cardinal = $9;
EWeaponStates__eSwitch:cardinal = $A;
EHudStates__eIdle:cardinal = $0;
EHudStates__eShowing:cardinal = $1;
EHudStates__eHiding:cardinal = $2;
EHudStates__eHidden:cardinal = $3;
EHudStates__eBore:cardinal = $4;
EHudStates__eLastBaseState:cardinal = $4;
EMissileStates__eThrowStart:cardinal = $5;
EMissileStates__eReady:cardinal = $6;
EMissileStates__eThrow:cardinal = $7;
EMissileStates__eThrowEnd:cardinal = $8;
EWeaponSubStates__eSubStateReloadBegin:byte = $0;
EWeaponSubStates__eSubStateReloadInProcess:byte = $1;
EWeaponSubStates__eSubStateReloadEnd:byte = $2;
ANM_LEFTHAND:string='anm_lefthand_';
CWEAPON_SHELL_PARTICLES:cardinal=$410;
CWEAPON_FLAME_PARTICLES_CURRENT:cardinal=$42C;
CWEAPON_FLAME_PARTICLES:cardinal=$430;
CWEAPON_SMOKE_PARTICLES_CURRENT:cardinal=$438;
CWEAPON_SMOKE_PARTICLES:cardinal=$43C;
HUD_DRAW:cardinal = 16;
HUD_DRAW_RT:cardinal = 1024;
HUD_WEAPON_RT2:cardinal = 2048;
//procedure SetCollimatorStatus(wpn:pointer; status:boolean); stdcall;
implementation
uses BaseGameData, gunsl_config, sysutils, ActorUtils, Misc, xr_BoneUtils, windows, dynamic_caster, xr_Cartridge, xr_strings, Vector;
var
PlayHudAnim_Func:cardinal;
_pps_HudFlags:pcardinal;
procedure SetHUDSection(wpn:pointer; new_hud_section:PChar); stdcall;
asm
pushad
pushfd
mov edi, wpn
//Ïîìåñòèì íîâóþ ñåêöèþ â str_container
push new_hud_section
call str_container_dock
test eax, eax
je @finish
mov ecx, [edi+$314]
test ecx, ecx
je @finish
cmp eax, ecx
je @finish
//óâåëè÷èì ñ÷åò÷èê èñïîëüçîâàíèÿ â íîâîé ñòðîêå õóäà è óìåíüøèì â ñòàðîé
add [eax], 1
sub [ecx], 1
//Çàïèøåì íîâûé õóä â îðóæèå
mov [edi+$314], eax
@finish:
popfd
popad
end;
procedure SetWpnVisual (wpn:pointer; name:pchar);stdcall;
//Áóäåì ìèìèêðèðîâàòü ïîä ñêðèïò
asm
pushad
pushfd
add wpn, $000000E8
push wpn
call game_object_GetScriptGameObject
mov ecx, eax
push name
mov eax, xrgame_addr
add eax, $1BFF60
call eax
popfd
popad
end;
procedure SetObjectVisual (obj:pointer; name:pchar);stdcall;
//Áóäåì ìèìèêðèðîâàòü ïîä ñêðèïò
asm
pushad
pushfd
push obj
call game_object_GetScriptGameObject
mov ecx, eax
push name
mov eax, xrgame_addr
add eax, $1BFF60
call eax
popfd
popad
end;
procedure PlayCycle (obj:pointer; anim:PChar; mix_in:boolean);stdcall;
asm
pushad
pushfd
add obj, $000000E8
push obj
call game_object_GetScriptGameObject
movzx ebx, mix_in
push ebx
push anim
mov ecx, eax
mov eax, xrgame_addr
add eax, $1c1ab0
call eax //CScriptGameObject::play_cycle
popfd
popad
end;
function GetInstalledUpgradeSection(wpn:pointer; index:cardinal):PChar; stdcall;
asm
mov eax, wpn
mov eax, [eax+$D8]
mov ecx, index
lea eax, [eax+4*ecx]
mov eax, [eax]
add eax, $10
mov @result, eax;
end;
function GetInstalledUpgradesCount(wpn:pointer):cardinal; stdcall;
asm
mov ecx, wpn
{ mov eax, [ecx+$DE]
cmp eax, 0
je @finish}
mov eax, [ecx+$DC] //Óêàçàòåëü êîíöà ìàññèâà àïãðåéäîâ
mov ecx, [ecx+$D8] //Óêàçàòåëü íà÷àëà ìàññèâà àïãðåéäîâ
sub eax, ecx
shr eax, 2
mov @result, eax
@finish:
end;
function FindBoolValueInUpgradesDef(wpn:pointer; key:PChar; def:boolean; scan_after_nodefault:boolean):boolean; stdcall;
var
i:integer;
str:PChar;
begin
result:=def;
for i:=0 to GetInstalledUpgradesCount(wpn)-1 do begin
str:=GetInstalledUpgradeSection(wpn, i);
str:=game_ini_read_string(str, 'section');
if game_ini_line_exist(str, key) then begin
result:=game_ini_r_bool(str, key);
if (not scan_after_nodefault) and (result<>def) then exit;
end;
end;
end;
function FindStrValueInUpgradesDef(wpn:pointer; key:PChar; def:PChar):PChar; stdcall;
var
i:integer;
str:PChar;
begin
for i:=0 to GetInstalledUpgradesCount(wpn)-1 do begin
str:=GetInstalledUpgradeSection(wpn, i);
str:=game_ini_read_string(str, 'section');
if game_ini_line_exist(str, key) then begin
result:=game_ini_read_string(str, key);
if result<>def then exit;
end;
end;
result:=def;
end;
function FindIntValueInUpgradesDef(wpn:pointer; key:PChar; def:integer):integer; stdcall;
var
i:integer;
str:PChar;
begin
result:=def;
for i:=0 to GetInstalledUpgradesCount(wpn)-1 do begin
str:=GetInstalledUpgradeSection(wpn, i);
str:=game_ini_read_string(str, 'section');
if game_ini_line_exist(str, key) then begin
result:=game_ini_r_int_def(str, key, def);
end;
end;
end;
function ModifyFloatUpgradedValue(wpn:pointer; key:PChar; def:single):single; stdcall;
var
i:integer;
str:PChar;
begin
result:=def;
for i:=0 to GetInstalledUpgradesCount(wpn)-1 do begin
str:=GetInstalledUpgradeSection(wpn, i);
str:=game_ini_read_string(str, 'section');
if game_ini_line_exist(str, key) then begin
result:=result+game_ini_r_single_def(str, key, 0);
end;
end;
end;
function GetAmmoInMagCount(wpn:pointer):cardinal; stdcall;
var
pstart, pend:cardinal;
ptr:pxr_vector;
begin
result:=0;
if wpn = nil then exit;
if not IsGrenadeMode(wpn) then
ptr:= pxr_vector(PChar(wpn)+$6C8)
else
ptr:= pxr_vector(PChar(wpn)+$7EC);
pstart:=cardinal(ptr.start);
pend:=cardinal(ptr.last);
result:=(pend-pstart) div sizeof(CCartridge);
end;
function GetAmmoInGLCount(wpn:pointer):cardinal; stdcall;
var
pstart, pend, gl_status:cardinal;
ptr:pxr_vector;
begin
result:=0;
if wpn = nil then exit;
gl_status:=GetGLStatus(wpn);
if (gl_status=0) or ((gl_status=2) and not IsGLAttached(wpn)) then exit;
if IsGrenadeMode(wpn) then
ptr:= pxr_vector(PChar(wpn)+$6C8)
else
ptr:= pxr_vector(PChar(wpn)+$7EC);
pstart:=cardinal(ptr.start);
pend:=cardinal(ptr.last);
result:=(pend-pstart) div sizeof(CCartridge);
end;
procedure SetAmmoInGLCount(wpn:pointer; cnt:cardinal); stdcall;
//ðàáîòàåò òîëüêî íà óìåíüøåíèå!!!
var
pstart, pend, gl_status:cardinal;
ptr:pointer;
begin
if wpn = nil then exit;
gl_status:=GetGLStatus(wpn);
if (gl_status=0) or ((gl_status=2) and not IsGLAttached(wpn)) then exit;
if IsGrenadeMode(wpn) then
ptr:= PChar(wpn)+$6C8
else
ptr:= PChar(wpn)+$7EC;
pstart:=(pcardinal(ptr))^;
pend:= pstart+cnt*sizeof(CCartridge);
(pcardinal(PChar(ptr)+4))^:=pend;
end;
function IsAimNow(wpn:pointer):boolean; stdcall;
asm
mov @result, 0
pushad
push 0
push RTTI_CWeapon
push RTTI_CHudItemObject
push 0
push wpn
call dynamic_cast
cmp eax, 0
je @finish
mov ecx, wpn
mov al, [ecx+$496]
mov @result, al
@finish:
popad
end;
function IsTriStateReload(wpn:pointer):boolean; stdcall;
asm
mov @result, 0
pushad
push 0
push RTTI_CWeapon
push RTTI_CWeaponShotgun
push 0
push wpn
call dynamic_cast
cmp eax, 0
jne @retval
push 0
push RTTI_CWeapon
push RTTI_CWeaponAutomaticShotgun
push 0
push wpn
call dynamic_cast
cmp eax, 0
je @finish
@retval:
mov ecx, wpn
mov al, [ecx+$458]
mov @result, al
@finish:
popad
end;
function GetOwner(wpn:pointer):pointer; stdcall;
asm
mov eax, wpn
mov eax, [eax+$19c]
mov @result, eax
end;
function GetScopesCount(wpn:pointer):cardinal; stdcall;
asm
pushad
mov edi, wpn
mov ebx, [edi+$6b4]
sub ebx, [edi+$6b0]
shr ebx, 2
mov @result, ebx
popad
end;
function GetCurrentScopeIndex(wpn:pointer):integer; stdcall;
asm
pushad
mov edi, wpn
movzx eax, byte ptr [edi+$6bc]
mov @result, eax
popad
end;
function GetScopeSection(wpn:pointer; index:cardinal):PChar; stdcall;
asm
pushad
mov @result, 0
mov edi, wpn
mov eax, [edi+$6B0]
mov ebx, index
shl ebx, 2
add eax, ebx
cmp eax, [edi+$6B4]
jae @finish
mov eax, [eax]
add eax, $10
mov @result, eax
@finish:
popad
end;
function GetCurrentScopeSection(wpn:pointer):PChar; stdcall;
const
FUNNAME:PChar = 'GetCurrentScopeSection';
EXPR:PChar='Invalid scope idx';
DEFAULT_SCOPE_SECT:PChar='';
asm
pushad
pushfd
mov eax, DEFAULT_SCOPE_SECT
mov @result, eax
mov edi, wpn
mov ebx, [edi+$6b0]
mov edx, [edi+$6b4]
cmp ebx, edx
je @finish
movzx eax, byte ptr [edi+$6bc]
//Ïðîâåðèì, âïèñûâàåìñÿ ëè â äèàïàçîí çíà÷åíèé (âñÿêîå áûâàåò)
sub edx, ebx
shr edx, 2
cmp eax, edx
jnb @assert_gen
mov ebx, [edi+$6b0]
mov ebx, [4*eax+ebx]
add ebx, $10
mov @result, ebx
jmp @finish
@assert_gen:
push FUNNAME
push EXPR
call DebugFail
@finish:
popfd
popad
end;
function GetGLStatus_internal(wpn:pointer):cardinal; stdcall;
asm
mov eax, wpn
mov eax, [eax+$46c]
mov @result, eax
end;
function GetGLStatus(wpn:pointer):cardinal; stdcall;
begin
result:=0;
if dynamic_cast(wpn, 0, RTTI_CHudItemObject, RTTI_CWeaponMagazinedWGrenade, false)=nil then exit;
result:=GetGLStatus_internal(wpn);
end;
function GetSilencerStatus_internal(wpn:pointer):cardinal; stdcall;
asm
mov eax, wpn
mov eax, [eax+$468]
mov @result, eax
end;
function GetSilencerStatus(wpn:pointer):cardinal; stdcall;
begin
result:=0;
if dynamic_cast(wpn, 0, RTTI_CHudItemObject, RTTI_CWeapon, false)=nil then exit;
result:=GetSilencerStatus_internal(wpn);
end;
function GetScopeStatus_internal(wpn:pointer):cardinal; stdcall;
asm
mov eax, wpn
mov eax, [eax+$464]
mov @result, eax
end;
function GetScopeStatus(wpn:pointer):cardinal; stdcall;
begin
result:=0;
if dynamic_cast(wpn, 0, RTTI_CHudItemObject, RTTI_CWeapon, false)=nil then exit;
result:=GetScopeStatus_internal(wpn);
end;
function IsWeaponJammed(wpn:pointer):boolean; stdcall;
asm
mov eax, wpn
mov al, [eax+$45A]
mov @result, al
end;
function CurrentQueueSize(wpn:pointer):integer; stdcall;
asm
mov eax, wpn
mov eax, [eax+$770]
mov @result, eax
end;
function HasDifferentFireModes(wpn:pointer):boolean; stdcall;
asm
mov eax, wpn
mov al, byte ptr [eax+$79E]
mov @result, al
end;
function QueueFiredCount(wpn:pointer):integer; stdcall;
asm
mov eax, wpn
mov eax, [eax+$774]
mov @result, eax
end;
procedure SetQueueFiredCount(wpn:pointer; cnt:cardinal); stdcall;
asm
pushad
mov eax, wpn
mov ecx, cnt
mov [eax+$774], ecx
popad
end;
function GetSection(wpn:pointer):PChar; stdcall;
asm
mov eax, [wpn]
mov eax, [eax+$90]
add eax, $10
mov @result, eax
end;
function GetID(inventoryitem:pointer):word; stdcall;
asm
mov eax, [inventoryitem]
movzx eax, word ptr [eax+$18c]
mov @result, ax
end;
function GetWeaponVisualName(wpn:pointer):pchar; stdcall;
asm
mov eax, [wpn]
mov eax, dword ptr [eax+$198] // NameVisual from CObject parent class
test eax, eax
je @finish
add eax, $10
@finish:
mov @result, eax
end;
function GetHUDSection(wpn:pointer):PChar; stdcall;
asm
mov eax, wpn
mov eax, [eax+$314]
add eax, $10
mov @result, eax
end;
function GetActualCurrentAnim(wpn:pointer):PChar; stdcall;
asm
mov eax, wpn
mov eax, [eax+$2FC]
test eax, eax
je @finish
add eax, $10
@finish:
mov @result, eax
end;
function get_addons_state(wpn:pointer):cardinal; stdcall;
asm
mov eax, wpn
movzx eax, byte ptr [eax+$460]
mov @result, eax
end;
procedure set_addons_state(wpn:pointer; state:cardinal); stdcall;
asm
pushad
mov eax, wpn
mov ebx, state
mov byte ptr [eax+$460], bl
mov ecx, wpn
mov eax, [ecx]
mov eax, [eax+$158] //wpn->InitAddons
call eax
popad
end;
function IsScopeAttached(wpn:pointer):boolean; stdcall;
asm
push wpn
call get_addons_state
test eax, 1
jz @noaddon
mov @result, 1
jmp @finish
@noaddon:
mov @result, 0
@finish:
end;
function IsSilencerAttached(wpn:pointer):boolean; stdcall;
asm
push wpn
call get_addons_state
test eax, 4
jz @noaddon
mov @result, 1
jmp @finish
@noaddon:
mov @result, 0
@finish:
end;
function IsGLAttached(wpn:pointer):boolean; stdcall;
asm
push wpn
call get_addons_state
test eax, 2
jz @noaddon
mov @result, 1
jmp @finish
@noaddon:
mov @result, 0
@finish:
end;
// UNSAFE! Try to use IsGrenadeMode instead
function IsGLEnabled(wpn:pointer):boolean; stdcall;
asm
mov @result, 0
mov eax, wpn
cmp byte ptr [eax+$7F8], 0;
je @finish
mov @result, 1
@finish:
end;
procedure SetGLEnabled(wpn:pointer; state:boolean); stdcall;
asm
pushad
mov eax, wpn
mov bl, state
mov byte ptr [eax+$7F8], bl;
popad
end;
procedure SetWorkingState(wpn:pointer; state:boolean); stdcall;
asm
pushad
mov eax, wpn
mov bl, state
mov byte ptr [eax+$35a], bl;
popad
end;
procedure PlayHudAnim(wpn: pointer; anim_name:PChar; bMixIn:boolean); stdcall;
asm
pushad
pushfd
push anim_name
call str_container_dock
test eax, eax
je @finish
// add [eax], 1
push eax
mov eax, esp
mov ebx, wpn
lea ecx, [ebx+$2E0]
push 0
push 0
movzx edx, bMixIn
push edx //ðåçêèé ëè áóäåò ïåðåõîä ê íåé
push eax //óêàçàòåëü íà èìÿ àíèìû
call PlayHudAnim_Func
pop eax
@finish:
popfd
popad
end;
procedure CHudItem__PlayHUDMotion(wpn: pointer; anim_name:PChar; bMixIn:boolean; state:cardinal); stdcall;
asm
pushad
pushfd
push anim_name
call str_container_dock
test eax, eax
je @finish
// add [eax], 1
push eax
mov eax, esp
mov ebx, wpn
lea ecx, [ebx+$2E0]
push state
push 0
movzx edx, bMixIn
push edx //ðåçêèé ëè áóäåò ïåðåõîä ê íåé
push eax //óêàçàòåëü íà èìÿ àíèìû
call PlayHudAnim_Func
pop eax
@finish:
popfd
popad
end;
function GetClassName(wpn:pointer):string; stdcall;
var i:cardinal;
c:char;
begin
result:='';
for i:=7 downto 0 do begin
asm
push eax
mov eax, wpn
add eax, $F0
add eax, i
mov al, [eax]
mov c, al
pop eax
end;
result:=result+c;
end;
result:=trim(result);
end;
function WpnCanShoot(wpn:pointer):boolean;stdcall;
begin
// result:=(cls='WP_AK74') or (cls='WP_LR300') or (cls='WP_BM16') or (cls='WP_PM') or (cls='WP_GROZA') or (cls='WP_SVD') or (cls='WP_HPSA') or (cls='WP_ASHTG') or (cls='WP_RG6') or (cls='WP_RPG7') or (cls='WP_VAL') or (cls='WP_SHOTG') or (cls='WP_SVU');
result:=(dynamic_cast(wpn, 0, RTTI_CHudItemObject, RTTI_CWeaponMagazined, false)<>nil) and (dynamic_cast(wpn, 0, RTTI_CHudItemObject, RTTI_CWeaponBinoculars, false)=nil);
end;
function IsThrowable(wpn:pointer):boolean;stdcall;
begin
// result:=(cls='G_F1_S') or (cls='G_RGD5_S') or (cls='II_BOLT');
result:=(dynamic_cast(wpn, 0, RTTI_CHudItemObject, RTTI_CMissile, false)<>nil);
end;
function IsDetector(wpn:pointer):boolean;stdcall;
begin
result:=(dynamic_cast(wpn, 0, RTTI_CHudItemObject, RTTI_CCustomDetector, false)<>nil);
end;
function IsBino(wpn:pointer):boolean;stdcall;
begin
// result:=(cls='WP_BINOC');
result:=(dynamic_cast(wpn, 0, RTTI_CHudItemObject, RTTI_CWeaponBinoculars, false)<>nil);
end;
function IsBM16(wpn:pointer):boolean;stdcall;
begin
result:=(dynamic_cast(wpn, 0, RTTI_CHudItemObject, RTTI_CWeaponBM16, false)<>nil);
end;
function GetCurrentState(wpn:pointer):integer; stdcall;
asm
mov eax, wpn
mov eax, [eax+$2E4]
mov @result, eax
end;
procedure SetCurrentState(wpn:pointer; status:cardinal); stdcall;
asm
push eax
push ecx
mov eax, wpn
mov ecx, status
mov [eax+$2e4], ecx
pop ecx
pop eax
end;
procedure SetNextState(wpn:pointer; status:cardinal); stdcall;
asm
push eax
push ecx
mov eax, wpn
mov ecx, status
mov [eax+$2e8], ecx
pop ecx
pop eax
end;
procedure SetZoomStatus(wpn:pointer; status:boolean); stdcall;
asm
push eax
push ecx
mov eax, wpn
mov cl, status