diff --git a/Misc/SAV6.cs b/Misc/SAV6.cs index 244e5350f..e3331adcd 100644 --- a/Misc/SAV6.cs +++ b/Misc/SAV6.cs @@ -26,6 +26,7 @@ public class SAV6 : PKX // Save Data Attributes public byte[] Data; public bool Exportable; + public bool Edited; public SAV6(byte[] data) { Exportable = !data.SequenceEqual(new byte[data.Length]); @@ -226,7 +227,7 @@ public byte[] Write() setChecksums(); return Data; } - public int CurrentBox { get { return Data[LastViewedBox] & 0x1F; } set { Data[LastViewedBox] = (byte)value; } } + public int CurrentBox { get { return Data[LastViewedBox]; } set { Data[LastViewedBox] = (byte)value; } } // Player Information public ushort TID { get { return BitConverter.ToUInt16(Data, TrainerCard + 0); } } @@ -310,6 +311,7 @@ public void setPK6Party(PK6 pk6, int offset, bool? trade = null, bool? dex = nul byte[] ek6 = encryptArray(pk6.Data); Array.Resize(ref ek6, PK6.SIZE_PARTY); setData(ek6, offset); + Edited = true; } public void setPK6Stored(PK6 pk6, int offset, bool? trade = null, bool? dex = null) { @@ -321,6 +323,7 @@ public void setPK6Stored(PK6 pk6, int offset, bool? trade = null, bool? dex = nu byte[] ek6 = encryptArray(pk6.Data); Array.Resize(ref ek6, PK6.SIZE_STORED); setData(ek6, offset); + Edited = true; } public void setEK6Stored(byte[] ek6, int offset, bool? trade = null, bool? dex = null) { @@ -332,6 +335,7 @@ public void setEK6Stored(byte[] ek6, int offset, bool? trade = null, bool? dex = Array.Resize(ref ek6, PK6.SIZE_STORED); setData(ek6, offset); + Edited = true; } // Meta @@ -397,6 +401,10 @@ public int getBoxWallpaper(int box) { return 1 + Data[BoxWallpapers + box]; } + public string getBoxName(int box) + { + return Encoding.Unicode.GetString(Data, PCLayout + 0x22*box, 0x22).Trim(); + } public void setParty() { byte partymembers = 0; // start off with a ctr of 0 diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index 4694488c1..465eba0e7 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -46,9 +46,8 @@ public Main() Width = shortWidth; // Initialize Boxes - byte[] ezeros = PKX.encryptArray(new byte[PK6.SIZE_STORED]); for (int i = 0; i < 30*31; i++) - SAV.setEK6Stored(ezeros, SAV.Box + i*PK6.SIZE_STORED); + SAV.setEK6Stored(blankEK6, SAV.Box + i*PK6.SIZE_STORED); // Initialize Tab Storage with Default Data (to skip Move check) pk6.Move1 = 1; @@ -188,11 +187,11 @@ public Main() } #region Global Variables: Always Visible! + public static readonly byte[] blankEK6 = PKX.encryptArray(new byte[PK6.SIZE_PARTY]); public static PK6 pk6 = new PK6(new byte[PK6.SIZE_PARTY]); // Tab Pokemon Data Storage public static SAV6 SAV = new SAV6(new byte[0x760000]); - public static byte[] originalSAV; // original save - public static byte[] ramsav; - public static bool savedited; + public static byte[] originalSAV; // original save for CyberGadget Codes + public static byte[] ramsav; // original ramsav for ramsav exporting public string pathSDF; public string path3DS; public pk2pk Converter = new pk2pk(); @@ -232,10 +231,7 @@ public Main() public static string[] wallpapernames, puffs, itempouch = { }; public static string curlanguage = "en"; 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 ToolTip Tip1 = new ToolTip(), Tip2 = new ToolTip(), Tip3 = new ToolTip(), NatureTip = new ToolTip(); public static List MoveDataSource, ItemDataSource, SpeciesDataSource, BallDataSource, NatureDataSource, AbilityDataSource, VersionDataSource; private PictureBox[] SlotPictureBoxes; #endregion @@ -432,7 +428,7 @@ private void openQuick(string path) { try { - byte[] blank = PKX.encryptArray(new byte[PK6.SIZE_PARTY]); + byte[] blank = (byte[])blankEK6.Clone(); for (int i = 0; i < PK6.SIZE_STORED; i++) blank[i] ^= input[i]; @@ -664,7 +660,7 @@ private void openSave(bool oras) GB_SAVtools.Enabled = B_JPEG.Enabled = true; - savedited = false; + SAV.Edited = false; Menu_ToggleBoxUI.Visible = false; B_VerifyCHK.Enabled = ramsav == null; @@ -677,7 +673,7 @@ private void openSave(bool oras) GB_SUBE.Visible = !oras; B_OpenSecretBase.Visible = oras; - int startBox = SAV.CurrentBox; + int startBox = SAV.CurrentBox; // FF if BattleBox if (startBox > 30) { tabBoxMulti.SelectedIndex = 1; CB_BoxSelect.SelectedIndex = 0; } else { tabBoxMulti.SelectedIndex = 0; CB_BoxSelect.SelectedIndex = startBox; } @@ -1231,7 +1227,7 @@ private void clickStatLabel(object sender, MouseEventArgs e) : 0).ToString(); } else - (new[] {TB_HPIV, TB_ATKIV, TB_DEFIV, TB_SPAIV, TB_SPDIV, TB_SPEIV})[index].Text = + new[] {TB_HPIV, TB_ATKIV, TB_DEFIV, TB_SPAIV, TB_SPDIV, TB_SPEIV}[index].Text = ((e.Button == MouseButtons.Left) ? 31 : 0).ToString(); } private void clickIV(object sender, EventArgs e) @@ -2387,7 +2383,7 @@ private void dragoutDrop(object sender, DragEventArgs e) // Integrity Checks // private void clickVerifyCHK(object sender, EventArgs e) { - if (savedited) { Util.Alert("Save has been edited. Cannot integrity check."); return; } + if (SAV.Edited) { Util.Alert("Save has been edited. Cannot integrity check."); return; } RTB_S.Text += PKX.verifyG6CHK(SAV.Data); } @@ -2527,7 +2523,7 @@ private void clickView(object sender, EventArgs e) { try { - byte[] blank = PKX.encryptArray(new byte[PK6.SIZE_STORED]); + byte[] blank = (byte[])blankEK6.Clone(); for (int i = 0; i < PK6.SIZE_STORED; i++) blank[i] = (byte)(pk6.Data[i] ^ blank[i]); @@ -2634,7 +2630,12 @@ private void updateEggRNGSeed(object sender, EventArgs e) } // Write final value back to the save - SAV.DaycareRNGSeed = Convert.ToUInt64(TB_RNGSeed.Text, 16); + ulong value = Convert.ToUInt64(TB_RNGSeed.Text, 16); + if (value != SAV.DaycareRNGSeed) + { + SAV.DaycareRNGSeed = value; + SAV.Edited = true; + } } private void refreshTrainerInfo() { @@ -2746,12 +2747,12 @@ private void setBoxNames() { CB_BoxSelect.Items.Clear(); for (int i = 0; i < 31; i++) - CB_BoxSelect.Items.Add(Encoding.Unicode.GetString(SAV.Data, SAV.PCLayout + 0x22 * i, 0x22)); + CB_BoxSelect.Items.Add(SAV.getBoxName(i)); } catch { CB_BoxSelect.Items.Clear(); - for (int i = 1; i < 32; i++) + for (int i = 1; i < 31; i++) CB_BoxSelect.Items.Add("Box " + i); } CB_BoxSelect.SelectedIndex = selectedbox; // restore selected box @@ -2914,9 +2915,8 @@ private void loadBoxesFromDB(string path) if (dr == DialogResult.Cancel) return; if (dr == DialogResult.Yes) { - byte[] ezeros = PKX.encryptArray(new byte[PK6.SIZE_STORED]); for (int i = ctr; i < 30 * 31; i++) - SAV.setEK6Stored(ezeros, offset + i * PK6.SIZE_STORED); + SAV.setEK6Stored(blankEK6, offset + i * PK6.SIZE_STORED); } string[] filepaths = Directory.GetFiles(path, "*.*", SearchOption.TopDirectoryOnly); @@ -3399,14 +3399,14 @@ private void pbBoxSlot_DragDrop(object sender, DragEventArgs e) pkm_from_offset = 0; // Clear offset value } - savedited = true; + SAV.Edited = true; } private void pbBoxSlot_DragEnter(object sender, DragEventArgs e) { if (e.Data != null) e.Effect = DragDropEffects.Move; } - private byte[] pkm_from = PKX.encryptArray(new byte[PK6.SIZE_STORED]); + private byte[] pkm_from = (byte[])blankEK6.Clone(); private int pkm_from_offset; private int pkm_from_slot = -1; #endregion diff --git a/SAV/SAV_BoxLayout.cs b/SAV/SAV_BoxLayout.cs index df33249ce..0a245f454 100644 --- a/SAV/SAV_BoxLayout.cs +++ b/SAV/SAV_BoxLayout.cs @@ -64,7 +64,7 @@ private void B_Cancel_Click(object sender, EventArgs e) private void B_Save_Click(object sender, EventArgs e) { Array.Copy(sav, Main.SAV.Data, sav.Length); - Main.savedited = true; + Main.SAV.Edited = true; Close(); } diff --git a/SAV/SAV_HallOfFame.cs b/SAV/SAV_HallOfFame.cs index d64ebb0a7..eb3ba63fa 100644 --- a/SAV/SAV_HallOfFame.cs +++ b/SAV/SAV_HallOfFame.cs @@ -100,6 +100,7 @@ private void B_Cancel_Click(object sender, EventArgs e) private void B_Close_Click(object sender, EventArgs e) { Array.Copy(data, 0, Main.SAV.Data, Main.SAV.HoF, data.Length); + Main.SAV.Edited = true; Close(); } private void displayEntry(object sender, EventArgs e) diff --git a/SAV/SAV_Inventory.cs b/SAV/SAV_Inventory.cs index 5904ccbdf..4f1b17d95 100644 --- a/SAV/SAV_Inventory.cs +++ b/SAV/SAV_Inventory.cs @@ -282,7 +282,7 @@ private void B_Save_Click(object sender, EventArgs e) { saveBag(sender); Array.Copy(sav, Main.SAV.Data, Main.SAV.Data.Length); - Main.savedited = true; + Main.SAV.Edited = true; Close(); } } diff --git a/SAV/SAV_OPower.cs b/SAV/SAV_OPower.cs index a717e7c15..da5fcdda2 100644 --- a/SAV/SAV_OPower.cs +++ b/SAV/SAV_OPower.cs @@ -98,6 +98,7 @@ private void SaveData() Main.SAV.Data[o + 0x19] = Convert.ToByte(CHK_6.Checked); Main.SAV.Data[o + 0x26] = Convert.ToByte(CHK_7.Checked); Main.SAV.Data[o + 0x2B] = Convert.ToByte(CHK_8.Checked); + Main.SAV.Edited = true; } private int getIndex(int o, int l) { diff --git a/SAV/SAV_PokedexORAS.cs b/SAV/SAV_PokedexORAS.cs index cb962e5db..7895bab89 100644 --- a/SAV/SAV_PokedexORAS.cs +++ b/SAV/SAV_PokedexORAS.cs @@ -173,6 +173,7 @@ private void B_Save_Click(object sender, EventArgs e) // Return back to the parent savefile Array.Copy(sav, Main.SAV.Data, sav.Length); + Main.SAV.Edited = true; Close(); } private void saveChanges() diff --git a/SAV/SAV_PokedexXY.cs b/SAV/SAV_PokedexXY.cs index ce1108c0f..70162554d 100644 --- a/SAV/SAV_PokedexXY.cs +++ b/SAV/SAV_PokedexXY.cs @@ -184,6 +184,7 @@ private void B_Save_Click(object sender, EventArgs e) // Return back to the parent savefile Array.Copy(sav, Main.SAV.Data, sav.Length); + Main.SAV.Edited = true; Close(); } private void saveChanges() diff --git a/SAV/SAV_Pokepuff.cs b/SAV/SAV_Pokepuff.cs index cda80faab..033f381d4 100644 --- a/SAV/SAV_Pokepuff.cs +++ b/SAV/SAV_Pokepuff.cs @@ -150,7 +150,7 @@ private void B_Save_Click(object sender, EventArgs e) } Array.Copy(puffarray, 0, sav, Main.SAV.Puff, 100); Array.Copy(sav, Main.SAV.Data, sav.Length); - Main.savedited = true; + Main.SAV.Edited = true; Close(); } } diff --git a/SAV/SAV_SecretBase.cs b/SAV/SAV_SecretBase.cs index e94bca637..d1a287422 100644 --- a/SAV/SAV_SecretBase.cs +++ b/SAV/SAV_SecretBase.cs @@ -206,7 +206,7 @@ private void B_Save_Click(object sender, EventArgs e) Array.Copy(BitConverter.GetBytes(flags), 0, sav, Main.SAV.PSSStats + 0x140, 4); // write pss Array.Copy(BitConverter.GetBytes(flags), 0, sav, Main.SAV.SecretBase + 0x62C, 4); // write counter Array.Copy(sav, Main.SAV.Data, sav.Length); - Main.savedited = true; + Main.SAV.Edited = true; Close(); } private void B_GiveDecor_Click(object sender, EventArgs e) diff --git a/SAV/SAV_SuperTrain.cs b/SAV/SAV_SuperTrain.cs index 80e58aa44..6bb99ee94 100644 --- a/SAV/SAV_SuperTrain.cs +++ b/SAV/SAV_SuperTrain.cs @@ -150,7 +150,7 @@ private void B_Save_Click(object sender, EventArgs e) } Array.Copy(bagarray, 0, sav, Main.SAV.SuperTrain + 0x308, 12); Array.Copy(sav, Main.SAV.Data, Main.SAV.Data.Length); - Main.savedited = true; + Main.SAV.Edited = true; Close(); } private void B_Cancel_Click(object sender, EventArgs e) diff --git a/SAV/SAV_Trainer.cs b/SAV/SAV_Trainer.cs index 45585b055..0323486b3 100644 --- a/SAV/SAV_Trainer.cs +++ b/SAV/SAV_Trainer.cs @@ -600,7 +600,7 @@ private void B_Save_Click(object sender, EventArgs e) { save(); Array.Copy(sav, Main.SAV.Data, Main.SAV.Data.Length); - Main.savedited = true; + Main.SAV.Edited = true; Close(); } private void B_MaxCash_Click(object sender, EventArgs e) diff --git a/SAV/SAV_Wondercard.cs b/SAV/SAV_Wondercard.cs index 5118017f8..1bee36cac 100644 --- a/SAV/SAV_Wondercard.cs +++ b/SAV/SAV_Wondercard.cs @@ -180,7 +180,7 @@ select Util.ToUInt32(cardID)) } Array.Copy(sav, Main.SAV.Data, sav.Length); - Main.savedited = true; + Main.SAV.Edited = true; Close(); }