Zeex / sampgdk

Write SA-MP gamemodes in C/C++
http://zeex.github.io/sampgdk
Apache License 2.0
156 stars 83 forks source link

How to get the address of a string argument passed to OnPublicCall? #207

Closed Double-O-Seven closed 5 years ago

Double-O-Seven commented 5 years ago

So, I need to use OnPublicCall in my plugin, where I use SAMPGDK as a dynamic library.

The signature is this one here: PLUGIN_EXPORT bool PLUGIN_CALL OnPublicCall(AMX *amx, const char *name, cell *params, cell *retval)

Now, let's say I want hooked "OnPlayerText". Now, to my understand, params[0] contains the value 8, since there are two parameters - playerid and text. How exactly do I get the real address of the text parameter? params[2] certainly does not contain the real address, since it's value is 0 and according to Y_Less, it's probably an offset.

Now, I've tried using amx_GetAddr, however, the server stops working on it's first invocation with

cell *heapPointer = nullptr;
amx_GetAddr(amx, params[2], &heapPointer);

How exactly am I supposed to do this? I need the pointer to the beginning of the string.

Zeex commented 5 years ago

Do you initialize pAMXFunctions in Load?

pAMXFunctions = ppData[PLUGIN_DATA_AMX_EXPORTS];
Double-O-Seven commented 5 years ago

I did not do that. Thank you very much!