Modify argument C++ func gets called with
Syntax: Select all
import memory
from entities import TakeDamageInfo
from players.entity import Player
from entities.hooks import EntityPreHook, EntityCondition
@EntityPreHook(EntityCondition.is_player, 'on_take_damage')
def pre_on_take_damage(args):
victim = memory.make_object(Player, args[0])
info = memory.make_object(TakeDamageInfo, args[1])
info.damage = 500
block C++ func from getting called (and pass return val back to the C++ func trying ot call our hooked func)
Syntax: Select all
import memory
from entities import TakeDamageInfo
from players.entity import Player
from entities.hooks import EntityPreHook, EntityCondition
@EntityPreHook(EntityCondition.is_player, 'on_take_damage')
def pre_on_take_damage(args):
return False # or True
Should do absolutely nothing
Syntax: Select all
import memory
from entities import TakeDamageInfo
from players.entity import Player
from entities.hooks import EntityPreHook, EntityCondition
@EntityPreHook(EntityCondition.is_player, 'on_take_damage')
def pre_on_take_damage(args):
return None
(I don't exactly know how a post hook would work? I know you get the hooked func's return value, I have no clue what returning anything would do)
Wouldn't this be better? (Maybe too costly performance-wise?)
Modify argument C++ func gets called with
Syntax: Select all
import memory
from entities import TakeDamageInfo
from players.entity import Player
from entities.hooks import EntityPreHook, EntityCondition
from memory.hooks import PreHookReturn
@EntityPreHook(EntityCondition.is_player, 'on_take_damage')
def pre_on_take_damage(args):
victim = memory.make_object(Player, args[0])
info = memory.make_object(TakeDamageInfo, args[1])
info.damage = 500
return PreHookReturn.Modify(victim,info) # positional args
block C++ func from getting called (and pass return val back to the C++ func trying to call our hooked func)
Syntax: Select all
import memory
from entities import TakeDamageInfo
from players.entity import Player
from entities.hooks import EntityPreHook, EntityCondition,
from memory.hooks import PreHookReturn
@EntityPreHook(EntityCondition.is_player, 'on_take_damage')
def pre_on_take_damage(args):
return PreHookReturn.Block(False)# or True or any value not None and PreHookReturn.Block() would be void (or None == void. So void would be calling PreHookReturn.Block(None)) (could do a check with rtn specified (e.g. Argument.BOOL) here)
Should do absolutely nothing
(used as a listener)
Syntax: Select all
import memory
from entities import TakeDamageInfo
from players.entity import Player
from entities.hooks import EntityPreHook, EntityCondition
from memory.hooks import PreHookReturn
@EntityPreHook(EntityCondition.is_player, 'on_take_damage')
def pre_on_take_damage(args):
return PreHookReturn.PASS# PreHookReturn.PASS == CONST_PASS == None
Then an idea for how this could work behind the curtain
Syntax: Select all
call: PreHookReturn.Modify(victim,info)
return: (Enum.MODIFY, victim, info)
call: PreHookReturn.Block(False)
return: (Enum.BLOCK, False)
or
Syntax: Select all
CONST_PASS = None
CONST_MODIFY = True
CONST_BLOCK = False
call: PreHookReturn.Modify(victim,info)
return: (CONST_MODIFY, victim, info)
call: PreHookReturn.Block(False)
return: (CONST_BLOCK, False)
And maybe it could be beneficial to call a function at any point in the hook (ASAP) instead of returning a value, so the engine doesn't have to wait for the Py function(our hook) to execute, more of a nice-to-have though, possible downside is losing clarity because function call would be working as using return implicitly.