2014-07-22 05:47:18 +00:00
|
|
|
|
using System;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
using System.Collections;
|
2014-10-11 07:22:22 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
2015-09-24 03:29:31 +00:00
|
|
|
|
using System.Drawing;
|
2015-09-21 03:34:09 +00:00
|
|
|
|
using System.IO;
|
2014-07-22 05:47:18 +00:00
|
|
|
|
using System.Linq;
|
2015-03-11 01:44:51 +00:00
|
|
|
|
using System.Reflection;
|
2014-07-22 05:47:18 +00:00
|
|
|
|
using System.Text;
|
2014-10-11 07:22:22 +00:00
|
|
|
|
using System.Windows.Forms;
|
2014-12-14 04:02:15 +00:00
|
|
|
|
|
2014-07-22 05:47:18 +00:00
|
|
|
|
namespace PKHeX
|
|
|
|
|
{
|
2014-10-11 07:22:22 +00:00
|
|
|
|
public partial class frmReport : Form
|
2014-07-22 05:47:18 +00:00
|
|
|
|
{
|
|
|
|
|
private byte[] SaveData;
|
2015-09-24 03:29:31 +00:00
|
|
|
|
|
|
|
|
|
public class Preview
|
|
|
|
|
{
|
2016-01-17 21:27:24 +00:00
|
|
|
|
private readonly PK6 pk6;
|
|
|
|
|
public string Position => pk6.Identifier;
|
|
|
|
|
public Image Sprite => pk6.Sprite;
|
|
|
|
|
public string Nickname => pk6.Nickname;
|
|
|
|
|
public string Species => Main.specieslist[pk6.Species];
|
|
|
|
|
public string Nature => Main.natures[pk6.Nature];
|
|
|
|
|
public string Gender => Main.gendersymbols[pk6.Gender];
|
|
|
|
|
public string ESV => pk6.PSV.ToString("0000");
|
2016-02-03 23:41:43 +00:00
|
|
|
|
public string HP_Type => Main.types[pk6.HPType+1];
|
2016-01-17 21:27:24 +00:00
|
|
|
|
public string Ability => Main.abilitylist[pk6.Ability];
|
|
|
|
|
public string Move1 => Main.movelist[pk6.Move1];
|
|
|
|
|
public string Move2 => Main.movelist[pk6.Move2];
|
|
|
|
|
public string Move3 => Main.movelist[pk6.Move3];
|
|
|
|
|
public string Move4 => Main.movelist[pk6.Move4];
|
|
|
|
|
public string HeldItem => Main.itemlist[pk6.HeldItem];
|
|
|
|
|
public string MetLoc => PKX.getLocation(false, pk6.Version, pk6.Met_Location);
|
|
|
|
|
public string EggLoc => PKX.getLocation(true, pk6.Version, pk6.Egg_Location);
|
|
|
|
|
public string Ball => Main.balllist[pk6.Ball];
|
|
|
|
|
public string OT => pk6.OT_Name;
|
|
|
|
|
public string Version => Main.gamelist[pk6.Version];
|
|
|
|
|
public string OTLang => Main.gamelanguages[pk6.Language] ?? $"UNK {pk6.Language}";
|
|
|
|
|
public string CountryID => pk6.Country.ToString();
|
|
|
|
|
public string RegionID => pk6.Region.ToString();
|
|
|
|
|
public string DSRegionID => pk6.ConsoleRegion.ToString();
|
2015-09-24 03:29:31 +00:00
|
|
|
|
|
|
|
|
|
#region Extraneous
|
2016-01-17 21:27:24 +00:00
|
|
|
|
public string EC => pk6.EncryptionConstant.ToString("X8");
|
|
|
|
|
public string PID => pk6.PID.ToString("X8");
|
|
|
|
|
public int HP_IV => pk6.IV_HP;
|
|
|
|
|
public int ATK_IV => pk6.IV_ATK;
|
|
|
|
|
public int DEF_IV => pk6.IV_DEF;
|
|
|
|
|
public int SPA_IV => pk6.IV_SPA;
|
|
|
|
|
public int SPD_IV => pk6.IV_SPD;
|
|
|
|
|
public int SPE_IV => pk6.IV_SPE;
|
|
|
|
|
public uint EXP => pk6.EXP;
|
2016-02-23 06:53:21 +00:00
|
|
|
|
public int Level => pk6.CurrentLevel;
|
2016-01-17 21:27:24 +00:00
|
|
|
|
public int HP_EV => pk6.EV_HP;
|
|
|
|
|
public int ATK_EV => pk6.EV_ATK;
|
|
|
|
|
public int DEF_EV => pk6.EV_DEF;
|
|
|
|
|
public int SPA_EV => pk6.EV_SPA;
|
|
|
|
|
public int SPD_EV => pk6.EV_SPD;
|
|
|
|
|
public int SPE_EV => pk6.EV_SPE;
|
|
|
|
|
public int Cool => pk6.CNT_Cool;
|
|
|
|
|
public int Beauty => pk6.CNT_Beauty;
|
|
|
|
|
public int Cute => pk6.CNT_Cute;
|
|
|
|
|
public int Smart => pk6.CNT_Smart;
|
|
|
|
|
public int Tough => pk6.CNT_Tough;
|
|
|
|
|
public int Sheen => pk6.CNT_Sheen;
|
|
|
|
|
public int Markings => pk6.Markings;
|
2015-09-24 03:29:31 +00:00
|
|
|
|
|
2016-01-17 21:27:24 +00:00
|
|
|
|
public string NotOT => pk6.HT_Name;
|
2015-09-24 03:29:31 +00:00
|
|
|
|
|
2016-01-17 21:27:24 +00:00
|
|
|
|
public int AbilityNum => pk6.AbilityNumber;
|
|
|
|
|
public int GenderFlag => pk6.Gender;
|
|
|
|
|
public int AltForms => pk6.AltForm;
|
|
|
|
|
public int PKRS_Strain => pk6.PKRS_Strain;
|
|
|
|
|
public int PKRS_Days => pk6.PKRS_Days;
|
|
|
|
|
public int MetLevel => pk6.Met_Level;
|
|
|
|
|
public int OT_Gender => pk6.OT_Gender;
|
2015-09-24 03:29:31 +00:00
|
|
|
|
|
2016-01-17 21:27:24 +00:00
|
|
|
|
public bool FatefulFlag => pk6.FatefulEncounter;
|
|
|
|
|
public bool IsEgg => pk6.IsEgg;
|
|
|
|
|
public bool IsNicknamed => pk6.IsNicknamed;
|
|
|
|
|
public bool IsShiny => pk6.IsShiny;
|
|
|
|
|
|
|
|
|
|
public int TID => pk6.TID;
|
|
|
|
|
public int SID => pk6.SID;
|
|
|
|
|
public int TSV => pk6.TSV;
|
|
|
|
|
public int Move1_PP => pk6.Move1_PP;
|
|
|
|
|
public int Move2_PP => pk6.Move2_PP;
|
|
|
|
|
public int Move3_PP => pk6.Move3_PP;
|
|
|
|
|
public int Move4_PP => pk6.Move4_PP;
|
|
|
|
|
public int Move1_PPUp => pk6.Move1_PPUps;
|
|
|
|
|
public int Move2_PPUp => pk6.Move2_PPUps;
|
|
|
|
|
public int Move3_PPUp => pk6.Move3_PPUps;
|
|
|
|
|
public int Move4_PPUp => pk6.Move4_PPUps;
|
|
|
|
|
public string Relearn1 => Main.movelist[pk6.RelearnMove1];
|
|
|
|
|
public string Relearn2 => Main.movelist[pk6.RelearnMove2];
|
|
|
|
|
public string Relearn3 => Main.movelist[pk6.RelearnMove3];
|
|
|
|
|
public string Relearn4 => Main.movelist[pk6.RelearnMove4];
|
|
|
|
|
public ushort Checksum => pk6.Checksum;
|
|
|
|
|
public int mFriendship => pk6.OT_Friendship;
|
|
|
|
|
public int OT_Affection => pk6.OT_Affection;
|
|
|
|
|
public int Egg_Year => pk6.Egg_Year;
|
|
|
|
|
public int Egg_Month => pk6.Egg_Month;
|
|
|
|
|
public int Egg_Day => pk6.Egg_Day;
|
|
|
|
|
public int Met_Year => pk6.Met_Year;
|
|
|
|
|
public int Met_Month => pk6.Met_Month;
|
|
|
|
|
public int Met_Day => pk6.Met_Day;
|
|
|
|
|
public int Encounter => pk6.EncounterType;
|
2015-09-24 03:29:31 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
public Preview(PK6 p) { pk6 = p; }
|
|
|
|
|
}
|
2014-10-11 07:22:22 +00:00
|
|
|
|
public frmReport()
|
2014-07-22 05:47:18 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2014-07-24 16:20:08 +00:00
|
|
|
|
dgData.DoubleBuffered(true);
|
2014-07-22 05:47:18 +00:00
|
|
|
|
}
|
2015-09-21 03:34:09 +00:00
|
|
|
|
public void PopulateData(byte[] InputData, int BoxDataOffset)
|
2014-07-22 05:47:18 +00:00
|
|
|
|
{
|
2015-09-21 03:34:09 +00:00
|
|
|
|
SaveData = (byte[])InputData.Clone();
|
2014-07-22 05:47:18 +00:00
|
|
|
|
PokemonList PL = new PokemonList();
|
2015-02-11 22:47:59 +00:00
|
|
|
|
BoxBar.Maximum = 930 + 100;
|
|
|
|
|
BoxBar.Step = 1;
|
2014-07-22 05:47:18 +00:00
|
|
|
|
for (int BoxNum = 0; BoxNum < 31; BoxNum++)
|
|
|
|
|
{
|
2016-01-18 01:07:19 +00:00
|
|
|
|
int boxoffset = BoxDataOffset + BoxNum*0xE8*30;
|
2014-07-22 05:47:18 +00:00
|
|
|
|
for (int SlotNum = 0; SlotNum < 30; SlotNum++)
|
|
|
|
|
{
|
2015-02-11 22:47:59 +00:00
|
|
|
|
BoxBar.PerformStep();
|
2014-07-22 05:47:18 +00:00
|
|
|
|
int offset = boxoffset + 0xE8 * SlotNum;
|
2014-12-12 05:45:01 +00:00
|
|
|
|
byte[] slotdata = new byte[0xE8];
|
2014-07-22 05:47:18 +00:00
|
|
|
|
Array.Copy(SaveData, offset, slotdata, 0, 0xE8);
|
2014-10-11 07:22:22 +00:00
|
|
|
|
byte[] dslotdata = PKX.decryptArray(slotdata);
|
2014-12-26 18:46:18 +00:00
|
|
|
|
if (BitConverter.ToUInt16(dslotdata, 0x8) == 0) continue;
|
2016-01-17 21:27:24 +00:00
|
|
|
|
string Identifier = $"B{(BoxNum + 1).ToString("00")}:{(SlotNum + 1).ToString("00")}";
|
2015-09-24 03:29:31 +00:00
|
|
|
|
PK6 pkm = new PK6(dslotdata, Identifier);
|
2016-01-24 18:19:30 +00:00
|
|
|
|
if (!pkm.ChecksumValid) continue;
|
2016-01-07 16:13:06 +00:00
|
|
|
|
pkm.Stat_Level = PKX.getLevel(pkm.Species, pkm.EXP); // recalc Level
|
2015-09-24 03:29:31 +00:00
|
|
|
|
PL.Add(new Preview(pkm));
|
2014-07-22 05:47:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
dgData.DataSource = PL;
|
|
|
|
|
dgData.AutoGenerateColumns = true;
|
2015-02-11 22:47:59 +00:00
|
|
|
|
BoxBar.Maximum = 930 + dgData.Columns.Count;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
for (int i = 0; i < dgData.Columns.Count; i++)
|
|
|
|
|
{
|
2015-02-11 22:47:59 +00:00
|
|
|
|
BoxBar.PerformStep();
|
2014-12-14 04:02:15 +00:00
|
|
|
|
if (dgData.Columns[i] is DataGridViewImageColumn) continue; // Don't add sorting for Sprites
|
2014-12-14 03:32:51 +00:00
|
|
|
|
dgData.Columns[i].SortMode = DataGridViewColumnSortMode.Automatic;
|
|
|
|
|
}
|
2015-02-11 22:47:59 +00:00
|
|
|
|
BoxBar.Visible = false;
|
2014-07-22 05:47:18 +00:00
|
|
|
|
}
|
2015-10-11 01:29:02 +00:00
|
|
|
|
public void PopulateData(PK6[] data)
|
|
|
|
|
{
|
|
|
|
|
BoxBar.Step = 1;
|
|
|
|
|
PokemonList PL = new PokemonList();
|
|
|
|
|
foreach (PK6 p in data)
|
|
|
|
|
PL.Add(new Preview(p));
|
|
|
|
|
|
|
|
|
|
dgData.DataSource = PL;
|
|
|
|
|
dgData.AutoGenerateColumns = true;
|
|
|
|
|
BoxBar.Maximum = data.Length + dgData.Columns.Count;
|
|
|
|
|
for (int i = 0; i < dgData.Columns.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
BoxBar.PerformStep();
|
|
|
|
|
if (dgData.Columns[i] is DataGridViewImageColumn) continue; // Don't add sorting for Sprites
|
|
|
|
|
dgData.Columns[i].SortMode = DataGridViewColumnSortMode.Automatic;
|
|
|
|
|
}
|
|
|
|
|
BoxBar.Visible = false;
|
|
|
|
|
}
|
2014-12-14 04:02:15 +00:00
|
|
|
|
private void promptSaveCSV(object sender, FormClosingEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (Util.Prompt(MessageBoxButtons.YesNo,"Save all the data to CSV?") == DialogResult.Yes)
|
|
|
|
|
{
|
2015-03-11 01:44:51 +00:00
|
|
|
|
SaveFileDialog savecsv = new SaveFileDialog
|
|
|
|
|
{
|
|
|
|
|
Filter = "Spreadsheet|*.csv",
|
|
|
|
|
FileName = "Box Data Dump.csv"
|
|
|
|
|
};
|
2014-12-14 04:02:15 +00:00
|
|
|
|
if (savecsv.ShowDialog() == DialogResult.OK)
|
|
|
|
|
Export_CSV(savecsv.FileName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void Export_CSV(string path)
|
|
|
|
|
{
|
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
var headers = dgData.Columns.Cast<DataGridViewColumn>();
|
|
|
|
|
sb.AppendLine(string.Join(",", headers.Select(column => "\"" + column.HeaderText + "\"").ToArray()));
|
|
|
|
|
|
|
|
|
|
foreach (DataGridViewRow row in dgData.Rows)
|
|
|
|
|
{
|
|
|
|
|
var cells = row.Cells.Cast<DataGridViewCell>();
|
|
|
|
|
sb.AppendLine(string.Join(",", cells.Select(cell => "\"" + cell.Value + "\"").ToArray()));
|
|
|
|
|
}
|
2015-09-21 03:34:09 +00:00
|
|
|
|
File.WriteAllText(path, sb.ToString(), Encoding.UTF8);
|
2014-12-14 04:02:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-24 03:29:31 +00:00
|
|
|
|
public class PokemonList : SortableBindingList<Preview> { }
|
2014-07-22 05:47:18 +00:00
|
|
|
|
}
|
2014-07-24 16:20:08 +00:00
|
|
|
|
public static class ExtensionMethods // Speed up scrolling
|
|
|
|
|
{
|
|
|
|
|
public static void DoubleBuffered(this DataGridView dgv, bool setting)
|
|
|
|
|
{
|
|
|
|
|
Type dgvType = dgv.GetType();
|
|
|
|
|
PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
|
|
|
|
|
pi.SetValue(dgv, setting, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-12-14 03:32:51 +00:00
|
|
|
|
public class SortableBindingList<T> : BindingList<T>
|
|
|
|
|
{
|
|
|
|
|
private readonly Dictionary<Type, PropertyComparer<T>> comparers;
|
|
|
|
|
private bool isSorted;
|
|
|
|
|
private ListSortDirection listSortDirection;
|
|
|
|
|
private PropertyDescriptor propertyDescriptor;
|
|
|
|
|
|
2015-03-11 01:44:51 +00:00
|
|
|
|
protected SortableBindingList()
|
2014-12-14 03:32:51 +00:00
|
|
|
|
: base(new List<T>())
|
|
|
|
|
{
|
2015-03-11 01:44:51 +00:00
|
|
|
|
comparers = new Dictionary<Type, PropertyComparer<T>>();
|
2014-12-14 03:32:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SortableBindingList(IEnumerable<T> enumeration)
|
|
|
|
|
: base(new List<T>(enumeration))
|
|
|
|
|
{
|
2015-03-11 01:44:51 +00:00
|
|
|
|
comparers = new Dictionary<Type, PropertyComparer<T>>();
|
2014-12-14 03:32:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-17 21:27:24 +00:00
|
|
|
|
protected override bool SupportsSortingCore => true;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
|
2016-01-17 21:27:24 +00:00
|
|
|
|
protected override bool IsSortedCore => isSorted;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
|
2016-01-17 21:27:24 +00:00
|
|
|
|
protected override PropertyDescriptor SortPropertyCore => propertyDescriptor;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
|
2016-01-17 21:27:24 +00:00
|
|
|
|
protected override ListSortDirection SortDirectionCore => listSortDirection;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
|
2016-01-17 21:27:24 +00:00
|
|
|
|
protected override bool SupportsSearchingCore => true;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
|
|
|
|
|
protected override void ApplySortCore(PropertyDescriptor property, ListSortDirection direction)
|
|
|
|
|
{
|
2015-03-11 01:44:51 +00:00
|
|
|
|
List<T> itemsList = (List<T>)Items;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
|
|
|
|
|
Type propertyType = property.PropertyType;
|
|
|
|
|
PropertyComparer<T> comparer;
|
2015-03-11 01:44:51 +00:00
|
|
|
|
if (!comparers.TryGetValue(propertyType, out comparer))
|
2014-12-14 03:32:51 +00:00
|
|
|
|
{
|
|
|
|
|
comparer = new PropertyComparer<T>(property, direction);
|
2015-03-11 01:44:51 +00:00
|
|
|
|
comparers.Add(propertyType, comparer);
|
2014-12-14 03:32:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
comparer.SetPropertyAndDirection(property, direction);
|
|
|
|
|
itemsList.Sort(comparer);
|
|
|
|
|
|
2015-03-11 01:44:51 +00:00
|
|
|
|
propertyDescriptor = property;
|
|
|
|
|
listSortDirection = direction;
|
|
|
|
|
isSorted = true;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
|
2015-03-11 01:44:51 +00:00
|
|
|
|
OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
|
2014-12-14 03:32:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void RemoveSortCore()
|
|
|
|
|
{
|
2015-03-11 01:44:51 +00:00
|
|
|
|
isSorted = false;
|
|
|
|
|
propertyDescriptor = base.SortPropertyCore;
|
|
|
|
|
listSortDirection = base.SortDirectionCore;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
|
2015-03-11 01:44:51 +00:00
|
|
|
|
OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
|
2014-12-14 03:32:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override int FindCore(PropertyDescriptor property, object key)
|
|
|
|
|
{
|
2015-03-11 01:44:51 +00:00
|
|
|
|
int count = Count;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
for (int i = 0; i < count; ++i)
|
|
|
|
|
{
|
|
|
|
|
T element = this[i];
|
|
|
|
|
if (property.GetValue(element).Equals(key))
|
|
|
|
|
{
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public class PropertyComparer<T> : IComparer<T>
|
|
|
|
|
{
|
|
|
|
|
private readonly IComparer comparer;
|
|
|
|
|
private PropertyDescriptor propertyDescriptor;
|
|
|
|
|
private int reverse;
|
|
|
|
|
|
|
|
|
|
public PropertyComparer(PropertyDescriptor property, ListSortDirection direction)
|
|
|
|
|
{
|
2015-03-11 01:44:51 +00:00
|
|
|
|
propertyDescriptor = property;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
Type comparerForPropertyType = typeof(Comparer<>).MakeGenericType(property.PropertyType);
|
2015-03-11 01:44:51 +00:00
|
|
|
|
comparer = (IComparer)comparerForPropertyType.InvokeMember("Default", BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.Public, null, null, null);
|
|
|
|
|
SetListSortDirection(direction);
|
2014-12-14 03:32:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region IComparer<T> Members
|
|
|
|
|
|
|
|
|
|
public int Compare(T x, T y)
|
|
|
|
|
{
|
2015-03-11 01:44:51 +00:00
|
|
|
|
return reverse * comparer.Compare(propertyDescriptor.GetValue(x), propertyDescriptor.GetValue(y));
|
2014-12-14 03:32:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
private void SetPropertyDescriptor(PropertyDescriptor descriptor)
|
|
|
|
|
{
|
2015-03-11 01:44:51 +00:00
|
|
|
|
propertyDescriptor = descriptor;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetListSortDirection(ListSortDirection direction)
|
|
|
|
|
{
|
2015-03-11 01:44:51 +00:00
|
|
|
|
reverse = direction == ListSortDirection.Ascending ? 1 : -1;
|
2014-12-14 03:32:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetPropertyAndDirection(PropertyDescriptor descriptor, ListSortDirection direction)
|
|
|
|
|
{
|
2015-03-11 01:44:51 +00:00
|
|
|
|
SetPropertyDescriptor(descriptor);
|
|
|
|
|
SetListSortDirection(direction);
|
2014-12-14 03:32:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-10-11 07:22:22 +00:00
|
|
|
|
}
|