-
Notifications
You must be signed in to change notification settings - Fork 1
/
abounce.sp
executable file
·2035 lines (1625 loc) · 70.3 KB
/
abounce.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
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <tf2_stocks>
#include <sdktools>
public Plugin myinfo =
{
name = "Bounce Analyser",
author = "ILDPRUT",
description = "Shows possible bounce methods",
version = "1.0.10",
}
#define NaN view_as<float>(0x7FFFFFFF) // NaN
static const float NaNVector[3] = {NaN, NaN, NaN};
#define Inf view_as<float>(0x7F800000) // Inf
#define EPSILON 0.001
#define TIMER_INTERVAL 0.1 // Interval for live checking update
#define DIST_EPSILON 0.03125 // 1/(1 << 5) = 0.3125 // From coordsize.h
#define TICK_INTERVAL 0.015 // 1/0.015 = 66.6666...
#define JUMPVEL 289.0 // From CTFGameMovement::CheckJumpButton
#define MAXVEL 3500.0 // sv_maxvelocity
#define GRAVITY (-800.0) // -sv_gravity
#define ACCELERATION 10.0 // sv_accelerate
#define FRICTION 4.0 // sv_friction
#define STOP_SPEED 100.0 // sv_stopspeed
#define DUCK_SPEED_SCALE 0.33333333 // From CGameMovement::HandleDuckingSpeedCrop
#define BACK_SPEED_SCALE 0.9 // ConVar: tf_clamp_back_speed
#define BACK_SPEED_MIN 100.0 // ConVar: tf_clamp_back_speed_min
#define WALK_SPEED_AIMING 80.0 // TF_COND_AIMING // From CTFPlayer::TeamFortress_CalculateMaxSpeed
#define WALK_SPEED_SOLDIER 240.0
// From CTFGameMovement::CategorizePosition
#define GROUND_LAND_INTERVAL 2.0
#define GROUND_NORMAL_MIN 0.7
#define GROUND_LEAVE_SPEED 250.0
// From g_TFViewVectors when game is loaded
#define HULL_WIDTH 48.0
#define HULL_HEIGHT 82.0
#define HULL_HEIGHT_DUCK 62.0
#define HULL_HEIGHT_OLD 55.0
#define HULL_HEIGHT_DIFF (HULL_HEIGHT-HULL_HEIGHT_DUCK)
#define VIEW_HEIGHT 68.0
#define VIEW_HEIGHT_DUCK 45.0
// From CTFWeaponBaseGun::FireRocket and CTFWeaponBaseGun::FireEnergyBall
#define AIM_DISTANCE 2000.0
#define MASK_SURFACE (MASK_SOLID^CONTENTS_MONSTER)
// From wiki.alliedmods.net/Team_Fortress_2_Item_Definition_Indexes
#define INDEX_DIRECTHIT 127
#define INDEX_LIBERTY 414
#define INDEX_MANGLER 441
#define INDEX_ORIGINAL 513
#define INDEX_BEGGARS 730
#define INDEX_AIRSTRIKE 1104
// From CTFWeaponBaseGun::FireRocket and CTFWeaponBaseGun::FireEnergyBall
#define OFFSET_FORWARD 23.5
#define OFFSET_UP (-3.0)
#define OFFSET_UP_DUCK 8.0
#define OFFSET_STOCK 12.0
#define OFFSET_ORIGINAL 0.0
#define OFFSET_MANGLER 8.0
#define ROCKET_DAMAGE 90.0 // Found using CTFWeaponBaseGun::GetProjectileDamage
#define ROCKET_RADIUS 121.0 // From CTFBaseRocket::Explode and CTFProjectile_EnergyBall::Explode
#define ROCKET_RADIUS_CHARGED (1.33*ROCKET_RADIUS) // More precisely (float)0x4320EE14 = 160.9299926757812 ~ 160.93 = 1.33*ROCKET_RADIUS // Cow Mangler Alt Fire // From CTFProjectile_EnergyBall::Explode
#define ROCKET_FALLOFF 0.5 // From CTFRadiusDamageInfo::CalculateFalloff
#define ROCKET_SPEED 1100.0 // From CTFBaseRocket::Create and CTFParticleCannon::GetProjectileSpeed
#define ROCKET_SPEED_LIBERTY (1.4*ROCKET_SPEED) // = mult_projectile_speed*ROCKET_SPEED // From CTFBaseRocket::Create
#define ROCKET_SPEED_DIRECTHIT (1.8*ROCKET_SPEED) // = mult_projectile_speed*ROCKET_SPEED // From CTFBaseRocket::Create
#define ROCKET_SURFACE_OFFSET 1.0 // From CTFBaseRocket::Explode and CTFProjectile_EnergyBall::Explode
#define BLAST_PUSH_OFFSET_Z (-10.0) // From CTFPlayer::OnTakeDamage_Alive
#define DAMAGE_FACTOR_SOLDIER_AIR 0.6 // When not on ground or in water (FL_ONGROUND | FL_INWATER) // From CTFPlayer::OnTakeDamage
#define DAMAGE_FACTOR_DEMOMAN_WEAPON 0.75 // Using Grenade Launcher (ID:23) or Sticky Bomb Launcher (ID:24) // From CTFRadiusDamageInfo::ApplyToEntity
// From CTFPlayer::ApplyPushFromDamage
// Knockback factor from ducking was originally calculated using STANDING_VOLUME / CURRENT_VOLUME = VEC_HULL_SIZE[2] / VEC_CURRENT_HULL_SIZE[2], but it seems they changed VEC_DUCK_HULL_SIZE[2] from 55 to 62, and to keep jumping consistent they hardcoded 55 into the factoring.
#define PUSH_SCALE_STAND 1.0
#define PUSH_SCALE_DUCK (HULL_HEIGHT/HULL_HEIGHT_OLD)
#define PUSH_SCALE_DEFAULT 9.0 // From CTFPlayer::ApplyPushFromDamage
#define PUSH_SCALE_SOLDIER_GROUND 5.0 // If FL_ONGROUND // ConVar: tf_damageforcescale_self_soldier_badrj
#define PUSH_SCALE_SOLDIER 10.0 // ConVar: tf_damageforcescale_self_soldier_rj
#define PUSH_SCALE_PYRO 8.5 // ConVar: tf_damageforcescale_pyro_jump
enum
{
UNCROUCHED,
CROUCHED
}
enum
{
LAUNCHER_STOCK,
LAUNCHER_ORIGINAL,
LAUNCHER_MANGLER,
LAUNCHER_COUNT,
LAUNCHER_NONE
}
enum
{
BOUNCE_START_FALL,
BOUNCE_START_WALK,
BOUNCE_START_CROUCHWALK,
BOUNCE_START_JUMP,
BOUNCE_START_CROUCHJUMP,
BOUNCE_START_CTAPJUMP,
BOUNCE_START_CEILING,
BOUNCE_START_ANGLE_STANDING,
BOUNCE_START_ANGLE_DUCKING,
BOUNCE_START_COUNT
}
enum
{
BOUNCE_TYPE_UNCROUCHED,
BOUNCE_TYPE_CROUCHED,
BOUNCE_TYPE_JUMPBUG,
BOUNCE_TYPE_COUNT
}
enum
{
GROUND_NONE,
GROUND_CHANGED,
GROUND_UNCHANGED,
GROUND_STEEP
}
enum
{
SURFACE_NONE,
SURFACE_FLOOR,
SURFACE_CEILING,
SURFACE_WALL
}
enum
{
ENTITY_NONE = -1,
ENTITY_INVALID = -2
}
enum struct Plane
{
int edict;
float dist;
float normal[3];
void InitVars(const int edict, float dist, const float[] normal)
{
this.edict = edict;
this.dist = dist;
CopyVector(normal, this.normal);
}
}
enum struct Session
{
Plane ground;
Plane trigger;
Plane floor;
Plane ceiling;
Plane wall;
Plane wall_ground;
ArrayList bounces;
int indexer[BOUNCE_TYPE_COUNT*(BOUNCE_START_COUNT+1)]; // BOUNCE_START_ANGLE_STANDING is for the simplest launcher strat, BOUNCE_START_ANGLE_DUCKING is for the simplest strat for the player's launcher, and BOUNCE_START_COUNT is the angled start for the player's launcher
int displayed;
bool grounded;
float landtick;
float lastusetime;
}
enum struct Launcher
{
int launcher;
bool charged;
}
enum struct Bounce
{
int start;
int type;
Launcher launcher;
float pitch;
int input[2];
}
float LAUNCHER_RADIUS[2];
float LAUNCHER_OFFSET[LAUNCHER_COUNT][2][3];
float BOUNCE_START[BOUNCE_START_COUNT][2];
char TEXT_BOUNCE_START[BOUNCE_START_COUNT][50];
char TEXT_BOUNCE_TYPE[BOUNCE_TYPE_COUNT][50];
char TEXT_BOUNCE_INPUT[3][3][50];
char TEXT_LAUNCHER[LAUNCHER_COUNT+1][50];
bool g_paneldraw = false;
Session g_sessions[MAXPLAYERS+1];
ConVar g_convar_pos;
ConVar g_convar_live;
Handle g_timer_live;
public void OnPluginStart()
{
/* INITIALISE SESSIONS */
for (int client = 0; client <= MaxClients; client++) {
g_sessions[client].bounces = new ArrayList(sizeof(Bounce));
ClearSession(client);
}
/* SET ARRAYS */
BOUNCE_START[BOUNCE_START_FALL] [0] = 0.0; BOUNCE_START[BOUNCE_START_FALL] [1] = NaN; // Fall
BOUNCE_START[BOUNCE_START_WALK] [0] = 0.0; BOUNCE_START[BOUNCE_START_WALK] [1] = 0.5*(GRAVITY*TICK_INTERVAL) ; // Walk
BOUNCE_START[BOUNCE_START_CROUCHWALK] [0] = -HULL_HEIGHT_DIFF; BOUNCE_START[BOUNCE_START_CROUCHWALK] [1] = 0.5*(GRAVITY*TICK_INTERVAL) ; // Crouchwalk
BOUNCE_START[BOUNCE_START_JUMP] [0] = 0.0; BOUNCE_START[BOUNCE_START_JUMP] [1] = 0.5*(GRAVITY*TICK_INTERVAL) + JUMPVEL; // Jump
BOUNCE_START[BOUNCE_START_CROUCHJUMP] [0] = 0.0; BOUNCE_START[BOUNCE_START_CROUCHJUMP] [1] = JUMPVEL; // Crouchjump
BOUNCE_START[BOUNCE_START_CTAPJUMP] [0] = -HULL_HEIGHT_DIFF; BOUNCE_START[BOUNCE_START_CTAPJUMP] [1] = JUMPVEL; // C-tap jump
BOUNCE_START[BOUNCE_START_CEILING] [0] = -HULL_HEIGHT; BOUNCE_START[BOUNCE_START_CEILING] [1] = 0.5*(GRAVITY*TICK_INTERVAL) ; // Ceiling
BOUNCE_START[BOUNCE_START_ANGLE_STANDING][0] = 0.0; BOUNCE_START[BOUNCE_START_ANGLE_STANDING][1] = NaN; // Standing using launcher
BOUNCE_START[BOUNCE_START_ANGLE_DUCKING] [0] = -HULL_HEIGHT_DIFF; BOUNCE_START[BOUNCE_START_ANGLE_DUCKING] [1] = NaN; // Ducking using launcher
LAUNCHER_RADIUS[0] = ROCKET_RADIUS; // Normal
LAUNCHER_RADIUS[1] = ROCKET_RADIUS_CHARGED; // Charged
float offsets[3] = {OFFSET_STOCK, OFFSET_ORIGINAL, OFFSET_MANGLER};
float offset[3] = {OFFSET_FORWARD, NaN, NaN};
for (int launcher = 0; launcher < LAUNCHER_COUNT; launcher++) {
offset[1] = offsets[launcher];
offset[2] = OFFSET_UP ; CopyVector(offset, LAUNCHER_OFFSET[launcher][UNCROUCHED]); // Uncrouched
offset[2] = OFFSET_UP_DUCK ; CopyVector(offset, LAUNCHER_OFFSET[launcher][CROUCHED] ); // Crouched
}
TEXT_BOUNCE_START[BOUNCE_START_FALL] = "Fall";
TEXT_BOUNCE_START[BOUNCE_START_WALK] = "Walk off";
TEXT_BOUNCE_START[BOUNCE_START_CROUCHWALK] = "Crouchwalk off";
TEXT_BOUNCE_START[BOUNCE_START_JUMP] = "Jump off";
TEXT_BOUNCE_START[BOUNCE_START_CROUCHJUMP] = "Crouchjump off";
TEXT_BOUNCE_START[BOUNCE_START_CTAPJUMP] = "C-tap off";
TEXT_BOUNCE_START[BOUNCE_START_CEILING] = "Hit ceiling";
TEXT_BOUNCE_START[BOUNCE_START_ANGLE_STANDING] = "Walk ";
TEXT_BOUNCE_START[BOUNCE_START_ANGLE_DUCKING] = "Crouch ";
TEXT_BOUNCE_TYPE[BOUNCE_TYPE_UNCROUCHED] = "Uncrouched";
TEXT_BOUNCE_TYPE[BOUNCE_TYPE_CROUCHED] = "Crouched";
TEXT_BOUNCE_TYPE[BOUNCE_TYPE_JUMPBUG] = "Jumpbug";
TEXT_BOUNCE_INPUT[0][0] = "Back+Left";
TEXT_BOUNCE_INPUT[0][1] = "Back";
TEXT_BOUNCE_INPUT[0][2] = "Back+Right";
TEXT_BOUNCE_INPUT[1][0] = "Left";
TEXT_BOUNCE_INPUT[1][1] = "Stand";
TEXT_BOUNCE_INPUT[1][2] = "Right";
TEXT_BOUNCE_INPUT[2][0] = "Forward+Left";
TEXT_BOUNCE_INPUT[2][1] = "Forward";
TEXT_BOUNCE_INPUT[2][2] = "Forward+Right";
TEXT_LAUNCHER[LAUNCHER_STOCK] = "Stock";
TEXT_LAUNCHER[LAUNCHER_ORIGINAL] = "Original";
TEXT_LAUNCHER[LAUNCHER_MANGLER] = "Mangler";
TEXT_LAUNCHER[LAUNCHER_MANGLER+1] = "Mangler Alt.";
RegConsoleCmd("sm_bounce", Command_Bounce);
RegConsoleCmd("sm_bcheck", Command_Bounce);
g_convar_pos = CreateConVar("sm_abounce_pos", "0", "Enables use of the player's current position");
g_convar_live = CreateConVar("sm_abounce_live", "0", "Enables live checking");
AutoExecConfig(true, "abounce");
if (g_convar_live.BoolValue) {
g_timer_live = CreateTimer(TIMER_INTERVAL, Timer_Live, _, TIMER_REPEAT);
}
g_convar_live.AddChangeHook(ConVarChanged_Live);
}
public void OnClientConnected(int client)
{
ClearSession(client);
}
public void OnClientDisconnect_Post(int client)
{
ClearSession(client);
}
public void ConVarChanged_Live(ConVar convar, const char[] old_value, const char[] new_value)
{
if (strcmp(old_value, new_value) == 0)
return;
if (convar.BoolValue)
g_timer_live = CreateTimer(TIMER_INTERVAL, Timer_Live, _, TIMER_REPEAT);
else
CloseHandle(g_timer_live);
}
public Action Timer_Live(Handle timer)
{
for (int client = 1; client <= MaxClients; client++) {
if (!IsClientInGame(client))
continue;
else if (!IsPlayerAlive(client))
continue;
if (g_sessions[client].ground.edict <= ENTITY_NONE)
continue;
float pos[3]; GetEntPropVector(client, Prop_Data, "m_vecOrigin", pos);
float vel[3]; GetEntPropVector(client, Prop_Data, "m_vecVelocity", vel);
int ground = GetEntPropEnt(client, Prop_Data, "m_hGroundEntity");
int ducked = (GetEntProp(client, Prop_Data, "m_fFlags") & FL_DUCKING) > 0;
float landtick = GetLandTickFromStartZVel(TICK_INTERVAL, GRAVITY, MAXVEL, (pos[2] - ducked*HULL_HEIGHT_DIFF) - GetGroundZ(g_sessions[client]), vel[2]);
if (FloatIsNaN(landtick))
return Plugin_Continue;
float diff = landtick - g_sessions[client].landtick;
bool changed = EPSILON <= FloatFraction(diff) < 1 - EPSILON;
bool statechange = (g_sessions[client].grounded) ^ (ground >= 0);
g_sessions[client].grounded = ground >= 0;
g_sessions[client].landtick = landtick;
if (statechange || changed&&ground==-1) {
UpdateBounces(client);
ShowMenu(client);
}
}
return Plugin_Continue;
}
void ClearSession(int client)
{
g_sessions[client].ground.InitVars(ENTITY_NONE, NaN, NaNVector);
g_sessions[client].trigger.InitVars(ENTITY_NONE, NaN, NaNVector);
g_sessions[client].floor.InitVars(ENTITY_NONE, NaN, NaNVector);
g_sessions[client].ceiling.InitVars(ENTITY_NONE, NaN, NaNVector);
g_sessions[client].wall.InitVars(ENTITY_NONE, NaN, NaNVector);
g_sessions[client].bounces.Clear();
for (int i = 0; i < BOUNCE_TYPE_COUNT*BOUNCE_START_COUNT; i++)
g_sessions[client].indexer[i] = -1;
g_sessions[client].displayed = BOUNCE_TYPE_COUNT;
g_sessions[client].lastusetime = GetGameTime();
}
int GetLauncher(int client)
{
if (!IsPlayerAlive(client) || TF2_GetPlayerClass(client) != TFClass_Soldier)
return LAUNCHER_NONE;
int launcheredict = GetPlayerWeaponSlot(client, 0);
if (launcheredict == -1)
return LAUNCHER_NONE;
int launcherid = GetEntProp(launcheredict, Prop_Send, "m_iItemDefinitionIndex");
int launcher;
switch (launcherid) {
case INDEX_ORIGINAL:
launcher = LAUNCHER_ORIGINAL;
case INDEX_MANGLER:
launcher = LAUNCHER_MANGLER;
case INDEX_DIRECTHIT, INDEX_LIBERTY, INDEX_BEGGARS, INDEX_AIRSTRIKE:
launcher = LAUNCHER_STOCK; // Treat as stock
default:
launcher = LAUNCHER_STOCK; // Assume stock
}
return launcher;
}
Action Command_Bounce(int client, int args)
{
if (GetGameTime() < g_sessions[client].lastusetime + 0.1) {
PrintToChat(client, "Wait 0.1 seconds between bcheck actions.");
return Plugin_Handled;
}
float ray_start[3];
float ray_angle[3];
GetClientEyePosition(client, ray_start);
GetClientEyeAngles(client, ray_angle);
UpdateGround(client, ray_start, ray_angle);
UpdateBounces(client);
ShowMenu(client);
g_sessions[client].lastusetime = GetGameTime();
return Plugin_Handled;
}
/* SESSION */
void UpdateGround(int client, float start[3], float angle[3])
{
int ground = FindGround(client, start, angle);
if (ground == GROUND_CHANGED) {
g_sessions[client].floor.InitVars(ENTITY_NONE, NaN, NaNVector);
g_sessions[client].ceiling.InitVars(ENTITY_NONE, NaN, NaNVector);
g_sessions[client].wall.InitVars(ENTITY_NONE, NaN, NaNVector);
}
if (ground != GROUND_NONE) {
bool newfloor = false;
float pos[3];
GetClientAbsOrigin(client, pos);
Plane plane;
FindPlane(ENTITY_NONE, pos, NaNVector, plane);
if (plane.edict > ENTITY_NONE) {
float dot = plane.dist - g_sessions[client].floor.dist;
if (!CompareVectors(plane.normal, g_sessions[client].floor.normal) || FloatIsNaN(dot) || FloatAbs(dot) > EPSILON)
newfloor = true;
newfloor &= CompareVectors(plane.normal, {0.0, 0.0, 1.0});
}
if (newfloor) {
g_sessions[client].floor.InitVars(plane.edict, plane.dist, plane.normal);
}
else if (g_convar_pos.BoolValue) {
bool setfloor = plane.edict > ENTITY_NONE ? plane.normal[2] >= GROUND_NORMAL_MIN : false;
if (!setfloor) {
float mins[3];
float maxs[3];
mins[0] = -HULL_WIDTH/2.0 - DIST_EPSILON; mins[1] = -HULL_WIDTH/2.0 - DIST_EPSILON; mins[2] = 0.0;
maxs[0] = HULL_WIDTH/2.0 + DIST_EPSILON; maxs[1] = HULL_WIDTH/2.0 + DIST_EPSILON; maxs[2] = HULL_HEIGHT;
TR_TraceHullFilter(pos, pos, mins, maxs, MASK_PLAYERSOLID, TraceEntityFilterPlayer);
setfloor = TR_AllSolid();
}
if (setfloor) {
int edict = plane.edict > ENTITY_NONE ? plane.edict : ENTITY_INVALID;
g_sessions[client].floor.InitVars(edict, pos[2] - DIST_EPSILON, {0.0, 0.0, 1.0});
}
}
}
if (ground == GROUND_CHANGED)
g_sessions[client].displayed = BOUNCE_TYPE_COUNT;
}
int CompareBounces(int index1, int index2, Handle array, Handle datapack)
{
Bounce bounce1; GetArrayArray(array, index1, bounce1);
Bounce bounce2; GetArrayArray(array, index2, bounce2);
int launcher = -1;
if (datapack != INVALID_HANDLE) {
ResetPack(datapack);
launcher = ReadPackCell(datapack);
}
if (bounce1.type < bounce2.type)
return -1;
else if (bounce1.type > bounce2.type)
return 1;
if (bounce1.start == BOUNCE_START_FALL && bounce2.start != BOUNCE_START_FALL)
return -1;
else if (bounce1.start != BOUNCE_START_FALL && bounce2.start == BOUNCE_START_FALL)
return 1;
else if (bounce1.start < bounce2.start && bounce1.start <= BOUNCE_START_CEILING)
return -1;
else if (bounce1.start > bounce2.start && bounce2.start <= BOUNCE_START_CEILING)
return 1;
else if (bounce1.start <= BOUNCE_START_CEILING && bounce2.start <= BOUNCE_START_CEILING)
return 0;
int com1 = bounce1.input[0]*bounce1.input[0] + bounce1.input[1]*bounce1.input[1];
int com2 = bounce2.input[0]*bounce2.input[0] + bounce2.input[1]*bounce2.input[1];
if (com1 < com2)
return -1;
else if (com1 > com2)
return 1;
if (!FloatIsNaN(bounce1.pitch) && FloatIsNaN(bounce2.pitch))
return -1;
else if (FloatIsNaN(bounce1.pitch) && !FloatIsNaN(bounce2.pitch))
return 1;
if (bounce1.launcher.launcher == launcher || bounce2.launcher.launcher == launcher) {
if (bounce2.launcher.launcher != launcher)
return -1;
if (bounce1.launcher.launcher != launcher)
return 1;
}
else {
if (bounce1.launcher.launcher < bounce2.launcher.launcher)
return -1;
else if (bounce1.launcher.launcher > bounce2.launcher.launcher)
return 1;
}
if (com1 != 2 && com2 != 2) {
if (bounce1.input[0] != 0 && bounce2.input[1] != 0)
return -1;
else if (bounce2.input[0] != 0 && bounce1.input[1] != 0)
return 1;
}
if (bounce1.start < bounce2.start)
return -1;
else if (bounce1.start > bounce2.start)
return 1;
if (bounce1.launcher.charged < bounce2.launcher.charged)
return -1;
else if (bounce1.launcher.charged > bounce2.launcher.charged)
return 1;
return 0;
}
void UpdateBounces(int client)
{
g_sessions[client].bounces.Clear();
for (int type = 0; type < BOUNCE_TYPE_COUNT; type++) {
Bounce bounce;
bounce.type = type;
for (int start = 0; start <= BOUNCE_START_CEILING; start++) {
bounce.start = start;
if (start == BOUNCE_START_FALL) {
float pos[3]; GetEntPropVector(client, Prop_Data, "m_vecOrigin", pos);
float vel[3]; GetEntPropVector(client, Prop_Data, "m_vecVelocity", vel);
if (g_convar_live.BoolValue || g_sessions[client].floor.edict == ENTITY_INVALID && FloatAbs(vel[2] - 0.5*GRAVITY*TICK_INTERVAL) < EPSILON) {
if (GetEntProp(client, Prop_Data, "m_fFlags") & FL_DUCKING)
pos[2] -= HULL_HEIGHT_DIFF;
Plane floor; floor = g_sessions[client].floor;
if (g_convar_live.BoolValue)
g_sessions[client].floor.InitVars(ENTITY_INVALID, pos[2] - DIST_EPSILON, {0.0, 0.0, 1.0});
g_sessions[client].floor.edict = 0;
BOUNCE_START[BOUNCE_START_FALL][1] = vel[2];
if (!g_sessions[client].grounded && CheckBounce(g_sessions[client], bounce))
g_sessions[client].bounces.PushArray(bounce);
g_sessions[client].floor = floor;
}
}
else if (CheckBounce(g_sessions[client], bounce))
g_sessions[client].bounces.PushArray(bounce);
}
for (int l = 0; l < LAUNCHER_COUNT; l++) {
bounce.launcher.launcher = l;
// Add angled bounce for launcher
bounce.start = BOUNCE_START_ANGLE_STANDING;
bounce.pitch = NaN;
bounce.input[0] = 0;
bounce.input[1] = 0;
bounce.launcher.charged = false;
float pitch[2];
GetPitchInterval(g_sessions[client], bounce, pitch);
if (!FloatIsNaN(pitch[0]) && !FloatIsNaN(pitch[1]))
g_sessions[client].bounces.PushArray(bounce);
bounce.pitch = DegToRad(89.0);
int cm = view_as<int>(l == LAUNCHER_MANGLER);
for (int c = 0; c <= cm; c++) {
bounce.launcher.charged = !!c; // Convert c to bool
for (int start = BOUNCE_START_ANGLE_STANDING; start < BOUNCE_START_COUNT; start++) {
bounce.start = start;
for (int f = -1; f <= 1; f++) {
int side = l == LAUNCHER_ORIGINAL ? 0 : -1;
for (int r = side; r <= 1; r++) {
bounce.input[0] = f; bounce.input[1] = r;
if (CheckBounce(g_sessions[client], bounce))
g_sessions[client].bounces.PushArray(bounce);
} // H
} // e
} // l
} // l
} // o
} // !
SortADTArrayCustom(g_sessions[client].bounces, CompareBounces, INVALID_HANDLE);
for (int i = 0; i < BOUNCE_TYPE_COUNT*(BOUNCE_START_COUNT+1); i++)
g_sessions[client].indexer[i] = -1;
int launcher = GetLauncher(client);
DataPack datapack = new DataPack();
datapack.WriteCell(launcher);
for (int i = 0; i < g_sessions[client].bounces.Length; i++) {
Bounce bounce; g_sessions[client].bounces.GetArray(i, bounce);
if (bounce.start <= BOUNCE_START_CEILING) {
g_sessions[client].indexer[bounce.type*(BOUNCE_START_COUNT+1) + bounce.start] = i;
}
else {
int strats = bounce.type*(BOUNCE_START_COUNT+1) + BOUNCE_START_ANGLE_STANDING;
int stratl = bounce.type*(BOUNCE_START_COUNT+1) + BOUNCE_START_ANGLE_DUCKING;
int strata = bounce.type*(BOUNCE_START_COUNT+1) + BOUNCE_START_COUNT;
if (FloatIsNaN(bounce.pitch)) {
if (bounce.launcher.launcher == launcher)
g_sessions[client].indexer[strata] = i;
continue;
}
if (g_sessions[client].indexer[stratl] == -1) {
if (g_sessions[client].indexer[strats] == -1)
g_sessions[client].indexer[strats] = i;
else if (CompareBounces(i, g_sessions[client].indexer[strats], g_sessions[client].bounces, datapack) == -1)
g_sessions[client].indexer[strats] = i;
}
if (bounce.launcher.launcher == launcher) {
if (g_sessions[client].indexer[stratl] == -1)
g_sessions[client].indexer[stratl] = i;
else if (CompareBounces(i, g_sessions[client].indexer[stratl], g_sessions[client].bounces, datapack) == -1)
g_sessions[client].indexer[stratl] = i;
g_sessions[client].indexer[strats] = -1;
}
}
}
delete datapack;
}
void BounceString(Session session, Bounce bounce, char[] buffer, int size)
{
if (bounce.start <= BOUNCE_START_CEILING) {
strcopy(buffer, size, TEXT_BOUNCE_START[bounce.start]);
}
else {
int li = bounce.launcher.charged ? bounce.launcher.launcher + 1 : bounce.launcher.launcher;
int f = bounce.input[0]; int r = bounce.input[1];
if (FloatIsNaN(bounce.pitch)) {
// Best place to calculate angled bounces sadly
float pitch[2];
GetPitchInterval(session, bounce, pitch);
FormatEx(buffer, size, "(%s) %.2f°-%.2f°", TEXT_LAUNCHER[bounce.launcher.launcher], float(RoundToCeil(RadToDeg(pitch[0])*100))/100 + 0.005, float(RoundToFloor(RadToDeg(pitch[1])*100))/100 + 0.005);
}
else if (f == 0 && r == 0) {
if (bounce.start == BOUNCE_START_ANGLE_STANDING)
FormatEx(buffer, size, "(%s) Stand", TEXT_LAUNCHER[li]);
else if (bounce.start == BOUNCE_START_ANGLE_DUCKING)
FormatEx(buffer, size, "(%s) Crouch", TEXT_LAUNCHER[li]);
}
else {
if (bounce.launcher.launcher == LAUNCHER_ORIGINAL && bounce.input[1] != 0)
FormatEx(buffer, size, "(%s) %s%s/%s", TEXT_LAUNCHER[li], TEXT_BOUNCE_START[bounce.start], TEXT_BOUNCE_INPUT[f+1][0], TEXT_BOUNCE_INPUT[1][2]);
else
FormatEx(buffer, size, "(%s) %s%s", TEXT_LAUNCHER[li], TEXT_BOUNCE_START[bounce.start], TEXT_BOUNCE_INPUT[f+1][r+1]);
}
}
}
void DrawBounceType(int client, Panel panel, int type)
{
char line[50];
bool empty = true;
bool hassimple = false;
for (int start = 0; start <= BOUNCE_START_COUNT; start++) {
if (g_sessions[client].indexer[type*(BOUNCE_START_COUNT+1) + start] >= 0) {
empty = false;
if (start < BOUNCE_START_CEILING && start != BOUNCE_START_FALL)
hassimple = true;
}
}
panel.CurrentKey = 3 + type;
strcopy(line, sizeof(line), TEXT_BOUNCE_TYPE[type]);
if (empty || g_sessions[client].floor.edict <= ENTITY_NONE && g_sessions[client].ceiling.edict <= ENTITY_NONE) {
panel.DrawItem(line, ITEMDRAW_DISABLED);
if (empty) {
panel.DrawText(" No setups found");
return;
}
}
else {
panel.DrawItem(line);
}
bool drawall = g_sessions[client].displayed != BOUNCE_TYPE_COUNT;
int size = drawall ? g_sessions[client].bounces.Length : BOUNCE_START_COUNT+1;
for (int i = 0; i < size; i++) {
int index = drawall ? i : g_sessions[client].indexer[type*(BOUNCE_START_COUNT+1) + i];
if (index < 0)
continue;
Bounce bounce; g_sessions[client].bounces.GetArray(index, bounce);
if (drawall && bounce.type != type)
continue;
if (!drawall) {
if (i > BOUNCE_START_CEILING && hassimple)
continue;
int indexl = g_sessions[client].indexer[type*(BOUNCE_START_COUNT+1) + BOUNCE_START_ANGLE_DUCKING];
if (i == BOUNCE_START_ANGLE_STANDING && index == indexl)
continue;
if (i == BOUNCE_START_COUNT && indexl >= 0) {
Bounce bouncel; g_sessions[client].bounces.GetArray(indexl, bouncel);
if (bouncel.input[0]*bouncel.input[0] + bouncel.input[1]*bouncel.input[1] == 0)
continue;
}
}
BounceString(g_sessions[client], bounce, line, sizeof(line));
Format(line, sizeof(line), " %s", line);
// Need to add 10 for some reason
if (strlen(line) + strlen(" and more...") + 10 <= panel.TextRemaining) {
panel.DrawText(line);
}
else {
panel.DrawText(" and more...");
break;
}
}
}
void ShowMenu(int client)
{
char line[50];
char addl[20];
char snum[10];
Panel panel = new Panel();
panel.SetTitle("Bounce analyser");
panel.DrawText(" ");
float groundangle = RadToDeg(ArcCosine(g_sessions[client].ground.normal[2]));
bool steep = g_sessions[client].ground.normal[2] < GROUND_NORMAL_MIN;
if (g_sessions[client].ground.edict > ENTITY_NONE) {
if (!steep)
FormatEx(line, sizeof(line), "Ground slope: %d°", RoundToNearest(groundangle));
else
FormatEx(line, sizeof(line), "Ground slope: %d° (too steep)", RoundToNearest(groundangle));
}
else
FormatEx(line, sizeof(line), "No ground selected");
panel.DrawText(line);
float triggerheight = GetTriggerHeight(g_sessions[client]);
FloatString(triggerheight, snum, sizeof(snum));
if (g_sessions[client].trigger.edict > ENTITY_NONE) {
if (CompareVectors(g_sessions[client].ground.normal, g_sessions[client].trigger.normal))
FormatEx(addl, sizeof(addl), "");
else if (IsWallValid(g_sessions[client]))
FormatEx(addl, sizeof(addl), " (wall)");
else
FormatEx(addl, sizeof(addl), " (point)");
if (FloatIsNaN(triggerheight))
FormatEx(line, sizeof(line), "Teleport height: Undefined");
if (triggerheight <= GROUND_LAND_INTERVAL + EPSILON)
FormatEx(line, sizeof(line), "Teleport height: %s%s", snum, addl);
else if (triggerheight <= GROUND_LAND_INTERVAL + BOUNCE_START[BOUNCE_START_JUMP][1]*TICK_INTERVAL + EPSILON)
FormatEx(line, sizeof(line), "Teleport height: %s%s (jumpbug only)", snum, addl);
else
FormatEx(line, sizeof(line), "Teleport height: %s%s (impossible)", snum, addl);
}
else if (g_sessions[client].trigger.edict == ENTITY_INVALID) {
FormatEx(line, sizeof(line), "Bad teleport orientation");
}
else {
FormatEx(line, sizeof(line), "No teleport found");
}
panel.DrawText(line);
if (CompareVectors(g_sessions[client].ground.normal, {0.0, 0.0, 1.0}))
FormatEx(addl, sizeof(addl), "");
else if (IsWallValid(g_sessions[client]))
FormatEx(addl, sizeof(addl), " (wall)");
else
FormatEx(addl, sizeof(addl), " (point)");
float floorheight = g_sessions[client].floor.dist - GetGroundZ(g_sessions[client]);
FloatString(floorheight, snum, sizeof(snum));
if (g_sessions[client].floor.edict > ENTITY_NONE) {
if (FloatIsNaN(floorheight))
FormatEx(line, sizeof(line), "Floor height: Undefined");
else
FormatEx(line, sizeof(line), "Floor height: %s%s", snum, addl);
}
else {
FormatEx(line, sizeof(line), "No floor selected");
}
panel.DrawText(line);
float ceilingheight = -g_sessions[client].ceiling.dist - GetGroundZ(g_sessions[client]);
FloatString(ceilingheight, snum, sizeof(snum));
if (g_sessions[client].ceiling.edict > ENTITY_NONE)
if (FloatIsNaN(ceilingheight))
FormatEx(line, sizeof(line), "Ceiling height: Undefined");
else
FormatEx(line, sizeof(line), "Ceiling height: %s%s", snum, addl);
else
FormatEx(line, sizeof(line), "No ceiling selected");
panel.DrawText(line);
panel.DrawText(" ");
if (g_sessions[client].ground.normal[2] == 1.0)
line = "Select start floor/ceiling";
else
line = "Select start floor/ceiling/wall";
panel.CurrentKey = 1;
panel.DrawItem("Select ground");
panel.CurrentKey = 2;
panel.DrawItem(line);
panel.DrawText(" ");
int typestart = 0;
int typeend = BOUNCE_TYPE_COUNT;
if (g_sessions[client].displayed != BOUNCE_TYPE_COUNT) {
typestart = g_sessions[client].displayed;
typeend = typestart + 1;
}
for (int type = typestart; type < typeend; type++) {
DrawBounceType(client, panel, type);
panel.DrawText(" ");
}
panel.CurrentKey = 10;
panel.DrawItem("Exit");
g_paneldraw = true;
panel.Send(client, PanelHandler, 0);
g_paneldraw = false;
delete panel;
}
public int PanelHandler(Menu menu, MenuAction action, int client, int choice)
{
if (action == MenuAction_Select) {
if (choice == 10) {
ClearSession(client);
return 0;
}
if (GetGameTime() < g_sessions[client].lastusetime + 0.1) {
PrintToChat(client, "Wait 0.1 seconds between bcheck actions.");
return 0;
}
if (choice <= 2) {
float ray_start[3];
float ray_angle[3];
GetClientEyePosition(client, ray_start);
GetClientEyeAngles(client, ray_angle);
if (choice == 1)
UpdateGround(client, ray_start, ray_angle);
else if (choice == 2)
FindSurface(client, ray_start, ray_angle);
UpdateBounces(client);
}
if (3 <= choice <= 5) {
if (g_sessions[client].displayed == BOUNCE_TYPE_COUNT) {
switch (choice) {
case 3:
g_sessions[client].displayed = BOUNCE_TYPE_UNCROUCHED;
case 4:
g_sessions[client].displayed = BOUNCE_TYPE_CROUCHED;
case 5:
g_sessions[client].displayed = BOUNCE_TYPE_JUMPBUG;
}
}
else {
g_sessions[client].displayed = BOUNCE_TYPE_COUNT;
}
}
g_sessions[client].lastusetime = GetGameTime();
ShowMenu(client);
}
else if (action == MenuAction_Cancel) {
if (!g_paneldraw)
ClearSession(client);
}
return 0;
}
/* PLUGIN */
bool TraceEntityFilterPlayer(int entity, int contentsMask) { return (entity == 0 || entity > MaxClients); }
void FindPlane(int edict, const float start[3], const float angle[3], Plane plane, float end[3] = NULL_VECTOR)
{
plane.InitVars(ENTITY_NONE, NaN, NaNVector);
if (!IsNullVector(end))
end = {NaN, NaN, NaN};
bool do_hull = FloatIsNaN(angle[0]) || FloatIsNaN(angle[1]) || FloatIsNaN(angle[2]); // Being NaN means hull check down
float mins[3];
float maxs[3];
if (do_hull) {
mins[0] = -HULL_WIDTH/2.0; mins[1] = -HULL_WIDTH/2.0; mins[2] = 0.0;
maxs[0] = HULL_WIDTH/2.0; maxs[1] = HULL_WIDTH/2.0; maxs[2] = 0.0;
}
else {
mins[0] = -0.01/2.0; mins[1] = -0.01/2.0; mins[2] = 0.0;
maxs[0] = 0.01/2.0; maxs[1] = 0.01/2.0; maxs[2] = 0.01;
}
Handle trace_rough;
if (edict > ENTITY_NONE)
{
trace_rough = TR_ClipRayToEntityEx(start, angle, MASK_ALL, RayType_Infinite, edict);
}
else if (do_hull) {
float end_hull[3];
end_hull[0] = start[0]; end_hull[1] = start[1]; end_hull[2] = start[2] - GROUND_LAND_INTERVAL;
trace_rough = TR_TraceHullFilterEx(start, end_hull, mins, maxs, MASK_PLAYERSOLID, TraceEntityFilterPlayer);
}
else {
trace_rough = TR_TraceRayFilterEx(start, angle, MASK_PLAYERSOLID, RayType_Infinite, TraceEntityFilterPlayer);
}
if (!TR_DidHit(trace_rough)) {
CloseHandle(trace_rough);
return;
}
float point[3];
float normal[3];
TR_GetEndPosition(point, trace_rough);
TR_GetPlaneNormal(trace_rough, normal);
CloseHandle(trace_rough);
if (edict <= ENTITY_NONE && !do_hull && normal[2] != 0.0 && FloatAbs(normal[2]) != 1.0) {
float dir[3] = {0.0, 0.0, 0.0};
dir[2] = normal[2] > 0.0 ? 1.0 : -1.0;