From: Rudolf Polzer Date: Sun, 5 Feb 2023 13:47:17 +0000 (-0500) Subject: Skip division by zero in snapback anticheat. X-Git-Tag: xonotic-v0.8.6~178 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=19568c59ebe46e31b1af8f4857cbef0c117c1639;p=xonotic%2Fxonotic-data.pk3dir.git Skip division by zero in snapback anticheat. --- diff --git a/qcsrc/server/anticheat.qc b/qcsrc/server/anticheat.qc index 622f74c83..a818df3eb 100644 --- a/qcsrc/server/anticheat.qc +++ b/qcsrc/server/anticheat.qc @@ -117,9 +117,12 @@ void anticheat_physics(entity this) float f = bound(0, dt * 4, 1); // About 0.25 seconds horizon for snapping back. vector aim_move = v_forward - CS(this).anticheat_div0_strafebot_forward_prev; vector snapback_prev = CS(this).anticheat_div0_snapback_prev; - float aim_snap = max(0, (aim_move * snapback_prev) / -vlen(snapback_prev)); - // Scales with aim_move, but is positive only when snapping back, otherwise zero. - MEAN_ACCUMULATE(CS(this), anticheat_div0_snapback, aim_snap, dt); + float snapback_len = vlen(snapback_prev); + if (snapback_len != 0) { + float aim_snap = max(0, (aim_move * snapback_prev) / -snapback_len); + // Scales with aim_move, but is positive only when snapping back, otherwise zero. + MEAN_ACCUMULATE(CS(this), anticheat_div0_snapback, aim_snap, dt); + } CS(this).anticheat_div0_snapback_prev = snapback_prev * (1 - f) + aim_move * f; } }