Add error messages and fix documentation
This commit is contained in:
parent
e0426f10b2
commit
4ceb767022
@ -251,9 +251,9 @@ void CtrlDetours_ClientCommand(bool set)
|
||||
#endif
|
||||
ClientCommandDetour = DETOUR_CREATE_STATIC_FIXED(C_ClientCommand, target);
|
||||
|
||||
if (ClientCommandDetour == NULL)
|
||||
if (!ClientCommandDetour)
|
||||
{
|
||||
MF_Log("No Client Commands detour could be initialized - Disabled Client Command forward.");
|
||||
MF_Log("ClientCommand is not available - forward client_command has been disabled");
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -337,9 +337,24 @@ void CtrlDetours_BuyCommands(bool set)
|
||||
GiveNamedItemDetour = DETOUR_CREATE_MEMBER_FIXED(GiveNamedItem, giveNamedItemAddress);
|
||||
AddAccountDetour = DETOUR_CREATE_MEMBER_FIXED(AddAccount, addAccountAddress);
|
||||
|
||||
if (GiveNamedItemDetour == NULL || AddAccountDetour == NULL)
|
||||
if (!GiveShieldDetour || !GiveNamedItemDetour || !AddAccountDetour)
|
||||
{
|
||||
MF_Log("No Buy Commands detours could be initialized - Disabled Buy forward.");
|
||||
if (!GiveNamedItemDetour)
|
||||
{
|
||||
MF_Log("GiveShield is not available");
|
||||
}
|
||||
|
||||
if (!GiveNamedItemDetour)
|
||||
{
|
||||
MF_Log("GiveNamedItem is not available");
|
||||
}
|
||||
|
||||
if (!AddAccountDetour)
|
||||
{
|
||||
MF_Log("AddAccount is not available");
|
||||
}
|
||||
|
||||
MF_Log("Some functions are not available - forward CS_OnBuyAttempt and CS_OnBuy have been disabled");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -1714,17 +1714,20 @@ extern UTIL_FindEntityByStringFunc CS_UTIL_FindEntityByString;
|
||||
// cs_create_entity(const classname[])
|
||||
static cell AMX_NATIVE_CALL cs_create_entity(AMX* amx, cell* params)
|
||||
{
|
||||
if (CS_CreateNamedEntity > 0)
|
||||
if (CS_CreateNamedEntity <= 0)
|
||||
{
|
||||
int len;
|
||||
int iszClass = ALLOC_STRING(MF_GetAmxString(amx, params[1], 0, &len));
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Native cs_create_entity() is disabled");
|
||||
return 0;
|
||||
}
|
||||
|
||||
edict_t *pEnt = CS_CreateNamedEntity(iszClass);
|
||||
int len;
|
||||
int iszClass = ALLOC_STRING(MF_GetAmxString(amx, params[1], 0, &len));
|
||||
|
||||
if (!FNullEnt(pEnt))
|
||||
{
|
||||
return ENTINDEX(pEnt);
|
||||
}
|
||||
edict_t *pEnt = CS_CreateNamedEntity(iszClass);
|
||||
|
||||
if (!FNullEnt(pEnt))
|
||||
{
|
||||
return ENTINDEX(pEnt);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -1733,18 +1736,21 @@ static cell AMX_NATIVE_CALL cs_create_entity(AMX* amx, cell* params)
|
||||
// cs_find_ent_by_class(start_index, const classname[])
|
||||
static cell AMX_NATIVE_CALL cs_find_ent_by_class(AMX* amx, cell* params)
|
||||
{
|
||||
if (CS_UTIL_FindEntityByString > 0)
|
||||
if (CS_UTIL_FindEntityByString <= 0)
|
||||
{
|
||||
int len;
|
||||
void* pEntity = G_HL_TypeConversion.id_to_cbase(params[1]);
|
||||
const char* value = MF_GetAmxString(amx, params[2], 0, &len);
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Native cs_find_ent_by_class() is disabled");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int index = G_HL_TypeConversion.cbase_to_id(CS_UTIL_FindEntityByString(pEntity, "classname", value));
|
||||
int len;
|
||||
void* pEntity = G_HL_TypeConversion.id_to_cbase(params[1]);
|
||||
const char* value = MF_GetAmxString(amx, params[2], 0, &len);
|
||||
|
||||
if (index != -1)
|
||||
{
|
||||
return index;
|
||||
}
|
||||
int index = G_HL_TypeConversion.cbase_to_id(CS_UTIL_FindEntityByString(pEntity, "classname", value));
|
||||
|
||||
if (index != -1)
|
||||
{
|
||||
return index;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -1836,7 +1842,7 @@ AMX_NATIVE_INFO CstrikeNatives[] = {
|
||||
{"cs_get_c4_defusing", cs_get_c4_defusing},
|
||||
{"cs_set_c4_defusing", cs_set_c4_defusing},
|
||||
{"cs_create_entity", cs_create_entity },
|
||||
{"cs_find_ent_by_class", cs_find_ent_by_class },
|
||||
{"cs_find_ent_by_class", cs_find_ent_by_class},
|
||||
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
@ -48,9 +48,19 @@ void OnAmxxAttach()
|
||||
|
||||
// cs_create_entity()
|
||||
CS_CreateNamedEntity = reinterpret_cast<CreateNamedEntityFunc>(UTIL_FindAddressFromEntry(CS_IDENT_CREATENAMEDENTITY, CS_IDENT_HIDDEN_STATE));
|
||||
|
||||
|
||||
if (CS_CreateNamedEntity <= 0)
|
||||
{
|
||||
MF_Log("CREATE_NAMED_ENITTY is not available - native cs_create_entity() has been disabled");
|
||||
}
|
||||
|
||||
// cs_find_ent_by_class()
|
||||
CS_UTIL_FindEntityByString = reinterpret_cast<UTIL_FindEntityByStringFunc>(UTIL_FindAddressFromEntry(CS_IDENT_UTIL_FINDENTITYBYSTRING, CS_IDENT_HIDDEN_STATE));
|
||||
|
||||
if (CS_UTIL_FindEntityByString <= 0)
|
||||
{
|
||||
MF_Log("UTIL_FindEntByString is not available - native cs_find_ent_by_class() has been disabled");
|
||||
}
|
||||
|
||||
// Search pev offset automatically.
|
||||
G_OffsetHandler = new OffsetHandler;
|
||||
|
@ -354,17 +354,18 @@ native cs_set_c4_defusing(c4index, bool:defusing);
|
||||
* Creates an entity using Counter-Strike's custom CreateNamedEntity wrapper.
|
||||
*
|
||||
* @note Unlike other mods CS keeps track of entities using a custom hashtable.
|
||||
* This function will add entities to this hashtable, providing benefits
|
||||
* over the default engine functions (used by create_entity() for example):
|
||||
* This function adds entities to this hashtable, providing benefits over
|
||||
* the default CreateNamedEntity (used by create_entity() for example):
|
||||
* - Storing entities in a hashtable allows CS to improve classname lookup
|
||||
* performance compared to functions like FindEntityByString that usually
|
||||
* have to loop incrementally through all entities.
|
||||
* performance compared to functions like FindEntityByString (used by
|
||||
* find_ent_by_class() for example) that usually have to loop
|
||||
* through all entities incrementally.
|
||||
* - As CS exclusively uses the hashtable for classname lookup, entities
|
||||
* created using the default engine functions will not be found by the
|
||||
* game. For example "weaponbox" entities are supposed to be
|
||||
* automatically cleaned up on round restart but are not considered if
|
||||
* they have not been added to the hashtable.
|
||||
* @note CS's faster hashtable lookup can be utilized with cs_find_ent_by_class()
|
||||
* @note The faster hashtable lookup can be utilized with cs_find_ent_by_class()
|
||||
*
|
||||
* @param classname Entity class name
|
||||
*
|
||||
@ -372,14 +373,14 @@ native cs_set_c4_defusing(c4index, bool:defusing);
|
||||
*/
|
||||
native cs_create_entity(const classname[]);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Finds an entity in the world using Counter-Strike's custom FindEntityByString
|
||||
* wrapper.
|
||||
*
|
||||
* @note Unlike other mods CS keeps track of entities using a custom hashtable.
|
||||
* This function utilizes the custom hasthable and allows for considerably
|
||||
* faster classname lookup compared to the default engine functions (used
|
||||
* by find_ent_by_class() for example).
|
||||
* This function utilizes the hasthable and allows for considerably faster
|
||||
* classname lookup compared to the default FindEntityByString (used by
|
||||
* find_ent_by_class() for example).
|
||||
* @note This exclusively considers entities in the hashtable, created by the
|
||||
* game itself or using cs_create_entity().
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user