mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-05-09 04:24:36 -05:00
Remove unnecessary null checks
this is a null free project /s dont provide null, else u deserve to get an exception
This commit is contained in:
parent
8312c52cc1
commit
843330a375
|
|
@ -124,6 +124,6 @@ protected PKMSummary(PKM p, GameStrings strings)
|
|||
/// <param name="arr">Array of strings</param>
|
||||
/// <param name="val">Index to fetch</param>
|
||||
/// <returns>Null if array is null</returns>
|
||||
private static string Get(IReadOnlyList<string> arr, int val) => (uint)val < arr?.Count ? arr[val] : string.Empty;
|
||||
private static string Get(IReadOnlyList<string> arr, int val) => (uint)val < arr.Count ? arr[val] : string.Empty;
|
||||
}
|
||||
}
|
||||
|
|
@ -50,7 +50,7 @@ private static string GetCountryName(int countryID, int l)
|
|||
if (countryID >= CountryList.Length)
|
||||
return INVALID;
|
||||
var countryNames = CountryList[countryID];
|
||||
if (l < countryNames?.Length)
|
||||
if (l < countryNames.Length)
|
||||
return countryNames[l + 1];
|
||||
return INVALID;
|
||||
}
|
||||
|
|
@ -71,7 +71,7 @@ private static string GetRegionName(int countryID, int regionID, int l)
|
|||
if (regionID >= regionstrs.Length)
|
||||
return INVALID;
|
||||
var localized = regionstrs[regionID];
|
||||
if (l < localized?.Length)
|
||||
if (l < localized.Length)
|
||||
return localized[l + 1];
|
||||
return INVALID;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ public static IEnumerable<PKM> GeneratePKMs(PKM pk, ITrainerInfo info, int[]? mo
|
|||
{
|
||||
pk.TID = info.TID;
|
||||
var m = moves ?? pk.Moves;
|
||||
var vers = versions?.Length >= 1 ? versions : GameUtil.GetVersionsWithinRange(pk, pk.Format);
|
||||
var vers = versions.Length >= 1 ? versions : GameUtil.GetVersionsWithinRange(pk, pk.Format);
|
||||
foreach (var ver in vers)
|
||||
{
|
||||
var encs = GenerateVersionEncounters(pk, m, ver);
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ public sealed class CK3 : G3PKM, IShadowPKM
|
|||
private byte[] SetString(string value, int maxLength) => StringConverter3.SetBEString3(value, maxLength);
|
||||
|
||||
// Trash Bytes
|
||||
public override byte[] Nickname_Trash { get => GetData(0x2E, 20); set { if (value?.Length == 20) value.CopyTo(Data, 0x2E); } }
|
||||
public override byte[] OT_Trash { get => GetData(0x18, 20); set { if (value?.Length == 20) value.CopyTo(Data, 0x18); } }
|
||||
public override byte[] Nickname_Trash { get => GetData(0x2E, 20); set { if (value.Length == 20) value.CopyTo(Data, 0x2E); } }
|
||||
public override byte[] OT_Trash { get => GetData(0x18, 20); set { if (value.Length == 20) value.CopyTo(Data, 0x18); } }
|
||||
|
||||
// Future Attributes
|
||||
|
||||
|
|
|
|||
|
|
@ -44,8 +44,8 @@ public override PKM Clone()
|
|||
private const string EggNameJapanese = "タマゴ";
|
||||
|
||||
// Trash Bytes
|
||||
public override byte[] Nickname_Trash { get => GetData(0x08, 10); set { if (value?.Length == 10) value.CopyTo(Data, 0x08); } }
|
||||
public override byte[] OT_Trash { get => GetData(0x14, 7); set { if (value?.Length == 7) value.CopyTo(Data, 0x14); } }
|
||||
public override byte[] Nickname_Trash { get => GetData(0x08, 10); set { if (value.Length == 10) value.CopyTo(Data, 0x08); } }
|
||||
public override byte[] OT_Trash { get => GetData(0x14, 7); set { if (value.Length == 7) value.CopyTo(Data, 0x14); } }
|
||||
|
||||
// At top for System.Reflection execution order hack
|
||||
|
||||
|
|
|
|||
|
|
@ -42,8 +42,8 @@ public PK5(byte[] data)
|
|||
private byte[] SetString(string value, int maxLength) => StringConverter.SetString5(value, maxLength);
|
||||
|
||||
// Trash Bytes
|
||||
public override byte[] Nickname_Trash { get => GetData(0x48, 22); set { if (value?.Length == 22) value.CopyTo(Data, 0x48); } }
|
||||
public override byte[] OT_Trash { get => GetData(0x68, 16); set { if (value?.Length == 16) value.CopyTo(Data, 0x68); } }
|
||||
public override byte[] Nickname_Trash { get => GetData(0x48, 22); set { if (value.Length == 22) value.CopyTo(Data, 0x48); } }
|
||||
public override byte[] OT_Trash { get => GetData(0x68, 16); set { if (value.Length == 16) value.CopyTo(Data, 0x68); } }
|
||||
|
||||
// Future Attributes
|
||||
public override uint EncryptionConstant { get => PID; set { } }
|
||||
|
|
|
|||
|
|
@ -65,9 +65,9 @@ public PK8(byte[] data)
|
|||
public override int SIZE_STORED => PokeCrypto.SIZE_8STORED;
|
||||
|
||||
// Trash Bytes
|
||||
public override byte[] Nickname_Trash { get => GetData(0x58, 24); set { if (value?.Length == 24) value.CopyTo(Data, 0x58); } }
|
||||
public override byte[] HT_Trash { get => GetData(0xA8, 24); set { if (value?.Length == 24) value.CopyTo(Data, 0xA8); } }
|
||||
public override byte[] OT_Trash { get => GetData(0xF8, 24); set { if (value?.Length == 24) value.CopyTo(Data, 0xF8); } }
|
||||
public override byte[] Nickname_Trash { get => GetData(0x58, 24); set { if (value.Length == 24) value.CopyTo(Data, 0x58); } }
|
||||
public override byte[] HT_Trash { get => GetData(0xA8, 24); set { if (value.Length == 24) value.CopyTo(Data, 0xA8); } }
|
||||
public override byte[] OT_Trash { get => GetData(0xF8, 24); set { if (value.Length == 24) value.CopyTo(Data, 0xF8); } }
|
||||
public override bool WasLink => Met_Location == Locations.LinkGift6 && Gen6;
|
||||
public override bool WasEvent => Locations.IsEventLocation5(Met_Location) || FatefulEncounter;
|
||||
public override bool WasEventEgg => GenNumber < 5 ? base.WasEventEgg : (Locations.IsEventLocation5(Egg_Location) || (FatefulEncounter && Egg_Location == Locations.LinkTrade6)) && Met_Level == 1;
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ public override int Characteristic
|
|||
}
|
||||
|
||||
// Trash Bytes
|
||||
public override byte[] Nickname_Trash { get => GetData(0x48, 22); set { if (value?.Length == 22) value.CopyTo(Data, 0x48); } }
|
||||
public override byte[] OT_Trash { get => GetData(0x68, 16); set { if (value?.Length == 16) value.CopyTo(Data, 0x68); } }
|
||||
public override byte[] Nickname_Trash { get => GetData(0x48, 22); set { if (value.Length == 22) value.CopyTo(Data, 0x48); } }
|
||||
public override byte[] OT_Trash { get => GetData(0x68, 16); set { if (value.Length == 16) value.CopyTo(Data, 0x68); } }
|
||||
|
||||
// Future Attributes
|
||||
public override uint EncryptionConstant { get => PID; set { } }
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ public abstract class G6PKM : PKM
|
|||
public override int SIZE_STORED => PokeCrypto.SIZE_6STORED;
|
||||
|
||||
// Trash Bytes
|
||||
public override byte[] Nickname_Trash { get => GetData(0x40, 24); set { if (value?.Length == 24) value.CopyTo(Data, 0x40); } }
|
||||
public override byte[] HT_Trash { get => GetData(0x78, 24); set { if (value?.Length == 24) value.CopyTo(Data, 0x78); } }
|
||||
public override byte[] OT_Trash { get => GetData(0xB0, 24); set { if (value?.Length == 24) value.CopyTo(Data, 0xB0); } }
|
||||
public override byte[] Nickname_Trash { get => GetData(0x40, 24); set { if (value.Length == 24) value.CopyTo(Data, 0x40); } }
|
||||
public override byte[] HT_Trash { get => GetData(0x78, 24); set { if (value.Length == 24) value.CopyTo(Data, 0x78); } }
|
||||
public override byte[] OT_Trash { get => GetData(0xB0, 24); set { if (value.Length == 24) value.CopyTo(Data, 0xB0); } }
|
||||
|
||||
protected override ushort CalculateChecksum()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -51,8 +51,8 @@ protected GBPKM(byte[] data, bool jp = false)
|
|||
internal byte[] nick;
|
||||
|
||||
// Trash Bytes
|
||||
public override byte[] Nickname_Trash { get => nick; set { if (value?.Length == nick.Length) nick = value; } }
|
||||
public override byte[] OT_Trash { get => otname; set { if (value?.Length == otname.Length) otname = value; } }
|
||||
public override byte[] Nickname_Trash { get => nick; set { if (value.Length == nick.Length) nick = value; } }
|
||||
public override byte[] OT_Trash { get => otname; set { if (value.Length == otname.Length) otname = value; } }
|
||||
|
||||
public override byte[] EncryptedPartyData => Encrypt();
|
||||
public override byte[] EncryptedBoxData => Encrypt();
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public static partial class Extensions
|
|||
{
|
||||
public static void SetContestStats(this IContestStats dest, int[] stats)
|
||||
{
|
||||
if (stats?.Length != 6)
|
||||
if (stats.Length != 6)
|
||||
return;
|
||||
|
||||
dest.CNT_Cool = stats[0];
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@ public sealed class XK3 : G3PKM, IShadowPKM
|
|||
private byte[] SetString(string value, int maxLength) => StringConverter3.SetBEString3(value, maxLength);
|
||||
|
||||
// Trash Bytes
|
||||
public override byte[] Nickname_Trash { get => GetData(0x4E, 20); set { if (value?.Length == 20) value.CopyTo(Data, 0x4E); } }
|
||||
public override byte[] OT_Trash { get => GetData(0x38, 20); set { if (value?.Length == 20) value.CopyTo(Data, 0x38); } }
|
||||
public override byte[] Nickname_Trash { get => GetData(0x4E, 20); set { if (value.Length == 20) value.CopyTo(Data, 0x4E); } }
|
||||
public override byte[] OT_Trash { get => GetData(0x38, 20); set { if (value.Length == 20) value.CopyTo(Data, 0x38); } }
|
||||
|
||||
// Silly Attributes
|
||||
public override ushort Sanity { get => 0; set { } } // valid flag set in pkm structure.
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ public int[] Types
|
|||
get => new[] { Type1, Type2 };
|
||||
set
|
||||
{
|
||||
if (value?.Length != 2) return;
|
||||
if (value.Length != 2) return;
|
||||
Type1 = value[0];
|
||||
Type2 = value[1];
|
||||
}
|
||||
|
|
@ -219,7 +219,7 @@ public int[] EggGroups
|
|||
get => new[] { EggGroup1, EggGroup2 };
|
||||
set
|
||||
{
|
||||
if (value?.Length != 2) return;
|
||||
if (value.Length != 2) return;
|
||||
EggGroup1 = (byte)value[0];
|
||||
EggGroup2 = (byte)value[1];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ public override int[] Items
|
|||
get => new[] { Item1, Item2, Item3 };
|
||||
set
|
||||
{
|
||||
if (value?.Length != 3) return;
|
||||
if (value.Length != 3) return;
|
||||
Item1 = value[0];
|
||||
Item2 = value[1];
|
||||
Item3 = value[2];
|
||||
|
|
@ -82,7 +82,7 @@ public override int[] Abilities
|
|||
get => new[] { Ability1, Ability2, AbilityH };
|
||||
set
|
||||
{
|
||||
if (value?.Length != 3) return;
|
||||
if (value.Length != 3) return;
|
||||
Ability1 = (byte)value[0];
|
||||
Ability2 = (byte)value[1];
|
||||
AbilityH = (byte)value[2];
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public int[] Moves
|
|||
get => new[] { Move1, Move2, Move3, Move4 };
|
||||
set
|
||||
{
|
||||
if (value?.Length != 4) return;
|
||||
if (value.Length != 4) return;
|
||||
Move1 = value[0];
|
||||
Move2 = value[1];
|
||||
Move3 = value[2];
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public override int[] Items
|
|||
get => new[] { Item1, Item2 };
|
||||
set
|
||||
{
|
||||
if (value?.Length != 2) return;
|
||||
if (value.Length != 2) return;
|
||||
Item1 = value[0];
|
||||
Item2 = value[1];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ public override int[] Items
|
|||
get => new[] { Item1, Item2 };
|
||||
set
|
||||
{
|
||||
if (value?.Length != 2) return;
|
||||
if (value.Length != 2) return;
|
||||
Item1 = value[0];
|
||||
Item2 = value[1];
|
||||
}
|
||||
|
|
@ -62,7 +62,7 @@ public override int[] Abilities
|
|||
get => new[] { Ability1, Ability2 };
|
||||
set
|
||||
{
|
||||
if (value?.Length != 2) return;
|
||||
if (value.Length != 2) return;
|
||||
Ability1 = (byte)value[0];
|
||||
Ability2 = (byte)value[1];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ public override int[] Items
|
|||
get => new[] { Item1, Item2, Item3 };
|
||||
set
|
||||
{
|
||||
if (value?.Length != 3) return;
|
||||
if (value.Length != 3) return;
|
||||
Item1 = value[0];
|
||||
Item2 = value[1];
|
||||
Item3 = value[2];
|
||||
|
|
@ -94,7 +94,7 @@ public override int[] Abilities
|
|||
get => new[] { Ability1, Ability2, AbilityH };
|
||||
set
|
||||
{
|
||||
if (value?.Length != 3) return;
|
||||
if (value.Length != 3) return;
|
||||
Ability1 = value[0];
|
||||
Ability2 = value[1];
|
||||
AbilityH = value[2];
|
||||
|
|
|
|||
|
|
@ -238,7 +238,7 @@ public override string OT
|
|||
set => SetString(value, OTLength).CopyTo(Data, Offsets.OT);
|
||||
}
|
||||
|
||||
public byte[] OT_Trash { get => GetData(Offsets.OT, StringLength); set { if (value?.Length == StringLength) SetData(value, Offsets.OT); } }
|
||||
public byte[] OT_Trash { get => GetData(Offsets.OT, StringLength); set { if (value.Length == StringLength) SetData(value, Offsets.OT); } }
|
||||
|
||||
public override int Gender
|
||||
{
|
||||
|
|
|
|||
|
|
@ -322,7 +322,7 @@ public override string OT
|
|||
public byte[] OT_Trash
|
||||
{
|
||||
get => GetData(Offsets.Trainer1 + 2, StringLength);
|
||||
set { if (value?.Length == StringLength) SetData(value, Offsets.Trainer1 + 2); }
|
||||
set { if (value.Length == StringLength) SetData(value, Offsets.Trainer1 + 2); }
|
||||
}
|
||||
|
||||
public override int Gender
|
||||
|
|
|
|||
|
|
@ -556,7 +556,7 @@ protected override bool[] MysteryGiftReceivedFlags
|
|||
}
|
||||
set
|
||||
{
|
||||
if (GiftFlagMax != value?.Length)
|
||||
if (GiftFlagMax != value.Length)
|
||||
return;
|
||||
|
||||
byte[] data = new byte[value.Length / 8];
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ private bool[] MysteryGiftDPSlotActiveFlags
|
|||
}
|
||||
set
|
||||
{
|
||||
if (value?.Length != GiftCountMax)
|
||||
if (value.Length != GiftCountMax)
|
||||
return;
|
||||
|
||||
int ofs = WondercardFlags + 0x100; // skip over flags
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public string[] PlayerNames
|
|||
}
|
||||
set
|
||||
{
|
||||
if (value?.Length != 4)
|
||||
if (value.Length != 4)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public string[] PlayerNames
|
|||
}
|
||||
set
|
||||
{
|
||||
if (value?.Length != 4)
|
||||
if (value.Length != 4)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ public int[] IVs
|
|||
get => new[] { IV_HP, IV_ATK, IV_DEF, IV_SPE, IV_SPA, IV_SPD };
|
||||
set
|
||||
{
|
||||
if (value?.Length != 6) return;
|
||||
if (value.Length != 6) return;
|
||||
IV_HP = value[0]; IV_ATK = value[1]; IV_DEF = value[2];
|
||||
IV_SPE = value[3]; IV_SPA = value[4]; IV_SPD = value[5];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public bool[] MysteryGiftReceivedFlags
|
|||
get => ArrayUtil.GitBitFlagArray(Data, Offset + FlagStart, MaxReceivedFlag);
|
||||
set
|
||||
{
|
||||
if (value?.Length != MaxReceivedFlag)
|
||||
if (value.Length != MaxReceivedFlag)
|
||||
return;
|
||||
ArrayUtil.SetBitFlagArray(Data, Offset + FlagStart, value);
|
||||
SAV.Edited = true;
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ public string NexUniqueID
|
|||
get => Data.Skip(Offset + 0x28).Take(4).Concat(Data.Skip(Offset + 0x18).Take(8)).ToArray();
|
||||
set
|
||||
{
|
||||
if (value?.Length != 12)
|
||||
if (value.Length != 12)
|
||||
return;
|
||||
Array.Copy(value, 0, Data, Offset + 0x28, 4);
|
||||
Array.Copy(value, 4, Data, Offset + 0x18, 8);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public bool[] MysteryGiftReceivedFlags
|
|||
get => ArrayUtil.GitBitFlagArray(Data, Offset + FlagStart, MaxReceivedFlag);
|
||||
set
|
||||
{
|
||||
if (value?.Length != MaxReceivedFlag)
|
||||
if (value.Length != MaxReceivedFlag)
|
||||
return;
|
||||
ArrayUtil.SetBitFlagArray(Data, Offset + FlagStart, value);
|
||||
SAV.Edited = true;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public PKM[] ResortPKM
|
|||
}
|
||||
set
|
||||
{
|
||||
if (value?.Length != ResortCount)
|
||||
if (value.Length != ResortCount)
|
||||
throw new ArgumentException(nameof(ResortCount));
|
||||
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ public static IEnumerable<SaveFile> GetSaveFiles(IReadOnlyList<string> drives, b
|
|||
|
||||
public static IEnumerable<string> GetFoldersToCheck(IReadOnlyList<string> drives, IEnumerable<string> extra)
|
||||
{
|
||||
var foldersToCheck = extra.Where(f => f?.Length > 0).Concat(CustomBackupPaths);
|
||||
var foldersToCheck = extra.Where(f => f.Length > 0).Concat(CustomBackupPaths);
|
||||
|
||||
string path3DS = Path.GetPathRoot(Get3DSLocation(drives));
|
||||
if (path3DS != null) // check for Homebrew/CFW backups
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user