From f93e992674ae6973a5aa8a898ee7015484a38466 Mon Sep 17 00:00:00 2001 From: s1lentq Date: Wed, 11 Jan 2017 20:47:13 +0700 Subject: [PATCH] Simplification natives members --- .../scripting/include/reapi_gamedll_const.inc | 8 ++-- reapi/src/hook_manager.h | 2 +- reapi/src/member_list.cpp | 16 +++++-- reapi/src/natives/natives_members.cpp | 47 +++++++++---------- shared_msvc.gradle | 2 +- 5 files changed, 39 insertions(+), 36 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc index 07e2eb1..9dccb13 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc @@ -1031,7 +1031,7 @@ enum CSGameRules_Members /* * Description: - * Member type: int [100] - * Get params: get_member_game(member); + * Get params: get_member_game(member, element); * Set params: set_member_game(member, value, element); */ m_iMapVotes, @@ -1119,7 +1119,7 @@ enum CSGameRules_Members /* * Description: - * Member type: int [5] - * Get params: get_member_game(member); + * Get params: get_member_game(member, element); * Set params: set_member_game(member, value, element); */ m_pVIPQueue, @@ -1232,8 +1232,8 @@ enum CSGameRules_Members /* * Description: - * Member type: float - * Get params: Float:get_member(index, member); - * Set params: set_member(index, member, Float:value); + * Get params: Float:get_member_game(member); + * Set params: set_member_game(member, Float:value); */ m_flEscapeRatio }; diff --git a/reapi/src/hook_manager.h b/reapi/src/hook_manager.h index 5cab4e7..40e023d 100644 --- a/reapi/src/hook_manager.h +++ b/reapi/src/hook_manager.h @@ -13,7 +13,7 @@ class CAmxxHook { public: CAmxxHook(AMX* amx, int index) : m_index(index), m_state(FSTATE_ENABLED), m_amx(amx) {}; - + int GetIndex() const; fwdstate GetState() const; AMX* GetAmx() const; diff --git a/reapi/src/member_list.cpp b/reapi/src/member_list.cpp index 77ac93c..95d4d5c 100644 --- a/reapi/src/member_list.cpp +++ b/reapi/src/member_list.cpp @@ -1,9 +1,17 @@ #include "precompiled.h" -#define CLASS_MEMBERS(cx, mx, postf, pref) ((!(postf & (MAX_REGION_RANGE - 1)) ? regmember::current_cell = 1, true : false) || (postf & (MAX_REGION_RANGE - 1)) == regmember::current_cell++) ? regmember([](member_t* ptr){ decltype(##cx::##pref##mx) f = {};ptr->size = getTypeSize(f);ptr->max_size = sizeof(f);ptr->offset = offsetof(##cx, ##pref##mx);ptr->type = getMemberType(f);ptr->name = #postf;}) : regmember(#pref#mx) +#if _MSC_VER <= 1800 && __INTEL_COMPILER < 1500 + // BUG BUG + // http://connect.microsoft.com/VisualStudio/feedbackdetail/view/797682/c-decltype-of-class-member-access-incompletely-implemented + #define decltypefx(cx, pref, dt, mx) decltype(std::declval()dt##pref##mx) +#else + #define decltypefx(cx, pref, dt, mx) decltype(cx::pref##mx) +#endif + +#define CLASS_MEMBERS(cx, mx, postf, pref) ((!(postf & (MAX_REGION_RANGE - 1)) ? regmember::current_cell = 1, true : false) || (postf & (MAX_REGION_RANGE - 1)) == regmember::current_cell++) ? regmember([](member_t* ptr){ decltypefx(cx, pref, ., mx) f = {};ptr->size = getTypeSize(f);ptr->max_size = sizeof(f);ptr->offset = offsetof(##cx, ##pref##mx);ptr->type = getMemberType(f);ptr->name = #postf;}) : regmember(#pref#mx) #define GM_MEMBERS(mx) CLASS_MEMBERS(CHalfLifeMultiplay, mx, mx,) -#define GM_VOICE_MEMBERS(mx) CLASS_MEMBERS(CVoiceGameMgr, mx, mx,) +#define GM_VOICE_MEMBERS(mx) CLASS_MEMBERS(CHalfLifeMultiplay, mx, mx, m_VoiceGameMgr.) #define BASE_MEMBERS(mx) CLASS_MEMBERS(CBaseEntity, mx, mx,) #define ANIM_MEMBERS(mx) CLASS_MEMBERS(CBaseAnimating, mx, mx,) #define MONST_MEMBERS(mx) CLASS_MEMBERS(CBaseMonster, mx, mx,) @@ -38,8 +46,8 @@ inline MType getMemberType(Vector*) { return MEMBER_VECTOR; } inline MType getMemberType(Vector) { return MEMBER_VECTOR; } inline MType getMemberType(char*) { return MEMBER_STRING; } -inline MType getMemberType(qstring_t) { return MEMBER_QSTRING; } -inline MType getMemberType(qstring_t*) { return MEMBER_QSTRING; } +inline MType getMemberType(qstring_t) { return MEMBER_QSTRING; } +inline MType getMemberType(qstring_t*) { return MEMBER_QSTRING; } inline MType getMemberType(char) { return MEMBER_BYTE; } inline MType getMemberType(byte) { return MEMBER_BYTE; } diff --git a/reapi/src/natives/natives_members.cpp b/reapi/src/natives/natives_members.cpp index c512119..b1507c4 100644 --- a/reapi/src/natives/natives_members.cpp +++ b/reapi/src/natives/natives_members.cpp @@ -71,7 +71,7 @@ cell AMX_NATIVE_CALL get_member(AMX *amx, cell *params) cell* arg3 = getAmxAddr(amx, params[arg_3]); if (isTypeReturnable(member->type)) { - dest = (member->type != MEMBER_FLOAT) ? nullptr : arg3; + dest = nullptr; element = *arg3; } else { @@ -123,7 +123,7 @@ cell AMX_NATIVE_CALL set_member_game(AMX *amx, cell *params) // native get_member_game(any:_member, any:...); cell AMX_NATIVE_CALL get_member_game(AMX *amx, cell *params) { - enum args_e { arg_count, arg_member, arg_3, arg_4 }; + enum args_e { arg_count, arg_member, arg_2 }; CHECK_GAMERULES(); @@ -137,16 +137,11 @@ cell AMX_NATIVE_CALL get_member_game(AMX *amx, cell *params) size_t element; size_t length; - if (PARAMS_COUNT == 4) { - dest = getAmxAddr(amx, params[arg_3]); - length = *getAmxAddr(amx, params[arg_4]); - element = 0; - } - else if (PARAMS_COUNT == 3) { - cell* arg3 = getAmxAddr(amx, params[arg_3]); - + if (PARAMS_COUNT == 2) + { + cell* arg3 = getAmxAddr(amx, params[arg_2]); if (isTypeReturnable(member->type)) { - dest = (member->type != MEMBER_FLOAT) ? nullptr : arg3; + dest = nullptr; element = *arg3; } else { @@ -154,22 +149,13 @@ cell AMX_NATIVE_CALL get_member_game(AMX *amx, cell *params) element = 0; } length = 0; - } - else { + } else { dest = nullptr; element = 0; length = 0; } - void* data; - // members of m_VoiceGameMgr - if (params[arg_member] >= m_msgPlayerVoiceMask && params[arg_member] <= m_UpdateInterval) { - data = &CSGameRules()->m_VoiceGameMgr; - } else { - data = g_pGameRules; - } - - return get_member(data, member, dest, element, length); + return get_member(g_pGameRules, member, dest, element, length); } // native set_entvar(const index, const EntVars:var, any:...); @@ -227,9 +213,15 @@ cell AMX_NATIVE_CALL get_entvar(AMX *amx, cell *params) else if (PARAMS_COUNT == 3) { cell* arg3 = getAmxAddr(amx, params[arg_3]); - if (isTypeReturnable(member->type)) { - dest = (member->type != MEMBER_FLOAT) ? nullptr : arg3; - element = *arg3; + if (isTypeReturnable(member->type)) + { + if (member->type == MEMBER_FLOAT) { + dest = arg3; + element = 0; + } else { + dest = nullptr; + element = *arg3; + } } else { dest = arg3; @@ -672,8 +664,11 @@ cell get_member(void* pdata, const member_t *member, cell* dest, size_t element, // native any:get_member(_index, any:_member, element); return get_member(pdata, member->offset, element); case MEMBER_DOUBLE: + { // native any:get_member(_index, any:_member, element); - return get_member(pdata, member->offset, element); + auto ret = (float)get_member(pdata, member->offset, element); + return (cell &)ret; + } case MEMBER_SIGNALS: { enum { _Signal, _State }; diff --git a/shared_msvc.gradle b/shared_msvc.gradle index 254b63b..e563c52 100644 --- a/shared_msvc.gradle +++ b/shared_msvc.gradle @@ -93,7 +93,7 @@ rootProject.ext.createMsvcConfig = { boolean release, BinaryKind binKind -> 'WIN32': null, '_MBCS': null, '_DEBUG': null, - 'NOMINMAX': null, + 'NOMINMAX': null ] ),