refactor for dhooks2
This commit is contained in:
parent
2733e53800
commit
ea25eb9aee
@ -1,113 +1,65 @@
|
|||||||
#pragma semicolon 1
|
#pragma semicolon 1
|
||||||
|
#pragma newdecls required
|
||||||
|
|
||||||
#include <sourcemod>
|
#include <sourcemod>
|
||||||
#include <dhooks>
|
#include <dhooks>
|
||||||
#undef REQUIRE_PLUGIN
|
#include <sdkhooks>
|
||||||
#include <updater>
|
|
||||||
|
|
||||||
#define PLUGIN_NAME "Napalm Lag Fix"
|
Handle g_hRadiusDamage = INVALID_HANDLE;
|
||||||
#define PLUGIN_VERSION "1.0.3"
|
|
||||||
|
|
||||||
#define UPDATE_URL "http://godtony.mooo.com/napalmlagfix/napalmlagfix.txt"
|
public Plugin myinfo =
|
||||||
|
|
||||||
#define DMG_BURN (1 << 3)
|
|
||||||
|
|
||||||
new Handle:g_hRadiusDamage = INVALID_HANDLE;
|
|
||||||
new bool:g_bCheckNullPtr = false;
|
|
||||||
|
|
||||||
public Plugin:myinfo =
|
|
||||||
{
|
{
|
||||||
name = PLUGIN_NAME,
|
name = "Napalm Lag Fix",
|
||||||
author = "GoD-Tony + BotoX",
|
author = "GoD-Tony + BotoX",
|
||||||
description = "Prevents lag when napalm is used on players",
|
description = "Prevents lag when napalm is used on players",
|
||||||
version = PLUGIN_VERSION,
|
version = "1.0.4",
|
||||||
url = "https://forums.alliedmods.net/showthread.php?t=188093" // Demo: http://youtu.be/YdhAu5IEVVM
|
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.
|
// Gamedata.
|
||||||
new Handle:hConfig = LoadGameConfigFile("napalmlagfix.games");
|
Handle hConfig = LoadGameConfigFile("napalmlagfix.games");
|
||||||
|
if(hConfig == INVALID_HANDLE)
|
||||||
if (hConfig == INVALID_HANDLE)
|
|
||||||
{
|
|
||||||
SetFailState("Could not find gamedata file: napalmlagfix.games.txt");
|
SetFailState("Could not find gamedata file: napalmlagfix.games.txt");
|
||||||
}
|
|
||||||
|
|
||||||
new offset = GameConfGetOffset(hConfig, "RadiusDamage");
|
int offset = GameConfGetOffset(hConfig, "RadiusDamage");
|
||||||
|
if(offset == -1)
|
||||||
if (offset == -1)
|
|
||||||
{
|
|
||||||
SetFailState("Failed to find RadiusDamage offset");
|
SetFailState("Failed to find RadiusDamage offset");
|
||||||
}
|
|
||||||
|
|
||||||
CloseHandle(hConfig);
|
CloseHandle(hConfig);
|
||||||
|
|
||||||
// DHooks.
|
// DHooks
|
||||||
g_bCheckNullPtr = (GetFeatureStatus(FeatureType_Native, "DHookIsNullParam") == FeatureStatus_Available);
|
|
||||||
|
|
||||||
g_hRadiusDamage = DHookCreate(offset, HookType_GameRules, ReturnType_Void, ThisPointer_Ignore, Hook_RadiusDamage);
|
g_hRadiusDamage = DHookCreate(offset, HookType_GameRules, ReturnType_Void, ThisPointer_Ignore, Hook_RadiusDamage);
|
||||||
DHookAddParam(g_hRadiusDamage, HookParamType_ObjectPtr); // 1 - CTakeDamageInfo &info
|
DHookAddParam(g_hRadiusDamage, HookParamType_ObjectPtr); // 1 - CTakeDamageInfo &info
|
||||||
DHookAddParam(g_hRadiusDamage, HookParamType_VectorPtr); // 2 - Vector &vecSrc
|
DHookAddParam(g_hRadiusDamage, HookParamType_VectorPtr); // 2 - Vector &vecSrc
|
||||||
DHookAddParam(g_hRadiusDamage, HookParamType_Float); // 3 - float flRadius
|
DHookAddParam(g_hRadiusDamage, HookParamType_Float); // 3 - float flRadius
|
||||||
DHookAddParam(g_hRadiusDamage, HookParamType_Int); // 4 - int iClassIgnore
|
DHookAddParam(g_hRadiusDamage, HookParamType_Int); // 4 - int iClassIgnore
|
||||||
DHookAddParam(g_hRadiusDamage, HookParamType_CBaseEntity); // 5 - CBaseEntity *pEntityIgnore
|
DHookAddParam(g_hRadiusDamage, HookParamType_CBaseEntity); // 5 - CBaseEntity *pEntityIgnore
|
||||||
|
|
||||||
// Updater.
|
|
||||||
if (LibraryExists("updater"))
|
|
||||||
{
|
|
||||||
Updater_AddPlugin(UPDATE_URL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public OnLibraryAdded(const String:name[])
|
public void OnMapStart()
|
||||||
{
|
|
||||||
if (StrEqual(name, "updater"))
|
|
||||||
{
|
|
||||||
Updater_AddPlugin(UPDATE_URL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Updater_OnPluginUpdated()
|
|
||||||
{
|
|
||||||
// There could be new gamedata in this update.
|
|
||||||
ReloadPlugin();
|
|
||||||
}
|
|
||||||
|
|
||||||
public OnMapStart()
|
|
||||||
{
|
{
|
||||||
DHookGamerules(g_hRadiusDamage, false);
|
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(DHookIsNullParam(hParams, 5))
|
||||||
if (g_bCheckNullPtr && DHookIsNullParam(hParams, 5))
|
|
||||||
return MRES_Ignored;
|
return MRES_Ignored;
|
||||||
|
|
||||||
new iDmgBits = DHookGetParamObjectPtrVar(hParams, 1, 60, ObjectValueType_Int);
|
int iDmgBits = DHookGetParamObjectPtrVar(hParams, 1, 60, ObjectValueType_Int);
|
||||||
new iEntIgnore = DHookGetParam(hParams, 5);
|
int iEntIgnore = DHookGetParam(hParams, 5);
|
||||||
|
|
||||||
if(!(iDmgBits & DMG_BURN))
|
if(!(iDmgBits & DMG_BURN))
|
||||||
return MRES_Ignored;
|
return MRES_Ignored;
|
||||||
|
|
||||||
// Block napalm damage if it's coming from another client.
|
// Block napalm damage if it's coming from another client.
|
||||||
if (1 <= iEntIgnore <= MaxClients)
|
if(1 <= iEntIgnore <= MaxClients)
|
||||||
return MRES_Supercede;
|
return MRES_Supercede;
|
||||||
|
|
||||||
// Block napalm that comes from grenades
|
// Block napalm that comes from grenades
|
||||||
new String:sEntClassName[64];
|
char sEntClassName[64];
|
||||||
if(GetEntityClassname(iEntIgnore, sEntClassName, sizeof(sEntClassName)))
|
if(GetEntityClassname(iEntIgnore, sEntClassName, sizeof(sEntClassName)))
|
||||||
{
|
{
|
||||||
if(!strcmp(sEntClassName, "hegrenade_projectile"))
|
if(!strcmp(sEntClassName, "hegrenade_projectile"))
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include <sdktools>
|
#include <sdktools>
|
||||||
#include <dhooks>
|
#include <dhooks>
|
||||||
|
|
||||||
//int CCSPlayer::OnDamagedByExplosion(CTakeDamageInfo const&)
|
// int CCSPlayer::OnDamagedByExplosion(CTakeDamageInfo const&)
|
||||||
Handle g_hDamagedByExplosion;
|
Handle g_hDamagedByExplosion;
|
||||||
|
|
||||||
public Plugin myinfo =
|
public Plugin myinfo =
|
||||||
@ -11,7 +11,7 @@ public Plugin myinfo =
|
|||||||
name = "NoGrenadeRinging",
|
name = "NoGrenadeRinging",
|
||||||
author = "BotoX",
|
author = "BotoX",
|
||||||
description = "Block the annoying ringing noise when a grenade explodes next to you",
|
description = "Block the annoying ringing noise when a grenade explodes next to you",
|
||||||
version = "1.0",
|
version = "1.0.1",
|
||||||
url = ""
|
url = ""
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -24,19 +24,26 @@ public void OnPluginStart()
|
|||||||
int Offset = GameConfGetOffset(hTemp, "OnDamagedByExplosion");
|
int Offset = GameConfGetOffset(hTemp, "OnDamagedByExplosion");
|
||||||
g_hDamagedByExplosion = DHookCreate(Offset, HookType_Entity, ReturnType_Int, ThisPointer_CBaseEntity, OnDamagedByExplosion);
|
g_hDamagedByExplosion = DHookCreate(Offset, HookType_Entity, ReturnType_Int, ThisPointer_CBaseEntity, OnDamagedByExplosion);
|
||||||
DHookAddParam(g_hDamagedByExplosion, HookParamType_ObjectPtr);
|
DHookAddParam(g_hDamagedByExplosion, HookParamType_ObjectPtr);
|
||||||
|
|
||||||
CloseHandle(hTemp);
|
CloseHandle(hTemp);
|
||||||
|
|
||||||
|
/* Late load */
|
||||||
|
for(int client = 1; client <= MaxClients; client++)
|
||||||
|
{
|
||||||
|
if(IsClientInGame(client))
|
||||||
|
OnClientPutInServer(client);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnClientPutInServer(int 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);
|
DHookEntity(g_hDamagedByExplosion, false, client);
|
||||||
}
|
}
|
||||||
|
|
||||||
//int CCSPlayer::OnDamagedByExplosion(CTakeDamageInfo const&)
|
// int CCSPlayer::OnDamagedByExplosion(CTakeDamageInfo const&)
|
||||||
public MRESReturn:OnDamagedByExplosion(int pThis, Handle hReturn, Handle hParams)
|
public MRESReturn OnDamagedByExplosion(int pThis, Handle hReturn, Handle hParams)
|
||||||
{
|
{
|
||||||
// Block call
|
// Block call
|
||||||
|
DHookSetReturn(hReturn, 0);
|
||||||
return MRES_Supercede;
|
return MRES_Supercede;
|
||||||
}
|
}
|
||||||
|
@ -84,8 +84,11 @@ enum MRESReturn
|
|||||||
|
|
||||||
enum DHookPassFlag
|
enum DHookPassFlag
|
||||||
{
|
{
|
||||||
DHookPass_ByVal = (1<<0),
|
DHookPass_ByVal = (1<<0), /**< Passing by value */
|
||||||
DHookPass_ByRef = (1<<1)
|
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
|
typeset ListenCB
|
||||||
@ -479,4 +482,4 @@ public __ext_dhooks_SetNTVOptional()
|
|||||||
MarkNativeAsOptional("DHookIsNullParam");
|
MarkNativeAsOptional("DHookIsNullParam");
|
||||||
MarkNativeAsOptional("DHookGetParamObjectPtrString");
|
MarkNativeAsOptional("DHookGetParamObjectPtrString");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user