2016-06-20 04:22:43 +00:00
|
|
|
|
using System;
|
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
|
|
|
|
using System.Collections.Generic;
|
2022-01-03 05:35:59 +00:00
|
|
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
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> Generation 3 <see cref="PKM"/> format. </summary>
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public sealed class PK3 : G3PKM, ISanityChecksum
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2019-11-16 01:34:18 +00:00
|
|
|
|
private static readonly ushort[] Unused =
|
2016-06-26 21:23:41 +00:00
|
|
|
|
{
|
2021-08-20 20:49:20 +00:00
|
|
|
|
0x2A, 0x2B,
|
2016-06-26 21:23:41 +00:00
|
|
|
|
};
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2020-01-04 22:48:39 +00:00
|
|
|
|
public override int SIZE_PARTY => PokeCrypto.SIZE_3PARTY;
|
|
|
|
|
public override int SIZE_STORED => PokeCrypto.SIZE_3STORED;
|
2022-05-31 04:43:52 +00:00
|
|
|
|
public override EntityContext Context => EntityContext.Gen3;
|
2016-10-24 05:01:39 +00:00
|
|
|
|
public override PersonalInfo PersonalInfo => PersonalTable.RS[Species];
|
|
|
|
|
|
2019-11-16 01:34:18 +00:00
|
|
|
|
public override IReadOnlyList<ushort> ExtraBytes => Unused;
|
2018-12-20 06:10:32 +00:00
|
|
|
|
|
2020-09-26 19:09:02 +00:00
|
|
|
|
public PK3() : base(PokeCrypto.SIZE_3PARTY) { }
|
|
|
|
|
public PK3(byte[] data) : base(DecryptParty(data)) { }
|
2018-11-21 22:15:48 +00:00
|
|
|
|
|
2020-09-26 19:09:02 +00:00
|
|
|
|
private static byte[] DecryptParty(byte[] data)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2020-01-04 22:48:39 +00:00
|
|
|
|
PokeCrypto.DecryptIfEncrypted3(ref data);
|
2020-08-02 22:51:22 +00:00
|
|
|
|
Array.Resize(ref data, PokeCrypto.SIZE_3PARTY);
|
2020-09-26 19:09:02 +00:00
|
|
|
|
return data;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-06-19 03:55:35 +00:00
|
|
|
|
public override PKM Clone()
|
|
|
|
|
{
|
2020-01-04 22:48:39 +00:00
|
|
|
|
// Don't use the byte[] constructor, the DecryptIfEncrypted call is based on checksum.
|
2019-06-19 03:55:35 +00:00
|
|
|
|
// An invalid checksum will shuffle the data; we already know it's un-shuffled. Set up manually.
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
var pk = new PK3();
|
2019-06-19 03:55:35 +00:00
|
|
|
|
Data.CopyTo(pk.Data, 0);
|
|
|
|
|
return pk;
|
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2018-12-15 07:26:46 +00:00
|
|
|
|
private const string EggNameJapanese = "タマゴ";
|
|
|
|
|
|
2017-04-09 21:06:50 +00:00
|
|
|
|
// Trash Bytes
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public override Span<byte> Nickname_Trash => Data.AsSpan(0x08, 10); // no inaccessible terminator
|
|
|
|
|
public override Span<byte> OT_Trash => Data.AsSpan(0x14, 7); // no inaccessible terminator
|
2017-04-09 21:06:50 +00:00
|
|
|
|
|
2018-02-03 20:42:06 +00:00
|
|
|
|
// At top for System.Reflection execution order hack
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
// 0x20 Intro
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public override uint PID { get => ReadUInt32LittleEndian(Data.AsSpan(0x00)); set => WriteUInt32LittleEndian(Data.AsSpan(0x00), value); }
|
|
|
|
|
public override int TID { get => ReadUInt16LittleEndian(Data.AsSpan(0x04)); set => WriteUInt16LittleEndian(Data.AsSpan(0x04), (ushort)value); }
|
|
|
|
|
public override int SID { get => ReadUInt16LittleEndian(Data.AsSpan(0x06)); set => WriteUInt16LittleEndian(Data.AsSpan(0x06), (ushort)value); }
|
|
|
|
|
public override string Nickname
|
|
|
|
|
{
|
|
|
|
|
get => StringConverter3.GetString(Nickname_Trash, Japanese);
|
|
|
|
|
set => StringConverter3.SetString(Nickname_Trash, (IsEgg ? EggNameJapanese : value).AsSpan(), 10, Japanese, StringConverterOption.None);
|
|
|
|
|
}
|
2018-12-15 07:26:46 +00:00
|
|
|
|
public override int Language { get => Data[0x12]; set => Data[0x12] = (byte)value; }
|
|
|
|
|
public bool FlagIsBadEgg { get => (Data[0x13] & 1) != 0; set => Data[0x13] = (byte)((Data[0x13] & ~1) | (value ? 1 : 0)); }
|
|
|
|
|
public bool FlagHasSpecies { get => (Data[0x13] & 2) != 0; set => Data[0x13] = (byte)((Data[0x13] & ~2) | (value ? 2 : 0)); }
|
|
|
|
|
public bool FlagIsEgg { get => (Data[0x13] & 4) != 0; set => Data[0x13] = (byte)((Data[0x13] & ~4) | (value ? 4 : 0)); }
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public override string OT_Name
|
|
|
|
|
{
|
|
|
|
|
get => StringConverter3.GetString(OT_Trash, Japanese);
|
|
|
|
|
set => StringConverter3.SetString(OT_Trash, value.AsSpan(), 7, Japanese, StringConverterOption.None);
|
|
|
|
|
}
|
2022-05-31 04:43:52 +00:00
|
|
|
|
public override int MarkValue { get => SwapBits(Data[0x1B], 1, 2); set => Data[0x1B] = (byte)SwapBits(value, 1, 2); }
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public ushort Checksum { get => ReadUInt16LittleEndian(Data.AsSpan(0x1C)); set => WriteUInt16LittleEndian(Data.AsSpan(0x1C), value); }
|
|
|
|
|
public ushort Sanity { get => ReadUInt16LittleEndian(Data.AsSpan(0x1E)); set => WriteUInt16LittleEndian(Data.AsSpan(0x1E), value); }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
#region Block A
|
2022-03-14 02:53:46 +00:00
|
|
|
|
public override ushort SpeciesID3 { get => ReadUInt16LittleEndian(Data.AsSpan(0x20)); set => WriteUInt16LittleEndian(Data.AsSpan(0x20), value); } // raw access
|
2018-12-15 07:26:46 +00:00
|
|
|
|
|
|
|
|
|
public override int Species
|
|
|
|
|
{
|
|
|
|
|
get => SpeciesConverter.GetG4Species(SpeciesID3);
|
|
|
|
|
set
|
|
|
|
|
{
|
2022-03-14 02:53:46 +00:00
|
|
|
|
SpeciesID3 = (ushort)SpeciesConverter.GetG3Species(value);
|
2018-12-15 07:26:46 +00:00
|
|
|
|
FlagHasSpecies = Species > 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-17 02:46:22 +00:00
|
|
|
|
public override int SpriteItem => ItemConverter.GetItemFuture3((ushort)HeldItem);
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public override int HeldItem { get => ReadUInt16LittleEndian(Data.AsSpan(0x22)); set => WriteUInt16LittleEndian(Data.AsSpan(0x22), (ushort)value); }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public override uint EXP { get => ReadUInt32LittleEndian(Data.AsSpan(0x24)); set => WriteUInt32LittleEndian(Data.AsSpan(0x24), value); }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
private byte PPUps { get => Data[0x28]; set => Data[0x28] = value; }
|
|
|
|
|
public override int Move1_PPUps { get => (PPUps >> 0) & 3; set => PPUps = (byte)((PPUps & ~(3 << 0)) | value << 0); }
|
|
|
|
|
public override int Move2_PPUps { get => (PPUps >> 2) & 3; set => PPUps = (byte)((PPUps & ~(3 << 2)) | value << 2); }
|
|
|
|
|
public override int Move3_PPUps { get => (PPUps >> 4) & 3; set => PPUps = (byte)((PPUps & ~(3 << 4)) | value << 4); }
|
|
|
|
|
public override int Move4_PPUps { get => (PPUps >> 6) & 3; set => PPUps = (byte)((PPUps & ~(3 << 6)) | value << 6); }
|
|
|
|
|
public override int OT_Friendship { get => Data[0x29]; set => Data[0x29] = (byte)value; }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
// Unused 0x2A 0x2B
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Block B
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public override int Move1 { get => ReadUInt16LittleEndian(Data.AsSpan(0x2C)); set => WriteUInt16LittleEndian(Data.AsSpan(0x2C), (ushort)value); }
|
|
|
|
|
public override int Move2 { get => ReadUInt16LittleEndian(Data.AsSpan(0x2E)); set => WriteUInt16LittleEndian(Data.AsSpan(0x2E), (ushort)value); }
|
|
|
|
|
public override int Move3 { get => ReadUInt16LittleEndian(Data.AsSpan(0x30)); set => WriteUInt16LittleEndian(Data.AsSpan(0x30), (ushort)value); }
|
|
|
|
|
public override int Move4 { get => ReadUInt16LittleEndian(Data.AsSpan(0x32)); set => WriteUInt16LittleEndian(Data.AsSpan(0x32), (ushort)value); }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int Move1_PP { get => Data[0x34]; set => Data[0x34] = (byte)value; }
|
|
|
|
|
public override int Move2_PP { get => Data[0x35]; set => Data[0x35] = (byte)value; }
|
|
|
|
|
public override int Move3_PP { get => Data[0x36]; set => Data[0x36] = (byte)value; }
|
|
|
|
|
public override int Move4_PP { get => Data[0x37]; set => Data[0x37] = (byte)value; }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Block C
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int EV_HP { get => Data[0x38]; set => Data[0x38] = (byte)value; }
|
|
|
|
|
public override int EV_ATK { get => Data[0x39]; set => Data[0x39] = (byte)value; }
|
|
|
|
|
public override int EV_DEF { get => Data[0x3A]; set => Data[0x3A] = (byte)value; }
|
|
|
|
|
public override int EV_SPE { get => Data[0x3B]; set => Data[0x3B] = (byte)value; }
|
|
|
|
|
public override int EV_SPA { get => Data[0x3C]; set => Data[0x3C] = (byte)value; }
|
|
|
|
|
public override int EV_SPD { get => Data[0x3D]; set => Data[0x3D] = (byte)value; }
|
2021-01-01 21:39:08 +00:00
|
|
|
|
public override byte CNT_Cool { get => Data[0x3E]; set => Data[0x3E] = value; }
|
|
|
|
|
public override byte CNT_Beauty { get => Data[0x3F]; set => Data[0x3F] = value; }
|
|
|
|
|
public override byte CNT_Cute { get => Data[0x40]; set => Data[0x40] = value; }
|
|
|
|
|
public override byte CNT_Smart { get => Data[0x41]; set => Data[0x41] = value; }
|
|
|
|
|
public override byte CNT_Tough { get => Data[0x42]; set => Data[0x42] = value; }
|
|
|
|
|
public override byte CNT_Sheen { get => Data[0x43]; set => Data[0x43] = value; }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Block D
|
2017-05-13 03:32:36 +00:00
|
|
|
|
private byte PKRS { get => Data[0x44]; set => Data[0x44] = value; }
|
2018-09-15 05:37:47 +00:00
|
|
|
|
public override int PKRS_Days { get => PKRS & 0xF; set => PKRS = (byte)((PKRS & ~0xF) | value); }
|
|
|
|
|
public override int PKRS_Strain { get => PKRS >> 4; set => PKRS = (byte)((PKRS & 0xF) | value << 4); }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int Met_Location { get => Data[0x45]; set => Data[0x45] = (byte)value; }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
// Origins
|
2022-01-03 05:35:59 +00:00
|
|
|
|
private ushort Origins { get => ReadUInt16LittleEndian(Data.AsSpan(0x46)); set => WriteUInt16LittleEndian(Data.AsSpan(0x46), value); }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int Met_Level { get => Origins & 0x7F; set => Origins = (ushort)((Origins & ~0x7F) | value); }
|
|
|
|
|
public override int Version { get => (Origins >> 7) & 0xF; set => Origins = (ushort)((Origins & ~0x780) | ((value & 0xF) << 7)); }
|
|
|
|
|
public override int Ball { get => (Origins >> 11) & 0xF; set => Origins = (ushort)((Origins & ~0x7800) | ((value & 0xF) << 11)); }
|
2018-09-15 05:37:47 +00:00
|
|
|
|
public override int OT_Gender { get => (Origins >> 15) & 1; set => Origins = (ushort)((Origins & ~(1 << 15)) | ((value & 1) << 15)); }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public uint IV32 { get => ReadUInt32LittleEndian(Data.AsSpan(0x48)); set => WriteUInt32LittleEndian(Data.AsSpan(0x48), value); }
|
2019-02-23 23:36:26 +00:00
|
|
|
|
public override int IV_HP { get => (int)(IV32 >> 00) & 0x1F; set => IV32 = (IV32 & ~(0x1Fu << 00)) | ((value > 31 ? 31u : (uint)value) << 00); }
|
|
|
|
|
public override int IV_ATK { get => (int)(IV32 >> 05) & 0x1F; set => IV32 = (IV32 & ~(0x1Fu << 05)) | ((value > 31 ? 31u : (uint)value) << 05); }
|
|
|
|
|
public override int IV_DEF { get => (int)(IV32 >> 10) & 0x1F; set => IV32 = (IV32 & ~(0x1Fu << 10)) | ((value > 31 ? 31u : (uint)value) << 10); }
|
|
|
|
|
public override int IV_SPE { get => (int)(IV32 >> 15) & 0x1F; set => IV32 = (IV32 & ~(0x1Fu << 15)) | ((value > 31 ? 31u : (uint)value) << 15); }
|
|
|
|
|
public override int IV_SPA { get => (int)(IV32 >> 20) & 0x1F; set => IV32 = (IV32 & ~(0x1Fu << 20)) | ((value > 31 ? 31u : (uint)value) << 20); }
|
|
|
|
|
public override int IV_SPD { get => (int)(IV32 >> 25) & 0x1F; set => IV32 = (IV32 & ~(0x1Fu << 25)) | ((value > 31 ? 31u : (uint)value) << 25); }
|
2018-12-15 07:26:46 +00:00
|
|
|
|
|
|
|
|
|
public override bool IsEgg
|
|
|
|
|
{
|
|
|
|
|
get => ((IV32 >> 30) & 1) == 1;
|
|
|
|
|
set
|
|
|
|
|
{
|
2019-02-23 23:36:26 +00:00
|
|
|
|
IV32 = (IV32 & ~0x40000000u) | (value ? 0x40000000u : 0);
|
2018-12-15 07:26:46 +00:00
|
|
|
|
FlagIsEgg = value;
|
|
|
|
|
if (value)
|
|
|
|
|
{
|
|
|
|
|
Nickname = EggNameJapanese;
|
|
|
|
|
Language = (int) LanguageID.Japanese;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-23 23:36:26 +00:00
|
|
|
|
public override bool AbilityBit { get => IV32 >> 31 == 1; set => IV32 = (IV32 & 0x7FFFFFFF) | (value ? 1u << 31 : 0u); }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
private uint RIB0 { get => ReadUInt32LittleEndian(Data.AsSpan(0x4C)); set => WriteUInt32LittleEndian(Data.AsSpan(0x4C), value); }
|
2019-02-23 23:36:26 +00:00
|
|
|
|
public override int RibbonCountG3Cool { get => (int)(RIB0 >> 00) & 7; set => RIB0 = ((RIB0 & ~(7u << 00)) | (uint)(value & 7) << 00); }
|
|
|
|
|
public override int RibbonCountG3Beauty { get => (int)(RIB0 >> 03) & 7; set => RIB0 = ((RIB0 & ~(7u << 03)) | (uint)(value & 7) << 03); }
|
|
|
|
|
public override int RibbonCountG3Cute { get => (int)(RIB0 >> 06) & 7; set => RIB0 = ((RIB0 & ~(7u << 06)) | (uint)(value & 7) << 06); }
|
|
|
|
|
public override int RibbonCountG3Smart { get => (int)(RIB0 >> 09) & 7; set => RIB0 = ((RIB0 & ~(7u << 09)) | (uint)(value & 7) << 09); }
|
|
|
|
|
public override int RibbonCountG3Tough { get => (int)(RIB0 >> 12) & 7; set => RIB0 = ((RIB0 & ~(7u << 12)) | (uint)(value & 7) << 12); }
|
2021-04-10 19:09:43 +00:00
|
|
|
|
public override bool RibbonChampionG3 { get => (RIB0 & (1 << 15)) == 1 << 15; set => RIB0 = ((RIB0 & ~(1u << 15)) | (value ? 1u << 15 : 0u)); }
|
2019-02-23 23:36:26 +00:00
|
|
|
|
public override bool RibbonWinning { get => (RIB0 & (1 << 16)) == 1 << 16; set => RIB0 = ((RIB0 & ~(1u << 16)) | (value ? 1u << 16 : 0u)); }
|
|
|
|
|
public override bool RibbonVictory { get => (RIB0 & (1 << 17)) == 1 << 17; set => RIB0 = ((RIB0 & ~(1u << 17)) | (value ? 1u << 17 : 0u)); }
|
|
|
|
|
public override bool RibbonArtist { get => (RIB0 & (1 << 18)) == 1 << 18; set => RIB0 = ((RIB0 & ~(1u << 18)) | (value ? 1u << 18 : 0u)); }
|
|
|
|
|
public override bool RibbonEffort { get => (RIB0 & (1 << 19)) == 1 << 19; set => RIB0 = ((RIB0 & ~(1u << 19)) | (value ? 1u << 19 : 0u)); }
|
|
|
|
|
public override bool RibbonChampionBattle { get => (RIB0 & (1 << 20)) == 1 << 20; set => RIB0 = ((RIB0 & ~(1u << 20)) | (value ? 1u << 20 : 0u)); }
|
|
|
|
|
public override bool RibbonChampionRegional { get => (RIB0 & (1 << 21)) == 1 << 21; set => RIB0 = ((RIB0 & ~(1u << 21)) | (value ? 1u << 21 : 0u)); }
|
|
|
|
|
public override bool RibbonChampionNational { get => (RIB0 & (1 << 22)) == 1 << 22; set => RIB0 = ((RIB0 & ~(1u << 22)) | (value ? 1u << 22 : 0u)); }
|
|
|
|
|
public override bool RibbonCountry { get => (RIB0 & (1 << 23)) == 1 << 23; set => RIB0 = ((RIB0 & ~(1u << 23)) | (value ? 1u << 23 : 0u)); }
|
|
|
|
|
public override bool RibbonNational { get => (RIB0 & (1 << 24)) == 1 << 24; set => RIB0 = ((RIB0 & ~(1u << 24)) | (value ? 1u << 24 : 0u)); }
|
|
|
|
|
public override bool RibbonEarth { get => (RIB0 & (1 << 25)) == 1 << 25; set => RIB0 = ((RIB0 & ~(1u << 25)) | (value ? 1u << 25 : 0u)); }
|
|
|
|
|
public override bool RibbonWorld { get => (RIB0 & (1 << 26)) == 1 << 26; set => RIB0 = ((RIB0 & ~(1u << 26)) | (value ? 1u << 26 : 0u)); }
|
|
|
|
|
public override bool Unused1 { get => (RIB0 & (1 << 27)) == 1 << 27; set => RIB0 = ((RIB0 & ~(1u << 27)) | (value ? 1u << 27 : 0u)); }
|
|
|
|
|
public override bool Unused2 { get => (RIB0 & (1 << 28)) == 1 << 28; set => RIB0 = ((RIB0 & ~(1u << 28)) | (value ? 1u << 28 : 0u)); }
|
|
|
|
|
public override bool Unused3 { get => (RIB0 & (1 << 29)) == 1 << 29; set => RIB0 = ((RIB0 & ~(1u << 29)) | (value ? 1u << 29 : 0u)); }
|
|
|
|
|
public override bool Unused4 { get => (RIB0 & (1 << 30)) == 1 << 30; set => RIB0 = ((RIB0 & ~(1u << 30)) | (value ? 1u << 30 : 0u)); }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override bool FatefulEncounter { get => RIB0 >> 31 == 1; set => RIB0 = (RIB0 & ~(1 << 31)) | (uint)(value ? 1 << 31 : 0); }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2018-12-03 05:23:10 +00:00
|
|
|
|
#region Battle Stats
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public override int Status_Condition { get => ReadInt32LittleEndian(Data.AsSpan(0x50)); set => WriteInt32LittleEndian(Data.AsSpan(0x50), value); }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int Stat_Level { get => Data[0x54]; set => Data[0x54] = (byte)value; }
|
2018-02-03 20:42:06 +00:00
|
|
|
|
public sbyte HeldMailID { get => (sbyte)Data[0x55]; set => Data[0x55] = (byte)value; }
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public override int Stat_HPCurrent { get => ReadUInt16LittleEndian(Data.AsSpan(0x56)); set => WriteUInt16LittleEndian(Data.AsSpan(0x56), (ushort)value); }
|
|
|
|
|
public override int Stat_HPMax { get => ReadUInt16LittleEndian(Data.AsSpan(0x58)); set => WriteUInt16LittleEndian(Data.AsSpan(0x58), (ushort)value); }
|
|
|
|
|
public override int Stat_ATK { get => ReadUInt16LittleEndian(Data.AsSpan(0x5A)); set => WriteUInt16LittleEndian(Data.AsSpan(0x5A), (ushort)value); }
|
|
|
|
|
public override int Stat_DEF { get => ReadUInt16LittleEndian(Data.AsSpan(0x5C)); set => WriteUInt16LittleEndian(Data.AsSpan(0x5C), (ushort)value); }
|
|
|
|
|
public override int Stat_SPE { get => ReadUInt16LittleEndian(Data.AsSpan(0x5E)); set => WriteUInt16LittleEndian(Data.AsSpan(0x5E), (ushort)value); }
|
|
|
|
|
public override int Stat_SPA { get => ReadUInt16LittleEndian(Data.AsSpan(0x60)); set => WriteUInt16LittleEndian(Data.AsSpan(0x60), (ushort)value); }
|
|
|
|
|
public override int Stat_SPD { get => ReadUInt16LittleEndian(Data.AsSpan(0x62)); set => WriteUInt16LittleEndian(Data.AsSpan(0x62), (ushort)value); }
|
2018-12-03 05:23:10 +00:00
|
|
|
|
#endregion
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected override byte[] Encrypt()
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
RefreshChecksum();
|
2020-01-04 22:48:39 +00:00
|
|
|
|
return PokeCrypto.EncryptArray3(Data);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-12-15 07:26:46 +00:00
|
|
|
|
public override void RefreshChecksum()
|
|
|
|
|
{
|
|
|
|
|
FlagIsBadEgg = false;
|
2022-01-03 05:35:59 +00:00
|
|
|
|
Checksum = PokeCrypto.GetCHK3(Data);
|
2018-12-15 07:26:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public override bool ChecksumValid => CalculateChecksum() == Checksum;
|
|
|
|
|
private ushort CalculateChecksum() => PokeCrypto.GetCHK3(Data);
|
2020-10-18 16:16:52 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public PK4 ConvertToPK4()
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2020-12-22 01:17:56 +00:00
|
|
|
|
PK4 pk4 = new() // Convert away!
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
PID = PID,
|
|
|
|
|
Species = Species,
|
|
|
|
|
TID = TID,
|
|
|
|
|
SID = SID,
|
2019-11-16 01:34:18 +00:00
|
|
|
|
EXP = IsEgg ? Experience.GetEXP(5, PersonalInfo.EXPGrowth) : EXP,
|
2022-05-07 03:38:55 +00:00
|
|
|
|
Gender = EntityGender.GetFromPID(Species, PID),
|
2020-12-11 04:42:30 +00:00
|
|
|
|
Form = Form,
|
2019-07-12 23:41:13 +00:00
|
|
|
|
// IsEgg = false, -- already false
|
2016-08-06 18:37:16 +00:00
|
|
|
|
OT_Friendship = 70,
|
2016-12-03 17:09:33 +00:00
|
|
|
|
Markings = Markings,
|
2016-06-20 04:22:43 +00:00
|
|
|
|
Language = Language,
|
|
|
|
|
EV_HP = EV_HP,
|
|
|
|
|
EV_ATK = EV_ATK,
|
|
|
|
|
EV_DEF = EV_DEF,
|
|
|
|
|
EV_SPA = EV_SPA,
|
|
|
|
|
EV_SPD = EV_SPD,
|
|
|
|
|
EV_SPE = EV_SPE,
|
|
|
|
|
CNT_Cool = CNT_Cool,
|
|
|
|
|
CNT_Beauty = CNT_Beauty,
|
|
|
|
|
CNT_Cute = CNT_Cute,
|
|
|
|
|
CNT_Smart = CNT_Smart,
|
|
|
|
|
CNT_Tough = CNT_Tough,
|
|
|
|
|
CNT_Sheen = CNT_Sheen,
|
|
|
|
|
Move1 = Move1,
|
|
|
|
|
Move2 = Move2,
|
|
|
|
|
Move3 = Move3,
|
|
|
|
|
Move4 = Move4,
|
|
|
|
|
Move1_PPUps = Move1_PPUps,
|
|
|
|
|
Move2_PPUps = Move2_PPUps,
|
|
|
|
|
Move3_PPUps = Move3_PPUps,
|
|
|
|
|
Move4_PPUps = Move4_PPUps,
|
|
|
|
|
IV_HP = IV_HP,
|
|
|
|
|
IV_ATK = IV_ATK,
|
|
|
|
|
IV_DEF = IV_DEF,
|
|
|
|
|
IV_SPA = IV_SPA,
|
|
|
|
|
IV_SPD = IV_SPD,
|
|
|
|
|
IV_SPE = IV_SPE,
|
2016-07-22 06:13:58 +00:00
|
|
|
|
Ability = Ability,
|
2016-06-20 04:22:43 +00:00
|
|
|
|
Version = Version,
|
|
|
|
|
Ball = Ball,
|
|
|
|
|
PKRS_Strain = PKRS_Strain,
|
|
|
|
|
PKRS_Days = PKRS_Days,
|
|
|
|
|
OT_Gender = OT_Gender,
|
2019-07-12 23:41:13 +00:00
|
|
|
|
MetDate = DateTime.Now,
|
|
|
|
|
Met_Level = CurrentLevel,
|
2019-05-11 03:46:49 +00:00
|
|
|
|
Met_Location = Locations.Transfer3, // Pal Park
|
2016-07-16 22:52:33 +00:00
|
|
|
|
|
2021-04-10 19:09:43 +00:00
|
|
|
|
RibbonChampionG3 = RibbonChampionG3,
|
2019-07-12 23:41:13 +00:00
|
|
|
|
RibbonWinning = RibbonWinning,
|
|
|
|
|
RibbonVictory = RibbonVictory,
|
|
|
|
|
RibbonArtist = RibbonArtist,
|
2016-07-16 22:52:33 +00:00
|
|
|
|
RibbonEffort = RibbonEffort,
|
|
|
|
|
RibbonChampionBattle = RibbonChampionBattle,
|
|
|
|
|
RibbonChampionRegional = RibbonChampionRegional,
|
|
|
|
|
RibbonChampionNational = RibbonChampionNational,
|
|
|
|
|
RibbonCountry = RibbonCountry,
|
|
|
|
|
RibbonNational = RibbonNational,
|
|
|
|
|
RibbonEarth = RibbonEarth,
|
|
|
|
|
RibbonWorld = RibbonWorld,
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2019-07-12 23:41:13 +00:00
|
|
|
|
// byte -> bool contest ribbons
|
|
|
|
|
RibbonG3Cool = RibbonCountG3Cool > 0,
|
|
|
|
|
RibbonG3CoolSuper = RibbonCountG3Cool > 1,
|
|
|
|
|
RibbonG3CoolHyper = RibbonCountG3Cool > 2,
|
|
|
|
|
RibbonG3CoolMaster = RibbonCountG3Cool > 3,
|
|
|
|
|
|
|
|
|
|
RibbonG3Beauty = RibbonCountG3Beauty > 0,
|
|
|
|
|
RibbonG3BeautySuper = RibbonCountG3Beauty > 1,
|
|
|
|
|
RibbonG3BeautyHyper = RibbonCountG3Beauty > 2,
|
|
|
|
|
RibbonG3BeautyMaster = RibbonCountG3Beauty > 3,
|
|
|
|
|
|
|
|
|
|
RibbonG3Cute = RibbonCountG3Cute > 0,
|
|
|
|
|
RibbonG3CuteSuper = RibbonCountG3Cute > 1,
|
|
|
|
|
RibbonG3CuteHyper = RibbonCountG3Cute > 2,
|
|
|
|
|
RibbonG3CuteMaster = RibbonCountG3Cute > 3,
|
|
|
|
|
|
|
|
|
|
RibbonG3Smart = RibbonCountG3Smart > 0,
|
|
|
|
|
RibbonG3SmartSuper = RibbonCountG3Smart > 1,
|
|
|
|
|
RibbonG3SmartHyper = RibbonCountG3Smart > 2,
|
|
|
|
|
RibbonG3SmartMaster = RibbonCountG3Smart > 3,
|
|
|
|
|
|
|
|
|
|
RibbonG3Tough = RibbonCountG3Tough > 0,
|
|
|
|
|
RibbonG3ToughSuper = RibbonCountG3Tough > 1,
|
|
|
|
|
RibbonG3ToughHyper = RibbonCountG3Tough > 2,
|
|
|
|
|
RibbonG3ToughMaster = RibbonCountG3Tough > 3,
|
|
|
|
|
|
|
|
|
|
FatefulEncounter = FatefulEncounter,
|
|
|
|
|
};
|
2016-08-14 16:55:58 +00:00
|
|
|
|
|
2019-07-12 23:41:13 +00:00
|
|
|
|
// Yay for reusing string buffers! The game allocates a buffer and reuses it when creating strings.
|
|
|
|
|
// Trash from the {unknown source} is currently in buffer. Set it to the Nickname region.
|
2019-03-21 04:50:44 +00:00
|
|
|
|
var trash = StringConverter345.G4TransferTrashBytes;
|
2018-04-07 06:36:13 +00:00
|
|
|
|
if (pk4.Language < trash.Length)
|
|
|
|
|
trash[pk4.Language].CopyTo(pk4.Data, 0x48 + 4);
|
2019-09-19 02:58:23 +00:00
|
|
|
|
pk4.Nickname = IsEgg ? SpeciesName.GetSpeciesNameGeneration(pk4.Species, pk4.Language, 4) : Nickname;
|
2019-07-12 23:41:13 +00:00
|
|
|
|
pk4.IsNicknamed = !IsEgg && IsNicknamed;
|
|
|
|
|
|
|
|
|
|
// Trash from the current string (Nickname) is in our string buffer. Slap the OT name over-top.
|
2017-09-30 21:08:35 +00:00
|
|
|
|
Buffer.BlockCopy(pk4.Data, 0x48, pk4.Data, 0x68, 0x10);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
pk4.OT_Name = OT_Name;
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2016-08-06 16:35:05 +00:00
|
|
|
|
if (HeldItem > 0)
|
2016-12-24 01:28:39 +00:00
|
|
|
|
{
|
2020-06-17 02:46:22 +00:00
|
|
|
|
ushort item = ItemConverter.GetItemFuture3((ushort)HeldItem);
|
2019-03-29 04:44:06 +00:00
|
|
|
|
if (ItemConverter.IsItemTransferable34(item))
|
2016-12-24 01:28:39 +00:00
|
|
|
|
pk4.HeldItem = item;
|
|
|
|
|
}
|
2016-08-06 16:35:05 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
// Remove HM moves
|
|
|
|
|
int[] newMoves = pk4.Moves;
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
2018-09-15 05:37:47 +00:00
|
|
|
|
{
|
2021-08-28 20:54:58 +00:00
|
|
|
|
var move = newMoves[i];
|
|
|
|
|
if (Array.IndexOf(Legal.HM_3, move) != -1)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
newMoves[i] = 0;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
pk4.Moves = newMoves;
|
|
|
|
|
pk4.FixMoves();
|
2019-07-12 23:41:13 +00:00
|
|
|
|
pk4.HealPP();
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
pk4.RefreshChecksum();
|
|
|
|
|
return pk4;
|
|
|
|
|
}
|
2018-02-03 20:42:06 +00:00
|
|
|
|
|
|
|
|
|
public XK3 ConvertToXK3()
|
|
|
|
|
{
|
|
|
|
|
var pk = ConvertTo<XK3>();
|
2019-07-12 23:41:13 +00:00
|
|
|
|
pk.ResetPartyStats();
|
2018-02-03 20:42:06 +00:00
|
|
|
|
return pk;
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-02-03 20:42:06 +00:00
|
|
|
|
public CK3 ConvertToCK3()
|
|
|
|
|
{
|
|
|
|
|
var pk = ConvertTo<CK3>();
|
2019-07-12 23:41:13 +00:00
|
|
|
|
pk.ResetPartyStats();
|
2018-02-03 20:42:06 +00:00
|
|
|
|
return pk;
|
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|