Advertisement
Hygcgggnngff

anti cheat do not leak

Sep 28th, 2024
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. using UnityEngine;
  2. using Oculus.Platform;
  3. using Oculus.Platform.Models;
  4.  
  5. public class AntiCheatMetaQuest : MonoBehaviour
  6. {
  7. public float maxAllowedSpeed = 5.0f; // Max speed player can move
  8. public float maxJumpHeight = 2.5f; // Max height player can jump
  9. private Vector3 lastPosition;
  10. private float checkInterval = 1.0f;
  11. private float timeSinceLastCheck = 0f;
  12. private float maxVerticalPosition = 10.0f; // Check against flying hacks
  13.  
  14. void Start()
  15. {
  16. lastPosition = transform.position;
  17.  
  18. // Oculus-specific: Check for entitlement (piracy check)
  19. CheckEntitlement();
  20. }
  21.  
  22. void Update()
  23. {
  24. timeSinceLastCheck += Time.deltaTime;
  25.  
  26. if (timeSinceLastCheck >= checkInterval)
  27. {
  28. CheckPlayerMovement();
  29. timeSinceLastCheck = 0f;
  30. }
  31. }
  32.  
  33. void CheckPlayerMovement()
  34. {
  35. // Calculate speed and detect teleport or speed hacks
  36. float distanceMoved = Vector3.Distance(transform.position, lastPosition);
  37. float playerSpeed = distanceMoved / checkInterval;
  38.  
  39. if (playerSpeed > maxAllowedSpeed)
  40. {
  41. Debug.LogWarning("Speed hack detected!");
  42. ApplyPenalty();
  43. }
  44.  
  45. // Check if player exceeds vertical limit (fly hacks)
  46. if (transform.position.y > maxVerticalPosition)
  47. {
  48. Debug.LogWarning("Fly hack detected!");
  49. ApplyPenalty();
  50. }
  51.  
  52. // Check jump height (for jump manipulation)
  53. if (transform.position.y - lastPosition.y > maxJumpHeight)
  54. {
  55. Debug.LogWarning("Jump hack detected!");
  56. ApplyPenalty();
  57. }
  58.  
  59. lastPosition = transform.position;
  60. }
  61.  
  62. void ApplyPenalty()
  63. {
  64. // Penalty - Slow down player or kick from the game
  65. Debug.Log("Penalizing player for cheating!");
  66. GetComponent<PlayerMovement>().movementSpeed = maxAllowedSpeed / 2;
  67.  
  68. // Optionally, log the event to a server or record it for admin review
  69. }
  70.  
  71. void CheckEntitlement()
  72. {
  73. Entitlements.IsUserEntitledToApplication().OnComplete((Message msg) =>
  74. {
  75. if (msg.IsError)
  76. {
  77. Debug.LogError("User not entitled. Kicking from the game.");
  78. // Kick player from the game if not entitled (pirated APK)
  79. Application.Quit();
  80. }
  81. });
  82. }
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement