diff --git a/[core]/es_extended/client/functions.lua b/[core]/es_extended/client/functions.lua index b387c4cd..70b22e99 100644 --- a/[core]/es_extended/client/functions.lua +++ b/[core]/es_extended/client/functions.lua @@ -1,11 +1,29 @@ +---@return boolean function ESX.IsPlayerLoaded() return ESX.PlayerLoaded end +---@return table function ESX.GetPlayerData() return ESX.PlayerData end +---@param name string +---@param func function +---@return nil +function ESX.SecureNetEvent(name, func) + RegisterNetEvent(name, function() + if source == '' then + return + end + + local success, result = pcall(func) + if not success then + error(("%s"):format(result)) + end + end) +end + local addonResourcesState = { ['esx_progressbar'] = GetResourceState('esx_progressbar') ~= 'missing', ['esx_notify'] = GetResourceState('esx_notify') ~= 'missing', @@ -1485,11 +1503,11 @@ function ESX.ShowInventory() end) end -RegisterNetEvent('esx:showNotification', ESX.ShowNotification) +ESX.SecureNetEvent('esx:showNotification', ESX.ShowNotification) -RegisterNetEvent('esx:showAdvancedNotification', ESX.ShowAdvancedNotification) +ESX.SecureNetEvent('esx:showAdvancedNotification', ESX.ShowAdvancedNotification) -RegisterNetEvent('esx:showHelpNotification', ESX.ShowHelpNotification) +ESX.SecureNetEvent('esx:showHelpNotification', ESX.ShowHelpNotification) AddEventHandler("onResourceStop", function(resourceName) for i = 1, #ESX.UI.Menu.Opened, 1 do diff --git a/[core]/es_extended/client/main.lua b/[core]/es_extended/client/main.lua index 97edfd9b..ee3cf180 100644 --- a/[core]/es_extended/client/main.lua +++ b/[core]/es_extended/client/main.lua @@ -1,6 +1,6 @@ local pickups = {} -RegisterNetEvent("esx:requestModel", function(model) +ESX.SecureNetEvent("esx:requestModel", function(model) ESX.Streaming.RequestModel(model) end) @@ -148,7 +148,7 @@ local function ApplyConfig() DisableNPCs() end -RegisterNetEvent("esx:playerLoaded", function(xPlayer, _, skin) +ESX.SecureNetEvent("esx:playerLoaded", function(xPlayer, _, skin) ESX.PlayerData = xPlayer if not Config.Multichar then @@ -192,11 +192,11 @@ RegisterNetEvent("esx:playerLoaded", function(xPlayer, _, skin) StartServerSyncLoops() end) -RegisterNetEvent("esx:onPlayerLogout", function() +ESX.SecureNetEvent("esx:onPlayerLogout", function() ESX.PlayerLoaded = false end) -RegisterNetEvent("esx:setMaxWeight", function(newMaxWeight) +ESX.SecureNetEvent("esx:setMaxWeight", function(newMaxWeight) ESX.SetPlayerData("maxWeight", newMaxWeight) end) @@ -273,7 +273,7 @@ AddStateBagChangeHandler("VehicleProperties", nil, function(bagName, _, value) ESX.Game.SetVehicleProperties(vehicle, value) end) -RegisterNetEvent("esx:setAccountMoney", function(account) +ESX.SecureNetEvent("esx:setAccountMoney", function(account) for i = 1, #ESX.PlayerData.accounts do if ESX.PlayerData.accounts[i].name == account.name then ESX.PlayerData.accounts[i] = account @@ -285,7 +285,7 @@ RegisterNetEvent("esx:setAccountMoney", function(account) end) if not Config.CustomInventory then - RegisterNetEvent("esx:addInventoryItem", function(item, count, showNotification) + ESX.SecureNetEvent("esx:addInventoryItem", function(item, count, showNotification) for k, v in ipairs(ESX.PlayerData.inventory) do if v.name == item then ESX.UI.ShowInventoryItemNotification(true, v.label, count - v.count) @@ -299,7 +299,7 @@ if not Config.CustomInventory then end end) - RegisterNetEvent("esx:removeInventoryItem", function(item, count, showNotification) + ESX.SecureNetEvent("esx:removeInventoryItem", function(item, count, showNotification) for i = 1, #ESX.PlayerData.inventory do if ESX.PlayerData.inventory[i].name == item then ESX.UI.ShowInventoryItemNotification(false, ESX.PlayerData.inventory[i].label, ESX.PlayerData.inventory[i].count - count) @@ -326,7 +326,7 @@ if not Config.CustomInventory then error("event ^5'esx:setWeaponAmmo'^1 Has Been Removed. Please use ^5xPlayer.addWeaponAmmo^1 Instead!") end) - RegisterNetEvent("esx:setWeaponTint", function(weapon, weaponTintIndex) + ESX.SecureNetEvent("esx:setWeaponTint", function(weapon, weaponTintIndex) SetPedWeaponTintIndex(ESX.PlayerData.ped, joaat(weapon), weaponTintIndex) end) @@ -334,22 +334,22 @@ if not Config.CustomInventory then error("event ^5'esx:removeWeapon'^1 Has Been Removed. Please use ^5xPlayer.removeWeapon^1 Instead!") end) - RegisterNetEvent("esx:removeWeaponComponent", function(weapon, weaponComponent) + ESX.SecureNetEvent("esx:removeWeaponComponent", function(weapon, weaponComponent) local componentHash = ESX.GetWeaponComponent(weapon, weaponComponent).hash RemoveWeaponComponentFromPed(ESX.PlayerData.ped, joaat(weapon), componentHash) end) end -RegisterNetEvent("esx:setJob", function(Job) +ESX.SecureNetEvent("esx:setJob", function(Job) ESX.SetPlayerData("job", Job) end) -RegisterNetEvent("esx:setGroup", function(group) +ESX.SecureNetEvent("esx:setGroup", function(group) ESX.SetPlayerData("group", group) end) if not Config.CustomInventory then - RegisterNetEvent("esx:createPickup", function(pickupId, label, coords, itemType, name, components, tintIndex) + ESX.SecureNetEvent("esx:createPickup", function(pickupId, label, coords, itemType, name, components, tintIndex) local function setObjectProperties(object) SetEntityAsMissionEntity(object, true, false) PlaceObjectOnGroundProperly(object) @@ -383,14 +383,14 @@ if not Config.CustomInventory then end end) - RegisterNetEvent("esx:createMissingPickups", function(missingPickups) + ESX.SecureNetEvent("esx:createMissingPickups", function(missingPickups) for pickupId, pickup in pairs(missingPickups) do TriggerEvent("esx:createPickup", pickupId, pickup.label, vector3(pickup.coords.x, pickup.coords.y, pickup.coords.z - 1.0), pickup.type, pickup.name, pickup.components, pickup.tintIndex) end end) end -RegisterNetEvent("esx:registerSuggestions", function(registeredCommands) +ESX.SecureNetEvent("esx:registerSuggestions", function(registeredCommands) for name, command in pairs(registeredCommands) do if command.suggestion then TriggerEvent("chat:addSuggestion", ("/%s"):format(name), command.suggestion.help, command.suggestion.arguments) @@ -399,7 +399,7 @@ RegisterNetEvent("esx:registerSuggestions", function(registeredCommands) end) if not Config.CustomInventory then - RegisterNetEvent("esx:removePickup", function(pickupId) + ESX.SecureNetEvent("esx:removePickup", function(pickupId) if pickups[pickupId] and pickups[pickupId].obj then ESX.Game.DeleteObject(pickups[pickupId].obj) pickups[pickupId] = nil @@ -408,7 +408,7 @@ if not Config.CustomInventory then end function StartServerSyncLoops() - if Config.CustomInventory then return end + if Config.CustomInventory then return end -- keep track of ammo CreateThread(function() local currentWeapon = { Ammo = 0 } @@ -495,7 +495,7 @@ if not Config.CustomInventory then end ----- Admin commands from esx_adminplus -RegisterNetEvent("esx:tpm", function() +ESX.SecureNetEvent("esx:tpm", function() local GetEntityCoords = GetEntityCoords local GetGroundZFor_3dCoord = GetGroundZFor_3dCoord local GetFirstBlipInfoId = GetFirstBlipInfoId @@ -627,7 +627,7 @@ local function noclipThread() end end -RegisterNetEvent("esx:noclip", function() +ESX.SecureNetEvent("esx:noclip", function() ESX.TriggerServerCallback("esx:isUserAdmin", function(admin) if not admin then return @@ -651,11 +651,11 @@ RegisterNetEvent("esx:noclip", function() end) end) -RegisterNetEvent("esx:killPlayer", function() +ESX.SecureNetEvent("esx:killPlayer", function() SetEntityHealth(ESX.PlayerData.ped, 0) end) -RegisterNetEvent("esx:repairPedVehicle", function() +ESX.SecureNetEvent("esx:repairPedVehicle", function() local ped = ESX.PlayerData.ped local vehicle = GetVehiclePedIsIn(ped, false) SetVehicleEngineHealth(vehicle, 1000) @@ -664,7 +664,7 @@ RegisterNetEvent("esx:repairPedVehicle", function() SetVehicleDirtLevel(vehicle, 0) end) -RegisterNetEvent("esx:freezePlayer", function(input) +ESX.SecureNetEvent("esx:freezePlayer", function(input) if input == "freeze" then SetEntityCollision(ESX.PlayerData.ped, false, false) FreezeEntityPosition(ESX.PlayerData.ped, true) @@ -680,6 +680,6 @@ ESX.RegisterClientCallback("esx:GetVehicleType", function(cb, model) cb(ESX.GetVehicleTypeClient(model)) end) -RegisterNetEvent('esx:updatePlayerData', function(key, val) +ESX.SecureNetEvent('esx:updatePlayerData', function(key, val) ESX.SetPlayerData(key, val) end) diff --git a/[core]/es_extended/client/modules/callback.lua b/[core]/es_extended/client/modules/callback.lua index b418878a..738b3bb1 100644 --- a/[core]/es_extended/client/modules/callback.lua +++ b/[core]/es_extended/client/modules/callback.lua @@ -66,7 +66,7 @@ ESX.TriggerServerCallback = function(eventName, callback, ...) Callbacks:Trigger(eventName, callback, invoker, ...) end -RegisterNetEvent("esx:serverCallback", function(...) +ESX.SecureNetEvent("esx:serverCallback", function(...) Callbacks:ServerRecieve(...) end) @@ -77,6 +77,6 @@ ESX.RegisterClientCallback = function(eventName, callback) Callbacks:Register(eventName, callback) end -RegisterNetEvent("esx:triggerClientCallback", function(...) +ESX.SecureNetEvent("esx:triggerClientCallback", function(...) Callbacks:ClientRecieve(...) end) diff --git a/[core]/es_extended/client/modules/npwd.lua b/[core]/es_extended/client/modules/npwd.lua index fd88354a..98ff92e6 100644 --- a/[core]/es_extended/client/modules/npwd.lua +++ b/[core]/es_extended/client/modules/npwd.lua @@ -9,7 +9,7 @@ local function checkPhone() npwd:setPhoneDisabled((phoneItem and phoneItem.count or 0) <= 0) end -RegisterNetEvent("esx:playerLoaded", checkPhone) +ESX.SecureNetEvent("esx:playerLoaded", checkPhone) AddEventHandler("onClientResourceStart", function(resource) if resource ~= "npwd" then @@ -29,7 +29,7 @@ AddEventHandler("onClientResourceStop", function(resource) end end) -RegisterNetEvent("esx:onPlayerLogout", function() +ESX.SecureNetEvent("esx:onPlayerLogout", function() if not npwd then return end @@ -38,7 +38,7 @@ RegisterNetEvent("esx:onPlayerLogout", function() npwd:setPhoneDisabled(true) end) -RegisterNetEvent("esx:removeInventoryItem", function(item, count) +ESX.SecureNetEvent("esx:removeInventoryItem", function(item, count) if not npwd then return end @@ -48,7 +48,7 @@ RegisterNetEvent("esx:removeInventoryItem", function(item, count) end end) -RegisterNetEvent("esx:addInventoryItem", function(item) +ESX.SecureNetEvent("esx:addInventoryItem", function(item) if not npwd or item ~= "phone" then return end diff --git a/[core]/es_extended/imports.lua b/[core]/es_extended/imports.lua index ffb7d4bf..7357675e 100644 --- a/[core]/es_extended/imports.lua +++ b/[core]/es_extended/imports.lua @@ -12,12 +12,12 @@ if not IsDuplicityVersion() then -- Only register this event for the client end end) - RegisterNetEvent("esx:playerLoaded", function(xPlayer) + ESX.SecureNetEvent("esx:playerLoaded", function(xPlayer) ESX.PlayerData = xPlayer ESX.PlayerLoaded = true end) - RegisterNetEvent("esx:onPlayerLogout", function() + ESX.SecureNetEvent("esx:onPlayerLogout", function() ESX.PlayerLoaded = false ESX.PlayerData = {} end) diff --git a/[core]/esx_identity/client/main.lua b/[core]/esx_identity/client/main.lua index 599ec7cf..911127b5 100644 --- a/[core]/esx_identity/client/main.lua +++ b/[core]/esx_identity/client/main.lua @@ -3,14 +3,14 @@ local ready = false local guiEnabled = false local timecycleModifier = "hud_def_blur" -RegisterNetEvent("esx_identity:alreadyRegistered", function() +ESX.SecureNetEvent("esx_identity:alreadyRegistered", function() while not loadingScreenFinished do Wait(100) end TriggerEvent("esx_skin:playerRegistered") end) -RegisterNetEvent("esx_identity:setPlayerData", function(data) +ESX.SecureNetEvent("esx_identity:setPlayerData", function(data) SetTimeout(1, function() ESX.SetPlayerData("name", ("%s %s"):format(data.firstName, data.lastName)) ESX.SetPlayerData("firstName", data.firstName) @@ -44,7 +44,7 @@ if not Config.UseDeferrals then SendNUIMessage({ type = "enableui", enable = state }) end - RegisterNetEvent("esx_identity:showRegisterIdentity", function() + ESX.SecureNetEvent("esx_identity:showRegisterIdentity", function() TriggerEvent("esx_skin:resetFirstSpawn") while not (ready and loadingScreenFinished) do print("Waiting for esx_identity NUI..") diff --git a/[core]/esx_multicharacter/client/main.lua b/[core]/esx_multicharacter/client/main.lua index 04b9a88e..33568bc6 100644 --- a/[core]/esx_multicharacter/client/main.lua +++ b/[core]/esx_multicharacter/client/main.lua @@ -29,15 +29,15 @@ end) -- Events -RegisterNetEvent("esx_multicharacter:SetupUI", function(data, slots) +ESX.SecureNetEvent("esx_multicharacter:SetupUI", function(data, slots) Multicharacter:SetupUI(data, slots) end) -RegisterNetEvent('esx:playerLoaded', function(playerData, isNew, skin) +ESX.SecureNetEvent('esx:playerLoaded', function(playerData, isNew, skin) Multicharacter:PlayerLoaded(playerData, isNew, skin) end) -RegisterNetEvent('esx:onPlayerLogout', function() +ESX.SecureNetEvent('esx:onPlayerLogout', function() DoScreenFadeOut(500) Wait(5000) diff --git a/[core]/esx_notify/Notify.lua b/[core]/esx_notify/Notify.lua index 2d8e5900..26dacd06 100644 --- a/[core]/esx_notify/Notify.lua +++ b/[core]/esx_notify/Notify.lua @@ -32,7 +32,7 @@ local function Notify(notificatonType, length, message) end exports("Notify", Notify) -RegisterNetEvent("ESX:Notify", Notify) +ESX.SecureNetEvent("ESX:Notify", Notify) if Debug then RegisterCommand("oldnotify", function() diff --git a/[core]/esx_skin/client/main.lua b/[core]/esx_skin/client/main.lua index 33b611a5..d37780d9 100644 --- a/[core]/esx_skin/client/main.lua +++ b/[core]/esx_skin/client/main.lua @@ -31,7 +31,7 @@ function Skin:CalcuatePosition(coords) } local angleToLook = self:CalcualteHeading(self.heading - 140.0) - + local thetaToLook = { x = math.cos(angleToLook), y = math.sin(angleToLook), @@ -70,7 +70,7 @@ AddEventHandler("esx_skin:playerRegistered", function() end) end) -RegisterNetEvent("esx:playerLoaded", function(_, _, skin) +ESX.SecureNetEvent("esx:playerLoaded", function(_, _, skin) ESX.PlayerLoaded = true TriggerServerEvent("esx_skin:setWeight", skin) end) @@ -97,4 +97,4 @@ end) AddEventHandler("esx_skin:setLastSkin", function(skin) Skin.Last = skin -end) \ No newline at end of file +end) diff --git a/[core]/esx_textui/TextUI.lua b/[core]/esx_textui/TextUI.lua index 756d8f24..a375a74d 100644 --- a/[core]/esx_textui/TextUI.lua +++ b/[core]/esx_textui/TextUI.lua @@ -23,8 +23,8 @@ end exports("TextUI", TextUI) exports("HideUI", HideUI) -RegisterNetEvent("ESX:TextUI", TextUI) -RegisterNetEvent("ESX:HideUI", HideUI) +ESX.SecureNetEvent("ESX:TextUI", TextUI) +ESX.SecureNetEvent("ESX:HideUI", HideUI) if Debug then RegisterCommand("textui:error", function() diff --git a/[core]/skinchanger/client/main.lua b/[core]/skinchanger/client/main.lua index 08dc2a45..81110aef 100644 --- a/[core]/skinchanger/client/main.lua +++ b/[core]/skinchanger/client/main.lua @@ -116,7 +116,7 @@ function SkinChanger:SetHead() if not self.character["grandparents"] then self.character["grandparents"] = 0 end - + SetPedHeadBlendData(self.playerPed, self.character["mom"], self.character["dad"], self.character["grandparents"] , self.character["mom"], self.character["dad"], self.character["grandparents"], face_weight, skin_weight, third_weight, false) @@ -304,4 +304,4 @@ AddEventHandler("skinchanger:getData", function(cb) cb(components, SkinChanger:MaxValues()) end) -SkinChanger:Init() \ No newline at end of file +SkinChanger:Init()