refactor for dhooks2

This commit is contained in:
BotoX 2016-12-19 08:33:16 +01:00
parent 2733e53800
commit ea25eb9aee
3 changed files with 39 additions and 77 deletions

View File

@ -1,113 +1,65 @@
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <dhooks>
#undef REQUIRE_PLUGIN
#include <updater>
#include <sdkhooks>
#define PLUGIN_NAME "Napalm Lag Fix"
#define PLUGIN_VERSION "1.0.3"
Handle g_hRadiusDamage = INVALID_HANDLE;
#define UPDATE_URL "http://godtony.mooo.com/napalmlagfix/napalmlagfix.txt"
#define DMG_BURN (1 << 3)
new Handle:g_hRadiusDamage = INVALID_HANDLE;
new bool:g_bCheckNullPtr = false;
public Plugin:myinfo =
public Plugin myinfo =
{
name = PLUGIN_NAME,
name = "Napalm Lag Fix",
author = "GoD-Tony + BotoX",
description = "Prevents lag when napalm is used on players",
version = PLUGIN_VERSION,
url = "https://forums.alliedmods.net/showthread.php?t=188093" // Demo: http://youtu.be/YdhAu5IEVVM
version = "1.0.4",
url = "https://forums.alliedmods.net/showthread.php?t=188093"
};
public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
public void OnPluginStart()
{
MarkNativeAsOptional("DHookIsNullParam");
return APLRes_Success;
}
public OnPluginStart()
{
// Convars.
new Handle:hCvar = CreateConVar("sm_napalmlagfix_version", PLUGIN_VERSION, PLUGIN_NAME, FCVAR_NOTIFY|FCVAR_DONTRECORD);
SetConVarString(hCvar, PLUGIN_VERSION);
// Gamedata.
new Handle:hConfig = LoadGameConfigFile("napalmlagfix.games");
if (hConfig == INVALID_HANDLE)
{
Handle hConfig = LoadGameConfigFile("napalmlagfix.games");
if(hConfig == INVALID_HANDLE)
SetFailState("Could not find gamedata file: napalmlagfix.games.txt");
}
new offset = GameConfGetOffset(hConfig, "RadiusDamage");
if (offset == -1)
{
int offset = GameConfGetOffset(hConfig, "RadiusDamage");
if(offset == -1)
SetFailState("Failed to find RadiusDamage offset");
}
CloseHandle(hConfig);
// DHooks.
g_bCheckNullPtr = (GetFeatureStatus(FeatureType_Native, "DHookIsNullParam") == FeatureStatus_Available);
// DHooks
g_hRadiusDamage = DHookCreate(offset, HookType_GameRules, ReturnType_Void, ThisPointer_Ignore, Hook_RadiusDamage);
DHookAddParam(g_hRadiusDamage, HookParamType_ObjectPtr); // 1 - CTakeDamageInfo &info
DHookAddParam(g_hRadiusDamage, HookParamType_VectorPtr); // 2 - Vector &vecSrc
DHookAddParam(g_hRadiusDamage, HookParamType_Float); // 3 - float flRadius
DHookAddParam(g_hRadiusDamage, HookParamType_Int); // 4 - int iClassIgnore
DHookAddParam(g_hRadiusDamage, HookParamType_CBaseEntity); // 5 - CBaseEntity *pEntityIgnore
// Updater.
if (LibraryExists("updater"))
{
Updater_AddPlugin(UPDATE_URL);
}
}
public OnLibraryAdded(const String:name[])
{
if (StrEqual(name, "updater"))
{
Updater_AddPlugin(UPDATE_URL);
}
}
public Updater_OnPluginUpdated()
{
// There could be new gamedata in this update.
ReloadPlugin();
}
public OnMapStart()
public void OnMapStart()
{
DHookGamerules(g_hRadiusDamage, false);
}
public MRESReturn:Hook_RadiusDamage(Handle:hParams)
public MRESReturn Hook_RadiusDamage(Handle hParams)
{
// As of DHooks 1.0.12 we must check for a null param.
if (g_bCheckNullPtr && DHookIsNullParam(hParams, 5))
if(DHookIsNullParam(hParams, 5))
return MRES_Ignored;
new iDmgBits = DHookGetParamObjectPtrVar(hParams, 1, 60, ObjectValueType_Int);
new iEntIgnore = DHookGetParam(hParams, 5);
int iDmgBits = DHookGetParamObjectPtrVar(hParams, 1, 60, ObjectValueType_Int);
int iEntIgnore = DHookGetParam(hParams, 5);
if(!(iDmgBits & DMG_BURN))
return MRES_Ignored;
// Block napalm damage if it's coming from another client.
if (1 <= iEntIgnore <= MaxClients)
if(1 <= iEntIgnore <= MaxClients)
return MRES_Supercede;
// Block napalm that comes from grenades
new String:sEntClassName[64];
char sEntClassName[64];
if(GetEntityClassname(iEntIgnore, sEntClassName, sizeof(sEntClassName)))
{
if(!strcmp(sEntClassName, "hegrenade_projectile"))

View File

@ -3,7 +3,7 @@
#include <sdktools>
#include <dhooks>
//int CCSPlayer::OnDamagedByExplosion(CTakeDamageInfo const&)
// int CCSPlayer::OnDamagedByExplosion(CTakeDamageInfo const&)
Handle g_hDamagedByExplosion;
public Plugin myinfo =
@ -11,7 +11,7 @@ public Plugin myinfo =
name = "NoGrenadeRinging",
author = "BotoX",
description = "Block the annoying ringing noise when a grenade explodes next to you",
version = "1.0",
version = "1.0.1",
url = ""
};
@ -24,19 +24,26 @@ public void OnPluginStart()
int Offset = GameConfGetOffset(hTemp, "OnDamagedByExplosion");
g_hDamagedByExplosion = DHookCreate(Offset, HookType_Entity, ReturnType_Int, ThisPointer_CBaseEntity, OnDamagedByExplosion);
DHookAddParam(g_hDamagedByExplosion, HookParamType_ObjectPtr);
CloseHandle(hTemp);
/* Late load */
for(int client = 1; client <= MaxClients; client++)
{
if(IsClientInGame(client))
OnClientPutInServer(client);
}
}
public void OnClientPutInServer(int client)
{
//Dont add removal callback for this one
// Don't add removal callback for this one
DHookEntity(g_hDamagedByExplosion, false, client);
}
//int CCSPlayer::OnDamagedByExplosion(CTakeDamageInfo const&)
public MRESReturn:OnDamagedByExplosion(int pThis, Handle hReturn, Handle hParams)
// int CCSPlayer::OnDamagedByExplosion(CTakeDamageInfo const&)
public MRESReturn OnDamagedByExplosion(int pThis, Handle hReturn, Handle hParams)
{
// Block call
DHookSetReturn(hReturn, 0);
return MRES_Supercede;
}

View File

@ -84,8 +84,11 @@ enum MRESReturn
enum DHookPassFlag
{
DHookPass_ByVal = (1<<0),
DHookPass_ByRef = (1<<1)
DHookPass_ByVal = (1<<0), /**< Passing by value */
DHookPass_ByRef = (1<<1), /**< Passing by reference */
DHookPass_ODTOR = (1<<2), /**< Object has a destructor */
DHookPass_OCTOR = (1<<3), /**< Object has a constructor */
DHookPass_OASSIGNOP = (1<<4), /**< Object has an assignment operator */
};
typeset ListenCB
@ -479,4 +482,4 @@ public __ext_dhooks_SetNTVOptional()
MarkNativeAsOptional("DHookIsNullParam");
MarkNativeAsOptional("DHookGetParamObjectPtrString");
}
#endif
#endif