Skip to content

Commit c6bb31a

Browse files
committed
Added support for the menuselect
This command is more standard, and some players may already have these binds set, so use them if possible.
1 parent 42490ab commit c6bb31a

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,34 @@ private unsafe HookResult ProcessUserCmds(DynamicHook hook)
338338
return HookResult.Continue;
339339
}
340340

341+
[ConsoleCommand("menuselect")]
342+
public HookResult MenuSelect(CCSPlayerController player, CommandInfo info)
343+
{
344+
if (player is null || !player.IsValid)
345+
return HookResult.Continue;
346+
var menuState = DriverInstance?.GetMenuState(player, create: true);
347+
if (menuState is null)
348+
return HookResult.Continue;
349+
350+
if (info.ArgCount < 2)
351+
{
352+
info.ReplyToCommand($"menuselect: Invalid number of arguments provided");
353+
return HookResult.Continue;
354+
}
355+
356+
var valStr = info.ArgByIndex(1);
357+
if (!int.TryParse(valStr, CultureInfo.InvariantCulture, out var val))
358+
{
359+
info.ReplyToCommand($"menuselect: Failed to parse argument as int: {valStr}");
360+
return HookResult.Continue;
361+
}
362+
363+
var key = (PlayerKey)((int)PlayerKey.SelectItem1 + (val - 1));
364+
365+
menuState.HandleInput(key, info.CallingContext == CommandCallingContext.Console);
366+
return HookResult.Stop;
367+
}
368+
341369
[ConsoleCommand("css_1")]
342370
public void Css1(CCSPlayerController player, CommandInfo info)
343371
{

0 commit comments

Comments
 (0)