Skip to content

Commit

Permalink
Update 22.06.01
Browse files Browse the repository at this point in the history
  • Loading branch information
kwsch committed Jun 2, 2022
1 parent 2f44d74 commit f2356f1
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 29 deletions.
29 changes: 27 additions & 2 deletions PKHeX.Core/MysteryGifts/WA8.cs
Expand Up @@ -374,6 +374,8 @@ private static int GetOTOffset(int language)
return 0x124 + (index * 0x1C);
}

public bool IsHOMEGift => CardID >= 9000;

public bool CanHandleOT(int language) => !GetHasOT(language);

public override GameVersion Version
Expand Down Expand Up @@ -468,6 +470,10 @@ public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)

pk.MetDate = IsDateRestricted && EncounterServerDate.WA8Gifts.TryGetValue(CardID, out var dt) ? dt.Start : DateTime.Now;

// HOME Gifts for Sinnoh/Hisui starters were forced JPN until May 20, 2022 (UTC).
if (CardID is 9018 or 9019 or 9020)
pk.Met_Day = 20;

var nickname_language = GetLanguage(language);
pk.Language = nickname_language != 0 ? nickname_language : sav.Language;
pk.IsNicknamed = GetIsNicknamed(language);
Expand Down Expand Up @@ -539,9 +545,24 @@ private void SetPINGA(PKM pk, EncounterCriteria criteria)
ShinyType8.Random => Util.Rand32(), // Random, Any
ShinyType8.AlwaysStar => (uint)(((tr.TID ^ tr.SID ^ (PID & 0xFFFF) ^ 1) << 16) | (PID & 0xFFFF)), // Fixed, Force Star
ShinyType8.AlwaysSquare => (uint)(((tr.TID ^ tr.SID ^ (PID & 0xFFFF) ^ 0) << 16) | (PID & 0xFFFF)), // Fixed, Force Square
ShinyType8.FixedValue => PID, // Fixed, Force Value
ShinyType8.FixedValue => GetFixedPID(tr),
_ => throw new ArgumentOutOfRangeException(nameof(type)),
};
private uint GetFixedPID(ITrainerID tr)
{
var pid = PID;
if (!tr.IsShiny(pid, 8))
return pid;
if (IsHOMEGift)
return GetAntishinyFixedHOME(tr);
return pid;
}

private static uint GetAntishinyFixedHOME(ITrainerID tr)
{
var fid = ((uint)(tr.SID << 16) | (uint)tr.TID);
return fid ^ 0x10u;
}

private static uint GetAntishiny(ITrainerID tr)
{
Expand Down Expand Up @@ -600,7 +621,11 @@ public override bool IsMatchExact(PKM pkm, EvoCriteria evo)

var OT = GetOT(pkm.Language); // May not be guaranteed to work.
if (!string.IsNullOrEmpty(OT) && OT != pkm.OT_Name) return false;
if (OriginGame != 0 && OriginGame != pkm.Version) return false;
if (OriginGame != 0 && OriginGame != pkm.Version)
{
if (OriginGame is (int)GameVersion.PLA && !(pkm.Version is (int)GameVersion.SW && pkm.Met_Location == Locations.HOME_SWLA))
return false;
}
if (EncryptionConstant != 0)
{
if (EncryptionConstant != pkm.EncryptionConstant)
Expand Down
64 changes: 44 additions & 20 deletions PKHeX.Core/MysteryGifts/WB8.cs
Expand Up @@ -443,6 +443,8 @@ public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)
Met_Location = MetLocation,
Egg_Location = EggLocation,
};
if (EggLocation == 0)
pk.Egg_Location = Locations.Default8bNone;

if (Species == (int)Core.Species.Manaphy && IsEgg)
{
Expand All @@ -466,7 +468,10 @@ public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)
pk.SID = sav.SID;
}

pk.MetDate = DateTime.Now;
pk.MetDate = IsDateRestricted && EncounterServerDate.WA8Gifts.TryGetValue(CardID, out var dt) ? dt.Start : DateTime.Now;
// HOME Gifts for Sinnoh/Hisui starters were forced JPN until May 20, 2022 (UTC).
if (CardID is 9015 or 9016 or 9017)
pk.Met_Day = 20;

var nickname_language = GetLanguage(language);
pk.Language = nickname_language != 0 ? nickname_language : sav.Language;
Expand Down Expand Up @@ -530,30 +535,43 @@ private void SetPINGA(PKM pk, EncounterCriteria criteria)
_ => AbilityPermission.Any12H,
};

private uint GetPID(ITrainerID tr, byte type)
private uint GetPID(ITrainerID tr, ShinyType8 type) => type switch
{
return type switch
{
0 => GetAntishiny(tr), // Random, Never Shiny
1 => Util.Rand32(), // Random, Any
2 => (uint) (((tr.TID ^ tr.SID ^ (PID & 0xFFFF) ^ 1) << 16) | (PID & 0xFFFF)), // Fixed, Force Star
3 => (uint) (((tr.TID ^ tr.SID ^ (PID & 0xFFFF) ^ 0) << 16) | (PID & 0xFFFF)), // Fixed, Force Square
4 => PID, // Fixed, Force Value
_ => throw new ArgumentOutOfRangeException(nameof(type)),
};
ShinyType8.Never => GetAntishiny(tr), // Random, Never Shiny
ShinyType8.Random => Util.Rand32(), // Random, Any
ShinyType8.AlwaysStar => (uint)(((tr.TID ^ tr.SID ^ (PID & 0xFFFF) ^ 1) << 16) | (PID & 0xFFFF)), // Fixed, Force Star
ShinyType8.AlwaysSquare => (uint)(((tr.TID ^ tr.SID ^ (PID & 0xFFFF) ^ 0) << 16) | (PID & 0xFFFF)), // Fixed, Force Square
ShinyType8.FixedValue => GetFixedPID(tr),
_ => throw new ArgumentOutOfRangeException(nameof(type)),
};

static uint GetAntishiny(ITrainerID tr)
{
var pid = Util.Rand32();
if (tr.IsShiny(pid, 8))
return pid ^ 0x1000_0000;
private uint GetFixedPID(ITrainerID tr)
{
var pid = PID;
if (!tr.IsShiny(pid, 8))
return pid;
}
if (IsHOMEGift)
return GetAntishinyFixedHOME(tr);
return pid;
}

private static uint GetAntishinyFixedHOME(ITrainerID tr)
{
var fid = ((uint)(tr.SID << 16) | (uint)tr.TID);
return fid ^ 0x10u;
}

private static uint GetAntishiny(ITrainerID tr)
{
var pid = Util.Rand32();
if (tr.IsShiny(pid, 8))
return pid ^ 0x1000_0000;
return pid;
}

private void SetPID(PKM pk)
{
pk.PID = GetPID(pk, PIDTypeValue);
pk.PID = GetPID(pk, PIDType);
}

private void SetIVs(PKM pk)
Expand Down Expand Up @@ -600,7 +618,13 @@ public override bool IsMatchExact(PKM pkm, EvoCriteria evo)

var OT = GetOT(pkm.Language); // May not be guaranteed to work.
if (!string.IsNullOrEmpty(OT) && OT != pkm.OT_Name) return false;
if (OriginGame != 0 && OriginGame != pkm.Version) return false;
if (OriginGame != 0 && OriginGame != pkm.Version)
{
if (OriginGame is (int)GameVersion.BD && !(pkm.Version is (int)GameVersion.SW && pkm.Met_Location == Locations.HOME_SWBD))
return false;
if (OriginGame is (int)GameVersion.SP && !(pkm.Version is (int)GameVersion.SH && pkm.Met_Location == Locations.HOME_SHSP))
return false;
}
if (EncryptionConstant != 0)
{
if (EncryptionConstant != pkm.EncryptionConstant)
Expand Down Expand Up @@ -657,7 +681,7 @@ public override bool IsMatchExact(PKM pkm, EvoCriteria evo)
var type = PIDTypeValue;
if (type <= 1)
return true;
return pkm.PID == GetPID(pkm, type);
return pkm.PID == GetPID(pkm, (ShinyType8)type);
}

protected override bool IsMatchEggLocation(PKM pk)
Expand Down
26 changes: 21 additions & 5 deletions PKHeX.Core/MysteryGifts/WC8.cs
Expand Up @@ -83,7 +83,7 @@ public override int Quantity

public override Shiny Shiny => PIDType switch
{
ShinyType8.FixedValue => IsHOMEGift && IsHOMEShinyPossible() ? Shiny.Random : GetShinyXor() switch
ShinyType8.FixedValue => IsHOMEGift && IsHOMEShinyPossible(DateTime.Now) ? Shiny.Random : GetShinyXor() switch
{
0 => Shiny.AlwaysSquare,
<= 15 => Shiny.AlwaysStar,
Expand Down Expand Up @@ -534,10 +534,26 @@ private void SetPINGA(PKM pk, EncounterCriteria criteria)
ShinyType8.Random => Util.Rand32(), // Random, Any
ShinyType8.AlwaysStar => (uint) (((tr.TID ^ tr.SID ^ (PID & 0xFFFF) ^ 1) << 16) | (PID & 0xFFFF)), // Fixed, Force Star
ShinyType8.AlwaysSquare => (uint) (((tr.TID ^ tr.SID ^ (PID & 0xFFFF) ^ 0) << 16) | (PID & 0xFFFF)), // Fixed, Force Square
ShinyType8.FixedValue => PID, // Fixed, Force Value
ShinyType8.FixedValue => GetFixedPID(tr),
_ => throw new ArgumentOutOfRangeException(nameof(type)),
};

private uint GetFixedPID(ITrainerID tr)
{
var pid = PID;
if (!tr.IsShiny(pid, 8))
return pid;
if (IsHOMEGift && !IsHOMEShinyPossible(DateTime.Now))
return GetAntishinyFixedHOME(tr);
return pid;
}

private static uint GetAntishinyFixedHOME(ITrainerID tr)
{
var fid = ((uint)(tr.SID << 16) | (uint)tr.TID);
return fid ^ 0x10u;
}

private static uint GetAntishiny(ITrainerID tr)
{
var pid = Util.Rand32();
Expand Down Expand Up @@ -617,7 +633,7 @@ public override bool IsMatchExact(PKM pkm, EvoCriteria evo)
}
else // Never or Random (HOME ID specific)
{
if (pkm.IsShiny && !IsHOMEShinyPossible())
if (pkm.IsShiny && !IsHOMEShinyPossible(pkm.MetDate ?? DateTime.Now))
return false;
}
}
Expand Down Expand Up @@ -683,10 +699,10 @@ public override bool IsMatchExact(PKM pkm, EvoCriteria evo)
return pkm.PID == GetPID(pkm, type);
}

private bool IsHOMEShinyPossible()
private bool IsHOMEShinyPossible(DateTime date)
{
// no defined TID/SID and having a fixed PID can cause the player's TID/SID to match the PID's shiny calc.
return TID == 0 && SID == 0 && PID != 0;
return TID == 0 && SID == 0 && PID != 0 && (CardID < 9015 && date < new DateTime(2022, 5, 18));
}

public bool IsDateRestricted => IsHOMEGift;
Expand Down
Binary file modified PKHeX.Core/Resources/legality/mgdb/wa8.pkl
Binary file not shown.
Binary file modified PKHeX.Core/Resources/legality/mgdb/wb8.pkl
Binary file not shown.
Binary file modified PKHeX.Core/Resources/legality/mgdb/wc8.pkl
Binary file not shown.
Binary file modified PKHeX.Core/Resources/legality/wild/encounter_go_home.pkl
Binary file not shown.
Binary file modified PKHeX.Core/Resources/legality/wild/encounter_go_lgpe.pkl
Binary file not shown.
2 changes: 1 addition & 1 deletion PKHeX.WinForms/PKHeX.WinForms.csproj
Expand Up @@ -12,7 +12,7 @@
<ApplicationIcon>Resources\icon.ico</ApplicationIcon>
<StartupObject>PKHeX.WinForms.Program</StartupObject>
<AssemblyName>PKHeX</AssemblyName>
<Version>22.05.08</Version>
<Version>22.06.01</Version>
<LangVersion>10</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
23 changes: 22 additions & 1 deletion PKHeX.WinForms/Resources/text/changelog.txt
@@ -1,7 +1,28 @@
PKHeX - By Kaphotics
http://projectpokemon.org/pkhex/

22/05/08 - New Update:
22/06/01 - New Update:
- Legality:
- - Added: HOME 2.0.0 support. Thanks @SciresM, @sora10pls, @Lusamine, & all contributing via the Discord server!
- - Changed: Revises legality checks to account for traveling between the three game islands (PLA/BDSP/SWSH)
- - Changed: Evolution History is now tracked in the Legality parse for specific contexts, rather than by generation only.
- - Fixed: More Gen1/2 tradeback edge cases are handled correctly.
- Added: HOME 2.0.0 conversion mechanisms between the three formats.
- Added: HOME 2.0.0 flexible conversion options to backfill missing data when converting from SW/SH back to PLA/BD/SP.
- Added: HOME 2.0.0 abstractions for HOME data storage format (EKH/PKH format 1, aka EH1/PH1).
- Added: `PKM` now exposes a `Context` to indicate the isolation context for legality purposes.
- Added: Gen8 BDSP misc editor can now unlock Arceus encounter same as Darkrai and Shaymin. Thanks @sora10pls!
- Fixed: Gen5 C-Gear Skins with incorrect file formats (not 32bit argb) show an error dialog rather than crash-erroring.
- Fixed: Gen5 Entree Forest/Misc5 out-of-range values no longer throw an error when the editor opens.
- Fixed: Loading a PKM while viewing an extrabyte index now correctly loads the new extrabyte value.
- Fixed: Gen8 PLA Initial mastery move flags are now suggested correctly for edge cases.
- Fixed: PKM Editor GUI controls now better aligned/sized with similar controls (ex: OT editing).
- Fixed: Drag & Drop now works correctly within the program. Still recommended to use ctrl/shift hotkeys!
- Removed: HaX mode can no longer change Stat_Level separately from Current Level. Set it via the batch editor instead.
- Changed: Enhanced the Gen1/2 Stadium save detection to now detect correctly if no team data has been set.
- Changed: Italian translation improved (GUI+Legality). Thanks @Manu098vm !

22/05/08 - New Update: (94641) [4908732]
- Legality:
- - Added: PLA move mastery/purchased flags are now legality checked thoroughly. Thanks @Lusamine & @Atrius97 !
- - Added: PLA event gifts are now checked for their date obtained.
Expand Down

0 comments on commit f2356f1

Please sign in to comment.