Xonotic
anticheat.qh File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void anticheat_endframe ()
 
void anticheat_fixangle (entity this)
 
void anticheat_init (entity this)
 
void anticheat_physics (entity this)
 
void anticheat_prethink (entity this)
 
void anticheat_register_to_playerstats ()
 
void anticheat_report_to_eventlog (entity this)
 
void anticheat_report_to_playerstats (entity this)
 
void anticheat_spectatecopy (entity this, entity spectatee)
 
void anticheat_startframe ()
 

Function Documentation

◆ anticheat_endframe()

void anticheat_endframe ( )

Definition at line 234 of file anticheat.qc.

References anticheat_div0_evade_evasion_delta, anticheat_fixangle(), FOREACH_CLIENT, frametime, and random().

Referenced by EndFrame().

235 {
236  FOREACH_CLIENT(it.fixangle, anticheat_fixangle(it));
238 }
#define FOREACH_CLIENT(cond, body)
Definition: utils.qh:49
float anticheat_div0_evade_evasion_delta
Definition: anticheat.qc:17
void anticheat_fixangle(entity this)
Definition: anticheat.qc:229
float frametime
Definition: csprogsdefs.qc:17
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ anticheat_fixangle()

void anticheat_fixangle ( entity  this)

Definition at line 229 of file anticheat.qc.

References ANTILAG_LATENCY, CS(), and servertime.

Referenced by anticheat_endframe(), and WarpZone_PostTeleportPlayer_Callback().

230 {
231  CS(this).anticheat_fixangle_endtime = servertime + ANTILAG_LATENCY(this) + 0.2;
232 }
ClientState CS(Client this)
Definition: state.qh:47
#define ANTILAG_LATENCY(e)
Definition: antilag.qh:19
float servertime
Definition: main.qh:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ anticheat_init()

void anticheat_init ( entity  this)

Definition at line 240 of file anticheat.qc.

References CS(), and servertime.

241 {
242  CS(this).anticheat_speedhack_offset = 0;
243  CS(this).anticheat_jointime = servertime;
244 }
ClientState CS(Client this)
Definition: state.qh:47
float servertime
Definition: main.qh:36
+ Here is the call graph for this function:

◆ anticheat_physics()

void anticheat_physics ( entity  this)

Definition at line 64 of file anticheat.qc.

References anticheat_div0_evade_evasion_delta, anticheat_div0_evade_forward_initial, anticheat_div0_evade_offset, anticheat_div0_strafebot_forward_prev, anticheat_div0_strafebot_movement_prev, anticheat_fixangle_endtime, anticheat_speedhack_accu, anticheat_speedhack_movetime_frac, anticheat_speedhack_offset, autocvar_slowmo, CS(), exp(), fabs(), falloff, floor(), frametime, M_PI, makevectors, max(), MEAN_ACCUMULATE, movement, movement_oddity(), servertime, sys_frametime, time, v_angle, and v_forward.

Referenced by sys_phys_monitor().

65 {
66  float f;
67 
68  // div0_evade -> SPECTATORS
69  makevectors(this.v_angle);
70  if(CS(this).anticheat_div0_evade_offset == 0)
71  {
73  CS(this).anticheat_div0_evade_offset = servertime + sys_frametime * (3 * f - 1);
74  CS(this).anticheat_div0_evade_v_angle = this.v_angle;
75  CS(this).anticheat_div0_evade_forward_initial = v_forward;
76  MEAN_ACCUMULATE(CS(this), anticheat_div0_evade, 0, 1);
77  }
78  else
79  {
81  CS(this).anticheat_div0_evade_v_angle = this.v_angle;
82  MEAN_ACCUMULATE(CS(this), anticheat_div0_evade, 0.5 - 0.5 * (CS(this).anticheat_div0_evade_forward_initial * v_forward), 1);
83  }
84 
85  MEAN_ACCUMULATE(CS(this), anticheat_div0_strafebot_old, movement_oddity(CS(this).movement, CS(this).anticheat_div0_strafebot_movement_prev), 1);
86  CS(this).anticheat_div0_strafebot_movement_prev = CS(this).movement;
87 
88  // Note: this actually tries to detect snap-aim.
90  float cosangle = CS(this).anticheat_div0_strafebot_forward_prev * v_forward;
91  float angle = cosangle < -1 ? M_PI : cosangle > 1 ? 0 : acos(cosangle);
92  /*
93  if (angle >= 10 * M_PI / 180)
94  printf("SNAP %s: %f for %f, %f since fixangle\n", this.netname, angle * 180 / M_PI, cosangle, time - CS(this).anticheat_fixangle_endtime);
95  */
96  MEAN_ACCUMULATE(CS(this), anticheat_div0_strafebot_new, angle / M_PI, 1);
97 
98  if (autocvar_slowmo > 0) {
99  // Technically this is a NOP, as the engine should be ensuring
100  // this in the first place. Let's guard against dividing by
101  // zero anyway.
102  float dt = max(0.001, frametime) / autocvar_slowmo;
103 
104  float anglespeed = angle / dt;
105  MEAN_ACCUMULATE(CS(this), anticheat_idle_snapaim_signal, anglespeed, dt);
106  MEAN_ACCUMULATE(CS(this), anticheat_idle_snapaim_noise, anglespeed, dt);
107  MEAN_ACCUMULATE(CS(this), anticheat_idle_snapaim_m2, anglespeed, dt);
108  MEAN_ACCUMULATE(CS(this), anticheat_idle_snapaim_m3, anglespeed, dt);
109  MEAN_ACCUMULATE(CS(this), anticheat_idle_snapaim_m4, anglespeed, dt);
110  MEAN_ACCUMULATE(CS(this), anticheat_idle_snapaim_m7, anglespeed, dt);
111  MEAN_ACCUMULATE(CS(this), anticheat_idle_snapaim_m10, anglespeed, dt);
112  }
113  }
114  CS(this).anticheat_div0_strafebot_forward_prev = v_forward;
115 
116  // generic speedhack detection: correlate anticheat_speedhack_movetime (UPDATED BEFORE THIS) and server time
117  CS(this).anticheat_speedhack_movetime_frac += frametime;
119  CS(this).anticheat_speedhack_movetime_frac -= f;
120  CS(this).anticheat_speedhack_movetime_count += f;
121  CS(this).anticheat_speedhack_movetime = CS(this).anticheat_speedhack_movetime_frac + CS(this).anticheat_speedhack_movetime_count;
122  f = CS(this).anticheat_speedhack_movetime - servertime;
123  if(CS(this).anticheat_speedhack_offset == 0)
124  CS(this).anticheat_speedhack_offset = f;
125  else
126  {
127  MEAN_ACCUMULATE(CS(this), anticheat_speedhack, max(0, f - CS(this).anticheat_speedhack_offset), 1);
128  CS(this).anticheat_speedhack_offset += (f - CS(this).anticheat_speedhack_offset) * frametime * 0.1;
129  }
130 
131  // new generic speedhack detection
132  if (CS(this).anticheat_speedhack_lasttime > 0) {
133  float dt = servertime - CS(this).anticheat_speedhack_lasttime;
134  const float falloff = 0.2;
135  CS(this).anticheat_speedhack_accu *= exp(-dt * falloff);
136  CS(this).anticheat_speedhack_accu += frametime * falloff;
137  // NOTE: at cl_netfps x, this actually averages not to 1, but to 1/x * falloff / (1 - exp(-1/x * falloff))
138  // For 15 netfps (absolute minimum bearable), and 0.2 falloff, this is: 1.0067
139  CS(this).anticheat_speedhack_lasttime = servertime;
140  MEAN_ACCUMULATE(CS(this), anticheat_speedhack_m1, CS(this).anticheat_speedhack_accu, frametime);
141  MEAN_ACCUMULATE(CS(this), anticheat_speedhack_m2, CS(this).anticheat_speedhack_accu, frametime);
142  MEAN_ACCUMULATE(CS(this), anticheat_speedhack_m3, CS(this).anticheat_speedhack_accu, frametime);
143  MEAN_ACCUMULATE(CS(this), anticheat_speedhack_m4, CS(this).anticheat_speedhack_accu, frametime);
144  MEAN_ACCUMULATE(CS(this), anticheat_speedhack_m5, CS(this).anticheat_speedhack_accu, frametime);
145  } else {
146  CS(this).anticheat_speedhack_accu = 1;
147  CS(this).anticheat_speedhack_lasttime = servertime;
148  }
149 }
vector anticheat_div0_strafebot_forward_prev
Definition: anticheat.qc:26
float anticheat_speedhack_offset
Definition: anticheat.qc:43
int falloff
Definition: impulse.qh:12
#define MEAN_ACCUMULATE(s, prefix, v, w)
Definition: math.qh:22
float anticheat_speedhack_movetime_frac
Definition: anticheat.qc:44
float anticheat_div0_evade_offset
Definition: anticheat.qc:18
ClientState CS(Client this)
Definition: state.qh:47
vector v_angle
Definition: progsdefs.qc:161
float movement_oddity(vector m0, vector m1)
Definition: anticheat.qc:55
float exp(float e)
Definition: mathlib.qc:73
float sys_frametime
Definition: common.qh:57
float anticheat_div0_evade_evasion_delta
Definition: anticheat.qc:17
float frametime
Definition: csprogsdefs.qc:17
vector movement
const float M_PI
Definition: csprogsdefs.qc:269
float anticheat_speedhack_accu
Definition: anticheat.qc:47
vector anticheat_div0_strafebot_movement_prev
Definition: anticheat.qc:23
#define autocvar_slowmo
Definition: main.qh:16
vector anticheat_div0_evade_forward_initial
Definition: anticheat.qc:20
float anticheat_fixangle_endtime
Definition: anticheat.qc:15
float servertime
Definition: main.qh:36
float time
Definition: csprogsdefs.qc:16
#define makevectors
Definition: post.qh:21
vector v_forward
Definition: csprogsdefs.qc:31
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ anticheat_prethink()

void anticheat_prethink ( entity  this)

Definition at line 157 of file anticheat.qc.

References CS().

Referenced by PlayerPreThink().

158 {
159  // div0_evade -> SPECTATORS
160  CS(this).anticheat_div0_evade_offset = 0;
161 }
ClientState CS(Client this)
Definition: state.qh:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ anticheat_register_to_playerstats()

void anticheat_register_to_playerstats ( )

Definition at line 214 of file anticheat.qc.

References ANTICHEAT_REGISTER_ONE, ANTICHEATS, and strcat().

214  {
215  PlayerStats_GameReport_AddEvent(strcat(PLAYERSTATS_ANTICHEAT, "_time"));
216 #define ANTICHEAT_REGISTER_ONE(name, unused_f, unused_tmin, unused_mi, unused_ma) \
217  PlayerStats_GameReport_AddEvent(strcat(PLAYERSTATS_ANTICHEAT, name))
219 #undef ANTICHEAT_REGISTER_ONE
220 }
#define ANTICHEAT_REGISTER_ONE(name, unused_f, unused_tmin, unused_mi, unused_ma)
#define ANTICHEATS(ANTICHEAT)
Definition: anticheat.qc:176
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
+ Here is the call graph for this function:

◆ anticheat_report_to_eventlog()

void anticheat_report_to_eventlog ( entity  this)

Definition at line 195 of file anticheat.qc.

References anticheat_jointime, ANTICHEAT_REPORT_ONE, ANTICHEATS, autocvar_sv_eventlog, CS(), ftos(), GameLogEcho(), playerid, servertime, and strcat().

195  {
197  return;
198  GameLogEcho(strcat(":anticheat:_time:", ftos(this.playerid), ":", ftos(servertime - CS(this).anticheat_jointime)));
199 #define ANTICHEAT_REPORT_ONE(name, f, tmin, mi, ma) \
200  GameLogEcho(strcat(":anticheat:", name, ":", anticheat_display(f, servertime - CS(this).anticheat_jointime, tmin, mi, ma)))
202 #undef ANTICHEAT_REPORT_ONE
203 }
#define ANTICHEATS(ANTICHEAT)
Definition: anticheat.qc:176
int playerid
Definition: client.qh:78
ClientState CS(Client this)
Definition: state.qh:47
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
void GameLogEcho(string s)
Definition: gamelog.qc:12
#define ANTICHEAT_REPORT_ONE(name, f, tmin, mi, ma)
float servertime
Definition: main.qh:36
bool autocvar_sv_eventlog
Definition: gamelog.qh:3
float anticheat_jointime
Definition: anticheat.qc:13
+ Here is the call graph for this function:

◆ anticheat_report_to_playerstats()

void anticheat_report_to_playerstats ( entity  this)

Definition at line 205 of file anticheat.qc.

References anticheat_jointime, ANTICHEAT_REPORT_ONE, ANTICHEATS, CS(), servertime, and strcat().

205  {
206  PlayerStats_GameReport_Event_Player(this,
207  strcat(PLAYERSTATS_ANTICHEAT, "_time"), servertime - CS(this).anticheat_jointime);
208 #define ANTICHEAT_REPORT_ONE(name, f, tmin, mi, ma) \
209  PlayerStats_GameReport_Event_Player(this, strcat(PLAYERSTATS_ANTICHEAT, name), f)
211 #undef ANTICHEAT_REPORT_ONE
212 }
#define ANTICHEATS(ANTICHEAT)
Definition: anticheat.qc:176
ClientState CS(Client this)
Definition: state.qh:47
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define ANTICHEAT_REPORT_ONE(name, f, tmin, mi, ma)
float servertime
Definition: main.qh:36
float anticheat_jointime
Definition: anticheat.qc:13
+ Here is the call graph for this function:

◆ anticheat_spectatecopy()

void anticheat_spectatecopy ( entity  this,
entity  spectatee 
)

Definition at line 151 of file anticheat.qc.

References angles, and CS().

Referenced by SpectateCopy().

152 {
153  // div0_evade -> SPECTATORS
154  this.angles = CS(spectatee).anticheat_div0_evade_v_angle;
155 }
ClientState CS(Client this)
Definition: state.qh:47
vector angles
Definition: csprogsdefs.qc:104
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ anticheat_startframe()

void anticheat_startframe ( )

Definition at line 224 of file anticheat.qc.

References anticheat_div0_evade_evasion_delta, frametime, and random().

Referenced by StartFrame().

225 {
227 }
float anticheat_div0_evade_evasion_delta
Definition: anticheat.qc:17
float frametime
Definition: csprogsdefs.qc:17
+ Here is the call graph for this function:
+ Here is the caller graph for this function: