Create weaponbox hook (#521)

* Add SpawnWeaponBox hook
This commit is contained in:
fant1kua 2020-03-27 04:17:41 +02:00 committed by GitHub
parent 9461d03c7f
commit 73f5d6d473
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 74 additions and 67 deletions

View File

@ -1,3 +1,3 @@
majorVersion=5 majorVersion=5
minorVersion=14 minorVersion=15
maintenanceVersion=0 maintenanceVersion=0

View File

@ -168,6 +168,8 @@ GAMEHOOK_REGISTRY(CBasePlayerWeapon_DefaultReload);
GAMEHOOK_REGISTRY(CBasePlayerWeapon_DefaultShotgunReload); GAMEHOOK_REGISTRY(CBasePlayerWeapon_DefaultShotgunReload);
GAMEHOOK_REGISTRY(CBasePlayer_DropIdlePlayer); GAMEHOOK_REGISTRY(CBasePlayer_DropIdlePlayer);
GAMEHOOK_REGISTRY(CreateWeaponBox);
int CReGameApi::GetMajorVersion() { int CReGameApi::GetMajorVersion() {
return REGAMEDLL_API_VERSION_MAJOR; return REGAMEDLL_API_VERSION_MAJOR;
} }

View File

@ -567,6 +567,10 @@ typedef IHookChainRegistryClassImpl<bool, CBasePlayerWeapon, int, int, float, fl
typedef IHookChainClassImpl<void, CBasePlayer, const char *> CReGameHook_CBasePlayer_DropIdlePlayer; typedef IHookChainClassImpl<void, CBasePlayer, const char *> CReGameHook_CBasePlayer_DropIdlePlayer;
typedef IHookChainRegistryClassImpl<void, CBasePlayer, const char *> CReGameHookRegistry_CBasePlayer_DropIdlePlayer; typedef IHookChainRegistryClassImpl<void, CBasePlayer, const char *> CReGameHookRegistry_CBasePlayer_DropIdlePlayer;
// CreateWeaponBox hook
typedef IHookChainImpl<CWeaponBox *, CBasePlayerItem *, CBasePlayer *, const char *, const Vector &, const Vector &, const Vector &, float, bool> CReGameHook_CreateWeaponBox;
typedef IHookChainRegistryImpl<CWeaponBox *, CBasePlayerItem *, CBasePlayer *, const char *, const Vector &, const Vector &, const Vector &, float, bool> CReGameHookRegistry_CreateWeaponBox;
class CReGameHookchains: public IReGameHookchains { class CReGameHookchains: public IReGameHookchains {
public: public:
// CBasePlayer virtual // CBasePlayer virtual
@ -681,6 +685,7 @@ public:
CReGameHookRegistry_CBasePlayerWeapon_DefaultReload m_CBasePlayerWeapon_DefaultReload; CReGameHookRegistry_CBasePlayerWeapon_DefaultReload m_CBasePlayerWeapon_DefaultReload;
CReGameHookRegistry_CBasePlayerWeapon_DefaultShotgunReload m_CBasePlayerWeapon_DefaultShotgunReload; CReGameHookRegistry_CBasePlayerWeapon_DefaultShotgunReload m_CBasePlayerWeapon_DefaultShotgunReload;
CReGameHookRegistry_CBasePlayer_DropIdlePlayer m_CBasePlayer_DropIdlePlayer; CReGameHookRegistry_CBasePlayer_DropIdlePlayer m_CBasePlayer_DropIdlePlayer;
CReGameHookRegistry_CreateWeaponBox m_CreateWeaponBox;
public: public:
virtual IReGameHookRegistry_CBasePlayer_Spawn *CBasePlayer_Spawn(); virtual IReGameHookRegistry_CBasePlayer_Spawn *CBasePlayer_Spawn();
@ -794,6 +799,7 @@ public:
virtual IReGameHookRegistry_CBasePlayerWeapon_DefaultReload *CBasePlayerWeapon_DefaultReload(); virtual IReGameHookRegistry_CBasePlayerWeapon_DefaultReload *CBasePlayerWeapon_DefaultReload();
virtual IReGameHookRegistry_CBasePlayerWeapon_DefaultShotgunReload *CBasePlayerWeapon_DefaultShotgunReload(); virtual IReGameHookRegistry_CBasePlayerWeapon_DefaultShotgunReload *CBasePlayerWeapon_DefaultShotgunReload();
virtual IReGameHookRegistry_CBasePlayer_DropIdlePlayer *CBasePlayer_DropIdlePlayer(); virtual IReGameHookRegistry_CBasePlayer_DropIdlePlayer *CBasePlayer_DropIdlePlayer();
virtual IReGameHookRegistry_CreateWeaponBox *CreateWeaponBox();
}; };
extern CReGameHookchains g_ReGameHookchains; extern CReGameHookchains g_ReGameHookchains;

View File

@ -1266,6 +1266,41 @@ BOOL EXT_FUNC CBasePlayer::__API_HOOK(TakeDamage)(entvars_t *pevInflictor, entva
return bTookDamage; return bTookDamage;
} }
LINK_HOOK_CHAIN(CWeaponBox *, CreateWeaponBox, (CBasePlayerItem *pItem, CBasePlayer *pPlayerOwner, const char *modelName, const Vector &origin, const Vector &angles, const Vector &velocity, float lifeTime, bool packAmmo), pItem, pPlayerOwner, modelName, origin, angles, velocity, lifeTime, packAmmo)
CWeaponBox *EXT_FUNC __API_HOOK(CreateWeaponBox)(CBasePlayerItem *pItem, CBasePlayer *pPlayerOwner, const char *modelName, const Vector &origin, const Vector &angles, const Vector &velocity, float lifeTime, bool packAmmo)
{
// create a box to pack the stuff into.
CWeaponBox *pWeaponBox = (CWeaponBox *)CBaseEntity::Create("weaponbox", origin, angles, ENT(pPlayerOwner->pev));
if (pWeaponBox)
{
// don't let weaponbox tilt.
pWeaponBox->pev->angles.x = 0;
pWeaponBox->pev->angles.z = 0;
pWeaponBox->pev->velocity = velocity;
pWeaponBox->SetThink(&CWeaponBox::Kill);
pWeaponBox->pev->nextthink = gpGlobals->time + lifeTime;
pWeaponBox->PackWeapon(pItem); // now pack all of the items in the lists
// pack the ammo
bool exhaustibleAmmo = (pItem->iFlags() & ITEM_FLAG_EXHAUSTIBLE) == ITEM_FLAG_EXHAUSTIBLE;
if (exhaustibleAmmo || packAmmo)
{
pWeaponBox->PackAmmo(MAKE_STRING(pItem->pszAmmo1()), pPlayerOwner->m_rgAmmo[pItem->PrimaryAmmoIndex()]);
if (exhaustibleAmmo)
{
pPlayerOwner->m_rgAmmo[pItem->PrimaryAmmoIndex()] = 0;
}
}
pWeaponBox->SetModel(modelName);
}
return pWeaponBox;
}
void PackPlayerItem(CBasePlayer *pPlayer, CBasePlayerItem *pItem, bool packAmmo) void PackPlayerItem(CBasePlayer *pPlayer, CBasePlayerItem *pItem, bool packAmmo)
{ {
if (!pItem) if (!pItem)
@ -1274,24 +1309,14 @@ void PackPlayerItem(CBasePlayer *pPlayer, CBasePlayerItem *pItem, bool packAmmo)
const char *modelName = GetCSModelName(pItem->m_iId); const char *modelName = GetCSModelName(pItem->m_iId);
if (modelName) if (modelName)
{ {
// create a box to pack the stuff into. // create a box to pack the stuff into
CWeaponBox *pWeaponBox = (CWeaponBox *)CBaseEntity::Create("weaponbox", pPlayer->pev->origin, pPlayer->pev->angles, ENT(pPlayer->pev)); CreateWeaponBox(pItem, pPlayer,
modelName,
// don't let weaponbox tilt. pPlayer->pev->origin,
pWeaponBox->pev->angles.x = 0; pPlayer->pev->angles,
pWeaponBox->pev->angles.z = 0; pPlayer->pev->velocity * 0.75f,
pWeaponBox->pev->velocity = pPlayer->pev->velocity * 0.75f; CGameRules::GetItemKillDelay(), packAmmo
pWeaponBox->SetThink(&CWeaponBox::Kill); );
pWeaponBox->pev->nextthink = gpGlobals->time + CGameRules::GetItemKillDelay();
pWeaponBox->PackWeapon(pItem); // now pack all of the items in the lists
// pack the ammo
if (packAmmo)
{
pWeaponBox->PackAmmo(MAKE_STRING(pItem->pszAmmo1()), pPlayer->m_rgAmmo[pItem->PrimaryAmmoIndex()]);
}
pWeaponBox->SetModel(modelName);
} }
} }
@ -1329,25 +1354,13 @@ void PackPlayerNade(CBasePlayer *pPlayer, CBasePlayerItem *pItem, bool packAmmo)
vecAngles.y += 45.0f; vecAngles.y += 45.0f;
// create a box to pack the stuff into. // create a box to pack the stuff into.
CWeaponBox *pWeaponBox = (CWeaponBox *)CBaseEntity::Create("weaponbox", pPlayer->pev->origin + dir, vecAngles, ENT(pPlayer->pev)); CreateWeaponBox(pItem, pPlayer,
modelName,
// don't let weaponbox tilt. pPlayer->pev->origin + dir,
pWeaponBox->pev->angles.x = 0; vecAngles,
pWeaponBox->pev->angles.z = 0; pPlayer->pev->velocity * 0.75f,
CGameRules::GetItemKillDelay(),
pWeaponBox->pev->velocity = pPlayer->pev->velocity * 0.75f; packAmmo);
pWeaponBox->SetThink(&CWeaponBox::Kill);
pWeaponBox->pev->nextthink = gpGlobals->time + CGameRules::GetItemKillDelay();
pWeaponBox->PackWeapon(pItem); // now pack all of the items in the lists
// pack the ammo
if (packAmmo)
{
pWeaponBox->PackAmmo(MAKE_STRING(pItem->pszAmmo1()), pPlayer->m_rgAmmo[pItem->PrimaryAmmoIndex()]);
}
pWeaponBox->SetModel(modelName);
} }
} }
#endif #endif
@ -7838,13 +7851,12 @@ CBaseEntity *EXT_FUNC CBasePlayer::__API_HOOK(DropPlayerItem)(const char *pszIte
} }
} }
CWeaponBox *pWeaponBox = (CWeaponBox *)CBaseEntity::Create("weaponbox", pev->origin + gpGlobals->v_forward * 10, pev->angles, edict()); const char *modelname = GetCSModelName(pWeapon->m_iId);
pWeaponBox->pev->angles.x = 0; CWeaponBox *pWeaponBox = CreateWeaponBox(pWeapon, this, modelname, pev->origin + gpGlobals->v_forward * 10, pev->angles, gpGlobals->v_forward * 300 + gpGlobals->v_forward * 100, CGameRules::GetItemKillDelay(), false);
pWeaponBox->pev->angles.z = 0; if (!pWeaponBox)
pWeaponBox->SetThink(&CWeaponBox::Kill); {
pWeaponBox->pev->nextthink = gpGlobals->time + CGameRules::GetItemKillDelay(); return nullptr;
pWeaponBox->PackWeapon(pWeapon); }
pWeaponBox->pev->velocity = gpGlobals->v_forward * 300 + gpGlobals->v_forward * 100;
if (FClassnameIs(pWeapon->pev, "weapon_c4")) if (FClassnameIs(pWeapon->pev, "weapon_c4"))
{ {
@ -7860,27 +7872,6 @@ CBaseEntity *EXT_FUNC CBasePlayer::__API_HOOK(DropPlayerItem)(const char *pszIte
} }
} }
if (pWeapon->iFlags() & ITEM_FLAG_EXHAUSTIBLE)
{
int iAmmoIndex = GetAmmoIndex(pWeapon->pszAmmo1());
if (iAmmoIndex != -1)
{
#ifdef REGAMEDLL_FIXES
// why not pack the ammo more than one?
pWeaponBox->PackAmmo(MAKE_STRING(pWeapon->pszAmmo1()), m_rgAmmo[iAmmoIndex]);
#else
pWeaponBox->PackAmmo(MAKE_STRING(pWeapon->pszAmmo1()), m_rgAmmo[iAmmoIndex] > 0);
#endif
m_rgAmmo[iAmmoIndex] = 0;
}
}
const char *modelname = GetCSModelName(pWeapon->m_iId);
if (modelname)
{
pWeaponBox->SetModel(modelname);
}
return pWeaponBox; return pWeaponBox;
} }

View File

@ -887,6 +887,9 @@ public:
#endif #endif
}; };
CWeaponBox *CreateWeaponBox(CBasePlayerItem *pItem, CBasePlayer *pPlayerOwner, const char *modelName, const Vector &origin, const Vector &angles, const Vector &velocity, float lifeTime, bool packAmmo);
CWeaponBox *CreateWeaponBox_OrigFunc(CBasePlayerItem *pItem, CBasePlayer *pPlayerOwner, const char *modelName, const Vector &origin, const Vector &angles, const Vector &velocity, float lifeTime, bool packAmmo);
class CWShield: public CBaseEntity class CWShield: public CBaseEntity
{ {
public: public:

View File

@ -38,7 +38,7 @@
#include <API/CSInterfaces.h> #include <API/CSInterfaces.h>
#define REGAMEDLL_API_VERSION_MAJOR 5 #define REGAMEDLL_API_VERSION_MAJOR 5
#define REGAMEDLL_API_VERSION_MINOR 14 #define REGAMEDLL_API_VERSION_MINOR 15
// CBasePlayer::Spawn hook // CBasePlayer::Spawn hook
typedef IHookChainClass<void, class CBasePlayer> IReGameHook_CBasePlayer_Spawn; typedef IHookChainClass<void, class CBasePlayer> IReGameHook_CBasePlayer_Spawn;
@ -464,6 +464,10 @@ typedef IHookChainRegistryClass<bool, class CBasePlayerWeapon, int, int, float,
typedef IHookChainClass<void, CBasePlayer, const char *> IReGameHook_CBasePlayer_DropIdlePlayer; typedef IHookChainClass<void, CBasePlayer, const char *> IReGameHook_CBasePlayer_DropIdlePlayer;
typedef IHookChainRegistryClass<void, CBasePlayer, const char *> IReGameHookRegistry_CBasePlayer_DropIdlePlayer; typedef IHookChainRegistryClass<void, CBasePlayer, const char *> IReGameHookRegistry_CBasePlayer_DropIdlePlayer;
// CreateWeaponBox hook
typedef IHookChain<class CWeaponBox *, class CBasePlayerItem *, class CBasePlayer *, const char *, const Vector &, const Vector &, const Vector &, float, bool> IReGameHook_CreateWeaponBox;
typedef IHookChainRegistry<class CWeaponBox *, class CBasePlayerItem *, class CBasePlayer *, const char *, const Vector &, const Vector &, const Vector &, float, bool> IReGameHookRegistry_CreateWeaponBox;
class IReGameHookchains { class IReGameHookchains {
public: public:
virtual ~IReGameHookchains() {} virtual ~IReGameHookchains() {}
@ -579,6 +583,7 @@ public:
virtual IReGameHookRegistry_CBasePlayerWeapon_DefaultReload *CBasePlayerWeapon_DefaultReload() = 0; virtual IReGameHookRegistry_CBasePlayerWeapon_DefaultReload *CBasePlayerWeapon_DefaultReload() = 0;
virtual IReGameHookRegistry_CBasePlayerWeapon_DefaultShotgunReload *CBasePlayerWeapon_DefaultShotgunReload() = 0; virtual IReGameHookRegistry_CBasePlayerWeapon_DefaultShotgunReload *CBasePlayerWeapon_DefaultShotgunReload() = 0;
virtual IReGameHookRegistry_CBasePlayer_DropIdlePlayer *CBasePlayer_DropIdlePlayer() = 0; virtual IReGameHookRegistry_CBasePlayer_DropIdlePlayer *CBasePlayer_DropIdlePlayer() = 0;
virtual IReGameHookRegistry_CreateWeaponBox *CreateWeaponBox() = 0;
}; };
struct ReGameFuncs_t { struct ReGameFuncs_t {