🐛 Validate tile IDs in static insertion

Sub-4000 filter entries underflowed to huge tile IDs, and placing
on top of statics with corrupt IDs indexed past the tiledata array.
This commit is contained in:
2026-11-15 22:08:32 +01:00
parent 8731ec150c
commit 6df8df9a9b
+8 -2
View File
@@ -340,14 +340,17 @@ procedure TLSInsertStatics.Apply(AMapCell: TMapCell; AStatics: TStaticItemList;
var var
staticItem, static: TStaticItem; staticItem, static: TStaticItem;
topZ, staticTop: ShortInt; topZ, staticTop: ShortInt;
i: Integer; i, tileID: Integer;
begin begin
if (Length(FTileIDs) = 0) or (Random(100) >= FProbability) then Exit; if (Length(FTileIDs) = 0) or (Random(100) >= FProbability) then Exit;
tileID := FTileIDs[Random(Length(FTileIDs))];
if tileID < $4000 then Exit;
staticItem := TStaticItem.Create(nil, nil, 0, 0); staticItem := TStaticItem.Create(nil, nil, 0, 0);
staticItem.X := AMapCell.X; staticItem.X := AMapCell.X;
staticItem.Y := AMapCell.Y; staticItem.Y := AMapCell.Y;
staticItem.TileID := FTileIDs[Random(Length(FTileIDs))] - $4000; staticItem.TileID := tileID - $4000;
staticItem.Hue := 0; staticItem.Hue := 0;
case FPlacementType of case FPlacementType of
@@ -361,12 +364,15 @@ begin
for i := 0 to AStatics.Count - 1 do for i := 0 to AStatics.Count - 1 do
begin begin
static := AStatics[i]; static := AStatics[i];
if static.TileID < Integer(CEDServerInstance.Landscape.TiledataProvider.StaticCount) then
begin
staticTop := EnsureRange(static.Z + staticTop := EnsureRange(static.Z +
CEDServerInstance.Landscape.TiledataProvider.StaticTiles[static.TileID].Height, CEDServerInstance.Landscape.TiledataProvider.StaticTiles[static.TileID].Height,
-128, 127); -128, 127);
if staticTop > topZ then topZ := staticTop; if staticTop > topZ then topZ := staticTop;
end; end;
end; end;
end;
spFix: spFix:
begin begin
staticItem.Z := FFixZ; staticItem.Z := FFixZ;