diff --git a/amxmodx/CPlugin.cpp b/amxmodx/CPlugin.cpp index 61557bc7..4dea3c6f 100755 --- a/amxmodx/CPlugin.cpp +++ b/amxmodx/CPlugin.cpp @@ -14,6 +14,7 @@ #include "natives.h" #include "debugger.h" #include "libraries.h" +#include extern const char *no_function; @@ -443,6 +444,45 @@ void CPluginMngr::CPlugin::unpausePlugin() } } +void CPluginMngr::CPlugin::AddConfig(bool create, const char *name, const char *folder) +{ + // Do a check for duplicates to prevent double-execution + for (size_t i = 0; i < m_configs.length(); ++i) + { + auto config = m_configs[i]; + + if (config->autocfg.compare(name) == 0 && config->folder.compare(folder) == 0 && config->create == create) + { + return; + } + } + + AutoConfig *c = new AutoConfig; + + c->autocfg = name; + c->folder = folder; + c->create = create; + + m_configs.append(c); +} + +size_t CPluginMngr::CPlugin::GetConfigCount() +{ + return m_configs.length(); +} + +AutoConfig *CPluginMngr::CPlugin::GetConfig(size_t i) +{ + if (i >= GetConfigCount()) + { + return nullptr; + } + + return m_configs[i]; +} + + + char *CPluginMngr::ReadIntoOrFromCache(const char *file, size_t &bufsize) { List::iterator iter; @@ -714,3 +754,5 @@ void CPluginMngr::CALMFromFile(const char *file) fclose(fp); } + + diff --git a/amxmodx/CPlugin.h b/amxmodx/CPlugin.h index 417a2986..8fe8e75a 100755 --- a/amxmodx/CPlugin.h +++ b/amxmodx/CPlugin.h @@ -14,6 +14,7 @@ #include "amx.h" #include "amxxfile.h" #include +#include // ***************************************************** // class CPluginMngr @@ -29,6 +30,13 @@ enum ps_running, //Plugin is running }; +struct AutoConfig +{ + ke::AString autocfg; + ke::AString folder; + bool create; +}; + class CPluginMngr { public: @@ -63,6 +71,7 @@ public: bool m_Debug; cell* m_pNullStringOfs; cell* m_pNullVectorOfs; + ke::Vector m_configs; public: inline const char* getName() { return name.chars();} inline const char* getVersion() { return version.chars();} @@ -94,6 +103,10 @@ public: inline bool isDebug() const { return m_Debug; } inline cell* getNullStringOfs() const { return m_pNullStringOfs; } inline cell* getNullVectorOfs() const { return m_pNullVectorOfs; } + public: + void AddConfig(bool create, const char *name, const char *folder); + size_t GetConfigCount(); + AutoConfig *GetConfig(size_t index); }; private: diff --git a/amxmodx/amxmodx.cpp b/amxmodx/amxmodx.cpp index 66d85a9e..28961137 100755 --- a/amxmodx/amxmodx.cpp +++ b/amxmodx/amxmodx.cpp @@ -4484,6 +4484,38 @@ static cell AMX_NATIVE_CALL has_map_ent_class(AMX *amx, cell *params) return len && !FNullEnt(FIND_ENTITY_BY_STRING(NULL, "classname", name)); }; +static cell AMX_NATIVE_CALL AutoExecConfig(AMX *amx, cell *params) +{ + int length; + bool autocreate = params[1] != 0; + const char *name = get_amxstring(amx, params[2], 0, length); + const char *folder = get_amxstring(amx, params[3], 1, length); + + auto plugin = g_plugins.findPluginFast(amx); + + if (*name == '\0') + { + char pluginName[PLATFORM_MAX_PATH]; + strncopy(pluginName, plugin->getName(), sizeof(pluginName)); + + char *ptr; + + if ((ptr = strstr(pluginName, ".amxx"))) + { + *ptr = '\0'; + } + + static char newName[PLATFORM_MAX_PATH]; + UTIL_Format(newName, sizeof(newName), "plugin.%s", pluginName); + + name = newName; + } + + plugin->AddConfig(autocreate, name, folder); + + return 1; +} + static cell AMX_NATIVE_CALL is_rukia_a_hag(AMX *amx, cell *params) { return 1; @@ -4677,6 +4709,7 @@ AMX_NATIVE_INFO amxmodx_Natives[] = {"SetGlobalTransTarget", SetGlobalTransTarget}, {"PrepareArray", PrepareArray}, {"ShowSyncHudMsg", ShowSyncHudMsg}, + {"AutoExecConfig", AutoExecConfig}, {"is_rukia_a_hag", is_rukia_a_hag}, {NULL, NULL} };