Exemple #1
0
        public static byte[] LoadFlags(int size, string name)
        {
            using var ofd = new OpenFileDialog
                  {
                      Filter   = "New Horizons Flag List (*.nhfl)|*.nhfl|All files (*.*)|*.*",
                      FileName = $"{name}.nhfl",
                  };
            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return(System.Array.Empty <byte>());
            }

            var file         = ofd.FileName;
            var fi           = new FileInfo(file);
            int expectLength = size;

            if (fi.Length != expectLength)
            {
                WinFormsUtil.Error(MessageStrings.MsgCanceling, string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expectLength));
                return(System.Array.Empty <byte>());
            }

            return(File.ReadAllBytes(file));
        }
Exemple #2
0
        private void WriteUSB_Click(object sender, EventArgs e)
        {
            if (!BotUSB.Connect())
            {
                return;
            }

            var offset = StringUtil.GetHexValue(RamOffsetUSB.Text);

            if (offset == 0)
            {
                WinFormsUtil.Error(MessageStrings.MsgInvalidHexValue);
                return;
            }

            InjectorUSB.SetWriteOffset(offset);
            Bot.SetOffset(offset);

            try
            {
                var result = InjectorUSB.Write(true);
                if (result == InjectionResult.Success)
                {
                    return;
                }
                WinFormsUtil.Alert(result.ToString());
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
            {
                WinFormsUtil.Error(ex.Message);
            }

            BotUSB.Disconnect();
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        private void B_LoadHouse_Click(object sender, EventArgs e)
        {
            var name = GetVillagerName(Houses[Index]);

            if (name == "???")
            {
                name = "*";
            }
            using var ofd = new OpenFileDialog
                  {
                      Filter   = "New Horizons Villager House (*.nhvh)|*.nhvh|All files (*.*)|*.*",
                      FileName = $"{name}.nhvh",
                  };
            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var       file         = ofd.FileName;
            var       fi           = new FileInfo(file);
            const int expectLength = VillagerHouse.SIZE;

            if (fi.Length != expectLength)
            {
                WinFormsUtil.Error(MessageStrings.MsgCanceling, string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expectLength));
                return;
            }

            var data    = File.ReadAllBytes(file);
            var h       = new VillagerHouse(data);
            var current = Houses[Index];

            h.NPC1                 = current.NPC1;
            Houses[Index]          = h;
            PG_Item.SelectedObject = h;
        }
Exemple #5
0
        private void B_LoadDesign_Click(object sender, EventArgs e)
        {
            if (sender == B_LoadDesignAll)
            {
                using var fbd = new FolderBrowserDialog();
                if (fbd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                var dir = Path.GetDirectoryName(fbd.SelectedPath);
                if (dir == null || !Directory.Exists(dir))
                {
                    return;
                }
                var result = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel, MessageStrings.MsgAskUpdateValues);
                Patterns.Load(fbd.SelectedPath, result == DialogResult.Yes);
                LoadPattern(Patterns[Index]);
                RepopulateList(Index);
                return;
            }

            var original = Patterns[Index];
            var name     = original.DesignName;

            using var ofd = new OpenFileDialog
                  {
                      Filter   = "New Horizons Design Pattern (*.nhd)|*.nhd|All files (*.*)|*.*",
                      FileName = $"{name}.nhd",
                  };
            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var file         = ofd.FileName;
            var expectLength = original.Data.Length;
            var fi           = new FileInfo(file);

            if (fi.Length != expectLength)
            {
                var msg = string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expectLength);
                WinFormsUtil.Error(MessageStrings.MsgCanceling, msg);
                return;
            }

            var data    = File.ReadAllBytes(ofd.FileName);
            var d       = new DesignPattern(data);
            var player0 = original;

            if (!d.IsOriginatedFrom(player0))
            {
                var notHost = string.Format(MessageStrings.MsgDataDidNotOriginateFromHost_0, player0.PlayerName);
                var result  = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel, notHost, MessageStrings.MsgAskUpdateValues);
                if (result == DialogResult.Cancel)
                {
                    return;
                }
                if (result == DialogResult.Yes)
                {
                    d.ChangeOrigins(player0, d.Data);
                }
            }

            Patterns[Index] = d;
            LoadPattern(d);
            RepopulateList(Index);
        }