Hooking respawn

Please post any questions about developing your plugin here. Please use the search function before posting!
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

Hooking respawn

Postby arawra » Tue May 20, 2014 9:29 am

Want to make sure I am hooking the right function.

I have two other questions also. Does this take place every time a player spawns, or only at round start? I see that there is one parameter for RoundRespawn, but I'm not sure what it is and a quick google didn't pull anything up for me. For CS:Source, Allied Modders says there are no arguments.

Syntax: Select all

import memory

from memory import Convention, Argument, Return

from memory.hooks import PreHook

from basetypes import TakeDamageInfo

from core import PLATFORM

# Signature and symbol for CCSPlayer::RoundRespawn
if PLATFORM == 'windows':
ON_PLAYER_SPAWN_IDENTIFIER = b'\x55\x8B\xEC\x83\xEC\x08\x56\x8B\xF1\x8B\x0D\x2A\x2A\x2A\x2A\x57'
else:
ON_PLAYER_SPAWN_IDENTIFIER = '_ZN9CCSPlayer12RoundRespawnEv'

# Get the server file
server = memory.find_binary('cstrike/bin/server')

# Search for the function pointer and convert it into a Function object
OnPlayerSpawn = server[ON_PLAYER_SPAWN_IDENTIFIER].make_function(
Convention.THISCALL,
(Argument.POINTER, Argument.POINTER),
Return.VOID

# =============================================================================
# Functions
# =============================================================================

@PreHook(OnPlayerSpawn)
def pre_player_spawn(args):
'''
Called at round start OR whenever a player spawns?
'''

# Convert the second pointer to a Player? object
player = memory.make_object(NotSureWhichObject, args[1])

# Modify health?
player.health += 20
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Tue May 20, 2014 1:24 pm

I think that function is called whenever a players spawns. It's correct to say that the function does not take any arguments, but since it's a member function there is also a "this" pointer you have to count as an argument. (FYI: On Linux the "this" pointer is pushed onto the stack just like an argument. On Windows it's stored in the ECX register.)

So, you script should look ike this:

Syntax: Select all

import memory

from memory import Convention, Argument, Return
from memory.hooks import PreHook

from core import PLATFORM
from players.entity import PlayerEntity

# Signature and symbol for CCSPlayer::RoundRespawn
if PLATFORM == 'windows':
ON_PLAYER_SPAWN_IDENTIFIER = b'\x55\x8B\xEC\x83\xEC\x08\x56\x8B\xF1\x8B\x0D\x2A\x2A\x2A\x2A\x57'
else:
ON_PLAYER_SPAWN_IDENTIFIER = '_ZN9CCSPlayer12RoundRespawnEv'

# Get the server file
server = memory.find_binary('cstrike/bin/server')

# Search for the function pointer and convert it into a Function object
OnPlayerSpawn = server[ON_PLAYER_SPAWN_IDENTIFIER].make_function(
Convention.THISCALL,
(Argument.POINTER,),
Return.VOID
)

# =============================================================================
# Functions
# =============================================================================
@PreHook(OnPlayerSpawn)
def pre_player_spawn(args):
'''
Called whenever a player spawns.
'''

# If we would have reconstructed the CCSPlayer class you would do this:
# player = make_object(CCSPlayer, args[0])

player = PlayerEntity(index_from_pointer(args[0]))

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 44 guests