added more api to help with amxmod compat layer

cleaned up some more bcompat stuff
This commit is contained in:
David Anderson 2006-09-12 07:59:56 +00:00
parent 4f8917ec44
commit 651c5d9f01
7 changed files with 318 additions and 16 deletions

View File

@ -58,6 +58,7 @@ public:
inline const char* getPluginName() { return plugin.c_str(); }
inline const char* getName() { return name.c_str(); }
inline bool operator == (const char* string) { return (strcmp(name.c_str(), string) == 0); }
int plugin_id;
};
// *****************************************************

View File

@ -1112,6 +1112,16 @@ static cell AMX_NATIVE_CALL get_plugin(AMX *amx, cell *params) /* 11 param */
return a->getId();
}
if (params[0] / sizeof(cell) >= 12)
{
cell *jit_info = get_amxaddr(amx, params[12]);
#if defined AMD64 || !defined JIT
*jit_info = 0;
#else
*jit_info = a->isDebug() ? 0 : 1;
#endif
}
return -1;
}
@ -1288,6 +1298,28 @@ static cell AMX_NATIVE_CALL get_concmd(AMX *amx, cell *params) /* 7 param */
return 1;
}
static cell AMX_NATIVE_CALL get_concmd_plid(AMX *amx, cell *params)
{
int who = params[3];
if (who > 0)
{
who = CMD_ClientCommand;
} else if (who == 0) {
who = CMD_ServerCommand;
} else {
who = CMD_ConsoleCommand;
}
CmdMngr::Command *cmd = g_commands.getCmd(params[1], who, params[2]);
if (cmd == NULL)
{
return -1;
}
return cmd->getPlugin()->getId();
}
static cell AMX_NATIVE_CALL get_clcmd(AMX *amx, cell *params) /* 7 param */
{
CmdMngr::Command* cmd = g_commands.getCmd(params[1], CMD_ClientCommand, params[7]);
@ -2189,8 +2221,7 @@ static cell AMX_NATIVE_CALL register_cvar(AMX *amx, cell *params) /* 3 param */
CPluginMngr::CPlugin *plugin = g_plugins.findPluginFast(amx);
CCVar* cvar = new CCVar(temp, plugin->getName(), params[3], amx_ctof(params[4]));
if (cvar == 0)
return 0;
cvar->plugin_id = plugin->getId();
g_cvars.put(cvar);
@ -2582,6 +2613,43 @@ static cell AMX_NATIVE_CALL remove_quotes(AMX *amx, cell *params) /* 1 param */
return 0;
}
//native get_plugins_cvar(id, name[], namelen, &flags=0, &plugin_id=0, &pcvar_handle=0);
static cell AMX_NATIVE_CALL get_plugins_cvar(AMX *amx, cell *params)
{
int id = params[1];
int iter_id = 0;
for (CList<CCVar>::iterator iter=g_cvars.begin(); iter; ++iter)
{
if (id == iter_id)
{
CCVar *var = &(*iter);
set_amxstring(amx, params[2], var->getName(), params[3]);
cvar_t *ptr = CVAR_GET_POINTER(var->getName());
if (!ptr)
{
return 0;
}
cell *addr = get_amxaddr(amx, params[4]);
*addr = ptr->flags;
addr = get_amxaddr(amx, params[5]);
*addr = var->plugin_id;
addr = get_amxaddr(amx, params[6]);
*addr = (cell)ptr;
return 1;
}
iter_id++;
}
return 0;
}
//native get_plugins_cvarsnum();
static cell AMX_NATIVE_CALL get_plugins_cvarsnum(AMX *amx, cell *params)
{
return g_cvars.size();
}
static cell AMX_NATIVE_CALL get_user_aiming(AMX *amx, cell *params) /* 4 param */
{
int index = params[1];
@ -4147,6 +4215,14 @@ static cell AMX_NATIVE_CALL AddTranslation(AMX *amx, cell *params)
return 1;
}
static cell AMX_NATIVE_CALL GetLangTransKey(AMX *amx, cell *params)
{
int len;
const char *key = get_amxstring(amx, params[1], 0, len);
return g_langMngr.GetKeyEntry(key);
}
AMX_NATIVE_INFO amxmodx_Natives[] =
{
{"abort", amx_abort},
@ -4181,6 +4257,7 @@ AMX_NATIVE_INFO amxmodx_Natives[] =
{"get_clcmdsnum", get_clcmdsnum},
{"get_concmd", get_concmd},
{"get_concmdsnum", get_concmdsnum},
{"get_concmd_plid", get_concmd_plid},
{"get_cvar_flags", get_cvar_flags},
{"get_cvar_float", get_cvar_float},
{"get_cvar_num", get_cvar_num},
@ -4205,6 +4282,8 @@ AMX_NATIVE_INFO amxmodx_Natives[] =
{"get_playersnum", get_playersnum},
{"get_plugin", get_plugin},
{"get_pluginsnum", get_pluginsnum},
{"get_plugins_cvar", get_plugins_cvar},
{"get_plugins_cvarsnum", get_plugins_cvarsnum},
{"get_srvcmd", get_srvcmd},
{"get_srvcmdsnum", get_srvcmdsnum},
{"get_systime", get_systime},
@ -4334,6 +4413,7 @@ AMX_NATIVE_INFO amxmodx_Natives[] =
{"CreateOneForward", CreateOneForward},
{"DestroyForward", DestroyForward},
{"ExecuteForward", ExecuteForward},
{"GetLangTransKey", GetLangTransKey},
{"LibraryExists", LibraryExists},
{"PrepareArray", PrepareArray},
{"ShowSyncHudMsg", ShowSyncHudMsg},

View File

@ -24,7 +24,7 @@ new g_MaxPlayers
public plugin_init()
{
register_plugin("AMX Mod Compat Engine", AMXX_VERSION_STR, "AMXX Dev Team")
register_plugin("AMX Mod Compat Engine", "1.76.rc4", "AMXX Dev Team")
g_MaxPlayers = get_maxplayers()

View File

@ -27,6 +27,11 @@ Core_Natives()
register_native("fpower", "__fpower")
register_native("flog", "__flog")
register_native("get_cmdaccess", "__get_cmdaccess")
register_native("is_translated", "__is_translated")
register_native("get_plugincmdsnum", "__get_plugincmdsnum")
register_native("get_plugincmd", "__get_plugincmd")
register_native("get_plugincvarsnum", "__get_plugincvarsnum")
register_native("get_plugincvar", "__get_plugincvar")
}
public __VelocityByAim(plid, num)
@ -185,7 +190,7 @@ public Float:__flog(plid, num)
//get_cmdaccess(cmd[], accessflags[], len)
public __get_cmdaccess(plid, num)
{
new command[32], accessflags[32]
static command[32], accessflags[32]
new ret
get_string(1, command, 31)
@ -197,3 +202,80 @@ public __get_cmdaccess(plid, num)
return ret
}
public __is_translated(plid, num)
{
static string[512]
get_string(1, string, 511)
return is_translated(string)
}
public __get_plugincmdsnum(plid, num)
{
static plugin[64]
get_string(1, plugin, 63)
return get_plugincmdsnum(plugin, get_param(2))
}
public __get_plugincmd(plid, num)
{
static plugin[64]
static command[32]
static accessflags[32]
static info[512]
get_string(1, plugin, 63)
if (get_plugincmd(plugin,
get_param(2),
command,
31,
accessflags,
31,
info,
511,
get_param(9),
get_param(10)))
{
set_string(3, command, get_param(4))
set_string(5, accessflags, get_param(6))
set_string(7, info, get_param(8))
return 1
}
return 0
}
public __get_plugincvarsnum(plid, num)
{
static plugin[64]
get_string(1, plugin, 63)
return get_plugincvarsnum(plugin, get_param(2))
}
//stock get_plugincvar(plugin[], index, cvar[], len1, value[], len2, flags=0)
public __get_plugincvar(plid, num)
{
static plugin[64]
static cvar[32]
static value[512]
get_string(1, plugin, 63)
if (get_plugincvar(plugin, get_param(2), cvar, 31, value, 511, get_param(7)))
{
set_string(3, cvar, get_param(4))
set_string(5, value, get_param(6))
return 1
}
return 0
}

View File

@ -54,7 +54,7 @@ stock strtonum(const string[])
stock build_path(path[], len, {Float,_}:... )
{
format_args(path, len, 2)
format_args(path, len, 2);
new pathlen = strlen(path);
new basedir[32];
if (containi(path, "$basedir") != -1)
@ -66,22 +66,22 @@ stock build_path(path[], len, {Float,_}:... )
}
if ((pathlen+strlen(basedir)-strlen("$basedir")) < len)
{
replace(path, len, "$basedir", basedir)
replace(path, len, "$basedir", basedir);
}
}
new dir[64], subdir[63];
if (containi(path, "$configdir") != -1)
{
get_localinfo("amxx_configsdir", dir, 63)
get_localinfo("amxx_configsdir", dir, 63);
if (!dir[0])
{
format(dir, 63, "%s/configs", basedir)
format(dir, 63, "%s/configs", basedir);
}
if ((pathlen+strlen(basedir)-strlen("$configdir")) < len)
{
replace(path, len, "$configdir", dir)
replace(path, len, "$configdir", dir);
}
dir[0] = '^0'
dir[0] = '^0';
}
if (containi(path, "$langdir") != -1)
{
@ -95,7 +95,7 @@ stock build_path(path[], len, {Float,_}:... )
{
replace(path, len, "$langdir", dir);
}
dir[0] = '^0''
dir[0] = '^0';
}
if (containi(path, "$modulesdir") != -1)
{
@ -128,14 +128,14 @@ stock build_path(path[], len, {Float,_}:... )
get_localinfo("amx_logs", dir, 63);
if (!dir[0])
{
format(dir, 63, "%s/logs", basedir)
format(dir, 63, "%s/logs", basedir);
}
if ((pathlen+strlen(basedir)-strlen("$logdir")) < len)
{
replace(path, len, "$logdir", dir);
}
}
return 1
return 1;
}
stock is_user_authorized(id)
@ -161,7 +161,7 @@ stock angle_to_vector(Float:vector[3], FRU, Float:ret[3])
return angle_vector(vector, FRU, ret);
}
get_cmdaccess(cmd[], accessflags[], len)
stock get_cmdaccess(cmd[], accessflags[], len)
{
new num = get_concmdsnum(-1);
new command[32], info[3];
@ -179,3 +179,120 @@ get_cmdaccess(cmd[], accessflags[], len)
return 0;
}
stock is_translated(const sentence[])
{
return (GetLangTransKey(sentence) != TransKey_Bad);
}
stock get_plugincmdsnum(plugin[], type=7)
{
new plid = find_plugin_byfile(plugin);
new our_type;
/**
* Whoever wrote this was a bit confused about the type stuff...
*/
if (type == 1) {
our_type = 1;
} else if (type == 4) {
our_type = 0;
} else {
our_type = -1;
}
new found = 0;
new total = get_concmdsnum(-1, our_type);
for (new i=0; i<total; i++)
{
if (plid == get_concmd_plid(i, -1, our_type))
{
found++;
}
}
return found;
}
stock get_plugincmd(plugin[], index, cmd[], len1, accessflags[], len2, info[], len3, destid=-1, type=7)
{
new plid = find_plugin_byfile(plugin);
new our_type;
/**
* Whoever wrote this was a bit confused about the type stuff...
*/
if (type == 1) {
our_type = 1;
} else if (type == 4) {
our_type = 0;
} else {
our_type = -1;
}
new found_iter = 0;
new total = get_concmdsnum(-1, our_type);
for (new i=0; i<total; i++)
{
if (plid == get_concmd_plid(i, -1, our_type))
{
if (found_iter == index)
{
new flags, result;
result = get_concmd(i, cmd, len1, flags, info, len3, -1, our_type);
get_flags(flags, accessflags, len2);
return result;
}
found_iter++;
}
}
/* get rid of a compiler warning */
destid = -1;
return (++destid);
}
stock get_plugincvar(plugin[], index, cvar[], len1, value[], len2, flags=0)
{
new plid = find_plugin_byfile(plugin);
new total = get_plugins_cvarsnum();
new cvar_flags, plugin_id, pcvar_handle;
new iter_id = 0;
for (new i=0; i<total; i++)
{
get_plugins_cvar(i, cvar, len1, cvar_flags, plugin_id, pcvar_handle);
if ((plugin_id == plid)
&& (!flags || (cvar_flags & flags)))
{
if (iter_id == index)
{
get_pcvar_string(pcvar_handle, value, len2);
return 1;
}
iter_id++;
}
}
return 0;
}
stock get_plugincvarsnum(plugin[], flags=0)
{
new plid = find_plugin_byfile(plugin);
new total = get_plugins_cvarsnum();
new cvar_flags, plugin_id;
new cvars_total = 0;
for (new i=0; i<total; i++)
{
get_plugins_cvar(i, "", 0, cvar_flags, plugin_id);
if ((plugin_id == plid)
&& (!flags || (cvar_flags & flags)))
{
cvars_total++;
}
}
return cvars_total;
}

View File

@ -497,9 +497,18 @@ then function returns only server cmds, if positive then
returns only client cmds. in other case returns all console commands. */
native get_concmd(index,cmd[],len1,&flags, info[],len2, flag, id = -1);
/* Gets the parent plugin id of a console command. */
native get_concmd_plid(cid, flag_mask, id_type);
/* Returns number of registered console commands. */
native get_concmdsnum(flag,id = -1);
/* Returns the number of plugin-registered cvars. */
native get_plugins_cvarsnum();
/* Returns information about a plugin-registered cvar. */
native get_plugins_cvar(num, name[], namelen, &flags=0, &plugin_id=0, &pcvar_handle=0);
/* Gets unique id of menu. Outside set to 1 allows
* to catch menus outside a plugin where register_menuid is called. */
native register_menuid(const menu[], outside=0 );
@ -588,8 +597,10 @@ native get_modulesnum();
native is_plugin_loaded(const name[]);
/* Gets info about plugin by given index.
* Function returns -1 if plugin doesn't exist with given index. */
native get_plugin(index,filename[],len1,name[],len2,version[],len3,author[],len4,status[],len5);
* Function returns -1 if plugin doesn't exist with given index.
* Note: the [...] portion should not be used, and is only for backward compatibility.
*/
native get_plugin(index,filename[],len1,name[],len2,version[],len3,author[],len4,status[],len5,...);
/* Returns number of all loaded plugins. */
native get_pluginsnum();

View File

@ -25,11 +25,22 @@ native register_dictionary(const filename[]);
//returns 1 if the language is loaded, 0 otherwise.
native lang_exists(const name[]);
enum TransKey
{
TransKey_Bad = -1,
};
/**
* Adds or finds a translation key.
*/
native TransKey:CreateLangKey(const key[]);
/**
* Finds a translation key id without adding on failure.
* Returns -1 on not found.
*/
native TransKey:GetLangTransKey(const key[]);
/**
* Adds a translation.
*/