From 0b5429ebbc0f188e71e9f8d5df95ea9910552fc5 Mon Sep 17 00:00:00 2001 From: Kurt Date: Fri, 25 Jan 2019 19:58:00 -0800 Subject: [PATCH] Relocate wormhole edit logic to separate class #2250 make arrays static (only spin up one copy ever) --- PKHeX.Core/Saves/SAV7.cs | 106 +---------------- .../Substructures/Gen7/WormholeInfoReader.cs | 109 ++++++++++++++++++ 2 files changed, 114 insertions(+), 101 deletions(-) create mode 100644 PKHeX.Core/Saves/Substructures/Gen7/WormholeInfoReader.cs diff --git a/PKHeX.Core/Saves/SAV7.cs b/PKHeX.Core/Saves/SAV7.cs index a78c8a25f..53b9b0914 100644 --- a/PKHeX.Core/Saves/SAV7.cs +++ b/PKHeX.Core/Saves/SAV7.cs @@ -218,12 +218,12 @@ private void GetSAVOffsets() private int Bag { get; set; } = int.MinValue; private int AdventureInfo { get; set; } = int.MinValue; private int Trainer2 { get; set; } = int.MinValue; - private int Misc { get; set; } = int.MinValue; + public int Misc { get; private set; } = int.MinValue; private int LastViewedBox { get; set; } = int.MinValue; private int WondercardFlags { get; set; } = int.MinValue; private int PlayTime { get; set; } = int.MinValue; private int Overworld { get; set; } = int.MinValue; - public int JoinFestaData { get; set; } = int.MinValue; + public int JoinFestaData { get; private set; } = int.MinValue; private int PokeFinderSave { get; set; } = int.MinValue; private int BattleTree { get; set; } = int.MinValue; private int BattleBoxFlags { get; set; } = int.MinValue; @@ -1226,8 +1226,11 @@ public override bool GetSeen(int species) + 0x80; // Misc Data (1024 bits) for (int i = 1; i <= 4; i++) // check all 4 seen flags (gender/shiny) + { if ((Data[ofs + bd + (i * brSize)] & mask) != 0) return true; + } + return false; } @@ -1533,104 +1536,5 @@ public override byte[] SetString(string value, int maxLength, int PadToSize = 0, PadToSize = maxLength + 1; return StringConverter.SetString7(value, maxLength, Language, PadToSize, PadWith); } - - // Wormhole shininess & flags found by @PP-theSLAYER - // https://projectpokemon.org/home/forums/topic/39433-gen-7-save-research-thread/?page=3&tab=comments#comment-239090 - public bool WormholeShininess // 0x4535 = Misc (0x4400 in USUM) + 0x0135 - { - get => Data[Misc + 0x0135] == 1; - set => Data[Misc + 0x0135] = (byte)(value ? 1 : 0); - } - - // TODO: Find out if legendaries are in slots too - public const int WormholeSlotMax = 4; - public int WormholeSlot - { - get - { - //if (!InWormhole()) - // return -1; - for (int i = 0; i <= WormholeSlotMax; i++) - { - if (GetEventFlag(i + 11) == false) - return i; - } - return -1; - } - set - { - if (value < 0 || value > WormholeSlotMax) - return; - for (int i = 0; i <= WormholeSlotMax; i++) - { - SetEventFlag(i + 11, value != i); - } - - // TODO: Is there a better way to set individual consts while using the API? - var consts = EventConsts; - consts[851] = (ushort)(value + 38); - EventConsts = consts; - } - } - - public readonly int[] StandardWormholes = new[] { - 256, // Red - 257, // Green - 258, // Yellow - 259, // Blue - }; - - public readonly int[] WormholeSlotsRed = new[] - { - 334, // Altaria - 469, // Yanmega - 561, // Sigilyph - 581, // Swanna - 277, // Swellow - }; - - public readonly int[] WormholeSlotsGreen = new[] - { - 542, // Drapion - 531, // Audino - 695, // Heliolisk - 274, // Nuzleaf - 326, // Grumpig - }; - - public readonly int[] WormholeSlotsYellow = new[] - { - 460, // Abomasnow - 308, // Medicham - 450, // Hippowdon - 558, // Crustle - 219, // Magcargo - }; - - public readonly int[] WormholeSlotsBlue = new[] - { - 689, // Barbaracle - 271, // Lombre - 618, // Stunfisk - 419, // Floatzel - 195, // Quagsire - }; - - public int WormholeSlotToPokemon(int mapid, int slot) - { - if (slot < 0 || slot > WormholeSlotMax) - return -1; - //if (!StandardWormholes.Contains(mapid)) - // return -1; - - switch (mapid) - { - case 256: return WormholeSlotsRed[slot]; - case 257: return WormholeSlotsGreen[slot]; - case 258: return WormholeSlotsYellow[slot]; - case 259: return WormholeSlotsBlue[slot]; - default: return -1; - } - } } } diff --git a/PKHeX.Core/Saves/Substructures/Gen7/WormholeInfoReader.cs b/PKHeX.Core/Saves/Substructures/Gen7/WormholeInfoReader.cs new file mode 100644 index 000000000..c32b8f99f --- /dev/null +++ b/PKHeX.Core/Saves/Substructures/Gen7/WormholeInfoReader.cs @@ -0,0 +1,109 @@ +namespace PKHeX.Core +{ + public class WormholeInfoReader + { + public readonly SAV7 SAV; + public WormholeInfoReader(SAV7 sav) => SAV = sav; + + // Wormhole shininess & flags found by @PP-theSLAYER + // https://projectpokemon.org/home/forums/topic/39433-gen-7-save-research-thread/?page=3&tab=comments#comment-239090 + public bool WormholeShininess // 0x4535 = Misc (0x4400 in USUM) + 0x0135 + { + get => SAV.Data[SAV.Misc + 0x0135] == 1; + set => SAV.Data[SAV.Misc + 0x0135] = (byte)(value ? 1 : 0); + } + + // TODO: Find out if legendaries are in slots too + public const int WormholeSlotMax = 4; + + public int WormholeSlot + { + get + { + //if (!InWormhole()) + // return -1; + for (int i = 0; i <= WormholeSlotMax; i++) + { + if (!SAV.GetEventFlag(i + 11)) + return i; + } + return -1; + } + set + { + if (value < 0 || value > WormholeSlotMax) + return; + for (int i = 0; i <= WormholeSlotMax; i++) + { + SAV.SetEventFlag(i + 11, value != i); + } + + // TODO: Is there a better way to set individual consts while using the API? + var consts = SAV.EventConsts; + consts[851] = (ushort)(value + 38); + SAV.EventConsts = consts; + } + } + + public static readonly int[] StandardWormholes = + { + 256, // Red + 257, // Green + 258, // Yellow + 259, // Blue + }; + + public static readonly int[] WormholeSlotsRed = + { + 334, // Altaria + 469, // Yanmega + 561, // Sigilyph + 581, // Swanna + 277, // Swellow + }; + + public static readonly int[] WormholeSlotsGreen = + { + 542, // Drapion + 531, // Audino + 695, // Heliolisk + 274, // Nuzleaf + 326, // Grumpig + }; + + public static readonly int[] WormholeSlotsYellow = + { + 460, // Abomasnow + 308, // Medicham + 450, // Hippowdon + 558, // Crustle + 219, // Magcargo + }; + + public static readonly int[] WormholeSlotsBlue = + { + 689, // Barbaracle + 271, // Lombre + 618, // Stunfisk + 419, // Floatzel + 195, // Quagsire + }; + + public int WormholeSlotToPokemon(int mapid, int slot) + { + if (slot < 0 || slot > WormholeSlotMax) + return -1; + //if (!StandardWormholes.Contains(mapid)) + // return -1; + + switch (mapid) + { + case 256: return WormholeSlotsRed[slot]; + case 257: return WormholeSlotsGreen[slot]; + case 258: return WormholeSlotsYellow[slot]; + case 259: return WormholeSlotsBlue[slot]; + default: return -1; + } + } + } +} \ No newline at end of file