@@ -417,6 +417,21 @@ versions[5] = function(encodedDupe)
417417 return deserialize (decompress (dupestring ), read5 ), info
418418end
419419
420+
421+ function AdvDupe2 .CheckValidDupe (dupe , info )
422+ if not dupe .HeadEnt then return false , " Missing HeadEnt table" end
423+ if not dupe .HeadEnt .Index then return false , " Missing HeadEnt.Index" end
424+ if not dupe .HeadEnt .Z then return false , " Missing HeadEnt.Z" end
425+ if not dupe .HeadEnt .Pos then return false , " Missing HeadEnt.Pos" end
426+ if not dupe .Entities then return false , " Missing Entities table" end
427+ if not dupe .Entities [dupe .HeadEnt .Index ] then return false , " Missing HeadEnt index from Entities table" end
428+ if not dupe .Entities [dupe .HeadEnt .Index ].PhysicsObjects then return false , " Missing PhysicsObject table from HeadEnt Entity table" end
429+ if not dupe .Entities [dupe .HeadEnt .Index ].PhysicsObjects [0 ] then return false , " Missing PhysicsObject[0] table from HeadEnt Entity table" end
430+ if not dupe .Entities [dupe .HeadEnt .Index ].PhysicsObjects [0 ].Pos then return false , " Missing PhysicsObject[0].Pos from HeadEnt Entity table" end
431+ if not dupe .Entities [dupe .HeadEnt .Index ].PhysicsObjects [0 ].Angle then return false , " Missing PhysicsObject[0].Angle from HeadEnt Entity table" end
432+ return true , dupe
433+ end
434+
420435--[[
421436 Name: Decode
422437 Desc: Generates the table for a dupe from the given string. Inverse of Encode
@@ -437,6 +452,8 @@ function AdvDupe2.Decode(encodedDupe)
437452 if sig == " [Inf" then -- legacy support, ENGAGE (AD1 dupe detected)
438453 local success , tbl , info , moreinfo = pcall (AdvDupe2 .LegacyDecoders [0 ], encodedDupe )
439454
455+ success , tbl = AdvDupe2 .CheckValidDupe (tbl , info )
456+
440457 if success then
441458 info .size = # encodedDupe
442459 info .revision = 0
@@ -455,13 +472,15 @@ function AdvDupe2.Decode(encodedDupe)
455472 return false , format (" attempt to use an invalid format revision (rev %d)" , rev )
456473 else
457474 local success , tbl , info = pcall (versions [rev ], encodedDupe )
475+
476+ success , tbl = AdvDupe2 .CheckValidDupe (tbl , info )
458477
459478 if success then
460479 info .revision = rev
461480 else
462481 ErrorNoHalt (tbl )
463482 end
464-
483+
465484 return success , tbl , info
466485 end
467486end
0 commit comments