Misc cleanup

( ͡° ͜ʖ ͡°)
This commit is contained in:
Kaphotics 2016-09-03 23:54:11 -07:00
parent 64205beae3
commit 316e9a2795
8 changed files with 97 additions and 115 deletions

View file

@ -2936,12 +2936,6 @@ namespace PKHeX
else else
SystemSounds.Exclamation.Play(); SystemSounds.Exclamation.Play();
} }
private void validateComboBox(object sender, System.ComponentModel.CancelEventArgs e)
{
}
private void clickSet(object sender, EventArgs e) private void clickSet(object sender, EventArgs e)
{ {
if (!verifiedPKM()) return; if (!verifiedPKM()) return;

View file

@ -30,11 +30,7 @@ namespace PKHeX
Identifier = ident; Identifier = ident;
if (Data.Length != SIZE_PARTY) if (Data.Length != SIZE_PARTY)
Array.Resize(ref Data, SIZE_PARTY); Array.Resize(ref Data, SIZE_PARTY);
int strLen = STRLEN_U; int strLen = jp ? STRLEN_J : STRLEN_U;
if (jp)
{
strLen = STRLEN_J;
}
otname = Enumerable.Repeat((byte) 0x50, strLen).ToArray(); otname = Enumerable.Repeat((byte) 0x50, strLen).ToArray();
nick = Enumerable.Repeat((byte) 0x50, strLen).ToArray(); nick = Enumerable.Repeat((byte) 0x50, strLen).ToArray();
} }
@ -104,8 +100,7 @@ namespace PKHeX
get get
{ {
string spName = PKX.getSpeciesName(Species, Japanese ? 1 : 2).ToUpper(); string spName = PKX.getSpeciesName(Species, Japanese ? 1 : 2).ToUpper();
return return !nick.SequenceEqual(
!nick.SequenceEqual(
PKX.setG1Str(spName, Japanese) PKX.setG1Str(spName, Japanese)
.Concat(Enumerable.Repeat((byte) 0x50, StringLength - spName.Length - 1))); .Concat(Enumerable.Repeat((byte) 0x50, StringLength - spName.Length - 1)));
} }
@ -257,14 +252,14 @@ namespace PKHeX
#endregion #endregion
} }
class PokemonList1 public class PokemonList1
{ {
internal const int CAPACITY_DAYCARE = 1; private const int CAPACITY_DAYCARE = 1;
internal const int CAPACITY_PARTY = 6; private const int CAPACITY_PARTY = 6;
internal const int CAPACITY_STORED = 20; private const int CAPACITY_STORED = 20;
internal const int CAPACITY_STORED_JP = 30; private const int CAPACITY_STORED_JP = 30;
private bool Japanese; private readonly bool Japanese;
private int StringLength => Japanese ? PK1.STRLEN_J : PK1.STRLEN_U; private int StringLength => Japanese ? PK1.STRLEN_J : PK1.STRLEN_U;
@ -312,9 +307,12 @@ namespace PKHeX
{ {
int base_ofs = 2 + Capacity; int base_ofs = 2 + Capacity;
byte[] dat = Data.Skip(base_ofs + Entry_Size * i).Take(Entry_Size).ToArray(); byte[] dat = Data.Skip(base_ofs + Entry_Size * i).Take(Entry_Size).ToArray();
Pokemon[i] = new PK1(dat, null, jp); 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(); 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 @@ namespace PKHeX
set { Data[0] = value > Capacity ? Capacity : value; } set { Data[0] = value > Capacity ? Capacity : value; }
} }
public int GetCapacity()
{
return Capacity;
}
public readonly PK1[] Pokemon; public readonly PK1[] Pokemon;
public PK1 this[int i] public PK1 this[int i]
@ -358,14 +351,14 @@ namespace PKHeX
set set
{ {
if (value == null) return; if (value == null) return;
Pokemon[i] = (PK1)(((PK1)value).Clone()); Pokemon[i] = (PK1)value.Clone();
} }
} }
private void Update() private void Update()
{ {
if (Pokemon.Any(pk => (pk.Species == 0))) if (Pokemon.Any(pk => pk.Species == 0))
Count = (byte) Array.FindIndex(Pokemon, pk => (pk.Species == 0)); Count = (byte) Array.FindIndex(Pokemon, pk => pk.Species == 0);
else else
Count = Capacity; Count = Capacity;
for (int i = 0; i < Count; i++) for (int i = 0; i < Count; i++)

View file

@ -30,11 +30,7 @@ namespace PKHeX
Identifier = ident; Identifier = ident;
if (Data.Length != SIZE_PARTY) if (Data.Length != SIZE_PARTY)
Array.Resize(ref Data, SIZE_PARTY); Array.Resize(ref Data, SIZE_PARTY);
int strLen = STRLEN_U; int strLen = jp ? STRLEN_J : STRLEN_U;
if (jp)
{
strLen = STRLEN_J;
}
otname = Enumerable.Repeat((byte) 0x50, strLen).ToArray(); otname = Enumerable.Repeat((byte) 0x50, strLen).ToArray();
nick = Enumerable.Repeat((byte) 0x50, strLen).ToArray(); nick = Enumerable.Repeat((byte) 0x50, strLen).ToArray();
@ -107,8 +103,7 @@ namespace PKHeX
get get
{ {
string spName = PKX.getSpeciesName(Species, Japanese ? 1 : 2).ToUpper(); string spName = PKX.getSpeciesName(Species, Japanese ? 1 : 2).ToUpper();
return return !nick.SequenceEqual(
!nick.SequenceEqual(
PKX.setG1Str(spName, Japanese) PKX.setG1Str(spName, Japanese)
.Concat(Enumerable.Repeat((byte) 0x50, StringLength - spName.Length - 1))); .Concat(Enumerable.Repeat((byte) 0x50, StringLength - spName.Length - 1)));
} }
@ -332,14 +327,14 @@ public override int Stat_Level
#endregion #endregion
} }
class PokemonList2 public class PokemonList2
{ {
internal const int CAPACITY_DAYCARE = 1; private const int CAPACITY_DAYCARE = 1;
internal const int CAPACITY_PARTY = 6; private const int CAPACITY_PARTY = 6;
internal const int CAPACITY_STORED = 20; private const int CAPACITY_STORED = 20;
internal const int CAPACITY_STORED_JP = 30; private const int CAPACITY_STORED_JP = 30;
private bool Japanese; private readonly bool Japanese;
private int StringLength => Japanese ? PK2.STRLEN_J : PK2.STRLEN_U; private int StringLength => Japanese ? PK2.STRLEN_J : PK2.STRLEN_U;
@ -387,10 +382,13 @@ public override int Stat_Level
{ {
int base_ofs = 2 + Capacity; int base_ofs = 2 + Capacity;
byte[] dat = Data.Skip(base_ofs + Entry_Size * i).Take(Entry_Size).ToArray(); byte[] dat = Data.Skip(base_ofs + Entry_Size * i).Take(Entry_Size).ToArray();
Pokemon[i] = new PK2(dat, null, jp); 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(); IsEgg = Data[1 + i] == 0xFD,
Pokemon[i].nick = Data.Skip(base_ofs + Capacity * Entry_Size + StringLength * Capacity + StringLength * i).Take(StringLength).ToArray(); 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 override int Stat_Level
set { Data[0] = value > Capacity ? Capacity : value; } set { Data[0] = value > Capacity ? Capacity : value; }
} }
public int GetCapacity()
{
return Capacity;
}
public readonly PK2[] Pokemon; public readonly PK2[] Pokemon;
public PK2 this[int i] public PK2 this[int i]
@ -434,14 +427,14 @@ public override int Stat_Level
set set
{ {
if (value == null) return; if (value == null) return;
Pokemon[i] = (PK2)(((PK2)value).Clone()); Pokemon[i] = (PK2)value.Clone();
} }
} }
private void Update() private void Update()
{ {
if (Pokemon.Any(pk => (pk.Species == 0))) if (Pokemon.Any(pk => pk.Species == 0))
Count = (byte)Array.FindIndex(Pokemon, pk => (pk.Species == 0)); Count = (byte)Array.FindIndex(Pokemon, pk => pk.Species == 0);
else else
Count = Capacity; Count = Capacity;
for (int i = 0; i < Count; i++) for (int i = 0; i < Count; i++)

View file

@ -1643,7 +1643,7 @@ namespace PKHeX
} }
#region Gen 1 Character Tables #region Gen 1 Character Tables
internal static Dictionary<byte, string> RBY2U_U => new Dictionary<byte, string>{ private static Dictionary<byte, string> RBY2U_U => new Dictionary<byte, string>{
{0x50, "\0"}, {0x50, "\0"},
{0x5D, "[TRAINER]"}, {0x5D, "[TRAINER]"},
{0x7F, " "}, {0x7F, " "},
@ -1706,8 +1706,8 @@ namespace PKHeX
{0xB8, "y"}, {0xB8, "y"},
{0xB9, "z"}, {0xB9, "z"},
{0xE1, "{"}, /* Pk */ {0xE1, "{"}, /* Pk */
{0xE2, "}"}, /* Mn */ {0xE2, "}"}, /* Mn */
{0xE3, "-"}, {0xE3, "-"},
{0xE6, "?"}, {0xE6, "?"},
{0xE7, "!"}, {0xE7, "!"},
{0xEF, "♂"}, {0xEF, "♂"},
@ -1727,7 +1727,7 @@ namespace PKHeX
{0xFF, "9"} {0xFF, "9"}
}; };
internal static Dictionary<string, byte> U2RBY_U => new Dictionary<string, byte> { private static Dictionary<string, byte> U2RBY_U => new Dictionary<string, byte> {
{"\0", 0x50}, {"\0", 0x50},
{"[TRAINER]", 0x5D}, {"[TRAINER]", 0x5D},
{" ", 0x7F}, {" ", 0x7F},
@ -1790,8 +1790,8 @@ namespace PKHeX
{"y", 0xB8}, {"y", 0xB8},
{"z", 0xB9}, {"z", 0xB9},
{"{", 0xE1}, /* Pk */ {"{", 0xE1}, /* Pk */
{"}", 0xE2}, /* Mn */ {"}", 0xE2}, /* Mn */
{"-", 0xE3}, {"-", 0xE3},
{"?", 0xE6}, {"?", 0xE6},
{"!", 0xE7}, {"!", 0xE7},
{"♂", 0xEF}, {"♂", 0xEF},
@ -1810,7 +1810,7 @@ namespace PKHeX
{"8", 0xFE}, {"8", 0xFE},
{"9", 0xFF} {"9", 0xFF}
}; };
internal static Dictionary<string, byte> U2RBY_J => new Dictionary<string, byte> { private static Dictionary<string, byte> U2RBY_J => new Dictionary<string, byte> {
{"ガ", 0x05}, {"ガ", 0x05},
{"ギ", 0x06}, {"ギ", 0x06},
{"グ", 0x07}, {"グ", 0x07},
@ -1981,7 +1981,7 @@ namespace PKHeX
{"9", 0xFF} {"9", 0xFF}
}; };
static Dictionary<byte, string> RBY2U_J => new Dictionary<byte, string> { private static Dictionary<byte, string> RBY2U_J => new Dictionary<byte, string> {
{0x05, "ガ"}, {0x05, "ガ"},
{0x06, "ギ"}, {0x06, "ギ"},
{0x07, "グ"}, {0x07, "グ"},

View file

@ -55,7 +55,7 @@ namespace PKHeX
public override int EXPGrowth { get { return Data[0x16]; } set { Data[0x16] = (byte)value; } } public override int EXPGrowth { get { return Data[0x16]; } set { Data[0x16] = (byte)value; } }
public override int[] EggGroups public override int[] EggGroups
{ {
get { return new int[] { Data[0x17] >> 4, Data[0x17] & 0xF }; } get { return new[] { Data[0x17] >> 4, Data[0x17] & 0xF }; }
set set
{ {
if (value?.Length != 2) return; if (value?.Length != 2) return;

View file

@ -26,43 +26,11 @@ namespace PKHeX
Box = Data.Length; Box = Data.Length;
Array.Resize(ref Data, Data.Length + SIZE_RESERVED); Array.Resize(ref Data, Data.Length + SIZE_RESERVED);
Party = getPartyOffset(0); Party = getPartyOffset(0);
Personal = Version == GameVersion.GS ? PersonalTable.GS : PersonalTable.C; Personal = Version == GameVersion.GS ? PersonalTable.GS : PersonalTable.C;
OptionsOffset = 0x2000; getSAVOffsets();
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;
}
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 }; 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}; 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}; 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 @@ namespace PKHeX
return outData; 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 // Configuration
public override SaveFile Clone() { return new SAV2(Data.Take(Data.Length - SIZE_RESERVED).ToArray()); } public override SaveFile Clone() { return new SAV2(Data.Take(Data.Length - SIZE_RESERVED).ToArray()); }
@ -232,19 +236,19 @@ namespace PKHeX
// Offsets // Offsets
protected int OptionsOffset { get; set; } = int.MinValue; private int OptionsOffset { get; set; } = int.MinValue;
protected int DaylightSavingsOffset { get; set; } = int.MinValue; private int DaylightSavingsOffset { get; set; } = int.MinValue;
protected int TimePlayedOffset { get; set; } = int.MinValue; private int TimePlayedOffset { get; set; } = int.MinValue;
protected int PaletteOffset { get; set; } = int.MinValue; private int PaletteOffset { get; set; } = int.MinValue;
protected int MoneyOffset { get; set; } = int.MinValue; private int MoneyOffset { get; set; } = int.MinValue;
protected int JohtoBadgesOffset { get; set; } = int.MinValue; private int JohtoBadgesOffset { get; set; } = int.MinValue;
protected int CurrentBoxIndexOffset { get; set; } = int.MinValue; private int CurrentBoxIndexOffset { get; set; } = int.MinValue;
protected int BoxNamesOffset { get; set; } = int.MinValue; private int BoxNamesOffset { get; set; } = int.MinValue;
protected int PartyOffset { get; set; } = int.MinValue; private int PartyOffset { get; set; } = int.MinValue;
protected int PokedexSeenOffset { get; set; } = int.MinValue; private int PokedexSeenOffset { get; set; } = int.MinValue;
protected int PokedexCaughtOffset { get; set; } = int.MinValue; private int PokedexCaughtOffset { get; set; } = int.MinValue;
protected int CurrentBoxOffset { get; set; } = int.MinValue; private int CurrentBoxOffset { get; set; } = int.MinValue;
protected int GenderOffset { get; set; } = int.MinValue; private int GenderOffset { get; set; } = int.MinValue;
// Checksums // Checksums
protected override void setChecksums() protected override void setChecksums()
@ -337,7 +341,7 @@ namespace PKHeX
return 0; 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 // Trainer Info
public override GameVersion Version { get; protected set; } public override GameVersion Version { get; protected set; }

View file

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Windows.Forms;
namespace PKHeX namespace PKHeX
{ {

View file

@ -59,7 +59,6 @@ namespace PKHeX
{ {
SAV2 sav2 = (SAV2)SAV; SAV2 sav2 = (SAV2)SAV;
MT_Coins.Text = sav2.Coin.ToString(); MT_Coins.Text = sav2.Coin.ToString();
badgeval = sav2.Badges;
L_Started.Visible = L_Fame.Visible = false; L_Started.Visible = L_Fame.Visible = false;
CAL_AdventureStartDate.Visible = CAL_HoFDate.Visible = false; CAL_AdventureStartDate.Visible = CAL_HoFDate.Visible = false;