PointServerCommandFilter: use dhooks2 instead of extension
Added !activator, !activator.name, !activator.steamid and !activator.team replacing
This commit is contained in:
parent
051348fb71
commit
ad45277f94
@ -42,7 +42,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// mp_ *
|
// mp_ *
|
||||||
"mp_flashlight" {}
|
|
||||||
"mp_freezetime"
|
"mp_freezetime"
|
||||||
{
|
{
|
||||||
"clamp"
|
"clamp"
|
||||||
@ -63,7 +62,7 @@
|
|||||||
"clamp"
|
"clamp"
|
||||||
{
|
{
|
||||||
"min" "1"
|
"min" "1"
|
||||||
"max" "16"
|
"max" "60"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"mp_timelimit"
|
"mp_timelimit"
|
||||||
@ -76,10 +75,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// sm_*
|
// sm_*
|
||||||
"sm" "plugins unload WeaponEquip"
|
"sm_gravity" {}
|
||||||
"sm_gravity" "/#STEAM_/"
|
"sm_freeze" {}
|
||||||
"sm_freeze" "/#STEAM_/"
|
"sm_slay" {}
|
||||||
"sm_slay" "@all"
|
|
||||||
"sm_say" {}
|
"sm_say" {}
|
||||||
"sm_csay" {}
|
"sm_csay" {}
|
||||||
"sm_tsay" {}
|
"sm_tsay" {}
|
||||||
@ -129,4 +127,5 @@
|
|||||||
"zr_ztele_max_zombie" {}
|
"zr_ztele_max_zombie" {}
|
||||||
"zr_ztele_max_human" {}
|
"zr_ztele_max_human" {}
|
||||||
"zr_ztele_autocancel" {}
|
"zr_ztele_autocancel" {}
|
||||||
|
"zr_config_reload" {}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
"Games"
|
||||||
|
{
|
||||||
|
"cstrike"
|
||||||
|
{
|
||||||
|
"Offsets"
|
||||||
|
{
|
||||||
|
"AcceptInput"
|
||||||
|
{
|
||||||
|
"windows" "36"
|
||||||
|
"linux" "37"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,16 @@
|
|||||||
#pragma semicolon 1
|
#pragma semicolon 1
|
||||||
#include <sourcemod>
|
#include <sourcemod>
|
||||||
|
#include <sdktools>
|
||||||
|
#include <cstrike>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <pscd>
|
#include <dhooks>
|
||||||
#pragma newdecls required
|
#pragma newdecls required
|
||||||
|
|
||||||
|
#define COMMAND_SIZE 1024
|
||||||
|
|
||||||
|
// bool CBaseEntity::AcceptInput( const char *szInputName, CBaseEntity *pActivator, CBaseEntity *pCaller, variant_t Value, int outputID )
|
||||||
|
Handle g_hAcceptInput;
|
||||||
|
|
||||||
StringMap g_Rules;
|
StringMap g_Rules;
|
||||||
ArrayList g_aRules;
|
ArrayList g_aRules;
|
||||||
ArrayList g_Regexes;
|
ArrayList g_Regexes;
|
||||||
@ -43,10 +50,99 @@ public Plugin myinfo =
|
|||||||
|
|
||||||
public void OnPluginStart()
|
public void OnPluginStart()
|
||||||
{
|
{
|
||||||
|
Handle hGameConf = LoadGameConfigFile("PointServerCommandFilter.games");
|
||||||
|
if(hGameConf == INVALID_HANDLE)
|
||||||
|
{
|
||||||
|
SetFailState("Couldn't load PointServerCommandFilter.games game config!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Offset = GameConfGetOffset(hGameConf, "AcceptInput");
|
||||||
|
g_hAcceptInput = DHookCreate(Offset, HookType_Entity, ReturnType_Bool, ThisPointer_CBaseEntity, AcceptInput);
|
||||||
|
DHookAddParam(g_hAcceptInput, HookParamType_CharPtr);
|
||||||
|
DHookAddParam(g_hAcceptInput, HookParamType_CBaseEntity);
|
||||||
|
DHookAddParam(g_hAcceptInput, HookParamType_CBaseEntity);
|
||||||
|
DHookAddParam(g_hAcceptInput, HookParamType_Object, 20, DHookPass_ByVal|DHookPass_ODTOR|DHookPass_OCTOR|DHookPass_OASSIGNOP); //varaint_t is a union of 12 (float[3]) plus two int type params 12 + 8 = 20
|
||||||
|
DHookAddParam(g_hAcceptInput, HookParamType_Int);
|
||||||
|
|
||||||
|
CloseHandle(hGameConf);
|
||||||
|
|
||||||
|
/* Late Load */
|
||||||
|
int entity = INVALID_ENT_REFERENCE;
|
||||||
|
while((entity = FindEntityByClassname(entity, "point_servercommand")) != INVALID_ENT_REFERENCE)
|
||||||
|
{
|
||||||
|
OnEntityCreated(entity, "point_servercommand");
|
||||||
|
}
|
||||||
|
|
||||||
LoadConfig();
|
LoadConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Action PointServerCommandForward(const char[] sOrigCommand)
|
public void OnEntityCreated(int entity, const char[] classname)
|
||||||
|
{
|
||||||
|
if(StrEqual(classname, "point_servercommand"))
|
||||||
|
{
|
||||||
|
DHookEntity(g_hAcceptInput, false, entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// bool CBaseEntity::AcceptInput( const char *szInputName, CBaseEntity *pActivator, CBaseEntity *pCaller, variant_t Value, int outputID )
|
||||||
|
public MRESReturn AcceptInput(int pThis, Handle hReturn, Handle hParams)
|
||||||
|
{
|
||||||
|
char szInputName[128];
|
||||||
|
DHookGetParamString(hParams, 1, szInputName, sizeof(szInputName));
|
||||||
|
|
||||||
|
if(!StrEqual(szInputName, "Command", true))
|
||||||
|
return MRES_Ignored;
|
||||||
|
|
||||||
|
int client = 0;
|
||||||
|
if(!DHookIsNullParam(hParams, 2))
|
||||||
|
client = DHookGetParam(hParams, 2);
|
||||||
|
|
||||||
|
char sCommand[COMMAND_SIZE];
|
||||||
|
DHookGetParamObjectPtrString(hParams, 4, 0, ObjectValueType_String, sCommand, sizeof(sCommand));
|
||||||
|
|
||||||
|
int bReplaced = 0;
|
||||||
|
if(client > 0 && client <= MaxClients && IsClientInGame(client))
|
||||||
|
{
|
||||||
|
char sName[MAX_NAME_LENGTH];
|
||||||
|
GetClientName(client, sName, sizeof(sName));
|
||||||
|
|
||||||
|
char sSteamId[32];
|
||||||
|
GetClientAuthId(client, AuthId_Engine, sSteamId, sizeof(sSteamId));
|
||||||
|
|
||||||
|
char sUserID[32];
|
||||||
|
FormatEx(sUserID, sizeof(sUserID), "#%d", GetClientUserId(client));
|
||||||
|
|
||||||
|
char sTeam[32];
|
||||||
|
if(GetClientTeam(client) == CS_TEAM_CT)
|
||||||
|
strcopy(sTeam, sizeof(sTeam), "@ct");
|
||||||
|
else if(GetClientTeam(client) == CS_TEAM_T)
|
||||||
|
strcopy(sTeam, sizeof(sTeam), "@t");
|
||||||
|
|
||||||
|
bReplaced += ReplaceString(sCommand, sizeof(sCommand), "!activator.name", sName, false);
|
||||||
|
bReplaced += ReplaceString(sCommand, sizeof(sCommand), "!activator.steamid", sSteamId, false);
|
||||||
|
bReplaced += ReplaceString(sCommand, sizeof(sCommand), "!activator.team", sTeam, false);
|
||||||
|
bReplaced += ReplaceString(sCommand, sizeof(sCommand), "!activator", sUserID, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Action iAction = PointServerCommandForward(sCommand);
|
||||||
|
|
||||||
|
if(iAction == Plugin_Stop)
|
||||||
|
{
|
||||||
|
DHookSetReturn(hReturn, false);
|
||||||
|
return MRES_Supercede;
|
||||||
|
}
|
||||||
|
else if(iAction == Plugin_Changed || bReplaced)
|
||||||
|
{
|
||||||
|
ServerCommand(sCommand);
|
||||||
|
DHookSetReturn(hReturn, true);
|
||||||
|
return MRES_Supercede;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MRES_Ignored;
|
||||||
|
}
|
||||||
|
|
||||||
|
Action PointServerCommandForward(char[] sOrigCommand)
|
||||||
{
|
{
|
||||||
static char sCommandRight[1024];
|
static char sCommandRight[1024];
|
||||||
static char sCommandLeft[128];
|
static char sCommandLeft[128];
|
||||||
@ -83,7 +179,7 @@ public Action PointServerCommandForward(const char[] sOrigCommand)
|
|||||||
return Plugin_Stop;
|
return Plugin_Stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
Action MatchRuleList(ArrayList RuleList, const char[] sOrigCommand, const char[] sCommandLeft, const char[] sCommandRight)
|
Action MatchRuleList(ArrayList RuleList, char[] sOrigCommand, const char[] sCommandLeft, const char[] sCommandRight)
|
||||||
{
|
{
|
||||||
for(int r = 0; r < RuleList.Length; r++)
|
for(int r = 0; r < RuleList.Length; r++)
|
||||||
{
|
{
|
||||||
@ -184,8 +280,8 @@ Action MatchRuleList(ArrayList RuleList, const char[] sOrigCommand, const char[]
|
|||||||
if(Clamp)
|
if(Clamp)
|
||||||
{
|
{
|
||||||
LogMessage("Clamped (%f -> %f): \"%s\"", IsValue, ClampValue, sOrigCommand);
|
LogMessage("Clamped (%f -> %f): \"%s\"", IsValue, ClampValue, sOrigCommand);
|
||||||
ServerCommand("%s %f", sCommandLeft, ClampValue);
|
FormatEx(sOrigCommand, COMMAND_SIZE, "%s %f", sCommandLeft, ClampValue);
|
||||||
return Plugin_Stop;
|
return Plugin_Changed;
|
||||||
}
|
}
|
||||||
else // Can this even happen? Yesh, dumb user. -> "clamp" {}
|
else // Can this even happen? Yesh, dumb user. -> "clamp" {}
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user