• Hello
Search Results for

    Show / Hide Table of Contents

    Universal - Game Time - Detector (Pro)

    Many games use Time.deltaTime for movement and cooldowns. A speed hack is a tool that makes that clock run too fast, too slow, or stop. This detector notices that and keeps ProtectedTime on real speed.

    This detector needs the Pro version.

    Walkthrough: Protecting against speedhacks.

    What it does

    GameTimeCheatingDetector (namespace GUPS.AntiCheat.Detector) does two things:

    • It detects. It listens to the GameTimeMonitor. The monitor measures how fast Unity's clock really runs. The detector decides if that is a speed hack.
    • It corrects. While a speed hack is on, ProtectedTime stays on real speed. A changed fixedDeltaTime is put back.

    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 Game Time 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 GameTimeMonitor must be on the same GameObject as the detector. Without it, the detector logs a warning and does nothing.

    Settings

    The GameTimeCheatingDetector settings.

    • Is Active (isActive, bool, default true): Turns the detector on or off.
    • Possibility Of False Positive (possibilityOfFalsePositive, 0 to 1, default 0.25): How likely a find is a false alarm. An uneven timer can look like a speed hack for a moment.
    • Threat Rating (threatRating, default 45): How much one find adds to the threat score. It is low because a speed hack is reported again about every 2.5 seconds while it stays on. The score adds up quickly.
    • Detect Delta Time Cheating (detectDeltaTimeCheating, bool, default true): React when the game clock is sped up or slowed down. This is the usual speed hack.
    • Detect Fixed Delta Time Cheating (detectFixedDeltaTimeCheating, bool, default false): React when fixedDeltaTime is changed. That value sets how often physics runs. Cheaters change it to skip physics, for example to walk through walls.
    • On Cheating Detection Event (OnCheatingDetectionEvent): Methods to call on every find.
    Important

    While Detect Fixed Delta Time Cheating is on, change the physics step only through ProtectedTime.fixedDeltaTime. Any other change to Time.fixedDeltaTime is treated as a cheat and put back.

    Use ProtectedTime

    The correction only helps code that reads the protected clock. Replace UnityEngine.Time with GUPS.AntiCheat.Protected.Time.ProtectedTime. The names match.

    // Before
    transform.position += velocity * Time.deltaTime;
    
    // After
    transform.position += velocity * ProtectedTime.deltaTime;
    

    All properties: Protected Game Time.

    What it reports

    On a find, the detector sends a GameTimeDetectionStatus:

    public struct GameTimeDetectionStatus : ICheatingDetectionStatus
    {
        // The kind of cheat. Always ECheatType.GameTime.
        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; }
    
        // SpedUp, SlowedDown, Stopped, or None.
        public EGameTimeDeviation Deviation { get; }
    
        // True when the game clock was sped up or slowed down.
        public bool DeltaTimeCheating { get; }
    
        // True when fixedDeltaTime was changed.
        public bool FixedDeltaTimeCheating { get; }
    }
    

    You can also read these properties on the detector:

    • PossibleCheatingDetected: true while a speed hack or a changed fixedDeltaTime is found.
    • DeltaTimeCheatingDetected and FixedDeltaTimeCheatingDetected: which of the two it is.
    • TimeDeviation: SpedUp, SlowedDown, or Stopped while a speed hack is found. Otherwise None.

    Good to know

    • The flag clears. PossibleCheatingDetected turns false again when the clock looks normal. Most other detectors keep it true.
    • A find takes about 2.5 seconds. The detector waits until most reports in that time agree. A short hitch is not reported. The correction of ProtectedTime starts earlier, with the first bad report.
    • No jump when the hack ends. ProtectedTime keeps going from where it is. It does not jump to Unity's sped-up time.
    • Time.timeScale is not a cheat. Pause and slow motion work as before. ProtectedTime.timeScale passes the value through.
    • Not found: a tool that slows the whole computer, not only the game.

    Platforms and requirements

    Every platform. On WebGL the protection is weaker. See the monitor page.

    The detector needs a GameTimeMonitor on the same GameObject. There are no other requirements.

    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. Ask the detector:

    var detector = AntiCheatMonitor.Instance.GetDetector<GameTimeCheatingDetector>();
    
    if (detector != null && detector.PossibleCheatingDetected)
    {
        // The game clock runs too fast or too slow right now.
    }
    

    Or 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;
    using UnityEngine;
    
    public class GameTimeDetectionLogger : MonoBehaviour, IObserver<IDetectorStatus>
    {
        private void Start()
        {
            var detector = AntiCheatMonitor.Instance.GetDetector<GameTimeCheatingDetector>();
            detector.Subscribe(this);
        }
    
        public void OnNext(IDetectorStatus status)
        {
            Debug.LogWarning($"Speed hack found. Threat: {status.ThreatRating}");
        }
    
        public void OnError(Exception error) { }
        public void OnCompleted() { }
    }
    

    Back to the Detector overview.

    In This Article
    Back to top GuardingPearSoftware documentation