private void OK_Button_Click(object sender, EventArgs e) { if (int.Parse(TextBox1.Text, System.Globalization.NumberStyles.HexNumber) + Data.Length < Program.MainForm.Read.FileLength - 512) { this.SaveOffset = int.Parse(TextBox1.Text, System.Globalization.NumberStyles.HexNumber); if (Program.MainForm.SafetyRepointing && this.SaveOffset % 4 == 0 || !Program.MainForm.SafetyRepointing) { byte[] ExistingData = Program.MainForm.Read.ReadBytes(SaveOffset, Data.Length); if (IsFreeSpace(ExistingData, SaveOffset) || !CheckBoxAbort.Checked) { write.WriteBytes(Data, this.SaveOffset); MessageBox.Show(this, "Inserted data at offset 0x" + this.SaveOffset.ToString("X"), "Success:", MessageBoxButtons.OK, MessageBoxIcon.Information); Program.MainForm.LogWriter.LogMessage("Inserted Data at 0x" + SaveOffset.ToString("X")); this.Close(); } else { MessageBox.Show(this, Data.Length.ToString() + " bytes is too long for this offset, Aborting", "Abort", MessageBoxButtons.OK, MessageBoxIcon.Error); SaveOffset = -1; } } else { MessageBox.Show(this, "Aborted:\n\t0x" + this.SaveOffset.ToString("X") + " is not a PointerSafe offset.\nPointerSafe offsets are multiples of 4 (ex. ending in 0, 4, 8, or C).\n\nTo disable SafetyRepointing, un-check Options>Safety Repointing.", "Abort:", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { TextBox1.Text = (Program.MainForm.Read.FileLength - 513).ToString("X"); } }
private void OK_Button_Click(object sender, EventArgs e) { if (int.Parse(TextBox1.Text, System.Globalization.NumberStyles.HexNumber) < Program.MainForm.Read.FileLength - 512) { this.SaveOffset = int.Parse(TextBox1.Text, System.Globalization.NumberStyles.HexNumber); if (Program.MainForm.SafetyRepointing && this.SaveOffset % 4 == 0 || !Program.MainForm.SafetyRepointing) { byte[] ExistingData = Program.MainForm.Read.ReadBytes(SaveOffset, Data.Length); if (IsFreeSpace(ExistingData, SaveOffset, OrigonalOffset, OrigonalLength) || !CheckBoxAbort.Checked) { write.WriteBytes(Data, this.SaveOffset); Program.MainForm.LogWriter.LogMessage("Saved Data 0x" + OrigonalOffset.ToString("X") + " to 0x" + SaveOffset.ToString("X")); if (CheckBoxPointers.Checked && SaveOffset != OrigonalOffset && OrigonalOffset != -1) { byte[] _old = BitConverter.GetBytes(OrigonalOffset); _old = new byte[] { _old[0], _old[1], _old[2], (byte)(_old[3] + 0x8) }; byte[] _new = BitConverter.GetBytes(this.SaveOffset); _new = new byte[] { _new[0], _new[1], _new[2], (byte)(_new[3] + 0x8) }; NSE_Framework.Find find = new NSE_Framework.Find(Program.MainForm.Filename); List <int> ReplacedOffsets = new List <int>(); if (!Program.MainForm.AdvancedRepointing) { find.SearchAndReplace(_old, _new, out ReplacedOffsets); if (ReplacedOffsets.Count != 0) { string mes = ""; foreach (int i in ReplacedOffsets) { mes = mes + " 0x" + i.ToString("X2"); } MessageBox.Show(this, "Replaced the pointers at offsets:\n\n" + mes, "Notice.", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); Program.MainForm.LogWriter.LogMessage("Replaced pointers at offsets: " + mes); this.Close(); } else { this.Close(); } } else { ReplacedOffsets = find.Search(_old); if (ReplacedOffsets.Count != 0) { NSE2.SelectOffsets so = new SelectOffsets(ReplacedOffsets); so.ShowDialog(this); if (so.DialogResult == System.Windows.Forms.DialogResult.OK) { ReplacedOffsets = so.SelectedOffsets; if (ReplacedOffsets.Count != 0) { foreach (int o in ReplacedOffsets) { write.WriteBytes(_new, o); } string mes = ""; foreach (int i in ReplacedOffsets) { mes = mes + " 0x" + i.ToString("X2"); } MessageBox.Show(this, "Replaced the pointers at offsets:\n\n" + mes, "Notice.", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); Program.MainForm.LogWriter.LogMessage("Replaced pointers at offsets: " + mes); this.Close(); } else { this.Close(); } } else if (so.DialogResult == System.Windows.Forms.DialogResult.Cancel) { this.Close(); } } else { this.Close(); } } } else { this.Close(); } } else { MessageBox.Show(this, Data.Length.ToString() + " bytes is too long for this offset, Aborting", "Abort", MessageBoxButtons.OK, MessageBoxIcon.Error); SaveOffset = -1; } } else { MessageBox.Show(this, "Aborted:\n\t0x" + this.SaveOffset.ToString("X") + " is not a PointerSafe offset.\nPointerSafe offsets end in 0, 4, 8, or C.\n\nTo disable SafetyRepointing, un-check Options>Safety Repointing.", "Safety Repointing", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { TextBox1.Text = (Program.MainForm.Read.FileLength - 513).ToString("X"); } }
private void MenuItemSave_Click(object sender, EventArgs e) { write.WriteBytes(byteSprite, ImageOffset); }