-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathcs2_esp.py
167 lines (135 loc) · 6.03 KB
/
cs2_esp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import requests
import pyMeow as pm
class Offsets:
m_pBoneArray = 496
class Colors:
orange = pm.get_color("orange")
black = pm.get_color("black")
cyan = pm.get_color("cyan")
white = pm.get_color("white")
grey = pm.fade_color(pm.get_color("#242625"), 0.7)
class Entity:
def __init__(self, ptr, pawn_ptr, proc):
self.ptr = ptr
self.pawn_ptr = pawn_ptr
self.proc = proc
self.pos2d = None
self.head_pos2d = None
@property
def name(self):
return pm.r_string(self.proc, self.ptr + Offsets.m_iszPlayerName)
@property
def health(self):
return pm.r_int(self.proc, self.pawn_ptr + Offsets.m_iHealth)
@property
def team(self):
return pm.r_int(self.proc, self.pawn_ptr + Offsets.m_iTeamNum)
@property
def pos(self):
return pm.r_vec3(self.proc, self.pawn_ptr + Offsets.m_vOldOrigin)
@property
def dormant(self):
return pm.r_bool(self.proc, self.pawn_ptr + Offsets.m_bDormant)
def bone_pos(self, bone):
game_scene = pm.r_int64(self.proc, self.pawn_ptr + Offsets.m_pGameSceneNode)
bone_array_ptr = pm.r_int64(self.proc, game_scene + Offsets.m_pBoneArray)
return pm.r_vec3(self.proc, bone_array_ptr + bone * 32)
def wts(self, view_matrix):
try:
self.pos2d = pm.world_to_screen(view_matrix, self.pos, 1)
self.head_pos2d = pm.world_to_screen(view_matrix, self.bone_pos(6), 1)
except:
return False
return True
class CS2Esp:
def __init__(self):
self.proc = pm.open_process("cs2.exe")
self.mod = pm.get_module(self.proc, "client.dll")["base"]
offsets_name = ["dwViewMatrix", "dwEntityList", "dwLocalPlayerController", "dwLocalPlayerPawn"]
offsets = requests.get("https://raw.githubusercontent.com/a2x/cs2-dumper/main/output/offsets.json").json()
[setattr(Offsets, k, offsets["client.dll"][k]) for k in offsets_name]
client_dll_name = {
"m_iIDEntIndex": "C_CSPlayerPawnBase",
"m_hPlayerPawn": "CCSPlayerController",
"m_fFlags": "C_BaseEntity",
"m_iszPlayerName": "CBasePlayerController",
"m_iHealth": "C_BaseEntity",
"m_iTeamNum": "C_BaseEntity",
"m_vOldOrigin": "C_BasePlayerPawn",
"m_pGameSceneNode": "C_BaseEntity",
"m_bDormant": "CGameSceneNode",
}
clientDll = requests.get("https://raw.githubusercontent.com/a2x/cs2-dumper/main/output/client_dll.json").json()
[setattr(Offsets, k, clientDll["client.dll"]["classes"][client_dll_name[k]]["fields"][k]) for k in client_dll_name]
def it_entities(self):
ent_list = pm.r_int64(self.proc, self.mod + Offsets.dwEntityList)
local = pm.r_int64(self.proc, self.mod + Offsets.dwLocalPlayerController)
for i in range(1, 65):
try:
entry_ptr = pm.r_int64(self.proc, ent_list + (8 * (i & 0x7FFF) >> 9) + 16)
controller_ptr = pm.r_int64(self.proc, entry_ptr + 120 * (i & 0x1FF))
if controller_ptr == local:
continue
controller_pawn_ptr = pm.r_int64(self.proc, controller_ptr + Offsets.m_hPlayerPawn)
list_entry_ptr = pm.r_int64(self.proc, ent_list + 0x8 * ((controller_pawn_ptr & 0x7FFF) >> 9) + 16)
pawn_ptr = pm.r_int64(self.proc, list_entry_ptr + 120 * (controller_pawn_ptr & 0x1FF))
except:
continue
yield Entity(controller_ptr, pawn_ptr, self.proc)
def run(self):
pm.overlay_init("Counter-Strike 2", fps=144)
while pm.overlay_loop():
view_matrix = pm.r_floats(self.proc, self.mod + Offsets.dwViewMatrix, 16)
pm.begin_drawing()
pm.draw_fps(0, 0)
for ent in self.it_entities():
if ent.wts(view_matrix) and ent.health > 0 and not ent.dormant:
color = Colors.cyan if ent.team != 2 else Colors.orange
head = ent.pos2d["y"] - ent.head_pos2d["y"]
width = head / 2
center = width / 2
# Snapline
pm.draw_line(
pm.get_screen_width() / 2,
pm.get_screen_height() / 2,
ent.head_pos2d["x"] - center,
ent.head_pos2d["y"] - center / 2,
Colors.black,
3
)
pm.draw_line(
pm.get_screen_width() / 2,
pm.get_screen_height() / 2,
ent.head_pos2d["x"] - center,
ent.head_pos2d["y"] - center / 2,
color,
)
# Box
pm.draw_rectangle(
ent.head_pos2d["x"] - center,
ent.head_pos2d["y"] - center / 2,
width,
head + center / 2,
Colors.grey,
)
pm.draw_rectangle_lines(
ent.head_pos2d["x"] - center,
ent.head_pos2d["y"] - center / 2,
width,
head + center / 2,
color,
1.2,
)
# Info
txt = f"{ent.name} ({ent.health}%)"
pm.draw_text(
txt,
ent.head_pos2d["x"] - pm.measure_text(txt, 15) // 2,
ent.pos2d["y"],
15,
Colors.white,
)
pm.end_drawing()
if __name__ == "__main__":
esp = CS2Esp()
esp.run()