• Hello
Search Results for

    Show / Hide Table of Contents

    Universal - Game Time - Detector (Pro)

    In Unity, frame-based calculations rely heavily on UnityEngine.Time.deltaTime. Unfortunately, this time calculation is vulnerable to manipulation by cheat or hacking tools that allow unwanted acceleration, deceleration, or interruption of your game. AntiCheat has introduced a way to counteract such time manipulation.

    Detector

    The 'GameTimeCheatingDetector' is used to detect game time (UnityEngine.Time) cheating. It observes the 'GameTimeMonitor' and subscribes to time deviations; based on these it calculates the possibility of cheating and notifies observers of the detected cheating. Additionally, it starts countermeasures by calculating the game time based on system ticks if cheating is detected. So even if cheating occurs, the game time will be calculated correctly and applied in GUPS.AntiCheat.Protected.Time.ProtectedTime.

    Observed Subject

    The detector observes the 'GameTimeStatus' sent by the 'GameTimeMonitor'.

    Detector Status

    The detector accumulates the received game time deviations and calculates an average to decide whether the game was paused, sped up, slowed down, or runs as planned. If a deviation, and so cheating, is detected, the detector notifies its observers with a 'CheatingDetectionStatus'. The status contains the following properties:

    1. PossibilityOfFalsePositive: A value indicating the possibility of a false positive when assessing threats for the implementing subject, from 0.0 to 1.0.
    2. ThreatRating: The threat rating associated with the detected cheating, indicating the assessed level of a potential threat.

    Supported Platforms

    The detector is available on all platforms.

    Requirements

    There are no requirements.

    How To Use

    The usage is quite simple: attach a 'GameTimeMonitor' (if not already done) and the 'GameTimeCheatingDetector' to a child GameObject of the 'AntiCheat-Monitor' and define a reaction on cheating detection.

    Add Monitor Component

    To detect any kind of game time manipulation, a source of game time deviation data is required. To do so, use the 'GameTimeMonitor' and attach it to the same GameObject you will attach the 'GameTimeCheatingDetector' to. The detector will subscribe to the 'GameTimeStatus', containing the game time deviation, sent by the monitor.

    Add Detector Component

    Manual

    Add the 'GameTimeCheatingDetector' MonoBehavior from the 'GUPS.AntiCheat.Detector' namespace to your 'AntiCheat-Monitor' GameObject, or better, to a child GameObject, next to your 'GameTimeMonitor' MonoBehavior.

    Add the 'GameTimeCheatingDetector' as a Component.

    Prefab

    There is also a prefab, including the detector and the monitors, which you can directly attach as a GameObject to the 'AntiCheat-Monitor'.

    Add the 'Game Time Cheating Detector' prefab to the 'AntiCheat-Monitor'.

    Settings

    After attaching the 'GameTimeCheatingDetector' MonoBehavior to a GameObject, you will see the following in the inspector:

    The settings of the 'GameTimeCheatingDetector' Component.

    • General Settings: Define here whether the detector should be active.
    • Threat Rating Settings: Define here the severity of the detected cheating.
    • Observable Settings: Add here callbacks invoked when cheating is detected.

    Runtime

    In the Awake callback, the detector observes the 'GameTimeMonitor' and subscribes to time deviations; based on these it calculates the possibility of cheating and notifies observers of the detected cheating. It also provides a trustworthy game time, provided in the ProtectedTime class.

    An abstract of the ProtectedTime class:

    // Replace your usage of the UnityEngine.Time class with GUPS.AntiCheat.Protected.Time.ProtectedTime.
    public static class ProtectedTime
    {
        // The time in seconds it took to complete the last frame (Read Only).
        public static float deltaTime { get; }
    
        // The real time in seconds since the game started (Read Only).
        public static float realtimeSinceStartup { get; }
    
        // The time at the beginning of this frame (Read Only). This is the time in seconds since the start of the game.
        public static float time { get; }
    
        // The scale at which the time is passing. This can be used for slow motion effects.
        public static float timeScale { get; set; }
    
        // The time this frame has started (Read Only). This is the time in seconds since the last level has been loaded.
        public static float timeSinceLevelLoad { get; }
    
        // The timeScale-independent interval in seconds from the last frame to the current one (Read Only).
        public static float unscaledDeltaTime { get; }
    
        // The timeScale-independent time for this frame (Read Only). This is the time in seconds since the start of the game.
        public static float unscaledTime { get; }
    }
    

    React On Cheating

    When the monitor (data provider) and detector (data validator) are set up, you surely want to react to detected cheating.

    Punisher

    In general, any cheat detected is forwarded to the 'AntiCheat-Monitor', which calculates an overall threat level. Based on the threat level, you can apply punishments by using Punisher components added to a child GameObject of the 'AntiCheat-Monitor'. There are some built-in punishers that you can find here as prefabs:

    The location of the built-in Punisher prefabs.

    Inspector

    You can set a callback in the Unity Inspector view of the detector. This callback is invoked as soon as the specific cheating is detected.

    A list of callbacks invoked when cheating is detected by the detector.

    Code

    If you would like to write a custom listener for the detector, you can attach an observer:

    // Get the detector.
    var detector = AntiCheatMonitor.Instance
          .GetDetector<GameTimeCheatingDetector>();
    
    // Subscribe as observer and get notified on inconsistency.
    detector.Subscribe(myObserver);
    

    The detector also has an inherited property 'PossibleCheatingDetected' which is set to true once cheating has been detected.

    In This Article
    Back to top GuardingPearSoftware documentation