2
0
mirror of https://github.com/rehlds/reapi.git synced 2025-03-13 05:50:16 +03:00

Added natives rh_set_mapname, rh_get_mapname, rh_reset_mapname

This commit is contained in:
s1lentq 2016-06-02 04:37:29 +06:00 committed by asmodai
parent 6f519c7551
commit fd7c58f32e
13 changed files with 210 additions and 49 deletions

View File

@ -17,3 +17,34 @@ native set_entvar(const index, const EntVars:var, any:...);
* Use the var_* EntVars enum * Use the var_* EntVars enum
*/ */
native any:get_entvar(const index, const EntVars:var, any:...); native any:get_entvar(const index, const EntVars:var, any:...);
/*
* Set name of the map
*
* @param mapname Change the name of the map.
*
* @noreturn
*
*/
native rh_set_mapname(const mapname[]);
/*
* Get name of the map
*
* @param output Buffer to copy mapname to
* @param len Maximum buffer size
* @param type MNT_SET return the name of the current map
* MNT_TRUE return true the name of the current map independently of the set via rh_set_mapname
*
* @noreturn
*
*/
native rh_get_mapname(output[], len, MapNameType:type = MNT_SET);
/*
* Reset to true map name
*
* @noreturn
*
*/
native rh_reset_mapname();

View File

@ -4,6 +4,9 @@
#define _reapi_engine_const_included #define _reapi_engine_const_included
// for natives rh_get_mapname
enum MapNameType { MNT_TRUE, MNT_SET };
enum EngineFunc enum EngineFunc
{ {
/* /*

View File

@ -30,13 +30,68 @@ enum AccountSet { AS_SET, AS_ADD };
// Weapon info types for use with rg_get_weapon_info() // Weapon info types for use with rg_get_weapon_info()
enum WpnInfo enum WpnInfo
{ {
/*
* Description: -
* Return type: enum WeaponIdType
* Get params: rg_get_weapon_info(const weapon_name[], WI_ID);
* Set params: -
*/
WI_ID, WI_ID,
/*
* Description: -
* Return type: int
* Get params: rg_get_weapon_info(const weapon_id, WI_COST);
* Set params: rg_set_weapon_info(const weapon_id, WI_COST, const value);
*/
WI_COST, WI_COST,
/*
* Description: -
* Return type: int
* Get params: rg_get_weapon_info(const weapon_id, WI_CLIP_COST);
* Set params: rg_set_weapon_info(const weapon_id, WI_CLIP_COST, const value);
*/
WI_CLIP_COST, WI_CLIP_COST,
/*
* Description: -
* Return type: int
* Get params: rg_get_weapon_info(const weapon_id, WI_BUY_CLIP_SIZE);
* Set params: -
*/
WI_BUY_CLIP_SIZE, WI_BUY_CLIP_SIZE,
/*
* Description: -
* Return type: int
* Get params: rg_get_weapon_info(const weapon_id, WI_GUN_CLIP_SIZE);
* Set params: -
*/
WI_GUN_CLIP_SIZE, WI_GUN_CLIP_SIZE,
/*
* Description: -
* Return type: int
* Get params: rg_get_weapon_info(const weapon_id, WI_MAX_ROUNDS);
* Set params: -
*/
WI_MAX_ROUNDS, WI_MAX_ROUNDS,
/*
* Description: -
* Return type: int
* Get params: rg_get_weapon_info(const weapon_id, WI_AMMO_TYPE);
* Set params: -
*/
WI_AMMO_TYPE, WI_AMMO_TYPE,
/*
* Description: -
* Return type: -
* Get params: rg_get_weapon_info(const weapon_id, WI_NAME, const output[], maxlenght);
* Set params: -
*/
WI_NAME WI_NAME
}; };

View File

@ -65,9 +65,15 @@ public:
virtual void DropPlayerItem(const char *pszItemName); virtual void DropPlayerItem(const char *pszItemName);
virtual void RemoveShield(); virtual void RemoveShield();
virtual void RemoveAllItems(bool bRemoveSuit); virtual void RemoveAllItems(bool bRemoveSuit);
virtual bool RemovePlayerItem(const char* pszItemName);
virtual void SetPlayerModel(bool bHasC4); virtual void SetPlayerModel(bool bHasC4);
virtual void SetPlayerModelEx(const char *modelName); virtual void SetPlayerModelEx(const char *modelName);
virtual void SetNewPlayerModel(const char *modelName); virtual void SetNewPlayerModel(const char *modelName);
virtual void ClientCommand(const char *cmd, const char *arg1 = nullptr, const char *arg2 = nullptr, const char *arg3 = nullptr);
virtual void SetProgressBarTime(int time);
virtual void SetProgressBarTime2(int time, float timeElapsed);
virtual struct edict_s *EntSelectSpawnPoint();
virtual void SendItemStatus();
CBasePlayer *BasePlayer() const; CBasePlayer *BasePlayer() const;
public: public:

View File

@ -35,7 +35,7 @@
#include "model.h" #include "model.h"
#define REHLDS_API_VERSION_MAJOR 2 #define REHLDS_API_VERSION_MAJOR 2
#define REHLDS_API_VERSION_MINOR 11 #define REHLDS_API_VERSION_MINOR 12
//Steam_NotifyClientConnect hook //Steam_NotifyClientConnect hook
typedef IHookChain<qboolean, IGameClient*, const void*, unsigned int> IRehldsHook_Steam_NotifyClientConnect; typedef IHookChain<qboolean, IGameClient*, const void*, unsigned int> IRehldsHook_Steam_NotifyClientConnect;
@ -181,6 +181,10 @@ typedef IVoidHookChainRegistry<IGameClient *, struct usercmd_s *, int, int, int>
typedef IVoidHookChain<> IRehldsHook_SV_Spawn_f; typedef IVoidHookChain<> IRehldsHook_SV_Spawn_f;
typedef IVoidHookChainRegistry<> IRehldsHookRegistry_SV_Spawn_f; typedef IVoidHookChainRegistry<> IRehldsHookRegistry_SV_Spawn_f;
//SV_CreatePacketEntities hook
typedef IHookChain<int, enum sv_delta_s, IGameClient *, struct packet_entities_s *, struct sizebuf_s *> IRehldsHook_SV_CreatePacketEntities;
typedef IHookChainRegistry<int, enum sv_delta_s, IGameClient *, struct packet_entities_s *, struct sizebuf_s *> IRehldsHookRegistry_SV_CreatePacketEntities;
class IRehldsHookchains { class IRehldsHookchains {
public: public:
virtual ~IRehldsHookchains() { } virtual ~IRehldsHookchains() { }
@ -221,6 +225,7 @@ public:
virtual IRehldsHookRegistry_Cvar_DirectSet* Cvar_DirectSet() = 0; virtual IRehldsHookRegistry_Cvar_DirectSet* Cvar_DirectSet() = 0;
virtual IRehldsHookRegistry_SV_EstablishTimeBase* SV_EstablishTimeBase() = 0; virtual IRehldsHookRegistry_SV_EstablishTimeBase* SV_EstablishTimeBase() = 0;
virtual IRehldsHookRegistry_SV_Spawn_f* SV_Spawn_f() = 0; virtual IRehldsHookRegistry_SV_Spawn_f* SV_Spawn_f() = 0;
virtual IRehldsHookRegistry_SV_CreatePacketEntities* SV_CreatePacketEntities() = 0;
}; };
struct RehldsFuncs_t { struct RehldsFuncs_t {
@ -283,4 +288,4 @@ public:
virtual IRehldsFlightRecorder* GetFlightRecorder() = 0; virtual IRehldsFlightRecorder* GetFlightRecorder() = 0;
}; };
#define VREHLDS_HLDS_API_VERSION "VREHLDS_HLDS_API_VERSION001" #define VREHLDS_HLDS_API_VERSION "VREHLDS_HLDS_API_VERSION001"

View File

@ -126,4 +126,7 @@ public:
virtual double GetTime() = 0; virtual double GetTime() = 0;
virtual void SetResourcesNum(int num) = 0; virtual void SetResourcesNum(int num) = 0;
virtual struct resource_s *GetResource(int index) = 0; virtual struct resource_s *GetResource(int index) = 0;
virtual void SetName(const char* name) = 0;
virtual class ISteamGameServer *GetSteamGameServer() = 0;
virtual struct netadr_s *GetNetFrom() = 0;
}; };

View File

@ -1,6 +1,7 @@
#include "precompiled.h" #include "precompiled.h"
edict_t* g_pEdicts; edict_t* g_pEdicts;
char g_szMapName[32];
int gmsgSendAudio, gmsgTeamScore, gmsgStatusIcon, gmsgArmorType, gmsgTeamInfo, gmsgItemStatus; int gmsgSendAudio, gmsgTeamScore, gmsgStatusIcon, gmsgArmorType, gmsgTeamInfo, gmsgItemStatus;
struct struct
@ -67,8 +68,22 @@ CGameRules *InstallGameRules(IReGameHook_InstallGameRules *chain)
int DispatchSpawn(edict_t* pEntity) int DispatchSpawn(edict_t* pEntity)
{ {
// save true mapname
strncpy(g_szMapName, STRING(gpGlobals->mapname), sizeof(g_szMapName) - 1);
g_szMapName[sizeof(g_szMapName) - 1] = '\0';
g_pEdicts = g_engfuncs.pfnPEntityOfEntIndex(0); g_pEdicts = g_engfuncs.pfnPEntityOfEntIndex(0);
g_pFunctionTable->pfnSpawn = nullptr; g_pFunctionTable->pfnSpawn = nullptr;
RETURN_META_VALUE(MRES_IGNORED, 0); RETURN_META_VALUE(MRES_IGNORED, 0);
} }
void ResetGlobalState()
{
// restore mapname
if (strcmp(g_RehldsData->GetName(), g_szMapName) != 0) {
g_RehldsData->SetName(g_szMapName);
g_pFunctionTable->pfnResetGlobalState = nullptr;
}
SET_META_RESULT(MRES_IGNORED);
}

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
extern char g_szMapName[32];
extern edict_t* g_pEdicts; extern edict_t* g_pEdicts;
extern int gmsgSendAudio; extern int gmsgSendAudio;
extern int gmsgTeamScore; extern int gmsgTeamScore;
@ -15,5 +16,6 @@ void OnMetaDetach();
void ServerActivate_Post(edict_t *pEdictList, int edictCount, int clientMax); void ServerActivate_Post(edict_t *pEdictList, int edictCount, int clientMax);
void ServerDeactivate_Post(); void ServerDeactivate_Post();
int DispatchSpawn(edict_t* pEntity); int DispatchSpawn(edict_t* pEntity);
void ResetGlobalState();
CGameRules *InstallGameRules(IReGameHook_InstallGameRules *chain); CGameRules *InstallGameRules(IReGameHook_InstallGameRules *chain);

View File

@ -2,6 +2,7 @@
IRehldsApi* g_RehldsApi; IRehldsApi* g_RehldsApi;
const RehldsFuncs_t* g_RehldsFuncs; const RehldsFuncs_t* g_RehldsFuncs;
IRehldsServerData* g_RehldsData;
IRehldsHookchains* g_RehldsHookchains; IRehldsHookchains* g_RehldsHookchains;
IRehldsServerStatic* g_RehldsSvs; IRehldsServerStatic* g_RehldsSvs;
@ -48,6 +49,7 @@ bool RehldsApi_Init()
} }
g_RehldsFuncs = g_RehldsApi->GetFuncs(); g_RehldsFuncs = g_RehldsApi->GetFuncs();
g_RehldsData = g_RehldsApi->GetServerData();
g_RehldsHookchains = g_RehldsApi->GetHookchains(); g_RehldsHookchains = g_RehldsApi->GetHookchains();
g_RehldsSvs = g_RehldsApi->GetServerStatic(); g_RehldsSvs = g_RehldsApi->GetServerStatic();

View File

@ -2,6 +2,7 @@
extern IRehldsApi* g_RehldsApi; extern IRehldsApi* g_RehldsApi;
extern const RehldsFuncs_t* g_RehldsFuncs; extern const RehldsFuncs_t* g_RehldsFuncs;
extern IRehldsServerData* g_RehldsData;
extern IRehldsHookchains* g_RehldsHookchains; extern IRehldsHookchains* g_RehldsHookchains;
extern IRehldsServerStatic* g_RehldsSvs; extern IRehldsServerStatic* g_RehldsSvs;

View File

@ -595,7 +595,7 @@ cell AMX_NATIVE_CALL rg_get_weapon_info(AMX *amx, cell *params)
return -1; return -1;
} }
// native rg_get_weapon_info(id, WPINFO_NAME, output[], maxlength); // native rg_get_weapon_info(id, WI_NAME, output[], maxlength);
cell* dest = getAmxAddr(amx, params[arg_3]); cell* dest = getAmxAddr(amx, params[arg_3]);
size_t length = *getAmxAddr(amx, params[arg_4]); size_t length = *getAmxAddr(amx, params[arg_4]);
@ -709,7 +709,7 @@ cell AMX_NATIVE_CALL rg_remove_item(AMX *amx, cell *params)
} }
const char* szItemName = getAmxString(amx, params[arg_item_name]); const char* szItemName = getAmxString(amx, params[arg_item_name]);
if (RemovePlayerItem(pPlayer, szItemName)) { if (pPlayer->CSPlayer()->RemovePlayerItem(szItemName)) {
return TRUE; return TRUE;
} }
@ -975,7 +975,7 @@ cell AMX_NATIVE_CALL rg_set_user_team(AMX *amx, cell *params)
CSGameRules()->m_iNumTerrorist--; CSGameRules()->m_iNumTerrorist--;
if (pPlayer->m_bHasC4 && !CSGameRules()->m_fTeamCount && CSGameRules()->m_bMapHasBombTarget) if (pPlayer->m_bHasC4 && !CSGameRules()->m_fTeamCount && CSGameRules()->m_bMapHasBombTarget)
{ {
if (CSGameRules()->m_iNumTerrorist > 0 && RemovePlayerItem(pPlayer, "weapon_c4")) { if (CSGameRules()->m_iNumTerrorist > 0 && pPlayer->CSPlayer()->RemovePlayerItem("weapon_c4")) {
pPlayer->m_bHasC4 = false; pPlayer->m_bHasC4 = false;
pPlayer->pev->body = 0; pPlayer->pev->body = 0;
@ -1001,7 +1001,7 @@ cell AMX_NATIVE_CALL rg_set_user_team(AMX *amx, cell *params)
WRITE_STRING("defuser"); WRITE_STRING("defuser");
MESSAGE_END(); MESSAGE_END();
SendItemStatus(pPlayer); pPlayer->CSPlayer()->SendItemStatus();
} }
break; break;
} }
@ -1118,7 +1118,7 @@ cell AMX_NATIVE_CALL rg_transfer_c4(AMX *amx, cell *params)
return FALSE; return FALSE;
} }
if (!pPlayer->m_bHasC4 || !RemovePlayerItem(pPlayer, "weapon_c4")) if (!pPlayer->m_bHasC4 || !pPlayer->CSPlayer()->RemovePlayerItem("weapon_c4"))
return FALSE; return FALSE;
pPlayer->m_bHasC4 = false; pPlayer->m_bHasC4 = false;
@ -1204,8 +1204,87 @@ AMX_NATIVE_INFO Misc_Natives_RG[] =
{ nullptr, nullptr } { nullptr, nullptr }
}; };
/*
* Set name of the map
*
* @param mapname Change the name of the map.
*
* @noreturn
*
* native rh_set_mapname(const mapname[]);
*/
cell AMX_NATIVE_CALL rh_set_mapname(AMX *amx, cell *params)
{
enum args_e { arg_count, arg_mapname };
const char *mapname = getAmxString(amx, params[arg_mapname]);
g_RehldsData->SetName(mapname);
g_pFunctionTable->pfnResetGlobalState = ResetGlobalState;
return TRUE;
}
enum MapNameType { MNT_TRUE, MNT_SET };
/*
* Get name of the map
*
* @param output Buffer to copy mapname to
* @param len Maximum buffer size
* @param type MNT_SET return the name of the current map
* MNT_TRUE return true the name of the current map independently of the set via rh_set_mapname
*
* @noreturn
*
* native rh_get_mapname(output[], len, MapNameType:type = MNT_SET);
*/
cell AMX_NATIVE_CALL rh_get_mapname(AMX *amx, cell *params)
{
enum args_e { arg_count, arg_output, arg_len, arg_type };
cell* dest = getAmxAddr(amx, params[arg_output]);
size_t length = *getAmxAddr(amx, params[arg_len]);
switch ((MapNameType)params[arg_type])
{
case MNT_TRUE:
setAmxString(dest, g_szMapName, length);
break;
case MNT_SET:
setAmxString(dest, g_RehldsData->GetName(), length);
break;
}
return TRUE;
}
/*
* Reset to true map name
*
* @noreturn
*
* native rh_reset_mapname();
*/
cell AMX_NATIVE_CALL rh_reset_mapname(AMX *amx, cell *params)
{
g_RehldsData->SetName(g_szMapName);
g_pFunctionTable->pfnResetGlobalState = nullptr;
return TRUE;
}
AMX_NATIVE_INFO Misc_Natives_RH[] =
{
{ "rh_set_mapname", rh_set_mapname },
{ "rh_get_mapname", rh_get_mapname },
{ "rh_reset_mapname", rh_reset_mapname },
{ nullptr, nullptr }
};
void RegisterNatives_Misc() void RegisterNatives_Misc()
{ {
if (api_cfg.hasReGameDLL()) if (api_cfg.hasReGameDLL())
g_amxxapi.AddNatives(Misc_Natives_RG); g_amxxapi.AddNatives(Misc_Natives_RG);
if (api_cfg.hasReHLDS())
g_amxxapi.AddNatives(Misc_Natives_RH);
} }

View File

@ -25,45 +25,6 @@ void UpdateTeamScores()
g_pengfuncsTable->pfnMessageEnd(); g_pengfuncsTable->pfnMessageEnd();
} }
bool RemovePlayerItem(CBasePlayer *pPlayer, const char* szItemName)
{
for (auto pItem : pPlayer->m_rgpPlayerItems) {
while (pItem != nullptr)
{
if (FClassnameIs(pItem->pev, szItemName))
{
CBasePlayerWeapon *pWeapon = static_cast<CBasePlayerWeapon *>(pItem);
if (pWeapon->IsWeapon()) {
pWeapon->RetireWeapon();
}
pPlayer->pev->weapons &= ~(1 << pItem->m_iId);
pPlayer->RemovePlayerItem(pItem);
pItem->Kill();
return true;
}
pItem = pItem->m_pNext;
}
}
return false;
}
void SendItemStatus(CBasePlayer *pPlayer)
{
int itemStatus = 0;
if (pPlayer->m_bHasNightVision)
itemStatus |= ITEM_STATUS_NIGHTVISION;
if (pPlayer->m_bHasDefuser)
itemStatus |= ITEM_STATUS_DEFUSER;
MESSAGE_BEGIN(MSG_ONE, gmsgItemStatus, NULL, pPlayer->pev);
WRITE_BYTE(itemStatus);
MESSAGE_END();
}
struct { struct {
TeamName team; TeamName team;
ModelName model; ModelName model;

View File

@ -119,8 +119,6 @@ inline const char *GetTeamName(TeamName team)
void Broadcast(const char *sentence); void Broadcast(const char *sentence);
void UpdateTeamScores(); void UpdateTeamScores();
bool RemovePlayerItem(CBasePlayer *pPlayer, const char* szItemName);
void SendItemStatus(CBasePlayer *pPlayer);
ModelName GetModelAuto(TeamName team); ModelName GetModelAuto(TeamName team);
extern void __declspec(noreturn) UTIL_SysError(const char *fmt, ...); extern void __declspec(noreturn) UTIL_SysError(const char *fmt, ...);