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 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;
}

View file

@ -116,9 +116,11 @@ public abstract class SCBlockAccessor : ISaveBlockAccessor<SCBlock>
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);
/// <summary>
/// Finds a specified <see cref="key"/> within the <see cref="array"/>.
/// </summary>

View file

@ -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;

View file

@ -14,17 +14,20 @@ public sealed class RaidSpawnList9 : SaveBlock<SAV9SV>
public const int RaidCountLegal_T2 = 80;
public readonly bool HasSeeds;
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;
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<SAV9SV>
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); }
}
/// <summary>