Added request am43012: per-map plugin files
This commit is contained in:
parent
5524d5dca1
commit
f7691a51c6
@ -81,14 +81,17 @@ void CPluginMngr::Finalize()
|
|||||||
m_Finalized = true;
|
m_Finalized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CPluginMngr::loadPluginsFromFile(const char* filename)
|
int CPluginMngr::loadPluginsFromFile(const char* filename, bool warn)
|
||||||
{
|
{
|
||||||
char file[256];
|
char file[256];
|
||||||
FILE *fp = fopen(build_pathname_r(file, sizeof(file) - 1, "%s", filename), "rt");
|
FILE *fp = fopen(build_pathname_r(file, sizeof(file) - 1, "%s", filename), "rt");
|
||||||
|
|
||||||
if (!fp)
|
if (!fp)
|
||||||
{
|
{
|
||||||
AMXXLOG_Log("[AMXX] Plugins list not found (file \"%s\")", filename);
|
if (warn)
|
||||||
|
{
|
||||||
|
AMXXLOG_Log("[AMXX] Plugins list not found (file \"%s\")", filename);
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ public:
|
|||||||
|
|
||||||
CPlugin* loadPlugin(const char* path, const char* name, char* error, int debug);
|
CPlugin* loadPlugin(const char* path, const char* name, char* error, int debug);
|
||||||
void unloadPlugin(CPlugin** a);
|
void unloadPlugin(CPlugin** a);
|
||||||
int loadPluginsFromFile(const char* filename);
|
int loadPluginsFromFile(const char* filename, bool warn=true);
|
||||||
|
|
||||||
inline CPlugin* findPluginFast(AMX *amx) { return (CPlugin*)(amx->userdata[UD_FINDPLUGIN]); }
|
inline CPlugin* findPluginFast(AMX *amx) { return (CPlugin*)(amx->userdata[UD_FINDPLUGIN]); }
|
||||||
CPlugin* findPlugin(AMX *amx);
|
CPlugin* findPlugin(AMX *amx);
|
||||||
|
@ -170,16 +170,18 @@ void ParseAndOrAdd(CStack<String *> & files, const char *name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuildPluginFileList(CStack<String *> & files)
|
void BuildPluginFileList(const char *initialdir, CStack<String *> & files)
|
||||||
{
|
{
|
||||||
char path[255];
|
char path[255];
|
||||||
#if defined WIN32
|
#if defined WIN32
|
||||||
build_pathname_r(path, sizeof(path)-1, "%s/*.ini", get_localinfo("amxx_configsdir", "addons/amxmodx/configs"));
|
build_pathname_r(path, sizeof(path)-1, "%s/*.ini", initialdir);
|
||||||
_finddata_t fd;
|
_finddata_t fd;
|
||||||
intptr_t handle = _findfirst(path, &fd);
|
intptr_t handle = _findfirst(path, &fd);
|
||||||
|
|
||||||
if (handle < 0)
|
if (handle < 0)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
while (!_findnext(handle, &fd))
|
while (!_findnext(handle, &fd))
|
||||||
{
|
{
|
||||||
@ -188,12 +190,14 @@ void BuildPluginFileList(CStack<String *> & files)
|
|||||||
|
|
||||||
_findclose(handle);
|
_findclose(handle);
|
||||||
#elif defined __linux__
|
#elif defined __linux__
|
||||||
build_pathname_r(path, sizeof(path)-1, "%s/", get_localinfo("amxx_configsdir", "addons/amxmodx/configs"));
|
build_pathname_r(path, sizeof(path)-1, "%s/", initialdir);
|
||||||
struct dirent *ep;
|
struct dirent *ep;
|
||||||
DIR *dp;
|
DIR *dp;
|
||||||
|
|
||||||
if ((dp = opendir(path)) == NULL)
|
if ((dp = opendir(path)) == NULL)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
while ( (ep=readdir(dp)) != NULL )
|
while ( (ep=readdir(dp)) != NULL )
|
||||||
{
|
{
|
||||||
@ -204,6 +208,41 @@ void BuildPluginFileList(CStack<String *> & files)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Loads a plugin list into the Plugin Cache and Load Modules cache
|
||||||
|
void LoadExtraPluginsToPCALM(const char *initialdir)
|
||||||
|
{
|
||||||
|
CStack<String *> files;
|
||||||
|
BuildPluginFileList(initialdir, files);
|
||||||
|
char path[255];
|
||||||
|
while (!files.empty())
|
||||||
|
{
|
||||||
|
String *pString = files.front();
|
||||||
|
snprintf(path, sizeof(path)-1, "%s/%s",
|
||||||
|
initialdir,
|
||||||
|
pString->c_str());
|
||||||
|
g_plugins.CALMFromFile(path);
|
||||||
|
delete pString;
|
||||||
|
files.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoadExtraPluginsFromDir(const char *initialdir)
|
||||||
|
{
|
||||||
|
CStack<String *> files;
|
||||||
|
char path[255];
|
||||||
|
BuildPluginFileList(initialdir, files);
|
||||||
|
while (!files.empty())
|
||||||
|
{
|
||||||
|
String *pString = files.front();
|
||||||
|
snprintf(path, sizeof(path)-1, "%s/%s",
|
||||||
|
initialdir,
|
||||||
|
pString->c_str());
|
||||||
|
g_plugins.loadPluginsFromFile(path);
|
||||||
|
delete pString;
|
||||||
|
files.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Precache stuff from force consistency calls
|
// Precache stuff from force consistency calls
|
||||||
// or check for pointed files won't be done
|
// or check for pointed files won't be done
|
||||||
int C_PrecacheModel(char *s)
|
int C_PrecacheModel(char *s)
|
||||||
@ -318,22 +357,18 @@ int C_Spawn(edict_t *pent)
|
|||||||
get_localinfo("amxx_configsdir", "addons/amxmodx/configs");
|
get_localinfo("amxx_configsdir", "addons/amxmodx/configs");
|
||||||
get_localinfo("amxx_customdir", "addons/amxmodx/custom");
|
get_localinfo("amxx_customdir", "addons/amxmodx/custom");
|
||||||
|
|
||||||
|
char map_pluginsfile_path[256];
|
||||||
|
|
||||||
// ###### Load modules
|
// ###### Load modules
|
||||||
loadModules(get_localinfo("amxx_modules", "addons/amxmodx/configs/modules.ini"), PT_ANYTIME);
|
loadModules(get_localinfo("amxx_modules", "addons/amxmodx/configs/modules.ini"), PT_ANYTIME);
|
||||||
g_plugins.CALMFromFile(get_localinfo("amxx_plugins", "addons/amxmodx/configs/plugins.ini"));
|
g_plugins.CALMFromFile(get_localinfo("amxx_plugins", "addons/amxmodx/configs/plugins.ini"));
|
||||||
CStack<String *> files;
|
LoadExtraPluginsToPCALM(get_localinfo("amxx_configsdir", "addons/amxmodx/configs"));
|
||||||
BuildPluginFileList(files);
|
snprintf(map_pluginsfile_path, sizeof(map_pluginsfile_path)-1,
|
||||||
char path[255];
|
"%s/maps/plugins-%s.ini",
|
||||||
while (!files.empty())
|
get_localinfo("amxx_configsdir", "addons/amxmodx/configs"),
|
||||||
{
|
STRING(gpGlobals->mapname));
|
||||||
String *pString = files.front();
|
g_plugins.CALMFromFile(map_pluginsfile_path);
|
||||||
snprintf(path, sizeof(path)-1, "%s/%s",
|
|
||||||
get_localinfo("amxx_configsdir", "addons/amxmodx/configs"),
|
|
||||||
pString->c_str());
|
|
||||||
g_plugins.CALMFromFile(path);
|
|
||||||
delete pString;
|
|
||||||
files.pop();
|
|
||||||
}
|
|
||||||
int loaded = countModules(CountModules_Running); // Call after attachModules so all modules don't have pending stat
|
int loaded = countModules(CountModules_Running); // Call after attachModules so all modules don't have pending stat
|
||||||
|
|
||||||
// Set some info about amx version and modules
|
// Set some info about amx version and modules
|
||||||
@ -371,17 +406,8 @@ int C_Spawn(edict_t *pent)
|
|||||||
|
|
||||||
// ###### Load AMX Mod X plugins
|
// ###### Load AMX Mod X plugins
|
||||||
g_plugins.loadPluginsFromFile(get_localinfo("amxx_plugins", "addons/amxmodx/configs/plugins.ini"));
|
g_plugins.loadPluginsFromFile(get_localinfo("amxx_plugins", "addons/amxmodx/configs/plugins.ini"));
|
||||||
BuildPluginFileList(files);
|
LoadExtraPluginsFromDir(get_localinfo("amxx_configsdir", "addons/amxmodx/configs"));
|
||||||
while (!files.empty())
|
g_plugins.loadPluginsFromFile(map_pluginsfile_path, false);
|
||||||
{
|
|
||||||
String *pString = files.front();
|
|
||||||
snprintf(path, sizeof(path)-1, "%s/%s",
|
|
||||||
get_localinfo("amxx_configsdir", "addons/amxmodx/configs"),
|
|
||||||
pString->c_str());
|
|
||||||
g_plugins.loadPluginsFromFile(path);
|
|
||||||
delete pString;
|
|
||||||
files.pop();
|
|
||||||
}
|
|
||||||
g_plugins.Finalize();
|
g_plugins.Finalize();
|
||||||
g_plugins.InvalidateCache();
|
g_plugins.InvalidateCache();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user