예제 #1
0
 static void ReadFixedArrayField(BinaryReader binaryReader, object item, FieldInfo field)
 {
     var marhsalAsAttribute = field.Attribute<MarshalAsAttribute>();
     var elementType = field.FieldType.GetElementType();
     if (marhsalAsAttribute.Value == UnmanagedType.ByValArray)
     {
         var count = marhsalAsAttribute.SizeConst;
         var array = Array.CreateInstance(elementType, count);
         if (elementType == typeof(byte))
         {
             array = binaryReader.ReadBytes(count);
         }
         else
         {
             for (int i = 0; i < count; ++i)
             {
                 var element = ReadField(binaryReader, elementType);
                 ArrayExtensions.SetElement(array, i, element);
             }
         }
         field.Set(item, array);
     }
 }
예제 #2
0
        private static void DefaultProcessTagBlockArray(BinaryReader sourceReader, object item, FieldInfo field)
        {
            Type elementType = field.FieldType.GetElementType();
            int elementSize = SizeOf(elementType);

            var count = sourceReader.ReadInt32();
            var address = sourceReader.ReadInt32();

            sourceReader.BaseStream.Position = address;

            var array = Deserializer.DeserializeArray(sourceReader, elementType, elementSize, count);
            field.Set(item, array);
        }
예제 #3
0
        private static void ProcessFixedStructArray(BinaryReader sourceReader, object item, FieldInfo field)
        {
            Type elementType = field.FieldType.GetElementType();
            int elementSize = SizeOf(elementType);

            var marhsalAsAttribute = field.Attribute<MarshalAsAttribute>();
            var count = marhsalAsAttribute.SizeConst;

            var array = Deserializer.DeserializeArray(sourceReader, elementType, elementSize, count);
            field.Set(item, array);
        }
        public void ReadSectionData(BinaryReader sourceReader, Object item, FieldInfo field)
        {
            var originalDelegate = Deserializer.ProcessTagBlockArray.Clone();
            Deserializer.ProcessTagBlockArray = new Deserializer.ProcessTagBlockArrayDelegate(CustomProcessTagBlockArray);

            if (!geometryBlockInfo.IsInternal)
            {
                Stream resourceStream;
                if (Halo2.TryGettingResourceStream(geometryBlockInfo.blockOffset + 8, out resourceStream))
                {
                    resourceStream.Position = geometryBlockInfo.BlockAddress + 8;
                    var readerResource = new BinaryReader(resourceStream);
                    var returnValue = Deserializer.Deserialize(readerResource, typeof(RenderModelSectionDataBlock));

                    Deserializer.PreprocessField = null;
                    Deserializer.ProcessTagBlockArray = (Deserializer.ProcessTagBlockArrayDelegate)originalDelegate;
                    field.Set(item, new RenderModelSectionDataBlock[] { returnValue });
                }
                else
                {
                    Deserializer.PreprocessField = null;
                    Deserializer.ProcessTagBlockArray = (Deserializer.ProcessTagBlockArrayDelegate)originalDelegate;
                    field.Set(item, new RenderModelSectionDataBlock[0]);
                }
            }
            else
            {
                sourceReader.BaseStream.Position = geometryBlockInfo.BlockAddress + 8;
                var returnValue = Deserializer.Deserialize(sourceReader, typeof(RenderModelSectionDataBlock));

                Deserializer.PreprocessField = null;
                Deserializer.ProcessTagBlockArray = (Deserializer.ProcessTagBlockArrayDelegate)originalDelegate;
                field.Set(item, new RenderModelSectionDataBlock[] { returnValue });
            }
        }