SmileYzn / LogApi

JSON API to comunicate with WebServer using HTTP/s Protocol as MetaMod Plugin
https://pugbr.net
Apache License 2.0
11 stars 3 forks source link

Menu #5

Closed GLoOoccK closed 2 months ago

GLoOoccK commented 2 months ago

@SmileYzn

Using the New Menu System from AMX Mod X, the page change options (8 and 9) are not working, along with other issues. When LogApi is disabled, it works normally

Example codes:

#include <amxmodx>

public plugin_init()
{
    register_clcmd("say /test", "TestMenu");
    register_clcmd("say_team /test", "TestMenu");
}

public TestMenu(id)
{
    new menu = menu_create("Test Menu", "menu_handler");

    menu_additem(menu, "1");
    menu_additem(menu, "2");
    menu_additem(menu, "3");
    menu_additem(menu, "4");
    menu_additem(menu, "5");
    menu_additem(menu, "6");
    menu_additem(menu, "7");
    menu_additem(menu, "8");
    menu_additem(menu, "9");
    menu_additem(menu, "10");
    menu_additem(menu, "11");
    menu_additem(menu, "12");

    menu_display(id, menu);
    return PLUGIN_HANDLED;
}

public menu_handler(id, menu, item)
{
    switch (item)
    {
        default:
        {
            client_print(id, print_chat, "menu_handler");
        }
    }

    menu_destroy(menu);
    return PLUGIN_HANDLED;
}

https://github.com/alliedmodders/amxmodx/blob/master/plugins/testsuite/menutest.sma

GLoOoccK commented 2 months ago

@SmileYzn

Problem is coming from this part of the code:

https://github.com/SmileYzn/LogApi/blob/main/LogApi/ReGameDLL.cpp#L138-L142

// Handle menu
if (gLogMenu[Player->entindex()].Handle(Player->entindex(), Q_atoi(parg1)))
{
    // [...]
}

Commenting on this part of the code. New Menu System works again

SmileYzn commented 2 months ago

Already fixed!

GLoOoccK commented 2 months ago

@SmileYzn

I tested the last action, it didn't work, it keeps replacing the New Menu System buttons

Perhaps you would have to create an identifier in the menu, for example:

https://github.com/SmileYzn/LogApi/blob/main/LogApi/LogMenu.cpp#L18-L31

this->m_IsLogApi = true;

Checking if it is a LogApi menu, before taking any action

SmileYzn commented 2 months ago

I already have removed return of original client command function.

Test it now, i have removed other return in menu function.

GLoOoccK commented 2 months ago

@SmileYzn

I just tested it, it didn't work, I think it's because of this:

https://github.com/alliedmodders/amxmodx/blob/master/amxmodx/newmenus.cpp#L922-L925

if (get_pdata<int>(pPlayer->pEdict, m_iJoiningState) == Joined || (get_pdata<int>(pPlayer->pEdict, m_iMenu) != Menu_ChooseTeam && get_pdata<int>(pPlayer->pEdict, m_iMenu) != Menu_ChooseAppearance))
{
        set_pdata<int>(pPlayer->pEdict, m_iMenu, Menu_OFF);
}

they are also setting this:

https://github.com/SmileYzn/LogApi/blob/main/LogApi/LogMenu.cpp#L231

Player->m_iMenu = Menu_OFF;

So that's why it's overwriting and causing a bug in the menu, because the code doesn't know how to differentiate, ending up entering this if:

https://github.com/SmileYzn/LogApi/blob/main/LogApi/LogMenu.cpp#L83-L107

SmileYzn commented 2 months ago

So the real problem is in amxx?

Do not make any sense, LogAPI still do nothing with internal command ant problem still in logapi plugin?

GLoOoccK commented 2 months ago

@SmileYzn

AMXX is defining first:

Player->m_iMenu = Menu_OFF;

Soon after, for some reason, AMXX is calling InternalCommand, causing the code to enter the following if:

void ReGameDLL_InternalCommand(IReGameHook_InternalCommand* chain, edict_t* pEntity, const char* pcmd, const char* parg1)
{
    // [...]

    if (Player->m_iMenu == Menu_OFF)
    {
        // [...]
    }
}

Running:

bool CLogMenu::Handle(int EntityIndex, int Key)
{
    // [...]

    if (Player->m_iMenu == Menu_OFF)
    {
        // [...]
    }
}

Causing this part of the code to completely bug the menu, as it shouldn't get here, just the menu created by LogApi

SmileYzn commented 2 months ago

Sorry, but still do not make sense.

In actual code LogAPI do not block InternalCommand, so AMXX still receiving normal InternalCommand, do not matter if an logapi menu is shown or not.

That: if (Player->m_iMenu == Menu_OFF)

Do nothing in menus, and logapi only set it to Menu_OFF before display a menu.

GLoOoccK commented 2 months ago

@SmileYzn

Yes, but for some reason the AMXX menu is interacting with this piece of code:

if (Player->m_iMenu == Menu_OFF)
{
    if (Key == 9)
    {
        this->Display(EntityIndex, ++this->m_Page);
    }
    else if (Key == 10)
    {
        this->Display(EntityIndex, --this->m_Page);
    }
    else
    {
        unsigned int ItemIndex = (Key + (this->m_Page * this->m_PageOption)) - 1;

        if (ItemIndex < this->m_Data.size())
        {
            this->Hide(EntityIndex);

            if (this->m_Func)
            {
                ((void(*)(int, std::string Callback, P_MENU_ITEM))this->m_Func)(EntityIndex, this->m_Callback, this->m_Data[ItemIndex]);
            }
        }
    }

    return true;
}

It is not entering else at any time and giving a bug, i believe there should be some check like this:

if (Player->m_iMenu == Menu_OFF)
{
    if (this->m_IsLogApi)
    {
        if (Key == 9)
        {
            this->Display(EntityIndex, ++this->m_Page);
        }

        // [...]
    }
}
SmileYzn commented 2 months ago

No is not interacting since:

if (this->m_Page != -1)

Only if menu is displaying a page, that here is not the case

SmileYzn commented 2 months ago

Did you put the amxx before logapi or after in metamod plugins?

SmileYzn commented 2 months ago

I did a new update on LogMenu.h see if is fixed now

GLoOoccK commented 2 months ago

With this last change it was resolved, now everything is fine. Thank you very much