AlliedModders
XFactor Servers

[EXTENSION] SDK Hooks 1.3 (Updated 2010-05-12)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: Netherlands
Old 10-18-2009 , 11:15   [EXTENSION] SDK Hooks 1.3 (Updated 2010-05-12)
Reply With Quote #1

So here we are again Hacks, Hooker and DukeHacks are getting a bit outdated, and I didn't like how they were written, so I wrote this extension to combine the three of them, and to add some more goodies. Currently it supports CS:S, DOD:S, HL2DM, INS, L4D & TF2. Support for more mods can easily be added through the gamedata file, no editing of the extension required. Thanks to CrimsonGT for helping out with the CTakeDamageInfo hack, and pRED* for general C++ questions

Hook Types:
PHP Code:
enum SDKHookType
{
    
SDKHook_EndTouch,
    
SDKHook_FireBulletsPost,
    
SDKHook_OnTakeDamage,
    
SDKHook_OnTakeDamagePost,
    
SDKHook_PreThink,
    
SDKHook_PostThink,
    
SDKHook_SetTransmit,
    
SDKHook_Spawn,
    
SDKHook_StartTouch,
    
SDKHook_Think,
    
SDKHook_Touch,
    
SDKHook_TraceAttack,
    
SDKHook_TraceAttackPost,
    
SDKHook_WeaponCanSwitchTo,
    
SDKHook_WeaponCanUse,
    
SDKHook_WeaponDrop,
    
SDKHook_WeaponEquip,
    
SDKHook_WeaponSwitch

Hook Callbacks:
PHP Code:
funcenum SDKHookCB
{
    
// PreThink
    // PostThink
    
public(client),
    
// Spawn
    // Think
    
public(entity),
    
// EndTouch
    // StartTouch
    // Touch
    
public(entityother),
    
// SetTransmit
    
Action:public(entityclient),
    
// WeaponCanSwitchTo
    // WeaponCanUse
    // WeaponDrop
    // WeaponEquip
    // WeaponSwitch
    
Action:public(clientweapon),
    
// OnTakeDamage
    
Action:public(victim, &attacker, &inflictor, &Float:damage, &damagetype),
    
// OnTakeDamagePost
    
public(victimattackerinflictorFloat:damagedamagetype),
    
// FireBullets
    
public(clientshotsString:weaponname[]),
    
// TraceAttack
    
Action:public(victim, &attacker, &inflictor, &Float:damage, &damagetype, &ammotypehitboxhitgroup),
    
// TraceAttackPost
    
public(victimattackerinflictorFloat:damagedamagetypeammotypehitboxhitgroup)

Forwards:
PHP Code:
/**
 * @brief When an entity is created
 *
 * @param        entity        Entity index
 * @param        classname    Class name
 * @noreturn
 */
forward OnEntityCreated(entity, const String:classname[]);

/**
 * @brief When an entity is destroyed
 *
 * @param        entity        Entity index
 * @noreturn
 */
forward OnEntityDestroyed(entity);

/**
 * @brief When the game description is retrieved
 *
 * @param        gameDesc        Game description
 * @noreturn
 */
forward Action:OnGetGameDescription(String:gameDesc[64]);

/**
 * @brief When the level is initialized
 *
 * @param        mapName            Name of the map
 * @param        mapEntities    Entities of the map
 * @noreturn
 */
forward Action:OnLevelInit(const String:mapName[], String:mapEntities[2097152]); 
Natives:
PHP Code:
/**
 * @brief Hooks an entity
 *
 * @param        entity        Entity index
 * @param        type            Type of function to hook
 * @param        callback    Function to call when hook is called
 * @noreturn
 */
native SDKHook(entitySDKHookType:typeSDKHookCB:callback);

/**
 * @brief Unhooks an entity
 *
 * @param    entity   Entity index
 * @param    type     Type of function to unhook
 * @param    callback Callback function to unhook
 * @noreturn
 */
native SDKUnhook(entitySDKHookType:typeSDKHookCB:callback); 
Changelog
  • 1.3 (credits to psychonic)
    • Added four new requested hooktypes (PreThinkPost, PostThinkPost, ThinkPost, and ShouldCollide).
    • Fixed issue with sdk functions being hooked multiple times when multiple hooks of the same type are made (thanks to Sammy Rock! for catching that).
    • SDK Hooks will no longer load without having both the EntityFactoryDictionary signature and UpdateOnRemove offset present in sdkhooks.games.txt.
    • SDKHook native now errors when using a hooktype not supported (not in gamedata) for current mod.
    • Added new SDKHookEx native that does not error on unsuccessful hook but returns a success bool.
    • Fixed WeaponCanSwitchTo calling the WeaponCanUse forward (thanks to Greyscale for catching that).
    • Added debug server command "sdkhooks_listhooks" to list all current hooks.
    • Updated gamedata to add ShouldCollide for all supported games.
    • Updated gamedata to remove OnTakeDamage for L4D(2) as it does not function properly.
  • 1.2 (credits to psychonic)
    • Added two new hook types:
      - SDKHook_WeaponCanSwitchTo
      - SDKHook_WeaponCanUse
    • Added some error checking on entity index values passed from plugins.
    • Fixed clients not being unhooked when disconnecting.
    • Fixed hooks from a plugin not being removed when plugin unloads.
    • Fixed null pointer being passed in some cases on SDKHook_FireBulletsPost.
    • Fixed some minor inconsistencies between include and extension.
    • Fixed Makefile causing linux version to require GLIBC 2.4 (rhelgeby).
  • 1.1 (credits to psychonic)
    • Added OnGetGameDescription forward
    • Added FireBullets, OnTakeDamagePost, TraceAttack & TraceAttackPost hooks
    • Added support for Empires Mod, Fortress Forever, The Hidden: Source, Stargate: The Last Stand, Zombie Master & Zombie Panic: Source
  • 1.0
    • Initial release
Downloads
http://downloads.tsunami-productions.nl
__________________
My Plugins
Don't PM me asking for support, post in the plugin's topic.

Last edited by psychonic; 05-12-2010 at 12:22. Reason: enabled syntax highlighting on the code blocks :3
DJ Tsunami is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: Netherlands
Old 10-18-2009 , 11:15   Re: [EXTENSION] SDK Hooks
Reply With Quote #2

Examples

Adding a simple spawn hook:
Code:
public OnEntityCreated(entity, const String:classname[])
{
    SDKHook(entity, SDKHook_Spawn, OnEntitySpawned);
}

public OnEntitySpawned(entity)
{
    // Stuff here
}
Blocking secondary attack:
Code:
public OnClientPutInServer(client)
{
    SDKHook(client, SDKHook_PreThink, OnPreThink);
}

public OnPreThink(client)
{
    new iButtons = GetClientButtons(client);
    if(iButtons & IN_ATTACK2)
    {
        iButtons &= ~IN_ATTACK2;
        SetEntProp(client, Prop_Data, "m_nButtons", iButtons);
    }
}
Blocking switching to a specific weapon:
Code:
public OnClientPutInServer(client)
{
    SDKHook(client, SDKHook_WeaponSwitch, OnWeaponSwitch);
}

public Action:OnWeaponSwitch(client, weapon)
{
    decl String:sWeapon[32];
    GetEdictClassname(weapon, sWeapon, sizeof(sWeapon));
    
    if(StrEqual(sWeapon, "tf_weapon_rocketlauncher"))
        return Plugin_Handled;
    
    return Plugin_Continue;
}
Changing damage done by a specific weapon:
Code:
public OnClientPutInServer(client)
{
    SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
}

public Action:OnTakeDamage(victim, &attacker, &inflictor, &Float:damage, &damagetype)
{
    decl String:sWeapon[32];
    GetEdictClassname(inflictor, sWeapon, sizeof(sWeapon));
    
    if(StrEqual(sWeapon, "tf_weapon_flamethrower"))
    {
        damage *= 2.0;
        return Plugin_Changed;
    }
    
    return Plugin_Continue;
}
Note, you don't have to worry about unhooking every hook before the entity is destroyed, or before your plugin is unloaded, the extension automatically does that for you.
__________________
My Plugins
Don't PM me asking for support, post in the plugin's topic.

Last edited by DJ Tsunami; 10-19-2009 at 06:04.
DJ Tsunami is offline
Chris-_-
SourceMod Donor
Join Date: Oct 2008
Old 10-18-2009 , 11:48   Re: [EXTENSION] SDK Hooks
Reply With Quote #3

Great work, easy to keep track now
__________________
Chris-_- is offline
exvel
SourceMod Donor
Join Date: Jun 2006
Location: Russia
Old 10-18-2009 , 12:45   Re: [EXTENSION] SDK Hooks
Reply With Quote #4

I Tsunami =)
__________________
For admins: My plugins

For developers: Colors library
exvel is offline
Send a message via ICQ to exvel
exvel
SourceMod Donor
Join Date: Jun 2006
Location: Russia
Old 10-18-2009 , 12:48   Re: [EXTENSION] SDK Hooks
Reply With Quote #5

And wow! You have a SetTransmit hook! This is awesome. Could you explain a little bit is it possible to block/change transmitting of some net-properties?
__________________
For admins: My plugins

For developers: Colors library
exvel is offline
Send a message via ICQ to exvel
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: Netherlands
Old 10-18-2009 , 13:36   Re: [EXTENSION] SDK Hooks
Reply With Quote #6

It's for blocking transmission of entities to clients (so they won't see them). Not sure if that has anything to do with net properties, you just hook the entity and return Plugin_Handled if you don't want it to transmit (it's called on every frame).
__________________
My Plugins
Don't PM me asking for support, post in the plugin's topic.
DJ Tsunami is offline
exvel
SourceMod Donor
Join Date: Jun 2006
Location: Russia
Old 10-18-2009 , 14:49   Re: [EXTENSION] SDK Hooks
Reply With Quote #7

But if this hook is called for each client on game frame then we could change properties of entity right before transmitting it to specific client. This will be hard to test alone.
__________________
For admins: My plugins

For developers: Colors library

Last edited by exvel; 10-18-2009 at 14:51.
exvel is offline
Send a message via ICQ to exvel
Damizean
SourceMod Donor
Join Date: Mar 2009
Old 10-18-2009 , 15:16   Re: [EXTENSION] SDK Hooks
Reply With Quote #8

Cool, I had ported the Equipment Manager plugin to L4D but I found out Dukehacks wasn't compiled for it.

Kewl
__________________
Dat annoying guy
Damizean is offline
Send a message via AIM to Damizean Send a message via MSN to Damizean
exvel
SourceMod Donor
Join Date: Jun 2006
Location: Russia
Old 10-18-2009 , 15:45   Re: [EXTENSION] SDK Hooks
Reply With Quote #9

For some reason I can't get SetTransmit to work.
Tried this:
PHP Code:
public OnEntityCreated(entity, const String:classname[])
{
    
SDKHook(entitySDKHook_SetTransmitHook_SetTransmit);
}

public 
Action:Hook_SetTransmit(entityclient)
{
    return 
Plugin_Handled;

and this
PHP Code:
public OnClientPutInServer(client)
{
    
SDKHook(clientSDKHook_SetTransmitHook_SetTransmit);
}

public 
Action:Hook_SetTransmit(entityclient)
{
    return 
Plugin_Handled;

All entities show as usual.
windows, sm 1.2.3
__________________
For admins: My plugins

For developers: Colors library
exvel is offline
Send a message via ICQ to exvel
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: Netherlands
Old 10-18-2009 , 17:23   Re: [EXTENSION] SDK Hooks
Reply With Quote #10

Looks like I put the blocking code in the Spawn hook instead of the SetTransmit hook. I'll fix it tomorrow.
__________________
My Plugins
Don't PM me asking for support, post in the plugin's topic.
DJ Tsunami 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 22:55.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Theme made by Freecode Sponsored by Layered Technologies