summaryrefslogtreecommitdiff
path: root/sourcemod/scripting/include/distbugfix.inc
blob: 6a7ed18da8649f24819b592ad39424c2a30af154 (plain)
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

#if defined _distbug_included
	#endinput
#endif
#define _distbug_included

#define DISTBUG_CONFIG_NAME "distbugfix"

#define CHAT_PREFIX     "{d}[{l}GC{d}]"
#define CONSOLE_PREFIX  "[GC]"
#define CHAT_SPACER     " {d}|{g} "
#define DISTBUG_VERSION "2.0.0"

#define MAX_STRAFES     32
#define MAX_EDGE        32.0
#define MAX_JUMP_FRAMES	150 // for frame based arrays
#define MAX_BHOP_FRAMES	8

#define MAX_COOKIE_SIZE 32

enum
{
	SETTINGS_DISTBUG_ENABLED      = (1 << 0),
	SETTINGS_SHOW_VEER_BEAM       = (1 << 1),
	SETTINGS_SHOW_JUMP_BEAM       = (1 << 2),
	SETTINGS_SHOW_HUD_GRAPH       = (1 << 3),
	SETTINGS_DISABLE_STRAFE_STATS = (1 << 4),
	SETTINGS_DISABLE_STRAFE_GRAPH = (1 << 5),
	SETTINGS_ADV_CHAT_STATS       = (1 << 6),
}

enum JumpType
{
	// unprintable jumptypes. only for tracking
	JUMPTYPE_NONE,
	
	JUMPTYPE_LJ,  // longjump
	JUMPTYPE_WJ,  // weirdjump
	JUMPTYPE_LAJ, // ladderjump
	JUMPTYPE_BH,  // bunnyhop
	JUMPTYPE_CBH, // crouched bunnyhop
};

enum JumpDir
{
	JUMPDIR_FORWARDS,
	JUMPDIR_BACKWARDS,
	JUMPDIR_LEFT,
	JUMPDIR_RIGHT,
};

enum StrafeType
{
	STRAFETYPE_OVERLAP,         // IN_MOVELEFT and IN_MOVERIGHT are overlapping and sidespeed is 0
	STRAFETYPE_NONE,            // IN_MOVELEFT and IN_MOVERIGHT are both not pressed and sidespeed is 0
	
	STRAFETYPE_LEFT,            // only IN_MOVELEFT is down and sidespeed isn't 0.
	STRAFETYPE_OVERLAP_LEFT,    // IN_MOVELEFT and IN_MOVERIGHT are overlapping, but sidespeed is smaller than 0 (not 0)
	STRAFETYPE_NONE_LEFT,       // IN_MOVELEFT and IN_MOVERIGHT are both not pressed and sidespeed is smaller than 0 (not 0)
	
	STRAFETYPE_RIGHT,           // only IN_MOVERIGHT is down and sidespeed isn't 0.
	STRAFETYPE_OVERLAP_RIGHT,   // IN_MOVELEFT and IN_MOVERIGHT are overlapping, but sidespeed is bigger than 0 (not 0)
	STRAFETYPE_NONE_RIGHT,      // IN_MOVELEFT and IN_MOVERIGHT are both not pressed and sidespeed is bigger than 0 (not 0)
};

enum JumpBeamColour
{
	JUMPBEAM_NEUTRAL, // speed stays the same
	JUMPBEAM_LOSS,    // speed loss
	JUMPBEAM_GAIN,    // speed gain
	JUMPBEAM_DUCK,    // duck key down
};

enum struct PlayerData
{
	int tickCount;
	int buttons;
	int lastButtons;
	int flags;
	int lastFlags;
	int framesOnGround;
	int framesInAir;
	MoveType movetype;
	MoveType lastMovetype;
	float stamina;
	float lastStamina;
	float forwardmove;
	float lastForwardmove;
	float sidemove;
	float lastSidemove;
	float gravity;
	float angles[3];
	float lastAngles[3];
	float position[3];
	float lastPosition[3];
	float velocity[3];
	float lastVelocity[3];
	float lastGroundPos[3]; // last position where the player left the ground.
	float ladderNormal[3];
	bool lastGroundPosWalkedOff;
	bool landedDucked;
	
	int prespeedFog;
	float prespeedStamina;
	
	float jumpGroundZ;
	float jumpPos[3];
	float jumpAngles[3];
	float landGroundZ;
	float landPos[3];
	
	int fwdReleaseFrame;
	int jumpFrame;
	bool trackingJump;
	bool failedJump;
	bool jumpGotFailstats;
	
	// jump data
	JumpType jumpType;
	JumpType lastJumpType;
	JumpDir jumpDir;
	float jumpDistance;
	float jumpPrespeed;
	float jumpMaxspeed;
	float jumpVeer;
	float jumpAirpath;
	float jumpSync;
	float jumpEdge;
	float jumpLandEdge;
	float jumpBlockDist;
	float jumpHeight;
	float jumpJumpoffAngle;
	int jumpAirtime;
	int jumpFwdRelease;
	int jumpOverlap;
	int jumpDeadair;
	
	// strafes!
	int strafeCount;
	float strafeSync[MAX_STRAFES];
	float strafeGain[MAX_STRAFES];
	float strafeLoss[MAX_STRAFES];
	float strafeMax[MAX_STRAFES];
	int strafeAirtime[MAX_STRAFES];
	int strafeOverlap[MAX_STRAFES];
	int strafeDeadair[MAX_STRAFES];
	float strafeAvgGain[MAX_STRAFES];
	
	float strafeAvgEfficiency[MAX_STRAFES];
	int strafeAvgEfficiencyCount[MAX_STRAFES]; // how many samples are in strafeAvgEfficiency
	float strafeMaxEfficiency[MAX_STRAFES];
	
	StrafeType strafeGraph[MAX_JUMP_FRAMES];
	float mouseGraph[MAX_JUMP_FRAMES];
	float jumpBeamX[MAX_JUMP_FRAMES];
	float jumpBeamY[MAX_JUMP_FRAMES];
	JumpBeamColour jumpBeamColour[MAX_JUMP_FRAMES];
}

/**
 * Check if player is overlapping their MOVERIGHT and MOVELEFT buttons.
 *
 * @param x					Buttons;
 * @return 					True if overlapping, false otherwise.
 */
stock bool IsOverlapping(int buttons, JumpDir jumpDir)
{
	if (jumpDir == JUMPDIR_FORWARDS || jumpDir == JUMPDIR_BACKWARDS)
	{
		return (buttons & IN_MOVERIGHT) && (buttons & IN_MOVELEFT);
	}
	// else if (jumpDir == JUMPDIR_LEFT || jumpDir == JUMPDIR_RIGHT)
	return (buttons & IN_FORWARD) && (buttons & IN_BACK);
}

/**
 * Checks if the player is not holding down their MOVERIGHT and MOVELEFT buttons.
 *
 * @param x					Buttons.
 * @return 					True if they're not holding either, false otherwise.
 */
stock bool IsDeadAirtime(int buttons, JumpDir jumpDir)
{
	if (jumpDir == JUMPDIR_FORWARDS || jumpDir == JUMPDIR_BACKWARDS)
	{
		return (!(buttons & IN_MOVERIGHT) && !(buttons & IN_MOVELEFT));
	}
	// else if (jumpDir == JUMPDIR_LEFT || jumpDir == JUMPDIR_RIGHT)
	return (!(buttons & IN_FORWARD) && !(buttons & IN_BACK));
}

stock void ToggleCVar(ConVar cvar)
{
	cvar.BoolValue = !cvar.BoolValue;
}

stock void GetRealLandingOrigin(float landGroundZ, const float origin[3], const float velocity[3], float result[3])
{
	if ((origin[2] - landGroundZ) == 0.0)
	{
		result = origin;
		return;
	}
	
	// this is like this because it works
	float frametime = GetTickInterval();
	float verticalDistance = origin[2] - (origin[2] + velocity[2] * frametime);
	float fraction = (origin[2] - landGroundZ) / verticalDistance;
	
	float addDistance[3];
	addDistance = velocity;
	ScaleVector(addDistance, frametime * fraction);
	
	AddVectors(origin, addDistance, result);
}

stock int FloatSign(float value)
{
	if (value > 0.0)
	{
		return 1;
	}
	else if (value < 0.0)
	{
		return -1;
	}
	return 0;
}

stock int FloatSign2(float value)
{
	if (value >= 0.0)
	{
		return 1;
	}
	// else if (value < 0.0)
	return -1;
}

stock void ShowPanel(int client, int duration, const char[] message)
{
	Event show_survival_respawn_status = CreateEvent("show_survival_respawn_status");
	if (show_survival_respawn_status == INVALID_HANDLE)
	{
		return;
	}
	
	show_survival_respawn_status.SetString("loc_token", message);
	show_survival_respawn_status.SetInt("duration", duration);
	show_survival_respawn_status.SetInt("userid", -1);
	
	if (client == -1)
	{
		show_survival_respawn_status.Fire();
	}
	else
	{
		show_survival_respawn_status.FireToClient(client);
		show_survival_respawn_status.Cancel();
	}
}