mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-10-02 12:36:44 -05:00
Minor clean
Remove unnecessary null checks Mark some methods with nullable type
This commit is contained in:
@@ -38,8 +38,6 @@ public static int[] GetMoveSet(this PKM pk, bool random = false)
|
||||
public static int[] GetMoveSet(this PKM pk, LegalityAnalysis la, bool random = false)
|
||||
{
|
||||
int[] m = la.GetSuggestedMoves(tm: random, tutor: random, reminder: random);
|
||||
if (m == null)
|
||||
return pk.Moves;
|
||||
|
||||
if (!m.All(z => la.AllSuggestedMovesAndRelearn().Contains(z)))
|
||||
m = m.Intersect(la.AllSuggestedMovesAndRelearn()).ToArray();
|
||||
|
||||
@@ -41,7 +41,7 @@ public static uint GetWurmpleEC(int evoVal)
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks to see if the input <see cref="pkm"/>, with species being that of Wurmple's evo chain, is valid.
|
||||
/// Checks to see if the input <see cref="pkm"/>, with species being that of Wurmple's evo chain, is valid.
|
||||
/// </summary>
|
||||
/// <param name="pkm">Pokémon data</param>
|
||||
/// <returns>True if valid, false if invalid</returns>
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace PKHeX.Core
|
||||
/// </summary>
|
||||
public static class GameInfo
|
||||
{
|
||||
private static readonly GameStrings[] Languages = new GameStrings[GameLanguage.LanguageCount];
|
||||
private static readonly GameStrings?[] Languages = new GameStrings[GameLanguage.LanguageCount];
|
||||
|
||||
public static string CurrentLanguage { get; set; } = GameLanguage.DefaultLanguage;
|
||||
public static readonly IReadOnlyList<string> GenderSymbolUnicode = new[] {"♂", "♀", "-"};
|
||||
|
||||
@@ -42,7 +42,7 @@ public static string GetTransporterName(int index)
|
||||
public static string[] GetStrings(string ident, string lang, string type = "text")
|
||||
{
|
||||
string[] data = Util.GetStringList(ident, lang, type);
|
||||
if (data == null || data.Length == 0)
|
||||
if (data.Length == 0)
|
||||
data = Util.GetStringList(ident, DefaultLanguage, type);
|
||||
|
||||
return data;
|
||||
|
||||
@@ -61,13 +61,7 @@ private static string GetRegionName(int countryID, int regionID, int l)
|
||||
return INVALID;
|
||||
if (countryID >= RegionList.Length)
|
||||
return INVALID;
|
||||
var regionstrs = RegionList[countryID];
|
||||
if (regionstrs == null)
|
||||
{
|
||||
regionstrs = RegionList[countryID] = GetRegionList(countryID);
|
||||
if (regionstrs == null)
|
||||
return INVALID;
|
||||
}
|
||||
var regionstrs = RegionList[countryID] ?? (RegionList[countryID] = GetRegionList(countryID));
|
||||
if (regionID >= regionstrs.Length)
|
||||
return INVALID;
|
||||
var localized = regionstrs[regionID];
|
||||
|
||||
@@ -267,7 +267,7 @@ private static IEnumerable<EncounterTrade> GetTrades(PKM pk, IReadOnlyCollection
|
||||
continue;
|
||||
}
|
||||
var em = trade.Moves;
|
||||
if (em != null && !needs.Except(em).Any())
|
||||
if (!needs.Except(em).Any())
|
||||
yield return trade;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ private static bool IsHiddenAbilitySlot(this EncounterSlot slot)
|
||||
return slot.Permissions.DexNav || slot.Type == SlotType.FriendSafari || slot.Type == SlotType.Horde || slot.Type == SlotType.SOS;
|
||||
}
|
||||
|
||||
internal static EncounterArea GetCaptureLocation(PKM pkm)
|
||||
internal static EncounterArea? GetCaptureLocation(PKM pkm)
|
||||
{
|
||||
var vs = EvolutionChain.GetValidPreEvolutions(pkm);
|
||||
return (from area in GetEncounterSlots(pkm)
|
||||
|
||||
@@ -146,7 +146,7 @@ private static EncounterStatic GetGSStaticTransfer(int species, int pkmMetLevel)
|
||||
};
|
||||
}
|
||||
|
||||
internal static EncounterStatic GetStaticLocation(PKM pkm, int species = -1)
|
||||
internal static EncounterStatic? GetStaticLocation(PKM pkm, int species = -1)
|
||||
{
|
||||
switch (pkm.GenNumber)
|
||||
{
|
||||
|
||||
@@ -44,8 +44,6 @@ public static IEnumerable<string> GetLearnSummary(string species, IEnumerable<st
|
||||
public static IEnumerable<IEncounterable> GetLearn(string species, IEnumerable<string> moves, string lang = GameLanguage.DefaultLanguage)
|
||||
{
|
||||
var str = GameInfo.GetStrings(lang);
|
||||
if (str == null)
|
||||
return Array.Empty<IEncounterable>();
|
||||
|
||||
var spec = StringUtil.FindIndexIgnoreCase(str.specieslist, species);
|
||||
var moveIDs = StringUtil.GetIndexes(str.movelist, moves.ToList());
|
||||
|
||||
@@ -184,7 +184,6 @@ public static int GetLowestLevel(PKM pkm, int startLevel)
|
||||
return startLevel;
|
||||
}
|
||||
|
||||
|
||||
public static int GetSuggestedMetLevel(PKM pkm, int minLevel)
|
||||
{
|
||||
var clone = pkm.Clone();
|
||||
|
||||
@@ -6,11 +6,11 @@ namespace PKHeX.Core
|
||||
{
|
||||
public static class MysteryGiftVerifier
|
||||
{
|
||||
private static readonly Dictionary<int, MysteryGiftRestriction>[] RestrictionSet = Get();
|
||||
private static readonly Dictionary<int, MysteryGiftRestriction>?[] RestrictionSet = Get();
|
||||
|
||||
private static Dictionary<int, MysteryGiftRestriction>[] Get()
|
||||
private static Dictionary<int, MysteryGiftRestriction>?[] Get()
|
||||
{
|
||||
var s = new Dictionary<int, MysteryGiftRestriction>[PKX.Generation + 1];
|
||||
var s = new Dictionary<int, MysteryGiftRestriction>?[PKX.Generation + 1];
|
||||
for (int i = 3; i < s.Length; i++)
|
||||
s[i] = GetRestriction(i);
|
||||
return s;
|
||||
|
||||
@@ -239,7 +239,7 @@ public static void CryptArray(byte[] data, uint seed, int start, int end)
|
||||
public static void CryptArray(byte[] data, uint seed) => CryptArray(data, seed, 0, data.Length);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static void Crypt(in byte[] data, ref uint seed, in int i)
|
||||
private static void Crypt(byte[] data, ref uint seed, in int i)
|
||||
{
|
||||
seed = (0x41C64E6D * seed) + 0x00006073;
|
||||
data[i] ^= (byte)(seed >> 16);
|
||||
|
||||
@@ -81,7 +81,7 @@ public SAV3(GameVersion version = GameVersion.FRLG, bool japanese = false) : bas
|
||||
Version = GameVersion.RS;
|
||||
else
|
||||
Version = version;
|
||||
_personal = SaveUtil.GetG3Personal(Version) ?? PersonalTable.RS;
|
||||
_personal = SaveUtil.GetG3Personal(Version);
|
||||
Japanese = japanese;
|
||||
|
||||
LoadBlocks(out BlockOrder, out BlockOfs);
|
||||
@@ -105,7 +105,7 @@ public SAV3(byte[] data, GameVersion versionOverride = GameVersion.Any) : base(d
|
||||
{
|
||||
LoadBlocks(out BlockOrder, out BlockOfs);
|
||||
Version = versionOverride != GameVersion.Any ? versionOverride : GetVersion(Data, BlockOfs[0]);
|
||||
_personal = SaveUtil.GetG3Personal(Version) ?? PersonalTable.RS;
|
||||
_personal = SaveUtil.GetG3Personal(Version);
|
||||
|
||||
// Japanese games are limited to 5 character OT names; any unused characters are 0xFF.
|
||||
// 5 for JP, 7 for INT. There's always 1 terminator, thus we can check 0x6-0x7 being 0xFFFF = INT
|
||||
|
||||
@@ -158,7 +158,7 @@ public override SaveFile Clone()
|
||||
|
||||
// Checksums
|
||||
private readonly SHA1 sha1 = SHA1.Create();
|
||||
public void Dispose() => sha1?.Dispose();
|
||||
public void Dispose() => sha1.Dispose();
|
||||
|
||||
private byte[] EncryptColosseum(byte[] input, byte[] digest)
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ public sealed class StrategyMemo
|
||||
private readonly List<StrategyMemoEntry> Entries = new List<StrategyMemoEntry>();
|
||||
public const int MAX_COUNT = 500;
|
||||
public const int MAX_SIZE = MAX_COUNT * SIZE_ENTRY;
|
||||
private StrategyMemoEntry this[int Species] => Entries.Find(e => e.Species == Species);
|
||||
private StrategyMemoEntry? this[int Species] => Entries.Find(e => e.Species == Species);
|
||||
private readonly byte[] _unk;
|
||||
|
||||
public StrategyMemo(bool xd = true) : this(new byte[MAX_SIZE], 0, xd) { }
|
||||
|
||||
@@ -17,7 +17,7 @@ public static class SaveDetection
|
||||
/// <param name="skipFirstDrive">Optional parameter to skip the first drive.
|
||||
/// The first drive is usually the system hard drive, or can be a floppy disk drive (slower to check, never has expected data).</param>
|
||||
/// <returns>Folder path pointing to the Nintendo 3DS folder.</returns>
|
||||
public static string Get3DSLocation(IEnumerable<string> drives, bool skipFirstDrive = true) =>
|
||||
public static string? Get3DSLocation(IEnumerable<string> drives, bool skipFirstDrive = true) =>
|
||||
FindConsoleRootFolder(drives, "Nintendo 3DS", skipFirstDrive);
|
||||
|
||||
/// <summary>
|
||||
@@ -27,10 +27,10 @@ public static class SaveDetection
|
||||
/// <param name="skipFirstDrive">Optional parameter to skip the first drive.
|
||||
/// The first drive is usually the system hard drive, or can be a floppy disk drive (slower to check, never has expected data).</param>
|
||||
/// <returns>Folder path pointing to the Nintendo folder.</returns>
|
||||
public static string GetSwitchLocation(IEnumerable<string> drives, bool skipFirstDrive = true) =>
|
||||
public static string? GetSwitchLocation(IEnumerable<string> drives, bool skipFirstDrive = true) =>
|
||||
FindConsoleRootFolder(drives, "Nintendo", skipFirstDrive);
|
||||
|
||||
private static string FindConsoleRootFolder(IEnumerable<string> drives, string path, bool skipFirstDrive)
|
||||
private static string? FindConsoleRootFolder(IEnumerable<string> drives, string path, bool skipFirstDrive)
|
||||
{
|
||||
if (skipFirstDrive)
|
||||
drives = drives.Skip(1);
|
||||
|
||||
@@ -347,7 +347,8 @@ private void SaveHandlingTrainer(PKM pk)
|
||||
// Misc
|
||||
private static void CheckTransferPIDValid(PKM pk)
|
||||
{
|
||||
if (pk.Version >= 24 && pk.Version != 0)
|
||||
var ver = pk.Version;
|
||||
if (ver >= (int)GameVersion.X || ver == 0)
|
||||
return;
|
||||
|
||||
uint EC = pk.EncryptionConstant;
|
||||
|
||||
@@ -288,7 +288,7 @@ public void UpdateLegality(LegalityAnalysis la = null, bool skipMoveRepop = fals
|
||||
var moves = Entity.Moves;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
bool invalid = !Legality.Info?.Moves[i]?.Valid ?? false;
|
||||
bool invalid = !Legality.Info?.Moves[i].Valid ?? false;
|
||||
|
||||
Bitmap img;
|
||||
if (invalid)
|
||||
@@ -304,7 +304,7 @@ public void UpdateLegality(LegalityAnalysis la = null, bool skipMoveRepop = fals
|
||||
if (Entity.Format >= 6)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
relearnPB[i].Visible = !Legality.Info?.Relearn[i]?.Valid ?? false;
|
||||
relearnPB[i].Visible = !Legality.Info?.Relearn[i].Valid ?? false;
|
||||
}
|
||||
|
||||
if (skipMoveRepop)
|
||||
@@ -704,7 +704,7 @@ private void ClickMoves(object sender, EventArgs e)
|
||||
private bool SetSuggestedMoves(bool random = false, bool silent = false)
|
||||
{
|
||||
int[] m = Entity.GetMoveSet(random);
|
||||
if (m?.Any(z => z != 0) != true)
|
||||
if (m.Any(z => z != 0) != true)
|
||||
{
|
||||
if (!silent)
|
||||
WinFormsUtil.Alert(MsgPKMSuggestionFormat);
|
||||
|
||||
@@ -95,7 +95,7 @@ public ItemVisibility(ToolStripItem toolStripItem, IBoxManip visible)
|
||||
Manip = visible;
|
||||
}
|
||||
|
||||
public void SetVisibility(SaveFile s) => Item.Visible = Manip.Usable?.Invoke(s) ?? true;
|
||||
public void SetVisibility(SaveFile s) => Item.Visible = Manip.Usable(s);
|
||||
}
|
||||
|
||||
public void ToggleVisibility()
|
||||
|
||||
@@ -992,8 +992,6 @@ private void ExportQRFromTabs()
|
||||
}
|
||||
|
||||
var qr = QREncode.GenerateQRCode(pk);
|
||||
if (qr == null)
|
||||
return;
|
||||
|
||||
var sprite = dragout.Image;
|
||||
var la = new LegalityAnalysis(pk, C_SAV.SAV.Personal);
|
||||
|
||||
@@ -221,7 +221,7 @@ private void SetEntry()
|
||||
}
|
||||
|
||||
var forms = SAV.GetForms(species);
|
||||
if (forms != null)
|
||||
if (forms.Length > 0)
|
||||
{
|
||||
int[] arr = new int[LB_Form.Items.Count];
|
||||
string[] formNames = GetFormNames4Dex(species);
|
||||
|
||||
@@ -80,7 +80,7 @@ private void LoadUnlockedCount()
|
||||
private void LoadFlags()
|
||||
{
|
||||
byte[] flags = SAV.BoxFlags;
|
||||
if (flags == null || flags.Length == 0)
|
||||
if (flags.Length == 0)
|
||||
{
|
||||
FLP_Flags.Visible = false;
|
||||
return;
|
||||
|
||||
@@ -332,8 +332,6 @@ private void ExportQRFromView()
|
||||
}
|
||||
|
||||
Image qr = QREncode.GenerateQRCode(mg);
|
||||
if (qr == null)
|
||||
return;
|
||||
|
||||
string desc = $"({mg.Type}) {string.Join(Environment.NewLine, mg.GetDescription())}";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user