From 7a3992e9609852853472a9d7ab8c400a0c2452c9 Mon Sep 17 00:00:00 2001 From: asmodai Date: Thu, 28 Apr 2016 00:28:17 +0300 Subject: [PATCH 01/13] Added missed safety checks A more clean design of natives_misc --- reapi/msvc/reapi.vcxproj | 2 + reapi/msvc/reapi.vcxproj.filters | 6 ++ reapi/src/amxxmodule.cpp | 2 + reapi/src/api_config.cpp | 4 +- reapi/src/api_config.h | 2 +- reapi/src/dllapi.cpp | 7 +- reapi/src/hook_list.cpp | 29 ++++-- reapi/src/hook_list.h | 1 + reapi/src/hook_manager.cpp | 12 +-- reapi/src/main.cpp | 16 ++- reapi/src/main.h | 12 +++ reapi/src/meta_api.cpp | 5 +- reapi/src/natives/natives_helper.h | 67 ++++++++++++ reapi/src/natives/natives_hookchains.cpp | 3 +- reapi/src/natives/natives_members.cpp | 13 +-- reapi/src/natives/natives_misc.cpp | 125 ++++++++++++----------- reapi/src/natives/natives_vtc.cpp | 3 +- reapi/src/precompiled.h | 2 + reapi/src/reapi_utils.cpp | 16 +-- reapi/src/reapi_utils.h | 1 - 20 files changed, 211 insertions(+), 117 deletions(-) create mode 100644 reapi/src/main.h create mode 100644 reapi/src/natives/natives_helper.h diff --git a/reapi/msvc/reapi.vcxproj b/reapi/msvc/reapi.vcxproj index b36141a..593bb2c 100644 --- a/reapi/msvc/reapi.vcxproj +++ b/reapi/msvc/reapi.vcxproj @@ -200,10 +200,12 @@ + + diff --git a/reapi/msvc/reapi.vcxproj.filters b/reapi/msvc/reapi.vcxproj.filters index a361ede..0bc343b 100644 --- a/reapi/msvc/reapi.vcxproj.filters +++ b/reapi/msvc/reapi.vcxproj.filters @@ -642,6 +642,12 @@ include + + src\natives + + + src + diff --git a/reapi/src/amxxmodule.cpp b/reapi/src/amxxmodule.cpp index a5e15cf..ba2b93b 100644 --- a/reapi/src/amxxmodule.cpp +++ b/reapi/src/amxxmodule.cpp @@ -159,6 +159,8 @@ C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc) *(void **)((unsigned long)&g_amxxapi + g_funcrequests[i].offset) = fptr; } + OnAmxxAttach(); + RegisterNatives_HookChains(); RegisterNatives_Members(); RegisterNatives_Misc(); diff --git a/reapi/src/api_config.cpp b/reapi/src/api_config.cpp index 38ae618..54bc442 100644 --- a/reapi/src/api_config.cpp +++ b/reapi/src/api_config.cpp @@ -7,13 +7,11 @@ CAPI_Config::CAPI_Config() : m_api_rehlds(false), m_api_regame(false), m_api_vtc } -bool CAPI_Config::Init() +void CAPI_Config::Init() { m_api_rehlds = RehldsApi_Init(); m_api_regame = RegamedllApi_Init(); m_api_vtc = VTC_Api_Init(); - - return true; } void CAPI_Config::ServerActivate() const diff --git a/reapi/src/api_config.h b/reapi/src/api_config.h index 87cb35b..500b395 100644 --- a/reapi/src/api_config.h +++ b/reapi/src/api_config.h @@ -6,7 +6,7 @@ class CAPI_Config { public: CAPI_Config(); - bool Init(); + void Init(); bool hasReHLDS() const { return m_api_rehlds; } bool hasReGameDLL() const { return m_api_regame; } diff --git a/reapi/src/dllapi.cpp b/reapi/src/dllapi.cpp index cbf822f..000190a 100644 --- a/reapi/src/dllapi.cpp +++ b/reapi/src/dllapi.cpp @@ -1,8 +1,5 @@ #include "precompiled.h" -extern void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax); -extern void ServerDeactivate_Post(); - DLL_FUNCTIONS gFunctionTable = { NULL, // pfnGameInit @@ -26,7 +23,7 @@ DLL_FUNCTIONS gFunctionTable = NULL, // pfnClientPutInServer NULL, // pfnClientCommand NULL, // pfnClientUserInfoChanged - &ServerActivate, // pfnServerActivate + NULL, // pfnServerActivate NULL, // pfnServerDeactivate NULL, // pfnPlayerPreThink NULL, // pfnPlayerPostThink @@ -80,7 +77,7 @@ DLL_FUNCTIONS gFunctionTable_Post = NULL, // pfnClientPutInServer NULL, // pfnClientCommand NULL, // pfnClientUserInfoChanged - NULL, // pfnServerActivate + &ServerActivate_Post, // pfnServerActivate &ServerDeactivate_Post, // pfnServerDeactivate NULL, // pfnPlayerPreThink NULL, // pfnPlayerPostThink diff --git a/reapi/src/hook_list.cpp b/reapi/src/hook_list.cpp index 59d1c21..05289ca 100644 --- a/reapi/src/hook_list.cpp +++ b/reapi/src/hook_list.cpp @@ -129,15 +129,30 @@ hook_t* hooklist_t::getHookSafe(size_t hook) return nullptr; } +void hooklist_t::clear() +{ + for (auto& h : hooklist_engine) + h.clear(); + for (auto& h : hooklist_gamedll) + h.clear(); + for (auto& h : hooklist_animating) + h.clear(); + for (auto& h : hooklist_player) + h.clear(); +} + + void hook_t::clear() { - for (auto h : pre) - delete h; - pre.clear(); + if (pre.size() || post.size()) { + for (auto h : pre) + delete h; + pre.clear(); - for (auto h : post) - delete h; - post.clear(); + for (auto h : post) + delete h; + post.clear(); - unregisterHookchain(); + unregisterHookchain(); + } } diff --git a/reapi/src/hook_list.h b/reapi/src/hook_list.h index 21e40c7..3024150 100644 --- a/reapi/src/hook_list.h +++ b/reapi/src/hook_list.h @@ -49,6 +49,7 @@ struct hooklist_t } static hook_t *getHookSafe(size_t hook); + static void clear(); enum hooks_tables_e { diff --git a/reapi/src/hook_manager.cpp b/reapi/src/hook_manager.cpp index f181add..922d11c 100644 --- a/reapi/src/hook_manager.cpp +++ b/reapi/src/hook_manager.cpp @@ -40,17 +40,7 @@ void CAmxxHook::SetState(fwdstate st) void CHookManager::clearHandlers() const { -#define CLEAR_HOOKLIST(__END__, __START__)\ - for (size_t i = BEGIN_FUNC_REGION(__START__); i < ##__END__; ++i) {\ - if (m_hooklist[i])\ - m_hooklist[i]->clear();\ - } - - CLEAR_HOOKLIST(RH_EngineFunc_End, engine); - - CLEAR_HOOKLIST(RG_End, gamedll); - CLEAR_HOOKLIST(RG_CBaseAnimating_End, animating); - CLEAR_HOOKLIST(RG_CBasePlayer_End, player); + m_hooklist.clear(); } hook_t* CHookManager::getHook(size_t func) const diff --git a/reapi/src/main.cpp b/reapi/src/main.cpp index d17552a..52b2e95 100644 --- a/reapi/src/main.cpp +++ b/reapi/src/main.cpp @@ -1,13 +1,17 @@ #include "precompiled.h" edict_t* g_pEdicts; +int gmsgSendAudio; +int gmsgTeamScore; + +void OnAmxxAttach() +{ + // initialize API + api_cfg.Init(); +} bool OnMetaAttach() { - // initialize API - if (!api_cfg.Init()) - return false; - return true; } @@ -22,9 +26,11 @@ void OnMetaDetach() } } -void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax) +void ServerActivate_Post(edict_t *pEdictList, int edictCount, int clientMax) { g_pEdicts = pEdictList; + gmsgSendAudio = GET_USER_MSG_ID(PLID, "SendAudio", NULL); + gmsgTeamScore = GET_USER_MSG_ID(PLID, "TeamScore", NULL); api_cfg.ServerActivate(); SET_META_RESULT(MRES_IGNORED); diff --git a/reapi/src/main.h b/reapi/src/main.h new file mode 100644 index 0000000..7d06d20 --- /dev/null +++ b/reapi/src/main.h @@ -0,0 +1,12 @@ +#pragma once + +extern edict_t* g_pEdicts; +extern int gmsgSendAudio; +extern int gmsgTeamScore; + +void OnAmxxAttach(); +bool OnMetaAttach(); +void OnMetaDetach(); + +void ServerActivate_Post(edict_t *pEdictList, int edictCount, int clientMax); +void ServerDeactivate_Post(); diff --git a/reapi/src/meta_api.cpp b/reapi/src/meta_api.cpp index 4eaedb8..1dbb08d 100644 --- a/reapi/src/meta_api.cpp +++ b/reapi/src/meta_api.cpp @@ -19,9 +19,6 @@ plugin_info_t Plugin_info = PT_NEVER, // (when) unloadable }; -extern bool OnMetaAttach(); -extern void OnMetaDetach(); - C_DLLEXPORT int Meta_Query(char *interfaceVersion, plugin_info_t* *plinfo, mutil_funcs_t *pMetaUtilFuncs) { *plinfo = &Plugin_info; @@ -34,7 +31,7 @@ META_FUNCTIONS gMetaFunctionTable = { NULL, // pfnGetEntityAPI HL SDK; called before game DLL NULL, // pfnGetEntityAPI_Post META; called after game DLL - GetEntityAPI2, // pfnGetEntityAPI2 HL SDK2; called before game DLL + NULL, // pfnGetEntityAPI2 HL SDK2; called before game DLL GetEntityAPI2_Post, // pfnGetEntityAPI2_Post META; called after game DLL NULL, // pfnGetNewDLLFunctions HL SDK2; called before game DLL NULL, // pfnGetNewDLLFunctions_Post META; called after game DLL diff --git a/reapi/src/natives/natives_helper.h b/reapi/src/natives/natives_helper.h new file mode 100644 index 0000000..173f114 --- /dev/null +++ b/reapi/src/natives/natives_helper.h @@ -0,0 +1,67 @@ +#pragma once + +#define CHECK_ISPLAYER(x) if (x <= 0 || x > gpGlobals->maxClients) { MF_LogError(amx, AMX_ERR_NATIVE, "invalid player index %i", x); return FALSE; } +#define CHECK_ISENTITY(x) if (x > gpGlobals->maxEntities) { MF_LogError(amx, AMX_ERR_NATIVE, "invalid entity index %i", x); return FALSE; } + +class CAmxArg +{ +public: + CAmxArg(AMX* amx, cell value) : m_amx(amx), m_value(value) {} + operator float() const + { + return *(float *)m_value; + } + operator Vector&() const + { + return *(Vector *)getAmxAddr(m_amx, m_value); + } + operator entvars_s*() const + { + if (m_value < 0) + return nullptr; + return PEV(m_value); + } + operator int() const + { + return m_value; + } + operator size_t() const + { + return size_t(m_value); + } + operator bool() const + { + return m_value != 0; + } + operator CBaseEntity*() const + { + return g_ReGameFuncs->UTIL_PlayerByIndex(m_value); + } + operator PLAYER_ANIM() const + { + return static_cast(m_value); + } + + Vector& vector() const + { + return operator Vector&(); + } + +private: + AMX* m_amx; + cell m_value; +}; + +class CAmxArgs +{ +public: + CAmxArgs(AMX* amx, cell* params) : m_amx(amx), m_params(params) {} + CAmxArg operator[](size_t index) const + { + return CAmxArg(m_amx, m_params[index]); + } + +private: + AMX* m_amx; + cell* m_params; +}; diff --git a/reapi/src/natives/natives_hookchains.cpp b/reapi/src/natives/natives_hookchains.cpp index 0012cee..643c21c 100644 --- a/reapi/src/natives/natives_hookchains.cpp +++ b/reapi/src/natives/natives_hookchains.cpp @@ -282,5 +282,6 @@ AMX_NATIVE_INFO HookChain_Natives[] = void RegisterNatives_HookChains() { - g_amxxapi.AddNatives(HookChain_Natives); + if (api_cfg.hasReHLDS() || api_cfg.hasReGameDLL()) + g_amxxapi.AddNatives(HookChain_Natives); } diff --git a/reapi/src/natives/natives_members.cpp b/reapi/src/natives/natives_members.cpp index 401b8d9..6622a09 100644 --- a/reapi/src/natives/natives_members.cpp +++ b/reapi/src/natives/natives_members.cpp @@ -145,7 +145,8 @@ AMX_NATIVE_INFO Member_Natives[] = void RegisterNatives_Members() { - g_amxxapi.AddNatives(Member_Natives); + if (api_cfg.hasReGameDLL()) + g_amxxapi.AddNatives(Member_Natives); } BOOL set_member(void* pdata, const member_t *member, size_t element, cell* value) @@ -300,14 +301,14 @@ cell get_member(void* pdata, const member_t *member, size_t element, cell* dest) } else { // char * const char *src = get_member(pdata, member->offset); - if (src != nullptr) { - setAmxString(dest, src, element); - return 1; + if (src == nullptr) { + setAmxString(dest, "", 1); + return 0; } - setAmxString(dest, "", 1); + setAmxString(dest, src, element); } - return 0; + return 1; } case MEMBER_FLOAT: case MEMBER_INTEGER: diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 5fe3c63..536e312 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -14,12 +14,15 @@ static cell AMX_NATIVE_CALL rg_set_animation(AMX *amx, cell *params) { enum args_e { arg_count, arg_index, arg_anim }; + CHECK_ISPLAYER(params[arg_index]); + ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); if (pPlayer == nullptr || !pPlayer->IsConnected()) { + MF_LogError(amx, AMX_ERR_NATIVE, "player %i is not connected", params[arg_index]); return FALSE; } - - pPlayer->SetAnimation(static_cast(params[arg_anim])); + + pPlayer->SetAnimation(CAmxArg(amx, params[arg_anim])); return TRUE; } @@ -38,8 +41,11 @@ static cell AMX_NATIVE_CALL rg_add_account(AMX *amx, cell *params) { enum args_e { arg_count, arg_index, arg_amount, arg_track_change }; + CHECK_ISPLAYER(params[arg_index]); + ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); if (pPlayer == nullptr || !pPlayer->IsConnected()) { + MF_LogError(amx, AMX_ERR_NATIVE, "player %i is not connected", params[arg_index]); return FALSE; } @@ -61,9 +67,11 @@ static cell AMX_NATIVE_CALL rg_give_item(AMX *amx, cell *params) { enum args_e { arg_count, arg_index, arg_item }; - ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); + CHECK_ISPLAYER(params[arg_index]); + ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); if (pPlayer == nullptr || !pPlayer->IsConnected()) { + MF_LogError(amx, AMX_ERR_NATIVE, "player %i is not connected", params[arg_index]); return FALSE; } @@ -85,8 +93,11 @@ static cell AMX_NATIVE_CALL rg_give_default_items(AMX *amx, cell *params) { enum args_e { arg_count, arg_index }; + CHECK_ISPLAYER(params[arg_index]); + ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); if (pPlayer == nullptr || !pPlayer->IsConnected()) { + MF_LogError(amx, AMX_ERR_NATIVE, "player %i is not connected", params[arg_index]); return FALSE; } @@ -108,8 +119,11 @@ static cell AMX_NATIVE_CALL rg_give_shield(AMX *amx, cell *params) { enum args_e { arg_count, arg_index, arg_deploy }; + CHECK_ISPLAYER(params[arg_index]); + ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); if (pPlayer == nullptr || !pPlayer->IsConnected()) { + MF_LogError(amx, AMX_ERR_NATIVE, "player %i is not connected", params[arg_index]); return FALSE; } @@ -136,13 +150,12 @@ static cell AMX_NATIVE_CALL rg_dmg_radius(AMX *amx, cell *params) { enum args_e { arg_count, arg_vec, arg_inflictor, arg_attacker, arg_damage, arg_radius, arg_ignore_class, arg_dmg_type }; - cell *pSrc = getAmxAddr(amx, params[arg_vec]); + CHECK_ISENTITY(params[arg_inflictor]); + CHECK_ISENTITY(params[arg_attacker]); - entvars_t *pevInflictor = VARS(INDEXENT(params[arg_inflictor])); - entvars_t *pevAttacker = VARS(INDEXENT(params[arg_attacker])); + CAmxArgs args(amx, params); + g_ReGameFuncs->RadiusDamage(args[arg_vec], args[arg_inflictor], args[arg_attacker], args[arg_damage], args[arg_radius], args[arg_ignore_class], args[arg_dmg_type]); - Vector vecSrc(*(float *)&pSrc[0], *(float *)&pSrc[1], *(float *)&pSrc[2]); - g_ReGameFuncs->RadiusDamage(vecSrc, pevInflictor, pevAttacker, *(float *)¶ms[arg_damage], *(float *)¶ms[arg_radius], params[arg_ignore_class], params[arg_dmg_type]); return TRUE; } @@ -173,10 +186,12 @@ static cell AMX_NATIVE_CALL rg_multidmg_apply(AMX *amx, cell *params) { enum args_e { arg_count, arg_inflictor, arg_attacker }; - entvars_t *pevInflictor = VARS(INDEXENT(params[arg_inflictor])); - entvars_t *pevAttacker = VARS(INDEXENT(params[arg_attacker])); + CHECK_ISENTITY(params[arg_inflictor]); + CHECK_ISENTITY(params[arg_attacker]); + + CAmxArgs args(amx, params); + g_ReGameFuncs->ApplyMultiDamage(args[arg_inflictor], args[arg_attacker]); - g_ReGameFuncs->ApplyMultiDamage(pevInflictor, pevAttacker); return TRUE; } @@ -196,14 +211,17 @@ static cell AMX_NATIVE_CALL rg_multidmg_add(AMX *amx, cell *params) { enum args_e { arg_count, arg_inflictor, arg_victim, arg_damage, arg_dmg_type }; - entvars_t *pevInflictor = VARS(INDEXENT(params[arg_inflictor])); - CBaseEntity *pVictim = g_ReGameFuncs->UTIL_PlayerByIndex(params[arg_inflictor]); + CHECK_ISENTITY(params[arg_inflictor]); + CHECK_ISENTITY(params[arg_victim]); - if (pVictim == nullptr) { + CAmxArgs args(amx, params); + + if (params[arg_victim] < 0) { // null + MF_LogError(amx, AMX_ERR_NATIVE, "rg_multidmg_add: victim == null"); return FALSE; } - g_ReGameFuncs->AddMultiDamage(pevInflictor, pVictim, *(float *)¶ms[arg_damage], params[arg_dmg_type]); + g_ReGameFuncs->AddMultiDamage(args[arg_inflictor], args[arg_victim], args[arg_damage], args[arg_dmg_type]); return TRUE; } @@ -229,29 +247,23 @@ static cell AMX_NATIVE_CALL rg_fire_bullets(AMX *amx, cell *params) { enum args_e { arg_count, arg_inflictor, arg_attacker, arg_shots, arg_vecSrc, arg_dir, arg_spread, arg_dist, arg_bullet_type, arg_tracefrq, arg_dmg }; + CHECK_ISENTITY(params[arg_inflictor]); + CHECK_ISENTITY(params[arg_attacker]); + + CAmxArgs args(amx, params); ICSEntity *pInflictor = g_ReGameFuncs->INDEX_TO_CSENTITY(params[arg_inflictor]); - cell *pSrc = getAmxAddr(amx, params[arg_vecSrc]); - cell *pDir = getAmxAddr(amx, params[arg_dir]); - cell *pSpread = getAmxAddr(amx, params[arg_spread]); - - Vector vecSrc(*(float *)&pSrc[0], *(float *)&pSrc[1], *(float *)&pSrc[2]); - Vector vecDirShooting(*(float *)&pDir[0], *(float *)&pDir[1], *(float *)&pDir[2]); - Vector vecSpread(*(float *)&pSpread[0], *(float *)&pSpread[1], *(float *)&pSpread[2]); - - entvars_t *pevAttacker = VARS(INDEXENT(params[arg_attacker])); - pInflictor->FireBullets ( - params[arg_shots], - vecSrc, - vecDirShooting, - vecSpread, - *(float *)¶ms[arg_dist], - params[arg_bullet_type], - params[arg_tracefrq], - params[arg_dmg], - pevAttacker + args[arg_shots], + args[arg_vecSrc], + args[arg_dir], + args[arg_spread], + args[arg_dist], + args[arg_bullet_type], + args[arg_tracefrq], + args[arg_dmg], + args[arg_attacker] ); return TRUE; @@ -281,31 +293,25 @@ static cell AMX_NATIVE_CALL rg_fire_bullets3(AMX *amx, cell *params) { enum args_e { arg_count, arg_inflictor, arg_attacker, arg_vecSrc, arg_dir, arg_spread, arg_dist, arg_penetration, arg_bullet_type, arg_dmg, arg_range_mod, arg_pistol, arg_rand, arg_out }; + CHECK_ISENTITY(params[arg_inflictor]); + CHECK_ISENTITY(params[arg_attacker]); + + CAmxArgs args(amx, params); ICSEntity *pInflictor = g_ReGameFuncs->INDEX_TO_CSENTITY(params[arg_inflictor]); - cell *pSrc = getAmxAddr(amx, params[arg_vecSrc]); - cell *pDir = getAmxAddr(amx, params[arg_dir]); - - Vector vecSrc(*(float *)&pSrc[0], *(float *)&pSrc[1], *(float *)&pSrc[2]); - Vector vecDirShooting(*(float *)&pDir[0], *(float *)&pDir[1], *(float *)&pDir[2]); - - entvars_t *pevAttacker = VARS(INDEXENT(params[arg_attacker])); - - Vector *pOut = (Vector *)getAmxAddr(amx, params[arg_out]); - - *pOut = pInflictor->FireBullets3 + args[arg_out].vector() = pInflictor->FireBullets3 ( - vecSrc, - vecDirShooting, - *(float *)¶ms[arg_spread], - *(float *)¶ms[arg_dist], - params[arg_penetration], - params[arg_bullet_type], - params[arg_dmg], - *(float *)¶ms[arg_range_mod], - pevAttacker, - params[arg_pistol] != 0, - params[arg_rand] + args[arg_vecSrc], + args[arg_dir], + args[arg_spread], + args[arg_dist], + args[arg_penetration], + args[arg_bullet_type], + args[arg_dmg], + args[arg_range_mod], + args[arg_attacker], + args[arg_pistol], + args[arg_rand] ); return TRUE; @@ -378,7 +384,7 @@ static cell AMX_NATIVE_CALL rg_round_end(AMX *amx, cell *params) if (_message[0]) g_ReGameFuncs->EndRoundMessage(_message, event); - (*g_pCSGameRules)->TerminateRound(*(float *)¶ms[arg_delay], winstatus); + (*g_pCSGameRules)->TerminateRound(CAmxArg(amx, params[arg_delay]), winstatus); return TRUE; } @@ -404,7 +410,7 @@ static cell AMX_NATIVE_CALL rg_update_teamscores(AMX *amx, cell *params) return TRUE; } -AMX_NATIVE_INFO Misc_Natives[] = +AMX_NATIVE_INFO Misc_Natives_RG[] = { { "rg_set_animation", rg_set_animation }, { "rg_add_account", rg_add_account }, @@ -428,5 +434,6 @@ AMX_NATIVE_INFO Misc_Natives[] = void RegisterNatives_Misc() { - g_amxxapi.AddNatives(Misc_Natives); + if (api_cfg.hasReGameDLL()) + g_amxxapi.AddNatives(Misc_Natives_RG); } diff --git a/reapi/src/natives/natives_vtc.cpp b/reapi/src/natives/natives_vtc.cpp index 5e02a12..9d003d8 100644 --- a/reapi/src/natives/natives_vtc.cpp +++ b/reapi/src/natives/natives_vtc.cpp @@ -57,5 +57,6 @@ AMX_NATIVE_INFO Vtc_Natives[] = void RegisterNatives_Vtc() { - g_amxxapi.AddNatives(Vtc_Natives); + if (api_cfg.hasVTC()) + g_amxxapi.AddNatives(Vtc_Natives); } diff --git a/reapi/src/precompiled.h b/reapi/src/precompiled.h index 3987e23..12f71de 100644 --- a/reapi/src/precompiled.h +++ b/reapi/src/precompiled.h @@ -10,6 +10,7 @@ #include // std::vector #include +#include "main.h" #include "reapi_utils.h" #include @@ -43,6 +44,7 @@ #include "natives_members.h" #include "natives_misc.h" #include "natives_vtc.h" +#include "natives_helper.h" #undef DLLEXPORT #ifdef _WIN32 diff --git a/reapi/src/reapi_utils.cpp b/reapi/src/reapi_utils.cpp index 452fba6..73a5cc1 100644 --- a/reapi/src/reapi_utils.cpp +++ b/reapi/src/reapi_utils.cpp @@ -2,16 +2,10 @@ void Broadcast(const char *sentence) { - char text[32]; + char text[128]; + snprintf(text, sizeof text, "%!MRAD_%s", sentence); - strcpy(text, "%!MRAD_"); - strcat(text, UTIL_VarArgs("%s", sentence)); - - static int gmsgSendAudio = 0; - if (gmsgSendAudio == 0 && !(gmsgSendAudio = REG_USER_MSG("SendAudio", -1))) - return; - - g_pengfuncsTable->pfnMessageBegin(MSG_BROADCAST, REG_USER_MSG("SendAudio", -1), NULL, NULL); + g_pengfuncsTable->pfnMessageBegin(MSG_BROADCAST, gmsgSendAudio, NULL, NULL); g_pengfuncsTable->pfnWriteByte(0); g_pengfuncsTable->pfnWriteString(text); g_pengfuncsTable->pfnWriteShort(100); @@ -20,10 +14,6 @@ void Broadcast(const char *sentence) void UpdateTeamScores() { - static int gmsgTeamScore = 0; - if (gmsgTeamScore == 0 && !(gmsgTeamScore = REG_USER_MSG("TeamScore", -1))) - return; - g_pengfuncsTable->pfnMessageBegin(MSG_ALL, gmsgTeamScore, NULL, NULL); g_pengfuncsTable->pfnWriteString("CT"); g_pengfuncsTable->pfnWriteShort((*g_pCSGameRules)->m_iNumCTWins); diff --git a/reapi/src/reapi_utils.h b/reapi/src/reapi_utils.h index b2b91d2..5dd0c41 100644 --- a/reapi/src/reapi_utils.h +++ b/reapi/src/reapi_utils.h @@ -7,7 +7,6 @@ char(&ArraySizeHelper(T(&array)[N]))[N]; #define INDEXENT edictByIndex #define ENTINDEX indexOfEdict -extern edict_t* g_pEdicts; extern enginefuncs_t* g_pengfuncsTable; inline size_t indexOfEdict(edict_t* ed) From 063f8e6ed561265b496f3a4289a3af6722f373eb Mon Sep 17 00:00:00 2001 From: asmodai Date: Sat, 30 Apr 2016 20:38:53 +0300 Subject: [PATCH 02/13] Removed static keyword for natives Reduced error strings length --- reapi/src/hook_list.cpp | 6 +++--- reapi/src/member_list.cpp | 4 ++-- reapi/src/natives/natives_hookchains.cpp | 12 +++++------ reapi/src/natives/natives_members.cpp | 8 ++++---- reapi/src/natives/natives_misc.cpp | 26 ++++++++++++------------ reapi/src/natives/natives_vtc.cpp | 6 +++--- 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/reapi/src/hook_list.cpp b/reapi/src/hook_list.cpp index 05289ca..dfdf1f1 100644 --- a/reapi/src/hook_list.cpp +++ b/reapi/src/hook_list.cpp @@ -51,7 +51,7 @@ struct regfunc }; } - regfunc(const char *error) { UTIL_SysError(error); } // to cause a amxx module failure. + regfunc(const char *name) { UTIL_SysError("%s doesn't match hook definition", name); } // to cause a amxx module failure. operator regfunc_t() const { return func; } regfunc_t func; @@ -60,7 +60,7 @@ struct regfunc int regfunc::current_cell = 1; -#define ENG(h) { {}, {}, #h, "ReHLDS", [](){ return api_cfg.hasReHLDS(); }, ((!(RH_##h & (MAX_REGION_RANGE - 1)) ? regfunc::current_cell = 1, true : false) || (RH_##h & (MAX_REGION_RANGE - 1)) == regfunc::current_cell++) ? regfunc(h) : regfunc(#h " doesn't match hook definition"), [](){ g_RehldsHookchains->##h##()->registerHook(&##h); }, [](){ g_RehldsHookchains->##h##()->unregisterHook(&##h); }} +#define ENG(h) { {}, {}, #h, "ReHLDS", [](){ return api_cfg.hasReHLDS(); }, ((!(RH_##h & (MAX_REGION_RANGE - 1)) ? regfunc::current_cell = 1, true : false) || (RH_##h & (MAX_REGION_RANGE - 1)) == regfunc::current_cell++) ? regfunc(h) : regfunc(#h), [](){ g_RehldsHookchains->##h##()->registerHook(&##h); }, [](){ g_RehldsHookchains->##h##()->unregisterHook(&##h); }} hook_t hooklist_engine[] = { ENG(SV_StartSound), ENG(SV_DropClient), @@ -68,7 +68,7 @@ hook_t hooklist_engine[] = { ENG(Cvar_DirectSet) }; -#define DLL(h) { {}, {}, #h, "ReGameDLL", [](){ return api_cfg.hasReGameDLL(); }, ((!(RG_##h & (MAX_REGION_RANGE - 1)) ? regfunc::current_cell = 1, true : false) || (RG_##h & (MAX_REGION_RANGE - 1)) == regfunc::current_cell++) ? regfunc(h) : regfunc(#h " doesn't match hook definition"), [](){ g_ReGameHookchains->##h##()->registerHook(&##h); }, [](){ g_ReGameHookchains->##h##()->unregisterHook(&##h); }} +#define DLL(h) { {}, {}, #h, "ReGameDLL", [](){ return api_cfg.hasReGameDLL(); }, ((!(RG_##h & (MAX_REGION_RANGE - 1)) ? regfunc::current_cell = 1, true : false) || (RG_##h & (MAX_REGION_RANGE - 1)) == regfunc::current_cell++) ? regfunc(h) : regfunc(#h), [](){ g_ReGameHookchains->##h##()->registerHook(&##h); }, [](){ g_ReGameHookchains->##h##()->unregisterHook(&##h); }} hook_t hooklist_gamedll[] = { DLL(GetForceCamera), DLL(PlayerBlind), diff --git a/reapi/src/member_list.cpp b/reapi/src/member_list.cpp index 1af8f66..62b0471 100644 --- a/reapi/src/member_list.cpp +++ b/reapi/src/member_list.cpp @@ -1,6 +1,6 @@ #include "precompiled.h" -#define CLASS_MEMBERS(cx, mx) ((!(mx & (MAX_REGION_RANGE - 1)) ? regmember::current_cell = 1, true : false) || (mx & (MAX_REGION_RANGE - 1)) == regmember::current_cell++) ? regmember([](member_t* ptr){ decltype(##cx::##mx) f = {};ptr->size = getTypeSize(f);ptr->max_size = sizeof(f);ptr->offset = offsetof(##cx, ##mx);ptr->type = getMemberType(f);}) : regmember(#mx " doesn't match member definition") +#define CLASS_MEMBERS(cx, mx) ((!(mx & (MAX_REGION_RANGE - 1)) ? regmember::current_cell = 1, true : false) || (mx & (MAX_REGION_RANGE - 1)) == regmember::current_cell++) ? regmember([](member_t* ptr){ decltype(##cx::##mx) f = {};ptr->size = getTypeSize(f);ptr->max_size = sizeof(f);ptr->offset = offsetof(##cx, ##mx);ptr->type = getMemberType(f);}) : regmember(#mx) #define GM_MEMBERS(mx) CLASS_MEMBERS(CHalfLifeMultiplay, mx) #define GM_VOICE_MEMBERS(mx) CLASS_MEMBERS(CVoiceGameMgr, mx) @@ -59,7 +59,7 @@ struct regmember template regmember(T lambdaFunc) { lambdaFunc(&member); } - regmember(const char *error) { UTIL_SysError(error); } // to cause a amxx module failure. + regmember(const char *name) { UTIL_SysError("%s doesn't match member definition", name); } // to cause a amxx module failure. operator member_t() const { return member; } member_t member; diff --git a/reapi/src/natives/natives_hookchains.cpp b/reapi/src/natives/natives_hookchains.cpp index 643c21c..bff5a0a 100644 --- a/reapi/src/natives/natives_hookchains.cpp +++ b/reapi/src/natives/natives_hookchains.cpp @@ -12,7 +12,7 @@ * native RegisterHookChain(any:function_id, const callback[], post = 0); */ -static cell AMX_NATIVE_CALL RegisterHookChain(AMX *amx, cell *params) +cell AMX_NATIVE_CALL RegisterHookChain(AMX *amx, cell *params) { enum args_e { arg_count, arg_func, arg_handler, arg_post }; @@ -60,7 +60,7 @@ static cell AMX_NATIVE_CALL RegisterHookChain(AMX *amx, cell *params) * native bool:EnableHookChain(any:fwd); */ -static cell AMX_NATIVE_CALL EnableHookChain(AMX *amx, cell *params) +cell AMX_NATIVE_CALL EnableHookChain(AMX *amx, cell *params) { enum args_e { arg_count, arg_handle_hook }; @@ -85,7 +85,7 @@ static cell AMX_NATIVE_CALL EnableHookChain(AMX *amx, cell *params) * native bool:DisableHookChain(any:fwd); */ -static cell AMX_NATIVE_CALL DisableHookChain(AMX *amx, cell *params) +cell AMX_NATIVE_CALL DisableHookChain(AMX *amx, cell *params) { enum args_e { arg_count, arg_handle_hook }; @@ -111,7 +111,7 @@ static cell AMX_NATIVE_CALL DisableHookChain(AMX *amx, cell *params) * native SetHookChainReturn(AType:type, any:...); */ -static cell AMX_NATIVE_CALL SetHookChainReturn(AMX *amx, cell *params) +cell AMX_NATIVE_CALL SetHookChainReturn(AMX *amx, cell *params) { if (!g_hookCtx) { @@ -169,7 +169,7 @@ static cell AMX_NATIVE_CALL SetHookChainReturn(AMX *amx, cell *params) * native GetHookChainReturn(AType:type, any:...); */ -static cell AMX_NATIVE_CALL GetHookChainReturn(AMX *amx, cell *params) +cell AMX_NATIVE_CALL GetHookChainReturn(AMX *amx, cell *params) { if (!g_hookCtx) { @@ -218,7 +218,7 @@ static cell AMX_NATIVE_CALL GetHookChainReturn(AMX *amx, cell *params) * native SetHookChainArg(number, AType:type, any:...); */ -static cell AMX_NATIVE_CALL SetHookChainArg(AMX *amx, cell *params) +cell AMX_NATIVE_CALL SetHookChainArg(AMX *amx, cell *params) { if (!g_hookCtx) { diff --git a/reapi/src/natives/natives_members.cpp b/reapi/src/natives/natives_members.cpp index 6622a09..cacdbc0 100644 --- a/reapi/src/natives/natives_members.cpp +++ b/reapi/src/natives/natives_members.cpp @@ -1,7 +1,7 @@ #include "precompiled.h" // native set_member(_index, any:_member, any:...); -static cell AMX_NATIVE_CALL set_member(AMX *amx, cell *params) +cell AMX_NATIVE_CALL set_member(AMX *amx, cell *params) { enum args_e { arg_count, arg_index, arg_member, arg_value, arg_elem }; member_t *member = memberlist[params[arg_member]]; @@ -24,7 +24,7 @@ static cell AMX_NATIVE_CALL set_member(AMX *amx, cell *params) } // native any:get_member(_index, any:_member, any:...); -static cell AMX_NATIVE_CALL get_member(AMX *amx, cell *params) +cell AMX_NATIVE_CALL get_member(AMX *amx, cell *params) { enum args_e { arg_count, arg_index, arg_member, arg_3, arg_4 }; member_t *member = memberlist[params[arg_member]]; @@ -68,7 +68,7 @@ static cell AMX_NATIVE_CALL get_member(AMX *amx, cell *params) } // native set_member_game(any:_member, any:...); -static cell AMX_NATIVE_CALL set_member_game(AMX *amx, cell *params) +cell AMX_NATIVE_CALL set_member_game(AMX *amx, cell *params) { enum args_e { arg_count, arg_member, arg_value, arg_elem }; member_t *member = memberlist[params[arg_member]]; @@ -90,7 +90,7 @@ static cell AMX_NATIVE_CALL set_member_game(AMX *amx, cell *params) } // native get_member_game(any:_member, any:...); -static cell AMX_NATIVE_CALL get_member_game(AMX *amx, cell *params) +cell AMX_NATIVE_CALL get_member_game(AMX *amx, cell *params) { enum args_e { arg_count, arg_member, arg_3, arg_4 }; member_t *member = memberlist[params[arg_member]]; diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 536e312..4b86208 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -10,7 +10,7 @@ * * native rg_set_animation(index, PLAYER_ANIM:playerAnim); */ -static cell AMX_NATIVE_CALL rg_set_animation(AMX *amx, cell *params) +cell AMX_NATIVE_CALL rg_set_animation(AMX *amx, cell *params) { enum args_e { arg_count, arg_index, arg_anim }; @@ -37,7 +37,7 @@ static cell AMX_NATIVE_CALL rg_set_animation(AMX *amx, cell *params) * * native rg_add_account(index, amount, bool:bTrackChange = true); */ -static cell AMX_NATIVE_CALL rg_add_account(AMX *amx, cell *params) +cell AMX_NATIVE_CALL rg_add_account(AMX *amx, cell *params) { enum args_e { arg_count, arg_index, arg_amount, arg_track_change }; @@ -63,7 +63,7 @@ static cell AMX_NATIVE_CALL rg_add_account(AMX *amx, cell *params) * * native rg_give_item(index, const pszName[]); */ -static cell AMX_NATIVE_CALL rg_give_item(AMX *amx, cell *params) +cell AMX_NATIVE_CALL rg_give_item(AMX *amx, cell *params) { enum args_e { arg_count, arg_index, arg_item }; @@ -89,7 +89,7 @@ static cell AMX_NATIVE_CALL rg_give_item(AMX *amx, cell *params) * * native rg_give_default_items(index); */ -static cell AMX_NATIVE_CALL rg_give_default_items(AMX *amx, cell *params) +cell AMX_NATIVE_CALL rg_give_default_items(AMX *amx, cell *params) { enum args_e { arg_count, arg_index }; @@ -115,7 +115,7 @@ static cell AMX_NATIVE_CALL rg_give_default_items(AMX *amx, cell *params) * * native rg_give_shield(index, bool:bDeploy = true); */ -static cell AMX_NATIVE_CALL rg_give_shield(AMX *amx, cell *params) +cell AMX_NATIVE_CALL rg_give_shield(AMX *amx, cell *params) { enum args_e { arg_count, arg_index, arg_deploy }; @@ -146,7 +146,7 @@ static cell AMX_NATIVE_CALL rg_give_shield(AMX *amx, cell *params) * * native rg_dmg_radius(Float:vecSrc[3], inflictor, attacker, Float:flDamage, Float:flRadius, iClassIgnore, bitsDamageType); */ -static cell AMX_NATIVE_CALL rg_dmg_radius(AMX *amx, cell *params) +cell AMX_NATIVE_CALL rg_dmg_radius(AMX *amx, cell *params) { enum args_e { arg_count, arg_vec, arg_inflictor, arg_attacker, arg_damage, arg_radius, arg_ignore_class, arg_dmg_type }; @@ -166,7 +166,7 @@ static cell AMX_NATIVE_CALL rg_dmg_radius(AMX *amx, cell *params) * * native rg_multidmg_clear(); */ -static cell AMX_NATIVE_CALL rg_multidmg_clear(AMX *amx, cell *params) +cell AMX_NATIVE_CALL rg_multidmg_clear(AMX *amx, cell *params) { g_ReGameFuncs->ClearMultiDamage(); return TRUE; @@ -182,7 +182,7 @@ static cell AMX_NATIVE_CALL rg_multidmg_clear(AMX *amx, cell *params) * * native rg_multidmg_apply(inflictor, attacker); */ -static cell AMX_NATIVE_CALL rg_multidmg_apply(AMX *amx, cell *params) +cell AMX_NATIVE_CALL rg_multidmg_apply(AMX *amx, cell *params) { enum args_e { arg_count, arg_inflictor, arg_attacker }; @@ -207,7 +207,7 @@ static cell AMX_NATIVE_CALL rg_multidmg_apply(AMX *amx, cell *params) * * native rg_multidmg_add(inflictor, victim, Float:flDamage, bitsDamageType); */ -static cell AMX_NATIVE_CALL rg_multidmg_add(AMX *amx, cell *params) +cell AMX_NATIVE_CALL rg_multidmg_add(AMX *amx, cell *params) { enum args_e { arg_count, arg_inflictor, arg_victim, arg_damage, arg_dmg_type }; @@ -243,7 +243,7 @@ static cell AMX_NATIVE_CALL rg_multidmg_add(AMX *amx, cell *params) * * native rg_fire_bullets(inflictor, attacker, shots, Float:vecSrc[3], Float:vecDirShooting[3], Float::vecSpread[3], Float:flDistance, iBulletType, iTracerFreq, iDamage); */ -static cell AMX_NATIVE_CALL rg_fire_bullets(AMX *amx, cell *params) +cell AMX_NATIVE_CALL rg_fire_bullets(AMX *amx, cell *params) { enum args_e { arg_count, arg_inflictor, arg_attacker, arg_shots, arg_vecSrc, arg_dir, arg_spread, arg_dist, arg_bullet_type, arg_tracefrq, arg_dmg }; @@ -289,7 +289,7 @@ static cell AMX_NATIVE_CALL rg_fire_bullets(AMX *amx, cell *params) * * native Float:[3] rg_fire_bullets3(inflictor, attacker, Float:vecSrc[3], Float:vecDirShooting[3], Float:vecSpread, Float:flDistance, iPenetration, iBulletType, iDamage, Float:flRangeModifier, bool:bPistol, shared_rand); */ -static cell AMX_NATIVE_CALL rg_fire_bullets3(AMX *amx, cell *params) +cell AMX_NATIVE_CALL rg_fire_bullets3(AMX *amx, cell *params) { enum args_e { arg_count, arg_inflictor, arg_attacker, arg_vecSrc, arg_dir, arg_spread, arg_dist, arg_penetration, arg_bullet_type, arg_dmg, arg_range_mod, arg_pistol, arg_rand, arg_out }; @@ -354,7 +354,7 @@ struct { * * native rg_round_end(Float:tmDelay, WinStatus:st, ScenarioEventEndRound:event = ROUND_NONE, const message[] = "default", const sentence[] = "default"); */ -static cell AMX_NATIVE_CALL rg_round_end(AMX *amx, cell *params) +cell AMX_NATIVE_CALL rg_round_end(AMX *amx, cell *params) { enum args_e { arg_count, arg_delay, arg_win, arg_event, arg_message, arg_sentence, arg_silent }; @@ -399,7 +399,7 @@ static cell AMX_NATIVE_CALL rg_round_end(AMX *amx, cell *params) * * native rg_update_teamscores(iCtsWins = 0, iTsWins = 0, bool:bAdd = true); */ -static cell AMX_NATIVE_CALL rg_update_teamscores(AMX *amx, cell *params) +cell AMX_NATIVE_CALL rg_update_teamscores(AMX *amx, cell *params) { enum args_e { arg_count, arg_cts, arg_ts, arg_add }; diff --git a/reapi/src/natives/natives_vtc.cpp b/reapi/src/natives/natives_vtc.cpp index 9d003d8..4b018bf 100644 --- a/reapi/src/natives/natives_vtc.cpp +++ b/reapi/src/natives/natives_vtc.cpp @@ -8,7 +8,7 @@ * * native VTC_IsClientSpeaking(index); */ -static cell AMX_NATIVE_CALL VTC_IsClientSpeaking(AMX *amx, cell *params) +cell AMX_NATIVE_CALL VTC_IsClientSpeaking(AMX *amx, cell *params) { enum args_e { arg_count, arg_index }; return g_pVoiceTranscoderApi->IsClientSpeaking((size_t)params[arg_index]); @@ -22,7 +22,7 @@ static cell AMX_NATIVE_CALL VTC_IsClientSpeaking(AMX *amx, cell *params) * * native VTC_MuteClient(index); */ -static cell AMX_NATIVE_CALL VTC_MuteClient(AMX *amx, cell *params) +cell AMX_NATIVE_CALL VTC_MuteClient(AMX *amx, cell *params) { enum args_e { arg_count, arg_index }; g_pVoiceTranscoderApi->MuteClient((size_t)params[arg_index]); @@ -38,7 +38,7 @@ static cell AMX_NATIVE_CALL VTC_MuteClient(AMX *amx, cell *params) * * native VTC_UnmuteClient(index); */ -static cell AMX_NATIVE_CALL VTC_UnmuteClient(AMX *amx, cell *params) +cell AMX_NATIVE_CALL VTC_UnmuteClient(AMX *amx, cell *params) { enum args_e { arg_count, arg_index }; g_pVoiceTranscoderApi->UnmuteClient((size_t)params[arg_index]); From 12b0573aa508abbeda9b01556648206467c121bb Mon Sep 17 00:00:00 2001 From: s1lentq Date: Mon, 2 May 2016 03:09:11 +0600 Subject: [PATCH 03/13] Added support Reunion API Added new regamedll natives: rg_create_entity, rg_find_ent_by_class, rg_find_ent_by_owner, rg_get_weapon_info, rg_remove_all_items, rg_remove_item Added hookchain CanBuyThis Added native (reunion) get_client_data --- .../scripting/include/reapi_gamedll.inc | 57 +++- .../scripting/include/reapi_gamedll_const.inc | 58 +++- .../amxmodx/scripting/include/reapi_misc.inc | 48 +++ reapi/include/cssdk/dlls/regamedll_api.h | 13 +- .../include/cssdk/dlls/regamedll_interfaces.h | 1 + reapi/include/reunion_api.h | 36 ++ reapi/msvc/reapi.vcxproj | 2 + reapi/msvc/reapi.vcxproj.filters | 6 + reapi/src/api_config.cpp | 16 +- reapi/src/api_config.h | 5 +- reapi/src/engine_api.cpp | 2 +- reapi/src/hook_callback.cpp | 74 ++-- reapi/src/hook_callback.h | 1 + reapi/src/hook_list.cpp | 4 +- reapi/src/hook_list.h | 1 + reapi/src/main.cpp | 12 +- reapi/src/main.h | 1 + reapi/src/mods/mod_regamedll_api.cpp | 2 +- reapi/src/mods/mod_regamedll_api.h | 2 +- reapi/src/mods/mod_reunion_api.cpp | 27 ++ reapi/src/mods/mod_reunion_api.h | 5 + reapi/src/natives/natives_hookchains.cpp | 2 +- reapi/src/natives/natives_members.cpp | 16 +- reapi/src/natives/natives_misc.cpp | 318 +++++++++++++++++- reapi/src/natives/natives_misc.h | 11 + reapi/src/precompiled.h | 9 +- reapi/src/reapi_utils.cpp | 4 +- 27 files changed, 661 insertions(+), 72 deletions(-) create mode 100644 reapi/include/reunion_api.h create mode 100644 reapi/src/mods/mod_reunion_api.cpp create mode 100644 reapi/src/mods/mod_reunion_api.h diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc index dd855c0..a6e65ce 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc @@ -188,7 +188,7 @@ native Float:[3] rg_fire_bullets3(const inflictor, const attacker, Float:vecSrc[ * * @noreturn */ -native rg_round_end(const Float:tmDelay, const WinStatus:st, const ScenarionEventEndRound:event = ROUND_NONE, const message[] = "default", const sentence[] = "default"); +native rg_round_end(const Float:tmDelay, const WinStatus:st, const ScenarioEventEndRound:event = ROUND_NONE, const message[] = "default", const sentence[] = "default"); /* * Update current scores @@ -200,3 +200,58 @@ native rg_round_end(const Float:tmDelay, const WinStatus:st, const ScenarionEven * @noreturn */ native rg_update_teamscores(const iCtsWins = 0, const iTsWins = 0, const bool:bAdd = true); + +/* +* Creates an entity using Counter-Strike's custom CreateNamedEntity wrapper. +* +* @param classname Entity class name +* +* @return Index of the created entity or 0 otherwise +* +*/ +native rg_create_entity(const classname[]); + +/* +* Finds an entity in the world using Counter-Strike's custom FindEntityByString wrapper. +* +* @param start_index Entity index to start searching from. -1 to start from the first entity +* @param classname Classname to search for +* +* @return Entity index > 0 if found, 0 otherwise +* +*/ +native rg_find_ent_by_class(start_index, const classname[]); + +/* +* Finds an entity in the world using Counter-Strike's custom FindEntityByString wrapper, matching by owner. +* +* @param start_index Entity index to start searching from. -1 to start from the first entity +* @param classname Classname to search for +* +* @return Entity index > 0 if found, 0 otherwise +* +*/ +native rg_find_ent_by_owner(start_index, const classname[], owner); + +/** +* Returns some information about a weapon. +* +* @param weapon_id Weapon id, see WEAPON_* constants +* @param type Info type, see WPINFO_* constants +* +* @return Weapon information value +* @error If weapon_id and type are out of bound, an error will be thrown. +* +*/ +native rg_get_weapon_info(const {WeaponIdType,_}:weapon_id, WpnInfo:type, any:...); + +/** +* Remove specifed the player's item by class name +* +* @param index Client index +* @param item_name Class name item +* +* @return 1 if found and remove, 0 otherwise +* +*/ +native rg_remove_item(const index, const item_name[]); diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc index 86f140f..425e399 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc @@ -11,6 +11,54 @@ #define SIGNAL_ESCAPE (1<<3) #define SIGNAL_VIPSAFETY (1<<4) +enum WeaponIdType +{ + WEAPON_NONE, + WEAPON_P228, + WEAPON_GLOCK, + WEAPON_SCOUT, + WEAPON_HEGRENADE, + WEAPON_XM1014, + WEAPON_C4, + WEAPON_MAC10, + WEAPON_AUG, + WEAPON_SMOKEGRENADE, + WEAPON_ELITE, + WEAPON_FIVESEVEN, + WEAPON_UMP45, + WEAPON_SG550, + WEAPON_GALIL, + WEAPON_FAMAS, + WEAPON_USP, + WEAPON_GLOCK18, + WEAPON_AWP, + WEAPON_MP5N, + WEAPON_M249, + WEAPON_M3, + WEAPON_M4A1, + WEAPON_TMP, + WEAPON_G3SG1, + WEAPON_FLASHBANG, + WEAPON_DEAGLE, + WEAPON_SG552, + WEAPON_AK47, + WEAPON_KNIFE, + WEAPON_P90, + WEAPON_SHIELDGUN = 99 +}; + +/* Weapon info types for use with rg_get_weapon_info() */ +enum WpnInfo +{ + WPINFO_COST, + WPINFO_CLIP_COST, + WPINFO_BUY_CLIP_SIZE, + WPINFO_GUN_CLIP_SIZE, + WPINFO_MAX_ROUNDS, + WPINFO_AMMO_TYPE, + WPINFO_NAME +}; + enum WinStatus { WINSTATUS_CTS = 1, @@ -19,7 +67,7 @@ enum WinStatus }; // used for EndRoundMessage() logged messages -enum ScenarionEventEndRound +enum ScenarioEventEndRound { ROUND_NONE, ROUND_TARGET_BOMB, @@ -78,10 +126,16 @@ enum GamedllFunc /** * Description: - - * Params: (WinStatus:status, ScenarionEventEndRound:event, Float:tmDelay) + * Params: (WinStatus:status, ScenarioEventEndRound:event, Float:tmDelay) */ RG_RoundEnd, + /** + * Description: - + * Params: (const index, const iWeapon) + */ + RG_CanBuyThis, + // [...] RG_End }; diff --git a/reapi/extra/amxmodx/scripting/include/reapi_misc.inc b/reapi/extra/amxmodx/scripting/include/reapi_misc.inc index 91886f0..7b6a559 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_misc.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_misc.inc @@ -3,6 +3,46 @@ #endif #define _reapi_misc_included +enum client_auth +{ + /** + * Description: - + * Return type: int + * Params: get_client_data(const index, CA_PROTOCOL) + */ + CA_PROTOCOL, + + /** + * Description: - + * Return type: client_auth_type + * Params: get_client_data(const index, CA_TYPE) + */ + CA_TYPE, + + /** + * Description: - + * Return type: - + * Params: get_client_data(const index, CA_STRING, output[], maxlength) + */ + CA_STRING, +}; + +enum client_auth_type +{ + CA_TYPE_NONE = 0, + CA_TYPE_DPROTO, + CA_TYPE_STEAM, + CA_TYPE_STEAMEMU, + CA_TYPE_REVEMU, + CA_TYPE_OLDREVEMU, + CA_TYPE_HLTV, + CA_TYPE_SC2009, + CA_TYPE_AVSMP, + CA_TYPE_SXEI, + CA_TYPE_REVEMU2013, + CA_TYPE_SSE3, +}; + /* * Checks whether the player is talking at this moment * @@ -43,3 +83,11 @@ forward VTC_OnClientStartSpeak(index); * @noreturn */ forward VTC_OnClientStopSpeak(index); + +/* +* Get out information of the client +* +* @param index Client index +* @type to look enum client_auth +*/ +native get_client_data(const index, client_auth:type, any:...); diff --git a/reapi/include/cssdk/dlls/regamedll_api.h b/reapi/include/cssdk/dlls/regamedll_api.h index 1f6ea12..dda1fc2 100644 --- a/reapi/include/cssdk/dlls/regamedll_api.h +++ b/reapi/include/cssdk/dlls/regamedll_api.h @@ -174,6 +174,14 @@ typedef IVoidHookChainRegistry IReGameHook_RoundEnd; typedef IHookChainRegistryClassEmpty IReGameHookRegistry_RoundEnd; +// CanBuyThis hook +typedef IHookChain IReGameHook_CanBuyThis; +typedef IHookChainRegistry IReGameHookRegistry_CanBuyThis; + +// InstallGameRules hook +typedef IHookChain IReGameHook_InstallGameRules; +typedef IHookChainRegistry IReGameHookRegistry_InstallGameRules; + class IReGameHookchains { public: virtual ~IReGameHookchains() {} @@ -216,6 +224,8 @@ public: virtual IReGameHookRegistry_PlayerBlind* PlayerBlind() = 0; virtual IReGameHookRegistry_RadiusFlash_TraceLine* RadiusFlash_TraceLine() = 0; virtual IReGameHookRegistry_RoundEnd* RoundEnd() = 0; + virtual IReGameHookRegistry_CanBuyThis* CanBuyThis() = 0; + virtual IReGameHookRegistry_InstallGameRules* InstallGameRules() = 0; }; @@ -235,7 +245,8 @@ struct ReGameFuncs_t { void (*AddMultiDamage)(entvars_t *pevInflictor, CBaseEntity *pEntity, float flDamage, int bitsDamageType); void (*EndRoundMessage)(const char *sentence, int event); - + class CBaseEntity *(*UTIL_FindEntityByString)(class CBaseEntity *pStartEntity, const char *szKeyword, const char *szValue); + struct WeaponInfoStruct *(*GetWeaponInfo)(int weaponID); }; class IReGameApi { diff --git a/reapi/include/cssdk/dlls/regamedll_interfaces.h b/reapi/include/cssdk/dlls/regamedll_interfaces.h index e2d3fd0..8abddd4 100644 --- a/reapi/include/cssdk/dlls/regamedll_interfaces.h +++ b/reapi/include/cssdk/dlls/regamedll_interfaces.h @@ -301,6 +301,7 @@ public: virtual void GiveNamedItem(const char *pszName) = 0; virtual void GiveDefaultItems() = 0; virtual void GiveShield(bool bDeploy = true) = 0; + virtual void RemoveAllItems(bool bRemoveSuit) = 0; }; class IAPI_Bot: public ICSPlayer { diff --git a/reapi/include/reunion_api.h b/reapi/include/reunion_api.h new file mode 100644 index 0000000..0bd7b35 --- /dev/null +++ b/reapi/include/reunion_api.h @@ -0,0 +1,36 @@ +#ifndef REUNION_API_H +#define REUNION_API_H + +#define REUNION_API_VERSION_MAJOR 1 +#define REUNION_API_VERSION_MINOR 1 + +enum dp_authkind_e +{ + DP_AUTH_NONE = 0, + DP_AUTH_DPROTO = 1, + DP_AUTH_STEAM = 2, + DP_AUTH_STEAMEMU = 3, + DP_AUTH_REVEMU = 4, + DP_AUTH_OLDREVEMU = 5, + DP_AUTH_HLTV = 6, + DP_AUTH_SC2009 = 7, + DP_AUTH_AVSMP = 8, + DP_AUTH_SXEI = 9, + DP_AUTH_REVEMU2013 = 10, + DP_AUTH_SSE3 = 11, +}; + +class IReunionApi +{ +public: + int version_major; + int version_minor; + + virtual int GetClientProtocol(int index) = 0; // index: 0-31 + virtual dp_authkind_e GetClientAuthtype(int index) = 0; // index: 0-31 + + virtual size_t GetClientAuthdata(int index, void *data, int maxlen) = 0; // get auth data as binary. index: 0-31 + virtual const char *GetClientAuthdataString(int index, char *data, int maxlen) = 0; // get auth data as string. index: 0-31 +}; + +#endif // REUNION_API_H diff --git a/reapi/msvc/reapi.vcxproj b/reapi/msvc/reapi.vcxproj index 593bb2c..21d4318 100644 --- a/reapi/msvc/reapi.vcxproj +++ b/reapi/msvc/reapi.vcxproj @@ -204,6 +204,7 @@ + @@ -243,6 +244,7 @@ + diff --git a/reapi/msvc/reapi.vcxproj.filters b/reapi/msvc/reapi.vcxproj.filters index 0bc343b..8b17e67 100644 --- a/reapi/msvc/reapi.vcxproj.filters +++ b/reapi/msvc/reapi.vcxproj.filters @@ -648,6 +648,9 @@ src + + src\mods + @@ -725,6 +728,9 @@ src\natives + + src\mods + diff --git a/reapi/src/api_config.cpp b/reapi/src/api_config.cpp index 54bc442..583257d 100644 --- a/reapi/src/api_config.cpp +++ b/reapi/src/api_config.cpp @@ -2,28 +2,26 @@ CAPI_Config api_cfg; -CAPI_Config::CAPI_Config() : m_api_rehlds(false), m_api_regame(false), m_api_vtc(false) +CAPI_Config::CAPI_Config() : m_api_rehlds(false), m_api_regame(false), m_api_vtc(false), m_api_reunion(false) { } void CAPI_Config::Init() { - m_api_rehlds = RehldsApi_Init(); - m_api_regame = RegamedllApi_Init(); - m_api_vtc = VTC_Api_Init(); -} + m_api_rehlds = RehldsApi_Init(); + m_api_regame = RegamedllApi_Init(); + m_api_vtc = VTC_Api_Init(); + m_api_reunion = ReunionApi_Init(); -void CAPI_Config::ServerActivate() const -{ if (m_api_regame) { - g_pCSGameRules = (CHalfLifeMultiplay **)g_ReGameApi->GetGameData()->GetGameRules(); + g_ReGameHookchains->InstallGameRules()->registerHook(&InstallGameRules); } } void CAPI_Config::ServerDeactivate() const { if (m_api_regame) { - g_pCSGameRules = nullptr; + g_pGameRules = nullptr; } } diff --git a/reapi/src/api_config.h b/reapi/src/api_config.h index 500b395..488cd73 100644 --- a/reapi/src/api_config.h +++ b/reapi/src/api_config.h @@ -11,8 +11,8 @@ public: bool hasReHLDS() const { return m_api_rehlds; } bool hasReGameDLL() const { return m_api_regame; } bool hasVTC() const { return m_api_vtc; } + bool hasReunion() const { return m_api_reunion; } - void ServerActivate() const; void ServerDeactivate() const; private: @@ -22,8 +22,9 @@ private: // future plans? bool m_api_vtc; // for gag + bool m_api_reunion; // for information about authorization client + //bool m_api_revoice; // for gag #2 - //bool m_api_reunion; // for information about authorization client //bool m_api_rechecker; // for detection when checking and adding few files }; diff --git a/reapi/src/engine_api.cpp b/reapi/src/engine_api.cpp index bcd5722..5194a40 100644 --- a/reapi/src/engine_api.cpp +++ b/reapi/src/engine_api.cpp @@ -1,6 +1,6 @@ #include "precompiled.h" -enginefuncs_t meta_engfuncs_post = +enginefuncs_t meta_engfuncs_post = { NULL, // pfnPrecacheModel() NULL, // pfnPrecacheSound() diff --git a/reapi/src/hook_callback.cpp b/reapi/src/hook_callback.cpp index 3193df1..043ad57 100644 --- a/reapi/src/hook_callback.cpp +++ b/reapi/src/hook_callback.cpp @@ -55,7 +55,7 @@ void CBasePlayer_Spawn(IReGameHook_CBasePlayer_Spawn *chain, CBasePlayer *pthis) chain->callNext(); }; - callVoidForward(RG_CBasePlayer_Spawn, original, pthis->entindex()); + callVoidForward(RG_CBasePlayer_Spawn, original, indexOfEdict(pthis->pev)); } void CBasePlayer_Precache(IReGameHook_CBasePlayer_Precache *chain, CBasePlayer *pthis) @@ -65,7 +65,7 @@ void CBasePlayer_Precache(IReGameHook_CBasePlayer_Precache *chain, CBasePlayer * chain->callNext(); }; - callVoidForward(RG_CBasePlayer_Precache, original, pthis->entindex()); + callVoidForward(RG_CBasePlayer_Precache, original, indexOfEdict(pthis->pev)); } int CBasePlayer_ObjectCaps(IReGameHook_CBasePlayer_ObjectCaps *chain, CBasePlayer *pthis) @@ -75,7 +75,7 @@ int CBasePlayer_ObjectCaps(IReGameHook_CBasePlayer_ObjectCaps *chain, CBasePlaye return chain->callNext(); }; - return callForward(RG_CBasePlayer_ObjectCaps, original, pthis->entindex()); + return callForward(RG_CBasePlayer_ObjectCaps, original, indexOfEdict(pthis->pev)); } int CBasePlayer_Classify(IReGameHook_CBasePlayer_Classify *chain, CBasePlayer *pthis) @@ -85,7 +85,7 @@ int CBasePlayer_Classify(IReGameHook_CBasePlayer_Classify *chain, CBasePlayer *p return chain->callNext(); }; - return callForward(RG_CBasePlayer_Classify, original, pthis->entindex()); + return callForward(RG_CBasePlayer_Classify, original, indexOfEdict(pthis->pev)); } void CBasePlayer_TraceAttack(IReGameHook_CBasePlayer_TraceAttack *chain, CBasePlayer *pthis, entvars_t *pevAttacker, float flDamage, Vector& vecDir, TraceResult *ptr, int bitsDamageType) @@ -97,7 +97,7 @@ void CBasePlayer_TraceAttack(IReGameHook_CBasePlayer_TraceAttack *chain, CBasePl chain->callNext(PEV(_pevAttacker), _flDamage, vecDirCopy, _ptr, _bitsDamageType); }; - callVoidForward(RG_CBasePlayer_TraceAttack, original, pthis->entindex(), indexOfEdict(pevAttacker), flDamage, g_amxxapi.PrepareCellArrayA(reinterpret_cast(&vecDirCopy), 3, true), ptr, bitsDamageType); + callVoidForward(RG_CBasePlayer_TraceAttack, original, indexOfEdict(pthis->pev), indexOfEdict(pevAttacker), flDamage, g_amxxapi.PrepareCellArrayA(reinterpret_cast(&vecDirCopy), 3, true), ptr, bitsDamageType); } int CBasePlayer_TakeDamage(IReGameHook_CBasePlayer_TakeDamage *chain, CBasePlayer *pthis, entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType) @@ -107,7 +107,7 @@ int CBasePlayer_TakeDamage(IReGameHook_CBasePlayer_TakeDamage *chain, CBasePlaye return chain->callNext(PEV(_pevInflictor), PEV(_pevAttacker), _flDamage, _bitsDamageType); }; - return callForward(RG_CBasePlayer_TakeDamage, original, pthis->entindex(), indexOfEdict(pevInflictor), indexOfEdict(pevAttacker), flDamage, bitsDamageType); + return callForward(RG_CBasePlayer_TakeDamage, original, indexOfEdict(pthis->pev), indexOfEdict(pevInflictor), indexOfEdict(pevAttacker), flDamage, bitsDamageType); } int CBasePlayer_TakeHealth(IReGameHook_CBasePlayer_TakeHealth *chain, CBasePlayer *pthis, float flHealth, int bitsDamageType) @@ -117,7 +117,7 @@ int CBasePlayer_TakeHealth(IReGameHook_CBasePlayer_TakeHealth *chain, CBasePlaye return chain->callNext(_flHealth, _bitsDamageType); }; - return callForward(RG_CBasePlayer_TakeHealth, original, pthis->entindex(), flHealth, bitsDamageType); + return callForward(RG_CBasePlayer_TakeHealth, original, indexOfEdict(pthis->pev), flHealth, bitsDamageType); } void CBasePlayer_Killed(IReGameHook_CBasePlayer_Killed *chain, CBasePlayer *pthis, entvars_t *pevAttacker, int iGib) @@ -127,7 +127,7 @@ void CBasePlayer_Killed(IReGameHook_CBasePlayer_Killed *chain, CBasePlayer *pthi chain->callNext(PEV(_pevAttacker), _iGib); }; - callVoidForward(RG_CBasePlayer_Killed, original, pthis->entindex(), indexOfEdict(pevAttacker), iGib); + callVoidForward(RG_CBasePlayer_Killed, original, indexOfEdict(pthis->pev), indexOfEdict(pevAttacker), iGib); } void CBasePlayer_AddPoints(IReGameHook_CBasePlayer_AddPoints *chain, CBasePlayer *pthis, int score, BOOL bAllowNegativeScore) @@ -137,7 +137,7 @@ void CBasePlayer_AddPoints(IReGameHook_CBasePlayer_AddPoints *chain, CBasePlayer chain->callNext(_score, _bAllowNegativeScore); }; - callVoidForward(RG_CBasePlayer_AddPoints, original, pthis->entindex(), score, bAllowNegativeScore); + callVoidForward(RG_CBasePlayer_AddPoints, original, indexOfEdict(pthis->pev), score, bAllowNegativeScore); } void CBasePlayer_AddPointsToTeam(IReGameHook_CBasePlayer_AddPointsToTeam *chain, CBasePlayer *pthis, int score, BOOL bAllowNegativeScore) @@ -147,7 +147,7 @@ void CBasePlayer_AddPointsToTeam(IReGameHook_CBasePlayer_AddPointsToTeam *chain, chain->callNext(_score, _bAllowNegativeScore); }; - callVoidForward(RG_CBasePlayer_AddPointsToTeam, original, pthis->entindex(), score, bAllowNegativeScore); + callVoidForward(RG_CBasePlayer_AddPointsToTeam, original, indexOfEdict(pthis->pev), score, bAllowNegativeScore); } BOOL CBasePlayer_AddPlayerItem(IReGameHook_CBasePlayer_AddPlayerItem *chain, CBasePlayer *pthis, CBasePlayerItem *pItem) @@ -157,7 +157,7 @@ BOOL CBasePlayer_AddPlayerItem(IReGameHook_CBasePlayer_AddPlayerItem *chain, CBa return chain->callNext(getPrivate(_pItem)); }; - return callForward(RG_CBasePlayer_AddPlayerItem, original, pthis->entindex(), pItem->entindex()); + return callForward(RG_CBasePlayer_AddPlayerItem, original, indexOfEdict(pthis->pev), indexOfEdict(pItem->pev)); } BOOL CBasePlayer_RemovePlayerItem(IReGameHook_CBasePlayer_RemovePlayerItem *chain, CBasePlayer *pthis, CBasePlayerItem *pItem) @@ -167,7 +167,7 @@ BOOL CBasePlayer_RemovePlayerItem(IReGameHook_CBasePlayer_RemovePlayerItem *chai return chain->callNext(getPrivate(_pItem)); }; - return callForward(RG_CBasePlayer_RemovePlayerItem, original, pthis->entindex(), pItem->entindex()); + return callForward(RG_CBasePlayer_RemovePlayerItem, original, indexOfEdict(pthis->pev), indexOfEdict(pItem->pev)); } int CBasePlayer_GiveAmmo(IReGameHook_CBasePlayer_GiveAmmo *chain, CBasePlayer *pthis, int iAmount, char *szName, int iMax) @@ -177,7 +177,7 @@ int CBasePlayer_GiveAmmo(IReGameHook_CBasePlayer_GiveAmmo *chain, CBasePlayer *p return chain->callNext(_iAmount, _szName, _iMax); }; - return callForward(RG_CBasePlayer_GiveAmmo, original, pthis->entindex(), iAmount, szName, iMax); + return callForward(RG_CBasePlayer_GiveAmmo, original, indexOfEdict(pthis->pev), iAmount, szName, iMax); } void CBasePlayer_ResetMaxSpeed(IReGameHook_CBasePlayer_ResetMaxSpeed *chain, CBasePlayer *pthis) @@ -187,7 +187,7 @@ void CBasePlayer_ResetMaxSpeed(IReGameHook_CBasePlayer_ResetMaxSpeed *chain, CBa chain->callNext(); }; - callVoidForward(RG_CBasePlayer_ResetMaxSpeed, original, pthis->entindex()); + callVoidForward(RG_CBasePlayer_ResetMaxSpeed, original, indexOfEdict(pthis->pev)); } void CBasePlayer_Jump(IReGameHook_CBasePlayer_Jump *chain, CBasePlayer *pthis) @@ -197,7 +197,7 @@ void CBasePlayer_Jump(IReGameHook_CBasePlayer_Jump *chain, CBasePlayer *pthis) chain->callNext(); }; - callVoidForward(RG_CBasePlayer_Jump, original, pthis->entindex()); + callVoidForward(RG_CBasePlayer_Jump, original, indexOfEdict(pthis->pev)); } void CBasePlayer_Duck(IReGameHook_CBasePlayer_Duck *chain, CBasePlayer *pthis) @@ -207,7 +207,7 @@ void CBasePlayer_Duck(IReGameHook_CBasePlayer_Duck *chain, CBasePlayer *pthis) chain->callNext(); }; - callVoidForward(RG_CBasePlayer_Duck, original, pthis->entindex()); + callVoidForward(RG_CBasePlayer_Duck, original, indexOfEdict(pthis->pev)); } void CBasePlayer_PreThink(IReGameHook_CBasePlayer_PreThink *chain, CBasePlayer *pthis) @@ -217,7 +217,7 @@ void CBasePlayer_PreThink(IReGameHook_CBasePlayer_PreThink *chain, CBasePlayer * chain->callNext(); }; - callVoidForward(RG_CBasePlayer_PreThink, original, pthis->entindex()); + callVoidForward(RG_CBasePlayer_PreThink, original, indexOfEdict(pthis->pev)); } void CBasePlayer_PostThink(IReGameHook_CBasePlayer_PostThink *chain, CBasePlayer *pthis) @@ -227,7 +227,7 @@ void CBasePlayer_PostThink(IReGameHook_CBasePlayer_PostThink *chain, CBasePlayer chain->callNext(); }; - callVoidForward(RG_CBasePlayer_PostThink, original, pthis->entindex()); + callVoidForward(RG_CBasePlayer_PostThink, original, indexOfEdict(pthis->pev)); } void CBasePlayer_UpdateClientData(IReGameHook_CBasePlayer_UpdateClientData *chain, CBasePlayer *pthis) @@ -237,7 +237,7 @@ void CBasePlayer_UpdateClientData(IReGameHook_CBasePlayer_UpdateClientData *chai chain->callNext(); }; - callVoidForward(RG_CBasePlayer_UpdateClientData, original, pthis->entindex()); + callVoidForward(RG_CBasePlayer_UpdateClientData, original, indexOfEdict(pthis->pev)); } void CBasePlayer_ImpulseCommands(IReGameHook_CBasePlayer_ImpulseCommands *chain, CBasePlayer *pthis) @@ -247,7 +247,7 @@ void CBasePlayer_ImpulseCommands(IReGameHook_CBasePlayer_ImpulseCommands *chain, chain->callNext(); }; - callVoidForward(RG_CBasePlayer_ImpulseCommands, original, pthis->entindex()); + callVoidForward(RG_CBasePlayer_ImpulseCommands, original, indexOfEdict(pthis->pev)); } void CBasePlayer_RoundRespawn(IReGameHook_CBasePlayer_RoundRespawn *chain, CBasePlayer *pthis) @@ -257,7 +257,7 @@ void CBasePlayer_RoundRespawn(IReGameHook_CBasePlayer_RoundRespawn *chain, CBase chain->callNext(); }; - callVoidForward(RG_CBasePlayer_RoundRespawn, original, pthis->entindex()); + callVoidForward(RG_CBasePlayer_RoundRespawn, original, indexOfEdict(pthis->pev)); } void CBasePlayer_Blind(IReGameHook_CBasePlayer_Blind *chain, CBasePlayer *pthis, float flUntilTime, float flHoldTime, float flFadeTime, int iAlpha) @@ -267,7 +267,7 @@ void CBasePlayer_Blind(IReGameHook_CBasePlayer_Blind *chain, CBasePlayer *pthis, chain->callNext(_flUntilTime, _flHoldTime, _flFadeTime, _iAlpha); }; - callVoidForward(RG_CBasePlayer_Blind, original, pthis->entindex(), flUntilTime, flHoldTime, flFadeTime, iAlpha); + callVoidForward(RG_CBasePlayer_Blind, original, indexOfEdict(pthis->pev), flUntilTime, flHoldTime, flFadeTime, iAlpha); } CBaseEntity *CBasePlayer_Observer_IsValidTarget(IReGameHook_CBasePlayer_Observer_IsValidTarget *chain, CBasePlayer *pthis, int iPlayerIndex, bool bSameTeam) @@ -277,7 +277,7 @@ CBaseEntity *CBasePlayer_Observer_IsValidTarget(IReGameHook_CBasePlayer_Observer return chain->callNext(_iPlayerIndex, _bSameTeam); }; - return callForward(RG_CBasePlayer_Observer_IsValidTarget, original, pthis->entindex(), iPlayerIndex, bSameTeam); + return callForward(RG_CBasePlayer_Observer_IsValidTarget, original, indexOfEdict(pthis->pev), iPlayerIndex, bSameTeam); } void CBasePlayer_SetAnimation(IReGameHook_CBasePlayer_SetAnimation *chain, CBasePlayer *pthis, PLAYER_ANIM playerAnim) @@ -287,7 +287,7 @@ void CBasePlayer_SetAnimation(IReGameHook_CBasePlayer_SetAnimation *chain, CBase chain->callNext(_playerAnim); }; - callVoidForward(RG_CBasePlayer_SetAnimation, original, pthis->entindex(), playerAnim); + callVoidForward(RG_CBasePlayer_SetAnimation, original, indexOfEdict(pthis->pev), playerAnim); } void CBasePlayer_GiveDefaultItems(IReGameHook_CBasePlayer_GiveDefaultItems *chain, CBasePlayer *pthis) @@ -297,7 +297,7 @@ void CBasePlayer_GiveDefaultItems(IReGameHook_CBasePlayer_GiveDefaultItems *chai chain->callNext(); }; - callVoidForward(RG_CBasePlayer_GiveDefaultItems, original, pthis->entindex()); + callVoidForward(RG_CBasePlayer_GiveDefaultItems, original, indexOfEdict(pthis->pev)); } void CBasePlayer_GiveNamedItem(IReGameHook_CBasePlayer_GiveNamedItem *chain, CBasePlayer *pthis, const char *pszName) @@ -307,7 +307,7 @@ void CBasePlayer_GiveNamedItem(IReGameHook_CBasePlayer_GiveNamedItem *chain, CBa chain->callNext(_pszName); }; - callVoidForward(RG_CBasePlayer_GiveNamedItem, original, pthis->entindex(), pszName); + callVoidForward(RG_CBasePlayer_GiveNamedItem, original, indexOfEdict(pthis->pev), pszName); } void CBasePlayer_AddAccount(IReGameHook_CBasePlayer_AddAccount *chain, CBasePlayer *pthis, int amount, bool bTrackChange) @@ -317,7 +317,7 @@ void CBasePlayer_AddAccount(IReGameHook_CBasePlayer_AddAccount *chain, CBasePlay chain->callNext(_amount, _bTrackChange); }; - callVoidForward(RG_CBasePlayer_AddAccount, original, pthis->entindex(), amount, bTrackChange); + callVoidForward(RG_CBasePlayer_AddAccount, original, indexOfEdict(pthis->pev), amount, bTrackChange); } void CBasePlayer_GiveShield(IReGameHook_CBasePlayer_GiveShield *chain, CBasePlayer *pthis, bool bDeploy) @@ -327,7 +327,7 @@ void CBasePlayer_GiveShield(IReGameHook_CBasePlayer_GiveShield *chain, CBasePlay chain->callNext(_bDeploy); }; - callVoidForward(RG_CBasePlayer_GiveShield, original, pthis->entindex(), bDeploy); + callVoidForward(RG_CBasePlayer_GiveShield, original, indexOfEdict(pthis->pev), bDeploy); } void CBaseAnimating_ResetSequenceInfo(IReGameHook_CBaseAnimating_ResetSequenceInfo *chain, CBaseAnimating *pthis) @@ -337,7 +337,7 @@ void CBaseAnimating_ResetSequenceInfo(IReGameHook_CBaseAnimating_ResetSequenceIn chain->callNext(); }; - callVoidForward(RG_CBaseAnimating_ResetSequenceInfo, original, pthis->entindex()); + callVoidForward(RG_CBaseAnimating_ResetSequenceInfo, original, indexOfEdict(pthis->pev)); } int GetForceCamera(IReGameHook_GetForceCamera *chain, CBasePlayer *pObserver) @@ -347,7 +347,7 @@ int GetForceCamera(IReGameHook_GetForceCamera *chain, CBasePlayer *pObserver) return chain->callNext(getPrivate(_pObserver)); }; - return callForward(RG_GetForceCamera, original, pObserver->entindex()); + return callForward(RG_GetForceCamera, original, indexOfEdict(pObserver->pev)); } void PlayerBlind(IReGameHook_PlayerBlind *chain, CBasePlayer *pPlayer, entvars_t *pevInflictor, entvars_t *pevAttacker, float fadeTime, float fadeHold, int alpha, Vector& color) @@ -359,7 +359,7 @@ void PlayerBlind(IReGameHook_PlayerBlind *chain, CBasePlayer *pPlayer, entvars_t chain->callNext(getPrivate(_pPlayer), PEV(_pevInflictor), PEV(_pevAttacker), _fadeTime, _fadeHold, _alpha, colorCopy); }; - callVoidForward(RG_PlayerBlind, original, pPlayer->entindex(), indexOfEdict(pevInflictor), indexOfEdict(pevAttacker), fadeTime, fadeHold, alpha, g_amxxapi.PrepareCellArrayA(reinterpret_cast(&colorCopy), 3, true)); + callVoidForward(RG_PlayerBlind, original, indexOfEdict(pPlayer->pev), indexOfEdict(pevInflictor), indexOfEdict(pevAttacker), fadeTime, fadeHold, alpha, g_amxxapi.PrepareCellArrayA(reinterpret_cast(&colorCopy), 3, true)); } void RadiusFlash_TraceLine(IReGameHook_RadiusFlash_TraceLine *chain, CBasePlayer *pPlayer, entvars_t *pevInflictor, entvars_t *pevAttacker, Vector& vecSrc, Vector& vecSpot, TraceResult *ptr) @@ -371,7 +371,7 @@ void RadiusFlash_TraceLine(IReGameHook_RadiusFlash_TraceLine *chain, CBasePlayer chain->callNext(getPrivate(_pPlayer), PEV(_pevInflictor), PEV(_pevAttacker), vecSrcCopy, vecSpotCopy, _ptr); }; - callVoidForward(RG_RadiusFlash_TraceLine, original, pPlayer->entindex(), indexOfEdict(pevInflictor), indexOfEdict(pevAttacker), g_amxxapi.PrepareCellArrayA(reinterpret_cast(&vecSrcCopy), 3, true), g_amxxapi.PrepareCellArrayA(reinterpret_cast(&vecSpotCopy), 3, true), ptr); + callVoidForward(RG_RadiusFlash_TraceLine, original, indexOfEdict(pPlayer->pev), indexOfEdict(pevInflictor), indexOfEdict(pevAttacker), g_amxxapi.PrepareCellArrayA(reinterpret_cast(&vecSrcCopy), 3, true), g_amxxapi.PrepareCellArrayA(reinterpret_cast(&vecSpotCopy), 3, true), ptr); } bool RoundEnd(IReGameHook_RoundEnd *chain, int winStatus, ScenarioEventEndRound event, float tmDelay) @@ -384,6 +384,16 @@ bool RoundEnd(IReGameHook_RoundEnd *chain, int winStatus, ScenarioEventEndRound return callForward(RG_RoundEnd, original, winStatus, event, tmDelay); } +bool CanBuyThis(IReGameHook_CanBuyThis *chain, CBasePlayer *pPlayer, int iWeapon) +{ + auto original = [chain](int _pPlayer, int _iWeapon) + { + return chain->callNext(getPrivate(_pPlayer), _iWeapon); + }; + + return callForward(RG_CanBuyThis, original, indexOfEdict(pPlayer->pev), iWeapon); +} + int g_iClientStartSpeak, g_iClientStopSpeak; void ClientStartSpeak(size_t clientIndex) diff --git a/reapi/src/hook_callback.h b/reapi/src/hook_callback.h index b9d1605..8307552 100644 --- a/reapi/src/hook_callback.h +++ b/reapi/src/hook_callback.h @@ -203,6 +203,7 @@ int GetForceCamera(IReGameHook_GetForceCamera *chain, CBasePlayer *pObserver); void PlayerBlind(IReGameHook_PlayerBlind *chain, CBasePlayer *pPlayer, entvars_t *pevInflictor, entvars_t *pevAttacker, float fadeTime, float fadeHold, int alpha, Vector& color); void RadiusFlash_TraceLine(IReGameHook_RadiusFlash_TraceLine *chain, CBasePlayer *pPlayer, entvars_t *pevInflictor, entvars_t *pevAttacker, Vector& vecSrc, Vector& vecSpot, TraceResult *ptr); bool RoundEnd(IReGameHook_RoundEnd *chain, int winStatus, ScenarioEventEndRound event, float tmDelay); +bool CanBuyThis(IReGameHook_CanBuyThis *chain, CBasePlayer *pPlayer, int iWeapon); // regamedll functions - player void CBasePlayer_Spawn(IReGameHook_CBasePlayer_Spawn *chain, CBasePlayer *pthis); diff --git a/reapi/src/hook_list.cpp b/reapi/src/hook_list.cpp index dfdf1f1..82ddb31 100644 --- a/reapi/src/hook_list.cpp +++ b/reapi/src/hook_list.cpp @@ -73,7 +73,8 @@ hook_t hooklist_gamedll[] = { DLL(GetForceCamera), DLL(PlayerBlind), DLL(RadiusFlash_TraceLine), - DLL(RoundEnd) + DLL(RoundEnd), + DLL(CanBuyThis) }; hook_t hooklist_animating[] = { @@ -141,7 +142,6 @@ void hooklist_t::clear() h.clear(); } - void hook_t::clear() { if (pre.size() || post.size()) { diff --git a/reapi/src/hook_list.h b/reapi/src/hook_list.h index 3024150..355dada 100644 --- a/reapi/src/hook_list.h +++ b/reapi/src/hook_list.h @@ -79,6 +79,7 @@ enum GamedllFunc RG_PlayerBlind, RG_RadiusFlash_TraceLine, RG_RoundEnd, + RG_CanBuyThis, // [...] RG_End diff --git a/reapi/src/main.cpp b/reapi/src/main.cpp index 52b2e95..eea0c48 100644 --- a/reapi/src/main.cpp +++ b/reapi/src/main.cpp @@ -24,6 +24,10 @@ void OnMetaDetach() g_pVoiceTranscoderApi->ClientStartSpeak()->unregisterCallback(&ClientStartSpeak); g_pVoiceTranscoderApi->ClientStopSpeak()->unregisterCallback(&ClientStopSpeak); } + + if (api_cfg.hasReGameDLL()) { + g_ReGameHookchains->InstallGameRules()->unregisterHook(&InstallGameRules); + } } void ServerActivate_Post(edict_t *pEdictList, int edictCount, int clientMax) @@ -31,15 +35,19 @@ void ServerActivate_Post(edict_t *pEdictList, int edictCount, int clientMax) g_pEdicts = pEdictList; gmsgSendAudio = GET_USER_MSG_ID(PLID, "SendAudio", NULL); gmsgTeamScore = GET_USER_MSG_ID(PLID, "TeamScore", NULL); - api_cfg.ServerActivate(); SET_META_RESULT(MRES_IGNORED); } void ServerDeactivate_Post() { - api_cfg.ServerActivate(); + api_cfg.ServerDeactivate(); g_hookManager.clearHandlers(); SET_META_RESULT(MRES_IGNORED); } + +CGameRules *InstallGameRules(IReGameHook_InstallGameRules *chain) +{ + return g_pGameRules = chain->callNext(); +} diff --git a/reapi/src/main.h b/reapi/src/main.h index 7d06d20..3a7033c 100644 --- a/reapi/src/main.h +++ b/reapi/src/main.h @@ -10,3 +10,4 @@ void OnMetaDetach(); void ServerActivate_Post(edict_t *pEdictList, int edictCount, int clientMax); void ServerDeactivate_Post(); +CGameRules *InstallGameRules(IReGameHook_InstallGameRules *chain); diff --git a/reapi/src/mods/mod_regamedll_api.cpp b/reapi/src/mods/mod_regamedll_api.cpp index f95d239..c36b939 100644 --- a/reapi/src/mods/mod_regamedll_api.cpp +++ b/reapi/src/mods/mod_regamedll_api.cpp @@ -3,7 +3,7 @@ IReGameApi *g_ReGameApi; const ReGameFuncs_t *g_ReGameFuncs; IReGameHookchains *g_ReGameHookchains; -CHalfLifeMultiplay **g_pCSGameRules = nullptr; +CGameRules *g_pGameRules = nullptr; bool RegamedllApi_Init() { diff --git a/reapi/src/mods/mod_regamedll_api.h b/reapi/src/mods/mod_regamedll_api.h index 3b8ef09..e0d1ab3 100644 --- a/reapi/src/mods/mod_regamedll_api.h +++ b/reapi/src/mods/mod_regamedll_api.h @@ -3,6 +3,6 @@ extern IReGameApi *g_ReGameApi; extern const ReGameFuncs_t *g_ReGameFuncs; extern IReGameHookchains *g_ReGameHookchains; -extern CHalfLifeMultiplay **g_pCSGameRules; +extern CGameRules *g_pGameRules; extern bool RegamedllApi_Init(); diff --git a/reapi/src/mods/mod_reunion_api.cpp b/reapi/src/mods/mod_reunion_api.cpp new file mode 100644 index 0000000..66451b4 --- /dev/null +++ b/reapi/src/mods/mod_reunion_api.cpp @@ -0,0 +1,27 @@ +#include "precompiled.h" + +IReunionApi* g_ReunionApi; + +bool ReunionApi_Init() +{ + if (g_RehldsApi == nullptr) + return false; + + g_ReunionApi = (IReunionApi *)g_RehldsApi->GetFuncs()->GetPluginApi("reunion"); + + if (g_ReunionApi == nullptr) { + return false; + } + + if (g_ReunionApi->version_major != REUNION_API_VERSION_MAJOR) { + UTIL_LogPrintf("[%s]: Reunion Api major version mismatch; expected %d, real %d\n", Plugin_info.logtag, REUNION_API_VERSION_MAJOR, g_ReunionApi->version_major); + return false; + } + + if (g_ReunionApi->version_minor < REUNION_API_VERSION_MINOR) { + UTIL_LogPrintf("[%s]: Reunion Api minor version mismatch; expected at least %d, real %d\n", Plugin_info.logtag, REUNION_API_VERSION_MINOR, g_ReunionApi->version_minor); + return false; + } + + return true; +} diff --git a/reapi/src/mods/mod_reunion_api.h b/reapi/src/mods/mod_reunion_api.h new file mode 100644 index 0000000..e1317f3 --- /dev/null +++ b/reapi/src/mods/mod_reunion_api.h @@ -0,0 +1,5 @@ +#pragma once + +extern IReunionApi* g_ReunionApi; + +extern bool ReunionApi_Init(); diff --git a/reapi/src/natives/natives_hookchains.cpp b/reapi/src/natives/natives_hookchains.cpp index bff5a0a..a6712d0 100644 --- a/reapi/src/natives/natives_hookchains.cpp +++ b/reapi/src/natives/natives_hookchains.cpp @@ -197,7 +197,7 @@ cell AMX_NATIVE_CALL GetHookChainReturn(AMX *amx, cell *params) break; } case ATYPE_CLASSPTR: - *dstAddr = retVal._classptr->entindex(); + *dstAddr = indexOfEdict(retVal._classptr->pev); break; default: return FALSE; diff --git a/reapi/src/natives/natives_members.cpp b/reapi/src/natives/natives_members.cpp index cacdbc0..adee8fb 100644 --- a/reapi/src/natives/natives_members.cpp +++ b/reapi/src/natives/natives_members.cpp @@ -16,7 +16,7 @@ cell AMX_NATIVE_CALL set_member(AMX *amx, cell *params) MF_LogError(amx, AMX_ERR_NATIVE, "set_member: invalid or uninitialized entity"); return FALSE; } - + cell* value = getAmxAddr(amx, params[arg_value]); size_t element = (PARAMS_COUNT == 4) ? *getAmxAddr(amx, params[arg_elem]) : 0; @@ -78,7 +78,7 @@ cell AMX_NATIVE_CALL set_member_game(AMX *amx, cell *params) return FALSE; } - if (g_pCSGameRules == nullptr || *g_pCSGameRules == nullptr) { + if (g_pGameRules == nullptr) { MF_LogError(amx, AMX_ERR_NATIVE, "get_member_game: gamerules not initialized"); return FALSE; } @@ -86,7 +86,7 @@ cell AMX_NATIVE_CALL set_member_game(AMX *amx, cell *params) cell* value = getAmxAddr(amx, params[arg_value]); size_t element = (PARAMS_COUNT == 4) ? *getAmxAddr(amx, params[arg_elem]) : 0; - return set_member(*g_pCSGameRules, member, element, value); + return set_member(g_pGameRules, member, element, value); } // native get_member_game(any:_member, any:...); @@ -100,14 +100,14 @@ cell AMX_NATIVE_CALL get_member_game(AMX *amx, cell *params) return FALSE; } - if (g_pCSGameRules == nullptr || *g_pCSGameRules == nullptr) { + if (g_pGameRules == nullptr) { MF_LogError(amx, AMX_ERR_NATIVE, "get_member_game: gamerules not initialized"); return FALSE; } cell* dest; size_t element; - + if (PARAMS_COUNT == 4) { dest = getAmxAddr(amx, params[arg_3]); element = *getAmxAddr(amx, params[arg_4]); @@ -129,14 +129,14 @@ cell AMX_NATIVE_CALL get_member_game(AMX *amx, cell *params) element = 0; } - return get_member(*g_pCSGameRules, member, element, dest); + return get_member(g_pGameRules, member, element, dest); } AMX_NATIVE_INFO Member_Natives[] = { { "set_member", set_member }, { "get_member", get_member }, - + { "set_member_game", set_member_game }, { "get_member_game", get_member_game }, @@ -254,7 +254,7 @@ cell get_member(void* pdata, const member_t *member, size_t element, cell* dest) { case MEMBER_CLASSPTR: // native any:get_member(_index, any:_member, element); - return get_member(pdata, member->offset, element)->entindex(); + return indexOfEdict(get_member(pdata, member->offset, element)->pev); case MEMBER_EHANDLE: { // native any:get_member(_index, any:_member, element); diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 4b86208..e8146f5 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -21,7 +21,7 @@ cell AMX_NATIVE_CALL rg_set_animation(AMX *amx, cell *params) MF_LogError(amx, AMX_ERR_NATIVE, "player %i is not connected", params[arg_index]); return FALSE; } - + pPlayer->SetAnimation(CAmxArg(amx, params[arg_anim])); return TRUE; } @@ -94,7 +94,7 @@ cell AMX_NATIVE_CALL rg_give_default_items(AMX *amx, cell *params) enum args_e { arg_count, arg_index }; CHECK_ISPLAYER(params[arg_index]); - + ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); if (pPlayer == nullptr || !pPlayer->IsConnected()) { MF_LogError(amx, AMX_ERR_NATIVE, "player %i is not connected", params[arg_index]); @@ -384,7 +384,7 @@ cell AMX_NATIVE_CALL rg_round_end(AMX *amx, cell *params) if (_message[0]) g_ReGameFuncs->EndRoundMessage(_message, event); - (*g_pCSGameRules)->TerminateRound(CAmxArg(amx, params[arg_delay]), winstatus); + CSGameRules()->TerminateRound(CAmxArg(amx, params[arg_delay]), winstatus); return TRUE; } @@ -403,13 +403,227 @@ cell AMX_NATIVE_CALL rg_update_teamscores(AMX *amx, cell *params) { enum args_e { arg_count, arg_cts, arg_ts, arg_add }; - (*g_pCSGameRules)->m_iNumCTWins = ((params[arg_add] != 0) ? (*g_pCSGameRules)->m_iNumCTWins : 0) + params[arg_cts]; - (*g_pCSGameRules)->m_iNumTerroristWins = ((params[arg_add] != 0) ? (*g_pCSGameRules)->m_iNumTerroristWins : 0) + params[arg_ts]; + CSGameRules()->m_iNumCTWins = ((params[arg_add] != 0) ? CSGameRules()->m_iNumCTWins : 0) + params[arg_cts]; + CSGameRules()->m_iNumTerroristWins = ((params[arg_add] != 0) ? CSGameRules()->m_iNumTerroristWins : 0) + params[arg_ts]; UpdateTeamScores(); return TRUE; } +/* +* Creates an entity using Counter-Strike's custom CreateNamedEntity wrapper. +* +* @param classname Entity class name +* +* @return Index of the created entity or 0 otherwise +* +* native rg_create_entity(const classname[]); +*/ +cell AMX_NATIVE_CALL rg_create_entity(AMX *amx, cell *params) +{ + //g_ReGameFuncs->CREATE_NAMED_ENTITY2(); + enum args_e { arg_count, arg_classname }; + + string_t iClass = g_engfuncs.pfnAllocString(getAmxString(amx, params[arg_classname])); + edict_t *pEnt = g_ReGameFuncs->CREATE_NAMED_ENTITY2(iClass); + + if (!FNullEnt(pEnt)) + { + return ENTINDEX(pEnt); + } + + return 0; +} + +/* +* Finds an entity in the world using Counter-Strike's custom FindEntityByString wrapper. +* +* @param start_index Entity index to start searching from. -1 to start from the first entity +* @param classname Classname to search for +* +* @return Entity index > 0 if found, 0 otherwise +* +* native rg_find_ent_by_class(start_index, const classname[]); +*/ +cell AMX_NATIVE_CALL rg_find_ent_by_class(AMX *amx, cell *params) +{ + enum args_e { arg_count, arg_start_index, arg_classname }; + + CBaseEntity *pStartEntity = getPrivate(params[arg_start_index]); + const char* value = getAmxString(amx, params[arg_classname]); + + CBaseEntity *pEntity = g_ReGameFuncs->UTIL_FindEntityByString(pStartEntity, "classname", value); + + if (pEntity != nullptr && !FNullEnt(pEntity->edict())) + { + return indexOfEdict(pEntity->pev); + } + + return 0; +} + +/* +* Finds an entity in the world using Counter-Strike's custom FindEntityByString wrapper, matching by owner. +* +* @param start_index Entity index to start searching from. -1 to start from the first entity +* @param classname Classname to search for +* +* @return Entity index > 0 if found, 0 otherwise +* +* native rg_find_ent_by_owner(start_index, const classname[], owner); +*/ +cell AMX_NATIVE_CALL rg_find_ent_by_owner(AMX *amx, cell *params) +{ + enum args_e { arg_count, arg_start_index, arg_classname, arg_onwer }; + + CHECK_ISENTITY(params[arg_onwer]); + + CBaseEntity *pEntity = getPrivate(params[arg_start_index]); + const char* value = getAmxString(amx, params[arg_classname]); + + edict_t *pOwner = edictByIndex(params[arg_onwer]); + while ((pEntity = g_ReGameFuncs->UTIL_FindEntityByString(pEntity, "classname", value)) != nullptr) + { + if (pEntity != nullptr && !FNullEnt(pEntity->edict()) && pEntity->pev->owner == pOwner) + { + return indexOfEdict(pEntity->pev); + } + } + + return 0; +} + +/** +* Returns some information about a weapon. +* +* @param weapon_id Weapon id, see WEAPON_* constants +* @param type Info type, see WPINFO_* constants +* +* @return Weapon information value +* @error If weapon_id and type are out of bound, an error will be thrown. +* +* native rg_get_weapon_info(const {WeaponIdType,_}:weapon_id, WpnInfo:type, any:...); +*/ +cell AMX_NATIVE_CALL rg_get_weapon_info(AMX *amx, cell *params) +{ + enum args_e { arg_count, arg_weapon_id, arg_type, arg_3, arg_4 }; + + int weapon_id = params[arg_weapon_id]; + if (weapon_id <= WEAPON_NONE || weapon_id == WEAPON_C4 || weapon_id == WEAPON_KNIFE || weapon_id > WEAPON_P90) + { + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid weapon id %i", weapon_id); + return 0; + } + + WeaponInfoStruct *info = g_ReGameFuncs->GetWeaponInfo(weapon_id); + WpnInfo info_type = static_cast(params[arg_type]); + + switch (info_type) + { + case WPINFO_COST: + return info->cost; + case WPINFO_CLIP_COST: + return info->clipCost; + case WPINFO_BUY_CLIP_SIZE: + return info->buyClipSize; + case WPINFO_GUN_CLIP_SIZE: + return info->gunClipSize; + case WPINFO_MAX_ROUNDS: + return info->maxRounds; + case WPINFO_AMMO_TYPE: + return info->ammoType; + case WPINFO_NAME: + { + if (PARAMS_COUNT != arg_4) { + MF_LogError(amx, AMX_ERR_NATIVE, "rg_get_weapon_info: bad parameter count, got %i, expected %i", PARAMS_COUNT, arg_4); + return -1; + } + + // native rg_get_weapon_info(id, WPINFO_NAME, output[], maxlength); + cell* dest = getAmxAddr(amx, params[arg_3]); + size_t length = *getAmxAddr(amx, params[arg_4]); + setAmxString(dest, info->entityName, length); + return 1; + } + default: + { + MF_LogError(amx, AMX_ERR_NATIVE, "rg_get_weapon_info: unknown type statement %i, params count %i", info_type, PARAMS_COUNT); + return -1; + } + } +} + +/** +* Remove all the player's stuff +* +* @param index Client index +* +* @noreturn +* +* native rg_remove_all_items(const index, bool:bRemove); +*/ +cell AMX_NATIVE_CALL rg_remove_all_items(AMX *amx, cell *params) +{ + enum args_e { arg_count, arg_index, arg_suit }; + + CHECK_ISPLAYER(params[arg_index]); + + ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); + if (pPlayer == nullptr || !pPlayer->IsConnected()) { + MF_LogError(amx, AMX_ERR_NATIVE, "player %i is not connected", params[arg_index]); + return FALSE; + } + + pPlayer->RemoveAllItems(params[arg_suit] != 0); + return TRUE; +} + +/** +* Remove specifed the player's item by class name +* +* @param index Client index +* @param item_name Class name item +* +* @noreturn +* +* native rg_remove_item(const index, const item_name[]); +*/ +cell AMX_NATIVE_CALL rg_remove_item(AMX *amx, cell *params) +{ + enum args_e { arg_count, arg_index, arg_item_name }; + + CHECK_ISPLAYER(params[arg_index]); + + CBasePlayer *pPlayer = (CBasePlayer *)g_ReGameFuncs->UTIL_PlayerByIndex(params[arg_index]); + if (pPlayer == nullptr || pPlayer->has_disconnected) { + MF_LogError(amx, AMX_ERR_NATIVE, "player %i is not connected", params[arg_index]); + return FALSE; + } + + const char* szItemName = getAmxString(amx, params[arg_item_name]); + for (auto& item : pPlayer->m_rgpPlayerItems) + { + CBasePlayerItem *pItem = item; + while (pItem != nullptr) + { + if (FClassnameIs(pItem->pev, szItemName)) + { + CBasePlayerWeapon *pWeapon = static_cast(pItem); + if (pWeapon->IsWeapon()) { + pWeapon->RetireWeapon(); + } + + pPlayer->RemovePlayerItem(pItem); + return TRUE; + } + + pItem = pItem->m_pNext; + } + } + + return FALSE; +} + AMX_NATIVE_INFO Misc_Natives_RG[] = { { "rg_set_animation", rg_set_animation }, @@ -429,6 +643,97 @@ AMX_NATIVE_INFO Misc_Natives_RG[] = { "rg_round_end", rg_round_end }, { "rg_update_teamscores", rg_update_teamscores }, + { "rg_create_entity", rg_create_entity }, + { "rg_find_ent_by_class", rg_find_ent_by_class }, + { "rg_find_ent_by_owner", rg_find_ent_by_owner }, + { "rg_get_weapon_info", rg_get_weapon_info }, + + { "rg_remove_all_items", rg_remove_all_items }, + { "rg_remove_item", rg_remove_item }, + + { nullptr, nullptr } +}; + +enum client_auth +{ + /** + * Description: - + * Return type: int + * Params: get_client_data(const index, CA_PROTOCOL) + */ + CA_PROTOCOL, + + /** + * Description: - + * Return type: client_auth_type + * Params: get_client_data(const index, CA_TYPE) + */ + CA_TYPE, + + /** + * Description: - + * Return type: - + * Params: get_client_data(const index, CA_STRING, output[], maxlength) + */ + CA_STRING, +}; + +/* +* Get out information of the client +* +* @param index Client index +* @type to look enum client_auth +* +* native get_client_data(const index, client_auth:type, any:...); +*/ +cell AMX_NATIVE_CALL get_client_data(AMX *amx, cell *params) +{ + enum args_e { arg_count, arg_index, arg_type, arg_3, arg_4 }; + + CHECK_ISPLAYER(params[arg_index]); + + client_auth type = static_cast(params[arg_type]); + switch (type) + { + case CA_PROTOCOL: + { + // native get_client_data(id, CA_PROTOCOL); + return g_ReunionApi->GetClientProtocol(params[arg_index] - 1); + } + case CA_TYPE: + { + // native client_auth_type:get_client_data(id, CA_TYPE); + return g_ReunionApi->GetClientAuthtype(params[arg_index] - 1); + } + case CA_STRING: + { + if (PARAMS_COUNT != arg_4) { + MF_LogError(amx, AMX_ERR_NATIVE, "get_client_data: bad parameter count, got %i, expected %i", PARAMS_COUNT, arg_4); + return -1; + } + + // native get_client_data(id, CA_STRING, output[], maxlength); + cell* dest = getAmxAddr(amx, params[arg_3]); + size_t length = *getAmxAddr(amx, params[arg_4]); + + char data[128]; + g_ReunionApi->GetClientAuthdataString(params[arg_index] - 1, data, sizeof data); + setAmxString(dest, data, length); + + return 1; + } + default: + { + MF_LogError(amx, AMX_ERR_NATIVE, "get_client_data: unknown type statement %i, params count %i", type, PARAMS_COUNT); + return -1; + } + } +} + +AMX_NATIVE_INFO Misc_Natives_Reunion[] = +{ + { "get_client_data", get_client_data }, + { nullptr, nullptr } }; @@ -436,4 +741,7 @@ void RegisterNatives_Misc() { if (api_cfg.hasReGameDLL()) g_amxxapi.AddNatives(Misc_Natives_RG); + + if (api_cfg.hasReunion()) + g_amxxapi.AddNatives(Misc_Natives_Reunion); } diff --git a/reapi/src/natives/natives_misc.h b/reapi/src/natives/natives_misc.h index 9272719..e2ca32b 100644 --- a/reapi/src/natives/natives_misc.h +++ b/reapi/src/natives/natives_misc.h @@ -1,3 +1,14 @@ #pragma once +enum WpnInfo +{ + WPINFO_COST, + WPINFO_CLIP_COST, + WPINFO_BUY_CLIP_SIZE, + WPINFO_GUN_CLIP_SIZE, + WPINFO_MAX_ROUNDS, + WPINFO_AMMO_TYPE, + WPINFO_NAME +}; + void RegisterNatives_Misc(); diff --git a/reapi/src/precompiled.h b/reapi/src/precompiled.h index 12f71de..99b87d8 100644 --- a/reapi/src/precompiled.h +++ b/reapi/src/precompiled.h @@ -10,8 +10,6 @@ #include // std::vector #include -#include "main.h" -#include "reapi_utils.h" #include #include "osdep.h" // win32 vsnprintf, etc @@ -27,6 +25,9 @@ #include "regamedll_api.h" #include "mod_regamedll_api.h" +#include "main.h" +#include "reapi_utils.h" + // rehlds API #include "rehlds_api.h" #include "mod_rehlds_api.h" @@ -35,6 +36,10 @@ #include "vtc_api.h" #include "mod_vtc_api.h" +// Reunion API +#include "reunion_api.h" +#include "mod_reunion_api.h" + #include "api_config.h" #include "hook_manager.h" #include "hook_callback.h" diff --git a/reapi/src/reapi_utils.cpp b/reapi/src/reapi_utils.cpp index 73a5cc1..7ac1c4b 100644 --- a/reapi/src/reapi_utils.cpp +++ b/reapi/src/reapi_utils.cpp @@ -16,11 +16,11 @@ void UpdateTeamScores() { g_pengfuncsTable->pfnMessageBegin(MSG_ALL, gmsgTeamScore, NULL, NULL); g_pengfuncsTable->pfnWriteString("CT"); - g_pengfuncsTable->pfnWriteShort((*g_pCSGameRules)->m_iNumCTWins); + g_pengfuncsTable->pfnWriteShort(CSGameRules()->m_iNumCTWins); g_pengfuncsTable->pfnMessageEnd(); g_pengfuncsTable->pfnMessageBegin(MSG_ALL, gmsgTeamScore, NULL, NULL); g_pengfuncsTable->pfnWriteString("TERRORIST"); - g_pengfuncsTable->pfnWriteShort((*g_pCSGameRules)->m_iNumTerroristWins); + g_pengfuncsTable->pfnWriteShort(CSGameRules()->m_iNumTerroristWins); g_pengfuncsTable->pfnMessageEnd(); } From e0fb129f4df640bbbfd913c7cf4397f074101605 Mon Sep 17 00:00:00 2001 From: asmodai Date: Sat, 30 Apr 2016 21:02:30 +0300 Subject: [PATCH 04/13] Avoid unnecessary copying in rg_fire_bullets3 --- publish.gradle | 1 + reapi/src/natives/natives_helper.h | 14 +++++++++----- reapi/src/natives/natives_misc.cpp | 11 ++++++----- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/publish.gradle b/publish.gradle index 0ca227e..ee206ff 100644 --- a/publish.gradle +++ b/publish.gradle @@ -24,6 +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/') _copyFile('publish/libreapi_amxx_i386.so', 'publish/publishRoot/reapi/addons/amxmodx/modules/reapi_amxx_i386.so') copy { diff --git a/reapi/src/natives/natives_helper.h b/reapi/src/natives/natives_helper.h index 173f114..82ce7d4 100644 --- a/reapi/src/natives/natives_helper.h +++ b/reapi/src/natives/natives_helper.h @@ -7,7 +7,7 @@ class CAmxArg { public: CAmxArg(AMX* amx, cell value) : m_amx(amx), m_value(value) {} - operator float() const + operator float&() const { return *(float *)m_value; } @@ -17,9 +17,8 @@ public: } operator entvars_s*() const { - if (m_value < 0) - return nullptr; - return PEV(m_value); + auto pev = PEV(m_value); + return m_value < 0 ? nullptr : pev; } operator int() const { @@ -35,12 +34,17 @@ public: } operator CBaseEntity*() const { - return g_ReGameFuncs->UTIL_PlayerByIndex(m_value); + auto player = g_ReGameFuncs->UTIL_PlayerByIndex(m_value); + return m_value < 0 ? nullptr : player; } operator PLAYER_ANIM() const { return static_cast(m_value); } + operator ICSEntity*() const + { + return g_ReGameFuncs->INDEX_TO_CSENTITY(m_value); + } Vector& vector() const { diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index e8146f5..1b14acf 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -214,14 +214,14 @@ cell AMX_NATIVE_CALL rg_multidmg_add(AMX *amx, cell *params) CHECK_ISENTITY(params[arg_inflictor]); CHECK_ISENTITY(params[arg_victim]); - CAmxArgs args(amx, params); - if (params[arg_victim] < 0) { // null MF_LogError(amx, AMX_ERR_NATIVE, "rg_multidmg_add: victim == null"); return FALSE; } + CAmxArgs args(amx, params); g_ReGameFuncs->AddMultiDamage(args[arg_inflictor], args[arg_victim], args[arg_damage], args[arg_dmg_type]); + return TRUE; } @@ -251,7 +251,7 @@ cell AMX_NATIVE_CALL rg_fire_bullets(AMX *amx, cell *params) CHECK_ISENTITY(params[arg_attacker]); CAmxArgs args(amx, params); - ICSEntity *pInflictor = g_ReGameFuncs->INDEX_TO_CSENTITY(params[arg_inflictor]); + ICSEntity *pInflictor = args[arg_inflictor]; pInflictor->FireBullets ( @@ -297,7 +297,8 @@ cell AMX_NATIVE_CALL rg_fire_bullets3(AMX *amx, cell *params) CHECK_ISENTITY(params[arg_attacker]); CAmxArgs args(amx, params); - ICSEntity *pInflictor = g_ReGameFuncs->INDEX_TO_CSENTITY(params[arg_inflictor]); + ICSEntity *pInflictor = args[arg_inflictor]; + entvars_t *pAttacker = args[arg_attacker]; args[arg_out].vector() = pInflictor->FireBullets3 ( @@ -309,7 +310,7 @@ cell AMX_NATIVE_CALL rg_fire_bullets3(AMX *amx, cell *params) args[arg_bullet_type], args[arg_dmg], args[arg_range_mod], - args[arg_attacker], + pAttacker, args[arg_pistol], args[arg_rand] ); From 73c1151962486ed752089f24257842f17a44ac2c Mon Sep 17 00:00:00 2001 From: asmodai Date: Mon, 2 May 2016 17:51:19 +0300 Subject: [PATCH 05/13] Refactored project structure Natives optimization --- .../extra/amxmodx/scripting/include/reapi.inc | 6 +- .../{reapi_misc.inc => reapi_addons.inc} | 42 +++---- .../amxmodx/scripting/include/reapi_const.inc | 8 -- .../scripting/include/reapi_engine.inc | 30 +---- .../scripting/include/reapi_engine_const.inc | 35 ++++++ reapi/msvc/reapi.vcxproj | 7 +- reapi/msvc/reapi.vcxproj.filters | 23 ++-- reapi/src/amxxmodule.cpp | 2 +- .../{natives_vtc.cpp => natives_addons.cpp} | 44 ++++++- reapi/src/natives/natives_addons.h | 3 + reapi/src/natives/natives_misc.cpp | 108 ++---------------- reapi/src/natives/natives_vtc.h | 3 - reapi/src/precompiled.h | 2 +- 13 files changed, 128 insertions(+), 185 deletions(-) rename reapi/extra/amxmodx/scripting/include/{reapi_misc.inc => reapi_addons.inc} (60%) delete mode 100644 reapi/extra/amxmodx/scripting/include/reapi_const.inc create mode 100644 reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc rename reapi/src/natives/{natives_vtc.cpp => natives_addons.cpp} (58%) create mode 100644 reapi/src/natives/natives_addons.h delete mode 100644 reapi/src/natives/natives_vtc.h diff --git a/reapi/extra/amxmodx/scripting/include/reapi.inc b/reapi/extra/amxmodx/scripting/include/reapi.inc index 2770ef3..8adefb3 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi.inc @@ -13,10 +13,14 @@ #pragma library reapi #endif +// reapi version +#define REAPI_VERISON_MAJOR 1 +#define REAPI_VERISON_MINOR 0 + #include #include // NOTE: only for ReHLDS #include // NOTE: only for gamedll Counter-Strike (ReGameDLL_CS) -#include // NOTE: Common set of natives and forwards. +#include // NOTE: 3-rd party addons // hookchain return type enum diff --git a/reapi/extra/amxmodx/scripting/include/reapi_misc.inc b/reapi/extra/amxmodx/scripting/include/reapi_addons.inc similarity index 60% rename from reapi/extra/amxmodx/scripting/include/reapi_misc.inc rename to reapi/extra/amxmodx/scripting/include/reapi_addons.inc index 7b6a559..e18d990 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_misc.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_addons.inc @@ -1,31 +1,7 @@ -#if defined _reapi_misc_included +#if defined _reapi_addons_included #endinput #endif -#define _reapi_misc_included - -enum client_auth -{ - /** - * Description: - - * Return type: int - * Params: get_client_data(const index, CA_PROTOCOL) - */ - CA_PROTOCOL, - - /** - * Description: - - * Return type: client_auth_type - * Params: get_client_data(const index, CA_TYPE) - */ - CA_TYPE, - - /** - * Description: - - * Return type: - - * Params: get_client_data(const index, CA_STRING, output[], maxlength) - */ - CA_STRING, -}; +#define _reapi_addons_included enum client_auth_type { @@ -85,9 +61,17 @@ forward VTC_OnClientStartSpeak(index); forward VTC_OnClientStopSpeak(index); /* -* Get out information of the client +* Get client protocol * * @param index Client index -* @type to look enum client_auth +* @noreturn */ -native get_client_data(const index, client_auth:type, any:...); +native REU_GetProtocol(const index); + +/* +* Get client auth type +* +* @param index Client index +* @noreturn +*/ +native REU_GetAuthtype(const index); diff --git a/reapi/extra/amxmodx/scripting/include/reapi_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_const.inc deleted file mode 100644 index 16c7a3b..0000000 --- a/reapi/extra/amxmodx/scripting/include/reapi_const.inc +++ /dev/null @@ -1,8 +0,0 @@ -#if defined _reapi_const_included - #endinput -#endif -#define _reapi_const_included - -// reapi version -#define REAPI_VERISON_MAJOR 1 -#define REAPI_VERISON_MINOR 0 diff --git a/reapi/extra/amxmodx/scripting/include/reapi_engine.inc b/reapi/extra/amxmodx/scripting/include/reapi_engine.inc index 79c0e27..cf8391e 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_engine.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_engine.inc @@ -4,32 +4,4 @@ #define _reapi_engine_included -enum EngineFunc -{ - /** - * Description: - - * Params: (const recipients, const entity, const channel, const sample[], const volume, Float:attenuation, const fFlags, const pitch) - */ - RH_SV_StartSound = 0, - - /** - * Description: - - * Params: (const client, bool:crash, const fmt[]) - */ - RH_SV_DropClient, - - /** - * Description: - - * Params: (const runPhysics) - */ - RH_SV_ActivateServer, - - /** - * Description: - - * Params: (pcvar, const value[]) - */ - RH_Cvar_DirectSet, - - // [...] - RH_EngineFunc_End -}; +#include diff --git a/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc new file mode 100644 index 0000000..0a5b425 --- /dev/null +++ b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc @@ -0,0 +1,35 @@ +#if defined _reapi_engine_const_included + #endinput +#endif + +#define _reapi_engine_const_included + +enum EngineFunc +{ + /** + * Description: - + * Params: (const recipients, const entity, const channel, const sample[], const volume, Float:attenuation, const fFlags, const pitch) + */ + RH_SV_StartSound = 0, + + /** + * Description: - + * Params: (const client, bool:crash, const fmt[]) + */ + RH_SV_DropClient, + + /** + * Description: - + * Params: (const runPhysics) + */ + RH_SV_ActivateServer, + + /** + * Description: - + * Params: (pcvar, const value[]) + */ + RH_Cvar_DirectSet, + + // [...] + RH_EngineFunc_End +}; diff --git a/reapi/msvc/reapi.vcxproj b/reapi/msvc/reapi.vcxproj index 21d4318..641825d 100644 --- a/reapi/msvc/reapi.vcxproj +++ b/reapi/msvc/reapi.vcxproj @@ -210,7 +210,7 @@ - + @@ -249,7 +249,7 @@ - + Create Create @@ -264,9 +264,10 @@ + - + diff --git a/reapi/msvc/reapi.vcxproj.filters b/reapi/msvc/reapi.vcxproj.filters index 8b17e67..4cc46c6 100644 --- a/reapi/msvc/reapi.vcxproj.filters +++ b/reapi/msvc/reapi.vcxproj.filters @@ -636,9 +636,6 @@ src\natives - - src\natives - include @@ -651,6 +648,9 @@ src\mods + + src\natives + @@ -725,12 +725,12 @@ src\natives - - src\natives - src\mods + + src\natives + @@ -746,16 +746,19 @@ amxmodx\scripting\include - - amxmodx\scripting\include - amxmodx\scripting\include amxmodx\scripting\include - + + amxmodx\scripting\include + + + amxmodx\scripting\include + + amxmodx\scripting\include diff --git a/reapi/src/amxxmodule.cpp b/reapi/src/amxxmodule.cpp index ba2b93b..282d154 100644 --- a/reapi/src/amxxmodule.cpp +++ b/reapi/src/amxxmodule.cpp @@ -164,7 +164,7 @@ C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc) RegisterNatives_HookChains(); RegisterNatives_Members(); RegisterNatives_Misc(); - RegisterNatives_Vtc(); + RegisterNatives_Addons(); return AMXX_OK; } diff --git a/reapi/src/natives/natives_vtc.cpp b/reapi/src/natives/natives_addons.cpp similarity index 58% rename from reapi/src/natives/natives_vtc.cpp rename to reapi/src/natives/natives_addons.cpp index 4b018bf..0b513f5 100644 --- a/reapi/src/natives/natives_vtc.cpp +++ b/reapi/src/natives/natives_addons.cpp @@ -55,8 +55,50 @@ AMX_NATIVE_INFO Vtc_Natives[] = { nullptr, nullptr } }; -void RegisterNatives_Vtc() +/* +* Get client protocol +* +* @param index Client index +* +* native REU_GetProtocol(const index); +*/ +cell AMX_NATIVE_CALL REU_GetProtocol(AMX *amx, cell *params) +{ + enum args_e { arg_count, arg_index }; + + CHECK_ISPLAYER(params[arg_index]); + + return g_ReunionApi->GetClientProtocol(params[arg_index] - 1); +} + +/* +* Get client auth type +* +* @param index Client index +* +* native REU_GetAuthtype(const index); +*/ +cell AMX_NATIVE_CALL REU_GetAuthtype(AMX *amx, cell *params) +{ + enum args_e { arg_count, arg_index }; + + CHECK_ISPLAYER(params[arg_index]); + + return g_ReunionApi->GetClientAuthtype(params[arg_index] - 1); +} + +AMX_NATIVE_INFO Reunion_Natives[] = +{ + { "REU_GetProtocol", REU_GetProtocol }, + { "REU_GetAuthtype", REU_GetAuthtype }, + + { nullptr, nullptr } +}; + +void RegisterNatives_Addons() { if (api_cfg.hasVTC()) g_amxxapi.AddNatives(Vtc_Natives); + if (api_cfg.hasReunion()) + g_amxxapi.AddNatives(Reunion_Natives); } diff --git a/reapi/src/natives/natives_addons.h b/reapi/src/natives/natives_addons.h new file mode 100644 index 0000000..a4093f7 --- /dev/null +++ b/reapi/src/natives/natives_addons.h @@ -0,0 +1,3 @@ +#pragma once + +void RegisterNatives_Addons(); diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 1b14acf..418735e 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -310,7 +310,7 @@ cell AMX_NATIVE_CALL rg_fire_bullets3(AMX *amx, cell *params) args[arg_bullet_type], args[arg_dmg], args[arg_range_mod], - pAttacker, + pAttacker, // icc fix args[arg_pistol], args[arg_rand] ); @@ -428,7 +428,7 @@ cell AMX_NATIVE_CALL rg_create_entity(AMX *amx, cell *params) string_t iClass = g_engfuncs.pfnAllocString(getAmxString(amx, params[arg_classname])); edict_t *pEnt = g_ReGameFuncs->CREATE_NAMED_ENTITY2(iClass); - if (!FNullEnt(pEnt)) + if (pEnt != nullptr) { return ENTINDEX(pEnt); } @@ -452,10 +452,9 @@ cell AMX_NATIVE_CALL rg_find_ent_by_class(AMX *amx, cell *params) CBaseEntity *pStartEntity = getPrivate(params[arg_start_index]); const char* value = getAmxString(amx, params[arg_classname]); - CBaseEntity *pEntity = g_ReGameFuncs->UTIL_FindEntityByString(pStartEntity, "classname", value); - if (pEntity != nullptr && !FNullEnt(pEntity->edict())) + if (pEntity != nullptr) { return indexOfEdict(pEntity->pev); } @@ -479,16 +478,14 @@ cell AMX_NATIVE_CALL rg_find_ent_by_owner(AMX *amx, cell *params) CHECK_ISENTITY(params[arg_onwer]); - CBaseEntity *pEntity = getPrivate(params[arg_start_index]); const char* value = getAmxString(amx, params[arg_classname]); - edict_t *pOwner = edictByIndex(params[arg_onwer]); - while ((pEntity = g_ReGameFuncs->UTIL_FindEntityByString(pEntity, "classname", value)) != nullptr) + edict_t *pEntity = g_pEdicts; + + for (int i = 0; i < gpGlobals->maxEntities; i++, pEntity++) { - if (pEntity != nullptr && !FNullEnt(pEntity->edict()) && pEntity->pev->owner == pOwner) - { - return indexOfEdict(pEntity->pev); - } + if (pEntity->v.owner == pOwner && !strcmp(STRING(pEntity->v.classname), value)) + return i; } return 0; @@ -602,9 +599,8 @@ cell AMX_NATIVE_CALL rg_remove_item(AMX *amx, cell *params) } const char* szItemName = getAmxString(amx, params[arg_item_name]); - for (auto& item : pPlayer->m_rgpPlayerItems) + for (auto pItem : pPlayer->m_rgpPlayerItems) { - CBasePlayerItem *pItem = item; while (pItem != nullptr) { if (FClassnameIs(pItem->pev, szItemName)) @@ -655,94 +651,8 @@ AMX_NATIVE_INFO Misc_Natives_RG[] = { nullptr, nullptr } }; -enum client_auth -{ - /** - * Description: - - * Return type: int - * Params: get_client_data(const index, CA_PROTOCOL) - */ - CA_PROTOCOL, - - /** - * Description: - - * Return type: client_auth_type - * Params: get_client_data(const index, CA_TYPE) - */ - CA_TYPE, - - /** - * Description: - - * Return type: - - * Params: get_client_data(const index, CA_STRING, output[], maxlength) - */ - CA_STRING, -}; - -/* -* Get out information of the client -* -* @param index Client index -* @type to look enum client_auth -* -* native get_client_data(const index, client_auth:type, any:...); -*/ -cell AMX_NATIVE_CALL get_client_data(AMX *amx, cell *params) -{ - enum args_e { arg_count, arg_index, arg_type, arg_3, arg_4 }; - - CHECK_ISPLAYER(params[arg_index]); - - client_auth type = static_cast(params[arg_type]); - switch (type) - { - case CA_PROTOCOL: - { - // native get_client_data(id, CA_PROTOCOL); - return g_ReunionApi->GetClientProtocol(params[arg_index] - 1); - } - case CA_TYPE: - { - // native client_auth_type:get_client_data(id, CA_TYPE); - return g_ReunionApi->GetClientAuthtype(params[arg_index] - 1); - } - case CA_STRING: - { - if (PARAMS_COUNT != arg_4) { - MF_LogError(amx, AMX_ERR_NATIVE, "get_client_data: bad parameter count, got %i, expected %i", PARAMS_COUNT, arg_4); - return -1; - } - - // native get_client_data(id, CA_STRING, output[], maxlength); - cell* dest = getAmxAddr(amx, params[arg_3]); - size_t length = *getAmxAddr(amx, params[arg_4]); - - char data[128]; - g_ReunionApi->GetClientAuthdataString(params[arg_index] - 1, data, sizeof data); - setAmxString(dest, data, length); - - return 1; - } - default: - { - MF_LogError(amx, AMX_ERR_NATIVE, "get_client_data: unknown type statement %i, params count %i", type, PARAMS_COUNT); - return -1; - } - } -} - -AMX_NATIVE_INFO Misc_Natives_Reunion[] = -{ - { "get_client_data", get_client_data }, - - { nullptr, nullptr } -}; - void RegisterNatives_Misc() { if (api_cfg.hasReGameDLL()) g_amxxapi.AddNatives(Misc_Natives_RG); - - if (api_cfg.hasReunion()) - g_amxxapi.AddNatives(Misc_Natives_Reunion); } diff --git a/reapi/src/natives/natives_vtc.h b/reapi/src/natives/natives_vtc.h deleted file mode 100644 index d77db48..0000000 --- a/reapi/src/natives/natives_vtc.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -void RegisterNatives_Vtc(); diff --git a/reapi/src/precompiled.h b/reapi/src/precompiled.h index 99b87d8..879c965 100644 --- a/reapi/src/precompiled.h +++ b/reapi/src/precompiled.h @@ -48,7 +48,7 @@ #include "natives_hookchains.h" #include "natives_members.h" #include "natives_misc.h" -#include "natives_vtc.h" +#include "natives_addons.h" #include "natives_helper.h" #undef DLLEXPORT From 7414e479edfaee22a5ef8c957a28dae366924383 Mon Sep 17 00:00:00 2001 From: asmodai Date: Mon, 2 May 2016 18:21:28 +0300 Subject: [PATCH 06/13] Added arg name for native params checks Added NULLENT Fixed some checks --- .../extra/amxmodx/scripting/include/reapi.inc | 2 ++ reapi/msvc/reapi.vcxproj | 1 - reapi/msvc/reapi.vcxproj.filters | 3 -- reapi/src/natives/natives_addons.cpp | 4 +-- reapi/src/natives/natives_helper.h | 13 +++---- reapi/src/natives/natives_misc.cpp | 36 +++++++++---------- 6 files changed, 29 insertions(+), 30 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi.inc b/reapi/extra/amxmodx/scripting/include/reapi.inc index 8adefb3..70d895e 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi.inc @@ -17,6 +17,8 @@ #define REAPI_VERISON_MAJOR 1 #define REAPI_VERISON_MINOR 0 +#define NULLENT -1 + #include #include // NOTE: only for ReHLDS #include // NOTE: only for gamedll Counter-Strike (ReGameDLL_CS) diff --git a/reapi/msvc/reapi.vcxproj b/reapi/msvc/reapi.vcxproj index 641825d..713f35f 100644 --- a/reapi/msvc/reapi.vcxproj +++ b/reapi/msvc/reapi.vcxproj @@ -262,7 +262,6 @@ - diff --git a/reapi/msvc/reapi.vcxproj.filters b/reapi/msvc/reapi.vcxproj.filters index 4cc46c6..3c4e06b 100644 --- a/reapi/msvc/reapi.vcxproj.filters +++ b/reapi/msvc/reapi.vcxproj.filters @@ -743,9 +743,6 @@ src - - amxmodx\scripting\include - amxmodx\scripting\include diff --git a/reapi/src/natives/natives_addons.cpp b/reapi/src/natives/natives_addons.cpp index 0b513f5..5c050aa 100644 --- a/reapi/src/natives/natives_addons.cpp +++ b/reapi/src/natives/natives_addons.cpp @@ -66,7 +66,7 @@ cell AMX_NATIVE_CALL REU_GetProtocol(AMX *amx, cell *params) { enum args_e { arg_count, arg_index }; - CHECK_ISPLAYER(params[arg_index]); + CHECK_ISPLAYER(arg_index); return g_ReunionApi->GetClientProtocol(params[arg_index] - 1); } @@ -82,7 +82,7 @@ cell AMX_NATIVE_CALL REU_GetAuthtype(AMX *amx, cell *params) { enum args_e { arg_count, arg_index }; - CHECK_ISPLAYER(params[arg_index]); + CHECK_ISPLAYER(arg_index); return g_ReunionApi->GetClientAuthtype(params[arg_index] - 1); } diff --git a/reapi/src/natives/natives_helper.h b/reapi/src/natives/natives_helper.h index 82ce7d4..6a64097 100644 --- a/reapi/src/natives/natives_helper.h +++ b/reapi/src/natives/natives_helper.h @@ -1,13 +1,13 @@ #pragma once -#define CHECK_ISPLAYER(x) if (x <= 0 || x > gpGlobals->maxClients) { MF_LogError(amx, AMX_ERR_NATIVE, "invalid player index %i", x); return FALSE; } -#define CHECK_ISENTITY(x) if (x > gpGlobals->maxEntities) { MF_LogError(amx, AMX_ERR_NATIVE, "invalid entity index %i", x); return FALSE; } +#define CHECK_ISPLAYER(x) if (params[x] <= 0 || params[x] > gpGlobals->maxClients) { MF_LogError(amx, AMX_ERR_NATIVE, "invalid player index %i [%s]", params[x], #x); return FALSE; } +#define CHECK_ISENTITY(x) if (params[x] > gpGlobals->maxEntities) { MF_LogError(amx, AMX_ERR_NATIVE, "invalid entity index %i [%s]", params[x], #x); return FALSE; } class CAmxArg { public: CAmxArg(AMX* amx, cell value) : m_amx(amx), m_value(value) {} - operator float&() const + operator float() const { return *(float *)m_value; } @@ -17,7 +17,7 @@ public: } operator entvars_s*() const { - auto pev = PEV(m_value); + auto pev = PEV(m_value); // faster return m_value < 0 ? nullptr : pev; } operator int() const @@ -34,8 +34,9 @@ public: } operator CBaseEntity*() const { - auto player = g_ReGameFuncs->UTIL_PlayerByIndex(m_value); - return m_value < 0 ? nullptr : player; + if (m_value < 0) + return nullptr; + return g_ReGameFuncs->UTIL_PlayerByIndex(m_value); } operator PLAYER_ANIM() const { diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 418735e..7075013 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -14,7 +14,7 @@ cell AMX_NATIVE_CALL rg_set_animation(AMX *amx, cell *params) { enum args_e { arg_count, arg_index, arg_anim }; - CHECK_ISPLAYER(params[arg_index]); + CHECK_ISPLAYER(arg_index); ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); if (pPlayer == nullptr || !pPlayer->IsConnected()) { @@ -41,7 +41,7 @@ cell AMX_NATIVE_CALL rg_add_account(AMX *amx, cell *params) { enum args_e { arg_count, arg_index, arg_amount, arg_track_change }; - CHECK_ISPLAYER(params[arg_index]); + CHECK_ISPLAYER(arg_index); ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); if (pPlayer == nullptr || !pPlayer->IsConnected()) { @@ -67,7 +67,7 @@ cell AMX_NATIVE_CALL rg_give_item(AMX *amx, cell *params) { enum args_e { arg_count, arg_index, arg_item }; - CHECK_ISPLAYER(params[arg_index]); + CHECK_ISPLAYER(arg_index); ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); if (pPlayer == nullptr || !pPlayer->IsConnected()) { @@ -93,7 +93,7 @@ cell AMX_NATIVE_CALL rg_give_default_items(AMX *amx, cell *params) { enum args_e { arg_count, arg_index }; - CHECK_ISPLAYER(params[arg_index]); + CHECK_ISPLAYER(arg_index); ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); if (pPlayer == nullptr || !pPlayer->IsConnected()) { @@ -119,7 +119,7 @@ cell AMX_NATIVE_CALL rg_give_shield(AMX *amx, cell *params) { enum args_e { arg_count, arg_index, arg_deploy }; - CHECK_ISPLAYER(params[arg_index]); + CHECK_ISPLAYER(arg_index); ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); if (pPlayer == nullptr || !pPlayer->IsConnected()) { @@ -150,8 +150,8 @@ cell AMX_NATIVE_CALL rg_dmg_radius(AMX *amx, cell *params) { enum args_e { arg_count, arg_vec, arg_inflictor, arg_attacker, arg_damage, arg_radius, arg_ignore_class, arg_dmg_type }; - CHECK_ISENTITY(params[arg_inflictor]); - CHECK_ISENTITY(params[arg_attacker]); + CHECK_ISENTITY(arg_inflictor); + CHECK_ISENTITY(arg_attacker); CAmxArgs args(amx, params); g_ReGameFuncs->RadiusDamage(args[arg_vec], args[arg_inflictor], args[arg_attacker], args[arg_damage], args[arg_radius], args[arg_ignore_class], args[arg_dmg_type]); @@ -186,8 +186,8 @@ cell AMX_NATIVE_CALL rg_multidmg_apply(AMX *amx, cell *params) { enum args_e { arg_count, arg_inflictor, arg_attacker }; - CHECK_ISENTITY(params[arg_inflictor]); - CHECK_ISENTITY(params[arg_attacker]); + CHECK_ISENTITY(arg_inflictor); + CHECK_ISENTITY(arg_attacker); CAmxArgs args(amx, params); g_ReGameFuncs->ApplyMultiDamage(args[arg_inflictor], args[arg_attacker]); @@ -211,8 +211,8 @@ cell AMX_NATIVE_CALL rg_multidmg_add(AMX *amx, cell *params) { enum args_e { arg_count, arg_inflictor, arg_victim, arg_damage, arg_dmg_type }; - CHECK_ISENTITY(params[arg_inflictor]); - CHECK_ISENTITY(params[arg_victim]); + CHECK_ISENTITY(arg_inflictor); + CHECK_ISENTITY(arg_victim); if (params[arg_victim] < 0) { // null MF_LogError(amx, AMX_ERR_NATIVE, "rg_multidmg_add: victim == null"); @@ -247,8 +247,8 @@ cell AMX_NATIVE_CALL rg_fire_bullets(AMX *amx, cell *params) { enum args_e { arg_count, arg_inflictor, arg_attacker, arg_shots, arg_vecSrc, arg_dir, arg_spread, arg_dist, arg_bullet_type, arg_tracefrq, arg_dmg }; - CHECK_ISENTITY(params[arg_inflictor]); - CHECK_ISENTITY(params[arg_attacker]); + CHECK_ISENTITY(arg_inflictor); + CHECK_ISENTITY(arg_attacker); CAmxArgs args(amx, params); ICSEntity *pInflictor = args[arg_inflictor]; @@ -293,8 +293,8 @@ cell AMX_NATIVE_CALL rg_fire_bullets3(AMX *amx, cell *params) { enum args_e { arg_count, arg_inflictor, arg_attacker, arg_vecSrc, arg_dir, arg_spread, arg_dist, arg_penetration, arg_bullet_type, arg_dmg, arg_range_mod, arg_pistol, arg_rand, arg_out }; - CHECK_ISENTITY(params[arg_inflictor]); - CHECK_ISENTITY(params[arg_attacker]); + CHECK_ISENTITY(arg_inflictor); + CHECK_ISENTITY(arg_attacker); CAmxArgs args(amx, params); ICSEntity *pInflictor = args[arg_inflictor]; @@ -476,7 +476,7 @@ cell AMX_NATIVE_CALL rg_find_ent_by_owner(AMX *amx, cell *params) { enum args_e { arg_count, arg_start_index, arg_classname, arg_onwer }; - CHECK_ISENTITY(params[arg_onwer]); + CHECK_ISENTITY(arg_onwer); const char* value = getAmxString(amx, params[arg_classname]); edict_t *pOwner = edictByIndex(params[arg_onwer]); @@ -564,7 +564,7 @@ cell AMX_NATIVE_CALL rg_remove_all_items(AMX *amx, cell *params) { enum args_e { arg_count, arg_index, arg_suit }; - CHECK_ISPLAYER(params[arg_index]); + CHECK_ISPLAYER(arg_index); ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); if (pPlayer == nullptr || !pPlayer->IsConnected()) { @@ -590,7 +590,7 @@ cell AMX_NATIVE_CALL rg_remove_item(AMX *amx, cell *params) { enum args_e { arg_count, arg_index, arg_item_name }; - CHECK_ISPLAYER(params[arg_index]); + CHECK_ISPLAYER(arg_index); CBasePlayer *pPlayer = (CBasePlayer *)g_ReGameFuncs->UTIL_PlayerByIndex(params[arg_index]); if (pPlayer == nullptr || pPlayer->has_disconnected) { From e64210dee7a99ee740e671b7a38480c711e0725b Mon Sep 17 00:00:00 2001 From: asmodai Date: Tue, 3 May 2016 03:35:19 +0300 Subject: [PATCH 07/13] Unified style of the error messages Fixed typo in reapi version define --- .../extra/amxmodx/scripting/include/reapi.inc | 4 ++-- reapi/src/natives/natives_addons.cpp | 9 +++++++ reapi/src/natives/natives_helper.h | 4 ++-- reapi/src/natives/natives_hookchains.cpp | 24 +++++++++---------- reapi/src/natives/natives_members.cpp | 16 ++++++------- reapi/src/natives/natives_misc.cpp | 24 +++++++++---------- 6 files changed, 45 insertions(+), 36 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi.inc b/reapi/extra/amxmodx/scripting/include/reapi.inc index 70d895e..7389491 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi.inc @@ -14,8 +14,8 @@ #endif // reapi version -#define REAPI_VERISON_MAJOR 1 -#define REAPI_VERISON_MINOR 0 +#define REAPI_VERSION_MAJOR 1 +#define REAPI_VERSION_MINOR 0 #define NULLENT -1 diff --git a/reapi/src/natives/natives_addons.cpp b/reapi/src/natives/natives_addons.cpp index 5c050aa..e12d6a8 100644 --- a/reapi/src/natives/natives_addons.cpp +++ b/reapi/src/natives/natives_addons.cpp @@ -11,6 +11,9 @@ cell AMX_NATIVE_CALL VTC_IsClientSpeaking(AMX *amx, cell *params) { enum args_e { arg_count, arg_index }; + + CHECK_ISPLAYER(arg_index); + return g_pVoiceTranscoderApi->IsClientSpeaking((size_t)params[arg_index]); } @@ -25,6 +28,9 @@ cell AMX_NATIVE_CALL VTC_IsClientSpeaking(AMX *amx, cell *params) cell AMX_NATIVE_CALL VTC_MuteClient(AMX *amx, cell *params) { enum args_e { arg_count, arg_index }; + + CHECK_ISPLAYER(arg_index); + g_pVoiceTranscoderApi->MuteClient((size_t)params[arg_index]); return FALSE; @@ -41,6 +47,9 @@ cell AMX_NATIVE_CALL VTC_MuteClient(AMX *amx, cell *params) cell AMX_NATIVE_CALL VTC_UnmuteClient(AMX *amx, cell *params) { enum args_e { arg_count, arg_index }; + + CHECK_ISPLAYER(arg_index); + g_pVoiceTranscoderApi->UnmuteClient((size_t)params[arg_index]); return FALSE; diff --git a/reapi/src/natives/natives_helper.h b/reapi/src/natives/natives_helper.h index 6a64097..ee406de 100644 --- a/reapi/src/natives/natives_helper.h +++ b/reapi/src/natives/natives_helper.h @@ -1,7 +1,7 @@ #pragma once -#define CHECK_ISPLAYER(x) if (params[x] <= 0 || params[x] > gpGlobals->maxClients) { MF_LogError(amx, AMX_ERR_NATIVE, "invalid player index %i [%s]", params[x], #x); return FALSE; } -#define CHECK_ISENTITY(x) if (params[x] > gpGlobals->maxEntities) { MF_LogError(amx, AMX_ERR_NATIVE, "invalid entity index %i [%s]", params[x], #x); return FALSE; } +#define CHECK_ISPLAYER(x) if (params[x] <= 0 || params[x] > gpGlobals->maxClients) { MF_LogError(amx, AMX_ERR_NATIVE, "%s: invalid player index %i [%s]", __FUNCTION__, params[x], #x); return FALSE; } +#define CHECK_ISENTITY(x) if (params[x] > gpGlobals->maxEntities) { MF_LogError(amx, AMX_ERR_NATIVE, "%s: invalid entity index %i [%s]", __FUNCTION__, params[x], #x); return FALSE; } class CAmxArg { diff --git a/reapi/src/natives/natives_hookchains.cpp b/reapi/src/natives/natives_hookchains.cpp index a6712d0..6cf124b 100644 --- a/reapi/src/natives/natives_hookchains.cpp +++ b/reapi/src/natives/natives_hookchains.cpp @@ -22,13 +22,13 @@ cell AMX_NATIVE_CALL RegisterHookChain(AMX *amx, cell *params) if (hook == nullptr) { - MF_LogError(amx, AMX_ERR_NATIVE, "RegisterHookChain: function with id (%d) doesn't exist in current API version.", func); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: function with id (%d) doesn't exist in current API version.", __FUNCTION__, func); return 0; } if (!hook->checkRequirements()) { - MF_LogError(amx, AMX_ERR_NATIVE, "RegisterHookChain: function (%s) is not available, %s required", hook->func_name, hook->depend_name); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: function (%s) is not available, %s required", __FUNCTION__, hook->func_name, hook->depend_name); return 0; } @@ -36,14 +36,14 @@ cell AMX_NATIVE_CALL RegisterHookChain(AMX *amx, cell *params) const char *funcname = getAmxString(amx, params[arg_handler]); if (g_amxxapi.amx_FindPublic(amx, funcname, &funcid) != AMX_ERR_NONE) { - MF_LogError(amx, AMX_ERR_NATIVE, "RegisterHookChain: public function \"%s\" not found.", funcname); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: public function \"%s\" not found.", __FUNCTION__, funcname); return 0; } int fwid = hook->registerForward(amx, funcname); if (fwid == -1) { - MF_LogError(amx, AMX_ERR_NATIVE, "RegisterHookChain: register forward failed."); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: register forward failed.", __FUNCTION__); return 0; } @@ -68,7 +68,7 @@ cell AMX_NATIVE_CALL EnableHookChain(AMX *amx, cell *params) if (hook == nullptr) { - MF_LogError(amx, AMX_ERR_NATIVE, "EnableHookChain: invalid HookChain handle."); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: invalid HookChain handle.", __FUNCTION__); return FALSE; } @@ -93,7 +93,7 @@ cell AMX_NATIVE_CALL DisableHookChain(AMX *amx, cell *params) if (hook == nullptr) { - MF_LogError(amx, AMX_ERR_NATIVE, "DisableHookChain: invalid HookChain handle."); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: invalid HookChain handle.", __FUNCTION__); return FALSE; } @@ -115,7 +115,7 @@ cell AMX_NATIVE_CALL SetHookChainReturn(AMX *amx, cell *params) { if (!g_hookCtx) { - MF_LogError(amx, AMX_ERR_NATIVE, "Trying to set return value without active hook."); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: trying to set return value without active hook.", __FUNCTION__); return FALSE; } @@ -124,7 +124,7 @@ cell AMX_NATIVE_CALL SetHookChainReturn(AMX *amx, cell *params) if (params[arg_type] != retVal.type) { - MF_LogError(amx, AMX_ERR_NATIVE, "Trying to set incompatible return type."); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: trying to set return value with incompatible type.", __FUNCTION__); return FALSE; } @@ -173,7 +173,7 @@ cell AMX_NATIVE_CALL GetHookChainReturn(AMX *amx, cell *params) { if (!g_hookCtx) { - MF_LogError(amx, AMX_ERR_NATIVE, "Trying to get return value without active hook."); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: trying to get return value without active hook.", __FUNCTION__); return FALSE; } @@ -222,7 +222,7 @@ cell AMX_NATIVE_CALL SetHookChainArg(AMX *amx, cell *params) { if (!g_hookCtx) { - MF_LogError(amx, AMX_ERR_NATIVE, "Trying to get return value without active hook."); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: trying to get return value without active hook.", __FUNCTION__); return FALSE; } @@ -231,7 +231,7 @@ cell AMX_NATIVE_CALL SetHookChainArg(AMX *amx, cell *params) if (number >= g_hookCtx->args_count) { - MF_LogError(amx, AMX_ERR_NATIVE, "SetHookChainArg: can't set argument %i of hookchain with %i args.", params[arg_number], g_hookCtx->args_count); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: can't set argument %i of hookchain with %i args.", __FUNCTION__, params[arg_number], g_hookCtx->args_count); return FALSE; } @@ -239,7 +239,7 @@ cell AMX_NATIVE_CALL SetHookChainArg(AMX *amx, cell *params) if (params[arg_type] != type) { - MF_LogError(amx, AMX_ERR_NATIVE, "SetHookChainArg: invalid argument type provided."); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: invalid argument type provided.", __FUNCTION__); return FALSE; } diff --git a/reapi/src/natives/natives_members.cpp b/reapi/src/natives/natives_members.cpp index adee8fb..9d9b268 100644 --- a/reapi/src/natives/natives_members.cpp +++ b/reapi/src/natives/natives_members.cpp @@ -7,13 +7,13 @@ cell AMX_NATIVE_CALL set_member(AMX *amx, cell *params) member_t *member = memberlist[params[arg_member]]; if (member == nullptr) { - MF_LogError(amx, AMX_ERR_NATIVE, "set_member: unknown member id %i", params[arg_member]); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: unknown member id %i", __FUNCTION__, params[arg_member]); return FALSE; } edict_t *pEdict = INDEXENT(params[arg_index]); if (pEdict == nullptr || pEdict->pvPrivateData == nullptr) { - MF_LogError(amx, AMX_ERR_NATIVE, "set_member: invalid or uninitialized entity"); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: invalid or uninitialized entity", __FUNCTION__); return FALSE; } @@ -30,13 +30,13 @@ cell AMX_NATIVE_CALL get_member(AMX *amx, cell *params) member_t *member = memberlist[params[arg_member]]; if (member == nullptr) { - MF_LogError(amx, AMX_ERR_NATIVE, "get_member: unknown member id %i", params[arg_member]); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: unknown member id %i", __FUNCTION__, params[arg_member]); return FALSE; } edict_t *pEdict = INDEXENT(params[arg_index]); if (pEdict == nullptr || pEdict->pvPrivateData == nullptr) { - MF_LogError(amx, AMX_ERR_NATIVE, "get_member: invalid or uninitialized entity"); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: invalid or uninitialized entity", __FUNCTION__); return FALSE; } @@ -74,12 +74,12 @@ cell AMX_NATIVE_CALL set_member_game(AMX *amx, cell *params) member_t *member = memberlist[params[arg_member]]; if (member == nullptr) { - MF_LogError(amx, AMX_ERR_NATIVE, "set_member_game: unknown member id %i", params[arg_member]); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: unknown member id %i", __FUNCTION__, params[arg_member]); return FALSE; } if (g_pGameRules == nullptr) { - MF_LogError(amx, AMX_ERR_NATIVE, "get_member_game: gamerules not initialized"); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: gamerules not initialized", __FUNCTION__); return FALSE; } @@ -96,12 +96,12 @@ cell AMX_NATIVE_CALL get_member_game(AMX *amx, cell *params) member_t *member = memberlist[params[arg_member]]; if (member == nullptr) { - MF_LogError(amx, AMX_ERR_NATIVE, "get_member_game: unknown member id %i", params[arg_member]); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: unknown member id %i", __FUNCTION__, params[arg_member]); return FALSE; } if (g_pGameRules == nullptr) { - MF_LogError(amx, AMX_ERR_NATIVE, "get_member_game: gamerules not initialized"); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: gamerules not initialized", __FUNCTION__); return FALSE; } diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 7075013..ffa56c2 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -18,7 +18,7 @@ cell AMX_NATIVE_CALL rg_set_animation(AMX *amx, cell *params) ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); if (pPlayer == nullptr || !pPlayer->IsConnected()) { - MF_LogError(amx, AMX_ERR_NATIVE, "player %i is not connected", params[arg_index]); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: player %i is not connected", __FUNCTION__, params[arg_index]); return FALSE; } @@ -45,7 +45,7 @@ cell AMX_NATIVE_CALL rg_add_account(AMX *amx, cell *params) ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); if (pPlayer == nullptr || !pPlayer->IsConnected()) { - MF_LogError(amx, AMX_ERR_NATIVE, "player %i is not connected", params[arg_index]); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: player %i is not connected", __FUNCTION__, params[arg_index]); return FALSE; } @@ -71,7 +71,7 @@ cell AMX_NATIVE_CALL rg_give_item(AMX *amx, cell *params) ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); if (pPlayer == nullptr || !pPlayer->IsConnected()) { - MF_LogError(amx, AMX_ERR_NATIVE, "player %i is not connected", params[arg_index]); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: player %i is not connected", __FUNCTION__, params[arg_index]); return FALSE; } @@ -97,7 +97,7 @@ cell AMX_NATIVE_CALL rg_give_default_items(AMX *amx, cell *params) ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); if (pPlayer == nullptr || !pPlayer->IsConnected()) { - MF_LogError(amx, AMX_ERR_NATIVE, "player %i is not connected", params[arg_index]); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: player %i is not connected", __FUNCTION__, params[arg_index]); return FALSE; } @@ -123,7 +123,7 @@ cell AMX_NATIVE_CALL rg_give_shield(AMX *amx, cell *params) ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); if (pPlayer == nullptr || !pPlayer->IsConnected()) { - MF_LogError(amx, AMX_ERR_NATIVE, "player %i is not connected", params[arg_index]); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: player %i is not connected", __FUNCTION__, params[arg_index]); return FALSE; } @@ -215,7 +215,7 @@ cell AMX_NATIVE_CALL rg_multidmg_add(AMX *amx, cell *params) CHECK_ISENTITY(arg_victim); if (params[arg_victim] < 0) { // null - MF_LogError(amx, AMX_ERR_NATIVE, "rg_multidmg_add: victim == null"); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: victim == null", __FUNCTION__); return FALSE; } @@ -361,7 +361,7 @@ cell AMX_NATIVE_CALL rg_round_end(AMX *amx, cell *params) size_t winstatus = params[arg_win]; if (winstatus <= 0) { - MF_LogError(amx, AMX_ERR_NATIVE, "rg_round_end: unknown win-status %i", winstatus); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: unknown win status %i", __FUNCTION__, winstatus); return FALSE; } @@ -509,7 +509,7 @@ cell AMX_NATIVE_CALL rg_get_weapon_info(AMX *amx, cell *params) int weapon_id = params[arg_weapon_id]; if (weapon_id <= WEAPON_NONE || weapon_id == WEAPON_C4 || weapon_id == WEAPON_KNIFE || weapon_id > WEAPON_P90) { - MF_LogError(amx, AMX_ERR_NATIVE, "Invalid weapon id %i", weapon_id); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: invalid weapon id %i", __FUNCTION__, weapon_id); return 0; } @@ -533,7 +533,7 @@ cell AMX_NATIVE_CALL rg_get_weapon_info(AMX *amx, cell *params) case WPINFO_NAME: { if (PARAMS_COUNT != arg_4) { - MF_LogError(amx, AMX_ERR_NATIVE, "rg_get_weapon_info: bad parameter count, got %i, expected %i", PARAMS_COUNT, arg_4); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: bad parameter count, got %i, expected %i", __FUNCTION__, PARAMS_COUNT, arg_4); return -1; } @@ -545,7 +545,7 @@ cell AMX_NATIVE_CALL rg_get_weapon_info(AMX *amx, cell *params) } default: { - MF_LogError(amx, AMX_ERR_NATIVE, "rg_get_weapon_info: unknown type statement %i, params count %i", info_type, PARAMS_COUNT); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: unknown type statement %i, params count %i", __FUNCTION__, info_type, PARAMS_COUNT); return -1; } } @@ -568,7 +568,7 @@ cell AMX_NATIVE_CALL rg_remove_all_items(AMX *amx, cell *params) ICSPlayer *pPlayer = g_ReGameFuncs->INDEX_TO_CSPLAYER(params[arg_index]); if (pPlayer == nullptr || !pPlayer->IsConnected()) { - MF_LogError(amx, AMX_ERR_NATIVE, "player %i is not connected", params[arg_index]); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: player %i is not connected", __FUNCTION__, params[arg_index]); return FALSE; } @@ -594,7 +594,7 @@ cell AMX_NATIVE_CALL rg_remove_item(AMX *amx, cell *params) CBasePlayer *pPlayer = (CBasePlayer *)g_ReGameFuncs->UTIL_PlayerByIndex(params[arg_index]); if (pPlayer == nullptr || pPlayer->has_disconnected) { - MF_LogError(amx, AMX_ERR_NATIVE, "player %i is not connected", params[arg_index]); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: player %i is not connected", __FUNCTION__, params[arg_index]); return FALSE; } From c1c59ce26c05c65e019d04bac205800ea65f0b75 Mon Sep 17 00:00:00 2001 From: s1lentq Date: Tue, 3 May 2016 19:11:45 +0600 Subject: [PATCH 08/13] Added reapi_version.inc and other typos --- publish.gradle | 4 ++++ reapi/extra/amxmodx/scripting/include/reapi.inc | 6 +----- .../amxmodx/scripting/include/reapi_addons.inc | 16 ++++++++-------- .../scripting/include/reapi_gamedll_const.inc | 3 +-- reapi/extra/amxmodx/scripting/reapi_test.sma | 2 +- reapi/msvc/reapi.vcxproj | 2 +- reapi/msvc/reapi.vcxproj.filters | 6 +++--- reapi/src/amxxmodule.cpp | 2 +- reapi/src/api_config.h | 2 +- reapi/src/natives/natives_addons.cpp | 8 +++++--- reapi/src/natives/natives_helper.h | 8 +++++++- reapi/src/natives/natives_misc.cpp | 4 ++-- reapi/src/reapi_const.inc | 8 -------- reapi/src/reapi_utils.h | 6 +++++- reapi/src/reapi_version.inc | 8 ++++++++ 15 files changed, 48 insertions(+), 37 deletions(-) delete mode 100644 reapi/src/reapi_const.inc create mode 100644 reapi/src/reapi_version.inc diff --git a/publish.gradle b/publish.gradle index ee206ff..504e7dd 100644 --- a/publish.gradle +++ b/publish.gradle @@ -31,6 +31,10 @@ task publishPrepareFiles << { from 'reapi/extra' into 'publish/publishRoot/reapi/addons' } + copy { + from 'reapi/src/reapi_version.inc' + into 'publish/publishRoot/reapi/addons/amxmodx/scripting/include' + } } task publishPackage(type: Zip, dependsOn: 'publishPrepareFiles') { diff --git a/reapi/extra/amxmodx/scripting/include/reapi.inc b/reapi/extra/amxmodx/scripting/include/reapi.inc index 7389491..7021721 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi.inc @@ -13,16 +13,12 @@ #pragma library reapi #endif -// reapi version -#define REAPI_VERSION_MAJOR 1 -#define REAPI_VERSION_MINOR 0 - #define NULLENT -1 -#include #include // NOTE: only for ReHLDS #include // NOTE: only for gamedll Counter-Strike (ReGameDLL_CS) #include // NOTE: 3-rd party addons +#include // hookchain return type enum diff --git a/reapi/extra/amxmodx/scripting/include/reapi_addons.inc b/reapi/extra/amxmodx/scripting/include/reapi_addons.inc index e18d990..9c18f4b 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_addons.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_addons.inc @@ -26,7 +26,7 @@ enum client_auth_type * @return 1 if client is speaking, 0 otherwise * */ -native VTC_IsClientSpeaking(index); +native VTC_IsClientSpeaking(const index); /* * Mutes this player @@ -34,7 +34,7 @@ native VTC_IsClientSpeaking(index); * @param index Client index * @noreturn */ -native VTC_MuteClient(index); +native VTC_MuteClient(const index); /* * Unmutes this player @@ -42,7 +42,7 @@ native VTC_MuteClient(index); * @param index Client index * @noreturn */ -native VTC_UnmuteClient(index); +native VTC_UnmuteClient(const index); /* * Called when player started talking @@ -50,7 +50,7 @@ native VTC_UnmuteClient(index); * @param index Client index * @noreturn */ -forward VTC_OnClientStartSpeak(index); +forward VTC_OnClientStartSpeak(const index); /* * Called when player stopped talking @@ -58,13 +58,13 @@ forward VTC_OnClientStartSpeak(index); * @param index Client index * @noreturn */ -forward VTC_OnClientStopSpeak(index); +forward VTC_OnClientStopSpeak(const index); /* * Get client protocol * * @param index Client index -* @noreturn +* @return client protocol */ native REU_GetProtocol(const index); @@ -72,6 +72,6 @@ native REU_GetProtocol(const index); * Get client auth type * * @param index Client index -* @noreturn +* @return client auth type */ -native REU_GetAuthtype(const index); +native client_auth_type:REU_GetAuthtype(const index); diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc index 425e399..ce1e3dc 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc @@ -173,7 +173,6 @@ enum GamedllFunc_CBasePlayer */ RG_CBasePlayer_ObjectCaps, - /** * Description: - * Return type: int @@ -571,7 +570,7 @@ enum CSGameRules_Members m_bMapHasEscapeZone, /** - * Description: 0 = uninitialized, 1 = has VIP safety zone, 2 = DOES not have VIP safetyzone + * Description: 0 = uninitialized, 1 = has VIP safety zone, 2 = DOES not have VIP safetyzone * Member type: int * Get params: get_member_game(member); * Set params: set_member_game(member, value); diff --git a/reapi/extra/amxmodx/scripting/reapi_test.sma b/reapi/extra/amxmodx/scripting/reapi_test.sma index 650e0d7..05db926 100644 --- a/reapi/extra/amxmodx/scripting/reapi_test.sma +++ b/reapi/extra/amxmodx/scripting/reapi_test.sma @@ -4,7 +4,7 @@ public plugin_init() { register_plugin("ReAPI Test", "1.0", "s1lent"); - RegisterHookChain(RH_CBasePlayer_GiveAmmo, "CBasePlayer_GiveAmmo"); + RegisterHookChain(RG_CBasePlayer_GiveAmmo, "CBasePlayer_GiveAmmo"); } public CBasePlayer_GiveAmmo(const this, iAmount, szName[], iMax) diff --git a/reapi/msvc/reapi.vcxproj b/reapi/msvc/reapi.vcxproj index 713f35f..2ee6175 100644 --- a/reapi/msvc/reapi.vcxproj +++ b/reapi/msvc/reapi.vcxproj @@ -268,7 +268,7 @@ - + diff --git a/reapi/msvc/reapi.vcxproj.filters b/reapi/msvc/reapi.vcxproj.filters index 3c4e06b..7ca71ec 100644 --- a/reapi/msvc/reapi.vcxproj.filters +++ b/reapi/msvc/reapi.vcxproj.filters @@ -739,9 +739,6 @@ amxmodx\scripting - - src - amxmodx\scripting\include @@ -758,6 +755,9 @@ amxmodx\scripting\include + + src + diff --git a/reapi/src/amxxmodule.cpp b/reapi/src/amxxmodule.cpp index 282d154..a06c7aa 100644 --- a/reapi/src/amxxmodule.cpp +++ b/reapi/src/amxxmodule.cpp @@ -177,7 +177,7 @@ C_DLLEXPORT int AMXX_Detach() C_DLLEXPORT int AMXX_PluginsLoaded() { int iFwd = g_amxxapi.RegisterForward("__reapi_version_check", ET_IGNORE, FP_CELL, FP_CELL, FP_DONE); - g_amxxapi.ExecuteForward(iFwd, REAPI_VERISON_MAJOR, REAPI_VERISON_MINOR); + g_amxxapi.ExecuteForward(iFwd, REAPI_VERSION_MAJOR, REAPI_VERSION_MINOR); if (api_cfg.hasVTC()) { diff --git a/reapi/src/api_config.h b/reapi/src/api_config.h index 488cd73..531bc9c 100644 --- a/reapi/src/api_config.h +++ b/reapi/src/api_config.h @@ -1,7 +1,7 @@ #pragma once // reapi version -#include "reapi_const.inc" +#include "reapi_version.inc" class CAPI_Config { public: diff --git a/reapi/src/natives/natives_addons.cpp b/reapi/src/natives/natives_addons.cpp index e12d6a8..d28986a 100644 --- a/reapi/src/natives/natives_addons.cpp +++ b/reapi/src/natives/natives_addons.cpp @@ -6,7 +6,7 @@ * @param index Client index * @return 1 if client is speaking, 0 otherwise * -* native VTC_IsClientSpeaking(index); +* native VTC_IsClientSpeaking(const index); */ cell AMX_NATIVE_CALL VTC_IsClientSpeaking(AMX *amx, cell *params) { @@ -23,7 +23,7 @@ cell AMX_NATIVE_CALL VTC_IsClientSpeaking(AMX *amx, cell *params) * @param index Client index * @noreturn * -* native VTC_MuteClient(index); +* native VTC_MuteClient(const index); */ cell AMX_NATIVE_CALL VTC_MuteClient(AMX *amx, cell *params) { @@ -42,7 +42,7 @@ cell AMX_NATIVE_CALL VTC_MuteClient(AMX *amx, cell *params) * @param index Client index * @noreturn * -* native VTC_UnmuteClient(index); +* native VTC_UnmuteClient(const index); */ cell AMX_NATIVE_CALL VTC_UnmuteClient(AMX *amx, cell *params) { @@ -68,6 +68,7 @@ AMX_NATIVE_INFO Vtc_Natives[] = * Get client protocol * * @param index Client index +* @return client protocol * * native REU_GetProtocol(const index); */ @@ -84,6 +85,7 @@ cell AMX_NATIVE_CALL REU_GetProtocol(AMX *amx, cell *params) * Get client auth type * * @param index Client index +* @return client auth type * * native REU_GetAuthtype(const index); */ diff --git a/reapi/src/natives/natives_helper.h b/reapi/src/natives/natives_helper.h index ee406de..7666cc7 100644 --- a/reapi/src/natives/natives_helper.h +++ b/reapi/src/natives/natives_helper.h @@ -36,7 +36,13 @@ public: { if (m_value < 0) return nullptr; - return g_ReGameFuncs->UTIL_PlayerByIndex(m_value); + return getPrivate(m_value); + } + operator CBasePlayer*() const + { + if (m_value < 0) + return nullptr; + return static_cast(g_ReGameFuncs->UTIL_PlayerByIndex(m_value)); } operator PLAYER_ANIM() const { diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index ffa56c2..b9216a5 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -221,7 +221,7 @@ cell AMX_NATIVE_CALL rg_multidmg_add(AMX *amx, cell *params) CAmxArgs args(amx, params); g_ReGameFuncs->AddMultiDamage(args[arg_inflictor], args[arg_victim], args[arg_damage], args[arg_dmg_type]); - + return TRUE; } @@ -481,7 +481,7 @@ cell AMX_NATIVE_CALL rg_find_ent_by_owner(AMX *amx, cell *params) const char* value = getAmxString(amx, params[arg_classname]); edict_t *pOwner = edictByIndex(params[arg_onwer]); edict_t *pEntity = g_pEdicts; - + for (int i = 0; i < gpGlobals->maxEntities; i++, pEntity++) { if (pEntity->v.owner == pOwner && !strcmp(STRING(pEntity->v.classname), value)) diff --git a/reapi/src/reapi_const.inc b/reapi/src/reapi_const.inc deleted file mode 100644 index 16c7a3b..0000000 --- a/reapi/src/reapi_const.inc +++ /dev/null @@ -1,8 +0,0 @@ -#if defined _reapi_const_included - #endinput -#endif -#define _reapi_const_included - -// reapi version -#define REAPI_VERISON_MAJOR 1 -#define REAPI_VERISON_MINOR 0 diff --git a/reapi/src/reapi_utils.h b/reapi/src/reapi_utils.h index 5dd0c41..d70b548 100644 --- a/reapi/src/reapi_utils.h +++ b/reapi/src/reapi_utils.h @@ -27,7 +27,11 @@ inline edict_t* edictByIndex(size_t index) template T* getPrivate(int index) { - return (T *)edictByIndex(index)->pvPrivateData; + edict_t* pent = edictByIndex(index); + if (pent) + return (T *)pent->pvPrivateData; + + return nullptr; } inline entvars_t* PEV(int index) diff --git a/reapi/src/reapi_version.inc b/reapi/src/reapi_version.inc new file mode 100644 index 0000000..1183145 --- /dev/null +++ b/reapi/src/reapi_version.inc @@ -0,0 +1,8 @@ +#if defined _reapi_version_included + #endinput +#endif +#define _reapi_version_included + +// reapi version +#define REAPI_VERSION_MAJOR 1 +#define REAPI_VERSION_MINOR 0 From 88f0a66c0bc45bdb62ad356f09d0d424568e48a3 Mon Sep 17 00:00:00 2001 From: s1lentq Date: Tue, 3 May 2016 22:56:07 +0600 Subject: [PATCH 09/13] Changed work native rg_find_ent_by_owner. Added edictByIndexAmx for safe use. --- .../scripting/include/reapi_gamedll.inc | 4 +- .../scripting/include/reapi_gamedll_const.inc | 20 ++++---- reapi/src/hook_callback.cpp | 2 +- reapi/src/natives/natives_hookchains.cpp | 4 +- reapi/src/natives/natives_members.cpp | 20 ++++---- reapi/src/natives/natives_misc.cpp | 46 +++++++++++-------- reapi/src/natives/natives_misc.h | 14 +++--- reapi/src/reapi_utils.h | 18 +++++--- 8 files changed, 71 insertions(+), 57 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc index a6e65ce..275c191 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc @@ -228,10 +228,10 @@ native rg_find_ent_by_class(start_index, const classname[]); * @param start_index Entity index to start searching from. -1 to start from the first entity * @param classname Classname to search for * -* @return Entity index > 0 if found, 0 otherwise +* @return 1 if found, 0 otherwise * */ -native rg_find_ent_by_owner(start_index, const classname[], owner); +native rg_find_ent_by_owner(&start_index, const classname[], owner); /** * Returns some information about a weapon. diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc index ce1e3dc..3383611 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc @@ -11,6 +11,10 @@ #define SIGNAL_ESCAPE (1<<3) #define SIGNAL_VIPSAFETY (1<<4) +// Returns 1, if round ended by expired time +// NOTE: Use this for hookchain RG_RoundEnd with the parametr ScenarioEventEndRound:event +#define HadRoundExpired(event) (1<callNext(_recipients, INDEXENT(_entity), _channel, _sample, _volume, _attenuation, _fFlags, _pitch); + chain->callNext(_recipients, edictByIndexAmx(_entity), _channel, _sample, _volume, _attenuation, _fFlags, _pitch); }; callVoidForward(RH_SV_StartSound, original, recipients, indexOfEdict(entity), channel, sample, volume, attenuation, fFlags, pitch); diff --git a/reapi/src/natives/natives_hookchains.cpp b/reapi/src/natives/natives_hookchains.cpp index 6cf124b..98db2c3 100644 --- a/reapi/src/natives/natives_hookchains.cpp +++ b/reapi/src/natives/natives_hookchains.cpp @@ -148,7 +148,7 @@ cell AMX_NATIVE_CALL SetHookChainReturn(AMX *amx, cell *params) break; } case ATYPE_CLASSPTR: - retVal._classptr = CBaseEntity::Instance(INDEXENT(*srcAddr)); + retVal._classptr = getPrivate(*srcAddr); break; default: return FALSE; @@ -258,7 +258,7 @@ cell AMX_NATIVE_CALL SetHookChainArg(AMX *amx, cell *params) *(char **)destAddr = getAmxStringTemp(srcAddr, temp_strings[number], sizeof temp_strings[0] - 1); break; case ATYPE_CLASSPTR: - *(CBaseEntity **)destAddr = CBaseEntity::Instance(INDEXENT(*srcAddr)); + *(CBaseEntity **)destAddr = getPrivate(*srcAddr); break; } diff --git a/reapi/src/natives/natives_members.cpp b/reapi/src/natives/natives_members.cpp index 9d9b268..fa98f8e 100644 --- a/reapi/src/natives/natives_members.cpp +++ b/reapi/src/natives/natives_members.cpp @@ -11,7 +11,7 @@ cell AMX_NATIVE_CALL set_member(AMX *amx, cell *params) return FALSE; } - edict_t *pEdict = INDEXENT(params[arg_index]); + edict_t *pEdict = edictByIndexAmx(params[arg_index]); if (pEdict == nullptr || pEdict->pvPrivateData == nullptr) { MF_LogError(amx, AMX_ERR_NATIVE, "%s: invalid or uninitialized entity", __FUNCTION__); return FALSE; @@ -34,7 +34,7 @@ cell AMX_NATIVE_CALL get_member(AMX *amx, cell *params) return FALSE; } - edict_t *pEdict = INDEXENT(params[arg_index]); + edict_t *pEdict = edictByIndexAmx(params[arg_index]); if (pEdict == nullptr || pEdict->pvPrivateData == nullptr) { MF_LogError(amx, AMX_ERR_NATIVE, "%s: invalid or uninitialized entity", __FUNCTION__); return FALSE; @@ -155,7 +155,7 @@ BOOL set_member(void* pdata, const member_t *member, size_t element, cell* value case MEMBER_CLASSPTR: { // native set_member(_index, any:_member, _value, _elem); - CBaseEntity *pEntity = CBaseEntity::Instance(INDEXENT(*value)); + CBaseEntity *pEntity = getPrivate(*value); set_member(pdata, member->offset, pEntity, element); return TRUE; } @@ -163,14 +163,14 @@ BOOL set_member(void* pdata, const member_t *member, size_t element, cell* value { // native set_member(_index, any:_member, _value, _elem); EHANDLE& ehandle = get_member(pdata, member->offset, element); - edict_t *pEdictValue = INDEXENT(*value); + edict_t *pEdictValue = edictByIndexAmx(*value); ehandle.Set(pEdictValue); return TRUE; } case MEMBER_EDICT: { // native set_member(_index, any:_member, _value, _elem); - edict_t *pEdictValue = INDEXENT(*value); + edict_t *pEdictValue = edictByIndexAmx(*value); set_member(pdata, member->offset, pEdictValue, element); return TRUE; } @@ -261,7 +261,7 @@ cell get_member(void* pdata, const member_t *member, size_t element, cell* dest) EHANDLE ehandle = get_member(pdata, member->offset, element); edict_t *pEntity = ehandle.Get(); if (pEntity != nullptr) { - return ENTINDEX(pEntity); + return indexOfEdict(pEntity); } return -1; } @@ -270,7 +270,7 @@ cell get_member(void* pdata, const member_t *member, size_t element, cell* dest) // native any:get_member(_index, any:_member, element); edict_t *pEntity = get_member(pdata, member->offset, element); if (pEntity != nullptr) { - return ENTINDEX(pEntity); + return indexOfEdict(pEntity); } return -1; @@ -281,11 +281,7 @@ cell get_member(void* pdata, const member_t *member, size_t element, cell* dest) if (!dest) return 0; - cell* vecSrc = get_member_direct(pdata, member->offset, element); - - dest[0] = vecSrc[0]; - dest[1] = vecSrc[1]; - dest[2] = vecSrc[2]; + dest = get_member_direct(pdata, member->offset, element); return 1; } case MEMBER_STRING: diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index b9216a5..7dad29c 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -422,7 +422,6 @@ cell AMX_NATIVE_CALL rg_update_teamscores(AMX *amx, cell *params) */ cell AMX_NATIVE_CALL rg_create_entity(AMX *amx, cell *params) { - //g_ReGameFuncs->CREATE_NAMED_ENTITY2(); enum args_e { arg_count, arg_classname }; string_t iClass = g_engfuncs.pfnAllocString(getAmxString(amx, params[arg_classname])); @@ -430,7 +429,7 @@ cell AMX_NATIVE_CALL rg_create_entity(AMX *amx, cell *params) if (pEnt != nullptr) { - return ENTINDEX(pEnt); + return indexOfEdict(pEnt); } return 0; @@ -468,9 +467,9 @@ cell AMX_NATIVE_CALL rg_find_ent_by_class(AMX *amx, cell *params) * @param start_index Entity index to start searching from. -1 to start from the first entity * @param classname Classname to search for * -* @return Entity index > 0 if found, 0 otherwise +* @return 1 if found, 0 otherwise * -* native rg_find_ent_by_owner(start_index, const classname[], owner); +* native rg_find_ent_by_owner(&start_index, const classname[], owner); */ cell AMX_NATIVE_CALL rg_find_ent_by_owner(AMX *amx, cell *params) { @@ -478,24 +477,35 @@ cell AMX_NATIVE_CALL rg_find_ent_by_owner(AMX *amx, cell *params) CHECK_ISENTITY(arg_onwer); + cell& startIndex = *getAmxAddr(amx, params[arg_start_index]); const char* value = getAmxString(amx, params[arg_classname]); - edict_t *pOwner = edictByIndex(params[arg_onwer]); - edict_t *pEntity = g_pEdicts; + edict_t* pOwner = edictByIndexAmx(params[arg_onwer]); + edict_t* pEntity = &g_pEdicts[startIndex]; - for (int i = 0; i < gpGlobals->maxEntities; i++, pEntity++) + for (int i = startIndex; i < gpGlobals->maxEntities; i++, pEntity++) { - if (pEntity->v.owner == pOwner && !strcmp(STRING(pEntity->v.classname), value)) - return i; + if (pEntity->v.owner != pOwner) + continue; + + // yet not allocated + if (!pEntity->pvPrivateData || pEntity->free) + continue; + + if (!strcmp(STRING(pEntity->v.classname), value)) + { + startIndex = i; + return TRUE; + } } - return 0; + return FALSE; } /** * Returns some information about a weapon. * * @param weapon_id Weapon id, see WEAPON_* constants -* @param type Info type, see WPINFO_* constants +* @param type Info type, see WI_* constants * * @return Weapon information value * @error If weapon_id and type are out of bound, an error will be thrown. @@ -518,19 +528,19 @@ cell AMX_NATIVE_CALL rg_get_weapon_info(AMX *amx, cell *params) switch (info_type) { - case WPINFO_COST: + case WI_COST: return info->cost; - case WPINFO_CLIP_COST: + case WI_CLIP_COST: return info->clipCost; - case WPINFO_BUY_CLIP_SIZE: + case WI_BUY_CLIP_SIZE: return info->buyClipSize; - case WPINFO_GUN_CLIP_SIZE: + case WI_GUN_CLIP_SIZE: return info->gunClipSize; - case WPINFO_MAX_ROUNDS: + case WI_MAX_ROUNDS: return info->maxRounds; - case WPINFO_AMMO_TYPE: + case WI_AMMO_TYPE: return info->ammoType; - case WPINFO_NAME: + case WI_NAME: { if (PARAMS_COUNT != arg_4) { MF_LogError(amx, AMX_ERR_NATIVE, "%s: bad parameter count, got %i, expected %i", __FUNCTION__, PARAMS_COUNT, arg_4); diff --git a/reapi/src/natives/natives_misc.h b/reapi/src/natives/natives_misc.h index e2ca32b..fd6154b 100644 --- a/reapi/src/natives/natives_misc.h +++ b/reapi/src/natives/natives_misc.h @@ -2,13 +2,13 @@ enum WpnInfo { - WPINFO_COST, - WPINFO_CLIP_COST, - WPINFO_BUY_CLIP_SIZE, - WPINFO_GUN_CLIP_SIZE, - WPINFO_MAX_ROUNDS, - WPINFO_AMMO_TYPE, - WPINFO_NAME + WI_COST, + WI_CLIP_COST, + WI_BUY_CLIP_SIZE, + WI_GUN_CLIP_SIZE, + WI_MAX_ROUNDS, + WI_AMMO_TYPE, + WI_NAME }; void RegisterNatives_Misc(); diff --git a/reapi/src/reapi_utils.h b/reapi/src/reapi_utils.h index d70b548..825f521 100644 --- a/reapi/src/reapi_utils.h +++ b/reapi/src/reapi_utils.h @@ -19,7 +19,15 @@ inline size_t indexOfEdict(entvars_t* pev) return indexOfEdict(pev->pContainingEntity); } -inline edict_t* edictByIndex(size_t index) +// safe to index -1 +inline edict_t* edictByIndexAmx(int index) +{ + auto ed = g_pEdicts + index; + return index < 0 ? nullptr : ed; +} + +// fast +inline edict_t* edictByIndex(int index) { return g_pEdicts + index; } @@ -27,16 +35,12 @@ inline edict_t* edictByIndex(size_t index) template T* getPrivate(int index) { - edict_t* pent = edictByIndex(index); - if (pent) - return (T *)pent->pvPrivateData; - - return nullptr; + return (T *)GET_PRIVATE(edictByIndexAmx(index)); } inline entvars_t* PEV(int index) { - return &edictByIndex(index)->v; + return VARS(edictByIndexAmx(index)); } // HLTypeConversion.h -> AMXModX From 37145904341fbce7767d9724d3d66792706ef744 Mon Sep 17 00:00:00 2001 From: s1lentq Date: Wed, 4 May 2016 17:39:34 +0600 Subject: [PATCH 10/13] Added natives rg_set_weapon_info --- .../scripting/include/reapi_gamedll.inc | 11 +++ reapi/include/cssdk/dlls/regamedll_api.h | 1 - .../include/cssdk/dlls/regamedll_interfaces.h | 3 +- reapi/include/cssdk/dlls/weapontype.h | 1 + reapi/src/natives/natives_misc.cpp | 76 ++++++++++++++++--- 5 files changed, 79 insertions(+), 13 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc index 275c191..53a3405 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc @@ -245,6 +245,17 @@ native rg_find_ent_by_owner(&start_index, const classname[], owner); */ native rg_get_weapon_info(const {WeaponIdType,_}:weapon_id, WpnInfo:type, any:...); +/** +* Sets specific values of weapons info. +* +* @param weapon_id Weapon id, see WEAPON_* constants +* @param type Info type, see WI_* constants +* +* @return 1 if successfully, 0 otherwise +* +*/ +native rg_set_weapon_info(const {WeaponIdType,_}:weapon_id, WpnInfo:type, any:...); + /** * Remove specifed the player's item by class name * diff --git a/reapi/include/cssdk/dlls/regamedll_api.h b/reapi/include/cssdk/dlls/regamedll_api.h index dda1fc2..716c5f1 100644 --- a/reapi/include/cssdk/dlls/regamedll_api.h +++ b/reapi/include/cssdk/dlls/regamedll_api.h @@ -246,7 +246,6 @@ struct ReGameFuncs_t { void (*EndRoundMessage)(const char *sentence, int event); class CBaseEntity *(*UTIL_FindEntityByString)(class CBaseEntity *pStartEntity, const char *szKeyword, const char *szValue); - struct WeaponInfoStruct *(*GetWeaponInfo)(int weaponID); }; class IReGameApi { diff --git a/reapi/include/cssdk/dlls/regamedll_interfaces.h b/reapi/include/cssdk/dlls/regamedll_interfaces.h index 8abddd4..aced5e1 100644 --- a/reapi/include/cssdk/dlls/regamedll_interfaces.h +++ b/reapi/include/cssdk/dlls/regamedll_interfaces.h @@ -2076,5 +2076,6 @@ class IReGameData { public: virtual ~IReGameData() {} - virtual class CGameRules** GetGameRules() = 0; + virtual class CGameRules* GetGameRules() = 0; + virtual struct WeaponInfoStruct *GetWeaponInfo(int weaponID) = 0; }; diff --git a/reapi/include/cssdk/dlls/weapontype.h b/reapi/include/cssdk/dlls/weapontype.h index c185b3e..8b1bd82 100644 --- a/reapi/include/cssdk/dlls/weapontype.h +++ b/reapi/include/cssdk/dlls/weapontype.h @@ -399,4 +399,5 @@ struct WeaponInfoStruct int maxRounds; int ammoType; char *entityName; + const char *ammoName; }; diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 7dad29c..f5c9394 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -523,23 +523,23 @@ cell AMX_NATIVE_CALL rg_get_weapon_info(AMX *amx, cell *params) return 0; } - WeaponInfoStruct *info = g_ReGameFuncs->GetWeaponInfo(weapon_id); + WeaponInfoStruct *info = g_ReGameApi->GetGameData()->GetWeaponInfo(weapon_id); WpnInfo info_type = static_cast(params[arg_type]); switch (info_type) { case WI_COST: - return info->cost; + return info->cost; case WI_CLIP_COST: - return info->clipCost; + return info->clipCost; case WI_BUY_CLIP_SIZE: - return info->buyClipSize; + return info->buyClipSize; case WI_GUN_CLIP_SIZE: - return info->gunClipSize; + return info->gunClipSize; case WI_MAX_ROUNDS: - return info->maxRounds; + return info->maxRounds; case WI_AMMO_TYPE: - return info->ammoType; + return info->ammoType; case WI_NAME: { if (PARAMS_COUNT != arg_4) { @@ -550,17 +550,69 @@ cell AMX_NATIVE_CALL rg_get_weapon_info(AMX *amx, cell *params) // native rg_get_weapon_info(id, WPINFO_NAME, output[], maxlength); cell* dest = getAmxAddr(amx, params[arg_3]); size_t length = *getAmxAddr(amx, params[arg_4]); + + if (info->entityName == nullptr) { + setAmxString(dest, "", 1); + return 0; + } + setAmxString(dest, info->entityName, length); return 1; } default: - { - MF_LogError(amx, AMX_ERR_NATIVE, "%s: unknown type statement %i, params count %i", __FUNCTION__, info_type, PARAMS_COUNT); - return -1; - } + MF_LogError(amx, AMX_ERR_NATIVE, "%s: unknown type statement %i, params count %i", __FUNCTION__, info_type, PARAMS_COUNT); + return -1; } } +/** +* Sets specific values of weapons info. +* +* @param weapon_id Weapon id, see WEAPON_* constants +* @param type Info type, see WI_* constants +* +* @return 1 if successfully, 0 otherwise +* +* native rg_set_weapon_info(const {WeaponIdType,_}:weapon_id, WpnInfo:type, any:...); +*/ +cell AMX_NATIVE_CALL rg_set_weapon_info(AMX *amx, cell *params) +{ + enum args_e { arg_count, arg_weapon_id, arg_type, arg_value }; + + int weapon_id = params[arg_weapon_id]; + if (weapon_id <= WEAPON_NONE || weapon_id == WEAPON_C4 || weapon_id == WEAPON_KNIFE || weapon_id > WEAPON_P90) + { + MF_LogError(amx, AMX_ERR_NATIVE, "%s: invalid weapon id %i", __FUNCTION__, weapon_id); + return 0; + } + + cell* value = getAmxAddr(amx, params[arg_value]); + WeaponInfoStruct *info = g_ReGameApi->GetGameData()->GetWeaponInfo(weapon_id); + WpnInfo info_type = static_cast(params[arg_type]); + + switch (info_type) + { + case WI_COST: + info->cost = *value; + break; + case WI_CLIP_COST: + info->clipCost = *value; + break; + case WI_BUY_CLIP_SIZE: + case WI_GUN_CLIP_SIZE: + case WI_MAX_ROUNDS: + case WI_AMMO_TYPE: + case WI_NAME: + MF_LogError(amx, AMX_ERR_NATIVE, "%s: this change will have no effect", __FUNCTION__); + return 0; + default: + MF_LogError(amx, AMX_ERR_NATIVE, "%s: unknown type statement %i, params count %i", __FUNCTION__, info_type, PARAMS_COUNT); + return 0; + } + + return 1; +} + /** * Remove all the player's stuff * @@ -653,7 +705,9 @@ AMX_NATIVE_INFO Misc_Natives_RG[] = { "rg_create_entity", rg_create_entity }, { "rg_find_ent_by_class", rg_find_ent_by_class }, { "rg_find_ent_by_owner", rg_find_ent_by_owner }, + { "rg_get_weapon_info", rg_get_weapon_info }, + { "rg_set_weapon_info", rg_set_weapon_info }, { "rg_remove_all_items", rg_remove_all_items }, { "rg_remove_item", rg_remove_item }, From 136efa87ab6b3b7fc10256794a6d5f9eb05bc9e1 Mon Sep 17 00:00:00 2001 From: s1lentq Date: Wed, 11 May 2016 17:34:45 +0600 Subject: [PATCH 11/13] Fix typo version --- reapi/extra/amxmodx/scripting/include/reapi.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi.inc b/reapi/extra/amxmodx/scripting/include/reapi.inc index 7021721..0e705c6 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi.inc @@ -116,18 +116,18 @@ native SetHookChainArg(number, AType:type, any:...); */ public __reapi_version_check(const majorVersion, const minorVersion) { - if (majorVersion != REAPI_VERISON_MAJOR) + if (majorVersion != REAPI_VERSION_MAJOR) { new temp[512]; - formatex(temp, sizeof temp - 1, "[ReAPI]: Api major version mismatch; expected %d, real %d", REAPI_VERISON_MAJOR, majorVersion); + formatex(temp, sizeof temp - 1, "[ReAPI]: Api major version mismatch; expected %d, real %d", REAPI_VERSION_MAJOR, majorVersion); set_fail_state(temp); return; } - if (minorVersion < REAPI_VERISON_MINOR) + if (minorVersion < REAPI_VERSION_MINOR) { new temp[512]; - formatex(temp, sizeof temp - 1, "[ReAPI]: Api minor version mismatch; expected at least %d, real %d", REAPI_VERISON_MINOR, minorVersion); + formatex(temp, sizeof temp - 1, "[ReAPI]: Api minor version mismatch; expected at least %d, real %d", REAPI_VERSION_MINOR, minorVersion); set_fail_state(temp); return; } From 86aead4b026c843274a5f9f5c9435c33e6e79697 Mon Sep 17 00:00:00 2001 From: s1lentq Date: Wed, 11 May 2016 19:52:49 +0600 Subject: [PATCH 12/13] Rework native rg_get_weapon_info --- reapi/build.gradle | 2 +- .../scripting/include/reapi_gamedll.inc | 11 +++-- .../scripting/include/reapi_gamedll_const.inc | 1 + reapi/src/natives/natives_misc.cpp | 46 +++++++++++++------ reapi/src/natives/natives_misc.h | 1 + reapi/src/reapi_utils.h | 15 ++++++ 6 files changed, 56 insertions(+), 20 deletions(-) diff --git a/reapi/build.gradle b/reapi/build.gradle index 67852cc..c6598d9 100644 --- a/reapi/build.gradle +++ b/reapi/build.gradle @@ -61,7 +61,7 @@ void setupToolchain(NativeBinarySpec b) { '_snprintf': 'snprintf' ]) - cfg.compilerOptions.args '-Qoption,cpp,--treat_func_as_string_literal_cpp', '-msse2', '-fp-model fast=2', '-fomit-frame-pointer', '-inline-forceinline', '-fvisibility=default', '-fvisibility-inlines-hidden', '-fno-rtti', '-g0', '-s' + cfg.compilerOptions.args '-Qoption,cpp,--treat_func_as_string_literal_cpp', '-msse2', '-fomit-frame-pointer', '-inline-forceinline', '-fvisibility=default', '-fvisibility-inlines-hidden', '-fno-rtti', '-g0', '-s' } ToolchainConfigUtils.apply(project, cfg, b) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc index 53a3405..919b245 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc @@ -236,14 +236,15 @@ native rg_find_ent_by_owner(&start_index, const classname[], owner); /** * Returns some information about a weapon. * -* @param weapon_id Weapon id, see WEAPON_* constants -* @param type Info type, see WPINFO_* constants +* @param weapon name or id Weapon id, see WEAPON_* constants WeaponIdType or weapon_* name +* @param WpnInfo:type Info type, see WI_* constants * -* @return Weapon information value -* @error If weapon_id and type are out of bound, an error will be thrown. +* @return Weapon information value +* @error If weapon_id and type are out of bound, an error will be thrown. * +* native rg_get_weapon_info(any:...); */ -native rg_get_weapon_info(const {WeaponIdType,_}:weapon_id, WpnInfo:type, any:...); +native rg_get_weapon_info(any:...); /** * Sets specific values of weapons info. diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc index 3383611..91aeba6 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc @@ -54,6 +54,7 @@ enum WeaponIdType // Weapon info types for use with rg_get_weapon_info() enum WpnInfo { + WI_ID, WI_COST, WI_CLIP_COST, WI_BUY_CLIP_SIZE, diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index f5c9394..330f705 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -504,30 +504,48 @@ cell AMX_NATIVE_CALL rg_find_ent_by_owner(AMX *amx, cell *params) /** * Returns some information about a weapon. * -* @param weapon_id Weapon id, see WEAPON_* constants -* @param type Info type, see WI_* constants +* @param weapon name or id Weapon id, see WEAPON_* constants or weapon_* name +* @param WpnInfo:type Info type, see WI_* constants * -* @return Weapon information value -* @error If weapon_id and type are out of bound, an error will be thrown. +* @return Weapon information value +* @error If weapon_id and type are out of bound, an error will be thrown. * -* native rg_get_weapon_info(const {WeaponIdType,_}:weapon_id, WpnInfo:type, any:...); +* native rg_get_weapon_info(any:...); */ cell AMX_NATIVE_CALL rg_get_weapon_info(AMX *amx, cell *params) { enum args_e { arg_count, arg_weapon_id, arg_type, arg_3, arg_4 }; - int weapon_id = params[arg_weapon_id]; - if (weapon_id <= WEAPON_NONE || weapon_id == WEAPON_C4 || weapon_id == WEAPON_KNIFE || weapon_id > WEAPON_P90) + WeaponIdType weaponID = static_cast(params[arg_weapon_id]); + WpnInfo info_type = static_cast(*getAmxAddr(amx, params[arg_type])); + + if (!GetWeaponInfoRange(weaponID) && info_type != WI_ID) { - MF_LogError(amx, AMX_ERR_NATIVE, "%s: invalid weapon id %i", __FUNCTION__, weapon_id); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: invalid weapon id %i", __FUNCTION__, weaponID); return 0; } - WeaponInfoStruct *info = g_ReGameApi->GetGameData()->GetWeaponInfo(weapon_id); - WpnInfo info_type = static_cast(params[arg_type]); + WeaponInfoStruct* info = g_ReGameApi->GetGameData()->GetWeaponInfo(weaponID); + char* szWeaponName = getAmxString(amx, params[arg_weapon_id]); switch (info_type) { + case WI_ID: + if (szWeaponName == nullptr) { + return WEAPON_NONE; + } + + _strlwr(szWeaponName); + for (int i = 0; i < MAX_WEAPONS; ++i) { + info = g_ReGameApi->GetGameData()->GetWeaponInfo(i); + if (info == nullptr || info->id == WEAPON_NONE) + continue; + + if (strcmp(info->entityName, szWeaponName) == 0) { + return info->id; + } + } + return WEAPON_NONE; case WI_COST: return info->cost; case WI_CLIP_COST: @@ -579,15 +597,15 @@ cell AMX_NATIVE_CALL rg_set_weapon_info(AMX *amx, cell *params) { enum args_e { arg_count, arg_weapon_id, arg_type, arg_value }; - int weapon_id = params[arg_weapon_id]; - if (weapon_id <= WEAPON_NONE || weapon_id == WEAPON_C4 || weapon_id == WEAPON_KNIFE || weapon_id > WEAPON_P90) + WeaponIdType weaponID = static_cast(params[arg_weapon_id]); + if (!GetWeaponInfoRange(weaponID)) { - MF_LogError(amx, AMX_ERR_NATIVE, "%s: invalid weapon id %i", __FUNCTION__, weapon_id); + MF_LogError(amx, AMX_ERR_NATIVE, "%s: invalid weapon id %i", __FUNCTION__, weaponID); return 0; } cell* value = getAmxAddr(amx, params[arg_value]); - WeaponInfoStruct *info = g_ReGameApi->GetGameData()->GetWeaponInfo(weapon_id); + WeaponInfoStruct *info = g_ReGameApi->GetGameData()->GetWeaponInfo(weaponID); WpnInfo info_type = static_cast(params[arg_type]); switch (info_type) diff --git a/reapi/src/natives/natives_misc.h b/reapi/src/natives/natives_misc.h index fd6154b..3991dd2 100644 --- a/reapi/src/natives/natives_misc.h +++ b/reapi/src/natives/natives_misc.h @@ -2,6 +2,7 @@ enum WpnInfo { + WI_ID, WI_COST, WI_CLIP_COST, WI_BUY_CLIP_SIZE, diff --git a/reapi/src/reapi_utils.h b/reapi/src/reapi_utils.h index 825f521..6d03399 100644 --- a/reapi/src/reapi_utils.h +++ b/reapi/src/reapi_utils.h @@ -7,6 +7,10 @@ char(&ArraySizeHelper(T(&array)[N]))[N]; #define INDEXENT edictByIndex #define ENTINDEX indexOfEdict +#ifndef _WIN32 +#define _strlwr(p) for (int i = 0; p[i] != 0; i++) p[i] = tolower(p[i]); +#endif + extern enginefuncs_t* g_pengfuncsTable; inline size_t indexOfEdict(edict_t* ed) @@ -86,6 +90,17 @@ inline T get_member_direct(edict_t *pEntity, int offset, int element = 0, int si return get_member_direct(pEntity->pvPrivateData, offset, element, size); } +inline bool GetWeaponInfoRange(WeaponIdType wpnid) +{ + if (wpnid == WEAPON_SHIELDGUN) + return true; + + if (wpnid > WEAPON_NONE && wpnid != WEAPON_C4 && wpnid != WEAPON_KNIFE && wpnid <= WEAPON_P90) + return true; + + return false; +} + void Broadcast(const char *sentence); void UpdateTeamScores(); From 9bdeb103ebc03bd78834d1fec1fcd10f7cfc142e Mon Sep 17 00:00:00 2001 From: s1lentq Date: Wed, 11 May 2016 22:54:06 +0600 Subject: [PATCH 13/13] Added bypass warning 200 on amxmodx 1.8.2 --- .../extra/amxmodx/scripting/include/reapi.inc | 75 +- .../scripting/include/reapi_engine_const.inc | 32 +- .../scripting/include/reapi_gamedll.inc | 17 +- .../scripting/include/reapi_gamedll_const.inc | 3819 +++++++++-------- reapi/src/hook_list.cpp | 14 +- reapi/src/hook_list.h | 5 +- reapi/src/member_list.h | 2 +- reapi/src/natives/natives_addons.cpp | 1 + reapi/src/natives/natives_helper.h | 1 - reapi/src/natives/natives_hookchains.cpp | 72 +- reapi/src/natives/natives_misc.cpp | 12 +- 11 files changed, 2028 insertions(+), 2022 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi.inc b/reapi/extra/amxmodx/scripting/include/reapi.inc index 0e705c6..3d7475b 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi.inc @@ -44,56 +44,54 @@ enum HookChain }; /* - * Hook API function that are available into enum - * Look at the enum's for parameter lists. - * - * @param function The function to hook. - * @param callback The forward to call. - * @param post Whether or not to forward this in post. - * @return Returns a handle to the hook. Use EnableHookChain/DisableHookChain to toggle the forward on or off. - * - */ +* Hook API function that are available into enum +* Look at the enum's for parameter lists. +* +* @param function The function to hook. +* @param callback The forward to call. +* @param post Whether or not to forward this in post. +* @return Returns a handle to the hook. Use EnableHookChain/DisableHookChain to toggle the forward on or off. +* +*/ native HookChain:RegisterHookChain(any:function_id, const callback[], post = 0); /* - * Stops a hook from triggering. - * Use the return value from RegisterHookChain as the parameter here! - * - * @param hook The hook to stop. - * - */ +* Stops a hook from triggering. +* Use the return value from RegisterHookChain as the parameter here! +* +* @param hook The hook to stop. +* +*/ native bool:DisableHookChain(HookChain:hook); /* - * Starts a hook back up. - * Use the return value from RegisterHookChain as the parameter here! - * - * @param hook The hook to re-enable. - * @return Returns if the function is successful executed true otherwise false - * - */ +* Starts a hook back up. +* Use the return value from RegisterHookChain as the parameter here! +* +* @param hook The hook to re-enable. +* @return Returns if the function is successful executed true otherwise false +* +*/ native bool:EnableHookChain(HookChain:hook); /* - * Sets the return value of a hookchain. - * This needs to be used in conjunction with RH_OVERRIDE or RH_SUPERCEDE. - * - * @param type To specify the type RHV_*, look at the enum HookChainReturn - * @param value The value to set the return to. - * - * native SetHookChainReturn(AType:type, any:...); - */ +* Sets the return value of a hookchain. +* This needs to be used in conjunction with RH_OVERRIDE or RH_SUPERCEDE. +* +* @param type To specify the type RHV_*, look at the enum HookChainReturn +* @param value The value to set the return to. +* +*/ native SetHookChainReturn(AType:type, any:...); /* - * Gets the return value of a hookchain. - * This needs to be used in conjunction with RH_OVERRIDE or RH_SUPERCEDE. - * - * @param type To specify the type RHV_*, look at the enum HookChainReturn - * @param value The value to set the return to. - * - * native GetHookChainReturn(AType:type, any:...); - */ +* Gets the return value of a hookchain. +* This needs to be used in conjunction with RH_OVERRIDE or RH_SUPERCEDE. +* +* @param type To specify the type RHV_*, look at the enum HookChainReturn +* @param value The value to set the return to. +* +*/ native GetHookChainReturn(AType:type, any:...); /* @@ -105,7 +103,6 @@ native GetHookChainReturn(AType:type, any:...); * @param [maxlen] Max length of string (optional) * @return Returns if the function is successful executed true otherwise false * -* native SetHookChainArg(number, AType:type, any:...); */ native SetHookChainArg(number, AType:type, any:...); diff --git a/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc index 0a5b425..5dafd29 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc @@ -6,28 +6,28 @@ enum EngineFunc { - /** - * Description: - - * Params: (const recipients, const entity, const channel, const sample[], const volume, Float:attenuation, const fFlags, const pitch) - */ + /* + * Description: - + * Params: (const recipients, const entity, const channel, const sample[], const volume, Float:attenuation, const fFlags, const pitch) + */ RH_SV_StartSound = 0, - /** - * Description: - - * Params: (const client, bool:crash, const fmt[]) - */ + /* + * Description: - + * Params: (const client, bool:crash, const fmt[]) + */ RH_SV_DropClient, - /** - * Description: - - * Params: (const runPhysics) - */ + /* + * Description: - + * Params: (const runPhysics) + */ RH_SV_ActivateServer, - /** - * Description: - - * Params: (pcvar, const value[]) - */ + /* + * Description: - + * Params: (pcvar, const value[]) + */ RH_Cvar_DirectSet, // [...] diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc index 919b245..40944b6 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc @@ -233,7 +233,7 @@ native rg_find_ent_by_class(start_index, const classname[]); */ native rg_find_ent_by_owner(&start_index, const classname[], owner); -/** +/* * Returns some information about a weapon. * * @param weapon name or id Weapon id, see WEAPON_* constants WeaponIdType or weapon_* name @@ -242,11 +242,10 @@ native rg_find_ent_by_owner(&start_index, const classname[], owner); * @return Weapon information value * @error If weapon_id and type are out of bound, an error will be thrown. * -* native rg_get_weapon_info(any:...); */ native rg_get_weapon_info(any:...); -/** +/* * Sets specific values of weapons info. * * @param weapon_id Weapon id, see WEAPON_* constants @@ -257,7 +256,17 @@ native rg_get_weapon_info(any:...); */ native rg_set_weapon_info(const {WeaponIdType,_}:weapon_id, WpnInfo:type, any:...); -/** +/* +* Remove all the player's stuff +* +* @param index Client index +* +* @noreturn +* +*/ +native rg_remove_all_items(const index, bool:bRemoveSuit); + +/* * Remove specifed the player's item by class name * * @param index Client index diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc index 91aeba6..554a3ce 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc @@ -12,9 +12,16 @@ #define SIGNAL_VIPSAFETY (1<<4) // Returns 1, if round ended by expired time -// NOTE: Use this for hookchain RG_RoundEnd with the parametr ScenarioEventEndRound:event +// NOTE: Use this for hookchain RG_RoundEnd with the parameter ScenarioEventEndRound:event #define HadRoundExpired(event) (1<INDEX_TO_CSENTITY(m_value); } - Vector& vector() const { return operator Vector&(); diff --git a/reapi/src/natives/natives_hookchains.cpp b/reapi/src/natives/natives_hookchains.cpp index 98db2c3..7dad4cf 100644 --- a/reapi/src/natives/natives_hookchains.cpp +++ b/reapi/src/natives/natives_hookchains.cpp @@ -1,17 +1,16 @@ #include "precompiled.h" /* - * Hook API function that are available into enum - * Look at the enum's for parameter lists. - * - * @param function The function to hook. - * @param callback The forward to call. - * @param post Whether or not to forward this in post. - * @return Returns a handle to the hook. Use EnableHookChain/DisableHookChain to toggle the forward on or off. - * - * native RegisterHookChain(any:function_id, const callback[], post = 0); - */ - +* Hook API function that are available into enum +* Look at the enum's for parameter lists. +* +* @param function The function to hook. +* @param callback The forward to call. +* @param post Whether or not to forward this in post. +* @return Returns a handle to the hook. Use EnableHookChain/DisableHookChain to toggle the forward on or off. +* +* native RegisterHookChain(any:function_id, const callback[], post = 0); +*/ cell AMX_NATIVE_CALL RegisterHookChain(AMX *amx, cell *params) { enum args_e { arg_count, arg_func, arg_handler, arg_post }; @@ -51,15 +50,14 @@ cell AMX_NATIVE_CALL RegisterHookChain(AMX *amx, cell *params) } /* - * Enable hook by handle. - * Use the return value from RegisterHookChain as the parameter here! - * - * @param fwd The hook to re-enable. - * @return Returns if the function is successful executed true otherwise false - * - * native bool:EnableHookChain(any:fwd); - */ - +* Enable hook by handle. +* Use the return value from RegisterHookChain as the parameter here! +* +* @param fwd The hook to re-enable. +* @return Returns if the function is successful executed true otherwise false +* +* native bool:EnableHookChain(any:fwd); +*/ cell AMX_NATIVE_CALL EnableHookChain(AMX *amx, cell *params) { enum args_e { arg_count, arg_handle_hook }; @@ -77,14 +75,13 @@ cell AMX_NATIVE_CALL EnableHookChain(AMX *amx, cell *params) } /* - * Disable hook by handle. - * Use the return value from RegisterHookChain as the parameter here! - * - * @param fwd The hook to stop. - * - * native bool:DisableHookChain(any:fwd); - */ - +* Disable hook by handle. +* Use the return value from RegisterHookChain as the parameter here! +* +* @param fwd The hook to stop. +* +* native bool:DisableHookChain(any:fwd); +*/ cell AMX_NATIVE_CALL DisableHookChain(AMX *amx, cell *params) { enum args_e { arg_count, arg_handle_hook }; @@ -102,15 +99,14 @@ cell AMX_NATIVE_CALL DisableHookChain(AMX *amx, cell *params) } /* - * Sets the return value of a hookchain. - * This needs to be used in conjunction with RH_OVERRIDE or RH_SUPERCEDE. - * - * @param type To specify the type RHV_*, look at the enum AType - * @param value The value to set the return to. - * - * native SetHookChainReturn(AType:type, any:...); - */ - +* Sets the return value of a hookchain. +* This needs to be used in conjunction with RH_OVERRIDE or RH_SUPERCEDE. +* +* @param type To specify the type RHV_*, look at the enum AType +* @param value The value to set the return to. +* +* native SetHookChainReturn(AType:type, any:...); +*/ cell AMX_NATIVE_CALL SetHookChainReturn(AMX *amx, cell *params) { if (!g_hookCtx) @@ -168,7 +164,6 @@ cell AMX_NATIVE_CALL SetHookChainReturn(AMX *amx, cell *params) * * native GetHookChainReturn(AType:type, any:...); */ - cell AMX_NATIVE_CALL GetHookChainReturn(AMX *amx, cell *params) { if (!g_hookCtx) @@ -217,7 +212,6 @@ cell AMX_NATIVE_CALL GetHookChainReturn(AMX *amx, cell *params) * * native SetHookChainArg(number, AType:type, any:...); */ - cell AMX_NATIVE_CALL SetHookChainArg(AMX *amx, cell *params) { if (!g_hookCtx) diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 330f705..51e181f 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -480,7 +480,7 @@ cell AMX_NATIVE_CALL rg_find_ent_by_owner(AMX *amx, cell *params) cell& startIndex = *getAmxAddr(amx, params[arg_start_index]); const char* value = getAmxString(amx, params[arg_classname]); edict_t* pOwner = edictByIndexAmx(params[arg_onwer]); - edict_t* pEntity = &g_pEdicts[startIndex]; + edict_t* pEntity = g_pEdicts + startIndex; for (int i = startIndex; i < gpGlobals->maxEntities; i++, pEntity++) { @@ -501,7 +501,7 @@ cell AMX_NATIVE_CALL rg_find_ent_by_owner(AMX *amx, cell *params) return FALSE; } -/** +/* * Returns some information about a weapon. * * @param weapon name or id Weapon id, see WEAPON_* constants or weapon_* name @@ -583,7 +583,7 @@ cell AMX_NATIVE_CALL rg_get_weapon_info(AMX *amx, cell *params) } } -/** +/* * Sets specific values of weapons info. * * @param weapon_id Weapon id, see WEAPON_* constants @@ -631,14 +631,14 @@ cell AMX_NATIVE_CALL rg_set_weapon_info(AMX *amx, cell *params) return 1; } -/** +/* * Remove all the player's stuff * * @param index Client index * * @noreturn * -* native rg_remove_all_items(const index, bool:bRemove); +* native rg_remove_all_items(const index, bool:bRemoveSuit); */ cell AMX_NATIVE_CALL rg_remove_all_items(AMX *amx, cell *params) { @@ -656,7 +656,7 @@ cell AMX_NATIVE_CALL rg_remove_all_items(AMX *amx, cell *params) return TRUE; } -/** +/* * Remove specifed the player's item by class name * * @param index Client index