public static bool LoadHouse(IReadOnlyList <Player> players, PlayerHouse[] houses, int index) { var name = PlayerHouseEditor.GetHouseSummary(players, houses[index], index); using var ofd = new OpenFileDialog { Filter = "New Horizons Player House (*.nhph)|*.nhph|All files (*.*)|*.*", FileName = $"{name}.nhph", }; if (ofd.ShowDialog() != DialogResult.OK) { return(false); } var file = ofd.FileName; var fi = new FileInfo(file); const int expectLength = PlayerHouse.SIZE; if (fi.Length != expectLength) { WinFormsUtil.Error(MessageStrings.MsgCanceling, string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expectLength)); return(false); } var data = File.ReadAllBytes(file); var h = new PlayerHouse(data); var current = houses[index]; h.NPC1 = current.NPC1; houses[index] = h; return(true); }
private void B_EditPlayerHouses_Click(object sender, EventArgs e) { var houses = SAV.Main.GetPlayerHouses(); using var editor = new PlayerHouseEditor(houses, SAV.Players, PlayerIndex); if (editor.ShowDialog() == DialogResult.OK) { SAV.Main.SetPlayerHouses(houses); } }
private static void DumpPlayerHouse(IReadOnlyList <Player> players, IReadOnlyList <PlayerHouse> houses, int index) { var house = houses[index]; var name = PlayerHouseEditor.GetHouseSummary(players, house, index); using var sfd = new SaveFileDialog { Filter = "New Horizons Player House (*.nhph)|*.nhph|All files (*.*)|*.*", FileName = $"{name}.nhph", }; if (sfd.ShowDialog() != DialogResult.OK) { return; } var data = house.Data; File.WriteAllBytes(sfd.FileName, data); }
public static bool LoadHouse(MainSaveOffsets offsets, IReadOnlyList <Player> players, IPlayerHouse[] houses, int index) { var h = houses[index]; var name = PlayerHouseEditor.GetHouseSummary(players, houses[index], index); using var ofd = new OpenFileDialog { Filter = "New Horizons Player House (*.nhph)|*.nhph|" + "New Horizons Player House (*.nhph2)|*.nhph2|" + "All files (*.*)|*.*", FileName = $"{name}.{h.Extension}", }; if (ofd.ShowDialog() != DialogResult.OK) { return(false); } var path = ofd.FileName; var expectLength = offsets.PlayerHouseSize; var fi = new FileInfo(path); if (!PlayerHouseConverter.IsCompatible((int)fi.Length, expectLength)) { WinFormsUtil.Error(string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expectLength), path); return(false); } var data = File.ReadAllBytes(ofd.FileName); data = PlayerHouseConverter.GetCompatible(data, expectLength); if (data.Length != expectLength) { WinFormsUtil.Error(MessageStrings.MsgCanceling, string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expectLength), path); return(false); } h = offsets.ReadPlayerHouse(data); var current = houses[index]; h.NPC1 = current.NPC1; houses[index] = h; return(true); }