Fix mp_refill_bpammo_weapons not working on default weapons (#177)

* Fix mp_refill_bpammo_weapons not working on default weapons
This commit is contained in:
In-line 2017-07-25 20:51:04 +04:00 committed by Dmitry Novikov
parent 0f1f4c002f
commit 83341a793e
8 changed files with 24 additions and 18 deletions

View File

@ -251,7 +251,7 @@ public:
virtual void AddPointsToTeam(int score, BOOL bAllowNegativeScore) {}
virtual BOOL AddPlayerItem(CBasePlayerItem *pItem) { return FALSE; }
virtual BOOL RemovePlayerItem(CBasePlayerItem *pItem) { return FALSE; }
virtual int GiveAmmo(int iAmount, char *szName, int iMax = -1) { return -1; }
virtual int GiveAmmo(int iAmount, const char *szName, int iMax = -1) { return -1; }
virtual float GetDelay() { return 0.0f; }
virtual int IsMoving() { return (pev->velocity != g_vecZero); }
virtual void OverrideReset() {}

View File

@ -1585,12 +1585,20 @@ void EXT_FUNC CBasePlayer::__API_HOOK(GiveDefaultItems)()
{
RemoveAllItems(FALSE);
// NOTE: NOTE: It is already does reset inside RemoveAllItems
// NOTE: It is already does reset inside RemoveAllItems
#ifndef REGAMEDLL_FIXES
m_bHasPrimary = false;
#endif
#ifdef REGAMEDLL_ADD
auto GiveWeapon = [&](int ammo, char* pszWeaponName) {
GiveNamedItem(pszWeaponName);
const WeaponInfoStruct *info = GetWeaponInfo(pszWeaponName);
if (info) {
GiveAmmo(refill_bpammo_weapons.value != 0.0f ? info->maxRounds : ammo, info->ammoName + 5/*ammo_*/);
}
};
switch (m_iTeam)
{
case CT:
@ -1599,8 +1607,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(GiveDefaultItems)()
GiveNamedItem("weapon_knife");
}
if (!HasRestrictItem(ITEM_USP, ITEM_TYPE_EQUIPPED)) {
GiveNamedItem("weapon_usp");
GiveAmmo(m_bIsVIP ? 12 : 24, "45acp");
GiveWeapon(m_bIsVIP ? 12 : 24, "weapon_usp");
}
break;
@ -1611,8 +1618,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(GiveDefaultItems)()
GiveNamedItem("weapon_knife");
}
if (!HasRestrictItem(ITEM_GLOCK18, ITEM_TYPE_EQUIPPED)) {
GiveNamedItem("weapon_glock18");
GiveAmmo(40, "9mm");
GiveWeapon(40, "weapon_glock18");
}
break;
@ -6561,10 +6567,10 @@ BOOL EXT_FUNC CBasePlayer::__API_HOOK(RemovePlayerItem)(CBasePlayerItem *pItem)
return FALSE;
}
LINK_HOOK_CLASS_CHAIN(int, CBasePlayer, GiveAmmo, (int iCount, char *szName, int iMax), iCount, szName, iMax)
LINK_HOOK_CLASS_CHAIN(int, CBasePlayer, GiveAmmo, (int iCount, const char *szName, int iMax), iCount, szName, iMax)
// Returns the unique ID for the ammo, or -1 if error
int EXT_FUNC CBasePlayer::__API_HOOK(GiveAmmo)(int iCount, char *szName, int iMax)
int EXT_FUNC CBasePlayer::__API_HOOK(GiveAmmo)(int iCount, const char *szName, int iMax)
{
if (pev->flags & FL_SPECTATOR)
return -1;

View File

@ -336,7 +336,7 @@ public:
virtual void AddPointsToTeam(int score, BOOL bAllowNegativeScore);
virtual BOOL AddPlayerItem(CBasePlayerItem *pItem);
virtual BOOL RemovePlayerItem(CBasePlayerItem *pItem);
virtual int GiveAmmo(int iAmount, char *szName, int iMax = -1);
virtual int GiveAmmo(int iAmount, const char *szName, int iMax = -1);
virtual void StartSneaking() { m_tSneaking = gpGlobals->time - 1; }
#ifndef REGAMEDLL_FIXES
@ -381,7 +381,7 @@ public:
void AddPointsToTeam_OrigFunc(int score, BOOL bAllowNegativeScore);
BOOL AddPlayerItem_OrigFunc(CBasePlayerItem *pItem);
BOOL RemovePlayerItem_OrigFunc(CBasePlayerItem *pItem);
int GiveAmmo_OrigFunc(int iAmount, char *szName, int iMax);
int GiveAmmo_OrigFunc(int iAmount, const char *szName, int iMax);
void ResetMaxSpeed_OrigFunc();
void Jump_OrigFunc();
void Duck_OrigFunc();

View File

@ -81,7 +81,7 @@ public:
virtual void AddPointsToTeam(int score, BOOL bAllowNegativeScore) = 0;
virtual BOOL AddPlayerItem(CBasePlayerItem *pItem) = 0;
virtual BOOL RemovePlayerItem(CBasePlayerItem *pItem) = 0;
virtual int GiveAmmo(int iAmount, char *szName, int iMax = -1) = 0;
virtual int GiveAmmo(int iAmount, const char *szName, int iMax = -1) = 0;
virtual float GetDelay() = 0;
virtual int IsMoving() = 0;
virtual void OverrideReset() = 0;

View File

@ -320,7 +320,7 @@ public:
virtual void AddPointsToTeam(int score, BOOL bAllowNegativeScore) = 0;
virtual BOOL AddPlayerItem(CBasePlayerItem *pItem) = 0;
virtual BOOL RemovePlayerItem(CBasePlayerItem *pItem) = 0;
virtual int GiveAmmo(int iAmount, char *szName, int iMax = -1) = 0;
virtual int GiveAmmo(int iAmount, const char *szName, int iMax = -1) = 0;
virtual void StartSneaking() = 0;
virtual void UpdateOnRemove() = 0;
virtual BOOL IsSneaking() = 0;

View File

@ -87,8 +87,8 @@ typedef IHookChainClass<BOOL, class CBasePlayer, class CBasePlayerItem *> IReGam
typedef IHookChainRegistryClass<BOOL, class CBasePlayer, class CBasePlayerItem *> IReGameHookRegistry_CBasePlayer_RemovePlayerItem;
// CBasePlayer::GiveAmmo hook
typedef IHookChainClass<int, class CBasePlayer, int , char *, int> IReGameHook_CBasePlayer_GiveAmmo;
typedef IHookChainRegistryClass<int, class CBasePlayer, int , char *, int> IReGameHookRegistry_CBasePlayer_GiveAmmo;
typedef IHookChainClass<int, class CBasePlayer, int , const char *, int> IReGameHook_CBasePlayer_GiveAmmo;
typedef IHookChainRegistryClass<int, class CBasePlayer, int , const char *, int> IReGameHookRegistry_CBasePlayer_GiveAmmo;
// CBasePlayer::ResetMaxSpeed hook
typedef IVoidHookChainClass<class CBasePlayer> IReGameHook_CBasePlayer_ResetMaxSpeed;

View File

@ -87,8 +87,8 @@ typedef IHookChainClass<BOOL, class CBasePlayer, class CBasePlayerItem *> IReGam
typedef IHookChainRegistryClass<BOOL, class CBasePlayer, class CBasePlayerItem *> IReGameHookRegistry_CBasePlayer_RemovePlayerItem;
// CBasePlayer::GiveAmmo hook
typedef IHookChainClass<int, class CBasePlayer, int , char *, int> IReGameHook_CBasePlayer_GiveAmmo;
typedef IHookChainRegistryClass<int, class CBasePlayer, int , char *, int> IReGameHookRegistry_CBasePlayer_GiveAmmo;
typedef IHookChainClass<int, class CBasePlayer, int , const char *, int> IReGameHook_CBasePlayer_GiveAmmo;
typedef IHookChainRegistryClass<int, class CBasePlayer, int , const char *, int> IReGameHookRegistry_CBasePlayer_GiveAmmo;
// CBasePlayer::ResetMaxSpeed hook
typedef IHookChainClass<void, class CBasePlayer> IReGameHook_CBasePlayer_ResetMaxSpeed;

View File

@ -83,8 +83,8 @@ typedef IHookChainClassImpl<BOOL, CBasePlayer, CBasePlayerItem *> CReGameHook_CB
typedef IHookChainRegistryClassImpl<BOOL, CBasePlayer, CBasePlayerItem *> CReGameHookRegistry_CBasePlayer_RemovePlayerItem;
// CBasePlayer::GiveAmmo hook
typedef IHookChainClassImpl<int, CBasePlayer, int , char *, int> CReGameHook_CBasePlayer_GiveAmmo;
typedef IHookChainRegistryClassImpl<int, CBasePlayer, int , char *, int> CReGameHookRegistry_CBasePlayer_GiveAmmo;
typedef IHookChainClassImpl<int, CBasePlayer, int , const char *, int> CReGameHook_CBasePlayer_GiveAmmo;
typedef IHookChainRegistryClassImpl<int, CBasePlayer, int , const char *, int> CReGameHookRegistry_CBasePlayer_GiveAmmo;
// CBasePlayer::ResetMaxSpeed hook
typedef IHookChainClassImpl<void, CBasePlayer> CReGameHook_CBasePlayer_ResetMaxSpeed;