Fix deserializing to a smaller inventory

Void excess slots when deserializing an inventory to a target that has
fewer slots than what was serialized.  This fixs inventory sync failing
when a stored inventory has trash slots in use but the player does not
have the slots unlocked.
This commit is contained in:
Hornwitser committed 2022-06-08 22:26:08 +02:00
1 parent 2a221456d9
commit 54897c1447
1 file changed
+4 -1
@@ -281,8 +281,11 @@ function serialize.deserialize_inventory(inventory, serialized)
local repeat_count = entry.r or 0
for offset = 0, repeat_count do
-- XXX what if the inventory is smaller on this instance?
local index = base_index + offset
if index > #inventory then
print("Error: Inventory index out of bounds deserializing inventory, voiding excess slots")
break
end
local slot = inventory[index]
if entry.f then
local call_success, call_return = pcall(inventory.set_filter, index, entry.f)