From 8cce737473ed0c5bb79fe1070844c34670b16026 Mon Sep 17 00:00:00 2001 From: Ashleigh Adams Date: Mon, 19 May 2025 21:37:44 +0100 Subject: [PATCH] Added support for the `menuselect` This command is more standard, and some players may already have these binds set, so use them if possible. --- README.md | 2 +- src/SharpModMenu/SharpModMenu.cs | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 937cb9b..3a424a9 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ https://www.youtube.com/watch?v=Be7qop6pVpI 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: ``` -bind 1 "slot1;css_1" +bind 1 "slot1;css_1" // menuselect 1 is also supported bind 2 "slot2;css_2" ... bind 9 "slot9;css_9" diff --git a/src/SharpModMenu/SharpModMenu.cs b/src/SharpModMenu/SharpModMenu.cs index 92670ac..9b532ae 100644 --- a/src/SharpModMenu/SharpModMenu.cs +++ b/src/SharpModMenu/SharpModMenu.cs @@ -338,6 +338,32 @@ private unsafe HookResult ProcessUserCmds(DynamicHook hook) return HookResult.Continue; } + [ConsoleCommand("menuselect")] + public void MenuSelect(CCSPlayerController player, CommandInfo info) + { + if (player is null || !player.IsValid) + return; + var menuState = DriverInstance?.GetMenuState(player, create: true); + if (menuState is null) + return; + + if (info.ArgCount < 2) + { + info.ReplyToCommand($"menuselect: Invalid number of arguments provided"); + return; + } + + var valStr = info.ArgByIndex(1); + if (!int.TryParse(valStr, CultureInfo.InvariantCulture, out var val)) + { + info.ReplyToCommand($"menuselect: Failed to parse argument as int: {valStr}"); + return; + } + + var key = (PlayerKey)((int)PlayerKey.SelectItem1 + (val - 1)); + menuState.HandleInput(key, info.CallingContext == CommandCallingContext.Console); + } + [ConsoleCommand("css_1")] public void Css1(CCSPlayerController player, CommandInfo info) {