2022-08-27 06:43:36 +00:00
|
|
|
using System;
|
2019-11-16 01:34:18 +00:00
|
|
|
using System.Collections.Generic;
|
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-03-06 01:34:09 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Generation 8 <see cref="SaveFile"/> object for <see cref="GameVersion.SWSH"/> games.
|
|
|
|
/// </summary>
|
|
|
|
public sealed class SAV8SWSH : SaveFile, ISaveBlock8SWSH, ITrainerStatRecord, ISaveFileRevision, ISCBlockArray
|
2019-09-23 23:56:47 +00:00
|
|
|
{
|
2022-03-06 01:34:09 +00:00
|
|
|
public SAV8SWSH(byte[] data) : this(SwishCrypto.Decrypt(data)) { }
|
|
|
|
|
|
|
|
private SAV8SWSH(IReadOnlyList<SCBlock> blocks) : base(Array.Empty<byte>())
|
|
|
|
{
|
|
|
|
AllBlocks = blocks;
|
|
|
|
Blocks = new SaveBlockAccessor8SWSH(this);
|
|
|
|
SaveRevision = Zukan.GetRevision();
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
public SAV8SWSH()
|
|
|
|
{
|
|
|
|
AllBlocks = Meta8.GetBlankDataSWSH();
|
|
|
|
Blocks = new SaveBlockAccessor8SWSH(this);
|
|
|
|
SaveRevision = Zukan.GetRevision();
|
|
|
|
Initialize();
|
|
|
|
ClearBoxes();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void CopyChangesFrom(SaveFile sav)
|
|
|
|
{
|
|
|
|
// Absorb changes from all blocks
|
|
|
|
var z = (SAV8SWSH)sav;
|
|
|
|
var mine = AllBlocks;
|
|
|
|
var newB = z.AllBlocks;
|
|
|
|
for (int i = 0; i < mine.Count; i++)
|
|
|
|
mine[i].CopyFrom(newB[i]);
|
|
|
|
State.Edited = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int SaveRevision { get; }
|
|
|
|
|
|
|
|
public string SaveRevisionString => SaveRevision switch
|
2019-09-23 23:56:47 +00:00
|
|
|
{
|
2022-03-06 01:34:09 +00:00
|
|
|
0 => "-Base", // Vanilla
|
|
|
|
1 => "-IoA", // DLC 1: Isle of Armor
|
|
|
|
2 => "-CT", // DLC 2: Crown Tundra
|
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(SaveRevision)),
|
|
|
|
};
|
2019-11-16 01:34:18 +00:00
|
|
|
|
2022-03-06 01:34:09 +00:00
|
|
|
public override bool ChecksumsValid => true;
|
|
|
|
public override string ChecksumInfo => string.Empty;
|
|
|
|
protected override void SetChecksums() { } // None!
|
|
|
|
protected override byte[] GetFinalData() => SwishCrypto.Encrypt(AllBlocks);
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public override PersonalTable8SWSH Personal => PersonalTable.SWSH;
|
2023-03-26 00:55:55 +00:00
|
|
|
public override ReadOnlySpan<ushort> HeldItems => Legal.HeldItems_SWSH;
|
2022-03-06 01:34:09 +00:00
|
|
|
|
|
|
|
#region Blocks
|
|
|
|
public SCBlockAccessor Accessor => Blocks;
|
|
|
|
public SaveBlockAccessor8SWSH Blocks { get; }
|
2022-03-06 01:46:03 +00:00
|
|
|
public IReadOnlyList<SCBlock> AllBlocks { get; }
|
|
|
|
public T GetValue<T>(uint key) where T : struct => Blocks.GetBlockValueSafe<T>(key);
|
|
|
|
public void SetValue<T>(uint key, T value) where T : struct => Blocks.SetBlockValueSafe(key, value);
|
2022-03-06 01:34:09 +00:00
|
|
|
public Box8 BoxInfo => Blocks.BoxInfo;
|
|
|
|
public Party8 PartyInfo => Blocks.PartyInfo;
|
2022-11-25 01:42:17 +00:00
|
|
|
public MyItem8 Items => Blocks.Items;
|
2022-03-06 01:34:09 +00:00
|
|
|
public MyStatus8 MyStatus => Blocks.MyStatus;
|
|
|
|
public Misc8 Misc => Blocks.Misc;
|
|
|
|
public Zukan8 Zukan => Blocks.Zukan;
|
|
|
|
public BoxLayout8 BoxLayout => Blocks.BoxLayout;
|
|
|
|
public PlayTime8 Played => Blocks.Played;
|
|
|
|
public Fused8 Fused => Blocks.Fused;
|
|
|
|
public Daycare8 Daycare => Blocks.Daycare;
|
|
|
|
public Record8 Records => Blocks.Records;
|
|
|
|
public TrainerCard8 TrainerCard => Blocks.TrainerCard;
|
2023-04-16 19:32:25 +00:00
|
|
|
public FashionUnlock8 Fashion => Blocks.Fashion;
|
2022-03-06 01:34:09 +00:00
|
|
|
public RaidSpawnList8 Raid => Blocks.Raid;
|
|
|
|
public RaidSpawnList8 RaidArmor => Blocks.RaidArmor;
|
|
|
|
public RaidSpawnList8 RaidCrown => Blocks.RaidCrown;
|
|
|
|
public TitleScreen8 TitleScreen => Blocks.TitleScreen;
|
|
|
|
public TeamIndexes8 TeamIndexes => Blocks.TeamIndexes;
|
|
|
|
#endregion
|
2022-03-06 01:46:03 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
protected override SAV8SWSH CloneInternal()
|
2022-03-06 01:34:09 +00:00
|
|
|
{
|
|
|
|
var blockCopy = new SCBlock[AllBlocks.Count];
|
|
|
|
for (int i = 0; i < AllBlocks.Count; i++)
|
|
|
|
blockCopy[i] = AllBlocks[i].Clone();
|
2023-01-22 04:02:33 +00:00
|
|
|
return new(blockCopy);
|
2022-03-06 01:34:09 +00:00
|
|
|
}
|
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
private ushort m_spec, m_item, m_move, m_abil;
|
|
|
|
public override ushort MaxMoveID => m_move;
|
|
|
|
public override ushort MaxSpeciesID => m_spec;
|
2022-03-06 01:34:09 +00:00
|
|
|
public override int MaxItemID => m_item;
|
|
|
|
public override int MaxBallID => Legal.MaxBallID_8;
|
|
|
|
public override int MaxGameID => Legal.MaxGameID_8;
|
|
|
|
public override int MaxAbilityID => m_abil;
|
|
|
|
|
|
|
|
private void Initialize()
|
|
|
|
{
|
|
|
|
Box = 0;
|
|
|
|
Party = 0;
|
|
|
|
PokeDex = 0;
|
|
|
|
TeamIndexes.LoadBattleTeams();
|
|
|
|
|
|
|
|
int rev = SaveRevision;
|
|
|
|
if (rev == 0)
|
2019-11-16 01:34:18 +00:00
|
|
|
{
|
2022-03-06 01:34:09 +00:00
|
|
|
m_move = Legal.MaxMoveID_8_O0;
|
|
|
|
m_spec = Legal.MaxSpeciesID_8_O0;
|
|
|
|
m_item = Legal.MaxItemID_8_O0;
|
|
|
|
m_abil = Legal.MaxAbilityID_8_O0;
|
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-03-06 01:34:09 +00:00
|
|
|
else if (rev == 1)
|
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-03-06 01:34:09 +00:00
|
|
|
m_move = Legal.MaxMoveID_8_R1;
|
|
|
|
m_spec = Legal.MaxSpeciesID_8_R1;
|
|
|
|
m_item = Legal.MaxItemID_8_R1;
|
|
|
|
m_abil = Legal.MaxAbilityID_8_R1;
|
2019-11-16 01:34:18 +00:00
|
|
|
}
|
2022-03-06 01:34:09 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_move = Legal.MaxMoveID_8_R2;
|
|
|
|
m_spec = Legal.MaxSpeciesID_8_R2;
|
|
|
|
m_item = Legal.MaxItemID_8_R2;
|
|
|
|
m_abil = Legal.MaxAbilityID_8_R2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save Data Attributes
|
|
|
|
protected internal override string ShortSummary => $"{OT} ({Version}) - {Played.LastSavedTime}";
|
|
|
|
public override string Extension => string.Empty;
|
|
|
|
|
|
|
|
public override IReadOnlyList<string> PKMExtensions => Array.FindAll(PKM.Extensions, f =>
|
|
|
|
{
|
|
|
|
int gen = f[^1] - 0x30;
|
|
|
|
return gen <= 8;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Configuration
|
|
|
|
protected override int SIZE_STORED => PokeCrypto.SIZE_8STORED;
|
|
|
|
protected override int SIZE_PARTY => PokeCrypto.SIZE_8PARTY;
|
|
|
|
public override int SIZE_BOXSLOT => PokeCrypto.SIZE_8PARTY;
|
2023-01-22 04:02:33 +00:00
|
|
|
public override PK8 BlankPKM => new();
|
2022-03-06 01:34:09 +00:00
|
|
|
public override Type PKMType => typeof(PK8);
|
|
|
|
|
|
|
|
public override int BoxCount => BoxLayout8.BoxCount;
|
|
|
|
public override int MaxEV => 252;
|
|
|
|
public override int Generation => 8;
|
2022-06-04 02:08:46 +00:00
|
|
|
public override EntityContext Context => EntityContext.Gen8;
|
2022-11-25 01:42:17 +00:00
|
|
|
public override int MaxStringLengthOT => 12;
|
|
|
|
public override int MaxStringLengthNickname => 12;
|
2023-01-22 04:02:33 +00:00
|
|
|
protected override PK8 GetPKM(byte[] data) => new(data);
|
2022-03-06 01:34:09 +00:00
|
|
|
protected override byte[] DecryptPKM(byte[] data) => PokeCrypto.DecryptArray8(data);
|
|
|
|
|
|
|
|
public override GameVersion Version => Game switch
|
|
|
|
{
|
|
|
|
(int)GameVersion.SW => GameVersion.SW,
|
|
|
|
(int)GameVersion.SH => GameVersion.SH,
|
|
|
|
_ => GameVersion.Invalid,
|
|
|
|
};
|
|
|
|
|
|
|
|
public override string GetString(ReadOnlySpan<byte> data) => StringConverter8.GetString(data);
|
|
|
|
public override int SetString(Span<byte> destBuffer, ReadOnlySpan<char> value, int maxLength, StringConverterOption option)
|
|
|
|
=> StringConverter8.SetString(destBuffer, value, maxLength, option);
|
|
|
|
|
|
|
|
// Player Information
|
2023-01-22 04:02:33 +00:00
|
|
|
public override uint ID32 { get => MyStatus.ID32; set => MyStatus.ID32 = value; }
|
|
|
|
public override ushort TID16 { get => MyStatus.TID16; set => MyStatus.TID16 = value; }
|
|
|
|
public override ushort SID16 { get => MyStatus.SID16; set => MyStatus.SID16 = value; }
|
2022-03-06 01:34:09 +00:00
|
|
|
public override int Game { get => MyStatus.Game; set => MyStatus.Game = value; }
|
|
|
|
public override int Gender { get => MyStatus.Gender; set => MyStatus.Gender = value; }
|
|
|
|
public override int Language { get => MyStatus.Language; set => MyStatus.Language = value; }
|
|
|
|
public override string OT { get => MyStatus.OT; set => MyStatus.OT = value; }
|
|
|
|
public override uint Money { get => Misc.Money; set => Misc.Money = value; }
|
|
|
|
public int Badges { get => Misc.Badges; set => Misc.Badges = value; }
|
|
|
|
|
|
|
|
public override int PlayedHours { get => Played.PlayedHours; set => Played.PlayedHours = value; }
|
|
|
|
public override int PlayedMinutes { get => Played.PlayedMinutes; set => Played.PlayedMinutes = value; }
|
|
|
|
public override int PlayedSeconds { get => Played.PlayedSeconds; set => Played.PlayedSeconds = value; }
|
|
|
|
|
|
|
|
// Inventory
|
|
|
|
public override IReadOnlyList<InventoryPouch> Inventory { get => Items.Inventory; set => Items.Inventory = value; }
|
|
|
|
|
|
|
|
// Storage
|
|
|
|
public override int GetPartyOffset(int slot) => Party + (SIZE_PARTY * slot);
|
|
|
|
public override int GetBoxOffset(int box) => Box + (SIZE_PARTY * box * 30);
|
|
|
|
public override string GetBoxName(int box) => BoxLayout[box];
|
2023-01-22 04:02:33 +00:00
|
|
|
public override void SetBoxName(int box, ReadOnlySpan<char> value) => BoxLayout.SetBoxName(box, value);
|
2022-06-18 18:04:24 +00:00
|
|
|
public override byte[] GetDataForBox(PKM pk) => pk.EncryptedPartyData;
|
2022-03-06 01:34:09 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override void SetPKM(PKM pk, bool isParty = false)
|
2022-03-06 01:34:09 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
PK8 pk8 = (PK8)pk;
|
2022-03-06 01:34:09 +00:00
|
|
|
// Apply to this Save File
|
|
|
|
DateTime Date = DateTime.Now;
|
2022-06-18 18:04:24 +00:00
|
|
|
pk8.Trade(this, Date.Day, Date.Month, Date.Year);
|
2019-11-16 01:34:18 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (FormArgumentUtil.IsFormArgumentTypeDatePair(pk8.Species, pk8.Form))
|
2019-11-16 01:34:18 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
pk8.FormArgumentElapsed = pk8.FormArgumentMaximum = 0;
|
|
|
|
pk8.FormArgumentRemain = (byte)GetFormArgument(pk8);
|
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
|
|
|
}
|
2019-09-23 23:56:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
pk8.RefreshChecksum();
|
|
|
|
AddCountAcquired(pk8);
|
2022-03-06 01:34:09 +00:00
|
|
|
}
|
2020-09-26 06:41:20 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private static uint GetFormArgument(PKM pk)
|
2022-03-06 01:34:09 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (pk.Form == 0)
|
2022-03-06 01:34:09 +00:00
|
|
|
return 0;
|
2022-06-18 18:04:24 +00:00
|
|
|
return pk.Species switch
|
2020-09-26 06:41:20 +00:00
|
|
|
{
|
2022-03-06 01:34:09 +00:00
|
|
|
(int)Species.Furfrou => 5u, // Furfrou
|
|
|
|
(int)Species.Hoopa => 3u, // Hoopa
|
|
|
|
_ => 0u,
|
2020-09-26 06:41:20 +00:00
|
|
|
};
|
2022-03-06 01:34:09 +00:00
|
|
|
}
|
2020-09-26 06:41:20 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void AddCountAcquired(PKM pk)
|
2022-03-06 01:34:09 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (pk.WasEgg)
|
2020-03-11 06:18:51 +00:00
|
|
|
{
|
2022-03-06 01:34:09 +00:00
|
|
|
Records.AddRecord(00);
|
2020-03-11 06:18:51 +00:00
|
|
|
}
|
2022-03-06 01:34:09 +00:00
|
|
|
else // capture, assume wild
|
2020-01-19 18:25:40 +00:00
|
|
|
{
|
2022-03-06 01:34:09 +00:00
|
|
|
Records.AddRecord(01); // wild capture
|
|
|
|
Records.AddRecord(06); // total captured
|
|
|
|
Records.AddRecord(16); // wild encountered
|
|
|
|
Records.AddRecord(23); // total battled
|
2020-01-19 18:25:40 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
if (pk.CurrentHandler == 1)
|
2022-03-06 01:34:09 +00:00
|
|
|
Records.AddRecord(17, 2); // trade * 2 -- these games count 1 trade as 2 for some reason.
|
|
|
|
}
|
2020-01-19 18:25:40 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override void SetDex(PKM pk) => Zukan.SetDex(pk);
|
2022-08-27 06:43:36 +00:00
|
|
|
public override bool GetCaught(ushort species) => Zukan.GetCaught(species);
|
|
|
|
public override bool GetSeen(ushort species) => Zukan.GetSeen(species);
|
2019-11-16 01:34:18 +00:00
|
|
|
|
2022-03-06 01:34:09 +00:00
|
|
|
public override int PartyCount
|
|
|
|
{
|
|
|
|
get => PartyInfo.PartyCount;
|
|
|
|
protected set => PartyInfo.PartyCount = value;
|
|
|
|
}
|
2019-09-23 23:56:47 +00:00
|
|
|
|
2023-03-26 06:14:50 +00:00
|
|
|
protected override Span<byte> BoxBuffer => BoxInfo.Data;
|
|
|
|
protected override Span<byte> PartyBuffer => PartyInfo.Data;
|
2023-01-22 04:02:33 +00:00
|
|
|
public override PK8 GetDecryptedPKM(byte[] data) => GetPKM(DecryptPKM(data));
|
2023-03-26 06:14:50 +00:00
|
|
|
public override PK8 GetBoxSlot(int offset) => GetDecryptedPKM(BoxInfo.Data.AsSpan(offset, SIZE_PARTY).ToArray()); // party format in boxes!
|
2020-06-19 23:51:15 +00:00
|
|
|
|
2022-03-06 01:34:09 +00:00
|
|
|
public int GetRecord(int recordID) => Records.GetRecord(recordID);
|
|
|
|
public void SetRecord(int recordID, int value) => Records.SetRecord(recordID, value);
|
|
|
|
public int GetRecordMax(int recordID) => Records.GetRecordMax(recordID);
|
|
|
|
public int GetRecordOffset(int recordID) => Records.GetRecordOffset(recordID);
|
|
|
|
public int RecordCount => Record8.RecordCount;
|
2019-11-16 01:34:18 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override StorageSlotSource GetSlotFlags(int index)
|
2022-03-06 01:34:09 +00:00
|
|
|
{
|
|
|
|
int team = Array.IndexOf(TeamIndexes.TeamSlots, index);
|
|
|
|
if (team < 0)
|
2022-06-18 18:04:24 +00:00
|
|
|
return StorageSlotSource.None;
|
2020-02-02 02:56:23 +00:00
|
|
|
|
2022-03-06 01:34:09 +00:00
|
|
|
team /= 6;
|
2022-06-18 18:04:24 +00:00
|
|
|
var result = (StorageSlotSource)((int)StorageSlotSource.BattleTeam1 << team);
|
2022-03-06 01:34:09 +00:00
|
|
|
if (TeamIndexes.GetIsTeamLocked(team))
|
2022-06-18 18:04:24 +00:00
|
|
|
result |= StorageSlotSource.Locked;
|
2022-03-06 01:34:09 +00:00
|
|
|
return result;
|
|
|
|
}
|
2020-03-11 06:18:51 +00:00
|
|
|
|
2022-03-06 01:34:09 +00:00
|
|
|
public override int CurrentBox { get => BoxLayout.CurrentBox; set => BoxLayout.CurrentBox = value; }
|
|
|
|
public override int BoxesUnlocked { get => (byte)Blocks.GetBlockValue(SaveBlockAccessor8SWSH.KBoxesUnlocked); set => Blocks.SetBlockValue(SaveBlockAccessor8SWSH.KBoxesUnlocked, (byte)value); }
|
2021-03-03 05:28:53 +00:00
|
|
|
|
2022-03-06 01:34:09 +00:00
|
|
|
public override byte[] BoxFlags
|
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
get => new [] {(byte)(Blocks.GetBlock(SaveBlockAccessor8SWSH.KSecretBoxUnlocked).Type - 1)};
|
2022-03-06 01:34:09 +00:00
|
|
|
set
|
2021-03-03 05:28:53 +00:00
|
|
|
{
|
2022-03-06 01:34:09 +00:00
|
|
|
if (value.Length != 1)
|
|
|
|
return;
|
|
|
|
var block = Blocks.GetBlock(SaveBlockAccessor8SWSH.KSecretBoxUnlocked);
|
|
|
|
block.ChangeBooleanType((SCTypeCode)(value[0] & 1) + 1);
|
2021-03-03 05:28:53 +00:00
|
|
|
}
|
2022-03-06 01:34:09 +00:00
|
|
|
}
|
2020-04-16 21:50:41 +00:00
|
|
|
|
2022-03-06 01:34:09 +00:00
|
|
|
public override bool HasBoxWallpapers => true;
|
|
|
|
public override bool HasNamableBoxes => true;
|
2020-04-16 21:50:41 +00:00
|
|
|
|
2022-03-06 01:34:09 +00:00
|
|
|
public override int GetBoxWallpaper(int box)
|
|
|
|
{
|
|
|
|
if ((uint)box >= BoxCount)
|
|
|
|
return box;
|
|
|
|
var b = Blocks.GetBlock(SaveBlockAccessor8SWSH.KBoxWallpapers);
|
|
|
|
return b.Data[box];
|
|
|
|
}
|
2020-04-16 21:50:41 +00:00
|
|
|
|
2022-03-06 01:34:09 +00:00
|
|
|
public override void SetBoxWallpaper(int box, int value)
|
|
|
|
{
|
|
|
|
if ((uint)box >= BoxCount)
|
|
|
|
return;
|
|
|
|
var b = Blocks.GetBlock(SaveBlockAccessor8SWSH.KBoxWallpapers);
|
|
|
|
b.Data[box] = (byte)value;
|
|
|
|
}
|
2022-03-02 05:34:16 +00:00
|
|
|
|
2022-03-06 01:34:09 +00:00
|
|
|
public void UnlockAllDiglett()
|
|
|
|
{
|
|
|
|
if (SaveRevision == 0)
|
|
|
|
return; // no blocks
|
2022-03-02 05:34:16 +00:00
|
|
|
|
2022-03-06 01:34:09 +00:00
|
|
|
// Zone specific values
|
|
|
|
(int Zone, int Max)[] zones =
|
|
|
|
{
|
|
|
|
(0201, 16), // Fields of Honor
|
|
|
|
(0202, 18), // Soothing Wetlands
|
|
|
|
(0203, 6), // Forest of Focus
|
|
|
|
(0204, 7), // Challenge Beach
|
|
|
|
(0205, 5), // Brawlers' Cave
|
|
|
|
(0206, 6), // Challenge Road
|
|
|
|
(0207, 5), // Courageous Cavern
|
|
|
|
(0208, 5), // Loop Lagoon
|
|
|
|
(0209, 13), // Training Lowlands
|
|
|
|
(0210, 1), // Warm-Up Tunnel
|
|
|
|
(0211, 8), // Potbottom Desert
|
|
|
|
(0221, 9), // Workout Sea
|
|
|
|
(0222, 5), // Stepping-Stone Sea
|
|
|
|
(0223, 3), // Insular Sea
|
|
|
|
(0224, 1), // Honeycalm Sea
|
|
|
|
(0231, 9), // Honeycalm Island
|
|
|
|
};
|
|
|
|
var s = Blocks;
|
|
|
|
foreach (var (zone, max) in zones)
|
|
|
|
{
|
|
|
|
var baseName = $"z_wr{zone:0000}_F_DHIGUDA";
|
|
|
|
s.GetBlock(baseName).ChangeBooleanType(SCTypeCode.Bool2);
|
|
|
|
for (int i = 0; i <= max; i++)
|
2022-03-02 05:34:16 +00:00
|
|
|
{
|
2022-03-06 01:34:09 +00:00
|
|
|
var otherName = $"{baseName}_{i}";
|
|
|
|
s.GetBlock(otherName).ChangeBooleanType(SCTypeCode.Bool2);
|
2022-03-02 05:34:16 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 01:34:09 +00:00
|
|
|
var countName = $"WK_EV_R1_DHIG_WR{zone:0000}";
|
|
|
|
var value = max + 2;
|
|
|
|
if (zone == 0223) // trio
|
|
|
|
value += 2;
|
|
|
|
s.GetBlock(countName).SetValue((uint)value);
|
2022-03-02 05:34:16 +00:00
|
|
|
}
|
2022-03-06 01:34:09 +00:00
|
|
|
|
|
|
|
// Atypical named values
|
|
|
|
const string TRIO1 = "z_wr0223_F_TRIO";
|
|
|
|
const string TRIO2 = "FE_R1_DHIGUDA_TRIO";
|
|
|
|
s.GetBlock(TRIO1).ChangeBooleanType(SCTypeCode.Bool2);
|
|
|
|
s.GetBlock(TRIO2).ChangeBooleanType(SCTypeCode.Bool2);
|
|
|
|
|
|
|
|
// Overall named values
|
|
|
|
const string unreported = "WK_EV_R1_DHIGUDA_ADD";
|
|
|
|
const string totalCount = "WK_EV_R1_DHIGUDA_COUNT";
|
|
|
|
const string progressCt = "WK_EV_R1_DHIGUDA_PROGRESS";
|
|
|
|
s.GetBlock(unreported).SetValue((uint)150); // 150 unreported
|
|
|
|
s.GetBlock(totalCount).SetValue((uint)1); // obtained count
|
|
|
|
s.GetBlock(progressCt).SetValue((uint)1); // none obtained progress value
|
2019-09-23 23:56:47 +00:00
|
|
|
}
|
2020-04-16 21:50:41 +00:00
|
|
|
}
|