/// <summary> /// Reads all the libraries in a GM file reader stream. /// </summary> public static GMList <GMLibrary> ReadLibraries(GMFileReader reader) { // Create a new list of libraries. GMList <GMLibrary> libraries = new GMList <GMLibrary>(); // Get number of libraries. int num = reader.ReadGMInt(); // Read libraries. for (int j = 0; j < num; j++) { // Create a new library. GMLibrary library = new GMLibrary(); // Read the library code. library.Code = reader.ReadGMString(); // Add the library. libraries.Add(library); } // Return libraries. return(libraries); }
private MemoryStream _zipStream = null; // A zip stream used for decompressing data. #endregion Fields #region Methods /// <summary> /// Reads a Game Maker project file. /// </summary> public GMProject ReadProject(string filePath) { // Create a new stream decoder. using (_reader = new BinaryReader(new FileStream(filePath, FileMode.Open, FileAccess.Read))) { // Create a new project. GMProject project = new GMProject(); // Read the magic number. int id = ReadInt(); // 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 = ReadInt(); // Check version. switch (version) { case 500: project.GameMakerVersion = GMVersionType.GameMaker50; break; case 510: project.GameMakerVersion = GMVersionType.GameMaker51; break; case 520: project.GameMakerVersion = GMVersionType.GameMaker52; break; case 530: project.GameMakerVersion = GMVersionType.GameMaker53; break; case 600: project.GameMakerVersion = GMVersionType.GameMaker60; break; case 701: project.GameMakerVersion = GMVersionType.GameMaker70; break; case 800: project.GameMakerVersion = GMVersionType.GameMaker80; break; } // Skip over reserved bytes. if (version < 600) ReadBytes(4); // Game Maker 7 project file encryption. if (version == 701) { // Bill and Fred, psssttt they like each other ;). int bill = ReadInt(); int fred = ReadInt(); // Skip bytes to treasure. ReadBytes(bill * 4); // Get the seed for swap table. int seed = ReadInt(); // Skip bytes to get out of the junk yard. ReadBytes(fred * 4); // Read first byte of Game id. (Not encrypted). byte b = ReadByte(); // Set the seed. SetSeed(seed); // Read game id. id = ReadInt(b); } else // Read game id normally. id = ReadInt(); // Skip unknown bytes. ReadBytes(16); // Read main project objects. project.Settings = ReadSettings(); project.Settings.GameIdentifier = id; // If the version is greater than Game Maker 7.0. if (version > 701) { // Read triggers and constants. project.Triggers = ReadTriggers(); project.Settings.Constants = ReadConstants(); } project.Sounds = ReadSounds(); project.Sprites = ReadSprites(); project.Backgrounds = ReadBackgrounds(); project.Paths = ReadPaths(); project.Scripts = ReadScripts(); // Get version. int version2 = ReadInt(); // 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) project.DataFiles = ReadDataFiles(); else project.Fonts = ReadFonts(version); project.Timelines = ReadTimelines(); project.Objects = ReadObjects(); project.Rooms = ReadRooms(project.Objects); // Read last ids for instances and tiles. project.LastInstanceId = ReadInt(); project.LastTileId = ReadInt(); // If the version is above 6.1, read include files and packages. if (version >= 700) { // Get include files. project.Settings.Includes = ReadIncludes(); // Get packages. project.Packages.AddRange(ReadPackages()); } // Read game information. project.GameInformation = ReadGameInformation(); // Get version. version = ReadInt(); // Check version. if (version != 500) throw new Exception("Unsupported Post-Game Information object version."); // Get number of libraries. int libNum = ReadInt(); // Read libraries. for (int j = 0; j < libNum; j++) { // Create a new library. GMLibrary library = new GMLibrary(); // Read the library code. library.Code = ReadString(); // Add the library. project.Libraries.Add(library); } // Read project tree. project.ProjectTree = ReadTree(filePath.Substring(filePath.LastIndexOf(@"\") + 1)); // Return the project. return project; } }