Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. #include <sdktools>
  2. #include <dhooks>
  3.  
  4. // windows
  5. #define GetPlayerSlotOffs 16
  6.  
  7. // linux
  8. //#define GetPlayerSlotOffs 4
  9.  
  10. Handle hGetPlayerSlot;
  11. Handle hExecuteStringCommand;
  12.  
  13. public void OnPluginStart()
  14. {
  15. Handle temp = LoadGameConfigFile("PTaH.games");
  16.  
  17. if(temp == INVALID_HANDLE)
  18. {
  19. SetFailState("Why you no has gamedata?");
  20. }
  21.  
  22. hExecuteStringCommand = DHookCreateDetour(Address_Null, CallConv_THISCALL, ReturnType_Bool, ThisPointer_Address);
  23. if (!hExecuteStringCommand)
  24. SetFailState("Failed to setup detour for ExecuteStringCommand");
  25.  
  26. if (!DHookSetFromConf(hExecuteStringCommand, temp, SDKConf_Signature, "ExecuteStringCommand"))
  27. SetFailState("Failed to load ExecuteStringCommand signature from gamedata");
  28.  
  29. DHookAddParam(hExecuteStringCommand, HookParamType_CharPtr);
  30.  
  31. if (!DHookEnableDetour(hExecuteStringCommand, false, Detour_OnExecuteStringCommand))
  32. SetFailState("Failed to detour ExecuteStringCommand.");
  33.  
  34. if (!DHookEnableDetour(hExecuteStringCommand, true, Detour_OnExecuteStringCommand_Post))
  35. SetFailState("Failed to detour ExecuteStringCommand post.");
  36.  
  37. PrintToServer("CBaseClient::ExecuteStringCommand detoured!");
  38.  
  39.  
  40. StartPrepSDKCall(SDKCall_Raw);
  41. PrepSDKCall_SetVirtual(GetPlayerSlotOffs);
  42. PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
  43. hGetPlayerSlot = EndPrepSDKCall();
  44. }
  45.  
  46. public MRESReturn Detour_OnExecuteStringCommand(Address pThis, Handle hReturn, Handle hParams)
  47. {
  48. int client = SDKCall(hGetPlayerSlot, pThis) + 1;
  49.  
  50. char sBuffer[512];
  51. DHookGetParamString(hParams, 1, sBuffer, sizeof(sBuffer));
  52. PrintToServer("ExecuteStringCommand called on client %d: %s", client, sBuffer);
  53. return MRES_Ignored;
  54. }
  55.  
  56. public MRESReturn Detour_OnExecuteStringCommand_Post(Address pThis, Handle hReturn, Handle hParams)
  57. {
  58. int client = SDKCall(hGetPlayerSlot, pThis) + 1;
  59.  
  60. char sBuffer[512];
  61. DHookGetParamString(hParams, 1, sBuffer, sizeof(sBuffer));
  62. PrintToServer("ExecuteStringCommand post called on client %d (ret %d): %s", client, DHookGetReturn(hReturn), sBuffer);
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement