Skip to content

Commit

Permalink
Added support for ArkCloudInventory v3
Browse files Browse the repository at this point in the history
  • Loading branch information
Qowyn committed Jun 21, 2017
1 parent 0c55147 commit 1317b08
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/qowyn/ark/ArkCloudInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public ArkCloudInventory(JsonObject object) {
public void readBinary(ArkArchive archive) {
inventoryVersion = archive.getInt();

if (inventoryVersion != 1) {
if (inventoryVersion != 1 && inventoryVersion != 3) {
throw new UnsupportedOperationException("Unknown Cloud Inventory Version " + inventoryVersion);
}

Expand Down
37 changes: 35 additions & 2 deletions src/main/java/qowyn/ark/ArkContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import javax.json.JsonValue.ValueType;
import javax.json.stream.JsonGenerator;

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

public class ArkContainer implements GameObjectContainer {
Expand Down Expand Up @@ -62,6 +63,17 @@ public ArkContainer(ArkArrayUInt8 source) {
readBinary(archive);
}

public ArkContainer(ArkArrayInt8 source) {
ByteBuffer buffer = ByteBuffer.allocateDirect(source.size());

source.forEach(buffer::put);

buffer.clear();

ArkArchive archive = new ArkArchive(buffer);
readBinary(archive);
}

public ArkContainer(JsonArray jsonObjects) {
readJson(jsonObjects);
}
Expand Down Expand Up @@ -169,7 +181,7 @@ public ArrayList<GameObject> getObjects() {
return objects;
}

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

size += objects.stream().mapToInt(object -> object.getSize(false)).sum();
Expand All @@ -191,11 +203,32 @@ public ArkArrayUInt8 toByteArray() {
object.writeProperties(archive, 0);
}

return buffer;

}

public ArkArrayUInt8 toByteArray() {
ByteBuffer buffer = toBuffer();

ArkArrayUInt8 result = new ArkArrayUInt8();

buffer.clear();

for (int n = 0; n < size; n++) {
for (int n = 0; n < buffer.capacity(); n++) {
result.add(buffer.get());
}

return result;
}

public ArkArrayInt8 toSignedByteArray() {
ByteBuffer buffer = toBuffer();

ArkArrayInt8 result = new ArkArrayInt8();

buffer.clear();

for (int n = 0; n < buffer.capacity(); n++) {
result.add(buffer.get());
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/qowyn/ark/arrays/ArkArrayStruct.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ArkArrayStruct(ArkArchive archive, PropertyArray property) {
}

public ArkArrayStruct(JsonArray a, PropertyArray property) {
int size = a.size();
int size = property.getDataSize();

ArkName structType = StructRegistry.mapArrayNameToTypeName(property.getName());
if (structType == null) {
Expand Down

0 comments on commit 1317b08

Please sign in to comment.