mirror of
https://github.com/alliedmodders/amxmodx.git
synced 2025-01-23 20:28:03 +03:00
Modules no longer need to have the correct extension (requested by UgLyPuNk)
This commit is contained in:
parent
ee28532c53
commit
1082ef31c7
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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; }
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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`;
|
||||
}
|
||||
|
@ -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<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)
|
||||
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<CModule>::iterator moduleIter;
|
||||
CList<CModule,const char *>::iterator moduleIter;
|
||||
|
||||
// find the module
|
||||
int i = params[1];
|
||||
|
@ -140,7 +140,7 @@ extern CList<CCVar> g_cvars;
|
||||
extern CList<ForceObject> g_forcemodels;
|
||||
extern CList<ForceObject> g_forcesounds;
|
||||
extern CList<ForceObject> g_forcegeneric;
|
||||
extern CList<CModule> g_modules;
|
||||
extern CList<CModule,const char *> g_modules;
|
||||
extern CList<CPlayer*> g_auth;
|
||||
extern EventsMngr g_events;
|
||||
extern Grenades g_grenades;
|
||||
|
@ -34,7 +34,7 @@
|
||||
#include "CFile.h"
|
||||
#include "amxxfile.h"
|
||||
|
||||
CList<CModule> g_modules;
|
||||
CList<CModule,const char*> g_modules;
|
||||
CList<CScript,AMX*> 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<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)
|
||||
{
|
||||
@ -273,7 +272,7 @@ int CheckModules(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 =
|
||||
(*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<CModule>::iterator a = g_modules.begin();
|
||||
CList<CModule,const char *>::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<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
|
||||
|
||||
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<CModule>::iterator a = g_modules.begin();
|
||||
CList<CModule,const char *>::iterator a = g_modules.begin();
|
||||
|
||||
while ( a )
|
||||
{
|
||||
@ -523,7 +601,7 @@ void detachModules()
|
||||
|
||||
void detachReloadModules()
|
||||
{
|
||||
CList<CModule>::iterator a = g_modules.begin();
|
||||
CList<CModule,const char *>::iterator a = g_modules.begin();
|
||||
|
||||
while ( a )
|
||||
{
|
||||
@ -541,7 +619,7 @@ void detachReloadModules()
|
||||
|
||||
void attachModules()
|
||||
{
|
||||
CList<CModule>::iterator a = g_modules.begin();
|
||||
CList<CModule,const char *>::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<CModule>::iterator iter;
|
||||
CList<CModule,const char *>::iterator iter;
|
||||
int num;
|
||||
switch (mode)
|
||||
{
|
||||
@ -660,7 +743,7 @@ int countModules(CountModulesMode mode)
|
||||
// Call all modules' AMXX_PluginsLoaded functions
|
||||
void modules_callPluginsLoaded()
|
||||
{
|
||||
CList<CModule>::iterator iter = g_modules.begin();
|
||||
CList<CModule,const char *>::iterator iter = g_modules.begin();
|
||||
while (iter)
|
||||
{
|
||||
(*iter).CallPluginsLoaded();
|
||||
@ -672,7 +755,7 @@ void modules_callPluginsLoaded()
|
||||
|
||||
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)
|
||||
return FALSE; // may only be called from attach
|
||||
|
@ -169,7 +169,7 @@ void amx_command(){
|
||||
int running = 0;
|
||||
int modules = 0;
|
||||
|
||||
CList<CModule>::iterator a = g_modules.begin();
|
||||
CList<CModule,const char *>::iterator a = g_modules.begin();
|
||||
|
||||
while ( a )
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user