summaryrefslogtreecommitdiff
path: root/sourcemod/scripting/gokz-anticheat/api.sp
blob: 7f997249eb34a1b35ca3af17ef66abb7892e8bd0 (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
static GlobalForward H_OnPlayerSuspected;



// =====[ FORWARDS ]=====

void CreateGlobalForwards()
{
	H_OnPlayerSuspected = new GlobalForward("GOKZ_AC_OnPlayerSuspected", ET_Ignore, Param_Cell, Param_Cell, Param_String, Param_String);
}

void Call_OnPlayerSuspected(int client, ACReason reason, const char[] notes, const char[] stats)
{
	Call_StartForward(H_OnPlayerSuspected);
	Call_PushCell(client);
	Call_PushCell(reason);
	Call_PushString(notes);
	Call_PushString(stats);
	Call_Finish();
}



// =====[ NATIVES ]=====

void CreateNatives()
{
	CreateNative("GOKZ_AC_GetSampleSize", Native_GetSampleSize);
	CreateNative("GOKZ_AC_GetHitPerf", Native_GetHitPerf);
	CreateNative("GOKZ_AC_GetPerfCount", Native_GetPerfCount);
	CreateNative("GOKZ_AC_GetPerfRatio", Native_GetPerfRatio);
	CreateNative("GOKZ_AC_GetJumpInputs", Native_GetJumpInputs);
	CreateNative("GOKZ_AC_GetAverageJumpInputs", Native_GetAverageJumpInputs);
	CreateNative("GOKZ_AC_GetPreJumpInputs", Native_GetPreJumpInputs);
	CreateNative("GOKZ_AC_GetPostJumpInputs", Native_GetPostJumpInputs);
}

public int Native_GetSampleSize(Handle plugin, int numParams)
{
	int client = GetNativeCell(1);
	return IntMin(gI_BhopCount[client], AC_MAX_BHOP_SAMPLES);
}

public int Native_GetHitPerf(Handle plugin, int numParams)
{
	int client = GetNativeCell(1);
	int sampleSize = IntMin(GOKZ_AC_GetSampleSize(client), GetNativeCell(3));

	if (sampleSize == 0)
	{
		return 0;
	}

	bool[] perfs = new bool[sampleSize];
	SortByRecent(gB_BhopHitPerf[client], AC_MAX_BHOP_SAMPLES, perfs, sampleSize, gI_BhopIndex[client]);
	SetNativeArray(2, perfs, sampleSize);
	return sampleSize;
}

public int Native_GetPerfCount(Handle plugin, int numParams)
{
	int client = GetNativeCell(1);
	int sampleSize = IntMin(GOKZ_AC_GetSampleSize(client), GetNativeCell(2));

	if (sampleSize == 0)
	{
		return 0;
	}

	bool[] perfs = new bool[sampleSize];
	GOKZ_AC_GetHitPerf(client, perfs, sampleSize);

	int perfCount = 0;
	for (int i = 0; i < sampleSize; i++)
	{
		if (perfs[i])
		{
			perfCount++;
		}
	}
	return perfCount;
}

public int Native_GetPerfRatio(Handle plugin, int numParams)
{
	int client = GetNativeCell(1);
	int sampleSize = IntMin(GOKZ_AC_GetSampleSize(client), GetNativeCell(2));

	if (sampleSize == 0)
	{
		return view_as<int>(0.0);
	}

	int perfCount = GOKZ_AC_GetPerfCount(client, sampleSize);
	return view_as<int>(float(perfCount) / float(sampleSize));
}

public int Native_GetJumpInputs(Handle plugin, int numParams)
{
	int client = GetNativeCell(1);
	int sampleSize = IntMin(GOKZ_AC_GetSampleSize(client), GetNativeCell(3));

	if (sampleSize == 0)
	{
		return 0;
	}

	int[] preJumpInputs = new int[sampleSize];
	SortByRecent(gI_BhopPreJumpInputs[client], AC_MAX_BHOP_SAMPLES, preJumpInputs, sampleSize, gI_BhopIndex[client]);
	int[] postJumpInputs = new int[sampleSize];
	SortByRecent(gI_BhopPostJumpInputs[client], AC_MAX_BHOP_SAMPLES, postJumpInputs, sampleSize, gI_BhopIndex[client]);

	int[] jumpInputs = new int[sampleSize];
	for (int i = 0; i < sampleSize; i++)
	{
		jumpInputs[i] = preJumpInputs[i] + postJumpInputs[i];
	}

	SetNativeArray(2, jumpInputs, sampleSize);
	return sampleSize;
}

public int Native_GetAverageJumpInputs(Handle plugin, int numParams)
{
	int client = GetNativeCell(1);
	int sampleSize = IntMin(GOKZ_AC_GetSampleSize(client), GetNativeCell(2));

	if (sampleSize == 0)
	{
		return view_as<int>(0.0);
	}

	int[] jumpInputs = new int[sampleSize];
	GOKZ_AC_GetJumpInputs(client, jumpInputs, sampleSize);

	int jumpInputCount = 0;
	for (int i = 0; i < sampleSize; i++)
	{
		jumpInputCount += jumpInputs[i];
	}
	return view_as<int>(float(jumpInputCount) / float(sampleSize));
}

public int Native_GetPreJumpInputs(Handle plugin, int numParams)
{
	int client = GetNativeCell(1);
	int sampleSize = IntMin(GOKZ_AC_GetSampleSize(client), GetNativeCell(3));

	if (sampleSize == 0)
	{
		return 0;
	}

	int[] preJumpInputs = new int[sampleSize];
	SortByRecent(gI_BhopPreJumpInputs[client], AC_MAX_BHOP_SAMPLES, preJumpInputs, sampleSize, gI_BhopIndex[client]);
	SetNativeArray(2, preJumpInputs, sampleSize);
	return sampleSize;
}

public int Native_GetPostJumpInputs(Handle plugin, int numParams)
{
	int client = GetNativeCell(1);
	int sampleSize = IntMin(GOKZ_AC_GetSampleSize(client), GetNativeCell(3));

	if (sampleSize == 0)
	{
		return 0;
	}

	int[] postJumpInputs = new int[sampleSize];
	SortByRecent(gI_BhopPostJumpInputs[client], AC_MAX_BHOP_SAMPLES, postJumpInputs, sampleSize, gI_BhopIndex[client]);
	SetNativeArray(2, postJumpInputs, sampleSize);
	return sampleSize;
}