Add RAM I/O

This commit is contained in:
Kurt 2015-08-14 22:14:26 -07:00
parent bb194986bb
commit 3e0e53c4fc
2 changed files with 67 additions and 1 deletions

View File

@ -33,6 +33,8 @@ private void InitializeComponent()
this.L_Info = new System.Windows.Forms.Label();
this.B_Save = new System.Windows.Forms.Button();
this.B_Cancel = new System.Windows.Forms.Button();
this.B_Import = new System.Windows.Forms.Button();
this.B_Export = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.PB_JPEG)).BeginInit();
this.SuspendLayout();
//
@ -76,11 +78,35 @@ private void InitializeComponent()
this.B_Cancel.UseVisualStyleBackColor = true;
this.B_Cancel.Click += new System.EventHandler(this.B_Cancel_Click);
//
// B_Import
//
this.B_Import.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.B_Import.Location = new System.Drawing.Point(12, 198);
this.B_Import.Name = "B_Import";
this.B_Import.Size = new System.Drawing.Size(75, 23);
this.B_Import.TabIndex = 4;
this.B_Import.Text = "Import RAM";
this.B_Import.UseVisualStyleBackColor = true;
this.B_Import.Click += new System.EventHandler(this.B_Import_Click);
//
// B_Export
//
this.B_Export.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.B_Export.Location = new System.Drawing.Point(12, 227);
this.B_Export.Name = "B_Export";
this.B_Export.Size = new System.Drawing.Size(75, 23);
this.B_Export.TabIndex = 5;
this.B_Export.Text = "Export RAM";
this.B_Export.UseVisualStyleBackColor = true;
this.B_Export.Click += new System.EventHandler(this.B_Export_Click);
//
// Garden
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.B_Export);
this.Controls.Add(this.B_Import);
this.Controls.Add(this.B_Cancel);
this.Controls.Add(this.B_Save);
this.Controls.Add(this.L_Info);
@ -103,5 +129,7 @@ private void InitializeComponent()
private System.Windows.Forms.Label L_Info;
private System.Windows.Forms.Button B_Save;
private System.Windows.Forms.Button B_Cancel;
private System.Windows.Forms.Button B_Import;
private System.Windows.Forms.Button B_Export;
}
}

View File

@ -1,6 +1,7 @@
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace NLSE
@ -24,6 +25,44 @@ private void B_Cancel_Click(object sender, EventArgs e)
{
Close();
}
private void B_Import_Click(object sender, EventArgs e)
{
var ofd = new OpenFileDialog
{
Filter = "RAM Dump|*.bin"
};
if (ofd.ShowDialog() != DialogResult.OK)
return;
var len = new FileInfo(ofd.FileName).Length;
if (new FileInfo(ofd.FileName).Length != 0x80000)
{
Util.Error(String.Format(
"Data lengths do not match.{0}" +
"Expected: 0x{1}{0}" +
"Received: 0x{2}",
Environment.NewLine, 0x80000.ToString("X5"), len.ToString("X5")));
return;
}
byte[] data = File.ReadAllBytes(ofd.FileName);
Array.Copy(data, 0, Save.Data, 0x80, Save.Data.Length - 0x80);
}
private void B_Export_Click(object sender, EventArgs e)
{
saveData();
var sfd = new SaveFileDialog
{
Filter = "RAM Dump|*.bin"
};
if (sfd.ShowDialog() != DialogResult.OK)
return;
byte[] RAM = Save.Data.Skip(0x80).ToArray();
Array.Resize(ref RAM, 0x80000);
File.WriteAllBytes(sfd.FileName, RAM);
}
// Garden Save Editing
private GardenData Save;
@ -71,6 +110,5 @@ private void lt_bank()
Array.Copy(BitConverter.GetBytes(0x8CF95678), 0, Save.Data, offset, 4);
Array.Copy(BitConverter.GetBytes(0x0D118636), 0, Save.Data, offset, 4);
}
}
}