139 lines
4.9 KiB
Python
139 lines
4.9 KiB
Python
|
from win32api import GetAsyncKeyState
|
||
|
|
||
|
from hack import Hack
|
||
|
from utils import Vec, angle_fixer, calculate_angle, hypot
|
||
|
|
||
|
|
||
|
class Aimbot(Hack):
|
||
|
def __init__(self) -> None:
|
||
|
super().__init__()
|
||
|
|
||
|
def aimbot(self) -> None:
|
||
|
# Aliases
|
||
|
mem = self.pm
|
||
|
offset = self.offsets
|
||
|
|
||
|
# Get module addresses
|
||
|
client = self.find_module("client")
|
||
|
engine = self.find_module("engine")
|
||
|
|
||
|
# Get local player
|
||
|
local_player = self.find_uint(client, offset["dwLocalPlayer"])
|
||
|
|
||
|
# Get local team
|
||
|
local_team = self.find_uint(local_player, offset["m_iTeamNum"])
|
||
|
|
||
|
# Get client state
|
||
|
client_state = self.find_uint(engine, offset["dwClientState"])
|
||
|
|
||
|
def cheat():
|
||
|
# Pressing left click
|
||
|
if not GetAsyncKeyState(self.vmap["LBUTTON"]):
|
||
|
return
|
||
|
|
||
|
# Where are the eyes
|
||
|
local_eye_pos = Vec(
|
||
|
mem.read_float(
|
||
|
local_player + offset["m_vecOrigin"]),
|
||
|
mem.read_float(
|
||
|
local_player + offset["m_vecOrigin"] + offset["float"]),
|
||
|
mem.read_float(
|
||
|
local_player + offset["m_vecOrigin"] + offset["float"] * 2)
|
||
|
).plus(Vec(
|
||
|
mem.read_float(
|
||
|
local_player + offset["m_vecViewOffset"]),
|
||
|
mem.read_float(
|
||
|
local_player + offset["m_vecViewOffset"] + offset["float"]),
|
||
|
mem.read_float(
|
||
|
local_player + offset["m_vecViewOffset"] + offset["float"] * 2)
|
||
|
))
|
||
|
|
||
|
# Where player is looking
|
||
|
view_angles = Vec(
|
||
|
mem.read_float(
|
||
|
client_state + offset["dwClientState_ViewAngles"]),
|
||
|
mem.read_float(
|
||
|
client_state + offset["dwClientState_ViewAngles"] + offset["float"])
|
||
|
)
|
||
|
|
||
|
# How much the view is modified
|
||
|
aim_punch = Vec(
|
||
|
mem.read_float(
|
||
|
local_player + offset["m_aimPunchAngle"]),
|
||
|
mem.read_float(
|
||
|
local_player + offset["m_aimPunchAngle"] + offset["float"])
|
||
|
).times(2.) # server multiple punch by 2
|
||
|
|
||
|
# AimBot FOV, higher = more aggressive
|
||
|
best_fov = 5.
|
||
|
best_angle = Vec()
|
||
|
|
||
|
# Loop all entities
|
||
|
for i in range(1, 32): # 0 is world
|
||
|
entity = mem.read_uint(
|
||
|
client + offset["dwEntityList"] + i * offset["entity_size"])
|
||
|
|
||
|
# Ignore if entity doesn't exist
|
||
|
if not entity:
|
||
|
continue
|
||
|
|
||
|
# Ignore allies
|
||
|
if mem.read_int(entity + offset["m_iTeamNum"]) == local_team:
|
||
|
continue
|
||
|
|
||
|
# Ignore dormant
|
||
|
if mem.read_bool(entity + offset["m_bDormant"]):
|
||
|
continue
|
||
|
|
||
|
# Check if ennemy is alive
|
||
|
if mem.read_int(entity + offset["m_lifeState"]):
|
||
|
continue
|
||
|
|
||
|
# Don't aim at ennemy behind a wall
|
||
|
if not (
|
||
|
mem.read_int(entity + offset["m_bSpottedByMask"])
|
||
|
&
|
||
|
(1 << mem.read_int(
|
||
|
client_state + offset["dwClientState_GetLocalPlayer"]))
|
||
|
):
|
||
|
continue
|
||
|
|
||
|
# Find head
|
||
|
boneMatrix = mem.read_uint(entity + offset["m_dwBoneMatrix"])
|
||
|
|
||
|
ennemy_head = Vec(
|
||
|
mem.read_float(
|
||
|
boneMatrix + offset["head_idx"] + offset["head_x"]),
|
||
|
mem.read_float(
|
||
|
boneMatrix + offset["head_idx"] + offset["head_y"]),
|
||
|
mem.read_float(
|
||
|
boneMatrix + offset["head_idx"] + offset["head_z"])
|
||
|
)
|
||
|
|
||
|
angle = calculate_angle(
|
||
|
local_eye_pos, ennemy_head, view_angles.plus(aim_punch))
|
||
|
|
||
|
# Current FOV
|
||
|
fov = hypot(angle.x, angle.y)
|
||
|
|
||
|
if (fov < best_fov):
|
||
|
best_fov = fov
|
||
|
best_angle = angle
|
||
|
|
||
|
# We found an ennemy to aim at
|
||
|
if not best_angle.is_zero():
|
||
|
# Smoothing, more = less efficient
|
||
|
best_angle = best_angle.div(3.)
|
||
|
|
||
|
final_angle = view_angles.plus(best_angle)
|
||
|
|
||
|
# Fix angle if needed
|
||
|
final_angle = angle_fixer(final_angle)
|
||
|
|
||
|
mem.write_float(
|
||
|
client_state + offset["dwClientState_ViewAngles"], final_angle.x)
|
||
|
mem.write_float(
|
||
|
client_state + offset["dwClientState_ViewAngles"] + offset["float"], final_angle.y)
|
||
|
|
||
|
self.hack_loop(cheat)
|