Prehook PlayerRunCmd & TraceAttack

Please post any questions about developing your plugin here. Please use the search function before posting!
stonedegg
Senior Member
Posts: 141
Joined: Sun Aug 12, 2012 11:45 am

Prehook PlayerRunCmd & TraceAttack

Postby stonedegg » Sun Sep 14, 2014 3:36 pm

Can you show me how to do it? :) I'm looking to have it working for css and csgo.
User avatar
Ayuto
Project Leader
Posts: 2209
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Mon Sep 15, 2014 6:18 pm

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...
stonedegg
Senior Member
Posts: 141
Joined: Sun Aug 12, 2012 11:45 am

Postby stonedegg » Wed Sep 17, 2014 3:56 pm

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.
User avatar
Ayuto
Project Leader
Posts: 2209
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Wed Sep 17, 2014 6:09 pm

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.
User avatar
satoon101
Project Leader
Posts: 2703
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed Sep 17, 2014 6:26 pm

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.
Image

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 140 guests