• Hello
Search Results for

    Show / Hide Table of Contents

    Universal - Input - Detector (Pro)

    Auto clickers and macros are tools that press a button faster than a person can. That matters in clicker games, rhythm games, weapons, and fast menus. This detector reports a button that is pressed too fast.

    This detector needs the Pro version.

    Walkthrough: Protecting against auto clickers.

    What it does

    InputCheatingDetector (namespace GUPS.AntiCheat.Detector.Input) listens to the InputMonitor. The monitor counts the presses of every button on every device. The detector works with two numbers:

    • The cheat line (30 presses per second by default). A button at or above this rate is reported as an auto clicker.
    • The allowed rate (10 presses per second by default). ProtectedInput uses it to limit how often a button counts as pressed. The detector only stores this number. It does not report on it.

    Each button is counted on its own device. Two players on two gamepads do not add up to one rate.

    Do you need to add it?

    No, if you use the predefined Anti-Cheat-Monitor prefab. It already includes this detector and its monitor.

    If you use your own monitor prefab, drag the Input Cheating Detector prefab onto the monitor so it becomes a child. The prefab holds the detector and the monitor together.

    The detector prefabs in Assets/GUPS/AntiCheat/Resources/Prefabs/Detectors.

    Note

    The InputMonitor must be on the same GameObject as the detector. Without it, the detector logs a warning and does nothing.

    Settings

    The InputCheatingDetector settings.

    • Is Active (isActive, bool, default true): Turns the detector on or off.
    • Possibility Of False Positive (possibilityOfFalsePositive, 0 to 1, default 0.3): How likely a find is a false alarm. Some real clicking styles reach high rates for a moment.
    • Threat Rating (threatRating, default 75): How much one find adds to the threat score. A button that stays too fast is reported again every Report Interval, so a running tool adds up.
    • Max Presses Per Second (maxPressesPerSecond, at least 1, default 10): The allowed rate for ProtectedInput. At 10, a button counts at most once every 100 ms.
    • Cheating Presses Per Second (cheatingPressesPerSecond, at least 1, default 30): The cheat line. People rarely press faster than 10 to 15 times a second.
    • Rate Mode (rateMode, default Peak): How the rate is measured. Peak is the busiest second and reacts within a second. Average needs a rate that stays high and causes fewer false alarms.
    • Report Interval (reportInterval, seconds, 0 to 60, default 5): The shortest wait between two finds for the same button.
    • On Cheating Detection Event (OnCheatingDetectionEvent): Methods to call on every find.

    Use ProtectedInput

    Read "pressed this frame" through ProtectedInput. Each button is then limited to Max Presses Per Second, so clicking faster gains nothing.

    using GUPS.AntiCheat.Protected.Input;
    using UnityEngine;
    using UnityEngine.InputSystem.LowLevel;
    
    public class Weapon : MonoBehaviour
    {
        private void Update()
        {
            // Fires at most 10 times per second, no matter how fast the mouse is clicked.
            if (ProtectedInput.GetMouseButtonDown(MouseButton.Left))
            {
                this.Shoot();
            }
        }
    }
    

    What it reports

    On a find, the detector sends an InputCheatingDetectionStatus:

    public struct InputCheatingDetectionStatus : IInputCheatingDetectionStatus
    {
        // The kind of cheat. Always ECheatType.Input.
        public ECheatType CheatType { get; }
    
        // How likely this find is a false alarm, from 0 to 1.
        public float PossibilityOfFalsePositive { get; }
    
        // How much this find adds to the threat score.
        public uint ThreatRating { get; }
    
        // The button that was too fast, with its device.
        public InputId Input { get; }
    
        // The measured presses per second.
        public float PressesPerSecond { get; }
    
        // The cheat line that was set.
        public uint CheatingPressesPerSecond { get; }
    
        // The allowed rate that was set.
        public uint MaxPressesPerSecond { get; }
    
        // How the rate was measured: Peak or Average.
        public EInputRateMode RateMode { get; }
    }
    

    You can also ask if one button is flagged right now. Pass the device, because flags are per device.

    using GUPS.AntiCheat;
    using GUPS.AntiCheat.Core.Input;
    using GUPS.AntiCheat.Detector.Input;
    using UnityEngine.InputSystem;
    using UnityEngine.InputSystem.LowLevel;
    
    var detector = AntiCheatMonitor.Instance.GetDetector<InputCheatingDetector>();
    
    if (detector != null && detector.IsFlagged(InputId.MouseButton(MouseButton.Left, Mouse.current)))
    {
        // The left button of the current mouse is driven by an auto clicker.
    }
    

    Good to know

    • The flag stays. PossibleCheatingDetected stays true after the first find.
    • A button's own flag clears. IsFlagged turns false again when that button slows down. FlaggedInputCount tells you how many buttons are flagged right now.
    • Finds are spaced. A running auto clicker is reported once per Report Interval, not every frame. Each find is also written to the console as a warning.
    • Works without the detector, but weaker. ProtectedInput still limits each button to 10 presses a second. No cheat is reported then.

    Platforms and requirements

    Every platform.

    • An InputMonitor on the same GameObject.
    • The Input System package (com.unity.inputsystem, version 1.1 or newer). In Edit > Project Settings > Player, set Active Input Handling to Input System Package (New) or Both. Without that, this code is not compiled.

    React to a find

    Every find is added to the threat score of the Anti-Cheat Monitor. The predefined monitor prefab has no punisher. So nothing more happens to the player until you react yourself or add a punisher.

    In the Inspector. Add a method to On Cheating Detection Event. It runs on every find.

    Inspector callbacks on a detector.

    In code. Listen, so your code runs at the moment of the find. Subscribe returns an IDisposable. Dispose it when you want to stop.

    using System;
    using GUPS.AntiCheat;
    using GUPS.AntiCheat.Core.Detector;
    using GUPS.AntiCheat.Detector.Input;
    using UnityEngine;
    
    public class InputDetectionLogger : MonoBehaviour, IObserver<IDetectorStatus>
    {
        private void Start()
        {
            var detector = AntiCheatMonitor.Instance.GetDetector<InputCheatingDetector>();
            detector.Subscribe(this);
        }
    
        public void OnNext(IDetectorStatus status)
        {
            if (status is IInputCheatingDetectionStatus input)
            {
                // For example: "Auto clicker on Gamepad/South#17: 64 presses/s". '#17' is the device id.
                Debug.LogWarning($"Auto clicker on {input.Input}: {input.PressesPerSecond:0.#} presses/s");
            }
        }
    
        public void OnError(Exception error) { }
        public void OnCompleted() { }
    }
    

    Back to the Detector overview.

    In This Article
    Back to top GuardingPearSoftware documentation