From d4aff0632e3b31aff810dd634784a6cedc77aae4 Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 4 Jul 2017 22:22:04 -0700 Subject: [PATCH] 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. --- .../Subforms/PKM Editors/BatchEditor.cs | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs b/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs index 962d8a6a8..5c3e0a3c7 100644 --- a/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs +++ b/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs @@ -56,6 +56,7 @@ private static string[][] GetPropArray() 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 @@ public static void ScreenStrings(IEnumerable il) 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 @@ private static ModifyResult TryModifyPKM(PKM PKM, IEnumerable } 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 @@ private static bool SetSuggestedPKMProperty(PKM PKM, StringInstruction cmd, PKMI 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))