• Hello
Search Results for

    Show / Hide Table of Contents

    06 - Protecting against auto clickers (Pro)

    Goal: You will learn how to stop tools that press a button faster than a person can, and still let honest players click as fast as your game allows.

    This guide needs the Pro version.

    The problem

    An auto clicker is a tool that presses a button for the player. A macro or a script can do the same. They press hundreds of times a second. A person cannot.

    That is an unfair advantage when each press gives something:

    • Clicker games give resources per click.
    • A pistol fires as fast as a machine gun.
    • Rhythm games give points for spam, not for timing.
    • Menus and crafting repeat faster than you planned.

    A normal player clicks about 6 to 8 times a second. A trained player can go higher for a moment. An auto clicker stays at 30, 100, or more.

    Image 1: A player clicking at a human rate.

    Image 2: An auto clicker on the gamepad of player 2. The cheat is found, and the button is limited.

    The solution

    Three parts work together:

    • ProtectedInput is what you call in your gameplay code. It lets each button through only so often.
    • The Input Monitor counts the presses of each button on each device.
    • The Input Cheating Detector reports a button that is pressed far too fast. It also holds the allowed rate.

    Two numbers on the detector decide what happens:

    Setting Default Meaning
    Max Presses Per Second 10 How often ProtectedInput lets a button fire. Extra presses wait their turn
    Cheating Presses Per Second 30 How fast a button must be pressed before it is reported as a cheat

    Keep a gap between the two. 10 is fast but fair. 30 is faster than a person can keep up.

    Step 1: Turn the Input System on

    ProtectedInput, the monitor, and the detector need Unity's Input System package. The old Input Manager alone is not enough.

    1. Install com.unity.inputsystem, version 1.1 or newer, in the Package Manager.
    2. Open Edit > Project Settings > Player. Set Active Input Handling to Input System Package (New) or Both.
    Important

    If only the old Input Manager is active, the input protection is not compiled. ProtectedInput is then not found in your code.

    Step 2: Make sure the detector is there

    The predefined Anti-Cheat-Monitor prefab already includes the Input Cheating Detector and its Input Monitor. If you use it, you have nothing to do here.

    If you use your own monitor prefab, add the Input Cheating Detector prefab to it. It holds the detector and the monitor together. Drag it onto the monitor in your prefab so it becomes a child.

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

    Note

    The monitor and the detector must be on the same GameObject. The prefab already sets this up.

    Without the detector, ProtectedInput still limits each button to 10 presses a second. But nothing is reported.

    Step 3: Set the limits

    Select the Input Cheating Detector. The Inspector shows these settings:

    Image 4: The Input Cheating Detector in the Inspector.

    Setting Default What it does
    Is Active On Turns the detector on or off
    Possibility Of False Positive 0.3 How likely a find is a false alarm. Very fast honest clicking can reach a high rate for a moment
    Threat Rating 75 How much one find adds to the threat score of the Anti-Cheat Monitor
    Max Presses Per Second 10 The rate your game allows
    Cheating Presses Per Second 30 The rate that counts as a cheat
    Rate Mode Peak Peak reacts to a short burst. Average waits for a high rate over the whole window
    Report Interval 5 How many seconds pass before the same button is reported again while it stays too fast
    On Cheating Detection Event Empty Your own reactions. Assign a method here

    The Input Monitor has one setting. Window Seconds is how long presses are remembered. The default is 5.

    Image 5: The Input Monitor in the Inspector.

    You can also change the limits while the game runs, for example per weapon:

    var detector = AntiCheatMonitor.Instance.GetDetector<InputCheatingDetector>();
    
    detector.MaxPressesPerSecond = 8;
    detector.CheatingPressesPerSecond = 25;
    

    Step 4: Use ProtectedInput

    Protect the presses that give an advantage: shots, clicks that add score, buy, craft, open. You do not need it for walking, or for a button that is only held down.

    A mouse click before:

    using UnityEngine.InputSystem;
    
    if (Mouse.current.leftButton.wasPressedThisFrame)
    {
        this.Shoot();
    }
    

    And after:

    using GUPS.AntiCheat.Protected.Input;
    using UnityEngine.InputSystem.LowLevel;
    
    if (ProtectedInput.GetMouseButtonDown(MouseButton.Left))
    {
        this.Shoot();
    }
    

    The gamepad of a second player. Each controller has its own limit:

    if (ProtectedInput.GetGamepadButtonDown(GamepadButton.South, playerTwoGamepad))
    {
        playerTwo.Shoot();
    }
    

    An input action:

    if (ProtectedInput.WasPressedThisFrame(this.fireAction))
    {
        this.Shoot();
    }
    

    Keys and touch work the same way. The full list is on the Protected Input page.

    Note

    A press that comes too early is kept, not thrown away. It fires as soon as the short wait is over. A person who clicks a little too fast loses nothing. An auto clicker at 100 clicks a second still gets only 10 shots.

    Step 5: React to a find

    Assign a method to On Cheating Detection Event on the detector. You need no code for that.

    In code, you can ignore a button that was already found cheating:

    using GUPS.AntiCheat.Core.Input;
    using GUPS.AntiCheat.Protected.Input;
    using UnityEngine.InputSystem;
    using UnityEngine.InputSystem.LowLevel;
    
    InputId leftButton = InputId.MouseButton(MouseButton.Left, Mouse.current);
    
    if (ProtectedInput.GetMouseButtonDown(MouseButton.Left)
        && !ProtectedInput.IsFlaggedAsCheating(leftButton))
    {
        this.AddCoin();
    }
    

    You can also ask the detector if it found anything:

    var detector = AntiCheatMonitor.Instance.GetDetector<InputCheatingDetector>();
    
    if (detector != null && detector.PossibleCheatingDetected)
    {
        // A button was pressed faster than a person can.
    }
    

    Step 6: Try it

    Open the demo scene Assets/GUPS/AntiCheat/Demos/Demo_AutoClick/Scene.unity. Two players shoot at targets. Player 1 uses the mouse or space. Player 2 uses a gamepad. Run an auto clicker on one of them, once without and once with Anti-Cheat. The demo folder has its own ReadMe.

    The result

    With ProtectedInput in your gameplay code and the Input Cheating Detector running:

    • An auto clicker at 100 clicks a second gets 10 actions a second. That is the same as a fast honest player.
    • The detector reports that button. The threat score rises while the tool keeps running.
    • A normal player does not notice the limit.
    • In local multiplayer, the macro of one player does not slow the other player.
    Note

    The predefined monitor prefab has no punisher. A find raises the threat score, but nothing more happens to the player until you react yourself or add a punisher.

    Settings reference: Protected Input, Input monitor, and Input detector.

    Next steps

    • Reacting to detected cheating shows how to run your own logic when an auto clicker is found.
    • Punishing cheaters shows how to react automatically.

    Next guide: 07 - Protecting an Android build (Pro).

    Back to the Guides overview.

    In This Article
    Back to top GuardingPearSoftware documentation