Disallow max moves from Sketch
Hide dmax moves from legal dropdown lists
Pass ushort for moves for validating memories
Internal class for move pp (hide empty class from dll users)
Fix RibbonVerifier4 not checking gen4 contest ribbons correctly
Split IRibbonCommon6 to have memory ribbons separate, as they are not implemented in mystery gifts. Also, we can add the boolean flags to the interface, and check that the boolean is set if count is nonzero.
Fix adding ribbons to Gen8 gift templates
Improve Gen8 template ribbon fetch (no closure, faster IndexOf)
`Moveset` struct stores 4 moves, and exposes methods to interact with a moveset.
`IndividualValueSet` stores a 6 IV template (signed).
Performance impact:
* Less allocating on the heap: Moves - (8 bytes member ptr, 20 bytes heap->8 bytes member)
* Less allocating on the heap: IVs - (8 bytes member ptr, 28 bytes heap->8 bytes member)
* No heap pointers, no need to jump to grab data.
* Easy to inline logic for checking if moves are present (no linq usage with temporary collections).
End result is faster ctor times, less memory used, faster program.
The dummy EncounterInvalid has Generation:0, when 7->6/2 depends on which generation the encounter originated on. Change it so that the origin generation gets passed along.
* Rewrite ribbon verification
* Explicitly verifies all ribbons instead of chained iterators.
* Verifies using only the stack, using `struct` and `Span<T>`. No allocation on heap, or `IEnumerable` iterators.
* Verifies all egg ribbons using a separate method, explicitly implemented. No reflection overhead.
* Separates each ribbon interface to separate `static` classes. Easier to identify code needing change on new game update.
* Extracted logic for specific ribbons. Can easily revise complicated ribbon's acquisition rules.
* Simplifies GiveAll/RemoveAll legal ribbon mutations. No reflection overhead, and no allocation.
* Can be expanded in the future if we need to track conditions for ribbon acquisition (was Sinnoh Champ received in BDSP or Gen4?)
End result is a more performant implementation and easier to maintain & reuse logic.
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
was checking stale value
make loop max adjustable by caller; knowingly requesting squares is 1:65,536, so a higher loop count than 50k might guarantee more successes.
Maybe in the future we'd have separate algorithms to pre-choose seeds by choosing a PID and unrolling -> rolling.
Co-Authored-By: Kermalis <29823718+Kermalis@users.noreply.github.com>
Bulk: Pass slot origin to legality analysis. Pass the proper personal data for good measure
Personal: check if the form truly does exist for presence check because sometimes the form will default to 0 on OOB
Showdown: Reduce some allocation, be more lenient in casing parse for Nature suffix and Hidden Power manually typed by user. Parse non-english hidden power sets (yay, now usable by all languages even though PS sets are English only!).
Will need to verify if Beast Balls can be used on other Pokémon, and if generic Poké Balls can be used on Ultra Beasts. We'll see when GO Fest Berlin starts.
Closes#3519
Usages weren't consistent; since `é` isn't accessible on usual english keyboards, just use regular `e` instead of alt-223 entry.
Not sure why VS preferred to save the text files without an encoding prefix; oh well.
New current handler verifier settings flag GO => LGPE transfers. Unlike GO => HOME, these transfers use your LGPE OT info, so it's legal to have no HT and have the current handler be OT
Co-Authored-By: Matt <17801814+sora10pls@users.noreply.github.com>
Default settings do not flag, as Database view does not track the savefile (LegalityAnalysis only indirectly references the latest loaded save file, not the true source).
Bulk Analysis will flag them correctly if run. Can be turned off.
* Revises legality checks to account for traveling between the three game islands (PLA/BDSP/SWSH)
* Adds conversion mechanisms between the three formats, as well as flexible conversion options to backfill missing data (thanks GameFreak/ILCA for opting for lossy conversion instead of updating the games).
* Adds API abstractions for HOME data storage format (EKH/PKH format 1, aka EH1/PH1).
* Revises some APIs for better usage:
- `PKM` now exposes a `Context` to indicate the isolation context for legality purposes.
- Some method signatures have changed to accept `Context` or `GameVersion` instead of a vague `int` for Generation.
- Evolution History is now tracked in the Legality parse for specific contexts, rather than only per generation.
ShowdownSet: Lessen allocation
MoveTutor: Remove boxing by calling the generic method instead of object method
Xoro8b: Add more xmldoc, use positive constant instead of inverse negative for parity
StadiumUtil: Use built-in endianness reversal methods
struct implementing interface is boxed when passed to method that accepts interface (not generic method).
Removes IDexLevel (no other inheritors but EvoCriteria) and uses the primitive the data is stored (array, not IReadOnlyList) for slightly better perf.
ty @Atrius97 for finally nailing the repro on this
Co-Authored-By: Atrius97 <39707481+Atrius97@users.noreply.github.com>
Co-Authored-By: Lusamine <30205550+Lusamine@users.noreply.github.com>
Many years ago, PKX used to be a >4,000 line bloated file, which spun off multiple classes like CommonEdits and most of the early non-GUI PKM related logic. Now, it's just a stub to source the latest generation & personal table.
Separate files = more concise info, and more room to grow to do more advanced things.
Makes the IsPresent methods public (no longer internal).
* Draft checks for encounter slot mastery
* Check encounter mastery flags
* Add moves for LA static encounters that don't follow learnset
* Add moves on crossover LA static encounters
* add alpha moveset population method
Now generates and applies moves as the game does
Updates some handling of other methods to use Span
* Show better message for bad mastery init flags
* Insert descending if candidates have same level
Level 78 Yanmega:
- [01] [10] Quick Attack
- [06] [15] Gust
- [11] [20] Silver Wind
- [18] [28] Hypnosis
- [25] [35] Air Slash
- [34] [45] Ancient Power
- [43] [54] Crunch
- [43] [54] Bug Buzz
Yields:
AlphaMove
Crunch*
Bug Buzz*
Ancient Power
* Descending order due to iteration
Co-authored-by: Lusamine <30205550+Lusamine@users.noreply.github.com>
Single underscore discards (one of the c# language revisions allowed reusing the single underscore discard).
Remove a temporary allocation in BDSP flag editor
* Make EvolutionCriteria struct
8 bytes per object instead of 26
Unify LevelMin/LevelMax to match EncounterTemplate
bubble up precise array type for better iteration
* Inline queue operations, less allocation
* Inline some logic
* Update EvolutionChain.cs
* Improve clarity on duplicate move check
* Search reverse
For a dual stage chain, finds it first iteration rather than second.
Instantiating from template now follows group seed -> spawn 1 correlation, including alpha move.
Differentiates static encounters that don't follow the ow8a correlation, scrambles EC to disassociate.
Adds rand64 to get initial seeds
Set correct level range to match slotSeed; not respecting the slot roll being valid, but whatever.
Getting close to weeding out all the easy inefficiencies to make me finally tackle the "stop gathering all moves instead of checking individual moves" allocation issue.
Sweet Heart still unobtainable (why did they give it a sprite if it's not functional ingame?)
Azure Flute is now obtainable
Sacred Ash was never obtainable
ddc6f414df caused it to be `<=` instead of `<`, but maybe the underlying issue was fixed a different way since all tests still pass with this reversion.
* Reuses move parse result objects for each encounter parsed in a LegalityCheck attempt, instead of creating a new object.
* Ensures the objects are never-null, and makes cleanup easier.
Slightly adjusts some other parts of the moveset validation to reduce allocations.
Have `Shiny.Random` be `0`, so we can skip init on this field for EncounterStatic. Plus makes it a little less brittle for future expansion if shiny qualities change.
Seal ComboItem
Reorder methods for easier reading
Fix BulkGenerator living dex setting CurrentLevel -- needs to be after species,form as EXPGrowth can vary for forms.
Change the data structure so that different locations are tied to the table, rather than separate usages of the table.
This de-bloats from 344KB->85KB and has less runtime memory consumption.
Adds structures to read/write saved spawner data such as seeds, counts.
Adds generator and validator to emulate the FixInitSpec builder used by the game logic
Similar to SW/SH raids, validating these in-process is not feasible due to the number crunching required.
This does not handle the encounter slot call or the follow-up level range call. Just the inner FixInitSpec ctor & fill.
level is calc'd:
randFloat(sum) -> slot float
rand.Next() -> gen_seed (for all the details)
rand.NextInt(delta) +min -> level
Co-Authored-By: Lusamine <30205550+Lusamine@users.noreply.github.com>
* Accurately implement height/weight calc
* Handle GUI reads
Having Auto off will read and write the values correctly
F6 will handle all the decimal points possible
* Remove no longer needed tolerance check
Update 22.02.04
Individual commits from this PR are not cherry-pickable in a vacuum; these were manually re-committed from a staging repo in order to group together changes for general public viewing. There were over 250 commits on the private development repo for this update.
Also hange >= to > because of new GO => HOME met date legality.9/1/2022 is legal if it was transferred in somewhere like Kiribati or New Zealand, but 9/2/2022 isn't.
Thanks @SadisticMystic!
https: //github.com/kwsch/PKHeX/commit/9ce0da6c46ebea3c7c6edd1f1e0571e5ecbec739#r63579484
Co-Authored-By: Russell Jones <questiondesk@gmail.com>
what a meme
All these edge cases make me want to move all this trade OT/Nick validation into the EncounterTrade classes and just get an enum indicating what is wrong with the trainer/OT details...
Existing `get`/`set` logic is flawed in that it doesn't work on Big Endian operating systems, and it allocates heap objects when it doesn't need to.
`System.Buffers.Binary.BinaryPrimitives` in the `System.Memory` NuGet package provides both Little Endian and Big Endian methods to read and write data; all the `get`/`set` operations have been reworked to use this new API. This removes the need for PKHeX's manual `BigEndian` class, as all functions are already covered by the BinaryPrimitives API.
The `StringConverter` has now been rewritten to accept a Span to read from & write to, no longer requiring a temporary StringBuilder.
Other Fixes included:
- The Super Training UI for Gen6 has been reworked according to the latest block structure additions.
- Cloning a Stadium2 Save File now works correctly (opening from the Folder browser list).
- Checksum & Sanity properties removed from parent PKM class, and is now implemented via interface.
As you progress the story in the Sinnoh games, the water level in Lake Verity will rise allowing you to Surf and reach the Verity Cavern. When this happens differs between DP/BDSP and Pt.
Zone 323 has nothing to do with it being early-game and only when Rowan's briefcase is present, but rather the differing water level. Riley's Riolu Egg can be hatched here without trading, as well.
Co-Authored-By: Billo-PS <63661653+Billo-PS@users.noreply.github.com>
PK4->PK5 fixes gendered Shedinja -> genderless.
Clean up PK4 ball value setters and expose those 2 properties separately.
Add edge case permission for HG/SS Sport Ball Shedinja being legal if evolved on DP (DP doesn't change 0x86, lol)
Copy PokéathlonStat and ball values individually for BK4<->PK4 conversion
Co-Authored-By: Lusamine <30205550+Lusamine@users.noreply.github.com>
any contest stat sum above 73 can have any sheen if you really give it trash blocks, lol
not trying to bruteforce the exact combination of consumed blocks/poffins, so these clamps may permit impossible intermediate values, but these are infrequent and meh.
Closes#3325
Can't lower contest stats, but there's no cases of them giving a pkm with contest stats in a game that can't obtain contest stats -- let's just reset instead of zero for futureproofing.
Make them extension methods too; add an overload if you want to purposefully maximize them.
0 is legal in most cases except for Gen2 and BDSP!
...it's technically possible to get 0 in BDSP if you have autosave turned on and have an Egg in your party after hatching one before it, but it will hatch immediately on your next game startup, so disallow it anyway.
Closes#3318
Gen8: if held item, only give if can be legally held; if dmax crystal, only give if available.
Gen8b: if held item, only give if can be legally held
Others: unimplemented; pull requests accepted.
verify BDSP legality restrictions
Enforce nonzero TID/SID in Trainer Editor window (can use Block Data editor to set whatever without restriction, idc).
#3305
They didn't reference the TamagoWazaIgnore table until v1.1 lmao
mimic BDSP's index fetching and just grab the array of eggmoves directly to avoid the abstraction method's overhead
set evotree back to private because don't need direct access anymore
shininess unrelated to your trainer ID, lol
probably also applies to other predetermined encounters like underground and radar, but those aren't EC-seed regenerated (?)
Remove unused interface declaration
because people couldn't hacc responsibly, I might as well give them a nudge in the right direction.
Doesn't mean I won't check your "random" choices distribution.
Yay abstractions to hide away the quirks.
BDSP traded eggs set HT_Friendship and the CurrentHandler flag, but the HatchCounter is always the OT_Friendship value.
Trades always receive BaseFriendship, instead of a hardcoded 50. Necessary to not hardcode because it's immutable for eggs.
Clicking the hatch counter label now sets it to the legal minimum hatch counter (best), and control clicking sets it to the max (worst). Check the encounter template for the true maximum.
Big thanks to @SciresM @sora10pls @Lusamine @architdate @ReignOfComputer for testing and contributing code / test cases. Can't add co-authors from the PR menu :(
Builds will fail because azure pipelines not yet updated with net6.
* Providing pkm/sav files via command line (dragging files onto exe / associated file launched) will more intelligently source a partner sav/pkm object if not provided.
* Gen1/2 mainline save files now indicate if they are VC era or GB era (legality implications) in the program title bar.
* Fixes loading VC era save backups not being recognized as VC era (`.bak` extension hides `.dat`)
* Export BAK moved to the SAV tab, which allows Export main to be deleted and Export SAV to be used as the single-click for exporting saves. `CTRL-E` is still the hotkey.
Hope this doesn't regress for stadium tutoring moves
RB eevee with special 2-move set was being flagged (wanted 4 moves cuz the base 2 aren't the normal levelup moves)
capture references for more concise expressions
Should have been "UTC+12"
We can just inline the shifting since it'll always add 12 hours to the current UTC time, thus that's the maximum date value possible
per the personal data in emerald, they are the only species that go from 2 distinct abilities to 1; since the game does not update the abilityNumber on evolution, it has the second ability being the same as the first, instead of the usual [ability,none] for all other single ability species.
Transfers use local date rather than UTC date, so we gotta allow dates up to kiribati's current date :)
Co-Authored-By: Matt <17801814+sora10pls@users.noreply.github.com>