Class ObscuredCheatingDetector
Detects CodeStage.AntiCheat.ObscuredTypes cheating.
[AddComponentMenu("Code Stage/Anti-Cheat Toolkit/Obscured Cheating Detector")]
[DisallowMultipleComponent]
[HelpURL("https://docs.codestage.net/actk/manual/detectors.html#obscured-cheating-detector")]
public class ObscuredCheatingDetector : ACTkDetectorBase<ObscuredCheatingDetector>
- Inheritance
-
objectObjectComponentBehaviourMonoBehaviourObscuredCheatingDetector
- Inherited Members
Remarks
It allows cheaters to find desired (fake) values in memory and change them, keeping original values secure.
It's like a cheese in the mouse trap - cheater tries to change some obscured value and get caught on it.
Just add it to any GameObject as usual or through the GameObject > Create Other > Code Stage > Anti-Cheat Toolkit
menu to get started.
You can use detector completely from inspector without writing any code except the actual reaction on cheating.
Avoid using detectors from code at the Awake phase.
// Basic usage - start detection with callback
void Start()
{
ObscuredCheatingDetector.StartDetection(OnObscuredCheatingDetected);
}
private void OnObscuredCheatingDetected()
{
Debug.Log("Obscured cheating detected!");
// Get detailed detection info
var info = ObscuredCheatingDetector.Instance.LastDetectionInfo;
if (info != null)
{
Debug.Log($"Type: {info.SourceType}");
Debug.Log($"Hash Valid: {info.HashValid}");
Debug.Log($"Decrypted Value: {info.ObscuredValue}");
Debug.Log($"Fake Value: {info.FakeValue}");
}
// Handle the detection - ban player, show warning, etc.
}
// Using with obscured types
public class PlayerData : MonoBehaviour
{
private ObscuredInt playerHealth = 100;
private ObscuredFloat playerScore = 0f;
void Start()
{
// Start detection when using obscured types
ObscuredCheatingDetector.StartDetection(OnCheatingDetected);
}
public void TakeDamage(int damage)
{
playerHealth -= damage;
// If cheater tries to modify playerHealth in memory, detector will catch it
}
public void AddScore(float points)
{
playerScore += points;
// If cheater tries to modify playerScore in memory, detector will catch it
}
private void OnCheatingDetected()
{
Debug.Log("Player tried to cheat with obscured values!");
// Ban player or take other action
}
}
Fields
ComponentName
public const string ComponentName = "Obscured Cheating Detector"
Field Value
- string
doubleEpsilon
Max allowed difference between encrypted and fake values in \link ObscuredTypes.ObscuredDouble ObscuredDouble\endlink. Increase in case of false positives.
[Tooltip("Max allowed difference between encrypted and fake values in ObscuredDouble. Increase in case of false positives.")]
public double doubleEpsilon
Field Value
- double
floatEpsilon
Max allowed difference between encrypted and fake values in \link ObscuredTypes.ObscuredFloat ObscuredFloat\endlink. Increase in case of false positives.
[Tooltip("Max allowed difference between encrypted and fake values in ObscuredFloat. Increase in case of false positives.")]
public float floatEpsilon
Field Value
- float
honeyPot
Creates fake decrypted values for cheaters to find and hack it, triggering cheating attempts detection.
[Tooltip("Creates fake decrypted values for cheaters to find and hack it, triggering cheating attempts detection.\nDisable to make it harder to reveal obscured variables in memory, or keep enabled to catch more casual cheaters.")]
public bool honeyPot
Field Value
- bool
Remarks
Disable to make it harder to reveal obscured variables in memory, or keep enabled to catch more casual cheaters.
quaternionEpsilon
Max allowed difference between encrypted and fake values in \link ObscuredTypes.ObscuredQuaternion ObscuredQuaternion\endlink. Increase in case of false positives.
[Tooltip("Max allowed difference between encrypted and fake values in ObscuredQuaternion. Increase in case of false positives.")]
public float quaternionEpsilon
Field Value
- float
vector2Epsilon
Max allowed difference between encrypted and fake values in \link ObscuredTypes.ObscuredVector2 ObscuredVector2\endlink. Increase in case of false positives.
[Tooltip("Max allowed difference between encrypted and fake values in ObscuredVector2. Increase in case of false positives.")]
public float vector2Epsilon
Field Value
- float
vector3Epsilon
Max allowed difference between encrypted and fake values in \link ObscuredTypes.ObscuredVector3 ObscuredVector3\endlink. Increase in case of false positives.
[Tooltip("Max allowed difference between encrypted and fake values in ObscuredVector3. Increase in case of false positives.")]
public float vector3Epsilon
Field Value
- float
Properties
LastDetectionInfo
Holds detailed information about latest triggered detection.
public ObscuredCheatingDetectionInfo LastDetectionInfo { get; }
Property Value
Remarks
Provides information about which obscured type triggered the detection, including the source type, hash validation status, and the actual vs fake values.
Methods
AddToSceneOrGetExisting()
Creates new instance of the detector at scene if it doesn't exists. Make sure to call NOT from Awake phase.
public static ObscuredCheatingDetector AddToSceneOrGetExisting()
Returns
- ObscuredCheatingDetector
New or existing instance of the detector.
Dispose()
Stops and completely disposes detector component.
public static void Dispose()
Remarks
On dispose Detector follows 2 rules:
- if Game Object's name is "Anti-Cheat Toolkit Detectors": it will be automatically
destroyed if no other Detectors left attached regardless of any other components or children;
- if Game Object's name is NOT "Anti-Cheat Toolkit Detectors": it will be automatically destroyed only if it has neither other components nor children attached;
StartDetection()
Starts all Obscured types cheating detection for detector you have in scene.
public static ObscuredCheatingDetector StartDetection()
Returns
Remarks
Make sure you have properly configured detector in scene with autoStart disabled before using this method.
StartDetection(Action)
Starts all Obscured types cheating detection with specified callback.
public static ObscuredCheatingDetector StartDetection(Action callback)
Parameters
callbackActionMethod to call after detection.
Returns
Remarks
If you have detector in scene make sure it has empty Detection Event.
Creates a new detector instance if it doesn't exists in scene.
StopDetection()
Stops detector. Detector's component remains in the scene. Use Dispose() to completely remove detector.
public static void StopDetection()
TriggerDetection()
Manually triggers cheating detection and invokes assigned events.
[ContextMenu("Trigger detection")]
public void TriggerDetection()
TryDetectCheating<T, TU, TA, T2>(TU, bool, TA, bool, T, T2)
public static void TryDetectCheating<T, TU, TA, T2>(TU type, bool hashValid, TA hash, bool honeypotValid, T real, T2 fake) where TU : IObscuredType
Parameters
typeTUhashValidboolhashTAhoneypotValidboolrealTfakeT2
Type Parameters
TTUTAT2