Zeex / sampgdk

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

Hooking streamer callbacks #191

Closed buridan1999 closed 6 years ago

buridan1999 commented 6 years ago

In header: bool OnDynamicObjectMoved(int objectid);

In cpp: PLUGIN_EXPORT bool PLUGIN_CALL OnPublicCall(AMX *amx, const char *name, cell *params, cell *retval) { auto Name = std::string(name);

if (Name.compare("OnDynamicObjectMoved") == 0) // Or without string with strcmp.
{
    OnDynamicObjectMoved(params[1]);
}
return true;

}

ERRORS: LNK2019 unauthorized external character reference "bool __cdecl OnDynamicObjectMoved(int)" (?OnDynamicObjectMoved@@YA_NH@Z)in function _OnPublicCall@16 helloworld E:\samp_server\project\PROJECT_BINARY_DIR\streamer.obj 1

1 month ago streamer hook work fine, but now I open project again and it broken. I think it connected with DLL location... But it's linked already...

buridan1999 commented 6 years ago

Okey, I find solution of the problem: if (Name.compare("OnDynamicObjectMoved") == 0) // Or without string with strcmp. { std::cout << "OnDynamicObjectMoved(" << params[1] << ")" << std::endl; }

But, why the first variant stopped working? I don't understand?

buridan1999 commented 6 years ago

OLD VARIANT: PLUGIN_EXPORT bool PLUGIN_CALL OnPublicCall( AMX * amx, const char * name, cell * params, cell * retval ) { std::string Name = std::string( name ); // Streamer if( Name == "OnDynamicObjectMoved" ) { // int object_id = static_cast<int>( params[ 1 ] ); // ( int objectid ) // Manipulation with parametrs, and other code // return OnDynamicObjectMoved( object_id ); return OnDynamicObjectMoved( static_cast<int>(params[1]) ); } return 1; }