]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Skip division by zero in snapback anticheat.
authorRudolf Polzer <divVerent@gmail.com>
Sun, 5 Feb 2023 13:47:17 +0000 (08:47 -0500)
committerRudolf Polzer <divVerent@gmail.com>
Sun, 5 Feb 2023 13:47:17 +0000 (08:47 -0500)
qcsrc/server/anticheat.qc

index 622f74c83f9ccfdebce90f68a2774df64751b3f5..a818df3eb6ec8e2b45eff3e12fd12a4e7c49b790 100644 (file)
@@ -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;
                }
        }