SA-MP Forums Archive
Complete redirect native function, not only in AMX - 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: Plugin Development (https://sampforum.blast.hk/forumdisplay.php?fid=18)
+--- Thread: Complete redirect native function, not only in AMX (/showthread.php?tid=532784)



Complete redirect native function, not only in AMX - kurta999 - 20.08.2014

Hi.

Currently which is the effective way to redirect native function within samp server, not only in AMX? Its possible with memory hacking, find addresses in IDA, but this is the worst way. I need this because I'm working on per-player pickup system in YSF. I re-created complete pickup pool, and re-direct original CreatePickup functions in AMX,but not enought in AMX, because who uses streamer they will get crash, because GDK will find original CreatePickup from samp server and streamer will use it.


Re: Complete redirect native function, not only in AMX - samiras - 20.08.2014

Hook CreatePickup in samp-server. You can find address like sampgdk does currently.
http://www.codeproject.com/Articles/...ni-Hook-Engine


AW: Complete redirect native function, not only in AMX - Mellnik - 20.08.2014

amx_Redirect by Zeex?


Re: Complete redirect native function, not only in AMX - Swimor - 21.08.2014

Код:
static void _sampgdk_amxhooks_hook_native(AMX *amx,
                                          const char *name,
                                          AMX_NATIVE address) {
  int index;
  AMX_HEADER *hdr = (AMX_HEADER *)amx->base;
  AMX_FUNCSTUBNT *natives = (AMX_FUNCSTUBNT *)(amx->base + hdr->natives);

  if (amx_FindNative(amx, name, &index) == AMX_ERR_NONE) {
    natives[index].address = (ucell)address;
  }
}
took from SA-MP GDK source code (amxhooks.c).

Also if you need to store the original address you can use my modification to zeex's function:
Код:
void _streamer_native_hook(AMX *amx, const char *name, AMX_NATIVE address, AMX_NATIVE *store) {
	int index;
	AMX_HEADER *hdr = (AMX_HEADER *)amx->base;
	AMX_FUNCSTUBNT *natives = (AMX_FUNCSTUBNT *)(amx->base + hdr->natives);

	if (amx_FindNative(amx, name, &index) == AMX_ERR_NONE) {
		if (store) {
			*store = (AMX_NATIVE)natives[index].address;
		}
		natives[index].address = (ucell)address;
	}
}
Took from my streamer plugin (native.c).


Re: Complete redirect native function, not only in AMX - xeeZ - 21.08.2014

I think you have to hook each native with something like your AssemblyRedirect() function or subhook (the library that I use in my plugins) to make them work with GDK.

Edit:

You'll also need to hook amx_Register() to get addresses of your native functions because if the AMX doesn't use them they are not present in the natives table.


Respuesta: Complete redirect native function, not only in AMX - JustBored - 21.08.2014

What is the purpose of AMX_FUNCSTUBNT? i've looked for it in ****** and i coudnt find any information about it


Re: Complete redirect native function, not only in AMX - IllidanS4 - 21.08.2014

Don't use it, only when Pawn define redirect doesn't work. Your implementation may have flaws and the script creators should always have an option to use the original function.


Re: Complete redirect native function, not only in AMX - kurta999 - 21.08.2014

Quote:
Originally Posted by sprtik
Посмотреть сообщение
Don't use it, only when Pawn define redirect doesn't work. Your implementation may have flaws and the script creators should always have an option to use the original function.
No, I don't want to give option to use original function, beucase i completly replaced the pPickupPool pointer, and every original function which use it, would result in crash.


Re: Complete redirect native function, not only in AMX - Swimor - 22.08.2014

Quote:
Originally Posted by xeeZ
Посмотреть сообщение
I think you have to hook each native with something like your AssemblyRedirect() function or subhook (the library that I use in my plugins) to make them work with GDK.
If using `_sampgdk_amxhooks_hook_native`the sampgdk will still use the old function because sampgdk saves the addresses to function on register, right?

Also what is the difference between subhook and `hook.h/c` from sampgdk?

Quote:
Originally Posted by kurta999
Посмотреть сообщение
No, I don't want to give option to use original function, beucase i completly replaced the pPickupPool pointer, and every original function which use it, would result in crash.
As Zeex said, because sampgdk saves the addresses to function on register and ignores the run time native function changes, you will need to use Zeex's subhook.

If you need help with subhook you can PM me and I will help you


Re: Complete redirect native function, not only in AMX - kurta999 - 22.08.2014

Quote:
Originally Posted by xeeZ
Посмотреть сообщение
I think you have to hook each native with something like your AssemblyRedirect() function or subhook (the library that I use in my plugins) to make them work with GDK.

Edit:

You'll also need to hook amx_Register() to get addresses of your native functions because if the AMX doesn't use them they are not present in the natives table.
I thinked this will be the solution, too. But, did server load plugins before amx_Register called from samp server with natives?


Re: Complete redirect native function, not only in AMX - Swimor - 22.08.2014

Quote:
Originally Posted by kurta999
Посмотреть сообщение
I thinked this will be the solution, too. But, did server load plugins before amx_Register called from samp server with natives?
Yes.