-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathL4D2_Aimbot.sp
1082 lines (858 loc) · 27.1 KB
/
L4D2_Aimbot.sp
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
#include <sdktools>
#include <sdkhooks>
#pragma newdecls required;
#define Address(%1) view_as<Address>(%1)
#define int(%1) view_as<int>(%1)
bool g_bAimbot[MAXPLAYERS + 1];
enum
{
AIM_NEAR = 0,
AIM_FOV,
NUM_AIM_MODES,
};
int g_iAimType[MAXPLAYERS + 1];
float g_flAimFOV[MAXPLAYERS + 1];
bool g_bAutoShoot[MAXPLAYERS + 1];
bool g_bSilentAim[MAXPLAYERS + 1];
bool g_bBunnyHop[MAXPLAYERS + 1];
bool g_bHeadshots[MAXPLAYERS + 1];
bool g_bAnnouncer[MAXPLAYERS + 1];
public Plugin myinfo =
{
name = "[L4D2] Aimbot V2",
author = "Pelipoika",
description = "",
version = "1.0",
url = "http://www.sourcemod.net/plugins.php?author=Pelipoika&search=1"
};
Handle g_hGetBonePosition;
Address TheZombieManager;
int g_iOffsetStudioHdr;
//TODO
public void OnPluginStart()
{
RegAdminCmd("sm_hacks", Command_Trigger, ADMFLAG_BAN);
RegAdminCmd("sm_zombiemanager", Command_TheZombieManager, 0);
for (int i = 1; i <= MaxClients; i++) {
OnClientPutInServer(i);
}
Handle hConf = LoadGameConfigFile("l4d2_aimbot");
// STR: "rhand", "ValveBiped.Bip01_L_Hand", "lhand", "ValveBiped.Bip01_R_Hand"
//void CBaseAnimating::GetBonePosition ( int iBone, Vector &origin, QAngle &angles )
StartPrepSDKCall(SDKCall_Entity);
PrepSDKCall_SetFromConf(hConf, SDKConf_Signature, "CBaseAnimating::GetBonePosition");
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
PrepSDKCall_AddParameter(SDKType_Vector, SDKPass_ByRef, _, VENCODE_FLAG_COPYBACK);
PrepSDKCall_AddParameter(SDKType_QAngle, SDKPass_ByRef, _, VENCODE_FLAG_COPYBACK);
if ((g_hGetBonePosition = EndPrepSDKCall()) == INVALID_HANDLE) SetFailState("Failed to create SDKCall for CBaseAnimating::GetBonePosition signature!");
//Get TheZombieManager ptr
TheZombieManager = GameConfGetAddress(hConf, "TheZombieManager");
PrintToServer("Found \"TheZombieManager\" @ 0x%X", TheZombieManager);
delete hConf;
HookEvent("player_death", Event_Kill, EventHookMode_Post);
g_iOffsetStudioHdr = FindSendPropInfo("CTerrorPlayer", "m_flexWeight") - 552;
}
public Action Command_TheZombieManager(int client, int argc)
{
ReplyToCommand(client, "\"TheZombieManager\" is @ 0x%X", TheZombieManager);
return Plugin_Handled;
}
/*
"Gambler"
"Producer"
"Coach"
"Mechanic"
"NamVet"
"TeenGirl"
"Biker"
"Manager"
"Nick"
"Rochelle"
"Coach"
"Ellis"
"Bill"
"Zoey"
"Francis"
"Louis"
Server event "player_death", Tick 9773:
- "userid" = "0"
- "entityid" = "160"
- "attacker" = "2"
- "attackername" = ""
- "attackerentid" = "0"
- "weapon" = "rifle_ak47"
- "headshot" = "1"
- "attackerisbot" = "0"
- "victimname" = "Infected"
- "victimisbot" = "1"
- "abort" = "0"
- "type" = "-1073741822"
- "victim_x" = "-5937.33"
- "victim_y" = "-2766.72"
- "victim_z" = "628.03"
*/
public void Event_Kill(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("attacker"));
if(!g_bAnnouncer[client])
return;
bool bWasHeadShot = event.GetBool("headshot");
char victimname[32], weapon[32];
event.GetString("victimname", victimname, sizeof(victimname));
event.GetString("weapon", weapon, sizeof(weapon));
char sMessage[PLATFORM_MAX_PATH];
Format(sMessage, PLATFORM_MAX_PATH, "[AIMBOT] Killed \"%s\" with \"%s\" %s", victimname, weapon, bWasHeadShot ? "by headshot!" : "");
float flRate = 2.0;
Handle msg = StartMessageOne("MessageText", client);
BfWriteByte(msg, RoundToNearest(Cosine((GetGameTime() * flRate) + client + 0) * 127.5 + 127.5)); //RED
BfWriteByte(msg, RoundToNearest(Cosine((GetGameTime() * flRate) + client + 2) * 127.5 + 127.5)); //GREEN
BfWriteByte(msg, RoundToNearest(Cosine((GetGameTime() * flRate) + client + 4) * 127.5 + 127.5)); //BLUE
BfWriteString(msg, sMessage);
EndMessage();
//PrintToChat(client, "[AIMBOT] Killed \"%s\" with \"%s\" %s", victimname, weapon, bWasHeadShot ? "by headshot!" : "");
}
public void OnClientPutInServer(int client)
{
g_bAimbot[client] = false;
g_bAutoShoot[client] = false;
g_bSilentAim[client] = false;
g_bAnnouncer[client] = false;
g_iAimType[client] = AIM_NEAR;
g_flAimFOV[client] = 10.0;
g_bBunnyHop[client] = false;
g_bHeadshots[client] = false;
}
public Action Command_Trigger(int client, int args)
{
if(client > 0 && client <= MaxClients && IsClientInGame(client))
{
DisplayHackMenuAtItem(client);
}
return Plugin_Handled;
}
stock void DisplayHackMenuAtItem(int client, int page = 0)
{
Menu menu = new Menu(MenuLegitnessHandler);
menu.SetTitle("LMAOBOX L4D2");
menu.AddItem("0", "Aimbot");
menu.AddItem("1", "Misc");
menu.ExitButton = true;
menu.DisplayAt(client, page, MENU_TIME_FOREVER);
}
stock void DisplayAimbotMenuAtItem(int client, int page = 0)
{
Menu menu = new Menu(MenuAimbotHandler);
menu.SetTitle("Aimbot - Settings");
if(g_bAimbot[client])
menu.AddItem("0", "Aimbot: On");
else
menu.AddItem("0", "Aimbot: Off");
if(g_iAimType[client] == AIM_NEAR)
menu.AddItem("1", "Aim Type: Closest");
else if(g_iAimType[client] == AIM_FOV)
menu.AddItem("1", "Aim Type: FOV");
char FOV[64];
Format(FOV, sizeof(FOV), "Aim FOV: %.2f", g_flAimFOV[client]);
menu.AddItem("2", FOV);
if(g_bAutoShoot[client])
menu.AddItem("3", "Auto Shoot: On");
else
menu.AddItem("3", "Auto Shoot: Off");
if(g_bSilentAim[client])
menu.AddItem("4", "Silent Aim: On");
else
menu.AddItem("4", "Silent Aim: Off");
if(g_bHeadshots[client])
menu.AddItem("5", "Headshots only: On");
else
menu.AddItem("5", "Headshots only: Off");
menu.ExitButton = true;
menu.ExitBackButton = true;
menu.DisplayAt(client, page, MENU_TIME_FOREVER);
}
stock void DisplayMiscMenuAtItem(int client, int page = 0)
{
Menu menu = new Menu(MenuMiscHandler);
menu.SetTitle("Misc - Settings");
if(g_bBunnyHop[client])
menu.AddItem("0", "Bunny Hop: On");
else
menu.AddItem("0", "Bunny Hop: Off");
if(g_bAnnouncer[client])
menu.AddItem("1", "Kill Announcer: On");
else
menu.AddItem("1", "Kill Announcer: Off");
menu.ExitButton = true;
menu.ExitBackButton = true;
menu.DisplayAt(client, page, MENU_TIME_FOREVER);
}
public int MenuAimbotHandler(Menu menu, MenuAction action, int param1, int param2)
{
if (action == MenuAction_Select)
{
switch(param2)
{
case 0:
{
g_bAimbot[param1] = !g_bAimbot[param1];
if(!g_bAimbot[param1])
{
SetEntProp(param1, Prop_Data, "m_bLagCompensation", true);
SetEntProp(param1, Prop_Data, "m_bPredictWeapons", true);
//TE_Start("FoundryHelpers");
//TE_WriteNum("m_iEntity", -1);
//TE_SendToClient(param1);
}
}
case 1:
{
if (g_iAimType[param1] == AIM_NEAR) g_iAimType[param1] = AIM_FOV;
else if(g_iAimType[param1] == AIM_FOV) g_iAimType[param1] = AIM_NEAR;
}
case 2: { PrintToConsole(param1, "Fuck all."); }
case 3:
{
g_bAutoShoot[param1] = !g_bAutoShoot[param1];
}
case 4:
{
g_bSilentAim[param1] = !g_bSilentAim[param1];
}
case 5:
{
g_bHeadshots[param1] = !g_bHeadshots[param1];
}
}
DisplayAimbotMenuAtItem(param1, GetMenuSelectionPosition());
}
else if(param2 == MenuCancel_ExitBack)
{
DisplayHackMenuAtItem(param1);
}
else if(action == MenuAction_End)
{
delete menu;
}
}
public int MenuMiscHandler(Menu menu, MenuAction action, int param1, int param2)
{
if (action == MenuAction_Select)
{
switch(param2)
{
case 0: g_bBunnyHop[param1] = !g_bBunnyHop[param1];
case 1: g_bAnnouncer[param1] = !g_bAnnouncer[param1];
}
DisplayMiscMenuAtItem(param1, GetMenuSelectionPosition());
}
else if(param2 == MenuCancel_ExitBack)
{
DisplayHackMenuAtItem(param1);
}
else if(action == MenuAction_End)
{
delete menu;
}
}
public int MenuLegitnessHandler(Menu menu, MenuAction action, int param1, int param2)
{
if (action == MenuAction_Select)
{
switch(param2)
{
case 0: DisplayAimbotMenuAtItem(param1);
case 1: DisplayMiscMenuAtItem(param1);
}
}
else if(action == MenuAction_End)
{
delete menu;
}
}
public void OnEntityCreated(int entity, const char[] classname)
{
bool bShouldHighlight = false;
if(entity > 0 && entity <= MaxClients)
{
bShouldHighlight = true;
}
if (StrEqual(classname, "infected") || StrEqual(classname, "witch"))
{
bShouldHighlight = true;
}
if(bShouldHighlight)
{
for (int i = 1; i <= MaxClients; i++)
{
if(!IsClientInGame(i))
continue;
if(IsFakeClient(i))
continue;
if(!g_bAimbot[i])
continue;
if(i == entity)
continue;
//TE_Start("FoundryHelpers");
//TE_WriteNum("m_iEntity", entity);
//TE_SendToClient(i);
}
}
}
public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3], float angles[3], int &weapon, int &subtype, int &cmdnum, int &tickcount, int &seed, int mouse[2])
{
if(!IsClientInGame(client) || IsFakeClient(client) || !IsPlayerAlive(client))
return Plugin_Continue;
//On a ladder
if(GetEntityMoveType(client) == MOVETYPE_LADDER)
return Plugin_Continue;
//Can't do anything while hanging from ledge
if(GetEntProp(client, Prop_Send, "m_isHangingFromLedge"))
return Plugin_Continue;
float oldAngle[3]; oldAngle = angles;
float oldForward = vel[0];
float oldSideMove = vel[1];
if(g_bBunnyHop[client])
{
if((buttons & IN_JUMP) && GetEntityFlags(client) & FL_ONGROUND)
{
int nOldButtons = GetEntProp(client, Prop_Data, "m_nOldButtons");
SetEntProp(client, Prop_Data, "m_nOldButtons", (nOldButtons &= ~(IN_JUMP|IN_DUCK)));
}
}
if(g_bAimbot[client])
{
int iAw = GetActiveWeapon(client);
//Not holding a weapon
if(!IsValidEntity(iAw) || IsPlayerReloading(client))
return Plugin_Continue;
//Not a shooty weapon
if(!HasEntProp(iAw, Prop_Send, "m_iPrimaryAmmoType")
|| GetEntProp(iAw, Prop_Send, "m_iPrimaryAmmoType") == -1
|| !HasEntProp(iAw, Prop_Data, "m_iClip1")
|| GetEntProp(iAw, Prop_Data, "m_iClip1") <= 0)
return Plugin_Continue;
//Remove recoil
SetEntPropVector(client, Prop_Send, "m_vecPunchAngle", view_as<float>({0.0, 0.0, 0.0}));
SetEntPropVector(client, Prop_Data, "m_vecPunchAngle", view_as<float>({0.0, 0.0, 0.0}));
SetEntPropVector(client, Prop_Send, "m_vecPunchAngleVel", view_as<float>({0.0, 0.0, 0.0}));
SetEntPropVector(client, Prop_Data, "m_vecPunchAngleVel", view_as<float>({0.0, 0.0, 0.0}));
static int iOffsetToSpread;
if(iOffsetToSpread == 0) {
PrintToServer("[AIMBOT] Updated max_spread offset!");
iOffsetToSpread = FindSendPropInfo("CTerrorWeapon", "m_DroppedByInfectedGender") + 60;
}
static int iOffsetPunchAngle;
if(iOffsetPunchAngle == 0) {
PrintToServer("[AIMBOT] Updated PunchAngle offset!");
iOffsetPunchAngle = FindSendPropInfo("CBasePlayer", "m_Local") + 112;
}
//Some weird weapon recoil property hidden in the player
SetEntDataVector(client, iOffsetPunchAngle, view_as<float>( { 0.0, 0.0, 0.0 } ));
//Make the spread huge so the game doesn't have time to add any to it before the bullet trace happens.
SetEntDataFloat(iAw, iOffsetToSpread, -90.0);
DoAimbot(client, iAw, buttons, oldAngle, angles, vel[0], vel[1], oldForward, oldSideMove);
}
FixSilentAimMovement(client, oldAngle, angles, vel[0], vel[1], oldForward, oldSideMove);
return Plugin_Changed;
}
stock bool DoAimbot(int client, int iAw, int &buttons, const float vOldAngles[3], float vViewAngles[3],
float &flForwardMove, float &flSideMove, float &fOldForward, float &fOldSidemove)
{
SetEntProp(client, Prop_Data, "m_bLagCompensation", false);
SetEntProp(client, Prop_Data, "m_bPredictWeapons", false);
//float spread = GetEntDataFloat(iAw, iOffsetToSpread);
//PrintToServer("spread %f", spread);
//float flSpreadX = SDKCall(g_hSharedRandomFloat, "CTerrorGun::FireBullet HorizSpread", -spread, spread, 0);
//float flSpreadY = SDKCall(g_hSharedRandomFloat, "CTerrorGun::FireBullet VertSpread", -spread, spread, 0);
//
//PrintToServer("flSpreadX %f, flSpreadY %f", flSpreadX, flSpreadY);
//angles[0] += flSpreadX;
//angles[1] += flSpreadY;
//Force aim if user is holding m1
if(!(buttons & IN_ATTACK)) {
if(IsPlayerReloading(client) || !g_bAutoShoot[client]) {
return false;
}
}
int iTarget = INVALID_ENT_REFERENCE;
float target_point[3]; target_point = SelectBestTargetPos(client, vOldAngles, iTarget);
if (iTarget == INVALID_ENT_REFERENCE)
return false;
if(g_bAutoShoot[client] && (!(buttons & IN_ATTACK)))
{
//We can't simply hold M1 to fire, gotta let go of M1 every once in a while
if(IsPlayerReloading(client)) {
buttons &= ~IN_ATTACK;
} else {
buttons |= IN_ATTACK;
}
//(IsPlayerReloading(client) ? (buttons &= ~IN_ATTACK) : (buttons |= IN_ATTACK))
}
float target_point_adjusted[3];
if(fOldForward != 0 || fOldSidemove != 0)
{
//Extrapolate target_point if we are moving.
SubtractVectors(VelocityExtrapolate(iTarget, target_point),
VelocityExtrapolate(client, GetEyePosition(client)),
target_point_adjusted);
}
else
{
SubtractVectors(target_point, GetEyePosition(client), target_point_adjusted);
}
SnapEyeAngles(client, target_point_adjusted, vViewAngles);
return true;
}
stock int GetEnemyTeam(int ent)
{
int enemy_team = GetClientTeam(ent);
switch(enemy_team)
{
case 2: enemy_team = 3;
case 3: enemy_team = 2;
}
return enemy_team;
}
float[] VelocityExtrapolate(int client, float point[3])
{
float absVel[3];
GetEntPropVector(client, Prop_Data, "m_vecVelocity", absVel);
float v[3];
v[0] = point[0] + (absVel[0] * GetTickInterval());
v[1] = point[1] + (absVel[1] * GetTickInterval());
v[2] = point[2] + (absVel[2] * GetTickInterval());
return v;
}
float[] SelectBestTargetPos(int client, const float oldAngles[3], int &iBestEnemy)
{
float flMyPos[3]; flMyPos = GetEyePosition(client);
float flTargetPos[3];
float flClosestDistance = 8192.0;
//FOV aim stuff
float nearest;
float fov = g_flAimFOV[client];
//Shoot special infected
for (int i = 1; i <= MaxClients; i++)
{
if(i == client)
continue;
if(!IsClientInGame(i))
continue;
//SetEntProp(i, Prop_Send, "m_iGlowType", 0);
if(!IsPlayerAlive(i))
continue;
if(!IsValidAliveTarget(client, i))
continue;
//SetEntProp(i, Prop_Send, "m_iGlowType", 3);
//SetEntProp(i, Prop_Send, "m_glowColorOverride", 255 + (0 * 256) + (255 * 65536));
float vVisiblePos[3];
//Not visible at all.
if(!GetBestHitBox(client, i, vVisiblePos))
continue;
if(g_iAimType[client] == AIM_FOV)
{
nearest = GetFov(oldAngles, CalcAngle(GetEyePosition(client), GetEyePosition(i)));
if (nearest > fov)
continue;
float distance = GetDistance(GetAbsOrigin(client), GetAbsOrigin(i));
if (FloatAbs(fov - nearest) < 5)
{
if (distance < flClosestDistance)
{
fov = nearest;
flClosestDistance = distance;
flTargetPos = vVisiblePos;
iBestEnemy = i;
}
}
else if (nearest < fov)
{
fov = nearest;
flClosestDistance = distance;
flTargetPos = vVisiblePos;
iBestEnemy = i;
}
}
else
{
float flDistance = GetVectorDistance(flMyPos, vVisiblePos);
if(flDistance < flClosestDistance)
{
flClosestDistance = flDistance;
flTargetPos = vVisiblePos;
iBestEnemy = i;
}
}
}
if(iBestEnemy > 0)
{
return flTargetPos;
}
//Shoot infected because we didn't find special infected.
int infected = -1;
while((infected = FindEntityByClassname(infected, "infected")) != -1)
{
//SetEntProp(infected, Prop_Send, "m_iGlowType", 0);
if(!IsValidAliveTarget(client, infected))
continue;
//SetEntProp(infected, Prop_Send, "m_iGlowType", 3);
//SetEntProp(infected, Prop_Send, "m_glowColorOverride", 255 + (0 * 256) + (0 * 65536));
float vVisiblePos[3];
//Not visible at all.
if(!GetBestHitBox(client, infected, vVisiblePos))
continue;
if(g_iAimType[client] == AIM_FOV)
{
//TODO FIX GetEyePosition for infected
nearest = GetFov(oldAngles, CalcAngle(GetEyePosition(client), GetPlayerCenterOfMass(infected)));
if (nearest > fov)
continue;
float distance = GetDistance(GetAbsOrigin(client), GetAbsOrigin(infected));
if (FloatAbs(fov - nearest) < 5)
{
if (distance < flClosestDistance)
{
fov = nearest;
flClosestDistance = distance;
flTargetPos = vVisiblePos;
iBestEnemy = infected;
}
}
else if (nearest < fov)
{
fov = nearest;
flClosestDistance = distance;
flTargetPos = vVisiblePos;
iBestEnemy = infected;
}
}
else
{
float flDistance = GetVectorDistance(flMyPos, vVisiblePos);
if(flDistance < flClosestDistance)
{
flClosestDistance = flDistance;
flTargetPos = vVisiblePos;
iBestEnemy = infected;
}
}
}
//if(iBestEnemy > 0)
//{
//SetEntProp(iBestEnemy, Prop_Send, "m_glowColorOverride", 55 + (255 * 256) + (0 * 65536));
//}
return flTargetPos;
}
bool IsValidAliveTarget(int client, int entity)
{
//Target is not alive
if(GetEntProp(entity, Prop_Data, "m_lifeState") != 0)
return false;
//Burning zombies die off naturally
if(HasEntProp(entity, Prop_Data, "m_bIsBurning") && GetEntProp(entity, Prop_Data, "m_bIsBurning"))
return false;
//Target is not an enemy
if(GetEntProp(entity, Prop_Data, "m_iTeamNum") != GetEnemyTeam(client))
return false;
return true;
}
bool IsPlayerReloading(int client)
{
int PlayerWeapon = GetActiveWeapon(client);
if(!IsValidEntity(PlayerWeapon))
return true;
bool bReloading = true;
float flNextPrimaryAttack = GetGameTime() - GetEntPropFloat(PlayerWeapon, Prop_Send, "m_flNextPrimaryAttack");
bool m_bInReload = !!GetEntProp(PlayerWeapon, Prop_Data, "m_bInReload");
//Can fire?
if(flNextPrimaryAttack > 0)
bReloading = false;
//Has ammo and is not reloading
if(GetEntProp(PlayerWeapon, Prop_Send, "m_iClip1") <= 0 && m_bInReload)
bReloading = true;
return bReloading;
}
enum //hitgroup_t
{
HITGROUP_GENERIC,
HITGROUP_HEAD,
HITGROUP_CHEST,
HITGROUP_STOMACH,
HITGROUP_LEFTARM,
HITGROUP_RIGHTARM,
HITGROUP_LEFTLEG,
HITGROUP_RIGHTLEG,
NUM_HITGROUPS
};
int g_iHitBoxOrderHeadshot[] =
{
HITGROUP_HEAD,
HITGROUP_CHEST,
HITGROUP_STOMACH,
HITGROUP_GENERIC,
HITGROUP_LEFTARM,
HITGROUP_RIGHTARM,
HITGROUP_LEFTLEG,
HITGROUP_RIGHTLEG,
}
int g_iHitBoxOrderBullet[] =
{
HITGROUP_STOMACH,
HITGROUP_CHEST,
HITGROUP_GENERIC,
HITGROUP_HEAD,
HITGROUP_LEFTARM,
HITGROUP_RIGHTARM,
HITGROUP_LEFTLEG,
HITGROUP_RIGHTLEG,
}
stock bool GetBestHitBox(int client, int entity, float vBestOut[3])
{
Address pStudioHdr = Address(Dereference(Address(GetEntData(entity, g_iOffsetStudioHdr))));
if(pStudioHdr == Address_Null)
return false;
int m_nHitboxSet = GetEntProp(entity, Prop_Send, "m_nHitboxSet");
if(m_nHitboxSet != 0)
return false;
Address pHitBoxSet = pStudioHdr + Address(ReadInt(pStudioHdr + Address(0xB0)));
if(pHitBoxSet == Address_Null)
return false;
int iNumHitboxes = ReadInt(pHitBoxSet + Address(0x4));
//Into the abyss.
pHitBoxSet += Address(0xC);
//Check if any hitbox is visible in an order
//that makes sense for our active weapon
//In L4D2 all weapons can headshot (i think)
bool bShouldHeadshot = true;
//Loop all hitgroups
for (int i = 0; i < NUM_HITGROUPS; i++)
{
//Match hitgroup to order we want to check
int hitGroup = (bShouldHeadshot ? (g_iHitBoxOrderHeadshot[i]) : (g_iHitBoxOrderBullet[i]));
//User wants headshots only, don't check for any other hitbox than head.
if(g_bHeadshots[client] && hitGroup != HITGROUP_HEAD)
continue;
for (int iHitBox = 0; iHitBox < iNumHitboxes; iHitBox++)
{
//mstudiobbox_t
Address pbox = Address(pHitBoxSet + Address(iHitBox * 0x44));
if(pbox == Address_Null)
continue;
int iBone = ReadInt(pbox);
int iGroup = ReadInt(pbox + Address(0x4));
if(iGroup != hitGroup)
continue;
float vBonePosition[3], vBoneAngles[3];
GetBonePosition(entity, iBone, vBonePosition, vBoneAngles);
//TODO
//If doing headshot only, perform multipoint checking on head hitbox.
//Is center visible?
bool bVisible = false;
if(g_bHeadshots[client] && iGroup == HITGROUP_HEAD)
{
float vMins[3]; vMins = ExtractVectorFromAddress(pbox + Address(0x8));
float vMaxs[3]; vMaxs = ExtractVectorFromAddress(pbox + Address(0x14));
//Hitbox Size
float vSize[3];
vSize[0] = FloatAbs(vMaxs[0]) + FloatAbs(vMins[0]);
vSize[1] = FloatAbs(vMaxs[1]) + FloatAbs(vMins[1]);
vSize[2] = FloatAbs(vMaxs[2]) + FloatAbs(vMins[2]);
//Hitbox Origin
float vCenter[3];
AddVectors(vMins, vMaxs, vCenter);
ScaleVector(vCenter, 0.5);
//Angle vectors
float vForward[3], vLeft[3], vUp[3];
GetAngleVectors(vBoneAngles, vForward, vLeft, vUp);
//Center bone pos to hitbox
vBonePosition[0] += vLeft[2] * vCenter[2];
vBonePosition[1] += vLeft[0] * vCenter[0];
vBonePosition[2] -= vLeft[2] * vCenter[1];
}
bVisible = (IsPointVisible(client, entity, GetEyePosition(client), vBonePosition, hitGroup));
if(bVisible)
{
//Since we traverse the hitboxes in an ideal order,
//we may break/return on the first visible hitbox.
vBestOut = vBonePosition;
return true;
}
}
}
return false;
}
//TODO
stock float[] GetHitBox(int entity, int hitbox)
{
}
//Correct movement for silent aim
stock void FixSilentAimMovement(int client, const float vOldAngles[3], float vViewAngles[3], float &flForwardMove, float &flSideMove, float fOldForward, float fOldSidemove)
{
float deltaView;
float f1;
float f2;
if (vOldAngles[1] < 0.0)
f1 = 360.0 + vOldAngles[1];
else
f1 = vOldAngles[1];
if (vViewAngles[1] < 0.0)
f2 = 360.0 + vViewAngles[1];
else
f2 = vViewAngles[1];
if (f2 < f1)
deltaView = FloatAbs(f2 - f1);
else
deltaView = 360.0 - FloatAbs(f1 - f2);
deltaView = 360.0 - deltaView;
flForwardMove = Cosine(DegToRad(deltaView)) * fOldForward + Cosine(DegToRad(deltaView + 90.0)) * fOldSidemove;
flSideMove = Sine(DegToRad(deltaView)) * fOldForward + Sine(DegToRad(deltaView + 90.0)) * fOldSidemove;
}
stock bool IsPointVisible(int looker, int target, float start[3], float point[3], int expectedHitGroup)
{
TR_TraceRayFilter(start, point, 0x46004003, RayType_EndPoint, ShouldHitEntity, looker);
int hitGroup = TR_GetHitGroup();
int hitEnt = TR_GetEntityIndex();
//PrintToServer("hitEnt %i; got %i expected %i == %s", hitEnt, hitGroup, expectedHitGroup, hitGroup == expectedHitGroup ? "YES" : "NO");
if(!TR_DidHit() || hitEnt == target)
{
//Ignore hitgroup expectance if not headshot only.
if(g_bHeadshots[looker]) {
return hitGroup == expectedHitGroup
} else {
return true;
}
}
return false;
}
public bool ShouldHitEntity(int entity, int contentsMask, any iExclude)
{
char class[64]; GetEntityClassname(entity, class, sizeof(class));
if(entity > MaxClients)
{
//We can shoot through these :)
if(StrEqual(class, "func_breakable") || StrEqual(class, "func_brush")
|| StrEqual(class, "prop_door_rotating") || StrEqual(class, "prop_dynamic")
|| StrEqual(class, "prop_physics") || StrEqual(class, "func_simpleladder")
|| StrEqual(class, "prop_door_rotating_checkpoint") || StrEqual(class, "phys_bone_follower")
|| StrEqual(class, "prop_car_alarm") || StrEqual(class, "prop_car_glass")
|| StrEqual(class, "func_breakable_surf") || StrEqual(class, "env_player_blocker"))
{
return GetEntProp(entity, Prop_Data, "m_takedamage") != 2;
}
//if(!StrEqual(class, "infected"))
//PrintToServer("ShouldHitEntity %s", class);
}
return !(entity == iExclude);
}
stock void SnapEyeAngles(int client, float target_point[3], float cmdAngles[3])
{
float eye_to_target[3];
GetVectorAngles(target_point, eye_to_target);
eye_to_target[0] = AngleNormalize(eye_to_target[0]);
eye_to_target[1] = AngleNormalize(eye_to_target[1]);
eye_to_target[2] = 0.0;
cmdAngles = eye_to_target;
if(!g_bSilentAim[client]) {
TeleportEntity(client, NULL_VECTOR, eye_to_target, NULL_VECTOR);
}
}
stock float[] GetPlayerCenterOfMass(int client)
{
float v[3]; v = GetAbsOrigin(client);
float vecMaxs[3];
GetEntPropVector(client, Prop_Send, "m_vecMaxs", vecMaxs);
v[2] += (vecMaxs[2] / 2);
return v;
}
stock float AngleNormalize( float angle )
{
angle = angle - 360.0 * RoundToFloor(angle / 360.0);
while (angle > 180.0) angle -= 360.0;
while (angle < -180.0) angle += 360.0;
return angle;
}
stock void GetBonePosition(int iEntity, int iBone, float origin[3], float angles[3])
{
SDKCall(g_hGetBonePosition, iEntity, iBone, origin, angles);
}
stock float GetFov(const float viewAngle[3], const float aimAngle[3])
{
float ang[3], aim[3];
GetAngleVectors(viewAngle, aim, NULL_VECTOR, NULL_VECTOR);
GetAngleVectors(aimAngle, ang, NULL_VECTOR, NULL_VECTOR);
return RadToDeg(ArcCosine(GetVectorDotProduct(aim, ang) / GetVectorLength(aim, true)));
}
stock float[] CalcAngle(float src[3], float dst[3])
{
float angles[3];
float delta[3];
SubtractVectors(dst, src, delta);
GetVectorAngles(delta, angles);
return angles;
}