Modules no longer need to have the correct extension (requested by UgLyPuNk)

This commit is contained in:
David Anderson 2004-09-12 03:48:21 +00:00
parent ee28532c53
commit 1082ef31c7
8 changed files with 124 additions and 39 deletions

View File

@ -126,8 +126,9 @@ pfnmodule_engine_g engModuleFunc = {
// class CModule // class CModule
// ***************************************************** // *****************************************************
CModule::CModule(const char* fname) : m_Filename(fname) CModule::CModule(const char* fname)
{ {
m_Filename.assign(fname);
clear(false); clear(false);
} }

View File

@ -95,7 +95,7 @@ public:
inline module_info_s* getInfo() const { return m_InfoOld; } // old inline module_info_s* getInfo() const { return m_InfoOld; } // old
inline const amxx_module_info_s* getInfoNew() const { return &m_InfoNew; } // new inline const amxx_module_info_s* getInfoNew() const { return &m_InfoNew; } // new
inline int getStatusValue() { return m_Status; } 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 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 bool isAmxx() const { return m_Amxx; }
inline const char *getMissingFunc() const { return m_MissingFunc; } inline const char *getMissingFunc() const { return m_MissingFunc; }

View File

@ -71,7 +71,7 @@ public:
void append(const char *t) void append(const char *t)
{ {
Grow(cSize + strlen(t)); Grow(cSize + strlen(t) + 1);
strcat(v, t); strcat(v, t);
cSize = strlen(v); cSize = strlen(v);
} }

View File

@ -219,6 +219,7 @@ for ($i=0; $i<=$#CPP_SOURCE_FILES; $i++)
$ofile_time = (stat($ofile))[9]; $ofile_time = (stat($ofile))[9];
if ($file_time > $ofile_time) if ($file_time > $ofile_time)
{ {
`rm $ofile`;
print "$gcc\n"; print "$gcc\n";
`$gcc`; `$gcc`;
} }

View File

@ -2257,7 +2257,7 @@ static cell AMX_NATIVE_CALL is_module_loaded(AMX *amx, cell *params)
int len; int len;
char *name = get_amxstring(amx, params[1], 0, len); char *name = get_amxstring(amx, params[1], 0, len);
int id = 0; int id = 0;
for (CList<CModule>::iterator iter = g_modules.begin(); iter; ++iter) for (CList<CModule,const char *>::iterator iter = g_modules.begin(); iter; ++iter)
{ {
if (stricmp((*iter).getName(), name) == 0) if (stricmp((*iter).getName(), name) == 0)
return id; 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); // native get_module(id, name[], nameLen, author[], authorLen, version[], versionLen, &status);
static cell AMX_NATIVE_CALL get_module(AMX *amx, cell *params) static cell AMX_NATIVE_CALL get_module(AMX *amx, cell *params)
{ {
CList<CModule>::iterator moduleIter; CList<CModule,const char *>::iterator moduleIter;
// find the module // find the module
int i = params[1]; int i = params[1];

View File

@ -140,7 +140,7 @@ extern CList<CCVar> g_cvars;
extern CList<ForceObject> g_forcemodels; extern CList<ForceObject> g_forcemodels;
extern CList<ForceObject> g_forcesounds; extern CList<ForceObject> g_forcesounds;
extern CList<ForceObject> g_forcegeneric; extern CList<ForceObject> g_forcegeneric;
extern CList<CModule> g_modules; extern CList<CModule,const char *> g_modules;
extern CList<CPlayer*> g_auth; extern CList<CPlayer*> g_auth;
extern EventsMngr g_events; extern EventsMngr g_events;
extern Grenades g_grenades; extern Grenades g_grenades;

View File

@ -34,7 +34,7 @@
#include "CFile.h" #include "CFile.h"
#include "amxxfile.h" #include "amxxfile.h"
CList<CModule> g_modules; CList<CModule,const char*> g_modules;
CList<CScript,AMX*> g_loadedscripts; CList<CScript,AMX*> g_loadedscripts;
CModule *g_CurrentlyCalledModule = NULL; // The module we are in at the moment; NULL otherwise 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 extern const char* no_function; // stupid work around
void report_error( int code, char* fmt, ... ) void report_error( int code, char* fmt, ... )
{ {
va_list argptr; va_list argptr;
@ -234,7 +233,7 @@ int CheckModules(AMX *amx, char error[64])
} }
//assume module is not found //assume module is not found
flag = 0; flag = 0;
for (CList<CModule>::iterator pMod = g_modules.begin(); pMod; ++pMod) for (CList<CModule,const char *>::iterator pMod = g_modules.begin(); pMod; ++pMod)
{ {
if (strcmpi(CurModuleList.front().c_str(), "dbi") == 0) 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]) int set_amxnatives(AMX* amx,char error[64])
{ {
for ( CList<CModule>::iterator a = g_modules.begin(); a ; ++a ) for ( CList<CModule,const char *>::iterator a = g_modules.begin(); a ; ++a )
{ {
for( CList<AMX_NATIVE_INFO*>::iterator cc = for( CList<AMX_NATIVE_INFO*>::iterator cc =
(*a).m_Natives.begin(); cc; ++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) int add_amxnatives(module_info_s* info,AMX_NATIVE_INFO*natives)
{ {
CList<CModule>::iterator a = g_modules.begin(); CList<CModule,const char *>::iterator a = g_modules.begin();
while ( a ) while ( a )
{ {
@ -443,9 +442,68 @@ bool validFile(const char* file)
#endif #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) int loadModules(const char* filename)
{ {
File fp( build_pathname("%s",filename), "r" ); FILE *fp = fopen(build_pathname("%s",filename), "rt");
if ( !fp ) if ( !fp )
{ {
@ -453,23 +511,40 @@ int loadModules(const char* filename)
return 0; return 0;
} }
char line[256], moduleName[256]; char moduleName[256];
char pathString[512];
String line;
int loaded = 0; 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; *moduleName = 0;
sscanf(line,"%s",moduleName); if (sscanf(line.c_str(),"%s",moduleName) == EOF)
if (!isalnum(*moduleName) || !validFile(moduleName) ) continue;
if (moduleName[0] == ';')
continue; continue;
char* pathname = build_pathname("%s/%s", get_localinfo("amxx_modulesdir", "addons/amxmodx/modules"), line);
CList<CModule>::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<CModule,const char *>::iterator a = g_modules.find( path.c_str() );
if ( a ) continue; // already loaded if ( a ) continue; // already loaded
CModule* cc = new CModule( pathname ); CModule* cc = new CModule( path.c_str() );
if ( cc == 0 ) return loaded; if ( cc == 0 ) return loaded;
@ -477,42 +552,45 @@ int loadModules(const char* filename)
switch( cc->getStatusValue() ) { switch( cc->getStatusValue() ) {
case MODULE_BADLOAD: 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; break;
case MODULE_NOINFO: 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; break;
case MODULE_NOQUERY: 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; break;
case MODULE_NOATTACH: 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; break;
case MODULE_OLD: 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; break;
case MODULE_NEWER: 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; break;
case MODULE_INTERROR: 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; break;
case MODULE_NOT64BIT: 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; break;
default: default:
++loaded; ++loaded;
} }
g_modules.put( cc ); g_modules.put( cc );
} }
fclose(fp);
return loaded; return loaded;
} }
void detachModules() void detachModules()
{ {
CList<CModule>::iterator a = g_modules.begin(); CList<CModule,const char *>::iterator a = g_modules.begin();
while ( a ) while ( a )
{ {
@ -523,7 +601,7 @@ void detachModules()
void detachReloadModules() void detachReloadModules()
{ {
CList<CModule>::iterator a = g_modules.begin(); CList<CModule,const char *>::iterator a = g_modules.begin();
while ( a ) while ( a )
{ {
@ -541,7 +619,7 @@ void detachReloadModules()
void attachModules() void attachModules()
{ {
CList<CModule>::iterator a = g_modules.begin(); CList<CModule,const char *>::iterator a = g_modules.begin();
while ( a ) while ( a )
{ {
@ -593,6 +671,7 @@ void attachMetaModModules(PLUG_LOADTIME now, const char* filename)
} }
char line[256], moduleName[256]; char line[256], moduleName[256];
String modPath, mmPath;
DLHANDLE module; DLHANDLE module;
while ( fp.getline( line , 255 ) ) while ( fp.getline( line , 255 ) )
@ -600,12 +679,16 @@ void attachMetaModModules(PLUG_LOADTIME now, const char* filename)
*moduleName = 0; *moduleName = 0;
sscanf(line,"%s",moduleName); sscanf(line,"%s",moduleName);
if (!isalnum(*moduleName) || !validFile(moduleName) ) if (!isalnum(*moduleName))
continue; continue;
char* pathname = build_pathname("%s/%s", get_localinfo("amxx_modulesdir", "addons/amxx/modules"), line); 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/amxx/modules"), line); char* mmpathname = build_pathname_addons("%s/%s", get_localinfo("amxx_modulesdir", "addons/amxmodx/modules"), line);
module = DLLOAD( pathname ); // link dll
ConvertModuleName(pathname, modPath);
ConvertModuleName(mmpathname, mmPath);
module = DLLOAD( modPath.c_str() ); // link dll
if ( module ) if ( module )
{ {
@ -614,7 +697,7 @@ void attachMetaModModules(PLUG_LOADTIME now, const char* filename)
if ( a ) 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 // Get the number of running modules
int countModules(CountModulesMode mode) int countModules(CountModulesMode mode)
{ {
CList<CModule>::iterator iter; CList<CModule,const char *>::iterator iter;
int num; int num;
switch (mode) switch (mode)
{ {
@ -660,7 +743,7 @@ int countModules(CountModulesMode mode)
// Call all modules' AMXX_PluginsLoaded functions // Call all modules' AMXX_PluginsLoaded functions
void modules_callPluginsLoaded() void modules_callPluginsLoaded()
{ {
CList<CModule>::iterator iter = g_modules.begin(); CList<CModule,const char *>::iterator iter = g_modules.begin();
while (iter) while (iter)
{ {
(*iter).CallPluginsLoaded(); (*iter).CallPluginsLoaded();
@ -672,7 +755,7 @@ void modules_callPluginsLoaded()
int MNF_AddNatives(AMX_NATIVE_INFO* natives) int MNF_AddNatives(AMX_NATIVE_INFO* natives)
{ {
CList<CModule>::iterator a = g_modules.begin(); CList<CModule,const char *>::iterator a = g_modules.begin();
if (!g_CurrentlyCalledModule || g_ModuleCallReason != ModuleCall_Attach) if (!g_CurrentlyCalledModule || g_ModuleCallReason != ModuleCall_Attach)
return FALSE; // may only be called from attach return FALSE; // may only be called from attach

View File

@ -169,7 +169,7 @@ void amx_command(){
int running = 0; int running = 0;
int modules = 0; int modules = 0;
CList<CModule>::iterator a = g_modules.begin(); CList<CModule,const char *>::iterator a = g_modules.begin();
while ( a ) while ( a )
{ {