/sourcemod/scripting/include/sdkhooks.inc

https://bitbucket.org/ksanderson/sdkhooks · Pascal · 373 lines · 180 code · 41 blank · 152 comment · 4 complexity · a068d295aa1b1f883772863fe2ade205 MD5 · raw file

  1. #if defined _sdkhooks_included
  2. #endinput
  3. #endif
  4. #define _sdkhooks_included
  5. // this is obviously _not_ a robust check, but it will solve most conflict and is clean
  6. #if !defined DMG_GENERIC
  7. #define DMG_GENERIC 0 // generic damage was done
  8. #define DMG_CRUSH (1 << 0) // crushed by falling or moving object.
  9. // NOTE: It's assumed crush damage is occurring as a result of physics collision, so no extra physics force is generated by crush damage.
  10. // DON'T use DMG_CRUSH when damaging entities unless it's the result of a physics collision. You probably want DMG_CLUB instead.
  11. #define DMG_BULLET (1 << 1) // shot
  12. #define DMG_SLASH (1 << 2) // cut, clawed, stabbed
  13. #define DMG_BURN (1 << 3) // heat burned
  14. #define DMG_VEHICLE (1 << 4) // hit by a vehicle
  15. #define DMG_FALL (1 << 5) // fell too far
  16. #define DMG_BLAST (1 << 6) // explosive blast damage
  17. #define DMG_CLUB (1 << 7) // crowbar, punch, headbutt
  18. #define DMG_SHOCK (1 << 8) // electric shock
  19. #define DMG_SONIC (1 << 9) // sound pulse shockwave
  20. #define DMG_ENERGYBEAM (1 << 10) // laser or other high energy beam
  21. #define DMG_PREVENT_PHYSICS_FORCE (1 << 11) // Prevent a physics force
  22. #define DMG_NEVERGIB (1 << 12) // with this bit OR'd in, no damage type will be able to gib victims upon death
  23. #define DMG_ALWAYSGIB (1 << 13) // with this bit OR'd in, any damage type can be made to gib victims upon death.
  24. #define DMG_DROWN (1 << 14) // Drowning
  25. #define DMG_PARALYZE (1 << 15) // slows affected creature down
  26. #define DMG_NERVEGAS (1 << 16) // nerve toxins, very bad
  27. #define DMG_POISON (1 << 17) // blood poisoning - heals over time like drowning damage
  28. #define DMG_RADIATION (1 << 18) // radiation exposure
  29. #define DMG_DROWNRECOVER (1 << 19) // drowning recovery
  30. #define DMG_ACID (1 << 20) // toxic chemicals or acid burns
  31. #define DMG_SLOWBURN (1 << 21) // in an oven
  32. #define DMG_REMOVENORAGDOLL (1 << 22) // with this bit OR'd in, no ragdoll will be created, and the target will be quietly removed.
  33. // use this to kill an entity that you've already got a server-side ragdoll for
  34. #define DMG_PHYSGUN (1 << 23) // Hit by manipulator. Usually doesn't do any damage.
  35. #define DMG_PLASMA (1 << 24) // Shot by Cremator
  36. #define DMG_AIRBOAT (1 << 25) // Hit by the airboat's gun
  37. #define DMG_DISSOLVE (1 << 26) // Dissolving!
  38. #define DMG_BLAST_SURFACE (1 << 27) // A blast on the surface of water that cannot harm things underwater
  39. #define DMG_DIRECT (1 << 28)
  40. #define DMG_BUCKSHOT (1 << 29) // not quite a bullet. Little, rounder, different.
  41. #endif
  42. #if !defined DMG_CRIT
  43. // TF2 crits and minicrits
  44. #define DMG_CRIT DMG_ACID
  45. #endif
  46. enum SDKHookType
  47. {
  48. SDKHook_EndTouch,
  49. SDKHook_FireBulletsPost,
  50. SDKHook_OnTakeDamage,
  51. SDKHook_OnTakeDamagePost,
  52. SDKHook_PreThink,
  53. SDKHook_PostThink,
  54. SDKHook_SetTransmit,
  55. SDKHook_Spawn,
  56. SDKHook_StartTouch,
  57. SDKHook_Think,
  58. SDKHook_Touch,
  59. SDKHook_TraceAttack,
  60. SDKHook_TraceAttackPost,
  61. SDKHook_WeaponCanSwitchTo,
  62. SDKHook_WeaponCanUse,
  63. SDKHook_WeaponDrop,
  64. SDKHook_WeaponEquip,
  65. SDKHook_WeaponSwitch,
  66. SDKHook_ShouldCollide,
  67. SDKHook_PreThinkPost,
  68. SDKHook_PostThinkPost,
  69. SDKHook_ThinkPost,
  70. SDKHook_EndTouchPost,
  71. SDKHook_GroundEntChangedPost,
  72. SDKHook_SpawnPost,
  73. SDKHook_StartTouchPost,
  74. SDKHook_TouchPost,
  75. SDKHook_VPhysicsUpdate,
  76. SDKHook_VPhysicsUpdatePost,
  77. SDKHook_WeaponCanSwitchToPost,
  78. SDKHook_WeaponCanUsePost,
  79. SDKHook_WeaponDropPost,
  80. SDKHook_WeaponEquipPost,
  81. SDKHook_WeaponSwitchPost,
  82. SDKHook_Use,
  83. SDKHook_UsePost,
  84. SDKHook_Reload,
  85. SDKHook_ReloadPost,
  86. SDKHook_GetMaxHealth, // ep2v and later
  87. };
  88. /*
  89. Alphabetized for easy readability
  90. SDKHook_EndTouch,
  91. SDKHook_EndTouchPost,
  92. SDKHook_FireBulletsPost,
  93. SDKHook_GetMaxHealth, (ep2v and later)
  94. SDKHook_GroundEntChangedPost,
  95. SDKHook_OnTakeDamage,
  96. SDKHook_OnTakeDamagePost,
  97. SDKHook_PreThink,
  98. SDKHook_PreThinkPost,
  99. SDKHook_PostThink,
  100. SDKHook_PostThinkPost,
  101. SDKHook_Reload,
  102. SDKHook_ReloadPost,
  103. SDKHook_SetTransmit,
  104. SDKHook_ShouldCollide,
  105. SDKHook_Spawn,
  106. SDKHook_SpawnPost,
  107. SDKHook_StartTouch,
  108. SDKHook_StartTouchPost,
  109. SDKHook_Think,
  110. SDKHook_ThinkPost,
  111. SDKHook_Touch,
  112. SDKHook_TouchPost,
  113. SDKHook_TraceAttack,
  114. SDKHook_TraceAttackPost,
  115. SDKHook_Use,
  116. SDKHook_UsePost,
  117. SDKHook_VPhysicsUpdate,
  118. SDKHook_VPhysicsUpdatePost,
  119. SDKHook_WeaponCanSwitchTo,
  120. SDKHook_WeaponCanSwitchToPost,
  121. SDKHook_WeaponCanUse,
  122. SDKHook_WeaponCanUsePost,
  123. SDKHook_WeaponDrop,
  124. SDKHook_WeaponDropPost,
  125. SDKHook_WeaponEquip,
  126. SDKHook_WeaponEquipPost,
  127. SDKHook_WeaponSwitch,
  128. SDKHook_WeaponSwitchPost
  129. */
  130. enum UseType
  131. {
  132. Use_Off,
  133. Use_On,
  134. Use_Set,
  135. Use_Toggle
  136. };
  137. funcenum SDKHookCB
  138. {
  139. // PreThink/Post
  140. // PostThink/Post
  141. public(client),
  142. // Spawn
  143. Action:public(entity),
  144. // GroundEntChanged
  145. // SpawnPost
  146. // Think/Post
  147. // VPhysicsUpdate/Post
  148. public(entity),
  149. // EndTouch
  150. // StartTouch
  151. // Touch
  152. Action:public(entity, other),
  153. // EndTouchPost
  154. // StartTouchPost
  155. // TouchPost
  156. public(entity, other),
  157. // SetTransmit
  158. Action:public(entity, client),
  159. // WeaponCanSwitchTo
  160. // WeaponCanUse
  161. // WeaponDrop
  162. // WeaponEquip
  163. // WeaponSwitch
  164. Action:public(client, weapon),
  165. // WeaponCanSwitchToPost
  166. // WeaponCanUsePost
  167. // WeaponDropPost
  168. // WeaponEquipPost
  169. // WeaponSwitchPost
  170. public(client, weapon),
  171. // GetMaxHealth (ep2v and later)
  172. Action:public(entity, &maxhealth),
  173. // OnTakeDamage
  174. // Note: Force application is dependent on game and damage type(s)
  175. // SDKHooks 1.0+
  176. Action:public(victim, &attacker, &inflictor, &Float:damage, &damagetype),
  177. // SDKHooks 2.0+
  178. Action:public(victim, &attacker, &inflictor, &Float:damage, &damagetype, &weapon, Float:damageForce[3], Float:damagePosition[3]),
  179. // SDKHooks 2.1+ (can check for support at runtime using GetFeatureStatus on SDKHook_DmgCustomInOTD capability.
  180. // DON'T attempt to access 'damagecustom' var if feature status != available
  181. Action:public(victim, &attacker, &inflictor, &Float:damage, &damagetype, &weapon,
  182. Float:damageForce[3], Float:damagePosition[3], damagecustom),
  183. // OnTakeDamagePost
  184. public(victim, attacker, inflictor, Float:damage, damagetype),
  185. public(victim, attacker, inflictor, Float:damage, damagetype, weapon, const Float:damageForce[3], const Float:damagePosition[3]),
  186. // FireBulletsPost
  187. public(client, shots, const String:weaponname[]),
  188. // TraceAttack
  189. Action:public(victim, &attacker, &inflictor, &Float:damage, &damagetype, &ammotype, hitbox, hitgroup),
  190. // TraceAttackPost
  191. public(victim, attacker, inflictor, Float:damage, damagetype, ammotype, hitbox, hitgroup),
  192. // ShouldCollide
  193. bool:public(entity, collisiongroup, contentsmask, bool:originalResult),
  194. // Use
  195. Action:public(entity, activator, caller, UseType:type, Float:value),
  196. // UsePost
  197. public(entity, activator, caller, UseType:type, Float:value),
  198. // Reload
  199. Action:public(weapon),
  200. // Reload post
  201. public(weapon, bool:bSuccessful)
  202. };
  203. /**
  204. * @brief When an entity is created
  205. *
  206. * @param entity Entity index
  207. * @param classname Class name
  208. * @noreturn
  209. */
  210. forward OnEntityCreated(entity, const String:classname[]);
  211. /**
  212. * @brief When an entity is destroyed
  213. *
  214. * @param entity Entity index
  215. * @noreturn
  216. */
  217. forward OnEntityDestroyed(entity);
  218. /**
  219. * @brief When the game description is retrieved
  220. *
  221. * @note Not supported on ep2v.
  222. *
  223. * @param gameDesc Game description
  224. * @noreturn
  225. */
  226. forward Action:OnGetGameDescription(String:gameDesc[64]);
  227. /**
  228. * @brief When the level is initialized
  229. *
  230. * @param mapName Name of the map
  231. * @param mapEntities Entities of the map
  232. * @noreturn
  233. */
  234. forward Action:OnLevelInit(const String:mapName[], String:mapEntities[2097152]);
  235. /**
  236. * @brief Hooks an entity
  237. *
  238. * @param entity Entity index
  239. * @param type Type of function to hook
  240. * @param callback Function to call when hook is called
  241. * @noreturn
  242. */
  243. native SDKHook(entity, SDKHookType:type, SDKHookCB:callback);
  244. /**
  245. * @brief Hooks an entity
  246. *
  247. * @param entity Entity index
  248. * @param type Type of function to hook
  249. * @param callback Function to call when hook is called
  250. * @return bool Hook Successful
  251. */
  252. native bool:SDKHookEx(entity, SDKHookType:type, SDKHookCB:callback);
  253. /**
  254. * @brief Unhooks an entity
  255. *
  256. * @param entity Entity index
  257. * @param type Type of function to unhook
  258. * @param callback Callback function to unhook
  259. * @noreturn
  260. */
  261. native SDKUnhook(entity, SDKHookType:type, SDKHookCB:callback);
  262. /**
  263. * @brief Applies damage to an entity
  264. *
  265. * @note Force application is dependent on game and damage type(s)
  266. *
  267. * @param entity Entity index taking damage
  268. * @param inflictor Inflictor entity index
  269. * @param attacker Attacker entity index
  270. * @param damage Amount of damage
  271. * @param damageType Bitfield of damage types
  272. * @param weapon Weapon index (orangebox and later) or -1 for unspecified
  273. * @param damageForce Velocity of damage force
  274. * @param damagePosition Origin of damage
  275. * @noreturn
  276. */
  277. 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);
  278. /**
  279. * @brief Forces a client to drop the specified weapon
  280. *
  281. * @param client Client index.
  282. * @param weapon Weapon entity index.
  283. * @param vecTarget Location to toss weapon to, or NULL_VECTOR for default.
  284. * @param vecVelocity Velocity at which to toss weapon, or NULL_VECTOR for default.
  285. * @noreturn
  286. * @error Invalid client or weapon entity, weapon not owned by client.
  287. */
  288. native SDKHooks_DropWeapon(client, weapon, const Float:vecTarget[3]=NULL_VECTOR, const Float:vecVelocity[3]=NULL_VECTOR);
  289. /** Do Not Edit Below This Line **/
  290. public Extension:__ext_sdkhooks =
  291. {
  292. name = "sdkhooks",
  293. file = "sdkhooks.ext",
  294. #if defined AUTOLOAD_EXTENSIONS
  295. autoload = 1,
  296. #else
  297. autoload = 0,
  298. #endif
  299. #if defined REQUIRE_EXTENSIONS
  300. required = 1,
  301. #else
  302. required = 0,
  303. #endif
  304. };
  305. #if !defined REQUIRE_EXTENSIONS
  306. public __ext_sdkhooks_SetNTVOptional()
  307. {
  308. MarkNativeAsOptional("SDKHook");
  309. MarkNativeAsOptional("SDKHookEx");
  310. MarkNativeAsOptional("SDKUnhook");
  311. MarkNativeAsOptional("SDKHooks_TakeDamage");
  312. MarkNativeAsOptional("SDKHooks_DropWeapon");
  313. }
  314. #endif