Add flag dump/load

Closes #234
This commit is contained in:
Kurt 2020-05-19 09:48:11 -07:00
parent 832a6717f8
commit 9645c16152
9 changed files with 212 additions and 7 deletions

View File

@ -33,6 +33,8 @@ private void InitializeComponent()
this.LB_Counts = new System.Windows.Forms.ListBox();
this.NUD_Count = new System.Windows.Forms.NumericUpDown();
this.L_Count = new System.Windows.Forms.Label();
this.B_Load = new System.Windows.Forms.Button();
this.B_Dump = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.NUD_Count)).BeginInit();
this.SuspendLayout();
//
@ -99,11 +101,35 @@ private void InitializeComponent()
this.L_Count.TabIndex = 10;
this.L_Count.Text = "Value:";
//
// FlagEditor
// B_Load
//
this.B_Load.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.B_Load.Location = new System.Drawing.Point(200, 158);
this.B_Load.Name = "B_Load";
this.B_Load.Size = new System.Drawing.Size(72, 23);
this.B_Load.TabIndex = 14;
this.B_Load.Text = "Load";
this.B_Load.UseVisualStyleBackColor = true;
this.B_Load.Click += new System.EventHandler(this.B_Load_Click);
//
// B_Dump
//
this.B_Dump.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.B_Dump.Location = new System.Drawing.Point(200, 129);
this.B_Dump.Name = "B_Dump";
this.B_Dump.Size = new System.Drawing.Size(72, 23);
this.B_Dump.TabIndex = 13;
this.B_Dump.Text = "Dump";
this.B_Dump.UseVisualStyleBackColor = true;
this.B_Dump.Click += new System.EventHandler(this.B_Dump_Click);
//
// LandFlagEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 261);
this.Controls.Add(this.B_Load);
this.Controls.Add(this.B_Dump);
this.Controls.Add(this.L_Count);
this.Controls.Add(this.NUD_Count);
this.Controls.Add(this.LB_Counts);
@ -112,7 +138,7 @@ private void InitializeComponent()
this.Icon = global::NHSE.WinForms.Properties.Resources.icon;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "FlagEditor";
this.Name = "LandFlagEditor";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Flag Editor";
((System.ComponentModel.ISupportInitialize)(this.NUD_Count)).EndInit();
@ -128,5 +154,7 @@ private void InitializeComponent()
private System.Windows.Forms.ListBox LB_Counts;
private System.Windows.Forms.NumericUpDown NUD_Count;
private System.Windows.Forms.Label L_Count;
private System.Windows.Forms.Button B_Load;
private System.Windows.Forms.Button B_Dump;
}
}

View File

@ -47,5 +47,20 @@ private void LB_Counts_SelectedIndexChanged(object sender, EventArgs e)
NUD_Count.Value = Counts[Index = LB_Counts.SelectedIndex];
}
private void B_Dump_Click(object sender, EventArgs e)
{
byte[] data = new byte[Counts.Length * 2];
Buffer.BlockCopy(Counts, 0, data, 0, data.Length);
MiscDumpHelper.DumpFlags(data, nameof(EventFlagLand));
}
private void B_Load_Click(object sender, EventArgs e)
{
var data = MiscDumpHelper.LoadFlags(Counts.Length * 2, nameof(EventFlagLand));
if (data.Length != 0)
Buffer.BlockCopy(data, 0, Counts, 0, data.Length);
LB_Counts.SelectedIndex = LB_Counts.SelectedIndex;
}
}
}

View File

@ -197,5 +197,38 @@ public static bool LoadRoom(PlayerRoom room, int index)
data.CopyTo(room.Data, 0);
return true;
}
public static void DumpFlags(byte[] data, string name)
{
using var sfd = new SaveFileDialog
{
Filter = "New Horizons Flag List (*.nhfl)|*.nhfl|All files (*.*)|*.*",
FileName = $"{name}.nhfl",
};
if (sfd.ShowDialog() == DialogResult.OK)
File.WriteAllBytes(sfd.FileName, data);
}
public static byte[] LoadFlags(int size, string name)
{
using var ofd = new OpenFileDialog
{
Filter = "New Horizons Flag List (*.nhfl)|*.nhfl|All files (*.*)|*.*",
FileName = $"{name}.nhfl",
};
if (ofd.ShowDialog() != DialogResult.OK)
return System.Array.Empty<byte>();
var file = ofd.FileName;
var fi = new FileInfo(file);
int expectLength = size;
if (fi.Length != expectLength)
{
WinFormsUtil.Error(MessageStrings.MsgCanceling, string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expectLength));
return System.Array.Empty<byte>();
}
return File.ReadAllBytes(file);
}
}
}
}

View File

@ -33,6 +33,8 @@ private void InitializeComponent()
this.LB_Counts = new System.Windows.Forms.ListBox();
this.NUD_Count = new System.Windows.Forms.NumericUpDown();
this.L_Count = new System.Windows.Forms.Label();
this.B_Load = new System.Windows.Forms.Button();
this.B_Dump = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.NUD_Count)).BeginInit();
this.SuspendLayout();
//
@ -99,11 +101,35 @@ private void InitializeComponent()
this.L_Count.TabIndex = 10;
this.L_Count.Text = "Value:";
//
// FlagEditor
// B_Load
//
this.B_Load.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.B_Load.Location = new System.Drawing.Point(200, 158);
this.B_Load.Name = "B_Load";
this.B_Load.Size = new System.Drawing.Size(72, 23);
this.B_Load.TabIndex = 14;
this.B_Load.Text = "Load";
this.B_Load.UseVisualStyleBackColor = true;
this.B_Load.Click += new System.EventHandler(this.B_Load_Click);
//
// B_Dump
//
this.B_Dump.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.B_Dump.Location = new System.Drawing.Point(200, 129);
this.B_Dump.Name = "B_Dump";
this.B_Dump.Size = new System.Drawing.Size(72, 23);
this.B_Dump.TabIndex = 13;
this.B_Dump.Text = "Dump";
this.B_Dump.UseVisualStyleBackColor = true;
this.B_Dump.Click += new System.EventHandler(this.B_Dump_Click);
//
// PlayerHouseFlagEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 261);
this.Controls.Add(this.B_Load);
this.Controls.Add(this.B_Dump);
this.Controls.Add(this.L_Count);
this.Controls.Add(this.NUD_Count);
this.Controls.Add(this.LB_Counts);
@ -112,7 +138,7 @@ private void InitializeComponent()
this.Icon = global::NHSE.WinForms.Properties.Resources.icon;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "FlagEditor";
this.Name = "PlayerHouseFlagEditor";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Flag Editor";
((System.ComponentModel.ISupportInitialize)(this.NUD_Count)).EndInit();
@ -128,5 +154,7 @@ private void InitializeComponent()
private System.Windows.Forms.ListBox LB_Counts;
private System.Windows.Forms.NumericUpDown NUD_Count;
private System.Windows.Forms.Label L_Count;
private System.Windows.Forms.Button B_Load;
private System.Windows.Forms.Button B_Dump;
}
}

View File

@ -46,5 +46,20 @@ private void LB_Counts_SelectedIndexChanged(object sender, EventArgs e)
NUD_Count.Value = Counts[Index = LB_Counts.SelectedIndex];
}
private void B_Dump_Click(object sender, EventArgs e)
{
byte[] data = new byte[Counts.Length * 2];
Buffer.BlockCopy(Counts, 0, data, 0, data.Length);
MiscDumpHelper.DumpFlags(data, nameof(EventFlagHouse));
}
private void B_Load_Click(object sender, EventArgs e)
{
var data = MiscDumpHelper.LoadFlags(Counts.Length * 2, nameof(EventFlagHouse));
if (data.Length != 0)
Buffer.BlockCopy(data, 0, Counts, 0, data.Length);
LB_Counts.SelectedIndex = LB_Counts.SelectedIndex;
}
}
}

View File

@ -33,6 +33,8 @@ private void InitializeComponent()
this.LB_Counts = new System.Windows.Forms.ListBox();
this.NUD_Count = new System.Windows.Forms.NumericUpDown();
this.L_Count = new System.Windows.Forms.Label();
this.B_Load = new System.Windows.Forms.Button();
this.B_Dump = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.NUD_Count)).BeginInit();
this.SuspendLayout();
//
@ -99,11 +101,35 @@ private void InitializeComponent()
this.L_Count.TabIndex = 10;
this.L_Count.Text = "Value:";
//
// B_Load
//
this.B_Load.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.B_Load.Location = new System.Drawing.Point(200, 158);
this.B_Load.Name = "B_Load";
this.B_Load.Size = new System.Drawing.Size(72, 23);
this.B_Load.TabIndex = 12;
this.B_Load.Text = "Load";
this.B_Load.UseVisualStyleBackColor = true;
this.B_Load.Click += new System.EventHandler(this.B_Load_Click);
//
// B_Dump
//
this.B_Dump.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.B_Dump.Location = new System.Drawing.Point(200, 129);
this.B_Dump.Name = "B_Dump";
this.B_Dump.Size = new System.Drawing.Size(72, 23);
this.B_Dump.TabIndex = 11;
this.B_Dump.Text = "Dump";
this.B_Dump.UseVisualStyleBackColor = true;
this.B_Dump.Click += new System.EventHandler(this.B_Dump_Click);
//
// FlagEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 261);
this.Controls.Add(this.B_Load);
this.Controls.Add(this.B_Dump);
this.Controls.Add(this.L_Count);
this.Controls.Add(this.NUD_Count);
this.Controls.Add(this.LB_Counts);
@ -128,5 +154,7 @@ private void InitializeComponent()
private System.Windows.Forms.ListBox LB_Counts;
private System.Windows.Forms.NumericUpDown NUD_Count;
private System.Windows.Forms.Label L_Count;
private System.Windows.Forms.Button B_Load;
private System.Windows.Forms.Button B_Dump;
}
}

View File

@ -46,5 +46,20 @@ private void LB_Counts_SelectedIndexChanged(object sender, EventArgs e)
NUD_Count.Value = Counts[Index = LB_Counts.SelectedIndex];
}
private void B_Dump_Click(object sender, EventArgs e)
{
byte[] data = new byte[Counts.Length * 2];
Buffer.BlockCopy(Counts, 0, data, 0, data.Length);
MiscDumpHelper.DumpFlags(data, nameof(EventFlagPlayer));
}
private void B_Load_Click(object sender, EventArgs e)
{
var data = MiscDumpHelper.LoadFlags(Counts.Length * 2, nameof(EventFlagPlayer));
if (data.Length != 0)
Buffer.BlockCopy(data, 0, Counts, 0, data.Length);
LB_Counts.SelectedIndex = LB_Counts.SelectedIndex;
}
}
}

View File

@ -33,6 +33,8 @@ private void InitializeComponent()
this.LB_Counts = new System.Windows.Forms.ListBox();
this.NUD_Count = new System.Windows.Forms.NumericUpDown();
this.L_Count = new System.Windows.Forms.Label();
this.B_Load = new System.Windows.Forms.Button();
this.B_Dump = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.NUD_Count)).BeginInit();
this.SuspendLayout();
//
@ -99,11 +101,35 @@ private void InitializeComponent()
this.L_Count.TabIndex = 10;
this.L_Count.Text = "Value:";
//
// FlagEditor
// B_Load
//
this.B_Load.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.B_Load.Location = new System.Drawing.Point(200, 158);
this.B_Load.Name = "B_Load";
this.B_Load.Size = new System.Drawing.Size(72, 23);
this.B_Load.TabIndex = 14;
this.B_Load.Text = "Load";
this.B_Load.UseVisualStyleBackColor = true;
this.B_Load.Click += new System.EventHandler(this.B_Load_Click);
//
// B_Dump
//
this.B_Dump.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.B_Dump.Location = new System.Drawing.Point(200, 129);
this.B_Dump.Name = "B_Dump";
this.B_Dump.Size = new System.Drawing.Size(72, 23);
this.B_Dump.TabIndex = 13;
this.B_Dump.Text = "Dump";
this.B_Dump.UseVisualStyleBackColor = true;
this.B_Dump.Click += new System.EventHandler(this.B_Dump_Click);
//
// VillagerFlagEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 261);
this.Controls.Add(this.B_Load);
this.Controls.Add(this.B_Dump);
this.Controls.Add(this.L_Count);
this.Controls.Add(this.NUD_Count);
this.Controls.Add(this.LB_Counts);
@ -112,7 +138,7 @@ private void InitializeComponent()
this.Icon = global::NHSE.WinForms.Properties.Resources.icon;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "FlagEditor";
this.Name = "VillagerFlagEditor";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Flag Editor";
((System.ComponentModel.ISupportInitialize)(this.NUD_Count)).EndInit();
@ -128,5 +154,7 @@ private void InitializeComponent()
private System.Windows.Forms.ListBox LB_Counts;
private System.Windows.Forms.NumericUpDown NUD_Count;
private System.Windows.Forms.Label L_Count;
private System.Windows.Forms.Button B_Load;
private System.Windows.Forms.Button B_Dump;
}
}

View File

@ -46,5 +46,20 @@ private void LB_Counts_SelectedIndexChanged(object sender, EventArgs e)
NUD_Count.Value = Counts[Index = LB_Counts.SelectedIndex];
}
private void B_Dump_Click(object sender, EventArgs e)
{
byte[] data = new byte[Counts.Length * 2];
Buffer.BlockCopy(Counts, 0, data, 0, data.Length);
MiscDumpHelper.DumpFlags(data, nameof(EventFlagVillager));
}
private void B_Load_Click(object sender, EventArgs e)
{
var data = MiscDumpHelper.LoadFlags(Counts.Length * 2, nameof(EventFlagVillager));
if (data.Length != 0)
Buffer.BlockCopy(data, 0, Counts, 0, data.Length);
LB_Counts.SelectedIndex = LB_Counts.SelectedIndex;
}
}
}