Page 1 of 1

PreHook: player_hurt

Posted: Sat Mar 07, 2015 3:40 pm
by MrMalina
I needed to get event pre player_hurt.

From the examples on the site I was able to make it up:

Syntax: Select all

# =============================================================================
# >> IMPORTS
# =============================================================================
import memory

from memory import find_binary
from memory import make_object
from memory import Convention
from memory import DataType
from memory.hooks import PreHook
from basetypes import TakeDamageInfo
from core import PLATFORM

# =============================================================================
# >> CONSTANTS
# =============================================================================
if PLATFORM == 'windows':
ON_TAKE_DAMAGE_IDENTIFIER = b'\x55\x8B\xEC\x81\xEC\x44\x01\x2A\x2A\x56' \
b'\x89\x4D\xFC'
else:
ON_TAKE_DAMAGE_IDENTIFIER = '_ZN20CBaseCombatCharacter12OnTakeDamageERK15CTakeDamageInfo'

# =============================================================================
# >> GLOBAL VARIABLES
# =============================================================================
server = find_binary('cstrike/bin/server')
OnTakeDamage = server[ON_TAKE_DAMAGE_IDENTIFIER].make_function(Convention.THISCALL, (DataType.POINTER, DataType.POINTER), DataType.VOID)

# =============================================================================
# >> CALLBACK
# =============================================================================
@PreHook(OnTakeDamage)
def pre_on_take_damage(args):

info = make_object(TakeDamageInfo, args[0])

print(info.inflictor)
print(info.attacker)
print(info.weapon)


When you deal damage I get to the console: 2 0 0

If I replace args [0] to args [1] I get an error:
The attachment 1.jpg is no longer available


What am I doing wrong?

SP (build on March 2). Platform: Windows

Posted: Sat Mar 07, 2015 8:23 pm
by L'In20Cible
MrMalina wrote:When you deal damage I get to the console: 2 0 0
Unexpected values are normal if you are using args[0] since this is the this pointer (the CBaseCombatCharacter pointer).


MrMalina wrote:If I replace args [0] to args [1] I get an error:
Using the exact same code and replacing args[0] to args[1] works just fine for me.

Posted: Sat Mar 07, 2015 9:30 pm
by Ayuto
Yeah, works fine for me, too. But it would be nice if you could just copy the error and post it here instead of making screenshots.