示例#1
0
        public override void Unserialize(GMDataReader reader, ListUnserialize before = null,
                                         ListUnserialize after             = null,
                                         ListUnserializeElement elemReader = null)
        {
            // Read the element count and begin reading elements
            int count = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                before?.Invoke(reader, i, Count);

                // Read the current element and add it to the list
                T elem;
                if (elemReader == null)
                {
                    elem = reader.ReadPointerObject <T>(reader.ReadInt32(), true);
                }
                else
                {
                    elem = (T)elemReader(reader, true);
                }
                Add(elem);

                after?.Invoke(reader, i, Count);
            }
        }
示例#2
0
 public virtual void Unserialize(GMDataReader reader)
 {
     // Read chunk length, measure start/end
     Length      = reader.ReadInt32();
     StartOffset = reader.Offset;
     EndOffset   = StartOffset + Length;
 }
示例#3
0
        public virtual void Unserialize(GMDataReader reader, ListUnserialize before = null,
                                        ListUnserialize after             = null,
                                        ListUnserializeElement elemReader = null)
        {
            // Read the element count and begin reading elements
            int count = reader.ReadInt32();

            Capacity = count;
            for (int i = 0; i < count; i++)
            {
                before?.Invoke(reader, i, count);

                // Read the current element and add it to the list
                T elem;
                if (elemReader == null)
                {
                    elem = new T();
                    elem.Unserialize(reader);
                }
                else
                {
                    elem = (T)elemReader(reader, (i + 1 != count));
                }
                Add(elem);

                after?.Invoke(reader, i, count);
            }
        }
示例#4
0
        public override void Unserialize(GMDataReader reader, ListUnserialize before = null,
                                         ListUnserialize after             = null,
                                         ListUnserializeElement elemReader = null)
        {
            // Define a default pointer reader if none is set
            if (elemReader == null)
            {
                if (UsePointerMap)
                {
                    elemReader = DoReadPointerObject;
                }
                else
                {
                    elemReader = DoReadPointerObjectUnique;
                }
            }

            // Read the element count and begin reading elements
            int count = reader.ReadInt32();

            Capacity = count;
            for (int i = 0; i < count; i++)
            {
                before?.Invoke(reader, i, count);

                // Read the current element and add it to the list
                Add((T)elemReader(reader, i + 1 != count));

                after?.Invoke(reader, i, count);
            }
        }
示例#5
0
        public override void Unserialize(GMDataReader reader)
        {
            base.Unserialize(reader);

            // Gather the names and offsets of the sub-chunks
            ChunkNames = new List <string>();
            List <int> ChunkOffsets = new List <int>();

            while (reader.Offset < EndOffset)
            {
                // Read its name and skip contents
                ChunkOffsets.Add(reader.Offset);
                string name = reader.ReadChars(4);
                ChunkNames.Add(name);
                int length = reader.ReadInt32();
                reader.Offset += length;

                // Check if this is a GMS 2.3+ file
                if (name == "SEQN")
                {
                    reader.Data.VersionInfo.SetNumber(2, 3);
                }
                else if (name == "FEDS")
                {
                    reader.Data.VersionInfo.SetNumber(2, 3, 6);
                }

                // Update whether this version aligns chunks to 16 bytes
                if (reader.Offset < EndOffset)
                {
                    reader.Data.VersionInfo.AlignChunksTo16 &= (reader.Offset % 16 == 0);
                }
            }

            // Actually read all the sub-chunks
            Chunks        = new Dictionary <string, GMChunk>();
            reader.Offset = StartOffset;
            for (int i = 0; i < ChunkNames.Count; i++)
            {
                reader.Offset = ChunkOffsets[i];
                reader.Data.Logger?.Invoke($"Reading {ChunkNames[i]} at {reader.Offset:X}");

                Type type;
                if (!ChunkMap.TryGetValue(ChunkNames[i], out type))
                {
                    // Unknown chunk name, so skip past it
                    reader.Warnings.Add(new GMWarning($"Unknown chunk with name {ChunkNames[i]}",
                                                      GMWarning.WarningLevel.Severe, GMWarning.WarningKind.UnknownChunk));
                    continue;
                }

                // Actually parse the chunk, starting at its length
                reader.Offset += 4;
                GMChunk chunk = (GMChunk)Activator.CreateInstance(type);
                Chunks.Add(ChunkNames[i], chunk);
                chunk.Unserialize(reader);
            }
        }
示例#6
0
 private static GMSerializable DoReadPointerObjectUnique(GMDataReader reader, bool notLast)
 {
     return(reader.ReadPointerObjectUnique <T>(reader.ReadInt32(), notLast));
 }