sm-plugins/NapalmLagFix/scripting/NapalmLagFix.sp

72 lines
2.0 KiB
SourcePawn
Raw Normal View History

2016-01-19 23:57:32 +01:00
#pragma semicolon 1
2016-12-19 08:33:16 +01:00
#pragma newdecls required
2016-01-19 23:57:32 +01:00
#include <sourcemod>
2016-12-19 08:33:16 +01:00
#include <sdkhooks>
#include <sdktools>
#include <dhooks>
2016-01-19 23:57:32 +01:00
2016-12-19 08:33:16 +01:00
Handle g_hRadiusDamage = INVALID_HANDLE;
2016-01-19 23:57:32 +01:00
2016-12-19 08:33:16 +01:00
public Plugin myinfo =
2016-01-19 23:57:32 +01:00
{
2016-12-19 08:33:16 +01:00
name = "Napalm Lag Fix",
2016-01-19 23:57:32 +01:00
author = "GoD-Tony + BotoX",
description = "Prevents lag when napalm is used on players",
2016-12-19 08:33:16 +01:00
version = "1.0.4",
url = "https://forums.alliedmods.net/showthread.php?t=188093"
2016-01-19 23:57:32 +01:00
};
2016-12-19 08:33:16 +01:00
public void OnPluginStart()
2016-01-19 23:57:32 +01:00
{
// Gamedata.
2016-12-19 08:33:16 +01:00
Handle hConfig = LoadGameConfigFile("napalmlagfix.games");
if(hConfig == INVALID_HANDLE)
2016-01-19 23:57:32 +01:00
SetFailState("Could not find gamedata file: napalmlagfix.games.txt");
2016-12-19 08:33:16 +01:00
int offset = GameConfGetOffset(hConfig, "RadiusDamage");
if(offset == -1)
2016-01-19 23:57:32 +01:00
SetFailState("Failed to find RadiusDamage offset");
CloseHandle(hConfig);
2016-12-19 08:33:16 +01:00
// DHooks
2016-01-19 23:57:32 +01:00
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
}
2016-12-19 08:33:16 +01:00
public void OnMapStart()
2016-01-19 23:57:32 +01:00
{
DHookGamerules(g_hRadiusDamage, false);
}
2016-12-19 08:33:16 +01:00
public MRESReturn Hook_RadiusDamage(Handle hParams)
2016-01-19 23:57:32 +01:00
{
2016-12-19 08:33:16 +01:00
if(DHookIsNullParam(hParams, 5))
2016-01-19 23:57:32 +01:00
return MRES_Ignored;
2016-12-19 08:33:16 +01:00
int iDmgBits = DHookGetParamObjectPtrVar(hParams, 1, 60, ObjectValueType_Int);
int iEntIgnore = DHookGetParam(hParams, 5);
2016-01-19 23:57:32 +01:00
if(!(iDmgBits & DMG_BURN))
return MRES_Ignored;
// Block napalm damage if it's coming from another client.
2016-12-19 08:33:16 +01:00
if(1 <= iEntIgnore <= MaxClients)
2016-01-19 23:57:32 +01:00
return MRES_Supercede;
// Block napalm that comes from grenades
2016-12-19 08:33:16 +01:00
char sEntClassName[64];
2016-01-19 23:57:32 +01:00
if(GetEntityClassname(iEntIgnore, sEntClassName, sizeof(sEntClassName)))
{
if(!strcmp(sEntClassName, "hegrenade_projectile"))
return MRES_Supercede;
}
return MRES_Ignored;
}