Commit graph

65 commits

Author SHA1 Message Date
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
a4533b62d8 Reduce size of display-able met location arrays
shaves 5KB off the core DLL
2022-03-20 19:07:33 -07:00
Kurt
5942a74147 Expose SpeciesID3 for CK3/XK3
Closes #3463
Not going to add unobtainable species IDs to the GUI.
2022-03-13 19:53:46 -07:00
Kurt
b20566eb59 Use actual primitive instead of int
Some interfaces aren't needed to be exposed as int
2022-03-05 18:30:35 -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
bedc52943e Trailing commas
No functional change
2021-08-20 13:49:20 -07:00
Kurt
97683932a1 Lowercase method paremeters 2021-07-26 15:31:46 -07:00
Kurt
103aa9aa4b
Revise EncounterArea and EncounterType for clarity (#3228)
EncounterArea now stores a more specific type'd array for encounter slots. Better iteration and less casting, as the nonspecific `Slots` fetch is rarely referenced.

EncounterType renamed to GroundTile to reflect how it actually works in Gen4. Was previously an ambiguous field that was clarified a little; we can describe it a little better now. Keep the GUI the same to not scare the end users.

Change Trash Byte properties to get/set a Span. Trash Byte legality checking easier on the garbage collector?
2021-06-29 20:58:06 -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
aaa69eac15 Rename Gen3 Champ ribbon to be more accurate
been like this since mid 2016

this ribbon can be obtained in either Hoenn or Kanto within Gen3
https://bulbapedia.bulbagarden.net/wiki/List_of_Ribbons_in_the_games#League_Ribbons
2021-04-10 12:09:43 -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
cc43550357 Simplify more expressions 2021-01-04 17:31:43 -08:00
Kurt
09089da14e Use more expression return style
Reduces indentation & bracketing, a bit more concise
2021-01-01 17:08:49 -08:00
Kurt
7523e0e200 Make ContestStat fields byte (from int) 2021-01-01 13:39:08 -08:00
Kurt
e8c23f6644 Simplify some repeated comparisons with expressions
Less prone for bugs since it uses the same value for all comparisons without re-specifying
2020-12-29 00:37:59 -08:00
Kurt
93910df2c6 Use new switch statements 2020-12-23 17:14:38 -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
61dc9a45ae Revise Shadow state detection
Closes #3012
2020-10-06 22:36:27 -07:00
Kurt
a34434f7cb Make pkm.Data a readonly field rather than property 2020-09-26 12:09:02 -07:00
Kurt
01fb233e48 Minor tweaks
Extract some interfaces
Suppress some warning messages with commented reasons if appropriate
2020-09-09 12:47:24 -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
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
afa368823e Minor clean
handle some compiler messages
2020-05-26 16:59:47 -07:00
Kurt
843330a375 Remove unnecessary null checks
this is a null free project /s
dont provide null, else u deserve to get an exception
2020-01-18 16:57:25 -08: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
cefb56a749 Sword/Shield Update 2019-11-15 17:52:08 -08:00
Kurt
fcc993784b Rename abstract pkm inherited class names
leading underscore for a class name = pls no
2019-10-26 12:42:33 -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
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
1d44136e54 Update xd fateful flag leniency
not enough documentation to know what every single flag does; just be
lenient

I assume that flags being present XK3->PK3 will set fateful, so we could
remove that logic...
Exposing bitflags for editing isn't fun for the editor, so just ignore
it behind the fateful bool get/set.

fateful required for all xk3 origin

#2289
2019-05-14 20:14:15 -07:00
Kurt
555e81205d Update fateful encounter read location
Closes #2289
2019-05-14 18:36:48 -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
8a08d32dff Simplify pkm constructors
remove Identifier param. 99% of the time, identifier is not provided,
resulting in a useless call

end result:
provide 'create new' and 'create from' constructors
2019-03-16 18:41:56 -07:00
Kurt
fb76032a39 Remove unnecessary null checks on constructors 2019-03-16 18:23:50 -07:00
Kurt
5765ce8229 Extract gc version IDs to separate logic 2019-03-16 16:48:38 -07:00
Kurt
13a6d16cb9 Relocate checksum/dexform logic 2019-03-16 12:01:21 -07:00
Kurt
ca0e012c5c Add Heal, make status_condition a pkm property
also split out battle box slot offset fetch
if anyone finds where colo&xd store their status bits, lmk 👍
2019-01-11 22:25:48 -08:00
Kurt
ec76bd6b03 Fix ability bit inversion
one of these was not like the other
ty TORNADO (discord)
2019-01-11 08:09:52 -08:00
Kurt
2d774ac7cc Allow dynamic default savefile type load
Make extrabytes a pkm property (don't mutate array pls)
reconfigure startup loading to only initialize after initial load of sav
& pkm (using blanks if not provided)
2018-12-19 22:10:32 -08:00
Kurt
085a6e2a2b Misc cxd format updates
fix friendship for xk3
fix colo fateful read
2018-11-26 19:21:48 -08:00
Kurt
b280ffcfef style updates
should be pretty much it
2018-09-14 22:37:47 -07:00
Kurt
e588565657 Refactoring
reduce pk3/ck3/xk3 logic, share AbilityBit property within _K3, and when
loading, type check (favored over hardcoding individual load cases)
pull some non-gui code from PKMEditor to core/etc for general data
fetching
2018-07-06 17:37:07 -07:00
Kurt
6cff642ff1 Skip format check on pk* init
also remove ck3/xk3 no-op call (no encryption for those formats, like
bk4).
2018-06-04 20:25:54 -07:00
Kurt
6a3b422a14 Fix xd fateful gift pkm
stored as wc3's, make "Version" from IVersion rather than int so that
"WasXD" recognizes it.

Update handling for fateful encounter trade-away cases.

#1970
2018-05-27 10:11:01 -07:00
Kurt
5a3c8f4147 Remove trailing whitespace 2018-05-12 08:41:29 -07:00
Kurt
49d92758c5 xd ribbon fix
lol
2018-03-17 10:36:37 -07:00
Kurt
c5655166bf Add shared pk3/xk3/ck3 class
standard generation 3 pkm content & interactions
generic inter-converter (more efficient than reflection)

update conversion methods; specific format conversion is now in the
object's src file now.

may be worth doing for gen4 pk4<->bk4
2018-02-03 12:42:06 -08:00
Kurt
a1f2f8708a Refactoring
pass identifier on cloning pkm
remove unnecessary ref for passing Data (not modifying array reference)
const some magic numbers
2017-12-27 16:36:24 -08:00
Kurt
3445b46526 Remove unnecessary array cloning
new objects would always clone the input array; only clone on object
cloning (keep the original array reference on initial creation from
bytes)
2017-12-26 21:38:19 -08:00
Kurt
18796d6f92 Misc tweaks
fix bk4 ribbon checks (lacked interface inheritance)
change MN -> UM for get blank save (unused in PKHeX solution)
prevent inheriting from derived pkm classes
2017-12-16 14:11:41 -08:00