mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
[Adventure] Try to load old save file
- override mismatch
This commit is contained in:
@@ -116,7 +116,7 @@ public class WorldBackground extends Actor {
|
|||||||
sprites = chunksSpritesBackground[x][y];
|
sprites = chunksSpritesBackground[x][y];
|
||||||
if (sprites != null) {
|
if (sprites != null) {
|
||||||
for (Actor sprite : sprites) {
|
for (Actor sprite : sprites) {
|
||||||
stage.GetSpriteGroup().removeActor(sprite);
|
stage.GetBackgroundSprites().removeActor(sprite);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,10 @@ import forge.Forge;
|
|||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
|
import java.io.ObjectStreamClass;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class SaveFileData extends HashMap<String,byte[]>
|
public class SaveFileData extends HashMap<String,byte[]>
|
||||||
@@ -181,7 +183,7 @@ public class SaveFileData extends HashMap<String,byte[]>
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
ByteArrayInputStream stream=new ByteArrayInputStream(get(key));
|
ByteArrayInputStream stream=new ByteArrayInputStream(get(key));
|
||||||
ObjectInputStream objStream=new ObjectInputStream(stream);
|
ObjectInputStream objStream=new DecompressibleInputStream(stream);
|
||||||
return objStream.readObject();
|
return objStream.readObject();
|
||||||
|
|
||||||
} catch (IOException | ClassNotFoundException e) {
|
} catch (IOException | ClassNotFoundException e) {
|
||||||
@@ -327,5 +329,40 @@ public class SaveFileData extends HashMap<String,byte[]>
|
|||||||
return false;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -214,7 +214,11 @@ public class World implements Disposable, SaveFileContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public long getBiome(int x, int y) {
|
public long getBiome(int x, int y) {
|
||||||
return biomeMap[x][height - y];
|
try {
|
||||||
|
return biomeMap[x][height - y];
|
||||||
|
} catch (ArrayIndexOutOfBoundsException e) {
|
||||||
|
return biomeMap[biomeMap.length-1][biomeMap[biomeMap.length-1].length-1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public WorldData getData() {
|
public WorldData getData() {
|
||||||
|
|||||||
Reference in New Issue
Block a user