SA-MP Forums Archive
fHooks.inc - Function hooks! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Discussion (https://sampforum.blast.hk/forumdisplay.php?fid=84)
+---- Thread: fHooks.inc - Function hooks! (/showthread.php?tid=477072)



Function hooking include - Emmet_ - 22.11.2013

fHooks.inc

Introduction
I've decided to attempt a challenge that nobody has EVER attempted before - automatic function hooks. This library allows scripters to basically hook functions EASILY, without any ALS bullshit.

This library took an entire 2 weeks of thinking for me to develop! I had to think of an effective way that scripters can hook the functions without having to change anything in their script.

How to use this?
This code:

pawn Code:
stock MyPrint(string[])
{
    printf("Time to print a message:");
    print(string);
    return 1;
}

#if defined _ALS_print
    #undef print
#else
    #define _ALS_print
#endif

#define print MyPrint
Would simply turn into this code:

pawn Code:
nhook print(message[])
{
    printf("Time to print a message:");
    print(message);
    return 1;
}
Just like y_hooks, only for functions (this won't work for callbacks, so don't try it).

Note that Hook_Call will call the original, unhooked function. Using print() directly in that function will cause the function to NOT execute properly - you have been warned.

Notes Credits Download
This is only a discussion for now - this will be released when the concept has been implemented into a library.