From d4b3e3c7eb20e16a8472fa93d349b879c29976e0 Mon Sep 17 00:00:00 2001 From: s1lent Date: Mon, 24 Jun 2019 00:40:02 +0700 Subject: [PATCH] GCC support and fixed warnings --- reapi/build.gradle | 30 ++++-- reapi/include/cssdk/engine/maintypes.h | 22 ++++- reapi/src/amx_hook.h | 75 ++++++--------- reapi/src/dllapi.cpp | 8 +- reapi/src/engine_api.cpp | 4 +- reapi/src/entity_callback.cpp | 10 +- reapi/src/entity_callback.h | 2 +- reapi/src/hook_callback.h | 4 +- reapi/src/hook_list.cpp | 6 +- reapi/src/hook_list.h | 10 +- reapi/src/hook_manager.cpp | 4 +- reapi/src/hook_manager.h | 2 +- reapi/src/member_list.cpp | 122 ++++++++++++++----------- reapi/src/member_list.h | 3 +- reapi/src/mods/mod_vtc_api.cpp | 4 +- reapi/src/natives/natives_misc.cpp | 7 +- reapi/src/reapi_utils.h | 2 +- reapi/src/sdk_util.cpp | 2 +- shared.gradle | 3 + shared_gcc.gradle | 63 +++++++++++++ 20 files changed, 243 insertions(+), 140 deletions(-) create mode 100644 shared_gcc.gradle diff --git a/reapi/build.gradle b/reapi/build.gradle index 69cfc7c..6b29610 100644 --- a/reapi/build.gradle +++ b/reapi/build.gradle @@ -14,6 +14,7 @@ import gradlecpp.VelocityUtils apply plugin: 'cpp' apply plugin: 'windows-resources' apply plugin: IccCompilerPlugin +apply plugin: GccCompilerPlugin List getRcCompileTasks(NativeBinarySpec binary) { def linkTask = GradleCppUtils.getLinkTask(binary) @@ -36,6 +37,7 @@ void postEvaluate(NativeBinarySpec b) { } void setupToolchain(NativeBinarySpec b) { + boolean useGcc = project.hasProperty("useGcc") ToolchainConfig cfg = rootProject.createToolchainConfig(b) cfg.projectInclude(project, '', '/src', '/common', '/src/mods', '/src/natives', '/include', '/include/metamod', '/include/cssdk/common', '/include/cssdk/dlls', '/include/cssdk/engine', '/include/cssdk/game_shared', '/include/cssdk/pm_shared', '/include/cssdk/public') cfg.singleDefines('HAVE_STRONG_TYPEDEF'); @@ -49,11 +51,13 @@ void setupToolchain(NativeBinarySpec b) { cfg.compilerOptions.args '/Ob2', '/Oi', '/GF', '/GR-', '/GS-' cfg.singleDefines('_CRT_SECURE_NO_WARNINGS') } else if (cfg instanceof GccToolchainConfig) { - cfg.compilerOptions.pchConfig = new GccToolchainConfig.PrecompilerHeaderOptions( - enabled: true, - pchSourceSet: 'reapi_pch' - ) - cfg.compilerOptions.languageStandard = 'c++0x' + if (!useGcc) { + cfg.compilerOptions.pchConfig = new GccToolchainConfig.PrecompilerHeaderOptions( + enabled: true, + pchSourceSet: 'reapi_pch' + ) + } + cfg.compilerOptions.languageStandard = 'c++11' cfg.defines([ '_stricmp': 'strcasecmp', '_strnicmp': 'strncasecmp', @@ -61,7 +65,13 @@ void setupToolchain(NativeBinarySpec b) { '_snprintf': 'snprintf' ]) - 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', '-fno-exceptions', '-no-ansi-alias' + if (useGcc) { + cfg.compilerOptions.args '-fno-strict-aliasing', '-finline-functions' + } else { + cfg.compilerOptions.args '-Qoption,cpp,--treat_func_as_string_literal_cpp', '-inline-forceinline', '-no-ansi-alias' + } + + cfg.compilerOptions.args '-Wall', '-Wno-unknown-pragmas', '-msse2', '-fomit-frame-pointer', '-fvisibility=default', '-fvisibility-inlines-hidden', '-fno-rtti', '-g0', '-s', '-fno-exceptions' } ToolchainConfigUtils.apply(project, cfg, b) @@ -84,9 +94,11 @@ model { } toolChains { - visualCpp(VisualCpp) { - } - icc(Icc) { + visualCpp(VisualCpp) + if (project.hasProperty("useGcc")) { + gcc(Gcc) + } else { + icc(Icc) } } diff --git a/reapi/include/cssdk/engine/maintypes.h b/reapi/include/cssdk/engine/maintypes.h index 5c7c3ad..b63fe99 100644 --- a/reapi/include/cssdk/engine/maintypes.h +++ b/reapi/include/cssdk/engine/maintypes.h @@ -32,11 +32,9 @@ #pragma once #endif - #include "osconfig.h" #include "mathlib.h" - // Has no references on server side. #define NOXREF // Function body is not implemented. @@ -44,6 +42,26 @@ // Function is not tested at all. #define UNTESTED +#define CONST_INTEGER_AS_STRING(x) #x //Wraps the integer in quotes, allowing us to form constant strings with it +#define __HACK_LINE_AS_STRING__(x) CONST_INTEGER_AS_STRING(x) //__LINE__ can only be converted to an actual number by going through this, otherwise the output is literally "__LINE__" +#define __LINE__AS_STRING __HACK_LINE_AS_STRING__(__LINE__) //Gives you the line number in constant string form + +#if defined _MSC_VER || defined __INTEL_COMPILER +#define NOXREFCHECK int __retAddr; __asm { __asm mov eax, [ebp + 4] __asm mov __retAddr, eax }; Sys_Error("[NOXREFCHECK]: %s: (" __FILE__ ":" __LINE__AS_STRING ") NOXREF, but called from 0x%.08x", __func__, __retAddr) +#else +// For EBP based stack (older gcc) (uncomment version apropriate for your compiler) +//#define NOXREFCHECK int __retAddr; __asm__ __volatile__("movl 4(%%ebp), %%eax;" "movl %%eax, %0":"=r"(__retAddr)::"%eax"); Sys_Error("[NOXREFCHECK]: %s: (" __FILE__ ":" __LINE__AS_STRING ") NOXREF, but called from 0x%.08x", __func__, __retAddr); +// For ESP based stack (newer gcc) (uncomment version apropriate for your compiler) +#define NOXREFCHECK int __retAddr; __asm__ __volatile__("movl 16(%%esp), %%eax;" "movl %%eax, %0":"=r"(__retAddr)::"%eax"); Sys_Error("[NOXREFCHECK]: %s: (" __FILE__ ":" __LINE__AS_STRING ") NOXREF, but called from 0x%.08x", __func__, __retAddr); +#endif + #define BIT(n) (1<<(n)) +// From engine/server.h +typedef enum sv_delta_s +{ + sv_packet_nodelta, + sv_packet_delta, +} sv_delta_t; + #endif // MAINTYPES_H diff --git a/reapi/src/amx_hook.h b/reapi/src/amx_hook.h index 7082868..8739b49 100644 --- a/reapi/src/amx_hook.h +++ b/reapi/src/amx_hook.h @@ -8,78 +8,61 @@ enum fwdstate FSTATE_STOPPED }; -template -class CAmxxHook +class CAmxxHookBase { public: - ~CAmxxHook() + ~CAmxxHookBase() { if (m_index != -1) { g_amxxapi.UnregisterSPForward(m_index); m_index = -1; } - - delete m_uniqueData; } - CAmxxHook(AMX *amx, const char *funcname, int index, T *data = nullptr) : + CAmxxHookBase(AMX *amx, const char *funcname, int index) : m_index(index), m_state(FSTATE_ENABLED), - m_amx(amx), - m_uniqueData(data) + m_amx(amx) { Q_strlcpy(m_CallbackName, funcname); - }; + } - T *GetUnique() const; - int GetIndex() const; - fwdstate GetState() const; - AMX *GetAmx() const; - const char *GetCallbackName() const; + int GetIndex() const { return m_index; } + fwdstate GetState() const { return m_state; } + AMX *GetAmx() const { return m_amx; } + const char *GetCallbackName() const { return m_CallbackName; } - void SetState(fwdstate st); + void SetState(fwdstate st) { m_state = st; } private: - T *m_uniqueData; int m_index; char m_CallbackName[64]; fwdstate m_state; AMX *m_amx; }; -// Inlines template -inline T *CAmxxHook::GetUnique() const +class CAmxxHookUnique: public CAmxxHookBase { - return m_uniqueData; -} +public: + ~CAmxxHookUnique() + { + if (m_uniqueData) + { + delete m_uniqueData; + m_uniqueData = nullptr; + } + } -template -inline AMX *CAmxxHook::GetAmx() const -{ - return m_amx; -} + CAmxxHookUnique(AMX *amx, const char *funcname, int index, T *data = nullptr) : + CAmxxHookBase(amx, funcname, index), + m_uniqueData(data) + { -template -inline const char *CAmxxHook::GetCallbackName() const -{ - return m_CallbackName; -} + } -template -inline int CAmxxHook::GetIndex() const -{ - return m_index; -} + T *GetUnique() const { return m_uniqueData; } -template -inline fwdstate CAmxxHook::GetState() const -{ - return m_state; -} - -template -inline void CAmxxHook::SetState(fwdstate st) -{ - m_state = st; -} +private: + T *m_uniqueData; +}; diff --git a/reapi/src/dllapi.cpp b/reapi/src/dllapi.cpp index 4b8c02c..f403e30 100644 --- a/reapi/src/dllapi.cpp +++ b/reapi/src/dllapi.cpp @@ -122,12 +122,12 @@ C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersi { if (!pFunctionTable) { - ALERT(at_logged, __FUNCTION__ " called with null pFunctionTable"); + ALERT(at_logged, "GetEntityAPI2 called with null pFunctionTable"); return FALSE; } else if (*interfaceVersion != INTERFACE_VERSION) { - ALERT(at_logged, __FUNCTION__ " version mismatch; requested=%d ours=%d", *interfaceVersion, INTERFACE_VERSION); + ALERT(at_logged, "GetEntityAPI2 version mismatch; requested=%d ours=%d", *interfaceVersion, INTERFACE_VERSION); //! Tell metamod what version we had, so it can figure out who is out of date. *interfaceVersion = INTERFACE_VERSION; @@ -143,12 +143,12 @@ C_DLLEXPORT int GetEntityAPI2_Post(DLL_FUNCTIONS *pFunctionTable, int *interface { if (!pFunctionTable) { - ALERT(at_logged, __FUNCTION__ " called with null pFunctionTable"); + ALERT(at_logged, "GetEntityAPI2_Post called with null pFunctionTable"); return FALSE; } else if (*interfaceVersion != INTERFACE_VERSION) { - ALERT(at_logged, __FUNCTION__ " version mismatch; requested=%d ours=%d", *interfaceVersion, INTERFACE_VERSION); + ALERT(at_logged, "GetEntityAPI2_Post version mismatch; requested=%d ours=%d", *interfaceVersion, INTERFACE_VERSION); //! Tell metamod what version we had, so it can figure out who is out of date. *interfaceVersion = INTERFACE_VERSION; diff --git a/reapi/src/engine_api.cpp b/reapi/src/engine_api.cpp index 5194a40..42320f6 100644 --- a/reapi/src/engine_api.cpp +++ b/reapi/src/engine_api.cpp @@ -176,12 +176,12 @@ C_DLLEXPORT int GetEngineFunctions_Post(enginefuncs_t *pengfuncsFromEngine, int { if (!pengfuncsFromEngine) { - ALERT(at_logged, __FUNCTION__ " called with null pengfuncsFromEngine"); + ALERT(at_logged, "GetEngineFunctions_Post called with null pengfuncsFromEngine"); return FALSE; } else if (*interfaceVersion != ENGINE_INTERFACE_VERSION) { - ALERT(at_logged, __FUNCTION__ " version mismatch; requested=%d ours=%d", *interfaceVersion, ENGINE_INTERFACE_VERSION); + ALERT(at_logged, "GetEngineFunctions_Post version mismatch; requested=%d ours=%d", *interfaceVersion, ENGINE_INTERFACE_VERSION); // Tell metamod what version we had, so it can figure out who is out of date. *interfaceVersion = ENGINE_INTERFACE_VERSION; return FALSE; diff --git a/reapi/src/entity_callback.cpp b/reapi/src/entity_callback.cpp index 3832d94..a11b59d 100644 --- a/reapi/src/entity_callback.cpp +++ b/reapi/src/entity_callback.cpp @@ -61,7 +61,7 @@ bool CEntityCallback::SetThink(AMX *amx, CBaseEntity *pEntity, const char *pszCa return false; } - m_callbacks.push_back(new CAmxxHook(amx, pszCallback, fwdid, new eCallback_t(pEntity, pParams, iParamsLen, CType_Think))); + m_callbacks.push_back(new CAmxxHookUnique(amx, pszCallback, fwdid, new eCallback_t(pEntity, pParams, iParamsLen, CType_Think))); pEntity->SetThink(&CBaseEntity::SUB_Think); return true; } @@ -82,7 +82,7 @@ bool CEntityCallback::SetTouch(AMX *amx, CBaseEntity *pEntity, const char *pszCa return false; } - m_callbacks.push_back(new CAmxxHook(amx, pszCallback, fwdid, new eCallback_t(pEntity, pParams, iParamsLen, CType_Touch))); + m_callbacks.push_back(new CAmxxHookUnique(amx, pszCallback, fwdid, new eCallback_t(pEntity, pParams, iParamsLen, CType_Touch))); pEntity->SetTouch(&CBaseEntity::SUB_Touch); return true; } @@ -103,7 +103,7 @@ bool CEntityCallback::SetUse(AMX *amx, CBaseEntity *pEntity, const char *pszCall return false; } - m_callbacks.push_back(new CAmxxHook(amx, pszCallback, fwdid, new eCallback_t(pEntity, pParams, iParamsLen, CType_Use))); + m_callbacks.push_back(new CAmxxHookUnique(amx, pszCallback, fwdid, new eCallback_t(pEntity, pParams, iParamsLen, CType_Use))); pEntity->SetUse(&CBaseEntity::SUB_Use); return true; } @@ -124,7 +124,7 @@ bool CEntityCallback::SetBlocked(AMX *amx, CBaseEntity *pEntity, const char *psz return false; } - m_callbacks.push_back(new CAmxxHook(amx, pszCallback, fwdid, new eCallback_t(pEntity, pParams, iParamsLen, CType_Blocked))); + m_callbacks.push_back(new CAmxxHookUnique(amx, pszCallback, fwdid, new eCallback_t(pEntity, pParams, iParamsLen, CType_Blocked))); pEntity->SetBlocked(&CBaseEntity::SUB_Blocked); return true; } @@ -145,7 +145,7 @@ bool CEntityCallback::SetMoveDone(AMX *amx, CBaseEntity *pEntity, const char *ps return false; } - m_callbacks.push_back(new CAmxxHook(amx, pszCallback, fwdid, new eCallback_t(pEntity, pParams, iParamsLen, CType_MoveDone))); + m_callbacks.push_back(new CAmxxHookUnique(amx, pszCallback, fwdid, new eCallback_t(pEntity, pParams, iParamsLen, CType_MoveDone))); // TODO: Make sure that the entity actually inherited from CBaseToggle ((CBaseToggle *)pEntity)->SetMoveDone(&CBaseToggle::SUB_MoveDone); diff --git a/reapi/src/entity_callback.h b/reapi/src/entity_callback.h index 0d0f772..b9fb720 100644 --- a/reapi/src/entity_callback.h +++ b/reapi/src/entity_callback.h @@ -72,7 +72,7 @@ private: size_t m_iParamLen; }; - std::vector *> m_callbacks; + std::vector *> m_callbacks; }; extern CEntityCallback g_entCallback; diff --git a/reapi/src/hook_callback.h b/reapi/src/hook_callback.h index 65dde99..4ba9e39 100644 --- a/reapi/src/hook_callback.h +++ b/reapi/src/hook_callback.h @@ -130,7 +130,9 @@ struct hookctx_t tempstrings_used++; return ptr; } - return ""; + + static char fatalErr[] = ""; + return fatalErr; } void clear_temp_strings() const diff --git a/reapi/src/hook_list.cpp b/reapi/src/hook_list.cpp index ea82b57..33fcbca 100644 --- a/reapi/src/hook_list.cpp +++ b/reapi/src/hook_list.cpp @@ -71,7 +71,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##__VA_ARGS__) : regfunc(#h#__VA_ARGS__), [](){ 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##__VA_ARGS__) : regfunc(#h#__VA_ARGS__), [](){ g_RehldsHookchains->h()->registerHook(&h); }, [](){ g_RehldsHookchains->h()->unregisterHook(&h); }} hook_t hooklist_engine[] = { ENG(SV_StartSound), ENG(SV_DropClient), @@ -80,7 +80,7 @@ hook_t hooklist_engine[] = { ENG(SV_WriteFullClientUpdate, _AMXX) }; -#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); }} +#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), @@ -196,7 +196,7 @@ hook_t hooklist_weaponbox[] = { DLL(CWeaponBox_SetModel), }; -#define RCHECK(h,...) { {}, {}, #h, "ReChecker", [](){ return api_cfg.hasRechecker(); }, ((!(RC_##h & (MAX_REGION_RANGE - 1)) ? regfunc::current_cell = 1, true : false) || (RC_##h & (MAX_REGION_RANGE - 1)) == regfunc::current_cell++) ? regfunc(h##__VA_ARGS__) : regfunc(#h#__VA_ARGS__), [](){ g_RecheckerHookchains->##h##()->registerHook(&##h); }, [](){ g_RecheckerHookchains->##h##()->unregisterHook(&##h); }} +#define RCHECK(h,...) { {}, {}, #h, "ReChecker", [](){ return api_cfg.hasRechecker(); }, ((!(RC_##h & (MAX_REGION_RANGE - 1)) ? regfunc::current_cell = 1, true : false) || (RC_##h & (MAX_REGION_RANGE - 1)) == regfunc::current_cell++) ? regfunc(h##__VA_ARGS__) : regfunc(#h#__VA_ARGS__), [](){ g_RecheckerHookchains->h()->registerHook(&h); }, [](){ g_RecheckerHookchains->h()->unregisterHook(&h); }} hook_t hooklist_rechecker[] = { RCHECK(FileConsistencyProcess, _AMXX), RCHECK(FileConsistencyFinal), diff --git a/reapi/src/hook_list.h b/reapi/src/hook_list.h index 21ee71b..a8b2932 100644 --- a/reapi/src/hook_list.h +++ b/reapi/src/hook_list.h @@ -11,8 +11,8 @@ typedef void (*regchain_t)(); struct hook_t { - std::vector *> pre; // pre forwards - std::vector *> post; // post forwards + std::vector pre; // pre forwards + std::vector post; // post forwards const char *func_name; // function name const char *depend_name; // platform dependency @@ -59,6 +59,8 @@ struct hooklist_t CASE(weaponbox) } + #undef CASE + return nullptr; } @@ -74,9 +76,7 @@ struct hooklist_t ht_gamerules, ht_rechecker, ht_grenade, - ht_weaponbox, - - ht_end + ht_weaponbox }; }; diff --git a/reapi/src/hook_manager.cpp b/reapi/src/hook_manager.cpp index 1c2050d..4476ccb 100644 --- a/reapi/src/hook_manager.cpp +++ b/reapi/src/hook_manager.cpp @@ -13,7 +13,7 @@ int CHookManager::addHandler(AMX *amx, int func, const char *funcname, int forwa } auto& dest = post ? hook->post : hook->pre; - dest.push_back(new CAmxxHook<>(amx, funcname, forward)); + dest.push_back(new CAmxxHookBase(amx, funcname, forward)); int id = func * MAX_HOOK_FORWARDS + dest.size(); return post ? -id : id; // use unsigned ids for post hooks } @@ -28,7 +28,7 @@ hook_t *CHookManager::getHook(size_t func) const return m_hooklist.getHookSafe(func); } -CAmxxHook<> *CHookManager::getAmxxHook(cell handle) const +CAmxxHookBase *CHookManager::getAmxxHook(cell handle) const { bool post = handle < 0; diff --git a/reapi/src/hook_manager.h b/reapi/src/hook_manager.h index f364f44..6c5a365 100644 --- a/reapi/src/hook_manager.h +++ b/reapi/src/hook_manager.h @@ -9,7 +9,7 @@ public: void Clear() const; cell addHandler(AMX *amx, int func, const char *funcname, int forward, bool post) const; hook_t *getHook(size_t func) const; - CAmxxHook<> *getAmxxHook(cell hook) const; + CAmxxHookBase *getAmxxHook(cell hook) const; hook_t *getHookFast(size_t func) const { return m_hooklist[func]; diff --git a/reapi/src/member_list.cpp b/reapi/src/member_list.cpp index 5ff0438..b9975bb 100644 --- a/reapi/src/member_list.cpp +++ b/reapi/src/member_list.cpp @@ -7,62 +7,66 @@ #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) + #define decltypefx(cx, pref, mx) decltype(std::declval().pref##mx) + #define decltypefxdot(cx, pref, mx) decltype(std::declval().pref.mx) #else - #define decltypefx(cx, pref, dt, mx) decltype(cx::pref##mx) + #define decltypefx(cx, pref, mx) decltype(cx::pref##mx) + #define decltypefxdot(cx, pref, 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 CLASS_MEMBERS(cx, mx, postf) ((!(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, , mx) f = {};ptr->size = getTypeSize(f);ptr->max_size = sizeof(f);ptr->offset = offsetof(cx, mx);ptr->type = getMemberType(f);ptr->name = #postf;}) : regmember(#mx) +#define CLASS_MEMBERS_PREF(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 CLASS_MEMBERS_DOT(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){ decltypefxdot(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(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,) -#define PL_MEMBERS(mx) CLASS_MEMBERS(CBasePlayer, mx, mx,) -#define EVAR_MEMBERS(mx) CLASS_MEMBERS(com_entvars, mx, var_##mx,) -#define PMOVE_MEMBERS(mx) CLASS_MEMBERS(com_playermove, mx, pm_##mx,) -#define MOVEVAR_MEMBERS(mx) CLASS_MEMBERS(movevars_t, mx, mv_##mx,) -#define UCMD_MEMBERS(mx) CLASS_MEMBERS(usercmd_s, mx, ucmd_##mx,) -#define PMTRACE_MEMBERS(mx) CLASS_MEMBERS(pmtrace_s, mx, pmt_##mx,) -#define CSPL_MEMBERS(mx) CLASS_MEMBERS(CCSPlayer, mx, mx,) -#define BASEITEM_MEMBERS(mx) CLASS_MEMBERS(CBasePlayerItem, mx, mx,) -#define BASEWPN_MEMBERS(mx) CLASS_MEMBERS(CBasePlayerWeapon, mx, m_Weapon_##mx, m_) -#define WPNBOX_MEMBERS(mx) CLASS_MEMBERS(CWeaponBox, mx, m_WeaponBox_##mx, m_) -#define ARMOURY_MEMBERS(mx) CLASS_MEMBERS(CArmoury, mx, m_Armoury_##mx, m_) -#define GRENADE_MEMBERS(mx) CLASS_MEMBERS(CGrenade, mx, m_Grenade_##mx, m_) -#define P228_MEMBERS(mx) CLASS_MEMBERS(CP228, mx, m_P228_##mx, m_) -#define SCOUT_MEMBERS(mx) CLASS_MEMBERS(CSCOUT, mx, m_SCOUT_##mx, m_) -#define HEGREN_MEMBERS(mx) CLASS_MEMBERS(CHEGrenade, mx, m_HEGrenade_##mx, m_) -#define XM1014_MEMBERS(mx) CLASS_MEMBERS(CXM1014, mx, m_XM1014_##mx, m_) -#define C4_MEMBERS(mx) CLASS_MEMBERS(CC4, mx, m_C4_##mx, m_) -#define MAC10_MEMBERS(mx) CLASS_MEMBERS(CMAC10, mx, m_MAC10_##mx, m_) -#define AUG_MEMBERS(mx) CLASS_MEMBERS(CAUG, mx, m_AUG_##mx, m_) -#define SMOKEGREN_MEMBERS(mx) CLASS_MEMBERS(CSmokeGrenade, mx, m_SmokeGrenade_##mx, m_) -#define ELITE_MEMBERS(mx) CLASS_MEMBERS(CELITE, mx, m_ELITE_##mx, m_) -#define FIVESEVEN_MEMBERS(mx) CLASS_MEMBERS(CFiveSeven, mx, m_FiveSeven_##mx, m_) -#define UMP45_MEMBERS(mx) CLASS_MEMBERS(CUMP45, mx, m_UMP45_##mx, m_) -#define SG550_MEMBERS(mx) CLASS_MEMBERS(CSG550, mx, m_SG550_##mx, m_) -#define GALIL_MEMBERS(mx) CLASS_MEMBERS(CGalil, mx, m_Galil_##mx, m_) -#define FAMAS_MEMBERS(mx) CLASS_MEMBERS(CFamas, mx, m_Famas_##mx, m_) -#define USP_MEMBERS(mx) CLASS_MEMBERS(CUSP, mx, m_USP_##mx, m_) -#define GLOCK18_MEMBERS(mx) CLASS_MEMBERS(CGLOCK18, mx, m_GLOCK18_##mx, m_) -#define AWP_MEMBERS(mx) CLASS_MEMBERS(CAWP, mx, m_AWP_##mx, m_) -#define MP5N_MEMBERS(mx) CLASS_MEMBERS(CMP5N, mx, m_MP5N_##mx, m_) -#define M249_MEMBERS(mx) CLASS_MEMBERS(CM249, mx, m_M249_##mx, m_) -#define M3_MEMBERS(mx) CLASS_MEMBERS(CM3, mx, m_M3_##mx, m_) -#define M4A1_MEMBERS(mx) CLASS_MEMBERS(CM4A1, mx, m_M4A1_##mx, m_) -#define TMP_MEMBERS(mx) CLASS_MEMBERS(CTMP, mx, m_TMP_##mx, m_) -#define G3SG1_MEMBERS(mx) CLASS_MEMBERS(CG3SG1, mx, m_G3SG1_##mx, m_) -#define DEAGLE_MEMBERS(mx) CLASS_MEMBERS(CDEAGLE, mx, m_DEAGLE_##mx, m_) -#define SG552_MEMBERS(mx) CLASS_MEMBERS(CSG552, mx, m_SG552_##mx, m_) -#define AK47_MEMBERS(mx) CLASS_MEMBERS(CAK47, mx, m_AK47_##mx, m_) -#define KNIFE_MEMBERS(mx) CLASS_MEMBERS(CKnife, mx, m_Knife_##mx, m_) -#define P90_MEMBERS(mx) CLASS_MEMBERS(CP90, mx, m_P90_##mx, m_) -#define SHIELD_MEMBERS(mx) CLASS_MEMBERS(CWShield, mx, m_Shield_##mx, m_) -#define REBUYSTRUCT_MEMBERS(mx) CLASS_MEMBERS(RebuyStruct, mx, mx,) -#define MAPINFO_MEMBERS(mx) CLASS_MEMBERS(CMapInfo, mx, m_MapInfo_##mx, m_) -#define CSPLWPN_MEMBERS(mx) CLASS_MEMBERS(CCSPlayerWeapon, mx, m_Weapon_##mx, m_) +#define GM_MEMBERS(mx) CLASS_MEMBERS(CHalfLifeMultiplay, mx, mx) +#define GM_VOICE_MEMBERS(mx) CLASS_MEMBERS_DOT(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) +#define PL_MEMBERS(mx) CLASS_MEMBERS(CBasePlayer, mx, mx) +#define EVAR_MEMBERS(mx) CLASS_MEMBERS(com_entvars, mx, var_##mx) +#define PMOVE_MEMBERS(mx) CLASS_MEMBERS(com_playermove, mx, pm_##mx) +#define MOVEVAR_MEMBERS(mx) CLASS_MEMBERS(movevars_t, mx, mv_##mx) +#define UCMD_MEMBERS(mx) CLASS_MEMBERS(usercmd_s, mx, ucmd_##mx) +#define PMTRACE_MEMBERS(mx) CLASS_MEMBERS(pmtrace_s, mx, pmt_##mx) +#define CSPL_MEMBERS(mx) CLASS_MEMBERS(CCSPlayer, mx, mx) +#define BASEITEM_MEMBERS(mx) CLASS_MEMBERS(CBasePlayerItem, mx, mx) +#define BASEWPN_MEMBERS(mx) CLASS_MEMBERS_PREF(CBasePlayerWeapon, mx, m_Weapon_##mx, m_) +#define WPNBOX_MEMBERS(mx) CLASS_MEMBERS_PREF(CWeaponBox, mx, m_WeaponBox_##mx, m_) +#define ARMOURY_MEMBERS(mx) CLASS_MEMBERS_PREF(CArmoury, mx, m_Armoury_##mx, m_) +#define GRENADE_MEMBERS(mx) CLASS_MEMBERS_PREF(CGrenade, mx, m_Grenade_##mx, m_) +#define P228_MEMBERS(mx) CLASS_MEMBERS_PREF(CP228, mx, m_P228_##mx, m_) +#define SCOUT_MEMBERS(mx) CLASS_MEMBERS_PREF(CSCOUT, mx, m_SCOUT_##mx, m_) +#define HEGREN_MEMBERS(mx) CLASS_MEMBERS_PREF(CHEGrenade, mx, m_HEGrenade_##mx, m_) +#define XM1014_MEMBERS(mx) CLASS_MEMBERS_PREF(CXM1014, mx, m_XM1014_##mx, m_) +#define C4_MEMBERS(mx) CLASS_MEMBERS_PREF(CC4, mx, m_C4_##mx, m_) +#define MAC10_MEMBERS(mx) CLASS_MEMBERS_PREF(CMAC10, mx, m_MAC10_##mx, m_) +#define AUG_MEMBERS(mx) CLASS_MEMBERS_PREF(CAUG, mx, m_AUG_##mx, m_) +#define SMOKEGREN_MEMBERS(mx) CLASS_MEMBERS_PREF(CSmokeGrenade, mx, m_SmokeGrenade_##mx, m_) +#define ELITE_MEMBERS(mx) CLASS_MEMBERS_PREF(CELITE, mx, m_ELITE_##mx, m_) +#define FIVESEVEN_MEMBERS(mx) CLASS_MEMBERS_PREF(CFiveSeven, mx, m_FiveSeven_##mx, m_) +#define UMP45_MEMBERS(mx) CLASS_MEMBERS_PREF(CUMP45, mx, m_UMP45_##mx, m_) +#define SG550_MEMBERS(mx) CLASS_MEMBERS_PREF(CSG550, mx, m_SG550_##mx, m_) +#define GALIL_MEMBERS(mx) CLASS_MEMBERS_PREF(CGalil, mx, m_Galil_##mx, m_) +#define FAMAS_MEMBERS(mx) CLASS_MEMBERS_PREF(CFamas, mx, m_Famas_##mx, m_) +#define USP_MEMBERS(mx) CLASS_MEMBERS_PREF(CUSP, mx, m_USP_##mx, m_) +#define GLOCK18_MEMBERS(mx) CLASS_MEMBERS_PREF(CGLOCK18, mx, m_GLOCK18_##mx, m_) +#define AWP_MEMBERS(mx) CLASS_MEMBERS_PREF(CAWP, mx, m_AWP_##mx, m_) +#define MP5N_MEMBERS(mx) CLASS_MEMBERS_PREF(CMP5N, mx, m_MP5N_##mx, m_) +#define M249_MEMBERS(mx) CLASS_MEMBERS_PREF(CM249, mx, m_M249_##mx, m_) +#define M3_MEMBERS(mx) CLASS_MEMBERS_PREF(CM3, mx, m_M3_##mx, m_) +#define M4A1_MEMBERS(mx) CLASS_MEMBERS_PREF(CM4A1, mx, m_M4A1_##mx, m_) +#define TMP_MEMBERS(mx) CLASS_MEMBERS_PREF(CTMP, mx, m_TMP_##mx, m_) +#define G3SG1_MEMBERS(mx) CLASS_MEMBERS_PREF(CG3SG1, mx, m_G3SG1_##mx, m_) +#define DEAGLE_MEMBERS(mx) CLASS_MEMBERS_PREF(CDEAGLE, mx, m_DEAGLE_##mx, m_) +#define SG552_MEMBERS(mx) CLASS_MEMBERS_PREF(CSG552, mx, m_SG552_##mx, m_) +#define AK47_MEMBERS(mx) CLASS_MEMBERS_PREF(CAK47, mx, m_AK47_##mx, m_) +#define KNIFE_MEMBERS(mx) CLASS_MEMBERS_PREF(CKnife, mx, m_Knife_##mx, m_) +#define P90_MEMBERS(mx) CLASS_MEMBERS_PREF(CP90, mx, m_P90_##mx, m_) +#define SHIELD_MEMBERS(mx) CLASS_MEMBERS_PREF(CWShield, mx, m_Shield_##mx, m_) +#define REBUYSTRUCT_MEMBERS(mx) CLASS_MEMBERS(RebuyStruct, mx, mx) +#define MAPINFO_MEMBERS(mx) CLASS_MEMBERS_PREF(CMapInfo, mx, m_MapInfo_##mx, m_) +#define CSPLWPN_MEMBERS(mx) CLASS_MEMBERS_PREF(CCSPlayerWeapon, mx, m_Weapon_##mx, m_) inline MType getMemberType(float*) { return MEMBER_FLOAT; } inline MType getMemberType(float) { return MEMBER_FLOAT; } @@ -118,8 +122,10 @@ inline MType getMemberType(RebuyStruct) { return MEBMER_REBUYSTRUCT; } inline MType getMemberType(pmtrace_t) { return MEMBER_PMTRACE; } inline MType getMemberType(usercmd_s) { return MEBMER_USERCMD; } +template struct always_false: std::false_type {}; + template -inline MType getMemberType(T) { static_assert(false, "Not implemented overload"); } +inline MType getMemberType(T) { static_assert(always_false::value, "Not implemented overload"); return MEMBER_NONE; } template inline size_t getTypeSize(T type[size]) { return sizeof(T); } @@ -141,6 +147,11 @@ struct regmember int regmember::current_cell = 1; +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Winvalid-offsetof" +#endif // #ifdef __GNUC__ + member_t memberlist_gamerules[] = { GM_MEMBERS(m_bFreezePeriod), GM_MEMBERS(m_bBombDropped), @@ -1004,6 +1015,10 @@ member_t memberlist_csplayerweapon[] = { CSPLWPN_MEMBERS(flBaseDamage), }; +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif // #ifdef __GNUC__ + memberlist_t memberlist; member_t *memberlist_t::operator[](size_t members) const @@ -1064,5 +1079,6 @@ member_t *memberlist_t::operator[](size_t members) const CASE(csplayerweapon) } + #undef CASE return nullptr; } diff --git a/reapi/src/member_list.h b/reapi/src/member_list.h index f14c714..0c7f32f 100644 --- a/reapi/src/member_list.h +++ b/reapi/src/member_list.h @@ -5,7 +5,8 @@ // member types enum MType { - MEMBER_FLOAT = 0, // Any floating point value + MEMBER_NONE = 0, + MEMBER_FLOAT, // Any floating point value MEMBER_DOUBLE, // double value MEMBER_ENTITY, // An entity offset (EOFFSET) MEMBER_CLASSPTR, // CBaseEntity * diff --git a/reapi/src/mods/mod_vtc_api.cpp b/reapi/src/mods/mod_vtc_api.cpp index ed2e678..470555d 100644 --- a/reapi/src/mods/mod_vtc_api.cpp +++ b/reapi/src/mods/mod_vtc_api.cpp @@ -12,8 +12,8 @@ bool VTC_Api_Init() if (!g_pVoiceTranscoderApi) return false; - int majorVersion = g_pVoiceTranscoderApi->GetMajorVersion(); - int minorVersion = g_pVoiceTranscoderApi->GetMinorVersion(); + size_t majorVersion = g_pVoiceTranscoderApi->GetMajorVersion(); + size_t minorVersion = g_pVoiceTranscoderApi->GetMinorVersion(); if (majorVersion != VOICETRANSCODER_API_VERSION_MAJOR) { diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 4150929..58bad25 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -1202,7 +1202,8 @@ cell AMX_NATIVE_CALL rg_give_defusekit(AMX *amx, cell *params) return FALSE; } - pPlayer->m_bHasDefuser = pPlayer->pev->body = params[arg_def] != 0; + pPlayer->m_bHasDefuser = params[arg_def] ? true : false; + pPlayer->pev->body = params[arg_def] ? 1 : 0; if (params[arg_def] != 0) { @@ -1326,6 +1327,8 @@ cell AMX_NATIVE_CALL rg_set_user_team(AMX *amx, cell *params) case CT: CSGameRules()->m_iNumCT++; break; + default: + break; } // previous team @@ -1359,6 +1362,8 @@ cell AMX_NATIVE_CALL rg_set_user_team(AMX *amx, cell *params) pPlayer->CSPlayer()->SendItemStatus(); } break; + default: + break; } } diff --git a/reapi/src/reapi_utils.h b/reapi/src/reapi_utils.h index c471483..7e73aca 100644 --- a/reapi/src/reapi_utils.h +++ b/reapi/src/reapi_utils.h @@ -57,4 +57,4 @@ void GetBonePosition(CBaseEntity *pEntity, int iBone, Vector *vecOrigin, Vector void GetAttachment(CBaseEntity *pEntity, int iBone, Vector *pVecOrigin, Vector *pVecAngles); void RemoveOrDropItem(CBasePlayer *pPlayer, CBasePlayerItem *pItem, GiveType type); -extern void __declspec(noreturn) UTIL_SysError(const char *fmt, ...); +extern void NORETURN UTIL_SysError(const char *fmt, ...); diff --git a/reapi/src/sdk_util.cpp b/reapi/src/sdk_util.cpp index a5f8baa..1df65c7 100644 --- a/reapi/src/sdk_util.cpp +++ b/reapi/src/sdk_util.cpp @@ -1,6 +1,6 @@ #include "precompiled.h" -void __declspec(noreturn) UTIL_SysError(const char *fmt, ...) +void NORETURN UTIL_SysError(const char *fmt, ...) { va_list argptr; char string[8192]; diff --git a/shared.gradle b/shared.gradle index cc61691..7aa1a6b 100644 --- a/shared.gradle +++ b/shared.gradle @@ -8,6 +8,7 @@ import org.gradle.nativeplatform.toolchain.VisualCpp apply from: 'shared_msvc.gradle' apply from: 'shared_icc.gradle' +apply from: 'shared_gcc.gradle' rootProject.ext.createToolchainConfig = { NativeBinarySpec bin -> BinaryKind binaryKind @@ -27,6 +28,8 @@ rootProject.ext.createToolchainConfig = { NativeBinarySpec bin -> return rootProject.createMsvcConfig(releaseBuild, binaryKind) } else if (bin.toolChain instanceof Icc) { return rootProject.createIccConfig(releaseBuild, binaryKind) + } else if (bin.toolChain instanceof Gcc) { + return rootProject.createGccConfig(releaseBuild, binaryKind) } else { throw new RuntimeException("Unknown native toolchain: ${bin.toolChain.class.name}") } diff --git a/shared_gcc.gradle b/shared_gcc.gradle new file mode 100644 index 0000000..a56ba45 --- /dev/null +++ b/shared_gcc.gradle @@ -0,0 +1,63 @@ +import org.doomedsociety.gradlecpp.cfg.BinaryKind +import org.doomedsociety.gradlecpp.gcc.GccToolchainConfig +import org.doomedsociety.gradlecpp.gcc.OptimizationLevel + +rootProject.ext.createGccConfig = { boolean release, BinaryKind binKind -> + GccToolchainConfig cfg + if (release) { + cfg = new GccToolchainConfig( + compilerOptions: new GccToolchainConfig.CompilerOptions( + optimizationLevel: OptimizationLevel.LEVEL_3, + stackProtector: false, + noBuiltIn: true, + positionIndependentCode: false, + + extraDefines: [ + 'linux': null, + '__linux__': null, + 'NDEBUG': null, + '_GLIBCXX_USE_CXX11_ABI': 0, // don't use specific c++11 features from GCC 5.X for backward compatibility to earlier version ABI libstdc++.so.6 + ], + ), + + linkerOptions: new GccToolchainConfig.LinkerOptions( + stripSymbolTable: false, + staticLibGcc: false, + staticLibStdCpp: false, + ), + + librarianOptions: new GccToolchainConfig.LibrarianOptions( + + ) + ) + } else { + // debug + cfg = new GccToolchainConfig( + compilerOptions: new GccToolchainConfig.CompilerOptions( + optimizationLevel: OptimizationLevel.DISABLE, + stackProtector: true, + noBuiltIn: true, + + extraDefines: [ + 'linux': null, + '__linux__': null, + 'NDEBUG': null, + '_GLIBCXX_USE_CXX11_ABI': 0, // don't use specific c++11 features from GCC 5.X for backward compatibility to earlier version ABI libstdc++.so.6 + ], + ), + + linkerOptions: new GccToolchainConfig.LinkerOptions( + stripSymbolTable: false, + staticLibGcc: false, + staticLibStdCpp: false, + ), + + librarianOptions: new GccToolchainConfig.LibrarianOptions( + + ) + ) + } + + cfg.singleDefines('LINUX', '_LINUX') + return cfg +}