Exemple #1
0
        public override void Unserialize(GMDataReader reader)
        {
            base.Unserialize(reader);

            reader.Offset -= 4;
            int chunkEnd = reader.Offset + 4 + reader.ReadInt32();

            int count = reader.ReadInt32();

            int[] ptrs = new int[count];
            for (int i = 0; i < count; i++)
            {
                ptrs[i] = reader.ReadInt32();
            }
            List = new List <GMShader>();
            for (int i = 0; i < count; i++)
            {
                GMShader s = new GMShader();
                reader.Offset = ptrs[i];
                if (i < count - 1)
                {
                    s.Unserialize(reader, ptrs[i + 1]);
                }
                else
                {
                    s.Unserialize(reader, chunkEnd);
                }
                List.Add(s);
            }
        }
Exemple #2
0
 public void Unserialize(GMDataReader reader)
 {
     Name        = reader.ReadStringPointerObject();
     DisplayName = reader.ReadStringPointerObject();
     Size        = reader.ReadInt32();
     if (Size < 0)
     {
         reader.Offset -= 4;
         SizeFloat      = -reader.ReadSingle();
     }
     Bold        = reader.ReadWideBoolean();
     Italic      = reader.ReadWideBoolean();
     RangeStart  = reader.ReadUInt16();
     Charset     = reader.ReadByte();
     AntiAlias   = reader.ReadByte();
     RangeEnd    = reader.ReadInt32();
     TextureItem = reader.ReadPointer <GMTextureItem>();
     ScaleX      = reader.ReadSingle();
     ScaleY      = reader.ReadSingle();
     if (reader.VersionInfo.FormatID >= 17)
     {
         AscenderOffset = reader.ReadInt32();
     }
     Glyphs = new GMPointerList <GMGlyph>();
     Glyphs.Unserialize(reader);
 }
        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!"));
            }
        }
Exemple #4
0
                public override void Unserialize(GMDataReader reader)
                {
                    Interpolation = (InterpolationEnum)reader.ReadInt32();

                    List = new GMList <Keyframe <Data> >();
                    List.Unserialize(reader);
                }
Exemple #5
0
 private void ReadOption(GMDataReader reader, OptionsFlags flag)
 {
     if (reader.ReadWideBoolean())
     {
         Options |= flag;
     }
 }
Exemple #6
0
 public static GMData LoadDataFile(this IConsole console, string file, bool verbose = false)
 {
     console.Output.WriteLine("Loading data file...");
     try
     {
         using FileStream fs = new FileStream(file, FileMode.Open);
         GMDataReader reader = new GMDataReader(fs, fs.Name);
         if (verbose)
         {
             reader.Data.Logger = console.Output.WriteLine;
         }
         else
         {
             reader.Data.Logger = null;
         }
         reader.Unserialize();
         foreach (GMWarning w in reader.Warnings)
         {
             console.Output.WriteLine($"[WARN: {w.Level}] {w.Message}"); // todo formatting
         }
         return(reader.Data);
     }
     catch (Exception e)
     {
         console.Error.WriteLine(e.ToString());
         return(null);
     }
 }
Exemple #7
0
        public override void Unserialize(GMDataReader reader)
        {
            base.Unserialize(reader);

            if (reader.VersionInfo.FormatID > 14)
            {
                VarCount1        = reader.ReadInt32();
                VarCount2        = reader.ReadInt32();
                MaxLocalVarCount = reader.ReadInt32();

                if (VarCount1 != VarCount2)
                {
                    reader.VersionInfo.DifferentVarCounts = true;
                }
            }

            int varLength = (reader.VersionInfo.FormatID > 14) ? 20 : 12;

            List = new List <GMVariable>();
            while (reader.Offset + varLength <= StartOffset + Length)
            {
                GMVariable gVar = new GMVariable();
                gVar.Unserialize(reader);
                List.Add(gVar);
            }
        }
Exemple #8
0
        public void Unserialize(GMDataReader reader)
        {
            Name              = reader.ReadStringPointerObject();
            PlaybackType      = (PlaybackTypeEnum)reader.ReadUInt32();
            PlaybackSpeed     = reader.ReadSingle();
            PlaybackSpeedType = (GMSprite.AnimSpeedType)reader.ReadUInt32();
            Length            = reader.ReadSingle();
            OriginX           = reader.ReadInt32();
            OriginY           = reader.ReadInt32();
            Volume            = reader.ReadSingle();

            BroadcastMessages = new GMList <Keyframe <BroadcastMessage> >();
            BroadcastMessages.Unserialize(reader);

            Tracks = new GMList <Track>();
            Tracks.Unserialize(reader);

            FunctionIDs = new Dictionary <int, GMString>();
            int count = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                int key = reader.ReadInt32();
                FunctionIDs[key] = reader.ReadStringPointerObject();
            }

            Moments = new GMList <Keyframe <Moment> >();
            Moments.Unserialize(reader);
        }
Exemple #9
0
        public void Unserialize(GMDataReader reader)
        {
            Name = reader.ReadStringPointerObject();

            if (reader.VersionInfo.FormatID > 14)
            {
                VariableType = (GMCode.Bytecode.Instruction.InstanceType)reader.ReadInt32();
                VariableID   = reader.ReadInt32();
            }
            Occurrences = reader.ReadInt32();
            if (Occurrences > 0)
            {
                int addr = reader.ReadInt32();

                // Parse reference chain
                GMCode.Bytecode.Instruction curr;
                for (int i = Occurrences; i > 0; i--)
                {
                    curr = reader.Instructions[addr];
                    curr.Variable.Target = this;
                    addr += curr.Variable.NextOccurrence;
                }
            }
            else
            {
                if (reader.ReadInt32() != -1)
                {
                    reader.Warnings.Add(new GMWarning("Variable with no occurrences, but still has a first occurrence address"));
                }
            }
        }
                public void Unserialize(GMDataReader reader)
                {
                    X     = reader.ReadSingle();
                    Value = reader.ReadSingle();

                    if (reader.ReadUInt32() != 0) // in 2.3 a int with the value of 0 would be set here,
                    {                             // it cannot be version 2.3 if this value isn't 0
                        reader.VersionInfo.SetNumber(2, 3, 1);
                        reader.Offset -= 4;
                    }
                    else
                    {
                        if (reader.ReadUInt32() == 0)              // At all points (besides the first one)
                        {
                            reader.VersionInfo.SetNumber(2, 3, 1); // if BezierX0 equals to 0 (the above check)
                        }
                        reader.Offset -= 8;                        // then BezierY0 equals to 0 as well (the current check)
                    }

                    if (reader.VersionInfo.IsNumberAtLeast(2, 3, 1))
                    {
                        BezierX0 = reader.ReadSingle();
                        BezierY0 = reader.ReadSingle();
                        BezierX1 = reader.ReadSingle();
                        BezierY1 = reader.ReadSingle();
                    }
                    else
                    {
                        reader.Offset += 4;
                    }
                }
Exemple #11
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);
        }
Exemple #12
0
        public override void Unserialize(GMDataReader reader)
        {
            base.Unserialize(reader);

            List = new GMPointerList <GMPath>();
            List.Unserialize(reader);
        }
        public override void Unserialize(GMDataReader reader)
        {
            base.Unserialize(reader);

            List = new GMUniquePointerList <GMObject>();
            List.Unserialize(reader);
        }
Exemple #14
0
        public override void Unserialize(GMDataReader reader)
        {
            base.Unserialize(reader);

            List = new GMPointerList <GMAudioGroup>();
            List.Unserialize(reader);

            // Now load the audio groups if possible
            string dir = reader.Data.Directory;

            if (dir != null)
            {
                AudioData = new Dictionary <int, GMData>();
                for (int i = 1; i < List.Count; i++)
                {
                    string fname = $"audiogroup{i}.dat";
                    string path  = Path.Combine(dir, fname);
                    if (File.Exists(path))
                    {
                        using (FileStream fs = new FileStream(path, FileMode.Open))
                        {
                            GMDataReader groupReader = new GMDataReader(fs, fs.Name);
                            AudioData[i] = groupReader.Data;
                            foreach (GMWarning w in groupReader.Warnings)
                            {
                                w.File = fname;
                                reader.Warnings.Add(w);
                            }
                        }
                    }
                }
            }
        }
Exemple #15
0
        public void Unserialize(GMDataReader reader)
        {
            Name                  = reader.ReadStringPointerObject();
            SpriteID              = reader.ReadInt32();
            Visible               = reader.ReadWideBoolean();
            Solid                 = reader.ReadWideBoolean();
            Depth                 = reader.ReadInt32();
            Persistent            = reader.ReadWideBoolean();
            ParentObjectID        = reader.ReadInt32();
            MaskSpriteID          = reader.ReadInt32();
            Physics               = reader.ReadWideBoolean();
            PhysicsSensor         = reader.ReadWideBoolean();
            PhysicsShape          = (CollisionShape)reader.ReadInt32();
            PhysicsDensity        = reader.ReadSingle();
            PhysicsRestitution    = reader.ReadSingle();
            PhysicsGroup          = reader.ReadInt32();
            PhysicsLinearDamping  = reader.ReadSingle();
            PhysicsAngularDamping = reader.ReadSingle();
            int vertexCount = reader.ReadInt32();

            PhysicsFriction  = reader.ReadSingle();
            PhysicsAwake     = reader.ReadWideBoolean();
            PhysicsKinematic = reader.ReadWideBoolean();
            PhysicsVertices  = new List <PhysicsVertex>();
            for (int i = vertexCount; i > 0; i--)
            {
                PhysicsVertex v = new PhysicsVertex();
                v.Unserialize(reader);
                PhysicsVertices.Add(v);
            }
            Events = new GMPointerList <GMPointerList <Event> >();
            Events.Unserialize(reader);
        }
Exemple #16
0
        public void Unserialize(GMDataReader reader, int endPos)
        {
            Name = reader.ReadStringPointerObject();
            Type = (ShaderType)(reader.ReadUInt32() & 0x7FFFFFFF);

            GLSL_ES_Vertex   = reader.ReadStringPointerObject();
            GLSL_ES_Fragment = reader.ReadStringPointerObject();
            GLSL_Vertex      = reader.ReadStringPointerObject();
            GLSL_Fragment    = reader.ReadStringPointerObject();
            HLSL9_Vertex     = reader.ReadStringPointerObject();
            HLSL9_Fragment   = reader.ReadStringPointerObject();

            int ptr1 = reader.ReadInt32();

            HLSL11_VertexBuffer = reader.ReadPointer <ShaderBuffer>(ptr1);
            int ptr2 = reader.ReadInt32();

            HLSL11_PixelBuffer = reader.ReadPointer <ShaderBuffer>(ptr2);

            VertexAttributes = new List <GMString>();
            for (int i = reader.ReadInt32(); i > 0; i--)
            {
                VertexAttributes.Add(reader.ReadStringPointerObject());
            }

            if (reader.ReadInt32() != 2)
            {
                reader.Warnings.Add(new GMWarning("expected 2 in SHDR"));
            }

            int ptr3 = reader.ReadInt32();

            PSSL_VertexBuffer = reader.ReadPointer <ShaderBuffer>(ptr3);
            ReadShaderData(reader, PSSL_VertexBuffer, ptr3, reader.ReadInt32());

            int currPtr = reader.ReadInt32();

            PSSL_PixelBuffer = reader.ReadPointer <ShaderBuffer>(currPtr);
            ReadShaderData(reader, PSSL_PixelBuffer, currPtr, reader.ReadInt32());

            currPtr             = reader.ReadInt32();
            CG_PSV_VertexBuffer = reader.ReadPointer <ShaderBuffer>(currPtr);
            ReadShaderData(reader, CG_PSV_VertexBuffer, currPtr, reader.ReadInt32());

            currPtr            = reader.ReadInt32();
            CG_PSV_PixelBuffer = reader.ReadPointer <ShaderBuffer>(currPtr);
            ReadShaderData(reader, CG_PSV_PixelBuffer, currPtr, reader.ReadInt32());

            currPtr             = reader.ReadInt32();
            CG_PS3_VertexBuffer = reader.ReadPointer <ShaderBuffer>(currPtr);
            ReadShaderData(reader, CG_PSV_VertexBuffer, currPtr, reader.ReadInt32());

            currPtr            = reader.ReadInt32();
            CG_PS3_PixelBuffer = reader.ReadPointer <ShaderBuffer>(currPtr);
            ReadShaderData(reader, CG_PSV_PixelBuffer, currPtr, reader.ReadInt32());

            ReadShaderData(reader, HLSL11_VertexBuffer, ptr1, -1, ptr2 == 0 ? endPos : ptr2);
            ReadShaderData(reader, HLSL11_PixelBuffer, ptr2, -1, ptr3 == 0 ? endPos : ptr3);
        }
Exemple #17
0
 public void Unserialize(GMDataReader reader)
 {
     InternalCount = reader.ReadInt32();
     if (InternalCount > 0)
     {
         Event = reader.ReadStringPointerObject();
     }
 }
Exemple #18
0
 public void Unserialize(GMDataReader reader)
 {
     Instances = new List <int>();
     for (int i = reader.ReadInt32(); i > 0; i--)
     {
         Instances.Add(reader.ReadInt32());
     }
 }
Exemple #19
0
        static void Main(string[] args)
        {
            Stopwatch s = new Stopwatch();

            s.Start();
            using (FileStream fs = new FileStream(@"input/data.win", FileMode.Open))
            {
                GMDataReader reader = new GMDataReader(fs, fs.Name);
                foreach (GMWarning w in reader.Warnings)
                {
                    Console.WriteLine(string.Format("[WARN: {0}] {1}", w.Level, w.Message));
                }

                ProjectFile pf = new ProjectFile(reader.Data, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "project"),
                                                 (ProjectFile.WarningType type, string info) =>
                {
                    Console.WriteLine($"Project warn: {type} {info ?? ""}");
                });

                bool first = !Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "project"));
                if (first)
                {
                    pf.AddAllAssetsToJSON(pf.Paths, "paths");
                    pf.AddAllAssetsToJSON(pf.Sounds, "sounds");
                    pf.AddAllAssetsToJSON(pf.Objects, "objects");
                    pf.Save();
                }
                else
                {
                    pf.Load();
                    pf.PurgeUnmodifiedAssets(pf.Paths);
                    pf.PurgeUnmodifiedAssets(pf.Sounds);
                    pf.PurgeUnmodifiedAssets(pf.Objects);
                }

                Directory.CreateDirectory("output");
                using (FileStream fs2 = new FileStream("output/data.win", FileMode.Create))
                {
                    using (GMDataWriter writer = new GMDataWriter(reader.Data, fs2, fs2.Name, reader.Length))
                    {
                        if (!first)
                        {
                            pf.ConvertToData();
                        }
                        writer.Write();
                        writer.Flush();
                        foreach (GMWarning w in writer.Warnings)
                        {
                            Console.WriteLine(string.Format("[WARN: {0}] {1}", w.Level, w.Message));
                        }
                    }
                }
            }
            s.Stop();
            Console.WriteLine(string.Format("Took {0} ms, {1} seconds.", s.Elapsed.TotalMilliseconds, Math.Round(s.Elapsed.TotalMilliseconds / 1000, 2)));

            Console.ReadLine();
        }
Exemple #20
0
 public void Unserialize(GMDataReader reader)
 {
     ID   = reader.ReadInt32();
     Tags = new List <GMString>();
     for (int i = reader.ReadInt32(); i > 0; i--)
     {
         Tags.Add(reader.ReadStringPointerObject());
     }
 }
 public void Unserialize(GMDataReader reader, int entryCount)
 {
     Name   = reader.ReadStringPointerObject();
     Region = reader.ReadStringPointerObject();
     for (uint i = 0; i < entryCount; i++)
     {
         Entries.Add(reader.ReadStringPointerObject());
     }
 }
        public override void Unserialize(GMDataReader reader)
        {
            base.Unserialize(reader);

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

            Padding = reader.ReadBytes(512);
        }
Exemple #23
0
 public void Unserialize(GMDataReader reader)
 {
     Scaled = reader.ReadUInt32();
     if (reader.VersionInfo.Major >= 2)
     {
         GeneratedMips = reader.ReadUInt32();
     }
     TextureData = reader.ReadPointerObject <GMTextureData>();
 }
            public void Unserialize(GMDataReader reader)
            {
                Name         = reader.ReadStringPointerObject();
                FunctionType = (FunctionTypeEnum)reader.ReadUInt32();
                Iterations   = (ushort)reader.ReadUInt32();

                Points = new GMList <Point>();
                Points.Unserialize(reader);
            }
Exemple #25
0
 public void Unserialize(GMDataReader reader)
 {
     Filename      = reader.ReadStringPointerObject();
     FinalFunction = reader.ReadStringPointerObject();
     InitFunction  = reader.ReadStringPointerObject();
     Kind          = (ExtensionKind)reader.ReadUInt32();
     Functions     = new GMPointerList <ExtensionFunction>();
     Functions.Unserialize(reader);
 }
Exemple #26
0
        public void Unserialize(GMDataReader reader)
        {
            EmptyString = reader.ReadStringPointerObject();
            Name        = reader.ReadStringPointerObject();
            ClassName   = reader.ReadStringPointerObject();

            Files = new GMPointerList <ExtensionFile>();
            Files.Unserialize(reader);
        }
Exemple #27
0
 public void Unserialize(GMDataReader reader)
 {
     Name           = reader.ReadStringPointerObject();
     TexturePageIDs = reader.ReadPointerObjectUnique <GMList <ResourceID> >();
     SpriteIDs      = reader.ReadPointerObjectUnique <GMList <ResourceID> >();
     SpineSpriteIDs = reader.ReadPointerObjectUnique <GMList <ResourceID> >();
     FontIDs        = reader.ReadPointerObjectUnique <GMList <ResourceID> >();
     TilesetIDs     = reader.ReadPointerObjectUnique <GMList <ResourceID> >();
 }
Exemple #28
0
 public void Unserialize(GMDataReader reader)
 {
     Name      = reader.ReadStringPointerObject();
     Smooth    = reader.ReadWideBoolean();
     Closed    = reader.ReadWideBoolean();
     Precision = reader.ReadUInt32();
     Points    = new GMList <Point>();
     Points.Unserialize(reader);
 }
 public void Unserialize(GMDataReader reader)
 {
     if (reader.ReadInt32() != 1)
     {
         reader.Warnings.Add(new GMWarning("Unexpected version for sequence reference in sprite"));
     }
     Sequence = new GMSequence();
     Sequence.Unserialize(reader);
 }
Exemple #30
0
            public void Unserialize(GMDataReader reader)
            {
                List = new List <GMString>();
                int count = reader.ReadInt32();

                for (int i = 0; i < count; i++)
                {
                    List.Add(reader.ReadStringPointerObject());
                }
            }