mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 04:23:12 +00:00
Minor refactoring
clean up some gc logic, no functional changes
This commit is contained in:
parent
4aa103a320
commit
258f0f0ad4
5 changed files with 54 additions and 69 deletions
|
@ -306,7 +306,9 @@ namespace PKHeX.Core
|
|||
|
||||
public override PKM GetPKM(byte[] data)
|
||||
{
|
||||
return new CK3(data.Take(SIZE_STORED).ToArray());
|
||||
if (data.Length != SIZE_STORED)
|
||||
Array.Resize(ref data, SIZE_STORED);
|
||||
return new CK3(data);
|
||||
}
|
||||
|
||||
public override byte[] DecryptPKM(byte[] data)
|
||||
|
|
|
@ -153,8 +153,7 @@ namespace PKHeX.Core
|
|||
public override SaveFile Clone()
|
||||
{
|
||||
byte[] data = Write(DSV: false, GCI: true).Skip(Header.Length).ToArray();
|
||||
var sav = new SAV3XD(data) {Header = (byte[]) Header.Clone()};
|
||||
return sav;
|
||||
return new SAV3XD(data) {Header = (byte[]) Header.Clone()};
|
||||
}
|
||||
|
||||
public override int SIZE_STORED => PKX.SIZE_3XSTORED;
|
||||
|
@ -255,42 +254,27 @@ namespace PKHeX.Core
|
|||
public uint Coupons { get => BigEndian.ToUInt32(Data, Trainer1 + 0x8E8); set => BigEndian.GetBytes(value).CopyTo(Data, Trainer1 + 0x8E8); }
|
||||
|
||||
// Storage
|
||||
public override int GetPartyOffset(int slot)
|
||||
{
|
||||
return Party + (SIZE_STORED * slot);
|
||||
}
|
||||
|
||||
public override int GetBoxOffset(int box)
|
||||
{
|
||||
return Box + (((30 * SIZE_STORED) + 0x14)*box) + 0x14;
|
||||
}
|
||||
|
||||
public override string GetBoxName(int box)
|
||||
{
|
||||
return GetString(Box + (((30 * SIZE_STORED) + 0x14)*box), 16);
|
||||
}
|
||||
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;
|
||||
public override string GetBoxName(int box) => GetString(GetBoxInfoOffset(box), 16);
|
||||
|
||||
public override void SetBoxName(int box, string value)
|
||||
{
|
||||
if (value.Length > 8)
|
||||
value = value.Substring(0, 8); // Hard cap
|
||||
SetString(value, 8).CopyTo(Data, Box + (0x24A4 * box));
|
||||
SetString(value, 8).CopyTo(Data, GetBoxInfoOffset(box));
|
||||
}
|
||||
|
||||
public override PKM GetPKM(byte[] data)
|
||||
{
|
||||
return new XK3(data.Take(SIZE_STORED).ToArray());
|
||||
if (data.Length != SIZE_STORED)
|
||||
Array.Resize(ref data, SIZE_STORED);
|
||||
return new XK3(data);
|
||||
}
|
||||
|
||||
public override byte[] DecryptPKM(byte[] data)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
public override PKM GetPartySlot(int offset)
|
||||
{
|
||||
return GetStoredSlot(offset);
|
||||
}
|
||||
public override byte[] DecryptPKM(byte[] data) => data;
|
||||
public override PKM GetPartySlot(int offset) => GetStoredSlot(offset);
|
||||
|
||||
public override PKM GetStoredSlot(int offset)
|
||||
{
|
||||
|
|
|
@ -158,15 +158,8 @@ namespace PKHeX.Core
|
|||
}
|
||||
|
||||
// Storage
|
||||
public override int GetPartyOffset(int slot)
|
||||
{
|
||||
return Party + (SIZE_PARTY * slot);
|
||||
}
|
||||
|
||||
public override int GetBoxOffset(int box)
|
||||
{
|
||||
return Box + (SIZE_STORED * box * 30);
|
||||
}
|
||||
public override int GetPartyOffset(int slot) => Party + (SIZE_PARTY * slot);
|
||||
public override int GetBoxOffset(int box) => Box + (SIZE_STORED * box * 30);
|
||||
|
||||
// Save file does not have Box Name / Wallpaper info
|
||||
private int BoxName = -1;
|
||||
|
@ -201,20 +194,14 @@ namespace PKHeX.Core
|
|||
|
||||
public override PKM GetPKM(byte[] data)
|
||||
{
|
||||
byte[] pkm = data.Take(SIZE_STORED).ToArray();
|
||||
PKM bk = new BK4(pkm);
|
||||
return bk;
|
||||
if (data.Length != SIZE_STORED)
|
||||
Array.Resize(ref data, SIZE_STORED);
|
||||
return new BK4(data);
|
||||
}
|
||||
|
||||
public override byte[] DecryptPKM(byte[] data)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
public override byte[] DecryptPKM(byte[] data) => data;
|
||||
|
||||
protected override void SetDex(PKM pkm)
|
||||
{
|
||||
// There's nothing in the dex
|
||||
}
|
||||
protected override void SetDex(PKM pkm) { /* There's no PokéDex */ }
|
||||
|
||||
protected override void SetPKM(PKM pkm)
|
||||
{
|
||||
|
|
|
@ -8,24 +8,30 @@ namespace PKHeX.Core
|
|||
{
|
||||
private readonly List<ShadowInfoEntryXD> Entries;
|
||||
private readonly int MaxLength;
|
||||
private const int SIZE_ENTRY = ShadowInfoEntryXD.SIZE_ENTRY;
|
||||
|
||||
public ShadowInfoTableXD(byte[] data)
|
||||
{
|
||||
Entries = new List<ShadowInfoEntryXD>();
|
||||
MaxLength = data.Length;
|
||||
const int eSize = ShadowInfoEntryXD.SIZE_ENTRY;
|
||||
int eCount = data.Length/eSize;
|
||||
int eCount = data.Length/SIZE_ENTRY;
|
||||
Entries = new List<ShadowInfoEntryXD>(eCount);
|
||||
for (int i = 0; i < eCount; i++)
|
||||
{
|
||||
byte[] d = new byte[eSize];
|
||||
Array.Copy(data, i*eSize, d, 0, eSize);
|
||||
|
||||
var entry = new ShadowInfoEntryXD(d);
|
||||
var entry = GetEntry(data, i);
|
||||
//if (entry.Species != 0)
|
||||
Entries.Add(entry);
|
||||
}
|
||||
}
|
||||
|
||||
private static ShadowInfoEntryXD GetEntry(byte[] data, int i)
|
||||
{
|
||||
var d = new byte[SIZE_ENTRY];
|
||||
Array.Copy(data, i * SIZE_ENTRY, d, 0, SIZE_ENTRY);
|
||||
|
||||
var entry = new ShadowInfoEntryXD(d);
|
||||
return entry;
|
||||
}
|
||||
|
||||
public byte[] FinalData => Entries.SelectMany(entry => entry.Data).Take(MaxLength).ToArray();
|
||||
|
||||
public ShadowInfoEntryXD GetEntry(int Species, uint PID)
|
||||
|
@ -39,8 +45,8 @@ namespace PKHeX.Core
|
|||
if (entry.IsEmpty)
|
||||
return;
|
||||
|
||||
int index = Array.FindIndex(Entries.ToArray(), ent => ent.Species == entry.Species);
|
||||
if (index > 0)
|
||||
int index = Entries.FindIndex(ent => ent.Species == entry.Species);
|
||||
if (index >= 0)
|
||||
Entries[index] = entry;
|
||||
else
|
||||
Entries.Add(entry);
|
||||
|
@ -52,13 +58,11 @@ namespace PKHeX.Core
|
|||
|
||||
public class ShadowInfoEntryXD
|
||||
{
|
||||
public byte[] Data { get; }
|
||||
public readonly byte[] Data;
|
||||
internal const int SIZE_ENTRY = 72;
|
||||
|
||||
public ShadowInfoEntryXD(byte[] data = null)
|
||||
{
|
||||
Data = data ?? new byte[SIZE_ENTRY];
|
||||
}
|
||||
public ShadowInfoEntryXD() => Data = new byte[SIZE_ENTRY];
|
||||
public ShadowInfoEntryXD(byte[] data) => Data = data;
|
||||
|
||||
public bool IsSnagged => Data[0] >> 6 != 0;
|
||||
public bool IsPurified { get => Data[0] >> 7 == 1; set { Data[0] &= 0x7F; if (value) Data[0] |= 0x80; } }
|
||||
|
@ -72,10 +76,11 @@ namespace PKHeX.Core
|
|||
|
||||
public class ShadowInfoEntryColo
|
||||
{
|
||||
public byte[] Data { get; }
|
||||
internal const int SIZE_ENTRY = 12;
|
||||
public readonly byte[] Data;
|
||||
private const int SIZE_ENTRY = 12;
|
||||
|
||||
public ShadowInfoEntryColo(byte[] data = null) => Data = data ?? new byte[SIZE_ENTRY];
|
||||
public ShadowInfoEntryColo() => Data = new byte[SIZE_ENTRY];
|
||||
public ShadowInfoEntryColo(byte[] data) => Data = data;
|
||||
|
||||
public uint PID { get => BigEndian.ToUInt32(Data, 0x00); set => BigEndian.GetBytes(value).CopyTo(Data, 0x00); }
|
||||
public int Met_Location { get => BigEndian.ToUInt16(Data, 0x06); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x06); }
|
||||
|
|
|
@ -21,12 +21,19 @@ namespace PKHeX.Core
|
|||
_unk = input.Skip(offset + 2).Take(2).ToArray();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
byte[] data = new byte[SIZE_ENTRY];
|
||||
Array.Copy(input, 4 + offset + (SIZE_ENTRY * i), data, 0, SIZE_ENTRY);
|
||||
Entries.Add(new StrategyMemoEntry(XD, data));
|
||||
var entry = Read(input, offset, i);
|
||||
Entries.Add(entry);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public byte[] FinalData => BigEndian.GetBytes((short)Entries.Count).Concat(_unk) // count followed by populated entries
|
||||
.Concat(Entries.SelectMany(entry => entry.Data)).ToArray();
|
||||
|
||||
|
@ -38,7 +45,7 @@ namespace PKHeX.Core
|
|||
public void SetEntry(StrategyMemoEntry entry)
|
||||
{
|
||||
int index = Entries.FindIndex(ent => ent.Species == entry.Species);
|
||||
if (index > 0)
|
||||
if (index >= 0)
|
||||
Entries[index] = entry;
|
||||
else
|
||||
Entries.Add(entry);
|
||||
|
|
Loading…
Reference in a new issue