Raised This Month: $12 Target: $400
 3% 

[EXTENSION] Hooker


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Fredd
Veteran Member
Join Date: Jul 2007
Old 05-18-2008 , 01:25   [EXTENSION] Hooker
Reply With Quote #1

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:
  • CSS
  • TF
  • HL2MP
  • DOD
  • INS

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
__________________
Need a private coder? AMXX, SourceMOD, MMS? PM me!

Last edited by Fredd; 06-09-2008 at 11:23.
Fredd is offline
Liam
SourceMod Developer
Join Date: Jan 2008
Location: Atlanta, GA
Old 05-18-2008 , 01:33   Re: [EXTENSION] Hooker *BETA
Reply With Quote #2

Great work!
Liam is offline
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 05-18-2008 , 01:39   Re: [EXTENSION] Hooker *BETA
Reply With Quote #3

Wow.

Great job...
__________________
http://www.nican132.com
I require reputation!

Last edited by Nican; 05-18-2008 at 01:42.
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 05-18-2008 , 02:30   Re: [EXTENSION] Hooker *BETA
Reply With Quote #4

Man, this is excellent stuff.
CrimsonGT is offline
raydan
Senior Member
Join Date: Aug 2006
Old 05-18-2008 , 04:29   Re: [EXTENSION] Hooker *BETA
Reply With Quote #5

great job!!

few question
1. all client hook/unhook when they connect/disconnect game?
2. if hook HK_*Touch, it will hook all entity? 1000 entity in server, got lag?
if entity remove it casue memory problem?

i got this problem in "Hacks", it make a code error, like
Code:
public OnClientPutInServer(client)
{
g_clientInGameScore[client] = 10000;
}
 
it got Array index is out of bounds, i 100% sure array size is enough
further questions
add a player command hook, same as HK_OnTakeDamage per hook, allow remove client command (like IN_JUMP, IN_DUCK)
raydan is offline
franzcis066
Member
Join Date: Nov 2007
Old 05-18-2008 , 10:04   Re: [EXTENSION] Hooker *BETA
Reply With Quote #6

I dunno if it is a bug or anything, I tried to blockHK_WeaponDrop, But in the game when someone wants to drop a weapon... It removed some of its ammos.
franzcis066 is offline
Exino
Junior Member
Join Date: Mar 2008
Old 05-18-2008 , 11:03   Re: [EXTENSION] Hooker *BETA
Reply With Quote #7

Looks awesome man!
Exino is offline
Fredd
Veteran Member
Join Date: Jul 2007
Old 05-18-2008 , 13:05   Re: [EXTENSION] Hooker *BETA
Reply With Quote #8

Quote:
Originally Posted by raydan View Post
great job!!

few question
1. all client hook/unhook when they connect/disconnect game?
2. if hook HK_*Touch, it will hook all entity? 1000 entity in server, got lag?
if entity remove it casue memory problem?

i got this problem in "Hacks", it make a code error, like
Code:
public OnClientPutInServer(client)
{
g_clientInGameScore[client] = 10000;
}
 
it got Array index is out of bounds, i 100% sure array size is enough
further questions
add a player command hook, same as HK_OnTakeDamage per hook, allow remove client command (like IN_JUMP, IN_DUCK)
1. yes
2. try not to hook every entity thats why i made the native 'AddHooksToEntity' to avoid having one forward for every game entity, if dont have a lot there wont be no lag issue, there shouldn't be a memory issue because sourcehook should unhook all of the hooks that are hooked when the entity because invalid

Quote:
Originally Posted by franzcis066 View Post
I dunno if it is a bug or anything, I tried to blockHK_WeaponDrop, But in the game when someone wants to drop a weapon... It removed some of its ammos.
are you sure, i have tested this feature in CS over 15 times and it seems to be fine...paste your code and let me take a look.
__________________
Need a private coder? AMXX, SourceMOD, MMS? PM me!
Fredd is offline
franzcis066
Member
Join Date: Nov 2007
Old 05-18-2008 , 13:14   Re: [EXTENSION] Hooker *BETA
Reply With Quote #9

Code:
public OnPluginStart()
{
        RegisterHook(HK_WeaponDrop, WeaponDrop, false);
}

public Action:WeaponDrop(client, weapon)
{
    decl String:WeaponName[64];
        GetEdictClassname(weapon, WeaponName, sizeof(WeaponName));
    if(StrEqual(WeaponName, "weapon_c4"))
    {
        return Plugin_Continue;
    }
    else
    {
        return Plugin_Handled;//Even if the code is only return Plugin_Handled it still the same..
    }
}
SourceMod Version "1.1.0.2119"
franzcis066 is offline
Fredd
Veteran Member
Join Date: Jul 2007
Old 05-18-2008 , 13:32   Re: [EXTENSION] Hooker *BETA
Reply With Quote #10

franzcis066@: you are right, the weapon drop is still blocked but the secondary ammo clip gets removed, but the thing is that the extension does not touch the clients ammo or anything of some sort, it simply blocks the weapon drop if returned Plugin_Handled so i assume this an issue with the game it self, and you can't really know since the only gun you can't drop is a knife and it doesn't have any ammo, so your best luck just getting the client secondary ammo value then creating a timer just after the block and setting it back.
__________________
Need a private coder? AMXX, SourceMOD, MMS? PM me!
Fredd is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:48.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode