From 0d69e803e154f80f9bc5cec6a6e78bc39db2d427 Mon Sep 17 00:00:00 2001 From: Kurt Date: Wed, 21 Mar 2018 21:10:23 -0700 Subject: [PATCH] Add gen4/5 synthetic trade logic was previously present for gen6 and gen7 only, resulting in eggs in gen4/5 not getting link trade values applied. that's really all. https://projectpokemon.org/home/forums/topic/44437-bug-eggs-transfer-for-gen-4-dppt-and-hgss/ --- PKHeX.Core/PKM/BK4.cs | 12 ++++++++++++ PKHeX.Core/PKM/PK4.cs | 12 ++++++++++++ PKHeX.Core/PKM/PK5.cs | 11 +++++++++++ PKHeX.Core/PKM/PK6.cs | 9 +-------- PKHeX.Core/PKM/PK7.cs | 9 +-------- PKHeX.Core/PKM/PKM.cs | 15 +++++++++++++++ PKHeX.Core/Saves/SAV4.cs | 9 +++++++++ PKHeX.Core/Saves/SAV4BR.cs | 8 ++++++++ PKHeX.Core/Saves/SAV5.cs | 8 ++++++++ PKHeX.Core/Saves/Storage/BulkStorage.cs | 1 - 10 files changed, 77 insertions(+), 17 deletions(-) diff --git a/PKHeX.Core/PKM/BK4.cs b/PKHeX.Core/PKM/BK4.cs index 1d9c58a1b..36b09d977 100644 --- a/PKHeX.Core/PKM/BK4.cs +++ b/PKHeX.Core/PKM/BK4.cs @@ -340,6 +340,18 @@ protected override ushort CalculateChecksum() return chk; } + // Synthetic Trading Logic + public bool Trade(string SAV_Trainer, int SAV_TID, int SAV_SID, int SAV_GENDER, int Day = 1, int Month = 1, int Year = 2009) + { + // Eggs do not have any modifications done if they are traded + if (IsEgg && !(SAV_Trainer == OT_Name && SAV_TID == TID && SAV_SID == SID && SAV_GENDER == OT_Gender)) + { + SetLinkTradeEgg(Day, Month, Year); + return true; + } + return false; + } + protected override byte[] Encrypt() { RefreshChecksum(); diff --git a/PKHeX.Core/PKM/PK4.cs b/PKHeX.Core/PKM/PK4.cs index 09a0ef948..4c0d17819 100644 --- a/PKHeX.Core/PKM/PK4.cs +++ b/PKHeX.Core/PKM/PK4.cs @@ -323,6 +323,18 @@ protected override byte[] Encrypt() return PKX.EncryptArray45(Data); } + // Synthetic Trading Logic + public bool Trade(string SAV_Trainer, int SAV_TID, int SAV_SID, int SAV_GENDER, int Day = 1, int Month = 1, int Year = 2009) + { + // Eggs do not have any modifications done if they are traded + if (IsEgg && !(SAV_Trainer == OT_Name && SAV_TID == TID && SAV_SID == SID && SAV_GENDER == OT_Gender)) + { + SetLinkTradeEgg(Day, Month, Year, 2002); + return true; + } + return false; + } + public BK4 ConvertToBK4() { BK4 bk4 = ConvertTo(); diff --git a/PKHeX.Core/PKM/PK5.cs b/PKHeX.Core/PKM/PK5.cs index f3652554f..c7e8d428c 100644 --- a/PKHeX.Core/PKM/PK5.cs +++ b/PKHeX.Core/PKM/PK5.cs @@ -287,6 +287,17 @@ protected override byte[] Encrypt() return PKX.EncryptArray45(Data); } + // Synthetic Trading Logic + public bool Trade(string SAV_Trainer, int SAV_TID, int SAV_SID, int SAV_GENDER, int Day = 1, int Month = 1, int Year = 2013) + { + if (IsEgg && !(SAV_Trainer == OT_Name && SAV_TID == TID && SAV_SID == SID && SAV_GENDER == OT_Gender)) + { + SetLinkTradeEgg(Day, Month, Year, 30003); + return true; + } + return false; + } + public PK6 ConvertToPK6() { PK6 pk6 = new PK6 // Convert away! diff --git a/PKHeX.Core/PKM/PK6.cs b/PKHeX.Core/PKM/PK6.cs index 87d05a716..5f03e536b 100644 --- a/PKHeX.Core/PKM/PK6.cs +++ b/PKHeX.Core/PKM/PK6.cs @@ -496,7 +496,7 @@ public void Trade(string SAV_Trainer, int SAV_TID, int SAV_SID, int SAV_COUNTRY, { // Eggs do not have any modifications done if they are traded if (IsEgg && !(SAV_Trainer == OT_Name && SAV_TID == TID && SAV_SID == SID && SAV_GENDER == OT_Gender)) - UpdateEgg(Day, Month, Year); + SetLinkTradeEgg(Day, Month, Year); // Process to the HT if the OT of the Pokémon does not match the SAV's OT info. else if (!TradeOT(SAV_Trainer, SAV_TID, SAV_SID, SAV_COUNTRY, SAV_REGION, SAV_GENDER)) TradeHT(SAV_Trainer, SAV_COUNTRY, SAV_REGION, SAV_GENDER, Bank); @@ -532,13 +532,6 @@ private void TradeHT(string SAV_Trainer, int SAV_COUNTRY, int SAV_REGION, int SA TradeMemory(Bank); } // Misc Updates - private void UpdateEgg(int Day, int Month, int Year) - { - Met_Location = 30002; - Met_Day = Day; - Met_Month = Month; - Met_Year = Year - 2000; - } private void TradeGeoLocation(int GeoCountry, int GeoRegion) { // Allow the method to abort if the values are invalid diff --git a/PKHeX.Core/PKM/PK7.cs b/PKHeX.Core/PKM/PK7.cs index f696fd3fc..4a77b9d7d 100644 --- a/PKHeX.Core/PKM/PK7.cs +++ b/PKHeX.Core/PKM/PK7.cs @@ -544,7 +544,7 @@ public void Trade(string SAV_Trainer, int SAV_TID, int SAV_SID, int SAV_COUNTRY, { // Eggs do not have any modifications done if they are traded if (IsEgg && !(SAV_Trainer == OT_Name && SAV_TID == TID && SAV_SID == SID && SAV_GENDER == OT_Gender)) - UpdateEgg(Day, Month, Year); + SetLinkTradeEgg(Day, Month, Year); // Process to the HT if the OT of the Pokémon does not match the SAV's OT info. else if (!TradeOT(SAV_Trainer, SAV_TID, SAV_SID, SAV_COUNTRY, SAV_REGION, SAV_GENDER)) TradeHT(SAV_Trainer, SAV_COUNTRY, SAV_REGION, SAV_GENDER, Bank); @@ -580,13 +580,6 @@ private void TradeHT(string SAV_Trainer, int SAV_COUNTRY, int SAV_REGION, int SA TradeMemory(Bank); } // Misc Updates - private void UpdateEgg(int Day, int Month, int Year) - { - Met_Location = 30002; - Met_Day = Day; - Met_Month = Month; - Met_Year = Year - 2000; - } private void TradeGeoLocation(int GeoCountry, int GeoRegion) { // No geolocations are set, ever! -- except for bank. Don't set them anyway. diff --git a/PKHeX.Core/PKM/PKM.cs b/PKHeX.Core/PKM/PKM.cs index 513a4d99d..4801128b3 100644 --- a/PKHeX.Core/PKM/PKM.cs +++ b/PKHeX.Core/PKM/PKM.cs @@ -766,6 +766,21 @@ public virtual bool CanHoldItem(ushort[] ValidArray) /// Cloned object public abstract PKM Clone(); + /// + /// Sets Link Trade data for an . + /// + /// Day the was traded. + /// Month the was traded. + /// Day the was traded. + /// Link Trade location value. + protected void SetLinkTradeEgg(int day, int month, int y, int location = 30002) + { + Met_Day = day; + Met_Month = month; + Met_Year = y - 2000; + Met_Location = location; + } + /// /// Gets the PP of a Move ID with consideration of the amount of PP Ups applied. /// diff --git a/PKHeX.Core/Saves/SAV4.cs b/PKHeX.Core/Saves/SAV4.cs index 27ef181da..6f7f9b0dd 100644 --- a/PKHeX.Core/Saves/SAV4.cs +++ b/PKHeX.Core/Saves/SAV4.cs @@ -584,6 +584,15 @@ public override byte[] DecryptPKM(byte[] data) return PKX.DecryptArray45(data); } + protected override void SetPKM(PKM pkm) + { + var pk4 = (PK4)pkm; + // Apply to this Save File + DateTime Date = DateTime.Now; + if (pk4.Trade(OT, TID, SID, Gender, Date.Day, Date.Month, Date.Year)) + pkm.RefreshChecksum(); + } + // Daycare public override int GetDaycareSlotOffset(int loc, int slot) { diff --git a/PKHeX.Core/Saves/SAV4BR.cs b/PKHeX.Core/Saves/SAV4BR.cs index 258ca8844..42b5cd4ed 100644 --- a/PKHeX.Core/Saves/SAV4BR.cs +++ b/PKHeX.Core/Saves/SAV4BR.cs @@ -148,6 +148,14 @@ public override byte[] DecryptPKM(byte[] data) } protected override void SetDex(PKM pkm) { } + protected override void SetPKM(PKM pkm) + { + var pk4 = (BK4)pkm; + // Apply to this Save File + DateTime Date = DateTime.Now; + if (pk4.Trade(OT, TID, SID, Gender, Date.Day, Date.Month, Date.Year)) + pkm.RefreshChecksum(); + } public static byte[] DecryptPBRSaveData(byte[] input) { diff --git a/PKHeX.Core/Saves/SAV5.cs b/PKHeX.Core/Saves/SAV5.cs index a8c90d5f1..ed62df32a 100644 --- a/PKHeX.Core/Saves/SAV5.cs +++ b/PKHeX.Core/Saves/SAV5.cs @@ -249,6 +249,14 @@ public override byte[] DecryptPKM(byte[] data) { return PKX.DecryptArray45(data); } + protected override void SetPKM(PKM pkm) + { + var pk5 = (PK5)pkm; + // Apply to this Save File + DateTime Date = DateTime.Now; + if (pk5.Trade(OT, TID, SID, Gender, Date.Day, Date.Month, Date.Year)) + pkm.RefreshChecksum(); + } // Mystery Gift public override MysteryGiftAlbum GiftAlbum diff --git a/PKHeX.Core/Saves/Storage/BulkStorage.cs b/PKHeX.Core/Saves/Storage/BulkStorage.cs index 265cc61ec..c0bd94331 100644 --- a/PKHeX.Core/Saves/Storage/BulkStorage.cs +++ b/PKHeX.Core/Saves/Storage/BulkStorage.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; namespace PKHeX.Core {