Skip to content

Commit

Permalink
0.8.1
Browse files Browse the repository at this point in the history
Added Component detection
Fixed reading JSON null StringProperty value as "null" String
Fixed ArrayProperty ByteProperty getting turned into ArrayProperty Int8Property
Fixed HibernationEntry object ids
Made Hibernation and dataFilesObjectMap accessible
  • Loading branch information
Qowyn committed Sep 18, 2017
1 parent 9508b7d commit 96a0d6a
Show file tree
Hide file tree
Showing 17 changed files with 277 additions and 111 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>qowyn.ark</groupId>
<artifactId>ark-savegame-toolkit</artifactId>
<version>0.8.0</version>
<version>0.8.1</version>
<packaging>jar</packaging>

<name>ARK Savegame Toolkit</name>
Expand Down
27 changes: 21 additions & 6 deletions src/main/java/qowyn/ark/ArkCloudInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonNode;

import qowyn.ark.properties.Property;
import qowyn.ark.types.ArkName;

public class ArkCloudInventory extends FileFormatBase implements PropertyContainer, GameObjectContainer {
public class ArkCloudInventory extends FileFormatBase implements PropertyContainer, GameObjectContainerMixin {

private int inventoryVersion;

private final ArrayList<GameObject> objects = new ArrayList<>();

private final Map<Integer, Map<List<ArkName>, GameObject>> objectMap = new HashMap<>();

private GameObject inventoryData;

public ArkCloudInventory() {}
Expand Down Expand Up @@ -50,8 +55,10 @@ public void readBinary(ArkArchive archive, ReadingOptions options) {

int objectCount = archive.getInt();

objects.clear();
objectMap.clear();
for (int i = 0; i < objectCount; i++) {
objects.add(new GameObject(archive));
addObject(new GameObject(archive), options.getBuildComponentTree());
}

for (int i = 0; i < objectCount; i++) {
Expand Down Expand Up @@ -112,15 +119,17 @@ public void writeBinary(Path filePath, WritingOptions options) throws FileNotFou
@Override
public void readJson(JsonNode node, ReadingOptions options) {
inventoryVersion = node.path("inventoryVersion").asInt();
objects.clear();

objects.clear();
objectMap.clear();
if (node.hasNonNull("inventoryData")) {
setInventoryData(new GameObject(node.get("inventoryData")));
addObject(new GameObject(node.get("inventoryData")), options.getBuildComponentTree());
inventoryData = objects.get(0);
}

if (node.hasNonNull("objects")) {
for (JsonNode profileObject : node.get("objects")) {
objects.add(new GameObject(profileObject));
for (JsonNode objectNode : node.get("objects")) {
addObject(new GameObject(objectNode), options.getBuildComponentTree());
}
}
}
Expand Down Expand Up @@ -162,10 +171,16 @@ public void setInventoryVersion(int inventoryVersion) {
this.inventoryVersion = inventoryVersion;
}

@Override
public ArrayList<GameObject> getObjects() {
return objects;
}

@Override
public Map<Integer, Map<List<ArkName>, GameObject>> getObjectMap() {
return objectMap;
}

public GameObject getInventoryData() {
return inventoryData;
}
Expand Down
29 changes: 20 additions & 9 deletions src/main/java/qowyn/ark/ArkContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonNode;

import qowyn.ark.arrays.ArkArrayInt8;
import qowyn.ark.arrays.ArkArrayUInt8;
import qowyn.ark.types.ArkName;

public class ArkContainer extends FileFormatBase implements GameObjectContainer {
public class ArkContainer extends FileFormatBase implements GameObjectContainerMixin {

private final ArrayList<GameObject> objects = new ArrayList<>();

private final Map<Integer, Map<List<ArkName>, GameObject>> objectMap = new HashMap<>();

public ArkContainer() {}

public ArkContainer(Path filePath) throws IOException {
Expand Down Expand Up @@ -62,8 +68,10 @@ public ArkContainer(ArkArrayInt8 source) {
public void readBinary(ArkArchive archive, ReadingOptions options) {
int objectCount = archive.getInt();

objects.clear();
objectMap.clear();
for (int i = 0; i < objectCount; i++) {
objects.add(new GameObject(archive));
addObject(new GameObject(archive), options.getBuildComponentTree());
}

for (int i = 0; i < objectCount; i++) {
Expand Down Expand Up @@ -118,20 +126,17 @@ public void writeBinary(Path filePath, WritingOptions options) throws FileNotFou

@Override
public void readJson(JsonNode node, ReadingOptions options) {
objects.clear();

objects.clear();
objectMap.clear();
if (node.isArray()) {
int id = 0;
for (JsonNode jsonObject : node) {
objects.add(new GameObject(jsonObject));
objects.get(id).setId(id++); // Set id and increase afterwards
addObject(new GameObject(jsonObject), options.getBuildComponentTree());
}
} else {
if (node.hasNonNull("objects")) {
int id = 0;
for (JsonNode jsonObject : node.get("objects")) {
objects.add(new GameObject(jsonObject));
objects.get(id).setId(id++); // Set id and increase afterwards
addObject(new GameObject(jsonObject), options.getBuildComponentTree());
}
}
}
Expand All @@ -148,10 +153,16 @@ public void writeJson(JsonGenerator generator, WritingOptions options) throws IO
generator.writeEndArray();
}

@Override
public ArrayList<GameObject> getObjects() {
return objects;
}

@Override
public Map<Integer, Map<List<ArkName>, GameObject>> getObjectMap() {
return objectMap;
}

private ByteBuffer toBuffer() {
int size = Integer.BYTES;

Expand Down
27 changes: 21 additions & 6 deletions src/main/java/qowyn/ark/ArkLocalProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonNode;

import qowyn.ark.properties.Property;
import qowyn.ark.types.ArkName;

public class ArkLocalProfile extends FileFormatBase implements PropertyContainer, GameObjectContainer {
public class ArkLocalProfile extends FileFormatBase implements PropertyContainer, GameObjectContainerMixin {

private static final int UNKNOWN_DATA_2_SIZE = 0xc;

Expand All @@ -26,6 +29,8 @@ public class ArkLocalProfile extends FileFormatBase implements PropertyContainer

private final ArrayList<GameObject> objects = new ArrayList<>();

private final Map<Integer, Map<List<ArkName>, GameObject>> objectMap = new HashMap<>();

private GameObject localProfile;

public ArkLocalProfile() {}
Expand Down Expand Up @@ -66,8 +71,10 @@ public void readBinary(ArkArchive archive, ReadingOptions options) {

int objectCount = archive.getInt();

objects.clear();
objectMap.clear();
for (int i = 0; i < objectCount; i++) {
objects.add(new GameObject(archive));
addObject(new GameObject(archive), options.getBuildComponentTree());
}

for (int i = 0; i < objectCount; i++) {
Expand Down Expand Up @@ -160,15 +167,17 @@ public void writeBinary(Path filePath, WritingOptions options) throws FileNotFou
@Override
public void readJson(JsonNode node, ReadingOptions options) {
localProfileVersion = node.path("localProfileVersion").asInt();
objects.clear();

objects.clear();
objectMap.clear();
if (node.hasNonNull("localProfile")) {
setLocalProfile(new GameObject(node.get("localProfile")));
addObject(new GameObject(node.get("localProfile")), options.getBuildComponentTree());
localProfile = objects.get(0);
}

if (node.hasNonNull("objects")) {
for (JsonNode profileObject : node.get("objects")) {
objects.add(new GameObject(profileObject));
for (JsonNode objectNode : node.get("objects")) {
addObject(new GameObject(objectNode), options.getBuildComponentTree());
}
}

Expand Down Expand Up @@ -233,10 +242,16 @@ public void setLocalProfileVersion(int localProfileVersion) {
this.localProfileVersion = localProfileVersion;
}

@Override
public ArrayList<GameObject> getObjects() {
return objects;
}

@Override
public Map<Integer, Map<List<ArkName>, GameObject>> getObjectMap() {
return objectMap;
}

public GameObject getLocalProfile() {
return localProfile;
}
Expand Down
27 changes: 21 additions & 6 deletions src/main/java/qowyn/ark/ArkProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonNode;

import qowyn.ark.properties.Property;
import qowyn.ark.types.ArkName;

public class ArkProfile extends FileFormatBase implements PropertyContainer, GameObjectContainer {
public class ArkProfile extends FileFormatBase implements PropertyContainer, GameObjectContainerMixin {

private int profileVersion;

private final ArrayList<GameObject> objects = new ArrayList<>();

private final Map<Integer, Map<List<ArkName>, GameObject>> objectMap = new HashMap<>();

private GameObject profile;

public ArkProfile() {}
Expand Down Expand Up @@ -50,8 +55,10 @@ public void readBinary(ArkArchive archive, ReadingOptions options) {

int profilesCount = archive.getInt();

objects.clear();
objectMap.clear();
for (int i = 0; i < profilesCount; i++) {
objects.add(new GameObject(archive));
addObject(new GameObject(archive), options.getBuildComponentTree());
}

for (int i = 0; i < profilesCount; i++) {
Expand Down Expand Up @@ -112,15 +119,17 @@ public void writeBinary(Path filePath, WritingOptions options) throws FileNotFou
@Override
public void readJson(JsonNode node, ReadingOptions options) {
profileVersion = node.path("profileVersion").asInt();
objects.clear();

objects.clear();
objectMap.clear();
if (node.hasNonNull("profile")) {
setProfile(new GameObject(node.get("profile")));
addObject(new GameObject(node.get("profile")), options.getBuildComponentTree());
profile = objects.get(0);
}

if (node.hasNonNull("objects")) {
for (JsonNode tribeObject : node.get("objects")) {
objects.add(new GameObject(tribeObject));
for (JsonNode objectNode : node.get("objects")) {
addObject(new GameObject(objectNode), options.getBuildComponentTree());
}
}
}
Expand Down Expand Up @@ -160,10 +169,16 @@ public void setProfileVersion(int profileVersion) {
this.profileVersion = profileVersion;
}

@Override
public ArrayList<GameObject> getObjects() {
return objects;
}

@Override
public Map<Integer, Map<List<ArkName>, GameObject>> getObjectMap() {
return objectMap;
}

public GameObject getProfile() {
return profile;
}
Expand Down
Loading

0 comments on commit 96a0d6a

Please sign in to comment.