Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sdktools>
- #include <dhooks>
- // windows
- #define GetPlayerSlotOffs 16
- // linux
- //#define GetPlayerSlotOffs 4
- Handle hGetPlayerSlot;
- Handle hExecuteStringCommand;
- public void OnPluginStart()
- {
- Handle temp = LoadGameConfigFile("PTaH.games");
- if(temp == INVALID_HANDLE)
- {
- SetFailState("Why you no has gamedata?");
- }
- hExecuteStringCommand = DHookCreateDetour(Address_Null, CallConv_THISCALL, ReturnType_Bool, ThisPointer_Address);
- if (!hExecuteStringCommand)
- SetFailState("Failed to setup detour for ExecuteStringCommand");
- if (!DHookSetFromConf(hExecuteStringCommand, temp, SDKConf_Signature, "ExecuteStringCommand"))
- SetFailState("Failed to load ExecuteStringCommand signature from gamedata");
- DHookAddParam(hExecuteStringCommand, HookParamType_CharPtr);
- if (!DHookEnableDetour(hExecuteStringCommand, false, Detour_OnExecuteStringCommand))
- SetFailState("Failed to detour ExecuteStringCommand.");
- if (!DHookEnableDetour(hExecuteStringCommand, true, Detour_OnExecuteStringCommand_Post))
- SetFailState("Failed to detour ExecuteStringCommand post.");
- PrintToServer("CBaseClient::ExecuteStringCommand detoured!");
- StartPrepSDKCall(SDKCall_Raw);
- PrepSDKCall_SetVirtual(GetPlayerSlotOffs);
- PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
- hGetPlayerSlot = EndPrepSDKCall();
- }
- public MRESReturn Detour_OnExecuteStringCommand(Address pThis, Handle hReturn, Handle hParams)
- {
- int client = SDKCall(hGetPlayerSlot, pThis) + 1;
- char sBuffer[512];
- DHookGetParamString(hParams, 1, sBuffer, sizeof(sBuffer));
- PrintToServer("ExecuteStringCommand called on client %d: %s", client, sBuffer);
- return MRES_Ignored;
- }
- public MRESReturn Detour_OnExecuteStringCommand_Post(Address pThis, Handle hReturn, Handle hParams)
- {
- int client = SDKCall(hGetPlayerSlot, pThis) + 1;
- char sBuffer[512];
- DHookGetParamString(hParams, 1, sBuffer, sizeof(sBuffer));
- PrintToServer("ExecuteStringCommand post called on client %d (ret %d): %s", client, DHookGetReturn(hReturn), sBuffer);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement