Cstrike: Refactor - Simplify forwards logic, fix and improve few things
- The logic around CS_OnBuy forward has been simplified. Since there is no way to have a consistent way to hook/block for all items, the new logic is to have as less as possible code, especially in blocking mode where we want to avoid to do extra stuffs (e.g blocking sound, event, etc). * All guns + shield -> CanBuyThis() * Nvgs and Fefuser only -> CanPlayerBuy() * The others items -> GiveNamedItem() + AddAccount() * Ammos -> -> BuyGunAmmo() + GiveNamedItem() + AddAccount() - Fixed missing buyzone check when alias from console are used (CS_OnBUy* were incorrectly fired). - Fixed an infinite loop when buying of ammos are blocked. Sorted by hooking BuyGunAmmo(). - Fixed blocking mode for some items. Some game behaviors were not blocked (e.g. weapon drop). - Fixed forwards being triggered even though errors were found. Detours are now a destroyed and associated variables resetted when necessary. Toggling forwards state is now based on detours state. - Moved things in its own functions (game functions to execute, class members retrieval) - Renamed CommandAliases -> ItemInfos (more generic)
This commit is contained in:
@ -12,9 +12,10 @@
|
||||
//
|
||||
|
||||
#include "CstrikeItemsInfos.h"
|
||||
#include <amxxmodule.h>
|
||||
#include "CstrikeHacks.h"
|
||||
|
||||
CsItemInfo ItemsManager;
|
||||
char WeaponNameList[MAX_WEAPONS][64];
|
||||
|
||||
#define PSTATE_ALIASES_TYPE 0
|
||||
#define PSTATE_ALIASES_ALIAS 1
|
||||
@ -52,15 +53,15 @@ SMCResult CsItemInfo::ReadSMC_NewSection(const SMCStates *states, const char *na
|
||||
{
|
||||
m_List = nullptr;
|
||||
|
||||
if (!strcmp(name, "Common"))
|
||||
if (!strcmp(name, "CommonAlias"))
|
||||
{
|
||||
m_List = &m_CommonAliasesList;
|
||||
}
|
||||
else if (!strcmp(name, "Weapon"))
|
||||
else if (!strcmp(name, "WeaponAlias"))
|
||||
{
|
||||
m_List = &m_WeaponAliasesList;
|
||||
}
|
||||
else if (!strcmp(name, "Buy") || !strcmp(name, "BuyEquip") || !strcmp(name, "BuyAmmo"))
|
||||
else if (!strcmp(name, "BuyAlias") || !strcmp(name, "BuyEquipAlias") || !strcmp(name, "BuyAmmoAlias"))
|
||||
{
|
||||
m_List = &m_BuyAliasesList;
|
||||
}
|
||||
@ -113,6 +114,21 @@ SMCResult CsItemInfo::ReadSMC_KeyValue(const SMCStates *states, const char *key,
|
||||
{
|
||||
m_AliasInfo.classname = value;
|
||||
}
|
||||
else if (!strcmp(key, "price"))
|
||||
{
|
||||
static int equipmentsList[static_cast<size_t>(Equipments::Count)] =
|
||||
{
|
||||
CSI_NONE, CSI_VEST, CSI_VESTHELM, CSI_FLASHBANG, CSI_HEGRENADE, CSI_SMOKEGRENADE, CSI_NVGS, CSI_DEFUSER
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAY_LENGTH(equipmentsList); ++i)
|
||||
{
|
||||
if (m_AliasInfo.itemid == equipmentsList[i])
|
||||
{
|
||||
m_EquipmentsPrice[i] = atoi(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -231,3 +247,31 @@ CsWeaponClassType CsItemInfo::WeaponIdToClass(int id)
|
||||
|
||||
return CS_WEAPONCLASS_NONE;
|
||||
}
|
||||
|
||||
int CsItemInfo::GetItemPrice(int itemId)
|
||||
{
|
||||
if (itemId <= CSI_NONE || itemId > CSI_SHIELD)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
Equipments id = Equipments::None;
|
||||
|
||||
switch (itemId)
|
||||
{
|
||||
case CSI_VEST: id = Equipments::Vest; break;
|
||||
case CSI_VESTHELM: id = Equipments::Vesthelm; break;
|
||||
case CSI_HEGRENADE: id = Equipments::HEGrenade; break;
|
||||
case CSI_SMOKEGRENADE: id = Equipments::SmokeGrenade; break;
|
||||
case CSI_FLASHBANG: id = Equipments::Flashbang; break;
|
||||
case CSI_NVGS: id = Equipments::Nvg; break;
|
||||
case CSI_DEFUSER: id = Equipments::Defuser; break;
|
||||
}
|
||||
|
||||
if (id != Equipments::None)
|
||||
{
|
||||
return m_EquipmentsPrice[static_cast<size_t>(id)];
|
||||
}
|
||||
|
||||
return GetWeaponInfo(itemId == CSI_SHIELD ? CSI_SHIELDGUN : itemId)->cost;
|
||||
}
|
||||
|
Reference in New Issue
Block a user