diff --git a/PKHeX.Core/Legality/Verifiers/IndividualValueVerifier.cs b/PKHeX.Core/Legality/Verifiers/IndividualValueVerifier.cs index aa3283c10..5619668dd 100644 --- a/PKHeX.Core/Legality/Verifiers/IndividualValueVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/IndividualValueVerifier.cs @@ -71,15 +71,10 @@ private void VerifyIVsSlot(LegalityAnalysis data, EncounterSlot w) { case 6: VerifyIVsGen6(data, w); break; case 7: VerifyIVsGen7(data); break; - case 8: VerifyIVsGen8(data); break; + // case 8: VerifyIVsGen8(data); break; // No rules for IV generation. } } - private void VerifyIVsGen8(LegalityAnalysis data) - { - // todo special rules - } - private void VerifyIVsGen7(LegalityAnalysis data) { var pkm = data.pkm; diff --git a/PKHeX.Core/Legality/Verifiers/PIDVerifier.cs b/PKHeX.Core/Legality/Verifiers/PIDVerifier.cs index d9e3cd963..0041006b0 100644 --- a/PKHeX.Core/Legality/Verifiers/PIDVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/PIDVerifier.cs @@ -102,7 +102,7 @@ private void VerifyECPIDWurmple(LegalityAnalysis data) } } - private void VerifyEC(LegalityAnalysis data) + private static void VerifyEC(LegalityAnalysis data) { var pkm = data.pkm; var Info = data.Info; @@ -124,7 +124,7 @@ private void VerifyEC(LegalityAnalysis data) // Gen1-2, Gen6+ should have PID != EC if (pkm.PID == pkm.EncryptionConstant) { - data.AddLine(GetInvalid(LPIDEqualsEC)); // better to flag than 1:2^32 odds since RNG is not feasible to yield match + data.AddLine(GetInvalid(LPIDEqualsEC, CheckIdentifier.EC)); // better to flag than 1:2^32 odds since RNG is not feasible to yield match return; } @@ -137,7 +137,7 @@ private void VerifyEC(LegalityAnalysis data) } } - private void VerifyTransferEC(LegalityAnalysis data) + private static void VerifyTransferEC(LegalityAnalysis data) { var pkm = data.pkm; // When transferred to Generation 6, the Encryption Constant is copied from the PID. diff --git a/PKHeX.Core/MysteryGifts/WB7.cs b/PKHeX.Core/MysteryGifts/WB7.cs index 123614f67..ec32251e3 100644 --- a/PKHeX.Core/MysteryGifts/WB7.cs +++ b/PKHeX.Core/MysteryGifts/WB7.cs @@ -281,13 +281,13 @@ public override IReadOnlyList Relearn public string GetOT(int language) => Util.TrimFromZero(Encoding.Unicode.GetString(Data, GetOTOffset(language), 0x1A)); public void SetOT(int language, string value) => Encoding.Unicode.GetBytes(value.PadRight(0x1A / 2, '\0')).CopyTo(Data, GetOTOffset(language)); - private int GetNicknameOffset(int language) + private static int GetNicknameOffset(int language) { int index = GetLanguageIndex(language); return 0x04 + (index * 0x1A); } - private int GetOTOffset(int language) + private static int GetOTOffset(int language) { int index = GetLanguageIndex(language); return 0xEE + (index * 0x1A); diff --git a/PKHeX.Core/PKM/CK3.cs b/PKHeX.Core/PKM/CK3.cs index f371830df..d03ff6792 100644 --- a/PKHeX.Core/PKM/CK3.cs +++ b/PKHeX.Core/PKM/CK3.cs @@ -27,7 +27,7 @@ public sealed class CK3 : G3PKM, IShadowPKM public override PKM Clone() => new CK3((byte[])Data.Clone()) {Identifier = Identifier}; private string GetString(int Offset, int Count) => StringConverter3.GetBEString3(Data, Offset, Count); - private byte[] SetString(string value, int maxLength) => StringConverter3.SetBEString3(value, maxLength); + private static 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); } } diff --git a/PKHeX.Core/PKM/PKM.cs b/PKHeX.Core/PKM/PKM.cs index a33857e82..82b8a95a5 100644 --- a/PKHeX.Core/PKM/PKM.cs +++ b/PKHeX.Core/PKM/PKM.cs @@ -431,13 +431,7 @@ public int[] Stats public int[] Moves { get => new[] { Move1, Move2, Move3, Move4 }; - set - { - Move1 = value.Length > 0 ? value[0] : 0; - Move2 = value.Length > 1 ? value[1] : 0; - Move3 = value.Length > 2 ? value[2] : 0; - Move4 = value.Length > 3 ? value[3] : 0; - } + set => SetMoves(value); } public void SetMoves(IReadOnlyList value) diff --git a/PKHeX.Core/PKM/Shared/G3PKM.cs b/PKHeX.Core/PKM/Shared/G3PKM.cs index 22bee5808..5b0b0bc84 100644 --- a/PKHeX.Core/PKM/Shared/G3PKM.cs +++ b/PKHeX.Core/PKM/Shared/G3PKM.cs @@ -104,7 +104,7 @@ protected T ConvertTo() where T : G3PKM, new() SID = SID, EXP = EXP, HeldItem = HeldItem, - AbilityNumber = AbilityNumber, + AbilityBit = AbilityBit, IsEgg = IsEgg, FatefulEncounter = FatefulEncounter, diff --git a/PKHeX.Core/PKM/XK3.cs b/PKHeX.Core/PKM/XK3.cs index 976503812..3938253bf 100644 --- a/PKHeX.Core/PKM/XK3.cs +++ b/PKHeX.Core/PKM/XK3.cs @@ -26,7 +26,7 @@ public sealed class XK3 : G3PKM, IShadowPKM public override PKM Clone() => new XK3((byte[])Data.Clone()){Identifier = Identifier, Purification = Purification}; private string GetString(int Offset, int Count) => StringConverter3.GetBEString3(Data, Offset, Count); - private byte[] SetString(string value, int maxLength) => StringConverter3.SetBEString3(value, maxLength); + private static 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); } } diff --git a/PKHeX.Core/Saves/MemeCrypto/SCBlockMetadata.cs b/PKHeX.Core/Saves/MemeCrypto/SCBlockMetadata.cs index d63e2319a..1e8b2b06a 100644 --- a/PKHeX.Core/Saves/MemeCrypto/SCBlockMetadata.cs +++ b/PKHeX.Core/Saves/MemeCrypto/SCBlockMetadata.cs @@ -140,6 +140,7 @@ public T Value set => Parent.SetValue(_value = value); } + // ReSharper disable once UnusedMember.Local [Description("Type of Value this Block stores")] public string ValueType => typeof(T).Name; diff --git a/PKHeX.Core/Saves/SaveFile.cs b/PKHeX.Core/Saves/SaveFile.cs index 1f63a990e..f259a09e7 100644 --- a/PKHeX.Core/Saves/SaveFile.cs +++ b/PKHeX.Core/Saves/SaveFile.cs @@ -8,7 +8,7 @@ namespace PKHeX.Core /// /// Base Class for Save Files /// - public abstract class SaveFile : ITrainerInfo, IGameValueLimit + public abstract class SaveFile : ITrainerInfo, IGameValueLimit, IBoxDetailWallpaper, IBoxDetailName { // General Object Properties public byte[] Data; diff --git a/PKHeX.Core/Saves/Substructures/Battle Videos/BattleStyle.cs b/PKHeX.Core/Saves/Substructures/Battle Videos/BattleStyle6.cs similarity index 79% rename from PKHeX.Core/Saves/Substructures/Battle Videos/BattleStyle.cs rename to PKHeX.Core/Saves/Substructures/Battle Videos/BattleStyle6.cs index 238b2d697..2a25d962d 100644 --- a/PKHeX.Core/Saves/Substructures/Battle Videos/BattleStyle.cs +++ b/PKHeX.Core/Saves/Substructures/Battle Videos/BattleStyle6.cs @@ -1,6 +1,6 @@ namespace PKHeX.Core { - public enum BattleStyle + public enum BattleStyle6 { Single, Double, @@ -8,4 +8,4 @@ public enum BattleStyle Rotation, Multi, } -} \ No newline at end of file +} diff --git a/PKHeX.Core/Saves/Substructures/Gen6/BoxLayout6.cs b/PKHeX.Core/Saves/Substructures/Gen6/BoxLayout6.cs index 20d02b8fc..dda77ece9 100644 --- a/PKHeX.Core/Saves/Substructures/Gen6/BoxLayout6.cs +++ b/PKHeX.Core/Saves/Substructures/Gen6/BoxLayout6.cs @@ -1,6 +1,6 @@ namespace PKHeX.Core { - public sealed class BoxLayout6 : SaveBlock + public sealed class BoxLayout6 : SaveBlock, IBoxDetailName, IBoxDetailWallpaper { // gfstr5[31] boxNames; // byte[31] wallpapers; @@ -20,7 +20,7 @@ public sealed class BoxLayout6 : SaveBlock public BoxLayout6(SAV6XY sav, int offset) : base(sav) => Offset = offset; public BoxLayout6(SAV6AO sav, int offset) : base(sav) => Offset = offset; - public int GetBoxWallpaperOffset(int box) => Offset + PCBackgrounds + box; + public int GetBoxWallpaperOffset(int box) => Offset + PCBackgrounds + box; public int GetBoxWallpaper(int box) { diff --git a/PKHeX.Core/Saves/Substructures/Gen6/MaisonBlock.cs b/PKHeX.Core/Saves/Substructures/Gen6/MaisonBlock.cs index 48ee091e8..168243f41 100644 --- a/PKHeX.Core/Saves/Substructures/Gen6/MaisonBlock.cs +++ b/PKHeX.Core/Saves/Substructures/Gen6/MaisonBlock.cs @@ -7,7 +7,14 @@ public sealed class MaisonBlock : SaveBlock public MaisonBlock(SAV6XY sav, int offset) : base(sav) => Offset = offset; public MaisonBlock(SAV6AO sav, int offset) : base(sav) => Offset = offset; - public ushort GetMaisonStat(int index) { return BitConverter.ToUInt16(Data, Offset + 0x1C0 + (2 * index)); } - public void SetMaisonStat(int index, ushort value) { BitConverter.GetBytes(value).CopyTo(Data, Offset + 0x1C0 + (2 * index)); } + // 5 * [u16*4: normal,super,normalStreak,superStreak] + public const int MaisonStatCount = 20; + + public ushort GetMaisonStat(int index) => BitConverter.ToUInt16(Data, Offset + 0x1C0 + (2 * index)); + public void SetMaisonStat(int index, ushort value) => BitConverter.GetBytes(value).CopyTo(Data, Offset + 0x1C0 + (2 * index)); + + private static int GetMaisonStatIndex(BattleStyle6 type, bool streak, bool super) => ((int)type << 2) | (streak ? 2 : 0) | (super ? 1 : 0); + public ushort GetMaisonStat(BattleStyle6 type, bool streak, bool super) => GetMaisonStat(GetMaisonStatIndex(type, streak, super)); + public void SetMaisonStat(BattleStyle6 type, bool streak, bool super, ushort value) => SetMaisonStat(GetMaisonStatIndex(type, streak, super), value); } } diff --git a/PKHeX.Core/Saves/Substructures/Gen6/MyItem6AO.cs b/PKHeX.Core/Saves/Substructures/Gen6/MyItem6AO.cs index 0f6db811a..df992ad0c 100644 --- a/PKHeX.Core/Saves/Substructures/Gen6/MyItem6AO.cs +++ b/PKHeX.Core/Saves/Substructures/Gen6/MyItem6AO.cs @@ -8,7 +8,8 @@ public sealed class MyItem6AO : MyItem private const int Medicine = 0x970; // 3, +2 items shift because 2 HMs added private const int Berry = 0xA70; // 4 - public MyItem6AO(SAV6 SAV, int offset) : base(SAV) => Offset = offset; + public MyItem6AO(SAV6AO SAV, int offset) : base(SAV) => Offset = offset; + public MyItem6AO(SAV6AODemo SAV, int offset) : base(SAV) => Offset = offset; public override InventoryPouch[] Inventory { diff --git a/PKHeX.Core/Saves/Substructures/Gen6/SubEventLog6.cs b/PKHeX.Core/Saves/Substructures/Gen6/SubEventLog6.cs index b78eb4b48..d06611340 100644 --- a/PKHeX.Core/Saves/Substructures/Gen6/SubEventLog6.cs +++ b/PKHeX.Core/Saves/Substructures/Gen6/SubEventLog6.cs @@ -2,6 +2,9 @@ namespace PKHeX.Core { + /// + /// SUBE block that stores in-game event results. + /// public abstract class SubEventLog6 : SaveBlock, IGymTeamInfo { protected SubEventLog6(SAV6 sav, int offset) : base(sav) => Offset = offset; diff --git a/PKHeX.Core/Saves/Substructures/Gen7/BoxLayout7.cs b/PKHeX.Core/Saves/Substructures/Gen7/BoxLayout7.cs index 1e3a7c3bc..33a29c09e 100644 --- a/PKHeX.Core/Saves/Substructures/Gen7/BoxLayout7.cs +++ b/PKHeX.Core/Saves/Substructures/Gen7/BoxLayout7.cs @@ -2,7 +2,7 @@ namespace PKHeX.Core { - public sealed class BoxLayout7 : SaveBlock + public sealed class BoxLayout7 : SaveBlock, IBoxDetailName, IBoxDetailWallpaper, ITeamIndexSet { private const int BoxCount = 32; @@ -118,6 +118,12 @@ public void SaveBattleTeams() } } + public void UnlockAllTeams() + { + for (int i = 0; i < TeamCount; i++) + SetIsTeamLocked(i, false); + } + public bool GetIsTeamLocked(int team) => Data[Offset + PCBackgrounds - TeamCount - team] == 1; public void SetIsTeamLocked(int team, bool value) => Data[Offset + PCBackgrounds - TeamCount - team] = (byte)(value ? 1 : 0); diff --git a/PKHeX.Core/Saves/Substructures/Gen7/BattleStyle7.cs b/PKHeX.Core/Saves/Substructures/Gen7/PlayerBattleStyle7.cs similarity index 88% rename from PKHeX.Core/Saves/Substructures/Gen7/BattleStyle7.cs rename to PKHeX.Core/Saves/Substructures/Gen7/PlayerBattleStyle7.cs index 6c13662ae..56776e73a 100644 --- a/PKHeX.Core/Saves/Substructures/Gen7/BattleStyle7.cs +++ b/PKHeX.Core/Saves/Substructures/Gen7/PlayerBattleStyle7.cs @@ -1,6 +1,6 @@ namespace PKHeX.Core { - public enum BattleStyle7 + public enum PlayerBattleStyle7 { Normal, Elegant, diff --git a/PKHeX.Core/Saves/Substructures/Gen7/SkinColor7.cs b/PKHeX.Core/Saves/Substructures/Gen7/PlayerSkinColor7.cs similarity index 82% rename from PKHeX.Core/Saves/Substructures/Gen7/SkinColor7.cs rename to PKHeX.Core/Saves/Substructures/Gen7/PlayerSkinColor7.cs index eda35c932..389cb24d5 100644 --- a/PKHeX.Core/Saves/Substructures/Gen7/SkinColor7.cs +++ b/PKHeX.Core/Saves/Substructures/Gen7/PlayerSkinColor7.cs @@ -1,6 +1,6 @@ namespace PKHeX.Core { - public enum SkinColor7 + public enum PlayerSkinColor7 { M_Pale, F_Pale, @@ -11,4 +11,4 @@ public enum SkinColor7 M_Dark, F_Dark, } -} \ No newline at end of file +} diff --git a/PKHeX.Core/Saves/Substructures/Gen8/BoxLayout8.cs b/PKHeX.Core/Saves/Substructures/Gen8/BoxLayout8.cs index e874e3658..f55da7794 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/BoxLayout8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/BoxLayout8.cs @@ -1,6 +1,6 @@ namespace PKHeX.Core { - public sealed class BoxLayout8 : SaveBlock + public sealed class BoxLayout8 : SaveBlock, IBoxDetailName { public const int BoxCount = 32; diff --git a/PKHeX.Core/Saves/Substructures/Gen8/MyStatus8.cs b/PKHeX.Core/Saves/Substructures/Gen8/MyStatus8.cs index 6b46c5cf6..021310808 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/MyStatus8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/MyStatus8.cs @@ -5,6 +5,8 @@ namespace PKHeX.Core { public sealed class MyStatus8 : SaveBlock { + public const uint MaxWatt = 9999999; + public MyStatus8(SAV8SWSH sav, SCBlock block) : base(sav, block.Data) { } public string Number @@ -176,7 +178,5 @@ public uint Watt SAV.SetData(Data, BitConverter.GetBytes(value), Offset + 0xD0); } } - - public uint MaxWatt => 9999999; } } diff --git a/PKHeX.Core/Saves/Substructures/Gen8/PouchSize8.cs b/PKHeX.Core/Saves/Substructures/Gen8/PouchSize8.cs index be95a20fe..bd72a7f27 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/PouchSize8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/PouchSize8.cs @@ -1,5 +1,8 @@ namespace PKHeX.Core { + /// + /// Contains information pertaining to Inventory Pouch capacity in Generation 8. + /// public static class PouchSize8 { /// @@ -35,12 +38,12 @@ public static class PouchSize8 /// /// Pouch5 Item Max Capacity /// - public const int Treasures = 100; // todo + public const int Treasures = 100; /// /// Pouch5 Item Max Capacity /// - public const int Ingredients = 100; // todo + public const int Ingredients = 100; /// /// Pouch5 Item Max Capacity diff --git a/PKHeX.Core/Saves/Substructures/Gen8/RentalTeam8.cs b/PKHeX.Core/Saves/Substructures/Gen8/RentalTeam8.cs index 093179f31..70c6f4b43 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/RentalTeam8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/RentalTeam8.cs @@ -3,10 +3,15 @@ namespace PKHeX.Core { - public sealed class RentalTeam8 + /// + /// Container block for Generation 8 saved Rental Teams + /// + public sealed class RentalTeam8 : IRentalTeam { private const int LEN_META = 0x56; - private const int LEN_POKE = PokeCrypto.SIZE_8PARTY; + private const int LEN_STORED = PokeCrypto.SIZE_8STORED; // 0x148 + private const int LEN_POKE = PokeCrypto.SIZE_8PARTY; // 0x158 + private const int LEN_PARTYSTAT = LEN_POKE - PokeCrypto.SIZE_8STORED; // 0x10 private const int COUNT_POKE = 6; private const int OFS_META = 0; @@ -35,7 +40,8 @@ public void SetSlot(int slot, PK8 pkm) { var ofs = GetSlotOffset(slot); var data = pkm.EncryptedPartyData; - Array.Clear(data, LEN_POKE - 0x10, 0x10); + // Wipe Party Stats + Array.Clear(data, LEN_STORED, LEN_PARTYSTAT); data.CopyTo(Data, ofs); } @@ -63,4 +69,4 @@ public static int GetSlotOffset(int slot) public byte[] GetMetadataStart() => Data.Slice(OFS_META, LEN_META); public byte[] GetMetadataEnd() => Data.SliceEnd(POST_META); } -} \ No newline at end of file +} diff --git a/PKHeX.Core/Saves/Substructures/Gen8/Situation8.cs b/PKHeX.Core/Saves/Substructures/Gen8/Situation8.cs index a5d2e3b34..e8662b9bc 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/Situation8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/Situation8.cs @@ -12,15 +12,5 @@ public sealed class Situation8 : SaveBlock public float Z { get => BitConverter.ToSingle(Data, Offset + 0x10); set => BitConverter.GetBytes(value).CopyTo(Data, Offset + 0x10); } public float Y { get => (int)BitConverter.ToSingle(Data, Offset + 0x18); set => BitConverter.GetBytes(value).CopyTo(Data, Offset + 0x18); } public float R { get => (int)BitConverter.ToSingle(Data, Offset + 0x20); set => BitConverter.GetBytes(value).CopyTo(Data, Offset + 0x20); } - - public void UpdateOverworldCoordinates() - { - //var o = ((SAV8)SAV).Overworld; - //o.M = M; - //o.X = X; - //o.Z = Z; - //o.Y = Y; - //o.R = R; - } } -} \ No newline at end of file +} diff --git a/PKHeX.Core/Saves/Substructures/Gen8/TeamIndexes8.cs b/PKHeX.Core/Saves/Substructures/Gen8/TeamIndexes8.cs index ebad71dce..9b3c5e5ba 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/TeamIndexes8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/TeamIndexes8.cs @@ -2,7 +2,7 @@ namespace PKHeX.Core { - public sealed class TeamIndexes8 : SaveBlock + public sealed class TeamIndexes8 : SaveBlock, ITeamIndexSet { private const int TeamCount = 6; private const int NONE_SELECTED = -1; diff --git a/PKHeX.Core/Saves/Substructures/Misc/IBoxDetailName.cs b/PKHeX.Core/Saves/Substructures/Misc/IBoxDetailName.cs new file mode 100644 index 000000000..a844db8c6 --- /dev/null +++ b/PKHeX.Core/Saves/Substructures/Misc/IBoxDetailName.cs @@ -0,0 +1,11 @@ +namespace PKHeX.Core +{ + /// + /// Provides details about box names within the save file. + /// + public interface IBoxDetailName + { + public string GetBoxName(int box); + public void SetBoxName(int box, string value); + } +} diff --git a/PKHeX.Core/Saves/Substructures/Misc/IBoxDetailWallpaper.cs b/PKHeX.Core/Saves/Substructures/Misc/IBoxDetailWallpaper.cs new file mode 100644 index 000000000..d59377295 --- /dev/null +++ b/PKHeX.Core/Saves/Substructures/Misc/IBoxDetailWallpaper.cs @@ -0,0 +1,11 @@ +namespace PKHeX.Core +{ + /// + /// Provides details about box wallpaper values within the save file. + /// + public interface IBoxDetailWallpaper + { + public int GetBoxWallpaper(int box); + public void SetBoxWallpaper(int box, int value); + } +} diff --git a/PKHeX.Core/Saves/Substructures/Misc/IRentalTeam.cs b/PKHeX.Core/Saves/Substructures/Misc/IRentalTeam.cs new file mode 100644 index 000000000..c4b446a50 --- /dev/null +++ b/PKHeX.Core/Saves/Substructures/Misc/IRentalTeam.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; + +namespace PKHeX.Core +{ + public interface IRentalTeam where T : PKM + { + T GetSlot(int slot); + void SetSlot(int slot, T pkm); + + T[] GetTeam(); + void SetTeam(IReadOnlyList team); + } +} diff --git a/PKHeX.Core/Saves/Substructures/Misc/ITeamIndexSet.cs b/PKHeX.Core/Saves/Substructures/Misc/ITeamIndexSet.cs new file mode 100644 index 000000000..ea69b41df --- /dev/null +++ b/PKHeX.Core/Saves/Substructures/Misc/ITeamIndexSet.cs @@ -0,0 +1,12 @@ +namespace PKHeX.Core +{ + public interface ITeamIndexSet + { + bool GetIsTeamLocked(int team); + void SetIsTeamLocked(int team, bool value); + + void ClearBattleTeams(); + void SaveBattleTeams(); + void UnlockAllTeams(); + } +} diff --git a/PKHeX.WinForms/Controls/PKM Editor/DrawConfig.cs b/PKHeX.WinForms/Controls/PKM Editor/DrawConfig.cs index 1da79ced9..a9f05390a 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/DrawConfig.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/DrawConfig.cs @@ -159,7 +159,9 @@ private void ApplyLine(string l) pi.SetValue(this, value); } } +#pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) +#pragma warning restore CA1031 // Do not catch general exception types { Debug.WriteLine($"Failed to write {name} to {value}!"); Debug.WriteLine(e.Message); diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs index 52009999e..0a0a3a12a 100644 --- a/PKHeX.WinForms/MainWindow/Main.cs +++ b/PKHeX.WinForms/MainWindow/Main.cs @@ -231,16 +231,18 @@ private void FormLoadCheckForUpdates() L_UpdateAvailable.Click += (sender, e) => Process.Start(ThreadPath); Task.Run(() => { - try - { - var latestVersion = NetUtil.GetLatestPKHeXVersion(); - if (latestVersion > CurrentProgramVersion) - Invoke((MethodInvoker)(() => NotifyNewVersionAvailable(latestVersion))); - } + Version latestVersion; + // User might not be connected to the internet or with a flaky connection. + try { latestVersion = NetUtil.GetLatestPKHeXVersion(); } +#pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) +#pragma warning restore CA1031 // Do not catch general exception types { Debug.WriteLine($"Exception while checking for latest version: {ex}"); + return; } + if (latestVersion > CurrentProgramVersion) + Invoke((MethodInvoker)(() => NotifyNewVersionAvailable(latestVersion))); }); } @@ -565,14 +567,18 @@ private void OpenFromPath(string path) return; } byte[] input; try { input = File.ReadAllBytes(path); } +#pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) { WinFormsUtil.Error(MsgFileInUse + path, e); return; } +#pragma warning restore CA1031 // Do not catch general exception types string ext = fi.Extension; #if DEBUG OpenFile(input, path, ext); #else try { OpenFile(input, path, ext); } +#pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) { WinFormsUtil.Error(MsgFileLoadFail + "\nPath: " + path, e); } +#pragma warning restore CA1031 // Do not catch general exception types #endif } diff --git a/PKHeX.WinForms/Misc/ErrorWindow.cs b/PKHeX.WinForms/Misc/ErrorWindow.cs index b59fdc73e..7be481ac0 100644 --- a/PKHeX.WinForms/Misc/ErrorWindow.cs +++ b/PKHeX.WinForms/Misc/ErrorWindow.cs @@ -82,7 +82,9 @@ private void UpdateExceptionDetailsMessage() details.AppendLine(); } } +#pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) +#pragma warning restore CA1031 // Do not catch general exception types { details.AppendLine("An error occurred while listing the Loaded Assemblies:"); details.AppendLine(ex.ToString()); diff --git a/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs b/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs index 60b74111d..888d3e997 100644 --- a/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs +++ b/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs @@ -210,7 +210,9 @@ private void LoadDatabase() PopulateComboBoxes(); })); } +#pragma warning disable CA1031 // Do not catch general exception types catch { /* Window Closed? */ } +#pragma warning restore CA1031 // Do not catch general exception types } // IO Usage diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Trainer.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Trainer.cs index 964cd2d04..0440f0e6a 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Trainer.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Trainer.cs @@ -128,7 +128,7 @@ private void GetTextBoxes() // Maison Data if (SAV is ISaveBlock6Main xyao) { - for (int i = 0; i < MaisonRecords.Length; i++) + for (int i = 0; i < MaisonBlock.MaisonStatCount; i++) MaisonRecords[i].Text = xyao.Maison.GetMaisonStat(i).ToString(); } @@ -147,7 +147,10 @@ private void GetTextBoxes() NUD_Z.Value = (decimal)sit.Z; NUD_Y.Value = (decimal)sit.Y; } + // If we can't accurately represent the coordinates, don't allow them to be changed. +#pragma warning disable CA1031 // Do not catch general exception types catch { GB_Map.Enabled = false; } +#pragma warning restore CA1031 // Do not catch general exception types } // Load BP and PokeMiles @@ -217,7 +220,7 @@ private void Save() // Copy Maison Data in if (SAV is ISaveBlock6Main xyao) { - for (int i = 0; i < MaisonRecords.Length; i++) + for (int i = 0; i < MaisonBlock.MaisonStatCount; i++) xyao.Maison.SetMaisonStat(i, ushort.Parse(MaisonRecords[i].Text)); } diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs index d7337e09f..5f00e6a2c 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs @@ -45,7 +45,7 @@ public SAV_Trainer7(SaveFile sav) private readonly bool Loading; private bool MapUpdated; - private static readonly string[] AllStyles = Enum.GetNames(typeof(BattleStyle7)); + private static readonly string[] AllStyles = Enum.GetNames(typeof(PlayerBattleStyle7)); private readonly List BattleStyles = new List(AllStyles); private int[] FlyDestFlagOfs, MapUnmaskFlagOfs; @@ -65,7 +65,7 @@ private void GetComboBoxes() Main.SetCountrySubRegion(CB_Country, "countries"); CB_SkinColor.Items.Clear(); - CB_SkinColor.Items.AddRange(Enum.GetNames(typeof(SkinColor7))); + CB_SkinColor.Items.AddRange(Enum.GetNames(typeof(PlayerSkinColor7))); L_Vivillon.Text = GameInfo.Strings.Species[(int)Species.Vivillon] + ":"; CB_Vivillon.InitializeBinding(); diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_Trainer8.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_Trainer8.cs index efa7a9dfd..a7198f859 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_Trainer8.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_Trainer8.cs @@ -22,7 +22,7 @@ public SAV_Trainer8(SaveFile sav) } B_MaxCash.Click += (sender, e) => MT_Money.Text = SAV.MaxMoney.ToString(); - B_MaxWatt.Click += (sender, e) => MT_Watt.Text = SAV.MyStatus.MaxWatt.ToString(); + B_MaxWatt.Click += (sender, e) => MT_Watt.Text = MyStatus8.MaxWatt.ToString(); CB_Gender.Items.Clear(); CB_Gender.Items.AddRange(Main.GenderSymbols.Take(2).ToArray()); // m/f depending on unicode selection diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_EventFlags.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_EventFlags.cs index ea73fe93e..184bc3375 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_EventFlags.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_EventFlags.cs @@ -151,7 +151,9 @@ private void AddFlagList(string[] list) num.Add(n); desc.Add(split[1]); } +#pragma warning disable CA1031 // Do not catch general exception types catch +#pragma warning restore CA1031 // Do not catch general exception types { // Ignore bad user values Debug.WriteLine(string.Concat(split)); diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs index 8f08502c4..39256e3a8 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs @@ -92,7 +92,10 @@ private void ViewGiftData(DataMysteryGift g) PB_Preview.Image = g.Sprite(); mg = g; } + // Some user input mystery gifts can have out-of-bounds values. Just swallow any exception. +#pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) +#pragma warning restore CA1031 // Do not catch general exception types { WinFormsUtil.Error(MsgMysteryGiftParseTypeUnknown, e); RTB.Clear(); @@ -392,7 +395,10 @@ private void BoxSlot_MouseDown(object sender, MouseEventArgs e) File.WriteAllBytes(newfile, gift.Write()); DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Move); } + // Sometimes the drag-drop is canceled or ends up at a bad location. Don't bother recovering from an exception; just display a safe error message. +#pragma warning disable CA1031 // Do not catch general exception types catch (Exception x) +#pragma warning restore CA1031 // Do not catch general exception types { WinFormsUtil.Error("Drag & Drop Error", x); } File.Delete(newfile); wc_slot = -1; @@ -409,15 +415,19 @@ private void BoxSlot_DragDrop(object sender, DragEventArgs e) if (wc_slot == -1) // dropped { - string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); - - if (files.Length < 1) + var files = (string[])e.Data.GetData(DataFormats.FileDrop); + if (files == null || files.Length == 0) return; - if (!MysteryGift.IsMysteryGift(new FileInfo(files[0]).Length)) - { WinFormsUtil.Alert(MsgFileUnsupported, files[0]); return; } - byte[] data = File.ReadAllBytes(files[0]); - MysteryGift gift = MysteryGift.GetMysteryGift(data, new FileInfo(files[0]).Extension); + var first = files[0]; + var fi = new FileInfo(first); + if (!MysteryGift.IsMysteryGift(fi.Length)) + { WinFormsUtil.Alert(MsgFileUnsupported, first); return; } + + byte[] data = File.ReadAllBytes(first); + var gift = MysteryGift.GetMysteryGift(data, fi.Extension); + if (gift == null) + { WinFormsUtil.Alert(MsgFileUnsupported, first); return; } if (gift is PCD pcd && mga.Gifts[index] is PGT) { diff --git a/PKHeX.WinForms/Util/FontUtil.cs b/PKHeX.WinForms/Util/FontUtil.cs index 85db4a086..6f79718f3 100644 --- a/PKHeX.WinForms/Util/FontUtil.cs +++ b/PKHeX.WinForms/Util/FontUtil.cs @@ -25,7 +25,9 @@ static FontUtil() catch (FileNotFoundException ex){ Debug.WriteLine($"Unable to read font file: {ex.Message}"); } +#pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) +#pragma warning restore CA1031 // Do not catch general exception types { Debug.WriteLine($"Unable to add in-game font: {ex.Message}"); }