• Hello
Search Results for

    Show / Hide Table of Contents

    02 - Protecting memory against Cheat Engine

    Goal: You will learn how to protect your variables against memory tools like Cheat Engine, and how to notice and react when someone tampers with them.

    The problem

    Changing values in memory is one of the easiest ways to cheat. A tool like Cheat Engine scans the memory of the running game. The player searches for a number they see on screen, such as coins, health, or score, and changes it to whatever they want.

    That hurts your game. Leaderboards become worthless, paid items become free, and honest players lose to cheaters.

    Image 1: Cheat Engine is used to find and change the number of coins in a game.

    The solution

    Use Anti-Cheat protected types. They hide the real value, so Cheat Engine cannot simply find and edit it. The Primitive Cheating Detector then tells the Anti-Cheat Monitor when someone tampers with a value.

    This works in the Free and the Pro version.

    Step 1: Decide what to protect

    You do not need to protect every value in your game. Protect the ones that give an unfair advantage when changed:

    • Player health: So players cannot make themselves invincible.
    • Currencies (coins, gems): So players cannot give themselves unlimited money.
    • Scores: So players cannot push themselves up a leaderboard.
    • Ammunition or resources: So players cannot fire forever without reloading.

    Step 2: Replace plain types with protected types

    Use the protected version of a type instead of the plain one. A protected type does two things:

    • It hides the real value in memory. A search for the number on screen does not find it.
    • It keeps a fake value in its place, called a honeypot. A cheater who searches for the coin amount finds the honeypot. As soon as they change it, Anti-Cheat notices.

    Here is a simple score script before:

    using UnityEngine;
    
    public class PlayerScore : MonoBehaviour
    {
        // Plain int: stored in memory as it is, easy to edit.
        private int coins = 0;
    
        public void AddCoins(int amount)
        {
            coins += amount;
        }
    }
    

    And after:

    using UnityEngine;
    using GUPS.AntiCheat.Protected;
    
    public class PlayerScore : MonoBehaviour
    {
        // ProtectedInt32: hidden in memory and watched.
        private ProtectedInt32 coins = 0;
    
        public void AddCoins(int amount)
        {
            coins += amount;
        }
    }
    

    Only the type changed. You add, subtract, and read the value like before.

    All protected types: Protected Primitives.

    Step 3: Make sure the detector is there

    A protected value notices tampering, but it does not react. It tells the Primitive Cheating Detector. The detector passes the find on to the Anti-Cheat Monitor.

    The predefined Anti-Cheat-Monitor prefab already includes this detector. If you use it, you have nothing to do here.

    If you use your own monitor prefab, add the detector to it. The prepared prefab is in Assets/GUPS/AntiCheat/Resources/Prefabs/Detectors. Drag it onto the monitor in your prefab so it becomes a child.

    Image 2: The Primitive Cheating Detector prefab in Assets/GUPS/AntiCheat/Resources/Prefabs/Detectors, next to the other detectors.

    Step 4: Set up the detector and react

    Select the detector. The Inspector shows these settings:

    Image 3: The Primitive Cheating Detector in the Inspector.

    • Is Active: Turns the detector on or off.
    • Threat Rating: How much one find adds to the threat score of the Anti-Cheat Monitor. The default is 500. A higher value makes memory tampering count more.
    • On Cheating Detection Event: Your own reactions. Assign a method here, like on a button's OnClick. You need no code for that.

    You can also ask the detector in code:

    var detector = AntiCheatMonitor.Instance.GetDetector<PrimitiveCheatingDetector>();
    
    if (detector != null && detector.PossibleCheatingDetected)
    {
        // A protected value was changed at least once.
    }
    
    Note

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

    Step 5: Try it

    Open the demo scene Assets/GUPS/AntiCheat/Demos/Demo_Memory/Scene.unity. It shows a score you can try to edit in memory, with and without protection. The demo folder has its own ReadMe.

    The result

    With protected variables and the Primitive Cheating Detector in place:

    • The real coin, health, or score value is hidden in memory. A scanner cannot change it by editing a plain number.
    • A cheater who searches for the number on screen finds a honeypot. Changing it is noticed as tampering.
    • The detector raises the threat score of the Anti-Cheat Monitor. It can also run your Inspector callbacks or your code.

    Settings reference: Memory tampering detector.

    Next steps

    • Reacting to detected cheating shows how to run your own logic when tampering is found.
    • Punishing cheaters shows how to react automatically.
    • Protected Primitives lists all protected types.

    Next guide: 03 - Protecting saved data (PlayerPrefs).

    Back to the Guides overview.

    In This Article
    Back to top GuardingPearSoftware documentation