mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-09-12 22:10:26 -05:00
Split daycare8 to its own file
Add method to fetch daycare seeds from metadata
This commit is contained in:
98
PKHeX.Core/Saves/Substructures/Gen8/Daycare8.cs
Normal file
98
PKHeX.Core/Saves/Substructures/Gen8/Daycare8.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Storage for the two in-game daycare structures.
|
||||
/// </summary>
|
||||
public sealed class Daycare8 : SaveBlock
|
||||
{
|
||||
public Daycare8(SaveFile sav, SCBlock block) : base(sav, block.Data) { }
|
||||
|
||||
// BLOCK STRUCTURE:
|
||||
// bool8 present
|
||||
// pk8 entry1
|
||||
// bool8 present
|
||||
// pk8 entry2
|
||||
// daycare metadata (0x26)
|
||||
// bool1 present
|
||||
// pk8 entry1
|
||||
// bool1 present
|
||||
// pk8 entry2
|
||||
// daycare metadata (0x26)
|
||||
|
||||
// daycare metadata:
|
||||
// u16 ??
|
||||
// u32 ?step count since last update?
|
||||
// u64 RNG seed
|
||||
// 0x18 unk
|
||||
|
||||
/// <summary>
|
||||
/// Size of each PKM data stored (bool, pk8)
|
||||
/// </summary>
|
||||
private const int STRUCT_SIZE = 1 + PKX.SIZE_8STORED;
|
||||
|
||||
/// <summary>
|
||||
/// Size of each daycare (both entries & metadata)
|
||||
/// </summary>
|
||||
private const int DAYCARE_SIZE = (2 * STRUCT_SIZE) + 0x26;
|
||||
|
||||
private const int META_1 = (2 * STRUCT_SIZE);
|
||||
private const int META_2 = DAYCARE_SIZE + META_1;
|
||||
|
||||
public bool GetDaycare1SlotOccupied(int slot)
|
||||
{
|
||||
if ((uint) slot >= 2)
|
||||
throw new IndexOutOfRangeException(nameof(slot));
|
||||
|
||||
return Data[GetDaycare1StructOffset(slot)] == 1;
|
||||
}
|
||||
|
||||
public bool GetDaycare2SlotOccupied(int slot)
|
||||
{
|
||||
if ((uint)slot >= 2)
|
||||
throw new IndexOutOfRangeException(nameof(slot));
|
||||
|
||||
return Data[GetDaycare2StructOffset(slot)] == 1;
|
||||
}
|
||||
|
||||
public static int GetDaycare1StructOffset(int slot)
|
||||
{
|
||||
if ((uint)slot >= 2)
|
||||
throw new IndexOutOfRangeException(nameof(slot));
|
||||
|
||||
return 0 + (slot * STRUCT_SIZE);
|
||||
}
|
||||
|
||||
public static int GetDaycare2StructOffset(int slot)
|
||||
{
|
||||
if ((uint)slot >= 2)
|
||||
throw new IndexOutOfRangeException(nameof(slot));
|
||||
|
||||
return DAYCARE_SIZE + (slot * STRUCT_SIZE);
|
||||
}
|
||||
|
||||
public static int GetDaycareSlotOffset(int daycare, int slot)
|
||||
{
|
||||
return daycare switch
|
||||
{
|
||||
0 => (1 + GetDaycare1StructOffset(slot)),
|
||||
1 => (1 + GetDaycare2StructOffset(slot)),
|
||||
_ => throw new IndexOutOfRangeException(nameof(daycare))
|
||||
};
|
||||
}
|
||||
|
||||
public static int GetDaycareMetadataOffset(int daycare)
|
||||
{
|
||||
return daycare switch
|
||||
{
|
||||
0 => META_1,
|
||||
1 => META_2,
|
||||
_ => throw new IndexOutOfRangeException(nameof(daycare))
|
||||
};
|
||||
}
|
||||
|
||||
public ulong GetDaycareSeed(int daycare) => BitConverter.ToUInt64(Data, GetDaycareMetadataOffset(daycare) + 6);
|
||||
public void SetDaycareSeed(int daycare, ulong value) => SAV.SetData(Data, BitConverter.GetBytes(value), GetDaycareMetadataOffset(daycare) + 6);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
using System;
|
||||
|
||||
namespace PKHeX.Core
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Storage for the Fused species, <see cref="Species.Kyurem"/>, <see cref="Species.Solgaleo"/>, <see cref="Species.Lunala"/>
|
||||
/// </summary>
|
||||
public sealed class Fused8 : SaveBlock
|
||||
{
|
||||
public Fused8(SaveFile sav, SCBlock block) : base(sav, block.Data) { }
|
||||
@@ -13,54 +14,4 @@ public static int GetFusedSlotOffset(int slot)
|
||||
return PKX.SIZE_8PARTY * slot;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class Daycare8 : SaveBlock
|
||||
{
|
||||
public Daycare8(SaveFile sav, SCBlock block) : base(sav, block.Data) { }
|
||||
|
||||
private const int STRUCT_SIZE = 4 + PKX.SIZE_8STORED;
|
||||
private const int DAYCARE_SIZE = (2 * STRUCT_SIZE) + 0x26;
|
||||
|
||||
public bool GetDaycare1SlotOccupied(int slot)
|
||||
{
|
||||
if ((uint) slot >= 2)
|
||||
throw new IndexOutOfRangeException(nameof(slot));
|
||||
|
||||
return Data[GetDaycare1StructOffset(slot)] == 1;
|
||||
}
|
||||
|
||||
public bool GetDaycare2SlotOccupied(int slot)
|
||||
{
|
||||
if ((uint)slot >= 2)
|
||||
throw new IndexOutOfRangeException(nameof(slot));
|
||||
|
||||
return Data[GetDaycare2StructOffset(slot)] == 1;
|
||||
}
|
||||
|
||||
public static int GetDaycare1StructOffset(int slot)
|
||||
{
|
||||
if ((uint)slot >= 2)
|
||||
throw new IndexOutOfRangeException(nameof(slot));
|
||||
|
||||
return 0 + (slot * STRUCT_SIZE);
|
||||
}
|
||||
|
||||
public static int GetDaycare2StructOffset(int slot)
|
||||
{
|
||||
if ((uint)slot >= 2)
|
||||
throw new IndexOutOfRangeException(nameof(slot));
|
||||
|
||||
return DAYCARE_SIZE + (slot * STRUCT_SIZE);
|
||||
}
|
||||
|
||||
public static int GetDaycareSlotOffset(int daycare, int slot)
|
||||
{
|
||||
return daycare switch
|
||||
{
|
||||
0 => (4 + GetDaycare1StructOffset(slot)),
|
||||
1 => (4 + GetDaycare2StructOffset(slot)),
|
||||
_ => throw new IndexOutOfRangeException(nameof(daycare))
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user