Skip to content

Commit

Permalink
Merge pull request #642 from lottehime/master
Browse files Browse the repository at this point in the history
Villager PRO Design owner overwrite + bug fix for placed design path compliance
  • Loading branch information
lottehime authored Dec 18, 2023
2 parents ad372b7 + 866a3b9 commit 57dda23
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion NHSE.Core/Save/Offsets/MainSaveOffsets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
24 changes: 14 additions & 10 deletions NHSE.WinForms/Controls/VillagerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
{
Expand All @@ -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))
{
Expand Down Expand Up @@ -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)));
Expand All @@ -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];
}
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion NHSE.WinForms/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 57dda23

Please sign in to comment.