Skip to content

Commit 83341a7

Browse files
In-lines1lentq
authored andcommitted
Fix mp_refill_bpammo_weapons not working on default weapons (#177)
* Fix mp_refill_bpammo_weapons not working on default weapons
1 parent 0f1f4c0 commit 83341a7

File tree

8 files changed

+24
-18
lines changed

8 files changed

+24
-18
lines changed

regamedll/dlls/cbase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ class CBaseEntity {
251251
virtual void AddPointsToTeam(int score, BOOL bAllowNegativeScore) {}
252252
virtual BOOL AddPlayerItem(CBasePlayerItem *pItem) { return FALSE; }
253253
virtual BOOL RemovePlayerItem(CBasePlayerItem *pItem) { return FALSE; }
254-
virtual int GiveAmmo(int iAmount, char *szName, int iMax = -1) { return -1; }
254+
virtual int GiveAmmo(int iAmount, const char *szName, int iMax = -1) { return -1; }
255255
virtual float GetDelay() { return 0.0f; }
256256
virtual int IsMoving() { return (pev->velocity != g_vecZero); }
257257
virtual void OverrideReset() {}

regamedll/dlls/player.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,12 +1585,20 @@ void EXT_FUNC CBasePlayer::__API_HOOK(GiveDefaultItems)()
15851585
{
15861586
RemoveAllItems(FALSE);
15871587

1588-
// NOTE: NOTE: It is already does reset inside RemoveAllItems
1588+
// NOTE: It is already does reset inside RemoveAllItems
15891589
#ifndef REGAMEDLL_FIXES
15901590
m_bHasPrimary = false;
15911591
#endif
15921592

15931593
#ifdef REGAMEDLL_ADD
1594+
auto GiveWeapon = [&](int ammo, char* pszWeaponName) {
1595+
GiveNamedItem(pszWeaponName);
1596+
const WeaponInfoStruct *info = GetWeaponInfo(pszWeaponName);
1597+
if (info) {
1598+
GiveAmmo(refill_bpammo_weapons.value != 0.0f ? info->maxRounds : ammo, info->ammoName + 5/*ammo_*/);
1599+
}
1600+
};
1601+
15941602
switch (m_iTeam)
15951603
{
15961604
case CT:
@@ -1599,8 +1607,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(GiveDefaultItems)()
15991607
GiveNamedItem("weapon_knife");
16001608
}
16011609
if (!HasRestrictItem(ITEM_USP, ITEM_TYPE_EQUIPPED)) {
1602-
GiveNamedItem("weapon_usp");
1603-
GiveAmmo(m_bIsVIP ? 12 : 24, "45acp");
1610+
GiveWeapon(m_bIsVIP ? 12 : 24, "weapon_usp");
16041611
}
16051612

16061613
break;
@@ -1611,8 +1618,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(GiveDefaultItems)()
16111618
GiveNamedItem("weapon_knife");
16121619
}
16131620
if (!HasRestrictItem(ITEM_GLOCK18, ITEM_TYPE_EQUIPPED)) {
1614-
GiveNamedItem("weapon_glock18");
1615-
GiveAmmo(40, "9mm");
1621+
GiveWeapon(40, "weapon_glock18");
16161622
}
16171623

16181624
break;
@@ -6561,10 +6567,10 @@ BOOL EXT_FUNC CBasePlayer::__API_HOOK(RemovePlayerItem)(CBasePlayerItem *pItem)
65616567
return FALSE;
65626568
}
65636569

6564-
LINK_HOOK_CLASS_CHAIN(int, CBasePlayer, GiveAmmo, (int iCount, char *szName, int iMax), iCount, szName, iMax)
6570+
LINK_HOOK_CLASS_CHAIN(int, CBasePlayer, GiveAmmo, (int iCount, const char *szName, int iMax), iCount, szName, iMax)
65656571

65666572
// Returns the unique ID for the ammo, or -1 if error
6567-
int EXT_FUNC CBasePlayer::__API_HOOK(GiveAmmo)(int iCount, char *szName, int iMax)
6573+
int EXT_FUNC CBasePlayer::__API_HOOK(GiveAmmo)(int iCount, const char *szName, int iMax)
65686574
{
65696575
if (pev->flags & FL_SPECTATOR)
65706576
return -1;

regamedll/dlls/player.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ class CBasePlayer: public CBaseMonster {
336336
virtual void AddPointsToTeam(int score, BOOL bAllowNegativeScore);
337337
virtual BOOL AddPlayerItem(CBasePlayerItem *pItem);
338338
virtual BOOL RemovePlayerItem(CBasePlayerItem *pItem);
339-
virtual int GiveAmmo(int iAmount, char *szName, int iMax = -1);
339+
virtual int GiveAmmo(int iAmount, const char *szName, int iMax = -1);
340340
virtual void StartSneaking() { m_tSneaking = gpGlobals->time - 1; }
341341

342342
#ifndef REGAMEDLL_FIXES
@@ -381,7 +381,7 @@ class CBasePlayer: public CBaseMonster {
381381
void AddPointsToTeam_OrigFunc(int score, BOOL bAllowNegativeScore);
382382
BOOL AddPlayerItem_OrigFunc(CBasePlayerItem *pItem);
383383
BOOL RemovePlayerItem_OrigFunc(CBasePlayerItem *pItem);
384-
int GiveAmmo_OrigFunc(int iAmount, char *szName, int iMax);
384+
int GiveAmmo_OrigFunc(int iAmount, const char *szName, int iMax);
385385
void ResetMaxSpeed_OrigFunc();
386386
void Jump_OrigFunc();
387387
void Duck_OrigFunc();

regamedll/extra/cssdk/dlls/cbase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class CBaseEntity {
8181
virtual void AddPointsToTeam(int score, BOOL bAllowNegativeScore) = 0;
8282
virtual BOOL AddPlayerItem(CBasePlayerItem *pItem) = 0;
8383
virtual BOOL RemovePlayerItem(CBasePlayerItem *pItem) = 0;
84-
virtual int GiveAmmo(int iAmount, char *szName, int iMax = -1) = 0;
84+
virtual int GiveAmmo(int iAmount, const char *szName, int iMax = -1) = 0;
8585
virtual float GetDelay() = 0;
8686
virtual int IsMoving() = 0;
8787
virtual void OverrideReset() = 0;

regamedll/extra/cssdk/dlls/player.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ class CBasePlayer: public CBaseMonster {
320320
virtual void AddPointsToTeam(int score, BOOL bAllowNegativeScore) = 0;
321321
virtual BOOL AddPlayerItem(CBasePlayerItem *pItem) = 0;
322322
virtual BOOL RemovePlayerItem(CBasePlayerItem *pItem) = 0;
323-
virtual int GiveAmmo(int iAmount, char *szName, int iMax = -1) = 0;
323+
virtual int GiveAmmo(int iAmount, const char *szName, int iMax = -1) = 0;
324324
virtual void StartSneaking() = 0;
325325
virtual void UpdateOnRemove() = 0;
326326
virtual BOOL IsSneaking() = 0;

regamedll/extra/cssdk/dlls/regamedll_api.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ typedef IHookChainClass<BOOL, class CBasePlayer, class CBasePlayerItem *> IReGam
8787
typedef IHookChainRegistryClass<BOOL, class CBasePlayer, class CBasePlayerItem *> IReGameHookRegistry_CBasePlayer_RemovePlayerItem;
8888

8989
// CBasePlayer::GiveAmmo hook
90-
typedef IHookChainClass<int, class CBasePlayer, int , char *, int> IReGameHook_CBasePlayer_GiveAmmo;
91-
typedef IHookChainRegistryClass<int, class CBasePlayer, int , char *, int> IReGameHookRegistry_CBasePlayer_GiveAmmo;
90+
typedef IHookChainClass<int, class CBasePlayer, int , const char *, int> IReGameHook_CBasePlayer_GiveAmmo;
91+
typedef IHookChainRegistryClass<int, class CBasePlayer, int , const char *, int> IReGameHookRegistry_CBasePlayer_GiveAmmo;
9292

9393
// CBasePlayer::ResetMaxSpeed hook
9494
typedef IVoidHookChainClass<class CBasePlayer> IReGameHook_CBasePlayer_ResetMaxSpeed;

regamedll/public/regamedll/regamedll_api.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ typedef IHookChainClass<BOOL, class CBasePlayer, class CBasePlayerItem *> IReGam
8787
typedef IHookChainRegistryClass<BOOL, class CBasePlayer, class CBasePlayerItem *> IReGameHookRegistry_CBasePlayer_RemovePlayerItem;
8888

8989
// CBasePlayer::GiveAmmo hook
90-
typedef IHookChainClass<int, class CBasePlayer, int , char *, int> IReGameHook_CBasePlayer_GiveAmmo;
91-
typedef IHookChainRegistryClass<int, class CBasePlayer, int , char *, int> IReGameHookRegistry_CBasePlayer_GiveAmmo;
90+
typedef IHookChainClass<int, class CBasePlayer, int , const char *, int> IReGameHook_CBasePlayer_GiveAmmo;
91+
typedef IHookChainRegistryClass<int, class CBasePlayer, int , const char *, int> IReGameHookRegistry_CBasePlayer_GiveAmmo;
9292

9393
// CBasePlayer::ResetMaxSpeed hook
9494
typedef IHookChainClass<void, class CBasePlayer> IReGameHook_CBasePlayer_ResetMaxSpeed;

regamedll/regamedll/regamedll_api_impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ typedef IHookChainClassImpl<BOOL, CBasePlayer, CBasePlayerItem *> CReGameHook_CB
8383
typedef IHookChainRegistryClassImpl<BOOL, CBasePlayer, CBasePlayerItem *> CReGameHookRegistry_CBasePlayer_RemovePlayerItem;
8484

8585
// CBasePlayer::GiveAmmo hook
86-
typedef IHookChainClassImpl<int, CBasePlayer, int , char *, int> CReGameHook_CBasePlayer_GiveAmmo;
87-
typedef IHookChainRegistryClassImpl<int, CBasePlayer, int , char *, int> CReGameHookRegistry_CBasePlayer_GiveAmmo;
86+
typedef IHookChainClassImpl<int, CBasePlayer, int , const char *, int> CReGameHook_CBasePlayer_GiveAmmo;
87+
typedef IHookChainRegistryClassImpl<int, CBasePlayer, int , const char *, int> CReGameHookRegistry_CBasePlayer_GiveAmmo;
8888

8989
// CBasePlayer::ResetMaxSpeed hook
9090
typedef IHookChainClassImpl<void, CBasePlayer> CReGameHook_CBasePlayer_ResetMaxSpeed;

0 commit comments

Comments
 (0)