Page 1 of 1

Prehook PlayerRunCmd & TraceAttack

Posted: Sun Sep 14, 2014 3:36 pm
by stonedegg
Can you show me how to do it? :) I'm looking to have it working for css and csgo.

Posted: Mon Sep 15, 2014 6:18 pm
by Ayuto
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...

Posted: Wed Sep 17, 2014 3:56 pm
by stonedegg
Thanks, I will try it out soon! Could you show me an example for prehooking TraceAttack too? I'm trying to find out if a player was hit by a flashbang (and on which hitbox). Would need that for cs:s only.

Posted: Wed Sep 17, 2014 6:09 pm
by Ayuto
You would also use the PreHook decorator to hook TraceAttack.

But I don't think you need to hook that method for this. Just use the player_hurt event and check the weapon and hitbox.

Posted: Wed Sep 17, 2014 6:26 pm
by satoon101
I cannot remember which, but either the flashbang or smokegrenade does not cause player_hurt if the victim is wearing armor. If it is the flashbang, you might try hooking OnTakeDamage to see if that is fired.