From a798010a52e53871fd5eae96680fb964dad81d4c Mon Sep 17 00:00:00 2001 From: Vaqtincha Date: Sun, 3 Nov 2019 17:37:54 +0500 Subject: [PATCH 1/3] WeaponBox: Fix hardcoded maxammo --- regamedll/dlls/player.cpp | 13 ++++++++- regamedll/dlls/weapons.cpp | 54 +++++++++++++++++++++++++++++++++++++- regamedll/dlls/weapons.h | 4 +++ 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index 32ab60f40..2e6ed6bac 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -1288,7 +1288,13 @@ void PackPlayerItem(CBasePlayer *pPlayer, CBasePlayerItem *pItem, bool packAmmo) // pack the ammo if (packAmmo) { + +#ifdef REGAMEDLL_FIXES + pWeaponBox->PackAmmoEx(MAKE_STRING(pItem->pszAmmo1()), pPlayer->m_rgAmmo[pItem->PrimaryAmmoIndex()], pItem->iMaxAmmo1()); +#else pWeaponBox->PackAmmo(MAKE_STRING(pItem->pszAmmo1()), pPlayer->m_rgAmmo[pItem->PrimaryAmmoIndex()]); +#endif + } pWeaponBox->SetModel(modelName); @@ -1344,7 +1350,12 @@ void PackPlayerNade(CBasePlayer *pPlayer, CBasePlayerItem *pItem, bool packAmmo) // pack the ammo if (packAmmo) { + +#ifdef REGAMEDLL_FIXES + pWeaponBox->PackAmmoEx(MAKE_STRING(pItem->pszAmmo1()), pPlayer->m_rgAmmo[pItem->PrimaryAmmoIndex()], pItem->iMaxAmmo1()); +#else pWeaponBox->PackAmmo(MAKE_STRING(pItem->pszAmmo1()), pPlayer->m_rgAmmo[pItem->PrimaryAmmoIndex()]); +#endif } pWeaponBox->SetModel(modelName); @@ -7791,7 +7802,7 @@ CBaseEntity *EXT_FUNC CBasePlayer::__API_HOOK(DropPlayerItem)(const char *pszIte { #ifdef REGAMEDLL_FIXES // why not pack the ammo more than one? - pWeaponBox->PackAmmo(MAKE_STRING(pWeapon->pszAmmo1()), m_rgAmmo[iAmmoIndex]); + pWeaponBox->PackAmmoEx(MAKE_STRING(pWeapon->pszAmmo1()), m_rgAmmo[iAmmoIndex], pWeapon->iMaxAmmo1()); #else pWeaponBox->PackAmmo(MAKE_STRING(pWeapon->pszAmmo1()), m_rgAmmo[iAmmoIndex] > 0); #endif diff --git a/regamedll/dlls/weapons.cpp b/regamedll/dlls/weapons.cpp index 2eff9fb01..d6b45fc6d 100644 --- a/regamedll/dlls/weapons.cpp +++ b/regamedll/dlls/weapons.cpp @@ -1931,8 +1931,11 @@ void CWeaponBox::Touch(CBaseEntity *pOther) if (!FStringNull(m_rgiszAmmo[n])) { // there's some ammo of this type. +#ifdef REGAMEDLL_FIXES + pPlayer->GiveAmmo(m_rgAmmo[n], (char *)STRING(m_rgiszAmmo[n]), m_rgAmmo[n]); +#else pPlayer->GiveAmmo(m_rgAmmo[n], (char *)STRING(m_rgiszAmmo[n]), MaxAmmoCarry(m_rgiszAmmo[n])); - +#endif // now empty the ammo from the weaponbox since we just gave it to the player m_rgiszAmmo[n] = iStringNull; m_rgAmmo[n] = 0; @@ -2005,6 +2008,55 @@ BOOL CWeaponBox::PackWeapon(CBasePlayerItem *pWeapon) return TRUE; } +#ifdef REGAMEDLL_FIXES +int CWeaponBox::PackAmmoEx(string_t iszName, int iCount, int iMaxCarry) +{ + if (!iszName) + { + // ALERT(at_console, "[%s] NULL string!\n", __FUNCTION__); + return -1; + } + + // Duplicate -- int CBasePlayer::GetAmmoIndex + auto GetAmmoIndex = [&](const char *pszAmmoName)->int + { + for (auto& ammo : ammoIndex) + { + if (!Q_stricmp(ammo.name, pszAmmoName)) { + return ammo.type; + } + } + + return -1; + }; + + int iAmmoIndex = GetAmmoIndex(iszName); + + if (iAmmoIndex < 0 || iAmmoIndex >= MAX_AMMO_SLOTS) + { + // ALERT(at_console, "[%s] out of named ammo slots!\n", __FUNCTION__); + return -1; + } + + if (iMaxCarry == -1) + iMaxCarry = MaxAmmoCarry(iszName); + + int iAdd = Q_min(iCount, iMaxCarry - m_rgAmmo[iAmmoIndex]); + + if (iAdd < 1) + return iAmmoIndex; + + if (FStringNull(m_rgiszAmmo[iAmmoIndex])) + { + m_rgiszAmmo[iAmmoIndex] = iszName; + } + + m_rgAmmo[iAmmoIndex] += iAdd; + + return iAmmoIndex; +} +#endif + BOOL CWeaponBox::PackAmmo(string_t iszName, int iCount) { if (!iszName) diff --git a/regamedll/dlls/weapons.h b/regamedll/dlls/weapons.h index f3d90ebb5..f8c0e6907 100644 --- a/regamedll/dlls/weapons.h +++ b/regamedll/dlls/weapons.h @@ -478,6 +478,10 @@ class CWeaponBox: public CBaseEntity BOOL PackWeapon(CBasePlayerItem *pWeapon); BOOL PackAmmo(string_t iszName, int iCount); +#ifdef REGAMEDLL_FIXES + int PackAmmoEx(string_t iszName, int iCount, int iMaxCarry = -1); +#endif + #ifdef REGAMEDLL_API void SetModel_OrigFunc(const char *pszModelName); #endif From 95b28ee362436a7b03575893e5ef1dd152aaa78d Mon Sep 17 00:00:00 2001 From: Vaqtincha Date: Sun, 3 Nov 2019 17:37:54 +0500 Subject: [PATCH 2/3] WeaponBox: Fix hardcoded maxammo --- regamedll/dlls/player.cpp | 13 ++++++++- regamedll/dlls/weapons.cpp | 54 +++++++++++++++++++++++++++++++++++++- regamedll/dlls/weapons.h | 4 +++ 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index 32ab60f40..2e6ed6bac 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -1288,7 +1288,13 @@ void PackPlayerItem(CBasePlayer *pPlayer, CBasePlayerItem *pItem, bool packAmmo) // pack the ammo if (packAmmo) { + +#ifdef REGAMEDLL_FIXES + pWeaponBox->PackAmmoEx(MAKE_STRING(pItem->pszAmmo1()), pPlayer->m_rgAmmo[pItem->PrimaryAmmoIndex()], pItem->iMaxAmmo1()); +#else pWeaponBox->PackAmmo(MAKE_STRING(pItem->pszAmmo1()), pPlayer->m_rgAmmo[pItem->PrimaryAmmoIndex()]); +#endif + } pWeaponBox->SetModel(modelName); @@ -1344,7 +1350,12 @@ void PackPlayerNade(CBasePlayer *pPlayer, CBasePlayerItem *pItem, bool packAmmo) // pack the ammo if (packAmmo) { + +#ifdef REGAMEDLL_FIXES + pWeaponBox->PackAmmoEx(MAKE_STRING(pItem->pszAmmo1()), pPlayer->m_rgAmmo[pItem->PrimaryAmmoIndex()], pItem->iMaxAmmo1()); +#else pWeaponBox->PackAmmo(MAKE_STRING(pItem->pszAmmo1()), pPlayer->m_rgAmmo[pItem->PrimaryAmmoIndex()]); +#endif } pWeaponBox->SetModel(modelName); @@ -7791,7 +7802,7 @@ CBaseEntity *EXT_FUNC CBasePlayer::__API_HOOK(DropPlayerItem)(const char *pszIte { #ifdef REGAMEDLL_FIXES // why not pack the ammo more than one? - pWeaponBox->PackAmmo(MAKE_STRING(pWeapon->pszAmmo1()), m_rgAmmo[iAmmoIndex]); + pWeaponBox->PackAmmoEx(MAKE_STRING(pWeapon->pszAmmo1()), m_rgAmmo[iAmmoIndex], pWeapon->iMaxAmmo1()); #else pWeaponBox->PackAmmo(MAKE_STRING(pWeapon->pszAmmo1()), m_rgAmmo[iAmmoIndex] > 0); #endif diff --git a/regamedll/dlls/weapons.cpp b/regamedll/dlls/weapons.cpp index 2eff9fb01..eee8de336 100644 --- a/regamedll/dlls/weapons.cpp +++ b/regamedll/dlls/weapons.cpp @@ -1931,8 +1931,11 @@ void CWeaponBox::Touch(CBaseEntity *pOther) if (!FStringNull(m_rgiszAmmo[n])) { // there's some ammo of this type. +#ifdef REGAMEDLL_FIXES + pPlayer->GiveAmmo(m_rgAmmo[n], STRING(m_rgiszAmmo[n]), m_rgAmmo[n]); +#else pPlayer->GiveAmmo(m_rgAmmo[n], (char *)STRING(m_rgiszAmmo[n]), MaxAmmoCarry(m_rgiszAmmo[n])); - +#endif // now empty the ammo from the weaponbox since we just gave it to the player m_rgiszAmmo[n] = iStringNull; m_rgAmmo[n] = 0; @@ -2005,6 +2008,55 @@ BOOL CWeaponBox::PackWeapon(CBasePlayerItem *pWeapon) return TRUE; } +#ifdef REGAMEDLL_FIXES +int CWeaponBox::PackAmmoEx(string_t iszName, int iCount, int iMaxCarry) +{ + if (!iszName) + { + // ALERT(at_console, "[%s] NULL string!\n", __FUNCTION__); + return -1; + } + + // Duplicate -- int CBasePlayer::GetAmmoIndex + auto GetAmmoIndex = [&](const char *pszAmmoName)->int + { + for (auto& ammo : ammoIndex) + { + if (!Q_stricmp(ammo.name, pszAmmoName)) { + return ammo.type; + } + } + + return -1; + }; + + int iAmmoIndex = GetAmmoIndex(iszName); + + if (iAmmoIndex < 0 || iAmmoIndex >= MAX_AMMO_SLOTS) + { + // ALERT(at_console, "[%s] out of named ammo slots!\n", __FUNCTION__); + return -1; + } + + if (iMaxCarry == -1) + iMaxCarry = MaxAmmoCarry(iszName); + + int iAdd = Q_min(iCount, iMaxCarry - m_rgAmmo[iAmmoIndex]); + + if (iAdd < 1) + return iAmmoIndex; + + if (FStringNull(m_rgiszAmmo[iAmmoIndex])) + { + m_rgiszAmmo[iAmmoIndex] = iszName; + } + + m_rgAmmo[iAmmoIndex] += iAdd; + + return iAmmoIndex; +} +#endif + BOOL CWeaponBox::PackAmmo(string_t iszName, int iCount) { if (!iszName) diff --git a/regamedll/dlls/weapons.h b/regamedll/dlls/weapons.h index f3d90ebb5..f8c0e6907 100644 --- a/regamedll/dlls/weapons.h +++ b/regamedll/dlls/weapons.h @@ -478,6 +478,10 @@ class CWeaponBox: public CBaseEntity BOOL PackWeapon(CBasePlayerItem *pWeapon); BOOL PackAmmo(string_t iszName, int iCount); +#ifdef REGAMEDLL_FIXES + int PackAmmoEx(string_t iszName, int iCount, int iMaxCarry = -1); +#endif + #ifdef REGAMEDLL_API void SetModel_OrigFunc(const char *pszModelName); #endif From e18bfc5d1583e79afcce991676654082a6d1546c Mon Sep 17 00:00:00 2001 From: Vaqtincha Date: Sun, 17 Nov 2019 15:14:14 +0500 Subject: [PATCH 3/3] oops --- regamedll/dlls/player.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index 93947934b..c28190e94 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -7800,17 +7800,19 @@ CBaseEntity *EXT_FUNC CBasePlayer::__API_HOOK(DropPlayerItem)(const char *pszIte int iAmmoIndex = GetAmmoIndex(pWeapon->pszAmmo1()); if (iAmmoIndex != -1) { -#ifdef REGAMEDLL_FIXES #ifdef REGAMEDLL_ADD pWeaponBox->PackAmmoEx(MAKE_STRING(pWeapon->pszAmmo1()), m_rgAmmo[iAmmoIndex], pWeapon->iMaxAmmo1()); -#else // REGAMEDLL_ADD +#else // REGAMEDLL_ADD + +#ifdef REGAMEDLL_FIXES // why not pack the ammo more than one? pWeaponBox->PackAmmo(MAKE_STRING(pWeapon->pszAmmo1()), m_rgAmmo[iAmmoIndex]); -#endif // REGAMEDLL_ADD -#else +#else // REGAMEDLL_FIXES pWeaponBox->PackAmmo(MAKE_STRING(pWeapon->pszAmmo1()), m_rgAmmo[iAmmoIndex] > 0); #endif // REGAMEDLL_FIXES + +#endif // REGAMEDLL_ADD m_rgAmmo[iAmmoIndex] = 0; } }