Refactoring

This commit is contained in:
Kaphotics
2016-02-10 00:33:42 -08:00
parent 02c786f91f
commit d2214f4fa1
23 changed files with 80 additions and 93 deletions

View File

@@ -8,7 +8,6 @@ namespace PKHeX
{
public partial class CodeGenerator : Form
{
byte[] codedata = new byte[232];
byte[] newdata = new byte[232];
readonly byte[] tabdata;
@@ -132,18 +131,18 @@ private void B_Save_Click(object sender, EventArgs e)
// Gotta read in the textbox.
if (RTB_Code.Text.Length < 1) return;
byte[] ncf = new byte[4 + (RTB_Code.Lines.Count()-1)*3*4];
byte[] ncf = new byte[4 + (RTB_Code.Lines.Length-1)*3*4];
Array.Copy(BitConverter.GetBytes(ncf.Length - 4), ncf, 4);
for (int i = 0; i < RTB_Code.Lines.Count()-1; i++)
for (int i = 0; i < RTB_Code.Lines.Length-1; i++)
{
string line = RTB_Code.Lines[i];
string[] rip = line.Split(new[] {" "}, StringSplitOptions.None);
// Write the 3 u32's to an array.
Array.Copy(BitConverter.GetBytes(UInt32.Parse(rip[0], NumberStyles.HexNumber)),0,ncf,4+i*12+0,4);
Array.Copy(BitConverter.GetBytes(UInt32.Parse(rip[1], NumberStyles.HexNumber)),0,ncf,4+i*12+4,4);
Array.Copy(BitConverter.GetBytes(UInt32.Parse(rip[2], NumberStyles.HexNumber)),0,ncf,4+i*12+8,4);
Array.Copy(BitConverter.GetBytes(uint.Parse(rip[0], NumberStyles.HexNumber)),0,ncf,4+i*12+0,4);
Array.Copy(BitConverter.GetBytes(uint.Parse(rip[1], NumberStyles.HexNumber)),0,ncf,4+i*12+4,4);
Array.Copy(BitConverter.GetBytes(uint.Parse(rip[2], NumberStyles.HexNumber)),0,ncf,4+i*12+8,4);
}
SaveFileDialog sfd = new SaveFileDialog {FileName = "code.bin", Filter = "Code File|*.bin"};
@@ -185,7 +184,7 @@ private void B_Diff_Click(object sender, EventArgs e)
{
string result = "";
RTB_Code.Clear();
byte[] cybersav = Main.originalSAV;
byte[] cybersav = Main.SAV.BAK;
byte[] newcyber = Main.SAV.Data;
int boxoffset = Main.SAV.Box;
@@ -215,17 +214,17 @@ private void B_Diff_Click(object sender, EventArgs e)
// Loop Through Party
for (int i = 0x14200; i < 0x14200 + 260 * 6; i+= 260)
{
byte[] newdata = new byte[260]; Array.Copy(newcyber, i, newdata, 0, 260);
byte[] bytes = new byte[260]; Array.Copy(newcyber, i, bytes, 0, 260);
byte[] olddata = new byte[260]; Array.Copy(cybersav, i, olddata, 0, 260);
if (newdata.SequenceEqual(olddata)) continue;
if (bytes.SequenceEqual(olddata)) continue;
for (int z = 0; z < newdata.Length; z += 4)
for (int z = 0; z < bytes.Length; z += 4)
{
result += (0x20000000 + i + z).ToString("X8") + " ";
result += BitConverter.ToUInt32(newdata, z).ToString("X8") + Environment.NewLine;
result += BitConverter.ToUInt32(bytes, z).ToString("X8") + Environment.NewLine;
lines++;
if ((lines % 128 == 0) && CHK_Break.Checked)
if (lines % 128 == 0 && CHK_Break.Checked)
{
result +=
Environment.NewLine +
@@ -256,14 +255,14 @@ private void B_Diff_Click(object sender, EventArgs e)
// Loop Through Boxes
for (int i = boxoffset; i < boxoffset + 232 * 30 * 31; i += 232)
{
byte[] newdata = new byte[232]; Array.Copy(newcyber, i, newdata, 0, 232);
byte[] bytes = new byte[232]; Array.Copy(newcyber, i, bytes, 0, 232);
byte[] olddata = new byte[232]; Array.Copy(cybersav, i, olddata, 0, 232);
if (newdata.SequenceEqual(olddata)) continue;
if (bytes.SequenceEqual(olddata)) continue;
for (int z = 0; z < newdata.Length; z += 4)
for (int z = 0; z < bytes.Length; z += 4)
{
result += (0x20000000 + i + z).ToString("X8") + " ";
result += BitConverter.ToUInt32(newdata, z).ToString("X8") + Environment.NewLine;
result += BitConverter.ToUInt32(bytes, z).ToString("X8") + Environment.NewLine;
lines++;
if ((lines % 128 == 0) && CHK_Break.Checked)
@@ -304,20 +303,19 @@ private void B_Import_Click(object sender, EventArgs e)
if (RTB_Code.Text.Length < 1) return;
byte[] data = new byte[0];
// Get Actual Lines
for (int i = 0; i < RTB_Code.Lines.Count(); i++)
foreach (string line in RTB_Code.Lines)
{
if (RTB_Code.Lines[i].Length <= 0) continue;
if (line.Length <= 0) continue;
if (RTB_Code.Lines[i].Length <= 2 * 8 && RTB_Code.Lines[i].Length > 2 * 8 + 2)
if (line.Length <= 2 * 8 && line.Length > 2 * 8 + 2)
{ Util.Error("Invalid code pasted (Type)"); return; }
try
{
// Grab Line Data
string line = RTB_Code.Lines[i];
string[] rip = line.Split(new[] { " " }, StringSplitOptions.None);
Array.Resize(ref data, data.Length + 4);
Array.Copy(BitConverter.GetBytes(UInt32.Parse(rip[1], NumberStyles.HexNumber)), 0, data, data.Length - 4, 4);
BitConverter.GetBytes(uint.Parse(rip[1], NumberStyles.HexNumber)).CopyTo(data, data.Length - 4);
}
catch (Exception x)
{ Util.Error("Invalid code pasted (Content):", x.ToString()); return; }

View File

@@ -1,6 +1,6 @@
namespace PKHeX
{
class Legal
internal static class Legal
{
// PKHeX Valid Array Storage
#region Items

View File

@@ -5,7 +5,7 @@ namespace PKHeX
{
public class PGF
{
internal static int Size = 0xCC;
internal const int Size = 0xCC;
public byte[] Data;
public PGF(byte[] data = null)

View File

@@ -4,7 +4,7 @@ namespace PKHeX
{
public class PCD
{
internal static int Size = 0x358; // 856
internal const int Size = 0x358; // 856
public byte[] Data;
public PCD(byte[] data = null)

View File

@@ -5,9 +5,9 @@ namespace PKHeX
{
public class PK3 // 3rd Generation PKM File
{
internal static readonly int SIZE_PARTY = 100;
internal static readonly int SIZE_STORED = 80;
internal static readonly int SIZE_BLOCK = 12;
internal const int SIZE_PARTY = 100;
internal const int SIZE_STORED = 80;
internal const int SIZE_BLOCK = 12;
public PK3(byte[] decryptedData = null, string ident = null)
{

View File

@@ -5,9 +5,9 @@ namespace PKHeX
{
public class PK4 // 4th Generation PKM File
{
internal static readonly int SIZE_PARTY = 236;
internal static readonly int SIZE_STORED = 136;
internal static readonly int SIZE_BLOCK = 32;
internal const int SIZE_PARTY = 236;
internal const int SIZE_STORED = 136;
internal const int SIZE_BLOCK = 32;
public PK4(byte[] decryptedData = null, string ident = null)
{

View File

@@ -6,9 +6,9 @@ namespace PKHeX
{
public class PK5 // 5th Generation PKM File
{
internal static readonly int SIZE_PARTY = 220;
internal static readonly int SIZE_STORED = 136;
internal static readonly int SIZE_BLOCK = 32;
internal const int SIZE_PARTY = 220;
internal const int SIZE_STORED = 136;
internal const int SIZE_BLOCK = 32;
public PK5(byte[] decryptedData = null, string ident = null)
{

View File

@@ -7,8 +7,8 @@ namespace PKHeX
{
public class PK6 : PKX
{
internal static readonly int SIZE_PARTY = 0x104;
internal static readonly int SIZE_STORED = 0xE8;
internal const int SIZE_PARTY = 0x104;
internal const int SIZE_STORED = 0xE8;
public PK6(byte[] decryptedData = null, string ident = null)
{

View File

@@ -3,7 +3,7 @@
namespace PKHeX
{
public class PKM // Past Gen
public static class PKM // Past Gen
{
internal static uint LCRNG(uint seed)
{
@@ -231,7 +231,7 @@ internal static string getSpeciesName(int species, int language)
}
#region Gen 3 Species Table
internal static int[] newindex =
internal static readonly int[] newindex =
{
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,
@@ -252,7 +252,7 @@ internal static string getSpeciesName(int species, int language)
345,346,347,348,280,281,282,371,372,373,374,375,376,377,378,379,382,383,384,380,381,
385,386,358,
};
internal static int[] oldindex =
internal static readonly int[] oldindex =
{
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,
@@ -275,7 +275,7 @@ internal static string getSpeciesName(int species, int language)
};
#endregion
#region Gen 3 Ability Table
internal static byte[][] Gen3Abilities =
internal static readonly byte[][] Gen3Abilities =
{
new byte[] {0x00, 0x00}, // 000
new byte[] {0x41, 0x41}, // 001
@@ -1057,7 +1057,7 @@ internal static string getSpeciesName(int species, int language)
};
#endregion
internal static byte[][] G4TransferTrashBytes = {
internal static readonly byte[][] G4TransferTrashBytes = {
new byte[] { }, // Unused
new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
new byte[] { 0x18, 0x20, 0x0D, 0x02, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0xA1, 0x0C, 0x02, 0xE0, 0xFF },

View File

@@ -135,7 +135,7 @@ internal static uint LCRNG(ref uint seed)
};
#endregion
internal static string[][] SpeciesLang =
internal static readonly string[][] SpeciesLang =
{
Util.getStringList("Species", "ja"), // none
Util.getStringList("Species", "ja"), // 1
@@ -775,7 +775,7 @@ internal static Image getSprite(byte[] data)
// Font Related
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
internal static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pdv, [System.Runtime.InteropServices.In] ref uint pcFonts);
internal static PrivateFontCollection s_FontCollection = new PrivateFontCollection();
internal static readonly PrivateFontCollection s_FontCollection = new PrivateFontCollection();
internal static FontFamily[] FontFamilies
{
get
@@ -1130,7 +1130,7 @@ internal static int[] setHPIVs(int type, int[] ivs)
ivs[i] = (ivs[i] & 0x1E) + hpivs[type, i];
return ivs;
}
internal static string[] hptypes = {
internal static readonly string[] hptypes = {
"Fighting", "Flying", "Poison", "Ground",
"Rock", "Bug", "Ghost", "Steel", "Fire", "Water",
"Grass", "Electric", "Psychic", "Ice", "Dragon", "Dark"
@@ -1154,17 +1154,16 @@ internal static int[] setHPIVs(int type, int[] ivs)
{ 1, 1, 1, 1, 1, 1 }, // Dark
};
internal static string[] StatNames = { "HP", "Atk", "Def", "SpA", "SpD", "Spe" };
internal static readonly string[] StatNames = { "HP", "Atk", "Def", "SpA", "SpD", "Spe" };
public class ShowdownSet
{
internal static string[] species = Util.getStringList("Species", "en");
internal static string[] items = Util.getStringList("Items", "en");
internal static string[] natures = Util.getStringList("Natures", "en");
internal static string[] moves = Util.getStringList("Moves", "en");
internal static string[] abilities = Util.getStringList("Abilities", "en");
internal static readonly string[] species = Util.getStringList("Species", "en");
internal static readonly string[] items = Util.getStringList("Items", "en");
internal static readonly string[] natures = Util.getStringList("Natures", "en");
internal static readonly string[] moves = Util.getStringList("Moves", "en");
internal static readonly string[] abilities = Util.getStringList("Abilities", "en");
// Default Set Data
public string Text;
public string Nickname;
public int Species;
public string Form;
@@ -1185,7 +1184,6 @@ public ShowdownSet(string input = null)
if (input == null)
return;
Text = input;
Nickname = null;
Species = -1;
Form = null;

View File

@@ -20,10 +20,10 @@ public enum GameVersion
}
public class SAV6 : PKX
{
internal static readonly int SIZE_XY = 0x65600;
internal static readonly int SIZE_ORAS = 0x76000;
internal static readonly int SIZE_ORASDEMO = 0x5A00;
internal static readonly int BEEF = 0x42454546;
internal const int SIZE_XY = 0x65600;
internal const int SIZE_ORAS = 0x76000;
internal const int SIZE_ORASDEMO = 0x5A00;
internal const int BEEF = 0x42454546;
// Global Settings
internal static bool SetUpdateDex = true;

View File

@@ -49,13 +49,6 @@ internal static Bitmap ChangeOpacity(Image img, double trans)
}
// Strings and Paths
internal static FileInfo GetNewestFile(DirectoryInfo directory)
{
return directory.GetFiles()
.Union(directory.GetDirectories().Select(GetNewestFile))
.OrderByDescending(f => f?.LastWriteTime ?? DateTime.MinValue)
.FirstOrDefault();
}
internal static string NormalizePath(string path)
{
return Path.GetFullPath(new Uri(path).LocalPath)
@@ -182,7 +175,7 @@ internal static string[] getNulledStringArray(string[] SimpleStringList)
}
// Randomization
internal static Random rand = new Random();
internal static readonly Random rand = new Random();
internal static uint rnd32()
{
return (uint)rand.Next(1 << 30) << 2 | (uint)rand.Next(1 << 2);
@@ -420,7 +413,7 @@ internal static List<cbItem> getOffsetCBList(List<cbItem> cbList, string[] inStr
}));
return cbList;
}
internal static List<cbItem> getVariedCBList(List<cbItem> cbList, string[] inStrings, int[] stringNum, int[] stringVal)
internal static List<cbItem> getVariedCBList(string[] inStrings, int[] stringNum, int[] stringVal)
{
// Set up
List<cbItem> newlist = new List<cbItem>();

View File

@@ -6,7 +6,7 @@ namespace PKHeX
{
public class WC6
{
internal static int Size = 0x108;
internal const int Size = 0x108;
public byte[] Data;
public WC6(byte[] data = null)

View File

@@ -130,7 +130,6 @@ public Main()
public static readonly byte[] blankEK6 = PKX.encryptArray(new byte[PK6.SIZE_PARTY]);
public static PK6 pk6 = new PK6(); // Tab Pokemon Data Storage
public static SAV6 SAV = new SAV6(); // Save File
public static byte[] originalSAV; // original save for CyberGadget Codes
public static string pathSDF;
public static string path3DS;
@@ -139,14 +138,14 @@ public Main()
public static Color defaultControlWhite;
public static Color defaultControlText;
public static int colorizedbox = 32;
public static Image mixedHighlight = Util.ChangeOpacity(Properties.Resources.slotSet, 0.5);
public static readonly Image mixedHighlight = Util.ChangeOpacity(Properties.Resources.slotSet, 0.5);
public static Image colorizedcolor;
public static int colorizedslot;
public static string eggname = "";
public static string DatabasePath = "db";
public static string BackupPath = "bak";
public static string[] lang_val = { "en", "ja", "fr", "it", "de", "es", "ko", "zh", "pt" };
public static string[] main_langlist =
public static readonly string[] lang_val = { "en", "ja", "fr", "it", "de", "es", "ko", "zh", "pt" };
public static readonly string[] main_langlist =
{
"English", // ENG
"日本語", // JPN
@@ -161,7 +160,7 @@ public Main()
public static string[] gendersymbols = { "♂", "♀", "-" };
public static string[] specieslist, movelist, itemlist, abilitylist, types, natures, forms,
memories, genloc, trainingbags, trainingstage, characteristics,
encountertypelist, gamelanguages, consoleregions, balllist, gamelist, pokeblocks = { };
encountertypelist, gamelanguages, balllist, gamelist, pokeblocks = { };
public static string origintrack;
public static string[] metHGSS_00000, metHGSS_02000, metHGSS_03000 = { };
public static string[] metBW2_00000, metBW2_30000, metBW2_40000, metBW2_60000 = { };
@@ -169,7 +168,7 @@ public Main()
public static string[] wallpapernames, puffs, itempouch = { };
public static string curlanguage = "en";
public static bool unicode;
public ToolTip Tip1 = new ToolTip(), Tip2 = new ToolTip(), Tip3 = new ToolTip(), NatureTip = new ToolTip();
public readonly ToolTip Tip1 = new ToolTip(), Tip2 = new ToolTip(), Tip3 = new ToolTip(), NatureTip = new ToolTip();
public static List<Util.cbItem> MoveDataSource, ItemDataSource, SpeciesDataSource, BallDataSource, NatureDataSource, AbilityDataSource, VersionDataSource;
public readonly PictureBox[] SlotPictureBoxes;
#endregion
@@ -820,7 +819,6 @@ private void InitializeStrings()
encountertypelist = Util.getStringList("EncounterType", l);
gamelist = Util.getStringList("Games", l);
gamelanguages = Util.getNulledStringArray(Util.getStringList("languages"));
consoleregions = Util.getNulledStringArray(Util.getStringList("regions3ds"));
balllist = new string[Legal.Items_Ball.Length];
for (int i = 0; i < balllist.Length; i++)
@@ -973,7 +971,7 @@ private void InitializeLanguage()
CB_Language.DataSource = Util.getUnsortedCBList("languages");
int[] ball_nums = { 7, 576, 13, 492, 497, 14, 495, 493, 496, 494, 11, 498, 8, 6, 12, 15, 9, 5, 499, 10, 1, 16 };
int[] ball_vals = { 7, 25, 13, 17, 22, 14, 20, 18, 21, 19, 11, 23, 8, 6, 12, 15, 9, 5, 24, 10, 1, 16 };
BallDataSource = Util.getVariedCBList(Util.getCBList(itemlist, new[] { 4 }, new[] { 3 }, new[] { 2 }, new[] { 1 }), itemlist, ball_nums, ball_vals);
BallDataSource = Util.getVariedCBList(itemlist, ball_nums, ball_vals);
ItemDataSource = Util.getCBList(itemlist, DEV_Ability.Enabled ? null : Legal.Items_Held);
SpeciesDataSource = Util.getCBList(specieslist, null);
NatureDataSource = Util.getCBList(natures, null);

View File

@@ -12,8 +12,7 @@ public SAV_BerryFieldXY()
sav = (byte[])Main.SAV.Data.Clone();
listBox1.SelectedIndex = 0;
}
public byte[] sav;
public bool editing = false;
public readonly byte[] sav;
private void changefield(object sender, EventArgs e)
{

View File

@@ -24,8 +24,8 @@ public SAV_EventFlagsORAS()
}
private bool setup = true;
public CheckBox[] chka;
public bool[] flags = new bool[3072];
public ushort[] Constants = new ushort[(Main.SAV.EventFlag - Main.SAV.EventConst) / 2];
public readonly bool[] flags = new bool[3072];
public readonly ushort[] Constants = new ushort[(Main.SAV.EventFlag - Main.SAV.EventConst) / 2];
private void B_Cancel_Click(object sender, EventArgs e)
{
Close();

View File

@@ -23,9 +23,9 @@ public SAV_EventFlagsXY()
// No Volcanic Ash in X/Y
}
private bool setup = true;
public CheckBox[] chka;
public bool[] flags = new bool[3072];
public ushort[] Constants = new ushort[(Main.SAV.EventFlag - Main.SAV.EventConst) / 2];
private CheckBox[] chka;
private readonly bool[] flags = new bool[3072];
private readonly ushort[] Constants = new ushort[(Main.SAV.EventFlag - Main.SAV.EventConst) / 2];
private void B_Cancel_Click(object sender, EventArgs e)
{
Close();

View File

@@ -29,8 +29,9 @@ public SAV_Inventory()
B_DisplayBerries.Text = Main.itempouch[3];
B_DisplayKeyItems.Text = Main.itempouch[4];
}
public byte[] sav;
public string[] item_val, keyitem_val, tmhm_val, medicine_val, berries_val;
private readonly byte[] sav;
private readonly string[] item_val, keyitem_val, tmhm_val, medicine_val, berries_val;
// Initialize String Tables

View File

@@ -19,7 +19,7 @@ public SAV_Pokepuff()
new ToolTip().SetToolTip(B_All, "Hold CTRL to give Deluxe instead of Supreme.");
}
public byte[] sav;
private readonly byte[] sav;
private readonly string[] pfa;
private void Setup()
{

View File

@@ -22,11 +22,12 @@ public SAV_SecretBase()
MT_Flags.Text = BitConverter.ToUInt32(sav, Main.SAV.SecretBase + 0x62C).ToString(); // read counter
B_SAV2FAV(null, null);
}
public byte[] sav;
public bool editing;
private readonly byte[] sav;
private bool editing;
private bool loading = true;
public static string[] abilitylist = { };
private static string[] abilitylist = { };
private void setupComboBoxes()
{

View File

@@ -22,8 +22,8 @@ public SAV_SuperTrain()
setup();
}
public byte[] sav;
private readonly byte[] sav;
private readonly string[] trba = {
"Empty",
"HP Bag S","HP Bag M","HP Bag L",

View File

@@ -201,9 +201,8 @@ public SAV_Trainer()
CB_Stats.SelectedIndex = 0;
}
private readonly string[] statdata = { };
public bool editing;
public ToolTip Tip1 = new ToolTip();
public ToolTip Tip2 = new ToolTip();
private bool editing;
private readonly ToolTip Tip1 = new ToolTip(), Tip2 = new ToolTip();
private readonly MaskedTextBox[] MaisonRecords;
private void getComboBoxes()

View File

@@ -42,8 +42,8 @@ public SAV_Wondercard(byte[] wcdata = null)
Array.Copy(wcdata, wondercard_data, wcdata.Length);
loadwcdata();
}
public byte[] sav;
public byte[] wondercard_data = new byte[WC6.Size];
private readonly byte[] sav;
private byte[] wondercard_data = new byte[WC6.Size];
private const uint EonTicketConst = 0x225D73C2;
private readonly PictureBox[] pba;