From 672dd7684b3b75ef0225c546544d75cf181ca4b1 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Fri, 3 Oct 2025 13:51:15 +0100 Subject: [PATCH 1/8] Fix ESX authtoken callback saying possible exploit --- shared/_authToken.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/shared/_authToken.lua b/shared/_authToken.lua index e42aa89..abe8ee3 100644 --- a/shared/_authToken.lua +++ b/shared/_authToken.lua @@ -7,14 +7,22 @@ AuthEvent = nil currentToken = nil if isServer() then + local excludeRes = { + [Exports.QBExport] = true, + [Exports.ESXExport] = true, + [Exports.VorpExport] = true, + } + local AuthEvent = getScript()..":"..keyGen()..keyGen()..keyGen()..keyGen()..":"..keyGen()..keyGen()..keyGen()..keyGen() validTokens = validTokens or {} createCallback(AuthEvent, function(source) local src = source local token = keyGen()..keyGen()..keyGen()..keyGen() -- Use a secure random generator here - --debugPrint(GetInvokingResource()) - if GetInvokingResource() and GetInvokingResource() ~= getScript() and GetInvokingResource() ~= Exports.QBExport and GetInvokingResource() ~= Exports.VorpExport then + local invokingRes = GetInvokingResource() + + debugPrint(invokingRes) + if invokingRes and invokingRes ~= getScript() and not excludeRes[invokingRes] then debugPrint("^1Error^7: ^1Possible exploit^7, ^1vital function was called from an external resource^7") return "" end @@ -47,9 +55,9 @@ if isServer() then createCallback(getScript()..":callback:GetAuthEvent", function(source) local src = source - --debugPrint(GetInvokingResource()) + local invokingRes = GetInvokingResource() - if GetInvokingResource() and GetInvokingResource() ~= getScript() and GetInvokingResource() ~= Exports.QBExport and GetInvokingResource() ~= Exports.VorpExport then + if invokingRes and invokingRes ~= getScript() and not excludeRes[invokingRes] then debugPrint("^1Error^7: ^1Possible exploit^7, ^1vital callback was called from an external resource^7") return "" end From 0bc3c0f9b4df8cf9d652ed4ea56b4857dd12af3d Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Fri, 3 Oct 2025 17:44:29 +0100 Subject: [PATCH 2/8] Update itemcontrol.lua --- shared/itemcontrol.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/shared/itemcontrol.lua b/shared/itemcontrol.lua index 85a2c41..a6275bc 100644 --- a/shared/itemcontrol.lua +++ b/shared/itemcontrol.lua @@ -1338,10 +1338,12 @@ end --- ``` function getPlayerInv(src) local grabInv = nil + local foundInv = "" for i = 1, #InvFunc do local inv = InvFunc[i] if isStarted(inv.invName) then + foundInv = inv.invName grabInv = inv.getPlayerInv(src) break end @@ -1364,6 +1366,7 @@ function getPlayerInv(src) grabInv = xPlayer and xPlayer.inventory or {} end end + --jsonPrint(grabInv) end if grabInv == nil then @@ -1958,7 +1961,7 @@ function getCurrentInvWeight(src) if weight == 0 then local itemcheck = getPlayerInv(src) for _, v in pairs(itemcheck) do - weight += ((v.weight * v.amount) or 0) + weight += ((v.weight * (v.amount or v.count)) or 0) end end return weight @@ -2356,6 +2359,8 @@ function stashRemoveItem(stashItems, stashName, items) return end end + + -- Fallback to core functions if isStarted(QBExport) then local stashItems = getStash(stashName[1]) for k, v in pairs(items) do @@ -2382,6 +2387,10 @@ function stashRemoveItem(stashItems, stashName, items) end RegisterNetEvent(getScript()..":server:stashRemoveItem", stashRemoveItem) +function stashAddItem(stashItems, stashName, items) + -- wip +end + ------------------------------------------------------------- -- Stash Item Availability Check ------------------------------------------------------------- From 63bcb86ac1c1002577893ffa3875acab33d5f406 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Sat, 4 Oct 2025 01:31:14 +0100 Subject: [PATCH 3/8] ESX Fallback functions are very basic. There aren't many native functions for what the script can do, if anyone has any better ideas - go to `itemcontrol.lua` - search `ESX` and tell me what could be done better/right --- shared/itemcontrol.lua | 59 ++++++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/shared/itemcontrol.lua b/shared/itemcontrol.lua index a6275bc..4d7da3d 100644 --- a/shared/itemcontrol.lua +++ b/shared/itemcontrol.lua @@ -1304,14 +1304,26 @@ function hasItem(items, amount, src) -- Fallback to default hasItem function if not hasTable or not next(hasTable) then - for item, amt in pairs(items) do - local count = 0 - for _, itemData in pairs(grabInv) do - if itemData and itemData.name == item then - count += (itemData.amount or itemData.count or 1) + if isStarted(ESXExport) then + for item, amt in pairs(items) do + local count = 0 + for itemName, amount in pairs(grabInv) do + if itemName and itemName == item then + count += (amount or 1) + end end + hasTable[item] = { hasItem = count >= amt, count = count } + end + else + for item, amt in pairs(items) do + local count = 0 + for _, itemData in pairs(grabInv) do + if itemData and itemData.name == item then + count += (itemData.amount or itemData.count or 1) + end + end + hasTable[item] = { hasItem = count >= amt, count = count } end - hasTable[item] = { hasItem = count >= amt, count = count } end end @@ -1362,8 +1374,7 @@ function getPlayerInv(src) local xPlayer = ESX.GetPlayerFromId(src) grabInv = xPlayer and xPlayer.getInventory() or {} else - local xPlayer = ESX.GetPlayerData() - grabInv = xPlayer and xPlayer.inventory or {} + grabInv = triggerCallback(getScript()..":GetESXInv") end end --jsonPrint(grabInv) @@ -1375,6 +1386,15 @@ function getPlayerInv(src) return grabInv, foundInv end +if isServer() then + createCallback(getScript()..":GetESXInv", function(source) + local src = source + local xPlayer = ESX.GetPlayerFromId(src) + local inv = xPlayer.getInventory() + return xPlayer.getInventory(src) + end) +end + function isInventoryOpen() return IsNuiFocused() @@ -1559,14 +1579,21 @@ end RegisterNetEvent(getScript()..":server:toggleItem", function(give, item, amount, newsrc, info, slot, token) + local excludeRes = { + [QBExport] = true, + [ESXExport] = true, + [VorpExport] = true, + } + local invokingRes = GetInvokingResource() + --debugPrint(GetInvokingResource()) - if GetInvokingResource() and GetInvokingResource() ~= getScript() and GetInvokingResource() ~= "qb-core" then + if invokingRes and invokingRes ~= getScript() and not excludeRes[invokingRes] then debugPrint("^1Error^7: ^1Possible exploit^7, ^1vital function was called from an external resource^7") return end - if not Items[item] then - print("^6Bridge^7: ^1Error^7 - ^2Tried to "..(tostring(give) == "true" and "add" or "remove").." '^3"..item.."^7' but it doesn't exist") + if not doesItemExist(item) then + print("^1Error^7 - ^2Tried to "..(tostring(give) == "true" and "add" or "remove").." '^3"..item.."^7' but it doesn't exist") return end @@ -1960,8 +1987,14 @@ function getCurrentInvWeight(src) -- fallback function if weight == 0 then local itemcheck = getPlayerInv(src) - for _, v in pairs(itemcheck) do - weight += ((v.weight * (v.amount or v.count)) or 0) + if isStarted(ESXExport) then + for _, amount in pairs(itemcheck) do + weight += (amount or 0) + end + else + for _, v in pairs(itemcheck) do + weight += ((v.weight * (v.amount or v.count)) or 0) + end end end return weight From 803c612cbb952682bf6f04635015b9961bbd4123 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Sat, 4 Oct 2025 19:12:50 +0100 Subject: [PATCH 4/8] Change stress to take away instead of increase --- shared/playerfunctions.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shared/playerfunctions.lua b/shared/playerfunctions.lua index 8cc5615..87f9b64 100644 --- a/shared/playerfunctions.lua +++ b/shared/playerfunctions.lua @@ -86,7 +86,7 @@ local hungerThirstFunc = { setStress = function(src, stress) local Player = Core.Functions.GetPlayer(src) - local newStress = Player.PlayerData.metadata.stress + stress + local newStress = Player.PlayerData.metadata.stress - stress newStress = (newStress >= 100.0 and 100.0) or (newStress <= 0 and 0) or newStress Player.Functions.SetMetaData('stress', newStress) TriggerClientEvent('hud:client:UpdateStress', src, newStress) @@ -187,10 +187,10 @@ end) --- Server event handler for setting player needs (thirst or hunger). --- --- @event ---- @param type string "thirst" or "hunger". +--- @param needType string "thirst" or "hunger". --- @param amount number New value to set. RegisterNetEvent(getScript()..":server:setNeed", function(needType, amount) - print("^1Deprecated function ':server:setNeed' called, please update your scripts^7") + print("^1Deprecated function ':server:setNeed' called, please update the scripts that use it^7") -- local src = source -- if needType == "thirst" then -- setThirst(src, amount) From 45f390c177ea9276b168d1d6f4390bc299cd4529 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Sat, 4 Oct 2025 22:10:39 +0100 Subject: [PATCH 5/8] Update playerfunctions.lua --- shared/playerfunctions.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/playerfunctions.lua b/shared/playerfunctions.lua index 87f9b64..768778c 100644 --- a/shared/playerfunctions.lua +++ b/shared/playerfunctions.lua @@ -32,7 +32,7 @@ local hungerThirstFunc = { setStress = function(src, stress) local Player = Core.Functions.GetPlayer(src) - local newStress = Player.PlayerData.metadata.stress + stress + local newStress = Player.PlayerData.metadata.stress - stress newStress = (newStress >= 100.0 and 100.0)or (newStress <= 0 and 0) or newStress Player.Functions.SetMetaData('stress', newStress) TriggerClientEvent('hud:client:UpdateStress', src, newStress) @@ -59,7 +59,7 @@ local hungerThirstFunc = { setStress = function(src, stress) local Player = Core.Functions.GetPlayer(src) - local newStress = Player.PlayerData.metadata.stress + stress + local newStress = Player.PlayerData.metadata.stress - stress newStress = (newStress >= 100.0 and 100.0)or (newStress <= 0 and 0) or newStress Player.Functions.SetMetaData('stress', newStress) TriggerClientEvent('hud:client:UpdateStress', src, newStress) From 9a78b057ddfb69cd2cb278f661d9c4208d8dffcf Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Mon, 6 Oct 2025 02:15:19 +0100 Subject: [PATCH 6/8] Create alcohol.lua Starting a "alcohol/drug" file to handle alcohol effects between scripts using exports to keep the "amount drunk/used" synchronized between scripts that use jim_bridge --- ui_modules/alcohol.lua | 289 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 289 insertions(+) create mode 100644 ui_modules/alcohol.lua diff --git a/ui_modules/alcohol.lua b/ui_modules/alcohol.lua new file mode 100644 index 0000000..84d1df6 --- /dev/null +++ b/ui_modules/alcohol.lua @@ -0,0 +1,289 @@ +local alcoholCount = 0 +local drugCount = 0 +local purgeTimer = 300000 + +local minDrugCount = 3 +local maxDrugCount = 7 + +local minAlcoholCount = 2 +local midAlcoholCount = 4 +local maxAlcoholCount = 7 + +local alcoholEffectData = { + levels = { + ["min"] = { + effect = "DrugsMichaelAliensFight", + movement = "move_m@drunk@slightlydrunk", + camShake = 0.5, + canStumble = false, + }, + ["mid"] = { + effect = "DrugsMichaelAliensFight", + movement = "move_m@drunk@moderatedrunk", + canRagdoll = true, + camShake = 0.5, + canStumble = true, + stumbleChance = 0.8, + drunkDriving = true, + }, + ["max"] = { + effect = "DrugsMichaelAliensFight", + movement = "move_m@drunk@verydrunk", + canRagdoll = true, + camShake = 2.8, + canStumble = true, + stumbleChance = 0.6, + drunkDriving = true, + }, + }, +} + +local drugEffectData = { + levels = { + ["min"] = { + --effect = "SwitchHUDTrevorIn", + --movement = "move_m@drunk@slightlydrunk", + }, + ["max"] = { + effect = "SwitchHUDTrevorIn", + movement = "move_m@drunk@slightlydrunk", + camShake = 0.2, + }, + } + +} + +-- Alcohol Thread +function addAlocholCount(count, canOD) + alcoholCount = alcoholCount + count + --print("Alcohol count increased, current amount:", alcoholCount) + CreateThread(function() + runAlcoholThread() + end) + if alcoholCount >= maxAlcoholCount then + -- max + startAlcoholEffect(alcoholEffectData.levels["max"], "max") + if canOD then + SetEntityHealth(PlayerPedId(), GetEntityHealth(PlayerPedId()) - math.random(10, 15)) + end + elseif alcoholCount < maxAlcoholCount and alcoholCount >= midAlcoholCount then + -- mid + startAlcoholEffect(alcoholEffectData.levels["mid"], "mid") + TriggerEvent("evidence:client:SetStatus", "heavyalcohol", 200) + if canOD then + SetEntityHealth(PlayerPedId(), GetEntityHealth(PlayerPedId()) - math.random(5, 10)) + end + elseif alcoholCount >= 1 then + -- min + TriggerEvent("evidence:client:SetStatus", "alcohol", 200) + startAlcoholEffect(alcoholEffectData.levels["min"], "min") + end +end + +function getAlcoholCount() + return alcoholCount +end + +function removeAlcoholCount(count) + alcoholCount = alcoholCount - count + if alcoholCount < minAlcoholCount then + clearCurrentAlcoholEffect() + end + --print("Alcohol count decreased, current amount:", alcoholCount) +end + +local alcoholThreadRun = false +function runAlcoholThread() + if alcoholThreadRun == true then + return + else + alcoholThreadRun = true + end + --print("Alcohol Thread triggered") + while alcoholCount > 0 do + Wait(purgeTimer) + removeAlcoholCount(1) + if alcoholCount <= 0 then + clearCurrentAlcoholEffect() + alcoholThreadRun = false + break + end + end +end + +exports("getAlcoholCount",getAlcoholCount) +exports("addAlocholCount", addAlocholCount) +exports("removeAlcoholCount", removeAlcoholCount) + + +-- EFFECT Management + +local currentAlcoholEffect = "" +local alcoholEffect = "" + +function clearCurrentAlcoholEffect() + local Ped = PlayerPedId() + if alcoholEffect ~= "" then + AnimpostfxStop(alcoholEffect) + ResetPedMovementClipset(Ped, 0.0) + ClearTimecycleModifier() + ResetScenarioTypesEnabled() + SetPedIsDrunk(Ped, false) + SetPedMotionBlur(Ped, false) + end + currentAlcoholEffect = "" + alcoholEffect = "" +end + +function startAlcoholEffect(data, level) + local Ped = PlayerPedId() + if currentAlcoholEffect == level then + return + else + clearCurrentAlcoholEffect() + currentAlcoholEffect = level + end + + -- Start effect using sent data + if alcoholEffect ~= data.effect then + alcoholEffect = data.effect + AnimpostfxPlay(data.effect, 0, true) + if data.movement then + RequestAnimSet(data.movement) + while not HasAnimSetLoaded(data.movement) do + Wait(100) + end + SetPedMovementClipset(Ped, data.movement, 3.0) + end + SetPedCanRagdoll(Ped, true) + if data.camShake then + ShakeGameplayCam("DRUNK_SHAKE", data.camShake) + end + SetTimecycleModifier("Drunk") + SetPedMotionBlur(Ped, true) + SetPedIsDrunk(Ped, true) + + if data.drivingEffect or data.canStumble then + + CreateThread(function() + local effectCheck = level + local lastStumbleTime = GetGameTimer() + 1200 + local lastDriveTime = GetGameTimer() + 6000 + while effectCheck == currentAlcoholEffect do + if data.camStumble and GetGameTimer() > lastStumbleTime and math.random() > (data.stumbleChance or 0.8) then + lastStumbleTime = GetGameTimer() + 1200 + SetPedToRagdoll(Ped, 5000, 5000, 0, true, true, false) + end + if data.driving and GetGameTimer() > lastDriveTime then + local inVeh, veh, seat = GetSeatPedIsIn() + if inVeh then + lastDriveTime = GetGameTimer() + 6000 + if seat == -1 then + if math.random() < 0.62 then + StartVehicleHorn(veh, 1000, "NORMAL", false) + end + end + end + end + Wait(1000) + end + print("Effect loop broken") + end) + + end + end +end + +-- Helper +function GetSeatPedIsIn() + local inVeh, veh, seat = false, 0, 0 + local veh = GetVehiclePedIsIn(PlayerPedId(), false) + if veh ~= 0 then + if GetPedInVehicleSeat(veh, -1) == PlayerPedId() then + inVeh = true + seat = -1 + end + end + return inVeh, veh, seat +end + + +-- Drug thread +function addDrugCount(count, canOD) + drugCount = drugCount + count + --print("Drug count increased, current amount:", drugCount) + if drugCount >= minDrugCount and drugCount <= maxDrugCount then + startDrugEffect(drugEffectData.levels["min"], "min") + elseif drugCount > maxDrugCount then + if canOD then + SetEntityHealth(PlayerPedId(), GetEntityHealth(PlayerPedId()) - math.random(10, 15)) + end + startDrugEffect(drugEffectData.levels["max"], "max") + end +end + +function getDrugCount() + return drugCount +end + +function removeDrugCount(count) + --print("Drug count decreased, current amount:", drugCount) + drugCount = drugCount - count +end + +local drugThreadRun = false +function runDrugThread() + if drugThreadRun == true then + return + else + drugThreadRun = true + end + --print("Drug Thread triggered") + while drugCount > 0 do + Wait(purgeTimer) + removeDrugCount(1) + if drugCount <= 0 then + drugThreadRun = false + break + end + end +end + +exports("getDrugCount", getDrugCount) +exports("addDrugCount", addDrugCount) +exports("removeDrugCount", removeDrugCount) + + +-- EFFECT Management + +local currentDrugEffect = "" +local drugEffect = "" +function startDrugEffect(data, level) + local Ped = PlayerPedId() + if currentDrugEffect == level then + return + else + clearCurrentAlcoholEffect() + currentDrugEffect = level + end + + -- Start effect using sent data + if drugEffect ~= data.effect then + drugEffect = data.effect + AnimpostfxPlay(data.effect, 0, true) + if data.movement then + RequestAnimSet(data.movement) + while not HasAnimSetLoaded(data.movement) do + Wait(100) + end + SetPedMovementClipset(Ped, data.movement, 3.0) + end + SetPedCanRagdoll(Ped, true) + if data.camShake then + ShakeGameplayCam("DRUNK_SHAKE", data.camShake) + end + SetTimecycleModifier("Drunk") + SetPedMotionBlur(Ped, true) + SetPedIsDrunk(Ped, true) + end +end \ No newline at end of file From 03ca409bf3f66d896060ec9332d2bbe7bb0bcde0 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Mon, 6 Oct 2025 02:28:30 +0100 Subject: [PATCH 7/8] Fix AnimSet loading for effects --- shared/effects.lua | 5 ++++- ui_modules/alcohol.lua | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/shared/effects.lua b/shared/effects.lua index 353aef1..1503af3 100644 --- a/shared/effects.lua +++ b/shared/effects.lua @@ -7,7 +7,10 @@ function AlienEffect() Wait(math.random(5000, 8000)) local Ped = PlayerPedId() local animDict = "MOVE_M@DRUNK@VERYDRUNK" - loadAnimDict(animDict) + RequestAnimSet(animDict) + while not HasAnimSetLoaded(animDict) do + Wait(100) + end SetPedCanRagdoll(Ped, true) ShakeGameplayCam('DRUNK_SHAKE', 2.80) SetTimecycleModifier("Drunk") diff --git a/ui_modules/alcohol.lua b/ui_modules/alcohol.lua index 84d1df6..93ba1af 100644 --- a/ui_modules/alcohol.lua +++ b/ui_modules/alcohol.lua @@ -12,13 +12,13 @@ local maxAlcoholCount = 7 local alcoholEffectData = { levels = { ["min"] = { - effect = "DrugsMichaelAliensFight", + effect = "DrugsMichaelAliensFightIn", movement = "move_m@drunk@slightlydrunk", camShake = 0.5, canStumble = false, }, ["mid"] = { - effect = "DrugsMichaelAliensFight", + effect = "DrugsMichaelAliensFightIn", movement = "move_m@drunk@moderatedrunk", canRagdoll = true, camShake = 0.5, @@ -27,7 +27,7 @@ local alcoholEffectData = { drunkDriving = true, }, ["max"] = { - effect = "DrugsMichaelAliensFight", + effect = "DrugsMichaelAliensFightIn", movement = "move_m@drunk@verydrunk", canRagdoll = true, camShake = 2.8, @@ -187,7 +187,7 @@ function startAlcoholEffect(data, level) end Wait(1000) end - print("Effect loop broken") + --print("Effect loop broken") end) end From 2404fff0023bb0bf98dd7618e8c9bf6ce5365a0e Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Mon, 6 Oct 2025 02:33:37 +0100 Subject: [PATCH 8/8] Version Bump `2.1.05` - `2.1.06` --- fxmanifest.lua | 2 +- version.txt | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/fxmanifest.lua b/fxmanifest.lua index 74bbf3a..378e2bb 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -1,6 +1,6 @@ name "Jim_Bridge" author "Jimathy" -version "2.1.05" +version "2.1.06" description "Framework Bridge By Jimathy" fx_version "cerulean" rdr3_warning 'I acknowledge that this is a prerelease build of RedM, and I am aware my resources *will* become incompatible once RedM ships.' diff --git a/version.txt b/version.txt index a3e3140..d40eed8 100644 --- a/version.txt +++ b/version.txt @@ -1,7 +1,8 @@ -2.1.05 +2.1.06 -- Fix "true/false" print from built-in gta progressbars -- Revert Crafting system to previous style (I was too quick to do this) -- Fix singleprogress multiplying crafting recipes +- Fix stress calculations adding instead of taking away +- Add basic support for fallback functions for inventory management (esx isn't very well supported currently) +- Create ui_modules/alcohol.lua to handle alcohol and drug effects between scripts +- Fix AnimSet loading for "AlienEffect()" https://github.com/jimathy/jim_bridge/releases/latest \ No newline at end of file