This repository has been archived on 2023-09-02. You can view files and clone it, but cannot push or open issues or pull requests.
csh/cheats/aimbot.py

147 lines
5.1 KiB
Python
Raw Normal View History

2023-03-31 18:52:22 +02:00
from win32api import GetAsyncKeyState
from hack import Hack
2023-03-31 19:48:21 +02:00
from utils import Vec, angle_fixer, hypot
2023-03-31 18:52:22 +02:00
class Aimbot(Hack):
def __init__(self) -> None:
super().__init__()
2023-03-31 21:58:07 +02:00
# AimBot FOV, higher = more aggressive
self.__fov_range = 5.
# Smoothing, more = less efficient
self.__smoothing = 3.
2023-03-31 18:52:22 +02:00
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 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
2023-03-31 21:58:07 +02:00
best_fov = self.__fov_range
2023-03-31 18:52:22 +02:00
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
2023-04-01 15:22:13 +02:00
if mem.read_int(entity + offset["m_iTeamNum"]) == (
mem.read_int(local_player + offset["m_iTeamNum"])):
2023-03-31 18:52:22 +02:00
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():
2023-03-31 21:58:07 +02:00
if self.__smoothing > 0.:
best_angle = best_angle.div(self.__smoothing)
2023-03-31 18:52:22 +02:00
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)
2023-03-31 19:48:21 +02:00
def calculate_angle(local_pos: Vec, ennemy_pos: Vec, angles: Vec) -> Vec:
"""Angle calculation for aimbot"""
return ((ennemy_pos.minus(local_pos).to_angle().minus(angles)))