Advertisement
Guest User

MapName Patcher

a guest
Oct 14th, 2012
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include "amxxmodule.h"
  2.  
  3. static cell AMX_NATIVE_CALL Patch_MapName( AMX * pAmx, cell * pParameters ) {
  4.     char * pMapName = ( char * ) malloc( 128 );
  5.  
  6.     if( !pMapName ) {
  7.         MF_LogError( pAmx, AMX_ERR_NATIVE, "Something went bad! Unable to allocate a new memory block!" );
  8.  
  9.         return 0;
  10.     }
  11.  
  12.     int Length = 0;
  13.     char * pName = ( char * ) MF_GetAmxString( pAmx, pParameters[ 1 ], 0, &Length );
  14.  
  15.     if( Length < 1 || Length > 128 ) {
  16.         MF_LogError( pAmx, AMX_ERR_NATIVE, "The map name length is null or too long!" );
  17.  
  18.         free( pMapName );
  19.  
  20.         return 0;
  21.     }
  22.  
  23.     sprintf( pMapName, "%s", pName );
  24.  
  25.     /* Allows any pointer to be converted into any other pointer type! */
  26.     int Address = reinterpret_cast < int > ( gpGlobals -> pStringBase + gpGlobals -> mapname );
  27.  
  28.     for( int i = 0; i <= Length; i++ )
  29.         *( unsigned char * ) ( Address + i ) = pMapName[ i ];
  30.  
  31.     free( pMapName );
  32.  
  33.     return 1;
  34. }
  35.  
  36. AMX_NATIVE_INFO MapPatcherExports[ ] = {
  37.     { "Patch_MapName", Patch_MapName },
  38.     { NULL, NULL }
  39. };
  40.  
  41. void OnAmxxAttach( void ) {
  42.     MF_AddNatives( MapPatcherExports );
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement