2016-07-13 05:19:51 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
2016-09-16 03:54:41 +00:00
|
|
|
|
using System.Globalization;
|
2016-07-13 05:19:51 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
2017-01-08 07:54:09 +00:00
|
|
|
|
using PKHeX.Core;
|
2016-07-13 05:19:51 +00:00
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.WinForms
|
2016-07-13 05:19:51 +00:00
|
|
|
|
{
|
|
|
|
|
public partial class BatchEditor : Form
|
|
|
|
|
{
|
2017-01-09 05:06:15 +00:00
|
|
|
|
public BatchEditor(PKM pk)
|
2016-07-13 05:19:51 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2017-01-09 05:06:15 +00:00
|
|
|
|
pkm = pk;
|
2016-07-13 05:19:51 +00:00
|
|
|
|
DragDrop += tabMain_DragDrop;
|
|
|
|
|
DragEnter += tabMain_DragEnter;
|
2016-12-07 05:36:31 +00:00
|
|
|
|
|
|
|
|
|
CB_Format.Items.Clear();
|
|
|
|
|
CB_Format.Items.Add("All");
|
|
|
|
|
foreach (Type t in types) CB_Format.Items.Add(t.Name.ToLower());
|
|
|
|
|
CB_Format.Items.Add("Any");
|
|
|
|
|
|
2016-07-18 00:06:50 +00:00
|
|
|
|
CB_Format.SelectedIndex = CB_Require.SelectedIndex = 0;
|
2017-01-09 05:06:15 +00:00
|
|
|
|
new ToolTip().SetToolTip(CB_Property, "Property of a given PKM to modify.");
|
|
|
|
|
new ToolTip().SetToolTip(L_PropType, "PropertyType of the currently loaded PKM in the main window.");
|
|
|
|
|
new ToolTip().SetToolTip(L_PropValue, "PropertyValue of the currently loaded PKM in the main window.");
|
2016-07-13 05:19:51 +00:00
|
|
|
|
}
|
2016-12-07 05:36:31 +00:00
|
|
|
|
private static string[][] getPropArray()
|
|
|
|
|
{
|
|
|
|
|
var p = new string[types.Length][];
|
|
|
|
|
for (int i = 0; i < p.Length; i++)
|
|
|
|
|
p[i] = ReflectUtil.getPropertiesCanWritePublic(types[i]).ToArray();
|
|
|
|
|
|
|
|
|
|
IEnumerable<string> all = p.SelectMany(prop => prop).Distinct();
|
|
|
|
|
IEnumerable<string> any = p[0];
|
|
|
|
|
for (int i = 1; i < p.Length; i++)
|
|
|
|
|
any = any.Union(p[i]);
|
|
|
|
|
|
|
|
|
|
var p1 = new string[types.Length + 2][];
|
|
|
|
|
Array.Copy(p, 0, p1, 1, p.Length);
|
|
|
|
|
p1[0] = all.ToArray();
|
|
|
|
|
p1[p1.Length-1] = any.ToArray();
|
|
|
|
|
|
|
|
|
|
return p1;
|
|
|
|
|
}
|
2016-07-13 05:19:51 +00:00
|
|
|
|
|
2017-01-09 05:06:15 +00:00
|
|
|
|
private readonly PKM pkm;
|
2016-07-23 18:44:37 +00:00
|
|
|
|
private const string CONST_RAND = "$rand";
|
2016-07-29 06:05:26 +00:00
|
|
|
|
private const string CONST_SHINY = "$shiny";
|
2016-07-18 00:06:50 +00:00
|
|
|
|
private int currentFormat = -1;
|
2016-12-07 05:36:31 +00:00
|
|
|
|
private static readonly Type[] types = {typeof (PK7), typeof (PK6), typeof (PK5), typeof (PK4), typeof (PK3)};
|
|
|
|
|
private static readonly string[][] properties = getPropArray();
|
2016-07-18 00:06:50 +00:00
|
|
|
|
|
2016-07-13 05:19:51 +00:00
|
|
|
|
// GUI Methods
|
|
|
|
|
private void B_Open_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!B_Go.Enabled) return;
|
|
|
|
|
var fbd = new FolderBrowserDialog();
|
|
|
|
|
if (fbd.ShowDialog() != DialogResult.OK)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
TB_Folder.Text = fbd.SelectedPath;
|
|
|
|
|
TB_Folder.Visible = true;
|
|
|
|
|
}
|
|
|
|
|
private void B_SAV_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
TB_Folder.Text = "";
|
|
|
|
|
TB_Folder.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
private void B_Go_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (b.IsBusy)
|
2017-01-08 07:54:09 +00:00
|
|
|
|
{ WinFormsUtil.Alert("Currently executing instruction list."); return; }
|
2016-07-13 05:19:51 +00:00
|
|
|
|
|
|
|
|
|
if (RTB_Instructions.Lines.Any(line => line.Length == 0))
|
2017-01-08 07:54:09 +00:00
|
|
|
|
{ WinFormsUtil.Error("Line length error in instruction list."); return; }
|
2016-07-13 05:19:51 +00:00
|
|
|
|
|
|
|
|
|
runBackgroundWorker();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private BackgroundWorker b = new BackgroundWorker { WorkerReportsProgress = true };
|
|
|
|
|
private void runBackgroundWorker()
|
|
|
|
|
{
|
|
|
|
|
var Filters = getFilters().ToList();
|
2016-07-21 05:43:26 +00:00
|
|
|
|
if (Filters.Any(z => string.IsNullOrWhiteSpace(z.PropertyValue)))
|
2017-01-08 07:54:09 +00:00
|
|
|
|
{ WinFormsUtil.Error("Empty Filter Value detected."); return; }
|
2016-07-21 05:43:26 +00:00
|
|
|
|
|
2016-07-13 05:19:51 +00:00
|
|
|
|
var Instructions = getInstructions().ToList();
|
2016-11-27 21:32:32 +00:00
|
|
|
|
var emptyVal = Instructions.Where(z => string.IsNullOrWhiteSpace(z.PropertyValue)).ToArray();
|
|
|
|
|
if (emptyVal.Any())
|
|
|
|
|
{
|
|
|
|
|
string props = string.Join(", ", emptyVal.Select(z => z.PropertyName));
|
2017-01-08 07:54:09 +00:00
|
|
|
|
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo,
|
2016-11-27 21:32:32 +00:00
|
|
|
|
$"Empty Property Value{(emptyVal.Length > 1 ? "s" : "")} detected:" + Environment.NewLine + props,
|
|
|
|
|
"Continue?"))
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-07-21 05:43:26 +00:00
|
|
|
|
|
2016-07-31 06:03:41 +00:00
|
|
|
|
string destPath = "";
|
|
|
|
|
if (RB_Path.Checked)
|
|
|
|
|
{
|
2017-01-08 07:54:09 +00:00
|
|
|
|
WinFormsUtil.Alert("Please select the folder where the files will be saved to.", "This can be the same folder as the source of PKM files.");
|
2016-07-31 06:03:41 +00:00
|
|
|
|
var fbd = new FolderBrowserDialog();
|
|
|
|
|
var dr = fbd.ShowDialog();
|
|
|
|
|
if (dr != DialogResult.OK)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
destPath = fbd.SelectedPath;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-21 05:43:26 +00:00
|
|
|
|
FLP_RB.Enabled = RTB_Instructions.Enabled = B_Go.Enabled = false;
|
|
|
|
|
|
2016-07-13 05:19:51 +00:00
|
|
|
|
b = new BackgroundWorker {WorkerReportsProgress = true};
|
2016-11-15 03:04:08 +00:00
|
|
|
|
screenStrings(Filters);
|
|
|
|
|
screenStrings(Instructions);
|
2016-07-13 05:19:51 +00:00
|
|
|
|
|
|
|
|
|
b.DoWork += (sender, e) => {
|
|
|
|
|
if (RB_SAV.Checked)
|
|
|
|
|
{
|
|
|
|
|
var data = Main.SAV.BoxData;
|
|
|
|
|
setupProgressBar(data.Length);
|
|
|
|
|
processSAV(data, Filters, Instructions);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var files = Directory.GetFiles(TB_Folder.Text, "*", SearchOption.AllDirectories);
|
|
|
|
|
setupProgressBar(files.Length);
|
2016-07-31 06:03:41 +00:00
|
|
|
|
processFolder(files, Filters, Instructions, destPath);
|
2016-07-13 05:19:51 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
b.ProgressChanged += (sender, e) =>
|
|
|
|
|
{
|
|
|
|
|
setProgressBar(e.ProgressPercentage);
|
|
|
|
|
};
|
|
|
|
|
b.RunWorkerCompleted += (sender, e) => {
|
2016-07-22 05:45:20 +00:00
|
|
|
|
string result = $"Modified {ctr}/{len} files.";
|
|
|
|
|
if (err > 0)
|
|
|
|
|
result += Environment.NewLine + $"{err} files ignored due to an internal error.";
|
2017-01-08 07:54:09 +00:00
|
|
|
|
WinFormsUtil.Alert(result);
|
2016-07-13 05:19:51 +00:00
|
|
|
|
FLP_RB.Enabled = RTB_Instructions.Enabled = B_Go.Enabled = true;
|
|
|
|
|
setupProgressBar(0);
|
|
|
|
|
};
|
|
|
|
|
b.RunWorkerAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Progress Bar
|
|
|
|
|
private void setupProgressBar(int count)
|
|
|
|
|
{
|
|
|
|
|
MethodInvoker mi = () => { PB_Show.Minimum = 0; PB_Show.Step = 1; PB_Show.Value = 0; PB_Show.Maximum = count; };
|
|
|
|
|
if (PB_Show.InvokeRequired)
|
|
|
|
|
PB_Show.Invoke(mi);
|
|
|
|
|
else
|
|
|
|
|
mi.Invoke();
|
|
|
|
|
}
|
|
|
|
|
private void setProgressBar(int i)
|
|
|
|
|
{
|
|
|
|
|
if (PB_Show.InvokeRequired)
|
|
|
|
|
PB_Show.Invoke((MethodInvoker)(() => PB_Show.Value = i));
|
|
|
|
|
else { PB_Show.Value = i; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mass Editing
|
2016-07-22 05:45:20 +00:00
|
|
|
|
private int ctr, len, err;
|
2016-07-13 05:19:51 +00:00
|
|
|
|
private IEnumerable<StringInstruction> getFilters()
|
|
|
|
|
{
|
|
|
|
|
var raw =
|
|
|
|
|
RTB_Instructions.Lines
|
|
|
|
|
.Where(line => !string.IsNullOrWhiteSpace(line))
|
|
|
|
|
.Where(line => new[] {'!','='}.Contains(line[0]));
|
|
|
|
|
|
|
|
|
|
return from line in raw
|
|
|
|
|
let eval = line[0] == '='
|
|
|
|
|
let split = line.Substring(1).Split('=')
|
|
|
|
|
where split.Length == 2 && !string.IsNullOrWhiteSpace(split[0])
|
|
|
|
|
select new StringInstruction {PropertyName = split[0], PropertyValue = split[1], Evaluator = eval};
|
|
|
|
|
}
|
|
|
|
|
private IEnumerable<StringInstruction> getInstructions()
|
|
|
|
|
{
|
|
|
|
|
var raw =
|
|
|
|
|
RTB_Instructions.Lines
|
|
|
|
|
.Where(line => !string.IsNullOrEmpty(line))
|
|
|
|
|
.Where(line => new[] {'.'}.Contains(line[0]))
|
|
|
|
|
.Select(line => line.Substring(1));
|
|
|
|
|
|
|
|
|
|
return from line in raw
|
|
|
|
|
select line.Split('=') into split
|
|
|
|
|
where split.Length == 2
|
|
|
|
|
select new StringInstruction { PropertyName = split[0], PropertyValue = split[1] };
|
|
|
|
|
}
|
|
|
|
|
private void processSAV(PKM[] data, List<StringInstruction> Filters, List<StringInstruction> Instructions)
|
|
|
|
|
{
|
2016-07-22 05:45:20 +00:00
|
|
|
|
len = err = ctr = 0;
|
2016-07-13 05:19:51 +00:00
|
|
|
|
for (int i = 0; i < data.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
var pkm = data[i];
|
2016-12-16 17:03:36 +00:00
|
|
|
|
if (!pkm.Valid || pkm.Locked)
|
2016-10-12 02:23:04 +00:00
|
|
|
|
{
|
|
|
|
|
b.ReportProgress(i);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-21 05:43:26 +00:00
|
|
|
|
ModifyResult r = ProcessPKM(pkm, Filters, Instructions);
|
|
|
|
|
if (r != ModifyResult.Invalid)
|
|
|
|
|
len++;
|
|
|
|
|
if (r == ModifyResult.Error)
|
|
|
|
|
err++;
|
|
|
|
|
if (r == ModifyResult.Modified)
|
2016-10-12 02:23:04 +00:00
|
|
|
|
{
|
|
|
|
|
if (pkm.Species != 0)
|
|
|
|
|
pkm.RefreshChecksum();
|
2016-07-13 05:19:51 +00:00
|
|
|
|
ctr++;
|
2016-10-12 02:23:04 +00:00
|
|
|
|
}
|
2016-07-21 05:43:26 +00:00
|
|
|
|
|
2016-07-13 05:19:51 +00:00
|
|
|
|
b.ReportProgress(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Main.SAV.BoxData = data;
|
|
|
|
|
}
|
2016-07-31 06:03:41 +00:00
|
|
|
|
private void processFolder(string[] files, List<StringInstruction> Filters, List<StringInstruction> Instructions, string destPath)
|
2016-07-13 05:19:51 +00:00
|
|
|
|
{
|
2016-07-22 05:45:20 +00:00
|
|
|
|
len = err = ctr = 0;
|
2016-07-13 05:19:51 +00:00
|
|
|
|
for (int i = 0; i < files.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
string file = files[i];
|
|
|
|
|
if (!PKX.getIsPKM(new FileInfo(file).Length))
|
|
|
|
|
{
|
|
|
|
|
b.ReportProgress(i);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
byte[] data = File.ReadAllBytes(file);
|
|
|
|
|
var pkm = PKMConverter.getPKMfromBytes(data);
|
2016-10-12 02:23:04 +00:00
|
|
|
|
|
|
|
|
|
if (!pkm.Valid)
|
|
|
|
|
{
|
|
|
|
|
b.ReportProgress(i);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-21 05:43:26 +00:00
|
|
|
|
ModifyResult r = ProcessPKM(pkm, Filters, Instructions);
|
|
|
|
|
if (r != ModifyResult.Invalid)
|
|
|
|
|
len++;
|
|
|
|
|
if (r == ModifyResult.Error)
|
|
|
|
|
err++;
|
|
|
|
|
if (r == ModifyResult.Modified)
|
|
|
|
|
{
|
2016-08-06 19:30:00 +00:00
|
|
|
|
if (pkm.Species > 0)
|
|
|
|
|
{
|
2016-10-12 02:23:04 +00:00
|
|
|
|
pkm.RefreshChecksum();
|
2016-08-06 19:30:00 +00:00
|
|
|
|
File.WriteAllBytes(Path.Combine(destPath, Path.GetFileName(file)), pkm.DecryptedBoxData);
|
2016-10-12 02:23:04 +00:00
|
|
|
|
ctr++;
|
2016-08-06 19:30:00 +00:00
|
|
|
|
}
|
2016-07-21 05:43:26 +00:00
|
|
|
|
}
|
2016-07-13 05:19:51 +00:00
|
|
|
|
|
|
|
|
|
b.ReportProgress(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-15 03:14:30 +00:00
|
|
|
|
public static void screenStrings(IEnumerable<StringInstruction> il)
|
2016-11-15 03:04:08 +00:00
|
|
|
|
{
|
|
|
|
|
foreach (var i in il.Where(i => !i.PropertyValue.All(char.IsDigit)))
|
|
|
|
|
{
|
2016-12-10 04:49:17 +00:00
|
|
|
|
string pv = i.PropertyValue;
|
|
|
|
|
if (pv.StartsWith("$") && pv.Contains(','))
|
|
|
|
|
{
|
|
|
|
|
string str = pv.Substring(1);
|
|
|
|
|
var split = str.Split(',');
|
|
|
|
|
int.TryParse(split[0], out i.Min);
|
|
|
|
|
int.TryParse(split[1], out i.Max);
|
|
|
|
|
|
|
|
|
|
if (i.Min == i.Max)
|
|
|
|
|
{
|
|
|
|
|
i.PropertyValue = i.Min.ToString();
|
|
|
|
|
Console.WriteLine(i.PropertyName + " randomization range Min/Max same?");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
i.Random = true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-15 03:04:08 +00:00
|
|
|
|
switch (i.PropertyName)
|
|
|
|
|
{
|
2017-01-08 07:54:09 +00:00
|
|
|
|
case nameof(PKM.Species): i.setScreenedValue(GameInfo.Strings.specieslist); continue;
|
|
|
|
|
case nameof(PKM.HeldItem): i.setScreenedValue(GameInfo.Strings.itemlist); continue;
|
|
|
|
|
case nameof(PKM.Ability): i.setScreenedValue(GameInfo.Strings.abilitylist); continue;
|
|
|
|
|
case nameof(PKM.Nature): i.setScreenedValue(GameInfo.Strings.natures); continue;
|
|
|
|
|
case nameof(PKM.Ball): i.setScreenedValue(GameInfo.Strings.balllist); continue;
|
2016-12-10 04:49:17 +00:00
|
|
|
|
case nameof(PKM.Move1):
|
|
|
|
|
case nameof(PKM.Move2):
|
|
|
|
|
case nameof(PKM.Move3):
|
|
|
|
|
case nameof(PKM.Move4):
|
|
|
|
|
case nameof(PKM.RelearnMove1):
|
|
|
|
|
case nameof(PKM.RelearnMove2):
|
|
|
|
|
case nameof(PKM.RelearnMove3):
|
|
|
|
|
case nameof(PKM.RelearnMove4):
|
2017-01-08 07:54:09 +00:00
|
|
|
|
i.setScreenedValue(GameInfo.Strings.movelist); continue;
|
2016-11-15 03:04:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-13 05:19:51 +00:00
|
|
|
|
|
|
|
|
|
private void tabMain_DragEnter(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
|
|
|
|
|
}
|
|
|
|
|
private void tabMain_DragDrop(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
|
|
|
|
if (!Directory.Exists(files[0])) return;
|
|
|
|
|
|
|
|
|
|
TB_Folder.Text = files[0];
|
|
|
|
|
TB_Folder.Visible = true;
|
|
|
|
|
RB_SAV.Checked = false;
|
|
|
|
|
RB_Path.Checked = true;
|
|
|
|
|
}
|
2016-12-07 05:36:31 +00:00
|
|
|
|
private void CB_Property_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
L_PropType.Text = getPropertyType(CB_Property.Text);
|
2017-01-09 05:06:15 +00:00
|
|
|
|
L_PropValue.Text = pkm.GetType().HasProperty(CB_Property.Text)
|
|
|
|
|
? ReflectUtil.GetValue(pkm, CB_Property.Text).ToString()
|
|
|
|
|
: "";
|
2016-12-07 05:36:31 +00:00
|
|
|
|
}
|
|
|
|
|
private string getPropertyType(string propertyName)
|
|
|
|
|
{
|
|
|
|
|
int typeIndex = CB_Format.SelectedIndex;
|
|
|
|
|
|
|
|
|
|
if (typeIndex == 0) // All
|
|
|
|
|
return types[0].GetProperty(propertyName).PropertyType.Name;
|
|
|
|
|
|
|
|
|
|
if (typeIndex == properties.Length - 1) // Any
|
|
|
|
|
foreach (var p in types.Select(t => t.GetProperty(propertyName)).Where(p => p != null))
|
|
|
|
|
return p.PropertyType.Name;
|
|
|
|
|
|
|
|
|
|
return types[typeIndex - 1].GetProperty(propertyName).PropertyType.Name;
|
|
|
|
|
}
|
2016-07-13 05:19:51 +00:00
|
|
|
|
|
|
|
|
|
// Utility Methods
|
2016-07-23 08:04:55 +00:00
|
|
|
|
public class StringInstruction
|
2016-07-13 05:19:51 +00:00
|
|
|
|
{
|
|
|
|
|
public string PropertyName;
|
|
|
|
|
public string PropertyValue;
|
|
|
|
|
public bool Evaluator;
|
2016-11-15 03:04:08 +00:00
|
|
|
|
public void setScreenedValue(string[] arr)
|
|
|
|
|
{
|
|
|
|
|
int index = Array.IndexOf(arr, PropertyValue);
|
|
|
|
|
PropertyValue = index > -1 ? index.ToString() : PropertyValue;
|
|
|
|
|
}
|
2016-12-10 04:49:17 +00:00
|
|
|
|
|
|
|
|
|
// Extra Functionality
|
|
|
|
|
public bool Random;
|
|
|
|
|
public int Min, Max;
|
|
|
|
|
public int RandomValue => Util.rand.Next(Min, Max + 1);
|
2016-07-13 05:19:51 +00:00
|
|
|
|
}
|
2016-07-21 05:43:26 +00:00
|
|
|
|
private enum ModifyResult
|
2016-07-13 05:19:51 +00:00
|
|
|
|
{
|
2016-07-21 05:43:26 +00:00
|
|
|
|
Invalid,
|
|
|
|
|
Error,
|
|
|
|
|
Filtered,
|
|
|
|
|
Modified,
|
|
|
|
|
}
|
|
|
|
|
private static ModifyResult ProcessPKM(PKM PKM, IEnumerable<StringInstruction> Filters, IEnumerable<StringInstruction> Instructions)
|
|
|
|
|
{
|
|
|
|
|
if (!PKM.ChecksumValid || PKM.Species == 0)
|
|
|
|
|
return ModifyResult.Invalid;
|
|
|
|
|
|
2016-07-23 08:04:55 +00:00
|
|
|
|
Type pkm = PKM.GetType();
|
|
|
|
|
|
2016-07-13 05:19:51 +00:00
|
|
|
|
foreach (var cmd in Filters)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2016-07-23 08:04:55 +00:00
|
|
|
|
if (!pkm.HasProperty(cmd.PropertyName))
|
|
|
|
|
return ModifyResult.Filtered;
|
2016-07-13 05:19:51 +00:00
|
|
|
|
if (ReflectUtil.GetValueEquals(PKM, cmd.PropertyName, cmd.PropertyValue) != cmd.Evaluator)
|
2016-07-21 05:43:26 +00:00
|
|
|
|
return ModifyResult.Filtered;
|
2016-07-13 05:19:51 +00:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}.");
|
2016-07-21 05:43:26 +00:00
|
|
|
|
return ModifyResult.Filtered;
|
2016-07-13 05:19:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-21 05:43:26 +00:00
|
|
|
|
ModifyResult result = ModifyResult.Error;
|
2016-07-13 05:19:51 +00:00
|
|
|
|
foreach (var cmd in Instructions)
|
|
|
|
|
{
|
2016-07-23 18:44:37 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2016-12-10 04:49:17 +00:00
|
|
|
|
if (cmd.PropertyName == nameof(PKM.MetDate))
|
2016-09-16 03:54:41 +00:00
|
|
|
|
PKM.MetDate = DateTime.ParseExact(cmd.PropertyValue, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
|
2016-12-10 04:49:17 +00:00
|
|
|
|
else if (cmd.PropertyName == nameof(PKM.EggMetDate))
|
2016-09-16 03:54:41 +00:00
|
|
|
|
PKM.EggMetDate = DateTime.ParseExact(cmd.PropertyValue, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
|
2016-12-10 04:49:17 +00:00
|
|
|
|
else if (cmd.PropertyName == nameof(PKM.EncryptionConstant) && cmd.PropertyValue == CONST_RAND)
|
2016-07-23 18:44:37 +00:00
|
|
|
|
ReflectUtil.SetValue(PKM, cmd.PropertyName, Util.rnd32().ToString());
|
2016-12-10 04:49:17 +00:00
|
|
|
|
else if(cmd.PropertyName == nameof(PKM.PID) && cmd.PropertyValue == CONST_RAND)
|
2016-08-15 06:23:38 +00:00
|
|
|
|
PKM.setPIDGender(PKM.Gender);
|
2016-12-10 04:49:17 +00:00
|
|
|
|
else if (cmd.PropertyName == nameof(PKM.EncryptionConstant) && cmd.PropertyValue == nameof(PKM.PID))
|
2016-08-15 06:23:38 +00:00
|
|
|
|
PKM.EncryptionConstant = PKM.PID;
|
2016-12-10 04:49:17 +00:00
|
|
|
|
else if (cmd.PropertyName == nameof(PKM.PID) && cmd.PropertyValue == CONST_SHINY)
|
2016-07-29 06:05:26 +00:00
|
|
|
|
PKM.setShinyPID();
|
2016-12-10 04:49:17 +00:00
|
|
|
|
else if (cmd.PropertyName == nameof(PKM.Species) && cmd.PropertyValue == "0")
|
2016-07-31 00:22:33 +00:00
|
|
|
|
PKM.Data = new byte[PKM.Data.Length];
|
2016-11-25 23:34:47 +00:00
|
|
|
|
else if (cmd.PropertyName.StartsWith("IV") && cmd.PropertyValue == CONST_RAND)
|
|
|
|
|
setRandomIVs(PKM, cmd);
|
2016-12-10 04:49:17 +00:00
|
|
|
|
else if (cmd.Random)
|
|
|
|
|
ReflectUtil.SetValue(PKM, cmd.PropertyName, cmd.RandomValue);
|
2016-07-23 18:44:37 +00:00
|
|
|
|
else
|
|
|
|
|
ReflectUtil.SetValue(PKM, cmd.PropertyName, cmd.PropertyValue);
|
|
|
|
|
|
|
|
|
|
result = ModifyResult.Modified;
|
|
|
|
|
}
|
2016-07-13 05:19:51 +00:00
|
|
|
|
catch { Console.WriteLine($"Unable to set {cmd.PropertyName} to {cmd.PropertyValue}."); }
|
|
|
|
|
}
|
2016-07-21 05:43:26 +00:00
|
|
|
|
return result;
|
2016-07-13 05:19:51 +00:00
|
|
|
|
}
|
2016-11-25 23:34:47 +00:00
|
|
|
|
private static void setRandomIVs(PKM PKM, StringInstruction cmd)
|
|
|
|
|
{
|
2016-11-27 17:26:58 +00:00
|
|
|
|
int MaxIV = PKM.Format <= 2 ? 15 : 31;
|
2016-11-25 23:34:47 +00:00
|
|
|
|
if (cmd.PropertyName == "IVs")
|
2016-11-27 17:26:58 +00:00
|
|
|
|
{
|
|
|
|
|
bool IV3 = Legal.Legends.Contains(PKM.Species) || Legal.SubLegends.Contains(PKM.Species);
|
|
|
|
|
int[] IVs = new int[6];
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
|
IVs[i] = (int)(Util.rnd32() & MaxIV);
|
|
|
|
|
} while (IV3 && IVs.Where(i => i == MaxIV).Count() < 3);
|
|
|
|
|
ReflectUtil.SetValue(PKM, cmd.PropertyName, IVs);
|
|
|
|
|
}
|
2016-11-25 23:34:47 +00:00
|
|
|
|
else
|
2016-11-27 17:26:58 +00:00
|
|
|
|
ReflectUtil.SetValue(PKM, cmd.PropertyName, Util.rnd32() & MaxIV);
|
2016-11-25 23:34:47 +00:00
|
|
|
|
}
|
2016-07-18 00:06:50 +00:00
|
|
|
|
|
|
|
|
|
private void B_Add_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2016-07-21 05:21:09 +00:00
|
|
|
|
if (CB_Property.SelectedIndex < 0)
|
2017-01-08 07:54:09 +00:00
|
|
|
|
{ WinFormsUtil.Alert("Invalid property selected."); return; }
|
2016-07-21 05:21:09 +00:00
|
|
|
|
|
2016-07-18 00:06:50 +00:00
|
|
|
|
char[] prefix = {'.', '=', '!'};
|
2016-07-21 05:21:09 +00:00
|
|
|
|
string s = prefix[CB_Require.SelectedIndex] + CB_Property.Items[CB_Property.SelectedIndex].ToString() + "=";
|
2016-07-18 00:06:50 +00:00
|
|
|
|
if (RTB_Instructions.Lines.Length != 0 && RTB_Instructions.Lines.Last().Length > 0)
|
|
|
|
|
s = Environment.NewLine + s;
|
|
|
|
|
|
|
|
|
|
RTB_Instructions.AppendText(s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CB_Format_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (currentFormat == CB_Format.SelectedIndex)
|
|
|
|
|
return;
|
|
|
|
|
|
2016-12-07 05:36:31 +00:00
|
|
|
|
int format = CB_Format.SelectedIndex;
|
2016-07-18 00:06:50 +00:00
|
|
|
|
CB_Property.Items.Clear();
|
2016-12-07 05:36:31 +00:00
|
|
|
|
CB_Property.Items.AddRange(properties[format]);
|
2016-07-18 00:06:50 +00:00
|
|
|
|
CB_Property.SelectedIndex = 0;
|
2016-12-07 05:36:31 +00:00
|
|
|
|
currentFormat = format;
|
2016-07-18 00:06:50 +00:00
|
|
|
|
}
|
2016-07-13 05:19:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|