alliedmodders / sourcemod

SourceMod - Source Engine Scripting and Administration
http://www.sourcemod.net/
976 stars 422 forks source link

[L4D2] Panel Items with ITEMDRAW_DISABLED / ITEMDRAW_NOTEXT are still functional when selected #2206

Open Mute-255 opened 5 days ago

Mute-255 commented 5 days ago

Help us help you

Left 4 Dead 2 on Linux server, SM 1.11.0.6968 / MM 1.11.0-dev+1155

Description

If a Panel created with CreatePanel has items with the ITEMDRAW_DISABLED or ITEMDRAW_NOTEXT draw style flags, in the past selecting these options would simply close the panel without passing the action == MenuAction_Select check in the callback (or maybe it didn't call the callback at all, I don't know). However, these options are now passing through when they shouldn't, meaning disabled and hidden menu options are incorrectly functioning equivalent to regular menu options. This does not seem to happen to Menus created with CreateMenu.

Example Code

public Action PanelTest(int client, int args)
{
    Panel panel = CreatePanel();
    DrawPanelItem(panel, "disabled option", ITEMDRAW_DISABLED);
    DrawPanelItem(panel, "functional option");
    SendPanelToClient(panel, client, PanelTestHandler, 999);
    CloseHandle(panel);
    return Plugin_Handled;
}

public PanelTestHandler(Menu menu, MenuAction action, int param1, int param2)
{
    if(action == MenuAction_Select)
    {
        switch(param2)
        {
            case 1:
                PrintToChatAll("this shouldnt be visible");
            case 2:
                PrintToChatAll("this should be visible");
        }
    }
}
asherkin commented 5 days ago

I believe this has always been the case for L4D2, it's related to the RadioMenuClosesOnInvalidSlot workaround:

https://github.com/alliedmodders/sourcemod/blob/4e15a92984570aee8cb8438c8fd8bd24876342ca/gamedata/core.games/common.games.txt#L386-L399

https://github.com/alliedmodders/sourcemod/blob/4e15a92984570aee8cb8438c8fd8bd24876342ca/core/MenuStyle_Radio.cpp#L476-L484

The menu system does have it's own validity concept which it uses to filter these out of the callback, but panels are meant to be a very low-level abstraction. MenuStyle_Radio does have the true key map, so it could filter them out itself in ClientPressedKey if the workaround is in use.

Mute-255 commented 4 days ago

Your response has implanted a little doubt, but I'm like 99% sure this hasn't always been the case, over several years I've made quite a lot of panels under the impression and implementation that clicking a disabled/hidden option will just close the panel, and it definitely worked as intended back then. I wish I had some form of video recording showing it working as intended but it's not something I foresaw breaking like this. I also feel like if this was always the case it would have been mentioned either here or anywhere else, yet I could not find any mention of this issue.