mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-03-22 01:55:10 -05:00
Compare commits
No commits in common. "master" and "26.01.07" have entirely different histories.
|
|
@ -5,37 +5,44 @@ root = true
|
|||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
tab_width = 4
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.txt]
|
||||
insert_final_newline = false
|
||||
# Solution Files
|
||||
[*.sln]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
# XML Project Files
|
||||
[*.{slnx,csproj}]
|
||||
[*.csproj]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
tab_width = 2
|
||||
|
||||
# Code Files
|
||||
[*.{cs,vb}]
|
||||
[*.cs]
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
tab_width = 4
|
||||
end_of_line = crlf
|
||||
|
||||
csharp_prefer_braces = when_multiline:warning
|
||||
dotnet_diagnostic.IDE0047.severity = none
|
||||
dotnet_diagnostic.IDE0048.severity = none
|
||||
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:suggest
|
||||
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:suggest
|
||||
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:suggest
|
||||
dotnet_style_parentheses_in_other_operators = always_for_clarity:suggest
|
||||
|
||||
csharp_indent_labels = one_less_than_current
|
||||
csharp_prefer_braces = when_multiline:warning
|
||||
csharp_using_directive_placement = outside_namespace:silent
|
||||
csharp_prefer_simple_using_statement = true:suggestion
|
||||
csharp_prefer_system_threading_lock = true:suggestion
|
||||
csharp_style_namespace_declarations = block_scoped:silent
|
||||
csharp_style_prefer_method_group_conversion = true:silent
|
||||
csharp_style_prefer_top_level_statements = true:silent
|
||||
csharp_style_prefer_primary_constructors = true:suggestion
|
||||
csharp_prefer_system_threading_lock = true:suggestion
|
||||
csharp_style_expression_bodied_methods = false:silent
|
||||
csharp_style_expression_bodied_constructors = false:silent
|
||||
csharp_style_expression_bodied_operators = false:silent
|
||||
|
|
@ -44,20 +51,17 @@ csharp_style_expression_bodied_indexers = true:silent
|
|||
csharp_style_expression_bodied_accessors = true:silent
|
||||
csharp_style_expression_bodied_lambdas = true:silent
|
||||
csharp_style_expression_bodied_local_functions = false:silent
|
||||
csharp_using_directive_placement = outside_namespace:silent
|
||||
dotnet_diagnostic.WFO1000.severity = none
|
||||
|
||||
dotnet_style_operator_placement_when_wrapping = beginning_of_line
|
||||
dotnet_style_coalesce_expression = true:suggestion
|
||||
dotnet_style_null_propagation = true:suggestion
|
||||
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
|
||||
dotnet_style_prefer_auto_properties = true:silent
|
||||
dotnet_style_object_initializer = true:suggestion
|
||||
dotnet_style_collection_initializer = true:suggestion
|
||||
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
|
||||
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
|
||||
dotnet_style_prefer_conditional_expression_over_return = true:silent
|
||||
dotnet_style_explicit_tuple_names = true:suggestion
|
||||
[*.{cs,vb}]
|
||||
#### Naming styles ####
|
||||
|
||||
# Naming styles
|
||||
|
||||
dotnet_naming_style.begins_with_i.required_prefix = I
|
||||
dotnet_naming_style.begins_with_i.capitalization = pascal_case
|
||||
|
||||
[*.{cs,vb}]
|
||||
#### Naming styles ####
|
||||
|
||||
# Naming rules
|
||||
|
|
@ -78,22 +82,45 @@ dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
|
|||
|
||||
dotnet_naming_symbols.interface.applicable_kinds = interface
|
||||
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.interface.required_modifiers =
|
||||
|
||||
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
|
||||
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.types.required_modifiers =
|
||||
|
||||
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
|
||||
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.non_field_members.required_modifiers =
|
||||
|
||||
# Naming styles
|
||||
|
||||
dotnet_naming_style.begins_with_i.required_prefix = I
|
||||
dotnet_naming_style.begins_with_i.required_suffix =
|
||||
dotnet_naming_style.begins_with_i.word_separator =
|
||||
dotnet_naming_style.begins_with_i.capitalization = pascal_case
|
||||
|
||||
dotnet_naming_style.pascal_case.required_prefix =
|
||||
dotnet_naming_style.pascal_case.required_suffix =
|
||||
dotnet_naming_style.pascal_case.word_separator =
|
||||
dotnet_naming_style.pascal_case.capitalization = pascal_case
|
||||
|
||||
dotnet_naming_style.pascal_case.required_prefix =
|
||||
dotnet_naming_style.pascal_case.required_suffix =
|
||||
dotnet_naming_style.pascal_case.word_separator =
|
||||
dotnet_naming_style.pascal_case.capitalization = pascal_case
|
||||
dotnet_style_operator_placement_when_wrapping = beginning_of_line
|
||||
tab_width = 4
|
||||
end_of_line = crlf
|
||||
dotnet_style_coalesce_expression = true:suggestion
|
||||
dotnet_style_null_propagation = true:suggestion
|
||||
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
|
||||
dotnet_style_prefer_auto_properties = true:silent
|
||||
dotnet_style_object_initializer = true:suggestion
|
||||
dotnet_style_collection_initializer = true:suggestion
|
||||
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
|
||||
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
|
||||
dotnet_style_prefer_conditional_expression_over_return = true:silent
|
||||
dotnet_style_explicit_tuple_names = true:suggestion
|
||||
|
||||
# IDE0130: Namespace does not match folder structure
|
||||
dotnet_diagnostic.IDE0130.severity = none
|
||||
|
||||
# WFO1000: Property does not configure the code serialization for its property content.
|
||||
dotnet_diagnostic.WFO1000.severity = none
|
||||
48
.github/README-fr.md
vendored
48
.github/README-fr.md
vendored
|
|
@ -1,48 +1,48 @@
|
|||
PKHeX
|
||||
=====
|
||||

|
||||

|
||||
|
||||
Éditeur de sauvegarde des jeux principaux de la série Pokémon, programmé en [C#](https://fr.wikipedia.org/wiki/C_sharp).
|
||||
Éditeur de sauvegarde de la série de base Pokémon, programmé en [C#](https://fr.wikipedia.org/wiki/C_sharp).
|
||||
|
||||
Les fichiers suivants sont pris en charge :
|
||||
* Fichiers de sauvegarde (« main », \*.sav, \*.dsv, \*.dat, \*.gci, \*.bin)
|
||||
* Fichiers de carte mémoire GameCube (\*.raw, \*.bin) contenant des sauvegardes de jeux Pokémon GameCube.
|
||||
Prend en charge les fichiers suivants:
|
||||
* Enregistrer les fichiers ("main", \*.sav, \*.dsv, \*.dat, \*.gci, \*.bin)
|
||||
* Fichiers de carte mémoire GameCube (\*.raw, \*.bin) contenant des sauvegardes de Pokémon GC.
|
||||
* Fichiers d'entités Pokémon individuels (.pk\*, \*.ck3, \*.xk3, \*.pb7, \*.sk2, \*.bk4, \*.rk4)
|
||||
* Fichiers de Cadeau Mystère (\*.pgt, \*.pcd, \*.pgf, .wc\*), incluant la conversion en .pk\*
|
||||
* Importation d'entités GO Park (\*.gp1), incluant la conversion en .pb7
|
||||
* Importation d'équipes à partir de vidéos de combat 3DS déchiffrées
|
||||
* Transfert d'une génération à l'autre, avec une conversion du format au passage.
|
||||
* Fichiers de cadeau mystère (\*.pgt, \*.pcd, \*.pgf, .wc\*) y compris la conversion en .pk\*
|
||||
* Importation d'entités GO Park (\*.gp1) incluant la conversion en .pb7
|
||||
* Importation d'équipes à partir de 3DS Battle Videos
|
||||
* Transfert d'une génération à l'autre, conversion des formats en cours de route.
|
||||
|
||||
Les données sont affichées sur une interface graphique, permettant de faire des modifications et des sauvegardes. L'interface peut être traduite avec des fichiers de ressources/textes externes afin que différentes langues puissent être prises en charge.
|
||||
Les données sont affichées dans une vue qui peut être modifiée et enregistrée. L'interface peut être traduite avec des fichiers de ressources/textes externes afin que différentes langues puissent être prises en charge.
|
||||
|
||||
Les sets Pokémon Showdown! et les QR codes peuvent être importés/exportés pour faciliter le partage.
|
||||
Les ensembles Pokémon Showdown et les QR codes peuvent être importés/exportés pour faciliter le partage.
|
||||
|
||||
PKHeX demande des fichiers de sauvegarde qui ne sont pas chiffrés par des clés spécifiques aux consoles. Utilisez un gestionnaire de sauvegardes pour importer et exporter des sauvegardes depuis une console ([Checkpoint](https://github.com/FlagBrew/Checkpoint), save_manager, [JKSM](https://github.com/J-D-K/JKSM), ou SaveDataFiler).
|
||||
PKHeX attend des fichiers de sauvegarde qui ne sont pas chiffrés avec des clés spécifiques à la console. Utilisez un gestionnaire de données enregistrées pour importer et exporter des données enregistrées à partir de la console ([Checkpoint](https://github.com/FlagBrew/Checkpoint) ou [JKSM](https://github.com/J-D-K/JKSM)).
|
||||
|
||||
**Nous ne soutenons ni ne tolérons la tricherie aux dépens des autres. N'utilisez pas de Pokémon piratés de manière significative en combat ou en échanges avec ceux qui ne savent pas que des Pokémon piratés sont utilisés.**
|
||||
**Nous ne soutenons ni ne tolérons la tricherie aux dépens des autres. N'utilisez pas de Pokémon piratés de manière significative au combat ou dans des échanges avec ceux qui ne savent pas que des Pokémon piratés sont en cours d'utilisation.**
|
||||
|
||||
## Capture d'écran
|
||||
## Captures d'écran
|
||||
|
||||

|
||||

|
||||
|
||||
## Compilation
|
||||
## Construction
|
||||
|
||||
PKHeX est une application Windows Forms qui nécessite [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0).
|
||||
PKHeX est une application Windows Forms qui nécessite [.NET 10.0](https://dotnet.microsoft.com/download/dotnet/10.0).
|
||||
|
||||
L'exécutable peut être compilé avec n'importe quel compilateur prenant en charge C# 14.
|
||||
L'exécutable peut être construit avec n'importe quel compilateur prenant en charge C# 14.
|
||||
|
||||
### Configurations de la compilation
|
||||
### Construire les configurations
|
||||
|
||||
Utilisez la configuration Debug ou Release lors de la compilation. Aucun code spécifique à une plateforme n'est utilisée dans le programme, donc soyez sans crainte !
|
||||
Utilisez les configurations Debug ou Release lors de la construction. Il n'y a pas de code spécifique à la plate-forme à craindre!
|
||||
|
||||
## Dépendances
|
||||
|
||||
Le code de génération des QR codes de PKHeX est extrait de [QRCoder](https://github.com/codebude/QRCoder), qui est [sous licence MIT](https://github.com/codebude/QRCoder/blob/master/LICENSE.txt).
|
||||
Le code de génération du QR code de PKHeX est extrait de [QRCoder](https://github.com/codebude/QRCoder), qui est [sous licence MIT](https://github.com/codebude/QRCoder/blob/master/LICENSE.txt).
|
||||
|
||||
La collection de sprites chromatiques de PKHeX est tirée de [pokesprite](https://github.com/msikma/pokesprite), qui est [sous licence MIT](https://github.com/msikma/pokesprite/blob/master/LICENSE).
|
||||
La collection de sprites shiny de PKHeX est tirée de [pokesprite](https://github.com/msikma/pokesprite), qui est [sous licence MIT](https://github.com/msikma/pokesprite/blob/master/LICENSE).
|
||||
|
||||
La collection de sprites Légendes Pokémon : Arceus de PKHeX est tirée du projet [National Pokédex - Icon Dex](https://www.deviantart.com/pikafan2000/art/National-Pokedex-Version-Delta-Icon-Dex-824897934), avec son abondance de collaborateurs et de contributeurs.
|
||||
PKHeX's Pokémon Legends: Arceus sprite collection is taken from the [National Pokédex - Icon Dex](https://www.deviantart.com/pikafan2000/art/National-Pokedex-Version-Delta-Icon-Dex-824897934) project and its abundance of collaborators and contributors.
|
||||
|
||||
## IDE
|
||||
|
||||
PKHeX peut être ouvert avec des IDEs tels que [Visual Studio](https://visualstudio.microsoft.com/fr/downloads/) en ouvrant le fichier .sln ou .csproj.
|
||||
PKHeX peut être ouvert avec des IDE tels que [Visual Studio](https://visualstudio.microsoft.com/fr/downloads/) en ouvrant le fichier .sln ou .csproj.
|
||||
|
|
|
|||
2
.github/README-it.md
vendored
2
.github/README-it.md
vendored
|
|
@ -9,7 +9,7 @@ Supporta i seguenti tipi di file:
|
|||
* File di Memory Card GameCube (\*.raw, \*.bin) contenenti File di Salvataggio Pokémon.
|
||||
* File di Entità Pokémon individuali (.pk\*, \*.ck3, \*.xk3, \*.pb7, \*.sk2, \*.bk4, \*.rk4)
|
||||
* File di Dono Segreto (\*.pgt, \*.pcd, \*.pgf, .wc\*) inclusa conversione in .pk\*
|
||||
* Importazione di Entità del GO Park (\*.gp1) inclusa conversione in .pb7
|
||||
* Importazione di Entità del Go Park (\*.gp1) inclusa conversione in .pb7
|
||||
* Importazione di squadre da Video Lotta del 3DS decriptati
|
||||
* Trasferimento da una generazione all'altra, convertendo i formati propriamente.
|
||||
|
||||
|
|
|
|||
2
.github/README-zh-Hans.md
vendored
2
.github/README-zh-Hans.md
vendored
|
|
@ -9,7 +9,7 @@ PKHeX
|
|||
* GameCube 宝可梦游戏存档包含 GameCube 记忆存档 (\*.raw, \*.bin)
|
||||
* 单个宝可梦实体文件 (.pk\*, \*.ck3, \*.xk3, \*.pb7, \*.sk2, \*.bk4, \*.rk4)
|
||||
* 神秘礼物文件 (\*.pgt, \*.pcd, \*.pgf, .wc\*) 并转换为 .pk\*
|
||||
* 导入 GO Park存档 (\*.gp1) 并转换为 .pb7
|
||||
* 导入 Go Park存档 (\*.gp1) 并转换为 .pb7
|
||||
* 从已破解的 3DS 对战视频中导入队伍
|
||||
* 支持宝可梦在不同世代的间转移,并转换文件格式
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<Project>
|
||||
<PropertyGroup>
|
||||
<Version>26.03.20</Version>
|
||||
<Version>26.01.07</Version>
|
||||
<LangVersion>14</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<NeutralLanguage>en</NeutralLanguage>
|
||||
|
|
|
|||
|
|
@ -69,15 +69,25 @@ public void SetMoves(ReadOnlySpan<ushort> input, bool maxPP = false)
|
|||
/// <summary>
|
||||
/// Updates the individual PP count values for each move slot based on the maximum possible value.
|
||||
/// </summary>
|
||||
/// <param name="moves"><see cref="PKM.Moves"/> to use (if already known).</param>
|
||||
/// <param name="moves"><see cref="PKM.Moves"/> to use (if already known). Will fetch the current <see cref="PKM.Moves"/> if not provided.</param>
|
||||
public void SetMaximumPPCurrent(ReadOnlySpan<ushort> moves)
|
||||
{
|
||||
// In some games, move[i] == 0` *should* set 0, but the game's configuration has a non-zero PP for `(None)`
|
||||
// (I'm looking at you, S/V and Z-A)
|
||||
pk.Move1_PP = pk.GetMovePP(moves.Length > 0 ? moves[0] : (ushort)0, pk.Move1_PPUps);
|
||||
pk.Move2_PP = pk.GetMovePP(moves.Length > 1 ? moves[1] : (ushort)0, pk.Move2_PPUps);
|
||||
pk.Move3_PP = pk.GetMovePP(moves.Length > 2 ? moves[2] : (ushort)0, pk.Move3_PPUps);
|
||||
pk.Move4_PP = pk.GetMovePP(moves.Length > 3 ? moves[3] : (ushort)0, pk.Move4_PPUps);
|
||||
pk.Move1_PP = moves.Length == 0 ? 0 : pk.GetMovePP(moves[0], pk.Move1_PPUps);
|
||||
pk.Move2_PP = moves.Length <= 1 ? 0 : pk.GetMovePP(moves[1], pk.Move2_PPUps);
|
||||
pk.Move3_PP = moves.Length <= 2 ? 0 : pk.GetMovePP(moves[2], pk.Move3_PPUps);
|
||||
pk.Move4_PP = moves.Length <= 3 ? 0 : pk.GetMovePP(moves[3], pk.Move4_PPUps);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the individual PP count values for each move slot based on the maximum possible value.
|
||||
/// </summary>
|
||||
/// <param name="moves"><see cref="PKM.Moves"/> to use (if already known). Will fetch the current <see cref="PKM.Moves"/> if not provided.</param>
|
||||
public void SetMaximumPPCurrent(Moveset moves)
|
||||
{
|
||||
pk.Move1_PP = moves.Move1 == 0 ? 0 : pk.GetMovePP(moves.Move1, pk.Move1_PPUps);
|
||||
pk.Move2_PP = moves.Move2 == 0 ? 0 : pk.GetMovePP(moves.Move2, pk.Move2_PPUps);
|
||||
pk.Move3_PP = moves.Move3 == 0 ? 0 : pk.GetMovePP(moves.Move3, pk.Move3_PPUps);
|
||||
pk.Move4_PP = moves.Move4 == 0 ? 0 : pk.GetMovePP(moves.Move4, pk.Move4_PPUps);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,29 +107,21 @@ public void SetMasteredFlag(Learnset learn, Learnset mastery, byte level, int in
|
|||
if (shop.GetMasteredRecordFlag(index))
|
||||
return;
|
||||
|
||||
if (learn.TryGetLevelLearnMove(move, out var learnLevel))
|
||||
if (learn.TryGetLevelLearnMove(move, out var learnLevel) && level < learnLevel) // Can't learn it yet; must purchase.
|
||||
{
|
||||
if (level < learnLevel) // Can't learn it yet; must purchase.
|
||||
{
|
||||
shop.SetPurchasedRecordFlag(index, true);
|
||||
shop.SetMasteredRecordFlag(index, true);
|
||||
return;
|
||||
}
|
||||
if (mastery.TryGetLevelLearnMove(move, out var masterLevel) && level < masterLevel) // Can't master it yet; must Seed of Mastery
|
||||
shop.SetMasteredRecordFlag(index, true);
|
||||
// Otherwise, is innately mastered, no need to force the flag.
|
||||
}
|
||||
else // Can't learn it without purchasing.
|
||||
{
|
||||
if (shop.GetPurchasedRecordFlag(index))
|
||||
shop.SetMasteredRecordFlag(index, true);
|
||||
shop.SetPurchasedRecordFlag(index, true);
|
||||
shop.SetMasteredRecordFlag(index, true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mastery.TryGetLevelLearnMove(move, out var masterLevel) && level < masterLevel) // Can't master it yet; must Seed of Mastery
|
||||
shop.SetMasteredRecordFlag(index, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the "mastered" move shop flag for the encounter.
|
||||
/// </summary>
|
||||
public void SetEncounterMasteryFlags(ReadOnlySpan<ushort> moves, Learnset mastery, byte metLevel, ushort alphaMove)
|
||||
public void SetEncounterMasteryFlags(ReadOnlySpan<ushort> moves, Learnset mastery, byte level)
|
||||
{
|
||||
var permit = shop.Permit;
|
||||
var possible = permit.RecordPermitIndexes;
|
||||
|
|
@ -145,14 +137,7 @@ public void SetEncounterMasteryFlags(ReadOnlySpan<ushort> moves, Learnset master
|
|||
// and it is high enough level to master it, the game will automatically
|
||||
// give it the "Mastered" flag but not the "Purchased" flag
|
||||
// For moves that are not in the learnset, set as mastered.
|
||||
if (!mastery.TryGetLevelLearnMove(move, out var masteryLevel) || metLevel >= masteryLevel)
|
||||
shop.SetMasteredRecordFlag(index, true);
|
||||
}
|
||||
|
||||
if (alphaMove != 0)
|
||||
{
|
||||
var index = possible.IndexOf(alphaMove);
|
||||
if (index != -1)
|
||||
if (!mastery.TryGetLevelLearnMove(move, out var masteryLevel) || level >= masteryLevel)
|
||||
shop.SetMasteredRecordFlag(index, true);
|
||||
}
|
||||
}
|
||||
|
|
@ -160,28 +145,14 @@ public void SetEncounterMasteryFlags(ReadOnlySpan<ushort> moves, Learnset master
|
|||
/// <summary>
|
||||
/// Sets the "purchased" move shop flag for all possible moves.
|
||||
/// </summary>
|
||||
public void SetPurchasedFlagsAll(PKM pk)
|
||||
public void SetPurchasedFlagsAll()
|
||||
{
|
||||
var (learn, _) = LearnSource8LA.GetLearnsetAndMastery(pk.Species, pk.Form);
|
||||
var level = pk.CurrentLevel;
|
||||
var alpha = pk is PA8 pa ? pa.AlphaMove : (ushort)0;
|
||||
|
||||
var permit = shop.Permit;
|
||||
for (int index = 0; index < permit.RecordCountUsed; index++)
|
||||
{
|
||||
var allowed = permit.IsRecordPermitted(index);
|
||||
if (!allowed)
|
||||
continue;
|
||||
|
||||
// If it can learn it naturally, it can't be purchased anymore.
|
||||
var move = permit.RecordPermitIndexes[index];
|
||||
if (learn.TryGetLevelLearnMove(move, out var learnLevel) && learnLevel <= level)
|
||||
continue;
|
||||
|
||||
// Skip purchasing alpha moves, even though it was possible on early versions of the game.
|
||||
if (move == alpha)
|
||||
continue;
|
||||
|
||||
shop.SetPurchasedRecordFlag(index, true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ public static string GetStringFromForm(byte form, GameStrings strings, ushort sp
|
|||
if (form == 0)
|
||||
return string.Empty;
|
||||
|
||||
var result = FormConverter.GetStringFromForm(species, form, strings, genderForms, context);
|
||||
var result = FormConverter.GetStringFromForm(form, strings, species, genderForms, context);
|
||||
if (result.Length == 0)
|
||||
return string.Empty;
|
||||
|
||||
|
|
|
|||
|
|
@ -142,8 +142,6 @@ private void ParseLines(SpanLineEnumerator lines, BattleTemplateLocalization loc
|
|||
first = false;
|
||||
continue;
|
||||
}
|
||||
if (trim.Length == 0)
|
||||
break;
|
||||
LogError(LineLength, line);
|
||||
continue;
|
||||
}
|
||||
|
|
@ -299,35 +297,35 @@ private void ParseLineAbilityBracket(ReadOnlySpan<char> line, GameStrings locali
|
|||
Ability = abilityIndex;
|
||||
}
|
||||
|
||||
private bool ParseEntry(BattleTemplateToken token, ReadOnlySpan<char> input, BattleTemplateLocalization localization) => token switch
|
||||
private bool ParseEntry(BattleTemplateToken token, ReadOnlySpan<char> value, BattleTemplateLocalization localization) => token switch
|
||||
{
|
||||
BattleTemplateToken.Ability => ParseLineAbility(input, localization.Strings.abilitylist),
|
||||
BattleTemplateToken.Nature => ParseLineNature(input, localization.Strings.natures),
|
||||
BattleTemplateToken.Ability => ParseLineAbility(value, localization.Strings.abilitylist),
|
||||
BattleTemplateToken.Nature => ParseLineNature(value, localization.Strings.natures),
|
||||
BattleTemplateToken.Shiny => Shiny = true,
|
||||
BattleTemplateToken.Gigantamax => CanGigantamax = true,
|
||||
BattleTemplateToken.HeldItem => ParseItemName(input, localization.Strings),
|
||||
BattleTemplateToken.Nickname => ParseNickname(input),
|
||||
BattleTemplateToken.Gender => ParseGender(input, localization.Config),
|
||||
BattleTemplateToken.Friendship => ParseFriendship(input),
|
||||
BattleTemplateToken.EVs => ParseLineEVs(input, localization),
|
||||
BattleTemplateToken.IVs => ParseLineIVs(input, localization.Config),
|
||||
BattleTemplateToken.Level => ParseLevel(input),
|
||||
BattleTemplateToken.DynamaxLevel => ParseDynamax(input),
|
||||
BattleTemplateToken.TeraType => ParseTeraType(input, localization.Strings.types),
|
||||
BattleTemplateToken.HeldItem => ParseItemName(value, localization.Strings),
|
||||
BattleTemplateToken.Nickname => ParseNickname(value),
|
||||
BattleTemplateToken.Gender => ParseGender(value, localization.Config),
|
||||
BattleTemplateToken.Friendship => ParseFriendship(value),
|
||||
BattleTemplateToken.EVs => ParseLineEVs(value, localization),
|
||||
BattleTemplateToken.IVs => ParseLineIVs(value, localization.Config),
|
||||
BattleTemplateToken.Level => ParseLevel(value),
|
||||
BattleTemplateToken.DynamaxLevel => ParseDynamax(value),
|
||||
BattleTemplateToken.TeraType => ParseTeraType(value, localization.Strings.types),
|
||||
_ => false,
|
||||
};
|
||||
|
||||
private bool ParseLineAbility(ReadOnlySpan<char> input, ReadOnlySpan<string> abilityNames)
|
||||
private bool ParseLineAbility(ReadOnlySpan<char> value, ReadOnlySpan<string> abilityNames)
|
||||
{
|
||||
var index = StringUtil.FindIndexIgnoreCase(abilityNames, input);
|
||||
var index = StringUtil.FindIndexIgnoreCase(abilityNames, value);
|
||||
if (index < 0)
|
||||
{
|
||||
LogError(AbilityUnrecognized, input);
|
||||
LogError(AbilityUnrecognized, value);
|
||||
return false;
|
||||
}
|
||||
if (Ability != -1 && Ability != index)
|
||||
{
|
||||
LogError(AbilityAlreadySpecified, input);
|
||||
LogError(AbilityAlreadySpecified, value);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -335,21 +333,21 @@ private bool ParseLineAbility(ReadOnlySpan<char> input, ReadOnlySpan<string> abi
|
|||
return true;
|
||||
}
|
||||
|
||||
private bool ParseLineNature(ReadOnlySpan<char> input, ReadOnlySpan<string> natureNames)
|
||||
private bool ParseLineNature(ReadOnlySpan<char> value, ReadOnlySpan<string> natureNames)
|
||||
{
|
||||
var index = StringUtil.FindIndexIgnoreCase(natureNames, input);
|
||||
var index = StringUtil.FindIndexIgnoreCase(natureNames, value);
|
||||
if (index < 0)
|
||||
return false;
|
||||
|
||||
var nature = (Nature)index;
|
||||
if (!nature.IsFixed)
|
||||
if (!nature.IsFixed())
|
||||
{
|
||||
LogError(NatureUnrecognized, input);
|
||||
LogError(NatureUnrecognized, value);
|
||||
return false;
|
||||
}
|
||||
if (Nature.IsFixed && Nature != nature)
|
||||
if (Nature != Nature.Random && Nature != nature)
|
||||
{
|
||||
LogError(NatureAlreadySpecified, input);
|
||||
LogError(NatureAlreadySpecified, value);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -357,23 +355,23 @@ private bool ParseLineNature(ReadOnlySpan<char> input, ReadOnlySpan<string> natu
|
|||
return true;
|
||||
}
|
||||
|
||||
private bool ParseNickname(ReadOnlySpan<char> input)
|
||||
private bool ParseNickname(ReadOnlySpan<char> value)
|
||||
{
|
||||
if (input.Length == 0)
|
||||
if (value.Length == 0)
|
||||
return false;
|
||||
// ignore length, but generally should be <= the Context's max length
|
||||
Nickname = input.ToString();
|
||||
Nickname = value.ToString();
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ParseGender(ReadOnlySpan<char> input, BattleTemplateConfig cfg)
|
||||
private bool ParseGender(ReadOnlySpan<char> value, BattleTemplateConfig cfg)
|
||||
{
|
||||
if (input.Equals(cfg.Male, StringComparison.OrdinalIgnoreCase))
|
||||
if (value.Equals(cfg.Male, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Gender = EntityGender.Male;
|
||||
return true;
|
||||
}
|
||||
if (input.Equals(cfg.Female, StringComparison.OrdinalIgnoreCase))
|
||||
if (value.Equals(cfg.Female, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Gender = EntityGender.Female;
|
||||
return true;
|
||||
|
|
@ -381,43 +379,43 @@ private bool ParseGender(ReadOnlySpan<char> input, BattleTemplateConfig cfg)
|
|||
return false;
|
||||
}
|
||||
|
||||
private bool ParseLevel(ReadOnlySpan<char> input)
|
||||
private bool ParseLevel(ReadOnlySpan<char> value)
|
||||
{
|
||||
if (!byte.TryParse(input.Trim(), out var value))
|
||||
if (!byte.TryParse(value.Trim(), out var val))
|
||||
return false;
|
||||
if ((uint)value is 0 or > Experience.MaxLevel)
|
||||
if ((uint)val is 0 or > Experience.MaxLevel)
|
||||
return false;
|
||||
Level = value;
|
||||
Level = val;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ParseFriendship(ReadOnlySpan<char> input)
|
||||
private bool ParseFriendship(ReadOnlySpan<char> value)
|
||||
{
|
||||
if (!byte.TryParse(input.Trim(), out var value))
|
||||
if (!byte.TryParse(value.Trim(), out var val))
|
||||
return false;
|
||||
Friendship = value;
|
||||
Friendship = val;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ParseDynamax(ReadOnlySpan<char> input)
|
||||
private bool ParseDynamax(ReadOnlySpan<char> value)
|
||||
{
|
||||
Context = EntityContext.Gen8;
|
||||
var value = Util.ToInt32(input);
|
||||
if ((uint)value > 10)
|
||||
var val = Util.ToInt32(value);
|
||||
if ((uint)val > 10)
|
||||
return false;
|
||||
DynamaxLevel = (byte)value;
|
||||
DynamaxLevel = (byte)val;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ParseTeraType(ReadOnlySpan<char> input, ReadOnlySpan<string> types)
|
||||
private bool ParseTeraType(ReadOnlySpan<char> value, ReadOnlySpan<string> types)
|
||||
{
|
||||
Context = EntityContext.Gen9;
|
||||
var value = StringUtil.FindIndexIgnoreCase(types, input);
|
||||
if (value < 0)
|
||||
var val = StringUtil.FindIndexIgnoreCase(types, value);
|
||||
if (val < 0)
|
||||
return false;
|
||||
if (value == TeraTypeUtil.StellarTypeDisplayStringIndex)
|
||||
value = TeraTypeUtil.Stellar;
|
||||
TeraType = (MoveType)value;
|
||||
if (val == TeraTypeUtil.StellarTypeDisplayStringIndex)
|
||||
val = TeraTypeUtil.Stellar;
|
||||
TeraType = (MoveType)val;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -561,7 +559,7 @@ private void PushToken(BattleTemplateToken token, List<string> result, in Battle
|
|||
result.Add(cfg.Push(token, Friendship));
|
||||
break;
|
||||
case BattleTemplateToken.IVs:
|
||||
var maxIV = Context.IsEraGameBoy ? 15 : 31;
|
||||
var maxIV = Context.Generation < 3 ? 15 : 31;
|
||||
if (!IVs.ContainsAnyExcept(maxIV))
|
||||
break; // skip if all IVs are maxed
|
||||
var nameIVs = cfg.GetStatDisplay(settings.StatsIVs);
|
||||
|
|
@ -627,7 +625,7 @@ private void AddEVs(List<string> result, in BattleTemplateExportSettings setting
|
|||
BattleTemplateToken.EVsAppendNature => GetStringStatsNatureAmp(EVs, 0, nameEVs, Nature),
|
||||
_ => GetStringStats(EVs, 0, nameEVs),
|
||||
};
|
||||
if (token is BattleTemplateToken.EVsAppendNature && Nature.IsFixed)
|
||||
if (token is BattleTemplateToken.EVsAppendNature && Nature.IsFixed())
|
||||
line += $" ({settings.Localization.Strings.natures[(int)Nature]})";
|
||||
result.Add(cfg.Push(BattleTemplateToken.EVs, line));
|
||||
}
|
||||
|
|
@ -1028,7 +1026,7 @@ private ReadOnlySpan<char> ParseLineMove(ReadOnlySpan<char> line, GameStrings st
|
|||
return hiddenPowerName;
|
||||
|
||||
HiddenPowerType = (sbyte)hpVal;
|
||||
var maxIV = Context.IsEraGameBoy ? 15 : 31;
|
||||
var maxIV = Context.Generation < 3 ? 15 : 31;
|
||||
if (IVs.ContainsAnyExcept(maxIV))
|
||||
{
|
||||
if (!HiddenPower.SetIVsForType(hpVal, IVs, Context))
|
||||
|
|
@ -1081,7 +1079,7 @@ private bool ParseLineEVs(ReadOnlySpan<char> line, BattleTemplateLocalization lo
|
|||
return false; // invalid line
|
||||
}
|
||||
|
||||
if (Nature.IsFixed) // specified in a separate Nature line
|
||||
if (Nature != Nature.Random) // specified in a separate Nature line
|
||||
LogError(NatureEffortAmpAlreadySpecified, natureName);
|
||||
else
|
||||
Nature = (Nature)natureIndex;
|
||||
|
|
@ -1100,7 +1098,7 @@ private bool ParseLineEVs(ReadOnlySpan<char> line, BattleTemplateLocalization lo
|
|||
result.TreatAmpsAsSpeedNotLast();
|
||||
var ampNature = AdjustNature(result.Plus, result.Minus);
|
||||
success &= ampNature;
|
||||
if (ampNature && currentNature.IsFixed && currentNature != Nature)
|
||||
if (ampNature && currentNature != Nature.Random && currentNature != Nature)
|
||||
{
|
||||
LogError(NatureEffortAmpConflictNature);
|
||||
Nature = currentNature; // revert to original
|
||||
|
|
|
|||
|
|
@ -176,160 +176,95 @@ public StatParseResult TryParse(ReadOnlySpan<char> message, Span<int> result)
|
|||
|
||||
private StatParseResult TryParseIsLeft(ReadOnlySpan<char> message, Span<int> result, char separator, ReadOnlySpan<char> valueGap)
|
||||
{
|
||||
// Parse left-to-right by splitting on separator, then identifying which stat each segment contains.
|
||||
// Format: "StatName Value / StatName Value / ..."
|
||||
var rec = new StatParseResult();
|
||||
|
||||
while (message.Length != 0)
|
||||
for (int i = 0; i < Names.Length; i++)
|
||||
{
|
||||
// Get the next segment
|
||||
ReadOnlySpan<char> segment;
|
||||
var indexSeparator = message.IndexOf(separator);
|
||||
if (message.Length == 0)
|
||||
break;
|
||||
|
||||
var statName = Names[i];
|
||||
var index = message.IndexOf(statName, StringComparison.OrdinalIgnoreCase);
|
||||
if (index == -1)
|
||||
continue;
|
||||
|
||||
if (index != 0)
|
||||
rec.MarkDirty(); // We have something before our stat name, so it isn't clean.
|
||||
|
||||
message = message[statName.Length..].TrimStart();
|
||||
if (valueGap.Length > 0 && message.StartsWith(valueGap))
|
||||
message = message[valueGap.Length..].TrimStart();
|
||||
|
||||
var value = message;
|
||||
|
||||
var indexSeparator = value.IndexOf(separator);
|
||||
if (indexSeparator != -1)
|
||||
{
|
||||
segment = message[..indexSeparator].Trim();
|
||||
message = message[(indexSeparator + 1)..].TrimStart();
|
||||
}
|
||||
value = value[..indexSeparator].Trim();
|
||||
else
|
||||
{
|
||||
segment = message.Trim();
|
||||
message = default;
|
||||
}
|
||||
|
||||
if (segment.Length == 0)
|
||||
{
|
||||
rec.MarkDirty(); // empty segment
|
||||
continue;
|
||||
}
|
||||
|
||||
// Find which stat name this segment contains (should be at the start for IsLeft)
|
||||
var statIndex = TryFindStatNameAtStart(segment, out var statNameLength);
|
||||
if (statIndex == -1)
|
||||
{
|
||||
rec.MarkDirty(); // unrecognized stat
|
||||
continue;
|
||||
}
|
||||
|
||||
// Extract the value after the stat name
|
||||
var value = segment[statNameLength..].TrimStart();
|
||||
if (valueGap.Length > 0 && value.StartsWith(valueGap))
|
||||
value = value[valueGap.Length..].TrimStart();
|
||||
message = default; // everything remaining belongs in the value we are going to parse.
|
||||
|
||||
if (value.Length != 0)
|
||||
{
|
||||
var amped = TryPeekAmp(ref value, ref rec, statIndex);
|
||||
var amped = TryPeekAmp(ref value, ref rec, i);
|
||||
if (amped && value.Length == 0)
|
||||
rec.MarkParsed(statIndex);
|
||||
rec.MarkParsed(index);
|
||||
else
|
||||
TryParse(result, ref rec, value, statIndex);
|
||||
}
|
||||
else if (rec.WasParsed(statIndex))
|
||||
{
|
||||
rec.MarkDirty(); // duplicate stat
|
||||
TryParse(result, ref rec, value, i);
|
||||
}
|
||||
|
||||
if (indexSeparator != -1)
|
||||
message = message[(indexSeparator+1)..].TrimStart();
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (!message.IsWhiteSpace()) // shouldn't be anything left in the message to parse
|
||||
rec.MarkDirty();
|
||||
rec.FinishParse(Names.Length);
|
||||
return rec;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to find a stat name at the start of the segment.
|
||||
/// </summary>
|
||||
/// <param name="segment">Segment to search</param>
|
||||
/// <param name="length">Length of the matched stat name</param>
|
||||
/// <returns>Stat index if found, -1 otherwise</returns>
|
||||
private int TryFindStatNameAtStart(ReadOnlySpan<char> segment, out int length)
|
||||
{
|
||||
for (int i = 0; i < Names.Length; i++)
|
||||
{
|
||||
var name = Names[i];
|
||||
if (segment.StartsWith(name, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
length = name.Length;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
length = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to find a stat name at the end of the segment.
|
||||
/// </summary>
|
||||
/// <param name="segment">Segment to search</param>
|
||||
/// <param name="length">Length of the matched stat name</param>
|
||||
/// <returns>Stat index if found, -1 otherwise</returns>
|
||||
private int TryFindStatNameAtEnd(ReadOnlySpan<char> segment, out int length)
|
||||
{
|
||||
for (int i = 0; i < Names.Length; i++)
|
||||
{
|
||||
var name = Names[i];
|
||||
if (segment.EndsWith(name, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
length = name.Length;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
length = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
private StatParseResult TryParseRight(ReadOnlySpan<char> message, Span<int> result, char separator, ReadOnlySpan<char> valueGap)
|
||||
{
|
||||
// Parse left-to-right by splitting on separator, then identifying which stat each segment contains.
|
||||
// Format: "Value StatName / Value StatName / ..."
|
||||
var rec = new StatParseResult();
|
||||
|
||||
while (message.Length != 0)
|
||||
for (int i = 0; i < Names.Length; i++)
|
||||
{
|
||||
// Get the next segment
|
||||
ReadOnlySpan<char> segment;
|
||||
var indexSeparator = message.IndexOf(separator);
|
||||
if (message.Length == 0)
|
||||
break;
|
||||
|
||||
var statName = Names[i];
|
||||
var index = message.IndexOf(statName, StringComparison.OrdinalIgnoreCase);
|
||||
if (index == -1)
|
||||
continue;
|
||||
|
||||
var value = message[..index].Trim();
|
||||
var indexSeparator = value.LastIndexOf(separator);
|
||||
if (indexSeparator != -1)
|
||||
{
|
||||
segment = message[..indexSeparator].Trim();
|
||||
message = message[(indexSeparator + 1)..].TrimStart();
|
||||
}
|
||||
else
|
||||
{
|
||||
segment = message.Trim();
|
||||
message = default;
|
||||
rec.MarkDirty(); // We have something before our stat name, so it isn't clean.
|
||||
value = value[(indexSeparator + 1)..].TrimStart();
|
||||
}
|
||||
|
||||
if (segment.Length == 0)
|
||||
{
|
||||
rec.MarkDirty(); // empty segment
|
||||
continue;
|
||||
}
|
||||
|
||||
// Find which stat name this segment contains (should be at the end for Right/English style)
|
||||
var statIndex = TryFindStatNameAtEnd(segment, out var statNameLength);
|
||||
if (statIndex == -1)
|
||||
{
|
||||
rec.MarkDirty(); // unrecognized stat
|
||||
continue;
|
||||
}
|
||||
|
||||
// Extract the value before the stat name
|
||||
var value = segment[..^statNameLength].TrimEnd();
|
||||
if (valueGap.Length > 0 && value.EndsWith(valueGap))
|
||||
value = value[..^valueGap.Length].TrimEnd();
|
||||
value = value[..^valueGap.Length];
|
||||
|
||||
if (value.Length != 0)
|
||||
{
|
||||
var amped = TryPeekAmp(ref value, ref rec, statIndex);
|
||||
var amped = TryPeekAmp(ref value, ref rec, i);
|
||||
if (amped && value.Length == 0)
|
||||
rec.MarkParsed(statIndex);
|
||||
rec.MarkParsed(index);
|
||||
else
|
||||
TryParse(result, ref rec, value, statIndex);
|
||||
}
|
||||
else if (rec.WasParsed(statIndex))
|
||||
{
|
||||
rec.MarkDirty(); // duplicate stat
|
||||
TryParse(result, ref rec, value, i);
|
||||
}
|
||||
|
||||
message = message[(index + statName.Length)..].TrimStart();
|
||||
if (message.StartsWith(separator))
|
||||
message = message[1..].TrimStart();
|
||||
}
|
||||
|
||||
if (!message.IsWhiteSpace()) // shouldn't be anything left in the message to parse
|
||||
rec.MarkDirty();
|
||||
rec.FinishParse(Names.Length);
|
||||
return rec;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,535 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Reflection;
|
||||
|
||||
using static PKHeX.Core.BatchEditingUtil;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Base logic for editing entities with user provided <see cref="StringInstruction"/> list.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Caches reflection results for the provided types, and provides utility methods for fetching properties and applying instructions.
|
||||
/// </remarks>
|
||||
public abstract class BatchEditingBase<TObject, TMeta> : IBatchEditor<TObject> where TObject : notnull
|
||||
{
|
||||
private readonly Type[] _types;
|
||||
private readonly string[] _customProperties;
|
||||
private readonly Dictionary<string, PropertyInfo>.AlternateLookup<ReadOnlySpan<char>>[] _props;
|
||||
private readonly Lazy<string[][]> _properties;
|
||||
|
||||
protected BatchEditingBase(Type[] types, string[] customProperties, int expectedMax)
|
||||
{
|
||||
_types = types;
|
||||
_customProperties = customProperties;
|
||||
_props = GetPropertyDictionaries(types, expectedMax);
|
||||
_properties = new Lazy<string[][]>(() => GetPropArray(_props, customProperties));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Property names, indexed by <see cref="Types"/>.
|
||||
/// </summary>
|
||||
public string[][] Properties => _properties.Value;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of supported entity types.
|
||||
/// </summary>
|
||||
public IReadOnlyList<Type> Types => _types;
|
||||
|
||||
protected abstract TMeta CreateMeta(TObject entity);
|
||||
|
||||
protected abstract bool ShouldModify(TObject entity);
|
||||
|
||||
protected abstract bool TryHandleSetOperation(StringInstruction cmd, TMeta info, TObject entity, out ModifyResult result);
|
||||
|
||||
protected abstract bool TryHandleFilter(StringInstruction cmd, TMeta info, TObject entity, out bool isMatch);
|
||||
|
||||
/// <summary>
|
||||
/// Tries to fetch the entity property from the cache of available properties.
|
||||
/// </summary>
|
||||
public bool TryGetHasProperty(TObject entity, ReadOnlySpan<char> name, [NotNullWhen(true)] out PropertyInfo? pi)
|
||||
=> TryGetHasProperty(entity.GetType(), name, out pi);
|
||||
|
||||
/// <summary>
|
||||
/// Tries to fetch the entity property from the cache of available properties.
|
||||
/// </summary>
|
||||
public bool TryGetHasProperty(Type type, ReadOnlySpan<char> name, [NotNullWhen(true)] out PropertyInfo? pi)
|
||||
{
|
||||
var index = _types.IndexOf(type);
|
||||
if (index < 0)
|
||||
{
|
||||
pi = null;
|
||||
return false;
|
||||
}
|
||||
var localProps = _props[index];
|
||||
return localProps.TryGetValue(name, out pi);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of entity types that implement the requested property.
|
||||
/// </summary>
|
||||
public IEnumerable<string> GetTypesImplementing(string property)
|
||||
{
|
||||
for (int i = 0; i < _types.Length; i++)
|
||||
{
|
||||
var type = _types[i];
|
||||
var localProps = _props[i];
|
||||
if (!localProps.TryGetValue(property, out var pi))
|
||||
continue;
|
||||
yield return $"{type.Name}: {pi.PropertyType.Name}";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the entity property using the saved cache of properties.
|
||||
/// </summary>
|
||||
public bool TryGetPropertyType(string propertyName, [NotNullWhen(true)] out string? result, int typeIndex = 0)
|
||||
{
|
||||
if (_customProperties.Contains(propertyName))
|
||||
{
|
||||
result = "Custom";
|
||||
return true;
|
||||
}
|
||||
|
||||
result = null;
|
||||
if (typeIndex == 0)
|
||||
{
|
||||
foreach (var p in _props)
|
||||
{
|
||||
if (!p.TryGetValue(propertyName, out var pi))
|
||||
continue;
|
||||
result = pi.PropertyType.Name;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int index = typeIndex - 1;
|
||||
if ((uint)index >= _props.Length)
|
||||
index = 0;
|
||||
var pr = _props[index];
|
||||
if (!pr.TryGetValue(propertyName, out var info))
|
||||
return false;
|
||||
result = info.PropertyType.Name;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the entity is filtered by the provided filters.
|
||||
/// </summary>
|
||||
public bool IsFilterMatch(IEnumerable<StringInstruction> filters, TObject entity)
|
||||
{
|
||||
var info = CreateMeta(entity);
|
||||
var localProps = GetProps(entity);
|
||||
foreach (var filter in filters)
|
||||
{
|
||||
if (!IsFilterMatch(filter, info, entity, localProps))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to modify the entity.
|
||||
/// </summary>
|
||||
public bool TryModifyIsSuccess(TObject entity, IEnumerable<StringInstruction> filters, IEnumerable<StringInstruction> modifications, Func<TObject, bool>? modifier = null)
|
||||
=> TryModify(entity, filters, modifications, modifier) is ModifyResult.Modified;
|
||||
|
||||
/// <summary>
|
||||
/// Tries to modify the entity using instructions and a custom modifier delegate.
|
||||
/// </summary>
|
||||
public ModifyResult TryModify(TObject entity, IEnumerable<StringInstruction> filters, IEnumerable<StringInstruction> modifications, Func<TObject, bool>? modifier = null)
|
||||
{
|
||||
if (!ShouldModify(entity))
|
||||
return ModifyResult.Skipped;
|
||||
|
||||
var info = CreateMeta(entity);
|
||||
var localProps = GetProps(entity);
|
||||
|
||||
foreach (var cmd in filters)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!IsFilterMatch(cmd, info, entity, localProps))
|
||||
return ModifyResult.Filtered;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine(ex.Message);
|
||||
return ModifyResult.Error;
|
||||
}
|
||||
}
|
||||
|
||||
var error = false;
|
||||
var result = ModifyResult.Skipped;
|
||||
|
||||
if (modifier is { } func)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!func(entity))
|
||||
return ModifyResult.Skipped;
|
||||
result = ModifyResult.Modified;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine(ex.Message);
|
||||
return ModifyResult.Error;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var cmd in modifications)
|
||||
{
|
||||
try
|
||||
{
|
||||
var tmp = SetProperty(cmd, entity, info, localProps);
|
||||
if (tmp == ModifyResult.Error)
|
||||
error = true;
|
||||
else if (tmp != ModifyResult.Skipped)
|
||||
result = tmp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine(ex.Message);
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
if (error)
|
||||
result |= ModifyResult.Error;
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Dictionary<string, PropertyInfo>.AlternateLookup<ReadOnlySpan<char>>[] GetPropertyDictionaries(ReadOnlySpan<Type> types, int expectedMax)
|
||||
{
|
||||
var result = new Dictionary<string, PropertyInfo>.AlternateLookup<ReadOnlySpan<char>>[types.Length];
|
||||
for (int i = 0; i < types.Length; i++)
|
||||
result[i] = GetPropertyDictionary(types[i], ReflectUtil.GetAllPropertyInfoPublic, expectedMax).GetAlternateLookup<ReadOnlySpan<char>>();
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Dictionary<string, PropertyInfo> GetPropertyDictionary(Type type, Func<Type, IEnumerable<PropertyInfo>> selector, int expectedMax)
|
||||
{
|
||||
var dict = new Dictionary<string, PropertyInfo>(expectedMax);
|
||||
var localProps = selector(type);
|
||||
foreach (var p in localProps)
|
||||
dict.TryAdd(p.Name, p);
|
||||
return dict;
|
||||
}
|
||||
|
||||
private static string[][] GetPropArray<T>(Dictionary<string, T>.AlternateLookup<ReadOnlySpan<char>>[] types, ReadOnlySpan<string> extra)
|
||||
{
|
||||
var result = new string[types.Length + 2][];
|
||||
var p = result.AsSpan(1, types.Length);
|
||||
|
||||
for (int i = 0; i < p.Length; i++)
|
||||
{
|
||||
var type = types[i].Dictionary;
|
||||
string[] combine = [..type.Keys, ..extra];
|
||||
combine.Sort();
|
||||
p[i] = combine;
|
||||
}
|
||||
|
||||
var first = p[0];
|
||||
var any = new HashSet<string>(first);
|
||||
var all = new HashSet<string>(first);
|
||||
foreach (var set in p[1..])
|
||||
{
|
||||
any.UnionWith(set);
|
||||
all.IntersectWith(set);
|
||||
}
|
||||
|
||||
var arrAny = any.ToArray();
|
||||
arrAny.Sort();
|
||||
result[0] = arrAny;
|
||||
|
||||
var arrAll = all.ToArray();
|
||||
arrAll.Sort();
|
||||
result[^1] = arrAll;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private Dictionary<string, PropertyInfo>.AlternateLookup<ReadOnlySpan<char>> GetProps(TObject entity)
|
||||
{
|
||||
var type = entity.GetType();
|
||||
var typeIndex = _types.IndexOf(type);
|
||||
return _props[typeIndex];
|
||||
}
|
||||
|
||||
private bool IsFilterMatch(StringInstruction cmd, TMeta info, TObject entity, Dictionary<string, PropertyInfo>.AlternateLookup<ReadOnlySpan<char>> localProps)
|
||||
{
|
||||
if (TryHandleFilter(cmd, info, entity, out var isMatch))
|
||||
return isMatch;
|
||||
return IsPropertyFiltered(cmd, entity, localProps);
|
||||
}
|
||||
|
||||
private static bool IsPropertyFiltered(StringInstruction cmd, TObject entity, Dictionary<string, PropertyInfo>.AlternateLookup<ReadOnlySpan<char>> localProps)
|
||||
{
|
||||
if (!localProps.TryGetValue(cmd.PropertyName, out var pi))
|
||||
return false;
|
||||
if (!pi.CanRead)
|
||||
return false;
|
||||
|
||||
var val = cmd.PropertyValue;
|
||||
if (val.StartsWith(PointerToken) && localProps.TryGetValue(val.AsSpan(1), out var opi))
|
||||
{
|
||||
var result = opi.GetValue(entity) ?? throw new NullReferenceException();
|
||||
return cmd.Comparer.IsCompareOperator(pi.CompareTo(entity, result));
|
||||
}
|
||||
return cmd.Comparer.IsCompareOperator(pi.CompareTo(entity, val));
|
||||
}
|
||||
|
||||
private ModifyResult SetProperty(StringInstruction cmd, TObject entity, TMeta info, Dictionary<string, PropertyInfo>.AlternateLookup<ReadOnlySpan<char>> localProps)
|
||||
{
|
||||
if (cmd.Operation == InstructionOperation.Set && TryHandleSetOperation(cmd, info, entity, out var result))
|
||||
return result;
|
||||
|
||||
if (!localProps.TryGetValue(cmd.PropertyName, out var pi))
|
||||
return ModifyResult.Error;
|
||||
|
||||
if (!pi.CanWrite)
|
||||
return ModifyResult.Error;
|
||||
|
||||
if (cmd.Operation != InstructionOperation.Set)
|
||||
return ApplyNumericOperation(entity, cmd, pi, localProps);
|
||||
|
||||
if (!TryResolveOperandValue(cmd, entity, localProps, out var value))
|
||||
return ModifyResult.Error;
|
||||
|
||||
ReflectUtil.SetValue(pi, entity, value);
|
||||
return ModifyResult.Modified;
|
||||
}
|
||||
|
||||
private static ModifyResult ApplyNumericOperation(TObject entity, StringInstruction cmd, PropertyInfo pi, Dictionary<string, PropertyInfo>.AlternateLookup<ReadOnlySpan<char>> localProps)
|
||||
{
|
||||
if (!pi.CanRead)
|
||||
return ModifyResult.Error;
|
||||
|
||||
if (!TryGetNumericType(pi.PropertyType, out var numericType))
|
||||
return ModifyResult.Error;
|
||||
|
||||
var currentValue = pi.GetValue(entity);
|
||||
if (currentValue is null)
|
||||
return ModifyResult.Error;
|
||||
|
||||
if (!TryResolveOperandValue(cmd, entity, localProps, out var operandValue))
|
||||
return ModifyResult.Error;
|
||||
|
||||
if (!TryApplyNumericOperation(numericType, cmd.Operation, currentValue, operandValue, out var value))
|
||||
return ModifyResult.Error;
|
||||
|
||||
ReflectUtil.SetValue(pi, entity, value);
|
||||
return ModifyResult.Modified;
|
||||
}
|
||||
|
||||
private static bool TryResolveOperandValue(StringInstruction cmd, TObject entity, Dictionary<string, PropertyInfo>.AlternateLookup<ReadOnlySpan<char>> localProps, [NotNullWhen(true)] out object? value)
|
||||
{
|
||||
if (cmd.Random)
|
||||
{
|
||||
value = cmd.RandomValue;
|
||||
return true;
|
||||
}
|
||||
|
||||
var propertyValue = cmd.PropertyValue;
|
||||
if (propertyValue.StartsWith(PointerToken) && localProps.TryGetValue(propertyValue.AsSpan(1), out var opi))
|
||||
{
|
||||
value = opi.GetValue(entity);
|
||||
return value is not null;
|
||||
}
|
||||
|
||||
value = propertyValue;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool TryGetNumericType(Type type, out Type numericType)
|
||||
{
|
||||
numericType = Nullable.GetUnderlyingType(type) ?? type;
|
||||
// bool isNullable = type != numericType;
|
||||
return numericType.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(INumber<>));
|
||||
}
|
||||
|
||||
private static bool TryApplyNumericOperation(Type numericType, InstructionOperation operation, object currentValue, object operandValue, [NotNullWhen(true)] out object? result)
|
||||
{
|
||||
result = null;
|
||||
if (numericType == typeof(byte))
|
||||
return ApplyBinaryInteger<byte>(currentValue, operandValue, operation, out result);
|
||||
if (numericType == typeof(sbyte))
|
||||
return ApplyBinaryInteger<sbyte>(currentValue, operandValue, operation, out result);
|
||||
if (numericType == typeof(short))
|
||||
return ApplyBinaryInteger<short>(currentValue, operandValue, operation, out result);
|
||||
if (numericType == typeof(ushort))
|
||||
return ApplyBinaryInteger<ushort>(currentValue, operandValue, operation, out result);
|
||||
if (numericType == typeof(int))
|
||||
return ApplyBinaryInteger<int>(currentValue, operandValue, operation, out result);
|
||||
if (numericType == typeof(uint))
|
||||
return ApplyBinaryInteger<uint>(currentValue, operandValue, operation, out result);
|
||||
if (numericType == typeof(long))
|
||||
return ApplyBinaryInteger<long>(currentValue, operandValue, operation, out result);
|
||||
if (numericType == typeof(ulong))
|
||||
return ApplyBinaryInteger<ulong>(currentValue, operandValue, operation, out result);
|
||||
if (numericType == typeof(nint))
|
||||
return ApplyBinaryInteger<nint>(currentValue, operandValue, operation, out result);
|
||||
if (numericType == typeof(nuint))
|
||||
return ApplyBinaryInteger<nuint>(currentValue, operandValue, operation, out result);
|
||||
if (numericType == typeof(BigInteger))
|
||||
return ApplyBinaryInteger<BigInteger>(currentValue, operandValue, operation, out result);
|
||||
if (numericType == typeof(float))
|
||||
return ApplyNumeric<float>(currentValue, operandValue, operation, out result);
|
||||
if (numericType == typeof(double))
|
||||
return ApplyNumeric<double>(currentValue, operandValue, operation, out result);
|
||||
if (numericType == typeof(decimal))
|
||||
return ApplyNumeric<decimal>(currentValue, operandValue, operation, out result);
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool ApplyNumeric<T>(object currentValue, object operandValue, InstructionOperation operation, [NotNullWhen(true)] out object? result)
|
||||
where T : INumber<T>
|
||||
{
|
||||
if (operation.IsBitwise)
|
||||
{
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
var success = TryApplyNumericOperationCore<T>(operation, currentValue, operandValue, out var typed);
|
||||
result = typed;
|
||||
return success;
|
||||
}
|
||||
|
||||
private static bool ApplyBinaryInteger<T>(object currentValue, object operandValue, InstructionOperation operation, [NotNullWhen(true)] out object? result)
|
||||
where T : IBinaryInteger<T>
|
||||
{
|
||||
var success = operation.IsBitwise
|
||||
? TryApplyBinaryIntegerOperationCore<T>(operation, currentValue, operandValue, out var typed)
|
||||
: TryApplyNumericOperationCore(operation, currentValue, operandValue, out typed);
|
||||
result = typed;
|
||||
return success;
|
||||
}
|
||||
|
||||
private static bool TryApplyNumericOperationCore<T>(InstructionOperation operation, object currentValue, object operandValue, [NotNullWhen(true)] out T? result)
|
||||
where T : INumber<T>
|
||||
{
|
||||
if (!TryConvertNumeric<T>(currentValue, out var left) || !TryConvertNumeric<T>(operandValue, out var right))
|
||||
{
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
return TryApplyNumericOperationCore(operation, left, right, out result);
|
||||
}
|
||||
|
||||
private static bool TryApplyNumericOperationCore<T>(InstructionOperation operation, T left, T right, [NotNullWhen(true)] out T? result)
|
||||
where T : INumber<T>
|
||||
{
|
||||
try
|
||||
{
|
||||
result = operation switch
|
||||
{
|
||||
InstructionOperation.Add => left + right,
|
||||
InstructionOperation.Subtract => left - right,
|
||||
InstructionOperation.Multiply => left * right,
|
||||
InstructionOperation.Divide => left / right,
|
||||
InstructionOperation.Modulo => left % right,
|
||||
_ => right,
|
||||
};
|
||||
return true;
|
||||
}
|
||||
catch (DivideByZeroException)
|
||||
{
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryApplyBinaryIntegerOperationCore<T>(InstructionOperation operation, object currentValue, object operandValue, [NotNullWhen(true)] out T? result)
|
||||
where T : IBinaryInteger<T>
|
||||
{
|
||||
if (!TryConvertNumeric<T>(currentValue, out var left) || !TryConvertNumeric<T>(operandValue, out var right))
|
||||
{
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
return TryApplyBinaryIntegerOperationCore(operation, left, right, out result);
|
||||
}
|
||||
|
||||
private static bool TryApplyBinaryIntegerOperationCore<T>(InstructionOperation operation, T left, T right, [NotNullWhen(true)] out T? result)
|
||||
where T : IBinaryInteger<T>
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (operation)
|
||||
{
|
||||
case InstructionOperation.BitwiseAnd:
|
||||
result = left & right;
|
||||
return true;
|
||||
case InstructionOperation.BitwiseOr:
|
||||
result = left | right;
|
||||
return true;
|
||||
case InstructionOperation.BitwiseXor:
|
||||
result = left ^ right;
|
||||
return true;
|
||||
case InstructionOperation.BitwiseShiftLeft:
|
||||
result = left << int.CreateChecked(right);
|
||||
return true;
|
||||
case InstructionOperation.BitwiseShiftRight:
|
||||
result = left >> int.CreateChecked(right);
|
||||
return true;
|
||||
default:
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (OverflowException)
|
||||
{
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryConvertNumeric<T>(object value, [NotNullWhen(true)] out T? result) where T : INumber<T>
|
||||
{
|
||||
if (value is T typed)
|
||||
{
|
||||
result = typed;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (value is string text)
|
||||
{
|
||||
if (T.TryParse(text, CultureInfo.InvariantCulture, out var parsed))
|
||||
{
|
||||
result = parsed;
|
||||
return true;
|
||||
}
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value is IConvertible)
|
||||
{
|
||||
try
|
||||
{
|
||||
var converted = Convert.ChangeType(value, typeof(T), CultureInfo.InvariantCulture);
|
||||
if (converted is T convertedValue)
|
||||
{
|
||||
result = convertedValue;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public static class BatchEditingUtil
|
||||
{
|
||||
public const string PROP_TYPENAME = "ObjectType";
|
||||
public const char PointerToken = '*';
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the object is filtered by the provided <see cref="filters"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Does not use cached reflection; less performant than a cached <see cref="BatchEditingBase{TObject,TMeta}"/> implementation.
|
||||
/// </remarks>
|
||||
/// <param name="filters">Filters which must be satisfied.</param>
|
||||
/// <param name="obj">Object to check.</param>
|
||||
/// <returns>True if <see cref="obj"/> matches all filters.</returns>
|
||||
public static bool IsFilterMatch<T>(IEnumerable<StringInstruction> filters, T obj) where T : notnull
|
||||
{
|
||||
foreach (var cmd in filters)
|
||||
{
|
||||
var name = cmd.PropertyName;
|
||||
var value = cmd.PropertyValue;
|
||||
if (name is PROP_TYPENAME)
|
||||
{
|
||||
var type = obj.GetType();
|
||||
var typeName = type.Name;
|
||||
if (!cmd.Comparer.IsCompareEquivalence(value == typeName))
|
||||
return false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ReflectUtil.HasProperty(obj, name, out var pi))
|
||||
return false;
|
||||
try
|
||||
{
|
||||
if (cmd.Comparer.IsCompareOperator(pi.CompareTo(obj, value)))
|
||||
continue;
|
||||
}
|
||||
// User provided inputs can mismatch the type's required value format, and fail to be compared.
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.WriteLine($"Unable to compare {name} to {value}.");
|
||||
Debug.WriteLine(e.Message);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Reflection;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Provides batch editing helpers for an entity type.
|
||||
/// </summary>
|
||||
public interface IBatchEditor<TObject> where TObject : notnull
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the list of supported entity types.
|
||||
/// </summary>
|
||||
IReadOnlyList<Type> Types { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property names, indexed by <see cref="Types"/>.
|
||||
/// </summary>
|
||||
string[][] Properties { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Tries to fetch the entity property from the cache of available properties.
|
||||
/// </summary>
|
||||
bool TryGetHasProperty(TObject entity, ReadOnlySpan<char> name, [NotNullWhen(true)] out PropertyInfo? pi);
|
||||
|
||||
/// <summary>
|
||||
/// Tries to fetch the entity property from the cache of available properties.
|
||||
/// </summary>
|
||||
bool TryGetHasProperty(Type type, ReadOnlySpan<char> name, [NotNullWhen(true)] out PropertyInfo? pi);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of entity types that implement the requested property.
|
||||
/// </summary>
|
||||
IEnumerable<string> GetTypesImplementing(string property);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the entity property using the saved cache of properties.
|
||||
/// </summary>
|
||||
bool TryGetPropertyType(string propertyName, [NotNullWhen(true)] out string? result, int typeIndex = 0);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the entity is filtered by the provided filters.
|
||||
/// </summary>
|
||||
bool IsFilterMatch(IEnumerable<StringInstruction> filters, TObject entity);
|
||||
|
||||
/// <summary>
|
||||
/// Tries to modify the entity.
|
||||
/// </summary>
|
||||
bool TryModifyIsSuccess(TObject entity, IEnumerable<StringInstruction> filters, IEnumerable<StringInstruction> modifications, Func<TObject, bool>? modifier = null);
|
||||
|
||||
/// <summary>
|
||||
/// Tries to modify the entity using instructions and a custom modifier delegate.
|
||||
/// </summary>
|
||||
ModifyResult TryModify(TObject entity, IEnumerable<StringInstruction> filters, IEnumerable<StringInstruction> modifications, Func<TObject, bool>? modifier = null);
|
||||
}
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
using System;
|
||||
using static PKHeX.Core.InstructionComparer;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Value comparison type
|
||||
/// </summary>
|
||||
public enum InstructionComparer : byte
|
||||
{
|
||||
None,
|
||||
IsEqual,
|
||||
IsNotEqual,
|
||||
IsGreaterThan,
|
||||
IsGreaterThanOrEqual,
|
||||
IsLessThan,
|
||||
IsLessThanOrEqual,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="InstructionComparer"/>
|
||||
/// </summary>
|
||||
public static class InstructionComparerExtensions
|
||||
{
|
||||
extension(InstructionComparer comparer)
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates if the <see cref="comparer"/> is supported by the logic.
|
||||
/// </summary>
|
||||
/// <returns>True if supported, false if unsupported.</returns>
|
||||
public bool IsSupported => comparer switch
|
||||
{
|
||||
IsEqual => true,
|
||||
IsNotEqual => true,
|
||||
IsGreaterThan => true,
|
||||
IsGreaterThanOrEqual => true,
|
||||
IsLessThan => true,
|
||||
IsLessThanOrEqual => true,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the compare operator is satisfied by a boolean comparison result.
|
||||
/// </summary>
|
||||
/// <param name="compareResult">Result from Equals comparison</param>
|
||||
/// <returns>True if satisfied</returns>
|
||||
/// <remarks>Only use this method if the comparison is boolean only. Use the <see cref="IsCompareOperator"/> otherwise.</remarks>
|
||||
public bool IsCompareEquivalence(bool compareResult) => comparer switch
|
||||
{
|
||||
IsEqual => compareResult,
|
||||
IsNotEqual => !compareResult,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the compare operator is satisfied by the <see cref="IComparable{T}.CompareTo"/> result.
|
||||
/// </summary>
|
||||
/// <param name="compareResult">Result from CompareTo</param>
|
||||
/// <returns>True if satisfied</returns>
|
||||
public bool IsCompareOperator(int compareResult) => comparer switch
|
||||
{
|
||||
IsEqual => compareResult is 0,
|
||||
IsNotEqual => compareResult is not 0,
|
||||
IsGreaterThan => compareResult > 0,
|
||||
IsGreaterThanOrEqual => compareResult >= 0,
|
||||
IsLessThan => compareResult < 0,
|
||||
IsLessThanOrEqual => compareResult <= 0,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
using static PKHeX.Core.InstructionOperation;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Operation type for applying a modification.
|
||||
/// </summary>
|
||||
public enum InstructionOperation : byte
|
||||
{
|
||||
Set,
|
||||
Add,
|
||||
Subtract,
|
||||
Multiply,
|
||||
Divide,
|
||||
Modulo,
|
||||
BitwiseAnd,
|
||||
BitwiseOr,
|
||||
BitwiseXor,
|
||||
BitwiseShiftRight,
|
||||
BitwiseShiftLeft,
|
||||
}
|
||||
|
||||
public static class InstructionOperationExtensions
|
||||
{
|
||||
extension(InstructionOperation operation)
|
||||
{
|
||||
public bool IsBitwise => operation switch
|
||||
{
|
||||
BitwiseAnd => true,
|
||||
BitwiseOr => true,
|
||||
BitwiseXor => true,
|
||||
BitwiseShiftRight => true,
|
||||
BitwiseShiftLeft => true,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
}
|
||||
612
PKHeX.Core/Editing/Bulk/BatchEditing.cs
Normal file
612
PKHeX.Core/Editing/Bulk/BatchEditing.cs
Normal file
|
|
@ -0,0 +1,612 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
using static PKHeX.Core.MessageStrings;
|
||||
using static PKHeX.Core.BatchModifications;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Logic for editing many <see cref="PKM"/> with user provided <see cref="StringInstruction"/> list.
|
||||
/// </summary>
|
||||
public static class BatchEditing
|
||||
{
|
||||
public static readonly Type[] Types =
|
||||
[
|
||||
typeof (PK9), typeof (PA9),
|
||||
typeof (PK8), typeof (PA8), typeof (PB8),
|
||||
typeof (PB7),
|
||||
typeof (PK7), typeof (PK6), typeof (PK5), typeof (PK4), typeof(BK4), typeof(RK4),
|
||||
typeof (PK3), typeof (XK3), typeof (CK3),
|
||||
typeof (PK2), typeof (SK2), typeof (PK1),
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Extra properties to show in the list of selectable properties (GUI)
|
||||
/// </summary>
|
||||
private static readonly string[] CustomProperties =
|
||||
[
|
||||
PROP_LEGAL, PROP_TYPENAME, PROP_RIBBONS, PROP_EVS, PROP_CONTESTSTATS, PROP_MOVEMASTERY, PROP_MOVEPLUS,
|
||||
PROP_TYPE1, PROP_TYPE2, PROP_TYPEEITHER,
|
||||
IdentifierContains, nameof(ISlotInfo.Slot), nameof(SlotInfoBox.Box),
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Property names, indexed by <see cref="Types"/>.
|
||||
/// </summary>
|
||||
public static string[][] Properties => GetProperties.Value;
|
||||
|
||||
private static readonly Dictionary<string, PropertyInfo>.AlternateLookup<ReadOnlySpan<char>>[] Props = GetPropertyDictionaries(Types);
|
||||
private static readonly Lazy<string[][]> GetProperties = new(() => GetPropArray(Props, CustomProperties));
|
||||
|
||||
private static Dictionary<string, PropertyInfo>.AlternateLookup<ReadOnlySpan<char>>[] GetPropertyDictionaries(IReadOnlyList<Type> types)
|
||||
{
|
||||
var result = new Dictionary<string, PropertyInfo>.AlternateLookup<ReadOnlySpan<char>>[types.Count];
|
||||
for (int i = 0; i < types.Count; i++)
|
||||
result[i] = GetPropertyDictionary(types[i], ReflectUtil.GetAllPropertyInfoPublic).GetAlternateLookup<ReadOnlySpan<char>>();
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Dictionary<string, PropertyInfo> GetPropertyDictionary(Type type, Func<Type, IEnumerable<PropertyInfo>> selector)
|
||||
{
|
||||
const int expectedMax = 0x200; // currently 0x160 as of 2022
|
||||
var dict = new Dictionary<string, PropertyInfo>(expectedMax);
|
||||
var props = selector(type);
|
||||
foreach (var p in props)
|
||||
dict.TryAdd(p.Name, p);
|
||||
return dict;
|
||||
}
|
||||
|
||||
internal const string CONST_RAND = "$rand";
|
||||
internal const string CONST_SHINY = "$shiny";
|
||||
internal const string CONST_SUGGEST = "$suggest";
|
||||
private const string CONST_BYTES = "$[]";
|
||||
private const char CONST_POINTER = '*';
|
||||
internal const char CONST_SPECIAL = '$';
|
||||
|
||||
internal const string PROP_LEGAL = "Legal";
|
||||
internal const string PROP_TYPENAME = "ObjectType";
|
||||
internal const string PROP_TYPEEITHER = "HasType";
|
||||
internal const string PROP_TYPE1 = "PersonalType1";
|
||||
internal const string PROP_TYPE2 = "PersonalType2";
|
||||
internal const string PROP_RIBBONS = "Ribbons";
|
||||
internal const string PROP_EVS = "EVs";
|
||||
internal const string PROP_CONTESTSTATS = "ContestStats";
|
||||
internal const string PROP_MOVEMASTERY = "MoveMastery";
|
||||
internal const string PROP_MOVEPLUS = "PlusMoves";
|
||||
internal const string IdentifierContains = nameof(IdentifierContains);
|
||||
|
||||
private static string[][] GetPropArray<T>(Dictionary<string, T>.AlternateLookup<ReadOnlySpan<char>>[] types, ReadOnlySpan<string> extra)
|
||||
{
|
||||
// Create a list for all types, [inAny, ..types, inAll]
|
||||
var result = new string[types.Length + 2][];
|
||||
var p = result.AsSpan(1, types.Length);
|
||||
|
||||
for (int i = 0; i < p.Length; i++)
|
||||
{
|
||||
var type = types[i].Dictionary;
|
||||
string[] combine = [..type.Keys, ..extra];
|
||||
Array.Sort(combine);
|
||||
p[i] = combine;
|
||||
}
|
||||
|
||||
// Properties for any PKM
|
||||
// Properties shared by all PKM
|
||||
var first = p[0];
|
||||
var any = new HashSet<string>(first);
|
||||
var all = new HashSet<string>(first);
|
||||
foreach (var set in p[1..])
|
||||
{
|
||||
any.UnionWith(set);
|
||||
all.IntersectWith(set);
|
||||
}
|
||||
|
||||
var arrAny = any.ToArray();
|
||||
Array.Sort(arrAny);
|
||||
result[0] = arrAny;
|
||||
|
||||
var arrAll = all.ToArray();
|
||||
Array.Sort(arrAll);
|
||||
result[^1] = arrAll;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to fetch the <see cref="PKM"/> property from the cache of available properties.
|
||||
/// </summary>
|
||||
/// <param name="pk">Pokémon to check</param>
|
||||
/// <param name="name">Property Name to check</param>
|
||||
/// <param name="pi">Property Info retrieved (if any).</param>
|
||||
/// <returns>True if it has property, false if it does not.</returns>
|
||||
public static bool TryGetHasProperty(PKM pk, ReadOnlySpan<char> name, [NotNullWhen(true)] out PropertyInfo? pi)
|
||||
{
|
||||
var type = pk.GetType();
|
||||
return TryGetHasProperty(type, name, out pi);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to fetch the <see cref="PKM"/> property from the cache of available properties.
|
||||
/// </summary>
|
||||
/// <param name="type">Type to check</param>
|
||||
/// <param name="name">Property Name to check</param>
|
||||
/// <param name="pi">Property Info retrieved (if any).</param>
|
||||
/// <returns>True if it has property, false if it does not.</returns>
|
||||
public static bool TryGetHasProperty(Type type, ReadOnlySpan<char> name, [NotNullWhen(true)] out PropertyInfo? pi)
|
||||
{
|
||||
var index = Types.IndexOf(type);
|
||||
if (index < 0)
|
||||
{
|
||||
pi = null;
|
||||
return false;
|
||||
}
|
||||
var props = Props[index];
|
||||
return props.TryGetValue(name, out pi);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of <see cref="PKM"/> types that implement the requested <see cref="property"/>.
|
||||
/// </summary>
|
||||
public static IEnumerable<string> GetTypesImplementing(string property)
|
||||
{
|
||||
for (int i = 0; i < Types.Length; i++)
|
||||
{
|
||||
var type = Types[i];
|
||||
var props = Props[i];
|
||||
if (!props.TryGetValue(property, out var pi))
|
||||
continue;
|
||||
yield return $"{type.Name}: {pi.PropertyType.Name}";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of the <see cref="PKM"/> property using the saved cache of properties.
|
||||
/// </summary>
|
||||
/// <param name="propertyName">Property Name to fetch the type for</param>
|
||||
/// <param name="result">Type name of the property</param>
|
||||
/// <param name="typeIndex">Type index (within <see cref="Types"/>). Leave empty (0) for a nonspecific format.</param>
|
||||
/// <returns>Short name of the property's type.</returns>
|
||||
public static bool TryGetPropertyType(string propertyName, [NotNullWhen(true)] out string? result, int typeIndex = 0)
|
||||
{
|
||||
if (CustomProperties.Contains(propertyName))
|
||||
{
|
||||
result ="Custom";
|
||||
return true;
|
||||
}
|
||||
|
||||
result = null;
|
||||
if (typeIndex == 0) // Any
|
||||
{
|
||||
foreach (var p in Props)
|
||||
{
|
||||
if (!p.TryGetValue(propertyName, out var pi))
|
||||
continue;
|
||||
result = pi.PropertyType.Name;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int index = typeIndex - 1;
|
||||
if ((uint)index >= Props.Length)
|
||||
index = 0; // All vs Specific
|
||||
var pr = Props[index];
|
||||
if (!pr.TryGetValue(propertyName, out var info))
|
||||
return false;
|
||||
result = info.PropertyType.Name;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the <see cref="StringInstruction"/> list with a context-sensitive value. If the provided value is a string, it will attempt to convert that string to its corresponding index.
|
||||
/// </summary>
|
||||
/// <param name="il">Instructions to initialize.</param>
|
||||
public static void ScreenStrings(IEnumerable<StringInstruction> il)
|
||||
{
|
||||
foreach (var i in il)
|
||||
{
|
||||
var pv = i.PropertyValue;
|
||||
if (pv.All(char.IsDigit))
|
||||
continue;
|
||||
|
||||
if (pv.StartsWith(CONST_SPECIAL) && !pv.StartsWith(CONST_BYTES, StringComparison.Ordinal))
|
||||
{
|
||||
var str = pv.AsSpan(1);
|
||||
if (StringInstruction.IsRandomRange(str))
|
||||
{
|
||||
i.SetRandomRange(str);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
SetInstructionScreenedValue(i);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the <see cref="StringInstruction"/> with a context-sensitive value. If the provided value is a string, it will attempt to convert that string to its corresponding index.
|
||||
/// </summary>
|
||||
/// <param name="i">Instruction to initialize.</param>
|
||||
private static void SetInstructionScreenedValue(StringInstruction i)
|
||||
{
|
||||
ReadOnlySpan<string> set;
|
||||
switch (i.PropertyName)
|
||||
{
|
||||
case nameof(PKM.Species): set = GameInfo.Strings.specieslist; break;
|
||||
case nameof(PKM.HeldItem): set = GameInfo.Strings.itemlist; break;
|
||||
case nameof(PKM.Ability): set = GameInfo.Strings.abilitylist; break;
|
||||
case nameof(PKM.Nature): set = GameInfo.Strings.natures; break;
|
||||
case nameof(PKM.Ball): set = GameInfo.Strings.balllist; break;
|
||||
|
||||
case nameof(PKM.Move1) or nameof(PKM.Move2) or nameof(PKM.Move3) or nameof(PKM.Move4):
|
||||
case nameof(PKM.RelearnMove1) or nameof(PKM.RelearnMove2) or nameof(PKM.RelearnMove3) or nameof(PKM.RelearnMove4):
|
||||
set = GameInfo.Strings.movelist; break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
i.SetScreenedValue(set);
|
||||
}
|
||||
|
||||
private static Dictionary<string, PropertyInfo>.AlternateLookup<ReadOnlySpan<char>> GetProps(PKM pk)
|
||||
{
|
||||
var type = pk.GetType();
|
||||
var typeIndex = Types.IndexOf(type);
|
||||
return Props[typeIndex];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the object is filtered by the provided <see cref="filters"/>.
|
||||
/// </summary>
|
||||
/// <param name="filters">Filters which must be satisfied.</param>
|
||||
/// <param name="pk">Object to check.</param>
|
||||
/// <returns>True if <see cref="pk"/> matches all filters.</returns>
|
||||
public static bool IsFilterMatch(IEnumerable<StringInstruction> filters, PKM pk)
|
||||
{
|
||||
var props = GetProps(pk);
|
||||
foreach (var filter in filters)
|
||||
{
|
||||
if (!IsFilterMatch(filter, pk, props))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the object is filtered by the provided <see cref="filters"/>.
|
||||
/// </summary>
|
||||
/// <param name="filters">Filters which must be satisfied.</param>
|
||||
/// <param name="pk">Object to check.</param>
|
||||
/// <returns>True if <see cref="pk"/> matches all filters.</returns>
|
||||
public static bool IsFilterMatchMeta(IEnumerable<StringInstruction> filters, SlotCache pk)
|
||||
{
|
||||
foreach (var i in filters)
|
||||
{
|
||||
foreach (var filter in BatchFilters.FilterMeta)
|
||||
{
|
||||
if (!filter.IsMatch(i.PropertyName))
|
||||
continue;
|
||||
|
||||
if (!filter.IsFiltered(pk, i))
|
||||
return false;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the object is filtered by the provided <see cref="filters"/>.
|
||||
/// </summary>
|
||||
/// <param name="filters">Filters which must be satisfied.</param>
|
||||
/// <param name="obj">Object to check.</param>
|
||||
/// <returns>True if <see cref="obj"/> matches all filters.</returns>
|
||||
public static bool IsFilterMatch(IEnumerable<StringInstruction> filters, object obj)
|
||||
{
|
||||
foreach (var cmd in filters)
|
||||
{
|
||||
if (cmd.PropertyName is PROP_TYPENAME)
|
||||
{
|
||||
var type = obj.GetType();
|
||||
var typeName = type.Name;
|
||||
if (!cmd.Comparer.IsCompareEquivalence(cmd.PropertyValue == typeName))
|
||||
return false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ReflectUtil.HasProperty(obj, cmd.PropertyName, out var pi))
|
||||
return false;
|
||||
try
|
||||
{
|
||||
if (cmd.Comparer.IsCompareOperator(pi.CompareTo(obj, cmd.PropertyValue)))
|
||||
continue;
|
||||
}
|
||||
// User provided inputs can mismatch the type's required value format, and fail to be compared.
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}.");
|
||||
Debug.WriteLine(e.Message);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to modify the <see cref="PKM"/>.
|
||||
/// </summary>
|
||||
/// <param name="pk">Object to modify.</param>
|
||||
/// <param name="filters">Filters which must be satisfied prior to any modifications being made.</param>
|
||||
/// <param name="modifications">Modifications to perform on the <see cref="pk"/>.</param>
|
||||
/// <returns>Result of the attempted modification.</returns>
|
||||
public static bool TryModify(PKM pk, IEnumerable<StringInstruction> filters, IEnumerable<StringInstruction> modifications)
|
||||
{
|
||||
var result = TryModifyPKM(pk, filters, modifications);
|
||||
return result == ModifyResult.Modified;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to modify the <see cref="BatchInfo"/>.
|
||||
/// </summary>
|
||||
/// <param name="pk">Command Filter</param>
|
||||
/// <param name="filters">Filters which must be satisfied prior to any modifications being made.</param>
|
||||
/// <param name="modifications">Modifications to perform on the <see cref="pk"/>.</param>
|
||||
/// <returns>Result of the attempted modification.</returns>
|
||||
internal static ModifyResult TryModifyPKM(PKM pk, IEnumerable<StringInstruction> filters, IEnumerable<StringInstruction> modifications)
|
||||
{
|
||||
if (!pk.ChecksumValid || pk.Species == 0)
|
||||
return ModifyResult.Skipped;
|
||||
|
||||
var info = new BatchInfo(pk);
|
||||
var props = GetProps(pk);
|
||||
foreach (var cmd in filters)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!IsFilterMatch(cmd, info, props))
|
||||
return ModifyResult.Filtered;
|
||||
}
|
||||
// Swallow any error because this can be malformed user input.
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine(MsgBEModifyFailCompare + " " + ex.Message, cmd.PropertyName, cmd.PropertyValue);
|
||||
return ModifyResult.Error;
|
||||
}
|
||||
}
|
||||
|
||||
var error = false;
|
||||
var result = ModifyResult.Skipped;
|
||||
foreach (var cmd in modifications)
|
||||
{
|
||||
try
|
||||
{
|
||||
var tmp = SetPKMProperty(cmd, info, props);
|
||||
if (tmp == ModifyResult.Error)
|
||||
error = true;
|
||||
else if (tmp != ModifyResult.Skipped)
|
||||
result = tmp;
|
||||
}
|
||||
// Swallow any error because this can be malformed user input.
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine(MsgBEModifyFail + " " + ex.Message, cmd.PropertyName, cmd.PropertyValue);
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
if (error)
|
||||
result |= ModifyResult.Error;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the property if the <see cref="BatchInfo"/> should be filtered due to the <see cref="StringInstruction"/> provided.
|
||||
/// </summary>
|
||||
/// <param name="cmd">Command Filter</param>
|
||||
/// <param name="info">Pokémon to check.</param>
|
||||
/// <param name="props">PropertyInfo cache (optional)</param>
|
||||
/// <returns>True if filtered, else false.</returns>
|
||||
private static ModifyResult SetPKMProperty(StringInstruction cmd, BatchInfo info, Dictionary<string, PropertyInfo>.AlternateLookup<ReadOnlySpan<char>> props)
|
||||
{
|
||||
var pk = info.Entity;
|
||||
if (cmd.PropertyValue.StartsWith(CONST_BYTES, StringComparison.Ordinal))
|
||||
return SetByteArrayProperty(pk, cmd);
|
||||
|
||||
if (cmd.PropertyValue.StartsWith(CONST_SUGGEST, StringComparison.OrdinalIgnoreCase))
|
||||
return SetSuggestedPKMProperty(cmd.PropertyName, info, cmd.PropertyValue);
|
||||
if (cmd is { PropertyValue: CONST_RAND, PropertyName: nameof(PKM.Moves) })
|
||||
return SetSuggestedMoveset(info, true);
|
||||
|
||||
if (SetComplexProperty(pk, cmd))
|
||||
return ModifyResult.Modified;
|
||||
|
||||
if (!props.TryGetValue(cmd.PropertyName, out var pi))
|
||||
return ModifyResult.Error;
|
||||
|
||||
if (!pi.CanWrite)
|
||||
return ModifyResult.Error;
|
||||
|
||||
object val;
|
||||
if (cmd.Random)
|
||||
val = cmd.RandomValue;
|
||||
else if (cmd.PropertyValue.StartsWith(CONST_POINTER) && props.TryGetValue(cmd.PropertyValue.AsSpan(1), out var opi))
|
||||
val = opi.GetValue(pk) ?? throw new NullReferenceException();
|
||||
else
|
||||
val = cmd.PropertyValue;
|
||||
|
||||
ReflectUtil.SetValue(pi, pk, val);
|
||||
return ModifyResult.Modified;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the <see cref="BatchInfo"/> should be filtered due to the <see cref="StringInstruction"/> provided.
|
||||
/// </summary>
|
||||
/// <param name="cmd">Command Filter</param>
|
||||
/// <param name="info">Pokémon to check.</param>
|
||||
/// <param name="props">PropertyInfo cache (optional)</param>
|
||||
/// <returns>True if filter matches, else false.</returns>
|
||||
private static bool IsFilterMatch(StringInstruction cmd, BatchInfo info, Dictionary<string, PropertyInfo>.AlternateLookup<ReadOnlySpan<char>> props)
|
||||
{
|
||||
var match = BatchFilters.FilterMods.Find(z => z.IsMatch(cmd.PropertyName));
|
||||
if (match is not null)
|
||||
return match.IsFiltered(info, cmd);
|
||||
return IsPropertyFiltered(cmd, info.Entity, props);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the <see cref="PKM"/> should be filtered due to the <see cref="StringInstruction"/> provided.
|
||||
/// </summary>
|
||||
/// <param name="cmd">Command Filter</param>
|
||||
/// <param name="pk">Pokémon to check.</param>
|
||||
/// <param name="props">PropertyInfo cache (optional)</param>
|
||||
/// <returns>True if filter matches, else false.</returns>
|
||||
private static bool IsFilterMatch(StringInstruction cmd, PKM pk, Dictionary<string, PropertyInfo>.AlternateLookup<ReadOnlySpan<char>> props)
|
||||
{
|
||||
var match = BatchFilters.FilterMods.Find(z => z.IsMatch(cmd.PropertyName));
|
||||
if (match is not null)
|
||||
return match.IsFiltered(pk, cmd);
|
||||
return IsPropertyFiltered(cmd, pk, props);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the <see cref="PKM"/> should be filtered due to the <see cref="StringInstruction"/> provided.
|
||||
/// </summary>
|
||||
/// <param name="cmd">Command Filter</param>
|
||||
/// <param name="pk">Pokémon to check.</param>
|
||||
/// <param name="props">PropertyInfo cache</param>
|
||||
/// <returns>True if filtered, else false.</returns>
|
||||
private static bool IsPropertyFiltered(StringInstruction cmd, PKM pk, Dictionary<string, PropertyInfo>.AlternateLookup<ReadOnlySpan<char>> props)
|
||||
{
|
||||
if (!props.TryGetValue(cmd.PropertyName, out var pi))
|
||||
return false;
|
||||
if (!pi.CanRead)
|
||||
return false;
|
||||
|
||||
var val = cmd.PropertyValue;
|
||||
if (val.StartsWith(CONST_POINTER) && props.TryGetValue(val.AsSpan(1), out var opi))
|
||||
{
|
||||
var result = opi.GetValue(pk) ?? throw new NullReferenceException();
|
||||
return cmd.Comparer.IsCompareOperator(pi.CompareTo(pk, result));
|
||||
}
|
||||
return cmd.Comparer.IsCompareOperator(pi.CompareTo(pk, val));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="PKM"/> data with a suggested value based on its <see cref="LegalityAnalysis"/>.
|
||||
/// </summary>
|
||||
/// <param name="name">Property to modify.</param>
|
||||
/// <param name="info">Cached info storing Legal data.</param>
|
||||
/// <param name="propValue">Suggestion string which starts with <see cref="CONST_SUGGEST"/></param>
|
||||
private static ModifyResult SetSuggestedPKMProperty(ReadOnlySpan<char> name, BatchInfo info, ReadOnlySpan<char> propValue)
|
||||
{
|
||||
foreach (var mod in BatchMods.SuggestionMods)
|
||||
{
|
||||
if (mod.IsMatch(name, propValue, info))
|
||||
return mod.Modify(name, propValue, info);
|
||||
}
|
||||
return ModifyResult.Error;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="PKM"/> byte array property to a specified value.
|
||||
/// </summary>
|
||||
/// <param name="pk">Pokémon to modify.</param>
|
||||
/// <param name="cmd">Modification</param>
|
||||
private static ModifyResult SetByteArrayProperty(PKM pk, StringInstruction cmd)
|
||||
{
|
||||
Span<byte> dest;
|
||||
switch (cmd.PropertyName)
|
||||
{
|
||||
case nameof(PKM.NicknameTrash) or nameof(PKM.Nickname): dest = pk.NicknameTrash; break;
|
||||
case nameof(PKM.OriginalTrainerTrash): dest = pk.OriginalTrainerTrash; break;
|
||||
case nameof(PKM.HandlingTrainerTrash): dest = pk.HandlingTrainerTrash; break;
|
||||
default:
|
||||
return ModifyResult.Error;
|
||||
}
|
||||
var src = cmd.PropertyValue.AsSpan(CONST_BYTES.Length); // skip prefix
|
||||
StringUtil.LoadHexBytesTo(src, dest, 3);
|
||||
return ModifyResult.Modified;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="PKM"/> property to a non-specific smart value.
|
||||
/// </summary>
|
||||
/// <param name="pk">Pokémon to modify.</param>
|
||||
/// <param name="cmd">Modification</param>
|
||||
/// <returns>True if modified, false if no modifications done.</returns>
|
||||
private static bool SetComplexProperty(PKM pk, StringInstruction cmd)
|
||||
{
|
||||
ReadOnlySpan<char> name = cmd.PropertyName;
|
||||
ReadOnlySpan<char> value = cmd.PropertyValue;
|
||||
|
||||
if (name.StartsWith("IV") && value is CONST_RAND)
|
||||
{
|
||||
SetRandomIVs(pk, name);
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (var mod in BatchMods.ComplexMods)
|
||||
{
|
||||
if (!mod.IsMatch(name, value))
|
||||
continue;
|
||||
mod.Modify(pk, cmd);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="PKM"/> IV(s) to a random value.
|
||||
/// </summary>
|
||||
/// <param name="pk">Pokémon to modify.</param>
|
||||
/// <param name="propertyName">Property to modify</param>
|
||||
private static void SetRandomIVs(PKM pk, ReadOnlySpan<char> propertyName)
|
||||
{
|
||||
if (propertyName is nameof(PKM.IVs))
|
||||
{
|
||||
var la = new LegalityAnalysis(pk);
|
||||
var enc = la.EncounterMatch;
|
||||
if (enc is IFlawlessIVCount { FlawlessIVCount: not 0 } fc)
|
||||
pk.SetRandomIVs(fc.FlawlessIVCount);
|
||||
else if (enc is IFixedIVSet { IVs: {IsSpecified: true} iv})
|
||||
pk.SetRandomIVs(iv);
|
||||
else if (enc is IFlawlessIVCountConditional c && c.GetFlawlessIVCount(pk) is { Max: not 0 } x)
|
||||
pk.SetRandomIVs(Util.Rand.Next(x.Min, x.Max + 1));
|
||||
else
|
||||
pk.SetRandomIVs();
|
||||
return;
|
||||
}
|
||||
|
||||
if (TryGetHasProperty(pk, propertyName, out var pi))
|
||||
{
|
||||
const string IV32 = nameof(PK9.IV32);
|
||||
if (propertyName is IV32)
|
||||
{
|
||||
var value = (uint)Util.Rand.Next(0x3FFFFFFF + 1);
|
||||
if (pk is BK4 bk) // Big Endian, reverse IV ordering
|
||||
{
|
||||
value <<= 2; // flags are the lowest bits, and our random value is still fine.
|
||||
value |= bk.IV32 & 3; // preserve the flags
|
||||
bk.IV32 = value;
|
||||
return;
|
||||
}
|
||||
|
||||
var exist = ReflectUtil.GetValue(pk, IV32);
|
||||
value |= exist switch
|
||||
{
|
||||
uint iv => iv & (3u << 30), // preserve the flags
|
||||
_ => 0,
|
||||
};
|
||||
ReflectUtil.SetValue(pi, pk, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
var value = Util.Rand.Next(pk.MaxIV + 1);
|
||||
ReflectUtil.SetValue(pi, pk, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,23 +8,20 @@ namespace PKHeX.Core;
|
|||
/// <summary>
|
||||
/// Carries out a batch edit and contains information summarizing the results.
|
||||
/// </summary>
|
||||
public sealed class EntityBatchProcessor
|
||||
public sealed class BatchEditor
|
||||
{
|
||||
private int Modified { get; set; }
|
||||
private int Iterated { get; set; }
|
||||
private int Failed { get; set; }
|
||||
|
||||
private static EntityBatchEditor Editor => EntityBatchEditor.Instance;
|
||||
|
||||
/// <summary>
|
||||
/// Tries to modify the <see cref="PKM"/> using instructions and a custom modifier delegate.
|
||||
/// Tries to modify the <see cref="PKM"/>.
|
||||
/// </summary>
|
||||
/// <param name="pk">Object to modify.</param>
|
||||
/// <param name="filters">Filters which must be satisfied prior to any modifications being made.</param>
|
||||
/// <param name="modifications">Modifications to perform on the <see cref="pk"/>.</param>
|
||||
/// <param name="modifier">Custom modifier delegate.</param>
|
||||
/// <returns>Result of the attempted modification.</returns>
|
||||
public bool Process(PKM pk, IEnumerable<StringInstruction> filters, IEnumerable<StringInstruction> modifications, Func<PKM, bool>? modifier = null)
|
||||
public bool Process(PKM pk, IEnumerable<StringInstruction> filters, IEnumerable<StringInstruction> modifications)
|
||||
{
|
||||
if (pk.Species == 0)
|
||||
return false;
|
||||
|
|
@ -36,12 +33,13 @@ public bool Process(PKM pk, IEnumerable<StringInstruction> filters, IEnumerable<
|
|||
return false;
|
||||
}
|
||||
|
||||
var result = Editor.TryModify(pk, filters, modifications, modifier);
|
||||
var result = BatchEditing.TryModifyPKM(pk, filters, modifications);
|
||||
if (result != ModifyResult.Skipped)
|
||||
Iterated++;
|
||||
if (result.HasFlag(ModifyResult.Error))
|
||||
{
|
||||
Failed++;
|
||||
// Still need to fix checksum if another modification was successful.
|
||||
result &= ~ModifyResult.Error;
|
||||
}
|
||||
if (result != ModifyResult.Modified)
|
||||
|
|
@ -75,16 +73,15 @@ public string GetEditorResults(IReadOnlyCollection<StringInstructionSet> sets)
|
|||
/// </summary>
|
||||
/// <param name="lines">Batch instruction line(s)</param>
|
||||
/// <param name="data">Entities to modify</param>
|
||||
/// <param name="modifier">Custom modifier delegate.</param>
|
||||
/// <returns>Editor object if follow-up modifications are desired.</returns>
|
||||
public static EntityBatchProcessor Execute(ReadOnlySpan<string> lines, IEnumerable<PKM> data, Func<PKM, bool>? modifier = null)
|
||||
public static BatchEditor Execute(ReadOnlySpan<string> lines, IEnumerable<PKM> data)
|
||||
{
|
||||
var editor = new EntityBatchProcessor();
|
||||
var editor = new BatchEditor();
|
||||
var sets = StringInstructionSet.GetBatchSets(lines);
|
||||
foreach (var pk in data)
|
||||
{
|
||||
foreach (var set in sets)
|
||||
editor.Process(pk, set.Filters, set.Instructions, modifier);
|
||||
editor.Process(pk, set.Filters, set.Instructions);
|
||||
}
|
||||
|
||||
return editor;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using static PKHeX.Core.EntityBatchEditor;
|
||||
using static PKHeX.Core.BatchEditing;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
|
|
@ -9,7 +9,7 @@ namespace PKHeX.Core;
|
|||
public static class BatchFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// Filters to use for <see cref="EntityBatchEditor"/> that are derived from the <see cref="PKM"/> data.
|
||||
/// Filters to use for <see cref="BatchEditing"/> that are derived from the <see cref="PKM"/> data.
|
||||
/// </summary>
|
||||
public static readonly List<IComplexFilter> FilterMods =
|
||||
[
|
||||
|
|
@ -17,7 +17,7 @@ public static class BatchFilters
|
|||
(pk, cmd) => bool.TryParse(cmd.PropertyValue, out var b) && cmd.Comparer.IsCompareEquivalence(b == new LegalityAnalysis(pk).Valid),
|
||||
(info, cmd) => bool.TryParse(cmd.PropertyValue, out var b) && cmd.Comparer.IsCompareEquivalence(b == info.Legality.Valid)),
|
||||
|
||||
new ComplexFilter(BatchEditingUtil.PROP_TYPENAME,
|
||||
new ComplexFilter(PROP_TYPENAME,
|
||||
(pk, cmd) => cmd.Comparer.IsCompareEquivalence(pk.GetType().Name == cmd.PropertyValue),
|
||||
(info, cmd) => cmd.Comparer.IsCompareEquivalence(info.Entity.GetType().Name == cmd.PropertyValue)),
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ public static class BatchFilters
|
|||
];
|
||||
|
||||
/// <summary>
|
||||
/// Filters to use for <see cref="EntityBatchEditor"/> that are derived from the <see cref="PKM"/> source.
|
||||
/// Filters to use for <see cref="BatchEditing"/> that are derived from the <see cref="PKM"/> source.
|
||||
/// </summary>
|
||||
public static readonly List<IComplexFilterMeta> FilterMeta =
|
||||
[
|
||||
|
|
@ -6,13 +6,12 @@ namespace PKHeX.Core;
|
|||
/// <param name="Entity"> Entity to be modified. </param>
|
||||
public sealed record BatchInfo(PKM Entity)
|
||||
{
|
||||
private LegalityAnalysis? la; // c# 14 replace with get-field
|
||||
|
||||
/// <summary>
|
||||
/// Legality analysis of the entity.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Eagerly evaluate on ctor, so that the initial state is remembered before any modifications may disturb matching.
|
||||
/// </remarks>
|
||||
public readonly LegalityAnalysis Legality = new(Entity);
|
||||
public LegalityAnalysis Legality => la ??= new LegalityAnalysis(Entity);
|
||||
|
||||
/// <inheritdoc cref="LegalityAnalysis.Valid"/>
|
||||
public bool Legal => Legality.Valid;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using static PKHeX.Core.EntityBatchEditor;
|
||||
using static PKHeX.Core.BatchEditing;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Default property provider that uses an <see cref="IBatchEditor{TObject}"/> for reflection.
|
||||
/// </summary>
|
||||
public class BatchPropertyProvider<TEditor, TObject>(TEditor editor) : IPropertyProvider<TObject> where TObject : notnull where TEditor : IBatchEditor<TObject>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BatchPropertyProvider{TEditor, TObject}"/> class with the specified editor.
|
||||
/// </summary>
|
||||
public bool TryGetProperty(TObject obj, string prop, [NotNullWhen(true)] out string? result)
|
||||
{
|
||||
result = null;
|
||||
if (!editor.TryGetHasProperty(obj, prop, out var pi))
|
||||
return false;
|
||||
|
||||
var value = pi.GetValue(obj);
|
||||
result = value?.ToString();
|
||||
return result is not null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,304 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using static PKHeX.Core.BatchModifications;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Logic for editing many <see cref="PKM"/> with user provided <see cref="StringInstruction"/> list.
|
||||
/// </summary>
|
||||
public sealed class EntityBatchEditor() : BatchEditingBase<PKM, BatchInfo>(EntityTypes, EntityCustomProperties, expectedMax: 0x200)
|
||||
{
|
||||
private static readonly Type[] EntityTypes =
|
||||
[
|
||||
typeof (PK9), typeof (PA9),
|
||||
typeof (PK8), typeof (PA8), typeof (PB8),
|
||||
typeof (PB7),
|
||||
typeof (PK7), typeof (PK6), typeof (PK5), typeof (PK4), typeof(BK4), typeof(RK4),
|
||||
typeof (PK3), typeof (XK3), typeof (CK3),
|
||||
typeof (PK2), typeof (SK2), typeof (PK1),
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Extra properties to show in the list of selectable properties (GUI) with special handling.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// These are not necessarily properties of the <see cref="PKM"/> themselves,
|
||||
/// but can be any context-sensitive value related to the <see cref="PKM"/> or its legality,
|
||||
/// such as "Legal" or "HasType". The handling of these properties must be implemented in the <see cref="TryHandleSetOperation"/> and <see cref="TryHandleFilter"/> methods.
|
||||
/// </remarks>
|
||||
private static readonly string[] EntityCustomProperties =
|
||||
[
|
||||
// General
|
||||
BatchEditingUtil.PROP_TYPENAME,
|
||||
|
||||
// Entity/PersonalInfo
|
||||
PROP_LEGAL, PROP_RIBBONS, PROP_EVS, PROP_CONTESTSTATS, PROP_MOVEMASTERY, PROP_MOVEPLUS,
|
||||
PROP_TYPE1, PROP_TYPE2, PROP_TYPEEITHER,
|
||||
|
||||
// SlotCache
|
||||
IdentifierContains, nameof(ISlotInfo.Slot), nameof(SlotInfoBox.Box),
|
||||
];
|
||||
|
||||
public static EntityBatchEditor Instance { get; } = new();
|
||||
|
||||
// Custom Identifiers for special handling.
|
||||
private const string CONST_BYTES = "$[]"; // Define a byte array with separated hex byte values, e.g. "$[]FF,02,03" or "$[]A0 02 0A FF"
|
||||
|
||||
// Custom Values to apply.
|
||||
internal const string CONST_RAND = "$rand";
|
||||
internal const string CONST_SHINY = "$shiny";
|
||||
internal const string CONST_SUGGEST = "$suggest";
|
||||
internal const char CONST_SPECIAL = '$';
|
||||
|
||||
// Custom Properties to change.
|
||||
internal const string PROP_LEGAL = "Legal";
|
||||
internal const string PROP_TYPEEITHER = "HasType";
|
||||
internal const string PROP_TYPE1 = "PersonalType1";
|
||||
internal const string PROP_TYPE2 = "PersonalType2";
|
||||
internal const string PROP_RIBBONS = "Ribbons";
|
||||
internal const string PROP_EVS = "EVs";
|
||||
internal const string PROP_CONTESTSTATS = "ContestStats";
|
||||
internal const string PROP_MOVEMASTERY = "MoveMastery";
|
||||
internal const string PROP_MOVEPLUS = "PlusMoves";
|
||||
internal const string IdentifierContains = nameof(IdentifierContains);
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the <see cref="StringInstruction"/> list with a context-sensitive value. If the provided value is a string, it will attempt to convert that string to its corresponding index.
|
||||
/// </summary>
|
||||
/// <param name="il">Instructions to initialize.</param>
|
||||
public static void ScreenStrings(IEnumerable<StringInstruction> il)
|
||||
{
|
||||
foreach (var i in il)
|
||||
{
|
||||
var pv = i.PropertyValue;
|
||||
if (pv.All(char.IsDigit))
|
||||
continue;
|
||||
|
||||
if (pv.StartsWith(CONST_SPECIAL) && !pv.StartsWith(CONST_BYTES, StringComparison.Ordinal))
|
||||
{
|
||||
var str = pv.AsSpan(1);
|
||||
if (StringInstruction.IsRandomRange(str))
|
||||
{
|
||||
i.SetRandomRange(str);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
SetInstructionScreenedValue(i);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the <see cref="StringInstruction"/> with a context-sensitive value. If the provided value is a string, it will attempt to convert that string to its corresponding index.
|
||||
/// </summary>
|
||||
/// <param name="i">Instruction to initialize.</param>
|
||||
private static void SetInstructionScreenedValue(StringInstruction i)
|
||||
{
|
||||
ReadOnlySpan<string> set;
|
||||
switch (i.PropertyName)
|
||||
{
|
||||
case nameof(PKM.Species): set = GameInfo.Strings.specieslist; break;
|
||||
case nameof(PKM.HeldItem): set = GameInfo.Strings.itemlist; break;
|
||||
case nameof(PKM.Ability): set = GameInfo.Strings.abilitylist; break;
|
||||
case nameof(PKM.Nature): set = GameInfo.Strings.natures; break;
|
||||
case nameof(PKM.Ball): set = GameInfo.Strings.balllist; break;
|
||||
|
||||
case nameof(PKM.Move1) or nameof(PKM.Move2) or nameof(PKM.Move3) or nameof(PKM.Move4):
|
||||
case nameof(PKM.RelearnMove1) or nameof(PKM.RelearnMove2) or nameof(PKM.RelearnMove3) or nameof(PKM.RelearnMove4):
|
||||
set = GameInfo.Strings.movelist; break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
i.SetScreenedValue(set);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the object is filtered by the provided <see cref="filters"/>.
|
||||
/// </summary>
|
||||
/// <param name="filters">Filters which must be satisfied.</param>
|
||||
/// <param name="pk">Object to check.</param>
|
||||
/// <returns>True if <see cref="pk"/> matches all filters.</returns>
|
||||
public static bool IsFilterMatchMeta(IEnumerable<StringInstruction> filters, SlotCache pk)
|
||||
{
|
||||
foreach (var i in filters)
|
||||
{
|
||||
foreach (var filter in BatchFilters.FilterMeta)
|
||||
{
|
||||
if (!filter.IsMatch(i.PropertyName))
|
||||
continue;
|
||||
|
||||
if (!filter.IsFiltered(pk, i))
|
||||
return false;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override BatchInfo CreateMeta(PKM entity) => new(entity);
|
||||
|
||||
protected override bool ShouldModify(PKM entity) => entity.ChecksumValid && entity.Species != 0;
|
||||
|
||||
protected override bool TryHandleSetOperation(StringInstruction cmd, BatchInfo info, PKM entity, out ModifyResult result)
|
||||
{
|
||||
if (cmd.PropertyValue.StartsWith(CONST_BYTES, StringComparison.Ordinal))
|
||||
{
|
||||
result = SetByteArrayProperty(entity, cmd);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (cmd.PropertyValue.StartsWith(CONST_SUGGEST, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
result = SetSuggestedProperty(cmd.PropertyName, info, cmd.PropertyValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (cmd is { PropertyValue: CONST_RAND, PropertyName: nameof(PKM.Moves) })
|
||||
{
|
||||
result = SetSuggestedMoveset(info, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (SetComplexProperty(info, cmd))
|
||||
{
|
||||
result = ModifyResult.Modified;
|
||||
return true;
|
||||
}
|
||||
|
||||
result = ModifyResult.Skipped;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override bool TryHandleFilter(StringInstruction cmd, BatchInfo info, PKM entity, out bool isMatch)
|
||||
{
|
||||
var match = BatchFilters.FilterMods.Find(z => z.IsMatch(cmd.PropertyName));
|
||||
if (match is null)
|
||||
{
|
||||
isMatch = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
isMatch = match.IsFiltered(info, cmd);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="PKM"/> data with a suggested value based on its <see cref="LegalityAnalysis"/>.
|
||||
/// </summary>
|
||||
/// <param name="name">Property to modify.</param>
|
||||
/// <param name="info">Cached info storing Legal data.</param>
|
||||
/// <param name="propValue">Suggestion string which starts with <see cref="CONST_SUGGEST"/></param>
|
||||
private static ModifyResult SetSuggestedProperty(ReadOnlySpan<char> name, BatchInfo info, ReadOnlySpan<char> propValue)
|
||||
{
|
||||
foreach (var mod in BatchMods.SuggestionMods)
|
||||
{
|
||||
if (mod.IsMatch(name, propValue, info))
|
||||
return mod.Modify(name, propValue, info);
|
||||
}
|
||||
return ModifyResult.Error;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="PKM"/> byte array property to a specified value.
|
||||
/// </summary>
|
||||
/// <param name="pk">Pokémon to modify.</param>
|
||||
/// <param name="cmd">Modification</param>
|
||||
private static ModifyResult SetByteArrayProperty(PKM pk, StringInstruction cmd)
|
||||
{
|
||||
Span<byte> dest;
|
||||
switch (cmd.PropertyName)
|
||||
{
|
||||
case nameof(PKM.NicknameTrash) or nameof(PKM.Nickname): dest = pk.NicknameTrash; break;
|
||||
case nameof(PKM.OriginalTrainerTrash): dest = pk.OriginalTrainerTrash; break;
|
||||
case nameof(PKM.HandlingTrainerTrash): dest = pk.HandlingTrainerTrash; break;
|
||||
default:
|
||||
return ModifyResult.Error;
|
||||
}
|
||||
var src = cmd.PropertyValue.AsSpan(CONST_BYTES.Length); // skip prefix
|
||||
StringUtil.LoadHexBytesTo(src, dest, 3);
|
||||
return ModifyResult.Modified;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="PKM"/> property to a non-specific smart value.
|
||||
/// </summary>
|
||||
/// <param name="info">Pokémon to modify.</param>
|
||||
/// <param name="cmd">Modification</param>
|
||||
/// <returns>True if modified, false if no modifications done.</returns>
|
||||
private bool SetComplexProperty(BatchInfo info, StringInstruction cmd)
|
||||
{
|
||||
ReadOnlySpan<char> name = cmd.PropertyName;
|
||||
ReadOnlySpan<char> value = cmd.PropertyValue;
|
||||
|
||||
if (name.StartsWith("IV") && value is CONST_RAND)
|
||||
{
|
||||
SetRandomIVs(info, name);
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (var mod in BatchMods.ComplexMods)
|
||||
{
|
||||
if (!mod.IsMatch(name, value))
|
||||
continue;
|
||||
mod.Modify(info.Entity, cmd);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="PKM"/> IV(s) to a random value.
|
||||
/// </summary>
|
||||
/// <param name="info">Pokémon to modify.</param>
|
||||
/// <param name="propertyName">Property to modify</param>
|
||||
private void SetRandomIVs(BatchInfo info, ReadOnlySpan<char> propertyName)
|
||||
{
|
||||
var pk = info.Entity;
|
||||
if (propertyName is nameof(PKM.IVs))
|
||||
{
|
||||
var la = info.Legality;
|
||||
var enc = la.EncounterMatch;
|
||||
if (enc is IFlawlessIVCount { FlawlessIVCount: not 0 } fc)
|
||||
pk.SetRandomIVs(fc.FlawlessIVCount);
|
||||
else if (enc is IFixedIVSet { IVs: {IsSpecified: true} iv})
|
||||
pk.SetRandomIVs(iv);
|
||||
else if (enc is IFlawlessIVCountConditional c && c.GetFlawlessIVCount(pk) is { Max: not 0 } x)
|
||||
pk.SetRandomIVs(Util.Rand.Next(x.Min, x.Max + 1));
|
||||
else
|
||||
pk.SetRandomIVs();
|
||||
return;
|
||||
}
|
||||
|
||||
if (TryGetHasProperty(pk, propertyName, out var pi))
|
||||
{
|
||||
const string IV32 = nameof(PK9.IV32);
|
||||
if (propertyName is IV32)
|
||||
{
|
||||
var value = (uint)Util.Rand.Next(0x3FFFFFFF + 1);
|
||||
if (pk is BK4 bk) // Big Endian, reverse IV ordering
|
||||
{
|
||||
value <<= 2; // flags are the lowest bits, and our random value is still fine.
|
||||
value |= bk.IV32 & 3; // preserve the flags
|
||||
bk.IV32 = value;
|
||||
return;
|
||||
}
|
||||
|
||||
var exist = ReflectUtil.GetValue(pk, IV32);
|
||||
value |= exist switch
|
||||
{
|
||||
uint iv => iv & (3u << 30), // preserve the flags
|
||||
_ => 0,
|
||||
};
|
||||
ReflectUtil.SetValue(pi, pk, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
var value = Util.Rand.Next(pk.MaxIV + 1);
|
||||
ReflectUtil.SetValue(pi, pk, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,16 +3,38 @@
|
|||
namespace PKHeX.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for retrieving properties from a <see cref="T"/>.
|
||||
/// Interface for retrieving properties from a <see cref="PKM"/>.
|
||||
/// </summary>
|
||||
public interface IPropertyProvider<in T> where T : notnull
|
||||
public interface IPropertyProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Attempts to retrieve a property's value (as string) from an entity instance.
|
||||
/// Attempts to retrieve a property's value (as string) from a <see cref="PKM"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="obj">Entity to retrieve the property from.</param>
|
||||
/// <param name="pk">Entity to retrieve the property from.</param>
|
||||
/// <param name="prop">Property name to retrieve.</param>
|
||||
/// <param name="result">Property value as string.</param>
|
||||
/// <returns><see langword="true"/> if the property was found and retrieved successfully; otherwise, <see langword="false"/>.</returns>
|
||||
bool TryGetProperty(T obj, string prop, [NotNullWhen(true)] out string? result);
|
||||
bool TryGetProperty(PKM pk, string prop, [NotNullWhen(true)] out string? result);
|
||||
}
|
||||
|
||||
public sealed class DefaultPropertyProvider : IPropertyProvider
|
||||
{
|
||||
public static readonly DefaultPropertyProvider Instance = new();
|
||||
|
||||
public bool TryGetProperty(PKM pk, string prop, [NotNullWhen(true)] out string? result)
|
||||
{
|
||||
result = null;
|
||||
if (!BatchEditing.TryGetHasProperty(pk, prop, out var pi))
|
||||
return false;
|
||||
try
|
||||
{
|
||||
var value = pi.GetValue(pk);
|
||||
result = value?.ToString();
|
||||
return result is not null;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace PKHeX.Core;
|
|||
/// <param name="PropertyName">Property to modify.</param>
|
||||
/// <param name="PropertyValue">Value to set to the property.</param>
|
||||
/// <param name="Comparer">Filter Comparison Type</param>
|
||||
public sealed record StringInstruction(string PropertyName, string PropertyValue, InstructionComparer Comparer, InstructionOperation Operation = InstructionOperation.Set)
|
||||
public sealed record StringInstruction(string PropertyName, string PropertyValue, InstructionComparer Comparer)
|
||||
{
|
||||
public string PropertyValue { get; private set; } = PropertyValue;
|
||||
|
||||
|
|
@ -44,35 +44,9 @@ public bool SetScreenedValue(ReadOnlySpan<string> arr)
|
|||
[
|
||||
Apply,
|
||||
FilterEqual, FilterNotEqual, FilterGreaterThan, FilterGreaterThanOrEqual, FilterLessThan, FilterLessThanOrEqual,
|
||||
ApplyAdd, ApplySubtract, ApplyMultiply, ApplyDivide, ApplyModulo,
|
||||
ApplyBitwiseAnd, ApplyBitwiseOr, ApplyBitwiseXor, ApplyBitwiseShiftRight, ApplyBitwiseShiftLeft,
|
||||
];
|
||||
|
||||
public static bool IsFilterInstruction(char c) => c switch
|
||||
{
|
||||
FilterEqual => true,
|
||||
FilterNotEqual => true,
|
||||
FilterGreaterThan => true,
|
||||
FilterLessThan => true,
|
||||
FilterGreaterThanOrEqual => true,
|
||||
FilterLessThanOrEqual => true,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
public static bool IsMutationInstruction(char c) => !IsFilterInstruction(c);
|
||||
|
||||
private const char Apply = '.';
|
||||
private const char ApplyAdd = '+';
|
||||
private const char ApplySubtract = '-';
|
||||
private const char ApplyMultiply = '*';
|
||||
private const char ApplyDivide = '/';
|
||||
private const char ApplyModulo = '%';
|
||||
private const char ApplyBitwiseAnd = '&';
|
||||
private const char ApplyBitwiseOr = '|';
|
||||
private const char ApplyBitwiseXor = '^';
|
||||
private const char ApplyBitwiseShiftRight = '»';
|
||||
private const char ApplyBitwiseShiftLeft = '«';
|
||||
|
||||
private const char SplitRange = ',';
|
||||
|
||||
private const char FilterEqual = '=';
|
||||
|
|
@ -282,19 +256,19 @@ public static bool TryParseFilter(ReadOnlySpan<char> line, [NotNullWhen(true)] o
|
|||
public static bool TryParseInstruction(ReadOnlySpan<char> line, [NotNullWhen(true)] out StringInstruction? entry)
|
||||
{
|
||||
entry = null;
|
||||
if (line.Length is 0 || !TryGetOperation(line[0], out var operation))
|
||||
if (line.Length is 0 || line[0] is not Apply)
|
||||
return false;
|
||||
return TryParseSplitTuple(line[1..], ref entry, default, operation);
|
||||
return TryParseSplitTuple(line[1..], ref entry);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to split a <see cref="StringInstruction"/> tuple from the input <see cref="tuple"/>.
|
||||
/// </summary>
|
||||
public static bool TryParseSplitTuple(ReadOnlySpan<char> tuple, [NotNullWhen(true)] ref StringInstruction? entry, InstructionComparer eval = default, InstructionOperation operation = InstructionOperation.Set)
|
||||
public static bool TryParseSplitTuple(ReadOnlySpan<char> tuple, [NotNullWhen(true)] ref StringInstruction? entry, InstructionComparer eval = default)
|
||||
{
|
||||
if (!TryParseSplitTuple(tuple, out var name, out var value))
|
||||
return false;
|
||||
entry = new StringInstruction(name.ToString(), value.ToString(), eval, operation);
|
||||
entry = new StringInstruction(name.ToString(), value.ToString(), eval);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -331,50 +305,71 @@ public static bool TryParseSplitTuple(ReadOnlySpan<char> tuple, out ReadOnlySpan
|
|||
FilterLessThanOrEqual => IsLessThanOrEqual,
|
||||
_ => None,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="InstructionOperation"/> from the input <see cref="opCode"/>.
|
||||
/// </summary>
|
||||
public static bool TryGetOperation(char opCode, out InstructionOperation operation)
|
||||
/// <summary>
|
||||
/// Value comparison type
|
||||
/// </summary>
|
||||
public enum InstructionComparer : byte
|
||||
{
|
||||
None,
|
||||
IsEqual,
|
||||
IsNotEqual,
|
||||
IsGreaterThan,
|
||||
IsGreaterThanOrEqual,
|
||||
IsLessThan,
|
||||
IsLessThanOrEqual,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="InstructionComparer"/>
|
||||
/// </summary>
|
||||
public static class InstructionComparerExtensions
|
||||
{
|
||||
extension(InstructionComparer comparer)
|
||||
{
|
||||
switch (opCode)
|
||||
/// <summary>
|
||||
/// Indicates if the <see cref="comparer"/> is supported by the logic.
|
||||
/// </summary>
|
||||
/// <returns>True if supported, false if unsupported.</returns>
|
||||
public bool IsSupported => comparer switch
|
||||
{
|
||||
case Apply:
|
||||
operation = InstructionOperation.Set;
|
||||
return true;
|
||||
case ApplyAdd:
|
||||
operation = InstructionOperation.Add;
|
||||
return true;
|
||||
case ApplySubtract:
|
||||
operation = InstructionOperation.Subtract;
|
||||
return true;
|
||||
case ApplyMultiply:
|
||||
operation = InstructionOperation.Multiply;
|
||||
return true;
|
||||
case ApplyDivide:
|
||||
operation = InstructionOperation.Divide;
|
||||
return true;
|
||||
case ApplyModulo:
|
||||
operation = InstructionOperation.Modulo;
|
||||
return true;
|
||||
case ApplyBitwiseAnd:
|
||||
operation = InstructionOperation.BitwiseAnd;
|
||||
return true;
|
||||
case ApplyBitwiseOr:
|
||||
operation = InstructionOperation.BitwiseOr;
|
||||
return true;
|
||||
case ApplyBitwiseXor:
|
||||
operation = InstructionOperation.BitwiseXor;
|
||||
return true;
|
||||
case ApplyBitwiseShiftRight:
|
||||
operation = InstructionOperation.BitwiseShiftRight;
|
||||
return true;
|
||||
case ApplyBitwiseShiftLeft:
|
||||
operation = InstructionOperation.BitwiseShiftLeft;
|
||||
return true;
|
||||
default:
|
||||
operation = default;
|
||||
return false;
|
||||
}
|
||||
IsEqual => true,
|
||||
IsNotEqual => true,
|
||||
IsGreaterThan => true,
|
||||
IsGreaterThanOrEqual => true,
|
||||
IsLessThan => true,
|
||||
IsLessThanOrEqual => true,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the compare operator is satisfied by a boolean comparison result.
|
||||
/// </summary>
|
||||
/// <param name="compareResult">Result from Equals comparison</param>
|
||||
/// <returns>True if satisfied</returns>
|
||||
/// <remarks>Only use this method if the comparison is boolean only. Use the <see cref="IsCompareOperator"/> otherwise.</remarks>
|
||||
public bool IsCompareEquivalence(bool compareResult) => comparer switch
|
||||
{
|
||||
IsEqual => compareResult,
|
||||
IsNotEqual => !compareResult,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the compare operator is satisfied by the <see cref="IComparable.CompareTo"/> result.
|
||||
/// </summary>
|
||||
/// <param name="compareResult">Result from CompareTo</param>
|
||||
/// <returns>True if satisfied</returns>
|
||||
public bool IsCompareOperator(int compareResult) => comparer switch
|
||||
{
|
||||
IsEqual => compareResult is 0,
|
||||
IsNotEqual => compareResult is not 0,
|
||||
IsGreaterThan => compareResult > 0,
|
||||
IsGreaterThanOrEqual => compareResult >= 0,
|
||||
IsLessThan => compareResult < 0,
|
||||
IsLessThanOrEqual => compareResult <= 0,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -54,12 +54,12 @@ public static ModifyResult SetSuggestedMasteryData(BatchInfo info, ReadOnlySpan<
|
|||
if (IsNone(propValue))
|
||||
return ModifyResult.Modified;
|
||||
|
||||
var enc = info.Legality.EncounterMatch;
|
||||
if (enc is IMasteryInitialMoveShop8 shop)
|
||||
shop.SetInitialMastery(pk, enc);
|
||||
var e = info.Legality.EncounterMatch;
|
||||
if (e is IMasteryInitialMoveShop8 enc)
|
||||
enc.SetInitialMastery(pk);
|
||||
if (IsAll(propValue))
|
||||
{
|
||||
t.SetPurchasedFlagsAll(pk);
|
||||
t.SetPurchasedFlagsAll();
|
||||
t.SetMoveShopFlagsAll(pk);
|
||||
}
|
||||
else
|
||||
|
|
@ -176,7 +176,7 @@ public static ModifyResult SetEVs(PKM pk)
|
|||
/// <param name="option">Option to apply with</param>
|
||||
public static ModifyResult SetContestStats(PKM pk, LegalityAnalysis la, ReadOnlySpan<char> option)
|
||||
{
|
||||
if (option.Length != 0 && option[EntityBatchEditor.CONST_SUGGEST.Length..] is not "0")
|
||||
if (option.Length != 0 && option[BatchEditing.CONST_SUGGEST.Length..] is not "0")
|
||||
pk.SetMaxContestStats(la.EncounterMatch, la.Info.EvoChainsAllGens);
|
||||
else
|
||||
pk.SetSuggestedContestStats(la.EncounterMatch, la.Info.EvoChainsAllGens);
|
||||
|
|
@ -30,10 +30,8 @@ public void SetNickname(string nick)
|
|||
pk.ClearNickname();
|
||||
return;
|
||||
}
|
||||
|
||||
pk.PrepareNickname();
|
||||
pk.Nickname = nick;
|
||||
pk.IsNicknamed = true;
|
||||
pk.Nickname = nick;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -139,7 +137,7 @@ public bool SetUnshiny()
|
|||
/// <param name="nature">Desired <see cref="PKM.Nature"/> value to set.</param>
|
||||
public void SetNature(Nature nature)
|
||||
{
|
||||
if (!nature.IsFixed)
|
||||
if (!nature.IsFixed())
|
||||
nature = 0; // default valid
|
||||
|
||||
var format = pk.Format;
|
||||
|
|
|
|||
|
|
@ -86,14 +86,14 @@ public ReadOnlySpan<ITrainerInfo> GetTrainers(GameVersion version)
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches an appropriate trainer based on the requested <see cref="context"/>.
|
||||
/// Fetches an appropriate trainer based on the requested <see cref="generation"/>.
|
||||
/// </summary>
|
||||
/// <param name="context">Generation the trainer should inhabit</param>
|
||||
/// <param name="generation">Generation the trainer should inhabit</param>
|
||||
/// <param name="lang">Language to request for</param>
|
||||
/// <returns>Null if no trainer found for this version.</returns>
|
||||
public ITrainerInfo? GetTrainerFromContext(EntityContext context, LanguageID? lang = null)
|
||||
public ITrainerInfo? GetTrainerFromGen(byte generation, LanguageID? lang = null)
|
||||
{
|
||||
var possible = Database.Where(z => z.Key.Context == context).ToList();
|
||||
var possible = Database.Where(z => z.Key.Generation == generation).ToList();
|
||||
if (possible.Count == 0)
|
||||
return null;
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public static class HiddenPower
|
|||
/// <param name="context">Generation format</param>
|
||||
public static int GetType(ReadOnlySpan<int> IVs, EntityContext context)
|
||||
{
|
||||
if (context.IsEraGameBoy)
|
||||
if (context.Generation <= 2)
|
||||
return GetTypeGB(IVs);
|
||||
return GetType(IVs);
|
||||
}
|
||||
|
|
@ -153,7 +153,7 @@ public static ushort SetTypeGB(int hiddenPowerType, ushort current)
|
|||
/// <returns>True if the Hidden Power of the <see cref="IVs"/> is obtained, with or without modifications</returns>
|
||||
public static bool SetIVsForType(int hiddenPowerType, Span<int> IVs, EntityContext context)
|
||||
{
|
||||
if (context.IsEraGameBoy)
|
||||
if (context.Generation <= 2)
|
||||
return SetTypeGB(hiddenPowerType, IVs);
|
||||
return SetIVsForType(hiddenPowerType, IVs);
|
||||
}
|
||||
|
|
@ -238,7 +238,7 @@ private static int GetFlawedBitCount(ReadOnlySpan<int> ivs, int bitValue)
|
|||
/// <param name="context">Generation specific format</param>
|
||||
public static void SetIVs(int type, Span<int> ivs, EntityContext context = Latest.Context)
|
||||
{
|
||||
if (context.IsEraGameBoy)
|
||||
if (context.Generation <= 2)
|
||||
{
|
||||
ivs[1] = (ivs[1] & 0b1100) | (type >> 2);
|
||||
ivs[2] = (ivs[2] & 0b1100) | (type & 3);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
namespace PKHeX.Core;
|
||||
namespace PKHeX.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Simple interface representing a <see cref="PKM"/> viewer.
|
||||
|
|
@ -44,10 +44,4 @@ public interface IPKMView
|
|||
/// <param name="focus">Cause the viewer to give focus to itself.</param>
|
||||
/// <param name="skipConversionCheck">Cause the viewer to skip converting the data. Faster if it is known that the format is the same as the previous format.</param>
|
||||
void PopulateFields(PKM pk, bool focus = true, bool skipConversionCheck = false);
|
||||
|
||||
/// <summary>
|
||||
/// Messages back that the entity has been saved.
|
||||
/// </summary>
|
||||
/// <param name="pk">Pokémon data that was saved.</param>
|
||||
void NotifyWasExported(PKM pk);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,11 +76,14 @@ private static void AddEncounterMoves(Span<IndicatedSourceType> type, IEncounter
|
|||
}
|
||||
else if (enc is IMoveset {Moves: {HasMoves: true} set})
|
||||
{
|
||||
foreach (var move in set.AsSpan())
|
||||
{
|
||||
if (type[move] == None)
|
||||
type[move] = Encounter;
|
||||
}
|
||||
if (type[set.Move1] == None)
|
||||
type[set.Move1] = Encounter;
|
||||
if (type[set.Move2] == None)
|
||||
type[set.Move2] = Encounter;
|
||||
if (type[set.Move3] == None)
|
||||
type[set.Move3] = Encounter;
|
||||
if (type[set.Move4] == None)
|
||||
type[set.Move4] = Encounter;
|
||||
}
|
||||
else if (enc is ISingleMoveBonus single)
|
||||
{
|
||||
|
|
@ -94,11 +97,14 @@ private static void AddEncounterMoves(Span<IndicatedSourceType> type, IEncounter
|
|||
|
||||
if (enc is IRelearn { Relearn: {HasMoves: true} relearn})
|
||||
{
|
||||
foreach (var move in relearn.AsSpan())
|
||||
{
|
||||
if (type[move] == None)
|
||||
type[move] = Relearn;
|
||||
}
|
||||
if (type[relearn.Move1] == None)
|
||||
type[relearn.Move1] = Relearn;
|
||||
if (type[relearn.Move2] == None)
|
||||
type[relearn.Move2] = Relearn;
|
||||
if (type[relearn.Move3] == None)
|
||||
type[relearn.Move3] = Relearn;
|
||||
if (type[relearn.Move4] == None)
|
||||
type[relearn.Move4] = Relearn;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,15 +5,12 @@ namespace PKHeX.Core;
|
|||
|
||||
public sealed class AdvancedSettings
|
||||
{
|
||||
[LocalizedDescription("Skip the Overwrite prompt when exporting a save file, to always Save As...")]
|
||||
public bool SaveExportForceSaveAs { get; set; }
|
||||
|
||||
[LocalizedDescription("Check if the Pokémon in the editor has unsaved changes before exporting the save file.")]
|
||||
public bool SaveExportCheckUnsavedEntity { get; set; } = true;
|
||||
|
||||
[LocalizedDescription("Folder path that contains dump(s) of block hash-names. If a specific dump file does not exist, only names defined within the program's code will be loaded.")]
|
||||
public string PathBlockKeyList { get; set; } = string.Empty;
|
||||
|
||||
[LocalizedDescription("Hide event variables below this event type value. Removes event values from the GUI that the user doesn't care to view.")]
|
||||
public NamedEventType HideEventTypeBelow { get; set; }
|
||||
|
||||
[LocalizedDescription("Hide event variable names for that contain any of the comma-separated substrings below. Removes event values from the GUI that the user doesn't care to view.")]
|
||||
public string HideEvent8Contains { get; set; } = string.Empty;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,21 @@
|
|||
using System;
|
||||
using System;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for defining a manipulation of box data.
|
||||
/// </summary>
|
||||
public abstract record BoxManipBase(BoxManipType Type, Func<SaveFile, bool> Usable) : IBoxManip
|
||||
public abstract class BoxManipBase : IBoxManip
|
||||
{
|
||||
public BoxManipType Type { get; }
|
||||
public Func<SaveFile, bool> Usable { get; }
|
||||
|
||||
protected BoxManipBase(BoxManipType type, Func<SaveFile, bool> usable)
|
||||
{
|
||||
Type = type;
|
||||
Usable = usable;
|
||||
}
|
||||
|
||||
public abstract string GetPrompt(bool all);
|
||||
public abstract string GetFail(bool all);
|
||||
public abstract string GetSuccess(bool all);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ namespace PKHeX.Core;
|
|||
/// <summary>
|
||||
/// Clears contents of boxes by deleting all that satisfy a criteria.
|
||||
/// </summary>
|
||||
public sealed record BoxManipClear(BoxManipType Type, Func<PKM, bool> Criteria, Func<SaveFile, bool> Usable) : BoxManipBase(Type, Usable)
|
||||
public sealed class BoxManipClear(BoxManipType Type, Func<PKM, bool> criteria, Func<SaveFile, bool> Usable) : BoxManipBase(Type, Usable)
|
||||
{
|
||||
public BoxManipClear(BoxManipType Type, Func<PKM, bool> Criteria) : this(Type, Criteria, _ => true) { }
|
||||
|
||||
|
|
@ -18,6 +18,6 @@ public override int Execute(SaveFile sav, BoxManipParam param)
|
|||
var (start, stop, reverse) = param;
|
||||
return sav.ClearBoxes(start, stop, Method);
|
||||
|
||||
bool Method(PKM p) => reverse ^ Criteria(p);
|
||||
bool Method(PKM p) => reverse ^ criteria(p);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ namespace PKHeX.Core;
|
|||
/// <summary>
|
||||
/// Clears contents of boxes by deleting all that satisfy a criteria based on a <see cref="SaveFile"/>.
|
||||
/// </summary>
|
||||
public sealed record BoxManipClearComplex(BoxManipType Type, Func<PKM, SaveFile, bool> Criteria, Func<SaveFile, bool> Usable) : BoxManipBase(Type, Usable)
|
||||
public sealed class BoxManipClearComplex(BoxManipType Type, Func<PKM, SaveFile, bool> criteria, Func<SaveFile, bool> Usable) : BoxManipBase(Type, Usable)
|
||||
{
|
||||
public BoxManipClearComplex(BoxManipType Type, Func<PKM, SaveFile, bool> Criteria) : this(Type, Criteria, _ => true) { }
|
||||
|
||||
|
|
@ -18,6 +18,6 @@ public override int Execute(SaveFile sav, BoxManipParam param)
|
|||
var (start, stop, reverse) = param;
|
||||
return sav.ClearBoxes(start, stop, Method);
|
||||
|
||||
bool Method(PKM p) => reverse ^ Criteria(p, sav);
|
||||
bool Method(PKM p) => reverse ^ criteria(p, sav);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ namespace PKHeX.Core;
|
|||
/// Clears contents of boxes by deleting all but the first duplicate detected.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Base type of the "is duplicate" hash for the duplicate detection.</typeparam>
|
||||
public sealed record BoxManipClearDuplicate<T> : BoxManipBase
|
||||
public sealed class BoxManipClearDuplicate<T> : BoxManipBase
|
||||
{
|
||||
private readonly HashSet<T> HashSet = [];
|
||||
private readonly Func<PKM, bool> Criteria;
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ namespace PKHeX.Core;
|
|||
/// <summary>
|
||||
/// Modifies contents of boxes by using an <see cref="Action"/> to change data.
|
||||
/// </summary>
|
||||
public sealed record BoxManipModify(BoxManipType Type, Action<PKM> Action, Func<SaveFile, bool> Usable)
|
||||
: BoxManipBase(Type, Usable)
|
||||
public sealed class BoxManipModify(BoxManipType type, Action<PKM> Action, Func<SaveFile, bool> Usable)
|
||||
: BoxManipBase(type, Usable)
|
||||
{
|
||||
public BoxManipModify(BoxManipType type, Action<PKM> Action) : this(type, Action, _ => true) { }
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ namespace PKHeX.Core;
|
|||
/// <summary>
|
||||
/// Modifies contents of boxes by using an <see cref="Action"/> (referencing a Save File) to change data.
|
||||
/// </summary>
|
||||
public sealed record BoxManipModifyComplex(BoxManipType Type, Action<PKM, SaveFile> Action, Func<SaveFile, bool> Usable)
|
||||
public sealed class BoxManipModifyComplex(BoxManipType Type, Action<PKM, SaveFile> Action, Func<SaveFile, bool> Usable)
|
||||
: BoxManipBase(Type, Usable)
|
||||
{
|
||||
public BoxManipModifyComplex(BoxManipType Type, Action<PKM, SaveFile> Action) : this(Type, Action, _ => true) { }
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ namespace PKHeX.Core;
|
|||
/// <summary>
|
||||
/// Sorts contents of boxes by using a Sorter to determine the order.
|
||||
/// </summary>
|
||||
public sealed record BoxManipSort(BoxManipType Type, Func<IEnumerable<PKM>, IEnumerable<PKM>> Sorter, Func<SaveFile, bool> Usable) : BoxManipBase(Type, Usable)
|
||||
public sealed class BoxManipSort(BoxManipType Type, Func<IEnumerable<PKM>, IEnumerable<PKM>> Sorter, Func<SaveFile, bool> Usable) : BoxManipBase(Type, Usable)
|
||||
{
|
||||
public BoxManipSort(BoxManipType Type, Func<IEnumerable<PKM>, IEnumerable<PKM>> Sorter) : this(Type, Sorter, _ => true) { }
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
|
@ -6,7 +6,7 @@ namespace PKHeX.Core;
|
|||
/// <summary>
|
||||
/// Sorts contents of boxes by using a <see cref="Sorter"/> (referencing a Save File) to determine the order.
|
||||
/// </summary>
|
||||
public sealed record BoxManipSortComplex : BoxManipBase
|
||||
public sealed class BoxManipSortComplex : BoxManipBase
|
||||
{
|
||||
private readonly Func<IEnumerable<PKM>, SaveFile, int, IEnumerable<PKM>> Sorter;
|
||||
public BoxManipSortComplex(BoxManipType type, Func<IEnumerable<PKM>, SaveFile, IEnumerable<PKM>> sorter) : this(type, sorter, _ => true) { }
|
||||
|
|
|
|||
|
|
@ -13,5 +13,4 @@ public sealed class FakePKMEditor(PKM template) : IPKMView
|
|||
|
||||
public PKM PreparePKM(bool click = true) => Data;
|
||||
public void PopulateFields(PKM pk, bool focus = true, bool skipConversionCheck = false) => Data = pk;
|
||||
public void NotifyWasExported(PKM pk) { }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,11 +61,11 @@ private static List<SlotInfoMisc> GetExtraSlots2(SAV2 sav)
|
|||
|
||||
private static List<SlotInfoMisc> GetExtraSlots3(SAV3 sav)
|
||||
{
|
||||
if (sav is not SAV3FRLG frlg)
|
||||
if (sav is not SAV3FRLG)
|
||||
return None;
|
||||
return
|
||||
[
|
||||
new(frlg.LargeBlock.SingleDaycareRoute5, 0) {Type = StorageSlotType.Daycare},
|
||||
new(sav.LargeBuffer[0x3C98..], 0) {Type = StorageSlotType.Daycare},
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ private static List<SlotInfoMisc> GetExtraSlots4(SAV4 sav)
|
|||
if (sav.GTS > 0)
|
||||
list.Add(new SlotInfoMisc(sav.GeneralBuffer[sav.GTS..], 0) { Type = StorageSlotType.GTS });
|
||||
if (sav is SAV4HGSS hgss)
|
||||
list.Add(new SlotInfoMisc(hgss.GeneralBuffer[SAV4HGSS.WalkerPair..], 1) {Type = StorageSlotType.Pokéwalker});
|
||||
list.Add(new SlotInfoMisc(hgss.GeneralBuffer[SAV4HGSS.WalkerPair..], 1) {Type = StorageSlotType.Misc});
|
||||
return list;
|
||||
}
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ private static List<SlotInfoMisc> GetExtraSlots5(SAV5 sav)
|
|||
var list = new List<SlotInfoMisc>
|
||||
{
|
||||
new(sav.GTS.Upload, 0) {Type = StorageSlotType.GTS},
|
||||
new(sav.GlobalLink.Upload, 0) { Type = StorageSlotType.PGL },
|
||||
new(sav.GlobalLink.Upload, 0) { Type = StorageSlotType.Misc },
|
||||
|
||||
new(sav.BattleBox[0], 0) {Type = StorageSlotType.BattleBox},
|
||||
new(sav.BattleBox[1], 1) {Type = StorageSlotType.BattleBox},
|
||||
|
|
@ -106,7 +106,7 @@ private static List<SlotInfoMisc> GetExtraSlots6XY(SAV6XY sav)
|
|||
[
|
||||
new(sav.GTS.Upload, 0) {Type = StorageSlotType.GTS},
|
||||
new(sav.Fused[0], 0) {Type = StorageSlotType.FusedKyurem},
|
||||
new(sav.SUBE.GiveSlot, 0, Mutable: true) {Type = StorageSlotType.Scripted}, // Old Man
|
||||
new(sav.SUBE.GiveSlot, 0, Mutable: true) {Type = StorageSlotType.Misc}, // Old Man
|
||||
|
||||
new(sav.BattleBox[0], 0) {Type = StorageSlotType.BattleBox},
|
||||
new(sav.BattleBox[1], 1) {Type = StorageSlotType.BattleBox},
|
||||
|
|
@ -123,7 +123,7 @@ private static List<SlotInfoMisc> GetExtraSlots6AO(SAV6AO sav)
|
|||
[
|
||||
new(sav.GTS.Upload, 0) { Type = StorageSlotType.GTS },
|
||||
new(sav.Fused[0], 0) { Type = StorageSlotType.FusedKyurem },
|
||||
new(sav.SUBE.GiveSlot, 0) {Type = StorageSlotType.Scripted},
|
||||
new(sav.SUBE.GiveSlot, 0) {Type = StorageSlotType.Misc},
|
||||
|
||||
new(sav.BattleBox[0], 0) {Type = StorageSlotType.BattleBox},
|
||||
new(sav.BattleBox[1], 1) {Type = StorageSlotType.BattleBox},
|
||||
|
|
@ -150,9 +150,9 @@ private static List<SlotInfoMisc> GetExtraSlots7(SAV7 sav, bool all)
|
|||
]);
|
||||
list.AddRange(
|
||||
[
|
||||
new SlotInfoMisc(uu.BattleAgency[0], 0) {Type = StorageSlotType.BattleAgency},
|
||||
new SlotInfoMisc(uu.BattleAgency[1], 1) {Type = StorageSlotType.BattleAgency},
|
||||
new SlotInfoMisc(uu.BattleAgency[2], 2) {Type = StorageSlotType.BattleAgency},
|
||||
new SlotInfoMisc(uu.BattleAgency[0], 0) {Type = StorageSlotType.Misc},
|
||||
new SlotInfoMisc(uu.BattleAgency[1], 1) {Type = StorageSlotType.Misc},
|
||||
new SlotInfoMisc(uu.BattleAgency[2], 2) {Type = StorageSlotType.Misc},
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -202,15 +202,15 @@ private static List<SlotInfoMisc> GetExtraSlots8b(SAV8BS sav)
|
|||
{
|
||||
return
|
||||
[
|
||||
new(sav.UgSaveData[0], 0, true) { Type = StorageSlotType.Underground, HideLegality = true },
|
||||
new(sav.UgSaveData[1], 1, true) { Type = StorageSlotType.Underground, HideLegality = true },
|
||||
new(sav.UgSaveData[2], 2, true) { Type = StorageSlotType.Underground, HideLegality = true },
|
||||
new(sav.UgSaveData[3], 3, true) { Type = StorageSlotType.Underground, HideLegality = true },
|
||||
new(sav.UgSaveData[4], 4, true) { Type = StorageSlotType.Underground, HideLegality = true },
|
||||
new(sav.UgSaveData[5], 5, true) { Type = StorageSlotType.Underground, HideLegality = true },
|
||||
new(sav.UgSaveData[6], 6, true) { Type = StorageSlotType.Underground, HideLegality = true },
|
||||
new(sav.UgSaveData[7], 7, true) { Type = StorageSlotType.Underground, HideLegality = true },
|
||||
new(sav.UgSaveData[8], 8, true) { Type = StorageSlotType.Underground, HideLegality = true },
|
||||
new(sav.UgSaveData[0], 0, true) { Type = StorageSlotType.Misc, HideLegality = true },
|
||||
new(sav.UgSaveData[1], 1, true) { Type = StorageSlotType.Misc, HideLegality = true },
|
||||
new(sav.UgSaveData[2], 2, true) { Type = StorageSlotType.Misc, HideLegality = true },
|
||||
new(sav.UgSaveData[3], 3, true) { Type = StorageSlotType.Misc, HideLegality = true },
|
||||
new(sav.UgSaveData[4], 4, true) { Type = StorageSlotType.Misc, HideLegality = true },
|
||||
new(sav.UgSaveData[5], 5, true) { Type = StorageSlotType.Misc, HideLegality = true },
|
||||
new(sav.UgSaveData[6], 6, true) { Type = StorageSlotType.Misc, HideLegality = true },
|
||||
new(sav.UgSaveData[7], 7, true) { Type = StorageSlotType.Misc, HideLegality = true },
|
||||
new(sav.UgSaveData[8], 8, true) { Type = StorageSlotType.Misc, HideLegality = true },
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -239,8 +239,8 @@ private static List<SlotInfoMisc> GetExtraSlots9(SAV9SV sav)
|
|||
|
||||
if (sav.Blocks.TryGetBlock(SaveBlockAccessor9SV.KSurpriseTrade, out var surprise))
|
||||
{
|
||||
list.Add(new(surprise.Raw[0x198..], 0) { Type = StorageSlotType.SurpriseTrade }); // my upload
|
||||
list.Add(new(surprise.Raw[0x02C..], 1) { Type = StorageSlotType.SurpriseTrade }); // received from others
|
||||
list.Add(new(surprise.Raw[0x198..], 0) { Type = StorageSlotType.Misc }); // my upload
|
||||
list.Add(new(surprise.Raw[0x02C..], 1) { Type = StorageSlotType.Misc }); // received from others
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
|
@ -268,7 +268,7 @@ private static List<SlotInfoMisc> GetExtraSlots9a(SAV9ZA sav)
|
|||
var ofs = (i * size) + 8;
|
||||
var entry = giveAway.Raw.Slice(ofs, PokeCrypto.SIZE_9PARTY);
|
||||
if (EntityDetection.IsPresent(entry.Span))
|
||||
list.Add(new(entry, i, true, Mutable: true) { Type = StorageSlotType.Scripted });
|
||||
list.Add(new(entry, i, true, Mutable: true) { Type = StorageSlotType.Misc });
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
|
@ -49,11 +48,4 @@ public interface ISlotViewer<T>
|
|||
/// Save data the <see cref="ISlotViewer{T}"/> is showing data from.
|
||||
/// </summary>
|
||||
SaveFile SAV { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Instructs the viewer to cache the provided filter and apply it to all slots, showing only those that match the filter.
|
||||
/// </summary>
|
||||
/// <param name="filter">Filter function to apply to the viewer's slots. Only slots for which this function returns true will be shown in the viewer.</param>
|
||||
/// <param name="reload">Trigger a reload of the viewer after applying the new filter. This is required to update the viewer's display after changing the filter.</param>
|
||||
void ApplyNewFilter(Func<PKM, bool>? filter, bool reload = true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
|
@ -12,7 +11,6 @@ public sealed class SlotPublisher<T>
|
|||
/// All <see cref="ISlotViewer{T}"/> instances that provide a view on individual <see cref="ISlotInfo"/> content.
|
||||
/// </summary>
|
||||
private List<ISlotViewer<T>> Subscribers { get; } = [];
|
||||
private Func<PKM, bool>? Filter { get; set; }
|
||||
|
||||
public ISlotInfo? Previous { get; private set; }
|
||||
public SlotTouchType PreviousType { get; private set; } = SlotTouchType.None;
|
||||
|
|
@ -51,11 +49,4 @@ public void ResetView(ISlotViewer<T> sub)
|
|||
|
||||
public void Subscribe(ISlotViewer<T> sub) => Subscribers.Add(sub);
|
||||
public bool Unsubscribe(ISlotViewer<T> sub) => Subscribers.Remove(sub);
|
||||
|
||||
public void UpdateFilter(Func<PKM, bool>? searchFilter, bool reload = true)
|
||||
{
|
||||
Filter = searchFilter;
|
||||
foreach (var sub in Subscribers)
|
||||
sub.ApplyNewFilter(Filter, reload);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the visibility options for a slot when it is displayed in the user interface.
|
||||
/// </summary>
|
||||
/// <remarks>This enumeration supports bitwise combination of its values to allow multiple visibility behaviors to be applied simultaneously.</remarks>
|
||||
[Flags]
|
||||
public enum SlotVisibilityType
|
||||
{
|
||||
/// <summary>
|
||||
/// No special visibility handling.
|
||||
/// </summary>
|
||||
None,
|
||||
|
||||
/// <summary>
|
||||
/// Check the legality of the slot when displaying it.
|
||||
/// </summary>
|
||||
CheckLegalityIndicate = 1 << 0,
|
||||
|
||||
/// <summary>
|
||||
/// Fade-out the slot if it does not match the current filter.
|
||||
/// </summary>
|
||||
FilterMismatch = 1 << 1,
|
||||
}
|
||||
|
|
@ -7,106 +7,28 @@ public enum StorageSlotType : byte
|
|||
{
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Originated from Box
|
||||
/// </summary>
|
||||
Box,
|
||||
|
||||
/// <summary>
|
||||
/// Originated from Party
|
||||
/// </summary>
|
||||
Party,
|
||||
|
||||
/// <summary>
|
||||
/// Battle Box
|
||||
/// </summary>
|
||||
/// <summary> Battle Box </summary>
|
||||
BattleBox,
|
||||
|
||||
/// <summary>
|
||||
/// Daycare
|
||||
/// </summary>
|
||||
/// <summary> Daycare </summary>
|
||||
Daycare,
|
||||
|
||||
/// <summary>
|
||||
/// Miscellaneous Origin (usually in-game scripted event recollection)
|
||||
/// </summary>
|
||||
Scripted,
|
||||
|
||||
/// <summary>
|
||||
/// Global Trade Station (GTS)
|
||||
/// </summary>
|
||||
/// <summary> Global Trade Station (GTS) </summary>
|
||||
GTS,
|
||||
|
||||
/// <summary>
|
||||
/// Pokémon Global Link (PGL)
|
||||
/// </summary>
|
||||
PGL,
|
||||
|
||||
/// <summary>
|
||||
/// Surprise Trade Upload/Download
|
||||
/// </summary>
|
||||
SurpriseTrade,
|
||||
|
||||
/// <summary>
|
||||
/// Shiny Overworld Cache
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <see cref="GameVersion.ZA"/>
|
||||
/// </remarks>
|
||||
/// <summary> Shiny Overworld Cache </summary>
|
||||
Shiny,
|
||||
|
||||
/// <summary>
|
||||
/// Underground area wild Pokémon cache
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <see cref="GameVersion.BD"/>
|
||||
/// <see cref="GameVersion.SP"/>
|
||||
/// </remarks>
|
||||
Underground,
|
||||
|
||||
/// <summary>
|
||||
/// Fused Legendary Storage
|
||||
/// </summary>
|
||||
Fused,
|
||||
|
||||
/// <summary>
|
||||
/// Sub-tag for <see cref="Species.Kyurem"/> differentiation.
|
||||
/// </summary>
|
||||
/// <summary> Fused Legendary Storage </summary>
|
||||
FusedKyurem,
|
||||
/// <summary>
|
||||
/// Sub-tag for <see cref="Species.Solgaleo"/> differentiation.
|
||||
/// </summary>
|
||||
FusedNecrozmaS,
|
||||
/// <summary>
|
||||
/// Sub-tag for <see cref="Species.Lunala"/> differentiation.
|
||||
/// </summary>
|
||||
FusedNecrozmaM,
|
||||
/// <summary>
|
||||
/// Sub-tag for <see cref="Species.Calyrex"/> differentiation.
|
||||
/// </summary>
|
||||
FusedCalyrex,
|
||||
|
||||
/// <summary>
|
||||
/// Poké Pelago (Gen7)
|
||||
/// </summary>
|
||||
/// <summary> Miscellaneous </summary>
|
||||
Misc,
|
||||
/// <summary> Poké Pelago (Gen7) </summary>
|
||||
Resort,
|
||||
|
||||
/// <summary>
|
||||
/// Ride Legendary Slot (S/V)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <see cref="GameVersion.SL"/>
|
||||
/// <see cref="GameVersion.VL"/>
|
||||
/// </remarks>
|
||||
/// <summary> Ride Legendary Slot (S/V) </summary>
|
||||
Ride,
|
||||
|
||||
/// <summary>
|
||||
/// Battle Agency (Gen7)
|
||||
/// </summary>
|
||||
BattleAgency,
|
||||
|
||||
/// <summary>
|
||||
/// Gen4 HeartGold/SoulSilver pedometer accessory upload
|
||||
/// </summary>
|
||||
Pokéwalker,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -238,11 +238,6 @@ public enum GameVersion : byte
|
|||
/// Pokémon Legends: (Z-A) (NX)
|
||||
/// </summary>
|
||||
ZA = 52,
|
||||
|
||||
/// <summary>
|
||||
/// Pokémon Champions (NX)
|
||||
/// </summary>
|
||||
CP = 53,
|
||||
#endregion
|
||||
|
||||
// The following values are not actually stored values in pk data,
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public static class NatureUtil
|
|||
/// Checks if the provided <see cref="value"/> is a valid stored <see cref="Nature"/> value.
|
||||
/// </summary>
|
||||
/// <returns>True if value is an actual nature.</returns>
|
||||
public bool IsFixed => value != Nature.Random;
|
||||
public bool IsFixed() => value < Nature.Random;
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the provided <see cref="value"/> is a possible mint nature.
|
||||
|
|
@ -63,12 +63,12 @@ public static class NatureUtil
|
|||
/// <remarks>
|
||||
/// The only valid mint natures are those which have a stat amp applied, or neutral nature being Serious.
|
||||
/// </remarks>
|
||||
public bool IsMint => (value.IsFixed && (byte)value % 6 != 0) || value == Nature.Serious;
|
||||
public bool IsMint() => (value.IsFixed() && (byte)value % 6 != 0) || value == Nature.Serious;
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the provided <see cref="value"/> is a neutral nature which has no stat amps applied.
|
||||
/// </summary>
|
||||
public bool IsNeutral => value.IsFixed && (byte)value % 6 == 0;
|
||||
public bool IsNeutral() => value.IsFixed() && (byte)value % 6 == 0;
|
||||
|
||||
/// <summary>
|
||||
/// Converts the provided <see cref="value"/> to a neutral nature.
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public FilteredGameDataSource(SaveFile sav, GameDataSource source, bool HaX = fa
|
|||
Items = [];
|
||||
}
|
||||
|
||||
var gamelist = GameUtil.GetVersionsWithinRange(sav, sav.Context).ToList();
|
||||
var gamelist = GameUtil.GetVersionsWithinRange(sav, sav.Generation).ToList();
|
||||
Games = Source.VersionDataSource.Where(g => gamelist.Contains((GameVersion)g.Value) || g.Value == 0).ToList();
|
||||
|
||||
Languages = Source.LanguageDataSource(sav.Generation, sav.Context);
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ internal GameStrings(string langFilePrefix)
|
|||
AppendLocationIndex(CXD.Met0.AsSpan(0, 227));
|
||||
|
||||
// Current Generation strings
|
||||
natures = Get("natures");
|
||||
natures = Util.GetNaturesList(langFilePrefix);
|
||||
types = Get("types");
|
||||
abilitylist = Get("abilities");
|
||||
|
||||
|
|
|
|||
|
|
@ -76,8 +76,6 @@ private static GameVersion[] GetValidGameVersions()
|
|||
SL or VL => SV,
|
||||
ZA => ZA,
|
||||
|
||||
CP => CP, // TODO: Champions
|
||||
|
||||
_ => Invalid,
|
||||
};
|
||||
|
||||
|
|
@ -170,7 +168,6 @@ private EntityContext GetContextInternal()
|
|||
SW or SH => Legal.MaxSpeciesID_8,
|
||||
SL or VL => Legal.MaxSpeciesID_9,
|
||||
ZA => Legal.MaxSpeciesID_9a,
|
||||
CP => Legal.MaxSpeciesID_9, // TODO: Champions
|
||||
_ => 0
|
||||
};
|
||||
|
||||
|
|
@ -255,23 +252,23 @@ public bool Contains(GameVersion g2)
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// List of possible <see cref="GameVersion"/> values within the provided <see cref="context"/>.
|
||||
/// List of possible <see cref="GameVersion"/> values within the provided <see cref="generation"/>.
|
||||
/// </summary>
|
||||
/// <param name="context">Generation to look within</param>
|
||||
/// <param name="generation">Generation to look within</param>
|
||||
/// <param name="version">Entity version</param>
|
||||
public static GameVersion[] GetVersionsInGeneration(EntityContext context, GameVersion version)
|
||||
public static GameVersion[] GetVersionsInGeneration(byte generation, GameVersion version)
|
||||
{
|
||||
if (context is EntityContext.Gen7b)
|
||||
if (Gen7b.Contains(version))
|
||||
return [GO, GP, GE];
|
||||
return Array.FindAll(GameVersions, z => z.Context == context);
|
||||
return Array.FindAll(GameVersions, z => z.Generation == generation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List of possible <see cref="GameVersion"/> values within the provided <see cref="IGameValueLimit"/> criteria.
|
||||
/// </summary>
|
||||
/// <param name="obj">Criteria for retrieving versions</param>
|
||||
/// <param name="context">Generation format minimum (necessary for the CXD/Gen4 swap etc.)</param>
|
||||
public static IEnumerable<GameVersion> GetVersionsWithinRange(IGameValueLimit obj, EntityContext context = 0)
|
||||
/// <param name="generation">Generation format minimum (necessary for the CXD/Gen4 swap etc.)</param>
|
||||
public static IEnumerable<GameVersion> GetVersionsWithinRange(IGameValueLimit obj, byte generation = 0)
|
||||
{
|
||||
var max = obj.MaxGameID;
|
||||
if (max == Legal.MaxGameID_7b) // edge case
|
||||
|
|
@ -280,14 +277,14 @@ public static IEnumerable<GameVersion> GetVersionsWithinRange(IGameValueLimit ob
|
|||
.Where(version => obj.MinGameID <= version && version <= max);
|
||||
if (max != BATREV)
|
||||
versions = versions.Where(static version => version != BATREV);
|
||||
if (context == 0)
|
||||
if (generation == 0)
|
||||
return versions;
|
||||
if (max == Legal.MaxGameID_7 && context == EntityContext.Gen7)
|
||||
if (max == Legal.MaxGameID_7 && generation == 7)
|
||||
versions = versions.Where(static version => version != GO);
|
||||
|
||||
// HOME allows up-reach to Gen9
|
||||
if (context.IsEraHOME)
|
||||
return versions;
|
||||
return versions.Where(version => version.Generation <= context.Generation);
|
||||
if (generation >= 8)
|
||||
generation = 9;
|
||||
return versions.Where(version => version.Generation <= generation);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,97 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a player's inventory bag and pouch rules.
|
||||
/// </summary>
|
||||
public abstract class PlayerBag
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the pouches represented by the bag.
|
||||
/// </summary>
|
||||
public abstract IReadOnlyList<InventoryPouch> Pouches { get; }
|
||||
|
||||
public abstract IItemStorage Info { get; }
|
||||
public virtual int MaxQuantityHaX => ushort.MaxValue;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the pouch for the specified inventory type.
|
||||
/// </summary>
|
||||
public InventoryPouch GetPouch(InventoryType type)
|
||||
{
|
||||
foreach (var pouch in Pouches)
|
||||
{
|
||||
if (pouch.Type == type)
|
||||
return pouch;
|
||||
}
|
||||
throw new ArgumentOutOfRangeException(nameof(type));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the base max count for the specified pouch.
|
||||
/// </summary>
|
||||
protected int GetMaxCount(InventoryType type) => GetPouch(type).MaxCount;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the max count for the specific item in the specified pouch.
|
||||
/// </summary>
|
||||
public virtual int GetMaxCount(InventoryType type, int itemIndex) => GetMaxCount(type);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a suggested count for an item after applying pouch-specific rules.
|
||||
/// </summary>
|
||||
public int Clamp(InventoryType type, int itemIndex, int requestVal)
|
||||
=> Math.Clamp(requestVal, 0, GetMaxCount(type, itemIndex));
|
||||
|
||||
/// <summary>
|
||||
/// Validates and clamps an item count for the specified pouch.
|
||||
/// </summary>
|
||||
/// <returns><see langword="true"/> if the count is valid after clamping; otherwise, <see langword="false"/>.</returns>
|
||||
public bool IsQuantitySane(InventoryType type, int itemIndex, ref int count, bool hasNew, bool HaX = false)
|
||||
{
|
||||
if (HaX)
|
||||
{
|
||||
// Only clamp to max storable quantity.
|
||||
count = Math.Clamp(count, 0, MaxQuantityHaX);
|
||||
return true;
|
||||
}
|
||||
if (itemIndex == 0)
|
||||
{
|
||||
// No item, no count.
|
||||
count = 0;
|
||||
return true;
|
||||
}
|
||||
if (count <= 0)
|
||||
{
|
||||
// No count, ensure positive quantity.
|
||||
// Only allow an ItemID if game supports "new" item remembering.
|
||||
// Otherwise, it's safe to ignore the item.
|
||||
// Note: a Zero value might not be legal for certain items based on game progress, but we aren't really validating that.
|
||||
count = 0;
|
||||
return hasNew;
|
||||
}
|
||||
|
||||
// Clamp non-zero value to pouch/item rules.
|
||||
count = Clamp(type, itemIndex, count);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether an item is legal for the specified pouch.
|
||||
/// </summary>
|
||||
public bool IsLegal(InventoryType type, int itemIndex, int itemCount) => Info.IsLegal(type, itemIndex, itemCount);
|
||||
|
||||
/// <summary>
|
||||
/// Persists pouch edits back to the save data source.
|
||||
/// </summary>
|
||||
public abstract void CopyTo(SaveFile sav);
|
||||
}
|
||||
|
||||
internal sealed class EmptyPlayerBag : PlayerBag
|
||||
{
|
||||
public override IReadOnlyList<InventoryPouch> Pouches { get; } = [];
|
||||
public override ItemStorage1 Info => ItemStorage1.Instance; // anything
|
||||
public override void CopyTo(SaveFile sav) { }
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static PKHeX.Core.InventoryType;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public sealed class PlayerBag1 : PlayerBag
|
||||
{
|
||||
public override IReadOnlyList<InventoryPouchGB> Pouches { get; }
|
||||
public override ItemStorage1 Info => ItemStorage1.Instance;
|
||||
public override int MaxQuantityHaX => byte.MaxValue;
|
||||
|
||||
private static InventoryPouchGB[] GetPouches(ItemStorage1 info, SAV1Offsets offsets) =>
|
||||
[
|
||||
new(offsets.Items, 20, 99, info, Items),
|
||||
new(offsets.PCItems, 50, 99, info, PCItems),
|
||||
];
|
||||
|
||||
public PlayerBag1(SAV1 sav, SAV1Offsets offsets) : this(sav.Data, offsets) { }
|
||||
public PlayerBag1(ReadOnlySpan<byte> data, SAV1Offsets offsets)
|
||||
{
|
||||
Pouches = GetPouches(ItemStorage1.Instance, offsets);
|
||||
Pouches.LoadAll(data);
|
||||
}
|
||||
|
||||
public override void CopyTo(SaveFile sav) => CopyTo((SAV1)sav);
|
||||
public void CopyTo(SAV1 sav) => CopyTo(sav.Data);
|
||||
public void CopyTo(Span<byte> data) => Pouches.SaveAll(data);
|
||||
|
||||
public override int GetMaxCount(InventoryType type, int itemIndex)
|
||||
{
|
||||
if (type is TMHMs && ItemConverter.IsItemHM1((ushort)itemIndex))
|
||||
return 1;
|
||||
return GetMaxCount(type);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static PKHeX.Core.InventoryType;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public sealed class PlayerBag2 : PlayerBag
|
||||
{
|
||||
public override IReadOnlyList<InventoryPouchGB> Pouches { get; }
|
||||
public override ItemStorage2 Info { get; }
|
||||
public override int MaxQuantityHaX => byte.MaxValue;
|
||||
|
||||
private static InventoryPouchGB[] GetPouches(ItemStorage2 info, SAV2Offsets offsets) =>
|
||||
[
|
||||
new(offsets.PouchTMHM, 57, 99, info, TMHMs),
|
||||
new(offsets.PouchItem, 20, 99, info, Items),
|
||||
new(offsets.PouchKey, 26, 99, info, KeyItems),
|
||||
new(offsets.PouchBall, 12, 99, info, Balls),
|
||||
new(offsets.PouchPC, 50, 99, info, PCItems),
|
||||
];
|
||||
|
||||
public PlayerBag2(SAV2 sav, ItemStorage2 info, SAV2Offsets offsets) : this(sav.Data, info, offsets) { }
|
||||
public PlayerBag2(ReadOnlySpan<byte> data, ItemStorage2 info, SAV2Offsets offsets)
|
||||
{
|
||||
Info = info;
|
||||
Pouches = GetPouches(info, offsets);
|
||||
Pouches.LoadAll(data);
|
||||
}
|
||||
|
||||
public override void CopyTo(SaveFile sav) => CopyTo((SAV2)sav);
|
||||
public void CopyTo(SAV2 sav) => CopyTo(sav.Data);
|
||||
public void CopyTo(Span<byte> data) => Pouches.SaveAll(data);
|
||||
|
||||
public override int GetMaxCount(InventoryType type, int itemIndex)
|
||||
{
|
||||
if (type is TMHMs && ItemConverter.IsItemHM2((ushort)itemIndex))
|
||||
return 1;
|
||||
return GetMaxCount(type);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static PKHeX.Core.InventoryType;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public sealed class PlayerBag3Colosseum : PlayerBag
|
||||
{
|
||||
private const int BaseOffset = 0x007F8;
|
||||
|
||||
public override IReadOnlyList<InventoryPouch3GC> Pouches { get; } = GetPouches(ItemStorage3Colo.Instance);
|
||||
public override ItemStorage3Colo Info => ItemStorage3Colo.Instance;
|
||||
|
||||
private static InventoryPouch3GC[] GetPouches(ItemStorage3Colo info) =>
|
||||
[
|
||||
new(0x000, 20, 099, info, Items),
|
||||
new(0x050, 43, 001, info, KeyItems),
|
||||
new(0x0FC, 16, 099, info, Balls),
|
||||
new(0x13C, 64, 099, info, TMHMs),
|
||||
new(0x23C, 46, 999, info, Berries),
|
||||
new(0x2F4, 03, 099, info, Medicine),
|
||||
];
|
||||
|
||||
public PlayerBag3Colosseum(SAV3Colosseum sav) => Pouches.LoadAll(sav.Data[BaseOffset..]);
|
||||
public PlayerBag3Colosseum(ReadOnlySpan<byte> data) => Pouches.LoadAll(data);
|
||||
|
||||
public override void CopyTo(SaveFile sav) => CopyTo((SAV3Colosseum)sav);
|
||||
public void CopyTo(SAV3Colosseum sav) => CopyTo(sav.Data[BaseOffset..]);
|
||||
public void CopyTo(Span<byte> data) => Pouches.SaveAll(data);
|
||||
}
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static PKHeX.Core.InventoryType;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public sealed class PlayerBag3E : PlayerBag, IPlayerBag3
|
||||
{
|
||||
public override IReadOnlyList<InventoryPouch3> Pouches { get; } = GetPouches(ItemStorage3E.Instance);
|
||||
public override ItemStorage3E Info => ItemStorage3E.Instance;
|
||||
|
||||
private static InventoryPouch3[] GetPouches(ItemStorage3E info) =>
|
||||
[
|
||||
new(0x0C8, 30, 099, info, Items),
|
||||
new(0x140, 30, 001, info, KeyItems),
|
||||
new(0x1B8, 16, 099, info, Balls),
|
||||
new(0x1F8, 64, 099, info, TMHMs),
|
||||
new(0x2F8, 46, 999, info, Berries),
|
||||
new(0x000, 50, 999, info, PCItems),
|
||||
];
|
||||
|
||||
public PlayerBag3E(SAV3E sav) : this(sav.LargeBlock.Inventory, sav.SmallBlock.SecurityKey) { }
|
||||
public PlayerBag3E(ReadOnlySpan<byte> data, uint security)
|
||||
{
|
||||
UpdateSecurityKey(security);
|
||||
Pouches.LoadAll(data);
|
||||
}
|
||||
|
||||
public override void CopyTo(SaveFile sav) => CopyTo((SAV3E)sav);
|
||||
public void CopyTo(SAV3E sav) => CopyTo(sav.LargeBlock.Inventory);
|
||||
public void CopyTo(Span<byte> data) => Pouches.SaveAll(data);
|
||||
|
||||
public override int GetMaxCount(InventoryType type, int itemIndex)
|
||||
{
|
||||
if (type is TMHMs && ItemConverter.IsItemHM3((ushort)itemIndex))
|
||||
return 1;
|
||||
return GetMaxCount(type);
|
||||
}
|
||||
|
||||
public void UpdateSecurityKey(uint securityKey)
|
||||
{
|
||||
foreach (var pouch in Pouches)
|
||||
{
|
||||
if (pouch.Type != PCItems)
|
||||
pouch.SecurityKey = securityKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encryption interface for player bags that utilize security keys.
|
||||
/// </summary>
|
||||
/// <see cref="PlayerBag3E"/>
|
||||
/// <see cref="PlayerBag3FRLG"/>
|
||||
public interface IPlayerBag3
|
||||
{
|
||||
/// <summary>
|
||||
/// Updates the security key for all pouches that require it.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Interior item data is not modified; this only changes the key used for read/write operations.
|
||||
/// </remarks>
|
||||
/// <param name="securityKey">The new security key to use.</param>
|
||||
void UpdateSecurityKey(uint securityKey);
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static PKHeX.Core.InventoryType;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public sealed class PlayerBag3FRLG(bool VC) : PlayerBag, IPlayerBag3
|
||||
{
|
||||
public override IItemStorage Info => GetInfo(VC);
|
||||
private static IItemStorage GetInfo(bool vc) => vc ? ItemStorage3FRLG_VC.Instance : ItemStorage3FRLG.Instance;
|
||||
public override IReadOnlyList<InventoryPouch3> Pouches { get; } = GetPouches(GetInfo(VC));
|
||||
|
||||
private static InventoryPouch3[] GetPouches(IItemStorage info) =>
|
||||
[
|
||||
new(0x078, 42, 999, info, Items),
|
||||
new(0x120, 30, 001, info, KeyItems),
|
||||
new(0x198, 13, 999, info, Balls),
|
||||
new(0x1CC, 58, 999, info, TMHMs),
|
||||
new(0x2B4, 43, 999, info, Berries),
|
||||
new(0x000, 30, 999, info, PCItems),
|
||||
];
|
||||
|
||||
public PlayerBag3FRLG(SAV3FRLG sav) : this(sav.LargeBlock.Inventory, sav.SmallBlock.SecurityKey, sav.IsVirtualConsole) { }
|
||||
public PlayerBag3FRLG(ReadOnlySpan<byte> data, uint security, bool vc) : this(vc)
|
||||
{
|
||||
UpdateSecurityKey(security);
|
||||
Pouches.LoadAll(data);
|
||||
}
|
||||
|
||||
public override void CopyTo(SaveFile sav) => CopyTo((SAV3FRLG)sav);
|
||||
public void CopyTo(SAV3FRLG sav) => CopyTo(sav.LargeBlock.Inventory);
|
||||
public void CopyTo(Span<byte> data) => Pouches.SaveAll(data);
|
||||
|
||||
public override int GetMaxCount(InventoryType type, int itemIndex)
|
||||
{
|
||||
if (type is TMHMs && ItemConverter.IsItemHM3((ushort)itemIndex))
|
||||
return 1;
|
||||
return GetMaxCount(type);
|
||||
}
|
||||
|
||||
public void UpdateSecurityKey(uint securityKey)
|
||||
{
|
||||
foreach (var pouch in Pouches)
|
||||
{
|
||||
if (pouch.Type != PCItems)
|
||||
pouch.SecurityKey = securityKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static PKHeX.Core.InventoryType;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public sealed class PlayerBag3RS : PlayerBag
|
||||
{
|
||||
public override IReadOnlyList<InventoryPouch3> Pouches { get; } = GetPouches(ItemStorage3RS.Instance);
|
||||
public override ItemStorage3RS Info => ItemStorage3RS.Instance;
|
||||
|
||||
private static InventoryPouch3[] GetPouches(ItemStorage3RS info) =>
|
||||
[
|
||||
new(0x0C8, 20, 099, info, Items),
|
||||
new(0x118, 20, 001, info, KeyItems),
|
||||
new(0x168, 16, 099, info, Balls),
|
||||
new(0x1A8, 64, 099, info, TMHMs),
|
||||
new(0x2A8, 46, 999, info, Berries),
|
||||
new(0x000, 50, 999, info, PCItems),
|
||||
];
|
||||
|
||||
public PlayerBag3RS(SAV3RS sav) : this(sav.LargeBlock.Inventory) { }
|
||||
public PlayerBag3RS(ReadOnlySpan<byte> data) => Pouches.LoadAll(data);
|
||||
|
||||
public override void CopyTo(SaveFile sav) => CopyTo((SAV3RS)sav);
|
||||
public void CopyTo(SAV3RS sav) => CopyTo(sav.LargeBlock.Inventory);
|
||||
public void CopyTo(Span<byte> data) => Pouches.SaveAll(data);
|
||||
|
||||
public override int GetMaxCount(InventoryType type, int itemIndex)
|
||||
{
|
||||
if (type is TMHMs && ItemConverter.IsItemHM3((ushort)itemIndex))
|
||||
return 1;
|
||||
return GetMaxCount(type);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static PKHeX.Core.InventoryType;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public sealed class PlayerBag3XD : PlayerBag
|
||||
{
|
||||
public override IReadOnlyList<InventoryPouch3GC> Pouches { get; } = GetPouches(ItemStorage3XD.Instance);
|
||||
public override ItemStorage3XD Info => ItemStorage3XD.Instance;
|
||||
|
||||
private static InventoryPouch3GC[] GetPouches(ItemStorage3XD info) =>
|
||||
[
|
||||
new(0x000, 30, 999, info, Items), // 20 COLO, 30 XD
|
||||
new(0x078, 43, 001, info, KeyItems),
|
||||
new(0x124, 16, 999, info, Balls),
|
||||
new(0x164, 64, 999, info, TMHMs),
|
||||
new(0x264, 46, 999, info, Berries),
|
||||
new(0x31C, 03, 999, info, Medicine), // Cologne
|
||||
new(0x328, 60, 001, info, BattleItems), // Disc
|
||||
];
|
||||
|
||||
public PlayerBag3XD(SAV3XD sav) : this(sav.Data[sav.OFS_Pouch..]) { }
|
||||
public PlayerBag3XD(ReadOnlySpan<byte> data) => Pouches.LoadAll(data);
|
||||
|
||||
public override void CopyTo(SaveFile sav) => CopyTo((SAV3XD)sav);
|
||||
public void CopyTo(SAV3XD sav) => CopyTo(sav.Data[sav.OFS_Pouch..]);
|
||||
public void CopyTo(Span<byte> data) => Pouches.SaveAll(data);
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static PKHeX.Core.InventoryType;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public sealed class PlayerBag4DP : PlayerBag
|
||||
{
|
||||
private const int BaseOffset = 0x624;
|
||||
|
||||
public override IReadOnlyList<InventoryPouch4> Pouches { get; } = GetPouches(ItemStorage4DP.Instance);
|
||||
public override ItemStorage4DP Info => ItemStorage4DP.Instance;
|
||||
|
||||
private static InventoryPouch4[] GetPouches(ItemStorage4DP info) =>
|
||||
[
|
||||
new(0x000, 999, info, Items),
|
||||
new(0x294, 001, info, KeyItems),
|
||||
new(0x35C, 099, info, TMHMs),
|
||||
new(0x4EC, 999, info, MailItems),
|
||||
new(0x51C, 999, info, Medicine),
|
||||
new(0x5BC, 999, info, Berries),
|
||||
new(0x6BC, 999, info, Balls),
|
||||
new(0x6F8, 999, info, BattleItems),
|
||||
];
|
||||
|
||||
public PlayerBag4DP(SAV4DP sav) : this(sav.General[BaseOffset..]) { }
|
||||
public PlayerBag4DP(ReadOnlySpan<byte> data) => Pouches.LoadAll(data);
|
||||
|
||||
public override void CopyTo(SaveFile sav) => CopyTo((SAV4DP)sav);
|
||||
public void CopyTo(SAV4DP sav) => CopyTo(sav.General[BaseOffset..]);
|
||||
public void CopyTo(Span<byte> data) => Pouches.SaveAll(data);
|
||||
|
||||
public override int GetMaxCount(InventoryType type, int itemIndex)
|
||||
{
|
||||
if (type is TMHMs && ItemConverter.IsItemHM4((ushort)itemIndex))
|
||||
return 1;
|
||||
return GetMaxCount(type);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static PKHeX.Core.InventoryType;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public sealed class PlayerBag4HGSS : PlayerBag
|
||||
{
|
||||
private const int BaseOffset = 0x644;
|
||||
|
||||
public override IReadOnlyList<InventoryPouch4> Pouches { get; } = GetPouches(ItemStorage4HGSS.Instance);
|
||||
public override ItemStorage4HGSS Info => ItemStorage4HGSS.Instance;
|
||||
|
||||
private static InventoryPouch4[] GetPouches(ItemStorage4HGSS info) =>
|
||||
[
|
||||
new(0x000, 999, info, Items),
|
||||
new(0x294, 001, info, KeyItems),
|
||||
new(0x35C, 099, info, TMHMs),
|
||||
new(0x4F0, 999, info, MailItems),
|
||||
new(0x520, 999, info, Medicine),
|
||||
new(0x5C0, 999, info, Berries),
|
||||
new(0x6C0, 999, info, Balls),
|
||||
new(0x720, 999, info, BattleItems),
|
||||
];
|
||||
|
||||
public PlayerBag4HGSS(SAV4HGSS sav) : this(sav.General[BaseOffset..]) { }
|
||||
public PlayerBag4HGSS(ReadOnlySpan<byte> data) => Pouches.LoadAll(data);
|
||||
|
||||
public override void CopyTo(SaveFile sav) => CopyTo((SAV4HGSS)sav);
|
||||
public void CopyTo(SAV4HGSS sav) => CopyTo(sav.General[BaseOffset..]);
|
||||
public void CopyTo(Span<byte> data) => Pouches.SaveAll(data);
|
||||
|
||||
public override int GetMaxCount(InventoryType type, int itemIndex)
|
||||
{
|
||||
if (type is TMHMs && ItemConverter.IsItemHM4((ushort)itemIndex))
|
||||
return 1;
|
||||
return GetMaxCount(type);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static PKHeX.Core.InventoryType;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public sealed class PlayerBag4Pt : PlayerBag
|
||||
{
|
||||
private const int BaseOffset = 0x630;
|
||||
|
||||
public override IReadOnlyList<InventoryPouch4> Pouches { get; } = GetPouches(ItemStorage4Pt.Instance);
|
||||
public override ItemStorage4Pt Info => ItemStorage4Pt.Instance;
|
||||
|
||||
private static InventoryPouch4[] GetPouches(ItemStorage4Pt info) =>
|
||||
[
|
||||
new(0x000, 999, info, Items),
|
||||
new(0x294, 001, info, KeyItems),
|
||||
new(0x35C, 099, info, TMHMs),
|
||||
new(0x4EC, 999, info, MailItems),
|
||||
new(0x51C, 999, info, Medicine),
|
||||
new(0x5BC, 999, info, Berries),
|
||||
new(0x6BC, 999, info, Balls),
|
||||
new(0x6F8, 999, info, BattleItems),
|
||||
];
|
||||
|
||||
public PlayerBag4Pt(SAV4Pt sav) : this(sav.General[BaseOffset..]) { }
|
||||
public PlayerBag4Pt(ReadOnlySpan<byte> data) => Pouches.LoadAll(data);
|
||||
|
||||
public override void CopyTo(SaveFile sav) => CopyTo((SAV4Pt)sav);
|
||||
public void CopyTo(SAV4Pt sav) => CopyTo(sav.General[BaseOffset..]);
|
||||
public void CopyTo(Span<byte> data) => Pouches.SaveAll(data);
|
||||
|
||||
public override int GetMaxCount(InventoryType type, int itemIndex)
|
||||
{
|
||||
if (type is TMHMs && ItemConverter.IsItemHM4((ushort)itemIndex))
|
||||
return 1;
|
||||
return GetMaxCount(type);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static PKHeX.Core.InventoryType;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public sealed class PlayerBag5B2W2 : PlayerBag
|
||||
{
|
||||
public override IReadOnlyList<InventoryPouch4> Pouches { get; } = GetPouches(ItemStorage5B2W2.Instance);
|
||||
public override ItemStorage5B2W2 Info => ItemStorage5B2W2.Instance;
|
||||
|
||||
private static InventoryPouch4[] GetPouches(ItemStorage5B2W2 info) =>
|
||||
[
|
||||
new(0x000, 999, info, Items), // 0
|
||||
new(0x4D8, 001, info, KeyItems), // 1
|
||||
new(0x624, 001, info, TMHMs), // 2
|
||||
new(0x7D8, 999, info, Medicine), // 3
|
||||
new(0x898, 999, info, Berries), // 4
|
||||
];
|
||||
|
||||
public PlayerBag5B2W2(SAV5B2W2 sav) : this(sav.Items) { }
|
||||
public PlayerBag5B2W2(MyItem5B2W2 block) : this(block.Data) { }
|
||||
public PlayerBag5B2W2(ReadOnlySpan<byte> data) => Pouches.LoadAll(data);
|
||||
|
||||
public override void CopyTo(SaveFile sav) => CopyTo((SAV5B2W2)sav);
|
||||
public void CopyTo(SAV5B2W2 sav) => CopyTo(sav.Items);
|
||||
public void CopyTo(MyItem5B2W2 block) => CopyTo(block.Data);
|
||||
public void CopyTo(Span<byte> data) => Pouches.SaveAll(data);
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static PKHeX.Core.InventoryType;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public sealed class PlayerBag5BW : PlayerBag
|
||||
{
|
||||
public override IReadOnlyList<InventoryPouch4> Pouches { get; } = GetPouches(ItemStorage5BW.Instance);
|
||||
public override ItemStorage5BW Info => ItemStorage5BW.Instance;
|
||||
|
||||
private static InventoryPouch4[] GetPouches(ItemStorage5BW info) =>
|
||||
[
|
||||
new(0x000, 999, info, Items), // 0
|
||||
new(0x4D8, 001, info, KeyItems), // 1
|
||||
new(0x624, 001, info, TMHMs), // 2
|
||||
new(0x7D8, 999, info, Medicine), // 3
|
||||
new(0x898, 999, info, Berries), // 4
|
||||
];
|
||||
|
||||
public PlayerBag5BW(SAV5BW sav) : this(sav.Items) { }
|
||||
public PlayerBag5BW(MyItem5BW block) : this(block.Data) { }
|
||||
public PlayerBag5BW(ReadOnlySpan<byte> data) => Pouches.LoadAll(data);
|
||||
|
||||
public override void CopyTo(SaveFile sav) => CopyTo((SAV5BW)sav);
|
||||
public void CopyTo(SAV5BW sav) => CopyTo(sav.Items);
|
||||
public void CopyTo(MyItem5BW block) => CopyTo(block.Data);
|
||||
public void CopyTo(Span<byte> data) => Pouches.SaveAll(data);
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static PKHeX.Core.InventoryType;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public sealed class PlayerBag6AO : PlayerBag
|
||||
{
|
||||
public override IReadOnlyList<InventoryPouch4> Pouches { get; } = GetPouches(ItemStorage6AO.Instance);
|
||||
public override ItemStorage6AO Info => ItemStorage6AO.Instance;
|
||||
|
||||
private static InventoryPouch4[] GetPouches(ItemStorage6AO info) =>
|
||||
[
|
||||
new(0x000, 999, info, Items), // 0
|
||||
new(0x640, 001, info, KeyItems), // 1
|
||||
new(0x7C0, 001, info, TMHMs), // 2
|
||||
new(0x970, 999, info, Medicine), // 3, +2 items shift because 2 HMs added
|
||||
new(0xA70, 999, info, Berries), // 4
|
||||
];
|
||||
|
||||
public PlayerBag6AO(SAV6AO sav) : this(sav.Items) { }
|
||||
public PlayerBag6AO(SAV6AODemo sav) : this(sav.Items) { }
|
||||
public PlayerBag6AO(MyItem6AO block) : this(block.Data) { }
|
||||
public PlayerBag6AO(ReadOnlySpan<byte> data) => Pouches.LoadAll(data);
|
||||
|
||||
public override void CopyTo(SaveFile sav)
|
||||
{
|
||||
if (sav is SAV6AO ao)
|
||||
CopyTo(ao);
|
||||
else if (sav is SAV6AODemo demo)
|
||||
CopyTo(demo);
|
||||
else
|
||||
throw new ArgumentException($"Incompatible save type {sav.GetType().Name} for {nameof(PlayerBag6AO)}");
|
||||
}
|
||||
public void CopyTo(SAV6AO sav) => CopyTo(sav.Items);
|
||||
public void CopyTo(SAV6AODemo sav) => CopyTo(sav.Items);
|
||||
public void CopyTo(MyItem6AO block) => CopyTo(block.Data);
|
||||
public void CopyTo(Span<byte> data) => Pouches.SaveAll(data);
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static PKHeX.Core.InventoryType;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public sealed class PlayerBag6XY : PlayerBag
|
||||
{
|
||||
public override ItemStorage6XY Info => ItemStorage6XY.Instance;
|
||||
public override IReadOnlyList<InventoryPouch4> Pouches { get; } = GetPouches(ItemStorage6XY.Instance);
|
||||
|
||||
private static InventoryPouch4[] GetPouches(ItemStorage6XY info) =>
|
||||
[
|
||||
new(0x000, 999, info, Items), // 0
|
||||
new(0x640, 001, info, KeyItems), // 1
|
||||
new(0x7C0, 001, info, TMHMs), // 2
|
||||
new(0x968, 999, info, Medicine), // 3
|
||||
new(0xA68, 999, info, Berries), // 4
|
||||
];
|
||||
|
||||
public PlayerBag6XY(SAV6XY sav) : this(sav.Items) { }
|
||||
public PlayerBag6XY(MyItem6XY block) : this(block.Data) { }
|
||||
public PlayerBag6XY(ReadOnlySpan<byte> data) => Pouches.LoadAll(data);
|
||||
|
||||
public override void CopyTo(SaveFile sav) => CopyTo((SAV6XY)sav);
|
||||
public void CopyTo(SAV6XY sav) => CopyTo(sav.Items);
|
||||
public void CopyTo(MyItem6XY block) => CopyTo(block.Data);
|
||||
public void CopyTo(Span<byte> data) => Pouches.SaveAll(data);
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static PKHeX.Core.InventoryType;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public sealed class PlayerBag7SM : PlayerBag
|
||||
{
|
||||
// 2x Key Item specifically for the Z-Ring: you're given one, Hala "borrows" it in the story, and then you're given it again.
|
||||
private const int ItemIndexZRing = 797;
|
||||
private const int ItemCountZRing = 2;
|
||||
|
||||
public override IReadOnlyList<InventoryPouch7> Pouches { get; } = GetPouches(ItemStorage7SM.Instance);
|
||||
public override ItemStorage7SM Info => ItemStorage7SM.Instance;
|
||||
|
||||
private static InventoryPouch7[] GetPouches(ItemStorage7SM info) =>
|
||||
[
|
||||
new(0x000, 430, 999, info, Items), // 0
|
||||
new(0xB48, 064, 999, info, Medicine), // 1
|
||||
new(0x998, 108, 001, info, TMHMs), // 2
|
||||
new(0xC48, 072, 999, info, Berries), // 3
|
||||
new(0x6B8, 184, 001, info, KeyItems), // 4
|
||||
new(0xD68, 030, 001, info, ZCrystals), // 5
|
||||
];
|
||||
|
||||
public PlayerBag7SM(SAV7SM sav) : this(sav.Items) { }
|
||||
public PlayerBag7SM(MyItem7SM block) : this(block.Data) { }
|
||||
public PlayerBag7SM(ReadOnlySpan<byte> data) => Pouches.LoadAll(data);
|
||||
|
||||
public override void CopyTo(SaveFile sav) => CopyTo((SAV7SM)sav);
|
||||
public void CopyTo(SAV7SM sav) => CopyTo(sav.Items);
|
||||
public void CopyTo(MyItem7SM block) => CopyTo(block.Data);
|
||||
public void CopyTo(Span<byte> data) => Pouches.SaveAll(data);
|
||||
|
||||
public override int GetMaxCount(InventoryType type, int itemIndex)
|
||||
{
|
||||
if (type is KeyItems && itemIndex == ItemIndexZRing)
|
||||
return ItemCountZRing;
|
||||
return GetMaxCount(type);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static PKHeX.Core.InventoryType;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public sealed class PlayerBag7USUM : PlayerBag
|
||||
{
|
||||
// 2x Key Item specifically for the Z-Ring: you're given one, Hala "borrows" it in the story, and then you're given it again.
|
||||
private const int ItemIndexZRing = 797;
|
||||
private const int ItemCountZRing = 2;
|
||||
|
||||
public override IReadOnlyList<InventoryPouch7> Pouches { get; } = GetPouches(ItemStorage7USUM.Instance);
|
||||
public override ItemStorage7USUM Info => ItemStorage7USUM.Instance;
|
||||
|
||||
private static InventoryPouch7[] GetPouches(ItemStorage7USUM info) =>
|
||||
[
|
||||
new(0x000, 427, 999, info, Items), // 0
|
||||
new(0xB74, 060, 999, info, Medicine), // 1
|
||||
new(0x9C4, 108, 001, info, TMHMs), // 2
|
||||
new(0xC64, 067, 999, info, Berries), // 3
|
||||
new(0x6AC, 198, 001, info, KeyItems), // 4
|
||||
new(0xD70, 035, 001, info, ZCrystals), // 5
|
||||
new(0xDFC, 011, 999, info, BattleItems), // 6
|
||||
];
|
||||
|
||||
public PlayerBag7USUM(SAV7USUM sav) : this(sav.Items) { }
|
||||
public PlayerBag7USUM(MyItem7USUM block) : this(block.Data) { }
|
||||
public PlayerBag7USUM(ReadOnlySpan<byte> data) => Pouches.LoadAll(data);
|
||||
|
||||
public override void CopyTo(SaveFile sav) => CopyTo((SAV7USUM)sav);
|
||||
public void CopyTo(SAV7USUM sav) => CopyTo(sav.Items);
|
||||
public void CopyTo(MyItem7USUM block) => CopyTo(block.Data);
|
||||
public void CopyTo(Span<byte> data) => Pouches.SaveAll(data);
|
||||
|
||||
public override int GetMaxCount(InventoryType type, int itemIndex)
|
||||
{
|
||||
if (type is KeyItems && itemIndex == ItemIndexZRing)
|
||||
return ItemCountZRing;
|
||||
return GetMaxCount(type);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static PKHeX.Core.InventoryType;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public sealed class PlayerBag7b : PlayerBag
|
||||
{
|
||||
public override IReadOnlyList<InventoryPouch7b> Pouches { get; } = GetPouches(ItemStorage7GG.Instance);
|
||||
public override ItemStorage7GG Info => ItemStorage7GG.Instance;
|
||||
|
||||
private static InventoryPouch7b[] GetPouches(ItemStorage7GG info) =>
|
||||
[
|
||||
new(0x0000, 060, 999, info, Medicine), // 0
|
||||
new(0x00F0, 108, 001, info, TMHMs), // 1
|
||||
new(0x02A0, 200, 999, info, Candy), // 2
|
||||
new(0x05C0, 150, 999, info, ZCrystals), // 3
|
||||
new(0x0818, 050, 999, info, Balls), // 4
|
||||
new(0x08E0, 150, 999, info, BattleItems), // 5 - Battle Items and Mega Stones mixed.
|
||||
new(0x0B38, 150, 999, info, Items), // 6 - Items and Key Items mixed.
|
||||
];
|
||||
|
||||
public PlayerBag7b(SAV7b sav) : this(sav.Items) { }
|
||||
public PlayerBag7b(MyItem7b block) : this(block.Data) { }
|
||||
public PlayerBag7b(ReadOnlySpan<byte> data) => Pouches.LoadAll(data);
|
||||
|
||||
public override void CopyTo(SaveFile sav) => CopyTo((SAV7b)sav);
|
||||
public void CopyTo(SAV7b sav) => CopyTo(sav.Items);
|
||||
public void CopyTo(MyItem7b block) => CopyTo(block.Data);
|
||||
public void CopyTo(Span<byte> data) => Pouches.SaveAll(data);
|
||||
|
||||
public override int GetMaxCount(InventoryType type, int itemIndex) => type switch
|
||||
{
|
||||
BattleItems when itemIndex > 100 => 1, // mixed regular battle items & mega stones
|
||||
Items when ItemStorage7GG.Key.Contains((ushort)itemIndex) => 1, // mixed regular items & key items
|
||||
_ => GetMaxCount(type)
|
||||
};
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static PKHeX.Core.InventoryType;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public sealed class PlayerBag8 : PlayerBag
|
||||
{
|
||||
public override IReadOnlyList<InventoryPouch8> Pouches { get; } = GetPouches(ItemStorage8SWSH.Instance);
|
||||
public override ItemStorage8SWSH Info => ItemStorage8SWSH.Instance;
|
||||
|
||||
private static InventoryPouch8[] GetPouches(ItemStorage8SWSH info) =>
|
||||
[
|
||||
new(0x0000, 060, 999, info, Medicine),
|
||||
new(0x00F0, 030, 999, info, Balls),
|
||||
new(0x0168, 020, 999, info, BattleItems),
|
||||
new(0x01B8, 080, 999, info, Berries),
|
||||
new(0x02F8, 550, 999, info, Items),
|
||||
new(0x0B90, 210, 999, info, TMHMs),
|
||||
new(0x0ED8, 100, 999, info, Treasure),
|
||||
new(0x1068, 100, 999, info, Candy),
|
||||
new(0x11F8, 064, 001, info, KeyItems),
|
||||
];
|
||||
|
||||
public PlayerBag8(SAV8SWSH sav) : this(sav.Items) { }
|
||||
public PlayerBag8(MyItem8 block) : this(block.Data) { }
|
||||
public PlayerBag8(ReadOnlySpan<byte> data) => Pouches.LoadAll(data);
|
||||
|
||||
public override void CopyTo(SaveFile sav) => CopyTo((SAV8SWSH)sav);
|
||||
public void CopyTo(SAV8SWSH sav) => CopyTo(sav.Items);
|
||||
public void CopyTo(MyItem8 block) => CopyTo(block.Data);
|
||||
public void CopyTo(Span<byte> data) => Pouches.SaveAll(data);
|
||||
|
||||
public override int GetMaxCount(InventoryType type, int itemIndex)
|
||||
{
|
||||
// TMs are clamped to 1, let TRs be whatever
|
||||
if (type is TMHMs && !ItemStorage8SWSH.IsTechRecord((ushort)itemIndex))
|
||||
return 1;
|
||||
return GetMaxCount(type);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static PKHeX.Core.SaveBlockAccessor8LA;
|
||||
using static PKHeX.Core.InventoryType;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public sealed class PlayerBag8a : PlayerBag
|
||||
{
|
||||
public override InventoryPouch8a[] Pouches { get; }
|
||||
public override ItemStorage8LA Info => ItemStorage8LA.Instance;
|
||||
|
||||
public PlayerBag8a(SAV8LA sav) => Pouches = LoadPouches(sav.Accessor);
|
||||
|
||||
private InventoryPouch8a[] LoadPouches(SCBlockAccessor access)
|
||||
{
|
||||
var satchel = (uint)access.GetBlock(KSatchelUpgrades).GetValue();
|
||||
var regularSize = (int)Math.Min(675, satchel + 20);
|
||||
var pouches = GetPouches(Info, regularSize);
|
||||
LoadFrom(pouches, access);
|
||||
return pouches;
|
||||
}
|
||||
|
||||
private static InventoryPouch8a[] GetPouches(ItemStorage8LA info, int size) =>
|
||||
[
|
||||
new(size, 999, info, Items),
|
||||
new(0100, 001, info, KeyItems),
|
||||
new(0180, 999, info, PCItems),
|
||||
new(0070, 001, info, Treasure),
|
||||
];
|
||||
|
||||
public override void CopyTo(SaveFile sav) => CopyTo((SAV8LA)sav);
|
||||
public void CopyTo(SAV8LA sav) => CopyTo(sav.Accessor);
|
||||
public void CopyTo(SCBlockAccessor access) => CopyTo(Pouches, access);
|
||||
|
||||
private static void LoadFrom(ReadOnlySpan<InventoryPouch8a> pouches, SCBlockAccessor access)
|
||||
{
|
||||
pouches[0].GetPouch(access.GetBlock(KItemRegular).Data);
|
||||
pouches[1].GetPouch(access.GetBlock(KItemKey).Data);
|
||||
pouches[2].GetPouch(access.GetBlock(KItemStored).Data);
|
||||
pouches[3].GetPouch(access.GetBlock(KItemRecipe).Data);
|
||||
LoadFavorites(pouches, access);
|
||||
}
|
||||
|
||||
private static void CopyTo(ReadOnlySpan<InventoryPouch8a> pouches, SCBlockAccessor access)
|
||||
{
|
||||
SavePouches(pouches, access);
|
||||
SaveFavorites(pouches, access);
|
||||
}
|
||||
|
||||
private static void SavePouches(ReadOnlySpan<InventoryPouch8a> pouches, SCBlockAccessor access)
|
||||
{
|
||||
pouches[0].SetPouch(access.GetBlock(KItemRegular).Data);
|
||||
pouches[1].SetPouch(access.GetBlock(KItemKey).Data);
|
||||
pouches[2].SetPouch(access.GetBlock(KItemStored).Data);
|
||||
pouches[3].SetPouch(access.GetBlock(KItemRecipe).Data);
|
||||
}
|
||||
|
||||
private static void LoadFavorites(ReadOnlySpan<InventoryPouch8a> pouches, SCBlockAccessor access)
|
||||
{
|
||||
var favorites = access.GetBlock(KItemFavorite).Data;
|
||||
foreach (var arr in pouches)
|
||||
LoadFavorites(arr.Items, favorites);
|
||||
}
|
||||
|
||||
private static void SaveFavorites(ReadOnlySpan<InventoryPouch8a> pouches, SCBlockAccessor access)
|
||||
{
|
||||
var favorites = access.GetBlock(KItemFavorite).Data;
|
||||
favorites.Clear();
|
||||
foreach (var arr in pouches)
|
||||
SaveFavorites(arr.Items, favorites);
|
||||
}
|
||||
|
||||
private static void LoadFavorites(ReadOnlySpan<InventoryItem8a> items, ReadOnlySpan<byte> favorites)
|
||||
{
|
||||
foreach (var item in items)
|
||||
{
|
||||
var itemID = item.Index;
|
||||
var ofs = itemID >> 3;
|
||||
if ((uint)ofs >= favorites.Length)
|
||||
continue;
|
||||
|
||||
var bit = itemID & 7;
|
||||
item.IsFavorite = FlagUtil.GetFlag(favorites, ofs, bit);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SaveFavorites(IEnumerable<InventoryItem8a> items, Span<byte> favorites)
|
||||
{
|
||||
foreach (var item in items)
|
||||
{
|
||||
var itemID = item.Index;
|
||||
var ofs = itemID >> 3;
|
||||
if ((uint)ofs >= favorites.Length)
|
||||
continue;
|
||||
|
||||
var bit = itemID & 7;
|
||||
var value = FlagUtil.GetFlag(favorites, ofs, bit);
|
||||
value |= item.IsFavorite;
|
||||
FlagUtil.SetFlag(favorites, ofs, bit, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static PKHeX.Core.InventoryType;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public sealed class PlayerBag8b : PlayerBag
|
||||
{
|
||||
public override IReadOnlyList<InventoryPouch8b> Pouches { get; } = GetPouches();
|
||||
public override ItemStorage8BDSP Info => ItemStorage8BDSP.Instance;
|
||||
|
||||
private static InventoryPouch8b[] GetPouches() =>
|
||||
[
|
||||
MakePouch(Items),
|
||||
MakePouch(KeyItems),
|
||||
MakePouch(TMHMs),
|
||||
MakePouch(Medicine),
|
||||
MakePouch(Berries),
|
||||
MakePouch(Balls),
|
||||
MakePouch(BattleItems),
|
||||
MakePouch(Treasure),
|
||||
];
|
||||
|
||||
public PlayerBag8b(SAV8BS sav) : this(sav.Items) { }
|
||||
public PlayerBag8b(MyItem8b block) : this(block.Data) { }
|
||||
public PlayerBag8b(ReadOnlySpan<byte> data) => Pouches.LoadAll(data);
|
||||
|
||||
|
||||
public override void CopyTo(SaveFile sav) => CopyTo((SAV8BS)sav);
|
||||
|
||||
public void CopyTo(SAV8BS sav) => CopyTo(sav.Items);
|
||||
public void CopyTo(MyItem8b items)
|
||||
{
|
||||
CopyTo(items.Data);
|
||||
items.CleanIllegalSlots();
|
||||
}
|
||||
|
||||
public void CopyTo(Span<byte> data) => Pouches.SaveAll(data);
|
||||
|
||||
private static InventoryPouch8b MakePouch(InventoryType type)
|
||||
{
|
||||
var info = ItemStorage8BDSP.Instance;
|
||||
var max = info.GetMax(type);
|
||||
return new InventoryPouch8b(type, info, max);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static PKHeX.Core.InventoryType;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public sealed class PlayerBag9 : PlayerBag
|
||||
{
|
||||
public override IReadOnlyList<InventoryPouch9> Pouches { get; } = GetPouches();
|
||||
public override ItemStorage9SV Info => ItemStorage9SV.Instance;
|
||||
|
||||
private static InventoryPouch9[] GetPouches() =>
|
||||
[
|
||||
MakePouch(Medicine),
|
||||
MakePouch(Balls),
|
||||
MakePouch(BattleItems),
|
||||
MakePouch(Berries),
|
||||
MakePouch(Items),
|
||||
MakePouch(TMHMs),
|
||||
MakePouch(Treasure),
|
||||
MakePouch(Ingredients),
|
||||
MakePouch(KeyItems),
|
||||
MakePouch(Candy),
|
||||
];
|
||||
|
||||
public PlayerBag9(SAV9SV sav) : this(sav.Items) { }
|
||||
public PlayerBag9(MyItem9 block) : this(block.Data) { }
|
||||
public PlayerBag9(ReadOnlySpan<byte> data) => Pouches.LoadAll(data);
|
||||
|
||||
public override void CopyTo(SaveFile sav) => CopyTo((SAV9SV)sav);
|
||||
public void CopyTo(SAV9SV sav) => CopyTo(sav.Items);
|
||||
public void CopyTo(MyItem9 items)
|
||||
{
|
||||
CopyTo(items.Data);
|
||||
items.CleanIllegalSlots();
|
||||
}
|
||||
|
||||
public void CopyTo(Span<byte> data) => Pouches.SaveAll(data);
|
||||
|
||||
public override int GetMaxCount(InventoryType type, int itemIndex)
|
||||
{
|
||||
if (type is Ingredients && ItemStorage9SV.IsAccessory(itemIndex))
|
||||
return 1;
|
||||
return GetMaxCount(type);
|
||||
}
|
||||
|
||||
private static InventoryPouch9 MakePouch(InventoryType type)
|
||||
{
|
||||
var info = ItemStorage9SV.Instance;
|
||||
var max = info.GetMax(type);
|
||||
return new InventoryPouch9(type, info, max, GetPouchIndex(type));
|
||||
}
|
||||
|
||||
private static uint GetPouchIndex(InventoryType type) => type switch
|
||||
{
|
||||
Items => InventoryItem9.PouchOther,
|
||||
KeyItems => InventoryItem9.PouchEvent,
|
||||
TMHMs => InventoryItem9.PouchTMHM,
|
||||
Medicine => InventoryItem9.PouchMedicine,
|
||||
Berries => InventoryItem9.PouchBerries,
|
||||
Balls => InventoryItem9.PouchBall,
|
||||
BattleItems => InventoryItem9.PouchBattle,
|
||||
Treasure => InventoryItem9.PouchTreasure,
|
||||
Ingredients => InventoryItem9.PouchPicnic,
|
||||
Candy => InventoryItem9.PouchMaterial,
|
||||
_ => InventoryItem9.PouchInvalid,
|
||||
};
|
||||
}
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static PKHeX.Core.InventoryType;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
public sealed class PlayerBag9a : PlayerBag
|
||||
{
|
||||
private const int CherishedRing = 2612;
|
||||
private const int MegaShardItemIndex = 2618;
|
||||
private const int ColorfulScrew = 2619;
|
||||
|
||||
private const int MegaShardCountMaxPatched = 9_999; // In 2.0.1 update, the max count for Mega Shard was increased to 9,999.
|
||||
|
||||
private readonly bool IsPatchedMegaShardCountMax;
|
||||
public override IReadOnlyList<InventoryPouch9a> Pouches { get; } = GetPouches();
|
||||
public override ItemStorage9ZA Info => ItemStorage9ZA.Instance;
|
||||
|
||||
private static InventoryPouch9a[] GetPouches() =>
|
||||
[
|
||||
MakePouch(Medicine),
|
||||
MakePouch(Balls),
|
||||
MakePouch(Berries),
|
||||
MakePouch(Items),
|
||||
MakePouch(TMHMs),
|
||||
MakePouch(MegaStones),
|
||||
MakePouch(Treasure),
|
||||
MakePouch(KeyItems),
|
||||
];
|
||||
|
||||
public PlayerBag9a(SAV9ZA sav) : this(sav.Items, sav.Accessor.HasBlock(0x0ABC6547)) { }
|
||||
public PlayerBag9a(MyItem9a block, bool isMegaShardMaxPatched = true) : this(block.Data, isMegaShardMaxPatched) { }
|
||||
public PlayerBag9a(Span<byte> data, bool isMegaShardMaxPatched = true)
|
||||
{
|
||||
IsPatchedMegaShardCountMax = isMegaShardMaxPatched;
|
||||
Pouches.LoadAll(data);
|
||||
}
|
||||
|
||||
public override void CopyTo(SaveFile sav) => CopyTo((SAV9ZA)sav);
|
||||
public void CopyTo(SAV9ZA sav) => CopyTo(sav.Items);
|
||||
public void CopyTo(MyItem9a items)
|
||||
{
|
||||
CopyTo(items.Data);
|
||||
items.CleanIllegalSlots();
|
||||
}
|
||||
|
||||
public void CopyTo(Span<byte> data) => Pouches.SaveAll(data);
|
||||
|
||||
public override int GetMaxCount(InventoryType type, int itemIndex) => itemIndex switch
|
||||
{
|
||||
MegaShardItemIndex when IsPatchedMegaShardCountMax => MegaShardCountMaxPatched,
|
||||
ColorfulScrew => GetCurrentItemCount(ColorfulScrew), // Don't modify.
|
||||
CherishedRing => 0, // Quest item, never possessed.
|
||||
_ => GetMaxCount(type),
|
||||
};
|
||||
|
||||
private int GetCurrentItemCount(int itemIndex)
|
||||
{
|
||||
foreach (var pouch in Pouches)
|
||||
{
|
||||
foreach (var item in pouch.Items)
|
||||
{
|
||||
if (item.Index == itemIndex)
|
||||
return item.Count;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static InventoryPouch9a MakePouch(InventoryType type)
|
||||
{
|
||||
var info = ItemStorage9ZA.Instance;
|
||||
var max = info.GetMax(type);
|
||||
return new InventoryPouch9a(type, info, max);
|
||||
}
|
||||
}
|
||||
|
|
@ -28,7 +28,7 @@ public sealed class ItemStorage3Colo : IItemStorage
|
|||
540, 541, 542, 546, 547,
|
||||
];
|
||||
|
||||
public bool IsLegal(InventoryType type, int itemIndex, int itemCount) => !Unreleased.Contains((ushort)itemIndex);
|
||||
public bool IsLegal(InventoryType type, int itemIndex, int itemCount) => true;
|
||||
|
||||
public ReadOnlySpan<ushort> GetItems(InventoryType type) => type switch
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,16 +13,14 @@ public sealed class ItemStorage3E : IItemStorage
|
|||
public static ReadOnlySpan<ushort> Key =>
|
||||
[
|
||||
// R/S
|
||||
259, 260, 261, 262, 263, 264, 265, 266, 268, 269, 270, 271, 272, 273, 274, 275, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288,
|
||||
259, 260, 261, 262, 263, 264, 265, 266, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288,
|
||||
// FR/LG
|
||||
370, 371, 372,
|
||||
349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374,
|
||||
// E
|
||||
375, 376,
|
||||
];
|
||||
|
||||
private static readonly ushort[] PCItems = [.. General, .. Berry, .. Balls, .. Machine];
|
||||
|
||||
public bool IsLegal(InventoryType type, int itemIndex, int itemCount) => !Unreleased.Contains((ushort)itemIndex);
|
||||
public bool IsLegal(InventoryType type, int itemIndex, int itemCount) => true;
|
||||
|
||||
public ReadOnlySpan<ushort> GetItems(InventoryType type) => type switch
|
||||
{
|
||||
|
|
@ -31,7 +29,7 @@ public sealed class ItemStorage3E : IItemStorage
|
|||
InventoryType.Balls => Balls,
|
||||
InventoryType.TMHMs => Machine,
|
||||
InventoryType.Berries => Berry,
|
||||
InventoryType.PCItems => PCItems,
|
||||
InventoryType.PCItems => General,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,12 +13,12 @@ public sealed class ItemStorage3FRLG : IItemStorage
|
|||
public static ReadOnlySpan<ushort> Key =>
|
||||
[
|
||||
// R/S
|
||||
260, 261, 262, 263, 264, 265,
|
||||
259, 260, 261, 262, 263, 264, 265, 266, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288,
|
||||
// FR/LG
|
||||
349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374,
|
||||
];
|
||||
|
||||
public bool IsLegal(InventoryType type, int itemIndex, int itemCount) => !Unreleased.Contains((ushort)itemIndex);
|
||||
public bool IsLegal(InventoryType type, int itemIndex, int itemCount) => true;
|
||||
|
||||
public ReadOnlySpan<ushort> GetItems(InventoryType type) => type switch
|
||||
{
|
||||
|
|
@ -31,58 +31,3 @@ public sealed class ItemStorage3FRLG : IItemStorage
|
|||
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Item storage for <see cref="GameVersion.FR"/> and <see cref="GameVersion.LG"/> on <see cref="GameConsole.NX"/>.
|
||||
/// </summary>
|
||||
public sealed class ItemStorage3FRLG_VC : IItemStorage // TODO VC RSE: delete me and any usages as RSE gives the remainder of items.
|
||||
{
|
||||
public static readonly ItemStorage3FRLG_VC Instance = new();
|
||||
public ReadOnlySpan<ushort> GetItems(InventoryType type) => ItemStorage3FRLG.Instance.GetItems(type);
|
||||
|
||||
public bool IsLegal(InventoryType type, int itemIndex, int itemCount) => !IsUnreleasedHeld(itemIndex); // use VC unreleased list
|
||||
|
||||
public static bool IsUnreleasedHeld(int itemIndex) => Unreleased.Contains((ushort)itemIndex);
|
||||
|
||||
private static ReadOnlySpan<ushort> Unreleased =>
|
||||
[
|
||||
// Unobtainable
|
||||
005, // Safari
|
||||
|
||||
// TODO RSE VC: Remove these
|
||||
007, 012, // Dive Ball, Premier Ball (Unobtainable without trading from R/S/E)
|
||||
039, 041, 042, 043, // Flutes (Yellow is obtainable via Coins)
|
||||
|
||||
// Unobtainable
|
||||
044, // Berry Juice
|
||||
|
||||
// TODO RSE VC: Remove these
|
||||
046, 047, // Shoal Salt, Shoal Shell
|
||||
048, 049, 050, 051, // Shards
|
||||
081, // Fluffy Tail
|
||||
121, 122, 123, 124, 125, 126, 127, 128, 129, // Mail
|
||||
168, // Liechi Berry (Mirage Island)
|
||||
|
||||
// Event Berries (Unobtainable)
|
||||
169, // Ganlon Berry (Event)
|
||||
170, // Salac Berry (Event)
|
||||
171, // Petaya Berry (Event)
|
||||
172, // Apicot Berry (Event)
|
||||
173, // Lansat Berry (Event)
|
||||
174, // Starf Berry (Event)
|
||||
175, // Enigma Berry (Event)
|
||||
|
||||
// TODO RSE VC: Remove these
|
||||
179, // BrightPowder
|
||||
180, // White Herb
|
||||
185, // Mental Herb
|
||||
186, // Choice Band
|
||||
191, // Soul Dew
|
||||
192, // DeepSeaTooth
|
||||
193, // DeepSeaScale
|
||||
198, // Scope Lens
|
||||
202, // Light Ball
|
||||
219, // Shell Bell
|
||||
254, 255, 256, 257, 258, 259, // Scarves
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,13 +54,13 @@ public sealed class ItemStorage3RS : IItemStorage
|
|||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
|
||||
];
|
||||
|
||||
internal static ReadOnlySpan<ushort> Unreleased => [005, 044]; // Safari Ball, Berry Juice
|
||||
internal static ReadOnlySpan<ushort> Unreleased => [005]; // Safari Ball
|
||||
|
||||
public static ushort[] GetAllHeld() => [..General, ..Balls, ..Berry, ..MachineOnlyTM];
|
||||
|
||||
private static readonly ushort[] PCItems = [..General, ..Key, .. Berry, ..Balls, ..Machine];
|
||||
|
||||
public bool IsLegal(InventoryType type, int itemIndex, int itemCount) => !Unreleased.Contains((ushort)itemIndex);
|
||||
public bool IsLegal(InventoryType type, int itemIndex, int itemCount) => true;
|
||||
|
||||
public ReadOnlySpan<ushort> GetItems(InventoryType type) => type switch
|
||||
{
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public sealed class ItemStorage3XD : IItemStorage
|
|||
590, 591, 592, 593,
|
||||
];
|
||||
|
||||
public bool IsLegal(InventoryType type, int itemIndex, int itemCount) => !Unreleased.Contains((ushort)itemIndex);
|
||||
public bool IsLegal(InventoryType type, int itemIndex, int itemCount) => true;
|
||||
|
||||
public ReadOnlySpan<ushort> GetItems(InventoryType type) => type switch
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ public sealed class ItemStorage4DP : ItemStorage4, IItemStorage
|
|||
|
||||
public static ushort[] GetAllHeld() => [..GeneralDP, ..Mail, ..Medicine, ..Berry, ..BallsDPPt, ..Battle, ..Machine[..^8]];
|
||||
|
||||
public bool IsLegal(InventoryType type, int itemIndex, int itemCount) => !Unreleased.Contains((ushort)itemIndex);
|
||||
public bool IsLegal(InventoryType type, int itemIndex, int itemCount) => true;
|
||||
|
||||
public ReadOnlySpan<ushort> GetItems(InventoryType type) => type switch
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public sealed class ItemStorage4HGSS : ItemStorage4, IItemStorage
|
|||
492, 493, 494, 495, 496, 497, 498, 499, 500, // Apricorn Balls
|
||||
];
|
||||
|
||||
public bool IsLegal(InventoryType type, int itemIndex, int itemCount) => !Unreleased.Contains((ushort)itemIndex);
|
||||
public bool IsLegal(InventoryType type, int itemIndex, int itemCount) => true;
|
||||
|
||||
public ReadOnlySpan<ushort> GetItems(InventoryType type) => type switch
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public sealed class ItemStorage4Pt : ItemStorage4, IItemStorage
|
|||
|
||||
public static ushort[] GetAllHeld() => [..GeneralPt, ..Mail, ..Medicine, ..Berry, ..BallsDPPt, ..Battle, ..Machine[..^8]];
|
||||
|
||||
public bool IsLegal(InventoryType type, int itemIndex, int itemCount) => !Unreleased.Contains((ushort)itemIndex);
|
||||
public bool IsLegal(InventoryType type, int itemIndex, int itemCount) => true;
|
||||
|
||||
public ReadOnlySpan<ushort> GetItems(InventoryType type) => type switch
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ public sealed class ItemStorage5B2W2 : ItemStorage5, IItemStorage
|
|||
616, 617, 621, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638,
|
||||
];
|
||||
|
||||
public bool IsLegal(InventoryType type, int itemIndex, int itemCount) => !Unreleased.Contains((ushort)itemIndex);
|
||||
public bool IsLegal(InventoryType type, int itemIndex, int itemCount) => true;
|
||||
|
||||
public ReadOnlySpan<ushort> GetItems(InventoryType type) => type switch
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ public sealed class ItemStorage5BW : ItemStorage5, IItemStorage
|
|||
616, 617, 621, 623, 624, 625, 626,
|
||||
];
|
||||
|
||||
public bool IsLegal(InventoryType type, int itemIndex, int itemCount) => !Unreleased.Contains((ushort)itemIndex);
|
||||
public bool IsLegal(InventoryType type, int itemIndex, int itemCount) => true;
|
||||
|
||||
public ReadOnlySpan<ushort> GetItems(InventoryType type) => type switch
|
||||
{
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ public sealed class ItemStorage9SV : IItemStorage
|
|||
InventoryType.Balls => 999,
|
||||
InventoryType.BattleItems => 999,
|
||||
InventoryType.Treasure => 999,
|
||||
InventoryType.Ingredients => 999, // 999 (depends on item)
|
||||
InventoryType.Ingredients => 999, // 999
|
||||
InventoryType.Candy => 999, // 999
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(type)),
|
||||
};
|
||||
|
|
@ -244,8 +244,4 @@ public static InventoryType GetInventoryPouch(ushort itemIndex)
|
|||
}
|
||||
return InventoryType.None;
|
||||
}
|
||||
|
||||
public static bool IsIngredient(int itemIndex) => itemIndex is (>= 1888 and <= 1946);
|
||||
public static bool IsPick(int itemIndex) => itemIndex is (>= 2334 and <= 2342) or (>= 2385 and <= 2394) or 2548; // Fiery Pick
|
||||
public static bool IsAccessory(int itemIndex) => itemIndex is (>= 2311 and <= 2400) or (>= 2417 and <= 2437) && !IsPick(itemIndex); // Tablecloths, chairs, cups, etc
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,9 +3,6 @@
|
|||
|
||||
namespace PKHeX.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Item storage for <see cref="EntityContext.Gen9a"/>
|
||||
/// </summary>
|
||||
public sealed class ItemStorage9ZA : IItemStorage
|
||||
{
|
||||
public static readonly ItemStorage9ZA Instance = new();
|
||||
|
|
@ -122,6 +119,11 @@ public sealed class ItemStorage9ZA : IItemStorage
|
|||
public static ReadOnlySpan<ushort> Unreleased =>
|
||||
[
|
||||
0016, // Cherish Ball
|
||||
|
||||
0664, // Blazikenite
|
||||
0752, // Swampertite
|
||||
|
||||
2640, // Garchompite Z
|
||||
];
|
||||
|
||||
public int GetMax(InventoryType type) => type switch
|
||||
|
|
|
|||
|
|
@ -34,26 +34,6 @@ public static BinLinkerAccessor Get([ConstantExpected] string resource, [Length(
|
|||
public static BinLinkerAccessor16 Get16([ConstantExpected] string resource, [Length(2, 2)] ReadOnlySpan<byte> ident)
|
||||
=> BinLinkerAccessor16.Get(Get(resource), ident);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the localization index list for all requested strings for the <see cref="fileName"/>.
|
||||
/// </summary>
|
||||
/// <param name="fileName">Base file name</param>
|
||||
/// <param name="maxLanguage">Max language ID (inclusive)</param>
|
||||
/// <remarks>Ignores Korean Language.</remarks>
|
||||
public static string[][] GetLanguageStrings([ConstantExpected] string fileName, [ConstantExpected(Min = 6)] int maxLanguage)
|
||||
{
|
||||
var result = new string[maxLanguage + 1][];
|
||||
result[0] = result[6] = []; // 0 - None, 6 - None
|
||||
for (int i = 1; i <= 5; i++)
|
||||
result[i] = Text(fileName, i);
|
||||
for (int i = 7; i <= maxLanguage; i++)
|
||||
result[i] = Text(fileName, i);
|
||||
return result;
|
||||
|
||||
static string[] Text([ConstantExpected] string fileName, int language)
|
||||
=> Util.GetStringList(fileName, ((LanguageID)language).GetLanguageCode());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Grabs the localized names for individual templates for all languages from the specified <see cref="index"/> of the <see cref="names"/> list.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ internal static class Encounters1
|
|||
internal static readonly EncounterArea1[] SlotsBU = EncounterArea1.GetAreas(Get("blue_jp", "g1"u8), BU);
|
||||
|
||||
private const string tradeRBY = "traderby";
|
||||
private static readonly string[][] TradeNames = GetLanguageStrings(tradeRBY, 7);
|
||||
private static readonly string[][] TradeNames = Util.GetLanguageStrings7(tradeRBY);
|
||||
|
||||
internal static readonly EncounterStatic1[] StaticRBY =
|
||||
[
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ internal static class Encounters2
|
|||
internal static readonly EncounterArea2[] SlotsC = EncounterArea2.GetAreas(Get("crystal", "g2"u8), C);
|
||||
|
||||
private const string tradeGSC = "tradegsc";
|
||||
private static readonly string[][] TradeNames = GetLanguageStrings(tradeGSC, 8);
|
||||
private static readonly string[][] TradeNames = Util.GetLanguageStrings8(tradeGSC);
|
||||
|
||||
public static readonly EncounterStatic2[] StaticGSC =
|
||||
[
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ private static EncounterArea3[] GetRegular([ConstantExpected] string resource, [
|
|||
=> EncounterArea3.GetAreas(Get(resource, ident), version);
|
||||
|
||||
private const string tradeFRLG = "tradefrlg";
|
||||
private static readonly string[][] TradeNames = GetLanguageStrings(tradeFRLG, 7);
|
||||
private static readonly string[][] TradeNames = Util.GetLanguageStrings7(tradeFRLG);
|
||||
|
||||
public static readonly EncounterStatic3[] StaticFRLG =
|
||||
[
|
||||
|
|
@ -71,19 +71,24 @@ private static EncounterArea3[] GetRegular([ConstantExpected] string resource, [
|
|||
new(147, 18, FR) { FixedBall = Ball.Poke, Location = 94 }, // Dratini
|
||||
new(137, 26, FR) { FixedBall = Ball.Poke, Location = 94 }, // Porygon
|
||||
|
||||
new(386, 30, FR) { Location = 187, FatefulEncounter = true, Form = 1 }, // Deoxys @ Birth Island
|
||||
new(386, 30, FR ) { Location = 187, FatefulEncounter = true, Form = 1 }, // Deoxys @ Birth Island
|
||||
];
|
||||
|
||||
public static readonly EncounterStatic3[] StaticLG =
|
||||
[
|
||||
// Celadon City Game Corner
|
||||
new(063, 09, FR) { FixedBall = Ball.Poke, Location = 94 }, // Abra
|
||||
new(035, 08, FR) { FixedBall = Ball.Poke, Location = 94 }, // Clefairy
|
||||
new(123, 25, FR) { FixedBall = Ball.Poke, Location = 94 }, // Scyther
|
||||
new(147, 18, FR) { FixedBall = Ball.Poke, Location = 94 }, // Dratini
|
||||
new(137, 26, FR) { FixedBall = Ball.Poke, Location = 94 }, // Porygon
|
||||
|
||||
new(063, 07, LG) { FixedBall = Ball.Poke, Location = 94 }, // Abra
|
||||
new(035, 12, LG) { FixedBall = Ball.Poke, Location = 94 }, // Clefairy
|
||||
new(127, 18, LG) { FixedBall = Ball.Poke, Location = 94 }, // Pinsir
|
||||
new(147, 24, LG) { FixedBall = Ball.Poke, Location = 94 }, // Dratini
|
||||
new(137, 18, LG) { FixedBall = Ball.Poke, Location = 94 }, // Porygon
|
||||
|
||||
new(386, 30, LG) { Location = 187, FatefulEncounter = true, Form = 2 }, // Deoxys @ Birth Island
|
||||
new(386, 30, LG) { Location = 187, FatefulEncounter = true, Form = 2 }, // Deoxys @ Birth Island
|
||||
];
|
||||
|
||||
private static ReadOnlySpan<byte> TradeContest_Cool => [ 30, 05, 05, 05, 05, 10 ];
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user