2
0
mirror of https://github.com/rehlds/reapi.git synced 2024-12-28 15:45:31 +03:00

Added native rg_instant_reload_weapons

Added forward CBasePlayer_SetClientUserInfoName
This commit is contained in:
s1lentq 2016-06-03 22:44:48 +06:00 committed by asmodai
parent 8db34b7a52
commit bbd489e34c
10 changed files with 87 additions and 26 deletions

View File

@ -24,7 +24,7 @@ task publishPrepareFiles << {
//project.file('publish/publishRoot/reapi/addons/amxmodx/scripting/include').mkdirs()
_copyFileToDir('publish/reapi_amxx.dll', 'publish/publishRoot/reapi/addons/amxmodx/modules/')
_copyFileToDir('publish/reapi_amxx.pdb', 'publish/publishRoot/reapi/addons/amxmodx/modules/')
//_copyFileToDir('publish/reapi_amxx.pdb', 'publish/publishRoot/reapi/addons/amxmodx/modules/')
_copyFile('publish/libreapi_amxx_i386.so', 'publish/publishRoot/reapi/addons/amxmodx/modules/reapi_amxx_i386.so')
copy {

View File

@ -403,3 +403,14 @@ native rg_reset_user_model(const index);
*
*/
native rg_transfer_c4(const index, const receiver = 0);
/*
* Instant reload weapons
*
* @param index Client index
* @param weapon Entity weapons, if 0 then all the weapons
*
* @return 1 if successfully, 0 otherwise
*
*/
native rg_instant_reload_weapons(const index, const weapon = 0);

View File

@ -24,6 +24,7 @@
#define RG_CSGameRules_CheckMapConditions RG_CSGameRules_CheckMapCond
#define RG_CSGameRules_CheckWinConditions RG_CSGameRules_CheckWinCond
#define RG_CBasePlayer_SetClientUserInfoModel RG_CBasePlayer_SetUserInfoModel
#define RG_CBasePlayer_SetClientUserInfoName RG_CBasePlayer_SetUserInfoName
#endif
enum AccountSet { AS_SET, AS_ADD };
@ -361,6 +362,12 @@ enum GamedllFunc_CBasePlayer
*/
RG_CBasePlayer_SetClientUserInfoModel,
/*
* Description: -
* Params: (const this, infobuffer[], szNewName[])
*/
RG_CBasePlayer_SetClientUserInfoName,
/*
* Description: -
* Params: (const this, iPlayerIndex, bool:bSameTeam)

View File

@ -30,6 +30,8 @@
#include "regamedll_interfaces.h"
#include "hookchains.h"
#include "interface.h"
#include "player.h"
#include "gamerules.h"
#define REGAMEDLL_API_VERSION_MAJOR 2
#define REGAMEDLL_API_VERSION_MINOR 1
@ -140,8 +142,8 @@ typedef IVoidHookChain<const char *> IReGameHook_CBasePlayer_GiveNamedItem;
typedef IVoidHookChainRegistryClass<class CBasePlayer, const char *> IReGameHookRegistry_CBasePlayer_GiveNamedItem;
// CBasePlayer::AddAccount hook
typedef IVoidHookChain<int, enum RewardType, bool> IReGameHook_CBasePlayer_AddAccount;
typedef IVoidHookChainRegistryClass<class CBasePlayer, int, enum RewardType, bool> IReGameHookRegistry_CBasePlayer_AddAccount;
typedef IVoidHookChain<int, RewardType, bool> IReGameHook_CBasePlayer_AddAccount;
typedef IVoidHookChainRegistryClass<class CBasePlayer, int, RewardType, bool> IReGameHookRegistry_CBasePlayer_AddAccount;
// CBasePlayer::GiveShield hook
typedef IVoidHookChain<bool> IReGameHook_CBasePlayer_GiveShield;
@ -151,6 +153,9 @@ typedef IVoidHookChainRegistryClass<class CBasePlayer, bool> IReGameHookRegistry
typedef IVoidHookChain<char *, char *> IReGameHook_CBasePlayer_SetClientUserInfoModel;
typedef IVoidHookChainRegistryClass<class CBasePlayer, char *, char *> IReGameHookRegistry_CBasePlayer_SetClientUserInfoModel;
// CBasePlayer:SetClientUserInfoName hook
typedef IVoidHookChain<char *, char *> IReGameHook_CBasePlayer_SetClientUserInfoName;
typedef IVoidHookChainRegistryClass<class CBasePlayer, char *, char *> IReGameHookRegistry_CBasePlayer_SetClientUserInfoName;
// CBaseAnimating::ResetSequenceInfo hook
typedef IVoidHookChain<> IReGameHook_CBaseAnimating_ResetSequenceInfo;
@ -173,8 +178,8 @@ typedef IVoidHookChain<class CBasePlayer *, struct entvars_s *, struct entvars_s
typedef IVoidHookChainRegistry<class CBasePlayer *, struct entvars_s *, struct entvars_s *, Vector &, Vector &, struct TraceResult *> IReGameHookRegistry_RadiusFlash_TraceLine;
// RoundEnd hook
typedef IHookChain<bool, int, enum ScenarioEventEndRound, float> IReGameHook_RoundEnd;
typedef IHookChainRegistry<bool, int, enum ScenarioEventEndRound, float> IReGameHookRegistry_RoundEnd;
typedef IHookChain<bool, int, ScenarioEventEndRound, float> IReGameHook_RoundEnd;
typedef IHookChainRegistry<bool, int, ScenarioEventEndRound, float> IReGameHookRegistry_RoundEnd;
// CanBuyThis hook
typedef IHookChain<bool, class CBasePlayer *, int> IReGameHook_CanBuyThis;
@ -373,6 +378,8 @@ public:
virtual IReGameHookRegistry_CSGameRules_GoToIntermission* CSGameRules_GoToIntermission() = 0;
virtual IReGameHookRegistry_CSGameRules_BalanceTeams* CSGameRules_BalanceTeams() = 0;
// later sort them on the positions and change the major version
virtual IReGameHookRegistry_CBasePlayer_SetClientUserInfoName* CBasePlayer_SetClientUserInfoName() = 0;
};
struct ReGameFuncs_t {

View File

@ -73,7 +73,10 @@ public:
virtual void SetProgressBarTime(int time);
virtual void SetProgressBarTime2(int time, float timeElapsed);
virtual struct edict_s *EntSelectSpawnPoint();
virtual void SetBombIcon(bool bFlash = false);
virtual void SetScoreAttrib(CBasePlayer *dest);
virtual void SendItemStatus();
virtual void ReloadWeapons(CBasePlayerItem *pWeapon = nullptr);
CBasePlayer *BasePlayer() const;
public:

View File

@ -644,6 +644,16 @@ void CBasePlayer_SetClientUserInfoModel(IReGameHook_CBasePlayer_SetClientUserInf
callVoidForward(RG_CBasePlayer_SetClientUserInfoModel, original, indexOfEdict(pthis->pev), infobuffer, szNewModel);
}
void CBasePlayer_SetClientUserInfoName(IReGameHook_CBasePlayer_SetClientUserInfoName *chain, CBasePlayer *pthis, char *infobuffer, char *szNewName)
{
auto original = [chain](int _pthis, char *_infobuffer, char *_szNewName)
{
chain->callNext(_infobuffer, _szNewName);
};
callVoidForward(RG_CBasePlayer_SetClientUserInfoName, original, indexOfEdict(pthis->pev), infobuffer, szNewName);
}
void HandleMenu_ChooseAppearance(IReGameHook_HandleMenu_ChooseAppearance *chain, CBasePlayer *pPlayer, int slot)
{
auto original = [chain](int _pPlayer, int _slot)

View File

@ -271,6 +271,8 @@ void CSGameRules_GoToIntermission(IReGameHook_CSGameRules_GoToIntermission *chai
void CSGameRules_BalanceTeams(IReGameHook_CSGameRules_BalanceTeams *chain);
void CBasePlayer_SetClientUserInfoModel(IReGameHook_CBasePlayer_SetClientUserInfoModel *chain, CBasePlayer *pthis, char *infobuffer, char *szNewModel);
void CBasePlayer_SetClientUserInfoName(IReGameHook_CBasePlayer_SetClientUserInfoName *chain, CBasePlayer *pthis, char *infobuffer, char *szNewName);
void HandleMenu_ChooseAppearance(IReGameHook_HandleMenu_ChooseAppearance *chain, CBasePlayer *pPlayer, int slot);
BOOL HandleMenu_ChooseTeam(IReGameHook_HandleMenu_ChooseTeam *chain, CBasePlayer *pPlayer, int slot);
void ShowMenu(IReGameHook_ShowMenu *chain, CBasePlayer *pPlayer, int bitsValidSlots, int nDisplayTime, BOOL fNeedMore, char *pszText);

View File

@ -113,6 +113,7 @@ hook_t hooklist_player[] = {
DLL(CBasePlayer_RoundRespawn),
DLL(CBasePlayer_Blind),
DLL(CBasePlayer_SetClientUserInfoModel),
DLL(CBasePlayer_SetClientUserInfoName),
DLL(CBasePlayer_Observer_IsValidTarget),
DLL(CBasePlayer_SetAnimation),

View File

@ -131,6 +131,7 @@ enum GamedllFunc_CBasePlayer
RG_CBasePlayer_Blind,
RG_CBasePlayer_SetClientUserInfoModel,
RG_CBasePlayer_SetClientUserInfoName,
RG_CBasePlayer_Observer_IsValidTarget,
RG_CBasePlayer_SetAnimation,
RG_CBasePlayer_GiveDefaultItems,

View File

@ -978,12 +978,8 @@ cell AMX_NATIVE_CALL rg_set_user_team(AMX *amx, cell *params)
if (CSGameRules()->m_iNumTerrorist > 0 && pPlayer->CSPlayer()->RemovePlayerItem("weapon_c4")) {
pPlayer->m_bHasC4 = false;
pPlayer->pev->body = 0;
MESSAGE_BEGIN(MSG_ONE, gmsgStatusIcon, NULL, pPlayer->pev);
WRITE_BYTE(STATUSICON_HIDE);
WRITE_STRING("c4");
MESSAGE_END();
pPlayer->CSPlayer()->SetBombIcon();
pPlayer->CSPlayer()->SetProgressBarTime(0);
CSGameRules()->GiveC4();
} else if (pPlayer->IsAlive()) {// are still alive
pPlayer->CSPlayer()->DropPlayerItem("weapon_c4");
@ -1121,13 +1117,10 @@ cell AMX_NATIVE_CALL rg_transfer_c4(AMX *amx, cell *params)
if (!pPlayer->m_bHasC4 || !pPlayer->CSPlayer()->RemovePlayerItem("weapon_c4"))
return FALSE;
pPlayer->m_bHasC4 = false;
pPlayer->pev->body = 0;
MESSAGE_BEGIN(MSG_ONE, gmsgStatusIcon, NULL, pPlayer->pev);
WRITE_BYTE(STATUSICON_HIDE);
WRITE_STRING("c4");
MESSAGE_END();
pPlayer->m_bHasC4 = false;
pPlayer->CSPlayer()->SetBombIcon();
pPlayer->CSPlayer()->SetProgressBarTime(0);
if (params[arg_receiver] != 0 && params[arg_receiver] <= gpGlobals->maxClients) {
CBasePlayer *pReceiver = g_ReGameFuncs->UTIL_PlayerByIndex(params[arg_receiver]);
@ -1137,16 +1130,9 @@ cell AMX_NATIVE_CALL rg_transfer_c4(AMX *amx, cell *params)
}
pReceiver->m_bHasC4 = true;
pReceiver->pev->body = 1;
pReceiver->CSPlayer()->GiveNamedItemEx("weapon_c4");
MESSAGE_BEGIN(MSG_ONE, gmsgStatusIcon, NULL, pReceiver->pev);
WRITE_BYTE(STATUSICON_SHOW);
WRITE_STRING("c4");
WRITE_BYTE(0);
WRITE_BYTE(160);
WRITE_BYTE(0);
MESSAGE_END();
pReceiver->CSPlayer()->SetBombIcon();
pReceiver->pev->body = 1;
} else {
auto flags = pPlayer->pev->flags;
pPlayer->pev->flags |= FL_DORMANT;
@ -1157,6 +1143,38 @@ cell AMX_NATIVE_CALL rg_transfer_c4(AMX *amx, cell *params)
return TRUE;
}
/*
* Instant reload weapons
*
* @param index Client index
* @param weapon Entity weapons, if 0 then all the weapons
*
* @return 1 if successfully, 0 otherwise
*
* native rg_instant_reload_weapons(const index, const weapon = 0);
*/
cell AMX_NATIVE_CALL rg_instant_reload_weapons(AMX *amx, cell *params)
{
enum args_e { arg_count, arg_index, arg_weapon };
CHECK_ISPLAYER(arg_index);
CBasePlayer *pPlayer = g_ReGameFuncs->UTIL_PlayerByIndex(params[arg_index]);
if (pPlayer == nullptr || pPlayer->has_disconnected) {
MF_LogError(amx, AMX_ERR_NATIVE, "%s: player %i is not connected", __FUNCTION__, params[arg_index]);
return FALSE;
}
auto pWeapon = getPrivate<CBasePlayerWeapon>(params[arg_weapon]);
if (params[arg_weapon] != 0 && pWeapon == nullptr) {
MF_LogError(amx, AMX_ERR_NATIVE, "%s: Invalid entity weapon", __FUNCTION__);
return FALSE;
}
pPlayer->CSPlayer()->ReloadWeapons(pWeapon);
return TRUE;
}
AMX_NATIVE_INFO Misc_Natives_RG[] =
{
{ "rg_set_animation", rg_set_animation },
@ -1200,6 +1218,7 @@ AMX_NATIVE_INFO Misc_Natives_RG[] =
{ "rg_reset_user_model", rg_reset_user_model },
{ "rg_transfer_c4", rg_transfer_c4 },
{ "rg_instant_reload_weapons", rg_instant_reload_weapons },
{ nullptr, nullptr }
};