mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-10 22:54:14 +00:00
Misc updates
Re-enable PKM (abstract class) property searching via Database/MGDB search Closes #1412 (can now search or exclude certain formats) Add auto-detection for all supported saves (rather than gen3+ except GC/PBR)
This commit is contained in:
parent
4f7c19d0cd
commit
ccc6357294
3 changed files with 76 additions and 80 deletions
|
@ -35,6 +35,16 @@ namespace PKHeX.Core
|
|||
public const int SIZE_G2BAT_J = 0x1002C;
|
||||
public const int SIZE_G1RAW = 0x8000;
|
||||
public const int SIZE_G1BAT = 0x802C;
|
||||
private static readonly HashSet<int> SIZES = new HashSet<int>
|
||||
{
|
||||
SIZE_G7SM,
|
||||
SIZE_G6XY, SIZE_G6ORAS, SIZE_G6ORASDEMO,
|
||||
SIZE_G5RAW, SIZE_G5BW, SIZE_G5B2W2,
|
||||
SIZE_G4BR, SIZE_G4RAW,
|
||||
SIZE_G3BOX, SIZE_G3BOXGCI, SIZE_G3COLO, SIZE_G3COLOGCI, SIZE_G3XD, SIZE_G3XDGCI, SIZE_G3RAW, SIZE_G3RAWHALF,
|
||||
SIZE_G2RAW_U, SIZE_G2VC, SIZE_G2BAT_U, SIZE_G2EMU, SIZE_G2RAW_J, SIZE_G2BAT_J,
|
||||
SIZE_G1RAW, SIZE_G1BAT
|
||||
};
|
||||
|
||||
public static readonly byte[] FOOTER_DSV = Encoding.ASCII.GetBytes("|-DESMUME SAVE-|");
|
||||
public static readonly string[] HEADER_COLO = { "GC6J","GC6E","GC6P" }; // NTSC-J, NTSC-U, PAL
|
||||
|
@ -568,25 +578,7 @@ namespace PKHeX.Core
|
|||
/// </summary>
|
||||
/// <param name="size">Size in bytes of the save data</param>
|
||||
/// <returns>A boolean indicating whether or not the save data size is valid.</returns>
|
||||
private static bool IsSizeValid(int size)
|
||||
{
|
||||
switch (size)
|
||||
{
|
||||
case SIZE_G3RAW:
|
||||
case SIZE_G3RAWHALF:
|
||||
|
||||
case SIZE_G4RAW: // Gen4/5
|
||||
|
||||
case SIZE_G6XY:
|
||||
case SIZE_G6ORASDEMO:
|
||||
case SIZE_G6ORAS:
|
||||
|
||||
case SIZE_G7SM:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private static bool IsSizeValid(int size) => SIZES.Contains(size);
|
||||
|
||||
// SAV Manipulation
|
||||
/// <summary>Calculates the CRC16-CCITT checksum over an input byte array.</summary>
|
||||
|
|
|
@ -471,65 +471,12 @@ namespace PKHeX.WinForms
|
|||
res = res.Where(pk => pk.PSV == Convert.ToInt16(MT_ESV.Text));
|
||||
|
||||
// Tertiary Searchables
|
||||
if (TB_Level.Text != "") // Level
|
||||
{
|
||||
int level = Convert.ToInt16(TB_Level.Text);
|
||||
if (level <= 100)
|
||||
switch (CB_Level.SelectedIndex)
|
||||
{
|
||||
case 0: break; // Any
|
||||
case 1: // <=
|
||||
res = res.Where(pk => pk.Stat_Level <= level);
|
||||
break;
|
||||
case 2: // ==
|
||||
res = res.Where(pk => pk.Stat_Level == level);
|
||||
break;
|
||||
case 3: // >=
|
||||
res = res.Where(pk => pk.Stat_Level >= level);
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch (CB_IV.SelectedIndex)
|
||||
{
|
||||
case 0: break; // Do nothing
|
||||
case 1: // <= 90
|
||||
res = res.Where(pk => pk.IVs.Sum() <= 90);
|
||||
break;
|
||||
case 2: // 91-120
|
||||
res = res.Where(pk => pk.IVs.Sum() > 90 && pk.IVs.Sum() <= 120);
|
||||
break;
|
||||
case 3: // 121-150
|
||||
res = res.Where(pk => pk.IVs.Sum() > 120 && pk.IVs.Sum() <= 150);
|
||||
break;
|
||||
case 4: // 151-179
|
||||
res = res.Where(pk => pk.IVs.Sum() > 150 && pk.IVs.Sum() < 180);
|
||||
break;
|
||||
case 5: // 180+
|
||||
res = res.Where(pk => pk.IVs.Sum() >= 180);
|
||||
break;
|
||||
case 6: // == 186
|
||||
res = res.Where(pk => pk.IVs.Sum() == 186);
|
||||
break;
|
||||
}
|
||||
switch (CB_EVTrain.SelectedIndex)
|
||||
{
|
||||
case 0: break; // Do nothing
|
||||
case 1: // None (0)
|
||||
res = res.Where(pk => pk.EVs.Sum() == 0);
|
||||
break;
|
||||
case 2: // Some (127-0)
|
||||
res = res.Where(pk => pk.EVs.Sum() < 128);
|
||||
break;
|
||||
case 3: // Half (128-507)
|
||||
res = res.Where(pk => pk.EVs.Sum() >= 128 && pk.EVs.Sum() < 508);
|
||||
break;
|
||||
case 4: // Full (508+)
|
||||
res = res.Where(pk => pk.EVs.Sum() >= 508);
|
||||
break;
|
||||
}
|
||||
res = FilterByLVL(res, CB_Level.SelectedIndex, TB_Level.Text);
|
||||
res = FilterByIVs(res, CB_IV.SelectedIndex);
|
||||
res = FilterByEVs(res, CB_EVTrain.SelectedIndex);
|
||||
|
||||
slotSelected = -1; // reset the slot last viewed
|
||||
|
||||
|
||||
if (Menu_SearchLegal.Checked && !Menu_SearchIllegal.Checked)
|
||||
res = res.Where(pk => new LegalityAnalysis(pk).ParsedValid);
|
||||
if (!Menu_SearchLegal.Checked && Menu_SearchIllegal.Checked)
|
||||
|
@ -547,7 +494,7 @@ namespace PKHeX.WinForms
|
|||
return pkm.Identifier.Contains(cmd.PropertyValue);
|
||||
if (!pkm.GetType().HasPropertyAll(cmd.PropertyName))
|
||||
return false;
|
||||
try { if (ReflectUtil.IsValueEqual(pkm, cmd.PropertyName, cmd.PropertyValue) == cmd.Evaluator) continue; }
|
||||
try { if (pkm.GetType().IsValueEqual(pkm, cmd.PropertyName, cmd.PropertyValue) == cmd.Evaluator) continue; }
|
||||
catch { Debug.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}."); }
|
||||
return false;
|
||||
}
|
||||
|
@ -560,6 +507,64 @@ namespace PKHeX.WinForms
|
|||
|
||||
return res;
|
||||
}
|
||||
private static IEnumerable<PKM> FilterByLVL(IEnumerable<PKM> res, int option, string lvl)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(lvl))
|
||||
return res;
|
||||
if (!int.TryParse(lvl, out int level))
|
||||
return res;
|
||||
if (level > 100)
|
||||
return res;
|
||||
|
||||
switch (option)
|
||||
{
|
||||
case 0: break; // Any (Do nothing)
|
||||
case 1: // <=
|
||||
return res.Where(pk => pk.Stat_Level <= level);
|
||||
case 2: // ==
|
||||
return res.Where(pk => pk.Stat_Level == level);
|
||||
case 3: // >=
|
||||
return res.Where(pk => pk.Stat_Level >= level);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
private static IEnumerable<PKM> FilterByEVs(IEnumerable<PKM> res, int option)
|
||||
{
|
||||
switch (option)
|
||||
{
|
||||
case 0: break; // Any (Do nothing)
|
||||
case 1: // None (0)
|
||||
return res.Where(pk => pk.EVs.Sum() == 0);
|
||||
case 2: // Some (127-0)
|
||||
return res.Where(pk => pk.EVs.Sum() < 128);
|
||||
case 3: // Half (128-507)
|
||||
return res.Where(pk => pk.EVs.Sum() >= 128 && pk.EVs.Sum() < 508);
|
||||
case 4: // Full (508+)
|
||||
return res.Where(pk => pk.EVs.Sum() >= 508);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
private static IEnumerable<PKM> FilterByIVs(IEnumerable<PKM> res, int option)
|
||||
{
|
||||
switch (option)
|
||||
{
|
||||
case 0: break; // Do nothing
|
||||
case 1: // <= 90
|
||||
return res.Where(pk => pk.IVs.Sum() <= 90);
|
||||
case 2: // 91-120
|
||||
return res.Where(pk => pk.IVs.Sum() > 90 && pk.IVs.Sum() <= 120);
|
||||
case 3: // 121-150
|
||||
return res.Where(pk => pk.IVs.Sum() > 120 && pk.IVs.Sum() <= 150);
|
||||
case 4: // 151-179
|
||||
return res.Where(pk => pk.IVs.Sum() > 150 && pk.IVs.Sum() < 180);
|
||||
case 5: // 180+
|
||||
return res.Where(pk => pk.IVs.Sum() >= 180);
|
||||
case 6: // == 186
|
||||
return res.Where(pk => pk.IVs.Sum() == 186);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private async void B_Search_Click(object sender, EventArgs e)
|
||||
{
|
||||
B_Search.Enabled = false;
|
||||
|
|
|
@ -303,7 +303,7 @@ namespace PKHeX.WinForms
|
|||
{
|
||||
if (!gift.GetType().HasPropertyAll(cmd.PropertyName))
|
||||
return false;
|
||||
try { if (ReflectUtil.IsValueEqual(gift, cmd.PropertyName, cmd.PropertyValue) == cmd.Evaluator) continue; }
|
||||
try { if (gift.GetType().IsValueEqual(gift, cmd.PropertyName, cmd.PropertyValue) == cmd.Evaluator) continue; }
|
||||
catch { Debug.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}."); }
|
||||
return false;
|
||||
}
|
||||
|
@ -313,9 +313,8 @@ namespace PKHeX.WinForms
|
|||
|
||||
var results = res.ToArray();
|
||||
if (results.Length == 0)
|
||||
{
|
||||
WinFormsUtil.Alert("No results found!");
|
||||
}
|
||||
|
||||
SetResults(new List<MysteryGift>(results)); // updates Count Label as well.
|
||||
System.Media.SystemSounds.Asterisk.Play();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue