Skip to content

Commit

Permalink
fix(es_extended/client): remove event handlers after resource stop
Browse files Browse the repository at this point in the history
  • Loading branch information
Mycroft-Studios committed Nov 4, 2024
1 parent 1594510 commit b17cde0
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
12 changes: 5 additions & 7 deletions [core]/es_extended/client/common.lua
Original file line number Diff line number Diff line change
@@ -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 = {}
Expand All @@ -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)
Expand Down
14 changes: 13 additions & 1 deletion [core]/es_extended/client/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = {
Expand Down
8 changes: 8 additions & 0 deletions [core]/es_extended/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 3 additions & 0 deletions [core]/es_extended/client/modules/scaleform.lua
Original file line number Diff line number Diff line change
@@ -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")

Expand Down
2 changes: 2 additions & 0 deletions [core]/es_extended/client/modules/streaming.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ESX.Streaming = {}

---@param modelHash number | string
---@param cb? function
---@return number | nil
Expand Down

0 comments on commit b17cde0

Please sign in to comment.