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

Public Member Functions

 ObscuredFile ()
 
 ObscuredFile (string fileName)
 
 ObscuredFile (ObscuredFileSettings settings)
 
 ObscuredFile (string fileNameOrPath, IObscuredFileSettings settings)
 
void Delete ()
 
ObscuredFileWriteResult WriteAllBytes (byte[] data)
 
ObscuredFileReadResult ReadAllBytes ()
 

Static Public Attributes

const string DefaultFileName = "actkfile"
 

Properties

IObscuredFileSettings CurrentSettings [get]
 
bool FileExists [get]
 
string FilePath [get]
 

Events

Action NotGenuineDataDetected
 
Action DataFromAnotherDeviceDetected
 

Detailed Description

Allows saving any binary data into the file either with or without encryption, with or without device locking and always with integrity check to make sure file is genuine.

Uses File IO which may cause main thread hiccups when operating with big amounts of data thus it's recommended to use it from background thread or at the stall moments of your app (like loading screens etc).
Please call DeviceIdHolder.ForceLockToDeviceInit() before accessing this class from background thread if you are using Device Lock feature without custom DeviceID.

Constructor & Destructor Documentation

◆ ObscuredFile() [1/4]

ObscuredFile ( )
inline

Creates instance with file name set to DefaultFileName and default ObscuredFileSettings.

◆ ObscuredFile() [2/4]

ObscuredFile ( string  fileName)
inline

Creates instance with specified file name and default ObscuredFileSettings.

Parameters
fileNameCustom file name to place at ObscuredFileLocation.PersistentData.

◆ ObscuredFile() [3/4]

ObscuredFile ( ObscuredFileSettings  settings)
inline

Creates instance with file name set to DefaultFileName and custom specific settings.

Parameters
settingsCustom settings to use with this instance.

◆ ObscuredFile() [4/4]

ObscuredFile ( string  fileNameOrPath,
IObscuredFileSettings  settings 
)
inline

Creates instance with specified file name or file path and custom specific settings.

Parameters
fileNameOrPathFile path if using ObscuredFileLocation.Custom, otherwise represents file name to use with set ObscuredFileLocation kind.
settingsCustom settings to use with this instance.

Member Function Documentation

◆ Delete()

void Delete ( )
inline

Deletes physical file assigned with this instance. Does nothing if file does not exists.

◆ WriteAllBytes()

ObscuredFileWriteResult WriteAllBytes ( byte[]  data)
inline

Writes passed data to the physical file on disk. Consider calling from background thread for the large data amount.

Parameters
dataCustom byte array to write.
Returns
Operation result.

◆ ReadAllBytes()

ObscuredFileReadResult ReadAllBytes ( )
inline

Reads all bytes from the physical file on disk. Consider calling from background thread for the large data amount.

Returns
Operation result structure allowing both to get read data and figure out possible violations and errors if data could not be read for some reason.

Member Data Documentation

◆ DefaultFileName

const string DefaultFileName = "actkfile"
static

Filename used by default, if other name or path was not specified in constructor.

Property Documentation

◆ CurrentSettings

IObscuredFileSettings CurrentSettings
get

Allows reading current settings.

◆ FileExists

bool FileExists
get

Returns true if file at FilePath physically exists on disk.

◆ FilePath

string FilePath
get

Returns path to the file. It's always not empty and valid even if file was not saved to the physical disk yet.

Event Documentation

◆ NotGenuineDataDetected

Action NotGenuineDataDetected

Fires when saved data tampering detected. Will not fire when data is damaged and not readable.

◆ DataFromAnotherDeviceDetected

Action DataFromAnotherDeviceDetected

Fires when saved data from some other device detected.

May be helpful to ban potential cheaters, trying to use someone's purchased in-app goods for example.
NOTE: Will fire if same device ID has changed (pretty rare case though). Read more at DeviceLockLevel.