2016-09-02 21:20:39 +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;
|
2016-09-02 21:20:39 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.Core
|
2016-09-02 21:20:39 +00:00
|
|
|
|
{
|
2017-10-24 06:12:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generation 2 <see cref="SaveFile"/> object.
|
|
|
|
|
/// </summary>
|
2019-07-14 22:06:45 +00:00
|
|
|
|
public sealed class SAV2 : SaveFile, ILangDeviantSave
|
2016-09-02 21:20:39 +00:00
|
|
|
|
{
|
2018-07-30 04:51:45 +00:00
|
|
|
|
protected override string BAKText => $"{OT} ({Version}) - {PlayTimeString}";
|
2016-10-17 14:49:40 +00:00
|
|
|
|
public override string Filter => "SAV File|*.sav|All Files|*.*";
|
2016-09-02 21:20:39 +00:00
|
|
|
|
public override string Extension => ".sav";
|
2019-07-14 22:06:45 +00:00
|
|
|
|
public bool Japanese { get; }
|
|
|
|
|
public bool Korean { get; }
|
2018-09-15 05:37:47 +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
|
|
|
|
public override PersonalTable Personal { get; }
|
|
|
|
|
public override IReadOnlyList<ushort> HeldItems => Legal.HeldItems_GSC;
|
|
|
|
|
|
2018-05-12 15:13:39 +00:00
|
|
|
|
public override string[] PKMExtensions => PKM.Extensions.Where(f =>
|
2017-01-05 06:22:50 +00:00
|
|
|
|
{
|
|
|
|
|
int gen = f.Last() - 0x30;
|
2017-09-11 02:56:21 +00:00
|
|
|
|
if (Korean)
|
|
|
|
|
return gen == 2;
|
2017-01-05 06:22:50 +00:00
|
|
|
|
return 1 <= gen && gen <= 2;
|
|
|
|
|
}).ToArray();
|
2016-09-02 21:20:39 +00:00
|
|
|
|
|
2019-07-21 19:30:21 +00:00
|
|
|
|
public SAV2(GameVersion version = GameVersion.C, LanguageID lang = LanguageID.English) : base(SaveUtil.SIZE_G2RAW_J)
|
2016-09-02 21:20:39 +00:00
|
|
|
|
{
|
2019-07-21 19:30:21 +00:00
|
|
|
|
Version = version;
|
2019-06-09 02:56:11 +00:00
|
|
|
|
switch (lang)
|
|
|
|
|
{
|
|
|
|
|
case LanguageID.Japanese:
|
|
|
|
|
Japanese = true;
|
|
|
|
|
break;
|
|
|
|
|
case LanguageID.Korean:
|
|
|
|
|
Korean = true;
|
|
|
|
|
break;
|
|
|
|
|
// otherwise, both false
|
|
|
|
|
}
|
|
|
|
|
Offsets = new SAV2Offsets(this);
|
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
|
|
|
|
Personal = Version == GameVersion.GS ? PersonalTable.GS : PersonalTable.C;
|
2019-06-09 02:56:11 +00:00
|
|
|
|
Initialize();
|
|
|
|
|
ClearBoxes();
|
|
|
|
|
}
|
2017-01-15 00:43:16 +00:00
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
public SAV2(byte[] data, GameVersion versionOverride = GameVersion.Any) : base(data)
|
|
|
|
|
{
|
|
|
|
|
Version = versionOverride != GameVersion.Any ? versionOverride : SaveUtil.GetIsG2SAV(Data);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
Japanese = SaveUtil.GetIsG2SAVJ(Data) != GameVersion.Invalid;
|
2017-09-11 02:56:21 +00:00
|
|
|
|
if (!Japanese)
|
|
|
|
|
Korean = SaveUtil.GetIsG2SAVK(Data) != GameVersion.Invalid;
|
2016-09-04 01:57:54 +00:00
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
Offsets = new SAV2Offsets(this);
|
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
|
|
|
|
Personal = Version == GameVersion.GS ? PersonalTable.GS : PersonalTable.C;
|
2019-06-09 02:56:11 +00:00
|
|
|
|
Initialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Initialize()
|
|
|
|
|
{
|
2016-09-02 21:20:39 +00:00
|
|
|
|
Box = Data.Length;
|
|
|
|
|
Array.Resize(ref Data, Data.Length + SIZE_RESERVED);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
Party = GetPartyOffset(0);
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2016-09-02 21:20:39 +00:00
|
|
|
|
// Stash boxes after the save file's end.
|
2018-08-06 00:28:54 +00:00
|
|
|
|
int splitAtIndex = (Japanese ? 6 : 7);
|
|
|
|
|
int stored = SIZE_STOREDBOX;
|
|
|
|
|
int baseDest = Data.Length - SIZE_RESERVED;
|
|
|
|
|
var capacity = Japanese ? PokeListType.StoredJP : PokeListType.Stored;
|
2016-09-02 21:20:39 +00:00
|
|
|
|
for (int i = 0; i < BoxCount; i++)
|
|
|
|
|
{
|
2018-08-06 00:28:54 +00:00
|
|
|
|
int ofs = GetBoxRawDataOffset(i, splitAtIndex);
|
|
|
|
|
var box = GetData(ofs, stored);
|
|
|
|
|
var boxDest = baseDest + (i * SIZE_BOX);
|
|
|
|
|
var boxPL = new PokeList2(box, capacity, Japanese);
|
|
|
|
|
for (int j = 0; j < boxPL.Pokemon.Length; j++)
|
2016-09-02 21:20:39 +00:00
|
|
|
|
{
|
2018-08-06 00:28:54 +00:00
|
|
|
|
var dest = boxDest + (j * SIZE_STORED);
|
|
|
|
|
var pkDat = (j < boxPL.Count)
|
|
|
|
|
? new PokeList2(boxPL[j]).Write()
|
|
|
|
|
: new byte[PokeList2.GetDataLength(PokeListType.Single, Japanese)];
|
|
|
|
|
pkDat.CopyTo(Data, dest);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-06 00:28:54 +00:00
|
|
|
|
var current = GetData(Offsets.CurrentBox, stored);
|
|
|
|
|
var curBoxPL = new PokeList2(current, capacity, Japanese);
|
|
|
|
|
var curDest = baseDest + (CurrentBox * SIZE_BOX);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
for (int i = 0; i < curBoxPL.Pokemon.Length; i++)
|
|
|
|
|
{
|
2018-08-06 00:28:54 +00:00
|
|
|
|
var dest = curDest + (i * SIZE_STORED);
|
|
|
|
|
var pkDat = i < curBoxPL.Count
|
|
|
|
|
? new PokeList2(curBoxPL[i]).Write()
|
|
|
|
|
: new byte[PokeList2.GetDataLength(PokeListType.Single, Japanese)];
|
|
|
|
|
pkDat.CopyTo(Data, dest);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-06 00:28:54 +00:00
|
|
|
|
var party = GetData(Offsets.Party, SIZE_STOREDPARTY);
|
|
|
|
|
var partyPL = new PokeList2(party, PokeListType.Party, Japanese);
|
|
|
|
|
for (int i = 0; i < partyPL.Pokemon.Length; i++)
|
2016-09-02 21:20:39 +00:00
|
|
|
|
{
|
2018-08-06 00:28:54 +00:00
|
|
|
|
var dest = GetPartyOffset(i);
|
|
|
|
|
var pkDat = i < partyPL.Count
|
|
|
|
|
? new PokeList2(partyPL[i]).Write()
|
|
|
|
|
: new byte[PokeList2.GetDataLength(PokeListType.Single, Japanese)];
|
|
|
|
|
pkDat.CopyTo(Data, dest);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
2016-09-04 01:57:54 +00:00
|
|
|
|
|
2018-07-08 22:46:37 +00:00
|
|
|
|
if (Offsets.Daycare >= 0)
|
|
|
|
|
{
|
|
|
|
|
int offset = Offsets.Daycare;
|
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
DaycareFlags[0] = Data[offset];
|
|
|
|
|
offset++;
|
2018-07-08 22:46:37 +00:00
|
|
|
|
var pk1 = ReadPKMFromOffset(offset); // parent 1
|
2018-08-06 00:28:54 +00:00
|
|
|
|
var daycare1 = new PokeList2(pk1);
|
2018-09-15 05:37:47 +00:00
|
|
|
|
offset += (StringLength * 2) + 0x20; // nick/ot/pkm
|
2019-06-09 02:56:11 +00:00
|
|
|
|
DaycareFlags[1] = Data[offset];
|
|
|
|
|
offset++;
|
2019-10-26 19:33:58 +00:00
|
|
|
|
//byte steps = Data[offset];
|
2019-06-09 02:56:11 +00:00
|
|
|
|
offset++;
|
2019-10-26 19:33:58 +00:00
|
|
|
|
//byte BreedMotherOrNonDitto = Data[offset];
|
2019-06-09 02:56:11 +00:00
|
|
|
|
offset++;
|
2018-07-08 22:46:37 +00:00
|
|
|
|
var pk2 = ReadPKMFromOffset(offset); // parent 2
|
2018-08-06 00:28:54 +00:00
|
|
|
|
var daycare2 = new PokeList2(pk2);
|
2020-01-04 22:48:39 +00:00
|
|
|
|
offset += (StringLength * 2) + PokeCrypto.SIZE_2STORED; // nick/ot/pkm
|
2018-07-08 22:46:37 +00:00
|
|
|
|
var pk3 = ReadPKMFromOffset(offset); // egg!
|
|
|
|
|
pk3.IsEgg = true;
|
2018-08-06 00:28:54 +00:00
|
|
|
|
var daycare3 = new PokeList2(pk3);
|
2018-07-08 22:46:37 +00:00
|
|
|
|
|
2018-08-06 00:28:54 +00:00
|
|
|
|
daycare1.Write().CopyTo(Data, GetPartyOffset(7 + (0 * 2)));
|
|
|
|
|
daycare2.Write().CopyTo(Data, GetPartyOffset(7 + (1 * 2)));
|
|
|
|
|
daycare3.Write().CopyTo(Data, GetPartyOffset(7 + (2 * 2)));
|
2019-10-19 03:42:03 +00:00
|
|
|
|
DaycareOffset = Offsets.Daycare;
|
2018-07-08 22:46:37 +00:00
|
|
|
|
}
|
2016-09-04 01:57:54 +00:00
|
|
|
|
|
2016-09-02 21:20:39 +00:00
|
|
|
|
// Enable Pokedex editing
|
|
|
|
|
PokeDex = 0;
|
2017-11-28 00:46:14 +00:00
|
|
|
|
EventFlag = Offsets.EventFlag;
|
2019-03-06 07:06:05 +00:00
|
|
|
|
EventConst = Offsets.EventConst;
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-08 22:46:37 +00:00
|
|
|
|
private PK2 ReadPKMFromOffset(int offset)
|
|
|
|
|
{
|
|
|
|
|
byte[] nick = new byte[StringLength];
|
|
|
|
|
byte[] ot = new byte[StringLength];
|
2020-01-04 22:48:39 +00:00
|
|
|
|
byte[] pk = new byte[PokeCrypto.SIZE_2STORED];
|
2018-07-08 22:46:37 +00:00
|
|
|
|
|
|
|
|
|
Array.Copy(Data, offset, nick, 0, nick.Length); offset += nick.Length;
|
|
|
|
|
Array.Copy(Data, offset, ot, 0, ot.Length); offset += ot.Length;
|
|
|
|
|
Array.Copy(Data, offset, pk, 0, pk.Length);
|
|
|
|
|
|
|
|
|
|
return new PK2(pk, jp: Japanese) { otname = ot, nick = nick };
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-02 21:20:39 +00:00
|
|
|
|
private const int SIZE_RESERVED = 0x8000; // unpacked box data
|
2017-09-11 02:56:21 +00:00
|
|
|
|
private readonly SAV2Offsets Offsets;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
|
2018-08-06 00:28:54 +00:00
|
|
|
|
private int GetBoxRawDataOffset(int i, int splitAtIndex)
|
|
|
|
|
{
|
|
|
|
|
if (i < splitAtIndex)
|
|
|
|
|
return 0x4000 + (i * (SIZE_STOREDBOX + 2));
|
|
|
|
|
return 0x6000 + ((i - splitAtIndex) * (SIZE_STOREDBOX + 2));
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-19 05:59:57 +00:00
|
|
|
|
protected override byte[] GetFinalData()
|
2016-09-02 21:20:39 +00:00
|
|
|
|
{
|
2018-08-06 00:28:54 +00:00
|
|
|
|
int splitAtIndex = (Japanese ? 6 : 7);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
for (int i = 0; i < BoxCount; i++)
|
|
|
|
|
{
|
2018-08-06 00:28:54 +00:00
|
|
|
|
var boxPL = new PokeList2(Japanese ? PokeListType.StoredJP : PokeListType.Stored, Japanese);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
int slot = 0;
|
|
|
|
|
for (int j = 0; j < boxPL.Pokemon.Length; j++)
|
|
|
|
|
{
|
2018-09-15 05:37:47 +00:00
|
|
|
|
PK2 boxPK = (PK2) GetPKM(GetData(GetBoxOffset(i) + (j * SIZE_STORED), SIZE_STORED));
|
2016-09-02 21:20:39 +00:00
|
|
|
|
if (boxPK.Species > 0)
|
|
|
|
|
boxPL[slot++] = boxPK;
|
|
|
|
|
}
|
2018-08-06 00:28:54 +00:00
|
|
|
|
|
|
|
|
|
int src = GetBoxRawDataOffset(i, splitAtIndex);
|
|
|
|
|
boxPL.Write().CopyTo(Data, src);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
if (i == CurrentBox)
|
2018-08-06 00:28:54 +00:00
|
|
|
|
boxPL.Write().CopyTo(Data, Offsets.CurrentBox);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-06 00:28:54 +00:00
|
|
|
|
var partyPL = new PokeList2(PokeListType.Party, Japanese);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
int pSlot = 0;
|
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
PK2 partyPK = (PK2)GetPKM(GetData(GetPartyOffset(i), SIZE_STORED));
|
2016-09-02 21:20:39 +00:00
|
|
|
|
if (partyPK.Species > 0)
|
|
|
|
|
partyPL[pSlot++] = partyPK;
|
|
|
|
|
}
|
2018-08-06 00:28:54 +00:00
|
|
|
|
partyPL.Write().CopyTo(Data, Offsets.Party);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetChecksums();
|
2017-09-11 02:56:21 +00:00
|
|
|
|
if (Japanese)
|
2016-09-04 01:57:54 +00:00
|
|
|
|
{
|
2017-09-11 02:56:21 +00:00
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
|
|
|
|
case GameVersion.GS: Array.Copy(Data, Offsets.Trainer1, Data, 0x7209, 0xC83); break;
|
|
|
|
|
case GameVersion.C: Array.Copy(Data, Offsets.Trainer1, Data, 0x7209, 0xADA); break;
|
|
|
|
|
}
|
2016-09-04 01:57:54 +00:00
|
|
|
|
}
|
2017-09-11 02:56:21 +00:00
|
|
|
|
else if (Korean)
|
2016-09-04 01:57:54 +00:00
|
|
|
|
{
|
2017-09-11 02:56:21 +00:00
|
|
|
|
// Calculate oddball checksum
|
|
|
|
|
ushort sum = 0;
|
|
|
|
|
ushort[][] offsetpairs =
|
|
|
|
|
{
|
|
|
|
|
new ushort[] {0x106B, 0x1533},
|
|
|
|
|
new ushort[] {0x1534, 0x1A12},
|
|
|
|
|
new ushort[] {0x1A13, 0x1C38},
|
|
|
|
|
new ushort[] {0x3DD8, 0x3F79},
|
|
|
|
|
new ushort[] {0x7E39, 0x7E6A},
|
|
|
|
|
};
|
|
|
|
|
foreach (ushort[] p in offsetpairs)
|
2018-09-15 05:37:47 +00:00
|
|
|
|
{
|
2017-09-11 02:56:21 +00:00
|
|
|
|
for (int i = p[0]; i < p[1]; i++)
|
|
|
|
|
sum += Data[i];
|
2018-09-15 05:37:47 +00:00
|
|
|
|
}
|
2017-09-11 02:56:21 +00:00
|
|
|
|
BitConverter.GetBytes(sum).CopyTo(Data, 0x7E6B);
|
2016-09-04 01:57:54 +00:00
|
|
|
|
}
|
2017-09-11 02:56:21 +00:00
|
|
|
|
else
|
2016-09-04 06:15:09 +00:00
|
|
|
|
{
|
2017-09-11 02:56:21 +00:00
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
|
|
|
|
case GameVersion.GS:
|
|
|
|
|
Array.Copy(Data, 0x2009, Data, 0x15C7, 0x222F - 0x2009);
|
|
|
|
|
Array.Copy(Data, 0x222F, Data, 0x3D69, 0x23D9 - 0x222F);
|
|
|
|
|
Array.Copy(Data, 0x23D9, Data, 0x0C6B, 0x2856 - 0x23D9);
|
|
|
|
|
Array.Copy(Data, 0x2856, Data, 0x7E39, 0x288A - 0x2856);
|
|
|
|
|
Array.Copy(Data, 0x288A, Data, 0x10E8, 0x2D69 - 0x288A);
|
|
|
|
|
break;
|
|
|
|
|
case GameVersion.C:
|
|
|
|
|
Array.Copy(Data, 0x2009, Data, 0x1209, 0xB7A);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-09-04 06:15:09 +00:00
|
|
|
|
}
|
2016-09-02 21:20:39 +00:00
|
|
|
|
byte[] outData = new byte[Data.Length - SIZE_RESERVED];
|
|
|
|
|
Array.Copy(Data, outData, outData.Length);
|
|
|
|
|
return outData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Configuration
|
2019-02-19 05:59:57 +00:00
|
|
|
|
public override SaveFile Clone() => new SAV2(Write());
|
2016-09-02 21:20:39 +00:00
|
|
|
|
|
2020-01-04 22:48:39 +00:00
|
|
|
|
public override int SIZE_STORED => Japanese ? PokeCrypto.SIZE_2JLIST : PokeCrypto.SIZE_2ULIST;
|
|
|
|
|
protected override int SIZE_PARTY => Japanese ? PokeCrypto.SIZE_2JLIST : PokeCrypto.SIZE_2ULIST;
|
2017-12-28 00:36:24 +00:00
|
|
|
|
public override PKM BlankPKM => new PK2(jp: Japanese);
|
2016-09-26 23:14:11 +00:00
|
|
|
|
public override Type PKMType => typeof(PK2);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
|
2017-01-05 06:22:50 +00:00
|
|
|
|
private int SIZE_BOX => BoxSlotCount*SIZE_STORED;
|
2018-08-06 00:28:54 +00:00
|
|
|
|
private int SIZE_STOREDBOX => PokeList2.GetDataLength(Japanese ? PokeListType.StoredJP : PokeListType.Stored, Japanese);
|
|
|
|
|
private int SIZE_STOREDPARTY => PokeList2.GetDataLength(PokeListType.Party, Japanese);
|
2017-01-05 06:22:50 +00:00
|
|
|
|
|
2017-01-27 03:18:20 +00:00
|
|
|
|
public override int MaxMoveID => Legal.MaxMoveID_2;
|
2016-10-24 04:59:27 +00:00
|
|
|
|
public override int MaxSpeciesID => Legal.MaxSpeciesID_2;
|
2017-01-27 03:18:20 +00:00
|
|
|
|
public override int MaxAbilityID => Legal.MaxAbilityID_2;
|
|
|
|
|
public override int MaxItemID => Legal.MaxItemID_2;
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override int MaxBallID => 0; // unused
|
|
|
|
|
public override int MaxGameID => 99; // unused
|
2016-09-09 03:20:32 +00:00
|
|
|
|
public override int MaxMoney => 999999;
|
2017-02-04 20:13:54 +00:00
|
|
|
|
public override int MaxCoins => 9999;
|
2016-09-02 21:20:39 +00:00
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
public override bool IsPKMPresent(byte[] data, int offset) => PKX.IsPKMPresentGB(data, offset);
|
2018-03-18 23:22:21 +00:00
|
|
|
|
|
2019-03-06 07:06:05 +00:00
|
|
|
|
protected override int EventConstMax => 0x100;
|
|
|
|
|
protected override int EventFlagMax => 2000;
|
2017-11-27 18:35:49 +00:00
|
|
|
|
|
2016-09-02 21:20:39 +00:00
|
|
|
|
public override int BoxCount => Japanese ? 9 : 14;
|
|
|
|
|
public override int MaxEV => 65535;
|
|
|
|
|
public override int MaxIV => 15;
|
|
|
|
|
public override int Generation => 2;
|
|
|
|
|
protected override int GiftCountMax => 0;
|
2017-10-25 01:49:51 +00:00
|
|
|
|
public override int OTLength => Japanese || Korean ? 5 : 7;
|
|
|
|
|
public override int NickLength => Japanese || Korean ? 5 : 10;
|
2016-09-02 21:20:39 +00:00
|
|
|
|
public override int BoxSlotCount => Japanese ? 30 : 20;
|
|
|
|
|
|
|
|
|
|
public override bool HasParty => true;
|
2017-12-27 23:52:29 +00:00
|
|
|
|
public override bool HasNamableBoxes => true;
|
2019-10-26 19:42:33 +00:00
|
|
|
|
private int StringLength => Japanese ? GBPKM.STRLEN_J : GBPKM.STRLEN_U;
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2016-09-02 21:20:39 +00:00
|
|
|
|
// Checksums
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private ushort GetChecksum()
|
2016-09-02 21:20:39 +00:00
|
|
|
|
{
|
2018-10-13 15:02:55 +00:00
|
|
|
|
ushort sum = 0;
|
|
|
|
|
for (int i = Offsets.Trainer1; i <= Offsets.AccumulatedChecksumEnd; i++)
|
|
|
|
|
sum += Data[i];
|
|
|
|
|
return sum;
|
2017-02-25 07:01:07 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected override void SetChecksums()
|
2017-02-25 07:01:07 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
ushort accum = GetChecksum();
|
2017-09-11 02:56:21 +00:00
|
|
|
|
BitConverter.GetBytes(accum).CopyTo(Data, Offsets.OverallChecksumPosition);
|
|
|
|
|
BitConverter.GetBytes(accum).CopyTo(Data, Offsets.OverallChecksumPosition2);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-09-02 21:20:39 +00:00
|
|
|
|
public override bool ChecksumsValid
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
ushort accum = GetChecksum();
|
2017-09-11 02:56:21 +00:00
|
|
|
|
ushort actual = BitConverter.ToUInt16(Data, Offsets.OverallChecksumPosition);
|
|
|
|
|
return accum == actual;
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-04 01:57:54 +00:00
|
|
|
|
|
2016-09-04 06:54:11 +00:00
|
|
|
|
public override string ChecksumInfo => ChecksumsValid ? "Checksum valid." : "Checksum invalid";
|
2016-09-02 21:20:39 +00:00
|
|
|
|
|
|
|
|
|
// Trainer Info
|
|
|
|
|
public override GameVersion Version { get; protected set; }
|
|
|
|
|
|
|
|
|
|
public override string OT
|
|
|
|
|
{
|
2017-10-25 01:49:51 +00:00
|
|
|
|
get => GetString(Offsets.Trainer1 + 2, (Korean ? 2 : 1) * OTLength);
|
|
|
|
|
set => SetString(value, (Korean ? 2 : 1) * OTLength).CopyTo(Data, Offsets.Trainer1 + 2);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-10-26 19:33:58 +00:00
|
|
|
|
public byte[] OT_Trash
|
|
|
|
|
{
|
|
|
|
|
get => GetData(Offsets.Trainer1 + 2, StringLength);
|
|
|
|
|
set { if (value?.Length == StringLength) SetData(value, Offsets.Trainer1 + 2); }
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-09-02 21:20:39 +00:00
|
|
|
|
public override int Gender
|
|
|
|
|
{
|
2017-09-11 02:56:21 +00:00
|
|
|
|
get => Version == GameVersion.C ? Data[Offsets.Gender] : 0;
|
2016-09-04 01:57:54 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (Version != GameVersion.C)
|
|
|
|
|
return;
|
2017-09-11 02:56:21 +00:00
|
|
|
|
Data[Offsets.Gender] = (byte) value;
|
|
|
|
|
Data[Offsets.Palette] = (byte) value;
|
2016-09-04 01:57:54 +00:00
|
|
|
|
}
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-04-28 18:06:58 +00:00
|
|
|
|
public override int TID
|
2016-09-02 21:20:39 +00:00
|
|
|
|
{
|
2019-10-26 19:33:58 +00:00
|
|
|
|
get => BigEndian.ToUInt16(Data, Offsets.Trainer1);
|
|
|
|
|
set => BigEndian.GetBytes((ushort)value).CopyTo(Data, Offsets.Trainer1);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-04-28 18:06:58 +00:00
|
|
|
|
public override int SID { get => 0; set { } }
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-09-02 21:20:39 +00:00
|
|
|
|
public override int PlayedHours
|
|
|
|
|
{
|
2017-09-11 02:56:21 +00:00
|
|
|
|
get => BigEndian.ToUInt16(Data, Offsets.TimePlayed);
|
|
|
|
|
set => BigEndian.GetBytes((ushort)value).CopyTo(Data, Offsets.TimePlayed);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-09-02 21:20:39 +00:00
|
|
|
|
public override int PlayedMinutes
|
|
|
|
|
{
|
2017-09-11 02:56:21 +00:00
|
|
|
|
get => Data[Offsets.TimePlayed + 2];
|
|
|
|
|
set => Data[Offsets.TimePlayed + 2] = (byte)value;
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-09-02 21:20:39 +00:00
|
|
|
|
public override int PlayedSeconds
|
|
|
|
|
{
|
2017-09-11 02:56:21 +00:00
|
|
|
|
get => Data[Offsets.TimePlayed + 3];
|
|
|
|
|
set => Data[Offsets.TimePlayed + 3] = (byte)value;
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Badges
|
|
|
|
|
{
|
2017-09-11 02:56:21 +00:00
|
|
|
|
get => BitConverter.ToUInt16(Data, Offsets.JohtoBadges);
|
2017-10-03 06:17:00 +00:00
|
|
|
|
set { if (value < 0) return; BitConverter.GetBytes((ushort)value).CopyTo(Data, Offsets.JohtoBadges); }
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-09-02 21:20:39 +00:00
|
|
|
|
private byte Options
|
|
|
|
|
{
|
2017-09-11 02:56:21 +00:00
|
|
|
|
get => Data[Offsets.Options];
|
|
|
|
|
set => Data[Offsets.Options] = value;
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-09-02 21:20:39 +00:00
|
|
|
|
public bool BattleEffects
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => (Options & 0x80) == 0;
|
|
|
|
|
set => Options = (byte)((Options & 0x7F) | (value ? 0 : 0x80));
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-09-02 21:20:39 +00:00
|
|
|
|
public bool BattleStyleSwitch
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => (Options & 0x40) == 0;
|
|
|
|
|
set => Options = (byte)((Options & 0xBF) | (value ? 0 : 0x40));
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-09-02 21:20:39 +00:00
|
|
|
|
public int Sound
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => (Options & 0x30) >> 4;
|
2019-03-30 23:38:52 +00:00
|
|
|
|
set => Options = (byte)((Options & 0xCF) | ((value != 0 ? 2 : 0) << 4)); // Stereo 2, Mono 0
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-09-02 21:20:39 +00:00
|
|
|
|
public int TextSpeed
|
|
|
|
|
{
|
2017-12-27 23:52:29 +00:00
|
|
|
|
get => Options & 0x7;
|
2019-03-30 23:38:52 +00:00
|
|
|
|
set => Options = (byte)((Options & 0xF8) | (value & 7));
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-06-09 21:15:42 +00:00
|
|
|
|
public bool SaveFileExists
|
|
|
|
|
{
|
|
|
|
|
get => Data[Offsets.Options + 1] == 1;
|
|
|
|
|
set => Data[Offsets.Options + 1] = (byte)(value ? 1 : 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int TextBoxFrame // 3bits
|
|
|
|
|
{
|
|
|
|
|
get => Data[Offsets.Options + 2] & 0b0000_0111;
|
|
|
|
|
set => Data[Offsets.Options + 2] = (byte)((Data[Offsets.Options + 2] & 0b1111_1000) | (value & 0b0000_0111));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int TextBoxFlags { get => Data[Offsets.Options + 3]; set => Data[Offsets.Options + 3] = (byte)value; }
|
|
|
|
|
|
|
|
|
|
public bool TextBoxFrameDelay1 // bit 0
|
|
|
|
|
{
|
|
|
|
|
get => (TextBoxFlags & 0x01) == 0x01;
|
|
|
|
|
set => TextBoxFlags = (TextBoxFlags & ~0x01) | (value ? 0x01 : 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool TextBoxFrameDelayNone // bit 4
|
|
|
|
|
{
|
|
|
|
|
get => (TextBoxFlags & 0x10) == 0x10;
|
|
|
|
|
set => TextBoxFlags = (TextBoxFlags & ~0x10) | (value ? 0x10 : 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public byte GBPrinterBrightness { get => Data[Offsets.Options + 4]; set => Data[Offsets.Options + 4] = value; }
|
|
|
|
|
|
|
|
|
|
public bool MenuAccountOn
|
|
|
|
|
{
|
|
|
|
|
get => Data[Offsets.Options + 5] == 1;
|
|
|
|
|
set => Data[Offsets.Options + 5] = (byte)(value ? 1 : 0);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-02 21:20:39 +00:00
|
|
|
|
public override uint Money
|
|
|
|
|
{
|
2017-09-11 02:56:21 +00:00
|
|
|
|
get => BigEndian.ToUInt32(Data, Offsets.Money - 1) & 0xFFFFFF;
|
2016-09-02 21:20:39 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
2017-03-05 05:52:39 +00:00
|
|
|
|
byte[] data = BigEndian.GetBytes((uint) Math.Min(value, MaxMoney));
|
2017-09-11 02:56:21 +00:00
|
|
|
|
Array.Copy(data, 1, Data, Offsets.Money, 3);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-09-02 21:20:39 +00:00
|
|
|
|
public uint Coin
|
|
|
|
|
{
|
2017-09-11 02:56:21 +00:00
|
|
|
|
get => BigEndian.ToUInt16(Data, Offsets.Money + 7);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
2017-02-08 23:51:18 +00:00
|
|
|
|
value = (ushort)Math.Min(value, MaxCoins);
|
2017-09-11 02:56:21 +00:00
|
|
|
|
BigEndian.GetBytes((ushort)value).CopyTo(Data, Offsets.Money + 7);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-26 19:33:58 +00:00
|
|
|
|
private static ushort[] LegalItems => Legal.Pouch_Items_GSC;
|
2019-11-16 21:15:09 +00:00
|
|
|
|
private ushort[] LegalKeyItems => Version == GameVersion.C? Legal.Pouch_Key_C : Legal.Pouch_Key_GS;
|
|
|
|
|
private static ushort[] LegalBalls => Legal.Pouch_Ball_GSC;
|
2019-10-26 19:33:58 +00:00
|
|
|
|
private static ushort[] LegalTMHMs => Legal.Pouch_TMHM_GSC;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-09-02 21:20:39 +00:00
|
|
|
|
public override InventoryPouch[] Inventory
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2018-07-29 20:55:07 +00:00
|
|
|
|
InventoryPouch[] pouch =
|
2016-09-04 01:57:54 +00:00
|
|
|
|
{
|
2018-07-29 20:55:07 +00:00
|
|
|
|
new InventoryPouchGB(InventoryType.TMHMs, LegalTMHMs, 99, Offsets.PouchTMHM, 57),
|
|
|
|
|
new InventoryPouchGB(InventoryType.Items, LegalItems, 99, Offsets.PouchItem, 20),
|
|
|
|
|
new InventoryPouchGB(InventoryType.KeyItems, LegalKeyItems, 99, Offsets.PouchKey, 26),
|
|
|
|
|
new InventoryPouchGB(InventoryType.Balls, LegalBalls, 99, Offsets.PouchBall, 12),
|
|
|
|
|
new InventoryPouchGB(InventoryType.PCItems, LegalItems.Concat(LegalKeyItems).Concat(LegalBalls).Concat(LegalTMHMs).ToArray(), 99, Offsets.PouchPC, 50)
|
2017-09-11 02:56:21 +00:00
|
|
|
|
};
|
2019-03-30 23:10:14 +00:00
|
|
|
|
return pouch.LoadAll(Data);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
2019-03-30 23:10:14 +00:00
|
|
|
|
set => value.SaveAll(Data);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-08 22:46:37 +00:00
|
|
|
|
private readonly byte[] DaycareFlags = new byte[2];
|
2018-09-15 05:37:47 +00:00
|
|
|
|
public override int GetDaycareSlotOffset(int loc, int slot) => GetPartyOffset(7 + (slot * 2));
|
2018-07-08 22:46:37 +00:00
|
|
|
|
public override uint? GetDaycareEXP(int loc, int slot) => null;
|
|
|
|
|
public override bool? IsDaycareOccupied(int loc, int slot) => (DaycareFlags[slot] & 1) != 0;
|
|
|
|
|
public override void SetDaycareEXP(int loc, int slot, uint EXP) { }
|
|
|
|
|
public override void SetDaycareOccupied(int loc, int slot, bool occupied) { }
|
2016-09-02 21:20:39 +00:00
|
|
|
|
|
|
|
|
|
// Storage
|
|
|
|
|
public override int PartyCount
|
|
|
|
|
{
|
2017-09-11 02:56:21 +00:00
|
|
|
|
get => Data[Offsets.Party]; protected set => Data[Offsets.Party] = (byte)value;
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override int GetBoxOffset(int box)
|
2016-09-02 21:20:39 +00:00
|
|
|
|
{
|
2018-09-15 05:37:47 +00:00
|
|
|
|
return Data.Length - SIZE_RESERVED + (box * SIZE_BOX);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override int GetPartyOffset(int slot)
|
2016-09-02 21:20:39 +00:00
|
|
|
|
{
|
2018-09-15 05:37:47 +00:00
|
|
|
|
return Data.Length - SIZE_RESERVED + (BoxCount * SIZE_BOX) + (slot * SIZE_STORED);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-09-02 21:20:39 +00:00
|
|
|
|
public override int CurrentBox
|
|
|
|
|
{
|
2017-09-11 02:56:21 +00:00
|
|
|
|
get => Data[Offsets.CurrentBoxIndex] & 0x7F; set => Data[Offsets.CurrentBoxIndex] = (byte)((Data[Offsets.OtherCurrentBox] & 0x80) | (value & 0x7F));
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
2017-09-11 02:56:21 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override string GetBoxName(int box)
|
2016-09-02 21:20:39 +00:00
|
|
|
|
{
|
2017-09-13 02:47:37 +00:00
|
|
|
|
int len = Korean ? 17 : 9;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
return GetString(Offsets.BoxNames + (box * len), len);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override void SetBoxName(int box, string value)
|
2016-09-02 21:20:39 +00:00
|
|
|
|
{
|
2017-12-27 23:52:29 +00:00
|
|
|
|
int len = Korean ? 17 : 9;
|
|
|
|
|
var data = SetString(value, len, len, 0x50);
|
2018-09-15 05:37:47 +00:00
|
|
|
|
SetData(data, Offsets.BoxNames + (box * len));
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-30 02:43:33 +00:00
|
|
|
|
protected override PKM GetPKM(byte[] data)
|
2016-09-02 21:20:39 +00:00
|
|
|
|
{
|
|
|
|
|
if (data.Length == SIZE_STORED)
|
2018-08-06 00:28:54 +00:00
|
|
|
|
return new PokeList2(data, PokeListType.Single, Japanese)[0];
|
2016-09-02 21:20:39 +00:00
|
|
|
|
return new PK2(data);
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-03-30 02:43:33 +00:00
|
|
|
|
protected override byte[] DecryptPKM(byte[] data)
|
2016-09-02 21:20:39 +00:00
|
|
|
|
{
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Pokédex
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected override void SetDex(PKM pkm)
|
2016-09-02 21:20:39 +00:00
|
|
|
|
{
|
2017-03-15 05:41:15 +00:00
|
|
|
|
int species = pkm.Species;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (!CanSetDex(species))
|
2017-03-15 05:41:15 +00:00
|
|
|
|
return;
|
2016-09-02 21:20:39 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetCaught(pkm.Species, true);
|
|
|
|
|
SetSeen(pkm.Species, true);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private bool CanSetDex(int species)
|
2016-09-02 21:20:39 +00:00
|
|
|
|
{
|
2017-03-15 05:41:15 +00:00
|
|
|
|
if (species <= 0)
|
2016-09-02 21:20:39 +00:00
|
|
|
|
return false;
|
2017-03-15 05:41:15 +00:00
|
|
|
|
if (species > MaxSpeciesID)
|
2016-09-02 21:20:39 +00:00
|
|
|
|
return false;
|
2018-03-12 01:07:48 +00:00
|
|
|
|
if (Version == GameVersion.Invalid)
|
2016-09-02 21:20:39 +00:00
|
|
|
|
return false;
|
2017-03-15 05:41:15 +00:00
|
|
|
|
return true;
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-09-11 02:56:21 +00:00
|
|
|
|
private void SetUnownFormFlags()
|
|
|
|
|
{
|
2017-03-15 05:41:15 +00:00
|
|
|
|
// Give all Unown caught to prevent a crash on pokedex view
|
|
|
|
|
for (int i = 1; i <= 26; i++)
|
2017-09-11 02:56:21 +00:00
|
|
|
|
Data[Offsets.PokedexSeen + 0x1F + i] = (byte)i;
|
2017-12-27 17:56:04 +00:00
|
|
|
|
if (UnownFirstSeen == 0) // Invalid
|
|
|
|
|
UnownFirstSeen = 1; // A
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-12-27 17:56:04 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Toggles the availability of Unown letter groups in the Wild
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Max value of 0x0F, 4 bitflags
|
|
|
|
|
/// 1 lsh 0: A, B, C, D, E, F, G, H, I, J, K
|
|
|
|
|
/// 1 lsh 1: L, M, N, O, P, Q, R
|
|
|
|
|
/// 1 lsh 2: S, T, U, V, W
|
|
|
|
|
/// 1 lsh 3: X, Y, Z
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public int UnownUnlocked
|
|
|
|
|
{
|
|
|
|
|
get => Data[Offsets.PokedexSeen + 0x1F + 27];
|
|
|
|
|
set => Data[Offsets.PokedexSeen + 0x1F + 27] = (byte)value;
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-12-27 17:56:04 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Unlocks all Unown letters/forms in the wild.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void UnownUnlockAll() => UnownUnlocked = 0x0F; // all 4 bitflags
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-12-27 17:56:04 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Flag that determines if Unown Letters are available in the wild: A, B, C, D, E, F, G, H, I, J, K
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool UnownUnlocked0
|
|
|
|
|
{
|
|
|
|
|
get => (UnownUnlocked & 1 << 0) == 1 << 0;
|
|
|
|
|
set => UnownUnlocked |= 1 << 0;
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-12-27 17:56:04 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Flag that determines if Unown Letters are available in the wild: L, M, N, O, P, Q, R
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool UnownUnlocked1
|
|
|
|
|
{
|
|
|
|
|
get => (UnownUnlocked & 1 << 1) == 1 << 1;
|
|
|
|
|
set => UnownUnlocked |= 1 << 1;
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-12-27 17:56:04 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Flag that determines if Unown Letters are available in the wild: S, T, U, V, W
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool UnownUnlocked2
|
|
|
|
|
{
|
|
|
|
|
get => (UnownUnlocked & 1 << 2) == 1 << 2;
|
|
|
|
|
set => UnownUnlocked |= 1 << 2;
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-12-27 17:56:04 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Flag that determines if Unown Letters are available in the wild: X, Y, Z
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool UnownUnlocked3
|
|
|
|
|
{
|
|
|
|
|
get => (UnownUnlocked & 1 << 3) == 1 << 3;
|
|
|
|
|
set => UnownUnlocked |= 1 << 3;
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-12-27 17:56:04 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Chooses which Unown sprite to show in the regular Pokédex View
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int UnownFirstSeen
|
|
|
|
|
{
|
|
|
|
|
get => Data[Offsets.PokedexSeen + 0x1F + 28];
|
|
|
|
|
set => Data[Offsets.PokedexSeen + 0x1F + 28] = (byte)value;
|
2017-03-15 05:41:15 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-03-30 23:38:52 +00:00
|
|
|
|
public override bool GetSeen(int species) => GetDexFlag(Offsets.PokedexSeen, species);
|
|
|
|
|
public override bool GetCaught(int species) => GetDexFlag(Offsets.PokedexCaught, species);
|
|
|
|
|
public override void SetSeen(int species, bool seen) => SetDexFlag(Offsets.PokedexSeen, species, seen);
|
|
|
|
|
|
|
|
|
|
public override void SetCaught(int species, bool caught)
|
|
|
|
|
{
|
|
|
|
|
SetDexFlag(Offsets.PokedexCaught, species, caught);
|
2019-12-09 01:39:19 +00:00
|
|
|
|
if (caught && species == (int)Species.Unown)
|
2019-03-30 23:38:52 +00:00
|
|
|
|
SetUnownFormFlags();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool GetDexFlag(int region, int species)
|
2017-03-15 05:41:15 +00:00
|
|
|
|
{
|
|
|
|
|
int bit = species - 1;
|
|
|
|
|
int ofs = bit >> 3;
|
2019-03-30 23:38:52 +00:00
|
|
|
|
return GetFlag(region + ofs, bit & 7);
|
2017-03-15 05:41:15 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-03-30 23:38:52 +00:00
|
|
|
|
private void SetDexFlag(int region, int species, bool value)
|
2017-03-15 05:41:15 +00:00
|
|
|
|
{
|
|
|
|
|
int bit = species - 1;
|
|
|
|
|
int ofs = bit >> 3;
|
2019-03-30 23:38:52 +00:00
|
|
|
|
SetFlag(region + ofs, bit & 7, value);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
2017-04-09 21:06:50 +00:00
|
|
|
|
|
2019-03-06 07:06:05 +00:00
|
|
|
|
/// <summary>All Event Constant values for the save file</summary>
|
|
|
|
|
/// <remarks>These are all bytes</remarks>
|
|
|
|
|
public override ushort[] EventConsts
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
ushort[] Constants = new ushort[EventConstMax];
|
|
|
|
|
for (int i = 0; i < Constants.Length; i++)
|
|
|
|
|
Constants[i] = Data[EventConst + i];
|
|
|
|
|
return Constants;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value.Length != EventConstMax)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < value.Length; i++)
|
|
|
|
|
Data[EventConst + i] = Math.Min(byte.MaxValue, (byte)value[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-23 23:03:59 +00:00
|
|
|
|
// Misc
|
|
|
|
|
public ushort ResetKey => GetResetKey();
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-09-23 23:03:59 +00:00
|
|
|
|
private ushort GetResetKey()
|
|
|
|
|
{
|
2017-09-24 17:59:35 +00:00
|
|
|
|
var val = (TID >> 8) + (TID & 0xFF) + ((Money >> 16) & 0xFF) + ((Money >> 8) & 0xFF) + (Money & 0xFF);
|
2017-09-23 23:03:59 +00:00
|
|
|
|
var ot = Data.Skip(Offsets.Trainer1 + 2).TakeWhile((z, i) => i < 5 && z != 0x50);
|
|
|
|
|
var tr = ot.Sum(z => z);
|
|
|
|
|
return (ushort)(val + tr);
|
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-03-30 19:34:51 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the "Time Not Set" flag to the RTC Flag list.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void ResetRTC() => Data[Offsets.RTCFlags] |= 0x80;
|
|
|
|
|
|
2018-02-08 02:29:45 +00:00
|
|
|
|
public void UnlockAllDecorations()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 676; i <= 721; i++)
|
|
|
|
|
SetEventFlag(i, true);
|
|
|
|
|
}
|
2017-09-23 23:03:59 +00:00
|
|
|
|
|
2018-12-05 06:00:57 +00:00
|
|
|
|
public override string GetString(byte[] data, int offset, int length)
|
2017-09-11 02:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
if (Korean)
|
2019-03-21 04:50:44 +00:00
|
|
|
|
return StringConverter2KOR.GetString2KOR(data, offset, length);
|
|
|
|
|
return StringConverter12.GetString1(data, offset, length, Japanese);
|
2017-09-11 02:56:21 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-09-11 02:56:21 +00:00
|
|
|
|
public override byte[] SetString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
|
|
|
|
|
{
|
|
|
|
|
if (Korean)
|
2019-03-21 04:50:44 +00:00
|
|
|
|
return StringConverter2KOR.SetString2KOR(value, maxLength);
|
|
|
|
|
return StringConverter12.SetString1(value, maxLength, Japanese);
|
2017-09-11 02:56:21 +00:00
|
|
|
|
}
|
2019-06-09 21:15:42 +00:00
|
|
|
|
|
|
|
|
|
public bool IsGBMobileAvailable => Japanese && Version == GameVersion.C;
|
|
|
|
|
public bool IsGBMobileEnabled => Japanese && Enum.IsDefined(typeof(GBMobileCableColor), GBMobileCable);
|
|
|
|
|
|
|
|
|
|
public GBMobileCableColor GBMobileCable
|
|
|
|
|
{
|
|
|
|
|
get => (GBMobileCableColor) Data[0xE800];
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Data[0xE800] = (byte)value;
|
|
|
|
|
Data[0x9000] = (byte)(0xFF - value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum GBMobileCableColor : byte
|
|
|
|
|
{
|
|
|
|
|
None = 0,
|
|
|
|
|
Blue = 1,
|
|
|
|
|
Yellow = 2,
|
|
|
|
|
Green = 3,
|
|
|
|
|
Red = 4,
|
|
|
|
|
Debug = 0x81,
|
2016-09-02 21:20:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|