2016-06-20 04:22:43 +00:00
|
|
|
|
using System;
|
2017-07-02 02:43:51 +00:00
|
|
|
|
using System.Diagnostics;
|
2016-09-26 23:14:11 +00:00
|
|
|
|
using System.Linq;
|
2017-05-12 04:34:18 +00:00
|
|
|
|
using System.Reflection;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2018-07-24 22:36:46 +00:00
|
|
|
|
using static PKHeX.Core.MessageStrings;
|
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.Core
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-10-24 06:12:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Logic for converting a <see cref="PKM"/> from one generation specific format to another.
|
|
|
|
|
/// </summary>
|
2016-08-08 20:47:56 +00:00
|
|
|
|
public static class PKMConverter
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2020-01-06 05:51:02 +00:00
|
|
|
|
public static void SetPrimaryTrainer(ITrainerInfo t)
|
|
|
|
|
{
|
|
|
|
|
Trainer = t;
|
|
|
|
|
if (t.ConsoleRegion != 0)
|
|
|
|
|
Trainer67 = t;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static ITrainerInfo Trainer { get; set; } = new SimpleTrainerInfo();
|
|
|
|
|
private static ITrainerInfo Trainer67 { get; set; } = new SimpleTrainerInfo(GameVersion.SN);
|
2018-07-13 01:15:20 +00:00
|
|
|
|
public static string OT_Name => Trainer.OT;
|
|
|
|
|
public static int OT_Gender => Trainer.Gender;
|
|
|
|
|
public static int Language => Trainer.Language;
|
|
|
|
|
public static int Format => Trainer.Generation;
|
2020-01-06 05:51:02 +00:00
|
|
|
|
public static int Game => Trainer.Game;
|
2018-01-29 06:47:03 +00:00
|
|
|
|
public static bool AllowIncompatibleConversion { private get; set; }
|
2017-01-08 07:54:09 +00:00
|
|
|
|
|
2020-01-06 05:41:32 +00:00
|
|
|
|
public static void SetConsoleRegionData3DS(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
var trainer = Trainer.ConsoleRegion != 0 ? Trainer : Trainer67;
|
|
|
|
|
pkm.ConsoleRegion = trainer.ConsoleRegion;
|
|
|
|
|
pkm.Country = trainer.Country;
|
|
|
|
|
pkm.Region = trainer.SubRegion;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void SetFirstCountryRegion(IGeoTrack pkm)
|
|
|
|
|
{
|
|
|
|
|
var trainer = Trainer.ConsoleRegion != 0 ? Trainer : Trainer67;
|
|
|
|
|
pkm.Geo1_Country = trainer.Country;
|
|
|
|
|
pkm.Geo1_Region = trainer.SubRegion;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-08 20:47:56 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the generation of the Pokemon data.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="data">Raw data representing a Pokemon.</param>
|
|
|
|
|
/// <returns>An integer indicating the generation of the PKM file, or -1 if the data is invalid.</returns>
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static int GetPKMDataFormat(byte[] data)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (!PKX.IsPKM(data.Length))
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
switch (data.Length)
|
|
|
|
|
{
|
2020-01-04 22:48:39 +00:00
|
|
|
|
case PokeCrypto.SIZE_1JLIST:
|
|
|
|
|
case PokeCrypto.SIZE_1ULIST:
|
2016-08-29 05:21:55 +00:00
|
|
|
|
return 1;
|
2020-01-04 22:48:39 +00:00
|
|
|
|
case PokeCrypto.SIZE_2ULIST:
|
|
|
|
|
case PokeCrypto.SIZE_2JLIST:
|
2016-09-04 01:57:54 +00:00
|
|
|
|
return 2;
|
2020-01-04 22:48:39 +00:00
|
|
|
|
case PokeCrypto.SIZE_3PARTY:
|
|
|
|
|
case PokeCrypto.SIZE_3STORED:
|
|
|
|
|
case PokeCrypto.SIZE_3CSTORED:
|
|
|
|
|
case PokeCrypto.SIZE_3XSTORED:
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return 3;
|
2020-01-04 22:48:39 +00:00
|
|
|
|
case PokeCrypto.SIZE_4PARTY:
|
|
|
|
|
case PokeCrypto.SIZE_4STORED:
|
|
|
|
|
case PokeCrypto.SIZE_5PARTY:
|
2016-10-23 03:09:22 +00:00
|
|
|
|
if ((BitConverter.ToUInt16(data, 0x4) == 0) && (BitConverter.ToUInt16(data, 0x80) >= 0x3333 || data[0x5F] >= 0x10) && BitConverter.ToUInt16(data, 0x46) == 0) // PK5
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return 5;
|
|
|
|
|
return 4;
|
2020-01-04 22:48:39 +00:00
|
|
|
|
case PokeCrypto.SIZE_6STORED:
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return 6;
|
2020-01-04 22:48:39 +00:00
|
|
|
|
case PokeCrypto.SIZE_6PARTY: // collision with PGT, same size.
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (BitConverter.ToUInt16(data, 0x4) != 0) // Bad Sanity?
|
|
|
|
|
return -1;
|
2020-01-04 22:48:39 +00:00
|
|
|
|
if (BitConverter.ToUInt32(data, 0x06) == PokeCrypto.GetCHK(data))
|
2016-07-04 01:27:12 +00:00
|
|
|
|
return 6;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (BitConverter.ToUInt16(data, 0x58) != 0) // Encrypted?
|
|
|
|
|
{
|
|
|
|
|
for (int i = data.Length - 0x10; i < data.Length; i++) // 0x10 of 00's at the end != PK6
|
2018-07-29 20:27:48 +00:00
|
|
|
|
{
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (data[i] != 0)
|
2016-07-04 01:27:12 +00:00
|
|
|
|
return 6;
|
2018-07-29 20:27:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-04 01:27:12 +00:00
|
|
|
|
return -1;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2016-07-04 01:27:12 +00:00
|
|
|
|
return 6;
|
2020-01-04 22:48:39 +00:00
|
|
|
|
case PokeCrypto.SIZE_8PARTY:
|
|
|
|
|
case PokeCrypto.SIZE_8STORED:
|
2019-09-23 23:56:47 +00:00
|
|
|
|
return 8;
|
2019-04-10 03:58:19 +00:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return -1;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-08 21:44:05 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates an instance of <see cref="PKM"/> from the given data.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="data">Raw data of the Pokemon file.</param>
|
2017-01-28 07:33:36 +00:00
|
|
|
|
/// <param name="prefer">Optional identifier for the preferred generation. Usually the generation of the destination save file.</param>
|
2016-08-08 21:44:05 +00:00
|
|
|
|
/// <returns>An instance of <see cref="PKM"/> created from the given <paramref name="data"/>, or null if <paramref name="data"/> is invalid.</returns>
|
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 static PKM? GetPKMfromBytes(byte[] data, int prefer = 7)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2018-06-05 03:25:54 +00:00
|
|
|
|
int format = GetPKMDataFormat(data);
|
|
|
|
|
switch (format)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2016-08-29 05:21:55 +00:00
|
|
|
|
case 1:
|
2018-08-06 00:28:54 +00:00
|
|
|
|
var PL1 = new PokeList1(data);
|
2016-09-04 01:57:54 +00:00
|
|
|
|
return PL1[0];
|
|
|
|
|
case 2:
|
2018-08-06 00:28:54 +00:00
|
|
|
|
var PL2 = new PokeList2(data);
|
2016-09-04 01:57:54 +00:00
|
|
|
|
return PL2[0];
|
2016-06-20 04:22:43 +00:00
|
|
|
|
case 3:
|
2019-10-08 01:40:09 +00:00
|
|
|
|
return data.Length switch
|
|
|
|
|
{
|
2020-01-04 22:48:39 +00:00
|
|
|
|
PokeCrypto.SIZE_3CSTORED => new CK3(data),
|
|
|
|
|
PokeCrypto.SIZE_3XSTORED => new XK3(data),
|
2020-01-07 01:50:18 +00:00
|
|
|
|
_ => new PK3(data)
|
2019-10-08 01:40:09 +00:00
|
|
|
|
};
|
2016-06-20 04:22:43 +00:00
|
|
|
|
case 4:
|
2020-03-20 16:28:16 +00:00
|
|
|
|
if (BitConverter.ToUInt16(data, 0x04) != 0)
|
2020-03-19 06:34:53 +00:00
|
|
|
|
return new BK4(data);
|
|
|
|
|
return new PK4(data);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
case 5:
|
2019-03-17 01:41:56 +00:00
|
|
|
|
return new PK5(data);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
case 6:
|
2019-03-17 01:41:56 +00:00
|
|
|
|
var pkx = new PK6(data);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return CheckPKMFormat7(pkx, prefer);
|
2019-09-23 23:56:47 +00:00
|
|
|
|
case 8:
|
|
|
|
|
return new PK8(data);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2017-01-27 03:18:20 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if the input PK6 file is really a PK7, if so, updates the object.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pk">PKM to check</param>
|
2017-01-28 07:33:36 +00:00
|
|
|
|
/// <param name="prefer">Prefer a certain generation over another</param>
|
2017-01-27 03:18:20 +00:00
|
|
|
|
/// <returns>Updated PKM if actually PK7</returns>
|
2019-10-26 19:42:33 +00:00
|
|
|
|
private static G6PKM CheckPKMFormat7(PK6 pk, int prefer)
|
2018-11-14 03:10:31 +00:00
|
|
|
|
{
|
|
|
|
|
if (GameVersion.GG.Contains(pk.Version))
|
|
|
|
|
return new PB7(pk.Data);
|
2019-09-23 23:56:47 +00:00
|
|
|
|
if (IsPK6FormatReallyPK7(pk, prefer))
|
|
|
|
|
return new PK7(pk.Data);
|
|
|
|
|
return pk;
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
2018-07-29 20:27:48 +00:00
|
|
|
|
|
2017-01-27 03:18:20 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if the input PK6 file is really a PK7.
|
|
|
|
|
/// </summary>
|
2017-01-28 07:33:36 +00:00
|
|
|
|
/// <param name="pk">PK6 to check</param>
|
2017-09-08 06:18:04 +00:00
|
|
|
|
/// <param name="preferredFormat">Prefer a certain generation over another</param>
|
2017-01-27 03:18:20 +00:00
|
|
|
|
/// <returns>Boolean is a PK7</returns>
|
2017-09-08 06:18:04 +00:00
|
|
|
|
private static bool IsPK6FormatReallyPK7(PK6 pk, int preferredFormat)
|
2017-01-27 03:18:20 +00:00
|
|
|
|
{
|
|
|
|
|
if (pk.Version > Legal.MaxGameID_6)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
// Check Ranges
|
|
|
|
|
if (pk.Species > Legal.MaxSpeciesID_6)
|
|
|
|
|
return true;
|
|
|
|
|
if (pk.Moves.Any(move => move > Legal.MaxMoveID_6_AO))
|
|
|
|
|
return true;
|
|
|
|
|
if (pk.RelearnMoves.Any(move => move > Legal.MaxMoveID_6_AO))
|
|
|
|
|
return true;
|
|
|
|
|
if (pk.Ability > Legal.MaxAbilityID_6_AO)
|
|
|
|
|
return true;
|
|
|
|
|
if (pk.HeldItem > Legal.MaxItemID_6_AO)
|
|
|
|
|
return true;
|
|
|
|
|
|
2017-01-28 07:33:36 +00:00
|
|
|
|
int et = pk.EncounterType;
|
|
|
|
|
if (et != 0)
|
|
|
|
|
{
|
|
|
|
|
if (pk.CurrentLevel < 100) // can't be hyper trained
|
|
|
|
|
return false;
|
|
|
|
|
|
2019-02-22 04:41:04 +00:00
|
|
|
|
if (!pk.Gen4) // can't have encounter type
|
2017-01-28 07:33:36 +00:00
|
|
|
|
return true;
|
2019-03-29 04:44:06 +00:00
|
|
|
|
if (et > 24) // invalid gen4 EncounterType
|
2017-01-28 07:33:36 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-01-28 05:36:39 +00:00
|
|
|
|
|
2017-01-28 18:10:15 +00:00
|
|
|
|
int mb = BitConverter.ToUInt16(pk.Data, 0x16);
|
|
|
|
|
if (mb > 0xAAA)
|
|
|
|
|
return false;
|
|
|
|
|
for (int i = 0; i < 6; i++)
|
2018-07-29 20:27:48 +00:00
|
|
|
|
{
|
2017-01-28 18:10:15 +00:00
|
|
|
|
if ((mb >> (i << 1) & 3) == 3) // markings are 10 or 01 (or 00), never 11
|
|
|
|
|
return false;
|
2018-07-29 20:27:48 +00:00
|
|
|
|
}
|
2017-01-28 18:10:15 +00:00
|
|
|
|
|
2018-08-28 03:44:26 +00:00
|
|
|
|
if (pk.Data[0x2A] > 20) // ResortEventStatus is always < 20
|
|
|
|
|
return false;
|
|
|
|
|
|
2017-09-08 06:18:04 +00:00
|
|
|
|
return preferredFormat > 6;
|
2017-01-27 03:18:20 +00:00
|
|
|
|
}
|
2017-01-08 07:54:09 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if the input <see cref="PKM"/> file is capable of being converted to the desired format.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pk"></param>
|
|
|
|
|
/// <param name="format"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool IsConvertibleToFormat(PKM pk, int format)
|
|
|
|
|
{
|
|
|
|
|
if (pk.Format >= 3 && pk.Format > format)
|
|
|
|
|
return false; // pk3->upward can't go backwards
|
|
|
|
|
if (pk.Format <= 2 && format > 2 && format < 7)
|
|
|
|
|
return false; // pk1/2->upward has to be 7 or greater
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-09-08 06:18:04 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-12-20 06:10:32 +00:00
|
|
|
|
/// Converts a PKM from one Generation format to another. If it matches the destination format, the conversion will automatically return.
|
2017-09-08 06:18:04 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pk">PKM to convert</param>
|
|
|
|
|
/// <param name="PKMType">Format/Type to convert to</param>
|
2018-05-12 19:28:48 +00:00
|
|
|
|
/// <param name="comment">Comments regarding the transfer's success/failure</param>
|
2017-09-08 06:18:04 +00:00
|
|
|
|
/// <returns>Converted PKM</returns>
|
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 static PKM? ConvertToType(PKM pk, Type PKMType, out string comment)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2016-09-26 23:14:11 +00:00
|
|
|
|
Type fromType = pk.GetType();
|
|
|
|
|
if (fromType == PKMType)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
comment = "No need to convert, current format matches requested format.";
|
|
|
|
|
return pk;
|
|
|
|
|
}
|
2017-09-08 06:18:04 +00:00
|
|
|
|
|
2018-01-29 06:47:03 +00:00
|
|
|
|
var pkm = ConvertPKM(pk, PKMType, fromType, out comment);
|
2018-06-05 04:32:15 +00:00
|
|
|
|
if (!AllowIncompatibleConversion || pkm != null)
|
2018-01-29 06:47:03 +00:00
|
|
|
|
return pkm;
|
|
|
|
|
|
|
|
|
|
// Try Incompatible Conversion
|
|
|
|
|
pkm = GetBlank(PKMType);
|
2018-02-03 23:32:45 +00:00
|
|
|
|
pk.TransferPropertiesWithReflection(pkm);
|
2018-07-21 04:32:33 +00:00
|
|
|
|
if (!IsPKMCompatibleWithModifications(pkm))
|
2018-01-29 06:47:03 +00:00
|
|
|
|
return null;
|
|
|
|
|
comment = "Converted via reflection.";
|
|
|
|
|
return pkm;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
private static PKM? ConvertPKM(PKM pk, Type PKMType, Type fromType, out string comment)
|
2018-01-29 06:47:03 +00:00
|
|
|
|
{
|
2019-03-29 04:44:06 +00:00
|
|
|
|
if (IsNotTransferable(pk, out comment))
|
2017-11-07 02:34:35 +00:00
|
|
|
|
return null;
|
|
|
|
|
|
2019-04-10 03:58:19 +00:00
|
|
|
|
string toName = PKMType.Name;
|
|
|
|
|
string fromName = fromType.Name;
|
|
|
|
|
Debug.WriteLine($"Trying to convert {fromName} to {toName}.");
|
2017-09-08 06:18:04 +00:00
|
|
|
|
|
2019-04-10 03:58:19 +00:00
|
|
|
|
int toFormat = toName.Last() - '0';
|
2018-06-05 04:28:14 +00:00
|
|
|
|
var pkm = ConvertPKM(pk, PKMType, toFormat, ref comment);
|
2019-04-17 05:38:50 +00:00
|
|
|
|
var msg = pkm == null ? MsgPKMConvertFailFormat : MsgPKMConvertSuccess;
|
|
|
|
|
var formatted = string.Format(msg, fromName, toName);
|
|
|
|
|
comment = comment == null ? formatted : string.Concat(formatted, Environment.NewLine, comment);
|
2018-01-29 06:47:03 +00:00
|
|
|
|
return pkm;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
private static PKM? ConvertPKM(PKM pk, Type PKMType, int toFormat, ref string comment)
|
2018-01-29 06:47:03 +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
|
|
|
|
PKM? pkm = pk.Clone();
|
2017-09-08 06:18:04 +00:00
|
|
|
|
if (pkm.IsEgg)
|
2018-04-22 19:43:18 +00:00
|
|
|
|
pkm.ForceHatchPKM();
|
2018-06-05 04:28:14 +00:00
|
|
|
|
while (true)
|
2017-09-08 06:18:04 +00:00
|
|
|
|
{
|
2018-06-05 04:28:14 +00:00
|
|
|
|
pkm = IntermediaryConvert(pkm, PKMType, toFormat, ref comment);
|
|
|
|
|
if (pkm == null) // fail convert
|
|
|
|
|
return null;
|
|
|
|
|
if (pkm.GetType() == PKMType) // finish convert
|
|
|
|
|
return pkm;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-29 20:27:48 +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
|
|
|
|
private static PKM? IntermediaryConvert(PKM pk, Type PKMType, int toFormat, ref string comment)
|
2018-06-05 04:28:14 +00:00
|
|
|
|
{
|
|
|
|
|
switch (pk)
|
|
|
|
|
{
|
|
|
|
|
// Non-sequential
|
2018-09-01 22:09:04 +00:00
|
|
|
|
case PK1 pk1 when toFormat > 2: return pk1.ConvertToPK7();
|
|
|
|
|
case PK2 pk2 when toFormat > 2: return pk2.ConvertToPK7();
|
2018-06-05 04:28:14 +00:00
|
|
|
|
case PK3 pk3 when PKMType == typeof(CK3): return pk3.ConvertToCK3();
|
|
|
|
|
case PK3 pk3 when PKMType == typeof(XK3): return pk3.ConvertToXK3();
|
|
|
|
|
case PK4 pk4 when PKMType == typeof(BK4): return pk4.ConvertToBK4();
|
2016-10-02 17:18:31 +00:00
|
|
|
|
|
2018-06-05 04:28:14 +00:00
|
|
|
|
// Invalid
|
|
|
|
|
case PK2 pk2 when pk.Species > Legal.MaxSpeciesID_1:
|
|
|
|
|
var lang = pk2.Japanese ? (int)LanguageID.Japanese : (int)LanguageID.English;
|
2019-09-19 02:58:23 +00:00
|
|
|
|
var name = SpeciesName.GetSpeciesName(pk2.Species, lang);
|
2018-07-24 22:36:46 +00:00
|
|
|
|
comment = string.Format(MsgPKMConvertFailFormat, name, PKMType.Name);
|
2018-06-05 04:28:14 +00:00
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
// Sequential
|
|
|
|
|
case PK1 pk1: return pk1.ConvertToPK2();
|
|
|
|
|
case PK2 pk2: return pk2.ConvertToPK1();
|
|
|
|
|
case CK3 ck3: return ck3.ConvertToPK3();
|
|
|
|
|
case XK3 xk3: return xk3.ConvertToPK3();
|
|
|
|
|
case PK3 pk3: return pk3.ConvertToPK4();
|
|
|
|
|
case BK4 bk4: return bk4.ConvertToPK4();
|
|
|
|
|
case PK4 pk4: return pk4.ConvertToPK5();
|
|
|
|
|
case PK5 pk5: return pk5.ConvertToPK6();
|
|
|
|
|
case PK6 pk6: return pk6.ConvertToPK7();
|
2019-09-23 23:56:47 +00:00
|
|
|
|
case PK7 pk7: return pk7.ConvertToPK8();
|
|
|
|
|
case PB7 pb7: return pb7.ConvertToPK8();
|
2018-06-05 04:28:14 +00:00
|
|
|
|
|
|
|
|
|
// None
|
|
|
|
|
default:
|
2018-07-24 22:36:46 +00:00
|
|
|
|
comment = MsgPKMConvertFailNoMethod;
|
2018-06-05 04:28:14 +00:00
|
|
|
|
return null;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-08 06:18:04 +00:00
|
|
|
|
|
2017-11-07 02:34:35 +00:00
|
|
|
|
/// <summary>
|
2019-03-29 04:44:06 +00:00
|
|
|
|
/// Checks to see if a PKM is transferable relative to in-game restrictions and <see cref="PKM.AltForm"/>.
|
2017-11-07 02:34:35 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pk">PKM to convert</param>
|
2019-03-29 04:44:06 +00:00
|
|
|
|
/// <param name="comment">Comment indicating why the <see cref="PKM"/> is not transferable.</param>
|
|
|
|
|
/// <returns>Indication if Not Transferable</returns>
|
|
|
|
|
private static bool IsNotTransferable(PKM pk, out string comment)
|
2017-11-07 02:34:35 +00:00
|
|
|
|
{
|
|
|
|
|
switch (pk.Species)
|
|
|
|
|
{
|
|
|
|
|
default:
|
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
|
|
|
|
comment = string.Empty;
|
2017-11-07 02:34:35 +00:00
|
|
|
|
return false;
|
2018-11-14 03:10:31 +00:00
|
|
|
|
|
2017-11-18 06:19:23 +00:00
|
|
|
|
case 025 when pk.AltForm != 0 && pk.Gen6: // Cosplay Pikachu
|
|
|
|
|
case 172 when pk.AltForm != 0 && pk.Gen4: // Spiky Eared Pichu
|
2020-04-16 19:48:18 +00:00
|
|
|
|
case 025 when pk.AltForm == 8 && pk.LGPE: // Buddy Pikachu
|
|
|
|
|
case 133 when pk.AltForm == 1 && pk.LGPE: // Buddy Eevee
|
2018-07-24 22:36:46 +00:00
|
|
|
|
comment = MsgPKMConvertFailForme;
|
2017-11-07 02:34:35 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-21 04:32:33 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if the <see cref="PKM"/> is compatible with the input <see cref="PKM"/>, and makes any necessary modifications to force compatibility.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>Should only be used when forcing a backwards conversion to sanitize the PKM fields to the target format.
|
|
|
|
|
/// If the PKM is compatible, some properties may be forced to sanitized values.</remarks>
|
|
|
|
|
/// <param name="pk">PKM input that is to be sanity checked.</param>
|
|
|
|
|
/// <returns>Indication whether or not the PKM is compatible.</returns>
|
|
|
|
|
public static bool IsPKMCompatibleWithModifications(PKM pk) => IsPKMCompatibleWithModifications(pk, pk);
|
|
|
|
|
|
|
|
|
|
public static bool IsPKMCompatibleWithModifications(PKM pk, IGameValueLimit limit)
|
|
|
|
|
{
|
|
|
|
|
if (pk.Species > limit.MaxSpeciesID)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (pk.HeldItem > limit.MaxItemID)
|
|
|
|
|
pk.HeldItem = 0;
|
|
|
|
|
|
|
|
|
|
if (pk.Nickname.Length > limit.NickLength)
|
|
|
|
|
pk.Nickname = pk.Nickname.Substring(0, pk.NickLength);
|
|
|
|
|
|
|
|
|
|
if (pk.OT_Name.Length > limit.OTLength)
|
|
|
|
|
pk.OT_Name = pk.OT_Name.Substring(0, pk.OTLength);
|
|
|
|
|
|
|
|
|
|
if (pk.Moves.Any(move => move > limit.MaxMoveID))
|
|
|
|
|
pk.ClearInvalidMoves();
|
|
|
|
|
|
|
|
|
|
if (pk.EVs.Any(ev => ev > limit.MaxEV))
|
|
|
|
|
pk.EVs = pk.EVs.Select(ev => Math.Min(limit.MaxEV, ev)).ToArray();
|
|
|
|
|
|
|
|
|
|
if (pk.IVs.Any(iv => iv > limit.MaxIV))
|
|
|
|
|
pk.IVs = pk.IVs.Select(iv => Math.Min(limit.MaxIV, iv)).ToArray();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-28 21:26:27 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if the input <see cref="PKM"/> is compatible with the target <see cref="PKM"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pk">Input to check -> update/sanitize</param>
|
|
|
|
|
/// <param name="target">Target type PKM with misc properties accessible for checking.</param>
|
|
|
|
|
/// <param name="c">Comment output</param>
|
|
|
|
|
/// <param name="pkm">Output compatible PKM</param>
|
|
|
|
|
/// <returns>Indication if the input is (now) compatible with the target.</returns>
|
|
|
|
|
public static bool TryMakePKMCompatible(PKM pk, PKM target, out string c, out PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
if (!IsConvertibleToFormat(pk, target.Format))
|
|
|
|
|
{
|
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
|
|
|
|
pkm = target;
|
2018-07-24 22:36:46 +00:00
|
|
|
|
c = string.Format(MsgPKMConvertFailBackwards, pk.GetType().Name, target.Format);
|
2018-01-29 06:47:03 +00:00
|
|
|
|
if (!AllowIncompatibleConversion)
|
|
|
|
|
return false;
|
2017-10-28 21:26:27 +00:00
|
|
|
|
}
|
2018-07-24 22:36:46 +00:00
|
|
|
|
if (IsIncompatibleGB(target.Format, target.Japanese, pk.Japanese))
|
2017-10-28 21:26:27 +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
|
|
|
|
pkm = target;
|
2018-07-24 22:36:46 +00:00
|
|
|
|
c = GetIncompatibleGBMessage(pk, target.Japanese);
|
|
|
|
|
return false;
|
2017-10-28 21:26:27 +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
|
|
|
|
var convert = ConvertToType(pk, target.GetType(), out c);
|
|
|
|
|
if (convert == null)
|
|
|
|
|
{
|
|
|
|
|
pkm = target;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pkm = convert;
|
2017-10-28 21:26:27 +00:00
|
|
|
|
Debug.WriteLine(c);
|
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 true;
|
2017-10-28 21:26:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-24 22:49:00 +00:00
|
|
|
|
public static string GetIncompatibleGBMessage(PKM pk, bool destJP)
|
2018-07-24 22:36:46 +00:00
|
|
|
|
{
|
|
|
|
|
var src = destJP ? MsgPKMConvertInternational : MsgPKMConvertJapanese;
|
|
|
|
|
var dest = !destJP ? MsgPKMConvertInternational : MsgPKMConvertJapanese;
|
|
|
|
|
return string.Format(MsgPKMConvertIncompatible, src, pk.GetType().Name, dest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool IsIncompatibleGB(int format, bool destJP, bool srcJP) => format <= 2 && destJP != srcJP;
|
|
|
|
|
|
2017-04-24 03:33:17 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a Blank <see cref="PKM"/> object of the specified type.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="t">Type of <see cref="PKM"/> instance desired.</param>
|
|
|
|
|
/// <returns>New instance of a blank <see cref="PKM"/> object.</returns>
|
2018-01-29 05:40:42 +00:00
|
|
|
|
public static PKM GetBlank(Type t)
|
|
|
|
|
{
|
|
|
|
|
var constructors = t.GetTypeInfo().DeclaredConstructors.Where(z => !z.IsStatic);
|
2019-03-17 03:04:44 +00:00
|
|
|
|
var argCount = constructors.Min(z => z.GetParameters().Length);
|
2018-01-29 05:40:42 +00:00
|
|
|
|
return (PKM)Activator.CreateInstance(t, new object[argCount]);
|
|
|
|
|
}
|
2018-07-29 20:27:48 +00:00
|
|
|
|
|
2018-11-20 00:14:49 +00:00
|
|
|
|
public static PKM GetBlank(int gen, GameVersion ver)
|
2018-11-14 03:10:31 +00:00
|
|
|
|
{
|
2018-11-20 00:14:49 +00:00
|
|
|
|
if (gen == 7 && GameVersion.GG.Contains(ver))
|
2018-11-14 03:10:31 +00:00
|
|
|
|
return new PB7();
|
2018-11-20 00:14:49 +00:00
|
|
|
|
return GetBlank(gen);
|
2018-11-14 03:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-20 00:14:49 +00:00
|
|
|
|
public static PKM GetBlank(int gen, int ver) => GetBlank(gen, (GameVersion) ver);
|
|
|
|
|
|
2018-03-29 03:34:58 +00:00
|
|
|
|
public static PKM GetBlank(int gen)
|
|
|
|
|
{
|
|
|
|
|
var type = Type.GetType($"PKHeX.Core.PK{gen}");
|
|
|
|
|
return GetBlank(type);
|
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|