Fix recursion issues with show_menu and newmenus
This commit is contained in:
parent
581f734099
commit
41d7554efd
|
@ -1251,22 +1251,13 @@ static cell AMX_NATIVE_CALL get_user_team(AMX *amx, cell *params) /* 3 param */
|
|||
|
||||
static cell AMX_NATIVE_CALL show_menu(AMX *amx, cell *params) /* 3 param */
|
||||
{
|
||||
int ilen = 0, ilen2 = 0;
|
||||
char *sMenu = get_amxstring(amx, params[3], 0, ilen);
|
||||
char *lMenu = get_amxstring(amx, params[5], 1, ilen2);
|
||||
int menuid = 0;
|
||||
|
||||
if (ilen2 && lMenu)
|
||||
{
|
||||
menuid = g_menucmds.findMenuId(lMenu, amx);
|
||||
} else {
|
||||
menuid = g_menucmds.findMenuId(sMenu, amx);
|
||||
}
|
||||
|
||||
int keys = params[2];
|
||||
int time = params[4];
|
||||
|
||||
if (params[1] == 0)
|
||||
// If show_menu is called from within a newmenu callback upon receiving MENU_EXIT
|
||||
// it is possible for this native to recurse. We need to close newmenus right away
|
||||
// because the recursive call would otherwise modify/corrupt the static get_amxstring
|
||||
// buffer mid execution. This will either display incorrect text or result in UTIL_ShowMenu
|
||||
// running into an infinite loop.
|
||||
int index = params[1];
|
||||
if (index == 0)
|
||||
{
|
||||
for (int i = 1; i <= gpGlobals->maxClients; ++i)
|
||||
{
|
||||
|
@ -1282,23 +1273,11 @@ static cell AMX_NATIVE_CALL show_menu(AMX *amx, cell *params) /* 3 param */
|
|||
pMenu->Close(pPlayer->index);
|
||||
|
||||
UTIL_FakeClientCommand(pPlayer->pEdict, "menuselect", "10", 0);
|
||||
|
||||
pPlayer->keys = keys;
|
||||
pPlayer->menu = menuid;
|
||||
pPlayer->vgui = false;
|
||||
|
||||
if (time == -1)
|
||||
pPlayer->menuexpire = INFINITE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
pPlayer->menuexpire = gpGlobals->time + static_cast<float>(time);
|
||||
|
||||
pPlayer->page = 0;
|
||||
UTIL_ShowMenu(pPlayer->pEdict, keys, time, sMenu, ilen);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int index = params[1];
|
||||
|
||||
{
|
||||
if (index < 1 || index > gpGlobals->maxClients)
|
||||
{
|
||||
LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", index);
|
||||
|
@ -1317,7 +1296,36 @@ static cell AMX_NATIVE_CALL show_menu(AMX *amx, cell *params) /* 3 param */
|
|||
pMenu->Close(pPlayer->index);
|
||||
|
||||
UTIL_FakeClientCommand(pPlayer->pEdict, "menuselect", "10", 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ilen = 0, ilen2 = 0;
|
||||
char *sMenu = get_amxstring(amx, params[3], 0, ilen);
|
||||
char *lMenu = get_amxstring(amx, params[5], 1, ilen2);
|
||||
int menuid = 0;
|
||||
|
||||
if (ilen2 && lMenu)
|
||||
{
|
||||
menuid = g_menucmds.findMenuId(lMenu, amx);
|
||||
} else {
|
||||
menuid = g_menucmds.findMenuId(sMenu, amx);
|
||||
}
|
||||
|
||||
int keys = params[2];
|
||||
int time = params[4];
|
||||
|
||||
if (index == 0)
|
||||
{
|
||||
for (int i = 1; i <= gpGlobals->maxClients; ++i)
|
||||
{
|
||||
CPlayer* pPlayer = GET_PLAYER_POINTER_I(i);
|
||||
|
||||
if (pPlayer->ingame)
|
||||
{
|
||||
pPlayer->keys = keys;
|
||||
pPlayer->menu = menuid;
|
||||
pPlayer->vgui = false;
|
||||
|
@ -1331,6 +1339,21 @@ static cell AMX_NATIVE_CALL show_menu(AMX *amx, cell *params) /* 3 param */
|
|||
UTIL_ShowMenu(pPlayer->pEdict, keys, time, sMenu, ilen);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);
|
||||
|
||||
pPlayer->keys = keys;
|
||||
pPlayer->menu = menuid;
|
||||
pPlayer->vgui = false;
|
||||
|
||||
if (time == -1)
|
||||
pPlayer->menuexpire = INFINITE;
|
||||
else
|
||||
pPlayer->menuexpire = gpGlobals->time + static_cast<float>(time);
|
||||
|
||||
pPlayer->page = 0;
|
||||
UTIL_ShowMenu(pPlayer->pEdict, keys, time, sMenu, ilen);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user