From c1e2c3048c796a3ea715fda16c61b58538d1002d Mon Sep 17 00:00:00 2001 From: Lotte Date: Wed, 8 Nov 2023 15:27:42 +1100 Subject: [PATCH 1/2] Villager PRO Design owner overwrite Shifted HorizonSave into VillagerEditor in place of MainSave and adjusted accordingly to give VillagerEditor better access to save file offsets etc. Added overwrite for Villager PRO patterns to set imported ones to be made/owned by the player for consistency. (town and player ID bytes) --- NHSE.WinForms/Controls/VillagerEditor.cs | 24 ++++++++++++++---------- NHSE.WinForms/Editor.cs | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/NHSE.WinForms/Controls/VillagerEditor.cs b/NHSE.WinForms/Controls/VillagerEditor.cs index 04100152..d3489469 100644 --- a/NHSE.WinForms/Controls/VillagerEditor.cs +++ b/NHSE.WinForms/Controls/VillagerEditor.cs @@ -12,11 +12,11 @@ public partial class VillagerEditor : UserControl { public IVillager[] Villagers; public IVillagerOrigin Origin; - private readonly MainSave SAV; + private readonly HorizonSave SAV; private int VillagerIndex = -1; private bool Loading; - public VillagerEditor(IVillager[] villagers, IVillagerOrigin origin, MainSave sav, bool hasHouses) + public VillagerEditor(IVillager[] villagers, IVillagerOrigin origin, HorizonSave sav, bool hasHouses) { InitializeComponent(); Villagers = villagers; @@ -132,7 +132,7 @@ private void B_LoadVillager_Click(object sender, EventArgs e) return; var path = ofd.FileName; - var expectLength = SAV.Offsets.VillagerSize; + var expectLength = SAV.Main.Offsets.VillagerSize; var fi = new FileInfo(path); if (!VillagerConverter.IsCompatible((int)fi.Length, expectLength)) { @@ -148,7 +148,7 @@ private void B_LoadVillager_Click(object sender, EventArgs e) return; } - var v = SAV.Offsets.ReadVillager(data); + var v = SAV.Main.Offsets.ReadVillager(data); var player0 = Origin; if (!v.IsOriginatedFrom(player0)) { @@ -203,11 +203,11 @@ private void ChangeVillager() private void B_EditHouse_Click(object sender, EventArgs e) { SaveVillager(VillagerIndex); - var villagers = SAV.GetVillagers(); - var houses = SAV.GetVillagerHouses(); - using var editor = new VillagerHouseEditor(houses, villagers, SAV, VillagerIndex); + var villagers = SAV.Main.GetVillagers(); + var houses = SAV.Main.GetVillagerHouses(); + using var editor = new VillagerHouseEditor(houses, villagers, SAV.Main, VillagerIndex); if (editor.ShowDialog() == DialogResult.OK) - SAV.SetVillagerHouses(houses); + SAV.Main.SetVillagerHouses(houses); } private static void ShowContextMenuBelow(ToolStripDropDown c, Control n) => c.Show(n.PointToScreen(new System.Drawing.Point(0, n.Height))); @@ -223,9 +223,13 @@ private void B_EditVillagerRoom_Click(object sender, EventArgs e) private void B_EditVillagerDesign_Click(object sender, EventArgs e) { + var playerID = SAV.Players[0].Personal.GetPlayerIdentity(); // fetch ID for overwrite ownership + var townID = SAV.Players[0].Personal.GetTownIdentity(); // fetch ID for overwrite ownership var v = Villagers[VillagerIndex]; var tmp = new[] {v.Design}; using var editor = new PatternEditorPRO(tmp); + playerID.CopyTo(tmp[0].Data, 0x54); // overwrite playerID bytes + townID.CopyTo(tmp[0].Data, 0x38); // overwrite townID bytes if (editor.ShowDialog() == DialogResult.OK) v.Design = tmp[0]; } @@ -306,13 +310,13 @@ private void B_ReplaceVillager_Click(object sender, EventArgs e) return; } - var houses = SAV.GetVillagerHouses(); + var houses = SAV.Main.GetVillagerHouses(); var houseIndex = Array.FindIndex(houses, z => z.NPC1 == index); var exist = new VillagerInfo(v2, houses[houseIndex]); var replace = VillagerSwap.GetReplacementVillager(exist, internalName); var nh = new VillagerHouse1(replace.House); - SAV.SetVillagerHouse(nh, houseIndex); + SAV.Main.SetVillagerHouse(nh, houseIndex); var nv = new Villager2(replace.Villager); LoadVillager(Villagers[index] = nv); System.Media.SystemSounds.Asterisk.Play(); diff --git a/NHSE.WinForms/Editor.cs b/NHSE.WinForms/Editor.cs index 244cae72..ebaa707f 100644 --- a/NHSE.WinForms/Editor.cs +++ b/NHSE.WinForms/Editor.cs @@ -166,7 +166,7 @@ private VillagerEditor LoadVillagers() { var p0 = SAV.Players[0].Personal; var villagers = SAV.Main.GetVillagers(); - var v = new VillagerEditor(villagers, p0, SAV.Main, true) {Dock = DockStyle.Fill}; + var v = new VillagerEditor(villagers, p0, SAV, true) {Dock = DockStyle.Fill}; Tab_Villagers.Controls.Add(v); return v; } From 30ea5a9b41e9fa880ca14e71fab8fbca88575ce0 Mon Sep 17 00:00:00 2001 From: Lotte Date: Mon, 18 Dec 2023 14:51:36 +1100 Subject: [PATCH 2/2] Update flag wipe for placed designs Update flag wipe for placed designs --- NHSE.Core/Save/Offsets/MainSaveOffsets.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NHSE.Core/Save/Offsets/MainSaveOffsets.cs b/NHSE.Core/Save/Offsets/MainSaveOffsets.cs index 298d3558..c160e5b8 100644 --- a/NHSE.Core/Save/Offsets/MainSaveOffsets.cs +++ b/NHSE.Core/Save/Offsets/MainSaveOffsets.cs @@ -116,7 +116,7 @@ public void WritePattern(DesignPattern p, byte[] data, int index, byte[] playerI throw new ArgumentOutOfRangeException(nameof(index)); playerID.CopyTo(p.Data, 0x54); // overwrite playerID bytes so player owns townID.CopyTo(p.Data, 0x38); // overwrite townID bytes so player owns - byte[] wipeflag = new byte[] { 0x00, 0x00, 0x00, 0x00 }; // wipe so player owns + byte[] wipeflag = new byte[] { 0x02, 0xEE, 0x00, 0x00 }; // wipe so player owns wipeflag.CopyTo(p.Data, 0x70); p.Data.CopyTo(data, LandMyDesign + (index * DesignPattern.SIZE)); byte[] editedflag = new byte[] { 0x00 };