mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-10 06:34:19 +00:00
Clean up some method signatures
rename things to be a little more consistent in naming conventions
This commit is contained in:
parent
bfef634a1a
commit
2cdb5d26db
100 changed files with 877 additions and 859 deletions
|
@ -116,10 +116,10 @@ namespace PKHeX.Core
|
|||
var colors = (PersonalColor[])Enum.GetValues(typeof(PersonalColor));
|
||||
foreach (var c in colors)
|
||||
{
|
||||
var vals = BallColors[c];
|
||||
var extra = allBalls.Except(vals).ToArray();
|
||||
var matchingColors = BallColors[c];
|
||||
var extra = allBalls.Except(matchingColors).ToArray();
|
||||
Util.Shuffle(extra);
|
||||
BallColors[c] = vals.Concat(extra).Concat(end).ToArray();
|
||||
BallColors[c] = matchingColors.Concat(extra).Concat(end).ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace PKHeX.Core
|
|||
gender = Math.Min(2, Math.Max(0, gender));
|
||||
if (pk.Format <= 2)
|
||||
{
|
||||
pk.SetATKIVGender(gender);
|
||||
pk.SetAttackIVFromGender(gender);
|
||||
}
|
||||
else if (pk.Format <= 5)
|
||||
{
|
||||
|
@ -64,7 +64,7 @@ namespace PKHeX.Core
|
|||
/// </summary>
|
||||
/// <param name="pk">Pokémon to modify.</param>
|
||||
/// <param name="gender">Desired <see cref="PKM.Gender"/>.</param>
|
||||
public static void SetATKIVGender(this PKM pk, int gender)
|
||||
public static void SetAttackIVFromGender(this PKM pk, int gender)
|
||||
{
|
||||
var rnd = Util.Rand;
|
||||
while (pk.Gender != gender)
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
/// </summary>
|
||||
/// <param name="pk">Pokémon to modify.</param>
|
||||
/// <param name="hptype">Desired Hidden Power typing.</param>
|
||||
public static void SetHiddenPower(this PKM pk, int hptype)
|
||||
public static void SetHiddenPower(this PKM pk, int hiddenPowerType)
|
||||
{
|
||||
var IVs = pk.IVs;
|
||||
HiddenPower.SetIVsForType(hptype, pk.IVs, pk.Format);
|
||||
HiddenPower.SetIVsForType(hiddenPowerType, pk.IVs, pk.Format);
|
||||
pk.IVs = IVs;
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
|||
/// Sets the <see cref="PKM.IVs"/> to match a provided <see cref="hptype"/>.
|
||||
/// </summary>
|
||||
/// <param name="pk">Pokémon to modify.</param>
|
||||
/// <param name="hptype">Desired Hidden Power typing.</param>
|
||||
public static void SetHiddenPower(this PKM pk, MoveType hptype) => pk.SetHiddenPower((int)hptype);
|
||||
/// <param name="hiddenPowerType">Desired Hidden Power typing.</param>
|
||||
public static void SetHiddenPower(this PKM pk, MoveType hiddenPowerType) => pk.SetHiddenPower((int)hiddenPowerType);
|
||||
}
|
||||
}
|
|
@ -23,7 +23,7 @@ namespace PKHeX.Core
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the individual PP Up count values depending if a Move is present in the moveslot or not.
|
||||
/// Sets the individual PP Up count values depending if a Move is present in the move slot or not.
|
||||
/// </summary>
|
||||
/// <param name="pk">Pokémon to modify.</param>
|
||||
public static void SetMaximumPPUps(this PKM pk) => pk.SetMaximumPPUps(pk.Moves);
|
||||
|
@ -50,7 +50,7 @@ namespace PKHeX.Core
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the individual PP count values for each moveslot based on the maximum possible value.
|
||||
/// Updates the individual PP count values for each move slot based on the maximum possible value.
|
||||
/// </summary>
|
||||
/// <param name="pk">Pokémon to modify.</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>
|
||||
|
@ -63,7 +63,7 @@ namespace PKHeX.Core
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the individual PP count values for each moveslot based on the maximum possible value.
|
||||
/// Updates the individual PP count values for each move slot based on the maximum possible value.
|
||||
/// </summary>
|
||||
/// <param name="pk">Pokémon to modify.</param>
|
||||
public static void SetMaximumPPCurrent(this PKM pk) => pk.SetMaximumPPCurrent(pk.Moves);
|
||||
|
|
|
@ -352,8 +352,8 @@ namespace PKHeX.Core
|
|||
/// <param name="propValue">Suggestion string which starts with <see cref="CONST_SUGGEST"/></param>
|
||||
private static ModifyResult SetSuggestedPKMProperty(string name, PKMInfo info, string propValue)
|
||||
{
|
||||
bool isAll() => propValue.EndsWith("All", true, CultureInfo.CurrentCulture);
|
||||
bool isNone() => propValue.EndsWith("None", true, CultureInfo.CurrentCulture);
|
||||
static bool IsAll(string p) => p.EndsWith("All", true, CultureInfo.CurrentCulture);
|
||||
static bool IsNone(string p) => p.EndsWith("None", true, CultureInfo.CurrentCulture);
|
||||
var pk = info.Entity;
|
||||
switch (name)
|
||||
{
|
||||
|
@ -392,15 +392,15 @@ namespace PKHeX.Core
|
|||
if (pk.Format >= 8)
|
||||
{
|
||||
pk.ClearRecordFlags();
|
||||
if (isAll())
|
||||
if (IsAll(propValue))
|
||||
pk.SetRecordFlags(); // all
|
||||
else if (!isNone())
|
||||
else if (!IsNone(propValue))
|
||||
pk.SetRecordFlags(pk.Moves); // whatever fit the current moves
|
||||
}
|
||||
pk.SetRelearnMoves(info.SuggestedRelearn);
|
||||
return ModifyResult.Modified;
|
||||
case PROP_RIBBONS:
|
||||
if (isNone())
|
||||
if (IsNone(propValue))
|
||||
RibbonApplicator.RemoveAllValidRibbons(pk);
|
||||
else // All
|
||||
RibbonApplicator.SetAllValidRibbons(pk);
|
||||
|
@ -412,11 +412,11 @@ namespace PKHeX.Core
|
|||
|
||||
int level = encounter.LevelMin;
|
||||
int location = encounter.Location;
|
||||
int minlvl = EncounterSuggestion.GetLowestLevel(pk, encounter.LevelMin);
|
||||
int minimumLevel = EncounterSuggestion.GetLowestLevel(pk, encounter.LevelMin);
|
||||
|
||||
pk.Met_Level = level;
|
||||
pk.Met_Location = location;
|
||||
pk.CurrentLevel = Math.Max(minlvl, level);
|
||||
pk.CurrentLevel = Math.Max(minimumLevel, level);
|
||||
|
||||
return ModifyResult.Modified;
|
||||
|
||||
|
@ -458,7 +458,7 @@ namespace PKHeX.Core
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="PKM"/> byte array propery to a specified value.
|
||||
/// 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>
|
||||
|
@ -467,15 +467,15 @@ namespace PKHeX.Core
|
|||
switch (cmd.PropertyName)
|
||||
{
|
||||
case nameof(PKM.Nickname_Trash):
|
||||
pk.Nickname_Trash = string2arr(cmd.PropertyValue);
|
||||
pk.Nickname_Trash = ConvertToBytes(cmd.PropertyValue);
|
||||
return ModifyResult.Modified;
|
||||
case nameof(PKM.OT_Trash):
|
||||
pk.OT_Trash = string2arr(cmd.PropertyValue);
|
||||
pk.OT_Trash = ConvertToBytes(cmd.PropertyValue);
|
||||
return ModifyResult.Modified;
|
||||
default:
|
||||
return ModifyResult.Error;
|
||||
}
|
||||
static byte[] string2arr(string str) => str.Substring(CONST_BYTES.Length).Split(',').Select(z => Convert.ToByte(z.Trim(), 16)).ToArray();
|
||||
static byte[] ConvertToBytes(string str) => str.Substring(CONST_BYTES.Length).Split(',').Select(z => Convert.ToByte(z.Trim(), 16)).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -486,12 +486,12 @@ namespace PKHeX.Core
|
|||
/// <returns>True if modified, false if no modifications done.</returns>
|
||||
private static bool SetComplexProperty(PKM pk, StringInstruction cmd)
|
||||
{
|
||||
static DateTime parseDate(string val) => DateTime.ParseExact(val, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
|
||||
static DateTime ParseDate(string val) => DateTime.ParseExact(val, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
|
||||
|
||||
if (cmd.PropertyName == nameof(PKM.MetDate))
|
||||
pk.MetDate = parseDate(cmd.PropertyValue);
|
||||
pk.MetDate = ParseDate(cmd.PropertyValue);
|
||||
else if (cmd.PropertyName == nameof(PKM.EggMetDate))
|
||||
pk.EggMetDate = parseDate(cmd.PropertyValue);
|
||||
pk.EggMetDate = ParseDate(cmd.PropertyValue);
|
||||
else if (cmd.PropertyName == nameof(PKM.EncryptionConstant) && cmd.PropertyValue == CONST_RAND)
|
||||
pk.EncryptionConstant = Util.Rand32();
|
||||
else if ((cmd.PropertyName == nameof(PKM.Ability) || cmd.PropertyName == nameof(PKM.AbilityNumber)) && cmd.PropertyValue.StartsWith("$"))
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace PKHeX.Core
|
|||
{
|
||||
private int Modified { get; set; }
|
||||
private int Iterated { get; set; }
|
||||
private int Errored { get; set; }
|
||||
private int Failed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Tries to modify the <see cref="PKM"/>.
|
||||
|
@ -22,7 +22,7 @@ namespace PKHeX.Core
|
|||
/// <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="pkm"/>.</param>
|
||||
/// <returns>Result of the attempted modification.</returns>
|
||||
public bool ProcessPKM(PKM pkm, IEnumerable<StringInstruction> filters, IEnumerable<StringInstruction> modifications)
|
||||
public bool Process(PKM pkm, IEnumerable<StringInstruction> filters, IEnumerable<StringInstruction> modifications)
|
||||
{
|
||||
if (pkm.Species <= 0)
|
||||
return false;
|
||||
|
@ -38,7 +38,7 @@ namespace PKHeX.Core
|
|||
if (result != ModifyResult.Invalid)
|
||||
Iterated++;
|
||||
if (result == ModifyResult.Error)
|
||||
Errored++;
|
||||
Failed++;
|
||||
if (result != ModifyResult.Modified)
|
||||
return false;
|
||||
|
||||
|
@ -60,8 +60,8 @@ namespace PKHeX.Core
|
|||
int len = Iterated / sets.Count;
|
||||
string maybe = sets.Count == 1 ? string.Empty : "~";
|
||||
string result = string.Format(MsgBEModifySuccess, maybe, ctr, len);
|
||||
if (Errored > 0)
|
||||
result += Environment.NewLine + maybe + string.Format(MsgBEModifyFailError, Errored);
|
||||
if (Failed > 0)
|
||||
result += Environment.NewLine + maybe + string.Format(MsgBEModifyFailError, Failed);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ namespace PKHeX.Core
|
|||
foreach (var pk in data)
|
||||
{
|
||||
foreach (var set in sets)
|
||||
editor.ProcessPKM(pk, set.Filters, set.Instructions);
|
||||
editor.Process(pk, set.Filters, set.Instructions);
|
||||
}
|
||||
|
||||
return editor;
|
||||
|
|
|
@ -49,20 +49,20 @@ namespace PKHeX.Core
|
|||
public const char SplitInstruction = '=';
|
||||
|
||||
// Extra Functionality
|
||||
private int Min, Max;
|
||||
private int RandomMinimum, RandomMaximum;
|
||||
public bool Random { get; private set; }
|
||||
public int RandomValue => Util.Rand.Next(Min, Max + 1);
|
||||
public int RandomValue => Util.Rand.Next(RandomMinimum, RandomMaximum + 1);
|
||||
|
||||
public void SetRandRange(string pv)
|
||||
{
|
||||
string str = pv.Substring(1);
|
||||
var split = str.Split(SplitRange);
|
||||
int.TryParse(split[0], out Min);
|
||||
int.TryParse(split[1], out Max);
|
||||
int.TryParse(split[0], out RandomMinimum);
|
||||
int.TryParse(split[1], out RandomMaximum);
|
||||
|
||||
if (Min == Max)
|
||||
if (RandomMinimum == RandomMaximum)
|
||||
{
|
||||
PropertyValue = Min.ToString();
|
||||
PropertyValue = RandomMinimum.ToString();
|
||||
Debug.WriteLine(PropertyName + " randomization range Min/Max same?");
|
||||
}
|
||||
else
|
||||
|
|
|
@ -80,23 +80,23 @@ namespace PKHeX.Core
|
|||
if (abil < 0)
|
||||
return;
|
||||
var abilities = pk.PersonalInfo.Abilities;
|
||||
int abilIndex = Array.IndexOf(abilities, abil);
|
||||
abilIndex = Math.Max(0, abilIndex);
|
||||
pk.SetAbilityIndex(abilIndex);
|
||||
int index = Array.IndexOf(abilities, abil);
|
||||
index = Math.Max(0, index);
|
||||
pk.SetAbilityIndex(index);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="PKM.Ability"/> value based on the provided ability index (0-2)
|
||||
/// </summary>
|
||||
/// <param name="pk">Pokémon to modify.</param>
|
||||
/// <param name="abilIndex">Desired <see cref="PKM.AbilityNumber"/> (shifted by 1) to set.</param>
|
||||
public static void SetAbilityIndex(this PKM pk, int abilIndex)
|
||||
/// <param name="index">Desired <see cref="PKM.AbilityNumber"/> (shifted by 1) to set.</param>
|
||||
public static void SetAbilityIndex(this PKM pk, int index)
|
||||
{
|
||||
if (pk is PK5 pk5 && abilIndex == 2)
|
||||
if (pk is PK5 pk5 && index == 2)
|
||||
pk5.HiddenAbility = true;
|
||||
else if (pk.Format <= 5)
|
||||
pk.PID = PKX.GetRandomPID(Util.Rand, pk.Species, pk.Gender, pk.Version, pk.Nature, pk.AltForm, (uint)(abilIndex * 0x10001));
|
||||
pk.RefreshAbility(abilIndex);
|
||||
pk.PID = PKX.GetRandomPID(Util.Rand, pk.Species, pk.Gender, pk.Version, pk.Nature, pk.AltForm, (uint)(index * 0x10001));
|
||||
pk.RefreshAbility(index);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -116,7 +116,7 @@ namespace PKHeX.Core
|
|||
int wIndex = WurmpleUtil.GetWurmpleEvoGroup(pk.Species);
|
||||
if (wIndex != -1)
|
||||
{
|
||||
pk.EncryptionConstant = WurmpleUtil.GetWurmpleEC(wIndex);
|
||||
pk.EncryptionConstant = WurmpleUtil.GetWurmpleEncryptionConstant(wIndex);
|
||||
return;
|
||||
}
|
||||
pk.EncryptionConstant = Util.Rand32();
|
||||
|
@ -252,7 +252,7 @@ namespace PKHeX.Core
|
|||
/// <param name="format">Format required for importing</param>
|
||||
public static void ApplyHeldItem(this PKM pk, int item, int format)
|
||||
{
|
||||
item = ItemConverter.GetFormatHeldItemID(item, format, pk.Format);
|
||||
item = ItemConverter.GetItemForFormat(item, format, pk.Format);
|
||||
pk.HeldItem = ((uint)item > pk.MaxItemID) ? 0 : item;
|
||||
}
|
||||
|
||||
|
@ -309,9 +309,7 @@ namespace PKHeX.Core
|
|||
if (pk.Format < 3)
|
||||
return ushort.MaxValue;
|
||||
|
||||
var EVs = pk.EVs;
|
||||
EVs[index] = 0;
|
||||
var sum = EVs.Sum();
|
||||
var sum = pk.EVTotal - pk.GetEV(index);
|
||||
int remaining = 510 - sum;
|
||||
return Math.Min(Math.Max(remaining, 0), 252);
|
||||
}
|
||||
|
@ -321,7 +319,7 @@ namespace PKHeX.Core
|
|||
/// </summary>
|
||||
/// <param name="pk">Pokémon to modify.</param>
|
||||
/// <param name="index">Index to fetch for</param>
|
||||
/// <param name="allow30">Causes the returned value to be dropped down -1 if the value is already at a maxmimum.</param>
|
||||
/// <param name="allow30">Causes the returned value to be dropped down -1 if the value is already at a maximum.</param>
|
||||
/// <returns>Highest value the value can be.</returns>
|
||||
public static int GetMaximumIV(this PKM pk, int index, bool allow30 = false)
|
||||
{
|
||||
|
@ -439,8 +437,8 @@ namespace PKHeX.Core
|
|||
if (pk.Format < 2)
|
||||
return string.Empty;
|
||||
|
||||
int locval = eggmet ? pk.Egg_Location : pk.Met_Location;
|
||||
return GameInfo.GetLocationName(eggmet, locval, pk.Format, pk.GenNumber, (GameVersion)pk.Version);
|
||||
int location = eggmet ? pk.Egg_Location : pk.Met_Location;
|
||||
return GameInfo.GetLocationName(eggmet, location, pk.Format, pk.GenNumber, (GameVersion)pk.Version);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,27 +43,27 @@ namespace PKHeX.Core
|
|||
/// <returns>Hidden Power Type of the <see cref="IVs"/></returns>
|
||||
public static int GetTypeGB(IReadOnlyList<int> IVs)
|
||||
{
|
||||
var IV_ATK = IVs[1];
|
||||
var IV_DEF = IVs[2];
|
||||
return ((IV_ATK & 3) << 2) | (IV_DEF & 3);
|
||||
var atk = IVs[1];
|
||||
var def = IVs[2];
|
||||
return ((atk & 3) << 2) | (def & 3);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modifies the provided <see cref="IVs"/> to have the requested <see cref="hpVal"/>.
|
||||
/// Modifies the provided <see cref="IVs"/> to have the requested <see cref="hiddenPowerType"/>.
|
||||
/// </summary>
|
||||
/// <param name="hpVal">Hidden Power Type</param>
|
||||
/// <param name="hiddenPowerType">Hidden Power Type</param>
|
||||
/// <param name="IVs">Current IVs (6 total)</param>
|
||||
/// <param name="format">Generation format</param>
|
||||
/// <returns>True if the Hidden Power of the <see cref="IVs"/> is obtained, with or without modifications</returns>
|
||||
public static bool SetIVsForType(int hpVal, int[] IVs, int format)
|
||||
public static bool SetIVsForType(int hiddenPowerType, int[] IVs, int format)
|
||||
{
|
||||
if (format <= 2)
|
||||
{
|
||||
IVs[1] = (IVs[1] & ~3) | (hpVal >> 2);
|
||||
IVs[2] = (IVs[2] & ~3) | (hpVal & 3);
|
||||
IVs[1] = (IVs[1] & ~3) | (hiddenPowerType >> 2);
|
||||
IVs[2] = (IVs[2] & ~3) | (hiddenPowerType & 3);
|
||||
return true;
|
||||
}
|
||||
return SetIVsForType(hpVal, IVs);
|
||||
return SetIVsForType(hiddenPowerType, IVs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
int Priority { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Entrypoint for the parent to initialize the plugin with provided arguments.
|
||||
/// Entry point for the parent to initialize the plugin with provided arguments.
|
||||
/// </summary>
|
||||
/// <param name="args">Arguments containing objects useful for initializing the plugin.</param>
|
||||
void Initialize(params object[] args);
|
||||
|
|
|
@ -10,18 +10,18 @@ namespace PKHeX.Core
|
|||
/// </summary>
|
||||
public static class EditPKMUtil
|
||||
{
|
||||
public static List<string> GetSuggestionMessage(PKM pkm, int level, int location, int minlvl)
|
||||
public static List<string> GetSuggestionMessage(PKM pkm, int level, int location, int minimumLevel)
|
||||
{
|
||||
var suggestion = new List<string> { MsgPKMSuggestionStart };
|
||||
if (pkm.Format >= 3)
|
||||
{
|
||||
var met_list = GameInfo.GetLocationList((GameVersion)pkm.Version, pkm.Format, egg: false);
|
||||
var locstr = met_list.First(loc => loc.Value == location).Text;
|
||||
suggestion.Add($"{MsgPKMSuggestionMetLocation} {locstr}");
|
||||
var metList = GameInfo.GetLocationList((GameVersion)pkm.Version, pkm.Format, egg: false);
|
||||
var locationName = metList.First(loc => loc.Value == location).Text;
|
||||
suggestion.Add($"{MsgPKMSuggestionMetLocation} {locationName}");
|
||||
suggestion.Add($"{MsgPKMSuggestionMetLevel} {level}");
|
||||
}
|
||||
if (pkm.CurrentLevel < minlvl)
|
||||
suggestion.Add($"{MsgPKMSuggestionLevel} {minlvl}");
|
||||
if (pkm.CurrentLevel < minimumLevel)
|
||||
suggestion.Add($"{MsgPKMSuggestionLevel} {minimumLevel}");
|
||||
return suggestion;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace PKHeX.Core
|
|||
|
||||
public void ReloadMoves(IReadOnlyList<int> moves)
|
||||
{
|
||||
// check prior movepool to not needlessly refresh the dataset
|
||||
// check prior move-pool to not needlessly refresh the data set
|
||||
if (AllowedMoves.Count == moves.Count && AllowedMoves.SetEquals(moves))
|
||||
return;
|
||||
|
||||
|
@ -28,7 +28,7 @@ namespace PKHeX.Core
|
|||
Array.Sort(MoveDataAllowed, Compare);
|
||||
// MoveDataAllowed = MoveDataAllowed.OrderByDescending(m => AllowedMoves.Contains(m.Value)).ToArray();
|
||||
|
||||
// defer repop until dropdown is opened; handled by dropdown event
|
||||
// defer re-population until dropdown is opened; handled by dropdown event
|
||||
for (int i = 0; i < IsMoveBoxOrdered.Count; i++)
|
||||
IsMoveBoxOrdered[i] = false;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace PKHeX.Core
|
|||
public abstract string GetPrompt(bool all);
|
||||
public abstract string GetFail(bool all);
|
||||
public abstract string GetSuccess(bool all);
|
||||
public abstract int Execute(SaveFile SAV, BoxManipParam param);
|
||||
public abstract int Execute(SaveFile sav, BoxManipParam param);
|
||||
|
||||
public static readonly IReadOnlyList<BoxManipBase> SortCommon = new List<BoxManipBase>
|
||||
{
|
||||
|
|
|
@ -12,10 +12,10 @@ namespace PKHeX.Core
|
|||
public override string GetFail(bool all) => all ? MessageStrings.MsgSaveBoxClearAllFailBattle : MessageStrings.MsgSaveBoxClearCurrentFailBattle;
|
||||
public override string GetSuccess(bool all) => all ? MessageStrings.MsgSaveBoxClearAllSuccess : MessageStrings.MsgSaveBoxClearCurrentSuccess;
|
||||
|
||||
public override int Execute(SaveFile SAV, BoxManipParam param)
|
||||
public override int Execute(SaveFile sav, BoxManipParam param)
|
||||
{
|
||||
bool Method(PKM p) => param.Reverse ^ Criteria(p);
|
||||
return SAV.ClearBoxes(param.Start, param.Stop, Method);
|
||||
return sav.ClearBoxes(param.Start, param.Stop, Method);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,10 +12,10 @@ namespace PKHeX.Core
|
|||
public override string GetFail(bool all) => all ? MessageStrings.MsgSaveBoxClearAllFailBattle : MessageStrings.MsgSaveBoxClearCurrentFailBattle;
|
||||
public override string GetSuccess(bool all) => all ? MessageStrings.MsgSaveBoxClearAllSuccess : MessageStrings.MsgSaveBoxClearCurrentSuccess;
|
||||
|
||||
public override int Execute(SaveFile SAV, BoxManipParam param)
|
||||
public override int Execute(SaveFile sav, BoxManipParam param)
|
||||
{
|
||||
bool Method(PKM p) => param.Reverse ^ Criteria(p, SAV);
|
||||
return SAV.ClearBoxes(param.Start, param.Stop, Method);
|
||||
bool Method(PKM p) => param.Reverse ^ Criteria(p, sav);
|
||||
return sav.ClearBoxes(param.Start, param.Stop, Method);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,11 +25,11 @@ namespace PKHeX.Core
|
|||
public override string GetFail(bool all) => all ? MessageStrings.MsgSaveBoxClearAllFailBattle : MessageStrings.MsgSaveBoxClearCurrentFailBattle;
|
||||
public override string GetSuccess(bool all) => all ? MessageStrings.MsgSaveBoxClearAllSuccess : MessageStrings.MsgSaveBoxClearCurrentSuccess;
|
||||
|
||||
public override int Execute(SaveFile SAV, BoxManipParam param)
|
||||
public override int Execute(SaveFile sav, BoxManipParam param)
|
||||
{
|
||||
HashSet.Clear();
|
||||
bool Method(PKM p) => param.Reverse ^ Criteria(p);
|
||||
return SAV.ClearBoxes(param.Start, param.Stop, Method);
|
||||
return sav.ClearBoxes(param.Start, param.Stop, Method);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,6 +12,6 @@ namespace PKHeX.Core
|
|||
public override string GetFail(bool all) => string.Empty;
|
||||
public override string GetSuccess(bool all) => string.Empty;
|
||||
|
||||
public override int Execute(SaveFile SAV, BoxManipParam param) => SAV.ModifyBoxes(Action, param.Start, param.Stop);
|
||||
public override int Execute(SaveFile sav, BoxManipParam param) => sav.ModifyBoxes(Action, param.Start, param.Stop);
|
||||
}
|
||||
}
|
|
@ -12,6 +12,6 @@ namespace PKHeX.Core
|
|||
public override string GetFail(bool all) => string.Empty;
|
||||
public override string GetSuccess(bool all) => string.Empty;
|
||||
|
||||
public override int Execute(SaveFile SAV, BoxManipParam param) => SAV.ModifyBoxes(pk => Action(pk, SAV), param.Start, param.Stop);
|
||||
public override int Execute(SaveFile sav, BoxManipParam param) => sav.ModifyBoxes(pk => Action(pk, sav), param.Start, param.Stop);
|
||||
}
|
||||
}
|
|
@ -13,10 +13,10 @@ namespace PKHeX.Core
|
|||
public override string GetFail(bool all) => all ? MessageStrings.MsgSaveBoxSortAllFailBattle: MessageStrings.MsgSaveBoxSortCurrentFailBattle;
|
||||
public override string GetSuccess(bool all) => all ? MessageStrings.MsgSaveBoxSortAllSuccess : MessageStrings.MsgSaveBoxSortCurrentSuccess;
|
||||
|
||||
public override int Execute(SaveFile SAV, BoxManipParam param)
|
||||
public override int Execute(SaveFile sav, BoxManipParam param)
|
||||
{
|
||||
IEnumerable<PKM> Method(IEnumerable<PKM> p) => Sorter(p);
|
||||
return SAV.SortBoxes(param.Start, param.Stop, Method, param.Reverse);
|
||||
return sav.SortBoxes(param.Start, param.Stop, Method, param.Reverse);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,10 +13,10 @@ namespace PKHeX.Core
|
|||
public override string GetFail(bool all) => all ? MessageStrings.MsgSaveBoxSortAllFailBattle : MessageStrings.MsgSaveBoxSortCurrentFailBattle;
|
||||
public override string GetSuccess(bool all) => all ? MessageStrings.MsgSaveBoxSortAllSuccess : MessageStrings.MsgSaveBoxSortCurrentSuccess;
|
||||
|
||||
public override int Execute(SaveFile SAV, BoxManipParam param)
|
||||
public override int Execute(SaveFile sav, BoxManipParam param)
|
||||
{
|
||||
IEnumerable<PKM> Method(IEnumerable<PKM> p) => Sorter(p, SAV);
|
||||
return SAV.SortBoxes(param.Start, param.Stop, Method, param.Reverse);
|
||||
IEnumerable<PKM> Method(IEnumerable<PKM> p) => Sorter(p, sav);
|
||||
return sav.SortBoxes(param.Start, param.Stop, Method, param.Reverse);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,23 +17,23 @@ namespace PKHeX.Core
|
|||
{
|
||||
Block = block;
|
||||
// load lines
|
||||
var worklines = work.Where(z => !string.IsNullOrWhiteSpace(z) && z.Length > 5);
|
||||
Work = EventWorkUtil.GetVars(worklines, (index, t, data) => new EventWork<T>(index, t, data));
|
||||
var flaglines = flag.Where(z => !string.IsNullOrWhiteSpace(z) && z.Length > 5);
|
||||
Flag = EventWorkUtil.GetVars(flaglines, (index, t, data) => new EventFlag(index, t, data));
|
||||
var workLines = work.Where(z => !string.IsNullOrWhiteSpace(z) && z.Length > 5);
|
||||
Work = EventWorkUtil.GetVars(workLines, (index, t, data) => new EventWork<T>(index, t, data));
|
||||
var flagLines = flag.Where(z => !string.IsNullOrWhiteSpace(z) && z.Length > 5);
|
||||
Flag = EventWorkUtil.GetVars(flagLines, (index, t, data) => new EventFlag(index, t, data));
|
||||
|
||||
// initialize lines
|
||||
foreach (var g in Work)
|
||||
foreach (var group in Work)
|
||||
{
|
||||
foreach (var item in g.Vars)
|
||||
foreach (var item in group.Vars)
|
||||
{
|
||||
item.RawIndex = block.GetWorkRawIndex(item.Type, item.RelativeIndex);
|
||||
((EventWork<T>)item).Value = block.GetWork(item.RawIndex);
|
||||
}
|
||||
}
|
||||
foreach (var g in Flag)
|
||||
foreach (var group in Flag)
|
||||
{
|
||||
foreach (var item in g.Vars)
|
||||
foreach (var item in group.Vars)
|
||||
{
|
||||
item.RawIndex = block.GetFlagRawIndex(item.Type, item.RelativeIndex);
|
||||
((EventFlag)item).Flag = block.GetFlag(item.RawIndex);
|
||||
|
|
|
@ -11,6 +11,6 @@ namespace PKHeX.Core
|
|||
string GetFail(bool all);
|
||||
string GetSuccess(bool all);
|
||||
|
||||
int Execute(SaveFile SAV, BoxManipParam param);
|
||||
int Execute(SaveFile sav, BoxManipParam param);
|
||||
}
|
||||
}
|
|
@ -6,16 +6,16 @@ namespace PKHeX.Core
|
|||
{
|
||||
public static IReadOnlyList<PKM> GetAllPKM(this SaveFile sav)
|
||||
{
|
||||
var pkms = new List<PKM>();
|
||||
var result = new List<PKM>();
|
||||
if (sav.HasBox)
|
||||
pkms.AddRange(sav.BoxData);
|
||||
result.AddRange(sav.BoxData);
|
||||
if (sav.HasParty)
|
||||
pkms.AddRange(sav.PartyData);
|
||||
result.AddRange(sav.PartyData);
|
||||
|
||||
var extra = sav.GetExtraPKM();
|
||||
pkms.AddRange(extra);
|
||||
pkms.RemoveAll(z => z.Species == 0);
|
||||
return pkms;
|
||||
result.AddRange(extra);
|
||||
result.RemoveAll(z => z.Species == 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static PKM[] GetExtraPKM(this SaveFile sav) => sav.GetExtraPKM(sav.GetExtraSlots());
|
||||
|
|
|
@ -8,8 +8,8 @@ namespace PKHeX.Core
|
|||
public interface ISlotInfo : IEquatable<ISlotInfo>
|
||||
{
|
||||
int Slot { get; }
|
||||
bool CanWriteTo(SaveFile SAV);
|
||||
WriteBlockedMessage CanWriteTo(SaveFile SAV, PKM pkm);
|
||||
bool CanWriteTo(SaveFile sav);
|
||||
WriteBlockedMessage CanWriteTo(SaveFile sav, PKM pkm);
|
||||
bool WriteTo(SaveFile sav, PKM pkm, PKMImportSetting setting = PKMImportSetting.UseDefault);
|
||||
PKM Read(SaveFile sav);
|
||||
}
|
||||
|
|
|
@ -78,10 +78,10 @@ namespace PKHeX.Core
|
|||
|
||||
private class SingleSlotReversion : SlotReversion
|
||||
{
|
||||
private readonly PKM pkm;
|
||||
public SingleSlotReversion(ISlotInfo info, SaveFile sav) : base(info) => pkm = info.Read(sav);
|
||||
private readonly PKM Entity;
|
||||
public SingleSlotReversion(ISlotInfo info, SaveFile sav) : base(info) => Entity = info.Read(sav);
|
||||
|
||||
public override void Revert(SaveFile sav) => Info.WriteTo(sav, pkm, PKMImportSetting.Skip);
|
||||
public override void Revert(SaveFile sav) => Info.WriteTo(sav, Entity, PKMImportSetting.Skip);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@ namespace PKHeX.Core
|
|||
|
||||
public ISlotInfo? Previous { get; private set; }
|
||||
public SlotTouchType PreviousType { get; private set; } = SlotTouchType.None;
|
||||
public PKM? PreviousPKM { get; private set; }
|
||||
public PKM? PreviousEntity { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Notifies all <see cref="Subscribers"/> with the latest slot change details.
|
||||
|
@ -28,7 +28,7 @@ namespace PKHeX.Core
|
|||
ResetView(sub, slot, type, pkm);
|
||||
Previous = slot;
|
||||
PreviousType = type;
|
||||
PreviousPKM = pkm;
|
||||
PreviousEntity = pkm;
|
||||
}
|
||||
|
||||
private void ResetView(ISlotViewer<T> sub, ISlotInfo slot, SlotTouchType type, PKM pkm)
|
||||
|
@ -42,9 +42,9 @@ namespace PKHeX.Core
|
|||
|
||||
public void ResetView(ISlotViewer<T> sub)
|
||||
{
|
||||
if (Previous == null || PreviousPKM == null)
|
||||
if (Previous == null || PreviousEntity == null)
|
||||
return;
|
||||
ResetView(sub, Previous, PreviousType, PreviousPKM);
|
||||
ResetView(sub, Previous, PreviousType, PreviousEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -383,8 +383,8 @@ namespace PKHeX.Core
|
|||
Form = string.Empty;
|
||||
return;
|
||||
}
|
||||
var Forms = FormConverter.GetFormList(Species, Strings.Types, Strings.forms, genderForms, Format);
|
||||
Form = FormIndex >= Forms.Length ? string.Empty : Forms[index];
|
||||
var forms = FormConverter.GetFormList(Species, Strings.Types, Strings.forms, genderForms, Format);
|
||||
Form = FormIndex >= forms.Length ? string.Empty : forms[index];
|
||||
}
|
||||
|
||||
private void ParseFirstLine(string first)
|
||||
|
@ -392,9 +392,9 @@ namespace PKHeX.Core
|
|||
if (first.Contains(" @ "))
|
||||
{
|
||||
string[] pieces = first.Split(ItemSplit, StringSplitOptions.None);
|
||||
string itemstr = pieces[pieces.Length - 1].Trim();
|
||||
string itemName = pieces[pieces.Length - 1].Trim();
|
||||
|
||||
ParseItemStr(itemstr);
|
||||
ParseItemName(itemName);
|
||||
ParseFirstLineNoItem(pieces[0]);
|
||||
}
|
||||
else
|
||||
|
@ -403,20 +403,20 @@ namespace PKHeX.Core
|
|||
}
|
||||
}
|
||||
|
||||
private void ParseItemStr(string itemstr)
|
||||
private void ParseItemName(string itemName)
|
||||
{
|
||||
if (tryGetItem(Format))
|
||||
if (TrySetItem(Format))
|
||||
return;
|
||||
if (tryGetItem(3))
|
||||
if (TrySetItem(3))
|
||||
return;
|
||||
if (tryGetItem(2))
|
||||
if (TrySetItem(2))
|
||||
return;
|
||||
InvalidLines.Add($"Unknown Item: {itemstr}");
|
||||
InvalidLines.Add($"Unknown Item: {itemName}");
|
||||
|
||||
bool tryGetItem(int format)
|
||||
bool TrySetItem(int format)
|
||||
{
|
||||
var items = (string[])Strings.GetItemStrings(format); // ireadonlylist->string[] must be possible for the provided strings
|
||||
int item = StringUtil.FindIndexIgnoreCase(items, itemstr);
|
||||
var items = (string[])Strings.GetItemStrings(format); // IReadOnlyList<string>->string[] must be possible for the provided strings
|
||||
int item = StringUtil.FindIndexIgnoreCase(items, itemName);
|
||||
if (item < 0)
|
||||
return false;
|
||||
HeldItem = item;
|
||||
|
@ -458,7 +458,7 @@ namespace PKHeX.Core
|
|||
if ((Species = StringUtil.FindIndexIgnoreCase(Strings.specieslist, spec)) >= 0) // success, nothing else!
|
||||
return true;
|
||||
|
||||
// Forme string present.
|
||||
// Form string present.
|
||||
int end = spec.LastIndexOf('-');
|
||||
if (end < 0)
|
||||
return false;
|
||||
|
@ -576,8 +576,8 @@ namespace PKHeX.Core
|
|||
{
|
||||
int pos = i * 2;
|
||||
int index = StringUtil.FindIndexIgnoreCase(StatNames, list[pos + 1]);
|
||||
if (index >= 0 && byte.TryParse(list[pos + 0], out var IV))
|
||||
IVs[index] = IV;
|
||||
if (index >= 0 && byte.TryParse(list[pos + 0], out var iv))
|
||||
IVs[index] = iv;
|
||||
else
|
||||
InvalidLines.Add($"Unknown IV stat: {list[pos]}");
|
||||
}
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
/// <summary>
|
||||
/// Gets the Wurmple Evolution Value for a given <see cref="PKM.EncryptionConstant"/>
|
||||
/// </summary>
|
||||
/// <param name="EC">Encryption Constant</param>
|
||||
/// <param name="encryptionConstant">Encryption Constant</param>
|
||||
/// <returns>Wurmple Evolution Value</returns>
|
||||
public static uint GetWurmpleEvoVal(uint EC)
|
||||
public static uint GetWurmpleEvoVal(uint encryptionConstant)
|
||||
{
|
||||
var evoVal = EC >> 16;
|
||||
var evoVal = encryptionConstant >> 16;
|
||||
return evoVal % 10 / 5;
|
||||
}
|
||||
|
||||
|
@ -32,12 +32,12 @@
|
|||
/// <param name="evoVal">Wurmple Evolution Value</param>
|
||||
/// <remarks>0 = Silcoon, 1 = Cascoon</remarks>
|
||||
/// <returns>Encryption Constant</returns>
|
||||
public static uint GetWurmpleEC(int evoVal)
|
||||
public static uint GetWurmpleEncryptionConstant(int evoVal)
|
||||
{
|
||||
uint EC;
|
||||
do EC = Util.Rand32();
|
||||
while (evoVal != GetWurmpleEvoVal(EC));
|
||||
return EC;
|
||||
uint result;
|
||||
do result = Util.Rand32();
|
||||
while (evoVal != GetWurmpleEvoVal(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -78,24 +78,24 @@ namespace PKHeX.Core
|
|||
|
||||
public IReadOnlyList<ComboItem> GetAbilityList(PKM pkm)
|
||||
{
|
||||
var abils = pkm.PersonalInfo.Abilities;
|
||||
var abilities = pkm.PersonalInfo.Abilities;
|
||||
int format = pkm.Format;
|
||||
return GetAbilityList(abils, format);
|
||||
return GetAbilityList(abilities, format);
|
||||
}
|
||||
|
||||
public IReadOnlyList<ComboItem> GetAbilityList(int[] abils, int format)
|
||||
public IReadOnlyList<ComboItem> GetAbilityList(IReadOnlyList<int> abilities, int format)
|
||||
{
|
||||
var count = format == 3 && (abils[1] == 0 || abils[1] == abils[0]) ? 1 : abils.Length;
|
||||
var count = format == 3 && (abilities[1] == 0 || abilities[1] == abilities[0]) ? 1 : abilities.Count;
|
||||
var list = new ComboItem[count];
|
||||
for (int i = 0; i < list.Length; i++)
|
||||
{
|
||||
var ability = abils[i];
|
||||
list[i] = new ComboItem(Source.Source.Ability[ability] + abilIdentifier[i], ability);
|
||||
var ability = abilities[i];
|
||||
list[i] = new ComboItem(Source.Source.Ability[ability] + AbilityIndexSuffixes[i], ability);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private static readonly string[] abilIdentifier = { " (1)", " (2)", " (H)" };
|
||||
private static readonly string[] AbilityIndexSuffixes = { " (1)", " (2)", " (H)" };
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,16 +85,16 @@ namespace PKHeX.Core
|
|||
|
||||
private List<ComboItem> CreateGen2(GameStrings s)
|
||||
{
|
||||
var met_list = Util.GetCBList(s.metGSC_00000, Enumerable.Range(0, 0x5F).ToArray());
|
||||
Util.AddCBWithOffset(met_list, s.metGSC_00000, 00000, 0x7E, 0x7F);
|
||||
return met_list;
|
||||
var locations = Util.GetCBList(s.metGSC_00000, Enumerable.Range(0, 0x5F).ToArray());
|
||||
Util.AddCBWithOffset(locations, s.metGSC_00000, 00000, 0x7E, 0x7F);
|
||||
return locations;
|
||||
}
|
||||
|
||||
private List<ComboItem> CreateGen3(GameStrings s)
|
||||
{
|
||||
var met_list = Util.GetCBList(s.metRSEFRLG_00000, Enumerable.Range(0, 213).ToArray());
|
||||
Util.AddCBWithOffset(met_list, s.metRSEFRLG_00000, 00000, 253, 254, 255);
|
||||
return met_list;
|
||||
var locations = Util.GetCBList(s.metRSEFRLG_00000, Enumerable.Range(0, 213).ToArray());
|
||||
Util.AddCBWithOffset(locations, s.metRSEFRLG_00000, 00000, 253, 254, 255);
|
||||
return locations;
|
||||
}
|
||||
|
||||
private static List<ComboItem> CreateGen3CXD(GameStrings s)
|
||||
|
@ -104,74 +104,75 @@ namespace PKHeX.Core
|
|||
|
||||
private static List<ComboItem> CreateGen4(GameStrings s)
|
||||
{
|
||||
var met_list = Util.GetCBList(s.metHGSS_00000, 0);
|
||||
Util.AddCBWithOffset(met_list, s.metHGSS_02000, 2000, Locations.Daycare4);
|
||||
Util.AddCBWithOffset(met_list, s.metHGSS_02000, 2000, Locations.LinkTrade4);
|
||||
Util.AddCBWithOffset(met_list, s.metHGSS_03000, 3000, Locations.Ranger4);
|
||||
Util.AddCBWithOffset(met_list, s.metHGSS_00000, 0000, Legal.Met_HGSS_0);
|
||||
Util.AddCBWithOffset(met_list, s.metHGSS_02000, 2000, Legal.Met_HGSS_2);
|
||||
Util.AddCBWithOffset(met_list, s.metHGSS_03000, 3000, Legal.Met_HGSS_3);
|
||||
return met_list;
|
||||
var locations = Util.GetCBList(s.metHGSS_00000, 0);
|
||||
Util.AddCBWithOffset(locations, s.metHGSS_02000, 2000, Locations.Daycare4);
|
||||
Util.AddCBWithOffset(locations, s.metHGSS_02000, 2000, Locations.LinkTrade4);
|
||||
Util.AddCBWithOffset(locations, s.metHGSS_03000, 3000, Locations.Ranger4);
|
||||
Util.AddCBWithOffset(locations, s.metHGSS_00000, 0000, Legal.Met_HGSS_0);
|
||||
Util.AddCBWithOffset(locations, s.metHGSS_02000, 2000, Legal.Met_HGSS_2);
|
||||
Util.AddCBWithOffset(locations, s.metHGSS_03000, 3000, Legal.Met_HGSS_3);
|
||||
return locations
|
||||
;
|
||||
}
|
||||
|
||||
private static List<ComboItem> CreateGen5(GameStrings s)
|
||||
{
|
||||
var met_list = Util.GetCBList(s.metBW2_00000, 0);
|
||||
Util.AddCBWithOffset(met_list, s.metBW2_60000, 60001, Locations.Daycare5);
|
||||
Util.AddCBWithOffset(met_list, s.metBW2_30000, 30001, Locations.LinkTrade5);
|
||||
Util.AddCBWithOffset(met_list, s.metBW2_00000, 00000, Legal.Met_BW2_0);
|
||||
Util.AddCBWithOffset(met_list, s.metBW2_30000, 30001, Legal.Met_BW2_3);
|
||||
Util.AddCBWithOffset(met_list, s.metBW2_40000, 40001, Legal.Met_BW2_4);
|
||||
Util.AddCBWithOffset(met_list, s.metBW2_60000, 60001, Legal.Met_BW2_6);
|
||||
return met_list;
|
||||
var locations = Util.GetCBList(s.metBW2_00000, 0);
|
||||
Util.AddCBWithOffset(locations, s.metBW2_60000, 60001, Locations.Daycare5);
|
||||
Util.AddCBWithOffset(locations, s.metBW2_30000, 30001, Locations.LinkTrade5);
|
||||
Util.AddCBWithOffset(locations, s.metBW2_00000, 00000, Legal.Met_BW2_0);
|
||||
Util.AddCBWithOffset(locations, s.metBW2_30000, 30001, Legal.Met_BW2_3);
|
||||
Util.AddCBWithOffset(locations, s.metBW2_40000, 40001, Legal.Met_BW2_4);
|
||||
Util.AddCBWithOffset(locations, s.metBW2_60000, 60001, Legal.Met_BW2_6);
|
||||
return locations;
|
||||
}
|
||||
|
||||
private static List<ComboItem> CreateGen6(GameStrings s)
|
||||
{
|
||||
var met_list = Util.GetCBList(s.metXY_00000, 0);
|
||||
Util.AddCBWithOffset(met_list, s.metXY_60000, 60001, Locations.Daycare5);
|
||||
Util.AddCBWithOffset(met_list, s.metXY_30000, 30001, Locations.LinkTrade6);
|
||||
Util.AddCBWithOffset(met_list, s.metXY_00000, 00000, Legal.Met_XY_0);
|
||||
Util.AddCBWithOffset(met_list, s.metXY_30000, 30001, Legal.Met_XY_3);
|
||||
Util.AddCBWithOffset(met_list, s.metXY_40000, 40001, Legal.Met_XY_4);
|
||||
Util.AddCBWithOffset(met_list, s.metXY_60000, 60001, Legal.Met_XY_6);
|
||||
return met_list;
|
||||
var locations = Util.GetCBList(s.metXY_00000, 0);
|
||||
Util.AddCBWithOffset(locations, s.metXY_60000, 60001, Locations.Daycare5);
|
||||
Util.AddCBWithOffset(locations, s.metXY_30000, 30001, Locations.LinkTrade6);
|
||||
Util.AddCBWithOffset(locations, s.metXY_00000, 00000, Legal.Met_XY_0);
|
||||
Util.AddCBWithOffset(locations, s.metXY_30000, 30001, Legal.Met_XY_3);
|
||||
Util.AddCBWithOffset(locations, s.metXY_40000, 40001, Legal.Met_XY_4);
|
||||
Util.AddCBWithOffset(locations, s.metXY_60000, 60001, Legal.Met_XY_6);
|
||||
return locations;
|
||||
}
|
||||
|
||||
private static List<ComboItem> CreateGen7(GameStrings s)
|
||||
{
|
||||
var met_list = Util.GetCBList(s.metSM_00000, 0);
|
||||
Util.AddCBWithOffset(met_list, s.metSM_60000, 60001, Locations.Daycare5);
|
||||
Util.AddCBWithOffset(met_list, s.metSM_30000, 30001, Locations.LinkTrade6);
|
||||
Util.AddCBWithOffset(met_list, s.metSM_00000, 00000, Legal.Met_SM_0);
|
||||
Util.AddCBWithOffset(met_list, s.metSM_30000, 30001, Legal.Met_SM_3);
|
||||
Util.AddCBWithOffset(met_list, s.metSM_40000, 40001, Legal.Met_SM_4);
|
||||
Util.AddCBWithOffset(met_list, s.metSM_60000, 60001, Legal.Met_SM_6);
|
||||
return met_list;
|
||||
var locations = Util.GetCBList(s.metSM_00000, 0);
|
||||
Util.AddCBWithOffset(locations, s.metSM_60000, 60001, Locations.Daycare5);
|
||||
Util.AddCBWithOffset(locations, s.metSM_30000, 30001, Locations.LinkTrade6);
|
||||
Util.AddCBWithOffset(locations, s.metSM_00000, 00000, Legal.Met_SM_0);
|
||||
Util.AddCBWithOffset(locations, s.metSM_30000, 30001, Legal.Met_SM_3);
|
||||
Util.AddCBWithOffset(locations, s.metSM_40000, 40001, Legal.Met_SM_4);
|
||||
Util.AddCBWithOffset(locations, s.metSM_60000, 60001, Legal.Met_SM_6);
|
||||
return locations;
|
||||
}
|
||||
|
||||
private static List<ComboItem> CreateGen7GG(GameStrings s)
|
||||
{
|
||||
var met_list = Util.GetCBList(s.metGG_00000, 0);
|
||||
Util.AddCBWithOffset(met_list, s.metGG_60000, 60001, 60002);
|
||||
Util.AddCBWithOffset(met_list, s.metGG_30000, 30001, Locations.LinkTrade6);
|
||||
Util.AddCBWithOffset(met_list, s.metGG_00000, 00000, Legal.Met_GG_0);
|
||||
Util.AddCBWithOffset(met_list, s.metGG_30000, 30001, Legal.Met_GG_3);
|
||||
Util.AddCBWithOffset(met_list, s.metGG_40000, 40001, Legal.Met_GG_4);
|
||||
Util.AddCBWithOffset(met_list, s.metGG_60000, 60001, Legal.Met_GG_6);
|
||||
return met_list;
|
||||
var locations = Util.GetCBList(s.metGG_00000, 0);
|
||||
Util.AddCBWithOffset(locations, s.metGG_60000, 60001, 60002);
|
||||
Util.AddCBWithOffset(locations, s.metGG_30000, 30001, Locations.LinkTrade6);
|
||||
Util.AddCBWithOffset(locations, s.metGG_00000, 00000, Legal.Met_GG_0);
|
||||
Util.AddCBWithOffset(locations, s.metGG_30000, 30001, Legal.Met_GG_3);
|
||||
Util.AddCBWithOffset(locations, s.metGG_40000, 40001, Legal.Met_GG_4);
|
||||
Util.AddCBWithOffset(locations, s.metGG_60000, 60001, Legal.Met_GG_6);
|
||||
return locations;
|
||||
}
|
||||
|
||||
private static List<ComboItem> CreateGen8(GameStrings s)
|
||||
{
|
||||
var met_list = Util.GetCBList(s.metSWSH_00000, 0);
|
||||
Util.AddCBWithOffset(met_list, s.metSWSH_60000, 60001, 60002);
|
||||
Util.AddCBWithOffset(met_list, s.metSWSH_30000, 30001, Locations.LinkTrade6);
|
||||
Util.AddCBWithOffset(met_list, s.metSWSH_00000, 00000, Legal.Met_SWSH_0);
|
||||
Util.AddCBWithOffset(met_list, s.metSWSH_30000, 30001, Legal.Met_SWSH_3);
|
||||
Util.AddCBWithOffset(met_list, s.metSWSH_40000, 40001, Legal.Met_SWSH_4);
|
||||
Util.AddCBWithOffset(met_list, s.metSWSH_60000, 60001, Legal.Met_SWSH_6);
|
||||
return met_list;
|
||||
var locations = Util.GetCBList(s.metSWSH_00000, 0);
|
||||
Util.AddCBWithOffset(locations, s.metSWSH_60000, 60001, 60002);
|
||||
Util.AddCBWithOffset(locations, s.metSWSH_30000, 30001, Locations.LinkTrade6);
|
||||
Util.AddCBWithOffset(locations, s.metSWSH_00000, 00000, Legal.Met_SWSH_0);
|
||||
Util.AddCBWithOffset(locations, s.metSWSH_30000, 30001, Legal.Met_SWSH_3);
|
||||
Util.AddCBWithOffset(locations, s.metSWSH_40000, 40001, Legal.Met_SWSH_4);
|
||||
Util.AddCBWithOffset(locations, s.metSWSH_60000, 60001, Legal.Met_SWSH_6);
|
||||
return locations;
|
||||
}
|
||||
|
||||
public List<ComboItem> GetItemDataSource(GameVersion game, int generation, IReadOnlyList<ushort> allowed, bool HaX = false)
|
||||
|
@ -184,7 +185,7 @@ namespace PKHeX.Core
|
|||
/// Fetches a Met Location list for a <see cref="version"/> that has been transferred away from and overwritten.
|
||||
/// </summary>
|
||||
/// <param name="version">Origin version</param>
|
||||
/// <param name="currentGen">Current savefile generation</param>
|
||||
/// <param name="currentGen">Current save file generation</param>
|
||||
/// <param name="egg">True if an egg location list, false if a regular met location list</param>
|
||||
/// <returns>Met location list</returns>
|
||||
public IReadOnlyList<ComboItem> GetLocationList(GameVersion version, int currentGen, bool egg = false)
|
||||
|
@ -274,7 +275,7 @@ namespace PKHeX.Core
|
|||
|
||||
case GameVersion.SW:
|
||||
case GameVersion.SH:
|
||||
return MetGen8.Take(3).Concat(MetGen8.Skip(3).OrderByDescending(loc => loc.Value < 400)).ToList(); // todo
|
||||
return MetGen8.Take(3).Concat(MetGen8.Skip(3).OrderByDescending(loc => loc.Value < 400)).ToList();
|
||||
}
|
||||
|
||||
return GetLocationListModified(version, currentGen);
|
||||
|
@ -284,7 +285,7 @@ namespace PKHeX.Core
|
|||
/// Fetches a Met Location list for a <see cref="version"/> that has been transferred away from and overwritten.
|
||||
/// </summary>
|
||||
/// <param name="version">Origin version</param>
|
||||
/// <param name="currentGen">Current savefile generation</param>
|
||||
/// <param name="currentGen">Current save file generation</param>
|
||||
/// <returns>Met location list</returns>
|
||||
private IReadOnlyList<ComboItem> GetLocationListModified(GameVersion version, int currentGen)
|
||||
{
|
||||
|
|
|
@ -57,15 +57,15 @@ namespace PKHeX.Core
|
|||
/// <summary>
|
||||
/// Gets the location name for the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="eggmet">Location is from the <see cref="PKM.Egg_Location"/></param>
|
||||
/// <param name="locval">Location value</param>
|
||||
/// <param name="isEggLocation">Location is from the <see cref="PKM.Egg_Location"/></param>
|
||||
/// <param name="location">Location value</param>
|
||||
/// <param name="format">Current <see cref="PKM.Format"/></param>
|
||||
/// <param name="generation"><see cref="PKM.GenNumber"/> of origin</param>
|
||||
/// <param name="version">Current GameVersion (only applicable for <see cref="GameVersion.GG"/> differentiation)</param>
|
||||
/// <returns>Location name</returns>
|
||||
public static string GetLocationName(bool eggmet, int locval, int format, int generation, GameVersion version)
|
||||
public static string GetLocationName(bool isEggLocation, int location, int format, int generation, GameVersion version)
|
||||
{
|
||||
return Strings.GetLocationName(eggmet, locval, format, generation, version);
|
||||
return Strings.GetLocationName(isEggLocation, location, format, generation, version);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -388,22 +388,22 @@ namespace PKHeX.Core
|
|||
if (Legal.EReaderBerryIsEnigma)
|
||||
return g3items;
|
||||
|
||||
var g3itemsEBerry = (string[])g3items.Clone();
|
||||
g3itemsEBerry[175] = Legal.EReaderBerryDisplayName;
|
||||
return g3itemsEBerry;
|
||||
var g3ItemsWithEBerry = (string[])g3items.Clone();
|
||||
g3ItemsWithEBerry[175] = Legal.EReaderBerryDisplayName;
|
||||
return g3ItemsWithEBerry;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the location name for the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="eggmet">Location is from the <see cref="PKM.Egg_Location"/></param>
|
||||
/// <param name="locval">Location value</param>
|
||||
/// <param name="isEggLocation">Location is from the <see cref="PKM.Egg_Location"/></param>
|
||||
/// <param name="location">Location value</param>
|
||||
/// <param name="format">Current <see cref="PKM.Format"/></param>
|
||||
/// <param name="generation"><see cref="PKM.GenNumber"/> of origin</param>
|
||||
/// <param name="version">Current GameVersion (only applicable for <see cref="GameVersion.GG"/> differentiation)</param>
|
||||
/// <returns>Location name</returns>
|
||||
public string GetLocationName(bool eggmet, int locval, int format, int generation, GameVersion version)
|
||||
public string GetLocationName(bool isEggLocation, int location, int format, int generation, GameVersion version)
|
||||
{
|
||||
int gen = -1;
|
||||
int bankID = 0;
|
||||
|
@ -416,17 +416,17 @@ namespace PKHeX.Core
|
|||
{
|
||||
gen = 3;
|
||||
}
|
||||
else if (generation == 4 && (eggmet || format == 4)) // 4
|
||||
else if (generation == 4 && (isEggLocation || format == 4)) // 4
|
||||
{
|
||||
const int size = 1000;
|
||||
bankID = locval / size;
|
||||
bankID = location / size;
|
||||
gen = 4;
|
||||
locval %= size;
|
||||
location %= size;
|
||||
}
|
||||
else // 5-7+
|
||||
{
|
||||
const int size = 10000;
|
||||
bankID = locval / size;
|
||||
bankID = location / size;
|
||||
|
||||
int g = generation;
|
||||
if (g >= 5)
|
||||
|
@ -434,15 +434,15 @@ namespace PKHeX.Core
|
|||
else if (format >= 5)
|
||||
gen = format;
|
||||
|
||||
locval %= size;
|
||||
location %= size;
|
||||
if (bankID >= 3) // 30000 and onwards don't use 0th index, shift down 1
|
||||
locval--;
|
||||
location--;
|
||||
}
|
||||
|
||||
var bank = GetLocationNames(gen, bankID, version);
|
||||
if (bank.Count <= locval)
|
||||
if (bank.Count <= location)
|
||||
return string.Empty;
|
||||
return bank[locval];
|
||||
return bank[location];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -43,28 +43,28 @@ namespace PKHeX.Core
|
|||
return entries;
|
||||
}
|
||||
|
||||
private static string GetCountryName(int countryID, int l)
|
||||
private static string GetCountryName(int country, int l)
|
||||
{
|
||||
if (l < 0)
|
||||
return INVALID;
|
||||
if (countryID >= CountryList.Length)
|
||||
if (country >= CountryList.Length)
|
||||
return INVALID;
|
||||
var countryNames = CountryList[countryID];
|
||||
var countryNames = CountryList[country];
|
||||
if (l < countryNames.Length)
|
||||
return countryNames[l + 1];
|
||||
return INVALID;
|
||||
}
|
||||
|
||||
private static string GetRegionName(int countryID, int regionID, int l)
|
||||
private static string GetRegionName(int country, int region, int l)
|
||||
{
|
||||
if (l < 0)
|
||||
return INVALID;
|
||||
if (countryID >= RegionList.Length)
|
||||
if (country >= RegionList.Length)
|
||||
return INVALID;
|
||||
var regionstrs = RegionList[countryID] ?? (RegionList[countryID] = GetRegionList(countryID));
|
||||
if (regionID >= regionstrs.Length)
|
||||
var regionNames = RegionList[country] ?? (RegionList[country] = GetRegionList(country));
|
||||
if (region >= regionNames.Length)
|
||||
return INVALID;
|
||||
var localized = regionstrs[regionID];
|
||||
var localized = regionNames[region];
|
||||
if (l < localized.Length)
|
||||
return localized[l + 1];
|
||||
return INVALID;
|
||||
|
@ -107,17 +107,17 @@ namespace PKHeX.Core
|
|||
/// <summary>
|
||||
/// Gets Country and Region strings for corresponding IDs and language.
|
||||
/// </summary>
|
||||
/// <param name="countryID">Country ID</param>
|
||||
/// <param name="regionID">Region ID</param>
|
||||
/// <param name="country">Country ID</param>
|
||||
/// <param name="region">Region ID</param>
|
||||
/// <param name="language">Language ID</param>
|
||||
/// <returns>Tuple containing country and region</returns>
|
||||
public static Tuple<string, string> GetCountryRegionText(int countryID, int regionID, string language)
|
||||
public static Tuple<string, string> GetCountryRegionText(int country, int region, string language)
|
||||
{
|
||||
// Get Language we're fetching for
|
||||
int lang = Array.IndexOf(lang_geo, language);
|
||||
var country = GetCountryName(countryID, lang);
|
||||
var region = GetRegionName(countryID, regionID, lang);
|
||||
return new Tuple<string, string>(country, region); // country, region
|
||||
var countryName = GetCountryName(country, lang);
|
||||
var regionName = GetRegionName(country, region, lang);
|
||||
return new Tuple<string, string>(countryName, regionName); // country, region
|
||||
}
|
||||
|
||||
private static int GetLanguageIndex(string language) => Array.IndexOf(lang_geo, language);
|
||||
|
|
|
@ -28,13 +28,13 @@ namespace PKHeX.Core
|
|||
public const GameVersion HighestGameID = RB - 1;
|
||||
|
||||
/// <summary>Determines the Version Grouping of an input Version ID</summary>
|
||||
/// <param name="Version">Version of which to determine the group</param>
|
||||
/// <param name="version">Version of which to determine the group</param>
|
||||
/// <returns>Version Group Identifier or Invalid if type cannot be determined.</returns>
|
||||
public static GameVersion GetMetLocationVersionGroup(GameVersion Version)
|
||||
public static GameVersion GetMetLocationVersionGroup(GameVersion version)
|
||||
{
|
||||
switch (Version)
|
||||
switch (version)
|
||||
{
|
||||
// Sidegame
|
||||
// Side games
|
||||
case CXD:
|
||||
return CXD;
|
||||
case GO:
|
||||
|
@ -267,12 +267,13 @@ namespace PKHeX.Core
|
|||
{
|
||||
if (obj.MaxGameID == Legal.MaxGameID_7b) // edge case
|
||||
return new[] {GO, GP, GE};
|
||||
var vers = GameVersions.Where(z => z >= (GameVersion)obj.MinGameID && z <= (GameVersion)obj.MaxGameID);
|
||||
var versions = GameVersions
|
||||
.Where(version => (GameVersion)obj.MinGameID <= version && version <= (GameVersion)obj.MaxGameID);
|
||||
if (generation < 0)
|
||||
return vers;
|
||||
return versions;
|
||||
if (obj.MaxGameID == Legal.MaxGameID_7 && generation == 7)
|
||||
vers = vers.Where(z => z != GO);
|
||||
return vers.Where(z => z.GetGeneration() <= generation);
|
||||
versions = versions.Where(version => version != GO);
|
||||
return versions.Where(version => version.GetGeneration() <= generation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,9 +25,9 @@ namespace PKHeX.Core
|
|||
private static IEnumerable<WC3> GetIngameCXDData()
|
||||
{
|
||||
var langs = new[]{LanguageID.Japanese, LanguageID.English, LanguageID.French, LanguageID.Italian, LanguageID.German, LanguageID.Spanish};
|
||||
var h = new[] {string.Empty, "ダニー", "HORDEL", "VOLKER", "ODINO", "HORAZ", string.Empty, "HORDEL"};
|
||||
var d = new[] {string.Empty, "ギンザル", "DUKING", "DOKING", "RODRIGO", "GRAND", string.Empty, "GERMÁN"};
|
||||
var m = new[] {string.Empty, "バトルやま", "MATTLE", "MT BATAILL", "MONTE LOTT", "DUELLBERG", string.Empty, "ERNESTO"}; // truncated on ck3->pk3 transfer
|
||||
string[] h = {string.Empty, "ダニー", "HORDEL", "VOLKER", "ODINO", "HORAZ", string.Empty, "HORDEL"};
|
||||
string[] d = {string.Empty, "ギンザル", "DUKING", "DOKING", "RODRIGO", "GRAND", string.Empty, "GERMÁN"};
|
||||
string[] m = {string.Empty, "バトルやま", "MATTLE", "MT BATAILL", "MONTE LOTT", "DUELLBERG", string.Empty, "ERNESTO"}; // truncated on ck3->pk3 transfer
|
||||
|
||||
return langs.SelectMany(l => GetIngame((int)l));
|
||||
IEnumerable<WC3> GetIngame(int l)
|
||||
|
|
|
@ -28,18 +28,18 @@ namespace PKHeX.Core
|
|||
Version = game;
|
||||
}
|
||||
|
||||
public PKM ConvertToPKM(ITrainerInfo SAV) => ConvertToPKM(SAV, EncounterCriteria.Unrestricted);
|
||||
public PKM ConvertToPKM(ITrainerInfo sav) => ConvertToPKM(sav, EncounterCriteria.Unrestricted);
|
||||
|
||||
public PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria)
|
||||
public PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)
|
||||
{
|
||||
int gen = Generation;
|
||||
var version = Version;
|
||||
var pk = PKMConverter.GetBlank(gen, version);
|
||||
|
||||
SAV.ApplyToPKM(pk);
|
||||
sav.ApplyTo(pk);
|
||||
|
||||
pk.Species = Species;
|
||||
pk.Nickname = SpeciesName.GetSpeciesNameGeneration(Species, SAV.Language, gen);
|
||||
pk.Nickname = SpeciesName.GetSpeciesNameGeneration(Species, sav.Language, gen);
|
||||
pk.CurrentLevel = Level;
|
||||
pk.Version = (int)version;
|
||||
pk.Ball = (int)Ball.Poke;
|
||||
|
@ -57,14 +57,14 @@ namespace PKHeX.Core
|
|||
return pk;
|
||||
|
||||
if (gen >= 4)
|
||||
pk.SetEggMetData(version, (GameVersion)SAV.Game);
|
||||
pk.SetEggMetData(version, (GameVersion)sav.Game);
|
||||
|
||||
if (gen < 6)
|
||||
return pk;
|
||||
if (gen == 6)
|
||||
pk.SetHatchMemory6();
|
||||
|
||||
SetAltForm(pk, SAV);
|
||||
SetAltForm(pk, sav);
|
||||
|
||||
pk.SetRandomEC();
|
||||
pk.RelearnMoves = moves;
|
||||
|
@ -72,7 +72,7 @@ namespace PKHeX.Core
|
|||
return pk;
|
||||
}
|
||||
|
||||
private void SetAltForm(PKM pk, ITrainerInfo SAV)
|
||||
private void SetAltForm(PKM pk, ITrainerInfo sav)
|
||||
{
|
||||
switch (Species)
|
||||
{
|
||||
|
@ -82,7 +82,7 @@ namespace PKHeX.Core
|
|||
case (int)Core.Species.Scatterbug:
|
||||
case (int)Core.Species.Spewpa:
|
||||
case (int)Core.Species.Vivillon:
|
||||
pk.AltForm = Legal.GetVivillonPattern((byte)SAV.Country, (byte)SAV.SubRegion);
|
||||
pk.AltForm = Legal.GetVivillonPattern((byte)sav.Country, (byte)sav.SubRegion);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace PKHeX.Core
|
|||
Version = (GameVersion)pkm.Version;
|
||||
}
|
||||
|
||||
public PKM ConvertToPKM(ITrainerInfo SAV) => ConvertToPKM(SAV, EncounterCriteria.Unrestricted);
|
||||
public PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) => throw new ArgumentException($"Cannot convert an {nameof(EncounterInvalid)} to PKM.");
|
||||
public PKM ConvertToPKM(ITrainerInfo sav) => ConvertToPKM(sav, EncounterCriteria.Unrestricted);
|
||||
public PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria) => throw new ArgumentException($"Cannot convert an {nameof(EncounterInvalid)} to PKM.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace PKHeX.Core
|
|||
Check = check;
|
||||
}
|
||||
|
||||
public PKM ConvertToPKM(ITrainerInfo SAV) => ConvertToPKM(SAV, EncounterCriteria.Unrestricted);
|
||||
public PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria) => throw new ArgumentException($"Cannot convert an {nameof(EncounterRejected)} to PKM.");
|
||||
public PKM ConvertToPKM(ITrainerInfo sav) => ConvertToPKM(sav, EncounterCriteria.Unrestricted);
|
||||
public PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria) => throw new ArgumentException($"Cannot convert an {nameof(EncounterRejected)} to PKM.");
|
||||
}
|
||||
}
|
|
@ -84,15 +84,15 @@ namespace PKHeX.Core
|
|||
}
|
||||
}
|
||||
|
||||
public PKM ConvertToPKM(ITrainerInfo SAV) => ConvertToPKM(SAV, EncounterCriteria.Unrestricted);
|
||||
public PKM ConvertToPKM(ITrainerInfo sav) => ConvertToPKM(sav, EncounterCriteria.Unrestricted);
|
||||
|
||||
public PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria)
|
||||
public PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)
|
||||
{
|
||||
var version = this.GetCompatibleVersion((GameVersion)SAV.Game);
|
||||
int lang = (int)Language.GetSafeLanguage(Generation, (LanguageID)SAV.Language);
|
||||
var version = this.GetCompatibleVersion((GameVersion)sav.Game);
|
||||
int lang = (int)Language.GetSafeLanguage(Generation, (LanguageID)sav.Language);
|
||||
int level = LevelMin;
|
||||
var pk = PKMConverter.GetBlank(Generation, Version);
|
||||
SAV.ApplyToPKM(pk);
|
||||
sav.ApplyTo(pk);
|
||||
|
||||
pk.Species = Species;
|
||||
pk.Language = lang;
|
||||
|
@ -102,7 +102,7 @@ namespace PKHeX.Core
|
|||
pk.Ball = (int)Type.GetBall();
|
||||
pk.Language = lang;
|
||||
pk.OT_Friendship = pk.PersonalInfo.BaseFriendship;
|
||||
pk.AltForm = GetWildAltForm(pk, Form, SAV);
|
||||
pk.AltForm = GetWildAltForm(pk, Form, sav);
|
||||
|
||||
SetMetData(pk, level, Location);
|
||||
SetPINGA(pk, criteria);
|
||||
|
@ -113,7 +113,7 @@ namespace PKHeX.Core
|
|||
if (pk.Format < 6)
|
||||
return pk;
|
||||
|
||||
SAV.ApplyHandlingTrainerInfo(pk);
|
||||
sav.ApplyHandlingTrainerInfo(pk);
|
||||
pk.SetRandomEC();
|
||||
|
||||
return pk;
|
||||
|
@ -191,7 +191,7 @@ namespace PKHeX.Core
|
|||
pk.MetDate = DateTime.Today;
|
||||
}
|
||||
|
||||
private static int GetWildAltForm(PKM pk, int form, ITrainerInfo SAV)
|
||||
private static int GetWildAltForm(PKM pk, int form, ITrainerInfo sav)
|
||||
{
|
||||
if (form < 30) // specified form
|
||||
{
|
||||
|
@ -204,7 +204,7 @@ namespace PKHeX.Core
|
|||
|
||||
int spec = pk.Species;
|
||||
if (spec == (int)Core.Species.Scatterbug || spec == (int)Core.Species.Spewpa || spec == (int)Core.Species.Vivillon)
|
||||
return Legal.GetVivillonPattern((byte)SAV.Country, (byte)SAV.SubRegion);
|
||||
return Legal.GetVivillonPattern((byte)sav.Country, (byte)sav.SubRegion);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -56,20 +56,20 @@ namespace PKHeX.Core
|
|||
public string Name => _name;
|
||||
public string LongName => Version == GameVersion.Any ? _name : $"{_name} ({Version})";
|
||||
|
||||
public PKM ConvertToPKM(ITrainerInfo SAV) => ConvertToPKM(SAV, EncounterCriteria.Unrestricted);
|
||||
public PKM ConvertToPKM(ITrainerInfo sav) => ConvertToPKM(sav, EncounterCriteria.Unrestricted);
|
||||
|
||||
public PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria)
|
||||
public PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)
|
||||
{
|
||||
var pk = PKMConverter.GetBlank(Generation, Version);
|
||||
SAV.ApplyToPKM(pk);
|
||||
sav.ApplyTo(pk);
|
||||
|
||||
pk.EncryptionConstant = Util.Rand32();
|
||||
pk.Species = Species;
|
||||
pk.AltForm = Form;
|
||||
|
||||
int lang = (int)Language.GetSafeLanguage(Generation, (LanguageID)SAV.Language);
|
||||
int lang = (int)Language.GetSafeLanguage(Generation, (LanguageID)sav.Language);
|
||||
int level = GetMinimalLevel();
|
||||
var version = this.GetCompatibleVersion((GameVersion)SAV.Game);
|
||||
var version = this.GetCompatibleVersion((GameVersion)sav.Game);
|
||||
SanityCheckVersion(ref version);
|
||||
|
||||
pk.Language = lang = GetEdgeCaseLanguage(pk, lang);
|
||||
|
@ -84,7 +84,7 @@ namespace PKHeX.Core
|
|||
var today = DateTime.Today;
|
||||
SetMetData(pk, level, today);
|
||||
if (EggEncounter)
|
||||
SetEggMetData(pk, SAV, today);
|
||||
SetEggMetData(pk, sav, today);
|
||||
|
||||
SetPINGA(pk, criteria);
|
||||
SetEncounterMoves(pk, version, level);
|
||||
|
@ -115,7 +115,7 @@ namespace PKHeX.Core
|
|||
return pk;
|
||||
|
||||
pk.SetRelearnMoves(Relearn);
|
||||
SAV.ApplyHandlingTrainerInfo(pk);
|
||||
sav.ApplyHandlingTrainerInfo(pk);
|
||||
pk.SetRandomEC();
|
||||
|
||||
if (this is IGigantamax g && pk is IGigantamax pg)
|
||||
|
|
|
@ -78,21 +78,21 @@ namespace PKHeX.Core
|
|||
Locations.LinkTrade6NPC, // 8 is same as 6
|
||||
};
|
||||
|
||||
public PKM ConvertToPKM(ITrainerInfo SAV) => ConvertToPKM(SAV, EncounterCriteria.Unrestricted);
|
||||
public PKM ConvertToPKM(ITrainerInfo sav) => ConvertToPKM(sav, EncounterCriteria.Unrestricted);
|
||||
|
||||
public PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria)
|
||||
public PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)
|
||||
{
|
||||
var pk = PKMConverter.GetBlank(Generation, Version);
|
||||
SAV.ApplyToPKM(pk);
|
||||
sav.ApplyTo(pk);
|
||||
|
||||
ApplyDetails(SAV, criteria, pk);
|
||||
ApplyDetails(sav, criteria, pk);
|
||||
return pk;
|
||||
}
|
||||
|
||||
protected virtual void ApplyDetails(ITrainerInfo SAV, EncounterCriteria criteria, PKM pk)
|
||||
protected virtual void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk)
|
||||
{
|
||||
var version = this.GetCompatibleVersion((GameVersion)SAV.Game);
|
||||
int lang = (int)Language.GetSafeLanguage(Generation, (LanguageID)SAV.Language);
|
||||
var version = this.GetCompatibleVersion((GameVersion)sav.Game);
|
||||
int lang = (int)Language.GetSafeLanguage(Generation, (LanguageID)sav.Language);
|
||||
int level = CurrentLevel > 0 ? CurrentLevel : LevelMin;
|
||||
if (level == 0)
|
||||
level = Math.Max(1, LevelMin);
|
||||
|
@ -105,8 +105,8 @@ namespace PKHeX.Core
|
|||
pk.Species = species;
|
||||
pk.AltForm = Form;
|
||||
pk.Language = lang;
|
||||
pk.OT_Name = pk.Format == 1 ? StringConverter12.G1TradeOTStr : HasTrainerName ? GetOT(lang) : SAV.OT;
|
||||
pk.OT_Gender = HasTrainerName ? Math.Max(0, OTGender) : SAV.Gender;
|
||||
pk.OT_Name = pk.Format == 1 ? StringConverter12.G1TradeOTStr : HasTrainerName ? GetOT(lang) : sav.OT;
|
||||
pk.OT_Gender = HasTrainerName ? Math.Max(0, OTGender) : sav.Gender;
|
||||
pk.SetNickname(GetNickname(lang));
|
||||
|
||||
pk.CurrentLevel = level;
|
||||
|
@ -143,7 +143,7 @@ namespace PKHeX.Core
|
|||
if (pk.Format < 6)
|
||||
return;
|
||||
|
||||
SAV.ApplyHandlingTrainerInfo(pk, force: true);
|
||||
sav.ApplyHandlingTrainerInfo(pk, force: true);
|
||||
pk.SetRandomEC();
|
||||
|
||||
if (pk.Format == 6)
|
||||
|
@ -416,9 +416,9 @@ namespace PKHeX.Core
|
|||
OT_TextVar = v;
|
||||
}
|
||||
|
||||
protected override void ApplyDetails(ITrainerInfo SAV, EncounterCriteria criteria, PKM pk)
|
||||
protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk)
|
||||
{
|
||||
base.ApplyDetails(SAV, criteria, pk);
|
||||
base.ApplyDetails(sav, criteria, pk);
|
||||
pk.OT_Memory = OT_Memory;
|
||||
pk.OT_Intensity = OT_Intensity;
|
||||
pk.OT_Feeling = OT_Feeling;
|
||||
|
@ -433,9 +433,9 @@ namespace PKHeX.Core
|
|||
public int OT_Feeling => 5;
|
||||
public int OT_TextVar => 40;
|
||||
|
||||
protected override void ApplyDetails(ITrainerInfo SAV, EncounterCriteria criteria, PKM pk)
|
||||
protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk)
|
||||
{
|
||||
base.ApplyDetails(SAV, criteria, pk);
|
||||
base.ApplyDetails(sav, criteria, pk);
|
||||
pk.OT_Memory = OT_Memory;
|
||||
pk.OT_Intensity = OT_Intensity;
|
||||
pk.OT_Feeling = OT_Feeling;
|
||||
|
|
|
@ -31,14 +31,14 @@ namespace PKHeX.Core
|
|||
return base.IsMatch(pkm, lvl);
|
||||
}
|
||||
|
||||
protected override void ApplyDetails(ITrainerInfo SAV, EncounterCriteria criteria, PKM pk)
|
||||
protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk)
|
||||
{
|
||||
base.ApplyDetails(SAV, criteria, pk);
|
||||
base.ApplyDetails(sav, criteria, pk);
|
||||
pk.SetRelearnMoves(Relearn);
|
||||
|
||||
var pk8 = (PK8)pk;
|
||||
pk8.DynamaxLevel = DynamaxLevel;
|
||||
pk8.HT_Language = SAV.Language;
|
||||
pk8.HT_Language = sav.Language;
|
||||
pk8.OT_Memory = OT_Memory;
|
||||
pk8.OT_TextVar = OT_TextVar;
|
||||
pk8.OT_Feeling = OT_Feeling;
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
int LevelMax { get; }
|
||||
int Generation { get; }
|
||||
|
||||
PKM ConvertToPKM(ITrainerInfo SAV);
|
||||
PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria);
|
||||
PKM ConvertToPKM(ITrainerInfo sav);
|
||||
PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria);
|
||||
}
|
||||
|
||||
public static partial class Extensions
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace PKHeX.Core
|
|||
|
||||
public static partial class Extensions
|
||||
{
|
||||
public static void ApplyToPKM(this ITrainerInfo info, PKM pk)
|
||||
public static void ApplyTo(this ITrainerInfo info, PKM pk)
|
||||
{
|
||||
pk.OT_Name = info.OT;
|
||||
pk.TID = info.TID;
|
||||
|
@ -35,21 +35,21 @@ namespace PKHeX.Core
|
|||
pk.ConsoleRegion = info.ConsoleRegion;
|
||||
}
|
||||
|
||||
public static void ApplyHandlingTrainerInfo(this ITrainerInfo SAV, PKM pk, bool force = false)
|
||||
public static void ApplyHandlingTrainerInfo(this ITrainerInfo sav, PKM pk, bool force = false)
|
||||
{
|
||||
if (pk.Format == SAV.Generation && !force)
|
||||
if (pk.Format == sav.Generation && !force)
|
||||
return;
|
||||
|
||||
pk.HT_Name = SAV.OT;
|
||||
pk.HT_Gender = SAV.Gender;
|
||||
pk.HT_Name = sav.OT;
|
||||
pk.HT_Gender = sav.Gender;
|
||||
pk.HT_Friendship = pk.OT_Friendship;
|
||||
pk.CurrentHandler = 1;
|
||||
|
||||
if (pk.Format == 6)
|
||||
{
|
||||
var g = (IGeoTrack) pk;
|
||||
g.Geo1_Country = SAV.Country;
|
||||
g.Geo1_Region = SAV.SubRegion;
|
||||
g.Geo1_Country = sav.Country;
|
||||
g.Geo1_Region = sav.SubRegion;
|
||||
((PK6)pk).TradeMemory(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,11 +14,11 @@ namespace PKHeX.Core
|
|||
|
||||
public override void Verify(LegalityAnalysis data)
|
||||
{
|
||||
var EncounterMatch = data.EncounterMatch;
|
||||
var encounter = data.EncounterMatch;
|
||||
var pkm = data.pkm;
|
||||
var Info = data.Info;
|
||||
// Check Unobtainable Ribbons
|
||||
var encounterContent = EncounterMatch is MysteryGift mg ? mg.Content : EncounterMatch;
|
||||
var encounterContent = encounter is MysteryGift mg ? mg.Content : encounter;
|
||||
if (pkm.IsEgg)
|
||||
{
|
||||
if (GetIncorrectRibbonsEgg(pkm, encounterContent))
|
||||
|
@ -57,17 +57,17 @@ namespace PKHeX.Core
|
|||
|
||||
private static bool GetIncorrectRibbonsEgg(PKM pkm, object encounterContent)
|
||||
{
|
||||
var RibbonNames = ReflectUtil.GetPropertiesStartWithPrefix(pkm.GetType(), "Ribbon");
|
||||
var names = ReflectUtil.GetPropertiesStartWithPrefix(pkm.GetType(), "Ribbon");
|
||||
if (encounterContent is IRibbonSetEvent3 event3)
|
||||
RibbonNames = RibbonNames.Except(event3.RibbonNames());
|
||||
names = names.Except(event3.RibbonNames());
|
||||
if (encounterContent is IRibbonSetEvent4 event4)
|
||||
RibbonNames = RibbonNames.Except(event4.RibbonNames());
|
||||
names = names.Except(event4.RibbonNames());
|
||||
|
||||
foreach (var RibbonValue in RibbonNames.Select(RibbonName => ReflectUtil.GetValue(pkm, RibbonName)))
|
||||
foreach (var value in names.Select(name => ReflectUtil.GetValue(pkm, name)))
|
||||
{
|
||||
if (RibbonValue is null)
|
||||
if (value is null)
|
||||
continue;
|
||||
if (HasFlag(RibbonValue) || HasCount(RibbonValue))
|
||||
if (HasFlag(value) || HasCount(value))
|
||||
return true;
|
||||
|
||||
static bool HasFlag(object o) => o is bool z && z;
|
||||
|
@ -100,6 +100,7 @@ namespace PKHeX.Core
|
|||
yield return new RibbonResult(nameof(u3.RibbonVictory));
|
||||
}
|
||||
}
|
||||
|
||||
if (pkm is IRibbonSetUnique4 u4)
|
||||
{
|
||||
if (!IsAllowedBattleFrontier(pkm.Species, pkm.AltForm, 4) || gen > 4)
|
||||
|
@ -108,30 +109,20 @@ namespace PKHeX.Core
|
|||
yield return z;
|
||||
}
|
||||
|
||||
var c3 = u4.RibbonBitsContest3(); var c3n = u4.RibbonNamesContest3();
|
||||
var c4 = u4.RibbonBitsContest4(); var c4n = u4.RibbonNamesContest4();
|
||||
var iter3 = gen == 3 ? getMissingContestRibbons(c3, c3n) : GetInvalidRibbonsNone(c3, c3n);
|
||||
var iter4 = (gen == 3 || gen == 4) && IsAllowedInContest4(pkm.Species) ? getMissingContestRibbons(c4, c4n) : GetInvalidRibbonsNone(c4, c4n);
|
||||
foreach (var z in iter3.Concat(iter4))
|
||||
var c3 = u4.RibbonBitsContest3();
|
||||
var c3n = u4.RibbonNamesContest3();
|
||||
var iter3 = gen == 3 ? GetMissingContestRibbons(c3, c3n) : GetInvalidRibbonsNone(c3, c3n);
|
||||
foreach (var z in iter3)
|
||||
yield return z;
|
||||
|
||||
for (int i = 0; i < 5; ++i)
|
||||
artist |= c3[3 | i << 2]; // any master rank ribbon
|
||||
|
||||
static IEnumerable<RibbonResult> getMissingContestRibbons(IReadOnlyList<bool> bits, IReadOnlyList<string> names)
|
||||
{
|
||||
for (int i = 0; i < bits.Count; i += 4)
|
||||
{
|
||||
bool required = false;
|
||||
for (int j = i + 3; j >= i; j--)
|
||||
{
|
||||
if (bits[j])
|
||||
required = true;
|
||||
else if (required)
|
||||
yield return new RibbonResult(names[j], false);
|
||||
}
|
||||
}
|
||||
}
|
||||
var c4 = u4.RibbonBitsContest4();
|
||||
var c4n = u4.RibbonNamesContest4();
|
||||
var iter4 = (gen == 3 || gen == 4) && IsAllowedInContest4(pkm.Species) ? GetMissingContestRibbons(c4, c4n) : GetInvalidRibbonsNone(c4, c4n);
|
||||
foreach (var z in iter4)
|
||||
yield return z;
|
||||
}
|
||||
if (pkm is IRibbonSetCommon4 s4)
|
||||
{
|
||||
|
@ -193,6 +184,20 @@ namespace PKHeX.Core
|
|||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<RibbonResult> GetMissingContestRibbons(IReadOnlyList<bool> bits, IReadOnlyList<string> names)
|
||||
{
|
||||
for (int i = 0; i < bits.Count; i += 4)
|
||||
{
|
||||
bool required = false;
|
||||
for (int j = i + 3; j >= i; j--)
|
||||
{
|
||||
if (bits[j])
|
||||
required = true;
|
||||
else if (required) yield return new RibbonResult(names[j], false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<RibbonResult> GetInvalidRibbons4Any(PKM pkm, IRibbonSetCommon4 s4, int gen)
|
||||
{
|
||||
if (s4.RibbonRecord)
|
||||
|
@ -258,8 +263,8 @@ namespace PKHeX.Core
|
|||
yield return new RibbonResult(rib);
|
||||
}
|
||||
|
||||
const int mem_Chatelaine = 30;
|
||||
bool hasChampMemory = pkm.HT_Memory == mem_Chatelaine || pkm.OT_Memory == mem_Chatelaine;
|
||||
const int memChatelaine = 30;
|
||||
bool hasChampMemory = pkm.HT_Memory == memChatelaine || pkm.OT_Memory == memChatelaine;
|
||||
if (!IsAllowedBattleFrontier(pkm.Species))
|
||||
{
|
||||
if (hasChampMemory || s6.RibbonBattlerSkillful) // having memory and not ribbon is too rare, just flag here.
|
||||
|
@ -335,8 +340,8 @@ namespace PKHeX.Core
|
|||
yield return new RibbonResult(nameof(s6.RibbonTraining));
|
||||
}
|
||||
|
||||
const int mem_Champion = 27;
|
||||
bool hasChampMemory = (pkm.Format < 8 && pkm.HT_Memory == mem_Champion) || (pkm.Gen6 && pkm.OT_Memory == mem_Champion);
|
||||
const int memChampion = 27;
|
||||
bool hasChampMemory = (pkm.Format < 8 && pkm.HT_Memory == memChampion) || (pkm.Gen6 && pkm.OT_Memory == memChampion);
|
||||
if (!hasChampMemory || s6.RibbonChampionKalos || s6.RibbonChampionG6Hoenn)
|
||||
yield break;
|
||||
|
||||
|
@ -371,8 +376,8 @@ namespace PKHeX.Core
|
|||
}
|
||||
else
|
||||
{
|
||||
const int mem_Champion = 27;
|
||||
bool hasChampMemory = (pkm.Format == 8 && pkm.HT_Memory == mem_Champion) || (pkm.Gen8 && pkm.OT_Memory == mem_Champion);
|
||||
const int memChampion = 27;
|
||||
bool hasChampMemory = (pkm.Format == 8 && pkm.HT_Memory == memChampion) || (pkm.Gen8 && pkm.OT_Memory == memChampion);
|
||||
if (hasChampMemory && !s8.RibbonChampionGalar)
|
||||
yield return new RibbonResult(nameof(s8.RibbonChampionGalar));
|
||||
}
|
||||
|
|
|
@ -48,9 +48,9 @@ namespace PKHeX.Core
|
|||
/// </summary>
|
||||
/// <param name="len">Length, in bytes, of the data of which to determine validity.</param>
|
||||
/// <returns>A boolean indicating whether or not the given length is valid for a mystery gift.</returns>
|
||||
public static bool IsMysteryGift(long len) => MGSizes.Contains((int)len);
|
||||
public static bool IsMysteryGift(long len) => Sizes.Contains((int)len);
|
||||
|
||||
private static readonly HashSet<int> MGSizes = new HashSet<int>{ WC8.Size, WC6Full.Size, WC6.Size, PGF.Size, PGT.Size, PCD.Size };
|
||||
private static readonly HashSet<int> Sizes = new HashSet<int>{ WC8.Size, WC6Full.Size, WC6.Size, PGF.Size, PGT.Size, PCD.Size };
|
||||
|
||||
/// <summary>
|
||||
/// Converts the given data to a <see cref="MysteryGift"/>.
|
||||
|
@ -129,8 +129,8 @@ namespace PKHeX.Core
|
|||
public string FileName => $"{CardHeader}.{Extension}";
|
||||
public abstract int Format { get; }
|
||||
|
||||
public PKM ConvertToPKM(ITrainerInfo SAV) => ConvertToPKM(SAV, EncounterCriteria.Unrestricted);
|
||||
public abstract PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria);
|
||||
public PKM ConvertToPKM(ITrainerInfo sav) => ConvertToPKM(sav, EncounterCriteria.Unrestricted);
|
||||
public abstract PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria);
|
||||
|
||||
protected abstract bool IsMatchExact(PKM pkm);
|
||||
protected abstract bool IsMatchDeferred(PKM pkm);
|
||||
|
@ -158,7 +158,7 @@ namespace PKHeX.Core
|
|||
/// <summary>
|
||||
/// Gets a friendly name for the underlying <see cref="MysteryGift"/> type for the <see cref="IEncounterable"/> interface.
|
||||
/// </summary>
|
||||
public string Name => $"Event Gift";
|
||||
public string Name => "Event Gift";
|
||||
|
||||
/// <summary>
|
||||
/// Gets a friendly name for the underlying <see cref="MysteryGift"/> type for the <see cref="IEncounterable"/> interface.
|
||||
|
|
|
@ -114,18 +114,18 @@ namespace PKHeX.Core
|
|||
/// Checks if the <see cref="MysteryGift"/> data is compatible with the <see cref="SaveFile"/>. Sets appropriate data to the save file in order to receive the gift.
|
||||
/// </summary>
|
||||
/// <param name="g">Gift data to potentially insert to the save file.</param>
|
||||
/// <param name="SAV">Save file receiving the gift data.</param>
|
||||
/// <param name="sav">Save file receiving the gift data.</param>
|
||||
/// <param name="message">Error message if incompatible.</param>
|
||||
/// <returns>True if compatible, false if incompatible.</returns>
|
||||
public static bool IsCardCompatible(this MysteryGift g, SaveFile SAV, out string message)
|
||||
public static bool IsCardCompatible(this MysteryGift g, SaveFile sav, out string message)
|
||||
{
|
||||
if (g.Format != SAV.Generation)
|
||||
if (g.Format != sav.Generation)
|
||||
{
|
||||
message = MsgMysteryGiftSlotSpecialReject;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!SAV.CanReceiveGift(g))
|
||||
if (!sav.CanReceiveGift(g))
|
||||
{
|
||||
message = MsgMysteryGiftTypeDetails;
|
||||
return false;
|
||||
|
@ -133,7 +133,7 @@ namespace PKHeX.Core
|
|||
|
||||
if (g is WC6 && g.CardID == 2048 && g.ItemID == 726) // Eon Ticket (OR/AS)
|
||||
{
|
||||
if (!(SAV is SAV6AO))
|
||||
if (!(sav is SAV6AO))
|
||||
{
|
||||
message = MsgMysteryGiftSlotSpecialReject;
|
||||
return false;
|
||||
|
@ -147,16 +147,16 @@ namespace PKHeX.Core
|
|||
/// <summary>
|
||||
/// Checks if the gift values are receivable by the game.
|
||||
/// </summary>
|
||||
/// <param name="SAV">Save file receiving the gift data.</param>
|
||||
/// <param name="sav">Save file receiving the gift data.</param>
|
||||
/// <param name="gift">Gift data to potentially insert to the save file.</param>
|
||||
/// <returns>True if compatible, false if incompatible.</returns>
|
||||
public static bool CanReceiveGift(this SaveFile SAV, MysteryGift gift)
|
||||
public static bool CanReceiveGift(this SaveFile sav, MysteryGift gift)
|
||||
{
|
||||
if (gift.Species > SAV.MaxSpeciesID)
|
||||
if (gift.Species > sav.MaxSpeciesID)
|
||||
return false;
|
||||
if (gift.Moves.Any(move => move > SAV.MaxMoveID))
|
||||
if (gift.Moves.Any(move => move > sav.MaxMoveID))
|
||||
return false;
|
||||
if (gift.HeldItem > SAV.MaxItemID)
|
||||
if (gift.HeldItem > sav.MaxItemID)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -122,9 +122,9 @@ namespace PKHeX.Core
|
|||
return true;
|
||||
}
|
||||
|
||||
public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria)
|
||||
public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)
|
||||
{
|
||||
return Gift.ConvertToPKM(SAV, criteria);
|
||||
return Gift.ConvertToPKM(sav, criteria);
|
||||
}
|
||||
|
||||
public bool CanBeReceivedBy(int pkmVersion) => (CardCompatibility >> pkmVersion & 1) == 1;
|
||||
|
|
|
@ -161,7 +161,7 @@ namespace PKHeX.Core
|
|||
public override bool IsItem { get => CardType == 2; set { if (value) CardType = 2; } }
|
||||
public bool IsPower { get => CardType == 3; set { if (value) CardType = 3; } }
|
||||
|
||||
public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria)
|
||||
public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)
|
||||
{
|
||||
if (!IsPokémon)
|
||||
throw new ArgumentException(nameof(IsPokémon));
|
||||
|
@ -185,8 +185,8 @@ namespace PKHeX.Core
|
|||
Met_Level = currentLevel,
|
||||
Nature = Nature != -1 ? Nature : rnd.Next(25),
|
||||
AltForm = Form,
|
||||
Version = OriginGame == 0 ? SAV.Game : OriginGame,
|
||||
Language = Language == 0 ? SAV.Language : Language,
|
||||
Version = OriginGame == 0 ? sav.Game : OriginGame,
|
||||
Language = Language == 0 ? sav.Language : Language,
|
||||
Ball = Ball,
|
||||
Move1 = Move1,
|
||||
Move2 = Move2,
|
||||
|
@ -224,7 +224,7 @@ namespace PKHeX.Core
|
|||
|
||||
FatefulEncounter = true,
|
||||
};
|
||||
if (SAV.Generation > 5 && OriginGame == 0) // Gen6+, give random gen5 game
|
||||
if (sav.Generation > 5 && OriginGame == 0) // Gen6+, give random gen5 game
|
||||
pk.Version = (int)GameVersion.W + rnd.Next(4);
|
||||
|
||||
if (Move1 == 0) // No moves defined
|
||||
|
@ -234,17 +234,17 @@ namespace PKHeX.Core
|
|||
|
||||
if (IsEgg) // User's
|
||||
{
|
||||
pk.TID = SAV.TID;
|
||||
pk.SID = SAV.SID;
|
||||
pk.OT_Name = SAV.OT;
|
||||
pk.OT_Gender = SAV.Gender;
|
||||
pk.TID = sav.TID;
|
||||
pk.SID = sav.SID;
|
||||
pk.OT_Name = sav.OT;
|
||||
pk.OT_Gender = sav.Gender;
|
||||
}
|
||||
else // Hardcoded
|
||||
{
|
||||
pk.TID = TID;
|
||||
pk.SID = SID;
|
||||
pk.OT_Name = OT_Name;
|
||||
pk.OT_Gender = (OTGender == 3 ? SAV.Gender : OTGender) & 1; // some events have variable gender based on receiving SaveFile
|
||||
pk.OT_Gender = (OTGender == 3 ? sav.Gender : OTGender) & 1; // some events have variable gender based on receiving SaveFile
|
||||
}
|
||||
|
||||
pk.IsNicknamed = IsNicknamed;
|
||||
|
@ -362,7 +362,7 @@ namespace PKHeX.Core
|
|||
}
|
||||
else if (PIDType == 0 && pkm.IsShiny)
|
||||
{
|
||||
return false; // can't be traded away for unshiny
|
||||
return false; // can't be traded away for un-shiny
|
||||
}
|
||||
|
||||
if (pkm.IsEgg && !pkm.IsNative)
|
||||
|
|
|
@ -61,10 +61,10 @@ namespace PKHeX.Core
|
|||
set
|
||||
{
|
||||
_pk = value;
|
||||
var pkdata = value.Data.All(z => z == 0)
|
||||
var data = value.Data.All(z => z == 0)
|
||||
? value.Data
|
||||
: PokeCrypto.EncryptArray45(value.Data);
|
||||
pkdata.CopyTo(Data, 8);
|
||||
data.CopyTo(Data, 8);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ namespace PKHeX.Core
|
|||
public override int Location { get => PK.Met_Location; set => PK.Met_Location = value; }
|
||||
public override int EggLocation { get => PK.Egg_Location; set => PK.Egg_Location = value; }
|
||||
|
||||
public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria)
|
||||
public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)
|
||||
{
|
||||
if (!IsPokémon)
|
||||
throw new ArgumentException(nameof(IsPokémon));
|
||||
|
@ -127,18 +127,18 @@ namespace PKHeX.Core
|
|||
PK4 pk4 = new PK4((byte[])PK.Data.Clone()) { Sanity = 0 };
|
||||
if (!IsHatched && Detail == 0)
|
||||
{
|
||||
pk4.OT_Name = SAV.OT;
|
||||
pk4.TID = SAV.TID;
|
||||
pk4.SID = SAV.SID;
|
||||
pk4.OT_Gender = SAV.Gender;
|
||||
pk4.Language = SAV.Language;
|
||||
pk4.OT_Name = sav.OT;
|
||||
pk4.TID = sav.TID;
|
||||
pk4.SID = sav.SID;
|
||||
pk4.OT_Gender = sav.Gender;
|
||||
pk4.Language = sav.Language;
|
||||
}
|
||||
|
||||
if (IsManaphyEgg)
|
||||
SetDefaultManaphyEggDetails(pk4);
|
||||
|
||||
SetPINGA(pk4, criteria);
|
||||
SetMetData(pk4, SAV);
|
||||
SetMetData(pk4, sav);
|
||||
|
||||
var pi = pk4.PersonalInfo;
|
||||
pk4.CurrentFriendship = pk4.IsEgg ? pi.HatchCycles : pi.BaseFriendship;
|
||||
|
|
|
@ -293,7 +293,7 @@ namespace PKHeX.Core
|
|||
return 0xEE + (index * 0x1A);
|
||||
}
|
||||
|
||||
public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria)
|
||||
public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)
|
||||
{
|
||||
if (!IsPokémon)
|
||||
throw new ArgumentException(nameof(IsPokémon));
|
||||
|
@ -303,7 +303,7 @@ namespace PKHeX.Core
|
|||
int currentLevel = Level > 0 ? Level : rnd.Next(1, 101);
|
||||
int metLevel = MetLevel > 0 ? MetLevel : currentLevel;
|
||||
var pi = PersonalTable.GG.GetFormeEntry(Species, Form);
|
||||
var OT = GetOT(SAV.Language);
|
||||
var OT = GetOT(sav.Language);
|
||||
|
||||
var pk = new PB7
|
||||
{
|
||||
|
@ -314,12 +314,12 @@ namespace PKHeX.Core
|
|||
Met_Level = metLevel,
|
||||
AltForm = Form,
|
||||
EncryptionConstant = EncryptionConstant != 0 ? EncryptionConstant : Util.Rand32(),
|
||||
Version = OriginGame != 0 ? OriginGame : SAV.Game,
|
||||
Language = SAV.Language,
|
||||
Version = OriginGame != 0 ? OriginGame : sav.Game,
|
||||
Language = sav.Language,
|
||||
Ball = Ball,
|
||||
Country = SAV.Country,
|
||||
Region = SAV.SubRegion,
|
||||
ConsoleRegion = SAV.ConsoleRegion,
|
||||
Country = sav.Country,
|
||||
Region = sav.SubRegion,
|
||||
ConsoleRegion = sav.ConsoleRegion,
|
||||
Move1 = Move1,
|
||||
Move2 = Move2,
|
||||
Move3 = Move3,
|
||||
|
@ -337,10 +337,10 @@ namespace PKHeX.Core
|
|||
AV_SPA = AV_SPA,
|
||||
AV_SPD = AV_SPD,
|
||||
|
||||
OT_Name = OT.Length > 0 ? OT : SAV.OT,
|
||||
OT_Gender = OTGender != 3 ? OTGender % 2 : SAV.Gender,
|
||||
HT_Name = OT_Name.Length > 0 ? SAV.OT : string.Empty,
|
||||
HT_Gender = OT_Name.Length > 0 ? SAV.Gender : 0,
|
||||
OT_Name = OT.Length > 0 ? OT : sav.OT,
|
||||
OT_Gender = OTGender != 3 ? OTGender % 2 : sav.Gender,
|
||||
HT_Name = OT_Name.Length > 0 ? sav.OT : string.Empty,
|
||||
HT_Gender = OT_Name.Length > 0 ? sav.Gender : 0,
|
||||
CurrentHandler = OT_Name.Length > 0 ? 1 : 0,
|
||||
|
||||
EXP = Experience.GetEXP(currentLevel, pi.EXPGrowth),
|
||||
|
@ -350,7 +350,7 @@ namespace PKHeX.Core
|
|||
};
|
||||
pk.SetMaximumPPCurrent();
|
||||
|
||||
if ((SAV.Generation > Format && OriginGame == 0) || !CanBeReceivedByVersion(pk.Version))
|
||||
if ((sav.Generation > Format && OriginGame == 0) || !CanBeReceivedByVersion(pk.Version))
|
||||
{
|
||||
// give random valid game
|
||||
do { pk.Version = (int)GameVersion.GP + rnd.Next(2); }
|
||||
|
@ -359,8 +359,8 @@ namespace PKHeX.Core
|
|||
|
||||
if (OTGender == 3)
|
||||
{
|
||||
pk.TID = SAV.TID;
|
||||
pk.SID = SAV.SID;
|
||||
pk.TID = sav.TID;
|
||||
pk.SID = sav.SID;
|
||||
}
|
||||
|
||||
pk.MetDate = Date ?? DateTime.Now;
|
||||
|
|
|
@ -70,7 +70,7 @@ namespace PKHeX.Core
|
|||
set => _metLevel = value;
|
||||
}
|
||||
|
||||
public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria)
|
||||
public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)
|
||||
{
|
||||
PK3 pk = new PK3
|
||||
{
|
||||
|
@ -88,24 +88,24 @@ namespace PKHeX.Core
|
|||
RibbonChampionNational = RibbonChampionNational,
|
||||
|
||||
FatefulEncounter = Fateful,
|
||||
Version = GetVersion(SAV),
|
||||
Version = GetVersion(sav),
|
||||
};
|
||||
pk.EXP = Experience.GetEXP(Level, pk.PersonalInfo.EXPGrowth);
|
||||
SetMoves(pk);
|
||||
|
||||
bool hatchedEgg = IsEgg && SAV.Generation != 3;
|
||||
bool hatchedEgg = IsEgg && sav.Generation != 3;
|
||||
if (hatchedEgg)
|
||||
{
|
||||
SetForceHatchDetails(pk, SAV);
|
||||
SetForceHatchDetails(pk, sav);
|
||||
}
|
||||
else
|
||||
{
|
||||
pk.OT_Gender = OT_Gender != 3 ? OT_Gender & 1 : SAV.Gender;
|
||||
pk.OT_Gender = OT_Gender != 3 ? OT_Gender & 1 : sav.Gender;
|
||||
pk.TID = TID;
|
||||
pk.SID = SID;
|
||||
|
||||
pk.Language = (int)GetSafeLanguage((LanguageID)SAV.Language);
|
||||
pk.OT_Name = !string.IsNullOrWhiteSpace(OT_Name) ? OT_Name : SAV.OT;
|
||||
pk.Language = (int)GetSafeLanguage((LanguageID)sav.Language);
|
||||
pk.OT_Name = !string.IsNullOrWhiteSpace(OT_Name) ? OT_Name : sav.OT;
|
||||
if (IsEgg)
|
||||
pk.IsEgg = true; // lang should be set to japanese already
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ namespace PKHeX.Core
|
|||
|
||||
// Generate PIDIV
|
||||
SetPINGA(pk, criteria);
|
||||
pk.HeldItem = 0; // clear, only random for Jirachis(?), no loss
|
||||
pk.HeldItem = 0; // clear, only random for Jirachi (?), no loss
|
||||
|
||||
if (Version == GameVersion.XD)
|
||||
pk.FatefulEncounter = true; // pk3 is already converted from xk3
|
||||
|
@ -125,25 +125,25 @@ namespace PKHeX.Core
|
|||
return pk;
|
||||
}
|
||||
|
||||
private static void SetForceHatchDetails(PK3 pk, ITrainerInfo SAV)
|
||||
private static void SetForceHatchDetails(PK3 pk, ITrainerInfo sav)
|
||||
{
|
||||
// ugly workaround for character table interactions
|
||||
pk.Language = (int)LanguageID.English;
|
||||
pk.OT_Name = "PKHeX";
|
||||
pk.OT_Gender = SAV.Gender;
|
||||
pk.TID = SAV.TID;
|
||||
pk.SID = SAV.SID;
|
||||
pk.OT_Gender = sav.Gender;
|
||||
pk.TID = sav.TID;
|
||||
pk.SID = sav.SID;
|
||||
pk.Met_Location = pk.FRLG ? 146 /* Four Island */ : 32; // Route 117
|
||||
pk.FatefulEncounter &= pk.FRLG; // clear flag for RSE
|
||||
pk.Met_Level = 0; // hatched
|
||||
}
|
||||
|
||||
private int GetVersion(ITrainerInfo SAV)
|
||||
private int GetVersion(ITrainerInfo sav)
|
||||
{
|
||||
if (Version != 0)
|
||||
return (int) GetRandomVersion(Version);
|
||||
bool gen3 = SAV.Game <= 15 && GameVersion.Gen3.Contains((GameVersion)SAV.Game);
|
||||
return gen3 ? SAV.Game : (int)GameVersion.R;
|
||||
bool gen3 = sav.Game <= 15 && GameVersion.Gen3.Contains((GameVersion)sav.Game);
|
||||
return gen3 ? sav.Game : (int)GameVersion.R;
|
||||
}
|
||||
|
||||
private void SetMoves(PK3 pk)
|
||||
|
@ -225,7 +225,7 @@ namespace PKHeX.Core
|
|||
var wcOT = OT_Name;
|
||||
if (!string.IsNullOrEmpty(wcOT))
|
||||
{
|
||||
if (wcOT.Length > 7) // Colosseum Mattle Ho-Oh
|
||||
if (wcOT.Length > 7) // Colosseum MATTLE Ho-Oh
|
||||
{
|
||||
if (!GetIsValidOTMattleHoOh(wcOT, pkm.OT_Name, pkm is CK3))
|
||||
return false;
|
||||
|
|
|
@ -265,7 +265,7 @@ namespace PKHeX.Core
|
|||
}
|
||||
}
|
||||
|
||||
public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria)
|
||||
public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)
|
||||
{
|
||||
if (!IsPokémon)
|
||||
throw new ArgumentException(nameof(IsPokémon));
|
||||
|
@ -283,12 +283,12 @@ namespace PKHeX.Core
|
|||
Met_Level = currentLevel,
|
||||
AltForm = Form,
|
||||
EncryptionConstant = EncryptionConstant != 0 ? EncryptionConstant : Util.Rand32(),
|
||||
Version = OriginGame != 0 ? OriginGame : SAV.Game,
|
||||
Language = Language != 0 ? Language : SAV.Language,
|
||||
Version = OriginGame != 0 ? OriginGame : sav.Game,
|
||||
Language = Language != 0 ? Language : sav.Language,
|
||||
Ball = Ball,
|
||||
Country = SAV.Country,
|
||||
Region = SAV.SubRegion,
|
||||
ConsoleRegion = SAV.ConsoleRegion,
|
||||
Country = sav.Country,
|
||||
Region = sav.SubRegion,
|
||||
ConsoleRegion = sav.ConsoleRegion,
|
||||
Move1 = Move1, Move2 = Move2, Move3 = Move3, Move4 = Move4,
|
||||
RelearnMove1 = RelearnMove1, RelearnMove2 = RelearnMove2,
|
||||
RelearnMove3 = RelearnMove3, RelearnMove4 = RelearnMove4,
|
||||
|
@ -301,10 +301,10 @@ namespace PKHeX.Core
|
|||
CNT_Tough = CNT_Tough,
|
||||
CNT_Sheen = CNT_Sheen,
|
||||
|
||||
OT_Name = OT_Name.Length > 0 ? OT_Name : SAV.OT,
|
||||
OT_Gender = OTGender != 3 ? OTGender % 2 : SAV.Gender,
|
||||
HT_Name = OT_Name.Length > 0 ? SAV.OT : string.Empty,
|
||||
HT_Gender = OT_Name.Length > 0 ? SAV.Gender : 0,
|
||||
OT_Name = OT_Name.Length > 0 ? OT_Name : sav.OT,
|
||||
OT_Gender = OTGender != 3 ? OTGender % 2 : sav.Gender,
|
||||
HT_Name = OT_Name.Length > 0 ? sav.OT : string.Empty,
|
||||
HT_Gender = OT_Name.Length > 0 ? sav.Gender : 0,
|
||||
CurrentHandler = OT_Name.Length > 0 ? 1 : 0,
|
||||
|
||||
EXP = Experience.GetEXP(Level, pi.EXPGrowth),
|
||||
|
@ -341,7 +341,7 @@ namespace PKHeX.Core
|
|||
|
||||
pk.MetDate = Date ?? DateTime.Now;
|
||||
|
||||
if ((SAV.Generation > Format && OriginGame == 0) || !CanBeReceivedByVersion(pk.Version))
|
||||
if ((sav.Generation > Format && OriginGame == 0) || !CanBeReceivedByVersion(pk.Version))
|
||||
{
|
||||
// give random valid game
|
||||
do { pk.Version = (int)GameVersion.X + rnd.Next(4); }
|
||||
|
@ -519,7 +519,7 @@ namespace PKHeX.Core
|
|||
switch (CardID)
|
||||
{
|
||||
case 0525 when IV_HP == 0xFE: // Diancie was distributed with no IV enforcement & 3IVs
|
||||
case 0504 when RibbonClassic != ((IRibbonSetEvent4)pkm).RibbonClassic: // magmar with/without classic
|
||||
case 0504 when RibbonClassic != ((IRibbonSetEvent4)pkm).RibbonClassic: // Magmar with/without classic
|
||||
return true;
|
||||
}
|
||||
if (RestrictLanguage != 0 && RestrictLanguage != pkm.Language)
|
||||
|
|
|
@ -308,7 +308,7 @@ namespace PKHeX.Core
|
|||
}
|
||||
}
|
||||
|
||||
public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria)
|
||||
public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)
|
||||
{
|
||||
if (!IsPokémon)
|
||||
throw new ArgumentException(nameof(IsPokémon));
|
||||
|
@ -327,12 +327,12 @@ namespace PKHeX.Core
|
|||
Met_Level = metLevel,
|
||||
AltForm = Form,
|
||||
EncryptionConstant = EncryptionConstant != 0 ? EncryptionConstant : Util.Rand32(),
|
||||
Version = OriginGame != 0 ? OriginGame : SAV.Game,
|
||||
Language = Language != 0 ? Language : SAV.Language,
|
||||
Version = OriginGame != 0 ? OriginGame : sav.Game,
|
||||
Language = Language != 0 ? Language : sav.Language,
|
||||
Ball = Ball,
|
||||
Country = SAV.Country,
|
||||
Region = SAV.SubRegion,
|
||||
ConsoleRegion = SAV.ConsoleRegion,
|
||||
Country = sav.Country,
|
||||
Region = sav.SubRegion,
|
||||
ConsoleRegion = sav.ConsoleRegion,
|
||||
Move1 = Move1, Move2 = Move2, Move3 = Move3, Move4 = Move4,
|
||||
RelearnMove1 = RelearnMove1, RelearnMove2 = RelearnMove2,
|
||||
RelearnMove3 = RelearnMove3, RelearnMove4 = RelearnMove4,
|
||||
|
@ -345,10 +345,10 @@ namespace PKHeX.Core
|
|||
CNT_Tough = CNT_Tough,
|
||||
CNT_Sheen = CNT_Sheen,
|
||||
|
||||
OT_Name = OT_Name.Length > 0 ? OT_Name : SAV.OT,
|
||||
OT_Gender = OTGender != 3 ? OTGender % 2 : SAV.Gender,
|
||||
HT_Name = OT_Name.Length > 0 ? SAV.OT : string.Empty,
|
||||
HT_Gender = OT_Name.Length > 0 ? SAV.Gender : 0,
|
||||
OT_Name = OT_Name.Length > 0 ? OT_Name : sav.OT,
|
||||
OT_Gender = OTGender != 3 ? OTGender % 2 : sav.Gender,
|
||||
HT_Name = OT_Name.Length > 0 ? sav.OT : string.Empty,
|
||||
HT_Gender = OT_Name.Length > 0 ? sav.Gender : 0,
|
||||
CurrentHandler = OT_Name.Length > 0 ? 1 : 0,
|
||||
|
||||
EXP = Experience.GetEXP(currentLevel, pi.EXPGrowth),
|
||||
|
@ -383,7 +383,7 @@ namespace PKHeX.Core
|
|||
};
|
||||
pk.SetMaximumPPCurrent();
|
||||
|
||||
if ((SAV.Generation > Format && OriginGame == 0) || !CanBeReceivedByVersion(pk.Version))
|
||||
if ((sav.Generation > Format && OriginGame == 0) || !CanBeReceivedByVersion(pk.Version))
|
||||
{
|
||||
// give random valid game
|
||||
do { pk.Version = (int)GameVersion.SN + rnd.Next(4); }
|
||||
|
@ -392,8 +392,8 @@ namespace PKHeX.Core
|
|||
|
||||
if (OTGender == 3)
|
||||
{
|
||||
pk.TID = SAV.TID;
|
||||
pk.SID = SAV.SID;
|
||||
pk.TID = sav.TID;
|
||||
pk.SID = sav.SID;
|
||||
}
|
||||
|
||||
pk.MetDate = Date ?? DateTime.Now;
|
||||
|
@ -530,7 +530,7 @@ namespace PKHeX.Core
|
|||
}
|
||||
else if (PIDType == 0 && pkm.IsShiny)
|
||||
{
|
||||
return false; // can't be traded away for unshiny
|
||||
return false; // can't be traded away for un-shiny
|
||||
}
|
||||
|
||||
if (pkm.IsEgg && !pkm.IsNative)
|
||||
|
|
|
@ -296,7 +296,7 @@ namespace PKHeX.Core
|
|||
|
||||
private bool IsHOMEGift => PIDType == Shiny.FixedValue && PID == 0 && EncryptionConstant == 0;
|
||||
|
||||
public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria)
|
||||
public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)
|
||||
{
|
||||
if (!IsPokémon)
|
||||
throw new ArgumentException(nameof(IsPokémon));
|
||||
|
@ -304,7 +304,7 @@ namespace PKHeX.Core
|
|||
int currentLevel = Level > 0 ? Level : Util.Rand.Next(1, 101);
|
||||
int metLevel = MetLevel > 0 ? MetLevel : currentLevel;
|
||||
var pi = PersonalTable.SWSH.GetFormeEntry(Species, Form);
|
||||
var OT = GetOT(SAV.Language);
|
||||
var OT = GetOT(sav.Language);
|
||||
|
||||
var pk = new PK8
|
||||
{
|
||||
|
@ -329,13 +329,13 @@ namespace PKHeX.Core
|
|||
RelearnMove3 = RelearnMove3,
|
||||
RelearnMove4 = RelearnMove4,
|
||||
|
||||
Version = OriginGame != 0 ? OriginGame : SAV.Game,
|
||||
Version = OriginGame != 0 ? OriginGame : sav.Game,
|
||||
|
||||
OT_Name = OT.Length > 0 ? OT : SAV.OT,
|
||||
OT_Gender = OTGender < 2 ? OTGender : SAV.Gender,
|
||||
HT_Name = GetHasOT(Language) ? SAV.OT : string.Empty,
|
||||
HT_Gender = GetHasOT(Language) ? SAV.Gender : 0,
|
||||
HT_Language = GetHasOT(Language) ? SAV.Language : 0,
|
||||
OT_Name = OT.Length > 0 ? OT : sav.OT,
|
||||
OT_Gender = OTGender < 2 ? OTGender : sav.Gender,
|
||||
HT_Name = GetHasOT(Language) ? sav.OT : string.Empty,
|
||||
HT_Gender = GetHasOT(Language) ? sav.Gender : 0,
|
||||
HT_Language = GetHasOT(Language) ? sav.Language : 0,
|
||||
CurrentHandler = GetHasOT(Language) ? 1 : 0,
|
||||
OT_Friendship = pi.BaseFriendship,
|
||||
|
||||
|
@ -355,7 +355,7 @@ namespace PKHeX.Core
|
|||
};
|
||||
pk.SetMaximumPPCurrent();
|
||||
|
||||
if ((SAV.Generation > Format && OriginGame == 0) || !CanBeReceivedByVersion(pk.Version))
|
||||
if ((sav.Generation > Format && OriginGame == 0) || !CanBeReceivedByVersion(pk.Version))
|
||||
{
|
||||
// give random valid game
|
||||
var rnd = Util.Rand;
|
||||
|
@ -365,8 +365,8 @@ namespace PKHeX.Core
|
|||
|
||||
if (OTGender >= 2)
|
||||
{
|
||||
pk.TID = SAV.TID;
|
||||
pk.SID = SAV.SID;
|
||||
pk.TID = sav.TID;
|
||||
pk.SID = sav.SID;
|
||||
}
|
||||
|
||||
// Official code explicitly corrects for meowstic
|
||||
|
@ -375,8 +375,8 @@ namespace PKHeX.Core
|
|||
|
||||
pk.MetDate = DateTime.Now;
|
||||
|
||||
var nickname_language = GetNicknameLanguage(SAV.Language);
|
||||
pk.Language = nickname_language != 0 ? nickname_language : SAV.Language;
|
||||
var nickname_language = GetNicknameLanguage(sav.Language);
|
||||
pk.Language = nickname_language != 0 ? nickname_language : sav.Language;
|
||||
pk.IsNicknamed = GetIsNicknamed(pk.Language);
|
||||
pk.Nickname = pk.IsNicknamed ? Nickname : SpeciesName.GetSpeciesNameGeneration(Species, pk.Language, Format);
|
||||
|
||||
|
@ -387,7 +387,7 @@ namespace PKHeX.Core
|
|||
pk.SetRibbon(ribbon);
|
||||
}
|
||||
|
||||
SetPINGA(pk, SAV, criteria);
|
||||
SetPINGA(pk, sav, criteria);
|
||||
|
||||
if (IsEgg)
|
||||
SetEggMetData(pk);
|
||||
|
@ -408,7 +408,7 @@ namespace PKHeX.Core
|
|||
pk.IsNicknamed = true;
|
||||
}
|
||||
|
||||
private void SetPINGA(PKM pk, ITrainerInfo SAV, EncounterCriteria criteria)
|
||||
private void SetPINGA(PKM pk, ITrainerInfo sav, EncounterCriteria criteria)
|
||||
{
|
||||
var pi = PersonalTable.SWSH.GetFormeEntry(Species, Form);
|
||||
pk.Nature = (int)criteria.GetNature(Nature == -1 ? Core.Nature.Random : (Nature)Nature);
|
||||
|
@ -416,7 +416,7 @@ namespace PKHeX.Core
|
|||
pk.Gender = criteria.GetGender(Gender, pi);
|
||||
var av = GetAbilityIndex(criteria, pi);
|
||||
pk.RefreshAbility(av);
|
||||
SetPID(pk, SAV);
|
||||
SetPID(pk, sav);
|
||||
SetIVs(pk);
|
||||
}
|
||||
|
||||
|
@ -436,21 +436,21 @@ namespace PKHeX.Core
|
|||
}
|
||||
}
|
||||
|
||||
private uint GetFixedPID(ITrainerInfo SAV)
|
||||
private uint GetFixedPID(ITrainerInfo sav)
|
||||
{
|
||||
uint pid = PID;
|
||||
var val = Data[CardStart + 0x248];
|
||||
if (val == 4)
|
||||
return pid;
|
||||
return (uint)((pid & 0xFFFF) | ((SAV.SID ^ SAV.TID ^ (pid & 0xFFFF) ^ (val == 2 ? 1 : 0)) << 16));
|
||||
return (uint)((pid & 0xFFFF) | ((sav.SID ^ sav.TID ^ (pid & 0xFFFF) ^ (val == 2 ? 1 : 0)) << 16));
|
||||
}
|
||||
|
||||
private void SetPID(PKM pk, ITrainerInfo SAV)
|
||||
private void SetPID(PKM pk, ITrainerInfo sav)
|
||||
{
|
||||
switch (PIDType)
|
||||
{
|
||||
case Shiny.FixedValue: // Specified
|
||||
pk.PID = GetFixedPID(SAV);
|
||||
pk.PID = GetFixedPID(sav);
|
||||
break;
|
||||
case Shiny.Random: // Random
|
||||
pk.PID = Util.Rand32();
|
||||
|
|
|
@ -125,7 +125,7 @@ namespace PKHeX.Core
|
|||
}
|
||||
}
|
||||
|
||||
public override PKM ConvertToPKM(ITrainerInfo SAV, EncounterCriteria criteria)
|
||||
public override PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)
|
||||
{
|
||||
// this method shouldn't really be called, use the WB7 data not the WR7 data.
|
||||
if (!IsPokémon)
|
||||
|
@ -133,8 +133,8 @@ namespace PKHeX.Core
|
|||
|
||||
// we'll just generate something as close as we can, since we must return something!
|
||||
var pk = new PB7();
|
||||
SAV.ApplyToPKM(pk);
|
||||
if (!GameVersion.GG.Contains((GameVersion) SAV.Game))
|
||||
sav.ApplyTo(pk);
|
||||
if (!GameVersion.GG.Contains((GameVersion) sav.Game))
|
||||
pk.Version = (int) GameVersion.GP;
|
||||
|
||||
pk.Species = Species;
|
||||
|
|
|
@ -78,7 +78,7 @@ namespace PKHeX.Core
|
|||
public override int Move4_PP { get => Data[0x86]; set => Data[0x86] = (byte)value; }
|
||||
public override int Move4_PPUps { get => Data[0x87]; set => Data[0x87] = (byte)value; }
|
||||
|
||||
public override int SpriteItem => ItemConverter.GetG4Item((ushort)HeldItem);
|
||||
public override int SpriteItem => ItemConverter.GetItemFuture3((ushort)HeldItem);
|
||||
public override int HeldItem { get => BigEndian.ToUInt16(Data, 0x88); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x88); }
|
||||
|
||||
// More party stats
|
||||
|
|
|
@ -101,7 +101,7 @@ namespace PKHeX.Core
|
|||
public override int Version { get => (int)GameVersion.RBY; set { } }
|
||||
public override int PKRS_Strain { get => 0; set { } }
|
||||
public override int PKRS_Days { get => 0; set { } }
|
||||
public override bool CanHoldItem(IReadOnlyList<ushort> ValidArray) => false;
|
||||
public override bool CanHoldItem(IReadOnlyList<ushort> valid) => false;
|
||||
|
||||
// Maximums
|
||||
public override int MaxMoveID => Legal.MaxMoveID_1;
|
||||
|
@ -116,7 +116,7 @@ namespace PKHeX.Core
|
|||
otname.CopyTo(pk2.otname, 0);
|
||||
nick.CopyTo(pk2.nick, 0);
|
||||
|
||||
pk2.HeldItem = ItemConverter.GetG2ItemTransfer(pk2.HeldItem);
|
||||
pk2.HeldItem = ItemConverter.GetItemFuture1(pk2.HeldItem);
|
||||
pk2.CurrentFriendship = pk2.PersonalInfo.BaseFriendship;
|
||||
pk2.Stat_Level = CurrentLevel;
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace PKHeX.Core
|
|||
|
||||
#region Stored Attributes
|
||||
public override int Species { get => Data[0]; set => Data[0] = (byte)value; }
|
||||
public override int SpriteItem => ItemConverter.GetG4Item((byte)HeldItem);
|
||||
public override int SpriteItem => ItemConverter.GetItemFuture2((byte)HeldItem);
|
||||
public override int HeldItem { get => Data[0x1]; set => Data[0x1] = (byte)value; }
|
||||
public override int Move1 { get => Data[2]; set => Data[2] = (byte)value; }
|
||||
public override int Move2 { get => Data[3]; set => Data[3] = (byte)value; }
|
||||
|
|
|
@ -76,7 +76,7 @@ namespace PKHeX.Core
|
|||
}
|
||||
}
|
||||
|
||||
public override int SpriteItem => ItemConverter.GetG4Item((ushort)HeldItem);
|
||||
public override int SpriteItem => ItemConverter.GetItemFuture3((ushort)HeldItem);
|
||||
public override int HeldItem { get => BitConverter.ToUInt16(Data, 0x22); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x22); }
|
||||
|
||||
public override uint EXP { get => BitConverter.ToUInt32(Data, 0x24); set => BitConverter.GetBytes(value).CopyTo(Data, 0x24); }
|
||||
|
@ -312,7 +312,7 @@ namespace PKHeX.Core
|
|||
|
||||
if (HeldItem > 0)
|
||||
{
|
||||
ushort item = ItemConverter.GetG4Item((ushort)HeldItem);
|
||||
ushort item = ItemConverter.GetItemFuture3((ushort)HeldItem);
|
||||
if (ItemConverter.IsItemTransferable34(item))
|
||||
pk4.HeldItem = item;
|
||||
}
|
||||
|
|
|
@ -630,37 +630,37 @@ namespace PKHeX.Core
|
|||
/// <summary>
|
||||
/// Checks if the <see cref="PKM"/> could inhabit a set of games.
|
||||
/// </summary>
|
||||
/// <param name="Generation">Set of games.</param>
|
||||
/// <param name="generation">Set of games.</param>
|
||||
/// <param name="species"></param>
|
||||
/// <returns>True if could inhabit, False if not.</returns>
|
||||
public bool InhabitedGeneration(int Generation, int species = -1)
|
||||
public bool InhabitedGeneration(int generation, int species = -1)
|
||||
{
|
||||
if (species < 0)
|
||||
species = Species;
|
||||
|
||||
if (Format == Generation)
|
||||
if (Format == generation)
|
||||
return true;
|
||||
|
||||
if (!IsOriginValid)
|
||||
return false;
|
||||
|
||||
// Sanity Check Species ID
|
||||
if (Legal.GetMaxSpeciesOrigin(Generation) < species && !Legal.GetFutureGenEvolutions(Generation).Contains(species))
|
||||
if (Legal.GetMaxSpeciesOrigin(generation) < species && !Legal.GetFutureGenEvolutions(generation).Contains(species))
|
||||
return false;
|
||||
|
||||
// Trade generation 1 -> 2
|
||||
if (Format == 2 && Generation == 1 && !Gen2_NotTradeback)
|
||||
if (Format == 2 && generation == 1 && !Gen2_NotTradeback)
|
||||
return true;
|
||||
|
||||
// Trade generation 2 -> 1
|
||||
if (Format == 1 && Generation == 2 && !Gen1_NotTradeback)
|
||||
if (Format == 1 && generation == 2 && !Gen1_NotTradeback)
|
||||
return true;
|
||||
|
||||
if (Format < Generation)
|
||||
if (Format < generation)
|
||||
return false; // Future
|
||||
|
||||
int gen = GenNumber;
|
||||
return Generation switch
|
||||
return generation switch
|
||||
{
|
||||
1 => (Format == 1 || VC), // species compat checked via sanity above
|
||||
2 => (Format == 2 || VC),
|
||||
|
@ -883,9 +883,9 @@ namespace PKHeX.Core
|
|||
/// <summary>
|
||||
/// Checks if the <see cref="PKM"/> can hold its <see cref="HeldItem"/>.
|
||||
/// </summary>
|
||||
/// <param name="ValidArray">Items that the <see cref="PKM"/> can hold.</param>
|
||||
/// <param name="valid">Items that the <see cref="PKM"/> can hold.</param>
|
||||
/// <returns>True/False if the <see cref="PKM"/> can hold its <see cref="HeldItem"/>.</returns>
|
||||
public virtual bool CanHoldItem(IReadOnlyList<ushort> ValidArray) => ValidArray.Contains((ushort)HeldItem);
|
||||
public virtual bool CanHoldItem(IReadOnlyList<ushort> valid) => valid.Contains((ushort)HeldItem);
|
||||
|
||||
/// <summary>
|
||||
/// Deep clones the <see cref="PKM"/> object. The clone will not have any shared resources with the source.
|
||||
|
@ -923,10 +923,10 @@ namespace PKHeX.Core
|
|||
/// <returns>Amount of PP the move has by default (no PP Ups).</returns>
|
||||
private int GetBasePP(int move)
|
||||
{
|
||||
var pptable = Legal.GetPPTable(this, Format);
|
||||
if (move >= pptable.Count)
|
||||
var table = Legal.GetPPTable(this, Format);
|
||||
if (move >= table.Count)
|
||||
move = 0;
|
||||
return pptable[move];
|
||||
return table[move];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1087,13 +1087,13 @@ namespace PKHeX.Core
|
|||
public void TransferPropertiesWithReflection(PKM Destination)
|
||||
{
|
||||
// Only transfer declared properties not defined in PKM.cs but in the actual type
|
||||
var src_t = GetType();
|
||||
var dst_t = Destination.GetType();
|
||||
var SourceProperties = ReflectUtil.GetAllPropertyInfoPublic(src_t).Select(z => z.Name);
|
||||
var DestinationProperties = ReflectUtil.GetAllPropertyInfoPublic(dst_t).Where(z => z.SetMethod != null).Select(z => z.Name);
|
||||
var srcType = GetType();
|
||||
var destType = Destination.GetType();
|
||||
var srcProperties = ReflectUtil.GetAllPropertyInfoPublic(srcType).Select(z => z.Name);
|
||||
var destProperties = ReflectUtil.GetAllPropertyInfoPublic(destType).Where(z => z.SetMethod != null).Select(z => z.Name);
|
||||
|
||||
// Transfer properties in the order they are defined in the destination PKM format for best conversion
|
||||
var shared = DestinationProperties.Intersect(SourceProperties);
|
||||
var shared = destProperties.Intersect(srcProperties);
|
||||
foreach (string property in shared)
|
||||
{
|
||||
BatchEditing.TryGetHasProperty(this, property, out var src);
|
||||
|
|
|
@ -115,7 +115,7 @@ namespace PKHeX.Core.Searching
|
|||
res = FilterResultEgg(res);
|
||||
|
||||
if (Level != null)
|
||||
res = SearchUtil.FilterByLVL(res, SearchLevel, (int)Level);
|
||||
res = SearchUtil.FilterByLevel(res, SearchLevel, (int)Level);
|
||||
|
||||
if (SearchLegal != null)
|
||||
res = res.Where(pk => new LegalityAnalysis(pk).Valid == SearchLegal);
|
||||
|
@ -135,27 +135,27 @@ namespace PKHeX.Core.Searching
|
|||
return res.Where(pk => pk.IsEgg);
|
||||
}
|
||||
|
||||
public IReadOnlyList<GameVersion> GetVersions(SaveFile SAV) => GetVersions(SAV, GetFallbackVersion(SAV));
|
||||
public IReadOnlyList<GameVersion> GetVersions(SaveFile sav) => GetVersions(sav, GetFallbackVersion(sav));
|
||||
|
||||
public IReadOnlyList<GameVersion> GetVersions(SaveFile SAV, GameVersion fallback)
|
||||
public IReadOnlyList<GameVersion> GetVersions(SaveFile sav, GameVersion fallback)
|
||||
{
|
||||
if (Version > 0)
|
||||
return new[] {(GameVersion) Version};
|
||||
if (Generation != 0)
|
||||
{
|
||||
return fallback.GetGeneration() == Generation
|
||||
? GameUtil.GetVersionsWithinRange(SAV, Generation).ToArray()
|
||||
? GameUtil.GetVersionsWithinRange(sav, Generation).ToArray()
|
||||
: GameUtil.GameVersions;
|
||||
}
|
||||
|
||||
return GameUtil.GameVersions;
|
||||
}
|
||||
|
||||
private static GameVersion GetFallbackVersion(SaveFile SAV)
|
||||
private static GameVersion GetFallbackVersion(ITrainerInfo sav)
|
||||
{
|
||||
var parent = GameUtil.GetMetLocationVersionGroup((GameVersion)SAV.Game);
|
||||
var parent = GameUtil.GetMetLocationVersionGroup((GameVersion)sav.Game);
|
||||
if (parent == GameVersion.Invalid)
|
||||
parent = GameUtil.GetMetLocationVersionGroup(GameUtil.GetVersion(SAV.Generation));
|
||||
parent = GameUtil.GetMetLocationVersionGroup(GameUtil.GetVersion(sav.Generation));
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace PKHeX.Core.Searching
|
|||
|
||||
if (format <= 2) // 1-2
|
||||
return res.Where(pk => pk.Format <= 2);
|
||||
if (format >= 3 && format <= 6) // 3-6
|
||||
if (format <= 6) // 3-6
|
||||
return res.Where(pk => pk.Format >= 3);
|
||||
|
||||
return res;
|
||||
|
@ -42,7 +42,7 @@ namespace PKHeX.Core.Searching
|
|||
};
|
||||
}
|
||||
|
||||
public static IEnumerable<PKM> FilterByLVL(IEnumerable<PKM> res, SearchComparison option, int level)
|
||||
public static IEnumerable<PKM> FilterByLevel(IEnumerable<PKM> res, SearchComparison option, int level)
|
||||
{
|
||||
if (level > 100)
|
||||
return res;
|
||||
|
@ -82,9 +82,9 @@ namespace PKHeX.Core.Searching
|
|||
};
|
||||
}
|
||||
|
||||
public static IEnumerable<PKM> FilterByMoves(IEnumerable<PKM> res, IEnumerable<int> Moves)
|
||||
public static IEnumerable<PKM> FilterByMoves(IEnumerable<PKM> res, IEnumerable<int> requiredMoves)
|
||||
{
|
||||
var moves = new HashSet<int>(Moves);
|
||||
var moves = new HashSet<int>(requiredMoves);
|
||||
int count = moves.Count;
|
||||
return res.Where(pk =>
|
||||
pk.Moves.Where(z => z > 0)
|
||||
|
@ -92,20 +92,20 @@ namespace PKHeX.Core.Searching
|
|||
);
|
||||
}
|
||||
|
||||
public static IEnumerable<PKM> FilterByBatchInstruction(IEnumerable<PKM> res, IList<string> BatchInstructions)
|
||||
public static IEnumerable<PKM> FilterByBatchInstruction(IEnumerable<PKM> res, IList<string> inputInstructions)
|
||||
{
|
||||
if (BatchInstructions.All(string.IsNullOrWhiteSpace))
|
||||
if (inputInstructions.All(string.IsNullOrWhiteSpace))
|
||||
return res; // none specified;
|
||||
|
||||
var lines = BatchInstructions.Where(z => !string.IsNullOrWhiteSpace(z));
|
||||
var lines = inputInstructions.Where(z => !string.IsNullOrWhiteSpace(z));
|
||||
var filters = StringInstruction.GetFilters(lines).ToArray();
|
||||
BatchEditing.ScreenStrings(filters);
|
||||
return res.Where(pkm => BatchEditing.IsFilterMatch(filters, pkm)); // Compare across all filters
|
||||
}
|
||||
|
||||
public static Func<PKM, string> GetCloneDetectMethod(CloneDetectionMethod Clones)
|
||||
public static Func<PKM, string> GetCloneDetectMethod(CloneDetectionMethod method)
|
||||
{
|
||||
return Clones switch
|
||||
return method switch
|
||||
{
|
||||
CloneDetectionMethod.HashPID => HashByPID,
|
||||
_ => HashByDetails,
|
||||
|
|
|
@ -15,13 +15,13 @@ namespace PKHeX.Core
|
|||
/// <param name="data">Encoded data</param>
|
||||
/// <param name="generation">Generation string format</param>
|
||||
/// <param name="jp">Encoding is Japanese</param>
|
||||
/// <param name="bigendian">Encoding is BigEndian</param>
|
||||
/// <param name="isBigEndian">Encoding is Big Endian</param>
|
||||
/// <param name="count">Length of data to read.</param>
|
||||
/// <param name="offset">Offset to read from</param>
|
||||
/// <returns>Decoded string.</returns>
|
||||
public static string GetString(byte[] data, int generation, bool jp, bool bigendian, int count, int offset = 0)
|
||||
public static string GetString(byte[] data, int generation, bool jp, bool isBigEndian, int count, int offset = 0)
|
||||
{
|
||||
if (bigendian)
|
||||
if (isBigEndian)
|
||||
return generation == 3 ? StringConverter3.GetBEString3(data, offset, count) : StringConverter4.GetBEString4(data, offset, count);
|
||||
|
||||
switch (generation)
|
||||
|
@ -42,15 +42,15 @@ namespace PKHeX.Core
|
|||
/// <param name="value">Decoded string.</param>
|
||||
/// <param name="generation">Generation string format</param>
|
||||
/// <param name="jp">Encoding is Japanese</param>
|
||||
/// <param name="bigendian">Encoding is BigEndian</param>
|
||||
/// <param name="isBigEndian">Encoding is Big Endian</param>
|
||||
/// <param name="maxLength"></param>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="padTo">Pad to given length</param>
|
||||
/// <param name="padWith">Pad with value</param>
|
||||
/// <returns>Encoded data.</returns>
|
||||
public static byte[] SetString(string value, int generation, bool jp, bool bigendian, int maxLength, int language = 0, int padTo = 0, ushort padWith = 0)
|
||||
public static byte[] SetString(string value, int generation, bool jp, bool isBigEndian, int maxLength, int language = 0, int padTo = 0, ushort padWith = 0)
|
||||
{
|
||||
if (bigendian)
|
||||
if (isBigEndian)
|
||||
return generation == 3 ? StringConverter3.SetBEString3(value, maxLength, padTo, padWith) : StringConverter4.SetBEString4(value, maxLength, padTo, padWith);
|
||||
|
||||
switch (generation)
|
||||
|
@ -168,36 +168,35 @@ namespace PKHeX.Core
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Unicode string to Generation 7 in-game chinese string.
|
||||
/// Converts a Unicode string to Generation 7 in-game Chinese string.
|
||||
/// </summary>
|
||||
/// <param name="inputstr">Unicode string.</param>
|
||||
/// <param name="input">Unicode string.</param>
|
||||
/// <param name="lang">Detection of language for Traditional Chinese check</param>
|
||||
/// <returns>In-game chinese string.</returns>
|
||||
private static string ConvertString2BinG7_zh(string inputstr, int lang)
|
||||
/// <returns>In-game Chinese string.</returns>
|
||||
private static string ConvertString2BinG7_zh(string input, int lang)
|
||||
{
|
||||
var str = new StringBuilder();
|
||||
|
||||
bool cht = lang == 10;
|
||||
// A string cannot contain a mix of CHS and CHT characters.
|
||||
bool IsCHT = inputstr.Any(chr => G7_CHT.ContainsKey(chr) && !G7_CHS.ContainsKey(chr));
|
||||
IsCHT |= cht && !inputstr.Any(chr => G7_CHT.ContainsKey(chr) ^ G7_CHS.ContainsKey(chr)); // CHS and CHT have the same display name
|
||||
var table = IsCHT ? G7_CHT : G7_CHS;
|
||||
bool traditional = input.Any(chr => G7_CHT.ContainsKey(chr) && !G7_CHS.ContainsKey(chr))
|
||||
|| (lang == 10 && !input.Any(chr => G7_CHT.ContainsKey(chr) ^ G7_CHS.ContainsKey(chr))); // CHS and CHT have the same display name
|
||||
var table = traditional ? G7_CHT : G7_CHS;
|
||||
|
||||
foreach (char chr in inputstr)
|
||||
foreach (char chr in input)
|
||||
str.Append(table.TryGetValue(chr, out int index) ? (char)(index + Gen7_ZH_Ofs) : chr);
|
||||
return str.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Generation 7 in-game chinese string to Unicode string.
|
||||
/// Converts a Generation 7 in-game Chinese string to Unicode string.
|
||||
/// </summary>
|
||||
/// <param name="inputstr">In-game chinese string.</param>
|
||||
/// <param name="input">In-game Chinese string.</param>
|
||||
/// <returns>Unicode string.</returns>
|
||||
private static string ConvertBin2StringG7_zh(string inputstr)
|
||||
private static string ConvertBin2StringG7_zh(string input)
|
||||
{
|
||||
var str = new StringBuilder();
|
||||
foreach (var val in inputstr)
|
||||
str.Append((char)Getg7zhChar(val));
|
||||
foreach (var val in input)
|
||||
str.Append((char)GetGen7ChineseChar(val));
|
||||
return str.ToString();
|
||||
}
|
||||
|
||||
|
@ -206,7 +205,7 @@ namespace PKHeX.Core
|
|||
/// </summary>
|
||||
/// <param name="val">Input value to shift</param>
|
||||
/// <returns>Shifted character</returns>
|
||||
private static ushort Getg7zhChar(ushort val)
|
||||
private static ushort GetGen7ChineseChar(ushort val)
|
||||
{
|
||||
if (Gen7_ZH_Ofs <= val && val < Gen7_ZH_Ofs + Gen7_ZH.Length)
|
||||
return Gen7_ZH[val - Gen7_ZH_Ofs];
|
||||
|
@ -240,7 +239,7 @@ namespace PKHeX.Core
|
|||
{
|
||||
if (str.Length == 0)
|
||||
return str;
|
||||
var s = str.Replace('’', '\''); // farfetch'd
|
||||
var s = str.Replace('’', '\''); // Farfetch'd
|
||||
|
||||
// remap custom glyphs to unicode
|
||||
s = s.Replace('\uE08F', '♀'); // ♀ (gen6+)
|
||||
|
@ -257,7 +256,7 @@ namespace PKHeX.Core
|
|||
private static string UnSanitizeString7b(string str)
|
||||
{
|
||||
// gender chars always full width
|
||||
return str.Replace('\'', '’'); // farfetch'd
|
||||
return str.Replace('\'', '’'); // Farfetch'd
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -270,7 +269,7 @@ namespace PKHeX.Core
|
|||
{
|
||||
var s = str;
|
||||
if (generation >= 6)
|
||||
s = str.Replace('\'', '’'); // farfetch'd
|
||||
s = str.Replace('\'', '’'); // Farfetch'd
|
||||
|
||||
if (generation <= 5)
|
||||
{
|
||||
|
@ -278,8 +277,8 @@ namespace PKHeX.Core
|
|||
return s.Replace('\u2642', '\u246D'); // ♂
|
||||
}
|
||||
|
||||
var langcontext = str.Except(FullToHalf);
|
||||
bool fullwidth = langcontext.Select(c => c >> 12) // select the group the char belongs to
|
||||
var context = str.Except(FullToHalf);
|
||||
bool fullwidth = context.Select(c => c >> 12) // select the group the char belongs to
|
||||
.Any(c => c != 0 /* Latin */ && c != 0xE /* Special Symbols */);
|
||||
|
||||
if (fullwidth) // jp/ko/zh strings
|
||||
|
|
|
@ -27,26 +27,26 @@ namespace PKHeX.Core
|
|||
/// <summary>
|
||||
/// Checks if the input byte array is definitely of German origin (any ÄÖÜäöü)
|
||||
/// </summary>
|
||||
/// <param name="data">Input string</param>
|
||||
/// <param name="value">Input string</param>
|
||||
/// <returns>Indication if the data is from a definitely-german string</returns>
|
||||
public static bool IsG12German(string data) => IsG12German(SetString1(data, data.Length, false));
|
||||
public static bool IsG12German(string value) => IsG12German(SetString1(value, value.Length, false));
|
||||
|
||||
/// <summary>
|
||||
/// Converts Generation 1 encoded data into a string.
|
||||
/// </summary>
|
||||
/// <param name="strdata">Encoded data.</param>
|
||||
/// <param name="data">Encoded data.</param>
|
||||
/// <param name="offset">Offset to read from</param>
|
||||
/// <param name="count"></param>
|
||||
/// <param name="jp">Data source is Japanese.</param>
|
||||
/// <returns>Decoded string.</returns>
|
||||
public static string GetString1(byte[] strdata, int offset, int count, bool jp)
|
||||
public static string GetString1(byte[] data, int offset, int count, bool jp)
|
||||
{
|
||||
var dict = jp ? RBY2U_J : RBY2U_U;
|
||||
|
||||
var s = new StringBuilder();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var val = strdata[offset + i];
|
||||
var val = data[offset + i];
|
||||
if (!dict.TryGetValue(val, out var c)) // Take valid values
|
||||
break;
|
||||
if (c == '\0') // Stop if Terminator
|
||||
|
@ -59,13 +59,13 @@ namespace PKHeX.Core
|
|||
/// <summary>
|
||||
/// Converts Generation 1 encoded data the same way Bank converts.
|
||||
/// </summary>
|
||||
/// <param name="strdata">Generation 1 encoded data.</param>
|
||||
/// <param name="data">Generation 1 encoded data.</param>
|
||||
/// <param name="jp">Data source is Japanese.</param>
|
||||
/// <returns>Decoded string.</returns>
|
||||
public static string GetG1ConvertedString(byte[] strdata, bool jp)
|
||||
public static string GetG1ConvertedString(byte[] data, bool jp)
|
||||
{
|
||||
var table = jp ? jp_table : us_table;
|
||||
return string.Concat(strdata.TakeWhile(b => b != 0).Select(b => (char)table[b]).TakeWhile(b => b != 0));
|
||||
return string.Concat(data.TakeWhile(b => b != 0).Select(b => (char)table[b]).TakeWhile(b => b != 0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -16,19 +16,19 @@ namespace PKHeX.Core
|
|||
/// <summary>
|
||||
/// Converts Generation 2 Korean encoded data into a string.
|
||||
/// </summary>
|
||||
/// <param name="strdata">Encoded data.</param>
|
||||
/// <param name="data">Encoded data.</param>
|
||||
/// <param name="offset">Offset to read from</param>
|
||||
/// <param name="count"></param>
|
||||
/// <returns>Decoded string.</returns>
|
||||
public static string GetString2KOR(byte[] strdata, int offset, int count)
|
||||
public static string GetString2KOR(byte[] data, int offset, int count)
|
||||
{
|
||||
var s = new StringBuilder();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var val = strdata[offset + i];
|
||||
var val = data[offset + i];
|
||||
var dict = val <= 0xB ? GSC2U_KOR[val] : RBY2U_U;
|
||||
if (val <= 0xB && val != 0)
|
||||
val = strdata[offset + ++i];
|
||||
val = data[offset + ++i];
|
||||
if (!dict.TryGetValue(val, out var c)) // Take valid values
|
||||
break;
|
||||
if (c == '\0') // Stop if Terminator
|
||||
|
|
|
@ -11,17 +11,17 @@ namespace PKHeX.Core
|
|||
/// <summary>
|
||||
/// Converts a Generation 3 encoded value array to string.
|
||||
/// </summary>
|
||||
/// <param name="strdata">Byte array containing string data.</param>
|
||||
/// <param name="data">Byte array containing string data.</param>
|
||||
/// <param name="offset">Offset to read from</param>
|
||||
/// <param name="count">Length of data to read.</param>
|
||||
/// <param name="jp">Value source is Japanese font.</param>
|
||||
/// <returns>Decoded string.</returns>
|
||||
public static string GetString3(byte[] strdata, int offset, int count, bool jp)
|
||||
public static string GetString3(byte[] data, int offset, int count, bool jp)
|
||||
{
|
||||
var s = new StringBuilder();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var val = strdata[offset + i];
|
||||
var val = data[offset + i];
|
||||
var c = GetG3Char(val, jp); // Convert to Unicode
|
||||
if (c == 0xFF) // Stop if Terminator/Invalid
|
||||
break;
|
||||
|
@ -43,30 +43,30 @@ namespace PKHeX.Core
|
|||
{
|
||||
if (value.Length > maxLength)
|
||||
value = value.Substring(0, maxLength); // Hard cap
|
||||
var strdata = new byte[value.Length + 1]; // +1 for 0xFF
|
||||
var data = new byte[value.Length + 1]; // +1 for 0xFF
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
{
|
||||
var chr = value[i];
|
||||
var val = SetG3Char(chr, jp);
|
||||
if (val == 0xFF) // end
|
||||
{
|
||||
Array.Resize(ref strdata, i + 1);
|
||||
Array.Resize(ref data, i + 1);
|
||||
break;
|
||||
}
|
||||
strdata[i] = val;
|
||||
data[i] = val;
|
||||
}
|
||||
if (strdata.Length > 0)
|
||||
strdata[strdata.Length - 1] = 0xFF;
|
||||
if (strdata.Length > maxLength && padTo <= maxLength)
|
||||
Array.Resize(ref strdata, maxLength);
|
||||
if (strdata.Length < padTo)
|
||||
if (data.Length > 0)
|
||||
data[data.Length - 1] = 0xFF;
|
||||
if (data.Length > maxLength && padTo <= maxLength)
|
||||
Array.Resize(ref data, maxLength);
|
||||
if (data.Length < padTo)
|
||||
{
|
||||
var start = strdata.Length;
|
||||
Array.Resize(ref strdata, padTo);
|
||||
for (int i = start; i < strdata.Length; i++)
|
||||
strdata[i] = (byte)padWith;
|
||||
var start = data.Length;
|
||||
Array.Resize(ref data, padTo);
|
||||
for (int i = start; i < data.Length; i++)
|
||||
data[i] = (byte)padWith;
|
||||
}
|
||||
return strdata;
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>Converts Big Endian encoded data to decoded string.</summary>
|
||||
|
@ -79,7 +79,7 @@ namespace PKHeX.Core
|
|||
return Util.TrimFromZero(Encoding.BigEndianUnicode.GetString(data, offset, count));
|
||||
}
|
||||
|
||||
/// <summary>Gets the bytes for a BigEndian string.</summary>
|
||||
/// <summary>Gets the bytes for a Big Endian string.</summary>
|
||||
/// <param name="value">Decoded string.</param>
|
||||
/// <param name="maxLength">Maximum length</param>
|
||||
/// <param name="padTo">Pad to given length</param>
|
||||
|
|
|
@ -26,8 +26,14 @@ namespace PKHeX.Core
|
|||
|
||||
public static string TransferGlyphs56(string str)
|
||||
{
|
||||
static char translate(char c) => Glyph56.TryGetValue(c, out var result) ? result : c;
|
||||
return string.Concat(str.Select(translate));
|
||||
var result = new char[str.Length];
|
||||
var table = Glyph56;
|
||||
for (int i = 0; i < str.Length; i++)
|
||||
{
|
||||
var c = str[i];
|
||||
result[i] = table.TryGetValue(c, out var translated) ? translated : c;
|
||||
}
|
||||
return new string(result);
|
||||
}
|
||||
|
||||
private static readonly Dictionary<char, char> Glyph56 = new Dictionary<char, char>
|
||||
|
|
|
@ -45,29 +45,29 @@ namespace PKHeX.Core
|
|||
.PadRight(value.Length + 1, (char)0xFFFF) // Null Terminator
|
||||
.PadRight(padTo, (char)padWith); // Padding
|
||||
|
||||
var strdata = new byte[temp.Length * 2];
|
||||
var data = new byte[temp.Length * 2];
|
||||
for (int i = 0; i < temp.Length; i++)
|
||||
{
|
||||
var chr = temp[i];
|
||||
var val = ConvertChar2ValueG4(chr);
|
||||
BitConverter.GetBytes(val).CopyTo(strdata, i * 2);
|
||||
BitConverter.GetBytes(val).CopyTo(data, i * 2);
|
||||
}
|
||||
return strdata;
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts Generation 4 Big Endian encoded character data to string.
|
||||
/// </summary>
|
||||
/// <param name="strdata">Byte array containing encoded character data.</param>
|
||||
/// <param name="data">Byte array containing encoded character data.</param>
|
||||
/// <param name="offset">Offset to read from</param>
|
||||
/// <param name="count">Length of data to read.</param>
|
||||
/// <returns>Converted string.</returns>
|
||||
public static string GetBEString4(byte[] strdata, int offset, int count)
|
||||
public static string GetBEString4(byte[] data, int offset, int count)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
for (int i = 0; i < count; i += 2)
|
||||
{
|
||||
var val = BigEndian.ToUInt16(strdata, offset + i);
|
||||
var val = BigEndian.ToUInt16(data, offset + i);
|
||||
if (val == 0xFFFF)
|
||||
break;
|
||||
var chr = ConvertValue2CharG4(val);
|
||||
|
@ -95,14 +95,14 @@ namespace PKHeX.Core
|
|||
.PadRight(value.Length + 1, (char)0xFFFF) // Null Terminator
|
||||
.PadRight(padTo, (char)padWith); // Padding
|
||||
|
||||
var strdata = new byte[temp.Length * 2];
|
||||
var data = new byte[temp.Length * 2];
|
||||
for (int i = 0; i < temp.Length; i++)
|
||||
{
|
||||
var chr = temp[i];
|
||||
var val = ConvertChar2ValueG4(chr);
|
||||
BigEndian.GetBytes(val).CopyTo(strdata, i * 2);
|
||||
BigEndian.GetBytes(val).CopyTo(data, i * 2);
|
||||
}
|
||||
return strdata;
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -958,7 +958,7 @@ namespace PKHeX.Core
|
|||
// iterate downwards using form0 as pattern ref, replacing on final loop
|
||||
for (int i = deco - 1; i >= 0; i--)
|
||||
{
|
||||
result[start + i] = $"{result[start]} ({((AlcremieDecoration)i).ToString()})";
|
||||
result[start + i] = $"{result[start]} ({(AlcremieDecoration)i})";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,40 +21,40 @@ namespace PKHeX.Core
|
|||
/// <summary>
|
||||
/// Converts a Generation 3 Item ID to Generation 4+ Item ID.
|
||||
/// </summary>
|
||||
/// <param name="g3val">Generation 3 Item ID.</param>
|
||||
/// <param name="item">Generation 3 Item ID.</param>
|
||||
/// <returns>Generation 4+ Item ID.</returns>
|
||||
internal static ushort GetG4Item(ushort g3val) => g3val > arr3.Length ? NaN : arr3[g3val];
|
||||
internal static ushort GetItemFuture3(ushort item) => item > arr3.Length ? NaN : arr3[item];
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Generation 2 Item ID to Generation 4+ Item ID.
|
||||
/// </summary>
|
||||
/// <param name="g2val">Generation 2 Item ID.</param>
|
||||
/// <param name="item">Generation 2 Item ID.</param>
|
||||
/// <returns>Generation 4+ Item ID.</returns>
|
||||
internal static ushort GetG4Item(byte g2val) => g2val > arr2.Length ? NaN : arr2[g2val];
|
||||
internal static ushort GetItemFuture2(byte item) => item > arr2.Length ? NaN : arr2[item];
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Generation 4+ Item ID to Generation 3 Item ID.
|
||||
/// </summary>
|
||||
/// <param name="g4val">Generation 4+ Item ID.</param>
|
||||
/// <param name="item">Generation 4+ Item ID.</param>
|
||||
/// <returns>Generation 3 Item ID.</returns>
|
||||
private static ushort GetG3Item(ushort g4val)
|
||||
private static ushort GetItemOld3(ushort item)
|
||||
{
|
||||
if (g4val == NaN)
|
||||
if (item == NaN)
|
||||
return 0;
|
||||
int index = Array.IndexOf(arr3, g4val);
|
||||
int index = Array.IndexOf(arr3, item);
|
||||
return (ushort)Math.Max(0, index);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Generation 4+ Item ID to Generation 2 Item ID.
|
||||
/// </summary>
|
||||
/// <param name="g4val">Generation 4+ Item ID.</param>
|
||||
/// <param name="item">Generation 4+ Item ID.</param>
|
||||
/// <returns>Generation 2 Item ID.</returns>
|
||||
private static byte GetG2Item(ushort g4val)
|
||||
private static byte GetItemOld2(ushort item)
|
||||
{
|
||||
if (g4val == NaN)
|
||||
if (item == NaN)
|
||||
return 0;
|
||||
int index = Array.IndexOf(arr2, g4val);
|
||||
int index = Array.IndexOf(arr2, item);
|
||||
return (byte)Math.Max(0, index);
|
||||
}
|
||||
|
||||
|
@ -134,12 +134,12 @@ namespace PKHeX.Core
|
|||
/// <summary>
|
||||
/// Converts a Generation 1 (Teru-sama) Item ID to Generation 2 Item ID.
|
||||
/// </summary>
|
||||
/// <param name="g1val">Gen1 Item ID</param>
|
||||
/// <param name="value">Gen1 Item ID</param>
|
||||
/// <returns>Gen2 Item ID</returns>
|
||||
/// <remarks>https://github.com/pret/pokecrystal/blob/edb624c20ceb50eef9d73a5df0ac041cc156dd32/engine/link/link.asm#L1093-L1115</remarks>
|
||||
private static int GetTeruSamaItem(int g1val)
|
||||
private static int GetTeruSamaItem(int value)
|
||||
{
|
||||
switch (g1val)
|
||||
switch (value)
|
||||
{
|
||||
case 0x19: return 0x92; // Leftovers
|
||||
case 0x2D: return 0x53; // Bitter Berry
|
||||
|
@ -156,15 +156,20 @@ namespace PKHeX.Core
|
|||
case 0xFF:
|
||||
return 0xAD; // Berry
|
||||
|
||||
default: return g1val;
|
||||
default: return value;
|
||||
}
|
||||
}
|
||||
|
||||
internal static int GetG2ItemTransfer(int g1val)
|
||||
/// <summary>
|
||||
/// Converts a Gen1 Item to Gen2 Item.
|
||||
/// </summary>
|
||||
/// <param name="value">Gen1 Item</param>
|
||||
/// <returns>Gen2 Item</returns>
|
||||
internal static int GetItemFuture1(int value)
|
||||
{
|
||||
if (!IsItemTransferable12((ushort) g1val))
|
||||
return GetTeruSamaItem(g1val);
|
||||
return g1val;
|
||||
if (!IsItemTransferable12((ushort) value))
|
||||
return GetTeruSamaItem(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
private static bool IsItemTransferable12(ushort item) => ((IList<ushort>) Legal.HeldItems_GSC).Contains(item);
|
||||
|
@ -172,38 +177,39 @@ namespace PKHeX.Core
|
|||
/// <summary>
|
||||
/// Gets a format specific <see cref="PKM.HeldItem"/> value depending on the desired format and the provided item index & origin format.
|
||||
/// </summary>
|
||||
/// <param name="item">Held Item to apply</param>
|
||||
/// <param name="srcItem">Held Item to apply</param>
|
||||
/// <param name="srcFormat">Format from importing</param>
|
||||
/// <param name="destFormat">Format required for holder</param>
|
||||
internal static int GetFormatHeldItemID(int item, int srcFormat, int destFormat)
|
||||
/// <returns>destItem</returns>
|
||||
internal static int GetItemForFormat(int srcItem, int srcFormat, int destFormat)
|
||||
{
|
||||
if (item <= 0)
|
||||
if (srcItem <= 0)
|
||||
return 0;
|
||||
|
||||
if (destFormat == srcFormat)
|
||||
return item;
|
||||
return srcItem;
|
||||
|
||||
if (destFormat != srcFormat && srcFormat <= 3) // past gen items
|
||||
{
|
||||
if (destFormat > 3) // try remapping
|
||||
return srcFormat == 2 ? GetG4Item((byte)item) : GetG4Item((ushort)item);
|
||||
return srcFormat == 2 ? GetItemFuture2((byte)srcItem) : GetItemFuture3((ushort)srcItem);
|
||||
|
||||
if (destFormat > srcFormat) // can't set past gen items
|
||||
return 0;
|
||||
|
||||
// ShowdownSet checks gen3 then gen2. For gen2 collisions (if any?) remap 3->4->2.
|
||||
item = GetG4Item((ushort)item);
|
||||
item = GetG2Item((ushort)item);
|
||||
if (item <= 0)
|
||||
srcItem = GetItemFuture3((ushort)srcItem);
|
||||
srcItem = GetItemOld2((ushort)srcItem);
|
||||
if (srcItem <= 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return destFormat switch
|
||||
{
|
||||
1 => 0,
|
||||
2 => (byte) item,
|
||||
3 => GetG3Item((ushort) item),
|
||||
_ => item
|
||||
2 => (byte) srcItem,
|
||||
3 => GetItemOld3((ushort) srcItem),
|
||||
_ => srcItem
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -111,11 +111,11 @@ namespace PKHeX.Core
|
|||
switch (format)
|
||||
{
|
||||
case 1:
|
||||
var PL1 = new PokeList1(data);
|
||||
return PL1[0];
|
||||
var list1 = new PokeList1(data);
|
||||
return list1[0];
|
||||
case 2:
|
||||
var PL2 = new PokeList2(data);
|
||||
return PL2[0];
|
||||
var list2 = new PokeList2(data);
|
||||
return list2[0];
|
||||
case 3:
|
||||
return data.Length switch
|
||||
{
|
||||
|
@ -223,24 +223,24 @@ namespace PKHeX.Core
|
|||
/// Converts a PKM from one Generation format to another. If it matches the destination format, the conversion will automatically return.
|
||||
/// </summary>
|
||||
/// <param name="pk">PKM to convert</param>
|
||||
/// <param name="PKMType">Format/Type to convert to</param>
|
||||
/// <param name="destType">Format/Type to convert to</param>
|
||||
/// <param name="comment">Comments regarding the transfer's success/failure</param>
|
||||
/// <returns>Converted PKM</returns>
|
||||
public static PKM? ConvertToType(PKM pk, Type PKMType, out string comment)
|
||||
public static PKM? ConvertToType(PKM pk, Type destType, out string comment)
|
||||
{
|
||||
Type fromType = pk.GetType();
|
||||
if (fromType == PKMType)
|
||||
if (fromType == destType)
|
||||
{
|
||||
comment = "No need to convert, current format matches requested format.";
|
||||
return pk;
|
||||
}
|
||||
|
||||
var pkm = ConvertPKM(pk, PKMType, fromType, out comment);
|
||||
var pkm = ConvertPKM(pk, destType, fromType, out comment);
|
||||
if (!AllowIncompatibleConversion || pkm != null)
|
||||
return pkm;
|
||||
|
||||
// Try Incompatible Conversion
|
||||
pkm = GetBlank(PKMType);
|
||||
pkm = GetBlank(destType);
|
||||
pk.TransferPropertiesWithReflection(pkm);
|
||||
if (!IsPKMCompatibleWithModifications(pkm))
|
||||
return null;
|
||||
|
@ -248,54 +248,54 @@ namespace PKHeX.Core
|
|||
return pkm;
|
||||
}
|
||||
|
||||
private static PKM? ConvertPKM(PKM pk, Type PKMType, Type fromType, out string comment)
|
||||
private static PKM? ConvertPKM(PKM pk, Type destType, Type srcType, out string comment)
|
||||
{
|
||||
if (IsNotTransferable(pk, out comment))
|
||||
return null;
|
||||
|
||||
string toName = PKMType.Name;
|
||||
string fromName = fromType.Name;
|
||||
Debug.WriteLine($"Trying to convert {fromName} to {toName}.");
|
||||
string destName = destType.Name;
|
||||
string srcName = srcType.Name;
|
||||
Debug.WriteLine($"Trying to convert {srcName} to {destName}.");
|
||||
|
||||
int toFormat = toName.Last() - '0';
|
||||
var pkm = ConvertPKM(pk, PKMType, toFormat, ref comment);
|
||||
int destGeneration = destName.Last() - '0';
|
||||
var pkm = ConvertPKM(pk, destType, destGeneration, ref comment);
|
||||
var msg = pkm == null ? MsgPKMConvertFailFormat : MsgPKMConvertSuccess;
|
||||
var formatted = string.Format(msg, fromName, toName);
|
||||
var formatted = string.Format(msg, srcName, destName);
|
||||
comment = comment == null ? formatted : string.Concat(formatted, Environment.NewLine, comment);
|
||||
return pkm;
|
||||
}
|
||||
|
||||
private static PKM? ConvertPKM(PKM pk, Type PKMType, int toFormat, ref string comment)
|
||||
private static PKM? ConvertPKM(PKM pk, Type destType, int destGeneration, ref string comment)
|
||||
{
|
||||
PKM? pkm = pk.Clone();
|
||||
if (pkm.IsEgg)
|
||||
pkm.ForceHatchPKM();
|
||||
while (true)
|
||||
{
|
||||
pkm = IntermediaryConvert(pkm, PKMType, toFormat, ref comment);
|
||||
pkm = IntermediaryConvert(pkm, destType, destGeneration, ref comment);
|
||||
if (pkm == null) // fail convert
|
||||
return null;
|
||||
if (pkm.GetType() == PKMType) // finish convert
|
||||
if (pkm.GetType() == destType) // finish convert
|
||||
return pkm;
|
||||
}
|
||||
}
|
||||
|
||||
private static PKM? IntermediaryConvert(PKM pk, Type PKMType, int toFormat, ref string comment)
|
||||
private static PKM? IntermediaryConvert(PKM pk, Type destType, int destGeneration, ref string comment)
|
||||
{
|
||||
switch (pk)
|
||||
{
|
||||
// Non-sequential
|
||||
case PK1 pk1 when toFormat > 2: return pk1.ConvertToPK7();
|
||||
case PK2 pk2 when toFormat > 2: return pk2.ConvertToPK7();
|
||||
case PK3 pk3 when PKMType == typeof(CK3): return pk3.ConvertToCK3();
|
||||
case PK3 pk3 when PKMType == typeof(XK3): return pk3.ConvertToXK3();
|
||||
case PK4 pk4 when PKMType == typeof(BK4): return pk4.ConvertToBK4();
|
||||
case PK1 pk1 when destGeneration > 2: return pk1.ConvertToPK7();
|
||||
case PK2 pk2 when destGeneration > 2: return pk2.ConvertToPK7();
|
||||
case PK3 pk3 when destType == typeof(CK3): return pk3.ConvertToCK3();
|
||||
case PK3 pk3 when destType == typeof(XK3): return pk3.ConvertToXK3();
|
||||
case PK4 pk4 when destType == typeof(BK4): return pk4.ConvertToBK4();
|
||||
|
||||
// Invalid
|
||||
case PK2 pk2 when pk.Species > Legal.MaxSpeciesID_1:
|
||||
var lang = pk2.Japanese ? (int)LanguageID.Japanese : (int)LanguageID.English;
|
||||
var name = SpeciesName.GetSpeciesName(pk2.Species, lang);
|
||||
comment = string.Format(MsgPKMConvertFailFormat, name, PKMType.Name);
|
||||
comment = string.Format(MsgPKMConvertFailFormat, name, destType.Name);
|
||||
return null;
|
||||
|
||||
// Sequential
|
||||
|
@ -411,25 +411,25 @@ namespace PKHeX.Core
|
|||
return true;
|
||||
}
|
||||
|
||||
public static string GetIncompatibleGBMessage(PKM pk, bool destJP)
|
||||
public static string GetIncompatibleGBMessage(PKM pk, bool destJapanese)
|
||||
{
|
||||
var src = destJP ? MsgPKMConvertInternational : MsgPKMConvertJapanese;
|
||||
var dest = !destJP ? MsgPKMConvertInternational : MsgPKMConvertJapanese;
|
||||
var src = destJapanese ? MsgPKMConvertInternational : MsgPKMConvertJapanese;
|
||||
var dest = !destJapanese ? MsgPKMConvertInternational : MsgPKMConvertJapanese;
|
||||
return string.Format(MsgPKMConvertIncompatible, src, pk.GetType().Name, dest);
|
||||
}
|
||||
|
||||
public static bool IsIncompatibleGB(int format, bool destJP, bool srcJP) => format <= 2 && destJP != srcJP;
|
||||
public static bool IsIncompatibleGB(int format, bool destJapanese, bool srcJapanese) => format <= 2 && destJapanese != srcJapanese;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a Blank <see cref="PKM"/> object of the specified type.
|
||||
/// </summary>
|
||||
/// <param name="t">Type of <see cref="PKM"/> instance desired.</param>
|
||||
/// <param name="type">Type of <see cref="PKM"/> instance desired.</param>
|
||||
/// <returns>New instance of a blank <see cref="PKM"/> object.</returns>
|
||||
public static PKM GetBlank(Type t)
|
||||
public static PKM GetBlank(Type type)
|
||||
{
|
||||
var constructors = t.GetTypeInfo().DeclaredConstructors.Where(z => !z.IsStatic);
|
||||
var constructors = type.GetTypeInfo().DeclaredConstructors.Where(z => !z.IsStatic);
|
||||
var argCount = constructors.Min(z => z.GetParameters().Length);
|
||||
return (PKM)Activator.CreateInstance(t, new object[argCount]);
|
||||
return (PKM)Activator.CreateInstance(type, new object[argCount]);
|
||||
}
|
||||
|
||||
public static PKM GetBlank(int gen, GameVersion ver)
|
||||
|
|
|
@ -126,8 +126,7 @@ namespace PKHeX.Core
|
|||
|
||||
int gt = Personal[species].Gender;
|
||||
bool g34 = origin <= 15;
|
||||
bool g5 = 20 <= origin && origin <= 23; // bw/b2w2
|
||||
uint abilBitVal = g5 ? oldPID & 0x0001_0000 : oldPID & 0x0000_0001;
|
||||
uint abilBitVal = g34 ? oldPID & 0x0000_0001 : oldPID & 0x0001_0000;
|
||||
|
||||
bool g3unown = origin <= 5 && species == (int)Species.Unown;
|
||||
bool singleGender = gt == 255 || gt == 254 || gt == 0; // skip gender check
|
||||
|
@ -151,7 +150,7 @@ namespace PKHeX.Core
|
|||
if (abilBitVal != (pid & 0x0000_0001)) // keep ability bits
|
||||
continue;
|
||||
}
|
||||
else if (g5)
|
||||
else
|
||||
{
|
||||
if (abilBitVal != (pid & 0x0001_0000)) // keep ability bits
|
||||
continue;
|
||||
|
@ -182,23 +181,23 @@ namespace PKHeX.Core
|
|||
/// Gets the gender ID of the species based on the Personality ID.
|
||||
/// </summary>
|
||||
/// <param name="species">National Dex ID.</param>
|
||||
/// <param name="PID">Personality ID.</param>
|
||||
/// <param name="pid">Personality ID.</param>
|
||||
/// <returns>Gender ID (0/1/2)</returns>
|
||||
/// <remarks>This method should only be used for Generations 3-5 origin.</remarks>
|
||||
public static int GetGenderFromPID(int species, uint PID)
|
||||
public static int GetGenderFromPID(int species, uint pid)
|
||||
{
|
||||
int gt = Personal[species].Gender;
|
||||
return GetGenderFromPIDAndRatio(PID, gt);
|
||||
return GetGenderFromPIDAndRatio(pid, gt);
|
||||
}
|
||||
|
||||
public static int GetGenderFromPIDAndRatio(uint PID, int gr)
|
||||
public static int GetGenderFromPIDAndRatio(uint pid, int gr)
|
||||
{
|
||||
return gr switch
|
||||
{
|
||||
255 => 2,
|
||||
254 => 1,
|
||||
0 => 0,
|
||||
_ => ((PID & 0xFF) < gr ? 1 : 0)
|
||||
_ => ((pid & 0xFF) < gr ? 1 : 0)
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -268,9 +268,9 @@ namespace PKHeX.Core
|
|||
/// <summary>
|
||||
/// Shuffles an 80 byte format Generation 3 Pokémon byte array.
|
||||
/// </summary>
|
||||
/// <param name="data">Unshuffled data.</param>
|
||||
/// <param name="data">Un-shuffled data.</param>
|
||||
/// <param name="sv">Block order shuffle value</param>
|
||||
/// <returns>Unshuffled data.</returns>
|
||||
/// <returns>Un-shuffled data.</returns>
|
||||
private static byte[] ShuffleArray3(byte[] data, uint sv)
|
||||
{
|
||||
byte[] sdata = (byte[])data.Clone();
|
||||
|
|
|
@ -22,10 +22,10 @@ namespace PKHeX.Core
|
|||
/// <returns>Decoded <see cref="PKM"/> object, null if invalid.</returns>
|
||||
public static PKM? GetPKM(string message, int format)
|
||||
{
|
||||
var pkdata = DecodeMessagePKM(message);
|
||||
if (pkdata == null)
|
||||
var data = DecodeMessagePKM(message);
|
||||
if (data == null)
|
||||
return null;
|
||||
return PKMConverter.GetPKMfromBytes(pkdata, format);
|
||||
return PKMConverter.GetPKMfromBytes(data, format);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -67,8 +67,8 @@ namespace PKHeX.Core
|
|||
|
||||
public static string GetMessageBase64(byte[] data, string server)
|
||||
{
|
||||
string qrdata = Convert.ToBase64String(data);
|
||||
return server + qrdata;
|
||||
string payload = Convert.ToBase64String(data);
|
||||
return server + payload;
|
||||
}
|
||||
|
||||
private static byte[]? DecodeMessagePKM(string message)
|
||||
|
|
|
@ -9,30 +9,30 @@
|
|||
/// <summary>
|
||||
/// Converts Generation 1 species ID to National Dex ID.
|
||||
/// </summary>
|
||||
/// <param name="raw_id">Generation 1 species ID.</param>
|
||||
/// <param name="raw">Generation 1 species ID.</param>
|
||||
/// <returns>National Dex ID.</returns>
|
||||
public static int GetG1Species(int raw_id) => table1_National[raw_id];
|
||||
public static int GetG1Species(int raw) => table1_National[raw];
|
||||
|
||||
/// <summary>
|
||||
/// Converts a National Dex ID to Generation 1 species ID.
|
||||
/// </summary>
|
||||
/// <param name="dex_id">National Dex ID.</param>
|
||||
/// <param name="species">National Dex ID.</param>
|
||||
/// <returns>Generation 1 species ID.</returns>
|
||||
public static int SetG1Species(int dex_id) => dex_id >= table1_Internal.Length ? 0 : table1_Internal[dex_id];
|
||||
public static int SetG1Species(int species) => species >= table1_Internal.Length ? 0 : table1_Internal[species];
|
||||
|
||||
/// <summary>
|
||||
/// Converts a National Dex ID to Generation 3 species ID.
|
||||
/// </summary>
|
||||
/// <param name="g4index">National Dex ID</param>
|
||||
/// <param name="species">National Dex ID</param>
|
||||
/// <returns>Generation 3 species ID.</returns>
|
||||
public static int GetG3Species(int g4index) => (uint)g4index >= table3_Internal.Length ? 0 : table3_Internal[g4index];
|
||||
public static int GetG3Species(int species) => (uint)species >= table3_Internal.Length ? 0 : table3_Internal[species];
|
||||
|
||||
/// <summary>
|
||||
/// Converts Generation 3 species ID to National Dex ID.
|
||||
/// </summary>
|
||||
/// <param name="g3index">Generation 3 species ID.</param>
|
||||
/// <param name="raw">Generation 3 species ID.</param>
|
||||
/// <returns>National Dex ID.</returns>
|
||||
public static int GetG4Species(int g3index) => (uint)g3index >= table3_National.Length ? 0 : table3_National[g3index];
|
||||
public static int GetG4Species(int raw) => (uint)raw >= table3_National.Length ? 0 : table3_National[raw];
|
||||
|
||||
private static readonly byte[] table1_Internal = { 0x00, 0x99, 0x09, 0x9A, 0xB0, 0xB2, 0xB4, 0xB1, 0xB3, 0x1C, 0x7B, 0x7C, 0x7D, 0x70, 0x71, 0x72, 0x24, 0x96, 0x97, 0xA5, 0xA6, 0x05, 0x23, 0x6C, 0x2D, 0x54, 0x55, 0x60, 0x61, 0x0F, 0xA8, 0x10, 0x03, 0xA7, 0x07, 0x04, 0x8E, 0x52, 0x53, 0x64, 0x65, 0x6B, 0x82, 0xB9, 0xBA, 0xBB, 0x6D, 0x2E, 0x41, 0x77, 0x3B, 0x76, 0x4D, 0x90, 0x2F, 0x80, 0x39, 0x75, 0x21, 0x14, 0x47, 0x6E, 0x6F, 0x94, 0x26, 0x95, 0x6A, 0x29, 0x7E, 0xBC, 0xBD, 0xBE, 0x18, 0x9B, 0xA9, 0x27, 0x31, 0xA3, 0xA4, 0x25, 0x08, 0xAD, 0x36, 0x40, 0x46, 0x74, 0x3A, 0x78, 0x0D, 0x88, 0x17, 0x8B, 0x19, 0x93, 0x0E, 0x22, 0x30, 0x81, 0x4E, 0x8A, 0x06, 0x8D, 0x0C, 0x0A, 0x11, 0x91, 0x2B, 0x2C, 0x0B, 0x37, 0x8F, 0x12, 0x01, 0x28, 0x1E, 0x02, 0x5C, 0x5D, 0x9D, 0x9E, 0x1B, 0x98, 0x2A, 0x1A, 0x48, 0x35, 0x33, 0x1D, 0x3C, 0x85, 0x16, 0x13, 0x4C, 0x66, 0x69, 0x68, 0x67, 0xAA, 0x62, 0x63, 0x5A, 0x5B, 0xAB, 0x84, 0x4A, 0x4B, 0x49, 0x58, 0x59, 0x42, 0x83, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
private static readonly byte[] table1_National = { 0x00, 0x70, 0x73, 0x20, 0x23, 0x15, 0x64, 0x22, 0x50, 0x02, 0x67, 0x6C, 0x66, 0x58, 0x5E, 0x1D, 0x1F, 0x68, 0x6F, 0x83, 0x3B, 0x97, 0x82, 0x5A, 0x48, 0x5C, 0x7B, 0x78, 0x09, 0x7F, 0x72, 0x00, 0x00, 0x3A, 0x5F, 0x16, 0x10, 0x4F, 0x40, 0x4B, 0x71, 0x43, 0x7A, 0x6A, 0x6B, 0x18, 0x2F, 0x36, 0x60, 0x4C, 0x00, 0x7E, 0x00, 0x7D, 0x52, 0x6D, 0x00, 0x38, 0x56, 0x32, 0x80, 0x00, 0x00, 0x00, 0x53, 0x30, 0x95, 0x00, 0x00, 0x00, 0x54, 0x3C, 0x7C, 0x92, 0x90, 0x91, 0x84, 0x34, 0x62, 0x00, 0x00, 0x00, 0x25, 0x26, 0x19, 0x1A, 0x00, 0x00, 0x93, 0x94, 0x8C, 0x8D, 0x74, 0x75, 0x00, 0x00, 0x1B, 0x1C, 0x8A, 0x8B, 0x27, 0x28, 0x85, 0x88, 0x87, 0x86, 0x42, 0x29, 0x17, 0x2E, 0x3D, 0x3E, 0x0D, 0x0E, 0x0F, 0x00, 0x55, 0x39, 0x33, 0x31, 0x57, 0x00, 0x00, 0x0A, 0x0B, 0x0C, 0x44, 0x00, 0x37, 0x61, 0x2A, 0x96, 0x8F, 0x81, 0x00, 0x00, 0x59, 0x00, 0x63, 0x5B, 0x00, 0x65, 0x24, 0x6E, 0x35, 0x69, 0x00, 0x5D, 0x3F, 0x41, 0x11, 0x12, 0x79, 0x01, 0x03, 0x49, 0x00, 0x76, 0x77, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x4E, 0x13, 0x14, 0x21, 0x1E, 0x4A, 0x89, 0x8E, 0x00, 0x51, 0x00, 0x00, 0x04, 0x07, 0x05, 0x08, 0x06, 0x00, 0x00, 0x00, 0x00, 0x2B, 0x2C, 0x2D, 0x45, 0x46, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace PKHeX.Core
|
|||
public override bool ChecksumValid => Valid;
|
||||
|
||||
public override int Species { get => SpeciesConverter.GetG4Species(BigEndian.ToUInt16(Data, 0x00)); set => BigEndian.GetBytes((ushort)SpeciesConverter.GetG3Species(value)).CopyTo(Data, 0x00); }
|
||||
public override int SpriteItem => ItemConverter.GetG4Item((ushort)HeldItem);
|
||||
public override int SpriteItem => ItemConverter.GetItemFuture3((ushort)HeldItem);
|
||||
public override int HeldItem { get => BigEndian.ToUInt16(Data, 0x02); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x02); }
|
||||
public override int Stat_HPCurrent { get => BigEndian.ToUInt16(Data, 0x04); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x04); }
|
||||
public override int OT_Friendship { get => BigEndian.ToUInt16(Data, 0x06); set => BigEndian.GetBytes((ushort)value).CopyTo(Data, 0x06); }
|
||||
|
|
|
@ -123,7 +123,7 @@ namespace PKHeX.Core
|
|||
public abstract int CatchRate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Evolution Stage value (or equivalent for unevolved).
|
||||
/// Evolution Stage value (or equivalent for un-evolved).
|
||||
/// </summary>
|
||||
public virtual int EvoStage { get; set; }
|
||||
|
||||
|
@ -133,7 +133,7 @@ namespace PKHeX.Core
|
|||
public abstract int[] Items { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gender Ratio value determining if the entry is a fixed gender or bigendered.
|
||||
/// Gender Ratio value determining if the entry is a fixed gender or bi-gendered.
|
||||
/// </summary>
|
||||
public abstract int Gender { get; set; }
|
||||
|
||||
|
@ -183,7 +183,7 @@ namespace PKHeX.Core
|
|||
public abstract int BaseEXP { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Main color ID of the entry. The majority of the pkm's color is of this color, usually.
|
||||
/// Main color ID of the entry. The majority of the Pokémon's color is of this color, usually.
|
||||
/// </summary>
|
||||
public abstract int Color { get; set; }
|
||||
|
||||
|
|
|
@ -192,11 +192,11 @@ namespace PKHeX.Core
|
|||
private static void PopulateGen3Tutors()
|
||||
{
|
||||
// Update Gen3 data with Emerald's data, FR/LG is a subset of Emerald's compatibility.
|
||||
var TMHM = BinLinker.Unpack(Util.GetBinaryResource("hmtm_g3.pkl"), "g3");
|
||||
var machine = BinLinker.Unpack(Util.GetBinaryResource("hmtm_g3.pkl"), "g3");
|
||||
var tutors = BinLinker.Unpack(Util.GetBinaryResource("tutors_g3.pkl"), "g3");
|
||||
for (int i = 0; i <= Legal.MaxSpeciesID_3; i++)
|
||||
{
|
||||
E[i].AddTMHM(TMHM[i]);
|
||||
E[i].AddTMHM(machine[i]);
|
||||
E[i].AddTypeTutors(tutors[i]);
|
||||
}
|
||||
}
|
||||
|
@ -352,12 +352,12 @@ namespace PKHeX.Core
|
|||
result[i] = species[i];
|
||||
if (AltForms[i].Length == 0)
|
||||
continue;
|
||||
int altformpointer = this[i].FormStatsIndex;
|
||||
if (altformpointer <= 0)
|
||||
int basePtr = this[i].FormStatsIndex;
|
||||
if (basePtr <= 0)
|
||||
continue;
|
||||
for (int j = 1; j < AltForms[i].Length; j++)
|
||||
{
|
||||
int ptr = altformpointer + j - 1;
|
||||
int ptr = basePtr + j - 1;
|
||||
baseForm[ptr] = i;
|
||||
formVal[ptr] = j;
|
||||
result[ptr] = AltForms[i][j];
|
||||
|
@ -370,12 +370,12 @@ namespace PKHeX.Core
|
|||
/// Checks to see if either of the input type combinations exist in the table.
|
||||
/// </summary>
|
||||
/// <remarks>Only useful for checking Generation 1 <see cref="PK1.Type_A"/> and <see cref="PK1.Type_B"/> properties.</remarks>
|
||||
/// <param name="Type1">First type</param>
|
||||
/// <param name="Type2">Second type</param>
|
||||
/// <param name="type1">First type</param>
|
||||
/// <param name="type2">Second type</param>
|
||||
/// <returns>Indication that the combination exists in the table.</returns>
|
||||
public bool IsValidTypeCombination(int Type1, int Type2)
|
||||
public bool IsValidTypeCombination(int type1, int type2)
|
||||
{
|
||||
return Table.Any(p => p.IsValidTypeCombination(Type1, Type2));
|
||||
return Table.Any(p => p.IsValidTypeCombination(type1, type2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace PKHeX.Core
|
|||
break;
|
||||
}
|
||||
|
||||
foreach (var len in new[] { memeLen, memeLen - 2 }) // Account for Pokedex QR Edge case
|
||||
foreach (var len in new[] { memeLen, memeLen - 2 }) // Account for Pokédex QR Edge case
|
||||
{
|
||||
if (VerifyMemeData(input, out output, 0, len, memeIndex))
|
||||
return true;
|
||||
|
@ -54,18 +54,18 @@ namespace PKHeX.Core
|
|||
output = input;
|
||||
return false;
|
||||
}
|
||||
var memekey = new MemeKey(keyIndex);
|
||||
var key = new MemeKey(keyIndex);
|
||||
output = (byte[])input.Clone();
|
||||
|
||||
var sigBuffer = new byte[0x60];
|
||||
Array.Copy(input, input.Length - 0x60, sigBuffer, 0, 0x60);
|
||||
sigBuffer = memekey.RsaPublic(sigBuffer);
|
||||
sigBuffer = key.RsaPublic(sigBuffer);
|
||||
using var sha1 = SHA1.Create();
|
||||
foreach (var orVal in new byte[] { 0, 0x80 })
|
||||
{
|
||||
sigBuffer[0x0] |= orVal;
|
||||
sigBuffer.CopyTo(output, output.Length - 0x60);
|
||||
memekey.AesDecrypt(output).CopyTo(output, 0);
|
||||
key.AesDecrypt(output).CopyTo(output, 0);
|
||||
// Check for 8-byte equality.
|
||||
var computed = BitConverter.ToUInt64(sha1.ComputeHash(output, 0, output.Length - 0x8), 0);
|
||||
var existing = BitConverter.ToUInt64(output, output.Length - 0x8);
|
||||
|
@ -112,8 +112,8 @@ namespace PKHeX.Core
|
|||
// Validate Input
|
||||
if (input.Length < 0x60)
|
||||
throw new ArgumentException("Cannot memesign a buffer less than 0x60 bytes in size!");
|
||||
var memekey = new MemeKey(keyIndex);
|
||||
if (!memekey.CanResign)
|
||||
var key = new MemeKey(keyIndex);
|
||||
if (!key.CanResign)
|
||||
throw new ArgumentException("Cannot sign with the specified memekey!");
|
||||
|
||||
var output = (byte[])input.Clone();
|
||||
|
@ -125,11 +125,11 @@ namespace PKHeX.Core
|
|||
}
|
||||
|
||||
// Perform AES operations
|
||||
output = memekey.AesEncrypt(output);
|
||||
output = key.AesEncrypt(output);
|
||||
var sigBuffer = new byte[0x60];
|
||||
Array.Copy(output, output.Length - 0x60, sigBuffer, 0, 0x60);
|
||||
sigBuffer[0] &= 0x7F;
|
||||
sigBuffer = memekey.RsaPrivate(sigBuffer);
|
||||
sigBuffer = key.RsaPrivate(sigBuffer);
|
||||
sigBuffer.CopyTo(output, output.Length - 0x60);
|
||||
return output;
|
||||
}
|
||||
|
@ -151,23 +151,23 @@ namespace PKHeX.Core
|
|||
var ChecksumSignatureLength = isUSUM ? 0x150 : 0x140;
|
||||
const int MemeCryptoSignatureLength = 0x80;
|
||||
|
||||
var outSav = (byte[])sav7.Clone();
|
||||
var result = (byte[])sav7.Clone();
|
||||
|
||||
using (var sha256 = SHA256.Create())
|
||||
{
|
||||
// Store current signature
|
||||
var CurSig = new byte[MemeCryptoSignatureLength];
|
||||
Buffer.BlockCopy(sav7, MemeCryptoOffset, CurSig, 0, MemeCryptoSignatureLength);
|
||||
var oldSig = new byte[MemeCryptoSignatureLength];
|
||||
Buffer.BlockCopy(sav7, MemeCryptoOffset, oldSig, 0, MemeCryptoSignatureLength);
|
||||
|
||||
var newSig = sha256.ComputeHash(sav7, ChecksumTableOffset, ChecksumSignatureLength);
|
||||
Array.Resize(ref newSig, MemeCryptoSignatureLength);
|
||||
|
||||
if (VerifyMemeData(CurSig, out var memeSig, MemeKeyIndex.PokedexAndSaveFile))
|
||||
if (VerifyMemeData(oldSig, out var memeSig, MemeKeyIndex.PokedexAndSaveFile))
|
||||
Buffer.BlockCopy(memeSig, 0x20, newSig, 0x20, 0x60);
|
||||
|
||||
SignMemeData(newSig).CopyTo(outSav, MemeCryptoOffset);
|
||||
SignMemeData(newSig).CopyTo(result, MemeCryptoOffset);
|
||||
}
|
||||
return outSav;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -323,7 +323,7 @@ namespace PKHeX.Core
|
|||
if (index == -1)
|
||||
continue;
|
||||
int len = chunkLength[index];
|
||||
ushort chk = Checksums.CRC32(Data, ofs, len);
|
||||
ushort chk = Checksums.CheckSum32(Data, ofs, len);
|
||||
BitConverter.GetBytes(chk).CopyTo(Data, ofs + 0xFF6);
|
||||
}
|
||||
|
||||
|
@ -332,11 +332,11 @@ namespace PKHeX.Core
|
|||
|
||||
// Hall of Fame Checksums
|
||||
{
|
||||
ushort chk = Checksums.CRC32(Data, 0x1C000, SIZE_BLOCK_USED);
|
||||
ushort chk = Checksums.CheckSum32(Data, 0x1C000, SIZE_BLOCK_USED);
|
||||
BitConverter.GetBytes(chk).CopyTo(Data, 0x1CFF4);
|
||||
}
|
||||
{
|
||||
ushort chk = Checksums.CRC32(Data, 0x1D000, SIZE_BLOCK_USED);
|
||||
ushort chk = Checksums.CheckSum32(Data, 0x1D000, SIZE_BLOCK_USED);
|
||||
BitConverter.GetBytes(chk).CopyTo(Data, 0x1DFF4);
|
||||
}
|
||||
}
|
||||
|
@ -364,7 +364,7 @@ namespace PKHeX.Core
|
|||
|
||||
private bool IsChunkValidHoF(int ofs)
|
||||
{
|
||||
ushort chk = Checksums.CRC32(Data, ofs, SIZE_BLOCK_USED);
|
||||
ushort chk = Checksums.CheckSum32(Data, ofs, SIZE_BLOCK_USED);
|
||||
return chk == BitConverter.ToUInt16(Data, ofs + 0xFF4);
|
||||
}
|
||||
|
||||
|
@ -372,7 +372,7 @@ namespace PKHeX.Core
|
|||
{
|
||||
int ofs = ABO + (i * SIZE_BLOCK);
|
||||
int len = chunkLength[BlockOrder[i]];
|
||||
ushort chk = Checksums.CRC32(Data, ofs, len);
|
||||
ushort chk = Checksums.CheckSum32(Data, ofs, len);
|
||||
return chk == BitConverter.ToUInt16(Data, ofs + 0xFF6);
|
||||
}
|
||||
|
||||
|
|
|
@ -172,31 +172,31 @@ namespace PKHeX.Core
|
|||
}
|
||||
}
|
||||
|
||||
public bool IsValidItemAndCount(ITrainerInfo SAV, int itemindex, bool HasNew, bool HaX, ref int itemcnt)
|
||||
public bool IsValidItemAndCount(ITrainerInfo sav, int item, bool HasNew, bool HaX, ref int count)
|
||||
{
|
||||
if (HaX && SAV.Generation != 7) // Gen7 has true cap at 1023, keep 999 cap.
|
||||
if (HaX && sav.Generation != 7) // Gen7 has true cap at 1023, keep 999 cap.
|
||||
{
|
||||
// Cap at absolute maximum
|
||||
if (SAV.Generation <= 2 && itemcnt > byte.MaxValue)
|
||||
itemcnt = byte.MaxValue;
|
||||
else if (SAV.Generation >= 3 && itemcnt > ushort.MaxValue)
|
||||
itemcnt = ushort.MaxValue;
|
||||
if (sav.Generation <= 2 && count > byte.MaxValue)
|
||||
count = byte.MaxValue;
|
||||
else if (sav.Generation >= 3 && count > ushort.MaxValue)
|
||||
count = ushort.MaxValue;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (itemcnt > MaxCount)
|
||||
if (count > MaxCount)
|
||||
{
|
||||
if (itemindex == 797 && itemcnt >= 2) // Edge case when for some reason the item count for Z-Ring was 2 in an unedited save and set 1 after using PKHeX
|
||||
itemcnt = 2;
|
||||
if (item == 797 && count >= 2) // Edge case when for some reason the item count for Z-Ring was 2 in an unedited save and set 1 after using PKHeX
|
||||
count = 2;
|
||||
else
|
||||
itemcnt = MaxCount; // Cap at pouch maximum
|
||||
count = MaxCount; // Cap at pouch maximum
|
||||
}
|
||||
else if (itemcnt <= 0 && !HasNew)
|
||||
else if (count <= 0 && !HasNew)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
itemcnt = GetSuggestedItemCount(SAV, itemindex, itemcnt);
|
||||
count = GetSuggestedItemCount(sav, item, count);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,32 +14,32 @@ namespace PKHeX.Core
|
|||
/// <summary>
|
||||
/// Dumps a folder of files to the <see cref="SaveFile"/>.
|
||||
/// </summary>
|
||||
/// <param name="SAV"><see cref="SaveFile"/> that is being dumped from.</param>
|
||||
/// <param name="sav"><see cref="SaveFile"/> that is being dumped from.</param>
|
||||
/// <param name="path">Folder to store <see cref="PKM"/> files.</param>
|
||||
/// <param name="boxFolders">Option to save in child folders with the Box Name as the folder name.</param>
|
||||
/// <returns>-1 if aborted, otherwise the amount of files dumped.</returns>
|
||||
public static int DumpBoxes(this SaveFile SAV, string path, bool boxFolders = false)
|
||||
public static int DumpBoxes(this SaveFile sav, string path, bool boxFolders = false)
|
||||
{
|
||||
if (!SAV.HasBox)
|
||||
if (!sav.HasBox)
|
||||
return -1;
|
||||
|
||||
var boxdata = SAV.BoxData;
|
||||
var boxData = sav.BoxData;
|
||||
var ctr = 0;
|
||||
foreach (var pk in boxdata)
|
||||
foreach (var pk in boxData)
|
||||
{
|
||||
if (pk.Species == 0 || !pk.Valid)
|
||||
continue;
|
||||
|
||||
var boxfolder = path;
|
||||
var boxFolder = path;
|
||||
if (boxFolders)
|
||||
{
|
||||
var boxName = Util.CleanFileName(SAV.GetBoxName(pk.Box - 1));
|
||||
boxfolder = Path.Combine(path, boxName);
|
||||
Directory.CreateDirectory(boxfolder);
|
||||
var boxName = Util.CleanFileName(sav.GetBoxName(pk.Box - 1));
|
||||
boxFolder = Path.Combine(path, boxName);
|
||||
Directory.CreateDirectory(boxFolder);
|
||||
}
|
||||
|
||||
var fileName = Util.CleanFileName(pk.FileName);
|
||||
var fn = Path.Combine(boxfolder, fileName);
|
||||
var fn = Path.Combine(boxFolder, fileName);
|
||||
if (File.Exists(fn))
|
||||
continue;
|
||||
|
||||
|
@ -52,18 +52,18 @@ namespace PKHeX.Core
|
|||
/// <summary>
|
||||
/// Dumps the <see cref="SaveFile.BoxData"/> to a folder with individual decrypted files.
|
||||
/// </summary>
|
||||
/// <param name="SAV"><see cref="SaveFile"/> that is being dumped from.</param>
|
||||
/// <param name="sav"><see cref="SaveFile"/> that is being dumped from.</param>
|
||||
/// <param name="path">Folder to store <see cref="PKM"/> files.</param>
|
||||
/// <param name="currentBox">Box contents to be dumped.</param>
|
||||
/// <returns>-1 if aborted, otherwise the amount of files dumped.</returns>
|
||||
public static int DumpBox(this SaveFile SAV, string path, int currentBox)
|
||||
public static int DumpBox(this SaveFile sav, string path, int currentBox)
|
||||
{
|
||||
if (!SAV.HasBox)
|
||||
if (!sav.HasBox)
|
||||
return -1;
|
||||
|
||||
var boxdata = SAV.BoxData;
|
||||
var boxData = sav.BoxData;
|
||||
var ctr = 0;
|
||||
foreach (var pk in boxdata)
|
||||
foreach (var pk in boxData)
|
||||
{
|
||||
if (pk.Species == 0 || !pk.Valid || pk.Box - 1 != currentBox)
|
||||
continue;
|
||||
|
@ -81,7 +81,7 @@ namespace PKHeX.Core
|
|||
/// <summary>
|
||||
/// Loads a folder of files to the <see cref="SaveFile"/>.
|
||||
/// </summary>
|
||||
/// <param name="SAV"><see cref="SaveFile"/> to load folder to.</param>
|
||||
/// <param name="sav"><see cref="SaveFile"/> to load folder to.</param>
|
||||
/// <param name="path">Folder to load <see cref="PKM"/> files from. Files are only loaded from the top directory.</param>
|
||||
/// <param name="result">Result message from the method.</param>
|
||||
/// <param name="boxStart">First box to start loading to. All prior boxes are not modified.</param>
|
||||
|
@ -90,37 +90,37 @@ namespace PKHeX.Core
|
|||
/// <param name="noSetb">Bypass option to not modify <see cref="PKM"/> properties when setting to Save File.</param>
|
||||
/// <param name="all">Enumerate all files even in sub-folders.</param>
|
||||
/// <returns>Count of files imported.</returns>
|
||||
public static int LoadBoxes(this SaveFile SAV, string path, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault, bool all = false)
|
||||
public static int LoadBoxes(this SaveFile sav, string path, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault, bool all = false)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path) || !Directory.Exists(path))
|
||||
{ result = MsgSaveBoxExportPathInvalid; return -1; }
|
||||
|
||||
var opt = all ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
|
||||
var filepaths = Directory.EnumerateFiles(path, "*.*", opt);
|
||||
return SAV.LoadBoxes(filepaths, out result, boxStart, boxClear, overwrite, noSetb);
|
||||
var option = all ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
|
||||
var files = Directory.EnumerateFiles(path, "*.*", option);
|
||||
return sav.LoadBoxes(files, out result, boxStart, boxClear, overwrite, noSetb);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a folder of files to the <see cref="SaveFile"/>.
|
||||
/// </summary>
|
||||
/// <param name="SAV"><see cref="SaveFile"/> to load folder to.</param>
|
||||
/// <param name="filepaths">Files to load <see cref="PKM"/> files from.</param>
|
||||
/// <param name="sav"><see cref="SaveFile"/> to load folder to.</param>
|
||||
/// <param name="files">Files to load <see cref="PKM"/> files from.</param>
|
||||
/// <param name="result">Result message from the method.</param>
|
||||
/// <param name="boxStart">First box to start loading to. All prior boxes are not modified.</param>
|
||||
/// <param name="boxClear">Instruction to clear boxes after the starting box.</param>
|
||||
/// <param name="overwrite">Overwrite existing full slots. If true, will only overwrite empty slots.</param>
|
||||
/// <param name="noSetb">Bypass option to not modify <see cref="PKM"/> properties when setting to Save File.</param>
|
||||
/// <returns>Count of files imported.</returns>
|
||||
public static int LoadBoxes(this SaveFile SAV, IEnumerable<string> filepaths, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault)
|
||||
public static int LoadBoxes(this SaveFile sav, IEnumerable<string> files, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault)
|
||||
{
|
||||
var pks = GetPossiblePKMsFromPaths(SAV, filepaths);
|
||||
return SAV.LoadBoxes(pks, out result, boxStart, boxClear, overwrite, noSetb);
|
||||
var pks = GetPossiblePKMsFromPaths(sav, files);
|
||||
return sav.LoadBoxes(pks, out result, boxStart, boxClear, overwrite, noSetb);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a folder of files to the <see cref="SaveFile"/>.
|
||||
/// </summary>
|
||||
/// <param name="SAV"><see cref="SaveFile"/> to load folder to.</param>
|
||||
/// <param name="sav"><see cref="SaveFile"/> to load folder to.</param>
|
||||
/// <param name="encounters">Encounters to create <see cref="PKM"/> files from.</param>
|
||||
/// <param name="result">Result message from the method.</param>
|
||||
/// <param name="boxStart">First box to start loading to. All prior boxes are not modified.</param>
|
||||
|
@ -128,16 +128,16 @@ namespace PKHeX.Core
|
|||
/// <param name="overwrite">Overwrite existing full slots. If true, will only overwrite empty slots.</param>
|
||||
/// <param name="noSetb">Bypass option to not modify <see cref="PKM"/> properties when setting to Save File.</param>
|
||||
/// <returns>Count of files imported.</returns>
|
||||
public static int LoadBoxes(this SaveFile SAV, IEnumerable<IEncounterable> encounters, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault)
|
||||
public static int LoadBoxes(this SaveFile sav, IEnumerable<IEncounterable> encounters, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault)
|
||||
{
|
||||
var pks = encounters.Select(z => z.ConvertToPKM(SAV));
|
||||
return SAV.LoadBoxes(pks, out result, boxStart, boxClear, overwrite, noSetb);
|
||||
var pks = encounters.Select(z => z.ConvertToPKM(sav));
|
||||
return sav.LoadBoxes(pks, out result, boxStart, boxClear, overwrite, noSetb);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a folder of files to the <see cref="SaveFile"/>.
|
||||
/// </summary>
|
||||
/// <param name="SAV"><see cref="SaveFile"/> to load folder to.</param>
|
||||
/// <param name="sav"><see cref="SaveFile"/> to load folder to.</param>
|
||||
/// <param name="pks">Unconverted <see cref="PKM"/> objects to load.</param>
|
||||
/// <param name="result">Result message from the method.</param>
|
||||
/// <param name="boxStart">First box to start loading to. All prior boxes are not modified.</param>
|
||||
|
@ -145,16 +145,16 @@ namespace PKHeX.Core
|
|||
/// <param name="overwrite">Overwrite existing full slots. If true, will only overwrite empty slots.</param>
|
||||
/// <param name="noSetb">Bypass option to not modify <see cref="PKM"/> properties when setting to Save File.</param>
|
||||
/// <returns>True if any files are imported.</returns>
|
||||
public static int LoadBoxes(this SaveFile SAV, IEnumerable<PKM> pks, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault)
|
||||
public static int LoadBoxes(this SaveFile sav, IEnumerable<PKM> pks, out string result, int boxStart = 0, bool boxClear = false, bool overwrite = false, PKMImportSetting noSetb = PKMImportSetting.UseDefault)
|
||||
{
|
||||
if (!SAV.HasBox)
|
||||
if (!sav.HasBox)
|
||||
{ result = MsgSaveBoxFailNone; return -1; }
|
||||
|
||||
var compat = SAV.GetCompatible(pks);
|
||||
var compat = sav.GetCompatible(pks);
|
||||
if (boxClear)
|
||||
SAV.ClearBoxes(boxStart);
|
||||
sav.ClearBoxes(boxStart);
|
||||
|
||||
int ctr = SAV.ImportPKMs(compat, overwrite, boxStart, noSetb);
|
||||
int ctr = sav.ImportPKMs(compat, overwrite, boxStart, noSetb);
|
||||
if (ctr <= 0)
|
||||
{
|
||||
result = MsgSaveBoxImportNoFiles;
|
||||
|
@ -165,9 +165,9 @@ namespace PKHeX.Core
|
|||
return ctr;
|
||||
}
|
||||
|
||||
public static IEnumerable<PKM> GetPKMsFromPaths(IEnumerable<string> filepaths, int generation)
|
||||
public static IEnumerable<PKM> GetPKMsFromPaths(IEnumerable<string> files, int generation)
|
||||
{
|
||||
var result = filepaths
|
||||
var result = files
|
||||
.Where(file => PKX.IsPKM(new FileInfo(file).Length))
|
||||
.Select(File.ReadAllBytes)
|
||||
.Select(data => PKMConverter.GetPKMfromBytes(data, prefer: generation));
|
||||
|
@ -179,9 +179,9 @@ namespace PKHeX.Core
|
|||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<PKM> GetPossiblePKMsFromPaths(SaveFile sav, IEnumerable<string> filepaths)
|
||||
private static IEnumerable<PKM> GetPossiblePKMsFromPaths(SaveFile sav, IEnumerable<string> files)
|
||||
{
|
||||
foreach (var f in filepaths)
|
||||
foreach (var f in files)
|
||||
{
|
||||
var obj = FileUtil.GetSupportedFile(f, sav);
|
||||
switch (obj)
|
||||
|
|
|
@ -102,7 +102,7 @@ namespace PKHeX.Core
|
|||
/// <param name="length">Length of array to checksum</param>
|
||||
/// <param name="initial">Initial value for checksum</param>
|
||||
/// <returns>Checksum</returns>
|
||||
public static ushort CRC32(byte[] data, int start, int length, uint initial = 0)
|
||||
public static ushort CheckSum32(byte[] data, int start, int length, uint initial = 0)
|
||||
{
|
||||
uint val = initial;
|
||||
for (int i = start; i < start + length; i += 4)
|
||||
|
@ -114,6 +114,6 @@ namespace PKHeX.Core
|
|||
/// <param name="data">Input byte array</param>
|
||||
/// <param name="initial">Initial value for checksum</param>
|
||||
/// <returns>Checksum</returns>
|
||||
public static ushort CRC32(byte[] data, uint initial = 0) => CRC32(data, 0, data.Length, initial);
|
||||
public static ushort CheckSum32(byte[] data, uint initial = 0) => CheckSum32(data, 0, data.Length, initial);
|
||||
}
|
||||
}
|
|
@ -3,13 +3,13 @@
|
|||
namespace PKHeX.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Logic for interacting with Pokedex AltForm flags
|
||||
/// Logic for interacting with Pokédex AltForm flags
|
||||
/// </summary>
|
||||
public static class DexFormUtil
|
||||
{
|
||||
public static int GetDexFormIndexSM(int species, int formct, int start) => GetDexFormBitIndex(species, formct, start, formtable_SM);
|
||||
public static int GetDexFormIndexUSUM(int species, int formct, int start) => GetDexFormBitIndex(species, formct, start, formtable_USUM);
|
||||
public static int GetDexFormIndexGG(int species, int formct, int start) => GetDexFormBitIndex(species, formct, start, formtable_GG);
|
||||
public static int GetDexFormIndexSM(int species, int formCount, int start) => GetDexFormBitIndex(species, formCount, start, formtable_SM);
|
||||
public static int GetDexFormIndexUSUM(int species, int formCount, int start) => GetDexFormBitIndex(species, formCount, start, formtable_USUM);
|
||||
public static int GetDexFormIndexGG(int species, int formCount, int start) => GetDexFormBitIndex(species, formCount, start, formtable_GG);
|
||||
public static int GetDexFormCountSM(int species) => GetDexFormCount(species, formtable_SM);
|
||||
public static int GetDexFormCountUSUM(int species) => GetDexFormCount(species, formtable_USUM);
|
||||
public static int GetDexFormCountGG(int species) => GetDexFormCount(species, formtable_GG);
|
||||
|
@ -94,34 +94,34 @@ namespace PKHeX.Core
|
|||
0x007F, 0x0002, 0x0082, 0x0002, 0x008E, 0x0002, 0x0096, 0x0003,
|
||||
};
|
||||
|
||||
private static int GetDexFormBitIndex(int species, int formct, int start, IReadOnlyList<ushort> formtable)
|
||||
private static int GetDexFormBitIndex(int species, int formCount, int start, IReadOnlyList<ushort> formTable)
|
||||
{
|
||||
int formindex = start;
|
||||
for (int i = 0; i < formtable.Count; i += 2)
|
||||
int formIndex = start;
|
||||
for (int i = 0; i < formTable.Count; i += 2)
|
||||
{
|
||||
int s = formtable[i];
|
||||
int f = formtable[i + 1];
|
||||
int s = formTable[i];
|
||||
int f = formTable[i + 1];
|
||||
if (s == species)
|
||||
return f > formct ? -1 : formindex;
|
||||
return f > formCount ? -1 : formIndex;
|
||||
|
||||
formindex += f - 1;
|
||||
formIndex += f - 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static int GetDexFormCount(int species, IReadOnlyList<ushort> formtable)
|
||||
private static int GetDexFormCount(int species, IReadOnlyList<ushort> formTable)
|
||||
{
|
||||
for (int i = 0; i < formtable.Count; i += 2)
|
||||
for (int i = 0; i < formTable.Count; i += 2)
|
||||
{
|
||||
if (formtable[i] == species)
|
||||
return formtable[i + 1];
|
||||
if (formTable[i] == species)
|
||||
return formTable[i + 1];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static int GetDexFormIndexBW(int species, int formct)
|
||||
public static int GetDexFormIndexBW(int species, int formCount)
|
||||
{
|
||||
if (formct < 1 || species < 0)
|
||||
if (formCount < 1 || species < 0)
|
||||
return -1; // invalid
|
||||
return species switch
|
||||
{
|
||||
|
@ -145,9 +145,9 @@ namespace PKHeX.Core
|
|||
};
|
||||
}
|
||||
|
||||
public static int GetDexFormIndexB2W2(int species, int formct)
|
||||
public static int GetDexFormIndexB2W2(int species, int formCount)
|
||||
{
|
||||
if (formct < 1 || species < 0)
|
||||
if (formCount < 1 || species < 0)
|
||||
return -1; // invalid
|
||||
return species switch
|
||||
{
|
||||
|
@ -156,13 +156,13 @@ namespace PKHeX.Core
|
|||
642 => 077, // 2 Thundurus
|
||||
641 => 079, // 2 Tornadus
|
||||
645 => 081, // 2 Landorus
|
||||
_ => GetDexFormIndexBW(species, formct)
|
||||
_ => GetDexFormIndexBW(species, formCount)
|
||||
};
|
||||
}
|
||||
|
||||
public static int GetDexFormIndexXY(int species, int formct)
|
||||
public static int GetDexFormIndexXY(int species, int formCount)
|
||||
{
|
||||
if (formct < 1 || species < 0)
|
||||
if (formCount < 1 || species < 0)
|
||||
return -1; // invalid
|
||||
return species switch
|
||||
{
|
||||
|
@ -202,13 +202,13 @@ namespace PKHeX.Core
|
|||
445 => 183, // 2 Garchomp
|
||||
448 => 185, // 2 Lucario
|
||||
460 => 187, // 2 Abomasnow
|
||||
_ => GetDexFormIndexB2W2(species, formct)
|
||||
_ => GetDexFormIndexB2W2(species, formCount)
|
||||
};
|
||||
}
|
||||
|
||||
public static int GetDexFormIndexORAS(int species, int formct)
|
||||
public static int GetDexFormIndexORAS(int species, int formCount)
|
||||
{
|
||||
if (formct < 1 || species < 0)
|
||||
if (formCount < 1 || species < 0)
|
||||
return -1; // invalid
|
||||
return species switch
|
||||
{
|
||||
|
@ -237,7 +237,7 @@ namespace PKHeX.Core
|
|||
493 => 238, // 18 Arceus
|
||||
649 => 256, // 5 Genesect
|
||||
676 => 261, // 10 Furfrou
|
||||
_ => GetDexFormIndexXY(species, formct)
|
||||
_ => GetDexFormIndexXY(species, formCount)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace PKHeX.Core
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets suggested export options for the savefile.
|
||||
/// Gets suggested export options for the save file.
|
||||
/// </summary>
|
||||
/// <param name="sav">SaveFile to be exported</param>
|
||||
/// <param name="ext">Selected export extension</param>
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace PKHeX.Core
|
|||
public static class SaveFinder
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the 3DS's root folder, usually from an inserted SD card.
|
||||
/// Searches the provided <see cref="drives"/> to find a valid 3DS drive, usually from an inserted SD card.
|
||||
/// </summary>
|
||||
/// <param name="drives">List of drives on the host machine.</param>
|
||||
/// <param name="skipFirstDrive">Optional parameter to skip the first drive.
|
||||
|
@ -21,7 +21,7 @@ namespace PKHeX.Core
|
|||
FindConsoleRootFolder(drives, "Nintendo 3DS", skipFirstDrive);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Switch's root folder, usually from an inserted SD card.
|
||||
/// Searches the provided <see cref="drives"/> to find a valid Switch drive, usually from an inserted SD card.
|
||||
/// </summary>
|
||||
/// <param name="drives">List of drives on the host machine.</param>
|
||||
/// <param name="skipFirstDrive">Optional parameter to skip the first drive.
|
||||
|
|
|
@ -54,12 +54,12 @@ namespace PKHeX.Core
|
|||
public const int SIZE_G4RANCH = 0x54000;
|
||||
public const int SIZE_G4RANCH_PLAT = 0x7C000;
|
||||
|
||||
private static readonly HashSet<int> SIZES_2 = new HashSet<int>
|
||||
private static readonly HashSet<int> SizesGen2 = new HashSet<int>
|
||||
{
|
||||
SIZE_G2RAW_U, SIZE_G2VC_U, SIZE_G2BAT_U, SIZE_G2EMU_U, SIZE_G2RAW_J, SIZE_G2BAT_J, SIZE_G2EMU_J, SIZE_G2VC_J,
|
||||
};
|
||||
|
||||
private static readonly HashSet<int> SIZES = new HashSet<int>(SIZES_2)
|
||||
private static readonly HashSet<int> Sizes = new HashSet<int>(SizesGen2)
|
||||
{
|
||||
SIZE_G8SWSH, SIZE_G8SWSH_1,
|
||||
SIZE_G7SM, SIZE_G7USUM, SIZE_G7GG,
|
||||
|
@ -175,7 +175,7 @@ namespace PKHeX.Core
|
|||
/// <returns>Version Identifier or Invalid if type cannot be determined.</returns>
|
||||
internal static GameVersion GetIsG2SAV(byte[] data)
|
||||
{
|
||||
if (!SIZES_2.Contains(data.Length))
|
||||
if (!SizesGen2.Contains(data.Length))
|
||||
return Invalid;
|
||||
|
||||
// Check if it's not an International, Japanese, or Korean save file
|
||||
|
@ -237,26 +237,26 @@ namespace PKHeX.Core
|
|||
int count = data.Length/SIZE_G3RAWHALF;
|
||||
for (int s = 0; s < count; s++)
|
||||
{
|
||||
const int blockcount = 14;
|
||||
const int blocksize = 0x1000;
|
||||
int ofs = blockcount * blocksize * s;
|
||||
int[] BlockOrder = new int[blockcount];
|
||||
for (int i = 0; i < BlockOrder.Length; i++)
|
||||
BlockOrder[i] = BitConverter.ToUInt16(data, (i * blocksize) + 0xFF4 + ofs);
|
||||
const int blockCount = 14;
|
||||
const int blockSize = 0x1000;
|
||||
int ofs = blockCount * blockSize * s;
|
||||
int[] order = new int[blockCount];
|
||||
for (int i = 0; i < order.Length; i++)
|
||||
order[i] = BitConverter.ToUInt16(data, (i * blockSize) + 0xFF4 + ofs);
|
||||
|
||||
if (Array.FindIndex(BlockOrder, i => i > 0xD) >= 0) // invalid block ID
|
||||
if (Array.FindIndex(order, i => i > 0xD) >= 0) // invalid block ID
|
||||
continue;
|
||||
|
||||
int Block0 = Array.IndexOf(BlockOrder, 0);
|
||||
int block0 = Array.IndexOf(order, 0);
|
||||
|
||||
// Sometimes not all blocks are present (start of game), yielding multiple block0's.
|
||||
// Real 0th block comes before block1.
|
||||
if (BlockOrder[0] == 1 && Block0 != BlockOrder.Length - 1)
|
||||
if (order[0] == 1 && block0 != order.Length - 1)
|
||||
continue;
|
||||
if (Array.FindIndex(BlockOrder, v => v != 0) < 0) // all blocks are 0
|
||||
if (Array.FindIndex(order, v => v != 0) < 0) // all blocks are 0
|
||||
continue;
|
||||
// Detect RS/E/FRLG
|
||||
return SAV3.GetVersion(data, (blocksize * Block0) + ofs);
|
||||
return SAV3.GetVersion(data, (blockSize * block0) + ofs);
|
||||
}
|
||||
return Invalid;
|
||||
}
|
||||
|
@ -333,7 +333,7 @@ namespace PKHeX.Core
|
|||
return Invalid;
|
||||
|
||||
// The block footers contain a u32 'size' followed by a u32 binary-coded-decimal timestamp(?)
|
||||
// Korean savegames have a different timestamp from other localizations.
|
||||
// Korean saves have a different timestamp from other localizations.
|
||||
bool validSequence(int offset)
|
||||
{
|
||||
var size = BitConverter.ToUInt32(data, offset - 0xC);
|
||||
|
@ -679,14 +679,14 @@ namespace PKHeX.Core
|
|||
{
|
||||
var searchOption = deep ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
|
||||
// force evaluation so that an invalid path will throw before we return true/false.
|
||||
// EnumerateFiles throws an exception while iterating, which won't be caught by the trycatch here.
|
||||
// EnumerateFiles throws an exception while iterating, which won't be caught by the try-catch here.
|
||||
var files = Directory.GetFiles(folderPath, "*", searchOption);
|
||||
static int safelen(string file)
|
||||
static int GetFileSize(string file)
|
||||
{
|
||||
try { return (int) new FileInfo(file).Length; }
|
||||
catch { return -1; } // Bad File / Locked
|
||||
}
|
||||
result = files.Where(f => IsSizeValid(safelen(f)));
|
||||
result = files.Where(f => IsSizeValid(GetFileSize(f)));
|
||||
return true;
|
||||
}
|
||||
catch (ArgumentException)
|
||||
|
@ -697,11 +697,11 @@ namespace PKHeX.Core
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the save data size is valid for autodetecting saves.
|
||||
/// Determines whether the save data size is valid for automatically detecting saves.
|
||||
/// </summary>
|
||||
/// <param name="size">Size in bytes of the save data</param>
|
||||
/// <returns>A boolean indicating whether or not the save data size is valid.</returns>
|
||||
public static bool IsSizeValid(int size) => SIZES.Contains(size);
|
||||
public static bool IsSizeValid(int size) => Sizes.Contains(size);
|
||||
|
||||
/// <summary>
|
||||
/// Checks the provided <see cref="input"/> and pulls out any <see cref="header"/> and/or <see cref="footer"/> arrays.
|
||||
|
|
|
@ -144,17 +144,17 @@ namespace PKHeX.Core
|
|||
{
|
||||
if (txt == null)
|
||||
return Array.Empty<string>();
|
||||
string[] rawlist = txt.Split('\n');
|
||||
for (int i = 0; i < rawlist.Length; i++)
|
||||
rawlist[i] = rawlist[i].TrimEnd('\r');
|
||||
string[] raw = txt.Split('\n');
|
||||
for (int i = 0; i < raw.Length; i++)
|
||||
raw[i] = raw[i].TrimEnd('\r');
|
||||
|
||||
lock (getStringListLoadLock) // Make sure only one thread can write to the cache
|
||||
{
|
||||
if (!stringListCache.ContainsKey(file)) // Check cache again in case of race condition
|
||||
stringListCache.Add(file, rawlist);
|
||||
stringListCache.Add(file, raw);
|
||||
}
|
||||
|
||||
return (string[])rawlist.Clone();
|
||||
return (string[])raw.Clone();
|
||||
}
|
||||
|
||||
public static string[] GetStringList(string fileName, string lang2char, string type = "text") => GetStringList($"{type}_{fileName}_{lang2char}");
|
||||
|
@ -169,16 +169,16 @@ namespace PKHeX.Core
|
|||
|
||||
public static string? GetStringResource(string name)
|
||||
{
|
||||
if (!resourceNameMap.TryGetValue(name, out var resname))
|
||||
if (!resourceNameMap.TryGetValue(name, out var resourceName))
|
||||
{
|
||||
bool Match(string x) => x.StartsWith("PKHeX.Core.Resources.text.") && x.EndsWith($"{name}.txt", StringComparison.OrdinalIgnoreCase);
|
||||
resname = Array.Find(manifestResourceNames, Match);
|
||||
if (resname == null)
|
||||
resourceName = Array.Find(manifestResourceNames, Match);
|
||||
if (resourceName == null)
|
||||
return null;
|
||||
resourceNameMap.Add(name, resname);
|
||||
resourceNameMap.Add(name, resourceName);
|
||||
}
|
||||
|
||||
using var resource = thisAssembly.GetManifestResourceStream(resname);
|
||||
using var resource = thisAssembly.GetManifestResourceStream(resourceName);
|
||||
if (resource == null)
|
||||
return null;
|
||||
using var reader = new StreamReader(resource);
|
||||
|
@ -284,9 +284,9 @@ namespace PKHeX.Core
|
|||
|
||||
private static readonly string[] CountryRegionLanguages = {"ja", "en", "fr", "de", "it", "es", "zh", "ko"};
|
||||
|
||||
public static List<ComboItem> GetCountryRegionList(string textfile, string lang)
|
||||
public static List<ComboItem> GetCountryRegionList(string textFile, string lang)
|
||||
{
|
||||
string[] inputCSV = GetStringList(textfile);
|
||||
string[] inputCSV = GetStringList(textFile);
|
||||
int index = Array.IndexOf(CountryRegionLanguages, lang);
|
||||
return GetCBListCSVSorted(inputCSV, index);
|
||||
}
|
||||
|
@ -298,9 +298,9 @@ namespace PKHeX.Core
|
|||
return list;
|
||||
}
|
||||
|
||||
public static List<ComboItem> GetCSVUnsortedCBList(string textfile)
|
||||
public static List<ComboItem> GetCSVUnsortedCBList(string textFile)
|
||||
{
|
||||
string[] inputCSV = GetStringList(textfile);
|
||||
string[] inputCSV = GetStringList(textFile);
|
||||
return GetCBListFromCSV(inputCSV, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,12 +29,12 @@ namespace PKHeX.Core
|
|||
}
|
||||
|
||||
private static readonly DateTime Epoch2000 = new DateTime(2000, 1, 1);
|
||||
private const int spd = 86400; // seconds per day
|
||||
private const int SecondsPerDay = 60*60*24; // 86400
|
||||
|
||||
public static int GetSecondsFrom2000(DateTime date, DateTime time)
|
||||
{
|
||||
int seconds = (int)(date - Epoch2000).TotalSeconds;
|
||||
seconds -= seconds % spd;
|
||||
seconds -= seconds % SecondsPerDay;
|
||||
seconds += (int)(time - Epoch2000).TotalSeconds;
|
||||
return seconds;
|
||||
}
|
||||
|
@ -42,14 +42,14 @@ namespace PKHeX.Core
|
|||
public static void GetDateTime2000(uint seconds, out DateTime date, out DateTime time)
|
||||
{
|
||||
date = Epoch2000.AddSeconds(seconds);
|
||||
time = Epoch2000.AddSeconds(seconds % spd);
|
||||
time = Epoch2000.AddSeconds(seconds % SecondsPerDay);
|
||||
}
|
||||
|
||||
public static string ConvertDateValueToString(int value, int secondsBias = -1)
|
||||
{
|
||||
string tip = string.Empty;
|
||||
if (value >= spd)
|
||||
tip += (value / spd) + "d ";
|
||||
if (value >= SecondsPerDay)
|
||||
tip += (value / SecondsPerDay) + "d ";
|
||||
tip += new DateTime(0).AddSeconds(value).ToString("HH:mm:ss");
|
||||
if (secondsBias >= 0)
|
||||
tip += Environment.NewLine + $"Date: {Epoch2000.AddSeconds(value + secondsBias)}";
|
||||
|
|
|
@ -208,24 +208,24 @@ namespace PKHeX.Core
|
|||
/// Gets a <see cref="PKM"/> from the provided <see cref="file"/> path, which is to be loaded to the <see cref="SaveFile"/>.
|
||||
/// </summary>
|
||||
/// <param name="file"><see cref="PKM"/> or <see cref="MysteryGift"/> file path.</param>
|
||||
/// <param name="SAV">Generation Info</param>
|
||||
/// <param name="sav">Generation Info</param>
|
||||
/// <returns>New <see cref="PKM"/> reference from the file.</returns>
|
||||
public static PKM? GetSingleFromPath(string file, ITrainerInfo SAV)
|
||||
public static PKM? GetSingleFromPath(string file, ITrainerInfo sav)
|
||||
{
|
||||
var fi = new FileInfo(file);
|
||||
if (!fi.Exists)
|
||||
return null;
|
||||
if (fi.Length == GP1.SIZE && TryGetGP1(File.ReadAllBytes(file), out var gp1))
|
||||
return gp1?.ConvertToPB7(SAV);
|
||||
return gp1?.ConvertToPB7(sav);
|
||||
if (!PKX.IsPKM(fi.Length) && !MysteryGift.IsMysteryGift(fi.Length))
|
||||
return null;
|
||||
var data = File.ReadAllBytes(file);
|
||||
var ext = fi.Extension;
|
||||
var mg = MysteryGift.GetMysteryGift(data, ext);
|
||||
var gift = mg?.ConvertToPKM(SAV);
|
||||
var gift = mg?.ConvertToPKM(sav);
|
||||
if (gift != null)
|
||||
return gift;
|
||||
int prefer = PKX.GetPKMFormatFromExtension(ext, SAV.Generation);
|
||||
int prefer = PKX.GetPKMFormatFromExtension(ext, sav.Generation);
|
||||
return PKMConverter.GetPKMfromBytes(data, prefer: prefer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,11 +8,11 @@ namespace PKHeX.Core
|
|||
{
|
||||
public static class NetUtil
|
||||
{
|
||||
public static string? GetStringFromURL(string webURL)
|
||||
public static string? GetStringFromURL(string url)
|
||||
{
|
||||
try
|
||||
{
|
||||
var stream = GetStreamFromURL(webURL);
|
||||
var stream = GetStreamFromURL(url);
|
||||
using var reader = new StreamReader(stream);
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
|
@ -23,9 +23,9 @@ namespace PKHeX.Core
|
|||
}
|
||||
}
|
||||
|
||||
private static Stream GetStreamFromURL(string webURL)
|
||||
private static Stream GetStreamFromURL(string url)
|
||||
{
|
||||
var httpWebRequest = (HttpWebRequest)WebRequest.Create(webURL);
|
||||
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
|
||||
|
||||
// The GitHub API will fail if no user agent is provided
|
||||
httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36";
|
||||
|
|
|
@ -13,41 +13,41 @@ namespace PKHeX.Drawing
|
|||
// QR Utility
|
||||
private const string DecodeAPI = "http://api.qrserver.com/v1/read-qr-code/?fileurl=";
|
||||
|
||||
public static QRDecodeMsg GetQRData(string address, out byte[] result)
|
||||
public static QRDecodeResult GetQRData(string address, out byte[] result)
|
||||
{
|
||||
result = Array.Empty<byte>();
|
||||
// Fetch data from QR code...
|
||||
|
||||
if (!address.StartsWith("http"))
|
||||
return QRDecodeMsg.BadPath;
|
||||
return QRDecodeResult.BadPath;
|
||||
|
||||
string webURL = DecodeAPI + WebUtility.UrlEncode(address);
|
||||
string url = DecodeAPI + WebUtility.UrlEncode(address);
|
||||
string data;
|
||||
try
|
||||
{
|
||||
var str = NetUtil.GetStringFromURL(webURL);
|
||||
var str = NetUtil.GetStringFromURL(url);
|
||||
if (str is null)
|
||||
return QRDecodeMsg.BadConnection;
|
||||
return QRDecodeResult.BadConnection;
|
||||
|
||||
data = str;
|
||||
if (data.Contains("could not find"))
|
||||
return QRDecodeMsg.BadImage;
|
||||
return QRDecodeResult.BadImage;
|
||||
|
||||
if (data.Contains("filetype not supported"))
|
||||
return QRDecodeMsg.BadType;
|
||||
return QRDecodeResult.BadType;
|
||||
}
|
||||
catch { return QRDecodeMsg.BadConnection; }
|
||||
catch { return QRDecodeResult.BadConnection; }
|
||||
|
||||
// Quickly convert the json response to a data string
|
||||
try
|
||||
{
|
||||
result = DecodeQRJson(data);
|
||||
return QRDecodeMsg.Success;
|
||||
return QRDecodeResult.Success;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.WriteLine(e.Message);
|
||||
return QRDecodeMsg.BadConversion;
|
||||
return QRDecodeResult.BadConversion;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,28 +78,18 @@ namespace PKHeX.Drawing
|
|||
return Convert.FromBase64String(pkstr);
|
||||
}
|
||||
|
||||
public static string ConvertMsg(this QRDecodeMsg msg)
|
||||
public static string ConvertMsg(this QRDecodeResult result)
|
||||
{
|
||||
return msg switch
|
||||
return result switch
|
||||
{
|
||||
QRDecodeMsg.Success => string.Empty,
|
||||
QRDecodeMsg.BadPath => MessageStrings.MsgQRUrlFailPath,
|
||||
QRDecodeMsg.BadImage => MessageStrings.MsgQRUrlFailImage,
|
||||
QRDecodeMsg.BadType => MessageStrings.MsgQRUrlFailType,
|
||||
QRDecodeMsg.BadConnection => MessageStrings.MsgQRUrlFailConnection,
|
||||
QRDecodeMsg.BadConversion => MessageStrings.MsgQRUrlFailConvert,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(msg), msg, null)
|
||||
QRDecodeResult.Success => string.Empty,
|
||||
QRDecodeResult.BadPath => MessageStrings.MsgQRUrlFailPath,
|
||||
QRDecodeResult.BadImage => MessageStrings.MsgQRUrlFailImage,
|
||||
QRDecodeResult.BadType => MessageStrings.MsgQRUrlFailType,
|
||||
QRDecodeResult.BadConnection => MessageStrings.MsgQRUrlFailConnection,
|
||||
QRDecodeResult.BadConversion => MessageStrings.MsgQRUrlFailConvert,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(result), result, null)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public enum QRDecodeMsg
|
||||
{
|
||||
Success,
|
||||
BadPath,
|
||||
BadImage,
|
||||
BadType,
|
||||
BadConnection,
|
||||
BadConversion,
|
||||
}
|
||||
}
|
||||
|
|
12
PKHeX.Drawing/QR/QRDecodeResult.cs
Normal file
12
PKHeX.Drawing/QR/QRDecodeResult.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
namespace PKHeX.Drawing
|
||||
{
|
||||
public enum QRDecodeResult
|
||||
{
|
||||
Success,
|
||||
BadPath,
|
||||
BadImage,
|
||||
BadType,
|
||||
BadConnection,
|
||||
BadConversion,
|
||||
}
|
||||
}
|
|
@ -9,9 +9,9 @@ namespace PKHeX.Drawing
|
|||
public static Image GenerateQRCode(DataMysteryGift mg) => GenerateQRCode(QRMessageUtil.GetMessage(mg));
|
||||
public static Image GenerateQRCode(PKM pkm) => GenerateQRCode(QRMessageUtil.GetMessage(pkm));
|
||||
|
||||
public static Image GenerateQRCode7(PK7 pk7, int box = 0, int slot = 0, int num_copies = 1)
|
||||
public static Image GenerateQRCode7(PK7 pk7, int box = 0, int slot = 0, int copies = 1)
|
||||
{
|
||||
byte[] data = QR7.GenerateQRData(pk7, box, slot, num_copies);
|
||||
byte[] data = QR7.GenerateQRData(pk7, box, slot, copies);
|
||||
var msg = QRMessageUtil.GetMessage(data);
|
||||
return GenerateQRCode(msg, ppm: 4);
|
||||
}
|
||||
|
@ -19,9 +19,9 @@ namespace PKHeX.Drawing
|
|||
private static Image GenerateQRCode(string msg, int ppm = 4)
|
||||
{
|
||||
using var generator = new QRCodeGenerator();
|
||||
using var qr_data = generator.CreateQrCode(msg, QRCodeGenerator.ECCLevel.Q);
|
||||
using var qr_code = new QRCode(qr_data);
|
||||
return qr_code.GetGraphic(ppm);
|
||||
using var data = generator.CreateQrCode(msg, QRCodeGenerator.ECCLevel.Q);
|
||||
using var code = new QRCode(data);
|
||||
return code.GetGraphic(ppm);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -405,7 +405,7 @@ namespace PKHeX.WinForms.Controls
|
|||
|
||||
public void SetATKIVGender(int gender)
|
||||
{
|
||||
Entity.SetATKIVGender(gender);
|
||||
Entity.SetAttackIVFromGender(gender);
|
||||
TB_IVATK.Text = Entity.IV_ATK.ToString();
|
||||
}
|
||||
|
||||
|
|
|
@ -8,34 +8,34 @@ namespace PKHeX.WinForms.Controls
|
|||
{
|
||||
public sealed class BoxMenuStrip : ContextMenuStrip
|
||||
{
|
||||
private readonly SAVEditor sav;
|
||||
private readonly SAVEditor SAV;
|
||||
private readonly List<ItemVisibility> CustomItems = new List<ItemVisibility>();
|
||||
private readonly BoxManipulator Manipulator;
|
||||
|
||||
public BoxMenuStrip(SAVEditor SAV)
|
||||
public BoxMenuStrip(SAVEditor sav)
|
||||
{
|
||||
Manipulator = new BoxManipulatorWF(SAV);
|
||||
sav = SAV;
|
||||
var Levels = BoxManipUtil.ManipCategories;
|
||||
var LevelNames = BoxManipUtil.ManipCategoryNames;
|
||||
for (int i = 0; i < Levels.Length; i++)
|
||||
Manipulator = new BoxManipulatorWF(sav);
|
||||
SAV = sav;
|
||||
var categories = BoxManipUtil.ManipCategories;
|
||||
var names = BoxManipUtil.ManipCategoryNames;
|
||||
for (int i = 0; i < categories.Length; i++)
|
||||
{
|
||||
var level = Levels[i];
|
||||
var category = categories[i];
|
||||
var sprite = TopLevelImages[i];
|
||||
var name = LevelNames[i];
|
||||
var name = names[i];
|
||||
var parent = new ToolStripMenuItem {Name = $"mnu_{name}", Text = name, Image = sprite};
|
||||
foreach (var item in level)
|
||||
AddItem(SAV, parent, item);
|
||||
foreach (var item in category)
|
||||
AddItem(sav, parent, item);
|
||||
Items.Add(parent);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddItem(ISaveFileProvider SAV, ToolStripDropDownItem parent, IBoxManip item)
|
||||
private void AddItem(ISaveFileProvider sav, ToolStripDropDownItem parent, IBoxManip item)
|
||||
{
|
||||
var name = item.Type.ToString();
|
||||
ManipTypeImage.TryGetValue(item.Type, out var img);
|
||||
var tsi = new ToolStripMenuItem { Name = $"mnu_{name}", Text = name, Image = img };
|
||||
tsi.Click += (s, e) => Manipulator.Execute(item, SAV.CurrentBox, All, Reverse);
|
||||
tsi.Click += (s, e) => Manipulator.Execute(item, sav.CurrentBox, All, Reverse);
|
||||
parent.DropDownItems.Add(tsi);
|
||||
CustomItems.Add(new ItemVisibility(tsi, item));
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ namespace PKHeX.WinForms.Controls
|
|||
public void ToggleVisibility()
|
||||
{
|
||||
foreach (var s in CustomItems)
|
||||
s.SetVisibility(sav.SAV);
|
||||
s.SetVisibility(SAV.SAV);
|
||||
}
|
||||
|
||||
private static readonly Image[] TopLevelImages =
|
||||
|
@ -112,8 +112,8 @@ namespace PKHeX.WinForms.Controls
|
|||
Resources.wand,
|
||||
};
|
||||
|
||||
public void Clear() => Manipulator.Execute(BoxManipType.DeleteAll, sav.SAV.CurrentBox, All);
|
||||
public void Sort() => Manipulator.Execute(BoxManipType.SortSpecies, sav.SAV.CurrentBox, All);
|
||||
public void Clear() => Manipulator.Execute(BoxManipType.DeleteAll, SAV.SAV.CurrentBox, All);
|
||||
public void Sort() => Manipulator.Execute(BoxManipType.SortSpecies, SAV.SAV.CurrentBox, All);
|
||||
|
||||
private static bool All => (ModifierKeys & Keys.Shift) != 0;
|
||||
private static bool Reverse => (ModifierKeys & Keys.Control) != 0;
|
||||
|
|
|
@ -1219,12 +1219,13 @@ namespace PKHeX.WinForms.Controls
|
|||
sav => (ModifierKeys & Keys.Control) != 0 ? sav.BoxData : sav.GetBoxData(CurrentBox));
|
||||
}
|
||||
|
||||
private static void ExportShowdownText(SaveFile SAV, string success, Func<SaveFile, IEnumerable<PKM>> func)
|
||||
private static void ExportShowdownText(SaveFile sav, string success, Func<SaveFile, IEnumerable<PKM>> fetch)
|
||||
{
|
||||
var pkms = func(SAV);
|
||||
var str = ShowdownSet.GetShowdownSets(pkms, Environment.NewLine + Environment.NewLine);
|
||||
if (string.IsNullOrWhiteSpace(str)) return;
|
||||
if (WinFormsUtil.SetClipboardText(str))
|
||||
var list = fetch(sav);
|
||||
var result = ShowdownSet.GetShowdownSets(list, Environment.NewLine + Environment.NewLine);
|
||||
if (string.IsNullOrWhiteSpace(result))
|
||||
return;
|
||||
if (WinFormsUtil.SetClipboardText(result))
|
||||
WinFormsUtil.Alert(success);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ using PKHeX.Drawing;
|
|||
namespace PKHeX.WinForms
|
||||
{
|
||||
/// <summary>
|
||||
/// Bindable summary object that can fetch sprite and strings that summarize a <see cref="PKM"/>.
|
||||
/// Bind-able summary object that can fetch sprite and strings that summarize a <see cref="PKM"/>.
|
||||
/// </summary>
|
||||
public class PKMSummaryImage : PKMSummary
|
||||
{
|
||||
|
|
|
@ -236,7 +236,7 @@ namespace PKHeX.WinForms
|
|||
{
|
||||
for (int i = 0; i < data.Count; i++)
|
||||
{
|
||||
editor.ProcessPKM(data[i], Filters, Instructions);
|
||||
editor.Process(data[i], Filters, Instructions);
|
||||
b.ReportProgress(i);
|
||||
}
|
||||
}
|
||||
|
@ -256,7 +256,7 @@ namespace PKHeX.WinForms
|
|||
int format = PKX.GetPKMFormatFromExtension(fi.Extension, SAV.Generation);
|
||||
byte[] data = File.ReadAllBytes(file);
|
||||
var pk = PKMConverter.GetPKMfromBytes(data, prefer: format);
|
||||
if (editor.ProcessPKM(pk, Filters, Instructions))
|
||||
if (editor.Process(pk, Filters, Instructions))
|
||||
File.WriteAllBytes(Path.Combine(destPath, Path.GetFileName(file)), pk.DecryptedPartyData);
|
||||
|
||||
b.ReportProgress(i);
|
||||
|
|
Loading…
Reference in a new issue