示例#1
0
        /// <summary>
        /// Reads rooms from GM file
        /// </summary>
        private GMList<GMRoom> ReadRooms(GMList<GMObject> objects)
        {
            // Get version.
            int version = ReadInt();

            // Check version.
            if (version != 420 && version != 800)
                throw new Exception("Unsupported Pre-Room object version.");

            // Create a new list of rooms.
            GMList<GMRoom> rooms = new GMList<GMRoom>();

            // Amount of room indexes.
            int num = ReadInt();

            // Iterate through rooms.
            for (int i = 0; i < num; i++)
            {
                // If version is 8.0, start inflate.
                if (version == 800)
                    Decompress();

                // If the room at index does not exists, continue.
                if (ReadBool() == false)
                {
                    rooms.LastId++;
                    EndDecompress();
                    continue;
                }

                // Create a room object.
                GMRoom room = new GMRoom();

                // Set room id.
                room.Id = i;

                // Read room data.
                room.Name = ReadString();

                // If version is 8.0, get last changed.
                if (version == 800)
                    room.LastChanged = ReadDouble();

                // Get version.
                int version2 = ReadInt();

                // Check version.
                if (version2 != 500 && version2 != 520 && version2 != 541)
                    throw new Exception("Unsupported Room object version.");

                // Read room data.
                room.Caption = ReadString();
                room.Width = ReadInt();
                room.Height = ReadInt();
                room.SnapY = ReadInt();
                room.SnapX = ReadInt();

                // Versions greater than 5.1 support isometric grid.
                if (version2 > 500)
                    room.IsometricGrid = ReadBool();

                room.Speed = ReadInt();
                room.Persistent = ReadBool();
                room.BackgroundColor = ReadInt();
                room.DrawBackgroundColor = ReadBool();
                room.CreationCode = ReadString();

                // Create new parallax array.
                room.Parallaxes = new GMParallax[ReadInt()];

                // Iterate through parallaxs.
                for (int j = 0; j < room.Parallaxes.Length; j++)
                {
                    // Create a new parallax object.
                    room.Parallaxes[j] = new GMParallax();

                    // Read room parallax data.
                    room.Parallaxes[j].Visible = ReadBool();
                    room.Parallaxes[j].Foreground = ReadBool();
                    room.Parallaxes[j].BackgroundId = ReadInt();
                    room.Parallaxes[j].X = ReadInt();
                    room.Parallaxes[j].Y = ReadInt();
                    room.Parallaxes[j].TileHorizontally = ReadBool();
                    room.Parallaxes[j].TileVertically = ReadBool();
                    room.Parallaxes[j].HorizontalSpeed = ReadInt();
                    room.Parallaxes[j].VerticalSpeed = ReadInt();

                    // Versions greater than 5.1 support parallax stretching.
                    if (version2 > 500)
                        room.Parallaxes[j].Stretch = ReadBool();
                }

                // Read room data.
                room.EnableViews = ReadBool();

                // Create new view array.
                room.Views = new GMView[ReadInt()];

                // Iterate through views
                for (int k = 0; k < room.Views.Length; k++)
                {
                    // Create new view object.
                    room.Views[k] = new GMView();

                    // Read room view data.
                    room.Views[k].Visible = ReadBool();
                    room.Views[k].ViewX = ReadInt();
                    room.Views[k].ViewY = ReadInt();
                    room.Views[k].ViewWidth = ReadInt();
                    room.Views[k].ViewHeight = ReadInt();
                    room.Views[k].PortX = ReadInt();
                    room.Views[k].PortY = ReadInt();

                    // Versions greater than 5.3 support port dimensions.
                    if (version2 > 520)
                    {
                        room.Views[k].PortWidth = ReadInt();
                        room.Views[k].PortHeight = ReadInt();
                    }

                    // Read room view data.
                    room.Views[k].HorizontalBorder = ReadInt();
                    room.Views[k].VerticalBorder = ReadInt();
                    room.Views[k].HorizontalSpeed = ReadInt();
                    room.Views[k].VerticalSpeed = ReadInt();
                    room.Views[k].ObjectToFollow = ReadInt();
                }

                // Create a new array of instances.
                room.Instances = new GMInstance[ReadInt()];

                // Iterate through room instances.
                for (int l = 0; l < room.Instances.Length; l++)
                {
                    // Create new instance.
                    room.Instances[l] = new GMInstance();

                    // Read room instance data.
                    room.Instances[l].X = ReadInt();
                    room.Instances[l].Y = ReadInt();
                    room.Instances[l].ObjectId = ReadInt();
                    room.Instances[l].Id = ReadInt();

                    // Versions greater than 5.1 support creation code and instance locking.
                    if (version2 > 500)
                    {
                        // Read room instance data.
                        room.Instances[l].CreationCode = ReadString();
                        room.Instances[l].Locked = ReadBool();
                    }

                    // Get the object the instance references.
                    GMObject obj = objects.Find(delegate(GMObject o) { return o.Id == room.Instances[l].ObjectId; });

                    // If the object was found, set instance name and depth.
                    if (obj != null)
                    {
                        // Read room instance data.
                        room.Instances[l].Name = obj.Name;
                        room.Instances[l].Depth = obj.Depth;
                    }

                    // Skipped reserved bytes.
                    if (version2 < 520)
                        ReadBytes(8);
                }

                // Create a new array of tiles.
                room.Tiles = new GMTile[ReadInt()];

                // Iterate through room tiles.
                for (int m = 0; m < room.Tiles.Length; m++)
                {
                    // Create new tile object.
                    room.Tiles[m] = new GMTile();

                    // Read room tile data.
                    room.Tiles[m].X = ReadInt();
                    room.Tiles[m].Y = ReadInt();
                    room.Tiles[m].BackgroundId = ReadInt();
                    room.Tiles[m].BackgroundX = ReadInt();
                    room.Tiles[m].BackgroundY = ReadInt();
                    room.Tiles[m].Width = ReadInt();
                    room.Tiles[m].Height = ReadInt();
                    room.Tiles[m].Depth = ReadInt();
                    room.Tiles[m].Id = ReadInt();

                    // Versions greater than 5.1 support tile locking.
                    if (version2 > 500)
                        room.Tiles[m].Locked = ReadBool();
                }

                // Read room data.
                room.RememberWindowSize = ReadBool();
                room.EditorWidth = ReadInt();
                room.EditorHeight = ReadInt();
                room.ShowGrid = ReadBool();
                room.ShowObjects = ReadBool();
                room.ShowTiles = ReadBool();
                room.ShowBackgrounds = ReadBool();
                room.ShowForegrounds = ReadBool();
                room.ShowViews = ReadBool();
                room.DeleteUnderlyingObjects = ReadBool();
                room.DeleteUnderlyingTiles = ReadBool();

                // Versions greater than 5.3 don't support tile settings.
                if (version2 > 520)
                {
                    // Read room tile data.
                    room.CurrentTab = (TabSetting)(ReadInt());
                    room.ScrollBarX = ReadInt();
                    room.ScrollBarY = ReadInt();
                }
                else
                {
                    // Read room tile data.
                    room.TileWidth = ReadInt();
                    room.TileHeight = ReadInt();
                    room.TileHorizontalSeperation = ReadInt();
                    room.TileVerticalSeperation = ReadInt();
                    room.TileHorizontalOffset = ReadInt();
                    room.TileVerticalOffset = ReadInt();
                    room.CurrentTab = (TabSetting)(ReadInt());
                    room.ScrollBarX = ReadInt();
                    room.ScrollBarY = ReadInt();
                }

                // End object inflate.
                EndDecompress();

                // Set room.
                rooms.Add(room);
            }

            // Return rooms
            return rooms;
        }
示例#2
0
        /// <summary>
        /// Writes objects from Game Maker project.
        /// </summary>
        private void WriteObjects(GMList<GMObject> objects, GMVersionType version)
        {
            // Write version number.
            if (version < GMVersionType.GameMaker80)
                WriteInt(400);
            else
                WriteInt(800);

            // Write the amount of object ids.
            WriteInt(objects.LastId + 1);

            // Iterate through objects
            for (int i = 0; i < objects.LastId + 1; i++)
            {
                // If version is 8.0, compress.
                if (version == GMVersionType.GameMaker80)
                    Compress();

                // Try to get the resource with the current id.
                GMObject obj = objects.Find(delegate(GMObject o) { return o.Id == i; });

                // If the resource at index does not exist, continue.
                if (obj == null)
                {
                    // No object exists at this id.
                    WriteBool(false);
                    EndCompress();
                    continue;
                }
                else
                    WriteBool(true);

                // Write object name.
                WriteString(obj.Name);

                // If version is 8.0, write last changed.
                if (version == GMVersionType.GameMaker80)
                    WriteDouble(obj.LastChanged);

                // Write version.
                WriteInt(430);

                // Write object data.
                WriteInt(obj.SpriteId);
                WriteBool(obj.Solid);
                WriteBool(obj.Visible);
                WriteInt(obj.Depth);
                WriteBool(obj.Persistent);
                WriteInt(obj.Parent);
                WriteInt(obj.Mask);

                // The amount of main event types.
                int amount = 11;

                // If version is 8.0.
                if (version == GMVersionType.GameMaker80)
                {
                    // 12 main events.
                    amount = 12;

                    // Write int.
                    WriteInt(11);
                }
                else  // Write int.
                    WriteInt(10);

                // Iterate through event types.
                for (int j = 0; j < amount; j++)
                {
                    // Iterate through object events.
                    foreach (GMEvent ev in obj.Events[j])
                    {
                        // If the event has actions in it, write the actions.
                        if (ev.Actions != null)
                        {
                            // Check if the event's type is a collision event, set other's id.
                            if (ev.MainType == EventType.Collision)
                                WriteInt(ev.OtherId);
                            else
                                WriteInt(ev.SubType);

                            // Write the event actions.
                            WriteActions(ev.Actions, version);
                        }
                    }

                    // End of event.
                    WriteInt(-1);
                }

                // End object compression.
                EndCompress();
            }
        }
示例#3
0
        /// <summary>
        /// Writes paths from Game Maker project.
        /// </summary>
        private void WritePaths(GMList<GMPath> paths, GMVersionType version)
        {
            // Write version number.
            if (version < GMVersionType.GameMaker80)
                WriteInt(420);
            else
                WriteInt(800);

            // Amount of path ids.
            WriteInt(paths.LastId + 1);

            // Iterate through paths.
            for (int i = 0; i < paths.LastId + 1; i++)
            {
                // If version is 8.0, compress.
                if (version == GMVersionType.GameMaker80)
                    Compress();

                // Try to get the resource by the current id.
                GMPath path = paths.Find(delegate(GMPath p) { return p.Id == i; });

                // If the path at index does not exists, continue.
                if (path == null)
                {
                    // No object exists at this id.
                    WriteBool(false);
                    EndCompress();
                    continue;
                }
                else
                    WriteBool(true);

                // Write path data.
                WriteString(path.Name);

                // If version is 8.0, write last changed.
                if (version == GMVersionType.GameMaker80)
                    WriteDouble(path.LastChanged);

                // Write version.
                if (version < GMVersionType.GameMaker53)
                    WriteInt(420);
                else
                    WriteInt(530);

                // Versions greater than 5.2, support the following variables.
                if (version > GMVersionType.GameMaker52)
                {
                    // Write path data.
                    WriteBool(path.Smooth);
                    WriteBool(path.Closed);
                    WriteInt(path.Precision);
                    WriteInt(path.RoomId);
                    WriteInt(path.SnapX);
                    WriteInt(path.SnapY);
                }
                else
                {
                    // Write path data.
                    WriteBool(path.Smooth);
                    WriteInt((int)path.ActionAtTheEnd);
                    WriteEmpty(4);
                }

                // If there are points to write.
                if (path.Points != null)
                {
                    // Write number of points.
                    WriteInt(path.Points.Length);

                    // Iterate through path points.
                    for (int j = 0; j < path.Points.Length; j++)
                    {
                        // Write point data.
                        WriteDouble(path.Points[j].X);
                        WriteDouble(path.Points[j].Y);
                        WriteDouble(path.Points[j].Speed);
                    }
                }
                else  // There are no points to write.
                    WriteInt(0);

                // End compression.
                EndCompress();
            }
        }
示例#4
0
        /// <summary>
        /// Writes data files from Game Maker project.
        /// </summary>
        private void WriteDataFiles(GMList<GMDataFile> dataFiles, GMVersionType version)
        {
            // If the version is greater than 5.3, return.
            if (version > GMVersionType.GameMaker53)
                return;

            // Write version.
            WriteInt(440);

            // Write amount of script ids.
            WriteInt(dataFiles.LastId + 1);

            // Iterate through data files.
            for (int i = 0; i < dataFiles.LastId + 1; i++)
            {
                // Try to get the resource by the current id.
                GMDataFile dataFile = dataFiles.Find(delegate(GMDataFile d) { return d.Id == i; });

                // If the script at current id does not exists, continue.
                if (dataFile == null)
                {
                    // No object exists at this id.
                    WriteBool(false);
                    continue;
                }
                else
                    WriteBool(true);

                // Write data file name.
                WriteString(dataFile.Name);

                // Write version.
                WriteInt(440);

                // Write data file data.
                WriteString(dataFile.FileName);

                // If data file exists.
                if (dataFile.Data != null)
                {
                    // Data exists.
                    WriteBool(true);

                    // Write the size of the data file.
                    WriteInt(dataFile.Data.Length);

                    // Write data file data.
                    WriteBytes(dataFile.Data);
                }
                else  // Data does not exist.
                    WriteBool(false);

                // Write data file data.
                WriteInt((int)dataFile.ExportMode);
                WriteBool(dataFile.OverwriteFile);
                WriteBool(dataFile.FreeDataMemory);
                WriteBool(dataFile.RemoveAtGameEnd);
            }
        }
示例#5
0
        /// <summary>
        /// Writes fonts from Game Maker project.
        /// </summary>
        private void WriteFonts(GMList<GMFont> fonts, GMVersionType version)
        {
            // If the version is before Game Maker 6, return.
            if (version < GMVersionType.GameMaker60)
                return;

            // Write version number.
            if (version < GMVersionType.GameMaker80)
                WriteInt(540);
            else
                WriteInt(800);

            // Amount of font ids.
            WriteInt(fonts.LastId + 1);

            // Iterate through fonts.
            for (int i = 0; i < fonts.LastId + 1; i++)
            {
                // If version is 8.0, compress.
                if (version == GMVersionType.GameMaker80)
                    Compress();

                // Try to get the resource with the current id.
                GMFont font = fonts.Find(delegate(GMFont f) { return f.Id == i; });

                // If the resource at index does not exist, continue.
                if (font == null)
                {
                    // No object exists at this id.
                    WriteBool(false);
                    EndCompress();
                    continue;
                }
                else
                    WriteBool(true);

                // Write font name.
                WriteString(font.Name);

                // If version is 8.0, write last changed.
                if (version == GMVersionType.GameMaker80)
                    WriteDouble(font.LastChanged);

                // Write version.
                if (version == GMVersionType.GameMaker80)
                    WriteInt(800);
                else
                WriteInt(540);

                // Write font data.
                WriteString(font.FontName);
                WriteInt(font.Size);
                WriteBool(font.Bold);
                WriteBool(font.Italic);
                WriteInt(font.CharacterRangeMin);
                WriteInt(font.CharacterRangeMax);

                // End object compression.
                EndCompress();
            }
        }
示例#6
0
        /// <summary>
        /// Writes Game Maker project triggers.
        /// </summary>
        private void WriteTriggers(GMList<GMTrigger> triggers, GMVersionType version)
        {
            // Write version number.
            WriteInt((int)version);

            // Write amount of triggers.
            WriteInt(triggers.LastId + 1);

            // Iterate through triggers.
            for (int i = 0; i < triggers.LastId + 1; i++)
            {
                // Start compress.
                Compress();

                // Try to get the resource by the current id.
                GMTrigger trigger = triggers.Find(delegate(GMTrigger t) { return t.Id == i; });

                // If the sound with the current id does not exist, continue.
                if (trigger == null)
                {
                    // No object exists at this id.
                    WriteBool(false);
                    EndCompress();
                    continue;
                }
                else
                    WriteBool(true);

                // Write version number.
                WriteInt((int)version);

                // Write trigger data.
                WriteString(trigger.Name);
                WriteString(trigger.Condition);
                WriteInt((int)trigger.Moment);
                WriteString(trigger.Constant);

                // End compress.
                EndCompress();
            }

            // Write last changed.
            WriteDouble(GMTrigger.TriggerLastChanged);
        }
示例#7
0
        /// <summary>
        /// Writes backgrounds from Game Maker project.
        /// </summary>
        private void WriteBackgrounds(GMList<GMBackground> backgrounds, GMVersionType version)
        {
            // Write version number.
            if (version < GMVersionType.GameMaker80)
                WriteInt(400);
            else
                WriteInt(800);

            // Amount of background ids.
            WriteInt(backgrounds.LastId + 1);

            // Iterate through backgrounds.
            for (int i = 0; i < backgrounds.LastId + 1; i++)
            {
                // If version is 8.0, compress.
                if (version == GMVersionType.GameMaker80)
                    Compress();

                // Try to get the resource by the current id.
                GMBackground background = backgrounds.Find(delegate(GMBackground b) { return b.Id == i; });

                // If the background at index does not exists, continue.
                if (background == null)
                {
                    // No object exists at this id.
                    WriteBool(false);
                    EndCompress();
                    continue;
                }
                else
                    WriteBool(true);

                // Get background data.
                WriteString(background.Name);

                // If version is 8.0, write last changed.
                if (version == GMVersionType.GameMaker80)
                    WriteDouble(background.LastChanged);

                // Write version number.
                if (version < GMVersionType.GameMaker60)
                    WriteInt(400);
                else if (version == GMVersionType.GameMaker60 || version == GMVersionType.GameMaker70)
                    WriteInt(543);
                else if (version == GMVersionType.GameMaker80)
                    WriteInt(710);

                // If version is less than GM 8.0.
                if (version < GMVersionType.GameMaker80)
                {
                    // Write background data
                    WriteInt(background.Width);
                    WriteInt(background.Height);
                    WriteBool(background.Transparent);

                    // Check version.
                    if (version > GMVersionType.GameMaker53)
                    {
                        // Write background data.
                        WriteBool(background.SmoothEdges);
                        WriteBool(background.Preload);
                        WriteBool(background.UseAsTileSet);
                        WriteInt(background.TileWidth);
                        WriteInt(background.TileHeight);
                        WriteInt(background.HorizontalOffset);
                        WriteInt(background.VerticalOffset);
                        WriteInt(background.HorizontalSeperation);
                        WriteInt(background.VerticalSeperation);
                    }
                    else
                    {
                        // Write background data.
                        WriteBool(background.UseVideoMemory);
                        WriteBool(background.LoadOnlyOnUse);
                    }

                    // If image data does not exist.
                    if (background.Image != null)
                    {
                        // There is image data, write flags.
                        WriteBool(true);
                        WriteInt(10);

                        // Write size of image data.
                        WriteInt(background.Image.Data.Length);

                        // Write image data.
                        WriteBytes(background.Image.Data);

                    }  // No image data exist.
                    else
                        WriteBool(false);
                }
                else  // GM 8.0.
                {
                    // Write background data.
                    WriteBool(background.UseAsTileSet);
                    WriteInt(background.TileWidth);
                    WriteInt(background.TileHeight);
                    WriteInt(background.HorizontalOffset);
                    WriteInt(background.VerticalOffset);
                    WriteInt(background.HorizontalSeperation);
                    WriteInt(background.VerticalSeperation);

                    // Write version.
                    WriteInt(800);

                    // Write background data.
                    WriteInt(background.Width);
                    WriteInt(background.Height);

                    // If the sprite size is not zero, write image data.
                    if (background.Width != 0 && background.Height != 0)
                    {
                        WriteInt(background.Image.Data.Length);
                        WriteBytes(background.Image.Data);
                    }
                }

                // End compression.
                EndCompress();
            }
        }
示例#8
0
        /// <summary>
        /// Writes timelines from Game Maker project.
        /// </summary>
        private void WriteTimelines(GMList<GMTimeline> timelines, GMVersionType version)
        {
            // Write version number.
            if (version < GMVersionType.GameMaker80)
                WriteInt(500);
            else
                WriteInt(800);

            // Write the amount of timeline ids.
            WriteInt(timelines.LastId + 1);

            // Iterate through timelines.
            for (int i = 0; i < timelines.LastId + 1; i++)
            {
                // If version is 8.0, compress.
                if (version == GMVersionType.GameMaker80)
                    Compress();

                // Try to get the resource with the current id.
                GMTimeline timeline = timelines.Find(delegate(GMTimeline t) { return t.Id == i; });

                // If the resource at index does not exist, continue.
                if (timeline == null)
                {
                    // No object exists at this id.
                    WriteBool(false);
                    EndCompress();
                    continue;
                }
                else
                    WriteBool(true);

                // Write timeline name.
                WriteString(timeline.Name);

                // If version is 8.0, write last changed.
                if (version == GMVersionType.GameMaker80)
                    WriteDouble(timeline.LastChanged);

                // Write version.
                WriteInt(500);

                // If there are moments to write.
                if (timeline.Moments != null)
                {
                    // Write number of timeline moments.
                    WriteInt(timeline.Moments.Length);

                    // Iterate through moments.
                    for (int j = 0; j < timeline.Moments.Length; j++)
                    {
                        // Write moment step number.
                        WriteInt(timeline.Moments[j].StepIndex);

                        // Write moment actions.
                        WriteActions(timeline.Moments[j].Actions, version);
                    }
                }
                else  // There are no moments.
                    WriteInt(0);

                // End object compression.
                EndCompress();
            }
        }
示例#9
0
        /// <summary>
        /// Writes sprites from Game Maker project.
        /// </summary>
        private void WriteSprites(GMList<GMSprite> sprites, GMVersionType version)
        {
            // Write version number.
            if (version < GMVersionType.GameMaker80)
                WriteInt(400);
            else
                WriteInt(800);

            // Write number of sprite ids.
            WriteInt(sprites.LastId + 1);

            // Iterate through sprites.
            for (int i = 0; i < sprites.LastId + 1; i++)
            {
                // If version is 8.0, compress.
                if (version == GMVersionType.GameMaker80)
                    Compress();

                // Try to get the resource by the current id.
                GMSprite sprite = sprites.Find(delegate(GMSprite s) { return s.Id == i; });

                // If the sprite with the current id does not exist, continue.
                if (sprite == null)
                {
                    // No object exists at this id.
                    WriteBool(false);
                    EndCompress();
                    continue;
                }
                else
                    WriteBool(true);

                // Write sprite data.
                WriteString(sprite.Name);

                // If version is 8.0, write last changed.
                if (version == GMVersionType.GameMaker80)
                    WriteDouble(sprite.LastChanged);

                // Write version number.
                if (version < GMVersionType.GameMaker60)
                    WriteInt(400);
                else if (version == GMVersionType.GameMaker70 || version == GMVersionType.GameMaker60)
                    WriteInt(542);
                else if (version == GMVersionType.GameMaker80)
                    WriteInt(800);

                if (version < GMVersionType.GameMaker80)
                {
                    // Write sprite data
                    WriteInt(sprite.Width);
                    WriteInt(sprite.Height);
                    WriteInt(sprite.BoundingBoxLeft);
                    WriteInt(sprite.BoundingBoxRight);
                    WriteInt(sprite.BoundingBoxBottom);
                    WriteInt(sprite.BoundingBoxTop);
                    WriteBool(sprite.Transparent);

                    // Check version.
                    if (version > GMVersionType.GameMaker53)
                    {
                        // Write sprite data.
                        WriteBool(sprite.SmoothEdges);
                        WriteBool(sprite.Preload);
                    }

                    // Write sprite data.
                    WriteInt((int)sprite.BoundingBoxMode);
                    WriteBool(sprite.Precise);

                    // Check version.
                    if (version < GMVersionType.GameMaker60)
                    {
                        // Write sprite data.
                        WriteBool(sprite.UseVideoMemory);
                        WriteBool(sprite.LoadOnlyOnUse);
                    }

                    // Write sprite data.
                    WriteInt(sprite.OriginX);
                    WriteInt(sprite.OriginY);

                    // If there are sub-images to write.
                    if (sprite.SubImages != null)
                    {
                        // Write number of sub images.
                        WriteInt(sprite.SubImages.Length);

                        // Iterate through sub-images.
                        for (int j = 0; j < sprite.SubImages.Length; j++)
                        {
                            // If the sub-image at index does not exists, continue.
                            if (sprite.SubImages[j] == null)
                            {
                                // No object exists at this id.
                                WriteInt(-1);
                                continue;
                            }
                            else  // There's image data.
                                WriteInt(10);

                            // Write size of image data.
                            WriteInt(sprite.SubImages[j].Data.Length);

                            // Write image data.
                            WriteBytes(sprite.SubImages[j].Data);
                        }
                    }
                    else  // There are no sub-images to write.
                        WriteInt(0);
                }
                else  // Game Maker 8.0.
                {
                    // Write sprite data.
                    WriteInt(sprite.OriginX);
                    WriteInt(sprite.OriginY);

                    // Sprite number of sub images.
                    WriteInt(sprite.SubImages.Length);

                    // Iterate through sub-images.
                    for (int j = 0; j < sprite.SubImages.Length; j++)
                    {
                        // Write version.
                        WriteInt(800);

                        // Write width and height of image.
                        WriteInt(sprite.SubImages[j].Width);
                        WriteInt(sprite.SubImages[j].Height);

                        // If the image data is not size zero.
                        if (sprite.SubImages[j].Width != 0 && sprite.SubImages[j].Height != 0)
                        {
                            WriteInt(sprite.SubImages[j].Data.Length);
                            WriteBytes(sprite.SubImages[j].Data);
                        }
                    }

                    // Write sprite data.
                    WriteInt((int)sprite.ShapeMode);
                    WriteInt(sprite.AlphaTolerance);
                    WriteBool(sprite.UseSeperateCollisionMasks);
                    WriteInt((int)sprite.BoundingBoxMode);
                    WriteInt(sprite.BoundingBoxLeft);
                    WriteInt(sprite.BoundingBoxRight);
                    WriteInt(sprite.BoundingBoxBottom);
                    WriteInt(sprite.BoundingBoxTop);
                }

                // End compression.
                EndCompress();
            }
        }
示例#10
0
        /// <summary>
        /// Writes sounds from Game Maker project.
        /// </summary>
        /// <param name="sounds">Sounds array to write.</param>
        /// <param name="version">Target Game Maker file version to write.</param>
        private void WriteSounds(GMList<GMSound> sounds, GMVersionType version)
        {
            // Write version number.
            if (version < GMVersionType.GameMaker80)
                WriteInt(400);
            else
                WriteInt(800);

            // Write number of sound ids.
            WriteInt(sounds.LastId + 1);

            // Iterate through sound ids.
            for (int i = 0; i < sounds.LastId + 1; i++)
            {
                // If version is 8.0, compress.
                if (version == GMVersionType.GameMaker80)
                    Compress();

                // Try to get the resource by the current id.
                GMSound sound = sounds.Find(delegate(GMSound s) { return s.Id == i; });

                // If the sound with the current id does not exist, continue.
                if (sound == null)
                {
                    // No object exists at this id.
                    WriteBool(false);
                    EndCompress();
                    continue;
                }
                else
                    WriteBool(true);

                // Write sound data.
                WriteString(sound.Name);

                // If version is 8.0, write last changed.
                if (version == GMVersionType.GameMaker80)
                    WriteDouble(sound.LastChanged);

                // Write version number.
                if (version < GMVersionType.GameMaker60)
                {
                    WriteInt(440);
                    WriteInt((int)sound.Kind);
                }
                else if (version == GMVersionType.GameMaker80)
                {
                    WriteInt(800);
                    WriteInt((int)sound.Type);
                }
                else
                {
                    WriteInt(600);
                    WriteInt((int)sound.Type);
                }

                // Write sound data.
                WriteString(sound.FileType);

                // Versions less than 6.0, have different sound data.
                if (version < GMVersionType.GameMaker60)
                {
                    // If sound data exists, read it.
                    if (sound.Kind != SoundKind.None)
                    {
                        // Write sound data.
                        WriteInt(sound.Data.Length);
                        WriteBytes(sound.Data);
                    }

                    // Write sound data.
                    WriteBool(sound.AllowSoundEffects);
                    WriteInt(sound.Buffers);
                    WriteBool(sound.Preload);
                }
                else
                {
                    // Write sound data.
                    WriteString(sound.FileName);

                    // If sound data exists, write it.
                    if (sound.Data != null)
                    {
                        // Write sound data.
                        WriteBool(true);
                        WriteInt(sound.Data.Length);
                        WriteBytes(sound.Data);
                    }
                    else
                        WriteBool(false);

                    // Write sound data.
                    WriteInt(sound.Effects);
                    WriteDouble(sound.Volume);
                    WriteDouble(sound.Pan);
                    WriteBool(sound.Preload);
                }

                // End compression.
                EndCompress();
            }
        }
示例#11
0
        /// <summary>
        /// Writes scripts from Game Maker project.
        /// </summary>
        private void WriteScripts(GMList<GMScript> scripts, GMVersionType version)
        {
            // Write version number.
            if (version < GMVersionType.GameMaker80)
                WriteInt(400);
            else
                WriteInt(800);

            // Write amount of script ids.
            WriteInt(scripts.LastId + 1);

            // Iterate through scripts.
            for (int i = 0; i < scripts.LastId + 1; i++)
            {
                // If version is 8.0, compress.
                if (version == GMVersionType.GameMaker80)
                    Compress();

                // Try to get the resource by the current id.
                GMScript script = scripts.Find(delegate(GMScript s) { return s.Id == i; });

                // If the script at the current id does not exist, continue.
                if (script == null)
                {
                    // No object exists at this id.
                    WriteBool(false);
                    EndCompress();
                    continue;
                }
                else
                    WriteBool(true);

                // Write script name.
                WriteString(script.Name);

                // If version is 8.0, write last changed.
                if (version == GMVersionType.GameMaker80)
                    WriteDouble(script.LastChanged);

                // Write version.
                if (version == GMVersionType.GameMaker80)
                    WriteInt(800);
                else
                    WriteInt(400);

                // Write script data.
                WriteString(script.Code);

                // End compression.
                EndCompress();
            }
        }
示例#12
0
        /// <summary>
        /// Writes rooms from Game Maker project.
        /// </summary>
        private void WriteRooms(GMList<GMRoom> rooms, GMVersionType version)
        {
            // Write version number.
            if (version < GMVersionType.GameMaker80)
                WriteInt(420);
            else
                WriteInt(800);

            // Write the amount of room ids.
            WriteInt(rooms.LastId + 1);

            // Iterate through rooms.
            for (int i = 0; i < rooms.LastId + 1; i++)
            {
                // If version is 8.0, compress.
                if (version == GMVersionType.GameMaker80)
                    Compress();

                // Try to get the resource with the current id.
                GMRoom room = rooms.Find(delegate(GMRoom r) { return r.Id == i; });

                // If the resource at index does not exist, continue.
                if (room == null)
                {
                    // No object exists at this id.
                    WriteBool(false);
                    EndCompress();
                    continue;
                }
                else
                    WriteBool(true);

                // Write room name.
                WriteString(room.Name);

                // If version is 8.0, write last changed.
                if (version == GMVersionType.GameMaker80)
                    WriteDouble(room.LastChanged);

                // Write version.
                switch (version)
                {
                    case GMVersionType.GameMaker50: WriteInt(500); break;
                    case GMVersionType.GameMaker51: WriteInt(500); break;
                    case GMVersionType.GameMaker52: WriteInt(520); break;
                    case GMVersionType.GameMaker53: WriteInt(520); break;
                    case GMVersionType.GameMaker60: WriteInt(541); break;
                    case GMVersionType.GameMaker70: WriteInt(541); break;
                    case GMVersionType.GameMaker80: WriteInt(541); break;
                }

                // Write room data.
                WriteString(room.Caption);
                WriteInt(room.Width);
                WriteInt(room.Height);
                WriteInt(room.SnapY);
                WriteInt(room.SnapX);

                // Versions greater than 5.1 support isometric grid.
                if (version > GMVersionType.GameMaker51)
                    WriteBool(room.IsometricGrid);

                WriteInt(room.Speed);
                WriteBool(room.Persistent);
                WriteInt(room.BackgroundColor);
                WriteBool(room.DrawBackgroundColor);
                WriteString(room.CreationCode);

                // Write the amount of room parallaxes.
                WriteInt(8);

                // Iterate through parallaxs.
                for (int j = 0; j < room.Parallaxes.Length; j++)
                {
                    // Write room parallax data.
                    WriteBool(room.Parallaxes[j].Visible);
                    WriteBool(room.Parallaxes[j].Foreground);
                    WriteInt(room.Parallaxes[j].BackgroundId);
                    WriteInt(room.Parallaxes[j].X);
                    WriteInt(room.Parallaxes[j].Y);
                    WriteBool(room.Parallaxes[j].TileHorizontally);
                    WriteBool(room.Parallaxes[j].TileVertically);
                    WriteInt(room.Parallaxes[j].HorizontalSpeed);
                    WriteInt(room.Parallaxes[j].VerticalSpeed);

                    // Versions greater than 5.1 support parallax stretching.
                    if (version > GMVersionType.GameMaker51)
                        WriteBool(room.Parallaxes[j].Stretch);
                }

                // Write room data.
                WriteBool(room.EnableViews);

                // Write the amount of room views.
                WriteInt(8);

                // Iterate through views
                for (int k = 0; k < room.Views.Length; k++)
                {
                    // Write room view data.
                    WriteBool(room.Views[k].Visible);
                    WriteInt(room.Views[k].ViewX);
                    WriteInt(room.Views[k].ViewY);
                    WriteInt(room.Views[k].ViewWidth);
                    WriteInt(room.Views[k].ViewHeight);
                    WriteInt(room.Views[k].PortX);
                    WriteInt(room.Views[k].PortY);

                    // Versions greater than 5.3 support port dimensions.
                    if (version > GMVersionType.GameMaker53)
                    {
                        // Write room view data.
                        WriteInt(room.Views[k].PortWidth);
                        WriteInt(room.Views[k].PortHeight);
                    }

                    // Write room view data.
                    WriteInt(room.Views[k].HorizontalBorder);
                    WriteInt(room.Views[k].VerticalBorder);
                    WriteInt(room.Views[k].HorizontalSpeed);
                    WriteInt(room.Views[k].VerticalSpeed);
                    WriteInt(room.Views[k].ObjectToFollow);
                }

                // If there are instances to write.
                if (room.Instances != null)
                {
                    // Write the amount of instances.
                    WriteInt(room.Instances.Length);

                    // Iterate through room instances.
                    for (int l = 0; l < room.Instances.Length; l++)
                    {
                        // Write room instance data.
                        WriteInt(room.Instances[l].X);
                        WriteInt(room.Instances[l].Y);
                        WriteInt(room.Instances[l].ObjectId);
                        WriteInt(room.Instances[l].Id);

                        // Versions greater than 5.1 support creation code and instance locking.
                        if (version > GMVersionType.GameMaker51)
                        {
                            WriteString(room.Instances[l].CreationCode);
                            WriteBool(room.Instances[l].Locked);
                        }

                        // Write empty reserved bytes.
                        if (version < GMVersionType.GameMaker52)
                            WriteEmpty(8);
                    }
                }
                else  // Write no instances.
                    WriteInt(0);

                // If there are tiles to write.
                if (room.Tiles != null)
                {
                    // Write the amount of room tiles.
                    WriteInt(room.Tiles.Length);

                    // Iterate through room tiles.
                    for (int m = 0; m < room.Tiles.Length; m++)
                    {
                        // Write room tile data.
                        WriteInt(room.Tiles[m].X);
                        WriteInt(room.Tiles[m].Y);
                        WriteInt(room.Tiles[m].BackgroundId);
                        WriteInt(room.Tiles[m].BackgroundX);
                        WriteInt(room.Tiles[m].BackgroundY);
                        WriteInt(room.Tiles[m].Width);
                        WriteInt(room.Tiles[m].Height);
                        WriteInt(room.Tiles[m].Depth);
                        WriteInt(room.Tiles[m].Id);

                        // Versions greater than 5.1 support tile locking.
                        if (version > GMVersionType.GameMaker51)
                            WriteBool(room.Tiles[m].Locked);
                    }
                }
                else  // Write no tiles.
                    WriteInt(0);

                // Write room data.
                WriteBool(room.RememberWindowSize);
                WriteInt(room.EditorWidth);
                WriteInt(room.EditorHeight);
                WriteBool(room.ShowGrid);
                WriteBool(room.ShowObjects);
                WriteBool(room.ShowTiles);
                WriteBool(room.ShowBackgrounds);
                WriteBool(room.ShowForegrounds);
                WriteBool(room.ShowViews);
                WriteBool(room.DeleteUnderlyingObjects);
                WriteBool(room.DeleteUnderlyingTiles);

                // Versions greater than 5.3 don't support tile settings.
                if (version > GMVersionType.GameMaker53)
                {
                    // Write room data.
                    WriteInt((int)room.CurrentTab);
                    WriteInt(room.ScrollBarX);
                    WriteInt(room.ScrollBarY);
                }
                else
                {
                    // Write room data.
                    WriteInt(room.TileWidth);
                    WriteInt(room.TileHeight);
                    WriteInt(room.TileHorizontalSeperation);
                    WriteInt(room.TileVerticalSeperation);
                    WriteInt(room.TileHorizontalOffset);
                    WriteInt(room.TileVerticalOffset);
                    WriteInt((int)room.CurrentTab);
                    WriteInt(room.ScrollBarX);
                    WriteInt(room.ScrollBarY);
                }

                // End object compression.
                EndCompress();
            }
        }