From fd7c58f32e0934dd96ea8f51a94961352dc0713a Mon Sep 17 00:00:00 2001 From: s1lentq Date: Thu, 2 Jun 2016 04:37:29 +0600 Subject: [PATCH] Added natives rh_set_mapname, rh_get_mapname, rh_reset_mapname --- .../scripting/include/reapi_engine.inc | 31 +++++++ .../scripting/include/reapi_engine_const.inc | 3 + .../scripting/include/reapi_gamedll_const.inc | 55 ++++++++++++ .../include/cssdk/dlls/regamedll_interfaces.h | 6 ++ reapi/include/cssdk/engine/rehlds_api.h | 9 +- .../include/cssdk/engine/rehlds_interfaces.h | 3 + reapi/src/main.cpp | 17 +++- reapi/src/main.h | 2 + reapi/src/mods/mod_rehlds_api.cpp | 2 + reapi/src/mods/mod_rehlds_api.h | 1 + reapi/src/natives/natives_misc.cpp | 89 +++++++++++++++++-- reapi/src/reapi_utils.cpp | 39 -------- reapi/src/reapi_utils.h | 2 - 13 files changed, 210 insertions(+), 49 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_engine.inc b/reapi/extra/amxmodx/scripting/include/reapi_engine.inc index ebf4ae1..ee5d0c8 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_engine.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_engine.inc @@ -17,3 +17,34 @@ native set_entvar(const index, const EntVars:var, any:...); * Use the var_* EntVars enum */ 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(); diff --git a/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc index cb734aa..7161dcf 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc @@ -4,6 +4,9 @@ #define _reapi_engine_const_included +// for natives rh_get_mapname +enum MapNameType { MNT_TRUE, MNT_SET }; + enum EngineFunc { /* diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc index f20028b..34ea479 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc @@ -30,13 +30,68 @@ enum AccountSet { AS_SET, AS_ADD }; // Weapon info types for use with rg_get_weapon_info() enum WpnInfo { + /* + * Description: - + * Return type: enum WeaponIdType + * Get params: rg_get_weapon_info(const weapon_name[], WI_ID); + * Set params: - + */ 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, + + /* + * 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, + + /* + * Description: - + * Return type: int + * Get params: rg_get_weapon_info(const weapon_id, WI_BUY_CLIP_SIZE); + * Set params: - + */ 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, + + /* + * Description: - + * Return type: int + * Get params: rg_get_weapon_info(const weapon_id, WI_MAX_ROUNDS); + * Set params: - + */ WI_MAX_ROUNDS, + + /* + * Description: - + * Return type: int + * Get params: rg_get_weapon_info(const weapon_id, WI_AMMO_TYPE); + * Set params: - + */ WI_AMMO_TYPE, + + /* + * Description: - + * Return type: - + * Get params: rg_get_weapon_info(const weapon_id, WI_NAME, const output[], maxlenght); + * Set params: - + */ WI_NAME }; diff --git a/reapi/include/cssdk/dlls/regamedll_interfaces.h b/reapi/include/cssdk/dlls/regamedll_interfaces.h index 888e1e2..5945a10 100644 --- a/reapi/include/cssdk/dlls/regamedll_interfaces.h +++ b/reapi/include/cssdk/dlls/regamedll_interfaces.h @@ -65,9 +65,15 @@ public: virtual void DropPlayerItem(const char *pszItemName); virtual void RemoveShield(); virtual void RemoveAllItems(bool bRemoveSuit); + virtual bool RemovePlayerItem(const char* pszItemName); virtual void SetPlayerModel(bool bHasC4); virtual void SetPlayerModelEx(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; public: diff --git a/reapi/include/cssdk/engine/rehlds_api.h b/reapi/include/cssdk/engine/rehlds_api.h index f57174b..54c1ba7 100644 --- a/reapi/include/cssdk/engine/rehlds_api.h +++ b/reapi/include/cssdk/engine/rehlds_api.h @@ -35,7 +35,7 @@ #include "model.h" #define REHLDS_API_VERSION_MAJOR 2 -#define REHLDS_API_VERSION_MINOR 11 +#define REHLDS_API_VERSION_MINOR 12 //Steam_NotifyClientConnect hook typedef IHookChain IRehldsHook_Steam_NotifyClientConnect; @@ -181,6 +181,10 @@ typedef IVoidHookChainRegistry typedef IVoidHookChain<> IRehldsHook_SV_Spawn_f; typedef IVoidHookChainRegistry<> IRehldsHookRegistry_SV_Spawn_f; +//SV_CreatePacketEntities hook +typedef IHookChain IRehldsHook_SV_CreatePacketEntities; +typedef IHookChainRegistry IRehldsHookRegistry_SV_CreatePacketEntities; + class IRehldsHookchains { public: virtual ~IRehldsHookchains() { } @@ -221,6 +225,7 @@ public: virtual IRehldsHookRegistry_Cvar_DirectSet* Cvar_DirectSet() = 0; virtual IRehldsHookRegistry_SV_EstablishTimeBase* SV_EstablishTimeBase() = 0; virtual IRehldsHookRegistry_SV_Spawn_f* SV_Spawn_f() = 0; + virtual IRehldsHookRegistry_SV_CreatePacketEntities* SV_CreatePacketEntities() = 0; }; struct RehldsFuncs_t { @@ -283,4 +288,4 @@ public: virtual IRehldsFlightRecorder* GetFlightRecorder() = 0; }; -#define VREHLDS_HLDS_API_VERSION "VREHLDS_HLDS_API_VERSION001" \ No newline at end of file +#define VREHLDS_HLDS_API_VERSION "VREHLDS_HLDS_API_VERSION001" diff --git a/reapi/include/cssdk/engine/rehlds_interfaces.h b/reapi/include/cssdk/engine/rehlds_interfaces.h index a5497ff..e2b909f 100644 --- a/reapi/include/cssdk/engine/rehlds_interfaces.h +++ b/reapi/include/cssdk/engine/rehlds_interfaces.h @@ -126,4 +126,7 @@ public: virtual double GetTime() = 0; virtual void SetResourcesNum(int num) = 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; }; diff --git a/reapi/src/main.cpp b/reapi/src/main.cpp index 02071dc..4fa42ac 100644 --- a/reapi/src/main.cpp +++ b/reapi/src/main.cpp @@ -1,6 +1,7 @@ #include "precompiled.h" edict_t* g_pEdicts; +char g_szMapName[32]; int gmsgSendAudio, gmsgTeamScore, gmsgStatusIcon, gmsgArmorType, gmsgTeamInfo, gmsgItemStatus; struct @@ -67,8 +68,22 @@ CGameRules *InstallGameRules(IReGameHook_InstallGameRules *chain) 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_pFunctionTable->pfnSpawn = nullptr; - 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); +} diff --git a/reapi/src/main.h b/reapi/src/main.h index b33ad24..9a95cbc 100644 --- a/reapi/src/main.h +++ b/reapi/src/main.h @@ -1,5 +1,6 @@ #pragma once +extern char g_szMapName[32]; extern edict_t* g_pEdicts; extern int gmsgSendAudio; extern int gmsgTeamScore; @@ -15,5 +16,6 @@ void OnMetaDetach(); void ServerActivate_Post(edict_t *pEdictList, int edictCount, int clientMax); void ServerDeactivate_Post(); int DispatchSpawn(edict_t* pEntity); +void ResetGlobalState(); CGameRules *InstallGameRules(IReGameHook_InstallGameRules *chain); diff --git a/reapi/src/mods/mod_rehlds_api.cpp b/reapi/src/mods/mod_rehlds_api.cpp index e363600..83d7cc5 100644 --- a/reapi/src/mods/mod_rehlds_api.cpp +++ b/reapi/src/mods/mod_rehlds_api.cpp @@ -2,6 +2,7 @@ IRehldsApi* g_RehldsApi; const RehldsFuncs_t* g_RehldsFuncs; +IRehldsServerData* g_RehldsData; IRehldsHookchains* g_RehldsHookchains; IRehldsServerStatic* g_RehldsSvs; @@ -48,6 +49,7 @@ bool RehldsApi_Init() } g_RehldsFuncs = g_RehldsApi->GetFuncs(); + g_RehldsData = g_RehldsApi->GetServerData(); g_RehldsHookchains = g_RehldsApi->GetHookchains(); g_RehldsSvs = g_RehldsApi->GetServerStatic(); diff --git a/reapi/src/mods/mod_rehlds_api.h b/reapi/src/mods/mod_rehlds_api.h index a2bbfc7..768dc8c 100644 --- a/reapi/src/mods/mod_rehlds_api.h +++ b/reapi/src/mods/mod_rehlds_api.h @@ -2,6 +2,7 @@ extern IRehldsApi* g_RehldsApi; extern const RehldsFuncs_t* g_RehldsFuncs; +extern IRehldsServerData* g_RehldsData; extern IRehldsHookchains* g_RehldsHookchains; extern IRehldsServerStatic* g_RehldsSvs; diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index ff89c22..3aa5413 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -595,7 +595,7 @@ cell AMX_NATIVE_CALL rg_get_weapon_info(AMX *amx, cell *params) 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]); 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]); - if (RemovePlayerItem(pPlayer, szItemName)) { + if (pPlayer->CSPlayer()->RemovePlayerItem(szItemName)) { return TRUE; } @@ -975,7 +975,7 @@ cell AMX_NATIVE_CALL rg_set_user_team(AMX *amx, cell *params) CSGameRules()->m_iNumTerrorist--; 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->pev->body = 0; @@ -1001,7 +1001,7 @@ cell AMX_NATIVE_CALL rg_set_user_team(AMX *amx, cell *params) WRITE_STRING("defuser"); MESSAGE_END(); - SendItemStatus(pPlayer); + pPlayer->CSPlayer()->SendItemStatus(); } break; } @@ -1118,7 +1118,7 @@ cell AMX_NATIVE_CALL rg_transfer_c4(AMX *amx, cell *params) return FALSE; } - if (!pPlayer->m_bHasC4 || !RemovePlayerItem(pPlayer, "weapon_c4")) + if (!pPlayer->m_bHasC4 || !pPlayer->CSPlayer()->RemovePlayerItem("weapon_c4")) return FALSE; pPlayer->m_bHasC4 = false; @@ -1204,8 +1204,87 @@ AMX_NATIVE_INFO Misc_Natives_RG[] = { 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() { if (api_cfg.hasReGameDLL()) g_amxxapi.AddNatives(Misc_Natives_RG); + + if (api_cfg.hasReHLDS()) + g_amxxapi.AddNatives(Misc_Natives_RH); } diff --git a/reapi/src/reapi_utils.cpp b/reapi/src/reapi_utils.cpp index 8dff8eb..6ff3ec7 100644 --- a/reapi/src/reapi_utils.cpp +++ b/reapi/src/reapi_utils.cpp @@ -25,45 +25,6 @@ void UpdateTeamScores() 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(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 { TeamName team; ModelName model; diff --git a/reapi/src/reapi_utils.h b/reapi/src/reapi_utils.h index 637c369..e205e36 100644 --- a/reapi/src/reapi_utils.h +++ b/reapi/src/reapi_utils.h @@ -119,8 +119,6 @@ inline const char *GetTeamName(TeamName team) void Broadcast(const char *sentence); void UpdateTeamScores(); -bool RemovePlayerItem(CBasePlayer *pPlayer, const char* szItemName); -void SendItemStatus(CBasePlayer *pPlayer); ModelName GetModelAuto(TeamName team); extern void __declspec(noreturn) UTIL_SysError(const char *fmt, ...);