From 82d255c5d0ea52070d0a8c9dbe1a3003ee3171f3 Mon Sep 17 00:00:00 2001 From: Wofsauge Date: Mon, 15 Apr 2024 19:36:37 +0200 Subject: [PATCH] Added better sanity check for entity object accesses --- eid_api.lua | 13 ++++++++++--- eid_data.lua | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/eid_api.lua b/eid_api.lua index f8cf0f7b..2b2663c2 100644 --- a/eid_api.lua +++ b/eid_api.lua @@ -652,8 +652,10 @@ end -- check if an entity is part of the describable entities function EID:hasDescription(entity) - if entity and EID:IsGridEntity(entity) then - if entity and EID.GridEntityWhitelist[entity:GetType()] then + if not EID:EntitySanityCheck(entity) then return false end + + if EID:IsGridEntity(entity) then + if EID.GridEntityWhitelist[entity:GetType()] then for _, func in ipairs(EID.GridEntityWhitelist[entity:GetType()]) do if func(entity) then return true @@ -1431,7 +1433,7 @@ function EID:getScreenSize() end function EID:getEntityData(entity, str) - if entity ~= nil and not EID:IsGridEntity(entity) and entity:GetData() ~= nil then + if EID:EntitySanityCheck(entity) and not EID:IsGridEntity(entity) and entity:GetData() ~= nil then return entity:GetData()[str] end return nil @@ -1927,6 +1929,11 @@ function EID:IsGridEntity(entity) return entity.Type == nil end +-- Returns true, if the given entity is a valid game object and actually is something useful to process. Sometimes the game sends weird shit so this function is needed to catch bullshit +function EID:EntitySanityCheck(entity) + return entity ~= nil and type(entity) == "userdata" +end + -- returns true if the given pill color was used at least once in this game function EID:WasPillUsed(pillColor) return EID.UsedPillColors[tostring(pillColor)] ~= nil diff --git a/eid_data.lua b/eid_data.lua index 1f512014..ca2d6b44 100644 --- a/eid_data.lua +++ b/eid_data.lua @@ -899,7 +899,7 @@ EID.ItemPoolTypeToMarkup = { [0] = "{{ItemPoolTreasure}}", "{{ItemPoolShop}}", " -- If a function returns a value, it will be used as the offset EID.LocalModePositionOffset = { Default = Vector(0, 20), - Shop = function(entity) if entity and not EID:IsGridEntity(entity) and entity:ToPickup() and entity:ToPickup():IsShopItem() then return Vector(0, 35) end end, + Shop = function(entity) if EID:EntitySanityCheck(entity) and not EID:IsGridEntity(entity) and entity:ToPickup() and entity:ToPickup():IsShopItem() then return Vector(0, 35) end end, } -- Character IDs that aren't allowed to have Red Health: ???, The Lost, The Soul