AutoExecConfig: Add AutoExecConfig native

This commit is contained in:
Arkshine 2015-07-19 21:12:24 +02:00
parent f22185d646
commit 9a1dc5d179
3 changed files with 88 additions and 0 deletions

View File

@ -14,6 +14,7 @@
#include "natives.h"
#include "debugger.h"
#include "libraries.h"
#include <amxmodx_version.h>
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<plcache_entry *>::iterator iter;
@ -714,3 +754,5 @@ void CPluginMngr::CALMFromFile(const char *file)
fclose(fp);
}

View File

@ -14,6 +14,7 @@
#include "amx.h"
#include "amxxfile.h"
#include <am-string.h>
#include <am-vector.h>
// *****************************************************
// 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<AutoConfig*> 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:

View File

@ -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}
};