2022-06-18 18:04:24 +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-09-26 23:15:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Generation 3 <see cref="SaveFile"/> object for Pokémon XD saves.
|
|
|
|
/// </summary>
|
|
|
|
public sealed class SAV3XD : SaveFile, IGCSaveFile
|
2016-09-26 23:15:40 +00:00
|
|
|
{
|
2022-07-07 00:33:15 +00:00
|
|
|
protected internal override string ShortSummary => $"{OT} ({Version}) {PlayTimeString}";
|
2022-06-18 18:04:24 +00:00
|
|
|
public override string Extension => this.GCExtension();
|
|
|
|
public SAV3GCMemoryCard? MemoryCard { get; init; }
|
|
|
|
|
|
|
|
private const int SLOT_SIZE = 0x28000;
|
|
|
|
private const int SLOT_START = 0x6000;
|
|
|
|
private const int SLOT_COUNT = 2;
|
|
|
|
|
|
|
|
private int SaveCount = -1;
|
|
|
|
private int SaveIndex = -1;
|
2022-07-07 00:33:15 +00:00
|
|
|
private int Config;
|
2022-06-18 18:04:24 +00:00
|
|
|
private int Trainer1;
|
|
|
|
private int Memo;
|
|
|
|
private int Shadow;
|
|
|
|
private readonly StrategyMemo StrategyMemo;
|
|
|
|
private readonly ShadowInfoTableXD ShadowInfo;
|
|
|
|
public int MaxShadowID => ShadowInfo.Count;
|
|
|
|
private int OFS_PouchHeldItem, OFS_PouchKeyItem, OFS_PouchBalls, OFS_PouchTMHM, OFS_PouchBerry, OFS_PouchCologne, OFS_PouchDisc;
|
|
|
|
private readonly int[] subOffsets = new int[16];
|
|
|
|
private readonly byte[] BAK;
|
|
|
|
|
|
|
|
public SAV3XD() : base(SaveUtil.SIZE_G3XD)
|
2016-09-26 23:15:40 +00:00
|
|
|
{
|
2023-12-04 04:13:20 +00:00
|
|
|
BAK = [];
|
2022-06-18 18:04:24 +00:00
|
|
|
// create fake objects
|
|
|
|
StrategyMemo = new StrategyMemo();
|
|
|
|
ShadowInfo = new ShadowInfoTableXD(false);
|
2022-07-07 00:33:15 +00:00
|
|
|
Config = 0xA8;
|
|
|
|
Trainer1 = 0xCCD8;
|
|
|
|
Party = 0xCD08;
|
|
|
|
Box = 0x10E08;
|
|
|
|
DaycareOffset = 0x1CA68;
|
|
|
|
Memo = 0xF678;
|
|
|
|
Shadow = 0x1CB48;
|
2022-06-18 18:04:24 +00:00
|
|
|
Initialize();
|
|
|
|
ClearBoxes();
|
|
|
|
}
|
2016-09-26 23:15:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public SAV3XD(byte[] data) : base(data)
|
|
|
|
{
|
|
|
|
BAK = data;
|
2022-07-07 00:33:15 +00:00
|
|
|
Japanese = InitializeData(out StrategyMemo, out ShadowInfo);
|
2022-06-18 18:04:24 +00:00
|
|
|
Initialize();
|
|
|
|
}
|
2016-09-26 23:15:40 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public override PersonalTable3 Personal => PersonalTable.RS;
|
2023-04-16 19:58:07 +00:00
|
|
|
public override ReadOnlySpan<ushort> HeldItems => Legal.HeldItems_RS;
|
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
|
|
|
|
2022-07-07 00:33:15 +00:00
|
|
|
private readonly bool Japanese;
|
|
|
|
|
|
|
|
private bool InitializeData(out StrategyMemo memo, out ShadowInfoTableXD info)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
// Scan all 3 save slots for the highest counter
|
|
|
|
for (int i = 0; i < SLOT_COUNT; i++)
|
2019-06-09 02:56:11 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
int slotOffset = SLOT_START + (i * SLOT_SIZE);
|
|
|
|
int SaveCounter = ReadInt32BigEndian(Data.AsSpan(slotOffset + 4));
|
|
|
|
if (SaveCounter <= SaveCount)
|
|
|
|
continue;
|
2016-09-26 23:15:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
SaveCount = SaveCounter;
|
|
|
|
SaveIndex = i;
|
2019-06-09 02:56:11 +00:00
|
|
|
}
|
2016-09-27 06:07:17 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Decrypt most recent save slot
|
|
|
|
Data = ReadSlot(Data, SaveIndex);
|
2022-03-26 20:28:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Get Offset Info
|
|
|
|
Span<ushort> subLength = stackalloc ushort[16];
|
|
|
|
for (int i = 0; i < 16; i++)
|
2019-06-09 02:56:11 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
subLength[i] = ReadUInt16BigEndian(Data.AsSpan(0x20 + (2 * i)));
|
|
|
|
subOffsets[i] = ReadUInt16BigEndian(Data.AsSpan(0x40 + (4 * i))) | (ReadUInt16BigEndian(Data.AsSpan(0x40 + (4 * i) + 2)) << 16);
|
2016-09-26 23:15:40 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Offsets are displaced by the 0xA8 savedata region
|
2022-07-07 00:33:15 +00:00
|
|
|
Config = subOffsets[0] + 0xA8;
|
2022-06-18 18:04:24 +00:00
|
|
|
Trainer1 = subOffsets[1] + 0xA8;
|
|
|
|
Party = Trainer1 + 0x30;
|
|
|
|
Box = subOffsets[2] + 0xA8;
|
|
|
|
DaycareOffset = subOffsets[4] + 0xA8;
|
|
|
|
Memo = subOffsets[5] + 0xA8;
|
|
|
|
Shadow = subOffsets[7] + 0xA8;
|
|
|
|
// Purifier = subOffsets[14] + 0xA8;
|
|
|
|
|
|
|
|
bool jp = subLength[7] == 0x1E00;
|
2023-01-22 04:02:33 +00:00
|
|
|
memo = new StrategyMemo(Data.AsSpan(Memo, subLength[5]), xd: true);
|
2022-06-18 18:04:24 +00:00
|
|
|
info = new ShadowInfoTableXD(Data.AsSpan(Shadow, subLength[7]), jp);
|
2022-07-07 00:33:15 +00:00
|
|
|
return jp;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-03-08 02:05:55 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static byte[] ReadSlot(Span<byte> data, int index)
|
|
|
|
{
|
|
|
|
int slotOffset = SLOT_START + (index * SLOT_SIZE);
|
|
|
|
var slot = data.Slice(slotOffset, SLOT_SIZE);
|
|
|
|
var result = new byte[SLOT_SIZE];
|
|
|
|
var destSpan = result.AsSpan();
|
|
|
|
|
|
|
|
// Decrypt Slot
|
|
|
|
Span<ushort> keys = stackalloc ushort[4];
|
|
|
|
GeniusCrypto.ReadKeys(slot.Slice(8, keys.Length * 2), keys);
|
|
|
|
Range r = new(0x10, 0x27FD8);
|
|
|
|
GeniusCrypto.Decrypt(slot[r], destSpan[r], keys); // body
|
|
|
|
slot[..0x10].CopyTo(destSpan[..0x10]); // checksums
|
|
|
|
slot[^0x18..].CopyTo(destSpan[^0x18..]); // tail end
|
|
|
|
return result;
|
|
|
|
}
|
2019-03-08 02:05:55 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void Initialize()
|
|
|
|
{
|
|
|
|
OFS_PouchHeldItem = Trainer1 + 0x4C8;
|
|
|
|
OFS_PouchKeyItem = Trainer1 + 0x540;
|
|
|
|
OFS_PouchBalls = Trainer1 + 0x5EC;
|
|
|
|
OFS_PouchTMHM = Trainer1 + 0x62C;
|
|
|
|
OFS_PouchBerry = Trainer1 + 0x72C;
|
|
|
|
OFS_PouchCologne = Trainer1 + 0x7E4;
|
|
|
|
OFS_PouchDisc = Trainer1 + 0x7F0;
|
|
|
|
|
|
|
|
// Since PartyCount is not stored in the save file,
|
|
|
|
// Count up how many party slots are active.
|
|
|
|
for (int i = 0; i < 6; i++)
|
2016-09-26 23:15:40 +00:00
|
|
|
{
|
2023-03-26 06:14:50 +00:00
|
|
|
var ofs = GetPartyOffset(i);
|
|
|
|
var span = Data.AsSpan(ofs);
|
|
|
|
if (ReadUInt16BigEndian(span) != 0) // species is at offset 0x00
|
2022-06-18 18:04:24 +00:00
|
|
|
PartyCount++;
|
2016-09-26 23:15:40 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2016-09-26 23:15:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override byte[] GetFinalData()
|
|
|
|
{
|
|
|
|
var newFile = GetInnerData();
|
2016-09-26 23:15:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Return the gci if Memory Card is not being exported
|
|
|
|
if (MemoryCard is null)
|
|
|
|
return newFile;
|
2016-09-26 23:15:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
MemoryCard.WriteSaveGameData(newFile);
|
|
|
|
return MemoryCard.Data;
|
|
|
|
}
|
2017-12-28 00:36:24 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private byte[] GetInnerData()
|
|
|
|
{
|
|
|
|
// Set Memo Back
|
|
|
|
StrategyMemo.Write(); // .CopyTo(Data, Memo);
|
|
|
|
ShadowInfo.Write().CopyTo(Data, Shadow);
|
|
|
|
SetChecksums();
|
|
|
|
|
|
|
|
// Put save slot back in original save data
|
|
|
|
var destOffset = SLOT_START + (SaveIndex * SLOT_SIZE);
|
2023-01-22 04:02:33 +00:00
|
|
|
byte[] dest = MemoryCard != null ? MemoryCard.ReadSaveGameData().ToArray() : (byte[])BAK.Clone();
|
2022-06-18 18:04:24 +00:00
|
|
|
var destSpan = dest.AsSpan(destOffset, Data.Length);
|
|
|
|
|
|
|
|
// Get updated save slot data
|
|
|
|
Span<byte> slot = Data;
|
|
|
|
Span<ushort> keys = stackalloc ushort[4];
|
|
|
|
GeniusCrypto.ReadKeys(slot.Slice(8, keys.Length * 2), keys);
|
|
|
|
Range r = new(0x10, 0x27FD8);
|
|
|
|
GeniusCrypto.Encrypt(slot[r], destSpan[r], keys);
|
|
|
|
slot[..0x10].CopyTo(destSpan[..0x10]); // checksum/keys
|
|
|
|
slot[^0x18..].CopyTo(destSpan[^0x18..]); // tail end
|
|
|
|
return dest;
|
|
|
|
}
|
2016-09-26 23:15:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Configuration
|
2023-01-22 04:02:33 +00:00
|
|
|
protected override SAV3XD CloneInternal() => new(GetInnerData()) { MemoryCard = MemoryCard };
|
2016-09-26 23:15:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override int SIZE_STORED => PokeCrypto.SIZE_3XSTORED;
|
|
|
|
protected override int SIZE_PARTY => PokeCrypto.SIZE_3XSTORED; // unused
|
2023-01-22 04:02:33 +00:00
|
|
|
public override XK3 BlankPKM => new();
|
2022-06-18 18:04:24 +00:00
|
|
|
public override Type PKMType => typeof(XK3);
|
2018-03-18 23:22:21 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
public override ushort MaxMoveID => Legal.MaxMoveID_3;
|
|
|
|
public override ushort MaxSpeciesID => Legal.MaxSpeciesID_3;
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int MaxAbilityID => Legal.MaxAbilityID_3;
|
|
|
|
public override int MaxBallID => Legal.MaxBallID_3;
|
|
|
|
public override int MaxItemID => Legal.MaxItemID_3_XD;
|
|
|
|
public override int MaxGameID => Legal.MaxGameID_3;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2023-09-28 05:15:59 +00:00
|
|
|
public override int MaxEV => EffortValues.Max255;
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int Generation => 3;
|
|
|
|
public override EntityContext Context => EntityContext.Gen3;
|
|
|
|
protected override int GiftCountMax => 1;
|
2022-11-25 01:42:17 +00:00
|
|
|
public override int MaxStringLengthOT => 7;
|
|
|
|
public override int MaxStringLengthNickname => 10;
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int MaxMoney => 9999999;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int BoxCount => 8;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override bool IsPKMPresent(ReadOnlySpan<byte> data) => EntityDetection.IsPresentGC(data);
|
|
|
|
|
|
|
|
// Checksums
|
|
|
|
protected override void SetChecksums()
|
|
|
|
{
|
|
|
|
Data = SetChecksums(Data, subOffsets[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool ChecksumsValid => !ChecksumInfo.Contains("Invalid");
|
|
|
|
|
|
|
|
public override string ChecksumInfo
|
|
|
|
{
|
|
|
|
get
|
2016-09-29 01:32:20 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
byte[] data = SetChecksums(Data, subOffsets[0]);
|
2016-09-29 01:32:20 +00:00
|
|
|
|
|
|
|
const int start = 0xA8; // 0x88 + 0x20
|
2022-06-18 18:04:24 +00:00
|
|
|
int oldHC = ReadInt32BigEndian(Data.AsSpan(start + subOffsets[0] + 0x38));
|
|
|
|
int newHC = ReadInt32BigEndian(data.AsSpan(start + subOffsets[0] + 0x38));
|
|
|
|
bool header = newHC == oldHC;
|
|
|
|
|
|
|
|
var oldCHK = Data.AsSpan(0x10, 0x10);
|
|
|
|
var newCHK = data.AsSpan(0x10, 0x10);
|
|
|
|
bool body = newCHK.SequenceEqual(oldCHK);
|
|
|
|
return $"Header Checksum {(header ? "V" : "Inv")}alid, Body Checksum {(body ? "V" : "Inv")}alid.";
|
|
|
|
}
|
|
|
|
}
|
2016-09-26 23:15:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static byte[] SetChecksums(byte[] input, int subOffset0)
|
|
|
|
{
|
2023-12-09 23:21:10 +00:00
|
|
|
ArgumentOutOfRangeException.ThrowIfNotEqual(input.Length, SLOT_SIZE);
|
2016-09-29 01:32:20 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
byte[] data = (byte[])input.Clone();
|
|
|
|
const int start = 0xA8; // 0x88 + 0x20
|
2016-09-29 01:32:20 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Header Checksum
|
|
|
|
int newHC = 0;
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
newHC += data[i];
|
2016-09-29 01:32:20 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
WriteInt32BigEndian(data.AsSpan(start + subOffset0 + 0x38), newHC);
|
2016-09-29 01:32:20 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Body Checksum
|
|
|
|
data.AsSpan(0x10, 0x10).Clear(); // Clear old Checksum Data
|
|
|
|
Span<uint> checksum = stackalloc uint[4];
|
|
|
|
int dt = 8;
|
|
|
|
for (int i = 0; i < checksum.Length; i++)
|
2016-09-26 23:15:40 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
uint val = 0;
|
|
|
|
var end = dt + 0x9FF4;
|
|
|
|
for (int j = dt; j < end; j += 2)
|
|
|
|
val += ReadUInt16BigEndian(data.AsSpan(j));
|
|
|
|
dt = end;
|
|
|
|
checksum[i] = val;
|
2016-09-26 23:15:40 +00:00
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
Span<ushort> newchks = stackalloc ushort[8];
|
|
|
|
for (int i = 0; i < 4; i++)
|
2016-09-26 23:15:40 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
newchks[i*2] = (ushort)(checksum[i] >> 16);
|
|
|
|
newchks[(i * 2) + 1] = (ushort)checksum[i];
|
2016-09-26 23:15:40 +00:00
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
for (int i = 0; i < newchks.Length; i++)
|
2016-10-01 23:52:29 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var dest = data.AsSpan(0x10 + (2 * i));
|
|
|
|
var chk = newchks[newchks.Length - 1 - i];
|
|
|
|
WriteUInt16BigEndian(dest, chk);
|
2016-10-01 23:52:29 +00:00
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
return data;
|
|
|
|
}
|
2022-07-07 00:33:15 +00:00
|
|
|
|
|
|
|
// Config
|
|
|
|
public GCVersion GCGameIndex { get => (GCVersion)Data[Config + 0x00]; set => Data[Config + 0x00] = (byte)value; }
|
|
|
|
public GCRegion CurrentRegion { get => (GCRegion)Data[Config + 0x01]; set => Data[Config + 0x01] = (byte)value; }
|
|
|
|
public GCRegion OriginalRegion { get => (GCRegion)Data[Config + 0x02]; set => Data[Config + 0x02] = (byte)value; }
|
|
|
|
public LanguageGC GCLanguage { get => (LanguageGC)Data[Config + 0x03]; set => Data[Config + 0x03] = (byte)value; }
|
|
|
|
public override int Language { get => (int)GCLanguage.ToLanguageID(); set => GCLanguage = ((LanguageID)value).ToLanguageGC(); }
|
|
|
|
|
|
|
|
private TimeSpan PlayedSpan
|
|
|
|
{
|
|
|
|
get => TimeSpan.FromSeconds(TotalSeconds);
|
|
|
|
set => TotalSeconds = value.TotalSeconds;
|
|
|
|
}
|
|
|
|
|
|
|
|
private double TotalSeconds
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (Japanese)
|
|
|
|
return ReadSingleBigEndian(Data.AsSpan(Config + 0x20));
|
|
|
|
return ReadDoubleBigEndian(Data.AsSpan(Config + 0x30));
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (Japanese)
|
|
|
|
WriteSingleBigEndian(Data.AsSpan(Config + 0x20), (float)value);
|
|
|
|
else
|
|
|
|
WriteDoubleBigEndian(Data.AsSpan(Config + 0x30), value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override int PlayedHours
|
|
|
|
{
|
2022-09-07 21:39:58 +00:00
|
|
|
get => (ushort)PlayedSpan.TotalHours;
|
|
|
|
set { var time = PlayedSpan; PlayedSpan = time - TimeSpan.FromHours(time.TotalHours) + TimeSpan.FromHours(value); }
|
2022-07-07 00:33:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override int PlayedMinutes
|
|
|
|
{
|
|
|
|
get => (byte)PlayedSpan.Minutes;
|
|
|
|
set { var time = PlayedSpan; PlayedSpan = time - TimeSpan.FromMinutes(time.Minutes) + TimeSpan.FromMinutes(value); }
|
|
|
|
}
|
|
|
|
|
|
|
|
public override int PlayedSeconds
|
|
|
|
{
|
|
|
|
get => (byte)PlayedSpan.Seconds;
|
|
|
|
set { var time = PlayedSpan; PlayedSpan = time - TimeSpan.FromSeconds(time.Seconds) + TimeSpan.FromSeconds(value); }
|
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Trainer Info
|
|
|
|
public override GameVersion Version { get => GameVersion.XD; protected set { } }
|
2023-03-26 06:14:50 +00:00
|
|
|
public override string OT { get => GetString(Data.AsSpan(Trainer1 + 0x00, 20)); set => SetString(Data.AsSpan(Trainer1 + 0x00, 20), value, 10, StringConverterOption.ClearZero); }
|
2023-01-22 04:02:33 +00:00
|
|
|
public override uint ID32 { get => ReadUInt32BigEndian(Data.AsSpan(Trainer1 + 0x2C)); set => WriteUInt32BigEndian(Data.AsSpan(Trainer1 + 0x2C), value); }
|
|
|
|
public override ushort SID16 { get => ReadUInt16BigEndian(Data.AsSpan(Trainer1 + 0x2C)); set => WriteUInt16BigEndian(Data.AsSpan(Trainer1 + 0x2C), value); }
|
|
|
|
public override ushort TID16 { get => ReadUInt16BigEndian(Data.AsSpan(Trainer1 + 0x2E)); set => WriteUInt16BigEndian(Data.AsSpan(Trainer1 + 0x2E), value); }
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
public override int Gender { get => Data[Trainer1 + 0x8E0]; set => Data[Trainer1 + 0x8E0] = (byte)value; }
|
|
|
|
public override uint Money { get => ReadUInt32BigEndian(Data.AsSpan(Trainer1 + 0x8E4)); set => WriteUInt32BigEndian(Data.AsSpan(Trainer1 + 0x8E4), value); }
|
|
|
|
public uint Coupons { get => ReadUInt32BigEndian(Data.AsSpan(Trainer1 + 0x8E8)); set => WriteUInt32BigEndian(Data.AsSpan(Trainer1 + 0x8E8), value); }
|
|
|
|
|
|
|
|
// Storage
|
|
|
|
public override int GetPartyOffset(int slot) => Party + (SIZE_STORED * slot);
|
|
|
|
private int GetBoxInfoOffset(int box) => Box + (((30 * SIZE_STORED) + 0x14) * box);
|
|
|
|
public override int GetBoxOffset(int box) => GetBoxInfoOffset(box) + 20;
|
2023-03-26 06:14:50 +00:00
|
|
|
public override string GetBoxName(int box) => GetString(Data.AsSpan(GetBoxInfoOffset(box), 16));
|
2022-06-18 18:04:24 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public override void SetBoxName(int box, ReadOnlySpan<char> value)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
SetString(Data.AsSpan(GetBoxInfoOffset(box), 20), value, 8, StringConverterOption.ClearZero);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
protected override XK3 GetPKM(byte[] data)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
if (data.Length != SIZE_STORED)
|
|
|
|
Array.Resize(ref data, SIZE_STORED);
|
2023-01-22 04:02:33 +00:00
|
|
|
return new(data);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2016-12-27 05:26:45 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override byte[] DecryptPKM(byte[] data) => data;
|
2023-03-26 06:14:50 +00:00
|
|
|
public override XK3 GetPartySlot(ReadOnlySpan<byte> data) => GetStoredSlot(data);
|
2016-10-01 23:52:29 +00:00
|
|
|
|
2023-03-26 06:14:50 +00:00
|
|
|
public override XK3 GetStoredSlot(ReadOnlySpan<byte> data)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
// Get Shadow Data
|
2023-03-26 06:14:50 +00:00
|
|
|
var pk = (XK3)base.GetStoredSlot(data);
|
2023-05-02 00:09:45 +00:00
|
|
|
|
|
|
|
// Get Shadow Data from save
|
|
|
|
var id = pk.ShadowID;
|
|
|
|
if (id == 0 || id >= ShadowInfo.Count)
|
|
|
|
return pk;
|
|
|
|
|
|
|
|
var entry = ShadowInfo[pk.ShadowID];
|
|
|
|
pk.Purification = entry.Purification;
|
|
|
|
pk.IsShadow = !entry.IsPurified;
|
2022-06-18 18:04:24 +00:00
|
|
|
return pk;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void SetPKM(PKM pk, bool isParty = false)
|
|
|
|
{
|
|
|
|
if (pk is not XK3 xk3)
|
|
|
|
return; // shouldn't ever hit
|
|
|
|
|
2022-07-07 00:33:15 +00:00
|
|
|
xk3.CurrentRegion = (byte)CurrentRegion;
|
|
|
|
xk3.OriginalRegion = (byte)OriginalRegion;
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
// Set Shadow Data back to save
|
2023-05-02 00:09:45 +00:00
|
|
|
var id = xk3.ShadowID;
|
|
|
|
if (id == 0 || id >= ShadowInfo.Count)
|
2022-06-18 18:04:24 +00:00
|
|
|
return;
|
|
|
|
|
2023-05-02 00:09:45 +00:00
|
|
|
var entry = ShadowInfo[id];
|
2022-06-18 18:04:24 +00:00
|
|
|
entry.Purification = xk3.Purification;
|
2023-05-02 00:09:45 +00:00
|
|
|
//entry.IsPurified = !xk3.IsShadow;
|
|
|
|
//entry.Species = xk3.Species;
|
2022-06-18 18:04:24 +00:00
|
|
|
entry.PID = xk3.PID;
|
|
|
|
entry.IV_HP = xk3.IV_HP ;
|
|
|
|
entry.IV_ATK = xk3.IV_ATK;
|
|
|
|
entry.IV_DEF = xk3.IV_DEF;
|
|
|
|
entry.IV_SPA = xk3.IV_SPA;
|
|
|
|
entry.IV_SPD = xk3.IV_SPD;
|
|
|
|
entry.IV_SPE = xk3.IV_SPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void SetDex(PKM pk)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
if (pk.Species is 0 or > Legal.MaxSpeciesID_3)
|
|
|
|
return;
|
|
|
|
if (pk.IsEgg)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Dex Related
|
|
|
|
var entry = StrategyMemo.GetEntry(pk.Species);
|
|
|
|
if (entry.IsEmpty) // Populate
|
|
|
|
{
|
2016-10-01 23:52:29 +00:00
|
|
|
entry.Species = pk.Species;
|
|
|
|
entry.PID = pk.PID;
|
2023-01-22 04:02:33 +00:00
|
|
|
entry.TID16 = pk.TID16;
|
|
|
|
entry.SID16 = pk.SID16;
|
2016-10-01 23:52:29 +00:00
|
|
|
}
|
2023-01-22 04:02:33 +00:00
|
|
|
if (entry.Matches(pk.Species, pk.PID, pk.TID16, pk.SID16))
|
2016-10-01 02:05:35 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
entry.Seen = true;
|
|
|
|
entry.Owned = true;
|
2016-10-01 02:05:35 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
StrategyMemo.SetEntry(entry);
|
|
|
|
*/
|
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override IReadOnlyList<InventoryPouch> Inventory
|
|
|
|
{
|
|
|
|
get
|
2016-09-26 23:15:40 +00:00
|
|
|
{
|
2023-04-16 19:58:07 +00:00
|
|
|
var info = ItemStorage3XD.Instance;
|
2022-06-18 18:04:24 +00:00
|
|
|
InventoryPouch[] pouch =
|
2023-12-04 04:13:20 +00:00
|
|
|
[
|
2023-04-16 19:58:07 +00:00
|
|
|
new InventoryPouch3GC(InventoryType.Items, info, 999, OFS_PouchHeldItem, 30), // 20 COLO, 30 XD
|
|
|
|
new InventoryPouch3GC(InventoryType.KeyItems, info, 1, OFS_PouchKeyItem, 43),
|
|
|
|
new InventoryPouch3GC(InventoryType.Balls, info, 999, OFS_PouchBalls, 16),
|
|
|
|
new InventoryPouch3GC(InventoryType.TMHMs, info, 999, OFS_PouchTMHM, 64),
|
|
|
|
new InventoryPouch3GC(InventoryType.Berries, info, 999, OFS_PouchBerry, 46),
|
|
|
|
new InventoryPouch3GC(InventoryType.Medicine, info, 999, OFS_PouchCologne, 3), // Cologne
|
|
|
|
new InventoryPouch3GC(InventoryType.BattleItems, info, 1, OFS_PouchDisc, 60),
|
2023-12-04 04:13:20 +00:00
|
|
|
];
|
2022-06-18 18:04:24 +00:00
|
|
|
return pouch.LoadAll(Data);
|
2016-09-26 23:15:40 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
set => value.SaveAll(Data);
|
|
|
|
}
|
2016-09-27 06:07:17 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Daycare Structure:
|
|
|
|
// 0x00 -- Occupied
|
|
|
|
// 0x01 -- Deposited Level
|
|
|
|
// 0x02-0x03 -- unused?
|
|
|
|
// 0x04-0x07 -- Initial EXP
|
|
|
|
public override int GetDaycareSlotOffset(int loc, int slot) { return DaycareOffset + 8; }
|
|
|
|
public override uint? GetDaycareEXP(int loc, int slot) { return null; }
|
|
|
|
public override bool? IsDaycareOccupied(int loc, int slot) { return null; }
|
|
|
|
public override void SetDaycareEXP(int loc, int slot, uint EXP) { /* todo */ }
|
|
|
|
public override void SetDaycareOccupied(int loc, int slot, bool occupied) { /* todo */ }
|
2017-06-18 01:37:19 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override string GetString(ReadOnlySpan<byte> data) => StringConverter3GC.GetString(data);
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int SetString(Span<byte> destBuffer, ReadOnlySpan<char> value, int maxLength, StringConverterOption option)
|
|
|
|
{
|
|
|
|
return StringConverter3GC.SetString(destBuffer, value, maxLength, option);
|
2022-01-03 05:35:59 +00:00
|
|
|
}
|
2016-09-26 23:15:40 +00:00
|
|
|
}
|