diff --git a/extensions/sdktools/CellRecipientFilter.h b/extensions/sdktools/CellRecipientFilter.h new file mode 100644 index 00000000..ee7ebbbc --- /dev/null +++ b/extensions/sdktools/CellRecipientFilter.h @@ -0,0 +1,99 @@ +/** + * vim: set ts=4 : + * =============================================================== + * SourceMod SDK Tools Extension + * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. + * =============================================================== + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Version: $Id$ + */ + +#ifndef _INCLUDE_SOURCEMOD_CELLRECIPIENTFILTER_H_ +#define _INCLUDE_SOURCEMOD_CELLRECIPIENTFILTER_H_ + +#include +#include + +class CellRecipientFilter : public IRecipientFilter +{ +public: + CellRecipientFilter() : m_IsReliable(false), m_IsInitMessage(false), m_Size(0) {} + ~CellRecipientFilter() {} +public: //IRecipientFilter + bool IsReliable() const; + bool IsInitMessage() const; + int GetRecipientCount() const; + int GetRecipientIndex(int slot) const; +public: + void Initialize(cell_t *ptr, size_t count); + void SetToReliable(bool isreliable); + void SetToInit(bool isinitmsg); + void Reset(); +private: + cell_t m_Players[255]; + bool m_IsReliable; + bool m_IsInitMessage; + size_t m_Size; +}; + +inline void CellRecipientFilter::Reset() +{ + m_IsReliable = false; + m_IsInitMessage = false; + m_Size = 0; +} + +inline bool CellRecipientFilter::IsReliable() const +{ + return m_IsReliable; +} + +inline bool CellRecipientFilter::IsInitMessage() const +{ + return m_IsInitMessage; +} + +inline int CellRecipientFilter::GetRecipientCount() const +{ + return m_Size; +} + +inline int CellRecipientFilter::GetRecipientIndex(int slot) const +{ + if ((slot < 0) || (slot >= GetRecipientCount())) + { + return -1; + } + return static_cast(m_Players[slot]); +} + +inline void CellRecipientFilter::SetToInit(bool isinitmsg) +{ + m_IsInitMessage = isinitmsg; +} + +inline void CellRecipientFilter::SetToReliable(bool isreliable) +{ + m_IsReliable = isreliable; +} + +inline void CellRecipientFilter::Initialize(cell_t *ptr, size_t count) +{ + memcpy(m_Players, ptr, count * sizeof(cell_t)); + m_Size = count; +} + +#endif //_INCLUDE_SOURCEMOD_CELLRECIPIENTFILTER_H_ diff --git a/extensions/sdktools/extension.cpp b/extensions/sdktools/extension.cpp index 6481baf6..3efac8dc 100644 --- a/extensions/sdktools/extension.cpp +++ b/extensions/sdktools/extension.cpp @@ -24,6 +24,7 @@ #include "extension.h" #include "vcallbuilder.h" #include "vnatives.h" +#include "tempents.h" /** * @file extension.cpp @@ -34,17 +35,22 @@ SDKTools g_SdkTools; /**< Global singleton for extension's main interface */ IServerGameEnts *gameents = NULL; IBinTools *g_pBinTools = NULL; IGameConfig *g_pGameConf = NULL; +IGameHelpers *g_pGameHelpers = NULL; HandleType_t g_CallHandle = 0; SMEXT_LINK(&g_SdkTools); extern sp_nativeinfo_t g_CallNatives[]; +extern sp_nativeinfo_t g_TENatives[]; bool SDKTools::SDK_OnLoad(char *error, size_t maxlength, bool late) { sharesys->AddDependency(myself, "bintools.ext", true, true); sharesys->AddNatives(myself, g_CallNatives); sharesys->AddNatives(myself, g_Natives); + sharesys->AddNatives(myself, g_TENatives); + + SM_GET_IFACE(GAMEHELPERS, g_pGameHelpers); if (!gameconfs->LoadGameConfigFile("sdktools.games", &g_pGameConf, error, maxlength)) { @@ -76,6 +82,8 @@ void SDKTools::SDK_OnUnload() } g_RegCalls.clear(); + g_TEManager.Shutdown(); + gameconfs->CloseGameConfigFile(g_pGameConf); } @@ -89,6 +97,7 @@ bool SDKTools::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool void SDKTools::SDK_OnAllLoaded() { SM_GET_LATE_IFACE(BINTOOLS, g_pBinTools); + g_TEManager.Initialize(); } bool SDKTools::QueryRunning(char *error, size_t maxlength) @@ -119,4 +128,5 @@ void SDKTools::NotifyInterfaceDrop(SMInterface *pInterface) } g_RegCalls.clear(); + g_TEManager.Shutdown(); } diff --git a/extensions/sdktools/extension.h b/extensions/sdktools/extension.h index 9693a67c..e40ac9b4 100644 --- a/extensions/sdktools/extension.h +++ b/extensions/sdktools/extension.h @@ -32,6 +32,7 @@ #include "smsdk_ext.h" #include #include +#include /** * @brief Implementation of the SDK Tools extension. @@ -60,6 +61,7 @@ public: extern IServerGameEnts *gameents; extern IBinTools *g_pBinTools; extern IGameConfig *g_pGameConf; +extern IGameHelpers *g_pGameHelpers; extern HandleType_t g_CallHandle; #endif //_INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_ diff --git a/extensions/sdktools/msvc8/sdktools.vcproj b/extensions/sdktools/msvc8/sdktools.vcproj index 7c8e7e87..92f602e3 100644 --- a/extensions/sdktools/msvc8/sdktools.vcproj +++ b/extensions/sdktools/msvc8/sdktools.vcproj @@ -1,7 +1,7 @@ + + + + @@ -207,10 +215,18 @@ Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{046AC4F8-1F40-462f-B652-698F87CDCA5F}" > + + + + diff --git a/extensions/sdktools/sdk/smsdk_config.h b/extensions/sdktools/sdk/smsdk_config.h index 402d3022..22e73f51 100644 --- a/extensions/sdktools/sdk/smsdk_config.h +++ b/extensions/sdktools/sdk/smsdk_config.h @@ -56,6 +56,6 @@ #define SMEXT_ENABLE_MEMUTILS //#define SMEXT_ENABLE_GAMEHELPERS //#define SMEXT_ENABLE_TIMERSYS -//#define SMEXT_ENABLE_ADTFACTORY +#define SMEXT_ENABLE_ADTFACTORY #endif // _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_ diff --git a/extensions/sdktools/tempents.cpp b/extensions/sdktools/tempents.cpp new file mode 100644 index 00000000..d67fcac7 --- /dev/null +++ b/extensions/sdktools/tempents.cpp @@ -0,0 +1,246 @@ +/** + * vim: set ts=4 : + * =============================================================== + * SourceMod SDK Tools Extension + * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. + * =============================================================== + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Version: $Id$ + */ + +#include "tempents.h" + +TempEntityManager g_TEManager; +ICallWrapper *g_GetServerClass = NULL; + +/************************* +* * +* Temp Entities Wrappers * +* * +**************************/ + +TempEntityInfo::TempEntityInfo(const char *name, void *me) +{ + m_Name.assign(name); + m_Me = me; + g_GetServerClass->Execute(&m_Me, &m_Sc); +} + +const char *TempEntityInfo::GetName() +{ + return m_Name.c_str(); +} + +bool TempEntityInfo::IsValidProp(const char *name) +{ + return (g_pGameHelpers->FindInSendTable(m_Sc->GetName(), name)) ? true : false; +} + +int TempEntityInfo::_FindOffset(const char *name, int *size) +{ + int offset; + + SendProp *prop = g_pGameHelpers->FindInSendTable(m_Sc->GetName(), name); + if (!prop) + { + return -1; + } + + offset = prop->GetOffset(); + if (size) + { + *size = prop->m_nBits + } + + return offset; +} + +bool TempEntityInfo::TE_SetEntData(const char *name, int value) +{ + /* Search for our offset */ + int size; + int offset = _FindOffset(name, &size); + + if (offset < 0) + { + return false; + } + + if (size <= 8) + { + *((uint8_t *)m_Me + offset) = value; + } else if (size <= 16) { + *(short *)((uint8_t *)m_Me + offset) = value; + } else if (size <= 32){ + *(int *)((uint8_t *)m_Me + offset) = value; + } else { + return false; + } + + return true; +} + +bool TempEntityInfo::TE_SetEntDataFloat(const char *name, float value) +{ + /* Search for our offset */ + int offset = _FindOffset(name); + + if (offset < 0) + { + return false; + } + + *(float *)((uint8_t *)m_Me + offset) = value; + + return true; +} + +bool TempEntityInfo::TE_SetEntDataVector(const char *name, float vector[3]) +{ + /* Search for our offset */ + int offset = _FindOffset(name); + + if (offset < 0) + { + return false; + } + + Vector *v = (Vector *)((uint8_t *)m_Me + offset); + v->x = vector[0]; + v->y = vector[1]; + v->z = vector[2]; + + return true; +} + +void TempEntityInfo::Send(IRecipientFilter &filter, float delay) +{ + engine->PlaybackTempEntity(filter, delay, (void *)m_Me, m_Sc->m_pTable, m_Sc->m_ClassID); +} + +/********************** +* * +* Temp Entity Manager * +* * +***********************/ + +void TempEntityManager::Initialize() +{ + void *addr; + int offset; + m_Loaded = false; + + /* Read our sigs and offsets from the config file */ + if (!g_pGameConf->GetMemSig("CBaseTempEntity", &addr) || !addr) + { + return; + } + if (!g_pGameConf->GetOffset("s_pTempEntities", &offset) || !offset) + { + return; + } + if (!g_pGameConf->GetOffset("GetTEName", &m_NameOffs) || !m_NameOffs) + { + return; + } + if (!g_pGameConf->GetOffset("GetTENext", &m_NextOffs) || !m_NextOffs) + { + return; + } + if (!g_pGameConf->GetOffset("TE_GetServerClass", &m_GetClassNameOffs) || !m_GetClassNameOffs) + { + return; + } + + /* Store the head of the TE linked list */ + m_ListHead = **(void ***)((unsigned char *)addr + offset); + + /* Create our trie */ + m_TempEntInfo = adtfactory->CreateBasicTrie(); + + /* Create the GetServerClass call */ + PassInfo retinfo; + retinfo.flags = PASSFLAG_BYVAL; + retinfo.type = PassType_Basic; + retinfo.size = sizeof(ServerClass *); + g_GetServerClass = g_pBinTools->CreateVCall(m_GetClassNameOffs, 0, 0, &retinfo, NULL, 0); + + /* We're done */ + m_Loaded = true; +} + +bool TempEntityManager::IsAvailable() +{ + return m_Loaded; +} + +void TempEntityManager::Shutdown() +{ + if (!IsAvailable()) + { + return; + } + + List::iterator iter; + for (iter=m_TEList.begin(); iter!=m_TEList.end(); iter++) + { + delete (*iter); + } + m_TEList.clear(); + + m_TempEntInfo->Destroy(); + g_GetServerClass->Destroy(); + g_GetServerClass = NULL; + m_ListHead = NULL; + m_NextOffs = m_NameOffs = m_GetClassNameOffs = 0; + m_Loaded = false; +} + +TempEntityInfo *TempEntityManager::GetTempEntityInfo(const char *name) +{ + /* If the system is unloaded skip the search */ + if (!IsAvailable()) + { + return NULL; + } + + TempEntityInfo *te = NULL; + + /* Start searching for the TE inside the engine */ + if (!m_TempEntInfo->Retrieve(name, reinterpret_cast(&te))) + { + void *iter = m_ListHead; + while (iter) + { + const char *realname = *(const char **)((unsigned char *)iter + m_NameOffs); + if (!realname) + { + continue; + } + if (strcmp(name, realname) == 0) + { + te = new TempEntityInfo(name, iter); + m_TempEntInfo->Insert(name, (void *)te); + m_TEList.push_back(te); + return te; + } + iter = *(void **)((unsigned char *)iter + m_NextOffs); + } + return NULL; + } + + return te; +} diff --git a/extensions/sdktools/tempents.h b/extensions/sdktools/tempents.h new file mode 100644 index 00000000..52b14600 --- /dev/null +++ b/extensions/sdktools/tempents.h @@ -0,0 +1,75 @@ +/** + * vim: set ts=4 : + * =============================================================== + * SourceMod SDK Tools Extension + * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. + * =============================================================== + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Version: $Id$ + */ + +#ifndef _INCLUDE_SOURCEMOD_TEMPENTS_H_ +#define _INCLUDE_SOURCEMOD_TEMPENTS_H_ + +#include "extension.h" +#include +#include +#include + +using namespace SourceHook; + +class TempEntityInfo +{ +public: + TempEntityInfo(const char *name, void *me); +public: + const char *GetName(); + bool IsValidProp(const char *name); + bool TE_SetEntData(const char *name, int value); + bool TE_SetEntDataFloat(const char *name, float value); + bool TE_SetEntDataVector(const char *name, float vector[3]); + void Send(IRecipientFilter &filter, float delay); +private: + int _FindOffset(const char *name, int *size=NULL); +private: + void *m_Me; + ServerClass *m_Sc; + String m_Name; +}; + +class TempEntityManager +{ +public: + TempEntityManager() : m_NameOffs(0), m_NextOffs(0), m_GetClassNameOffs(0), m_Loaded(false) {} +public: + void Initialize(); + bool IsAvailable(); + void Shutdown(); +public: + TempEntityInfo *GetTempEntityInfo(const char *name); +private: + List m_TEList; + IBasicTrie *m_TempEntInfo; + void *m_ListHead; + int m_NameOffs; + int m_NextOffs; + int m_GetClassNameOffs; + bool m_Loaded; +}; + +extern TempEntityManager g_TEManager; + +#endif //_INCLUDE_SOURCEMOD_TEMPENTS_H_ diff --git a/extensions/sdktools/tenatives.cpp b/extensions/sdktools/tenatives.cpp new file mode 100644 index 00000000..db682763 --- /dev/null +++ b/extensions/sdktools/tenatives.cpp @@ -0,0 +1,169 @@ +/** + * vim: set ts=4 : + * =============================================================== + * SourceMod SDK Tools Extension + * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. + * =============================================================== + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Version: $Id$ + */ + +#include "tempents.h" +#include "CellRecipientFilter.h" + +CellRecipientFilter g_TERecFilter; +TempEntityInfo *g_CurrentTE = NULL; + +static cell_t smn_TEStart(IPluginContext *pContext, const cell_t *params) +{ + if (!g_TEManager.IsAvailable()) + { + return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report"); + } + + char *name; + pContext->LocalToString(params[1], &name); + + g_CurrentTE = g_TEManager.GetTempEntityInfo(name); + if (!g_CurrentTE) + { + return pContext->ThrowNativeError("Invalid TempEntity name: \"%s\"", name); + } + + return 1; +} + +static cell_t smn_TEWriteNum(IPluginContext *pContext, const cell_t *params) +{ + if (!g_TEManager.IsAvailable()) + { + return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report"); + } + if (!g_CurrentTE) + { + return pContext->ThrowNativeError("No TempEntity call is in progress"); + } + + char *prop; + pContext->LocalToString(params[1], &prop); + + if (!g_CurrentTE->TE_SetEntData(prop, params[2])) + { + return pContext->ThrowNativeError("Temp entity property \"%s\" not found", prop); + } + + return 1; +} + +static cell_t smn_TE_WriteFloat(IPluginContext *pContext, const cell_t *params) +{ + if (!g_TEManager.IsAvailable()) + { + return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report"); + } + if (!g_CurrentTE) + { + return pContext->ThrowNativeError("No TempEntity call is in progress"); + } + + char *prop; + pContext->LocalToString(params[1], &prop); + + if (!g_CurrentTE->TE_SetEntDataFloat(prop, sp_ctof(params[2]))) + { + return pContext->ThrowNativeError("Temp entity property \"%s\" not found", prop); + } + + return 1; +} + +static cell_t smn_TEWriteVector(IPluginContext *pContext, const cell_t *params) +{ + if (!g_TEManager.IsAvailable()) + { + return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report"); + } + if (!g_CurrentTE) + { + return pContext->ThrowNativeError("No TempEntity call is in progress"); + } + + char *prop; + pContext->LocalToString(params[1], &prop); + + cell_t *addr; + pContext->LocalToPhysAddr(params[2], &addr); + float vec[3] = {sp_ctof(addr[0]), sp_ctof(addr[1]), sp_ctof(addr[2])}; + + if (!g_CurrentTE->TE_SetEntDataVector(prop, vec)) + { + return pContext->ThrowNativeError("Temp entity property \"%s\" not found", prop); + } + + return 1; +} + +static cell_t smn_TESend(IPluginContext *pContext, const cell_t *params) +{ + if (!g_TEManager.IsAvailable()) + { + return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report"); + } + if (!g_CurrentTE) + { + return pContext->ThrowNativeError("No TempEntity call is in progress"); + } + + cell_t *cl_array; + pContext->LocalToPhysAddr(params[1], &cl_array); + + g_TERecFilter.Reset(); + g_TERecFilter.Initialize(cl_array, params[2]); + + g_CurrentTE->Send(g_TERecFilter, sp_ctof(params[3])); + g_CurrentTE = NULL; + + return 1; +} + +static cell_t smn_TEIsValidProp(IPluginContext *pContext, const cell_t *params) +{ + if (!g_TEManager.IsAvailable()) + { + return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report"); + } + if (!g_CurrentTE) + { + return pContext->ThrowNativeError("No TempEntity call is in progress"); + } + + char *prop; + pContext->LocalToString(params[1], &prop); + + return g_CurrentTE->IsValidProp(prop) ? 1 : 0; +} + +sp_nativeinfo_t g_TENatives[] = +{ + {"TE_Start", smn_TEStart}, + {"TE_WriteNum", smn_TEWriteNum}, + {"TE_WriteFloat", smn_TE_WriteFloat}, + {"TE_WriteVector", smn_TEWriteVector}, + {"TE_WriteAngles", smn_TEWriteVector}, + {"TE_Send", smn_TESend}, + {"TE_IsValidProp", smn_TEIsValidProp}, + {NULL, NULL} +}; diff --git a/extensions/sdktools/vcallbuilder.cpp b/extensions/sdktools/vcallbuilder.cpp index 934b672e..7243408b 100644 --- a/extensions/sdktools/vcallbuilder.cpp +++ b/extensions/sdktools/vcallbuilder.cpp @@ -1,3 +1,26 @@ +/** + * vim: set ts=4 : + * =============================================================== + * SourceMod SDK Tools Extension + * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. + * =============================================================== + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Version: $Id$ + */ + #include "vcallbuilder.h" #include "extension.h" diff --git a/extensions/sdktools/vcallbuilder.h b/extensions/sdktools/vcallbuilder.h index 23b9e295..937dd05c 100644 --- a/extensions/sdktools/vcallbuilder.h +++ b/extensions/sdktools/vcallbuilder.h @@ -1,3 +1,26 @@ +/** + * vim: set ts=4 : + * =============================================================== + * SourceMod SDK Tools Extension + * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. + * =============================================================== + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Version: $Id$ + */ + #ifndef _INCLUDE_SOURCEMOD_VALVE_CALLER_H_ #define _INCLUDE_SOURCEMOD_VALVE_CALLER_H_ diff --git a/extensions/sdktools/vcaller.cpp b/extensions/sdktools/vcaller.cpp index f6d8ab6d..73c6db0f 100644 --- a/extensions/sdktools/vcaller.cpp +++ b/extensions/sdktools/vcaller.cpp @@ -1,3 +1,26 @@ +/** + * vim: set ts=4 : + * =============================================================== + * SourceMod SDK Tools Extension + * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. + * =============================================================== + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Version: $Id$ + */ + #include "extension.h" #include "vcallbuilder.h" diff --git a/extensions/sdktools/vdecoder.cpp b/extensions/sdktools/vdecoder.cpp index 0f01c25d..e2089dba 100644 --- a/extensions/sdktools/vdecoder.cpp +++ b/extensions/sdktools/vdecoder.cpp @@ -1,3 +1,26 @@ +/** + * vim: set ts=4 : + * =============================================================== + * SourceMod SDK Tools Extension + * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. + * =============================================================== + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Version: $Id$ + */ + #include "smsdk_ext.h" #include "extension.h" #include "vdecoder.h" diff --git a/extensions/sdktools/vdecoder.h b/extensions/sdktools/vdecoder.h index eb98894e..453e98c4 100644 --- a/extensions/sdktools/vdecoder.h +++ b/extensions/sdktools/vdecoder.h @@ -1,3 +1,26 @@ +/** + * vim: set ts=4 : + * =============================================================== + * SourceMod SDK Tools Extension + * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. + * =============================================================== + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Version: $Id$ + */ + #ifndef _INCLUDE_SOURCEMOD_VDECODER_H_ #define _INCLUDE_SOURCEMOD_VDECODER_H_ diff --git a/extensions/sdktools/vnatives.cpp b/extensions/sdktools/vnatives.cpp index c016fdb4..0c3e7e0a 100644 --- a/extensions/sdktools/vnatives.cpp +++ b/extensions/sdktools/vnatives.cpp @@ -1,3 +1,26 @@ +/** + * vim: set ts=4 : + * =============================================================== + * SourceMod SDK Tools Extension + * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. + * =============================================================== + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Version: $Id$ + */ + #include "extension.h" #include "vcallbuilder.h" #include "vnatives.h" diff --git a/extensions/sdktools/vnatives.h b/extensions/sdktools/vnatives.h index 8c235644..a0ac3ae4 100644 --- a/extensions/sdktools/vnatives.h +++ b/extensions/sdktools/vnatives.h @@ -1,3 +1,26 @@ +/** + * vim: set ts=4 : + * =============================================================== + * SourceMod SDK Tools Extension + * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. + * =============================================================== + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Version: $Id$ + */ + #ifndef _INCLUDE_SDKTOOLS_VNATIVES_H_ #define _INCLUDE_SDKTOOLS_VNATIVES_H_ diff --git a/gamedata/sdktools.games.txt b/gamedata/sdktools.games.txt index 0837b14c..bdeda297 100644 --- a/gamedata/sdktools.games.txt +++ b/gamedata/sdktools.games.txt @@ -41,4 +41,50 @@ } } } + + /* Temp Entities Section */ + "#default" + { + "#supported" + { + "game" "cstrike" + "game" "dod" + "game" "hl2mp" + } + + "Offsets" + { + /* Offset into CBaseTempEntity constructor */ + "s_pTempEntities" + { + "windows" "17" + "linux" "27" + } + "GetTEName" + { + "windows" "4" + "linux" "4" + } + "GetTENext" + { + "windows" "8" + "linux" "8" + } + "TE_GetServerClass" + { + "windows" "1" + "linux" "1" + } + } + + "Signatures" + { + "CBaseTempEntity" + { + "library" "server" + "windows" "\x8B\xC1\x8B\x4C\x24\x04\xC7\x00\x2A\x2A\x2A\x2A\x89\x48\x04\x8B\x15\x2A\x2A\x2A\x2A\x89\x50\x08\xA3\x2A\x2A\x2A\x2A\xC2\x04\x00" + "linux" "@_ZN15CBaseTempEntityC2EPKc" + } + } + } } diff --git a/plugins/include/sdktools.inc b/plugins/include/sdktools.inc index 988ea505..94617190 100644 --- a/plugins/include/sdktools.inc +++ b/plugins/include/sdktools.inc @@ -20,6 +20,7 @@ #include #include +#include enum SDKCallType { diff --git a/plugins/include/sdktools_tempents.inc b/plugins/include/sdktools_tempents.inc new file mode 100644 index 00000000..5ad21fbb --- /dev/null +++ b/plugins/include/sdktools_tempents.inc @@ -0,0 +1,142 @@ +/** + * vim: set ts=4 : + * =============================================================== + * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. + * =============================================================== + * + * This file is part of the SourceMod/SourcePawn SDK. This file may only be used + * or modified under the Terms and Conditions of its License Agreement, which is found + * in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins + * may change at any time. To view the latest information, see: + * http://www.sourcemod.net/license.php + * + * Version: $Id$ + */ + +#if defined _sdktools_tempents_included + #endinput +#endif +#define _sdktools_tempents_included + +/** + * Starts a temp entity transmission. + * + * @param te_name TE name. + * @noreturn + * @error Temp Entity name not available. + */ +native TE_Start(const String:te_name[]); + +/** + * Checks if a certain TE property exists. + * + * @param prop Property to use. + * @return True if the property exists, otherwise false. + */ +native bool:TE_IsValidProp(const String:prop[]); + +/** + * Sets an integer value in the current temp entity. + * + * @param prop Property to use. + * @param value Integer value to set. + * @noreturn + * @error Property not found. + */ +native TE_WriteNum(const String:prop[], value); + +/** + * Sets a floating point number in the current temp entity. + * + * @param prop Property to use. + * @param value Floating point number to set. + * @noreturn + * @error Property not found. + */ +native TE_WriteFloat(const String:prop[], Float:value); + +/** + * Sets a vector in the current temp entity. + * + * @param prop Property to use. + * @param vector Vector to set. + * @noreturn + * @error Property not found. + */ +native TE_WriteVector(const String:prop[], Float:vector[3]); + +/** + * Sets a QAngle in the current temp entity. + * + * @param prop Property to use. + * @param angles Angles to set. + * @return True on success, otherwise false. + * @error Property not found. + */ +native TE_WriteAngles(const String:prop[], Float:angles[3]); + +/** + * Sends the current temp entity to one or more clients. + * + * @param clients Array containing player indexes to broadcast to. + * @param numClients Number of players in the array. + * @param delay Delay in seconds to send the TE. + * @noreturn + * @error Invalid client index or client not in game. + */ +native TE_Send(clients[], numClients, Float:delay=0.0); + +/** + * Sets an encoded entity index in the current temp entity. + * (This is usually used for m_nStartEntity and m_nEndEntity). + * + * @param prop Property to use. + * @param value Value to set. + * @noreturn + * @error Property not found. + */ +stock TE_WriteEncodedEnt(const String:prop[], value) +{ + new encvalue = (value & 0x0FFF) | ((1 & 0xF)<<12); + return TE_WriteNum(prop, encvalue); +} + +/** + * Broadcasts the current temp entity to all clients. + * @note See TE_Start(). + * + * @param delay Delay in seconds to send the TE. + * @noreturn + */ +stock TE_SendToAll(Float:delay=0.0) +{ + new maxClients = GetMaxClients(); + new total = 0; + new clients[maxClients]; + for (new i=1; i<=maxClients; i++) + { + if (IsClientInGame(i)) + { + clients[total++] = i; + } + } + return TE_Send(clients, total, delay); +} + +/** + * Sends the current TE to only a client. + * @note See TE_Start(). + * + * @param client Client to send to. + * @param delay Delay in seconds to send the TE. + * @noreturn + * @error Invalid client index or client not in game. + */ +stock TE_SendToOne(client, Float:delay=0.0) +{ + new players[1]; + + players[0] = client; + + return TE_Send(players, 1, delay); +}