This repository has been archived by the owner on Oct 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathentity.py
176 lines (134 loc) · 8.03 KB
/
entity.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
168
169
170
171
172
173
174
175
176
import offsets, struct
from helper import *
class Entity():
def __init__(self, mem) -> None:
self.mem = mem
self.entity_list = []
self.glow_objects_list = []
def entity_loop(self) -> list:
try:
self.entity_list.clear()
# 0 - world entity
# 1 - 64 - reserved for players
for i in range(0, 512):
entity = self.mem.game_handle.read_uint(self.mem.client_dll + offsets.dwEntityList + i * 0x10)
if entity != 0:
class_id = self.class_id(entity)
if class_id == None:
continue
if [entity, class_id] not in self.entity_list:
self.entity_list.append([i, entity, class_id])
except Exception as err:
pass
def glow_objects_loop(self) -> list:
try:
self.glow_objects_list.clear()
for i in range(1, self.glow_object_size()):
glow_object = self.mem.game_handle.read_uint(self.glow_object() + 0x38 * (i - 1) + 0x4)
if glow_object != 0:
class_id = self.class_id(glow_object)
if class_id == None:
continue
if [glow_object, class_id] not in self.glow_objects_list:
self.glow_objects_list.append([i, glow_object, class_id])
except Exception as err:
pass
def get_entity(self, entity: int) -> int:
return self.mem.game_handle.read_uint((self.mem.client_dll + offsets.dwEntityList) + entity * 0x10)
def get_life_state(self, entity: int) -> int:
return self.mem.game_handle.read_int(entity + offsets.m_lifeState)
def get_health(self, entity: int) -> int:
return self.mem.game_handle.read_int(entity + offsets.m_iHealth)
def get_team(self, entity: int) -> int:
return self.mem.game_handle.read_int(entity + offsets.m_iTeamNum)
def get_dormant(self, entity: int) -> bool:
return self.mem.game_handle.read_bool(entity + offsets.m_bDormant)
def set_dormant(self, entity: int, value: bool) -> None:
return self.mem.game_handle.write_bool(entity + offsets.m_bDormant, value)
def is_spotted(self, entity: int) -> bool:
return self.mem.game_handle.read_bool(entity + offsets.m_bSpotted)
def set_spotted(self, entity: int, value: bool) -> None:
return self.mem.game_handle.write_bool(entity + offsets.m_bSpotted, value)
def is_spotted_by_mask(self, entity: int) -> bool:
return self.mem.game_handle.read_bool(entity + offsets.m_bSpottedByMask)
def set_spotted_by_mask(self, entity: int, value: bool) -> None:
return self.mem.game_handle.write_bool(entity + offsets.m_bSpottedByMask, value)
def is_defusing(self, entity: int) -> bool:
return self.mem.game_handle.read_bool(entity + offsets.m_bIsDefusing)
def is_scoping(self, entity: int) -> bool:
return self.mem.game_handle.read_bool(entity + offsets.m_bIsScoped)
def is_protected(self, entity: int) -> bool:
return self.mem.game_handle.read_bool(entity + offsets.m_bGunGameImmunity)
def get_flag(self, entity: int) -> int:
return self.mem.game_handle.read_uint(entity + offsets.m_fFlags)
def is_bomb_planted(self) -> bool:
return self.mem.game_handle.read_bool(
self.mem.game_handle.read_int(
self.mem.client_dll + offsets.dwGameRulesProxy) + offsets.m_bBombPlanted)
def glow_object(self) -> int:
return self.mem.game_handle.read_uint(self.mem.client_dll + offsets.dwGlowObjectManager)
def glow_object_size(self) -> int:
return self.mem.game_handle.read_uint(self.mem.client_dll + offsets.dwGlowObjectManager + 0xC)
def glow_index(self, entity: int) -> int:
return self.mem.game_handle.read_uint(entity + offsets.m_iGlowIndex)
def is_bomb_planted(self) -> bool:
return self.mem.game_handle.read_bool((self.mem.client_dll + offsets.dwGameRulesProxy) + offsets.m_bBombPlanted)
def engine_ptr(self) -> int:
return self.mem.game_handle.read_uint(self.mem.engine_dll + offsets.dwClientState)
def force_update(self) -> None:
self.mem.game_handle.write_int(self.engine_ptr() + 0x174, -1)
def in_game(self) -> int:
return self.mem.game_handle.read_uint(self.engine_ptr() + offsets.dwClientState_State) == 6
def get_map_name(self) -> str:
return self.mem.game_handle.read_string(self.engine_ptr() + offsets.dwClientState_Map)
def get_map_dir(self) -> str:
return self.mem.game_handle.read_string(self.engine_ptr() + offsets.dwClientState_MapDirectory)
def class_id(self, entity: int) -> int:
client_networkable = self.mem.game_handle.read_uint(entity + 0x8)
dwGetClientClassFn = self.mem.game_handle.read_uint(client_networkable + 0x8)
entity_client_class = self.mem.game_handle.read_uint(dwGetClientClassFn + 0x1)
class_id = self.mem.game_handle.read_uint(entity_client_class + 0x14)
return class_id
def get_position(self, entity: int) -> Vector3:
position_bytes = self.mem.game_handle.read_bytes(entity + offsets.m_vecOrigin, 0xC)
var = struct.unpack("3f", position_bytes)
return Vector3(*var)
def set_position(self, entity, position: Vector3) -> None:
Vector3(self.mem.game_handle.write_float(entity + offsets.m_vecOrigin, position.x),
self.mem.game_handle.write_float(entity + offsets.m_vecOrigin + 0x4, position.y),
self.mem.game_handle.write_float(entity + offsets.m_vecOrigin + 0x4, position.z)
)
def get_view_angle(self) -> Vector3:
view_angle_bytes = self.mem.game_handle.read_bytes(self.engine_ptr() + offsets.dwClientState_ViewAngles, 0xC)
var = struct.unpack("3f", view_angle_bytes)
return Vector3(*var)
def set_view_angle(self, angle: Vector3) -> None:
Vector3(self.mem.game_handle.write_float(self.engine_ptr() + offsets.dwClientState_ViewAngles, angle.x),
self.mem.game_handle.write_float(self.engine_ptr() + offsets.dwClientState_ViewAngles + 0x4, angle.y),
self.mem.game_handle.write_float(self.engine_ptr() + offsets.dwClientState_ViewAngles + 0x8, angle.z),
)
def get_bone_position(self, entity, bone_id: int) -> Vector3:
bone_matrix = self.mem.game_handle.read_uint(entity + offsets.m_dwBoneMatrix)
return Vector3(self.mem.game_handle.read_float(bone_matrix + 0x30 * bone_id + 0x0c),
self.mem.game_handle.read_float(bone_matrix + 0x30 * bone_id + 0x1c),
self.mem.game_handle.read_float(bone_matrix + 0x30 * bone_id + 0x2c)
)
def get_name(self, entity: int) -> bytes:
player_info = self.mem.game_handle.read_uint(self.engine_ptr()
+ offsets.dwClientState_PlayerInfo)
player_info_items = self.mem.game_handle.read_uint(
self.mem.game_handle.read_uint(player_info + 0x40) + 0xC
)
info = self.mem.game_handle.read_uint(player_info_items + 0x28 + (entity * 0x34))
if info > 0:
return self.mem.game_handle.read_bytes(info + 0x10, 32)
# return self.mem.game_handle.read_string(info + 0x10)
def get_rank(self, entity: int) -> int:
return self.mem.game_handle.read_uint((self.mem.client_dll + offsets.dwPlayerResource)
+ offsets.m_iCompetitiveRanking + (entity + 1) * 0x4)
def get_wins(self, entity: int) -> int:
return self.mem.game_handle.read_uint((self.mem.client_dll + offsets.dwPlayerResource)
+ offsets.m_iCompetitiveWins + (entity + 1) * 0x4)
def view_matrix(self) -> Vector3:
view_matrix = self.mem.game_handle.read_bytes(self.mem.client_dll + offsets.dwViewMatrix, 64)
return struct.unpack("16f", view_matrix)