Current Version 1.1.0
well i got tired of not having virtual hooks in sourcepawn so i made this extension, i know there is a similar extension called "Hacks" but the author has left SourceMod and it's pretty much broken...so what does this extension exactly do? it catchs whenever clients connect/disconnect and it adds sourcehooks on them so all of the game clients are already prehooked for developers and it also you give the ability to hook other game entities other than clients...
Current Supported Games:
Natives and such..
Code:
/**
* Adds a Hook to a function
*
* @param type type of hook.
* @param func function name to send the hook to.
* @param post post hook or pre hook, pre=false and post=true.
* @noreturn
*/
native RegisterHook(HookType:type, Hooks:func, bool:post=false);
/**
* Adds hooks to the entity, then hooks will be retrieved using RegisterHook.
* @param type type of entity
* @param EntityIndex Entity index.
* @noreturn
* @error if entity is invalid or entity has been just created but has no propterties.
*/
native HookEntity(HK_Ents:type, EntityIndex);
/**
* Removes players hook.
*
* @param EntityIndex Entity index.
* @noreturn
*/
native UnHookPlayer(HK_Ents:type, PlayerIndex);
/**
* Forward called when an entity is created.
* @param EntIndex index of the entity that just got created.
* @param Classname classname of the entity that got created.
*/
forward HookerOnEntityCreated(EntIndex, const String:Classname[]);
Current available hook types...
Code:
HK_GameNameDescription
HK_WeaponDrop
HK_WeaponCanUse
HK_WeaponCanSwitchTo
HK_OnChangeActiveWeapon
HK_Touch
HK_StartTouch
HK_EndTouch
HK_EventKilled
HK_OnTakeDamage
HK_TraceAttack
HK_Spawn
HK_EntityThink
HK_ClientPreThink
HK_ClientPostThink
HK_PlayerJump
HK_PlayerDuck
HK_CommitSuicide
HK_Respawn
HK_SetModel
HK_ShowViewPortPanel
HK_ImpulseCommands
and these are the entity types that you should use with HookEntity and UnHookPlayer
Code:
HKE_CBaseEntity
HKE_CCSPlayer
HKE_CTFPlayer
HKE_CDODPlayer
HKE_CHL2MP_Player
HKE_CINSPlayer
IMPORTANT: all of the hooks work except HK_EventKilled/HK_OnTakeDamage/HK_TraceAttack in tf2, due to sdk issues with CTakeDamageInfo...
If you are wondering why i only have UnHookPlayer and not UnHookEntity is because i couldn't get any the IEntityFactoryDictionary:
estory working or maybe it wasn't just used by the game...so i figured out a way to unhook entites without having to worry about it in a plugin..in other words every time a plugin uses 'HookEntity' if the entity is not a player a manual hook called UpdateOnRemove will be hookoked to the entity and the moment this function gets called it will remove all of the hooks from the entity..a little hacky but thanks to lduke ;]
another reminder is that not every hook type works in every game some functions are not there for every game and some functions seem to have a different return type in just one game than the others(just one lol)...so please check 'hooker.games.txt' to make sure the function is listed for the game you are using...
ok since everything up there ^^ didn't make any sense here some good examples!
Changing damage in CSS
Code:
#pragma semicolon 1
#include <sourcemod>
#include <hooker>
public Plugin:myinfo =
{
name = "Changing Damage",
author = "Fredd",
description = "<- Description ->",
version = "",
url = "http://sourcemod.net/"
}
public OnPluginStart()
{
RegisterHook(HK_OnTakeDamage, TakeDamageFunction, false);
}
public OnClientPutInServer(client)
{
HookEntity(HKE_CCSPlayer, client);
}
public OnClientDisconnect(client)
{
UnHookPlayer(HKE_CCSPlayer, client);
}
public Action:TakeDamageFunction(client, &inflictor, &attacker, &Float:Damage, &DamageType, &AmmoType)
{
Damage += 10; //adds 10 to the damage
return Plugin_Changed; // tells the extension something was changed use the new value!
}
Blocking weapon switch:
Code:
#pragma semicolon 1
#include <sourcemod>
#include <hooker>
public Plugin:myinfo =
{
name = "No Weapon Switch",
author = "Fredd",
description = "<- Description ->",
version = "",
url = "http://sourcemod.net/"
}
public OnPluginStart()
{
RegisterHook(HK_WeaponCanSwitchTo, WeaponSwitchFunction, false);
}
public OnClientPutInServer(client)
{
HookEntity(HKE_CTFPlayer, client);
}
public OnClientDisconnect(client)
{
UnHookPlayer(HKE_CTFPlayer, client);
}
public Action:WeaponSwitchFunction(client, weapon)
{
decl String:cls[64];
GetEdictClassname(weapon, cls, sizeof(cls));
if(StrEqual(cls, "tf_weapon_rocketlauncher"))
{
PrintToChat(client, "no rocket launcher for you stupid!");
return Plugin_Handled; //tells the extension to block the weapon switch
}
return Plugin_Continue;
}
Using HookEntity on non player entity example
Code:
#pragma semicolon 1
#include <sourcemod>
#include <hooker>
public Plugin:myinfo =
{
name = "Using HookEntity on non players..",
author = "Fredd",
description = "<- Description ->",
version = "",
url = "http://sourcemod.net/"
}
public HookerOnEntityCreated(index, const String:Classname[])
{
if(strcmp(Classname, "prop_physics_multiplayer") == 0)
HookEntity(HKE_CBaseEntity, index);
}
public OnPluginStart()
{
RegisterHook(HK_Spawn, OnSpawnFunction, false);
}
public Action:OnSpawnFunction(entity)
{
//now this function will get called ONLY when a "prop_physics_multiplayer" spawns
// if a players were hooked this function will get calle don both players and "prop_physics_multiplayer" ents..
}
i know its kinda of weird how you need to to declare which type game player you adding hooks to but thats the deal since not every game has the same functions..if you trying to add a support for more than one game in your plugin is suggest using "GetGameFolderName" and playing around with the game types..
if you have any further questions or if you want me to add any new hooks i will be happy too...
Credits
BAILOPAN, LDuke, sawce, pred, sslice, cybermind, and everyone else on irc! thank you all
Changelog- 1.0.0 Intial Release
- 1.1.0 Added Bunch of stuff...
SOURCE CODE
DOWNLOAD PACKAGE
__________________