2022-07-07 00:33:15 +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-26 23:15:40 +00:00
|
|
|
using System.Security.Cryptography;
|
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 Colosseum saves.
|
|
|
|
/// </summary>
|
|
|
|
public sealed class SAV3Colosseum : SaveFile, IGCSaveFile
|
2016-09-26 23:15:40 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
protected internal override string ShortSummary => $"{OT} ({Version}) - {PlayTimeString}";
|
|
|
|
public override string Extension => this.GCExtension();
|
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;
|
2022-06-18 18:04:24 +00:00
|
|
|
public SAV3GCMemoryCard? MemoryCard { get; init; }
|
|
|
|
|
|
|
|
// 3 Save files are stored
|
|
|
|
// 0x0000-0x6000 contains memory card data
|
|
|
|
// 0x6000-0x60000 contains the 3 save slots
|
|
|
|
// 0x5A000 / 3 = 0x1E000 per save slot
|
|
|
|
// Checksum is SHA1 over 0-0x1DFD7, stored in the last 20 bytes of the save slot.
|
|
|
|
// Another SHA1 hash is 0x1DFD8, for 20 bytes. Unknown purpose.
|
|
|
|
// Checksum is used as the crypto key.
|
|
|
|
|
|
|
|
private const int SLOT_SIZE = 0x1E000;
|
|
|
|
private const int SLOT_START = 0x6000;
|
|
|
|
private const int SLOT_COUNT = 3;
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
private const int sha1HashSize = 20;
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private int SaveCount = -1;
|
|
|
|
private int SaveIndex = -1;
|
|
|
|
private readonly StrategyMemo StrategyMemo;
|
|
|
|
public const int MaxShadowID = 0x80; // 128
|
|
|
|
private int Memo;
|
|
|
|
|
|
|
|
private readonly byte[] BAK;
|
|
|
|
|
|
|
|
public SAV3Colosseum() : base(SaveUtil.SIZE_G3COLO)
|
2016-09-26 23:15:40 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
BAK = Array.Empty<byte>();
|
|
|
|
StrategyMemo = Initialize();
|
|
|
|
ClearBoxes();
|
|
|
|
}
|
2016-09-26 23:15:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public SAV3Colosseum(byte[] data) : base(data)
|
|
|
|
{
|
|
|
|
BAK = data;
|
|
|
|
InitializeData();
|
|
|
|
StrategyMemo = Initialize();
|
|
|
|
}
|
2016-09-26 23:15:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private StrategyMemo Initialize()
|
|
|
|
{
|
|
|
|
// Trainer1 = 0x00078;
|
|
|
|
Party = 0x000A8;
|
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-06-18 18:04:24 +00:00
|
|
|
Box = 0x00B90;
|
|
|
|
DaycareOffset = 0x08170;
|
|
|
|
Memo = 0x082B0;
|
2016-09-26 23:15:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Since PartyCount is not stored in the save file,
|
|
|
|
// Count up how many party slots are active.
|
|
|
|
for (int i = 0; i < 6; i++)
|
2019-01-05 23:37:06 +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++;
|
2019-01-05 23:37:06 +00:00
|
|
|
}
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
var memo = new StrategyMemo(Data.AsSpan(Memo), xd: false);
|
2022-06-18 18:04:24 +00:00
|
|
|
return memo;
|
|
|
|
}
|
2019-03-08 02:05:55 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void InitializeData()
|
|
|
|
{
|
|
|
|
// Scan all 3 save slots for the highest counter
|
|
|
|
for (int i = 0; i < SLOT_COUNT; i++)
|
|
|
|
{
|
|
|
|
int slotOffset = SLOT_START + (i * SLOT_SIZE);
|
|
|
|
int SaveCounter = ReadInt32BigEndian(Data.AsSpan(slotOffset + 4));
|
|
|
|
if (SaveCounter <= SaveCount)
|
|
|
|
continue;
|
2019-03-08 02:05:55 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
SaveCount = SaveCounter;
|
|
|
|
SaveIndex = i;
|
2019-03-08 02:05:55 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Decrypt most recent save slot
|
2016-09-26 23:15:40 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
int slotOffset = SLOT_START + (SaveIndex * SLOT_SIZE);
|
|
|
|
ReadOnlySpan<byte> slot = Data.AsSpan(slotOffset, SLOT_SIZE);
|
2023-01-22 04:02:33 +00:00
|
|
|
Span<byte> digest = stackalloc byte[sha1HashSize];
|
|
|
|
slot[^sha1HashSize..].CopyTo(digest);
|
2016-09-26 23:15:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Decrypt Slot
|
|
|
|
Data = DecryptColosseum(slot, digest);
|
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;
|
|
|
|
}
|
2016-09-26 23:15:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private byte[] GetInnerData()
|
|
|
|
{
|
|
|
|
StrategyMemo.Write().CopyTo(Data, Memo);
|
|
|
|
SetChecksums();
|
|
|
|
|
|
|
|
// Get updated save slot data
|
|
|
|
ReadOnlySpan<byte> slot = Data;
|
2023-01-22 04:02:33 +00:00
|
|
|
Span<byte> digest = stackalloc byte[sha1HashSize];
|
|
|
|
slot[^sha1HashSize..].CopyTo(digest);
|
2022-06-18 18:04:24 +00:00
|
|
|
byte[] newSAV = EncryptColosseum(slot, digest);
|
|
|
|
|
|
|
|
// Put save slot back in original save data
|
2023-01-22 04:02:33 +00:00
|
|
|
byte[] newFile = MemoryCard != null ? MemoryCard.ReadSaveGameData().ToArray() : (byte[])BAK.Clone();
|
2022-06-18 18:04:24 +00:00
|
|
|
Array.Copy(newSAV, 0, newFile, SLOT_START + (SaveIndex * SLOT_SIZE), newSAV.Length);
|
|
|
|
return newFile;
|
|
|
|
}
|
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 SAV3Colosseum CloneInternal() => new(GetInnerData()) { MemoryCard = MemoryCard };
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
protected override int SIZE_STORED => PokeCrypto.SIZE_3CSTORED;
|
|
|
|
protected override int SIZE_PARTY => PokeCrypto.SIZE_3CSTORED; // unused
|
2023-01-22 04:02:33 +00:00
|
|
|
public override CK3 BlankPKM => new();
|
2022-06-18 18:04:24 +00:00
|
|
|
public override Type PKMType => typeof(CK3);
|
|
|
|
|
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_COLO;
|
|
|
|
public override int MaxGameID => Legal.MaxGameID_3;
|
|
|
|
|
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 => 10; // as evident by Mattle Ho-Oh
|
|
|
|
public override int MaxStringLengthNickname => 10;
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int MaxMoney => 9999999;
|
|
|
|
|
|
|
|
public override int BoxCount => 3;
|
|
|
|
public override bool IsPKMPresent(ReadOnlySpan<byte> data) => EntityDetection.IsPresentGC(data);
|
|
|
|
|
|
|
|
private static byte[] EncryptColosseum(ReadOnlySpan<byte> input, Span<byte> digest)
|
|
|
|
{
|
|
|
|
if (input.Length != SLOT_SIZE)
|
2023-01-22 04:02:33 +00:00
|
|
|
throw new ArgumentException("Incorrect slot size", nameof(input));
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
byte[] output = input.ToArray();
|
|
|
|
|
|
|
|
// NOT key
|
2023-01-22 04:02:33 +00:00
|
|
|
for (int i = 0; i < digest.Length; i++)
|
2022-06-18 18:04:24 +00:00
|
|
|
digest[i] = (byte)~digest[i];
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2023-02-26 23:18:32 +00:00
|
|
|
const int start = 0x18;
|
|
|
|
const int end = (SLOT_SIZE - (2 * sha1HashSize));
|
|
|
|
var crypt = output.AsSpan();
|
|
|
|
for (int i = start; i < end; i += sha1HashSize)
|
2016-09-26 23:15:40 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
var slice = crypt.Slice(i, digest.Length);
|
|
|
|
for (int j = 0; j < digest.Length; j++)
|
|
|
|
slice[j] ^= digest[j];
|
|
|
|
SHA1.HashData(slice, digest); // update digest
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
2016-09-26 23:15:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static byte[] DecryptColosseum(ReadOnlySpan<byte> input, Span<byte> digest)
|
|
|
|
{
|
|
|
|
if (input.Length != SLOT_SIZE)
|
2023-01-22 04:02:33 +00:00
|
|
|
throw new ArgumentException("Incorrect slot size", nameof(input));
|
2016-09-26 23:15:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
byte[] output = input.ToArray();
|
2016-09-26 23:15:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// NOT key
|
2023-01-22 04:02:33 +00:00
|
|
|
for (int i = 0; i < digest.Length; i++)
|
2022-06-18 18:04:24 +00:00
|
|
|
digest[i] = (byte)~digest[i];
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
Span<byte> hash = stackalloc byte[sha1HashSize];
|
2023-02-26 23:18:32 +00:00
|
|
|
const int start = 0x18;
|
|
|
|
const int end = (SLOT_SIZE - (2 * sha1HashSize));
|
|
|
|
var crypt = output.AsSpan();
|
|
|
|
for (int i = start; i < end; i += sha1HashSize)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-02-26 23:18:32 +00:00
|
|
|
var slice = crypt.Slice(i, Math.Min(crypt.Length - i, sha1HashSize));
|
2023-01-22 04:02:33 +00:00
|
|
|
SHA1.HashData(slice, hash); // update digest
|
2023-02-26 23:18:32 +00:00
|
|
|
for (int j = 0; j < slice.Length; j++)
|
2023-01-22 04:02:33 +00:00
|
|
|
slice[j] ^= digest[j];
|
|
|
|
hash.CopyTo(digest); // for use in next loop
|
2016-09-26 23:15:40 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void SetChecksums()
|
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
var data = Data.AsSpan();
|
|
|
|
var header = data[..0x20];
|
|
|
|
var payload = data[..(SLOT_SIZE - (2 * sha1HashSize))];
|
|
|
|
var hash = data[^sha1HashSize..];
|
|
|
|
var headerCHK = data[0x0C..];
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Clear Header Checksum
|
|
|
|
WriteInt32BigEndian(headerCHK, 0);
|
|
|
|
// Compute checksum of data
|
2023-01-22 04:02:33 +00:00
|
|
|
SHA1.HashData(payload, hash);
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
// Compute new header checksum
|
2023-01-22 04:02:33 +00:00
|
|
|
int newHC = ComputeHeaderChecksum(header, hash);
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
// Set Header Checksum
|
|
|
|
WriteInt32BigEndian(headerCHK, newHC);
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
private static int ComputeHeaderChecksum(Span<byte> header, Span<byte> hash)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
for (int i = 0; i < 0x18; i += 4)
|
|
|
|
result -= ReadInt32BigEndian(header[i..]);
|
|
|
|
result -= ReadInt32BigEndian(header[0x18..]) ^ ~ReadInt32BigEndian(hash);
|
|
|
|
result -= ReadInt32BigEndian(header[0x1C..]) ^ ~ReadInt32BigEndian(hash[4..]);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override bool ChecksumsValid => !ChecksumInfo.Contains("Invalid");
|
|
|
|
|
|
|
|
public override string ChecksumInfo
|
|
|
|
{
|
|
|
|
get
|
2016-09-26 23:15:40 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
var data = Data.AsSpan();
|
|
|
|
var header = data[..0x20];
|
|
|
|
var payload = data[..(SLOT_SIZE - (2 * sha1HashSize))];
|
|
|
|
var storedHash = data[^sha1HashSize..];
|
|
|
|
var hc = header[0x0C..];
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
int oldHC = ReadInt32BigEndian(hc);
|
2016-09-26 23:15:40 +00:00
|
|
|
// Clear Header Checksum
|
2023-01-22 04:02:33 +00:00
|
|
|
WriteInt32BigEndian(hc, 0);
|
|
|
|
Span<byte> currentHash = stackalloc byte[sha1HashSize];
|
|
|
|
SHA1.HashData(payload, currentHash);
|
2016-09-26 23:15:40 +00:00
|
|
|
|
|
|
|
// Compute new header checksum
|
2023-01-22 04:02:33 +00:00
|
|
|
int newHC = ComputeHeaderChecksum(header, currentHash);
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
// Restore old header checksum
|
|
|
|
WriteInt32BigEndian(hc, oldHC);
|
2022-06-18 18:04:24 +00:00
|
|
|
bool isHeaderValid = newHC == oldHC;
|
2023-01-22 04:02:33 +00:00
|
|
|
bool isBodyValid = storedHash.SequenceEqual(currentHash);
|
2022-06-18 18:04:24 +00:00
|
|
|
static string valid(bool s) => s ? "Valid" : "Invalid";
|
|
|
|
return $"Header Checksum {valid(isHeaderValid)}, Body Checksum {valid(isBodyValid)}.";
|
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
|
|
|
// Trainer Info
|
|
|
|
public override GameVersion Version { get => GameVersion.COLO; protected set { } }
|
2016-09-26 23:15:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Storage
|
|
|
|
public override int GetPartyOffset(int slot)
|
|
|
|
{
|
|
|
|
return Party + (SIZE_STORED * slot);
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int GetBoxOffset(int box)
|
|
|
|
{
|
|
|
|
return Box + (((30 * SIZE_STORED) + 0x14)*box) + 0x14;
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2023-03-26 06:14:50 +00:00
|
|
|
private Span<byte> GetBoxNameSpan(int box) => Data.AsSpan(Box + (0x24A4 * box), 16);
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override string GetBoxName(int box)
|
|
|
|
{
|
2023-03-26 06:14:50 +00:00
|
|
|
return GetString(GetBoxNameSpan(box));
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-09-15 05:37:47 +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-03-26 06:14:50 +00:00
|
|
|
SetString(GetBoxNameSpan(box), value, 8, StringConverterOption.ClearZero);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
protected override CK3 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
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override byte[] DecryptPKM(byte[] data) => data;
|
2016-09-26 23:15:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override void SetPKM(PKM pk, bool isParty = false)
|
|
|
|
{
|
|
|
|
if (pk is not CK3 ck3)
|
|
|
|
return;
|
2016-12-27 05:26:45 +00:00
|
|
|
|
2022-07-07 00:33:15 +00:00
|
|
|
ck3.CurrentRegion = (byte)CurrentRegion;
|
|
|
|
ck3.OriginalRegion = (byte)OriginalRegion;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
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 02:05:35 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
entry.Species = pk.Species;
|
|
|
|
entry.PID = pk.PID;
|
2023-01-22 04:02:33 +00:00
|
|
|
entry.ID32 = pk.ID32;
|
2016-10-01 02:05:35 +00:00
|
|
|
}
|
2023-01-22 04:02:33 +00:00
|
|
|
if (entry.Matches(pk.Species, pk.PID, pk.ID32))
|
2016-09-26 23:15:40 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
entry.Seen = true;
|
|
|
|
entry.Owned = true;
|
2016-09-26 23:15:40 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
StrategyMemo.SetEntry(entry);
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-07-07 00:33:15 +00:00
|
|
|
// Config
|
|
|
|
private const int Config = 0x08;
|
|
|
|
|
|
|
|
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(); }
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private TimeSpan PlayedSpan
|
|
|
|
{
|
2022-07-07 00:33:15 +00:00
|
|
|
get => TimeSpan.FromSeconds(ReadSingleBigEndian(Data.AsSpan(Config + 0x20)));
|
|
|
|
set => WriteSingleBigEndian(Data.AsSpan(Config + 0x20), (float)value.TotalSeconds);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int PlayedHours
|
|
|
|
{
|
2022-09-07 21:39:58 +00:00
|
|
|
get => (ushort)PlayedSpan.TotalHours;
|
|
|
|
set { var time = PlayedSpan; PlayedSpan = time - TimeSpan.FromHours((int)time.TotalHours) + TimeSpan.FromHours(value); }
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +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); }
|
|
|
|
}
|
2016-09-26 23:15:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Trainer Info (offset 0x78, length 0xB18, end @ 0xB90)
|
2023-03-26 06:14:50 +00:00
|
|
|
public override string OT { get => GetString(Data.AsSpan(0x78, 20)); set { SetString(Data.AsSpan(0x78, 20), value, 10, StringConverterOption.ClearZero); OT2 = value; } }
|
|
|
|
public string OT2 { get => GetString(Data.AsSpan(0x8C, 20)); set => SetString(Data.AsSpan(0x8C, 20), value, 10, StringConverterOption.ClearZero); }
|
2023-01-22 04:02:33 +00:00
|
|
|
|
|
|
|
public override uint ID32 { get => ReadUInt32BigEndian(Data.AsSpan(0xA4)); set => WriteUInt32BigEndian(Data.AsSpan(0xA4), value); }
|
|
|
|
public override ushort SID16 { get => ReadUInt16BigEndian(Data.AsSpan(0xA4)); set => WriteUInt16BigEndian(Data.AsSpan(0xA4), value); }
|
|
|
|
public override ushort TID16 { get => ReadUInt16BigEndian(Data.AsSpan(0xA6)); set => WriteUInt16BigEndian(Data.AsSpan(0xA6), value); }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int Gender { get => Data[0xAF8]; set => Data[0xAF8] = (byte)value; }
|
|
|
|
public override uint Money { get => ReadUInt32BigEndian(Data.AsSpan(0xAFC)); set => WriteUInt32BigEndian(Data.AsSpan(0xAFC), value); }
|
|
|
|
public uint Coupons { get => ReadUInt32BigEndian(Data.AsSpan(0xB00)); set => WriteUInt32BigEndian(Data.AsSpan(0xB00), value); }
|
2023-03-26 06:14:50 +00:00
|
|
|
public string RUI_Name { get => GetString(Data.AsSpan(0xB3A, 20)); set => SetString(Data.AsSpan(0xB3A, 20), value, 10, StringConverterOption.ClearZero); }
|
2016-09-26 23:15:40 +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 = ItemStorage3Colo.Instance;
|
2022-06-18 18:04:24 +00:00
|
|
|
InventoryPouch[] pouch =
|
2016-09-26 23:15:40 +00:00
|
|
|
{
|
2023-04-16 19:58:07 +00:00
|
|
|
new InventoryPouch3GC(InventoryType.Items, info, 99, 0x007F8, 20), // 20 COLO, 30 XD
|
|
|
|
new InventoryPouch3GC(InventoryType.KeyItems, info, 1, 0x00848, 43),
|
|
|
|
new InventoryPouch3GC(InventoryType.Balls, info, 99, 0x008F4, 16),
|
|
|
|
new InventoryPouch3GC(InventoryType.TMHMs, info, 99, 0x00934, 64), // no HMs
|
|
|
|
new InventoryPouch3GC(InventoryType.Berries, info, 999, 0x00A34, 46),
|
|
|
|
new InventoryPouch3GC(InventoryType.Medicine, info, 99, 0x00AEC, 3), // Cologne
|
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-26 23:15:40 +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) { }
|
|
|
|
public override void SetDaycareOccupied(int loc, int slot, bool occupied) { }
|
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);
|
2016-09-26 23:15:40 +00:00
|
|
|
}
|
|
|
|
}
|