• Hello
Search Results for

    Show / Hide Table of Contents

    Protected Game Time (Pro)

    Many games use Time.deltaTime for movement and cooldowns. A speed hack can change that clock. ProtectedTime keeps a safer clock.

    Walkthrough: Protecting against speedhacks.

    How to use

    Replace UnityEngine.Time with ProtectedTime. The names match.

    
    // 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 interval in seconds at which physics and other fixed frame rate updates are performed. Use the setter to change it.
        public static float fixedDeltaTime { get; set; }
    
        // 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; }
    }
    

    Two pieces do the work. The monitor compares Unity's clock with a real-time clock that speed hacks cannot easily fake. Speed hacks scale the clocks the game can read, so comparing two of those shows nothing. The monitor reports the measured speed.

    The detector groups those reports into windows of about 2.5 seconds. A cheat is confirmed when most reports in a window agree. It then tells the AntiCheat-Monitor once for that window.

    From the first bad report, ProtectedTime is corrected by the measured speed. It stays on real speed while a hack starts, changes, or stops. It does not jump when the hack ends. A changed fixedDeltaTime is written back to the last value set through ProtectedTime.fixedDeltaTime. Time.timeScale is not treated as cheating. ProtectedTime.timeScale is a plain pass-through.

    Drag and drop the prefab onto the AntiCheat monitor in your scene.

    Custom Observer

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

    
    // Get the detector from the AntiCheat monitor.
    var detector = AntiCheatMonitor.Instance
          .GetDetector<GameTimeCheatingDetector>();
    
    // Subscribe as observer and get notified on cheating.
    detector.Subscribe(myObserver);
    
    In This Article
    Back to top GuardingPearSoftware documentation