-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathControllerMonster.pas
More file actions
983 lines (835 loc) · 29.9 KB
/
ControllerMonster.pas
File metadata and controls
983 lines (835 loc) · 29.9 KB
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
unit ControllerMonster;
{$IFDEF FPC}{$MODE DELPHI}{$ENDIF}
interface
function Init():boolean; stdcall;
function IsActorControlled():boolean; stdcall;
function IsActorSuicideNow():boolean; stdcall;
function IsSuicideAnimPlaying(wpn:pointer):boolean; stdcall;
function IsActorPlanningSuicide():boolean; stdcall;
function IsSuicideInreversible():boolean; stdcall;
function IsKnifeSuicideExit():boolean; stdcall;
function SetExitKnifeSuicide(status:boolean):boolean; stdcall; //óñòàíîâèòü ôëàã íåîáõîäèìîñòè ïðîèãðàòü àíèìó âûõîäà èç ñóèöèäà íîæîì
procedure ResetActorControl(); stdcall;
procedure Update(dt:cardinal); stdcall;
procedure DoSuicideShot(); stdcall;
function CanUseItemForSuicide(wpn:pointer):boolean;
function GetCurrentSuicideWalkKoef():single;
function IsControllerPreparing():boolean; stdcall;
function CheckActorVisibilityForController():boolean; stdcall;
procedure NotifySuicideStopCallbackIfNeeded();
procedure NotifySuicideShotCallbackIfNeeded();
type controller_input_correction_params = packed record
active:boolean;
rotate_angle:single;
sense_scaler_x:single;
sense_scaler_y:single;
reverse_axis_y:boolean;
end;
function GetCurrentControllerInputCorrectionParams():controller_input_correction_params;
type controller_input_random_offset = packed record
offset_x:integer;
offset_y:integer;
end;
function GetControllerInputRandomOffset():controller_input_random_offset;
implementation
uses BaseGameData, ActorUtils, HudItemUtils, WeaponAdditionalBuffer, DetectorUtils, gunsl_config, math, sysutils, uiutils, Level, MatVectors, strutils, ScriptFunctors, misc, WeaponEvents, Throwable, dynamic_caster, KeyUtils, xr_strings;
var
_controlled_time_remains:cardinal;
_suicide_now:boolean;
_planning_suicide:boolean;
_lastshot_done_time:cardinal;
_death_action_started:boolean;
_inventory_disabled_set:boolean;
_knife_suicide_exit:boolean;
_controller_preparing_starttime:cardinal;
IsPsiBlocked_adapter_ptr:pointer;
_active_controllers:array of pointer;
_psi_block_failed:boolean;
_input_correction:controller_input_correction_params;
function DistToSelectedContr(controller_monster:pointer):single; stdcall;
var
a_pos, c_pos:pFVector3;
c_pos_cp:FVector3;
act:pointer;
begin
result:=1000;
act:=GetActor();
if act=nil then exit;
a_pos:=GetEntityPosition(act);
c_pos:=GetEntityPosition(controller_monster);
c_pos_cp:=c_pos^;
v_sub(@c_pos_cp, a_pos);
result:=v_length(@c_pos_cp);
end;
function DistToContr():single; stdcall;
var
dist:single;
i:integer;
begin
result:=1000;
for i:=0 to length(_active_controllers)-1 do begin
dist:=DistToSelectedContr(_active_controllers[i]);
if dist < result then begin
dist:=result;
end;
end;
end;
procedure UpdatePsiBlockFailedState(monster_controller:pointer);
var
dist, prob:single;
params:controller_psiunblock_params;
begin
dist:=DistToSelectedContr(monster_controller);
params:=GetControllerPsiUnblockProb();
if dist <= params.min_dist then begin
prob:=params.min_dist_prob;
end else if dist >= params.max_dist then begin
prob:=params.max_dist_prob;
end else begin
prob:= 1 - (dist-params.min_dist) / (params.max_dist - params.min_dist);
prob:= prob * (params.min_dist_prob - params.max_dist_prob) + params.max_dist_prob;
end;
_psi_block_failed:=random < prob;
// Log('psi unblock prob '+floattostr(prob)+', dist '+floattostr(dist)+', state '+booltostr(_psi_block_failed, true));
end;
function IsPsiBlockFailed():boolean;
begin
result:=_psi_block_failed;
end;
function IsPsiBlocked(act:pointer):boolean; stdcall;
var
c:pCActorCondition;
begin
c:=GetActorConditions(act);
result:=(GetBoosterFromConditions(@c.base_CEntityCondition, eBoostTelepaticProtection) <> nil);
end;
procedure IsPsiBlocked_adapter(); stdcall;
asm
pushad
mov eax, [ecx+04]
test eax, eax
je @finish
push eax
call IsPsiBlocked
@finish:
cmp al, 0
popad
je @no_block
mov eax, 1
ret
@no_block:
mov eax, 0
ret
end;
procedure CGameObject__script_export(); stdcall;
const
is_psi_blocked_name:PChar = 'is_psi_blocked';
asm
pop edx
mov [esp+$54], bl
mov ecx, [esp+$54]
push ecx
mov [esp+$24], bl
mov ecx, [esp+$24]
push ecx
lea ecx, [esp+$5c]
push ecx
lea ecx, [esp+$24]
push ecx
push is_psi_blocked_name
mov ecx,IsPsiBlocked_adapter_ptr
mov [esp+$2c],ecx
mov ecx, eax
mov ebx, edx
mov edx, xrgame_addr
add edx, $1D4D10
call edx
mov edx, ebx
xor ebx, ebx
mov [esp+$54], bl
mov ecx, [esp+$54]
jmp edx
end;
procedure ChangeInputRotateAngle();
const
MIN_ANGLE:single = 70/180*pi;
MAX_ANGLE:single = 290/180*pi;
var
min_sense, max_sense:single;
begin
min_sense:=GetControllerMouseControlParams().min_sense_scale;
max_sense:=GetControllerMouseControlParams().max_sense_scale;
_input_correction.rotate_angle:=random * (MAX_ANGLE-MIN_ANGLE) + MIN_ANGLE;
_input_correction.sense_scaler_x:=random * (max_sense - min_sense) + min_sense;
_input_correction.sense_scaler_y:=random * (max_sense - min_sense) + min_sense;
_input_correction.reverse_axis_y:=random < 0.5;
end;
function GetCurrentControllerInputCorrectionParams():controller_input_correction_params;
var
suicide_anm:boolean;
itm:pointer;
begin
itm:=GetActorActiveItem();
suicide_anm := (itm<>nil) and IsSuicideAnimPlaying(itm);
if (IsActorPlanningSuicide() and not IsPsiBlocked(GetActor()) and (GetCurrentDifficulty() >= gd_master) ) or IsActorSuicideNow() or suicide_anm then begin
result:=_input_correction;
result.active:=true;
end else begin
result.active:=false;
result.rotate_angle:=0;
result.sense_scaler_x:=1;
result.sense_scaler_y:=1;
result.reverse_axis_y:=false;
end;
end;
function GetControllerInputRandomOffset():controller_input_random_offset;
var
suicide_anm:boolean;
itm:pointer;
min_offset:single;
max_offset:single;
begin
itm:=GetActorActiveItem();
suicide_anm := (itm<>nil) and IsSuicideAnimPlaying(itm);
min_offset:=GetControllerMouseControlParams().min_offset;
max_offset:=GetControllerMouseControlParams().max_offset;
if IsActorSuicideNow() or suicide_anm or (not IsPsiBlocked(GetActor) and ( IsActorControlled() or IsActorPlanningSuicide() or IsControllerPreparing())) then begin
result.offset_x:=floor(random*(max_offset-min_offset)+min_offset);
result.offset_y:=floor(random*(max_offset-min_offset)+min_offset);
end else begin
result.offset_x:=0;
result.offset_y:=0;
end;
end;
function GetCurrentSuicideWalkKoef():single;
var
itm:pointer;
begin
result:=1.0;
if IsActorControlled() or IsActorSuicideNow() or IsActorPlanningSuicide() or IsControllerPreparing() then begin
result:=GetControlledActorSpeedKoef();
exit;
end;
itm:=GetActorActiveItem();
if (itm<>nil) and IsSuicideAnimPlaying(itm) then begin
result:=GetControlledActorSpeedKoef();
exit;
end;
end;
function IsActorControlled():boolean;stdcall;
begin
result:=_controlled_time_remains>0
end;
function IsSuicideAnimPlaying(wpn:pointer):boolean; stdcall;
var
anm:PChar;
begin
anm:=GetActualCurrentAnim(wpn);
result:=(leftstr(anm, length('anm_prepare_suicide'))='anm_prepare_suicide') or (leftstr(anm, length('anm_suicide'))='anm_suicide');
end;
function IsActorSuicideNow():boolean; stdcall;
begin
result:=_suicide_now;
end;
function IsActorPlanningSuicide():boolean; stdcall;
begin
result:=_planning_suicide;
end;
procedure AddActiveController(monster_controller:pointer); stdcall;
begin
if length(_active_controllers) = 0 then begin
script_call('gunsl_controller.on_suicide_scheme_start', '', GetCObjectID(monster_controller));
end;
setlength(_active_controllers, length(_active_controllers)+1);
_active_controllers[length(_active_controllers)-1] := monster_controller;
script_call('gunsl_controller.on_suicide_selected_by_controller', '', GetCObjectID(monster_controller));
end;
procedure ClearActiveControllers(); stdcall;
begin
if length(_active_controllers) > 0 then begin
script_call('gunsl_controller.on_suicide_scheme_finish', '', 0);
end;
setlength(_active_controllers, 0);
end;
procedure ResetActorControl(); stdcall;
begin
ClearActiveControllers();
_controlled_time_remains:=0;
_suicide_now:=false;
_lastshot_done_time:=0;
_planning_suicide:=false;
_death_action_started:=false;
_knife_suicide_exit:=false;
end;
function IsSuicideInreversible():boolean; stdcall;
begin
result:=(_lastshot_done_time>0) or _death_action_started;
end;
function CanUseItemForSuicide(wpn:pointer):boolean;
var
can_shoot, is_knife, can_switch_gl, can_shoot_gl:boolean;
begin
result:=false;
if (wpn=nil) then exit;
can_shoot:=WpnCanShoot(wpn);
is_knife:=IsKnife(wpn);
if (not is_knife) and (not can_shoot) then exit;
if game_ini_r_bool_def(GetHUDSection(wpn), 'prohibit_suicide', false) then exit;
if IsGrenadeMode(wpn) then begin
can_switch_gl:= game_ini_r_bool_def(GetHUDSection(wpn), 'controller_can_switch_gl', false); //êîíòðîëåð âûêëþ÷èò ïîäñòâîë
can_shoot_gl := game_ini_r_bool_def(GetHUDSection(wpn), 'controller_can_shoot_gl', false); //êîíòðîëåð âûñòðåëèò èç ïîäñòâîëà ïîä íîãè
if (GetAmmoInGLCount(wpn) > 0) then begin
result:=can_switch_gl or can_shoot_gl;
end else if GetAmmoInMagCount(wpn) > 0 then begin
result:=can_switch_gl;
end else begin
result:=false;
end;
end else begin
if can_shoot then begin
result:= (GetAmmoInMagCount(wpn) > 0) and not IsWeaponJammed(wpn) and (GetCurrentState(wpn) <> EWeaponStates__eReload);
end else begin
result:=true;
end;
end;
end;
procedure Update(dt:cardinal); stdcall;
var
wpn, act, det:pointer;
last_contr_time:cardinal;
begin
act:=GetActor();
if (act = nil) or (GetActorHealth(act) <= 0) then begin
ResetActorControl();
exit;
end;
wpn:=GetActorActiveItem();
if act<>nil then det:=GetActiveDetector(act) else det:=nil;
last_contr_time:=_controlled_time_remains;
if _controlled_time_remains>dt then _controlled_time_remains:=_controlled_time_remains-dt else _controlled_time_remains:=0;
if (_controlled_time_remains=0) and (_lastshot_done_time=0) and not _death_action_started then begin
if _inventory_disabled_set then begin
CActor__set_inventory_disabled(act, false);
_inventory_disabled_set:=false;
end;
if last_contr_time>0 then SetHandsJitterTime(GetShockTime());
ResetActorControl();
end else if (wpn<>nil) and IsKnife(wpn) then begin
if _planning_suicide and (GetActualCurrentAnim(wpn)='anm_prepare_suicide') then begin
_suicide_now:=true;
end else if _suicide_now and (GetActualCurrentAnim(wpn)='anm_selfkill') then begin
_death_action_started:=true;
end;
end else if _lastshot_done_time>0 then begin
if (act<>nil) then begin
SetActorActionState(act, actMovingForward, false, mState_WISHFUL);
SetActorActionState(act, actMovingBack, false, mState_WISHFUL);
SetActorActionState(act, actMovingLeft, false, mState_WISHFUL);
SetActorActionState(act, actMovingRight, false, mState_WISHFUL);
end;
if (wpn=nil) or (GetTimeDeltaSafe(_lastshot_done_time, GetGameTickCount()) > floor(1000*game_ini_r_single_def(GetHUDSection(wpn), 'suicide_delay', 0.1))) then begin
KillActor(act, act);
_lastshot_done_time:=0;
end;
end;
if (act<>nil) and (_controlled_time_remains>0) then begin
if (det<>nil) then begin
if (GetCurrentState(det)<>EHudStates__eHiding) and (GetCurrentState(det)<>EHudStates__eHidden) then virtual_CHudItem_SwitchState(det, EHudStates__eHiding);
end;
if (wpn<>nil) and (WpnCanShoot(wpn) or IsBino(wpn)) and (IsAimNow(wpn)) then begin
SetActorKeyRepeatFlag(kfUNZOOM, true, true);
end;
if (wpn<>nil) and (WpnCanShoot(wpn)) then begin
//Åñëè ñòðåëüáà "çàëèïëà", íå äîïóñêàåì èñ÷åðïàíèÿ áîåçàïàñà (íå íîæîì æå ðåçàòüñÿ :) )
if (GetCurrentState(wpn)=EWeaponStates__eFire) and (_lastshot_done_time=0) and (GetCurrentAmmoCount(wpn) <= 3) then begin
SetWorkingState(wpn, false);
end;
end;
if (wpn<>nil) and (GetSection(wpn)=GetPDAShowAnimator()) then begin
if IsPDAWindowVisible() then HidePDAMenu();
end else if (wpn<>nil) and IsThrowable(wpn) then begin
_planning_suicide:=true;
_suicide_now:=false;
if (GetCurrentState(wpn) = EMissileStates__eReady) then begin
//äåëàòü íå÷åãî - ïðèäåòñÿ êèäàòü... Íî êèäàåì ïîä íîãè è âðåìåíåì äåñòðîÿ íå ìàíèïóëèðóåì
virtual_CHudItem_SwitchState(wpn, EMissileStates__eThrow);
PrepareGrenadeForSuicideThrow(wpn, game_ini_r_single_def(GetSection(wpn), 'suicide_ready_force', 8));
virtual_Action(wpn, kWPN_ZOOM, kActRelease);
end else if (GetCurrentState(wpn) = EMissileStates__eThrowStart) then begin
//Çäåñü ìîæåò áûòü ëèáî íà÷àëî îáû÷íîãî áðîñêà, ëèáî ñóèöèäíîãî.
//Åñëè ñóèöèä - íà âñÿêèé îáíîâëÿåì ñòàòóñû äëÿ ãàðàíòèðîâàííîãî ñðàáàòûâàíèÿ áðîñêà (õîòÿ îíè è äîëæíû îáíîâèòüñÿ íàìè â OnAnimationEnd ïåðåä ñàìèì áðîñêîì)
if IsMissileInSuicideState(wpn) then begin
SetConstPowerStatus(wpn, true);
SetImmediateThrowStatus(wpn, true);
end else begin
PrepareGrenadeForSuicideThrow(wpn, game_ini_r_single_def(GetSection(wpn), 'suicide_ready_force', 8));
virtual_Action(wpn, kWPN_ZOOM, kActRelease);
end;
end else if (dynamic_cast(wpn, 0, RTTI_CHudItemObject, RTTI_CGrenade, false)<>nil) and (DistToContr()>game_ini_r_single_def(GetHUDSection(wpn), 'controller_g_attack_min_dist', 10)) and (GetCurrentState(wpn) = EHudStates__eIdle) and (not game_ini_r_bool_def(GetHUDSection(wpn), 'prohibit_suicide', false)) then begin
//àòàêóåì èãðîêà åãî æå ãðåíîé
virtual_CHudItem_SwitchState(wpn, EMissileStates__eThrowStart);
end else if CanUseItemForSuicide(ItemInSlot(act, KNIFE_SLOT)) then begin
ActivateActorSlot__CInventory(1, false);
end else begin
ActivateActorSlot__CInventory(0, false);
end;
end else begin
_planning_suicide:=CanUseItemForSuicide(wpn);
if not _planning_suicide then begin
//ýòîé øòóêîé óáèòüñÿ íåëüçÿ...
if (wpn<>nil) then begin
PerformDrop(act);
end;
//À ìîæíî ëè íîæîì?
if CanUseItemForSuicide(ItemInSlot(act, KNIFE_SLOT)) then begin
ActivateActorSlot__CInventory(1, false);
_planning_suicide:=true;
_suicide_now:=false;
end else begin
ActivateActorSlot__CInventory(0, false);
_suicide_now:=false;
end;
end;
end;
end;
end;
procedure DoSuicideShot(); stdcall;
var
wpn:pointer;
begin
wpn:=GetActorActiveItem();
if (wpn=nil) then exit;
if (_lastshot_done_time>0) then begin
exit;
end;
SetDisableInputStatus(true);
_lastshot_done_time:=GetGameTickCount();
_death_action_started:=true;
// virtual_CHudItem_SwitchState(wpn, EWeaponStates__eFire);
if IsGrenadeMode(wpn) then begin
TryShootGLFix(wpn);
end else begin
virtual_CShootingObject_FireStart(wpn);
end;
NotifySuicideShotCallbackIfNeeded();
// ClearActiveControllers() âûçîâåòñÿ íà àïäåéòå, óâèäåâ _lastshot_done_time
end;
function IsControllerSeeActor(contr:pointer; act:pointer):boolean; stdcall;
asm
pushad
mov ecx, contr
add ecx, $5b4
push act
mov ebx, xrgame_addr
add ebx, $D0C80 //CMonsterEnemyManager::see_enemy_now
call ebx
mov @result, al
popad
end;
function CheckActorVisibilityForController():boolean; stdcall;
var
act:pointer;
i:integer;
contr_section:PAnsiChar;
begin
result:=false;
act:=GetActor();
if act=nil then exit;
// Log('Check visibility for '+inttostr(length(_active_controllers))+'controllers');
for i:=0 to length(_active_controllers)-1 do begin
if GetCurrentDifficulty >= gd_veteran then begin
// íà âûñîêîé ñëîæíîñòè êîíòðîëåð âñåãäà çàâåðøàåò ñâîå, åñëè íå ïðîïèñàíî îáðàòíîå
contr_section:= get_string_value(GetCObjectSection(_active_controllers[i]));
if not game_ini_r_bool_def(contr_section, 'mandatory_suicide_visibility_check', false) then begin
result:=true;
break
end;
end;
if IsControllerSeeActor(_active_controllers[i], act) then begin
result:=true;
break
end;
end;
end;
procedure OnSuicideAnimEnd(wpn:pointer; param:integer);stdcall;
begin
if (wpn<>GetActorActiveItem()) then exit;
if (not IsPsiBlocked(GetActor()) or IsPsiBlockFailed()) and (_suicide_now or _planning_suicide) and CheckActorVisibilityForController() then begin
DoSuicideShot();
end else begin
_suicide_now:=false;
_planning_suicide:=false;
NotifySuicideStopCallbackIfNeeded();
ClearActiveControllers();
WeaponAdditionalBuffer.PlayCustomAnimStatic(wpn, 'anm_stop_suicide', 'sndStopSuicide');
SetHandsJitterTime(GetShockTime());
end;
end;
function PsiEffects(monster_controller:pointer):boolean; stdcall;
var
act, det, wpn:pointer;
buf:WpnBuf;
psi_blocked, not_seen, dist_forcer:boolean;
c_pos, a_pos:pFVector3;
c_pos_cp:FVector3;
dist:single;
contr_feel:controller_feel_params;
can_switch_gl, can_shoot_gl:boolean;
begin
//true â ðåçóëüòàòå îçíà÷àåò, ÷òî ìû èñïîëüçîâàëè êàñòîìíûé ýôôåêò è îáû÷íóþ àòàêó èãðàòü íå íàäî
result:=true;
act:=GetActor();
if act=nil then exit;
psi_blocked:=IsPsiBlocked(act) and not IsPsiBlockFailed();
not_seen:= not IsControllerSeeActor(monster_controller, act);
dist:=DistToSelectedContr(monster_controller);
contr_feel:=GetControllerFeelParams();
if dist < contr_feel.min_dist then begin
dist_forcer:=true;
end else if dist > contr_feel.max_dist then begin
dist_forcer:=false;
end else begin
dist_forcer:= ((dist - contr_feel.min_dist) / (contr_feel.max_dist - contr_feel.min_dist)) > random;
end;
//Åñëè àêòèâåí áóñòåð ïñèáëîêàäû, òî ñóèöèä íå äåëàåì
//Òàêæå íå äåëàåì, åñëè àêòîð ñâàëèë
if ( psi_blocked or (not dist_forcer and not_seen) ) and not IsActorSuicideNow() and not IsSuicideInreversible() then begin
result:=not_seen;
_planning_suicide:=false;
_suicide_now:=false;
SetHandsJitterTime(GetControllerBlockedTime());
exit;
end;
_controlled_time_remains:=GetControllerTime();
det:=GetActiveDetector(act);
wpn:=GetActorActiveItem();
if IsPDAWindowVisible() or ((wpn<>nil) and (GetSection(wpn)=GetPDAShowAnimator())) then begin
result:=false; //áüåì ñòàíäàðòíûì ïñè-õèòîì
_planning_suicide:=false;
_suicide_now:=false;
SetHandsJitterTime(GetControllerTime());
exit;
end;
if (det<>nil) or ((wpn<>nil) and not CanUseItemForSuicide(wpn)) then begin
_planning_suicide:=CanUseItemForSuicide(wpn);
_suicide_now:=false;
result:= (wpn=nil) or (not ((GetCurrentState(wpn)=EHudStates__eHidden) or (GetCurrentState(wpn)=EHudStates__eHiding)));
exit;
end;
if (wpn=nil) then begin
{if (GetCurrentDifficulty()>=gd_master) and CanUseItemForSuicide(ItemInSlot(act, KNIFE_SLOT)) then begin
_planning_suicide:=true;
result:=true;
end else begin
_planning_suicide:=false;
result:=false;
end;}
if CanUseItemForSuicide(ItemInSlot(act, KNIFE_SLOT)) then begin
_planning_suicide:=true;
result:=true;
end else begin
_planning_suicide:=false;
result:=false;
end;
_suicide_now:=false;
exit;
end;
//Åñëè â ðóêàõ ñåé÷àñ íîæ - ðåæåìñÿ èì
if IsKnife(wpn) then begin
_controlled_time_remains:=floor(game_ini_r_single_def(GetHUDSection(wpn), 'controller_time', _controlled_time_remains/1000)*1000);
_planning_suicide:=true;
//åñëè äî ñèõ ïîð àíèìà ñóèöèäà íå ñòàðòîâàëà - ôîðñèðóåì ñîáûòèå
if ( not _suicide_now or not IsSuicideAnimPlaying(wpn) ) and ((GetCurrentState(wpn)<>EWeaponStates__eFire) or (GetCurrentState(wpn)<>EWeaponStates__eFire2)) then begin
virtual_CHudItem_SwitchState(wpn, EWeaponStates__eFire);
end;
exit;
end;
buf:=GetBuffer(wpn);
//à òåïåðü çàéìåìñÿ ñòðåëÿþùèì îðóæèåì
c_pos:=GetEntityPosition(monster_controller);
c_pos_cp:=c_pos^;
a_pos:=GetEntityPosition(act);
v_sub(@c_pos_cp, a_pos);
if IsGrenadeMode(wpn) then begin
//åñëè äîøëþ ñþäà - çíà÷èò, ñ ïîäñòâîëîì ìîæåì ðàáîòàòü
can_switch_gl:=game_ini_r_bool_def(GetHUDSection(wpn), 'controller_can_switch_gl', false);
can_shoot_gl:=game_ini_r_bool_def(GetHUDSection(wpn), 'controller_can_shoot_gl', false);
if can_shoot_gl and (GetAmmoInGLCount(wpn) > 0) and (game_ini_r_single_def(GetHUDSection(wpn), 'controller_shoot_gl_min_dist', 10) < v_length(@c_pos_cp)) then begin
//äèñòàíöèÿ äî êîíòðû áîëüøàÿ, ìîæíî ñòðåëÿòü èç ïîäñòâîëà
//Íè÷åãî îñîáåííîãî äåëàòü òóò íå íàäî (ïîêà?), ïðîñòî èäåì äàëüøå ïî if'àì
end else if can_switch_gl and (GetAmmoInMagCount(wpn) > 0) and not IsWeaponJammed(wpn) then begin
//âûêëþ÷àåì ïîäñòâîë
virtual_CHudItem_SwitchState(wpn, EWeaponStates__eSwitch);
_planning_suicide:=true;
_suicide_now:=false;
exit;
end else begin
//âûáðàñûâàåì ñòâîë
PerformDrop(act);
exit;
end;
end else if (dynamic_cast(wpn, 0, RTTI_CHudItemObject, RTTI_CWeaponRG6, false)<>nil) or (dynamic_cast(wpn, 0, RTTI_CHudItemObject, RTTI_CWeaponRPG7, false)<>nil) then begin
//ÐÏÃ èëè ÐÃ-6
if (game_ini_r_single_def(GetHUDSection(wpn), 'controller_shoot_expl_min_dist', 10)>v_length(@c_pos_cp)) then begin
PerformDrop(act);
exit;
end;
end;
_planning_suicide:=false; //õàê - ÷òîáû ôóíêöèÿ îïðåäåëåíèÿ âîçìîæíîñòè äåéñòâèÿ íå ó÷èòûâàëà ýòî
_suicide_now:=false;
if game_ini_r_bool_def(GetHUDSection(wpn), 'suicide_by_animation', false) then begin
_suicide_now:=IsSuicideAnimPlaying(wpn) or (_lastshot_done_time>0);
if not _suicide_now then _suicide_now:=WeaponAdditionalBuffer.PlayCustomAnimStatic(wpn, 'anm_suicide', 'sndSuicide', OnSuicideAnimEnd);
if _suicide_now then begin
_controlled_time_remains:=floor(game_ini_r_single_def(GetHUDSection(wpn), 'controller_time', _controlled_time_remains/1000)*1000);
//log(inttostr(_controlled_time_remains));
end;
_planning_suicide:=true;
end else begin
if CanStartAction(wpn) then begin
_suicide_now:=true;
_controlled_time_remains:=floor(game_ini_r_single_def(GetHUDSection(wpn), 'controller_time', _controlled_time_remains/1000)*1000);
end;
_planning_suicide:=true;
end;
if (GetCurrentState(wpn)=EWeaponStates__eFire) then begin
// Êîãäà àêòîð âåäåò îãîíü î÷åðåäüþ, ñòðåëüáà ìîæåò ëèáî ïðåêðàòèòüñÿ, ëèáî "çàëèïíóòü". Ýòî ïîâåäåíèå by design
if (GetControllerQueueStopProb() >= random) then begin
SetWorkingState(wpn, false);
end;
end;
end;
function PsiStart(monster_controller:pointer):boolean; stdcall;
var
wpn, act:pointer;
scream:string;
v, va:FVector3;
i,j:cardinal;
radius:single;
p:phantoms_params;
found:boolean;
k:integer;
begin
// _is_controller_preparing:=false;
result:=PsiEffects(monster_controller);
act:=GetActor();
if (act<>nil) and not CActor__get_inventory_disabled(act) then begin
HideShownDialogs();
CActor__set_inventory_disabled(act, true);
_inventory_disabled_set:=true;
end;
if result then begin
wpn:=GetActorActiveItem();
if (wpn<>nil) and not game_ini_r_bool_def(GetHUDSection(wpn), 'suicide_by_animation', false) and (IsKnife(wpn) or WpnCanShoot(wpn)) then begin
scream:='sndScream'+inttostr(random(3)+1);
CHudItem_Play_Snd(wpn, PChar(scream));
end;
found:=false;
for k:=0 to length(_active_controllers)-1 do begin
if _active_controllers[k]=monster_controller then begin
found:=true;
break;
end;
end;
if not found then begin
AddActiveController(monster_controller);
end;
if _planning_suicide or _suicide_now then begin
script_call('gunsl_controller.on_suicide_attack', '', GetCObjectID(monster_controller));
end;
end else begin
script_call('gunsl_controller.on_std_attack', '', GetCObjectID(monster_controller));
end;
//ôàíòîì÷èêè
p:=GetControllerPhantomsParams();
i:=random(p.max_cnt-p.min_cnt)+p.min_cnt;
va:=FVector3_copyfromengine(CRenderDevice__GetCamPos());
for j:=1 to i do begin
v.x:=random(1000)-500;
v.y:=random(200);
v.z:=random(1000)-500;
radius:= ((p.max_radius-p.min_radius)*random(1000)/1000)+p.min_radius;
v_setlength(@v, radius);
v_add(@v, @va);
spawn_phantom(@v);
end;
end;
function IsNeedPsiHitOverride():boolean;
begin
//âûçûâàåòñÿ, åñëè êîíòðîëåð ðåøèë íå áèòü àêòîðà ïñè-óäàðîì ïî ïðè÷èíå ìàëîé äèñòàíöèè
//ïðè âîçâðàùåíèè true îí ìåíÿåò ñâîå ðåøåíèå...
result:=(GetActorActiveItem()<>nil);
end;
procedure CControllerPsyHit__check_start_conditions_distance_patch(); stdcall;
asm
jna @std_psihit //óæå ðåøèëè íàíîñèòü òåëåïàòè÷åñêèé óäàð
pushad
call IsNeedPsiHitOverride
cmp al, 0
popad
jne @std_psihit
xor eax, eax
pop esi
ret
@std_psihit:
mov al, 1
pop esi
ret
end;
procedure CControllerPsyHit__check_conditions_final_distance_patch(); stdcall;
asm
jna @std_psihit //óæå ðåøèëè íàíîñèòü òåëåïàòè÷åñêèé óäàð
pushad
call IsNeedPsiHitOverride
cmp al, 0
popad
jne @std_psihit
xor eax, eax
pop esi
ret
@std_psihit:
mov ecx, esi
pop esi
mov eax, xrgame_addr
add eax, $131250 //CControllerPsyHit::see_enemy
jmp eax
end;
procedure CControllerPsyHit__death_glide_start_Patch; stdcall;
asm
mov eax, xrgame_addr
add eax, $131270
call eax //CControllerPsyHit::check_conditions_final
je @finish
pushad
push [esi+$8] //CBaseMonster* CControllerPsyHit.m_object
call PsiStart
cmp al, 1
popad
@finish:
end;
function NeedContinueSoundPlayingOnIndependent(wpn:pointer):boolean; stdcall;
begin
result:= (GetActor()<>nil) and (GetActor()=GetOwner(wpn)) and (IsSuicideInreversible());// and IsActorSuicideNow();
end;
procedure CHudItem__OnH_B_Independent_Patch_Sound; stdcall;
//ïîêàçûâàåò, áóäåò ëè çâóê ïðîäîëæâàòü èãðàòüñÿ ïîñëå îáðåòåíèÿ íåçàâèñèìîñòè îðóæèåì, èëè íåò
asm
pushad
sub esi, $2e0
push esi
call NeedContinueSoundPlayingOnIndependent
cmp al, 1
popad
je @finish
mov eax, xrgame_addr
add eax, $2FA560
call eax
@finish:
end;
function IsKnifeSuicideExit():boolean; stdcall;
begin
result:=_knife_suicide_exit;
end;
function SetExitKnifeSuicide(status:boolean):boolean; stdcall;
begin
_knife_suicide_exit:=status;
end;
procedure OnPsyHitActivate(monster_controller:pointer); stdcall;
begin
if (_controlled_time_remains = 0) then begin
UpdatePsiBlockFailedState(monster_controller);
ChangeInputRotateAngle();
end;
_controller_preparing_starttime:=GetGameTickCount();
script_call('gunsl_controller.on_psi_attack_prepare', '', GetCObjectID(monster_controller));
if (not IsPsiBlocked(GetActor()) or IsPsiBlockFailed()) and (_controlled_time_remains>0) then begin
_controlled_time_remains:=GetControllerPrepareTime();
end;
end;
procedure CControllerPsyHit__activate_Patch(); stdcall;
asm
add edi, $AA0
pushad
push [esi+8] //CBaseMonster* CControllerPsyHit.m_object
call OnPsyHitActivate
popad
end;
function IsControllerPreparing():boolean; stdcall;
begin
if IsPsiBlocked(GetActor()) and (not IsPsiBlockFailed()) then
result:=false
else
result:=(GetTimeDeltaSafe(_controller_preparing_starttime)<GetControllerPrepareTime+1000);
end;
procedure NotifySuicideStopCallbackIfNeeded();
begin
if length(_active_controllers) > 0 then begin
script_call('gunsl_controller.on_stop_suicide', '', 0);
end;
end;
procedure NotifySuicideShotCallbackIfNeeded();
begin
if length(_active_controllers) > 0 then begin
script_call('gunsl_controller.on_suicide_shot', '', 0);
end;
end;
procedure CPhantom__net_Spawn_checkenemy_Patch(); stdcall;
asm
cmp eax, 0 // if (m_enemy == NULL)
jne @finish
mov eax, esi // m_enemy = this
mov [esi+$23c], 3 // m_TgtState = stShoot
@finish:
//original
mov ecx,[esi+$200]
end;
function Init():boolean; stdcall;
var
addr:cardinal;
addr2:cardinal;
begin
result:=false;
IsPsiBlocked_adapter_ptr:=@IsPsiBlocked_adapter;
addr:=xrgame_addr+$1ED146;
if not WriteJump(addr, cardinal(@CGameObject__script_export), 8, true) then exit;
addr:=xrgame_addr+$131A3D;
if not WriteJump(addr, cardinal(@CControllerPsyHit__death_glide_start_Patch), 7, true) then exit;
addr:=xrgame_addr+$1314A5;
if not WriteJump(addr, cardinal(@CControllerPsyHit__check_start_conditions_distance_patch), 6, false) then exit;
addr:=xrgame_addr+$12A6C6;
if not WriteJump(addr, cardinal(@CControllerPsyHit__check_start_conditions_distance_patch), 6, false) then exit;
addr:=xrgame_addr+$131302;
if not WriteJump(addr, cardinal(@CControllerPsyHit__check_conditions_final_distance_patch), 6, false) then exit;
addr:=xrgame_addr+$2f9716;
if not WriteJump(addr, cardinal(@CHudItem__OnH_B_Independent_Patch_Sound), 5, true) then exit;
addr:=xrgame_addr+$1318DF;
if not WriteJump(addr, cardinal(@CControllerPsyHit__activate_Patch), 6, true) then exit;
// [bug] Áàã â CPhantom::net_Spawn - èíîãäà íà çàãðóçêå èãðû çâåçäû ìîãóò ñîéòèñü òàê, ÷òî â m_enemy ïîïàäåò null, ÷òî òóò æå ïðèâåäåò ê âûëåòó
//  êà÷åñòâå èñïðàâëåíèÿ ïîäñòàâëÿåì óêàçàòåëü íà ñàìîãî ôàíòîìà - óâû, â xform çàâåäóòñÿ nan'û ïðè ïîïûòêå óñòàíîâêå îðèåíòàöèè, òàê ÷òî ñðàçó è â ñòåéò ïðîïèøåì òåðìèíàëüíûé
addr:=xrgame_addr+$13B80B;
if not WriteJump(addr, cardinal(@CPhantom__net_Spawn_checkenemy_Patch), 6, true) then exit;
//ïî÷åìó-òî ïðè îáû÷íûõ àòàêàõ êîíòðîëÿ âîçíèêàþò ðàíäîìíûå âûëåòû âèäà
//Expression : assertion failed
//Function : CLensFlare::OnFrame
//File : D:\prog_repository\sources\trunk\xrEngine\xr_efflensflare.cpp
//Line : 330
//Description : _valid(vecX)
//ïðè÷èíà - NaN'û â CRenderDevice, êàê îíè òóäà ïîïàäàþò - õç
//Ïðåäïîëàãàþòñÿ îñîáåííîñòè ðàáîòû ýôôåêòîðà, âîçìîæíî, èç-çà êàêîé-òî âðåçêè
//Îòðóáàåì ýòîò ýôôåêòîð ê ÷åðòÿì îò ãðåõà ïîäàëüøå
addr:=xrgame_addr+$131C20;
addr2:=xrgame_addr+$131C94;
if not WriteJump(addr, addr2, 9, false) then exit;
nop_code(xrgame_addr+$131E93, 1);
nop_code(xrgame_addr+$131E9B, 8);
nop_code(xrgame_addr+$131F01, 5);
nop_code(xrgame_addr+$131A5C, 6);
nop_code(xrgame_addr+$131A69, 1, CHR($EB));
nop_code(xrgame_addr+$131F12, 1,chr(0));
result:=true;
end;
// CPhantom::OnFlyState - xrgame.dll+13aba0
// CController::Die - xrgame.dll+12b7a0
// CBaseMonster::Die - xrgame.dll+c6ed0
// CCustomMonster::Die - xrgame.dll+bcba0
end.