diff --git a/Misc/CodeGenerator.cs b/Misc/CodeGenerator.cs index 21d8bcfed..23f2cb14f 100644 --- a/Misc/CodeGenerator.cs +++ b/Misc/CodeGenerator.cs @@ -11,19 +11,15 @@ public partial class CodeGenerator : Form { byte[] codedata = new byte[232]; byte[] newdata = new byte[232]; - PKX.Structures.SaveGame SaveGame = new PKX.Structures.SaveGame(null); - Form1 m_parent; byte[] tabdata; - public CodeGenerator(Form1 frm1, byte[] formdata) + public CodeGenerator(byte[] formdata) { - m_parent = frm1; tabdata = formdata; InitializeComponent(); CenterToParent(); RTB_Code.Clear(); TB_Write.Clear(); - SaveGame = m_parent.SaveGame; CB_Box.Items.Clear(); for (int i = 1; i <= 31; i++) CB_Box.Items.Add(i.ToString()); @@ -49,8 +45,8 @@ private bool loaddata() else if (CB_Source.SelectedIndex == 1) { newdata = new byte[0xE8]; - Array.Copy(m_parent.savefile, - SaveGame.Box // Box Offset + Array.Copy(Main.savefile, + Main.SaveGame.Box // Box Offset + CB_Box.SelectedIndex * (232 * 30) // Box Shift + CB_Slot.SelectedIndex * 232, // Slot Shift newdata, 0, 0xE8); @@ -65,9 +61,9 @@ private bool loaddata() // Wondercard newdata = new byte[0x108]; // Wondercard # - int wcn = CB_Slot.SelectedIndex; + int index = CB_Slot.SelectedIndex; // copy from save, the chosen wondercard offset, to new data - Array.Copy(m_parent.savefile, SaveGame.Wondercard + wcn * 0x108 + 0x100, newdata, 0, 0x108); + Array.Copy(Main.savefile, Main.SaveGame.WondercardData + index * 0x108, newdata, 0, 0x108); byte[] zerodata = new byte[0x108]; if (!newdata.SequenceEqual(zerodata)) return true; @@ -76,52 +72,6 @@ private bool loaddata() } return true; } - private void changeDataSource(object sender, EventArgs e) - { - int sourceindex = CB_Source.SelectedIndex; - B_Add.Enabled = true; - - if (sourceindex == 0) - { - // Hide Box/Etc - CB_Box.Visible = false; - L_Box.Visible = false; - CB_Slot.Visible = false; - L_Slot.Visible = false; - - TB_Write.Text = (0x27A00 - 0x5400).ToString("X8"); // Box 1, Slot 1 - } - else if (sourceindex == 1) - { - CB_Box.Visible = L_Box.Visible = true; - CB_Slot.Visible = L_Slot.Visible = true; - - L_Slot.Text = "Slot:"; - - CB_Slot.Items.Clear(); - for (int i = 1; i <= 30; i++) - CB_Slot.Items.Add(i.ToString()); - - CB_Slot.SelectedIndex = 0; - - TB_Write.Text = (0x27A00 - 0x5400).ToString("X8"); // Box 1, Slot 1 - } - else if (sourceindex == 2) - { - CB_Box.Visible = L_Box.Visible = false; - CB_Slot.Visible = L_Slot.Visible = true; - - L_Slot.Text = "Card:"; - - // Set up cards - CB_Slot.Items.Clear(); - for (int i = 1; i <= 24; i++) - CB_Slot.Items.Add(i.ToString()); - - CB_Slot.SelectedIndex = 0; - TB_Write.Text = (0x22000 - 0x5400).ToString("X8"); // WC Slot 1 - } - } private void B_Add_Click(object sender, EventArgs e) { @@ -236,20 +186,11 @@ private void B_Diff_Click(object sender, EventArgs e) { string result = ""; RTB_Code.Clear(); - byte[] cybersav = m_parent.cyberSAV; - byte[] editedsav = m_parent.savefile; - byte[] newcyber = new byte[m_parent.cyberSAV.Length]; - Array.Copy(editedsav, 0x5400, newcyber, 0, newcyber.Length); - - int boxoffset = 0x22600; - if (m_parent.savegame_oras) boxoffset = 0x33000; - - if (!m_parent.cybergadget) - { - Array.Copy(editedsav, m_parent.savindex * 0x7F000 + 0x5400, - newcyber, 0, newcyber.Length); - } + byte[] cybersav = Main.originalSAV; + byte[] newcyber = Main.savefile; + int boxoffset = Main.SaveGame.Box; + int lines = 0; // 65400 for (int i = 0; i < newcyber.Length - 0x200; i += 4) { diff --git a/Misc/PKX.cs b/Misc/PKX.cs index 7b6cc6986..74a52e6b5 100644 --- a/Misc/PKX.cs +++ b/Misc/PKX.cs @@ -323,23 +323,23 @@ internal static string getLocation(bool eggmet, int gameorigin, int locval) { if (gameorigin < 13 && gameorigin > 6 && eggmet) { - if (locval < 2000) return Form1.metHGSS_00000[locval]; - if (locval < 3000) return Form1.metHGSS_02000[locval % 2000]; - return Form1.metHGSS_03000[locval % 3000]; + if (locval < 2000) return Main.metHGSS_00000[locval]; + if (locval < 3000) return Main.metHGSS_02000[locval % 2000]; + return Main.metHGSS_03000[locval % 3000]; } if (gameorigin < 24) { - if (locval < 30000) return Form1.metBW2_00000[locval]; - if (locval < 40000) return Form1.metBW2_30000[locval % 10000 - 1]; - if (locval < 60000) return Form1.metBW2_40000[locval % 10000 - 1]; - return Form1.metBW2_60000[locval % 10000 - 1]; + if (locval < 30000) return Main.metBW2_00000[locval]; + if (locval < 40000) return Main.metBW2_30000[locval % 10000 - 1]; + if (locval < 60000) return Main.metBW2_40000[locval % 10000 - 1]; + return Main.metBW2_60000[locval % 10000 - 1]; } if (gameorigin > 23) { - if (locval < 30000) return Form1.metXY_00000[locval]; - if (locval < 40000) return Form1.metXY_30000[locval % 10000 - 1]; - if (locval < 60000) return Form1.metXY_40000[locval % 10000 - 1]; - return Form1.metXY_60000[locval % 10000 - 1]; + if (locval < 30000) return Main.metXY_00000[locval]; + if (locval < 40000) return Main.metXY_30000[locval % 10000 - 1]; + if (locval < 60000) return Main.metXY_40000[locval % 10000 - 1]; + return Main.metXY_60000[locval % 10000 - 1]; } return null; // Shouldn't happen. } @@ -745,7 +745,7 @@ public PKX(byte[] pkx, string ident) motgender = (pkx[0xDD]) >> 7; mencountertype = pkx[0xDE]; mgamevers = pkx[0xDF]; - string[] data = getCountryRegionText(pkx[0xE0], pkx[0xE1], Form1.curlanguage); + string[] data = getCountryRegionText(pkx[0xE0], pkx[0xE1], Main.curlanguage); mcountryID = data[0x0]; mregionID = data[0x1]; mdsregID = pkx[0xE2]; @@ -774,26 +774,26 @@ public PKX(byte[] pkx, string ident) } try { - mSpeciesName = Form1.specieslist[mspecies]; - mhelditemN = Form1.itemlist[mhelditem]; - mNatureName = Form1.natures[mnature]; - mHPName = Form1.types[mhptype]; - mAbilityName = Form1.abilitylist[mability]; - mMove1N = Form1.movelist[mmove1]; - mMove2N = Form1.movelist[mmove2]; - mMove3N = Form1.movelist[mmove3]; - mMove4N = Form1.movelist[mmove4]; - mRMove1N = Form1.movelist[meggmove1]; - mRMove2N = Form1.movelist[meggmove2]; - mRMove3N = Form1.movelist[meggmove3]; - mRMove4N = Form1.movelist[meggmove4]; + mSpeciesName = Main.specieslist[mspecies]; + mhelditemN = Main.itemlist[mhelditem]; + mNatureName = Main.natures[mnature]; + mHPName = Main.types[mhptype]; + mAbilityName = Main.abilitylist[mability]; + mMove1N = Main.movelist[mmove1]; + mMove2N = Main.movelist[mmove2]; + mMove3N = Main.movelist[mmove3]; + mMove4N = Main.movelist[mmove4]; + mRMove1N = Main.movelist[meggmove1]; + mRMove2N = Main.movelist[meggmove2]; + mRMove3N = Main.movelist[meggmove3]; + mRMove4N = Main.movelist[meggmove4]; mMetLocN = getLocation(false, mgamevers, mmetloc); mEggLocN = getLocation(true, mgamevers, meggloc); mLevel = getLevel(mspecies, ref mexp); - mGameN = Form1.gamelist[mgamevers]; - mBallN = Form1.balllist[mball]; - motlangN = Form1.gamelanguages[motlang] ?? String.Format("UNK {0}", motlang); - mdsregIDN = Form1.consoleregions[mdsregID] ?? String.Format("UNK {0}", mdsregID); + mGameN = Main.gamelist[mgamevers]; + mBallN = Main.balllist[mball]; + motlangN = Main.gamelanguages[motlang] ?? String.Format("UNK {0}", motlang); + mdsregIDN = Main.consoleregions[mdsregID] ?? String.Format("UNK {0}", mdsregID); } catch { return; } } @@ -942,85 +942,138 @@ public PK6(byte[] pk6) } public struct SaveGame { - public int Box, TrainerCard, Party, BattleBox, GTS, Daycare, Fused, SUBE, Puff, Item, Trainer1, Trainer2, PCLayout, Wondercard, BerryField, OPower, EventFlag, PokeDex, HoF, PSS, JPEG; + public class Inventory + { + public int HeldItem, KeyItem, Medicine, TMHM, Berry; + public Inventory(string GameID, int Offset) + { + switch (GameID) + { + case "XY": + HeldItem = Offset + 0; + KeyItem = Offset + 0x640; + TMHM = Offset + 0x7C0; + Medicine = Offset + 0x968; + Berry = Offset + 0xA68; + break; + case "ORAS": + HeldItem = Offset + 0; + KeyItem = Offset + 0x640; + TMHM = Offset + 0x7C0; + Medicine = Offset + 0x970; + Berry = Offset + 0xA70; + break; + default: + HeldItem = KeyItem = TMHM = Medicine = Berry = 0; + break; + } + } + } + public int Box, TrainerCard, Party, BattleBox, GTS, Daycare, EonTicket, + Fused, SUBE, Puff, Item, Trainer1, Trainer2, SuperTrain, PSSStats, MaisonStats, Vivillon, SecretBase, + PCLayout, PCBackgrounds, PCFlags, WondercardFlags, WondercardData, BerryField, OPower, EventConst, EventFlag, EventAsh, + PokeDex, PokeDexLanguageFlags, Spinda, EncounterCount, HoF, PSS, JPEG; + + public Inventory Items; public string Name; + public int[] DaycareSlot; + public bool ORAS; + public SaveGame(string GameID) { switch (GameID) { case "XY": Name = "XY"; - Box = 0x27A00; - TrainerCard = 0x19400; - Party = 0x19600; - BattleBox = 0x09E00; - Daycare = 0x20600; - GTS = 0x1CC00; - Fused = 0x1B400; - SUBE = 0x22C90; - Puff = 0x5400; - Item = 0x5800; - Trainer1 = 0x6800; - Trainer2 = 0x9600; - PCLayout = 0x9800; - Wondercard = 0x21000; - BerryField = 0x20C00; - OPower = 0x1BE00; - EventFlag = 0x19E00; - PokeDex = 0x1A400; - HoF = 0x1E800; - JPEG = 0x5C600; - PSS = 0x0A400; + ORAS = false; + Box = 0x22600; + TrainerCard = 0x14000; + Party = 0x14200; + BattleBox = 0x04A00; + Daycare = 0x1B200; + GTS = 0x17800; + Fused = 0x16000; + SUBE = 0x1D890; + Puff = 0x00000; + Item = 0x00400; + Items = new Inventory(Name, Item); + Trainer1 = 0x1400; + Trainer2 = 0x4200; + PCLayout = 0x4400; + PCBackgrounds = PCLayout + 0x41E; + PCFlags = PCLayout + 0x43D; + WondercardFlags = 0x1BC00; + WondercardData = WondercardFlags + 0x100; + BerryField = 0x1B800; + OPower = 0x16A00; + EventConst = 0x14A00; + EventAsh = -1; + EventFlag = EventConst + 0x2FC; + PokeDex = 0x15000; + PokeDexLanguageFlags = PokeDex + 0x3C8; + Spinda = PokeDex + 0x648; + EncounterCount = -1; + HoF = 0x19400; + SuperTrain = 0x1F200; + JPEG = 0x57200; + MaisonStats = 0x1B1C0; + PSS = 0x05000; + PSSStats = 0x1E400; + Vivillon = 0x4250; + SecretBase = -1; + EonTicket = -1; break; case "ORAS": Name = "ORAS"; - Box = 0x38400; // Confirmed - TrainerCard = 0x19400; // Confirmed - Party = 0x19600; // Confirmed - BattleBox = 0x09E00;// Confirmed - Daycare = 0x21000; // Confirmed (thanks Rei) - GTS = 0x1D600; // Confirmed - Fused = 0x1BE00; // Confirmed - SUBE = 0x22C90; // ****not in use, not updating?**** - Puff = 0x5400; // Confirmed - Item = 0x5800; // Confirmed - Trainer1 = 0x6800; // Confirmed - Trainer2 = 0x9600; // Confirmed - PCLayout = 0x9800; // Confirmed - Wondercard = 0x22000; // Confirmed - BerryField = 0x20C00; // ****changed**** - OPower = 0x1BE00; - EventFlag = 0x19E00; // Confirmed - PokeDex = 0x1A400; - HoF = 0x1F200; // Confirmed - JPEG = 0x6D000; // Confirmed - PSS = 0x0A400; // Confirmed (thanks Rei) + ORAS = true; + Box = 0x33000; // Confirmed + TrainerCard = 0x14000; // Confirmed + Party = 0x14200; // Confirmed + BattleBox = 0x04A00;// Confirmed + Daycare = 0x1BC00; // Confirmed (thanks Rei) + GTS = 0x18200; // Confirmed + Fused = 0x16A00; // Confirmed + SUBE = 0x1D890; // ****not in use, not updating?**** + Puff = 0x00000; // Confirmed + Item = 0x00400; // Confirmed + Items = new Inventory(Name, Item); + Trainer1 = 0x01400; // Confirmed + Trainer2 = 0x04200; // Confirmed + PCLayout = 0x04400; // Confirmed + PCBackgrounds = PCLayout + 0x41E; + PCFlags = PCLayout + 0x43D; + WondercardFlags = 0x1CC00; // Confirmed + WondercardData = WondercardFlags + 0x100; + BerryField = 0x1C400; // ****changed**** + OPower = 0x17400; // ****changed**** + EventConst = 0x14A00; + EventAsh = EventConst + 0x78; + EventFlag = 0x14A00; // Confirmed + PokeDex = 0x15000; + Spinda = PokeDex + 0x680; + EncounterCount = PokeDex + 0x686; + PokeDexLanguageFlags = PokeDex + 0x400; + HoF = 0x19E00; // Confirmed + SuperTrain = 0x20200; + JPEG = 0x67C00; // Confirmed + MaisonStats = 0x1BBC0; + PSS = 0x05000; // Confirmed (thanks Rei) + PSSStats = 0x1F400; + Vivillon = 0x4244; + SecretBase = 0x23A00; + EonTicket = 0x319B8; break; default: + Box = TrainerCard = Party = BattleBox = GTS = Daycare = + Fused = SUBE = Puff = Item = Trainer1 = Trainer2 = SecretBase = EonTicket = + PCLayout = PCBackgrounds = PCFlags = WondercardFlags = WondercardData = BerryField = OPower = SuperTrain = MaisonStats = PSSStats = Vivillon = + EventConst = EventAsh = EventFlag = PokeDex = PokeDexLanguageFlags = Spinda = EncounterCount = HoF = PSS = JPEG = 0; Name = "Unknown"; - Box = 0x27A00; - TrainerCard = 0x19400; - Party = 0x19600; - BattleBox = 0x09E00; - Daycare = 0x20600; - GTS = 0x1CC00; - Fused = 0x1B400; - SUBE = 0x22C90; - Puff = 0x5400; - Item = 0x5800; - Trainer1 = 0x6800; - Trainer2 = 0x9600; - PCLayout = 0x9800; - Wondercard = 0x21000; - BerryField = 0x20C00; - OPower = 0x1BE00; - EventFlag = 0x19E00; - PokeDex = 0x1A400; - HoF = 0x1E800; - JPEG = 0x5C600; - PSS = 0x0A400; + ORAS = false; + Items = new Inventory(Name, Item); break; } + DaycareSlot = new[] { Daycare, Daycare + 0x1F0 }; } } } @@ -1056,7 +1109,7 @@ internal static string[] getPKXSummary(PKX data) } // SAV Manipulation - internal static int detectSAVIndex(byte[] data, ref int savindex) + internal static int detectSAVIndex(byte[] data, out int savindex) { SHA256 mySHA256 = SHA256.Create(); { @@ -1106,38 +1159,49 @@ internal static ushort ccitt16(byte[] data) } return crc; } - internal static string verifyG6CHK(byte[] savefile, bool oras, int savegame, ref int[] ctr) + internal static string verifyG6CHK(byte[] savefile) { string rv = ""; int invalid = 0; - // Prepare Region Loops - int[] start = (oras) - ? new [] { 0x05400, 0x05800, 0x06400, 0x06600, 0x06800, 0x06A00, 0x06C00, 0x06E00, 0x07000, 0x07200, 0x07400, 0x09600, 0x09800, 0x09E00, 0x0A400, 0x0F400, 0x14400, 0x19400, 0x19600, 0x19E00, 0x1A400, 0x1B600, 0x1BE00, 0x1C000, 0x1C200, 0x1C800, 0x1CA00, 0x1CE00, 0x1D600, 0x1D800, 0x1DA00, 0x1DC00, 0x1DE00, 0x1E000, 0x1E800, 0x1EE00, 0x1F200, 0x20E00, 0x21000, 0x21400, 0x21800, 0x22000, 0x23C00, 0x24000, 0x24800, 0x24C00, 0x25600, 0x25A00, 0x26200, 0x27000, 0x27200, 0x27400, 0x28200, 0x28A00, 0x28E00, 0x30A00, 0x38400, 0x6D000, } - : new [] { 0x05400, 0x05800, 0x06400, 0x06600, 0x06800, 0x06A00, 0x06C00, 0x06E00, 0x07000, 0x07200, 0x07400, 0x09600, 0x09800, 0x09E00, 0x0A400, 0x0F400, 0x14400, 0x19400, 0x19600, 0x19E00, 0x1A400, 0x1AC00, 0x1B400, 0x1B600, 0x1B800, 0x1BE00, 0x1C000, 0x1C400, 0x1CC00, 0x1CE00, 0x1D000, 0x1D200, 0x1D400, 0x1D600, 0x1DE00, 0x1E400, 0x1E800, 0x20400, 0x20600, 0x20800, 0x20C00, 0x21000, 0x22C00, 0x23000, 0x23800, 0x23C00, 0x24600, 0x24A00, 0x25200, 0x26000, 0x26200, 0x26400, 0x27200, 0x27A00, 0x5C600, }; - int[] length = (oras) - ? new [] { 0x000002C8, 0x00000B90, 0x0000002C, 0x00000038, 0x00000150, 0x00000004, 0x00000008, 0x000001C0, 0x000000BE, 0x00000024, 0x00002100, 0x00000130, 0x00000440, 0x00000574, 0x00004E28, 0x00004E28, 0x00004E28, 0x00000170, 0x0000061C, 0x00000504, 0x000011CC, 0x00000644, 0x00000104, 0x00000004, 0x00000420, 0x00000064, 0x000003F0, 0x0000070C, 0x00000180, 0x00000004, 0x0000000C, 0x00000048, 0x00000054, 0x00000644, 0x000005C8, 0x000002F8, 0x00001B40, 0x000001F4, 0x000003E0, 0x00000216, 0x00000640, 0x00001A90, 0x00000400, 0x00000618, 0x0000025C, 0x00000834, 0x00000318, 0x000007D0, 0x00000C48, 0x00000078, 0x00000200, 0x00000C84, 0x00000628, 0x00000400, 0x00007AD0, 0x000078B0, 0x00034AD0, 0x0000E058, } - : new [] { 0x000002C8, 0x00000B88, 0x0000002C, 0x00000038, 0x00000150, 0x00000004, 0x00000008, 0x000001C0, 0x000000BE, 0x00000024, 0x00002100, 0x00000140, 0x00000440, 0x00000574, 0x00004E28, 0x00004E28, 0x00004E28, 0x00000170, 0x0000061C, 0x00000504, 0x000006A0, 0x00000644, 0x00000104, 0x00000004, 0x00000420, 0x00000064, 0x000003F0, 0x0000070C, 0x00000180, 0x00000004, 0x0000000C, 0x00000048, 0x00000054, 0x00000644, 0x000005C8, 0x000002F8, 0x00001B40, 0x000001F4, 0x000001F0, 0x00000216, 0x00000390, 0x00001A90, 0x00000308, 0x00000618, 0x0000025C, 0x00000834, 0x00000318, 0x000007D0, 0x00000C48, 0x00000078, 0x00000200, 0x00000C84, 0x00000628, 0x00034AD0, 0x0000E058, }; - int csoff = oras ? 0x7B21A : 0x6A81A; - if (savegame == 1) // Offset by 0x7F000 + // Dynamic handling of checksums regardless of save size. + + int verificationOffset = savefile.Length - 0x200 + 0x10; + if (BitConverter.ToUInt32(savefile, verificationOffset) != 0x42454546) + verificationOffset -= 0x200; // No savegames have more than 0x3D blocks, maybe in the future? + + int count = (savefile.Length - verificationOffset - 0x8) / 8; + verificationOffset += 4; + int[] Lengths = new int[count]; + ushort[] BlockIDs = new ushort[count]; + ushort[] Checksums = new ushort[count]; + int[] Start = new int[count]; + int CurrentPosition = 0; + for (int i = 0; i < count; i++) { - start = Array.ConvertAll(start, x => x + 0x7F000); - csoff += 0x7F000; + Start[i] = CurrentPosition; + Lengths[i] = BitConverter.ToInt32(savefile, verificationOffset + 0 + 8 * i); + BlockIDs[i] = BitConverter.ToUInt16(savefile, verificationOffset + 4 + 8 * i); + Checksums[i] = BitConverter.ToUInt16(savefile, verificationOffset + 6 + 8 * i); + + CurrentPosition += (Lengths[i] % 0x200 == 0) ? Lengths[i] : (0x200 - Lengths[i] % 0x200 + Lengths[i]); + + if ((BlockIDs[i] != 0) || i == 0) continue; + count = i; + break; } - // Calculate checksums and spit out result. - for (int i = 0; i < length.Length; i++) + // Apply checksums + for (int i = 0; i < count; i++) { - byte[] array = savefile.Skip(start[i]).Take(length[i]).ToArray(); - ushort checksum = ccitt16(array); - ushort actualsum = BitConverter.ToUInt16(savefile, csoff + i*0x8); - if (checksum == actualsum) continue; + ushort chk = ccitt16(savefile.Skip(Start[i]).Take(Lengths[i]).ToArray()); + ushort old = BitConverter.ToUInt16(savefile, verificationOffset + 6 + i * 8); + + if (chk == old) continue; invalid++; - rv += String.Format("Invalid: {0} @ Region {1}", i.ToString("X2"), start[i].ToString("X5") + Environment.NewLine); + rv += String.Format("Invalid: {0} @ Region {1}", i.ToString("X2"), Start[i].ToString("X5") + Environment.NewLine); } // Return Outputs - rv += String.Format("SAV{2}: {0}/{1}", (start.Length - invalid), start.Length + Environment.NewLine, savegame + 1); - ctr[0] += invalid; - ctr[1] += length.Length - 1; + rv += String.Format("SAV: {0}/{1}", (count - invalid), count + Environment.NewLine); return rv; } internal static string verifyG6SHA(byte[] savefile, bool oras) @@ -1350,28 +1414,40 @@ internal static string verifyG6SHA(byte[] savefile, bool oras) } return rv; } - internal static byte[] writeG6CHK(byte[] savefile, bool oras, int savegame) + internal static void writeG6CHK(byte[] savefile) { - // Prepare Region Loops - int[] start = (oras) - ? new[] { 0x05400, 0x05800, 0x06400, 0x06600, 0x06800, 0x06A00, 0x06C00, 0x06E00, 0x07000, 0x07200, 0x07400, 0x09600, 0x09800, 0x09E00, 0x0A400, 0x0F400, 0x14400, 0x19400, 0x19600, 0x19E00, 0x1A400, 0x1B600, 0x1BE00, 0x1C000, 0x1C200, 0x1C800, 0x1CA00, 0x1CE00, 0x1D600, 0x1D800, 0x1DA00, 0x1DC00, 0x1DE00, 0x1E000, 0x1E800, 0x1EE00, 0x1F200, 0x20E00, 0x21000, 0x21400, 0x21800, 0x22000, 0x23C00, 0x24000, 0x24800, 0x24C00, 0x25600, 0x25A00, 0x26200, 0x27000, 0x27200, 0x27400, 0x28200, 0x28A00, 0x28E00, 0x30A00, 0x38400, 0x6D000, } - : new[] { 0x05400, 0x05800, 0x06400, 0x06600, 0x06800, 0x06A00, 0x06C00, 0x06E00, 0x07000, 0x07200, 0x07400, 0x09600, 0x09800, 0x09E00, 0x0A400, 0x0F400, 0x14400, 0x19400, 0x19600, 0x19E00, 0x1A400, 0x1AC00, 0x1B400, 0x1B600, 0x1B800, 0x1BE00, 0x1C000, 0x1C400, 0x1CC00, 0x1CE00, 0x1D000, 0x1D200, 0x1D400, 0x1D600, 0x1DE00, 0x1E400, 0x1E800, 0x20400, 0x20600, 0x20800, 0x20C00, 0x21000, 0x22C00, 0x23000, 0x23800, 0x23C00, 0x24600, 0x24A00, 0x25200, 0x26000, 0x26200, 0x26400, 0x27200, 0x27A00, 0x5C600, }; - int[] length = (oras) - ? new[] { 0x000002C8, 0x00000B90, 0x0000002C, 0x00000038, 0x00000150, 0x00000004, 0x00000008, 0x000001C0, 0x000000BE, 0x00000024, 0x00002100, 0x00000130, 0x00000440, 0x00000574, 0x00004E28, 0x00004E28, 0x00004E28, 0x00000170, 0x0000061C, 0x00000504, 0x000011CC, 0x00000644, 0x00000104, 0x00000004, 0x00000420, 0x00000064, 0x000003F0, 0x0000070C, 0x00000180, 0x00000004, 0x0000000C, 0x00000048, 0x00000054, 0x00000644, 0x000005C8, 0x000002F8, 0x00001B40, 0x000001F4, 0x000003E0, 0x00000216, 0x00000640, 0x00001A90, 0x00000400, 0x00000618, 0x0000025C, 0x00000834, 0x00000318, 0x000007D0, 0x00000C48, 0x00000078, 0x00000200, 0x00000C84, 0x00000628, 0x00000400, 0x00007AD0, 0x000078B0, 0x00034AD0, 0x0000E058, } - : new[] { 0x000002C8, 0x00000B88, 0x0000002C, 0x00000038, 0x00000150, 0x00000004, 0x00000008, 0x000001C0, 0x000000BE, 0x00000024, 0x00002100, 0x00000140, 0x00000440, 0x00000574, 0x00004E28, 0x00004E28, 0x00004E28, 0x00000170, 0x0000061C, 0x00000504, 0x000006A0, 0x00000644, 0x00000104, 0x00000004, 0x00000420, 0x00000064, 0x000003F0, 0x0000070C, 0x00000180, 0x00000004, 0x0000000C, 0x00000048, 0x00000054, 0x00000644, 0x000005C8, 0x000002F8, 0x00001B40, 0x000001F4, 0x000001F0, 0x00000216, 0x00000390, 0x00001A90, 0x00000308, 0x00000618, 0x0000025C, 0x00000834, 0x00000318, 0x000007D0, 0x00000C48, 0x00000078, 0x00000200, 0x00000C84, 0x00000628, 0x00034AD0, 0x0000E058, }; - int csoff = oras ? 0x7B21A : 0x6A81A; - if (savegame == 1) // Offset by 0x7F000 + // Dynamic handling of checksums regardless of save size. + + int verificationOffset = savefile.Length - 0x200 + 0x10; + if (BitConverter.ToUInt32(savefile, verificationOffset) != 0x42454546) + verificationOffset -= 0x200; // No savegames have more than 0x3D blocks, maybe in the future? + + int count = (savefile.Length - verificationOffset - 0x8) / 8; + verificationOffset += 4; + int[] Lengths = new int[count]; + ushort[] BlockIDs = new ushort[count]; + ushort[] Checksums = new ushort[count]; + int[] Start = new int[count]; + int CurrentPosition = 0; + for (int i = 0; i < count; i++) { - start = Array.ConvertAll(start, x => x + 0x7F000); - csoff += 0x7F000; + Start[i] = CurrentPosition; + Lengths[i] = BitConverter.ToInt32(savefile, verificationOffset + 0 + 8 * i); + BlockIDs[i] = BitConverter.ToUInt16(savefile, verificationOffset + 4 + 8 * i); + Checksums[i] = BitConverter.ToUInt16(savefile, verificationOffset + 6 + 8 * i); + + CurrentPosition += (Lengths[i]%0x200 == 0) ? Lengths[i] : (0x200 - Lengths[i]%0x200 + Lengths[i]); + + if ((BlockIDs[i] != 0) || i == 0) continue; + count = i; + break; } - // Calculate checksums and write back to save file. - for (int i = 0; i < length.Length; i++) + // Apply checksums + for (int i = 0; i < count; i++) { - byte[] array = savefile.Skip(start[i]).Take(length[i]).ToArray(); - Array.Copy(BitConverter.GetBytes(ccitt16(array)), 0, savefile, csoff + i * 8, 2); + byte[] array = savefile.Skip(Start[i]).Take(Lengths[i]).ToArray(); + Array.Copy(BitConverter.GetBytes(ccitt16(array)), 0, savefile, verificationOffset + 6 + i * 8, 2); } - return savefile; } internal static byte[] writeG6SHA(byte[] savefile, bool oras, int savegame) { diff --git a/Misc/QR.cs b/Misc/QR.cs index c5cafcb8c..a99cd9903 100644 --- a/Misc/QR.cs +++ b/Misc/QR.cs @@ -9,7 +9,7 @@ public partial class QR : Form public QR(Image qr, Image pkm, string top, string bottom, string left, string right) { InitializeComponent(); - Font font = (Form1.unicode) ? FontLabel.Font : PKX.getPKXFont((float)8.25); + Font font = (Main.unicode) ? FontLabel.Font : PKX.getPKXFont((float)8.25); Image preview = new Bitmap(45, 45); using (Graphics gfx = Graphics.FromImage(preview)) { diff --git a/Misc/SplashScreen.cs b/Misc/SplashScreen.cs index 70bfcc98b..929b27f65 100644 --- a/Misc/SplashScreen.cs +++ b/Misc/SplashScreen.cs @@ -5,11 +5,9 @@ namespace PKHeX { public partial class SplashScreen : Form { - Form1 m_parent; - public SplashScreen(Form1 frm1) + public SplashScreen() { InitializeComponent(); - m_parent = frm1; System.Timers.Timer myTimer = new System.Timers.Timer(); myTimer.Elapsed += DisplayTimeEvent; myTimer.Interval = 50; // milliseconds per trigger interval @@ -17,9 +15,9 @@ public SplashScreen(Form1 frm1) } public void DisplayTimeEvent(object source, ElapsedEventArgs e) { - if (!m_parent.init) - if (L_Status.InvokeRequired) L_Status.Invoke((MethodInvoker)delegate { L_Status.Text = Form1.Status; }); - else { L_Status.Text = Form1.Status; } + if (!Main.init) + if (L_Status.InvokeRequired) L_Status.Invoke((MethodInvoker)delegate { L_Status.Text = Main.Status; }); + else { L_Status.Text = Main.Status; } else if (InvokeRequired && IsHandleCreated) try { Invoke((MethodInvoker)Close); } catch { Close(); } diff --git a/Misc/pk2pk.cs b/Misc/pk2pk.cs index 5937c1392..27bb9ce37 100644 --- a/Misc/pk2pk.cs +++ b/Misc/pk2pk.cs @@ -6,33 +6,16 @@ namespace PKHeX { public class pk2pk { - public byte[] ConvertPKM(byte[] input, byte[] savefile = null, int savindex = -1) + public void setG6TrainerInfo(byte SUBREGION, byte COUNTRY, byte _3DSREGION, string TRAINERNAME, byte TRAINERGENDER) + { + subreg = SUBREGION; + country = COUNTRY; + _3DSreg = _3DSREGION; + g6trname = TRAINERNAME; + g6trgend = TRAINERGENDER; + } + public byte[] ConvertPKM(byte[] input) { - #region Initialize Everything - - // Load Species Name Tables - speclang_ja = Util.getStringList("Species", "ja"); - speclang_en = Util.getStringList("Species", "en"); - speclang_fr = Util.getStringList("Species", "fr"); - speclang_it = Util.getStringList("Species", "it"); - speclang_de = Util.getStringList("Species", "de"); - speclang_es = Util.getStringList("Species", "es"); - - // Get the 6th Gen Data from the save file if it exists. - int savshift = savindex * 0x7F000; - - // Import trainer details for importing, else use the default values that are already defined. - if ((savefile != null && savindex != -1) && ( - BitConverter.ToUInt32(savefile, 0x6A810 + savshift) == 0x42454546 || - BitConverter.ToUInt32(savefile, 0x7B210 + savshift) == 0x42454546)) // Set for X/Y/OR/AS loaded saves. - { - subreg = savefile[0x19426 + savshift]; - country = savefile[0x19427 + savshift]; - _3DSreg = savefile[0x1942C + savshift]; - g6trname = Util.TrimFromZero(Encoding.Unicode.GetString(savefile, 0x19448 + savshift, 0x1A)); - g6trgend = savefile[0x19405 + savshift]; - } - #endregion #region Convert if (input.Length == 100 || input.Length == 80) // We have a Gen 3 PKM. { @@ -56,12 +39,12 @@ public byte[] ConvertPKM(byte[] input, byte[] savefile = null, int savindex = -1 } #region Utility public DateTime moment = DateTime.Now; - public string[] speclang_ja; - public string[] speclang_en; - public string[] speclang_fr; - public string[] speclang_it; - public string[] speclang_de; - public string[] speclang_es; + public string[] speclang_ja = Util.getStringList("Species", "ja"); + public string[] speclang_en = Util.getStringList("Species", "en"); + public string[] speclang_fr = Util.getStringList("Species", "fr"); + public string[] speclang_it = Util.getStringList("Species", "it"); + public string[] speclang_de = Util.getStringList("Species", "de"); + public string[] speclang_es = Util.getStringList("Species", "es"); public int country = 0x31; // US public int subreg = 0x7; // California public int _3DSreg = 0x1; // Americas diff --git a/PKX/f1-Main.Designer.cs b/PKX/f1-Main.Designer.cs index e9d36869c..e6d75aab7 100644 --- a/PKX/f1-Main.Designer.cs +++ b/PKX/f1-Main.Designer.cs @@ -1,6 +1,6 @@ namespace PKHeX { - partial class Form1 + partial class Main { /// /// Required designer variable. @@ -29,7 +29,7 @@ protected override void Dispose(bool disposing) public void InitializeComponent() { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Main)); this.tabMain = new System.Windows.Forms.TabControl(); this.Tab_Main = new System.Windows.Forms.TabPage(); this.CB_Language = new System.Windows.Forms.ComboBox(); @@ -313,7 +313,6 @@ public void InitializeComponent() this.B_SwitchSAV = new System.Windows.Forms.Button(); this.B_VerifyCHK = new System.Windows.Forms.Button(); this.L_IntegrityCheck = new System.Windows.Forms.Label(); - this.B_VerifySHA = new System.Windows.Forms.Button(); this.B_ExportSAV = new System.Windows.Forms.Button(); this.RTB_S = new System.Windows.Forms.RichTextBox(); this.B_OpenHallofFame = new System.Windows.Forms.Button(); @@ -538,7 +537,7 @@ public void InitializeComponent() this.TB_PID.TabIndex = 1; this.TB_PID.Text = "12345678"; this.TB_PID.TextChanged += new System.EventHandler(this.update_ID); - this.TB_PID.MouseHover += new System.EventHandler(this.getTSV); + this.TB_PID.MouseHover += new System.EventHandler(this.updateTSV); // // CHK_Nicknamed // @@ -750,7 +749,7 @@ public void InitializeComponent() this.CB_Nature.TabIndex = 9; this.CB_Nature.SelectedIndexChanged += new System.EventHandler(this.validateComboBox2); this.CB_Nature.KeyDown += new System.Windows.Forms.KeyEventHandler(this.removedropCB); - this.CB_Nature.MouseHover += new System.EventHandler(this.getNatureModification); + this.CB_Nature.MouseHover += new System.EventHandler(this.updateNatureModification); this.CB_Nature.Validating += new System.ComponentModel.CancelEventHandler(this.validateComboBox); // // Label_3DSRegion @@ -2495,7 +2494,7 @@ public void InitializeComponent() this.TB_SID.TabIndex = 2; this.TB_SID.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; this.TB_SID.TextChanged += new System.EventHandler(this.update_ID); - this.TB_SID.MouseHover += new System.EventHandler(this.getTSV); + this.TB_SID.MouseHover += new System.EventHandler(this.updateTSV); // // TB_TID // @@ -2507,7 +2506,7 @@ public void InitializeComponent() this.TB_TID.TabIndex = 1; this.TB_TID.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; this.TB_TID.TextChanged += new System.EventHandler(this.update_ID); - this.TB_TID.MouseHover += new System.EventHandler(this.getTSV); + this.TB_TID.MouseHover += new System.EventHandler(this.updateTSV); // // Label_OT // @@ -3779,7 +3778,6 @@ public void InitializeComponent() this.Tab_SAV.Controls.Add(this.B_SwitchSAV); this.Tab_SAV.Controls.Add(this.B_VerifyCHK); this.Tab_SAV.Controls.Add(this.L_IntegrityCheck); - this.Tab_SAV.Controls.Add(this.B_VerifySHA); this.Tab_SAV.Controls.Add(this.B_ExportSAV); this.Tab_SAV.Controls.Add(this.RTB_S); this.Tab_SAV.Location = new System.Drawing.Point(4, 22); @@ -3829,17 +3827,6 @@ public void InitializeComponent() this.L_IntegrityCheck.TabIndex = 5; this.L_IntegrityCheck.Text = "Integrity Check:"; // - // B_VerifySHA - // - this.B_VerifySHA.Enabled = false; - this.B_VerifySHA.Location = new System.Drawing.Point(32, 42); - this.B_VerifySHA.Name = "B_VerifySHA"; - this.B_VerifySHA.Size = new System.Drawing.Size(75, 23); - this.B_VerifySHA.TabIndex = 1; - this.B_VerifySHA.Text = "Hashes"; - this.B_VerifySHA.UseVisualStyleBackColor = true; - this.B_VerifySHA.Click += new System.EventHandler(this.clickVerifySHA); - // // B_ExportSAV // this.B_ExportSAV.Enabled = false; @@ -4039,7 +4026,7 @@ public void InitializeComponent() this.L_QR.Visible = false; this.L_QR.Click += new System.EventHandler(this.clickQR); // - // Form1 + // Main // this.AllowDrop = true; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -4056,7 +4043,7 @@ public void InitializeComponent() this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; - this.Name = "Form1"; + this.Name = "Main"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "PKHeX"; this.tabMain.ResumeLayout(false); @@ -4400,7 +4387,6 @@ public void InitializeComponent() private System.Windows.Forms.TabPage Tab_SAV; private System.Windows.Forms.Button B_ExportSAV; private System.Windows.Forms.Button B_VerifyCHK; - private System.Windows.Forms.Button B_VerifySHA; private System.Windows.Forms.RichTextBox RTB_S; private System.Windows.Forms.Button B_BoxRight; private System.Windows.Forms.Button B_BoxLeft; diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index 3e1a20b22..ea1870e84 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -11,16 +11,28 @@ namespace PKHeX { - public partial class Form1 : Form + public partial class Main : Form { - public Form1() + public Main() { #region Pop open a splash screen while we load up. - Thread SplashSCR = new Thread(() => new SplashScreen(this).ShowDialog()); + Thread SplashSCR = new Thread(() => new SplashScreen().ShowDialog()); SplashSCR.Start(); #endregion #region Initialize Form InitializeComponent(); + SlotPictureBoxes = new[] { + bpkx1, bpkx2, bpkx3, bpkx4, bpkx5, bpkx6, + bpkx7, bpkx8, bpkx9, bpkx10,bpkx11,bpkx12, + bpkx13,bpkx14,bpkx15,bpkx16,bpkx17,bpkx18, + bpkx19,bpkx20,bpkx21,bpkx22,bpkx23,bpkx24, + bpkx25,bpkx26,bpkx27,bpkx28,bpkx29,bpkx30, + + ppkx1, ppkx2, ppkx3, ppkx4, ppkx5, ppkx6, + bbpkx1,bbpkx2,bbpkx3,bbpkx4,bbpkx5,bbpkx6, + + dcpkx1, dcpkx2, gtspkx, fusedpkx,subepkx1,subepkx2,subepkx3, + }; defaultControlWhite = CB_Species.BackColor; defaultControlText = Label_Species.ForeColor; CB_ExtraBytes.SelectedIndex = 0; @@ -175,18 +187,19 @@ public Form1() } #region Global Variables: Always Visible! - public byte[] buff = new byte[260]; // Tab Pokemon Data Storage - public byte[] savefile = new byte[0x100000]; - public byte[] cyberSAV = new byte[0x65600]; + public static byte[] buff = new byte[260]; // Tab Pokemon Data Storage + public static byte[] savefile = new byte[0x760000]; // required to initialize the program + public static PKX.Structures.SaveGame SaveGame = new PKX.Structures.SaveGame("ORAS"); + public static byte[] originalSAV; // original save + public static byte[] powersave; // raw Powersave file public static byte[] ramsav; public static bool ramsavloaded; - public bool savegame_oras = true; - public bool cybergadget; public bool savLoaded; public int savindex; - public bool savedited; + public static bool savedited; public string pathSDF; public string path3DS; + public pk2pk Converter = new pk2pk(); public static string Status = "Starting up PKHeX..."; public static bool HaX; @@ -246,13 +259,14 @@ public Form1() public static string[] itempouch = { }; public static string origintrack; public static string curlanguage = "en"; - public volatile bool init; + public static volatile bool init; public static bool unicode; public ToolTip Tip1 = new ToolTip(); public ToolTip Tip2 = new ToolTip(); public ToolTip Tip3 = new ToolTip(); public ToolTip NatureTip = new ToolTip(); - public PKX.Structures.SaveGame SaveGame = new PKX.Structures.SaveGame("ORAS"); + public static List MoveDataSource, ItemDataSource, SpeciesDataSource, BallDataSource, NatureDataSource; + private PictureBox[] SlotPictureBoxes; #endregion #region //// MAIN MENU FUNCTIONS //// @@ -360,7 +374,7 @@ private void mainMenuCodeGen(object sender, EventArgs e) // Open Code Generator byte[] formdata = null; if (verifiedPKX()) formdata = preparepkx(); - CodeGenerator CodeGen = new CodeGenerator(this, formdata); + CodeGenerator CodeGen = new CodeGenerator(formdata); CodeGen.ShowDialog(); byte[] data = CodeGen.returnArray; if (data == null) return; @@ -377,9 +391,8 @@ private void mainMenuCodeGen(object sender, EventArgs e) private void mainMenuBoxReport(object sender, EventArgs e) { frmReport ReportForm = new frmReport(); - int offset = 0x27A00; if (savegame_oras) offset = 0x33000 + 0x5400; ReportForm.Show(); - ReportForm.PopulateData(savefile, savindex, offset); + ReportForm.PopulateData(savefile, SaveGame.Box); } private void mainMenuUnicode(object sender, EventArgs e) { @@ -475,7 +488,7 @@ private void openFile(byte[] input, string path, string ext) B_SwitchSAV.Enabled = true; open1MB(input, path, GameType, false); } - else if (PKX.detectSAVIndex(input, ref savindex) == 2) + else if (PKX.detectSAVIndex(input, out savindex) == 2) { DialogResult dialogResult = Util.Prompt(MessageBoxButtons.YesNo, "Hash verification failed.", "Press Yes to ignore this warning and continue loading the save file."); if (dialogResult != DialogResult.Yes) return; @@ -494,7 +507,7 @@ private void openFile(byte[] input, string path, string ext) { B_ExportSAV.Enabled = true; B_SwitchSAV.Enabled = true; - PKX.detectSAVIndex(input, ref savindex); + PKX.detectSAVIndex(input, out savindex); open1MB(input, path, GameType, false); } } @@ -516,11 +529,10 @@ private void openFile(byte[] input, string path, string ext) #region PK3/PK4/PK5 else if ((input.Length == 136) || (input.Length == 220) || (input.Length == 236) || (input.Length == 100) || (input.Length == 80)) // to convert g5pkm { - var Converter = new pk2pk(); if (!PKX.verifychk(input)) Util.Error("Invalid File (Checksum Error)"); try // to convert g5pkm { - byte[] data = Converter.ConvertPKM(input, savefile, savindex); + byte[] data = Converter.ConvertPKM(input); Array.Copy(data, buff, 232); populateFields(buff); } @@ -613,7 +625,7 @@ private void openFile(byte[] input, string path, string ext) #endregion #region Wondercard else if (input.Length == 0x108 && ext == ".wc6") - new SAV_Wondercard(this, input).Show(); + new SAV_Wondercard(input).Show(); #endregion else Util.Error("Attempted to load an unsupported file type/size.", "File Loaded:" + Environment.NewLine + path, "File Size:" + Environment.NewLine + new FileInfo(path).Length.ToString("X8")); @@ -626,12 +638,11 @@ private void openMAIN(byte[] input, string path, string GameType, bool oras, boo // Load CyberGadget savindex = 0; - savefile = new byte[0x100000]; - cyberSAV = input; - cybergadget = true; + savefile = input; + powersave = null; B_ExportSAV.Enabled = true; B_SwitchSAV.Enabled = false; - Array.Copy(input, 0, savefile, 0x5400, input.Length); + savefile = input; openSave(oras); } @@ -640,31 +651,20 @@ private void open1MB(byte[] input, string path, string GameType, bool oras) ramsavloaded = false; L_Save.Text = "SAV: " + Path.GetFileName(path); SaveGame = new PKX.Structures.SaveGame(GameType); - savegame_oras = oras; - savefile = input; - cybergadget = false; + powersave = input; + savefile = input.Skip(0x5400).Take(oras ? 0x76000 : 0x65600).ToArray(); // Logic to allow unlocking of Switch SAV - // Setup SHA - SHA256 mySHA256 = SHA256.Create(); - // Check both IVFC Hashes - byte[] zeroarray = new byte[0x200]; - Array.Copy(savefile, 0x2000 + 0 * 0x7F000, zeroarray, 0, 0x20); - byte[] hashValue1 = mySHA256.ComputeHash(zeroarray); - Array.Copy(savefile, 0x2000 + 1 * 0x7F000, zeroarray, 0, 0x20); - byte[] hashValue2 = mySHA256.ComputeHash(zeroarray); - - byte[] realHash1 = new byte[0x20]; - byte[] realHash2 = new byte[0x20]; - - Array.Copy(savefile, 0x43C - 0 * 0x130, realHash1, 0, 0x20); - Array.Copy(savefile, 0x43C - 1 * 0x130, realHash2, 0, 0x20); - + SHA256 mySHA256 = SHA256.Create(); + byte[] hashValue1 = mySHA256.ComputeHash(powersave.Skip(0x2000 + 0 * 0x7F000).Take(0x20).ToArray()); + byte[] hashValue2 = mySHA256.ComputeHash(powersave.Skip(0x2000 + 1 * 0x7F000).Take(0x20).ToArray()); + byte[] realHash1 = powersave.Skip(0x43C - 0*0x130).Take(0x20).ToArray(); + byte[] realHash2 = powersave.Skip(0x43C - 1*0x130).Take(0x20).ToArray(); B_SwitchSAV.Enabled = (hashValue1.SequenceEqual(realHash1) && hashValue2.SequenceEqual(realHash2)); + getSAVOffsets(ref oras); // to detect if we are ORAS or not - Array.Copy(savefile, 0x5400 + 0x7F000 * savindex, cyberSAV, 0, cyberSAV.Length); openSave(oras); } @@ -722,7 +722,6 @@ private bool openXOR(byte[] input, string path) } private void openSave(bool oras) { - savegame_oras = oras; // Enable Secondary Tools GB_SAVtools.Enabled = B_JPEG.Enabled = true; @@ -730,8 +729,8 @@ private void openSave(bool oras) savedited = false; Menu_ToggleBoxUI.Visible = false; - B_VerifySHA.Enabled = !cybergadget; B_VerifyCHK.Enabled = !ramsavloaded; + DaycareSlot = 0; setBoxNames(); // Display the Box Names setPKXBoxes(); // Reload all of the PKX Windows @@ -741,12 +740,16 @@ private void openSave(bool oras) GB_SUBE.Visible = !oras; B_OpenSecretBase.Visible = oras; - int startBox = savefile[SaveGame.PCLayout + savindex * 0x7FFFF + 0x43F] & 0x1F; + int startBox = savefile[SaveGame.PCLayout + 0x43F] & 0x1F; if (startBox > 30) { tabBoxMulti.SelectedIndex = 1; CB_BoxSelect.SelectedIndex = 0; } else { tabBoxMulti.SelectedIndex = 0; CB_BoxSelect.SelectedIndex = startBox; } Width = largeWidth; savLoaded = true; + + // Refresh instance of pk2pk + refreshTrainerInfo(); + // Indicate audibly the save is loaded System.Media.SystemSounds.Beep.Play(); } @@ -927,11 +930,17 @@ 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 }; - CB_Ball.DataSource = Util.getVariedCBList(Util.getCBList(itemlist, new[] { 4 }, new[] { 3 }, new[] { 2 }, new[] { 1 }), itemlist, ball_nums, ball_vals); - CB_HeldItem.DataSource = Util.getCBList(itemlist, (DEV_Ability.Enabled) ? null : Legal.Items_Held); - CB_Species.DataSource = Util.getCBList(specieslist, null); + BallDataSource = Util.getVariedCBList(Util.getCBList(itemlist, new[] { 4 }, new[] { 3 }, new[] { 2 }, new[] { 1 }), 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); + + CB_Ball.DataSource = new BindingSource(BallDataSource, null); + CB_Species.DataSource = new BindingSource(SpeciesDataSource, null); + CB_HeldItem.DataSource = new BindingSource(ItemDataSource, null); + CB_Nature.DataSource = new BindingSource(NatureDataSource, null); + DEV_Ability.DataSource = Util.getCBList(abilitylist, null); - CB_Nature.DataSource = Util.getCBList(natures, null); CB_EncounterType.DataSource = Util.getCBList(encountertypelist, new[] { 0 }, Legal.Gen4EncounterTypes); CB_GameOrigin.DataSource = Util.getCBList(gamelist, Legal.Games_6oras, Legal.Games_6xy, Legal.Games_5, Legal.Games_4, Legal.Games_4e, Legal.Games_4r, Legal.Games_3, Legal.Games_3e, Legal.Games_3r, Legal.Games_3s); @@ -940,11 +949,11 @@ private void InitializeLanguage() // Set the Move ComboBoxes too.. { - var moves = Util.getCBList(movelist, null); + MoveDataSource = Util.getCBList(movelist, null); foreach (ComboBox cb in new[] { CB_Move1, CB_Move2, CB_Move3, CB_Move4, CB_RelearnMove1, CB_RelearnMove2, CB_RelearnMove3, CB_RelearnMove4 }) { cb.DisplayMember = "Text"; cb.ValueMember = "Value"; - cb.DataSource = new BindingSource(moves, null); + cb.DataSource = new BindingSource(MoveDataSource, null); } } } @@ -971,7 +980,7 @@ private void populateFields(byte[] data) // 0x16, 0x17 - Training Bags handled by the Ribbon Editor uint PID = BitConverter.ToUInt32(buff, 0x18); int nature = buff[0x1C]; - int feflag = buff[0x1D] % 2; + int feflag = buff[0x1D] & 1; int genderflag = (buff[0x1D] >> 1) & 0x3; int altforms = (buff[0x1D] >> 3); int HP_EV = buff[0x1E]; @@ -988,7 +997,7 @@ private void populateFields(byte[] data) int cnt_sheen = buff[0x29]; int markings = buff[0x2A]; int PKRS_Strain = buff[0x2B] >> 4; - int PKRS_Duration = buff[0x2B] % 0x10; + int PKRS_Duration = buff[0x2B] & 0xF; // Medals and Ribbons, passed with buff to new form // 0x2C, 0x2D, 0x2E, 0x2F @@ -1236,7 +1245,7 @@ private void populateFields(byte[] data) Util.Alert("PKX File has an invalid checksum."); } // General Use Functions shared by other Forms // - public void setCountrySubRegion(ComboBox CB, string type) + internal static void setCountrySubRegion(ComboBox CB, string type) { int index = CB.SelectedIndex; // fix for Korean / Chinese being swapped @@ -1248,7 +1257,7 @@ public void setCountrySubRegion(ComboBox CB, string type) if (index > 0 && index < CB.Items.Count && init) CB.SelectedIndex = index; } - public void setForms(int species, ComboBox cb, Label l = null) + internal static void setForms(int species, ComboBox cb, Label l = null) { // Form Tables cb.DisplayMember = "Text"; @@ -1260,7 +1269,7 @@ public void setForms(int species, ComboBox cb, Label l = null) cb.DataSource = PKX.getFormList(species, types, forms, gendersymbols).ToList(); } - public void setAbilityList(MaskedTextBox tb_abil, int species, ComboBox cb_abil, ComboBox cb_forme) + internal static void setAbilityList(MaskedTextBox tb_abil, int species, ComboBox cb_abil, ComboBox cb_forme) { if (!init && tb_abil.Text == "") return; @@ -1386,23 +1395,22 @@ private void clickMarking(object sender, EventArgs e) } private void clickOT(object sender, EventArgs e) { - string OT = Util.TrimFromZero(Encoding.Unicode.GetString(savefile, SaveGame.TrainerCard + 0x48 + savindex * 0x7F000, 0x1A)); + string OT = Util.TrimFromZero(Encoding.Unicode.GetString(savefile, SaveGame.TrainerCard + 0x48, 0x1A)); if (OT.Length <= 0) return; TB_OT.Text = OT; - int savshift = 0x7F000 * savindex; // Set Gender Label - int g6trgend = savefile[SaveGame.TrainerCard + 0x5 + savshift]; + int g6trgend = savefile[SaveGame.TrainerCard + 0x5]; Label_OTGender.Text = g6trgend == 1 ? gendersymbols[1] : gendersymbols[0]; // Get TID/SID - TB_TID.Text = BitConverter.ToUInt16(savefile, SaveGame.TrainerCard + 0 + savshift).ToString(); - TB_SID.Text = BitConverter.ToUInt16(savefile, SaveGame.TrainerCard + 2 + savshift).ToString(); - int game = savefile[SaveGame.TrainerCard + 0x4 + savshift]; - int subreg = savefile[SaveGame.TrainerCard + 0x26 + savshift]; - int country = savefile[SaveGame.TrainerCard + 0x27 + savshift]; - int _3DSreg = savefile[SaveGame.TrainerCard + 0x2C + savshift]; - int lang = savefile[SaveGame.TrainerCard + 0x2D + savshift]; + TB_TID.Text = BitConverter.ToUInt16(savefile, SaveGame.TrainerCard + 0).ToString(); + TB_SID.Text = BitConverter.ToUInt16(savefile, SaveGame.TrainerCard + 2).ToString(); + int game = savefile[SaveGame.TrainerCard + 0x4]; + int subreg = savefile[SaveGame.TrainerCard + 0x26]; + int country = savefile[SaveGame.TrainerCard + 0x27]; + int _3DSreg = savefile[SaveGame.TrainerCard + 0x2C]; + int lang = savefile[SaveGame.TrainerCard + 0x2D]; // CB_GameOrigin.SelectedValue = game; @@ -1416,7 +1424,7 @@ private void clickOT(object sender, EventArgs e) private void clickCT(object sender, EventArgs e) { if (TB_OTt2.Text.Length > 0) - Label_CTGender.Text = gendersymbols[savefile[0x19405 + savindex * 0x7F000]]; + Label_CTGender.Text = gendersymbols[savefile[SaveGame.TrainerCard + 0x5]]; } private void clickGT(object sender, EventArgs e) { @@ -1913,6 +1921,24 @@ private void updateExtraByteIndex(object sender, EventArgs e) // Byte changed, need to refresh the Text box for the byte's value. TB_ExtraByte.Text = buff[Convert.ToInt32(CB_ExtraBytes.Text, 16)].ToString(); } + private void updateNatureModification(object sender, EventArgs e) + { + if (sender is ComboBox && (sender as ComboBox).Name != CB_Nature.Name) return; + int nature = Util.getIndex(CB_Nature); + int incr = nature / 5; + int decr = nature % 5; + + Label[] labarray = { Label_ATK, Label_DEF, Label_SPE, Label_SPA, Label_SPD }; + // Reset Label Colors + foreach (Label label in labarray) + label.ForeColor = defaultControlText; + + // Set Colored StatLabels only if Nature isn't Neutral + NatureTip.SetToolTip(CB_Nature, + incr != decr + ? String.Format("+{0} / -{1}", labarray[incr].Text, labarray[decr].Text).Replace(":", "") + : "-/-"); + } private void updateNickname(object sender, EventArgs e) { if (init && ModifierKeys == Keys.Control) { getShowdownSet(); return; } @@ -2028,6 +2054,15 @@ private void updateShinyPID(object sender, EventArgs e) setIsShiny(); getQuickFiller(dragout); } + private void updateTSV(object sender, EventArgs e) + { + uint tsv = PKX.getTSV(Util.ToUInt32(TB_TID.Text), Util.ToUInt32(TB_SID.Text)); + Tip1.SetToolTip(TB_TID, "TSV: " + tsv.ToString("0000")); + Tip2.SetToolTip(TB_SID, "TSV: " + tsv.ToString("0000")); + + uint psv = PKX.getPSV(Util.getHEXval(TB_PID)); + Tip3.SetToolTip(TB_PID, "PSV: " + psv.ToString("0000")); + } private void update_ID(object sender, EventArgs e) { // Trim out nonhex characters @@ -2063,7 +2098,7 @@ private void validateComboBox2(object sender, EventArgs e) TB_AbilityNumber.Text = (1 << CB_Ability.SelectedIndex).ToString(); else if ((cb == CB_Move1) || (cb == CB_Move2) || (cb == CB_Move3) || (cb == CB_Move4)) updatePP(sender, e); - getNatureModification(sender, null); + updateNatureModification(sender, null); updateIVs(null, null); // updating Nature will trigger stats to update as well } private void removedropCB(object sender, KeyEventArgs e) @@ -2195,7 +2230,7 @@ private void getShowdownSet() // Secondary Windows for Ribbons/Amie/Memories private void openRibbons(object sender, EventArgs e) { - new RibbMedal(this).ShowDialog(); + new RibbMedal().ShowDialog(); } private void openHistory(object sender, EventArgs e) { @@ -2570,161 +2605,109 @@ private void clickVerifyCHK(object sender, EventArgs e) { if (savedited) { Util.Alert("Save has been edited. Cannot integrity check."); return; } - int[] ctr = {0, 0}; - RTB_S.Text += PKX.verifyG6CHK(savefile, savegame_oras, 0, ref ctr); - if (cybergadget) return; - RTB_S.Text += PKX.verifyG6CHK(savefile, savegame_oras, 1, ref ctr); - - if (ctr[0] == ctr[1]) RTB_S.Text = "No checksums are valid."; - } - private void clickVerifySHA(object sender, EventArgs e) - { - if (savedited) { Util.Alert("Save has been edited. Cannot integrity check."); return; } - - RTB_S.Text += PKX.verifyG6SHA(savefile, savegame_oras); + RTB_S.Text += PKX.verifyG6CHK(savefile); } private void clickExportSAV(object sender, EventArgs e) { // Set the current box to the save - savefile[SaveGame.PCLayout + savindex * 0x7FFFF + 0x43F] = (byte) + savefile[SaveGame.PCLayout + 0x43F] = (byte) (tabBoxMulti.SelectedIndex == 1 ? 0xFF // If Battle/Party selected : CB_BoxSelect.SelectedIndex); // Box // Create another version of the save file. - byte[] editedsav = new byte[0x100000]; - Array.Copy(savefile, editedsav, savefile.Length); + + byte[] sav = (byte[])savefile.Clone(); // Since we only edited one of the save files, we only have to fix half of the chk/hashes! // Fix Checksums - editedsav = PKX.writeG6CHK(editedsav, savegame_oras, savindex); - if (!cybergadget) // Fix Hashes - editedsav = PKX.writeG6SHA(editedsav, savegame_oras, savindex); - // Write the active save index - editedsav[0x168] = (byte)(savindex ^ 1); - // File Integrity has been restored as well as it can. Export! + PKX.writeG6CHK(sav); - if (cybergadget) - #region Saving CyberGadget/RAMSAV + // Chunk Error Checking + byte[] FFFF = Enumerable.Repeat((byte)0xFF, 0x200).ToArray(); + for (int i = 0; i < sav.Length / 0x200; i++) { - byte[] cybersav = new byte[savegame_oras ? 0x76000 : 0x65600]; - Array.Copy(editedsav, 0x5400, cybersav, 0, cybersav.Length); - if (ramsav == null) - { - // Chunk Error Checking - byte[] FFFF = new byte[0x200]; - byte[] section = new byte[0x200]; - for (int i = 0; i < 0x200; i++) - FFFF[i] = 0xFF; + if (!FFFF.SequenceEqual(sav.Skip(i*0x200).Take(0x200))) continue; + string problem = String.Format("0x200 chunk @ 0x{0} is FF'd.", (i * 0x200).ToString("X5")) + + Environment.NewLine + "Cyber will screw up (as of August 31st)." + Environment.NewLine + Environment.NewLine; - for (int i = 0; i < cybersav.Length / 0x200; i++) - { - Array.Copy(cybersav, i * 0x200, section, 0, 0x200); - if (!section.SequenceEqual(FFFF)) continue; - string problem = String.Format("0x200 chunk @ 0x{0} is FF'd.", (i * 0x200).ToString("X5")) - + Environment.NewLine + "Cyber will screw up (as of August 31st)." + Environment.NewLine + Environment.NewLine; + // Check to see if it is in the Pokedex + if (i * 0x200 > SaveGame.PokeDex && i * 0x200 < SaveGame.PokeDex + 0x900) + { + problem += "Problem lies in the Pokedex. "; + if (i * 0x200 == SaveGame.PokeDex + 0x400) + problem += "Remove a language flag for a species ~ ex " + specieslist[548]; + } - // Check to see if it is in the Pokedex - if (i * 0x200 > 0x14E00 && i * 0x200 < 0x15700) - { - problem += "Problem lies in the Pokedex. "; - if (i * 0x200 == 0x15400) - problem += "Remove a language flag for a species ~ ex " + specieslist[548]; - } - - if (Util.Prompt(MessageBoxButtons.YesNo, problem, "Continue saving?") != DialogResult.Yes) - return; - } - } - SaveFileDialog cySAV = new SaveFileDialog(); - - // Try for file path - string cyberpath = Util.GetTempFolder(); - if (ramsav != null && Directory.Exists(path3DS)) - { - cySAV.InitialDirectory = Path.GetPathRoot(path3DS); - cySAV.RestoreDirectory = true; - } - else if (path3DS != null && File.Exists(Path.Combine(Path.GetPathRoot(path3DS), "SaveDataBackup", "main"))) - { - cySAV.InitialDirectory = Path.Combine(Path.GetPathRoot(path3DS), "SaveDataBackup"); - cySAV.RestoreDirectory = true; - } - else if (pathSDF != null && Directory.Exists(pathSDF)) - { - cySAV.InitialDirectory = pathSDF; - cySAV.RestoreDirectory = true; - } - else if (Directory.Exists(Path.Combine(cyberpath, "root"))) - { - cySAV.InitialDirectory = Path.Combine(cyberpath, "root"); - cySAV.RestoreDirectory = true; - } - else if (Directory.Exists(cyberpath)) - { - cySAV.InitialDirectory = cyberpath; - cySAV.RestoreDirectory = true; - } - if (ramsavloaded && ModifierKeys == Keys.Shift) // Export RAM SAV to another. - { - Util.Alert("Please specify the target cart/console-RAM save."); - OpenFileDialog ofd = new OpenFileDialog(); - if (ofd.ShowDialog() != DialogResult.OK) return; - string target = ofd.FileName; - byte[] targetRAM = File.ReadAllBytes(target); - byte[] newRAM = ram2sav.getRAM(targetRAM, cybersav); - - cySAV.Filter = "ramsav|*.bin"; - cySAV.FileName = "ramsav.bin"; - DialogResult sdr = cySAV.ShowDialog(); - if (sdr != DialogResult.OK) return; - string path = cySAV.FileName; - File.WriteAllBytes(path, newRAM); - Util.Alert("Saved RAM SAV to:" + Environment.NewLine + path, "Target RAM:" + Environment.NewLine + target); - } - else if (ramsavloaded && ModifierKeys != Keys.Control) // Export RAM SAV if it is the currently loaded one. - { - cySAV.Filter = "ramsav|*.bin"; - cySAV.FileName = "ramsav.bin"; - DialogResult sdr = cySAV.ShowDialog(); - if (sdr != DialogResult.OK) return; - string path = cySAV.FileName; - File.WriteAllBytes(path, ram2sav.getRAM(ramsav, cybersav)); - Util.Alert("Saved RAM SAV to:", path); - } - else - { - cySAV.Filter = "Cyber SAV|*.*"; - cySAV.FileName = L_Save.Text.Split(new[] { ": " }, StringSplitOptions.None)[1]; - DialogResult sdr = cySAV.ShowDialog(); - if (sdr != DialogResult.OK) return; - string path = cySAV.FileName; - File.WriteAllBytes(path, cybersav); - Util.Alert("Saved Cyber SAV to:", path); - } + if (Util.Prompt(MessageBoxButtons.YesNo, problem, "Continue saving?") != DialogResult.Yes) + return; + } + + SaveFileDialog cySAV = new SaveFileDialog(); + // Try for file path + string cyberpath = Util.GetTempFolder(); + if (ramsav != null && Directory.Exists(path3DS)) + { + cySAV.InitialDirectory = Path.GetPathRoot(path3DS); + cySAV.RestoreDirectory = true; + } + else if (path3DS != null && File.Exists(Path.Combine(Path.GetPathRoot(path3DS), "SaveDataBackup", "main"))) + { + cySAV.InitialDirectory = Path.Combine(Path.GetPathRoot(path3DS), "SaveDataBackup"); + cySAV.RestoreDirectory = true; + } + else if (pathSDF != null && Directory.Exists(pathSDF)) + { + cySAV.InitialDirectory = pathSDF; + cySAV.RestoreDirectory = true; + } + else if (Directory.Exists(Path.Combine(cyberpath, "root"))) + { + cySAV.InitialDirectory = Path.Combine(cyberpath, "root"); + cySAV.RestoreDirectory = true; + } + else if (Directory.Exists(cyberpath)) + { + cySAV.InitialDirectory = cyberpath; + cySAV.RestoreDirectory = true; + } + + // Export + if (ramsavloaded && ModifierKeys == Keys.Shift) // Export RAM SAV to another. + { + Util.Alert("Please specify the target cart/console-RAM save."); + OpenFileDialog ofd = new OpenFileDialog(); + if (ofd.ShowDialog() != DialogResult.OK) return; + string target = ofd.FileName; + byte[] targetRAM = File.ReadAllBytes(target); + byte[] newRAM = ram2sav.getRAM(targetRAM, sav); + + cySAV.Filter = "ramsav|*.bin"; + cySAV.FileName = "ramsav.bin"; + DialogResult sdr = cySAV.ShowDialog(); + if (sdr != DialogResult.OK) return; + string path = cySAV.FileName; + File.WriteAllBytes(path, newRAM); + Util.Alert("Saved RAM SAV to:" + Environment.NewLine + path, "Target RAM:" + Environment.NewLine + target); + } + else if (ramsavloaded && ModifierKeys != Keys.Control) // Export RAM SAV if it is the currently loaded one. + { + cySAV.Filter = "ramsav|*.bin"; + cySAV.FileName = "ramsav.bin"; + DialogResult sdr = cySAV.ShowDialog(); + if (sdr != DialogResult.OK) return; + string path = cySAV.FileName; + File.WriteAllBytes(path, ram2sav.getRAM(ramsav, sav)); + Util.Alert("Saved RAM SAV to:", path); } - #endregion else - #region Saving Full Save File { - // Save Full Save File - SaveFileDialog savesav = new SaveFileDialog - { - Filter = "SAV|*.bin;*.sav", - FileName = L_Save.Text.Split(new[] {": "}, StringSplitOptions.None)[1] - }; - DialogResult result = savesav.ShowDialog(); - if (result != DialogResult.OK) return; - string path = savesav.FileName; - - if (File.Exists(path)) - { - // File already exists, save a .bak - byte[] backupfile = File.ReadAllBytes(path); - File.WriteAllBytes(path + ".bak", backupfile); - } - File.WriteAllBytes(path, editedsav); - Util.Alert("Saved 1MB SAV to:", path); + cySAV.Filter = "Cyber SAV|*.*"; + cySAV.FileName = L_Save.Text.Split(new[] { ": " }, StringSplitOptions.None)[1]; + DialogResult sdr = cySAV.ShowDialog(); + if (sdr != DialogResult.OK) return; + string path = cySAV.FileName; + File.WriteAllBytes(path, sav); + Util.Alert("Saved Cyber SAV to:", path); } - #endregion } // Box/SAV Functions // private void clickBoxRight(object sender, EventArgs e) @@ -2814,7 +2797,7 @@ private void clickSet(object sender, EventArgs e) byte[] pkxdata = preparepkx(); byte[] ekxdata = PKX.encryptArray(pkxdata); - if (!savegame_oras) + if (!SaveGame.ORAS) { // User Protection bool move1 = BitConverter.ToInt16(pkxdata, 0x5A) > 617; @@ -2843,7 +2826,7 @@ private void clickSet(object sender, EventArgs e) setParty(); setPokedex(pkxdata); - getQuickFiller(getPictureBox(slot), pkxdata); + getQuickFiller(SlotPictureBoxes[slot], pkxdata); savedited = true; getSlotColor(slot, Properties.Resources.slotSet); @@ -2865,7 +2848,7 @@ private void clickDelete(object sender, EventArgs e) { Array.Copy(ekxdata, 0, savefile, offset, 0xE8); } else return; - getQuickFiller(getPictureBox(slot), pkxdata); + getQuickFiller(SlotPictureBoxes[slot], pkxdata); getSlotColor(slot, Properties.Resources.slotDel); } private void clickClone(object sender, EventArgs e) @@ -2892,7 +2875,7 @@ private void clickClone(object sender, EventArgs e) Array.Copy(ekxdata, 0, savefile, getPKXOffset(i), 0xE8); for (int i = 0; i < 30; i++) - getQuickFiller(getPictureBox(i), pkxdata); + getQuickFiller(SlotPictureBoxes[i], pkxdata); savedited = true; } @@ -2904,7 +2887,7 @@ private void updateEggRNGSeed(object sender, EventArgs e) { Util.Alert("Expected HEX (0-9, A-F).", "Received: " + Environment.NewLine + TB_RNGSeed.Text); // Reset to Stored Value - TB_RNGSeed.Text = BitConverter.ToUInt64(savefile, SaveGame.Daycare + (0x7F000 * savindex) + 0x1E8).ToString("X16"); + TB_RNGSeed.Text = BitConverter.ToUInt64(savefile, SaveGame.DaycareSlot[DaycareSlot] + 0x1E8).ToString("X16"); return; // recursively triggers this method, no need to continue } @@ -2916,7 +2899,17 @@ private void updateEggRNGSeed(object sender, EventArgs e) } // Write final value back to the save - Array.Copy(BitConverter.GetBytes(Convert.ToUInt64(TB_RNGSeed.Text, 16)), 0, savefile, SaveGame.Daycare + 0x7F000 * savindex + 0x1E8, 0x8); + Array.Copy(BitConverter.GetBytes(Convert.ToUInt64(TB_RNGSeed.Text, 16)), 0, savefile, SaveGame.DaycareSlot[DaycareSlot] + 0x1E8, 0x8); + } + private void refreshTrainerInfo() + { + // Set Gender Label + byte subreg = savefile[SaveGame.TrainerCard + 0x26]; + byte country = savefile[SaveGame.TrainerCard + 0x27]; + byte _3DSreg = savefile[SaveGame.TrainerCard + 0x2C]; + string OT = Util.TrimFromZero(Encoding.Unicode.GetString(savefile, SaveGame.TrainerCard + 0x48, 0x1A)); + byte g6trgend = savefile[SaveGame.TrainerCard + 0x5]; + Converter.setG6TrainerInfo(subreg, country, _3DSreg, OT, g6trgend); } // Generic Subfunctions // private void setPokedex(byte[] pkxdata) @@ -2930,72 +2923,68 @@ private void setPokedex(byte[] pkxdata) ushort TID = BitConverter.ToUInt16(pkxdata, 0xC); ushort SID = BitConverter.ToUInt16(pkxdata, 0xE); int shiny = (PKX.getPSV(pid) ^ PKX.getTSV(TID, SID)) >> 4 == 0 ? 1 : 0; - int dexoff = savindex * 0x7F000 + SaveGame.PokeDex; // Same offset for XY-ORAS - int langoff = 0x3C8; if (savegame_oras) langoff = 0x400; // Not the same offset for language bools int shiftoff = (shiny * 0x60 * 2) + (gender * 0x60) + 0x60; // Set the [Species/Gender/Shiny] Owned Flag - savefile[dexoff + shiftoff + (species - 1) / 8 + 0x8] |= (byte)(1 << ((species - 1) % 8)); + savefile[SaveGame.PokeDex + shiftoff + (species - 1) / 8 + 0x8] |= (byte)(1 << ((species - 1) % 8)); // Owned quality flag - if (origin < 0x18 && species < 650 && !savegame_oras) // Pre 650 for X/Y, and not for ORAS; Set the Foreign Owned Flag - savefile[0x1AA4C + 0x7F000 * savindex + (species - 1) / 8] |= (byte)(1 << ((species - 1) % 8)); - else if (origin >= 0x18 || savegame_oras) // Set Native Owned Flag (should always happen) - savefile[dexoff + (species - 1) / 8 + 0x8] |= (byte)(1 << ((species - 1) % 8)); + if (origin < 0x18 && species < 650 && !SaveGame.ORAS) // Pre 650 for X/Y, and not for ORAS; Set the Foreign Owned Flag + savefile[SaveGame.PokeDex + 0x64C + (species - 1) / 8] |= (byte)(1 << ((species - 1) % 8)); + else if (origin >= 0x18 || SaveGame.ORAS) // Set Native Owned Flag (should always happen) + savefile[SaveGame.PokeDex + (species - 1) / 8 + 0x8] |= (byte)(1 << ((species - 1) % 8)); // Set the Language if (lang < 0) lang = 1; - savefile[dexoff + langoff + ((species - 1) * 7 + lang) / 8] |= (byte)(1 << ((((species - 1) * 7) + lang) % 8)); + savefile[SaveGame.PokeDex + SaveGame.PokeDexLanguageFlags + ((species - 1) * 7 + lang) / 8] |= (byte)(1 << ((((species - 1) * 7) + lang) % 8)); } private byte setParty() { byte partymembers = 0; // start off with a ctr of 0 - int offset = SaveGame.Party + 0x7F000 * savindex; for (int i = 0; i < 6; i++) { // Gather all the species byte[] data = new byte[0x104]; - Array.Copy(savefile, offset + i * 0x104, data, 0, 0x104); + Array.Copy(savefile, SaveGame.Party + i * 0x104, data, 0, 0x104); byte[] decdata = PKX.decryptArray(data); int species = BitConverter.ToInt16(decdata, 8); if ((species != 0) && (species < 722)) - Array.Copy(data, 0, savefile, offset + (partymembers++) * 0x104, 0x104); + Array.Copy(data, 0, savefile, SaveGame.Party + (partymembers++) * 0x104, 0x104); } // Write in the current party count - savefile[offset + 6 * 0x104 + savindex * 0x7F000] = partymembers; + savefile[SaveGame.Party + 6 * 0x104] = partymembers; // Zero out the party slots that are empty. for (int i = 0; i < 6; i++) if (i >= partymembers) - Array.Copy(PKX.encryptArray(new byte[0x104]), 0, savefile, offset + (i * 0x104), 0x104); + Array.Copy(PKX.encryptArray(new byte[0x104]), 0, savefile, SaveGame.Party + (i * 0x104), 0x104); // Repeat for Battle Box. byte battlemem = 0; - int offset2 = SaveGame.BattleBox + 0x7F000 * savindex; for (int i = 0; i < 6; i++) { // Gather all the species byte[] data = new byte[0x104]; - Array.Copy(savefile, offset2 + i * 0xE8, data, 0, 0xE8); + Array.Copy(savefile, SaveGame.BattleBox + i * 0xE8, data, 0, 0xE8); byte[] decdata = PKX.decryptArray(data); int species = BitConverter.ToInt16(decdata, 8); if ((species != 0) && (species < 722)) - Array.Copy(data, 0, savefile, offset2 + (battlemem++) * 0xE8, 0xE8); + Array.Copy(data, 0, savefile, SaveGame.BattleBox + (battlemem++) * 0xE8, 0xE8); } // Zero out the party slots that are empty. for (int i = 0; i < 6; i++) if (i >= battlemem) - Array.Copy(PKX.encryptArray(new byte[0x104]), 0, savefile, offset2 + (i * 0xE8), 0xE8); + Array.Copy(PKX.encryptArray(new byte[0x104]), 0, savefile, SaveGame.BattleBox + (i * 0xE8), 0xE8); if (battlemem == 0) - savefile[offset2 + 6 * 0xE8 + savindex * 0x7F000] = 0; + savefile[SaveGame.BattleBox + 6 * 0xE8] = 0; // Refresh slots for (int i = 0; i < 6; i++) { - getQuickFiller(getPictureBox(i + 30), PKX.decryptArray(savefile.Skip(SaveGame.Party + 0x7F000 * savindex + 260 * i).Take(232).ToArray())); - getQuickFiller(getPictureBox(i + 36), PKX.decryptArray(savefile.Skip(SaveGame.BattleBox + 0x7F000 * savindex + 232 * i).Take(232).ToArray())); + getQuickFiller(SlotPictureBoxes[i + 30], PKX.decryptArray(savefile.Skip(SaveGame.Party + 260 * i).Take(232).ToArray())); + getQuickFiller(SlotPictureBoxes[i + 36], PKX.decryptArray(savefile.Skip(SaveGame.BattleBox + 232 * i).Take(232).ToArray())); } return partymembers; @@ -3011,7 +3000,7 @@ private int getPKXOffset(int slot) else if (slot < 42) // Battle Box Slot offset = SaveGame.BattleBox + (slot - 36) * 0xE8; else if (slot < 44) // Daycare - offset = SaveGame.Daycare + 8 + (slot - 42) * 0xF0; + offset = SaveGame.DaycareSlot[DaycareSlot] + 8 + (slot - 42) * 0xF0; else if (slot < 45) // GTS offset = SaveGame.GTS; else if (slot < 46) // Fused @@ -3019,63 +3008,35 @@ private int getPKXOffset(int slot) else // SUBE offset = SaveGame.SUBE + (slot - 46) * 0xEC; } - offset += 0x7F000 * savindex; return offset; } private int getSlot(object sender) { - string name = (sender is ToolStripItem) - ? - ((sender as ToolStripItem).Owner as ContextMenuStrip).SourceControl.Name - : - (sender as PictureBox).Name; + string name = (sender is ToolStripItem) + ? ((sender as ToolStripItem).Owner as ContextMenuStrip).SourceControl.Name + : (sender as PictureBox).Name; - string[] pba = { - "bpkx1", "bpkx2", "bpkx3", "bpkx4", "bpkx5", "bpkx6", - "bpkx7", "bpkx8", "bpkx9", "bpkx10","bpkx11","bpkx12", - "bpkx13","bpkx14","bpkx15","bpkx16","bpkx17","bpkx18", - "bpkx19","bpkx20","bpkx21","bpkx22","bpkx23","bpkx24", - "bpkx25","bpkx26","bpkx27","bpkx28","bpkx29","bpkx30", - - "ppkx1", "ppkx2", "ppkx3", "ppkx4", "ppkx5", "ppkx6", - "bbpkx1","bbpkx2","bbpkx3","bbpkx4","bbpkx5","bbpkx6", - - "dcpkx1", "dcpkx2", "gtspkx", "fusedpkx","subepkx1","subepkx2","subepkx3", - }; - int slot = Array.IndexOf(pba, name); - return slot; + return Array.FindIndex(SlotPictureBoxes, p => p.Name == name); } private void setPKXBoxes() { - int boxoffset = SaveGame.Box + 0x7F000 * savindex + CB_BoxSelect.SelectedIndex * (0xE8 * 30); + int boxoffset = SaveGame.Box + CB_BoxSelect.SelectedIndex * (0xE8 * 30); - int boxbgofst = (0x7F000 * savindex) + 0x9C1E + CB_BoxSelect.SelectedIndex; + int boxbgofst = 0x481E + CB_BoxSelect.SelectedIndex; int boxbgval = 1 + savefile[boxbgofst]; - string imagename = "box_wp" + boxbgval.ToString("00"); if (savegame_oras && boxbgval > 16) imagename += "o"; + string imagename = "box_wp" + boxbgval.ToString("00"); if (SaveGame.ORAS && boxbgval > 16) imagename += "o"; PAN_Box.BackgroundImage = (Image)Properties.Resources.ResourceManager.GetObject(imagename); - PictureBox[] pba = { - bpkx1, bpkx2, bpkx3, bpkx4, bpkx5, bpkx6, - bpkx7, bpkx8, bpkx9, bpkx10,bpkx11,bpkx12, - bpkx13,bpkx14,bpkx15,bpkx16,bpkx17,bpkx18, - bpkx19,bpkx20,bpkx21,bpkx22,bpkx23,bpkx24, - bpkx25,bpkx26,bpkx27,bpkx28,bpkx29,bpkx30, - - ppkx1, ppkx2, ppkx3, ppkx4, ppkx5, ppkx6, - bbpkx1,bbpkx2,bbpkx3,bbpkx4,bbpkx5,bbpkx6, - - dcpkx1, dcpkx2, gtspkx, fusedpkx,subepkx1,subepkx2,subepkx3, - }; for (int i = 0; i < 30; i++) - getSlotFiller(boxoffset + 0xE8 * i, pba[i]); + getSlotFiller(boxoffset + 0xE8 * i, SlotPictureBoxes[i]); // Reload Party for (int i = 0; i < 6; i++) - getSlotFiller(SaveGame.Party + (0x7F000 * savindex) + 0x104 * i, pba[i + 30]); + getSlotFiller(SaveGame.Party + 0x104 * i, SlotPictureBoxes[i + 30]); // Reload Battle Box for (int i = 0; i < 6; i++) - getSlotFiller(SaveGame.BattleBox + (0x7F000 * savindex) + 0xE8 * i, pba[i + 36]); + getSlotFiller(SaveGame.BattleBox + 0xE8 * i, SlotPictureBoxes[i + 36]); // Reload Daycare Label[] dclabela = { L_DC1, L_DC2, }; @@ -3083,37 +3044,37 @@ private void setPKXBoxes() for (int i = 0; i < 2; i++) { - 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 + getSlotFiller(SaveGame.Daycare + 0xE8 * i + 8 * (i + 1), SlotPictureBoxes[i + 42]); + dctexta[i].Text = BitConverter.ToUInt32(savefile, SaveGame.Daycare + 0xF0 * i + 4).ToString(); + if (Convert.ToBoolean(savefile[SaveGame.Daycare + 0xF0 * i])) // If Occupied dclabela[i].Text = (i + 1) + ": ✓"; else { dclabela[i].Text = (i + 1) + ": ✘"; - pba[i + 42].Image = Util.ChangeOpacity(pba[i + 42].Image, 0.6); + SlotPictureBoxes[i + 42].Image = Util.ChangeOpacity(SlotPictureBoxes[i + 42].Image, 0.6); } } - DayCare_HasEgg.Checked = Convert.ToBoolean(savefile[SaveGame.Daycare + (0x7F000 * savindex) + 0x1E0]); - TB_RNGSeed.Text = BitConverter.ToUInt64(savefile, SaveGame.Daycare + (0x7F000 * savindex) + 0x1E8).ToString("X16"); + DayCare_HasEgg.Checked = Convert.ToBoolean(savefile[SaveGame.Daycare + 0x1E0]); + TB_RNGSeed.Text = BitConverter.ToUInt64(savefile, SaveGame.Daycare + 0x1E8).ToString("X16"); // GTS - getSlotFiller(SaveGame.GTS + (0x7F000 * savindex), pba[44]); + getSlotFiller(SaveGame.GTS, SlotPictureBoxes[44]); // Fused - getSlotFiller(SaveGame.Fused + (0x7F000 * savindex), pba[45]); + getSlotFiller(SaveGame.Fused, SlotPictureBoxes[45]); // SUBE for (int i = 0; i < 3; i++) { - int offset = 0x22C90 + i * 0xEC + (0x7F000 * savindex); + int offset = 0x1D890 + i * 0xEC; if (BitConverter.ToUInt64(savefile, offset) != 0) - getSlotFiller(offset, pba[46 + i]); - else pba[46 + i].Image = null; + getSlotFiller(offset, SlotPictureBoxes[46 + i]); + else SlotPictureBoxes[46 + i].Image = null; } // Recoloring of a storage box slot (to not show for other storage boxes) if (colorizedslot < 32) - pba[colorizedslot].BackgroundImage = (colorizedbox == CB_BoxSelect.SelectedIndex) ? colorizedcolor : null; + SlotPictureBoxes[colorizedslot].BackgroundImage = (colorizedbox == CB_BoxSelect.SelectedIndex) ? colorizedcolor : null; } private void setBoxNames() { @@ -3123,7 +3084,7 @@ private void setBoxNames() { CB_BoxSelect.Items.Clear(); for (int i = 0; i < 31; i++) - CB_BoxSelect.Items.Add(Encoding.Unicode.GetString(savefile, SaveGame.PCLayout + (0x7F000 * savindex) + 0x22 * i, 0x22)); + CB_BoxSelect.Items.Add(Encoding.Unicode.GetString(savefile, SaveGame.PCLayout + 0x22 * i, 0x22)); } catch { @@ -3142,12 +3103,12 @@ private void getSAVOffsets(ref bool oras) { // Get the save file offsets for the input game bool enableInterface = false; - if (BitConverter.ToUInt32(savefile, 0x6A810 + 0x7F000 * savindex) == 0x42454546) + if (savefile.Length == 0x65600 && BitConverter.ToUInt32(savefile, savefile.Length - 0x1F0) == 0x42454546) { enableInterface = true; SaveGame = new PKX.Structures.SaveGame("XY"); } - else if (BitConverter.ToUInt32(savefile, 0x7B210 + 0x7F000 * savindex) == 0x42454546) + else if (savefile.Length == 0x76000 && BitConverter.ToUInt32(savefile, savefile.Length - 0x1F0) == 0x42454546) { enableInterface = true; SaveGame = new PKX.Structures.SaveGame("ORAS"); @@ -3160,25 +3121,9 @@ private void getSAVOffsets(ref bool oras) } // Enable Buttons - GB_SAVtools.Enabled = B_JPEG.Enabled = B_VerifyCHK.Enabled = B_VerifySHA.Enabled = B_SwitchSAV.Enabled + GB_SAVtools.Enabled = B_JPEG.Enabled = B_VerifyCHK.Enabled = B_SwitchSAV.Enabled = enableInterface; } - private PictureBox getPictureBox(int slot) - { - PictureBox[] pba = { - bpkx1, bpkx2, bpkx3, bpkx4, bpkx5, bpkx6, - bpkx7, bpkx8, bpkx9, bpkx10,bpkx11,bpkx12, - bpkx13,bpkx14,bpkx15,bpkx16,bpkx17,bpkx18, - bpkx19,bpkx20,bpkx21,bpkx22,bpkx23,bpkx24, - bpkx25,bpkx26,bpkx27,bpkx28,bpkx29,bpkx30, - - ppkx1, ppkx2, ppkx3, ppkx4, ppkx5, ppkx6, - bbpkx1,bbpkx2,bbpkx3,bbpkx4,bbpkx5,bbpkx6, - - dcpkx1, dcpkx2, gtspkx, fusedpkx,subepkx1,subepkx2,subepkx3, - }; - return pba[slot]; - } private void getQuickFiller(PictureBox pb, byte[] dslotdata = null) { if (!init) return; @@ -3233,40 +3178,14 @@ private void getBox(object sender, EventArgs e) { setPKXBoxes(); } - private void getTSV(object sender, EventArgs e) - { - uint tsv = PKX.getTSV(Util.ToUInt32(TB_TID.Text), Util.ToUInt32(TB_SID.Text)); - Tip1.SetToolTip(TB_TID, "TSV: " + tsv.ToString("0000")); - Tip2.SetToolTip(TB_SID, "TSV: " + tsv.ToString("0000")); - uint psv = PKX.getPSV(Util.getHEXval(TB_PID)); - Tip3.SetToolTip(TB_PID, "PSV: " + psv.ToString("0000")); - } - - private void getNatureModification(object sender, EventArgs e) - { - if (sender is ComboBox && (sender as ComboBox).Name != CB_Nature.Name) return; - int nature = Util.getIndex(CB_Nature); - int incr = nature / 5; - int decr = nature % 5; - - Label[] labarray = { Label_ATK, Label_DEF, Label_SPE, Label_SPA, Label_SPD }; - // Reset Label Colors - foreach (Label label in labarray) - label.ForeColor = defaultControlText; - - // Set Colored StatLabels only if Nature isn't Neutral - NatureTip.SetToolTip(CB_Nature, - incr != decr - ? String.Format("+{0} / -{1}", labarray[incr].Text, labarray[decr].Text).Replace(":", "") - : "-/-"); - } + private int DaycareSlot; private void switchDaycare(object sender, EventArgs e) { - if (!savegame_oras) return; - if (DialogResult.Yes == Util.Prompt(MessageBoxButtons.YesNo, "Would you like to switch the view to the other Daycare?", String.Format("Currently viewing daycare {0}.", SaveGame.Daycare / 0x211F0 + 1))) + if (!SaveGame.ORAS) return; + if (DialogResult.Yes == Util.Prompt(MessageBoxButtons.YesNo, "Would you like to switch the view to the other Daycare?", String.Format("Currently viewing daycare {0}.", DaycareSlot + 1))) // If ORAS, alter the daycare offset via toggle. - SaveGame.Daycare = (SaveGame.Daycare == 0x21000) ? 0x211F0 : 0x21000; + DaycareSlot ^= 1; // Refresh Boxes setPKXBoxes(); @@ -3392,7 +3311,6 @@ private void loadBoxesFromDB(string path) Array.Copy(ezeros, 0, savefile, offset + i * 232, 232); } string[] filepaths = Directory.GetFiles(path, "*.*", SearchOption.TopDirectoryOnly); - var Converter = new pk2pk(); foreach (string t in filepaths) { @@ -3418,7 +3336,7 @@ private void loadBoxesFromDB(string path) if (!PKX.verifychk(input)) continue; { try // to convert g5pkm - { data = PKX.encryptArray(Converter.ConvertPKM(input, savefile, savindex)); pastctr++; } + { data = PKX.encryptArray(Converter.ConvertPKM(input)); pastctr++; } catch { continue; } } } @@ -3497,35 +3415,36 @@ private void B_SaveBoxBin_Click(object sender, EventArgs e) private void B_OpenWondercards_Click(object sender, EventArgs e) { // Open Wondercard Menu - new SAV_Wondercard(this).ShowDialog(); + new SAV_Wondercard().ShowDialog(); } private void B_OpenBoxLayout_Click(object sender, EventArgs e) { // Open Box Layout Menu - new SAV_BoxLayout(this).ShowDialog(); + new SAV_BoxLayout(CB_BoxSelect.SelectedIndex).ShowDialog(); setBoxNames(); // fix box names setPKXBoxes(); // refresh box background } private void B_OpenTrainerInfo_Click(object sender, EventArgs e) { - new SAV_Trainer(this).ShowDialog(); + new SAV_Trainer().ShowDialog(); + refreshTrainerInfo(); } private void B_OpenPokepuffs_Click(object sender, EventArgs e) { - new SAV_Pokepuff(this).ShowDialog(); + new SAV_Pokepuff().ShowDialog(); } private void B_OpenItemPouch_Click(object sender, EventArgs e) { - new SAV_Inventory(this).ShowDialog(); + new SAV_Inventory().ShowDialog(); } private void B_OpenBerryField_Click(object sender, EventArgs e) { - if (savegame_oras) + if (SaveGame.ORAS) { DialogResult dr = Util.Prompt(MessageBoxButtons.YesNo, "No editing support for ORAS :(", "Repopulate all with random berries?"); if (dr != DialogResult.Yes) return; // abort // Randomize the trees. - int offset = 0x1C400 + 0x5400 + savindex * 0x7F000; + byte[] ready = { 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x80, 0x40, 0x01, 0x00, 0x00, 0x00, }; int[] berrylist = { @@ -3537,22 +3456,22 @@ private void B_OpenBerryField_Click(object sender, EventArgs e) }; for (int i = 0; i < 90; i++) { - Array.Copy(ready, 0, savefile, offset + 0x10 * i, 0x10); // prep the berry template tree (which we replace offset 0x6 for the Tree Item) + Array.Copy(ready, 0, savefile, SaveGame.BerryField + 0x10 * i, 0x10); // prep the berry template tree (which we replace offset 0x6 for the Tree Item) int randberry = (int)(Util.rnd32() % berrylist.Length); // generate a random berry that will go into the tree int index = berrylist[randberry]; // get berry item ID from list - Array.Copy(BitConverter.GetBytes(index), 0, savefile, offset + 0x10 * i + 6, 2); // put berry into tree. + Array.Copy(BitConverter.GetBytes(index), 0, savefile, SaveGame.BerryField + 0x10 * i + 6, 2); // put berry into tree. } } else - new SAV_BerryField(this, SaveGame.BerryField).ShowDialog(); + new SAV_BerryField().ShowDialog(); } private void B_OpenEventFlags_Click(object sender, EventArgs e) { // Open Flag Menu - if (savegame_oras) - new SAV_EventFlagsORAS(this).ShowDialog(); + if (SaveGame.ORAS) + new SAV_EventFlagsORAS().ShowDialog(); else - new SAV_EventFlagsXY(this).ShowDialog(); + new SAV_EventFlagsXY().ShowDialog(); } private void B_OpenSuperTraining_Click(object sender, EventArgs e) { @@ -3562,7 +3481,7 @@ private void B_OpenSuperTraining_Click(object sender, EventArgs e) private void B_OpenOPowers_Click(object sender, EventArgs e) { // Open O-Power Menu - if (savegame_oras) + if (SaveGame.ORAS) { DialogResult dr = Util.Prompt(MessageBoxButtons.YesNo, "No editing support for ORAS :(", "Max O-Powers with a working code?"); if (dr != DialogResult.Yes) return; @@ -3586,18 +3505,18 @@ private void B_OpenOPowers_Click(object sender, EventArgs e) 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, }; - Array.Copy(maxoras, 0, savefile, 0x17400 + 0x5400 + 0x7F000 * savindex, 0x44); + Array.Copy(maxoras, 0, savefile, SaveGame.OPower, 0x44); } else - new SAV_OPower(this).ShowDialog(); + new SAV_OPower().ShowDialog(); } private void B_OpenPokedex_Click(object sender, EventArgs e) { // Open Pokedex Menu - if (savegame_oras) - new SAV_PokedexORAS(this).ShowDialog(); + if (SaveGame.ORAS) + new SAV_PokedexORAS().ShowDialog(); else - new SAV_PokedexXY(this).ShowDialog(); + new SAV_PokedexXY().ShowDialog(); } private void B_OUTPasserby_Click(object sender, EventArgs e) { @@ -3608,7 +3527,7 @@ private void B_OUTPasserby_Click(object sender, EventArgs e) "PSS Data - Acquaintances", "PSS Data - Passerby", }; - int offset = savindex * 0x7F000 + SaveGame.PSS; + int offset = SaveGame.PSS; for (int g = 0; g < 3; g++) { result += Environment.NewLine @@ -3662,18 +3581,17 @@ private void B_OUTPasserby_Click(object sender, EventArgs e) private void B_OUTHallofFame_Click(object sender, EventArgs e) { // Open HoF Menu - new SAV_HallOfFame(this).ShowDialog(); + new SAV_HallOfFame().ShowDialog(); } private void B_OpenSecretBase_Click(object sender, EventArgs e) { // Open Secret Base Menu - new SAV_SecretBase(this).ShowDialog(); + new SAV_SecretBase().ShowDialog(); } private void B_JPEG_Click(object sender, EventArgs e) { - int offset = 0x7F000 * savindex + SaveGame.JPEG; - - string filename = Encoding.Unicode.GetString(savefile, offset + 0, 0x1A).Replace("\0", string.Empty); + int offset = SaveGame.JPEG; + string filename = Encoding.Unicode.GetString(savefile, offset, 0x1A).Trim(); filename += "'s picture"; offset += 0x54; if (savefile[offset] != 0xFF) @@ -3744,15 +3662,13 @@ private void clickOpenTempFolder(object sender, EventArgs e) private void clickSwitchSAV(object sender, EventArgs e) { - DialogResult switchsav = Util.Prompt(MessageBoxButtons.YesNo, String.Format("Current Savefile is Save {0}.", (savindex + 1)), String.Format("Would you like to switch to Save {0}?", ((savindex + 1) % 2 + 1))); - if (switchsav != DialogResult.Yes) return; - savindex = (savindex + 1) % 2; - setBoxNames(); - setPKXBoxes(); - setSAVLabel(); - int startBox = savefile[SaveGame.PCLayout + savindex * 0x7FFFF + 0x43F] & 0x1F; - if (startBox > 30) { tabBoxMulti.SelectedIndex = 1; CB_BoxSelect.SelectedIndex = 0; } - else { tabBoxMulti.SelectedIndex = 0; CB_BoxSelect.SelectedIndex = startBox; } + if (DialogResult.Yes != + Util.Prompt(MessageBoxButtons.YesNo, String.Format("Current Savefile is Save {0}.", (savindex + 1)), + String.Format("Would you like to switch to Save {0}?", ((savindex + 1)%2 + 1)))) + return; + + savefile = powersave.Skip(0x5400 + 0x7F000 + savindex).Take(savefile.Length).ToArray(); + openSave(SaveGame.ORAS); } // Drag & Drop within Box @@ -3817,11 +3733,10 @@ private void pbBoxSlot_DragDrop(object sender, DragEventArgs e) if ((fi.Length == 136) || (fi.Length == 220) || (fi.Length == 236) || (fi.Length == 100) || (fi.Length == 80)) { byte[] input = File.ReadAllBytes(files[0]); - var Converter = new pk2pk(); if (!PKX.verifychk(input)) Util.Alert("Invalid File Loaded.", "Checksum is not valid."); try // to convert past gen pkm { - byte[] data = Converter.ConvertPKM(input, savefile, savindex); + byte[] data = Converter.ConvertPKM(input); Array.Copy(PKX.encryptArray(data), 0, savefile, offset, 0xE8); } catch @@ -3842,7 +3757,7 @@ private void pbBoxSlot_DragDrop(object sender, DragEventArgs e) { Array.Copy(data, 0, savefile, offset, 0xE8); setPokedex(decdata); - getQuickFiller(getPictureBox(slot), decdata); + getQuickFiller(SlotPictureBoxes[slot], decdata); getSlotColor(slot, Properties.Resources.slotSet); } } @@ -3857,7 +3772,7 @@ private void pbBoxSlot_DragDrop(object sender, DragEventArgs e) byte[] cleardata = new Byte[0xE8]; // Clear from slot picture - getQuickFiller(getPictureBox(pkm_from_slot), cleardata); + getQuickFiller(SlotPictureBoxes[pkm_from_slot], cleardata); // Clear from slot data Array.Copy(PKX.encryptArray(cleardata), 0, savefile, pkm_from_offset, 0xE8); @@ -3869,14 +3784,14 @@ private void pbBoxSlot_DragDrop(object sender, DragEventArgs e) Array.Copy(savefile, offset, swapdata, 0, 0xE8); // Swap slot picture - getQuickFiller(getPictureBox(pkm_from_slot), PKX.decryptArray(swapdata)); + getQuickFiller(SlotPictureBoxes[pkm_from_slot], PKX.decryptArray(swapdata)); // Swap slot data to source Array.Copy(swapdata, 0, savefile, pkm_from_offset, 0xE8); } // Copy from temp slot to new. Array.Copy(pkm_from, 0, savefile, offset, 0xE8); - getQuickFiller(getPictureBox(slot), PKX.decryptArray(pkm_from)); + getQuickFiller(SlotPictureBoxes[slot], PKX.decryptArray(pkm_from)); pkm_from_offset = 0; // Clear offset value } diff --git a/PKX/f1-Main.resx b/PKX/f1-Main.resx index 2d857f435..b8594dd25 100644 --- a/PKX/f1-Main.resx +++ b/PKX/f1-Main.resx @@ -591,9 +591,6 @@ True - - True - True diff --git a/PKX/f2-Text.cs b/PKX/f2-Text.cs index d4c45a3bf..0398a097b 100644 --- a/PKX/f2-Text.cs +++ b/PKX/f2-Text.cs @@ -8,10 +8,10 @@ public partial class f2_Text : Form { public f2_Text(TextBox TB_NN) { - Form1.specialChars = true; + Main.specialChars = true; Hide(); InitializeComponent(); - Util.TranslateInterface(this, Form1.curlanguage); + Util.TranslateInterface(this, Main.curlanguage); TB_Nickname = TB_NN; Font pkxFont = PKX.getPKXFont(12F); Label[] lbla = @@ -46,7 +46,7 @@ private void onClick(object sender, EventArgs e) } private void onClosed(object sender, FormClosedEventArgs e) { - Form1.specialChars = false; + Main.specialChars = false; } } } diff --git a/PKX/f3-MemoryAmie.cs b/PKX/f3-MemoryAmie.cs index af279449d..eadab76fc 100644 --- a/PKX/f3-MemoryAmie.cs +++ b/PKX/f3-MemoryAmie.cs @@ -6,7 +6,7 @@ namespace PKHeX { public partial class MemoryAmie : Form { - Form1 m_parent; + Main m_parent; public byte[] h = new byte[260]; // Always Visible private string disabled = "Disabled"; private string notleft = "Never left"; @@ -14,14 +14,14 @@ public partial class MemoryAmie : Form private string past = "Past Gen"; private string withOT = "Memories with"; // these get replaced when the form is translated. private string[] vartypes = new string[5]; - public MemoryAmie(Form1 frm1) + public MemoryAmie(Main frm1) // Keeping the form reference as a lot of control elements are required to operate. { InitializeComponent(); CB_Country0.DisplayMember = CB_Country1.DisplayMember = CB_Country2.DisplayMember = CB_Country3.DisplayMember = CB_Country4.DisplayMember = "Text"; CB_Country0.ValueMember = CB_Country1.ValueMember = CB_Country2.ValueMember = CB_Country3.ValueMember = CB_Country4.ValueMember = "Value"; CB_Region0.DisplayMember = CB_Region1.DisplayMember = CB_Region2.DisplayMember = CB_Region3.DisplayMember = CB_Region4.DisplayMember = "Text"; CB_Region0.ValueMember = CB_Region1.ValueMember = CB_Region2.ValueMember = CB_Region3.ValueMember = CB_Region4.ValueMember = "Value"; - Util.TranslateInterface(this, Form1.curlanguage); + Util.TranslateInterface(this, Main.curlanguage); m_parent = frm1; string[] arguments = Regex.Split(L_Arguments.Text, " ; "); @@ -46,7 +46,7 @@ public MemoryAmie(Form1 frm1) past = "Past Gen"; withOT = "Memories with"; } - h = m_parent.buff; + h = Main.buff; getCountries(); getLangStrings(); @@ -85,9 +85,9 @@ private void loadFields() if (Util.TrimFromZero(m_parent.TB_OTt2.Text) != "") CB_Handler.Items.AddRange(new object[] { m_parent.TB_OTt2.Text }); else - m_parent.buff[0x93] = 0; + Main.buff[0x93] = 0; - tabControl1.SelectedIndex = CB_Handler.SelectedIndex = m_parent.buff[0x93]; + tabControl1.SelectedIndex = CB_Handler.SelectedIndex = Main.buff[0x93]; if (m_parent.CHK_IsEgg.Checked) { @@ -97,8 +97,8 @@ private void loadFields() BTN_Save.Enabled = M_Fullness.Enabled = M_Enjoyment.Enabled = false; L_Fullness.Enabled = L_Enjoyment.Enabled = false; - GB_M_OT.Text = "N/A: " + Form1.eggname; - GB_M_CT.Text = "N/A: " + Form1.eggname; + GB_M_OT.Text = "N/A: " + Main.eggname; + GB_M_CT.Text = "N/A: " + Main.eggname; } else { @@ -167,8 +167,8 @@ private void saveFields() cb1v(CB_CTMemory, 0xA5); if (!CB_CTVar.Enabled) { - m_parent.buff[0xA8] = 0; - m_parent.buff[0xA9] = 0; + Main.buff[0xA8] = 0; + Main.buff[0xA9] = 0; } else cb2v(CB_CTVar, 0xA8); @@ -176,21 +176,21 @@ private void saveFields() // If memory doesn't contain a feeling/quality if (!CB_CTFeel.Enabled) { - m_parent.buff[0xA4] = 0; - m_parent.buff[0xA6] = 0; + Main.buff[0xA4] = 0; + Main.buff[0xA6] = 0; } else { cb1i(CB_CTFeel, 0xA6); - m_parent.buff[0xA4] = (byte)(CB_CTQual.SelectedIndex + 1); + Main.buff[0xA4] = (byte)(CB_CTQual.SelectedIndex + 1); } #endregion #region // OT MEMORIES cb1v(CB_OTMemory, 0xCD); if (!CB_OTVar.Enabled) { - m_parent.buff[0xCE] = 0; - m_parent.buff[0xCF] = 0; + Main.buff[0xCE] = 0; + Main.buff[0xCF] = 0; } else cb2v(CB_OTVar, 0xCE); @@ -198,13 +198,13 @@ private void saveFields() // If memory doesn't contain a feeling/quality if (!CB_OTFeel.Enabled) { - m_parent.buff[0xCC] = 0; - m_parent.buff[0xD0] = 0; + Main.buff[0xCC] = 0; + Main.buff[0xD0] = 0; } else { cb1i(CB_OTFeel, 0xD0); - m_parent.buff[0xCC] = (byte)(CB_OTQual.SelectedIndex + 1); + Main.buff[0xCC] = (byte)(CB_OTQual.SelectedIndex + 1); } #endregion } @@ -263,19 +263,19 @@ private void getCountries() { comboBox.DisplayMember = "Text"; comboBox.ValueMember = "Value"; - m_parent.setCountrySubRegion(comboBox, "countries"); + Main.setCountrySubRegion(comboBox, "countries"); } } private void getLangStrings() { // Memory Chooser - int memorycount = Form1.memories.Length - 38; + int memorycount = Main.memories.Length - 38; string[] memories = new string[memorycount]; int[] allowed = new int[memorycount]; for (int i = 0; i < memorycount; i++) { - memories[i] = Form1.memories[38 + i]; + memories[i] = Main.memories[38 + i]; allowed[i] = i + 1; } Array.Resize(ref allowed, allowed.Length - 1); @@ -295,8 +295,8 @@ private void getLangStrings() CB_OTQual.Items.Clear(); for (int i = 0; i < 7; i++) { - CB_CTQual.Items.Add(Form1.memories[2 + i]); - CB_OTQual.Items.Add(Form1.memories[2 + i]); + CB_CTQual.Items.Add(Main.memories[2 + i]); + CB_OTQual.Items.Add(Main.memories[2 + i]); } // Feeling Chooser @@ -304,8 +304,8 @@ private void getLangStrings() CB_OTFeel.Items.Clear(); for (int i = 0; i < 24; i++) { - CB_CTFeel.Items.Add(Form1.memories[10 + i]); - CB_OTFeel.Items.Add(Form1.memories[10 + i]); + CB_CTFeel.Items.Add(Main.memories[10 + i]); + CB_OTFeel.Items.Add(Main.memories[10 + i]); } } private void getMemoryArguments(string ARG, ComboBox sender) @@ -321,11 +321,11 @@ private void getMemoryArguments(string ARG, ComboBox sender) vs = ""; break; case "PKM": - argvals = Util.getCBList(Form1.specieslist, null); + argvals = Util.getCBList(Main.specieslist, null); vs = vartypes[0]; break; case "GENLOC": - argvals = Util.getCBList(Form1.genloc, null); + argvals = Util.getCBList(Main.genloc, null); vs = vartypes[1]; break; case "ITEM": @@ -351,18 +351,18 @@ private void getMemoryArguments(string ARG, ComboBox sender) /* ORAS */ 718,719,720,737,738,739,740,741,742,752,753,754,755,756,757,758,759,760,761,762,763,764,765,767,768, 769,770,775 }; - var item_list = Util.getCBList(Form1.itemlist, items_allowed); + var item_list = Util.getCBList(Main.itemlist, items_allowed); #endregion argvals = item_list; vs = vartypes[2]; } break; case "MOVE": - argvals = Util.getCBList(Form1.movelist, null); + argvals = Util.getCBList(Main.movelist, null); vs = vartypes[3]; break; case "LOCATION": - argvals = Util.getCBList(Form1.metXY_00000, Legal.Met_XY_0); + argvals = Util.getCBList(Main.metXY_00000, Legal.Met_XY_0); vs = vartypes[4]; break; } @@ -386,17 +386,17 @@ private void getMemoryArguments(string ARG, ComboBox sender) } private string getMemoryString(ComboBox m, ComboBox arg, ComboBox q, ComboBox f, string tr) { - string result = ""; + string result; string nn = m_parent.TB_Nickname.Text; string a = ((Util.cbItem)(arg.SelectedItem) == null) ? arg.Text ?? "ERROR" : ((Util.cbItem)(arg.SelectedItem)).Text; int mem = Util.getIndex(m); bool enabled = false; if (mem == 0) - result = Form1.memories[38]; + result = Main.memories[38]; else { - result = String.Format(Form1.memories[mem + 38], nn, tr, a, f.Text, q.Text); + result = String.Format(Main.memories[mem + 38], nn, tr, a, f.Text, q.Text); enabled = true; } @@ -505,7 +505,7 @@ private void changeCountry(object sender, EventArgs e) }; int index = Array.IndexOf(cba, sender as ComboBox); if (Util.getIndex(sender as ComboBox) > 0) - m_parent.setCountrySubRegion(mta[index], "sr_" + Util.getIndex(sender as ComboBox).ToString("000")); + Main.setCountrySubRegion(mta[index], "sr_" + Util.getIndex(sender as ComboBox).ToString("000")); } private void update255_MTB(object sender, EventArgs e) diff --git a/PKX/f4-RibbMedal.cs b/PKX/f4-RibbMedal.cs index 83c8f829c..0ac095a31 100644 --- a/PKX/f4-RibbMedal.cs +++ b/PKX/f4-RibbMedal.cs @@ -7,20 +7,18 @@ namespace PKHeX { public partial class RibbMedal : Form { - Form1 m_parent; - public RibbMedal(Form1 frm1) + public RibbMedal() { InitializeComponent(); - Util.TranslateInterface(this, Form1.curlanguage); - m_parent = frm1; + Util.TranslateInterface(this, Main.curlanguage); // Set up Training Bag Data comboBox1.Items.Clear(); comboBox1.Items.Add("---"); - for (int i = 1; i < Form1.trainingbags.Length - 1; i++) - comboBox1.Items.Add(Form1.trainingbags[i]); - comboBox1.SelectedIndex = m_parent.buff[0x17]; - numericUpDown1.Value = m_parent.buff[0x16]; + for (int i = 1; i < Main.trainingbags.Length - 1; i++) + comboBox1.Items.Add(Main.trainingbags[i]); + comboBox1.SelectedIndex = Main.buff[0x17]; + numericUpDown1.Value = Main.buff[0x16]; getRibbons(); } private void getRibbons() @@ -66,11 +64,9 @@ private void getRibbons() for (int i = 0; i < bma.Length; i++) pba[i].Image = Util.ChangeOpacity(bma[i], 0.1); - - int rv = 0; // Read from value (later redefined) // Populate Medals (what a mess) - rv = m_parent.buff[0x2C]; + int rv = Main.buff[0x2C]; updateRibbon(TMedal1_0, rv, 0); updateRibbon(TMedal1_1, rv, 1); updateRibbon(TMedal1_2, rv, 2); @@ -79,7 +75,7 @@ private void getRibbons() updateRibbon(TMedal1_5, rv, 5); updateRibbon(TMedal1_6, rv, 6); updateRibbon(TMedal1_7, rv, 7); - rv = m_parent.buff[0x2D]; + rv = Main.buff[0x2D]; updateRibbon(TMedal2_0, rv, 0); updateRibbon(TMedal2_1, rv, 1); updateRibbon(TMedal2_2, rv, 2); @@ -88,7 +84,7 @@ private void getRibbons() updateRibbon(TMedal2_5, rv, 5); updateRibbon(TMedal2_6, rv, 6); updateRibbon(TMedal2_7, rv, 7); - rv = m_parent.buff[0x2E]; + rv = Main.buff[0x2E]; updateRibbon(TMedal3_0, rv, 0); updateRibbon(TMedal3_1, rv, 1); updateRibbon(TMedal3_2, rv, 2); @@ -97,7 +93,7 @@ private void getRibbons() updateRibbon(TMedal3_5, rv, 5); updateRibbon(TMedal3_6, rv, 6); updateRibbon(TMedal3_7, rv, 7); - rv = m_parent.buff[0x2F]; + rv = Main.buff[0x2F]; updateRibbon(TMedal4_0, rv, 0); updateRibbon(TMedal4_1, rv, 1); updateRibbon(TMedal4_2, rv, 2); @@ -108,7 +104,7 @@ private void getRibbons() updateRibbon(TMedal4_7, rv, 7); // Populate Kalos Ribbons - rv = m_parent.buff[0x30]; + rv = Main.buff[0x30]; updateRibbon(Kalos1a_0, rv, 0); updateRibbon(Kalos1a_1, rv, 1); updateRibbon(Kalos1a_2, rv, 2); @@ -117,7 +113,7 @@ private void getRibbons() updateRibbon(Kalos1a_5, rv, 5); updateRibbon(Kalos1a_6, rv, 6); updateRibbon(Kalos1a_7, rv, 7); - rv = m_parent.buff[0x31]; + rv = Main.buff[0x31]; updateRibbon(Kalos1b_0, rv, 0); updateRibbon(Kalos1b_1, rv, 1); updateRibbon(Kalos1b_2, rv, 2); @@ -126,7 +122,7 @@ private void getRibbons() updateRibbon(Kalos1b_5, rv, 5); updateRibbon(Kalos1b_6, rv, 6); updateRibbon(Kalos1b_7, rv, 7); - rv = m_parent.buff[0x32]; + rv = Main.buff[0x32]; updateRibbon(Kalos2a_0, rv, 0); updateRibbon(Kalos2a_1, rv, 1); updateRibbon(Kalos2a_2, rv, 2); @@ -135,7 +131,7 @@ private void getRibbons() updateRibbon(Kalos2a_5, rv, 5); updateRibbon(Kalos2a_6, rv, 6); updateRibbon(Kalos2a_7, rv, 7); - rv = m_parent.buff[0x33]; + rv = Main.buff[0x33]; updateRibbon(Kalos2b_0, rv, 0); updateRibbon(Kalos2b_1, rv, 1); updateRibbon(Kalos2b_2, rv, 2); @@ -146,7 +142,7 @@ private void getRibbons() updateRibbon(Kalos2b_7, rv, 7); // Populate Extra Ribbons - rv = m_parent.buff[0x34]; + rv = Main.buff[0x34]; updateRibbon(Extra1_0, rv, 0); updateRibbon(Extra1_1, rv, 1); updateRibbon(Extra1_2, rv, 2); @@ -155,7 +151,7 @@ private void getRibbons() // oras updateRibbon(Extra1_7, rv, 7); - rv = m_parent.buff[0x35]; + rv = Main.buff[0x35]; updateRibbon(ORAS_0, rv, 0); updateRibbon(ORAS_1, rv, 1); updateRibbon(ORAS_2, rv, 2); @@ -163,10 +159,10 @@ private void getRibbons() updateRibbon(ORAS_4, rv, 4); updateRibbon(ORAS_5, rv, 5); - TB_PastContest.Text = m_parent.buff[0x38].ToString(); - TB_PastBattle.Text = m_parent.buff[0x39].ToString(); + TB_PastContest.Text = Main.buff[0x38].ToString(); + TB_PastBattle.Text = Main.buff[0x39].ToString(); - rv = m_parent.buff[0x3A]; + rv = Main.buff[0x3A]; updateRibbon(CHK_D0, rv, 0); updateRibbon(CHK_D1, rv, 1); updateRibbon(CHK_D2, rv, 2); @@ -174,7 +170,7 @@ private void getRibbons() updateRibbon(CHK_D4, rv, 4); updateRibbon(CHK_D5, rv, 5); - CHK_Secret.Checked = Convert.ToBoolean(m_parent.buff[0x72]); + CHK_Secret.Checked = Convert.ToBoolean(Main.buff[0x72]); } // Populate Ribbons prompted private void setRibbons() { @@ -212,10 +208,10 @@ private void setRibbons() kalos2b |= addRibbon(Kalos2b_5); kalos2b |= addRibbon(Kalos2b_6); kalos2b |= addRibbon(Kalos2b_7);//// - m_parent.buff[0x30] = (byte)kalos1a; - m_parent.buff[0x31] = (byte)kalos1b; - m_parent.buff[0x32] = (byte)kalos2a; - m_parent.buff[0x33] = (byte)kalos2b; + Main.buff[0x30] = (byte)kalos1a; + Main.buff[0x31] = (byte)kalos1b; + Main.buff[0x32] = (byte)kalos2a; + Main.buff[0x33] = (byte)kalos2b; // Pass Extra Ribbon int extra1 = 0; @@ -227,7 +223,7 @@ private void setRibbons() // ORAS extra1 |= addRibbon(Extra1_7); // Hoenn Champ - m_parent.buff[0x34] = (byte)extra1; + Main.buff[0x34] = (byte)extra1; int oras = 0; oras |= addRibbon(ORAS_0); @@ -236,7 +232,7 @@ private void setRibbons() oras |= addRibbon(ORAS_3); oras |= addRibbon(ORAS_4); oras |= addRibbon(ORAS_5); - m_parent.buff[0x35] = (byte)oras; + Main.buff[0x35] = (byte)oras; // Gather Super Training Medals int medals1 = 0, medals2 = 0, medals3 = 0, medals4 = 0; @@ -272,13 +268,13 @@ private void setRibbons() medals4 |= addRibbon(TMedal4_5); medals4 |= addRibbon(TMedal4_6); medals4 |= addRibbon(TMedal4_7);//// - m_parent.buff[0x2C] = (byte)medals1; - m_parent.buff[0x2D] = (byte)medals2; - m_parent.buff[0x2E] = (byte)medals3; - m_parent.buff[0x2F] = (byte)medals4; + Main.buff[0x2C] = (byte)medals1; + Main.buff[0x2D] = (byte)medals2; + Main.buff[0x2E] = (byte)medals3; + Main.buff[0x2F] = (byte)medals4; - m_parent.buff[0x38] = (byte)Util.ToUInt32(TB_PastContest.Text); - m_parent.buff[0x39] = (byte)Util.ToUInt32(TB_PastBattle.Text); + Main.buff[0x38] = (byte)Util.ToUInt32(TB_PastContest.Text); + Main.buff[0x39] = (byte)Util.ToUInt32(TB_PastBattle.Text); int dis = 0; dis |= addRibbon(CHK_D0); @@ -287,9 +283,9 @@ private void setRibbons() dis |= addRibbon(CHK_D3); dis |= addRibbon(CHK_D4); dis |= addRibbon(CHK_D5); - m_parent.buff[0x3A] = (byte)dis; + Main.buff[0x3A] = (byte)dis; - m_parent.buff[0x72] = Convert.ToByte(CHK_Secret.Checked); + Main.buff[0x72] = Convert.ToByte(CHK_Secret.Checked); } // Saving Ribbons prompted private void updateRibbon(CheckBox chk, int rv, int sh) { @@ -332,7 +328,7 @@ private void buttonFlag(bool b) TB_PastContest.Text = (Convert.ToInt32(b) * 40).ToString(); TB_PastBattle.Text = (Convert.ToInt32(b) * 8).ToString(); - if (m_parent.buff[0xDF] <= 0x10) return; // gen3 + if (Main.buff[0xDF] <= 0x10) return; // gen3 TB_PastContest.Text = 0.ToString(); // no past gen ribbons 4-5 TB_PastBattle.Text = 0.ToString(); } @@ -364,8 +360,8 @@ private void buttonFlag(bool b) private void BTN_Save_Click(object sender, EventArgs e) { - m_parent.buff[0x17] = (byte)comboBox1.SelectedIndex; - m_parent.buff[0x16] = (byte)numericUpDown1.Value; + Main.buff[0x17] = (byte)comboBox1.SelectedIndex; + Main.buff[0x16] = (byte)numericUpDown1.Value; setRibbons(); Close(); } // Save Button diff --git a/Program.cs b/Program.cs index 2a86901bb..1fecfc3d7 100644 --- a/Program.cs +++ b/Program.cs @@ -13,7 +13,7 @@ static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new Form1()); + Application.Run(new Main()); } } } diff --git a/SAV/SAV_BerryField.cs b/SAV/SAV_BerryField.cs index b81a59d08..aaaddb164 100644 --- a/SAV/SAV_BerryField.cs +++ b/SAV/SAV_BerryField.cs @@ -5,36 +5,29 @@ namespace PKHeX { public partial class SAV_BerryField : Form { - public SAV_BerryField(Form1 frm1, int bfo) + public SAV_BerryField() { - berryfoffset = bfo; InitializeComponent(); - Util.TranslateInterface(this, Form1.curlanguage); - Form1 mParent = frm1; - Array.Copy(mParent.savefile, sav, 0x100000); - savindex = mParent.savindex; - shiftval = savindex * 0x7F000; + Util.TranslateInterface(this, Main.curlanguage); + sav = (byte[])Main.savefile.Clone(); listBox1.SelectedIndex = 0; } - int berryfoffset; - public byte[] sav = new byte[0x100000]; - public int savindex; int shiftval; + public byte[] sav; public bool editing = false; private void changefield(object sender, EventArgs e) { // Change Berry Field - int offset = berryfoffset + shiftval; // Gather Data - int berry = BitConverter.ToUInt16(sav, offset + 0xC + listBox1.SelectedIndex*0x18 + 1 * 0); - int u1 = BitConverter.ToUInt16(sav, offset + 0xC + listBox1.SelectedIndex * 0x18 + 1 * 2); - int u2 = BitConverter.ToUInt16(sav, offset + 0xC + listBox1.SelectedIndex * 0x18 + 2 * 2); - int u3 = BitConverter.ToUInt16(sav, offset + 0xC + listBox1.SelectedIndex * 0x18 + 3 * 2); - int u4 = BitConverter.ToUInt16(sav, offset + 0xC + listBox1.SelectedIndex * 0x18 + 4 * 2); - int u5 = BitConverter.ToUInt16(sav, offset + 0xC + listBox1.SelectedIndex * 0x18 + 5 * 2); - int u6 = BitConverter.ToUInt16(sav, offset + 0xC + listBox1.SelectedIndex * 0x18 + 6 * 2); - int u7 = BitConverter.ToUInt16(sav, offset + 0xC + listBox1.SelectedIndex * 0x18 + 7 * 2); + int berry = BitConverter.ToUInt16(sav, Main.SaveGame.BerryField + 0xC + listBox1.SelectedIndex*0x18 + 1 * 0); + int u1 = BitConverter.ToUInt16(sav, Main.SaveGame.BerryField + 0xC + listBox1.SelectedIndex * 0x18 + 1 * 2); + int u2 = BitConverter.ToUInt16(sav, Main.SaveGame.BerryField + 0xC + listBox1.SelectedIndex * 0x18 + 2 * 2); + int u3 = BitConverter.ToUInt16(sav, Main.SaveGame.BerryField + 0xC + listBox1.SelectedIndex * 0x18 + 3 * 2); + int u4 = BitConverter.ToUInt16(sav, Main.SaveGame.BerryField + 0xC + listBox1.SelectedIndex * 0x18 + 4 * 2); + int u5 = BitConverter.ToUInt16(sav, Main.SaveGame.BerryField + 0xC + listBox1.SelectedIndex * 0x18 + 5 * 2); + int u6 = BitConverter.ToUInt16(sav, Main.SaveGame.BerryField + 0xC + listBox1.SelectedIndex * 0x18 + 6 * 2); + int u7 = BitConverter.ToUInt16(sav, Main.SaveGame.BerryField + 0xC + listBox1.SelectedIndex * 0x18 + 7 * 2); // Display Data diff --git a/SAV/SAV_BoxLayout.cs b/SAV/SAV_BoxLayout.cs index c28700a96..6f2eeea2c 100644 --- a/SAV/SAV_BoxLayout.cs +++ b/SAV/SAV_BoxLayout.cs @@ -7,43 +7,38 @@ namespace PKHeX { public partial class SAV_BoxLayout : Form { - public SAV_BoxLayout(Form1 frm1) + public SAV_BoxLayout(int box) { - m_parent = frm1; InitializeComponent(); - Util.TranslateInterface(this, Form1.curlanguage); + Util.TranslateInterface(this, Main.curlanguage); + sav = (byte[])Main.savefile.Clone(); editing = true; - Array.Copy(m_parent.savefile, sav, 0x100000); - savindex = m_parent.savindex; // Repopulate Wallpaper names CB_BG.Items.Clear(); - foreach (string wallpaper in Form1.wallpapernames) + foreach (string wallpaper in Main.wallpapernames) CB_BG.Items.Add(wallpaper); // Go - LB_BoxSelect.SelectedIndex = m_parent.CB_BoxSelect.SelectedIndex; + LB_BoxSelect.SelectedIndex = box; } - Form1 m_parent; - public byte[] sav = new byte[0x100000]; - public int savindex; + public byte[] sav; public bool editing; private void changeBox(object sender, EventArgs e) { editing = true; int index = LB_BoxSelect.SelectedIndex; - int offset = 0x9800 + savindex * 0x7F000; - int bgoff = (0x7F000 * savindex) + 0x9C1E + LB_BoxSelect.SelectedIndex; + int bgoff = Main.SaveGame.PCBackgrounds + LB_BoxSelect.SelectedIndex; CB_BG.SelectedIndex = sav[bgoff]; - changeBoxBG(null, null); - TB_BoxName.Text = Encoding.Unicode.GetString(sav, offset + 0x22 * index, 0x22); - CB_BG.SelectedIndex = sav[0x9C1E + savindex * 0x7F000 + index]; - MT_BG1.Text = sav[0x9C3D + savindex * 0x7F000].ToString(); - MT_BG2.Text = sav[0x9C3F + savindex * 0x7F000].ToString(); + TB_BoxName.Text = Encoding.Unicode.GetString(sav, Main.SaveGame.PCLayout + 0x22 * index, 0x22); + CB_BG.SelectedIndex = sav[bgoff]; + + MT_BG1.Text = sav[Main.SaveGame.PCFlags + 0].ToString(); + CB_Unlocked.SelectedIndex = sav[Main.SaveGame.PCFlags + 1] - 1; + MT_BG2.Text = sav[Main.SaveGame.PCFlags + 2].ToString(); - CB_Unlocked.SelectedIndex = sav[0x9C3E + savindex * 0x7F000] - 1; editing = false; } private void changeBoxDetails(object sender, EventArgs e) @@ -51,20 +46,16 @@ private void changeBoxDetails(object sender, EventArgs e) if (editing) return; int index = LB_BoxSelect.SelectedIndex; - int offset = 0x9800 + savindex * 0x7F000; - - sav[(0x7F000 * savindex) + 0x9C1E + LB_BoxSelect.SelectedIndex] = (byte)CB_BG.SelectedIndex; - - // Get Sender Index - + sav[Main.SaveGame.PCBackgrounds + index] = (byte)CB_BG.SelectedIndex; + byte[] boxname = Encoding.Unicode.GetBytes(TB_BoxName.Text); Array.Resize(ref boxname, 0x22); - Array.Copy(boxname, 0, sav, offset + 0x22 * index, boxname.Length); + Array.Copy(boxname, 0, sav, Main.SaveGame.PCLayout + 0x22 * index, boxname.Length); - sav[0x9C1E + savindex * 0x7F000 + index] = (byte)CB_BG.SelectedIndex; - sav[0x9C3D + savindex * 0x7F000] = (byte)Util.ToUInt32(MT_BG1.Text); - sav[0x9C3F + savindex * 0x7F000] = (byte)Util.ToUInt32(MT_BG2.Text); - sav[0x9C3E + savindex * 0x7F000] = (byte)Util.ToUInt32(CB_Unlocked.Text); + sav[Main.SaveGame.PCBackgrounds + index] = (byte)CB_BG.SelectedIndex; + sav[Main.SaveGame.PCFlags + 0] = (byte)Util.ToUInt32(MT_BG1.Text); + sav[Main.SaveGame.PCFlags + 1] = (byte)Util.ToUInt32(CB_Unlocked.Text); + sav[Main.SaveGame.PCFlags + 2] = (byte)Util.ToUInt32(MT_BG2.Text); } private void B_Cancel_Click(object sender, EventArgs e) { @@ -72,16 +63,16 @@ private void B_Cancel_Click(object sender, EventArgs e) } private void B_Save_Click(object sender, EventArgs e) { - Array.Copy(sav, m_parent.savefile, 0x100000); - m_parent.savedited = true; + Array.Copy(sav, Main.savefile, sav.Length); + Main.savedited = true; Close(); } private void changeBoxBG(object sender, EventArgs e) { - sav[(0x7F000 * savindex) + 0x9C1E + LB_BoxSelect.SelectedIndex] = (byte)CB_BG.SelectedIndex; + sav[Main.SaveGame.PCBackgrounds + LB_BoxSelect.SelectedIndex] = (byte)CB_BG.SelectedIndex; - string imagename = "box_wp" + (CB_BG.SelectedIndex + 1).ToString("00"); if (m_parent.savegame_oras && (CB_BG.SelectedIndex + 1) > 16) imagename += "o"; + string imagename = "box_wp" + (CB_BG.SelectedIndex + 1).ToString("00"); if (Main.SaveGame.ORAS && (CB_BG.SelectedIndex + 1) > 16) imagename += "o"; PAN_BG.BackgroundImage = (Image)Properties.Resources.ResourceManager.GetObject(imagename); } } diff --git a/SAV/SAV_EventFlagsORAS.cs b/SAV/SAV_EventFlagsORAS.cs index a026dc7e1..6ddd5e334 100644 --- a/SAV/SAV_EventFlagsORAS.cs +++ b/SAV/SAV_EventFlagsORAS.cs @@ -8,12 +8,10 @@ namespace PKHeX { public partial class SAV_EventFlagsORAS : Form { - public SAV_EventFlagsORAS(Form1 frm1) + public SAV_EventFlagsORAS() { InitializeComponent(); - Util.TranslateInterface(this, Form1.curlanguage); - m_parent = frm1; - savshift = 0x7F000 * m_parent.savindex; + Util.TranslateInterface(this, Main.curlanguage); AllowDrop = true; DragEnter += tabMain_DragEnter; @@ -21,14 +19,12 @@ public SAV_EventFlagsORAS(Form1 frm1) Setup(); nud.Text = "0"; // Prompts an update for flag 0. - MT_Ash.Text = BitConverter.ToUInt16(m_parent.savefile, savshift + 0x14A78 + 0x5400).ToString(); + MT_Ash.Text = BitConverter.ToUInt16(Main.savefile, Main.SaveGame.EventAsh).ToString(); } - Form1 m_parent; - public int savshift; bool setup = true; public CheckBox[] chka; public bool[] flags = new bool[3072]; - public ushort[] Constants = new ushort[0x2FC / 2]; + public ushort[] Constants = new ushort[(Main.SaveGame.EventFlag - Main.SaveGame.EventConst) / 2]; private void B_Cancel_Click(object sender, EventArgs e) { Close(); @@ -45,15 +41,15 @@ private void B_Save_Click(object sender, EventArgs e) if (flags[i]) data[i / 8] |= (byte)(1 << i % 8); - Array.Copy(data, 0, m_parent.savefile, 0x1A0FC + savshift, 0x180); + Array.Copy(data, 0, Main.savefile, Main.SaveGame.EventFlag, 0x180); // Copy back Volcanic Ash counter - Array.Copy(BitConverter.GetBytes(Util.ToUInt32(MT_Ash)), 0, m_parent.savefile, 0x14A78 + 0x5400 + savshift, 2); + Array.Copy(BitConverter.GetBytes(Util.ToUInt32(MT_Ash)), 0, Main.savefile, Main.SaveGame.EventAsh, 2); // Copy back Constants changeConstantIndex(null, null); // Trigger Saving for (int i = 0; i < Constants.Length; i++) - Array.Copy(BitConverter.GetBytes(Constants[i]), 0, m_parent.savefile, 0x19E00 + savshift + 2 * i, 2); + Array.Copy(BitConverter.GetBytes(Constants[i]), 0, Main.savefile, Main.SaveGame.EventConst + 2 * i, 2); Close(); } @@ -105,18 +101,17 @@ private void Setup() //flag_0675, // Chatelaine 50 //flag_2546, // Pokedex }; - int offset = 0x1A0FC + savshift; byte[] data = new byte[0x180]; - Array.Copy(m_parent.savefile, offset, data, 0, 0x180); + Array.Copy(Main.savefile, Main.SaveGame.EventFlag, data, 0, 0x180); BitArray BitRegion = new BitArray(data); BitRegion.CopyTo(flags, 0); // Setup Event Constant Editor CB_Stats.Items.Clear(); - for (int i = 0; i < 0x2FC; i += 2) + for (int i = 0; i < Constants.Length; i += 2) { CB_Stats.Items.Add(String.Format("0x{0}", i.ToString("X3"))); - Constants[i / 2] = BitConverter.ToUInt16(m_parent.savefile, 0x19E00 + i); + Constants[i / 2] = BitConverter.ToUInt16(Main.savefile, Main.SaveGame.EventConst + i); } CB_Stats.SelectedIndex = 0; @@ -159,7 +154,7 @@ private void changeCustomFlag(object sender, EventArgs e) else { CHK_CustomFlag.Enabled = true; - nud.BackColor = Form1.defaultControlWhite; + nud.BackColor = Main.defaultControlWhite; CHK_CustomFlag.Checked = flags[flag]; } } @@ -212,14 +207,14 @@ private void loadSAV(object sender, string path) switch (fi.Length) { case 0x100000: // ramsav - Array.Copy(File.ReadAllBytes(path), 0x1A0FC, eventflags, 0, 0x180); + Array.Copy(File.ReadAllBytes(path), Main.SaveGame.EventFlag, eventflags, 0, 0x180); break; case 0x76000: // oras main - Array.Copy(File.ReadAllBytes(path), 0x1A0FC - 0x5400, eventflags, 0, 0x180); + Array.Copy(File.ReadAllBytes(path), Main.SaveGame.EventFlag, eventflags, 0, 0x180); break; default: // figure it out if (fi.Name.ToLower().Contains("ram") && fi.Length == 0x80000) - Array.Copy(ram2sav.getMAIN(File.ReadAllBytes(path)), 0x1A0FC - 0x5400, eventflags, 0, 0x180); + Array.Copy(ram2sav.getMAIN(File.ReadAllBytes(path)), Main.SaveGame.EventFlag, eventflags, 0, 0x180); else { Util.Error("Invalid SAV Size", String.Format("File Size: 0x{1} ({0} bytes)", fi.Length, fi.Length.ToString("X5")), "File Loaded: " + path); return; } break; diff --git a/SAV/SAV_EventFlagsXY.cs b/SAV/SAV_EventFlagsXY.cs index 25ac2b367..b64cf6c1e 100644 --- a/SAV/SAV_EventFlagsXY.cs +++ b/SAV/SAV_EventFlagsXY.cs @@ -8,27 +8,23 @@ namespace PKHeX { public partial class SAV_EventFlagsXY : Form { - public SAV_EventFlagsXY(Form1 frm1) + public SAV_EventFlagsXY() { InitializeComponent(); - Util.TranslateInterface(this, Form1.curlanguage); - m_parent = frm1; - savshift = 0x7F000 * m_parent.savindex; + Util.TranslateInterface(this, Main.curlanguage); AllowDrop = true; DragEnter += tabMain_DragEnter; DragDrop += tabMain_DragDrop; - Setup(); nud.Text = "0"; // Prompts an update for flag 0. + // No Volcanic Ash in X/Y } - Form1 m_parent; - public int savshift; bool setup = true; public CheckBox[] chka; public bool[] flags = new bool[3072]; - public ushort[] Constants = new ushort[0x2FC / 2]; + public ushort[] Constants = new ushort[(Main.SaveGame.EventFlag - Main.SaveGame.EventConst) / 2]; private void B_Cancel_Click(object sender, EventArgs e) { Close(); @@ -42,16 +38,18 @@ private void B_Save_Click(object sender, EventArgs e) byte[] data = new byte[flags.Length / 8]; for (int i = 0; i < flags.Length; i++) - { if (flags[i]) data[i / 8] |= (byte)(1 << i % 8); - } - Array.Copy(data, 0, m_parent.savefile, 0x1A0FC + savshift, 0x180); + + Array.Copy(data, 0, Main.savefile, Main.SaveGame.EventFlag, 0x180); + + // No Volcanic Ash in X/Y + // Copy back Constants changeConstantIndex(null, null); // Trigger Saving for (int i = 0; i < Constants.Length; i++) - Array.Copy(BitConverter.GetBytes(Constants[i]), 0, m_parent.savefile, 0x19E00 + savshift + 2 * i, 2); + Array.Copy(BitConverter.GetBytes(Constants[i]), 0, Main.savefile, Main.SaveGame.EventConst + 2 * i, 2); Close(); } @@ -69,18 +67,17 @@ private void Setup() flag_0675, // Chatelaine 50 flag_2546, // Pokedex }; - int offset = 0x1A0FC + savshift; byte[] data = new byte[0x180]; - Array.Copy(m_parent.savefile, offset, data, 0, 0x180); + Array.Copy(Main.savefile, Main.SaveGame.EventFlag, data, 0, 0x180); BitArray BitRegion = new BitArray(data); BitRegion.CopyTo(flags, 0); // Setup Event Constant Editor CB_Stats.Items.Clear(); - for (int i = 0; i < 0x2FC; i += 2) + for (int i = 0; i < Constants.Length; i += 2) { CB_Stats.Items.Add(String.Format("0x{0}", i.ToString("X3"))); - Constants[i / 2] = BitConverter.ToUInt16(m_parent.savefile, 0x19E00 + i); + Constants[i / 2] = BitConverter.ToUInt16(Main.savefile, Main.SaveGame.EventConst + i); } CB_Stats.SelectedIndex = 0; @@ -123,7 +120,7 @@ private void changeCustomFlag(object sender, EventArgs e) else { CHK_CustomFlag.Enabled = true; - nud.BackColor = Form1.defaultControlWhite; + nud.BackColor = Main.defaultControlWhite; CHK_CustomFlag.Checked = flags[flag]; } } @@ -178,14 +175,14 @@ private void loadSAV(object sender, string path) switch (fi.Length) { case 0x100000: // ramsav - Array.Copy(File.ReadAllBytes(path), 0x1A0FC, eventflags, 0, 0x180); + Array.Copy(File.ReadAllBytes(path), Main.SaveGame.EventFlag, eventflags, 0, 0x180); break; - case 0x65600: // xy main - Array.Copy(File.ReadAllBytes(path), 0x1A0FC - 0x5400, eventflags, 0, 0x180); + case 0x76000: // oras main + Array.Copy(File.ReadAllBytes(path), Main.SaveGame.EventFlag, eventflags, 0, 0x180); break; default: // figure it out - if (fi.Name.ToLower().Contains("ram") && fi.Length == 0x70000) - Array.Copy(ram2sav.getMAIN(File.ReadAllBytes(path)), 0x1A0FC - 0x5400, eventflags, 0, 0x180); + if (fi.Name.ToLower().Contains("ram") && fi.Length == 0x80000) + Array.Copy(ram2sav.getMAIN(File.ReadAllBytes(path)), Main.SaveGame.EventFlag, eventflags, 0, 0x180); else { Util.Error("Invalid SAV Size", String.Format("File Size: 0x{1} ({0} bytes)", fi.Length, fi.Length.ToString("X5")), "File Loaded: " + path); return; } break; diff --git a/SAV/SAV_HallOfFame.cs b/SAV/SAV_HallOfFame.cs index 6d67c413e..c719f1c5b 100644 --- a/SAV/SAV_HallOfFame.cs +++ b/SAV/SAV_HallOfFame.cs @@ -7,16 +7,13 @@ namespace PKHeX { public partial class SAV_HallOfFame : Form { - public SAV_HallOfFame(Form1 frm1) + public SAV_HallOfFame() { InitializeComponent(); - Util.TranslateInterface(this, Form1.curlanguage); - m_parent = frm1; - Array.Copy(m_parent.savefile, sav, 0x100000); - savindex = m_parent.savindex; - shiftval = savindex * 0x7F000; - if (m_parent.savegame_oras) data_offset = 0x1F200; - Array.Copy(sav, shiftval + data_offset, data, 0, data.Length); //Copy HoF section of save into Data + Util.TranslateInterface(this, Main.curlanguage); + sav = (byte[])Main.savefile.Clone(); + + Array.Copy(sav, Main.SaveGame.HoF, data, 0, data.Length); //Copy HoF section of save into Data Setup(); editor_spec = new object[]{ GB_OT, @@ -51,15 +48,10 @@ public SAV_HallOfFame(Form1 frm1) catch (Exception e) { Util.Alert("Font loading failed...", e.ToString()); } editing = true; } - Form1 m_parent; public byte[] sav = new byte[0x100000]; - public int savindex; int shiftval; public bool editing; - private int data_offset = 0x1E800; - private string[] types = Form1.types; - private string[] forms = Form1.forms; - private string[] gendersymbols = Form1.gendersymbols; + private string[] gendersymbols = Main.gendersymbols; private byte[] data = new byte[0x1B40]; private object[] editor_spec; @@ -75,7 +67,7 @@ private void Setup() #region Species { - var species_list = Util.getCBList(Form1.specieslist, null); + var species_list = Util.getCBList(Main.specieslist, null); species_list.RemoveAt(0); // Remove 0th Entry CB_Species.DisplayMember = "Text"; CB_Species.ValueMember = "Value"; @@ -87,17 +79,17 @@ private void Setup() CB_Move1.DisplayMember = CB_Move2.DisplayMember = CB_Move3.DisplayMember = CB_Move4.DisplayMember = "Text"; CB_Move1.ValueMember = CB_Move2.ValueMember = CB_Move3.ValueMember = CB_Move4.ValueMember = "Value"; - CB_Move1.DataSource = new BindingSource(m_parent.CB_Move1.DataSource, null); - CB_Move2.DataSource = new BindingSource(m_parent.CB_Move1.DataSource, null); - CB_Move3.DataSource = new BindingSource(m_parent.CB_Move1.DataSource, null); - CB_Move4.DataSource = new BindingSource(m_parent.CB_Move1.DataSource, null); + CB_Move1.DataSource = new BindingSource(Main.MoveDataSource, null); + CB_Move2.DataSource = new BindingSource(Main.MoveDataSource, null); + CB_Move3.DataSource = new BindingSource(Main.MoveDataSource, null); + CB_Move4.DataSource = new BindingSource(Main.MoveDataSource, null); } #endregion #region Items { CB_HeldItem.DisplayMember = "Text"; CB_HeldItem.ValueMember = "Value"; - CB_HeldItem.DataSource = new BindingSource(m_parent.CB_HeldItem.DataSource, null); + CB_HeldItem.DataSource = new BindingSource(Main.ItemDataSource, null); } #endregion } @@ -107,7 +99,7 @@ private void B_Cancel_Click(object sender, EventArgs e) } private void B_Close_Click(object sender, EventArgs e) { - Array.Copy(data, 0, m_parent.savefile, shiftval + data_offset, data.Length); + Array.Copy(data, 0, Main.savefile, Main.SaveGame.HoF, data.Length); Close(); } private void displayEntry(object sender, EventArgs e) @@ -172,14 +164,14 @@ private void displayEntry(object sender, EventArgs e) string shinystr = (shiny == 1) ? "Yes" : "No"; s += "Name: " + nickname; - s += " (" + Form1.specieslist[species] + " - " + genderstr + ")" + Environment.NewLine; + s += " (" + Main.specieslist[species] + " - " + genderstr + ")" + Environment.NewLine; s += "Level: " + level + Environment.NewLine; s += "Shiny: " + shinystr + Environment.NewLine; - s += "Held Item: " + Form1.itemlist[helditem] + Environment.NewLine; - s += "Move 1: " + Form1.movelist[move1] + Environment.NewLine; - s += "Move 2: " + Form1.movelist[move2] + Environment.NewLine; - s += "Move 3: " + Form1.movelist[move3] + Environment.NewLine; - s += "Move 4: " + Form1.movelist[move4] + Environment.NewLine; + s += "Held Item: " + Main.itemlist[helditem] + Environment.NewLine; + s += "Move 1: " + Main.movelist[move1] + Environment.NewLine; + s += "Move 2: " + Main.movelist[move2] + Environment.NewLine; + s += "Move 3: " + Main.movelist[move3] + Environment.NewLine; + s += "Move 4: " + Main.movelist[move4] + Environment.NewLine; s += "OT: " + OTname + " (" + TID + "/" + SID + ")" + Environment.NewLine; s += Environment.NewLine; @@ -240,7 +232,7 @@ private void NUP_PartyIndex_ValueChanged(object sender, EventArgs e) CHK_Nicknamed.Checked = nick == 1; - m_parent.setForms(species, CB_Form); + Main.setForms(species, CB_Form); CB_Form.SelectedIndex = (int)form; setGenderLabel((int)gender); updateNickname(sender, e); @@ -360,7 +352,7 @@ private void updateNickname(object sender, EventArgs e) else { // get language - string l = Form1.curlanguage; + string l = Main.curlanguage; TB_Nickname.Text = Util.getStringList("Species", l)[species]; } } @@ -371,7 +363,7 @@ private void updateNickname(object sender, EventArgs e) private void updateSpecies(object sender, EventArgs e) { int species = Util.getIndex(CB_Species); - m_parent.setForms(species, CB_Form); + Main.setForms(species, CB_Form); updateNickname(null, null); } private void updateShiny(object sender, EventArgs e) @@ -449,7 +441,7 @@ private void changeNickname(object sender, MouseEventArgs e) { TextBox tb = (!(sender is TextBox)) ? TB_Nickname : (sender as TextBox); // Special Character Form - if (ModifierKeys == Keys.Control && !Form1.specialChars) + if (ModifierKeys == Keys.Control && !Main.specialChars) (new f2_Text(tb)).Show(); } } diff --git a/SAV/SAV_Inventory.cs b/SAV/SAV_Inventory.cs index cbd1b67ef..d54e450be 100644 --- a/SAV/SAV_Inventory.cs +++ b/SAV/SAV_Inventory.cs @@ -6,25 +6,11 @@ namespace PKHeX { public partial class SAV_Inventory : Form { - public SAV_Inventory(Form1 frm1) + public SAV_Inventory() { InitializeComponent(); - Util.TranslateInterface(this, Form1.curlanguage); - m_parent = frm1; - Array.Copy(m_parent.savefile, sav, 0x100000); - savindex = m_parent.savindex; - shiftval = savindex * 0x7F000; - if (m_parent.savegame_oras) - { - bagoffsets = new[] - { - 0x05800, - 0x05E40, - 0x05FC0, - 0x06170, - 0x06270, - }; - } + Util.TranslateInterface(this, Main.curlanguage); + sav = (byte[])Main.savefile.Clone(); getListItems(); getListKeyItems(); @@ -36,15 +22,13 @@ public SAV_Inventory(Form1 frm1) popItems(); - B_DisplayItems.Text = Form1.itempouch[0]; - B_DisplayMedicine.Text = Form1.itempouch[1]; - B_DisplayTMHM.Text = Form1.itempouch[2]; - B_DisplayBerries.Text = Form1.itempouch[3]; - B_DisplayKeyItems.Text = Form1.itempouch[4]; + B_DisplayItems.Text = Main.itempouch[0]; + B_DisplayMedicine.Text = Main.itempouch[1]; + B_DisplayTMHM.Text = Main.itempouch[2]; + B_DisplayBerries.Text = Main.itempouch[3]; + B_DisplayKeyItems.Text = Main.itempouch[4]; } - Form1 m_parent; - public byte[] sav = new byte[0x100000]; - public int savindex; int shiftval; + public byte[] sav; public string[] item_val; public string[] keyitem_val; @@ -52,46 +36,38 @@ public SAV_Inventory(Form1 frm1) public string[] medicine_val; public string[] berries_val; - public int[] bagoffsets = - { - 0x05800, - 0x05E40, - 0x05FC0, - 0x06168, - 0x06268, - }; // Initialize String Tables private void getListItems() { - ushort[] itemlist = (m_parent.savegame_oras) ? Legal.Pouch_Items_ORAS : Legal.Pouch_Items_XY; + ushort[] itemlist = (Main.SaveGame.ORAS) ? Legal.Pouch_Items_ORAS : Legal.Pouch_Items_XY; item_val = new string[itemlist.Length]; for (int i = 0; i < itemlist.Length; i++) - item_val[i] = Form1.itemlist[itemlist[i]]; + item_val[i] = Main.itemlist[itemlist[i]]; Array.Sort(item_val); } private void getListKeyItems() { - ushort[] itemlist = (m_parent.savegame_oras) ? Legal.Pouch_Key_ORAS : Legal.Pouch_Key_XY; + ushort[] itemlist = (Main.SaveGame.ORAS) ? Legal.Pouch_Key_ORAS : Legal.Pouch_Key_XY; keyitem_val = new string[itemlist.Length]; for (int i = 0; i < itemlist.Length; i++) - keyitem_val[i] = Form1.itemlist[itemlist[i]]; + keyitem_val[i] = Main.itemlist[itemlist[i]]; Array.Sort(keyitem_val); } private void getListTMHM() { - ushort[] itemlist = (m_parent.savegame_oras) ? Legal.Pouch_TMHM_ORAS : Legal.Pouch_TMHM_XY; + ushort[] itemlist = (Main.SaveGame.ORAS) ? Legal.Pouch_TMHM_ORAS : Legal.Pouch_TMHM_XY; tmhm_val = new string[itemlist.Length]; for (int i = 0; i < itemlist.Length; i++) - tmhm_val[i] = Form1.itemlist[itemlist[i]]; + tmhm_val[i] = Main.itemlist[itemlist[i]]; // Array.Sort(tmhm_val); Already sorted, keep HMs last. } private void getListMedicine() { - ushort[] itemlist = (m_parent.savegame_oras) ? Legal.Pouch_Medicine_ORAS : Legal.Pouch_Medicine_XY; + ushort[] itemlist = (Main.SaveGame.ORAS) ? Legal.Pouch_Medicine_ORAS : Legal.Pouch_Medicine_XY; medicine_val = new string[itemlist.Length]; for (int i = 0; i < itemlist.Length; i++) - medicine_val[i] = Form1.itemlist[itemlist[i]]; + medicine_val[i] = Main.itemlist[itemlist[i]]; Array.Sort(medicine_val); } private void getListBerries() @@ -99,34 +75,34 @@ private void getListBerries() ushort[] itemlist = Legal.Pouch_Berry_XY; berries_val = new string[itemlist.Length]; for (int i = 0; i < itemlist.Length; i++) - berries_val[i] = Form1.itemlist[itemlist[i]]; + berries_val[i] = Main.itemlist[itemlist[i]]; Array.Sort(berries_val); } // Populate DataGrid private void popItems() { - int offset = bagoffsets[0] + shiftval; + int offset = Main.SaveGame.Items.HeldItem; populateList(item_val, offset, item_val.Length - 1); // max 400 } private void popKeyItems() { - int offset = bagoffsets[1] + shiftval; + int offset = Main.SaveGame.Items.KeyItem; populateList(keyitem_val, offset, keyitem_val.Length - 1); // max 96 } private void popTMHM() { - int offset = bagoffsets[2] + shiftval; + int offset = Main.SaveGame.Items.TMHM; populateList(tmhm_val, offset, tmhm_val.Length - 1); } private void popMedicine() { - int offset = bagoffsets[3] + shiftval; + int offset = Main.SaveGame.Items.Medicine; populateList(medicine_val, offset, medicine_val.Length - 1); // 64 total slots } private void popBerries() { - int offset = bagoffsets[4] + shiftval; + int offset = Main.SaveGame.Items.Berry; populateList(berries_val, offset, berries_val.Length - 1); // 102 slots } @@ -164,7 +140,7 @@ private void populateList(string[] itemarr, int offset, int itemcount) for (int i = 0; i < itemcount; i++) { int itemvalue = BitConverter.ToUInt16(sav, offset + i*4); - try { itemname = Form1.itemlist[itemvalue]; } + try { itemname = Main.itemlist[itemvalue]; } catch { Util.Error("Unknown item detected.", "Item ID: " + itemvalue, "Item is after: " + itemname); @@ -195,25 +171,15 @@ private void saveBag(object sender) { int offset = 0; if (B_DisplayItems.ForeColor == Color.Red) - { - offset = bagoffsets[0] + shiftval; - } + offset = Main.SaveGame.Items.HeldItem; else if (B_DisplayKeyItems.ForeColor == Color.Red) - { - offset = bagoffsets[1] + shiftval; - } + offset = Main.SaveGame.Items.KeyItem; else if (B_DisplayTMHM.ForeColor == Color.Red) - { - offset = bagoffsets[2] + shiftval; - } + offset = Main.SaveGame.Items.TMHM; else if (B_DisplayMedicine.ForeColor == Color.Red) - { - offset = bagoffsets[3] + shiftval; - } + offset = Main.SaveGame.Items.Medicine; else if (B_DisplayBerries.ForeColor == Color.Red) - { - offset = bagoffsets[4] + shiftval; - } + offset = Main.SaveGame.Items.Berry; // Fetch Data int itemcount = dataGridView1.Rows.Count; @@ -221,7 +187,7 @@ private void saveBag(object sender) for (int i = 0; i < itemcount; i++) { string item = dataGridView1.Rows[i].Cells[0].Value.ToString(); - int itemindex = Array.IndexOf(Form1.itemlist, item); + int itemindex = Array.IndexOf(Main.itemlist, item); int itemcnt; try { itemcnt = Convert.ToUInt16(dataGridView1.Rows[i].Cells[1].Value.ToString()); } @@ -235,29 +201,28 @@ private void saveBag(object sender) if (itemcnt == 0) itemcnt++; // No 0 count of items else if (itemcnt > 995) - itemcnt = 995; + itemcnt = 995; // cap out // Write Data into Save File - Array.Copy(BitConverter.GetBytes(itemindex), 0, sav, offset + 4 * (i - emptyslots), 2); // item # - Array.Copy(BitConverter.GetBytes(itemcnt), 0, sav, offset + 4 * (i - emptyslots) + 2, 2); // count + Array.Copy(BitConverter.GetBytes((ushort)itemindex), 0, sav, offset + 4 * (i - emptyslots), 2); // item # + Array.Copy(BitConverter.GetBytes((ushort)itemcnt), 0, sav, offset + 4 * (i - emptyslots) + 2, 2); // count } // Delete Empty Trash for (int i = itemcount - emptyslots; i < itemcount; i++) { - Array.Copy(BitConverter.GetBytes(0), 0, sav, offset + 4 * i + 0, 2); // item # - Array.Copy(BitConverter.GetBytes(0), 0, sav, offset + 4 * i + 2, 2); // count + Array.Copy(BitConverter.GetBytes((ushort)0), 0, sav, offset + 4 * i + 0, 2); // item # + Array.Copy(BitConverter.GetBytes((ushort)0), 0, sav, offset + 4 * i + 2, 2); // count } // Load New Button Color, after finished we'll load the new data. - Button btn = sender as Button; B_DisplayItems.ForeColor = B_DisplayKeyItems.ForeColor = B_DisplayTMHM.ForeColor = B_DisplayMedicine.ForeColor = - B_DisplayBerries.ForeColor = Form1.defaultControlText; + B_DisplayBerries.ForeColor = Main.defaultControlText; - btn.ForeColor = Color.Red; + (sender as Button).ForeColor = Color.Red; } private void giveAll(string[] inarray, int count) { @@ -275,7 +240,7 @@ private void B_DisplayItems_Click(object sender, EventArgs e) saveBag(sender); popItems(); if (ModifierKeys == Keys.Alt) - giveAll(item_val,995); + giveAll(item_val, 995); } private void B_DisplayKeyItems_Click(object sender, EventArgs e) { @@ -299,7 +264,7 @@ private void B_DisplayMedicine_Click(object sender, EventArgs e) saveBag(sender); popMedicine(); if (ModifierKeys == Keys.Alt) - giveAll(medicine_val,995); + giveAll(medicine_val, 995); } private void B_DisplayBerries_Click(object sender, EventArgs e) { @@ -307,7 +272,7 @@ private void B_DisplayBerries_Click(object sender, EventArgs e) saveBag(sender); popBerries(); if (ModifierKeys == Keys.Alt) - giveAll(berries_val,995); + giveAll(berries_val, 995); } private void B_Cancel_Click(object sender, EventArgs e) { @@ -316,8 +281,8 @@ private void B_Cancel_Click(object sender, EventArgs e) private void B_Save_Click(object sender, EventArgs e) { saveBag(sender); - Array.Copy(sav, m_parent.savefile, 0x100000); - m_parent.savedited = true; + Array.Copy(sav, Main.savefile, Main.savefile.Length); + Main.savedited = true; Close(); } } diff --git a/SAV/SAV_OPower.cs b/SAV/SAV_OPower.cs index 2089390b1..84cbce8b3 100644 --- a/SAV/SAV_OPower.cs +++ b/SAV/SAV_OPower.cs @@ -6,15 +6,12 @@ namespace PKHeX { public partial class SAV_OPower : Form { - public SAV_OPower(Form1 frm1) + public SAV_OPower() { - m_parent = frm1; - if (m_parent.savegame_oras) opoweroffset = 0x1C800; InitializeComponent(); - Util.TranslateInterface(this, Form1.curlanguage); + Util.TranslateInterface(this, Main.curlanguage); LoadData(); } - Form1 m_parent; private void B_Cancel_Click(object sender, EventArgs e) { @@ -25,10 +22,9 @@ private void B_Save_Click(object sender, EventArgs e) SaveData(); Close(); } - private int opoweroffset = 0x1BE00; private void LoadData() { - int o = opoweroffset + m_parent.savindex * 0x7F000; // offset + int o = Main.SaveGame.OPower; // Fill up the 17 o-powers // 1 2 3 4 5 10 use 4 bytes, everything else uses 3 @@ -53,17 +49,18 @@ private void LoadData() CB_14.SelectedIndex = getIndex(o, 3); o += 3; // 35-37 CB_15.SelectedIndex = getIndex(o, 3); o += 3; // 38-3A CB_16.SelectedIndex = getIndex(o, 3); o += 3; // 3B-3D - CB_17.SelectedIndex = getIndex(o, 3); o += 3; // 3E-40 + CB_17.SelectedIndex = getIndex(o, 3);//o += 3; // 3E-40 // Load Maxes - CHK_1.Checked = Convert.ToBoolean(m_parent.savefile[0x1BE00 + 0x00]); - CHK_2.Checked = Convert.ToBoolean(m_parent.savefile[0x1BE00 + 0x05]); - CHK_3.Checked = Convert.ToBoolean(m_parent.savefile[0x1BE00 + 0x0A]); - CHK_4.Checked = Convert.ToBoolean(m_parent.savefile[0x1BE00 + 0x0F]); - CHK_5.Checked = Convert.ToBoolean(m_parent.savefile[0x1BE00 + 0x14]); - CHK_6.Checked = Convert.ToBoolean(m_parent.savefile[0x1BE00 + 0x19]); - CHK_7.Checked = Convert.ToBoolean(m_parent.savefile[0x1BE00 + 0x26]); - CHK_8.Checked = Convert.ToBoolean(m_parent.savefile[0x1BE00 + 0x2B]); + o = Main.SaveGame.OPower; + CHK_1.Checked = Convert.ToBoolean(Main.savefile[o + 0x00]); + CHK_2.Checked = Convert.ToBoolean(Main.savefile[o + 0x05]); + CHK_3.Checked = Convert.ToBoolean(Main.savefile[o + 0x0A]); + CHK_4.Checked = Convert.ToBoolean(Main.savefile[o + 0x0F]); + CHK_5.Checked = Convert.ToBoolean(Main.savefile[o + 0x14]); + CHK_6.Checked = Convert.ToBoolean(Main.savefile[o + 0x19]); + CHK_7.Checked = Convert.ToBoolean(Main.savefile[o + 0x26]); + CHK_8.Checked = Convert.ToBoolean(Main.savefile[o + 0x2B]); } private void SaveData() { @@ -79,7 +76,7 @@ private void SaveData() 0x27, 0x2C,0x2F,0x32,0x35,0x38,0x3B,0x3E, }; - int o = opoweroffset + m_parent.savindex * 0x7F000; // offset + int o = Main.SaveGame.OPower; // offset for (int i = 0; i < cba.Length; i++) { @@ -88,19 +85,19 @@ private void SaveData() { data[c] = 1; } - Array.Copy(data, 0, m_parent.savefile, o + offsets[i], data.Length); + Array.Copy(data, 0, Main.savefile, o + offsets[i], data.Length); } // Save Maxes - m_parent.savefile[m_parent.savindex * 0x7F000 + opoweroffset + 0x00] = Convert.ToByte(CHK_1.Checked); - m_parent.savefile[m_parent.savindex * 0x7F000 + opoweroffset + 0x05] = Convert.ToByte(CHK_2.Checked); - m_parent.savefile[m_parent.savindex * 0x7F000 + opoweroffset + 0x0A] = Convert.ToByte(CHK_3.Checked); - m_parent.savefile[m_parent.savindex * 0x7F000 + opoweroffset + 0x0F] = Convert.ToByte(CHK_4.Checked); - m_parent.savefile[m_parent.savindex * 0x7F000 + opoweroffset + 0x14] = Convert.ToByte(CHK_5.Checked); - m_parent.savefile[m_parent.savindex * 0x7F000 + opoweroffset + 0x19] = Convert.ToByte(CHK_6.Checked); - m_parent.savefile[m_parent.savindex * 0x7F000 + opoweroffset + 0x26] = Convert.ToByte(CHK_7.Checked); - m_parent.savefile[m_parent.savindex * 0x7F000 + opoweroffset + 0x2B] = Convert.ToByte(CHK_8.Checked); + Main.savefile[o + 0x00] = Convert.ToByte(CHK_1.Checked); + Main.savefile[o + 0x05] = Convert.ToByte(CHK_2.Checked); + Main.savefile[o + 0x0A] = Convert.ToByte(CHK_3.Checked); + Main.savefile[o + 0x0F] = Convert.ToByte(CHK_4.Checked); + Main.savefile[o + 0x14] = Convert.ToByte(CHK_5.Checked); + Main.savefile[o + 0x19] = Convert.ToByte(CHK_6.Checked); + Main.savefile[o + 0x26] = Convert.ToByte(CHK_7.Checked); + Main.savefile[o + 0x2B] = Convert.ToByte(CHK_8.Checked); } private int getIndex(int o, int l) { @@ -111,7 +108,7 @@ private int getIndex(int o, int l) byte[] _4 = { 01, 01, 01, 01, }; byte[] data = new byte[4]; - Array.Copy(m_parent.savefile, o, data, 0, l); + Array.Copy(Main.savefile, o, data, 0, l); if (data.SequenceEqual(_4)) return 4; if (data.SequenceEqual(_3)) return 3; diff --git a/SAV/SAV_PokedexORAS.cs b/SAV/SAV_PokedexORAS.cs index c22e03006..9bfa679b1 100644 --- a/SAV/SAV_PokedexORAS.cs +++ b/SAV/SAV_PokedexORAS.cs @@ -6,23 +6,18 @@ namespace PKHeX { public partial class SAV_PokedexORAS : Form { - public SAV_PokedexORAS(Form1 frm1) + public SAV_PokedexORAS() { InitializeComponent(); - Util.TranslateInterface(this, Form1.curlanguage); - m_parent = frm1; - Array.Copy(m_parent.savefile, sav, sav.Length); - sv = m_parent.savindex * 0x7F000; - dexoffset += sv; + Util.TranslateInterface(this, Main.curlanguage); + sav = (byte[])Main.savefile.Clone(); + Setup(); editing = false; LB_Species.SelectedIndex = 0; - TB_Spinda.Text = BitConverter.ToUInt32(sav, dexoffset + 0x680).ToString("X8"); + TB_Spinda.Text = BitConverter.ToUInt32(sav, Main.SaveGame.Spinda).ToString("X8"); } - private int dexoffset = 0x15000 + 0x5400; - Form1 m_parent; - public byte[] sav = new byte[0x100000]; - public int sv; + public byte[] sav; public bool[,] specbools = new bool[9, 0x60 * 8]; public bool[,] langbools = new bool[7, 0x60 * 8]; bool editing = true; @@ -35,7 +30,7 @@ private void Setup() // Fill List #region Species { - var species_list = Util.getCBList(Form1.specieslist, null); + var species_list = Util.getCBList(Main.specieslist, null); species_list.RemoveAt(0); // Remove 0th Entry CB_Species.DisplayMember = "Text"; CB_Species.ValueMember = "Value"; @@ -43,8 +38,8 @@ private void Setup() } #endregion - for (int i = 1; i < Form1.specieslist.Length; i++) - LB_Species.Items.Add(i.ToString("000") + " - " + Form1.specieslist[i]); + for (int i = 1; i < Main.specieslist.Length; i++) + LB_Species.Items.Add(i.ToString("000") + " - " + Main.specieslist[i]); getBools(); } @@ -105,7 +100,7 @@ private void loadchks() // Load Encountered Count editing = true; - MT_Count.Text = BitConverter.ToUInt16(sav, dexoffset + 0x686 + (pk - 1) * 2).ToString(); + MT_Count.Text = BitConverter.ToUInt16(sav, Main.SaveGame.EncounterCount + (pk - 1) * 2).ToString(); editing = false; } private void removedropCB(object sender, KeyEventArgs e) @@ -146,7 +141,7 @@ private void B_Save_Click(object sender, EventArgs e) saveChanges(); // Return back to the parent savefile - Array.Copy(sav, m_parent.savefile, sav.Length); + Array.Copy(sav, Main.savefile, sav.Length); Close(); } private void saveChanges() @@ -161,7 +156,7 @@ private void saveChanges() if (specbools[p, i]) sdata[i / 8] |= (byte)(1 << i % 8); - Array.Copy(sdata, 0, sav, sv + dexoffset + 0x8 + 0x60 * p, 0x60); + Array.Copy(sdata, 0, sav, Main.SaveGame.PokeDex + 0x8 + 0x60 * p, 0x60); } // Build new bool array for the Languages @@ -178,12 +173,12 @@ private void saveChanges() if (languagedata[i]) ldata[i / 8] |= (byte)(1 << i % 8); - Array.Copy(ldata, 0, sav, sv + dexoffset + 0x400, 0x27C); + Array.Copy(ldata, 0, sav, Main.SaveGame.PokeDexLanguageFlags, 0x27C); } // Store Spinda Spot uint PID = Util.getHEXval(TB_Spinda); - Array.Copy(BitConverter.GetBytes(PID), 0, sav, dexoffset + 0x680, 4); + Array.Copy(BitConverter.GetBytes(PID), 0, sav, Main.SaveGame.Spinda, 4); } private void getBools() @@ -192,7 +187,7 @@ private void getBools() for (int i = 0; i < 9; i++) { byte[] data = new byte[0x60]; - int offset = dexoffset + 0x8 + 0x60 * i; + int offset = Main.SaveGame.PokeDex + 0x8 + 0x60 * i; Array.Copy(sav, offset, data, 0, 0x60); BitArray BitRegion = new BitArray(data); for (int b = 0; b < (0x60 * 8); b++) @@ -201,7 +196,7 @@ private void getBools() // Fill Language arrays byte[] langdata = new byte[0x280]; - Array.Copy(sav, dexoffset + 0x400, langdata, 0, 0x280); + Array.Copy(sav, Main.SaveGame.PokeDexLanguageFlags, langdata, 0, 0x280); BitArray LangRegion = new BitArray(langdata); for (int b = 0; b < (721); b++) // 721 Species for (int i = 0; i < 7; i++) // 7 Languages @@ -243,12 +238,12 @@ private void B_FillDex_Click(object sender, EventArgs e) // Copy Full Dex Byte Array // Native Byte Writing for (int i = 0; i < 0x5A; i++) - sav[sv + 0x1A400 + 8 + i] = 0xFF; - sav[sv + 8 + 0x1A45A] = 0x01; + sav[Main.SaveGame.PokeDex + 8 + i] = 0xFF; + // Write remainder + sav[Main.SaveGame.PokeDex + 8 + 0x5A] = 0x01; // Midsection Writing { - // starting at 0x15068; #region Payload uint[] payload = { @@ -454,24 +449,25 @@ private void B_FillDex_Click(object sender, EventArgs e) }; #endregion for (int i = 0; i < payload.Length; i++) - Array.Copy(BitConverter.GetBytes(payload[i]), 0, sav, sv + 0x5400 + 0x15068 + 4 * i, 4); + Array.Copy(BitConverter.GetBytes(payload[i]), 0, sav, Main.SaveGame.PokeDex + 68 + 4 * i, 4); } // Language Writing for (int i = 0; i < 0x9D; i++) - Array.Copy(BitConverter.GetBytes(0xFFFFFFFF), 0, sav ,sv + 0x5400 + 0x15400 + 4 * i, 4); - Array.Copy(BitConverter.GetBytes(0x007FFFFF), 0, sav ,sv + 0x5400 + 0x15674, 4); + Array.Copy(BitConverter.GetBytes(0xFFFFFFFF), 0, sav, Main.SaveGame.PokeDexLanguageFlags + 4 * i, 4); + Array.Copy(BitConverter.GetBytes(0x007FFFFF), 0, sav, Main.SaveGame.PokeDexLanguageFlags + 4 * 0x9D, 4); // Encounter Count Writing (999*all species) for (int i = 0; i < 0x2D1; i++) - Array.Copy(BitConverter.GetBytes(999), 0, sav, sv + 0x5400 + 0x15686 + i * 2, 2); + Array.Copy(BitConverter.GetBytes(999), 0, sav, Main.SaveGame.EncounterCount + i * 2, 2); + // Turn off Italian Petlil - sav[0x1A9DF + sv] &= 0xFE; + sav[Main.SaveGame.PokeDexLanguageFlags + 0x1DF] &= 0xFE; // Forms Bool Writing for (int i = 0; i < 0x9C; i++) - sav[sv + 0x5400 + 0x15000 + 0x364 + i] = 0xFF; - sav[sv + 0x5400 + 0x15000 + 0x3FF] = 0x8F; // make sure we don't have FF because CGSE may screw up. + sav[Main.SaveGame.PokeDex + 0x364 + i] = 0xFF; + sav[Main.SaveGame.PokeDex + 0x3FF] = 0x8F; // make sure we don't have FF because CGSE may screw up. // Fetch the dex bools getBools(); @@ -483,7 +479,7 @@ private void B_FillDex_Click(object sender, EventArgs e) private void changeEncounteredCount(object sender, EventArgs e) { if (!editing) - Array.Copy(BitConverter.GetBytes(Math.Min(0xFFFF, Util.ToUInt32(MT_Count))), 0, sav, dexoffset + 0x686 + (Util.getIndex(CB_Species) - 1) * 2, 2); + Array.Copy(BitConverter.GetBytes(Math.Min(0xFFFF, Util.ToUInt32(MT_Count))), 0, sav, Main.SaveGame.EncounterCount + (Util.getIndex(CB_Species) - 1) * 2, 2); } } } diff --git a/SAV/SAV_PokedexXY.cs b/SAV/SAV_PokedexXY.cs index c681c36ef..8849205c1 100644 --- a/SAV/SAV_PokedexXY.cs +++ b/SAV/SAV_PokedexXY.cs @@ -6,21 +6,17 @@ namespace PKHeX { public partial class SAV_PokedexXY : Form { - public SAV_PokedexXY(Form1 frm1) + public SAV_PokedexXY() { InitializeComponent(); - Util.TranslateInterface(this, Form1.curlanguage); - m_parent = frm1; - Array.Copy(m_parent.savefile, sav, sav.Length); - savshift = m_parent.savindex * 0x7F000; + Util.TranslateInterface(this, Main.curlanguage); + sav = (byte[])Main.savefile.Clone(); Setup(); editing = false; LB_Species.SelectedIndex = 0; - TB_Spinda.Text = BitConverter.ToUInt32(sav, 0x1AA48 + Convert.ToInt16(m_parent.savegame_oras) * 0x38).ToString("X8"); + TB_Spinda.Text = BitConverter.ToUInt32(sav, Main.SaveGame.Spinda).ToString("X8"); } - Form1 m_parent; - public byte[] sav = new byte[0x100000]; - public int savshift; + public byte[] sav; public bool[,] specbools = new bool[10, 0x60 * 8]; public bool[,] langbools = new bool[7, 0x60 * 8]; public bool[] foreignbools = new bool[0x52 * 8]; @@ -34,7 +30,7 @@ private void Setup() // Fill List #region Species { - var species_list = Util.getCBList(Form1.specieslist, null); + var species_list = Util.getCBList(Main.specieslist, null); species_list.RemoveAt(0); // Remove 0th Entry CB_Species.DisplayMember = "Text"; CB_Species.ValueMember = "Value"; @@ -42,8 +38,8 @@ private void Setup() } #endregion - for (int i = 1; i < Form1.specieslist.Length; i++) - LB_Species.Items.Add(i.ToString("000") + " - " + Form1.specieslist[i]); + for (int i = 1; i < Main.specieslist.Length; i++) + LB_Species.Items.Add(i.ToString("000") + " - " + Main.specieslist[i]); for (int i = 722; i <= 0x300; i++) LB_Species.Items.Add(i.ToString("000") + " - ???"); @@ -167,7 +163,7 @@ private void B_Save_Click(object sender, EventArgs e) saveChanges(); // Return back to the parent savefile - Array.Copy(sav, m_parent.savefile, sav.Length); + Array.Copy(sav, Main.savefile, sav.Length); Close(); } private void saveChanges() @@ -182,7 +178,7 @@ private void saveChanges() if (specbools[p, i]) sdata[i / 8] |= (byte)(1 << i % 8); - Array.Copy(sdata, 0, sav, savshift + 0x1A408 + 0x60 * p, 0x60); + Array.Copy(sdata, 0, sav, Main.SaveGame.PokeDex + 8 + 0x60 * p, 0x60); } // Build new bool array for the Languages @@ -199,7 +195,7 @@ private void saveChanges() if (languagedata[i]) ldata[i / 8] |= (byte)(1 << i % 8); - Array.Copy(ldata, 0, sav, savshift + 0x1A7C8, 0x280); + Array.Copy(ldata, 0, sav, Main.SaveGame.PokeDexLanguageFlags, 0x280); } // Return Foreign Array @@ -208,12 +204,12 @@ private void saveChanges() for (int i = 0; i < 0x52 * 8; i++) if (foreignbools[i]) foreigndata[i / 8] |= (byte)(1 << i % 8); - Array.Copy(foreigndata, 0, sav, savshift + 0x1AA4C, 0x52); + Array.Copy(foreigndata, 0, sav, Main.SaveGame.PokeDex + 0x64C, 0x52); } // Store Spinda Spot uint PID = Util.getHEXval(TB_Spinda); - Array.Copy(BitConverter.GetBytes(PID), 0, sav, 0x1AA48 + Convert.ToInt16(m_parent.savegame_oras) * 0x38 + savshift, 4); + Array.Copy(BitConverter.GetBytes(PID), 0, sav, Main.SaveGame.Spinda, 4); } private void getBools() @@ -222,7 +218,7 @@ private void getBools() for (int i = 0; i < 0xA; i++) { byte[] data = new byte[0x60]; - Array.Copy(sav, savshift + 0x1A408 + 0x60 * i, data, 0, 0x60); + Array.Copy(sav, Main.SaveGame.PokeDex + 8 + 0x60 * i, data, 0, 0x60); BitArray BitRegion = new BitArray(data); for (int b = 0; b < (0x60 * 8); b++) specbools[i, b] = BitRegion[b]; @@ -230,7 +226,7 @@ private void getBools() // Fill Language arrays byte[] langdata = new byte[0x280]; - Array.Copy(sav, savshift + 0x1A7C8, langdata, 0, 0x280); + Array.Copy(sav, Main.SaveGame.PokeDexLanguageFlags, langdata, 0, 0x280); BitArray LangRegion = new BitArray(langdata); for (int b = 0; b < (721); b++) // 721 Species for (int i = 0; i < 7; i++) // 7 Languages @@ -239,7 +235,7 @@ private void getBools() // Fill Foreign array { byte[] foreigndata = new byte[0x52]; - Array.Copy(sav, savshift + 0x1AA4C, foreigndata, 0, 0x52); + Array.Copy(sav, Main.SaveGame.PokeDex + 0x64C, foreigndata, 0, 0x52); BitArray ForeignRegion = new BitArray(foreigndata); for (int b = 0; b < (0x52 * 8); b++) foreignbools[b] = ForeignRegion[b]; @@ -286,15 +282,15 @@ private void B_FillDex_Click(object sender, EventArgs e) byte[] fulldex = Properties.Resources.fulldex_XY; if (ModifierKeys != Keys.Control) { - Array.Copy(fulldex, 0x008, sav, savshift + 0x1A408, 0x638); + Array.Copy(fulldex, 0x008, sav, Main.SaveGame.PokeDex + 8, 0x638); } else { - Array.Copy(fulldex, 0x008, sav, savshift + 0x1A408, 0x1E0); // Copy Partitions 1-5 - Array.Copy(fulldex, 0x368, sav, savshift + 0x1A768, 0x2D8); // Copy A & language + Array.Copy(fulldex, 0x008, sav, Main.SaveGame.PokeDex + 8, 0x1E0); // Copy Partitions 1-5 + Array.Copy(fulldex, 0x368, sav, Main.SaveGame.PokeDex + 0x368, 0x2D8); // Copy A & language } // Skip the unknown sections then - Array.Copy(fulldex, 0x64C, sav, savshift + 0x1AA4C, 0x054); + Array.Copy(fulldex, 0x64C, sav, Main.SaveGame.PokeDex + 0x64C, 0x054); // Fetch the dex bools getBools(); diff --git a/SAV/SAV_Pokepuff.Designer.cs b/SAV/SAV_Pokepuff.Designer.cs index 3ddaa04fc..43a795727 100644 --- a/SAV/SAV_Pokepuff.Designer.cs +++ b/SAV/SAV_Pokepuff.Designer.cs @@ -29,7 +29,7 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SAV_Pokepuff)); - this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.dgv = new System.Windows.Forms.DataGridView(); this.B_Save = new System.Windows.Forms.Button(); this.B_Cancel = new System.Windows.Forms.Button(); this.B_All = new System.Windows.Forms.Button(); @@ -37,31 +37,31 @@ private void InitializeComponent() this.B_None = new System.Windows.Forms.Button(); this.L_Count = new System.Windows.Forms.Label(); this.MT_CNT = new System.Windows.Forms.MaskedTextBox(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.dgv)).BeginInit(); this.SuspendLayout(); // - // dataGridView1 + // dgv // - this.dataGridView1.AllowUserToAddRows = false; - this.dataGridView1.AllowUserToDeleteRows = false; - this.dataGridView1.AllowUserToResizeColumns = false; - this.dataGridView1.AllowUserToResizeRows = false; - this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom))); - this.dataGridView1.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; - this.dataGridView1.CellBorderStyle = System.Windows.Forms.DataGridViewCellBorderStyle.None; - this.dataGridView1.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single; - this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView1.ColumnHeadersVisible = false; - this.dataGridView1.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter; - this.dataGridView1.Location = new System.Drawing.Point(12, 43); - this.dataGridView1.MultiSelect = false; - this.dataGridView1.Name = "dataGridView1"; - this.dataGridView1.RowHeadersVisible = false; - this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.CellSelect; - this.dataGridView1.ShowEditingIcon = false; - this.dataGridView1.Size = new System.Drawing.Size(200, 186); - this.dataGridView1.TabIndex = 11; - this.dataGridView1.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dropclick); + this.dgv.AllowUserToAddRows = false; + this.dgv.AllowUserToDeleteRows = false; + this.dgv.AllowUserToResizeColumns = false; + this.dgv.AllowUserToResizeRows = false; + this.dgv.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom))); + this.dgv.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dgv.CellBorderStyle = System.Windows.Forms.DataGridViewCellBorderStyle.None; + this.dgv.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single; + this.dgv.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dgv.ColumnHeadersVisible = false; + this.dgv.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter; + this.dgv.Location = new System.Drawing.Point(12, 43); + this.dgv.MultiSelect = false; + this.dgv.Name = "dgv"; + this.dgv.RowHeadersVisible = false; + this.dgv.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.CellSelect; + this.dgv.ShowEditingIcon = false; + this.dgv.Size = new System.Drawing.Size(200, 186); + this.dgv.TabIndex = 11; + this.dgv.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dropclick); // // B_Save // @@ -148,7 +148,7 @@ private void InitializeComponent() this.Controls.Add(this.B_All); this.Controls.Add(this.B_Cancel); this.Controls.Add(this.B_Save); - this.Controls.Add(this.dataGridView1); + this.Controls.Add(this.dgv); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; this.MaximumSize = new System.Drawing.Size(240, 750); @@ -157,7 +157,7 @@ private void InitializeComponent() this.Name = "SAV_Pokepuff"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "‎Poké Puffs Editor"; - ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.dgv)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -165,7 +165,7 @@ private void InitializeComponent() #endregion - private System.Windows.Forms.DataGridView dataGridView1; + private System.Windows.Forms.DataGridView dgv; private System.Windows.Forms.Button B_Save; private System.Windows.Forms.Button B_Cancel; private System.Windows.Forms.Button B_All; diff --git a/SAV/SAV_Pokepuff.cs b/SAV/SAV_Pokepuff.cs index d99ef061f..d58f171b2 100644 --- a/SAV/SAV_Pokepuff.cs +++ b/SAV/SAV_Pokepuff.cs @@ -5,14 +5,13 @@ namespace PKHeX { public partial class SAV_Pokepuff : Form { - public SAV_Pokepuff(Form1 frm1) + public SAV_Pokepuff() { InitializeComponent(); - Util.TranslateInterface(this, Form1.curlanguage); - m_parent = frm1; - Array.Copy(m_parent.savefile, sav, 0x100000); - pfa = Form1.puffs; - savindex = m_parent.savindex; + Util.TranslateInterface(this, Main.curlanguage); + sav = (byte[])Main.savefile.Clone(); + + pfa = Main.puffs; pfa[0] = "---"; Setup(); @@ -20,9 +19,7 @@ public SAV_Pokepuff(Form1 frm1) new ToolTip().SetToolTip(B_All, "Hold CTRL to give Deluxe instead of Supreme."); } - private Form1 m_parent; - public byte[] sav = new byte[0x100000]; - public int savindex; + public byte[] sav; private string[] pfa = { "Empty", @@ -34,8 +31,8 @@ public SAV_Pokepuff(Form1 frm1) }; private void Setup() { - dataGridView1.Rows.Clear(); - dataGridView1.Columns.Clear(); + dgv.Rows.Clear(); + dgv.Columns.Clear(); DataGridViewColumn dgvIndex = new DataGridViewTextBoxColumn(); { @@ -57,24 +54,21 @@ private void Setup() dgvPuff.Width = 135; dgvPuff.FlatStyle = FlatStyle.Flat; } - dataGridView1.Columns.Add(dgvIndex); - dataGridView1.Columns.Add(dgvPuff); + dgv.Columns.Add(dgvIndex); + dgv.Columns.Add(dgvPuff); - dataGridView1.Rows.Add(100); - int offset = 0x5400 + 0x7F000*savindex; + dgv.Rows.Add(100); for (int i = 0; i < 100; i++) { - dataGridView1.Rows[i].Cells[0].Value = (i + 1).ToString(); - dataGridView1.Rows[i].Cells[1].Value = pfa[sav[offset + i]]; + dgv.Rows[i].Cells[0].Value = (i + 1).ToString(); + dgv.Rows[i].Cells[1].Value = pfa[sav[Main.SaveGame.Puff + i]]; } - MT_CNT.Text = BitConverter.ToUInt32(sav, offset + 100).ToString("0"); + MT_CNT.Text = BitConverter.ToUInt32(sav, Main.SaveGame.Puff + 100).ToString("0"); } private void dropclick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex != 1) return; - - ComboBox comboBox = (ComboBox) dataGridView1.EditingControl; - comboBox.DroppedDown = true; + ((ComboBox)(sender as DataGridView).EditingControl).DroppedDown = true; } private void B_Cancel_Click(object sender, EventArgs e) @@ -94,7 +88,7 @@ private void B_All_Click(object sender, EventArgs e) for (int i = 0; i < 100; i++) newpuffs[i] = (byte) (Util.rnd32()%basemod + basepuff); - Array.Copy(newpuffs, 0, sav, 0x5400 + savindex*0x7F000, 100); + Array.Copy(newpuffs, 0, sav, Main.SaveGame.Puff, 100); Setup(); } private void B_None_Click(object sender, EventArgs e) @@ -105,7 +99,7 @@ private void B_None_Click(object sender, EventArgs e) newpuffs[2] = 3; newpuffs[3] = 4; newpuffs[4] = 5; - Array.Copy(newpuffs, 0, sav, 0x5400 + savindex*0x7F000, 100); + Array.Copy(newpuffs, 0, sav, Main.SaveGame.Puff, 100); Setup(); } private void B_Sort_Click(object sender, EventArgs e) @@ -115,7 +109,7 @@ private void B_Sort_Click(object sender, EventArgs e) { for (int i = 0; i < 100; i++) { - string puff = dataGridView1.Rows[i].Cells[1].Value.ToString(); + string puff = dgv.Rows[i].Cells[1].Value.ToString(); puffarray[i] = (byte) Array.IndexOf(pfa, puff); } Array.Sort(puffarray); @@ -126,7 +120,7 @@ private void B_Sort_Click(object sender, EventArgs e) int count = 0; for (int i = 0; i < 100; i++) { - string puff = dataGridView1.Rows[i].Cells[1].Value.ToString(); + string puff = dgv.Rows[i].Cells[1].Value.ToString(); byte puffval = (byte) Array.IndexOf(pfa, puff); if (puffval == 0) continue; puffarray[count] = puffval; @@ -136,7 +130,7 @@ private void B_Sort_Click(object sender, EventArgs e) Array.Sort(puffarray); Array.Resize(ref puffarray, 100); } - Array.Copy(puffarray, 0, sav, 0x5400 + savindex*0x7F000, 100); + Array.Copy(puffarray, 0, sav, Main.SaveGame.Puff, 100); Setup(); } private void B_Save_Click(object sender, EventArgs e) @@ -145,7 +139,7 @@ private void B_Save_Click(object sender, EventArgs e) int emptyslots = 0; for (int i = 0; i < 100; i++) { - string puff = dataGridView1.Rows[i].Cells[1].Value.ToString(); + string puff = dgv.Rows[i].Cells[1].Value.ToString(); if (Array.IndexOf(pfa, puff) == 0) { emptyslots++; @@ -154,9 +148,9 @@ private void B_Save_Click(object sender, EventArgs e) puffarray[i - emptyslots] = (byte) Array.IndexOf(pfa, puff); } - Array.Copy(puffarray, 0, sav, 0x5400 + savindex*0x7F000, 100); - Array.Copy(sav, m_parent.savefile, 0x100000); - m_parent.savedited = true; + Array.Copy(puffarray, 0, sav, Main.SaveGame.Puff, 100); + Array.Copy(sav, Main.savefile, sav.Length); + Main.savedited = true; Close(); } } diff --git a/SAV/SAV_SecretBase.cs b/SAV/SAV_SecretBase.cs index b852e0484..f5faf0d02 100644 --- a/SAV/SAV_SecretBase.cs +++ b/SAV/SAV_SecretBase.cs @@ -6,13 +6,12 @@ namespace PKHeX { public partial class SAV_SecretBase : Form { - public SAV_SecretBase(Form1 frm1) + public SAV_SecretBase() { InitializeComponent(); - Util.TranslateInterface(this, Form1.curlanguage); - m_parent = frm1; - Array.Copy(m_parent.savefile, sav, 0x100000); - abilitylist = Form1.abilitylist; + Util.TranslateInterface(this, Main.curlanguage); + sav = (byte[])Main.savefile.Clone(); + abilitylist = Main.abilitylist; setupComboBoxes(); popFavorite(); @@ -20,14 +19,11 @@ public SAV_SecretBase(Form1 frm1) LB_Favorite.SelectedIndex = 0; // MT_Flags.Text = BitConverter.ToUInt16(sav, 0x24800 + 0x140).ToString(); PSS Stat transmitted - MT_Flags.Text = BitConverter.ToUInt32(sav, 0x2942C).ToString(); // read counter + MT_Flags.Text = BitConverter.ToUInt32(sav, Main.SaveGame.SecretBase + 0x62C).ToString(); // read counter B_SAV2FAV(null, null); } - Form1 m_parent; - public byte[] sav = new byte[0x100000]; + public byte[] sav; public bool editing; - private const int sv = 0; - private const int fav_offset = 0x23A00; private bool loading = true; public static string[] abilitylist = { }; @@ -37,32 +33,32 @@ private void setupComboBoxes() { CB_Ball.DisplayMember = "Text"; CB_Ball.ValueMember = "Value"; - CB_Ball.DataSource = new BindingSource(m_parent.CB_Ball.DataSource, null); + CB_Ball.DataSource = new BindingSource(Main.BallDataSource, null); } { CB_HeldItem.DisplayMember = "Text"; CB_HeldItem.ValueMember = "Value"; - CB_HeldItem.DataSource = new BindingSource(m_parent.CB_HeldItem.DataSource, null); + CB_HeldItem.DataSource = new BindingSource(Main.ItemDataSource, null); } { CB_Species.DisplayMember = "Text"; CB_Species.ValueMember = "Value"; - CB_Species.DataSource = new BindingSource(m_parent.CB_Species.DataSource, null); + CB_Species.DataSource = new BindingSource(Main.SpeciesDataSource, null); } { CB_Nature.DisplayMember = "Text"; CB_Nature.ValueMember = "Value"; - CB_Nature.DataSource = new BindingSource(m_parent.CB_Nature.DataSource, null); + CB_Nature.DataSource = new BindingSource(Main.NatureDataSource, null); } #region Moves { CB_Move1.DisplayMember = CB_Move2.DisplayMember = CB_Move3.DisplayMember = CB_Move4.DisplayMember = "Text"; CB_Move1.ValueMember = CB_Move2.ValueMember = CB_Move3.ValueMember = CB_Move4.ValueMember = "Value"; - CB_Move1.DataSource = new BindingSource(m_parent.CB_Move1.DataSource, null); - CB_Move2.DataSource = new BindingSource(m_parent.CB_Move1.DataSource, null); - CB_Move3.DataSource = new BindingSource(m_parent.CB_Move1.DataSource, null); - CB_Move4.DataSource = new BindingSource(m_parent.CB_Move1.DataSource, null); + CB_Move1.DataSource = new BindingSource(Main.MoveDataSource, null); + CB_Move2.DataSource = new BindingSource(Main.MoveDataSource, null); + CB_Move3.DataSource = new BindingSource(Main.MoveDataSource, null); + CB_Move4.DataSource = new BindingSource(Main.MoveDataSource, null); } #endregion } @@ -72,13 +68,13 @@ private void popFavorite() { LB_Favorite.Items.Clear(); - const int playeroff = fav_offset + 0x5400 + 0x326; - const int favoff = fav_offset + 0x5400 + 0x63A; - string OT = Util.TrimFromZero(Encoding.Unicode.GetString(sav, sv + playeroff + 0x218, 0x1A)); + int playeroff = Main.SaveGame.SecretBase + 0x326; + int favoff = Main.SaveGame.SecretBase + 0x63A; + string OT = Util.TrimFromZero(Encoding.Unicode.GetString(sav, playeroff + 0x218, 0x1A)); LB_Favorite.Items.Add("* " + OT); for (int i = 0; i < 30; i++) { - string BaseTrainer = Util.TrimFromZero(Encoding.Unicode.GetString(sav, sv + favoff + i * 0x3E0 + 0x218, 0x1A)); + string BaseTrainer = Util.TrimFromZero(Encoding.Unicode.GetString(sav, favoff + i * 0x3E0 + 0x218, 0x1A)); if (BaseTrainer.Length < 1 || BaseTrainer[0] == '\0') BaseTrainer = "Empty"; LB_Favorite.Items.Add(i + " " + BaseTrainer); @@ -89,24 +85,24 @@ private void B_SAV2FAV(object sender, EventArgs e) loading = true; int index = LB_Favorite.SelectedIndex; if (index < 0) return; - int offset = fav_offset + 0x5400 + 0x25A; + int offset = Main.SaveGame.SecretBase + 0x25A; // Base Offset Changing - if (index == 0) offset = fav_offset + 0x5400 + 0x326; + if (index == 0) offset = Main.SaveGame.SecretBase + 0x326; else offset += 0x3E0 * index; - string TrainerName = Util.TrimFromZero(Encoding.Unicode.GetString(sav, sv + offset + 0x218, 0x1A)); + string TrainerName = Util.TrimFromZero(Encoding.Unicode.GetString(sav, offset + 0x218, 0x1A)); TB_FOT.Text = TrainerName; - TB_FT1.Text = Util.TrimFromZero(Encoding.Unicode.GetString(sav, sv + offset + 0x232 + 0x22 * 0, 0x22)); - TB_FT2.Text = Util.TrimFromZero(Encoding.Unicode.GetString(sav, sv + offset + 0x232 + 0x22 * 1, 0x22)); + TB_FT1.Text = Util.TrimFromZero(Encoding.Unicode.GetString(sav, offset + 0x232 + 0x22 * 0, 0x22)); + TB_FT2.Text = Util.TrimFromZero(Encoding.Unicode.GetString(sav, offset + 0x232 + 0x22 * 1, 0x22)); - string saying1 = Util.TrimFromZero(Encoding.Unicode.GetString(sav, sv + offset + 0x276 + 0x22 * 0, 0x22)); - string saying2 = Util.TrimFromZero(Encoding.Unicode.GetString(sav, sv + offset + 0x276 + 0x22 * 1, 0x22)); - string saying3 = Util.TrimFromZero(Encoding.Unicode.GetString(sav, sv + offset + 0x276 + 0x22 * 2, 0x22)); - string saying4 = Util.TrimFromZero(Encoding.Unicode.GetString(sav, sv + offset + 0x276 + 0x22 * 3, 0x22)); + string saying1 = Util.TrimFromZero(Encoding.Unicode.GetString(sav, offset + 0x276 + 0x22 * 0, 0x22)); + string saying2 = Util.TrimFromZero(Encoding.Unicode.GetString(sav, offset + 0x276 + 0x22 * 1, 0x22)); + string saying3 = Util.TrimFromZero(Encoding.Unicode.GetString(sav, offset + 0x276 + 0x22 * 2, 0x22)); + string saying4 = Util.TrimFromZero(Encoding.Unicode.GetString(sav, offset + 0x276 + 0x22 * 3, 0x22)); - int baseloc = BitConverter.ToInt16(sav, sv + offset); + int baseloc = BitConverter.ToInt16(sav, offset); NUD_FBaseLocation.Value = baseloc; TB_FSay1.Text = saying1; TB_FSay2.Text = saying2; TB_FSay3.Text = saying3; TB_FSay4.Text = saying4; @@ -115,7 +111,7 @@ private void B_SAV2FAV(object sender, EventArgs e) objdata = new byte[25, 12]; for (int i = 0; i < 25; i++) for (int z = 0; z < 12; z++) - objdata[i, z] = sav[sv + offset + 2 + 12 * i + z]; + objdata[i, z] = sav[offset + 2 + 12 * i + z]; NUD_FObject.Value = 1; // Trigger Update changeObjectIndex(null, null); @@ -126,7 +122,7 @@ private void B_SAV2FAV(object sender, EventArgs e) if (index > 0) for (int i = 0; i < 3; i++) for (int z = 0; z < 0x34; z++) - pkmdata[i, z] = sav[sv + offset + 0x32E + 0x34 * i + z]; + pkmdata[i, z] = sav[offset + 0x32E + 0x34 * i + z]; NUD_FPKM.Value = 1; changeFavPKM(null, null); // Trigger Update @@ -146,54 +142,54 @@ private void B_FAV2SAV(object sender, EventArgs e) if (LB_Favorite.Items[index].ToString().Substring(LB_Favorite.Items[index].ToString().Length - 5, 5) == "Empty") { Util.Error("Sorry, no overwriting an empty base with someone else's."); return; } if (index < 0) return; - int offset = fav_offset + 0x5400 + 0x25A; + int offset = Main.SaveGame.SecretBase + 0x25A; // Base Offset Changing if (index == 0) - offset = fav_offset + 0x5400 + 0x326; + offset = Main.SaveGame.SecretBase + 0x326; else offset += 0x3E0 * index; string TrainerName = TB_FOT.Text; byte[] tr = Encoding.Unicode.GetBytes(TrainerName); - Array.Resize(ref tr, 0x22); Array.Copy(tr, 0, sav, sv + offset + 0x218, 0x1A); + Array.Resize(ref tr, 0x22); Array.Copy(tr, 0, sav, offset + 0x218, 0x1A); string team1 = TB_FT1.Text; string team2 = TB_FT2.Text; byte[] t1 = Encoding.Unicode.GetBytes(team1); - Array.Resize(ref t1, 0x22); Array.Copy(t1, 0, sav, sv + offset + 0x232 + 0x22 * 0, 0x22); + Array.Resize(ref t1, 0x22); Array.Copy(t1, 0, sav, offset + 0x232 + 0x22 * 0, 0x22); byte[] t2 = Encoding.Unicode.GetBytes(team2); - Array.Resize(ref t2, 0x22); Array.Copy(t2, 0, sav, sv + offset + 0x232 + 0x22 * 1, 0x22); + Array.Resize(ref t2, 0x22); Array.Copy(t2, 0, sav, offset + 0x232 + 0x22 * 1, 0x22); string saying1 = TB_FSay1.Text; string saying2 = TB_FSay2.Text; string saying3 = TB_FSay3.Text; string saying4 = TB_FSay4.Text; byte[] s1 = Encoding.Unicode.GetBytes(saying1); - Array.Resize(ref s1, 0x22); Array.Copy(s1, 0, sav, sv + offset + 0x276 + 0x22 * 0, 0x22); + Array.Resize(ref s1, 0x22); Array.Copy(s1, 0, sav, offset + 0x276 + 0x22 * 0, 0x22); byte[] s2 = Encoding.Unicode.GetBytes(saying2); - Array.Resize(ref s2, 0x22); Array.Copy(s2, 0, sav, sv + offset + 0x276 + 0x22 * 1, 0x22); + Array.Resize(ref s2, 0x22); Array.Copy(s2, 0, sav, offset + 0x276 + 0x22 * 1, 0x22); byte[] s3 = Encoding.Unicode.GetBytes(saying3); - Array.Resize(ref s3, 0x22); Array.Copy(s3, 0, sav, sv + offset + 0x276 + 0x22 * 2, 0x22); + Array.Resize(ref s3, 0x22); Array.Copy(s3, 0, sav, offset + 0x276 + 0x22 * 2, 0x22); byte[] s4 = Encoding.Unicode.GetBytes(saying4); - Array.Resize(ref s4, 0x22); Array.Copy(s4, 0, sav, sv + offset + 0x276 + 0x22 * 3, 0x22); + Array.Resize(ref s4, 0x22); Array.Copy(s4, 0, sav, offset + 0x276 + 0x22 * 3, 0x22); int baseloc = (int)NUD_FBaseLocation.Value; if (baseloc < 3) baseloc = 0; // skip 1/2 baselocs as they are dummied out ingame. - Array.Copy(BitConverter.GetBytes(baseloc), 0, sav, sv + offset, 2); + Array.Copy(BitConverter.GetBytes(baseloc), 0, sav, offset, 2); TB_FOT.Text = TrainerName; TB_FSay1.Text = saying1; TB_FSay2.Text = saying2; TB_FSay3.Text = saying3; TB_FSay4.Text = saying4; // Copy back Objects for (int i = 0; i < 25; i++) for (int z = 0; z < 12; z++) - sav[sv + offset + 2 + 12 * i + z] = objdata[i, z]; + sav[offset + 2 + 12 * i + z] = objdata[i, z]; if (GB_PKM.Enabled) // Copy pkm data back in { saveFavPKM(); for (int i = 0; i < 3; i++) for (int z = 0; z < 0x34; z++) - sav[sv + offset + 0x32E + 0x34 * i + z] = pkmdata[i, z]; + sav[offset + 0x32E + 0x34 * i + z] = pkmdata[i, z]; } popFavorite(); LB_Favorite.SelectedIndex = index; @@ -207,22 +203,21 @@ private void B_Cancel_Click(object sender, EventArgs e) private void B_Save_Click(object sender, EventArgs e) { uint flags = Util.ToUInt32(MT_Flags); - Array.Copy(BitConverter.GetBytes(flags), 0, sav, 0x24800 + 0x140, 4); // write pss - Array.Copy(BitConverter.GetBytes(flags), 0, sav, 0x2942C, 4); // write counter - Array.Copy(sav, m_parent.savefile, 0x100000); - m_parent.savedited = true; + Array.Copy(BitConverter.GetBytes(flags), 0, sav, Main.SaveGame.PSSStats + 0x140, 4); // write pss + Array.Copy(BitConverter.GetBytes(flags), 0, sav, Main.SaveGame.SecretBase + 0x62C, 4); // write counter + Array.Copy(sav, Main.savefile, sav.Length); + Main.savedited = true; Close(); } private void B_GiveDecor_Click(object sender, EventArgs e) { - const int offset = sv + 0x23A00 + 0x5400; for (int i = 0; i < 173; i++) { // int qty = BitConverter.ToUInt16(sav, offset + i * 4); // int has = BitConverter.ToUInt16(sav, offset + i * 4 + 2); - sav[offset + i * 4] = 25; - sav[offset + i * 4 + 2] = 1; + sav[Main.SaveGame.SecretBase + i * 4] = 25; + sav[Main.SaveGame.SecretBase + i * 4 + 2] = 1; } } @@ -416,18 +411,18 @@ private void loadFavPKM() CHK_Shiny.Checked = isshiny; // Set Form - m_parent.setForms(spec, CB_Form); + Main.setForms(spec, CB_Form); int form = genform >> 3; CB_Form.SelectedIndex = form; // Set Ability - m_parent.setAbilityList(MT_AbilNo, spec, CB_Ability, CB_Form); + Main.setAbilityList(MT_AbilNo, spec, CB_Ability, CB_Form); } private void updateSpecies(object sender, EventArgs e) { // Get Forms for Given Species - m_parent.setForms(Util.getIndex(CB_Species), CB_Form); + Main.setForms(Util.getIndex(CB_Species), CB_Form); // Check for Gender Changes // Get Gender Threshold @@ -442,15 +437,15 @@ private void updateSpecies(object sender, EventArgs e) genderflag = 0; setGenderLabel(); - m_parent.setAbilityList(MT_AbilNo, Util.getIndex(CB_Species), CB_Ability, CB_Form); + Main.setAbilityList(MT_AbilNo, Util.getIndex(CB_Species), CB_Ability, CB_Form); } private void updateForm(object sender, EventArgs e) { - m_parent.setAbilityList(MT_AbilNo, Util.getIndex(CB_Species), CB_Ability, CB_Form); + Main.setAbilityList(MT_AbilNo, Util.getIndex(CB_Species), CB_Ability, CB_Form); // If form has a single gender, account for it. if (PKX.getGender(CB_Form.Text) < 2) - Label_Gender.Text = Form1.gendersymbols[CB_Form.SelectedIndex]; + Label_Gender.Text = Main.gendersymbols[CB_Form.SelectedIndex]; } private int genderflag; @@ -464,11 +459,11 @@ private void Label_Gender_Click(object sender, EventArgs e) return; if (gt < 256) // If not a single gender(less) species: - Label_Gender.Text = Form1.gendersymbols[PKX.getGender(Label_Gender.Text) ^ 1]; + Label_Gender.Text = Main.gendersymbols[PKX.getGender(Label_Gender.Text) ^ 1]; } private void setGenderLabel() { - Label_Gender.Text = Form1.gendersymbols[genderflag]; + Label_Gender.Text = Main.gendersymbols[genderflag]; } private void B_FDelete_Click(object sender, EventArgs e) @@ -476,8 +471,8 @@ private void B_FDelete_Click(object sender, EventArgs e) if (LB_Favorite.SelectedIndex < 1) { Util.Alert("Cannot delete your Secret Base."); return; } int index = LB_Favorite.SelectedIndex - 1; - const int favoff = fav_offset + 0x5400 + 0x63A; - string BaseTrainer = Util.TrimFromZero(Encoding.Unicode.GetString(sav, sv + favoff + index * 0x3E0 + 0x218, 0x1A)); + int favoff = Main.SaveGame.SecretBase + 0x63A; + string BaseTrainer = Util.TrimFromZero(Encoding.Unicode.GetString(sav, favoff + index * 0x3E0 + 0x218, 0x1A)); if (BaseTrainer.Length < 1 || BaseTrainer[0] == '\0') BaseTrainer = "Empty"; @@ -487,7 +482,7 @@ private void B_FDelete_Click(object sender, EventArgs e) return; const int max = 29; const int size = 0x3E0; - int offset = sv + favoff + index * size; + int offset = favoff + index * size; if (index != max) Array.Copy(sav, offset + size, sav, offset, size * (max - index)); // Ensure Last Entry is Cleared Array.Copy(new byte[size], 0, sav, size * max, size); diff --git a/SAV/SAV_SuperTrain.cs b/SAV/SAV_SuperTrain.cs index d3d59706b..6bda90ec4 100644 --- a/SAV/SAV_SuperTrain.cs +++ b/SAV/SAV_SuperTrain.cs @@ -5,30 +5,26 @@ namespace PKHeX { public partial class SAV_SuperTrain : Form { - public SAV_SuperTrain(Form1 frm1) + public SAV_SuperTrain(Main frm1) { m_parent = frm1; - savindex = m_parent.savindex; - Array.Copy(m_parent.savefile, sav, 0x100000); - if (m_parent.savegame_oras) data_offset = 0x25600; - trba = Form1.trainingbags; + sav = (byte[])Main.savefile.Clone(); + trba = Main.trainingbags; trba[0] = "---"; - offsetTime = data_offset + 0x08 + 0x7F000 * savindex; - offsetSpec = data_offset + 0x188 + 0x7F000 * savindex; - offsetVal = data_offset + 0x18A + 0x7F000 * savindex; + offsetTime = Main.SaveGame.SuperTrain + 0x08; + offsetSpec = Main.SaveGame.SuperTrain + 0x188; + offsetVal = Main.SaveGame.SuperTrain + 0x18A; InitializeComponent(); - Util.TranslateInterface(this, Form1.curlanguage); - string[] stages = Form1.trainingstage; + Util.TranslateInterface(this, Main.curlanguage); + string[] stages = Main.trainingstage; listBox1.Items.Clear(); for (int i = 0; i < 30; i++) listBox1.Items.Add((i + 1).ToString("00") + " - " + stages[i + 2]); setup(); } - Form1 m_parent; - public byte[] sav = new byte[0x100000]; - public int savindex; - private int data_offset = 0x24600; + Main m_parent; + public byte[] sav; private string[] trba = { "Empty", "HP Bag S","HP Bag M","HP Bag L", @@ -91,7 +87,7 @@ private void fillTrainingBags() dataGridView1.Columns.Add(dgvBag); dataGridView1.Rows.Add(12); - int offset = data_offset + 0x308 + 0x7F000 * savindex; + int offset = Main.SaveGame.SuperTrain + 0x308; for (int i = 0; i < 12; i++) { dataGridView1.Rows[i].Cells[0].Value = (i + 1).ToString(); @@ -131,7 +127,7 @@ private void B_Save_Click(object sender, EventArgs e) } bagarray[i - emptyslots] = (byte)Array.IndexOf(trba, bag); } - int offsetTime = data_offset + 0x10 + 0x7F000 * savindex; + int offsetTime = Main.SaveGame.SuperTrain + 0x10; try { byte[] data = BitConverter.GetBytes(Single.Parse(TB_Time1.Text)); @@ -147,14 +143,14 @@ private void B_Save_Click(object sender, EventArgs e) } catch { } { - int offsetSpec = data_offset + 0x188 + 0x7F000 * savindex; + int offsetSpec = Main.SaveGame.SuperTrain + 0x188; byte[] data = BitConverter.GetBytes(Convert.ToUInt16(CB_S2.SelectedValue.ToString())); Array.Resize(ref data, 2); Array.Copy(data, 0, sav, offsetSpec + 4 * 30, 2); } - Array.Copy(bagarray, 0, sav, data_offset + 0x308 + savindex * 0x7F000, 12); - Array.Copy(sav, m_parent.savefile, 0x100000); - m_parent.savedited = true; + Array.Copy(bagarray, 0, sav, Main.SaveGame.SuperTrain + 0x308, 12); + Array.Copy(sav, Main.savefile, Main.savefile.Length); + Main.savedited = true; Close(); } private void B_Cancel_Click(object sender, EventArgs e) diff --git a/SAV/SAV_Trainer.cs b/SAV/SAV_Trainer.cs index 6b39b7f91..ba711befc 100644 --- a/SAV/SAV_Trainer.cs +++ b/SAV/SAV_Trainer.cs @@ -8,27 +8,17 @@ namespace PKHeX { public partial class SAV_Trainer : Form { - private const int TrainerCard = 0x19400; - private const int Trainer1 = 0x6800; - private const int Trainer2 = 0x9600; - private int Maison = 0x205C0; - private int VivillonForm = 0x9650; - public SAV_Trainer(Form1 frm1) + public SAV_Trainer() { InitializeComponent(); - if (!Form1.unicode) + if (!Main.unicode) try { TB_OTName.Font = PKX.getPKXFont(11); } catch (Exception e) { Util.Alert("Font loading failed...", e.ToString()); } - Util.TranslateInterface(this, Form1.curlanguage); - m_parent = frm1; - Array.Copy(m_parent.savefile, sav, 0x100000); - savindex = m_parent.savindex; - savshift = savindex * 0x7F000; - if (m_parent.savegame_oras) + Util.TranslateInterface(this, Main.curlanguage); + sav = (byte[])Main.savefile.Clone(); + if (Main.SaveGame.ORAS) { - psssatoffset = 0x24800; Maison += 0xA00; - VivillonForm = 0x9644; Width = (int)((float)Width * 428 / 590); CB_Multi.Enabled = true; L_MultiplayerSprite.Enabled = true; // Multiplayer Sprite Label @@ -41,7 +31,7 @@ public SAV_Trainer(Form1 frm1) getComboBoxes(); getTextBoxes(); getBadges(); - GB_Map.Enabled = !Form1.ramsavloaded; + GB_Map.Enabled = !Main.ramsavloaded; statdata = new[] { "0x000", "0x000", // Steps taken? @@ -203,10 +193,7 @@ public SAV_Trainer(Form1 frm1) CB_Stats.SelectedIndex = 0; } private string[] statdata = { }; - Form1 m_parent; public byte[] sav = new byte[0x100000]; - public int savshift; - public int savindex; public bool editing; public byte badgeval; public ToolTip Tip1 = new ToolTip(); @@ -244,7 +231,7 @@ private void getComboBoxes() CB_Country.ValueMember = "Value"; CB_Region.DisplayMember = "Text"; CB_Region.ValueMember = "Value"; - m_parent.setCountrySubRegion(CB_Country, "countries"); + Main.setCountrySubRegion(CB_Country, "countries"); var oras_sprite_list = new[] { //new { Text = "Calem", Value = 00 }, @@ -327,25 +314,14 @@ private void getComboBoxes() CB_Multi.ValueMember = "Value"; CB_Multi.DataSource = oras_sprite_list; - L_Vivillon.Text = Form1.specieslist[666] + ":"; - m_parent.setForms(666, CB_Vivillon); + L_Vivillon.Text = Main.specieslist[666] + ":"; + Main.setForms(666, CB_Vivillon); } private void getBadges() { // Fetch Badges - Bitmap[] bma = { - Properties.Resources.badge_1, - Properties.Resources.badge_2, - Properties.Resources.badge_3, - Properties.Resources.badge_4, - Properties.Resources.badge_5, - Properties.Resources.badge_6, - Properties.Resources.badge_7, - Properties.Resources.badge_8, - }; - if (m_parent.savegame_oras) - { - bma = new[] { + Bitmap[] bma = (Main.SaveGame.ORAS) ? + new[] { Properties.Resources.badge_01, // ORAS Badges Properties.Resources.badge_02, Properties.Resources.badge_03, @@ -354,48 +330,53 @@ private void getBadges() Properties.Resources.badge_06, Properties.Resources.badge_07, Properties.Resources.badge_08, - }; - } + } : + new [] { + Properties.Resources.badge_1, // XY Badges + Properties.Resources.badge_2, + Properties.Resources.badge_3, + Properties.Resources.badge_4, + Properties.Resources.badge_5, + Properties.Resources.badge_6, + Properties.Resources.badge_7, + Properties.Resources.badge_8, + }; CheckBox[] cba = { cb1, cb2, cb3, cb4, cb5, cb6, cb7, cb8, }; PictureBox[] pba = { pb1, pb2, pb3, pb4, pb5, pb6, pb7, pb8, }; for (int i = 0; i < 8; i++) - { pba[i].Image = Util.ChangeOpacity(bma[i], !cba[i].Checked ? 0.1 : 1); - } } private void getTextBoxes() { - badgeval = sav[Trainer2 + 0xC + savindex * 0x7F000]; + badgeval = sav[Main.SaveGame.Trainer2 + 0xC]; CheckBox[] cba = { cb1, cb2, cb3, cb4, cb5, cb6, cb7, cb8, }; for (int i = 0; i < 8; i++) cba[i].Checked = (badgeval & (1 << i)) != 0; // Get Data - string OT_NAME = Encoding.Unicode.GetString(sav, TrainerCard + 0x48 + savshift, 0x1A); - // string RIV_NAME = Encoding.Unicode.GetString(sav, Trainer2 + 0x10 + savshift, 0x1A); + string OT_NAME = Encoding.Unicode.GetString(sav, Main.SaveGame.TrainerCard + 0x48, 0x1A); - CB_Game.SelectedIndex = sav[TrainerCard + 0x04 + savshift] - 0x18; - CB_Gender.SelectedIndex = sav[TrainerCard + 0x05 + savshift]; + CB_Game.SelectedIndex = sav[Main.SaveGame.TrainerCard + 0x04] - 0x18; + CB_Gender.SelectedIndex = sav[Main.SaveGame.TrainerCard + 0x05]; - int TID = BitConverter.ToUInt16(sav, TrainerCard + 0x0 + savshift); - int SID = BitConverter.ToUInt16(sav, TrainerCard + 0x2 + savshift); - uint money = BitConverter.ToUInt32(sav, Trainer2 + 0x8 + savshift); + int TID = BitConverter.ToUInt16(sav, Main.SaveGame.TrainerCard + 0x0); + int SID = BitConverter.ToUInt16(sav, Main.SaveGame.TrainerCard + 0x2); + uint money = BitConverter.ToUInt32(sav, Main.SaveGame.Trainer2 + 0x8); - string saying1 = Encoding.Unicode.GetString(sav, TrainerCard + 0x7C + savshift, 0x20); - string saying2 = Encoding.Unicode.GetString(sav, TrainerCard + 0x9E + savshift, 0x20); - string saying3 = Encoding.Unicode.GetString(sav, TrainerCard + 0xC0 + savshift, 0x20); - string saying4 = Encoding.Unicode.GetString(sav, TrainerCard + 0xE2 + savshift, 0x20); - string saying5 = Encoding.Unicode.GetString(sav, TrainerCard + 0x104 + savshift, 0x20); + string saying1 = Encoding.Unicode.GetString(sav, Main.SaveGame.TrainerCard + 0x7C, 0x20); + string saying2 = Encoding.Unicode.GetString(sav, Main.SaveGame.TrainerCard + 0x9E, 0x20); + string saying3 = Encoding.Unicode.GetString(sav, Main.SaveGame.TrainerCard + 0xC0, 0x20); + string saying4 = Encoding.Unicode.GetString(sav, Main.SaveGame.TrainerCard + 0xE2, 0x20); + string saying5 = Encoding.Unicode.GetString(sav, Main.SaveGame.TrainerCard + 0x104, 0x20); - int _region = sav[TrainerCard + 0x26 + savshift]; - int _country = sav[TrainerCard + 0x27 + savshift]; - int _3dsreg = sav[TrainerCard + 0x2C + savshift]; - int _language = sav[TrainerCard + 0x2D + savshift]; + int _region = sav[Main.SaveGame.TrainerCard + 0x26]; + int _country = sav[Main.SaveGame.TrainerCard + 0x27]; + int _3dsreg = sav[Main.SaveGame.TrainerCard + 0x2C]; + int _language = sav[Main.SaveGame.TrainerCard + 0x2D]; // Display Data TB_OTName.Text = OT_NAME; - //TB_Rival.Text = RIV_NAME; MT_TID.Text = TID.ToString("00000"); MT_SID.Text = SID.ToString("00000"); @@ -414,85 +395,85 @@ private void getTextBoxes() CB_Language.SelectedValue = _language; // Maison Data - TB_MCSN.Text = BitConverter.ToUInt16(sav, savshift + Maison + 2 * 0).ToString(); - TB_MCSS.Text = BitConverter.ToUInt16(sav, savshift + Maison + 2 * 1).ToString(); + TB_MCSN.Text = BitConverter.ToUInt16(sav, Main.SaveGame.MaisonStats + 2 * 0).ToString(); + TB_MCSS.Text = BitConverter.ToUInt16(sav, Main.SaveGame.MaisonStats + 2 * 1).ToString(); - TB_MBSN.Text = BitConverter.ToUInt16(sav, savshift + Maison + 2 * 2).ToString(); - TB_MBSS.Text = BitConverter.ToUInt16(sav, savshift + Maison + 2 * 3).ToString(); + TB_MBSN.Text = BitConverter.ToUInt16(sav, Main.SaveGame.MaisonStats + 2 * 2).ToString(); + TB_MBSS.Text = BitConverter.ToUInt16(sav, Main.SaveGame.MaisonStats + 2 * 3).ToString(); - TB_MCDN.Text = BitConverter.ToUInt16(sav, savshift + Maison + 2 * 4).ToString(); - TB_MCDS.Text = BitConverter.ToUInt16(sav, savshift + Maison + 2 * 5).ToString(); + TB_MCDN.Text = BitConverter.ToUInt16(sav, Main.SaveGame.MaisonStats + 2 * 4).ToString(); + TB_MCDS.Text = BitConverter.ToUInt16(sav, Main.SaveGame.MaisonStats + 2 * 5).ToString(); - TB_MBDN.Text = BitConverter.ToUInt16(sav, savshift + Maison + 2 * 6).ToString(); - TB_MBDS.Text = BitConverter.ToUInt16(sav, savshift + Maison + 2 * 7).ToString(); + TB_MBDN.Text = BitConverter.ToUInt16(sav, Main.SaveGame.MaisonStats + 2 * 6).ToString(); + TB_MBDS.Text = BitConverter.ToUInt16(sav, Main.SaveGame.MaisonStats + 2 * 7).ToString(); - TB_MCTN.Text = BitConverter.ToUInt16(sav, savshift + Maison + 2 * 8).ToString(); - TB_MCTS.Text = BitConverter.ToUInt16(sav, savshift + Maison + 2 * 9).ToString(); + TB_MCTN.Text = BitConverter.ToUInt16(sav, Main.SaveGame.MaisonStats + 2 * 8).ToString(); + TB_MCTS.Text = BitConverter.ToUInt16(sav, Main.SaveGame.MaisonStats + 2 * 9).ToString(); - TB_MBTN.Text = BitConverter.ToUInt16(sav, savshift + Maison + 2 * 10).ToString(); - TB_MBTS.Text = BitConverter.ToUInt16(sav, savshift + Maison + 2 * 11).ToString(); + TB_MBTN.Text = BitConverter.ToUInt16(sav, Main.SaveGame.MaisonStats + 2 * 10).ToString(); + TB_MBTS.Text = BitConverter.ToUInt16(sav, Main.SaveGame.MaisonStats + 2 * 11).ToString(); - TB_MCRN.Text = BitConverter.ToUInt16(sav, savshift + Maison + 2 * 12).ToString(); - TB_MCRS.Text = BitConverter.ToUInt16(sav, savshift + Maison + 2 * 13).ToString(); + TB_MCRN.Text = BitConverter.ToUInt16(sav, Main.SaveGame.MaisonStats + 2 * 12).ToString(); + TB_MCRS.Text = BitConverter.ToUInt16(sav, Main.SaveGame.MaisonStats + 2 * 13).ToString(); - TB_MBRN.Text = BitConverter.ToUInt16(sav, savshift + Maison + 2 * 14).ToString(); - TB_MBRS.Text = BitConverter.ToUInt16(sav, savshift + Maison + 2 * 15).ToString(); + TB_MBRN.Text = BitConverter.ToUInt16(sav, Main.SaveGame.MaisonStats + 2 * 14).ToString(); + TB_MBRS.Text = BitConverter.ToUInt16(sav, Main.SaveGame.MaisonStats + 2 * 15).ToString(); - TB_MCMN.Text = BitConverter.ToUInt16(sav, savshift + Maison + 2 * 16).ToString(); - TB_MCMS.Text = BitConverter.ToUInt16(sav, savshift + Maison + 2 * 17).ToString(); + TB_MCMN.Text = BitConverter.ToUInt16(sav, Main.SaveGame.MaisonStats + 2 * 16).ToString(); + TB_MCMS.Text = BitConverter.ToUInt16(sav, Main.SaveGame.MaisonStats + 2 * 17).ToString(); - TB_MBMN.Text = BitConverter.ToUInt16(sav, savshift + Maison + 2 * 18).ToString(); - TB_MBMS.Text = BitConverter.ToUInt16(sav, savshift + Maison + 2 * 19).ToString(); + TB_MBMN.Text = BitConverter.ToUInt16(sav, Main.SaveGame.MaisonStats + 2 * 18).ToString(); + TB_MBMS.Text = BitConverter.ToUInt16(sav, Main.SaveGame.MaisonStats + 2 * 19).ToString(); - TB_CoordM.Text = BitConverter.ToUInt16(sav, savshift + Trainer1 + 0x02).ToString(); - TB_CoordX.Text = BitConverter.ToSingle(sav, savshift + Trainer1 + 0x10).ToString(); - TB_CoordZ.Text = BitConverter.ToSingle(sav, savshift + Trainer1 + 0x14).ToString(); - TB_CoordY.Text = BitConverter.ToSingle(sav, savshift + Trainer1 + 0x18).ToString(); + TB_CoordM.Text = BitConverter.ToUInt16(sav, Main.SaveGame.Trainer1 + 0x02).ToString(); + TB_CoordX.Text = BitConverter.ToSingle(sav, Main.SaveGame.Trainer1 + 0x10).ToString(); + TB_CoordZ.Text = BitConverter.ToSingle(sav, Main.SaveGame.Trainer1 + 0x14).ToString(); + TB_CoordY.Text = BitConverter.ToSingle(sav, Main.SaveGame.Trainer1 + 0x18).ToString(); // Load BP and PokeMiles - TB_BP.Text = BitConverter.ToUInt32(sav, savshift + Trainer2 + 0x3C - 0xC * Convert.ToInt16(m_parent.savegame_oras)).ToString(); - TB_PM.Text = BitConverter.ToUInt32(sav, savshift + psssatoffset + 0xFC).ToString(); + TB_BP.Text = BitConverter.ToUInt32(sav, Main.SaveGame.Trainer2 + 0x3C - 0xC * Convert.ToInt16(Main.SaveGame.ORAS)).ToString(); + TB_PM.Text = BitConverter.ToUInt32(sav, Main.SaveGame.PSSStats + 0xFC).ToString(); - // Temp ORAS + // Temp ORAS GB_Misc.Visible = true; - TB_Style.Text = sav[0x694D + savshift].ToString(); + TB_Style.Text = sav[0x694D].ToString(); // Load Play Time - MT_Hours.Text = BitConverter.ToUInt16(sav, savshift + 0x6C00).ToString(); - MT_Minutes.Text = sav[0x6C02 + savshift].ToString(); - MT_Seconds.Text = sav[0x6C03 + savshift].ToString(); + MT_Hours.Text = BitConverter.ToUInt16(sav, 0x6C00).ToString(); + MT_Minutes.Text = sav[0x6C02].ToString(); + MT_Seconds.Text = sav[0x6C03].ToString(); // Load PSS Sprite - int sprite = sav[TrainerCard + 0x07]; + int sprite = sav[Main.SaveGame.TrainerCard + 0x07]; CB_Multi.SelectedValue = sprite; PB_Sprite.Image = (Image)Properties.Resources.ResourceManager.GetObject("tr_" + sprite.ToString("00")); // Load Clothing Data - int hat = sav[TrainerCard + 0x31 + savshift] >> 3; - int haircolor = sav[TrainerCard + 0x31 + savshift] & 7; + int hat = sav[Main.SaveGame.TrainerCard + 0x31] >> 3; + int haircolor = sav[Main.SaveGame.TrainerCard + 0x31] & 7; MT_Hat.Text = hat.ToString(); MT_HairColor.Text = haircolor.ToString(); - MT_14030.Text = sav[TrainerCard + 0x30 + savshift].ToString(); - MT_14031.Text = sav[TrainerCard + 0x31 + savshift].ToString(); - MT_14032.Text = sav[TrainerCard + 0x32 + savshift].ToString(); - MT_14033.Text = sav[TrainerCard + 0x33 + savshift].ToString(); - MT_14034.Text = sav[TrainerCard + 0x34 + savshift].ToString(); - MT_14035.Text = sav[TrainerCard + 0x35 + savshift].ToString(); - MT_14036.Text = sav[TrainerCard + 0x36 + savshift].ToString(); - MT_14037.Text = sav[TrainerCard + 0x37 + savshift].ToString(); - MT_14038.Text = sav[TrainerCard + 0x38 + savshift].ToString(); - MT_14039.Text = sav[TrainerCard + 0x39 + savshift].ToString(); - MT_1403A.Text = sav[TrainerCard + 0x3A + savshift].ToString(); - MT_1403B.Text = sav[TrainerCard + 0x3B + savshift].ToString(); - MT_1403C.Text = sav[TrainerCard + 0x3C + savshift].ToString(); - MT_1403D.Text = sav[TrainerCard + 0x3D + savshift].ToString(); - MT_1403E.Text = sav[TrainerCard + 0x3E + savshift].ToString(); - MT_1403F.Text = sav[TrainerCard + 0x3F + savshift].ToString(); + MT_14030.Text = sav[Main.SaveGame.TrainerCard + 0x30].ToString(); + MT_14031.Text = sav[Main.SaveGame.TrainerCard + 0x31].ToString(); + MT_14032.Text = sav[Main.SaveGame.TrainerCard + 0x32].ToString(); + MT_14033.Text = sav[Main.SaveGame.TrainerCard + 0x33].ToString(); + MT_14034.Text = sav[Main.SaveGame.TrainerCard + 0x34].ToString(); + MT_14035.Text = sav[Main.SaveGame.TrainerCard + 0x35].ToString(); + MT_14036.Text = sav[Main.SaveGame.TrainerCard + 0x36].ToString(); + MT_14037.Text = sav[Main.SaveGame.TrainerCard + 0x37].ToString(); + MT_14038.Text = sav[Main.SaveGame.TrainerCard + 0x38].ToString(); + MT_14039.Text = sav[Main.SaveGame.TrainerCard + 0x39].ToString(); + MT_1403A.Text = sav[Main.SaveGame.TrainerCard + 0x3A].ToString(); + MT_1403B.Text = sav[Main.SaveGame.TrainerCard + 0x3B].ToString(); + MT_1403C.Text = sav[Main.SaveGame.TrainerCard + 0x3C].ToString(); + MT_1403D.Text = sav[Main.SaveGame.TrainerCard + 0x3D].ToString(); + MT_1403E.Text = sav[Main.SaveGame.TrainerCard + 0x3E].ToString(); + MT_1403F.Text = sav[Main.SaveGame.TrainerCard + 0x3F].ToString(); // Vivillon - byte vivillon = sav[VivillonForm + savshift]; + byte vivillon = sav[Main.SaveGame.Vivillon]; CB_Vivillon.SelectedIndex = vivillon; } private void save() @@ -500,8 +481,8 @@ private void save() string OT_Name = TB_OTName.Text; //string RIV_Name = TB_Rival.Text; - sav[TrainerCard + 0x04 + savshift] = (byte)(CB_Game.SelectedIndex + 0x18); - sav[TrainerCard + 0x05 + savshift] = (byte)CB_Gender.SelectedIndex; + sav[Main.SaveGame.TrainerCard + 0x04] = (byte)(CB_Game.SelectedIndex + 0x18); + sav[Main.SaveGame.TrainerCard + 0x05] = (byte)CB_Gender.SelectedIndex; uint TID = Util.ToUInt32(MT_TID.Text); uint SID = Util.ToUInt32(MT_SID.Text); @@ -518,36 +499,21 @@ private void save() uint _3dsreg = Util.ToUInt32(CB_3DSReg.SelectedValue.ToString()); uint _language = Util.ToUInt32(CB_Language.SelectedValue.ToString()); - Array.Copy(BitConverter.GetBytes(TID), 0, sav, TrainerCard + 0x0 + savshift, 2); - Array.Copy(BitConverter.GetBytes(SID), 0, sav, TrainerCard + 0x2 + savshift, 2); - Array.Copy(BitConverter.GetBytes(money), 0, sav, Trainer2 + 0x8 + savshift, 4); - Array.Copy(BitConverter.GetBytes(_region), 0, sav, TrainerCard + 0x26 + savshift, 1); - Array.Copy(BitConverter.GetBytes(_country), 0, sav, TrainerCard + 0x27 + savshift, 1); - Array.Copy(BitConverter.GetBytes(_3dsreg), 0, sav, TrainerCard + 0x2C + savshift, 1); - Array.Copy(BitConverter.GetBytes(_language), 0, sav, TrainerCard + 0x2D + savshift, 1); + Array.Copy(BitConverter.GetBytes(TID), 0, sav, Main.SaveGame.TrainerCard + 0x0, 2); + Array.Copy(BitConverter.GetBytes(SID), 0, sav, Main.SaveGame.TrainerCard + 0x2, 2); + Array.Copy(BitConverter.GetBytes(money), 0, sav, Main.SaveGame.Trainer2 + 0x8, 4); + Array.Copy(BitConverter.GetBytes(_region), 0, sav, Main.SaveGame.TrainerCard + 0x26, 1); + Array.Copy(BitConverter.GetBytes(_country), 0, sav, Main.SaveGame.TrainerCard + 0x27, 1); + Array.Copy(BitConverter.GetBytes(_3dsreg), 0, sav, Main.SaveGame.TrainerCard + 0x2C, 1); + Array.Copy(BitConverter.GetBytes(_language), 0, sav, Main.SaveGame.TrainerCard + 0x2D, 1); - byte[] OT = Encoding.Unicode.GetBytes(OT_Name); - Array.Resize(ref OT, 0x1A); - Array.Copy(OT, 0, sav, TrainerCard + 0x48 + savshift, 0x1A); - //byte[] Rival = Encoding.Unicode.GetBytes(RIV_Name); - //Array.Resize(ref Rival, 0x1A); - //Array.Copy(Rival, 0, sav, 0x9610 + savshift, 0x1A); + Array.Copy(Encoding.Unicode.GetBytes(OT_Name.PadRight(13, '\0')), 0, sav, Main.SaveGame.TrainerCard + 0x48, 0x1A); - byte[] s1 = Encoding.Unicode.GetBytes(saying1); - Array.Resize(ref s1, 0x22); - Array.Copy(s1, 0, sav, TrainerCard + 0x7C + savshift, 0x22); - byte[] s2 = Encoding.Unicode.GetBytes(saying2); - Array.Resize(ref s2, 0x22); - Array.Copy(s2, 0, sav, TrainerCard + 0x9E + savshift, 0x22); - byte[] s3 = Encoding.Unicode.GetBytes(saying3); - Array.Resize(ref s3, 0x22); - Array.Copy(s3, 0, sav, TrainerCard + 0xC0 + savshift, 0x22); - byte[] s4 = Encoding.Unicode.GetBytes(saying4); - Array.Resize(ref s4, 0x22); - Array.Copy(s4, 0, sav, TrainerCard + 0xE2 + savshift, 0x22); - byte[] s5 = Encoding.Unicode.GetBytes(saying5); - Array.Resize(ref s5, 0x22); - Array.Copy(s5, 0, sav, TrainerCard + 0x104 + savshift, 0x22); + Array.Copy(Encoding.Unicode.GetBytes(saying1.PadRight(17, '\0')), 0, sav, Main.SaveGame.TrainerCard + 0x7C, 0x22); + Array.Copy(Encoding.Unicode.GetBytes(saying2.PadRight(17, '\0')), 0, sav, Main.SaveGame.TrainerCard + 0x9E, 0x22); + Array.Copy(Encoding.Unicode.GetBytes(saying3.PadRight(17, '\0')), 0, sav, Main.SaveGame.TrainerCard + 0xC0, 0x22); + Array.Copy(Encoding.Unicode.GetBytes(saying4.PadRight(17, '\0')), 0, sav, Main.SaveGame.TrainerCard + 0xE2, 0x22); + Array.Copy(Encoding.Unicode.GetBytes(saying5.PadRight(17, '\0')), 0, sav, Main.SaveGame.TrainerCard + 0x104, 0x22); // New stuff. // Copy Maison Data in @@ -559,74 +525,69 @@ private void save() TB_MCRN,TB_MCRS,TB_MBRN,TB_MBRS, TB_MCMN,TB_MCMS,TB_MBMN,TB_MBMS, }; - for (int i = 0; i < tba.Length; i++) - { - byte[] streak = BitConverter.GetBytes(Util.ToUInt32(tba[i].Text)); - Array.Resize(ref streak, 2); - Array.Copy(streak, 0, sav, Maison + 2 * i + savshift, 2); - } + Array.Copy(BitConverter.GetBytes(UInt16.Parse(tba[i].Text)), 0, sav, Main.SaveGame.MaisonStats + 2 * i, 2); // Copy Position - byte[] m = BitConverter.GetBytes(Int16.Parse(TB_CoordM.Text)); Array.Resize(ref m, 2); Array.Copy(m, 0, sav, savshift + Trainer1 + 0x02, 2); - byte[] x = BitConverter.GetBytes(Single.Parse(TB_CoordX.Text)); Array.Resize(ref x, 4); Array.Copy(x, 0, sav, savshift + Trainer1 + 0x10, 4); - byte[] z = BitConverter.GetBytes(Single.Parse(TB_CoordZ.Text)); Array.Resize(ref z, 4); Array.Copy(z, 0, sav, savshift + Trainer1 + 0x14, 4); - byte[] y = BitConverter.GetBytes(Single.Parse(TB_CoordY.Text)); Array.Resize(ref y, 4); Array.Copy(y, 0, sav, savshift + Trainer1 + 0x18, 4); + Array.Copy(BitConverter.GetBytes(UInt16.Parse(TB_CoordM.Text)), 0, sav, Main.SaveGame.Trainer1 + 0x02, 2); // m + Array.Copy(BitConverter.GetBytes(Single.Parse(TB_CoordX.Text)), 0, sav, Main.SaveGame.Trainer1 + 0x10, 4); // x + Array.Copy(BitConverter.GetBytes(Single.Parse(TB_CoordZ.Text)), 0, sav, Main.SaveGame.Trainer1 + 0x14, 4); // y + Array.Copy(BitConverter.GetBytes(Single.Parse(TB_CoordY.Text)), 0, sav, Main.SaveGame.Trainer1 + 0x18, 4); // z - byte[] bp = BitConverter.GetBytes(Util.ToUInt32(TB_BP.Text)); Array.Resize(ref bp, 2); Array.Copy(bp, 0, sav, savshift + 0x963C - 0xC * Convert.ToInt16(m_parent.savegame_oras), 2); - byte[] pm = BitConverter.GetBytes(Util.ToUInt32(TB_PM.Text)); Array.Resize(ref pm, 4); Array.Copy(pm, 0, sav, savshift + psssatoffset + 0xFC, 4); Array.Copy(pm, 0, sav, savshift + psssatoffset + 0x100, 4); - sav[0x694D + savshift] = Byte.Parse(TB_Style.Text); + Array.Copy(BitConverter.GetBytes(UInt16.Parse(TB_BP.Text)), 0, sav, 0x963C - 0xC * Convert.ToInt16(Main.SaveGame.ORAS), 2); + Array.Copy(BitConverter.GetBytes(Util.ToUInt32(TB_PM.Text)), 0, sav, Main.SaveGame.PSSStats + 0xFC, 4); + Array.Copy(BitConverter.GetBytes(Util.ToUInt32(TB_PM.Text)), 0, sav, Main.SaveGame.PSSStats + 0x100, 4); + sav[0x694D] = Byte.Parse(TB_Style.Text); // Copy Badges badgeval = 0; CheckBox[] cba = { cb1, cb2, cb3, cb4, cb5, cb6, cb7, cb8, }; for (int i = 0; i < 8; i++) badgeval |= (byte)(Convert.ToByte(cba[i].Checked) << i); - sav[0x960C + savshift] = badgeval; + sav[0x960C] = badgeval; // Save PlayTime - byte[] h = BitConverter.GetBytes(UInt16.Parse(MT_Hours.Text)); Array.Resize(ref h, 2); Array.Copy(h, 0, sav, savshift + 0x6C00, 2); - sav[0x6C02 + savshift] = (byte)(UInt16.Parse(MT_Minutes.Text) % 60); - sav[0x6C03 + savshift] = (byte)(UInt16.Parse(MT_Seconds.Text) % 60); + Array.Copy(BitConverter.GetBytes(UInt16.Parse(MT_Hours.Text)), 0, sav, 0x6C00, 2); + sav[0x6C02] = (byte)(UInt16.Parse(MT_Minutes.Text) % 60); + sav[0x6C03] = (byte)(UInt16.Parse(MT_Seconds.Text) % 60); // Sprite - sav[TrainerCard + 0x07] = Convert.ToByte(CB_Multi.SelectedValue); + sav[Main.SaveGame.TrainerCard + 0x07] = Convert.ToByte(CB_Multi.SelectedValue); - sav[TrainerCard + 0x31] = (byte)(Byte.Parse(MT_HairColor.Text) + (Byte.Parse(MT_Hat.Text) << 3)); - - sav[TrainerCard + 0x30 + savshift] = Byte.Parse(MT_14030.Text); - //sav[TrainerCard + 0x31 + savshift] = Byte.Parse(MT_14031.Text); - sav[TrainerCard + 0x32 + savshift] = Byte.Parse(MT_14032.Text); - sav[TrainerCard + 0x33 + savshift] = Byte.Parse(MT_14033.Text); - sav[TrainerCard + 0x34 + savshift] = Byte.Parse(MT_14034.Text); - sav[TrainerCard + 0x35 + savshift] = Byte.Parse(MT_14035.Text); - sav[TrainerCard + 0x36 + savshift] = Byte.Parse(MT_14036.Text); - sav[TrainerCard + 0x37 + savshift] = Byte.Parse(MT_14037.Text); - sav[TrainerCard + 0x38 + savshift] = Byte.Parse(MT_14038.Text); - sav[TrainerCard + 0x39 + savshift] = Byte.Parse(MT_14039.Text); - sav[TrainerCard + 0x3A + savshift] = Byte.Parse(MT_1403A.Text); - sav[TrainerCard + 0x3B + savshift] = Byte.Parse(MT_1403B.Text); - sav[TrainerCard + 0x3C + savshift] = Byte.Parse(MT_1403C.Text); - sav[TrainerCard + 0x3D + savshift] = Byte.Parse(MT_1403D.Text); - sav[TrainerCard + 0x3E + savshift] = Byte.Parse(MT_1403E.Text); - sav[TrainerCard + 0x3F + savshift] = Byte.Parse(MT_1403F.Text); + // Appearance + sav[Main.SaveGame.TrainerCard + 0x30] = Byte.Parse(MT_14030.Text); + sav[Main.SaveGame.TrainerCard + 0x31] = (byte)(Byte.Parse(MT_HairColor.Text) + (Byte.Parse(MT_Hat.Text) << 3)); + sav[Main.SaveGame.TrainerCard + 0x32] = Byte.Parse(MT_14032.Text); + sav[Main.SaveGame.TrainerCard + 0x33] = Byte.Parse(MT_14033.Text); + sav[Main.SaveGame.TrainerCard + 0x34] = Byte.Parse(MT_14034.Text); + sav[Main.SaveGame.TrainerCard + 0x35] = Byte.Parse(MT_14035.Text); + sav[Main.SaveGame.TrainerCard + 0x36] = Byte.Parse(MT_14036.Text); + sav[Main.SaveGame.TrainerCard + 0x37] = Byte.Parse(MT_14037.Text); + sav[Main.SaveGame.TrainerCard + 0x38] = Byte.Parse(MT_14038.Text); + sav[Main.SaveGame.TrainerCard + 0x39] = Byte.Parse(MT_14039.Text); + sav[Main.SaveGame.TrainerCard + 0x3A] = Byte.Parse(MT_1403A.Text); + sav[Main.SaveGame.TrainerCard + 0x3B] = Byte.Parse(MT_1403B.Text); + sav[Main.SaveGame.TrainerCard + 0x3C] = Byte.Parse(MT_1403C.Text); + sav[Main.SaveGame.TrainerCard + 0x3D] = Byte.Parse(MT_1403D.Text); + sav[Main.SaveGame.TrainerCard + 0x3E] = Byte.Parse(MT_1403E.Text); + sav[Main.SaveGame.TrainerCard + 0x3F] = Byte.Parse(MT_1403F.Text); // Vivillon - sav[VivillonForm + savshift] = (byte)CB_Vivillon.SelectedIndex; + sav[Main.SaveGame.Vivillon] = (byte)CB_Vivillon.SelectedIndex; } private void clickOT(object sender, MouseEventArgs e) { TextBox tb = (!(sender is TextBox)) ? TB_OTName : (sender as TextBox); // Special Character Form - if (ModifierKeys == Keys.Control && !Form1.specialChars) + if (ModifierKeys == Keys.Control && !Main.specialChars) (new f2_Text(tb)).Show(); } private void showTSV(object sender, EventArgs e) { uint TID = Util.ToUInt32(MT_TID.Text); uint SID = Util.ToUInt32(MT_SID.Text); - uint tsv = (TID ^ SID) >> 4; + uint tsv = PKX.getTSV(TID, SID); Tip1.SetToolTip(MT_TID, "TSV: " + tsv.ToString("0000")); Tip2.SetToolTip(MT_SID, "TSV: " + tsv.ToString("0000")); } @@ -638,8 +599,8 @@ private void B_Cancel_Click(object sender, EventArgs e) private void B_Save_Click(object sender, EventArgs e) { save(); - Array.Copy(sav, m_parent.savefile, 0x100000); - m_parent.savedited = true; + Array.Copy(sav, Main.savefile, Main.savefile.Length); + Main.savedited = true; Close(); } private void B_MaxCash_Click(object sender, EventArgs e) @@ -672,16 +633,14 @@ private void changeFFFF(object sender, EventArgs e) if (box.Text == "") box.Text = "0"; if (Util.ToInt32(box.Text) > 65535) box.Text = "65535"; } - private int psssatoffset = 0x23800; private void changeStat(object sender, EventArgs e) { editing = true; { - int pssoff = psssatoffset + savindex * 0x7F000; string offsetstr = statdata[CB_Stats.SelectedIndex * 2]; int offset = (int)new System.ComponentModel.Int32Converter().ConvertFromString(offsetstr); - MT_Stat.Text = BitConverter.ToUInt32(sav, pssoff + offset).ToString(); + MT_Stat.Text = BitConverter.ToUInt32(sav, Main.SaveGame.PSSStats + offset).ToString(); L_Offset.Text = "0x" + offset.ToString("X3"); } editing = false; @@ -690,14 +649,13 @@ private void changeStatVal(object sender, EventArgs e) { if (editing) return; - int pssoff = psssatoffset + savindex * 0x7F000; string offsetstr = statdata[CB_Stats.SelectedIndex * 2]; int offset = (int)new System.ComponentModel.Int32Converter().ConvertFromString(offsetstr); uint val = UInt32.Parse(MT_Stat.Text); byte[] data = BitConverter.GetBytes(val); Array.Resize(ref data, 4); - Array.Copy(data, 0, sav, pssoff + offset, 4); + Array.Copy(data, 0, sav, Main.SaveGame.PSSStats + offset, 4); } private void giveAllAccessories(object sender, EventArgs e) { @@ -711,13 +669,13 @@ private void giveAllAccessories(object sender, EventArgs e) 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; - Array.Copy(data, 0, sav, savshift + 0x6E00, 0x6C); + Array.Copy(data, 0, sav, 0x6E00, 0x6C); } private void updateCountry(object sender, EventArgs e) { if (Util.getIndex(sender as ComboBox) > 0) - m_parent.setCountrySubRegion(CB_Region, "sr_" + Util.getIndex(sender as ComboBox).ToString("000")); + Main.setCountrySubRegion(CB_Region, "sr_" + Util.getIndex(sender as ComboBox).ToString("000")); } private void toggleBadge(object sender, EventArgs e) { @@ -728,7 +686,7 @@ private void toggleBadge(object sender, EventArgs e) private void CB_Multi_SelectedIndexChanged(object sender, EventArgs e) { - PB_Sprite.Image = (Image)Properties.Resources.ResourceManager.GetObject((m_parent.savegame_oras) ? "tr_" + Util.getIndex(CB_Multi).ToString("00") : "tr_00"); + PB_Sprite.Image = (Image)Properties.Resources.ResourceManager.GetObject((Main.SaveGame.ORAS) ? "tr_" + Util.getIndex(CB_Multi).ToString("00") : "tr_00"); } } } \ No newline at end of file diff --git a/SAV/SAV_Wondercard.cs b/SAV/SAV_Wondercard.cs index 09b05f28c..7494a2de6 100644 --- a/SAV/SAV_Wondercard.cs +++ b/SAV/SAV_Wondercard.cs @@ -9,14 +9,11 @@ namespace PKHeX { public partial class SAV_Wondercard : Form { - public SAV_Wondercard(Form1 frm1, byte[] wcdata = null) + public SAV_Wondercard(byte[] wcdata = null) { InitializeComponent(); - Util.TranslateInterface(this, Form1.curlanguage); - m_parent = frm1; - Array.Copy(m_parent.savefile, sav, 0x100000); - savindex = m_parent.savindex; - if (m_parent.savegame_oras) wcoffset = 0x22100; + Util.TranslateInterface(this, Main.curlanguage); + sav = (byte[])Main.savefile.Clone(); populateWClist(); populateReceived(); @@ -32,12 +29,9 @@ public SAV_Wondercard(Form1 frm1, byte[] wcdata = null) Array.Copy(wcdata, wondercard_data, wcdata.Length); loadwcdata(); } - Form1 m_parent; - public byte[] sav = new byte[0x100000]; + public byte[] sav; public byte[] wondercard_data = new byte[0x108]; - public int savindex; - private int wcoffset = 0x21100; - private const uint herpesval = 0x225D73C2; + private const uint EonTicketConst = 0x225D73C2; // Repopulation Functions private void populateWClist() @@ -45,7 +39,7 @@ private void populateWClist() LB_WCs.Items.Clear(); for (int i = 0; i < 24; i++) { - int offset = wcoffset + savindex * 0x7F000 + i * 0x108; + int offset = Main.SaveGame.WondercardData + i * 0x108; int cardID = BitConverter.ToUInt16(sav, offset); if (cardID == 0) LB_WCs.Items.Add((i + 1).ToString("00") + " - Empty"); @@ -79,10 +73,9 @@ private void loadwcdata() } private void populateReceived() { - int offset = wcoffset - 0x100 + savindex * 0x7F000; LB_Received.Items.Clear(); for (int i = 1; i < 2048; i++) - if ((((sav[offset + i / 8]) >> (i % 8)) & 0x1) == 1) + if ((((sav[Main.SaveGame.WondercardFlags + i / 8]) >> (i % 8)) & 0x1) == 1) LB_Received.Items.Add(i.ToString("0000")); } @@ -128,7 +121,7 @@ private void B_SAV2WC(object sender, EventArgs e) { // Load Wondercard from Save File int index = LB_WCs.SelectedIndex; - int offset = wcoffset + savindex * 0x7F000 + index * 0x108; + int offset = Main.SaveGame.WondercardData + index * 0x108; Array.Copy(sav, offset, wondercard_data, 0, 0x108); loadwcdata(); } @@ -136,11 +129,11 @@ private void B_WC2SAV(object sender, EventArgs e) { // Write Wondercard to Save File int index = LB_WCs.SelectedIndex; - int offset = wcoffset + savindex * 0x7F000 + index * 0x108; - if (m_parent.savegame_oras) // ORAS Only + int offset = Main.SaveGame.WondercardData + index * 0x108; + if (Main.SaveGame.ORAS) // ORAS Only if (BitConverter.ToUInt16(wondercard_data, 0) == 0x800) // Eon Ticket # if (BitConverter.ToUInt16(wondercard_data, 0x68) == 0x2D6) // Eon Ticket - Array.Copy(BitConverter.GetBytes(herpesval), 0, sav, 0x319B8 + 0x5400 + savindex * 0x7F000, 4); + Array.Copy(BitConverter.GetBytes(EonTicketConst), 0, sav, Main.SaveGame.EonTicket, 4); Array.Copy(wondercard_data, 0, sav, offset, 0x108); populateWClist(); int cardID = BitConverter.ToUInt16(wondercard_data, 0); @@ -153,7 +146,7 @@ private void B_WC2SAV(object sender, EventArgs e) private void B_DeleteWC_Click(object sender, EventArgs e) { int index = LB_WCs.SelectedIndex; - int offset = wcoffset + savindex * 0x7F000 + index * 0x108; + int offset = Main.SaveGame.WondercardData + index * 0x108; byte[] zeros = new byte[0x108]; Array.Copy(zeros, 0, sav, offset, 0x108); populateWClist(); @@ -166,7 +159,7 @@ private void B_Cancel_Click(object sender, EventArgs e) } private void B_Save_Click(object sender, EventArgs e) { - int offset = wcoffset - 0x100 + savindex * 0x7F000; + int offset = Main.SaveGame.WondercardFlags; // Make sure all of the Received Flags are flipped! byte[] wcflags = new byte[0x100]; @@ -186,8 +179,8 @@ select Util.ToUInt32(cardID)) Array.Copy(sav, offset + j * 0x108, sav, offset + (j - 1) * 0x108, 0x108); } - Array.Copy(sav, m_parent.savefile, 0x100000); - m_parent.savedited = true; + Array.Copy(sav, Main.savefile, sav.Length); + Main.savedited = true; Close(); } @@ -265,7 +258,7 @@ private string getWCDescriptionString(byte[] data) int item = BitConverter.ToUInt16(data, 0x68); int qty = BitConverter.ToUInt16(data, 0x70); - s += "Item: " + Form1.itemlist[item] + Environment.NewLine + "Quantity: " + qty; + s += "Item: " + Main.itemlist[item] + Environment.NewLine + "Quantity: " + qty; } else if (cardtype == 0) // PKM { @@ -283,12 +276,12 @@ private string getWCDescriptionString(byte[] data) "{1} @ {2} --- {7} - {8}/{9}{0}" + "{3} / {4} / {5} / {6}{0}", Environment.NewLine, - Form1.specieslist[species], - Form1.itemlist[helditem], - Form1.movelist[move1], - Form1.movelist[move2], - Form1.movelist[move3], - Form1.movelist[move4], + Main.specieslist[species], + Main.itemlist[helditem], + Main.movelist[move1], + Main.movelist[move2], + Main.movelist[move3], + Main.movelist[move4], OTname, TID.ToString("00000"), SID.ToString("00000")); } else @@ -337,7 +330,7 @@ private void L_QR_Click(object sender, EventArgs e) else { if (wondercard_data.SequenceEqual((new byte[wondercard_data.Length]))) - { Util.Alert("No wondercard data found"); return; } + { Util.Alert("No wondercard data found in loaded slot!"); return; } if (BitConverter.ToUInt16(wondercard_data, 0x68) == 726 && wondercard_data[0x51] == 1) { Util.Alert("Eon Ticket Wondercards will not function properly", "Inject to the save file instead."); return; } // Prep data diff --git a/SAV/frmReport.cs b/SAV/frmReport.cs index f08c1e5f0..b42397618 100644 --- a/SAV/frmReport.cs +++ b/SAV/frmReport.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.ComponentModel; +using System.IO; using System.Linq; using System.Reflection; using System.Text; @@ -17,17 +18,15 @@ public frmReport() InitializeComponent(); dgData.DoubleBuffered(true); } - public void PopulateData(byte[] InputData, int savindex, int baseoffset) + public void PopulateData(byte[] InputData, int BoxDataOffset) { - SaveData = new byte[InputData.Length]; - Array.Copy(InputData, SaveData, InputData.Length); + SaveData = (byte[])InputData.Clone(); PokemonList PL = new PokemonList(); - if (savindex > 1) savindex = 0; BoxBar.Maximum = 930 + 100; BoxBar.Step = 1; for (int BoxNum = 0; BoxNum < 31; BoxNum++) { - int boxoffset = baseoffset + 0x7F000 * savindex + BoxNum * (0xE8 * 30); + int boxoffset = BoxDataOffset + BoxNum * (0xE8 * 30); for (int SlotNum = 0; SlotNum < 30; SlotNum++) { BoxBar.PerformStep(); @@ -78,11 +77,10 @@ private void Export_CSV(string path) var cells = row.Cells.Cast(); sb.AppendLine(string.Join(",", cells.Select(cell => "\"" + cell.Value + "\"").ToArray())); } - System.IO.File.WriteAllText(path, sb.ToString(), Encoding.UTF8); + File.WriteAllText(path, sb.ToString(), Encoding.UTF8); } public class PokemonList : SortableBindingList { } - } public static class ExtensionMethods // Speed up scrolling {