mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-27 14:30:56 +00:00
remove linq personalinfo bit fetch
reads the bits out of the original array (saves a few ms by not allocating/gc)
This commit is contained in:
parent
b75313cd87
commit
47643f49b6
9 changed files with 34 additions and 46 deletions
|
@ -78,11 +78,13 @@
|
|||
/// </summary>
|
||||
public bool[][] SpecialTutors { get; protected set; } = new bool[0][];
|
||||
|
||||
protected static bool[] GetBits(byte[] data)
|
||||
protected static bool[] GetBits(byte[] data, int start = 0, int length = -1)
|
||||
{
|
||||
bool[] r = new bool[data.Length<<3];
|
||||
if (length < 0)
|
||||
length = data.Length;
|
||||
bool[] r = new bool[length << 3];
|
||||
for (int i = 0; i < r.Length; i++)
|
||||
r[i] = (data[i>>3] >> (i&7) & 0x1) == 1;
|
||||
r[i] = (data[start + (i >> 3)] >> (i & 7) & 0x1) == 1;
|
||||
return r;
|
||||
}
|
||||
protected static byte[] SetBits(bool[] bits)
|
||||
|
@ -96,12 +98,11 @@
|
|||
/// <summary>
|
||||
/// Injects supplementary TM/HM compatibility which is not present in the generation specific <see cref="PersonalInfo"/> format.
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
internal void AddTMHM(byte[] data) => TMHM = GetBits(data);
|
||||
internal void AddTMHM(byte[] data, int start = 0, int length = -1) => TMHM = GetBits(data, start, length);
|
||||
/// <summary>
|
||||
/// Injects supplementary Type Tutor compatibility which is not present in the generation specific <see cref="PersonalInfo"/> format.
|
||||
/// </summary>
|
||||
internal void AddTypeTutors(byte[] data) => TypeTutors = GetBits(data);
|
||||
internal void AddTypeTutors(byte[] data, int start = 0, int length = -1) => TypeTutors = GetBits(data, start, length);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="PersonalTable"/> <see cref="PKM.AltForm"/> entry index for the input criteria, with fallback for the original species entry.
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
using System.Linq;
|
||||
|
||||
namespace PKHeX.Core
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// <see cref="PersonalInfo"/> class with values from the Black 2 & White 2 games.
|
||||
|
@ -15,14 +13,14 @@ namespace PKHeX.Core
|
|||
Data = data;
|
||||
|
||||
// Unpack TMHM & Tutors
|
||||
TMHM = GetBits(Data.Skip(0x28).Take(0x10).ToArray());
|
||||
TypeTutors = GetBits(Data.Skip(0x38).Take(0x4).ToArray());
|
||||
TMHM = GetBits(Data, 0x28, 0x10);
|
||||
TypeTutors = GetBits(Data, 0x3, 0x4);
|
||||
SpecialTutors = new[]
|
||||
{
|
||||
GetBits(Data.Skip(0x3C).Take(0x04).ToArray()),
|
||||
GetBits(Data.Skip(0x40).Take(0x04).ToArray()),
|
||||
GetBits(Data.Skip(0x44).Take(0x04).ToArray()),
|
||||
GetBits(Data.Skip(0x48).Take(0x04).ToArray()),
|
||||
GetBits(Data, 0x3C, 0x04),
|
||||
GetBits(Data, 0x40, 0x04),
|
||||
GetBits(Data, 0x44, 0x04),
|
||||
GetBits(Data, 0x48, 0x04),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
|
@ -17,8 +16,8 @@ namespace PKHeX.Core
|
|||
Data = data;
|
||||
|
||||
// Unpack TMHM & Tutors
|
||||
TMHM = GetBits(Data.Skip(0x28).Take(0x10).ToArray());
|
||||
TypeTutors = GetBits(Data.Skip(0x38).Take(0x4).ToArray());
|
||||
TMHM = GetBits(Data, 0x28, 0x10);
|
||||
TypeTutors = GetBits(Data, 0x38, 0x4);
|
||||
}
|
||||
public override byte[] Write()
|
||||
{
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
using System.Linq;
|
||||
|
||||
namespace PKHeX.Core
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// <see cref="PersonalInfo"/> class with values from Generation 1 games.
|
||||
|
@ -15,7 +13,7 @@ namespace PKHeX.Core
|
|||
return;
|
||||
|
||||
Data = data;
|
||||
TMHM = GetBits(Data.Skip(0x14).Take(0x8).ToArray());
|
||||
TMHM = GetBits(Data, 0x14, 0x8);
|
||||
}
|
||||
public override byte[] Write()
|
||||
{
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
using System.Linq;
|
||||
|
||||
namespace PKHeX.Core
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// <see cref="PersonalInfo"/> class with values from Generation 2 games.
|
||||
|
@ -15,7 +13,7 @@ namespace PKHeX.Core
|
|||
return;
|
||||
|
||||
Data = data;
|
||||
TMHM = GetBits(Data.Skip(0x18).Take(0x8).ToArray());
|
||||
TMHM = GetBits(Data, 0x18, 0x8);
|
||||
}
|
||||
public override byte[] Write()
|
||||
{
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
|
@ -16,7 +15,7 @@ namespace PKHeX.Core
|
|||
Data = data;
|
||||
|
||||
// Unpack TMHM & Tutors
|
||||
TMHM = GetBits(Data.Skip(0x1C).Take(0x0D).ToArray());
|
||||
TMHM = GetBits(Data, 0x1C, 0x0D);
|
||||
TypeTutors = new bool[0]; // not stored in personal
|
||||
}
|
||||
public override byte[] Write()
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
using System.Linq;
|
||||
|
||||
namespace PKHeX.Core
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// <see cref="PersonalInfo"/> class with values from the OR & AS games.
|
||||
|
@ -15,15 +13,15 @@ namespace PKHeX.Core
|
|||
Data = data;
|
||||
|
||||
// Unpack TMHM & Tutors
|
||||
TMHM = GetBits(Data.Skip(0x28).Take(0x10).ToArray());
|
||||
TypeTutors = GetBits(Data.Skip(0x38).Take(0x4).ToArray());
|
||||
TMHM = GetBits(Data, 0x28, 0x10);
|
||||
TypeTutors = GetBits(Data, 0x38, 0x4);
|
||||
// 0x3C-0x40 unknown
|
||||
SpecialTutors = new[]
|
||||
{
|
||||
GetBits(Data.Skip(0x40).Take(0x04).ToArray()),
|
||||
GetBits(Data.Skip(0x44).Take(0x04).ToArray()),
|
||||
GetBits(Data.Skip(0x48).Take(0x04).ToArray()),
|
||||
GetBits(Data.Skip(0x4C).Take(0x04).ToArray()),
|
||||
GetBits(Data, 0x40, 0x04),
|
||||
GetBits(Data, 0x44, 0x04),
|
||||
GetBits(Data, 0x48, 0x04),
|
||||
GetBits(Data, 0x4C, 0x04),
|
||||
};
|
||||
}
|
||||
public override byte[] Write()
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
|
@ -15,12 +14,12 @@ namespace PKHeX.Core
|
|||
return;
|
||||
Data = data;
|
||||
|
||||
TMHM = GetBits(Data.Skip(0x28).Take(0x10).ToArray()); // 36-39
|
||||
TypeTutors = GetBits(Data.Skip(0x38).Take(0x4).ToArray()); // 40
|
||||
TMHM = GetBits(Data, 0x28, 0x10); // 36-39
|
||||
TypeTutors = GetBits(Data, 0x38, 0x4); // 40
|
||||
|
||||
SpecialTutors = new[]
|
||||
{
|
||||
GetBits(Data.Skip(0x3C).Take(0x0A).ToArray()),
|
||||
GetBits(Data, 0x3C, 0x0A),
|
||||
};
|
||||
}
|
||||
public override byte[] Write()
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
using System.Linq;
|
||||
|
||||
namespace PKHeX.Core
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// <see cref="PersonalInfo"/> class with values from the X & Y games.
|
||||
|
@ -16,8 +14,8 @@ namespace PKHeX.Core
|
|||
Data = data;
|
||||
|
||||
// Unpack TMHM & Tutors
|
||||
TMHM = GetBits(Data.Skip(0x28).Take(0x10).ToArray());
|
||||
TypeTutors = GetBits(Data.Skip(0x38).Take(0x4).ToArray());
|
||||
TMHM = GetBits(Data, 0x28, 0x10);
|
||||
TypeTutors = GetBits(Data, 0x38, 0x4);
|
||||
// 0x3C-0x40 unknown
|
||||
}
|
||||
public override byte[] Write()
|
||||
|
|
Loading…
Reference in a new issue