Add OnTakeDamage_Alive hook support to SDKHooks (bug=6249).
This commit is contained in:
parent
40b1067ef7
commit
be55587d70
@ -90,6 +90,8 @@ HookTypeData g_HookTypes[SDKHook_MAXHOOKS] =
|
||||
{"GetMaxHealth", "", false},
|
||||
{"Blocked", "", false},
|
||||
{"BlockedPost", "", false},
|
||||
{"OnTakeDamageAlive", "DT_BaseCombatCharacter", false},
|
||||
{"OnTakeDamageAlivePost", "DT_BaseCombatCharacter", false},
|
||||
};
|
||||
|
||||
SDKHooks g_Interface;
|
||||
@ -168,6 +170,7 @@ SH_DECL_MANUALHOOK0(GetMaxHealth, 0, 0, 0, int);
|
||||
#endif
|
||||
SH_DECL_MANUALHOOK1_void(GroundEntChanged, 0, 0, 0, void *);
|
||||
SH_DECL_MANUALHOOK1(OnTakeDamage, 0, 0, 0, int, CTakeDamageInfoHack &);
|
||||
SH_DECL_MANUALHOOK1(OnTakeDamageAlive, 0, 0, 0, int, CTakeDamageInfoHack &);
|
||||
SH_DECL_MANUALHOOK0_void(PreThink, 0, 0, 0);
|
||||
SH_DECL_MANUALHOOK0_void(PostThink, 0, 0, 0);
|
||||
SH_DECL_MANUALHOOK0(Reload, 0, 0, 0, bool);
|
||||
@ -515,6 +518,7 @@ void SDKHooks::SetupHooks()
|
||||
CHECKOFFSET(FireBullets, false, true);
|
||||
CHECKOFFSET(GroundEntChanged, false, true);
|
||||
CHECKOFFSET(OnTakeDamage, true, true);
|
||||
CHECKOFFSET(OnTakeDamageAlive,true, true);
|
||||
CHECKOFFSET(PreThink, true, true);
|
||||
CHECKOFFSET(PostThink, true, true);
|
||||
CHECKOFFSET(Reload, true, true);
|
||||
@ -607,6 +611,12 @@ HookReturn SDKHooks::Hook(int entity, SDKHookType type, IPluginFunction *callbac
|
||||
case SDKHook_OnTakeDamagePost:
|
||||
hookid = SH_ADD_MANUALVPHOOK(OnTakeDamage, pEnt, SH_MEMBER(&g_Interface, &SDKHooks::Hook_OnTakeDamagePost), true);
|
||||
break;
|
||||
case SDKHook_OnTakeDamageAlive:
|
||||
hookid = SH_ADD_MANUALVPHOOK(OnTakeDamageAlive, pEnt, SH_MEMBER(&g_Interface, &SDKHooks::Hook_OnTakeDamageAlive), false);
|
||||
break;
|
||||
case SDKHook_OnTakeDamageAlivePost:
|
||||
hookid = SH_ADD_MANUALVPHOOK(OnTakeDamageAlive, pEnt, SH_MEMBER(&g_Interface, &SDKHooks::Hook_OnTakeDamageAlivePost), true);
|
||||
break;
|
||||
case SDKHook_PreThink:
|
||||
hookid = SH_ADD_MANUALVPHOOK(PreThink, pEnt, SH_MEMBER(&g_Interface, &SDKHooks::Hook_PreThink), false);
|
||||
break;
|
||||
@ -999,12 +1009,12 @@ void SDKHooks::Hook_GroundEntChangedPost(void *pVar)
|
||||
Call(META_IFACEPTR(CBaseEntity), SDKHook_GroundEntChangedPost);
|
||||
}
|
||||
|
||||
int SDKHooks::Hook_OnTakeDamage(CTakeDamageInfoHack &info)
|
||||
int SDKHooks::HandleOnTakeDamageHook(CTakeDamageInfoHack &info, SDKHookType hookType)
|
||||
{
|
||||
CBaseEntity *pEntity = META_IFACEPTR(CBaseEntity);
|
||||
|
||||
CVTableHook vhook(pEntity);
|
||||
ke::Vector<CVTableList *> &vtablehooklist = g_HookList[SDKHook_OnTakeDamage];
|
||||
ke::Vector<CVTableList *> &vtablehooklist = g_HookList[hookType];
|
||||
for (size_t entry = 0; entry < vtablehooklist.length(); ++entry)
|
||||
{
|
||||
if (vhook != vtablehooklist[entry]->vtablehook)
|
||||
@ -1020,10 +1030,10 @@ int SDKHooks::Hook_OnTakeDamage(CTakeDamageInfoHack &info)
|
||||
int weapon = info.GetWeapon();
|
||||
|
||||
Vector force = info.GetDamageForce();
|
||||
cell_t damageForce[3] = {sp_ftoc(force.x), sp_ftoc(force.y), sp_ftoc(force.z)};
|
||||
cell_t damageForce[3] = { sp_ftoc(force.x), sp_ftoc(force.y), sp_ftoc(force.z) };
|
||||
|
||||
Vector pos = info.GetDamagePosition();
|
||||
cell_t damagePosition[3] = {sp_ftoc(pos.x), sp_ftoc(pos.y), sp_ftoc(pos.z)};
|
||||
cell_t damagePosition[3] = { sp_ftoc(pos.x), sp_ftoc(pos.y), sp_ftoc(pos.z) };
|
||||
|
||||
cell_t res, ret = Pl_Continue;
|
||||
|
||||
@ -1039,23 +1049,23 @@ int SDKHooks::Hook_OnTakeDamage(CTakeDamageInfoHack &info)
|
||||
callback->PushCellByRef(&damagetype);
|
||||
callback->PushCellByRef(&weapon);
|
||||
callback->PushArray(damageForce, 3, SM_PARAM_COPYBACK);
|
||||
callback->PushArray(damagePosition, 3, SM_PARAM_COPYBACK);
|
||||
callback->PushArray(damagePosition, 3, SM_PARAM_COPYBACK);
|
||||
callback->PushCell(info.GetDamageCustom());
|
||||
callback->Execute(&res);
|
||||
|
||||
if(res >= ret)
|
||||
if (res >= ret)
|
||||
{
|
||||
ret = res;
|
||||
if(ret == Pl_Changed)
|
||||
if (ret == Pl_Changed)
|
||||
{
|
||||
CBaseEntity *pEntAttacker = gamehelpers->ReferenceToEntity(attacker);
|
||||
if(!pEntAttacker)
|
||||
if (!pEntAttacker)
|
||||
{
|
||||
callback->GetParentRuntime()->GetDefaultContext()->ThrowNativeError("Entity %d for attacker is invalid", attacker);
|
||||
RETURN_META_VALUE(MRES_IGNORED, 0);
|
||||
}
|
||||
CBaseEntity *pEntInflictor = gamehelpers->ReferenceToEntity(inflictor);
|
||||
if(!pEntInflictor)
|
||||
if (!pEntInflictor)
|
||||
{
|
||||
callback->GetParentRuntime()->GetDefaultContext()->ThrowNativeError("Entity %d for inflictor is invalid", inflictor);
|
||||
RETURN_META_VALUE(MRES_IGNORED, 0);
|
||||
@ -1077,12 +1087,12 @@ int SDKHooks::Hook_OnTakeDamage(CTakeDamageInfoHack &info)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(ret >= Pl_Handled)
|
||||
|
||||
if (ret >= Pl_Handled)
|
||||
RETURN_META_VALUE(MRES_SUPERCEDE, 1);
|
||||
|
||||
if(ret == Pl_Changed)
|
||||
RETURN_META_VALUE(MRES_HANDLED, 1);
|
||||
if (ret == Pl_Changed)
|
||||
RETURN_META_VALUE(MRES_HANDLED, 1);
|
||||
|
||||
break;
|
||||
}
|
||||
@ -1090,12 +1100,12 @@ int SDKHooks::Hook_OnTakeDamage(CTakeDamageInfoHack &info)
|
||||
RETURN_META_VALUE(MRES_IGNORED, 0);
|
||||
}
|
||||
|
||||
int SDKHooks::Hook_OnTakeDamagePost(CTakeDamageInfoHack &info)
|
||||
int SDKHooks::HandleOnTakeDamageHookPost(CTakeDamageInfoHack &info, SDKHookType hookType)
|
||||
{
|
||||
CBaseEntity *pEntity = META_IFACEPTR(CBaseEntity);
|
||||
|
||||
CVTableHook vhook(pEntity);
|
||||
ke::Vector<CVTableList *> &vtablehooklist = g_HookList[SDKHook_OnTakeDamagePost];
|
||||
ke::Vector<CVTableList *> &vtablehooklist = g_HookList[hookType];
|
||||
for (size_t entry = 0; entry < vtablehooklist.length(); ++entry)
|
||||
{
|
||||
if (vhook != vtablehooklist[entry]->vtablehook)
|
||||
@ -1118,11 +1128,11 @@ int SDKHooks::Hook_OnTakeDamagePost(CTakeDamageInfoHack &info)
|
||||
callback->PushCell(info.GetWeapon());
|
||||
|
||||
Vector force = info.GetDamageForce();
|
||||
cell_t damageForce[3] = {sp_ftoc(force.x), sp_ftoc(force.y), sp_ftoc(force.z)};
|
||||
cell_t damageForce[3] = { sp_ftoc(force.x), sp_ftoc(force.y), sp_ftoc(force.z) };
|
||||
callback->PushArray(damageForce, 3);
|
||||
|
||||
Vector pos = info.GetDamagePosition();
|
||||
cell_t damagePosition[3] = {sp_ftoc(pos.x), sp_ftoc(pos.y), sp_ftoc(pos.z)};
|
||||
cell_t damagePosition[3] = { sp_ftoc(pos.x), sp_ftoc(pos.y), sp_ftoc(pos.z) };
|
||||
callback->PushArray(damagePosition, 3);
|
||||
|
||||
callback->PushCell(info.GetDamageCustom());
|
||||
@ -1136,6 +1146,26 @@ int SDKHooks::Hook_OnTakeDamagePost(CTakeDamageInfoHack &info)
|
||||
RETURN_META_VALUE(MRES_IGNORED, 0);
|
||||
}
|
||||
|
||||
int SDKHooks::Hook_OnTakeDamage(CTakeDamageInfoHack &info)
|
||||
{
|
||||
return HandleOnTakeDamageHook(info, SDKHook_OnTakeDamage);
|
||||
}
|
||||
|
||||
int SDKHooks::Hook_OnTakeDamagePost(CTakeDamageInfoHack &info)
|
||||
{
|
||||
return HandleOnTakeDamageHookPost(info, SDKHook_OnTakeDamagePost);
|
||||
}
|
||||
|
||||
int SDKHooks::Hook_OnTakeDamageAlive(CTakeDamageInfoHack &info)
|
||||
{
|
||||
return HandleOnTakeDamageHook(info, SDKHook_OnTakeDamageAlive);
|
||||
}
|
||||
|
||||
int SDKHooks::Hook_OnTakeDamageAlivePost(CTakeDamageInfoHack &info)
|
||||
{
|
||||
return HandleOnTakeDamageHookPost(info, SDKHook_OnTakeDamageAlivePost);
|
||||
}
|
||||
|
||||
void SDKHooks::Hook_PreThink()
|
||||
{
|
||||
Call(META_IFACEPTR(CBaseEntity), SDKHook_PreThink);
|
||||
|
@ -1,353 +1,361 @@
|
||||
#ifndef _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
|
||||
#define _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
|
||||
|
||||
#include "smsdk_ext.h"
|
||||
#include <ISDKHooks.h>
|
||||
#include <IBinTools.h>
|
||||
#include <convar.h>
|
||||
#include <sh_list.h>
|
||||
#include <amtl/am-vector.h>
|
||||
#include <vtable_hook_helper.h>
|
||||
|
||||
#include <iplayerinfo.h>
|
||||
#include <shareddefs.h>
|
||||
|
||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||
#include <itoolentity.h>
|
||||
#endif
|
||||
|
||||
#include "takedamageinfohack.h"
|
||||
|
||||
#ifndef METAMOD_PLAPI_VERSION
|
||||
#define GetCGlobals pGlobals
|
||||
#define GetEngineFactory engineFactory
|
||||
#define GetServerFactory serverFactory
|
||||
#endif
|
||||
|
||||
#if SOURCE_ENGINE >= SE_CSS && SOURCE_ENGINE != SE_LEFT4DEAD
|
||||
#define GETMAXHEALTH_IS_VIRTUAL
|
||||
#endif
|
||||
#if SOURCE_ENGINE != SE_HL2DM && SOURCE_ENGINE != SE_DODS && SOURCE_ENGINE != SE_CSS && SOURCE_ENGINE != SE_TF2 && SOURCE_ENGINE != SE_LEFT4DEAD2 && SOURCE_ENGINE != SE_CSGO && SOURCE_ENGINE != SE_NUCLEARDAWN
|
||||
#define GAMEDESC_CAN_CHANGE
|
||||
#endif
|
||||
|
||||
#if SOURCE_ENGINE == SE_DOTA
|
||||
class CEntityKeyValues;
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* Globals
|
||||
*/
|
||||
|
||||
struct HookTypeData
|
||||
{
|
||||
const char *name;
|
||||
const char *dtReq;
|
||||
bool supported;
|
||||
};
|
||||
|
||||
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,
|
||||
SDKHook_ShouldCollide,
|
||||
SDKHook_PreThinkPost,
|
||||
SDKHook_PostThinkPost,
|
||||
SDKHook_ThinkPost,
|
||||
SDKHook_EndTouchPost,
|
||||
SDKHook_GroundEntChangedPost,
|
||||
SDKHook_SpawnPost,
|
||||
SDKHook_StartTouchPost,
|
||||
SDKHook_TouchPost,
|
||||
SDKHook_VPhysicsUpdate,
|
||||
SDKHook_VPhysicsUpdatePost,
|
||||
SDKHook_WeaponCanSwitchToPost,
|
||||
SDKHook_WeaponCanUsePost,
|
||||
SDKHook_WeaponDropPost,
|
||||
SDKHook_WeaponEquipPost,
|
||||
SDKHook_WeaponSwitchPost,
|
||||
SDKHook_Use,
|
||||
SDKHook_UsePost,
|
||||
SDKHook_Reload,
|
||||
SDKHook_ReloadPost,
|
||||
SDKHook_GetMaxHealth,
|
||||
#ifndef _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
|
||||
#define _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
|
||||
|
||||
#include "smsdk_ext.h"
|
||||
#include <ISDKHooks.h>
|
||||
#include <IBinTools.h>
|
||||
#include <convar.h>
|
||||
#include <sh_list.h>
|
||||
#include <amtl/am-vector.h>
|
||||
#include <vtable_hook_helper.h>
|
||||
|
||||
#include <iplayerinfo.h>
|
||||
#include <shareddefs.h>
|
||||
|
||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||
#include <itoolentity.h>
|
||||
#endif
|
||||
|
||||
#include "takedamageinfohack.h"
|
||||
|
||||
#ifndef METAMOD_PLAPI_VERSION
|
||||
#define GetCGlobals pGlobals
|
||||
#define GetEngineFactory engineFactory
|
||||
#define GetServerFactory serverFactory
|
||||
#endif
|
||||
|
||||
#if SOURCE_ENGINE >= SE_CSS && SOURCE_ENGINE != SE_LEFT4DEAD
|
||||
#define GETMAXHEALTH_IS_VIRTUAL
|
||||
#endif
|
||||
#if SOURCE_ENGINE != SE_HL2DM && SOURCE_ENGINE != SE_DODS && SOURCE_ENGINE != SE_CSS && SOURCE_ENGINE != SE_TF2 && SOURCE_ENGINE != SE_LEFT4DEAD2 && SOURCE_ENGINE != SE_CSGO && SOURCE_ENGINE != SE_NUCLEARDAWN
|
||||
#define GAMEDESC_CAN_CHANGE
|
||||
#endif
|
||||
|
||||
#if SOURCE_ENGINE == SE_DOTA
|
||||
class CEntityKeyValues;
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* Globals
|
||||
*/
|
||||
|
||||
struct HookTypeData
|
||||
{
|
||||
const char *name;
|
||||
const char *dtReq;
|
||||
bool supported;
|
||||
};
|
||||
|
||||
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,
|
||||
SDKHook_ShouldCollide,
|
||||
SDKHook_PreThinkPost,
|
||||
SDKHook_PostThinkPost,
|
||||
SDKHook_ThinkPost,
|
||||
SDKHook_EndTouchPost,
|
||||
SDKHook_GroundEntChangedPost,
|
||||
SDKHook_SpawnPost,
|
||||
SDKHook_StartTouchPost,
|
||||
SDKHook_TouchPost,
|
||||
SDKHook_VPhysicsUpdate,
|
||||
SDKHook_VPhysicsUpdatePost,
|
||||
SDKHook_WeaponCanSwitchToPost,
|
||||
SDKHook_WeaponCanUsePost,
|
||||
SDKHook_WeaponDropPost,
|
||||
SDKHook_WeaponEquipPost,
|
||||
SDKHook_WeaponSwitchPost,
|
||||
SDKHook_Use,
|
||||
SDKHook_UsePost,
|
||||
SDKHook_Reload,
|
||||
SDKHook_ReloadPost,
|
||||
SDKHook_GetMaxHealth,
|
||||
SDKHook_Blocked,
|
||||
SDKHook_BlockedPost,
|
||||
SDKHook_MAXHOOKS
|
||||
};
|
||||
|
||||
enum HookReturn
|
||||
{
|
||||
HookRet_Successful,
|
||||
HookRet_InvalidEntity,
|
||||
HookRet_InvalidHookType,
|
||||
HookRet_NotSupported,
|
||||
HookRet_BadEntForHookType,
|
||||
};
|
||||
|
||||
#if SOURCE_ENGINE >= SE_CSS
|
||||
typedef void *(*ReticulateSplines)();
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Classes
|
||||
*/
|
||||
|
||||
class IPhysicsObject;
|
||||
class CDmgAccumulator;
|
||||
typedef CBaseEntity CBaseCombatWeapon;
|
||||
|
||||
struct HookList
|
||||
{
|
||||
public:
|
||||
int entity;
|
||||
IPluginFunction *callback;
|
||||
};
|
||||
|
||||
class CVTableList
|
||||
{
|
||||
public:
|
||||
CVTableList() : vtablehook(NULL)
|
||||
{
|
||||
};
|
||||
|
||||
~CVTableList()
|
||||
{
|
||||
delete vtablehook;
|
||||
};
|
||||
public:
|
||||
CVTableHook *vtablehook;
|
||||
ke::Vector<HookList> hooks;
|
||||
};
|
||||
|
||||
SDKHook_BlockedPost,
|
||||
SDKHook_OnTakeDamageAlive,
|
||||
SDKHook_OnTakeDamageAlivePost,
|
||||
SDKHook_MAXHOOKS
|
||||
};
|
||||
|
||||
enum HookReturn
|
||||
{
|
||||
HookRet_Successful,
|
||||
HookRet_InvalidEntity,
|
||||
HookRet_InvalidHookType,
|
||||
HookRet_NotSupported,
|
||||
HookRet_BadEntForHookType,
|
||||
};
|
||||
|
||||
#if SOURCE_ENGINE >= SE_CSS
|
||||
typedef void *(*ReticulateSplines)();
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Classes
|
||||
*/
|
||||
|
||||
class IPhysicsObject;
|
||||
class CDmgAccumulator;
|
||||
typedef CBaseEntity CBaseCombatWeapon;
|
||||
|
||||
struct HookList
|
||||
{
|
||||
public:
|
||||
int entity;
|
||||
IPluginFunction *callback;
|
||||
};
|
||||
|
||||
class CVTableList
|
||||
{
|
||||
public:
|
||||
CVTableList() : vtablehook(NULL)
|
||||
{
|
||||
};
|
||||
|
||||
~CVTableList()
|
||||
{
|
||||
delete vtablehook;
|
||||
};
|
||||
public:
|
||||
CVTableHook *vtablehook;
|
||||
ke::Vector<HookList> hooks;
|
||||
};
|
||||
|
||||
class IEntityListener
|
||||
{
|
||||
public:
|
||||
virtual void OnEntityCreated( CBaseEntity *pEntity ) {};
|
||||
virtual void OnEntitySpawned( CBaseEntity *pEntity ) {};
|
||||
virtual void OnEntityDeleted( CBaseEntity *pEntity ) {};
|
||||
};
|
||||
|
||||
class SDKHooks :
|
||||
public SDKExtension,
|
||||
public IConCommandBaseAccessor,
|
||||
public IPluginsListener,
|
||||
public IFeatureProvider,
|
||||
public IEntityListener,
|
||||
public IClientListener,
|
||||
public ISDKHooks
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief This is called after the initial loading sequence has been processed.
|
||||
*
|
||||
* @param error Error message buffer.
|
||||
* @param maxlength Size of error message buffer.
|
||||
* @param late Whether or not the module was loaded after map load.
|
||||
* @return True to succeed loading, false to fail.
|
||||
*/
|
||||
virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late);
|
||||
|
||||
/**
|
||||
* @brief This is called right before the extension is unloaded.
|
||||
*/
|
||||
virtual void SDK_OnUnload();
|
||||
|
||||
/**
|
||||
* @brief This is called once all known extensions have been loaded.
|
||||
* Note: It is is a good idea to add natives here, if any are provided.
|
||||
*/
|
||||
virtual void SDK_OnAllLoaded();
|
||||
|
||||
/**
|
||||
* @brief Called when the pause state is changed.
|
||||
*/
|
||||
//virtual void SDK_OnPauseChange(bool paused);
|
||||
|
||||
/**
|
||||
* @brief this is called when Core wants to know if your extension is working.
|
||||
*
|
||||
* @param error Error message buffer.
|
||||
* @param maxlength Size of error message buffer.
|
||||
* @return True if working, false otherwise.
|
||||
*/
|
||||
//virtual bool QueryRunning(char *error, size_t maxlength);
|
||||
|
||||
/** Returns version string */
|
||||
virtual const char *GetExtensionVerString();
|
||||
|
||||
/** Returns date string */
|
||||
virtual const char *GetExtensionDateString();
|
||||
|
||||
public:
|
||||
#if defined SMEXT_CONF_METAMOD
|
||||
/**
|
||||
* @brief Called when Metamod is attached, before the extension version is called.
|
||||
*
|
||||
* @param error Error buffer.
|
||||
* @param maxlength Maximum size of error buffer.
|
||||
* @param late Whether or not Metamod considers this a late load.
|
||||
* @return True to succeed, false to fail.
|
||||
*/
|
||||
virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
|
||||
|
||||
/**
|
||||
* @brief Called when Metamod is detaching, after the extension version is called.
|
||||
* NOTE: By default this is blocked unless sent from SourceMod.
|
||||
*
|
||||
* @param error Error buffer.
|
||||
* @param maxlength Maximum size of error buffer.
|
||||
* @return True to succeed, false to fail.
|
||||
*/
|
||||
//virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength);
|
||||
|
||||
/**
|
||||
* @brief Called when Metamod's pause state is changing.
|
||||
* NOTE: By default this is blocked unless sent from SourceMod.
|
||||
*
|
||||
* @param paused Pause state being set.
|
||||
* @param error Error buffer.
|
||||
* @param maxlength Maximum size of error buffer.
|
||||
* @return True to succeed, false to fail.
|
||||
*/
|
||||
//virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength);
|
||||
#endif
|
||||
|
||||
public: // IPluginsListener
|
||||
virtual void OnPluginLoaded(IPlugin *plugin);
|
||||
virtual void OnPluginUnloaded(IPlugin *plugin);
|
||||
|
||||
public: // IConCommandBaseAccessor
|
||||
virtual bool RegisterConCommandBase(ConCommandBase *pVar);
|
||||
|
||||
public: // IFeatureProvider
|
||||
virtual FeatureStatus GetFeatureStatus(FeatureType type, const char *name);
|
||||
|
||||
public: // IEntityListener
|
||||
virtual void OnEntityCreated(CBaseEntity *pEntity);
|
||||
virtual void OnEntityDeleted(CBaseEntity *pEntity);
|
||||
|
||||
public: // IClientListener
|
||||
virtual void OnClientPutInServer(int client);
|
||||
virtual void OnClientDisconnecting(int client);
|
||||
|
||||
public: // ISDKHooks
|
||||
virtual void AddEntityListener(ISMEntityListener *listener);
|
||||
virtual void RemoveEntityListener(ISMEntityListener *listener);
|
||||
|
||||
private:
|
||||
SourceHook::List<ISMEntityListener *> m_EntListeners;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Functions
|
||||
*/
|
||||
};
|
||||
|
||||
class SDKHooks :
|
||||
public SDKExtension,
|
||||
public IConCommandBaseAccessor,
|
||||
public IPluginsListener,
|
||||
public IFeatureProvider,
|
||||
public IEntityListener,
|
||||
public IClientListener,
|
||||
public ISDKHooks
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief This is called after the initial loading sequence has been processed.
|
||||
*
|
||||
* @param error Error message buffer.
|
||||
* @param maxlength Size of error message buffer.
|
||||
* @param late Whether or not the module was loaded after map load.
|
||||
* @return True to succeed loading, false to fail.
|
||||
*/
|
||||
virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late);
|
||||
|
||||
/**
|
||||
* @brief This is called right before the extension is unloaded.
|
||||
*/
|
||||
virtual void SDK_OnUnload();
|
||||
|
||||
/**
|
||||
* @brief This is called once all known extensions have been loaded.
|
||||
* Note: It is is a good idea to add natives here, if any are provided.
|
||||
*/
|
||||
virtual void SDK_OnAllLoaded();
|
||||
|
||||
/**
|
||||
* @brief Called when the pause state is changed.
|
||||
*/
|
||||
//virtual void SDK_OnPauseChange(bool paused);
|
||||
|
||||
/**
|
||||
* @brief this is called when Core wants to know if your extension is working.
|
||||
*
|
||||
* @param error Error message buffer.
|
||||
* @param maxlength Size of error message buffer.
|
||||
* @return True if working, false otherwise.
|
||||
*/
|
||||
//virtual bool QueryRunning(char *error, size_t maxlength);
|
||||
|
||||
/** Returns version string */
|
||||
virtual const char *GetExtensionVerString();
|
||||
|
||||
/** Returns date string */
|
||||
virtual const char *GetExtensionDateString();
|
||||
|
||||
public:
|
||||
#if defined SMEXT_CONF_METAMOD
|
||||
/**
|
||||
* @brief Called when Metamod is attached, before the extension version is called.
|
||||
*
|
||||
* @param error Error buffer.
|
||||
* @param maxlength Maximum size of error buffer.
|
||||
* @param late Whether or not Metamod considers this a late load.
|
||||
* @return True to succeed, false to fail.
|
||||
*/
|
||||
virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
|
||||
|
||||
/**
|
||||
* @brief Called when Metamod is detaching, after the extension version is called.
|
||||
* NOTE: By default this is blocked unless sent from SourceMod.
|
||||
*
|
||||
* @param error Error buffer.
|
||||
* @param maxlength Maximum size of error buffer.
|
||||
* @return True to succeed, false to fail.
|
||||
*/
|
||||
//virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength);
|
||||
|
||||
/**
|
||||
* @brief Called when Metamod's pause state is changing.
|
||||
* NOTE: By default this is blocked unless sent from SourceMod.
|
||||
*
|
||||
* @param paused Pause state being set.
|
||||
* @param error Error buffer.
|
||||
* @param maxlength Maximum size of error buffer.
|
||||
* @return True to succeed, false to fail.
|
||||
*/
|
||||
//virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength);
|
||||
#endif
|
||||
|
||||
public: // IPluginsListener
|
||||
virtual void OnPluginLoaded(IPlugin *plugin);
|
||||
virtual void OnPluginUnloaded(IPlugin *plugin);
|
||||
|
||||
public: // IConCommandBaseAccessor
|
||||
virtual bool RegisterConCommandBase(ConCommandBase *pVar);
|
||||
|
||||
public: // IFeatureProvider
|
||||
virtual FeatureStatus GetFeatureStatus(FeatureType type, const char *name);
|
||||
|
||||
public: // IEntityListener
|
||||
virtual void OnEntityCreated(CBaseEntity *pEntity);
|
||||
virtual void OnEntityDeleted(CBaseEntity *pEntity);
|
||||
|
||||
public: // IClientListener
|
||||
virtual void OnClientPutInServer(int client);
|
||||
virtual void OnClientDisconnecting(int client);
|
||||
|
||||
public: // ISDKHooks
|
||||
virtual void AddEntityListener(ISMEntityListener *listener);
|
||||
virtual void RemoveEntityListener(ISMEntityListener *listener);
|
||||
|
||||
private:
|
||||
SourceHook::List<ISMEntityListener *> m_EntListeners;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Functions
|
||||
*/
|
||||
cell_t Call(int entity, SDKHookType type, int other=INVALID_EHANDLE_INDEX);
|
||||
cell_t Call(CBaseEntity *pEnt, SDKHookType type, int other=INVALID_EHANDLE_INDEX);
|
||||
cell_t Call(CBaseEntity *pEnt, SDKHookType type, CBaseEntity *pOther);
|
||||
void SetupHooks();
|
||||
|
||||
HookReturn Hook(int entity, SDKHookType type, IPluginFunction *pCallback);
|
||||
void Unhook(int entity, SDKHookType type, IPluginFunction *pCallback);
|
||||
|
||||
/**
|
||||
* IServerGameDLL & IVEngineServer Hook Handlers
|
||||
*/
|
||||
#ifdef GAMEDESC_CAN_CHANGE
|
||||
const char *Hook_GetGameDescription();
|
||||
#endif
|
||||
const char *Hook_GetMapEntitiesString();
|
||||
bool Hook_LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background);
|
||||
|
||||
/**
|
||||
* CBaseEntity Hook Handlers
|
||||
*/
|
||||
void Hook_EndTouch(CBaseEntity *pOther);
|
||||
void Hook_EndTouchPost(CBaseEntity *pOther);
|
||||
void Hook_FireBulletsPost(const FireBulletsInfo_t &info);
|
||||
#ifdef GETMAXHEALTH_IS_VIRTUAL
|
||||
int Hook_GetMaxHealth();
|
||||
#endif
|
||||
void Hook_GroundEntChangedPost(void *pVar);
|
||||
int Hook_OnTakeDamage(CTakeDamageInfoHack &info);
|
||||
int Hook_OnTakeDamagePost(CTakeDamageInfoHack &info);
|
||||
void Hook_PreThink();
|
||||
void Hook_PreThinkPost();
|
||||
void Hook_PostThink();
|
||||
void Hook_PostThinkPost();
|
||||
bool Hook_Reload();
|
||||
bool Hook_ReloadPost();
|
||||
void Hook_SetTransmit(CCheckTransmitInfo *pInfo, bool bAlways);
|
||||
bool Hook_ShouldCollide(int collisonGroup, int contentsMask);
|
||||
#if SOURCE_ENGINE == SE_DOTA
|
||||
void Hook_Spawn(CEntityKeyValues *kv);
|
||||
void Hook_SpawnPost(CEntityKeyValues *kv);
|
||||
#else
|
||||
void Hook_Spawn();
|
||||
void Hook_SpawnPost();
|
||||
#endif
|
||||
void Hook_StartTouch(CBaseEntity *pOther);
|
||||
void Hook_StartTouchPost(CBaseEntity *pOther);
|
||||
void Hook_Think();
|
||||
void Hook_ThinkPost();
|
||||
void Hook_Touch(CBaseEntity *pOther);
|
||||
void Hook_TouchPost(CBaseEntity *pOther);
|
||||
#if SOURCE_ENGINE == SE_HL2DM || SOURCE_ENGINE == SE_DODS || SOURCE_ENGINE == SE_CSS || SOURCE_ENGINE == SE_TF2 || SOURCE_ENGINE == SE_SDK2013
|
||||
void Hook_TraceAttack(CTakeDamageInfoHack &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator);
|
||||
void Hook_TraceAttackPost(CTakeDamageInfoHack &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator);
|
||||
#else
|
||||
void Hook_TraceAttack(CTakeDamageInfoHack &info, const Vector &vecDir, trace_t *ptr);
|
||||
void Hook_TraceAttackPost(CTakeDamageInfoHack &info, const Vector &vecDir, trace_t *ptr);
|
||||
#endif
|
||||
void Hook_UpdateOnRemove();
|
||||
void Hook_Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value);
|
||||
void Hook_UsePost(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value);
|
||||
void Hook_VPhysicsUpdate(IPhysicsObject *pPhysics);
|
||||
void Hook_VPhysicsUpdatePost(IPhysicsObject *pPhysics);
|
||||
void Hook_Blocked(CBaseEntity *pOther);
|
||||
void Hook_BlockedPost(CBaseEntity *pOther);
|
||||
bool Hook_WeaponCanSwitchTo(CBaseCombatWeapon *pWeapon);
|
||||
bool Hook_WeaponCanSwitchToPost(CBaseCombatWeapon *pWeapon);
|
||||
bool Hook_WeaponCanUse(CBaseCombatWeapon *pWeapon);
|
||||
bool Hook_WeaponCanUsePost(CBaseCombatWeapon *pWeapon);
|
||||
void Hook_WeaponDrop(CBaseCombatWeapon *pWeapon, const Vector *pvecTarget, const Vector *pVelocity);
|
||||
void Hook_WeaponDropPost(CBaseCombatWeapon *pWeapon, const Vector *pvecTarget, const Vector *pVelocity);
|
||||
void Hook_WeaponEquip(CBaseCombatWeapon *pWeapon);
|
||||
void Hook_WeaponEquipPost(CBaseCombatWeapon *pWeapon);
|
||||
bool Hook_WeaponSwitch(CBaseCombatWeapon *pWeapon, int viewmodelindex);
|
||||
bool Hook_WeaponSwitchPost(CBaseCombatWeapon *pWeapon, int viewmodelindex);
|
||||
|
||||
private:
|
||||
void HandleEntityCreated(CBaseEntity *pEntity, int ref);
|
||||
void HandleEntityDeleted(CBaseEntity *pEntity, int ref);
|
||||
void Unhook(CBaseEntity *pEntity);
|
||||
void Unhook(IPluginContext *pContext);
|
||||
};
|
||||
|
||||
extern CGlobalVars *gpGlobals;
|
||||
extern ke::Vector<CVTableList *> g_HookList[SDKHook_MAXHOOKS];
|
||||
|
||||
extern ICvar *icvar;
|
||||
|
||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||
extern IServerTools *servertools;
|
||||
#endif
|
||||
|
||||
#endif // _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
|
||||
cell_t Call(CBaseEntity *pEnt, SDKHookType type, int other=INVALID_EHANDLE_INDEX);
|
||||
cell_t Call(CBaseEntity *pEnt, SDKHookType type, CBaseEntity *pOther);
|
||||
void SetupHooks();
|
||||
|
||||
HookReturn Hook(int entity, SDKHookType type, IPluginFunction *pCallback);
|
||||
void Unhook(int entity, SDKHookType type, IPluginFunction *pCallback);
|
||||
|
||||
/**
|
||||
* IServerGameDLL & IVEngineServer Hook Handlers
|
||||
*/
|
||||
#ifdef GAMEDESC_CAN_CHANGE
|
||||
const char *Hook_GetGameDescription();
|
||||
#endif
|
||||
const char *Hook_GetMapEntitiesString();
|
||||
bool Hook_LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background);
|
||||
|
||||
/**
|
||||
* CBaseEntity Hook Handlers
|
||||
*/
|
||||
void Hook_EndTouch(CBaseEntity *pOther);
|
||||
void Hook_EndTouchPost(CBaseEntity *pOther);
|
||||
void Hook_FireBulletsPost(const FireBulletsInfo_t &info);
|
||||
#ifdef GETMAXHEALTH_IS_VIRTUAL
|
||||
int Hook_GetMaxHealth();
|
||||
#endif
|
||||
void Hook_GroundEntChangedPost(void *pVar);
|
||||
int Hook_OnTakeDamage(CTakeDamageInfoHack &info);
|
||||
int Hook_OnTakeDamagePost(CTakeDamageInfoHack &info);
|
||||
int Hook_OnTakeDamageAlive(CTakeDamageInfoHack &info);
|
||||
int Hook_OnTakeDamageAlivePost(CTakeDamageInfoHack &info);
|
||||
void Hook_PreThink();
|
||||
void Hook_PreThinkPost();
|
||||
void Hook_PostThink();
|
||||
void Hook_PostThinkPost();
|
||||
bool Hook_Reload();
|
||||
bool Hook_ReloadPost();
|
||||
void Hook_SetTransmit(CCheckTransmitInfo *pInfo, bool bAlways);
|
||||
bool Hook_ShouldCollide(int collisonGroup, int contentsMask);
|
||||
#if SOURCE_ENGINE == SE_DOTA
|
||||
void Hook_Spawn(CEntityKeyValues *kv);
|
||||
void Hook_SpawnPost(CEntityKeyValues *kv);
|
||||
#else
|
||||
void Hook_Spawn();
|
||||
void Hook_SpawnPost();
|
||||
#endif
|
||||
void Hook_StartTouch(CBaseEntity *pOther);
|
||||
void Hook_StartTouchPost(CBaseEntity *pOther);
|
||||
void Hook_Think();
|
||||
void Hook_ThinkPost();
|
||||
void Hook_Touch(CBaseEntity *pOther);
|
||||
void Hook_TouchPost(CBaseEntity *pOther);
|
||||
#if SOURCE_ENGINE == SE_HL2DM || SOURCE_ENGINE == SE_DODS || SOURCE_ENGINE == SE_CSS || SOURCE_ENGINE == SE_TF2 || SOURCE_ENGINE == SE_SDK2013
|
||||
void Hook_TraceAttack(CTakeDamageInfoHack &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator);
|
||||
void Hook_TraceAttackPost(CTakeDamageInfoHack &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator);
|
||||
#else
|
||||
void Hook_TraceAttack(CTakeDamageInfoHack &info, const Vector &vecDir, trace_t *ptr);
|
||||
void Hook_TraceAttackPost(CTakeDamageInfoHack &info, const Vector &vecDir, trace_t *ptr);
|
||||
#endif
|
||||
void Hook_UpdateOnRemove();
|
||||
void Hook_Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value);
|
||||
void Hook_UsePost(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value);
|
||||
void Hook_VPhysicsUpdate(IPhysicsObject *pPhysics);
|
||||
void Hook_VPhysicsUpdatePost(IPhysicsObject *pPhysics);
|
||||
void Hook_Blocked(CBaseEntity *pOther);
|
||||
void Hook_BlockedPost(CBaseEntity *pOther);
|
||||
bool Hook_WeaponCanSwitchTo(CBaseCombatWeapon *pWeapon);
|
||||
bool Hook_WeaponCanSwitchToPost(CBaseCombatWeapon *pWeapon);
|
||||
bool Hook_WeaponCanUse(CBaseCombatWeapon *pWeapon);
|
||||
bool Hook_WeaponCanUsePost(CBaseCombatWeapon *pWeapon);
|
||||
void Hook_WeaponDrop(CBaseCombatWeapon *pWeapon, const Vector *pvecTarget, const Vector *pVelocity);
|
||||
void Hook_WeaponDropPost(CBaseCombatWeapon *pWeapon, const Vector *pvecTarget, const Vector *pVelocity);
|
||||
void Hook_WeaponEquip(CBaseCombatWeapon *pWeapon);
|
||||
void Hook_WeaponEquipPost(CBaseCombatWeapon *pWeapon);
|
||||
bool Hook_WeaponSwitch(CBaseCombatWeapon *pWeapon, int viewmodelindex);
|
||||
bool Hook_WeaponSwitchPost(CBaseCombatWeapon *pWeapon, int viewmodelindex);
|
||||
|
||||
private:
|
||||
void HandleEntityCreated(CBaseEntity *pEntity, int ref);
|
||||
void HandleEntityDeleted(CBaseEntity *pEntity, int ref);
|
||||
void Unhook(CBaseEntity *pEntity);
|
||||
void Unhook(IPluginContext *pContext);
|
||||
|
||||
private:
|
||||
int HandleOnTakeDamageHook(CTakeDamageInfoHack &info, SDKHookType hookType);
|
||||
int HandleOnTakeDamageHookPost(CTakeDamageInfoHack &info, SDKHookType hookType);
|
||||
};
|
||||
|
||||
extern CGlobalVars *gpGlobals;
|
||||
extern ke::Vector<CVTableList *> g_HookList[SDKHook_MAXHOOKS];
|
||||
|
||||
extern ICvar *icvar;
|
||||
|
||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||
extern IServerTools *servertools;
|
||||
#endif
|
||||
|
||||
#endif // _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
|
||||
|
@ -119,6 +119,8 @@ enum SDKHookType
|
||||
SDKHook_GetMaxHealth, /**< ep2v and later */
|
||||
SDKHook_Blocked,
|
||||
SDKHook_BlockedPost,
|
||||
SDKHook_OnTakeDamageAlive,
|
||||
SDKHook_OnTakeDamageAlivePost,
|
||||
};
|
||||
|
||||
/*
|
||||
@ -139,6 +141,9 @@ enum SDKHookType
|
||||
SDKHook_OnTakeDamage,
|
||||
SDKHook_OnTakeDamagePost,
|
||||
|
||||
SDKHook_OnTakeDamageAlive,
|
||||
SDKHook_OnTakeDamageAlivePost,
|
||||
|
||||
SDKHook_PreThink,
|
||||
SDKHook_PreThinkPost,
|
||||
|
||||
@ -244,6 +249,7 @@ union SDKHookCB
|
||||
function Action (int entity, int &maxhealth);
|
||||
|
||||
// OnTakeDamage
|
||||
// OnTakeDamagAlive
|
||||
// Note: The weapon parameter is not used by all games and damage sources.
|
||||
// Note: Force application is dependent on game and damage type(s)
|
||||
// SDKHooks 1.0+
|
||||
@ -256,6 +262,7 @@ union SDKHookCB
|
||||
float[3] damageForce, float[3] damagePosition, int damagecustom);
|
||||
|
||||
// OnTakeDamagePost
|
||||
// OnTakeDamageAlivePost
|
||||
function void (int victim, int attacker, int inflictor, float damage, int damagetype);
|
||||
function void (int victim, int attacker, int inflictor, float damage, int damagetype, const float[3] damageForce, const float[3] damagePosition);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user