From 61d958e07a4ac6757288704c4898895da95622f0 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 17 Dec 2023 19:45:13 -0800 Subject: [PATCH] Fix blueberry raids & stellar showdown parse --- PKHeX.Core/Editing/Showdown/ShowdownSet.cs | 6 ++--- PKHeX.Core/Saves/Access/SCBlockAccessor.cs | 4 +++- .../Saves/Access/SaveBlockAccessor9SV.cs | 24 +++++++++++++++---- .../Substructures/Gen9/RaidSpawnList9.cs | 17 +++++++------ 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/PKHeX.Core/Editing/Showdown/ShowdownSet.cs b/PKHeX.Core/Editing/Showdown/ShowdownSet.cs index 23a01bc79..aff8b89f2 100644 --- a/PKHeX.Core/Editing/Showdown/ShowdownSet.cs +++ b/PKHeX.Core/Editing/Showdown/ShowdownSet.cs @@ -309,11 +309,9 @@ public sealed class ShowdownSet : IBattleTemplate var types = Strings.types; var val = StringUtil.FindIndexIgnoreCase(types, value); if (val < 0) - { - if (value is not "Stellar") - return false; + return false; + if (val == TeraTypeUtil.StellarTypeDisplayStringIndex) val = TeraTypeUtil.Stellar; - } TeraType = (MoveType)val; return true; } diff --git a/PKHeX.Core/Saves/Access/SCBlockAccessor.cs b/PKHeX.Core/Saves/Access/SCBlockAccessor.cs index e51e5cb7e..10ea8a473 100644 --- a/PKHeX.Core/Saves/Access/SCBlockAccessor.cs +++ b/PKHeX.Core/Saves/Access/SCBlockAccessor.cs @@ -116,9 +116,11 @@ public abstract class SCBlockAccessor : ISaveBlockAccessor var index = FindIndex(array, key); if (index != -1) return array[index]; - return new SCBlock(0, SCTypeCode.None); + return GetFakeBlock(); } + protected static SCBlock GetFakeBlock() => new(0, SCTypeCode.None); + /// /// Finds a specified within the . /// diff --git a/PKHeX.Core/Saves/Access/SaveBlockAccessor9SV.cs b/PKHeX.Core/Saves/Access/SaveBlockAccessor9SV.cs index 905d5247a..8211a27c9 100644 --- a/PKHeX.Core/Saves/Access/SaveBlockAccessor9SV.cs +++ b/PKHeX.Core/Saves/Access/SaveBlockAccessor9SV.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; // ReSharper disable UnusedMember.Local #pragma warning disable IDE0051 // Remove unused private members @@ -47,9 +48,24 @@ public sealed class SaveBlockAccessor9SV : SCBlockAccessor, ISaveBlock9Main LastSaved = new Epoch1970Value(GetBlock(KLastSaved)); PlayerFashion = new PlayerFashion9(sav, GetBlock(KCurrentClothing)); PlayerAppearance = new PlayerAppearance9(sav, GetBlock(KCurrentAppearance)); - RaidPaldea = new RaidSpawnList9(sav, GetBlock(KTeraRaidPaldea), RaidSpawnList9.RaidCountLegal_T0, true); - RaidKitakami = new RaidSpawnList9(sav, GetBlockSafe(KTeraRaidKitakami), RaidSpawnList9.RaidCountLegal_T1, false); - RaidBlueberry = new RaidSpawnList9(sav, GetBlockSafe(KTeraRaidBlueberry), RaidSpawnList9.RaidCountLegal_T2, false); + + var raidPaldea = GetBlock(KTeraRaidPaldea); + RaidPaldea = new RaidSpawnList9(sav, raidPaldea, raidPaldea.Data, RaidSpawnList9.RaidCountLegal_T0, true); + if (TryGetBlock(KTeraRaidDLC, out var raidDLC)) + { + var buffer = raidDLC.Data; + const int size = 0xC80; + var memKita = buffer.AsMemory(0, size); + var memBlue = buffer.AsMemory(size, size); + RaidKitakami = new RaidSpawnList9(sav, raidDLC, memKita, RaidSpawnList9.RaidCountLegal_T1, false); + RaidBlueberry = new RaidSpawnList9(sav, raidDLC, memBlue, RaidSpawnList9.RaidCountLegal_T2, false); + } + else + { + var fake = GetFakeBlock(); + RaidKitakami = new RaidSpawnList9(sav, fake, default, RaidSpawnList9.RaidCountLegal_T1, false); + RaidBlueberry = new RaidSpawnList9(sav, fake, default, RaidSpawnList9.RaidCountLegal_T2, false); + } RaidSevenStar = new RaidSevenStar9(sav, GetBlock(KSevenStarRaidsCapture)); EnrollmentDate = new Epoch1900Value(GetBlock(KEnrollmentDate)); BlueberryQuestRecord = new BlueberryQuestRecord9(sav, GetBlockSafe(KBlueberryQuestRecords)); @@ -85,7 +101,7 @@ public sealed class SaveBlockAccessor9SV : SCBlockAccessor, ISaveBlock9Main private const uint KOverworld = 0x173304D8; // [0x158+7C][20] overworld Pokémon private const uint KGimmighoul = 0x53DC955C; // ulong seed x2 (today and tomorrow); Gimmighoul struct (0x20): bool is_active, u64 hash, u64 seed, bool ??, bool first_time private const uint KTeraRaidPaldea = 0xCAAC8800; - private const uint KTeraRaidKitakami = 0x100B93DA; + private const uint KTeraRaidDLC = 0x100B93DA; private const uint KTeraRaidBlueberry = 0x0C62D416; public const uint KBoxesUnlocked = 0x71825204; public const uint KFusedKyurem = 0x7E0ADF89; diff --git a/PKHeX.Core/Saves/Substructures/Gen9/RaidSpawnList9.cs b/PKHeX.Core/Saves/Substructures/Gen9/RaidSpawnList9.cs index 77fd2294e..314685ab5 100644 --- a/PKHeX.Core/Saves/Substructures/Gen9/RaidSpawnList9.cs +++ b/PKHeX.Core/Saves/Substructures/Gen9/RaidSpawnList9.cs @@ -14,17 +14,20 @@ public sealed class RaidSpawnList9 : SaveBlock public const int RaidCountLegal_T2 = 80; public readonly bool HasSeeds; private readonly int OffsetRaidStart; + private readonly Memory Memory; + private Span Span => Memory.Span; - public RaidSpawnList9(SAV9SV sav, SCBlock block, int countUsed, bool hasSeeds) : base(sav, block.Data) + public RaidSpawnList9(SAV9SV sav, SCBlock block, Memory memory, int countUsed, bool hasSeeds) : base(sav, block.Data) { - var length = block.Data.Length; + Memory = memory; + var length = memory.Length; HasSeeds = hasSeeds; OffsetRaidStart = hasSeeds ? 0x10 : 0; CountAll = length == 0 ? 0 : (length - OffsetRaidStart) / TeraRaidDetail.SIZE; CountUsed = countUsed; } - public TeraRaidDetail GetRaid(int entry) => new(Data.AsMemory(GetOffset(entry), TeraRaidDetail.SIZE)); + public TeraRaidDetail GetRaid(int entry) => new(Memory.Slice(GetOffset(entry), TeraRaidDetail.SIZE)); private int GetOffset(int entry) => OffsetRaidStart + (entry * TeraRaidDetail.SIZE); @@ -38,14 +41,14 @@ public sealed class RaidSpawnList9 : SaveBlock public ulong CurrentSeed { - get => HasSeeds ? ReadUInt64LittleEndian(Data.AsSpan(0x00)) : 0; - set { if (HasSeeds) WriteUInt64LittleEndian(Data.AsSpan(0x00), value); } + get => HasSeeds ? ReadUInt64LittleEndian(Span) : 0; + set { if (HasSeeds) WriteUInt64LittleEndian(Span, value); } } public ulong TomorrowSeed { - get => HasSeeds ? ReadUInt64LittleEndian(Data.AsSpan(0x08)) : 0; - set { if (HasSeeds) WriteUInt64LittleEndian(Data.AsSpan(0x08), value); } + get => HasSeeds ? ReadUInt64LittleEndian(Span[0x8..]) : 0; + set { if (HasSeeds) WriteUInt64LittleEndian(Span[0x8..], value); } } ///