From 1663497e6c754e5d2880e81af44bdd22a0fbe7f7 Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 29 Oct 2020 19:03:58 -0400 Subject: [PATCH] Better save validation --- core/src/mindustry/content/UnitTypes.java | 1 + core/src/mindustry/editor/DrawOperation.java | 4 ++-- core/src/mindustry/entities/bullet/BulletType.java | 10 ++++++---- core/src/mindustry/io/SaveFileReader.java | 10 ++++++++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/core/src/mindustry/content/UnitTypes.java b/core/src/mindustry/content/UnitTypes.java index bf96d2dcf8..d61e8cf29f 100644 --- a/core/src/mindustry/content/UnitTypes.java +++ b/core/src/mindustry/content/UnitTypes.java @@ -875,6 +875,7 @@ public class UnitTypes implements ContentList{ health = 75; engineOffset = 5.5f; range = 140f; + targetAir = false; weapons.add(new Weapon(){{ y = 0f; diff --git a/core/src/mindustry/editor/DrawOperation.java b/core/src/mindustry/editor/DrawOperation.java index 7910de4892..53134663ea 100755 --- a/core/src/mindustry/editor/DrawOperation.java +++ b/core/src/mindustry/editor/DrawOperation.java @@ -13,7 +13,7 @@ public class DrawOperation{ private MapEditor editor; private LongSeq array = new LongSeq(); - public DrawOperation(MapEditor editor) { + public DrawOperation(MapEditor editor){ this.editor = editor; } @@ -37,7 +37,7 @@ public class DrawOperation{ } } - private void updateTile(int i) { + private void updateTile(int i){ long l = array.get(i); array.set(i, TileOp.get(TileOp.x(l), TileOp.y(l), TileOp.type(l), getTile(editor.tile(TileOp.x(l), TileOp.y(l)), TileOp.type(l)))); setTile(editor.tile(TileOp.x(l), TileOp.y(l)), TileOp.type(l), TileOp.value(l)); diff --git a/core/src/mindustry/entities/bullet/BulletType.java b/core/src/mindustry/entities/bullet/BulletType.java index 8e06cf466e..9b2cb9af02 100644 --- a/core/src/mindustry/entities/bullet/BulletType.java +++ b/core/src/mindustry/entities/bullet/BulletType.java @@ -79,8 +79,10 @@ public abstract class BulletType extends Content{ public boolean backMove = true; /** Bullet range override. */ public float range = -1f; - /** Heal Bullet Percent **/ + /** % of block health healed **/ public float healPercent = 0f; + /** whether to make fire on impact */ + public boolean makeFire = false; //additional effects @@ -158,7 +160,7 @@ public abstract class BulletType extends Content{ } public void hitTile(Bullet b, Building tile, float initialHealth){ - if(status == StatusEffects.burning) { + if(makeFire) { Fires.create(tile.tile); } hit(b); @@ -209,14 +211,14 @@ public abstract class BulletType extends Content{ Damage.status(b.team, x, y, splashDamageRadius, status, statusDuration, collidesAir, collidesGround); } - if(healPercent > 0f) { + if(healPercent > 0f){ indexer.eachBlock(b.team, x, y, splashDamageRadius, other -> other.damaged(), other -> { Fx.healBlockFull.at(other.x, other.y, other.block.size, Pal.heal); other.heal(healPercent / 100f * other.maxHealth()); }); } - if(status == StatusEffects.burning) { + if(makeFire){ indexer.eachBlock(null, x, y, splashDamageRadius, other -> other.team != b.team, other -> { Fires.create(other.tile); }); diff --git a/core/src/mindustry/io/SaveFileReader.java b/core/src/mindustry/io/SaveFileReader.java index 0aef1a19df..85f2d86677 100644 --- a/core/src/mindustry/io/SaveFileReader.java +++ b/core/src/mindustry/io/SaveFileReader.java @@ -2,6 +2,7 @@ package mindustry.io; import arc.struct.*; import arc.struct.ObjectMap.*; +import arc.util.*; import arc.util.io.*; import mindustry.world.*; @@ -60,9 +61,11 @@ public abstract class SaveFileReader{ protected final DataOutputStream dataBytesSmall = new DataOutputStream(byteOutputSmall); protected int lastRegionLength; + protected @Nullable CounterInputStream currCounter; protected void region(String name, DataInput stream, CounterInputStream counter, IORunner cons) throws IOException{ counter.resetCount(); + this.currCounter = counter; int length; try{ length = readChunk(stream, cons); @@ -70,8 +73,8 @@ public abstract class SaveFileReader{ throw new IOException("Error reading region \"" + name + "\".", e); } - if(length != counter.count() - 4){ - throw new IOException("Error reading region \"" + name + "\": read length mismatch. Expected: " + length + "; Actual: " + (counter.count() - 4)); + if(length != counter.count - 4){ + throw new IOException("Error reading region \"" + name + "\": read length mismatch. Expected: " + length + "; Actual: " + (counter.count - 4)); } } @@ -114,8 +117,11 @@ public abstract class SaveFileReader{ /** Reads a chunk of some length. Use the runner for reading to catch more descriptive errors. */ public int readChunk(DataInput input, boolean isShort, IORunner runner) throws IOException{ int length = isShort ? input.readUnsignedShort() : input.readInt(); + int pos = currCounter.count; lastRegionLength = length; runner.accept(input); + + if(pos + length != currCounter.count) throw new IOException("Read length mismatch. Expected: " + length + ", Actual: " + (currCounter.count - pos)); return length; }