import pyMeow as pm
from libs.core import Pointer, ProcessManager, KeyboardManager
from modules.esp import Entity, init_colors as init_esp_colors
from modules.aimbot import do_aimbot

def init():
    ProcessManager.initialize()
    KeyboardManager.setup()

    print("Starting ESP + Aimbot (Hold Right Shift) overlay...")
    pm.overlay_init(target="AssaultCube", fps=144, trackTarget=True)
    init_esp_colors()


def main():
    proc = ProcessManager.get_proc()
    base = ProcessManager.get_base()
    
    while pm.overlay_loop():
        pm.begin_drawing()
        pm.draw_fps(10, 10)
        
        try:
            player_count = pm.r_int(proc, base + Pointer.player_count)
            local_player_addr = pm.r_int(proc, base + Pointer.local_player)
            my_team = pm.r_int(proc, local_player_addr + 0x30C)  # team offset

            valid_entities = []

            if player_count > 1:
                ent_list = pm.r_int(proc, base + Pointer.entity_list)
                ent_buffer = pm.r_ints(proc, ent_list, player_count)[1:]
                v_matrix = pm.r_floats(proc, base + Pointer.view_matrix, 16)
                
                for addr in ent_buffer:
                    if addr == 0: continue
                    try:
                        ent = Entity(proc, addr)
                        valid_entities.append(ent)
                        if ent.wts(v_matrix):
                            ent.draw_box()
                            ent.draw_name()
                            ent.draw_health()
                    except:
                        continue
            
            # 에임봇 실행
            do_aimbot(proc, valid_entities, local_player_addr, my_team, KeyboardManager.is_left_shift_pressed())
                        
        except Exception as e:
            pass
            
        pm.end_drawing()

if __name__ == "__main__":
    init()
    main()
