kwsch / PKHeX

Pokémon Save File Editor
https://projectpokemon.org/pkhex/
Other
3.71k stars 698 forks source link

Provide "List includes" filters for batch editor #4040

Closed kfsass closed 1 year ago

kfsass commented 1 year ago

I'm sorry if I've missed the operator or solution to this somewhere. I've pored over the ProjectPokemon guide and the source code but can't find out whether what I'd like to do is possible or not.

I'm trying to modify Pokémon on my Emerald save file to remove any HM moves in preparation for migrating them to Gen IV. Ideally, I'd like to provide the batch editor with a list of move IDs to check the Pokémon's Moves list for, e.g.

=Moves=[15,17,249,273,26]
.Moves=$suggest

Right now, it seems like achieving this would require me to check Move1,2,3,4 individually for each individual HM move ID, e.g.

# four move slots and 8 HM moves mean 32 separate scripts need to be run
=Move1=15
.Moves=$suggest

Is the comparator able to support this? I thought I saw some methods related to including a range or set of values. I suppose I could just export the PKMs from Emerald and import them into HeartGold, but I'm enjoying doing the Catching Show (couldn't tell you why, lol). Thank you for this wonderful tool and your hard work! <3

kwsch commented 1 year ago

The Batch Editor scripting engine isn't meant to be a functionally complete language, so it's relatively limited in the things it can do (specific value comparisons only). If you're looking to do advanced edits like that, I recommend using LINQPad and reference PKHeX.Core.dll to do the following statements:

const string path = @"E:\Downloads\emerald.sav";
byte[] data = File.ReadAllBytes(path);
var sav = new SAV3E(data)
var boxData = sav.BoxData;
var hms = new[] {15,17,249,273,26};
foreach (var pk in boxData)
    if (pk.Moves.Any(hms.Contains))
        pk.SetMoveset();
sav.BoxData = boxData;
File.WriteAllBytes(path, sav.Write());
kfsass commented 1 year ago

Awesome, thank you for the tip!