From 1082ef31c7055800eeee00ffe18a835cfb5650e5 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 12 Sep 2004 03:48:21 +0000 Subject: [PATCH] Modules no longer need to have the correct extension (requested by UgLyPuNk) --- amxmodx/CModule.cpp | 3 +- amxmodx/CModule.h | 2 +- amxmodx/CString.h | 2 +- amxmodx/Makefile.pl | 1 + amxmodx/amxmodx.cpp | 4 +- amxmodx/amxmodx.h | 2 +- amxmodx/modules.cpp | 147 ++++++++++++++++++++++++++++++++++---------- amxmodx/srvcmd.cpp | 2 +- 8 files changed, 124 insertions(+), 39 deletions(-) diff --git a/amxmodx/CModule.cpp b/amxmodx/CModule.cpp index b7f42d82..b7628d8b 100755 --- a/amxmodx/CModule.cpp +++ b/amxmodx/CModule.cpp @@ -126,8 +126,9 @@ pfnmodule_engine_g engModuleFunc = { // class CModule // ***************************************************** -CModule::CModule(const char* fname) : m_Filename(fname) +CModule::CModule(const char* fname) { + m_Filename.assign(fname); clear(false); } diff --git a/amxmodx/CModule.h b/amxmodx/CModule.h index 2bad7908..0c530be0 100755 --- a/amxmodx/CModule.h +++ b/amxmodx/CModule.h @@ -95,7 +95,7 @@ public: inline module_info_s* getInfo() const { return m_InfoOld; } // old inline const amxx_module_info_s* getInfoNew() const { return &m_InfoNew; } // new inline int getStatusValue() { return m_Status; } - inline bool operator==( void* fname ) { return !strcmp( m_Filename.c_str() , (char*)fname ); } + inline bool operator==( const char* fname ) { return !strcmp( m_Filename.c_str() , fname ); } inline bool isReloadable() { return m_Amxx ? ((m_Status == MODULE_LOADED) && (m_InfoNew.reload != 0)) : ( (m_Status==MODULE_LOADED) && (m_InfoOld->type==RELOAD_MODULE)); } inline bool isAmxx() const { return m_Amxx; } inline const char *getMissingFunc() const { return m_MissingFunc; } diff --git a/amxmodx/CString.h b/amxmodx/CString.h index 0224646a..f578491e 100755 --- a/amxmodx/CString.h +++ b/amxmodx/CString.h @@ -71,7 +71,7 @@ public: void append(const char *t) { - Grow(cSize + strlen(t)); + Grow(cSize + strlen(t) + 1); strcat(v, t); cSize = strlen(v); } diff --git a/amxmodx/Makefile.pl b/amxmodx/Makefile.pl index f2a9f227..6ca4b70c 100755 --- a/amxmodx/Makefile.pl +++ b/amxmodx/Makefile.pl @@ -219,6 +219,7 @@ for ($i=0; $i<=$#CPP_SOURCE_FILES; $i++) $ofile_time = (stat($ofile))[9]; if ($file_time > $ofile_time) { + `rm $ofile`; print "$gcc\n"; `$gcc`; } diff --git a/amxmodx/amxmodx.cpp b/amxmodx/amxmodx.cpp index 772d7525..c6545d99 100755 --- a/amxmodx/amxmodx.cpp +++ b/amxmodx/amxmodx.cpp @@ -2257,7 +2257,7 @@ static cell AMX_NATIVE_CALL is_module_loaded(AMX *amx, cell *params) int len; char *name = get_amxstring(amx, params[1], 0, len); int id = 0; - for (CList::iterator iter = g_modules.begin(); iter; ++iter) + for (CList::iterator iter = g_modules.begin(); iter; ++iter) { if (stricmp((*iter).getName(), name) == 0) return id; @@ -2290,7 +2290,7 @@ static cell AMX_NATIVE_CALL get_modulesnum(AMX *amx, cell *params) // native get_module(id, name[], nameLen, author[], authorLen, version[], versionLen, &status); static cell AMX_NATIVE_CALL get_module(AMX *amx, cell *params) { - CList::iterator moduleIter; + CList::iterator moduleIter; // find the module int i = params[1]; diff --git a/amxmodx/amxmodx.h b/amxmodx/amxmodx.h index 8fab409e..8832b0f9 100755 --- a/amxmodx/amxmodx.h +++ b/amxmodx/amxmodx.h @@ -140,7 +140,7 @@ extern CList g_cvars; extern CList g_forcemodels; extern CList g_forcesounds; extern CList g_forcegeneric; -extern CList g_modules; +extern CList g_modules; extern CList g_auth; extern EventsMngr g_events; extern Grenades g_grenades; diff --git a/amxmodx/modules.cpp b/amxmodx/modules.cpp index 5ff4253f..bba9f213 100755 --- a/amxmodx/modules.cpp +++ b/amxmodx/modules.cpp @@ -34,7 +34,7 @@ #include "CFile.h" #include "amxxfile.h" -CList g_modules; +CList g_modules; CList g_loadedscripts; CModule *g_CurrentlyCalledModule = NULL; // The module we are in at the moment; NULL otherwise @@ -44,7 +44,6 @@ ModuleCallReason g_ModuleCallReason; extern const char* no_function; // stupid work around - void report_error( int code, char* fmt, ... ) { va_list argptr; @@ -234,7 +233,7 @@ int CheckModules(AMX *amx, char error[64]) } //assume module is not found flag = 0; - for (CList::iterator pMod = g_modules.begin(); pMod; ++pMod) + for (CList::iterator pMod = g_modules.begin(); pMod; ++pMod) { if (strcmpi(CurModuleList.front().c_str(), "dbi") == 0) { @@ -273,7 +272,7 @@ int CheckModules(AMX *amx, char error[64]) int set_amxnatives(AMX* amx,char error[64]) { - for ( CList::iterator a = g_modules.begin(); a ; ++a ) + for ( CList::iterator a = g_modules.begin(); a ; ++a ) { for( CList::iterator cc = (*a).m_Natives.begin(); cc; ++cc ) @@ -411,7 +410,7 @@ char* build_pathname_addons(char *fmt, ... ) int add_amxnatives(module_info_s* info,AMX_NATIVE_INFO*natives) { - CList::iterator a = g_modules.begin(); + CList::iterator a = g_modules.begin(); while ( a ) { @@ -443,9 +442,68 @@ bool validFile(const char* file) #endif } +void ConvertModuleName(const char *pathString, String &path) +{ +#if SMALL_CELL_SIZE==64 + char *ptr = strstr(pathString, "i386"); + if (ptr) + { + //attempt to fix the binary name + *ptr = 0; + path.assign(pathString); + path.append("amd64.so"); + } else { + ptr = strstr(pathString, ".dll"); + if (ptr) + { + *ptr = 0; + path.assign(pathString); + path.append("_amd64.so"); + } else { + ptr = strstr(pathString, ".so"); + if (ptr) + { + path.assign(pathString); + } else { + //no extension at all + path.assign(pathString); + path.append("_amd64.so"); + } + } + } +#else + char *ptr = strstr(pathString, "amd64"); + if (ptr) + { + //attempt to fix the binary name + *ptr = 0; + path.assign(pathString); + path.append("i386.so"); + } else { + ptr = strstr(pathString, ".dll"); + if (ptr) + { + *ptr = 0; + path.assign(pathString); + path.append("_i386.so"); + } else { + //check to see if this file even has an extenti + ptr = strstr(pathString, ".so"); + if (ptr) + { + path.assign(pathString); + } else { + path.assign(pathString); + path.append("_i386.so"); + } + } + } +#endif +} + int loadModules(const char* filename) { - File fp( build_pathname("%s",filename), "r" ); + FILE *fp = fopen(build_pathname("%s",filename), "rt"); if ( !fp ) { @@ -453,23 +511,40 @@ int loadModules(const char* filename) return 0; } - char line[256], moduleName[256]; + char moduleName[256]; + char pathString[512]; + String line; int loaded = 0; - while ( fp.getline( line , 255 ) ) + String path; + + while (!feof(fp)) { + if (!line._fread(fp) || line.size() < 1) + continue; + line.trim(); *moduleName = 0; - sscanf(line,"%s",moduleName); - if (!isalnum(*moduleName) || !validFile(moduleName) ) + if (sscanf(line.c_str(),"%s",moduleName) == EOF) + continue; + if (moduleName[0] == ';') continue; - char* pathname = build_pathname("%s/%s", get_localinfo("amxx_modulesdir", "addons/amxmodx/modules"), line); - CList::iterator a = g_modules.find( pathname ); + char* pathname = build_pathname("%s/%s", get_localinfo("amxx_modulesdir", "addons/amxmodx/modules"), moduleName); + strcpy(pathString, pathname); + + path.assign(""); + + ConvertModuleName(pathString, path); + + if (!validFile(path.c_str())) + continue; + + CList::iterator a = g_modules.find( path.c_str() ); if ( a ) continue; // already loaded - CModule* cc = new CModule( pathname ); + CModule* cc = new CModule( path.c_str() ); if ( cc == 0 ) return loaded; @@ -477,42 +552,45 @@ int loadModules(const char* filename) switch( cc->getStatusValue() ) { case MODULE_BADLOAD: - report_error( 1 , "[AMXX] Module is not a valid library (file \"%s\")",pathname ); + report_error( 1 , "[AMXX] Module is not a valid library (file \"%s\")", path.c_str()); break; case MODULE_NOINFO: - report_error( 1 ,"[AMXX] Couldn't find info. about module (file \"%s\")",pathname ); + report_error( 1 ,"[AMXX] Couldn't find info. about module (file \"%s\")", path.c_str()); break; case MODULE_NOQUERY: - report_error( 1 , "[AMXX] Couldn't find \"AMX_Query\" or \"AMXX_Query\" (file \"%s\")", pathname ); + report_error( 1 , "[AMXX] Couldn't find \"AMX_Query\" or \"AMXX_Query\" (file \"%s\")", path.c_str()); break; case MODULE_NOATTACH: - report_error( 1 , "[AMXX] Couldn't find \"%s\" (file \"%s\")", cc->isAmxx() ? "AMXX_Attach" : "AMX_Attach", pathname ); + report_error( 1 , "[AMXX] Couldn't find \"%s\" (file \"%s\")", cc->isAmxx() ? "AMXX_Attach" : "AMX_Attach", path.c_str()); break; case MODULE_OLD: - report_error( 1 , "[AMXX] Module has a different interface version (file \"%s\")",pathname ); + report_error( 1 , "[AMXX] Module has a different interface version (file \"%s\")",path.c_str()); break; case MODULE_NEWER: - report_error(1, "[AMXX] Module has a newer interface version (file \"%s\"). Please download a new amxmodx.", pathname); + report_error(1, "[AMXX] Module has a newer interface version (file \"%s\"). Please download a new amxmodx.", path.c_str()); break; case MODULE_INTERROR: - report_error(1, "[AMXX] Internal error during module load (file \"%s\")", pathname); + report_error(1, "[AMXX] Internal error during module load (file \"%s\")", path.c_str()); break; case MODULE_NOT64BIT: - report_error(1, "[AMXX] Module \"%s\" is not 64 bit compatible.", pathname); + report_error(1, "[AMXX] Module \"%s\" is not 64 bit compatible.", path.c_str()); break; default: ++loaded; } g_modules.put( cc ); + } + fclose(fp); + return loaded; } void detachModules() { - CList::iterator a = g_modules.begin(); + CList::iterator a = g_modules.begin(); while ( a ) { @@ -523,7 +601,7 @@ void detachModules() void detachReloadModules() { - CList::iterator a = g_modules.begin(); + CList::iterator a = g_modules.begin(); while ( a ) { @@ -541,7 +619,7 @@ void detachReloadModules() void attachModules() { - CList::iterator a = g_modules.begin(); + CList::iterator a = g_modules.begin(); while ( a ) { @@ -593,6 +671,7 @@ void attachMetaModModules(PLUG_LOADTIME now, const char* filename) } char line[256], moduleName[256]; + String modPath, mmPath; DLHANDLE module; while ( fp.getline( line , 255 ) ) @@ -600,12 +679,16 @@ void attachMetaModModules(PLUG_LOADTIME now, const char* filename) *moduleName = 0; sscanf(line,"%s",moduleName); - if (!isalnum(*moduleName) || !validFile(moduleName) ) + if (!isalnum(*moduleName)) continue; - char* pathname = build_pathname("%s/%s", get_localinfo("amxx_modulesdir", "addons/amxx/modules"), line); - char* mmpathname = build_pathname_addons("%s/%s", get_localinfo("amxx_modulesdir", "addons/amxx/modules"), line); - module = DLLOAD( pathname ); // link dll + char* pathname = build_pathname("%s/%s", get_localinfo("amxx_modulesdir", "addons/amxmodx/modules"), line); + char* mmpathname = build_pathname_addons("%s/%s", get_localinfo("amxx_modulesdir", "addons/amxmodx/modules"), line); + + ConvertModuleName(pathname, modPath); + ConvertModuleName(mmpathname, mmPath); + + module = DLLOAD( modPath.c_str() ); // link dll if ( module ) { @@ -614,7 +697,7 @@ void attachMetaModModules(PLUG_LOADTIME now, const char* filename) if ( a ) { - g_FakeMeta.AddPlugin(mmpathname); + g_FakeMeta.AddPlugin(mmPath.c_str()); } } } @@ -627,7 +710,7 @@ void attachMetaModModules(PLUG_LOADTIME now, const char* filename) // Get the number of running modules int countModules(CountModulesMode mode) { - CList::iterator iter; + CList::iterator iter; int num; switch (mode) { @@ -660,7 +743,7 @@ int countModules(CountModulesMode mode) // Call all modules' AMXX_PluginsLoaded functions void modules_callPluginsLoaded() { - CList::iterator iter = g_modules.begin(); + CList::iterator iter = g_modules.begin(); while (iter) { (*iter).CallPluginsLoaded(); @@ -672,7 +755,7 @@ void modules_callPluginsLoaded() int MNF_AddNatives(AMX_NATIVE_INFO* natives) { - CList::iterator a = g_modules.begin(); + CList::iterator a = g_modules.begin(); if (!g_CurrentlyCalledModule || g_ModuleCallReason != ModuleCall_Attach) return FALSE; // may only be called from attach diff --git a/amxmodx/srvcmd.cpp b/amxmodx/srvcmd.cpp index 28d9cdef..684bab8f 100755 --- a/amxmodx/srvcmd.cpp +++ b/amxmodx/srvcmd.cpp @@ -169,7 +169,7 @@ void amx_command(){ int running = 0; int modules = 0; - CList::iterator a = g_modules.begin(); + CList::iterator a = g_modules.begin(); while ( a ) {