From f8bf3e400b036c7371b0ebbbba572caa405ad4fb Mon Sep 17 00:00:00 2001 From: Kurt Date: Thu, 15 Feb 2018 17:05:45 -0800 Subject: [PATCH] Misc tweaks Add bulkstorage SaveFile template remove unused using un-virtual box property (don't override behavior) Split new-USUM island names (unused) Remove island names from valid egg locations (thanks Davil !) https://projectpokemon.org/home/forums/topic/43874-bug-met-location/?tab=comments#comment-227684 --- PKHeX.Core/Game/GameInfo.cs | 1 + PKHeX.Core/Legality/Tables7.cs | 6 +- PKHeX.Core/Saves/SAV4BR.cs | 11 ++-- PKHeX.Core/Saves/SaveFile.cs | 2 +- PKHeX.Core/Saves/Storage/BulkStorage.cs | 64 +++++++++++++++++++ .../Saves/Substructures/CGearBackground.cs | 1 - 6 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 PKHeX.Core/Saves/Storage/BulkStorage.cs diff --git a/PKHeX.Core/Game/GameInfo.cs b/PKHeX.Core/Game/GameInfo.cs index ad17038f9..d8229ea5c 100644 --- a/PKHeX.Core/Game/GameInfo.cs +++ b/PKHeX.Core/Game/GameInfo.cs @@ -237,6 +237,7 @@ private void SanitizeMetLocations() if (i > 0 && !string.IsNullOrWhiteSpace(metSM_00000_good[i]) && metSM_00000_good.Take(i - 1).Contains(metSM_00000_good[i])) metSM_00000_good[i] += $" ({metSM_00000_good.Take(i - 1).Count(s => s == metSM_00000_good[i]) + 1})"; } + Array.Copy(metSM_00000, 194, metSM_00000_good, 194, 4); // Restore Island Names (unused) metSM_00000_good.CopyTo(metSM_00000, 0); metSM_30000[0] += $" ({NPC})"; // Anything from an NPC diff --git a/PKHeX.Core/Legality/Tables7.cs b/PKHeX.Core/Legality/Tables7.cs index 7025a5f4c..eccacb974 100644 --- a/PKHeX.Core/Legality/Tables7.cs +++ b/PKHeX.Core/Legality/Tables7.cs @@ -29,7 +29,8 @@ public static partial class Legal 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, - 194, 196, 198, + 194, 195, 196, 197, // Invalid + 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224, 226, 228, 230, 232, }; @@ -480,7 +481,8 @@ public static partial class Legal }; internal static readonly HashSet ValidMet_USUM = new HashSet(ValidMet_SM) { - 194, 196, 198, + // 194, 195, 196, 197, // Unobtainable new Locations + 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224, 226, 228, 230, 232, }; diff --git a/PKHeX.Core/Saves/SAV4BR.cs b/PKHeX.Core/Saves/SAV4BR.cs index 93eb80e93..f13dbfe34 100644 --- a/PKHeX.Core/Saves/SAV4BR.cs +++ b/PKHeX.Core/Saves/SAV4BR.cs @@ -69,10 +69,13 @@ protected override byte[] Write(bool DSV) public readonly List SaveSlots; public readonly string[] SaveNames; - public int CurrentSlot; - protected override int Box { // 4 save slots, data reading depends on current slot - get => 0x978 + 0x6FF00 * CurrentSlot; - set { } + + private int _currentSlot; + public int CurrentSlot + { + get => _currentSlot; + // 4 save slots, data reading depends on current slot + set => Box = 0x978 + 0x6FF00 * (_currentSlot = value); } public override int SIZE_STORED => PKX.SIZE_4STORED; diff --git a/PKHeX.Core/Saves/SaveFile.cs b/PKHeX.Core/Saves/SaveFile.cs index 36f7f7bc3..f30b10722 100644 --- a/PKHeX.Core/Saves/SaveFile.cs +++ b/PKHeX.Core/Saves/SaveFile.cs @@ -130,7 +130,7 @@ protected virtual byte[] Write(bool DSV) public virtual int MaxShadowID => 0; // Offsets - protected virtual int Box { get; set; } = int.MinValue; + protected int Box { get; set; } = int.MinValue; protected int Party { get; set; } = int.MinValue; protected int Trainer1 { get; set; } = int.MinValue; protected int Daycare { get; set; } = int.MinValue; diff --git a/PKHeX.Core/Saves/Storage/BulkStorage.cs b/PKHeX.Core/Saves/Storage/BulkStorage.cs new file mode 100644 index 000000000..7af0c8f69 --- /dev/null +++ b/PKHeX.Core/Saves/Storage/BulkStorage.cs @@ -0,0 +1,64 @@ +using System; + +namespace PKHeX.Core +{ + /// + /// Simple Storage Binary wrapper for a concatenated list of data. + /// + public class BulkStorage : SaveFile + { + public BulkStorage(byte[] data, Type t, int start, int slotsPerBox = 30) + { + Box = start; + Data = data; + SlotsPerBox = slotsPerBox; + + blank = PKMConverter.GetBlank(t); + var slots = (Data.Length - Box) / blank.SIZE_STORED; + BoxCount = slots / SlotsPerBox; + } + + private readonly int SlotsPerBox; + + public override string BAKName => $"{FileName} [{SaveUtil.CRC16(Data, Box, Data.Length - Box)}].bak"; + public override SaveFile Clone() => new BulkStorage((byte[])Data.Clone(), PKMType, Box, SlotsPerBox); + public override string Filter { get; } = "All Files|*.*"; + public override string Extension { get; } = ".bin"; + public override bool ChecksumsValid { get; } = true; + public override string ChecksumInfo { get; } = "No Info."; + + private readonly PKM blank; + public override Type PKMType => blank.GetType(); + public override PKM BlankPKM => blank.Clone(); + + public override PKM GetPKM(byte[] data) => PKMConverter.GetPKMfromBytes(data, prefer: Generation); + public override byte[] DecryptPKM(byte[] data) => GetPKM(data).Data; + + public override int SIZE_STORED => blank.SIZE_STORED; + protected override int SIZE_PARTY => blank.SIZE_PARTY; + public override int MaxEV => blank.MaxEV; + public override int Generation => blank.Format; + public override int MaxMoveID => blank.MaxMoveID; + public override int MaxSpeciesID => blank.MaxSpeciesID; + public override int MaxAbilityID => blank.MaxAbilityID; + public override int MaxItemID => blank.MaxItemID; + public override int MaxBallID => blank.MaxBallID; + public override int MaxGameID => blank.MaxGameID; + public override int OTLength => blank.OTLength; + public override int NickLength => blank.NickLength; + public bool BigEndian => blank is BK4 || blank is XK3 || blank is CK3; + + public override int BoxCount { get; } + protected override void SetChecksums() { } + + public override int GetBoxOffset(int box) => Box + SlotsPerBox * SIZE_STORED; + public override string GetBoxName(int box) => $"Box {box + 1:d2}"; + public override void SetBoxName(int box, string val) { } + public override int GetPartyOffset(int slot) => int.MinValue; + + public override string GetString(int Offset, int Length) + => StringConverter.GetString(Data, Generation, blank.Japanese, BigEndian, Length, Offset); + public override byte[] SetString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0) + => StringConverter.SetString(value, Generation, blank.Japanese, BigEndian, maxLength, padTo: PadToSize, padWith: PadWith); + } +} diff --git a/PKHeX.Core/Saves/Substructures/CGearBackground.cs b/PKHeX.Core/Saves/Substructures/CGearBackground.cs index 66dc2fc43..b38166f19 100644 --- a/PKHeX.Core/Saves/Substructures/CGearBackground.cs +++ b/PKHeX.Core/Saves/Substructures/CGearBackground.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; namespace PKHeX.Core