Skip to content

Instantly share code, notes, and snippets.

@KebabLord
Last active September 4, 2024 00:00
Show Gist options
  • Save KebabLord/123d0901258d2d2a4d38bd4ce83a1d41 to your computer and use it in GitHub Desktop.
Save KebabLord/123d0901258d2d2a4d38bd4ce83a1d41 to your computer and use it in GitHub Desktop.
CS2 Triggerbot for Linux
"""
CS2 Triggerbot for linux by Github/KebabLord
Usage:
$ pip install pynput keyboard
$ sudo python3 trigger.py
*Hold capslock to enable triggerbot*
Note:
If script fails to run, you probably need to update memory offsets:
Get the latest offsets by running: https://github.com/a2x/cs2-dumper/tree/linux
"""
from time import sleep
from random import uniform
from pynput.mouse import Controller, Button
import keyboard
import subprocess
try:
pid = int(subprocess.check_output(['pidof', "cs2"]).strip().decode())
except subprocess.CalledProcessError:
print("CS2 not running.")
exit(1)
# offsets
dwLocalPlayerPawn = 59304032
m_iIDEntIndex = 4944
dwEntityList = 57641928
m_iOldHealth = 2556
triggerkey = "capslock"
# Function to get base address of the library
def find_lib_base_address(pid, lib_name):
with open(f"/proc/{pid}/maps", "r") as maps_file:
for line in maps_file:
if lib_name in line:
return int(line.split('-')[0], 16)
raise RuntimeError(f"Library {lib_name} not found in process {pid}")
# Function to read memory at a specific address, converts hex to int
def read_memory(pid, address, length):
with open(f"/proc/{pid}/mem", "rb") as mem_file:
mem_file.seek(address)
return int.from_bytes(mem_file.read(length), byteorder="little")
libclient = find_lib_base_address(pid,"libclient.so")
def read_pos():
player = read_memory(pid, libclient + dwLocalPlayerPawn, 8) # longlong
# entity id mouse'un üstünde duran entity'nin id'sini temsil eder
entity_id = read_memory(pid, player + m_iIDEntIndex, 4) # int
if entity_id <= 0:
return None
entity_list = read_memory(pid, libclient + dwEntityList, 8) # longlong
ent_entry = read_memory(pid, entity_list + 0x8 * (entity_id >> 9) + 0x10, 8) # longlong
if ent_entry <= 0:
return None # Not a player
entity = read_memory(pid, ent_entry + 120 * (entity_id & 0x1FF), 8) # longlong
entity_hp = read_memory(pid, entity + m_iOldHealth, 4) # int
if entity_hp <= 0:
return None
return entity_hp
mouse = Controller()
health = None
while True:
if keyboard.is_pressed(triggerkey):
try:
health = read_pos()
except (OSError,ValueError):
health = None
if health is not None:
sleep(uniform(0.01, 0.03))
mouse.press(Button.left)
sleep(uniform(0.01, 0.05))
mouse.release(Button.left)
else:
sleep(0.013)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment