Code cleanup

Seems like every time I go through the code I find more of my newb code.
This commit is contained in:
Kurt 2015-01-02 17:07:29 -08:00
parent bb951188a0
commit 5eaf603c3b
3 changed files with 97 additions and 128 deletions

View file

@ -18,7 +18,7 @@ namespace PKHeX
// Relies on Util for some common operations.
// Data
public static uint LCRNG(uint seed)
internal static uint LCRNG(uint seed)
{
uint a = 0x41C64E6D;
uint c = 0x00006073;
@ -26,7 +26,7 @@ namespace PKHeX
seed = (seed * a + c) & 0xFFFFFFFF;
return seed;
}
public static uint LCRNG(ref uint seed)
internal static uint LCRNG(ref uint seed)
{
uint a = 0x41C64E6D;
uint c = 0x00006073;
@ -34,7 +34,7 @@ namespace PKHeX
seed = (seed * a + c) & 0xFFFFFFFF;
return seed;
}
public static DataTable ExpTable()
internal static DataTable ExpTable()
{
DataTable table = new DataTable();
table.Columns.Add("Level", typeof(byte));
@ -149,11 +149,11 @@ namespace PKHeX
}
// Stat Fetching
public static int getMovePP(int move, int ppup)
internal static int getMovePP(int move, int ppup)
{
return (getBasePP(move) * (5 + ppup) / 5);
}
public static int getBasePP(int move)
internal static int getBasePP(int move)
{
byte[] movepptable =
{
@ -194,7 +194,7 @@ namespace PKHeX
if (move < 0) { move = 0; }
return (byte)movepptable[move];
}
public static byte[] getRandomEVs()
internal static byte[] getRandomEVs()
{
byte[] evs = new byte[6] { 0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xBE, }; // ha ha, just to start off above 510!
@ -210,11 +210,11 @@ namespace PKHeX
Util.Shuffle(evs);
return evs;
}
public static byte getBaseFriendship(int species)
internal static byte getBaseFriendship(int species)
{
return PersonalGetter.GetPersonal(species).BaseFriendship;
}
public static int getLevel(int species, ref uint exp)
internal static int getLevel(int species, ref uint exp)
{
if (exp == 0) { return 1; }
@ -235,13 +235,13 @@ namespace PKHeX
}
return --tl;
}
public static bool getIsShiny(uint PID, uint TID, uint SID)
internal static bool getIsShiny(uint PID, uint TID, uint SID)
{
uint PSV = getPSV(PID);
uint TSV = getTSV(TID, SID);
return (TSV == PSV);
}
public static uint getEXP(int level, int species)
internal static uint getEXP(int level, int species)
{
// Fetch Growth
if ((level == 0) || (level == 1))
@ -254,11 +254,11 @@ namespace PKHeX
uint exp = (uint)PKX.ExpTable().Rows[level][growth + 1];
return exp;
}
public static byte[] getAbilities(int species, int formnum)
internal static byte[] getAbilities(int species, int formnum)
{
return PersonalGetter.GetPersonal(species, formnum).Abilities;
}
public static int getGender(string s)
internal static int getGender(string s)
{
if (s == "♂" || s == "M")
return 0;
@ -266,7 +266,7 @@ namespace PKHeX
return 1;
else return 2;
}
public static string[] getCountryRegionText(int country, int region, string lang)
internal static string[] getCountryRegionText(int country, int region, string lang)
{
// Get Language we're fetching for
int index = Array.IndexOf(new string[] { "ja", "en", "fr", "de", "it", "es", "zh", "ko", }, lang);
@ -326,7 +326,7 @@ namespace PKHeX
catch { data[1] = "Illegal"; }
return data;
}
public static string getLocation(bool eggmet, int gameorigin, int locval)
internal static string getLocation(bool eggmet, int gameorigin, int locval)
{
string loctext = "";
if (gameorigin < 13 && gameorigin > 6 && eggmet)
@ -362,7 +362,7 @@ namespace PKHeX
}
return loctext;
}
public static ushort[] getStats(int species, int level, int nature, int form,
internal static ushort[] getStats(int species, int level, int nature, int form,
int HP_EV, int ATK_EV, int DEF_EV, int SPA_EV, int SPD_EV, int SPE_EV,
int HP_IV, int ATK_IV, int DEF_IV, int SPA_IV, int SPD_IV, int SPE_IV)
{
@ -397,7 +397,7 @@ namespace PKHeX
}
// Manipulation
public static byte[] shuffleArray(byte[] pkx, uint sv)
internal static byte[] shuffleArray(byte[] pkx, uint sv)
{
byte[] ekx = new byte[260];
Array.Copy(pkx, ekx, 8);
@ -423,7 +423,7 @@ namespace PKHeX
return ekx;
}
public static byte[] decryptArray(byte[] ekx)
internal static byte[] decryptArray(byte[] ekx)
{
byte[] pkx = (byte[])ekx.Clone();
@ -447,7 +447,7 @@ namespace PKHeX
return pkx;
}
public static byte[] encryptArray(byte[] pkx)
internal static byte[] encryptArray(byte[] pkx)
{
// Shuffle
uint pv = BitConverter.ToUInt32(pkx, 0);
@ -474,7 +474,7 @@ namespace PKHeX
// Done
return ekx;
}
public static ushort getCHK(byte[] data)
internal static ushort getCHK(byte[] data)
{
ushort chk = 0;
for (int i = 8; i < 232; i += 2) // Loop through the entire PKX
@ -482,7 +482,7 @@ namespace PKHeX
return chk;
}
public static bool verifychk(byte[] input)
internal static bool verifychk(byte[] input)
{
ushort checksum = 0;
if (input.Length == 100 || input.Length == 80) // Gen 3 Files
@ -507,15 +507,15 @@ namespace PKHeX
return (chk == BitConverter.ToUInt16(input, 0x6));
}
}
public static uint getPSV(uint PID)
internal static uint getPSV(uint PID)
{
return Convert.ToUInt16(((PID >> 16) ^ (PID & 0xFFFF)) >> 4);
}
public static uint getTSV(uint TID, uint SID)
internal static uint getTSV(uint TID, uint SID)
{
return ((TID ^ SID) >> 4);
}
public static uint getRandomPID(int species, int cg)
internal static uint getRandomPID(int species, int cg)
{
PersonalParser.Personal MonData = PersonalGetter.GetPersonal(species);
int gt = MonData.GenderRatio;
@ -1197,7 +1197,6 @@ namespace PKHeX
data.FormPointer = MonData[0xD];
return data;
}
internal Personal GetPersonal(int species, int formID)
{
Personal data = GetPersonal(species);

View file

@ -226,7 +226,7 @@ namespace PKHeX
return 0;
try
{
value = value.TrimEnd(new char[]{'_'});
value = value.TrimEnd(new char[] { '_' });
return Int32.Parse(value);
}
catch { return 0; }
@ -238,7 +238,7 @@ namespace PKHeX
return 0;
try
{
value = value.TrimEnd(new char[]{'_'});
value = value.TrimEnd(new char[] { '_' });
return UInt32.Parse(value);
}
catch { return 0; }
@ -257,7 +257,7 @@ namespace PKHeX
return 0;
try
{ val = Util.ToInt32(cb.SelectedValue.ToString()); }
{ val = (int)cb.SelectedValue; }
catch
{ val = cb.SelectedIndex; if (val < 0) val = 0; }
return val;
@ -274,7 +274,7 @@ namespace PKHeX
c = str[i];
// filter for hex
if ((c < 0x0047 && c > 0x002F) || (c < 0x0067 && c > 0x0060))
s+= c;
s += c;
else
System.Media.SystemSounds.Beep.Play();
}
@ -403,11 +403,6 @@ namespace PKHeX
{
public string Text { get; set; }
public object Value { get; set; }
public override string ToString()
{
return Text;
}
}
internal static List<cbItem> getCBList(string textfile, string lang)
{

View file

@ -177,14 +177,12 @@ namespace PKHeX
}
#region Global Variables: Always Visible!
public byte[] buff = new byte[260];
public byte[] buff = new byte[260]; // Tab Pokemon Data Storage
public byte[] savefile = new byte[0x100000];
public byte[] cyberSAV = new byte[0x65600];
public bool savegame_oras = false;
public bool cybergadget = false;
public bool savLoaded = false;
public int gt = 258;
public int genderflag, species;
public int savindex;
public bool savedited;
public string SDFLoc = null;
@ -888,7 +886,7 @@ namespace PKHeX
uint PID = BitConverter.ToUInt32(buff, 0x18);
int nature = buff[0x1C];
int feflag = buff[0x1D] % 2;
this.genderflag = (buff[0x1D] >> 1) & 0x3;
int genderflag = (buff[0x1D] >> 1) & 0x3;
int altforms = (buff[0x1D] >> 3);
int HP_EV = buff[0x1E];
int ATK_EV = buff[0x1F];
@ -1116,8 +1114,7 @@ namespace PKHeX
// Load Extrabyte Value
TB_ExtraByte.Text = buff[Convert.ToInt32(CB_ExtraBytes.Text, 16)].ToString();
// Reload Gender Flag
this.genderflag = ((buff[0x1D] >> 1) & 0x3);
// Load Gender Flag
Label_Gender.Text = gendersymbols[genderflag];
updateStats();
setIsShiny();
@ -1516,9 +1513,8 @@ namespace PKHeX
private void clickGender(object sender, EventArgs e)
{
// Get Gender Threshold
species = Util.getIndex(CB_Species);
PKX.PersonalParser.Personal MonData = PKX.PersonalGetter.GetPersonal(species);
gt = MonData.GenderRatio;
PKX.PersonalParser.Personal MonData = PKX.PersonalGetter.GetPersonal(Util.getIndex(CB_Species));
int gt = MonData.GenderRatio;
if (gt == 255 || gt == 0 || gt == 254) // Single gender/genderless
return;
@ -1920,7 +1916,8 @@ namespace PKHeX
// Get Gender Threshold
species = Util.getIndex(CB_Species);
PKX.PersonalParser.Personal MonData = PKX.PersonalGetter.GetPersonal(species);
gt = MonData.GenderRatio;
int gt = MonData.GenderRatio;
int genderflag;
if (gt == 255) // Genderless
genderflag = 2;
@ -2207,7 +2204,7 @@ namespace PKHeX
private void updateStats()
{
// Gather the needed information.
species = Util.getIndex(CB_Species);
int species = Util.getIndex(CB_Species);
int level = Util.ToInt32((MT_Level.Enabled) ? MT_Level.Text : TB_Level.Text);
if (level == 0) { level = 1; }
int form = CB_Form.SelectedIndex;
@ -2621,10 +2618,7 @@ namespace PKHeX
// Dragout Display
private void dragoutHover(object sender, EventArgs e)
{
if (Util.getIndex(CB_Species) > 0)
dragout.BackgroundImage = Properties.Resources.slotSet;
else
dragout.BackgroundImage = Properties.Resources.slotDel;
dragout.BackgroundImage = (Util.getIndex(CB_Species) > 0) ? Properties.Resources.slotSet : Properties.Resources.slotDel;
}
private void dragoutLeave(object sender, EventArgs e)
{
@ -2642,7 +2636,7 @@ namespace PKHeX
{
if (savedited)
{
RTB_S.Text = "Save has been edited. Cannot integrity check.";
Util.Alert("Save has been edited. Cannot integrity check.");
return;
}
// Verify Checksums
@ -3236,15 +3230,11 @@ namespace PKHeX
// Box/SAV Functions //
private void clickBoxRight(object sender, EventArgs e)
{
if (C_BoxSelect.SelectedIndex < 30)
C_BoxSelect.SelectedIndex++;
else C_BoxSelect.SelectedIndex = 0;
C_BoxSelect.SelectedIndex = (C_BoxSelect.SelectedIndex + 1) % 31;
}
private void clickBoxLeft(object sender, EventArgs e)
{
if (C_BoxSelect.SelectedIndex > 0)
C_BoxSelect.SelectedIndex--;
else C_BoxSelect.SelectedIndex = 30;
C_BoxSelect.SelectedIndex = (C_BoxSelect.SelectedIndex + 30) % 31;
}
private void clickSlot(object sender, EventArgs e)
{
@ -3562,24 +3552,15 @@ namespace PKHeX
dcpkx1, dcpkx2, gtspkx, fusedpkx,subepkx1,subepkx2,subepkx3,
};
for (int i = 0; i < 30; i++)
{
int offset = boxoffset + 0xE8 * i;
getSlotFiller(offset, pba[i]);
}
getSlotFiller(boxoffset + 0xE8 * i, pba[i]);
// Reload Party
for (int i = 0; i < 6; i++)
{
int offset = SaveGame.Party + (0x7F000 * savindex) + 0x104 * i;
getSlotFiller(offset, pba[i + 30]);
}
getSlotFiller(SaveGame.Party + (0x7F000 * savindex) + 0x104 * i, pba[i + 30]);
// Reload Battle Box
for (int i = 0; i < 6; i++)
{
int offset = SaveGame.BattleBox + (0x7F000 * savindex) + 0xE8 * i;
getSlotFiller(offset, pba[i + 36]);
}
getSlotFiller(SaveGame.BattleBox + (0x7F000 * savindex) + 0xE8 * i, pba[i + 36]);
// Reload Daycare
Label[] dclabela = { L_DC1, L_DC2, };
@ -3587,8 +3568,7 @@ namespace PKHeX
for (int i = 0; i < 2; i++)
{
int offset = SaveGame.Daycare + (0x7F000 * savindex) + 0xE8 * i + 8 * (i + 1);
getSlotFiller(offset, pba[i + 42]);
getSlotFiller(SaveGame.Daycare + (0x7F000 * savindex) + 0xE8 * i + 8 * (i + 1), pba[i + 42]);
dctexta[i].Text = BitConverter.ToUInt32(savefile, SaveGame.Daycare + (0x7F000 * savindex) + 0xF0 * i + 4).ToString();
if (Convert.ToBoolean(savefile[SaveGame.Daycare + (0x7F000 * savindex) + 0xF0 * i])) // If Occupied
dclabela[i].Text = (i + 1) + ": ✓";
@ -4185,7 +4165,7 @@ namespace PKHeX
private void B_OUTPasserby_Click(object sender, EventArgs e)
{
string result = "";
result += "PSS List" + Environment.NewLine + Environment.NewLine;
result += "PSS List" + Environment.NewLine;
string[] headers = {
"PSS Data - Friends",
"PSS Data - Acquaintances",
@ -4194,14 +4174,18 @@ namespace PKHeX
int offset = savindex * 0x7F000 + SaveGame.PSS;
for (int g = 0; g < 3; g++)
{
result += "----" + Environment.NewLine + headers[g] + Environment.NewLine + "----" + Environment.NewLine + Environment.NewLine;
result += Environment.NewLine
+ "----" + Environment.NewLine
+ headers[g] + Environment.NewLine
+ "----" + Environment.NewLine;
uint count = BitConverter.ToUInt32(savefile, offset + 0x4E20);
int r_offset = offset;
for (int i = 0; i < 100; i++)
{
ulong unkn = BitConverter.ToUInt64(savefile, r_offset);
if (unkn == 0) break;
if (unkn == 0) break; // No data present here
if (i > 0) result += Environment.NewLine + Environment.NewLine;
string otname = Util.TrimFromZero(Encoding.Unicode.GetString(savefile, r_offset + 8, 0x1A));
string message = Util.TrimFromZero(Encoding.Unicode.GetString(savefile, r_offset + 0x22, 0x22));
@ -4217,16 +4201,8 @@ namespace PKHeX
byte game = savefile[r_offset + 0x5A];
ulong outfit = BitConverter.ToUInt64(savefile, r_offset + 0x5C);
int favpkm = BitConverter.ToUInt16(savefile, r_offset + 0x9C) & 0x7FF;
string gamename;
if (game == 24)
gamename = "X";
else if (game == 25)
gamename = "Y";
else if (game == 26)
gamename = "AS";
else if (game == 27)
gamename = "OR";
else gamename = "UNK GAME";
string gamename = "UNKNOWN GAME";
try { gamename = gamelist[game]; } catch { }
string[] cr = PKX.getCountryRegionText(country, region, curlanguage);
result +=
@ -4235,12 +4211,11 @@ namespace PKHeX
"Game: " + gamename + Environment.NewLine +
"Country: " + cr[0] + Environment.NewLine +
"Region: " + cr[1] + Environment.NewLine +
"Favorite: " + specieslist[favpkm] + Environment.NewLine;
"Favorite: " + specieslist[favpkm];
result += Environment.NewLine;
r_offset += 0xC8;
r_offset += 0xC8; // Advance to next entry
}
offset += 0x5000;
offset += 0x5000; // Advance to next block
}
RTB_T.Text = result;
RTB_T.Font = new Font("Courier New", 8);