2016-08-27 08:52:34 +00:00
|
|
|
|
using System;
|
2019-02-24 00:05:01 +00:00
|
|
|
|
using System.Collections.Generic;
|
2016-08-27 08:52:34 +00:00
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.Core
|
2016-08-27 08:52:34 +00:00
|
|
|
|
{
|
2017-10-24 06:12:58 +00:00
|
|
|
|
/// <summary> Generation 1 <see cref="PKM"/> format. </summary>
|
2019-10-26 19:42:33 +00:00
|
|
|
|
public sealed class PK1 : GBPKM
|
2016-08-27 08:52:34 +00:00
|
|
|
|
{
|
2017-02-13 06:31:31 +00:00
|
|
|
|
public override PersonalInfo PersonalInfo => PersonalTable.Y[Species];
|
2016-08-27 08:52:34 +00:00
|
|
|
|
|
2016-09-15 05:04:22 +00:00
|
|
|
|
public override bool Valid => Species <= 151 && (Data[0] == 0 || Species != 0);
|
2016-08-28 10:18:22 +00:00
|
|
|
|
|
2017-12-16 22:11:41 +00:00
|
|
|
|
public override int SIZE_PARTY => PKX.SIZE_1PARTY;
|
2016-08-27 08:52:34 +00:00
|
|
|
|
public override int SIZE_STORED => PKX.SIZE_1STORED;
|
2018-08-19 22:50:15 +00:00
|
|
|
|
public override bool Korean => false;
|
2017-04-09 21:06:50 +00:00
|
|
|
|
|
2016-08-27 08:52:34 +00:00
|
|
|
|
public override int Format => 1;
|
|
|
|
|
|
2019-03-17 01:41:56 +00:00
|
|
|
|
public PK1(bool jp = false) : base(new byte[PKX.SIZE_1PARTY], jp) { }
|
2019-03-17 03:04:44 +00:00
|
|
|
|
public PK1(byte[] decryptedData, bool jp = false) : base(decryptedData, jp) { }
|
2016-08-27 08:52:34 +00:00
|
|
|
|
|
2019-03-17 01:41:56 +00:00
|
|
|
|
public override PKM Clone() => new PK1((byte[])Data.Clone(), Japanese)
|
2016-08-27 08:52:34 +00:00
|
|
|
|
{
|
2019-03-17 01:41:56 +00:00
|
|
|
|
Identifier = Identifier,
|
2017-12-28 00:36:24 +00:00
|
|
|
|
otname = (byte[])otname.Clone(),
|
|
|
|
|
nick = (byte[])nick.Clone(),
|
|
|
|
|
};
|
2016-08-27 08:52:34 +00:00
|
|
|
|
|
2018-08-06 00:28:54 +00:00
|
|
|
|
protected override byte[] Encrypt() => new PokeList1(this).Write();
|
2017-01-25 11:29:38 +00:00
|
|
|
|
|
2016-08-27 08:52:34 +00:00
|
|
|
|
#region Stored Attributes
|
2018-05-05 01:05:41 +00:00
|
|
|
|
public int SpeciesID1 { get => Data[0]; set => Data[0] = (byte)value; } // raw access
|
2018-08-19 22:50:15 +00:00
|
|
|
|
public override int Species { get => SpeciesConverter.GetG1Species(SpeciesID1); set => SetSpeciesValues(value); }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int Stat_HPCurrent { get => BigEndian.ToUInt16(Data, 0x1); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x1); }
|
2018-08-19 20:35:20 +00:00
|
|
|
|
public int Stat_LevelBox { get => Data[3];set => Data[3] = (byte)value; }
|
2019-01-12 06:25:48 +00:00
|
|
|
|
public override int Status_Condition { get => Data[4]; set => Data[4] = (byte)value; }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public int Type_A { get => Data[5]; set => Data[5] = (byte)value; }
|
|
|
|
|
public int Type_B { get => Data[6]; set => Data[6] = (byte)value; }
|
|
|
|
|
public int Catch_Rate { get => Data[7]; set => Data[7] = (byte)value; }
|
|
|
|
|
public override int Move1 { get => Data[8]; set => Data[8] = (byte)value; }
|
|
|
|
|
public override int Move2 { get => Data[9]; set => Data[9] = (byte)value; }
|
|
|
|
|
public override int Move3 { get => Data[10]; set => Data[10] = (byte)value; }
|
|
|
|
|
public override int Move4 { get => Data[11]; set => Data[11] = (byte)value; }
|
|
|
|
|
public override int TID { get => BigEndian.ToUInt16(Data, 0xC); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0xC); }
|
2018-08-19 22:50:15 +00:00
|
|
|
|
public override uint EXP { get => BigEndian.ToUInt32(Data, 0xE) >> 8; set => Array.Copy(BigEndian.GetBytes(value << 8), 0, Data, 0xE, 3); }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int EV_HP { get => BigEndian.ToUInt16(Data, 0x11); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x11); }
|
|
|
|
|
public override int EV_ATK { get => BigEndian.ToUInt16(Data, 0x13); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x13); }
|
|
|
|
|
public override int EV_DEF { get => BigEndian.ToUInt16(Data, 0x15); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x15); }
|
|
|
|
|
public override int EV_SPE { get => BigEndian.ToUInt16(Data, 0x17); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x17); }
|
|
|
|
|
public int EV_SPC { get => BigEndian.ToUInt16(Data, 0x19); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x19); }
|
|
|
|
|
public override int EV_SPA { get => EV_SPC; set => EV_SPC = value; }
|
|
|
|
|
public override int EV_SPD { get => EV_SPC; set { } }
|
2018-08-19 22:50:15 +00:00
|
|
|
|
public override ushort DV16 { get => BigEndian.ToUInt16(Data, 0x1B); set => BigEndian.GetBytes(value).CopyTo(Data, 0x1B); }
|
2017-05-19 16:22:12 +00:00
|
|
|
|
public override int Move1_PP { get => Data[0x1D] & 0x3F; set => Data[0x1D] = (byte)((Data[0x1D] & 0xC0) | Math.Min(63, value)); }
|
|
|
|
|
public override int Move2_PP { get => Data[0x1E] & 0x3F; set => Data[0x1E] = (byte)((Data[0x1E] & 0xC0) | Math.Min(63, value)); }
|
|
|
|
|
public override int Move3_PP { get => Data[0x1F] & 0x3F; set => Data[0x1F] = (byte)((Data[0x1F] & 0xC0) | Math.Min(63, value)); }
|
|
|
|
|
public override int Move4_PP { get => Data[0x20] & 0x3F; set => Data[0x20] = (byte)((Data[0x20] & 0xC0) | Math.Min(63, value)); }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int Move1_PPUps { get => (Data[0x1D] & 0xC0) >> 6; set => Data[0x1D] = (byte)((Data[0x1D] & 0x3F) | ((value & 0x3) << 6)); }
|
|
|
|
|
public override int Move2_PPUps { get => (Data[0x1E] & 0xC0) >> 6; set => Data[0x1E] = (byte)((Data[0x1E] & 0x3F) | ((value & 0x3) << 6)); }
|
|
|
|
|
public override int Move3_PPUps { get => (Data[0x1F] & 0xC0) >> 6; set => Data[0x1F] = (byte)((Data[0x1F] & 0x3F) | ((value & 0x3) << 6)); }
|
|
|
|
|
public override int Move4_PPUps { get => (Data[0x20] & 0xC0) >> 6; set => Data[0x20] = (byte)((Data[0x20] & 0x3F) | ((value & 0x3) << 6)); }
|
2016-08-27 08:52:34 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Party Attributes
|
2018-08-19 22:50:15 +00:00
|
|
|
|
public override int Stat_Level { get => Data[0x21]; set => Stat_LevelBox = Data[0x21] = (byte)value; }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int Stat_HPMax { get => BigEndian.ToUInt16(Data, 0x22); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x22); }
|
|
|
|
|
public override int Stat_ATK { get => BigEndian.ToUInt16(Data, 0x24); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x24); }
|
|
|
|
|
public override int Stat_DEF { get => BigEndian.ToUInt16(Data, 0x26); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x26); }
|
|
|
|
|
public override int Stat_SPE { get => BigEndian.ToUInt16(Data, 0x28); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x28); }
|
|
|
|
|
public int Stat_SPC { get => BigEndian.ToUInt16(Data, 0x2A); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x2A); }
|
2016-08-27 08:52:34 +00:00
|
|
|
|
// Leave SPA and SPD as alias for SPC
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int Stat_SPA { get => Stat_SPC; set => Stat_SPC = value; }
|
|
|
|
|
public override int Stat_SPD { get => Stat_SPC; set { } }
|
2016-08-27 08:52:34 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2018-08-19 22:50:15 +00:00
|
|
|
|
private void SetSpeciesValues(int value)
|
2016-08-28 10:18:22 +00:00
|
|
|
|
{
|
2018-08-19 22:50:15 +00:00
|
|
|
|
var updated = (byte)SpeciesConverter.SetG1Species(value);
|
|
|
|
|
if (SpeciesID1 == updated)
|
|
|
|
|
return;
|
2016-08-28 10:18:22 +00:00
|
|
|
|
|
2018-08-21 14:37:15 +00:00
|
|
|
|
SpeciesID1 = updated;
|
|
|
|
|
|
2018-08-19 22:50:15 +00:00
|
|
|
|
Type_A = PersonalInfo.Type1;
|
|
|
|
|
Type_B = PersonalInfo.Type2;
|
|
|
|
|
|
|
|
|
|
// Before updating catch rate, check if non-standard
|
|
|
|
|
if (TradebackStatus != TradebackType.WasTradeback && !Legal.IsCatchRateHeldItem(Catch_Rate) && !(value == 25 && Catch_Rate == 0xA3)) // Light Ball Pikachu
|
|
|
|
|
{
|
|
|
|
|
int Rate = Catch_Rate;
|
2019-11-19 04:26:11 +00:00
|
|
|
|
int baseSpecies = Legal.GetBaseSpecies(this).Species;
|
2018-08-19 22:50:15 +00:00
|
|
|
|
for (int z = baseSpecies; z <= value; z++)
|
|
|
|
|
{
|
|
|
|
|
if (Rate == PersonalTable.RB[z].CatchRate && Rate == PersonalTable.Y[z].CatchRate)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Catch_Rate = PersonalTable.RB[value].CatchRate;
|
|
|
|
|
}
|
2018-07-24 23:41:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int Version { get => (int)GameVersion.RBY; set { } }
|
|
|
|
|
public override int PKRS_Strain { get => 0; set { } }
|
|
|
|
|
public override int PKRS_Days { get => 0; 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 override bool CanHoldItem(IReadOnlyList<ushort> ValidArray) => false;
|
2017-09-06 16:12:56 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
// Maximums
|
|
|
|
|
public override int MaxMoveID => Legal.MaxMoveID_1;
|
|
|
|
|
public override int MaxSpeciesID => Legal.MaxSpeciesID_1;
|
|
|
|
|
public override int MaxAbilityID => Legal.MaxAbilityID_1;
|
|
|
|
|
public override int MaxItemID => Legal.MaxItemID_1;
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public PK2 ConvertToPK2()
|
2016-09-04 22:03:40 +00:00
|
|
|
|
{
|
2019-04-18 01:35:51 +00:00
|
|
|
|
PK2 pk2 = new PK2(Japanese) {Species = Species};
|
2016-09-04 22:03:40 +00:00
|
|
|
|
Array.Copy(Data, 0x7, pk2.Data, 0x1, 0x1A);
|
2018-09-30 04:03:34 +00:00
|
|
|
|
otname.CopyTo(pk2.otname, 0);
|
|
|
|
|
nick.CopyTo(pk2.nick, 0);
|
2018-08-19 22:50:15 +00:00
|
|
|
|
|
2018-08-21 05:09:35 +00:00
|
|
|
|
pk2.HeldItem = ItemConverter.GetG2ItemTransfer(pk2.HeldItem);
|
2016-10-29 16:39:11 +00:00
|
|
|
|
pk2.CurrentFriendship = pk2.PersonalInfo.BaseFriendship;
|
2018-07-24 23:41:18 +00:00
|
|
|
|
pk2.Stat_Level = CurrentLevel;
|
2016-09-04 22:03:40 +00:00
|
|
|
|
|
|
|
|
|
return pk2;
|
|
|
|
|
}
|
2017-01-25 11:29:38 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public PK7 ConvertToPK7()
|
2017-01-25 11:29:38 +00:00
|
|
|
|
{
|
|
|
|
|
var pk7 = new PK7
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
EncryptionConstant = Util.Rand32(),
|
2017-01-25 11:29:38 +00:00
|
|
|
|
Species = Species,
|
|
|
|
|
TID = TID,
|
|
|
|
|
CurrentLevel = CurrentLevel,
|
2017-01-26 06:51:52 +00:00
|
|
|
|
EXP = EXP,
|
2017-01-25 11:29:38 +00:00
|
|
|
|
Met_Level = CurrentLevel,
|
2018-07-30 00:43:30 +00:00
|
|
|
|
Nature = Experience.GetNatureVC(EXP),
|
2017-06-18 01:37:19 +00:00
|
|
|
|
PID = Util.Rand32(),
|
2017-01-25 11:29:38 +00:00
|
|
|
|
Ball = 4,
|
|
|
|
|
MetDate = DateTime.Now,
|
2017-11-23 05:45:30 +00:00
|
|
|
|
Version = (int)GameVersion.RD, // Default to red
|
2017-01-25 11:29:38 +00:00
|
|
|
|
Move1 = Move1,
|
|
|
|
|
Move2 = Move2,
|
|
|
|
|
Move3 = Move3,
|
|
|
|
|
Move4 = Move4,
|
|
|
|
|
Move1_PPUps = Move1_PPUps,
|
|
|
|
|
Move2_PPUps = Move2_PPUps,
|
|
|
|
|
Move3_PPUps = Move3_PPUps,
|
|
|
|
|
Move4_PPUps = Move4_PPUps,
|
|
|
|
|
Move1_PP = Move1_PP,
|
|
|
|
|
Move2_PP = Move2_PP,
|
|
|
|
|
Move3_PP = Move3_PP,
|
|
|
|
|
Move4_PP = Move4_PP,
|
2017-11-23 05:45:30 +00:00
|
|
|
|
Met_Location = Legal.Transfer1, // "Kanto region", hardcoded.
|
2017-09-06 16:12:56 +00:00
|
|
|
|
Gender = Gender,
|
2019-03-21 04:50:44 +00:00
|
|
|
|
OT_Name = StringConverter12.GetG1ConvertedString(otname, Japanese),
|
2017-01-26 06:51:52 +00:00
|
|
|
|
IsNicknamed = false,
|
|
|
|
|
|
|
|
|
|
Country = PKMConverter.Country,
|
|
|
|
|
Region = PKMConverter.Region,
|
|
|
|
|
ConsoleRegion = PKMConverter.ConsoleRegion,
|
|
|
|
|
CurrentHandler = 1,
|
|
|
|
|
HT_Name = PKMConverter.OT_Name,
|
|
|
|
|
HT_Gender = PKMConverter.OT_Gender,
|
2017-01-28 17:48:00 +00:00
|
|
|
|
Geo1_Country = PKMConverter.Country,
|
|
|
|
|
Geo1_Region = PKMConverter.Region
|
2017-01-26 06:51:52 +00:00
|
|
|
|
};
|
2019-05-27 18:23:47 +00:00
|
|
|
|
pk7.Language = TransferLanguage(PKMConverter.Language);
|
2019-09-19 02:58:23 +00:00
|
|
|
|
pk7.Nickname = SpeciesName.GetSpeciesNameGeneration(pk7.Species, pk7.Language, pk7.Format);
|
2019-03-21 04:50:44 +00:00
|
|
|
|
if (otname[0] == StringConverter12.G1TradeOTCode) // Ingame Trade
|
2018-07-10 23:45:24 +00:00
|
|
|
|
pk7.OT_Name = Encounters1.TradeOTG1[pk7.Language];
|
2017-01-26 06:51:52 +00:00
|
|
|
|
pk7.OT_Friendship = pk7.HT_Friendship = PersonalTable.SM[Species].BaseFriendship;
|
|
|
|
|
|
2017-01-25 11:29:38 +00:00
|
|
|
|
// IVs
|
|
|
|
|
var new_ivs = new int[6];
|
2017-01-26 06:51:52 +00:00
|
|
|
|
int flawless = Species == 151 ? 5 : 3;
|
2018-07-04 18:30:43 +00:00
|
|
|
|
for (var i = 0; i < new_ivs.Length; i++) new_ivs[i] = Util.Rand.Next(pk7.MaxIV + 1);
|
2017-01-26 06:51:52 +00:00
|
|
|
|
for (var i = 0; i < flawless; i++) new_ivs[i] = 31;
|
2017-01-25 11:29:38 +00:00
|
|
|
|
Util.Shuffle(new_ivs);
|
|
|
|
|
pk7.IVs = new_ivs;
|
|
|
|
|
|
|
|
|
|
if (IsShiny)
|
2018-10-27 15:53:09 +00:00
|
|
|
|
pk7.SetShiny();
|
2017-01-25 11:29:38 +00:00
|
|
|
|
|
2017-01-26 06:51:52 +00:00
|
|
|
|
int abil = 2; // Hidden
|
2017-01-27 05:35:26 +00:00
|
|
|
|
if (Legal.TransferSpeciesDefaultAbility_1.Contains(Species))
|
2017-01-26 06:51:52 +00:00
|
|
|
|
abil = 0; // Reset
|
|
|
|
|
pk7.RefreshAbility(abil); // 0/1/2 (not 1/2/4)
|
2017-01-25 11:29:38 +00:00
|
|
|
|
|
2017-01-26 06:51:52 +00:00
|
|
|
|
if (Species == 151) // Mew gets special treatment.
|
2018-08-19 22:50:15 +00:00
|
|
|
|
{
|
2017-01-26 06:51:52 +00:00
|
|
|
|
pk7.FatefulEncounter = true;
|
2018-08-19 22:50:15 +00:00
|
|
|
|
}
|
2017-01-26 06:51:52 +00:00
|
|
|
|
else if (IsNicknamedBank)
|
2017-01-25 11:29:38 +00:00
|
|
|
|
{
|
|
|
|
|
pk7.IsNicknamed = true;
|
2019-03-21 04:50:44 +00:00
|
|
|
|
pk7.Nickname = StringConverter12.GetG1ConvertedString(nick, Japanese);
|
2017-01-25 11:29:38 +00:00
|
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2017-01-26 06:51:52 +00:00
|
|
|
|
pk7.TradeMemory(Bank:true); // oh no, memories on gen7 pkm
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2017-01-25 11:29:38 +00:00
|
|
|
|
pk7.RefreshChecksum();
|
|
|
|
|
return pk7;
|
|
|
|
|
}
|
2016-08-27 08:52:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|