Commit graph

57 commits

Author SHA1 Message Date
Kurt
95fbf66a6e
Refactor: Gen3/4 Lead Encounters, property fixing (#4193)
In addition to the Method 1 (and other sibling PIDIV types) correlation, an encounter can only be triggered if the calls prior land on the Method {1} seed. The RNG community has dubbed these patterns as "Method J" (D/P/Pt), "Method K" (HG/SS), and "Method H" (Gen3, coined by yours truly). The basic gist of these is that they are pre-requisites, like the Shadow locks of Colosseum/XD. 

Rename/re-type a bunch of properties to get the codebase more in line with correct property names & more obvious underlying types.
2024-02-22 21:20:54 -06:00
Kurt
5706fb2fb5 Gen6: Add mach & acro to usable key item memories 2024-01-25 18:56:57 -08:00
Kurt
d47bb1d297
Update .NET Runtime to .NET 8.0 (#4082)
With the new version of Visual Studio bringing C# 12, we can revise our logic for better readability as well as use new methods/APIs introduced in the .NET 8.0 BCL.
2023-12-03 20:13:20 -08:00
Kurt
9f340b592b Evolve-With-Move: Refactor to be memory-like
Evolving with a move requires once knowing the move, should be a much better approximation solution here. Ideally we check in specific contexts as Pokemon may learn their requisite moves after evolution, but this should catch most for now.
2023-09-12 18:14:22 -07:00
Kurt
f7d66db7e2 Misc tweaks
Check HT move memories in Gen9 appropriately for deferral cases
Add missing ID32 set for GO8->PKM
Slight pre-work for Mightiest Mark Mew method signatures
2023-08-19 11:13:20 -07:00
Kurt
f632aedd15
Encounter Templates: Searching and Creating (#3955)
We implement simple state machine iterators to iterate through every split type encounter array, and more finely control the path we iterate through. And, by using generics, we can have the compiler generate optimized code to avoid virtual calls.

In addition to this, we shift away from the big-5 encounter types and not inherit from an abstract class. This allows for creating a PK* of a specific type and directly writing properties (no virtual calls). Plus we can now fine-tune each encounter type to call specific code, and not have to worry about future game encounter types bothering the generation routines.
2023-08-12 16:01:16 -07:00
Kurt
dcc0e79435
Evotree: Evolution Traversal Enhancements (#3936)
Like move validation, evolutions are the earliest thing we wish to traverse when determining what encounters may have originated the current Pokémon. To determine the permitted species-form-levels a Pokémon could originate with, we must devolve a Pokémon by traveling down-generation to origin. Once we have an encounter, we can then evolve it to the current species, traversing upwards from origin to the current format.
2023-07-05 21:14:09 -07:00
Lusamine
e02b33ef2c Add Wedgehurst as valid general location to gen 8 sign memory 2023-07-05 19:40:17 -05:00
Kurt
1174e354b1
Initial support for Pokémon HOME 3.0.0 (#3899)
* Heavily rewrites the `PKH` abstractions.
* Uses HOME's core-side classes as the transfer middlemen instead of direct A->B transfers.
* Revises logic to account for most of HOME's quirks (scale/height copying, safe refuge PLA)

Future revisions hinge on better handling of evotree (need better metadata about existing as specific evolutions in each game).

---------

Co-authored-by: sora10pls <17801814+sora10pls@users.noreply.github.com>
Co-authored-by: Lusamine <30205550+Lusamine@users.noreply.github.com>
2023-06-03 18:19:16 -07:00
Kurt
e75da5d3b7 Misc tweaks
More readonlyspan for the rest of the defined ushort[] arrays, less dictionary/hashset
Simplify some slot-empty checks, makes it easier to see an api for slot interaction (future?)
2023-05-07 13:32:29 -07:00
Jonathan Herbert
599387e7aa
Fix ORAS Held Items Using XY Held Items By Mistake (#3866)
- Add HeldItems_XY
- Fix that HeldItem_AO pointed to what should have been HeldItems_XY
- Fix HeldItem_AO being inconsistent with the rest of the HeldItems
- Correct HeldItems_AO only having XY  held items and not ones added in ORAS
2023-04-23 01:35:26 -07:00
Kurt
5bdc6b9ef8
Privatize some static fields, more robust legal helper classes. (#3865)
* Uses LearnSource more throughout the codebase when appropriate, rather than loosely coupled pivot methods.
* Hides Learnset/EggMove data inside the LearnSource classes.
* Extracts functionality from the large Legal class & partial Table*.cs files into better performing helper classes.
* Cleans up some code from prior LearnSource commits.
2023-04-20 21:23:15 -07:00
Kurt
fa9a809751
Encapsulate item pouch arrays/etc for finer control (#3860)
* Extract/encapsulate inventory legal arrays to interface+class

Hiding them behind methods allows these to be left as ReadOnlySpan<ushort> and thus never allocate on the heap.
Also refactors out some logic for checking if an item is legal.

End result feels more maintainable and is less bloaty (no more passing in a nullable func)

Batch editing
* Add HasType filter

```
=HasType=11
.HeldItem=Meadow Plate
```

slaps a meadow plate on any pkm with grass type
Use `=PersonalType1=11` for only primary grass types; only-secondary-type grass will not match it.
2023-04-16 12:58:07 -07:00
Kurt
c73264d4f3 Minor minor perf
Small changes to reduce some allocations
2023-04-15 01:58:37 -07:00
Kurt
0087ccb44f Use span for savefile slot API
No more offset fetch
2023-03-25 23:14:50 -07:00
Kurt
5ce3e734b8
Skip initial cctor alloc on non-byte primitives (#3850)
Runtime/jit repoints these to the dll rather than heap if we're Little Endian (always, otherwise will allocate like before).

Eliminates quite a few static constructors, so even faster startup. Items later.
2023-03-25 17:55:55 -07:00
Kurt
88830e0d00
Update from .NET Framework 4.6 to .NET 7 (#3729)
Updates from net46->net7, dropping support for mono in favor of using the latest runtime (along with the performance/API improvements). Releases will be posted as 64bit only for now.

Refactors a good amount of internal API methods to be more performant and more customizable for future updates & fixes.

Adds functionality for Batch Editor commands to `>`, `<` and <=/>=

TID/SID properties renamed to TID16/SID16 for clarity; other properties exposed for Gen7 / display variants.

Main window has a new layout to account for DPI scaling (8 point grid)

Fixed: Tatsugiri and Paldean Tauros now output Showdown form names as Showdown expects
Changed: Gen9 species now interact based on the confirmed National Dex IDs (closes #3724)
Fixed: Pokedex set all no longer clears species with unavailable non-base forms (closes #3720)
Changed: Hyper Training suggestions now apply for level 50 in SV. (closes #3714)
Fixed: B2/W2 hatched egg met locations exclusive to specific versions are now explicitly checked (closes #3691)
Added: Properties for ribbon/mark count (closes #3659)
Fixed: Traded SV eggs are now checked correctly (closes #3692)
2023-01-21 20:02:33 -08:00
Kurt
03182ebd3d Update 22.11.24
Adds support for Scarlet & Violet.

Co-Authored-By: SciresM <8676005+SciresM@users.noreply.github.com>
Co-Authored-By: Matt <17801814+sora10pls@users.noreply.github.com>
Co-Authored-By: Lusamine <30205550+Lusamine@users.noreply.github.com>
2022-11-24 17:42:17 -08:00
Kurt
da642ee16e Remap context for sidegame HT memory checks
gastrodon with recover as HT memory needs to verify within the context of SW/SH and prior learn environments.
2022-09-02 15:41:22 -07:00
Kurt
66e0613d82 Minor clean 2022-08-30 15:00:45 -07:00
Kurt
d8fe34011d Remove some bounds checks, int->byte form oops
https://github.com/kwsch/PKHeX/pull/3575#issuecomment-1229244453
ty @Kermalis !
2022-08-27 12:53:30 -07:00
Kurt
3c232505e5
Refactoring: Narrow some value types (Species, Move, Form) (#3575)
In this pull request I've changed a ton of method signatures to reflect the more-narrow types of Species, Move# and Form; additionally, I've narrowed other large collections that stored lists of species / permitted values, and reworked them to be more performant with the latest API spaghetti that PKHeX provides. Roamer met locations, usually in a range of [max-min]<64, can be quickly checked using a bitflag operation on a UInt64. Other collections (like "Is this from Colosseum or XD") were eliminated -- shadow state is not transferred COLO<->XD, so having a Shadow ID or matching the met location from a gift/wild encounter is a sufficient check for "originated in XD".
2022-08-26 23:43:36 -07:00
Kurt
444c3d2209 Narrow more types 2022-08-26 10:07:24 -07:00
Kurt
b241c19520 Simplify some memory args 2022-08-24 23:29:03 -07:00
Kurt
d3c2d77d11 Misc move/memory tweaks
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)
2022-08-24 20:32:40 -07:00
Kurt
2cb2531288 Add more xmldoc 2022-08-21 01:39:16 -07:00
Kurt
9166d0eb64
Refactoring: Move Source (Legality) (#3560)
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
2022-08-03 16:15:27 -07:00
Kurt
fc754b346b
File scoped namespaces (#3529)
[Language Reference](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/file-scoped-namespaces)

Updates all the files, one less level of indentation.

Some small changes were made to API surfaces, renaming `PKM pkm` -> `PKM pk`, and `LegalityAnalysis.pkm` -> `LegalityAnalysis.Entity`
2022-06-18 11:04:24 -07:00
Kurt
893b5d5293 Revise more PB7/PK8->Interface type checks 2022-06-04 21:03:25 -07:00
Kurt
382ea5cd61 Extract move info api 2022-06-04 13:14:50 -07:00
Kurt
df02532697 Misc fixes
Simplify HM memory check (bit permission superset, just check directly)
Disallow BestFriends & Effort on PA8 exclusives
PA8 techrecord permits none.
2022-06-02 20:05:27 -07:00
Kurt
5bcccc6d92
HOME 2.0.0: Handle conversion behavior & restrictions (#3506)
* 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.
2022-05-30 21:43:52 -07:00
Kurt
ccf87242c1 Eliminate boxing on encounter search (criteria)
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.
2022-05-07 18:29:36 -07:00
Kurt
c51d51d381 More specific primitives for Memories/others 2022-03-06 12:01:47 -08:00
Kurt
da9d09ea76 Misc tweaks
No functional change
2022-01-11 22:53:20 -08:00
Kurt
47071b41f3
Refactoring: Span-based value writes and method signatures (#3361)
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.
2022-01-02 21:35:59 -08:00
Kurt
88ddc5822e c#10: readonly record structs
Reduces some boilerplate constructors/equality compares
2021-12-04 18:32:35 -08:00
Lusamine
aef7987f82 Enable SWSH restaurant memory
Obtained by eating at the Circhester restaurant in story mode!
2021-12-03 16:58:07 -06:00
Kurt
723514e89c
Update 21.11.19 - Brilliant Diamond & Shining Pearl (#3289)
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.
2021-11-19 18:23:49 -08:00
Lusamine
25313ad58d Eternatus can trigger legendary encounter memory 2021-09-15 20:04:09 -05:00
Lusamine
4e398322b0
More memory legality checks (#3256)
* Add more memory legality checks

Includes the following new memory checks:
- 4: met in link-trade, allows all possible genlocs except dangerous place
- 7: successful fishing, allows fishable species in gen 6 and 8
- 9: paying attention to another mon, allows only available species for gen 8
- 29: encountering legendary Pokémon, only seen on Zacian, Zamazenta, Calyrex so far
- 32: riding a bike, only in genlocs where biking is possible
- 75: taken to Nursery and placed with a mon, allows only available species for gen 8

Unstubs lotto check and applies it to gen 6.

Co-Authored-By: Skadiv <62726360+Skadiv@users.noreply.github.com>
Co-Authored-By: Matt <17801814+sora10pls@users.noreply.github.com>

* Loto-ID only has one t

* Crown Shrine has another genloc outside

* Consistent Loto name for array

Co-authored-by: Skadiv <62726360+Skadiv@users.noreply.github.com>
Co-authored-by: Matt <17801814+sora10pls@users.noreply.github.com>
2021-09-12 12:01:45 -07:00
Lusamine
4cb525aac1 Restrict memory 39 general locations for SWSH 2021-09-06 12:39:08 -05:00
Lusamine
2f2cb43bd0 Disallow memory 17 from SWSH
It's a 1% memory that is impossible to obtain normally, but was missed earlier since it occurs on the in-game Throh/Sawk trades.
2021-08-29 19:22:09 -05:00
Kurt
adb7466a22 More memory legality additions
probably worthwhile to move the checks into the context, and return an enum -> switch to generate checkresult
2021-08-29 15:56:09 -07:00
Kurt
1ac125d335 Add Gen8 memory table data
The middle table in poke_memory.prmb contains the analogue of Gen6's memory table data. All existing memory data is the same, with 20 memories added.

Feeling bitflags are the same as before, but as we've noticed, feeling 0 is not obtainable. All the feelings are value upshifted by 1. This is why the game shows a blank line for Gen6 Feeling-0, as that game was [0,23] not [1,24] for the span of feeling strings.

Memories with 1% chance are actually 0% due to how they if-abort in the game code. Nice bug, GameFreak! @Lusamine had previously committed the unobtainable memories, derived from the community's empirical data.
2021-08-29 13:06:44 -07:00
Lusamine
3627ff4104 Disallow specific memories from SWSH
Never observed these in 20k+ memories, and I wasn't able to trigger them myself either.
2021-08-29 10:42:16 -05:00
Skadiv
809557715d
Add Wyndon to the sign memory locations (#3252) 2021-08-29 09:38:15 -05:00
Lusamine
e85a75e796 Add Wyndon as a location for sitting on bench memory 2021-08-29 01:28:42 -05:00
Lusamine
81f2744af2 Add story raid species for Dynamax memory 2021-08-28 15:55:47 -05:00
Kurt
92f30e26cc Add misc memory checks for gen8 memID 42/51/70 args
Closes #3249

Co-Authored-By: Skadiv <62726360+Skadiv@users.noreply.github.com>
2021-08-26 21:20:52 -07:00