From c6e133cff8d5642da72bdd1892469468ed2150e1 Mon Sep 17 00:00:00 2001 From: Zazsona <40435178+Zazsona@users.noreply.github.com> Date: Sun, 5 Feb 2023 19:47:35 +0000 Subject: [PATCH] =?UTF-8?q?Add=20Toys=20from=20the=20My=20Pok=C3=A9mon=20R?= =?UTF-8?q?anch=20Platinum=20Update=20(#3766)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add Ranch Toys from Platinum Update * Add ToyType validation to SAV4Ranch --- PKHeX.Core/Saves/Storage/SAV4Ranch.cs | 13 +++++++++---- .../Substructures/Gen4/Ranch/RanchLevel.cs | 4 ++-- .../Substructures/Gen4/Ranch/RanchToyType.cs | 18 +++++++++++++++++- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/PKHeX.Core/Saves/Storage/SAV4Ranch.cs b/PKHeX.Core/Saves/Storage/SAV4Ranch.cs index 8b721b866..c020c4d29 100644 --- a/PKHeX.Core/Saves/Storage/SAV4Ranch.cs +++ b/PKHeX.Core/Saves/Storage/SAV4Ranch.cs @@ -13,6 +13,7 @@ public sealed class SAV4Ranch : BulkStorage, ISaveFileRevision { protected override int SIZE_STORED => PokeCrypto.SIZE_4RSTORED; protected override int SIZE_PARTY => PokeCrypto.SIZE_4RSTORED; + public int MaxToyID => (int) ((SaveRevision == 0) ? RanchToyType.Poke_Ball : RanchToyType.Water); public int SaveRevision => Version == GameVersion.DP ? 0 : 1; public string SaveRevisionString => Version == GameVersion.DP ? "-DP" : "-Pt"; @@ -30,8 +31,10 @@ public sealed class SAV4Ranch : BulkStorage, ISaveFileRevision public override int BoxCount => (int)Math.Ceiling((decimal)SlotCount / SlotsPerBox); public int MiiCount { get; } public int TrainerMiiCount { get; } - public int MaxToys => RanchLevel.GetMaxToys(CurrentRanchLevelIndex); - public int MaxMiiCount => RanchLevel.GetMaxMiis(CurrentRanchLevelIndex); + public int MaxToyCount => RanchLevel.GetMaxToyCount(CurrentRanchLevelIndex); + public int MaxMiiCount => RanchLevel.GetMaxMiiCount(CurrentRanchLevelIndex); + + private readonly RanchToy BlankToy = new(new byte[] { (byte)RanchToyType.None, 0 }); public override PersonalTable4 Personal => PersonalTable.Pt; public override IReadOnlyList HeldItems => Legal.HeldItems_Pt; @@ -90,7 +93,7 @@ public sealed class SAV4Ranch : BulkStorage, ISaveFileRevision public RanchToy GetRanchToy(int index) { - if ((uint)index >= MaxToys) + if ((uint)index >= MaxToyCount) throw new ArgumentOutOfRangeException(nameof(index)); int toyOffset = ToyBaseOffset + (RanchToy.SIZE * index); @@ -100,8 +103,10 @@ public sealed class SAV4Ranch : BulkStorage, ISaveFileRevision public void SetRanchToy(RanchToy toy, int index) { - if ((uint)index >= MaxToys) + if ((uint)index >= MaxToyCount) throw new ArgumentOutOfRangeException(nameof(index)); + if (((int)toy.ToyType) > MaxToyID) // Ranch will throw "Corrupt Save" error if ToyId is > expected. + toy = BlankToy; int toyOffset = ToyBaseOffset + (RanchToy.SIZE * index); SetData(Data, toy.Data, toyOffset); diff --git a/PKHeX.Core/Saves/Substructures/Gen4/Ranch/RanchLevel.cs b/PKHeX.Core/Saves/Substructures/Gen4/Ranch/RanchLevel.cs index 61db27314..e09dadebe 100644 --- a/PKHeX.Core/Saves/Substructures/Gen4/Ranch/RanchLevel.cs +++ b/PKHeX.Core/Saves/Substructures/Gen4/Ranch/RanchLevel.cs @@ -7,7 +7,7 @@ public static class RanchLevel { public static int GetLevel(byte levelIndex) => levelIndex + 1; - public static int GetMaxMiis(byte levelIndex) => levelIndex switch + public static int GetMaxMiiCount(byte levelIndex) => levelIndex switch { >= 11 => 20, >= 08 => 15, @@ -15,7 +15,7 @@ public static class RanchLevel _ => 5, }; - public static int GetMaxToys(byte levelIndex) => levelIndex switch + public static int GetMaxToyCount(byte levelIndex) => levelIndex switch { >= 25 => 6, >= 20 => 5, diff --git a/PKHeX.Core/Saves/Substructures/Gen4/Ranch/RanchToyType.cs b/PKHeX.Core/Saves/Substructures/Gen4/Ranch/RanchToyType.cs index 8ec52272f..a0c040766 100644 --- a/PKHeX.Core/Saves/Substructures/Gen4/Ranch/RanchToyType.cs +++ b/PKHeX.Core/Saves/Substructures/Gen4/Ranch/RanchToyType.cs @@ -30,5 +30,21 @@ public enum RanchToyType : byte Sprint_Stand = 22, Attractor = 23, Challenger = 24, - Toy_Box = 25, + Toy_Box = 25, // Supports metadata - Metadata value is the index of the contained toy. + Poke_Ball = 26, // Normally unused + + // Pt Update: + Birthday_Cake = 27, + Apple_Box_S = 28, // Small Apple Box + Apple_Box_L = 29, // Large Apple Box + Dice = 30, + Picture_Frame_S = 31, // Small Picture Frame + Picture_Frame_L = 32, // Large Picture Frame + Flower = 33, + Lamp = 34, + Magnet = 35, + Twirler = 36, + Bound_Mat = 37, + Tree = 38, + Water = 39 // Normally unused; creates a massive plane of water in the sky }