Raised This Month: $7 Target: $400
 1% 

SDK Hooks 2.1 - Updated 2011-9-10


Post New Thread Closed Thread   
 
Thread Tools Display Modes
Author Message
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 10-18-2009 , 11:15   SDK Hooks 2.1 - Updated 2011-9-10
#1

SDK Hooks is now included with SourceMod 1.5. Previous versions are unsupported.

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 almost every game and mod that SourceMod itself does. 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:
Code:
SDKHook_EndTouch
SDKHook_EndTouchPost
SDKHook_FireBulletsPost
SDKHook_GroundEntChangedPost
SDKHook_OnTakeDamage
SDKHook_OnTakeDamagePost
SDKHook_PreThink
SDKHook_PreThinkPost
SDKHook_PostThink
SDKHook_PostThinkPost
SDKHook_Reload
SDKHook_ReloadPost
SDKHook_SetTransmit
SDKHook_ShouldCollide
SDKHook_Spawn
SDKHook_SpawnPost
SDKHook_StartTouch
SDKHook_StartTouchPost
SDKHook_Think
SDKHook_ThinkPost
SDKHook_Touch
SDKHook_TouchPost
SDKHook_TraceAttack
SDKHook_TraceAttackPost
SDKHook_Use
SDKHook_UsePost
SDKHook_VPhysicsUpdate
SDKHook_VPhysicsUpdatePost
SDKHook_WeaponCanSwitchTo
SDKHook_WeaponCanSwitchToPost
SDKHook_WeaponCanUse
SDKHook_WeaponCanUsePost
SDKHook_WeaponDrop
SDKHook_WeaponDropPost
Hook Callbacks:
< see sdkhooks.inc >

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 Hooks an entity
 *
 * @param        entity        Entity index
 * @param        type            Type of function to hook
 * @param        callback    Function to call when hook is called
 * @return        bool        Hook Successful
 */
native bool:SDKHookEx(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);

/**
 * @brief Applies damage to an entity
 *
 * @note Force application is dependent on game and damage type(s)
 *
 * @param    entity         Entity index taking damage
 * @param    inflictor      Inflictor entity index
 * @param    attacker       Attacker entity index
 * @param    damage         Amount of damage
 * @param    damageType     Bitfield of damage types
 * @param    weapon         Weapon index (orangebox and later) or -1 for unspecified
 * @param    damageForce    Velocity of damage force
 * @param    damagePosition Origin of damage
 * @noreturn
 */
native SDKHooks_TakeDamage(entityinflictorattackerFloat:damagedamageType=DMG_GENERICweapon=-1, const Float:damageForce[3]=NULL_VECTOR, const Float:damagePosition[3]=NULL_VECTOR);

/**
 * @brief                Forces a client to drop the specified weapon
 *
 * @param client        Client index.
 * @param weapon        Weapon entity index.
 * @param vecTarget        Location to toss weapon to, or NULL_VECTOR for default.
 * @param vecVelocity    Velocity at which to toss weapon, or NULL_VECTOR for default.
 * @noreturn
 * @error                Invalid client or weapon entity, weapon not owned by client.
 */
native SDKHooks_DropWeapon(clientweapon, const Float:vecTarget[3]=NULL_VECTOR, const Float:vecVelocity[3]=NULL_VECTOR); 
Changelog
  • 2.1 (psychonic)
    • Updated gamedata for many games.
    • Added gamedata for Nuclear Dawn, Age of Chivalry, and CSPromod by request.
    • Fixed a case where extremely invalid entity indexes were passed through to to some callbacks (notably WeaponDrop) rather than -1 for invalid.
    • Fixed a case where 4095 was being passed for invalid ent indexes rather than -1.
    • Added more safety checks when hooking to guard against hooking functions that don't exist on type of given entity. Will now error instead of crash.
    • Initial game description now gets populated properly before being passed to OnGetGameDescription forward.
    • Added Reload and ReloadPost hooks by request. Note that you should be hooking the weapon rather than the player.
    • SDKHook_Spawn is now blockable by returning Plugin_Handled.
    • Added "damagecustom" value to ontakedamage hooks. To check for support of this at runtime, check the status of the "SDKHook_DmgCustomInOTD" feature.
    • Fixed player penetration count sometimes getting set to random values in TF2 when using SDKHooks_TakeDamage native.
  • 2.0 (psychonic)
    • Fixed loading issue on EP2V after 2011-04-14 update.
    • Updated lots of gamedata.
    • Added support for Alien Swarm, Dino D-Day, Dark Messiah, and Bloody Good Time.
    • Added the much-requested 'TakeDamage' native that DukeHacks had.
    • Added SDKHooks_DropWeapon native.
    • Added many new posthook types for existing hook types.
    • Added VPhysicsThink, GroundEntChanged, and Use hooks.
    • Passing and allowing changes to the damage force and position OnTakeDamage are now enabled (think: removing knockback).
    • Touch hooks are now blockable.
    • Made (breaking) changes to ShouldCollide hook to make it behave as expected.
    • SDKHooks now registers a library, "sdkhooks", for use with LibraryExists, OnLibraryAdded, and OnLibraryRemoved natives in SM.
    • Much code cleanup, mostly by Tsunami
    • Distribution simplified. (single package with files for all platforms)
  • 1.3 (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 (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 (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 (Tsunami)
    • Initial release

Upgrading from 1.x.x to 2.0.0:

For users,
  • Your existing plugins that use SDKHooks should continue to work fine (with the exception of ones that use the ShouldCollide hook)
  • Before upgrading, stop your gameserver and delete the following files if they exist or SDKHooks 2.x.x will not load.
    • gamedata/sdkhooks.games.txt
    • extensions/sdkhooks.ext.dll
    • extensions/sdkhooks.ext.so

For developers,
  • Any plugins that use the ShouldCollide hook will need to be updated and recompiled with the new callback prototype.
  • If you take advantage of any features new to SDKHooks 2.0, your plugin will need a recompile (obviously) and SDKHooks 2.0 will be required. Else, it should still load on 1.x.
  • The new, preferred method to detect the optional existance of SDKHooks is checking for the "sdkhooks" library rather than getting the extension status. This will guarantee that it is 2.0 or higher and is loaded.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.

Last edited by DJ Tsunami; 09-22-2013 at 11:05.
DJ Tsunami is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 10-18-2009 , 11:15   Re: [EXTENSION] SDK Hooks
#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 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.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.

Last edited by psychonic; 12-07-2011 at 10:07.
DJ Tsunami is offline
Chris-_-
SourceMod Donor
Join Date: Oct 2008
Old 10-18-2009 , 11:48   Re: [EXTENSION] SDK Hooks
#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
#4

I <3 Tsunami =)
__________________
For admins: My plugins

For developers: Colors library

Last edited by asherkin; 12-18-2010 at 02:02. Reason: Removed <3 graphic due to malware warning.
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
#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: The Netherlands
Old 10-18-2009 , 13:36   Re: [EXTENSION] SDK Hooks
#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).
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.
DJ Tsunami is offline
exvel
SourceMod Donor
Join Date: Jun 2006
Location: Russia
Old 10-18-2009 , 14:49   Re: [EXTENSION] SDK Hooks
#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
#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
#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: The Netherlands
Old 10-18-2009 , 17:23   Re: [EXTENSION] SDK Hooks
#10

Looks like I put the blocking code in the Spawn hook instead of the SetTransmit hook. I'll fix it tomorrow.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.
DJ Tsunami is offline
Closed Thread


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 05:51.


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