static cell_t SetEntProp(IPluginContext *pContext, const cell_t *params)
{
CBaseEntity *pEntity;
char *prop;
int offset;
edict_t *pEdict;
int bit_count;
int element = 0;
if (params[0] >= 6)
{
element = params[6];
}
if (!IndexToAThings(params[1], &pEntity, &pEdict))
{
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
}
pContext->LocalToString(params[3], &prop);
switch (params[2])
{
case Prop_Data:
{
typedescription_t *td;
FIND_PROP_DATA(td);
if ((bit_count = MatchTypeDescAsInteger(td->fieldType, td->flags)) == 0)
{
return pContext->ThrowNativeError("Data field %s is not an integer (%d)",
prop,
td->fieldType);
}
CHECK_SET_PROP_DATA_OFFSET();
if (td->fieldType == FIELD_CUSTOM && (td->flags & FTYPEDESC_OUTPUT) == FTYPEDESC_OUTPUT)
{
auto *pVariant = (variant_t *)((intptr_t)pEntity + offset);
// These are the only three int-ish types that variants support. If set to valid one that isn't
// (32-bit) integer, leave it alone. It's probably the intended type.
if (pVariant->fieldType != FIELD_COLOR32 && pVariant->fieldType != FIELD_BOOLEAN)
{
pVariant->fieldType = FIELD_INTEGER;
}
bit_count = MatchTypeDescAsInteger(pVariant->fieldType, 0);
}
SET_TYPE_IF_VARIANT(FIELD_INTEGER);
break;
}
case Prop_Send:
{
FIND_PROP_SEND(DPT_Int, "integer");
if (!CanSetPropName(prop))
{
return pContext->ThrowNativeError("Cannot set %s with \"FollowCSGOServerGuidelines\" option enabled.", prop);
}
// This isn't in CS:S yet, but will be, doesn't hurt to add now, and will save us a build later
#if SOURCE_ENGINE == SE_CSS || SOURCE_ENGINE == SE_HL2DM || SOURCE_ENGINE == SE_DODS \
|| SOURCE_ENGINE == SE_BMS || SOURCE_ENGINE == SE_SDK2013 || SOURCE_ENGINE == SE_TF2 \
|| SOURCE_ENGINE == SE_CSGO
if (pProp->GetFlags() & SPROP_VARINT)
{
bit_count = sizeof(int) * 8;
}
#endif
break;
}
default:
{
return pContext->ThrowNativeError("Invalid Property type %d", params[2]);
}
}
if (bit_count < 1)
{
bit_count = params[5] * 8;
}
if (bit_count >= 17)
{
*(int32_t *)((uint8_t *)pEntity + offset) = params[4];
}
else if (bit_count >= 9)
{
*(int16_t *)((uint8_t *)pEntity + offset) = (int16_t)params[4];
}
else if (bit_count >= 2)
{
*(int8_t *)((uint8_t *)pEntity + offset) = (int8_t)params[4];
}
else
{
*(bool *)((uint8_t *)pEntity + offset) = params[4] ? true : false;
}
if (params[2] == Prop_Send && (pEdict != NULL))
{
g_HL2.SetEdictStateChanged(pEdict, offset);
}
return 0;
}