Cvars: De-frenchify by Nextra

This commit is contained in:
Arkshine
2015-01-29 21:44:53 +01:00
parent a5b5c7e9cd
commit 1488b9747f
4 changed files with 99 additions and 83 deletions

View File

@ -48,9 +48,9 @@ DETOUR_DECL_STATIC2(Cvar_DirectSet, void, struct cvar_s*, var, const char*, valu
return;
}
}
ke::AString oldValue; // We save old value since it will be likely changed after original function called.
if (!info->hooks.empty())
{
oldValue = var->string;
@ -58,7 +58,7 @@ DETOUR_DECL_STATIC2(Cvar_DirectSet, void, struct cvar_s*, var, const char*, valu
DETOUR_STATIC_CALL(Cvar_DirectSet)(var, value);
if (!info->binds.empty())
if (!info->binds.empty())
{
for (size_t i = 0; i < info->binds.length(); ++i)
{
@ -155,7 +155,7 @@ void CvarManager::CreateCvarHook(void)
}
CvarInfo* CvarManager::CreateCvar(const char* name, const char* value, const char* plugin, int pluginId, int flags,
const char* helpText, bool hasMin, float min, bool hasMax, float max)
const char* helpText, bool hasMin, float min, bool hasMax, float max)
{
cvar_t* var = nullptr;
CvarInfo* info = nullptr;
@ -294,8 +294,8 @@ AutoForward* CvarManager::HookCvarChange(cvar_t* var, AMX* amx, cell param, cons
CvarInfo* info = nullptr;
// A cvar is guaranteed to be in cache if pointer is got from
// get_cvar_pointer and register_cvar natives. Though it might be
// provided by another way. If by any chance we run in such
// get_cvar_pointer and register_cvar natives. Though it might be
// provided by another way. If by any chance we run in such
// situation, we create a new entry right now.
if (!CacheLookup(var->name, &info))
@ -322,7 +322,7 @@ AutoForward* CvarManager::HookCvarChange(cvar_t* var, AMX* amx, cell param, cons
// Detour is disabled on map change.
m_HookDetour->EnableDetour();
AutoForward* forward = new AutoForward(forwardId, *callback);
info->hooks.append(new CvarHook(g_plugins.findPlugin(amx)->getId(), forward));
@ -333,7 +333,7 @@ bool CvarManager::BindCvar(CvarInfo* info, CvarBind::CvarType type, AMX* amx, ce
{
if (varofs > amx->hlw) // If variable address is not inside global area, we can't bind it.
{
LogError(amx, AMX_ERR_NATIVE, "A global variable must be provided");
LogError(amx, AMX_ERR_NATIVE, "Cvars can only be bound to global variables");
return false;
}
@ -349,7 +349,7 @@ bool CvarManager::BindCvar(CvarInfo* info, CvarBind::CvarType type, AMX* amx, ce
{
if (bind->varAddress == address)
{
LogError(amx, AMX_ERR_NATIVE, "A same variable can't be binded with several cvars");
LogError(amx, AMX_ERR_NATIVE, "A global variable can not be bound to multiple Cvars");
return false;
}
}
@ -392,7 +392,7 @@ bool CvarManager::SetCvarMin(CvarInfo* info, bool set, float value, int pluginId
}
info->bound.minVal = value;
// Detour is disabled on map change.
m_HookDetour->EnableDetour();
@ -475,7 +475,7 @@ void CvarManager::OnConsoleCommand()
if (argcount > 2)
{
const char* argument = CMD_ARGV(2);
indexToSearch = atoi(argument); // amxx cvars 2
if (!indexToSearch)
@ -492,16 +492,15 @@ void CvarManager::OnConsoleCommand()
if (!indexToSearch)
{
print_srvconsole("\nManaged cvars:\n");
print_srvconsole(" %-24.23s %-24.23s %-18.17s %-8.7s %-8.7s %-8.7s\n", "NAME", "VALUE", "PLUGIN", "BINDED", "HOOKED", "BOUNDED");
print_srvconsole(" %-24.23s %-24.23s %-18.17s %-8.7s %-8.7s %-8.7s\n", "NAME", "VALUE", "PLUGIN", "BOUND", "HOOKED", "BOUNDED");
print_srvconsole(" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n");
}
for (CvarsList::iterator iter = m_Cvars.begin(); iter != m_Cvars.end(); iter++)
{
CvarInfo* ci = (*iter);
// List any cvars having a status either created, hooked, binded or bounded by a plugin.
// List any cvars having a status either created, hooked or bound by a plugin.
bool in_list = ci->amxmodx || !ci->binds.empty() || !ci->hooks.empty() || ci->bound.hasMin || ci->bound.hasMax;
if (in_list && (!partialName.length() || strncmp(ci->plugin.chars(), partialName.chars(), partialName.length()) == 0))
@ -514,8 +513,8 @@ void CvarManager::OnConsoleCommand()
ci->hooks.empty() ? "no" : "yes",
ci->bound.hasMin || ci->bound.hasMax ? "yes" : "no");
}
else
{
else
{
if (++index != indexToSearch)
{
continue;
@ -530,7 +529,7 @@ void CvarManager::OnConsoleCommand()
print_srvconsole(" %-12s %-26.25s %s\n", "STATUS", "PLUGIN", "INFOS");
print_srvconsole(" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
if (ci->amxmodx)
{
print_srvconsole(" Registered %-26.25s %s\n", ci->plugin.chars(), "-");
@ -538,19 +537,19 @@ void CvarManager::OnConsoleCommand()
if (ci->bound.hasMin)
{
print_srvconsole(" Min Bounded %-26.25s %f\n", g_plugins.findPlugin(ci->bound.minPluginId)->getName(), ci->bound.minVal);
print_srvconsole(" Min value %-26.25s %f\n", g_plugins.findPlugin(ci->bound.minPluginId)->getName(), ci->bound.minVal);
}
if (ci->bound.hasMax)
{
print_srvconsole(" Max Bounded %-26.25s %f\n", g_plugins.findPlugin(ci->bound.maxPluginId)->getName(), ci->bound.maxVal);
print_srvconsole(" Max value %-26.25s %f\n", g_plugins.findPlugin(ci->bound.maxPluginId)->getName(), ci->bound.maxVal);
}
if (!ci->binds.empty())
{
for (size_t i = 0; i < ci->binds.length(); ++i)
{
print_srvconsole(" Binded %-26.25s %s\n", g_plugins.findPlugin(ci->binds[i]->pluginId)->getName(), "-");
print_srvconsole(" Bound %-26.25s %s\n", g_plugins.findPlugin(ci->binds[i]->pluginId)->getName(), "-");
}
}
@ -561,7 +560,7 @@ void CvarManager::OnConsoleCommand()
CvarHook* hook = ci->hooks[i];
print_srvconsole(" Hooked %-26.25s %s (%s)\n", g_plugins.findPlugin(hook->pluginId)->getName(),
hook->forward->callback.chars(),
hook->forward->callback.chars(),
hook->forward->state == AutoForward::FSTATE_OK ? "active" : "inactive");
}
}

View File

@ -12,7 +12,7 @@
#include "nongpl_matches.h"
char CVarTempBuffer[64];
const char *invis_cvar_list[5] = { "amxmodx_version", "amxmodx_modules", "amx_debug", "amx_mldebug", "amx_client_languages" };
const char *invis_cvar_list[5] ={ "amxmodx_version", "amxmodx_modules", "amx_debug", "amx_mldebug", "amx_client_languages" };
// create_cvar(const name[], const default_value[], flags = 0, const description[] = "", bool:has_min = false, Float:min_val = 0.0, bool:has_max = false, Float:max_val = 0.0)
static cell AMX_NATIVE_CALL create_cvar(AMX *amx, cell *params)
@ -23,7 +23,7 @@ static cell AMX_NATIVE_CALL create_cvar(AMX *amx, cell *params)
const char* helpText = get_amxstring(amx, params[4], 2, length);
int flags = params[3];
CPluginMngr::CPlugin *plugin = g_plugins.findPluginFast(amx);
if (CheckBadConList(name, 0))
@ -42,13 +42,13 @@ static cell AMX_NATIVE_CALL create_cvar(AMX *amx, cell *params)
if (!g_CvarManager.SetCvarMin(info, hasMin, minVal, plugin->getId()))
{
LogError(amx, AMX_ERR_NATIVE, "A lower bound can't be above an upper bound");
LogError(amx, AMX_ERR_NATIVE, "The minimum value can not be above the maximum value");
return 0;
}
if (!g_CvarManager.SetCvarMax(info, hasMax, maxVal, plugin->getId()))
{
LogError(amx, AMX_ERR_NATIVE, "An upper bound can't be below a lower bound");
LogError(amx, AMX_ERR_NATIVE, "The maximum value can not be below the minimum value");
return 0;
}
@ -500,7 +500,7 @@ static cell AMX_NATIVE_CALL set_pcvar_bounds(AMX *amx, cell *params)
{
if (!g_CvarManager.SetCvarMin(info, set, value, pluginId))
{
LogError(amx, AMX_ERR_NATIVE, "A lower bound can't be above an upper bound");
LogError(amx, AMX_ERR_NATIVE, "The minimum value can not be above the maximum value");
return 0;
}
break;
@ -509,7 +509,7 @@ static cell AMX_NATIVE_CALL set_pcvar_bounds(AMX *amx, cell *params)
{
if (!g_CvarManager.SetCvarMax(info, set, value, pluginId))
{
LogError(amx, AMX_ERR_NATIVE, "An upper bound can't be below a lower bound");
LogError(amx, AMX_ERR_NATIVE, "The maximum value can not be below the minimum value");
return 0;
}
break;
@ -670,7 +670,6 @@ static cell AMX_NATIVE_CALL query_client_cvar(AMX *amx, cell *params)
return 1;
}
AMX_NATIVE_INFO g_CvarNatives[] =
{
{"create_cvar", create_cvar},
@ -714,7 +713,7 @@ AMX_NATIVE_INFO g_CvarNatives[] =
{"get_plugins_cvar", get_plugins_cvar},
{"get_plugins_cvarsnum", get_plugins_cvarsnum},
{"query_client_cvar", query_client_cvar},
{NULL, NULL}

View File

@ -13,10 +13,9 @@
void amx_command()
{
const char* cmd = CMD_ARGV(1);
if (!strcmp(cmd, "plugins") || !strcmp(cmd, "list"))
{
print_srvconsole("Currently loaded plugins:\n");
print_srvconsole(" %-23.22s %-11.10s %-17.16s %-16.15s %-9.8s\n", "name", "version", "author", "file", "status");
@ -24,11 +23,11 @@ void amx_command()
int running = 0;
CPluginMngr::iterator a = g_plugins.begin();
while (a)
while (a)
{
++plugins;
if ((*a).isValid() && !(*a).isPaused())
if ((*a).isValid() && !(*a).isPaused())
++running;
print_srvconsole(" [%3d] %-23.22s %-11.10s %-17.16s %-16.15s %-9.8s\n", plugins, (*a).getTitle(), (*a).getVersion(), (*a).getAuthor(), (*a).getName(), (*a).getStatus());
@ -45,7 +44,8 @@ void amx_command()
{
//error
print_srvconsole("(%3d) Load fails: %s\n", num, (*a).getError());
} else if ( (*a).getStatusCode() == ps_error) {
}
else if ((*a).getStatusCode() == ps_error) {
//error
print_srvconsole("(%3d) Error: %s\n", num, (*a).getError());
}
@ -54,23 +54,23 @@ void amx_command()
print_srvconsole("%d plugins, %d running\n", plugins, running);
}
else if (!strcmp(cmd, "pause") && CMD_ARGC() > 2)
else if (!strcmp(cmd, "pause") && CMD_ARGC() > 2)
{
const char* sPlugin = CMD_ARGV(2);
CPluginMngr::CPlugin *plugin = g_plugins.findPlugin(sPlugin);
if (plugin && plugin->isValid())
if (plugin && plugin->isValid())
{
if (plugin->isPaused())
{
if (plugin->isStopped())
{
print_srvconsole("Plugin \"%s\" is stopped and may not be paused.\n",plugin->getName());
print_srvconsole("Plugin \"%s\" is stopped and may not be paused.\n", plugin->getName());
}
else
{
print_srvconsole("Plugin \"%s\" is already paused.\n",plugin->getName());
print_srvconsole("Plugin \"%s\" is already paused.\n", plugin->getName());
}
}
else
@ -79,18 +79,18 @@ void amx_command()
print_srvconsole("Paused plugin \"%s\"\n", plugin->getName());
}
}
else
else
{
print_srvconsole("Couldn't find plugin matching \"%s\"\n", sPlugin);
}
}
else if (!strcmp(cmd, "unpause") && CMD_ARGC() > 2)
else if (!strcmp(cmd, "unpause") && CMD_ARGC() > 2)
{
const char* sPlugin = CMD_ARGV(2);
CPluginMngr::CPlugin *plugin = g_plugins.findPlugin(sPlugin);
if (plugin && plugin->isValid() && plugin->isPaused())
if (plugin && plugin->isValid() && plugin->isPaused())
{
if (plugin->isStopped())
{
@ -105,19 +105,20 @@ void amx_command()
else if (!plugin)
{
print_srvconsole("Couldn't find plugin matching \"%s\"\n", sPlugin);
} else {
}
else {
print_srvconsole("Plugin %s can't be unpaused right now.\n", sPlugin);
}
}
else if (!strcmp(cmd, "cvars"))
else if (!strcmp(cmd, "cvars"))
{
g_CvarManager.OnConsoleCommand();
}
else if (!strcmp(cmd, "cmds"))
else if (!strcmp(cmd, "cmds"))
{
print_srvconsole("Registered commands:\n");
print_srvconsole(" %-24.23s %-16.15s %-8.7s %-16.15s\n", "name", "access", "type", "plugin");
int ammount = 0;
char access[32];
@ -146,9 +147,9 @@ void amx_command()
++a;
}
}
print_srvconsole("%d commands\n",ammount);
print_srvconsole("%d commands\n", ammount);
}
else if (!strcmp(cmd, "version"))
else if (!strcmp(cmd, "version"))
{
print_srvconsole("%s %s (%s)\n", Plugin_info.name, Plugin_info.version, Plugin_info.url);
print_srvconsole("Authors:\n\tDavid \"BAILOPAN\" Anderson, Pavol \"PM OnoTo\" Marko\n");
@ -178,7 +179,7 @@ void amx_command()
int running = 0;
int modules = 0;
CList<CModule,const char *>::iterator a = g_modules.begin();
CList<CModule, const char *>::iterator a = g_modules.begin();
while (a)
{
@ -229,14 +230,16 @@ void amx_command()
print_srvconsole("\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3A\x78\x78\x24\x40\x4E\x4E\x4D\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x5E\x3E\x3E\x3F\x3E\x3E\x3E\x3E\x3B\x3B\x3B\x3A\x3A\x3F\x3E\x3A\x2E\x2E\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x2E\x45\x4D\x40\x45\x78\x5E\x33\x68\x33\x2B\n");
print_srvconsole("\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x24\x48\x45\x48\x78\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x2B\x4E\x40\x2B\x66\x33\x78\x20\x20\n");
print_srvconsole("\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x2B\x2C\x20\x3A\x20\x20\n");
} else {
}
else
{
print_srvconsole("Usage: amxx < command > [ argument ]\n");
print_srvconsole("Commands:\n");
print_srvconsole(" version - display amxx version info\n");
print_srvconsole(" gpl - print the license\n");
print_srvconsole(" plugins - list plugins currently loaded\n");
print_srvconsole(" modules - list modules currently loaded\n");
print_srvconsole(" cvars [ plugin ] [ index ] - list cvars handled by amxx or show informations about a cvar if index is provided\n");
print_srvconsole(" cvars [ plugin ] [ index ] - list cvars handled by amxx or show information about a cvar if index is provided\n");
print_srvconsole(" cmds [ plugin ] - list commands registered by plugins\n");
print_srvconsole(" pause < plugin > - pause a running plugin\n");
print_srvconsole(" unpause < plugin > - unpause a previously paused plugin\n");
@ -246,15 +249,15 @@ void amx_command()
void plugin_srvcmd()
{
const char* cmd = CMD_ARGV(0);
CmdMngr::iterator a = g_commands.srvcmdbegin();
while (a)
{
if ((*a).matchCommand(cmd) && (*a).getPlugin()->isExecutable((*a).getFunction()))
{
cell ret = executeForwards((*a).getFunction(), static_cast<cell>(g_srvindex),
static_cast<cell>((*a).getFlags()), static_cast<cell>((*a).getId()));
static_cast<cell>((*a).getFlags()), static_cast<cell>((*a).getId()));
if (ret) break;
}
++a;