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

80 lines
2.6 KiB
Python
Raw Permalink Normal View History

2023-03-31 18:52:22 +02:00
from hack import Hack
from utils import Vec, angle_normalizer
2023-03-31 18:52:22 +02:00
class Norecoil(Hack):
2023-04-01 16:11:56 +02:00
def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
2023-03-31 18:52:22 +02:00
2023-03-31 20:33:53 +02:00
# Control variable
2023-04-02 20:12:06 +02:00
self.__old_punch = Vec()
2023-03-31 18:52:22 +02:00
2023-04-04 11:06:18 +02:00
def norecoil(self) -> None:
2023-03-31 18:52:22 +02:00
# 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
2023-05-05 16:04:06 +02:00
client_state = int(mem.read_uint(engine + offset["dwClientState"]))
2023-03-31 18:52:22 +02:00
def cheat():
# Check if player is shooting
if mem.read_int(local_player + offset["m_iShotsFired"]):
# Where player is looking
view_angles = Vec(
2023-05-05 16:04:06 +02:00
float(
mem.read_float(
client_state + offset["dwClientState_ViewAngles"]
)
),
float(
mem.read_float(
client_state
+ offset["dwClientState_ViewAngles"]
+ offset["float"]
)
),
2023-03-31 18:52:22 +02:00
)
# Bullet shift
2023-03-31 18:52:22 +02:00
aim_punch = Vec(
2023-05-05 16:04:06 +02:00
float(mem.read_float(local_player + offset["m_aimPunchAngle"])),
float(
mem.read_float(
local_player + offset["m_aimPunchAngle"] + offset["float"]
)
),
).times(
2.0
) # server multiple punch by 2
2023-03-31 18:52:22 +02:00
# New angles
2023-05-05 16:04:06 +02:00
new_angle = angle_normalizer(
view_angles.plus(self.__old_punch).minus(aim_punch)
)
2023-03-31 18:52:22 +02:00
# Cancel recoil by moving the player view angle
2023-03-31 18:52:22 +02:00
mem.write_float(
2023-05-05 16:04:06 +02:00
client_state + offset["dwClientState_ViewAngles"], new_angle.x
)
2023-03-31 18:52:22 +02:00
mem.write_float(
2023-05-05 16:04:06 +02:00
client_state + offset["dwClientState_ViewAngles"] + offset["float"],
new_angle.y,
)
2023-03-31 18:52:22 +02:00
# Save the current spray value for the next bullet
2023-04-02 20:12:06 +02:00
self.__old_punch = aim_punch
2023-03-31 18:52:22 +02:00
else:
# Not spraying
2023-04-02 20:12:06 +02:00
self.__old_punch = Vec()
2023-03-31 18:52:22 +02:00
self.hack_loop(cheat)