• Hello
Search Results for

    Show / Hide Table of Contents

    Struct ProtectedInt32

    Drop-in replacement for System.Int32 that obfuscates the value in memory and reports tampering to the .

    Implements
    IProtected
    IDisposable
    ISerializationCallbackReceiver
    Namespace: GUPS.AntiCheat.Protected
    Assembly: cs.temp.dll.dll
    Syntax
    public struct ProtectedInt32
    Examples

    Use it as a drop-in replacement for System.Int32:

    using GUPS.AntiCheat.Protected;
    
    public class Score : MonoBehaviour
    {
        // The score is XOR-obfuscated in memory and watched by the primitive cheating detector.
        [SerializeField] private ProtectedInt32 points = 0;
    
        public void Add(int amount) => points += amount;
        public int  Get()           => points;          // implicit conversion to int
    }

    Constructors

    ProtectedInt32(Int32)

    Initializes a new protected Int32 with the specified value.

    Declaration
    public ProtectedInt32(Int32 _Value = null)
    Parameters
    Type Name Description
    Int32 _Value

    Initial value.

    Properties

    HasIntegrity

    Gets a value indicating whether the protected value still has integrity (i.e. the honeypot has not been tampered with).

    Declaration
    public bool HasIntegrity { get; }
    Property Value
    Type Description
    System.Boolean

    Value

    Gets or sets the unobfuscated value.

    Declaration
    public Int32 Value { get; set; }
    Property Value
    Type Description
    Int32
    Remarks

    Reading the value runs an integrity check; if the honeypot has been tampered with, the is notified.

    Methods

    CheckIntegrity()

    Returns true when the honeypot still matches the obfuscated value.

    Declaration
    public bool CheckIntegrity()
    Returns
    Type Description
    System.Boolean

    true if the value is intact; otherwise false.

    Dispose()

    Clears the obfuscated value and the secret.

    Declaration
    public void Dispose()

    Equals(Object)

    Returns true when this protected value equals the given object.

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    System.Object obj

    Object to compare with.

    Returns
    Type Description
    System.Boolean

    true if equal; otherwise false.

    Overrides
    System.ValueType.Equals(System.Object)

    GetHashCode()

    Returns the hash code of the unobfuscated value.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    System.Int32

    Hash code of the unobfuscated value.

    Overrides
    System.ValueType.GetHashCode()

    Obfuscate()

    Rerolls the secret and re-obfuscates the current value.

    Declaration
    public void Obfuscate()

    OnAfterDeserialize()

    Unity deserialization hook; rebuilds the obfuscation state from the deserialized honeypot value.

    Declaration
    public void OnAfterDeserialize()

    OnBeforeSerialize()

    Unity serialization hook; writes the true value into the honeypot field.

    Declaration
    public void OnBeforeSerialize()

    ToString()

    Returns the string representation of the unobfuscated value.

    Declaration
    public override string ToString()
    Returns
    Type Description
    System.String

    The string representation of the unobfuscated value.

    Overrides
    System.ValueType.ToString()

    Operators

    Addition(ProtectedInt32, ProtectedInt32)

    Adds two protected values.

    Declaration
    public static ProtectedInt32 operator +(ProtectedInt32 v1, ProtectedInt32 v2)
    Parameters
    Type Name Description
    ProtectedInt32 v1

    First operand.

    ProtectedInt32 v2

    Second operand.

    Returns
    Type Description
    ProtectedInt32

    The sum.

    Division(ProtectedInt32, ProtectedInt32)

    Divides the first protected value by the second.

    Declaration
    public static ProtectedInt32 operator /(ProtectedInt32 v1, ProtectedInt32 v2)
    Parameters
    Type Name Description
    ProtectedInt32 v1

    First operand.

    ProtectedInt32 v2

    Second operand.

    Returns
    Type Description
    ProtectedInt32

    The quotient.

    Equality(ProtectedInt32, ProtectedInt32)

    Returns true when both protected values represent the same number.

    Declaration
    public static bool operator ==(ProtectedInt32 v1, ProtectedInt32 v2)
    Parameters
    Type Name Description
    ProtectedInt32 v1

    First operand.

    ProtectedInt32 v2

    Second operand.

    Returns
    Type Description
    System.Boolean

    true if equal; otherwise false.

    GreaterThan(ProtectedInt32, ProtectedInt32)

    Returns true when the first value is greater than the second.

    Declaration
    public static bool operator>(ProtectedInt32 v1, ProtectedInt32 v2)
    Parameters
    Type Name Description
    ProtectedInt32 v1

    First operand.

    ProtectedInt32 v2

    Second operand.

    Returns
    Type Description
    System.Boolean

    true if v1 > v2; otherwise false.

    GreaterThanOrEqual(ProtectedInt32, ProtectedInt32)

    Returns true when the first value is greater than or equal to the second.

    Declaration
    public static bool operator >=(ProtectedInt32 v1, ProtectedInt32 v2)
    Parameters
    Type Name Description
    ProtectedInt32 v1

    First operand.

    ProtectedInt32 v2

    Second operand.

    Returns
    Type Description
    System.Boolean

    true if v1 >= v2; otherwise false.

    Implicit(ProtectedInt32 to Int32)

    Implicitly unwraps a protected Int32 to its Int32 value.

    Declaration
    public static implicit operator Int32(ProtectedInt32 _Value)
    Parameters
    Type Name Description
    ProtectedInt32 _Value

    Protected Int32 to unwrap.

    Returns
    Type Description
    Int32

    The unobfuscated Int32 value.

    Implicit(Int32 to ProtectedInt32)

    Implicitly wraps an Int32 in a protected Int32.

    Declaration
    public static implicit operator ProtectedInt32(Int32 _Value)
    Parameters
    Type Name Description
    Int32 _Value

    Value to wrap.

    Returns
    Type Description
    ProtectedInt32

    A protected Int32 holding the given value.

    Inequality(ProtectedInt32, ProtectedInt32)

    Returns true when the two protected values represent different numbers.

    Declaration
    public static bool operator !=(ProtectedInt32 v1, ProtectedInt32 v2)
    Parameters
    Type Name Description
    ProtectedInt32 v1

    First operand.

    ProtectedInt32 v2

    Second operand.

    Returns
    Type Description
    System.Boolean

    true if not equal; otherwise false.

    LessThan(ProtectedInt32, ProtectedInt32)

    Returns true when the first value is less than the second.

    Declaration
    public static bool operator <(ProtectedInt32 v1, ProtectedInt32 v2)
    Parameters
    Type Name Description
    ProtectedInt32 v1

    First operand.

    ProtectedInt32 v2

    Second operand.

    Returns
    Type Description
    System.Boolean

    true if v1 < v2; otherwise false.

    LessThanOrEqual(ProtectedInt32, ProtectedInt32)

    Returns true when the first value is less than or equal to the second.

    Declaration
    public static bool operator <=(ProtectedInt32 v1, ProtectedInt32 v2)
    Parameters
    Type Name Description
    ProtectedInt32 v1

    First operand.

    ProtectedInt32 v2

    Second operand.

    Returns
    Type Description
    System.Boolean

    true if v1 <= v2; otherwise false.

    Multiply(ProtectedInt32, ProtectedInt32)

    Multiplies two protected values.

    Declaration
    public static ProtectedInt32 operator *(ProtectedInt32 v1, ProtectedInt32 v2)
    Parameters
    Type Name Description
    ProtectedInt32 v1

    First operand.

    ProtectedInt32 v2

    Second operand.

    Returns
    Type Description
    ProtectedInt32

    The product.

    Subtraction(ProtectedInt32, ProtectedInt32)

    Subtracts the second protected value from the first.

    Declaration
    public static ProtectedInt32 operator -(ProtectedInt32 v1, ProtectedInt32 v2)
    Parameters
    Type Name Description
    ProtectedInt32 v1

    First operand.

    ProtectedInt32 v2

    Second operand.

    Returns
    Type Description
    ProtectedInt32

    The difference.

    Implements

    IProtected
    IDisposable
    ISerializationCallbackReceiver
    In This Article
    Back to top GuardingPearSoftware documentation