Added ISDKHooks interface with entity listeners (bug 5602, r=psychonic).
This commit is contained in:
@@ -185,6 +185,7 @@ bool SDKHooks::SDK_OnLoad(char *error, size_t maxlength, bool late)
|
||||
sharesys->AddDependency(myself, "bintools.ext", true, true);
|
||||
sharesys->AddNatives(myself, g_Natives);
|
||||
sharesys->RegisterLibrary(myself, "sdkhooks");
|
||||
sharesys->AddInterface(myself, &g_Interface);
|
||||
sharesys->AddCapabilityProvider(myself, this, "SDKHook_DmgCustomInOTD");
|
||||
sharesys->AddCapabilityProvider(myself, this, "SDKHook_LogicalEntSupport");
|
||||
|
||||
@@ -391,18 +392,36 @@ void SDKHooks::OnPluginUnloaded(IPlugin *plugin)
|
||||
|
||||
void SDKHooks::OnClientPutInServer(int client)
|
||||
{
|
||||
g_pOnEntityCreated->PushCell(client);
|
||||
|
||||
CBaseEntity *pPlayer = gamehelpers->ReferenceToEntity(client);
|
||||
const char *pName = gamehelpers->GetEntityClassname(pPlayer);
|
||||
|
||||
const char * pName = gamehelpers->GetEntityClassname(pPlayer);
|
||||
// Send OnEntityCreated to SM listeners
|
||||
SourceHook::List<ISMEntityListener *>::iterator iter;
|
||||
ISMEntityListener *pListener = NULL;
|
||||
for (iter=m_EntListeners.begin(); iter!=m_EntListeners.end(); iter++)
|
||||
{
|
||||
pListener = (*iter);
|
||||
pListener->OnEntityCreated(pPlayer, pName ? pName : "");
|
||||
}
|
||||
|
||||
// Call OnEntityCreated forward
|
||||
g_pOnEntityCreated->PushCell(client);
|
||||
g_pOnEntityCreated->PushString(pName ? pName : "");
|
||||
g_pOnEntityCreated->Execute(NULL);
|
||||
|
||||
m_EntityExists.Set(client);
|
||||
}
|
||||
|
||||
void SDKHooks::AddEntityListener(ISMEntityListener *listener)
|
||||
{
|
||||
m_EntListeners.push_back(listener);
|
||||
}
|
||||
|
||||
void SDKHooks::RemoveEntityListener(ISMEntityListener *listener)
|
||||
{
|
||||
m_EntListeners.remove(listener);
|
||||
}
|
||||
|
||||
bool SDKHooks::RegisterConCommandBase(ConCommandBase *pVar)
|
||||
{
|
||||
/* Always call META_REGCVAR instead of going through the engine. */
|
||||
@@ -824,11 +843,19 @@ void SDKHooks::OnEntityCreated(CBaseEntity *pEntity)
|
||||
return;
|
||||
}
|
||||
|
||||
const char *pName = gamehelpers->GetEntityClassname(pEntity);
|
||||
|
||||
// Send OnEntityCreated to SM listeners
|
||||
SourceHook::List<ISMEntityListener *>::iterator iter;
|
||||
ISMEntityListener *pListener = NULL;
|
||||
for (iter=m_EntListeners.begin(); iter!=m_EntListeners.end(); iter++)
|
||||
{
|
||||
pListener = (*iter);
|
||||
pListener->OnEntityCreated(pEntity, pName ? pName : "");
|
||||
}
|
||||
|
||||
g_pOnEntityCreated->PushCell(gamehelpers->EntityToBCompatRef(pEntity));
|
||||
|
||||
const char * pName = gamehelpers->GetEntityClassname(pEntity);
|
||||
g_pOnEntityCreated->PushString(pName ? pName : "");
|
||||
|
||||
g_pOnEntityCreated->Execute(NULL);
|
||||
|
||||
m_EntityExists.Set(entity);
|
||||
@@ -1394,6 +1421,15 @@ void SDKHooks::Hook_UsePost(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_T
|
||||
|
||||
void SDKHooks::OnEntityDeleted(CBaseEntity *pEntity)
|
||||
{
|
||||
// Send OnEntityDestroyed to SM listeners
|
||||
SourceHook::List<ISMEntityListener *>::iterator iter;
|
||||
ISMEntityListener *pListener = NULL;
|
||||
for (iter=m_EntListeners.begin(); iter!=m_EntListeners.end(); iter++)
|
||||
{
|
||||
pListener = (*iter);
|
||||
pListener->OnEntityDestroyed(pEntity);
|
||||
}
|
||||
|
||||
int entity = gamehelpers->EntityToBCompatRef(pEntity);
|
||||
|
||||
// Call OnEntityDestroyed forward
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
#define _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
|
||||
|
||||
#include "smsdk_ext.h"
|
||||
#include <ISDKHooks.h>
|
||||
#include <IBinTools.h>
|
||||
#include <convar.h>
|
||||
#include <sh_list.h>
|
||||
|
||||
#include <iplayerinfo.h>
|
||||
#include <shareddefs.h>
|
||||
@@ -120,7 +122,8 @@ class SDKHooks :
|
||||
public IPluginsListener,
|
||||
public IFeatureProvider,
|
||||
public IEntityListener,
|
||||
public IClientListener
|
||||
public IClientListener,
|
||||
public ISDKHooks
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -215,6 +218,13 @@ public: // IEntityListener
|
||||
public: // IClientListener
|
||||
virtual void OnClientPutInServer(int client);
|
||||
|
||||
public: // ISDKHooks
|
||||
virtual void AddEntityListener(ISMEntityListener *listener);
|
||||
virtual void RemoveEntityListener(ISMEntityListener *listener);
|
||||
|
||||
private:
|
||||
SourceHook::List<ISMEntityListener *> m_EntListeners;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Functions
|
||||
|
||||
@@ -1300,6 +1300,7 @@
|
||||
<ClCompile Include="..\sdk\smsdk_ext.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\..\public\extensions\ISDKHooks.h" />
|
||||
<ClInclude Include="..\extension.h" />
|
||||
<ClInclude Include="..\macros.h" />
|
||||
<ClInclude Include="..\natives.h" />
|
||||
|
||||
@@ -56,6 +56,9 @@
|
||||
<ClInclude Include="..\sdk\smsdk_ext.h">
|
||||
<Filter>SourceMod SDK</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\public\extensions\ISDKHooks.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="..\version.rc">
|
||||
|
||||
Reference in New Issue
Block a user