2017-04-29 23:22:32 +00:00
|
|
|
|
using System.Collections.Generic;
|
2017-08-04 04:35:41 +00:00
|
|
|
|
using System.Diagnostics;
|
2017-04-29 23:22:32 +00:00
|
|
|
|
using System.Linq;
|
2017-08-29 15:32:22 +00:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2017-04-29 23:22:32 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class containing logic to obtain a PKM's PIDIV method.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class MethodFinder
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Analyzes a <see cref="PKM"/> to find a matching PIDIV method.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pk">Input <see cref="PKM"/>.</param>
|
|
|
|
|
/// <returns><see cref="PIDIV"/> object containing seed and method info.</returns>
|
|
|
|
|
public static PIDIV Analyze(PKM pk)
|
|
|
|
|
{
|
|
|
|
|
if (pk.Format < 3)
|
|
|
|
|
return AnalyzeGB(pk);
|
2017-05-04 06:14:34 +00:00
|
|
|
|
var pid = pk.EncryptionConstant;
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2017-04-29 23:22:32 +00:00
|
|
|
|
var top = pid >> 16;
|
|
|
|
|
var bot = pid & 0xFFFF;
|
|
|
|
|
|
|
|
|
|
var IVs = new uint[6];
|
|
|
|
|
for (int i = 0; i < 6; i++)
|
2019-01-05 18:51:41 +00:00
|
|
|
|
IVs[i] = (uint)pk.GetIV(i);
|
2017-04-29 23:22:32 +00:00
|
|
|
|
|
2018-05-12 19:28:48 +00:00
|
|
|
|
if (GetLCRNGMatch(top, bot, IVs, out PIDIV pidiv))
|
2017-04-29 23:22:32 +00:00
|
|
|
|
return pidiv;
|
2019-12-09 01:39:19 +00:00
|
|
|
|
if (pk.Species == (int)Species.Unown && GetLCRNGUnownMatch(top, bot, IVs, out pidiv)) // frlg only
|
2017-05-01 15:37:23 +00:00
|
|
|
|
return pidiv;
|
2017-11-02 04:12:44 +00:00
|
|
|
|
if (GetColoStarterMatch(pk, top, bot, IVs, out pidiv))
|
|
|
|
|
return pidiv;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (GetXDRNGMatch(top, bot, IVs, out pidiv))
|
2017-04-29 23:22:32 +00:00
|
|
|
|
return pidiv;
|
|
|
|
|
|
|
|
|
|
// Special cases
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (GetLCRNGRoamerMatch(top, bot, IVs, out pidiv))
|
2017-05-02 06:41:19 +00:00
|
|
|
|
return pidiv;
|
2017-06-30 02:32:29 +00:00
|
|
|
|
if (GetChannelMatch(top, bot, IVs, out pidiv, pk))
|
2017-04-29 23:22:32 +00:00
|
|
|
|
return pidiv;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (GetMG4Match(pid, IVs, out pidiv))
|
2017-04-29 23:22:32 +00:00
|
|
|
|
return pidiv;
|
2017-04-30 03:04:54 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (GetBACDMatch(pk, pid, IVs, out pidiv))
|
2017-04-30 03:04:54 +00:00
|
|
|
|
return pidiv;
|
2017-08-29 15:32:22 +00:00
|
|
|
|
if (GetModifiedPIDMatch(pk, pid, IVs, out pidiv))
|
2017-06-25 00:20:15 +00:00
|
|
|
|
return pidiv;
|
2017-04-29 23:22:32 +00:00
|
|
|
|
|
2017-06-03 22:16:24 +00:00
|
|
|
|
return new PIDIV {Type=PIDType.None, NoSeed=true}; // no match
|
2017-04-29 23:22:32 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-08-29 15:32:22 +00:00
|
|
|
|
private static bool GetModifiedPIDMatch(PKM pk, uint pid, uint[] IVs, out PIDIV pidiv)
|
|
|
|
|
{
|
|
|
|
|
if (pk.IsShiny)
|
|
|
|
|
{
|
|
|
|
|
if (GetChainShinyMatch(pk, pid, IVs, out pidiv))
|
|
|
|
|
return true;
|
|
|
|
|
if (GetModified8BitMatch(pk, pid, out pidiv))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (pid <= 0xFF && GetCuteCharmMatch(pk, pid, out pidiv))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return GetPokewalkerMatch(pk, pid, out pidiv);
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-08-29 15:32:22 +00:00
|
|
|
|
private static bool GetModified8BitMatch(PKM pk, uint pid, out PIDIV pidiv)
|
|
|
|
|
{
|
2017-11-18 06:19:23 +00:00
|
|
|
|
return pk.Gen4
|
2018-08-03 03:11:42 +00:00
|
|
|
|
? (pid <= 0xFF && GetCuteCharmMatch(pk, pid, out pidiv)) || GetG5MGShinyMatch(pk, pid, out pidiv)
|
|
|
|
|
: GetG5MGShinyMatch(pk, pid, out pidiv) || (pid <= 0xFF && GetCuteCharmMatch(pk, pid, out pidiv));
|
2017-08-29 15:32:22 +00:00
|
|
|
|
}
|
2017-04-29 23:22:32 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static bool GetLCRNGMatch(uint top, uint bot, uint[] IVs, out PIDIV pidiv)
|
2017-04-29 23:22:32 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var reg = GetSeedsFromPID(RNG.LCRNG, top, bot);
|
|
|
|
|
var iv1 = GetIVChunk(IVs, 0);
|
|
|
|
|
var iv2 = GetIVChunk(IVs, 3);
|
2017-04-29 23:22:32 +00:00
|
|
|
|
foreach (var seed in reg)
|
|
|
|
|
{
|
|
|
|
|
// A and B are already used by PID
|
|
|
|
|
var B = RNG.LCRNG.Advance(seed, 2);
|
|
|
|
|
|
|
|
|
|
// Method 1/2/4 can use 3 different RNG frames
|
|
|
|
|
var C = RNG.LCRNG.Next(B);
|
2017-05-02 06:41:19 +00:00
|
|
|
|
var ivC = C >> 16 & 0x7FFF;
|
|
|
|
|
if (iv1 == ivC)
|
2017-04-29 23:22:32 +00:00
|
|
|
|
{
|
2017-05-02 06:41:19 +00:00
|
|
|
|
var D = RNG.LCRNG.Next(C);
|
|
|
|
|
var ivD = D >> 16 & 0x7FFF;
|
|
|
|
|
if (iv2 == ivD) // ABCD
|
|
|
|
|
{
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
pidiv = new PIDIV {OriginSeed = seed, RNG = RNGType.LCRNG, Type = PIDType.Method_1};
|
2017-05-02 06:41:19 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-04-29 23:22:32 +00:00
|
|
|
|
|
2017-05-02 06:41:19 +00:00
|
|
|
|
var E = RNG.LCRNG.Next(D);
|
|
|
|
|
var ivE = E >> 16 & 0x7FFF;
|
|
|
|
|
if (iv2 == ivE) // ABCE
|
|
|
|
|
{
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
pidiv = new PIDIV {OriginSeed = seed, RNG = RNGType.LCRNG, Type = PIDType.Method_4};
|
2017-05-02 06:41:19 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-04-29 23:22:32 +00:00
|
|
|
|
}
|
2017-05-02 06:41:19 +00:00
|
|
|
|
else
|
2017-04-29 23:22:32 +00:00
|
|
|
|
{
|
2017-05-02 06:41:19 +00:00
|
|
|
|
var D = RNG.LCRNG.Next(C);
|
|
|
|
|
var ivD = D >> 16 & 0x7FFF;
|
|
|
|
|
if (iv1 != ivD)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
var E = RNG.LCRNG.Next(D);
|
|
|
|
|
var ivE = E >> 16 & 0x7FFF;
|
|
|
|
|
if (iv2 == ivE) // ABDE
|
|
|
|
|
{
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
pidiv = new PIDIV {OriginSeed = seed, RNG = RNGType.LCRNG, Type = PIDType.Method_2};
|
2017-05-02 06:41:19 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-04-29 23:22:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-20 02:15:06 +00:00
|
|
|
|
reg = GetSeedsFromPIDSkip(RNG.LCRNG, top, bot);
|
|
|
|
|
foreach (var seed in reg)
|
|
|
|
|
{
|
|
|
|
|
// A and B are already used by PID
|
|
|
|
|
var C = RNG.LCRNG.Advance(seed, 3);
|
|
|
|
|
|
|
|
|
|
// Method 3
|
|
|
|
|
var D = RNG.LCRNG.Next(C);
|
|
|
|
|
var ivD = D >> 16 & 0x7FFF;
|
|
|
|
|
if (iv1 != ivD)
|
|
|
|
|
continue;
|
|
|
|
|
var E = RNG.LCRNG.Next(D);
|
|
|
|
|
var ivE = E >> 16 & 0x7FFF;
|
|
|
|
|
if (iv2 != ivE)
|
|
|
|
|
continue;
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
pidiv = new PIDIV {OriginSeed = seed, RNG = RNGType.LCRNG, Type = PIDType.Method_3};
|
2019-06-20 02:15:06 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-08-29 15:32:22 +00:00
|
|
|
|
return GetNonMatch(out pidiv);
|
2017-04-29 23:22:32 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static bool GetLCRNGUnownMatch(uint top, uint bot, uint[] IVs, out PIDIV pidiv)
|
2017-05-01 15:37:23 +00:00
|
|
|
|
{
|
|
|
|
|
// this is an exact copy of LCRNG 1,2,4 matching, except the PID has its halves switched (BACD, BADE, BACE)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var reg = GetSeedsFromPID(RNG.LCRNG, bot, top); // reversed!
|
|
|
|
|
var iv1 = GetIVChunk(IVs, 0);
|
|
|
|
|
var iv2 = GetIVChunk(IVs, 3);
|
2017-05-01 15:37:23 +00:00
|
|
|
|
foreach (var seed in reg)
|
|
|
|
|
{
|
|
|
|
|
// A and B are already used by PID
|
|
|
|
|
var B = RNG.LCRNG.Advance(seed, 2);
|
|
|
|
|
|
|
|
|
|
// Method 1/2/4 can use 3 different RNG frames
|
|
|
|
|
var C = RNG.LCRNG.Next(B);
|
2017-05-02 06:41:19 +00:00
|
|
|
|
var ivC = C >> 16 & 0x7FFF;
|
|
|
|
|
if (iv1 == ivC)
|
2017-05-01 15:37:23 +00:00
|
|
|
|
{
|
2017-05-02 06:41:19 +00:00
|
|
|
|
var D = RNG.LCRNG.Next(C);
|
|
|
|
|
var ivD = D >> 16 & 0x7FFF;
|
|
|
|
|
if (iv2 == ivD) // BACD
|
|
|
|
|
{
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
pidiv = new PIDIV {OriginSeed = seed, RNG = RNGType.LCRNG, Type = PIDType.Method_1_Unown};
|
2017-05-02 06:41:19 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-05-01 15:37:23 +00:00
|
|
|
|
|
2017-05-02 06:41:19 +00:00
|
|
|
|
var E = RNG.LCRNG.Next(D);
|
|
|
|
|
var ivE = E >> 16 & 0x7FFF;
|
|
|
|
|
if (iv2 == ivE) // BACE
|
|
|
|
|
{
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
pidiv = new PIDIV {OriginSeed = seed, RNG = RNGType.LCRNG, Type = PIDType.Method_4_Unown};
|
2017-05-02 06:41:19 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-05-01 15:37:23 +00:00
|
|
|
|
}
|
2017-05-02 06:41:19 +00:00
|
|
|
|
else
|
2017-05-01 15:37:23 +00:00
|
|
|
|
{
|
2017-05-02 06:41:19 +00:00
|
|
|
|
var D = RNG.LCRNG.Next(C);
|
|
|
|
|
var ivD = D >> 16 & 0x7FFF;
|
|
|
|
|
if (iv1 != ivD)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
var E = RNG.LCRNG.Next(D);
|
|
|
|
|
var ivE = E >> 16 & 0x7FFF;
|
2017-05-02 15:59:55 +00:00
|
|
|
|
if (iv2 == ivE) // BADE
|
2017-05-02 06:41:19 +00:00
|
|
|
|
{
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
pidiv = new PIDIV {OriginSeed = seed, RNG = RNGType.LCRNG, Type = PIDType.Method_2_Unown};
|
2017-05-02 06:41:19 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-05-01 15:37:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-20 02:15:06 +00:00
|
|
|
|
reg = GetSeedsFromPIDSkip(RNG.LCRNG, bot, top); // reversed!
|
|
|
|
|
foreach (var seed in reg)
|
|
|
|
|
{
|
|
|
|
|
// A and B are already used by PID
|
|
|
|
|
var C = RNG.LCRNG.Advance(seed, 3);
|
|
|
|
|
|
|
|
|
|
// Method 3
|
|
|
|
|
var D = RNG.LCRNG.Next(C);
|
|
|
|
|
var ivD = D >> 16 & 0x7FFF;
|
|
|
|
|
if (iv1 != ivD)
|
|
|
|
|
continue;
|
|
|
|
|
var E = RNG.LCRNG.Next(D);
|
|
|
|
|
var ivE = E >> 16 & 0x7FFF;
|
|
|
|
|
if (iv2 != ivE)
|
|
|
|
|
continue;
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
pidiv = new PIDIV {OriginSeed = seed, RNG = RNGType.LCRNG, Type = PIDType.Method_3_Unown};
|
2019-06-20 02:15:06 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-08-29 15:32:22 +00:00
|
|
|
|
return GetNonMatch(out pidiv);
|
2017-05-01 15:37:23 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static bool GetLCRNGRoamerMatch(uint top, uint bot, uint[] IVs, out PIDIV pidiv)
|
2017-05-02 06:41:19 +00:00
|
|
|
|
{
|
2018-10-13 15:02:55 +00:00
|
|
|
|
if (IVs[2] != 0 || IVs[3] != 0 || IVs[4] != 0 || IVs[5] != 0 || IVs[1] > 7)
|
2017-08-29 15:32:22 +00:00
|
|
|
|
return GetNonMatch(out pidiv);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var iv1 = GetIVChunk(IVs, 0);
|
|
|
|
|
var reg = GetSeedsFromPID(RNG.LCRNG, top, bot);
|
2017-05-02 06:41:19 +00:00
|
|
|
|
foreach (var seed in reg)
|
|
|
|
|
{
|
2017-06-03 22:43:41 +00:00
|
|
|
|
// Only the first 8 bits are kept
|
|
|
|
|
var ivC = RNG.LCRNG.Advance(seed, 3) >> 16 & 0x00FF;
|
2017-05-02 06:41:19 +00:00
|
|
|
|
if (iv1 != ivC)
|
|
|
|
|
continue;
|
|
|
|
|
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
pidiv = new PIDIV {OriginSeed = seed, RNG = RNGType.LCRNG, Type = PIDType.Method_1_Roamer};
|
2017-05-02 06:41:19 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-08-29 15:32:22 +00:00
|
|
|
|
return GetNonMatch(out pidiv);
|
2017-05-02 06:41:19 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static bool GetXDRNGMatch(uint top, uint bot, uint[] IVs, out PIDIV pidiv)
|
2017-04-29 23:22:32 +00:00
|
|
|
|
{
|
2017-08-05 08:51:29 +00:00
|
|
|
|
var xdc = GetSeedsFromPIDEuclid(RNG.XDRNG, top, bot);
|
2017-04-29 23:22:32 +00:00
|
|
|
|
foreach (var seed in xdc)
|
|
|
|
|
{
|
2017-05-28 05:18:04 +00:00
|
|
|
|
var B = RNG.XDRNG.Prev(seed);
|
|
|
|
|
var A = RNG.XDRNG.Prev(B);
|
2017-04-29 23:22:32 +00:00
|
|
|
|
|
2019-01-06 09:26:18 +00:00
|
|
|
|
var hi = A >> 16;
|
|
|
|
|
var lo = B >> 16;
|
|
|
|
|
if (!IVsMatch(hi, lo, IVs))
|
2017-12-04 21:18:24 +00:00
|
|
|
|
{
|
2019-01-06 09:26:18 +00:00
|
|
|
|
// check for antishiny
|
|
|
|
|
// allow 2 different TSVs to proc antishiny for XD
|
2019-05-11 07:59:07 +00:00
|
|
|
|
var tsv1 = (int)((hi ^ lo) >> 3);
|
2019-01-06 09:26:18 +00:00
|
|
|
|
var tsv2 = -1;
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
B = RNG.XDRNG.Prev(A);
|
|
|
|
|
A = RNG.XDRNG.Prev(B);
|
|
|
|
|
hi = A >> 16;
|
|
|
|
|
lo = B >> 16;
|
|
|
|
|
if (!IVsMatch(hi, lo, IVs))
|
|
|
|
|
{
|
|
|
|
|
var anti = (int)(hi ^ lo) >> 3;
|
|
|
|
|
if (anti == tsv1)
|
|
|
|
|
continue;
|
|
|
|
|
if (anti == tsv2)
|
|
|
|
|
continue;
|
|
|
|
|
if (tsv2 >= 0) // already set
|
|
|
|
|
break; // can't have this many shiny TSVs
|
|
|
|
|
tsv2 = anti;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
pidiv = new PIDIVTSV
|
|
|
|
|
{
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
OriginSeed = RNG.XDRNG.Prev(A), RNG = RNGType.XDRNG, Type = PIDType.CXDAnti,
|
2019-05-11 07:59:07 +00:00
|
|
|
|
TSV1 = tsv1, TSV2 = tsv2,
|
2019-01-06 09:26:18 +00:00
|
|
|
|
};
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
continue;
|
2017-12-04 21:18:24 +00:00
|
|
|
|
}
|
2017-04-29 23:22:32 +00:00
|
|
|
|
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
pidiv = new PIDIV {OriginSeed = RNG.XDRNG.Prev(A), RNG = RNGType.XDRNG, Type = PIDType.CXD};
|
2017-04-29 23:22:32 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-08-29 15:32:22 +00:00
|
|
|
|
return GetNonMatch(out pidiv);
|
2017-04-29 23:22:32 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-30 02:32:29 +00:00
|
|
|
|
private static bool GetChannelMatch(uint top, uint bot, uint[] IVs, out PIDIV pidiv, PKM pk)
|
2017-04-29 23:22:32 +00:00
|
|
|
|
{
|
2017-06-30 02:32:29 +00:00
|
|
|
|
var ver = pk.Version;
|
|
|
|
|
if (ver != (int) GameVersion.R && ver != (int) GameVersion.S)
|
2017-08-29 15:32:22 +00:00
|
|
|
|
return GetNonMatch(out pidiv);
|
2017-06-30 02:32:29 +00:00
|
|
|
|
|
2017-07-16 02:59:38 +00:00
|
|
|
|
var undo = top ^ 0x8000;
|
|
|
|
|
if ((undo > 7 ? 0 : 1) != (bot ^ pk.SID ^ 40122))
|
|
|
|
|
top = undo;
|
2017-08-05 08:51:29 +00:00
|
|
|
|
var channel = GetSeedsFromPIDEuclid(RNG.XDRNG, top, bot);
|
2017-04-29 23:22:32 +00:00
|
|
|
|
foreach (var seed in channel)
|
|
|
|
|
{
|
2017-06-30 02:32:29 +00:00
|
|
|
|
var C = RNG.XDRNG.Advance(seed, 3); // held item
|
|
|
|
|
// no checks, held item can be swapped
|
|
|
|
|
|
|
|
|
|
var D = RNG.XDRNG.Next(C); // Version
|
|
|
|
|
if ((D >> 31) + 1 != ver) // (0-Sapphire, 1-Ruby)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
var E = RNG.XDRNG.Next(D); // OT Gender
|
|
|
|
|
if (E >> 31 != pk.OT_Gender)
|
|
|
|
|
continue;
|
|
|
|
|
|
2017-07-16 01:36:55 +00:00
|
|
|
|
if (!RNG.XDRNG.GetSequentialIVsUInt32(E).SequenceEqual(IVs))
|
2017-04-29 23:22:32 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
2017-06-30 02:32:29 +00:00
|
|
|
|
if (seed >> 16 != pk.SID)
|
|
|
|
|
continue;
|
|
|
|
|
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
pidiv = new PIDIV {OriginSeed = RNG.XDRNG.Prev(seed), RNG = RNGType.XDRNG, Type = PIDType.Channel};
|
2017-04-29 23:22:32 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-08-29 15:32:22 +00:00
|
|
|
|
return GetNonMatch(out pidiv);
|
2017-04-29 23:22:32 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static bool GetMG4Match(uint pid, uint[] IVs, out PIDIV pidiv)
|
2017-04-29 23:22:32 +00:00
|
|
|
|
{
|
|
|
|
|
uint mg4Rev = RNG.ARNG.Prev(pid);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var mg4 = GetSeedsFromPID(RNG.LCRNG, mg4Rev >> 16, mg4Rev & 0xFFFF);
|
2017-04-29 23:22:32 +00:00
|
|
|
|
foreach (var seed in mg4)
|
|
|
|
|
{
|
|
|
|
|
var B = RNG.LCRNG.Advance(seed, 2);
|
|
|
|
|
var C = RNG.LCRNG.Next(B);
|
|
|
|
|
var D = RNG.LCRNG.Next(C);
|
2019-01-06 09:26:18 +00:00
|
|
|
|
if (!IVsMatch(C >> 16, D >> 16, IVs))
|
2017-04-29 23:22:32 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
pidiv = new PIDIV {OriginSeed = seed, RNG = RNGType.LCRNG, Type = PIDType.G4MGAntiShiny};
|
2017-04-29 23:22:32 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-08-29 15:32:22 +00:00
|
|
|
|
return GetNonMatch(out pidiv);
|
2017-04-29 23:22:32 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-08-29 15:32:22 +00:00
|
|
|
|
private static bool GetG5MGShinyMatch(PKM pk, uint pid, out PIDIV pidiv)
|
2017-04-29 23:22:32 +00:00
|
|
|
|
{
|
2017-04-30 03:04:54 +00:00
|
|
|
|
var low = pid & 0xFFFF;
|
2017-04-29 23:22:32 +00:00
|
|
|
|
// generation 5 shiny PIDs
|
2017-04-30 03:04:54 +00:00
|
|
|
|
if (low <= 0xFF)
|
|
|
|
|
{
|
2017-09-17 21:43:28 +00:00
|
|
|
|
var av = (pid >> 16) & 1;
|
|
|
|
|
var genPID = PIDGenerator.GetMG5ShinyPID(low, av, pk.TID, pk.SID);
|
|
|
|
|
if (genPID == pid)
|
2017-04-30 03:04:54 +00:00
|
|
|
|
{
|
|
|
|
|
pidiv = new PIDIV {NoSeed = true, Type = PIDType.G5MGShiny};
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-29 15:32:22 +00:00
|
|
|
|
return GetNonMatch(out pidiv);
|
2017-04-29 23:22:32 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static bool GetCuteCharmMatch(PKM pk, uint pid, out PIDIV pidiv)
|
2017-04-29 23:22:32 +00:00
|
|
|
|
{
|
2017-08-29 15:32:22 +00:00
|
|
|
|
if (pid > 0xFF)
|
|
|
|
|
return GetNonMatch(out pidiv);
|
|
|
|
|
|
2017-10-13 06:18:43 +00:00
|
|
|
|
GetCuteCharmGenderSpecies(pk, pid, out int genderValue, out int species);
|
|
|
|
|
int getRatio() => PersonalTable.HGSS[species].Gender;
|
2017-04-29 23:22:32 +00:00
|
|
|
|
switch (genderValue)
|
|
|
|
|
{
|
|
|
|
|
case 2: break; // can't cute charm a genderless pkm
|
|
|
|
|
case 0: // male
|
2017-10-13 06:18:43 +00:00
|
|
|
|
var gr = getRatio();
|
2017-04-29 23:22:32 +00:00
|
|
|
|
if (254 <= gr) // no modification for PID
|
|
|
|
|
break;
|
2018-08-03 03:11:42 +00:00
|
|
|
|
var rate = 25*((gr / 25) + 1); // buffered
|
2017-05-14 19:42:27 +00:00
|
|
|
|
var nature = pid % 25;
|
|
|
|
|
if (nature + rate != pid)
|
2017-04-29 23:22:32 +00:00
|
|
|
|
break;
|
|
|
|
|
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
pidiv = new PIDIV {NoSeed = true, RNG = RNGType.LCRNG, Type = PIDType.CuteCharm};
|
2017-04-29 23:22:32 +00:00
|
|
|
|
return true;
|
|
|
|
|
case 1: // female
|
2017-04-30 06:18:36 +00:00
|
|
|
|
if (pid >= 25)
|
2019-05-11 07:59:07 +00:00
|
|
|
|
break; // nope, this isn't a valid nature
|
2017-10-13 06:18:43 +00:00
|
|
|
|
if (254 <= getRatio()) // no modification for PID
|
2017-04-29 23:22:32 +00:00
|
|
|
|
break;
|
|
|
|
|
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
pidiv = new PIDIV {NoSeed = true, RNG = RNGType.LCRNG, Type = PIDType.CuteCharm};
|
2017-04-29 23:22:32 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-08-29 15:32:22 +00:00
|
|
|
|
return GetNonMatch(out pidiv);
|
2017-04-29 23:22:32 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static bool GetChainShinyMatch(PKM pk, uint pid, uint[] IVs, out PIDIV pidiv)
|
2017-04-30 03:04:54 +00:00
|
|
|
|
{
|
|
|
|
|
// 13 shiny bits
|
|
|
|
|
// PIDH & 7
|
|
|
|
|
// PIDL & 7
|
|
|
|
|
// IVs
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var bot = GetIVChunk(IVs, 0);
|
|
|
|
|
var top = GetIVChunk(IVs, 3);
|
|
|
|
|
var reg = GetSeedsFromIVs(RNG.LCRNG, top, bot);
|
2017-04-30 03:04:54 +00:00
|
|
|
|
foreach (var seed in reg)
|
|
|
|
|
{
|
|
|
|
|
// check the individual bits
|
|
|
|
|
var s = seed;
|
|
|
|
|
int i = 15;
|
2018-05-12 19:28:48 +00:00
|
|
|
|
do
|
2017-04-30 03:04:54 +00:00
|
|
|
|
{
|
|
|
|
|
var bit = s >> 16 & 1;
|
|
|
|
|
if (bit != (pid >> i & 1))
|
|
|
|
|
break;
|
|
|
|
|
s = RNG.LCRNG.Prev(s);
|
|
|
|
|
}
|
2018-05-12 19:28:48 +00:00
|
|
|
|
while (--i != 2);
|
2017-04-30 03:04:54 +00:00
|
|
|
|
if (i != 2) // bit failed
|
2017-04-30 06:18:36 +00:00
|
|
|
|
continue;
|
2017-04-30 03:04:54 +00:00
|
|
|
|
// Shiny Bits of PID validated
|
|
|
|
|
var upper = s;
|
|
|
|
|
if ((upper >> 16 & 7) != (pid >> 16 & 7))
|
2017-04-30 06:18:36 +00:00
|
|
|
|
continue;
|
2017-04-30 03:04:54 +00:00
|
|
|
|
var lower = RNG.LCRNG.Prev(upper);
|
|
|
|
|
if ((lower >> 16 & 7) != (pid & 7))
|
2017-04-30 06:18:36 +00:00
|
|
|
|
continue;
|
2017-04-30 03:04:54 +00:00
|
|
|
|
|
2018-08-03 03:11:42 +00:00
|
|
|
|
var upid = (((pid & 0xFFFF) ^ pk.TID ^ pk.SID) & 0xFFF8) | ((upper >> 16) & 0x7);
|
2017-04-30 03:04:54 +00:00
|
|
|
|
if (upid != pid >> 16)
|
2017-04-30 06:18:36 +00:00
|
|
|
|
continue;
|
2017-04-30 03:04:54 +00:00
|
|
|
|
|
|
|
|
|
s = RNG.LCRNG.Reverse(lower, 2); // unroll one final time to get the origin seed
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
pidiv = new PIDIV {OriginSeed = s, RNG = RNGType.LCRNG, Type = PIDType.ChainShiny};
|
2017-04-30 03:04:54 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-08-29 15:32:22 +00:00
|
|
|
|
return GetNonMatch(out pidiv);
|
2017-04-30 03:04:54 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static bool GetBACDMatch(PKM pk, uint pid, uint[] IVs, out PIDIV pidiv)
|
2017-04-30 06:18:36 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var bot = GetIVChunk(IVs, 0);
|
|
|
|
|
var top = GetIVChunk(IVs, 3);
|
|
|
|
|
var reg = GetSeedsFromIVs(RNG.LCRNG, top, bot);
|
2017-09-12 07:27:16 +00:00
|
|
|
|
PIDType type = PIDType.BACD_U;
|
2017-04-30 06:18:36 +00:00
|
|
|
|
foreach (var seed in reg)
|
|
|
|
|
{
|
|
|
|
|
var B = seed;
|
|
|
|
|
var A = RNG.LCRNG.Prev(B);
|
2017-09-12 07:27:16 +00:00
|
|
|
|
var low = B >> 16;
|
2017-04-30 06:18:36 +00:00
|
|
|
|
|
2018-08-03 03:11:42 +00:00
|
|
|
|
var PID = (A & 0xFFFF0000) | low;
|
2017-04-30 06:18:36 +00:00
|
|
|
|
if (PID != pid)
|
|
|
|
|
{
|
2017-09-12 07:27:16 +00:00
|
|
|
|
uint idxor = (uint)(pk.TID ^ pk.SID);
|
2018-08-03 03:11:42 +00:00
|
|
|
|
bool isShiny = (idxor ^ PID >> 16 ^ (PID & 0xFFFF)) < 8;
|
2017-04-30 06:18:36 +00:00
|
|
|
|
if (!isShiny)
|
2017-05-01 05:11:51 +00:00
|
|
|
|
{
|
2017-09-12 07:27:16 +00:00
|
|
|
|
if (!pk.IsShiny) // check for nyx antishiny
|
|
|
|
|
{
|
|
|
|
|
if (!IsBACD_U_AX(idxor, pid, low, A, ref type))
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else // check for force shiny pkm
|
|
|
|
|
{
|
|
|
|
|
if (!IsBACD_U_S(idxor, pid, low, ref A, ref type))
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2017-05-01 05:11:51 +00:00
|
|
|
|
}
|
2017-09-12 07:27:16 +00:00
|
|
|
|
else if (!IsBACD_U_AX(idxor, pid, low, A, ref type))
|
2017-06-03 07:12:05 +00:00
|
|
|
|
{
|
|
|
|
|
if ((PID + 8 & 0xFFFFFFF8) != pid)
|
|
|
|
|
continue;
|
2017-09-12 07:27:16 +00:00
|
|
|
|
type = PIDType.BACD_U_A;
|
2017-06-03 07:12:05 +00:00
|
|
|
|
}
|
2017-04-30 06:18:36 +00:00
|
|
|
|
}
|
|
|
|
|
var s = RNG.LCRNG.Prev(A);
|
|
|
|
|
|
2017-05-02 06:41:19 +00:00
|
|
|
|
// Check for prior Restricted seed
|
2017-04-30 06:18:36 +00:00
|
|
|
|
var sn = s;
|
|
|
|
|
for (int i = 0; i < 3; i++, sn = RNG.LCRNG.Prev(sn))
|
|
|
|
|
{
|
|
|
|
|
if ((sn & 0xFFFF0000) != 0)
|
|
|
|
|
continue;
|
2017-09-12 07:27:16 +00:00
|
|
|
|
// shift from unrestricted enum val to restricted enum val
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
pidiv = new PIDIV {OriginSeed = sn, RNG = RNGType.LCRNG, Type = --type };
|
2017-04-30 06:18:36 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-05-02 06:41:19 +00:00
|
|
|
|
// no restricted seed found, thus unrestricted
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
pidiv = new PIDIV {OriginSeed = s, RNG = RNGType.LCRNG, Type = type};
|
2017-04-30 06:18:36 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-08-29 15:32:22 +00:00
|
|
|
|
return GetNonMatch(out pidiv);
|
2017-04-30 06:18:36 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-25 00:20:15 +00:00
|
|
|
|
private static bool GetPokewalkerMatch(PKM pk, uint oldpid, out PIDIV pidiv)
|
|
|
|
|
{
|
2017-08-29 06:40:04 +00:00
|
|
|
|
// check surface compatibility
|
|
|
|
|
var mid = oldpid & 0x00FFFF00;
|
|
|
|
|
if (mid != 0 && mid != 0x00FFFF00) // not expected bits
|
2017-08-29 15:32:22 +00:00
|
|
|
|
return GetNonMatch(out pidiv);
|
2017-06-25 00:20:15 +00:00
|
|
|
|
var nature = oldpid % 25;
|
2017-08-29 06:40:04 +00:00
|
|
|
|
if (nature == 24) // impossible nature
|
2017-08-29 15:32:22 +00:00
|
|
|
|
return GetNonMatch(out pidiv);
|
2017-06-25 00:20:15 +00:00
|
|
|
|
|
2019-05-16 00:14:48 +00:00
|
|
|
|
var gender = pk.Gender;
|
|
|
|
|
uint pid = PIDGenerator.GetPokeWalkerPID(pk.TID, pk.SID, nature, gender, pk.PersonalInfo.Gender);
|
2018-04-30 01:26:36 +00:00
|
|
|
|
|
2017-08-29 15:32:22 +00:00
|
|
|
|
if (pid != oldpid)
|
2019-05-16 00:14:48 +00:00
|
|
|
|
{
|
|
|
|
|
if (!(gender == 0 && IsAzurillEdgeCaseM(pk, nature, oldpid)))
|
|
|
|
|
return GetNonMatch(out pidiv);
|
|
|
|
|
}
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
pidiv = new PIDIV {NoSeed = true, RNG = RNGType.LCRNG, Type = PIDType.Pokewalker};
|
2017-08-29 15:32:22 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2019-05-16 00:14:48 +00:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
private static bool IsAzurillEdgeCaseM(PKM pk, uint nature, uint oldpid)
|
|
|
|
|
{
|
|
|
|
|
// check for Azurill evolution edge case... 75% F-M is now 50% F-M; was this a F->M bend?
|
|
|
|
|
int spec = pk.Species;
|
|
|
|
|
if (spec != (int)Species.Marill && spec != (int)Species.Azumarill)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
const int AzurillGenderRatio = 0xBF;
|
|
|
|
|
var gender = PKX.GetGenderFromPIDAndRatio(pk.PID, AzurillGenderRatio);
|
|
|
|
|
if (gender != 1)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
var pid = PIDGenerator.GetPokeWalkerPID(pk.TID, pk.SID, nature, 1, AzurillGenderRatio);
|
|
|
|
|
return pid == oldpid;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-02 04:12:44 +00:00
|
|
|
|
private static bool GetColoStarterMatch(PKM pk, uint top, uint bot, uint[] IVs, out PIDIV pidiv)
|
|
|
|
|
{
|
2018-08-03 03:11:42 +00:00
|
|
|
|
if (pk.Version != 15 || (pk.Species != 196 && pk.Species != 197))
|
2017-11-02 04:12:44 +00:00
|
|
|
|
return GetNonMatch(out pidiv);
|
|
|
|
|
|
|
|
|
|
var iv1 = GetIVChunk(IVs, 0);
|
|
|
|
|
var iv2 = GetIVChunk(IVs, 3);
|
|
|
|
|
var xdc = GetSeedsFromPIDEuclid(RNG.XDRNG, top, bot);
|
|
|
|
|
foreach (var seed in xdc)
|
|
|
|
|
{
|
|
|
|
|
uint origin = seed;
|
|
|
|
|
if (!LockFinder.IsColoStarterValid(pk.Species, ref origin, pk.TID, pk.SID, pk.PID, iv1, iv2))
|
|
|
|
|
continue;
|
|
|
|
|
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
pidiv = new PIDIV { OriginSeed = origin, RNG = RNGType.XDRNG, Type = PIDType.CXD_ColoStarter };
|
2017-11-02 04:12:44 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return GetNonMatch(out pidiv);
|
|
|
|
|
}
|
2017-06-25 00:20:15 +00:00
|
|
|
|
|
2017-08-29 15:32:22 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns false and no <see cref="PIDIV"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pidiv">Null</param>
|
|
|
|
|
/// <returns>False</returns>
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
private static bool GetNonMatch(out PIDIV pidiv)
|
|
|
|
|
{
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
pidiv = PIDIV.None;
|
2017-06-25 00:20:15 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-09-12 07:27:16 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if the PID is a <see cref="PIDType.BACD_U_S"></see> match.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idxor"><see cref="PKM.TID"/> ^ <see cref="PKM.SID"/></param>
|
|
|
|
|
/// <param name="pid">Full actual PID</param>
|
|
|
|
|
/// <param name="low">Low portion of PID (B)</param>
|
|
|
|
|
/// <param name="A">First RNG call</param>
|
|
|
|
|
/// <param name="type">PID Type is updated if successful</param>
|
|
|
|
|
/// <returns>True/False if the PID matches</returns>
|
|
|
|
|
/// <remarks>First RNG call is unrolled once if the PID is valid with this correlation</remarks>
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
private static bool IsBACD_U_S(uint idxor, uint pid, uint low, ref uint A, ref PIDType type)
|
|
|
|
|
{
|
|
|
|
|
// 0-Origin
|
|
|
|
|
// 1-PIDH
|
|
|
|
|
// 2-PIDL (ends up unused)
|
|
|
|
|
// 3-FORCEBITS
|
|
|
|
|
// PID = PIDH << 16 | (SID ^ TID ^ PIDH)
|
|
|
|
|
|
|
|
|
|
var X = RNG.LCRNG.Prev(A); // unroll once as there's 3 calls instead of 2
|
2018-08-03 03:11:42 +00:00
|
|
|
|
uint PID = (X & 0xFFFF0000) | (idxor ^ X >> 16);
|
2017-09-12 07:27:16 +00:00
|
|
|
|
PID &= 0xFFFFFFF8;
|
|
|
|
|
PID |= low & 0x7; // lowest 3 bits
|
|
|
|
|
|
|
|
|
|
if (PID != pid)
|
|
|
|
|
return false;
|
|
|
|
|
A = X; // keep the unrolled seed
|
|
|
|
|
type = PIDType.BACD_U_S;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-09-12 07:27:16 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if the PID is a <see cref="PIDType.BACD_U_AX"></see> match.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idxor"><see cref="PKM.TID"/> ^ <see cref="PKM.SID"/></param>
|
|
|
|
|
/// <param name="pid">Full actual PID</param>
|
|
|
|
|
/// <param name="low">Low portion of PID (B)</param>
|
|
|
|
|
/// <param name="A">First RNG call</param>
|
|
|
|
|
/// <param name="type">PID Type is updated if successful</param>
|
|
|
|
|
/// <returns>True/False if the PID matches</returns>
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
private static bool IsBACD_U_AX(uint idxor, uint pid, uint low, uint A, ref PIDType type)
|
|
|
|
|
{
|
|
|
|
|
if ((pid & 0xFFFF) != low)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// 0-Origin
|
|
|
|
|
// 1-ushort rnd, do until >8
|
|
|
|
|
// 2-PIDL
|
|
|
|
|
|
|
|
|
|
uint rnd = A >> 16;
|
|
|
|
|
if (rnd < 8)
|
|
|
|
|
return false;
|
|
|
|
|
uint PID = ((rnd ^ idxor ^ low) << 16) | low;
|
|
|
|
|
if (PID != pid)
|
|
|
|
|
return false;
|
|
|
|
|
type = PIDType.BACD_U_AX;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-04-29 23:22:32 +00:00
|
|
|
|
|
2018-08-03 03:11:42 +00:00
|
|
|
|
private static PIDIV AnalyzeGB(PKM _)
|
2017-04-29 23:22:32 +00:00
|
|
|
|
{
|
2019-05-11 07:59:07 +00:00
|
|
|
|
// not implemented; correlation between IVs and RNG hasn't been converted to code.
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
return PIDIV.None;
|
2017-04-29 23:22:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static IEnumerable<uint> GetSeedsFromPID(RNG method, uint a, uint b)
|
2017-04-29 23:22:32 +00:00
|
|
|
|
{
|
2017-08-04 04:35:41 +00:00
|
|
|
|
Debug.Assert(a >> 16 == 0);
|
|
|
|
|
Debug.Assert(b >> 16 == 0);
|
|
|
|
|
uint second = a << 16;
|
|
|
|
|
uint first = b << 16;
|
|
|
|
|
return method.RecoverLower16Bits(first, second);
|
2017-04-29 23:22:32 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2019-06-20 02:15:06 +00:00
|
|
|
|
private static IEnumerable<uint> GetSeedsFromPIDSkip(RNG method, uint a, uint b)
|
|
|
|
|
{
|
|
|
|
|
Debug.Assert(a >> 16 == 0);
|
|
|
|
|
Debug.Assert(b >> 16 == 0);
|
|
|
|
|
uint third = a << 16;
|
|
|
|
|
uint first = b << 16;
|
|
|
|
|
return method.RecoverLower16BitsGap(first, third);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static IEnumerable<uint> GetSeedsFromIVs(RNG method, uint a, uint b)
|
2017-04-29 23:22:32 +00:00
|
|
|
|
{
|
2017-08-04 04:35:41 +00:00
|
|
|
|
Debug.Assert(a >> 15 == 0);
|
|
|
|
|
Debug.Assert(b >> 15 == 0);
|
|
|
|
|
uint second = a << 16;
|
|
|
|
|
uint first = b << 16;
|
|
|
|
|
var pairs = method.RecoverLower16Bits(first, second)
|
|
|
|
|
.Concat(method.RecoverLower16Bits(first, second ^ 0x80000000));
|
|
|
|
|
foreach (var z in pairs)
|
|
|
|
|
{
|
|
|
|
|
yield return z;
|
|
|
|
|
yield return z ^ 0x80000000; // sister bitflip
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-08-04 04:35:41 +00:00
|
|
|
|
public static IEnumerable<uint> GetSeedsFromIVsSkip(RNG method, uint rand1, uint rand3)
|
|
|
|
|
{
|
|
|
|
|
Debug.Assert(rand1 >> 15 == 0);
|
|
|
|
|
Debug.Assert(rand3 >> 15 == 0);
|
|
|
|
|
rand1 <<= 16;
|
|
|
|
|
rand3 <<= 16;
|
|
|
|
|
var seeds = method.RecoverLower16BitsGap(rand1, rand3)
|
|
|
|
|
.Concat(method.RecoverLower16BitsGap(rand1, rand3 ^ 0x80000000));
|
|
|
|
|
foreach (var z in seeds)
|
|
|
|
|
{
|
|
|
|
|
yield return z;
|
|
|
|
|
yield return z ^ 0x80000000; // sister bitflip
|
|
|
|
|
}
|
2017-04-29 23:22:32 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-08-05 08:51:29 +00:00
|
|
|
|
public static IEnumerable<uint> GetSeedsFromPIDEuclid(RNG method, uint rand1, uint rand2)
|
|
|
|
|
{
|
|
|
|
|
return method.RecoverLower16BitsEuclid16(rand1 << 16, rand2 << 16);
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-08-05 08:51:29 +00:00
|
|
|
|
public static IEnumerable<uint> GetSeedsFromIVsEuclid(RNG method, uint rand1, uint rand2)
|
|
|
|
|
{
|
|
|
|
|
return method.RecoverLower16BitsEuclid15(rand1 << 16, rand2 << 16);
|
|
|
|
|
}
|
2017-04-29 23:22:32 +00:00
|
|
|
|
|
2019-01-06 09:26:18 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generates IVs from 2 RNG calls using 15 bits of each to generate 6 IVs (5bits each).
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="r1">First rand frame</param>
|
|
|
|
|
/// <param name="r2">Second rand frame</param>
|
|
|
|
|
/// <param name="IVs">IVs that should be the result</param>
|
|
|
|
|
/// <returns>IVs match random number IVs</returns>
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
private static bool IVsMatch(uint r1, uint r2, IReadOnlyList<uint> IVs)
|
|
|
|
|
{
|
|
|
|
|
if (IVs[0] != (r1 & 31))
|
|
|
|
|
return false;
|
|
|
|
|
if (IVs[1] != (r1 >> 5 & 31))
|
|
|
|
|
return false;
|
|
|
|
|
if (IVs[2] != (r1 >> 10 & 31))
|
|
|
|
|
return false;
|
|
|
|
|
if (IVs[3] != (r2 & 31))
|
|
|
|
|
return false;
|
|
|
|
|
if (IVs[4] != (r2 >> 5 & 31))
|
|
|
|
|
return false;
|
|
|
|
|
if (IVs[5] != (r2 >> 10 & 31))
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-29 23:22:32 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generates IVs from 2 RNG calls using 15 bits of each to generate 6 IVs (5bits each).
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="r1">First rand frame</param>
|
|
|
|
|
/// <param name="r2">Second rand frame</param>
|
|
|
|
|
/// <returns>Array of 6 IVs</returns>
|
2019-01-06 09:26:18 +00:00
|
|
|
|
internal static uint[] GetIVs(uint r1, uint r2)
|
2017-04-29 23:22:32 +00:00
|
|
|
|
{
|
|
|
|
|
return new[]
|
|
|
|
|
{
|
|
|
|
|
r1 & 31,
|
|
|
|
|
r1 >> 5 & 31,
|
|
|
|
|
r1 >> 10 & 31,
|
|
|
|
|
r2 & 31,
|
|
|
|
|
r2 >> 5 & 31,
|
|
|
|
|
r2 >> 10 & 31,
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-07-16 01:36:55 +00:00
|
|
|
|
internal static int[] GetIVsInt32(uint r1, uint r2)
|
2017-04-29 23:22:32 +00:00
|
|
|
|
{
|
2017-07-16 01:36:55 +00:00
|
|
|
|
return new[]
|
2017-04-29 23:22:32 +00:00
|
|
|
|
{
|
2017-07-16 01:36:55 +00:00
|
|
|
|
(int)r1 & 31,
|
|
|
|
|
(int)r1 >> 5 & 31,
|
|
|
|
|
(int)r1 >> 10 & 31,
|
|
|
|
|
(int)r2 & 31,
|
|
|
|
|
(int)r2 >> 5 & 31,
|
|
|
|
|
(int)r2 >> 10 & 31,
|
|
|
|
|
};
|
2017-04-29 23:22:32 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static uint GetIVChunk(uint[] IVs, int start)
|
2017-04-30 03:04:54 +00:00
|
|
|
|
{
|
|
|
|
|
uint val = 0;
|
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
|
val |= IVs[i+start] << (5*i);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
2017-04-30 23:53:54 +00:00
|
|
|
|
|
2019-01-04 05:29:19 +00:00
|
|
|
|
public static IEnumerable<PIDIV> GetColoEReaderMatches(uint PID)
|
|
|
|
|
{
|
|
|
|
|
var top = PID >> 16;
|
|
|
|
|
var bot = (ushort)PID;
|
|
|
|
|
var xdc = GetSeedsFromPIDEuclid(RNG.XDRNG, top, bot);
|
|
|
|
|
foreach (var seed in xdc)
|
|
|
|
|
{
|
|
|
|
|
var B = RNG.XDRNG.Prev(seed);
|
|
|
|
|
var A = RNG.XDRNG.Prev(B);
|
|
|
|
|
|
|
|
|
|
var C = RNG.XDRNG.Advance(A, 7);
|
|
|
|
|
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
yield return new PIDIV { OriginSeed = RNG.XDRNG.Prev(C), RNG = RNGType.XDRNG, Type = PIDType.CXD };
|
2019-01-04 05:29:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static IEnumerable<PIDIV> GetPokeSpotSeeds(PKM pkm, int slot)
|
2017-04-30 23:53:54 +00:00
|
|
|
|
{
|
|
|
|
|
// Activate (rand % 3)
|
|
|
|
|
// Munchlax / Bonsly (10%/30%)
|
|
|
|
|
// Encounter Slot Value (ESV) = 50%/35%/15% rarity (0-49, 50-84, 85-99)
|
|
|
|
|
var pid = pkm.PID;
|
|
|
|
|
var top = pid >> 16;
|
|
|
|
|
var bot = pid & 0xFFFF;
|
2017-08-05 08:51:29 +00:00
|
|
|
|
var seeds = GetSeedsFromPIDEuclid(RNG.XDRNG, top, bot);
|
2017-04-30 23:53:54 +00:00
|
|
|
|
foreach (var seed in seeds)
|
|
|
|
|
{
|
|
|
|
|
// check for valid encounter slot info
|
2018-04-30 01:26:36 +00:00
|
|
|
|
if (!IsPokeSpotActivation(slot, seed, out uint s))
|
|
|
|
|
continue;
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
yield return new PIDIV {OriginSeed = s, RNG = RNGType.XDRNG, Type = PIDType.PokeSpot};
|
2017-04-30 23:53:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2018-04-30 01:26:36 +00:00
|
|
|
|
public static bool IsPokeSpotActivation(int slot, uint seed, out uint s)
|
|
|
|
|
{
|
|
|
|
|
s = seed;
|
|
|
|
|
var esv = (seed >> 16) % 100;
|
2018-06-06 02:08:31 +00:00
|
|
|
|
if (!IsPokeSpotSlotValid(slot, esv))
|
2018-04-30 01:26:36 +00:00
|
|
|
|
{
|
2018-06-06 02:08:31 +00:00
|
|
|
|
// todo
|
2018-04-30 01:26:36 +00:00
|
|
|
|
}
|
|
|
|
|
// check for valid activation
|
|
|
|
|
s = RNG.XDRNG.Prev(seed);
|
|
|
|
|
if ((s >> 16) % 3 != 0)
|
|
|
|
|
{
|
|
|
|
|
if ((s >> 16) % 100 < 10) // can't fail a munchlax/bonsly encounter check
|
2018-06-06 02:08:31 +00:00
|
|
|
|
{
|
|
|
|
|
// todo
|
|
|
|
|
}
|
2018-04-30 01:26:36 +00:00
|
|
|
|
s = RNG.XDRNG.Prev(s);
|
|
|
|
|
if ((s >> 16) % 3 != 0) // can't activate even if generous
|
2018-06-06 02:08:31 +00:00
|
|
|
|
{
|
|
|
|
|
// todo
|
|
|
|
|
}
|
2018-04-30 01:26:36 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2018-06-06 02:08:31 +00:00
|
|
|
|
private static bool IsPokeSpotSlotValid(int slot, uint esv)
|
|
|
|
|
{
|
2019-10-08 01:40:09 +00:00
|
|
|
|
return slot switch
|
2018-06-06 02:08:31 +00:00
|
|
|
|
{
|
2019-10-08 01:40:09 +00:00
|
|
|
|
0 when esv < 50 => true,
|
|
|
|
|
1 when 50 <= esv && esv < 85 => true,
|
|
|
|
|
2 when 85 <= esv => true,
|
|
|
|
|
_ => false
|
|
|
|
|
};
|
2018-06-06 02:08:31 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-03 07:12:05 +00:00
|
|
|
|
public static bool IsCompatible3(this PIDType val, IEncounterable encounter, PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
switch (encounter)
|
|
|
|
|
{
|
|
|
|
|
case WC3 g:
|
2018-07-15 03:19:13 +00:00
|
|
|
|
if (val == g.Method)
|
|
|
|
|
return true;
|
|
|
|
|
// forced shiny eggs, when hatched, can lose their detectable correlation.
|
|
|
|
|
return g.IsEgg && !pkm.IsEgg && val == PIDType.None && (g.Method == PIDType.BACD_R_S || g.Method == PIDType.BACD_U_S);
|
2017-06-03 07:12:05 +00:00
|
|
|
|
case EncounterStatic s:
|
2017-06-04 00:49:37 +00:00
|
|
|
|
switch (pkm.Version)
|
|
|
|
|
{
|
2019-01-06 09:26:18 +00:00
|
|
|
|
case (int)GameVersion.CXD: return val == PIDType.CXD || val == PIDType.CXD_ColoStarter || val == PIDType.CXDAnti;
|
2017-06-04 00:49:37 +00:00
|
|
|
|
case (int)GameVersion.E: return val == PIDType.Method_1; // no roamer glitch
|
|
|
|
|
|
|
|
|
|
case (int)GameVersion.FR:
|
|
|
|
|
case (int)GameVersion.LG:
|
2018-01-25 03:07:03 +00:00
|
|
|
|
return s.Roaming ? val.IsRoamerPIDIV(pkm) : val == PIDType.Method_1; // roamer glitch
|
2017-06-04 00:49:37 +00:00
|
|
|
|
default: // RS, roamer glitch && RSBox s/w emulation => method 4 available
|
2019-06-20 02:15:06 +00:00
|
|
|
|
return s.Roaming ? val.IsRoamerPIDIV(pkm) : MethodH14.Contains(val);
|
2017-06-04 00:49:37 +00:00
|
|
|
|
}
|
2017-06-03 07:12:05 +00:00
|
|
|
|
case EncounterSlot w:
|
|
|
|
|
if (pkm.Version == 15)
|
2017-06-03 22:16:24 +00:00
|
|
|
|
return val == PIDType.PokeSpot;
|
2019-12-09 01:39:19 +00:00
|
|
|
|
return (w.Species == (int)Species.Unown ? MethodH_Unown : MethodH).Contains(val);
|
2017-06-03 07:12:05 +00:00
|
|
|
|
default:
|
|
|
|
|
return val == PIDType.None;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2018-01-25 03:07:03 +00:00
|
|
|
|
private static bool IsRoamerPIDIV(this PIDType val, PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
// Roamer PIDIV is always Method 1.
|
|
|
|
|
// M1 is checked before M1R. A M1R PIDIV can also be a M1 PIDIV, so check that collision.
|
|
|
|
|
if (PIDType.Method_1_Roamer == val)
|
|
|
|
|
return true;
|
|
|
|
|
if (PIDType.Method_1 != val)
|
|
|
|
|
return false;
|
2019-01-05 18:51:41 +00:00
|
|
|
|
|
|
|
|
|
// only 8 bits are stored instead of 32 -- 5 bits HP, 3 bits for ATK.
|
|
|
|
|
return !(pkm.IV_DEF != 0 || pkm.IV_SPE != 0 || pkm.IV_SPA != 0 || pkm.IV_SPD != 0 || pkm.IV_ATK > 7);
|
2018-01-25 03:07:03 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-16 01:34:03 +00:00
|
|
|
|
public static bool IsCompatible4(this PIDType val, IEncounterable encounter, PKM pkm)
|
2017-06-03 07:12:05 +00:00
|
|
|
|
{
|
|
|
|
|
switch (encounter)
|
|
|
|
|
{
|
|
|
|
|
case EncounterStatic s:
|
2019-05-11 03:46:49 +00:00
|
|
|
|
if (s == Encounters4.SpikyEaredPichu || (s.Location == Locations.PokeWalker4 && s.Gift)) // Pokewalker
|
2017-06-25 00:20:15 +00:00
|
|
|
|
return val == PIDType.Pokewalker;
|
2018-03-17 02:35:55 +00:00
|
|
|
|
if (s.Shiny == Shiny.Always)
|
2017-10-02 04:25:23 +00:00
|
|
|
|
return val == PIDType.ChainShiny;
|
2017-10-13 06:18:43 +00:00
|
|
|
|
if (val == PIDType.CuteCharm && IsCuteCharm4Valid(encounter, pkm))
|
2017-10-02 04:25:23 +00:00
|
|
|
|
return true;
|
|
|
|
|
return val == PIDType.Method_1;
|
2017-07-07 11:53:21 +00:00
|
|
|
|
case EncounterSlot sl:
|
|
|
|
|
if (val == PIDType.Method_1)
|
|
|
|
|
return true;
|
2017-10-13 06:18:43 +00:00
|
|
|
|
if (val == PIDType.CuteCharm && IsCuteCharm4Valid(encounter, pkm))
|
2018-05-07 23:14:31 +00:00
|
|
|
|
return true;
|
2017-07-07 11:53:21 +00:00
|
|
|
|
if (val != PIDType.ChainShiny)
|
|
|
|
|
return false;
|
|
|
|
|
// Chain shiny with poke radar is only possible in DPPt in tall grass, safari zone do not allow pokeradar
|
|
|
|
|
// TypeEncounter TallGrass discard any cave or city
|
2019-01-06 09:26:18 +00:00
|
|
|
|
var ver = (GameVersion)pkm.Version;
|
|
|
|
|
var IsDPPt = ver == GameVersion.D || ver == GameVersion.P || ver == GameVersion.Pt;
|
2017-07-25 07:28:43 +00:00
|
|
|
|
return pkm.IsShiny && IsDPPt && sl.TypeEncounter == EncounterType.TallGrass && !Encounters4.SafariZoneLocation_4.Contains(sl.Location);
|
2017-06-16 01:34:03 +00:00
|
|
|
|
case PGT _: // manaphy
|
|
|
|
|
return IsG4ManaphyPIDValid(val, pkm);
|
2018-10-20 03:27:18 +00:00
|
|
|
|
case PCD d when d.Gift.PK.PID != 1:
|
|
|
|
|
return true; // already matches PCD's fixed PID requirement
|
2017-10-02 04:25:23 +00:00
|
|
|
|
default: // eggs
|
2017-06-03 07:12:05 +00:00
|
|
|
|
return val == PIDType.None;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-06-16 01:34:03 +00:00
|
|
|
|
private static bool IsG4ManaphyPIDValid(PIDType val, PKM pkm)
|
|
|
|
|
{
|
2017-07-06 00:47:48 +00:00
|
|
|
|
if (pkm.IsEgg)
|
|
|
|
|
{
|
|
|
|
|
if (pkm.IsShiny)
|
|
|
|
|
return false;
|
|
|
|
|
if (val == PIDType.Method_1)
|
|
|
|
|
return true;
|
|
|
|
|
return val == PIDType.G4MGAntiShiny && IsAntiShinyARNG();
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-16 01:34:03 +00:00
|
|
|
|
if (val == PIDType.Method_1)
|
|
|
|
|
return pkm.WasTradedEgg || !pkm.IsShiny; // can't be shiny on received game
|
2017-07-06 00:47:48 +00:00
|
|
|
|
return val == PIDType.G4MGAntiShiny && (pkm.WasTradedEgg || IsAntiShinyARNG());
|
|
|
|
|
|
|
|
|
|
bool IsAntiShinyARNG()
|
|
|
|
|
{
|
|
|
|
|
var shinyPID = RNG.ARNG.Prev(pkm.PID);
|
|
|
|
|
return (pkm.TID ^ pkm.SID ^ (shinyPID & 0xFFFF) ^ (shinyPID >> 16)) < 8; // shiny proc
|
|
|
|
|
}
|
2017-06-16 01:34:03 +00:00
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-10-13 06:18:43 +00:00
|
|
|
|
private static bool IsCuteCharm4Valid(IEncounterable encounter, PKM pkm)
|
|
|
|
|
{
|
2019-06-01 17:22:49 +00:00
|
|
|
|
if (pkm.Species == (int)Species.Marill || pkm.Species == (int)Species.Azumarill)
|
2018-08-03 03:11:42 +00:00
|
|
|
|
{
|
2017-10-13 06:18:43 +00:00
|
|
|
|
return !IsCuteCharmAzurillMale(pkm.PID) // recognized as not Azurill
|
2019-06-01 17:22:49 +00:00
|
|
|
|
|| encounter.Species == (int)Species.Azurill; // encounter must be male Azurill
|
2018-08-03 03:11:42 +00:00
|
|
|
|
}
|
2017-10-13 06:18:43 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-10-13 06:18:43 +00:00
|
|
|
|
private static bool IsCuteCharmAzurillMale(uint pid) => pid >= 0xC8 && pid <= 0xE0;
|
2018-08-03 03:11:42 +00:00
|
|
|
|
|
2017-10-13 06:18:43 +00:00
|
|
|
|
private static void GetCuteCharmGenderSpecies(PKM pk, uint pid, out int genderValue, out int species)
|
|
|
|
|
{
|
|
|
|
|
// There are some edge cases when the gender ratio changes across evolutions.
|
|
|
|
|
species = pk.Species;
|
2019-06-01 17:22:49 +00:00
|
|
|
|
if (species == (int)Species.Ninjask)
|
2017-10-13 06:18:43 +00:00
|
|
|
|
{
|
2019-06-01 17:22:49 +00:00
|
|
|
|
species = (int)Species.Nincada; // Nincada evo chain travels from M/F -> Genderless Shedinja
|
|
|
|
|
genderValue = PKX.GetGenderFromPID(species, pid);
|
2017-10-13 06:18:43 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (species)
|
|
|
|
|
{
|
|
|
|
|
// These evolved species cannot be encountered with cute charm.
|
|
|
|
|
// 100% fixed gender does not modify PID; override this with the encounter species for correct calculation.
|
|
|
|
|
// We can assume the re-mapped species's [gender ratio] is what was encountered.
|
|
|
|
|
|
2019-06-01 17:22:49 +00:00
|
|
|
|
case (int)Species.Wormadam: species = (int)Species.Burmy; break; // Wormadam -> Burmy
|
|
|
|
|
case (int)Species.Mothim: species = (int)Species.Burmy; break; // Mothim -> Burmy
|
|
|
|
|
case (int)Species.Vespiquen: species = (int)Species.Combee; break; // Vespiquen -> Combee
|
|
|
|
|
case (int)Species.Gallade: species = (int)Species.Kirlia; break; // Gallade -> Kirlia/Ralts
|
|
|
|
|
case (int)Species.Froslass: species = (int)Species.Snorunt; break; // Froslass -> Snorunt
|
2017-10-13 06:18:43 +00:00
|
|
|
|
|
|
|
|
|
// Changed gender ratio (25% M -> 50% M) needs special treatment.
|
|
|
|
|
// Double check the encounter species with IsCuteCharm4Valid afterwards.
|
2019-06-01 17:22:49 +00:00
|
|
|
|
case (int)Species.Marill: case (int)Species.Azumarill: // Azurill & Marill/Azumarill collision
|
2017-10-13 06:18:43 +00:00
|
|
|
|
if (IsCuteCharmAzurillMale(pid))
|
|
|
|
|
{
|
2019-06-01 17:22:49 +00:00
|
|
|
|
species = (int)Species.Azurill;
|
2017-10-13 06:18:43 +00:00
|
|
|
|
genderValue = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
genderValue = pk.Gender;
|
|
|
|
|
}
|
2017-06-03 07:12:05 +00:00
|
|
|
|
|
2019-06-20 02:15:06 +00:00
|
|
|
|
private static readonly PIDType[] MethodH = { PIDType.Method_1, PIDType.Method_2, PIDType.Method_3, PIDType.Method_4 };
|
2017-06-04 00:49:37 +00:00
|
|
|
|
private static readonly PIDType[] MethodH14 = { PIDType.Method_1, PIDType.Method_4 };
|
2019-06-20 02:15:06 +00:00
|
|
|
|
private static readonly PIDType[] MethodH_Unown = { PIDType.Method_1_Unown, PIDType.Method_2_Unown, PIDType.Method_3_Unown, PIDType.Method_4_Unown };
|
2017-04-29 23:22:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|