Add ability to batch edit trashbytes

Raw editing of byte fields

.Nickname_Trash=$[]43,00,65,00,72,00,66,00,72,00,6F,00,75,00,73,00,73,00,65,00,00,00,00,00

only use cases are OT/Nickname trash bytes

not too concerned about speed re-parsing values or storing it to an auto
property; it's fast enough.
This commit is contained in:
Kurt 2017-07-04 22:22:04 -07:00
parent 6f6a9dfaaf
commit d4aff0632e

View file

@ -56,6 +56,7 @@ namespace PKHeX.WinForms
private const string CONST_RAND = "$rand";
private const string CONST_SHINY = "$shiny";
private const string CONST_SUGGEST = "$suggest";
private const string CONST_BYTES = "$[]";
private const string PROP_LEGAL = "Legal";
private static readonly string[] CustomProperties = {PROP_LEGAL};
@ -398,7 +399,7 @@ namespace PKHeX.WinForms
foreach (var i in il.Where(i => !i.PropertyValue.All(char.IsDigit)))
{
string pv = i.PropertyValue;
if (pv.StartsWith("$") && pv.Contains(','))
if (pv.StartsWith("$") && !pv.StartsWith(CONST_BYTES) && pv.Contains(','))
i.SetRandRange(pv);
SetInstructionScreenedValue(i);
@ -455,6 +456,11 @@ namespace PKHeX.WinForms
}
private static ModifyResult SetPKMProperty(PKM PKM, PKMInfo info, StringInstruction cmd)
{
if (cmd.PropertyValue.StartsWith(CONST_BYTES))
return SetByteArrayProperty(PKM, cmd)
? ModifyResult.Modified
: ModifyResult.Error;
if (cmd.PropertyValue == CONST_SUGGEST)
return SetSuggestedPKMProperty(PKM, cmd, info)
? ModifyResult.Modified
@ -516,6 +522,21 @@ namespace PKHeX.WinForms
return false;
}
}
private static bool SetByteArrayProperty(PKM PKM, StringInstruction cmd)
{
switch (cmd.PropertyName)
{
case nameof(PKM.Nickname_Trash):
PKM.Nickname_Trash = string2arr(cmd.PropertyValue);
return true;
case nameof(PKM.OT_Trash):
PKM.OT_Trash = string2arr(cmd.PropertyValue);
return true;
default:
return false;
}
byte[] string2arr(string str) => str.Substring(CONST_BYTES.Length).Split(',').Select(z => Convert.ToByte(z.Trim(), 16)).ToArray();
}
private static void SetProperty(PKM PKM, StringInstruction cmd)
{
if (cmd.PropertyName == nameof(PKM.MetDate))