diff --git a/managed/CounterStrikeSharp.API/Modules/Commands/CommandInfo.cs b/managed/CounterStrikeSharp.API/Modules/Commands/CommandInfo.cs index bfb621af5..265fa60e6 100644 --- a/managed/CounterStrikeSharp.API/Modules/Commands/CommandInfo.cs +++ b/managed/CounterStrikeSharp.API/Modules/Commands/CommandInfo.cs @@ -47,7 +47,29 @@ internal CommandInfo(IntPtr pointer, CCSPlayerController? player) public string ArgByIndex(int index) => NativeAPI.CommandGetArgByIndex(Handle, index); public string GetArg(int index) => NativeAPI.CommandGetArgByIndex(Handle, index); - + + public IEnumerable GetArgs(int startIndex = 0, int endIndex = -1) + { + if (string.IsNullOrEmpty(ArgString)) + return []; + + string[] args = ArgString.Split(' ', StringSplitOptions.RemoveEmptyEntries); + int lastIndex = args.Length - 1; + + startIndex = Math.Clamp(startIndex, 0, lastIndex); + endIndex = Math.Clamp(endIndex < 0 ? lastIndex : endIndex, startIndex, lastIndex); + + string[] selectedArgs = startIndex == endIndex + ? [args[startIndex]] + : args[startIndex..(endIndex + 1)]; + + return selectedArgs.Select(arg => + arg.Length >= 2 && arg[0] == '"' && arg[^1] == '"' + ? arg[1..^1] + : arg + ); + } + /// /// Whether or not the command was sent via Console or Chat. /// @@ -87,4 +109,4 @@ public void ReplyToCommand(string message) } } } -} \ No newline at end of file +}