From ea25eb9aee67666b1d2281fa6e2de973fb9630a1 Mon Sep 17 00:00:00 2001 From: BotoX Date: Mon, 19 Dec 2016 08:33:16 +0100 Subject: [PATCH] refactor for dhooks2 --- NapalmLagFix/scripting/NapalmLagFix.sp | 88 +++++-------------- .../scripting/NoGrenadeRinging.sp | 19 ++-- includes/dhooks.inc | 9 +- 3 files changed, 39 insertions(+), 77 deletions(-) diff --git a/NapalmLagFix/scripting/NapalmLagFix.sp b/NapalmLagFix/scripting/NapalmLagFix.sp index 811c5dc1..1f31dddd 100644 --- a/NapalmLagFix/scripting/NapalmLagFix.sp +++ b/NapalmLagFix/scripting/NapalmLagFix.sp @@ -1,113 +1,65 @@ #pragma semicolon 1 +#pragma newdecls required #include #include -#undef REQUIRE_PLUGIN -#include +#include -#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")) diff --git a/NoGrenadeRinging/scripting/NoGrenadeRinging.sp b/NoGrenadeRinging/scripting/NoGrenadeRinging.sp index d5fcafb3..95f6d7fb 100644 --- a/NoGrenadeRinging/scripting/NoGrenadeRinging.sp +++ b/NoGrenadeRinging/scripting/NoGrenadeRinging.sp @@ -3,7 +3,7 @@ #include #include -//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; } diff --git a/includes/dhooks.inc b/includes/dhooks.inc index 9a1af292..1224c130 100644 --- a/includes/dhooks.inc +++ b/includes/dhooks.inc @@ -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 \ No newline at end of file +#endif