From 1f57da5aa0adecbd4e32d8c8ca6a21b9a4624660 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 22 Feb 2008 16:51:15 +0000 Subject: [PATCH] added amb1418 - FIELD_STRING support for GetEntPropString() --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401890 --- core/smn_entities.cpp | 30 ++++++++++++++++++++++++++++-- plugins/include/entity.inc | 8 ++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/core/smn_entities.cpp b/core/smn_entities.cpp index f8fe5ecf..cd3e4ea1 100644 --- a/core/smn_entities.cpp +++ b/core/smn_entities.cpp @@ -52,6 +52,7 @@ enum PropFieldType PropField_Entity, /**< Valid for Data fields only (SendProp shows as int) */ PropField_Vector, /**< Valid for SendProp and Data fields */ PropField_String, /**< Valid for SendProp and Data fields */ + PropField_String_T, /**< Valid for Data fields. Read only! */ }; inline edict_t *GetEdict(cell_t num) @@ -795,6 +796,12 @@ static cell_t FindDataMapOffs(IPluginContext *pContext, const cell_t *params) } break; } + case FIELD_STRING: + { + *pSize = sizeof(string_t); + *pType = PropField_String_T; + break; + } case FIELD_FLOAT: case FIELD_TIME: { @@ -1580,6 +1587,7 @@ static cell_t GetEntPropString(IPluginContext *pContext, const cell_t *params) int offset; const char *class_name; edict_t *pEdict; + bool bIsStringIndex; pEdict = GetEntity(params[1], &pEntity); @@ -1595,6 +1603,8 @@ static cell_t GetEntPropString(IPluginContext *pContext, const cell_t *params) pContext->LocalToString(params[3], &prop); + bIsStringIndex = false; + switch (params[2]) { case Prop_Data: @@ -1603,7 +1613,8 @@ static cell_t GetEntPropString(IPluginContext *pContext, const cell_t *params) FIND_PROP_DATA(td); - if (td->fieldType != FIELD_CHARACTER) + if (td->fieldType != FIELD_CHARACTER + && td->fieldType != FIELD_STRING) { return pContext->ThrowNativeError("Data field %s is not a string (%d != %d)", prop, @@ -1611,6 +1622,8 @@ static cell_t GetEntPropString(IPluginContext *pContext, const cell_t *params) FIELD_CHARACTER); } + bIsStringIndex = (td->fieldType == FIELD_STRING); + offset = td->fieldOffset[TD_OFFSET_NORMAL]; break; } @@ -1639,7 +1652,20 @@ static cell_t GetEntPropString(IPluginContext *pContext, const cell_t *params) } size_t len; - char *src = (char *)((uint8_t *)pEntity + offset); + const char *src; + + if (!bIsStringIndex) + { + src = (char *)((uint8_t *)pEntity + offset); + } + else + { + string_t idx; + + idx = *(string_t *)((uint8_t *)pEntity + offset); + src = (idx == NULL_STRING) ? "" : STRING(idx); + } + pContext->StringToLocalUTF8(params[4], params[5], src, &len); return len; diff --git a/plugins/include/entity.inc b/plugins/include/entity.inc index 79d90fc4..fefc76f5 100644 --- a/plugins/include/entity.inc +++ b/plugins/include/entity.inc @@ -67,6 +67,11 @@ enum PropFieldType PropField_Entity, /**< Valid for Data fields only (SendProp shows as int) */ PropField_Vector, /**< Valid for SendProp and Data fields */ PropField_String, /**< Valid for SendProp and Data fields */ + PropField_String_T, /**< Valid for Data fields. Read only. + Note that the size of a string_t is dynamic, and + thus FindDataMapOffs() will return the constant size + of the string_t container (which is 32 bits right now). + */ }; /** @@ -619,6 +624,9 @@ native GetEntPropString(entity, PropType:type, const String:prop[], String:buffe /** * Sets a network property as a string. + * + * This cannot set property fields of type PropField_String_T (such as "m_target"). + * To set such fields, you should use DispatchKeyValue() from SDKTools. * * @param entity Edict index. * @param type Property type.