2016-06-20 04:22:43 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.Core
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-10-23 22:45:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generation 4 Mystery Gift Template File
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Big thanks to Grovyle91's Pokémon Mystery Gift Editor, from which the structure was referenced.
|
2018-01-08 19:15:19 +00:00
|
|
|
|
/// https://projectpokemon.org/home/profile/859-grovyle91/
|
|
|
|
|
/// https://projectpokemon.org/home/forums/topic/5870-pok%C3%A9mon-mystery-gift-editor-v143-now-with-bw-support/
|
2017-10-23 22:45:58 +00:00
|
|
|
|
/// See also: http://tccphreak.shiny-clique.net/debugger/pcdfiles.htm
|
|
|
|
|
/// </remarks>
|
2016-07-07 12:44:43 +00:00
|
|
|
|
public sealed class PCD : MysteryGift
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-01-08 07:54:09 +00:00
|
|
|
|
public const int Size = 0x358; // 856
|
2016-09-04 17:38:53 +00:00
|
|
|
|
public override int Format => 4;
|
2016-10-23 19:48:49 +00:00
|
|
|
|
public override int Level
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Gift.Level;
|
|
|
|
|
set => Gift.Level = value;
|
2016-10-23 19:48:49 +00:00
|
|
|
|
}
|
|
|
|
|
public override int Ball
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Gift.Ball;
|
|
|
|
|
set => Gift.Ball = value;
|
2016-10-23 19:48:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public PCD(byte[] data = null)
|
|
|
|
|
{
|
2017-12-27 05:38:19 +00:00
|
|
|
|
Data = data ?? new byte[Size];
|
2017-01-21 05:43:59 +00:00
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2017-01-21 05:43:59 +00:00
|
|
|
|
public PGT Gift
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-09-30 05:40:35 +00:00
|
|
|
|
if (_gift != null)
|
|
|
|
|
return _gift;
|
2017-01-21 05:43:59 +00:00
|
|
|
|
byte[] giftData = new byte[PGT.Size];
|
|
|
|
|
Array.Copy(Data, 0, giftData, 0, PGT.Size);
|
2017-09-30 05:40:35 +00:00
|
|
|
|
return _gift = new PGT(giftData);
|
2017-01-21 05:43:59 +00:00
|
|
|
|
}
|
2017-09-30 05:40:35 +00:00
|
|
|
|
set => (_gift = value)?.Data.CopyTo(Data, 0);
|
2017-01-21 05:43:59 +00:00
|
|
|
|
}
|
2017-09-30 05:40:35 +00:00
|
|
|
|
private PGT _gift;
|
2017-01-21 05:43:59 +00:00
|
|
|
|
public byte[] Information
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var data = new byte[Data.Length - PGT.Size];
|
|
|
|
|
Array.Copy(Data, PGT.Size, data, 0, data.Length);
|
|
|
|
|
return data;
|
|
|
|
|
}
|
2017-05-13 03:32:36 +00:00
|
|
|
|
set => value?.CopyTo(Data, Data.Length - PGT.Size);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2016-10-23 19:48:49 +00:00
|
|
|
|
public override object Content => Gift.PK;
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override bool GiftUsed { get => Gift.GiftUsed; set => Gift.GiftUsed = value; }
|
|
|
|
|
public override bool IsPokémon { get => Gift.IsPokémon; set => Gift.IsPokémon = value; }
|
|
|
|
|
public override bool IsItem { get => Gift.IsItem; set => Gift.IsItem = value; }
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override int ItemID { get => Gift.ItemID; set => Gift.ItemID = value; }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public override int CardID
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => BitConverter.ToUInt16(Data, 0x150);
|
|
|
|
|
set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x150);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
public override string CardTitle
|
|
|
|
|
{
|
2017-08-01 06:03:51 +00:00
|
|
|
|
get => StringConverter.GetString4(Data, 0x104, 0x48);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
2017-08-01 06:03:51 +00:00
|
|
|
|
byte[] data = StringConverter.SetString4(value, 0x48/2-1, 0x48/2, 0xFFFF);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
int len = data.Length;
|
|
|
|
|
Array.Resize(ref data, 0x48);
|
|
|
|
|
for (int i = 0; i < len; i++)
|
|
|
|
|
data[i] = 0xFF;
|
|
|
|
|
data.CopyTo(Data, 0x104);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-18 06:09:00 +00:00
|
|
|
|
public ushort CardCompatibility => BitConverter.ToUInt16(Data, 0x14C); // rest of bytes we don't really care about
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int Species { get => Gift.IsManaphyEgg ? 490 : Gift.Species; set => Gift.Species = value; }
|
|
|
|
|
public override int[] Moves { get => Gift.Moves; set => Gift.Moves = value; }
|
|
|
|
|
public override int HeldItem { get => Gift.HeldItem; set => Gift.HeldItem = value; }
|
2017-01-05 06:25:45 +00:00
|
|
|
|
public override bool IsShiny => Gift.IsShiny;
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override bool IsEgg { get => Gift.IsEgg; set => Gift.IsEgg = value; }
|
2017-11-18 19:34:23 +00:00
|
|
|
|
public override int Gender { get => Gift.Gender; set => Gift.Gender = value; }
|
|
|
|
|
public override int Form { get => Gift.Form; set => Gift.Form = value; }
|
|
|
|
|
public override int TID { get => Gift.TID; set => Gift.TID = value; }
|
|
|
|
|
public override int SID { get => Gift.SID; set => Gift.SID = value; }
|
|
|
|
|
public override string OT_Name { get => Gift.OT_Name; set => Gift.OT_Name = value; }
|
2018-01-02 20:00:41 +00:00
|
|
|
|
public override int Location { get => Gift.Location; set => Gift.Location = value; }
|
|
|
|
|
public override int EggLocation { get => Gift.EggLocation; set => Gift.EggLocation = value; }
|
2016-09-04 17:38:53 +00:00
|
|
|
|
|
2017-01-21 03:35:56 +00:00
|
|
|
|
public bool GiftEquals(PGT pgt)
|
|
|
|
|
{
|
2017-01-21 04:59:50 +00:00
|
|
|
|
// Skip over the PGT's "Corresponding PCD Slot" @ 0x02
|
|
|
|
|
byte[] g = pgt.Data;
|
|
|
|
|
byte[] c = Gift.Data;
|
|
|
|
|
if (g.Length != c.Length || g.Length < 3)
|
|
|
|
|
return false;
|
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
|
if (g[i] != c[i])
|
|
|
|
|
return false;
|
|
|
|
|
for (int i = 3; i < g.Length; i++)
|
|
|
|
|
if (g[i] != c[i])
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
2017-01-21 03:35:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override PKM ConvertToPKM(SaveFile SAV)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return Gift.ConvertToPKM(SAV);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2017-06-18 06:09:00 +00:00
|
|
|
|
|
|
|
|
|
public bool CanBeReceivedBy(int pkmVersion) => (CardCompatibility >> pkmVersion & 1) == 1;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2017-10-23 22:45:58 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generation 4 Mystery Gift Template File (Inner Gift Data, no card data)
|
|
|
|
|
/// </summary>
|
2017-02-04 16:20:59 +00:00
|
|
|
|
public sealed class PGT : MysteryGift
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-03-19 23:19:59 +00:00
|
|
|
|
public const int Size = 0x104; // 260
|
2016-09-04 17:38:53 +00:00
|
|
|
|
public override int Format => 4;
|
2016-10-23 19:48:49 +00:00
|
|
|
|
public override int Level
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => IsPokémon ? PK.Met_Level : 0;
|
2016-10-23 19:48:49 +00:00
|
|
|
|
set { if (IsPokémon) PK.Met_Level = value; }
|
|
|
|
|
}
|
|
|
|
|
public override int Ball
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => IsPokémon ? PK.Ball : 0;
|
2016-10-23 19:48:49 +00:00
|
|
|
|
set { if (IsPokémon) PK.Ball = value; }
|
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
private enum GiftType
|
|
|
|
|
{
|
|
|
|
|
Pokémon = 1,
|
|
|
|
|
PokémonEgg = 2,
|
|
|
|
|
Item = 3,
|
|
|
|
|
Rule = 4,
|
|
|
|
|
Seal = 5,
|
|
|
|
|
Accessory = 6,
|
|
|
|
|
ManaphyEgg = 7,
|
|
|
|
|
MemberCard = 8,
|
|
|
|
|
OaksLetter = 9,
|
|
|
|
|
AzureFlute = 10,
|
|
|
|
|
PokétchApp = 11,
|
|
|
|
|
Ribbon = 12,
|
|
|
|
|
PokéWalkerArea = 14
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override string CardTitle { get => "Raw Gift (PGT)"; set { } }
|
|
|
|
|
public override int CardID { get => -1; set { } }
|
|
|
|
|
public override bool GiftUsed { get => false; set { } }
|
2016-10-23 19:48:49 +00:00
|
|
|
|
public override object Content => PK;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
public PGT(byte[] data = null)
|
|
|
|
|
{
|
2017-12-27 05:38:19 +00:00
|
|
|
|
Data = data ?? new byte[Size];
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public byte CardType { get => Data[0]; set => Data[0] = value; }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
// Unused 0x01
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public byte Slot { get => Data[2]; set => Data[2] = value; }
|
|
|
|
|
public byte Detail { get => Data[3]; set => Data[3] = value; }
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override int ItemID { get => BitConverter.ToUInt16(Data, 0x4); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x4); }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2017-01-21 05:43:59 +00:00
|
|
|
|
public PK4 PK
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-01-21 05:43:59 +00:00
|
|
|
|
get
|
|
|
|
|
{
|
2017-09-30 05:40:35 +00:00
|
|
|
|
if (_pk != null)
|
|
|
|
|
return _pk;
|
2017-01-21 05:43:59 +00:00
|
|
|
|
byte[] ekdata = new byte[PKX.SIZE_4PARTY];
|
|
|
|
|
Array.Copy(Data, 8, ekdata, 0, ekdata.Length);
|
2017-11-07 01:12:59 +00:00
|
|
|
|
return _pk = new PK4(ekdata);
|
2017-01-21 05:43:59 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2017-09-30 05:40:35 +00:00
|
|
|
|
if ((_pk = value) == null)
|
2017-01-21 05:43:59 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2018-03-01 05:05:50 +00:00
|
|
|
|
var pkdata = value.Data.All(z => z == 0)
|
2017-01-21 05:43:59 +00:00
|
|
|
|
? value.Data
|
2017-06-18 01:37:19 +00:00
|
|
|
|
: PKX.EncryptArray45(value.Data);
|
2017-01-21 05:43:59 +00:00
|
|
|
|
pkdata.CopyTo(Data, 8);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-30 05:40:35 +00:00
|
|
|
|
private PK4 _pk;
|
2017-01-21 05:43:59 +00:00
|
|
|
|
|
2017-12-11 18:13:08 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Double checks the encryption of the gift data for Pokemon data.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>True if data was encrypted, false if the data was not modified.</returns>
|
|
|
|
|
public bool VerifyPKEncryption()
|
|
|
|
|
{
|
|
|
|
|
if (!IsPokémon || BitConverter.ToUInt32(Data, 0x64 + 8) != 0)
|
|
|
|
|
return false;
|
|
|
|
|
EncryptPK();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
private void EncryptPK()
|
|
|
|
|
{
|
|
|
|
|
byte[] ekdata = new byte[PKX.SIZE_4PARTY];
|
|
|
|
|
Array.Copy(Data, 8, ekdata, 0, ekdata.Length);
|
2018-02-16 03:07:41 +00:00
|
|
|
|
ekdata = PKX.EncryptArray45(ekdata);
|
2017-12-11 18:13:08 +00:00
|
|
|
|
ekdata.CopyTo(Data, 8);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
private GiftType PGTGiftType { get => (GiftType)Data[0]; set => Data[0] = (byte)value; }
|
2016-08-25 21:44:02 +00:00
|
|
|
|
public bool IsHatched => PGTGiftType == GiftType.Pokémon;
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override bool IsEgg { get => PGTGiftType == GiftType.PokémonEgg; set { if (value) { PGTGiftType = GiftType.PokémonEgg; PK.IsEgg = true; } } }
|
|
|
|
|
public bool IsManaphyEgg { get => PGTGiftType == GiftType.ManaphyEgg; set { if (value) PGTGiftType = GiftType.ManaphyEgg; } }
|
Gen 1 move analysis improvement. Adapted the valid moves to take into account that move deleter and move reminder do not exits in generation 1 (#1037)
* Fix getMoves with min level, when SkipWhile and TakeWhile is used together the index i in TakeWhile is calculated from the enumerator that results of the SkipWhile function, not the index of the initial array, those giving an incorrect index to check Levels array in the TakeWhile
* Fix getMoves when levelmin or levelmax is above max level in the levels array, TakeWhile and SkipWhile return empty list if the while goes beyond the last element of the array
* Include player hatched egg in the list of possible encounters for parseMoves only if the pokemon was an egg
Also change the valur of WasEgg for gen1,2,3 pokemon if the encounter analyzed is not an egg
add the non egg encounters to the list instead of checking the non-egg encounter inside parseMovesWasEggPreRelearn
* Fix for gen3 egg encounters
Remove non-egg encounters without special moves if there is an egg encounter because egg encounter already cover every possible move combination
Do not add daycare egg encounter for gen3 unhatched egg if there is another encounter, that means is an event or gift egg, not a daycare egg
Remove duplicate encounters
* Gift egg should not allow inherited moves even it they dont have special moves
Those gift eggs are hatched only with the species base moves
* Added getEncounterMoves functions, to be used for generation 1 encounters to find what moves have a pokemon at the moment of being caught because there is no move reminder in generation 1
* Added GBEncounterData, structure for refactor the tuples used in generation 1 and 2 encounters
* Add LevelMin and LevelMax to IEncounterable to get the encounter moves by the min level of the generation 1 EncounterLink
Add iGeneration to difference generation 1 and generation 2 encounters for GB Era pokemon
* Mark generation in gen 1 and 2 encounters
There is no need to mark the generation in gen 3 to 7 encounters because in that generations it match the pokemon generation number
* Add min level for generation 1 moves in getMoves functions
Add function to return the default moves for a GB encounters, for generation 1 games that included both moves from level up table and level 1 moves from personal table
Fix getMoves with min level when the moves list is empty, like Raichu generation 1
* Add maxSpecies to getBaseSpecies function for gen1 pokemon with a gen2 egg encounter
Refactor VC Encounter changing Tuples for GBData class
* Fixed for gen 2 Checks
Also do not search for generation1 encounter if the gen2 pokemon have met location from crystal
* Fix VC wild encounters, should be stored as array or else other verifyEncounter functions wont work
* Add generation 1 parse moves function including default moves
* Clean-up get encounters
* Verify empty moves for generation 1 encounters, in generation 1 does not exits move deleter
That means when a move slot have been used by a level up move or a TM/HM/Tutor move it cant be empty again
Does not apply if generation 2 tradeback is allowed, in generation 2 there is a move deleter
* Added two edge cases for pokemon that learn in red/blue and yellow different moves at the same level, this combinations can not exits until a later level when they learn again one of the levels in the other game, only happen for flareon and vaporeon
* Check incompatible moves between evolution species, it is for species that learn a move in a level as an evolved species and a move at a upper level as a preevolution
Also added most edge cases for the min slots used for generation 1 games, i think every weird combination is already covered
* Fix gen 1 eevee and evolutions move checks
* Cleanup
* Move the code to change valid moves for generation 1 to a function
* Fix getMoveMinLevelGBEncounter
* getUsedMoveSlots, removed wild Butterfree edge case, it is not possible
* Filter the min level of the encounter by the possible games the pokemon could be originated, yellow pikachu and kadabra can be detected
2017-04-09 00:17:20 +00:00
|
|
|
|
public override bool EggEncounter => IsEgg || IsManaphyEgg;
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override bool IsItem { get => PGTGiftType == GiftType.Item; set { if (value) PGTGiftType = GiftType.Item; } }
|
|
|
|
|
public override bool IsPokémon { get => PGTGiftType == GiftType.Pokémon || PGTGiftType == GiftType.PokémonEgg || PGTGiftType == GiftType.ManaphyEgg; set { } }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int Species { get => IsManaphyEgg ? 490 : PK.Species; set => PK.Species = value; }
|
|
|
|
|
public override int[] Moves { get => PK.Moves; set => PK.Moves = value; }
|
|
|
|
|
public override int HeldItem { get => PK.HeldItem; set => PK.HeldItem = value; }
|
2016-09-04 17:38:53 +00:00
|
|
|
|
public override bool IsShiny => PK.IsShiny;
|
2017-11-18 19:34:23 +00:00
|
|
|
|
public override int Gender { get => PK.Gender; set => PK.Gender = value; }
|
|
|
|
|
public override int Form { get => PK.AltForm; set => PK.AltForm = value; }
|
|
|
|
|
public override int TID { get => (ushort)PK.TID; set => PK.TID = value; }
|
|
|
|
|
public override int SID { get => (ushort)PK.SID; set => PK.SID = value; }
|
|
|
|
|
public override string OT_Name { get => PK.OT_Name; set => PK.OT_Name = value; }
|
2018-01-02 20:00:41 +00:00
|
|
|
|
public override int Location { get => PK.Met_Location; set => PK.Met_Location = value; }
|
|
|
|
|
public override int EggLocation { get => PK.Egg_Location; set => PK.Egg_Location = value; }
|
2016-09-04 17:38:53 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override PKM ConvertToPKM(SaveFile SAV)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
if (!IsPokémon)
|
|
|
|
|
return null;
|
|
|
|
|
|
2018-02-12 01:28:23 +00:00
|
|
|
|
PK4 pk4 = new PK4((byte[])PK.Data.Clone()) {Sanity = 0};
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (!IsHatched && Detail == 0)
|
|
|
|
|
{
|
|
|
|
|
pk4.OT_Name = SAV.OT;
|
|
|
|
|
pk4.TID = SAV.TID;
|
|
|
|
|
pk4.SID = SAV.SID;
|
|
|
|
|
pk4.OT_Gender = SAV.Gender;
|
2017-03-24 06:15:49 +00:00
|
|
|
|
pk4.Language = SAV.Language;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
if (IsManaphyEgg)
|
|
|
|
|
{
|
|
|
|
|
// Since none of this data is populated, fill in default info.
|
|
|
|
|
pk4.Species = 490;
|
|
|
|
|
// Level 1 Moves
|
|
|
|
|
pk4.Move1 = 294;
|
|
|
|
|
pk4.Move2 = 145;
|
|
|
|
|
pk4.Move3 = 346;
|
2017-03-24 06:15:49 +00:00
|
|
|
|
pk4.Ability = pk4.PersonalInfo.Abilities[0];
|
2016-06-20 04:22:43 +00:00
|
|
|
|
pk4.FatefulEncounter = true;
|
|
|
|
|
pk4.Ball = 4;
|
|
|
|
|
pk4.Version = 10; // Diamond
|
2017-10-23 04:01:08 +00:00
|
|
|
|
pk4.Language = (int)LanguageID.English; // English
|
2016-06-20 04:22:43 +00:00
|
|
|
|
pk4.Nickname = "MANAPHY";
|
|
|
|
|
pk4.Egg_Location = 1; // Ranger (will be +3000 later)
|
2017-07-14 04:05:20 +00:00
|
|
|
|
pk4.Move1_PP = pk4.GetMovePP(pk4.Move1, 0);
|
|
|
|
|
pk4.Move2_PP = pk4.GetMovePP(pk4.Move2, 0);
|
|
|
|
|
pk4.Move3_PP = pk4.GetMovePP(pk4.Move3, 0);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Generate IV
|
2017-06-18 01:37:19 +00:00
|
|
|
|
uint seed = Util.Rand32();
|
2017-03-24 06:15:49 +00:00
|
|
|
|
if (pk4.PID == 1) // Create Nonshiny
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
uint pid1 = PKX.LCRNG(ref seed) >> 16;
|
|
|
|
|
uint pid2 = PKX.LCRNG(ref seed) >> 16;
|
|
|
|
|
|
|
|
|
|
while ((pid1 ^ pid2 ^ pk4.TID ^ pk4.SID) < 8)
|
|
|
|
|
{
|
|
|
|
|
uint testPID = pid1 | pid2 << 16;
|
|
|
|
|
|
|
|
|
|
// Call the ARNG to change the PID
|
2017-06-16 01:34:03 +00:00
|
|
|
|
testPID = RNG.ARNG.Next(testPID);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
pid1 = testPID & 0xFFFF;
|
|
|
|
|
pid2 = testPID >> 16;
|
|
|
|
|
}
|
|
|
|
|
pk4.PID = pid1 | (pid2 << 16);
|
|
|
|
|
}
|
2017-06-16 01:34:03 +00:00
|
|
|
|
if (!IsManaphyEgg)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
seed = Util.Rand32(); // reseed, do not have method 1 correlation
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
// Generate IVs
|
|
|
|
|
if (pk4.IV32 == 0)
|
|
|
|
|
{
|
2017-06-16 01:34:03 +00:00
|
|
|
|
uint iv1 = (PKX.LCRNG(ref seed) >> 16) & 0x7FFF;
|
|
|
|
|
uint iv2 = (PKX.LCRNG(ref seed) >> 16) & 0x7FFF;
|
|
|
|
|
pk4.IV32 = iv1 | iv2 << 15;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Generate Met Info
|
2017-03-24 06:15:49 +00:00
|
|
|
|
if (!IsEgg && !IsManaphyEgg)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
pk4.Met_Location = pk4.Egg_Location + 3000;
|
|
|
|
|
pk4.Egg_Location = 0;
|
2016-08-10 14:02:31 +00:00
|
|
|
|
pk4.MetDate = DateTime.Now;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
pk4.IsEgg = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-07-14 04:05:20 +00:00
|
|
|
|
pk4.Egg_Location = pk4.Egg_Location + 3000;
|
2017-03-24 06:15:49 +00:00
|
|
|
|
if (SAV.Generation == 4)
|
|
|
|
|
{
|
|
|
|
|
pk4.IsEgg = true;
|
2017-07-14 04:05:20 +00:00
|
|
|
|
pk4.IsNicknamed = false;
|
2017-06-21 05:53:39 +00:00
|
|
|
|
pk4.Nickname = PKX.GetSpeciesNameGeneration(0, pk4.Language, Format);
|
2017-03-24 06:15:49 +00:00
|
|
|
|
pk4.MetDate = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pk4.IsEgg = false;
|
|
|
|
|
// Met Location is modified when transferred to pk5; don't worry about it.
|
|
|
|
|
pk4.EggMetDate = DateTime.Now;
|
|
|
|
|
}
|
2017-07-14 04:05:20 +00:00
|
|
|
|
while (pk4.IsShiny)
|
|
|
|
|
pk4.PID = RNG.ARNG.Next(pk4.PID);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2017-09-30 05:40:35 +00:00
|
|
|
|
var pi = pk4.PersonalInfo;
|
2017-07-14 04:05:20 +00:00
|
|
|
|
pk4.CurrentFriendship = pk4.IsEgg ? pi.HatchCycles : pi.BaseFriendship;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (pk4.Species == 201) // Never will be true; Unown was never distributed.
|
2017-06-18 01:37:19 +00:00
|
|
|
|
pk4.AltForm = PKX.GetUnownForm(pk4.PID);
|
2016-07-28 23:30:48 +00:00
|
|
|
|
|
|
|
|
|
pk4.RefreshChecksum();
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return pk4;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|