• Hello
Search Results for

    Show / Hide Table of Contents

    12 - Reacting to detected cheating

    Goal: You will learn how to get told when someone cheats in your game, so you can react and not only protect silently.

    This guide works in the Free and the Pro version. The samples use the Primitive Cheating Detector, which is in both. Most other detectors need Pro.

    The problem

    Protecting your values is only half the job. A detector can find a cheat, and still nothing happens. There is no log, no warning, and no flag on the account.

    That hurts your game. The cheater simply tries again, and you never learn that it happened.

    The solution

    Listen to the detectors. Every detector can tell you about a find in three ways: through an event in the Inspector, through a flag you check, or through an observer in code. An observer is a small class of yours that gets called on each find.

    Step 1: Understand how a find travels

    Three parts work together:

    • Monitors watch the game or the device. They only report what they measure. They do not judge.
    • Detectors decide if a report looks like cheating.
    • The Anti-Cheat Monitor listens to every detector. It adds each find to one threat score. When the score gets high enough, it runs the punishers.

    In short:

    Monitor -> Detector -> Anti-Cheat Monitor -> Punisher or your own reaction
    

    Most of the time you react at the detector. That is what the next steps show.

    Step 2: React with an Inspector event (no code)

    Every detector has an On Cheating Detection Event in the Inspector. You assign a method there, like on a button's OnClick. It runs each time that detector finds a cheat.

    Image 1: The On Cheating Detection Event of a detector in the Inspector.

    Note

    The detectors are part of the monitor prefab, and Anti-Cheat adds that prefab to your game when it starts. Set the event up in your own monitor prefab. The method you assign must be on an object inside that prefab. Getting started shows how to make your own monitor prefab.

    Step 3: Check the flag

    Every detector has a PossibleCheatingDetected property. It starts as false. It turns true when the detector finds a cheat. That is handy as a simple gate, for example before you give a reward:

    using GUPS.AntiCheat;
    using GUPS.AntiCheat.Detector;
    
    var detector = AntiCheatMonitor.Instance.GetDetector<PrimitiveCheatingDetector>();
    
    if (detector != null && detector.PossibleCheatingDetected)
    {
        // A protected value was changed at least once. Do not give the reward.
    }
    

    For most detectors the flag stays true after the first find. The game time and device time detectors turn it off again when the clock looks normal.

    Step 4: Listen to one detector

    To run your own code at the moment of a find, write an observer and subscribe it to the detector. OnNext is called on each find. It gets a status with the ThreatRating and the PossibilityOfFalsePositive of that find.

    using System;
    using GUPS.AntiCheat;
    using GUPS.AntiCheat.Core.Detector;
    using GUPS.AntiCheat.Detector;
    using UnityEngine;
    
    public class CheatingLogger : MonoBehaviour, IObserver<IDetectorStatus>
    {
        private IDisposable subscription;
    
        private void Start()
        {
            var detector = AntiCheatMonitor.Instance.GetDetector<PrimitiveCheatingDetector>();
    
            if (detector != null)
            {
                this.subscription = detector.Subscribe(this);
            }
        }
    
        public void OnNext(IDetectorStatus status)
        {
            Debug.LogWarning($"Cheat detected. Threat: {status.ThreatRating}, false alarm chance: {status.PossibilityOfFalsePositive}");
        }
    
        public void OnError(Exception error) { }
        public void OnCompleted() { }
    
        private void OnDestroy()
        {
            // Stop listening.
            this.subscription?.Dispose();
        }
    }
    

    Subscribe returns an IDisposable. Dispose it when you want to stop listening.

    Step 5: Listen to all detectors at once

    You can also subscribe to the Anti-Cheat Monitor itself. Then you hear every find of every detector. The status has a CheatType that tells you what kind of cheat it was, for example Memory, GameTime, or Jailbreak.

    using System;
    using GUPS.AntiCheat;
    using GUPS.AntiCheat.Detector;
    using UnityEngine;
    
    public class AllCheatsLogger : MonoBehaviour, IObserver<ICheatingDetectionStatus>
    {
        private void Start()
        {
            AntiCheatMonitor.Instance.Subscribe(this);
        }
    
        public void OnNext(ICheatingDetectionStatus status)
        {
            Debug.LogWarning($"Cheat detected: {status.CheatType}. Threat score now: {AntiCheatMonitor.Instance.ThreatLevel}");
        }
    
        public void OnError(Exception error) { }
        public void OnCompleted() { }
    }
    

    This is a good place to send a report to your own server.

    There are two shorter ways to hear every find on the monitor.

    The event on the monitor. The Anti-Cheat Monitor has an On Cheating Detected event. Assign a method in the Inspector of your own monitor prefab, or add a listener in code:

    AntiCheatMonitor.Instance.OnCheatingDetected.AddListener(status =>
    {
        Debug.LogWarning($"Cheat detected: {status.CheatType}");
    });
    

    A method on the monitor object. Add a component to the same GameObject as the Anti-Cheat Monitor and give it a method named OnCheatingDetected. The monitor calls it on every find. You do not have to subscribe.

    using GUPS.AntiCheat.Detector;
    using UnityEngine;
    
    public class CheatReporter : MonoBehaviour
    {
        // Called by the Anti-Cheat Monitor on the same GameObject.
        private void OnCheatingDetected(ICheatingDetectionStatus status)
        {
            Debug.LogWarning($"Cheat detected: {status.CheatType}");
        }
    }
    

    The component must sit on the monitor's own GameObject. A component on a child is not called.

    Step 6: Listen to a monitor (optional)

    For most games the detectors are enough. If you want the raw readings before a detector judges them, you can subscribe to a monitor in the same way. The Monitor page shows how. Monitors need the Pro version.

    The result

    When a cheat is found, you now know about it:

    • An Inspector event runs your method with no extra code.
    • Your game logic can hold back rewards or features with PossibleCheatingDetected.
    • An observer gets the find at the moment it happens. You can log it, warn the player, or flag the session.
    Tip

    You do not have to react at once. Often it is better to note that a player cheated, on the device or on your server, and to decide later what to do.

    Settings reference: Detector.

    Next steps

    • Protecting memory against Cheat Engine sets up the detector used in the samples here.
    • The Guides overview lists the other cheats you can protect against.

    Next guide: 13 - Punishing cheaters.

    Back to the Guides overview.

    In This Article
    Back to top GuardingPearSoftware documentation