Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "main.h"
- typedef void (*logprintf_t)(char* format, ...);
- logprintf_t logprintf;
- unsigned long base = 0x00;
- bool GetMysqlInfos( char* host, char* username, char* password )
- {
- FILE* fichier = fopen( "mysql_config.ini", "r" );
- if( fichier )
- {
- char buffer[ 2048 ] = "";
- int idx = 0, line_idx = 0;
- bool eof = false;
- while( fread( &buffer[ idx ], 1, 1, fichier ) == 1 || eof == false ) // ( buffer[ idx ] = (char)fgetc( fichier ) ) bug ...
- {
- if( buffer[ idx ] == '\n' || buffer[ idx ] == 0 )
- {
- if( buffer[ idx ] == 0 ) eof = true;
- std::string str( &buffer[ line_idx ], &buffer[ idx ] );
- line_idx = idx + 1;
- /* traitement des données */
- if( str.find( "hostname=" ) != -1 )
- {
- strcpy( host, str.substr( 9 ).c_str( ) );
- }
- else if( str.find( "username=" ) != -1 )
- {
- strcpy( username, str.substr( 9 ).c_str( ) );
- }
- else if( str.find( "password=" ) != -1 )
- {
- strcpy( password, str.substr( 9 ).c_str( ) );
- }
- }
- idx++;
- }
- fclose( fichier );
- return true;
- }
- return false;
- }
- cell amxSampMysqlConnect( AMX* a_AmxInterface, cell a_Params[] )
- {
- char host[ 128 ] = "", username[ 128 ] = "", pass[ 128 ] = "";
- if( GetMysqlInfos( host, username, pass ) == true )
- {
- logprintf( "mysql_config.ini opened." );
- logprintf( "hostname=%s\n", host );
- logprintf( "username=%s\n", username );
- logprintf( "password=%s\n", pass );
- }
- else
- {
- logprintf( "Unable to load \"mysql_config.ini" );
- return 0;
- }
- if( a_Params[ 0 ] == 3 * 8 )
- {
- amx_SetString( &a_Params[ 1 ], host, 0, 0, strlen( host ) );
- amx_SetString( &a_Params[ 2 ], host, 0, 0, strlen( username ) );
- amx_SetString( &a_Params[ 3 ], host, 0, 0, strlen( pass ) );
- unsigned long samp_mysql_connect = base + 0x290A;
- cell ret = 0;
- __asm_volatile
- {
- push a_Params
- push a_AmxInterface
- call samp_mysql_connect
- mov ret, eax
- }
- return ret;
- }
- return 0;
- }
- PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports()
- {
- return SUPPORTS_VERSION | SUPPORTS_AMX_NATIVES;
- }
- PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData)
- {
- pAMXFunctions = ppData[PLUGIN_DATA_AMX_EXPORTS];
- logprintf = (logprintf_t) ppData[PLUGIN_DATA_LOGPRINTF];
- base = ( unsigned long )dlsym( dlopen( "sampmysqlsyg.so", RTLD_NOLOAD ), 0 );
- mprotect( (void*)( base + _REGISTER_OFF_SAMP_MYSQL_CONNECT ), 0x04, PROT_READ | PROT_WRITE | PROT_EXEC );
- *( unsigned long* )( base + REGISTER_OFF_SAMP_MYSQL_CONNECT ) = ( unsigned long) amxSampMysqlConnect;
- return true;
- }
- PLUGIN_EXPORT void PLUGIN_CALL Unload()
- {
- }
- PLUGIN_EXPORT int PLUGIN_CALL AmxLoad( AMX *amx )
- {
- return -1;
- }
- PLUGIN_EXPORT int PLUGIN_CALL AmxUnload( AMX *amx )
- {
- return AMX_ERR_NONE;
- }
Add Comment
Please, Sign In to add comment