private object GetValueArray(Type type, STUFieldAttribute element, STUArrayInfo info, STUInstanceField writtenField) { Array array = Array.CreateInstance(type, info.Count); for (uint i = 0; i < info.Count; ++i) { if (element != null) { Metadata.Position += element.Padding; } uint parent = 0; if (InstanceArrayRef?.Length > info.InstanceIndex) { parent = InstanceArrayRef[info.InstanceIndex].Checksum; } array.SetValue(GetValueArrayInner(type, element, parent, writtenField.FieldChecksum), i); } return(array); }
protected void TryReadArray(FieldGuessData output, STUInstanceField field, BinaryReader reader) { long beforePos = reader.BaseStream.Position; try { int offset = reader.ReadInt32(); Metadata.Position = offset; STUArrayInfo array = MetadataReader.Read <STUArrayInfo>(); if (array.Count < 99999 && array.Count > 0) { output.IsArray = true; output.ArrayInfo = array; } // uint parent = 0; // if (instanceArrayRef?.Length > array.InstanceIndex) { // parent = instanceArrayRef[array.InstanceIndex].Checksum; // } } catch (Exception) { output.IsArray = false; } reader.BaseStream.Position = beforePos; }
private object InitializeObjectArray(STUInstanceField field, Type type, BinaryReader reader, STUFieldAttribute element) { if (field.FieldSize == 0 && field.FieldChecksum != 0) { STUInlineArrayInfo inlineInfo = reader.Read <STUInlineArrayInfo>(); if (inlineInfo.Size > 600000) { return(null); // i feel that it's unlikley that there will be an inline with this count, exceptions if this isn't checked. } Array array = Array.CreateInstance(type, (uint)inlineInfo.Count); // if (inlineInfo.FieldListIndex == 0) return array; for (uint i = 0; i < (uint)inlineInfo.Count; ++i) { Stream.Position += element.Padding; uint fieldIndex = reader.ReadUInt32(); object instance = Activator.CreateInstance(type); if (fieldIndex >= InstanceFieldLists.Length) { continue; } array.SetValue(InitializeObject(instance, type, InstanceFields[fieldIndex], reader), i); STUInstance fieldInstance = array.GetValue(i) as STUInstance; if (fieldInstance != null) { fieldInstance.Usage = InstanceUsage.InlineArray; } HiddenInstances.Add(fieldInstance); } return(array); } if (typeof(STUInstance).IsAssignableFrom(type)) { int embedArrayOffset = reader.ReadInt32(); Metadata.Position = embedArrayOffset; STUEmbedArrayInfo embedArrayInfo = MetadataReader.Read <STUEmbedArrayInfo>(); if (embedArrayInfo.Count == 0) { return(null); } Metadata.Position = embedArrayInfo.Offset; Array array = Array.CreateInstance(type, embedArrayInfo.Count); List <int> request = new List <int>(); for (int i = 0; i < embedArrayInfo.Count; i++) { int instanceIndex = MetadataReader.ReadInt32(); MetadataReader.ReadInt32(); // Padding if (instanceIndex == -1) { return(null); } request.Add(instanceIndex); } EmbedArrayRequests[array] = request.ToArray(); return(array); } int offset = reader.ReadInt32(); Metadata.Position = offset; STUArrayInfo arrayInfo = MetadataReader.Read <STUArrayInfo>(); Metadata.Position = arrayInfo.Offset; return(GetValueArray(type, element, arrayInfo, field)); }