Skip to content

Commit 5c7ec1d

Browse files
Merge pull request #1 from CSGALS/menuselect
Added support for the `menuselect`
2 parents a5beb60 + 8cce737 commit 5c7ec1d

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ https://www.youtube.com/watch?v=Be7qop6pVpI
77
When number keys are bound with the following snippet, automatically detected and the menu will look like it used to in CSS and CS:GO:
88

99
```
10-
bind 1 "slot1;css_1"
10+
bind 1 "slot1;css_1" // menuselect 1 is also supported
1111
bind 2 "slot2;css_2"
1212
...
1313
bind 9 "slot9;css_9"

src/SharpModMenu/SharpModMenu.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,32 @@ private unsafe HookResult ProcessUserCmds(DynamicHook hook)
362362
return HookResult.Continue;
363363
}
364364

365+
[ConsoleCommand("menuselect")]
366+
public void MenuSelect(CCSPlayerController player, CommandInfo info)
367+
{
368+
if (player is null || !player.IsValid)
369+
return;
370+
var menuState = DriverInstance?.GetMenuState(player, create: true);
371+
if (menuState is null)
372+
return;
373+
374+
if (info.ArgCount < 2)
375+
{
376+
info.ReplyToCommand($"menuselect: Invalid number of arguments provided");
377+
return;
378+
}
379+
380+
var valStr = info.ArgByIndex(1);
381+
if (!int.TryParse(valStr, CultureInfo.InvariantCulture, out var val))
382+
{
383+
info.ReplyToCommand($"menuselect: Failed to parse argument as int: {valStr}");
384+
return;
385+
}
386+
387+
var key = (PlayerKey)((int)PlayerKey.SelectItem1 + (val - 1));
388+
menuState.HandleInput(key, info.CallingContext == CommandCallingContext.Console);
389+
}
390+
365391
[ConsoleCommand("css_1")]
366392
public void Css1(CCSPlayerController player, CommandInfo info)
367393
{

0 commit comments

Comments
 (0)