-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathWeaponInertion.pas
940 lines (770 loc) · 34.7 KB
/
WeaponInertion.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
unit WeaponInertion;
{$IFDEF FPC}{$MODE DELPHI}{$ENDIF}
interface
function Init():boolean;
procedure UpdateInertion (wpn:pointer);
procedure UpdateWeaponOffset(act:pointer; delta:cardinal);
procedure ResetWpnOffset();
procedure ResetCamHeight();
procedure ResetItmHudOffset(itm:pointer); stdcall;
implementation
uses BaseGameData, gunsl_config, HudItemUtils, windows, strutils, MatVectors, ActorUtils, DetectorUtils, sysutils, math, WeaponAdditionalBuffer, ControllerMonster;
type default_hud_coords_params = packed record
hud_sect:PAnsiChar;
hands_position:FVector3;
hands_orientation:FVector3;
is16x9:boolean;
end;
var
i_p:weapon_inertion_params;
time_accumulator:cardinal;
_last_camera_height:single;
_last_cam_update_time:cardinal;
_landing_effect_time_remains:cardinal;
_landing2_effect_time_remains:cardinal;
_landing_effect_finish_time_remains:cardinal;
_last_default_hud_params:default_hud_coords_params;
tocrouch_time_remains, fromcrouch_time_remains:cardinal;
toslowcrouch_time_remains, fromslowcrouch_time_remains:cardinal;
torlookout_time_remains, fromrlookout_time_remains:cardinal;
tollookout_time_remains, fromllookout_time_remains:cardinal;
function GetDefaultHudCoords(hud_sect:PAnsiChar):default_hud_coords_params;
var
zerovec:FVector3;
begin
if (_last_default_hud_params.hud_sect <> hud_sect) or (Is16x9()<>_last_default_hud_params.is16x9) then begin
v_zero(@zerovec);
_last_default_hud_params.hud_sect:=hud_sect;
_last_default_hud_params.is16x9:=Is16x9();
if _last_default_hud_params.is16x9 then begin
_last_default_hud_params.hands_position:=game_ini_read_vector3_def(hud_sect, 'hands_position_16x9', @zerovec);
_last_default_hud_params.hands_orientation:=game_ini_read_vector3_def(hud_sect, 'hands_orientation_16x9', @zerovec);
end else begin
_last_default_hud_params.hands_position:=game_ini_read_vector3_def(hud_sect, 'hands_position', @zerovec);
_last_default_hud_params.hands_orientation:=game_ini_read_vector3_def(hud_sect, 'hands_orientation', @zerovec);
end;
end;
result:=_last_default_hud_params;
end;
procedure ResetWpnOffset();
begin
time_accumulator:=0;
tocrouch_time_remains:=0;
fromcrouch_time_remains:=0;
toslowcrouch_time_remains:=0;
fromslowcrouch_time_remains:=0;
torlookout_time_remains:=0;
fromrlookout_time_remains:=0;
tollookout_time_remains:=0;
fromllookout_time_remains:=0;
end;
function ValueSineInterpolation_f(x:single; max_val:single; period:single):single;
begin
result:=0.5*max_val*(1+sin(-pi/2 + x*pi/period));
end;
function ValueSineInterpolation_f_inverse(cur_val:single; max_val:single; period:single):single;
begin
result:=(arcsin((2*cur_val/max_val) - 1)+pi/2)*(period/pi);
end;
function ValueSineInterpolation(cur_val:single; max_val:single; period:single; dt:single):single;
var
x:single;
const
EPS:single=0.00001;
begin
//1) ïîëó÷èì õ ïî f(x)
//2) âåðíåì f(x+dt)
if abs(dt)<EPS then begin
result:=cur_val;
exit;
end else if (dt>0) and (abs(cur_val-max_val)<EPS) then begin
result:=max_val;
exit;
end else if (dt<0) and (abs(cur_val-max_val)<EPS) then begin
result:=0;
exit;
end;
x:=ValueSineInterpolation_f_inverse(cur_val, max_val, period);
if (dt>0) and (x+dt>period) then begin
x:=period;
end else if (dt<0) and (x-dt<0) then begin
x:=0;
end else begin
x:=x+dt;
end;
result:=ValueSineInterpolation_f(x, max_val, period);
end;
procedure ResetCamHeight();
begin
_last_camera_height:=0;
_last_cam_update_time:=0;
_landing_effect_time_remains:=0;
_landing2_effect_time_remains:=0;
_landing_effect_finish_time_remains:=0;
end;
procedure CWeapon__OnZoomOut_inertion(wpn:pointer); stdcall;
begin
if game_ini_r_bool_def(GetHUDSection(wpn), 'zoom_inertion', false) and game_ini_r_bool_def(GetHUDSection(wpn), 'hud_inertion', true) then begin
AllowWeaponInertion(wpn, true);
end;
end;
procedure CWeapon__OnZoomOut_inertion_Patch(); stdcall;
asm
pushad
push esi
call CWeapon__OnZoomOut_inertion
popad
end;
function GradientClamp(target, current, koef, eps:single):single;
begin
result:=(target-current)*koef;
if abs(result)<eps then result:=(target-current);
end;
type cached_inertion_params = packed record
main:weapon_inertion_params;
gl:weapon_inertion_params;
aim:weapon_inertion_params;
section:string;
end;
var
cached_inertion_wpn:cached_inertion_params;
cached_inertion_scope:cached_inertion_params;
cached_hud_inertion_enabled:cached_cfg_param_bool;
function GetCachedInertionForWeapon(section:string):cached_inertion_params;
begin
if (length(cached_inertion_wpn.section) <> length(section)) or (cached_inertion_wpn.section <> section) then begin
cached_inertion_wpn.section:=section;
cached_inertion_wpn.main.pitch_offset_r:=game_ini_r_single_def(PAnsiChar(section), 'inertion_pitch_offset_r', -1);
cached_inertion_wpn.main.pitch_offset_n:=game_ini_r_single_def(PAnsiChar(section), 'inertion_pitch_offset_n', -1);
cached_inertion_wpn.main.pitch_offset_d:=game_ini_r_single_def(PAnsiChar(section), 'inertion_pitch_offset_d', -1);
cached_inertion_wpn.main.origin_offset:=game_ini_r_single_def(PAnsiChar(section), 'inertion_origin_offset', -1);
cached_inertion_wpn.main.speed:=game_ini_r_single_def(PAnsiChar(section), 'inertion_speed', -1);
cached_inertion_wpn.gl.pitch_offset_r:=game_ini_r_single_def(PAnsiChar(section), 'inertion_gl_pitch_offset_r', -1);
cached_inertion_wpn.gl.pitch_offset_n:=game_ini_r_single_def(PAnsiChar(section), 'inertion_gl_pitch_offset_n', -1);
cached_inertion_wpn.gl.pitch_offset_d:=game_ini_r_single_def(PAnsiChar(section), 'inertion_gl_pitch_offset_d', -1);
cached_inertion_wpn.gl.origin_offset:=game_ini_r_single_def(PAnsiChar(section), 'inertion_gl_origin_offset', -1);
cached_inertion_wpn.gl.speed:=game_ini_r_single_def(PAnsiChar(section), 'inertion_gl_speed', -1);
cached_inertion_wpn.aim.pitch_offset_r:=game_ini_r_single_def(PAnsiChar(section), 'inertion_aim_pitch_offset_r', -1);
cached_inertion_wpn.aim.pitch_offset_n:=game_ini_r_single_def(PAnsiChar(section), 'inertion_aim_pitch_offset_n', -1);
cached_inertion_wpn.aim.pitch_offset_d:=game_ini_r_single_def(PAnsiChar(section), 'inertion_aim_pitch_offset_d', -1);
cached_inertion_wpn.aim.origin_offset:=game_ini_r_single_def(PAnsiChar(section), 'inertion_aim_origin_offset', -1);
cached_inertion_wpn.aim.speed:=game_ini_r_single_def(PAnsiChar(section), 'inertion_aim_speed', -1);
end;
result:=cached_inertion_wpn;
end;
function GetCachedInertionForScope(section:string):cached_inertion_params;
begin
if (length(cached_inertion_scope.section) <> length(section)) or (cached_inertion_scope.section <> section) then begin
cached_inertion_scope.section:=section;
cached_inertion_scope.main.pitch_offset_r:=game_ini_r_single_def(PAnsiChar(section), 'inertion_pitch_offset_r_factor', 1.0);
cached_inertion_scope.main.pitch_offset_n:=game_ini_r_single_def(PAnsiChar(section), 'inertion_pitch_offset_n_factor', 1.0);
cached_inertion_scope.main.pitch_offset_d:=game_ini_r_single_def(PAnsiChar(section), 'inertion_pitch_offset_d_factor', 1.0);
cached_inertion_scope.main.origin_offset:=game_ini_r_single_def(PAnsiChar(section), 'inertion_origin_offset_factor', 1.0);
cached_inertion_scope.main.speed:=game_ini_r_single_def(PAnsiChar(section), 'inertion_speed_factor', 1.0);
cached_inertion_scope.gl.pitch_offset_r:=game_ini_r_single_def(PAnsiChar(section), 'inertion_gl_pitch_offset_r', -1);
cached_inertion_scope.gl.pitch_offset_n:=game_ini_r_single_def(PAnsiChar(section), 'inertion_gl_pitch_offset_n', -1);
cached_inertion_scope.gl.pitch_offset_d:=game_ini_r_single_def(PAnsiChar(section), 'inertion_gl_pitch_offset_d', -1);
cached_inertion_scope.gl.origin_offset:=game_ini_r_single_def(PAnsiChar(section), 'inertion_gl_origin_offset', -1);
cached_inertion_scope.gl.speed:=game_ini_r_single_def(PAnsiChar(section), 'inertion_gl_speed', -1);
cached_inertion_scope.aim.pitch_offset_r:=game_ini_r_single_def(PAnsiChar(section), 'inertion_aim_pitch_offset_r', -1);
cached_inertion_scope.aim.pitch_offset_n:=game_ini_r_single_def(PAnsiChar(section), 'inertion_aim_pitch_offset_n', -1);
cached_inertion_scope.aim.pitch_offset_d:=game_ini_r_single_def(PAnsiChar(section), 'inertion_aim_pitch_offset_d', -1);
cached_inertion_scope.aim.origin_offset:=game_ini_r_single_def(PAnsiChar(section), 'inertion_aim_origin_offset', -1);
cached_inertion_scope.aim.speed:=game_ini_r_single_def(PAnsiChar(section), 'inertion_aim_speed', -1);
end;
result:=cached_inertion_scope;
end;
procedure ApplyInertionParamsWithDef(var dest:weapon_inertion_params; new:weapon_inertion_params; def:weapon_inertion_params);
begin
if new.pitch_offset_r < 0 then dest.pitch_offset_r := def.pitch_offset_r else dest.pitch_offset_r := new.pitch_offset_r;
if new.pitch_offset_n < 0 then dest.pitch_offset_n := def.pitch_offset_n else dest.pitch_offset_n := new.pitch_offset_n;
if new.pitch_offset_d < 0 then dest.pitch_offset_d := def.pitch_offset_d else dest.pitch_offset_d := new.pitch_offset_d;
if new.origin_offset < 0 then dest.origin_offset := def.origin_offset else dest.origin_offset := new.origin_offset;
if new.speed < 0 then dest.speed := def.speed else dest.speed := new.speed;
end;
procedure UpdateInertion (wpn:pointer);
var
koef:single;
sect, scp:PChar;
def_inert, aim_inert:weapon_inertion_params;
wpn_inert, scope_inert:cached_inertion_params;
const
eps:single = 0.0003;
g_koef:single = 0.07;
begin
def_inert:=GetStdInertion(false);
if wpn<>nil then begin
sect:=GetHUDSection(wpn);
if not GetCachedCfgParamBoolDef(cached_hud_inertion_enabled, sect, 'hud_inertion', true) then begin
AllowWeaponInertion(wpn, false);
end;
wpn_inert:=GetCachedInertionForWeapon(sect);
ApplyInertionParamsWithDef(def_inert, wpn_inert.main, def_inert);
if (GetScopeStatus(wpn)=2) and IsScopeAttached(wpn) then begin
//âëèÿíèå óñòàíîâëåííîãî ïðèöåëà íà èíåðöèþ âíå çóìà
scp:=GetCurrentScopeSection(wpn);
scope_inert:=GetCachedInertionForScope(scp);
def_inert.pitch_offset_r:=def_inert.pitch_offset_r*scope_inert.main.pitch_offset_r;
def_inert.pitch_offset_n:=def_inert.pitch_offset_n*scope_inert.main.pitch_offset_n;
def_inert.pitch_offset_d:=def_inert.pitch_offset_d*scope_inert.main.pitch_offset_d;
def_inert.origin_offset:=def_inert.origin_offset*scope_inert.main.origin_offset;
def_inert.speed:=def_inert.speed*scope_inert.main.speed;
end;
if IsAimNow(wpn) or (leftstr(GetActualCurrentAnim(wpn), length('anm_idle_aim'))='anm_idle_aim') then begin
aim_inert:=GetStdInertion(true);
if IsGrenadeMode(wpn) then begin
ApplyInertionParamsWithDef(aim_inert, wpn_inert.gl, aim_inert);
end else begin
ApplyInertionParamsWithDef(aim_inert, wpn_inert.aim, aim_inert);
end;
if (GetScopeStatus(wpn)=2) and IsScopeAttached(wpn) then begin
//âëèÿíèå óñòàíîâëåííîãî ïðèöåëà íà èíåðöèþ â çóìå
scp:=GetCurrentScopeSection(wpn);
scope_inert:=GetCachedInertionForScope(scp);
if IsGrenadeMode(wpn) then begin
ApplyInertionParamsWithDef(aim_inert, scope_inert.gl, aim_inert);
end else begin
ApplyInertionParamsWithDef(aim_inert, scope_inert.aim, aim_inert);
end;
end;
koef:=GetAimFactor(wpn);
def_inert.pitch_offset_r:= def_inert.pitch_offset_r - (def_inert.pitch_offset_r-aim_inert.pitch_offset_r)*koef;
def_inert.pitch_offset_n:= def_inert.pitch_offset_n - (def_inert.pitch_offset_n-aim_inert.pitch_offset_n)*koef;
def_inert.pitch_offset_d:= def_inert.pitch_offset_d - (def_inert.pitch_offset_d-aim_inert.pitch_offset_d)*koef;
def_inert.origin_offset:= def_inert.origin_offset - (def_inert.origin_offset-aim_inert.origin_offset)*koef;
def_inert.speed:= def_inert.speed - (def_inert.speed-aim_inert.speed)*koef;
end;
end;
i_p:=def_inert;
end;
procedure CWeapon__OnZoomIn_inertion(wpn:pointer); stdcall;
begin
if game_ini_r_bool_def(GetHUDSection(wpn), 'zoom_inertion', false) then begin
AllowWeaponInertion(wpn, false);
end;
end;
procedure CWeapon__OnZoomIn_inertion_Patch(); stdcall;
asm
pushad
push esi
call CWeapon__OnZoomIn_inertion
popad
end;
procedure AddOffsets(base:string; section:PChar; pos:pFVector3; rot:pFVector3; koef:single=1.0);
var
tmp, zerovec:FVector3;
begin
v_zero(@zerovec);
if Is16x9() then begin
tmp:=game_ini_read_vector3_def(section, PChar(base+'_pos_16x9'), @zerovec);
v_mul(@tmp, koef);
v_add(pos, @tmp);
tmp:=game_ini_read_vector3_def(section, PChar(base+'_rot_16x9'), @zerovec);
v_mul(@tmp, koef);
v_add(rot, @tmp);
end else begin
tmp:=game_ini_read_vector3_def(section, PChar(base+'_pos'), @zerovec);
v_mul(@tmp, koef);
v_add(pos, @tmp);
tmp:=game_ini_read_vector3_def(section, PChar(base+'_rot'), @zerovec);
v_mul(@tmp, koef);
v_add(rot, @tmp);
end;
end;
procedure AddSuicideOffset(act:pointer; section:PChar; pos:pFVector3; rot:pFVector3);stdcall;
begin
if game_ini_r_bool_def(section, 'prohibit_suicide', false) then exit;
if game_ini_r_bool_def(section, 'no_other_hud_moving_while_suicide', false) then begin
v_zero(rot);
v_zero(pos);
end;
AddOffsets('hud_move_suicide_offset', section, pos, rot);
//todo:ðàçíûå ñêîðîñòè ñóèöèäà â çàâèñèìîñòè îò ïñè-çàùèùåííîñòè
end;
procedure GetCurrentTargetOffset_aim(act:pointer; section:PChar; pos:pFVector3; rot:pFVector3; factor:pSingle);
var
zerovec:FVector3;
koef:single;
begin
v_zero(pos);
v_zero(rot);
v_zero(@zerovec);
factor^:=1;
if GetActorActionState(act, actCrouch) and GetActorActionState(act, actSlow) then begin
koef:=game_ini_r_single_def(section, 'hud_aim_move_slow_crouch_factor', 1.0);
end else if GetActorActionState(act, actCrouch) then begin
koef:=game_ini_r_single_def(section, 'hud_aim_move_crouch_factor', 1.0);
end else if GetActorActionState(act, actSlow) then begin
koef:=game_ini_r_single_def(section, 'hud_aim_move_slow_factor', 1.0);
end else begin
koef:=1;
end;
if tocrouch_time_remains>0 then begin
AddOffsets('hud_aim_move_to_crouch_offset', section, pos, rot, koef);
end;
if fromcrouch_time_remains>0 then begin
AddOffsets('hud_aim_move_from_crouch_offset', section, pos, rot, koef);
end;
if toslowcrouch_time_remains>0 then begin
AddOffsets('hud_aim_move_to_slow_crouch_offset', section, pos, rot, koef);
end;
if fromslowcrouch_time_remains>0 then begin
AddOffsets('hud_aim_move_from_slow_crouch_offset', section, pos, rot, koef);
end;
if torlookout_time_remains>0 then begin
AddOffsets('hud_aim_move_to_rlookout_offset', section, pos, rot, koef);
end;
if fromrlookout_time_remains>0 then begin
AddOffsets('hud_aim_move_from_rlookout_offset', section, pos, rot, koef);
end;
if tollookout_time_remains>0 then begin
AddOffsets('hud_aim_move_to_llookout_offset', section, pos, rot, koef);
end;
if fromllookout_time_remains>0 then begin
AddOffsets('hud_aim_move_from_llookout_offset', section, pos, rot, koef);
end;
end;
var
cached_hud_move_stabilize_factor:cached_cfg_param_float;
cached_hud_move_slow_crouch_factor:cached_cfg_param_float;
cached_hud_move_crouch_factor:cached_cfg_param_float;
cached_hud_move_slow_factor:cached_cfg_param_float;
procedure GetCurrentTargetOffset(act:pointer; section:PChar; pos:pFVector3; rot:pFVector3; factor:pSingle);
var
zerovec:FVector3;
koef:single;
begin
factor^:=GetCachedCfgParamFloatDef(cached_hud_move_stabilize_factor, section, 'hud_move_stabilize_factor', 2.0);
v_zero(pos);
v_zero(rot);
v_zero(@zerovec);
if GetActorActionState(act, actCrouch) and GetActorActionState(act, actSlow) then begin
koef:=GetCachedCfgParamFloatDef(cached_hud_move_slow_crouch_factor, section, 'hud_move_slow_crouch_factor', 1.0);
end else if GetActorActionState(act, actCrouch) then begin
koef:=GetCachedCfgParamFloatDef(cached_hud_move_crouch_factor, section, 'hud_move_crouch_factor', 1.0);
end else if GetActorActionState(act, actSlow) then begin
koef:=GetCachedCfgParamFloatDef(cached_hud_move_slow_factor, section, 'hud_move_slow_factor', 1.0);
end else begin
koef:=1;
end;
if tocrouch_time_remains>0 then begin
AddOffsets('hud_move_to_crouch_offset', section, pos, rot, koef);
factor^:=1;
end;
if fromcrouch_time_remains>0 then begin
AddOffsets('hud_move_from_crouch_offset', section, pos, rot, koef);
factor^:=1;
end;
if toslowcrouch_time_remains>0 then begin
AddOffsets('hud_move_to_slow_crouch_offset', section, pos, rot, koef);
factor^:=1;
end;
if fromslowcrouch_time_remains>0 then begin
AddOffsets('hud_move_from_slow_crouch_offset', section, pos, rot, koef);
factor^:=1;
end;
if torlookout_time_remains>0 then begin
AddOffsets('hud_move_to_rlookout_offset', section, pos, rot, koef);
factor^:=1;
end;
if fromrlookout_time_remains>0 then begin
AddOffsets('hud_move_from_rlookout_offset', section, pos, rot, koef);
factor^:=1;
end;
if tollookout_time_remains>0 then begin
AddOffsets('hud_move_to_llookout_offset', section, pos, rot, koef);
factor^:=1;
end;
if fromllookout_time_remains>0 then begin
AddOffsets('hud_move_from_llookout_offset', section, pos, rot, koef);
factor^:=1;
end;
if GetActorActionState(act, actRLookout) and not GetActorActionState(act, actLLookout) then begin
AddOffsets('hud_move_rlookout_offset', section, pos, rot, koef);
factor^:=game_ini_r_single_def(section, 'hud_move_rlookout_offset_speed_factor', 1);
end;
if GetActorActionState(act, actLLookout) and not GetActorActionState(act, actRLookout) then begin
AddOffsets('hud_move_llookout_offset', section, pos, rot, koef);
factor^:=game_ini_r_single_def(section, 'hud_move_llookout_offset_speed_factor', 1);
end;
if GetActorActionState(act, actMovingLeft) and not GetActorActionState(act, actMovingRight) then begin
AddOffsets('hud_move_left_offset', section, pos, rot, koef);
factor^:=1;
end;
if GetActorActionState(act, actMovingRight) and not GetActorActionState(act, actMovingLeft) then begin
AddOffsets('hud_move_right_offset', section, pos, rot, koef);
factor^:=1;
end;
if GetActorActionState(act, actMovingForward) and not GetActorActionState(act, actMovingBack) then begin
AddOffsets('hud_move_forward_offset', section, pos, rot, koef);
factor^:=1;
end;
if GetActorActionState(act, actMovingBack) and not GetActorActionState(act, actMovingForward) then begin
AddOffsets('hud_move_back_offset', section, pos, rot, koef);
factor^:=1;
end;
if GetActorActionState(act, actJump) and not GetActorActionState(act, actFall) and not GetActorActionState(act, actLanding) and not GetActorActionState(act, actLanding2) then begin
AddOffsets('hud_move_jump_offset', section, pos, rot, koef);
factor^:=1;
end;
if GetActorActionState(act, actFall) and not GetActorActionState(act, actJump) and not GetActorActionState(act, actLanding) and not GetActorActionState(act, actLanding2) then begin
AddOffsets('hud_move_fall_offset', section, pos, rot, koef);
factor^:=1;
end;
if GetActorActionState(act, actLanding) and not GetActorActionState(act, actJump) and not GetActorActionState(act, actFall) and not GetActorActionState(act, actLanding2) then begin
AddOffsets('hud_move_landing_offset', section, pos, rot, koef);
factor^:=1;
end;
if GetActorActionState(act, actLanding2) and not GetActorActionState(act, actJump) and not GetActorActionState(act, actFall) and not GetActorActionState(act, actLanding) then begin
AddOffsets('hud_move_landing2_offset', section, pos, rot, koef);
factor^:=1;
end;
end;
procedure ResetItmHudOffset(itm:pointer); stdcall;
var
zerovec:FVector3;
hid:pointer;
section:PChar;
def_hud_params:default_hud_coords_params;
begin
hid:=CHudItem__HudItemData(itm);
if hid=nil then exit;
section:=GetHUDSection(itm);
def_hud_params:=GetDefaultHudCoords(section);
SetHandsPosOffset(hid, @def_hud_params.hands_position);
SetHandsRotOffset(hid, @def_hud_params.hands_orientation);
end;
var
cached_hud_move_weaponhide_factor:cached_cfg_param_float;
cached_hud_move_unzoom_factor:cached_cfg_param_float;
cached_hud_move_speed_rot:cached_cfg_param_float;
cached_hud_move_speed_pos:cached_cfg_param_float;
cached_suicide_speed_rot:cached_cfg_param_float;
cached_suicide_speed_pos:cached_cfg_param_float;
procedure UpdateWeaponOffset(act:pointer; delta:cardinal);
var
itm, det, HID:pointer;
section:PChar;
factor, speed_pos, speed_rot:single;
jitter:jitter_params;
targetpos, targetrot, cur_pos, cur_rot, pos, rot, zerovec:FVector3;
def_hud_params:default_hud_coords_params;
begin
if not IsWeaponmoveEnabled() then exit;
itm:=GetActorActiveItem();
if itm=nil then begin
itm:=GetActiveDetector(act);
det:=nil;
end else begin
det:=GetActiveDetector(act);
end;
if itm=nil then exit;
HID:=CHudItem__HudItemData(itm);
if HID=nil then exit;
time_accumulator:=time_accumulator+delta;
section:=GetHUDSection(itm);
v_zero(@zerovec);
if GetActorActionState(act, actCrouch, mState_WISHFUL) and not GetActorActionState(act, actCrouch, mState_REAL) then begin
//íà÷àëè ïðèñÿä
tocrouch_time_remains:=floor(game_ini_r_single_def(section, 'to_crouch_time', 0)*1000);
fromcrouch_time_remains:=0;
end else if not GetActorActionState(act, actCrouch, mState_WISHFUL) and GetActorActionState(act, actCrouch, mState_REAL) then begin
//çàêîí÷èëè ïðèñÿä
fromcrouch_time_remains:=floor(game_ini_r_single_def(section, 'from_crouch_time', 0)*1000);
tocrouch_time_remains:=0;
end;
if GetActorActionState(act, actCrouch, mState_WISHFUL) and GetActorActionState(act, actSlow, mState_WISHFUL) and not GetActorActionState(act, actSlow, mState_REAL) then begin
//íà÷àëè ïðèñÿä
toslowcrouch_time_remains:=floor(game_ini_r_single_def(section, 'to_slow_crouch_time', 0)*1000);
fromslowcrouch_time_remains:=0;
end else if GetActorActionState(act, actCrouch, mState_WISHFUL) and not GetActorActionState(act, actSlow, mState_WISHFUL) and GetActorActionState(act, actSlow, mState_REAL) then begin
//çàêîí÷èëè ïðèñÿä
fromslowcrouch_time_remains:=floor(game_ini_r_single_def(section, 'from_slow_crouch_time', 0)*1000);
toslowcrouch_time_remains:=0;
end;
if not (GetActorActionState(act, actRLookout, mState_REAL) and GetActorActionState(act, actLLookout, mState_REAL)) then begin
//åñëè îäíîâðåìåííî âûãëÿäûâàåì âëåâî è âïðàâî - ÷òî-òî òóò íå òàê...
if GetActorActionState(act, actRLookout, mState_WISHFUL) and not GetActorActionState(act, actRLookout, mState_REAL) then begin
//íà÷àëè âûãëÿäûâàòü âïðàâî
torlookout_time_remains:=floor(game_ini_r_single_def(section, 'to_rlookout_time', 0)*1000);
fromrlookout_time_remains:=0;
end else if not GetActorActionState(act, actRLookout, mState_WISHFUL) and GetActorActionState(act, actRLookout, mState_REAL) then begin
//çàêîí÷èëè âûãëÿäûâàòü âïðàâî
fromrlookout_time_remains:=floor(game_ini_r_single_def(section, 'from_rlookout_time', 0)*1000);
torlookout_time_remains:=0;
end;
if GetActorActionState(act, actLLookout, mState_WISHFUL) and not GetActorActionState(act, actLLookout, mState_REAL) then begin
//íà÷àëè âûãëÿäûâàòü âëåâî
tollookout_time_remains:=floor(game_ini_r_single_def(section, 'to_llookout_time', 0)*1000);
fromllookout_time_remains:=0;
end else if not GetActorActionState(act, actLLookout, mState_WISHFUL) and GetActorActionState(act, actLLookout, mState_REAL) then begin
//çàêîí÷èëè âûãëÿäûâàòü âëåâî
fromllookout_time_remains:=floor(game_ini_r_single_def(section, 'from_llookout_time', 0)*1000);
tollookout_time_remains:=0;
end;
end;
//ïðî÷èòàåì êîíôèãîâûå óìîë÷àíèÿ
def_hud_params:=GetDefaultHudCoords(section);
pos:=def_hud_params.hands_position;
rot:=def_hud_params.hands_orientation;
//âû÷èñëèì öåëåâîå ñìåùåíèå îò ðàâíîâåñèÿ
if (cardinal(GetCurrentState(itm))=EHudStates__eHiding) or ((det<>nil) and (cardinal(GetCurrentState(det))=EHudStates__eHiding)) then begin
v_zero(@targetpos);
v_zero(@targetrot);
factor:=GetCachedCfgParamFloatDef(cached_hud_move_weaponhide_factor, section, 'hud_move_weaponhide_factor', 1.0);
end else if (WpnCanShoot(itm) or IsBino(itm)) and (IsAimNow(itm) or IsHolderInAimState(itm) or (GetAimFactor(itm)>0)) then begin
GetCurrentTargetOffset_aim(act, section, @targetpos, @targetrot, @factor);
factor:=GetCachedCfgParamFloatDef(cached_hud_move_unzoom_factor, section, 'hud_move_unzoom_factor', 1.0);
end else begin
GetCurrentTargetOffset(act, section, @targetpos, @targetrot, @factor);
if IsActorSuicideNow() and CheckActorVisibilityForController() then begin
AddSuicideOffset(act, section, @targetpos, @targetrot);
end else if (hid<>nil) and (not GetActorActionState(act, actMovingForward)) and (not GetActorActionState(act, actMovingBack)) and (not GetActorActionState(act, actMovingLeft)) and (not GetActorActionState(act, actMovingRight)) and (not GetActorActionState(act, actMovingForward)) and (not GetActorActionState(act, actSprint)) and not GetActorActionState(act, actJump) and not GetActorActionState(act, actFall) and not GetActorActionState(act, actLanding) and not GetActorActionState(act, actLanding2) then begin
//todo:ñìåùåíèå â èäëå
end;
end;
//íàõîäèì öåëåâóþ ïîçèöèþ
v_add(@targetpos, @pos);
v_add(@targetrot, @rot);
//ñìîòðèì íà ñêîðîñòü ñäâèãà
if not IsActorSuicideNow() and not IsSuicideAnimPlaying(itm) then begin
speed_rot:= GetCachedCfgParamFloatDef(cached_hud_move_speed_rot, section, 'hud_move_speed_rot', 0.4) * factor/100;
speed_pos:= GetCachedCfgParamFloatDef(cached_hud_move_speed_pos, section, 'hud_move_speed_pos', 0.1) * factor/100;
end else begin
speed_rot:=GetCachedCfgParamFloatDef(cached_suicide_speed_rot, section, 'suicide_speed_rot', 0.002);
speed_pos:=GetCachedCfgParamFloatDef(cached_suicide_speed_pos, section, 'suicide_speed_pos', 0.2);
end;
//120 êîððåêöèé â ñåêóíäó ê âû÷èñëåííîìó ïîëîæåíèþ
while (time_accumulator>8) do begin
//ñìîòðèì, êóäà áóäåì äâèãàòü õóä
pos:=targetpos;
rot:=targetrot;
cur_pos:=GetHandsPosOffset(hid);
cur_rot:=GetHandsRotOffset(hid);
v_sub(@pos, @cur_pos);
v_sub(@rot, @cur_rot);
//ïåðåñ÷èòûâàåì âåêòîð ñäâèãà ñ ó÷åòîì ñêîðîñòè
if IsActorSuicideNow() then begin
//èäåì ëèíåéíî
if v_length(@pos)>speed_pos then v_setlength(@pos, speed_pos);
if v_length(@rot)>speed_rot then v_setlength(@rot, speed_rot);
end else begin
if v_length(@pos)>0.0001 then v_mul(@pos, speed_pos);
if v_length(@rot)>0.0001 then v_mul(@rot, speed_rot);
end;
//äîáàâëÿåì ïåðåñ÷èòàííûé ñäâèã ê òåêóùåìó ïîëîæåíèþ è çàïèñûâàåì åãî
v_add(@cur_pos, @pos);
v_add(@cur_rot, @rot);
//åñëè àêòîð â çîíå äåéñòâèÿ êîíòðîëåðà - äîáàâèì äðîæàíèå ðóê
if IsHandJitter(itm) then begin;
jitter:=GetCurJitterParams(section);
pos.x:=random(1000)-500;
pos.y:=random(500)-250;
pos.z:=random(1000)-500;
v_setlength(@pos, jitter.pos_amplitude*GetHandJitterScale(itm));
v_add(@cur_pos, @pos);
rot.x:=random(1000)-500;
rot.y:=random(1000)-500;
rot.z:=random(1000)-500;
v_setlength(@rot, jitter.rot_amplitude*GetHandJitterScale(itm));
v_add(@cur_rot, @rot);
end;
SetHandsPosOffset(hid, @cur_pos);
SetHandsRotOffset(hid, @cur_rot);
time_accumulator:=time_accumulator-8;
end;
if IsActorSuicideNow() and CheckActorVisibilityForController() and not (game_ini_r_bool_def(section, 'prohibit_suicide', false) or game_ini_r_bool_def(section, 'suicide_by_animation', false)) then begin
jitter:=GetCurJitterParams(section);
pos:=GetHandsPosOffset(hid);
rot:=GetHandsRotOffset(hid);
v_sub(@pos, @targetpos);
v_sub(@rot, @targetrot);
if (v_length(@pos)<jitter.pos_amplitude*2) and (v_length(@rot)<jitter.rot_amplitude*2) then begin
DoSuicideShot();
end;
end;
if fromcrouch_time_remains>delta then fromcrouch_time_remains:=fromcrouch_time_remains-delta else fromcrouch_time_remains:=0;
if tocrouch_time_remains>delta then tocrouch_time_remains:=tocrouch_time_remains-delta else tocrouch_time_remains:=0;
if fromslowcrouch_time_remains>delta then fromslowcrouch_time_remains:=fromslowcrouch_time_remains-delta else fromslowcrouch_time_remains:=0;
if toslowcrouch_time_remains>delta then toslowcrouch_time_remains:=toslowcrouch_time_remains-delta else toslowcrouch_time_remains:=0;
if fromrlookout_time_remains>delta then fromrlookout_time_remains:=fromrlookout_time_remains-delta else fromrlookout_time_remains:=0;
if torlookout_time_remains>delta then torlookout_time_remains:=torlookout_time_remains-delta else torlookout_time_remains:=0;
if fromllookout_time_remains>delta then fromllookout_time_remains:=fromllookout_time_remains-delta else fromllookout_time_remains:=0;
if tollookout_time_remains>delta then tollookout_time_remains:=tollookout_time_remains-delta else tollookout_time_remains:=0;
end;
//h - è âõîä è âûõîä. Âõîä - öåëåâîå, âûõîä - ôàêòè÷åñêîå ê óñòàíîâêå
procedure CorrectActorCameraHeight(h:psingle); stdcall;
var
dt, curtime:cardinal;
max_offset, speed, target_h, dh, delta, dh_pow:single;
landing:landing_params;
act, wpn:pointer;
buf:WpnBuf;
begin
act:=GetActor();
if _last_camera_height = 0 then begin
_last_camera_height:=h^;
_last_cam_update_time:=GetGameTickCount();
exit;
end;
curtime:=GetGameTickCount();
dt:=GetTimeDeltaSafe(_last_cam_update_time, curtime);
_last_cam_update_time:=curtime;
landing:=GetCamLandingParams();
if (act<>nil) and GetActorActionState(act, actLanding2) then begin
_landing2_effect_time_remains:=landing.time_landing2;
_landing_effect_time_remains:=0;
_landing_effect_finish_time_remains:=0;
end else if (act<>nil) and GetActorActionState(act, actLanding) then begin
_landing2_effect_time_remains:=0;
_landing_effect_time_remains:=landing.time_landing;
_landing_effect_finish_time_remains:=0;
end;
dh_pow:=GetCamSpeedPow();
speed:=GetCamSpeedDef();
if act<>nil then begin
wpn := GetActorActiveItem();
if wpn<>nil then begin
buf:=GetBuffer(wpn);
if buf<>nil then begin
speed:= buf.GetCameraSpeed();
end;
end;
end;
if _landing_effect_time_remains>0 then begin
max_offset:=landing.offset_landing;
speed:=speed*landing.cam_speed_factor;
dh_pow:=dh_pow*landing.pow_factor;
end else if _landing2_effect_time_remains>0 then begin
max_offset:=landing.offset_landing2;
speed:=speed*landing.cam_speed_factor2;
dh_pow:=dh_pow*landing.pow_factor2;
end else if _landing_effect_finish_time_remains>0 then begin
speed:=speed*landing.cam_speed_finish_landing_factor;
dh_pow:=dh_pow*landing.pow_finish_landing_factor;
max_offset:=0;
//log('Up');
end else begin
max_offset:=0;
end;
target_h:=h^+max_offset;
dh:=target_h-_last_camera_height;
delta:=abs(power(abs(dh), dh_pow)*dt*speed/1000);
if dh<0 then begin
delta:=delta*(-1);
end;
if abs(delta)>abs(dh) then begin
delta:=dh;
_landing_effect_finish_time_remains:=0;
end;
h^:=_last_camera_height+delta;
_last_camera_height:=h^;
if _landing_effect_time_remains>dt then begin
_landing_effect_time_remains:=_landing_effect_time_remains-dt;
end else if _landing_effect_time_remains > 0 then begin
_landing_effect_finish_time_remains:=landing.time_finish_landing;
_landing_effect_time_remains:=0;
end;
if _landing_effect_finish_time_remains>dt then _landing_effect_finish_time_remains:=_landing_effect_finish_time_remains-dt else _landing_effect_finish_time_remains:=0;
if _landing2_effect_time_remains>dt then _landing2_effect_time_remains:=_landing2_effect_time_remains-dt else _landing2_effect_time_remains:=0;
end;
procedure CActor__CameraHeight_Patch(); stdcall;
asm
addss xmm0, [esi+$52c]
pushad
push eax
movss [esp], xmm0
push esp
call CorrectActorCameraHeight
movss xmm0, [esp]
add esp, 4
popad
end;
procedure LookoutFunctionReplace(act:pointer; cur_roll:psingle; tgt_roll:single; dt:single); stdcall;
var
dx, delta:single;
speed, koef, ampl_k, dx_pow:single;
itm:pointer;
const
EPS=0.0001;
begin
speed:=GetBaseLookoutParams().speed;
ampl_k:=GetBaseLookoutParams().ampl_k;
dx_pow:=GetBaseLookoutParams().dx_pow;
if (act<>nil) and (act=GetActor()) then begin
itm:=GetActorActiveItem;
if itm<>nil then begin
koef:=game_ini_r_single_def(GetHUDSection(itm), 'lookout_speed_koef', 1.0);
speed:=koef*speed;
koef:=game_ini_r_single_def(GetHUDSection(itm), 'lookout_ampl_k', 1.0);
ampl_k:=ampl_k*koef;
end;
end;
tgt_roll:=tgt_roll*ampl_k;
dx:=tgt_roll-cur_roll^;
delta:=abs(power(abs(dx), dx_pow)*dt*speed);
if dx<0 then begin
delta:=delta*(-1);
end;
if abs(delta)>abs(dx) then begin
delta:=dx;
end;
cur_roll^:=cur_roll^+delta;
end;
procedure LookoutFunctionReplace_Patch; stdcall;
asm
mov eax, esp
pushad
push [eax+$10]
push [eax+$8]
push [eax+$4]
push esi
call LookoutFunctionReplace;
popad
end;
function Init():boolean;
var
addr, rb:cardinal;
ptr:pointer;
b:byte;
begin
result:=false;
_last_default_hud_params.hud_sect:=nil;
//CWeapon::OnZoomIn - îòêëþ÷àåì AllowInertion(false);
addr:=xrgame_addr+$2c07dc;
if not WriteJump(addr, cardinal(@CWeapon__OnZoomOut_inertion_Patch), 9, true) then exit;
//CWeapon::OnZoomOut - îòêëþ÷àåì AllowInertion(true);
addr:=xrgame_addr+$2BEE36;
if not WriteJump(addr, cardinal(@CWeapon__OnZoomOut_inertion_Patch), 8, true) then exit;
//CActor::cam_Update - â èíëàéíå CActor::CameraHeight ïîäìåíÿåì ðåçóëüòèðóþùåå çíà÷åíèå âûñîòû êàìåðû (äëÿ ïëàâíîñòè)
addr:=xrgame_addr+$274359;
if not WriteJump(addr, cardinal(@CActor__CameraHeight_Patch), 8, true) then exit;
//ïåðåïèñûâàåì óêàçàòåëü íà ïðåäåëüíîå çíà÷åíèå èíåðöèè
addr:=xrgame_addr+$2fcbc8;
ptr:=@i_p.pitch_offset_n;
writeprocessmemory(hndl, PChar(addr), @ptr, 4, rb);
addr:=xrgame_addr+$2fcbd0;
ptr:=@i_p.pitch_offset_r;
writeprocessmemory(hndl, PChar(addr), @ptr, 4, rb);
addr:=xrgame_addr+$2fcba2;
ptr:=@i_p.pitch_offset_d;
writeprocessmemory(hndl, PChar(addr), @ptr, 4, rb);
ptr:=@i_p.speed;
addr:=xrgame_addr+$2fc98f;
writeprocessmemory(hndl, PChar(addr), @ptr, 4, rb);
ptr:=@i_p.origin_offset;
addr:=xrgame_addr+$2fc9b2;
writeprocessmemory(hndl, PChar(addr), @ptr, 4, rb);
//ìåíÿåì áàéò ïåðåõîäà â CActor::g_Physics íà áåçóñëîâíûé, ÷òîáû íå íàçíà÷àëñÿ ýôôåêòîð ïàäåíèÿ àêòîðà (â ìîäå ñâîÿ ñõåìà)
b:=$EB;
addr:=xrgame_addr+$261BD2;
writeprocessmemory(hndl, PChar(addr), @b, 1, rb);
//Ìåíÿåì ëèíåéíûé õàðàêòåð íàêëîíîâ-âûãëÿäûâàíèé
addr:=xrgame_addr+$26a10a;
if not WriteJump(addr, cardinal(@LookoutFunctionReplace_Patch), 5, true) then exit;
//óáèðàåì óñëîâèå, ÷òîáû íàêëîíû îáðàáàòûâàëèñü âñåãäà
addr:=xrgame_addr+$26a0eb;
nop_code(addr, 6);
result:=true;
end;
end.