2024-02-22 21:20:54 -06:00
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
namespace PKHeX.Core;
|
2017-04-29 20:04:54 -07:00
|
|
|
|
2021-12-04 18:32:35 -08:00
|
|
|
/// <summary>
|
|
|
|
/// Stores details about a <see cref="PKM.EncryptionConstant"/> (PID) and any associated details being traced to a known correlation.
|
|
|
|
/// </summary>
|
2024-02-22 21:20:54 -06:00
|
|
|
[StructLayout(LayoutKind.Explicit, Size = 10)]
|
|
|
|
public readonly struct PIDIV
|
2021-12-04 18:32:35 -08:00
|
|
|
{
|
|
|
|
internal static readonly PIDIV None = new();
|
2024-02-22 21:20:54 -06:00
|
|
|
internal static readonly PIDIV CuteCharm = new(PIDType.CuteCharm); // can be one of many seeds!
|
2021-12-04 18:32:35 -08:00
|
|
|
internal static readonly PIDIV Pokewalker = new(PIDType.Pokewalker);
|
|
|
|
internal static readonly PIDIV G5MGShiny = new(PIDType.G5MGShiny);
|
2021-01-27 16:52:04 -08:00
|
|
|
|
2024-02-22 21:20:54 -06:00
|
|
|
/// <summary>The RNG seed which immediately generates the PIDIV (starting with PID or IVs, whichever comes first)</summary>
|
|
|
|
[field: FieldOffset(0)]
|
|
|
|
public uint OriginSeed { get; }
|
|
|
|
/// <summary>The RNG seed which starts the encounter generation routine.</summary>
|
|
|
|
[field: FieldOffset(4)]
|
|
|
|
public uint EncounterSeed { get; init; }
|
|
|
|
|
|
|
|
/// <summary>The RNG seed which immediately generates the PIDIV (starting with PID or IVs, whichever comes first)</summary>
|
|
|
|
[field: FieldOffset(0)]
|
|
|
|
public ulong Seed64 { get; }
|
|
|
|
|
|
|
|
/// <summary>Type of PIDIV correlation</summary>
|
|
|
|
[field: FieldOffset(8)]
|
|
|
|
public PIDType Type { get; }
|
|
|
|
|
|
|
|
[field: FieldOffset(9)]
|
|
|
|
public LeadRequired Lead { get; init; }
|
|
|
|
|
|
|
|
public PIDIV(PIDType type, uint seed = 0)
|
|
|
|
{
|
|
|
|
Type = type;
|
|
|
|
OriginSeed = seed;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PIDIV(PIDType type, ulong seed)
|
|
|
|
{
|
|
|
|
Type = type;
|
|
|
|
Seed64 = seed;
|
|
|
|
}
|
|
|
|
|
2021-12-04 18:32:35 -08:00
|
|
|
/// <remarks> Some PIDIVs may be generated without a single seed, but may follow a traceable pattern. </remarks>
|
2024-02-22 21:20:54 -06:00
|
|
|
/// <summary> Indicates that there is no <see cref="OriginSeed"/> to refer to. </summary>
|
|
|
|
public bool NoSeed => Type is PIDType.None or PIDType.Pokewalker or PIDType.G5MGShiny;
|
2021-08-21 18:24:38 -07:00
|
|
|
|
|
|
|
#if DEBUG
|
2021-12-04 18:32:35 -08:00
|
|
|
public override string ToString() => NoSeed ? Type.ToString() : $"{Type} - 0x{OriginSeed:X8}";
|
2021-08-21 18:24:38 -07:00
|
|
|
#endif
|
2024-02-22 21:20:54 -06:00
|
|
|
public bool IsClassicMethod() => Type.IsClassicMethod();
|
|
|
|
|
2024-02-23 21:16:32 -06:00
|
|
|
public bool IsSeed64() => Type is PIDType.Xoroshiro;
|
2024-02-22 21:20:54 -06:00
|
|
|
|
|
|
|
public PIDIV AsEncounteredVia(LeadSeed condition) => this with { Lead = condition.Lead, EncounterSeed = condition.Seed };
|
2017-04-23 09:18:42 -07:00
|
|
|
}
|