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
/** * @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(entity, SDKHookType:type, SDKHookCB: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(entity, SDKHookType:type, SDKHookCB: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(entity, SDKHookType:type, SDKHookCB: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(entity, inflictor, attacker, Float:damage, damageType=DMG_GENERIC, weapon=-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(client, weapon, 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).