added amb1418 - FIELD_STRING support for GetEntPropString()

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401890
This commit is contained in:
David Anderson 2008-02-22 16:51:15 +00:00
parent 67442ac4a0
commit 1f57da5aa0
2 changed files with 36 additions and 2 deletions

View File

@ -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;

View File

@ -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.