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/hack.py

128 lines
3.7 KiB
Python
Raw Normal View History

2023-04-01 17:17:01 +02:00
from json import load, loads
2023-03-30 23:19:17 +02:00
from time import sleep
from pymem import Pymem
from requests import get
2023-05-05 16:04:06 +02:00
class Hack:
2023-03-30 23:19:17 +02:00
"""Base class for playing with CSGO memory"""
2023-04-01 16:11:56 +02:00
def __init__(self, offline: bool = False) -> None:
# Time values
self.wait_time = 0.01
self.timeout = self.wait_time * 50
2023-03-30 23:19:17 +02:00
# Loading offsets
2023-04-01 16:11:56 +02:00
self.offsets = self._find_offsets(offline)
# Load virtual mapping of keys
2023-03-31 05:05:36 +02:00
self.vmap = self._find_keys()
2023-03-30 23:19:17 +02:00
# Load process
2023-03-30 23:19:17 +02:00
self.pm = self._find_process(True)
def _find_offsets(self, offline: bool) -> dict[str, int]:
"""Load CSGO offset from online repository or local file"""
2023-04-01 03:23:25 +02:00
if offline:
with open("hazedumper/csgo.min.json", "r") as f:
serial_data = load(f)
else:
hazedumper_data = get(
2023-05-05 16:04:06 +02:00
"https://raw.githubusercontent.com/frk1/hazedumper/master/csgo.min.json"
)
2023-04-01 03:23:25 +02:00
serial_data = loads(hazedumper_data.text)
2023-03-30 23:19:17 +02:00
2023-05-05 16:04:06 +02:00
return (
serial_data["signatures"]
| serial_data["netvars"]
| {
"entity_size": 0x10,
"glow_obj_size": 0x38,
"glow_R": 0x8,
"glow_G": 0xC,
"glow_B": 0x10,
"glow_A": 0x14,
"GOM_wall": 0x27,
"GOM_visible": 0x28,
"render_R": 0x0,
"render_G": 0x1,
"render_B": 0x2,
"float": 0x4,
"head_idx": 0x30 * 8,
"head_x": 0x0C,
"head_y": 0x1C,
"head_z": 0x2C,
}
)
2023-03-30 23:19:17 +02:00
2023-03-31 05:05:36 +02:00
def _find_keys(self) -> dict[str, int]:
"""https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes"""
return {
"SPACE": 0x20,
"+": 0xBB,
"LBUTTON": 0x01,
2023-03-31 21:10:52 +02:00
"END": 0x23,
"PAGE_UP": 0x21,
"PAGE_DOWN": 0x22,
2023-03-31 05:05:36 +02:00
}
2023-03-30 23:19:17 +02:00
def _find_process(self, verbose: bool = False) -> Pymem:
"""Find game process"""
process_found = False
2023-05-05 16:04:06 +02:00
print("Looking for process... ", end="", flush=True) if verbose else None
2023-03-30 23:19:17 +02:00
pm = None
while not process_found:
try:
pm = Pymem("csgo.exe")
2023-05-05 16:04:06 +02:00
except: # noqa: E722
try:
sleep(self.timeout)
except KeyboardInterrupt:
print("Canceled!")
exit(1)
2023-03-30 23:19:17 +02:00
else:
print("Process found!") if verbose else print("")
2023-03-30 23:19:17 +02:00
process_found = True
if pm:
return pm
exit(1)
def find_module(self, module: str):
"""Find module address"""
found = None
for internal_module in list(self.pm.list_modules()):
if internal_module.name == module + ".dll":
found = internal_module.lpBaseOfDll
if found:
return found
else:
2023-04-01 17:17:01 +02:00
raise MemoryError(
2023-05-05 16:04:06 +02:00
"Maybe the game isn't fully loaded yet? Wait for menu screen"
)
2023-03-30 23:19:17 +02:00
def find_uint(self, base, offset: int) -> int:
2023-03-31 04:08:09 +02:00
"""Find unsigned integer in memory for sure"""
2023-03-30 23:19:17 +02:00
local_element = None
while not local_element:
local_element = self.pm.read_uint(base + offset)
sleep(self.timeout)
2023-05-05 16:04:06 +02:00
return int(local_element)
2023-03-30 23:19:17 +02:00
2023-03-31 19:42:10 +02:00
def hack_loop(self, method, time: float | None = None):
2023-03-30 23:19:17 +02:00
"""Run the hack loop"""
2023-05-05 16:04:06 +02:00
if time is None:
2023-03-31 19:42:10 +02:00
time = self.wait_time
2023-03-30 23:19:17 +02:00
while True:
# Reduce CPU usage
2023-03-31 19:42:10 +02:00
sleep(time)
2023-03-30 23:19:17 +02:00
# Cheat
method()