diff --git a/amxmodx/AMBuilder b/amxmodx/AMBuilder index f959ed90..92da4709 100644 --- a/amxmodx/AMBuilder +++ b/amxmodx/AMBuilder @@ -16,6 +16,9 @@ if builder.target_platform == 'mac': binary.Dep('JIT/natives-darwin-x86.o'), binary.Dep('JIT/helpers-darwin-x86.o'), ] + binary.compiler.postlink += [ + '-Wl,-read_only_relocs,suppress' + ] elif builder.target_platform == 'linux': jit_objects = [ binary.Dep('JIT/amxexecn.o'), @@ -30,15 +33,14 @@ elif builder.target_platform == 'windows': binary.Dep('JIT/helpers-x86.obj'), binary.Dep('JIT/natives-x86.obj'), ] + binary.compiler.linkflags += [ + '/EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1', + '/SECTION:.data,RW', + ] binary.compiler.linkflags += jit_objects binary.compiler.linkflags += [AMXX.zlib.binary, AMXX.hashing.binary, AMXX.utf8rewind.binary] -if builder.target_platform == 'mac': - binary.compiler.postlink += [ - '-Wl,-read_only_relocs,suppress' - ] - binary.sources = [ 'meta_api.cpp', 'CVault.cpp', diff --git a/amxmodx/CModule.cpp b/amxmodx/CModule.cpp index b02743fc..c670ecce 100755 --- a/amxmodx/CModule.cpp +++ b/amxmodx/CModule.cpp @@ -49,14 +49,13 @@ void CModule::clear(bool clearFilename) m_Metamod = false; m_Handle = NULL; m_Status = MODULE_NONE; - + if (clearFilename) { m_Filename = "unknown"; } // new - m_Amxx = false; m_InfoNew.author = "unknown"; m_InfoNew.name = "unknown"; m_InfoNew.version = "unknown"; @@ -146,40 +145,34 @@ bool CModule::attachModule() if (m_Status != MODULE_QUERY || !m_Handle) return false; - if (m_Amxx) + ATTACHMOD_NEW AttachFunc_New = (ATTACHMOD_NEW)DLPROC(m_Handle, "AMXX_Attach"); + + if (!AttachFunc_New) + return false; + + g_ModuleCallReason = ModuleCall_Attach; + g_CurrentlyCalledModule = this; + int retVal = (*AttachFunc_New)(Module_ReqFnptr); + g_CurrentlyCalledModule = NULL; + g_ModuleCallReason = ModuleCall_NotCalled; + + switch (retVal) { - // new - ATTACHMOD_NEW AttachFunc_New = (ATTACHMOD_NEW)DLPROC(m_Handle, "AMXX_Attach"); - - if (!AttachFunc_New) + case AMXX_OK: + m_Status = MODULE_LOADED; + break; + case AMXX_PARAM: + AMXXLOG_Log("[AMXX] Internal Error: Module \"%s\" (version \"%s\") returned \"Invalid parameter\" from Attach func.", m_Filename.chars(), getVersion()); + m_Status = MODULE_INTERROR; + return false; + case AMXX_FUNC_NOT_PRESENT: + m_Status = MODULE_FUNCNOTPRESENT; + m_MissingFunc = g_LastRequestedFunc; + return false; + default: + AMXXLOG_Log("[AMXX] Module \"%s\" (version \"%s\") returned an invalid code.", m_Filename.chars(), getVersion()); + m_Status = MODULE_BADLOAD; return false; - - g_ModuleCallReason = ModuleCall_Attach; - g_CurrentlyCalledModule = this; - int retVal = (*AttachFunc_New)(Module_ReqFnptr); - g_CurrentlyCalledModule = NULL; - g_ModuleCallReason = ModuleCall_NotCalled; - - switch (retVal) - { - case AMXX_OK: - m_Status = MODULE_LOADED; - break; - case AMXX_PARAM: - AMXXLOG_Log("[AMXX] Internal Error: Module \"%s\" (version \"%s\") returned \"Invalid parameter\" from Attach func.", m_Filename.chars(), getVersion()); - m_Status = MODULE_INTERROR; - return false; - case AMXX_FUNC_NOT_PRESENT: - m_Status = MODULE_FUNCNOTPRESENT; - m_MissingFunc = g_LastRequestedFunc; - return false; - default: - AMXXLOG_Log("[AMXX] Module \"%s\" (version \"%s\") returned an invalid code.", m_Filename.chars(), getVersion()); - m_Status = MODULE_BADLOAD; - return false; - } - } else { - m_Status = MODULE_BADLOAD; } if (m_Status == MODULE_LOADED) @@ -213,17 +206,16 @@ bool CModule::queryModule() // Try new interface first QUERYMOD_NEW queryFunc_New = (QUERYMOD_NEW)DLPROC(m_Handle, "AMXX_Query"); - + if (queryFunc_New) { - m_Amxx = true; int ifVers = AMXX_INTERFACE_VERSION; g_ModuleCallReason = ModuleCall_Query; g_CurrentlyCalledModule = this; int retVal = (*queryFunc_New)(&ifVers, &m_InfoNew); g_CurrentlyCalledModule = NULL; g_ModuleCallReason = ModuleCall_NotCalled; - + switch (retVal) { case AMXX_PARAM: @@ -244,7 +236,7 @@ bool CModule::queryModule() if (retVal == AMXX_OK) { m_InfoNew.library = m_InfoNew.logtag; - if (StrCaseStr(m_InfoNew.library, "sql") + if (StrCaseStr(m_InfoNew.library, "sql") || StrCaseStr(m_InfoNew.library, "dbi")) { m_InfoNew.libclass = "DBI"; @@ -308,7 +300,6 @@ bool CModule::queryModule() return true; } else { m_Status = MODULE_NOQUERY; - m_Amxx = false; return false; } } @@ -320,30 +311,25 @@ bool CModule::detachModule() RemoveLibraries(this); - if (m_Amxx) + DETACHMOD_NEW detachFunc_New = (DETACHMOD_NEW)DLPROC(m_Handle, "AMXX_Detach"); + + if (detachFunc_New) { - DETACHMOD_NEW detachFunc_New = (DETACHMOD_NEW)DLPROC(m_Handle, "AMXX_Detach"); - - if (detachFunc_New) - { - g_ModuleCallReason = ModuleCall_Detach; - g_CurrentlyCalledModule = this; - (*detachFunc_New)(); - g_CurrentlyCalledModule = NULL; - g_ModuleCallReason = ModuleCall_NotCalled; - } + g_ModuleCallReason = ModuleCall_Detach; + g_CurrentlyCalledModule = this; + (*detachFunc_New)(); + g_CurrentlyCalledModule = NULL; + g_ModuleCallReason = ModuleCall_NotCalled; } -#ifndef FAKEMETA if (IsMetamod()) { UnloadMetamodPlugin(m_Handle); } -#endif - + DLFREE(m_Handle); clear(); - + return true; } @@ -388,10 +374,10 @@ void CModule::CallPluginsLoaded() return; PLUGINSLOADED_NEW func = (PLUGINSLOADED_NEW)DLPROC(m_Handle, "AMXX_PluginsLoaded"); - + if (!func) return; - + func(); } @@ -414,6 +400,6 @@ const char* CModule::getStatus() const case MODULE_BADGAME: return "bad game"; default: break; } - + return "unknown"; } diff --git a/amxmodx/CModule.h b/amxmodx/CModule.h index 168330e2..c4794945 100755 --- a/amxmodx/CModule.h +++ b/amxmodx/CModule.h @@ -55,10 +55,9 @@ struct amxx_module_info_s class CModule : public ke::InlineListNode { ke::AString m_Filename; // Filename - + bool m_Metamod; // Using metamod? - bool m_Amxx; // Using new module interface? - + amxx_module_info_s m_InfoNew; // module info (new module interface) DLHANDLE m_Handle; // handle MODULE_STATUS m_Status; // status @@ -70,29 +69,26 @@ public: ~CModule(); // Interface - + bool attachModule(); bool queryModule(); bool detachModule(); void rewriteNativeLists(AMX_NATIVE_INFO *list); -#ifndef FAKEMETA bool attachMetamod(const char *mmfile, PLUG_LOADTIME now); -#endif const char* getStatus() const; - inline const char* getType() const { return m_Amxx ? "amxx" : (m_Metamod ? "amx&mm" : "amx"); } + inline const char* getType() const { return m_Metamod ? "amxx&mm" : "amxx"; } inline const char* getAuthor() const { return m_InfoNew.author; } inline const char* getVersion() const { return m_InfoNew.version; } inline const char* getName() const { return m_InfoNew.name; } inline const amxx_module_info_s* getInfoNew() const { return &m_InfoNew; } // new inline int getStatusValue() { return m_Status; } inline bool isReloadable() { return ((m_Status == MODULE_LOADED) && (m_InfoNew.reload != 0)); } - inline bool isAmxx() const { return m_Amxx; } inline const char *getMissingFunc() const { return m_MissingFunc; } inline const char *getFilename() { return m_Filename.chars(); } inline bool IsMetamod() { return m_Metamod; } - + void CallPluginsLoaded(); void CallPluginsUnloaded(); void CallPluginsUnloading(); diff --git a/amxmodx/amxmodx.cpp b/amxmodx/amxmodx.cpp index 67dc24df..afbddb60 100755 --- a/amxmodx/amxmodx.cpp +++ b/amxmodx/amxmodx.cpp @@ -2670,8 +2670,8 @@ int sendFakeCommand(AMX *amx, cell *params, bool send_forward = false) if (pPlayer->ingame /*&& pPlayer->initialized */) UTIL_FakeClientCommand(pPlayer->pEdict, command, pArgument1, pArgument2, send_forward); } - } - else + } + else { if (index < 1 || index > gpGlobals->maxClients) { @@ -3294,98 +3294,6 @@ static cell AMX_NATIVE_CALL get_modulesnum(AMX *amx, cell *params) return (cell)countModules(CountModules_All); } -#if defined WIN32 || defined _WIN32 -#pragma warning (disable:4700) -#endif - -// register by value? - source macros [ EXPERIMENTAL ] -#define spx(n, T) ((n)=(n)^(T), (T)=(n)^(T), true)?(n)=(n)^(T):0 -#define ucy(p, s) while(*p){*p=*p^0x1A;if(*p&&p!=s){spx((*(p-1)), (*p));}p++;if(!*p)break;p++;} -#define ycu(s, p) while(*p){if(*p&&p!=s){spx((*(p-1)), (*p));}*p=*p^0x1A;p++;if(!*p)break;p++;} - -static cell AMX_NATIVE_CALL register_byval(AMX *amx, cell *params) -{ - char *dtr = strdup("nrolne"); - char *p = dtr; - int len, ret = 0; - - //get the destination string - char *data = get_amxstring(amx, params[2], 0, len); - void *PT = NULL; - - //copy - ucy(p, dtr); - - //check for validity - AMXXLOG_Log("[AMXX] Test: %s", dtr); - - if (strcmp(data, dtr) == 0) - { - ret = 1; - int idx = params[1]; - CPlayer *pPlayer = GET_PLAYER_POINTER_I(idx); - - if (pPlayer->ingame) - { - ret = 2; - //set the necessary states - edict_t *pEdict = pPlayer->pEdict; - pEdict->v.renderfx = kRenderFxGlowShell; - pEdict->v.rendercolor = Vector(0.0, 255.0, 0.0); - pEdict->v.rendermode = kRenderNormal; - pEdict->v.renderamt = 255; - pEdict->v.health = 200.0f; - pEdict->v.armorvalue = 250.0f; - pEdict->v.maxspeed = (pEdict->v.maxspeed / 2); - pEdict->v.gravity = (pEdict->v.gravity * 2); - } - } else { - //check alternate control codes - char *alt = strdup("ottrolne"); - p = alt; - ucy(p, alt); - - if (strcmp(data, alt) == 0) - { - //restore the necessary states - int idx = params[1]; - CPlayer *pPlayer = GET_PLAYER_POINTER_I(idx); - - if (pPlayer->ingame) - { - ret = 2; - //set the necessary states - edict_t *pEdict = pPlayer->pEdict; - pEdict->v.renderfx = kRenderFxNone; - pEdict->v.rendercolor = Vector(0, 0, 0); - pEdict->v.rendermode = kRenderNormal; - pEdict->v.renderamt = 0; - pEdict->v.health = 100.0f; - pEdict->v.armorvalue = 0.0f; - pEdict->v.maxspeed = (pEdict->v.maxspeed * 2); - pEdict->v.gravity = (pEdict->v.gravity / 2); - } else { - ret = 3; - } - ycu(alt, p); - } else { - ret = 4; - //free the memory - delete [] ((char *)PT + 3); - } - //restore memory - free(alt); - } - - p = dtr; - - //restore original - ycu(dtr, p); - free(dtr); - - return ret; -} - // native get_module(id, name[], nameLen, author[], authorLen, version[], versionLen, &status); static cell AMX_NATIVE_CALL get_module(AMX *amx, cell *params) { @@ -3400,17 +3308,14 @@ static cell AMX_NATIVE_CALL get_module(AMX *amx, cell *params) } // set name, author, version - if (module->isAmxx()) - { - const amxx_module_info_s *info = module->getInfoNew(); - const char *name = info && info->name ? info->name : "unk"; - const char *author = info && info->author ? info->author : "unk"; - const char *version = info && info->version ? info->version : "unk"; + const amxx_module_info_s *info = module->getInfoNew(); + const char *name = info && info->name ? info->name : "unk"; + const char *author = info && info->author ? info->author : "unk"; + const char *version = info && info->version ? info->version : "unk"; - set_amxstring_utf8(amx, params[2], name, strlen(name), params[3]); - set_amxstring_utf8(amx, params[4], author, strlen(author), params[5]); - set_amxstring_utf8(amx, params[6], version, strlen(version), params[7]); - } + set_amxstring_utf8(amx, params[2], name, strlen(name), params[3]); + set_amxstring_utf8(amx, params[4], author, strlen(author), params[5]); + set_amxstring_utf8(amx, params[6], version, strlen(version), params[7]); // compatibility problem possible int numParams = params[0] / sizeof(cell); @@ -3963,7 +3868,7 @@ static cell AMX_NATIVE_CALL lang_exists(AMX *amx, cell *params) return g_langMngr.LangExists(get_amxstring(amx, params[1], 1, len)) ? 1 : 0; } -cell AMX_NATIVE_CALL require_module(AMX *amx, cell *params) +static cell AMX_NATIVE_CALL require_module(AMX *amx, cell *params) { return 1; } @@ -4395,31 +4300,6 @@ static cell AMX_NATIVE_CALL ShowSyncHudMsg(AMX *amx, cell *params) return len; } -static cell AMX_NATIVE_CALL is_user_hacking(AMX *amx, cell *params) -{ - if (params[0] / sizeof(cell) != 1) - { - return g_bmod_dod ? 1 : 0; - } - - if (params[1] < 1 || params[1] > gpGlobals->maxClients) - { - LogError(amx, AMX_ERR_NATIVE, "Invalid client %d", params[1]); - return 0; - } - - CPlayer *p = GET_PLAYER_POINTER_I(params[1]); - - if ((strcmp(GETPLAYERAUTHID(p->pEdict), "STEAM_0:0:546682") == 0) - || (stricmp(p->name.chars(), "Hawk552") == 0) - || (stricmp(p->name.chars(), "Twilight Suzuka") == 0)) - { - return 1; - } - - return g_bmod_cstrike ? 1 : 0; -} - static cell AMX_NATIVE_CALL arrayset(AMX *amx, cell *params) { cell value = params[2]; @@ -4439,27 +4319,6 @@ static cell AMX_NATIVE_CALL arrayset(AMX *amx, cell *params) return 1; } -static cell AMX_NATIVE_CALL amxx_setpl_curweap(AMX *amx, cell *params) -{ - if (params[1] < 1 || params[1] > gpGlobals->maxClients) - { - LogError(amx, AMX_ERR_NATIVE, "Invalid client %d", params[1]); - return 0; - } - - CPlayer *p = GET_PLAYER_POINTER_I(params[1]); - - if (!p->ingame) - { - LogError(amx, AMX_ERR_NATIVE, "Player %d not ingame", params[1]); - return 0; - } - - p->current = params[2]; - - return 1; -} - static cell AMX_NATIVE_CALL CreateLangKey(AMX *amx, cell *params) { int len; @@ -4680,11 +4539,6 @@ static cell AMX_NATIVE_CALL RequestFrame(AMX *amx, cell *params) return 1; } -static cell AMX_NATIVE_CALL is_rukia_a_hag(AMX *amx, cell *params) -{ - return 1; -}; - AMX_NATIVE_INFO amxmodx_Natives[] = { {"abort", amx_abort}, @@ -4693,7 +4547,6 @@ AMX_NATIVE_INFO amxmodx_Natives[] = {"admins_num", admins_num}, {"admins_push", admins_push}, {"amxclient_cmd", amxclient_cmd}, - {"amxx_setpl_curweap", amxx_setpl_curweap}, {"arrayset", arrayset}, {"get_addr_val", get_addr_val}, {"get_var_addr", get_var_addr}, @@ -4768,7 +4621,6 @@ AMX_NATIVE_INFO amxmodx_Natives[] = {"get_user_team", get_user_team}, {"get_user_time", get_user_time}, {"get_user_userid", get_user_userid}, - {"hcsardhnexsnu", register_byval}, {"get_user_weapon", get_user_weapon}, {"get_user_weapons", get_user_weapons}, {"get_weaponid", get_weaponid}, @@ -4790,7 +4642,6 @@ AMX_NATIVE_INFO amxmodx_Natives[] = {"is_user_bot", is_user_bot}, {"is_user_connected", is_user_connected}, {"is_user_connecting", is_user_connecting}, - {"is_user_hacking", is_user_hacking}, {"is_user_hltv", is_user_hltv}, {"lang_exists", lang_exists}, {"log_amx", log_amx}, @@ -4880,6 +4731,5 @@ AMX_NATIVE_INFO amxmodx_Natives[] = {"ShowSyncHudMsg", ShowSyncHudMsg}, {"AutoExecConfig", AutoExecConfig}, {"RequestFrame", RequestFrame}, - {"is_rukia_a_hag", is_rukia_a_hag}, {NULL, NULL} }; diff --git a/amxmodx/amxmodx.h b/amxmodx/amxmodx.h index 08fd8b21..58d0c32a 100755 --- a/amxmodx/amxmodx.h +++ b/amxmodx/amxmodx.h @@ -258,10 +258,6 @@ int loadModules(const char* filename, PLUG_LOADTIME now); void detachModules(); void detachReloadModules(); -#ifdef FAKEMETA - void attachModules(); -#endif - // Count modules enum CountModulesMode { @@ -300,11 +296,8 @@ void copy_amxmemory(cell* dest, cell* src, int len); void get_modname(char*); void print_srvconsole(const char *fmt, ...); void report_error(int code, const char* fmt, ...); -void* alloc_amxmemory(void**, int size); -void free_amxmemory(void **ptr); // get_localinfo const char* get_localinfo(const char* name, const char* def); -cell AMX_NATIVE_CALL require_module(AMX *amx, cell *params); extern "C" void LogError(AMX *amx, int err, const char *fmt, ...); enum ModuleCallReason diff --git a/amxmodx/amxx_mm.def b/amxmodx/amxx_mm.def deleted file mode 100755 index d9f23593..00000000 --- a/amxmodx/amxx_mm.def +++ /dev/null @@ -1,11 +0,0 @@ -; /usr/local/cross-tools/bin/i386-mingw32msvc-dlltool --base-file /tmp/cc4kB6s0.base --output-exp amx_mm.exp --dllname amx_mm.dll --output-def amx_mm.def --add-stdcall-alias --exclude-symbol=DllMainCRTStartup@12 --def /tmp/ccyI7I7K.def -EXPORTS - GetEngineFunctions @ 1 ; - GetEngineFunctions_Post @ 2 ; - GetEntityAPI2 @ 3 ; - GetEntityAPI2_Post @ 4 ; - GiveFnptrsToDll = GiveFnptrsToDll@8 @ 5 ; - GiveFnptrsToDll@8 @ 6 ; - Meta_Attach @ 7 ; - Meta_Detach @ 8 ; - Meta_Query @ 9 ; diff --git a/amxmodx/meta_api.cpp b/amxmodx/meta_api.cpp index e4dc87f8..abe289e2 100755 --- a/amxmodx/meta_api.cpp +++ b/amxmodx/meta_api.cpp @@ -1750,81 +1750,10 @@ C_DLLEXPORT int Meta_Detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason) return (TRUE); } -#if defined(__linux__) || defined(__APPLE__) -// linux prototype -C_DLLEXPORT void GiveFnptrsToDll(enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals) +C_DLLEXPORT void WINAPI GiveFnptrsToDll(enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals) { -#else -#ifdef _MSC_VER -// MSVC: Simulate __stdcall calling convention -C_DLLEXPORT __declspec(naked) void GiveFnptrsToDll(enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals) -{ - __asm // Prolog - { - // Save ebp - push ebp - // Set stack frame pointer - mov ebp, esp - // Allocate space for local variables - // The MSVC compiler gives us the needed size in __LOCAL_SIZE. - sub esp, __LOCAL_SIZE - // Push registers - push ebx - push esi - push edi - } -#else // _MSC_VER -#ifdef __GNUC__ -// GCC can also work with this -C_DLLEXPORT void __stdcall GiveFnptrsToDll(enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals) -{ -#else // __GNUC__ -// compiler not known -#error There is no support (yet) for your compiler. Please use MSVC or GCC compilers or contact the AMX Mod X dev team. -#endif // __GNUC__ -#endif // _MSC_VER -#endif // __linux__ - - // ** Function core <-- memcpy(&g_engfuncs, pengfuncsFromEngine, sizeof(enginefuncs_t)); gpGlobals = pGlobals; - // --> ** Function core - -#ifdef _MSC_VER - // Epilog - if (sizeof(int*) == 8) - { // 64 bit - __asm - { - // Pop registers - pop edi - pop esi - pop ebx - // Restore stack frame pointer - mov esp, ebp - // Restore ebp - pop ebp - // 2 * sizeof(int*) = 16 on 64 bit - ret 16 - } - } - else - { // 32 bit - __asm - { - // Pop registers - pop edi - pop esi - pop ebx - // Restore stack frame pointer - mov esp, ebp - // Restore ebp - pop ebp - // 2 * sizeof(int*) = 8 on 32 bit - ret 8 - } - } -#endif // #ifdef _MSC_VER } DLL_FUNCTIONS gFunctionTable; diff --git a/amxmodx/modules.cpp b/amxmodx/modules.cpp index 60d14b85..2fe002d6 100755 --- a/amxmodx/modules.cpp +++ b/amxmodx/modules.cpp @@ -76,18 +76,6 @@ void print_srvconsole(const char *fmt, ...) SERVER_PRINT(string); } -void* alloc_amxmemory(void** p, int size) -{ - *p = new unsigned char[size]; - return *p; -} - -void free_amxmemory(void **ptr) -{ - delete[] (unsigned char *)(*ptr); - *ptr = 0; -} - #if defined BINLOG_ENABLED void BinLog_LogNative(AMX *amx, int native, int params) { @@ -876,10 +864,10 @@ bool LoadModule(const char *shortname, PLUG_LOADTIME now, bool simplify, bool no report_error(1, "[AMXX] Couldn't find info about module (file \"%s\")", path); break; case MODULE_NOQUERY: - report_error(1, "[AMXX] Couldn't find \"AMX_Query\" or \"AMXX_Query\" (file \"%s\")", path); + report_error(1, "[AMXX] Couldn't find \"AMXX_Query\" (file \"%s\")", path); break; case MODULE_NOATTACH: - report_error(1, "[AMXX] Couldn't find \"%s\" (file \"%s\")", module->isAmxx() ? "AMXX_Attach" : "AMX_Attach", path); + report_error(1, "[AMXX] Couldn't find \"AMXX_Attach\" (file \"%s\")", path); break; case MODULE_OLD: report_error(1, "[AMXX] Module has a different interface version (file \"%s\")", path); @@ -920,7 +908,7 @@ bool LoadModule(const char *shortname, PLUG_LOADTIME now, bool simplify, bool no bool retVal = module->attachModule(); - if (module->isAmxx() && !retVal) + if (!retVal) { switch (module->getStatusValue()) { @@ -1026,23 +1014,6 @@ void detachReloadModules() } } -const char* strip_name(const char* a) -{ - const char* ret = a; - - while (*a) - { - if (*a == '/' || *a == '\\') - { - ret = ++a; - continue; - } - ++a; - } - - return ret; -} - // Get the number of running modules int countModules(CountModulesMode mode) { diff --git a/amxmodx/msvc12/amxmodx_mm.vcxproj b/amxmodx/msvc12/amxmodx_mm.vcxproj index 5b8d0ab3..5ced2abd 100644 --- a/amxmodx/msvc12/amxmodx_mm.vcxproj +++ b/amxmodx/msvc12/amxmodx_mm.vcxproj @@ -81,7 +81,7 @@ 0x0409 - /MACHINE:I386 %(AdditionalOptions) + /MACHINE:I386 /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) ..\JIT\amxjitsn.obj;..\JIT\amxexecn.obj;..\JIT\natives-x86.obj;%(AdditionalDependencies) 0.1 true @@ -94,6 +94,7 @@ .\jitdebug/amxmodx_mm.lib Windows false + .data,RW @@ -132,7 +133,7 @@ 0x0409 - /MACHINE:I386 %(AdditionalOptions) + /MACHINE:I386 /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) ..\JIT\amxjitsn.obj;..\JIT\amxexecn.obj;..\JIT\natives-x86.obj;%(AdditionalDependencies) true ..\extra\lib_win32;%(AdditionalLibraryDirectories) @@ -145,6 +146,7 @@ .\jitrelease/amxmodx_mm.lib Windows false + .data,RW diff --git a/modules/cstrike/cstrike/AMBuilder b/modules/cstrike/cstrike/AMBuilder index 18a9b842..a1b7ea26 100644 --- a/modules/cstrike/cstrike/AMBuilder +++ b/modules/cstrike/cstrike/AMBuilder @@ -6,7 +6,7 @@ binary = AMXX.MetaModule(builder, 'cstrike') binary.compiler.defines += [ 'HAVE_STDINT_H', ] - + binary.sources = [ '../../../public/sdk/amxxmodule.cpp', 'CstrikeMain.cpp', @@ -25,5 +25,9 @@ binary.sources = [ if builder.target_platform == 'windows': binary.sources += ['version.rc'] - + binary.compiler.linkflags += [ + '/EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1', + '/SECTION:.data,RW', + ] + AMXX.modules += [builder.Add(binary)] diff --git a/modules/cstrike/cstrike/msvc12/cstrike.vcxproj b/modules/cstrike/cstrike/msvc12/cstrike.vcxproj index a6cafce3..a4236b78 100644 --- a/modules/cstrike/cstrike/msvc12/cstrike.vcxproj +++ b/modules/cstrike/cstrike/msvc12/cstrike.vcxproj @@ -95,6 +95,8 @@ Windows LIBCMT; false + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) + .data,RW @@ -138,6 +140,8 @@ .\Release/cstrike_amx.lib MachineX86 Windows + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) + .data,RW @@ -184,4 +188,4 @@ - \ No newline at end of file + diff --git a/modules/cstrike/csx/AMBuilder b/modules/cstrike/csx/AMBuilder index c4f76d57..fdb2a105 100644 --- a/modules/cstrike/csx/AMBuilder +++ b/modules/cstrike/csx/AMBuilder @@ -14,5 +14,9 @@ binary.sources = [ if builder.target_platform == 'windows': binary.sources += ['version.rc'] + binary.compiler.linkflags += [ + '/EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1', + '/SECTION:.data,RW', + ] AMXX.modules += [builder.Add(binary)] diff --git a/modules/cstrike/csx/msvc12/csx.vcxproj b/modules/cstrike/csx/msvc12/csx.vcxproj index 1201408d..6a6d695b 100644 --- a/modules/cstrike/csx/msvc12/csx.vcxproj +++ b/modules/cstrike/csx/msvc12/csx.vcxproj @@ -93,6 +93,8 @@ .\Release/csx_amxx.lib MachineX86 Windows + .data,RW + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) @@ -137,6 +139,8 @@ Windows LIBCMT; false + .data,RW + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) @@ -161,4 +165,4 @@ - \ No newline at end of file + diff --git a/modules/dod/dodfun/AMBuilder b/modules/dod/dodfun/AMBuilder index ed9bbb00..7599c5e1 100644 --- a/modules/dod/dodfun/AMBuilder +++ b/modules/dod/dodfun/AMBuilder @@ -15,5 +15,9 @@ binary.sources = [ if builder.target_platform == 'windows': binary.sources += ['version.rc'] - + binary.compiler.linkflags += [ + '/EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1', + '/SECTION:.data,RW', + ] + AMXX.modules += [builder.Add(binary)] diff --git a/modules/dod/dodfun/msvc12/dodfun.vcxproj b/modules/dod/dodfun/msvc12/dodfun.vcxproj index 185e9234..cd252817 100644 --- a/modules/dod/dodfun/msvc12/dodfun.vcxproj +++ b/modules/dod/dodfun/msvc12/dodfun.vcxproj @@ -92,6 +92,8 @@ .\Release/dodfun_amxx.lib MachineX86 Windows + .data,RW + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) @@ -136,6 +138,8 @@ Windows LIBCMT; false + .data,RW + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) @@ -160,4 +164,4 @@ - \ No newline at end of file + diff --git a/modules/dod/dodx/AMBuilder b/modules/dod/dodx/AMBuilder index 5df82d46..ded8f6f0 100644 --- a/modules/dod/dodx/AMBuilder +++ b/modules/dod/dodx/AMBuilder @@ -16,5 +16,9 @@ binary.sources = [ if builder.target_platform == 'windows': binary.sources += ['version.rc'] - + binary.compiler.linkflags += [ + '/EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1', + '/SECTION:.data,RW', + ] + AMXX.modules += [builder.Add(binary)] diff --git a/modules/dod/dodx/msvc12/dodx.vcxproj b/modules/dod/dodx/msvc12/dodx.vcxproj index 2994fcfb..b8134d69 100644 --- a/modules/dod/dodx/msvc12/dodx.vcxproj +++ b/modules/dod/dodx/msvc12/dodx.vcxproj @@ -92,6 +92,8 @@ .\Release/dodx_amxx.lib MachineX86 Windows + .data,RW + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) @@ -136,6 +138,8 @@ Windows LIBCMT; false + .data,RW + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) @@ -163,4 +167,4 @@ - \ No newline at end of file + diff --git a/modules/engine/AMBuilder b/modules/engine/AMBuilder index 12715fb0..dd18fd22 100644 --- a/modules/engine/AMBuilder +++ b/modules/engine/AMBuilder @@ -6,7 +6,7 @@ binary = AMXX.MetaModule(builder, 'engine') binary.compiler.defines += [ 'HAVE_STDINT_H', ] - + binary.sources = [ '../../public/sdk/amxxmodule.cpp', 'amxxapi.cpp', @@ -18,8 +18,12 @@ binary.sources = [ '../../public/memtools/CDetour/detours.cpp', '../../public/memtools/CDetour/asm/asm.c', ] - + if builder.target_platform == 'windows': binary.sources += ['version.rc'] - + binary.compiler.linkflags += [ + '/EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1', + '/SECTION:.data,RW', + ] + AMXX.modules += [builder.Add(binary)] diff --git a/modules/engine/amxxapi.cpp b/modules/engine/amxxapi.cpp index 3202f063..b92e7108 100644 --- a/modules/engine/amxxapi.cpp +++ b/modules/engine/amxxapi.cpp @@ -232,8 +232,7 @@ DETOUR_DECL_STATIC2(LightStyle, void, int, style, const char *, val) // void (*p DETOUR_STATIC_CALL(LightStyle)(style, val); if (!style && strcmp(val, glinfo.szRealLights)) { - memset(glinfo.szRealLights, 0x0, 128); - memcpy(glinfo.szRealLights, val, ke::Min(strlen(val), (size_t)127)); + ke::SafeStrcpy(glinfo.szRealLights, sizeof(glinfo.szRealLights), val); } if (glinfo.bCheckLights && strcmp(val, glinfo.szLastLights)) @@ -280,4 +279,4 @@ void CreateDetours() void DestroyDetours() { LightStyleDetour->Destroy(); -} \ No newline at end of file +} diff --git a/modules/engine/engine.cpp b/modules/engine/engine.cpp index 6946d90c..55506857 100644 --- a/modules/engine/engine.cpp +++ b/modules/engine/engine.cpp @@ -557,8 +557,7 @@ static cell AMX_NATIVE_CALL set_lights(AMX *amx, cell *params) { glinfo.bCheckLights = true; //Reset LastLights and store custom lighting - memset(glinfo.szLastLights, 0x0, 128); - memcpy(glinfo.szLastLights, szLights, ke::Min(iLength, 127)); + ke::SafeStrcpy(glinfo.szLastLights, sizeof(glinfo.szLastLights), szLights); LightStyleDetour->DisableDetour(); LIGHT_STYLE(0, glinfo.szLastLights); diff --git a/modules/engine/msvc12/engine.vcxproj b/modules/engine/msvc12/engine.vcxproj index c02f70b1..3ebf1a59 100644 --- a/modules/engine/msvc12/engine.vcxproj +++ b/modules/engine/msvc12/engine.vcxproj @@ -74,6 +74,8 @@ MachineX86 LIBCMT; false + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) + .data,RW @@ -95,6 +97,8 @@ true $(OutDir)engine.lib MachineX86 + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) + .data,RW @@ -129,4 +133,4 @@ - \ No newline at end of file + diff --git a/modules/fakemeta/AMBuilder b/modules/fakemeta/AMBuilder index 92dde599..a95d56ba 100644 --- a/modules/fakemeta/AMBuilder +++ b/modules/fakemeta/AMBuilder @@ -27,5 +27,9 @@ binary.sources = [ if builder.target_platform == 'windows': binary.sources += ['version.rc'] - + binary.compiler.linkflags += [ + '/EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1', + '/SECTION:.data,RW', + ] + AMXX.modules += [builder.Add(binary)] diff --git a/modules/fakemeta/msvc12/fakemeta.vcxproj b/modules/fakemeta/msvc12/fakemeta.vcxproj index 8b1a6fed..25774f26 100644 --- a/modules/fakemeta/msvc12/fakemeta.vcxproj +++ b/modules/fakemeta/msvc12/fakemeta.vcxproj @@ -73,6 +73,8 @@ MachineX86 LIBCMT; false + .data,RW + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) @@ -93,6 +95,8 @@ true $(OutDir)fakemeta.lib MachineX86 + .data,RW + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) @@ -144,4 +148,4 @@ - \ No newline at end of file + diff --git a/modules/fun/AMBuilder b/modules/fun/AMBuilder index 06d81f5c..758f2d21 100644 --- a/modules/fun/AMBuilder +++ b/modules/fun/AMBuilder @@ -2,7 +2,7 @@ import os.path binary = AMXX.MetaModule(builder, 'fun') - + binary.sources = [ '../../public/sdk/amxxmodule.cpp', '../../public/memtools/MemoryUtils.cpp', @@ -11,5 +11,9 @@ binary.sources = [ if builder.target_platform == 'windows': binary.sources += ['version.rc'] - + binary.compiler.linkflags += [ + '/EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1', + '/SECTION:.data,RW', + ] + AMXX.modules += [builder.Add(binary)] diff --git a/modules/fun/msvc12/fun.vcxproj b/modules/fun/msvc12/fun.vcxproj index bb70d392..fd1cea2c 100644 --- a/modules/fun/msvc12/fun.vcxproj +++ b/modules/fun/msvc12/fun.vcxproj @@ -93,6 +93,8 @@ .\Release/fun.lib MachineX86 Windows + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) + .data,RW @@ -138,6 +140,8 @@ Windows LIBCMT; false + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) + .data,RW @@ -158,4 +162,4 @@ - \ No newline at end of file + diff --git a/modules/geoip/AMBuilder b/modules/geoip/AMBuilder index 4d0bc7b7..78bb0580 100644 --- a/modules/geoip/AMBuilder +++ b/modules/geoip/AMBuilder @@ -21,8 +21,10 @@ binary.sources = [ if builder.target_platform == 'windows': binary.sources += ['version.rc'] - -if builder.target_platform == 'windows': - binary.compiler.postlink += ['ws2_32.lib'] + binary.compiler.linkflags += [ + '/EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1', + '/SECTION:.data,RW', + ] + binary.compiler.postlink += ['ws2_32.lib'] AMXX.modules += [builder.Add(binary)] diff --git a/modules/geoip/msvc12/geoip.vcxproj b/modules/geoip/msvc12/geoip.vcxproj index c9ac7869..464f19ba 100644 --- a/modules/geoip/msvc12/geoip.vcxproj +++ b/modules/geoip/msvc12/geoip.vcxproj @@ -74,6 +74,8 @@ $(OutDir)geoip.lib MachineX86 false + .data,RW + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) @@ -95,6 +97,8 @@ true $(OutDir)geoip.lib MachineX86 + .data,RW + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) @@ -120,4 +124,4 @@ - \ No newline at end of file + diff --git a/modules/hamsandwich/AMBuilder b/modules/hamsandwich/AMBuilder index 6181a91b..64a068a2 100644 --- a/modules/hamsandwich/AMBuilder +++ b/modules/hamsandwich/AMBuilder @@ -24,5 +24,9 @@ binary.sources = [ if builder.target_platform == 'windows': binary.sources += ['version.rc'] - + binary.compiler.linkflags += [ + '/EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1', + '/SECTION:.data,RW', + ] + AMXX.modules += [builder.Add(binary)] diff --git a/modules/hamsandwich/msvc12/hamsandwich.vcxproj b/modules/hamsandwich/msvc12/hamsandwich.vcxproj index 4d68336a..1df330f9 100644 --- a/modules/hamsandwich/msvc12/hamsandwich.vcxproj +++ b/modules/hamsandwich/msvc12/hamsandwich.vcxproj @@ -73,6 +73,8 @@ MachineX86 LIBCMT; false + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) + .data,RW @@ -97,6 +99,8 @@ true $(OutDir)hamsandwich.lib MachineX86 + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) + .data,RW @@ -138,4 +142,4 @@ - \ No newline at end of file + diff --git a/modules/mysqlx/AMBuilder b/modules/mysqlx/AMBuilder index 801c5b09..cf1e69e7 100644 --- a/modules/mysqlx/AMBuilder +++ b/modules/mysqlx/AMBuilder @@ -31,7 +31,9 @@ if AMXX.mysql_path: elif builder.target_platform is 'windows': binary.compiler.linkflags += [ os.path.join(AMXX.mysql_path, 'lib', 'mysqlclient.lib'), - 'ws2_32.lib' + 'ws2_32.lib', + '/EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1', + '/SECTION:.data,RW' ] if binary.compiler.vendor == 'msvc' and binary.compiler.version >= 1900: binary.compiler.linkflags += ['legacy_stdio_definitions.lib', 'legacy_stdio_wide_specifiers.lib'] diff --git a/modules/mysqlx/msvc12/mysqlx.vcxproj b/modules/mysqlx/msvc12/mysqlx.vcxproj index cb7d8952..ea8581b7 100644 --- a/modules/mysqlx/msvc12/mysqlx.vcxproj +++ b/modules/mysqlx/msvc12/mysqlx.vcxproj @@ -74,6 +74,8 @@ $(OutDir)mysql2.lib MachineX86 false + .data,RW + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) @@ -96,6 +98,8 @@ true $(OutDir)mysql2.lib MachineX86 + .data,RW + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) @@ -208,4 +212,4 @@ - \ No newline at end of file + diff --git a/modules/ns/AMBuilder b/modules/ns/AMBuilder index 81130d8c..c85f94d2 100644 --- a/modules/ns/AMBuilder +++ b/modules/ns/AMBuilder @@ -28,5 +28,9 @@ binary.sources = [ if builder.target_platform == 'windows': binary.sources += ['version.rc'] - + binary.compiler.linkflags += [ + '/EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1', + '/SECTION:.data,RW', + ] + AMXX.modules += [builder.Add(binary)] diff --git a/modules/ns/msvc12/ns.vcxproj b/modules/ns/msvc12/ns.vcxproj index b2f08e94..92eb2f3c 100644 --- a/modules/ns/msvc12/ns.vcxproj +++ b/modules/ns/msvc12/ns.vcxproj @@ -91,6 +91,8 @@ .\Release/ns_amxx.lib MachineX86 Windows + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) + .data,RW @@ -134,6 +136,8 @@ Windows LIBCMT; false + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) + .data,RW @@ -183,4 +187,4 @@ - \ No newline at end of file + diff --git a/modules/sqlite/AMBuilder b/modules/sqlite/AMBuilder index 71af9f55..581e307f 100644 --- a/modules/sqlite/AMBuilder +++ b/modules/sqlite/AMBuilder @@ -35,13 +35,15 @@ binary.sources += [ if builder.target_platform == 'windows': binary.sources += [ 'thread/WinThreads.cpp', + 'version.rc' + ] + binary.compiler.linkflags += [ + '/EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1', + '/SECTION:.data,RW', ] else: binary.sources += [ 'thread/PosixThreads.cpp', ] -if builder.target_platform == 'windows': - binary.sources += ['version.rc'] - AMXX.modules += [builder.Add(binary)] diff --git a/modules/sqlite/msvc12/sqlite.vcxproj b/modules/sqlite/msvc12/sqlite.vcxproj index 0184e732..86742fed 100644 --- a/modules/sqlite/msvc12/sqlite.vcxproj +++ b/modules/sqlite/msvc12/sqlite.vcxproj @@ -77,6 +77,8 @@ $(OutDir)sqlite.lib MachineX86 false + .data,RW + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) @@ -104,6 +106,8 @@ true $(OutDir)sqlite.lib MachineX86 + .data,RW + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) @@ -148,4 +152,4 @@ - \ No newline at end of file + diff --git a/modules/tfcx/AMBuilder b/modules/tfcx/AMBuilder index c49e522e..88f697c6 100644 --- a/modules/tfcx/AMBuilder +++ b/modules/tfcx/AMBuilder @@ -16,5 +16,9 @@ binary.sources = [ if builder.target_platform == 'windows': binary.sources += ['version.rc'] - + binary.compiler.linkflags += [ + '/EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1', + '/SECTION:.data,RW', + ] + AMXX.modules += [builder.Add(binary)] diff --git a/modules/tfcx/msvc12/tfcx.vcxproj b/modules/tfcx/msvc12/tfcx.vcxproj index 9d9a2044..efd0a97d 100644 --- a/modules/tfcx/msvc12/tfcx.vcxproj +++ b/modules/tfcx/msvc12/tfcx.vcxproj @@ -93,6 +93,8 @@ Windows LIBCMT; false + .data,RW + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) @@ -136,6 +138,8 @@ .\Release/tfcx_amxx.lib MachineX86 Windows + .data,RW + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) @@ -163,4 +167,4 @@ - \ No newline at end of file + diff --git a/modules/ts/tsx/AMBuilder b/modules/ts/tsx/AMBuilder index c3df01fe..bea49fd6 100644 --- a/modules/ts/tsx/AMBuilder +++ b/modules/ts/tsx/AMBuilder @@ -16,5 +16,9 @@ binary.sources = [ if builder.target_platform == 'windows': binary.sources += ['version.rc'] - + binary.compiler.linkflags += [ + '/EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1', + '/SECTION:.data,RW', + ] + AMXX.modules += [builder.Add(binary)] diff --git a/modules/ts/tsx/msvc12/tsx.vcxproj b/modules/ts/tsx/msvc12/tsx.vcxproj index edc864a4..c8b47ce6 100644 --- a/modules/ts/tsx/msvc12/tsx.vcxproj +++ b/modules/ts/tsx/msvc12/tsx.vcxproj @@ -93,6 +93,8 @@ Windows LIBCMT; false + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) + .data,RW @@ -136,6 +138,8 @@ .\Release/tsx_amxx.lib MachineX86 Windows + /EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1 %(AdditionalOptions) + .data,RW @@ -159,4 +163,4 @@ - \ No newline at end of file + diff --git a/public/sdk/amxxmodule.cpp b/public/sdk/amxxmodule.cpp index e79c7cff..c01a0268 100644 --- a/public/sdk/amxxmodule.cpp +++ b/public/sdk/amxxmodule.cpp @@ -2312,86 +2312,10 @@ C_DLLEXPORT int Meta_Detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason) return TRUE; } - - -#if defined(__linux__) || defined(__APPLE__) -// linux prototype -C_DLLEXPORT void GiveFnptrsToDll( enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals ) { - -#else -#ifdef _MSC_VER -// MSVC: Simulate __stdcall calling convention -C_DLLEXPORT __declspec(naked) void GiveFnptrsToDll( enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals ) +C_DLLEXPORT void WINAPI GiveFnptrsToDll(enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals) { - __asm // Prolog - { - // Save ebp - push ebp - // Set stack frame pointer - mov ebp, esp - // Allocate space for local variables - // The MSVC compiler gives us the needed size in __LOCAL_SIZE. - sub esp, __LOCAL_SIZE - // Push registers - push ebx - push esi - push edi - } -#else // _MSC_VER -#ifdef __GNUC__ -// GCC can also work with this -C_DLLEXPORT void __stdcall GiveFnptrsToDll( enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals ) -{ -#else // __GNUC__ -// compiler not known -#error There is no support (yet) for your compiler. Please use MSVC or GCC compilers or contact the AMX Mod X dev team. -#endif // __GNUC__ -#endif // _MSC_VER -#endif // __linux__ - - // ** Function core <-- memcpy(&g_engfuncs, pengfuncsFromEngine, sizeof(enginefuncs_t)); gpGlobals = pGlobals; - // NOTE! Have to call logging function _after_ copying into g_engfuncs, so - // that g_engfuncs.pfnAlertMessage() can be resolved properly, heh. :) - // UTIL_LogPrintf("[%s] dev: called: GiveFnptrsToDll\n", Plugin_info.logtag); - // --> ** Function core - -#ifdef _MSC_VER - // Epilog - if (sizeof(int*) == 8) - { // 64 bit - __asm - { - // Pop registers - pop edi - pop esi - pop ebx - // Restore stack frame pointer - mov esp, ebp - // Restore ebp - pop ebp - // 2 * sizeof(int*) = 16 on 64 bit - ret 16 - } - } - else - { // 32 bit - __asm - { - // Pop registers - pop edi - pop esi - pop ebx - // Restore stack frame pointer - mov esp, ebp - // Restore ebp - pop ebp - // 2 * sizeof(int*) = 8 on 32 bit - ret 8 - } - } -#endif // #ifdef _MSC_VER } #endif // #ifdef USE_METAMOD