/// <summary>
        /// Reads game information from GM file.
        /// </summary>
        public static GMGameInformation ReadGameInformation(GMFileReader reader)
        {
            // Get version.
            int version = reader.ReadGMInt();

            // Check version.
            if (version != 430 && version != 600 && version != 620 && version != 800)
            {
                throw new Exception("Unsupported Pre-Game Information object version.");
            }

            // Create new game information.
            GMGameInformation gameInfo = new GMGameInformation();

            // If version is 8.0, start inflate.
            if (version == 800)
            {
                reader.Decompress();
            }

            // Read game information data.
            gameInfo.BackgroundColor = reader.ReadGMInt();
            gameInfo.MimicGameWindow = reader.ReadGMBool();

            // Check version.
            if (version > 430)
            {
                // Read game information data.
                gameInfo.FormCaption = reader.ReadGMString();
                gameInfo.X           = reader.ReadGMInt();
                gameInfo.Y           = reader.ReadGMInt();
                gameInfo.Width       = reader.ReadGMInt();
                gameInfo.Height      = reader.ReadGMInt();
                gameInfo.ShowBorder  = reader.ReadGMBool();
                gameInfo.AllowResize = reader.ReadGMBool();
                gameInfo.AlwaysOnTop = reader.ReadGMBool();
                gameInfo.PauseGame   = reader.ReadGMBool();
            }

            // If version is 8.0, get last changed.
            if (version == 800)
            {
                gameInfo.LastChanged = reader.ReadGMDouble();
            }

            // Read game information data.
            gameInfo.Information = reader.ReadGMString();

            // End object inflate.
            reader.EndDecompress();

            // Return game information object.
            return(gameInfo);
        }
Beispiel #2
0
        /// <summary>
        /// Reads a Game Maker project file
        /// </summary>
        public void ReadProject(string file)
        {
            // If the file does not exist, throw exception
            if (File.Exists(file) == false)
            {
                throw new Exception("The Game Maker project file does not exist.");
            }

            // Get file extension
            string ext = file.Substring(file.LastIndexOf('.')).ToLower();

            // If a GMS project file
            if (ext == ".gmx")
            {
                // Read in the project as a Game Maker Studio project and return
                ReadProjectGMS(file);
                return;
            }

            // Get file size
            FileInfo info   = new FileInfo(file);
            long     length = info.Length;

            // Create a new GM file reader
            using (GMFileReader reader = new GMFileReader(new FileStream(file, FileMode.Open, FileAccess.Read)))
            {
                // Progress event
                ProgressChanged("Starting project read...", reader.BaseStream.Position, length);

                // Read the magic number
                int id = reader.ReadGMInt();

                // If the magic number was incorrect, not a Game Maker project file
                if (id != 1234321)
                {
                    throw new Exception("Not a valid Game Maker project file.");
                }

                // Get Game Maker project file version
                int version = reader.ReadGMInt();

                // Check version
                switch (version)
                {
                case 500: this.GameMakerVersion = GMVersionType.GameMaker50; break;

                case 510: this.GameMakerVersion = GMVersionType.GameMaker51; break;

                case 520: this.GameMakerVersion = GMVersionType.GameMaker52; break;

                case 530: this.GameMakerVersion = GMVersionType.GameMaker53; break;

                case 600: this.GameMakerVersion = GMVersionType.GameMaker60; break;

                case 701: this.GameMakerVersion = GMVersionType.GameMaker70; break;

                case 800: this.GameMakerVersion = GMVersionType.GameMaker80; break;

                case 810: this.GameMakerVersion = GMVersionType.GameMaker81; break;
                }

                // Skip over reserved bytes
                if (version < 600)
                {
                    reader.ReadGMBytes(4);
                }

                // Game Maker 7 project file encryption
                if (version == 701)
                {
                    // Bill and Fred, psssttt they like each other ;)
                    int bill = reader.ReadGMInt();
                    int fred = reader.ReadGMInt();

                    // Skip bytes to treasure.
                    reader.ReadGMBytes(bill * 4);

                    // Get the seed for swap table
                    int seed = reader.ReadGMInt();

                    // Skip bytes to get out of the junk yard
                    reader.ReadGMBytes(fred * 4);

                    // Read first byte of Game id (Not encrypted)
                    byte b = reader.ReadByte();

                    // Set the seed
                    reader.SetSeed(seed);

                    // Read game id
                    id = reader.ReadGMInt(b);
                }
                else  // Read game id normally
                {
                    id = reader.ReadGMInt();
                }

                // Skip unknown bytes
                reader.ReadGMBytes(16);

                // Read settings
                ProgressChanged("Reading Settings...", reader.BaseStream.Position, length);

                // Read main project objects
                this.Settings = GMSettings.ReadSettings(reader);
                this.Settings.GameIdentifier = id;

                // If the version is greater than Game Maker 7.0
                if (version > 701)
                {
                    // Read triggers and constants.
                    this.Triggers           = GMTrigger.ReadTriggers(reader);
                    this.Settings.Constants = GMConstant.ReadConstants(reader);
                }

                // Read sounds
                ProgressChanged("Reading Sounds...", reader.BaseStream.Position, length);
                this.Sounds = GMSound.ReadSounds(reader);

                // Read sprites
                ProgressChanged("Reading Sprites...", reader.BaseStream.Position, length);
                this.Sprites = GMSprite.ReadSprites(reader);

                // Read backgrounds
                ProgressChanged("Reading Backgrounds...", reader.BaseStream.Position, length);
                this.Backgrounds = GMBackground.ReadBackgrounds(reader);

                // Read paths
                ProgressChanged("Reading Paths...", reader.BaseStream.Position, length);
                this.Paths = GMPath.ReadPaths(reader);

                // Read scripts
                ProgressChanged("Reading Scripts...", reader.BaseStream.Position, length);
                this.Scripts = GMScript.ReadScripts(reader);

                // Get version
                int version2 = reader.ReadGMInt();

                // Check version
                if (version2 != 440 && version2 != 540 && version2 != 800)
                {
                    throw new Exception("Unsupported Pre-Font/Pre-Data File object version.");
                }

                // If version is old, read data files else, read fonts.
                if (version2 == 440)
                {
                    // Read data files
                    ProgressChanged("Reading Data Files...", reader.BaseStream.Position, length);
                    this.DataFiles = GMDataFile.ReadDataFiles(reader);
                }
                else
                {
                    // Read fonts
                    ProgressChanged("Reading Fonts...", reader.BaseStream.Position, length);
                    this.Fonts = GMFont.ReadFonts(version2, reader);
                }

                // Read timelines
                ProgressChanged("Reading Timelines...", reader.BaseStream.Position, length);
                this.Timelines = GMTimeline.ReadTimelines(reader);

                // Read objects
                ProgressChanged("Reading Objects...", reader.BaseStream.Position, length);
                this.Objects = GMObject.ReadObjects(reader);

                // Read rooms
                ProgressChanged("Reading Rooms...", reader.BaseStream.Position, length);
                this.Rooms = GMRoom.ReadRooms(this.Objects, reader);

                // Read last ids for instances and tiles
                this.LastInstanceId = reader.ReadGMInt();
                this.LastTileId     = reader.ReadGMInt();

                // If the version is above 6.1, read include files and packages
                if (version >= 700)
                {
                    // Read includes
                    ProgressChanged("Reading Includes...", reader.BaseStream.Position, length);
                    this.Settings.Includes = GMInclude.ReadIncludes(reader);

                    // Read packages
                    ProgressChanged("Reading Packages...", reader.BaseStream.Position, length);
                    this.Packages.AddRange(GMPackage.ReadPackages(reader));
                }

                // Read game information
                ProgressChanged("Reading Game Information...", reader.BaseStream.Position, length);
                this.GameInformation = GMGameInformation.ReadGameInformation(reader);

                // Get version
                version = reader.ReadGMInt();

                // Check version
                if (version != 500)
                {
                    throw new Exception("Unsupported Post-Game Information object version.");
                }

                // Read libraries
                ProgressChanged("Reading Libraries...", reader.BaseStream.Position, length);
                this.Libraries = GMLibrary.ReadLibraries(reader);

                // Read project tree
                ProgressChanged("Reading Project Tree...", reader.BaseStream.Position, length);
                this.ProjectTree = GMNode.ReadTree(file.Substring(file.LastIndexOf(@"\") + 1), reader);

                // Progress event
                ProgressChanged("Finished Reading Project.", reader.BaseStream.Position, length);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Reads game information from GM file.
        /// </summary>
        private GMGameInformation ReadGameInformation()
        {
            // Get version.
            int version = ReadInt();

            // Check version.
            if (version != 430 && version != 600 && version != 620 && version != 800)
                throw new Exception("Unsupported Pre-Game Information object version.");

            // Create new game information.
            GMGameInformation gameInfo = new GMGameInformation();

            // If version is 8.0, start inflate.
            if (version == 800)
                Decompress();

            // Read game information data.
            gameInfo.BackgroundColor = ReadInt();
            gameInfo.MimicGameWindow = ReadBool();

            // Check version.
            if (version > 430)
            {
                // Read game information data.
                gameInfo.FormCaption = ReadString();
                gameInfo.X = ReadInt();
                gameInfo.Y = ReadInt();
                gameInfo.Width = ReadInt();
                gameInfo.Height = ReadInt();
                gameInfo.ShowBorder = ReadBool();
                gameInfo.AllowResize = ReadBool();
                gameInfo.AlwaysOnTop = ReadBool();
                gameInfo.PauseGame = ReadBool();
            }

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

            // Read game information data.
            gameInfo.Information = ReadString();

            // End object inflate.
            EndDecompress();

            // Return game information object.
            return gameInfo;
        }
Beispiel #4
0
        /// <summary>
        /// Writes game information from Game Maker project.
        /// </summary>
        private void WriteGameInformation(GMGameInformation gameInfo, GMVersionType version)
        {
            // If version is 8.0, compress.
            if (version == GMVersionType.GameMaker80)
                Compress();

            // Write game information data.
            WriteInt(gameInfo.BackgroundColor);
            WriteBool(gameInfo.MimicGameWindow);

            // Versions greater than 5.3, support the following data.
            if (version > GMVersionType.GameMaker53)
            {
                // Write game information data.
                WriteString(gameInfo.FormCaption);
                WriteInt(gameInfo.X);
                WriteInt(gameInfo.Y);
                WriteInt(gameInfo.Width);
                WriteInt(gameInfo.Height);
                WriteBool(gameInfo.ShowBorder);
                WriteBool(gameInfo.AllowResize);
                WriteBool(gameInfo.AlwaysOnTop);
                WriteBool(gameInfo.PauseGame);
            }

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

            // Write game information data.
            WriteString(gameInfo.Information);

            // End object compression.
            EndCompress();
        }