Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f5933d181e | ||
|
|
246aa90f4d | ||
|
|
d93f6984cc | ||
|
|
207584818f | ||
|
|
7a42d6b564 |
@@ -36,7 +36,11 @@
|
||||
|
||||
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
||||
SH_DECL_HOOK1_void(ICvar, UnregisterConCommand, SH_NOATTRIB, 0, ConCommandBase *);
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
SH_DECL_HOOK2_void(ICvar, RegisterConCommand, SH_NOATTRIB, 0, ConCommandBase *, bool);
|
||||
#else
|
||||
SH_DECL_HOOK1_void(ICvar, RegisterConCommand, SH_NOATTRIB, 0, ConCommandBase *);
|
||||
#endif
|
||||
#else
|
||||
SH_DECL_HOOK1_void(ICvar, RegisterConCommandBase, SH_NOATTRIB, 0, ConCommandBase *);
|
||||
#endif
|
||||
@@ -78,7 +82,11 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
void LinkConCommandBase(ConCommandBase *pBase, bool unknown)
|
||||
#else
|
||||
void LinkConCommandBase(ConCommandBase *pBase)
|
||||
#endif
|
||||
{
|
||||
IConCommandLinkListener *listener = IConCommandLinkListener::head;
|
||||
while (listener)
|
||||
|
||||
@@ -356,27 +356,6 @@ static cell_t GetAvgPackets(IPluginContext *pContext, const cell_t *params)
|
||||
return sp_ftoc(value);
|
||||
}
|
||||
|
||||
static cell_t sm_GetClientIClient(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
int client = params[1];
|
||||
|
||||
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
|
||||
if (!pPlayer)
|
||||
{
|
||||
return pContext->ThrowNativeError("Client index %d is invalid", client);
|
||||
}
|
||||
else if (!pPlayer->IsConnected())
|
||||
{
|
||||
return pContext->ThrowNativeError("Client %d is not connected", client);
|
||||
}
|
||||
else if (pPlayer->IsFakeClient())
|
||||
{
|
||||
return pContext->ThrowNativeError("Client %d is a bot", client);
|
||||
}
|
||||
|
||||
return (cell_t)pPlayer->GetIClient();
|
||||
}
|
||||
|
||||
static cell_t RunAdminCacheChecks(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
int client = params[1];
|
||||
@@ -413,7 +392,6 @@ REGISTER_NATIVES(playernatives)
|
||||
{"GetClientAvgChoke", GetAvgChoke},
|
||||
{"GetClientAvgData", GetAvgData},
|
||||
{"GetClientAvgPackets", GetAvgPackets},
|
||||
{"GetClientIClient", sm_GetClientIClient },
|
||||
{"RunAdminCacheChecks", RunAdminCacheChecks},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@@ -51,6 +51,7 @@ IGameConfig *g_pGameConf = NULL;
|
||||
IGameEventManager2 *gameevents = NULL;
|
||||
bool hooked_everything = false;
|
||||
int g_msgHintText = -1;
|
||||
CGlobalVars *gpGlobals;
|
||||
|
||||
SMEXT_LINK(&g_CStrike);
|
||||
|
||||
@@ -107,6 +108,7 @@ bool CStrike::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool
|
||||
{
|
||||
GET_V_IFACE_CURRENT(GetEngineFactory, gameevents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
|
||||
GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
|
||||
gpGlobals = ismm->GetCGlobals();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -166,6 +166,7 @@ private:
|
||||
extern IBinTools *g_pBinTools;
|
||||
extern IGameConfig *g_pGameConf;
|
||||
extern ISDKTools *g_pSDKTools;
|
||||
extern CGlobalVars *gpGlobals;
|
||||
extern int g_msgHintText;
|
||||
extern bool g_pIgnoreTerminateDetour;
|
||||
extern bool g_pIgnoreCSWeaponDropDetour;
|
||||
|
||||
@@ -58,7 +58,19 @@ void TimeLeftEvents::FireGameEvent(IGameEvent *event)
|
||||
if (get_new_timeleft_offset || !round_end_found)
|
||||
{
|
||||
get_new_timeleft_offset = false;
|
||||
timersys->NotifyOfGameStart();
|
||||
|
||||
float flGameStartTime = gpGlobals->curtime;
|
||||
uintptr_t gamerules = (uintptr_t)g_pSDKTools->GetGameRules();
|
||||
if (gamerules)
|
||||
{
|
||||
sm_sendprop_info_t info;
|
||||
if (gamehelpers->FindSendPropInfo("CCSGameRulesProxy", "m_flGameStartTime", &info))
|
||||
{
|
||||
flGameStartTime = *(float *)(gamerules + info.actual_offset);
|
||||
}
|
||||
}
|
||||
|
||||
timersys->NotifyOfGameStart(flGameStartTime - gpGlobals->curtime);
|
||||
timersys->MapTimeLeftChanged();
|
||||
}
|
||||
round_end_found = false;
|
||||
|
||||
@@ -112,6 +112,7 @@ IServerTools *servertools = NULL;
|
||||
|
||||
// global hooks and forwards
|
||||
IForward *g_pOnEntityCreated = NULL;
|
||||
IForward *g_pOnEntitySpawned = NULL;
|
||||
IForward *g_pOnEntityDestroyed = NULL;
|
||||
|
||||
#ifdef GAMEDESC_CAN_CHANGE
|
||||
@@ -252,6 +253,7 @@ bool SDKHooks::SDK_OnLoad(char *error, size_t maxlength, bool late)
|
||||
plsys->AddPluginsListener(&g_Interface);
|
||||
|
||||
g_pOnEntityCreated = forwards->CreateForward("OnEntityCreated", ET_Ignore, 2, NULL, Param_Cell, Param_String);
|
||||
g_pOnEntitySpawned = forwards->CreateForward("OnEntitySpawned", ET_Ignore, 2, NULL, Param_Cell, Param_String);
|
||||
g_pOnEntityDestroyed = forwards->CreateForward("OnEntityDestroyed", ET_Ignore, 1, NULL, Param_Cell);
|
||||
#ifdef GAMEDESC_CAN_CHANGE
|
||||
g_pOnGetGameNameDescription = forwards->CreateForward("OnGetGameDescription", ET_Hook, 2, NULL, Param_String);
|
||||
@@ -344,6 +346,7 @@ void SDKHooks::SDK_OnUnload()
|
||||
#endif
|
||||
|
||||
forwards->ReleaseForward(g_pOnEntityCreated);
|
||||
forwards->ReleaseForward(g_pOnEntitySpawned);
|
||||
forwards->ReleaseForward(g_pOnEntityDestroyed);
|
||||
#ifdef GAMEDESC_CAN_CHANGE
|
||||
forwards->ReleaseForward(g_pOnGetGameNameDescription);
|
||||
@@ -420,6 +423,7 @@ void SDKHooks::OnClientPutInServer(int client)
|
||||
CBaseEntity *pPlayer = gamehelpers->ReferenceToEntity(client);
|
||||
|
||||
HandleEntityCreated(pPlayer, client, gamehelpers->EntityToReference(pPlayer));
|
||||
HandleEntitySpawned(pPlayer, client, gamehelpers->EntityToReference(pPlayer));
|
||||
}
|
||||
|
||||
void SDKHooks::OnClientDisconnecting(int client)
|
||||
@@ -879,6 +883,27 @@ void SDKHooks::OnEntityCreated(CBaseEntity *pEntity)
|
||||
}
|
||||
}
|
||||
|
||||
void SDKHooks::OnEntitySpawned(CBaseEntity *pEntity)
|
||||
{
|
||||
// Call OnEntitySpawned forward
|
||||
int ref = gamehelpers->EntityToReference(pEntity);
|
||||
int index = gamehelpers->ReferenceToIndex(ref);
|
||||
|
||||
// This can be -1 for player ents before any players have connected
|
||||
if ((unsigned)index == INVALID_EHANDLE_INDEX || (index > 0 && index <= playerhelpers->GetMaxClients()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IsEntityIndexInRange(index))
|
||||
{
|
||||
g_pSM->LogError(myself, "SDKHooks::OnEntitySpawned - Got entity index out of range (%d)", index);
|
||||
return;
|
||||
}
|
||||
|
||||
HandleEntitySpawned(pEntity, index, ref);
|
||||
}
|
||||
|
||||
#ifdef GAMEDESC_CAN_CHANGE
|
||||
const char *SDKHooks::Hook_GetGameDescription()
|
||||
{
|
||||
@@ -1791,6 +1816,32 @@ void SDKHooks::HandleEntityCreated(CBaseEntity *pEntity, int index, cell_t ref)
|
||||
m_EntityCache[index] = ref;
|
||||
}
|
||||
|
||||
void SDKHooks::HandleEntitySpawned(CBaseEntity *pEntity, int index, cell_t ref)
|
||||
{
|
||||
if (g_pOnEntitySpawned->GetFunctionCount() || m_EntListeners.size())
|
||||
{
|
||||
cell_t bcompatRef = gamehelpers->EntityToBCompatRef(pEntity);
|
||||
const char *pName = gamehelpers->GetEntityClassname(pEntity);
|
||||
if (!pName)
|
||||
pName = "";
|
||||
|
||||
// Send OnEntitySpawned to SM listeners
|
||||
for (SourceHook::List<ISMEntityListener *>::iterator iter = m_EntListeners.begin(); iter != m_EntListeners.end(); iter++)
|
||||
{
|
||||
ISMEntityListener *pListener = (*iter);
|
||||
pListener->OnEntitySpawned(pEntity, pName);
|
||||
}
|
||||
|
||||
// Call OnEntitySpawned forward
|
||||
if (g_pOnEntitySpawned->GetFunctionCount())
|
||||
{
|
||||
g_pOnEntitySpawned->PushCell(bcompatRef);
|
||||
g_pOnEntitySpawned->PushString(pName);
|
||||
g_pOnEntitySpawned->Execute(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SDKHooks::HandleEntityDeleted(CBaseEntity *pEntity)
|
||||
{
|
||||
cell_t bcompatRef = gamehelpers->EntityToBCompatRef(pEntity);
|
||||
|
||||
@@ -238,6 +238,7 @@ public: // IFeatureProvider
|
||||
|
||||
public: // IEntityListener
|
||||
virtual void OnEntityCreated(CBaseEntity *pEntity);
|
||||
virtual void OnEntitySpawned(CBaseEntity *pEntity);
|
||||
virtual void OnEntityDeleted(CBaseEntity *pEntity);
|
||||
|
||||
public: // IClientListener
|
||||
@@ -330,6 +331,7 @@ public:
|
||||
|
||||
private:
|
||||
void HandleEntityCreated(CBaseEntity *pEntity, int index, cell_t ref);
|
||||
void HandleEntitySpawned(CBaseEntity *pEntity, int index, cell_t ref);
|
||||
void HandleEntityDeleted(CBaseEntity *pEntity);
|
||||
void Unhook(CBaseEntity *pEntity);
|
||||
void Unhook(IPluginContext *pContext);
|
||||
|
||||
@@ -741,15 +741,6 @@ native float GetClientAvgData(int client, NetFlow flow);
|
||||
*/
|
||||
native float GetClientAvgPackets(int client, NetFlow flow);
|
||||
|
||||
/**
|
||||
* Returns the client's baseserver IClient pointer.
|
||||
*
|
||||
* @param client Player's index.
|
||||
* @return IClient address.
|
||||
* @error Invalid client index, client not connected, or fake client.
|
||||
*/
|
||||
native Address GetClientIClient(int client);
|
||||
|
||||
/**
|
||||
* Translates an userid index to the real player index.
|
||||
*
|
||||
|
||||
@@ -615,7 +615,10 @@ native int FormatNativeString(int out_param,
|
||||
*
|
||||
* @param data Data passed to the RequestFrame native.
|
||||
*/
|
||||
typedef RequestFrameCallback = function void (any data);
|
||||
typeset RequestFrameCallback {
|
||||
function void ();
|
||||
function void (any data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a single use Next Frame hook.
|
||||
|
||||
@@ -333,6 +333,14 @@ typeset SDKHookCB
|
||||
*/
|
||||
forward void OnEntityCreated(int entity, const char[] classname);
|
||||
|
||||
/**
|
||||
* When an entity is spawned
|
||||
*
|
||||
* @param entity Entity index
|
||||
* @param classname Class name
|
||||
*/
|
||||
forward void OnEntitySpawned(int entity, const char[] classname);
|
||||
|
||||
/**
|
||||
* When an entity is destroyed
|
||||
*
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#include <IShareSys.h>
|
||||
|
||||
#define SMINTERFACE_SDKHOOKS_NAME "ISDKHooks"
|
||||
#define SMINTERFACE_SDKHOOKS_VERSION 1
|
||||
#define SMINTERFACE_SDKHOOKS_VERSION 2
|
||||
|
||||
class CBaseEntity;
|
||||
|
||||
@@ -71,6 +71,16 @@ namespace SourceMod
|
||||
virtual void OnEntityDestroyed(CBaseEntity *pEntity)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief When an entity is spawned
|
||||
*
|
||||
* @param pEntity CBaseEntity entity.
|
||||
* @param classname Entity classname.
|
||||
*/
|
||||
virtual void OnEntitySpawned(CBaseEntity *pEntity, const char *classname)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user