diff --git a/GUI.NET/Forms/Cheats/MesenCheatExporter.cs b/GUI.NET/Forms/Cheats/MesenCheatExporter.cs index fcb117a0..94434ae7 100644 --- a/GUI.NET/Forms/Cheats/MesenCheatExporter.cs +++ b/GUI.NET/Forms/Cheats/MesenCheatExporter.cs @@ -13,30 +13,36 @@ namespace Mesen.GUI.Forms.Cheats public static void Export(string filename, IEnumerable cheats) { //Exports to an XML format compatible with Nestopia's, but with an extra flag (isPrgOffset) - string xml = ""; + XmlWriter writer = XmlWriter.Create(filename, new XmlWriterSettings() { Indent = true }); + writer.WriteStartElement("cheats"); + writer.WriteAttributeString("MesenCheatFile", "true"); + writer.WriteAttributeString("version", "1.0"); foreach(CheatInfo cheat in cheats) { - string enabled = cheat.Enabled ? "1" : "0"; - string gameCrc = "0x" + cheat.GameCrc; - string address = "0x" + cheat.Address.ToString("X4"); - string value = "0x" + cheat.Value.ToString("X2"); - string compare = "0x" + cheat.CompareValue.ToString("X2"); - string genie = cheat.GameGenieCode; - string rocky = cheat.ProActionRockyCode.ToString("X8"); + writer.WriteStartElement("cheat"); + writer.WriteAttributeString("enabled", cheat.Enabled ? "1" : "0"); + writer.WriteAttributeString("game", "0x" + cheat.GameCrc); + writer.WriteAttributeString("gameName", cheat.GameName); - string genieTag = cheat.CheatType == CheatType.GameGenie ? $"{genie}" : ""; - string rockyTag = cheat.CheatType == CheatType.ProActionRocky ? $"{rocky}" : ""; - string customTags = cheat.CheatType == CheatType.Custom ? $"
{address}
{value}{compare}" : ""; - - string prgAddress = !cheat.IsRelativeAddress ? "true" : ""; - - xml += $"{genieTag}{rockyTag}{customTags}{prgAddress}{cheat.CheatName}"; + switch(cheat.CheatType) { + case CheatType.GameGenie: writer.WriteElementString("genie", cheat.GameGenieCode); break; + case CheatType.ProActionRocky: writer.WriteElementString("rocky", cheat.ProActionRockyCode.ToString("X8")); break; + case CheatType.Custom: + writer.WriteElementString("address", "0x" + cheat.Address.ToString("X4")); + writer.WriteElementString("value", "0x" + cheat.Value.ToString("X2")); + writer.WriteElementString("compare", "0x" + cheat.CompareValue.ToString("X2")); + if(!cheat.IsRelativeAddress) { + writer.WriteElementString("isPrgOffset", "true"); + } + break; + } + writer.WriteElementString("description", cheat.CheatName); + writer.WriteEndElement(); } - xml += "
"; + writer.WriteEndElement(); - XmlDocument xmlDoc = new XmlDocument(); - xmlDoc.LoadXml(xml); - xmlDoc.Save(filename); + writer.Flush(); + writer.Close(); } } } diff --git a/GUI.NET/Forms/Cheats/NestopiaCheatLoader.cs b/GUI.NET/Forms/Cheats/NestopiaCheatLoader.cs index 1163ea57..c20a9006 100644 --- a/GUI.NET/Forms/Cheats/NestopiaCheatLoader.cs +++ b/GUI.NET/Forms/Cheats/NestopiaCheatLoader.cs @@ -70,7 +70,7 @@ namespace Mesen.GUI.Forms.Cheats var address = node.SelectSingleNode("address"); var value = node.SelectSingleNode("value"); var compare = node.SelectSingleNode("compare"); - bool isPrgOffset = node.SelectSingleNode("isPrgOffset")?.Value == "true"; + bool isPrgOffset = node.SelectSingleNode("isPrgOffset")?.InnerText == "true"; var cheat = new CheatInfo(); cheat.GameCrc = crc; diff --git a/GUI.NET/Resources/CheatCode.png b/GUI.NET/Resources/CheatCode.png index 327971df..4d9e7932 100644 Binary files a/GUI.NET/Resources/CheatCode.png and b/GUI.NET/Resources/CheatCode.png differ