mirror of
https://github.com/kwsch/PKHeX
synced 2025-02-16 21:38:40 +00:00
Misc perf tweaks
hopefully resolves the image corruption issue (dont use unsafe?) remove some linq
This commit is contained in:
parent
b7acb7fa1d
commit
f7f5d78beb
5 changed files with 39 additions and 20 deletions
|
@ -182,7 +182,7 @@ namespace PKHeX.Core
|
|||
|
||||
private static bool GetLCRNGRoamerMatch(uint top, uint bot, uint[] IVs, out PIDIV pidiv)
|
||||
{
|
||||
if (IVs.Skip(2).Any(iv => iv != 0) || IVs[1] > 7)
|
||||
if (IVs[2] != 0 || IVs[3] != 0 || IVs[4] != 0 || IVs[5] != 0 || IVs[1] > 7)
|
||||
return GetNonMatch(out pidiv);
|
||||
var iv1 = GetIVChunk(IVs, 0);
|
||||
var reg = GetSeedsFromPID(RNG.LCRNG, top, bot);
|
||||
|
@ -726,7 +726,7 @@ namespace PKHeX.Core
|
|||
if (PIDType.Method_1 != val)
|
||||
return false;
|
||||
var IVs = pkm.IVs;
|
||||
return !(IVs.Skip(2).Any(iv => iv != 0) || IVs[1] > 7);
|
||||
return !(IVs[2] != 0 || IVs[3] != 0 || IVs[4] != 0 || IVs[5] != 0 || IVs[1] > 7);
|
||||
}
|
||||
|
||||
public static bool IsCompatible4(this PIDType val, IEncounterable encounter, PKM pkm)
|
||||
|
|
|
@ -157,7 +157,6 @@ namespace PKHeX.Core
|
|||
|
||||
protected override byte[] Write(bool DSV)
|
||||
{
|
||||
int len = SIZE_STOREDBOX;
|
||||
int splitAtIndex = (Japanese ? 6 : 7);
|
||||
for (int i = 0; i < BoxCount; i++)
|
||||
{
|
||||
|
@ -273,12 +272,15 @@ namespace PKHeX.Core
|
|||
|
||||
public override bool HasParty => true;
|
||||
public override bool HasNamableBoxes => true;
|
||||
private int StringLength => Japanese ? PK1.STRLEN_J : PK1.STRLEN_U;
|
||||
private int StringLength => Japanese ? _K12.STRLEN_J : _K12.STRLEN_U;
|
||||
|
||||
// Checksums
|
||||
private ushort GetChecksum()
|
||||
{
|
||||
return (ushort)Data.Skip(Offsets.Trainer1).Take(Offsets.AccumulatedChecksumEnd - Offsets.Trainer1 + 1).Sum(a => a);
|
||||
ushort sum = 0;
|
||||
for (int i = Offsets.Trainer1; i <= Offsets.AccumulatedChecksumEnd; i++)
|
||||
sum += Data[i];
|
||||
return sum;
|
||||
}
|
||||
|
||||
protected override void SetChecksums()
|
||||
|
|
|
@ -759,31 +759,45 @@ namespace PKHeX.Core
|
|||
input = input.Skip(header.Length).ToArray();
|
||||
return;
|
||||
}
|
||||
if (!FOOTER_DSV.SequenceEqual(input.Skip(input.Length - FOOTER_DSV.Length)))
|
||||
return;
|
||||
footer = input.Skip(SIZE_G4RAW).ToArray();
|
||||
input = input.Take(SIZE_G4RAW).ToArray();
|
||||
int start = input.Length - FOOTER_DSV.Length;
|
||||
for (int i = 0; i < FOOTER_DSV.Length; i++)
|
||||
{
|
||||
if (FOOTER_DSV[i] != input[start + i])
|
||||
return;
|
||||
}
|
||||
|
||||
footer = GetSubsection(input, SIZE_G4RAW);
|
||||
input = GetSubsection(input, 0, SIZE_G4RAW);
|
||||
}
|
||||
else if (input.Length == SIZE_G3BOXGCI)
|
||||
{
|
||||
if (!IsGameMatchHeader(HEADER_RSBOX, input))
|
||||
return; // not gci
|
||||
header = input.Take(SIZE_G3BOXGCI - SIZE_G3BOX).ToArray();
|
||||
input = input.Skip(header.Length).ToArray();
|
||||
header = GetSubsection(input, 0, SIZE_G3BOXGCI - SIZE_G3BOX);
|
||||
input = GetSubsection(input, header.Length);
|
||||
}
|
||||
else if (input.Length == SIZE_G3COLOGCI)
|
||||
{
|
||||
if (!IsGameMatchHeader(HEADER_COLO, input))
|
||||
return; // not gci
|
||||
header = input.Take(SIZE_G3COLOGCI - SIZE_G3COLO).ToArray();
|
||||
input = input.Skip(header.Length).ToArray();
|
||||
header = GetSubsection(input, 0, SIZE_G3COLOGCI - SIZE_G3COLO);
|
||||
input = GetSubsection(input, header.Length);
|
||||
}
|
||||
else if (input.Length == SIZE_G3XDGCI)
|
||||
{
|
||||
if (!IsGameMatchHeader(HEADER_XD, input))
|
||||
return; // not gci
|
||||
header = input.Take(SIZE_G3XDGCI - SIZE_G3XD).ToArray();
|
||||
input = input.Skip(header.Length).ToArray();
|
||||
header = GetSubsection(input, 0, SIZE_G3XDGCI - SIZE_G3XD);
|
||||
input = GetSubsection(input, header.Length);
|
||||
}
|
||||
|
||||
byte[] GetSubsection(byte[] data, int start, int length = -1)
|
||||
{
|
||||
if (length < 0)
|
||||
length = data.Length - start;
|
||||
byte[] result = new byte[length];
|
||||
Buffer.BlockCopy(data, start, result, 0, length);
|
||||
return result;
|
||||
}
|
||||
bool IsGameMatchHeader(IEnumerable<string> headers, byte[] data) => headers.Contains(Encoding.ASCII.GetString(data, 0, 4));
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ namespace PKHeX.WinForms
|
|||
string fstr = Regex.Unescape(pkstr);
|
||||
byte[] raw = Encoding.Unicode.GetBytes(fstr);
|
||||
// Remove 00 interstitials and retrieve from offset 0x30, take PK7 Stored Size (always)
|
||||
return raw.ToList().Where((_, i) => i % 2 == 0).Skip(0x30).Take(0xE8).ToArray();
|
||||
return raw.Where((_, i) => i % 2 == 0).Skip(0x30).Take(0xE8).ToArray();
|
||||
}
|
||||
// All except G7
|
||||
pkstr = pkstr.Substring(pkstr.IndexOf("#", StringComparison.Ordinal) + 1); // Trim URL
|
||||
|
|
|
@ -89,11 +89,14 @@ namespace PKHeX.WinForms
|
|||
data = new byte[bmp.Width * bmp.Height * 4];
|
||||
}
|
||||
|
||||
public static Bitmap GetBitmap(byte[] data, int width, int height, int stride = -1, PixelFormat format = PixelFormat.Format32bppArgb)
|
||||
public static Bitmap GetBitmap(byte[] data, int width, int height, PixelFormat format = PixelFormat.Format32bppArgb)
|
||||
{
|
||||
if (stride == -1 && format == PixelFormat.Format32bppArgb)
|
||||
stride = 4 * width; // defaults
|
||||
return new Bitmap(width, height, stride, format, Marshal.UnsafeAddrOfPinnedArrayElement(data, 0));
|
||||
var bmp = new Bitmap(width, height, format);
|
||||
var bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, format);
|
||||
var ptr = bmpData.Scan0;
|
||||
Marshal.Copy(data, 0, ptr, data.Length);
|
||||
bmp.UnlockBits(bmpData);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
public static byte[] GetPixelData(Bitmap bitmap)
|
||||
|
|
Loading…
Add table
Reference in a new issue