From c946633ba9830f3e67e0a06e002ec11eb2a681fc Mon Sep 17 00:00:00 2001 From: zImSkillz <83404249+zImSkillz@users.noreply.github.com> Date: Sat, 12 Oct 2024 19:42:02 +0200 Subject: [PATCH 1/2] Add an option to use the cancel function instead of the close function --- [core]/es_extended/client/functions.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/[core]/es_extended/client/functions.lua b/[core]/es_extended/client/functions.lua index 2095bcb89..a950ec78d 100644 --- a/[core]/es_extended/client/functions.lua +++ b/[core]/es_extended/client/functions.lua @@ -236,21 +236,29 @@ function ESX.UI.Menu.Open(menuType, namespace, name, data, submit, cancel, chang return menu end -function ESX.UI.Menu.Close(menuType, namespace, name) +function ESX.UI.Menu.Close(menuType, namespace, name, cancel) for i = 1, #ESX.UI.Menu.Opened, 1 do if ESX.UI.Menu.Opened[i] then if ESX.UI.Menu.Opened[i].type == menuType and ESX.UI.Menu.Opened[i].namespace == namespace and ESX.UI.Menu.Opened[i].name == name then - ESX.UI.Menu.Opened[i].close() + if not cancel then + ESX.UI.Menu.Opened[i].close() + else + ESX.UI.Menu.Opened[i].cancel() + end ESX.UI.Menu.Opened[i] = nil end end end end -function ESX.UI.Menu.CloseAll() +function ESX.UI.Menu.CloseAll(cancel) for i = 1, #ESX.UI.Menu.Opened, 1 do if ESX.UI.Menu.Opened[i] then - ESX.UI.Menu.Opened[i].close() + if not cancel then + ESX.UI.Menu.Opened[i].close() + else + ESX.UI.Menu.Opened[i].cancel() + end ESX.UI.Menu.Opened[i] = nil end end From 622c8e5299448d5b6cdedcb310bfe0643ff88da0 Mon Sep 17 00:00:00 2001 From: Sergio <89666307+feelfreetofee@users.noreply.github.com> Date: Sun, 13 Oct 2024 16:06:25 +0200 Subject: [PATCH 2/2] fix(es_extended/client/functions.lua) RegisterInput and HashString bug In the last update, **RegisterInput** tries to execute the command on key release due some checks removal in #1303 . The check was restored and tested. **HashString** breaks when the joaat returns a hash bigger than 2^31. It was fix using a [shift mask](https://stackoverflow.com/a/20294714). --- [core]/es_extended/client/functions.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/[core]/es_extended/client/functions.lua b/[core]/es_extended/client/functions.lua index 2095bcb89..f35fb4528 100644 --- a/[core]/es_extended/client/functions.lua +++ b/[core]/es_extended/client/functions.lua @@ -120,7 +120,7 @@ function ESX.DrawMissionText(msg, time) end function ESX.HashString(str) - return ('~INPUT_%s~'):format(('%x'):format(joaat(str)):upper()) + return ('~INPUT_%s~'):format(('%x'):format(joaat(str) & 0x7fffffff + 2 ^ 31):upper()) end function ESX.OpenContext(...) @@ -140,12 +140,12 @@ function ESX.RefreshContext(...) end function ESX.RegisterInput(command_name, label, input_group, key, on_press, on_release) - RegisterCommand("+" .. command_name, on_press) - Core.Input[command_name] = ESX.HashString("+" .. command_name) + RegisterCommand(on_release and '+' .. command_name or command_name, on_press) + Core.Input[command_name] = ESX.HashString(command_name) if on_release then - RegisterCommand("-" .. command_name, on_release) + RegisterCommand('-' .. command_name, on_release) end - RegisterKeyMapping("+" .. command_name, label or '', input_group or 'keyboard', key or '') + RegisterKeyMapping(command_name, label or '', input_group or 'keyboard', key or '') end function ESX.UI.Menu.RegisterType(menuType, open, close)