public static void SaveDeck(MemTools.YdcDeck deck, string path) { try { using (TextWriter writer = File.CreateText(path)) { writer.WriteLine("#main"); for (int i = 0; i < deck.NumMainDeckCards; i++) { long ydkCardId; if (officialIdToYdkId.TryGetValue(deck.MainDeck[i], out ydkCardId)) { writer.WriteLine(ydkCardId); } } writer.WriteLine(); writer.WriteLine("#extra"); for (int i = 0; i < deck.NumExtraDeckCards; i++) { long ydkCardId; if (officialIdToYdkId.TryGetValue(deck.ExtraDeck[i], out ydkCardId)) { writer.WriteLine(ydkCardId); } } writer.WriteLine(); writer.WriteLine("!side"); for (int i = 0; i < deck.NumSideDeckCards; i++) { long ydkCardId; if (officialIdToYdkId.TryGetValue(deck.SideDeck[i], out ydkCardId)) { writer.WriteLine(ydkCardId); } } writer.WriteLine(); } } catch { } }
public static MemTools.YdcDeck LoadDeck(string filePath) { // Loader is based on https://github.com/Fluorohydride/ygopro/blob/master/gframe/deck_manager.cpp MemTools.YdcDeck result = new MemTools.YdcDeck(); result.DeckName = Path.GetFileNameWithoutExtension(filePath); result.MainDeck = new short[Constants.NumMainDeckCards]; result.ExtraDeck = new short[Constants.NumMainDeckCards]; result.SideDeck = new short[Constants.NumMainDeckCards]; result.Unk1 = new byte[12]; result.Unk2 = new byte[12]; result.IsDeckComplete = true; result.DeckAvatarId = 5;// Joey! TODO: Allow this to be configured... if (File.Exists(filePath)) { bool isSide = false; string[] lines = File.ReadAllLines(filePath); foreach (string line in lines) { if (line.StartsWith("!")) { isSide = true; } else if (!line.StartsWith("#")) { long ydkCardId, officialCardId; CardInfo card; if (long.TryParse(line.Trim(), out ydkCardId) && ydkIdToOfficialId.TryGetValue(ydkCardId, out officialCardId) && Program.Manager.CardManager.Cards.TryGetValue((short)officialCardId, out card)) { if (isSide) { if (result.NumSideDeckCards < result.SideDeck.Length) { result.SideDeck[result.NumSideDeckCards] = card.CardId; result.NumSideDeckCards++; } } else if (card.CardTypeFlags.HasFlag(CardTypeFlags.Fusion) || card.CardTypeFlags.HasFlag(CardTypeFlags.Synchro) || card.CardTypeFlags.HasFlag(CardTypeFlags.DarkSynchro) || card.CardTypeFlags.HasFlag(CardTypeFlags.Xyz) || card.CardTypeFlags.HasFlag(CardTypeFlags.Link)) { if (result.NumExtraDeckCards < result.ExtraDeck.Length) { result.ExtraDeck[result.NumExtraDeckCards] = card.CardId; result.NumExtraDeckCards++; } } else { if (result.NumMainDeckCards < result.MainDeck.Length) { result.MainDeck[result.NumMainDeckCards] = card.CardId; result.NumMainDeckCards++; } } } } } } return(result); }