private void postProcessObjectNode(FieldNode fieldNode) { // convert byte buffers to string instances in "string" fields for convenience if (fieldNode.typenode == null || fieldNode.typenode.type == null) { return; } if (fieldNode.typenode.type == "string") { // strings use "char" arrays, so it should be wrapped in a ByteBuffer //ByteBuffer buf = fieldNode.getArrayData<ByteBuffer>(); object arrayobj = fieldNode.getArrayData(); if (arrayobj != null && arrayobj is ByteBuffer) { ByteBuffer buf = (ByteBuffer)arrayobj; char[] carray = new char[buf.data.Length]; for (int i = 0; i < carray.Length; i++) { carray[i] = (char)buf.data[i]; } fieldNode.value = new String(carray);//, "UTF-8" fieldNode.cleanChilds(); } } else if (fieldNode.typenode.isArray) { int size = fieldNode.getSInt32("size"); fieldNode.value = fieldNode.getObject("data"); } else if (fieldNode.typenode.type.StartsWith("PPtr<") && fieldNode.typenode.type.EndsWith(">")) { object obj = new PPtrObject(); fillobject(obj, fieldNode); fieldNode.cleanChilds(); } else if (fieldNode.typenode.type == "Quaternionf" || fieldNode.typenode.type == "Vector3f" || fieldNode.typenode.type == "PackedBitVector" || fieldNode.typenode.type == "VertexData" || fieldNode.typenode.type == "UnityPropertySheet" || fieldNode.typenode.type == "AssetInfo" || fieldNode.typenode.type == "ResourceManager_Dependency") { System.Type t = System.Type.GetType("AssetEx." + fieldNode.typenode.type, false, false); System.Reflection.ConstructorInfo ci = t.GetConstructor(new Type[] { }); object v = ci.Invoke(new object[] { }); fillobject(v, fieldNode); fieldNode.cleanChilds(); } else if (fieldNode.typenode.type == "map") { List <FieldNode> childnodes = (List <FieldNode>)fieldNode.getArrayData(); Dictionary <object, object> map = new Dictionary <object, object>(); foreach (FieldNode fn in childnodes) { object first = fn.getObject("first"); object second = fn.getObject("second"); if (first != null && second != null) { map[first] = second; } } fieldNode.value = map; fieldNode.cleanChilds(); } else if (fieldNode.typenode.type == "vector") { object obj = fieldNode.getArrayData(); if (obj is List <FieldNode> ) { List <FieldNode> childnodes = (List <FieldNode>)obj; List <object> vectorl = new List <object>(); foreach (FieldNode fn in childnodes) { if (fn.value != null) { vectorl.Add(fn.value); } else { vectorl.Add(fn); } } fieldNode.value = vectorl; fieldNode.cleanChilds(); } else { fieldNode.value = obj; fieldNode.cleanChilds(); } } else if (fieldNode.getChilds() != null && fieldNode.getChilds().Count == 1) { fieldNode.value = fieldNode.getArrayData(); if (fieldNode.value != null) { fieldNode.cleanChilds(); } } }
public void setObject(String name, FieldNode v) { setChildValue(name, v); }
//throws IOException private FieldNode readObject(DataReader inr, TypeNode typeNode) { if (typeNode == null) { return(null); } //if (DEBUG) //{ // System.out.printf("%s0x%x: %s v: %d, f: 0x%x, s: %d\n", // StringUtils.repeat(" ", type.treeLevel()), in.position(), type.typeName(), // type.version(), type.metaFlag(), type.size()); //} FieldNode fieldNode = new FieldNode(); fieldNode.typenode = typeNode; // if the type has no children, it has a primitve value if (typeNode.isEmpty() && typeNode.size > 0) { fieldNode.value = readPrimitiveValue(inr, typeNode, -1); } // read object fields foreach (TypeNode childTypeNode in typeNode.childs()) { //TypeNode childTypeNode = pair.Value; // Check if the current node is an array and if the current field is // "data". In that case, "data" needs to be read "size" times. if (typeNode.isArray && childTypeNode.name == "size") { FieldNode childFieldNode = readObject(inr, childTypeNode); fieldNode.add(childFieldNode); int size = fieldNode.getSInt32("size"); if (size > 4096 * 4096 * 4) { fieldNode.error = true; break; } } else if (typeNode.isArray && childTypeNode.name == "data") { int size = fieldNode.getSInt32("size"); if (size > 4096 * 4096 * 4) { fieldNode.error = true; break; } FieldNode childFieldNode = new FieldNode(); childFieldNode.typenode = childTypeNode; // if the child type has no children, it has a primitve array if (childTypeNode.isEmpty()) { childFieldNode.value = readPrimitiveValue(inr, childTypeNode, size); } else { // read list of object nodes bool error = false; List <FieldNode> childFieldNodes = new List <FieldNode>(size); for (int i = 0; i < size; i++) { FieldNode fn = readObject(inr, childTypeNode); childFieldNodes.Add(fn); if (fn.error) { error = true; break; } } childFieldNode.value = childFieldNodes; if (error) { childFieldNode.error = true; } } fieldNode.add(childFieldNode); if (childFieldNode.error) { fieldNode.error = true; break; } } else { FieldNode childFieldNode = readObject(inr, childTypeNode); fieldNode.add(childFieldNode); if (childFieldNode.error) { fieldNode.error = true; break; } } } postProcessObjectNode(fieldNode); return(fieldNode); }