Merge pull request #332 from Arkshine/feature/cs_set_ent_class

Add cs_set_ent_class native
This commit is contained in:
Vincent Herbet
2016-02-09 11:34:40 +01:00
5 changed files with 82 additions and 2 deletions

View File

@ -39,6 +39,8 @@ CDetour *BuyGunAmmoDetour;
CreateNamedEntityFunc CS_CreateNamedEntity;
UTIL_FindEntityByStringFunc CS_UTIL_FindEntityByString;
GetWeaponInfoFunc GetWeaponInfo;
AddEntityHashValueFunc AddEntityHashValue;
RemoveEntityHashValueFunc RemoveEntityHashValue;
int CurrentItemId;
bool TriggeredFromCommand;
@ -537,6 +539,16 @@ void InitFuncsAddresses()
GetWeaponInfo = reinterpret_cast<GetWeaponInfoFunc>(address);
}
if (MainConfig->GetMemSig("AddEntityHashValue", &address)) // cs_set_ent_class()
{
AddEntityHashValue = reinterpret_cast<AddEntityHashValueFunc>(address);
}
if (MainConfig->GetMemSig("RemoveEntityHashValue", &address)) // cs_set_ent_class()
{
RemoveEntityHashValue = reinterpret_cast<RemoveEntityHashValueFunc>(address);
}
if (!CS_CreateNamedEntity)
{

View File

@ -54,13 +54,22 @@ extern CDetour *CanBuyThisDetour;
extern CDetour *GiveDefaultItemsDetour;
extern CDetour *BuyGunAmmoDetour;
enum class HashType
{
Classname
};
typedef edict_t* (*CreateNamedEntityFunc)(string_t iszClassname);
typedef void* (*UTIL_FindEntityByStringFunc)(void* pStartEntity, const char *szKeyword, const char *szValue);
typedef WeaponInfoStruct* (*GetWeaponInfoFunc)(int id);
typedef void (*AddEntityHashValueFunc)(struct entvars_s *pev, const char *value, HashType fieldType);
typedef void (*RemoveEntityHashValueFunc)(struct entvars_s *pev, const char *value, HashType fieldType);
extern CreateNamedEntityFunc CS_CreateNamedEntity;
extern UTIL_FindEntityByStringFunc CS_UTIL_FindEntityByString;
extern GetWeaponInfoFunc GetWeaponInfo;
extern AddEntityHashValueFunc AddEntityHashValue;
extern RemoveEntityHashValueFunc RemoveEntityHashValue;
extern CDetour *GiveDefaultItemsDetour;
extern enginefuncs_t *g_pengfuncsTable;

View File

@ -1782,6 +1782,34 @@ static cell AMX_NATIVE_CALL cs_find_ent_by_owner(AMX* amx, cell* params)
return 0;
}
// cs_set_ent_class(index, const classname[])
static cell AMX_NATIVE_CALL cs_set_ent_class(AMX* amx, cell* params)
{
if (AddEntityHashValue <= 0 || RemoveEntityHashValue <= 0)
{
MF_LogError(amx, AMX_ERR_NATIVE, "Native cs_set_ent_class() is disabled. Check your amxx logs.");
return 0;
}
auto entity = params[1];
CHECK_ENTITY_SIMPLE(entity);
auto pev = TypeConversion.id_to_entvars(entity);
if (pev->classname)
{
RemoveEntityHashValue(pev, STRING(pev->classname), HashType::Classname);
}
int length;
auto new_classname = MF_GetAmxString(amx, params[2], 0, &length);
pev->classname = ALLOC_STRING(new_classname);
AddEntityHashValue(pev, STRING(pev->classname), HashType::Classname);
return 1;
}
// native any:cs_get_item_id(const name[], &CsWeaponClassType:classid = CS_WEAPONCLASS_NONE);
static cell AMX_NATIVE_CALL cs_get_item_id(AMX* amx, cell* params)
{
@ -2004,6 +2032,7 @@ AMX_NATIVE_INFO CstrikeNatives[] =
{"cs_create_entity", cs_create_entity },
{"cs_find_ent_by_class", cs_find_ent_by_class},
{"cs_find_ent_by_owner", cs_find_ent_by_owner},
{"cs_set_ent_class", cs_set_ent_class },
{"cs_get_item_id", cs_get_item_id},
{"cs_get_translated_item_alias",cs_get_translated_item_alias},
{"cs_get_weapon_info", cs_get_weapon_info},