diff --git a/PKHeX/MainWindow/Main.cs b/PKHeX/MainWindow/Main.cs index 0247350a2..f7a889044 100644 --- a/PKHeX/MainWindow/Main.cs +++ b/PKHeX/MainWindow/Main.cs @@ -2936,12 +2936,6 @@ private void clickView(object sender, EventArgs e) else SystemSounds.Exclamation.Play(); } - - private void validateComboBox(object sender, System.ComponentModel.CancelEventArgs e) - { - - } - private void clickSet(object sender, EventArgs e) { if (!verifiedPKM()) return; diff --git a/PKHeX/PKM/PK1.cs b/PKHeX/PKM/PK1.cs index 8658feb8f..7226a23ad 100644 --- a/PKHeX/PKM/PK1.cs +++ b/PKHeX/PKM/PK1.cs @@ -30,11 +30,7 @@ public PK1(byte[] decryptedData = null, string ident = null, bool jp = false) Identifier = ident; if (Data.Length != SIZE_PARTY) Array.Resize(ref Data, SIZE_PARTY); - int strLen = STRLEN_U; - if (jp) - { - strLen = STRLEN_J; - } + int strLen = jp ? STRLEN_J : STRLEN_U; otname = Enumerable.Repeat((byte) 0x50, strLen).ToArray(); nick = Enumerable.Repeat((byte) 0x50, strLen).ToArray(); } @@ -104,8 +100,7 @@ public override bool IsNicknamed get { string spName = PKX.getSpeciesName(Species, Japanese ? 1 : 2).ToUpper(); - return - !nick.SequenceEqual( + return !nick.SequenceEqual( PKX.setG1Str(spName, Japanese) .Concat(Enumerable.Repeat((byte) 0x50, StringLength - spName.Length - 1))); } @@ -257,14 +252,14 @@ public override bool CanHoldItem(ushort[] ValidArray) #endregion } - class PokemonList1 + public class PokemonList1 { - internal const int CAPACITY_DAYCARE = 1; - internal const int CAPACITY_PARTY = 6; - internal const int CAPACITY_STORED = 20; - internal const int CAPACITY_STORED_JP = 30; + private const int CAPACITY_DAYCARE = 1; + private const int CAPACITY_PARTY = 6; + private const int CAPACITY_STORED = 20; + private const int CAPACITY_STORED_JP = 30; - private bool Japanese; + private readonly bool Japanese; private int StringLength => Japanese ? PK1.STRLEN_J : PK1.STRLEN_U; @@ -312,9 +307,12 @@ public PokemonList1(byte[] d, CapacityType c = CapacityType.Single, bool jp = fa { int base_ofs = 2 + Capacity; byte[] dat = Data.Skip(base_ofs + Entry_Size * i).Take(Entry_Size).ToArray(); - Pokemon[i] = new PK1(dat, null, jp); - Pokemon[i].otname = Data.Skip(base_ofs + Capacity * Entry_Size + StringLength * i).Take(StringLength).ToArray(); - Pokemon[i].nick = Data.Skip(base_ofs + Capacity * Entry_Size + StringLength * Capacity + StringLength * i).Take(StringLength).ToArray(); + Pokemon[i] = new PK1(dat, null, jp) + { + otname = Data.Skip(base_ofs + Capacity*Entry_Size + StringLength*i).Take(StringLength).ToArray(), + nick = Data.Skip(base_ofs + Capacity*Entry_Size + StringLength*Capacity + StringLength*i) + .Take(StringLength).ToArray() + }; } } @@ -341,11 +339,6 @@ public byte Count set { Data[0] = value > Capacity ? Capacity : value; } } - public int GetCapacity() - { - return Capacity; - } - public readonly PK1[] Pokemon; public PK1 this[int i] @@ -358,14 +351,14 @@ public int GetCapacity() set { if (value == null) return; - Pokemon[i] = (PK1)(((PK1)value).Clone()); + Pokemon[i] = (PK1)value.Clone(); } } private void Update() { - if (Pokemon.Any(pk => (pk.Species == 0))) - Count = (byte) Array.FindIndex(Pokemon, pk => (pk.Species == 0)); + if (Pokemon.Any(pk => pk.Species == 0)) + Count = (byte) Array.FindIndex(Pokemon, pk => pk.Species == 0); else Count = Capacity; for (int i = 0; i < Count; i++) diff --git a/PKHeX/PKM/PK2.cs b/PKHeX/PKM/PK2.cs index ad1cd1b32..21fbfe3b5 100644 --- a/PKHeX/PKM/PK2.cs +++ b/PKHeX/PKM/PK2.cs @@ -30,11 +30,7 @@ public PK2(byte[] decryptedData = null, string ident = null, bool jp = false) Identifier = ident; if (Data.Length != SIZE_PARTY) Array.Resize(ref Data, SIZE_PARTY); - int strLen = STRLEN_U; - if (jp) - { - strLen = STRLEN_J; - } + int strLen = jp ? STRLEN_J : STRLEN_U; otname = Enumerable.Repeat((byte) 0x50, strLen).ToArray(); nick = Enumerable.Repeat((byte) 0x50, strLen).ToArray(); @@ -107,8 +103,7 @@ public override bool IsNicknamed get { string spName = PKX.getSpeciesName(Species, Japanese ? 1 : 2).ToUpper(); - return - !nick.SequenceEqual( + return !nick.SequenceEqual( PKX.setG1Str(spName, Japanese) .Concat(Enumerable.Repeat((byte) 0x50, StringLength - spName.Length - 1))); } @@ -332,14 +327,14 @@ public override int HPType #endregion } - class PokemonList2 + public class PokemonList2 { - internal const int CAPACITY_DAYCARE = 1; - internal const int CAPACITY_PARTY = 6; - internal const int CAPACITY_STORED = 20; - internal const int CAPACITY_STORED_JP = 30; + private const int CAPACITY_DAYCARE = 1; + private const int CAPACITY_PARTY = 6; + private const int CAPACITY_STORED = 20; + private const int CAPACITY_STORED_JP = 30; - private bool Japanese; + private readonly bool Japanese; private int StringLength => Japanese ? PK2.STRLEN_J : PK2.STRLEN_U; @@ -387,10 +382,13 @@ public PokemonList2(byte[] d, CapacityType c = CapacityType.Single, bool jp = fa { int base_ofs = 2 + Capacity; byte[] dat = Data.Skip(base_ofs + Entry_Size * i).Take(Entry_Size).ToArray(); - Pokemon[i] = new PK2(dat, null, jp); - Pokemon[i].IsEgg = Data[1 + i] == 0xFD; - Pokemon[i].otname = Data.Skip(base_ofs + Capacity * Entry_Size + StringLength * i).Take(StringLength).ToArray(); - Pokemon[i].nick = Data.Skip(base_ofs + Capacity * Entry_Size + StringLength * Capacity + StringLength * i).Take(StringLength).ToArray(); + Pokemon[i] = new PK2(dat, null, jp) + { + IsEgg = Data[1 + i] == 0xFD, + otname = Data.Skip(base_ofs + Capacity*Entry_Size + StringLength*i).Take(StringLength).ToArray(), + nick = Data.Skip(base_ofs + Capacity*Entry_Size + StringLength*Capacity + StringLength*i) + .Take(StringLength).ToArray() + }; } } @@ -417,11 +415,6 @@ public byte Count set { Data[0] = value > Capacity ? Capacity : value; } } - public int GetCapacity() - { - return Capacity; - } - public readonly PK2[] Pokemon; public PK2 this[int i] @@ -434,14 +427,14 @@ public int GetCapacity() set { if (value == null) return; - Pokemon[i] = (PK2)(((PK2)value).Clone()); + Pokemon[i] = (PK2)value.Clone(); } } private void Update() { - if (Pokemon.Any(pk => (pk.Species == 0))) - Count = (byte)Array.FindIndex(Pokemon, pk => (pk.Species == 0)); + if (Pokemon.Any(pk => pk.Species == 0)) + Count = (byte)Array.FindIndex(Pokemon, pk => pk.Species == 0); else Count = Capacity; for (int i = 0; i < Count; i++) diff --git a/PKHeX/PKM/PKX.cs b/PKHeX/PKM/PKX.cs index b9bdf6146..3f5b51498 100644 --- a/PKHeX/PKM/PKX.cs +++ b/PKHeX/PKM/PKX.cs @@ -1643,7 +1643,7 @@ public static ushort getG4Item(ushort g3val) } #region Gen 1 Character Tables - internal static Dictionary RBY2U_U => new Dictionary{ + private static Dictionary RBY2U_U => new Dictionary{ {0x50, "\0"}, {0x5D, "[TRAINER]"}, {0x7F, " "}, @@ -1706,8 +1706,8 @@ public static ushort getG4Item(ushort g3val) {0xB8, "y"}, {0xB9, "z"}, {0xE1, "{"}, /* Pk */ - {0xE2, "}"}, /* Mn */ - {0xE3, "-"}, + {0xE2, "}"}, /* Mn */ + {0xE3, "-"}, {0xE6, "?"}, {0xE7, "!"}, {0xEF, "♂"}, @@ -1727,7 +1727,7 @@ public static ushort getG4Item(ushort g3val) {0xFF, "9"} }; - internal static Dictionary U2RBY_U => new Dictionary { + private static Dictionary U2RBY_U => new Dictionary { {"\0", 0x50}, {"[TRAINER]", 0x5D}, {" ", 0x7F}, @@ -1790,8 +1790,8 @@ public static ushort getG4Item(ushort g3val) {"y", 0xB8}, {"z", 0xB9}, {"{", 0xE1}, /* Pk */ - {"}", 0xE2}, /* Mn */ - {"-", 0xE3}, + {"}", 0xE2}, /* Mn */ + {"-", 0xE3}, {"?", 0xE6}, {"!", 0xE7}, {"♂", 0xEF}, @@ -1810,7 +1810,7 @@ public static ushort getG4Item(ushort g3val) {"8", 0xFE}, {"9", 0xFF} }; - internal static Dictionary U2RBY_J => new Dictionary { + private static Dictionary U2RBY_J => new Dictionary { {"ガ", 0x05}, {"ギ", 0x06}, {"グ", 0x07}, @@ -1981,7 +1981,7 @@ public static ushort getG4Item(ushort g3val) {"9", 0xFF} }; - static Dictionary RBY2U_J => new Dictionary { + private static Dictionary RBY2U_J => new Dictionary { {0x05, "ガ"}, {0x06, "ギ"}, {0x07, "グ"}, diff --git a/PKHeX/PersonalInfo/PersonalInfoG2.cs b/PKHeX/PersonalInfo/PersonalInfoG2.cs index 890b43018..a7e43d060 100644 --- a/PKHeX/PersonalInfo/PersonalInfoG2.cs +++ b/PKHeX/PersonalInfo/PersonalInfoG2.cs @@ -55,7 +55,7 @@ public override int[] Items public override int EXPGrowth { get { return Data[0x16]; } set { Data[0x16] = (byte)value; } } public override int[] EggGroups { - get { return new int[] { Data[0x17] >> 4, Data[0x17] & 0xF }; } + get { return new[] { Data[0x17] >> 4, Data[0x17] & 0xF }; } set { if (value?.Length != 2) return; diff --git a/PKHeX/Saves/SAV2.cs b/PKHeX/Saves/SAV2.cs index b3fddf23e..2af40cf19 100644 --- a/PKHeX/Saves/SAV2.cs +++ b/PKHeX/Saves/SAV2.cs @@ -26,43 +26,11 @@ public SAV2(byte[] data = null) Box = Data.Length; Array.Resize(ref Data, Data.Length + SIZE_RESERVED); Party = getPartyOffset(0); - - + Personal = Version == GameVersion.GS ? PersonalTable.GS : PersonalTable.C; - OptionsOffset = 0x2000; - Trainer1 = 0x2009; - switch (Version) - { - case GameVersion.GS: - DaylightSavingsOffset = Japanese ? 0x2029 : 0x2042; - TimePlayedOffset = Japanese ? 0x2034 : 0x2053; - PaletteOffset = Japanese ? 0x204C : 0x206B; - MoneyOffset = Japanese ? 0x23BC : 0x23DB; - JohtoBadgesOffset = Japanese ? 0x23C5 : 0x23E4; - CurrentBoxIndexOffset = Japanese ? 0x2705 : 0x2724; - BoxNamesOffset = Japanese ? 0x2708 : 0x2727; - PartyOffset = Japanese ? 0x283E : 0x288A; - PokedexCaughtOffset = Japanese ? 0x29CE : 0x2A4C; - PokedexSeenOffset = Japanese ? 0x29EE : 0x2A6C; - CurrentBoxOffset = Japanese ? 0x2D10 : 0x2D6C; - GenderOffset = -1; // No gender in GSC - break; - case GameVersion.C: - DaylightSavingsOffset = Japanese ? 0x2029 : 0x2042; - TimePlayedOffset = Japanese ? 0x2034 : 0x2052; - PaletteOffset = Japanese ? 0x204C : 0x206A; - MoneyOffset = Japanese ? 0x23BE : 0x23DC; - JohtoBadgesOffset = Japanese ? 0x23C7 : 0x23E5; - CurrentBoxIndexOffset = Japanese ? 0x26E2 : 0x2700; - BoxNamesOffset = Japanese ? 0x26E5 : 0x2703; - PartyOffset = Japanese ? 0x281A : 0x2865; - PokedexCaughtOffset = Japanese ? 0x29AA : 0x2A27; - PokedexSeenOffset = Japanese ? 0x29CA : 0x2A47; - CurrentBoxOffset = 0x2D10; - GenderOffset = Japanese ? 0x8000 : 0x3E3D; - break; - } + getSAVOffsets(); + LegalItems = new ushort[] { 3, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, 48, 49, 51, 52, 53, 57, 60, 62, 63, 64, 65, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 91, 92, 93, 94, 95, 96, 97, 98, 99, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 117, 118, 119, 121, 122, 123, 124, 125, 126, 131, 132, 138, 139, 140, 143, 144, 146, 150, 151, 152, 156, 158, 163, 168, 169, 170, 172, 173, 174, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189 }; LegalBalls = new ushort[] { 1, 2, 4, 5, 157, 159, 160, 161, 164, 165, 166, 167}; LegalKeyItems = new ushort[] {7, 54, 55, 58, 59, 61, 66, 67, 68 , 69, 71, 127, 128, 130, 133, 134, 175, 178}; @@ -197,6 +165,42 @@ public override byte[] Write(bool DSV) return outData; } + private void getSAVOffsets() + { + OptionsOffset = 0x2000; + Trainer1 = 0x2009; + switch (Version) + { + case GameVersion.GS: + DaylightSavingsOffset = Japanese ? 0x2029 : 0x2042; + TimePlayedOffset = Japanese ? 0x2034 : 0x2053; + PaletteOffset = Japanese ? 0x204C : 0x206B; + MoneyOffset = Japanese ? 0x23BC : 0x23DB; + JohtoBadgesOffset = Japanese ? 0x23C5 : 0x23E4; + CurrentBoxIndexOffset = Japanese ? 0x2705 : 0x2724; + BoxNamesOffset = Japanese ? 0x2708 : 0x2727; + PartyOffset = Japanese ? 0x283E : 0x288A; + PokedexCaughtOffset = Japanese ? 0x29CE : 0x2A4C; + PokedexSeenOffset = Japanese ? 0x29EE : 0x2A6C; + CurrentBoxOffset = Japanese ? 0x2D10 : 0x2D6C; + GenderOffset = -1; // No gender in GSC + break; + case GameVersion.C: + DaylightSavingsOffset = Japanese ? 0x2029 : 0x2042; + TimePlayedOffset = Japanese ? 0x2034 : 0x2052; + PaletteOffset = Japanese ? 0x204C : 0x206A; + MoneyOffset = Japanese ? 0x23BE : 0x23DC; + JohtoBadgesOffset = Japanese ? 0x23C7 : 0x23E5; + CurrentBoxIndexOffset = Japanese ? 0x26E2 : 0x2700; + BoxNamesOffset = Japanese ? 0x26E5 : 0x2703; + PartyOffset = Japanese ? 0x281A : 0x2865; + PokedexCaughtOffset = Japanese ? 0x29AA : 0x2A27; + PokedexSeenOffset = Japanese ? 0x29CA : 0x2A47; + CurrentBoxOffset = 0x2D10; + GenderOffset = Japanese ? 0x8000 : 0x3E3D; + break; + } + } // Configuration public override SaveFile Clone() { return new SAV2(Data.Take(Data.Length - SIZE_RESERVED).ToArray()); } @@ -232,19 +236,19 @@ public override byte[] Write(bool DSV) // Offsets - protected int OptionsOffset { get; set; } = int.MinValue; - protected int DaylightSavingsOffset { get; set; } = int.MinValue; - protected int TimePlayedOffset { get; set; } = int.MinValue; - protected int PaletteOffset { get; set; } = int.MinValue; - protected int MoneyOffset { get; set; } = int.MinValue; - protected int JohtoBadgesOffset { get; set; } = int.MinValue; - protected int CurrentBoxIndexOffset { get; set; } = int.MinValue; - protected int BoxNamesOffset { get; set; } = int.MinValue; - protected int PartyOffset { get; set; } = int.MinValue; - protected int PokedexSeenOffset { get; set; } = int.MinValue; - protected int PokedexCaughtOffset { get; set; } = int.MinValue; - protected int CurrentBoxOffset { get; set; } = int.MinValue; - protected int GenderOffset { get; set; } = int.MinValue; + private int OptionsOffset { get; set; } = int.MinValue; + private int DaylightSavingsOffset { get; set; } = int.MinValue; + private int TimePlayedOffset { get; set; } = int.MinValue; + private int PaletteOffset { get; set; } = int.MinValue; + private int MoneyOffset { get; set; } = int.MinValue; + private int JohtoBadgesOffset { get; set; } = int.MinValue; + private int CurrentBoxIndexOffset { get; set; } = int.MinValue; + private int BoxNamesOffset { get; set; } = int.MinValue; + private int PartyOffset { get; set; } = int.MinValue; + private int PokedexSeenOffset { get; set; } = int.MinValue; + private int PokedexCaughtOffset { get; set; } = int.MinValue; + private int CurrentBoxOffset { get; set; } = int.MinValue; + private int GenderOffset { get; set; } = int.MinValue; // Checksums protected override void setChecksums() @@ -337,7 +341,7 @@ private int getChecksum() return 0; } - public override string ChecksumInfo => ChecksumsValid ? "Checksum valid." : string.Format("Checksum invalid ({0} != {1})", Util.SwapEndianness(BitConverter.ToUInt16(Data, 0x2D0D)).ToString("X4"), getChecksum().ToString("X4")); + public override string ChecksumInfo => ChecksumsValid ? "Checksum valid." : "Checksum invalid"; // Trainer Info public override GameVersion Version { get; protected set; } diff --git a/PKHeX/Saves/SaveUtil.cs b/PKHeX/Saves/SaveUtil.cs index a7067634f..e5351fbbf 100644 --- a/PKHeX/Saves/SaveUtil.cs +++ b/PKHeX/Saves/SaveUtil.cs @@ -3,7 +3,6 @@ using System.IO; using System.Linq; using System.Text; -using System.Windows.Forms; namespace PKHeX { diff --git a/PKHeX/Subforms/Save Editors/SAV_SimpleTrainer.cs b/PKHeX/Subforms/Save Editors/SAV_SimpleTrainer.cs index e19a0c003..feda2adf8 100644 --- a/PKHeX/Subforms/Save Editors/SAV_SimpleTrainer.cs +++ b/PKHeX/Subforms/Save Editors/SAV_SimpleTrainer.cs @@ -59,7 +59,6 @@ public SAV_SimpleTrainer() { SAV2 sav2 = (SAV2)SAV; MT_Coins.Text = sav2.Coin.ToString(); - badgeval = sav2.Badges; L_Started.Visible = L_Fame.Visible = false; CAL_AdventureStartDate.Visible = CAL_HoFDate.Visible = false;