コード例 #1
0
        public void Unserialize(GMDataReader reader)
        {
            int startOffset = reader.Offset;

            if (!reader.ReadBytes(8).SequenceEqual(new byte[8] {
                137, 80, 78, 71, 13, 10, 26, 10
            }))
            {
                reader.Warnings.Add(new GMWarning("PNG header expected.", GMWarning.WarningLevel.Bad));
            }

            while (true)
            {
                uint   length = (uint)reader.ReadByte() << 24 | (uint)reader.ReadByte() << 16 | (uint)reader.ReadByte() << 8 | (uint)reader.ReadByte();
                string type   = reader.ReadChars(4);
                reader.Offset += (int)length + 4;
                if (type == "IEND")
                {
                    break;
                }
            }

            int texLength = reader.Offset - startOffset;

            reader.Offset = startOffset;
            Data          = reader.ReadBytes(texLength);
        }
コード例 #2
0
        private void ParseMaskData(GMDataReader reader)
        {
            int MaskCount = reader.ReadInt32();
            int len       = ((Width + 7) / 8) * Height;

            CollisionMasks = new List <BufferRegion>();
            int total = 0;

            for (uint i = 0; i < MaskCount; i++)
            {
                CollisionMasks.Add(reader.ReadBytes(len));
                total += len;
            }

            // Pad to 4 bytes
            if (total % 4 != 0)
            {
                total += 4 - (total % 4);
            }

            int totalBits  = ((Width + 7) / 8 * 8) * Height * MaskCount;
            int totalBytes = ((totalBits + 31) / 32 * 32) / 8;

            if (total != totalBytes)
            {
                reader.Warnings.Add(new GMWarning("Unexpected sprite mask length!"));
            }
        }
コード例 #3
0
        public override void Unserialize(GMDataReader reader)
        {
            base.Unserialize(reader);

            List = new GMUniquePointerList <GMFont>();
            List.Unserialize(reader);

            Padding = reader.ReadBytes(512);
        }
コード例 #4
0
        public override void Unserialize(GMDataReader reader)
        {
            base.Unserialize(reader);

            List.Unserialize(reader);

            // Product ID information for each extension
            if (reader.VersionInfo.IsNumberAtLeast(1, 0, 0, 9999))
            {
                for (int i = 0; i < List.Count; i++)
                {
                    List[i].ProductID = new Guid(reader.ReadBytes(16));
                }
            }
        }
コード例 #5
0
        public void Unserialize(GMDataReader reader)
        {
            Name         = reader.ReadStringPointerObject();
            Width        = reader.ReadInt32();
            Height       = reader.ReadInt32();
            MarginLeft   = reader.ReadInt32();
            MarginRight  = reader.ReadInt32();
            MarginBottom = reader.ReadInt32();
            MarginTop    = reader.ReadInt32();
            Transparent  = reader.ReadWideBoolean();
            Smooth       = reader.ReadWideBoolean();
            Preload      = reader.ReadWideBoolean();
            BBoxMode     = reader.ReadUInt32();
            SepMasks     = (SepMaskType)reader.ReadInt32();
            OriginX      = reader.ReadInt32();
            OriginY      = reader.ReadInt32();

            TextureItems = new GMRemotePointerList <GMTextureItem>();
            if (reader.ReadInt32() == -1)
            {
                // Special/GMS2 sprite type
                SpecialOrGMS2 = true;

                int version = reader.ReadInt32();
                S_SpriteType = (SpriteType)reader.ReadInt32();
                if (reader.VersionInfo.IsNumberAtLeast(2))
                {
                    GMS2_PlaybackSpeed     = reader.ReadSingle();
                    GMS2_PlaybackSpeedType = (AnimSpeedType)reader.ReadInt32();
                    if (version >= 2)
                    {
                        GMS2_3_Sequence = reader.ReadPointerObjectUnique <SequenceReference>();
                        if (version >= 3)
                        {
                            reader.VersionInfo.SetNumber(2, 3, 2);
                            GMS2_3_2_NineSlice = reader.ReadPointerObjectUnique <NineSlice>();
                        }
                    }
                }

                switch (S_SpriteType)
                {
                case SpriteType.Normal:
                    TextureItems.Unserialize(reader);
                    ParseMaskData(reader);
                    break;

                case SpriteType.SWF:
                {
                    if (reader.ReadInt32() != 8)
                    {
                        reader.Warnings.Add(new GMWarning("SWF format not correct"));
                    }
                    TextureItems.Unserialize(reader);

                    // Parse the actual data
                    reader.Pad(4);
                    int begin            = reader.Offset;
                    int jpegTablesLength = (reader.ReadInt32() & ~int.MinValue);
                    if (reader.ReadInt32() != 8)
                    {
                        reader.Warnings.Add(new GMWarning("SWF format not correct"));
                    }
                    reader.Offset += jpegTablesLength;
                    reader.Pad(4);
                    reader.Offset += (reader.ReadInt32() * 8) + 4;
                    int frameCount = reader.ReadInt32();
                    reader.Offset += 16;
                    int maskCount = reader.ReadInt32();
                    reader.Offset += 8;
                    for (int i = 0; i < frameCount; i++)
                    {
                        reader.Offset += (reader.ReadInt32() * 100) + 16;
                    }
                    for (int i = 0; i < maskCount; i++)
                    {
                        reader.Offset += reader.ReadInt32();
                        reader.Pad(4);
                    }
                    int swfDataLength = reader.Offset - begin;
                    reader.Offset = begin;
                    S_Buffer      = reader.ReadBytes(swfDataLength);
                }
                break;

                case SpriteType.Spine:
                {
                    reader.Pad(4);

                    int begin = reader.Offset;
                    reader.ReadUInt32();         // version number
                    int jsonLength    = reader.ReadInt32();
                    int atlasLength   = reader.ReadInt32();
                    int textureLength = reader.ReadInt32();
                    reader.ReadUInt32();         // atlas tex width
                    reader.ReadUInt32();         // atlas tex height
                    reader.Offset = begin;

                    S_Buffer = reader.ReadBytes(24 + jsonLength + atlasLength + textureLength);
                }
                break;
                }
            }
            else
            {
                // Normal, GM:S 1.4 sprite
                reader.Offset -= 4;
                TextureItems.Unserialize(reader);
                ParseMaskData(reader);
            }
        }
コード例 #6
0
        public void Unserialize(GMDataReader reader)
        {
            int length = reader.ReadInt32();

            Data = reader.ReadBytes(length);
        }
コード例 #7
0
        public override void Unserialize(GMDataReader reader)
        {
            base.Unserialize(reader);

            DisableDebug = reader.ReadBoolean();
            FormatID     = reader.ReadByte();
            reader.VersionInfo.FormatID = FormatID;
            Unknown      = reader.ReadInt16();
            Filename     = reader.ReadStringPointerObject();
            Config       = reader.ReadStringPointerObject();
            LastObjectID = reader.ReadInt32();
            LastTileID   = reader.ReadInt32();
            GameID       = reader.ReadInt32();
            LegacyGUID   = new Guid(reader.ReadBytes(16).Memory.ToArray());
            GameName     = reader.ReadStringPointerObject();
            Major        = reader.ReadInt32();
            Minor        = reader.ReadInt32();
            Release      = reader.ReadInt32();
            Build        = reader.ReadInt32();
            reader.VersionInfo.SetNumber(Major, Minor, Release, Build);
            DefaultWindowWidth  = reader.ReadInt32();
            DefaultWindowHeight = reader.ReadInt32();
            Info                    = (InfoFlags)reader.ReadUInt32();
            LicenseCRC32            = reader.ReadInt32();
            LicenseMD5              = reader.ReadBytes(16);
            Timestamp               = reader.ReadInt64();
            DisplayName             = reader.ReadStringPointerObject();
            ActiveTargets           = reader.ReadInt64();
            FunctionClassifications = (FunctionClassification)reader.ReadUInt64();
            SteamAppID              = reader.ReadInt32();
            if (FormatID >= 14)
            {
                DebuggerPort = reader.ReadInt32();
            }

            int count = reader.ReadInt32();

            RoomOrder = new List <int>(count);
            for (int i = 0; i < count; i++)
            {
                RoomOrder.Add(reader.ReadInt32());
            }

            if (reader.VersionInfo.Major >= 2)
            {
                // Begin parsing random UID, and verify it based on original algorithm
                GMS2_RandomUID = new List <long>();

                Random random      = new Random((int)(Timestamp & 4294967295L));
                long   firstRandom = (long)random.Next() << 32 | (long)random.Next();
                if (reader.ReadInt64() != firstRandom)
                {
                    reader.Warnings.Add(new GMWarning("Unexpected random UID", GMWarning.WarningLevel.Info));
                }
                long  infoNumber = Timestamp - 1000;
                ulong temp       = (ulong)infoNumber;
                temp = ((temp << 56 & 18374686479671623680UL) | (temp >> 8 & 71776119061217280UL) |
                        (temp << 32 & 280375465082880UL) | (temp >> 16 & 1095216660480UL) | (temp << 8 & 4278190080UL) |
                        (temp >> 24 & 16711680UL) | (temp >> 16 & 65280UL) | (temp >> 32 & 255UL));
                infoNumber  = (long)temp;
                infoNumber ^= firstRandom;
                infoNumber  = ~infoNumber;
                infoNumber ^= ((long)GameID << 32 | (long)GameID);
                infoNumber ^= ((long)(DefaultWindowWidth + (int)Info) << 48 |
                               (long)(DefaultWindowHeight + (int)Info) << 32 |
                               (long)(DefaultWindowHeight + (int)Info) << 16 |
                               (long)(DefaultWindowWidth + (int)Info));
                infoNumber ^= FormatID;
                int infoLocation = Math.Abs((int)(Timestamp & 65535L) / 7 + (GameID - DefaultWindowWidth) + RoomOrder.Count) % 4;
                for (int i = 0; i < 4; i++)
                {
                    if (i == infoLocation)
                    {
                        long curr = reader.ReadInt64();
                        GMS2_RandomUID.Add(curr);
                        if (curr != infoNumber)
                        {
                            reader.Warnings.Add(new GMWarning("Unexpected random UID info", GMWarning.WarningLevel.Info));
                        }
                    }
                    else
                    {
                        int first  = reader.ReadInt32();
                        int second = reader.ReadInt32();
                        if (first != random.Next())
                        {
                            reader.Warnings.Add(new GMWarning("Unexpected random UID", GMWarning.WarningLevel.Info));
                        }
                        if (second != random.Next())
                        {
                            reader.Warnings.Add(new GMWarning("Unexpected random UID", GMWarning.WarningLevel.Info));
                        }
                        GMS2_RandomUID.Add((long)(first << 32) | (long)second);
                    }
                }

                // Other GMS2-specific data
                GMS2_FPS             = reader.ReadSingle();
                GMS2_AllowStatistics = reader.ReadWideBoolean();
                GMS2_GameGUID        = new Guid(reader.ReadBytes(16).Memory.ToArray());
            }
        }
コード例 #8
0
 public void Unserialize(GMDataReader reader, int length)
 {
     Buffer = reader.ReadBytes(length);
 }