Page 1 of 1

A Hooks Library?

Posted: Tue Aug 28, 2012 12:53 pm
by MiBShidobu
I was wondering if Source.Python will come with a hooking module for scripts. Sorta like how scripts can fire custom events but can instead make custom listeners/hooks that can return information back to the calling script. Sorta of like this:

Syntax: Select all

from Source import Player
from events.decorator import Event
from hooks import CallHook

@Event("player_activate")
def OnPlayerActivate(game_event):
# variable(list/tuple) = CallHook(<hookname>, <input variables>)
hook_args = CallHook("player_should_get_health", (Player.EdictOfUserid(game_event.GetInt('userid')), ))
if hook_args:
# do stuff


And then another script can do this:

Syntax: Select all

from hooks import Hook

# Works same way as Event method from events.decorator module.
@Hook("player_should_get_health")
def OnPlayerShouldGetHealth(player)
return (true, )


This way scripts can extend their functionality with hooks to change how it was gonna handle stuff.

Posted: Tue Aug 28, 2012 2:00 pm
by satoon101
This seems very silly to me. What exactly would be the point of including this? Maybe your example is confusing me, but it seems pointless.

Also, 2 things with your first bit of code. First, in future versions (committed changes last night), it will be:[python]from events import Event[/python]
Second, you cannot declare custom names for events like that, nor will that be added in the future.

Satoon

Posted: Tue Aug 28, 2012 2:30 pm
by Omega_K2
I don't see the point of this either.

Or do you mean something like pre-hooking events and preventing them from fireing and/or chageing the attributes before they actually fire?

Posted: Sun Jan 20, 2013 8:08 am
by Logifl3x
Even though this is bumping a few month old thread but I have the same question. Is pre-hooking/detouring available to do at the moment and if so could someone explain how to do it.

Posted: Sun Jan 20, 2013 8:13 am
by satoon101
Not yet. I'm not sure, at this point, "when" it will get implemented, but it definitely will be at some point. I really don't think that is what MiBShidobu was referencing, though.

Satoon

Posted: Sun Jan 20, 2013 8:48 am
by Logifl3x
Yeah I understand what you mean. I just didn't want to recreate a topic when there's one with the same topic.