Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // HyperionAnticheat.h - Core header for Hyperion Anticheat System
- #pragma once
- #include <vector>
- #include <memory>
- #include <string>
- #include <unordered_map>
- #include <functional>
- #include <chrono>
- #include <thread>
- #include <mutex>
- #include <atomic>
- #include <queue>
- #include <random>
- namespace Hyperion {
- // Forward declarations
- class Entity;
- class Player;
- class Server;
- class Module;
- class GameInstance;
- class DetectionEvent;
- // Detection severity levels
- enum class DetectionSeverity {
- INFO, // Suspicious but not necessarily malicious
- WARNING, // Likely malicious but with potential false positives
- CRITICAL // Almost certainly malicious with minimal false positive risk
- };
- // Detection categories
- enum class DetectionCategory {
- SPEED_HACK,
- TELEPORT_HACK,
- FLY_HACK,
- NOCLIP_HACK,
- ANIMATION_EXPLOIT,
- WEAPON_EXPLOIT,
- SERVER_CRASH_ATTEMPT,
- MEMORY_MANIPULATION,
- CLIENT_INTEGRITY,
- INJECTION,
- PACKET_MANIPULATION,
- SUSPICIOUS_BEHAVIOR
- };
- // Vector and transformation classes
- struct Vec2 {
- float x, y;
- Vec2() : x(0.0f), y(0.0f) {}
- Vec2(float _x, float _y) : x(_x), y(_y) {}
- float Length() const;
- Vec2 Normalized() const;
- // Additional vector operations...
- };
- struct Vec3 {
- float x, y, z;
- Vec3() : x(0.0f), y(0.0f), z(0.0f) {}
- Vec3(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {}
- float Length() const;
- Vec3 Normalized() const;
- float DistanceTo(const Vec3& other) const;
- // Additional vector operations...
- };
- // Base component class
- class Component {
- public:
- Component(Entity* owner) : m_Owner(owner), m_IsActive(true) {}
- virtual ~Component() = default;
- virtual void Initialize() {}
- virtual void Update(float deltaTime) {}
- virtual void Shutdown() {}
- bool IsActive() const { return m_IsActive; }
- void SetActive(bool active) { m_IsActive = active; }
- Entity* GetOwner() const { return m_Owner; }
- protected:
- Entity* m_Owner;
- bool m_IsActive;
- };
- // Entity class (represents players, objects, etc.)
- class Entity {
- public:
- Entity(const std::string& name, uint64_t id);
- ~Entity();
- void Update(float deltaTime);
- const std::string& GetName() const { return m_Name; }
- uint64_t GetID() const { return m_EntityID; }
- const Vec3& GetPosition() const { return m_Position; }
- void SetPosition(const Vec3& position);
- const Vec3& GetRotation() const { return m_Rotation; }
- void SetRotation(const Vec3& rotation);
- const Vec3& GetScale() const { return m_Scale; }
- void SetScale(const Vec3& scale);
- const Vec3& GetVelocity() const { return m_Velocity; }
- void SetVelocity(const Vec3& velocity);
- template<typename T, typename... Args>
- T* AddComponent(Args&&... args) {
- static_assert(std::is_base_of<Component, T>::value, "T must derive from Component");
- auto component = std::make_unique<T>(this, std::forward<Args>(args)...);
- T* componentPtr = component.get();
- m_Components.push_back(std::move(component));
- componentPtr->Initialize();
- return componentPtr;
- }
- template<typename T>
- T* GetComponent() const {
- for (const auto& component : m_Components) {
- if (auto derivedComponent = dynamic_cast<T*>(component.get())) {
- return derivedComponent;
- }
- }
- return nullptr;
- }
- private:
- std::string m_Name;
- uint64_t m_EntityID;
- Vec3 m_Position;
- Vec3 m_Rotation;
- Vec3 m_Scale;
- Vec3 m_Velocity;
- std::vector<std::unique_ptr<Component>> m_Components;
- };
- // Player class (extends Entity)
- class Player : public Entity {
- public:
- Player(const std::string& name, uint64_t id, uint64_t userID);
- uint64_t GetUserID() const { return m_UserID; }
- float GetLastMovementTime() const { return m_LastMovementTime; }
- void SetLastMovementTime(float time) { m_LastMovementTime = time; }
- const std::unordered_map<std::string, float>& GetMovementStats() const { return m_MovementStats; }
- void SetMovementStat(const std::string& stat, float value) { m_MovementStats[stat] = value; }
- float GetMovementStat(const std::string& stat) const;
- void AddDetection(DetectionCategory category, DetectionSeverity severity, const std::string& reason);
- void ClearDetections();
- int GetViolationCount() const { return m_ViolationCount; }
- int GetViolationScore() const { return m_ViolationScore; }
- void Ban(const std::string& reason, int durationMinutes = 0);
- void Kick(const std::string& reason);
- bool IsBanned() const { return m_IsBanned; }
- private:
- uint64_t m_UserID;
- float m_LastMovementTime;
- std::unordered_map<std::string, float> m_MovementStats;
- int m_ViolationCount;
- int m_ViolationScore;
- std::vector<DetectionEvent> m_Detections;
- bool m_IsBanned;
- std::string m_BanReason;
- std::chrono::time_point<std::chrono::system_clock> m_BanExpiration;
- };
- // Detection event class
- class DetectionEvent {
- public:
- DetectionEvent(
- Player* player,
- DetectionCategory category,
- DetectionSeverity severity,
- const std::string& reason,
- std::chrono::system_clock::time_point timestamp
- );
- Player* GetPlayer() const { return m_Player; }
- DetectionCategory GetCategory() const { return m_Category; }
- DetectionSeverity GetSeverity() const { return m_Severity; }
- const std::string& GetReason() const { return m_Reason; }
- std::chrono::system_clock::time_point GetTimestamp() const { return m_Timestamp; }
- std::string ToString() const;
- private:
- Player* m_Player;
- DetectionCategory m_Category;
- DetectionSeverity m_Severity;
- std::string m_Reason;
- std::chrono::system_clock::time_point m_Timestamp;
- };
- // Base module class for anticheat functionality
- class Module {
- public:
- Module(const std::string& name);
- virtual ~Module() = default;
- virtual void Initialize() = 0;
- virtual void Update(float deltaTime) = 0;
- virtual void Shutdown() = 0;
- const std::string& GetName() const { return m_Name; }
- bool IsEnabled() const { return m_Enabled; }
- void SetEnabled(bool enabled) { m_Enabled = enabled; }
- protected:
- std::string m_Name;
- bool m_Enabled;
- };
- // Specific anticheat modules
- class SpeedHackDetector : public Module {
- public:
- SpeedHackDetector();
- void Initialize() override;
- void Update(float deltaTime) override;
- void Shutdown() override;
- void SetMaxSpeed(float maxSpeed) { m_MaxSpeed = maxSpeed; }
- float GetMaxSpeed() const { return m_MaxSpeed; }
- void SetTeleportThreshold(float threshold) { m_TeleportThreshold = threshold; }
- float GetTeleportThreshold() const { return m_TeleportThreshold; }
- private:
- float m_MaxSpeed;
- float m_TeleportThreshold;
- float m_DetectionCooldown;
- std::unordered_map<uint64_t, std::chrono::system_clock::time_point> m_LastDetections;
- };
- class FlyHackDetector : public Module {
- public:
- FlyHackDetector();
- void Initialize() override;
- void Update(float deltaTime) override;
- void Shutdown() override;
- void SetMaxAirTime(float maxAirTime) { m_MaxAirTime = maxAirTime; }
- float GetMaxAirTime() const { return m_MaxAirTime; }
- private:
- float m_MaxAirTime;
- float m_GravityThreshold;
- std::unordered_map<uint64_t, float> m_PlayerAirTime;
- };
- class ClientIntegrityChecker : public Module {
- public:
- ClientIntegrityChecker();
- void Initialize() override;
- void Update(float deltaTime) override;
- void Shutdown() override;
- void AddHashCheck(const std::string& filename, const std::string& expectedHash);
- void PerformClientCheck(Player* player);
- private:
- struct HashCheck {
- std::string filename;
- std::string expectedHash;
- };
- std::vector<HashCheck> m_HashChecks;
- float m_CheckInterval;
- float m_TimeUntilNextCheck;
- };
- // Main Hyperion Engine class
- class Engine {
- public:
- static Engine* GetInstance();
- bool Initialize(const std::string& gameName, int maxPlayers);
- void Shutdown();
- void Update();
- void SetTickRate(int tickRate) { m_TickRate = tickRate; }
- int GetTickRate() const { return m_TickRate; }
- template<typename T, typename... Args>
- T* RegisterModule(Args&&... args) {
- static_assert(std::is_base_of<Module, T>::value, "T must derive from Module");
- auto module = std::make_unique<T>(std::forward<Args>(args)...);
- T* modulePtr = module.get();
- m_Modules.push_back(std::move(module));
- if (IsInitialized()) {
- modulePtr->Initialize();
- }
- return modulePtr;
- }
- template<typename T>
- T* GetModule() const {
- for (const auto& module : m_Modules) {
- if (auto derivedModule = dynamic_cast<T*>(module.get())) {
- return derivedModule;
- }
- }
- return nullptr;
- }
- void AddPlayer(std::shared_ptr<Player> player);
- void RemovePlayer(uint64_t playerID);
- std::shared_ptr<Player> GetPlayer(uint64_t playerID) const;
- const std::vector<std::shared_ptr<Player>>& GetPlayers() const { return m_Players; }
- void LogDetection(Player* player, DetectionCategory category, DetectionSeverity severity, const std::string& reason);
- const std::vector<DetectionEvent>& GetDetectionLog() const { return m_DetectionLog; }
- void EnableModule(const std::string& moduleName, bool enabled = true);
- bool IsModuleEnabled(const std::string& moduleName) const;
- private:
- Engine();
- ~Engine();
- static Engine* s_Instance;
- bool m_IsInitialized;
- std::string m_GameName;
- int m_MaxPlayers;
- int m_TickRate;
- std::vector<std::unique_ptr<Module>> m_Modules;
- std::vector<std::shared_ptr<Player>> m_Players;
- std::vector<DetectionEvent> m_DetectionLog;
- std::thread m_UpdateThread;
- std::atomic<bool> m_StopUpdateThread;
- std::mutex m_PlayersMutex;
- std::mutex m_LogMutex;
- };
- // Configuration manager
- class ConfigManager {
- public:
- static ConfigManager* GetInstance();
- bool LoadConfig(const std::string& filename);
- bool SaveConfig(const std::string& filename) const;
- template<typename T>
- void SetValue(const std::string& key, const T& value);
- template<typename T>
- T GetValue(const std::string& key, const T& defaultValue) const;
- private:
- ConfigManager();
- ~ConfigManager();
- static ConfigManager* s_Instance;
- std::unordered_map<std::string, std::string> m_ConfigValues;
- };
- // Network packet analyzer
- class PacketAnalyzer {
- public:
- using PacketCallback = std::function<void(const void*, size_t, bool)>;
- static PacketAnalyzer* GetInstance();
- void Initialize();
- void Shutdown();
- void RegisterCallback(const std::string& name, PacketCallback callback);
- void UnregisterCallback(const std::string& name);
- void ProcessIncomingPacket(Player* sender, const void* data, size_t size);
- void ProcessOutgoingPacket(Player* recipient, const void* data, size_t size);
- void EnablePacketValidation(bool enabled) { m_ValidatePackets = enabled; }
- bool IsPacketValidationEnabled() const { return m_ValidatePackets; }
- private:
- PacketAnalyzer();
- ~PacketAnalyzer();
- static PacketAnalyzer* s_Instance;
- bool m_Initialized;
- bool m_ValidatePackets;
- std::unordered_map<std::string, PacketCallback> m_Callbacks;
- };
- // Utility functions
- namespace Utils {
- std::string GenerateRandomToken(size_t length);
- std::string HashString(const std::string& input);
- bool VerifyHash(const std::string& input, const std::string& hash);
- std::string EncryptData(const std::string& data, const std::string& key);
- std::string DecryptData(const std::string& encryptedData, const std::string& key);
- }
- } // namespace Hyperion
- // HyperionImplementation.cpp - Main implementation file
- #include "HyperionAnticheat.h"
- #include <iostream>
- #include <algorithm>
- #include <fstream>
- #include <sstream>
- #include <iomanip>
- #include <ctime>
- namespace Hyperion {
- // Initialize static members
- Engine* Engine::s_Instance = nullptr;
- ConfigManager* ConfigManager::s_Instance = nullptr;
- PacketAnalyzer* PacketAnalyzer::s_Instance = nullptr;
- // Vector implementations
- float Vec2::Length() const {
- return std::sqrt(x * x + y * y);
- }
- Vec2 Vec2::Normalized() const {
- float len = Length();
- if (len < 0.0001f) return Vec2(0.0f, 0.0f);
- return Vec2(x / len, y / len);
- }
- float Vec3::Length() const {
- return std::sqrt(x * x + y * y + z * z);
- }
- Vec3 Vec3::Normalized() const {
- float len = Length();
- if (len < 0.0001f) return Vec3(0.0f, 0.0f, 0.0f);
- return Vec3(x / len, y / len, z / len);
- }
- float Vec3::DistanceTo(const Vec3& other) const {
- float dx = x - other.x;
- float dy = y - other.y;
- float dz = z - other.z;
- return std::sqrt(dx * dx + dy * dy + dz * dz);
- }
- // Entity implementation
- Entity::Entity(const std::string& name, uint64_t id)
- : m_Name(name), m_EntityID(id),
- m_Position(0.0f, 0.0f, 0.0f),
- m_Rotation(0.0f, 0.0f, 0.0f),
- m_Scale(1.0f, 1.0f, 1.0f),
- m_Velocity(0.0f, 0.0f, 0.0f) {
- }
- Entity::~Entity() {
- for (auto& component : m_Components) {
- component->Shutdown();
- }
- m_Components.clear();
- }
- void Entity::Update(float deltaTime) {
- for (auto& component : m_Components) {
- if (component->IsActive()) {
- component->Update(deltaTime);
- }
- }
- }
- void Entity::SetPosition(const Vec3& position) {
- m_Position = position;
- }
- void Entity::SetRotation(const Vec3& rotation) {
- m_Rotation = rotation;
- }
- void Entity::SetScale(const Vec3& scale) {
- m_Scale = scale;
- }
- void Entity::SetVelocity(const Vec3& velocity) {
- m_Velocity = velocity;
- }
- // Player implementation
- Player::Player(const std::string& name, uint64_t id, uint64_t userID)
- : Entity(name, id), m_UserID(userID),
- m_LastMovementTime(0.0f),
- m_ViolationCount(0), m_ViolationScore(0),
- m_IsBanned(false) {
- }
- float Player::GetMovementStat(const std::string& stat) const {
- auto it = m_MovementStats.find(stat);
- if (it != m_MovementStats.end()) {
- return it->second;
- }
- return 0.0f;
- }
- void Player::AddDetection(DetectionCategory category, DetectionSeverity severity, const std::string& reason) {
- int severityScore = 0;
- switch (severity) {
- case DetectionSeverity::INFO:
- severityScore = 1;
- break;
- case DetectionSeverity::WARNING:
- severityScore = 5;
- break;
- case DetectionSeverity::CRITICAL:
- severityScore = 25;
- break;
- }
- m_ViolationCount++;
- m_ViolationScore += severityScore;
- auto now = std::chrono::system_clock::now();
- m_Detections.emplace_back(this, category, severity, reason, now);
- Engine::GetInstance()->LogDetection(this, category, severity, reason);
- }
- void Player::ClearDetections() {
- m_Detections.clear();
- m_ViolationCount = 0;
- m_ViolationScore = 0;
- }
- void Player::Ban(const std::string& reason, int durationMinutes) {
- m_IsBanned = true;
- m_BanReason = reason;
- if (durationMinutes > 0) {
- m_BanExpiration = std::chrono::system_clock::now() + std::chrono::minutes(durationMinutes);
- } else {
- // Permanent ban
- m_BanExpiration = std::chrono::system_clock::time_point::max();
- }
- // Log the ban action
- std::cout << "BANNED player " << GetName() << " (ID: " << GetUserID()
- << ") for: " << reason << std::endl;
- // Kick the player
- Kick("You have been banned: " + reason);
- }
- void Player::Kick(const std::string& reason) {
- std::cout << "KICKED player " << GetName() << " (ID: " << GetUserID()
- << ") for: " << reason << std::endl;
- // In a real implementation, this would disconnect the player
- }
- // Detection event implementation
- DetectionEvent::DetectionEvent(
- Player* player,
- DetectionCategory category,
- DetectionSeverity severity,
- const std::string& reason,
- std::chrono::system_clock::time_point timestamp
- ) : m_Player(player),
- m_Category(category),
- m_Severity(severity),
- m_Reason(reason),
- m_Timestamp(timestamp) {
- }
- std::string DetectionEvent::ToString() const {
- // Convert timestamp to string
- auto timeT = std::chrono::system_clock::to_time_t(m_Timestamp);
- std::stringstream ss;
- ss << std::put_time(std::localtime(&timeT), "%Y-%m-%d %H:%M:%S");
- // Severity string
- std::string severityStr;
- switch (m_Severity) {
- case DetectionSeverity::INFO:
- severityStr = "INFO";
- break;
- case DetectionSeverity::WARNING:
- severityStr = "WARNING";
- break;
- case DetectionSeverity::CRITICAL:
- severityStr = "CRITICAL";
- break;
- }
- // Category string
- std::string categoryStr;
- switch (m_Category) {
- case DetectionCategory::SPEED_HACK:
- categoryStr = "SPEED_HACK";
- break;
- case DetectionCategory::TELEPORT_HACK:
- categoryStr = "TELEPORT_HACK";
- break;
- case DetectionCategory::FLY_HACK:
- categoryStr = "FLY_HACK";
- break;
- case DetectionCategory::NOCLIP_HACK:
- categoryStr = "NOCLIP_HACK";
- break;
- case DetectionCategory::ANIMATION_EXPLOIT:
- categoryStr = "ANIMATION_EXPLOIT";
- break;
- case DetectionCategory::WEAPON_EXPLOIT:
- categoryStr = "WEAPON_EXPLOIT";
- break;
- case DetectionCategory::SERVER_CRASH_ATTEMPT:
- categoryStr = "SERVER_CRASH_ATTEMPT";
- break;
- case DetectionCategory::MEMORY_MANIPULATION:
- categoryStr = "MEMORY_MANIPULATION";
- break;
- case DetectionCategory::CLIENT_INTEGRITY:
- categoryStr = "CLIENT_INTEGRITY";
- break;
- case DetectionCategory::INJECTION:
- categoryStr = "INJECTION";
- break;
- case DetectionCategory::PACKET_MANIPULATION:
- categoryStr = "PACKET_MANIPULATION";
- break;
- case DetectionCategory::SUSPICIOUS_BEHAVIOR:
- categoryStr = "SUSPICIOUS_BEHAVIOR";
- break;
- }
- // Format the detection event string
- return ss.str() + " [" + severityStr + "] " + categoryStr + " - " +
- m_Player->GetName() + " (ID: " + std::to_string(m_Player->GetUserID()) +
- "): " + m_Reason;
- }
- // Module implementation
- Module::Module(const std::string& name)
- : m_Name(name), m_Enabled(true) {
- }
- // SpeedHackDetector implementation
- SpeedHackDetector::SpeedHackDetector()
- : Module("SpeedHackDetector"),
- m_MaxSpeed(50.0f),
- m_TeleportThreshold(100.0f),
- m_DetectionCooldown(5.0f) {
- }
- void SpeedHackDetector::Initialize() {
- std::cout << "Initializing SpeedHackDetector module" << std::endl;
- // Load configuration
- auto config = ConfigManager::GetInstance();
- m_MaxSpeed = config->GetValue<float>("speedhack_max_speed", 50.0f);
- m_TeleportThreshold = config->GetValue<float>("speedhack_teleport_threshold", 100.0f);
- m_DetectionCooldown = config->GetValue<float>("speedhack_detection_cooldown", 5.0f);
- }
- void SpeedHackDetector::Update(float deltaTime) {
- if (!m_Enabled) return;
- auto engine = Engine::GetInstance();
- auto now = std::chrono::system_clock::now();
- for (const auto& playerPtr : engine->GetPlayers()) {
- Player* player = playerPtr.get();
- // Skip detection if on cooldown
- auto it = m_LastDetections.find(player->GetID());
- if (it != m_LastDetections.end()) {
- auto elapsedTime = std::chrono::duration_cast<std::chrono::seconds>(now - it->second).count();
- if (elapsedTime < m_DetectionCooldown) {
- continue;
- }
- }
- const Vec3& velocity = player->GetVelocity();
- float speed = velocity.Length();
- // Check for excessive speed
- if (speed > m_MaxSpeed) {
- std::string reason = "Speed exceeds maximum allowed (" +
- std::to_string(speed) + " > " +
- std::to_string(m_MaxSpeed) + ")";
- player->AddDetection(DetectionCategory::SPEED_HACK,
- DetectionSeverity::WARNING,
- reason);
- m_LastDetections[player->GetID()] = now;
- }
- // Check for teleport (sudden position change)
- Vec3 lastPosition = Vec3(
- player->GetMovementStat("last_position_x"),
- player->GetMovementStat("last_position_y"),
- player->GetMovementStat("last_position_z")
- );
- const Vec3& currentPosition = player->GetPosition();
- float distance = lastPosition.DistanceTo(currentPosition);
- // Only check if we have a valid last position
- if (lastPosition.Length() > 0.01f &&
- distance > m_TeleportThreshold &&
- player->GetLastMovementTime() > 0.0f) {
- float timeDiff = deltaTime;
- if (timeDiff > 0.0001f) {
- float impliedSpeed = distance / timeDiff;
- if (impliedSpeed > m_MaxSpeed * 2.0f) {
- std::string reason = "Possible teleport detected (" +
- std::to_string(distance) + " units in " +
- std::to_string(timeDiff) + " seconds)";
- player->AddDetection(DetectionCategory::TELEPORT_HACK,
- DetectionSeverity::WARNING,
- reason);
- m_LastDetections[player->GetID()] = now;
- }
- }
- }
- // Update last position
- player->SetMovementStat("last_position_x", currentPosition.x);
- player->SetMovementStat("last_position_y", currentPosition.y);
- player->SetMovementStat("last_position_z", currentPosition.z);
- player->SetLastMovementTime(player->GetLastMovementTime() + deltaTime);
- }
- }
- void SpeedHackDetector::Shutdown() {
- std::cout << "Shutting down SpeedHackDetector module" << std::endl;
- }
- // FlyHackDetector implementation
- FlyHackDetector::FlyHackDetector()
- : Module("FlyHackDetector"),
- m_MaxAirTime(5.0f),
- m_GravityThreshold(0.1f) {
- }
- void FlyHackDetector::Initialize() {
- std::cout << "Initializing FlyHackDetector module" << std::endl;
- // Load configuration
- auto config = ConfigManager::GetInstance();
- m_MaxAirTime = config->GetValue<float>("flyhack_max_air_time", 5.0f);
- m_GravityThreshold = config->GetValue<float>("flyhack_gravity_threshold", 0.1f);
- }
- void FlyHackDetector::Update(float deltaTime) {
- if (!m_Enabled) return;
- auto engine = Engine::GetInstance();
- for (const auto& playerPtr : engine->GetPlayers()) {
- Player* player = playerPtr.get();
- bool isGrounded = player->GetMovementStat("is_grounded") > 0.5f;
- if (!isGrounded) {
- // Player is in the air
- float airTime = 0.0f;
- auto it = m_PlayerAirTime.find(player->GetID());
- if (it != m_PlayerAirTime.end()) {
- airTime = it->second;
- }
- airTime += deltaTime;
- m_PlayerAirTime[player->GetID()] = airTime;
- // Check for excessive air time
- if (airTime > m_MaxAirTime) {
- std::string reason = "Excessive air time detected (" +
- std::to_string(airTime) + " seconds)";
- player->AddDetection(DetectionCategory::FLY_HACK,
- DetectionSeverity::WARNING,
- reason);
- // Reset air time to avoid spam
- m_PlayerAirTime[player->GetID()] = 0.0f;
- }
- // Check if player is ignoring gravity
- const Vec3& velocity = player->GetVelocity();
- float verticalVelocity = velocity.y;
- float prevVerticalVelocity = player->GetMovementStat("prev_vertical_velocity");
- if (std::abs(verticalVelocity - prevVerticalVelocity) < m_GravityThreshold && airTime > 1.0f) {
- std::string reason = "Possible gravity manipulation detected (vertical velocity: " +
- std::to_string(verticalVelocity) + ")";
- player->AddDetection(DetectionCategory::FLY_HACK,
- DetectionSeverity::WARNING,
- reason);
- }
- // Store current vertical velocity for next update
- player->SetMovementStat("prev_vertical_velocity", verticalVelocity);
- } else {
- // Player is grounded, reset air time
- m_PlayerAirTime[player->GetID()] = 0.0f;
- }
- }
- }
- void FlyHackDetector::Shutdown() {
- std::cout << "Shutting down FlyHackDetector module" << std::endl;
- }
- // ClientIntegrityChecker implementation
- ClientIntegrityChecker::ClientIntegrityChecker()
- : Module("ClientIntegrityChecker"),
- m_CheckInterval(300.0f), // Check every 5 minutes
- m_TimeUntilNextCheck(30.0f) { // First check after 30 seconds
- }
- void ClientIntegrityChecker::Initialize() {
- std::cout << "Initializing ClientIntegrityChecker module" << std::endl;
- // Load configuration
- auto config = ConfigManager::GetInstance();
- m_CheckInterval = config->GetValue<float>("integrity_check_interval", 300.0f);
- // Initialize default hash checks
- AddHashCheck("client_core.dll", "a1b2c3d4e5f6g7h8i9j0");
- AddHashCheck("game_module.dll", "1a2b3c4d5e6f7g8h9i0j");
- AddHashCheck("physics_engine.dll", "2a3b4c5d6e7f8g9h0i1j");
- }
- void ClientIntegrityChecker::Update(float deltaTime) {
- if (!m_Enabled) return;
- m_TimeUntilNextCheck -= deltaTime;
- if (m_TimeUntilNextCheck <= 0.0f) {
- m_TimeUntilNextCheck = m_CheckInterval;
- auto engine = Engine::GetInstance();
- for (const auto& playerPtr : engine->GetPlayers()) {
- Player* player = playerPtr.get();
- PerformClientCheck(player);
- }
- }
- }
- void ClientIntegrityChecker::Shutdown() {
- std::cout << "Shutting down ClientIntegrityChecker module" << std::endl;
- }
- void ClientIntegrityChecker::AddHashCheck(const std::string& filename, const std::string& expectedHash) {
- HashCheck check;
- check.filename = filename;
- check.expectedHash = expectedHash;
- m_HashChecks.push_back(check);
- }
- void ClientIntegrityChecker::PerformClientCheck(Player* player) {
- // In a real implementation, this would send a request to the client
- // to verify file integrity and wait for a response
- std::cout << "Performing integrity check for player " << player->GetName() << std::endl;
- // Simulated response
- bool integrityCheckPassed = (rand() % 100) < 95; // 95% pass rate for simulation
- if (!integrityCheckPassed) {
- std::string reason = "Client integrity check failed";
- player->AddDetection(DetectionCategory::CLIENT_INTEGRITY,
- DetectionSeverity::CRITICAL,
- reason);
- // If violation score is too high, ban the player
- if (player->GetViolationScore() > 50) {
- player->Ban("Multiple integrity violations detected", 1440); // 24-hour ban
- }
- }
- }
- // Engine implementation
- Engine* Engine::GetInstance() {
- if (s_Instance == nullptr) {
- s_Instance = new Engine();
- }
- return s_Instance;
- }
- Engine::Engine()
- : m_IsInitialized(false),
- m_GameName(""),
- m_MaxPlayers(0),
- m_TickRate(60),
- m_StopUpdateThread(false) {
- }
- Engine::~Engine() {
- Shutdown();
- }
- bool Engine::Initialize(const std::string& gameName, int maxPlayers) {
- if (m_IsInitialized) {
- std::cerr << "Engine already initialized!" << std::endl;
- return false;
- }
- std::cout << "Initializing Hyperion Anticheat Engine..." << std::endl;
- m_GameName = gameName;
- m_MaxPlayers = maxPlayers;
- // Initialize modules
- RegisterModule<SpeedHackDetector>();
- RegisterModule<FlyHackDetector>();
- RegisterModule<ClientIntegrityChecker>();
- // Initialize other subsystems
- PacketAnalyzer::GetInstance()->Initialize();
- // Initialize modules
- for (auto& module : m_Modules) {
- module->Initialize();
- }
- // Start update thread
- m_StopUpdateThread = false;
- m_UpdateThread = std::thread([this]() {
- const float targetDeltaTime = 1.0f / static_cast<float>(m_TickRate);
- auto lastUpdateTime = std::chrono::high_resolution_clock::now();
- while (!m_StopUpdateThread) {
- auto currentTime = std::chrono::high_resolution_clock::now();
- float deltaTime = std::chrono::duration<float>(currentTime - lastUpdateTime).count();
- lastUpdateTime = currentTime;
- Update();
- // Sleep to maintain target tick rate
- float remainingTime = targetDeltaTime - deltaTime;
- if (remainingTime > 0) {
- std::this_thread::sleep_for(std::chrono::milliseconds(
- static_cast<int>(remainingTime * 1000)
- ));
- }
- }
- });
- m_IsInitialized = true;
- std::cout << "Hyperion Anticheat Engine initialized successfully!" << std::endl;
- return true;
- }
- void Engine::Shutdown() {
- if (!m_IsInitialized) {
- return;
- }
- std::cout << "Shutting down Hyperion Anticheat Engine..." << std::endl;
- // Stop update thread
- m_StopUpdateThread = true;
- if (m_UpdateThread.joinable()) {
- m_UpdateThread.join();
- }
- // Shutdown modules
- for (auto& module : m_Modules) {
- module->Shutdown();
- }
- m_Modules.clear();
- // Shutdown other subsystems
- PacketAnalyzer::GetInstance()->Shutdown();
- m_Players.clear();
- m_DetectionLog.clear();
- m_IsInitialized = false;
- std::cout << "Hyperion Anticheat Engine shut down successfully!" << std::endl;
- }
- void Engine::Update() {
- if (!m_IsInitialized) {
- return;
- }
- // Calculate delta time (in a real implementation)
- float deltaTime = 1.0f / static_cast<float>(m_TickRate);
- // Update players
- {
- std::lock_guard<std::mutex> lock(m_PlayersMutex);
- for (auto& player : m_Players) {
- player->Update(deltaTime);
- }
- }
- // Update modules
- for (auto& module : m_Modules) {
- if (module->IsEnabled()) {
- module->Update(deltaTime);
- }
- }
- }
- void Engine::AddPlayer(std::shared_ptr<Player> player) {
- std::lock_guard<std::mutex> lock(m_PlayersMutex);
- m_Players.push_back(player);
- std::cout << "Player added: " << player->GetName()
- << " (ID: " << player->GetUserID() << ")" << std::endl;
- }
- void Engine::RemovePlayer(uint64_t playerID) {
- std::lock_guard<std::mutex> lock(m_PlayersMutex);
- auto it = std::find_if(m_Players.begin(), m_Players.end(),
- [playerID](const std::shared_ptr<Player>& player) {
- return player->GetID() == playerID;
- });
- if (it != m_Players.end()) {
- std::cout << "Player removed: " << (*it)->GetName()
- << " (ID: " << (*it)->GetUserID() << ")" << std::endl;
- m_Players.erase(it);
- }
- }
- std::shared_ptr<Player> Engine::GetPlayer(uint64_t playerID) const {
- std::lock_guard<std::mutex> lock(m_PlayersMutex);
- auto it = std::find_if(m_Players.begin(), m_Players.end(),
- [playerID](const std::shared_ptr<Player>& player) {
- return player->GetID() == playerID;
- });
- if (it != m_Players.end()) {
- return *it;
- }
- return nullptr;
- }
- void Engine::LogDetection(Player* player, DetectionCategory category,
- DetectionSeverity severity, const std::string& reason) {
- std::lock_guard<std::mutex> lock(m_LogMutex);
- auto now = std::chrono::system_clock::now();
- DetectionEvent event(player, category, severity, reason, now);
- m_DetectionLog.push_back(event);
- std::cout << event.ToString() << std::endl;
- // Automatic enforcement based on severity
- if (severity == DetectionSeverity::CRITICAL) {
- if (player->GetViolationScore() > 50) {
- player->Ban("Multiple critical violations detected", 1440); // 24-hour ban
- }
- }
- }
- void Engine::EnableModule(const std::string& moduleName, bool enabled) {
- for (auto& module : m_Modules) {
- if (module->GetName() == moduleName) {
- module->SetEnabled(enabled);
- std::cout << "Module " << moduleName << (enabled ? " enabled" : " disabled") << std::endl;
- return;
- }
- }
- std::cerr << "Module not found: " << moduleName << std::endl;
- }
- bool Engine::IsModuleEnabled(const std::string& moduleName) const {
- for (const auto& module : m_Modules) {
- if (module->GetName() == moduleName) {
- return module->IsEnabled();
- }
- }
- return false;
- }
- // ConfigManager implementation
- ConfigManager* ConfigManager::GetInstance() {
- if (s_Instance == nullptr) {
- s_Instance = new ConfigManager();
- }
- return s_Instance;
- }
- ConfigManager::ConfigManager() {
- // Set default values
- m_ConfigValues["speedhack_max_speed"] = "50.0";
- m_ConfigValues["speedhack_teleport_threshold"] = "100.0";
- m_ConfigValues["speedhack_detection_cooldown"] = "5.0";
- m_ConfigValues["flyhack_max_air_time"] = "5.0";
- m_ConfigValues["flyhack_gravity_threshold"] = "0.1";
- m_ConfigValues["integrity_check_interval"] = "300.0";
- }
- ConfigManager::~ConfigManager() {
- }
- bool ConfigManager::LoadConfig(const std::string& filename) {
- std::ifstream file(filename);
- if (!file.is_open()) {
- std::cerr << "Failed to open config file: " << filename << std::endl;
- return false;
- }
- std::string line;
- while (std::getline(file, line)) {
- // Skip comments and empty lines
- if (line.empty() || line[0] == '#') {
- continue;
- }
- size_t separatorPos = line.find('=');
- if (separatorPos != std::string::npos) {
- std::string key = line.substr(0, separatorPos);
- std::string value = line.substr(separatorPos + 1);
- // Trim whitespace
- key.erase(0, key.find_first_not_of(" \t"));
- key.erase(key.find_last_not_of(" \t") + 1);
- value.erase(0, value.find_first_not_of(" \t"));
- value.erase(value.find_last_not_of(" \t") + 1);
- m_ConfigValues[key] = value;
- }
- }
- return true;
- }
- bool ConfigManager::SaveConfig(const std::string& filename) const {
- std::ofstream file(filename);
- if (!file.is_open()) {
- std::cerr << "Failed to open config file for writing: " << filename << std::endl;
- return false;
- }
- file << "# Hyperion Anticheat Configuration\n";
- file << "# Generated on " << std::put_time(std::localtime(&std::time(nullptr)), "%Y-%m-%d %H:%M:%S") << "\n\n";
- for (const auto& pair : m_ConfigValues) {
- file << pair.first << " = " << pair.second << "\n";
- }
- return true;
- }
- template<>
- void ConfigManager::SetValue<std::string>(const std::string& key, const std::string& value) {
- m_ConfigValues[key] = value;
- }
- template<>
- void ConfigManager::SetValue<int>(const std::string& key, const int& value) {
- m_ConfigValues[key] = std::to_string(value);
- }
- template<>
- void ConfigManager::SetValue<float>(const std::string& key, const float& value) {
- m_ConfigValues[key] = std::to_string(value);
- }
- template<>
- void ConfigManager::SetValue<bool>(const std::string& key, const bool& value) {
- m_ConfigValues[key] = value ? "true" : "false";
- }
- template<>
- std::string ConfigManager::GetValue<std::string>(const std::string& key, const std::string& defaultValue) const {
- auto it = m_ConfigValues.find(key);
- if (it != m_ConfigValues.end()) {
- return it->second;
- }
- return defaultValue;
- }
- template<>
- int ConfigManager::GetValue<int>(const std::string& key, const int& defaultValue) const {
- auto it = m_ConfigValues.find(key);
- if (it != m_ConfigValues.end()) {
- try {
- return std::stoi(it->second);
- } catch (...) {
- return defaultValue;
- }
- }
- return defaultValue;
- }
- template<>
- float ConfigManager::GetValue<float>(const std::string& key, const float& defaultValue) const {
- auto it = m_ConfigValues.find(key);
- if (it != m_ConfigValues.end()) {
- try {
- return std::stof(it->second);
- } catch (...) {
- return defaultValue;
- }
- }
- return defaultValue;
- }
- template<>
- bool ConfigManager::GetValue<bool>(const std::string& key, const bool& defaultValue) const {
- auto it = m_ConfigValues.find(key);
- if (it != m_ConfigValues.end()) {
- std::string value = it->second;
- std::transform(value.begin(), value.end(), value.begin(), ::tolower);
- return (value == "true" || value == "1" || value == "yes" || value == "y");
- }
- return defaultValue;
- }
- // PacketAnalyzer implementation
- PacketAnalyzer* PacketAnalyzer::GetInstance() {
- if (s_Instance == nullptr) {
- s_Instance = new PacketAnalyzer();
- }
- return s_Instance;
- }
- PacketAnalyzer::PacketAnalyzer()
- : m_Initialized(false), m_ValidatePackets(true) {
- }
- PacketAnalyzer::~PacketAnalyzer() {
- Shutdown();
- }
- void PacketAnalyzer::Initialize() {
- if (m_Initialized) {
- return;
- }
- std::cout << "Initializing Packet Analyzer..." << std::endl;
- // Register default packet handlers
- RegisterCallback("invalid_packet", [](const void* data, size_t size, bool isIncoming) {
- std::cout << "Invalid packet detected (" << (isIncoming ? "incoming" : "outgoing")
- << "): " << size << " bytes" << std::endl;
- // In a real implementation, this would report the player
- });
- m_Initialized = true;
- std::cout << "Packet Analyzer initialized successfully!" << std::endl;
- }
- void PacketAnalyzer::Shutdown() {
- if (!m_Initialized) {
- return;
- }
- std::cout << "Shutting down Packet Analyzer..." << std::endl;
- m_Callbacks.clear();
- m_Initialized = false;
- std::cout << "Packet Analyzer shut down successfully!" << std::endl;
- }
- void PacketAnalyzer::RegisterCallback(const std::string& name, PacketCallback callback) {
- m_Callbacks[name] = callback;
- }
- void PacketAnalyzer::UnregisterCallback(const std::string& name) {
- m_Callbacks.erase(name);
- }
- void PacketAnalyzer::ProcessIncomingPacket(Player* sender, const void* data, size_t size) {
- if (!m_Initialized || !m_ValidatePackets) {
- return;
- }
- // Validate packet
- bool isValidPacket = true; // Basic validation check
- if (!isValidPacket) {
- auto it = m_Callbacks.find("invalid_packet");
- if (it != m_Callbacks.end()) {
- it->second(data, size, true);
- }
- // Report player
- sender->AddDetection(DetectionCategory::PACKET_MANIPULATION,
- DetectionSeverity::WARNING,
- "Invalid incoming packet detected");
- }
- // Process packet through registered callbacks
- for (const auto& pair : m_Callbacks) {
- if (pair.first != "invalid_packet") {
- pair.second(data, size, true);
- }
- }
- }
- void PacketAnalyzer::ProcessOutgoingPacket(Player* recipient, const void* data, size_t size) {
- if (!m_Initialized) {
- return;
- }
- // Process packet through registered callbacks
- for (const auto& pair : m_Callbacks) {
- pair.second(data, size, false);
- }
- }
- // Utility functions implementation
- namespace Utils {
- std::string GenerateRandomToken(size_t length) {
- static const char charset[] =
- "0123456789"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "abcdefghijklmnopqrstuvwxyz";
- std::random_device rd;
- std::mt19937 generator(rd());
- std::uniform_int_distribution<int> distribution(0, sizeof(charset) - 2);
- std::string result;
- result.reserve(length);
- for (size_t i = 0; i < length; ++i) {
- result += charset[distribution(generator)];
- }
- return result;
- }
- std::string HashString(const std::string& input) {
- // Simple hash function for demonstration
- // In a real implementation, use a cryptographic hash function like SHA-256
- size_t hash = 0;
- for (char c : input) {
- hash = hash * 31 + c;
- }
- std::stringstream ss;
- ss << std::hex << hash;
- return ss.str();
- }
- bool VerifyHash(const std::string& input, const std::string& hash) {
- return HashString(input) == hash;
- }
- std::string EncryptData(const std::string& data, const std::string& key) {
- // Simple XOR encryption for demonstration
- // In a real implementation, use a proper encryption algorithm
- std::string result = data;
- size_t keyLength = key.length();
- for (size_t i = 0; i < result.length(); ++i) {
- result[i] ^= key[i % keyLength];
- }
- return result;
- }
- std::string DecryptData(const std::string& encryptedData, const std::string& key) {
- // XOR encryption is symmetric, so decryption is the same as encryption
- return EncryptData(encryptedData, key);
- }
- }
- } // namespace Hyperion
- // HyperionExample.cpp - Example usage of Hyperion Anticheat
- #include "HyperionAnticheat.h"
- #include <iostream>
- #include <memory>
- #include <thread>
- #include <chrono>
- int main() {
- // Create and initialize the engine
- Hyperion::Engine* engine = Hyperion::Engine::GetInstance();
- if (!engine->Initialize("Hyperion Roblox Anticheat", 100)) {
- std::cerr << "Failed to initialize Hyperion Anticheat Engine!" << std::endl;
- return -1;
- }
- // Load configuration
- Hyperion::ConfigManager* config = Hyperion::ConfigManager::GetInstance();
- if (!config->LoadConfig("hyperion_config.txt")) {
- std::cout << "Could not load config file, using default values" << std::endl;
- }
- // Override some settings
- config->SetValue("speedhack_max_speed", 30.0f);
- config->SetValue("flyhack_max_air_time", 3.0f);
- // Add some test players
- std::shared_ptr<Hyperion::Player> player1 = std::make_shared<Hyperion::Player>("Player1", 1, 10001);
- std::shared_ptr<Hyperion::Player> player2 = std::make_shared<Hyperion::Player>("Player2", 2, 10002);
- engine->AddPlayer(player1);
- engine->AddPlayer(player2);
- // Simulate some player activity
- player1->SetPosition(Hyperion::Vec3(0.0f, 0.0f, 0.0f));
- player1->SetVelocity(Hyperion::Vec3(0.0f, 0.0f, 0.0f));
- player1->SetMovementStat("is_grounded", 1.0f);
- player2->SetPosition(Hyperion::Vec3(10.0f, 0.0f, 10.0f));
- player2->SetVelocity(Hyperion::Vec3(0.0f, 0.0f, 0.0f));
- player2->SetMovementStat("is_grounded", 1.0f);
- // Run simulation for a while
- std::cout << "Running Hyperion Anticheat simulation..." << std::endl;
- std::cout << "Press Ctrl+C to exit" << std::endl;
- // Simulate normal player movement
- for (int i = 0; i < 10; ++i) {
- // Update player1 position (normal movement)
- Hyperion::Vec3 pos1 = player1->GetPosition();
- pos1.x += 1.0f;
- pos1.z += 0.5f;
- player1->SetPosition(pos1);
- player1->SetVelocity(Hyperion::Vec3(1.0f, 0.0f, 0.5f));
- // Update player2 position (normal movement)
- Hyperion::Vec3 pos2 = player2->GetPosition();
- pos2.x -= 0.5f;
- pos2.z -= 1.0f;
- player2->SetPosition(pos2);
- player2->SetVelocity(Hyperion::Vec3(-0.5f, 0.0f, -1.0f));
- std::this_thread::sleep_for(std::chrono::milliseconds(100));
- }
- // Simulate player1 speedhack
- std::cout << "Simulating speedhack for Player1..." << std::endl;
- player1->SetVelocity(Hyperion::Vec3(45.0f, 0.0f, 45.0f));
- std::this_thread::sleep_for(std::chrono::milliseconds(500));
- // Reset to normal movement
- player1->SetVelocity(Hyperion::Vec3(1.0f, 0.0f, 0.5f));
- // Simulate player2 flyhack
- std::cout << "Simulating flyhack for Player2..." << std::endl;
- player2->SetMovementStat("is_grounded", 0.0f);
- player2->SetVelocity(Hyperion::Vec3(0.0f, 0.0f, 0.0f));
- std::this_thread::sleep_for(std::chrono::seconds(4));
- // Reset to normal movement
- player2->SetMovementStat("is_grounded", 1.0f);
- // Simulate teleport hack
- std::cout << "Simulating teleport hack for Player1..." << std::endl;
- Hyperion::Vec3 pos1 = player1->GetPosition();
- pos1.x += 500.0f;
- pos1.z += 500.0f;
- player1->SetPosition(pos1);
- std::this_thread::sleep_for(std::chrono::milliseconds(100));
- // Wait a bit more for detections to process
- std::this_thread::sleep_for(std::chrono::seconds(2));
- // Print final detection log
- std::cout << "\n===== DETECTION LOG =====\n";
- for (const auto& detection : engine->GetDetectionLog()) {
- std::cout << detection.ToString() << std::endl;
- }
- // Shutdown the engine
- engine->Shutdown();
- // Save configuration
- config->SaveConfig("hyperion_config.txt");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement