3 * =============================================================================
5 * Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #include "sm_globals.h"
33 #include "sourcemod.h"
34 #include "sourcemm_api.h"
35 #include "PlayerManager.h"
36 #include "HalfLife2.h"
37 #include <IGameConfigs.h>
38 #include "sm_stringutil.h"
39 #include "logic_bridge.h"
41 // These values need to mirror the values in entity_prop_stocks
42 #define ENTFLAG_ONGROUND (1 << 0)
43 #define ENTFLAG_DUCKING (1 << 1)
44 #define ENTFLAG_WATERJUMP (1 << 2)
45 #define ENTFLAG_ONTRAIN (1 << 3)
46 #define ENTFLAG_INRAIN (1 << 4)
47 #define ENTFLAG_FROZEN (1 << 5)
48 #define ENTFLAG_ATCONTROLS (1 << 6)
49 #define ENTFLAG_CLIENT (1 << 7)
50 #define ENTFLAG_FAKECLIENT (1 << 8)
51 #define ENTFLAG_INWATER (1 << 9)
52 #define ENTFLAG_FLY (1 << 10)
53 #define ENTFLAG_SWIM (1 << 11)
54 #define ENTFLAG_CONVEYOR (1 << 12)
55 #define ENTFLAG_NPC (1 << 13)
56 #define ENTFLAG_GODMODE (1 << 14)
57 #define ENTFLAG_NOTARGET (1 << 15)
58 #define ENTFLAG_AIMTARGET (1 << 16)
59 #define ENTFLAG_PARTIALGROUND (1 << 17)
60 #define ENTFLAG_STATICPROP (1 << 18)
61 #define ENTFLAG_GRAPHED (1 << 19)
62 #define ENTFLAG_GRENADE (1 << 20)
63 #define ENTFLAG_STEPMOVEMENT (1 << 21)
64 #define ENTFLAG_DONTTOUCH (1 << 22)
65 #define ENTFLAG_BASEVELOCITY (1 << 23)
66 #define ENTFLAG_WORLDBRUSH (1 << 24)
67 #define ENTFLAG_OBJECT (1 << 25)
68 #define ENTFLAG_KILLME (1 << 26)
69 #define ENTFLAG_ONFIRE (1 << 27)
70 #define ENTFLAG_DISSOLVING (1 << 28)
71 #define ENTFLAG_TRANSRAGDOLL (1 << 29)
72 #define ENTFLAG_UNBLOCKABLE_BY_PLAYER (1 << 30)
73 #define ENTFLAG_FREEZING (1 << 31)
74 #define ENTFLAG_EP2V_UNKNOWN1 (1 << 31)
76 // Not defined in the sdk as we have no clue what it is
77 #define FL_EP2V_UNKNOWN (1 << 2)
87 PropField_Unsupported, /**< The type is unsupported. */
88 PropField_Integer, /**< Valid for SendProp and Data fields */
89 PropField_Float, /**< Valid for SendProp and Data fields */
90 PropField_Entity, /**< Valid for Data fields only (SendProp shows as int) */
91 PropField_Vector, /**< Valid for SendProp and Data fields */
92 PropField_String, /**< Valid for SendProp and Data fields */
93 PropField_String_T, /**< Valid for Data fields. Read only! */
96 inline edict_t *BaseEntityToEdict(CBaseEntity *pEntity)
98 IServerUnknown *pUnk = (IServerUnknown *)pEntity;
99 IServerNetworkable *pNet = pUnk->GetNetworkable();
106 return pNet->GetEdict();
109 inline edict_t *GetEdict(cell_t num)
112 if (!IndexToAThings(num, NULL, &pEdict))
120 inline CBaseEntity *GetEntity(cell_t num)
122 CBaseEntity *pEntity;
123 if (!IndexToAThings(num, &pEntity, NULL))
131 /* Given an entity reference or index, fill out a CBaseEntity and/or edict.
132 If lookup is successful, returns true and writes back the two parameters.
133 If lookup fails, returns false and doesn't touch the params. */
134 bool IndexToAThings(cell_t num, CBaseEntity **pEntData, edict_t **pEdictData)
136 CBaseEntity *pEntity = g_HL2.ReferenceToEntity(num);
143 int index = g_HL2.ReferenceToIndex(num);
144 if (index > 0 && index <= g_Players.GetMaxClients())
146 CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
147 if (!pPlayer || !pPlayer->IsConnected())
160 edict_t *pEdict = ::BaseEntityToEdict(pEntity);
161 if (!pEdict || pEdict->IsFree())
166 *pEdictData = pEdict;
172 <predcrab> AThings is like guaranteed r+ by dvander though
173 <predcrab> he wont even read the rest of the patch to nit stuff
174 <Fyren> Like I wasn't going to r? you anyway!
175 <predcrab> he still sees!
176 <predcrab> he's everywhere
179 class VEmptyClass {};
180 datamap_t *VGetDataDescMap(CBaseEntity *pThisPtr, int offset)
182 void **this_ptr = *reinterpret_cast<void ***>(&pThisPtr);
183 void **vtable = *reinterpret_cast<void ***>(pThisPtr);
184 void *vfunc = vtable[offset];
188 datamap_t *(VEmptyClass::*mfpnew)();
189 #ifndef PLATFORM_POSIX
204 return (datamap_t *)(reinterpret_cast<VEmptyClass *>(this_ptr)->*u.mfpnew)();
207 inline datamap_t *CBaseEntity_GetDataDescMap(CBaseEntity *pEntity)
211 if (!g_pGameConf->GetOffset("GetDataDescMap", &offset) || !offset)
216 return VGetDataDescMap(pEntity, offset);
219 /* :TODO: Move this! */
220 datamap_t *CHalfLife2::GetDataMap(CBaseEntity *pEntity)
222 return CBaseEntity_GetDataDescMap(pEntity);
225 static cell_t GetMaxEntities(IPluginContext *pContext, const cell_t *params)
227 return gpGlobals->maxEntities;
230 static cell_t CreateEdict(IPluginContext *pContext, const cell_t *params)
232 edict_t *pEdict = engine->CreateEdict();
239 return IndexOfEdict(pEdict);
242 static cell_t RemoveEdict(IPluginContext *pContext, const cell_t *params)
244 edict_t *pEdict = GetEdict(params[1]);
248 return pContext->ThrowNativeError("Edict %d (%d) is not a valid edict", g_HL2.ReferenceToIndex(params[1]), params[1]);
251 engine->RemoveEdict(pEdict);
256 static cell_t IsValidEdict(IPluginContext *pContext, const cell_t *params)
258 edict_t *pEdict = GetEdict(params[1]);
265 /* Shouldn't be necessary... not sure though */
266 return pEdict->IsFree() ? 0 : 1;
269 static cell_t IsValidEntity(IPluginContext *pContext, const cell_t *params)
271 CBaseEntity *pEntity = g_HL2.ReferenceToEntity(params[1]);
273 return (pEntity != NULL) ? 1 : 0;
276 static cell_t IsEntNetworkable(IPluginContext *pContext, const cell_t *params)
278 edict_t *pEdict = GetEdict(params[1]);
285 return (pEdict->GetNetworkable() != NULL) ? 1 : 0;
288 static cell_t GetEntityCount(IPluginContext *pContext, const cell_t *params)
290 return engine->GetEntityCount();
293 static cell_t GetEdictFlags(IPluginContext *pContext, const cell_t *params)
295 edict_t *pEdict = GetEdict(params[1]);
299 return pContext->ThrowNativeError("Invalid edict (%d - %d)", g_HL2.ReferenceToIndex(params[1]), params[1]);
302 return pEdict->m_fStateFlags;
305 static cell_t SetEdictFlags(IPluginContext *pContext, const cell_t *params)
307 edict_t *pEdict = GetEdict(params[1]);
311 return pContext->ThrowNativeError("Invalid edict (%d - %d)", g_HL2.ReferenceToIndex(params[1]), params[1]);
314 pEdict->m_fStateFlags = params[2];
319 static cell_t GetEdictClassname(IPluginContext *pContext, const cell_t *params)
321 edict_t *pEdict = GetEdict(params[1]);
325 return pContext->ThrowNativeError("Invalid edict (%d - %d)", g_HL2.ReferenceToIndex(params[1]), params[1]);
328 const char *cls = pEdict->GetClassName();
330 if (!cls || cls[0] == '\0')
335 pContext->StringToLocal(params[2], params[3], cls);
340 static cell_t GetEntityNetClass(IPluginContext *pContext, const cell_t *params)
342 CBaseEntity *pEntity = g_HL2.ReferenceToEntity(params[1]);
344 IServerUnknown *pUnk = (IServerUnknown *)pEntity;
348 return pContext->ThrowNativeError("Invalid entity (%d - %d)", g_HL2.ReferenceToIndex(params[1]), params[1]);
351 IServerNetworkable *pNet = pUnk->GetNetworkable();
357 ServerClass *pClass = pNet->GetServerClass();
359 pContext->StringToLocal(params[2], params[3], pClass->GetName());
364 static cell_t GetEntData(IPluginContext *pContext, const cell_t *params)
366 CBaseEntity *pEntity = GetEntity(params[1]);
370 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
373 int offset = params[2];
374 if (offset <= 0 || offset > 32768)
376 return pContext->ThrowNativeError("Offset %d is invalid", offset);
382 return *(int *)((uint8_t *)pEntity + offset);
384 return *(short *)((uint8_t *)pEntity + offset);
386 return *((uint8_t *)pEntity + offset);
388 return pContext->ThrowNativeError("Integer size %d is invalid", params[3]);
392 static cell_t SetEntData(IPluginContext *pContext, const cell_t *params)
394 CBaseEntity *pEntity;
397 if (!IndexToAThings(params[1], &pEntity, &pEdict))
399 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
402 int offset = params[2];
403 if (offset <= 0 || offset > 32768)
405 return pContext->ThrowNativeError("Offset %d is invalid", offset);
408 if (params[5] && (pEdict != NULL))
410 g_HL2.SetEdictStateChanged(pEdict, offset);
417 *(int *)((uint8_t *)pEntity + offset) = params[3];
422 *(short *)((uint8_t *)pEntity + offset) = params[3];
427 *((uint8_t *)pEntity + offset) = params[3];
431 return pContext->ThrowNativeError("Integer size %d is invalid", params[4]);
437 static cell_t GetEntDataFloat(IPluginContext *pContext, const cell_t *params)
439 CBaseEntity *pEntity = GetEntity(params[1]);
443 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
446 int offset = params[2];
447 if (offset <= 0 || offset > 32768)
449 return pContext->ThrowNativeError("Offset %d is invalid", offset);
452 float f = *(float *)((uint8_t *)pEntity + offset);
457 static cell_t SetEntDataFloat(IPluginContext *pContext, const cell_t *params)
459 CBaseEntity *pEntity;
462 if (!IndexToAThings(params[1], &pEntity, &pEdict))
464 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
467 int offset = params[2];
468 if (offset <= 0 || offset > 32768)
470 return pContext->ThrowNativeError("Offset %d is invalid", offset);
473 *(float *)((uint8_t *)pEntity + offset) = sp_ctof(params[3]);
475 if (params[4] && (pEdict != NULL))
477 g_HL2.SetEdictStateChanged(pEdict, offset);
483 static cell_t GetEntDataVector(IPluginContext *pContext, const cell_t *params)
485 CBaseEntity *pEntity = GetEntity(params[1]);
489 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
492 int offset = params[2];
493 if (offset <= 0 || offset > 32768)
495 return pContext->ThrowNativeError("Offset %d is invalid", offset);
498 Vector *v = (Vector *)((uint8_t *)pEntity + offset);
501 pContext->LocalToPhysAddr(params[3], &vec);
503 vec[0] = sp_ftoc(v->x);
504 vec[1] = sp_ftoc(v->y);
505 vec[2] = sp_ftoc(v->z);
510 static cell_t SetEntDataVector(IPluginContext *pContext, const cell_t *params)
512 CBaseEntity *pEntity;
515 if (!IndexToAThings(params[1], &pEntity, &pEdict))
517 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
520 int offset = params[2];
521 if (offset <= 0 || offset > 32768)
523 return pContext->ThrowNativeError("Offset %d is invalid", offset);
526 Vector *v = (Vector *)((uint8_t *)pEntity + offset);
529 pContext->LocalToPhysAddr(params[3], &vec);
531 v->x = sp_ctof(vec[0]);
532 v->y = sp_ctof(vec[1]);
533 v->z = sp_ctof(vec[2]);
535 if (params[4] && (pEdict != NULL))
537 g_HL2.SetEdictStateChanged(pEdict, offset);
543 /* THIS GUY IS DEPRECATED. */
544 static cell_t GetEntDataEnt(IPluginContext *pContext, const cell_t *params)
546 CBaseEntity *pEntity = GetEntity(params[1]);
550 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
553 int offset = params[2];
554 if (offset <= 0 || offset > 32768)
556 return pContext->ThrowNativeError("Offset %d is invalid", offset);
559 CBaseHandle &hndl = *(CBaseHandle *)((uint8_t *)pEntity + offset);
566 int ref = g_HL2.IndexToReference(hndl.GetEntryIndex());
567 return g_HL2.ReferenceToBCompatRef(ref);
570 int CheckBaseHandle(CBaseHandle &hndl)
577 int index = hndl.GetEntryIndex();
579 edict_t *pStoredEdict;
580 CBaseEntity *pStoredEntity;
582 if (!IndexToAThings(index, &pStoredEntity, &pStoredEdict))
587 if (pStoredEdict == NULL || pStoredEntity == NULL)
592 IServerEntity *pSE = pStoredEdict->GetIServerEntity();
599 if (pSE->GetRefEHandle() != hndl)
607 static cell_t GetEntDataEnt2(IPluginContext *pContext, const cell_t *params)
609 CBaseEntity *pEntity = GetEntity(params[1]);
613 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
616 int offset = params[2];
617 if (offset <= 0 || offset > 32768)
619 return pContext->ThrowNativeError("Offset %d is invalid", offset);
622 CBaseHandle &hndl = *(CBaseHandle *)((uint8_t *)pEntity + offset);
624 int ref = g_HL2.IndexToReference(hndl.GetEntryIndex());
625 return g_HL2.ReferenceToBCompatRef(ref);
628 /* THIS GUY IS DEPRECATED. */
629 static cell_t SetEntDataEnt(IPluginContext *pContext, const cell_t *params)
631 CBaseEntity *pEntity;
634 if (!IndexToAThings(params[1], &pEntity, &pEdict))
636 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
639 int offset = params[2];
640 if (offset <= 0 || offset > 32768)
642 return pContext->ThrowNativeError("Offset %d is invalid", offset);
645 CBaseHandle &hndl = *(CBaseHandle *)((uint8_t *)pEntity + offset);
647 if (params[3] == 0 || (unsigned)params[3] == INVALID_EHANDLE_INDEX)
651 CBaseEntity *pOther = GetEntity(params[3]);
655 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[3]), params[3]);
658 IHandleEntity *pHandleEnt = (IHandleEntity *)pOther;
659 hndl.Set(pHandleEnt);
662 if (params[4] && (pEdict != NULL))
664 g_HL2.SetEdictStateChanged(pEdict, offset);
670 static cell_t SetEntDataEnt2(IPluginContext *pContext, const cell_t *params)
672 CBaseEntity *pEntity;
675 if (!IndexToAThings(params[1], &pEntity, &pEdict))
677 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
680 int offset = params[2];
681 if (offset <= 0 || offset > 32768)
683 return pContext->ThrowNativeError("Offset %d is invalid", offset);
686 CBaseHandle &hndl = *(CBaseHandle *)((uint8_t *)pEntity + offset);
688 if ((unsigned)params[3] == INVALID_EHANDLE_INDEX)
694 CBaseEntity *pOther = GetEntity(params[3]);
698 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[3]), params[3]);
701 IHandleEntity *pHandleEnt = (IHandleEntity *)pOther;
702 hndl.Set(pHandleEnt);
705 if (params[4] && (pEdict != NULL))
707 g_HL2.SetEdictStateChanged(pEdict, offset);
713 static cell_t ChangeEdictState(IPluginContext *pContext, const cell_t *params)
715 edict_t *pEdict = GetEdict(params[1]);
719 return pContext->ThrowNativeError("Edict %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
722 g_HL2.SetEdictStateChanged(pEdict, params[2]);
727 static cell_t FindSendPropOffs(IPluginContext *pContext, const cell_t *params)
730 pContext->LocalToString(params[1], &cls);
731 pContext->LocalToString(params[2], &prop);
733 SendProp *pSend = g_HL2.FindInSendTable(cls, prop);
740 return pSend->GetOffset();
743 static cell_t FindSendPropInfo(IPluginContext *pContext, const cell_t *params)
746 sm_sendprop_info_t info;
747 cell_t *pType, *pBits, *pLocal;
749 pContext->LocalToString(params[1], &cls);
750 pContext->LocalToString(params[2], &prop);
752 if (!g_HL2.FindSendPropInfo(cls, prop, &info))
757 pContext->LocalToPhysAddr(params[3], &pType);
758 pContext->LocalToPhysAddr(params[4], &pBits);
759 pContext->LocalToPhysAddr(params[5], &pLocal);
761 switch (info.prop->GetType())
765 *pType = PropField_Integer;
770 *pType = PropField_Float;
775 *pType = PropField_String;
780 *pType = PropField_Vector;
785 *pType = PropField_Unsupported;
790 *pBits = info.prop->m_nBits;
791 *pLocal = info.prop->GetOffset();
793 return info.actual_offset;
796 static cell_t FindDataMapOffs(IPluginContext *pContext, const cell_t *params)
798 CBaseEntity *pEntity;
800 typedescription_t *td;
802 pEntity = GetEntity(params[1]);
806 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
809 if ((pMap=CBaseEntity_GetDataDescMap(pEntity)) == NULL)
811 return pContext->ThrowNativeError("Unable to retrieve GetDataDescMap offset");
814 pContext->LocalToString(params[2], &offset);
815 if ((td=g_HL2.FindInDataMap(pMap, offset)) == NULL)
822 cell_t *pType, *pSize;
824 pContext->LocalToPhysAddr(params[3], &pType);
825 pContext->LocalToPhysAddr(params[4], &pSize);
827 switch (td->fieldType)
830 case FIELD_MODELINDEX:
831 case FIELD_MATERIALINDEX:
835 *pType = PropField_Integer;
840 case FIELD_POSITION_VECTOR:
842 *pType = PropField_Vector;
848 *pType = PropField_Integer;
854 *pType = PropField_Integer;
858 case FIELD_CHARACTER:
860 if (td->fieldSize == 1)
862 *pType = PropField_Integer;
867 *pType = PropField_String;
868 *pSize = 8 * td->fieldSize;
872 case FIELD_MODELNAME:
873 case FIELD_SOUNDNAME:
876 *pSize = sizeof(string_t);
877 *pType = PropField_String_T;
883 *pType = PropField_Float;
889 *pType = PropField_Entity;
895 *pType = PropField_Unsupported;
901 return GetTypeDescOffs(td);
904 static cell_t GetEntDataString(IPluginContext *pContext, const cell_t *params)
906 CBaseEntity *pEntity = GetEntity(params[1]);
910 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
913 int offset = params[2];
914 if (offset < 0 || offset > 32768)
916 return pContext->ThrowNativeError("Offset %d is invalid", offset);
920 char *src = (char *)((uint8_t *)pEntity + offset);
921 pContext->StringToLocalUTF8(params[3], params[4], src, &len);
926 static cell_t SetEntDataString(IPluginContext *pContext, const cell_t *params)
928 CBaseEntity *pEntity;
931 if (!IndexToAThings(params[1], &pEntity, &pEdict))
933 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
936 int offset = params[2];
937 if (offset < 0 || offset > 32768)
939 return pContext->ThrowNativeError("Offset %d is invalid", offset);
943 char *dest = (char *)((uint8_t *)pEntity + offset);
945 pContext->LocalToString(params[3], &src);
946 size_t len = strncopy(dest, src, params[4]);
948 if (params[5] && (pEdict != NULL))
950 g_HL2.SetEdictStateChanged(pEdict, offset);
956 #define FIND_PROP_DATA(td) \
958 if ((pMap = CBaseEntity_GetDataDescMap(pEntity)) == NULL) \
960 return pContext->ThrowNativeError("Could not retrieve datamap"); \
962 if ((td = g_HL2.FindInDataMap(pMap, prop)) == NULL) \
964 return pContext->ThrowNativeError("Property \"%s\" not found (entity %d/%s)", \
970 #define CHECK_SET_PROP_DATA_OFFSET() \
971 if (element < 0 || element >= td->fieldSize) \
973 return pContext->ThrowNativeError("Element %d is out of bounds (Prop %s has %d elements).", \
979 offset = GetTypeDescOffs(td) + (element * (td->fieldSizeInBytes / td->fieldSize));
981 #define FIND_PROP_SEND(type, type_name) \
982 sm_sendprop_info_t info;\
983 IServerUnknown *pUnk = (IServerUnknown *)pEntity; \
984 IServerNetworkable *pNet = pUnk->GetNetworkable(); \
987 return pContext->ThrowNativeError("Edict %d (%d) is not networkable", g_HL2.ReferenceToIndex(params[1]), params[1]); \
989 if (!g_HL2.FindSendPropInfo(pNet->GetServerClass()->GetName(), prop, &info)) \
991 return pContext->ThrowNativeError("Property \"%s\" not found (entity %d/%s)", \
997 offset = info.actual_offset; \
998 bit_count = info.prop->m_nBits; \
1000 switch (info.prop->GetType()) \
1006 return pContext->ThrowNativeError("SendProp %s is not an array. Element %d is invalid.", \
1012 case DPT_DataTable: \
1015 FIND_PROP_SEND_IN_SENDTABLE(info, pProp, element, type, type_name); \
1017 offset += pProp->GetOffset(); \
1018 bit_count = pProp->m_nBits; \
1023 return pContext->ThrowNativeError("SendProp %s type is not " type_name " (%d != %d)", \
1025 info.prop->GetType(), \
1030 #define FIND_PROP_SEND_IN_SENDTABLE(info, pProp, element, type, type_name) \
1031 SendTable *pTable = info.prop->GetDataTable(); \
1034 return pContext->ThrowNativeError("Error looking up DataTable for prop %s", \
1038 int elementCount = pTable->GetNumProps(); \
1039 if (element < 0 || element >= elementCount) \
1041 return pContext->ThrowNativeError("Element %d is out of bounds (Prop %s has %d elements).", \
1047 pProp = pTable->GetProp(element); \
1048 if (pProp->GetType() != type) \
1050 return pContext->ThrowNativeError("SendProp %s type is not " type_name " ([%d,%d] != %d)", \
1052 info.prop->GetType(), \
1053 info.prop->m_nBits, \
1058 inline int MatchFieldAsInteger(int field_type)
1063 case FIELD_MODELINDEX:
1064 case FIELD_MATERIALINDEX:
1070 case FIELD_CHARACTER:
1081 static cell_t GetEntPropArraySize(IPluginContext *pContext, const cell_t *params)
1083 CBaseEntity *pEntity;
1085 const char *class_name;
1088 if (!IndexToAThings(params[1], &pEntity, &pEdict))
1090 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
1093 if (!pEdict || (class_name = pEdict->GetClassName()) == NULL)
1098 pContext->LocalToString(params[3], &prop);
1104 typedescription_t *td;
1108 return td->fieldSize;
1112 sm_sendprop_info_t info;
1114 IServerUnknown *pUnk = (IServerUnknown *)pEntity;
1115 IServerNetworkable *pNet = pUnk->GetNetworkable();
1118 return pContext->ThrowNativeError("Edict %d (%d) is not networkable", g_HL2.ReferenceToIndex(params[1]), params[1]);
1120 if (!g_HL2.FindSendPropInfo(pNet->GetServerClass()->GetName(), prop, &info))
1122 return pContext->ThrowNativeError("Property \"%s\" not found (entity %d/%s)",
1128 if (info.prop->GetType() != DPT_DataTable)
1133 SendTable *pTable = info.prop->GetDataTable();
1136 return pContext->ThrowNativeError("Error looking up DataTable for prop %s", prop);
1139 return pTable->GetNumProps();
1143 return pContext->ThrowNativeError("Invalid Property type %d", params[2]);
1150 static cell_t GetEntProp(IPluginContext *pContext, const cell_t *params)
1152 CBaseEntity *pEntity;
1155 const char *class_name;
1158 bool is_unsigned = false;
1163 element = params[5];
1166 if (!IndexToAThings(params[1], &pEntity, &pEdict))
1168 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
1171 /* TODO: Find a way to lookup classname without having an edict - Is this a guaranteed prop? */
1172 if (!pEdict || (class_name = pEdict->GetClassName()) == NULL)
1177 pContext->LocalToString(params[3], &prop);
1183 typedescription_t *td;
1187 if ((bit_count = MatchFieldAsInteger(td->fieldType)) == 0)
1189 return pContext->ThrowNativeError("Data field %s is not an integer (%d)",
1194 CHECK_SET_PROP_DATA_OFFSET();
1200 FIND_PROP_SEND(DPT_Int, "integer");
1201 is_unsigned = ((info.prop->GetFlags() & SPROP_UNSIGNED) == SPROP_UNSIGNED);
1206 return pContext->ThrowNativeError("Invalid Property type %d", params[2]);
1212 bit_count = params[4] * 8;
1215 if (bit_count >= 17)
1217 return *(int32_t *)((uint8_t *)pEntity + offset);
1219 else if (bit_count >= 9)
1223 return *(uint16_t *)((uint8_t *)pEntity + offset);
1227 return *(int16_t *)((uint8_t *)pEntity + offset);
1230 else if (bit_count >= 2)
1234 return *(uint8_t *)((uint8_t *)pEntity + offset);
1238 return *(int8_t *)((uint8_t *)pEntity + offset);
1243 return *(bool *)((uint8_t *)pEntity + offset) ? 1 : 0;
1249 static cell_t SetEntProp(IPluginContext *pContext, const cell_t *params)
1251 CBaseEntity *pEntity;
1254 const char *class_name;
1261 element = params[6];
1264 if (!IndexToAThings(params[1], &pEntity, &pEdict))
1266 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
1269 if (!pEdict || (class_name = pEdict->GetClassName()) == NULL)
1274 pContext->LocalToString(params[3], &prop);
1280 typedescription_t *td;
1284 if ((bit_count = MatchFieldAsInteger(td->fieldType)) == 0)
1286 return pContext->ThrowNativeError("Data field %s is not an integer (%d)",
1291 CHECK_SET_PROP_DATA_OFFSET();
1297 FIND_PROP_SEND(DPT_Int, "integer");
1302 return pContext->ThrowNativeError("Invalid Property type %d", params[2]);
1308 bit_count = params[5] * 8;
1311 if (bit_count >= 17)
1313 *(int32_t *)((uint8_t *)pEntity + offset) = params[4];
1315 else if (bit_count >= 9)
1317 *(int16_t *)((uint8_t *)pEntity + offset) = (int16_t)params[4];
1319 else if (bit_count >= 2)
1321 *(int8_t *)((uint8_t *)pEntity + offset) = (int8_t)params[4];
1325 *(bool *)((uint8_t *)pEntity + offset) = params[4] ? true : false;
1328 if (params[2] == Prop_Send && (pEdict != NULL))
1330 g_HL2.SetEdictStateChanged(pEdict, offset);
1336 static cell_t GetEntPropFloat(IPluginContext *pContext, const cell_t *params)
1338 CBaseEntity *pEntity;
1342 const char *class_name;
1348 element = params[4];
1351 if (!IndexToAThings(params[1], &pEntity, &pEdict))
1353 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
1356 if (!pEdict || (class_name = pEdict->GetClassName()) == NULL)
1361 pContext->LocalToString(params[3], &prop);
1367 typedescription_t *td;
1371 if (td->fieldType != FIELD_FLOAT
1372 && td->fieldType != FIELD_TIME)
1374 return pContext->ThrowNativeError("Data field %s is not a float (%d != [%d,%d])",
1381 CHECK_SET_PROP_DATA_OFFSET();
1387 FIND_PROP_SEND(DPT_Float, "float");
1392 return pContext->ThrowNativeError("Invalid Property type %d", params[2]);
1396 float val = *(float *)((uint8_t *)pEntity + offset);
1398 return sp_ftoc(val);
1401 static cell_t SetEntPropFloat(IPluginContext *pContext, const cell_t *params)
1403 CBaseEntity *pEntity;
1407 const char *class_name;
1413 element = params[5];
1416 if (!IndexToAThings(params[1], &pEntity, &pEdict))
1418 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
1421 if (!pEdict || (class_name = pEdict->GetClassName()) == NULL)
1426 pContext->LocalToString(params[3], &prop);
1432 typedescription_t *td;
1436 if (td->fieldType != FIELD_FLOAT
1437 && td->fieldType != FIELD_TIME)
1439 return pContext->ThrowNativeError("Data field %s is not a float (%d != [%d,%d])",
1446 CHECK_SET_PROP_DATA_OFFSET();
1452 FIND_PROP_SEND(DPT_Float, "float");
1457 return pContext->ThrowNativeError("Invalid Property type %d", params[2]);
1461 *(float *)((uint8_t *)pEntity + offset) = sp_ctof(params[4]);
1463 if (params[2] == Prop_Send && (pEdict != NULL))
1465 g_HL2.SetEdictStateChanged(pEdict, offset);
1471 static cell_t GetEntPropEnt(IPluginContext *pContext, const cell_t *params)
1473 CBaseEntity *pEntity;
1477 const char *class_name;
1483 element = params[4];
1486 if (!IndexToAThings(params[1], &pEntity, &pEdict))
1488 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
1491 if (!pEdict || (class_name = pEdict->GetClassName()) == NULL)
1496 pContext->LocalToString(params[3], &prop);
1502 typedescription_t *td;
1506 if (td->fieldType != FIELD_EHANDLE)
1508 return pContext->ThrowNativeError("Data field %s is not an entity (%d != %d)",
1514 CHECK_SET_PROP_DATA_OFFSET();
1520 FIND_PROP_SEND(DPT_Int, "integer");
1525 return pContext->ThrowNativeError("Invalid Property type %d", params[2]);
1529 CBaseHandle &hndl = *(CBaseHandle *)((uint8_t *)pEntity + offset);
1531 int ref = g_HL2.IndexToReference(hndl.GetEntryIndex());
1532 return g_HL2.ReferenceToBCompatRef(ref);
1535 static cell_t SetEntPropEnt(IPluginContext *pContext, const cell_t *params)
1537 CBaseEntity *pEntity;
1541 const char *class_name;
1547 element = params[5];
1550 if (!IndexToAThings(params[1], &pEntity, &pEdict))
1552 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
1555 if (!pEdict || (class_name = pEdict->GetClassName()) == NULL)
1560 pContext->LocalToString(params[3], &prop);
1566 typedescription_t *td;
1570 if (td->fieldType != FIELD_EHANDLE)
1572 return pContext->ThrowNativeError("Data field %s is not an entity (%d != %d)",
1578 CHECK_SET_PROP_DATA_OFFSET();
1584 FIND_PROP_SEND(DPT_Int, "integer");
1589 return pContext->ThrowNativeError("Invalid Property type %d", params[2]);
1593 CBaseHandle &hndl = *(CBaseHandle *)((uint8_t *)pEntity + offset);
1595 if (params[4] == -1)
1601 CBaseEntity *pOther = GetEntity(params[4]);
1605 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[4]), params[4]);
1608 IHandleEntity *pHandleEnt = (IHandleEntity *)pOther;
1609 hndl.Set(pHandleEnt);
1612 if (params[2] == Prop_Send && (pEdict != NULL))
1614 g_HL2.SetEdictStateChanged(pEdict, offset);
1620 static cell_t GetEntPropVector(IPluginContext *pContext, const cell_t *params)
1622 CBaseEntity *pEntity;
1626 const char *class_name;
1632 element = params[5];
1635 if (!IndexToAThings(params[1], &pEntity, &pEdict))
1637 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
1640 if (!pEdict || (class_name = pEdict->GetClassName()) == NULL)
1645 pContext->LocalToString(params[3], &prop);
1651 typedescription_t *td;
1655 if (td->fieldType != FIELD_VECTOR
1656 && td->fieldType != FIELD_POSITION_VECTOR)
1658 return pContext->ThrowNativeError("Data field %s is not a vector (%d != [%d,%d])",
1662 FIELD_POSITION_VECTOR);
1665 CHECK_SET_PROP_DATA_OFFSET();
1671 FIND_PROP_SEND(DPT_Vector, "vector");
1676 return pContext->ThrowNativeError("Invalid Property type %d", params[2]);
1680 Vector *v = (Vector *)((uint8_t *)pEntity + offset);
1683 pContext->LocalToPhysAddr(params[4], &vec);
1685 vec[0] = sp_ftoc(v->x);
1686 vec[1] = sp_ftoc(v->y);
1687 vec[2] = sp_ftoc(v->z);
1692 static cell_t SetEntPropVector(IPluginContext *pContext, const cell_t *params)
1694 CBaseEntity *pEntity;
1698 const char *class_name;
1704 element = params[5];
1707 if (!IndexToAThings(params[1], &pEntity, &pEdict))
1709 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
1712 if (!pEdict || (class_name = pEdict->GetClassName()) == NULL)
1717 pContext->LocalToString(params[3], &prop);
1723 typedescription_t *td;
1727 if (td->fieldType != FIELD_VECTOR
1728 && td->fieldType != FIELD_POSITION_VECTOR)
1730 return pContext->ThrowNativeError("Data field %s is not a vector (%d != [%d,%d])",
1734 FIELD_POSITION_VECTOR);
1737 CHECK_SET_PROP_DATA_OFFSET();
1743 FIND_PROP_SEND(DPT_Vector, "vector");
1748 return pContext->ThrowNativeError("Invalid Property type %d", params[2]);
1752 Vector *v = (Vector *)((uint8_t *)pEntity + offset);
1755 pContext->LocalToPhysAddr(params[4], &vec);
1757 v->x = sp_ctof(vec[0]);
1758 v->y = sp_ctof(vec[1]);
1759 v->z = sp_ctof(vec[2]);
1761 if (params[2] == Prop_Send && (pEdict != NULL))
1763 g_HL2.SetEdictStateChanged(pEdict, offset);
1769 static cell_t GetEntPropString(IPluginContext *pContext, const cell_t *params)
1771 CBaseEntity *pEntity;
1774 const char *class_name;
1776 bool bIsStringIndex;
1781 element = params[6];
1784 if (!IndexToAThings(params[1], &pEntity, &pEdict))
1786 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
1789 if (!pEdict || (class_name = pEdict->GetClassName()) == NULL)
1794 pContext->LocalToString(params[3], &prop);
1796 bIsStringIndex = false;
1802 typedescription_t *td;
1806 if (td->fieldType != FIELD_CHARACTER
1807 && td->fieldType != FIELD_STRING
1808 && td->fieldType != FIELD_MODELNAME
1809 && td->fieldType != FIELD_SOUNDNAME)
1811 return pContext->ThrowNativeError("Data field %s is not a string (%d != %d)",
1817 bIsStringIndex = (td->fieldType != FIELD_CHARACTER);
1819 if (bIsStringIndex && (element < 0 || element >= td->fieldSize))
1821 return pContext->ThrowNativeError("Element %d is out of bounds (Prop %s has %d elements).",
1826 else if (element != 0)
1828 return pContext->ThrowNativeError("Prop %s is not an array. Element %d is invalid.",
1833 offset = GetTypeDescOffs(td);
1836 offset += (element * (td->fieldSizeInBytes / td->fieldSize));
1842 sm_sendprop_info_t info;
1844 IServerUnknown *pUnk = (IServerUnknown *)pEntity;
1845 IServerNetworkable *pNet = pUnk->GetNetworkable();
1848 return pContext->ThrowNativeError("Edict %d (%d) is not networkable", g_HL2.ReferenceToIndex(params[1]), params[1]);
1850 if (!g_HL2.FindSendPropInfo(pNet->GetServerClass()->GetName(), prop, &info))
1852 return pContext->ThrowNativeError("Property \"%s\" not found (entity %d/%s)",
1858 offset = info.actual_offset;
1860 if (info.prop->GetType() != DPT_String)
1862 return pContext->ThrowNativeError("SendProp %s is not a string (%d != %d)",
1864 info.prop->GetType(),
1867 else if (element != 0)
1869 return pContext->ThrowNativeError("SendProp %s is not an array. Element %d is invalid.",
1878 return pContext->ThrowNativeError("Invalid Property type %d", params[2]);
1885 if (!bIsStringIndex)
1887 src = (char *)((uint8_t *)pEntity + offset);
1893 idx = *(string_t *)((uint8_t *)pEntity + offset);
1894 src = (idx == NULL_STRING) ? "" : STRING(idx);
1897 pContext->StringToLocalUTF8(params[4], params[5], src, &len);
1902 static cell_t SetEntPropString(IPluginContext *pContext, const cell_t *params)
1904 CBaseEntity *pEntity;
1910 if (!IndexToAThings(params[1], &pEntity, &pEdict))
1912 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
1920 typedescription_t *td;
1921 if ((pMap=CBaseEntity_GetDataDescMap(pEntity)) == NULL)
1923 return pContext->ThrowNativeError("Unable to retrieve GetDataDescMap offset");
1925 pContext->LocalToString(params[3], &prop);
1926 if ((td=g_HL2.FindInDataMap(pMap, prop)) == NULL)
1928 return pContext->ThrowNativeError("Property \"%s\" not found for entity %d", prop, params[1]);
1930 if (td->fieldType != FIELD_CHARACTER)
1932 return pContext->ThrowNativeError("Property \"%s\" is not a valid string", prop);
1934 offset = GetTypeDescOffs(td);
1935 maxlen = td->fieldSize;
1941 IServerUnknown *pUnk = (IServerUnknown *)pEntity;
1942 IServerNetworkable *pNet = pUnk->GetNetworkable();
1945 return pContext->ThrowNativeError("The edict is not networkable");
1947 pContext->LocalToString(params[3], &prop);
1948 SendProp *pSend = g_HL2.FindInSendTable(pNet->GetServerClass()->GetName(), prop);
1951 return pContext->ThrowNativeError("Property \"%s\" not found for entity %d", prop, params[1]);
1953 if (pSend->GetType() != DPT_String)
1955 return pContext->ThrowNativeError("Property \"%s\" is not a valid string", prop);
1957 offset = pSend->GetOffset();
1958 maxlen = DT_MAX_STRING_BUFFERSIZE;
1963 return pContext->ThrowNativeError("Invalid Property type %d", params[2]);
1968 char *dest = (char *)((uint8_t *)pEntity + offset);
1970 pContext->LocalToString(params[4], &src);
1971 size_t len = strncopy(dest, src, maxlen);
1973 if (params[2] == Prop_Send && (pEdict != NULL))
1975 g_HL2.SetEdictStateChanged(pEdict, offset);
1981 static int32_t SDKEntFlagToSMEntFlag(int flag)
1986 return ENTFLAG_ONGROUND;
1988 return ENTFLAG_DUCKING;
1990 return ENTFLAG_WATERJUMP;
1992 return ENTFLAG_ONTRAIN;
1994 return ENTFLAG_INRAIN;
1996 return ENTFLAG_FROZEN;
1998 return ENTFLAG_ATCONTROLS;
2000 return ENTFLAG_CLIENT;
2002 return ENTFLAG_FAKECLIENT;
2004 return ENTFLAG_INWATER;
2008 return ENTFLAG_SWIM;
2010 return ENTFLAG_CONVEYOR;
2014 return ENTFLAG_GODMODE;
2016 return ENTFLAG_NOTARGET;
2018 return ENTFLAG_AIMTARGET;
2019 case FL_PARTIALGROUND:
2020 return ENTFLAG_PARTIALGROUND;
2022 return ENTFLAG_STATICPROP;
2024 return ENTFLAG_GRAPHED;
2026 return ENTFLAG_GRENADE;
2027 case FL_STEPMOVEMENT:
2028 return ENTFLAG_STEPMOVEMENT;
2030 return ENTFLAG_DONTTOUCH;
2031 case FL_BASEVELOCITY:
2032 return ENTFLAG_BASEVELOCITY;
2034 return ENTFLAG_WORLDBRUSH;
2036 return ENTFLAG_OBJECT;
2038 return ENTFLAG_KILLME;
2040 return ENTFLAG_ONFIRE;
2042 return ENTFLAG_DISSOLVING;
2043 case FL_TRANSRAGDOLL:
2044 return ENTFLAG_TRANSRAGDOLL;
2045 case FL_UNBLOCKABLE_BY_PLAYER:
2046 return ENTFLAG_UNBLOCKABLE_BY_PLAYER;
2047 #if SOURCE_ENGINE == SE_ALIENSWARM
2049 return ENTFLAG_FREEZING;
2050 #elif SOURCE_ENGINE == SE_ORANGEBOXVALVE
2051 case FL_EP2V_UNKNOWN:
2052 return ENTFLAG_EP2V_UNKNOWN1;
2059 static int32_t SMEntFlagToSDKEntFlag(int32_t flag)
2063 case ENTFLAG_ONGROUND:
2065 case ENTFLAG_DUCKING:
2067 case ENTFLAG_WATERJUMP:
2068 return FL_WATERJUMP;
2069 case ENTFLAG_ONTRAIN:
2071 case ENTFLAG_INRAIN:
2073 case ENTFLAG_FROZEN:
2075 case ENTFLAG_ATCONTROLS:
2076 return FL_ATCONTROLS;
2077 case ENTFLAG_CLIENT:
2079 case ENTFLAG_FAKECLIENT:
2080 return FL_FAKECLIENT;
2081 case ENTFLAG_INWATER:
2087 case ENTFLAG_CONVEYOR:
2091 case ENTFLAG_GODMODE:
2093 case ENTFLAG_NOTARGET:
2095 case ENTFLAG_AIMTARGET:
2096 return FL_AIMTARGET;
2097 case ENTFLAG_PARTIALGROUND:
2098 return FL_PARTIALGROUND;
2099 case ENTFLAG_STATICPROP:
2100 return FL_STATICPROP;
2101 case ENTFLAG_GRAPHED:
2103 case ENTFLAG_GRENADE:
2105 case ENTFLAG_STEPMOVEMENT:
2106 return FL_STEPMOVEMENT;
2107 case ENTFLAG_DONTTOUCH:
2108 return FL_DONTTOUCH;
2109 case ENTFLAG_BASEVELOCITY:
2110 return FL_BASEVELOCITY;
2111 case ENTFLAG_WORLDBRUSH:
2112 return FL_WORLDBRUSH;
2113 case ENTFLAG_OBJECT:
2115 case ENTFLAG_KILLME:
2117 case ENTFLAG_ONFIRE:
2119 case ENTFLAG_DISSOLVING:
2120 return FL_DISSOLVING;
2121 case ENTFLAG_TRANSRAGDOLL:
2122 return FL_TRANSRAGDOLL;
2123 case ENTFLAG_UNBLOCKABLE_BY_PLAYER:
2124 return FL_UNBLOCKABLE_BY_PLAYER;
2125 #if SOURCE_ENGINE == SE_ALIENSWARM
2126 case ENTFLAG_FREEZING:
2128 #elif SOURCE_ENGINE == SE_ORANGEBOXVALVE
2129 case ENTFLAG_EP2V_UNKNOWN1:
2130 return FL_EP2V_UNKNOWN;
2137 static cell_t GetEntityFlags(IPluginContext *pContext, const cell_t *params)
2139 CBaseEntity *pEntity = g_HL2.ReferenceToEntity(params[1]);
2142 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
2145 const char *prop = g_pGameConf->GetKeyValue("m_fFlags");
2148 return pContext->ThrowNativeError("Could not find m_fFlags prop in gamedata");
2151 typedescription_t *td;
2154 if ((pMap = CBaseEntity_GetDataDescMap(pEntity)) == NULL)
2156 return pContext->ThrowNativeError("Could not retrieve datamap");
2158 if ((td = g_HL2.FindInDataMap(pMap, prop)) == NULL)
2160 return pContext->ThrowNativeError("Property \"%s\" not found (entity %d)",
2165 int offset = GetTypeDescOffs(td);
2167 int32_t actual_flags = *(int32_t *)((uint8_t *)pEntity + offset);
2168 int32_t sm_flags = 0;
2170 for (int32_t i = 0; i < 32; i++)
2172 int32_t flag = (1<<i);
2173 if ((actual_flags & flag) == flag)
2175 sm_flags |= SDKEntFlagToSMEntFlag(flag);
2182 static cell_t SetEntityFlags(IPluginContext *pContext, const cell_t *params)
2184 CBaseEntity *pEntity = g_HL2.ReferenceToEntity(params[1]);
2187 return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
2190 const char *prop = g_pGameConf->GetKeyValue("m_fFlags");
2193 return pContext->ThrowNativeError("Could not find m_fFlags prop in gamedata");
2196 typedescription_t *td;
2199 if ((pMap = CBaseEntity_GetDataDescMap(pEntity)) == NULL)
2201 return pContext->ThrowNativeError("Could not retrieve datamap");
2203 if ((td = g_HL2.FindInDataMap(pMap, prop)) == NULL)
2205 return pContext->ThrowNativeError("Property \"%s\" not found (entity %d)",
2210 int offset = GetTypeDescOffs(td);
2212 int32_t sm_flags = params[2];
2213 int32_t actual_flags = 0;
2215 for (int32_t i = 0; i < 32; i++)
2217 int32_t flag = (1<<i);
2218 if ((sm_flags & flag) == flag)
2220 actual_flags |= SMEntFlagToSDKEntFlag(flag);
2224 *(int32_t *)((uint8_t *)pEntity + offset) = actual_flags;
2229 REGISTER_NATIVES(entityNatives)
2231 {"ChangeEdictState", ChangeEdictState},
2232 {"CreateEdict", CreateEdict},
2233 {"FindDataMapOffs", FindDataMapOffs},
2234 {"FindSendPropInfo", FindSendPropInfo},
2235 {"FindSendPropOffs", FindSendPropOffs},
2236 {"GetEdictClassname", GetEdictClassname},
2237 {"GetEdictFlags", GetEdictFlags},
2238 {"GetEntData", GetEntData},
2239 {"GetEntDataEnt", GetEntDataEnt}, /** DEPRECATED */
2240 {"GetEntDataEnt2", GetEntDataEnt2},
2241 {"GetEntDataFloat", GetEntDataFloat},
2242 {"GetEntDataString", GetEntDataString},
2243 {"GetEntDataVector", GetEntDataVector},
2244 {"GetEntProp", GetEntProp},
2245 {"GetEntPropArraySize", GetEntPropArraySize},
2246 {"GetEntPropEnt", GetEntPropEnt},
2247 {"GetEntPropFloat", GetEntPropFloat},
2248 {"GetEntPropString", GetEntPropString},
2249 {"GetEntPropVector", GetEntPropVector},
2250 {"GetEntityCount", GetEntityCount},
2251 {"GetEntityFlags", GetEntityFlags},
2252 {"GetEntityNetClass", GetEntityNetClass},
2253 {"GetMaxEntities", GetMaxEntities},
2254 {"IsEntNetworkable", IsEntNetworkable},
2255 {"IsValidEdict", IsValidEdict},
2256 {"IsValidEntity", IsValidEntity},
2257 {"RemoveEdict", RemoveEdict},
2258 {"SetEdictFlags", SetEdictFlags},
2259 {"SetEntData", SetEntData},
2260 {"SetEntDataEnt", SetEntDataEnt}, /** DEPRECATED */
2261 {"SetEntDataEnt2", SetEntDataEnt2},
2262 {"SetEntDataFloat", SetEntDataFloat},
2263 {"SetEntDataVector", SetEntDataVector},
2264 {"SetEntDataString", SetEntDataString},
2265 {"SetEntityFlags", SetEntityFlags},
2266 {"SetEntProp", SetEntProp},
2267 {"SetEntPropEnt", SetEntPropEnt},
2268 {"SetEntPropFloat", SetEntPropFloat},
2269 {"SetEntPropString", SetEntPropString},
2270 {"SetEntPropVector", SetEntPropVector},