toribio

toribio

Feb 3rd, 2011
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. #include "amx.h"
  2. #include "plugincommon.h"
  3. #include <windows.h>
  4.  
  5. typedef void (*logprintf_t)(char* format, ...);
  6.  
  7. logprintf_t logprintf;
  8. void **ppPluginData;
  9. extern void *pAMXFunctions;
  10. AMX *gMachines[51];
  11.  
  12. PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports()
  13. {
  14.     return SUPPORTS_VERSION | SUPPORTS_AMX_NATIVES;
  15. }
  16.  
  17. void Call(DWORD from, DWORD to)
  18. {
  19.     DWORD oldp, newp, disp;
  20.     disp = to - (from + 5);
  21.     VirtualProtect((LPVOID)from, 5, PAGE_EXECUTE_READWRITE, &oldp);
  22.     *(PBYTE)(from) = 0xE8;
  23.     *(PDWORD)(from + 1) = (DWORD)disp;
  24.     VirtualProtect((LPVOID)from, 5, oldp, &newp);
  25. }
  26.  
  27. void OnModifiedPacket(char *string, int playerid, char *ip)
  28. {
  29.     cell retval;
  30.     for(short i = 0; i < sizeof gMachines; ++i)
  31.     {
  32.         if(gMachines[i])
  33.         {
  34.             int index;
  35.             if(amx_FindPublic(gMachines[i], "OnModifiedPacket", &index) == AMX_ERR_NONE)
  36.             {
  37.                 amx_Push(gMachines[i], (cell)playerid);
  38.                 amx_Exec(gMachines[i], &retval, index);
  39.             }
  40.         }
  41.     }
  42.     if(retval)
  43.     {
  44.         logprintf(string, playerid, ip);
  45.     }
  46. }
  47.  
  48. PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData)
  49. {
  50.     pAMXFunctions = ppData[PLUGIN_DATA_AMX_EXPORTS];
  51.     logprintf = (logprintf_t)ppData[PLUGIN_DATA_LOGPRINTF];
  52.     Call(0x0049B801, (DWORD)OnModifiedPacket);
  53.     logprintf("Anti-packet-modifier by Flavio Toribio loaded.");
  54.     return true;
  55. }
  56.  
  57. PLUGIN_EXPORT void PLUGIN_CALL Unload()
  58. {
  59.     logprintf("Anti-packet-modifier by Flavio Toribio unloaded.");
  60. }
  61.  
  62. PLUGIN_EXPORT int PLUGIN_CALL AmxLoad(AMX *amx)
  63. {
  64.     for(short i = 0; i < sizeof gMachines; ++i)
  65.     {
  66.         if(!gMachines[i])
  67.         {
  68.             gMachines[i] = amx;
  69.             break;
  70.         }
  71.     }
  72.     return AMX_ERR_NONE;
  73. }
  74.  
  75. PLUGIN_EXPORT int PLUGIN_CALL AmxUnload(AMX *amx)
  76. {
  77.     for(short i = 0; i < sizeof gMachines; ++i)
  78.     {
  79.         if(gMachines[i] == amx)
  80.         {
  81.             gMachines[i] = NULL;
  82.             break;
  83.         }
  84.     }
  85.     return AMX_ERR_NONE;
  86. }
Add Comment
Please, Sign In to add comment