mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-10-02 19:26:48 -05:00
Minor bugfixes and cleanup
Added an Edited property for the save blank slot (encrypted) is initialized once and can be used elsewhere instead of constantly being recreated for no reason. Fixed having 32 boxes for non-saves All SAV editing forms now set the Edited flag when saving->close.
This commit is contained in:
10
Misc/SAV6.cs
10
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
|
||||
|
||||
@@ -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<Util.cbItem> 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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -180,7 +180,7 @@ select Util.ToUInt32(cardID))
|
||||
}
|
||||
|
||||
Array.Copy(sav, Main.SAV.Data, sav.Length);
|
||||
Main.savedited = true;
|
||||
Main.SAV.Edited = true;
|
||||
Close();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user