From 7ebe84cc0ee8713ea184d49045354e13dbe1c4c7 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 18 Aug 2020 23:42:05 -0400 Subject: [PATCH] Fixed save incompatibility with missing types --- core/src/mindustry/io/SaveFileReader.java | 3 +++ core/src/mindustry/io/SaveVersion.java | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/core/src/mindustry/io/SaveFileReader.java b/core/src/mindustry/io/SaveFileReader.java index 857551860f..07dde7eb8a 100644 --- a/core/src/mindustry/io/SaveFileReader.java +++ b/core/src/mindustry/io/SaveFileReader.java @@ -37,6 +37,8 @@ public abstract class SaveFileReader{ "command-center", "legacy-command-center" ); + protected int lastRegionLength; + protected void region(String name, DataInput stream, CounterInputStream counter, IORunner cons) throws IOException{ counter.resetCount(); int length; @@ -90,6 +92,7 @@ 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(); + lastRegionLength = length; runner.accept(input); return length; } diff --git a/core/src/mindustry/io/SaveVersion.java b/core/src/mindustry/io/SaveVersion.java index 0f7206f500..c3f83b30d8 100644 --- a/core/src/mindustry/io/SaveVersion.java +++ b/core/src/mindustry/io/SaveVersion.java @@ -331,6 +331,11 @@ public abstract class SaveVersion extends SaveFileReader{ for(int j = 0; j < amount; j++){ readChunk(stream, true, in -> { byte typeid = in.readByte(); + if(EntityMapping.map(typeid) == null){ + in.skipBytes(lastRegionLength - 1); + return; + } + Entityc entity = (Entityc)EntityMapping.map(typeid).get(); entity.read(Reads.get(in)); entity.add();