Add error messages and fix documentation

This commit is contained in:
Arkshine 2015-01-31 14:45:37 +01:00
parent e0426f10b2
commit 4ceb767022
4 changed files with 64 additions and 32 deletions

View File

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

View File

@ -1714,8 +1714,12 @@ 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)
{
MF_LogError(amx, AMX_ERR_NATIVE, "Native cs_create_entity() is disabled");
return 0;
}
int len;
int iszClass = ALLOC_STRING(MF_GetAmxString(amx, params[1], 0, &len));
@ -1725,7 +1729,6 @@ static cell AMX_NATIVE_CALL cs_create_entity(AMX* amx, cell* params)
{
return ENTINDEX(pEnt);
}
}
return 0;
}
@ -1733,8 +1736,12 @@ 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)
{
MF_LogError(amx, AMX_ERR_NATIVE, "Native cs_find_ent_by_class() is disabled");
return 0;
}
int len;
void* pEntity = G_HL_TypeConversion.id_to_cbase(params[1]);
const char* value = MF_GetAmxString(amx, params[2], 0, &len);
@ -1745,7 +1752,6 @@ static cell AMX_NATIVE_CALL cs_find_ent_by_class(AMX* amx, cell* params)
{
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}
};

View File

@ -49,9 +49,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;
}

View File

@ -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
*
@ -377,9 +378,9 @@ native cs_create_entity(const classname[]);
* 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().
*