Better save validation
This commit is contained in:
@@ -875,6 +875,7 @@ public class UnitTypes implements ContentList{
|
||||
health = 75;
|
||||
engineOffset = 5.5f;
|
||||
range = 140f;
|
||||
targetAir = false;
|
||||
|
||||
weapons.add(new Weapon(){{
|
||||
y = 0f;
|
||||
|
||||
@@ -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);
|
||||
@@ -216,7 +218,7 @@ public abstract class BulletType extends Content{
|
||||
});
|
||||
}
|
||||
|
||||
if(status == StatusEffects.burning) {
|
||||
if(makeFire){
|
||||
indexer.eachBlock(null, x, y, splashDamageRadius, other -> other.team != b.team, other -> {
|
||||
Fires.create(other.tile);
|
||||
});
|
||||
|
||||
@@ -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<DataInput> 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<DataInput> 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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user