Ejemplo n.º 1
0
        private void WriteMaskData(GMDataWriter writer)
        {
            writer.Write(CollisionMasks.Count);
            int total = 0;

            foreach (var mask in CollisionMasks)
            {
                writer.Write(mask);
                total += mask.Length;
            }

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

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

            if (total != totalBytes)
            {
                writer.Warnings.Add(new GMWarning("Unexpected sprite mask length!"));
            }
        }
Ejemplo n.º 2
0
            public void Serialize(GMDataWriter writer)
            {
                writer.WritePointerString(Name);
                writer.Write((uint)FunctionType);
                writer.Write((uint)Iterations);

                Points.Serialize(writer);
            }
Ejemplo n.º 3
0
 public void Serialize(GMDataWriter writer)
 {
     writer.Write(Instances.Count);
     foreach (int i in Instances)
     {
         writer.Write(i);
     }
 }
Ejemplo n.º 4
0
 public void Serialize(GMDataWriter writer)
 {
     writer.Write(Scaled);
     if (writer.VersionInfo.Major >= 2)
     {
         writer.Write(GeneratedMips);
     }
     writer.WritePointer(TextureData);
 }
Ejemplo n.º 5
0
 public void Serialize(GMDataWriter writer)
 {
     writer.Write(ID);
     writer.Write(Tags.Count);
     foreach (GMString s in Tags)
     {
         writer.WritePointerString(s);
     }
 }
Ejemplo n.º 6
0
        public override void Serialize(GMDataWriter writer)
        {
            base.Serialize(writer);

            writer.Write(List.Count);
            foreach (int item in List)
            {
                writer.Write(item);
            }
        }
Ejemplo n.º 7
0
        public override void Serialize(GMDataWriter writer)
        {
            base.Serialize(writer);

            if (writer.VersionInfo.FormatID > 14)
            {
                // Count instance/global variables
                if (writer.VersionInfo.DifferentVarCounts)
                {
                    VarCount1 = 0;
                    VarCount2 = 0;
                    foreach (GMVariable v in List)
                    {
                        if (v.VariableType == GMCode.Bytecode.Instruction.InstanceType.Global)
                        {
                            VarCount1++;
                        }
                        else if (v.VariableID >= 0 && v.VariableType == GMCode.Bytecode.Instruction.InstanceType.Self)
                        {
                            VarCount2++;
                        }
                    }
                }
                else
                {
                    VarCount1 = -1;
                    foreach (GMVariable v in List)
                    {
                        if (v.VariableType == GMCode.Bytecode.Instruction.InstanceType.Global ||
                            v.VariableType == GMCode.Bytecode.Instruction.InstanceType.Self)
                        {
                            VarCount1 = Math.Max(VarCount1, v.VariableID);
                        }
                    }
                    VarCount1 += 1;
                    VarCount2  = VarCount1;
                }
                writer.Write(VarCount1);
                writer.Write(VarCount2);

                // Set MaxLocalVarCount to highest amount of locals within all entires
                MaxLocalVarCount = 0;
                foreach (GMLocalsEntry item in ((GMChunkFUNC)writer.Data.Chunks["FUNC"]).Locals)
                {
                    MaxLocalVarCount = Math.Max(MaxLocalVarCount, item.Entries.Count);
                }

                writer.Write(MaxLocalVarCount);
            }

            foreach (GMVariable variable in List)
            {
                variable.Serialize(writer);
            }
        }
Ejemplo n.º 8
0
 public void Serialize(GMDataWriter writer)
 {
     writer.WritePointerString(Name);
     if (Constructor)
     {
         writer.Write((uint)CodeID | 2147483648u);
     }
     else
     {
         writer.Write(CodeID);
     }
 }
Ejemplo n.º 9
0
 public void Serialize(GMDataWriter writer)
 {
     writer.WritePointerString(Name);
     writer.Write(AssetID);
     writer.Write(X); writer.Write(Y);
     writer.Write(ScaleX); writer.Write(ScaleY);
     writer.Write(Color);
     writer.Write(AnimationSpeed);
     writer.Write((int)AnimationSpeedType);
     writer.Write(FrameIndex);
     writer.Write(Rotation);
 }
Ejemplo n.º 10
0
 public void Serialize(GMDataWriter writer)
 {
     writer.Write(Left);
     writer.Write(Top);
     writer.Write(Right);
     writer.Write(Bottom);
     writer.WriteWideBoolean(Enabled);
     for (int i = 0; i < 5; i++)
     {
         writer.Write((int)TileModes[i]);
     }
 }
Ejemplo n.º 11
0
        public void Serialize(GMDataWriter writer)
        {
            writer.WritePointerString(Name);
            writer.Write(Occurrences);

            List <int> references;

            if (writer.FunctionReferences.TryGetValue(this, out references))
            {
                Occurrences = references.Count;
            }
            else
            {
                Occurrences = 0;
            }

            if (Occurrences > 0)
            {
                if (writer.VersionInfo.IsNumberAtLeast(2, 3))
                {
                    writer.Write(references[0] + 4);
                }
                else
                {
                    writer.Write(references[0]);
                }

                int returnTo = writer.Offset;
                for (int i = 0; i < references.Count; i++)
                {
                    int curr = references[i];

                    int nextDiff;
                    if (i < references.Count - 1)
                    {
                        nextDiff = references[i + 1] - curr;
                    }
                    else
                    {
                        nextDiff = ((GMChunkSTRG)writer.Data.Chunks["STRG"]).List.IndexOf(Name);
                    }

                    writer.Offset = curr + 4;
                    writer.WriteInt24(nextDiff);
                }
                writer.Offset = returnTo;
            }
            else
            {
                writer.Write((int)-1);
            }
        }
Ejemplo n.º 12
0
 public void Serialize(GMDataWriter writer)
 {
     writer.Write(BackgroundID);
     writer.Write(TilesX);
     writer.Write(TilesY);
     for (int y = 0; y < TilesY; y++)
     {
         for (int x = 0; x < TilesX; x++)
         {
             writer.Write(TileData[y][x]);
         }
     }
 }
Ejemplo n.º 13
0
 public void Serialize(GMDataWriter writer)
 {
     writer.Write(Key);
     writer.Write(Length);
     writer.WriteWideBoolean(Stretch);
     writer.WriteWideBoolean(Disabled);
     writer.Write(Channels.Count);
     foreach (KeyValuePair <int, T> kvp in Channels)
     {
         writer.Write(kvp.Key);
         kvp.Value.Serialize(writer);
     }
 }
Ejemplo n.º 14
0
 public void Serialize(GMDataWriter writer)
 {
     writer.WriteWideBoolean(Visible);
     writer.WriteWideBoolean(Foreground);
     writer.Write(SpriteID);
     writer.WriteWideBoolean(TileHorz);
     writer.WriteWideBoolean(TileVert);
     writer.WriteWideBoolean(Stretch);
     writer.Write(Color);
     writer.Write(FirstFrame);
     writer.Write(AnimationSpeed);
     writer.Write((int)AnimationSpeedType);
 }
Ejemplo n.º 15
0
 public void Serialize(GMDataWriter writer)
 {
     writer.Write(Value);
     writer.WriteWideBoolean(IsCurveEmbedded);
     if (IsCurveEmbedded)
     {
         writer.Write((int)-1);
         AnimCurve.Serialize(writer, false);
     }
     else
     {
         writer.Write(AnimCurveID);
     }
 }
Ejemplo n.º 16
0
            public void Serialize(GMDataWriter writer)
            {
                writer.WritePointerString(Name);
                writer.Write(ID);
                writer.Write(Kind);
                writer.Write((uint)ReturnType);
                writer.WritePointerString(ExternalName);

                writer.Write(ArgumentTypes.Count);
                for (int i = 0; i < ArgumentTypes.Count; i++)
                {
                    writer.Write((uint)ArgumentTypes[i]);
                }
            }
Ejemplo n.º 17
0
        public override void Serialize(GMDataWriter writer)
        {
            base.Serialize(writer);

            writer.Pad(4);
            writer.Write(1);

            writer.Write(AllTags.Count);
            foreach (GMString s in AllTags)
            {
                writer.WritePointerString(s);
            }

            AssetTagsList.Serialize(writer);
        }
Ejemplo n.º 18
0
        public override void Serialize(GMDataWriter writer)
        {
            base.Serialize(writer);

            List.Serialize(writer);

            // Now save the audio groups if possible
            string dir = writer.Data.Directory;

            if (dir != null && AudioData != null)
            {
                foreach (var pair in AudioData)
                {
                    string fname = $"audiogroup{pair.Key}.dat";
                    string path  = Path.Combine(dir, fname);
                    using (FileStream fs = new FileStream(path, FileMode.Create))
                    {
                        GMData data = AudioData[pair.Key];
                        using (GMDataWriter groupWriter = new GMDataWriter(data, fs, fs.Name, data.Length))
                        {
                            groupWriter.Write();
                            groupWriter.Flush();
                            foreach (GMWarning w in groupWriter.Warnings)
                            {
                                w.File = fname;
                                writer.Warnings.Add(w);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 19
0
        public override void Serialize(GMDataWriter writer)
        {
            base.Serialize(writer);

            writer.Write(1);
            List.Serialize(writer);
        }
Ejemplo n.º 20
0
        public override void Serialize(GMDataWriter writer)
        {
            base.Serialize(writer);

            List.Serialize(writer);

            // Whatever this is
            for (short i = 0; i < 0x80; i++)
            {
                writer.Write(i);
            }
            for (short i = 0; i < 0x80; i++)
            {
                writer.Write((short)0x3f);
            }
        }
Ejemplo n.º 21
0
                public GMPointerList <AssetInstance> NineSlices; // apparently removed in 2.3.2

                public void Serialize(GMDataWriter writer)
                {
                    writer.WritePointer(LegacyTiles);
                    writer.WritePointer(Sprites);
                    if (writer.VersionInfo.IsNumberAtLeast(2, 3))
                    {
                        writer.WritePointer(Sequences);
                        if (!writer.VersionInfo.IsNumberAtLeast(2, 3, 2))
                        {
                            writer.WritePointer(NineSlices);
                        }
                    }

                    writer.WriteObjectPointer(LegacyTiles);
                    LegacyTiles.Serialize(writer);
                    writer.WriteObjectPointer(Sprites);
                    Sprites.Serialize(writer);
                    if (writer.VersionInfo.IsNumberAtLeast(2, 3))
                    {
                        writer.WriteObjectPointer(Sequences);
                        Sequences.Serialize(writer);
                        if (!writer.VersionInfo.IsNumberAtLeast(2, 3, 2))
                        {
                            if (NineSlices == null)
                            {
                                writer.Write(0); // Even if it's 2.3.2 but we don't detect it, this shouldn't break format... probably
                            }
                            else
                            {
                                writer.WriteObjectPointer(NineSlices);
                                NineSlices.Serialize(writer);
                            }
                        }
                    }
                }
Ejemplo n.º 22
0
 public void Serialize(GMDataWriter writer)
 {
     writer.WritePointerString(Filename);
     writer.WritePointerString(FinalFunction);
     writer.WritePointerString(InitFunction);
     writer.Write((uint)Kind);
     Functions.Serialize(writer);
 }
Ejemplo n.º 23
0
 public void Serialize(GMDataWriter writer)
 {
     writer.WritePointerString(Name);
     writer.WriteWideBoolean(Smooth);
     writer.WriteWideBoolean(Closed);
     writer.Write(Precision);
     Points.Serialize(writer);
 }
Ejemplo n.º 24
0
 public void Serialize(GMDataWriter writer)
 {
     writer.Write(InternalCount);
     if (InternalCount > 0)
     {
         writer.WritePointerString(Event);
     }
 }
Ejemplo n.º 25
0
        public void Serialize(GMDataWriter writer)
        {
            writer.WritePointerString(Name);
            writer.Write(Length);

            if (writer.VersionInfo.FormatID <= 14)
            {
                BytecodeEntry.Serialize(writer);
            }
            else
            {
                writer.Write(LocalsCount);
                writer.Write((short)((int)ArgumentsCount | ((int)Flags << 13)));
                writer.Write(writer.PointerOffsets[BytecodeEntry] - writer.Offset);
                writer.Write(BytecodeOffset);
            }
        }
Ejemplo n.º 26
0
 public void Serialize(GMDataWriter writer)
 {
     writer.Write(List.Count);
     foreach (GMString str in List)
     {
         writer.WritePointerString(str);
     }
 }
Ejemplo n.º 27
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();
        }
Ejemplo n.º 28
0
            public void Serialize(GMDataWriter writer)
            {
                writer.WritePointerString(Name);
                writer.Write(ID);
                writer.Write((int)Kind);
                writer.Write(Depth);
                writer.Write(OffsetX); writer.Write(OffsetY);
                writer.Write(HSpeed); writer.Write(VSpeed);
                writer.WriteWideBoolean(Visible);
                switch (Kind)
                {
                case LayerKind.Background:
                    Background.Serialize(writer);
                    break;

                case LayerKind.Instances:
                    Instances.Serialize(writer);
                    break;

                case LayerKind.Assets:
                    Assets.Serialize(writer);
                    break;

                case LayerKind.Tiles:
                    Tiles.Serialize(writer);
                    break;

                default:
                    writer.Warnings.Add(new GMWarning($"Unknown layer kind {Kind}"));
                    break;
                }
            }
Ejemplo n.º 29
0
 public void Serialize(GMDataWriter writer)
 {
     writer.Write(Entries.Count);
     writer.WritePointerString(Name);
     for (int i = 0; i < Entries.Count; i++)
     {
         Entries[i].Serialize(writer);
     }
 }
Ejemplo n.º 30
0
        public void Serialize(GMDataWriter writer, bool includeName)
        {
            if (includeName)
            {
                writer.WritePointerString(Name);
            }
            writer.Write((uint)GraphType);

            Channels.Serialize(writer);
        }