Refactoring

Pre 3-5 moving of useful arrays
Reduce footprint of unpackMini (was taking 88ms, now <1us)
This commit is contained in:
Kurt 2017-03-16 23:16:11 -07:00
parent e6b2da51db
commit 17b87f568e
7 changed files with 27 additions and 44 deletions

View file

@ -871,7 +871,7 @@ namespace PKHeX.Core
result[0] = "Missing Ribbons: " + string.Join(", ", missingRibbons);
if (invalidRibbons.Count > 0)
result[1] = "Invalid Ribbons: " + string.Join(", ", invalidRibbons);
AddLine(Severity.Invalid, string.Join(Environment.NewLine, result.Where(s=>!string.IsNullOrEmpty(s))), CheckIdentifier.Ribbon);
AddLine(Severity.Invalid, string.Join(Environment.NewLine, result.Where(s => !string.IsNullOrEmpty(s))), CheckIdentifier.Ribbon);
}
private void verifyAbility()
{
@ -2143,7 +2143,7 @@ namespace PKHeX.Core
else
reqBase = baseCt;
if (pkm.RelearnMoves.Where(m=>m != 0).Count() < Math.Min(4, baseMoves.Count))
if (pkm.RelearnMoves.Where(m => m != 0).Count() < Math.Min(4, baseMoves.Count))
reqBase = Math.Min(4, unique);
// Movepool finalized! Check validity.

View file

@ -1,5 +1,4 @@
using System;
using System.IO;
namespace PKHeX.Core
{
@ -10,41 +9,22 @@ namespace PKHeX.Core
if (fileData == null || fileData.Length < 4)
return null;
using (var s = new MemoryStream(fileData))
using (var br = new BinaryReader(s))
if (identifier[0] != fileData[0] || identifier[1] != fileData[1])
return null;
int count = BitConverter.ToUInt16(fileData, 2); int ctr = 4;
int start = BitConverter.ToInt32(fileData, ctr); ctr += 4;
byte[][] returnData = new byte[count][];
for (int i = 0; i < count; i++)
{
if (identifier != new string(br.ReadChars(2)))
return null;
ushort count = br.ReadUInt16();
byte[][] returnData = new byte[count][];
uint[] offsets = new uint[count + 1];
for (int i = 0; i < count; i++)
offsets[i] = br.ReadUInt32();
uint length = br.ReadUInt32();
offsets[offsets.Length - 1] = length;
for (int i = 0; i < count; i++)
{
br.BaseStream.Seek(offsets[i], SeekOrigin.Begin);
using (MemoryStream dataout = new MemoryStream())
{
byte[] data = new byte[0];
s.CopyTo(dataout, (int)offsets[i]);
int len = (int)offsets[i + 1] - (int)offsets[i];
if (len != 0)
{
data = dataout.ToArray();
Array.Resize(ref data, len);
}
returnData[i] = data;
}
}
return returnData;
int end = BitConverter.ToInt32(fileData, ctr); ctr += 4;
int len = end - start;
byte[] data = new byte[len];
Buffer.BlockCopy(fileData, start, data, 0, len);
returnData[i] = data;
start = end;
}
return returnData;
}
}
}

View file

@ -183,7 +183,7 @@ namespace PKHeX.Core
internal static readonly int[] FutureEvolutionsGen1_Gen2LevelUp =
{
169,196,197,242
169,196,197,242
};
//Crobat Espeon Umbreon Blissey
}

View file

@ -99,5 +99,6 @@ namespace PKHeX.Core
// todo
};
internal static readonly bool[] ReleasedHeldItems_3 = Enumerable.Range(0, MaxItemID_3+1).Select(i => HeldItems_RS.Contains((ushort)i) && !UnreleasedItems_3.Contains(i)).ToArray();
internal static readonly int[] HM_3 = {15, 19, 57, 70, 148, 249, 127, 291};
}
}

View file

@ -140,5 +140,6 @@ namespace PKHeX.Core
// todo
};
internal static readonly bool[] ReleasedHeldItems_4 = Enumerable.Range(0, MaxItemID_4_HGSS+1).Select(i => HeldItems_HGSS.Contains((ushort)i) && !UnreleasedItems_4.Contains(i)).ToArray();
internal static readonly int[] CrownBeasts = {251, 243, 244, 245};
}
}

View file

@ -298,10 +298,9 @@ namespace PKHeX.Core
}
// Remove HM moves
int[] banned = { 15, 19, 57, 70, 148, 249, 127, 291 };
int[] newMoves = pk4.Moves;
for (int i = 0; i < 4; i++)
if (banned.Contains(newMoves[i]))
if (Legal.HM_3.Contains(newMoves[i]))
newMoves[i] = 0;
pk4.Moves = newMoves;
pk4.FixMoves();

View file

@ -443,8 +443,6 @@ namespace PKHeX.Core
// Apply new met date
MetDate = moment
};
if (Legal.HeldItems_BW.Contains((ushort) HeldItem))
pk5.HeldItem = HeldItem;
// Arceus Type Changing -- Plate forcibly removed.
if (pk5.Species == 493)
@ -452,6 +450,10 @@ namespace PKHeX.Core
pk5.AltForm = 0;
pk5.HeldItem = 0;
}
else
{
pk5.HeldItem = Legal.HeldItems_BW.Contains((ushort) HeldItem) ? HeldItem : 0;
}
// Fix PP
pk5.Move1_PP = pk5.getMovePP(pk5.Move1, pk5.Move1_PPUps);
@ -459,14 +461,14 @@ namespace PKHeX.Core
pk5.Move3_PP = pk5.getMovePP(pk5.Move3, pk5.Move3_PPUps);
pk5.Move4_PP = pk5.getMovePP(pk5.Move4, pk5.Move4_PPUps);
// Disassociate Nature and PID
pk5.Nature = (int)(pk5.PID % 25);
// Disassociate Nature and PID, pk4 getter does PID%25
pk5.Nature = Nature;
// Delete Platinum/HGSS Met Location Data
BitConverter.GetBytes((uint)0).CopyTo(pk5.Data, 0x44);
// Met / Crown Data Detection
pk5.Met_Location = pk5.Gen4 && pk5.FatefulEncounter && Array.IndexOf(new[] {251, 243, 244, 245}, pk5.Species) >= 0
pk5.Met_Location = pk5.Gen4 && pk5.FatefulEncounter && Array.IndexOf(Legal.CrownBeasts, pk5.Species) >= 0
? (pk5.Species == 251 ? 30010 : 30012) // Celebi : Beast
: 30001; // Pokétransfer (not Crown)