import sys
import pyMeow as pm
from pynput import keyboard


class Pointer:
    local_player = 0x17E0A8
    entity_list = 0x18AC04
    player_count = 0x18AC0C
    view_matrix = 0x17DFD0


class ProcessManager:
    """프로세스 및 모듈 초기화 관리"""
    proc = None
    base = None

    @classmethod
    def initialize(cls):
        """AssaultCube 프로세스 초기화"""
        try:
            cls.proc = pm.open_process("ac_client.exe")
            cls.base = pm.get_module(cls.proc, "ac_client.exe")["base"]
            print("Process and base initialized successfully.")
        except Exception as e:
            print(f"Error initializing process: {e}")
            sys.exit(1)

    @classmethod
    def get_proc(cls):
        return cls.proc

    @classmethod
    def get_base(cls):
        return cls.base


class KeyboardManager:
    """키보드 입력 관리"""
    left_shift_pressed = False

    @classmethod
    def setup(cls):
        """키보드 리스너 시작"""
        listener = keyboard.Listener(on_press=cls._on_press, on_release=cls._on_release)
        listener.start()

    @classmethod
    def _on_press(cls, key):
        if key == keyboard.Key.shift_l:
            cls.left_shift_pressed = True

    @classmethod
    def _on_release(cls, key):
        if key == keyboard.Key.shift_l:
            cls.left_shift_pressed = False

    @classmethod
    def is_left_shift_pressed(cls):
        return cls.left_shift_pressed
