Android - Device Cheating - Detector (Pro)
Not only can a user modify or manipulate your game or app, but they can also try to gain an advantage by making changes to their device. For example, by installing cheat engine apps that try to manipulate the device's or game's memory and gain advantages.
Because these types of apps are typically installed on a user's device their installation cannot be prevented. However, it is possible to identify which apps a user has installed and respond accordingly.
Detector
Use the 'AndroidDeviceCheatingDetector' to detect unwanted installed apps. It monitors the 'AndroidInstalledApplicationMonitor' and subscribes to the installed apps found. The detector enables you to do a comparison with a number of unwanted apps and notifies the observers of the detection. This gives you the opportunity to react to those.
Observed Subject
The detector observes the 'IAndroidStatus' interface sent by:
- AndroidInstalledApplicationMonitor: Determines the installed apps on the device and notifies observers.
Detector Status
The detector receives the installed apps by its package name and compares them to your expected values. For example you can disallow specific apps like cheating apps on the users device and react accordingly to found ones. The expected values can be assigned in the 'AntiCheat-Settings', described in the next chapters. If unexpected or unallowed apps were detected, the detector notifies its observers with a 'AndroidCheatingDetectionStatus'. The status contains the following properties:
- PossibilityOfFalsePositive: A value indicating the possibility of a false positive when assessing threats for the implementing subject from 0.0 to 1.0.
- ThreatRating: The threat rating associated with the detected cheating, indicating the assessed level of a potential threat.
- AndroidCheatingType: The type of cheating detected on the Android device.
- MonitorFailedToRetrieveData: If the monitor notifing the detector failed to retrieve its data or an exception occurred while retrieving the data over the native interface. So no valid value was returned and no validation could be performed by the detector. Mostly the cause is that parts of the native implementation are not available on the current Android device, because an older sdk was used.
The 'AndroidCheatingType' property can take the following values:
- DEVICE_INSTALLED_APPS: The device has installed apps that are not allowed.
Supported Platforms
The detector is only available on Android platforms.
Requirements
Requires an Android build with at least Android 4.4 (API level 19) (December 2013).
How To Use
The usage is quite simple, attach a 'AndroidInstalledApplicationMonitor' (if not already done) and the 'AndroidDeviceCheatingDetector' to a child GameObject of the 'AntiCheat-Monitor', enter the unwanted apps in the 'AntiCheat-Project Settings' and define a reaction on detection of those.
Requirements
To detect unwanted installed apps, you need to add the 'AndroidInstalledApplicationMonitor' to the same GameObject you will attach the 'AndroidDeviceCheatingDetector' to. The detector will subscribe to the 'AndroidInstalledApplicationStatus', containing the installed app package names, send by the monitor.
Add Detector Component
Manual
Add the 'AndroidDeviceCheatingDetector' MonoBehavior from the 'GUPS.AntiCheat.Detector.Android' namespace to your 'AntiCheat-Monitor' GameObject or better to a child GameObject, next to your 'AndroidInstalledApplicationMonitor' MonoBehavior.
Add the 'AndroidDeviceCheatingDetector' as Component.
Prefab
There is also a prefab, including the detector and the monitors, which you can directly attach as a GameObject to the 'AntiCheat-Monitor'.
Add the 'Android Device Cheating Detector' prefab to the 'AntiCheat-Monitor'.
Settings
After attaching the 'AndroidDeviceCheatingDetector' MonoBehavior to a GameObject, you will see the following in the inspector:
The settings of the 'AndroidDeviceCheatingDetector' Component.
General Settings: Define here if the detector should be active.
Threat Rating Settings: Define here the severity of the detected cheating.
Observable Settings: Add here callbacks invoken when a cheating got detected.
Runtime
On the Awake callback the detector observes the 'AndroidInstalledApplicationMonitor' and subscribes to the installed apps found. The detector enables you to do a comparison with a number of unwanted apps and notifies the observers of the detection. This gives you the opportunity to react to those.
Define Unwanted Apps
To define the unwanted apps you have to enter their package names in the global 'AntiCheat-Project Settings'. Do do so, go to 'Project Settings -> GuardingPearSoftware -> AntiCheat'. Go to the section 'Android - Device App - Settings'. Activate the 'Blacklist device apps' checkbox and enter the package names of the apps you want to detect.
In the AntiCheat Project Settings assign the package names of the unwanted (blacklisted) apps.
In the image shown, you can see two examples of package names:
- "com.cheating.app": Some demo package name to show possible input values.
- "catch_.me_.if_.you_.can_": The package name of the general cheating app "GameGuardian".
So if a user runs your app, the detector will react to any installed app with the entered package names. In the image case, this would be "com.cheating.app" and "catch_.me_.if_.you_.can_".
React On Cheating
When the monitor (data provider) and detector (data validator) are set up, you sure want to react on detected cheating.
Punisher
In general, any cheat detected is forwarded to the 'AntiCheat-Monitor', which calculates an overall threat level. Based on the threat level, you can apply punishments by using Punisher components added to a child GameObject of the 'AntiCheat-Monitor'. There are some built-in punishers that you can find here as prefabs:
The location of the built-in Punisher prefabs.
Inspector
You can set a callback in the Unity Inspector view of the detector. This callback is invoken as soon as the specific cheating is detected.
A list of callbacks invoken when cheating got detected from the detector.
Code
If you would like to write a custom listener to the detector, you can attach an observer:
// Get the detector.
var detector = AntiCheatMonitor.Instance
.GetDetector<AndroidDeviceCheatingDetector>();
// Subscribe as observer and get notified on inconsistency.
detector.Subscribe(myObserver);
Also the detector has an inherited property 'PossibleCheatingDetected' which is set to true once a cheating got detected.