Skip to content

Implement PlayerGotItem Hook #351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,12 @@ enum GamedllFunc_CSGameRules
* Params: (const pKiller, const pVictim, const pAssister, const pevInflictor, const killerWeaponName[], const DeathMessageFlags:iDeathMessageFlags, const KillRarity:iRarityOfKill)
*/
RG_CSGameRules_SendDeathMessage,

/*
* Description: Called when a player picks up an item.
* Params: (const pPlayer, const pItem)
*/
RG_CSGameRules_PlayerGotItem,
};

/**
Expand Down
7 changes: 6 additions & 1 deletion reapi/include/cssdk/dlls/regamedll_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include <API/CSInterfaces.h>

#define REGAMEDLL_API_VERSION_MAJOR 5
#define REGAMEDLL_API_VERSION_MINOR 30
#define REGAMEDLL_API_VERSION_MINOR 31

// CBasePlayer::Spawn hook
typedef IHookChainClass<void, class CBasePlayer> IReGameHook_CBasePlayer_Spawn;
Expand Down Expand Up @@ -638,6 +638,10 @@ typedef IHookChainRegistryClass<void, class CBasePlayer> IReGameHookRegistry_CBa
typedef IHookChainClass<void, class CBasePlayer, class CBasePlayer *, float, float> IReGameHook_CBasePlayer_TakeDamageImpulse;
typedef IHookChainRegistryClass<void, class CBasePlayer, class CBasePlayer *, float, float> IReGameHookRegistry_CBasePlayer_TakeDamageImpulse;

// CHalfLifeMultiplay::PlayerGotItem hook
typedef IHookChain<void, CBasePlayer *, CItem *> IReGameHook_CSGameRules_PlayerGotItem;
typedef IHookChainRegistry<void, CBasePlayer *, CItem *> IReGameHookRegistry_CSGameRules_PlayerGotItem;

class IReGameHookchains {
public:
virtual ~IReGameHookchains() {}
Expand Down Expand Up @@ -802,6 +806,7 @@ class IReGameHookchains {
virtual IReGameHookRegistry_CBasePlayer_RemoveAllItems *CBasePlayer_RemoveAllItems() = 0;
virtual IReGameHookRegistry_CBasePlayer_UpdateStatusBar *CBasePlayer_UpdateStatusBar() = 0;
virtual IReGameHookRegistry_CBasePlayer_TakeDamageImpulse *CBasePlayer_TakeDamageImpulse() = 0;
virtual IReGameHookRegistry_CSGameRules_PlayerGotItem *CSGameRules_PlayerGotItem() = 0;
};

struct ReGameFuncs_t {
Expand Down
10 changes: 10 additions & 0 deletions reapi/src/hook_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1786,6 +1786,16 @@ void CBasePlayer_TakeDamageImpulse(IReGameHook_CBasePlayer_TakeDamageImpulse *ch
callVoidForward(RG_CBasePlayer_TakeDamageImpulse, original, indexOfEdict(pthis->pev), indexOfEdict(pAttacker->pev), flKnockbackForce, flVelModifier);
}

void CSGameRules_PlayerGotItem(IReGameHook_CSGameRules_PlayerGotItem *chain, CBasePlayer *pPlayer, CItem *pItem)
{
auto original = [chain](int _pPlayer, int _pItem)
{
chain->callNext(getPrivate<CBasePlayer>(_pPlayer), getPrivate<CItem>(_pItem));
};

callVoidForward(RG_CSGameRules_PlayerGotItem, original, indexOfEdict(pPlayer->pev), indexOfEdict(pItem->pev));
}

/*
* VTC functions
*/
Expand Down
1 change: 1 addition & 0 deletions reapi/src/hook_callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ void CBasePlayer_RemoveAllItems(IReGameHook_CBasePlayer_RemoveAllItems *chain, C
void CSGameRules_SendDeathMessage(IReGameHook_CSGameRules_SendDeathMessage *chain, CBaseEntity *pKiller, CBasePlayer *pVictim, CBasePlayer *pAssister, entvars_t *pevInflictor, const char *killerWeaponName, int iDeathMessageFlags, int iRarityOfKill);
void CBasePlayer_UpdateStatusBar(IReGameHook_CBasePlayer_UpdateStatusBar *chain, CBasePlayer *pthis);
void CBasePlayer_TakeDamageImpulse(IReGameHook_CBasePlayer_TakeDamageImpulse *chain, CBasePlayer *pthis, CBasePlayer *pAttacker, float flKnockbackForce, float flVelModifier);
void CSGameRules_PlayerGotItem(IReGameHook_CSGameRules_PlayerGotItem *chain, CBasePlayer *pPlayer, CItem *pItem);

/*
* VTC functions
Expand Down
1 change: 1 addition & 0 deletions reapi/src/hook_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ hook_t hooklist_gamerules[] = {
DLL(CSGameRules_TeamStacked),
DLL(CSGameRules_PlayerGotWeapon),
DLL(CSGameRules_SendDeathMessage),
DLL(CSGameRules_PlayerGotItem),
};

hook_t hooklist_grenade[] = {
Expand Down
1 change: 1 addition & 0 deletions reapi/src/hook_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ enum GamedllFunc_CSGameRules
RG_CSGameRules_TeamStacked,
RG_CSGameRules_PlayerGotWeapon,
RG_CSGameRules_SendDeathMessage,
RG_CSGameRules_PlayerGotItem,

// [...]
};
Expand Down
2 changes: 1 addition & 1 deletion reapi/version/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
#pragma once

#define VERSION_MAJOR 5
#define VERSION_MINOR 29
#define VERSION_MINOR 30
#define VERSION_MAINTENANCE 0