hooking natives within plugin itself?
#1

Has anyone succesfuly hooked natives registered by sa-mp to run some custom code inbetween? i have a list of particular natives i need to override for some new math plugin i'm working on.

Additionally, is it possible to register plugin to a public callback or do i really need a ugly mirror-pwn hack script to call my plugin for each onplayerupdate? i noticed that even project shoebill uses pawn-activated plugin publics to execute stuff in plugin, so is there really no better way?
Reply
#2

I cant really understand what your asking for (your wording is unclear), but i think one of these two links will be of assistance:

This posts explains how to setup invoke which calls natives (which i can help with via PM if you want):
http://forum.sa-mp.com/showpost.php?...93&postcount=8

And this one explains a new method that i have yet to actually use myself. I guess it does the same as invoke and offers a method for callback hooks as well (havent looked at it in to much detail tbh).
https://github.com/Zeex/samp-gamemode-sdk


If im completely off base maybe try explaining what it is you're actually doing (in a bit more detail)?
Reply
#3

You totally missed the point, i am talking about two things:

1. Gamemode callbacks - i want to know when onplayerupdate public is called inside my plugin without exporting a native and calling it from pawn/amx

2. I wish to override a native with a new one - if script or any filterscripts call setplayerpos, i want my plugin to hook between the calls to do something internally.
Reply
#4

Quote:
Originally Posted by JernejL
Посмотреть сообщение
You totally missed the point, i am talking about two things:

1. Gamemode callbacks - i want to know when onplayerupdate public is called inside my plugin without exporting a native and calling it from pawn/amx

2. I wish to override a native with a new one - if script or any filterscripts call setplayerpos, i want my plugin to hook between the calls to do something internally.
Oh i apologize then! I THINK the second link has an option of hooking callbacks without having to call a custom plugin function. Im not entirely sure though as i havent jumped into the code yet (just looked at a few bits). I've been going through PAWN so far for my C++ GM callbacks (its certainly less than ideal) so let me know if you mess with it before i do :P.

I dont really know about the second thing (well without using PAWN) so im of no use there . Hopefully someone with a bit more C/++ experience will come along and answer that one.
Reply
#5

Look inside the 'hello world' seems to be exactly what you want to do.
Reply
#6

That gamemode sdk looks promising on how to resolve the publics problem, but what about overriding / hooking sa-mp natives called from script to route them thru my plugin? i would really need this for some things that i am planning to use with this plugin, otherwise integration with script will be a big mess to override those via pawn.
Reply
#7

Yes you can override a native function - just find its address in the native table and replace with your own

Код:
AMX_NATIVE SetPlayerPos;

cell AMX_NATIVE_CALL MySetPlayerPos(AMX *amx, cell *params) {
    ...
    return SetPlayerPos(amx, params);
}

PLUGIN_EXPORT int PLUGIN_CALL AmxLoad(AMX *amx) {
    int index;
    if (amx_FindNative(amx, "SetPlayerPos", &index) == AMX_ERR_NONE) {
        // Get a pointer to the start of the native table
        AMX_HEADER *hdr = reinterpret_cast<AMX_HEADER*>(amx->base);
        AMX_FUNCSTUBNT *natives = reinterpret_cast<AMX_FUNCSTUBNT*>(amx->base + hdr->natives);
        // Override the address 
        ::SetPlayerPos = reinterpret_cast<AMX_NATIVE>(natives[index].address);
        natives[index].address = reinterpret_cast<ucell>(MySetPlayerPos);
    } else {
        logprintf("SetPlayerPos not used in this script");
    }
    ...
}
Reply
#8

I think if you hook amx_Register (like in gamemode sdk) then it can be done permanently, but this method needs some extra initialization code to be put in Load() anyway
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)