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

Inherits IPostprocessBuildWithReport.

Public Member Functions

delegate void OnHashesGenerated (BuildReport report, IReadOnlyList< BuildHashes > hashedBuilds)
 

Static Public Member Functions

static BuildHashes CalculateExternalBuildHashes (string buildPath, bool printToConsole)
 
static async Task< BuildHashesCalculateExternalBuildHashesAsync (string buildPath, bool printToConsole)
 
static Task< IReadOnlyList< BuildHashes > > CalculateBuildReportHashesAsync (BuildReport report, bool printToConsole)
 

Static Public Attributes

const int CallbackOrder = int.MaxValue
 

Events

static OnHashesGenerated HashesGenerated
 

Detailed Description

Does calculates code hash after build if you use option "Generate code hash". Listen to HashesGenerated or look for hash for each build in the Editor Console.

Resulting hash in most cases should match value you get from the CodeHashGenerator

Member Function Documentation

◆ OnHashesGenerated()

delegate void OnHashesGenerated ( BuildReport  report,
IReadOnlyList< BuildHashes hashedBuilds 
)

HashesGenerated event delegate.

Parameters
reportStandard post-build report from Unity.
hashedBuildsBuild hashing results array.

You may generate multiple actual builds within single build operation, like multiple APKs when you use "Split APKs by target architecture" option, so you may have more than one valid hashed builds for one actual build procedure.

◆ CalculateExternalBuildHashes()

static BuildHashes CalculateExternalBuildHashes ( string  buildPath,
bool  printToConsole 
)
inlinestatic

Calls selection dialog and calculates hashes for the selected build.

Parameters
buildPathPath to the .apk / .aab or .exe file. Pass null to show file selection dialog.
printToConsolePath to the .apk / .aab or .exe file. Pass null to show file selection dialog.
Returns
Valid BuildHashes instance or null in case of error / user cancellation.

◆ CalculateExternalBuildHashesAsync()

static async Task<BuildHashes> CalculateExternalBuildHashesAsync ( string  buildPath,
bool  printToConsole 
)
inlinestatic

Calls selection dialog and calculates hashes for the selected build.

Parameters
buildPathPath to the .apk / .aab or .exe file. Pass null to show file selection dialog.
printToConsolePath to the .apk / .aab or .exe file. Pass null to show file selection dialog.
Returns
Task with Valid BuildHashes instance or null in case of error / user cancellation.

◆ CalculateBuildReportHashesAsync()

static Task<IReadOnlyList<BuildHashes> > CalculateBuildReportHashesAsync ( BuildReport  report,
bool  printToConsole 
)
inlinestatic

Calculates hashes for the given build report. Can be useful if you wish to hash build you just made with BuildPipeline.

Will not trigger the HashesGenerated event.

Parameters
reportBuildReport you wish to calculates hashes for
printToConsoleSpecifies if calculated hashes should be printed to Unity Console
Returns
Readonly List of the BuildHashes, one per each resulting build from the BuildReport.

Member Data Documentation

◆ CallbackOrder

const int CallbackOrder = int.MaxValue
static

Equals int.MaxValue to make sure this postprocessor will run as late as possible so you could run own postprocessors before and subscribe to HashesGenerated event.

Used at CodeHashGeneratorListener example.

Event Documentation

◆ HashesGenerated

OnHashesGenerated HashesGenerated
static

You may listen to this event if you wish to post-process resulting code hash, e.g. upload it to the server for the later runtime check with CodeHashGenerator.

Make sure to enable "Generate code hash on build completion" option in the ACTk settings to make this event work.