• Hello
Search Results for

    Show / Hide Table of Contents

    Protected Collection (Pro)

    Important data is not only a single number. It can also be a list, a queue, or a stack. AntiCheat has protected versions of those. You can check that they were not changed.

    Protected List

    A protected list works like a normal List<T>. Each time you get, add, or set an item, it builds a hash of its data. Call CheckIntegrity to see if that hash still matches.

    By default the items must be value types (structs), not classes. A class could be changed from outside the list, and the check would fail even when you meant to change it. You can allow classes if you want.

    Typical situations where you might use a list include:

    • Player inventory: A list can be used to store the items that a player has collected or is carrying.
    • High scores: A list can be employed to keep track of the top scores achieved by players.
    • Quest objectives: A list can be useful for storing the objectives or tasks that a player needs to complete during a quest.

    If that data matters, use ProtectedList<T> instead of List<T>.

    /// <summary>
    /// Represents a protected list that implements the <see cref="IList{T}"/> interface. This list allows tracking changes 
    /// and provides a hash code for verification purposes. Before interacting with the list, you should call the <see cref="CheckIntegrity"/> 
    /// method to verify its integrity.
    /// </summary>
    /// <typeparam name="T">The type of elements in the list.</typeparam>
    public class ProtectedList<T> : IList<T>, IDataIntegrity where T : struct
    

    Using a ProtectedList might look like this:

    // Create a new protected list.
    ProtectedList<Int32> protectedList = new ProtectedList<Int32>();
    
    // Fill it with data.
    protectedList.Add(1);
    protectedList.Add(2);
    protectedList.Add(3);
    
    // Verify its integrity.
    if(protectedList.CheckIntegrity())
    {
       // Still has its integrity, do some calculation and send it to the server.
       // ... TODO: Put your code here.
    }
    else
    {
       // Has lost its integrity, probably caused by memory manipulation.
       // ... TODO: Put your code here.
    }
    

    A protected list does not tell a detector on its own. Checking on every access can be too slow. Call CheckIntegrity when you need it.

    Protected Queue

    A protected queue works like a normal Queue<T>. Each time you get, add, or set an item, it builds a hash of its data. Call CheckIntegrity to see if that hash still matches.

    By default the items must be value types (structs), not classes. You can allow classes if you want.

    Typical situations where you might use a queue include:

    • Player actions: A queue can be used to store the actions or commands issued by a player, processing them in a first-in-first-out (FIFO) manner.
    • Event queue: Game events, such as notifications, messages, or triggers, can be stored in a queue to be processed sequentially.
    • AI behavior queue: In a strategy game, a queue could store AI actions or decisions to be executed one after the other.

    If that data matters, use ProtectedQueue<T> instead of Queue<T>.

    /// <summary>
    /// Represents a protected queue that implements the <see cref="IEnumerable{T}"/>, <see cref="IEnumerable"/>, 
    /// <see cref="IReadOnlyCollection{T}"/>, and <see cref="ICollection"/> interfaces. This queue allows tracking changes and 
    /// provides a hash code for verification purposes. Before interacting with the queue, you should call the <see cref="CheckIntegrity"/>
    /// to verify its integrity.
    /// </summary>
    /// <typeparam name="T">The type of elements in the queue.</typeparam>
    public class ProtectedQueue<T> : IEnumerable<T>, IEnumerable, IReadOnlyCollection<T>, ICollection, IDataIntegrity where T : struct
    

    Using a ProtectedQueue might look like this:

    // Create a new protected queue.
    ProtectedQueue<Int32> protectedQueue = new ProtectedQueue<Int32>();
    
    // Fill it with data.
    protectedQueue.Enqueue(1);
    protectedQueue.Enqueue(2);
    protectedQueue.Enqueue(3);
    
    // Verify its integrity.
    if(protectedQueue.CheckIntegrity())
    {
       // Still has its integrity, do some calculation and send it to the server.
       // ... TODO: Put your code here.
    }
    else
    {
       // Has lost its integrity, probably caused by memory manipulation.
       // ... TODO: Put your code here.
    }
    

    A protected queue does not tell a detector on its own. Call CheckIntegrity when you need it.

    Protected Stack

    A protected stack works like a normal Stack<T>. Each time you get, add, or set an item, it builds a hash of its data. Call CheckIntegrity to see if that hash still matches.

    By default the items must be value types (structs), not classes. You can allow classes if you want.

    Typical situations where you might use a stack include:

    • Undo/redo functionality: Stacks are suitable for implementing undo and redo functionality, allowing players to revert or repeat their actions.
    • Navigation history: A stack can store the history of player movements or locations, making it easy to backtrack through the game.
    • Buffs and debuffs: Stacks can be used to manage the application and removal of temporary effects on characters, such as buffs or debuffs.
    /// <summary>
    /// Represents a protected stack that implements the <see cref="IEnumerable{T}"/>, <see cref="IEnumerable"/>, 
    /// <see cref="IReadOnlyCollection{T}"/>, and <see cref="ICollection"/> interfaces. This stack allows tracking changes 
    /// and provides a hash code for verification purposes. Before interacting with the stack, you should call the <see cref="CheckIntegrity"/>
    /// to verify its integrity.
    /// </summary>
    /// <typeparam name="T">The type of elements in the stack.</typeparam>
    public class ProtectedStack<T> : IEnumerable<T>, IEnumerable, IReadOnlyCollection<T>, ICollection, IDataIntegrity where T : struct
    

    Using a ProtectedStack might look like this:

    // Create a new protected stack.
    ProtectedStack<Int32> protectedStack = new ProtectedStack<Int32>();
    
    // Fill it with data.
    protectedStack.Push(1);
    protectedStack.Push(2);
    protectedStack.Push(3);
    
    // Verify its integrity.
    if(protectedStack.CheckIntegrity())
    {
       // Still has its integrity, do some calculation and send it to the server.
       // ... TODO: Put your code here.
    }
    else
    {
       // Has lost its integrity, probably caused by memory manipulation.
       // ... TODO: Put your code here.
    }
    

    A protected stack does not tell a detector on its own. Call CheckIntegrity when you need it.

    In This Article
    Back to top GuardingPearSoftware documentation