Ejemplo n.º 1
0
 public static void Constant(ProjectWriter writer, GMConstant self, GMProject _)
 {
     writer.Write(self.Name);
     writer.Write(self.Value);
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Reads game settings from GM file.
        /// </summary>
        private GMSettings ReadSettings()
        {
            // Create a new game maker settings object.
            GMSettings settings = new GMSettings();

            // Get Game Settings object version.
            int version = ReadInt();

            // Check version.
            if (version != 500 && version != 510 && version != 520 && version != 530 && version != 542 &&
                version != 600 && version != 702 && version != 800)
                throw new Exception("Unsupported Game Settings object version.");

            // If version is GM8, start inflater stream.
            if (version == 800)
                Decompress();

            // Read settings data
            settings.StartFullscreen = ReadBool();

            // Versions greater than 5.3 support interpolation.
            if (version > 542)
                settings.Interpolate = ReadBool();

            // Read settings data.
            settings.DontDrawBorder = ReadBool();
            settings.DisplayCursor = ReadBool();

            // Versions greater than 5.3 support the below variables.
            if (version > 530)
            {
                // Read settings data.
                settings.Scaling = ReadInt();
                settings.AllowWindowResize = ReadBool();
                settings.AlwaysOnTop = ReadBool();
                settings.ColorOutsideRoom = ReadInt();
            }
            else
            {
                // Read settings data.
                settings.ScaleInWindowedMode = ReadInt();
                settings.ScaleInFullScreenMode = ReadInt();
                settings.ScaleOnHardwareSupport = ReadBool();
            }

            // Read settings data.
            settings.SetResolution = ReadBool();

            // Versions greater than 5.3 support the below variables.
            if (version > 530)
            {
                // Read settings data.
                settings.ColorDepth2 = (ColorDepthType2)ReadInt();
                settings.Resolution2 = (ResolutionType2)ReadInt();
                settings.Frequency2 = (FrequencyType2)ReadInt();
            }
            else
            {
                // Read settings data.
                settings.ColorDepth1 = (ColorDepthType1)ReadInt();
                settings.UseExclusiveGraphicsMode = ReadBool();
                settings.Resolution1 = (ResolutionType1)ReadInt();
                settings.Frequency1 = (FrequencyType1)ReadInt();
                settings.UseSynchronization = ReadBool();
                settings.DisplayCaptionInFullScreenMode = ReadBool();
            }

            // Read settings data.
            settings.DontShowButtons = ReadBool();

            // Versions greater than 5.3 support screen synchronization.
            if (version > 530)
                settings.UseSynchronization = ReadBool();

            // Versions greater than 7.0 support disabling the screensaver, and power saving options.
            if (version > 720)
                settings.DisableScreensaver = ReadBool();

            // Read settings.
            settings.LetF4SwitchFullscreen = ReadBool();
            settings.LetF1ShowGameInfo = ReadBool();
            settings.LetEscEndGame = ReadBool();
            settings.LetF5SaveF6Load = ReadBool();

            // Skip reserved bytes.
            if (version < 542)
                ReadBytes(8);

            // Versions greater than 6.0, treat close as esc, F9 screenshot.
            if (version > 600)
            {
                settings.LetF9TakeScreenShot = ReadBool();
                settings.TreatCloseButtonAsESC = ReadBool();
            }

            // Versions greater than 5.1 support game priority.
            if (version > 510)
                settings.GamePriority = (PriorityType)ReadInt();

            // Read settings data.
            settings.FreezeOnLoseFocus = ReadBool();
            settings.LoadBarMode = (LoadProgressBarType)ReadInt();

            // If the loadbar type is a custom loadbar.
            if (settings.LoadBarMode == LoadProgressBarType.Custom)
            {
                // If version is greater than 7.0.
                if (version > 702)
                {
                    // If a back loadbar image exists.
                    if (ReadBool() == true)
                    {
                        // Get size of image data.
                        int size = ReadInt();

                        // Get back loadbar image data.
                        settings.BackLoadBarImage = ReadBytes(size);
                    }

                    // If a front loadbar image exists.
                    if (ReadBool() == true)
                    {
                        // Get size of image data.
                        int size = ReadInt();

                        // Get ffront loadbar image data.
                        settings.FrontLoadBarImage = ReadBytes(size);
                    }
                }
                else
                {
                    // If a back loadbar image exists.
                    if (ReadInt() != -1)
                    {
                        // Get size of image data.
                        int size = ReadInt();

                        // Get back loadbar image data.
                        settings.BackLoadBarImage = ReadBytes(size);
                    }

                    // If a front loadbar image exists.
                    if (ReadInt() != -1)
                    {
                        // Get size of image data.
                        int size = ReadInt();

                        // Get front loadbar image data.
                        settings.FrontLoadBarImage = ReadBytes(size);
                    }
                }
            }

            // Read settings data.
            settings.ShowCustomLoadImage = ReadBool();

            // If a custom load image must be shown
            if (settings.ShowCustomLoadImage == true)
            {
                // If version is greater than 7.0.
                if (version > 702)
                {
                    // If a custom load image is present
                    if (ReadBool() == true)
                    {
                        // Get size of image data
                        int size = ReadInt();

                        // Get custom load image data
                        settings.LoadingImage = ReadBytes(size);
                    }
                }
                else
                {
                    // If a custom load image is present
                    if (ReadInt() != -1)
                    {
                        // Get size of image data
                        int size = ReadInt();

                        // Get custom load image data
                        settings.LoadingImage = ReadBytes(size);
                    }
                }
            }

            // Versions greater than 5.0 support loading image alpha.
            if (version > 500)
            {
                // Read settings data.
                settings.ImagePartiallyTransparent = ReadBool();
                settings.LoadImageAlpha = ReadInt();
                settings.ScaleProgressBar = ReadBool();
            }

            // Get size of icon image data.
            int iconSize = ReadInt();

            // Read settings data.
            settings.GameIcon = ReadBytes(iconSize);
            settings.DisplayErrors = ReadBool();
            settings.WriteToLog = ReadBool();
            settings.AbortOnError = ReadBool();
            settings.TreatUninitializedAsZero = ReadBool();
            settings.Author = ReadString();

            // Versions greater than 6.0 use a string for the version data.
            if (version > 600)
                settings.Version = ReadString();
            else
                settings.Version = ReadInt().ToString();

            // Read settings data.
            settings.ProjectLastChanged = ReadDouble();
            settings.Information = ReadString();

            // Versions greater than 5.2 support constants. Versions greater than 7 read constants elsewhere.
            if (version > 520 && version < 800)
            {
                // Number of constants defined.
                settings.Constants = new GMConstant[ReadInt()];

                // Iterate through constants.
                for (int i = 0; i < settings.Constants.Length; i++)
                {
                    // Create a new constant.
                    GMConstant constant = new GMConstant();

                    // Get constant data.
                    constant.Name = ReadString();
                    constant.Value = ReadString();

                    // Add constant to settings.
                    settings.Constants[i] = constant;
                }
            }

            // If version is greater than 6.0.
            if (version > 600)
            {
                // Read build information.
                settings.Major = ReadInt();
                settings.Minor = ReadInt();
                settings.Release = ReadInt();
                settings.Build = ReadInt();
                settings.Company = ReadString();
                settings.Product = ReadString();
                settings.Copyright = ReadString();
                settings.Description = ReadString();

                // If the version is greater than 7.0, read last time global settings were changed.
                if (version > 702)
                    settings.SettingsLastChanged = ReadDouble();
            }
            else if (version > 530)  // If version is greater than 5.3.
            {
                // Number of include files.
                settings.Includes = new GMInclude[ReadInt()];

                // Get each include file.
                for (int i = 0; i < settings.Includes.Length; i++)
                {
                    // Read settings include file data.
                    settings.Includes[i].FileName = ReadString();
                }

                // Read settings data.
                settings.IncludeFolder = ReadInt();
                settings.OverwriteExisting = ReadBool();
                settings.RemoveAtGameEnd = ReadBool();
            }

            // End inflater.
            EndDecompress();

            // Return a GMProject settings object.
            return settings;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Reads all constants from Game Maker project file.
        /// </summary>
        private GMConstant[] ReadConstants()
        {
            // Get version.
            int version = ReadInt();

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

            // Number of constants defined.
            GMConstant[] constants = new GMConstant[ReadInt()];

            // Iterate through constants.
            for (int i = 0; i < constants.Length; i++)
            {
                // Create a new constant.
                GMConstant constant = new GMConstant();

                // Get constant data.
                constant.Name = ReadString();
                constant.Value = ReadString();

                // Add constant.
                constants[i] = constant;
            }

            // Last changed.
            GMConstant.LastChanged = ReadDouble();

            // Return constants.
            return constants;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Writes Game Maker project constants.
        /// </summary>
        private void WriteConstants(GMConstant[] constants, GMVersionType version)
        {
            // Write version number.
            WriteInt((int)version);

            // Write amount of constants.
            WriteInt(constants.Length);

            // Iterate through constants.
            for (int i = 0; i < constants.Length; i++)
            {
                // Write constant data.
                WriteString(constants[i].Name);
                WriteString(constants[i].Value);
            }

            // Write last changed.
            WriteDouble(GMConstant.LastChanged);
        }