• Hello
Search Results for

    Show / Hide Table of Contents

    Protected DataChain & BlockChain (Pro)

    Some data grows over time, such as a list of scores, earned achievements, or a currency log. A cheat tool can rewrite an old entry or change the order. A data chain is an ordered list that notices that.

    Data chain and block chain need the Pro version.

    Which one to use

    Type Use it when
    DataChain<T> The data only lives in memory while the game runs
    BlockChain<T> The data must also be saved to a file or sent to your server, and loaded back

    Both are in the namespace GUPS.AntiCheat.Protected.Collection.Chain. Both check themselves and tell the PrimitiveCheatingDetector when the check fails.

    DataChain

    A data chain is a line of items. You add to the end, or remove from the end. Before each add or remove, the chain checks itself.

    using GUPS.AntiCheat.Protected.Collection.Chain;
    
    DataChain<int> scores = new DataChain<int>();
    
    // Append returns false when the chain was changed from outside.
    if (scores.Append(100))
    {
        // The chain is fine and the item was added.
    }
    else
    {
        // The chain was changed, most likely by a memory tool.
    }
    

    More calls:

    • RemoveLast() removes the last item. It returns false when the chain was changed.
    • CheckIntegrity() checks the chain without changing it.
    • AppendAsync and RemoveLastAsync do the same work without blocking the game.

    BlockChain

    A block chain is a data chain that can be saved and loaded. It stores the items in blocks. A synchronizer is the part that saves and loads them. Two are built in:

    • FileSynchronizer<T>: Saves the chain to a file on disk.
    • WebSynchronizer<T>: Saves the chain on your web server. Your server needs one address to read from and one to write to.

    You can also write your own with the ISynchronizer<T> interface.

    using GUPS.AntiCheat.Protected.Collection.Chain;
    
    // Save the chain to a file.
    string filePath = System.IO.Path.Combine(Application.persistentDataPath, "scores.dat");
    FileSynchronizer<int> synchronizer = new FileSynchronizer<int>(filePath);
    
    // 10 is the number of items per block.
    BlockChain<int> scores = new BlockChain<int>(10, synchronizer);
    
    // Add items. If the file already holds data, it is loaded first.
    await scores.AppendAsync(100);
    await scores.AppendAsync(250);
    
    // Load new items from the file or server yourself.
    await scores.SynchronizeAsync();
    
    // Check the chain yourself.
    if (!scores.CheckIntegrity())
    {
        // The chain was changed.
    }
    

    For a web server:

    WebSynchronizer<int> synchronizer = new WebSynchronizer<int>(
        "https://your-server.com/chain/read",
        "https://your-server.com/chain/write");
    

    The read address gets a timestamp and returns the newer items as a JSON list. The write address takes a JSON list of items.

    Do you need to add the detector?

    Both chains report to the PrimitiveCheatingDetector. The predefined Anti-Cheat-Monitor prefab already includes it.

    If you use your own monitor prefab, drag the Primitive Cheating Detector prefab onto the monitor in your prefab so it becomes a child.

    Settings: Memory tampering detector.

    Good to know

    • Keep it small. Every check goes through the whole chain. Do not use a chain for thousands of items.
    • Value types only. The items must be value types (structs), such as int, float, or your own struct. Classes are not allowed.
    • Checked before a sync. A block chain checks its last block before it loads or saves. A changed block is not sent on.
    • Not a real blockchain network. There is no mining and no shared ledger. The name only means that the entries are linked, so a rewrite is noticed.

    Back to the Protected overview.

    In This Article
    Back to top GuardingPearSoftware documentation