Commit graph

215 commits

Author SHA1 Message Date
Kurt
0b32cbf132 Update PKHeX.Core abstractions with latest logic
Co-Authored-By: Matt <17801814+sora10pls@users.noreply.github.com>
Co-Authored-By: SciresM <8676005+SciresM@users.noreply.github.com>
Co-Authored-By: Lusamine <30205550+Lusamine@users.noreply.github.com>
2022-02-04 17:35:15 -08:00
Kurt
9bddc89c07 Use span if possible instead of new arrays 2022-01-07 20:56:44 -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
a2f61166e4 Use System.Memory for BigEndian value reads
Temp testing commit; will improve performance in the future
2021-12-27 13:56:52 -08:00
Kurt
cc8ac7a4f1 Remove unnecessary warning suppression
fixed dat .editorconfig in vs22
Catching general exceptions is okay because this program handles user modified data that can potentially be corrupt.
2021-12-27 12:09:15 -08:00
Kurt
009e37662f
Startup Enhancements, Gen1/2 Save Indication, Export SAV cleaned up (#3275)
* 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.
2021-10-21 22:13:21 -07:00
Kurt
63580a2835 Minor tweaks
For BigEndian we don't have to invert the array access if we just iterate backwards :)
Fix xmldoc for gen1 trades ampersand
Add xmldoc for enc trade classes

No functional change.
2021-09-15 18:13:17 -07:00
Kurt
c6342a163f Minor clean
variable swaps, simplifications
2021-08-20 13:42:25 -07:00
Kurt
59d480c834 Minor tweaks
Discard empty pkm files (species 0) when loading boxes or templates
Add more xmldoc
Simplify some method parameter names for readability
2021-08-05 17:05:39 -07:00
Kurt
ebb47867dd Use FileUtil tryget for pkm from path
GetPKMFormatFromExtension is now only used once internally.
2021-08-05 16:29:32 -07:00
Kurt
a10b35190c Minor tweaks
off by 1 max range for gen2 slot -> pk2
SetRandomIVs already sets IVs inside the method, retval is for knowing what the new value sare
show WC8 restricted version rather than defaulting to SH
pass the rand object rather than fetching for the current thread every loop for Unown & random IV shuffling
Use ToLowerInvariant for resource fetching, should resolve the turkish issue
Check typeof(T) first, not that we check for ToolStripItem or ContextMenuStrip with this function.
2021-06-24 00:36:04 -07:00
Kurt
3e7775fc44
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately

Don't store within the object, track the slot origin data separately.

Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.

- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code

* Remove WasLink virtual in PKM

Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.

* Use Fateful to directly check gen5 mysterygift origins

No other encounter types in gen5 apply Fateful

* Simplify double ball comparison

Used to be separate for deferral cases, now no longer needed to be separate.

* Grab move/relearn reference and update locally

Fix relearn move identifier

* Inline defog HM transfer preference check

HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.

* Extract more met location metadata checks: WasBredEgg

* Replace Console.Write* with Debug.Write*

There's no console output UI, so don't include them in release builds.

* Inline WasGiftEgg, WasEvent, and WasEventEgg logic

Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-22 20:23:48 -07:00
Kurt
9e427ad9a0 Update translatables with latest 2021-06-15 20:01:01 -07:00
Kurt
8c970ec991 Minor tweaks
no functional change, readability++
add more xmldoc
2021-06-03 12:04:19 -07:00
Kurt
138501da2f Minor clean
Condense some expressions
Use less linq
Rename some fields
2021-05-29 15:31:47 -07:00
Kurt
b2e4ca393b Minor perf improvements
GetHexStringFromBytes: don't allocate temp slice array on heap
Tile: Span Slice toarray rather than new+copy
2021-05-23 10:56:25 -07:00
Kurt
904ba8787a Uppercase gamesync ID
ok matt
2021-05-21 19:24:30 -07:00
Kurt
fc8f9ebd56 Add first row for subregions, remove header from countries txt 2021-05-19 09:36:20 -07:00
Kurt
99f0978630 Extract random date to util 2021-05-18 16:58:53 -07:00
Kurt
4e12e54028 Replace regex parse with string find
Only remaining uses of regex in the sln are wordfilter (required), and unescape for QR replies from web api.

This is slightly faster -- cover all cases if the response json changes (shouldn't).
2021-05-15 12:39:37 -07:00
Kurt
ad4aec3439 Improve resource loading speed by precomputing full manifest lookup
no longer needing to compare manifest names with case insensitivity before finding the manifest name.
muh startup speed
2021-05-15 11:56:06 -07:00
Kurt
44affe3caa Add flag unit tests, more xmldoc 2021-05-15 11:32:25 -07:00
Kurt
acdbda4e12 Split DateUtil from Util class 2021-05-14 16:46:48 -07:00
Kurt
3ac1882151 Move BinaryCodedDecimal conversions to separate class
Add unit tests, clarify names
2021-05-14 16:32:26 -07:00
Kurt
50b15cd740 Use range/index
More in line with modernizing the codebase with latest c# syntax

improve web-qr decode speed slightly (no linq skiptake)
get money/coin mask without a temporary string (lol performance)
2021-05-14 15:30:55 -07:00
Kurt
014835ed14 Add BigEndian span conversions 2021-05-14 12:23:12 -07:00
Kurt
013aac602f Don't clone string resources on fetch
Hardcode egg names, don't rely on string resource loading order for SpeciesNames to get an un-mutated copy.

fixes the infrequent race condition for legality unit tests
2021-05-10 18:41:01 -07:00
Kurt
ef4857fa9f Improve perf of byte->hexstring parse
just use a stringbuilder
2021-05-10 16:07:25 -07:00
Kurt
01f75f8441 Add test for hex string (arbitrary length) convert 2021-05-09 23:33:54 -07:00
Kurt
96d941db69 Preformat csv files, remove header
Shaves off a few kb
2021-05-09 15:47:21 -07:00
Kurt
f25ad054ef Selectively TrimEnd without extra robust logic
TrimEnd has some loops and stuff which isn't necessary for single-char, single-time trims
2021-05-09 13:21:59 -07:00
Kurt
31142ee297 Replace some linq usage with direct logic 2021-05-06 23:26:38 -07:00
Kurt
f063014879 Improve clarity of plugin load failures 2021-05-02 18:27:04 -07:00
Kurt
0d45075d4b
Rewrite settings handling; enhance some user experiences (#3193)
- Settings now stored as json next to exe
- Settings now exposes all legality checking setttings that can be changed
- Slot hovering now can play cries in MGDB/PKMDB/etc, not just the main boxes.
- Enhanced hover text for mystery gifts and encounters that have movesets
- Show recently loaded save files in ctrl-f browser
- Toggle auto-load savefile setting to be none/detect-latest/last-loaded
- Custom extensions & extra backup paths can now be configured directly in the json settings
- Settings editor now uses propertygrid & tabs.
2021-04-11 18:09:54 -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
41096fb56e Minor xmldoc / usage updates 2021-02-21 15:01:28 -08:00
Kurt
680e8b711d Add some code analysis for try-return with nullable out 2021-01-17 00:05:07 -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
934316d68d Simplify some expressions for game datasources
Reduce allocations for ball
Use a clean switch expression for version->met list
2020-12-28 13:32:36 -08:00
Kurt
d225f3391a Split up DataUtil to separate files
ya i know there's already a localizeutil class, whatever
2020-12-21 19:13:18 -08:00
Kurt
98be0f6739 Target type'd new 2020-12-21 17:17:56 -08:00
Kurt
0303eada32 this is not that
clearer than before, yay
2020-12-21 17:12:39 -08:00
Kurt
6d030831ab Bump PKHeX.Core to C#9 language version
Add FrameworkUtil.cs which is compiled if the build isn't net5+, needed to support init setters & records
2020-12-21 16:52:11 -08:00
Kurt
62018cce1a Unify concepts with different names
AltForm & Form & Forme => Form
GenNumber & Generation => Generation

Extract out SpeciesForm interface, and re-add IGeneration

For those using PKHeX as a dependency, this should be a pretty straightforward manual replacement... GenNumber and AltForm should be quick find-replace`s.
2020-12-10 20:42:30 -08:00
Kurt
23e765e550 Add opening for rental team dumps
Dunno why anyone would want these, lol
Closes #3074
2020-11-03 20:12:42 -08:00
Kurt
7132750c9b Placeholder crown tundra logic
To be updated:
- Tables8: magic numbers for maximums
- IGigantamax: any new gigantamax forms?
- FormConverter: any new forms? (calyrex)
2020-10-10 13:14:32 -07:00
Kurt
2c8e0bc8f7 Add automatic byteswap 2020-09-30 22:46:07 -07:00
Kurt
2b7e06e217 Refactoring
Extract some logic, suppress some compiler messages
2020-09-18 22:11:13 -07:00
Kurt
5d3bc289b6 seal hunting
Mark things as sealed as they shouldn't be inherited from or overriden in a derived class.
2020-09-07 13:51:13 -07:00
Kurt
9191f023a3 Minor clean
Nullability annotations and some logic simplification
2020-09-06 11:24:54 -07:00
Kurt
b03a5f2818 Fix pika beach score reading
fix reads as little endian instead of big endian
fix truncation if editor value from byte => ushort
Closes #2976
2020-09-01 16:05:52 -07:00
Kurt
9c99e7ab7b Add some overloads with 1 less allocation
kinda splitting hairs but whatever
2020-07-19 16:35:52 -05:00
Kurt
9f20aa2f4f Remove unnecessary comparison
in Array.Resize, an array is only created if the size is not equivalent
we're just repeating the same logic; let the jit optimize out the null check
2020-07-19 16:35:31 -05:00
Kurt
808ca8f307 Add a temp size that isn't 100% dlc sized
dunno what RoC did but it exists?
2020-06-19 19:58:56 -05:00
Kurt
36dd5ece21 Initial Isle of Armor support
Co-Authored-By: sciresm <sciresm@users.noreply.github.com>
Co-Authored-By: Matt <sora10pls@users.noreply.github.com>
Co-Authored-By: Archit Date <architdate@gmail.com>
2020-06-19 18:51:15 -05:00
Kurt
2cdb5d26db Clean up some method signatures
rename things to be a little more consistent in naming conventions
2020-06-16 21:46:22 -05:00
Kurt
09cbe47240 Add battle tree scout edits
Closes #2833
2020-05-24 18:31:52 -07:00
Kurt
c4326698a5 Add prompt for loading new save with unsaved changes
Closes #2823

remove old gen6 powersaves decrypted-xorpad strings (unused logic)
remove gen8 save fixing beta-pkhex-caused corruption (behaved for 6months)
2020-05-24 11:03:23 -07:00
Kurt
e9406599e0 Remove more unnecessary null checks 2020-04-16 13:11:27 -07:00
Kurt
3100471299 Strip out some unnecessary logic
notnull => no need to check for null manually
2020-04-16 12:58:48 -07:00
Kurt
f4952faa6f Add zh2 trade localization
ye it's different from the zh strings, resulting in different nick/OT

ty @Lusamine !

add another gyarados location while we're here
2020-03-21 10:48:26 -07:00
Kurt
fbd533092d Fix misspelling of the word "Received"
Closes #2757

Co-Authored-By: pi1024e <pi1024e@users.noreply.github.com>
2020-03-12 15:05:34 -07:00
Kurt
e77fa205a0 Add tracker editor 2020-02-12 18:10:03 -08:00
Kurt
c301ce88ab Update Random to be a bit more thread safe
Random isn't thread safe; users of PKHeX.Core.dll might run multithreaded operations (see PKSM + ALM), so we need to have a thread-specific RNG available.

Thread Local get; to improve performance, save the random object locally whenever it is used more than once in the method.

https://docs.microsoft.com/en-us/dotnet/api/system.threading.threadlocal-1?redirectedfrom=MSDN&view=netframework-4.8
https://stackoverflow.com/questions/18333885/threadstatic-v-s-threadlocalt-is-generic-better-than-attribute/18337158#18337158
2020-01-25 21:49:52 -08:00
Kurt
9b062bc770 Remove unused legality check strings
Fix spanish translation messages not being loaded
2020-01-25 17:37:47 -08:00
Kurt
c730dfa1ba Remove empty ushort[1], improve item combo fetch
held item list now allocates less (concat arrays instead of ienumerables)
item list already prunes out of range items, so simplify data source fetch
simplify item list prune (return as list, so we can call RemoveAll instead of Where.ToList)
2020-01-24 23:29:45 -08:00
Kurt
99baa171f4 Indicate known block types at top
Uses reflection to grab a list of defined constants (block keys), and a list of defined block reader classes.

Show name of block in red for a more prominent hint that this block is somewhat editable :)
2020-01-23 20:11:39 -08:00
Kurt
ba5cc26e83 Add indication to which blocks changed
Use reflection to grab all const declarations (private and public), and grab the name of that const. Whenever that block is mentioned in our diff, use the name instead of the key.

Helps identify what changed / remove noise if you don't care about that block.
2020-01-22 17:06:23 -08:00
Kurt
bbd1aff5fe Add new lengths
new format still crashes as block absolute index is now different
should do a different way of loading blocks (key instead of index)
2020-01-09 08:17:41 -08:00
Kurt
852bd2af20 Relocate gui-only text files to WinForms project
Split up the DataUtil method to load text files so that the caching
functionality can be reused
2020-01-03 15:53:48 -08:00
Kurt
fe8e5e3fd9 Add more string search methods
exposes some common string search operations that can be useful for
parsing user entered data
2020-01-02 12:06:58 -08:00
Kurt
35c7195d77 Add custom int/uint parse tests
Correctly handle negative parsing for int by flipping sign at end
optimize out a compare char digit/hex check
2020-01-02 11:11:31 -08:00
Kurt
166f8d82e5 Misc clean
Refactor out some logic, make "en" literals reference one spot (where
appropriate)
2020-01-01 19:07:21 -08:00
Kurt
c6f515c755 Use more performat array join 2019-11-20 17:07:55 -08:00
Kurt
9734010fcd Add unsorted combolist method
#2465
2019-11-19 08:48:44 -08:00
Kurt
025e36c5fc Add treasure items to valid held item table 2019-11-15 19:50:22 -08:00
Kurt
cefb56a749 Sword/Shield Update 2019-11-15 17:52:08 -08:00
Kurt
4be35890e7 Make some usages generic 2019-10-24 18:10:23 -07: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
4baf745af8 Use some c#8 sugar
static local functions
switch expressions
using usings :)

nullable next?
2019-10-07 18:40:09 -07:00
Kurt
94baab1c45
Split off image generation to separate project (#2395)
With the approaching games, PKM sprites are a different size from the 3DS era (as already hinted by LGPE, which has 56x68). It'll be a little easier to manage with this portion of the library walled off from the rest of the codebase.

Eventually the net46 target will use fody or something to merge in these extra dependency dll's automatically to not disturb the usual exe/dll experience.
2019-09-29 09:47:06 -07:00
Kurt
33649d4e02 Fix bitflag clearing for g6/7 gifts
https://projectpokemon.org/home/forums/topic/55092-recevied-list-in-mystery-gift/?tab=comments#comment-249220
ty tsubasa830 !
2019-09-23 19:01:37 -07:00
Kurt
b41f2a3062 Extract logic from PKX
Extract Species Name logic to SpeciesName
Extract Language logic to Language
Remove FormConverter wrapper for string[] fetch
Rearrange some logic to more appropriate locations, update access
modifiers / types
Move some pkm array methods to arrayutil, make generic

PKX.GetVCLanguage was a dupe of _K12.GuessedLanguage() so just expose
the method

PKX is now back to pkm data manip only
2019-09-18 19:58:23 -07:00
Kurt
b9246ece37 Extract y2k datetime logic, also wardrobe tweak
swsh gonna have wardrobe, so rename class and relocate some logic in for
better docs
2019-09-15 22:12:32 -07:00
Kurt
477187a66c Split EncounterArea into game-specific classes
Generating encounters from an EncounterArea is getting a little stupid
without inheritance; each type can now have its own specific behavior
without checking for each individual type of generation pattern. Will
add the abstract method implementations in a future commit

Move some string[] array fetch (for all languages) to Util
2019-09-11 22:06:24 -07:00
Kurt
40cbbaa695 Relocate to more appropriate util class 2019-09-11 18:39:49 -07:00
Kurt
c5ebbbbe15 Minor clean
Magic number -> const usage
default(T) -> default (c#7.x feature)
remove some unused stuff
fix indentation in some spots
2019-09-10 22:07:50 -07:00
Kurt
62d08d7c30 Misc clean
split some methods with optional parameters=null
add more xmldoc
replace some magic numbers -> enum/const references
consolidate common array operations (span soon maybe?)
2019-09-10 00:21:51 -07:00
Kurt
cbd039b18c Extract datasource filtered lists to object
GameInfo has been the storage for the current Game Language environment
When using GameInfo, only one environment is tracked at a time, which is
initialized by the PKM editor (items, moves). Rework things to allow
multiple filtered sources to exist, and keep the filtering logic in
PKHeX.Core for reuse in other programs... ;)
2019-06-22 10:50:32 -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
de774ed131 readonly ComboItem
create once, never modified after
2019-06-01 19:12:41 -07:00
ReignOfComputer
7625ab66b4 Fix Import Count on Load Boxes (#2308)
Calculation was wrong if non-overwrite is selected. Also fixed OCD-triggering extra space in output message.
2019-05-15 09:11:48 -07:00
ReignOfComputer
6c42e3b1bb Enhance Invalid Convert Error (#2305)
Makes it clearer for conversion failure with Pokemon files - prevent confusion with save files.
2019-05-13 15:38:33 -07:00
Kurt
520c9da5c9 Update string loading
Remove usage of linq for sorting, use array.sort for in-place sorting.
Wasteful creating temp sorted buffers then enumerating them to dump into
the list.
2019-04-29 21:55:43 -07:00
Kurt
e1a3c8edb3 Add RTC reset, allows game to define on continue
Closes #2273 , thanks @SatoMew !
2019-03-30 12:34:51 -07:00
Kurt
cce362b98a Relocate FFFF trim (and 0000) to same location 2019-03-20 22:13:09 -07:00
Kurt
fad5e4bdee Expand comboitem loading for simple cases
slightly less gc pressure, precompute capacity
2019-03-18 21:55:33 -07:00
Kurt
82a40cb965 Misc updates
add comboitem list to string[]
add regions list as cached comboitem list
lock resource cache on fetch
extract alola time list generating
2019-03-18 21:34:21 -07:00