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); }
public static bool LoadRoom(MainSaveOffsets offsets, ref IPlayerRoom room, int index) { using var ofd = new OpenFileDialog { Filter = "New Horizons Player House Room (*.nhpr)|*.nhpr|" + "New Horizons Player House Room (*.nhpr2)|*.nhpr2|" + "All files (*.*)|*.*", FileName = $"Room {index + 1}.{room.Extension}", }; if (ofd.ShowDialog() != DialogResult.OK) { return(false); } var path = ofd.FileName; var expectLength = offsets.PlayerRoomSize; var fi = new FileInfo(path); if (!PlayerRoomConverter.IsCompatible((int)fi.Length, expectLength)) { WinFormsUtil.Error(string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expectLength), path); return(false); } var data = File.ReadAllBytes(ofd.FileName); data = PlayerRoomConverter.GetCompatible(data, offsets.PlayerRoomSize); if (data.Length != expectLength) { WinFormsUtil.Error(MessageStrings.MsgCanceling, string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expectLength), path); return(false); } room = offsets.ReadPlayerRoom(data); return(true); }