67
A downloadable game
using UnityEngine;
public class AntiCheatManager : MonoBehaviour
{
void Start()
{
// Only run these checks on an actual Android/Quest build
#if UNITY_ANDROID && !UNITY_EDITOR
CheckForUnauthorizedTools();
#endif
}
void CheckForUnauthorizedTools()
{
bool isThreatDetected = false;
// 1. Check if ADB (Android Debug Bridge) or USB/Wireless Debugging is active
if (IsDebugModeActive())
{
Debug.LogWarning("Security Violation: Debugging tools are active.");
isThreatDetected = true;
}
// 2. Optional: Check for common root/exploit indicators in the system properties
if (IsDeviceRooted())
{
Debug.LogWarning("Security Violation: Device integrity compromised.");
isThreatDetected = true;
}
// Action: If a threat is found, close the game immediately
if (isThreatDetected)
{
ForceQuitGame();
}
}
bool IsDebugModeActive()
{
try
{
using (AndroidJavaClass contextClass = new AndroidJavaClass("android.provider.Settings$Secure"))
{
using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
using (AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
{
using (AndroidJavaObject contentResolver = currentActivity.Call<AndroidJavaObject>("getContentResolver"))
{
// Checks "adb_enabled". Returns 1 if active, 0 if inactive.
int adbEnabled = contextClass.CallStatic<int>("getInt", contentResolver, "adb_enabled", 0);
return adbEnabled > 0;
}
}
}
}
}
catch (System.Exception e)
{
Debug.LogError("Failed to read system debug settings: " + e.Message);
return false;
}
}
bool IsDeviceRooted()
{
// Checks system properties for a "test-keys" tag, which indicates a custom/rooted operating system image
try
{
string buildTags = System.Environment.GetEnvironmentVariable("ro.build.tags");
if (buildTags != null && buildTags.Contains("test-keys"))
{
return true;
}
}
catch {}
return false;
}
void ForceQuitGame()
{
// Closes the application immediately on standalone builds
Application.Quit();
}
}
Leave a comment
Log in with itch.io to leave a comment.