import math
import pyMeow as pm

# Aimbot 오프셋
class AimbotOffsets:
    pos = 0x4      # Head position
    yaw = 0x34     # camera_x
    pitch = 0x38   # camera_y

def AimBot(proc, entities, local_player_addr, my_team, left_shift_pressed):
    if not left_shift_pressed or not entities:
        return
        
    try:
        my_pos = pm.r_vec3(proc, local_player_addr + AimbotOffsets.pos)
        
        target = None
        min_dist = float('inf')
        
        screen_center_x = pm.get_screen_width() / 2
        screen_center_y = pm.get_screen_height() / 2
        
        for ent in entities:
            if ent.team == my_team or ent.health <= 0:
                continue
                
            if ent.pos2d:
                dist_to_crosshair = math.hypot(ent.pos2d["x"] - screen_center_x, ent.pos2d["y"] - screen_center_y)
                if dist_to_crosshair < min_dist:
                    min_dist = dist_to_crosshair
                    target = ent

        if target:
            dx = target.pos3d["x"] - my_pos["x"]
            dy = target.pos3d["y"] - my_pos["y"]
            dz = target.pos3d["z"] - my_pos["z"]

            distance = math.hypot(dx, dy)
            
            yaw = math.atan2(dy, dx) * 180 / math.pi + 90
            pitch = math.atan2(dz, distance) * 180 / math.pi
            
            pm.w_float(proc, local_player_addr + AimbotOffsets.yaw, yaw)
            pm.w_float(proc, local_player_addr + AimbotOffsets.pitch, pitch)
            
    except Exception as e:
        pass
