[Library] y_hooks 4 - Hook callbacks, functions, and natives. - Printable Version + open.mp forum (https://forum.open.mp) -- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3) --- Forum: Releases (https://forum.open.mp/forumdisplay.php?fid=13) ---- Forum: Libraries (https://forum.open.mp/forumdisplay.php?fid=31) ---- Thread: [Library] y_hooks 4 - Hook callbacks, functions, and natives. (/showthread.php?tid=625) |
y_hooks 4 - Hook callbacks, functions, and natives. - Y_Less - 2019-06-02 Introduction After some discussion recently, I have finally gotten around to updating y_hooks. You can now hook callbacks (publics), functions (your own code), and natives! The full documentation is on github: https://github.com/pawn-lang/YSI-Includes/tree/5.x But in short, there are three types of hooks: original, callback, and function. Original Originals are still the fastest (faster even than a normal function call) and simplest, but can only hook publics: PHP Code: #include <YSI_Coding\y_hooks> The system will call each hook of a public in the order they are declared. When one ends the next starts. There is a way to stop the chain entirely, such that no more hooks are called, but this is all the control given. These can hook callbacks that don't even exist, you don't need `public OnPlayerConnect` anywhere in code for this example to work. Function A function hook hooks a function - i.e. something called within the script. This includes pawn functions and natives: PHP Code: #include <YSI_Coding\y_hooks> Every time `SetPlayerPos` is used in the script, this hook will be called first. `continue` is an explicit call to the next function in the chain - this may be another hook or the original code (a native in this case). Callback A callback hook combines the hooking of callbacks from original hooks with the explicit chaining of function hooks: PHP Code: #include <YSI_Coding\y_hooks> Note that I haven't ACTUALLY written this last one 1yet. RE: y_hooks 4 - Hook callbacks, functions, and natives. - JustMichael - 2019-06-02 Will definitely start using this immediately, will be waiting for you to finish the callback one :) Great work as always ;) RE: y_hooks 4 - Hook callbacks, functions, and natives. - Y_Less - 2019-06-02 Now uploaded. More information in these links: https://github.com/pawn-lang/YSI-Includes/blob/5.x/YSI_Coding/y_hooks/quick-start.md https://github.com/pawn-lang/YSI-Includes/blob/5.x/YSI_Coding/y_hooks/features.md https://github.com/pawn-lang/YSI-Includes/blob/5.x/YSI_Coding/y_hooks/faqs.md RE: y_hooks 4 - Hook callbacks, functions, and natives. - Stanislav - 2019-06-02 Thank you! a great improvement :) RE: y_hooks 4 - Hook callbacks, functions, and natives. - Dayrion - 2019-06-03 Nice work, thanks RE: y_hooks 4 - Hook callbacks, functions, and natives. - spacemud - 2019-06-03 Fantastic! Time to start converting all my ALS hooks... RE: y_hooks 4 - Hook callbacks, functions, and natives. - Y_Less - 2019-08-04 v0.2: Fixed Linux. Turns out SYSREQ.pri is broken there. Also, how to hook long function names. `DEFINE_HOOK_REPLACEMENT` doesn't work with these (and sadly can't). But this does work: PHP Code: #define SPP SetPlayerPos RE: y_hooks 4 - Hook callbacks, functions, and natives. - Logan - 2019-08-09 Dope shit. Well done sir. RE: y_hooks 4 - Hook callbacks, functions, and natives. - Chaprnks - 2020-03-31 (2019-06-02, 09:14 PM)Y_Less Wrote: Last time I talked to you, I was told to do "hook native SetPlayerPos". Does that still work? or should I switch those to "hook function SetPlayerPos"? EDIT I got a response via Discord. For anyone else who might want to know this; yes "hook native" & "hook function" both do the same thing for hooking natives. RE: y_hooks 4 - Hook callbacks, functions, and natives. - Y_Less - 2020-04-23 "hook stock" also does the same thing, because many people incorrectly call functions "stocks", so I supported that as well. It turns out this works because the code to hook those different function types is identical. |