2018-04-29 05:56:10 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
2017-07-16 01:36:55 +00:00
|
|
|
|
{
|
|
|
|
|
public static class PIDGenerator
|
|
|
|
|
{
|
|
|
|
|
private static void SetValuesFromSeedLCRNG(PKM pk, PIDType type, uint seed)
|
|
|
|
|
{
|
|
|
|
|
var rng = RNG.LCRNG;
|
|
|
|
|
var A = rng.Next(seed);
|
|
|
|
|
var B = rng.Next(A);
|
2018-08-03 03:11:42 +00:00
|
|
|
|
var pid = (B & 0xFFFF0000) | A >> 16;
|
2018-05-09 03:13:55 +00:00
|
|
|
|
if (type == PIDType.Method_1_Unown || type == PIDType.Method_2_Unown || type == PIDType.Method_4_Unown)
|
|
|
|
|
pk.PID = (pid >> 16) | (pid << 16); // swap halves
|
|
|
|
|
else
|
|
|
|
|
pk.PID = pid;
|
2017-07-16 01:36:55 +00:00
|
|
|
|
|
|
|
|
|
var skipIV1Frame = type == PIDType.Method_2 || type == PIDType.Method_2_Unown;
|
|
|
|
|
if (skipIV1Frame)
|
|
|
|
|
B = rng.Next(B);
|
|
|
|
|
var C = rng.Next(B);
|
|
|
|
|
var D = rng.Next(C);
|
|
|
|
|
|
|
|
|
|
var skipIV2Frame = type == PIDType.Method_4 || type == PIDType.Method_4_Unown;
|
|
|
|
|
if (skipIV2Frame)
|
|
|
|
|
D = rng.Next(D);
|
|
|
|
|
|
2018-04-29 05:56:10 +00:00
|
|
|
|
var IVs = MethodFinder.GetIVsInt32(C >> 16, D >> 16);
|
|
|
|
|
if (type == PIDType.Method_1_Roamer)
|
|
|
|
|
{
|
|
|
|
|
IVs[1] &= 7;
|
|
|
|
|
for (int i = 2; i < 6; i++)
|
|
|
|
|
IVs[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
pk.IVs = IVs;
|
2017-07-16 01:36:55 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-07-16 01:36:55 +00:00
|
|
|
|
private static void SetValuesFromSeedBACD(PKM pk, PIDType type, uint seed)
|
|
|
|
|
{
|
|
|
|
|
var rng = RNG.LCRNG;
|
|
|
|
|
bool shiny = type == PIDType.BACD_R_S || type == PIDType.BACD_U_S;
|
|
|
|
|
uint X = shiny ? rng.Next(seed) : seed;
|
|
|
|
|
var A = rng.Next(X);
|
|
|
|
|
var B = rng.Next(A);
|
|
|
|
|
var C = rng.Next(B);
|
|
|
|
|
var D = rng.Next(C);
|
|
|
|
|
|
|
|
|
|
if (shiny)
|
|
|
|
|
{
|
2018-08-03 03:11:42 +00:00
|
|
|
|
uint PID = (X & 0xFFFF0000) | ((uint)pk.SID ^ (uint)pk.TID ^ X >> 16);
|
2017-07-16 01:36:55 +00:00
|
|
|
|
PID &= 0xFFFFFFF8;
|
|
|
|
|
PID |= B >> 16 & 0x7; // lowest 3 bits
|
|
|
|
|
|
|
|
|
|
pk.PID = PID;
|
|
|
|
|
}
|
2017-09-12 07:27:16 +00:00
|
|
|
|
else if (type == PIDType.BACD_R_AX || type == PIDType.BACD_U_AX)
|
|
|
|
|
{
|
|
|
|
|
uint low = B >> 16;
|
2018-08-03 03:11:42 +00:00
|
|
|
|
pk.PID = ((A & 0xFFFF0000) ^ (((uint)pk.TID ^ (uint)pk.SID ^ low) << 16)) | low;
|
2017-09-12 07:27:16 +00:00
|
|
|
|
}
|
2017-07-16 01:36:55 +00:00
|
|
|
|
else
|
2018-08-03 03:11:42 +00:00
|
|
|
|
{
|
|
|
|
|
pk.PID = (A & 0xFFFF0000) | B >> 16;
|
|
|
|
|
}
|
2017-07-16 01:36:55 +00:00
|
|
|
|
|
|
|
|
|
pk.IVs = MethodFinder.GetIVsInt32(C >> 16, D >> 16);
|
|
|
|
|
|
|
|
|
|
bool antishiny = type == PIDType.BACD_R_A || type == PIDType.BACD_U_A;
|
|
|
|
|
while (antishiny && pk.IsShiny)
|
|
|
|
|
pk.PID = unchecked(pk.PID + 1);
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-07-16 01:36:55 +00:00
|
|
|
|
private static void SetValuesFromSeedXDRNG(PKM pk, uint seed)
|
|
|
|
|
{
|
|
|
|
|
var rng = RNG.XDRNG;
|
2018-05-08 04:16:54 +00:00
|
|
|
|
switch (pk.Species)
|
|
|
|
|
{
|
2019-06-01 17:22:49 +00:00
|
|
|
|
case (int)Species.Umbreon: // Colo Umbreon
|
|
|
|
|
case (int)Species.Eevee: // XD Eevee
|
2018-05-08 04:16:54 +00:00
|
|
|
|
pk.TID = (int)((seed = rng.Next(seed)) >> 16);
|
|
|
|
|
pk.SID = (int)((seed = rng.Next(seed)) >> 16);
|
|
|
|
|
seed = rng.Advance(seed, 2); // PID calls consumed
|
|
|
|
|
break;
|
2019-06-01 17:22:49 +00:00
|
|
|
|
case (int)Species.Espeon: // Colo Espeon
|
2018-05-08 04:16:54 +00:00
|
|
|
|
pk.TID = (int)((seed = rng.Next(seed)) >> 16);
|
|
|
|
|
pk.SID = (int)((seed = rng.Next(seed)) >> 16);
|
2018-05-09 03:13:55 +00:00
|
|
|
|
seed = rng.Advance(seed, 9); // PID calls consumed, skip over Umbreon
|
2018-05-08 04:16:54 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2017-07-16 01:36:55 +00:00
|
|
|
|
var A = rng.Next(seed); // IV1
|
|
|
|
|
var B = rng.Next(A); // IV2
|
|
|
|
|
var C = rng.Next(B); // Ability?
|
|
|
|
|
var D = rng.Next(C); // PID
|
|
|
|
|
var E = rng.Next(D); // PID
|
|
|
|
|
|
2018-08-03 03:11:42 +00:00
|
|
|
|
pk.PID = (D & 0xFFFF0000) | E >> 16;
|
2017-07-16 01:36:55 +00:00
|
|
|
|
pk.IVs = MethodFinder.GetIVsInt32(A >> 16, B >> 16);
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-07-16 01:36:55 +00:00
|
|
|
|
private static void SetValuesFromSeedChannel(PKM pk, uint seed)
|
|
|
|
|
{
|
|
|
|
|
var rng = RNG.XDRNG;
|
|
|
|
|
var O = rng.Next(seed); // SID
|
|
|
|
|
var A = rng.Next(O); // PID
|
|
|
|
|
var B = rng.Next(A); // PID
|
|
|
|
|
var C = rng.Next(B); // Held Item
|
|
|
|
|
var D = rng.Next(C); // Version
|
|
|
|
|
var E = rng.Next(D); // OT Gender
|
|
|
|
|
|
2018-05-12 19:28:48 +00:00
|
|
|
|
const int TID = 40122;
|
2017-07-16 02:59:38 +00:00
|
|
|
|
var SID = (int)(O >> 16);
|
|
|
|
|
var pid1 = A >> 16;
|
|
|
|
|
var pid2 = B >> 16;
|
|
|
|
|
pk.TID = TID;
|
|
|
|
|
pk.SID = SID;
|
|
|
|
|
var pid = pid1 << 16 | pid2;
|
|
|
|
|
if ((pid2 > 7 ? 0 : 1) != (pid1 ^ SID ^ TID))
|
|
|
|
|
pid ^= 0x80000000;
|
|
|
|
|
pk.PID = pid;
|
2017-07-16 01:36:55 +00:00
|
|
|
|
pk.HeldItem = (int)(C >> 31) + 169; // 0-Ganlon, 1-Salac
|
|
|
|
|
pk.Version = (int)(D >> 31) + 1; // 0-Sapphire, 1-Ruby
|
|
|
|
|
pk.OT_Gender = (int)(E >> 31);
|
|
|
|
|
pk.IVs = rng.GetSequentialIVsInt32(E);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void SetValuesFromSeed(PKM pk, PIDType type, uint seed)
|
|
|
|
|
{
|
2018-04-29 16:31:13 +00:00
|
|
|
|
var method = GetGeneratorMethod(type);
|
|
|
|
|
method(pk, seed);
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2018-04-29 16:31:13 +00:00
|
|
|
|
private static Action<PKM, uint> GetGeneratorMethod(PIDType t)
|
|
|
|
|
{
|
|
|
|
|
switch (t)
|
2017-07-16 01:36:55 +00:00
|
|
|
|
{
|
|
|
|
|
case PIDType.Channel:
|
2018-04-29 16:31:13 +00:00
|
|
|
|
return SetValuesFromSeedChannel;
|
2017-07-16 01:36:55 +00:00
|
|
|
|
case PIDType.CXD:
|
2018-04-29 16:31:13 +00:00
|
|
|
|
return SetValuesFromSeedXDRNG;
|
2017-07-16 01:36:55 +00:00
|
|
|
|
|
|
|
|
|
case PIDType.Method_1:
|
|
|
|
|
case PIDType.Method_2:
|
|
|
|
|
case PIDType.Method_4:
|
2018-04-29 16:31:13 +00:00
|
|
|
|
case PIDType.Method_1_Unown:
|
|
|
|
|
case PIDType.Method_2_Unown:
|
|
|
|
|
case PIDType.Method_4_Unown:
|
|
|
|
|
case PIDType.Method_1_Roamer:
|
|
|
|
|
return (pk, seed) => SetValuesFromSeedLCRNG(pk, t, seed);
|
2017-07-16 01:36:55 +00:00
|
|
|
|
|
|
|
|
|
case PIDType.BACD_R:
|
|
|
|
|
case PIDType.BACD_R_A:
|
|
|
|
|
case PIDType.BACD_R_S:
|
2018-04-29 16:31:13 +00:00
|
|
|
|
return (pk, seed) => SetValuesFromSeedBACD(pk, t, seed & 0xFFFF);
|
2017-07-16 01:36:55 +00:00
|
|
|
|
case PIDType.BACD_U:
|
|
|
|
|
case PIDType.BACD_U_A:
|
|
|
|
|
case PIDType.BACD_U_S:
|
2018-04-29 16:31:13 +00:00
|
|
|
|
return (pk, seed) => SetValuesFromSeedBACD(pk, t, seed);
|
2017-07-16 01:36:55 +00:00
|
|
|
|
|
2018-04-29 16:31:13 +00:00
|
|
|
|
case PIDType.PokeSpot:
|
|
|
|
|
return SetRandomPIDIV;
|
2017-07-16 01:36:55 +00:00
|
|
|
|
|
2018-04-29 18:33:35 +00:00
|
|
|
|
case PIDType.G5MGShiny:
|
|
|
|
|
return SetValuesFromSeedMG5Shiny;
|
|
|
|
|
|
|
|
|
|
case PIDType.Pokewalker:
|
|
|
|
|
return (pk, seed) => pk.PID = GetPokeWalkerPID(pk.TID, pk.SID, seed%24, pk.Gender, pk.PersonalInfo.Gender);
|
|
|
|
|
|
2018-04-29 16:31:13 +00:00
|
|
|
|
// others: unimplemented
|
2017-07-16 01:36:55 +00:00
|
|
|
|
case PIDType.CuteCharm:
|
|
|
|
|
break;
|
2018-04-29 16:31:13 +00:00
|
|
|
|
case PIDType.ChainShiny:
|
2018-05-08 04:16:54 +00:00
|
|
|
|
return SetRandomChainShinyPID;
|
2017-07-16 01:36:55 +00:00
|
|
|
|
case PIDType.G4MGAntiShiny:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
return (_, __) => { };
|
2017-07-16 01:36:55 +00:00
|
|
|
|
}
|
2017-09-17 21:43:28 +00:00
|
|
|
|
|
2018-05-08 04:16:54 +00:00
|
|
|
|
public static void SetRandomChainShinyPID(PKM pk, uint seed)
|
|
|
|
|
{
|
|
|
|
|
// 13 rand bits
|
|
|
|
|
// 1 3-bit for upper
|
|
|
|
|
// 1 3-bit for lower
|
|
|
|
|
|
|
|
|
|
uint Next() => (seed = RNG.LCRNG.Next(seed)) >> 16;
|
|
|
|
|
uint lower = Next() & 7;
|
|
|
|
|
uint upper = Next() & 7;
|
|
|
|
|
for (int i = 0; i < 13; i++)
|
|
|
|
|
lower |= (Next() & 1) << (3 + i);
|
|
|
|
|
|
2018-08-03 03:11:42 +00:00
|
|
|
|
upper = ((uint)(lower ^ pk.TID ^ pk.SID) & 0xFFF8) | (upper & 0x7);
|
2018-05-08 04:16:54 +00:00
|
|
|
|
pk.PID = upper << 16 | lower;
|
|
|
|
|
pk.IVs = MethodFinder.GetIVsInt32(Next(), Next());
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-30 01:26:36 +00:00
|
|
|
|
public static void SetRandomPokeSpotPID(PKM pk, int nature, int gender, int ability, int slot)
|
|
|
|
|
{
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
var seed = Util.Rand32();
|
|
|
|
|
if (!MethodFinder.IsPokeSpotActivation(slot, seed, out var _))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
var rng = RNG.XDRNG;
|
|
|
|
|
var D = rng.Next(seed); // PID
|
|
|
|
|
var E = rng.Next(D); // PID
|
|
|
|
|
|
2018-08-03 03:11:42 +00:00
|
|
|
|
pk.PID = (D & 0xFFFF0000) | E >> 16;
|
2018-04-30 01:26:36 +00:00
|
|
|
|
if (!IsValidCriteria4(pk, nature, ability, gender))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
pk.SetRandomIVs();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-17 21:43:28 +00:00
|
|
|
|
public static uint GetMG5ShinyPID(uint gval, uint av, int TID, int SID)
|
|
|
|
|
{
|
|
|
|
|
uint PID = (uint)((TID ^ SID ^ gval) << 16 | gval);
|
|
|
|
|
if ((PID & 0x10000) != av << 16)
|
|
|
|
|
PID ^= 0x10000;
|
|
|
|
|
return PID;
|
|
|
|
|
}
|
2018-04-29 05:56:10 +00:00
|
|
|
|
|
2018-04-29 18:33:35 +00:00
|
|
|
|
public static uint GetPokeWalkerPID(int TID, int SID, uint nature, int gender, int gr)
|
|
|
|
|
{
|
|
|
|
|
if (nature >= 24)
|
|
|
|
|
nature = 0;
|
|
|
|
|
uint pid = (uint)((TID ^ SID) >> 8 ^ 0xFF) << 24; // the most significant byte of the PID is chosen so the Pokémon can never be shiny.
|
|
|
|
|
// Ensure nature is set to required nature without affecting shininess
|
2018-08-03 03:11:42 +00:00
|
|
|
|
pid += nature - (pid % 25);
|
2018-04-29 18:33:35 +00:00
|
|
|
|
|
2019-01-02 04:04:29 +00:00
|
|
|
|
if (gr >= 0xFE || gr == 0) // non-dual gender
|
|
|
|
|
return pid;
|
|
|
|
|
|
2018-04-29 18:33:35 +00:00
|
|
|
|
// Ensure Gender is set to required gender without affecting other properties
|
|
|
|
|
// If Gender is modified, modify the ability if appropriate
|
2018-04-30 01:26:36 +00:00
|
|
|
|
|
|
|
|
|
// either m/f
|
|
|
|
|
var pidGender = (pid & 0xFF) < gr ? 1 : 0;
|
2019-01-02 04:04:29 +00:00
|
|
|
|
if (gender == pidGender)
|
2018-04-30 01:26:36 +00:00
|
|
|
|
return pid;
|
|
|
|
|
|
2019-01-02 04:04:29 +00:00
|
|
|
|
if (gender == 0) // Male
|
2018-04-29 18:33:35 +00:00
|
|
|
|
{
|
2018-08-03 03:11:42 +00:00
|
|
|
|
pid += (uint)((((gr - (pid & 0xFF)) / 25) + 1) * 25);
|
2018-04-30 01:26:36 +00:00
|
|
|
|
if ((nature & 1) != (pid & 1))
|
|
|
|
|
pid += 25;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-08-03 03:11:42 +00:00
|
|
|
|
pid -= (uint)(((((pid & 0xFF) - gr) / 25) + 1) * 25);
|
2018-04-30 01:26:36 +00:00
|
|
|
|
if ((nature & 1) != (pid & 1))
|
|
|
|
|
pid -= 25;
|
2018-04-29 18:33:35 +00:00
|
|
|
|
}
|
|
|
|
|
return pid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void SetValuesFromSeedMG5Shiny(PKM pk, uint seed)
|
|
|
|
|
{
|
|
|
|
|
var gv = seed >> 24;
|
|
|
|
|
var av = seed & 1;
|
|
|
|
|
pk.PID = GetMG5ShinyPID(gv, av, pk.TID, pk.SID);
|
|
|
|
|
SetRandomIVs(pk);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-29 16:31:13 +00:00
|
|
|
|
public static void SetRandomWildPID(PKM pk, int gen, int nature, int ability, int gender, PIDType specific = PIDType.None)
|
2018-04-29 05:56:10 +00:00
|
|
|
|
{
|
2018-04-29 18:33:35 +00:00
|
|
|
|
if (specific == PIDType.Pokewalker)
|
|
|
|
|
{
|
|
|
|
|
pk.Gender = gender;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
pk.PID = GetPokeWalkerPID(pk.TID, pk.SID, (uint) nature, gender, pk.PersonalInfo.Gender);
|
|
|
|
|
} while (!pk.IsGenderValid());
|
|
|
|
|
pk.RefreshAbility((int)(pk.PID & 1));
|
|
|
|
|
SetRandomIVs(pk);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-04-29 05:56:10 +00:00
|
|
|
|
switch (gen)
|
|
|
|
|
{
|
|
|
|
|
case 3:
|
|
|
|
|
case 4:
|
2018-04-29 16:31:13 +00:00
|
|
|
|
SetRandomWildPID4(pk, nature, ability, gender, specific);
|
2018-04-29 05:56:10 +00:00
|
|
|
|
break;
|
|
|
|
|
case 5:
|
2018-05-08 04:16:54 +00:00
|
|
|
|
SetRandomWildPID5(pk, nature, ability, gender, specific);
|
2018-04-29 05:56:10 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
SetRandomWildPID(pk, nature, ability, gender);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-29 16:31:13 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generates a <see cref="PKM.PID"/> and <see cref="PKM.IVs"/> that are unrelated.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pkm">Pokémon to modify.</param>
|
|
|
|
|
/// <param name="seed">Seed which is used for the <see cref="PKM.PID"/>.</param>
|
|
|
|
|
private static void SetRandomPIDIV(PKM pkm, uint seed)
|
|
|
|
|
{
|
|
|
|
|
pkm.PID = seed;
|
|
|
|
|
SetRandomIVs(pkm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void SetRandomWildPID4(PKM pk, int nature, int ability, int gender, PIDType specific = PIDType.None)
|
2018-04-29 05:56:10 +00:00
|
|
|
|
{
|
|
|
|
|
pk.RefreshAbility(ability);
|
2018-04-30 04:56:12 +00:00
|
|
|
|
pk.Gender = gender;
|
2018-04-29 16:31:13 +00:00
|
|
|
|
var type = GetPIDType(pk, specific);
|
|
|
|
|
var method = GetGeneratorMethod(type);
|
|
|
|
|
|
2018-04-29 05:56:10 +00:00
|
|
|
|
while (true)
|
|
|
|
|
{
|
2018-04-29 16:31:13 +00:00
|
|
|
|
method(pk, Util.Rand32());
|
2018-04-30 01:26:36 +00:00
|
|
|
|
if (!IsValidCriteria4(pk, nature, ability, gender))
|
2018-04-29 05:56:10 +00:00
|
|
|
|
continue;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-30 01:26:36 +00:00
|
|
|
|
private static bool IsValidCriteria4(PKM pk, int nature, int ability, int gender)
|
|
|
|
|
{
|
2018-05-10 00:50:56 +00:00
|
|
|
|
if (pk.GetSaneGender() != gender)
|
2018-04-30 01:26:36 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (pk.Nature != nature)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if ((pk.PID & 1) != ability)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-29 16:31:13 +00:00
|
|
|
|
private static PIDType GetPIDType(PKM pk, PIDType specific)
|
2018-04-29 05:56:10 +00:00
|
|
|
|
{
|
2018-04-29 16:31:13 +00:00
|
|
|
|
if (specific != PIDType.None)
|
|
|
|
|
return specific;
|
2018-04-29 05:56:10 +00:00
|
|
|
|
if (pk.Version == 15)
|
|
|
|
|
return PIDType.CXD;
|
2019-02-22 04:41:04 +00:00
|
|
|
|
if (pk.Gen3 && pk.Species == 201)
|
2018-10-28 04:59:31 +00:00
|
|
|
|
return PIDType.Method_1_Unown + Util.Rand.Next(3);
|
2018-04-29 05:56:10 +00:00
|
|
|
|
|
|
|
|
|
return PIDType.Method_1;
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2018-05-08 04:16:54 +00:00
|
|
|
|
private static void SetRandomWildPID5(PKM pk, int nature, int ability, int gender, PIDType specific = PIDType.None)
|
2018-04-29 05:56:10 +00:00
|
|
|
|
{
|
|
|
|
|
var tidbit = (pk.TID ^ pk.SID) & 1;
|
|
|
|
|
pk.RefreshAbility(ability);
|
|
|
|
|
pk.Gender = gender;
|
|
|
|
|
pk.Nature = nature;
|
|
|
|
|
|
|
|
|
|
if (ability == 2)
|
|
|
|
|
ability = 0;
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
uint seed = Util.Rand32();
|
2018-05-08 04:16:54 +00:00
|
|
|
|
if (specific == PIDType.G5MGShiny)
|
|
|
|
|
{
|
|
|
|
|
SetValuesFromSeedMG5Shiny(pk, seed);
|
|
|
|
|
seed = pk.PID;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var bitxor = (seed >> 31) ^ (seed & 1);
|
|
|
|
|
if (bitxor != tidbit)
|
|
|
|
|
seed ^= 1;
|
|
|
|
|
}
|
2018-04-29 05:56:10 +00:00
|
|
|
|
|
|
|
|
|
if (seed % 25 != nature)
|
|
|
|
|
continue;
|
|
|
|
|
if (((seed >> 16) & 1) != ability)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
pk.PID = seed;
|
2018-05-10 00:50:56 +00:00
|
|
|
|
if (pk.GetSaneGender() != gender)
|
2018-04-29 05:56:10 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
SetRandomIVs(pk);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void SetRandomWildPID(PKM pk, int nature, int ability, int gender)
|
|
|
|
|
{
|
|
|
|
|
uint seed = Util.Rand32();
|
|
|
|
|
pk.PID = seed;
|
|
|
|
|
pk.Nature = nature;
|
|
|
|
|
pk.Gender = gender;
|
|
|
|
|
pk.RefreshAbility(ability);
|
|
|
|
|
SetRandomIVs(pk);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void SetRandomIVs(PKM pk)
|
|
|
|
|
{
|
|
|
|
|
pk.IVs = new[]
|
|
|
|
|
{
|
|
|
|
|
Util.Rand.Next(32),
|
|
|
|
|
Util.Rand.Next(32),
|
|
|
|
|
Util.Rand.Next(32),
|
|
|
|
|
Util.Rand.Next(32),
|
|
|
|
|
Util.Rand.Next(32),
|
|
|
|
|
Util.Rand.Next(32),
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-07-16 01:36:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|