From b17cde0a175d9c80d480f8b46b2487a881899a96 Mon Sep 17 00:00:00 2001 From: Kasey FItton Date: Mon, 4 Nov 2024 02:32:31 +0000 Subject: [PATCH] fix(es_extended/client): remove event handlers after resource stop --- [core]/es_extended/client/common.lua | 12 +++++------- [core]/es_extended/client/functions.lua | 14 +++++++++++++- [core]/es_extended/client/main.lua | 8 ++++++++ [core]/es_extended/client/modules/scaleform.lua | 3 +++ [core]/es_extended/client/modules/streaming.lua | 2 ++ 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/[core]/es_extended/client/common.lua b/[core]/es_extended/client/common.lua index 696251330..441af7662 100644 --- a/[core]/es_extended/client/common.lua +++ b/[core]/es_extended/client/common.lua @@ -1,9 +1,12 @@ Core = {} +Core.Input = {} +Core.Events = {} + ESX.PlayerData = {} +ESX.PlayerLoaded = false ESX.playerId = PlayerId() ESX.serverId = GetPlayerServerId(ESX.playerId) -ESX.PlayerLoaded = false -Core.Input = {} + ESX.UI = {} ESX.UI.Menu = {} ESX.UI.Menu.RegisteredTypes = {} @@ -12,11 +15,6 @@ ESX.UI.Menu.Opened = {} ESX.Game = {} ESX.Game.Utils = {} -ESX.Scaleform = {} -ESX.Scaleform.Utils = {} - -ESX.Streaming = {} - CreateThread(function() while not Config.Multichar do Wait(100) diff --git a/[core]/es_extended/client/functions.lua b/[core]/es_extended/client/functions.lua index ad95a6fbe..022b3821d 100644 --- a/[core]/es_extended/client/functions.lua +++ b/[core]/es_extended/client/functions.lua @@ -12,7 +12,17 @@ end ---@param func function ---@return nil function ESX.SecureNetEvent(name, func) - RegisterNetEvent(name, function(...) + local invoker = GetInvokingResource() + local invokingResource = invoker and invoker ~= 'unknown' and invoker or 'es_extended' + if not invokingResource then + return + end + + if not Core.Events[invokingResource] then + Core.Events[invokingResource] = {} + end + + local event = RegisterNetEvent(name, function(...) if source == '' then return end @@ -22,6 +32,8 @@ function ESX.SecureNetEvent(name, func) error(("%s"):format(result)) end end) + local eventIndex = #Core.Events[invokingResource] + 1 + Core.Events[invokingResource][eventIndex] = event end local addonResourcesState = { diff --git a/[core]/es_extended/client/main.lua b/[core]/es_extended/client/main.lua index ee3cf180c..268bb58fa 100644 --- a/[core]/es_extended/client/main.lua +++ b/[core]/es_extended/client/main.lua @@ -683,3 +683,11 @@ end) ESX.SecureNetEvent('esx:updatePlayerData', function(key, val) ESX.SetPlayerData(key, val) end) + +AddEventHandler("onResourceStop", function(resource) + if Core.Events[resource] then + for i = 1, #Core.Events[resource] do + RemoveEventHandler(Core.Events[resource][i]) + end + end +end) diff --git a/[core]/es_extended/client/modules/scaleform.lua b/[core]/es_extended/client/modules/scaleform.lua index b8a5359ef..66479685c 100644 --- a/[core]/es_extended/client/modules/scaleform.lua +++ b/[core]/es_extended/client/modules/scaleform.lua @@ -1,3 +1,6 @@ +ESX.Scaleform = {} +ESX.Scaleform.Utils = {} + function ESX.Scaleform.ShowFreemodeMessage(title, msg, sec) local scaleform = ESX.Scaleform.Utils.RequestScaleformMovie("MP_BIG_MESSAGE_FREEMODE") diff --git a/[core]/es_extended/client/modules/streaming.lua b/[core]/es_extended/client/modules/streaming.lua index b583bbcb2..8614c4fba 100644 --- a/[core]/es_extended/client/modules/streaming.lua +++ b/[core]/es_extended/client/modules/streaming.lua @@ -1,3 +1,5 @@ +ESX.Streaming = {} + ---@param modelHash number | string ---@param cb? function ---@return number | nil