static analysis fixes

fixes the friend safari form checks (if else were chained incorrectly)
argumentorder of some unused sections (BV date, canlearnmachinemove)
This commit is contained in:
Kurt 2017-03-20 00:03:31 -07:00
parent 55e8732740
commit 127d2c2aaa
15 changed files with 42 additions and 31 deletions

View file

@ -297,7 +297,8 @@ namespace PKHeX.WinForms
// Select Language
string l = Settings.Language;
int lang = Array.IndexOf(GameInfo.lang_val, l);
if (lang < 0) Array.IndexOf(GameInfo.lang_val, "en");
if (lang < 0)
lang = Array.IndexOf(GameInfo.lang_val, "en");
if (lang > -1)
languageID = lang;
@ -2998,10 +2999,10 @@ namespace PKHeX.WinForms
// Refresh Move Legality
for (int i = 0; i < 4; i++)
movePB[i].Visible = !Legality.vMoves[i].Valid && !HaX;
movePB[i].Visible = !Legality.vMoves[i].Valid;
for (int i = 0; i < 4; i++)
relearnPB[i].Visible = !Legality.vRelearn[i].Valid && !HaX && pkm.Format >= 6;
relearnPB[i].Visible = !Legality.vRelearn[i].Valid && pkm.Format >= 6;
if (skipMoveRepop)
return;
@ -3465,7 +3466,7 @@ namespace PKHeX.WinForms
setParty();
getSlotColor(slot, Resources.slotSet);
}
else if (slot < 30 || HaX && slot >= 36 && slot < 42)
else if (slot < 30 || HaX)
{
if (slot < 30)
{
@ -3509,7 +3510,7 @@ namespace PKHeX.WinForms
getSlotColor(slot, Resources.slotDel);
return;
}
if (slot < 30 || HaX && slot >= 36 && slot < 42)
if (slot < 30 || HaX)
{
if (slot < 30)
{

View file

@ -127,7 +127,7 @@ namespace PKHeX.WinForms
else if (abils[0] == abils[1] || abils[1] == 0)
CB_Ability.SelectedIndex = pk4.PIDAbility;
else
CB_Ability.SelectedIndex = abil < 0 || abil >= CB_Ability.Items.Count ? 0 : abil;
CB_Ability.SelectedIndex = abil >= CB_Ability.Items.Count ? 0 : abil;
}
}
private PKM preparePK4()
@ -364,7 +364,7 @@ namespace PKHeX.WinForms
else if (abils[0] == abils[1] || abils[1] == 0)
CB_Ability.SelectedIndex = pk4.PIDAbility;
else
CB_Ability.SelectedIndex = abil < 0 || abil >= CB_Ability.Items.Count ? 0 : abil;
CB_Ability.SelectedIndex = abil >= CB_Ability.Items.Count ? 0 : abil;
}
}
private PKM prepareBK4()

View file

@ -140,7 +140,7 @@ namespace PKHeX.WinForms
else if (abils[0] == abils[1] || abils[1] == 0)
CB_Ability.SelectedIndex = pk5.PIDAbility;
else
CB_Ability.SelectedIndex = abil < 0 || abil >= CB_Ability.Items.Count ? 0 : abil;
CB_Ability.SelectedIndex = abil >= CB_Ability.Items.Count ? 0 : abil;
}
}
private PKM preparePK5()

View file

@ -23,6 +23,7 @@ namespace PKHeX.WinForms
{
WinFormsUtil.Alert("Invalid save file / Link Information");
Close();
return;
}
data = data.Skip(0x1FF).Take(PL6.Size).ToArray();
loadLinkData(data);

View file

@ -236,7 +236,7 @@ namespace PKHeX.WinForms
}
private void setEntry()
{
if (species < 0)
if (species <= 0)
return;
int pk = species - 1;

View file

@ -165,8 +165,8 @@ namespace PKHeX.WinForms
// Poké Finder
NUD_SnapCount.Value = Math.Min(NUD_SnapCount.Maximum, SAV.PokeFinderSnapCount);
NUD_ThumbsTotal.Value = Math.Min(NUD_SnapCount.Maximum, SAV.PokeFinderThumbsTotalValue);
NUD_ThumbsRecord.Value = Math.Min(NUD_SnapCount.Maximum, SAV.PokeFinderThumbsHighValue);
NUD_ThumbsTotal.Value = Math.Min(NUD_ThumbsTotal.Maximum, SAV.PokeFinderThumbsTotalValue);
NUD_ThumbsRecord.Value = Math.Min(NUD_ThumbsRecord.Maximum, SAV.PokeFinderThumbsHighValue);
CB_CameraVersion.SelectedIndex = Math.Min(CB_CameraVersion.Items.Count - 1, SAV.PokeFinderCameraVersion);
CHK_Gyro.Checked = SAV.PokeFinderGyroFlag;

View file

@ -305,8 +305,7 @@ namespace PKHeX.WinForms
if (editing)
return;
editing = true;
editing = true;
Constants[CB_Stats.SelectedIndex] = (ushort)(Util.ToUInt32(((MaskedTextBox)sender).Text) & 0xFFFF);
MaskedTextBox m = TLP_Flags.Controls[constTag + CB_Stats.SelectedIndex.ToString("0000")] as MaskedTextBox;
if (m != null)

View file

@ -122,7 +122,7 @@ namespace PKHeX.WinForms
};
dgv.Columns.Add(dgvFree);
}
if (HasFreeSpace)
if (HasNew)
{
DataGridViewCheckBoxColumn dgvNew = new DataGridViewCheckBoxColumn
{
@ -243,7 +243,7 @@ namespace PKHeX.WinForms
NUD_Count.Maximum = byte.MaxValue;
else if (SAV.Generation >= 7)
NUD_Count.Maximum = pouch.MaxCount;
else if (SAV.Generation >= 3)
else // if (SAV.Generation >= 3)
NUD_Count.Maximum = ushort.MaxValue;
}
else

View file

@ -190,7 +190,7 @@ namespace PKHeX.Core
EncounterType = (EncounterOriginal ?? EncounterMatch)?.GetType();
if (EncounterType == typeof (MysteryGift))
EncounterType = EncounterType.BaseType;
EncounterType = EncounterType?.BaseType;
}
private void updateChecks()
{

View file

@ -563,18 +563,27 @@ namespace PKHeX.Core
private CheckResult verifyEncounterSafari()
{
if (pkm.Species == 670 || pkm.Species == 671) // Floette
if (!new[] {0, 1, 3}.Contains(pkm.AltForm)) // 0/1/3 - RBY
return new CheckResult(Severity.Invalid, "Friend Safari: Not valid color.", CheckIdentifier.Encounter);
else if (pkm.Species == 710 || pkm.Species == 711) // Pumpkaboo
if (pkm.AltForm != 1) // Average
return new CheckResult(Severity.Invalid, "Friend Safari: Not average sized.", CheckIdentifier.Encounter);
else if (pkm.Species == 586) // Sawsbuck
if (pkm.AltForm != 0)
return new CheckResult(Severity.Invalid, "Friend Safari: Not Spring form.", CheckIdentifier.Encounter);
switch (pkm.Species)
{
case 670: // Floette
case 671: // Florges
if (!new[] {0, 1, 3}.Contains(pkm.AltForm)) // 0/1/3 - RBY
return new CheckResult(Severity.Invalid, "Friend Safari: Not valid color.", CheckIdentifier.Encounter);
break;
case 710: // Pumpkaboo
case 711: // Goregeist
if (pkm.AltForm != 1) // Average
return new CheckResult(Severity.Invalid, "Friend Safari: Not average sized.", CheckIdentifier.Encounter);
break;
case 586: // Sawsbuck
if (pkm.AltForm != 0)
return new CheckResult(Severity.Invalid, "Friend Safari: Not Spring form.", CheckIdentifier.Encounter);
break;
}
return new CheckResult(Severity.Valid, "Valid Friend Safari encounter.", CheckIdentifier.Encounter);
}
private CheckResult verifyEncounterWild()
{
EncounterSlot[] enc = (EncounterSlot[])EncounterMatch;

View file

@ -1321,7 +1321,7 @@ namespace PKHeX.Core
internal static bool getCanLearnMachineMove(PKM pkm, int move, IEnumerable<int> generations, GameVersion version = GameVersion.Any)
{
return generations.Any(generation => getCanLearnMachineMove(pkm, generation, move, version));
return generations.Any(generation => getCanLearnMachineMove(pkm, move, generation, version));
}
internal static bool getCanRelearnMove(PKM pkm, int move, IEnumerable<int> generations, GameVersion version = GameVersion.Any)
{

View file

@ -255,7 +255,7 @@ namespace PKHeX.Core
}
// Generate Met Info
if (IsPokémon)
if (!IsEgg)
{
pk4.Met_Location = pk4.Egg_Location + 3000;
pk4.Egg_Location = 0;

View file

@ -318,7 +318,7 @@ namespace PKHeX.Core
{
int index = line.LastIndexOf("(", StringComparison.Ordinal);
string n1, n2;
if (index != 0) // correct format
if (index > 1) // correct format
{
n1 = line.Substring(0, index - 1);
n2 = line.Substring(index).Trim();

View file

@ -4,7 +4,7 @@ using System.Security.Cryptography;
namespace PKHeX.Core
{
public sealed class SAV3Colosseum : SaveFile
public sealed class SAV3Colosseum : SaveFile, IDisposable
{
public override string BAKName => $"{FileName} [{OT} ({Version}) - {PlayTimeString}].bak";
public override string Filter => "GameCube Save File|*.gci|All Files|*.*";
@ -145,6 +145,7 @@ namespace PKHeX.Core
// Checksums
private readonly SHA1 sha1 = SHA1.Create();
public void Dispose() => sha1.Dispose();
private byte[] EncryptColosseum(byte[] input, byte[] digest)
{
if (input.Length != SLOT_SIZE)

View file

@ -122,7 +122,7 @@ namespace PKHeX.Core
private int MatchFlags { get { return Data[0x2E57]; } set { Data[0x2E57] = (byte)value; } }
public DateTime MatchStamp
{
get { return new DateTime(MatchYear, MatchDay, MatchMonth, MatchHour, MatchMinute, MatchSecond); }
get { return new DateTime(MatchYear, MatchMonth, MatchDay, MatchHour, MatchMinute, MatchSecond); }
set { MatchYear = value.Year; MatchDay = value.Day; MatchMonth = value.Month; MatchHour = value.Hour; MatchMinute = value.Minute; MatchSecond = value.Second; }
}
private int UploadYear { get { return BitConverter.ToUInt16(Data, 0x2E58); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x2E58); } }
@ -134,7 +134,7 @@ namespace PKHeX.Core
private int UploadFlags { get { return Data[0x2E5F]; } set { Data[0x2E5F] = (byte)value; } }
public DateTime UploadStamp
{
get { return new DateTime(UploadYear, UploadDay, UploadMonth, UploadHour, UploadMinute, UploadSecond); }
get { return new DateTime(UploadYear, UploadMonth, UploadDay, UploadHour, UploadMinute, UploadSecond); }
set { UploadYear = value.Year; UploadDay = value.Day; UploadMonth = value.Month; UploadHour = value.Hour; UploadMinute = value.Minute; UploadSecond = value.Second; }
}