2018-12-30 05:24:38 +00:00
using System ;
namespace PKHeX.Core
{
2018-12-30 07:38:59 +00:00
/// <summary>
/// Record of a received <see cref="WB7"/> file.
/// </summary>
/// <remarks>
/// A full <see cref="WB7"/> is not stored in the <see cref="SAV7b"/> structure, as it is immediately converted to <see cref="PKM"/> upon receiving from server.
/// The save file just stores a summary of the received data for the user to look back at.
/// </remarks>
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
public sealed class WR7 : DataMysteryGift
2018-12-30 05:24:38 +00:00
{
2018-12-30 07:33:36 +00:00
public const int Size = 0x140 ;
Fracture the encounter matching checks to allow progressive validation (#3137)
## Issue
We want to discard-but-remember any slots that aren't a perfect fit, on the off chance that a better one exists later in the search space. If there's no better match, then we gotta go with what we got.
## Example:
Wurmple exists in area `X`, and also has a more rare slot for Silcoon, with the same level for both slots.
* We have a Silcoon that we've leveled up a few times.
Was our Silcoon originally a Wurmple, or was it caught as a Silcoon?
* To be sure, we have to check the EC/PID if the Wurmple wouldn't evolve into Cascoon instead.
* We don't want to wholly reject that Wurmple slot, as maybe the Met Level isn't within Silcoon's slot range.
---
Existing implementation would store "deferred" matches in a list; we only need to keep 1 of these matches around (less allocation!). We also want to differentiate between a "good" deferral and a "bad" deferral; I don't think this is necessary but it's currently used by Mystery Gift matching (implemented for the Eeveelution mystery gifts which matter for evolution moves).
The existing logic didn't use inheritance, and instead had static methods being reused across generations. Quite kludgy. Also, the existing logic was a pain to modify the master encounter yield methods, as one generation's quirks had to not impact all other generations that used the method.
---
The new implementation splits out the encounter yielding methods to be separate for each generation / subset. Now, things don't have to check `WasLink` for Gen7 origin, because Pokémon Link wasn't a thing in Gen7.
---
## Future
Maybe refactoring yielders into "GameCores" that expose yielding behaviors / properties, rather than the static logic. As more generations and side-gamegroups get added (thanks LGPE/GO/GameCube), all this switch stuff gets annoying to maintain instead of just overriding/inheritance.
## Conclusion
This shouldn't impact any legality results negatively; if you notice any regressions, report them! This should reduce false flags where we didn't defer-discard an encounter when we should have (wild area mons being confused with raids).
2021-01-30 01:55:27 +00:00
public override int Generation = > 7 ;
2018-12-30 05:24:38 +00:00
2021-08-26 22:47:44 +00:00
public override GameVersion Version { get = > GameVersion . GG ; set { } }
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
public WR7 ( ) : this ( new byte [ Size ] ) { }
public WR7 ( byte [ ] data ) : base ( data ) { }
2018-12-30 05:24:38 +00:00
2021-12-09 08:46:59 +00:00
public override int Ability = > - 1 ; // undefined
2018-12-30 05:24:38 +00:00
public uint Epoch
{
get = > BitConverter . ToUInt32 ( Data , 0x00 ) ;
set = > BitConverter . GetBytes ( value ) . CopyTo ( Data , 0x00 ) ;
}
public DateTime Date = > new DateTime ( 1970 , 1 , 1 , 0 , 0 , 0 , DateTimeKind . Utc ) . AddSeconds ( Epoch ) ;
2018-12-30 06:09:27 +00:00
public override int CardID
2018-12-30 05:24:38 +00:00
{
get = > BitConverter . ToUInt16 ( Data , 0x08 ) ;
2018-12-30 06:09:27 +00:00
set = > BitConverter . GetBytes ( ( ushort ) value ) . CopyTo ( Data , 0x08 ) ;
2018-12-30 05:24:38 +00:00
}
public ushort CardType
{
get = > BitConverter . ToUInt16 ( Data , 0x0A ) ;
set = > BitConverter . GetBytes ( value ) . CopyTo ( Data , 0x0A ) ;
}
2018-12-30 06:09:27 +00:00
public WR7GiftType GiftType
2018-12-30 05:24:38 +00:00
{
2018-12-30 06:09:27 +00:00
get = > ( WR7GiftType ) Data [ 0x0C ] ;
2018-12-30 05:24:38 +00:00
set = > Data [ 0x0C ] = ( byte ) value ;
}
public int ItemCount
{
get = > Data [ 0x0D ] ;
set = > Data [ 0x0D ] = ( byte ) value ;
}
2018-12-30 07:38:59 +00:00
// unknown: region from 0x10 to 0xFF ?
2018-12-30 06:09:27 +00:00
public override int Species
2018-12-30 05:24:38 +00:00
{
get = > BitConverter . ToUInt16 ( Data , 0x10C ) ;
2018-12-30 06:09:27 +00:00
set = > BitConverter . GetBytes ( ( ushort ) value ) . CopyTo ( Data , 0x10C ) ;
2018-12-30 05:24:38 +00:00
}
2018-12-30 06:09:27 +00:00
public override bool GiftUsed { get ; set ; }
2018-12-30 07:38:59 +00:00
public override int Level // are moves stored? mew has '1' but this could be move
2018-12-30 05:24:38 +00:00
{
get = > BitConverter . ToUInt16 ( Data , 0x10E ) ;
2018-12-30 06:09:27 +00:00
set = > BitConverter . GetBytes ( ( ushort ) value ) . CopyTo ( Data , 0x10E ) ;
2018-12-30 05:24:38 +00:00
}
2018-12-30 06:09:27 +00:00
public override int ItemID { get = > BitConverter . ToUInt16 ( Data , 0x110 ) ; set = > BitConverter . GetBytes ( ( ushort ) value ) . CopyTo ( Data , 0x110 ) ; }
public ushort ItemIDCount { get = > BitConverter . ToUInt16 ( Data , 0x112 ) ; set = > BitConverter . GetBytes ( value ) . CopyTo ( Data , 0x112 ) ; }
2018-12-30 05:24:38 +00:00
public ushort ItemSet2Item { get = > BitConverter . ToUInt16 ( Data , 0x114 ) ; set = > BitConverter . GetBytes ( value ) . CopyTo ( Data , 0x114 ) ; }
public ushort ItemSet2Count { get = > BitConverter . ToUInt16 ( Data , 0x116 ) ; set = > BitConverter . GetBytes ( value ) . CopyTo ( Data , 0x116 ) ; }
public ushort ItemSet3Item { get = > BitConverter . ToUInt16 ( Data , 0x118 ) ; set = > BitConverter . GetBytes ( value ) . CopyTo ( Data , 0x118 ) ; }
public ushort ItemSet3Count { get = > BitConverter . ToUInt16 ( Data , 0x11A ) ; set = > BitConverter . GetBytes ( value ) . CopyTo ( Data , 0x11A ) ; }
public ushort ItemSet4Item { get = > BitConverter . ToUInt16 ( Data , 0x11C ) ; set = > BitConverter . GetBytes ( value ) . CopyTo ( Data , 0x11C ) ; }
public ushort ItemSet4Count { get = > BitConverter . ToUInt16 ( Data , 0x11E ) ; set = > BitConverter . GetBytes ( value ) . CopyTo ( Data , 0x11E ) ; }
public ushort ItemSet5Item { get = > BitConverter . ToUInt16 ( Data , 0x120 ) ; set = > BitConverter . GetBytes ( value ) . CopyTo ( Data , 0x120 ) ; } // struct union overlaps OT Name data, beware!
public ushort ItemSet5Count { get = > BitConverter . ToUInt16 ( Data , 0x122 ) ; set = > BitConverter . GetBytes ( value ) . CopyTo ( Data , 0x122 ) ; }
public ushort ItemSet6Item { get = > BitConverter . ToUInt16 ( Data , 0x124 ) ; set = > BitConverter . GetBytes ( value ) . CopyTo ( Data , 0x124 ) ; }
public ushort ItemSet6Count { get = > BitConverter . ToUInt16 ( Data , 0x126 ) ; set = > BitConverter . GetBytes ( value ) . CopyTo ( Data , 0x126 ) ; }
2018-12-30 06:09:27 +00:00
public override int Gender { get ; set ; }
public override int Form { get ; set ; }
public override int TID { get ; set ; }
public override int SID { get ; set ; }
public override string OT_Name
2018-12-30 05:24:38 +00:00
{
2021-04-19 01:29:02 +00:00
get = > StringConverter . GetString7b ( Data , 0x120 , 0x1A ) ;
2021-01-15 06:50:13 +00:00
set = > StringConverter . SetString7b ( value , 12 , 13 ) . CopyTo ( Data , 0x120 + 0xB6 ) ; // careful with length
2018-12-30 05:24:38 +00:00
}
public LanguageID LanguageReceived
{
get = > ( LanguageID ) Data [ 0x13A ] ;
set = > Data [ 0x13A ] = ( byte ) value ;
}
Fracture the encounter matching checks to allow progressive validation (#3137)
## Issue
We want to discard-but-remember any slots that aren't a perfect fit, on the off chance that a better one exists later in the search space. If there's no better match, then we gotta go with what we got.
## Example:
Wurmple exists in area `X`, and also has a more rare slot for Silcoon, with the same level for both slots.
* We have a Silcoon that we've leveled up a few times.
Was our Silcoon originally a Wurmple, or was it caught as a Silcoon?
* To be sure, we have to check the EC/PID if the Wurmple wouldn't evolve into Cascoon instead.
* We don't want to wholly reject that Wurmple slot, as maybe the Met Level isn't within Silcoon's slot range.
---
Existing implementation would store "deferred" matches in a list; we only need to keep 1 of these matches around (less allocation!). We also want to differentiate between a "good" deferral and a "bad" deferral; I don't think this is necessary but it's currently used by Mystery Gift matching (implemented for the Eeveelution mystery gifts which matter for evolution moves).
The existing logic didn't use inheritance, and instead had static methods being reused across generations. Quite kludgy. Also, the existing logic was a pain to modify the master encounter yield methods, as one generation's quirks had to not impact all other generations that used the method.
---
The new implementation splits out the encounter yielding methods to be separate for each generation / subset. Now, things don't have to check `WasLink` for Gen7 origin, because Pokémon Link wasn't a thing in Gen7.
---
## Future
Maybe refactoring yielders into "GameCores" that expose yielding behaviors / properties, rather than the static logic. As more generations and side-gamegroups get added (thanks LGPE/GO/GameCube), all this switch stuff gets annoying to maintain instead of just overriding/inheritance.
## Conclusion
This shouldn't impact any legality results negatively; if you notice any regressions, report them! This should reduce false flags where we didn't defer-discard an encounter when we should have (wild area mons being confused with raids).
2021-01-30 01:55:27 +00:00
// Mystery Gift implementation, unused.
public override bool IsMatchExact ( PKM pkm , DexLevel evo ) = > false ;
2018-12-30 06:09:27 +00:00
protected override bool IsMatchDeferred ( PKM pkm ) = > false ;
Fracture the encounter matching checks to allow progressive validation (#3137)
## Issue
We want to discard-but-remember any slots that aren't a perfect fit, on the off chance that a better one exists later in the search space. If there's no better match, then we gotta go with what we got.
## Example:
Wurmple exists in area `X`, and also has a more rare slot for Silcoon, with the same level for both slots.
* We have a Silcoon that we've leveled up a few times.
Was our Silcoon originally a Wurmple, or was it caught as a Silcoon?
* To be sure, we have to check the EC/PID if the Wurmple wouldn't evolve into Cascoon instead.
* We don't want to wholly reject that Wurmple slot, as maybe the Met Level isn't within Silcoon's slot range.
---
Existing implementation would store "deferred" matches in a list; we only need to keep 1 of these matches around (less allocation!). We also want to differentiate between a "good" deferral and a "bad" deferral; I don't think this is necessary but it's currently used by Mystery Gift matching (implemented for the Eeveelution mystery gifts which matter for evolution moves).
The existing logic didn't use inheritance, and instead had static methods being reused across generations. Quite kludgy. Also, the existing logic was a pain to modify the master encounter yield methods, as one generation's quirks had to not impact all other generations that used the method.
---
The new implementation splits out the encounter yielding methods to be separate for each generation / subset. Now, things don't have to check `WasLink` for Gen7 origin, because Pokémon Link wasn't a thing in Gen7.
---
## Future
Maybe refactoring yielders into "GameCores" that expose yielding behaviors / properties, rather than the static logic. As more generations and side-gamegroups get added (thanks LGPE/GO/GameCube), all this switch stuff gets annoying to maintain instead of just overriding/inheritance.
## Conclusion
This shouldn't impact any legality results negatively; if you notice any regressions, report them! This should reduce false flags where we didn't defer-discard an encounter when we should have (wild area mons being confused with raids).
2021-01-30 01:55:27 +00:00
protected override bool IsMatchPartial ( PKM pkm ) = > false ;
2018-12-30 06:09:27 +00:00
public override int Location { get ; set ; }
public override int EggLocation { get ; set ; }
public override int Ball { get ; set ; } = 4 ;
2018-12-30 06:15:40 +00:00
public override string CardTitle { get = > $"{nameof(WB7)} Record ({OT_Name}) [{LanguageReceived}]" ; set { } }
2018-12-30 06:09:27 +00:00
public override bool IsItem
{
get = > GiftType = = WR7GiftType . Item ;
set
{
if ( value )
GiftType = WR7GiftType . Item ;
}
}
public override bool IsPokémon
{
get = > GiftType = = WR7GiftType . Pokemon ;
set
{
if ( value )
GiftType = WR7GiftType . Pokemon ;
}
}
2018-12-30 07:33:36 +00:00
2020-06-17 02:46:22 +00:00
public override PKM ConvertToPKM ( ITrainerInfo sav , EncounterCriteria criteria )
2018-12-30 07:33:36 +00:00
{
2018-12-30 07:38:59 +00:00
// this method shouldn't really be called, use the WB7 data not the WR7 data.
2018-12-30 07:33:36 +00:00
if ( ! IsPokémon )
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
throw new ArgumentException ( nameof ( IsPokémon ) ) ;
2018-12-30 07:33:36 +00:00
2018-12-30 07:38:59 +00:00
// we'll just generate something as close as we can, since we must return something!
2018-12-30 07:33:36 +00:00
var pk = new PB7 ( ) ;
2020-06-17 02:46:22 +00:00
sav . ApplyTo ( pk ) ;
if ( ! GameVersion . GG . Contains ( ( GameVersion ) sav . Game ) )
2018-12-30 07:33:36 +00:00
pk . Version = ( int ) GameVersion . GP ;
pk . Species = Species ;
pk . Met_Level = pk . CurrentLevel = Level ;
2018-12-30 07:38:59 +00:00
pk . MetDate = Date ;
2018-12-30 07:33:36 +00:00
2018-12-30 07:38:59 +00:00
return pk ; // can't really do much more, just return the rough data
2018-12-30 07:33:36 +00:00
}
2018-12-30 05:24:38 +00:00
}
}