plugins/include/sdkhooks.inc
author Kyle Sanderson <kyle.leet@gmail.com>
Thu Jul 18 19:40:42 2013 -0400 (2013-07-18)
changeset 3953 ea7a34452243
parent 3767 7223d0a452a8
child 3967 ceafb87d38a7
permissions -rw-r--r--
Make compile.sh set working dir to own dir (bug 5710, r=psychonic).
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod (C)2009-2013 AlliedModders LLC.  All rights reserved.
     5  * =============================================================================
     6  *
     7  * This file is part of the SourceMod/SourcePawn SDK.
     8  *
     9  * This program is free software; you can redistribute it and/or modify it under
    10  * the terms of the GNU General Public License, version 3.0, as published by the
    11  * Free Software Foundation.
    12  * 
    13  * This program is distributed in the hope that it will be useful, but WITHOUT
    14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    16  * details.
    17  *
    18  * You should have received a copy of the GNU General Public License along with
    19  * this program.  If not, see <http://www.gnu.org/licenses/>.
    20  *
    21  * As a special exception, AlliedModders LLC gives you permission to link the
    22  * code of this program (as well as its derivative works) to "Half-Life 2," the
    23  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    24  * by the Valve Corporation.  You must obey the GNU General Public License in
    25  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    26  * this exception to all derivative works.  AlliedModders LLC defines further
    27  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    28  * or <http://www.sourcemod.net/license.php>.
    29  */
    30 
    31 #if defined _sdkhooks_included
    32  #endinput
    33 #endif
    34 #define _sdkhooks_included
    35 
    36 // this is obviously _not_ a robust check, but it will solve most conflict and is clean
    37 #if !defined DMG_GENERIC
    38 #define DMG_GENERIC								0					// generic damage was done
    39 #define DMG_CRUSH									(1 << 0)	// crushed by falling or moving object. 
    40 																						// NOTE: It's assumed crush damage is occurring as a result of physics collision, so no extra physics force is generated by crush damage.
    41 																						// DON'T use DMG_CRUSH when damaging entities unless it's the result of a physics collision. You probably want DMG_CLUB instead.
    42 #define DMG_BULLET								(1 << 1)	// shot
    43 #define DMG_SLASH									(1 << 2)	// cut, clawed, stabbed
    44 #define DMG_BURN									(1 << 3)	// heat burned
    45 #define DMG_VEHICLE								(1 << 4)	// hit by a vehicle
    46 #define DMG_FALL									(1 << 5)	// fell too far
    47 #define DMG_BLAST									(1 << 6)	// explosive blast damage
    48 #define DMG_CLUB									(1 << 7)	// crowbar, punch, headbutt
    49 #define DMG_SHOCK									(1 << 8)	// electric shock
    50 #define DMG_SONIC									(1 << 9)	// sound pulse shockwave
    51 #define DMG_ENERGYBEAM						(1 << 10)	// laser or other high energy beam 
    52 #define DMG_PREVENT_PHYSICS_FORCE	(1 << 11)	// Prevent a physics force 
    53 #define DMG_NEVERGIB							(1 << 12)	// with this bit OR'd in, no damage type will be able to gib victims upon death
    54 #define DMG_ALWAYSGIB							(1 << 13)	// with this bit OR'd in, any damage type can be made to gib victims upon death.
    55 #define DMG_DROWN									(1 << 14)	// Drowning
    56 #define DMG_PARALYZE							(1 << 15)	// slows affected creature down
    57 #define DMG_NERVEGAS							(1 << 16)	// nerve toxins, very bad
    58 #define DMG_POISON								(1 << 17)	// blood poisoning - heals over time like drowning damage
    59 #define DMG_RADIATION							(1 << 18)	// radiation exposure
    60 #define DMG_DROWNRECOVER					(1 << 19)	// drowning recovery
    61 #define DMG_ACID									(1 << 20)	// toxic chemicals or acid burns
    62 #define DMG_SLOWBURN							(1 << 21)	// in an oven
    63 #define DMG_REMOVENORAGDOLL				(1 << 22)	// with this bit OR'd in, no ragdoll will be created, and the target will be quietly removed.
    64 																						// use this to kill an entity that you've already got a server-side ragdoll for
    65 #define DMG_PHYSGUN								(1 << 23)	// Hit by manipulator. Usually doesn't do any damage.
    66 #define DMG_PLASMA								(1 << 24)	// Shot by Cremator
    67 #define DMG_AIRBOAT								(1 << 25)	// Hit by the airboat's gun
    68 #define DMG_DISSOLVE							(1 << 26)	// Dissolving!
    69 #define DMG_BLAST_SURFACE					(1 << 27)	// A blast on the surface of water that cannot harm things underwater
    70 #define DMG_DIRECT								(1 << 28)
    71 #define DMG_BUCKSHOT							(1 << 29)	// not quite a bullet. Little, rounder, different.
    72 #endif
    73 
    74 #if !defined DMG_CRIT
    75 	// TF2 crits and minicrits
    76 	#define DMG_CRIT DMG_ACID
    77 #endif
    78 
    79 enum SDKHookType
    80 {
    81 	SDKHook_EndTouch,
    82 	SDKHook_FireBulletsPost,
    83 	SDKHook_OnTakeDamage,
    84 	SDKHook_OnTakeDamagePost,
    85 	SDKHook_PreThink,
    86 	SDKHook_PostThink,
    87 	SDKHook_SetTransmit,
    88 	SDKHook_Spawn,
    89 	SDKHook_StartTouch,
    90 	SDKHook_Think,
    91 	SDKHook_Touch,
    92 	SDKHook_TraceAttack,
    93 	SDKHook_TraceAttackPost,
    94 	SDKHook_WeaponCanSwitchTo,
    95 	SDKHook_WeaponCanUse,
    96 	SDKHook_WeaponDrop,
    97 	SDKHook_WeaponEquip,
    98 	SDKHook_WeaponSwitch,
    99 	SDKHook_ShouldCollide,
   100 	SDKHook_PreThinkPost,
   101 	SDKHook_PostThinkPost,
   102 	SDKHook_ThinkPost,
   103 	SDKHook_EndTouchPost,
   104 	SDKHook_GroundEntChangedPost,
   105 	SDKHook_SpawnPost,
   106 	SDKHook_StartTouchPost,
   107 	SDKHook_TouchPost,
   108 	SDKHook_VPhysicsUpdate,
   109 	SDKHook_VPhysicsUpdatePost,
   110 	SDKHook_WeaponCanSwitchToPost,
   111 	SDKHook_WeaponCanUsePost,
   112 	SDKHook_WeaponDropPost,
   113 	SDKHook_WeaponEquipPost,
   114 	SDKHook_WeaponSwitchPost,
   115 	SDKHook_Use,
   116 	SDKHook_UsePost,
   117 	SDKHook_Reload,
   118 	SDKHook_ReloadPost,
   119 	SDKHook_GetMaxHealth,  // ep2v and later
   120 };
   121 
   122 /*
   123 	Alphabetized for easy readability
   124 	
   125 	SDKHook_EndTouch,
   126 	SDKHook_EndTouchPost,
   127 	
   128 	SDKHook_FireBulletsPost,
   129 	
   130 	SDKHook_GetMaxHealth,  (ep2v and later)
   131 	
   132 	SDKHook_GroundEntChangedPost,
   133 	
   134 	SDKHook_OnTakeDamage,
   135 	SDKHook_OnTakeDamagePost,
   136 	
   137 	SDKHook_PreThink,
   138 	SDKHook_PreThinkPost,
   139 	
   140 	SDKHook_PostThink,
   141 	SDKHook_PostThinkPost,
   142 	
   143 	SDKHook_Reload,
   144 	SDKHook_ReloadPost,
   145 	
   146 	SDKHook_SetTransmit,
   147 	
   148 	SDKHook_ShouldCollide,
   149 	
   150 	SDKHook_Spawn,
   151 	SDKHook_SpawnPost,
   152 	
   153 	SDKHook_StartTouch,
   154 	SDKHook_StartTouchPost,
   155 	
   156 	SDKHook_Think,
   157 	SDKHook_ThinkPost,
   158 	
   159 	SDKHook_Touch,
   160 	SDKHook_TouchPost,
   161 	
   162 	SDKHook_TraceAttack,
   163 	SDKHook_TraceAttackPost,
   164 	
   165 	SDKHook_Use,
   166 	SDKHook_UsePost,
   167 	
   168 	SDKHook_VPhysicsUpdate,
   169 	SDKHook_VPhysicsUpdatePost,
   170 	
   171 	SDKHook_WeaponCanSwitchTo,
   172 	SDKHook_WeaponCanSwitchToPost,
   173 	
   174 	SDKHook_WeaponCanUse,
   175 	SDKHook_WeaponCanUsePost,
   176 	
   177 	SDKHook_WeaponDrop,
   178 	SDKHook_WeaponDropPost,
   179 	
   180 	SDKHook_WeaponEquip,
   181 	SDKHook_WeaponEquipPost,
   182 	
   183 	SDKHook_WeaponSwitch,
   184 	SDKHook_WeaponSwitchPost
   185 */
   186 
   187 enum UseType
   188 {
   189 	Use_Off,
   190 	Use_On,
   191 	Use_Set,
   192 	Use_Toggle
   193 };
   194 
   195 funcenum SDKHookCB
   196 {
   197 	// PreThink/Post
   198 	// PostThink/Post
   199 	public(client),
   200 	
   201 	// Spawn
   202 	Action:public(entity),
   203 	
   204 	// GroundEntChanged
   205 	// SpawnPost
   206 	// Think/Post
   207 	// VPhysicsUpdate/Post
   208 	public(entity),
   209 	
   210 	// EndTouch
   211 	// StartTouch
   212 	// Touch
   213 	Action:public(entity, other),
   214 	
   215 	// EndTouchPost
   216 	// StartTouchPost
   217 	// TouchPost
   218 	public(entity, other),
   219 	
   220 	// SetTransmit
   221 	Action:public(entity, client),
   222 	
   223 	// WeaponCanSwitchTo
   224 	// WeaponCanUse
   225 	// WeaponDrop
   226 	// WeaponEquip
   227 	// WeaponSwitch
   228 	Action:public(client, weapon),
   229 	
   230 	// WeaponCanSwitchToPost
   231 	// WeaponCanUsePost
   232 	// WeaponDropPost
   233 	// WeaponEquipPost
   234 	// WeaponSwitchPost
   235 	public(client, weapon),
   236 	
   237 	// GetMaxHealth (ep2v and later)
   238 	Action:public(entity, &maxhealth),
   239 	
   240 	// OnTakeDamage
   241 	// Note: The weapon parameter is not used by all games and damage sources.
   242 	// Note: Force application is dependent on game and damage type(s)
   243 	// SDKHooks 1.0+
   244 	Action:public(victim, &attacker, &inflictor, &Float:damage, &damagetype),
   245 	// SDKHooks 2.0+
   246 	Action:public(victim, &attacker, &inflictor, &Float:damage, &damagetype, &weapon, Float:damageForce[3], Float:damagePosition[3]),
   247 	// SDKHooks 2.1+  (can check for support at runtime using GetFeatureStatus on SDKHook_DmgCustomInOTD capability.
   248 	// DON'T attempt to access 'damagecustom' var if feature status != available
   249 	Action:public(victim, &attacker, &inflictor, &Float:damage, &damagetype, &weapon,
   250 		Float:damageForce[3], Float:damagePosition[3], damagecustom),
   251 	
   252 	// OnTakeDamagePost
   253 	public(victim, attacker, inflictor, Float:damage, damagetype),
   254 	public(victim, attacker, inflictor, Float:damage, damagetype, weapon, const Float:damageForce[3], const Float:damagePosition[3]),
   255 	
   256 	// FireBulletsPost
   257 	public(client, shots, const String:weaponname[]),
   258 	
   259 	// TraceAttack
   260 	Action:public(victim, &attacker, &inflictor, &Float:damage, &damagetype, &ammotype, hitbox, hitgroup),
   261 	
   262 	// TraceAttackPost
   263 	public(victim, attacker, inflictor, Float:damage, damagetype, ammotype, hitbox, hitgroup),
   264 	
   265 	// ShouldCollide
   266 	bool:public(entity, collisiongroup, contentsmask, bool:originalResult),
   267 	
   268 	// Use
   269 	Action:public(entity, activator, caller, UseType:type, Float:value),
   270 	
   271 	// UsePost
   272 	public(entity, activator, caller, UseType:type, Float:value),
   273 	
   274 	// Reload
   275 	Action:public(weapon),
   276 	
   277 	// Reload post
   278 	public(weapon, bool:bSuccessful)
   279 };
   280 
   281 
   282 /**
   283  * @brief When an entity is created
   284  *
   285  * @param		entity		Entity index
   286  * @param		classname	Class name
   287  * @noreturn
   288  */
   289 forward OnEntityCreated(entity, const String:classname[]);
   290 
   291 /**
   292  * @brief When an entity is destroyed
   293  *
   294  * @param		entity		Entity index
   295  * @noreturn
   296  */
   297 forward OnEntityDestroyed(entity);
   298 
   299 /**
   300  * @brief When the game description is retrieved
   301  *
   302  * @note  Not supported on ep2v.
   303  *
   304  * @param		gameDesc		Game description
   305  * @noreturn
   306  */
   307 forward Action:OnGetGameDescription(String:gameDesc[64]);
   308 
   309 /**
   310  * @brief When the level is initialized
   311  *
   312  * @param		mapName			Name of the map
   313  * @param		mapEntities	Entities of the map
   314  * @noreturn
   315  */
   316 forward Action:OnLevelInit(const String:mapName[], String:mapEntities[2097152]);
   317 
   318 /**
   319  * @brief Hooks an entity
   320  *
   321  * @param		entity		Entity index
   322  * @param		type			Type of function to hook
   323  * @param		callback	Function to call when hook is called
   324  * @noreturn
   325  */
   326 native SDKHook(entity, SDKHookType:type, SDKHookCB:callback);
   327 
   328 /**
   329  * @brief Hooks an entity
   330  *
   331  * @param		entity		Entity index
   332  * @param		type			Type of function to hook
   333  * @param		callback	Function to call when hook is called
   334  * @return		bool		Hook Successful
   335  */
   336 native bool:SDKHookEx(entity, SDKHookType:type, SDKHookCB:callback);
   337 
   338 /**
   339  * @brief Unhooks an entity
   340  *
   341  * @param    entity   Entity index
   342  * @param    type     Type of function to unhook
   343  * @param    callback Callback function to unhook
   344  * @noreturn
   345  */
   346 native SDKUnhook(entity, SDKHookType:type, SDKHookCB:callback);
   347 
   348 /**
   349  * @brief Applies damage to an entity
   350  *
   351  * @note Force application is dependent on game and damage type(s)
   352  *
   353  * @param    entity         Entity index taking damage
   354  * @param    inflictor      Inflictor entity index
   355  * @param    attacker       Attacker entity index
   356  * @param    damage         Amount of damage
   357  * @param    damageType     Bitfield of damage types
   358  * @param    weapon         Weapon index (orangebox and later) or -1 for unspecified
   359  * @param    damageForce    Velocity of damage force
   360  * @param    damagePosition Origin of damage
   361  * @noreturn
   362  */
   363 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);
   364 
   365 /**
   366  * @brief				Forces a client to drop the specified weapon
   367  *
   368  * @param client		Client index.
   369  * @param weapon		Weapon entity index.
   370  * @param vecTarget		Location to toss weapon to, or NULL_VECTOR for default.
   371  * @param vecVelocity	Velocity at which to toss weapon, or NULL_VECTOR for default.
   372  * @noreturn
   373  * @error				Invalid client or weapon entity, weapon not owned by client.
   374  */
   375 native SDKHooks_DropWeapon(client, weapon, const Float:vecTarget[3]=NULL_VECTOR, const Float:vecVelocity[3]=NULL_VECTOR);
   376 
   377 /**
   378  * Do not edit below this line!
   379  */
   380 public Extension:__ext_sdkhooks = 
   381 {
   382 	name = "SDKHooks",
   383 	file = "sdkhooks.ext",
   384 #if defined AUTOLOAD_EXTENSIONS
   385 	autoload = 1,
   386 #else
   387 	autoload = 0,
   388 #endif
   389 #if defined REQUIRE_EXTENSIONS
   390 	required = 1,
   391 #else
   392 	required = 0,
   393 #endif
   394 };