Fix broken tests

some gen6 cards have bad data? trickled out to tests which failed to
generate a celebi
revert to old code, add in some year-set safety checks
This commit is contained in:
Kurt 2018-12-12 18:00:26 -08:00
parent f6da84b699
commit 96ec0ff28b
3 changed files with 16 additions and 16 deletions

View File

@ -69,7 +69,7 @@ private uint Day
set => RawDate = SetDate(Year, Month, value);
}
private static uint SetDate(uint year, uint month, uint day) => ((year - 2000) * 10000) + (month * 100) + day;
private static uint SetDate(uint year, uint month, uint day) => Math.Max(0, year - 2000) * 10000 + (month * 100) + day;
/// <summary>
/// Gets or sets the date of the card.

View File

@ -18,21 +18,21 @@ public sealed class WC6 : MysteryGift, IRibbonSetEvent3, IRibbonSetEvent4, ILang
public WC6(byte[] data)
{
Data = data;
if (Data.Length != SizeFull)
return;
Data = data; if (Data.Length == SizeFull)
{
// Load Restrictions
RestrictVersion = Data[0x000];
RestrictLanguage = Data[0x1FF];
byte[] wc6 = new byte[Size];
if (Data[0x205] != 0) // Valid data
Array.Copy(Data, SizeFull - Size, wc6, 0, wc6.Length);
Data = wc6;
// Load Restrictions
RestrictVersion = Data[0x000];
RestrictLanguage = Data[0x1FF];
byte[] wc6 = new byte[Size];
if (Data[0x205] != 0) // Valid data
Array.Copy(Data, SizeFull - Size, wc6, 0, wc6.Length);
Data = wc6;
DateTime now = DateTime.Now;
RawDate = SetDate((uint) now.Year, (uint) now.Month, (uint) now.Day);
DateTime now = DateTime.Now;
SetDate((uint) now.Year, (uint) now.Month, (uint) now.Day);
}
if (Year < 2000)
Data = new byte[Data.Length]; // Invalidate
}
public int RestrictLanguage { get; set; } = 0; // None

View File

@ -85,7 +85,7 @@ private uint Day
set => RawDate = SetDate(Year, Month, value);
}
private static uint SetDate(uint year, uint month, uint day) => ((year - 2000) * 10000) + (month * 100) + day;
private static uint SetDate(uint year, uint month, uint day) => Math.Max(0, year - 2000) * 10000 + (month * 100) + day;
/// <summary>
/// Gets or sets the date of the card.