[Adventure] Try to load old save file

- override mismatch
This commit is contained in:
Anthony Calosa
2022-02-27 11:00:28 +08:00
parent b72a991d5c
commit 26f27bdd76
3 changed files with 44 additions and 3 deletions

View File

@@ -116,7 +116,7 @@ public class WorldBackground extends Actor {
sprites = chunksSpritesBackground[x][y];
if (sprites != null) {
for (Actor sprite : sprites) {
stage.GetSpriteGroup().removeActor(sprite);
stage.GetBackgroundSprites().removeActor(sprite);
}
}
}

View File

@@ -9,8 +9,10 @@ import forge.Forge;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamClass;
import java.util.HashMap;
public class SaveFileData extends HashMap<String,byte[]>
@@ -181,7 +183,7 @@ public class SaveFileData extends HashMap<String,byte[]>
try {
ByteArrayInputStream stream=new ByteArrayInputStream(get(key));
ObjectInputStream objStream=new ObjectInputStream(stream);
ObjectInputStream objStream=new DecompressibleInputStream(stream);
return objStream.readObject();
} catch (IOException | ClassNotFoundException e) {
@@ -327,5 +329,40 @@ public class SaveFileData extends HashMap<String,byte[]>
return false;
}
class DecompressibleInputStream extends ObjectInputStream {
//private static Logger logger = LoggerFactory.getLogger(DecompressibleInputStream.class);
public DecompressibleInputStream(InputStream in) throws IOException {
super(in);
}
@Override
protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
ObjectStreamClass resultClassDescriptor = super.readClassDescriptor(); // initially streams descriptor
Class localClass; // the class in the local JVM that this descriptor represents.
try {
localClass = Class.forName(resultClassDescriptor.getName());
} catch (ClassNotFoundException e) {
//logger.error("No local class for " + resultClassDescriptor.getName(), e);
System.err.println("[Class Not Found Exception]\nNo local class for " + resultClassDescriptor.getName());
return resultClassDescriptor;
}
ObjectStreamClass localClassDescriptor = ObjectStreamClass.lookup(localClass);
if (localClassDescriptor != null) { // only if class implements serializable
final long localSUID = localClassDescriptor.getSerialVersionUID();
final long streamSUID = resultClassDescriptor.getSerialVersionUID();
if (streamSUID != localSUID) { // check for serialVersionUID mismatch.
final StringBuffer s = new StringBuffer("Overriding serialized class version mismatch: ");
s.append("local serialVersionUID = ").append(localSUID);
s.append(" stream serialVersionUID = ").append(streamSUID);
//Exception e = new InvalidClassException(s.toString());
//logger.error("Potentially Fatal Deserialization Operation.", e);
System.err.println("[Invalid Class Exception\n]"+s);
resultClassDescriptor = localClassDescriptor; // Use local class descriptor for deserialization
}
}
return resultClassDescriptor;
}
}
}

View File

@@ -214,7 +214,11 @@ public class World implements Disposable, SaveFileContent {
}
public long getBiome(int x, int y) {
try {
return biomeMap[x][height - y];
} catch (ArrayIndexOutOfBoundsException e) {
return biomeMap[biomeMap.length-1][biomeMap[biomeMap.length-1].length-1];
}
}
public WorldData getData() {