Skip to content

Commit

Permalink
Feature: new command redm_dump_settings - show mode current settings (
Browse files Browse the repository at this point in the history
#89)

* redm.inc: add GetCvarTypeStr()

* new command: `redm_dump_settings` - show mode current settings
  • Loading branch information
SergeyShorokhov authored Feb 11, 2024
1 parent 56b2043 commit b019871
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ static Trie: g_cvarValues = Invalid_Trie

CvarsHandler_Init() {
register_concmd("redm_dump_cvars", "ConCmd_redm_dump_cvars", ADMIN_MAP, "Dump changed CVar to table.")
register_concmd("redm_dump_settings", "ConCmd_redm_dump_settings", ADMIN_MAP, "Dump mode settings")
}

/**
Expand All @@ -21,6 +22,23 @@ public ConCmd_redm_dump_cvars(const player, const level, const commandId) {
return PLUGIN_HANDLED
}

/**
* Displays mode settings to the specified player.
*
* @param player The player to whom the CVAR values should be displayed.
* @param level The access level of the player executing the command.
* @param commandId The ID of the command.
* @return Returns PLUGIN_HANDLED.
*/
public ConCmd_redm_dump_settings(const player, const level, const commandId) {
if (!cmd_access(player, level, commandId, 1))
return PLUGIN_HANDLED

DumpAllSettings(player)

return PLUGIN_HANDLED
}

/**
* Loads CVAR settings from a Re:DM configuration.
*
Expand Down Expand Up @@ -194,3 +212,81 @@ stock DumpAllSavedCvars(const player = 0) {

TrieIterDestroy(iter)
}

DumpAllSettings(const player = 0, const prefix[] = "redm_") {
new const template[] = "| %-2i | %-32.32s | %-7s | %-16s | %10s |"
console_print(player, "| %-2s | %-32.32s | %-7s | %-16s | %10s |",
"#", "ConVar name", "type", "value", "bounds"
)
console_print(player,
"| -- | -------------------------------- | ------- | ---------------- | ---------- |"
)

for (new cvarIndex, idx; cvarIndex < 100; cvarIndex++) {
new name[32]
new flags
new pluginId
new cvarHandle
new description[192]

new bool: found = get_plugins_cvar(
cvarIndex,
name, charsmax(name),
flags,
pluginId,
cvarHandle,
description, charsmax(description)
) != 0

if (!found)
continue

if (flags & FCVAR_PROTECTED)
continue

#if 0
// TODO: Does it need to be?
static currentPluginId = -1
if (currentPluginId == -1)
currentPluginId = get_plugin(-1)

if (pluginId != currentPluginId)
continue
#endif

if (strncmp(name, prefix, strlen(prefix), .ignorecase = true) != 0)
continue

new valueStr[32]
if (flags & _FCVAR_FLOAT)
formatex(valueStr, charsmax(valueStr), "%.2f", get_pcvar_float(cvarHandle))
else
get_pcvar_string(cvarHandle, valueStr, charsmax(valueStr))

enum Bounds_s {
bool: hasBound,
Float: value
}
new bounds[CvarBounds][Bounds_s]

for (new CvarBounds: boundType; boundType < CvarBounds; boundType++) {
bounds[boundType][hasBound] = get_pcvar_bounds(cvarHandle, boundType, bounds[boundType][value])
}

new boundsBuffer[32]
if (bounds[CvarBound_Lower][hasBound] || bounds[CvarBound_Upper][hasBound]) {
formatex(boundsBuffer, charsmax(boundsBuffer), "%s .. %s",
bounds[CvarBound_Lower][hasBound] ? fmt("%.1f", bounds[CvarBound_Lower][value]) : " - ",
bounds[CvarBound_Upper][hasBound] ? fmt("%.1f", bounds[CvarBound_Upper][value]) : " - "
)
}

console_print(player, template,
++idx,
name,
GetCvarTypeStr(flags),
valueStr,
boundsBuffer
)
}
}
16 changes: 16 additions & 0 deletions cstrike/addons/amxmodx/scripting/include/redm.inc
Original file line number Diff line number Diff line change
Expand Up @@ -597,3 +597,19 @@ enum _: ConVar_ExtendedFlags (<<= 1) {
_FCVAR_STRING, /**< Can contain string value */
_FCVAR_FLOAT, /**< Can contain float value */
}

stock GetCvarTypeStr(const /* ConVar_ExtendedFlags: */ flags) {
new buffer[32]
copy(buffer, charsmax(buffer), "number")

if (flags & _FCVAR_BOOLEAN)
copy(buffer, charsmax(buffer), "boolean")

if (flags & _FCVAR_STRING)
copy(buffer, charsmax(buffer), "string")

if (flags & _FCVAR_FLOAT)
copy(buffer, charsmax(buffer), "float")

return buffer
}

0 comments on commit b019871

Please sign in to comment.