|
18 | 18 | using Steamworks; |
19 | 19 |
|
20 | 20 | using System.Diagnostics.CodeAnalysis; |
| 21 | +using System.Globalization; |
21 | 22 | using System.Runtime.CompilerServices; |
22 | 23 | using System.Text; |
23 | 24 |
|
@@ -1610,6 +1611,78 @@ public void ShutdownServer() { |
1610 | 1611 | GC.Collect(GC.MaxGeneration, GCCollectionMode.Aggressive); |
1611 | 1612 | } |
1612 | 1613 |
|
| 1614 | + [ConCommand(helpText: "Increment specified convar value.", flags: FCvar.DontRecord)] |
| 1615 | + void incrementvar(in TokenizedCommand args) { |
| 1616 | + if (args.ArgC() != 5) { |
| 1617 | + Warning("Usage: incrementvar varName minValue maxValue delta\n"); |
| 1618 | + return; |
| 1619 | + } |
| 1620 | + |
| 1621 | + ReadOnlySpan<char> varName = args[1]; |
| 1622 | + |
| 1623 | + ConVar? var = cvar.FindVar(varName); |
| 1624 | + if (var == null) { |
| 1625 | + ConDMsg("cvar \"%s\" not found\n", varName.ToString()); |
| 1626 | + return; |
| 1627 | + } |
| 1628 | + |
| 1629 | + float currentValue = var.GetFloat(); |
| 1630 | + float startValue = (float)atof(args[2]); |
| 1631 | + float endValue = (float)atof(args[3]); |
| 1632 | + float delta = (float)atof(args[4]); |
| 1633 | + float newValue = currentValue + delta; |
| 1634 | + if (newValue > endValue) |
| 1635 | + newValue = startValue; |
| 1636 | + else if (newValue < startValue) |
| 1637 | + newValue = endValue; |
| 1638 | + |
| 1639 | + string value = ((double)newValue).ToString("F6", CultureInfo.InvariantCulture); |
| 1640 | + string command = $"{varName} {value}"; |
| 1641 | +#if GMOD_DLL |
| 1642 | + Cbuf.AddRawText(command); |
| 1643 | +#else |
| 1644 | + Cbuf.AddText(command); |
| 1645 | +#endif |
| 1646 | + |
| 1647 | + ConDMsg("%s = %s\n", var.GetName(), value); |
| 1648 | + } |
| 1649 | + |
| 1650 | + [ConCommand(helpText: "Multiply specified convar value.", flags: FCvar.DontRecord)] |
| 1651 | + void multvar(in TokenizedCommand args) { |
| 1652 | + if (args.ArgC() != 5) { |
| 1653 | + Warning("Usage: multvar varName minValue maxValue factor\n"); |
| 1654 | + return; |
| 1655 | + } |
| 1656 | + |
| 1657 | + ReadOnlySpan<char> varName = args[1]; |
| 1658 | + |
| 1659 | + ConVar? var = cvar.FindVar(varName); |
| 1660 | + if (var == null) { |
| 1661 | + ConDMsg("cvar \"%s\" not found\n", varName.ToString()); |
| 1662 | + return; |
| 1663 | + } |
| 1664 | + |
| 1665 | + float currentValue = var.GetFloat(); |
| 1666 | + float startValue = (float)atof(args[2]); |
| 1667 | + float endValue = (float)atof(args[3]); |
| 1668 | + float factor = (float)atof(args[4]); |
| 1669 | + float newValue = currentValue * factor; |
| 1670 | + if (newValue > endValue) |
| 1671 | + newValue = endValue; |
| 1672 | + else if (newValue < startValue) |
| 1673 | + newValue = startValue; |
| 1674 | + |
| 1675 | + string value = ((double)newValue).ToString("F6", CultureInfo.InvariantCulture); |
| 1676 | + string command = $"{varName} {value}"; |
| 1677 | +#if GMOD_DLL |
| 1678 | + Cbuf.AddRawText(command); |
| 1679 | +#else |
| 1680 | + Cbuf.AddText(command); |
| 1681 | +#endif |
| 1682 | + |
| 1683 | + ConDMsg("%s = %s\n", var.GetName(), value); |
| 1684 | + } |
| 1685 | + |
1613 | 1686 | [ConCommand] |
1614 | 1687 | void dumpstringtables() { |
1615 | 1688 | SV.DumpStringTables(); |
|
0 commit comments