Anti-Cheat Toolkit  2023.2.6
Multi-purpose anti-cheat solution for Unity Engine
CodeHashGenerator Class Reference

Inherits KeepAliveBehaviour< CodeHashGenerator >, and ICodeHashGenerator.

Static Public Member Functions

static bool IsTargetPlatformCompatible ()
 
static ICodeHashGenerator AddToSceneOrGetExisting ()
 
static ICodeHashGenerator Generate (int maxThreads=1)
 
static Task< HashGeneratorResultGenerateAsync (int maxThreads=1)
 

Public Attributes

bool keepAlive
 

Properties

HashGeneratorResult LastResult [get]
 
bool IsBusy [get]
 
static T Instance [get, protected set]
 

Events

static HashGeneratorResultHandler HashGenerated
 

Detailed Description

Generates current application runtime code hash to let you validate it against previously generated runtime code hash to detect external code manipulations.

Calculation is done on the separate threads where possible to prevent noticeable CPU spikes and performance impact.
Supported platforms: Windows PC, Android (more to come)
Resulting hash in most cases should match value you get from the CodeHashGeneratorPostprocessor.

Member Function Documentation

◆ IsTargetPlatformCompatible()

static bool IsTargetPlatformCompatible ( )
inlinestatic

Call to make sure current platform is compatible before calling Generate().

Returns
True if current platform is supported by the CodeHashGenerator, otherwise returns false. Can return true in Editor but Hash Generation in Editor is not possible (nothing to hash).

◆ AddToSceneOrGetExisting()

static ICodeHashGenerator AddToSceneOrGetExisting ( )
inlinestatic

Creates new instance of the CodeHashGenerator at scene if it doesn't exists. Make sure to call NOT from Awake phase.

Returns
New or existing instance of the detector.

◆ Generate()

static ICodeHashGenerator Generate ( int  maxThreads = 1)
inlinestatic

Call to start current runtime code hash generation. Automatically adds instance to the scene if necessary.

Parameters
maxThreadsThreads to use while hashing the files.

Implements ICodeHashGenerator.

◆ GenerateAsync()

static Task<HashGeneratorResult> GenerateAsync ( int  maxThreads = 1)
inlinestatic

Awaitable version of Generate(). Allows awaiting for the generation result.

Parameters
maxThreadsThreads to use while hashing the files.

Implements ICodeHashGenerator.

Member Data Documentation

◆ keepAlive

bool keepAlive
inherited

Will survive new level (scene) load if checked. Otherwise it will be destroyed.

On dispose Behaviour follows 2 rules:

  • if Game Object's name is "Anti-Cheat Toolkit": it will be automatically destroyed if no other Behaviours left attached regardless of any other components or children;
  • if Game Object's name is NOT "Anti-Cheat Toolkit": it will be automatically destroyed only if it has neither other components nor children attached;

Property Documentation

◆ LastResult

HashGeneratorResult LastResult
get

Stores previously calculated result. Can be null if Generate() wasn't called yet or if it was called but calculation is still in process.

See also
IsBusy

◆ IsBusy

bool IsBusy
get

Indicates if hash generation is currently in process.

◆ Instance

T Instance
staticgetprotected setinherited

Allows reaching public properties from code. Can be null if behaviour does not exist in scene or if accessed at or before Awake phase.

Event Documentation

◆ HashGenerated

HashGeneratorResultHandler HashGenerated
static

Subscribe to get resulting hash right after it gets calculated.