Fix blueberry raids & stellar showdown parse

This commit is contained in:
Kurt 2023-12-17 19:45:13 -08:00
parent b8d370b661
commit 61d958e07a
4 changed files with 35 additions and 16 deletions

View file

@ -309,11 +309,9 @@ public sealed class ShowdownSet : IBattleTemplate
var types = Strings.types; var types = Strings.types;
var val = StringUtil.FindIndexIgnoreCase(types, value); var val = StringUtil.FindIndexIgnoreCase(types, value);
if (val < 0) if (val < 0)
{ return false;
if (value is not "Stellar") if (val == TeraTypeUtil.StellarTypeDisplayStringIndex)
return false;
val = TeraTypeUtil.Stellar; val = TeraTypeUtil.Stellar;
}
TeraType = (MoveType)val; TeraType = (MoveType)val;
return true; return true;
} }

View file

@ -116,9 +116,11 @@ public abstract class SCBlockAccessor : ISaveBlockAccessor<SCBlock>
var index = FindIndex(array, key); var index = FindIndex(array, key);
if (index != -1) if (index != -1)
return array[index]; return array[index];
return new SCBlock(0, SCTypeCode.None); return GetFakeBlock();
} }
protected static SCBlock GetFakeBlock() => new(0, SCTypeCode.None);
/// <summary> /// <summary>
/// Finds a specified <see cref="key"/> within the <see cref="array"/>. /// Finds a specified <see cref="key"/> within the <see cref="array"/>.
/// </summary> /// </summary>

View file

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
// ReSharper disable UnusedMember.Local // ReSharper disable UnusedMember.Local
#pragma warning disable IDE0051 // Remove unused private members #pragma warning disable IDE0051 // Remove unused private members
@ -47,9 +48,24 @@ public sealed class SaveBlockAccessor9SV : SCBlockAccessor, ISaveBlock9Main
LastSaved = new Epoch1970Value(GetBlock(KLastSaved)); LastSaved = new Epoch1970Value(GetBlock(KLastSaved));
PlayerFashion = new PlayerFashion9(sav, GetBlock(KCurrentClothing)); PlayerFashion = new PlayerFashion9(sav, GetBlock(KCurrentClothing));
PlayerAppearance = new PlayerAppearance9(sav, GetBlock(KCurrentAppearance)); 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); var raidPaldea = GetBlock(KTeraRaidPaldea);
RaidBlueberry = new RaidSpawnList9(sav, GetBlockSafe(KTeraRaidBlueberry), RaidSpawnList9.RaidCountLegal_T2, false); 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)); RaidSevenStar = new RaidSevenStar9(sav, GetBlock(KSevenStarRaidsCapture));
EnrollmentDate = new Epoch1900Value(GetBlock(KEnrollmentDate)); EnrollmentDate = new Epoch1900Value(GetBlock(KEnrollmentDate));
BlueberryQuestRecord = new BlueberryQuestRecord9(sav, GetBlockSafe(KBlueberryQuestRecords)); 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 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 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 KTeraRaidPaldea = 0xCAAC8800;
private const uint KTeraRaidKitakami = 0x100B93DA; private const uint KTeraRaidDLC = 0x100B93DA;
private const uint KTeraRaidBlueberry = 0x0C62D416; private const uint KTeraRaidBlueberry = 0x0C62D416;
public const uint KBoxesUnlocked = 0x71825204; public const uint KBoxesUnlocked = 0x71825204;
public const uint KFusedKyurem = 0x7E0ADF89; public const uint KFusedKyurem = 0x7E0ADF89;

View file

@ -14,17 +14,20 @@ public sealed class RaidSpawnList9 : SaveBlock<SAV9SV>
public const int RaidCountLegal_T2 = 80; public const int RaidCountLegal_T2 = 80;
public readonly bool HasSeeds; public readonly bool HasSeeds;
private readonly int OffsetRaidStart; private readonly int OffsetRaidStart;
private readonly Memory<byte> Memory;
private Span<byte> Span => Memory.Span;
public RaidSpawnList9(SAV9SV sav, SCBlock block, int countUsed, bool hasSeeds) : base(sav, block.Data) public RaidSpawnList9(SAV9SV sav, SCBlock block, Memory<byte> memory, int countUsed, bool hasSeeds) : base(sav, block.Data)
{ {
var length = block.Data.Length; Memory = memory;
var length = memory.Length;
HasSeeds = hasSeeds; HasSeeds = hasSeeds;
OffsetRaidStart = hasSeeds ? 0x10 : 0; OffsetRaidStart = hasSeeds ? 0x10 : 0;
CountAll = length == 0 ? 0 : (length - OffsetRaidStart) / TeraRaidDetail.SIZE; CountAll = length == 0 ? 0 : (length - OffsetRaidStart) / TeraRaidDetail.SIZE;
CountUsed = countUsed; 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); private int GetOffset(int entry) => OffsetRaidStart + (entry * TeraRaidDetail.SIZE);
@ -38,14 +41,14 @@ public sealed class RaidSpawnList9 : SaveBlock<SAV9SV>
public ulong CurrentSeed public ulong CurrentSeed
{ {
get => HasSeeds ? ReadUInt64LittleEndian(Data.AsSpan(0x00)) : 0; get => HasSeeds ? ReadUInt64LittleEndian(Span) : 0;
set { if (HasSeeds) WriteUInt64LittleEndian(Data.AsSpan(0x00), value); } set { if (HasSeeds) WriteUInt64LittleEndian(Span, value); }
} }
public ulong TomorrowSeed public ulong TomorrowSeed
{ {
get => HasSeeds ? ReadUInt64LittleEndian(Data.AsSpan(0x08)) : 0; get => HasSeeds ? ReadUInt64LittleEndian(Span[0x8..]) : 0;
set { if (HasSeeds) WriteUInt64LittleEndian(Data.AsSpan(0x08), value); } set { if (HasSeeds) WriteUInt64LittleEndian(Span[0x8..], value); }
} }
/// <summary> /// <summary>