using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; using Mesen.GUI.Config; namespace Mesen.GUI.Forms.Cheats { class MesenCheatExporter { 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 = ""; 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"); 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}"; } xml += "
"; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); xmlDoc.Save(filename); } } }