private static Image getSprite(MysteryGift gift) { if (gift.Empty) return null; Image img; if (gift.IsPokémon) img = getSprite(gift.convertToPKM(Main.SAV)); else if (gift.IsItem) img = (Image)(Resources.ResourceManager.GetObject("item_" + gift.Item) ?? Resources.unknown); else img = Resources.unknown; if (gift.GiftUsed) img = ImageUtil.LayerImage(new Bitmap(img.Width, img.Height), img, 0, 0, 0.3); return img; }
public SAV_Wondercard(MysteryGift g = null) { InitializeComponent(); WinFormsUtil.TranslateInterface(this, Main.curlanguage); mga = Main.SAV.GiftAlbum; switch (SAV.Generation) { case 4: pba = popG4Gifts().ToArray(); break; case 5: case 6: case 7: pba = popG567Gifts().ToArray(); break; default: throw new ArgumentException("Game not supported."); } foreach (PictureBox pb in pba) { pb.AllowDrop = true; pb.DragDrop += pbBoxSlot_DragDrop; pb.DragEnter += pbBoxSlot_DragEnter; pb.MouseDown += pbBoxSlot_MouseDown; pb.ContextMenuStrip = mnuVSD; } setGiftBoxes(); getReceivedFlags(); if (LB_Received.Items.Count > 0) LB_Received.SelectedIndex = 0; DragEnter += tabMain_DragEnter; DragDrop += tabMain_DragDrop; if (g == null) clickView(pba[0], null); else viewGiftData(g); }
private static void VerifyFatefulMysteryGift(LegalityAnalysis data, MysteryGift g) { var pkm = data.pkm; if (g is PGF p && p.IsShiny) { var Info = data.Info; Info.PIDIV = MethodFinder.Analyze(pkm); if (Info.PIDIV.Type != PIDType.G5MGShiny && pkm.Egg_Location != 30003) { data.AddLine(GetInvalid(LPIDTypeMismatch, CheckIdentifier.PID)); } } var result = pkm.FatefulEncounter ? GetValid(LFatefulMystery, CheckIdentifier.Fateful) : GetInvalid(LFatefulMysteryMissing, CheckIdentifier.Fateful); data.AddLine(result); }
private static void AddLinesPKM(MysteryGift gift, IBasicStrings strings, ICollection <string> result) { var id = gift.Format < 7 ? $"{gift.TID:D5}/{gift.SID:D5}" : $"[{gift.TrainerSID7:D4}]{gift.TrainerID7:D6}"; var first = $"{strings.Species[gift.Species]} @ {strings.Item[gift.HeldItem]} --- " + (gift.IsEgg ? strings.EggName : $"{gift.OT_Name} - {id}"); result.Add(first); result.Add(string.Join(" / ", gift.Moves.Select(z => strings.Move[z]))); if (gift is WC7 wc7) { var addItem = wc7.AdditionalItem; if (addItem != 0) { result.Add($"+ {strings.Item[addItem]}"); } } }
private static void VerifyReceivability(LegalityAnalysis data, MysteryGift g) { var pkm = data.pkm; switch (g) { case WC6 wc6 when !wc6.CanBeReceivedByVersion(pkm.Version) && !pkm.WasTradedEgg: case WC7 wc7 when !wc7.CanBeReceivedByVersion(pkm.Version) && !pkm.WasTradedEgg: data.AddLine(GetInvalid(LEncGiftVersionNotDistributed, GameOrigin)); return; case WC6 wc6 when wc6.RestrictLanguage != 0 && wc6.Language != wc6.RestrictLanguage: data.AddLine(GetInvalid(string.Format(LOTLanguage, wc6.RestrictLanguage, pkm.Language), CheckIdentifier.Language)); return; case WC7 wc7 when wc7.RestrictLanguage != 0 && wc7.Language != wc7.RestrictLanguage: data.AddLine(GetInvalid(string.Format(LOTLanguage, wc7.RestrictLanguage, pkm.Language), CheckIdentifier.Language)); return; } }
private static void VerifyReceivability(LegalityAnalysis data, MysteryGift g) { var pkm = data.pkm; switch (g) { case WC6 wc6 when !wc6.CanBeReceivedByVersion(pkm.Version): case WC7 wc7 when !wc7.CanBeReceivedByVersion(pkm.Version): data.AddLine(GetInvalid(V416, CheckIdentifier.GameOrigin)); return; case WC6 wc6 when wc6.RestrictLanguage != 0 && wc6.Language != wc6.RestrictLanguage: data.AddLine(GetInvalid(string.Format(V5, wc6.RestrictLanguage, pkm.Language), CheckIdentifier.Language)); return; case WC7 wc7 when wc7.RestrictLanguage != 0 && wc7.Language != wc7.RestrictLanguage: data.AddLine(GetInvalid(string.Format(V5, wc7.RestrictLanguage, pkm.Language), CheckIdentifier.Language)); return; } }
public static void RefreshMGDB(params string[] paths) { var g4 = GetPCDDB(Util.GetBinaryResource("wc4.pkl")); var g5 = GetPGFDB(Util.GetBinaryResource("pgf.pkl")); var g6 = GetWC6DB(Util.GetBinaryResource("wc6.pkl"), Util.GetBinaryResource("wc6full.pkl")); var g7 = GetWC7DB(Util.GetBinaryResource("wc7.pkl"), Util.GetBinaryResource("wc7full.pkl")); var b7 = GetWB7DB(Util.GetBinaryResource("wb7full.pkl")); foreach (var path in paths.Where(Directory.Exists)) { foreach (var file in Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories)) { var fi = new FileInfo(file); if (!MysteryGift.IsMysteryGift(fi.Length)) { continue; } var gift = MysteryGift.GetMysteryGift(File.ReadAllBytes(file), fi.Extension); switch (gift) { case PCD pcd: g4.Add(pcd); continue; case PGF pgf: g5.Add(pgf); continue; case WC6 wc6: g6.Add(wc6); continue; case WC7 wc7: g7.Add(wc7); continue; case WB7 wb7: b7.Add(wb7); continue; } } } MGDB_G3 = Encounter_WC3; // hardcoded MGDB_G4 = g4.ToArray(); MGDB_G5 = g5.ToArray(); MGDB_G6 = g6.ToArray(); MGDB_G7 = g7.ToArray(); MGDB_G7GG = b7.ToArray(); }
private void viewGiftData(MysteryGift g) { try { // only check if the form is visible (not opening) if (Visible && g.GiftUsed && DialogResult.Yes == WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Wonder Card is marked as USED and will not be able to be picked up in-game.", "Do you want to remove the USED flag so that it is UNUSED?")) g.GiftUsed = false; RTB.Text = getDescription(g); PB_Preview.Image = g.Sprite(); mg = g; } catch (Exception e) { WinFormsUtil.Error("Loading of data failed... is this really a Wonder Card?", e); RTB.Clear(); } }
public static IEnumerable <MysteryGift> GetAllEvents(bool sorted = true) { var regular = new MysteryGift[][] { MGDB_G4, MGDB_G5, MGDB_G6, MGDB_G7, MGDB_G7GG, MGDB_G8, }.SelectMany(z => z); regular = regular.Where(mg => !mg.IsItem && mg.IsPokémon && mg.Species > 0); var result = MGDB_G3.Concat(regular); if (sorted) { result = result.OrderBy(mg => mg.Species); } return(result); }
public static bool IsCardCompatible(this MysteryGift g, SaveFile SAV, out string message) { if (g.Format != SAV.Generation) { message = MsgMysteryGiftSlotSpecialReject; return(false); } if (g is WC6 && g.CardID == 2048 && g.ItemID == 726) // Eon Ticket (OR/AS) { if (!SAV.ORAS) { message = MsgMysteryGiftSlotSpecialReject; return(false); } // Set the special recieved data BitConverter.GetBytes(WC6.EonTicketConst).CopyTo(SAV.Data, ((SAV6)SAV).EonTicket); } message = null; return(true); }
private void VerifyFatefulMysteryGift(LegalityAnalysis data, MysteryGift g) { var pkm = data.pkm; if (g is PGF p && p.IsShiny) { var Info = data.Info; Info.PIDIV = MethodFinder.Analyze(pkm); if (Info.PIDIV.Type != PIDType.G5MGShiny && pkm.Egg_Location != 30003) { data.AddLine(GetInvalid(V411, CheckIdentifier.PID)); } } if (pkm.FatefulEncounter) { data.AddLine(GetValid(V321, CheckIdentifier.Fateful)); } else { data.AddLine(GetInvalid(V322, CheckIdentifier.Fateful)); } }
private static CheckResult VerifyEncounterEvent(PKM pkm, MysteryGift MatchedGift) { switch (MatchedGift) { case PCD pcd: if (!pcd.CanBeReceivedBy(pkm.Version) && pcd.Gift.PK.Version == 0) { return(new CheckResult(Severity.Invalid, string.Format(L_XMatches0_1, MatchedGift.CardHeader, $"-- {LEncGiftVersionNotDistributed}"), CheckIdentifier.Encounter)); } break; } if (!pkm.IsEgg && MatchedGift.IsEgg) // hatched { var hatchCheck = VerifyEncounterEgg(pkm); if (!hatchCheck.Valid) { return(hatchCheck); } } // Strict matching already performed by EncounterGenerator. May be worth moving some checks here to better flag invalid gifts. return(new CheckResult(Severity.Valid, string.Format(L_XMatches0_1, MatchedGift.CardHeader, string.Empty), CheckIdentifier.Encounter)); }
private void VerifyIVsMystery(LegalityAnalysis data, MysteryGift g) { int[] IVs = g.IVs; if (IVs == null) { return; } var ivflag = Array.Find(IVs, iv => (byte)(iv - 0xFC) < 3); if (ivflag == 0) // Random IVs { bool valid = GetIsFixedIVSequenceValid(IVs, data.pkm.IVs); if (!valid) { data.AddLine(GetInvalid(LEncGiftIVMismatch)); } } else { int IVCount = ivflag - 0xFB; // IV2/IV3 VerifyIVsFlawless(data, IVCount); } }
private void setWC6(MysteryGift wc6, int index) { if (WondercardData < 0) return; if (index < 0 || index > GiftCountMax) return; wc6.Data.CopyTo(Data, WondercardData + index * WC6.Size); for (int i = 0; i < GiftCountMax; i++) if (BitConverter.ToUInt16(Data, WondercardData + i * WC6.Size) == 0) for (int j = i + 1; j < GiftCountMax - i; j++) // Shift everything down Array.Copy(Data, WondercardData + j * WC6.Size, Data, WondercardData + (j - 1) * WC6.Size, WC6.Size); Edited = true; }
private void clickSet(object sender, EventArgs e) { if (!checkSpecialWonderCard(mg)) return; sender = ((sender as ToolStripItem)?.Owner as ContextMenuStrip)?.SourceControl ?? sender as PictureBox; int index = Array.IndexOf(pba, sender); // Hijack to the latest unfilled slot if index creates interstitial empty slots. int lastUnfilled = getLastUnfilledByType(mg, mga); if (lastUnfilled > -1 && lastUnfilled < index) index = lastUnfilled; if (mg is PCD && mga.Gifts[index] is PGT) mg = (mg as PCD).Gift; else if (mg.Type != mga.Gifts[index].Type) { WinFormsUtil.Alert("Can't set slot here.", $"{mg.Type} != {mga.Gifts[index].Type}"); return; } setBackground(index, Core.Properties.Resources.slotSet); mga.Gifts[index] = mg.Clone(); setGiftBoxes(); setCardID(mg.CardID); }
private static bool getIsMysteryGiftAvailable(MysteryGift[] value) { if (value == null) return false; for (int i = 0; i < 8; i++) // 8 PGT if ((value[i] as PGT)?.CardType != 0) return true; for (int i = 8; i < 11; i++) // 3 PCD if ((value[i] as PCD)?.Gift.CardType != 0) return true; return false; }
private CheckResult VerifyBallMysteryGift(LegalityAnalysis data, MysteryGift g) { if (g.Generation == 4 && g.Species == (int)Species.Manaphy && g.Ball == 0) // there is no ball data in Manaphy Mystery Gift from Gen4 return VerifyBallEquals(data, (int)Poke); // Pokeball return VerifyBallEquals(data, g.Ball); }
private static int[] matchMysteryGifts(MysteryGift[] value) { if (value == null) return null; int[] cardMatch = new int[8]; for (int i = 0; i < 8; i++) { var pgt = value[i] as PGT; if (pgt == null) continue; cardMatch[i] = pgt.Slot = 3; for (byte j = 0; j < 3; j++) { var pcd = value[8 + j] as PCD; if (pcd == null) continue; // Check if data matches (except Slot @ 0x02) if (!pcd.Gift.Data.Take(2).Skip(1).SequenceEqual(pgt.Data.Take(2).Skip(1))) continue; cardMatch[i] = pgt.Slot = j; break; } } return cardMatch; }
/// <summary> /// Tries to get a <see cref="MysteryGift"/> object from the input parameters. /// </summary> /// <param name="data">Binary data</param> /// <param name="mg">Output result</param> /// <param name="ext">Format hint</param> /// <returns>True if file object reference is valid, false if none found.</returns> public static bool TryGetMysteryGift(byte[] data, out MysteryGift?mg, string ext) { mg = MysteryGift.GetMysteryGift(data, ext); return(mg != null); }
private int getLastUnfilledByType(MysteryGift Gift, MysteryGiftAlbum Album) { for (int i = 0; i < Album.Gifts.Length; i++) { if (!Album.Gifts[i].Empty) continue; if (Album.Gifts[i].Type != Gift.Type) continue; return i; } return -1; }
private static string getDescription(MysteryGift gift) { if (gift.Empty) return "Empty Slot. No data!"; string s = gift.getCardHeader() + Environment.NewLine; if (gift.IsItem) { s += "Item: " + GameInfo.Strings.itemlist[gift.Item] + Environment.NewLine + "Quantity: " + gift.Quantity + Environment.NewLine; } else if (gift.IsPokémon) { PKM pk = gift.convertToPKM(Main.SAV); try { s += $"{GameInfo.Strings.specieslist[pk.Species]} @ {GameInfo.Strings.itemlist[pk.HeldItem]} --- "; s += (pk.IsEgg ? GameInfo.Strings.eggname : $"{pk.OT_Name} - {pk.TID:00000}/{pk.SID:00000}") + Environment.NewLine; s += $"{GameInfo.Strings.movelist[pk.Move1]} / {GameInfo.Strings.movelist[pk.Move2]} / {GameInfo.Strings.movelist[pk.Move3]} / {GameInfo.Strings.movelist[pk.Move4]}" + Environment.NewLine; if (gift is WC7) { var addItem = ((WC7) gift).AdditionalItem; if (addItem != 0) s += $"+ {GameInfo.Strings.itemlist[addItem]}"; } } catch { s += "Unable to create gift description." + Environment.NewLine; } } else { s += "Unknown Wonder Card Type!" + Environment.NewLine; } if (gift is WC7) { var wc7 = (WC7) gift; s += $"Repeatable: {wc7.GiftRepeatable}" + Environment.NewLine; s += $"Collected: {wc7.GiftUsed}" + Environment.NewLine; s += $"Once Per Day: {wc7.GiftOncePerDay}" + Environment.NewLine; } return s; }
private void pbBoxSlot_DragDrop(object sender, DragEventArgs e) { int index = Array.IndexOf(pba, sender); // Hijack to the latest unfilled slot if index creates interstitial empty slots. int lastUnfilled = getLastUnfilledByType(mg, mga); if (lastUnfilled > -1 && lastUnfilled < index) index = lastUnfilled; if (wc_slot == -1) // dropped { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); if (files.Length < 1) return; if (PCD.Size < (int)new FileInfo(files[0]).Length) { WinFormsUtil.Alert("Data size invalid.", files[0]); return; } byte[] data = File.ReadAllBytes(files[0]); MysteryGift mg = MysteryGift.getMysteryGift(data, new FileInfo(files[0]).Extension); if (mg is PCD && mga.Gifts[index] is PGT) mg = (mg as PCD).Gift; else if (mg.Type != mga.Gifts[index].Type) { WinFormsUtil.Alert("Can't set slot here.", $"{mg.Type} != {mga.Gifts[index].Type}"); return; } setBackground(index, Core.Properties.Resources.slotSet); mga.Gifts[index] = mg.Clone(); setCardID(mga.Gifts[index].CardID); viewGiftData(mga.Gifts[index]); } else // Swap Data { MysteryGift s1 = mga.Gifts[index]; MysteryGift s2 = mga.Gifts[wc_slot]; if (s1.Type != s2.Type) { WinFormsUtil.Alert($"Can't swap {s1.Type} with {s2.Type}."); return; } mga.Gifts[wc_slot] = s1; mga.Gifts[index] = s2; if (mga.Gifts[wc_slot].Empty) // empty slot created, slide down { int i = wc_slot; while (i < index) { if (mga.Gifts[i + 1].Empty) break; if (mga.Gifts[i + 1].Type != mga.Gifts[i].Type) break; i++; var mg1 = mga.Gifts[i]; var mg2 = mga.Gifts[i - 1]; mga.Gifts[i - 1] = mg1; mga.Gifts[i] = mg2; } index = i-1; } } setBackground(index, Core.Properties.Resources.slotView); setGiftBoxes(); }
/// <summary> /// Gets a description of the <see cref="MysteryGift"/> using the current default string data. /// </summary> /// <param name="gift">Gift data to parse</param> /// <returns>List of lines</returns> public static IEnumerable <string> GetDescription(this MysteryGift gift) => gift.GetDescription(GameInfo.Strings);
private bool checkSpecialWonderCard(MysteryGift g) { if (SAV.Generation != 6) return true; if (g is WC6) { if (g.CardID == 2048 && g.Item == 726) // Eon Ticket (OR/AS) { if (!Main.SAV.ORAS || ((SAV6)SAV).EonTicket < 0) goto reject; BitConverter.GetBytes(WC6.EonTicketConst).CopyTo(SAV.Data, ((SAV6)SAV).EonTicket); } } return true; reject: WinFormsUtil.Alert("Unable to insert the Mystery Gift.", "Does this Mystery Gift really belong to this game?"); return false; }