2021-06-13 07:38:47 +00:00
|
|
|
|
using System;
|
2022-01-03 05:35:59 +00:00
|
|
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
2021-06-13 07:38:47 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
|
|
public sealed class SecretBase6Block : SaveBlock<SAV6AO>
|
2021-06-13 07:38:47 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
public SecretBase6Block(SAV6AO sav, int offset) : base(sav) => Offset = offset;
|
2021-06-13 07:38:47 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
// structure: 0x7AD0 bytes total
|
|
|
|
|
// [0000-031F] SecretBaseGoodStock[200] (800 bytes)
|
|
|
|
|
// [0320-0321] u16 SecretBaseSelfLocation (-1 if not created)
|
|
|
|
|
// [0322-0323] u16 alignment padding
|
|
|
|
|
// [0324-0633] SecretBase6Self (0x310 bytes)
|
|
|
|
|
// [0634-0637] alignment for next field
|
|
|
|
|
// [0638-7A77] SecretBase6Other[30] (0x7440 bytes, 0x3E0 each)
|
|
|
|
|
// each SecretBase6Other is a SecretBaseSelf followed by extra fields
|
|
|
|
|
// [7A78-7AC7] u128[5] keys?
|
|
|
|
|
// [7AC8.. ] u8 SecretBaseHasFlag
|
2021-06-13 07:38:47 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
public const int Count_Goods = 200;
|
|
|
|
|
public const int Count_Goods_Used = 173;
|
2021-06-13 07:38:47 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
public SecretBase6GoodStock GetGood(int index) => new(Data.AsSpan(Offset + GetGoodOffset(index)));
|
|
|
|
|
public void SetGood(SecretBase6GoodStock good, int index) => good.Write(Data.AsSpan(Offset + GetGoodOffset(index)));
|
2021-06-13 07:38:47 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
private static int GetGoodOffset(int index)
|
|
|
|
|
{
|
|
|
|
|
if ((uint) index >= Count_Goods)
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(index));
|
|
|
|
|
return SecretBase6GoodStock.SIZE * index;
|
|
|
|
|
}
|
2021-06-13 07:38:47 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
public void GiveAllGoods()
|
|
|
|
|
{
|
|
|
|
|
const uint value = 25u | (1 << 16); // count: 25, new flag.
|
|
|
|
|
for (int i = 0; i < Count_Goods_Used; i++)
|
|
|
|
|
WriteUInt32LittleEndian(Data.AsSpan(Offset + GetGoodOffset(i)), value);
|
|
|
|
|
}
|
2021-06-13 07:38:47 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
public ushort SecretBaseSelfLocation
|
|
|
|
|
{
|
|
|
|
|
get => ReadUInt16LittleEndian(Data.AsSpan(Offset + 800));
|
|
|
|
|
set => WriteUInt16LittleEndian(Data.AsSpan(Offset + 800), value);
|
|
|
|
|
}
|
2021-06-13 07:38:47 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
public const int OtherSecretBaseCount = 30;
|
|
|
|
|
private const int OtherSecretStart = 0x638;
|
|
|
|
|
public SecretBase6 GetSecretBaseSelf() => new(Data, Offset + 0x324);
|
|
|
|
|
public SecretBase6Other GetSecretBaseOther(int index) => new(Data, Offset + OtherSecretStart + GetSecretBaseOtherOffset(index));
|
2021-06-13 07:38:47 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
private static int GetSecretBaseOtherOffset(int index)
|
|
|
|
|
{
|
|
|
|
|
if ((uint) index >= OtherSecretBaseCount)
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(index));
|
|
|
|
|
return SecretBase6Other.SIZE * index;
|
|
|
|
|
}
|
2021-06-13 07:38:47 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
public bool SecretBaseHasFlag
|
|
|
|
|
{
|
|
|
|
|
get => Data[Offset + 0x7AC8] == 1;
|
|
|
|
|
set => Data[Offset + 0x7AC8] = (byte) (value ? 1 : 0);
|
|
|
|
|
}
|
2021-06-13 07:38:47 +00:00
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
|
public void DeleteOther(int index)
|
|
|
|
|
{
|
|
|
|
|
int baseOffset = Offset + OtherSecretStart;
|
|
|
|
|
const int maxBaseIndex = OtherSecretBaseCount - 1;
|
|
|
|
|
const int size = SecretBase6Other.SIZE;
|
|
|
|
|
int offset = baseOffset + GetSecretBaseOtherOffset(index);
|
|
|
|
|
var arr = SAV.Data;
|
|
|
|
|
if ((uint)index < OtherSecretBaseCount)
|
2021-06-13 07:38:47 +00:00
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
|
int shiftDownCount = maxBaseIndex - index;
|
|
|
|
|
int shiftDownLength = size * shiftDownCount;
|
|
|
|
|
Array.Copy(arr, offset + size, arr, offset, shiftDownLength);
|
2021-06-13 07:38:47 +00:00
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
|
|
// Ensure Last Entry is Cleared
|
|
|
|
|
int lastBaseOffset = baseOffset + (size * maxBaseIndex);
|
|
|
|
|
arr.AsSpan(lastBaseOffset, size).Clear();
|
2021-06-13 07:38:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|