Class WallHackDetector
Detects common types of wall hack cheating: walking through the walls (Rigidbody and CharacterController modules), shooting through the walls (Raycast module), looking through the walls (Wireframe module).
[AddComponentMenu("Code Stage/Anti-Cheat Toolkit/WallHack Detector")]
[DisallowMultipleComponent]
[HelpURL("https://docs.codestage.net/actk/manual/detectors.html#wallhack-detector")]
public class WallHackDetector : ACTkDetectorBase<WallHackDetector>
- Inheritance
-
objectObjectComponentBehaviourMonoBehaviourWallHackDetector
- Inherited Members
Remarks
In order to work properly, this detector creates and uses some service objects right in the scene.
It places all such objects within 3x3x3 sandbox area which is placed at the spawnPosition and drawn as a red wire cube in
the scene when you select Game Object with this detector.
Please, place this sandbox area at the empty unreachable space of your game to avoid any collisions and false positives.
To get started:
- add detector to any GameObject as usual or through the
GameObject > Create Other > Code Stage > Anti-Cheat Toolkitmenu; - make sure 3x3x3 area at the spawnPosition is unreachable for any objects of your game;
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.
📝 Important Notes:
• Adds new objects to the scene and places them into the "[WH Detector Service]" container at the spawnPosition.
• May use physics and shaders. It may lead to the build size increase and additional resources usage.
// Basic usage - start detection with callback
void Start()
{
WallHackDetector.StartDetection(OnWallHackDetected);
}
private void OnWallHackDetected()
{
Debug.Log("Wall hack detected!");
// Get detailed detection info
Debug.Log($"Detection details: {WallHackDetector.Instance.LastDetectionInfo}");
}
// Advanced usage with specific modules
void Start()
{
var detector = WallHackDetector.AddToSceneOrGetExisting();
// Enable specific detection modules
detector.rigidbodyModule = true; // Detect walking through walls
detector.characterControllerModule = true; // Detect character controller hacks
detector.wireframeModule = true; // Detect wireframe hacks
detector.raycastModule = true; // Detect shooting through walls
detector.StartDetection(OnWallHackDetected);
}
private void OnWallHackDetected()
{
Debug.Log("Wall hack detected!");
// Get detailed detection info
Debug.Log($"Detection details: {WallHackDetector.Instance.LastDetectionInfo}");
}
// Setting up spawn position for the detector
void SetupWallHackDetector()
{
var detector = WallHackDetector.AddToSceneOrGetExisting();
// Set spawn position to an empty area away from gameplay
detector.spawnPosition = new Vector3(1000, 1000, 1000);
// Configure detection settings
detector.rigidbodyModule = true;
detector.wireframeModule = true;
detector.StartDetection(OnWallHackDetected);
}
Fields
ComponentName
public const string ComponentName = "WallHack Detector"
Field Value
- string
maxFalsePositives
Maximum false positives in a row for each detection module before registering a wall hack.
[Tooltip("Maximum false positives in a row for each detection module before registering a wall hack.")]
public byte maxFalsePositives
Field Value
- byte
raycastDelay
Delay between Raycast module checks, from 1 up to 60 secs.
[Tooltip("Delay between Raycast module checks, from 1 up to 60 secs.")]
[Range(1, 60)]
public int raycastDelay
Field Value
- int
spawnPosition
World coordinates of the service container. Please keep in mind it will have different active objects within 3x3x3 cube during gameplay. It should be unreachable for your game objects to avoid collisions and false positives.
[Tooltip("World position of the container for service objects within 3x3x3 cube (drawn as red wire cube in scene).")]
public Vector3 spawnPosition
Field Value
- Vector3
wireframeDelay
Delay between Wireframe module checks, from 1 up to 60 secs.
[Tooltip("Delay between Wireframe module checks, from 1 up to 60 secs.")]
[Range(1, 60)]
public int wireframeDelay
Field Value
- int
Properties
CheckController
Check for the "walk through the walls" kind of cheats made via Character Controller hacks?
public bool CheckController { get; set; }
Property Value
- bool
Remarks
Disable to save some resources if you're not using Character Controllers.
CheckRaycast
Check for the "shoot through the walls" kind of cheats made via Raycast hacks?
public bool CheckRaycast { get; set; }
Property Value
- bool
Remarks
Disable to save some resources in case you don't care about such cheats.
CheckRigidbody
Check for the "walk through the walls" kind of cheats made via Rigidbody hacks?
public bool CheckRigidbody { get; set; }
Property Value
- bool
Remarks
Disable to save some resources if you're not using Rigidbody for characters.
CheckWireframe
Check for the "see through the walls" kind of cheats made via shader or driver hacks (wireframe, color alpha, etc.)?
public bool CheckWireframe { get; set; }
Property Value
- bool
Remarks
Disable to save some resources in case you don't care about such cheats.
📝 Note: Uses specific shader under the hood.
Thus such shader should be included into the build to exist at runtime.
You may easily add or remove shader at the ACTk Settings window (Tools > Code Stage > Anti-Cheat Toolkit > Settings).
You'll see error in logs at runtime if you'll have no needed shader included.
LastDetectionInfo
Holds detailed information about latest triggered detection.
public WallHackDetectionInfo LastDetectionInfo { get; }
Property Value
Remarks
Provides information about which detection module triggered the wall hack detection (Rigidbody, CharacterController, Wireframe, or Raycast).
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 WallHackDetector AddToSceneOrGetExisting()
Returns
- WallHackDetector
New or existing instance of the detector.
Dispose()
Stops and completely disposes detector component and destroys Service Container as well.
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 detection for detector you have in scene.
public static WallHackDetector StartDetection()
Returns
Remarks
Make sure you have properly configured detector in scene with autoStart disabled before using this method.
StartDetection(Action)
Starts detection with specified callback.
public static WallHackDetector 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.
StartDetection(Action, Vector3)
Starts detection with specified callback using passed spawnPosition.
public static WallHackDetector StartDetection(Action callback, Vector3 spawnPosition)
Parameters
callbackActionMethod to call after detection.
spawnPositionVector3World position of the service 3x3x3 container. Overrides spawnPosition property.
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.
StartDetection(Action, Vector3, byte)
Starts detection with specified callback using passed spawnPosition and maxFalsePositives.
public static WallHackDetector StartDetection(Action callback, Vector3 spawnPosition, byte maxFalsePositives)
Parameters
callbackActionMethod to call after detection.
spawnPositionVector3World position of the service 3x3x3 container. Overrides spawnPosition property.
maxFalsePositivesbyteAmount of possible false positives in a row before registering detection. Overrides maxFalsePositives property.
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()