2016-10-01 02:05:35 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.Core
|
2016-10-01 02:05:35 +00:00
|
|
|
|
{
|
2019-10-04 02:09:02 +00:00
|
|
|
|
public sealed class StrategyMemo
|
2016-10-01 02:05:35 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly bool XD;
|
2019-10-26 19:58:55 +00:00
|
|
|
|
public const int SIZE_ENTRY = 12;
|
2016-10-01 02:05:35 +00:00
|
|
|
|
private readonly List<StrategyMemoEntry> Entries = new List<StrategyMemoEntry>();
|
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 const int MAX_COUNT = 500;
|
|
|
|
|
public const int MAX_SIZE = MAX_COUNT * SIZE_ENTRY;
|
2018-05-12 19:28:48 +00:00
|
|
|
|
private StrategyMemoEntry this[int Species] => Entries.Find(e => e.Species == Species);
|
2017-08-07 00:20:04 +00:00
|
|
|
|
private readonly byte[] _unk;
|
2016-10-01 02:05:35 +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 StrategyMemo(bool xd = true) : this(new byte[MAX_SIZE], 0, xd) { }
|
|
|
|
|
|
2016-10-01 02:05:35 +00:00
|
|
|
|
public StrategyMemo(byte[] input, int offset, bool xd)
|
|
|
|
|
{
|
|
|
|
|
XD = xd;
|
|
|
|
|
int count = BigEndian.ToInt16(input, offset);
|
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
|
|
|
|
if (count > MAX_COUNT)
|
|
|
|
|
count = MAX_COUNT;
|
2019-09-23 22:13:22 +00:00
|
|
|
|
_unk = input.Slice(offset + 2, 2);
|
2016-10-01 02:05:35 +00:00
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
|
{
|
2019-02-17 18:42:43 +00:00
|
|
|
|
var entry = Read(input, offset, i);
|
|
|
|
|
Entries.Add(entry);
|
2016-10-01 02:05:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-29 20:27:48 +00:00
|
|
|
|
|
2019-02-17 18:42:43 +00:00
|
|
|
|
private StrategyMemoEntry Read(byte[] input, int offset, int index)
|
|
|
|
|
{
|
|
|
|
|
byte[] data = new byte[SIZE_ENTRY];
|
|
|
|
|
var ofs = 4 + offset + (SIZE_ENTRY * index);
|
|
|
|
|
Array.Copy(input, ofs, data, 0, SIZE_ENTRY);
|
|
|
|
|
return new StrategyMemoEntry(XD, data);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-26 19:58:55 +00:00
|
|
|
|
public byte[] Write() => BigEndian.GetBytes((short)Entries.Count).Concat(_unk) // count followed by populated entries
|
2017-08-07 00:20:04 +00:00
|
|
|
|
.Concat(Entries.SelectMany(entry => entry.Data)).ToArray();
|
2016-10-01 02:05:35 +00:00
|
|
|
|
|
|
|
|
|
public StrategyMemoEntry GetEntry(int Species)
|
|
|
|
|
{
|
|
|
|
|
return this[Species] ?? new StrategyMemoEntry(XD);
|
|
|
|
|
}
|
2018-07-29 20:27:48 +00:00
|
|
|
|
|
2016-10-01 02:05:35 +00:00
|
|
|
|
public void SetEntry(StrategyMemoEntry entry)
|
|
|
|
|
{
|
2017-04-23 16:18:42 +00:00
|
|
|
|
int index = Entries.FindIndex(ent => ent.Species == entry.Species);
|
2019-02-17 18:42:43 +00:00
|
|
|
|
if (index >= 0)
|
2016-10-01 02:05:35 +00:00
|
|
|
|
Entries[index] = entry;
|
|
|
|
|
else
|
|
|
|
|
Entries.Add(entry);
|
|
|
|
|
}
|
2019-10-26 19:58:55 +00:00
|
|
|
|
}
|
2018-07-29 20:27:48 +00:00
|
|
|
|
|
2019-10-26 19:58:55 +00:00
|
|
|
|
public sealed class StrategyMemoEntry
|
|
|
|
|
{
|
|
|
|
|
public readonly byte[] Data;
|
|
|
|
|
private readonly bool XD;
|
|
|
|
|
|
|
|
|
|
public StrategyMemoEntry(bool xd) : this(xd, new byte[StrategyMemo.SIZE_ENTRY]) { }
|
2018-07-29 20:27:48 +00:00
|
|
|
|
|
2019-10-26 19:58:55 +00:00
|
|
|
|
public StrategyMemoEntry(bool xd, byte[] data)
|
|
|
|
|
{
|
|
|
|
|
Data = data;
|
|
|
|
|
XD = xd;
|
|
|
|
|
}
|
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-10-26 19:58:55 +00:00
|
|
|
|
public int Species
|
|
|
|
|
{
|
|
|
|
|
get
|
2016-10-01 02:05:35 +00:00
|
|
|
|
{
|
2019-10-26 19:58:55 +00:00
|
|
|
|
int val = BigEndian.ToUInt16(Data, 0) & 0x1FF;
|
|
|
|
|
return SpeciesConverter.GetG4Species(val);
|
2016-10-01 02:05:35 +00:00
|
|
|
|
}
|
2019-10-26 19:58:55 +00:00
|
|
|
|
set
|
2016-10-01 02:05:35 +00:00
|
|
|
|
{
|
2019-10-26 19:58:55 +00:00
|
|
|
|
value = SpeciesConverter.GetG3Species(value);
|
|
|
|
|
int cval = BigEndian.ToUInt16(Data, 0);
|
|
|
|
|
cval &= 0xE00; value &= 0x1FF; cval |= value;
|
|
|
|
|
BigEndian.GetBytes((ushort)cval).CopyTo(Data, 0);
|
2016-10-01 02:05:35 +00:00
|
|
|
|
}
|
2019-10-26 19:58:55 +00:00
|
|
|
|
}
|
2018-07-29 20:27:48 +00:00
|
|
|
|
|
2019-10-26 19:58:55 +00:00
|
|
|
|
private bool Flag0 { get => Data[0] >> 6 == 1; set { Data[0] &= 0xBF; if (value) Data[0] |= 0x40; } } // Unused
|
|
|
|
|
private bool Flag1 { get => Data[0] >> 7 == 1; set { Data[0] &= 0x7F; if (value) Data[0] |= 0x80; } } // Complete Entry
|
|
|
|
|
public int SID { get => BigEndian.ToUInt16(Data, 4); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 4); }
|
|
|
|
|
public int TID { get => BigEndian.ToUInt16(Data, 6); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 6); }
|
|
|
|
|
public uint PID { get => BigEndian.ToUInt32(Data, 8); set => BigEndian.GetBytes(value).CopyTo(Data, 8); }
|
2016-10-01 02:05:35 +00:00
|
|
|
|
|
2019-10-26 19:58:55 +00:00
|
|
|
|
public bool Seen
|
|
|
|
|
{
|
|
|
|
|
get
|
2016-10-01 02:05:35 +00:00
|
|
|
|
{
|
2019-10-26 19:58:55 +00:00
|
|
|
|
if (XD) return !Flag1;
|
|
|
|
|
return Species != 0;
|
2016-10-01 02:05:35 +00:00
|
|
|
|
}
|
2019-10-26 19:58:55 +00:00
|
|
|
|
set
|
2016-10-01 02:05:35 +00:00
|
|
|
|
{
|
2019-10-26 19:58:55 +00:00
|
|
|
|
if (XD)
|
|
|
|
|
Flag1 = !value;
|
|
|
|
|
else if (!value)
|
|
|
|
|
new byte[StrategyMemo.SIZE_ENTRY].CopyTo(Data, 0);
|
2016-10-01 02:05:35 +00:00
|
|
|
|
}
|
2019-10-26 19:58:55 +00:00
|
|
|
|
}
|
2016-10-01 02:05:35 +00:00
|
|
|
|
|
2019-10-26 19:58:55 +00:00
|
|
|
|
public bool Owned
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (XD) return false;
|
|
|
|
|
return Flag0 || !Flag1;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (XD) return;
|
|
|
|
|
if (!value)
|
|
|
|
|
Flag1 = true;
|
|
|
|
|
}
|
2016-10-01 02:05:35 +00:00
|
|
|
|
}
|
2019-10-26 19:58:55 +00:00
|
|
|
|
|
|
|
|
|
public bool IsEmpty => Species == 0;
|
|
|
|
|
public bool Matches(int species, uint pid, int tid, int sid) => Species == species && PID == pid && TID == tid && SID == sid;
|
2016-10-01 02:05:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|