From ade97e006720244b36766c02bc0253767961ab38 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Sat, 29 Oct 2016 11:32:21 -0700 Subject: [PATCH] Generalize box wallpaper interaction Move get/set logic into abstract class, only offset fetch is overridden --- PKHeX/Saves/SAV1.cs | 4 ---- PKHeX/Saves/SAV2.cs | 4 ---- PKHeX/Saves/SAV3.cs | 5 ++--- PKHeX/Saves/SAV3Colosseum.cs | 5 ----- PKHeX/Saves/SAV3RSBox.cs | 4 ++-- PKHeX/Saves/SAV3XD.cs | 5 ----- PKHeX/Saves/SAV4.cs | 4 ++-- PKHeX/Saves/SAV4BR.cs | 2 -- PKHeX/Saves/SAV5.cs | 4 ++-- PKHeX/Saves/SAV6.cs | 21 +++++++++++++++++---- PKHeX/Saves/SAV7.cs | 25 ++++++++++++++++++++++--- PKHeX/Saves/SaveFile.cs | 23 ++++++++++++++++++++--- 12 files changed, 67 insertions(+), 39 deletions(-) diff --git a/PKHeX/Saves/SAV1.cs b/PKHeX/Saves/SAV1.cs index 55817a118..520e03477 100644 --- a/PKHeX/Saves/SAV1.cs +++ b/PKHeX/Saves/SAV1.cs @@ -403,10 +403,6 @@ namespace PKHeX get { return Data[Japanese ? 0x2842 : 0x284C] & 0x7F; } set { Data[Japanese ? 0x2842 : 0x284C] = (byte)((Data[Japanese ? 0x2842 : 0x284C] & 0x80) | (value & 0x7F)); } } - public override int getBoxWallpaper(int box) - { - return 0; - } public override string getBoxName(int box) { return $"BOX {box + 1}"; diff --git a/PKHeX/Saves/SAV2.cs b/PKHeX/Saves/SAV2.cs index 8e59f6c37..37166aa54 100644 --- a/PKHeX/Saves/SAV2.cs +++ b/PKHeX/Saves/SAV2.cs @@ -554,10 +554,6 @@ namespace PKHeX get { return Data[CurrentBoxIndexOffset] & 0x7F; } set { Data[CurrentBoxIndexOffset] = (byte)((Data[Japanese ? 0x2842 : 0x284C] & 0x80) | (value & 0x7F)); } } - public override int getBoxWallpaper(int box) - { - return 0; - } public override string getBoxName(int box) { return PKX.getG1Str(Data.Skip(BoxNamesOffset + box*9).Take(9).ToArray(), Japanese); diff --git a/PKHeX/Saves/SAV3.cs b/PKHeX/Saves/SAV3.cs index c7ab79834..938365562 100644 --- a/PKHeX/Saves/SAV3.cs +++ b/PKHeX/Saves/SAV3.cs @@ -434,12 +434,11 @@ namespace PKHeX get { return Data[Box]; } set { Data[Box] = (byte)value; } } - public override int getBoxWallpaper(int box) + protected override int getBoxWallpaperOffset(int box) { - // Box Wallpaper is directly after the Box Names int offset = getBoxOffset(BoxCount); offset += BoxCount * 0x9 + box; - return Data[offset]; + return offset; } public override string getBoxName(int box) { diff --git a/PKHeX/Saves/SAV3Colosseum.cs b/PKHeX/Saves/SAV3Colosseum.cs index 267df8f9e..1b257cb9c 100644 --- a/PKHeX/Saves/SAV3Colosseum.cs +++ b/PKHeX/Saves/SAV3Colosseum.cs @@ -255,11 +255,6 @@ namespace PKHeX { return Box + (30 * SIZE_STORED + 0x14)*box + 0x14; } - public override int CurrentBox { get { return 0; } set { } } - public override int getBoxWallpaper(int box) - { - return box; - } public override string getBoxName(int box) { return PKX.getColoStr(Data, Box + 0x24A4*box, 8); diff --git a/PKHeX/Saves/SAV3RSBox.cs b/PKHeX/Saves/SAV3RSBox.cs index 626bc3bf9..e135943f6 100644 --- a/PKHeX/Saves/SAV3RSBox.cs +++ b/PKHeX/Saves/SAV3RSBox.cs @@ -127,11 +127,11 @@ namespace PKHeX get { return Data[Box + 4]*2; } set { Data[Box + 4] = (byte)(value/2); } } - public override int getBoxWallpaper(int box) + protected override int getBoxWallpaperOffset(int box) { // Box Wallpaper is directly after the Box Names int offset = Box + 0x1ED19 + box/2; - return Data[offset]; + return offset; } public override string getBoxName(int box) { diff --git a/PKHeX/Saves/SAV3XD.cs b/PKHeX/Saves/SAV3XD.cs index 0df0c2b2e..06fa9a676 100644 --- a/PKHeX/Saves/SAV3XD.cs +++ b/PKHeX/Saves/SAV3XD.cs @@ -229,11 +229,6 @@ namespace PKHeX { return Box + (30 * SIZE_STORED + 0x14)*box + 0x14; } - public override int CurrentBox { get { return 0; } set { } } - public override int getBoxWallpaper(int box) - { - return box; - } public override string getBoxName(int box) { return PKX.getColoStr(Data, Box + (30 * SIZE_STORED + 0x14)*box, 8); diff --git a/PKHeX/Saves/SAV4.cs b/PKHeX/Saves/SAV4.cs index 2eb963227..a79e09e87 100644 --- a/PKHeX/Saves/SAV4.cs +++ b/PKHeX/Saves/SAV4.cs @@ -571,13 +571,13 @@ namespace PKHeX get { return Data[Version == GameVersion.HGSS ? getBoxOffset(BoxCount) : Box - 4]; } set { Data[Version == GameVersion.HGSS ? getBoxOffset(BoxCount) : Box - 4] = (byte)value; } } - public override int getBoxWallpaper(int box) + protected override int getBoxWallpaperOffset(int box) { // Box Wallpaper is directly after the Box Names int offset = getBoxOffset(BoxCount); if (Version == GameVersion.HGSS) offset += 0x18; offset += BoxCount*0x28 + box; - return Data[offset]; + return offset; } public override string getBoxName(int box) { diff --git a/PKHeX/Saves/SAV4BR.cs b/PKHeX/Saves/SAV4BR.cs index 60d66b9c5..13d83b3df 100644 --- a/PKHeX/Saves/SAV4BR.cs +++ b/PKHeX/Saves/SAV4BR.cs @@ -126,8 +126,6 @@ namespace PKHeX } // Save file does not have Box Name / Wallpaper info - public override int CurrentBox { get { return 0; } set { } } - public override int getBoxWallpaper(int box) { return box; } public override string getBoxName(int box) { return $"BOX {box + 1}"; } public override void setBoxName(int box, string value) { } diff --git a/PKHeX/Saves/SAV5.cs b/PKHeX/Saves/SAV5.cs index ee6a23441..e499fa27a 100644 --- a/PKHeX/Saves/SAV5.cs +++ b/PKHeX/Saves/SAV5.cs @@ -450,9 +450,9 @@ namespace PKHeX Encoding.Unicode.GetBytes(val.PadRight(0x14, '\0')).CopyTo(Data, PCLayout + 0x28 * box + 4); Edited = true; } - public override int getBoxWallpaper(int box) + protected override int getBoxWallpaperOffset(int box) { - return Data[PCLayout + 0x3C4 + box]; + return PCLayout + 0x3C4 + box; } public override int CurrentBox { diff --git a/PKHeX/Saves/SAV6.cs b/PKHeX/Saves/SAV6.cs index f6525c906..daedf4996 100644 --- a/PKHeX/Saves/SAV6.cs +++ b/PKHeX/Saves/SAV6.cs @@ -651,10 +651,12 @@ namespace PKHeX { return Box + SIZE_STORED*box*30; } - public override int getBoxWallpaper(int box) + protected override int getBoxWallpaperOffset(int box) { - int ofs = PCBackgrounds > 0 && PCBackgrounds < Data.Length ? PCBackgrounds : 0; - return Data[ofs + box]; + int ofs = PCBackgrounds > 0 && PCBackgrounds < Data.Length ? PCBackgrounds : -1; + if (ofs > -1) + return ofs + box; + return ofs; } public override string getBoxName(int box) { @@ -773,6 +775,17 @@ namespace PKHeX get { return Data[BattleBox + 6 * SIZE_STORED] != 0; } set { Data[BattleBox + 6 * SIZE_STORED] = (byte)(value ? 1 : 0); } } + public override int BoxesUnlocked { get { return Data[PCFlags + 1] - 1; } set { Data[PCFlags + 1] = (byte)(value + 1); } } + public override byte[] BoxFlags + { + get { return new[] { Data[PCFlags], Data[PCFlags + 2] }; } + set + { + if (value.Length != 2) return; + Data[PCFlags] = value[0]; + Data[PCFlags + 2] = value[1]; + } + } // Mystery Gift protected override bool[] MysteryGiftReceivedFlags @@ -847,7 +860,7 @@ namespace PKHeX } } - private WC6 getWC6(int index) + private MysteryGift getWC6(int index) { if (WondercardData < 0) return null; diff --git a/PKHeX/Saves/SAV7.cs b/PKHeX/Saves/SAV7.cs index 613d3b566..b4b34756f 100644 --- a/PKHeX/Saves/SAV7.cs +++ b/PKHeX/Saves/SAV7.cs @@ -430,10 +430,19 @@ namespace PKHeX { return Box + SIZE_STORED*box*30; } - public override int getBoxWallpaper(int box) + protected override int getBoxWallpaperOffset(int box) { + int ofs = PCBackgrounds > 0 && PCBackgrounds < Data.Length ? PCBackgrounds : -1; + if (ofs > -1) + return ofs + box; + return ofs; + } + public override void setBoxWallpaper(int box, int value) + { + if (PCBackgrounds < 0) + return; int ofs = PCBackgrounds > 0 && PCBackgrounds < Data.Length ? PCBackgrounds : 0; - return Data[ofs + box]; + Data[ofs + box] = (byte)value; } public override string getBoxName(int box) { @@ -575,7 +584,17 @@ namespace PKHeX get { return Data[Party + 6 * SIZE_PARTY]; } protected set { Data[Party + 6 * SIZE_PARTY] = (byte)value; } } - + public override int BoxesUnlocked { get { return -1; } set { Data[PCFlags + 1] = (byte)(value + 1); } } + public override byte[] BoxFlags { + get { return null; } + set + { + if (value.Length != 2) return; + Data[PCFlags] = value[0]; + Data[PCFlags + 2] = value[1]; + } + } + public override int DaycareSeedSize => 16; public override int getDaycareSlotOffset(int loc, int slot) { diff --git a/PKHeX/Saves/SaveFile.cs b/PKHeX/Saves/SaveFile.cs index 6e1e68b0e..a0341986f 100644 --- a/PKHeX/Saves/SaveFile.cs +++ b/PKHeX/Saves/SaveFile.cs @@ -95,7 +95,7 @@ namespace PKHeX public bool HasGTS => GTS > -1; public bool HasDaycare => Daycare > -1; public virtual bool HasPokeDex => PokeDex > -1; - public virtual bool HasBoxWallpapers => PCLayout > -1; + public virtual bool HasBoxWallpapers => getBoxWallpaperOffset(0) > -1; public virtual bool HasSUBE => SUBE > -1 && !ORAS; public virtual bool HasGeolocation => false; public bool HasPokeBlock => ORAS && !ORASDEMO; @@ -319,14 +319,12 @@ namespace PKHeX public virtual uint Money { get; set; } public abstract int BoxCount { get; } public virtual int PartyCount { get; protected set; } - public abstract int CurrentBox { get; set; } public abstract string Extension { get; } // Varied Methods protected abstract void setChecksums(); public abstract int getBoxOffset(int box); public abstract int getPartyOffset(int slot); - public abstract int getBoxWallpaper(int box); public abstract string getBoxName(int box); public abstract void setBoxName(int box, string val); public virtual ulong? GameSyncID { get { return null; } set { } } @@ -349,6 +347,25 @@ namespace PKHeX // Storage public virtual int BoxSlotCount => 30; + public virtual int BoxesUnlocked { get { return -1; } set { } } + public virtual byte[] BoxFlags { get { return null; } set { } } + public virtual int CurrentBox { get { return 0; } set { } } + + protected virtual int getBoxWallpaperOffset(int box) { return -1; } + public int getBoxWallpaper(int box) + { + int offset = getBoxWallpaperOffset(box); + if (offset < 0 || box > BoxCount) + return box; + return Data[offset]; + } + public virtual void setBoxWallpaper(int box, int val) + { + int offset = getBoxWallpaperOffset(box); + if (offset < 0 || box > BoxCount) + return; + Data[offset] = (byte)val; + } public virtual PKM getPartySlot(int offset) {