mirror of
https://github.com/jaquadro/NBTExplorer.git
synced 2025-01-09 17:36:25 +00:00
Byte and Int arrays can be modified to different lengths
This commit is contained in:
parent
d27234e2cd
commit
8f092842e9
4 changed files with 42 additions and 11 deletions
|
@ -319,7 +319,8 @@ namespace NBTExplorer.Model
|
|||
};
|
||||
|
||||
if (FormRegistry.EditByteArray(data)) {
|
||||
Array.Copy(data.Data, tag.ToTagByteArray().Data, tag.ToTagByteArray().Length);
|
||||
tag.ToTagByteArray().Data = data.Data;
|
||||
//Array.Copy(data.Data, tag.ToTagByteArray().Data, tag.ToTagByteArray().Length);
|
||||
IsDataModified = true;
|
||||
return true;
|
||||
}
|
||||
|
@ -345,6 +346,7 @@ namespace NBTExplorer.Model
|
|||
};
|
||||
|
||||
if (FormRegistry.EditByteArray(data)) {
|
||||
iatag.Data = new int[data.Data.Length / 4];
|
||||
for (int i = 0; i < iatag.Length; i++) {
|
||||
iatag.Data[i] = BitConverter.ToInt32(data.Data, i * 4);
|
||||
}
|
||||
|
|
32
Windows/EditHex.Designer.cs
generated
32
Windows/EditHex.Designer.cs
generated
|
@ -30,9 +30,11 @@
|
|||
this.hexBox1 = new Be.Windows.Forms.HexBox();
|
||||
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
|
||||
this._curPositionLabel = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this._curElementLabel = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this._buttonCancel = new System.Windows.Forms.Button();
|
||||
this._buttonOK = new System.Windows.Forms.Button();
|
||||
this._curElementLabel = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this._space = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this._insertStateLabel = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
|
@ -56,7 +58,9 @@
|
|||
//
|
||||
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this._curPositionLabel,
|
||||
this._curElementLabel});
|
||||
this._curElementLabel,
|
||||
this._space,
|
||||
this._insertStateLabel});
|
||||
this.statusStrip1.Location = new System.Drawing.Point(0, 333);
|
||||
this.statusStrip1.Name = "statusStrip1";
|
||||
this.statusStrip1.Size = new System.Drawing.Size(516, 22);
|
||||
|
@ -70,6 +74,13 @@
|
|||
this._curPositionLabel.Size = new System.Drawing.Size(100, 17);
|
||||
this._curPositionLabel.Text = "0000";
|
||||
//
|
||||
// _curElementLabel
|
||||
//
|
||||
this._curElementLabel.Name = "_curElementLabel";
|
||||
this._curElementLabel.Size = new System.Drawing.Size(59, 17);
|
||||
this._curElementLabel.Text = "Element 0";
|
||||
this._curElementLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
|
||||
//
|
||||
// _buttonCancel
|
||||
//
|
||||
this._buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
|
@ -92,12 +103,17 @@
|
|||
this._buttonOK.UseVisualStyleBackColor = true;
|
||||
this._buttonOK.Click += new System.EventHandler(this._buttonOK_Click);
|
||||
//
|
||||
// _curElementLabel
|
||||
// _space
|
||||
//
|
||||
this._curElementLabel.Name = "_curElementLabel";
|
||||
this._curElementLabel.Size = new System.Drawing.Size(59, 17);
|
||||
this._curElementLabel.Text = "Element 0";
|
||||
this._curElementLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
|
||||
this._space.Name = "_space";
|
||||
this._space.Size = new System.Drawing.Size(253, 17);
|
||||
this._space.Spring = true;
|
||||
//
|
||||
// _insertStateLabel
|
||||
//
|
||||
this._insertStateLabel.Name = "_insertStateLabel";
|
||||
this._insertStateLabel.Size = new System.Drawing.Size(58, 17);
|
||||
this._insertStateLabel.Text = "Overwrite";
|
||||
//
|
||||
// HexEditor
|
||||
//
|
||||
|
@ -126,5 +142,7 @@
|
|||
private System.Windows.Forms.Button _buttonCancel;
|
||||
private System.Windows.Forms.Button _buttonOK;
|
||||
private System.Windows.Forms.ToolStripStatusLabel _curElementLabel;
|
||||
private System.Windows.Forms.ToolStripStatusLabel _space;
|
||||
private System.Windows.Forms.ToolStripStatusLabel _insertStateLabel;
|
||||
}
|
||||
}
|
|
@ -36,7 +36,7 @@ namespace NBTExplorer.Windows
|
|||
_data = new byte[data.Length];
|
||||
Array.Copy(data, _data, data.Length);
|
||||
|
||||
_byteProvider = new FixedByteProvider(_data);
|
||||
_byteProvider = new DynamicByteProvider(_data);
|
||||
_byteProvider.Changed += (o, e) => { _modified = true; };
|
||||
|
||||
hexBox1.ByteProvider = _byteProvider;
|
||||
|
@ -44,6 +44,7 @@ namespace NBTExplorer.Windows
|
|||
hexBox1.HorizontalByteCountChanged += HexBox_HorizontalByteCountChanged;
|
||||
hexBox1.CurrentLineChanged += HexBox_CurrentLineChanged;
|
||||
hexBox1.CurrentPositionInLineChanged += HexBox_CurrentPositionInLineChanged;
|
||||
hexBox1.InsertActiveChanged += HexBox_InsertActiveChanged;
|
||||
|
||||
hexBox1.ReadOnly = false;
|
||||
}
|
||||
|
@ -73,6 +74,14 @@ namespace NBTExplorer.Windows
|
|||
UpdatePosition();
|
||||
}
|
||||
|
||||
private void HexBox_InsertActiveChanged (object sender, EventArgs e)
|
||||
{
|
||||
if (hexBox1.InsertActive)
|
||||
_insertStateLabel.Text = "Insert";
|
||||
else
|
||||
_insertStateLabel.Text = "Overwrite";
|
||||
}
|
||||
|
||||
private void UpdatePosition ()
|
||||
{
|
||||
long pos = (hexBox1.CurrentLine - 1) * hexBox1.HorizontalByteCount + hexBox1.CurrentPositionInLine - 1;
|
||||
|
@ -83,9 +92,10 @@ namespace NBTExplorer.Windows
|
|||
|
||||
private void Apply ()
|
||||
{
|
||||
long len = Math.Min(_data.Length, _byteProvider.Length);
|
||||
if (_data.Length != _byteProvider.Length)
|
||||
_data = new byte[_byteProvider.Length];
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
for (int i = 0; i < _data.Length; i++) {
|
||||
_data[i] = _byteProvider.Bytes[i];
|
||||
}
|
||||
|
||||
|
|
|
@ -60,6 +60,7 @@ namespace NBTExplorer.Windows
|
|||
{
|
||||
HexEditor form = new HexEditor(data.NodeName, data.Data, data.BytesPerElement);
|
||||
if (form.ShowDialog() == DialogResult.OK && form.Modified) {
|
||||
data.Data = new byte[form.Data.Length];
|
||||
Array.Copy(form.Data, data.Data, data.Data.Length);
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue