Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using Oculus.Platform;
- using Oculus.Platform.Models;
- public class AntiCheatMetaQuest : MonoBehaviour
- {
- public float maxAllowedSpeed = 5.0f; // Max speed player can move
- public float maxJumpHeight = 2.5f; // Max height player can jump
- private Vector3 lastPosition;
- private float checkInterval = 1.0f;
- private float timeSinceLastCheck = 0f;
- private float maxVerticalPosition = 10.0f; // Check against flying hacks
- void Start()
- {
- lastPosition = transform.position;
- // Oculus-specific: Check for entitlement (piracy check)
- CheckEntitlement();
- }
- void Update()
- {
- timeSinceLastCheck += Time.deltaTime;
- if (timeSinceLastCheck >= checkInterval)
- {
- CheckPlayerMovement();
- timeSinceLastCheck = 0f;
- }
- }
- void CheckPlayerMovement()
- {
- // Calculate speed and detect teleport or speed hacks
- float distanceMoved = Vector3.Distance(transform.position, lastPosition);
- float playerSpeed = distanceMoved / checkInterval;
- if (playerSpeed > maxAllowedSpeed)
- {
- Debug.LogWarning("Speed hack detected!");
- ApplyPenalty();
- }
- // Check if player exceeds vertical limit (fly hacks)
- if (transform.position.y > maxVerticalPosition)
- {
- Debug.LogWarning("Fly hack detected!");
- ApplyPenalty();
- }
- // Check jump height (for jump manipulation)
- if (transform.position.y - lastPosition.y > maxJumpHeight)
- {
- Debug.LogWarning("Jump hack detected!");
- ApplyPenalty();
- }
- lastPosition = transform.position;
- }
- void ApplyPenalty()
- {
- // Penalty - Slow down player or kick from the game
- Debug.Log("Penalizing player for cheating!");
- GetComponent<PlayerMovement>().movementSpeed = maxAllowedSpeed / 2;
- // Optionally, log the event to a server or record it for admin review
- }
- void CheckEntitlement()
- {
- Entitlements.IsUserEntitledToApplication().OnComplete((Message msg) =>
- {
- if (msg.IsError)
- {
- Debug.LogError("User not entitled. Kicking from the game.");
- // Kick player from the game if not entitled (pirated APK)
- Application.Quit();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement