From 827eb94f3c272e58d53dcb76a1d804dcf85258ab Mon Sep 17 00:00:00 2001 From: Kurt Date: Thu, 16 May 2019 22:26:51 -0700 Subject: [PATCH] Add GameSync r/w for lgpe https://projectpokemon.org/home/forums/topic/52797-request-lgpe-game-sync-like-value-to-be-added/ ty @PP-theSLAYER ! --- PKHeX.Core/Saves/SAV7b.cs | 45 ++++++++++--------- .../Saves/Substructures/Gen7/MyStatus7b.cs | 25 +++++++++++ 2 files changed, 49 insertions(+), 21 deletions(-) diff --git a/PKHeX.Core/Saves/SAV7b.cs b/PKHeX.Core/Saves/SAV7b.cs index 66bf82775..97f42d7c6 100644 --- a/PKHeX.Core/Saves/SAV7b.cs +++ b/PKHeX.Core/Saves/SAV7b.cs @@ -109,27 +109,27 @@ public SAV7b(byte[] data) private static readonly BlockInfo[] BlockInfoGG = { - new BlockInfo3DS {Length = 3472, Offset = 0}, - new BlockInfo3DS {Length = 512, Offset = 3584}, - new BlockInfo3DS {Length = 360, Offset = 4096}, - new BlockInfo3DS {Length = 6144, Offset = 4608}, - new BlockInfo3DS {Length = 8424, Offset = 10752}, - new BlockInfo3DS {Length = 2352, Offset = 19456}, - new BlockInfo3DS {Length = 4, Offset = 22016}, - new BlockInfo3DS {Length = 304, Offset = 22528}, - new BlockInfo3DS {Length = 18, Offset = 23040}, - new BlockInfo3DS {Length = 260000, Offset = 23552}, - new BlockInfo3DS {Length = 8, Offset = 283648}, - new BlockInfo3DS {Length = 3728, Offset = 284160}, - new BlockInfo3DS {Length = 4260, Offset = 288256}, - new BlockInfo3DS {Length = 240, Offset = 292864}, - new BlockInfo3DS {Length = 24592, Offset = 293376}, - new BlockInfo3DS {Length = 512, Offset = 318464}, - new BlockInfo3DS {Length = 152, Offset = 318976}, - new BlockInfo3DS {Length = 104, Offset = 319488}, - new BlockInfo3DS {Length = 432000, Offset = 320000}, - new BlockInfo3DS {Length = 176, Offset = 752128}, - new BlockInfo3DS {Length = 2368, Offset = 752640}, + new BlockInfo3DS {Offset = 0x00000, Length = 0x00D90}, + new BlockInfo3DS {Offset = 0x00E00, Length = 0x00200}, + new BlockInfo3DS {Offset = 0x01000, Length = 0x00168}, + new BlockInfo3DS {Offset = 0x01200, Length = 0x01800}, + new BlockInfo3DS {Offset = 0x02A00, Length = 0x020E8}, + new BlockInfo3DS {Offset = 0x04C00, Length = 0x00930}, + new BlockInfo3DS {Offset = 0x05600, Length = 0x00004}, + new BlockInfo3DS {Offset = 0x05800, Length = 0x00130}, + new BlockInfo3DS {Offset = 0x05A00, Length = 0x00012}, + new BlockInfo3DS {Offset = 0x05C00, Length = 0x3F7A0}, + new BlockInfo3DS {Offset = 0x45400, Length = 0x00008}, + new BlockInfo3DS {Offset = 0x45600, Length = 0x00E90}, + new BlockInfo3DS {Offset = 0x46600, Length = 0x010A4}, + new BlockInfo3DS {Offset = 0x47800, Length = 0x000F0}, + new BlockInfo3DS {Offset = 0x47A00, Length = 0x06010}, + new BlockInfo3DS {Offset = 0x4DC00, Length = 0x00200}, + new BlockInfo3DS {Offset = 0x4DE00, Length = 0x00098}, + new BlockInfo3DS {Offset = 0x4E000, Length = 0x00068}, + new BlockInfo3DS {Offset = 0x4E200, Length = 0x69780}, + new BlockInfo3DS {Offset = 0xB7A00, Length = 0x000B0}, + new BlockInfo3DS {Offset = 0xB7C00, Length = 0x00940}, }; private bool CanReadChecksums() @@ -257,5 +257,8 @@ public override GameVersion Version protected override bool[] MysteryGiftReceivedFlags { get => GiftRecords.Flags; set => GiftRecords.Flags = value; } protected override MysteryGift[] MysteryGiftCards { get => GiftRecords.Records; set => GiftRecords.Records = (WR7[])value; } + + public override int GameSyncIDSize => MyStatus7b.GameSyncIDSize; // 64 bits + public override string GameSyncID { get => Status.GameSyncID; set => Status.GameSyncID = value; } } } diff --git a/PKHeX.Core/Saves/Substructures/Gen7/MyStatus7b.cs b/PKHeX.Core/Saves/Substructures/Gen7/MyStatus7b.cs index f1a44a662..88b33ac26 100644 --- a/PKHeX.Core/Saves/Substructures/Gen7/MyStatus7b.cs +++ b/PKHeX.Core/Saves/Substructures/Gen7/MyStatus7b.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; namespace PKHeX.Core { @@ -40,6 +41,30 @@ public int Gender set => Data[Offset + 5] = OverworldGender = (byte)value; } + public const int GameSyncIDSize = 16; // 8 bytes + + public string GameSyncID + { + get + { + var data = Data.Skip(Offset + 0x10).Take(GameSyncIDSize / 2).Reverse().ToArray(); + return BitConverter.ToString(data).Replace("-", string.Empty); + } + set + { + if (value == null) + return; + if (value.Length > 16) + return; + + Enumerable.Range(0, value.Length) + .Where(x => x % 2 == 0) + .Reverse() + .Select(x => Convert.ToByte(value.Substring(x, 2), 16)) + .ToArray().CopyTo(Data, Offset + 0x10); + } + } + public int Language { get => Data[Offset + 0x35];