Загрузка данных


import pymem
import pymem.process
import time
import struct
import win32gui
import win32con
import win32api
import pygame
import sys

# --- АКТУАЛЬНЫЕ ГЛОБАЛЬНЫЕ СМЕЩЕНИЯ ---
DW_ENTITY_LIST = 40965528
DW_LOCAL_PLAYER_CONTROLLER = 39008424
DW_VIEW_MATRIX = 39197904

# --- СМЕЩЕНИЯ СУЩНОСТЕЙ ---
M_H_PLAYER_PAWN = 1724
M_I_HEALTH = 812
M_I_TEAM_NUM = 959
M_LIFE_STATE = 816
M_V_OLD_ORIGIN = 4844
M_V_VEC_VIEW_OFFSET = 3200
M_P_GAME_SCENE_NODE = 0x310
M_B_DORMANT = 231

def read_vector3(pm, address):
    buffer = pm.read_bytes(address, 12)
    return struct.unpack('3f', buffer)

def world_to_screen(matrix, pos_x, pos_y, pos_z, screen_width, screen_height):
    w = matrix[12] * pos_x + matrix[13] * pos_y + matrix[14] * pos_z + matrix[15]
    if w < 0.01:
        return None, None

    inv_w = 1.0 / w
    x = matrix[0] * pos_x + matrix[1] * pos_y + matrix[2] * pos_z + matrix[3]
    y = matrix[4] * pos_x + matrix[5] * pos_y + matrix[6] * pos_z + matrix[7]

    ndc_x = x * inv_w
    ndc_y = y * inv_w

    screen_x = (screen_width / 2.0) * (1.0 + ndc_x)
    screen_y = (screen_height / 2.0) * (1.0 - ndc_y)
    return screen_x, screen_y

def setup_transparent_window(width, height):
    pygame.init()
    screen = pygame.display.set_mode((width, height), pygame.NOFRAME | pygame.SRCALPHA)
    pygame.display.set_caption("Shadow Overlay")

    hwnd = pygame.display.get_wm_info()["window"]

    style = win32gui.GetWindowLong(hwnd, win32con.GWL_STYLE)
    win32gui.SetWindowLong(hwnd, win32con.GWL_STYLE, style & ~win32con.WS_CAPTION & ~win32con.WS_THICKFRAME)

    win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE,
                           win32con.WS_EX_LAYERED | win32con.WS_EX_TRANSPARENT | win32con.WS_EX_TOPMOST)

    win32gui.SetLayeredWindowAttributes(hwnd, win32api.RGB(0, 0, 0), 0, win32con.LWA_COLORKEY)
    return screen, hwnd

def main():
    print("Инициализация оверлея...")
    try:
        pm = pymem.Pymem("cs2.exe")
        client = pymem.process.module_from_name(pm.process_handle, "client.dll").lpBaseOfDll
        print(f"База client.dll: {hex(client)}")
    except Exception as e:
        print(f"Ошибка подключения: {e}")
        return

    game_hwnd = win32gui.FindWindow(None, "Counter-Strike 2")
    if game_hwnd:
        rect = win32gui.GetClientRect(game_hwnd)
        SCREEN_WIDTH = rect[2] if rect[2] > 0 else 1920
        SCREEN_HEIGHT = rect[3] if rect[3] > 0 else 1080
    else:
        SCREEN_WIDTH, SCREEN_HEIGHT = 1920, 1080

    screen, hwnd = setup_transparent_window(SCREEN_WIDTH, SCREEN_HEIGHT)
    clock = pygame.time.Clock()

    print("Оверлей запущен. Выход: Ctrl+C в консоли.")

    running = True
    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    running = False

        screen.fill((0, 0, 0, 0))

        try:
            entity_list = pm.read_longlong(client + DW_ENTITY_LIST)
            local_controller = pm.read_longlong(client + DW_LOCAL_PLAYER_CONTROLLER)

            if entity_list and local_controller:
                local_team = pm.read_int(local_controller + M_I_TEAM_NUM)
                matrix_bytes = pm.read_bytes(client + DW_VIEW_MATRIX, 64)
                view_matrix = struct.unpack('16f', matrix_bytes)

                for i in range(64):
                    try:
                        list_entry = pm.read_longlong(entity_list + (8 * (i & 0x7FFF) >> 9) + 16)
                        if not list_entry:
                            continue

                        player_controller = pm.read_longlong(list_entry + 8 * (i & 0x1FF))
                        if not player_controller or player_controller == local_controller:
                            continue

                        pawn_handle = pm.read_int(player_controller + M_H_PLAYER_PAWN)
                        if not pawn_handle:
                            continue

                        pawn_entry = pm.read_longlong(entity_list + (8 * ((pawn_handle & 0x7FFF) >> 9)) + 16)
                        if not pawn_entry:
                            continue

                        player_pawn = pm.read_longlong(pawn_entry + 8 * (pawn_handle & 0x1FF))
                        if not player_pawn:
                            continue

                        game_scene_node = pm.read_longlong(player_pawn + M_P_GAME_SCENE_NODE)
                        if game_scene_node and pm.read_bool(game_scene_node + M_B_DORMANT):
                            continue

                        if pm.read_int(player_pawn + M_LIFE_STATE) != 0:
                            continue

                        health = pm.read_int(player_pawn + M_I_HEALTH)
                        if health <= 0 or health > 100:
                            continue

                        if pm.read_int(player_pawn + M_I_TEAM_NUM) == local_team:
                            continue

                        pos_x, pos_y, pos_z = read_vector3(player_pawn + M_V_OLD_ORIGIN)
                        view_offset_z = pm.read_float(player_pawn + M_V_VEC_VIEW_OFFSET + 8)
                        head_z = pos_z + view_offset_z + 10

                        foot_x, foot_y = world_to_screen(view_matrix, pos_x, pos_y, pos_z, SCREEN_WIDTH, SCREEN_HEIGHT)
                        head_x, head_y = world_to_screen(view_matrix, pos_x, pos_y, head_z, SCREEN_WIDTH, SCREEN_HEIGHT)

                        if foot_x is not None and head_x is not None:
                            box_height = abs(foot_y - head_y)
                            box_width = box_height / 2.0
                            box_x = foot_x - (box_width / 2.0)
                            box_y = head_y

                            pygame.draw.rect(screen, (255, 50, 50, 220), (box_x, box_y, box_width, box_height), 1)

                            bar_width = 3
                            bar_x = box_x - 6
                            current_bar_height = (box_height * health) / 100.0
                            pygame.draw.rect(screen, (50, 50, 50, 200), (bar_x, box_y, bar_width, box_height))
                            pygame.draw.rect(screen, (0, 255, 0, 220), (bar_x, box_y + (box_height - current_bar_height), bar_width, current_bar_height))

                    except Exception:
                        continue
        except Exception:
            pass

        pygame.display.flip()
        clock.tick(120)

    pygame.quit()
    sys.exit()

if __name__ == "__main__":
    main()