mirror of
https://github.com/kwsch/NHSE.git
synced 2026-07-12 22:30:57 -05:00
Add villager import button
This commit is contained in:
parent
7005e31d2a
commit
b85b69308b
|
|
@ -60,7 +60,7 @@ public static void DumpVillagers(this MainSave sav, string path)
|
|||
{
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
var v = sav.Offsets.ReadVillager(sav.Data, i);
|
||||
var v = sav.GetVillager(i);
|
||||
var name = GameInfo.Strings.GetVillager(v.InternalName);
|
||||
var dest = Path.Combine(path, $"{name}.nhv");
|
||||
File.WriteAllBytes(dest, v.Data);
|
||||
|
|
|
|||
13
NHSE.WinForms/Editor.Designer.cs
generated
13
NHSE.WinForms/Editor.Designer.cs
generated
|
|
@ -73,6 +73,7 @@ private void InitializeComponent()
|
|||
this.Tab_Map = new System.Windows.Forms.TabPage();
|
||||
this.B_RecycleBin = new System.Windows.Forms.Button();
|
||||
this.Menu_LoadDecrypted = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.B_LoadVillager = new System.Windows.Forms.Button();
|
||||
this.Menu_Editor.SuspendLayout();
|
||||
this.TC_Editors.SuspendLayout();
|
||||
this.Tab_Players.SuspendLayout();
|
||||
|
|
@ -352,6 +353,7 @@ private void InitializeComponent()
|
|||
//
|
||||
// Tab_Villagers
|
||||
//
|
||||
this.Tab_Villagers.Controls.Add(this.B_LoadVillager);
|
||||
this.Tab_Villagers.Controls.Add(this.B_DumpVillager);
|
||||
this.Tab_Villagers.Controls.Add(this.L_ExternalName);
|
||||
this.Tab_Villagers.Controls.Add(this.L_InternalName);
|
||||
|
|
@ -554,6 +556,16 @@ private void InitializeComponent()
|
|||
this.Menu_LoadDecrypted.Text = "Load Decrypted";
|
||||
this.Menu_LoadDecrypted.Click += new System.EventHandler(this.Menu_LoadDecrypted_Click);
|
||||
//
|
||||
// B_LoadVillager
|
||||
//
|
||||
this.B_LoadVillager.Location = new System.Drawing.Point(112, 168);
|
||||
this.B_LoadVillager.Name = "B_LoadVillager";
|
||||
this.B_LoadVillager.Size = new System.Drawing.Size(100, 40);
|
||||
this.B_LoadVillager.TabIndex = 25;
|
||||
this.B_LoadVillager.Text = "Load Villager";
|
||||
this.B_LoadVillager.UseVisualStyleBackColor = true;
|
||||
this.B_LoadVillager.Click += new System.EventHandler(this.B_LoadVillager_Click);
|
||||
//
|
||||
// Editor
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
|
|
@ -635,6 +647,7 @@ private void InitializeComponent()
|
|||
private System.Windows.Forms.Button B_RecycleBin;
|
||||
private System.Windows.Forms.Button B_EditPlayerStorage;
|
||||
private System.Windows.Forms.ToolStripMenuItem Menu_LoadDecrypted;
|
||||
private System.Windows.Forms.Button B_LoadVillager;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -310,8 +310,35 @@ private void B_DumpVillager_Click(object sender, EventArgs e)
|
|||
return;
|
||||
|
||||
SaveVillager(VillagerIndex);
|
||||
var data = SAV.Main.Offsets.ReadVillager(SAV.Main.Data, VillagerIndex).Data;
|
||||
File.WriteAllBytes(sfd.FileName, data);
|
||||
var v = SAV.Main.GetVillager(VillagerIndex);
|
||||
File.WriteAllBytes(sfd.FileName, v.Data);
|
||||
}
|
||||
|
||||
private void B_LoadVillager_Click(object sender, EventArgs e)
|
||||
{
|
||||
var name = L_ExternalName.Text;
|
||||
using var ofd = new OpenFileDialog
|
||||
{
|
||||
Filter = "New Horizons Villager (*.nhv)|*.nhv|All files (*.*)|*.*",
|
||||
FileName = $"{name}.nhv",
|
||||
};
|
||||
if (ofd.ShowDialog() != DialogResult.OK)
|
||||
return;
|
||||
|
||||
var file = ofd.FileName;
|
||||
var v = SAV.Main.GetVillager(VillagerIndex);
|
||||
var expectLength = v.Data.Length;
|
||||
var fi = new FileInfo(file);
|
||||
if (fi.Length != expectLength)
|
||||
{
|
||||
var msg = $"Imported villager's data length (0x{fi.Length:X}) does not match the required length (0x{expectLength:X}).";
|
||||
WinFormsUtil.Error("Cancelling:", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
var update = File.ReadAllBytes(ofd.FileName);
|
||||
update.CopyTo(v.Data, 0);
|
||||
SAV.Main.SetVillager(v, VillagerIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user