Commit graph

71 commits

Author SHA1 Message Date
Kurt
1dcda6d2e8 Fix sav clone metadata inclusion
Need to not include it when cloning saves into the sav constructor, need to mirror it in metadata instead.
2024-07-04 22:27:53 -05:00
Kurt
7b6abc0520 Reduce alloc for ot/nick by raw trash reads
Legality check now catches buffer overflow mons.
Now that I have each type exposing a trash length & charcount, should be easy to have some reusable trash byte measuring methods (see the old branch)
2024-05-12 14:46:58 -05:00
Kurt
093264bc24 Add IStringConverter, impl on PKM & SaveFile
use in trash editor to translate strings, from PKM instead of SAV.
Closes #4222
2024-04-23 00:57:17 -05:00
abcboy101
21a1d5fe6f
Add PBR Poké Coupons accessor (#4230) 2024-03-21 07:56:28 -06:00
Kurt
fa80dac2ac
Refactoring: Rework saveblock to be Memory<byte> based (#4200) 2024-03-03 23:13:16 -06:00
Kurt
034658b764 Remove extra Memory forcing
Closes #4133
Refactors most of the `Trade` methods
Fix default egg friendship to 120
Fix Version value exposed for Gen4 saves (and others)
2024-02-23 17:01:36 -06:00
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
12ee201431 Extract EV limit logic 2023-09-27 22:15:59 -07:00
Kurt
b536388d0d Misc tweaks
Add xmldoc
Simplify some casts
Demote priority of Gen2 event yielding
Remove old EncounterMatchUtil code
Repoint DateTime.Now to console specific date provider stubs
2023-09-10 21:17:47 -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
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
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
ab723af640 Expose Context for SaveFile/ITrainerInfo 2022-06-03 19:08:46 -07:00
Kurt
977e977dbf Rewrite GeniusCrypto (XD/Batrev)
More clear usage of span
slightly less allocation+copying
more comments for future readers
2022-03-26 13:28:29 -07:00
Kurt
574a7f43a0 BDSP: Handle uninitialized box names
span refactoring didn't catch this
also apply same change for gen4 battle revolution string reads
2022-02-11 10:43:27 -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
0f3e5095c5 Replace more linq usage 2021-08-05 22:39:38 -07:00
Kurt
645f2b4db5 Revert implicit casting
Looks like netstandard2.0 wasn't meant to receive that new c#9 goodie
2021-03-29 00:14:44 -07:00
Kurt
3b344bd5c3 Add batrev as a blank sav option via code 2021-03-16 18:49:27 -07:00
Kurt
6bce4eea14 Minor clean
Annotations (nullable), some switch cases for readability
2021-03-14 16:16:55 -07:00
Kurt
155e0283ce Inline some string logic, extract magic values, xmldoc 2021-03-09 21:31:53 -08:00
Kurt
37cb15749e Update FormArgument handling for gen6/7
Disassociate pk4/pk6 backing byte[] when converting to pk5|pk7, as we no longer make a copy of the byte[] in the pkm's constructor.

Change UpdatePKM to include isParty, as we want it optional to update FormArgument too.

Change FormArgument saving to be handled by FormConverter; kinda not really good to have it there, but nothing else is handling FormArgument values.

Expand IFormArgument to have all FormArgument values exposed. "Maximum" is furfrou only.
PK6: Max is in the "FormArgument" u32, and the remain/elapsed is in party stats (hence the reverting when boxed)
PK7: u8 remain, u8 elapsed, u8 max, u8 unused.
PK8: assumedly the same as PK7, given the disassembly hints that it's the same as past games (even though Furfrou and Hoopa are not in SWSH).
2021-02-08 20:26:53 -08:00
Kurt
edfb8fc2ff Add TID/SID fetch for Battle Revolution
Can unlock boxes by setting a nonzero TID/SID

https://projectpokemon.org/home/forums/topic/36582-pok%C3%A9mon-battle-revolution-save-research-thread/?do=findComment&comment=221812
ty Akunoko
2021-01-22 22:55:55 -08:00
Kurt
06e6242944 Update SAV4BR.cs
Uses Big Endian unicode for savefile strings, but pkm strings are big-endian-g4
2021-01-20 22:13:59 -08:00
Kurt
803b8675fe Rework batrev current slot handling
Show all slots even if they're uninitialized. Empty first slots but present second slots caused errors on init.
2021-01-20 20:29:26 -08:00
Kurt
613e6db744 Use StringConverter api consistently; use stringbuilder when possible
Retain a stringbuilder to mutate the string rather than finalizing temporary strings

yields some speed improvements (less gen0 string objects allocated)
2021-01-14 22:50:13 -08:00
Kurt
1138cd44bc Minor rearranging 2021-01-07 18:05:21 -08:00
Kurt
98be0f6739 Target type'd new 2020-12-21 17:17:56 -08:00
Kurt
5729718d68 Simplify ternary byte casts
No longer needed to explicitly cast, thanks c#9 !
2020-12-21 16:53:28 -08:00
Kurt
e72c80613e Extract metadata/state tracking from SaveFile obj 2020-12-05 05:36:23 -08:00
Kurt
32f2703339 Fix entire-box swaps by using correct lengths
Add SIZE_BOXSLOT and update usages
Make SIZE_STORED protected like SIZE_PARTY

probably need to redesign how slot metadata is presented within the savefile...
Closes #2961 ty @Kermalis !
2020-08-07 16:16:10 -07:00
Kurt
287a2ac5c5 Rework handling of bk4 constructor
Can't really detect if it's shuffled or not; just assume it's always unshuffled unless it originates from a save file read. Probably not a perfect solution, but achieves better results.

https://projectpokemon.org/home/forums/topic/56217-error-in-archive-bk4/
2020-03-18 23:34:53 -07:00
Kurt
e21d108fb2 Split PokeCrypto from PKX
All logic in PokeCrypto is separate from the rest of the PKHeX.Core
library; makes it easy to just rip this portion out and reuse in other
projects without needing the entirety of PKHeX.Core logic

optimize out the CheckEncrypted to the actual path, separate methods.
Only usages of this method were with hardcoded Format values, so no
impact
2020-01-04 14:48:39 -08:00
Kurt
02420d3e93
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases

Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization

* Handle bits more obviously without null

* Make SaveFile.BAK explicitly readonly again

* merge constructor methods to have readonly fields

* Inline some properties

* More nullable handling

* Rearrange box actions

define straightforward classes to not have any null properties

* Make extrabyte reference array immutable

* Move tooltip creation to designer

* Rearrange some logic to reduce nesting

* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum

* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case

* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable

* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator

* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever

* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)

* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-16 18:47:31 -07:00
Kurt
1b028198ad
Split gen5-7 saves with inheritance (#2319)
refer to pull request comments for summary
2019-06-08 19:56:11 -07:00
Kurt
e614aa9ac8 Relocate xd/batrev encryption
update some xmldoc too
2019-03-30 21:28:32 -07:00
Kurt
bb8cf5d3d8 Simplify get/decrypt pkm access 2019-03-29 19:43:33 -07:00
Kurt
b1ead9e630 Split StringConverter into smaller pieces
reduces loading time (don't have to allocate conversion arrays when
launching a gen7 game), and separates things to easier to manage
locations

reworks gen3 string encode/decode, no longer does 3->4->5 and 5->4->3;
instead goes straight to the end result without an intermediary format.

String sanitization should probably be broken up rather than reused, oh
well.
2019-03-20 21:50:44 -07:00
Kurt
cffa6e681d Add OT name setter 2019-02-20 21:52:22 -08:00
Kurt
a385a8481d Misc tweak to savefile export
Use flags to request header/footer in the output
gets rid of the DSV/GCI bool arguments
2019-02-18 21:59:57 -08:00
Kurt
258f0f0ad4 Minor refactoring
clean up some gc logic, no functional changes
2019-02-17 10:42:43 -08:00
Kurt
383d4b7700 "" -> string.Empty
be explicit that the string is empty rather than possibly missing
disallow encrypted export for BK4 (they're not encrypted), removes type
check
simplify replaceall in showdownset (don't call ReplaceAll 4x, just get
valid chars and rebuild)
simplify get ribbon sprite name (precompute ToLower and appended values
2019-02-07 21:40:20 -08:00
Kurt
aa022fad40 Misc refactoring
remove some null usages, return an empty array instead
reduce as arg
2019-02-01 23:08:03 -08:00
Kurt
7ab42e7cc2 Misc improvements
remove alloc on gc key advancement; advance keys in place
make g6 sizes an explicit comparison instead of new[].Contains
replace Any/Count with Array.Find calls (removes linq dependency from
savetype detection!)
2019-01-04 00:07:37 -08:00
Kurt
4c1232855f Add getstring method with non-sav data 2018-12-04 22:00:57 -08:00
Kurt
b280ffcfef style updates
should be pretty much it
2018-09-14 22:37:47 -07:00