
Prehook PlayerRunCmd & TraceAttack
Prehook PlayerRunCmd & TraceAttack
Can you show me how to do it?
I'm looking to have it working for css and csgo.

Here is an example for CS:S (CS:GO shouldn't differ very much).
Syntax: Select all
# =============================================================================
# >> IMPORTS
# =============================================================================
# Memory
import memory
from memory import Argument
from memory import Return
from memory import Convention
from memory.hooks import PreHook
# Players
from players.bots import BotCmd
from players.helpers import index_from_pointer
# Core
from core import PLATFORM
# =============================================================================
# >> GLOBAL VARIABLES
# =============================================================================
# Get the server binary
server = memory.find_binary('cstrike/bin/server')
if PLATFORM == 'windows':
identifier = b'\x55\x8B\xEC\x83\xEC\x54\x56\x89\x4D\xFC'
else:
identifier = '_ZN9CCSPlayer16PlayerRunCommandEP8CUserCmdP11IMoveHelper'
# CCSPlayer::PlayerRunCommand(CUserCmd *, IMoveHelper *)
# The signature for CS:GO might be the same.
PLAYER_RUN_COMMAND = server[identifier].make_function(
Convention.THISCALL,
(Argument.POINTER, Argument.POINTER, Argument.BOOL),
Return.VOID
)
# =============================================================================
# >> CALLBACKS
# =============================================================================
@PreHook(PLAYER_RUN_COMMAND)
def pre_player_run_command(args):
# Get the player index
ply_index = index_from_pointer(args[0])
# Actually, this isn't a CBotCmd pointer, but CBotCmd has exactly the same
# structure like CUserCmd. That's why we can use CBotCmd here.
ucmd = memory.make_object(BotCmd, args[1])
# Get the IMoveHelper pointer. We haven't exposed IMoveHelper, so if you
# want to call a method of it, you need to reconstruct the class on your
# own.
move_helper = args[2]
# TODO: Your code...
Return to “Plugin Development Support”
Who is online
Users browsing this forum: No registered users and 155 guests