mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-10 06:34:19 +00:00
Split pgf and wc5full
Importing had a bug where it would retain the metadata when setting to save file, rather than trimming down to the gift. Split them into separate classes like gen6+ Remove erroneous WB7 size; 0x108 is only valid for a subsection, and won't work with the class since it needs to pull from the localization data. Nobody should be affected by that change.
This commit is contained in:
parent
73c5e258b7
commit
00ce859584
6 changed files with 84 additions and 12 deletions
|
@ -80,7 +80,7 @@ public static class EncounterEvent
|
|||
private static WC6[] GetWC6DB(ReadOnlySpan<byte> wc6bin, ReadOnlySpan<byte> wc6full) => WC6Full.GetArray(wc6full, wc6bin);
|
||||
private static WC7[] GetWC7DB(ReadOnlySpan<byte> wc7bin, ReadOnlySpan<byte> wc7full) => WC7Full.GetArray(wc7full, wc7bin);
|
||||
|
||||
private static WB7[] GetWB7DB(ReadOnlySpan<byte> bin) => Get(bin, WB7.SizeFull, static d => new WB7(d));
|
||||
private static WB7[] GetWB7DB(ReadOnlySpan<byte> bin) => Get(bin, WB7.Size, static d => new WB7(d));
|
||||
private static WC8[] GetWC8DB(ReadOnlySpan<byte> bin) => Get(bin, WC8.Size, static d => new WC8(d));
|
||||
private static WB8[] GetWB8DB(ReadOnlySpan<byte> bin) => Get(bin, WB8.Size, static d => new WB8(d));
|
||||
private static WA8[] GetWA8DB(ReadOnlySpan<byte> bin) => Get(bin, WA8.Size, static d => new WA8(d));
|
||||
|
|
|
@ -515,6 +515,9 @@ public sealed class MiscVerifier : Verifier
|
|||
case WA8 wa8 when !wa8.CanBeReceivedByVersion(pk.Version, pk):
|
||||
data.AddLine(GetInvalid(LEncGiftVersionNotDistributed, GameOrigin));
|
||||
return;
|
||||
case PGF pgf when pgf.RestrictLanguage != 0 && pk.Language != pgf.RestrictLanguage:
|
||||
data.AddLine(GetInvalid(string.Format(LOTLanguage, pgf.RestrictLanguage, pk.Language), CheckIdentifier.Language));
|
||||
return;
|
||||
case WC6 wc6 when wc6.RestrictLanguage != 0 && pk.Language != wc6.RestrictLanguage:
|
||||
data.AddLine(GetInvalid(string.Format(LOTLanguage, wc6.RestrictLanguage, pk.Language), CheckIdentifier.Language));
|
||||
return;
|
||||
|
|
|
@ -35,15 +35,14 @@ public abstract class MysteryGift : IEncounterable, IMoveset, ITrainerID32, IFat
|
|||
PGF.Size when Equals(ext, ".pgf") => new PGF(data),
|
||||
WC6.Size when Equals(ext, ".wc6") => new WC6(data),
|
||||
WC7.Size when Equals(ext, ".wc7") => new WC7(data),
|
||||
WB7.Size when Equals(ext, ".wb7") => new WB7(data),
|
||||
WR7.Size when Equals(ext, ".wr7") => new WR7(data),
|
||||
WB7.Size when Equals(ext, ".wb7", ".wb7full") => new WB7(data),
|
||||
WC8.Size when Equals(ext, ".wc8", ".wc8full") => new WC8(data),
|
||||
WB8.Size when Equals(ext, ".wb8") => new WB8(data),
|
||||
WA8.Size when Equals(ext, ".wa8") => new WA8(data),
|
||||
WC9.Size when Equals(ext, ".wc9") => new WC9(data),
|
||||
|
||||
PGF.SizeFull when Equals(ext, ".wc5full") => new PGF(data),
|
||||
WB7.SizeFull when Equals(ext, ".wb7full") => new WB7(data),
|
||||
WC5Full.Size when Equals(ext, ".wc5full") => new WC5Full(data).Gift,
|
||||
WC6Full.Size when Equals(ext, ".wc6full") => new WC6Full(data).Gift,
|
||||
WC7Full.Size when Equals(ext, ".wc7full") => new WC7Full(data).Gift,
|
||||
_ => null,
|
||||
|
|
|
@ -10,12 +10,23 @@ public sealed class PGF(byte[] Data) : DataMysteryGift(Data), IRibbonSetEvent3,
|
|||
IContestStats, INature, IRestrictVersion
|
||||
{
|
||||
public PGF() : this(new byte[Size]) { }
|
||||
public int RestrictLanguage { get; set; } // None
|
||||
public byte RestrictVersion { get; set; } // Permit All
|
||||
|
||||
public const int Size = 0xCC;
|
||||
public const int SizeFull = 0x2D0;
|
||||
public override byte Generation => 5;
|
||||
public override EntityContext Context => EntityContext.Gen5;
|
||||
public override GameVersion Version => OriginGame == 0 ? GameVersion.Gen5 : (GameVersion)OriginGame;
|
||||
public override GameVersion Version => OriginGame != 0 ? (GameVersion)OriginGame : RestrictVersion switch
|
||||
{
|
||||
1 => GameVersion.W,
|
||||
2 => GameVersion.B,
|
||||
3 => GameVersion.BW,
|
||||
4 => GameVersion.W2,
|
||||
8 => GameVersion.B2,
|
||||
12 => GameVersion.B2W2,
|
||||
_ => GameVersion.Gen5,
|
||||
};
|
||||
|
||||
public override bool FatefulEncounter => true;
|
||||
|
||||
public override uint ID32 { get => ReadUInt32LittleEndian(Data.AsSpan(0x00)); set => WriteUInt32LittleEndian(Data.AsSpan(0x00), value); }
|
||||
|
@ -433,7 +444,24 @@ public sealed class PGF(byte[] Data) : DataMysteryGift(Data), IRibbonSetEvent3,
|
|||
}
|
||||
|
||||
protected override bool IsMatchDeferred(PKM pk) => false;
|
||||
protected override bool IsMatchPartial(PKM pk) => !CanBeReceivedByVersion(pk.Version);
|
||||
|
||||
public bool CanBeReceivedByVersion(GameVersion game) => OriginGame == 0 || (GameVersion)OriginGame == game;
|
||||
protected override bool IsMatchPartial(PKM pk)
|
||||
{
|
||||
if (RestrictLanguage != 0 && RestrictLanguage != pk.Language)
|
||||
return true;
|
||||
return !CanBeReceivedByVersion(pk.Version);
|
||||
}
|
||||
|
||||
public bool CanBeReceivedByVersion(GameVersion version)
|
||||
{
|
||||
if (OriginGame != 0)
|
||||
return version == (GameVersion)OriginGame;
|
||||
if (version is < GameVersion.W or > GameVersion.B2)
|
||||
return false;
|
||||
if (RestrictVersion == 0)
|
||||
return true; // no data
|
||||
var bitIndex = (int)(version - GameVersion.W);
|
||||
var bit = 1 << bitIndex;
|
||||
return (RestrictVersion & bit) != 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,11 +9,10 @@ namespace PKHeX.Core;
|
|||
public sealed class WB7(byte[] Data)
|
||||
: DataMysteryGift(Data), ILangNick, IAwakened, IRelearn, INature, ILangNicknamedTemplate, IRestrictVersion
|
||||
{
|
||||
public WB7() : this(new byte[SizeFull]) { }
|
||||
public WB7() : this(new byte[Size]) { }
|
||||
|
||||
public const int Size = 0x108;
|
||||
public const int SizeFull = 0x310;
|
||||
private const int CardStart = SizeFull - Size;
|
||||
public const int Size = 0x310;
|
||||
private const int CardStart = 0x208;
|
||||
public override bool FatefulEncounter => true;
|
||||
|
||||
public override byte Generation => 7;
|
||||
|
|
43
PKHeX.Core/MysteryGifts/WC5Full.cs
Normal file
43
PKHeX.Core/MysteryGifts/WC5Full.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
using System;
|
||||
using static System.Buffers.Binary.BinaryPrimitives;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public sealed class WC5Full
|
||||
{
|
||||
public const int Size = 0x2D0;
|
||||
public readonly byte[] Data;
|
||||
public readonly PGF Gift;
|
||||
|
||||
private Span<byte> Metadata => Data.AsSpan(PGF.Size);
|
||||
|
||||
public WC5Full(byte[] data)
|
||||
{
|
||||
Data = data;
|
||||
var wc5 = data.AsSpan(0, PGF.Size).ToArray();
|
||||
Gift = new PGF(wc5)
|
||||
{
|
||||
Date = EncounterDate.GetDateNDS(),
|
||||
RestrictVersion = RestrictVersion,
|
||||
RestrictLanguage = RestrictLanguage,
|
||||
};
|
||||
}
|
||||
|
||||
public byte RestrictVersion { get => Metadata[2]; set => Metadata[2] = value; }
|
||||
// 1 byte unused, since ^ is u16
|
||||
|
||||
// 506 bytes for distribution text
|
||||
public Span<byte> DistributionTextData => Metadata[4..^6];
|
||||
|
||||
public string DistributionText
|
||||
{
|
||||
get => StringConverter5.GetString(DistributionTextData);
|
||||
set => StringConverter5.SetString(DistributionTextData, value, (DistributionTextData.Length / 2) - 1, 0, StringConverterOption.ClearFF);
|
||||
}
|
||||
|
||||
public byte DownloadAnimation { get => Metadata[^6]; set => Metadata[^6] = value; }
|
||||
public byte RestrictLanguage { get => Metadata[^5]; set => Metadata[^5] = value; }
|
||||
|
||||
// u16 unused
|
||||
public ushort Checksum { get => ReadUInt16LittleEndian(Metadata[^2..]); set => WriteUInt16LittleEndian(Metadata[^2..], value); }
|
||||
}
|
Loading…
Reference in a new issue