public override int ReadAttribute(byte[] data, int offset, FieldInfo f, object target, Dictionary <string, byte[]> other) { PointerArray namesPointer = (PointerArray)target.GetType().GetField(pointerName).GetValue(target); Pointer[] pointers = (Pointer[])target.GetType().GetField(varName).GetValue(target); byte[] sourceData = data; if (source != "") { sourceData = other[source]; } int pos = offset; Type elemType = f.FieldType.GetElementType(); BinaryStructure[] objs = (BinaryStructure[])Array.CreateInstance(elemType, namesPointer.max); for (int i = 0; i < namesPointer.max; i++) { pos = (int)pointers[i].offset; //Debug.Log("Pointer points to " + pos); BinaryStructure obj = (BinaryStructure)Activator.CreateInstance(elemType); pos = obj.Load(sourceData, other, pos); objs[i] = obj; } f.SetValue(target, objs); return(pos); }
public override int ReadAttribute(byte[] data, int offset, FieldInfo f, object target, Dictionary <string, byte[]> other) { byte[] sourceData = data; if (source != "") { sourceData = other[source]; } PointerArray pointer = (PointerArray)target.GetType().GetField(varName).GetValue(target); int pos = (int)pointer.pointer; if (offsetName != "") { pos += (int)(uint)target.GetType().GetField(offsetName).GetValue(target); } Type elemType = f.FieldType.GetElementType(); BinaryStructure[] objs = (BinaryStructure[])Array.CreateInstance(elemType, pointer.used); for (int i = 0; i < pointer.used; i++) { BinaryStructure obj = (BinaryStructure)Activator.CreateInstance(elemType); pos = obj.Load(sourceData, other, pos); objs[i] = obj; } f.SetValue(target, objs); if (pointer.used == 0 || !movePos) { return(offset); } return(pos); }