Complete redirect native function, not only in AMX
#1

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.
Reply
#2

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

amx_Redirect by Zeex?
Reply
#4

Код:
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).
Reply
#5

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.
Reply
#6

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

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.
Reply
#8

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.
Reply
#9

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
Reply
#10

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?
Reply
#11

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)