Search in sources :

Example 1 with Node

use of info.ata4.util.collection.Node in project disunity by ata4.

the class TypeTreeV1 method writeNode.

private void writeNode(DataWriter out, Node<T> node) throws IOException {
    T type = node.data();
    out.writeStruct(type);
    int numChildren = node.size();
    out.writeInt(numChildren);
    for (Node child : node) {
        writeNode(out, child);
    }
}
Also used : Node(info.ata4.util.collection.Node)

Example 2 with Node

use of info.ata4.util.collection.Node in project disunity by ata4.

the class AssetTypes method printTypeNodeText.

private void printTypeNodeText(Node<? extends Type> node, int level) {
    String indent = StringUtils.repeat("  ", level);
    Type type = node.data();
    output().printf("% 4d: %s%s %s (metaFlag: %x)%n", type.index(), indent, type.typeName(), type.fieldName(), type.metaFlag());
    node.forEach(t -> printTypeNodeText(t, level + 1));
}
Also used : Type(info.ata4.junity.serialize.typetree.Type)

Example 3 with Node

use of info.ata4.util.collection.Node in project disunity by ata4.

the class TypeTreeV3 method writeNode.

private void writeNode(DataWriter out, Node<T> node) throws IOException {
    List<T> types = new ArrayList<>();
    serializeNode(node, types, 0);
    // build string table
    AtomicInteger index = new AtomicInteger();
    Map<String, Integer> localMap = new LinkedHashMap<>();
    Map<String, Integer> commonMap = StringTable.commonStrings(revision.major()).inverse();
    Function<String, Integer> addStringOffset = typeName -> {
        if (commonMap.containsKey(typeName)) {
            return commonMap.get(typeName);
        } else if (localMap.containsKey(typeName)) {
            return localMap.get(typeName);
        } else {
            int stringIndex = index.getAndAdd(typeName.length() + 1);
            localMap.put(typeName, stringIndex);
            return stringIndex;
        }
    };
    // apply string offsets
    types.forEach(type -> {
        type.typeOffset(addStringOffset.apply(type.typeName()));
        type.nameOffset(addStringOffset.apply(type.fieldName()));
    });
    out.writeInt(types.size());
    out.writeInt(index.get());
    for (T type : types) {
        out.writeStruct(type);
    }
    for (String string : localMap.keySet()) {
        out.writeStringNull(string);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BiMap(com.google.common.collect.BiMap) DataWriter(info.ata4.io.DataWriter) Node(info.ata4.util.collection.Node) IOException(java.io.IOException) SerializedFileException(info.ata4.junity.serialize.SerializedFileException) Function(java.util.function.Function) ArrayList(java.util.ArrayList) UnityHash128(info.ata4.junity.UnityHash128) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) DataReader(info.ata4.io.DataReader) UnityVersion(info.ata4.junity.UnityVersion) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with Node

use of info.ata4.util.collection.Node in project disunity by ata4.

the class TypeTreeV3 method read.

@Override
public void read(DataReader in) throws IOException {
    revision = new UnityVersion(in.readStringNull(255));
    attributes = in.readInt();
    embedded = in.readBoolean();
    int numBaseClasses = in.readInt();
    for (int i = 0; i < numBaseClasses; i++) {
        int classID = in.readInt();
        TypeRoot typeRoot = new TypeRoot();
        typeRoot.classID(classID);
        if (classID < 0) {
            UnityHash128 scriptID = new UnityHash128();
            in.readStruct(scriptID);
            typeRoot.scriptID(scriptID);
        }
        UnityHash128 oldTypeHash = new UnityHash128();
        in.readStruct(oldTypeHash);
        typeRoot.oldTypeHash(oldTypeHash);
        if (embedded) {
            Node<T> node = new Node<>();
            readNode(in, node);
            typeRoot.nodes(node);
        }
        typeMap.put(classID, typeRoot);
    }
}
Also used : Node(info.ata4.util.collection.Node) UnityVersion(info.ata4.junity.UnityVersion) UnityHash128(info.ata4.junity.UnityHash128)

Aggregations

Node (info.ata4.util.collection.Node)3 UnityHash128 (info.ata4.junity.UnityHash128)2 UnityVersion (info.ata4.junity.UnityVersion)2 BiMap (com.google.common.collect.BiMap)1 DataReader (info.ata4.io.DataReader)1 DataWriter (info.ata4.io.DataWriter)1 SerializedFileException (info.ata4.junity.serialize.SerializedFileException)1 Type (info.ata4.junity.serialize.typetree.Type)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Function (java.util.function.Function)1