示例#1
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;
        }
示例#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);
            }
        }
示例#3
0
        /// <summary>
        /// Writes Game Maker project settings.
        /// </summary>
        /// <param name="settings">Settings object to write.</param>
        /// <param name="version">Target Game Maker file version to write.</param>
        private void WriteSettings(GMSettings settings, GMVersionType version)
        {
            // Write version number.
            if (version != GMVersionType.GameMaker70)
                WriteInt((int)version);
            else
                WriteInt(702);

            // If version is GM8, start compressing.
            if (version == GMVersionType.GameMaker80)
                Compress();

            // Write settings data
            WriteBool(settings.StartFullscreen);

            // Versions greater than 5.3 support interpolation.
            if (version > GMVersionType.GameMaker53)
                WriteBool(settings.Interpolate);

            // Write settings data.
            WriteBool(settings.DontDrawBorder);
            WriteBool(settings.DisplayCursor);

            // Versions greater than 5.3 support the below variables.
            if (version > GMVersionType.GameMaker53)
            {
                // Write settings data.
                WriteInt(settings.Scaling);
                WriteBool(settings.AllowWindowResize);
                WriteBool(settings.AlwaysOnTop);
                WriteInt(settings.ColorOutsideRoom);
            }
            else
            {
                // Write settings data.
                WriteInt(settings.ScaleInWindowedMode);
                WriteInt(settings.ScaleInFullScreenMode);
                WriteBool(settings.ScaleOnHardwareSupport);
            }

            // Write settings data.
            WriteBool(settings.SetResolution);

            // Versions greater than 5.3 support the below variables.
            if (version > GMVersionType.GameMaker53)
            {
                // Write settings data.
                WriteInt((int)settings.ColorDepth2);
                WriteInt((int)settings.Resolution2);
                WriteInt((int)settings.Frequency2);
            }
            else
            {
                // Write settings data.
                WriteInt((int)settings.ColorDepth1);
                WriteBool(settings.UseExclusiveGraphicsMode);
                WriteInt((int)settings.Resolution1);
                WriteInt((int)settings.Frequency1);
                WriteBool(settings.UseSynchronization);
                WriteBool(settings.DisplayCaptionInFullScreenMode);
            }

            // Write settings data.
            WriteBool(settings.DontShowButtons);

            // Versions greater than 5.3 support screen synchronization.
            if (version > GMVersionType.GameMaker53)
                WriteBool(settings.UseSynchronization);

            // Versions greater than 7.0 support disabling the screensaver, and power saving options.
            if (version > GMVersionType.GameMaker70)
                WriteBool(settings.DisableScreensaver);

            // Write settings.
            WriteBool(settings.LetF4SwitchFullscreen);
            WriteBool(settings.LetF1ShowGameInfo);
            WriteBool(settings.LetEscEndGame);
            WriteBool(settings.LetF5SaveF6Load);

            // Write empty bytes.
            if (version < GMVersionType.GameMaker60)
                WriteEmpty(8);

            // Versions greater than 6.0, treat close as esc, F9 screenshot.
            if (version > GMVersionType.GameMaker60)
            {
                // Write settings data.
                WriteBool(settings.LetF9TakeScreenShot);
                WriteBool(settings.TreatCloseButtonAsESC);
            }

            // Versions greater than 5.1 support game priority.
            if (version > GMVersionType.GameMaker51)
                WriteInt((int)settings.GamePriority);

            // Write settings data.
            WriteBool(settings.FreezeOnLoseFocus);
            WriteInt((int)settings.LoadBarMode);

            // If the loadbar type is a custom loadbar.
            if (settings.LoadBarMode == LoadProgressBarType.Custom)
            {
                // If version greater than 7.0.
                if (version > GMVersionType.GameMaker70)
                {
                    // If a back loadbar image exists.
                    if (settings.BackLoadBarImage != null)
                    {
                        // Write that there is a back load bar image.
                        WriteBool(true);

                        // Write size of image data.
                        WriteInt(settings.BackLoadBarImage.Length);

                        // Write back loadbar image data.
                        WriteBytes(settings.BackLoadBarImage);
                    }
                    else  // No back load bar image.
                        WriteBool(false);

                    // If a front loadbar image exists.
                    if (settings.FrontLoadBarImage != null)
                    {
                        // Write that there is a front load bar image.
                        WriteBool(true);

                        // Write size of image data.
                        WriteInt(settings.FrontLoadBarImage.Length);

                        // Write front loadbar image data.
                        WriteBytes(settings.FrontLoadBarImage);
                    }
                    else  // No front load bar image.
                        WriteBool(false);
                }
                else
                {
                    // If a back loadbar image exists.
                    if (settings.BackLoadBarImage != null)
                    {
                        // Write that there is a back load bar image.
                        WriteInt(10);

                        // Write size of image data.
                        WriteInt(settings.BackLoadBarImage.Length);

                        // Write back loadbar image data.
                        WriteBytes(settings.BackLoadBarImage);
                    }
                    else  // No back load bar image.
                        WriteInt(-1);

                    // If a front loadbar image exists.
                    if (settings.FrontLoadBarImage != null)
                    {
                        // Write that there is a front load bar image.
                        WriteInt(10);

                        // Write size of image data.
                        WriteInt(settings.FrontLoadBarImage.Length);

                        // Write front loadbar image data.
                        WriteBytes(settings.FrontLoadBarImage);
                    }
                    else  // No front load bar image.
                        WriteInt(-1);
                }
            }

            // Write settings data.
            WriteBool(settings.ShowCustomLoadImage);

            // If a custom load image must be shown.
            if (settings.ShowCustomLoadImage == true)
            {
                // If version is greater than 7.0.
                if (version > GMVersionType.GameMaker70)
                {
                    // If a custom load image is present
                    if (settings.LoadingImage != null)
                    {
                        // Write that there is a custom load image.
                        WriteBool(true);

                        // Write size of image data.
                        WriteInt(settings.LoadingImage.Length);

                        // Write custom load image data
                        WriteBytes(settings.LoadingImage);
                    }
                    else  // No custom load image.
                        WriteBool(false);
                }
                else
                {
                    // If a custom load image is present
                    if (settings.LoadingImage != null)
                    {
                        // Write that there is a custom load image.
                        WriteInt(10);

                        // Write size of image data.
                        WriteInt(settings.LoadingImage.Length);

                        // Write custom load image data
                        WriteBytes(settings.LoadingImage);
                    }
                    else  // No custom load image.
                        WriteInt(-1);
                }
            }

            // Versions greater than 5.0 support loading image alpha.
            if (version > GMVersionType.GameMaker50)
            {
                // Write settings data.
                WriteBool(settings.ImagePartiallyTransparent);
                WriteInt(settings.LoadImageAlpha);
                WriteBool(settings.ScaleProgressBar);
            }

            // Write size of icon image data.
            WriteInt(settings.GameIcon.Length);

            // Write settings data.
            WriteBytes(settings.GameIcon);
            WriteBool(settings.DisplayErrors);
            WriteBool(settings.WriteToLog);
            WriteBool(settings.AbortOnError);
            WriteBool(settings.TreatUninitializedAsZero);
            WriteString(settings.Author);

            // Versions greater than 6.0 use a string for the version data.
            if (version > GMVersionType.GameMaker60)
                WriteString(settings.Version);
            else
                WriteInt(Convert.ToInt32(settings.Version));

            // Write settings data.
            WriteDouble(settings.ProjectLastChanged);
            WriteString(settings.Information);

            // Versions greater than 5.2 support constants. Versions greater than 7.0 write constants elsewhere.
            if (version > GMVersionType.GameMaker52 && version < GMVersionType.GameMaker80)
            {
                // If there are constants to write.
                if (settings.Constants != null)
                {
                    // Write the amount of constants.
                    WriteInt(settings.Constants.Length);

                    // Iterate through constants.
                    for (int i = 0; i < settings.Constants.Length; i++)
                    {
                        // Write constant data.
                        WriteString(settings.Constants[i].Name);
                        WriteString(settings.Constants[i].Value);
                    }
                }
                else  // There are no constants to write.
                    WriteInt(0);
            }

            // If version is greater than 6.0, write build data, else write includes.
            if (version > GMVersionType.GameMaker60)
            {
                // Write build information.
                WriteInt(settings.Major);
                WriteInt(settings.Minor);
                WriteInt(settings.Release);
                WriteInt(settings.Build);
                WriteString(settings.Company);
                WriteString(settings.Product);
                WriteString(settings.Copyright);
                WriteString(settings.Description);

                // If the version is greater than 7.0, write last time global settings were changed.
                if (version > GMVersionType.GameMaker70)
                    WriteDouble(settings.SettingsLastChanged);
            }
            else if (version > GMVersionType.GameMaker53)
            {
                // If there are include files to write.
                if (settings.Includes != null)
                {
                    // Number of include files.
                    WriteInt(settings.Includes.Length);

                    // Iterate through include files.
                    for (int i = 0; i < settings.Includes.Length; i++)
                    {
                        // Write include file data.
                        WriteString(settings.Includes[i].FileName);
                    }
                }
                else  // There are no includes to write.
                    WriteInt(0);

                // Write settings data.
                WriteInt(settings.IncludeFolder);
                WriteBool(settings.OverwriteExisting);
                WriteBool(settings.RemoveAtGameEnd);
            }

            // Write compressed data.
            EndCompress();
        }