public override void Unserialize(GMDataReader reader) { Interpolation = (InterpolationEnum)reader.ReadInt32(); List = new GMList <Keyframe <Data> >(); List.Unserialize(reader); }
private static void ConvertPaths(ProjectFile pf) { GMList <GMPath> dataAssets = ((GMChunkPATH)pf.DataHandle.Chunks["PATH"]).List; dataAssets.Clear(); for (int i = 0; i < pf.Paths.Count; i++) { AssetPath assetPath = pf.Paths[i]; dataAssets.Add(new GMPath() { Name = pf.DataHandle.DefineString(assetPath.Name), Smooth = assetPath.Smooth, Closed = assetPath.Closed, Precision = assetPath.Precision, Points = new GMList <GMPath.Point>() }); GMPath gmPath = dataAssets[dataAssets.Count - 1]; foreach (AssetPath.Point point in assetPath.Points) { gmPath.Points.Add(new GMPath.Point() { X = point.X, Y = point.Y, Speed = point.Speed }); } } }
public void Unserialize(GMDataReader reader) { Name = reader.ReadStringPointerObject(); PlaybackType = (PlaybackTypeEnum)reader.ReadUInt32(); PlaybackSpeed = reader.ReadSingle(); PlaybackSpeedType = (GMSprite.AnimSpeedType)reader.ReadUInt32(); Length = reader.ReadSingle(); OriginX = reader.ReadInt32(); OriginY = reader.ReadInt32(); Volume = reader.ReadSingle(); BroadcastMessages = new GMList <Keyframe <BroadcastMessage> >(); BroadcastMessages.Unserialize(reader); Tracks = new GMList <Track>(); Tracks.Unserialize(reader); FunctionIDs = new Dictionary <int, GMString>(); int count = reader.ReadInt32(); for (int i = 0; i < count; i++) { int key = reader.ReadInt32(); FunctionIDs[key] = reader.ReadStringPointerObject(); } Moments = new GMList <Keyframe <Moment> >(); Moments.Unserialize(reader); }
/// <summary> /// Reads all data files from GM file reader stream. /// </summary> public static GMList <GMDataFile> ReadDataFiles(GMFileReader reader) { // Create a new list of data files. GMList <GMDataFile> dataFiles = new GMList <GMDataFile>(); // Amount of data file ids. int num = reader.ReadGMInt(); // Iterate through data files. for (int i = 0; i < num; i++) { // If the data file at index does not exists, continue. if (reader.ReadGMBool() == false) { dataFiles.LastId++; continue; } // Create a new data file object. GMDataFile dataFile = new GMDataFile(); // Set data file id. dataFile.Id = i; // Read data file data. dataFile.Name = reader.ReadGMString(); // Get version. int version = reader.ReadGMInt(); // Check version. if (version != 440) { throw new Exception("Unsupported Data File object version."); } // Read data file data. dataFile.FileName = reader.ReadGMString(); // If data file exists, read it in. if (reader.ReadGMBool()) { dataFile.Data = reader.ReadGMBytes(reader.ReadGMInt()); } // Read data file data. dataFile.ExportMode = (ExportType)(reader.ReadGMInt()); dataFile.OverwriteFile = reader.ReadGMBool(); dataFile.FreeDataMemory = reader.ReadGMBool(); dataFile.RemoveAtGameEnd = reader.ReadGMBool(); // Add data file. dataFiles.Add(dataFile); } // Return data files. return(dataFiles); }
public void Unserialize(GMDataReader reader) { Name = reader.ReadStringPointerObject(); Smooth = reader.ReadWideBoolean(); Closed = reader.ReadWideBoolean(); Precision = reader.ReadUInt32(); Points = new GMList <Point>(); Points.Unserialize(reader); }
public void Unserialize(GMDataReader reader) { Name = reader.ReadStringPointerObject(); TexturePageIDs = reader.ReadPointerObjectUnique <GMList <ResourceID> >(); SpriteIDs = reader.ReadPointerObjectUnique <GMList <ResourceID> >(); SpineSpriteIDs = reader.ReadPointerObjectUnique <GMList <ResourceID> >(); FontIDs = reader.ReadPointerObjectUnique <GMList <ResourceID> >(); TilesetIDs = reader.ReadPointerObjectUnique <GMList <ResourceID> >(); }
public void Unserialize(GMDataReader reader) { Name = reader.ReadStringPointerObject(); FunctionType = (FunctionTypeEnum)reader.ReadUInt32(); Iterations = (ushort)reader.ReadUInt32(); Points = new GMList <Point>(); Points.Unserialize(reader); }
public void Unserialize(GMDataReader reader, bool includeName) { if (includeName) { Name = reader.ReadStringPointerObject(); } GraphType = (GraphTypeEnum)reader.ReadUInt32(); Channels = new GMList <Channel>(); Channels.Unserialize(reader); }
public override void Unserialize(GMDataReader reader) { base.Unserialize(reader); if (reader.ReadInt32() != 1) { reader.Warnings.Add(new GMWarning("Unexpected EMBI version, != 1", GMWarning.WarningLevel.Severe)); } List = new GMPointerList <EmbeddedImage>(); List.Unserialize(reader); }
public override void Unserialize(GMDataReader reader) { base.Unserialize(reader); int chunkVersion = reader.ReadInt32(); if (chunkVersion != 1) { reader.Warnings.Add(new GMWarning($"EMBI version is {chunkVersion}, expected 1")); } List = new GMList <EmbeddedImage>(); List.Unserialize(reader); }
public override void Unserialize(GMDataReader reader) { base.Unserialize(reader); Unknown = reader.ReadUInt64(); Options = (OptionsFlags)reader.ReadUInt64(); Scale = reader.ReadUInt32(); WindowColor = reader.ReadUInt32(); ColorDepth = reader.ReadUInt32(); Resolution = reader.ReadUInt32(); Frequency = reader.ReadUInt32(); VertexSync = reader.ReadUInt32(); Priority = reader.ReadUInt32(); SplashBackImage = reader.ReadPointerObject <GMTextureItem>(); SplashFrontImage = reader.ReadPointerObject <GMTextureItem>(); SplashLoadImage = reader.ReadPointerObject <GMTextureItem>(); LoadAlpha = reader.ReadUInt32(); Constants = new GMList <Constant>(); Constants.Unserialize(reader); }
public override void Unserialize(GMDataReader reader) { base.Unserialize(reader); FunctionEntries = new GMList <GMFunctionEntry>(); Locals = new GMList <GMLocalsEntry>(); if (reader.VersionInfo.FormatID <= 14) { int startOff = reader.Offset; while (reader.Offset + 12 <= startOff + Length) { GMFunctionEntry entry = new GMFunctionEntry(); entry.Unserialize(reader); FunctionEntries.Add(entry); } } else { FunctionEntries.Unserialize(reader); Locals.Unserialize(reader); } }
/// <summary> /// Reads shaders from Game Maker Studio project file /// </summary> /// <param name="directory">The directory the shaders are placed</param> /// <param name="assets">Collection of project assets</param> public static GMList <GMShader> ReadShadersGMX(string directory, ref List <string> assets) { // A list of shader GMList <GMShader> shaders = new GMList <GMShader>(); shaders.AutoIncrementIds = false; // Iterate through .gmx files in the directory foreach (string file in Directory.GetFiles(directory, "*.shader")) { // Set name of the shader string name = GetResourceName(file); // If the file is not in the asset list, it has been orphaned, continue if (!assets.Contains(name)) { continue; } // Create a stream to the shader file using (StreamReader streamReader = new StreamReader(file)) { // Create a new shader GMShader shader = new GMShader(); shader.Name = name; shader.Id = GetIdFromName(name); shader.Code = streamReader.ReadToEnd(); shader.Type = name; // Add the shader shaders.Add(shader); } } // Return the list of shaders return(shaders); }
/// <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); }
/// <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(); } }
/// <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(); } }
/// <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); }
/// <summary> /// Reads all backgrounds from a background XML file /// </summary> /// <param name="directory">The XML (.GMX) file path</param> /// <param name="assets">A list of assets listed in the project GMX</param> /// <returns>A GM background</returns> public static GMList <GMBackground> ReadBackgroundsGMX(string directory, ref List <string> assets) { // A list of backgrounds GMList <GMBackground> backgrounds = new GMList <GMBackground>(); backgrounds.AutoIncrementIds = false; // Iterate through .gmx files in the directory foreach (string file in Directory.GetFiles(directory, "*.gmx")) { // Set name of the background string name = GetResourceName(file); // If the file is not in the asset list, it has been orphaned, continue if (!assets.Contains(name)) { continue; } // Create a dictionary of room properties Dictionary <string, string> properties = new Dictionary <string, string>(); foreach (GMXBackgroundProperty property in Enum.GetValues(typeof(GMXBackgroundProperty))) { properties.Add(GMXEnumString(property), ""); } // Background image and texture group strings GMImage image = null; string textureGroup = GMXEnumString(GMXBackgroundProperty.TextureGroup); string textureGroup0 = GMXEnumString(GMXBackgroundProperty.TextureGroup0); // Create an XMLReader to read in the resource elements using (XmlReader reader = XmlReader.Create(file)) { // Move to a content node reader.MoveToContent(); // Read XML file while (reader.Read()) { // If the node is not an element, continue if (reader.NodeType != XmlNodeType.Element) { continue; } // Get the element name string nodeName = reader.Name; // Read reader.Read(); // If the element value is null or empty, continue if (string.IsNullOrEmpty(reader.Value)) { continue; } // If the element is a frame element create subimage, else normal property if (nodeName.ToLower() == GMXEnumString(GMXBackgroundProperty.Data)) { // Create an image and set the image path image = new GMImage(); image.Compressed = false; image.FilePath = reader.Value; image.Data = GMUtilities.LoadBytesFromBitmap(directory + "\\" + image.FilePath); } else { // Set the property value properties[nodeName] = reader.Value; } } } // Create a new background and set its properties GMBackground background = new GMBackground(); background.Id = GetIdFromName(name); background.Name = name; background.UseAsTileSet = GMXBool(properties[GMXEnumString(GMXBackgroundProperty.IsTileset)], background.UseAsTileSet); background.TileWidth = GMXInt(properties[GMXEnumString(GMXBackgroundProperty.TileWidth)], background.TileWidth); background.TileHeight = GMXInt(properties[GMXEnumString(GMXBackgroundProperty.TileHeight)], background.TileHeight); background.HorizontalOffset = GMXInt(properties[GMXEnumString(GMXBackgroundProperty.TileXOff)], background.HorizontalOffset); background.VerticalOffset = GMXInt(properties[GMXEnumString(GMXBackgroundProperty.TileYOff)], background.VerticalOffset); background.HorizontalSeperation = GMXInt(properties[GMXEnumString(GMXBackgroundProperty.TileHSep)], background.HorizontalSeperation); background.VerticalSeperation = GMXInt(properties[GMXEnumString(GMXBackgroundProperty.TileVSep)], background.VerticalSeperation); background.TileHorizontally = GMXBool(properties[GMXEnumString(GMXBackgroundProperty.HTile)], background.TileHorizontally); background.TileVertically = GMXBool(properties[GMXEnumString(GMXBackgroundProperty.VTile)], background.TileVertically); background.UsedFor3D = GMXBool(properties[GMXEnumString(GMXBackgroundProperty.For3D)], background.UsedFor3D); background.Width = GMXInt(properties[GMXEnumString(GMXBackgroundProperty.Width)], background.Width); background.Height = GMXInt(properties[GMXEnumString(GMXBackgroundProperty.Height)], background.Height); properties[textureGroup] = properties[textureGroup] == "" ? "0" : properties[textureGroup]; properties[textureGroup0] = properties[textureGroup0] == "" ? "0" : properties[textureGroup0]; image.Width = background.Width; image.Height = background.Height; background.Image = image; // The texture group does not equal zero set texture group 0 to the texture group value if (properties[textureGroup] != "0") { properties[textureGroup0] = properties[textureGroup]; } // The texture group zero does not equal zero set texture group to the texture group 0 value else if (properties[textureGroup0] != "0") { properties[textureGroup] = properties[textureGroup0]; } // Create a list of texture groups List <int> textureGroups = new List <int>(); for (int i = 0; properties.ContainsKey(string.Concat(textureGroup, i)); i++) { textureGroups.Add(Convert.ToInt32(properties[string.Concat(textureGroup, i)])); } background.TextureGroups = textureGroups.ToArray(); // Add the background backgrounds.Add(background); } // Return the list of backgrounds return(backgrounds); }
/// <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); } }
/// <summary> /// Reads all fonts from a GM file reader stream. /// </summary> public static GMList <GMFont> ReadFonts(int version, GMFileReader reader) { // Create a new list of fonts. GMList <GMFont> fonts = new GMList <GMFont>(); // Amount of font ids. int num = reader.ReadGMInt(); // Iterate through fonts. for (int i = 0; i < num; i++) { // If version is 8.0, start inflate. if (version == 800) { reader.Decompress(); } // If the font at index does not exists, continue. if (reader.ReadGMBool() == false) { fonts.LastId++; reader.EndDecompress(); continue; } // Create a new font object. GMFont font = new GMFont(); // Set font id. font.Id = i; // Read font data. font.Name = reader.ReadGMString(); // If version is 8.0, get last changed. if (version == 800) { font.LastChanged = reader.ReadGMDouble(); } // Get version. version = reader.ReadGMInt(); // Check version. if (version != 540 && version != 800) { throw new Exception("Unsupported Font object version."); } // Read font data. font.FontName = reader.ReadGMString(); font.Size = reader.ReadGMInt(); font.Bold = reader.ReadGMBool(); font.Italic = reader.ReadGMBool(); font.CharacterRangeMin = reader.ReadGMShort(); font.CharacterSet = reader.ReadGMByte(); font.AntiAliasing = reader.ReadGMByte(); font.CharacterRangeMax = reader.ReadGMInt(); // End object inflate. reader.EndDecompress(); // Add font. fonts.Add(font); } // Return fonts. return(fonts); }
/// <summary> /// Reads all sounds from Game Maker project file stream. /// </summary> public static GMList <GMSound> ReadSounds(GMFileReader reader) { // Get version. int version = reader.ReadGMInt(); // Check version. if (version != 400 && version != 800) { throw new Exception("Unsupported Pre-Sound object version."); } // Create a new sound list. GMList <GMSound> sounds = new GMList <GMSound>(); // Amount of sound ids. int num = reader.ReadGMInt(); // Iterate through sounds. for (int i = 0; i < num; i++) { // If version is 8.0, start inflate. if (version == 800) { reader.Decompress(); } // If the sound at index does not exists, continue. if (reader.ReadGMBool() == false) { sounds.LastId++; reader.EndDecompress(); continue; } // Create sound object. GMSound sound = new GMSound(); // Set sound id. sound.Id = i; // Read sound data. sound.Name = reader.ReadGMString(); // If version is 8.0, get last changed. if (version == 800) { sound.LastChanged = reader.ReadGMDouble(); } // Get version. version = reader.ReadGMInt(); // Check version. if (version != 440 && version != 600 && version != 800) { throw new Exception("Unsupported Sound object version."); } // Check version. if (version == 440) { sound.Kind = reader.ReadGMInt(); } else { // Read sound data. sound.Type = reader.ReadGMInt(); } // Read sound data. sound.FileType = reader.ReadGMString(); // Check version. if (version == 440) { // If sound data exists, read it. if ((int)sound.Kind != -1) { sound.Data = reader.ReadGMBytes(reader.ReadGMInt()); } // Read sound data. sound.AllowSoundEffects = reader.ReadGMBool(); sound.Buffers = reader.ReadGMInt(); sound.LoadOnlyOnUse = reader.ReadGMBool(); } else { // Read sound data. sound.FileName = reader.ReadGMString(); // If sound data exists, read it. if (reader.ReadGMBool() == true) { sound.Data = reader.ReadGMBytes(reader.ReadGMInt()); } // Read sound data. sound.Effects = reader.ReadGMInt(); sound.Volume = reader.ReadGMDouble(); sound.Pan = reader.ReadGMDouble(); sound.Preload = reader.ReadGMBool(); } // End object inflate. reader.EndDecompress(); // Add sound. sounds.Add(sound); } // Return sounds. return(sounds); }
public override void Unserialize(GMDataReader reader) { List = new GMList <Keyframe <GMString> >(); List.Unserialize(reader); }
/// <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(); } }
/// <summary> /// Reads all sounds from Game Maker project file. /// </summary> private GMList<GMSound> ReadSounds() { // Get version. int version = ReadInt(); // Check version. if (version != 400 && version != 800) throw new Exception("Unsupported Pre-Sound object version."); // Create a new sound list. GMList<GMSound> sounds = new GMList<GMSound>(); // Amount of sound ids. int num = ReadInt(); // Iterate through sounds. for (int i = 0; i < num; i++) { // If version is 8.0, start inflate. if (version == 800) Decompress(); // If the sound at index does not exists, continue. if (ReadBool() == false) { sounds.LastId++; EndDecompress(); continue; } // Create sound object. GMSound sound = new GMSound(); // Set sound id. sound.Id = i; // Read sound data. sound.Name = ReadString(); // If version is 8.0, get last changed. if (version == 800) sound.LastChanged = ReadDouble(); // Get version. version = ReadInt(); // Check version. if (version != 440 && version != 600 && version != 800) throw new Exception("Unsupported Sound object version."); // Check version. if (version == 440) sound.Kind = (SoundKind)ReadInt(); else // Read sound data. sound.Type = (SoundType)ReadInt(); // Read sound data. sound.FileType = ReadString(); // Check version. if (version == 440) { // If sound data exists, read it. if ((int)sound.Kind != -1) sound.Data = ReadBytes(ReadInt()); // Read sound data. sound.AllowSoundEffects = ReadBool(); sound.Buffers = ReadInt(); sound.LoadOnlyOnUse = ReadBool(); } else { // Read sound data. sound.FileName = ReadString(); // If sound data exists, read it. if (ReadBool() == true) sound.Data = ReadBytes(ReadInt()); // Read sound data. sound.Effects = ReadInt(); sound.Volume = ReadDouble(); sound.Pan = ReadDouble(); sound.Preload = ReadBool(); } // End object inflate. EndDecompress(); // Add sound. sounds.Add(sound); } // Return sounds. return sounds; }
/// <summary> /// Reads sprites from Game Maker project file. /// </summary> private GMList<GMSprite> ReadSprites() { // Get version. int version = ReadInt(); // Check version. if (version != 400 && version != 800) throw new Exception("Unsupported Pre-Sprite object version."); // Create a new list of sprites. GMList<GMSprite> sprites = new GMList<GMSprite>(); // Amount of sprite ids. int num = ReadInt(); // Iterate through sprites. for (int i = 0; i < num; i++) { // If version is 8.0, start inflate. if (version == 800) Decompress(); // If the sprite at index does not exists, continue. if (ReadBool() == false) { sprites.LastId++; EndDecompress(); continue; } // Create a new sprite object. GMSprite sprite = new GMSprite(); // Set sprite id. sprite.Id = i; // Read sprite data. sprite.Name = ReadString(); // If version is 8.0, get last changed. if (version == 800) sprite.LastChanged = ReadDouble(); // Get version. version = ReadInt(); // Check version. if (version != 400 && version != 542 && version != 800) throw new Exception("Unsupported Sprite object version."); // If less than version 8.0. if (version < 800) { // Read sprite data sprite.Width = ReadInt(); sprite.Height = ReadInt(); sprite.BoundingBoxLeft = ReadInt(); sprite.BoundingBoxRight = ReadInt(); sprite.BoundingBoxBottom = ReadInt(); sprite.BoundingBoxTop = ReadInt(); sprite.Transparent = ReadBool(); // Check version. if (version > 400) { // Read sprite data sprite.SmoothEdges = ReadBool(); sprite.Preload = ReadBool(); } // Read sprite data. sprite.BoundingBoxMode = (BoundingBoxType)ReadInt(); sprite.Precise = ReadBool(); // Check version. if (version == 400) { // Read sprtie data. sprite.UseVideoMemory = ReadBool(); sprite.LoadOnlyOnUse = ReadBool(); } // Read sprite data. sprite.OriginX = ReadInt(); sprite.OriginY = ReadInt(); // Sprite number of sub images sprite.SubImages = new GMImage[ReadInt()]; // Iterate through sub-images for (int j = 0; j < sprite.SubImages.Length; j++) { // If the sub-image at index does not exists, continue. if (ReadInt() == -1) continue; // Create a new image object. GMImage image = new GMImage(); // Get size of image data. int size = ReadInt(); // Get image data. image.Data = ReadBytes(size); // Insert compressed image data. sprite.SubImages[j] = image; } } else { // Read sprite data. sprite.OriginX = ReadInt(); sprite.OriginY = ReadInt(); // Sprite number of sub images. sprite.SubImages = new GMImage[ReadInt()]; // Iterate through sub-images. for (int j = 0; j < sprite.SubImages.Length; j++) { // Get version. version = ReadInt(); // Check version. if (version != 800) throw new Exception("Unsupported Sprite object version."); // Get width and height of image. int width = ReadInt(); int height = ReadInt(); // If the sprite size is not zero. if (width != 0 && height != 0) { // Create a new image object. GMImage image = new GMImage(); image.Compressed = false; // Set image data. image.Width = width; image.Height = height; // Get size of image data. int size = ReadInt(); // Get image data. image.Data = ReadBytes(size); // Insert compressed image data. sprite.SubImages[j] = image; } } // Read sprite data. sprite.ShapeMode = (ShapeType)ReadInt(); sprite.AlphaTolerance = ReadInt(); sprite.UseSeperateCollisionMasks = ReadBool(); sprite.BoundingBoxMode = (BoundingBoxType)ReadInt(); sprite.BoundingBoxLeft = ReadInt(); sprite.BoundingBoxRight = ReadInt(); sprite.BoundingBoxBottom = ReadInt(); sprite.BoundingBoxTop = ReadInt(); } // End object inflate. EndDecompress(); // Add sprite. sprites.Add(sprite); } // Return sprites. return sprites; }
/// <summary> /// Reads scripts from GM file /// </summary> private GMList<GMScript> ReadScripts() { // Get version. int version = ReadInt(); // Check version. if (version != 400 && version != 800) throw new Exception("Unsupported Pre-Script object version."); // Create a new list of scripts. GMList<GMScript> scripts = new GMList<GMScript>(); // Amount of script ids. int num = ReadInt(); // Iterate through scripts. for (int i = 0; i < num; i++) { // If version is 8.0, start inflate. if (version == 800) Decompress(); // If the script at index does not exists, continue. if (ReadBool() == false) { scripts.LastId++; EndDecompress(); continue; } // Create a new script object. GMScript script = new GMScript(); // Set script id. script.Id = i; // Read script data. script.Name = ReadString(); // If version is 8.0, get last changed. if (version == 800) script.LastChanged = ReadDouble(); // Get version. version = ReadInt(); // Check version. if (version != 400 && version != 800) throw new Exception("Unsupported Script object version."); // Read script data. script.Code = ReadString(); // End object inflate. EndDecompress(); // Add script. scripts.Add(script); } // Return scripts. return scripts; }
/// <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; }
/// <summary> /// Reads paths from GM file. /// </summary> private GMList<GMPath> ReadPaths() { // Get version. int version = ReadInt(); // Check version. if (version != 420 && version !=800) throw new Exception("Unsupported Pre-Path object version."); // Create a new list of paths. GMList<GMPath> paths = new GMList<GMPath>(); // Amount of path indexes. int num = ReadInt(); // Iterate through paths. for (int i = 0; i < num; i++) { // If version is 8.0, start inflate. if (version == 800) Decompress(); // If the path at index does not exists, continue. if (ReadBool() == false) { paths.LastId++; EndDecompress(); continue; } // Create a new path object. GMPath path = new GMPath(); // Set path id. path.Id = i; // Read path data. path.Name = ReadString(); // If version is 8.0, get last changed. if (version == 800) path.LastChanged = ReadDouble(); // Get version. int version2 = ReadInt(); // Check version. if (version2 != 420 && version2 != 530) throw new Exception("Unsupported Path object version."); // Check version. if (version2 > 420) { // Read path data. path.Smooth = ReadBool(); path.Closed = ReadBool(); path.Precision = ReadInt(); path.RoomId = ReadInt(); path.SnapX = ReadInt(); path.SnapY = ReadInt(); } else { // Read path data. path.Smooth = ReadBool(); path.ActionAtTheEnd = (ActionAtTheEnd)ReadInt(); ReadBytes(4); } // Number of path points. path.Points = new GMPoint[ReadInt()]; // Iterate through path points. for (int j = 0; j < path.Points.Length; j++) { // Create a new point. GMPoint point = new GMPoint(); // Read point data. point.X = ReadDouble(); point.Y = ReadDouble(); point.Speed = ReadDouble(); // Set point. path.Points[j] = point; } // End object inflate. EndDecompress(); // Add path. paths.Add(path); } // Return paths. return paths; }
/// <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(); } }
/// <summary> /// Reads all backgrounds from a GM file reader /// </summary> public static GMList <GMBackground> ReadBackgrounds(GMFileReader reader) { // Get version int version = reader.ReadGMInt(); // Check version if (version != 400 && version != 800) { throw new Exception("Unsupported Pre-Background object version."); } // Create a new list of backgrounds GMList <GMBackground> backgrounds = new GMList <GMBackground>(); // Amount of background ids int num = reader.ReadGMInt(); // Iterate through backgrounds for (int i = 0; i < num; i++) { // If version is 8.0, start inflate if (version == 800) { reader.Decompress(); } // If the background at index does not exists, continue if (reader.ReadGMBool() == false) { backgrounds.LastId++; reader.EndDecompress(); continue; } // Create a new background object GMBackground background = new GMBackground(); // Set background id background.Id = i; // Get background data background.Name = reader.ReadGMString(); // If version is 8.0, get last changed if (version == 800) { background.LastChanged = reader.ReadGMDouble(); } // Get version version = reader.ReadGMInt(); // Check version if (version != 400 && version != 543 && version != 710) { throw new Exception("Unsupported Background object version."); } // If version is less than 7.1 if (version < 710) { // Background data background.Width = reader.ReadGMInt(); background.Height = reader.ReadGMInt(); background.Transparent = reader.ReadGMBool(); // Check version if (version > 400) { // Read background data background.SmoothEdges = reader.ReadGMBool(); background.Preload = reader.ReadGMBool(); background.UseAsTileSet = reader.ReadGMBool(); background.TileWidth = reader.ReadGMInt(); background.TileHeight = reader.ReadGMInt(); background.HorizontalOffset = reader.ReadGMInt(); background.VerticalOffset = reader.ReadGMInt(); background.HorizontalSeperation = reader.ReadGMInt(); background.VerticalSeperation = reader.ReadGMInt(); } else { // Read background data background.UseVideoMemory = reader.ReadGMBool(); background.LoadOnlyOnUse = reader.ReadGMBool(); } // If image data exists if (reader.ReadGMBool()) { // If pixel data does not exist if (reader.ReadGMInt() == -1) { continue; } // Create a new image GMImage image = new GMImage(); // Set image data image.Width = background.Width; image.Height = background.Height; // Get size of image data int size = reader.ReadGMInt(); // Get compressed image data image.Data = reader.ReadGMBytes(size); // Set background image background.Image = image; } } else { // Get background data background.UseAsTileSet = reader.ReadGMBool(); background.TileWidth = reader.ReadGMInt(); background.TileHeight = reader.ReadGMInt(); background.HorizontalOffset = reader.ReadGMInt(); background.VerticalOffset = reader.ReadGMInt(); background.HorizontalSeperation = reader.ReadGMInt(); background.VerticalSeperation = reader.ReadGMInt(); // Get version version = reader.ReadGMInt(); // Check version if (version != 800) { throw new Exception("Unsupported Background object version."); } // Get image data background.Width = reader.ReadGMInt(); background.Height = reader.ReadGMInt(); // If the sprite size is not zero if (background.Width != 0 && background.Height != 0) { // Create a new image object GMImage image = new GMImage(); image.Compressed = false; // Set image data image.Width = background.Width; image.Height = background.Height; // Get size of image data int size = reader.ReadGMInt(); // Get image data image.Data = reader.ReadGMBytes(size); // Insert compressed image data background.Image = image; } } // End object inflate reader.EndDecompress(); // Add background backgrounds.Add(background); } // Return backgrounds return(backgrounds); }
/// <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(); } }
/// <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(); } }
public override void Unserialize(GMDataReader reader) { base.Unserialize(reader); reader.VersionInfo.OptionBitflag = (reader.ReadInt32() == int.MinValue); reader.Offset -= 4; if (reader.VersionInfo.OptionBitflag) { Unknown = reader.ReadUInt64(); Options = (OptionsFlags)reader.ReadUInt64(); Scale = reader.ReadInt32(); WindowColor = reader.ReadUInt32(); ColorDepth = reader.ReadUInt32(); Resolution = reader.ReadUInt32(); Frequency = reader.ReadUInt32(); VertexSync = reader.ReadUInt32(); Priority = reader.ReadUInt32(); SplashBackImage = reader.ReadPointerObject <GMTextureItem>(); SplashFrontImage = reader.ReadPointerObject <GMTextureItem>(); SplashLoadImage = reader.ReadPointerObject <GMTextureItem>(); LoadAlpha = reader.ReadUInt32(); } else { Options = 0; ReadOption(reader, OptionsFlags.FullScreen); ReadOption(reader, OptionsFlags.InterpolatePixels); ReadOption(reader, OptionsFlags.UseNewAudio); ReadOption(reader, OptionsFlags.NoBorder); ReadOption(reader, OptionsFlags.ShowCursor); Scale = reader.ReadInt32(); ReadOption(reader, OptionsFlags.Sizeable); ReadOption(reader, OptionsFlags.StayOnTop); WindowColor = reader.ReadUInt32(); ReadOption(reader, OptionsFlags.ChangeResolution); ColorDepth = reader.ReadUInt32(); Resolution = reader.ReadUInt32(); Frequency = reader.ReadUInt32(); ReadOption(reader, OptionsFlags.NoButtons); VertexSync = reader.ReadUInt32(); ReadOption(reader, OptionsFlags.ScreenKey); ReadOption(reader, OptionsFlags.HelpKey); ReadOption(reader, OptionsFlags.QuitKey); ReadOption(reader, OptionsFlags.SaveKey); ReadOption(reader, OptionsFlags.ScreenShotKey); ReadOption(reader, OptionsFlags.CloseSec); Priority = reader.ReadUInt32(); ReadOption(reader, OptionsFlags.Freeze); ReadOption(reader, OptionsFlags.ShowProgress); SplashBackImage = reader.ReadPointerObject <GMTextureItem>(); SplashFrontImage = reader.ReadPointerObject <GMTextureItem>(); SplashLoadImage = reader.ReadPointerObject <GMTextureItem>(); ReadOption(reader, OptionsFlags.LoadTransparent); LoadAlpha = reader.ReadUInt32(); ReadOption(reader, OptionsFlags.ScaleProgress); ReadOption(reader, OptionsFlags.DisplayErrors); ReadOption(reader, OptionsFlags.WriteErrors); ReadOption(reader, OptionsFlags.AbortErrors); ReadOption(reader, OptionsFlags.VariableErrors); ReadOption(reader, OptionsFlags.CreationEventOrder); } Constants = new GMList <Constant>(); Constants.Unserialize(reader); }
/// <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(); } }
/// <summary> /// Reads all GMX sounds from a directory /// </summary> /// <param name="file">The XML (.GMX) file path</param> /// <returns>A list of sounds</returns> public static GMList <GMSound> ReadSoundsGMX(string directory, ref List <string> assets) { // A list of sounds GMList <GMSound> sounds = new GMList <GMSound>(); sounds.AutoIncrementIds = false; // Iterate through .gmx files in the directory foreach (string file in Directory.GetFiles(directory, "*.gmx")) { // Set name of the sound string name = GetResourceName(file); // If the file is not in the asset list, it has been orphaned, continue if (!assets.Contains(name)) { continue; } // Create a dictionary of sound properties Dictionary <string, string> properties = new Dictionary <string, string>(); foreach (GMXSoundProperty property in Enum.GetValues(typeof(GMXSoundProperty))) { properties.Add(GMXEnumString(property), ""); } // Create an xml reader using (XmlReader reader = XmlReader.Create(file)) { // Seek to content reader.MoveToContent(); // Read the GMX file while (reader.Read()) { // If the node is not an element, continue if (reader.NodeType != XmlNodeType.Element) { continue; } // Get the element name string nodeName = reader.Name; // Read element reader.Read(); // If the element value is null or empty, continue if (String.IsNullOrEmpty(reader.Value)) { continue; } // Set the property value properties[nodeName] = reader.Value; } } // Create a new sound, set properties GMSound sound = new GMSound(); sound.Id = GetIdFromName(name); sound.Name = name; sound.Kind = GMXInt(properties[GMXEnumString(GMXSoundProperty.Kind)], sound.Kind); sound.Extension = GMXString(properties[GMXEnumString(GMXSoundProperty.Extension)], sound.Extension); sound.FilePath = GMXString(properties[GMXEnumString(GMXSoundProperty.Origname)], sound.FilePath); sound.Effects = GMXInt(properties[GMXEnumString(GMXSoundProperty.Effects)], sound.Effects); sound.Volume = GMXDouble(properties[GMXEnumString(GMXSoundProperty.Volume)], sound.Volume); sound.Pan = GMXDouble(properties[GMXEnumString(GMXSoundProperty.Pan)], sound.Pan); sound.OGGQuality = GMXInt(properties[GMXEnumString(GMXSoundProperty.OggQuality)], sound.OGGQuality); sound.Preload = GMXBool(properties[GMXEnumString(GMXSoundProperty.Preload)], sound.Preload); sound.FileName = GMXString(properties[GMXEnumString(GMXSoundProperty.Data)], sound.FileName); sound.SampleRate = GMXInt(properties[GMXEnumString(GMXSoundProperty.SampleRate)], sound.SampleRate); sound.Type = GMXInt(properties[GMXEnumString(GMXSoundProperty.Type)], sound.Type); sound.BitDepth = GMXInt(properties[GMXEnumString(GMXSoundProperty.BitDepth)], sound.BitDepth); sound.Streamed = GMXBool(properties[GMXEnumString(GMXSoundProperty.Streamed)], sound.Streamed); sound.UncompressOnLoad = GMXBool(properties[GMXEnumString(GMXSoundProperty.UncompressOnLoad)], sound.UncompressOnLoad); sound.Compressed = GMXBool(properties[GMXEnumString(GMXSoundProperty.Compressed)], sound.Compressed); // Set bit rate if (properties.ContainsKey(GMXEnumString(GMXSoundProperty.BitRate))) { sound.BitRate = GMXInt(properties[GMXEnumString(GMXSoundProperty.BitRate)], sound.BitRate); } else if (properties.ContainsKey(GMXEnumString(GMXSoundProperty.Mp3BitRate))) { sound.BitRate = GMXInt(properties[GMXEnumString(GMXSoundProperty.Mp3BitRate)], sound.BitRate); } // Add the sound sounds.Add(sound); } // Return the list of sounds return(sounds); }
public override void ConvertProject(ProjectFile pf) { var dataAssets = pf.DataHandle.GetChunk <GMChunkOBJT>().List; // TODO: use asset refs whenever code is implemented GMList <GMCode> dataCode = ((GMChunkCODE)pf.DataHandle.Chunks["CODE"]).List; int getCode(string name) { try { return(dataCode.Select((elem, index) => new { elem, index }).First(p => p.elem.Name.Content == name).index); } catch (InvalidOperationException) { return(-1); } } int getObject(string name) { if (name == null) { return(-1); } if (name == "<undefined>") { return(-100); } return(pf.Objects.FindIndex(name)); } List <GMObject> newList = new List <GMObject>(); for (int i = 0; i < pf.Objects.Count; i++) { AssetObject projectAsset = pf.Objects[i].Asset; if (projectAsset == null) { // This asset was never converted // No need to update IDs since they won't change newList.Add((GMObject)pf.Objects[i].DataAsset); continue; } GMObject dataAsset = new GMObject() { Name = pf.DataHandle.DefineString(projectAsset.Name), SpriteID = pf.Sprites.FindIndex(projectAsset.Sprite), Visible = projectAsset.Visible, Solid = projectAsset.Solid, Depth = projectAsset.Depth, Persistent = projectAsset.Persistent, ParentObjectID = getObject(projectAsset.ParentObject), MaskSpriteID = pf.Sprites.FindIndex(projectAsset.MaskSprite), Physics = projectAsset.Physics, PhysicsSensor = projectAsset.PhysicsSensor, PhysicsShape = projectAsset.PhysicsShape, PhysicsDensity = projectAsset.PhysicsDensity, PhysicsRestitution = projectAsset.PhysicsRestitution, PhysicsGroup = projectAsset.PhysicsGroup, PhysicsLinearDamping = projectAsset.PhysicsLinearDamping, PhysicsAngularDamping = projectAsset.PhysicsAngularDamping, PhysicsVertices = new List <GMObject.PhysicsVertex>(), PhysicsFriction = projectAsset.PhysicsFriction, PhysicsAwake = projectAsset.PhysicsAwake, PhysicsKinematic = projectAsset.PhysicsKinematic, Events = new GMUniquePointerList <GMUniquePointerList <GMObject.Event> >() }; foreach (AssetObject.PhysicsVertex v in projectAsset.PhysicsVertices) { dataAsset.PhysicsVertices.Add(new GMObject.PhysicsVertex() { X = v.X, Y = v.Y }); } foreach (var events in projectAsset.Events.Values) { var newEvents = new GMUniquePointerList <GMObject.Event>(); foreach (var ev in events) { GMObject.Event newEv = new GMObject.Event() { Subtype = 0, Actions = new GMUniquePointerList <GMObject.Event.Action>() { new GMObject.Event.Action() { LibID = 1, ID = ev.Actions[0].ID, Kind = 7, UseRelative = false, IsQuestion = false, UseApplyTo = ev.Actions[0].UseApplyTo, ExeType = 2, ActionName = ev.Actions[0].ActionName != null?pf.DataHandle.DefineString(ev.Actions[0].ActionName) : null, CodeID = getCode(ev.Actions[0].Code), ArgumentCount = ev.Actions[0].ArgumentCount, Who = -1, Relative = false, IsNot = false } } }; // Handle subtype switch (ev) { case AssetObject.EventAlarm e: newEv.Subtype = e.AlarmNumber; break; case AssetObject.EventStep e: newEv.Subtype = (int)e.SubtypeStep; break; case AssetObject.EventCollision e: newEv.Subtype = getObject(e.ObjectName); break; case AssetObject.EventKeyboard e: newEv.Subtype = (int)e.SubtypeKey; break; case AssetObject.EventMouse e: newEv.Subtype = (int)e.SubtypeMouse; break; case AssetObject.EventOther e: newEv.Subtype = (int)e.SubtypeOther; break; case AssetObject.EventDraw e: newEv.Subtype = (int)e.SubtypeDraw; break; case AssetObject.EventGesture e: newEv.Subtype = (int)e.SubtypeGesture; break; } newEvents.Add(newEv); } dataAsset.Events.Add(newEvents); } newList.Add(dataAsset); } dataAssets.Clear(); foreach (var obj in newList) { dataAssets.Add(obj); } }
/// <summary> /// Reads a Game Maker Studio project file /// </summary> private void ReadProjectGMS(string file) { // Set version GameMakerVersion = GMVersionType.GameMakerStudio; // Path with project file removed string folder = file.Remove(file.LastIndexOf("\\")); // Set up resource directory strings Dictionary <GMResourceType, string> directories = new Dictionary <GMResourceType, string>(); directories.Add(GMResourceType.Assets, file); directories.Add(GMResourceType.DataFiles, file); directories.Add(GMResourceType.Configs, file); directories.Add(GMResourceType.Constants, file); directories.Add(GMResourceType.Hash, file); directories.Add(GMResourceType.Backgrounds, folder + "\\" + "background"); directories.Add(GMResourceType.Objects, folder + "\\" + "objects"); directories.Add(GMResourceType.Rooms, folder + "\\" + "rooms"); directories.Add(GMResourceType.Sprites, folder + "\\" + "sprites"); directories.Add(GMResourceType.Sounds, folder + "\\" + "sound"); directories.Add(GMResourceType.TimeLines, folder + "\\" + "timelines"); directories.Add(GMResourceType.Shaders, folder + "\\" + "shaders"); directories.Add(GMResourceType.Scripts, folder + "\\" + "scripts"); directories.Add(GMResourceType.Paths, folder + "\\" + "paths"); // Resource load index int index = 0; // Iterate through directories foreach (KeyValuePair <GMResourceType, string> item in directories) { // Increment directory index index++; // If the directory does not exist, continue if (Path.GetExtension(item.Value) != ".gmx" && !Directory.Exists(item.Value)) { continue; } // Progress changed ProgressChanged("Reading " + item.Key.ToString() + "...", index, directories.Count); // Load data based on resource type switch (item.Key) { case GMResourceType.Hash: Settings.Hash = ReadHashGMX(item.Value); break; case GMResourceType.Assets: ProjectTree = GMNode.ReadTreeGMX(item.Value); Assets = (List <string>)ProjectTree.Tag; break; case GMResourceType.DataFiles: DataFiles = GMDataFile.ReadDataFilesGMX(item.Value, out LastDataFileId); break; case GMResourceType.Sprites: Sprites = GMSprite.ReadSpritesGMX(item.Value, ref Assets); break; //case GMResourceType.Configs: Settings.Configs = GMSettings.GetConfigsGMX(item.Value); break; //case GMResourceType.Constants: Settings.Constants = GMSettings.ReadConstantsGMX(item.Value); break; case GMResourceType.Backgrounds: Backgrounds = GMBackground.ReadBackgroundsGMX(item.Value, ref Assets); break; case GMResourceType.Objects: Objects = GMObject.ReadObjectsGMX(item.Value, ref Assets); break; case GMResourceType.Rooms: Rooms = GMRoom.ReadRoomsGMX(item.Value, ref Assets, out LastTileId); break; //case GMResourceType.TimeLines: Timelines = GMTimeline.ReadTimelinesGMX(item.Value, Assets); break; //case GMResourceType.Sounds: Sounds = GMSound.ReadSoundsGMX(item.Value, ref Assets); break; //case GMResourceType.Shaders: Shaders = GMShader.ReadShadersGMX(item.Value, ref Assets); break; //case GMResourceType.Scripts: Scripts = GMScript.ReadScriptsGMX(item.Value, ref Assets); break; //case GMResourceType.Paths: Paths = GMPath.ReadPathsGMX(item.Value, ref Assets); break; //case GMResourceType.TimeLines: Timelines = GMTimeline.ReadTimelinesGMX(item.Value, Assets); break; } } // Retrieve tutorial data foreach (GMNode node in ProjectTree.Nodes) { // If the node is the tutorial state node and it has the nodes we're looking for if (node.ResourceType == GMResourceType.TutorialState && node.Nodes != null && node.Nodes.Length == 3) { Settings.IsTutorial = node.Nodes[0].Nodes == null ? Settings.IsTutorial : GMResource.GMXBool(node.Nodes[0].Nodes[0].Name, true); Settings.TutorialName = node.Nodes[1].Nodes == null ? Settings.TutorialName : GMResource.GMXString(node.Nodes[1].Nodes[0].FilePath, ""); Settings.TutorialPage = node.Nodes[2].Nodes == null ? Settings.TutorialPage : GMResource.GMXInt(node.Nodes[2].Nodes[0].Name, 0); } } // Progress event ProgressChanged("Finished Reading Project.", index, directories.Count); }
/// <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(); } }
/// <summary> /// Reads sprites from Game Maker project file. /// </summary> public static GMList <GMSprite> ReadSpritesGMX(string directory, ref List <string> assets) { // A list of sprites GMList <GMSprite> sprites = new GMList <GMSprite>(); sprites.AutoIncrementIds = false; // Iterate through .gmx files in the directory foreach (string file in Directory.GetFiles(directory, "*.gmx")) { // Set name of the sprite string name = GetResourceName(file); // If the file is not in the asset list, it has been orphaned, continue if (!assets.Contains(name)) { continue; } // Create a dictionary of sprite properties Dictionary <string, string> properties = new Dictionary <string, string>(); foreach (GMXSpriteProperty property in Enum.GetValues(typeof(GMXSpriteProperty))) { properties.Add(GMXEnumString(property), ""); } // Local variables and texture group strings List <GMImage> subImages = new List <GMImage>(); string textureGroup = GMXEnumString(GMXSpriteProperty.TextureGroup); string textureGroup0 = GMXEnumString(GMXSpriteProperty.TextureGroup0); // Create an xml reader using (XmlReader reader = XmlReader.Create(file)) { // Seek to content reader.MoveToContent(); // Read the GMX file while (reader.Read()) { // If the node is not an element, continue if (reader.NodeType != XmlNodeType.Element) { continue; } // Get the element name string nodeName = reader.Name; // Read element reader.Read(); // If the element value is null or empty, continue if (String.IsNullOrEmpty(reader.Value)) { continue; } // If the element is a frame element create subimage, else normal property if (nodeName.ToLower() == GMXEnumString(GMXSpriteProperty.Frame).ToLower()) { // Create a sub image and set the image path GMImage subImage = new GMImage(); subImage.Compressed = false; subImage.FilePath = reader.Value; subImage.Data = GMUtilities.LoadBytesFromBitmap(directory + "\\" + subImage.FilePath); subImages.Add(subImage); } else { // Set the property value properties[nodeName] = reader.Value; } } } // Create a new sprite, set properties GMSprite sprite = new GMSprite(); sprite.Id = GetIdFromName(name); sprite.Name = name; sprite.OriginX = GMXInt(properties[GMXEnumString(GMXSpriteProperty.XOrigin)], sprite.OriginX); sprite.OriginY = GMXInt(properties[GMXEnumString(GMXSpriteProperty.YOrigin)], sprite.OriginY); sprite.ShapeMode = GMXInt(properties[GMXEnumString(GMXSpriteProperty.ColKind)], sprite.ShapeMode); sprite.AlphaTolerance = GMXInt(properties[GMXEnumString(GMXSpriteProperty.ColTolerance)], sprite.AlphaTolerance); sprite.UseSeperateCollisionMasks = GMXBool(properties[GMXEnumString(GMXSpriteProperty.SepMasks)], sprite.UseSeperateCollisionMasks); sprite.BoundingBoxMode = GMXInt(properties[GMXEnumString(GMXSpriteProperty.BBoxMode)], sprite.BoundingBoxMode); sprite.BoundingBoxLeft = GMXInt(properties[GMXEnumString(GMXSpriteProperty.BBoxLeft)], sprite.BoundingBoxLeft); sprite.BoundingBoxRight = GMXInt(properties[GMXEnumString(GMXSpriteProperty.BBoxRight)], sprite.BoundingBoxRight); sprite.BoundingBoxTop = GMXInt(properties[GMXEnumString(GMXSpriteProperty.BBoxTop)], sprite.BoundingBoxTop); sprite.BoundingBoxBottom = GMXInt(properties[GMXEnumString(GMXSpriteProperty.BBoxBottom)], sprite.BoundingBoxBottom); sprite.TileHorizontally = GMXBool(properties[GMXEnumString(GMXSpriteProperty.HTile)], sprite.TileHorizontally); sprite.TileVertically = GMXBool(properties[GMXEnumString(GMXSpriteProperty.VTile)], sprite.TileVertically); sprite.UsedFor3D = GMXBool(properties[GMXEnumString(GMXSpriteProperty.For3D)], sprite.UsedFor3D); sprite.Width = GMXInt(properties[GMXEnumString(GMXSpriteProperty.Width)], sprite.Width); sprite.Height = GMXInt(properties[GMXEnumString(GMXSpriteProperty.Height)], sprite.Height); properties[textureGroup] = properties[textureGroup] == "" ? "0" : properties[textureGroup]; properties[textureGroup0] = properties[textureGroup0] == "" ? "0" : properties[textureGroup0]; // The texture group does not equal zero set texture group 0 to the texture group value if (properties[textureGroup] != "0") { properties[textureGroup0] = properties[textureGroup]; } // The texture group zero does not equal zero set texture group to the texture group 0 value else if (properties[textureGroup0] != "0") { properties[textureGroup] = properties[textureGroup0]; } // Create a list of texture groups List <int> textureGroups = new List <int>(); for (int i = 0; properties.ContainsKey(textureGroup + i); i++) { textureGroups.Add(Convert.ToInt32(properties[textureGroup + i])); } // Set the subimage size for all subimages foreach (GMImage image in subImages) { image.Width = sprite.Width; image.Height = sprite.Height; } sprite.TextureGroups = textureGroups.ToArray(); sprite.SubImages = subImages.ToArray(); // Add the sprite sprites.Add(sprite); } // Return the list of sprites return(sprites); }
/// <summary> /// Reads timelines from GM file. /// </summary> public static GMList <GMTimeline> ReadTimelines(GMFileReader reader) { // Get version. int version = reader.ReadGMInt(); // Check version. if (version != 500 && version != 800) { throw new Exception("Unsupported Pre-Timeline object version."); } // Create a new timeline list. GMList <GMTimeline> timelines = new GMList <GMTimeline>(); // Amount of timeline ids. int num = reader.ReadGMInt(); // Iterate through timelines for (int i = 0; i < num; i++) { // If version is 8.0, start inflate. if (version == 800) { reader.Decompress(); } // If the timeline at index does not exists, continue. if (reader.ReadGMBool() == false) { timelines.LastId++; reader.EndDecompress(); continue; } // Create a new timeline object. GMTimeline timeline = new GMTimeline(); // Set timeline id. timeline.Id = i; // Read timeline data. timeline.Name = reader.ReadGMString(); // If version is 8.0, get last changed. if (version == 800) { timeline.LastChanged = reader.ReadGMDouble(); } // Get version. int version2 = reader.ReadGMInt(); // Check version. if (version2 != 500) { throw new Exception("Unsupported Timeline object version."); } // Get number of timeline moments. timeline.Moments = new GMMoment[reader.ReadGMInt()]; // Iterate through moments. for (int j = 0; j < timeline.Moments.Length; j++) { // Create a new timeline moment object. GMMoment moment = new GMMoment(); // Moment step number moment.StepIndex = reader.ReadGMInt(); // Read moment actions. moment.Actions = GMAction.ReadActions(reader); // Add moment to timeline. timeline.Moments[j] = moment; } // End object inflate. reader.EndDecompress(); // Add timeline. timelines.Add(timeline); } // Return timelines. return(timelines); }
/// <summary> /// Reads timelines from GM file. /// </summary> private GMList<GMTimeline> ReadTimelines() { // Get version. int version = ReadInt(); // Check version. if (version != 500 && version != 800) throw new Exception("Unsupported Pre-Timeline object version."); // Create a new timeline list. GMList<GMTimeline> timelines = new GMList<GMTimeline>(); // Amount of timeline ids. int num = ReadInt(); // Iterate through timelines for (int i = 0; i < num; i++) { // If version is 8.0, start inflate. if (version == 800) Decompress(); // If the timeline at index does not exists, continue. if (ReadBool() == false) { timelines.LastId++; EndDecompress(); continue; } // Create a new timeline object. GMTimeline timeline = new GMTimeline(); // Set timeline id. timeline.Id = i; // Read timeline data. timeline.Name = ReadString(); // If version is 8.0, get last changed. if (version == 800) timeline.LastChanged = ReadDouble(); // Get version. int version2 = ReadInt(); // Check version. if (version2 != 500) throw new Exception("Unsupported Timeline object version."); // Get number of timeline moments. timeline.Moments = new GMMoment[ReadInt()]; // Iterate through moments. for (int j = 0; j < timeline.Moments.Length; j++) { // Create a new timeline moment object. GMMoment moment = new GMMoment(); // Moment step number moment.StepIndex = ReadInt(); // Read moment actions. moment.Actions = ReadActions(); // Add moment to timeline. timeline.Moments[j] = moment; } // End object inflate. EndDecompress(); // Add timeline. timelines.Add(timeline); } // Return timelines. return timelines; }
/// <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(); } }
/// <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); } }
/// <summary> /// Reads all triggers from Game Maker project file. /// </summary> private GMList<GMTrigger> ReadTriggers() { // Get version. int version = ReadInt(); // Check version. if (version != 800) throw new Exception("Unsupported Pre-Trigger object version."); // Create a new trigger list. GMList<GMTrigger> triggers = new GMList<GMTrigger>(); // Amount of trigger ids. int num = ReadInt(); // Iterate through triggers. for (int i = 0; i < num; i++) { // Start inflate. Decompress(); // If the trigger at index does not exists, continue. if (ReadBool() == false) { triggers.LastId++; EndDecompress(); continue; } // Get version. version = ReadInt(); // Check version. if (version != 800) throw new Exception("Unsupported trigger object version."); // Create a new trigger. GMTrigger trigger = new GMTrigger(); // Read trigger data. trigger.Name = ReadString(); trigger.Condition = ReadString(); trigger.Moment = (MomentType)ReadInt(); trigger.Constant = ReadString(); // End object inflate. EndDecompress(); // Add trigger. triggers.Add(trigger); } // Get last changed. GMTrigger.TriggerLastChanged = ReadDouble(); // Return triggers. return triggers; }
/// <summary> /// Reads sprites from Game Maker project file. /// </summary> public static GMList <GMSprite> ReadSprites(GMFileReader reader) { // Get version int version = reader.ReadGMInt(); // Check version if (version != 400 && version != 800) { throw new Exception("Unsupported Pre-Sprite object version."); } // Create a new list of sprites GMList <GMSprite> sprites = new GMList <GMSprite>(); // Amount of sprite ids int num = reader.ReadGMInt(); // Iterate through sprites for (int i = 0; i < num; i++) { // If version is 8.0, start inflate if (version == 800) { reader.Decompress(); } // If the sprite at index does not exists, continue if (reader.ReadGMBool() == false) { sprites.LastId++; reader.EndDecompress(); continue; } // Create a new sprite object GMSprite sprite = new GMSprite(); // Set sprite id sprite.Id = i; // Read sprite data sprite.Name = reader.ReadGMString(); // If version is 8.0, get last changed if (version == 800) { sprite.LastChanged = reader.ReadGMDouble(); } // Get version version = reader.ReadGMInt(); // Check version if (version != 400 && version != 542 && version != 800) { throw new Exception("Unsupported Sprite object version."); } // If less than version 8.0 if (version < 800) { // Read sprite data sprite.Width = reader.ReadGMInt(); sprite.Height = reader.ReadGMInt(); sprite.BoundingBoxLeft = reader.ReadGMInt(); sprite.BoundingBoxRight = reader.ReadGMInt(); sprite.BoundingBoxBottom = reader.ReadGMInt(); sprite.BoundingBoxTop = reader.ReadGMInt(); sprite.Transparent = reader.ReadGMBool(); // Check version if (version > 400) { // Read sprite data sprite.SmoothEdges = reader.ReadGMBool(); sprite.Preload = reader.ReadGMBool(); } // Read sprite data sprite.BoundingBoxMode = reader.ReadGMInt(); sprite.Precise = reader.ReadGMBool(); // Check version if (version == 400) { // Read sprtie data sprite.UseVideoMemory = reader.ReadGMBool(); sprite.LoadOnlyOnUse = reader.ReadGMBool(); } // Read sprite data sprite.OriginX = reader.ReadGMInt(); sprite.OriginY = reader.ReadGMInt(); // Sprite number of sub images sprite.SubImages = new GMImage[reader.ReadGMInt()]; // Iterate through sub-images for (int j = 0; j < sprite.SubImages.Length; j++) { // If the sub-image at index does not exists, continue if (reader.ReadGMInt() == -1) { continue; } // Create a new image object GMImage image = new GMImage(); // Get size of image data int size = reader.ReadGMInt(); // Get image data image.Data = reader.ReadGMBytes(size); // Insert compressed image data sprite.SubImages[j] = image; } } else { // Read sprite data sprite.OriginX = reader.ReadGMInt(); sprite.OriginY = reader.ReadGMInt(); // Sprite number of sub images sprite.SubImages = new GMImage[reader.ReadGMInt()]; // Iterate through sub-images for (int j = 0; j < sprite.SubImages.Length; j++) { // Get version. version = reader.ReadGMInt(); // Check version if (version != 800) { throw new Exception("Unsupported Sprite object version."); } // Get width and height of image int width = reader.ReadGMInt(); int height = reader.ReadGMInt(); // If the sprite size is not zero if (width != 0 && height != 0) { // Create a new image object GMImage image = new GMImage(); image.Compressed = false; // Set image data image.Width = width; image.Height = height; // Get size of image data int size = reader.ReadGMInt(); // Get image data image.Data = reader.ReadGMBytes(size); // Insert compressed image data sprite.SubImages[j] = image; } } // Read sprite data sprite.ShapeMode = reader.ReadGMInt(); sprite.AlphaTolerance = reader.ReadGMInt(); sprite.UseSeperateCollisionMasks = reader.ReadGMBool(); sprite.BoundingBoxMode = reader.ReadGMInt(); sprite.BoundingBoxLeft = reader.ReadGMInt(); sprite.BoundingBoxRight = reader.ReadGMInt(); sprite.BoundingBoxBottom = reader.ReadGMInt(); sprite.BoundingBoxTop = reader.ReadGMInt(); } // End object inflate reader.EndDecompress(); // Add sprite sprites.Add(sprite); } // Return sprites return(sprites); }
/// <summary> /// Reads backgrounds from GM file. /// </summary> private GMList<GMBackground> ReadBackgrounds() { // Get version. int version = ReadInt(); // Check version. if (version != 400 && version != 800) throw new Exception("Unsupported Pre-Background object version."); // Create a new list of backgrounds. GMList<GMBackground> backgrounds = new GMList<GMBackground>(); // Amount of background ids. int num = ReadInt(); // Iterate through backgrounds. for (int i = 0; i < num; i++) { // If version is 8.0, start inflate. if (version == 800) Decompress(); // If the background at index does not exists, continue. if (ReadBool() == false) { backgrounds.LastId++; EndDecompress(); continue; } // Create a new background object. GMBackground background = new GMBackground(); // Set background id background.Id = i; // Get background data. background.Name = ReadString(); // If version is 8.0, get last changed. if (version == 800) background.LastChanged = ReadDouble(); // Get version. version = ReadInt(); // Check version. if (version != 400 && version != 543 && version != 710) throw new Exception("Unsupported Background object version."); // If version is less than 7.1. if (version < 710) { // Background data background.Width = ReadInt(); background.Height = ReadInt(); background.Transparent = ReadBool(); // Check version. if (version > 400) { // Read background data. background.SmoothEdges = ReadBool(); background.Preload = ReadBool(); background.UseAsTileSet = ReadBool(); background.TileWidth = ReadInt(); background.TileHeight = ReadInt(); background.HorizontalOffset = ReadInt(); background.VerticalOffset = ReadInt(); background.HorizontalSeperation = ReadInt(); background.VerticalSeperation = ReadInt(); } else { // Read background data. background.UseVideoMemory = ReadBool(); background.LoadOnlyOnUse = ReadBool(); } // If image data exists. if (ReadBool()) { // If pixel data does not exist. if (ReadInt() == -1) continue; // Create a new image. GMImage image = new GMImage(); // Get size of image data. int size = ReadInt(); // Get compressed image data. image.Data = ReadBytes(size); // Set background image. background.Image = image; } } else { // Get background data. background.UseAsTileSet = ReadBool(); background.TileWidth = ReadInt(); background.TileHeight = ReadInt(); background.HorizontalOffset = ReadInt(); background.VerticalOffset = ReadInt(); background.HorizontalSeperation = ReadInt(); background.VerticalSeperation = ReadInt(); // Get version. version = ReadInt(); // Check version. if (version != 800) throw new Exception("Unsupported Background object version."); // Get image data. background.Width = ReadInt(); background.Height = ReadInt(); // If the sprite size is not zero. if (background.Width != 0 && background.Height != 0) { // Create a new image object. GMImage image = new GMImage(); image.Compressed = false; // Set image data. image.Width = background.Width; image.Height = background.Height; // Get size of image data. int size = ReadInt(); // Get image data. image.Data = ReadBytes(size); // Insert compressed image data. background.Image = image; } } // End object inflate. EndDecompress(); // Add background. backgrounds.Add(background); } // Return backgrounds. return backgrounds; }
/// <summary> /// Reads all GMX timelines from a directory /// </summary> /// <param name="file">The XML (.GMX) file path</param> /// <returns>A list of timelines</returns> public static GMList <GMTimeline> ReadTimelinesGMX(string directory, List <string> assets) { // A list of timelines GMList <GMTimeline> timelines = new GMList <GMTimeline>(); timelines.AutoIncrementIds = false; // Iterate through .gmx files in the directory foreach (string file in Directory.GetFiles(directory, "*.gmx")) { // Set name of the timeline string name = GetResourceName(file); // If the file is not in the asset list, it has been orphaned, continue if (!assets.Contains(name)) { continue; } // Create a dictionary of object properties Dictionary <string, string> objectProperties = new Dictionary <string, string>(); foreach (GMXObjectProperty property in Enum.GetValues(typeof(GMXObjectProperty))) { objectProperties.Add(GMXEnumString(property), ""); } // Create a dictionary of action properties Dictionary <string, string> actionProperties = new Dictionary <string, string>(); foreach (GMXActionProperty property in Enum.GetValues(typeof(GMXActionProperty))) { actionProperties.Add(GMXEnumString(property), ""); } // Create a dictionary of argument properties Dictionary <string, string> argumentProperties = new Dictionary <string, string>(); foreach (GMXArgumentProperty property in Enum.GetValues(typeof(GMXArgumentProperty))) { argumentProperties.Add(GMXEnumString(property), ""); } // Local variables List <GMMoment> moments = new List <GMMoment>(); // Create an xml reader using (XmlReader reader = XmlReader.Create(file)) { // Seek to content reader.MoveToContent(); // Read the GMX file while (reader.Read()) { // If the node is not an element, continue if (reader.NodeType != XmlNodeType.Element) { continue; } // Get the element name string nodeName = reader.Name; // Create a new moment and get it's properties GMMoment moment = new GMMoment(); // If the element is an event if (nodeName.ToLower() == GMXEnumString(GMXObjectProperty.Event).ToLower()) { // Action list List <GMAction> actions = new List <GMAction>(); // Seek to content reader.MoveToContent(); // Create a reader for the actions using (XmlReader reader2 = reader.ReadSubtree()) { // Argument list List <GMArgument> arguments = new List <GMArgument>(); // Read in action properties while (reader2.Read()) { // If the node is not an element, continue if (reader.NodeType != XmlNodeType.Element) { continue; } // Get the element name string nodeName2 = reader2.Name; // If the node is an argument if (nodeName2.ToLower() == EnumString.GetEnumString(GMXObjectProperty.Argument).ToLower()) { // Seek to content reader2.MoveToContent(); // Create a reader for the arguments using (XmlReader reader3 = reader2.ReadSubtree()) { // Read in argument properties while (reader3.Read()) { // If the node is not an element, continue if (reader.NodeType != XmlNodeType.Element) { continue; } // Get the element name string nodeName3 = reader3.Name; // Read element reader3.Read(); // If the element value is null or empty, continue if (String.IsNullOrEmpty(reader3.Value)) { continue; } // Set the property value argumentProperties[nodeName3] = reader3.Value; } // Create a new argument GMArgument argument = new GMArgument(); argument.Type = GMXInt(argumentProperties[GMXEnumString(GMXArgumentProperty.Kind)], argument.Type); argument.Value = GMXString(argumentProperties[GMXEnumString(GMXArgumentProperty.String)], argument.Value); // Add argument to the list arguments.Add(argument); } } // Read element reader2.Read(); // If the element value is null or empty, continue if (String.IsNullOrEmpty(reader2.Value)) { continue; } // Set the property value actionProperties[nodeName2] = reader2.Value; } // Create a new action GMAction action = new GMAction(); action.LibraryId = GMXInt(actionProperties[GMXEnumString(GMXActionProperty.LibId)], action.LibraryId); action.ActionId = GMXInt(actionProperties[GMXEnumString(GMXActionProperty.Id)], action.ActionId); action.ActionKind = GMXInt(actionProperties[GMXEnumString(GMXActionProperty.Kind)], action.ActionKind); action.AllowRelative = GMXBool(actionProperties[GMXEnumString(GMXActionProperty.UseRelative)], action.AllowRelative); action.Question = GMXBool(actionProperties[GMXEnumString(GMXActionProperty.IsQuestion)], action.Question); action.CanApplyTo = GMXBool(actionProperties[GMXEnumString(GMXActionProperty.UseApplyTo)], action.CanApplyTo); action.ExecuteMode = GMXInt(actionProperties[GMXEnumString(GMXActionProperty.ExeType)], action.ExecuteMode); action.FunctionName = GMXString(actionProperties[GMXEnumString(GMXActionProperty.FunctionName)], action.FunctionName); action.ExecuteCode = GMXString(actionProperties[GMXEnumString(GMXActionProperty.CodeString)], action.ExecuteCode); action.AppliesToName = GMXString(actionProperties[GMXEnumString(GMXActionProperty.WhoName)], action.AppliesToName); action.AppliesTo = action.AppliesToName == "" ? -1 : GetIdFromName(action.AppliesToName); action.Relative = GMXBool(actionProperties[GMXEnumString(GMXActionProperty.Relative)], action.Relative); action.Not = GMXBool(actionProperties[GMXEnumString(GMXActionProperty.IsNot)], action.Not); action.Arguments = arguments.ToArray(); // Add action to the list actions.Add(action); } // Set the events actions moment.Actions = actions.ToArray(); moments.Add(moment); } if (nodeName.ToLower() == "step") { // Read element reader.Read(); // If the element value is null or empty, continue if (String.IsNullOrEmpty(reader.Value)) { continue; } moment.StepIndex = GMXInt(reader.Value, moment.StepIndex); moments.Add(moment); } // Set the property value objectProperties[nodeName] = reader.Value; } } // Create a new timeline, set properties GMTimeline timeline = new GMTimeline(); timeline.Moments = moments.ToArray(); // Add the timeline timelines.Add(timeline); } // Return the list of timelines return(timelines); }
/// <summary> /// Reads data files from GM file. /// </summary> private GMList<GMDataFile> ReadDataFiles() { // Create a new list of data files. GMList<GMDataFile> dataFiles = new GMList<GMDataFile>(); // Amount of data file ids. int num = ReadInt(); // Iterate through data files. for (int i = 0; i < num; i++) { // If the data file at index does not exists, continue. if (ReadBool() == false) { dataFiles.LastId++; continue; } // Create a new data file object. GMDataFile dataFile = new GMDataFile(); // Set data file id. dataFile.Id = i; // Read data file data. dataFile.Name = ReadString(); // Get version. int version = ReadInt(); // Check version. if (version != 440) throw new Exception("Unsupported Data File object version."); // Read data file data. dataFile.FileName = ReadString(); // If data file exists, read it in. if (ReadBool()) dataFile.Data = ReadBytes(ReadInt()); // Read data file data. dataFile.ExportMode = (ExportType)(ReadInt()); dataFile.OverwriteFile = ReadBool(); dataFile.FreeDataMemory = ReadBool(); dataFile.RemoveAtGameEnd = ReadBool(); // Add data file. dataFiles.Add(dataFile); } // Return data files. return dataFiles; }
/// <summary> /// Reads all scripts from a GM file reader stream. /// </summary> public static GMList <GMScript> ReadScripts(GMFileReader reader) { // Get version. int version = reader.ReadGMInt(); // Check version. if (version != 400 && version != 800) { throw new Exception("Unsupported Pre-Script object version."); } // Create a new list of scripts. GMList <GMScript> scripts = new GMList <GMScript>(); // Amount of script ids. int num = reader.ReadGMInt(); // Iterate through scripts. for (int i = 0; i < num; i++) { // If version is 8.0, start inflate. if (version == 800) { reader.Decompress(); } // If the script at index does not exists, continue. if (reader.ReadGMBool() == false) { scripts.LastId++; reader.EndDecompress(); continue; } // Create a new script object. GMScript script = new GMScript(); // Set script id. script.Id = i; // Read script data. script.Name = reader.ReadGMString(); // If version is 8.0, get last changed. if (version == 800) { script.LastChanged = reader.ReadGMDouble(); } // Get version. version = reader.ReadGMInt(); // Check version. if (version != 400 && version != 800) { throw new Exception("Unsupported Script object version."); } // Read script data. script.Code = reader.ReadGMString(); // End object inflate. reader.EndDecompress(); // Add script. scripts.Add(script); } // Return scripts. return(scripts); }
/// <summary> /// Reads fonts from GM file. /// </summary> private GMList<GMFont> ReadFonts(int version) { // Create a new list of fonts. GMList<GMFont> fonts = new GMList<GMFont>(); // Amount of font ids. int num = ReadInt(); // Iterate through fonts. for (int i = 0; i < num; i++) { // If version is 8.0, start inflate. if (version == 800) Decompress(); // If the font at index does not exists, continue. if (ReadBool() == false) { fonts.LastId++; EndDecompress(); continue; } // Create a new font object. GMFont font = new GMFont(); // Set font id. font.Id = i; // Read font data. font.Name = ReadString(); // If version is 8.0, get last changed. if (version == 800) font.LastChanged = ReadDouble(); // Get version. version = ReadInt(); // Check version. if (version != 540 && version != 800) throw new Exception("Unsupported Font object version."); // Read font data. font.FontName = ReadString(); font.Size = ReadInt(); font.Bold = ReadBool(); font.Italic = ReadBool(); font.CharacterRangeMin = ReadInt(); font.CharacterRangeMax = ReadInt(); // End object inflate. EndDecompress(); // Add font. fonts.Add(font); } // Return fonts. return fonts; }
/// <summary> /// Reads all triggers from GM file reader stream. /// </summary> public static GMList <GMTrigger> ReadTriggers(GMFileReader reader) { // Get version. int version = reader.ReadGMInt(); // Check version. if (version != 800) { throw new Exception("Unsupported Pre-Trigger object version."); } // Create a new trigger list. GMList <GMTrigger> triggers = new GMList <GMTrigger>(); // Amount of trigger ids. int num = reader.ReadGMInt(); // Iterate through triggers. for (int i = 0; i < num; i++) { // Start inflate. reader.Decompress(); // If the trigger at index does not exists, continue. if (reader.ReadGMBool() == false) { triggers.LastId++; reader.EndDecompress(); continue; } // Get version. version = reader.ReadGMInt(); // Check version. if (version != 800) { throw new Exception("Unsupported trigger object version."); } // Create a new trigger. GMTrigger trigger = new GMTrigger(); // Read trigger data. trigger.Name = reader.ReadGMString(); trigger.Condition = reader.ReadGMString(); trigger.Moment = (MomentType)reader.ReadGMInt(); trigger.Constant = reader.ReadGMString(); // End object inflate. reader.EndDecompress(); // Add trigger. triggers.Add(trigger); } // Get last changed. GMTrigger.TriggerLastChanged = reader.ReadGMDouble(); // Return triggers. return(triggers); }
/// <summary> /// Reads objects from GM file /// </summary> private GMList<GMObject> ReadObjects() { // Get version. int version = ReadInt(); // Check version. if (version != 400 && version != 800) throw new Exception("Unsupported Pre-Object object version."); // The number of objects. GMList<GMObject> objects = new GMList<GMObject>(); // Amount of object ids. int num = ReadInt(); // Iterate through objects for (int i = 0; i < num; i++) { // If version is 8.0, start inflate. if (version == 800) Decompress(); // If the object at index does not exists, continue. if (ReadBool() == false) { objects.LastId++; EndDecompress(); continue; } // Create a new script object. GMObject obj = new GMObject(); // Set script id. obj.Id = i; // Read script data. obj.Name = ReadString(); // If version is 8.0, get last changed. if (version == 800) obj.LastChanged = ReadDouble(); // Get version. int version2 = ReadInt(); // Check version. if (version2 != 430) throw new Exception("Unsupported Object object version."); // Read object data. obj.SpriteId = ReadInt(); obj.Solid = ReadBool(); obj.Visible = ReadBool(); obj.Depth = ReadInt(); obj.Persistent = ReadBool(); obj.Parent = ReadInt(); obj.Mask = ReadInt(); // Skip data. ReadBytes(4); // The amount of main event types. int amount = 11; // If version 8.0, there are 12 main event types. if (version == 800) amount = 12; // Iterate through events. for (int j = 0; j < amount; j++) { // Not done processing. bool done = false; // While not done processing events. while (!done) { // Check for event int eventNum = ReadInt(); // If the event exists if (eventNum != -1) { // Create new event. GMEvent ev = new GMEvent(); // Set type of event. ev.MainType = (EventType)(j); // If a collision type of event set other object id. if (ev.MainType == EventType.Collision) ev.OtherId = eventNum; else ev.SubType = eventNum; // Read event actions. ev.Actions = ReadActions(); // Add new event. obj.Events[j].Add(ev); } else done = true; } } // End object inflate. EndDecompress(); // Add object to list. objects.Add(obj); } // Return objects. return objects; }